diff --git a/slsDetectorSoftware/multiSlsDetector/multiSlsDetector.cpp b/slsDetectorSoftware/multiSlsDetector/multiSlsDetector.cpp index 934ff5ac1..0b88fc87a 100644 --- a/slsDetectorSoftware/multiSlsDetector/multiSlsDetector.cpp +++ b/slsDetectorSoftware/multiSlsDetector/multiSlsDetector.cpp @@ -1955,6 +1955,53 @@ std::string multiSlsDetector::getAdditionalJsonParameter(const std::string &key, return sls::concatenateIfDifferent(r); } + +int multiSlsDetector::setDetectorMinMaxEnergyThreshold(const int index, int value, int detPos) { + std::string parameter = (index ? "emax" : "emin"); + + std::string result; + if (value < 0) { + result = getAdditionalJsonParameter(parameter, detPos); + } else { + result = setAdditionalJsonParameter(parameter, std::to_string(value), detPos); + } + + // convert to integer + try { + return stoi(result); + } + // not found or cannot scan integer + catch(...) { + return -1; + } +} + +int multiSlsDetector::setFrameMode(frameModeType value, int detPos) { + std::string parameter = "frameMode"; + std::string result; + + if (value == GET_FRAME_MODE) { + result = getAdditionalJsonParameter(parameter, detPos); + } else { + result = setAdditionalJsonParameter(parameter, getFrameModeType(value), detPos); + } + + return getFrameModeType(result); +} + +int multiSlsDetector::setDetectorMode(detectorModeType value, int detPos) { + std::string parameter = "detectorMode"; + std::string result; + + if (value == GET_DETECTOR_MODE) { + result = getAdditionalJsonParameter(parameter, detPos); + } else { + result = setAdditionalJsonParameter(parameter, getDetectorModeType(value), detPos); + } + + return getDetectorModeType(result); +} + int multiSlsDetector::setReceiverUDPSocketBufferSize(int udpsockbufsize, int detPos) { // single if (detPos >= 0) { diff --git a/slsDetectorSoftware/multiSlsDetector/multiSlsDetector.h b/slsDetectorSoftware/multiSlsDetector/multiSlsDetector.h index fc17bcc50..2c62a579b 100644 --- a/slsDetectorSoftware/multiSlsDetector/multiSlsDetector.h +++ b/slsDetectorSoftware/multiSlsDetector/multiSlsDetector.h @@ -1087,6 +1087,30 @@ class multiSlsDetector : public virtual slsDetectorDefs, */ std::string getAdditionalJsonParameter(const std::string& key, int detPos = -1); + /** + * Sets the detector minimum/maximum energy threshold in processor (for Moench only) + * @param index 0 for emin, antyhing else for emax + * @param v value to set (-1 gets) + * @returns detector minimum/maximum energy threshold (-1 for not found or error in computing json parameter value) + */ + int setDetectorMinMaxEnergyThreshold(const int index, int value, int detPos = -1); + + /** + * Sets the frame mode in processor (Moench only) + * @param value frameModeType (-1 gets) + * @param detPos -1 for all detectors in list or specific detector position + * @returns frame mode (-1 for not found or error in computing json parameter value) + */ + int setFrameMode(frameModeType value, int detPos = -1); + + /** + * Sets the detector mode in processor (Moench only) + * @param value detectorModetype (-1 gets) + * @param detPos -1 for all detectors in list or specific detector position + * @returns detector mode (-1 for not found or error in computing json parameter value) + */ + int setDetectorMode(detectorModeType value, int detPos = -1); + /** * Sets the receiver UDP socket buffer size * @param udpsockbufsize additional json header diff --git a/slsDetectorSoftware/slsDetector/slsDetectorCommand.cpp b/slsDetectorSoftware/slsDetector/slsDetectorCommand.cpp index 2ae77b080..d6aa07ac4 100644 --- a/slsDetectorSoftware/slsDetector/slsDetectorCommand.cpp +++ b/slsDetectorSoftware/slsDetector/slsDetectorCommand.cpp @@ -63,7 +63,7 @@ The commands are sudivided into different pages depending on their functionaliti - \ref output "Output": commands to define output file destination and format - \ref network "Network": commands to setup the network between client, detector and receiver - \ref receiver "Receiver": commands to configure the receiver - - \ref prototype "Prototype (Chip Test Board / Moench)": commands specific for the chiptest board or moench + - \ref prototype "Chip Test Board / Moench": commands specific for the chiptest board or moench - \ref test "Developer": commands to be used only for software debugging. Avoid using them! */ @@ -1796,10 +1796,37 @@ slsDetectorCommand::slsDetectorCommand(multiSlsDetector *det) { /* pattern generator */ - /*! \page prototype Protoype (Chip Test Board / Moench) + /*! \page prototype Chip Test Board / Moench 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 + */ + descrToFuncMap[i].m_pFuncName = "framemode"; // + descrToFuncMap[i].m_pFuncPtr = &slsDetectorCommand::cmdProcessor; + ++i; + + /*! \page prototype + - detectormode [i] Sets/gets detector mode for Moench (soft setting in processor). Options: counting, interpolating, analog + */ + descrToFuncMap[i].m_pFuncName = "detectormode"; // + descrToFuncMap[i].m_pFuncPtr = &slsDetectorCommand::cmdProcessor; + ++i; /*! \page prototype - adcinvert [mask] Sets/gets ADC inversion mask (8 digits hex format) @@ -5443,3 +5470,62 @@ std::string slsDetectorCommand::cmdPulse(int narg, char *args[], int action, int } +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; + } + return os.str(); +} + +std::string slsDetectorCommand::cmdProcessor(int narg, char *args[], int action, int detPos) { + if (action == HELP_ACTION) + return helpProcessor(action); + + myDet->setOnline(ONLINE_FLAG, detPos); + myDet->setReceiverOnline(ONLINE_FLAG, detPos); + + 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 (action == PUT_ACTION) { + frameModeType ival = getFrameModeType(args[1]); + if (ival == GET_FRAME_MODE) + return std::string("cannot parse frame mode value"); + myDet->setFrameMode(ival, detPos); + } + return getFrameModeType(frameModeType(myDet->setFrameMode(GET_FRAME_MODE, detPos))); + } + + else if (cmd == "detectorMode") { + if (action == PUT_ACTION) { + detectorModeType ival = getDetectorModeType(args[1]); + if (ival == GET_DETECTOR_MODE) + return std::string("cannot parse detector mode value"); + myDet->setDetectorMode(ival, detPos); + } + return getDetectorModeType(detectorModeType(myDet->setDetectorMode(GET_DETECTOR_MODE, detPos))); + } + return std::string("unknown action"); +} + + + diff --git a/slsDetectorSoftware/slsDetector/slsDetectorCommand.h b/slsDetectorSoftware/slsDetector/slsDetectorCommand.h index f29185044..2a4117d9c 100644 --- a/slsDetectorSoftware/slsDetector/slsDetectorCommand.h +++ b/slsDetectorSoftware/slsDetector/slsDetectorCommand.h @@ -79,7 +79,7 @@ class slsDetectorCommand : public virtual slsDetectorDefs { static std::string helpReceiver(int action); static std::string helpPattern(int action); static std::string helpPulse(int action); - + static std::string helpProcessor(int action); @@ -141,6 +141,7 @@ class slsDetectorCommand : public virtual slsDetectorDefs { std::string cmdReceiver(int narg, char *args[], int action, int detPos = -1); std::string cmdPattern(int narg, char *args[], int action, int detPos = -1); std::string cmdPulse(int narg, char *args[], int action, int detPos = -1); + std::string cmdProcessor(int narg, char *args[], int action, int detPos = -1); int numberOfCommands; std::string cmd; diff --git a/slsDetectorSoftware/slsDetector/slsDetectorUsers.cpp b/slsDetectorSoftware/slsDetector/slsDetectorUsers.cpp index 463ac3abe..5707be53c 100644 --- a/slsDetectorSoftware/slsDetector/slsDetectorUsers.cpp +++ b/slsDetectorSoftware/slsDetector/slsDetectorUsers.cpp @@ -359,14 +359,19 @@ int slsDetectorUsers::setReceiverFramesPerFile(int f, int detPos) { return detector.setReceiverFramesPerFile(f, detPos); } -std::string slsDetectorUsers::setAdditionalJsonParameter(const std::string& key, const std::string& value, int detPos) { - return detector.setAdditionalJsonParameter(key, value, detPos); +int slsDetectorUsers::setDetectorMinMaxEnergyThreshold(const int index, int v, int detPos) { + return detector.setDetectorMinMaxEnergyThreshold(index, v, detPos); } -std::string slsDetectorUsers::getAdditionalJsonParameter(const std::string& key, int detPos) { - return detector.getAdditionalJsonParameter(key, detPos); +int slsDetectorUsers::setFrameMode(int value, int detPos) { + return detector.setFrameMode(slsDetectorDefs::frameModeType(value), detPos); } +int slsDetectorUsers::setDetectorMode(int value, int detPos) { + return detector.setDetectorMode(slsDetectorDefs::detectorModeType(value), detPos); +} + + /************************************************************************ CALLBACKS & COMMAND LINE PARSING diff --git a/slsDetectorSoftware/slsDetector/slsDetectorUsers.h b/slsDetectorSoftware/slsDetector/slsDetectorUsers.h index 967d3682d..6d701392e 100644 --- a/slsDetectorSoftware/slsDetector/slsDetectorUsers.h +++ b/slsDetectorSoftware/slsDetector/slsDetectorUsers.h @@ -769,24 +769,34 @@ public: */ int setReceiverFramesPerFile(int f = -1, int detPos = -1); - /** - * Sets the value for the additional json header parameter if found, else append it - * @param key additional json header parameter - * @param value additional json header parameter value (cannot be empty) + /** + * Sets the detector minimum/maximum energy threshold in processor (for Moench only) + * @param index 0 for emin, antyhing else for emax + * @param v value to set (-1 gets) * @param detPos -1 for all detectors in list or specific detector position - * @returns the additional json header parameter value, - * empty if no parameter found in additional json header - */ - std::string setAdditionalJsonParameter(const std::string& key, const std::string& value, int detPos = -1); + * @returns detector minimum/maximum energy threshold + */ + int setDetectorMinMaxEnergyThreshold(const int index, int v, int detPos = -1); + + /** + * Sets the frame mode in processor (Moench only) + * @param value frame mode value (-1 gets) + * Options (slsDetectorDefs::frameModeType) + * PEDESTAL, NEW_PEDESTAL, FLATFIELD, NEW_FLATFIELD + * @param detPos -1 for all detectors in list or specific detector position + * @returns frame mode (-1 for not found or error in computing json parameter value) + */ + int setFrameMode(int value, int detPos = -1); /** - * Returns the additional json header parameter value - * @param key additional json header parameter + * Sets the detector mode in processor (Moench only) + * @param value detector mode value (-1 gets) + * Options (slsDetectorDefs::detectorModeType) + * COUNTING, INTERPOLATING, ANALOG * @param detPos -1 for all detectors in list or specific detector position - * @returns the additional json header parameter value, - * empty if no parameter found in additional json header + * @returns detector mode (-1 for not found or error in computing json parameter value) */ - std::string getAdditionalJsonParameter(const std::string& key, int detPos = -1); + int setDetectorMode(int value, int detPos = -1); /************************************************************************ diff --git a/slsSupportLib/include/sls_detector_defs.h b/slsSupportLib/include/sls_detector_defs.h index b7554e2fb..bd083d207 100755 --- a/slsSupportLib/include/sls_detector_defs.h +++ b/slsSupportLib/include/sls_detector_defs.h @@ -557,6 +557,28 @@ public: }; + /** + * frame mode for processor + */ + enum frameModeType { + GET_FRAME_MODE = -1, + PEDESTAL, /** < pedestal */ + NEW_PEDESTAL, /** < new pedestal */ + FLATFIELD, /** < flatfield */ + NEW_FLATFIELD /** < new flatfield */ + }; + + /** + * detector mode for processor + */ + enum detectorModeType { + GET_DETECTOR_MODE = -1, + COUNTING, /** < counting */ + INTERPOLATING, /** < interpolating */ + ANALOG /** < analog */ + }; + + #ifdef __cplusplus /** returns string from enabled/disabled \param b true or false @@ -875,6 +897,64 @@ public: }}; \ + /** + * returns frameModeType as enum + * @param s pedestal, newpedestal, flatfield, newflatfield + * @returns PEDESTAL, NEW_PEDESTAL, FLATFIELD, NEW_FLATFIELD, GET_FRAME_MODE (if unknown) + */ + static frameModeType getFrameModeType(std::string s) { \ + for (auto &c: s) \ + c = std::tolower(c); \ + if (s == "pedestal") return PEDESTAL; \ + if (s == "newpedestal") return NEW_PEDESTAL; \ + if (s == "flatfield") return FLATFIELD; \ + if (s == "newflatfield")return NEW_FLATFIELD; \ + return GET_FRAME_MODE; \ + } \ + + /** + * returns frameModeType as string + * @param f PEDESTAL, NEW_PEDESTAL, FLATFIELD, NEW_FLATFIELD + * @return string pedestal, newpedestal, flatfield, newflatfield, unknown + */ + static std::string getFrameModeType(frameModeType f) { \ + switch(f) { \ + case PEDESTAL: return std::string("pedestal"); \ + case NEW_PEDESTAL: return std::string("newPedestal"); \ + case FLATFIELD: return std::string("flatfield"); \ + case NEW_FLATFIELD: return std::string("newFlatfield"); \ + default: return std::string("unknown"); \ + } \ + } \ + + /** + * returns detectorModeType as enum + * @param s counting, interpolating, analog + * @returns COUNTING, INTERPOLATING, ANALOG, GET_DETECTOR_MODE (if unknown) + */ + static detectorModeType getDetectorModeType(std::string s) { \ + for (auto &c: s) \ + c = std::tolower(c); \ + if (s == "counting") return COUNTING; \ + if (s == "interpolating") return INTERPOLATING; \ + if (s == "analog") return ANALOG; \ + return GET_DETECTOR_MODE; \ + } \ + + /** + * returns frameModeType as string + * @param f COUNTING, INTERPOLATING, ANALOG + * @return string counting, interpolating, analog, unknown + */ + static std::string getDetectorModeType(detectorModeType f) { \ + switch(f) { \ + case COUNTING: return std::string("counting"); \ + case INTERPOLATING: return std::string("interpolating"); \ + case ANALOG: return std::string("analog"); \ + default: return std::string("unknown"); \ + } \ + } \ + #endif #ifdef __cplusplus