From bf25493de38465b46b2d6618a53e419efe7918da Mon Sep 17 00:00:00 2001 From: Dhanya Thattil Date: Fri, 13 Mar 2026 16:51:41 +0100 Subject: [PATCH] power all returns all --- slsDetectorSoftware/src/CallerSpecial.cpp | 68 +++++++++++++------ .../Caller/test-Caller-chiptestboard.cpp | 12 +++- 2 files changed, 60 insertions(+), 20 deletions(-) diff --git a/slsDetectorSoftware/src/CallerSpecial.cpp b/slsDetectorSoftware/src/CallerSpecial.cpp index 70d8004c2..a91ffffbd 100644 --- a/slsDetectorSoftware/src/CallerSpecial.cpp +++ b/slsDetectorSoftware/src/CallerSpecial.cpp @@ -1970,8 +1970,9 @@ std::string Caller::power(int action) { os << "[list of power names] [on|off]\n\t[Ctb][Xilinx Ctb] Enable or " "disable power rails. Power name can be v_a, v_b, v_c, v_d or " "v_io or any defines using 'powername'. If power name is set to " - "'all', the command applies to all 'powers'. Only one power can " - "be queried at a time." + "'all', the command applies to all 'powers'. When retrieving the " + "states of multiple power rails, they are queried sequentially " + "(one after another), not in parallel." << '\n'; return os.str(); } @@ -1983,27 +1984,56 @@ std::string Caller::power(int action) { "and Xilinx ChipTestBoard."); } - if (action == defs::GET_ACTION) { - if (args.size() != 1) { - WrongNumberOfParameters(1); + // 'all' argument + bool all = false; + if (std::find(args.begin(), args.end(), "all") != args.end()) { + all = true; + } + + // number of args + if (action == defs::GET_ACTION && args.size() != 1) + WrongNumberOfParameters(1); + if (all) { + if (action == defs::PUT_ACTION && args.size() != 2) { + WrongNumberOfParameters(2); + } + } else { + if (args.size() < 1 || args.size() > 6) + WrongNumberOfParameters(1); + } + + if (action == defs::GET_ACTION) { + if (!all) { + auto t = det->isPowerEnabled(parsePowerIndex(0), + std::vector{det_id}) + .tsquash("Inconsistent across modules"); + os << args[0] << ' ' << ToString(t, defs::OnOff) << '\n'; + } else { + // get each state and store in map + std::map m; + auto powerIndices = det->getPowerList(); + for (const auto &index : powerIndices) { + auto name = ToString(index); + auto state = + det->isPowerEnabled(index, std::vector{det_id}) + .tsquash("Inconsistent across modules"); + m[name] = ToString(state, defs::OnOff); + } + if (m.empty()) { + throw RuntimeError("Could not get power states."); + } + auto first = m.begin()->second; + // if all the same, print in short form, else print all states + if (std::all_of(m.begin(), m.end(), + [&](const auto &p) { return p.second == first; })) { + os << "all " << first << '\n'; + } else { + os << ToString(m) << '\n'; + } } - auto t = - det->isPowerEnabled(parsePowerIndex(0), std::vector{det_id}) - .tsquash("Inconsistent across modules"); - os << args[0] << ' ' << ToString(t, defs::OnOff) << '\n'; } else if (action == defs::PUT_ACTION) { - bool all = false; - if (std::find(args.begin(), args.end(), "all") != args.end()) { - if (args.size() != 2) - WrongNumberOfParameters(2); - all = true; - } - if (args.size() < 1 || args.size() > 6) { - WrongNumberOfParameters(1); - } - // enable arg std::string lastArg = args.back(); if (lastArg != "on" && lastArg != "off") { diff --git a/slsDetectorSoftware/tests/Caller/test-Caller-chiptestboard.cpp b/slsDetectorSoftware/tests/Caller/test-Caller-chiptestboard.cpp index 4c689c133..485ba2d47 100644 --- a/slsDetectorSoftware/tests/Caller/test-Caller-chiptestboard.cpp +++ b/slsDetectorSoftware/tests/Caller/test-Caller-chiptestboard.cpp @@ -1266,6 +1266,14 @@ TEST_CASE("power", "[.detectorintegration]") { REQUIRE(oss[6].str() == "power v_d on\n"); REQUIRE(oss[7].str() == "power v_io off\n"); } + // all + { + std::ostringstream oss; + caller.call("power", {"all"}, -1, GET, oss); + REQUIRE( + oss.str() == + "power {v_a: off, v_b: off, v_c: on, v_d: on, v_io: off}\n"); + } { // power on all caller.call("power", {"all", "on"}, -1, PUT); std::ostringstream oss1, oss2, oss3, oss4, oss5; @@ -1279,8 +1287,10 @@ TEST_CASE("power", "[.detectorintegration]") { REQUIRE(oss3.str() == "power v_c on\n"); REQUIRE(oss4.str() == "power v_d on\n"); REQUIRE(oss5.str() == "power v_io on\n"); + std::ostringstream oss; + caller.call("power", {"all"}, -1, GET, oss); + REQUIRE(oss.str() == "power all on\n"); } - REQUIRE_THROWS(caller.call("power", {"all"}, -1, GET)); for (size_t iPower = 0; iPower < cmds.size(); ++iPower) { det.setPowerEnabled(std::vector{indices[iPower]}, prev_val[iPower]); }