Jungfrausync (#519)

* jungfrau sync
This commit is contained in:
Dhanya Thattil 2022-08-23 10:29:16 +02:00 committed by GitHub
parent da16c1101c
commit 4638bf7cf8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
16 changed files with 158 additions and 4 deletions

View File

@ -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
==================

View File

@ -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):

View File

@ -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<bool>(Detector::*)(sls::Positions) const) &
Detector::getSynchronization,
py::arg() = Positions{})
.def("setSynchronization",
(void (Detector::*)(bool)) & Detector::setSynchronization,
py::arg())
.def("isVirtualDetectorServer",
(Result<bool>(Detector::*)(sls::Positions) const) &
Detector::isVirtualDetectorServer,

View File

@ -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)

View File

@ -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:

View File

@ -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

View File

@ -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);

View File

@ -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);
}
}
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);
}

View File

@ -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<bool> 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<bool> getSynchronization(Positions pos = {}) const;
/** [Jungfrau] */
void setSynchronization(bool value);
Result<bool> isVirtualDetectorServer(Positions pos = {}) const;
///@}

View File

@ -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<int>,
"[0, 1]\n\t[Jungfrau] Enables or disables "
"synchronization between modules.");
/* acquisition parameters */
INTEGER_COMMAND_SET_NOID_GET_ID(

View File

@ -325,6 +325,14 @@ void Detector::setMaster(bool master, int pos) {
}
}
Result<bool> Detector::getSynchronization(Positions pos) const {
return pimpl->Parallel(&Module::getSynchronization, pos);
}
void Detector::setSynchronization(bool value) {
pimpl->Parallel(&Module::setSynchronization, {}, value);
}
Result<bool> Detector::isVirtualDetectorServer(Positions pos) const {
return pimpl->Parallel(&Module::isVirtualDetectorServer, pos);
}

View File

@ -490,6 +490,14 @@ void Module::setMaster(const bool master) {
sendToDetectorStop(F_SET_MASTER, static_cast<int>(master), nullptr);
}
bool Module::getSynchronization() const {
return sendToDetector<int>(F_GET_SYNCHRONIZATION);
}
void Module::setSynchronization(const bool value) {
sendToDetector(F_SET_SYNCHRONIZATION, static_cast<int>(value), nullptr);
}
bool Module::isVirtualDetectorServer() const {
return sendToDetector<int>(F_IS_VIRTUAL);
}

View File

@ -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;

View File

@ -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

View File

@ -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";