diff --git a/RELEASE.txt b/RELEASE.txt index 7b216ffd1..de26b90c0 100755 --- a/RELEASE.txt +++ b/RELEASE.txt @@ -91,6 +91,7 @@ This document describes the differences between v7.0.0 and v6.x.x -help should not create a new object - jungfrau master - g2 parallel command +- jungfrau sync 2. Resolved Issues ================== diff --git a/python/slsdet/detector.py b/python/slsdet/detector.py index 602dbc452..c852f080c 100755 --- a/python/slsdet/detector.py +++ b/python/slsdet/detector.py @@ -1488,6 +1488,18 @@ class Detector(CppDetectorApi): def master(self, value): ut.set_using_dict(self.setMaster, value) + @property + @element + def sync(self): + """ + [Jungfrau] Enables or disables synchronization between modules. + """ + return self.getSynchronization() + + @sync.setter + def sync(self, value): + ut.set_using_dict(self.setSynchronization, value) + @property @element def lock(self): diff --git a/python/src/detector.cpp b/python/src/detector.cpp index ab6c98f67..7a0eb6af7 100644 --- a/python/src/detector.cpp +++ b/python/src/detector.cpp @@ -183,6 +183,13 @@ void init_det(py::module &m) { py::arg() = Positions{}) .def("setMaster", (void (Detector::*)(bool, int)) & Detector::setMaster, py::arg(), py::arg()) + .def("getSynchronization", + (Result(Detector::*)(sls::Positions) const) & + Detector::getSynchronization, + py::arg() = Positions{}) + .def("setSynchronization", + (void (Detector::*)(bool)) & Detector::setSynchronization, + py::arg()) .def("isVirtualDetectorServer", (Result(Detector::*)(sls::Positions) const) & Detector::isVirtualDetectorServer, diff --git a/slsDetectorServers/jungfrauDetectorServer/RegisterDefs.h b/slsDetectorServers/jungfrauDetectorServer/RegisterDefs.h index 61e3b3b7b..1a123546e 100644 --- a/slsDetectorServers/jungfrauDetectorServer/RegisterDefs.h +++ b/slsDetectorServers/jungfrauDetectorServer/RegisterDefs.h @@ -210,6 +210,8 @@ #define EXT_SIGNAL_OFST (0) #define EXT_SIGNAL_MSK (0x00000001 << EXT_SIGNAL_OFST) +#define EXT_SYNC_OFST (4) +#define EXT_SYNC_MSK (0x00000001 << EXT_SYNC_OFST) /* Control Register */ #define CONTROL_REG (0x4F << MEM_MAP_SHIFT) diff --git a/slsDetectorServers/jungfrauDetectorServer/bin/jungfrauDetectorServer_developer b/slsDetectorServers/jungfrauDetectorServer/bin/jungfrauDetectorServer_developer index d6c978eb0..ddf8f2f3e 100755 Binary files a/slsDetectorServers/jungfrauDetectorServer/bin/jungfrauDetectorServer_developer and b/slsDetectorServers/jungfrauDetectorServer/bin/jungfrauDetectorServer_developer differ diff --git a/slsDetectorServers/jungfrauDetectorServer/slsDetectorFunctionList.c b/slsDetectorServers/jungfrauDetectorServer/slsDetectorFunctionList.c index 679b47cb7..1b335ce7f 100644 --- a/slsDetectorServers/jungfrauDetectorServer/slsDetectorFunctionList.c +++ b/slsDetectorServers/jungfrauDetectorServer/slsDetectorFunctionList.c @@ -1380,6 +1380,19 @@ int isMaster(int *retval) { return OK; } +int getSynchronization() { + return ((bus_r(EXT_SIGNAL_REG) & EXT_SYNC_MSK) >> EXT_SYNC_OFST); +} + +void setSynchronization(int enable) { + LOG(logINFOBLUE, + ("%s Synchronization\n", (enable ? "Enabling" : "Disabling"))); + if (enable) + bus_w(EXT_SIGNAL_REG, bus_r(EXT_SIGNAL_REG) | EXT_SYNC_MSK); + else + bus_w(EXT_SIGNAL_REG, bus_r(EXT_SIGNAL_REG) & ~EXT_SYNC_MSK); +} + void setTiming(enum timingMode arg) { switch (arg) { case AUTO_TIMING: diff --git a/slsDetectorServers/slsDetectorServer/include/slsDetectorFunctionList.h b/slsDetectorServers/slsDetectorServer/include/slsDetectorFunctionList.h index 2b254c854..28c02e2a7 100644 --- a/slsDetectorServers/slsDetectorServer/include/slsDetectorFunctionList.h +++ b/slsDetectorServers/slsDetectorServer/include/slsDetectorFunctionList.h @@ -397,6 +397,11 @@ int isTop(int *retval); int isMaster(int *retval); #endif +#ifdef JUNGFRAUD +int getSynchronization(); +void setSynchronization(int enable); +#endif + #ifdef GOTTHARD2D void updatingRegisters(); #endif diff --git a/slsDetectorServers/slsDetectorServer/include/slsDetectorServer_funcs.h b/slsDetectorServers/slsDetectorServer/include/slsDetectorServer_funcs.h index 62e208406..716ca53bf 100644 --- a/slsDetectorServers/slsDetectorServer/include/slsDetectorServer_funcs.h +++ b/slsDetectorServers/slsDetectorServer/include/slsDetectorServer_funcs.h @@ -304,3 +304,5 @@ int set_analog_pulsing(int); int get_digital_pulsing(int); int set_digital_pulsing(int); int get_module(int); +int get_synchronization(int); +int set_synchronization(int); \ No newline at end of file diff --git a/slsDetectorServers/slsDetectorServer/src/slsDetectorServer_funcs.c b/slsDetectorServers/slsDetectorServer/src/slsDetectorServer_funcs.c index 0f0d52863..5dd6fd637 100644 --- a/slsDetectorServers/slsDetectorServer/src/slsDetectorServer_funcs.c +++ b/slsDetectorServers/slsDetectorServer/src/slsDetectorServer_funcs.c @@ -468,6 +468,8 @@ void function_table() { flist[F_GET_DIGITAL_PULSING] = &get_digital_pulsing; flist[F_SET_DIGITAL_PULSING] = &set_digital_pulsing; flist[F_GET_MODULE] = &get_module; + flist[F_GET_SYNCHRONIZATION] = &get_synchronization; + flist[F_SET_SYNCHRONIZATION] = &set_synchronization; // check if (NUM_DET_FUNCTIONS >= RECEIVER_ENUM_START) { @@ -10126,4 +10128,51 @@ int set_digital_pulsing(int file_des) { } #endif return Server_SendResult(file_des, INT32, NULL, 0); -} \ No newline at end of file +} + +int get_synchronization(int file_des) { + ret = OK; + memset(mess, 0, sizeof(mess)); + int retval = -1; + + LOG(logDEBUG1, ("Getting synchronization\n")); + +#ifndef JUNGFRAUD + functionNotImplemented(); +#else + retval = getSynchronization(); +#endif + return Server_SendResult(file_des, INT32, &retval, sizeof(retval)); +} + +int set_synchronization(int file_des) { + ret = OK; + memset(mess, 0, sizeof(mess)); + int arg = -1; + + if (receiveData(file_des, &arg, sizeof(arg), INT32) < 0) + return printSocketReadError(); + LOG(logDEBUG1, ("Setting synchronization: %u\n", (int)arg)); + +#ifndef JUNGFRAUD + functionNotImplemented(); +#else + // only set + if (Server_VerifyLock() == OK) { + if ((check_detector_idle("set synchronization") == OK) && + (arg != 0 && arg != 1)) { + ret = FAIL; + sprintf(mess, + "Could not set synchronization. Invalid argument %d.\n", + arg); + LOG(logERROR, (mess)); + } else { + setSynchronization(arg); + int retval = getSynchronization(); + LOG(logDEBUG1, ("synchronization retval: %u\n", retval)); + validate(&ret, mess, arg, retval, "set synchronization", DEC); + } + } +#endif + return Server_SendResult(file_des, INT32, NULL, 0); +} diff --git a/slsDetectorSoftware/include/sls/Detector.h b/slsDetectorSoftware/include/sls/Detector.h index 3b5458112..ad2a93947 100644 --- a/slsDetectorSoftware/include/sls/Detector.h +++ b/slsDetectorSoftware/include/sls/Detector.h @@ -197,13 +197,19 @@ class Detector { */ void setFlipRows(bool value, Positions pos = {}); - /** [Eiger][Mythen3][Gotthard1][Gotthard2] via stop server **/ + /** [Eiger][Mythen3][Gotthard1][Gotthard2][Jungfrau] via stop server **/ Result getMaster(Positions pos = {}) const; - /** [Eiger][Gotthard2] Set (half) module to master and the other(s) to - * slaves */ + /** [Eiger][Gotthard2][Jungfrau] Set (half) module to master and the + * other(s) to slaves */ void setMaster(bool value, int pos); + /** [Jungfrau] **/ + Result getSynchronization(Positions pos = {}) const; + + /** [Jungfrau] */ + void setSynchronization(bool value); + Result isVirtualDetectorServer(Positions pos = {}) const; ///@} diff --git a/slsDetectorSoftware/src/CmdProxy.h b/slsDetectorSoftware/src/CmdProxy.h index 07a9deeda..3258e3cef 100644 --- a/slsDetectorSoftware/src/CmdProxy.h +++ b/slsDetectorSoftware/src/CmdProxy.h @@ -787,6 +787,7 @@ class CmdProxy { {"gappixels", &CmdProxy::GapPixels}, {"fliprows", &CmdProxy::fliprows}, {"master", &CmdProxy::master}, + {"sync", &CmdProxy::sync}, /* acquisition parameters */ {"acquire", &CmdProxy::Acquire}, @@ -1303,6 +1304,11 @@ class CmdProxy { "slaves.\n\t[Gotthard][Gotthard2][Mythen3][Eiger][Jungfrau] Gets if " "the current (half) module is master."); + INTEGER_COMMAND_SET_NOID_GET_ID(sync, getSynchronization, + setSynchronization, StringTo, + "[0, 1]\n\t[Jungfrau] Enables or disables " + "synchronization between modules."); + /* acquisition parameters */ INTEGER_COMMAND_SET_NOID_GET_ID( diff --git a/slsDetectorSoftware/src/Detector.cpp b/slsDetectorSoftware/src/Detector.cpp index 1f197c9d2..72f579a40 100644 --- a/slsDetectorSoftware/src/Detector.cpp +++ b/slsDetectorSoftware/src/Detector.cpp @@ -325,6 +325,14 @@ void Detector::setMaster(bool master, int pos) { } } +Result Detector::getSynchronization(Positions pos) const { + return pimpl->Parallel(&Module::getSynchronization, pos); +} + +void Detector::setSynchronization(bool value) { + pimpl->Parallel(&Module::setSynchronization, {}, value); +} + Result Detector::isVirtualDetectorServer(Positions pos) const { return pimpl->Parallel(&Module::isVirtualDetectorServer, pos); } diff --git a/slsDetectorSoftware/src/Module.cpp b/slsDetectorSoftware/src/Module.cpp index fdcaec49c..5650f13d6 100644 --- a/slsDetectorSoftware/src/Module.cpp +++ b/slsDetectorSoftware/src/Module.cpp @@ -490,6 +490,14 @@ void Module::setMaster(const bool master) { sendToDetectorStop(F_SET_MASTER, static_cast(master), nullptr); } +bool Module::getSynchronization() const { + return sendToDetector(F_GET_SYNCHRONIZATION); +} + +void Module::setSynchronization(const bool value) { + sendToDetector(F_SET_SYNCHRONIZATION, static_cast(value), nullptr); +} + bool Module::isVirtualDetectorServer() const { return sendToDetector(F_IS_VIRTUAL); } diff --git a/slsDetectorSoftware/src/Module.h b/slsDetectorSoftware/src/Module.h index f83e257d8..33af4287d 100644 --- a/slsDetectorSoftware/src/Module.h +++ b/slsDetectorSoftware/src/Module.h @@ -123,6 +123,8 @@ class Module : public virtual slsDetectorDefs { void setFlipRows(bool value); bool isMaster() const; void setMaster(const bool master); + bool getSynchronization() const; + void setSynchronization(const bool value); bool isVirtualDetectorServer() const; diff --git a/slsDetectorSoftware/tests/test-CmdProxy-jungfrau.cpp b/slsDetectorSoftware/tests/test-CmdProxy-jungfrau.cpp index 7a4e24698..ed33f3a2e 100644 --- a/slsDetectorSoftware/tests/test-CmdProxy-jungfrau.cpp +++ b/slsDetectorSoftware/tests/test-CmdProxy-jungfrau.cpp @@ -539,4 +539,33 @@ TEST_CASE("filtercells", "[.cmd]") { } } +TEST_CASE("sync", "[.cmd]") { + Detector det; + CmdProxy proxy(&det); + auto det_type = det.getDetectorType().squash(); + if (det_type == defs::JUNGFRAU) { + auto prev_val = det.getSynchronization().tsquash( + "inconsistent synchronization to test"); + { + std::ostringstream oss; + proxy.Call("sync", {"0"}, -1, PUT, oss); + REQUIRE(oss.str() == "sync 0\n"); + } + { + std::ostringstream oss; + proxy.Call("sync", {"1"}, -1, PUT, oss); + REQUIRE(oss.str() == "sync 1\n"); + } + { + std::ostringstream oss; + proxy.Call("sync", {}, -1, GET, oss); + REQUIRE(oss.str() == "sync 1\n"); + } + det.getSynchronization(prev_val); + } else { + REQUIRE_THROWS(proxy.Call("sync", {}, -1, GET)); + REQUIRE_THROWS(proxy.Call("sync", {"0"}, -1, PUT)); + } +} + } // namespace sls diff --git a/slsSupportLib/include/sls/sls_detector_funcs.h b/slsSupportLib/include/sls/sls_detector_funcs.h index edcecee7a..ea25b4db4 100755 --- a/slsSupportLib/include/sls/sls_detector_funcs.h +++ b/slsSupportLib/include/sls/sls_detector_funcs.h @@ -271,6 +271,8 @@ enum detFuncs { F_GET_DIGITAL_PULSING, F_SET_DIGITAL_PULSING, F_GET_MODULE, + F_GET_SYNCHRONIZATION, + F_SET_SYNCHRONIZATION, NUM_DET_FUNCTIONS, RECEIVER_ENUM_START = 512, /**< detector function should not exceed this @@ -648,6 +650,8 @@ const char* getFunctionNameFromEnum(enum detFuncs func) { case F_GET_DIGITAL_PULSING: return "F_GET_DIGITAL_PULSING"; case F_SET_DIGITAL_PULSING: return "F_SET_DIGITAL_PULSING"; case F_GET_MODULE: return "F_GET_MODULE"; + case F_GET_SYNCHRONIZATION: return "F_GET_SYNCHRONIZATION"; + case F_SET_SYNCHRONIZATION: return "F_SET_SYNCHRONIZATION"; case NUM_DET_FUNCTIONS: return "NUM_DET_FUNCTIONS"; case RECEIVER_ENUM_START: return "RECEIVER_ENUM_START";