Merge branch 'developer' of github.com:slsdetectorgroup/slsDetectorPackage into developer

This commit is contained in:
maliakal_d 2020-03-19 11:36:44 +01:00
commit 272a8bfaf1
4 changed files with 57 additions and 37 deletions

View File

@ -1345,7 +1345,7 @@ std::string CmdProxy::VetoReference(int action) {
if (args.size() != 2) {
WrongNumberOfParameters(2);
}
det->setVetoReference(std::stoi(args[0]), stoiHex(args[1]), {det_id});
det->setVetoReference(StringTo<int>(args[0]), StringTo<int>(args[1]), {det_id});
os << sls::ToString(args) << '\n';
} else {
throw sls::RuntimeError("Unknown action");
@ -1577,7 +1577,7 @@ std::string CmdProxy::DigitalIODelay(int action) {
if (args.size() != 2) {
WrongNumberOfParameters(2);
}
det->setDigitalIODelay(stoulHex(args[0]), std::stoi(args[1]), {det_id});
det->setDigitalIODelay(StringTo<uint64_t>(args[0]), StringTo<int>(args[1]), {det_id});
os << sls::ToString(args) << '\n';
} else {
throw sls::RuntimeError("Unknown action");
@ -1619,13 +1619,13 @@ std::string CmdProxy::PatternWord(int action) {
if (args.size() != 1) {
WrongNumberOfParameters(1);
}
auto t = det->getPatternWord(stoiHex(args[0]), {det_id});
auto t = det->getPatternWord(StringTo<uint64_t>(args[0]), {det_id});
os << OutStringHex(t) << '\n';
} else if (action == defs::PUT_ACTION) {
if (args.size() != 2) {
WrongNumberOfParameters(2);
}
det->setPatternWord(stoiHex(args[0]), stoulHex(args[1]), {det_id});
det->setPatternWord(StringTo<int>(args[0]), StringTo<uint64_t>(args[1]), {det_id});
os << sls::ToString(args) << '\n';
} else {
throw sls::RuntimeError("Unknown action");
@ -1678,8 +1678,8 @@ std::string CmdProxy::PatternLoopAddresses(int action) {
if (args.size() != 2) {
WrongNumberOfParameters(2);
}
det->setPatternLoopAddresses(level, stoiHex(args[0]),
stoiHex(args[1]), {det_id});
det->setPatternLoopAddresses(level, StringTo<int>(args[0]),
StringTo<int>(args[1]), {det_id});
os << sls::ToString(args) << '\n';
} else {
throw sls::RuntimeError("Unknown action");
@ -1769,7 +1769,7 @@ std::string CmdProxy::PatternWaitAddress(int action) {
if (args.size() != 1) {
WrongNumberOfParameters(1);
}
det->setPatternWaitAddr(level, stoiHex(args[0]), {det_id});
det->setPatternWaitAddr(level, StringTo<int>(args[0]), {det_id});
os << args.front() << '\n';
} else {
throw sls::RuntimeError("Unknown action");
@ -1978,13 +1978,13 @@ std::string CmdProxy::Register(int action) {
if (args.size() != 1) {
WrongNumberOfParameters(1);
}
auto t = det->readRegister(stoiHex(args[0]), {det_id});
auto t = det->readRegister(StringTo<uint32_t>(args[0]), {det_id});
os << OutStringHex(t) << '\n';
} else if (action == defs::PUT_ACTION) {
if (args.size() != 2) {
WrongNumberOfParameters(2);
}
det->writeRegister(stoiHex(args[0]), stoiHex(args[1]), {det_id});
det->writeRegister(StringTo<uint32_t>(args[0]), StringTo<uint32_t>(args[1]), {det_id});
os << sls::ToString(args) << '\n';
} else {
throw sls::RuntimeError("Unknown action");
@ -2005,7 +2005,7 @@ std::string CmdProxy::AdcRegister(int action) {
if (args.size() != 2) {
WrongNumberOfParameters(2);
}
det->writeAdcRegister(stoiHex(args[0]), stoiHex(args[1]), {det_id});
det->writeAdcRegister(StringTo<uint32_t>(args[0]), StringTo<uint32_t>(args[1]), {det_id});
os << sls::ToString(args) << '\n';
} else {
throw sls::RuntimeError("Unknown action");
@ -2041,8 +2041,8 @@ std::string CmdProxy::BitOperations(int action) {
if (args.size() != 2) {
WrongNumberOfParameters(2);
}
uint32_t addr = stoiHex(args[0]);
int bitnr = std::stoi(args[1]);
auto addr = StringTo<uint32_t>(args[0]);
auto bitnr = StringTo<int>(args[1]);
if (bitnr < 0 || bitnr > 31) {
return std::string("Bit number out of range") +
std::to_string(bitnr);

View File

@ -448,19 +448,19 @@ class CmdProxy {
return ToString(value, unit);
}
inline unsigned int stoiHex(const std::string& s) {
unsigned long lresult = stoul(s, nullptr, 16);
unsigned int result = lresult;
if (result != lresult) {
throw std::out_of_range("cannot convert to unsigned int");
}
return result;
}
// inline unsigned int stoiHex(const std::string& s) {
// unsigned long lresult = stoul(s, nullptr, 16);
// unsigned int result = lresult;
// if (result != lresult) {
// throw std::out_of_range("cannot convert to unsigned int");
// }
// return result;
// }
inline unsigned long int stoulHex(const std::string& s) {
unsigned long result = stoul(s, nullptr, 16);
return result;
}
// inline unsigned long int stoulHex(const std::string& s) {
// unsigned long result = stoul(s, nullptr, 16);
// return result;
// }
using FunctionMap = std::map<std::string, std::string (CmdProxy::*)(int)>;
using StringMap = std::map<std::string, std::string>;
@ -1325,22 +1325,22 @@ class CmdProxy {
/* on chip dacs */
INTEGER_USER_IND_COMMAND(vchip_comp_fe, getOnChipDAC, setOnChipDAC, stoiHex, defs::VB_COMP_FE,
INTEGER_USER_IND_COMMAND(vchip_comp_fe, getOnChipDAC, setOnChipDAC, StringTo<int>, defs::VB_COMP_FE,
"[chip index 0-10, -1 for all][10 bit hex value] \n\t[Gotthard2] On chip Dac for comparator current of analogue front end.");
INTEGER_USER_IND_COMMAND(vchip_opa_1st, getOnChipDAC, setOnChipDAC, stoiHex, defs::VB_OPA_1ST,
INTEGER_USER_IND_COMMAND(vchip_opa_1st, getOnChipDAC, setOnChipDAC, StringTo<int>, defs::VB_OPA_1ST,
"[chip index 0-10, -1 for all][10 bit hex value] \n\t[Gotthard2] On chip Dac for opa current for driving the other DACs in chip.");
INTEGER_USER_IND_COMMAND(vchip_opa_fd, getOnChipDAC, setOnChipDAC, stoiHex, defs::VB_OPA_FD,
INTEGER_USER_IND_COMMAND(vchip_opa_fd, getOnChipDAC, setOnChipDAC, StringTo<int>, defs::VB_OPA_FD,
"[chip index 0-10, -1 for all][10 bit hex value] \n\t[Gotthard2] On chip Dac current for CDS opa stage.");
INTEGER_USER_IND_COMMAND(vchip_comp_adc, getOnChipDAC, setOnChipDAC, stoiHex, defs::VB_COMP_ADC,
INTEGER_USER_IND_COMMAND(vchip_comp_adc, getOnChipDAC, setOnChipDAC, StringTo<int>, defs::VB_COMP_ADC,
"[chip index 0-10, -1 for all][10 bit hex value] \n\t[Gotthard2] On chip Dac for comparator current of ADC.");
INTEGER_USER_IND_COMMAND(vchip_ref_comp_fe, getOnChipDAC, setOnChipDAC, stoiHex, defs::VREF_COMP_FE,
INTEGER_USER_IND_COMMAND(vchip_ref_comp_fe, getOnChipDAC, setOnChipDAC, StringTo<int>, defs::VREF_COMP_FE,
"[chip index 0-10, -1 for all][10 bit hex value] \n\t[Gotthard2] On chip Dac for reference voltage of the comparator of analogue front end.");
INTEGER_USER_IND_COMMAND(vchip_cs, getOnChipDAC, setOnChipDAC, stoiHex, defs::VB_CS,
INTEGER_USER_IND_COMMAND(vchip_cs, getOnChipDAC, setOnChipDAC, StringTo<int>, defs::VB_CS,
"[chip index 0-10, -1 for all][10 bit hex value] \n\t[Gotthard2] On chip Dac for current injection into preamplifier.");
@ -1620,10 +1620,10 @@ class CmdProxy {
INTEGER_IND_COMMAND(v_limit, getVoltage, setVoltage, std::stoi, defs::V_LIMIT,
"[n_value]\n\t[Ctb][Moench] Soft limit for power supplies(ctb only) and DACS in mV.");
INTEGER_COMMAND_HEX(adcenable, getADCEnableMask, setADCEnableMask, stoiHex,
INTEGER_COMMAND_HEX(adcenable, getADCEnableMask, setADCEnableMask, StringTo<uint32_t>,
"[bitmask]\n\t[Ctb][Moench] ADC Enable Mask for 1Gb Mode for each 32 ADC channel.");
INTEGER_COMMAND_HEX(adcenable10g, getTenGigaADCEnableMask, setTenGigaADCEnableMask, stoiHex,
INTEGER_COMMAND_HEX(adcenable10g, getTenGigaADCEnableMask, setTenGigaADCEnableMask, StringTo<uint32_t>,
"[bitmask]\n\t[Ctb][Moench] ADC Enable Mask for 10Gb mode for each 32 ADC channel. However, if any of consecutive 4 bits are enabled, the complete 4 bits are enabled.");
/* CTB Specific */
@ -1707,16 +1707,16 @@ class CmdProxy {
EXECUTE_SET_COMMAND_NOID_1ARG(savepattern, savePattern,
"[fname]\n\t[Ctb][Moench][Mythen3] Saves pattern to file (ascii). Also executes pattern.");
INTEGER_COMMAND_HEX(patioctrl, getPatternIOControl, setPatternIOControl, stoulHex,
INTEGER_COMMAND_HEX(patioctrl, getPatternIOControl, setPatternIOControl, StringTo<uint64_t>,
"[64 bit mask]\n\t[Ctb][Moench][Mythen3] 64 bit mask defining input (0) and output (1) signals.");
INTEGER_COMMAND_HEX(patclkctrl, getPatternClockControl, setPatternClockControl, stoulHex,
INTEGER_COMMAND_HEX(patclkctrl, getPatternClockControl, setPatternClockControl, StringTo<uint64_t>,
"[64 bit mask]\n\t[Ctb][Moench][Mythen3] 64 bit mask defining output clock enable.");
INTEGER_COMMAND_HEX(patmask, getPatternMask, setPatternMask, stoulHex,
INTEGER_COMMAND_HEX(patmask, getPatternMask, setPatternMask, StringTo<uint64_t>,
"[64 bit mask]\n\t[Ctb][Moench][Mythen3] 64 bit mask applied to every pattern. Only these bits for each pattern will be masked against.");
INTEGER_COMMAND_HEX(patsetbit, getPatternBitMask, setPatternBitMask, stoulHex,
INTEGER_COMMAND_HEX(patsetbit, getPatternBitMask, setPatternBitMask, StringTo<uint64_t>,
"[64 bit mask]\n\t[Ctb][Moench][Mythen3] 64 bit values applied to the selected patmask for every pattern.");
/* Moench */
@ -1745,7 +1745,7 @@ class CmdProxy {
EXECUTE_SET_COMMAND(bustest, executeBusTest,
"\n\t[Jungfrau][Gotthard][Mythen3][Gotthard2][Ctb][Moench] Bus test, ie. keeps writing and reading back different values in R/W register.");
INTEGER_COMMAND_HEX(adcinvert, getADCInvert, setADCInvert, stoiHex,
INTEGER_COMMAND_HEX(adcinvert, getADCInvert, setADCInvert, StringTo<uint32_t>,
"[bitmask]\n\t[Ctb][Moench][Jungfrau][Moench] ADC Inversion Mask.\n\t[Jungfrau][Moench] Inversions on top of the default mask.");
/* Insignificant */

View File

@ -622,6 +622,12 @@ inline uint64_t StringTo(const std::string &s) {
return std::stoull(s, nullptr, base);
}
template <>
inline int StringTo(const std::string &s) {
int base = s.find("0x") != std::string::npos ? 16 : 10;
return std::stoi(s, nullptr, base);
}
/** For types with a .str() method use this for conversion */
template <typename T>
typename std::enable_if<has_str<T>::value, std::string>::type

View File

@ -165,3 +165,17 @@ TEST_CASE("uint64 from string"){
}
TEST_CASE("int from string"){
REQUIRE(StringTo<int>("-1") == -1);
REQUIRE(StringTo<int>("-0x1") == -0x1);
REQUIRE(StringTo<int>("-0x1") == -1);
REQUIRE(StringTo<int>("0") == 0);
REQUIRE(StringTo<int>("5") == 5);
REQUIRE(StringTo<int>("16") == 16);
REQUIRE(StringTo<int>("20") == 20);
REQUIRE(StringTo<int>("0x14") == 20);
REQUIRE(StringTo<int>("0x15") == 21);
REQUIRE(StringTo<int>("0xffffff") == 0xffffff);
}