diff --git a/python/slsdet/detector.py b/python/slsdet/detector.py index d8df1c5b7..f748834a3 100755 --- a/python/slsdet/detector.py +++ b/python/slsdet/detector.py @@ -3412,6 +3412,13 @@ class Detector(CppDetectorApi): fname = ut.make_string_path(fname) ut.set_using_dict(self.setPattern, fname) + @property + def patfname(self): + """ + [Ctb][Mythen3] Gets the pattern file name including path of the last pattern uploaded. Returns an empty if nothing was uploaded or via a server default + file + """ + return self.getPatterFileName() @property @element diff --git a/python/src/detector.cpp b/python/src/detector.cpp index dea965a63..5dfd3ed4c 100644 --- a/python/src/detector.cpp +++ b/python/src/detector.cpp @@ -1737,6 +1737,11 @@ void init_det(py::module &m) { (std::string(Detector::*)(const defs::dacIndex) const) & Detector::getSlowAdcName, py::arg()); + CppDetectorApi.def( + "getPatterFileName", + (Result(Detector::*)(sls::Positions) const) & + Detector::getPatterFileName, + py::arg() = Positions{}); CppDetectorApi.def( "setPattern", (void (Detector::*)(const std::string &, sls::Positions)) & diff --git a/slsDetectorServers/ctbDetectorServer/bin/ctbDetectorServer_developer b/slsDetectorServers/ctbDetectorServer/bin/ctbDetectorServer_developer index 49397c9ad..257ec6527 100755 Binary files a/slsDetectorServers/ctbDetectorServer/bin/ctbDetectorServer_developer and b/slsDetectorServers/ctbDetectorServer/bin/ctbDetectorServer_developer differ diff --git a/slsDetectorServers/mythen3DetectorServer/bin/mythen3DetectorServer_developer b/slsDetectorServers/mythen3DetectorServer/bin/mythen3DetectorServer_developer index 43cd01807..bdc2183d9 100755 Binary files a/slsDetectorServers/mythen3DetectorServer/bin/mythen3DetectorServer_developer and b/slsDetectorServers/mythen3DetectorServer/bin/mythen3DetectorServer_developer differ diff --git a/slsDetectorServers/mythen3DetectorServer/slsDetectorFunctionList.c b/slsDetectorServers/mythen3DetectorServer/slsDetectorFunctionList.c index 16dd362de..dda8c2b4c 100644 --- a/slsDetectorServers/mythen3DetectorServer/slsDetectorFunctionList.c +++ b/slsDetectorServers/mythen3DetectorServer/slsDetectorFunctionList.c @@ -1375,7 +1375,7 @@ int setTrimbits(int *trimbits) { error = 1; } else { memset(cmess, 0, MAX_STR_LENGTH); - error |= loadPattern(cmess, logDEBUG5, pat); + error |= loadPattern(cmess, logDEBUG5, pat, ""); if (!error) startPattern(); free(pat); @@ -2827,7 +2827,7 @@ int setChipStatusRegister(int csr) { iret = FAIL; } else { memset(cmess, 0, MAX_STR_LENGTH); - iret = loadPattern(cmess, logDEBUG5, pat); + iret = loadPattern(cmess, logDEBUG5, pat, ""); if (iret == OK) { startPattern(); LOG(logINFO, ("CSR is now: 0x%x\n", csr)); diff --git a/slsDetectorServers/slsDetectorServer/include/loadPattern.h b/slsDetectorServers/slsDetectorServer/include/loadPattern.h index dfc040270..1d87956b9 100644 --- a/slsDetectorServers/slsDetectorServer/include/loadPattern.h +++ b/slsDetectorServers/slsDetectorServer/include/loadPattern.h @@ -54,8 +54,9 @@ uint64_t getPatternBitMask(); #ifdef MYTHEN3D void startPattern(); #endif - -int loadPattern(char *mess, enum TLogLevel printLevel, patternParameters *pat); +char *getPatternFileName(); +int loadPattern(char *mess, enum TLogLevel printLevel, patternParameters *pat, + char *patfname); int getPattern(char *mess, patternParameters *pat); int loadPatternFile(char *patFname, char *errMessage); diff --git a/slsDetectorServers/slsDetectorServer/include/slsDetectorServer_funcs.h b/slsDetectorServers/slsDetectorServer/include/slsDetectorServer_funcs.h index 6c2c6b218..3a3e11b1b 100644 --- a/slsDetectorServers/slsDetectorServer/include/slsDetectorServer_funcs.h +++ b/slsDetectorServers/slsDetectorServer/include/slsDetectorServer_funcs.h @@ -226,6 +226,7 @@ int get_gate_delay_all_gates(int); int get_veto(int); int set_veto(int); int set_pattern(int); +int get_pattern_file(int); int get_scan(int); int set_scan(int); int get_scan_error_message(int); diff --git a/slsDetectorServers/slsDetectorServer/src/loadPattern.c b/slsDetectorServers/slsDetectorServer/src/loadPattern.c index f0cf214fe..1c2e49f04 100644 --- a/slsDetectorServers/slsDetectorServer/src/loadPattern.c +++ b/slsDetectorServers/slsDetectorServer/src/loadPattern.c @@ -32,6 +32,8 @@ extern void setU64BitReg(uint64_t value, int aLSB, int aMSB); #define MAX_LEVELS MAX_PATTERN_LEVELS #endif +char clientPatternfile[MAX_STR_LENGTH]; + void initializePatternAddresses() { LOG(logDEBUG1, ("Setting default Loop and Wait Addresses(0x%x)\n", MAX_PATTERN_LENGTH - 1)); @@ -747,10 +749,15 @@ void startPattern() { } #endif +char *getPatternFileName() { return clientPatternfile; } + int loadPattern(char *message, enum TLogLevel printLevel, - patternParameters *pat) { + patternParameters *pat, char *patfname) { LOG(logINFOBLUE, ("Loading Pattern from structure\n")); int ret = OK; + memset(clientPatternfile, 0, MAX_STR_LENGTH); + memcpy(clientPatternfile, patfname, MAX_STR_LENGTH); + printf("Client Pattern File:%s\n", clientPatternfile); #ifdef MYTHEN3D trimmingPrint = printLevel; #endif diff --git a/slsDetectorServers/slsDetectorServer/src/slsDetectorServer_funcs.c b/slsDetectorServers/slsDetectorServer/src/slsDetectorServer_funcs.c index 8df278d70..1d991713e 100644 --- a/slsDetectorServers/slsDetectorServer/src/slsDetectorServer_funcs.c +++ b/slsDetectorServers/slsDetectorServer/src/slsDetectorServer_funcs.c @@ -397,6 +397,7 @@ void function_table() { flist[F_GET_VETO] = &get_veto; flist[F_SET_VETO] = &set_veto; flist[F_SET_PATTERN] = &set_pattern; + flist[F_GET_PATTERN_FILE_NAME] = &get_pattern_file; flist[F_GET_SCAN] = &get_scan; flist[F_SET_SCAN] = &set_scan; flist[F_GET_SCAN_ERROR_MESSAGE] = &get_scan_error_message; @@ -7604,6 +7605,8 @@ int set_veto(int file_des) { int set_pattern(int file_des) { ret = OK; memset(mess, 0, sizeof(mess)); + char args[MAX_STR_LENGTH]; + memset(args, 0, MAX_STR_LENGTH); #if !defined(CHIPTESTBOARDD) && !defined(MYTHEN3D) functionNotImplemented(); @@ -7617,10 +7620,15 @@ int set_pattern(int file_des) { free(pat); return printSocketReadError(); } + if (receiveData(file_des, args, MAX_STR_LENGTH, OTHER) < 0) { + if (pat != NULL) + free(pat); + return printSocketReadError(); + } if (Server_VerifyLock() == OK) { - LOG(logINFO, ("Setting Pattern from structure\n")); - ret = loadPattern(mess, logINFO, pat); + LOG(logDEBUG1, ("Setting Pattern from structure\n")); + ret = loadPattern(mess, logINFO, pat, args); } if (pat != NULL) free(pat); @@ -7629,6 +7637,24 @@ int set_pattern(int file_des) { return Server_SendResult(file_des, INT32, NULL, 0); } +int get_pattern_file(int file_des) { + ret = OK; + memset(mess, 0, sizeof(mess)); + char retvals[MAX_STR_LENGTH]; + memset(retvals, 0, MAX_STR_LENGTH); + + LOG(logDEBUG1, ("Getting pattern file name\n")); + +#if !defined(CHIPTESTBOARDD) && !defined(MYTHEN3D) + functionNotImplemented(); +#else + // get only + strcpy(retvals, getPatternFileName()); + LOG(logDEBUG1, ("pattern file name retval: %s\n", retvals)); +#endif + return Server_SendResult(file_des, OTHER, retvals, sizeof(retvals)); +} + int get_pattern(int file_des) { ret = OK; memset(mess, 0, sizeof(mess)); diff --git a/slsDetectorSoftware/include/sls/Detector.h b/slsDetectorSoftware/include/sls/Detector.h index 45be0bb05..9cf8dedff 100644 --- a/slsDetectorSoftware/include/sls/Detector.h +++ b/slsDetectorSoftware/include/sls/Detector.h @@ -1803,6 +1803,10 @@ class Detector { * Pattern * * * * ************************************************/ + /** [CTB][Mythen3] Gets the pattern file name including path of the last + * pattern uploaded. \n Returns an empty if nothing was uploaded or via a + * server default file*/ + Result getPatterFileName(Positions pos = {}) const; /** [CTB][Mythen3] Loads ASCII pattern file directly to server * (instead of executing line by line)*/ diff --git a/slsDetectorSoftware/src/CmdProxy.h b/slsDetectorSoftware/src/CmdProxy.h index ddea0dbf3..52c42d007 100644 --- a/slsDetectorSoftware/src/CmdProxy.h +++ b/slsDetectorSoftware/src/CmdProxy.h @@ -1224,6 +1224,7 @@ class CmdProxy { /* Pattern */ {"pattern", &CmdProxy::Pattern}, + {"patfname", &CmdProxy::patfname}, {"savepattern", &CmdProxy::savepattern}, {"defaultpattern", &CmdProxy::defaultpattern}, {"patioctrl", &CmdProxy::patioctrl}, @@ -1721,7 +1722,8 @@ class CmdProxy { "[voltagename1 voltagename2 .. voltagename4] \n\t\t[ChipTestBoard] Set " "the list of voltage names for this board."); - CTB_SINGLE_DACNAME(voltagename, getVoltageName, setVoltageName, defs::V_POWER_A, + CTB_SINGLE_DACNAME(voltagename, getVoltageName, setVoltageName, + defs::V_POWER_A, "[0-4][name] \n\t\t[ChipTestBoard] Set " "the voltage at the given position to the given name."); @@ -1734,7 +1736,8 @@ class CmdProxy { "[slowadcname1 slowadcname2 .. slowadcname7] \n\t\t[ChipTestBoard] Set " "the list of slowadc names for this board."); - CTB_SINGLE_DACNAME(slowadcname, getSlowAdcName, setSlowAdcName, defs::SLOW_ADC0, + CTB_SINGLE_DACNAME(slowadcname, getSlowAdcName, setSlowAdcName, + defs::SLOW_ADC0, "[0-7][name] \n\t\t[ChipTestBoard] Set " "the slowadc at the given position to the given name."); @@ -2473,6 +2476,11 @@ class CmdProxy { /* Pattern */ + GET_COMMAND(patfname, getPatterFileName, + "\n\t[Ctb][Mythen3] Gets the pattern file name including " + "path of the last pattern uploaded. Returns an empty if " + "nothing was uploaded or via a server default file"); + EXECUTE_SET_COMMAND_NOID_1ARG( savepattern, savePattern, "[fname]\n\t[Ctb][Mythen3] Saves pattern to file (ascii). " diff --git a/slsDetectorSoftware/src/Detector.cpp b/slsDetectorSoftware/src/Detector.cpp index be93dfa6b..dc43cb396 100644 --- a/slsDetectorSoftware/src/Detector.cpp +++ b/slsDetectorSoftware/src/Detector.cpp @@ -2335,7 +2335,7 @@ defs::dacIndex Detector::getVoltageIndex(const std::string &name) const { } void Detector::setVoltageName(const defs::dacIndex index, - const std::string &name) { + const std::string &name) { if (getDetectorType().squash() != defs::CHIPTESTBOARD) throw RuntimeError("Named powers only for CTB"); pimpl->setCtbVoltageName(index, name); @@ -2370,7 +2370,7 @@ defs::dacIndex Detector::getSlowAdcIndex(const std::string &name) const { } void Detector::setSlowAdcName(const defs::dacIndex index, - const std::string &name) { + const std::string &name) { if (getDetectorType().squash() != defs::CHIPTESTBOARD) throw RuntimeError("Named SlowAdcs only for CTB"); pimpl->setCtbSlowAdcName(index, name); @@ -2384,16 +2384,20 @@ std::string Detector::getSlowAdcName(const defs::dacIndex i) const { // Pattern +Result Detector::getPatterFileName(Positions pos) const { + return pimpl->Parallel(&Module::getPatterFileName, pos); +} + void Detector::setPattern(const std::string &fname, Positions pos) { Pattern pat; pat.load(fname); pat.validate(); - setPattern(pat, pos); + pimpl->Parallel(&Module::setPattern, pos, pat, fname); } void Detector::setPattern(const Pattern &pat, Positions pos) { pat.validate(); - pimpl->Parallel(&Module::setPattern, pos, pat); + pimpl->Parallel(&Module::setPattern, pos, pat, ""); } void Detector::savePattern(const std::string &fname) { diff --git a/slsDetectorSoftware/src/DetectorImpl.cpp b/slsDetectorSoftware/src/DetectorImpl.cpp index 0a74b412f..b08cec4df 100644 --- a/slsDetectorSoftware/src/DetectorImpl.cpp +++ b/slsDetectorSoftware/src/DetectorImpl.cpp @@ -2051,7 +2051,7 @@ std::string DetectorImpl::getCtbVoltageName(const defs::dacIndex i) const { } void DetectorImpl::setCtbVoltageName(const defs::dacIndex index, - const std::string &name) { + const std::string &name) { ctb_shm()->setVoltageName(static_cast(index - defs::V_POWER_A), name); } @@ -2068,7 +2068,7 @@ std::string DetectorImpl::getCtbSlowAdcName(const defs::dacIndex i) const { } void DetectorImpl::setCtbSlowAdcName(const defs::dacIndex index, - const std::string &name) { + const std::string &name) { ctb_shm()->setSlowAdcName(static_cast(index - defs::SLOW_ADC0), name); } diff --git a/slsDetectorSoftware/src/Module.cpp b/slsDetectorSoftware/src/Module.cpp index 6101d5179..e9fd77e4f 100644 --- a/slsDetectorSoftware/src/Module.cpp +++ b/slsDetectorSoftware/src/Module.cpp @@ -2478,9 +2478,23 @@ void Module::setLEDEnable(bool enable) { } // Pattern +std::string Module::getPatterFileName() const { + char retval[MAX_STR_LENGTH]{}; + sendToDetector(F_GET_PATTERN_FILE_NAME, nullptr, retval); + return retval; +} -void Module::setPattern(const Pattern &pat) { - sendToDetector(F_SET_PATTERN, pat.data(), pat.size(), nullptr, 0); +void Module::setPattern(const Pattern &pat, const std::string &fname) { + auto client = DetectorSocket(shm()->hostname, shm()->controlPort); + client.Send(F_SET_PATTERN); + client.Send(pat.data(), pat.size()); + char args[MAX_STR_LENGTH]{}; + strcpy_safe(args, fname.c_str()); + client.Send(args); + if (client.Receive() == FAIL) { + throw DetectorError("Detector " + std::to_string(moduleIndex) + + " returned error: " + client.readErrorMessage()); + } } Pattern Module::getPattern() { diff --git a/slsDetectorSoftware/src/Module.h b/slsDetectorSoftware/src/Module.h index 40233c720..74c2786e3 100644 --- a/slsDetectorSoftware/src/Module.h +++ b/slsDetectorSoftware/src/Module.h @@ -525,7 +525,8 @@ class Module : public virtual slsDetectorDefs { * Pattern * * * * ************************************************/ - void setPattern(const Pattern &pat); + std::string getPatterFileName() const; + void setPattern(const Pattern &pat, const std::string &fname); Pattern getPattern(); void loadDefaultPattern(); uint64_t getPatternIOControl() const; diff --git a/slsDetectorSoftware/tests/test-CmdProxy-chiptestboard.cpp b/slsDetectorSoftware/tests/test-CmdProxy-chiptestboard.cpp index 918033e11..3a35fdc03 100644 --- a/slsDetectorSoftware/tests/test-CmdProxy-chiptestboard.cpp +++ b/slsDetectorSoftware/tests/test-CmdProxy-chiptestboard.cpp @@ -309,15 +309,15 @@ TEST_CASE("voltagename", "[.cmd]") { REQUIRE_THROWS(proxy.Call("voltagename", {"5", "bname"}, -1, PUT)); { std::ostringstream oss; - REQUIRE_NOTHROW(proxy.Call("voltagename", {str_voltage_index, "bname"}, - -1, PUT, oss)); + REQUIRE_NOTHROW(proxy.Call( + "voltagename", {str_voltage_index, "bname"}, -1, PUT, oss)); } { std::ostringstream oss; REQUIRE_NOTHROW( proxy.Call("voltagename", {str_voltage_index}, -1, GET, oss)); - REQUIRE(oss.str() == - std::string("voltagename ") + str_voltage_index + " bname\n"); + REQUIRE(oss.str() == std::string("voltagename ") + + str_voltage_index + " bname\n"); } det.setVoltageName(ind, prev); @@ -401,15 +401,15 @@ TEST_CASE("slowadcname", "[.cmd]") { REQUIRE_THROWS(proxy.Call("slowadcname", {"8", "bname"}, -1, PUT)); { std::ostringstream oss; - REQUIRE_NOTHROW(proxy.Call("slowadcname", {str_slowadc_index, "bname"}, - -1, PUT, oss)); + REQUIRE_NOTHROW(proxy.Call( + "slowadcname", {str_slowadc_index, "bname"}, -1, PUT, oss)); } { std::ostringstream oss; REQUIRE_NOTHROW( proxy.Call("slowadcname", {str_slowadc_index}, -1, GET, oss)); - REQUIRE(oss.str() == - std::string("slowadcname ") + str_slowadc_index + " bname\n"); + REQUIRE(oss.str() == std::string("slowadcname ") + + str_slowadc_index + " bname\n"); } det.setSlowAdcName(ind, prev); diff --git a/slsDetectorSoftware/tests/test-CmdProxy-pattern.cpp b/slsDetectorSoftware/tests/test-CmdProxy-pattern.cpp index 6d055e5c6..08fad83bc 100644 --- a/slsDetectorSoftware/tests/test-CmdProxy-pattern.cpp +++ b/slsDetectorSoftware/tests/test-CmdProxy-pattern.cpp @@ -19,6 +19,18 @@ using test::PUT; /* Pattern */ +TEST_CASE("patfname", "[.cmd]") { + Detector det; + CmdProxy proxy(&det); + auto det_type = det.getDetectorType().squash(); + if (det_type == defs::CHIPTESTBOARD || det_type == defs::MYTHEN3) { + REQUIRE_THROWS(proxy.Call("patfname", {}, -1, PUT)); + REQUIRE_NOTHROW(proxy.Call("patfname", {}, -1, GET)); + } else { + REQUIRE_THROWS(proxy.Call("patfname", {}, -1, GET)); + } +} + TEST_CASE("pattern", "[.cmd]") { Detector det; CmdProxy proxy(&det); diff --git a/slsSupportLib/include/sls/sls_detector_funcs.h b/slsSupportLib/include/sls/sls_detector_funcs.h index ed729d912..6b5061529 100755 --- a/slsSupportLib/include/sls/sls_detector_funcs.h +++ b/slsSupportLib/include/sls/sls_detector_funcs.h @@ -281,6 +281,7 @@ enum detFuncs { F_SET_BIT, F_CLEAR_BIT, F_GET_PATTERN_IO_CONTROL, + F_GET_PATTERN_FILE_NAME, NUM_DET_FUNCTIONS, RECEIVER_ENUM_START = 512, /**< detector function should not exceed this @@ -665,6 +666,7 @@ const char* getFunctionNameFromEnum(enum detFuncs func) { case F_SET_BIT: return "F_SET_BIT"; case F_CLEAR_BIT: return "F_CLEAR_BIT"; case F_GET_PATTERN_IO_CONTROL: return "F_GET_PATTERN_IO_CONTROL"; + case F_GET_PATTERN_FILE_NAME: return "F_GET_PATTERN_FILE_NAME"; case NUM_DET_FUNCTIONS: return "NUM_DET_FUNCTIONS"; diff --git a/slsSupportLib/include/sls/versionAPI.h b/slsSupportLib/include/sls/versionAPI.h index c33337c94..d4eb71e9a 100644 --- a/slsSupportLib/include/sls/versionAPI.h +++ b/slsSupportLib/include/sls/versionAPI.h @@ -5,9 +5,9 @@ #define APILIB "developer 0x230224" #define APIRECEIVER "developer 0x230224" #define APIEIGER "developer 0x230525" -#define APICTB "developer 0x230615" #define APIGOTTHARD "developer 0x230615" #define APIGOTTHARD2 "developer 0x230615" #define APIJUNGFRAU "developer 0x230615" -#define APIMYTHEN3 "developer 0x230615" #define APIMOENCH "developer 0x230615" +#define APICTB "developer 0x230621" +#define APIMYTHEN3 "developer 0x230621"