diff --git a/slsDetectorSoftware/include/CmdProxy.h b/slsDetectorSoftware/include/CmdProxy.h index 0a270058a..06c741e40 100644 --- a/slsDetectorSoftware/include/CmdProxy.h +++ b/slsDetectorSoftware/include/CmdProxy.h @@ -734,6 +734,8 @@ class CmdProxy { /* Moench */ {"rx_jsonaddheader", &CmdProxy::rx_jsonaddheader}, {"rx_jsonpara", &CmdProxy::JsonParameter}, + {"emin", &CmdProxy::MinMaxEnergyThreshold}, + {"emax", &CmdProxy::MinMaxEnergyThreshold}, @@ -801,6 +803,7 @@ class CmdProxy { std::string PatternWaitTime(int action); /* Moench */ std::string JsonParameter(int action); + std::string MinMaxEnergyThreshold(int action); @@ -1271,7 +1274,7 @@ class CmdProxy { /* Moench */ STRING_COMMAND(rx_jsonaddheader, getAdditionalJsonHeader, setAdditionalJsonHeader, - "[\"label1\":\"value1\"], [\"label2\":\"value2\"]\n\t[Moench] Additional json header to be streamd out from receiver via zmq. Default is empty. Use only if to be processed by an intermediate user process listening to receiver zmq packets."); + "[\"label1\":\"value1\"], [\"label2\":\"value2\"]\n\tAdditional json header to be streamd out from receiver via zmq. Default is empty. Use only if to be processed by an intermediate user process listening to receiver zmq packets."); diff --git a/slsDetectorSoftware/include/Detector.h b/slsDetectorSoftware/include/Detector.h index 3d8c367ec..cda942645 100644 --- a/slsDetectorSoftware/include/Detector.h +++ b/slsDetectorSoftware/include/Detector.h @@ -1096,13 +1096,13 @@ class Detector { Positions pos = {}); /** [Moench: -1 if unknown mode] */ - Result getFrameMode(Positions pos = {}) const; + Result getFrameMode(Positions pos = {}) const; /** [Moench] */ void setFrameMode(defs::frameModeType value, Positions pos = {}); /** [Moench: -1 if unknown mode] */ - Result getDetectorMode(Positions pos = {}) const; + Result getDetectorMode(Positions pos = {}) const; /** [Moench] */ void setDetectorMode(defs::detectorModeType value, Positions pos = {}); diff --git a/slsDetectorSoftware/src/CmdProxy.cpp b/slsDetectorSoftware/src/CmdProxy.cpp index df9b66937..c99116b34 100644 --- a/slsDetectorSoftware/src/CmdProxy.cpp +++ b/slsDetectorSoftware/src/CmdProxy.cpp @@ -1246,7 +1246,7 @@ std::string CmdProxy::JsonParameter(int action) { std::ostringstream os; os << cmd << ' '; if (action == defs::HELP_ACTION) { - os << "[key1] [value1]\n\t[Moench] Additional json header parameter streamed out from receiver. This is same as calling rx_jsonaddheader \"key\":\"value1\"" << '\n'; + os << "[key1] [value1]\n\tAdditional json header parameter streamed out from receiver. If empty in a get, then no parameter found. This is same as calling rx_jsonaddheader \"key\":\"value1\"." << '\n'; } else if (action == defs::GET_ACTION) { if (args.size() != 1) { WrongNumberOfParameters(1); @@ -1265,5 +1265,35 @@ std::string CmdProxy::JsonParameter(int action) { return os.str(); } +std::string CmdProxy::MinMaxEnergyThreshold(int action) { + std::ostringstream os; + os << cmd << ' '; + if (action == defs::HELP_ACTION) { + if (cmd == "emin") { + os << "[n_value]\n\t[Moench] Minimum energy threshold (soft setting) for processor." << '\n'; + } else if (cmd == "emin") { + os << "[n_value]\n\t[Moench] Maximum energy threshold (soft setting) for processor." << '\n'; + } else { + throw sls::RuntimeError("Unknown command, use list to list all commands"); + } + } else if (action == defs::GET_ACTION) { + if (args.size() != 0) { + WrongNumberOfParameters(0); + } + auto t = det->getDetectorMinMaxEnergyThreshold((cmd == "emax" ? true :false), {det_id}); + os << OutString(t) << '\n'; + } else if (action == defs::PUT_ACTION) { + if (args.size() != 1) { + WrongNumberOfParameters(1); + } + det->setDetectorMinMaxEnergyThreshold((cmd == "emax" ? true : false), std::stoi(args[0]), {det_id}); + os << args.front() << '\n'; + } else { + throw sls::RuntimeError("Unknown action"); + } + return os.str(); +} + + } // namespace sls \ No newline at end of file diff --git a/slsDetectorSoftware/src/Detector.cpp b/slsDetectorSoftware/src/Detector.cpp index c00a03929..0746bb4ef 100644 --- a/slsDetectorSoftware/src/Detector.cpp +++ b/slsDetectorSoftware/src/Detector.cpp @@ -1420,10 +1420,10 @@ void Detector::setDetectorMinMaxEnergyThreshold(const bool isEmax, isEmax ? "emax" : "emin", std::to_string(value)); } -Result Detector::getFrameMode(Positions pos) const { +Result Detector::getFrameMode(Positions pos) const { auto res = pimpl->Parallel(&slsDetector::getAdditionalJsonParameter, pos, "frameMode"); - Result intResult(res.size()); + Result intResult(res.size()); try { for (unsigned int i = 0; i < res.size(); ++i) { intResult[i] = defs::getFrameModeType(res[i]); @@ -1440,10 +1440,10 @@ void Detector::setFrameMode(defs::frameModeType value, Positions pos) { defs::getFrameModeType(value)); } -Result Detector::getDetectorMode(Positions pos) const { +Result Detector::getDetectorMode(Positions pos) const { auto res = pimpl->Parallel(&slsDetector::getAdditionalJsonParameter, pos, "detectorMode"); - Result intResult(res.size()); + Result intResult(res.size()); try { for (unsigned int i = 0; i < res.size(); ++i) { intResult[i] = defs::getDetectorModeType(res[i]); diff --git a/slsDetectorSoftware/src/slsDetectorCommand.cpp b/slsDetectorSoftware/src/slsDetectorCommand.cpp index 384563b2a..a89f95fa7 100755 --- a/slsDetectorSoftware/src/slsDetectorCommand.cpp +++ b/slsDetectorSoftware/src/slsDetectorCommand.cpp @@ -929,13 +929,6 @@ slsDetectorCommand::slsDetectorCommand(multiSlsDetector *det) { descrToFuncMap[i].m_pFuncPtr = &slsDetectorCommand::cmdReceiver; ++i; - /*! \page receiver - - rx_jsonpara [k] [v] sets/gets value v for additional json header parameter k to be streamed out with the zmq from receiver. If empty, then no parameter found Use only if it needs to be processed by an intermediate process. \c Returns \c (string) - */ - descrToFuncMap[i].m_pFuncName = "rx_jsonpara"; - descrToFuncMap[i].m_pFuncPtr = &slsDetectorCommand::cmdReceiver; - i++; - /* pattern generator */ @@ -943,20 +936,6 @@ slsDetectorCommand::slsDetectorCommand(multiSlsDetector *det) { Commands specific for the chiptest board or moench */ - /*! \page prototype - - emin [i] Sets/gets detector minimum energy threshold for Moench (soft setting in processor) - */ - descrToFuncMap[i].m_pFuncName = "emin"; - descrToFuncMap[i].m_pFuncPtr = &slsDetectorCommand::cmdProcessor; - ++i; - - /*! \page prototype - - emax [i] Sets/gets detector maximum energy threshold for Moench (soft setting in processor) - */ - descrToFuncMap[i].m_pFuncName = "emax"; - descrToFuncMap[i].m_pFuncPtr = &slsDetectorCommand::cmdProcessor; - ++i; - /*! \page prototype - framemode [i] Sets/gets frame mode for Moench (soft setting in processor). Options: pedestal, newpedestal, flatfield, newflatfield */ @@ -2066,12 +2045,6 @@ std::string slsDetectorCommand::cmdReceiver(int narg, const char * const args[], } } - else if (cmd == "rx_jsonpara") { - if (action == PUT_ACTION) { - myDet->setAdditionalJsonParameter(args[1], args[2], detPos); - } - return myDet->getAdditionalJsonParameter(args[1], detPos); - } return std::string("could not decode command"); } @@ -2081,12 +2054,10 @@ std::string slsDetectorCommand::helpReceiver(int action) { std::ostringstream os; if (action == PUT_ACTION || action == HELP_ACTION) { os << "resetframescaught [any value] \t resets frames caught by receiver" << std::endl; - os << "rx_jsonpara [k] [v]\n sets value to v for additional json header parameter k to be streamed out with the zmq from receiver." << std::endl; } if (action == GET_ACTION || action == HELP_ACTION) { os << "frameindex \t returns the current frame index of receiver(average for multi)" << std::endl; - os << "rx_jsonpara [k] \n gets value of additional json header parameter k to be streamed out with the zmq from receiver. If empty, then no parameter found." << std::endl; } return os.str(); @@ -2098,14 +2069,10 @@ std::string slsDetectorCommand::helpProcessor(int action) { std::ostringstream os; if (action == PUT_ACTION || action == HELP_ACTION) { - os << "emin [n] \t Sets detector minimum energy threshold to x for Moench (soft setting in processor)" << std::endl; - os << "emax [n] \t Sets detector maximum energy threshold to x for Moench (soft setting in processor)" << std::endl; os << "framemode [n] \t Sets frame mode for Moench (soft setting in processor). Options: pedestal, newpedestal, flatfield, newflatfield" << std::endl; os << "detectormode [n] \t Sets detector mode for Moench (soft setting in processor). Options: counting, interpolating, analog" << std::endl; } if (action == GET_ACTION || action == HELP_ACTION) { - os << "emin [n] \t Gets detector minimum energy threshold to x for Moench (soft setting in processor)" << std::endl; - os << "emax [n] \t Gets detector maximum energy threshold to x for Moench (soft setting in processor)" << std::endl; os << "framemode [n] \t Gets frame mode for Moench (soft setting in processor). Options: pedestal, newpedestal, flatfield, newflatfield" << std::endl; os << "detectormode [n] \t Gets detector mode for Moench (soft setting in processor). Options: counting, interpolating, analog" << std::endl; } @@ -2117,17 +2084,8 @@ std::string slsDetectorCommand::cmdProcessor(int narg, const char * const args[] return helpProcessor(action); - if (cmd == "emin" || cmd == "emax") { - if (action == PUT_ACTION) { - int ival = -1; - if(!sscanf(args[1],"%d",&ival)) - return std::string("cannot parse emin/emax value"); - myDet->setDetectorMinMaxEnergyThreshold((cmd == "emin" ? 0 : 1), ival, detPos); - } - return std::to_string(myDet->setDetectorMinMaxEnergyThreshold(0, -1, detPos)); - } - else if (cmd == "framemode") { + if (cmd == "framemode") { if (action == PUT_ACTION) { frameModeType ival = getFrameModeType(args[1]); if (ival == GET_FRAME_MODE) diff --git a/slsDetectorSoftware/tests/test-multiSlsDetectorClient.cpp b/slsDetectorSoftware/tests/test-multiSlsDetectorClient.cpp index 8eb0cea71..b659e9b0a 100644 --- a/slsDetectorSoftware/tests/test-multiSlsDetectorClient.cpp +++ b/slsDetectorSoftware/tests/test-multiSlsDetectorClient.cpp @@ -9,6 +9,26 @@ auto GET = slsDetectorDefs::GET_ACTION; auto PUT = slsDetectorDefs::PUT_ACTION; +TEST_CASE("emin", "[.cmd][.moench]") { + { + std::ostringstream oss; + REQUIRE_NOTHROW(multiSlsDetectorClient("emin 100", PUT, nullptr, oss)); + REQUIRE(oss.str() == "emin 100\n"); + } + { + std::ostringstream oss; + REQUIRE_NOTHROW(multiSlsDetectorClient("emax 200", PUT, nullptr, oss)); + REQUIRE(oss.str() == "emax 200\n"); + } + { + std::ostringstream oss; + REQUIRE_NOTHROW(multiSlsDetectorClient("rx_jsonpara emax", GET, nullptr, oss)); + REQUIRE(oss.str() == "rx_jsonpara 200\n"); + } + REQUIRE_NOTHROW(multiSlsDetectorClient("rx_jsonaddheader \"\"", PUT)); +} + + TEST_CASE("rx_jsonpara", "[.cmd][.moench]") { REQUIRE_NOTHROW(multiSlsDetectorClient("rx_jsonaddheader \"key1\":\"value1\"", PUT)); {