From 9a48d9b832714f9d7af7a6979dcfb3316c3b5b7a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Erik=20Fr=C3=B6jdh?= Date: Fri, 23 Aug 2019 17:39:41 +0200 Subject: [PATCH] Intcmd (#53) * migrated more * more --- slsDetectorSoftware/include/CmdProxy.h | 136 ++++++++++- slsDetectorSoftware/include/Detector.h | 2 +- .../include/slsDetectorCommand.h | 20 -- slsDetectorSoftware/src/CmdProxy.cpp | 58 +---- slsDetectorSoftware/src/Detector.cpp | 4 +- .../src/slsDetectorCommand.cpp | 225 ------------------ .../tests/test-multiSlsDetectorClient.cpp | 19 ++ 7 files changed, 158 insertions(+), 306 deletions(-) diff --git a/slsDetectorSoftware/include/CmdProxy.h b/slsDetectorSoftware/include/CmdProxy.h index 5cb19d19d..e9e26b225 100644 --- a/slsDetectorSoftware/include/CmdProxy.h +++ b/slsDetectorSoftware/include/CmdProxy.h @@ -1,12 +1,78 @@ #pragma once +#include "Detector.h" +#include "Result.h" +#include "sls_detector_exceptions.h" #include #include #include #include +/** Macro to make an integer command. + * CMDNAME name of the function that does the command + * GETFCN Detector function to get + * SETFCN Detector function to set + * CONV Function to convert from string to the correct integer type + * HLPSTR Help string for --help and docs + */ + +#define INTEGER_COMMAND(CMDNAME, GETFCN, SETFCN, CONV, HLPSTR) \ + std::string CMDNAME(const int action) { \ + std::ostringstream os; \ + os << cmd << ' '; \ + if (action == slsDetectorDefs::HELP_ACTION) \ + os << HLPSTR << '\n'; \ + else if (action == slsDetectorDefs::GET_ACTION) { \ + auto t = det->GETFCN({det_id}); \ + if (args.size() == 0) { \ + os << OutString(t) << '\n'; \ + } else { \ + WrongNumberOfParameters(2); \ + } \ + } else if (action == slsDetectorDefs::PUT_ACTION) { \ + if (args.size() == 1) { \ + auto val = CONV(args[0]); \ + det->SETFCN(val, {det_id}); \ + os << args.front() << '\n'; \ + } else { \ + WrongNumberOfParameters(1); \ + } \ + \ + } else { \ + throw sls::RuntimeError("Unknown action"); \ + } \ + return os.str(); \ + } + +#define INTEGER_COMMAND_NOID(CMDNAME, GETFCN, SETFCN, CONV, HLPSTR) \ + std::string CMDNAME(const int action) { \ + std::ostringstream os; \ + os << cmd << ' '; \ + if (action == slsDetectorDefs::HELP_ACTION) \ + os << HLPSTR << '\n'; \ + else if (action == slsDetectorDefs::GET_ACTION) { \ + auto t = det->GETFCN(); \ + if (args.size() == 0) { \ + os << OutString(t) << '\n'; \ + } else { \ + WrongNumberOfParameters(2); \ + } \ + } else if (action == slsDetectorDefs::PUT_ACTION) { \ + if (args.size() == 1) { \ + auto val = CONV(args[0]); \ + det->SETFCN(val); \ + os << args.front() << '\n'; \ + } else { \ + WrongNumberOfParameters(1); \ + } \ + \ + } else { \ + throw sls::RuntimeError("Unknown action"); \ + } \ + return os.str(); \ + } + namespace sls { -class Detector; class CmdProxy { public: @@ -27,9 +93,17 @@ class CmdProxy { std::vector args; int det_id{-1}; - template std::string OutString(const V &value); + template std::string OutString(const V &value) { + if (value.equal()) + return ToString(value.front()); + return ToString(value); + } template - std::string OutString(const V &value, const std::string &unit); + std::string OutString(const V &value, const std::string &unit) { + if (value.equal()) + return ToString(value.front(), unit); + return ToString(value, unit); + } using FunctionMap = std::map; using StringMap = std::map; @@ -39,8 +113,18 @@ class CmdProxy { {"exptime", &CmdProxy::Exptime}, {"period", &CmdProxy::Period}, {"subexptime", &CmdProxy::SubExptime}, - {"rx_fifodepth", &CmdProxy::RxFifoDepth}, - {"rx_silent", &CmdProxy::RxSilent}}; + {"frames", &CmdProxy::frames}, + {"fwrite", &CmdProxy::fwrite}, + {"fmaster", &CmdProxy::fmaster}, + {"foverwrite", &CmdProxy::foverwrite}, + {"findex", &CmdProxy::findex}, + {"rx_fifodepth", &CmdProxy::rx_fifodepth}, + {"rx_silent", &CmdProxy::rx_silent}, + {"rx_lock", &CmdProxy::rx_lock}, + {"lock", &CmdProxy::lock}, + {"rx_readfreq", &CmdProxy::rx_readfreq}, + {"rx_padding", &CmdProxy::rx_padding}, + {"rx_framesperfile", &CmdProxy::rx_framesperfile}}; StringMap depreciated_functions{{"r_readfreq", "rx_readfreq"}, {"r_padding", "rx_padding"}, @@ -69,8 +153,46 @@ class CmdProxy { std::string Period(int action); std::string Exptime(int action); std::string SubExptime(int action); - std::string RxFifoDepth(const int action); - std::string RxSilent(const int action); + + INTEGER_COMMAND( + rx_fifodepth, getRxFifoDepth, setRxFifoDepth, std::stoi, + "[n_frames]\n\tSet the number of frames in the receiver fifo"); + + INTEGER_COMMAND(rx_silent, getRxSilentMode, setRxSilentMode, std::stoi, + "[0, 1]\n\tSwitch on or off receiver text output"); + + INTEGER_COMMAND(rx_lock, getRxLock, setRxLock, std::stoi, + "[0, 1]\n\tLock receiver to one IP, 1: locks"); + + INTEGER_COMMAND(lock, getDetectorLock, setDetectorLock, std::stoi, + "[0, 1]\n\tLock detector to one IP, 1: locks"); + + INTEGER_COMMAND(rx_readfreq, getRxZmqFrequency, setRxZmqFrequency, + std::stoi, "[nth frame]\n\tStream out every nth frame"); + + INTEGER_COMMAND(rx_padding, getPartialFramesPadding, + setPartialFramesPadding, std::stoi, + "[0, 1]\n\tgets partial frames padding enable in the " + "receiver. 0 does not pad partial frames(fastest), 1 " + "(default) pads partial frames"); + INTEGER_COMMAND(rx_framesperfile, getFramesPerFile, setFramesPerFile, + std::stoi, "[n_frames]\n\tNumber of frames per file"); + + INTEGER_COMMAND_NOID(frames, getNumberOfFrames, setNumberOfFrames, + std::stol, + "[n_frames]\n\tNumber of frames per aquire"); + + INTEGER_COMMAND(fwrite, getFileWrite, setFileWrite, std::stoi, + "[0, 1]\n\tEnable or disable receiver file write"); + + INTEGER_COMMAND(fmaster, getMasterFileWrite, setMasterFileWrite, std::stoi, + "[0, 1]\n\tEnable or disable receiver master file"); + + INTEGER_COMMAND(foverwrite, getFileOverWrite, setFileOverWrite, std::stoi, + "[0, 1]\n\tEnable or disable file overwriting"); + + INTEGER_COMMAND(findex, getAcquisitionIndex, setAcquisitionIndex, std::stoi, + "[0, 1]\n\tFile index"); }; } // namespace sls diff --git a/slsDetectorSoftware/include/Detector.h b/slsDetectorSoftware/include/Detector.h index 679646a37..e74a07ed6 100644 --- a/slsDetectorSoftware/include/Detector.h +++ b/slsDetectorSoftware/include/Detector.h @@ -488,7 +488,7 @@ class Detector { */ void setFileNamePrefix(const std::string &fname, Positions pos = {}); - Result getAcquisitonIndex(Positions pos = {}) const; + Result getAcquisitionIndex(Positions pos = {}) const; void setAcquisitionIndex(int i, Positions pos = {}); diff --git a/slsDetectorSoftware/include/slsDetectorCommand.h b/slsDetectorSoftware/include/slsDetectorCommand.h index 053f716d3..c62e8a634 100755 --- a/slsDetectorSoftware/include/slsDetectorCommand.h +++ b/slsDetectorSoftware/include/slsDetectorCommand.h @@ -52,12 +52,10 @@ class slsDetectorCommand : public virtual slsDetectorDefs { static std::string helpTrimEn(int action); static std::string helpOutDir(int action); static std::string helpFileName(int action); - static std::string helpFileIndex(int action); static std::string helpRateCorr(int action); static std::string helpThreaded(int action); static std::string helpNetworkParameter(int action); static std::string helpPort(int action); - static std::string helpLock(int action); static std::string helpLastClient(int action); static std::string helpOnline(int action); static std::string helpConfigureMac(int action); @@ -76,26 +74,12 @@ class slsDetectorCommand : public virtual slsDetectorDefs { static std::string helpCounter(int action); static std::string helpADC(int action); static std::string helpTempControl(int action); - static std::string helpEnablefwrite(int action); - static std::string helpOverwrite(int action); static std::string helpReceiver(int action); static std::string helpPattern(int action); static std::string helpPulse(int action); static std::string helpProcessor(int action); - - - - - - - - - - private: - - multiSlsDetector *myDet; std::string cmdUnderDevelopment(int narg, const char * const args[], int action, int detPos = -1); @@ -113,11 +97,9 @@ class slsDetectorCommand : public virtual slsDetectorDefs { std::string cmdTrimEn(int narg, const char * const args[], int action, int detPos = -1); std::string cmdOutDir(int narg, const char * const args[], int action, int detPos = -1); std::string cmdFileName(int narg, const char * const args[], int action, int detPos = -1); - std::string cmdFileIndex(int narg, const char * const args[], int action, int detPos = -1); std::string cmdRateCorr(int narg, const char * const args[], int action, int detPos = -1); std::string cmdNetworkParameter(int narg, const char * const args[], int action, int detPos = -1); std::string cmdPort(int narg, const char * const args[], int action, int detPos = -1); - std::string cmdLock(int narg, const char * const args[], int action, int detPos = -1); std::string cmdLastClient(int narg, const char * const args[], int action, int detPos = -1); std::string cmdOnline(int narg, const char * const args[], int action, int detPos = -1); std::string cmdConfigureMac(int narg, const char * const args[], int action, int detPos = -1); @@ -136,8 +118,6 @@ class slsDetectorCommand : public virtual slsDetectorDefs { std::string cmdCounter(int narg, const char * const args[], int action, int detPos = -1); std::string cmdADC(int narg, const char * const args[], int action, int detPos = -1); std::string cmdTempControl(int narg, const char * const args[], int action, int detPos = -1); - std::string cmdEnablefwrite(int narg, const char * const args[], int action, int detPos = -1); - std::string cmdOverwrite(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); std::string cmdPattern(int narg, const char * const args[], int action, int detPos = -1); std::string cmdPulse(int narg, const char * const args[], int action, int detPos = -1); diff --git a/slsDetectorSoftware/src/CmdProxy.cpp b/slsDetectorSoftware/src/CmdProxy.cpp index f4d8b0a26..a18f7f497 100644 --- a/slsDetectorSoftware/src/CmdProxy.cpp +++ b/slsDetectorSoftware/src/CmdProxy.cpp @@ -1,20 +1,18 @@ #include "CmdProxy.h" -#include "Detector.h" -#include "Result.h" + + #include "TimeHelper.h" #include "ToString.h" #include "logger.h" #include "slsDetectorCommand.h" #include "sls_detector_defs.h" -#include "sls_detector_exceptions.h" + #include -#include #include +#include #include - - #define TIME_COMMAND(GETFCN, SETFCN, HLPSTR) \ std::ostringstream os; \ os << cmd << ' '; \ @@ -47,31 +45,7 @@ } \ return os.str(); -#define INTEGER_COMMAND(GETFCN, SETFCN, CONV, HLPSTR) \ - std::ostringstream os; \ - os << cmd << ' '; \ - if (action == slsDetectorDefs::HELP_ACTION) \ - os << HLPSTR << '\n'; \ - else if (action == slsDetectorDefs::GET_ACTION) { \ - auto t = det->GETFCN({det_id}); \ - if (args.size() == 0) { \ - os << OutString(t) << '\n'; \ - } else { \ - WrongNumberOfParameters(2); \ - } \ - } else if (action == slsDetectorDefs::PUT_ACTION) { \ - if (args.size() == 1) { \ - auto val = CONV(args[0]); \ - det->SETFCN(val, {det_id}); \ - os << args.front() << '\n'; \ - } else { \ - WrongNumberOfParameters(1); \ - } \ - \ - } else { \ - throw sls::RuntimeError("Unknown action"); \ - } \ - return os.str(); + namespace sls { @@ -139,17 +113,7 @@ void CmdProxy::WrongNumberOfParameters(size_t expected) { " parameter/s but got " + std::to_string(args.size()) + "\n"); } -template std::string CmdProxy::OutString(const V &value) { - if (value.equal()) - return ToString(value.front()); - return ToString(value); -} -template -std::string CmdProxy::OutString(const V &value, const std::string &unit) { - if (value.equal()) - return ToString(value.front(), unit); - return ToString(value, unit); -} + /************************************************ * * @@ -172,16 +136,8 @@ std::string CmdProxy::SubExptime(int action) { "exposure time of EIGER subframes"); } -std::string CmdProxy::RxFifoDepth(const int action) { - INTEGER_COMMAND( - getRxFifoDepth, setRxFifoDepth, std::stoi, - "[n_frames]\n\tSet the number of frames in the receiver fifo"); -} -std::string CmdProxy::RxSilent(const int action) { - INTEGER_COMMAND(getRxSilentMode, setRxSilentMode, std::stoi, - "[0, 1]\n\tSwitch on or off receiver text output"); -} + std::string CmdProxy::ListCommands(int action) { if (action == slsDetectorDefs::HELP_ACTION) diff --git a/slsDetectorSoftware/src/Detector.cpp b/slsDetectorSoftware/src/Detector.cpp index 566b00561..440d055db 100644 --- a/slsDetectorSoftware/src/Detector.cpp +++ b/slsDetectorSoftware/src/Detector.cpp @@ -578,7 +578,7 @@ void Detector::setFileNamePrefix(const std::string &fname, Positions pos) { pimpl->Parallel(&slsDetector::setFileName, pos, fname); } -Result Detector::getAcquisitonIndex(Positions pos) const { +Result Detector::getAcquisitionIndex(Positions pos) const { return pimpl->Parallel(&slsDetector::getFileIndex, pos); } @@ -631,7 +631,7 @@ void Detector::setRxZmqDataStream(bool enable, Positions pos) { } Result Detector::getRxZmqFrequency(Positions pos) const { - return pimpl->Parallel(&slsDetector::setReceiverStreamingTimer, pos, -1); + return pimpl->Parallel(&slsDetector::setReceiverStreamingFrequency, pos, -1); } void Detector::setRxZmqFrequency(int freq, Positions pos) { diff --git a/slsDetectorSoftware/src/slsDetectorCommand.cpp b/slsDetectorSoftware/src/slsDetectorCommand.cpp index 3441a39dd..5a980398c 100755 --- a/slsDetectorSoftware/src/slsDetectorCommand.cpp +++ b/slsDetectorSoftware/src/slsDetectorCommand.cpp @@ -548,12 +548,6 @@ slsDetectorCommand::slsDetectorCommand(multiSlsDetector *det) { descrToFuncMap[i].m_pFuncPtr = &slsDetectorCommand::cmdTimer; ++i; - /*! \page timing - - frames [i] sets/gets number of frames. If \c timing is not \c auto, then it is the number of frames per cycle/trigger. \c Returns \c (long long int) - */ - descrToFuncMap[i].m_pFuncName = "frames"; - descrToFuncMap[i].m_pFuncPtr = &slsDetectorCommand::cmdTimer; - ++i; /*! \page timing - startingfnum [i] sets/gets starting frame number for the next acquisition. Only for Jungfrau and Eiger. \c Returns \c (long long int) @@ -1481,27 +1475,6 @@ slsDetectorCommand::slsDetectorCommand(multiSlsDetector *det) { descrToFuncMap[i].m_pFuncPtr = &slsDetectorCommand::cmdFileName; ++i; - /*! \page output - - findex [i] Sets/gets the current file index. \c Returns \c (int) - */ - descrToFuncMap[i].m_pFuncName = "findex"; - descrToFuncMap[i].m_pFuncPtr = &slsDetectorCommand::cmdFileIndex; - ++i; - - /*! \page output - - fwrite [i] Enables/disables file writing. 1 enables, 0 disables. \c Returns \c (int) - */ - descrToFuncMap[i].m_pFuncName = "fwrite"; - descrToFuncMap[i].m_pFuncPtr = &slsDetectorCommand::cmdEnablefwrite; - ++i; - - /*! \page output - - foverwrite [i] enables(1) /disables(0) file overwriting. \c Returns \c (int) - */ - descrToFuncMap[i].m_pFuncName = "foverwrite"; - descrToFuncMap[i].m_pFuncPtr = &slsDetectorCommand::cmdOverwrite; - ++i; - /*! \page output - fformat [i] sets/gets the file format for data in receiver. Options: [binary, hdf5]. \c Returns \c (string) */ @@ -1509,13 +1482,6 @@ slsDetectorCommand::slsDetectorCommand(multiSlsDetector *det) { descrToFuncMap[i].m_pFuncPtr = &slsDetectorCommand::cmdFileName; ++i; - /*! \page output - - fmaster [i] sets/gets the master file write enable in receiver. \c Returns \c (int) - */ - descrToFuncMap[i].m_pFuncName = "fmaster"; - descrToFuncMap[i].m_pFuncPtr = &slsDetectorCommand::cmdEnablefwrite; - ++i; - /* communication configuration */ /*! \page network Network @@ -1715,13 +1681,6 @@ slsDetectorCommand::slsDetectorCommand(multiSlsDetector *det) { descrToFuncMap[i].m_pFuncPtr = &slsDetectorCommand::cmdPort; ++i; - /*! \page network - - lock [i] Locks/Unlocks the detector to communicate with this client. 1 locks, 0 unlocks. \c Returns \c (int) - */ - descrToFuncMap[i].m_pFuncName = "lock"; - descrToFuncMap[i].m_pFuncPtr = &slsDetectorCommand::cmdLock; - ++i; - /*! \page network - lastclient Gets the last client communicating with the detector. Cannot put!. \c Returns \c (string) */ @@ -1763,13 +1722,6 @@ slsDetectorCommand::slsDetectorCommand(multiSlsDetector *det) { descrToFuncMap[i].m_pFuncPtr = &slsDetectorCommand::cmdReceiver; ++i; - /*! \page receiver - - rx_lock [i] locks/unlocks the receiver to communicate with only this client. 1 locks, 0 unlocks. \c Returns \c (int) - */ - descrToFuncMap[i].m_pFuncName = "rx_lock"; - descrToFuncMap[i].m_pFuncPtr = &slsDetectorCommand::cmdLock; - ++i; - /*! \page receiver - rx_lastclient gets the last client communicating with the receiver. Only get! \c Returns \c (int) */ @@ -1777,14 +1729,6 @@ slsDetectorCommand::slsDetectorCommand(multiSlsDetector *det) { descrToFuncMap[i].m_pFuncPtr = &slsDetectorCommand::cmdLastClient; ++i; - /*! \page receiver - - rx_readfreq [i] sets/gets the stream frequency of data from receiver to client. i > 0 is the nth frame being streamed. 0 sets frequency to a default timer (200ms). Default: sends every frame \c Returns \c (int) - */ - descrToFuncMap[i].m_pFuncName = "rx_readfreq"; - descrToFuncMap[i].m_pFuncPtr = &slsDetectorCommand::cmdReceiver; - ++i; - - /*! \page receiver - rx_framesperfile [i] sets/gets the frames per file in receiver to i. 0 means infinite or all frames in a single file. \c Returns \c (int) */ @@ -1799,13 +1743,6 @@ slsDetectorCommand::slsDetectorCommand(multiSlsDetector *det) { descrToFuncMap[i].m_pFuncPtr = &slsDetectorCommand::cmdReceiver; ++i; - /*! \page receiver - - rx_padding sets/gets the frame padding in the receiver. 0 does not pad partial frames(fastest), 1 (default) pads partial frames. \c Returns \c (int) - */ - descrToFuncMap[i].m_pFuncName = "rx_padding"; - descrToFuncMap[i].m_pFuncPtr = &slsDetectorCommand::cmdReceiver; - ++i; - /*! \page receiver - rx_jsonaddheader [t] sets/gets additional json header to be streamed out with the zmq from receiver. Default is empty. \c t must be in the format "\"label1\":\"value1\",\"label2\":\"value2\"" etc. Use only if it needs to be processed by an intermediate process. \c Returns \c (string) */ @@ -2531,94 +2468,6 @@ std::string slsDetectorCommand::helpFileName(int action) { return os.str(); } -std::string slsDetectorCommand::cmdEnablefwrite(int narg, const char * const args[], int action, int detPos) { - - int i; - char ans[100]; - if (action == HELP_ACTION) { - return helpEnablefwrite(action); - } - if (cmd == "fwrite") { - if (action == PUT_ACTION) { - if (sscanf(args[1], "%d", &i)) - myDet->setFileWrite(i, detPos); - else - return std::string("could not decode enable file write"); - } - sprintf(ans, "%d", myDet->getFileWrite(detPos)); - return std::string(ans); - } - - else if (cmd == "fmaster") { - if (action == PUT_ACTION) { - if (sscanf(args[1], "%d", &i)) - myDet->setMasterFileWrite(i, detPos); - else - return std::string("could not decode master file enable"); - } - sprintf(ans, "%d", myDet->getMasterFileWrite(detPos)); - return std::string(ans); - } - - else return std::string("unknown command " + cmd); -} - -std::string slsDetectorCommand::helpEnablefwrite(int action) { - std::ostringstream os; - if (action == GET_ACTION || action == HELP_ACTION) { - os << std::string("fwrite \t When Enabled writes the data into the file\n"); - os << std::string("fmaster \t When Enabled writes the master file\n"); - } - if (action == PUT_ACTION || action == HELP_ACTION) { - os << std::string("fwrite i \t should be 1 or 0\n"); - os << std::string("fmaster i \t sets the master file write enable. should be 1 or 0\n"); - } - return os.str(); -} - -std::string slsDetectorCommand::cmdOverwrite(int narg, const char * const args[], int action, int detPos) { - int i; - char ans[100]; - if (action == HELP_ACTION) { - return helpOverwrite(action); - } - if (action == PUT_ACTION) { - if (sscanf(args[1], "%d", &i)) - myDet->setFileOverWrite(i, detPos); - else - return std::string("could not decode foverwrite"); - } - sprintf(ans, "%d", myDet->getFileOverWrite(detPos)); - return std::string(ans); -} - -std::string slsDetectorCommand::helpOverwrite(int action) { - std::ostringstream os; - if (action == GET_ACTION || action == HELP_ACTION) - os << std::string("foverwrite \t When Enabled overwrites files\n"); - if (action == PUT_ACTION || action == HELP_ACTION) - os << std::string("foverwrite i \t should be 1 or 0 or -1\n"); - return os.str(); -} - -std::string slsDetectorCommand::cmdFileIndex(int narg, const char * const args[], int action, int detPos) { - if (action == HELP_ACTION) { - return helpFileName(action); - } else if (action == PUT_ACTION) { - int i = std::stoi(args[1]); - myDet->setFileIndex(i, detPos); - } - return std::to_string(myDet->getFileIndex(detPos)); -} - -std::string slsDetectorCommand::helpFileIndex(int action) { - std::ostringstream os; - if (action == GET_ACTION || action == HELP_ACTION) - os << std::string("findex \t gets the file index for the next the data file\n"); - if (action == PUT_ACTION || action == HELP_ACTION) - os << std::string("findex i \t sets the fileindex for the next data file\n"); - return os.str(); -} std::string slsDetectorCommand::cmdRateCorr(int narg, const char * const args[], int action, int detPos) { @@ -3006,55 +2855,6 @@ std::string slsDetectorCommand::helpPort(int action) { return os.str(); } -std::string slsDetectorCommand::cmdLock(int narg, const char * const args[], int action, int detPos) { - - if (action == HELP_ACTION) - return helpLock(action); - - int val; //, ret; - char ans[1000]; - - if (cmd == "lock") { - if (action == PUT_ACTION) { - if (sscanf(args[1], "%d", &val)) - myDet->lockServer(val, detPos); - else - return std::string("could not lock status") + std::string(args[1]); - } - - sprintf(ans, "%d", myDet->lockServer(-1, detPos)); - } - - else if (cmd == "rx_lock") { - if (action == PUT_ACTION) { - if (sscanf(args[1], "%d", &val)) - myDet->lockReceiver(val, detPos); - else - return std::string("could not decode lock status") + std::string(args[1]); - } - sprintf(ans, "%d", myDet->lockReceiver(-1, detPos)); - } - - else - return std::string("could not decode command"); - - return std::string(ans); -} - -std::string slsDetectorCommand::helpLock(int action) { - - std::ostringstream os; - if (action == PUT_ACTION || action == HELP_ACTION) { - os << "lock i \n locks (1) or unlocks (0) the detector to communicate to this client" << std::endl; - os << "rx_lock i \n locks (1) or unlocks (0) the receiver to communicate to this client" << std::endl; - } - if (action == GET_ACTION || action == HELP_ACTION) { - os << "lock \n returns the detector lock status" << std::endl; - os << "rx_lock \n returns the receiver lock status" << std::endl; - } - return os.str(); -} - std::string slsDetectorCommand::cmdLastClient(int narg, const char * const args[], int action, int detPos) { if (action == HELP_ACTION) @@ -4232,8 +4032,6 @@ std::string slsDetectorCommand::cmdTimer(int narg, const char * const args[], in index = SUBFRAME_DEADTIME; else if (cmd == "delay") index = DELAY_AFTER_TRIGGER; - else if (cmd == "frames") - index = FRAME_NUMBER; else if (cmd == "cycles") index = CYCLES_NUMBER; // also does digital sample @@ -4860,18 +4658,7 @@ std::string slsDetectorCommand::cmdReceiver(int narg, const char * const args[], sprintf(answer, "%lu", myDet->getReceiverCurrentFrameIndex(detPos)); return std::string(answer); } - } else if (cmd == "rx_readfreq") { - if (action == PUT_ACTION) { - if (!sscanf(args[1], "%d", &ival)) - return std::string("Could not scan read frequency mode ") + std::string(args[1]); - if (ival >= 0) - myDet->setReceiverStreamingFrequency(ival, detPos); - } - sprintf(answer, "%d", myDet->setReceiverStreamingFrequency(-1, detPos)); - return std::string(answer); - } - else if (cmd == "tengiga") { if (action == PUT_ACTION) { if (!sscanf(args[1], "%d", &ival)) @@ -4906,18 +4693,6 @@ std::string slsDetectorCommand::cmdReceiver(int narg, const char * const args[], return myDet->getReceiverFrameDiscardPolicy(myDet->setReceiverFramesDiscardPolicy(GET_FRAME_DISCARD_POLICY, detPos)); } - else if (cmd == "rx_padding") { - if (action == PUT_ACTION) { - if (sscanf(args[1], "%d", &ival)) { - myDet->setPartialFramesPadding(ival, detPos); - } else - return std::string("could not scan receiver padding enable\n"); - } - memset(answer, 0, 100); - sprintf(answer, "%d", myDet->getPartialFramesPadding(detPos)); - return std::string(answer); - } - else if (cmd == "rx_jsonaddheader") { if (action == PUT_ACTION) { myDet->setAdditionalJsonHeader(args[1], detPos); diff --git a/slsDetectorSoftware/tests/test-multiSlsDetectorClient.cpp b/slsDetectorSoftware/tests/test-multiSlsDetectorClient.cpp index a4d744c91..c7dcd85a7 100644 --- a/slsDetectorSoftware/tests/test-multiSlsDetectorClient.cpp +++ b/slsDetectorSoftware/tests/test-multiSlsDetectorClient.cpp @@ -376,6 +376,25 @@ TEST_CASE("rx_lock", "[.cmd]") { } } +TEST_CASE("lock", "[.cmd]") { + { + std::ostringstream oss; + multiSlsDetectorClient("lock 1", PUT, nullptr, oss); + REQUIRE(oss.str() == "lock 1\n"); + } + { + std::ostringstream oss; + multiSlsDetectorClient("lock", GET, nullptr, oss); + REQUIRE(oss.str() == "lock 1\n"); + } + { + std::ostringstream oss; + multiSlsDetectorClient("lock 0", PUT, nullptr, oss); + REQUIRE(oss.str() == "lock 0\n"); + } +} + + TEST_CASE("rx_lastclient", "[.cmd]") { std::ostringstream oss;