mirror of
https://github.com/slsdetectorgroup/slsDetectorPackage.git
synced 2025-04-23 06:50:02 +02:00
module id instead of serial number
This commit is contained in:
parent
9e1716da56
commit
200df88dcf
@ -69,9 +69,12 @@ void init_det(py::module &m) {
|
||||
(Result<int64_t>(Detector::*)(sls::Positions) const) &
|
||||
Detector::getSerialNumber,
|
||||
py::arg() = Positions{})
|
||||
.def("setSerialNumber",
|
||||
(Result<int64_t>(Detector::*)(sls::Positions) const) &
|
||||
Detector::setSerialNumber,
|
||||
.def("getModuleId",
|
||||
(Result<int>(Detector::*)(sls::Positions) const) &
|
||||
Detector::getModuleId,
|
||||
py::arg() = Positions{})
|
||||
.def("setModuleId",
|
||||
(void (Detector::*)(int, sls::Positions)) & Detector::setModuleId,
|
||||
py::arg(), py::arg() = Positions{})
|
||||
.def("getReceiverVersion",
|
||||
(Result<int64_t>(Detector::*)(sls::Positions) const) &
|
||||
|
@ -280,17 +280,22 @@ u_int16_t getHardwareVersionNumber() {
|
||||
MCB_SERIAL_NO_VRSN_OFST);
|
||||
}
|
||||
|
||||
uint16_t getSerialNumber() {
|
||||
return ((bus_r(MOD_ID_REG) & MOD_ID_MSK) >> MOD_ID_OFST);
|
||||
u_int32_t getDetectorNumber() {
|
||||
#ifdef VIRTUAL
|
||||
return 0;
|
||||
#endif
|
||||
return bus_r(MCB_SERIAL_NO_REG);
|
||||
}
|
||||
|
||||
void setSerialNumber(uint16_t arg) {
|
||||
LOG(logINFOBLUE, ("Setting Serial Number to 0x%x\n", arg));
|
||||
int getModuleId() { return ((bus_r(MOD_ID_REG) & MOD_ID_MSK) >> MOD_ID_OFST); }
|
||||
|
||||
void setModuleId(int arg) {
|
||||
LOG(logINFOBLUE, ("Setting Module Id to 0x%x\n", arg));
|
||||
bus_w(MOD_ID_REG, bus_r(MOD_ID_REG) & ~MOD_ID_MSK);
|
||||
bus_w(MOD_ID_REG, bus_r(MOD_ID_REG) | ((arg << MOD_ID_OFST) & MOD_ID_MSK));
|
||||
}
|
||||
|
||||
int getMaxSerialNumber() { return MOD_MAX_VAL; }
|
||||
int getMaxModuleId() { return MOD_MAX_VAL; }
|
||||
|
||||
u_int64_t getDetectorMAC() {
|
||||
#ifdef VIRTUAL
|
||||
|
@ -94,9 +94,9 @@ void readDetectorNumber();
|
||||
#endif
|
||||
u_int32_t getDetectorNumber();
|
||||
#ifdef GOTTHARD2D
|
||||
uint16_t getSerialNumber();
|
||||
void setSerialNumber(uint16_t arg);
|
||||
int getMaxSerialNumber();
|
||||
int getModuleId();
|
||||
void setModuleId(int arg);
|
||||
int getMaxModuleId();
|
||||
#endif
|
||||
u_int64_t getDetectorMAC();
|
||||
u_int32_t getDetectorIP();
|
||||
|
@ -267,4 +267,5 @@ int set_adc_pipeline(int);
|
||||
int get_adc_pipeline(int);
|
||||
int set_dbit_pipeline(int);
|
||||
int get_dbit_pipeline(int);
|
||||
int set_serial_number(int);
|
||||
int get_module_id(int);
|
||||
int set_module_id(int);
|
@ -392,7 +392,8 @@ void function_table() {
|
||||
flist[F_GET_ADC_PIPELINE] = &get_adc_pipeline;
|
||||
flist[F_SET_DBIT_PIPELINE] = &set_dbit_pipeline;
|
||||
flist[F_GET_DBIT_PIPELINE] = &get_dbit_pipeline;
|
||||
flist[F_SET_SERIAL_NUMBER] = &set_serial_number;
|
||||
flist[F_GET_MODULE_ID] = &get_module_id;
|
||||
flist[F_SET_MODULE_ID] = &set_module_id;
|
||||
|
||||
// check
|
||||
if (NUM_DET_FUNCTIONS >= RECEIVER_ENUM_START) {
|
||||
@ -666,39 +667,11 @@ int get_serial_number(int file_des) {
|
||||
ret = OK;
|
||||
memset(mess, 0, sizeof(mess));
|
||||
int64_t retval = -1;
|
||||
#ifdef GOTTHARD2D
|
||||
retval = getSerialNumber();
|
||||
#else
|
||||
retval = getDetectorNumber();
|
||||
#endif
|
||||
LOG(logDEBUG1, ("detector number retval: 0x%llx\n", (long long int)retval));
|
||||
return Server_SendResult(file_des, INT64, &retval, sizeof(retval));
|
||||
}
|
||||
|
||||
int set_serial_number(int file_des) {
|
||||
ret = OK;
|
||||
memset(mess, 0, sizeof(mess));
|
||||
int64_t arg = -1;
|
||||
|
||||
if (receiveData(file_des, &arg, sizeof(arg), INT64) < 0)
|
||||
return printSocketReadError();
|
||||
LOG(logDEBUG1, ("Setting serial number to 0x%llx\n", (long long int)arg));
|
||||
|
||||
#ifndef GOTTHARD2D
|
||||
functionNotImplemented();
|
||||
#else
|
||||
if (arg > getMaxSerialNumber()) {
|
||||
ret = FAIL;
|
||||
sprintf(mess, "Could not set serial number. Max value: %d\n",
|
||||
getMaxSerialNumber());
|
||||
LOG(logERROR, (mess));
|
||||
} else {
|
||||
setSerialNumber(arg);
|
||||
}
|
||||
#endif
|
||||
return Server_SendResult(file_des, INT64, NULL, 0);
|
||||
}
|
||||
|
||||
int set_firmware_test(int file_des) {
|
||||
ret = OK;
|
||||
memset(mess, 0, sizeof(mess));
|
||||
@ -8952,4 +8925,44 @@ int get_dbit_pipeline(int file_des) {
|
||||
LOG(logDEBUG1, ("retval dbit pipeline: %d\n", retval));
|
||||
#endif
|
||||
return Server_SendResult(file_des, INT32, &retval, sizeof(retval));
|
||||
}
|
||||
|
||||
int get_module_id(int file_des) {
|
||||
ret = OK;
|
||||
memset(mess, 0, sizeof(mess));
|
||||
int retval = -1;
|
||||
#ifndef GOTTHARD2D
|
||||
functionNotImplemented();
|
||||
#else
|
||||
retval = getModuleId();
|
||||
#endif
|
||||
LOG(logDEBUG1, ("module id retval: 0x%x\n", retval));
|
||||
return Server_SendResult(file_des, INT32, &retval, sizeof(retval));
|
||||
}
|
||||
|
||||
int set_module_id(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 module id to 0x%x\n", arg));
|
||||
|
||||
#ifndef GOTTHARD2D
|
||||
functionNotImplemented();
|
||||
#else
|
||||
if (arg > getMaxModuleId()) {
|
||||
ret = FAIL;
|
||||
sprintf(mess, "Could not set module id. Max value: 0x%x\n",
|
||||
getMaxModuleId());
|
||||
LOG(logERROR, (mess));
|
||||
} else {
|
||||
setModuleId(arg);
|
||||
int retval = getModuleId();
|
||||
LOG(logDEBUG1, ("retval module id: %d\n", retval));
|
||||
validate(&ret, mess, arg, retval, "set module id", DEC);
|
||||
}
|
||||
#endif
|
||||
return Server_SendResult(file_des, INT32, NULL, 0);
|
||||
}
|
@ -80,10 +80,12 @@ class Detector {
|
||||
|
||||
Result<int64_t> getSerialNumber(Positions pos = {}) const;
|
||||
|
||||
/** [Gotthard2] Can overwrite and is sent out as mod_id in
|
||||
* sls_detector_header in header of UDP data packet streamed out from
|
||||
* detector.*/
|
||||
void setSerialNumber(const int64_t value, Positions pos = {});
|
||||
/** [Gotthard2] */
|
||||
Result<int> getModuleId(Positions pos = {}) const;
|
||||
|
||||
/** [Gotthard2] 6 bit value (ideally unique) that is "
|
||||
"streamed out1 in the UDP header of the detector. Default is 0. */
|
||||
void setModuleId(const int value, Positions pos = {});
|
||||
|
||||
Result<int64_t> getReceiverVersion(Positions pos = {}) const;
|
||||
|
||||
|
@ -257,33 +257,6 @@ std::string CmdProxy::FirmwareVersion(int action) {
|
||||
return os.str();
|
||||
}
|
||||
|
||||
std::string CmdProxy::SerialNumber(int action) {
|
||||
std::ostringstream os;
|
||||
os << cmd << ' ';
|
||||
if (action == slsDetectorDefs::HELP_ACTION)
|
||||
os << "\n\tSerial number of detector.\n\t[Gotthard2] Can overwrite and "
|
||||
"is sent out as mod_id in sls_detector_header in header of UDP "
|
||||
"data packet streamed out from detector."
|
||||
<< '\n';
|
||||
else if (action == slsDetectorDefs::GET_ACTION) {
|
||||
if (!args.empty()) {
|
||||
WrongNumberOfParameters(0);
|
||||
}
|
||||
auto t = det->getSerialNumber(std::vector<int>{det_id});
|
||||
os << OutStringHex(t) << '\n';
|
||||
} else if (action == slsDetectorDefs::PUT_ACTION) {
|
||||
if (args.size() != 1) {
|
||||
WrongNumberOfParameters(1);
|
||||
}
|
||||
det->setSerialNumber(StringTo<int64_t>(args[0]),
|
||||
std::vector<int>{det_id});
|
||||
os << args[0] << '\n';
|
||||
} else {
|
||||
throw sls::RuntimeError("Unknown action");
|
||||
}
|
||||
return os.str();
|
||||
}
|
||||
|
||||
std::string CmdProxy::Versions(int action) {
|
||||
std::ostringstream os;
|
||||
os << cmd << ' ';
|
||||
|
@ -758,7 +758,8 @@ class CmdProxy {
|
||||
{"firmwareversion", &CmdProxy::FirmwareVersion},
|
||||
{"detectorserverversion", &CmdProxy::detectorserverversion},
|
||||
{"rx_version", &CmdProxy::rx_version},
|
||||
{"serialnumber", &CmdProxy::SerialNumber},
|
||||
{"serialnumber", &CmdProxy::serialnumber},
|
||||
{"moduleid", &CmdProxy::moduleid},
|
||||
{"type", &CmdProxy::type},
|
||||
{"nmod", &CmdProxy::nmod},
|
||||
{"detsize", &CmdProxy::DetectorSize},
|
||||
@ -1078,7 +1079,6 @@ class CmdProxy {
|
||||
std::string Hostname(int action);
|
||||
std::string VirtualServer(int action);
|
||||
std::string FirmwareVersion(int action);
|
||||
std::string SerialNumber(int action);
|
||||
std::string Versions(int action);
|
||||
std::string PackageVersion(int action);
|
||||
std::string ClientVersion(int action);
|
||||
@ -1192,6 +1192,14 @@ class CmdProxy {
|
||||
GET_COMMAND_HEX(rx_version, getReceiverVersion,
|
||||
"\n\tReceiver version in format [0xYYMMDD].");
|
||||
|
||||
GET_COMMAND_HEX(serialnumber, getSerialNumber,
|
||||
"\n\tSerial number of detector.");
|
||||
|
||||
INTEGER_COMMAND_HEX(
|
||||
moduleid, getModuleId, setModuleId, StringTo<int>,
|
||||
"[value]\n\t[Gotthard2] 16 bit value (ideally unique) that is "
|
||||
"streamed out in the UDP header of the detector. Default is 0.");
|
||||
|
||||
GET_COMMAND(type, getDetectorType,
|
||||
"\n\tReturns detector type. Can be Eiger, Jungfrau, Gotthard, "
|
||||
"Moench, Mythen3, Gotthard2, ChipTestBoard");
|
||||
|
@ -119,8 +119,12 @@ Result<int64_t> Detector::getSerialNumber(Positions pos) const {
|
||||
return pimpl->Parallel(&Module::getSerialNumber, pos);
|
||||
}
|
||||
|
||||
void Detector::setSerialNumber(const int64_t value, Positions pos) {
|
||||
pimpl->Parallel(&Module::setSerialNumber, pos, value);
|
||||
Result<int> Detector::getModuleId(Positions pos) const {
|
||||
return pimpl->Parallel(&Module::getModuleId, pos);
|
||||
}
|
||||
|
||||
void Detector::setModuleId(const int value, Positions pos) {
|
||||
pimpl->Parallel(&Module::setModuleId, pos, value);
|
||||
}
|
||||
|
||||
Result<int64_t> Detector::getReceiverVersion(Positions pos) const {
|
||||
|
@ -94,8 +94,10 @@ int64_t Module::getSerialNumber() const {
|
||||
return sendToDetector<int64_t>(F_GET_SERIAL_NUMBER);
|
||||
}
|
||||
|
||||
void Module::setSerialNumber(const int64_t value) {
|
||||
return sendToDetector(F_SET_SERIAL_NUMBER, value, nullptr);
|
||||
int Module::getModuleId() const { return sendToDetector<int>(F_GET_MODULE_ID); }
|
||||
|
||||
void Module::setModuleId(const int value) {
|
||||
return sendToDetector(F_SET_MODULE_ID, value, nullptr);
|
||||
}
|
||||
|
||||
int64_t Module::getReceiverSoftwareVersion() const {
|
||||
|
@ -90,7 +90,8 @@ class Module : public virtual slsDetectorDefs {
|
||||
int64_t getFirmwareVersion() const;
|
||||
int64_t getDetectorServerVersion() const;
|
||||
int64_t getSerialNumber() const;
|
||||
void setSerialNumber(const int64_t value);
|
||||
int getModuleId() const;
|
||||
void setModuleId(const int value);
|
||||
int64_t getReceiverSoftwareVersion() const;
|
||||
static detectorType getTypeFromDetector(const std::string &hostname,
|
||||
int cport = DEFAULT_PORTNO);
|
||||
|
@ -105,21 +105,27 @@ TEST_CASE("serialnumber", "[.cmd]") {
|
||||
Detector det;
|
||||
CmdProxy proxy(&det);
|
||||
REQUIRE_NOTHROW(proxy.Call("serialnumber", {}, -1, GET));
|
||||
}
|
||||
|
||||
TEST_CASE("moduleid", "[.cmd]") {
|
||||
Detector det;
|
||||
CmdProxy proxy(&det);
|
||||
if (det.getDetectorType().squash() == defs::GOTTHARD2) {
|
||||
auto prev_val = det.getSerialNumber();
|
||||
auto prev_val = det.getModuleId();
|
||||
REQUIRE_NOTHROW(proxy.Call("moduleid", {}, -1, GET));
|
||||
std::ostringstream oss1, oss2, oss3;
|
||||
proxy.Call("serialnumber", {"0x5d"}, -1, PUT, oss1);
|
||||
REQUIRE(oss1.str() == "serialnumber 0x5d\n");
|
||||
proxy.Call("serialnumber", {}, -1, GET, oss2);
|
||||
REQUIRE(oss2.str() == "serialnumber 0x5d\n");
|
||||
proxy.Call("serialnumber", {"0xffff"}, -1, PUT, oss3);
|
||||
REQUIRE(oss3.str() == "serialnumber 0xffff\n");
|
||||
REQUIRE_THROWS(proxy.Call("serialnumber", {"65536"}, -1, PUT));
|
||||
proxy.Call("moduleid", {"0x5d"}, -1, PUT, oss1);
|
||||
REQUIRE(oss1.str() == "moduleid 0x5d\n");
|
||||
proxy.Call("moduleid", {}, -1, GET, oss2);
|
||||
REQUIRE(oss2.str() == "moduleid 0x5d\n");
|
||||
proxy.Call("moduleid", {"0xffff"}, -1, PUT, oss3);
|
||||
REQUIRE(oss3.str() == "moduleid 0xffff\n");
|
||||
REQUIRE_THROWS(proxy.Call("moduleid", {"65536"}, -1, PUT));
|
||||
for (int i = 0; i != det.size(); ++i) {
|
||||
det.setSerialNumber(prev_val[i], {i});
|
||||
det.setModuleId(prev_val[i], {i});
|
||||
}
|
||||
} else {
|
||||
REQUIRE_THROWS(proxy.Call("serialnumber", {"0"}, -1, PUT));
|
||||
REQUIRE_THROWS(proxy.Call("moduleid", {"0"}, -1, GET));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -243,7 +243,8 @@ enum detFuncs {
|
||||
F_GET_ADC_PIPELINE,
|
||||
F_SET_DBIT_PIPELINE,
|
||||
F_GET_DBIT_PIPELINE,
|
||||
F_SET_SERIAL_NUMBER,
|
||||
F_GET_MODULE_ID,
|
||||
F_SET_MODULE_ID,
|
||||
|
||||
NUM_DET_FUNCTIONS,
|
||||
RECEIVER_ENUM_START = 256, /**< detector function should not exceed this
|
||||
@ -594,7 +595,8 @@ const char* getFunctionNameFromEnum(enum detFuncs func) {
|
||||
case F_GET_ADC_PIPELINE: return "F_GET_ADC_PIPELINE";
|
||||
case F_SET_DBIT_PIPELINE: return "F_SET_DBIT_PIPELINE";
|
||||
case F_GET_DBIT_PIPELINE: return "F_GET_DBIT_PIPELINE";
|
||||
case F_SET_SERIAL_NUMBER: return "F_SET_SERIAL_NUMBER";
|
||||
case F_GET_MODULE_ID: return "F_GET_MODULE_ID";
|
||||
case F_SET_MODULE_ID: return "F_SET_MODULE_ID";
|
||||
|
||||
case NUM_DET_FUNCTIONS: return "NUM_DET_FUNCTIONS";
|
||||
case RECEIVER_ENUM_START: return "RECEIVER_ENUM_START";
|
||||
|
Loading…
x
Reference in New Issue
Block a user