diff --git a/slsDetectorSoftware/include/CmdProxy.h b/slsDetectorSoftware/include/CmdProxy.h index 836e7d9fb..56f001258 100644 --- a/slsDetectorSoftware/include/CmdProxy.h +++ b/slsDetectorSoftware/include/CmdProxy.h @@ -761,6 +761,11 @@ class CmdProxy { {"stopport", &CmdProxy::stopport}, {"lock", &CmdProxy::lock}, {"lastclient", &CmdProxy::lastclient}, + {"execcommand", &CmdProxy::ExecuteCommand}, + {"nframes", &CmdProxy::nframes}, + {"now", &CmdProxy::now}, + {"timestamp", &CmdProxy::timestamp}, + {"user", &CmdProxy::UserDetails}, @@ -838,8 +843,8 @@ class CmdProxy { std::string AdcRegister(int action); std::string BitOperations(int action); /* Insignificant */ - - + std::string ExecuteCommand(int action); + std::string UserDetails(int action); /* configuration */ @@ -1347,6 +1352,15 @@ class CmdProxy { GET_COMMAND(lastclient, getLastClientIP, "\n\tClient IP Address that last communicated with the detector."); + GET_COMMAND(nframes, getNumberOfFramesFromStart, + "\n\t[Gotthard][Jungfrau][CTB] Number of frames from start run control."); + + TIME_GET_COMMAND(now, getActualTime, + "[(optional unit) ns|us|ms|s]\n\t[Jungfrau][CTB] Time from detector start up."); + + TIME_GET_COMMAND(timestamp, getMeasurementTime, + "[(optional unit) ns|us|ms|s]\n\t[Jungfrau][CTB] Timestamp at a frame start."); + diff --git a/slsDetectorSoftware/include/slsDetectorCommand.h b/slsDetectorSoftware/include/slsDetectorCommand.h index 062bc1e04..11c3262ed 100755 --- a/slsDetectorSoftware/include/slsDetectorCommand.h +++ b/slsDetectorSoftware/include/slsDetectorCommand.h @@ -44,14 +44,12 @@ class slsDetectorCommand : public virtual slsDetectorDefs { static std::string helpData(int action); static std::string helpFree(int action); static std::string helpHostname(int action); - static std::string helpUser(int action); static std::string helpExitServer(int action); static std::string helpThreaded(int action); static std::string helpSettings(int action); static std::string helpSN(int action); static std::string helpDigiTest(int action); static std::string helpDAC(int action); - static std::string helpTimeLeft(int action); static std::string helpConfiguration(int action); static std::string helpReceiver(int action); @@ -64,14 +62,12 @@ class slsDetectorCommand : public virtual slsDetectorDefs { std::string cmdData(int narg, const char * const args[], int action, int detPos = -1); std::string cmdFree(int narg, const char * const args[], int action, int detPos = -1); std::string cmdHostname(int narg, const char * const args[], int action, int detPos = -1); - std::string cmdUser(int narg, const char * const args[], int action, int detPos = -1); std::string cmdHelp(int narg, const char * const args[], int action, int detPos = -1); std::string cmdExitServer(int narg, const char * const args[], int action, int detPos = -1); std::string cmdSettings(int narg, const char * const args[], int action, int detPos = -1); std::string cmdSN(int narg, const char * const args[], int action, int detPos = -1); std::string cmdDigiTest(int narg, const char * const args[], int action, int detPos = -1); std::string cmdDAC(int narg, const char * const args[], int action, int detPos = -1); - std::string cmdTimeLeft(int narg, const char * const args[], int action, int detPos = -1); std::string cmdConfiguration(int narg, const char * const args[], int action, int detPos = -1); std::string cmdReceiver(int narg, const char * const args[], int action, int detPos = -1); diff --git a/slsDetectorSoftware/src/CmdProxy.cpp b/slsDetectorSoftware/src/CmdProxy.cpp index 18349a78c..76dc84280 100644 --- a/slsDetectorSoftware/src/CmdProxy.cpp +++ b/slsDetectorSoftware/src/CmdProxy.cpp @@ -1467,6 +1467,45 @@ std::string CmdProxy::BitOperations(int action) { /* Insignificant */ +std::string CmdProxy::ExecuteCommand(int action) { + std::ostringstream os; + os << cmd << ' '; + if (action == defs::HELP_ACTION) { + os << "[command]\n\tExecutes command on detector server." << '\n'; + } else if (action == defs::GET_ACTION) { + throw sls::RuntimeError("Cannot get."); + } else if (action == defs::PUT_ACTION) { + if (args.size() != 1) { + WrongNumberOfParameters(1); + } + det->executeCommand(args[0], {det_id}); + os << "successful" << '\n'; + } else { + throw sls::RuntimeError("Unknown action"); + } + return os.str(); +} +std::string CmdProxy::UserDetails(int action) { + std::ostringstream os; + os << cmd << ' '; + if (action == defs::HELP_ACTION) { + os << "\n\tUser details from shared memory." << '\n'; + } else if (action == defs::GET_ACTION) { + if (det_id != -1) { + throw sls::RuntimeError("Cannot execute this at module level"); + } + if (args.size() != 0) { + WrongNumberOfParameters(0); + } + auto t = det->getUserDetails(); + os << t << '\n'; + } else if (action == defs::PUT_ACTION) { + throw sls::RuntimeError("Cannot put."); + } else { + throw sls::RuntimeError("Unknown action"); + } + return os.str(); +} } // namespace sls \ No newline at end of file diff --git a/slsDetectorSoftware/src/slsDetectorCommand.cpp b/slsDetectorSoftware/src/slsDetectorCommand.cpp index b25adbac1..c8b6f1bed 100755 --- a/slsDetectorSoftware/src/slsDetectorCommand.cpp +++ b/slsDetectorSoftware/src/slsDetectorCommand.cpp @@ -108,13 +108,6 @@ slsDetectorCommand::slsDetectorCommand(multiSlsDetector *det) { descrToFuncMap[i].m_pFuncPtr = &slsDetectorCommand::cmdExitServer; ++i; - /*! \page test - - execcommand Executes a command on the detector server. Don't use it!!!! - */ - descrToFuncMap[i].m_pFuncName = "execcommand"; - descrToFuncMap[i].m_pFuncPtr = &slsDetectorCommand::cmdExitServer; - ++i; - /*! \page test - rx_execcommand Executes a command on the receiver server. Don't use it!!!! */ @@ -180,14 +173,7 @@ slsDetectorCommand::slsDetectorCommand(multiSlsDetector *det) { ++i; - /*! \page config - - user \c Returns user details from shared memory. Only allowed at multi detector level. Cannot put. \c (string) - */ - descrToFuncMap[i].m_pFuncName = "user"; - descrToFuncMap[i].m_pFuncPtr = &slsDetectorCommand::cmdUser; - ++i; - - /*! \page config + /*! \page config \section configstatus Status commands to configure detector status */ @@ -239,26 +225,6 @@ slsDetectorCommand::slsDetectorCommand(multiSlsDetector *det) { /* read only timers */ - /*! \page timing - - now Getting actual time of the detector from start. For Jungfrau only. Only get! - */ - descrToFuncMap[i].m_pFuncName = "now"; - descrToFuncMap[i].m_pFuncPtr = &slsDetectorCommand::cmdTimeLeft; - ++i; - - /*! \page timing - - timestamp Getting timestamp. For Jungfrau only. Only get! - */ - descrToFuncMap[i].m_pFuncName = "timestamp"; - descrToFuncMap[i].m_pFuncPtr = &slsDetectorCommand::cmdTimeLeft; - ++i; - - /*! \page timing - - nframes Frames from start run control. Only Jungfrau. Only get! \c Returns \c (long long int) - */ - descrToFuncMap[i].m_pFuncName = "nframes"; - descrToFuncMap[i].m_pFuncPtr = &slsDetectorCommand::cmdTimeLeft; - ++i; /* speed */ @@ -1040,35 +1006,6 @@ std::string slsDetectorCommand::helpHostname(int action) { return os.str(); } -std::string slsDetectorCommand::cmdUser(int narg, const char * const args[], int action, int detPos) { -#ifdef VERBOSE - std::cout << std::string("Executing command ") + std::string(args[0]) + std::string(" ( ") + cmd + std::string(" )\n"); -#endif - - if (action == HELP_ACTION) { - return helpHostname(HELP_ACTION); - } - if (action == PUT_ACTION) { - return std::string("cannot put"); - } - if (detPos >= 0) { - return std::string("Wrong usage - getting user details only from " - "multiDetector level"); - } - return myDet->getUserDetails(); -} - -std::string slsDetectorCommand::helpUser(int action) { - std::ostringstream os; - if (action == GET_ACTION || action == HELP_ACTION) { - os << std::string("user \t returns user details from shared memory without updating shared memory. " - "Only allowed at multi detector level.\n"); - } - if (action == PUT_ACTION || action == HELP_ACTION) { - os << std::string("user \t cannot put\n"); - } - return os.str(); -} std::string slsDetectorCommand::cmdHelp(int narg, const char * const args[], int action, int detPos) { #ifdef VERBOSE @@ -1099,9 +1036,6 @@ std::string slsDetectorCommand::cmdExitServer(int narg, const char * const args[ myDet->exitReceiver(detPos); return std::string("Receiver shut down\n"); - } else if (cmd == "execcommand") { - myDet->execCommand(std::string(args[1]), detPos); - return std::string("Command executed successfully\n"); } else if (cmd == "rx_execcommand") { myDet->execReceiverCommand(std::string(args[1]), detPos); @@ -1116,7 +1050,6 @@ std::string slsDetectorCommand::helpExitServer(int action) { std::ostringstream os; os << std::string("exitserver \t shuts down all the detector servers. Don't use it!!!!\n"); os << std::string("rx_exit \t shuts down all the receiver servers.\n"); - os << std::string("execcommand \t executes command in detector server. Don't use it if you do not know what you are doing.\n"); os << std::string("rx_execcommand \t executes command in receiver server. Don't use it if you do not know what you are doing.\n"); return os.str(); } @@ -1607,51 +1540,6 @@ std::string slsDetectorCommand::helpDAC(int action) { -std::string slsDetectorCommand::cmdTimeLeft(int narg, const char * const args[], int action, int detPos) { - timerIndex index; - int64_t ret; - double rval; - - char answer[1000]; - - if (action == HELP_ACTION) - return helpTimeLeft(action); - - if (cmd == "now") - index = ACTUAL_TIME; - else if (cmd == "timestamp") - index = MEASUREMENT_TIME; - else if (cmd == "nframes") - index = FRAMES_FROM_START; - else - return std::string("could not decode timer ") + cmd; - - if (action == PUT_ACTION) { - return std::string("cannot set ") + std::string(args[1]); - } - - - ret = myDet->getTimeLeft(index, detPos); - - if ((ret != -1) && (index == ACTUAL_TIME || index == MEASUREMENT_TIME)) { - rval = (double)ret * 1E-9; - sprintf(answer,"%0.9f",rval); - } else { - sprintf(answer,"%lld",(long long int)ret); - } - - return std::string(answer); -} - -std::string slsDetectorCommand::helpTimeLeft(int action) { - - std::ostringstream os; - if (action == GET_ACTION || action == HELP_ACTION) { - os << std::endl; - } - return os.str(); -} - std::string slsDetectorCommand::cmdConfiguration(int narg, const char * const args[], int action, int detPos) { diff --git a/slsDetectorSoftware/tests/test-multiSlsDetectorClient.cpp b/slsDetectorSoftware/tests/test-multiSlsDetectorClient.cpp index 17a441118..b56c2a6a9 100644 --- a/slsDetectorSoftware/tests/test-multiSlsDetectorClient.cpp +++ b/slsDetectorSoftware/tests/test-multiSlsDetectorClient.cpp @@ -9,6 +9,41 @@ auto GET = slsDetectorDefs::GET_ACTION; auto PUT = slsDetectorDefs::PUT_ACTION; + +TEST_CASE("user", "[.cmd]") { + REQUIRE_NOTHROW(multiSlsDetectorClient("user", GET)); + REQUIRE_THROWS(multiSlsDetectorClient("user bla", PUT)); +} + +TEST_CASE("now", "[.cmd]") { + if (test::type == slsDetectorDefs::JUNGFRAU || test::type == slsDetectorDefs::CHIPTESTBOARD) { + REQUIRE_NOTHROW(multiSlsDetectorClient("now", GET)); + } else { + REQUIRE_THROWS(multiSlsDetectorClient("now", GET)); + } +} + +TEST_CASE("timestamp", "[.cmd]") { + if (test::type == slsDetectorDefs::JUNGFRAU || test::type == slsDetectorDefs::CHIPTESTBOARD) { + REQUIRE_NOTHROW(multiSlsDetectorClient("timestamp", GET)); + } else { + REQUIRE_THROWS(multiSlsDetectorClient("timestamp", GET)); + } +} + +TEST_CASE("nframes", "[.cmd]") { + if (test::type == slsDetectorDefs::JUNGFRAU || test::type == slsDetectorDefs::CHIPTESTBOARD || test::type == slsDetectorDefs::GOTTHARD) { + REQUIRE_NOTHROW(multiSlsDetectorClient("nframes", GET)); + } else { + REQUIRE_THROWS(multiSlsDetectorClient("nframes", GET)); + } +} + + +TEST_CASE("execcommand", "[.cmd]") { + REQUIRE_NOTHROW(multiSlsDetectorClient("execcommand ls", PUT)); +} + TEST_CASE("port", "[.cmd]") { { std::ostringstream oss;