diff --git a/slsDetectorSoftware/generator/Caller.in.h b/slsDetectorSoftware/generator/Caller.in.h index 8e1b6fad9..d03f691c8 100644 --- a/slsDetectorSoftware/generator/Caller.in.h +++ b/slsDetectorSoftware/generator/Caller.in.h @@ -93,10 +93,9 @@ class Caller { // applicable RegisterAddress getRegisterAddress(const std::string &saddr) const; BitAddress getBitAddress() const; - defs::dacIndex parsePowerIndex(int argIndex); - std::optional parseIfPowerIndex(int argIndex); defs::dacIndex parseDacIndex(int argIndex, bool isCtb); bool parseMV(int argIndex); + defs::dacIndex parsePowerIndex(int argIndex); FunctionMap functions{ {"list", &Caller::list}, diff --git a/slsDetectorSoftware/generator/commands.yaml b/slsDetectorSoftware/generator/commands.yaml index d9bc4b583..dd8d92650 100644 --- a/slsDetectorSoftware/generator/commands.yaml +++ b/slsDetectorSoftware/generator/commands.yaml @@ -2757,6 +2757,17 @@ dac: arg_types: [ std::string ] - argc: 2 arg_types: [ std::string, bool ] + + +powerdac: + is_description: true + actions: + PUT: + argc: 2 + arg_types: [ std::string, int ] + GET: + argc: 1 + arg_types: [ std::string ] v_limit: diff --git a/slsDetectorSoftware/include/sls/Detector.h b/slsDetectorSoftware/include/sls/Detector.h index 02033c544..c2e7b1c7d 100644 --- a/slsDetectorSoftware/include/sls/Detector.h +++ b/slsDetectorSoftware/include/sls/Detector.h @@ -535,9 +535,7 @@ class Detector { Result getDAC(defs::dacIndex index, bool mV = false, Positions pos = {}) const; - /** Sets dac in dac units or mV - * [Ctb][Xilinx Ctb] also includes V_LIMIT, V_POWER_A, V_POWER_B, V_POWER_C, - * V_POWER_D, V_POWER_IO, V_POWER_CHIP (get only)*/ + /** Sets dac in dac units or mV1 */ void setDAC(defs::dacIndex index, int value, bool mV = false, Positions pos = {}); @@ -1632,20 +1630,40 @@ class Detector { Result getSYNCClock(Positions pos = {}) const; /** gets list of power enums */ - std::vector getPowerList() const; - - /** gets list of slow adc enums */ - std::vector getSlowADCList() const; + std::vector getPowerList() const; /** [CTB][Xilinx CTB] */ - Result isPowerEnabled(defs::dacIndex index, Positions pos = {}) const; + int getPowerDAC(defs::powerIndex index) const; + + /** [CTB][Xilinx CTB] Options: V_POWE_A, V_POWER_B, V_POWER_C, + * V_POWER_D, V_POWER_IO */ + void setPowerDAC(defs::powerIndex index, int value); + + /** [CTB][Xilinx CTB] */ + bool isPowerEnabled(defs::powerIndex index) const; /** * [Ctb][Xilinx CTB] Options: V_POWER_A, V_POWER_B, V_POWER_C, * V_POWER_D, V_POWER_IO */ - void setPowerEnabled(const std::vector &indices, - bool enable, Positions pos = {}); + void setPowerEnabled(const std::vector &indices, + bool enable); + + /** + * [CTB] mV + * Options: V_POWER_A, V_POWER_B, V_POWER_C, V_POWER_D, V_POWER_IO */ + int getMeasuredPower(defs::powerIndex index) const; + + /** + * [CTB] mA + * Options: I_POWER_A, I_POWER_B, I_POWER_C, I_POWER_D, I_POWER_IO */ + int getMeasuredCurrent(defs::powerIndex index) const; + + /** [CTB][Xilinx CTB] gets list of slow adc enums */ + std::vector getSlowADCList() const; + + /** [CTB][Xilinx CTB] Options: SLOW_ADC0 - SLOW_ADC7 in uV */ + Result getSlowADC(defs::dacIndex index, Positions pos = {}) const; /** * [CTB] Options: [0- 4] or [1V, 1.14V, 1.33V, 1.6V, 2V] @@ -1701,21 +1719,6 @@ class Detector { /** [CTB] in MHz, [XCTB] in kHz */ void setDBITClock(int value_in_MHz, Positions pos = {}); - /** - * [CTB] mV - * Options: V_POWER_A, V_POWER_B, V_POWER_C, V_POWER_D, V_POWER_IO */ - Result getMeasuredPower(defs::dacIndex index, - Positions pos = {}) const; - - /** - * [CTB] mA - * Options: I_POWER_A, I_POWER_B, I_POWER_C, I_POWER_D, I_POWER_IO */ - Result getMeasuredCurrent(defs::dacIndex index, - Positions pos = {}) const; - - /** [CTB][Xilinx CTB] Options: SLOW_ADC0 - SLOW_ADC7 in uV */ - Result getSlowADC(defs::dacIndex index, Positions pos = {}) const; - /** [CTB] */ Result getExternalSamplingSource(Positions pos = {}) const; @@ -1818,13 +1821,13 @@ class Detector { std::vector getPowerNames() const; /** [CTB][Xilinx CTB] */ - defs::dacIndex getPowerIndex(const std::string &name) const; + defs::powerIndex getPowerIndex(const std::string &name) const; /** [CTB][Xilinx CTB] */ - void setPowerName(const defs::dacIndex i, const std::string &name); + void setPowerName(const defs::powerIndex i, const std::string &name); /** [CTB][Xilinx CTB] */ - std::string getPowerName(const defs::dacIndex i) const; + std::string getPowerName(const defs::powerIndex i) const; /** [CTB][Xilinx CTB] */ void setSlowADCNames(const std::vector names); diff --git a/slsDetectorSoftware/src/CallerSpecial.cpp b/slsDetectorSoftware/src/CallerSpecial.cpp index a91ffffbd..017021f2e 100644 --- a/slsDetectorSoftware/src/CallerSpecial.cpp +++ b/slsDetectorSoftware/src/CallerSpecial.cpp @@ -1854,37 +1854,6 @@ std::string Caller::dac(int action) { return os.str(); } -defs::dacIndex Caller::parsePowerIndex(int argIndex) { - auto res = parseIfPowerIndex(argIndex); - if (!res.has_value()) { - throw RuntimeError("Invalid power name. Power name can be v_a, v_b, " - "v_c, v_d, v_io, v_chip or any names set using " - "powername command."); - } - return res.value(); -} - -std::optional Caller::parseIfPowerIndex(int argIndex) { - if (argIndex >= (int)args.size()) { - throw RuntimeError("Invalid arguments. Power name is required."); - } - auto arg = args[argIndex]; - - // power default names - if (is_int(arg) || arg == "v_a" || arg == "v_b" || arg == "v_c" || - arg == "v_d" || arg == "v_io" || arg == "v_chip") { - return std::make_optional(StringTo(arg)); - } - - // power name - auto names = det->getPowerNames(); - auto it = std::find(names.begin(), names.end(), arg); - if (it != names.end()) { - return std::make_optional(det->getPowerIndex(arg)); - } - return std::nullopt; -} - defs::dacIndex Caller::parseDacIndex(int argIndex, bool isCtb) { if (argIndex >= (int)args.size()) { throw RuntimeError("Invalid arguments. DAC index is required."); @@ -1892,10 +1861,9 @@ defs::dacIndex Caller::parseDacIndex(int argIndex, bool isCtb) { auto arg = args[argIndex]; if (isCtb) { - // power dacs - auto res = parseIfPowerIndex(argIndex); - if (res.has_value()) { - return res.value(); + // dac index + if (is_int(arg)) { + return StringTo(arg); } // dac name return det->getDacIndex(arg); @@ -1922,6 +1890,78 @@ bool Caller::parseMV(int argIndex) { return false; } +std::string Caller::powerdac(int action) { + std::ostringstream os; + + if (action == defs::HELP_ACTION) { + os << "[powername][mV value]\n\t[Ctb][Xilinx Ctb] Controls the dac " + "used for Power supply. Default names for powername are v_a, " + "v_b, v_c, v_d, v_io, v_chip(v_chip only applies to Ctb, not " + "Xilinx_Ctb). If custom names are assigned using the 'powername' " + "command, those names could be used instead instead of the " + "defaults. By default, all are set to minimum values. \n\t[Ctb] " + "v_chip can also be queried to get the vchip dac value, although " + "its rail cannot be enabled or disabled by the user. It is " + "enabled by default. Its dac value is automatically updated " + "whenever a power dac is modified. It is then set to the max of " + "power dacs + 200mV." + << '\n'; + return os.str(); + } + + auto detType = det->getDetectorType().squash(defs::GENERIC); + if (detType != defs::CHIPTESTBOARD && + detType != defs::XILINX_CHIPTESTBOARD) { + throw RuntimeError("This command is only applicable for ChipTestBoard " + "and Xilinx ChipTestBoard."); + } + if (det_id != -1) { + throw RuntimeError("Cannot use powerdac at module level."); + } + auto index = parsePowerIndex(0); + + if (action == defs::GET_ACTION) { + auto t = det->getPowerDAC(index); + os << args[0] << ' ' << OutString(t) << '\n'; + } + + else if (action == defs::PUT_ACTION) { + if (args.size() != 2) { + WrongNumberOfParameters(2); + } + auto val = StringTo(args[1]); + det->setPowerDAC(index, val); + os << args[0] << ' ' << args[1] << '\n'; + } else { + throw RuntimeError("Unknown action"); + } + + return os.str(); +} + +defs::dacIndex Caller::parsePowerIndex(int argIndex) { + if (argIndex >= (int)args.size()) { + throw RuntimeError("Invalid arguments. Power name is required."); + } + auto arg = args[argIndex]; + + // power default names + if (is_int(arg) || arg == "v_a" || arg == "v_b" || arg == "v_c" || + arg == "v_d" || arg == "v_io" || arg == "v_chip") { + return StringTo(arg); + } + + // power name + auto names = det->getPowerNames(); + auto it = std::find(names.begin(), names.end(), arg); + if (it != names.end()) { + return det->getPowerIndex(arg); + } + throw RuntimeError( + "Unknown power name '" + arg + + "'. Use 'powername' command to see defined power names."); +} + std::string Caller::v_limit(int action) { std::ostringstream os; diff --git a/slsDetectorSoftware/src/HelpDacs.cpp b/slsDetectorSoftware/src/HelpDacs.cpp index 8b40ad244..3e432f306 100644 --- a/slsDetectorSoftware/src/HelpDacs.cpp +++ b/slsDetectorSoftware/src/HelpDacs.cpp @@ -283,48 +283,6 @@ std::string GetHelpDac(std::string dac) { if (dac == "vtgstv") { return std::string(""); } - - if (dac == "v_a") { - return std::string( - "[mV value] mV \n\t[Ctb][Xilinx Ctb] Dac for Power supply a. Can " - "only be set in mV. Default to minimum values. To switch off must " - "switch off power rails using 'power' command.\n\t[Ctb] Changes " - "vchip (max of power supply voltages + 200mV)."); - } - if (dac == "v_b") { - return std::string( - "[mV value] mV \n\t[Ctb][Xilinx Ctb] Dac for Power supply b. Can " - "only be set in mV. Default to minimum values. To switch off must " - "switch off power rails using 'power' command.\n\t[Ctb] Changes " - "vchip (max of power supply voltages + 200mV)."); - } - if (dac == "v_c") { - return std::string( - "[mV value] mV \n\t[Ctb][Xilinx Ctb] Dac for Power supply c. Can " - "only be set in mV. Default to minimum values. To switch off must " - "switch off power rails using 'power' command.\n\t[Ctb] Changes " - "vchip (max of power supply voltages + 200mV)."); - } - if (dac == "v_d") { - return std::string( - "[mV value] mV \n\t[Ctb][Xilinx Ctb] Dac for Power supply d. Can " - "only be set in mV. Default to minimum values. To switch off must " - "switch off power rails using 'power' command.\n\t[Ctb] Changes " - "vchip (max of power supply voltages + 200mV)."); - } - if (dac == "v_io") { - return std::string( - "[mV value] mV \n\t[Ctb][Xilinx Ctb] Dac for Power supply IO. Can " - "only be set in mV. Default to minimum values. To switch off must " - "switch off power rails using 'power' command.\n\t[Ctb] Changes " - "vchip (max of power supply voltages + 200mV)."); - } - if (dac == "v_chip") { - return std::string("mV \n\t[Ctb] Dac for Vchip. Can only get. Default " - "to minimum values. Vchip is set in the background " - "when v_a, b, c, d or io are set."); - } - throw sls::RuntimeError("Unknown dac command"); } diff --git a/slsDetectorSoftware/tests/Caller/test-Caller-chiptestboard.cpp b/slsDetectorSoftware/tests/Caller/test-Caller-chiptestboard.cpp index 485ba2d47..821889bf7 100644 --- a/slsDetectorSoftware/tests/Caller/test-Caller-chiptestboard.cpp +++ b/slsDetectorSoftware/tests/Caller/test-Caller-chiptestboard.cpp @@ -315,7 +315,7 @@ TEST_CASE("powername", "[.detectorintegration]") { if (det_type == defs::CHIPTESTBOARD || det_type == defs::XILINX_CHIPTESTBOARD) { - defs::dacIndex ind = static_cast(2 + defs::V_POWER_A); + defs::powerIndex ind = static_cast(2); std::string str_power_index = "2"; auto prev = det.getPowerName(ind); @@ -350,7 +350,7 @@ TEST_CASE("powerindex", "[.detectorintegration]") { if (det_type == defs::CHIPTESTBOARD || det_type == defs::XILINX_CHIPTESTBOARD) { - defs::dacIndex ind = static_cast(2 + defs::V_POWER_A); + defs::powerIndex ind = static_cast(2); std::string str_power_index = "2"; // 1 arg throw @@ -593,15 +593,38 @@ TEST_CASE("dac", "[.detectorintegration][dacs]") { caller.call("dac", {std::to_string(idac), "-1"}, -1, PUT)); } - // power dacs + // power dacs (shouldnt work anymore. TODO: remove after testing) + REQUIRE_THROWS(caller.call("dac", {"v_a", "mV"}, -1, GET)); + } +} + +TEST_CASE("powerdac", "[.detectorintegration][dacs]") { + Detector det; + Caller caller(&det); + auto det_type = det.getDetectorType().squash(); + if (det_type == defs::CHIPTESTBOARD || + det_type == defs::XILINX_CHIPTESTBOARD) { if (det.isVirtualDetectorServer().tsquash( "Inconsistent virtual servers")) { + + // test only get of vchip + if (det_type == defs::CHIPTESTBOARD) { + REQUIRE_THROWS( + caller.call("powerdac", {"v_chip", "1700", "mV"}, -1, PUT)); + REQUIRE_THROWS( + caller.call("powerdac", {"v_chip", "mV"}, -1, GET)); + REQUIRE_NOTHROW(caller.call("powerdac", {"v_chip"}, -1, GET)); + } else { + REQUIRE_THROWS(caller.call("powerdac", {"v_chip"}, -1, GET)); + } + + // other power dacs std::vector names{"v_a", "v_b", "v_c", "v_d", "v_io"}; - std::vector indices{ + std::vector indices{ defs::V_POWER_A, defs::V_POWER_B, defs::V_POWER_C, defs::V_POWER_D, defs::V_POWER_IO}; for (size_t iPower = 0; iPower < names.size(); ++iPower) { - auto prev_val = det.getDAC(indices[iPower], true); + auto prev_val = det.getPowerDAC(indices[iPower]); auto prev_val_power = det.isPowerEnabled(indices[iPower]); // turn them off to be able to set the power dacs without issue @@ -609,100 +632,90 @@ TEST_CASE("dac", "[.detectorintegration][dacs]") { // this is the first command touching power dacs, should not be // -100 - if (det_type == defs::XILINX_CHIPTESTBOARD || - det_type == defs::CHIPTESTBOARD) { - REQUIRE(prev_val.any(-100) == false); - REQUIRE(prev_val.any(-1) == false); - REQUIRE(prev_val.any(0) == false); - } + REQUIRE(prev_val.any(-100) == false); + REQUIRE(prev_val.any(-1) == false); + REQUIRE(prev_val.any(0) == false); REQUIRE_THROWS( - caller.call("dac", {names[iPower], "-2"}, -1, PUT)); + caller.call("powerdac", {names[iPower], "-2"}, -1, PUT)); REQUIRE_THROWS( - caller.call("dac", {names[iPower], "-100"}, -1, PUT)); + caller.call("powerdac", {names[iPower], "-100"}, -1, PUT)); REQUIRE_THROWS( - caller.call("dac", {names[iPower], "-1"}, -1, PUT)); + caller.call("powerdac", {names[iPower], "-1"}, -1, PUT)); REQUIRE_THROWS( - caller.call("dac", {names[iPower], "0"}, -1, PUT)); + caller.call("powerdac", {names[iPower], "0"}, -1, PUT)); REQUIRE_THROWS( - caller.call("dac", {names[iPower], "4096"}, -1, PUT)); - // not mV + caller.call("powerdac", {names[iPower], "4096"}, -1, PUT)); + // dont need mV + REQUIRE_THROWS(caller.call( + "powerdac", {names[iPower], "1200", "mV"}, -1, PUT)); REQUIRE_THROWS( - caller.call("dac", {names[iPower], "1200"}, -1, PUT)); - REQUIRE_THROWS(caller.call("dac", {names[iPower]}, -1, GET)); + caller.call("powerdac", {names[iPower], "mV"}, -1, GET)); // min if (names[iPower] == "v_io") REQUIRE_THROWS(caller.call( - "dac", {names[iPower], "1199", "mV"}, -1, PUT)); + "powerdac", {names[iPower], "1199"}, -1, PUT)); else { if (det_type == defs::XILINX_CHIPTESTBOARD) { REQUIRE_THROWS(caller.call( - "dac", {names[iPower], "1040", "mV"}, -1, PUT)); + "powerdac", {names[iPower], "1040"}, -1, PUT)); } else { REQUIRE_THROWS(caller.call( - "dac", {names[iPower], "635", "mV"}, -1, PUT)); + "powerdac", {names[iPower], "635"}, -1, PUT)); } } // max if (det_type == defs::XILINX_CHIPTESTBOARD) { REQUIRE_THROWS(caller.call( - "dac", {names[iPower], "2662", "mV"}, -1, PUT)); + "powerdac", {names[iPower], "2662"}, -1, PUT)); } else { REQUIRE_THROWS(caller.call( - "dac", {names[iPower], "2469", "mV"}, -1, PUT)); + "powerdac", {names[iPower], "2469"}, -1, PUT)); } { std::ostringstream oss1, oss2; - caller.call("dac", {names[iPower], "1200", "mV"}, -1, PUT, + caller.call("powerdac", {names[iPower], "1200"}, -1, PUT, oss1); - REQUIRE(oss1.str() == - "dac " + names[iPower] + " 1200 mV\n"); - caller.call("dac", {names[iPower], "mV"}, -1, GET, oss2); - REQUIRE(oss2.str() == - "dac " + names[iPower] + " 1200 mV\n"); + REQUIRE(oss1.str() == "dac " + names[iPower] + " 1200\n"); + caller.call("powerdac", {names[iPower]}, -1, GET, oss2); + REQUIRE(oss2.str() == "dac " + names[iPower] + " 1200\n"); } { // power name det.setPowerName(indices[iPower], "pwrname_" + names[iPower]); std::ostringstream oss1, oss2; - caller.call("dac", - {"pwrname_" + names[iPower], "1200", "mV"}, -1, - PUT, oss1); + caller.call("powerdac", + {"pwrname_" + names[iPower], "1200"}, -1, PUT, + oss1); REQUIRE(oss1.str() == - "dac pwrname_" + names[iPower] + " 1200 mV\n"); - caller.call("dac", {"pwrname_" + names[iPower], "mV"}, -1, + "dac pwrname_" + names[iPower] + " 1200\n"); + caller.call("powerdac", {"pwrname_" + names[iPower]}, -1, GET, oss2); REQUIRE(oss2.str() == "dac pwrname_" + names[iPower] + " 1200 mV\n"); } - // throw if trying to set dac when power is on + // trying to set dac when power is on { det.setPowerEnabled(std::vector{indices[iPower]}, true); - REQUIRE_THROWS(caller.call( - "dac", {names[iPower], "1200", "mV"}, -1, PUT)); + std::ostringstream oss1, oss2; + caller.call("powerdac", {names[iPower], "1200"}, -1, PUT, + oss1); + REQUIRE(oss1.str() == "dac " + names[iPower] + " 1200\n"); + caller.call("powerdac", {names[iPower]}, -1, GET, oss2); + REQUIRE(oss2.str() == "dac " + names[iPower] + " 1200\n"); } - // Reset all dacs to previous value - for (int imod = 0; imod != det.size(); ++imod) { - det.setPowerEnabled(std::vector{indices[iPower]}, false, - {imod}); - det.setDAC(indices[iPower], prev_val[imod], true, {imod}); - det.setPowerEnabled(std::vector{indices[iPower]}, - prev_val_power[imod], {imod}); - } - } - // test get of vchip - if (det_type == defs::CHIPTESTBOARD) { - REQUIRE_THROWS( - caller.call("dac", {"v_chip", "1700", "mV"}, -1, PUT)); - REQUIRE_THROWS(caller.call("dac", {"v_chip"}, -1, GET)); - REQUIRE_NOTHROW(caller.call("dac", {"v_chip", "mV"}, -1, GET)); - } else { - REQUIRE_THROWS(caller.call("dac", {"v_chip", "mV"}, -1, GET)); + // Reset all dacs to previous value + det.setPowerDAC(indices[iPower], prev_val, true); + det.setPowerEnabled(std::vector{indices[iPower]}, + prev_val_power); } } + + } else { + REQUIRE_THROWS(caller.call("powerdac", {"v_a"}, -1, GET)); } } @@ -1178,9 +1191,6 @@ TEST_CASE("v_abcd", "[.detectorintegration]") { // removed in favor of "dac" and "power" commands std::vector cmds{"v_a", "v_b", "v_c", "v_d", "v_io", "v_chip"}; - std::vector indices{defs::V_POWER_A, defs::V_POWER_B, - defs::V_POWER_C, defs::V_POWER_D, - defs::V_POWER_IO, defs::V_POWER_CHIP}; for (size_t i = 0; i < cmds.size(); ++i) { try { @@ -1201,15 +1211,11 @@ TEST_CASE("power", "[.detectorintegration]") { det_type == defs::XILINX_CHIPTESTBOARD) { std::vector cmds{"v_a", "v_b", "v_c", "v_d", "v_io"}; - std::vector indices{defs::V_POWER_A, defs::V_POWER_B, - defs::V_POWER_C, defs::V_POWER_D, - defs::V_POWER_IO}; - + auto indices = det->getPowerList(); std::vector prev_val(cmds.size()); for (size_t iPower = 0; iPower < cmds.size(); ++iPower) { prev_val[iPower] = det.isPowerEnabled(indices[iPower]) .tsquash("Inconsistent power enabled state"); - det.setPowerEnabled(std::vector{indices[iPower]}, false); } REQUIRE_THROWS(caller.call("power", {"vrandom"}, -1, GET)); diff --git a/slsSupportLib/include/sls/ToString.h b/slsSupportLib/include/sls/ToString.h index c7525a156..777a98207 100644 --- a/slsSupportLib/include/sls/ToString.h +++ b/slsSupportLib/include/sls/ToString.h @@ -37,6 +37,8 @@ std::string ToString(const defs::externalSignalFlag s); std::string ToString(const defs::readoutMode s); std::string ToString(const defs::dacIndex s); std::string ToString(const std::vector &vec); +std::string ToString(const defs::powerIndex s); +std::string ToString(const std::vector &vec); std::string ToString(const defs::burstMode s); std::string ToString(const defs::timingSourceType s); std::string ToString(const defs::M3_GainCaps s); @@ -317,6 +319,7 @@ template <> defs::fileFormat StringTo(const std::string &s); template <> defs::externalSignalFlag StringTo(const std::string &s); template <> defs::readoutMode StringTo(const std::string &s); template <> defs::dacIndex StringTo(const std::string &s); +template <> defs::powerIndex StringTo(const std::string &s); template <> defs::burstMode StringTo(const std::string &s); template <> defs::timingSourceType StringTo(const std::string &s); template <> defs::M3_GainCaps StringTo(const std::string &s); diff --git a/slsSupportLib/include/sls/sls_detector_defs.h b/slsSupportLib/include/sls/sls_detector_defs.h index 9e0c80187..f8b4b7877 100644 --- a/slsSupportLib/include/sls/sls_detector_defs.h +++ b/slsSupportLib/include/sls/sls_detector_defs.h @@ -396,18 +396,6 @@ typedef struct { TEMPERATURE_FPGA2, TEMPERATURE_FPGA3, TRIMBIT_SCAN, - V_POWER_A = 100, - V_POWER_B = 101, - V_POWER_C = 102, - V_POWER_D = 103, - V_POWER_IO = 104, - V_POWER_CHIP = 105, - I_POWER_A = 106, - I_POWER_B = 107, - I_POWER_C = 108, - I_POWER_D = 109, - I_POWER_IO = 110, - V_LIMIT = 111, SLOW_ADC0 = 1000, SLOW_ADC1, SLOW_ADC2, @@ -419,6 +407,20 @@ typedef struct { SLOW_ADC_TEMP }; + enum powerIndex { + V_POWER_A, + V_POWER_B, + V_POWER_C, + V_POWER_D, + V_POWER_IO, + V_POWER_CHIP, + I_POWER_A, + I_POWER_B, + I_POWER_C, + I_POWER_D, + I_POWER_IO + }; + /** detector settings indexes */ diff --git a/slsSupportLib/src/ToString.cpp b/slsSupportLib/src/ToString.cpp index 8ff889117..f8ac4c684 100644 --- a/slsSupportLib/src/ToString.cpp +++ b/slsSupportLib/src/ToString.cpp @@ -519,18 +519,6 @@ std::string ToString(const defs::dacIndex s) { return std::string("vipre_cds"); case defs::IBIAS_SFP: return std::string("ibias_sfp"); - case defs::V_POWER_A: - return std::string("v_a"); - case defs::V_POWER_B: - return std::string("v_b"); - case defs::V_POWER_C: - return std::string("v_c"); - case defs::V_POWER_D: - return std::string("v_d"); - case defs::V_POWER_IO: - return std::string("v_io"); - case defs::V_POWER_CHIP: - return std::string("v_chip"); case defs::TRIMBIT_SCAN: return std::string("trimbits"); case defs::HIGH_VOLTAGE: @@ -575,6 +563,38 @@ std::string ToString(const std::vector &vec) { return os.str(); } +std::string ToString(const defs::powerIndex s) { + switch (s) { + case defs::V_POWER_A: + return std::string("v_a"); + case defs::V_POWER_B: + return std::string("v_b"); + case defs::V_POWER_C: + return std::string("v_c"); + case defs::V_POWER_D: + return std::string("v_d"); + case defs::V_POWER_IO: + return std::string("v_io"); + case defs::V_POWER_CHIP: + return std::string("v_chip"); + default: + return std::string("Unknown"); + } +} + +std::string ToString(const std::vector &vec) { + std::ostringstream os; + os << '['; + if (!vec.empty()) { + auto it = vec.begin(); + os << ToString(*it++); + while (it != vec.end()) + os << ", " << ToString(*it++); + } + os << ']'; + return os.str(); +} + std::string ToString(const defs::burstMode s) { switch (s) { case defs::BURST_INTERNAL: @@ -1012,18 +1032,6 @@ template <> defs::dacIndex StringTo(const std::string &s) { return defs::VIPRE_CDS; if (s == "ibias_sfp") return defs::IBIAS_SFP; - if (s == "v_a") - return defs::V_POWER_A; - if (s == "v_b") - return defs::V_POWER_B; - if (s == "v_c") - return defs::V_POWER_C; - if (s == "v_d") - return defs::V_POWER_D; - if (s == "v_io") - return defs::V_POWER_IO; - if (s == "v_chip") - return defs::V_POWER_CHIP; if (s == "trimbits") return defs::TRIMBIT_SCAN; if (s == "highvoltage") @@ -1053,6 +1061,22 @@ template <> defs::dacIndex StringTo(const std::string &s) { throw RuntimeError("Unknown dac Index " + s); } +template <> defs::powerIndex StringTo(const std::string &s) { + if (s == "v_a") + return defs::V_POWER_A; + if (s == "v_b") + return defs::V_POWER_B; + if (s == "v_c") + return defs::V_POWER_C; + if (s == "v_d") + return defs::V_POWER_D; + if (s == "v_io") + return defs::V_POWER_IO; + if (s == "v_chip") + return defs::V_POWER_CHIP; + throw RuntimeError("Unknown power Index " + s); +} + template <> defs::burstMode StringTo(const std::string &s) { if (s == "burst_internal") return defs::BURST_INTERNAL;