diff --git a/slsDetectorServers/CMakeLists.txt b/slsDetectorServers/CMakeLists.txt index f185b732a..9d6d45d31 100644 --- a/slsDetectorServers/CMakeLists.txt +++ b/slsDetectorServers/CMakeLists.txt @@ -22,7 +22,7 @@ install(TARGETS slsProjectCWarnings add_subdirectory(ctbDetectorServer) add_subdirectory(eigerDetectorServer) add_subdirectory(gotthardDetectorServer) -add_subdirectory(jungfrauDetectorServer) -add_subdirectory(mythen3DetectorServer) -add_subdirectory(gotthard2DetectorServer) +#add_subdirectory(jungfrauDetectorServer) +#add_subdirectory(mythen3DetectorServer) +#add_subdirectory(gotthard2DetectorServer) add_subdirectory(moenchDetectorServer) diff --git a/slsDetectorServers/ctbDetectorServer/slsDetectorFunctionList.c b/slsDetectorServers/ctbDetectorServer/slsDetectorFunctionList.c index 8ca4963a9..f8f2a1137 100755 --- a/slsDetectorServers/ctbDetectorServer/slsDetectorFunctionList.c +++ b/slsDetectorServers/ctbDetectorServer/slsDetectorFunctionList.c @@ -13,19 +13,26 @@ #include #include // usleep +#include #ifdef VIRTUAL #include #include +#include //ceil #endif // Global variable from slsDetectorServer_funcs extern int debugflag; extern udpStruct udpDetails; +extern const enum detectorType myDetectorType; // Global variable from UDPPacketHeaderGenerator extern uint64_t udpFrameNumber; extern uint32_t udpPacketNumber; +// Global variable from communication_funcs.c +extern void getMacAddressinString(char* cmac, int size, uint64_t mac); +extern void getIpAddressinString(char* cip, uint32_t ip); + int initError = OK; int initCheckDone = 0; char initErrorMessage[MAX_STR_LENGTH]; @@ -1473,26 +1480,36 @@ void calcChecksum(udp_header* udp) { int configureMAC(){ - uint32_t sourceip = udpDetails.srcip; - uint32_t destip = udpDetails.dstip; - uint64_t sourcemac = udpDetails.srcmac; - uint64_t destmac = udpDetails.dstmac; - int sourceport = udpDetails.srcport; - int destport = udpDetails.dstport; -#ifdef VIRTUAL - return OK; -#endif + uint32_t srcip = udpDetails.srcip; + uint32_t dstip = udpDetails.dstip; + uint64_t srcmac = udpDetails.srcmac; + uint64_t dstmac = udpDetails.dstmac; + int srcport = udpDetails.srcport; + int dstport = udpDetails.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); + getIpAddressinString(src_ip, srcip); + getIpAddressinString(dst_ip, dstip); + + LOG(logINFO, ( + "\tSource IP : %s\n" + "\tSource MAC : %s\n" + "\tSource Port : %d\n" + "\tDest IP : %s\n" + "\tDest MAC : %s\n" + "\tDest Port : %d\n", + src_ip, src_mac, srcport, + dst_ip, dst_mac, dstport)); + // 1 giga udp if (!enableTenGigabitEthernet(-1)) { - LOG(logINFOBLUE, ("Configuring 1G MAC\n")); + LOG(logINFOBLUE, ("\t1G MAC\n")); if (updateDatabytesandAllocateRAM() == FAIL) return -1; - char cDestIp[MAX_STR_LENGTH]; - memset(cDestIp, 0, MAX_STR_LENGTH); - sprintf(cDestIp, "%d.%d.%d.%d", (destip>>24)&0xff,(destip>>16)&0xff,(destip>>8)&0xff,(destip)&0xff); - LOG(logINFO, ("1G UDP: Destination (IP: %s, port:%d)\n", cDestIp, destport)); - if (setUDPDestinationDetails(0, cDestIp, destport) == FAIL) { + if (setUDPDestinationDetails(0, dst_ip, dstport) == FAIL) { LOG(logERROR, ("could not set udp 1G destination IP and port\n")); return FAIL; } @@ -1500,31 +1517,7 @@ int configureMAC(){ } // 10 G - LOG(logINFOBLUE, ("Configuring 10G MAC\n")); - - LOG(logINFO, ("\tSource IP : %d.%d.%d.%d \t\t(0x%08x)\n", - (sourceip>>24)&0xff,(sourceip>>16)&0xff,(sourceip>>8)&0xff,(sourceip)&0xff, sourceip)); - LOG(logINFO, ("\tSource MAC : %02x:%02x:%02x:%02x:%02x:%02x \t(0x%010llx)\n", - (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), - (long long unsigned int)sourcemac)); - LOG(logINFO, ("\tSource Port : %d \t\t\t(0x%08x)\n",sourceport, sourceport)); - - LOG(logINFO, ("\tDest. IP : %d.%d.%d.%d \t\t(0x%08x)\n", - (destip>>24)&0xff,(destip>>16)&0xff,(destip>>8)&0xff,(destip)&0xff, destip)); - LOG(logINFO, ("\tDest. MAC : %02x:%02x:%02x:%02x:%02x:%02x \t(0x%010llx)\n", - (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), - (long long unsigned int)destmac)); - LOG(logINFO, ("\tDest. Port : %d \t\t\t(0x%08x)\n",destport, destport)); + LOG(logINFOBLUE, ("\t10G MAC\n")); // start addr uint32_t addr = RXR_ENDPOINT_START_REG; @@ -1534,21 +1527,21 @@ int configureMAC(){ // mac addresses // msb (32) + lsb (16) - udp->udp_destmac_msb = ((destmac >> 16) & BIT32_MASK); - udp->udp_destmac_lsb = ((destmac >> 0) & BIT16_MASK); + udp->udp_destmac_msb = ((dstmac >> 16) & BIT32_MASK); + udp->udp_destmac_lsb = ((dstmac >> 0) & BIT16_MASK); // msb (16) + lsb (32) - udp->udp_srcmac_msb = ((sourcemac >> 32) & BIT16_MASK); - udp->udp_srcmac_lsb = ((sourcemac >> 0) & BIT32_MASK); + udp->udp_srcmac_msb = ((srcmac >> 32) & BIT16_MASK); + udp->udp_srcmac_lsb = ((srcmac >> 0) & BIT32_MASK); // ip addresses - udp->ip_srcip_msb = ((sourceip >> 16) & BIT16_MASK); - udp->ip_srcip_lsb = ((sourceip >> 0) & BIT16_MASK); - udp->ip_destip_msb = ((destip >> 16) & BIT16_MASK); - udp->ip_destip_lsb = ((destip >> 0) & BIT16_MASK); + udp->ip_srcip_msb = ((srcip >> 16) & BIT16_MASK); + udp->ip_srcip_lsb = ((srcip >> 0) & BIT16_MASK); + udp->ip_destip_msb = ((dstip >> 16) & BIT16_MASK); + udp->ip_destip_lsb = ((dstip >> 0) & BIT16_MASK); // source port - udp->udp_srcport = sourceport; - udp->udp_destport = destport; + udp->udp_srcport = srcport; + udp->udp_destport = dstport; // other defines udp->udp_ethertype = 0x800; @@ -1579,6 +1572,9 @@ int* getDetectorPosition() { } int enableTenGigabitEthernet(int val) { +#ifdef VIRTUAL + return 0; +#endif uint32_t addr = CONFIG_REG; // set @@ -2157,11 +2153,16 @@ uint64_t getPatternBitMask() { int startStateMachine(){ #ifdef VIRTUAL - virtual_status = 1; + // create udp socket + if(createUDPSocket(0) != OK) { + return FAIL; + } + LOG(logINFOBLUE, ("Starting State Machine\n")); + virtual_status = 1; virtual_stop = 0; if(pthread_create(&pthread_virtual_tid, NULL, &start_timer, NULL)) { - virtual_status = 0; LOG(logERROR, ("Could not start Virtual acquisition thread\n")); + virtual_status = 0; return FAIL; } LOG(logINFOGREEN, ("Virtual Acquisition started\n")); @@ -2195,41 +2196,83 @@ int startStateMachine(){ #ifdef VIRTUAL void* start_timer(void* arg) { - int64_t periodns = getPeriod(); + int64_t periodNs = getPeriod(); int numFrames = (getNumFrames() * getNumTriggers() ); - int64_t exp_ns = getExpTime(); + int64_t expUs = getExpTime() / 1000; - int frameNr = 0; - // loop over number of frames - for(frameNr=0; frameNr!= numFrames; ++frameNr ) { + int imageSize = dataBytes; + int dataSize = UDP_PACKET_DATA_BYTES; + int packetSize = sizeof(sls_detector_header) + dataSize; + int packetsPerFrame = ceil((double)imageSize / (double)dataSize); - //check if virtual_stop is high - if(virtual_stop == 1){ - break; - } - - // sleep for exposure time - struct timespec begin, end; - clock_gettime(CLOCK_REALTIME, &begin); - usleep(exp_ns / 1000); - clock_gettime(CLOCK_REALTIME, &end); - - // calculate time left in period - int64_t time_ns = ((end.tv_sec - begin.tv_sec) * 1E9 + - (end.tv_nsec - begin.tv_nsec)); - - // sleep for (period - exptime) - if (frameNr < numFrames) { // if there is a next frame - if (periodns > time_ns) { - usleep((periodns - time_ns)/ 1000); - } - } - - // set register frames left + // Generate Data + char imageData[imageSize]; + memset(imageData, 0, imageSize); + { + int i = 0; + for (i = 0; i < imageSize; i += sizeof(uint16_t)) { + *((uint16_t*)(imageData + i)) = i; + } } - // set status to idle + // Send data + { + int frameNr = 0; + // loop over number of frames + for(frameNr=0; frameNr!= numFrames; ++frameNr ) { + + //check if virtual_stop is high + if(virtual_stop == 1){ + break; + } + + // sleep for exposure time + struct timespec begin, end; + clock_gettime(CLOCK_REALTIME, &begin); + usleep(expUs); + + int srcOffset = 0; + char packetData[packetSize]; + memset(packetData, 0, packetSize); + + // loop packet + { + int i = 0; + for(i = 0; i != packetsPerFrame; ++i) { + // set header + sls_detector_header* header = (sls_detector_header*)(packetData); + header->detType = (uint16_t)myDetectorType; + header->version = SLS_DETECTOR_HEADER_VERSION - 1; + header->frameNumber = frameNr; + header->packetNumber = i; + header->modId = 0; + header->row = detPos[X]; + header->column = detPos[Y]; + + // fill data + memcpy(packetData + sizeof(sls_detector_header), imageData + srcOffset, dataSize); + srcOffset += dataSize; + + sendUDPPacket(0, packetData, packetSize); + } + } + LOG(logINFO, ("Sent frame: %d\n", frameNr)); + clock_gettime(CLOCK_REALTIME, &end); + int64_t timeNs = ((end.tv_sec - begin.tv_sec) * 1E9 + + (end.tv_nsec - begin.tv_nsec)); + + // sleep for (period - exptime) + if (frameNr < numFrames) { // if there is a next frame + if (periodNs > timeNs) { + usleep((periodNs - timeNs)/ 1000); + } + } + } + } + + closeUDPSocket(0); + virtual_status = 0; LOG(logINFOBLUE, ("Finished Acquiring\n")); return NULL; diff --git a/slsDetectorServers/eigerDetectorServer/slsDetectorFunctionList.c b/slsDetectorServers/eigerDetectorServer/slsDetectorFunctionList.c index 2a59ce9b4..db5f40809 100755 --- a/slsDetectorServers/eigerDetectorServer/slsDetectorFunctionList.c +++ b/slsDetectorServers/eigerDetectorServer/slsDetectorFunctionList.c @@ -1200,21 +1200,20 @@ enum timingMode getTiming() { /* configure mac */ int configureMAC() { - uint32_t sourceip = udpDetails.srcip; - uint32_t destip = udpDetails.dstip; - uint64_t sourcemac = udpDetails.srcmac; - uint64_t destmac = udpDetails.dstmac; - int src_port = udpDetails.srcport; - int destport = udpDetails.dstport; - int destport2 = udpDetails.dstport2; + uint32_t srcip = udpDetails.srcip; + uint32_t dstip = udpDetails.dstip; + uint64_t srcmac = udpDetails.srcmac; + uint64_t dstmac = udpDetails.dstmac; + int srcport = udpDetails.srcport; + int dstport = udpDetails.dstport; + int dstport2 = udpDetails.dstport2; - LOG(logINFO, ("Configuring MAC\n")); - + LOG(logINFOBLUE, ("Configuring MAC\n")); 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); + getMacAddressinString(src_mac, 50, srcmac); + getMacAddressinString(dst_mac, 50, dstmac); + getIpAddressinString(src_ip, srcip); + getIpAddressinString(dst_ip, dstip); LOG(logINFO, ( "\tSource IP : %s\n" @@ -1224,19 +1223,15 @@ int configureMAC() { "\tDest MAC : %s\n" "\tDest Port : %d\n" "\tDest Port2 : %d\n", - src_ip, src_mac, src_port, - dst_ip, dst_mac, destport, destport2)); + src_ip, src_mac, srcport, + dst_ip, dst_mac, dstport, dstport2)); #ifdef VIRTUAL - char cDestIp[MAX_STR_LENGTH]; - memset(cDestIp, 0, MAX_STR_LENGTH); - sprintf(cDestIp, "%d.%d.%d.%d", (destip>>24)&0xff,(destip>>16)&0xff,(destip>>8)&0xff,(destip)&0xff); - LOG(logINFO, ("1G UDP: Destination (IP: %s, port:%d, port2:%d)\n", cDestIp, destport, destport2)); - if (setUDPDestinationDetails(0, cDestIp, destport) == FAIL) { + if (setUDPDestinationDetails(0, dst_ip, dstport) == FAIL) { LOG(logERROR, ("could not set udp destination IP and port\n")); return FAIL; } - if (setUDPDestinationDetails(1, cDestIp, destport2) == FAIL) { + if (setUDPDestinationDetails(1, dst_ip, dstport2) == FAIL) { LOG(logERROR, ("could not set udp destination IP and port2\n")); return FAIL; } @@ -1245,11 +1240,9 @@ int configureMAC() { int beb_num = detid; int header_number = 0; - int dst_port = destport; + int dst_port = dstport; if (!top) - dst_port = destport2; - - LOG(logINFO, ("\tDest Port : %d\n", dst_port)); + dst_port = dstport2; int i=0; /* for(i=0;i<32;i++) { modified for Aldo*/ @@ -1262,10 +1255,9 @@ int configureMAC() { /*}*/ header_number = 32; - dst_port = destport2; + dst_port = dstport2; if (!top) - dst_port = destport; - LOG(logINFO, ("\tDest Port : %d\n",dst_port)); + dst_port = dstport; /*for(i=0;i<32;i++) {*//** modified for Aldo*/ if (Beb_SetBebSrcHeaderInfos(beb_num,send_to_ten_gig,src_mac,src_ip,src_port) && @@ -1752,7 +1744,7 @@ int startStateMachine() { if(createUDPSocket(1) != OK) { return FAIL; } - LOG(logINFOBLUE, ("starting state machine\n")); + LOG(logINFOBLUE, ("Starting State Machine\n")); eiger_virtual_status = 1; eiger_virtual_stop = 0; if (pthread_create(&eiger_virtual_tid, NULL, &start_timer, NULL)) { @@ -1763,7 +1755,7 @@ int startStateMachine() { LOG(logINFO ,("Virtual Acquisition started\n")); return OK; #else - + LOG(logINFOBLUE, ("Starting State Machine\n")); int ret = OK,prev_flag; //get the DAQ toggle bit prev_flag = Feb_Control_AcquisitionStartedBit(); @@ -1791,9 +1783,9 @@ int startStateMachine() { #ifdef VIRTUAL void* start_timer(void* arg) { - int64_t periodns = eiger_virtual_period; + int64_t periodNs = eiger_virtual_period; int numFrames = nimages_per_request; - int64_t exp_us = eiger_virtual_exptime / 1000; + int64_t expUs = eiger_virtual_exptime / 1000; int dr = eiger_dynamicrange; double bytesPerPixel = (double)dr/8.00; @@ -1811,7 +1803,7 @@ void* start_timer(void* arg) { LOG(logINFO, (" dr:%d\n bytesperpixel:%f\n tgenable:%d\n datasize:%d\n packetsize:%d\n numpackes:%d\n npixelsx:%d\n databytes:%d\n ntotpixels:%d\n", dr, bytesPerPixel, tgEnable, datasize, packetsize, numPacketsPerFrame, npixelsx, databytes, ntotpixels)); - //TODO: Generate data + // Generate data char imageData[databytes * 2]; memset(imageData, 0, databytes * 2); { @@ -1842,9 +1834,10 @@ void* start_timer(void* arg) { } } - //TODO: Send data + // Send data { int frameNr = 1; + // loop over number of frames for(frameNr=1; frameNr <= numFrames; ++frameNr ) { usleep(eiger_virtual_transmission_delay_frame); @@ -1854,12 +1847,13 @@ void* start_timer(void* arg) { break; } - int srcOffset = 0; - int srcOffset2 = npixelsx; - + // sleep for exposure time struct timespec begin, end; clock_gettime(CLOCK_REALTIME, &begin); - usleep(exp_us); + usleep(expUs); + + int srcOffset = 0; + int srcOffset2 = npixelsx; char packetData[packetsize]; memset(packetData, 0, packetsize); char packetData2[packetsize]; @@ -1929,13 +1923,13 @@ void* start_timer(void* arg) { } LOG(logINFO, ("Sent frame: %d\n", frameNr)); clock_gettime(CLOCK_REALTIME, &end); - int64_t time_ns = ((end.tv_sec - begin.tv_sec) * 1E9 + + int64_t timeNs = ((end.tv_sec - begin.tv_sec) * 1E9 + (end.tv_nsec - begin.tv_nsec)); // sleep for (period - exptime) if (frameNr < numFrames) { // if there is a next frame - if (periodns > time_ns) { - usleep((periodns - time_ns)/ 1000); + if (periodNs > timeNs) { + usleep((periodNs - timeNs)/ 1000); } } } diff --git a/slsDetectorServers/gotthard2DetectorServer/slsDetectorFunctionList.c b/slsDetectorServers/gotthard2DetectorServer/slsDetectorFunctionList.c index 89ba8ae64..25ded2347 100644 --- a/slsDetectorServers/gotthard2DetectorServer/slsDetectorFunctionList.c +++ b/slsDetectorServers/gotthard2DetectorServer/slsDetectorFunctionList.c @@ -25,6 +25,10 @@ extern int checkModuleFlag; extern udpStruct udpDetails; extern const enum detectorType myDetectorType; +// Global variable from communication_funcs.c +extern void getMacAddressinString(char* cmac, int size, uint64_t mac); +extern void getIpAddressinString(char* cip, uint32_t ip); + int initError = OK; int initCheckDone = 0; char initErrorMessage[MAX_STR_LENGTH]; @@ -2067,7 +2071,6 @@ void* start_timer(void* arg) { struct timespec begin, end; clock_gettime(CLOCK_REALTIME, &begin); usleep(exp_ns / 1000); - clock_gettime(CLOCK_REALTIME, &end); char packetData[packetsize]; memset(packetData, 0, packetsize); @@ -2086,6 +2089,7 @@ void* start_timer(void* arg) { // send 1 packet = 1 frame sendUDPPacket(0, packetData, packetsize); + clock_gettime(CLOCK_REALTIME, &end); LOG(logINFO, ("Sent frame: %d\n", frameNr)); // calculate time left in period diff --git a/slsDetectorServers/gotthardDetectorServer/CMakeLists.txt b/slsDetectorServers/gotthardDetectorServer/CMakeLists.txt index 6055fcbc4..8d38278af 100644 --- a/slsDetectorServers/gotthardDetectorServer/CMakeLists.txt +++ b/slsDetectorServers/gotthardDetectorServer/CMakeLists.txt @@ -9,6 +9,7 @@ add_executable(gotthardDetectorServer_virtual ../slsDetectorServer/src/LTC2620.c ../slsDetectorServer/src/common.c ../slsDetectorServer/src/commonServerFunctions.c + ../slsDetectorServer/src/communication_funcs_UDP.c ) include_directories( diff --git a/slsDetectorServers/gotthardDetectorServer/slsDetectorFunctionList.c b/slsDetectorServers/gotthardDetectorServer/slsDetectorFunctionList.c index 133879600..1279e06ef 100755 --- a/slsDetectorServers/gotthardDetectorServer/slsDetectorFunctionList.c +++ b/slsDetectorServers/gotthardDetectorServer/slsDetectorFunctionList.c @@ -4,19 +4,28 @@ #include "RegisterDefs.h" #include "LTC2620.h" // dacs +#ifdef VIRTUAL +#include "communication_funcs_UDP.h" +#endif #include "string.h" #include // usleep +#include #ifdef VIRTUAL #include #include #endif extern udpStruct udpDetails; +extern const enum detectorType myDetectorType; // Variables that will be exported int phaseShift = DEFAULT_PHASE_SHIFT; +// Global variable from communication_funcs.c +extern void getMacAddressinString(char* cmac, int size, uint64_t mac); +extern void getIpAddressinString(char* cip, uint32_t ip); + int initError = OK; int initCheckDone = 0; char initErrorMessage[MAX_STR_LENGTH]; @@ -1263,44 +1272,42 @@ void calcChecksum(mac_conf* mac, int sourceip, int destip) { } int configureMAC() { - uint32_t sourceip = udpDetails.srcip; - uint32_t destip = udpDetails.dstip; - uint64_t sourcemac = udpDetails.srcmac; - uint64_t destmac = udpDetails.dstmac; - int sourceport = udpDetails.srcport; - int destport = udpDetails.dstport; + uint32_t srcip = udpDetails.srcip; + uint32_t dstip = udpDetails.dstip; + uint64_t srcmac = udpDetails.srcmac; + uint64_t dstmac = udpDetails.dstmac; + int srcport = udpDetails.srcport; + int dstport = udpDetails.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); + getIpAddressinString(src_ip, srcip); + getIpAddressinString(dst_ip, dstip); + + LOG(logINFO, ( + "\tSource IP : %s\n" + "\tSource MAC : %s\n" + "\tSource Port : %d\n" + "\tDest IP : %s\n" + "\tDest MAC : %s\n" + "\tDest Port : %d\n", + src_ip, src_mac, srcport, + dst_ip, dst_mac, dstport)); + #ifdef VIRTUAL + if (setUDPDestinationDetails(0, dst_ip, dstport) == FAIL) { + LOG(logERROR, ("could not set udp 1G destination IP and port\n")); + return FAIL; + } return OK; #endif - LOG(logINFOBLUE, ("Configuring MAC\n")); u_int32_t addr = MULTI_PURPOSE_REG; LOG(logDEBUG1, ("\tRoi: %d, Ip Packet size: %d UDP Packet size: %d\n", adcConfigured, ipPacketSize, udpPacketSize)); - LOG(logINFO, ("\tSource IP : %d.%d.%d.%d (0x%08x)\n", - (sourceip>>24)&0xff,(sourceip>>16)&0xff,(sourceip>>8)&0xff,(sourceip)&0xff, sourceip)); - LOG(logINFO, ("\tSource MAC : %02x:%02x:%02x:%02x:%02x:%02x (0x%010llx)\n", - (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), - (long long unsigned int)sourcemac)); - LOG(logINFO, ("\tSource Port : %d (0x%08x)\n",sourceport, sourceport)); - LOG(logINFO, ("\tDest. IP : %d.%d.%d.%d (0x%08x)\n", - (destip>>24)&0xff,(destip>>16)&0xff,(destip>>8)&0xff,(destip)&0xff, destip)); - LOG(logINFO, ("\tDest. MAC : %02x:%02x:%02x:%02x:%02x:%02x (0x%010llx)\n", - (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), - (long long unsigned int)destmac)); - LOG(logINFO, ("\tDest. Port : %d (0x%08x)\n",destport, destport)); - //reset mac bus_w (addr, bus_r(addr) | RST_MSK); LOG(logDEBUG1, ("\tReset Mac. MultiPurpose reg: 0x%x\n", bus_r(addr))); @@ -1321,28 +1328,28 @@ int configureMAC() { LOG(logDEBUG1, ("\tConfiguring MAC CONF\n")); mac_conf *mac_conf_regs = (mac_conf*)(Blackfin_getBaseAddress() + ENET_CONF_REG / 2); // direct write - mac_conf_regs->mac.mac_dest_mac1 = ((destmac >> (8 * 5)) & 0xFF); - mac_conf_regs->mac.mac_dest_mac2 = ((destmac >> (8 * 4)) & 0xFF); - mac_conf_regs->mac.mac_dest_mac3 = ((destmac >> (8 * 3)) & 0xFF); - mac_conf_regs->mac.mac_dest_mac4 = ((destmac >> (8 * 2)) & 0xFF); - mac_conf_regs->mac.mac_dest_mac5 = ((destmac >> (8 * 1)) & 0xFF); - mac_conf_regs->mac.mac_dest_mac6 = ((destmac >> (8 * 0)) & 0xFF); + mac_conf_regs->mac.mac_dest_mac1 = ((dstmac >> (8 * 5)) & 0xFF); + mac_conf_regs->mac.mac_dest_mac2 = ((dstmac >> (8 * 4)) & 0xFF); + mac_conf_regs->mac.mac_dest_mac3 = ((dstmac >> (8 * 3)) & 0xFF); + mac_conf_regs->mac.mac_dest_mac4 = ((dstmac >> (8 * 2)) & 0xFF); + mac_conf_regs->mac.mac_dest_mac5 = ((dstmac >> (8 * 1)) & 0xFF); + mac_conf_regs->mac.mac_dest_mac6 = ((dstmac >> (8 * 0)) & 0xFF); LOG(logDEBUG1, ("\tDestination Mac: %llx %x:%x:%x:%x:%x:%x\n", - destmac, + dstmac, mac_conf_regs->mac.mac_dest_mac1, mac_conf_regs->mac.mac_dest_mac2, mac_conf_regs->mac.mac_dest_mac3, mac_conf_regs->mac.mac_dest_mac4, mac_conf_regs->mac.mac_dest_mac5, mac_conf_regs->mac.mac_dest_mac6)); - mac_conf_regs->mac.mac_src_mac1 = ((sourcemac >> (8 * 5)) & 0xFF); - mac_conf_regs->mac.mac_src_mac2 = ((sourcemac >> (8 * 4)) & 0xFF); - mac_conf_regs->mac.mac_src_mac3 = ((sourcemac >> (8 * 3)) & 0xFF); - mac_conf_regs->mac.mac_src_mac4 = ((sourcemac >> (8 * 2)) & 0xFF); - mac_conf_regs->mac.mac_src_mac5 = ((sourcemac >> (8 * 1)) & 0xFF); - mac_conf_regs->mac.mac_src_mac6 = ((sourcemac >> (8 * 0)) & 0xFF); + mac_conf_regs->mac.mac_src_mac1 = ((srcmac >> (8 * 5)) & 0xFF); + mac_conf_regs->mac.mac_src_mac2 = ((srcmac >> (8 * 4)) & 0xFF); + mac_conf_regs->mac.mac_src_mac3 = ((srcmac >> (8 * 3)) & 0xFF); + mac_conf_regs->mac.mac_src_mac4 = ((srcmac >> (8 * 2)) & 0xFF); + mac_conf_regs->mac.mac_src_mac5 = ((srcmac >> (8 * 1)) & 0xFF); + mac_conf_regs->mac.mac_src_mac6 = ((srcmac >> (8 * 0)) & 0xFF); LOG(logDEBUG1, ("\tSource Mac: %llx %x:%x:%x:%x:%x:%x\n", - sourcemac, + srcmac, mac_conf_regs->mac.mac_src_mac1, mac_conf_regs->mac.mac_src_mac2, mac_conf_regs->mac.mac_src_mac3, @@ -1351,9 +1358,9 @@ int configureMAC() { mac_conf_regs->mac.mac_src_mac6)); mac_conf_regs->mac.mac_ether_type = 0x0800; //ipv4 - calcChecksum(mac_conf_regs, sourceip, destip); - mac_conf_regs->udp.udp_srcport = sourceport; - mac_conf_regs->udp.udp_destport = destport; + calcChecksum(mac_conf_regs, srcip, dstip); + mac_conf_regs->udp.udp_srcport = srcport; + mac_conf_regs->udp.udp_destport = dstport; mac_conf_regs->udp.udp_len = udpPacketSize; mac_conf_regs->udp.udp_chksum = 0x0000; @@ -1488,11 +1495,16 @@ int setPhase(enum CLKINDEX ind, int val, int degrees) { int startStateMachine(){ #ifdef VIRTUAL - virtual_status = 1; + // create udp socket + if(createUDPSocket(0) != OK) { + return FAIL; + } + LOG(logINFOBLUE, ("Starting State Machine\n")); + virtual_status = 1; virtual_stop = 0; if(pthread_create(&pthread_virtual_tid, NULL, &start_timer, NULL)) { - virtual_status = 0; LOG(logERROR, ("Could not start Virtual acquisition thread\n")); + virtual_status = 0; return FAIL; } LOG(logINFOGREEN, ("Virtual Acquisition started\n")); @@ -1512,17 +1524,83 @@ int startStateMachine(){ #ifdef VIRTUAL void* start_timer(void* arg) { - int wait_in_s = (getNumFrames() * - getNumTriggers() * - (getPeriod()/(1E9))); - LOG(logDEBUG1, ("going to wait for %d s\n", wait_in_s)); - while(!virtual_stop && (wait_in_s >= 0)) { - usleep(1000 * 1000); - wait_in_s--; - } - LOG(logINFOGREEN, ("Virtual Timer Done\n")); + int64_t periodNs = getPeriod(); + int numFrames = (getNumFrames() * + getNumTriggers() ); + int64_t expUs = getExpTime() / 1000; + + int imageSize = adcConfigured == -1 ? DATA_BYTES : NCHAN_PER_ADC * NUM_BITS_PER_PIXEL; + int dataSize = adcConfigured == -1 ? 1280 : 512; + int packetSize = adcConfigured == -1 ? 1286 : 518; + int packetsPerFrame = adcConfigured == -1 ? 2 : 1; + + // Generate Data + char imageData[imageSize]; + memset(imageData, 0, imageSize); + { + int i = 0; + if (adcConfigured == -1) { + *((uint32_t*)(imageData)) = 0xCACACACA; + } + for (i = 4; i < imageSize; i += sizeof(uint16_t)) { + *((uint16_t*)(imageData + i)) = i; + } + } + + // Send data + { + int frameNr = 0; + int frameHeaderNr = 2; + // loop over number of frames + for(frameNr=0; frameNr!= numFrames; ++frameNr ) { + + //check if virtual_stop is high + if(virtual_stop == 1){ + break; + } + + // sleep for exposure time + struct timespec begin, end; + clock_gettime(CLOCK_REALTIME, &begin); + usleep(expUs); + + int srcOffset = 0; + char packetData[packetSize]; + memset(packetData, 0, packetSize); + + // loop packet + { + int i = 0; + for(i = 0; i != packetsPerFrame; ++i) { + // set header + *((uint16_t*)(packetData)) = frameHeaderNr; + ++frameHeaderNr; + + // fill data + memcpy(packetData + 4, imageData + srcOffset, dataSize); + srcOffset += dataSize; + + sendUDPPacket(0, packetData, packetSize); + } + } + LOG(logINFO, ("Sent frame: %d\n", frameNr)); + clock_gettime(CLOCK_REALTIME, &end); + int64_t timeNs = ((end.tv_sec - begin.tv_sec) * 1E9 + + (end.tv_nsec - begin.tv_nsec)); + + // sleep for (period - exptime) + if (frameNr < numFrames) { // if there is a next frame + if (periodNs > timeNs) { + usleep((periodNs - timeNs)/ 1000); + } + } + } + } + + closeUDPSocket(0); virtual_status = 0; + LOG(logINFOBLUE, ("Finished Acquiring\n")); return NULL; } #endif diff --git a/slsDetectorServers/jungfrauDetectorServer/slsDetectorFunctionList.c b/slsDetectorServers/jungfrauDetectorServer/slsDetectorFunctionList.c index dba6bad05..7392b5975 100755 --- a/slsDetectorServers/jungfrauDetectorServer/slsDetectorFunctionList.c +++ b/slsDetectorServers/jungfrauDetectorServer/slsDetectorFunctionList.c @@ -23,6 +23,10 @@ extern int debugflag; extern udpStruct udpDetails; extern const enum detectorType myDetectorType; +// Global variable from communication_funcs.c +extern void getMacAddressinString(char* cmac, int size, uint64_t mac); +extern void getIpAddressinString(char* cip, uint32_t ip); + int initError = OK; int initCheckDone = 0; char initErrorMessage[MAX_STR_LENGTH]; @@ -1672,7 +1676,7 @@ void* start_timer(void* arg) { const int numPacketsPerFrame = 128; int transmissionDelayUs = getTransmissionDelayFrame() * 1000; - //TODO: Generate data + // Generate data char imageData[DATA_BYTES]; memset(imageData, 0, DATA_BYTES); { @@ -1684,7 +1688,7 @@ void* start_timer(void* arg) { } - //TODO: Send data + // Send data { int frameNr = 0; for(frameNr=0; frameNr!= numFrames; ++frameNr ) { @@ -1696,13 +1700,12 @@ void* start_timer(void* arg) { break; } - int srcOffset = 0; - + // sleep for exposure time struct timespec begin, end; clock_gettime(CLOCK_REALTIME, &begin); - usleep(exp_us); + int srcOffset = 0; char packetData[packetsize]; memset(packetData, 0, packetsize); diff --git a/slsDetectorServers/moenchDetectorServer/slsDetectorFunctionList.c b/slsDetectorServers/moenchDetectorServer/slsDetectorFunctionList.c index 4e1e22470..1db423728 100755 --- a/slsDetectorServers/moenchDetectorServer/slsDetectorFunctionList.c +++ b/slsDetectorServers/moenchDetectorServer/slsDetectorFunctionList.c @@ -11,19 +11,26 @@ #include #include // usleep +#include #ifdef VIRTUAL #include #include +#include //ceil #endif // Global variable from slsDetectorServer_funcs extern int debugflag; extern udpStruct udpDetails; +extern const enum detectorType myDetectorType; // Global variable from UDPPacketHeaderGenerator extern uint64_t udpFrameNumber; extern uint32_t udpPacketNumber; +// Global variable from communication_funcs.c +extern void getMacAddressinString(char* cmac, int size, uint64_t mac); +extern void getIpAddressinString(char* cip, uint32_t ip); + int initError = OK; int initCheckDone = 0; char initErrorMessage[MAX_STR_LENGTH]; @@ -1136,26 +1143,36 @@ void calcChecksum(udp_header* udp) { int configureMAC(){ - uint32_t sourceip = udpDetails.srcip; - uint32_t destip = udpDetails.dstip; - uint64_t sourcemac = udpDetails.srcmac; - uint64_t destmac = udpDetails.dstmac; - int sourceport = udpDetails.srcport; - int destport = udpDetails.dstport; -#ifdef VIRTUAL - return OK; -#endif + uint32_t srcip = udpDetails.srcip; + uint32_t dstip = udpDetails.dstip; + uint64_t srcmac = udpDetails.srcmac; + uint64_t dstmac = udpDetails.dstmac; + int srcport = udpDetails.srcport; + int dstport = udpDetails.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); + getIpAddressinString(src_ip, srcip); + getIpAddressinString(dst_ip, dstip); + + LOG(logINFO, ( + "\tSource IP : %s\n" + "\tSource MAC : %s\n" + "\tSource Port : %d\n" + "\tDest IP : %s\n" + "\tDest MAC : %s\n" + "\tDest Port : %d\n", + src_ip, src_mac, srcport, + dst_ip, dst_mac, dstport)); + // 1 giga udp if (!enableTenGigabitEthernet(-1)) { - LOG(logINFOBLUE, ("Configuring 1G MAC\n")); + LOG(logINFOBLUE, ("\t1G MAC\n")); if (updateDatabytesandAllocateRAM() == FAIL) return -1; - char cDestIp[MAX_STR_LENGTH]; - memset(cDestIp, 0, MAX_STR_LENGTH); - sprintf(cDestIp, "%d.%d.%d.%d", (destip>>24)&0xff,(destip>>16)&0xff,(destip>>8)&0xff,(destip)&0xff); - LOG(logINFO, ("1G UDP: Destination (IP: %s, port:%d)\n", cDestIp, destport)); - if (setUDPDestinationDetails(0, cDestIp, destport) == FAIL) { + if (setUDPDestinationDetails(0, dst_ip, dstport) == FAIL) { LOG(logERROR, ("could not set udp 1G destination IP and port\n")); return FAIL; } @@ -1163,31 +1180,7 @@ int configureMAC(){ } // 10 G - LOG(logINFOBLUE, ("Configuring 10G MAC\n")); - - LOG(logINFO, ("\tSource IP : %d.%d.%d.%d \t\t(0x%08x)\n", - (sourceip>>24)&0xff,(sourceip>>16)&0xff,(sourceip>>8)&0xff,(sourceip)&0xff, sourceip)); - LOG(logINFO, ("\tSource MAC : %02x:%02x:%02x:%02x:%02x:%02x \t(0x%010llx)\n", - (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), - (long long unsigned int)sourcemac)); - LOG(logINFO, ("\tSource Port : %d \t\t\t(0x%08x)\n",sourceport, sourceport)); - - LOG(logINFO, ("\tDest. IP : %d.%d.%d.%d \t\t(0x%08x)\n", - (destip>>24)&0xff,(destip>>16)&0xff,(destip>>8)&0xff,(destip)&0xff, destip)); - LOG(logINFO, ("\tDest. MAC : %02x:%02x:%02x:%02x:%02x:%02x \t(0x%010llx)\n", - (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), - (long long unsigned int)destmac)); - LOG(logINFO, ("\tDest. Port : %d \t\t\t(0x%08x)\n",destport, destport)); + LOG(logINFOBLUE, ("\t10G MAC\n")); // start addr uint32_t addr = RXR_ENDPOINT_START_REG; @@ -1197,21 +1190,21 @@ int configureMAC(){ // mac addresses // msb (32) + lsb (16) - udp->udp_destmac_msb = ((destmac >> 16) & BIT32_MASK); - udp->udp_destmac_lsb = ((destmac >> 0) & BIT16_MASK); + udp->udp_destmac_msb = ((dstmac >> 16) & BIT32_MASK); + udp->udp_destmac_lsb = ((dstmac >> 0) & BIT16_MASK); // msb (16) + lsb (32) - udp->udp_srcmac_msb = ((sourcemac >> 32) & BIT16_MASK); - udp->udp_srcmac_lsb = ((sourcemac >> 0) & BIT32_MASK); + udp->udp_srcmac_msb = ((srcmac >> 32) & BIT16_MASK); + udp->udp_srcmac_lsb = ((srcmac >> 0) & BIT32_MASK); // ip addresses - udp->ip_srcip_msb = ((sourceip >> 16) & BIT16_MASK); - udp->ip_srcip_lsb = ((sourceip >> 0) & BIT16_MASK); - udp->ip_destip_msb = ((destip >> 16) & BIT16_MASK); - udp->ip_destip_lsb = ((destip >> 0) & BIT16_MASK); + udp->ip_srcip_msb = ((srcip >> 16) & BIT16_MASK); + udp->ip_srcip_lsb = ((srcip >> 0) & BIT16_MASK); + udp->ip_destip_msb = ((dstip >> 16) & BIT16_MASK); + udp->ip_destip_lsb = ((dstip >> 0) & BIT16_MASK); // source port - udp->udp_srcport = sourceport; - udp->udp_destport = destport; + udp->udp_srcport = srcport; + udp->udp_destport = dstport; // other defines udp->udp_ethertype = 0x800; @@ -1242,6 +1235,9 @@ int* getDetectorPosition() { } int enableTenGigabitEthernet(int val) { +#ifdef VIRTUAL + return 0; +#endif uint32_t addr = CONFIG_REG; // set @@ -1819,11 +1815,16 @@ uint64_t getPatternBitMask() { int startStateMachine(){ #ifdef VIRTUAL - virtual_status = 1; + // create udp socket + if(createUDPSocket(0) != OK) { + return FAIL; + } + LOG(logINFOBLUE, ("Starting State Machine\n")); + virtual_status = 1; virtual_stop = 0; if(pthread_create(&pthread_virtual_tid, NULL, &start_timer, NULL)) { - virtual_status = 0; LOG(logERROR, ("Could not start Virtual acquisition thread\n")); + virtual_status = 0; return FAIL; } LOG(logINFOGREEN, ("Virtual Acquisition started\n")); @@ -1857,41 +1858,83 @@ int startStateMachine(){ #ifdef VIRTUAL void* start_timer(void* arg) { - int64_t periodns = getPeriod(); + int64_t periodNs = getPeriod(); int numFrames = (getNumFrames() * getNumTriggers() ); - int64_t exp_ns = getExpTime(); + int64_t expNs = getExpTime(); - int frameNr = 0; - // loop over number of frames - for(frameNr=0; frameNr!= numFrames; ++frameNr ) { + int imageSize = dataBytes; + int dataSize = UDP_PACKET_DATA_BYTES; + int packetSize = sizeof(sls_detector_header) + dataSize; + int packetsPerFrame = ceil((double)imageSize / (double)dataSize); - //check if virtual_stop is high - if(virtual_stop == 1){ - break; - } - - // sleep for exposure time - struct timespec begin, end; - clock_gettime(CLOCK_REALTIME, &begin); - usleep(exp_ns / 1000); - clock_gettime(CLOCK_REALTIME, &end); - - // calculate time left in period - int64_t time_ns = ((end.tv_sec - begin.tv_sec) * 1E9 + - (end.tv_nsec - begin.tv_nsec)); - - // sleep for (period - exptime) - if (frameNr < numFrames) { // if there is a next frame - if (periodns > time_ns) { - usleep((periodns - time_ns)/ 1000); - } - } - - // set register frames left + // Generate Data + char imageData[imageSize]; + memset(imageData, 0, imageSize); + { + int i = 0; + for (i = 0; i < imageSize; i += sizeof(uint16_t)) { + *((uint16_t*)(imageData + i)) = i; + } } - // set status to idle + // Send data + { + int frameNr = 0; + // loop over number of frames + for(frameNr=0; frameNr!= numFrames; ++frameNr ) { + + //check if virtual_stop is high + if(virtual_stop == 1){ + break; + } + + // sleep for exposure time + struct timespec begin, end; + clock_gettime(CLOCK_REALTIME, &begin); + usleep(expNs / 1000); + + int srcOffset = 0; + char packetData[packetSize]; + memset(packetData, 0, packetSize); + + // loop packet + { + int i = 0; + for(i = 0; i != packetsPerFrame; ++i) { + // set header + sls_detector_header* header = (sls_detector_header*)(packetData); + header->detType = (uint16_t)myDetectorType; + header->version = SLS_DETECTOR_HEADER_VERSION - 1; + header->frameNumber = frameNr; + header->packetNumber = i; + header->modId = 0; + header->row = detPos[X]; + header->column = detPos[Y]; + + // fill data + memcpy(packetData + sizeof(sls_detector_header), imageData + srcOffset, dataSize); + srcOffset += dataSize; + + sendUDPPacket(0, packetData, packetSize); + } + } + LOG(logINFO, ("Sent frame: %d\n", frameNr)); + clock_gettime(CLOCK_REALTIME, &end); + int64_t timeNs = ((end.tv_sec - begin.tv_sec) * 1E9 + + (end.tv_nsec - begin.tv_nsec)); + + // sleep for (period - exptime) + if (frameNr < numFrames) { // if there is a next frame + if (periodNs > timeNs) { + usleep((periodNs - timeNs)/ 1000); + } + } + } + } + + closeUDPSocket(0); + virtual_status = 0; LOG(logINFOBLUE, ("Finished Acquiring\n")); return NULL; diff --git a/slsDetectorServers/mythen3DetectorServer/slsDetectorFunctionList.c b/slsDetectorServers/mythen3DetectorServer/slsDetectorFunctionList.c index 9d8158ec2..5c881b4f2 100644 --- a/slsDetectorServers/mythen3DetectorServer/slsDetectorFunctionList.c +++ b/slsDetectorServers/mythen3DetectorServer/slsDetectorFunctionList.c @@ -22,6 +22,10 @@ extern int debugflag; extern udpStruct udpDetails; extern const enum detectorType myDetectorType; +// Global variable from communication_funcs.c +extern void getMacAddressinString(char* cmac, int size, uint64_t mac); +extern void getIpAddressinString(char* cip, uint32_t ip); + int initError = OK; int initCheckDone = 0; char initErrorMessage[MAX_STR_LENGTH]; diff --git a/slsDetectorServers/slsDetectorServer/src/communication_funcs.c b/slsDetectorServers/slsDetectorServer/src/communication_funcs.c index 18c2ba516..7eaf89732 100755 --- a/slsDetectorServers/slsDetectorServer/src/communication_funcs.c +++ b/slsDetectorServers/slsDetectorServer/src/communication_funcs.c @@ -616,7 +616,12 @@ void getMacAddressinString(char* cmac, int size, uint64_t mac) { void getIpAddressinString(char* cip, uint32_t ip) { memset(cip, 0, INET_ADDRSTRLEN); +#if defined(EIGERD) && !defined(VIRTUAL) inet_ntop(AF_INET, &ip, cip, INET_ADDRSTRLEN); +#else + sprintf(cip, "%d.%d.%d.%d", + (ip>>24)&0xff,(ip>>16)&0xff,(ip>>8)&0xff,(ip)&0xff); +#endif } diff --git a/slsDetectorServers/slsDetectorServer/src/communication_funcs_UDP.c b/slsDetectorServers/slsDetectorServer/src/communication_funcs_UDP.c index dd3a4d635..edc9c7eab 100755 --- a/slsDetectorServers/slsDetectorServer/src/communication_funcs_UDP.c +++ b/slsDetectorServers/slsDetectorServer/src/communication_funcs_UDP.c @@ -16,7 +16,7 @@ int udpSockfd[2] = {-1, -1}; struct addrinfo* udpServerAddrInfo[2] = {0, 0}; unsigned short int udpDestinationPort[2] = {0, 0}; -char udpDestinationIp[2][MAX_STR_LENGTH] = {"", ""}; +char udpDestinationIp[2][INET_ADDRSTRLEN] = {"", ""}; //DEFAULT_TX_UDP_PORT;// src port int getUdPSocketDescriptor(int index) { @@ -26,8 +26,8 @@ int getUdPSocketDescriptor(int index) { int setUDPDestinationDetails(int index, const char* ip, unsigned short int port) { udpDestinationPort[index] = port; size_t len = strlen(ip); - memset(udpDestinationIp[index], 0, MAX_STR_LENGTH); - strncpy(udpDestinationIp[index], ip, len > MAX_STR_LENGTH ? MAX_STR_LENGTH : len ); + memset(udpDestinationIp[index], 0, INET_ADDRSTRLEN); + strncpy(udpDestinationIp[index], ip, len > INET_ADDRSTRLEN ? INET_ADDRSTRLEN : len ); if (udpServerAddrInfo[index]) { freeaddrinfo(udpServerAddrInfo[index]);