diff --git a/slsDetectorServers/eigerDetectorServer/bin/eigerDetectorServer_developer b/slsDetectorServers/eigerDetectorServer/bin/eigerDetectorServer_developer index e8fc3dea5..5381a6f42 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 ca5614029..2395d6687 100755 --- a/slsDetectorServers/eigerDetectorServer/slsDetectorFunctionList.c +++ b/slsDetectorServers/eigerDetectorServer/slsDetectorFunctionList.c @@ -21,6 +21,8 @@ extern int debugflag; // Global variable from communication_funcs.c extern int isControlServer; +extern void getMacAddressinString(char* cmac, int size, uint64_t mac); +extern void getIpAddressinString(char* cip, uint32_t ip); int firmware_compatibility = OK; int firmware_check_done = 0; @@ -1213,24 +1215,14 @@ enum externalCommunicationMode getTiming() { int configureMAC(uint32_t destip, uint64_t destmac, uint64_t sourcemac, uint32_t sourceip, uint32_t udpport, uint32_t udpport2) { #ifndef VIRTUAL FILE_LOG(logINFO, ("Configuring MAC\n")); - char src_mac[50], src_ip[50],dst_mac[50], dst_ip[50]; - int src_port = 0xE185; - sprintf(src_ip,"%d.%d.%d.%d",(sourceip>>24)&0xff,(sourceip>>16)&0xff,(sourceip>>8)&0xff,(sourceip)&0xff); - sprintf(dst_ip,"%d.%d.%d.%d",(destip>>24)&0xff,(destip>>16)&0xff,(destip>>8)&0xff,(destip)&0xff); - sprintf(src_mac,"%02x:%02x:%02x:%02x:%02x:%02x",(unsigned int)((sourcemac>>40)&0xFF), - (unsigned int)((sourcemac>>32)&0xFF), - (unsigned int)((sourcemac>>24)&0xFF), - (unsigned int)((sourcemac>>16)&0xFF), - (unsigned int)((sourcemac>>8)&0xFF), - (unsigned int)((sourcemac>>0)&0xFF)); - sprintf(dst_mac,"%02x:%02x:%02x:%02x:%02x:%02x",(unsigned int)((destmac>>40)&0xFF), - (unsigned int)((destmac>>32)&0xFF), - (unsigned int)((destmac>>24)&0xFF), - (unsigned int)((destmac>>16)&0xFF), - (unsigned int)((destmac>>8)&0xFF), - (unsigned int)((destmac>>0)&0xFF)); - + + int src_port = DEFAULT_UDP_SOURCE_PORT; + char src_mac[50], src_ip[INET_ADDRSTRLEN],dst_mac[50], dst_ip[INET_ADDRSTRLEN]; + getMacAddressinString(src_mac, 50, sourcemac); + getMacAddressinString(dst_mac, 50, destmac); + getIpAddressinString(src_ip, sourceip); + getIpAddressinString(dst_ip, destip); FILE_LOG(logINFO, ( "\tSource IP : %s\n" diff --git a/slsDetectorServers/eigerDetectorServer/slsDetectorServer_defs.h b/slsDetectorServers/eigerDetectorServer/slsDetectorServer_defs.h index 3ab0c42f6..71bf95ca0 100755 --- a/slsDetectorServers/eigerDetectorServer/slsDetectorServer_defs.h +++ b/slsDetectorServers/eigerDetectorServer/slsDetectorServer_defs.h @@ -47,6 +47,7 @@ enum {E_PARALLEL, E_NON_PARALLEL, E_SAFE}; #define NORMAL_HIGHVOLTAGE_OUTPUTPORT "/sys/class/hwmon/hwmon5/device/out0_output" #define SPECIAL9M_HIGHVOLTAGE_PORT "/dev/ttyS1" #define SPECIAL9M_HIGHVOLTAGE_BUFFERSIZE (16) +#define DEFAULT_UDP_SOURCE_PORT (0xE185) /** Default Parameters */ #define DEFAULT_NUM_FRAMES (1) diff --git a/slsDetectorServers/slsDetectorServer/communication_funcs.c b/slsDetectorServers/slsDetectorServer/communication_funcs.c index 9dbfbacee..11de0f631 100755 --- a/slsDetectorServers/slsDetectorServer/communication_funcs.c +++ b/slsDetectorServers/slsDetectorServer/communication_funcs.c @@ -520,3 +520,19 @@ int Server_SendResult(int fileDes, intType itype, int update, void* retval, int return ret; } + + +void getMacAddressinString(char* cmac, int size, uint64_t mac) { + memset(cmac, 0, size); + sprintf(cmac,"%02x:%02x:%02x:%02x:%02x:%02x",(unsigned int)((mac>>40)&0xFF), + (unsigned int)((mac>>32)&0xFF), + (unsigned int)((mac>>24)&0xFF), + (unsigned int)((mac>>16)&0xFF), + (unsigned int)((mac>>8)&0xFF), + (unsigned int)((mac>>0)&0xFF)); +} + +void getIpAddressinString(char* cip, uint32_t ip) { + memset(cip, 0, INET_ADDRSTRLEN); + inet_ntop(AF_INET, &ip, cip, INET_ADDRSTRLEN); +} \ No newline at end of file diff --git a/slsDetectorServers/slsDetectorServer/communication_funcs.h b/slsDetectorServers/slsDetectorServer/communication_funcs.h index 633139740..cfe4b5637 100755 --- a/slsDetectorServers/slsDetectorServer/communication_funcs.h +++ b/slsDetectorServers/slsDetectorServer/communication_funcs.h @@ -52,4 +52,19 @@ int Server_VerifyLock(); */ int Server_SendResult(int fileDes, intType itype, int update, void* retval, int retvalSize); +/** + * Convert mac address from integer to char array + * @param cmac char arrary result + * @param size size of char array result + * @param mac mac address as an integer + */ +void getMacAddressinString(char* cmac, int size, uint64_t mac); + +/** + * Convert ip address from integer to char array + * @param cip char arrary result + * @param ip ip address as an integer + */ +void getIpAddressinString(char* cip, uint32_t ip); + #endif diff --git a/slsDetectorServers/slsDetectorServer/slsDetectorServer_funcs.c b/slsDetectorServers/slsDetectorServer/slsDetectorServer_funcs.c index 7c318bc9c..b5aeaca75 100755 --- a/slsDetectorServers/slsDetectorServer/slsDetectorServer_funcs.c +++ b/slsDetectorServers/slsDetectorServer/slsDetectorServer_funcs.c @@ -2298,8 +2298,6 @@ int send_update(int file_des) { - - int configure_mac(int file_des) { ret = OK; memset(mess, 0, sizeof(mess)); @@ -2323,9 +2321,12 @@ int configure_mac(int file_des) { // dest ip uint32_t dstIp = 0; sscanf(args[1], "%x", &dstIp); - FILE_LOG(logDEBUG1, ("Dst Ip Addr: %d.%d.%d.%d = 0x%x \n", - (dstIp >> 24) & 0xff, (dstIp >> 16) & 0xff, (dstIp >> 8) & 0xff, (dstIp) & 0xff, - dstIp)); + { + char ipstring[INET_ADDRSTRLEN]; + getIpAddressinString(ipstring, dstIp); + FILE_LOG(logINFO, ("Dst Ip Addr: %s\n", ipstring)); + } + // dest mac uint64_t dstMac = 0; #ifdef VIRTUAL @@ -2333,23 +2334,19 @@ int configure_mac(int file_des) { #else sscanf(args[2], "%llx", &dstMac); #endif - FILE_LOG(logDEBUG1, ("Dst Mac Addr: (0x) ")); { - int iloop = 5; - for (iloop = 5; iloop >= 0; --iloop) { - printf ("%x", (unsigned int)(((dstMac >> (8 * iloop)) & 0xFF))); - if (iloop > 0) { - printf(":"); - } - } + char macstring[50]; + getMacAddressinString(macstring, 50, dstMac); + FILE_LOG(logDEBUG1, ("Dst Mac Addr: %s\n", macstring)); } - FILE_LOG(logDEBUG1, (" = %llx\n", dstMac)); // source ip uint32_t srcIp = 0; sscanf(args[3], "%x", &srcIp); - FILE_LOG(logDEBUG1, ("Src Ip Addr: %d.%d.%d.%d = 0x%x \n", - (srcIp >> 24) & 0xff, (srcIp >> 16) & 0xff, (srcIp >> 8) & 0xff, (srcIp) & 0xff, - srcIp)); + { + char ipstring[INET_ADDRSTRLEN]; + getIpAddressinString(ipstring, srcIp); + FILE_LOG(logINFO, ("Src Ip Addr: %s\n", ipstring)); + } // source mac uint64_t srcMac = 0; #ifdef VIRTUAL @@ -2357,17 +2354,11 @@ int configure_mac(int file_des) { #else sscanf(args[4], "%llx", &srcMac); #endif - FILE_LOG(logDEBUG1, ("Src Mac Addr: (0x) ")); { - int iloop = 5; - for (iloop = 5; iloop >= 0; --iloop) { - printf("%x", (unsigned int)(((srcMac >> (8 * iloop)) & 0xFF))); - if (iloop > 0) { - printf(":"); - } - } + char macstring[50]; + getMacAddressinString(macstring, 50, srcMac); + FILE_LOG(logDEBUG1, ("Src Mac Addr: %s\n", macstring)); } - FILE_LOG(logDEBUG1, (" = %llx\n", srcMac)); #if defined(JUNGFRAUD) || defined(EIGERD) // source port 2 @@ -2379,9 +2370,11 @@ int configure_mac(int file_des) { // dest ip2 uint32_t dstIp2 = 0; sscanf(args[6], "%x", &dstIp2); - FILE_LOG(logDEBUG1, ("Dst Ip Addr: %d.%d.%d.%d = 0x%x \n", - (dstIp2 >> 24) & 0xff, (dstIp2 >> 16) & 0xff, (dstIp2 >> 8) & 0xff, (dstIp2) & 0xff, - dstIp2)); + { + char ipstring[INET_ADDRSTRLEN]; + getIpAddressinString(ipstring, dstIp2); + FILE_LOG(logDEBUG1, ("Dst Ip Addr2: %s\n", ipstring)); + } // dest mac2 uint64_t dstMac2 = 0; #ifdef VIRTUAL @@ -2389,23 +2382,19 @@ int configure_mac(int file_des) { #else sscanf(args[7], "%llx", &dstMac2); #endif - FILE_LOG(logDEBUG1, ("Dst Mac Addr: (0x) ")); { - int iloop = 5; - for (iloop = 5; iloop >= 0; --iloop) { - printf ("%x", (unsigned int)(((dstMac2 >> (8 * iloop)) & 0xFF))); - if (iloop > 0) { - printf(":"); - } - } + char macstring[50]; + getMacAddressinString(macstring, 50, dstMac2); + FILE_LOG(logDEBUG1, ("Dst Mac Addr2: %s\n", macstring)); } - FILE_LOG(logDEBUG1, (" = %llx\n", dstMac2)); // source ip2 uint32_t srcIp2 = 0; sscanf(args[8], "%x", &srcIp2); - FILE_LOG(logDEBUG1, ("Src Ip Addr: %d.%d.%d.%d = 0x%x \n", - (srcIp2 >> 24) & 0xff, (srcIp2 >> 16) & 0xff, (srcIp2 >> 8) & 0xff, (srcIp2) & 0xff, - srcIp2)); + { + char ipstring[INET_ADDRSTRLEN]; + getIpAddressinString(ipstring, srcIp2); + FILE_LOG(logDEBUG1, ("Src Ip Addr2: %s\n", ipstring)); + } // source mac2 uint64_t srcMac2 = 0; #ifdef VIRTUAL @@ -2413,17 +2402,11 @@ int configure_mac(int file_des) { #else sscanf(args[9], "%llx", &srcMac2); #endif - FILE_LOG(logDEBUG1, ("Src Mac Addr: (0x) ")); { - int iloop = 5; - for (iloop = 5; iloop >= 0; --iloop) { - printf("%x", (unsigned int)(((srcMac2 >> (8 * iloop)) & 0xFF))); - if (iloop > 0) { - printf(":"); - } - } + char macstring[50]; + getMacAddressinString(macstring, 50, srcMac2); + FILE_LOG(logDEBUG1, ("Src Mac Addr2: %s\n", macstring)); } - FILE_LOG(logDEBUG1, (" = %llx\n", srcMac2)); // number of interfaces int numInterfaces = 0; diff --git a/slsSupportLib/include/versionAPI.h b/slsSupportLib/include/versionAPI.h index b31d1f42a..4a39bc3a9 100644 --- a/slsSupportLib/include/versionAPI.h +++ b/slsSupportLib/include/versionAPI.h @@ -6,5 +6,5 @@ #define APILIB 0x190405 #define APIRECEIVER 0x190405 #define APIGUI 0x190405 -#define APIEIGER 0x190514 #define APICTB 0x190514 +#define APIEIGER 0x190516 diff --git a/slsSupportLib/src/network_utils.cpp b/slsSupportLib/src/network_utils.cpp index 5153cf234..ec496e52a 100755 --- a/slsSupportLib/src/network_utils.cpp +++ b/slsSupportLib/src/network_utils.cpp @@ -35,9 +35,9 @@ std::string IpAddr::str() const { } std::string IpAddr::hex() const { std::ostringstream ss; - ss << std::hex << std::setfill('0') << std::setw(2); for (int i = 0; i != 4; ++i) { - ss << ((addr_ >> i * 8) & 0xFF); + ss << std::hex << std::setfill('0') << std::setw(2) + << ((addr_ >> i * 8) & 0xFF); } return ss.str(); } diff --git a/slsSupportLib/tests/test-network_utils.cpp b/slsSupportLib/tests/test-network_utils.cpp index 54683807c..684cdd43c 100755 --- a/slsSupportLib/tests/test-network_utils.cpp +++ b/slsSupportLib/tests/test-network_utils.cpp @@ -42,9 +42,12 @@ TEST_CASE("Hex representation of MAC", "[support]") { } TEST_CASE("Convert IP using classes ", "[support]") { - std::vector vec_addr{4073554305, 2747957633, 2697625985, 16779786}; + std::vector vec_addr{4073554305, 2747957633, 2697625985, 2566979594, 0}; std::vector vec_ans{"129.129.205.242", "129.129.202.163", - "129.129.202.160", "10.10.0.1"}; + "129.129.202.160", "10.0.1.153", "0.0.0.0"}; + std::vector vec_hex{"8181cdf2", "8181caa3", + "8181caa0", "0a000199","00000000"}; + for (size_t i = 0; i != vec_addr.size(); ++i) { auto ip0 = IpAddr(vec_addr[i]); @@ -57,6 +60,8 @@ TEST_CASE("Convert IP using classes ", "[support]") { CHECK(ip1 == vec_ans[i]); CHECK(ip0.str() == vec_ans[i]); CHECK(ip1.str() == vec_ans[i]); + CHECK(ip0.hex() == vec_hex[i]); + CHECK(ip1.hex() == vec_hex[i]); } } @@ -96,4 +101,4 @@ TEST_CASE("MAC Output operator gives same result as string", "[support]") { CHECK(os.str() == addr.str()); } -//TODO!(Erik) Look up a real hostname and verify the IP \ No newline at end of file +//TODO!(Erik) Look up a real hostname and verify the IP