diff --git a/python/slsdet/utils.py b/python/slsdet/utils.py index ae7de4815..f7d4fbd9d 100755 --- a/python/slsdet/utils.py +++ b/python/slsdet/utils.py @@ -41,7 +41,7 @@ def list_to_bitmask(values): return mask def make_bitmask(args): - if isinstance(args, list): + if isinstance(args, (list,tuple)): return list_to_bitmask(args) elif isinstance(args, dict): return {key: list_to_bitmask(value) for key, value in args.items()} diff --git a/python/src/detector.cpp b/python/src/detector.cpp index 337630046..f34c141fd 100644 --- a/python/src/detector.cpp +++ b/python/src/detector.cpp @@ -73,9 +73,6 @@ void init_det(py::module &m) { (Result(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(Detector::*)(sls::Positions) const) & Detector::getReceiverVersion, diff --git a/slsDetectorServers/ctbDetectorServer/bin/ctbDetectorServer_developer b/slsDetectorServers/ctbDetectorServer/bin/ctbDetectorServer_developer index 6ed2072cd..378ff747b 100755 Binary files a/slsDetectorServers/ctbDetectorServer/bin/ctbDetectorServer_developer and b/slsDetectorServers/ctbDetectorServer/bin/ctbDetectorServer_developer differ diff --git a/slsDetectorServers/ctbDetectorServer/slsDetectorFunctionList.c b/slsDetectorServers/ctbDetectorServer/slsDetectorFunctionList.c index 7c65c6bf0..e7f57a896 100644 --- a/slsDetectorServers/ctbDetectorServer/slsDetectorFunctionList.c +++ b/slsDetectorServers/ctbDetectorServer/slsDetectorFunctionList.c @@ -392,7 +392,7 @@ uint32_t getDetectorIP() { #ifdef VIRTUAL return 0; #endif - char temp[50] = ""; + char temp[INET_ADDRSTRLEN] = ""; uint32_t res = 0; // execute and get address char output[255]; @@ -1525,10 +1525,10 @@ int configureMAC() { int dstport = udpDetails[0].dstport; LOG(logINFOBLUE, ("Configuring MAC\n")); - char src_mac[50], src_ip[INET_ADDRSTRLEN], dst_mac[50], - dst_ip[INET_ADDRSTRLEN]; - getMacAddressinString(src_mac, 50, srcmac); - getMacAddressinString(dst_mac, 50, dstmac); + char src_mac[MAC_ADDRESS_SIZE], src_ip[INET_ADDRSTRLEN], + dst_mac[MAC_ADDRESS_SIZE], dst_ip[INET_ADDRSTRLEN]; + getMacAddressinString(src_mac, MAC_ADDRESS_SIZE, srcmac); + getMacAddressinString(dst_mac, MAC_ADDRESS_SIZE, dstmac); getIpAddressinString(src_ip, srcip); getIpAddressinString(dst_ip, dstip); diff --git a/slsDetectorServers/eigerDetectorServer/bin/eigerDetectorServer_developer b/slsDetectorServers/eigerDetectorServer/bin/eigerDetectorServer_developer index 100ec1ffd..0b6c2bff1 100755 Binary files a/slsDetectorServers/eigerDetectorServer/bin/eigerDetectorServer_developer and b/slsDetectorServers/eigerDetectorServer/bin/eigerDetectorServer_developer differ diff --git a/slsDetectorServers/eigerDetectorServer/slsDetectorFunctionList.c b/slsDetectorServers/eigerDetectorServer/slsDetectorFunctionList.c index 0bfdcfb31..eb44e5aaa 100644 --- a/slsDetectorServers/eigerDetectorServer/slsDetectorFunctionList.c +++ b/slsDetectorServers/eigerDetectorServer/slsDetectorFunctionList.c @@ -263,7 +263,7 @@ u_int64_t getDetectorMAC() { } u_int32_t getDetectorIP() { - char temp[50] = ""; + char temp[INET_ADDRSTRLEN] = ""; u_int32_t res = 0; // execute and get address char output[255]; @@ -303,7 +303,7 @@ void initControlServer() { LOG(logINFOBLUE, ("Configuring Control server\n")); if (!updateFlag && initError == OK) { #ifndef VIRTUAL - int detid = getModuleIdInFile(&initError, initErrorMessage, ID_FILE); + int modid = getModuleIdInFile(&initError, initErrorMessage, ID_FILE); #else getModuleIdInFile(&initError, initErrorMessage, ID_FILE); #endif @@ -342,7 +342,7 @@ void initControlServer() { LOG(logDEBUG1, ("Control server: FEB Initialization done\n")); Beb_SetTopVariable(top); Beb_Beb(); - Beb_SetModuleId(detid); + Beb_SetModuleId(modid); LOG(logDEBUG1, ("Control server: BEB Initialization done\n")); #endif // also reads config file and deactivates @@ -1531,10 +1531,10 @@ int configureMAC() { int dstport = udpDetails[iRxEntry].dstport; int dstport2 = udpDetails[iRxEntry].dstport2; - char src_mac[50], src_ip[INET_ADDRSTRLEN], dst_mac[50], - dst_ip[INET_ADDRSTRLEN]; - getMacAddressinString(src_mac, 50, srcmac); - getMacAddressinString(dst_mac, 50, dstmac); + char src_mac[MAC_ADDRESS_SIZE], src_ip[INET_ADDRSTRLEN], + dst_mac[MAC_ADDRESS_SIZE], dst_ip[INET_ADDRSTRLEN]; + getMacAddressinString(src_mac, MAC_ADDRESS_SIZE, srcmac); + getMacAddressinString(dst_mac, MAC_ADDRESS_SIZE, dstmac); getIpAddressinString(src_ip, srcip); getIpAddressinString(dst_ip, dstip); diff --git a/slsDetectorServers/gotthard2DetectorServer/bin/gotthard2DetectorServer_developer b/slsDetectorServers/gotthard2DetectorServer/bin/gotthard2DetectorServer_developer index db76d95d8..851a71620 100755 Binary files a/slsDetectorServers/gotthard2DetectorServer/bin/gotthard2DetectorServer_developer and b/slsDetectorServers/gotthard2DetectorServer/bin/gotthard2DetectorServer_developer differ diff --git a/slsDetectorServers/gotthard2DetectorServer/slsDetectorFunctionList.c b/slsDetectorServers/gotthard2DetectorServer/slsDetectorFunctionList.c index 084a50951..8c45ae8ed 100644 --- a/slsDetectorServers/gotthard2DetectorServer/slsDetectorFunctionList.c +++ b/slsDetectorServers/gotthard2DetectorServer/slsDetectorFunctionList.c @@ -288,16 +288,13 @@ u_int32_t getDetectorNumber() { } int getModuleId(int *ret, char *mess) { - return getModuleIdInFile(ret, mess, ID_FILE); + return ((bus_r(MOD_ID_REG) & ~MOD_ID_MSK) >> MOD_ID_OFST); } -void setModuleId(int *ret, char *mess, int arg) { - *ret = setModuleIdInFile(mess, arg, ID_FILE); - if (*ret == FAIL) { - return; - } +void setModuleId(int modid) { + LOG(logINFOBLUE, ("Setting module id in fpga: %d\n", modid)) 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)); + bus_w(MOD_ID_REG, bus_r(MOD_ID_REG) | ((modid << MOD_ID_OFST) & MOD_ID_MSK)); } u_int64_t getDetectorMAC() { @@ -326,7 +323,7 @@ u_int32_t getDetectorIP() { #ifdef VIRTUAL return 0; #endif - char temp[50] = ""; + char temp[INET_ADDRSTRLEN] = ""; u_int32_t res = 0; // execute and get address char output[255]; @@ -422,10 +419,6 @@ void setupDetector() { sharedMemory_setStatus(IDLE); setupUDPCommParameters(); #endif - getModuleIdInFile(&initError, initErrorMessage, ID_FILE); - if (initError == FAIL) { - return; - } // pll defines ALTERA_PLL_C10_SetDefines(REG_OFFSET, BASE_READOUT_PLL, BASE_SYSTEM_PLL, PLL_RESET_REG, PLL_RESET_READOUT_MSK, @@ -483,6 +476,14 @@ void setupDetector() { if (readConfigFile() == FAIL) { return; } + + // set module id in register + int modid = getModuleIdInFile(&initError, initErrorMessage, ID_FILE); + if (initError == FAIL) { + return; + } + setModuleId(modid); + setBurstMode(DEFAULT_BURST_MODE); setFilterResistor(DEFAULT_FILTER_RESISTOR); setCDSGain(DEFAILT_CDS_GAIN); @@ -1749,16 +1750,16 @@ int configureMAC() { int dstport2 = udpDetails[0].dstport2; LOG(logINFOBLUE, ("Configuring MAC\n")); - char src_mac[50], src_ip[INET_ADDRSTRLEN], dst_mac[50], - dst_ip[INET_ADDRSTRLEN]; - getMacAddressinString(src_mac, 50, srcmac); - getMacAddressinString(dst_mac, 50, dstmac); + char src_mac[MAC_ADDRESS_SIZE], src_ip[INET_ADDRSTRLEN], + dst_mac[MAC_ADDRESS_SIZE], dst_ip[INET_ADDRSTRLEN]; + getMacAddressinString(src_mac, MAC_ADDRESS_SIZE, srcmac); + getMacAddressinString(dst_mac, MAC_ADDRESS_SIZE, dstmac); getIpAddressinString(src_ip, srcip); getIpAddressinString(dst_ip, dstip); - char src_mac2[50], src_ip2[INET_ADDRSTRLEN], dst_mac2[50], - dst_ip2[INET_ADDRSTRLEN]; - getMacAddressinString(src_mac2, 50, srcmac2); - getMacAddressinString(dst_mac2, 50, dstmac2); + char src_mac2[MAC_ADDRESS_SIZE], src_ip2[INET_ADDRSTRLEN], + dst_mac2[MAC_ADDRESS_SIZE], dst_ip2[INET_ADDRSTRLEN]; + getMacAddressinString(src_mac2, MAC_ADDRESS_SIZE, srcmac2); + getMacAddressinString(dst_mac2, MAC_ADDRESS_SIZE, dstmac2); getIpAddressinString(src_ip2, srcip2); getIpAddressinString(dst_ip2, dstip2); diff --git a/slsDetectorServers/gotthardDetectorServer/bin/gotthardDetectorServer_developer b/slsDetectorServers/gotthardDetectorServer/bin/gotthardDetectorServer_developer index ccb2bc6cd..08db997a4 100755 Binary files a/slsDetectorServers/gotthardDetectorServer/bin/gotthardDetectorServer_developer and b/slsDetectorServers/gotthardDetectorServer/bin/gotthardDetectorServer_developer differ diff --git a/slsDetectorServers/gotthardDetectorServer/slsDetectorFunctionList.c b/slsDetectorServers/gotthardDetectorServer/slsDetectorFunctionList.c index 453493943..895042dd6 100644 --- a/slsDetectorServers/gotthardDetectorServer/slsDetectorFunctionList.c +++ b/slsDetectorServers/gotthardDetectorServer/slsDetectorFunctionList.c @@ -315,7 +315,7 @@ u_int32_t getDetectorIP() { #ifdef VIRTUAL return 0; #endif - char temp[50] = ""; + char temp[INET_ADDRSTRLEN] = ""; u_int32_t res = 0; // execute and get address char output[255]; @@ -1340,10 +1340,10 @@ int configureMAC() { int dstport = udpDetails[0].dstport; LOG(logINFOBLUE, ("Configuring MAC\n")); - char src_mac[50], src_ip[INET_ADDRSTRLEN], dst_mac[50], - dst_ip[INET_ADDRSTRLEN]; - getMacAddressinString(src_mac, 50, srcmac); - getMacAddressinString(dst_mac, 50, dstmac); + char src_mac[MAC_ADDRESS_SIZE], src_ip[INET_ADDRSTRLEN], + dst_mac[MAC_ADDRESS_SIZE], dst_ip[INET_ADDRSTRLEN]; + getMacAddressinString(src_mac, MAC_ADDRESS_SIZE, srcmac); + getMacAddressinString(dst_mac, MAC_ADDRESS_SIZE, dstmac); getIpAddressinString(src_ip, srcip); getIpAddressinString(dst_ip, dstip); diff --git a/slsDetectorServers/jungfrauDetectorServer/bin/jungfrauDetectorServer_developer b/slsDetectorServers/jungfrauDetectorServer/bin/jungfrauDetectorServer_developer index 229aeb1ac..b46df8aa2 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 efeb45544..a63984352 100644 --- a/slsDetectorServers/jungfrauDetectorServer/slsDetectorFunctionList.c +++ b/slsDetectorServers/jungfrauDetectorServer/slsDetectorFunctionList.c @@ -52,9 +52,6 @@ int detPos[4] = {}; int chipVersion = 10; // (1.0) int chipConfigured = 0; -// until firmware is done -int temp_readNRows = 512; - int isInitCheckDone() { return initCheckDone; } int getInitResult(char **mess) { @@ -337,7 +334,7 @@ u_int32_t getDetectorIP() { #ifdef VIRTUAL return 0; #endif - char temp[50] = ""; + char temp[INET_ADDRSTRLEN] = ""; u_int32_t res = 0; // execute and get address char output[255]; @@ -1480,16 +1477,16 @@ int configureMAC() { int dstport = udpDetails[iRxEntry].dstport; int dstport2 = udpDetails[iRxEntry].dstport2; - char src_mac[50], src_ip[INET_ADDRSTRLEN], dst_mac[50], - dst_ip[INET_ADDRSTRLEN]; - getMacAddressinString(src_mac, 50, srcmac); - getMacAddressinString(dst_mac, 50, dstmac); + char src_mac[MAC_ADDRESS_SIZE], src_ip[INET_ADDRSTRLEN], + dst_mac[MAC_ADDRESS_SIZE], dst_ip[INET_ADDRSTRLEN]; + getMacAddressinString(src_mac, MAC_ADDRESS_SIZE, srcmac); + getMacAddressinString(dst_mac, MAC_ADDRESS_SIZE, dstmac); getIpAddressinString(src_ip, srcip); getIpAddressinString(dst_ip, dstip); - char src_mac2[50], src_ip2[INET_ADDRSTRLEN], dst_mac2[50], - dst_ip2[INET_ADDRSTRLEN]; - getMacAddressinString(src_mac2, 50, srcmac2); - getMacAddressinString(dst_mac2, 50, dstmac2); + char src_mac2[MAC_ADDRESS_SIZE], src_ip2[INET_ADDRSTRLEN], + dst_mac2[MAC_ADDRESS_SIZE], dst_ip2[INET_ADDRSTRLEN]; + getMacAddressinString(src_mac2, MAC_ADDRESS_SIZE, srcmac2); + getMacAddressinString(dst_mac2, MAC_ADDRESS_SIZE, dstmac2); getIpAddressinString(src_ip2, srcip2); getIpAddressinString(dst_ip2, dstip2); @@ -1642,11 +1639,6 @@ int setReadNRows(int value) { return FAIL; } - // will be replaced when firmware is fixed - LOG(logWARNING, ("Setting number of rows: %d (Not implemented in firmware yet)\n", value)); - temp_readNRows = value; - return OK; - // regval is numpackets - 1 int regval = (value / READ_N_ROWS_MULTIPLE) - 1; uint32_t addr = READ_N_ROWS_REG; @@ -1665,10 +1657,6 @@ int setReadNRows(int value) { } int getReadNRows() { - - // will be replaced when firmware is fixed - return temp_readNRows; - int enable = (bus_r(READ_N_ROWS_REG) & READ_N_ROWS_ENBL_MSK); int regval = ((bus_r(READ_N_ROWS_REG) & READ_N_ROWS_NUM_ROWS_MSK) >> READ_N_ROWS_NUM_ROWS_OFST); diff --git a/slsDetectorServers/moenchDetectorServer/bin/moenchDetectorServer_developer b/slsDetectorServers/moenchDetectorServer/bin/moenchDetectorServer_developer index 83f6521bd..8342753d5 100755 Binary files a/slsDetectorServers/moenchDetectorServer/bin/moenchDetectorServer_developer and b/slsDetectorServers/moenchDetectorServer/bin/moenchDetectorServer_developer differ diff --git a/slsDetectorServers/moenchDetectorServer/slsDetectorFunctionList.c b/slsDetectorServers/moenchDetectorServer/slsDetectorFunctionList.c index 45bda6da6..bdda08571 100644 --- a/slsDetectorServers/moenchDetectorServer/slsDetectorFunctionList.c +++ b/slsDetectorServers/moenchDetectorServer/slsDetectorFunctionList.c @@ -389,7 +389,7 @@ uint32_t getDetectorIP() { #ifdef VIRTUAL return 0; #endif - char temp[50] = ""; + char temp[INET_ADDRSTRLEN] = ""; uint32_t res = 0; // execute and get address char output[255]; @@ -1190,10 +1190,10 @@ int configureMAC() { int dstport = udpDetails[0].dstport; LOG(logINFOBLUE, ("Configuring MAC\n")); - char src_mac[50], src_ip[INET_ADDRSTRLEN], dst_mac[50], - dst_ip[INET_ADDRSTRLEN]; - getMacAddressinString(src_mac, 50, srcmac); - getMacAddressinString(dst_mac, 50, dstmac); + char src_mac[MAC_ADDRESS_SIZE], src_ip[INET_ADDRSTRLEN], + dst_mac[MAC_ADDRESS_SIZE], dst_ip[INET_ADDRSTRLEN]; + getMacAddressinString(src_mac, MAC_ADDRESS_SIZE, srcmac); + getMacAddressinString(dst_mac, MAC_ADDRESS_SIZE, dstmac); getIpAddressinString(src_ip, srcip); getIpAddressinString(dst_ip, dstip); diff --git a/slsDetectorServers/mythen3DetectorServer/bin/mythen3DetectorServer_developer b/slsDetectorServers/mythen3DetectorServer/bin/mythen3DetectorServer_developer index b556b89d4..03ef8baef 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 6d3a22451..3d8c99b13 100644 --- a/slsDetectorServers/mythen3DetectorServer/slsDetectorFunctionList.c +++ b/slsDetectorServers/mythen3DetectorServer/slsDetectorFunctionList.c @@ -312,7 +312,7 @@ u_int32_t getDetectorIP() { #ifdef VIRTUAL return 0; #endif - char temp[50] = ""; + char temp[INET_ADDRSTRLEN] = ""; u_int32_t res = 0; // execute and get address char output[255]; @@ -444,6 +444,14 @@ void setupDetector() { setASICDefaults(); setADIFDefaults(); + // set module id in register + getModuleIdInFile(&initError, initErrorMessage, ID_FILE); + if (initError == FAIL) { + return; + } + // until firmware is done + // setModuleId(modid); + // set trigger flow for m3 (for all timing modes) bus_w(FLOW_TRIGGER_REG, bus_r(FLOW_TRIGGER_REG) | FLOW_TRIGGER_MSK); @@ -1720,10 +1728,10 @@ int configureMAC() { int dstport = udpDetails[0].dstport; LOG(logINFOBLUE, ("Configuring MAC\n")); - char src_mac[50], src_ip[INET_ADDRSTRLEN], dst_mac[50], - dst_ip[INET_ADDRSTRLEN]; - getMacAddressinString(src_mac, 50, srcmac); - getMacAddressinString(dst_mac, 50, dstmac); + char src_mac[MAC_ADDRESS_SIZE], src_ip[INET_ADDRSTRLEN], + dst_mac[MAC_ADDRESS_SIZE], dst_ip[INET_ADDRSTRLEN]; + getMacAddressinString(src_mac, MAC_ADDRESS_SIZE, srcmac); + getMacAddressinString(dst_mac, MAC_ADDRESS_SIZE, dstmac); getIpAddressinString(src_ip, srcip); getIpAddressinString(dst_ip, dstip); diff --git a/slsDetectorServers/slsDetectorServer/include/slsDetectorFunctionList.h b/slsDetectorServers/slsDetectorServer/include/slsDetectorFunctionList.h index 447d94ca5..8614e7672 100644 --- a/slsDetectorServers/slsDetectorServer/include/slsDetectorFunctionList.h +++ b/slsDetectorServers/slsDetectorServer/include/slsDetectorFunctionList.h @@ -52,6 +52,7 @@ typedef struct udpStruct_s { uint32_t dstip; uint32_t dstip2; } udpStruct; +#define MAC_ADDRESS_SIZE 18 // basic tests int isInitCheckDone(); @@ -96,7 +97,7 @@ u_int32_t getDetectorNumber(); int getModuleId(int *ret, char *mess); #endif #ifdef GOTTHARD2D -void setModuleId(int *ret, char *mess, int arg); +void setModuleId(int modid); #endif u_int64_t getDetectorMAC(); u_int32_t getDetectorIP(); diff --git a/slsDetectorServers/slsDetectorServer/include/slsDetectorServer_funcs.h b/slsDetectorServers/slsDetectorServer/include/slsDetectorServer_funcs.h index 521b56ba3..da20ee922 100644 --- a/slsDetectorServers/slsDetectorServer/include/slsDetectorServer_funcs.h +++ b/slsDetectorServers/slsDetectorServer/include/slsDetectorServer_funcs.h @@ -268,7 +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); int get_dest_udp_list(int); int set_dest_udp_list(int); int get_num_dest_list(int); diff --git a/slsDetectorServers/slsDetectorServer/src/slsDetectorServer_funcs.c b/slsDetectorServers/slsDetectorServer/src/slsDetectorServer_funcs.c index f3e519edd..28372f103 100644 --- a/slsDetectorServers/slsDetectorServer/src/slsDetectorServer_funcs.c +++ b/slsDetectorServers/slsDetectorServer/src/slsDetectorServer_funcs.c @@ -404,7 +404,6 @@ void function_table() { flist[F_SET_DBIT_PIPELINE] = &set_dbit_pipeline; 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; flist[F_GET_NUM_DEST_UDP] = &get_num_dest_list; @@ -1760,8 +1759,8 @@ int acquire(int blocking, int file_des) { if (udpDetails[0].srcmac != getDetectorMAC()) { ret = FAIL; uint64_t sourcemac = getDetectorMAC(); - char src_mac[50]; - getMacAddressinString(src_mac, 50, sourcemac); + char src_mac[MAC_ADDRESS_SIZE]; + getMacAddressinString(src_mac, MAC_ADDRESS_SIZE, sourcemac); sprintf(mess, "Invalid udp source mac address for this detector. Must be " "same as hardware detector mac address %s\n", @@ -4875,8 +4874,8 @@ void calculate_and_set_position() { else { // create detector mac from x and y if (udpDetails[0].srcmac == 0) { - char dmac[50]; - memset(dmac, 0, 50); + char dmac[MAC_ADDRESS_SIZE]; + memset(dmac, 0, MAC_ADDRESS_SIZE); sprintf(dmac, "aa:bb:cc:dd:%02x:%02x", pos[0] & 0xFF, pos[1] & 0xFF); LOG(logINFO, ("Udp source mac address created: %s\n", dmac)); @@ -4895,8 +4894,8 @@ void calculate_and_set_position() { #if defined(JUNGFRAUD) || defined(GOTTHARD2D) if (getNumberofUDPInterfaces() > 1) { if (udpDetails[0].srcmac2 == 0) { - char dmac2[50]; - memset(dmac2, 0, 50); + char dmac2[MAC_ADDRESS_SIZE]; + memset(dmac2, 0, MAC_ADDRESS_SIZE); sprintf(dmac2, "aa:bb:cc:dd:%02x:%02x", (pos[0] + 1) & 0xFF, pos[1] & 0xFF); LOG(logINFO, ("Udp source mac address2 created: %s\n", dmac2)); @@ -9034,34 +9033,6 @@ int get_module_id(int file_des) { 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 > 0xFFFF) { - ret = FAIL; - sprintf(mess, "Could not set module id. Max value: 0x%x\n", 0xFFFF); - LOG(logERROR, (mess)); - } else { - setModuleId(&ret, mess, arg); - if (ret != FAIL) { - int retval = getModuleId(&ret, mess); - 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); -} - int get_dest_udp_list(int file_des) { ret = OK; memset(mess, 0, sizeof(mess)); @@ -9100,9 +9071,9 @@ int get_dest_udp_list(int file_des) { char ip[INET_ADDRSTRLEN], ip2[INET_ADDRSTRLEN]; getIpAddressinString(ip, retvals[3]); getIpAddressinString(ip2, retvals[4]); - char mac[50], mac2[50]; - getMacAddressinString(mac, 50, retvals64[0]); - getMacAddressinString(mac2, 50, retvals64[1]); + char mac[MAC_ADDRESS_SIZE], mac2[MAC_ADDRESS_SIZE]; + getMacAddressinString(mac, MAC_ADDRESS_SIZE, retvals64[0]); + getMacAddressinString(mac2, MAC_ADDRESS_SIZE, retvals64[1]); LOG(logDEBUG1, ("Udp Dest. retval [%d]: [port %d, port2 %d, ip %s, ip2 %s, " "mac %s, mac2 %s]\n", @@ -9136,9 +9107,9 @@ int set_dest_udp_list(int file_des) { char ip[INET_ADDRSTRLEN], ip2[INET_ADDRSTRLEN]; getIpAddressinString(ip, args[3]); getIpAddressinString(ip2, args[4]); - char mac[50], mac2[50]; - getMacAddressinString(mac, 50, args64[0]); - getMacAddressinString(mac2, 50, args64[1]); + char mac[MAC_ADDRESS_SIZE], mac2[MAC_ADDRESS_SIZE]; + getMacAddressinString(mac, MAC_ADDRESS_SIZE, args64[0]); + getMacAddressinString(mac2, MAC_ADDRESS_SIZE, args64[1]); #if !defined(EIGERD) && !defined(JUNGFRAUD) functionNotImplemented(); diff --git a/slsDetectorSoftware/include/sls/Detector.h b/slsDetectorSoftware/include/sls/Detector.h index 960c0545d..420f605de 100644 --- a/slsDetectorSoftware/include/sls/Detector.h +++ b/slsDetectorSoftware/include/sls/Detector.h @@ -81,13 +81,9 @@ class Detector { /* [Jungfrau][Gotthard][Mythen3][Gotthard2][CTB][Moench] */ Result getSerialNumber(Positions pos = {}) const; - /** [Eiger][Gotthard2][Mythen3] */ + /** [Eiger][Gotthard2][Mythen3] 6 bit value (ideally unique) that is streamed out in the UDP header of the detector.*/ Result getModuleId(Positions pos = {}) const; - /** [Gotthard2] 6 bit value (ideally unique) that is " - "streamed out1 in the UDP header of the detector. */ - void setModuleId(const int value, Positions pos = {}); - Result getReceiverVersion(Positions pos = {}) const; /** Options: EIGER, JUNGFRAU, GOTTHARD, MOENCH, MYTHEN3, GOTTHARD2, @@ -667,10 +663,10 @@ class Detector { /** [Jungfrau] bottom half [Gotthard2] veto debugging */ void setSourceUDPMAC2(const MacAddr mac, Positions pos = {}); - Result - getDestinationUDPList(const uint32_t entry, Positions pos = {}) const; + Result getDestinationUDPList(const uint32_t entry, + Positions pos = {}) const; - void setDestinationUDPList(const defs::udpDestination, const int module_id); + void setDestinationUDPList(const UdpDestination, const int module_id); /** [Jungfrau][Eiger] */ Result getNumberofUDPDestinations(Positions pos = {}) const; diff --git a/slsDetectorSoftware/src/CmdProxy.cpp b/slsDetectorSoftware/src/CmdProxy.cpp index ee5c5edda..2f66ad821 100644 --- a/slsDetectorSoftware/src/CmdProxy.cpp +++ b/slsDetectorSoftware/src/CmdProxy.cpp @@ -1379,15 +1379,8 @@ IpAddr CmdProxy::getIpFromAuto() { return val; } -defs::udpDestination CmdProxy::getUdpList() { - uint32_t entry{}; - uint32_t port{}; - uint32_t port2{}; - uint32_t ip{}; - uint32_t ip2{}; - uint64_t mac{}; - uint64_t mac2{}; - +UdpDestination CmdProxy::getUdpEntry() { + UdpDestination udpDestination{}; bool hasEntry = false; for (auto it : args) { @@ -1395,40 +1388,40 @@ defs::udpDestination CmdProxy::getUdpList() { std::string key = it.substr(0, pos); std::string value = it.substr(pos + 1); if (key == "entry") { - entry = StringTo(value); + udpDestination.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; - ip = val.uint32(); + udpDestination.ip = val; } else { - ip = IpAddr(value).uint32(); + udpDestination.ip = IpAddr(value); } } else if (key == "ip2") { if (value == "auto") { auto val = getIpFromAuto(); LOG(logINFO) << "Setting udp_dstip2 of detector " << det_id << " to " << val; - ip2 = val.uint32(); + udpDestination.ip2 = val; } else { - ip2 = IpAddr(value).uint32(); + udpDestination.ip2 = IpAddr(value); } } else if (key == "mac") { - mac = MacAddr(value).uint64(); + udpDestination.mac = MacAddr(value); } else if (key == "mac2") { - mac2 = MacAddr(value).uint64(); + udpDestination.mac2 = MacAddr(value); } else if (key == "port") { - port = StringTo(value); + udpDestination.port = StringTo(value); } else if (key == "port2") { - port2 = StringTo(value); + udpDestination.port2 = StringTo(value); } } if (!hasEntry) { throw sls::RuntimeError("Found no entry argument."); } - return defs::udpDestination(entry, port, ip, mac, port2, ip2, mac2); + return udpDestination; } std::string CmdProxy::UDPDestinationList(int action) { @@ -1454,7 +1447,7 @@ std::string CmdProxy::UDPDestinationList(int action) { if (args.empty()) { WrongNumberOfParameters(1); } - auto t = getUdpList(); + auto t = getUdpEntry(); det->setDestinationUDPList(t, det_id); os << ToString(args) << std::endl; } else { diff --git a/slsDetectorSoftware/src/CmdProxy.h b/slsDetectorSoftware/src/CmdProxy.h index d1e536f37..e2834d957 100644 --- a/slsDetectorSoftware/src/CmdProxy.h +++ b/slsDetectorSoftware/src/CmdProxy.h @@ -1117,7 +1117,7 @@ class CmdProxy { std::string Trigger(int action); /* Network Configuration (Detector<->Receiver) */ IpAddr getIpFromAuto(); - slsDetectorDefs::udpDestination getUdpList(); + UdpDestination getUdpEntry(); std::string UDPDestinationList(int action); std::string UDPDestinationIP(int action); std::string UDPDestinationIP2(int action); @@ -1203,11 +1203,10 @@ class CmdProxy { "\n\t[Jungfrau][Gotthard][Mythen3][Gotthard2][CTB][Moench]" "Serial number of detector."); - INTEGER_COMMAND_HEX( - moduleid, getModuleId, setModuleId, StringTo, - "[value]\n\t[Gotthard2][Eiger][Mythen3] 16 bit value (ideally unique) " - "that is streamed out in the UDP header of the detector. " - "\n\t[Gotthard2] Can set it too."); + GET_COMMAND_HEX( + moduleid, getModuleId, + "\n\t[Gotthard2][Eiger][Mythen3] 16 bit value (ideally unique) " + "that is streamed out in the UDP header of the detector. Picked up from a file on the module."); GET_COMMAND(type, getDetectorType, "\n\tReturns detector type. Can be Eiger, Jungfrau, Gotthard, " diff --git a/slsDetectorSoftware/src/Detector.cpp b/slsDetectorSoftware/src/Detector.cpp index 3e316e984..80c6c0c0e 100644 --- a/slsDetectorSoftware/src/Detector.cpp +++ b/slsDetectorSoftware/src/Detector.cpp @@ -123,10 +123,6 @@ Result 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 Detector::getReceiverVersion(Positions pos) const { return pimpl->Parallel(&Module::getReceiverSoftwareVersion, pos); } @@ -908,12 +904,12 @@ void Detector::setSourceUDPMAC2(const MacAddr mac, Positions pos) { pimpl->Parallel(&Module::setSourceUDPMAC2, pos, mac); } -Result -Detector::getDestinationUDPList(const uint32_t entry, Positions pos) const { +Result Detector::getDestinationUDPList(const uint32_t entry, + Positions pos) const { return pimpl->Parallel(&Module::getDestinationUDPList, pos, entry); } -void Detector::setDestinationUDPList(const defs::udpDestination dest, +void Detector::setDestinationUDPList(const UdpDestination dest, const int module_id) { if (module_id == -1 && size() > 1) { throw sls::RuntimeError("Cannot set this parameter at detector level."); diff --git a/slsDetectorSoftware/src/Module.cpp b/slsDetectorSoftware/src/Module.cpp index ef1bfbd49..aeb2f393c 100644 --- a/slsDetectorSoftware/src/Module.cpp +++ b/slsDetectorSoftware/src/Module.cpp @@ -27,8 +27,8 @@ namespace sls { // creating new shm -Module::Module(detectorType type, int det_id, int module_id, bool verify) - : moduleId(module_id), shm(det_id, module_id) { +Module::Module(detectorType type, int det_id, int module_index, bool verify) + : moduleIndex(module_index), shm(det_id, module_index) { // ensure shared memory was not created before if (shm.IsExisting()) { @@ -42,8 +42,8 @@ Module::Module(detectorType type, int det_id, int module_id, bool verify) } // opening existing shm -Module::Module(int det_id, int module_id, bool verify) - : moduleId(module_id), shm(det_id, module_id) { +Module::Module(int det_id, int module_index, bool verify) + : moduleIndex(module_index), shm(det_id, module_index) { // getDetectorType From shm will check if existing detectorType type = getDetectorTypeFromShm(det_id, verify); @@ -98,10 +98,6 @@ int64_t Module::getSerialNumber() const { int Module::getModuleId() const { return sendToDetector(F_GET_MODULE_ID); } -void Module::setModuleId(const int value) { - return sendToDetector(F_SET_MODULE_ID, value, nullptr); -} - int64_t Module::getReceiverSoftwareVersion() const { if (shm()->useReceiverFlag) { return sendToReceiver(F_GET_RECEIVER_VERSION); @@ -144,7 +140,7 @@ slsDetectorDefs::xy Module::getNumberOfChannels() const { void Module::updateNumberOfDetector(slsDetectorDefs::xy det) { shm()->numberOfDetector = det; - int args[2] = {shm()->numberOfDetector.y, moduleId}; + int args[2] = {shm()->numberOfDetector.y, moduleIndex}; sendToDetector(F_SET_POSITION, args, nullptr); } @@ -825,13 +821,13 @@ std::vector Module::getNumMissingPackets() const { auto client = ReceiverSocket(shm()->rxHostname, shm()->rxTCPPort); client.Send(F_GET_NUM_MISSING_PACKETS); if (client.Receive() == FAIL) { - throw RuntimeError("Receiver " + std::to_string(moduleId) + + throw RuntimeError("Receiver " + std::to_string(moduleIndex) + " returned error: " + client.readErrorMessage()); } else { auto nports = client.Receive(); std::vector retval(nports); client.Receive(retval); - LOG(logDEBUG1) << "Missing packets of Receiver" << moduleId << ": " + LOG(logDEBUG1) << "Missing packets of Receiver" << moduleIndex << ": " << sls::ToString(retval); return retval; } @@ -941,31 +937,30 @@ void Module::setSourceUDPMAC2(const sls::MacAddr mac) { sendToDetector(F_SET_SOURCE_UDP_MAC2, mac, nullptr); } -slsDetectorDefs::udpDestination -Module::getDestinationUDPList(const uint32_t entry) const { - return sendToDetector(F_GET_DEST_UDP_LIST, entry); +sls::UdpDestination Module::getDestinationUDPList(const uint32_t entry) const { + return sendToDetector(F_GET_DEST_UDP_LIST, entry); } -void Module::setDestinationUDPList(const slsDetectorDefs::udpDestination dest) { +void Module::setDestinationUDPList(const sls::UdpDestination dest) { // set them in the default way so the receivers are also set up - if (dest.entry_ == 0) { - if (dest.port_ != 0) { - setDestinationUDPPort(dest.port_); + if (dest.entry == 0) { + if (dest.port != 0) { + setDestinationUDPPort(dest.port); } - if (dest.ip_ != 0) { - setDestinationUDPIP(IpAddr(dest.ip_)); + if (dest.ip != 0) { + setDestinationUDPIP(dest.ip); } - if (dest.mac_ != 0) { - setDestinationUDPMAC(MacAddr(dest.mac_)); + if (dest.mac != 0) { + setDestinationUDPMAC(dest.mac); } - if (dest.port2_ != 0) { - setDestinationUDPPort2(dest.port2_); + if (dest.port2 != 0) { + setDestinationUDPPort2(dest.port2); } - if (dest.ip2_ != 0) { - setDestinationUDPIP2(IpAddr(dest.ip2_)); + if (dest.ip2 != 0) { + setDestinationUDPIP2(dest.ip2); } - if (dest.mac2_ != 0) { - setDestinationUDPMAC2(MacAddr(dest.mac2_)); + if (dest.mac2 != 0) { + setDestinationUDPMAC2(dest.mac2); } } else { sendToDetector(F_SET_DEST_UDP_LIST, dest, nullptr); @@ -1000,7 +995,7 @@ void Module::setDestinationUDPIP(const IpAddr ip) { if (shm()->useReceiverFlag) { sls::MacAddr retval(0LU); sendToReceiver(F_SET_RECEIVER_UDP_IP, ip, retval); - LOG(logINFO) << "Setting destination udp mac of detector " << moduleId + LOG(logINFO) << "Setting destination udp mac of detector " << moduleIndex << " to " << retval; sendToDetector(F_SET_DEST_UDP_MAC, retval, nullptr); } @@ -1020,7 +1015,7 @@ void Module::setDestinationUDPIP2(const IpAddr ip) { if (shm()->useReceiverFlag) { sls::MacAddr retval(0LU); sendToReceiver(F_SET_RECEIVER_UDP_IP2, ip, retval); - LOG(logINFO) << "Setting destination udp mac2 of detector " << moduleId + LOG(logINFO) << "Setting destination udp mac2 of detector " << moduleIndex << " to " << retval; sendToDetector(F_SET_DEST_UDP_MAC2, retval, nullptr); } @@ -1078,7 +1073,7 @@ void Module::validateUDPConfiguration() { std::string Module::printReceiverConfiguration() { std::ostringstream os; - os << "\n\nDetector " << moduleId << "\nReceiver Hostname:\t" + os << "\n\nDetector " << moduleIndex << "\nReceiver Hostname:\t" << getReceiverHostname(); if (shm()->myDetectorType == JUNGFRAU) { @@ -1192,7 +1187,7 @@ void Module::setReceiverHostname(const std::string &receiverIP) { retval.detType = shm()->myDetectorType; retval.numberOfDetector.x = shm()->numberOfDetector.x; retval.numberOfDetector.y = shm()->numberOfDetector.y; - retval.moduleId = moduleId; + retval.moduleIndex = moduleIndex; memset(retval.hostname, 0, sizeof(retval.hostname)); strcpy_safe(retval.hostname, shm()->hostname); @@ -1202,13 +1197,13 @@ void Module::setReceiverHostname(const std::string &receiverIP) { if (retval.udp_dstmac == 0 && retvals[0] != 0) { LOG(logINFO) << "Setting destination udp mac of " "detector " - << moduleId << " to " << retvals[0]; + << moduleIndex << " to " << retvals[0]; sendToDetector(F_SET_DEST_UDP_MAC, retvals[0], nullptr); } if (retval.udp_dstmac2 == 0 && retvals[1] != 0) { LOG(logINFO) << "Setting destination udp mac2 of " "detector " - << moduleId << " to " << retvals[1]; + << moduleIndex << " to " << retvals[1]; sendToDetector(F_SET_DEST_UDP_MAC2, retvals[1], nullptr); } @@ -1524,7 +1519,7 @@ void Module::sendReceiverRateCorrections(const std::vector &t) { receiver.Send(static_cast(t.size())); receiver.Send(t); if (receiver.Receive() == FAIL) { - throw RuntimeError("Receiver " + std::to_string(moduleId) + + throw RuntimeError("Receiver " + std::to_string(moduleIndex) + " returned error: " + receiver.readErrorMessage()); } } @@ -1789,7 +1784,7 @@ void Module::sendVetoPhoton(const int chipIndex, client.Send(gainIndices); client.Send(values); if (client.Receive() == FAIL) { - throw RuntimeError("Detector " + std::to_string(moduleId) + + throw RuntimeError("Detector " + std::to_string(moduleIndex) + " returned error: " + client.readErrorMessage()); } } @@ -1801,7 +1796,7 @@ void Module::getVetoPhoton(const int chipIndex, client.Send(F_GET_VETO_PHOTON); client.Send(chipIndex); if (client.Receive() == FAIL) { - throw RuntimeError("Detector " + std::to_string(moduleId) + + throw RuntimeError("Detector " + std::to_string(moduleIndex) + " returned error: " + client.readErrorMessage()); } @@ -2036,7 +2031,7 @@ void Module::getBadChannels(const std::string &fname) const { auto client = DetectorSocket(shm()->hostname, shm()->controlPort); client.Send(F_GET_BAD_CHANNELS); if (client.Receive() == FAIL) { - throw RuntimeError("Detector " + std::to_string(moduleId) + + throw RuntimeError("Detector " + std::to_string(moduleIndex) + " returned error: " + client.readErrorMessage()); } // receive badchannels @@ -2093,7 +2088,7 @@ void Module::setBadChannels(const std::string &fname) { client.Send(badchannels); } if (client.Receive() == FAIL) { - throw RuntimeError("Detector " + std::to_string(moduleId) + + throw RuntimeError("Detector " + std::to_string(moduleIndex) + " returned error: " + client.readErrorMessage()); } } @@ -2407,7 +2402,7 @@ std::map Module::getAdditionalJsonHeader() const { auto client = ReceiverSocket(shm()->rxHostname, shm()->rxTCPPort); client.Send(F_GET_ADDITIONAL_JSON_HEADER); if (client.Receive() == FAIL) { - throw RuntimeError("Receiver " + std::to_string(moduleId) + + throw RuntimeError("Receiver " + std::to_string(moduleIndex) + " returned error: " + client.readErrorMessage()); } else { auto size = client.Receive(); @@ -2456,7 +2451,7 @@ void Module::setAdditionalJsonHeader( client.Send(&buff[0], buff.size()); if (client.Receive() == FAIL) { - throw RuntimeError("Receiver " + std::to_string(moduleId) + + throw RuntimeError("Receiver " + std::to_string(moduleIndex) + " returned error: " + client.readErrorMessage()); } } @@ -3010,7 +3005,7 @@ slsDetectorDefs::detectorType Module::getDetectorTypeFromShm(int det_id, shm.OpenSharedMemory(); if (verify && shm()->shmversion != SLS_SHMVERSION) { std::ostringstream ss; - ss << "Single shared memory (" << det_id << "-" << moduleId + ss << "Single shared memory (" << det_id << "-" << moduleIndex << ":)version mismatch (expected 0x" << std::hex << SLS_SHMVERSION << " but got 0x" << shm()->shmversion << ")" << std::dec << ". Clear Shared memory to continue."; @@ -3021,7 +3016,7 @@ slsDetectorDefs::detectorType Module::getDetectorTypeFromShm(int det_id, } void Module::initSharedMemory(detectorType type, int det_id, bool verify) { - shm = SharedMemory(det_id, moduleId); + shm = SharedMemory(det_id, moduleIndex); if (!shm.IsExisting()) { shm.CreateSharedMemory(); initializeDetectorStructure(type); @@ -3029,7 +3024,7 @@ void Module::initSharedMemory(detectorType type, int det_id, bool verify) { shm.OpenSharedMemory(); if (verify && shm()->shmversion != SLS_SHMVERSION) { std::ostringstream ss; - ss << "Single shared memory (" << det_id << "-" << moduleId + ss << "Single shared memory (" << det_id << "-" << moduleIndex << ":) version mismatch (expected 0x" << std::hex << SLS_SHMVERSION << " but got 0x" << shm()->shmversion << ")" << std::dec << ". Clear Shared memory to continue."; @@ -3051,7 +3046,7 @@ void Module::initializeDetectorStructure(detectorType type) { shm()->rxTCPPort = DEFAULT_PORTNO + 2; shm()->useReceiverFlag = false; shm()->zmqport = DEFAULT_ZMQ_CL_PORTNO + - (moduleId * ((shm()->myDetectorType == EIGER) ? 2 : 1)); + (moduleIndex * ((shm()->myDetectorType == EIGER) ? 2 : 1)); shm()->zmqip = IpAddr{}; shm()->numUDPInterfaces = 1; shm()->stoppedFlag = false; @@ -3164,7 +3159,7 @@ void Module::setModule(sls_detector_module &module, bool trimbits) { client.Send(F_SET_MODULE); sendModule(&module, client); if (client.Receive() == FAIL) { - throw RuntimeError("Detector " + std::to_string(moduleId) + + throw RuntimeError("Detector " + std::to_string(moduleIndex) + " returned error: " + client.readErrorMessage()); } } @@ -3177,7 +3172,7 @@ void Module::updateReceiverStreamingIP() { if (ip == 0) { ip = HostnameToIp(shm()->rxHostname); } - LOG(logINFO) << "Setting default receiver " << moduleId + LOG(logINFO) << "Setting default receiver " << moduleIndex << " streaming zmq ip to " << ip; } setReceiverStreamingIP(ip); @@ -3426,7 +3421,7 @@ std::string Module::calculateChecksum(char *buffer, ssize_t bytes) { void Module::programFPGAviaBlackfin(std::vector buffer) { // send program from memory to detector LOG(logINFO) << "Sending programming binary (from pof) to module " - << moduleId << " (" << shm()->hostname << ")"; + << moduleIndex << " (" << shm()->hostname << ")"; auto client = DetectorSocket(shm()->hostname, shm()->controlPort); client.Send(F_PROGRAM_FPGA); uint64_t filesize = buffer.size(); @@ -3444,7 +3439,7 @@ void Module::programFPGAviaBlackfin(std::vector buffer) { if (client.Receive() == FAIL) { std::cout << '\n'; std::ostringstream os; - os << "Detector " << moduleId << " (" << shm()->hostname << ")" + os << "Detector " << moduleIndex << " (" << shm()->hostname << ")" << " returned error: " << client.readErrorMessage(); throw RuntimeError(os.str()); } @@ -3464,7 +3459,7 @@ void Module::programFPGAviaBlackfin(std::vector buffer) { if (client.Receive() == FAIL) { std::cout << '\n'; std::ostringstream os; - os << "Detector " << moduleId << " (" << shm()->hostname << ")" + os << "Detector " << moduleIndex << " (" << shm()->hostname << ")" << " returned error: " << client.readErrorMessage(); throw RuntimeError(os.str()); } @@ -3475,22 +3470,22 @@ void Module::programFPGAviaBlackfin(std::vector buffer) { // checksum if (client.Receive() == FAIL) { std::ostringstream os; - os << "Detector " << moduleId << " (" << shm()->hostname << ")" + os << "Detector " << moduleIndex << " (" << shm()->hostname << ")" << " returned error: " << client.readErrorMessage(); throw RuntimeError(os.str()); } - if (moduleId == 0) { + if (moduleIndex == 0) { LOG(logINFO) << "Checksum verified"; } // copied to flash if (client.Receive() == FAIL) { std::ostringstream os; - os << "Detector " << moduleId << " (" << shm()->hostname << ")" + os << "Detector " << moduleIndex << " (" << shm()->hostname << ")" << " returned error: " << client.readErrorMessage(); throw RuntimeError(os.str()); } - if (moduleId == 0) { + if (moduleIndex == 0) { LOG(logINFO) << "Copied to flash and checksum verified"; } @@ -3500,7 +3495,7 @@ void Module::programFPGAviaBlackfin(std::vector buffer) { void Module::programFPGAviaNios(std::vector buffer) { LOG(logINFO) << "Sending programming binary (from rbf) to detector " - << moduleId << " (" << shm()->hostname << ")"; + << moduleIndex << " (" << shm()->hostname << ")"; auto client = DetectorSocket(shm()->hostname, shm()->controlPort); client.Send(F_PROGRAM_FPGA); @@ -3517,14 +3512,14 @@ void Module::programFPGAviaNios(std::vector buffer) { if (client.Receive() == FAIL) { std::ostringstream os; - os << "Detector " << moduleId << " (" << shm()->hostname << ")" + os << "Detector " << moduleIndex << " (" << shm()->hostname << ")" << " returned error: " << client.readErrorMessage(); throw RuntimeError(os.str()); } client.Send(buffer); if (client.Receive() == FAIL) { std::ostringstream os; - os << "Detector " << moduleId << " (" << shm()->hostname << ")" + os << "Detector " << moduleIndex << " (" << shm()->hostname << ")" << " returned error: " << client.readErrorMessage(); throw RuntimeError(os.str()); } diff --git a/slsDetectorSoftware/src/Module.h b/slsDetectorSoftware/src/Module.h index d2bbe47f1..b6b1439d1 100644 --- a/slsDetectorSoftware/src/Module.h +++ b/slsDetectorSoftware/src/Module.h @@ -66,12 +66,12 @@ class Module : public virtual slsDetectorDefs { /** creating new shared memory verify is if shared memory version matches existing one */ - explicit Module(detectorType type, int det_id = 0, int module_id = 0, + explicit Module(detectorType type, int det_id = 0, int module_index = 0, bool verify = true); /** opening existing shared memory verify is if shared memory version matches existing one */ - explicit Module(int det_id = 0, int module_id = 0, bool verify = true); + explicit Module(int det_id = 0, int module_index = 0, bool verify = true); virtual ~Module(); @@ -91,7 +91,6 @@ class Module : public virtual slsDetectorDefs { int64_t getDetectorServerVersion() const; int64_t getSerialNumber() const; int getModuleId() const; - void setModuleId(const int value); int64_t getReceiverSoftwareVersion() const; static detectorType getTypeFromDetector(const std::string &hostname, int cport = DEFAULT_PORTNO); @@ -222,8 +221,8 @@ class Module : public virtual slsDetectorDefs { void setSourceUDPMAC(const sls::MacAddr mac); sls::MacAddr getSourceUDPMAC2() const; void setSourceUDPMAC2(const sls::MacAddr mac); - udpDestination getDestinationUDPList(const uint32_t entry) const; - void setDestinationUDPList(const defs::udpDestination dest); + sls::UdpDestination getDestinationUDPList(const uint32_t entry) const; + void setDestinationUDPList(const sls::UdpDestination dest); int getNumberofUDPDestinations() const; void setNumberofUDPDestinations(const int value); int getFirstUDPDestination() const; @@ -748,7 +747,7 @@ class Module : public virtual slsDetectorDefs { void programFPGAviaBlackfin(std::vector buffer); void programFPGAviaNios(std::vector buffer); - const int moduleId; + const int moduleIndex; mutable sls::SharedMemory shm{0, 0}; }; diff --git a/slsReceiverSoftware/src/ClientInterface.cpp b/slsReceiverSoftware/src/ClientInterface.cpp index afbd2f168..b4d7464db 100644 --- a/slsReceiverSoftware/src/ClientInterface.cpp +++ b/slsReceiverSoftware/src/ClientInterface.cpp @@ -337,7 +337,7 @@ int ClientInterface::setup_receiver(Interface &socket) { int msize[2] = {arg.numberOfDetector.x, arg.numberOfDetector.y}; impl()->setDetectorSize(msize); } - impl()->setModulePositionId(arg.moduleId); + impl()->setModulePositionId(arg.moduleIndex); impl()->setDetectorHostname(arg.hostname); // udp setup diff --git a/slsSupportLib/include/sls/ToString.h b/slsSupportLib/include/sls/ToString.h index bd102e2b2..bbcd4a6c9 100644 --- a/slsSupportLib/include/sls/ToString.h +++ b/slsSupportLib/include/sls/ToString.h @@ -55,9 +55,6 @@ std::ostream &operator<<(std::ostream &os, std::string ToString(const slsDetectorDefs::currentSrcParameters &r); std::ostream &operator<<(std::ostream &os, const slsDetectorDefs::currentSrcParameters &r); -std::string ToString(const slsDetectorDefs::udpDestination &r); -std::ostream &operator<<(std::ostream &os, - const slsDetectorDefs::udpDestination &r); const std::string &ToString(const std::string &s); /** Convert std::chrono::duration with specified output unit */ diff --git a/slsSupportLib/include/sls/network_utils.h b/slsSupportLib/include/sls/network_utils.h index b741b6e5e..68b090651 100644 --- a/slsSupportLib/include/sls/network_utils.h +++ b/slsSupportLib/include/sls/network_utils.h @@ -30,7 +30,7 @@ class IpAddr { return addr_ != other; } constexpr uint32_t uint32() const noexcept { return addr_; } -}; +} __attribute__((packed)); class MacAddr { private: @@ -57,13 +57,33 @@ class MacAddr { return addr_ != other; } constexpr uint64_t uint64() const noexcept { return addr_; } -}; +} __attribute__((packed)); + +struct UdpDestination { + uint32_t entry{}; + uint32_t port{}; + uint32_t port2{}; + IpAddr ip; + IpAddr ip2; + MacAddr mac; + MacAddr mac2; + std::string str() const; + + constexpr bool operator==(const UdpDestination &other) const { + return ((entry == other.entry) && (port == other.port) && + (port2 == other.port2) && (ip== other.ip) && + (ip2 == other.ip2) && (mac == other.mac) && + (mac2 == other.mac2)); + } +} __attribute__((packed)); + +std::ostream &operator<<(std::ostream &out, const IpAddr &addr); +std::ostream &operator<<(std::ostream &out, const MacAddr &addr); +std::ostream &operator<<(std::ostream &out, const UdpDestination &dest); IpAddr HostnameToIp(const char *hostname); std::string IpToInterfaceName(const std::string &ip); MacAddr InterfaceNameToMac(const std::string &inf); IpAddr InterfaceNameToIp(const std::string &ifn); -std::ostream &operator<<(std::ostream &out, const IpAddr &addr); -std::ostream &operator<<(std::ostream &out, const MacAddr &addr); } // namespace sls diff --git a/slsSupportLib/include/sls/sls_detector_defs.h b/slsSupportLib/include/sls/sls_detector_defs.h index 0311ee816..85d10288f 100644 --- a/slsSupportLib/include/sls/sls_detector_defs.h +++ b/slsSupportLib/include/sls/sls_detector_defs.h @@ -494,35 +494,13 @@ typedef struct { } } __attribute__((packed)); - struct 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 = 0, uint32_t ip = 0, uint64_t mac = 0, - uint32_t port2 = 0, uint32_t ip2 = 0, uint64_t mac2 = 0) - : entry_(entry), port_(port), port2_(port2), ip_(ip), ip2_(ip2), - mac_(mac), mac2_(mac2) {} - - bool operator==(const udpDestination &other) const { - return ((entry_ == other.entry_) && (port_ == other.port_) && - (port2_ == other.port2_) && (ip_ == other.ip_) && - (ip2_ == other.ip2_) && (mac_ == other.mac_) && - (mac2_ == other.mac2_)); - } - } __attribute__((packed)); - /** * structure to udpate receiver */ struct rxParameters { detectorType detType{GENERIC}; xy numberOfDetector; - int moduleId{0}; + int moduleIndex{0}; char hostname[MAX_STR_LENGTH]; int udpInterfaces{1}; int udp_dstport{0}; diff --git a/slsSupportLib/include/sls/sls_detector_funcs.h b/slsSupportLib/include/sls/sls_detector_funcs.h index 0c0403aca..4a4fd8f61 100755 --- a/slsSupportLib/include/sls/sls_detector_funcs.h +++ b/slsSupportLib/include/sls/sls_detector_funcs.h @@ -244,7 +244,6 @@ enum detFuncs { F_SET_DBIT_PIPELINE, F_GET_DBIT_PIPELINE, F_GET_MODULE_ID, - F_SET_MODULE_ID, F_GET_DEST_UDP_LIST, F_SET_DEST_UDP_LIST, F_GET_NUM_DEST_UDP, @@ -602,7 +601,6 @@ const char* getFunctionNameFromEnum(enum detFuncs func) { case F_SET_DBIT_PIPELINE: return "F_SET_DBIT_PIPELINE"; 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 F_GET_NUM_DEST_UDP: return "F_GET_NUM_DEST_UDP"; diff --git a/slsSupportLib/include/sls/versionAPI.h b/slsSupportLib/include/sls/versionAPI.h index 1ffaac211..f2ca9f43a 100644 --- a/slsSupportLib/include/sls/versionAPI.h +++ b/slsSupportLib/include/sls/versionAPI.h @@ -1,15 +1,13 @@ /** API versions */ #define GITBRANCH "roundrobin" - - - #define APILIB 0x210831 #define APIRECEIVER 0x210831 #define APIGUI 0x210819 -#define APICTB 0x210908 -#define APIGOTTHARD 0x210908 -#define APIGOTTHARD2 0x210908 -#define APIJUNGFRAU 0x210908 -#define APIMYTHEN3 0x210908 -#define APIMOENCH 0x210907 -#define APIEIGER 0x210908 + +#define APICTB 0x210909 +#define APIGOTTHARD 0x210909 +#define APIGOTTHARD2 0x210909 +#define APIJUNGFRAU 0x210909 +#define APIMYTHEN3 0x210909 +#define APIMOENCH 0x210909 +#define APIEIGER 0x210909 diff --git a/slsSupportLib/src/ToString.cpp b/slsSupportLib/src/ToString.cpp index e37ef0d73..8e7bd69cd 100644 --- a/slsSupportLib/src/ToString.cpp +++ b/slsSupportLib/src/ToString.cpp @@ -28,7 +28,7 @@ std::string ToString(const slsDetectorDefs::rxParameters &r) { oss << '[' << "detType:" << r.detType << std::endl << "numberOfDetector.x:" << r.numberOfDetector.x << std::endl << "numberOfDetector.y:" << r.numberOfDetector.y << std::endl - << "moduleId:" << r.moduleId << std::endl + << "moduleIndex:" << r.moduleIndex << std::endl << "hostname:" << r.hostname << std::endl << "udpInterfaces:" << r.udpInterfaces << std::endl << "udp_dstport:" << r.udp_dstport << std::endl @@ -148,31 +148,6 @@ std::ostream &operator<<(std::ostream &os, return os << ToString(r); } -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; - } - if (r.ip2_ != 0) { - oss << "ip2 " << IpAddr(r.ip2_) << std::endl; - } - if (r.mac2_ != 0) { - oss << "mac2 " << MacAddr(r.mac2_) << std::endl; - } - oss << ']'; - return oss.str(); -} - -std::ostream &operator<<(std::ostream &os, - const slsDetectorDefs::udpDestination &r) { - return os << ToString(r); -} - std::string ToString(const defs::runStatus s) { switch (s) { case defs::ERROR: diff --git a/slsSupportLib/src/network_utils.cpp b/slsSupportLib/src/network_utils.cpp index 2f05e948c..56507e8f1 100644 --- a/slsSupportLib/src/network_utils.cpp +++ b/slsSupportLib/src/network_utils.cpp @@ -69,6 +69,26 @@ std::string MacAddr::str() const { return to_hex(':'); } std::string MacAddr::hex() const { return to_hex(); } +std::string UdpDestination::str() const { + std::ostringstream oss; + oss << '[' << std::endl + << "entry " << entry << std::endl + << "ip " << ip << std::endl + << "mac " << mac << std::endl + << "port " << port << std::endl; + if (port2 != 0) { + oss << "port2 " << port2 << std::endl; + } + if (ip2 != 0) { + oss << "ip2 " << ip2 << std::endl; + } + if (mac2 != 0) { + oss << "mac2 " << mac2 << std::endl; + } + oss << ']'; + return oss.str(); +} + std::ostream &operator<<(std::ostream &out, const IpAddr &addr) { return out << addr.str(); } @@ -77,6 +97,10 @@ std::ostream &operator<<(std::ostream &out, const MacAddr &addr) { return out << addr.str(); } +std::ostream &operator<<(std::ostream &out, const UdpDestination &dest) { + return out << dest.str(); +} + IpAddr HostnameToIp(const char *hostname) { addrinfo hints; addrinfo *result = nullptr; diff --git a/slsSupportLib/tests/test-file_utils.cpp b/slsSupportLib/tests/test-file_utils.cpp index 254c52055..b4f71cfb9 100644 --- a/slsSupportLib/tests/test-file_utils.cpp +++ b/slsSupportLib/tests/test-file_utils.cpp @@ -9,7 +9,7 @@ TEST_CASE("Get size of empty file") { char fname[] = "temfile_XXXXXX"; std::ifstream ifs(fname); auto size = sls::getFileSize(ifs); - REQUIRE(size == 0); + REQUIRE(size <= 0); // -1 or zero } TEST_CASE("Get size of file with data") { diff --git a/slsSupportLib/tests/test-network_utils.cpp b/slsSupportLib/tests/test-network_utils.cpp index 295da4c10..a6464d2b4 100644 --- a/slsSupportLib/tests/test-network_utils.cpp +++ b/slsSupportLib/tests/test-network_utils.cpp @@ -112,4 +112,19 @@ TEST_CASE("Copy construct a MacAddr") { CHECK(addr == addr2); } + +TEST_CASE("udp dst struct basic properties"){ + static_assert(sizeof(UdpDestination) == 36); + UdpDestination dst{}; + REQUIRE(dst.entry == 0); + REQUIRE(dst.port == 0); + REQUIRE(dst.port2 == 0); + REQUIRE(dst.ip == 0); + REQUIRE(dst.ip2 == 0); + REQUIRE(dst.mac == 0); + REQUIRE(dst.mac2 == 0); + +} + + // TODO!(Erik) Look up a real hostname and verify the IP