From c4c16ad9c0e2d74ca64c019c772e3f665cb7c404 Mon Sep 17 00:00:00 2001 From: Dhanya Thattil Date: Tue, 17 Aug 2021 14:05:59 +0200 Subject: [PATCH] wip --- .../include/slsDetectorServer_funcs.h | 4 +- .../src/slsDetectorServer_funcs.c | 146 +++++++++++++++++- slsDetectorSoftware/include/sls/Detector.h | 2 +- slsDetectorSoftware/src/CmdProxy.cpp | 51 ++++-- slsDetectorSoftware/src/Detector.cpp | 2 +- slsDetectorSoftware/src/Module.cpp | 29 ++-- slsDetectorSoftware/src/Module.h | 3 +- slsSupportLib/include/sls/sls_detector_defs.h | 87 ++++++----- .../include/sls/sls_detector_funcs.h | 4 + slsSupportLib/src/ToString.cpp | 36 ++--- 10 files changed, 273 insertions(+), 91 deletions(-) diff --git a/slsDetectorServers/slsDetectorServer/include/slsDetectorServer_funcs.h b/slsDetectorServers/slsDetectorServer/include/slsDetectorServer_funcs.h index ea1c86554..71a0d6858 100644 --- a/slsDetectorServers/slsDetectorServer/include/slsDetectorServer_funcs.h +++ b/slsDetectorServers/slsDetectorServer/include/slsDetectorServer_funcs.h @@ -268,4 +268,6 @@ int get_adc_pipeline(int); int set_dbit_pipeline(int); int get_dbit_pipeline(int); int get_module_id(int); -int set_module_id(int); \ No newline at end of file +int set_module_id(int); +int get_dest_udp_list(int); +int set_dest_udp_list(int); \ No newline at end of file diff --git a/slsDetectorServers/slsDetectorServer/src/slsDetectorServer_funcs.c b/slsDetectorServers/slsDetectorServer/src/slsDetectorServer_funcs.c index 0cd9fcfe0..d36519531 100644 --- a/slsDetectorServers/slsDetectorServer/src/slsDetectorServer_funcs.c +++ b/slsDetectorServers/slsDetectorServer/src/slsDetectorServer_funcs.c @@ -394,6 +394,8 @@ void function_table() { flist[F_GET_DBIT_PIPELINE] = &get_dbit_pipeline; flist[F_GET_MODULE_ID] = &get_module_id; flist[F_SET_MODULE_ID] = &set_module_id; + flist[F_GET_DEST_UDP_LIST] = &get_dest_udp_list; + flist[F_SET_DEST_UDP_LIST] = &set_dest_udp_list; // check if (NUM_DET_FUNCTIONS >= RECEIVER_ENUM_START) { @@ -8977,4 +8979,146 @@ int set_module_id(int file_des) { } #endif return Server_SendResult(file_des, INT32, NULL, 0); -} \ No newline at end of file +} + +int get_dest_udp_list(int file_des) { + ret = OK; + memset(mess, 0, sizeof(mess)); + uint32_t arg = 0; + uint32_t retvals[5] = {0, 0, 0, 0, 0}; + uint64_t retvals64[2] = {0, 0}; + LOG(logDEBUG1, ("Getting udp destination list for entry %d\n", arg)); + +#if !defined(EIGERD) && !defined(JUNGFRAUD) + functionNotImplemented(); +#else + // get only (allow entry 0???? if so, then must talk to receiver) + retvals[] = getCurrentSource(); + LOG(logDEBUG1, ("current source enable retval: %u\n", retvals[0])); +#ifdef JUNGFRAUD + if (retvals[0]) { + retvals[1] = getFixCurrentSource(); + retvals[2] = getNormalCurrentSource(); + retval_select = getSelectCurrentSource(); + } + LOG(logDEBUG1, ("current source parameters retval: [enable:%d fix:%d, " + "normal:%d, select:%lld]\n", + retvals[0], retvals[1], retvals[2], retval_select)); +#endif +#endif + Server_SendResult(file_des, INT32, NULL, 0); + if (ret != FAIL) { + sendData(file_des, retvals, sizeof(retvals), INT32); + sendData(file_des, &retval_select, sizeof(retval_select), INT64); + } + return ret; +} + +int set_dest_udp_list(int file_des) { + ret = OK; + memset(mess, 0, sizeof(mess)); + uint64_t select = 0; + int args[3] = {-1, -1, -1}; + if (receiveData(file_des, args, sizeof(args), INT32) < 0) + return printSocketReadError(); + if (receiveData(file_des, &select, sizeof(select), INT64) < 0) + return printSocketReadError(); + int enable = args[0]; + int fix = args[1]; + int normal = args[2]; + + LOG(logINFOBLUE, ("Setting current source [enable:%d, fix:%d, select:%lld, " + "normal:%d]\n", + enable, fix, (long long int)select, normal)); + +#if !defined(GOTTHARD2D) && !defined(JUNGFRAUD) + functionNotImplemented(); +#else + // only set + if (Server_VerifyLock() == OK) { + if (enable != 0 && enable != 1) { + ret = FAIL; + strcpy(mess, "Could not enable/disable current source. Enable can " + "be 0 or 1 only.\n"); + LOG(logERROR, (mess)); + } + // disable + else if (enable == 0 && (fix != -1 || normal != -1)) { + ret = FAIL; + strcpy( + mess, + "Could not disable current source. Requires no parameters.\n"); + LOG(logERROR, (mess)); + } + // enable + else if (enable == 1) { +#ifdef GOTTHARD2D + // no parameters allowed + if (fix != -1 || normal != -1) { + ret = FAIL; + strcpy(mess, "Could not enable current source. Fix and normal " + "are invalid parameters for this detector.\n"); + LOG(logERROR, (mess)); + } +#else + int chipVersion = getChipVersion(); + if (ret == OK) { + if (chipVersion == 11) { + // require both + if ((fix != 0 && fix != 1) || + (normal != 0 && normal != 1)) { + ret = FAIL; + strcpy(mess, "Could not enable current source. Invalid " + "or insufficient parameters (fix or " + "normal). or Options: 0 or 1.\n"); + LOG(logERROR, (mess)); + } + } + // chipv1.0 + else { + // require only fix + if (fix != 0 && fix != 1) { + ret = FAIL; + strcpy(mess, + "Could not enable current source. Invalid value " + "for parameter (fix). Options: 0 or 1.\n"); + LOG(logERROR, (mess)); + } else if (normal != -1) { + ret = FAIL; + strcpy(mess, "Could not enable current source. Invalid " + "parmaeter (normal). Require only fix and " + "select for chipv1.0.\n"); + LOG(logERROR, (mess)); + } + // select can only be 0-63 + else if (select > MAX_SELECT_CHIP10_VAL) { + ret = FAIL; + strcpy(mess, + "Could not enable current source. Invalid value " + "for parameter (select). Options: 0-63.\n"); + LOG(logERROR, (mess)); + } + } + } +#endif + } + + if (ret == OK) { +#ifdef JUNGFRAUD + if (enable == 0) { + disableCurrentSource(); + } else { + enableCurrentSource(fix, select, normal); + } +#else + setCurrentSource(enable); +#endif + int retval = getCurrentSource(); + LOG(logDEBUG1, ("current source enable retval: %u\n", retval)); + validate(&ret, mess, enable, retval, "set current source enable", + 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 b1cd459af..a79978518 100644 --- a/slsDetectorSoftware/include/sls/Detector.h +++ b/slsDetectorSoftware/include/sls/Detector.h @@ -667,7 +667,7 @@ class Detector { void setSourceUDPMAC2(const MacAddr mac, Positions pos = {}); Result - getDestinationUDPList(const int entry, Positions pos = {}) const; + getDestinationUDPList(const uint32_t entry, Positions pos = {}) const; void setDestinationUDPList(const defs::udpDestination, const int module_id); diff --git a/slsDetectorSoftware/src/CmdProxy.cpp b/slsDetectorSoftware/src/CmdProxy.cpp index 7184236a5..781c1c7c4 100644 --- a/slsDetectorSoftware/src/CmdProxy.cpp +++ b/slsDetectorSoftware/src/CmdProxy.cpp @@ -1380,40 +1380,69 @@ IpAddr CmdProxy::getIpFromAuto() { } defs::udpDestination CmdProxy::getUdpList() { - defs::udpDestination dest{}; + uint32_t entry{}; + uint32_t port{}; + uint32_t port2{}; + uint32_t ip{}; + uint32_t ip2{}; + uint64_t mac{}; + uint64_t mac2{}; + + bool hasEntry = false; + for (auto it : args) { size_t pos = it.find('='); std::string key = it.substr(0, pos); std::string value = it.substr(pos + 1); - if (key == "ip") { + if (key == "entry") { + entry = StringTo(value); + hasEntry = true; + } else if (key == "ip") { if (value == "auto") { auto val = getIpFromAuto(); LOG(logINFO) << "Setting udp_dstip of detector " << det_id << " to " << val; - dest.ip = val.uint32(); + ip = val.uint32(); } else { - dest.ip = IpAddr(value).uint32(); + ip = IpAddr(value).uint32(); } } else if (key == "ip2") { if (value == "auto") { auto val = getIpFromAuto(); LOG(logINFO) << "Setting udp_dstip2 of detector " << det_id << " to " << val; - dest.ip2 = val.uint32(); + ip2 = val.uint32(); } else { - dest.ip2 = IpAddr(value).uint32(); + ip2 = IpAddr(value).uint32(); } } else if (key == "mac") { - dest.mac = MacAddr(value).uint64(); + mac = MacAddr(value).uint64(); } else if (key == "mac2") { - dest.mac2 = MacAddr(value).uint64(); + mac2 = MacAddr(value).uint64(); } else if (key == "port") { - dest.port = StringTo(value); + port = StringTo(value); } else if (key == "port2") { - dest.port2 = StringTo(value); + port2 = StringTo(value); } } - return dest; + // necessary arguments + if (hasEntry && ip != 0 && mac != 0 && port != 0) { + if (ip2 == 0 && mac2 == 0) { + // default (no second interface) + if (port2 == 0) { + return defs::udpDestination(entry, port, ip, mac); + } + // eiger (second udp port) + else { + return defs::udpDestination(entry, port, ip, mac, port2); + } + } + // jungfrau and gotthard2 (second interface) + if (ip2 != 0 && mac2 != 0 && port2 != 0) { + return defs::udpDestination(entry, port, ip, mac, port2, ip2, mac2); + } + } + throw sls::RuntimeError("Insufficient arguments"); } std::string CmdProxy::UDPDestinationList(int action) { diff --git a/slsDetectorSoftware/src/Detector.cpp b/slsDetectorSoftware/src/Detector.cpp index 5dc5279e8..47d1da5bb 100644 --- a/slsDetectorSoftware/src/Detector.cpp +++ b/slsDetectorSoftware/src/Detector.cpp @@ -909,7 +909,7 @@ void Detector::setSourceUDPMAC2(const MacAddr mac, Positions pos) { } Result -Detector::getDestinationUDPList(const int entry, Positions pos) const { +Detector::getDestinationUDPList(const uint32_t entry, Positions pos) const { return pimpl->Parallel(&Module::getDestinationUDPList, pos, entry); } diff --git a/slsDetectorSoftware/src/Module.cpp b/slsDetectorSoftware/src/Module.cpp index 804b3a0df..8c5278ea5 100644 --- a/slsDetectorSoftware/src/Module.cpp +++ b/slsDetectorSoftware/src/Module.cpp @@ -940,21 +940,26 @@ void Module::setSourceUDPMAC2(const sls::MacAddr mac) { } slsDetectorDefs::udpDestination -Module::getDestinationUDPList(const int entry) const { - // return sendToDetector(F_GET_DEST_UDP_LIST); - return bla; +Module::getDestinationUDPList(const uint32_t entry) const { + return sendToDetector(F_GET_DEST_UDP_LIST, entry); } void Module::setDestinationUDPList(const slsDetectorDefs::udpDestination dest) { - LOG(logINFO) << "setting stuff to " << dest; - bla.entry = dest.entry; - bla.ip = dest.ip; - bla.ip2 = dest.ip2; - bla.mac = dest.mac; - bla.mac2 = dest.mac2; - bla.port = dest.port; - bla.port2 = dest.port2; - // sendToDetector(F_SET_DEST_UDP_LIST, dest, nullptr); + // set them in the default way so the receivers are also set up + if (dest.entry_ == 0) { + setDestinationUDPPort(dest.port_); + setDestinationUDPIP(dest.ip_); + setDestinationUDPMAC(dest.mac_); + if (dest.port_ != 0) { + setDestinationUDPPort2(dest.port2_); + } + if (dest.ip2_ != 0) { + setDestinationUDPIP2(dest.ip2_); + setDestinationUDPMAC2(dest.mac2_); + } + } else { + sendToDetector(F_SET_DEST_UDP_LIST, dest, nullptr); + } } sls::IpAddr Module::getDestinationUDPIP() const { diff --git a/slsDetectorSoftware/src/Module.h b/slsDetectorSoftware/src/Module.h index d03470f0b..9bfc57b1e 100644 --- a/slsDetectorSoftware/src/Module.h +++ b/slsDetectorSoftware/src/Module.h @@ -222,7 +222,7 @@ class Module : public virtual slsDetectorDefs { void setSourceUDPMAC(const sls::MacAddr mac); sls::MacAddr getSourceUDPMAC2() const; void setSourceUDPMAC2(const sls::MacAddr mac); - udpDestination getDestinationUDPList(const int entry) const; + udpDestination getDestinationUDPList(const uint32_t entry) const; void setDestinationUDPList(const defs::udpDestination dest); sls::IpAddr getDestinationUDPIP() const; void setDestinationUDPIP(const sls::IpAddr ip); @@ -745,7 +745,6 @@ class Module : public virtual slsDetectorDefs { const int moduleId; mutable sls::SharedMemory shm{0, 0}; - udpDestination bla{}; }; } // namespace sls \ No newline at end of file diff --git a/slsSupportLib/include/sls/sls_detector_defs.h b/slsSupportLib/include/sls/sls_detector_defs.h index 3408b5457..6b8049b80 100644 --- a/slsSupportLib/include/sls/sls_detector_defs.h +++ b/slsSupportLib/include/sls/sls_detector_defs.h @@ -457,64 +457,63 @@ typedef struct { } __attribute__((packed)); struct currentSrcParameters { - int enable; - int fix; - int normal; - uint64_t select; + int enable_; + int fix_; + int normal_; + uint64_t select_; /** [Gotthard2][Jungfrau] disable */ - currentSrcParameters() : enable(0), fix(-1), normal(-1), select(0) {} + currentSrcParameters() + : enable_(0), fix_(-1), normal_(-1), select_(0) {} /** [Gotthard2] enable or disable */ - explicit currentSrcParameters(bool ena) - : enable(static_cast(ena)), fix(-1), normal(-1), select(0) {} + explicit currentSrcParameters(bool enable) + : enable_(static_cast(enable)), fix_(-1), normal_(-1), + select_(0) {} /** [Jungfrau](chipv1.0) enable current src with fix or no fix, - * selectColumn is 0 to 63 columns only */ - currentSrcParameters(bool fixCurrent, uint64_t selectColumn) - : enable(1), fix(static_cast(fixCurrent)), normal(-1), - select(selectColumn) {} + * select is 0 to 63 columns only */ + currentSrcParameters(bool fix, uint64_t select) + : enable_(1), fix_(static_cast(fix)), normal_(-1), + select_(select) {} - /** [Jungfrau](chipv1.1) enable current src, fixCurrent[fix|no fix], - * selectColumn is a mask of 63 bits (muliple columns can be selected - * simultaneously, normalCurrent [normal|low] */ - currentSrcParameters(bool fixCurrent, uint64_t selectColumn, - bool normalCurrent) - : enable(1), fix(static_cast(fixCurrent)), - normal(static_cast(normalCurrent)), select(selectColumn) {} + /** [Jungfrau](chipv1.1) enable current src, fix[fix|no fix], + * select is a mask of 63 bits (muliple columns can be selected + * simultaneously, normal [normal|low] */ + currentSrcParameters(bool fix, uint64_t select, bool normal) + : enable_(1), fix_(static_cast(fix)), + normal_(static_cast(normal)), select_(select) {} bool operator==(const currentSrcParameters &other) const { - return ((enable == other.enable) && (fix == other.fix) && - (normal == other.normal) && (select == other.select)); + return ((enable_ == other.enable_) && (fix_ == other.fix_) && + (normal_ == other.normal_) && (select_ == other.select_)); } } __attribute__((packed)); struct udpDestination { - int entry; - uint32_t ip{}; - uint32_t ip2{}; - uint64_t mac{}; - uint64_t mac2{}; - int port{}; - int port2{}; - udpDestination(); + uint32_t entry_{}; + uint32_t port_{}; + uint32_t port2_{}; + uint32_t ip_{}; + uint32_t ip2_{}; + uint64_t mac_{}; + uint64_t mac2_{}; + udpDestination() {} + udpDestination(uint32_t entry, uint32_t port, uint32_t ip, uint64_t mac) + : entry_(entry), port_(port), ip_(ip), mac_(mac) {} + udpDestination(uint32_t entry, uint32_t port, uint32_t ip, uint64_t mac, + uint32_t port2) + : entry_(entry), port_(port), port2_(port2), ip_(ip), mac_(mac) {} + udpDestination(uint32_t entry, uint32_t port, uint32_t ip, uint64_t mac, + uint32_t port2, uint32_t ip2, uint64_t mac2) + : entry_(entry), port_(port), port2_(port2), ip_(ip), ip2_(ip2), + mac_(mac), mac2_(mac2) {} + bool operator==(const udpDestination &other) const { - return ((entry == other.entry) && (ip == other.ip) && - (ip2 == other.ip2) && (mac == other.mac) && - (mac2 == other.mac2) && (port == other.port) && - (port2 == other.port2)); - } - udpDestination operator=(const udpDestination &other) const { - if (this == &other) - return *this; - entry = other.entry; - ip = other.ip; - ip2 = other.ip2; - mac = other.mac; - mac2 = other.mac2; - port = other.port; - port2 = other.port2; - return *this; + return ((entry_ == other.entry_) && (port_ == other.port_) && + (port2_ == other.port2_) && (ip_ == other.ip_) && + (ip2_ == other.ip2_) && (mac_ == other.mac_) && + (mac2_ == other.mac2_)); } } __attribute__((packed)); diff --git a/slsSupportLib/include/sls/sls_detector_funcs.h b/slsSupportLib/include/sls/sls_detector_funcs.h index 0c1cf104d..c557f69b1 100755 --- a/slsSupportLib/include/sls/sls_detector_funcs.h +++ b/slsSupportLib/include/sls/sls_detector_funcs.h @@ -245,6 +245,8 @@ enum detFuncs { F_GET_DBIT_PIPELINE, F_GET_MODULE_ID, F_SET_MODULE_ID, + F_GET_DEST_UDP_LIST, + F_SET_DEST_UDP_LIST, NUM_DET_FUNCTIONS, RECEIVER_ENUM_START = 256, /**< detector function should not exceed this @@ -597,6 +599,8 @@ const char* getFunctionNameFromEnum(enum detFuncs func) { case F_GET_DBIT_PIPELINE: return "F_GET_DBIT_PIPELINE"; case F_GET_MODULE_ID: return "F_GET_MODULE_ID"; case F_SET_MODULE_ID: return "F_SET_MODULE_ID"; + case F_GET_DEST_UDP_LIST: return "F_GET_DEST_UDP_LIST"; + case F_SET_DEST_UDP_LIST: return "F_SET_DEST_UDP_LIST"; case NUM_DET_FUNCTIONS: return "NUM_DET_FUNCTIONS"; case RECEIVER_ENUM_START: return "RECEIVER_ENUM_START"; diff --git a/slsSupportLib/src/ToString.cpp b/slsSupportLib/src/ToString.cpp index 64c60d7d2..fddff9aa6 100644 --- a/slsSupportLib/src/ToString.cpp +++ b/slsSupportLib/src/ToString.cpp @@ -116,25 +116,25 @@ std::ostream &operator<<(std::ostream &os, std::string ToString(const slsDetectorDefs::currentSrcParameters &r) { std::ostringstream oss; - if (r.fix < -1 || r.fix > 1 || r.normal < -1 || r.normal > 1) { + if (r.fix_ < -1 || r.fix_ > 1 || r.normal_ < -1 || r.normal_ > 1) { throw sls::RuntimeError( "Invalid current source parameters. Cannot print."); } oss << '['; - if (r.enable) { + if (r.enable_) { oss << "enabled"; // [jungfrau] - if (r.fix != -1) { - oss << (r.fix == 1 ? ", fix" : ", nofix"); + if (r.fix_ != -1) { + oss << (r.fix_ == 1 ? ", fix" : ", nofix"); } // [jungfrau chip v1.1] - if (r.normal != -1) { - oss << ", " << ToStringHex(r.select, 16); - oss << (r.normal == 1 ? ", normal" : ", low"); + if (r.normal_ != -1) { + oss << ", " << ToStringHex(r.select_, 16); + oss << (r.normal_ == 1 ? ", normal" : ", low"); } // [jungfrau chip v1.0] else { - oss << ", " << r.select; + oss << ", " << r.select_; } } else { oss << "disabled"; @@ -151,18 +151,18 @@ std::ostream &operator<<(std::ostream &os, std::string ToString(const slsDetectorDefs::udpDestination &r) { std::ostringstream oss; oss << '[' << std::endl - << "entry " << r.entry << std::endl - << "ip " << IpAddr(r.ip) << std::endl - << "mac " << MacAddr(r.mac) << std::endl - << "port " << r.port << std::endl; - if (r.port2 != 0) { - oss << "port2 " << r.port2 << std::endl; + << "entry " << r.entry_ << std::endl + << "ip " << IpAddr(r.ip_) << std::endl + << "mac " << MacAddr(r.mac_) << std::endl + << "port " << r.port_ << std::endl; + if (r.port2_ != 0) { + oss << "port2 " << r.port2_ << std::endl; } - if (r.ip2 != 0) { - oss << "ip2 " << IpAddr(r.ip2) << std::endl; + if (r.ip2_ != 0) { + oss << "ip2 " << IpAddr(r.ip2_) << std::endl; } - if (r.mac2 != 0) { - oss << "mac2 " << MacAddr(r.mac2) << std::endl; + if (r.mac2_ != 0) { + oss << "mac2 " << MacAddr(r.mac2_) << std::endl; } oss << ']'; return oss.str();