From fbfafb98fd0686471ddb64e66309160c5ba3c5e1 Mon Sep 17 00:00:00 2001 From: Dhanya Maliakal Date: Fri, 3 Jul 2015 16:10:04 +0200 Subject: [PATCH 01/68] small change --- .../include/UDPStandardImplementation.h | 11 +- .../src/UDPBaseImplementation.cpp | 2 +- .../src/UDPStandardImplementation.cpp | 173 +++++++++++++----- 3 files changed, 140 insertions(+), 46 deletions(-) diff --git a/slsReceiverSoftware/include/UDPStandardImplementation.h b/slsReceiverSoftware/include/UDPStandardImplementation.h index bad7f7a2e..99c159bcb 100644 --- a/slsReceiverSoftware/include/UDPStandardImplementation.h +++ b/slsReceiverSoftware/include/UDPStandardImplementation.h @@ -463,10 +463,19 @@ private: */ void stopWriting(int ithread, char* wbuffer[]); + /** + * updates parameters and writes to file when not a dummy frame + * Also calls writeToFile_withoutCompression or handleDataCompression + * Called by startWriting() + * @param ithread writing thread number + * @param wbuffer writer buffer + * @param npackets number of packets from the fifo + */ + int handleWithoutDataCompression(int ithread, char* wbuffer[], int &npackets); /** * data compression for each fifo output - * @param ithread listening thread number + * @param ithread writing thread number * @param wbuffer writer buffer * @param npackets number of packets from the fifo * @param data pointer to the next packet start diff --git a/slsReceiverSoftware/src/UDPBaseImplementation.cpp b/slsReceiverSoftware/src/UDPBaseImplementation.cpp index bbb8b331d..98adfb6e7 100644 --- a/slsReceiverSoftware/src/UDPBaseImplementation.cpp +++ b/slsReceiverSoftware/src/UDPBaseImplementation.cpp @@ -1826,7 +1826,7 @@ int i; void UDPBaseImplementation::stopWriting(int ithread, char* wbuffer[]){ FILE_LOG(logDEBUG) << __AT__ << " starting"; - int i,j; + int i; #ifdef VERYDEBUG cout << ithread << " **********************popped last dummy frame:" << (void*)wbuffer[wIndex] << endl; #endif diff --git a/slsReceiverSoftware/src/UDPStandardImplementation.cpp b/slsReceiverSoftware/src/UDPStandardImplementation.cpp index 0b22d8888..c93b52f9a 100644 --- a/slsReceiverSoftware/src/UDPStandardImplementation.cpp +++ b/slsReceiverSoftware/src/UDPStandardImplementation.cpp @@ -1734,19 +1734,19 @@ int UDPStandardImplementation::startListening(){ cout << ithread << " *** rc:" << dec << rc << ". expected:" << dec << expected << endl; #endif -/* + //start indices for each start of scan/acquisition - eiger does it before if((!measurementStarted) && (rc > 0) && (!ithread)) startFrameIndices(ithread); -*/ + //problem in receiving or end of acquisition if((rc < expected)||(rc <= 0)){ - if(myDetectorType != EIGER){ + /*if(myDetectorType != EIGER){ //start indices for each start of scan/acquisition - this should be done earlier for normal detectors if((!measurementStarted) && (rc > 0) && (!ithread)) startFrameIndices(ithread); - } + }*/ stopListening(ithread,rc,packetcount,total); continue; } @@ -1882,13 +1882,12 @@ int UDPStandardImplementation::startWriting(){ thread_started = 1; - int totalheader = HEADER_SIZE_NUM_TOT_PACKETS + EIGER_HEADER_LENGTH; int numpackets, nf; uint32_t tempframenum; char* wbuf[numListeningThreads];//interleaved char *d=new char[bufferSize*numListeningThreads]; int xmax=0,ymax=0; - int ret,i,j; + int ret,i; int packetsPerThread = packetsPerFrame/numListeningThreads; while(1){ @@ -1927,9 +1926,9 @@ int UDPStandardImplementation::startWriting(){ cprintf(MAGENTA,"%d writer poped from fifo %x\n", ithread, (void*)(wbuf[i])); #endif numpackets = (uint16_t)(*((uint16_t*)wbuf[i])); -#ifdef VERYDEBUG +//#ifdef VERYDEBUG cout << i << " numpackets:" << dec << numpackets << "for fifo :"<< i << endl; -#endif +//#endif } @@ -1947,7 +1946,7 @@ int UDPStandardImplementation::startWriting(){ - //for progress + //update current frame number for progress if(myDetectorType == EIGER){ if(dynamicRange != 32) @@ -1977,12 +1976,12 @@ int UDPStandardImplementation::startWriting(){ #endif - //without datacompression: write datacall back, or write data, free fifo + /* //without datacompression: write datacall back, or write data, free fifo if(!dataCompression){ if (cbAction < DO_EVERYTHING){ for(i=0;ifnum); - else*/ - startFrameIndex = htonl(*(unsigned int*)((eiger_image_header *)((char*)(buffer[ithread] + HEADER_SIZE_NUM_TOT_PACKETS)))->fnum); + startFrameIndex = htonl(*(unsigned int*)((eiger_image_header *)((char*)(buffer[ithread] + HEADER_SIZE_NUM_TOT_PACKETS)))->fnum); } //gotthard has +1 for frame number and not a short frame else if ((myDetectorType == GOTTHARD) && (shortFrame == -1)) @@ -2169,19 +2167,19 @@ void UDPStandardImplementation::startFrameIndices(int ithread){ startAcquisitionIndex=startFrameIndex; currframenum = startAcquisitionIndex; acqStarted = true; - cout << "startAcquisitionIndex:" << hex << startAcquisitionIndex<push(buffer[ithread]);/** why not while(!)*/ -#ifdef FIFO_DEBUG - cprintf(BLUE,"%d listener last buffer free pushed into fifofree %x\n", ithread,(void*)(buffer[ithread])); -#endif - } //eiger (complete frames) + other detectors - else{ - pc = (rc/onePacketSize); + pc = (rc/onePacketSize); #ifdef VERYDEBUG - cout << ithread << " last rc:"<push(buffer[ithread])); + (*((uint16_t*)(buffer[ithread]))) = pc; + totalListeningFrameCount[ithread] += pc; + while(!fifo[ithread]->push(buffer[ithread])); #ifdef FIFO_DEBUG - cprintf(RED,"%d listener last buffer pushed into fifo %x\n", ithread,(void*)(buffer[ithread])); + cprintf(RED,"%d listener last buffer pushed into fifo %x\n", ithread,(void*)(buffer[ithread])); #endif - } + } @@ -2269,9 +2256,9 @@ int i; #endif pthread_mutex_unlock(&(status_mutex)); -#ifdef VERYDEBUG +//#ifdef VERYDEBUG cout << ithread << ": Frames listened to " << dec << ((totalListeningFrameCount[ithread]*numListeningThreads)/packetsPerFrame) << endl; -#endif +//#endif //waiting for all listening threads to be done, to print final count of frames listened to if(ithread == 0){ @@ -2281,12 +2268,12 @@ int i; #endif while(listeningthreads_mask) usleep(5000); -#ifdef VERYDEBUG +//#ifdef VERYDEBUG t = 0; for(i=0;i 0){ + for(j=0;jnum1)) = currframenum; + //overwriting port number and dynamic range + if (!j) (*(uint8_t*)(((eiger_packet_header *)((char*)(wbuffer[j] + totalheader + EIGER_ONE_GIGA_ONE_PACKET_SIZE*i)))->num3)) = (dynamicRange<<2); + else (*(uint8_t*)(((eiger_packet_header *)((char*)(wbuffer[j] + totalheader + EIGER_ONE_GIGA_ONE_PACKET_SIZE*i)))->num3)) = ((dynamicRange<<2)|(0x1)); + +#ifdef VERYDEBUG + cprintf(RED, "%d - 0x%x - %d\n", i, + (*(uint8_t*)(((eiger_packet_header *)((char*)(wbuffer[j] + totalheader +i*EIGER_ONE_GIGA_ONE_PACKET_SIZE)))->num3)), + (*(uint8_t*)(((eiger_packet_header *)((char*)(wbuffer[j] + totalheader +i*EIGER_ONE_GIGA_ONE_PACKET_SIZE)))->num4))); +#endif + + } + + //for 32 bit,port number needs to be changed and packet number reconstructed + if(dynamicRange == 32){ + for (i = 0; i < packetsPerFrame/4; i++){ + //new packet number that has space for 16 bit + (*(uint16_t*)(((eiger_packet_header *)((char*)(wbuffer[j] + totalheader + EIGER_ONE_GIGA_ONE_PACKET_SIZE*i)))->num2)) + = ((*(uint8_t*)(((eiger_packet_header *)((char*)(wbuffer[j] + totalheader + EIGER_ONE_GIGA_ONE_PACKET_SIZE*i)))->num4))); + +#ifdef VERYDEBUG + cprintf(RED, "%d - 0x%x - %d - %d\n", i, + (*(uint8_t*)(((eiger_packet_header *)((char*)(wbuffer[j] + totalheader +i*EIGER_ONE_GIGA_ONE_PACKET_SIZE)))->num3)), + (*(uint8_t*)(((eiger_packet_header *)((char*)(wbuffer[j] + totalheader +i*EIGER_ONE_GIGA_ONE_PACKET_SIZE)))->num4)), + (*(uint16_t*)(((eiger_packet_header *)((char*)(wbuffer[j] + totalheader +i*EIGER_ONE_GIGA_ONE_PACKET_SIZE)))->num2))); +#endif + } + for (i = packetsPerFrame/4; i < packetsPerFrame/2; i++){ + //new packet number that has space for 16 bit + (*(uint16_t*)(((eiger_packet_header *)((char*)(wbuffer[j] + totalheader + EIGER_ONE_GIGA_ONE_PACKET_SIZE*i)))->num2)) + = ((*(uint8_t*)(((eiger_packet_header *)((char*)(wbuffer[j] + totalheader + EIGER_ONE_GIGA_ONE_PACKET_SIZE*i)))->num4))+(packetsPerFrame/4)); + +#ifdef VERYDEBUG + cprintf(RED, "%d -0x%x - %d - %d\n", i, + (*(uint8_t*)(((eiger_packet_header *)((char*)(wbuffer[j] + totalheader +i*EIGER_ONE_GIGA_ONE_PACKET_SIZE)))->num3)), + (*(uint8_t*)(((eiger_packet_header *)((char*)(wbuffer[j] + totalheader +i*EIGER_ONE_GIGA_ONE_PACKET_SIZE)))->num4)), + (*(uint16_t*)(((eiger_packet_header *)((char*)(wbuffer[j] + totalheader +i*EIGER_ONE_GIGA_ONE_PACKET_SIZE)))->num2))); +#endif + } + } + } +#endif + + writeToFile_withoutCompression(wbuffer[j], npackets,currframenum); + } +#ifdef VERYDEBUG + cprintf(BLUE,"written everyting\n"); +#endif + } + + + if(myDetectorType == EIGER) { +#ifdef VERYDEBUG + cprintf(BLUE,"gonna copy frame\n"); +#endif + copyFrameToGui(wbuffer,currframenum); +#ifdef VERYDEBUG + cprintf(BLUE,"copied frame\n"); +#endif + for(i=0;ipush(wbuffer[i])); +#ifdef FIFO_DEBUG + cprintf(BLUE,"%d writer freed pushed into fifofree %x for listener %d\n",ithread, (void*)(wbuffer[i]),i); +#endif + } + + + } + else{ + //copy to gui + if(npackets >= packetsPerFrame){//min 1 frame, but neednt be + //if(npackets == packetsPerFrame * numJobsPerThread){ //only full frames + copyFrameToGui(NULL,-1,wbuffer[0]+HEADER_SIZE_NUM_TOT_PACKETS); +#ifdef VERYVERBOSE + cout << ithread << " finished copying" << endl; +#endif + }//else cout << "unfinished buffersize" << endl; + while(!fifoFree[0]->push(wbuffer[0])); +#ifdef FIFO_DEBUG + cprintf(BLUE,"%d writer freed pushed into fifofree %x for listener 0\n",ithread, (void*)(wbuffer[0])); +#endif + } +} From 476d1b452f61a1212c8eaf39d90fd28bd5ab89e1 Mon Sep 17 00:00:00 2001 From: Dhanya Maliakal Date: Fri, 10 Jul 2015 16:04:29 +0200 Subject: [PATCH 02/68] some changes --- .../include/UDPBaseImplementation.h | 3 +- .../include/UDPStandardImplementation.h | 11 +- .../include/sls_receiver_defs.h | 2 +- .../src/UDPBaseImplementation.cpp | 5 +- .../src/UDPStandardImplementation.cpp | 591 +++++++++--------- slsReceiverSoftware/src/slsReceiver.cpp | 2 +- .../src/slsReceiverTCPIPInterface.cpp | 253 ++++---- slsReceiverSoftware/src/slsReceiverUsers.cpp | 2 +- 8 files changed, 444 insertions(+), 425 deletions(-) diff --git a/slsReceiverSoftware/include/UDPBaseImplementation.h b/slsReceiverSoftware/include/UDPBaseImplementation.h index cb5c08195..6a8c53bd3 100644 --- a/slsReceiverSoftware/include/UDPBaseImplementation.h +++ b/slsReceiverSoftware/include/UDPBaseImplementation.h @@ -471,13 +471,12 @@ protected: * data compression for each fifo output * @param ithread listening thread number * @param wbuffer writer buffer - * @param npackets number of packets from the fifo * @param data pointer to the next packet start * @param xmax max pixels in x direction * @param ymax max pixels in y direction * @param nf nf */ - void handleDataCompression(int ithread, char* wbuffer[], int &npackets, char* data, int xmax, int ymax, int &nf); + void handleDataCompression(int ithread, char* wbuffer[], char* data, int xmax, int ymax, int &nf); diff --git a/slsReceiverSoftware/include/UDPStandardImplementation.h b/slsReceiverSoftware/include/UDPStandardImplementation.h index 99c159bcb..4c04265d4 100644 --- a/slsReceiverSoftware/include/UDPStandardImplementation.h +++ b/slsReceiverSoftware/include/UDPStandardImplementation.h @@ -459,9 +459,8 @@ private: /** * When acquisition is over, this is called * @param ithread listening thread number - * @param wbuffer writer buffer */ - void stopWriting(int ithread, char* wbuffer[]); + void stopWriting(int ithread); /** * updates parameters and writes to file when not a dummy frame @@ -469,21 +468,21 @@ private: * Called by startWriting() * @param ithread writing thread number * @param wbuffer writer buffer - * @param npackets number of packets from the fifo + * @param partialframe is 1 if both ports of eiger dont have same frame + * @param smaller is which port is the smaller frame number if only partial frame received */ - int handleWithoutDataCompression(int ithread, char* wbuffer[], int &npackets); + void handleWithoutDataCompression(int ithread, char* wbuffer[], int partialframe = 0, int smaller = 0); /** * data compression for each fifo output * @param ithread writing thread number * @param wbuffer writer buffer - * @param npackets number of packets from the fifo * @param data pointer to the next packet start * @param xmax max pixels in x direction * @param ymax max pixels in y direction * @param nf nf */ - void handleDataCompression(int ithread, char* wbuffer[], int &npackets, char* data, int xmax, int ymax, int &nf); + void handleDataCompression(int ithread, char* wbuffer[], char* data, int xmax, int ymax, int &nf); diff --git a/slsReceiverSoftware/include/sls_receiver_defs.h b/slsReceiverSoftware/include/sls_receiver_defs.h index 025e3b9cf..7ed6e0837 100755 --- a/slsReceiverSoftware/include/sls_receiver_defs.h +++ b/slsReceiverSoftware/include/sls_receiver_defs.h @@ -19,7 +19,7 @@ typedef int int32_t; #define MAX_FRAMES_PER_FILE 20000 #define SHORT_MAX_FRAMES_PER_FILE 100000 #define MOENCH_MAX_FRAMES_PER_FILE 1000 -#define EIGER_MAX_FRAMES_PER_FILE 20000 +#define EIGER_MAX_FRAMES_PER_FILE 20 #define JFCTB_MAX_FRAMES_PER_FILE 100000 diff --git a/slsReceiverSoftware/src/UDPBaseImplementation.cpp b/slsReceiverSoftware/src/UDPBaseImplementation.cpp index 98adfb6e7..b279147ae 100644 --- a/slsReceiverSoftware/src/UDPBaseImplementation.cpp +++ b/slsReceiverSoftware/src/UDPBaseImplementation.cpp @@ -1647,7 +1647,7 @@ int UDPBaseImplementation::startWriting(){ FILE_LOG(logDEBUG) << __AT__ << " sta } //data compression else - handleDataCompression(ithread,wbuf,numpackets,d, xmax, ymax, nf); + handleDataCompression(ithread,wbuf,d, xmax, ymax, nf); @@ -1998,7 +1998,7 @@ void UDPBaseImplementation::writeToFile_withoutCompression(char* buf,int numpack -void UDPBaseImplementation::handleDataCompression(int ithread, char* wbuffer[], int &npackets, char* data, int xmax, int ymax, int &nf){ +void UDPBaseImplementation::handleDataCompression(int ithread, char* wbuffer[], char* data, int xmax, int ymax, int &nf){ FILE_LOG(logDEBUG) << __FILE__ << "::" << __func__ << " starting"; @@ -2009,6 +2009,7 @@ void UDPBaseImplementation::handleDataCompression(int ithread, char* wbuffer[], eventType thisEvent = PEDESTAL; int ndata; char* buff = 0; + int npackets = (uint16_t)(*((uint16_t*)wbuffer[0])); data = wbuffer[0]+ HEADER_SIZE_NUM_TOT_PACKETS; int remainingsize = npackets * onePacketSize; int np; diff --git a/slsReceiverSoftware/src/UDPStandardImplementation.cpp b/slsReceiverSoftware/src/UDPStandardImplementation.cpp index c93b52f9a..cd4963e4b 100644 --- a/slsReceiverSoftware/src/UDPStandardImplementation.cpp +++ b/slsReceiverSoftware/src/UDPStandardImplementation.cpp @@ -1,6 +1,10 @@ /********************************************//** * @file UDPStandardImplementation.cpp * @short does all the functions for a receiver, set/get parameters, start/stop etc. + * update: 08 July 2015 + * startwriting assumes that for eiger numberoflisteningthreads is limited to 2. + * Otherwise logic to compare n number of frame numbers and store previous frames + * is more complicated compared to just 2 threads. ***********************************************/ @@ -850,7 +854,7 @@ void UDPStandardImplementation::setupFifoStructure(){ while(!fifoFree[i]->isEmpty()) fifoFree[i]->pop(buffer[i]); #ifdef FIFO_DEBUG - //cprintf(GREEN,"%d fifostructure popped from fifofree %x\n", i, (void*)(buffer[i])); + cprintf(CYAN,"%d fifostructure popped from fifofree %x\n", i, (void*)(buffer[i])); #endif delete fifoFree[i]; } @@ -872,7 +876,7 @@ void UDPStandardImplementation::setupFifoStructure(){ while (buffer[i]<(mem0[i]+(bufferSize * numJobsPerThread + HEADER_SIZE_NUM_TOT_PACKETS)*(fifosize-1))) { fifoFree[i]->push(buffer[i]); #ifdef FIFO_DEBUG - cprintf(BLUE,"%d fifostructure free pushed into fifofree %x\n", i, (void*)(buffer[i])); + cprintf(CYAN,"%d fifostructure free pushed into fifofree %x\n", i, (void*)(buffer[i])); #endif buffer[i]+=(bufferSize * numJobsPerThread + HEADER_SIZE_NUM_TOT_PACKETS); } @@ -893,7 +897,7 @@ void UDPStandardImplementation::readFrame(char* c,char** raw, uint32_t &fnum, ui if (guiData == NULL){ guiData = latestData; #ifdef VERY_VERY_DEBUG - cprintf(CYAN,"gui data not null anymore\n"); + cprintf(MAGENTA,"gui data not null anymore\n"); #endif } @@ -907,14 +911,14 @@ void UDPStandardImplementation::readFrame(char* c,char** raw, uint32_t &fnum, ui //could not get gui data if(!guiDataReady){ #ifdef VERY_VERY_DEBUG - cprintf(CYAN,"gui data not ready\n"); + cprintf(MAGENTA,"gui data not ready\n"); #endif *raw = NULL; } //data ready, set guidata to receive new data else{ #ifdef VERY_VERY_DEBUG - cprintf(CYAN,"gui data ready\n"); + cprintf(MAGENTA,"gui data ready\n"); #endif *raw = guiData; guiData = NULL; @@ -924,14 +928,14 @@ void UDPStandardImplementation::readFrame(char* c,char** raw, uint32_t &fnum, ui pthread_mutex_unlock(&dataReadyMutex);*/ if((nFrameToGui) && (writerthreads_mask)){ #ifdef VERY_VERY_DEBUG - cprintf(CYAN,"gonna post\n"); + cprintf(MAGENTA,"gonna post\n"); #endif /*if(nFrameToGui){*/ //release after getting data sem_post(&smp); } #ifdef VERY_VERY_DEBUG - cprintf(CYAN,"done post\n"); + cprintf(MAGENTA,"done post\n"); #endif } } @@ -1367,6 +1371,9 @@ int UDPStandardImplementation::createNewFile(){ int gt = getFrameIndex(); if(gt==-1) gt=0; + //just because currframenum will start from 1, while getframeindex will start from 0 + else if(myDetectorType == EIGER) + gt++; //create file name if(frameIndexNeeded==-1) sprintf(savefilename, "%s/%s_%d.raw", filePath,fileName,fileIndex); @@ -1401,6 +1408,8 @@ int UDPStandardImplementation::createNewFile(){ if(!packetsCaught) cout << savefilename << endl; else{ + + cout << savefilename << "\tpacket loss " << setw(4)<pop(buffer[ithread]); #ifdef FIFO_DEBUG - cprintf(GREEN,"%d listener popped from fifofree %x\n", ithread, (void*)(buffer[ithread])); + cprintf(BLUE,"%d listener popped from fifofree %x\n", ithread, (void*)(buffer[ithread])); #endif @@ -1706,14 +1721,17 @@ int UDPStandardImplementation::startListening(){ //normal listening else if(!carryonBufferSize){ - /* if(!ithread){*/ +#ifdef SOCKET_DEBUG + if(!ithread){ +#endif rc = udpSocket[ithread]->ReceiveDataOnly(buffer[ithread] + HEADER_SIZE_NUM_TOT_PACKETS, maxBufferSize); //cout<<"value:"<fnum)< 0) && (!ithread)) startFrameIndices(ithread); -//*/ +*/ //reset packetcount = (packetsPerFrame/numListeningThreads) * numJobsPerThread; carryonBufferSize = 0; - //check if last packet valid and calculate packet count switch(myDetectorType){ @@ -1818,30 +1835,72 @@ int UDPStandardImplementation::startListening(){ & (frameIndexMask)) >> frameIndexOffset) << endl; #endif break; - default: + + case EIGER: + lastpacketoffset = (((numJobsPerThread * packetsPerFrame/numListeningThreads - 1) * onePacketSize) + EIGER_HEADER_LENGTH + HEADER_SIZE_NUM_TOT_PACKETS); +#ifdef VERYDEBUG + cprintf(BLUE,"%d fnum: 0x%x\n", ithread, htonl(*(unsigned int*)((eiger_image_header *)((char*)(buffer[ithread] + HEADER_SIZE_NUM_TOT_PACKETS)))->fnum)); + cprintf(BLUE,"%d 1st pnum: 0x%x\n", ithread, ((*(uint8_t*)(((eiger_packet_header *)((char*)(buffer[ithread] + EIGER_HEADER_LENGTH + HEADER_SIZE_NUM_TOT_PACKETS)))->num4)))); + cprintf(BLUE,"%d last packet offset: %d\n",ithread,lastpacketoffset); + cprintf(BLUE,"%d last pnum: 0x%x\n", ithread,((*(uint8_t*)(((eiger_packet_header *)((char*)(buffer[ithread] + lastpacketoffset)))->num4)))); +/*for 32 bit try to print 64 bit value of packet header to rule out no other byte changes value other than num4 */ +#endif + //if eiger last packet value is NOT as expected according to bit mode + cprintf(BLUE,"%d lastpacket value: %d\n",ithread,((*(uint8_t*)(((eiger_packet_header *)((char*)(buffer[ithread] + lastpacketoffset)))->num4)))); + cprintf(BLUE,"%d lastpacket value -1: %d\n",ithread,((*(uint8_t*)(((eiger_packet_header *)((char*)(buffer[ithread] + lastpacketoffset - onePacketSize)))->num4)))); + + if( ((*(uint8_t*)(((eiger_packet_header *)((char*)(buffer[ithread] + lastpacketoffset)))->num4))) != last_packet_value){ +//#ifdef VERYDEBUG + cprintf(RED,"NOT full frame\n"); +//#endif + lastpacketheader = ((*(uint8_t*)(((eiger_packet_header *)((char*)(buffer[ithread] + lastpacketoffset)))->num4))); + carryonBufferSize += onePacketSize; + cprintf(BLUE,"%d lastpacket value: %d packet count: %d\n",ithread,lastpacketheader,packetcount); + lastpacketoffset -= onePacketSize; + --packetcount; + + cprintf(BLUE,"%d lastpacket value -1: %d\n",ithread,((*(uint8_t*)(((eiger_packet_header *)((char*)(buffer[ithread] + lastpacketoffset - onePacketSize)))->num4)))); + + //while last packet value is greater than current offset packet value (till we reach ff) + while (lastpacketheader > ((*(uint8_t*)(((eiger_packet_header *)((char*)(buffer[ithread] + lastpacketoffset)))->num4))) ){ + lastpacketheader = ((*(uint8_t*)(((eiger_packet_header *)((char*)(buffer[ithread] + lastpacketoffset)))->num4))); + carryonBufferSize += onePacketSize; + cprintf(BLUE,"%d check value: %d lastpacket value: %d packet count: %d\n",ithread,lastpacketheader,packetcount); + lastpacketoffset -= onePacketSize; + --packetcount; + cprintf(BLUE,"%d lastpacket value -1: %d\n",ithread,((*(uint8_t*)(((eiger_packet_header *)((char*)(buffer[ithread] + lastpacketoffset - onePacketSize)))->num4)))); + + } + memcpy(tempchar, buffer[ithread]+(lastpacketoffset+onePacketSize), carryonBufferSize); +//#ifdef VERYDEBUG + cprintf(BLUE,"%d tempchar 1st pnum: 0x%x\n", ithread, ((*(uint8_t*)(((eiger_packet_header *)((char*)(tempchar)))->num4)))); +//#endif + + } + break; + + + default: break; } - // cout<<"*********** "<fnum)<push(buffer[ithread])); #ifdef FIFO_DEBUG //if(!ithread) - cprintf(MAGENTA, "%d listener pushed into fifo %x\n",ithread, (void*)(buffer[ithread])); + cprintf(BLUE, "%d listener pushed into fifo %x\n",ithread, (void*)(buffer[ithread])); #endif } @@ -1877,18 +1936,20 @@ int UDPStandardImplementation::startWriting(){ int ithread = currentWriterThreadIndex; #ifdef VERYVERBOSE - cout << ithread << "In startWriting()" <pop(wbuf[i]); -#ifdef FIFO_DEBUG - cprintf(MAGENTA,"%d writer poped from fifo %x\n", ithread, (void*)(wbuf[i])); -#endif - numpackets = (uint16_t)(*((uint16_t*)wbuf[i])); + //if previous popped out frame was last dummy frame, dont pop out or you're stuck + //also check if there is a previous frame, then also dont pop out or you miss one frame + if(!previousframe[i]){ //#ifdef VERYDEBUG - cout << i << " numpackets:" << dec << numpackets << "for fifo :"<< i << endl; + cprintf(GREEN,"%d writer gonna pop from fifo: %d\n",ithread,i); //#endif + fifo[i]->pop(wbuf[i]); +#ifdef FIFO_DEBUG + cprintf(GREEN,"%d writer poped from fifo %x\n", ithread, (void*)(wbuf[i])); +#endif + numpackets[i] = (uint16_t)(*((uint16_t*)wbuf[i])); +//#ifdef VERYDEBUG + cprintf(GREEN,"%d numpackets: %d for fifo :%d\n", ithread, numpackets[i], i); +//#endif + + + //if last dummy packet, free it + if(numpackets[i] == 0xFFFF){ +//#ifdef VERYDEBUG + cprintf(GREEN, "%d popped last dummy frame:0x%x for listen thread %d\n", ithread, (void*)wbuf[i], i); +//#endif + while(!fifoFree[i]->push(wbuf[i])); +#ifdef FIFO_DEBUG + cprintf(GREEN,"%d writer free dummy pushed into fifofree %x for listener %d\n", ithread,(void*)(wbuf[i]),i); +#endif + + }else allDummyFramesPopped = 0; + } } - //last dummy packet - if(numpackets == 0xFFFF){ + + //if all last dummy frames popped + if(allDummyFramesPopped){ #ifdef VERYDEBUG - cout << "**LAST dummy packet" << endl; + cprintf(GREEN,"%d all dummy frames popped\n", ithread); #endif - stopWriting(ithread,wbuf); + stopWriting(ithread); continue; } #ifdef VERYDEBUG - else cout <<"**NOT a dummy packet"<< dec << numpackets<< endl; + else cprintf(GREEN,"%d NOT all dummy frames popped\n", ,ithread); #endif @@ -1949,14 +2036,42 @@ int UDPStandardImplementation::startWriting(){ //update current frame number for progress if(myDetectorType == EIGER){ - if(dynamicRange != 32) - tempframenum = htonl(*(unsigned int*)((eiger_image_header *)((char*)(wbuf[ithread] + HEADER_SIZE_NUM_TOT_PACKETS)))->fnum); + /* Assuming there are only 2 listening threads of eiger, + * else logic is more complex to find smallest frame number + * and store n number of previous frames for n number of threads */ + + if (numpackets[0] == 0xFFFF) + tempframenum = 0xFFFF; else - tempframenum = htonl(*(unsigned int*)((eiger_image_header *)((char*)(wbuf[ithread] + HEADER_SIZE_NUM_TOT_PACKETS)))->fnum); + tempframenum = htonl(*(unsigned int*)((eiger_image_header *)((char*)(wbuf[0] + HEADER_SIZE_NUM_TOT_PACKETS)))->fnum); + + if (numpackets[1] == 0xFFFF) + tempframenum2 = 0xFFFF; + else + tempframenum2 = htonl(*(unsigned int*)((eiger_image_header *)((char*)(wbuf[1] + HEADER_SIZE_NUM_TOT_PACKETS)))->fnum); - tempframenum += (startFrameIndex-1); //eiger frame numbers start at 1, so need to -1 - //tempframenum = ((tempframenum / EIGER_32BIT_INITIAL_CONSTANT) + startFrameIndex)-1;//eiger 32 bit mode is a multiple of 17c. +startframeindex for scans + //check if one of them is less than the other (both dummies wouldnt reach here) + if(tempframenum!=tempframenum2){ + //frame number of the smaller one + onlyoneport = 1; + smaller = (tempframenum > tempframenum2); + //dummy frame will always be bigger fnum,previousframe = 1 means dont pop out that fifo next time + previousframe[!smaller] = 1; + previousframe[smaller] = 0; + + //update only the smaller number + if (smaller) + tempframenum = tempframenum2; + tempframenum += (startFrameIndex-1); //eiger frame numbers start at 1, so need to -1 + } + //no leftover frames left when you write both + else{ + onlyoneport = 0; + previousframe[0] = 0; + previousframe[1] = 0; + } + }else if ((myDetectorType == GOTTHARD) && (shortFrame == -1)) tempframenum = (((((uint32_t)(*((uint32_t*)(wbuf[ithread] + HEADER_SIZE_NUM_TOT_PACKETS))))+1)& (frameIndexMask)) >> frameIndexOffset); @@ -1972,122 +2087,18 @@ int UDPStandardImplementation::startWriting(){ pthread_mutex_unlock(&progress_mutex); } #ifdef EIGER_DEBUG2 - cout << endl < 0){ - for(j=0;jnum1)) = currframenum; - //overwriting port number and dynamic range - if (!j) (*(uint8_t*)(((eiger_packet_header *)((char*)(wbuf[j] + totalheader + EIGER_ONE_GIGA_ONE_PACKET_SIZE*i)))->num3)) = (dynamicRange<<2); - else (*(uint8_t*)(((eiger_packet_header *)((char*)(wbuf[j] + totalheader + EIGER_ONE_GIGA_ONE_PACKET_SIZE*i)))->num3)) = ((dynamicRange<<2)|(0x1)); - -#ifdef VERYDEBUG - cprintf(RED, "%d - 0x%x - %d\n", i, - (*(uint8_t*)(((eiger_packet_header *)((char*)(wbuf[j] + totalheader +i*EIGER_ONE_GIGA_ONE_PACKET_SIZE)))->num3)), - (*(uint8_t*)(((eiger_packet_header *)((char*)(wbuf[j] + totalheader +i*EIGER_ONE_GIGA_ONE_PACKET_SIZE)))->num4))); -#endif - - } - - //for 32 bit,port number needs to be changed and packet number reconstructed - if(dynamicRange == 32){ - for (i = 0; i < packetsPerFrame/4; i++){ - //new packet number that has space for 16 bit - (*(uint16_t*)(((eiger_packet_header *)((char*)(wbuf[j] + totalheader + EIGER_ONE_GIGA_ONE_PACKET_SIZE*i)))->num2)) - = ((*(uint8_t*)(((eiger_packet_header *)((char*)(wbuf[j] + totalheader + EIGER_ONE_GIGA_ONE_PACKET_SIZE*i)))->num4))); - -#ifdef VERYDEBUG - cprintf(RED, "%d - 0x%x - %d - %d\n", i, - (*(uint8_t*)(((eiger_packet_header *)((char*)(wbuf[j] + totalheader +i*EIGER_ONE_GIGA_ONE_PACKET_SIZE)))->num3)), - (*(uint8_t*)(((eiger_packet_header *)((char*)(wbuf[j] + totalheader +i*EIGER_ONE_GIGA_ONE_PACKET_SIZE)))->num4)), - (*(uint16_t*)(((eiger_packet_header *)((char*)(wbuf[j] + totalheader +i*EIGER_ONE_GIGA_ONE_PACKET_SIZE)))->num2))); -#endif - } - for (i = packetsPerFrame/4; i < packetsPerFrame/2; i++){ - //new packet number that has space for 16 bit - (*(uint16_t*)(((eiger_packet_header *)((char*)(wbuf[j] + totalheader + EIGER_ONE_GIGA_ONE_PACKET_SIZE*i)))->num2)) - = ((*(uint8_t*)(((eiger_packet_header *)((char*)(wbuf[j] + totalheader + EIGER_ONE_GIGA_ONE_PACKET_SIZE*i)))->num4))+(packetsPerFrame/4)); - -#ifdef VERYDEBUG - cprintf(RED, "%d -0x%x - %d - %d\n", i, - (*(uint8_t*)(((eiger_packet_header *)((char*)(wbuf[j] + totalheader +i*EIGER_ONE_GIGA_ONE_PACKET_SIZE)))->num3)), - (*(uint8_t*)(((eiger_packet_header *)((char*)(wbuf[j] + totalheader +i*EIGER_ONE_GIGA_ONE_PACKET_SIZE)))->num4)), - (*(uint16_t*)(((eiger_packet_header *)((char*)(wbuf[j] + totalheader +i*EIGER_ONE_GIGA_ONE_PACKET_SIZE)))->num2))); -#endif - } - } - } -#endif - - writeToFile_withoutCompression(wbuf[j], numpackets,currframenum); - } -#ifdef VERYDEBUG - cprintf(BLUE,"written everyting\n"); -#endif - } - - - if(myDetectorType == EIGER) { -#ifdef VERYDEBUG - cprintf(BLUE,"gonna copy frame\n"); -#endif - copyFrameToGui(wbuf,currframenum); -#ifdef VERYDEBUG - cprintf(BLUE,"copied frame\n"); -#endif - for(i=0;ipush(wbuf[i])); -#ifdef FIFO_DEBUG - cprintf(BLUE,"%d writer freed pushed into fifofree %x for listener %d\n",ithread, (void*)(wbuf[i]),i); -#endif - } - - - } - else{ - //copy to gui - if(numpackets >= packetsPerFrame){//min 1 frame, but neednt be - //if(numpackets == packetsPerFrame * numJobsPerThread){ //only full frames - copyFrameToGui(NULL,-1,wbuf[0]+HEADER_SIZE_NUM_TOT_PACKETS); -#ifdef VERYVERBOSE - cout << ithread << " finished copying" << endl; -#endif - }//else cout << "unfinished buffersize" << endl; - while(!fifoFree[0]->push(wbuf[0])); -#ifdef FIFO_DEBUG - cprintf(BLUE,"%d writer freed pushed into fifofree %x for listener 0\n",ithread, (void*)(wbuf[0])); -#endif - } - } - */ //without datacompression: write datacall back, or write data, free fifo - if(!dataCompression) handleWithoutDataCompression(ithread,wbuf,numpackets); + if(!dataCompression) handleWithoutDataCompression(ithread,wbuf,onlyoneport,smaller); //data compression - else handleDataCompression(ithread,wbuf,numpackets,d, xmax, ymax, nf); - - - + else handleDataCompression(ithread,wbuf,d, xmax, ymax, nf); } #ifdef VERYVERBOSE - cout << ithread << " gonna wait for 1st sem" << endl; + cprintf(GREEN,"%d gonna wait for 1st sem\n", ithread); #endif //wait sem_wait(&writersmp[ithread]); @@ -2097,7 +2108,7 @@ int UDPStandardImplementation::startWriting(){ pthread_exit(NULL); } #ifdef VERYVERBOSE - cout << ithread << " got 1st post" << endl; + cprintf(GREEN,"%d got 1st post\n", ithread); #endif @@ -2124,7 +2135,7 @@ int UDPStandardImplementation::startWriting(){ #ifdef VERYVERBOSE - cout << ithread << " gonna wait for 2nd sem" << endl; + cprintf(GREEN,"%d gonna wait for 2nd sem\n", ithread); #endif //wait sem_wait(&writersmp[ithread]); @@ -2134,7 +2145,7 @@ int UDPStandardImplementation::startWriting(){ pthread_exit(NULL); } #ifdef VERYVERBOSE - cout << ithread << " got 2nd post" << endl; + cprintf(GREEN,"%d got 2nd post\n", ithread); #endif } @@ -2167,7 +2178,7 @@ void UDPStandardImplementation::startFrameIndices(int ithread){ startAcquisitionIndex=startFrameIndex; currframenum = startAcquisitionIndex; acqStarted = true; - cout << "startAcquisitionIndex:" << dec << startAcquisitionIndex<push(buffer[ithread]); #ifdef FIFO_DEBUG cprintf(BLUE,"%d listener not txm free pushed into fifofree %x\n", ithread,(void*)(buffer[ithread])); @@ -2207,7 +2218,7 @@ int i; //free buffer if(rc <= 0){ - cout << ithread << "Discarding empty frame/ End of acquisition" << endl; + cprintf(BLUE,"%d End of acquisition\n", ithread); fifoFree[ithread]->push(buffer[ithread]);/** why not while(!)*/ #ifdef FIFO_DEBUG cprintf(BLUE,"%d listener empty buffer pushed into fifofree %x\n", ithread, (void*)(buffer[ithread])); @@ -2215,17 +2226,20 @@ int i; } //push the last buffer into fifo else{ + + if (rc < (bufferSize * numJobsPerThread)) + cprintf(RED,"%d Pushing Incomplete frame into fifo\n", ithread); //eiger (complete frames) + other detectors pc = (rc/onePacketSize); -#ifdef VERYDEBUG - cout << ithread << " last rc:"<push(buffer[ithread])); #ifdef FIFO_DEBUG - cprintf(RED,"%d listener last buffer pushed into fifo %x\n", ithread,(void*)(buffer[ithread])); + cprintf(BLUE,"%d listener last buffer pushed into fifo %x\n", ithread,(void*)(buffer[ithread])); #endif } @@ -2236,15 +2250,15 @@ int i; for(i=0;ipop(buffer[ithread]); #ifdef FIFO_DEBUG - cprintf(GREEN,"%d listener popped dummy buffer from fifofree %x\n", ithread,(void*)(buffer[ithread])); + cprintf(BLUE,"%d listener popped dummy buffer from fifofree %x\n", ithread,(void*)(buffer[ithread])); #endif (*((uint16_t*)(buffer[ithread]))) = 0xFFFF; #ifdef VERYDEBUG - cout << ithread << " dummy buffer num packets:"<< (*((uint16_t*)(buffer[ithread]))) << endl; + cprintf(BLUE,"%d dummy buffer num packets:%d\n", ithread(*((uint16_t*)(buffer[ithread])))); #endif while(!fifo[ithread]->push(buffer[ithread])); #ifdef FIFO_DEBUG - cprintf(RED,"%d listener pushed dummy buffer into fifo %x\n", ithread,(void*)(buffer[ithread])); + cprintf(BLUE,"%d listener pushed dummy buffer into fifo %x\n", ithread,(void*)(buffer[ithread])); #endif } @@ -2252,19 +2266,19 @@ int i; pthread_mutex_lock(&status_mutex); listeningthreads_mask^=(1< 1) - cout << "Waiting for listening to be done.. current mask:" << hex << listeningthreads_mask << endl; + cprintf(BLUE,"%d Waiting for listening to be done.. current mask:0x%x\n", ithread, listeningthreads_mask); #endif while(listeningthreads_mask) usleep(5000); @@ -2272,7 +2286,7 @@ int i; t = 0; for(i=0;ipush(wbuffer[i])); -#ifdef FIFO_DEBUG - cprintf(BLUE,"%d writer free dummy pushed into fifofree %x for listener %d\n", ithread,(void*)(wbuffer[i]),i); -#endif - } - - - //all threads need to close file, reset mask and exit loop closeFile(ithread); pthread_mutex_lock(&status_mutex); writerthreads_mask^=(1<num1))); - cprintf(RED, "p1:0x%x\n", (*(uint8_t*)(((eiger_packet_header *)((char*)(buf + offset+k*1040)))->num3))); - cprintf(RED, "p0 num:%d - %d\n", k, (*(uint8_t*)(((eiger_packet_header *)((char*)(buf + offset+k*1040)))->num4))); + cprintf(GREEN, "\np1 fnum:0x%x\n", (*(unsigned int*)(((eiger_packet_header *)((char*)(buf + offset+k*1040)))->num1))); + cprintf(GREEN, "p1:0x%x\n", (*(uint8_t*)(((eiger_packet_header *)((char*)(buf + offset+k*1040)))->num3))); + cprintf(GREEN, "p0 num:%d - %d\n", k, (*(uint8_t*)(((eiger_packet_header *)((char*)(buf + offset+k*1040)))->num4))); k = 1; - cprintf(RED, "p2 fnum:0x%x\n", (*(unsigned int*)(((eiger_packet_header *)((char*)(buf + offset +k*1040)))->num1))); - cprintf(RED, "p2:0x%x\n", (*(uint8_t*)(((eiger_packet_header *)((char*)(buf + offset +k*1040)))->num3))); - cprintf(RED, "p1 num:%d - %d\n", k,(*(uint8_t*)(((eiger_packet_header *)((char*)(buf + offset +k*1040)))->num4))); + cprintf(GREEN, "p2 fnum:0x%x\n", (*(unsigned int*)(((eiger_packet_header *)((char*)(buf + offset +k*1040)))->num1))); + cprintf(GREEN, "p2:0x%x\n", (*(uint8_t*)(((eiger_packet_header *)((char*)(buf + offset +k*1040)))->num3))); + cprintf(GREEN, "p1 num:%d - %d\n", k,(*(uint8_t*)(((eiger_packet_header *)((char*)(buf + offset +k*1040)))->num4))); k = 2; - cprintf(RED, "p3 fnum:0x%x\n", (*(unsigned int*)(((eiger_packet_header *)((char*)(buf + offset + k*1040)))->num1))); - cprintf(RED, "p3:0x%x\n", (*(uint8_t*)(((eiger_packet_header *)((char*)(buf + offset +k*1040)))->num3))); - cprintf(RED, "p2 num:%d - %d\n", k,(*(uint8_t*)(((eiger_packet_header *)((char*)(buf + offset +k*1040)))->num4))); + cprintf(GREEN, "p3 fnum:0x%x\n", (*(unsigned int*)(((eiger_packet_header *)((char*)(buf + offset + k*1040)))->num1))); + cprintf(GREEN, "p3:0x%x\n", (*(uint8_t*)(((eiger_packet_header *)((char*)(buf + offset +k*1040)))->num3))); + cprintf(GREEN, "p2 num:%d - %d\n", k,(*(uint8_t*)(((eiger_packet_header *)((char*)(buf + offset +k*1040)))->num4))); }else{ k = 0; - cprintf(RED, "\np1 fnum:0x%x\n", (*(unsigned int*)(((eiger_packet_header *)((char*)(buf + offset+k*1040)))->num1))); - cprintf(RED, "p1:0x%x\n", (*(uint8_t*)(((eiger_packet_header *)((char*)(buf + offset+k*1040)))->num3))); - cprintf(RED, "p0 num:%d - %d\n", k, (*(uint16_t*)(((eiger_packet_header *)((char*)(buf + offset+k*1040)))->num2))); + cprintf(GREEN, "\np1 fnum:0x%x\n", (*(unsigned int*)(((eiger_packet_header *)((char*)(buf + offset+k*1040)))->num1))); + cprintf(GREEN, "p1:0x%x\n", (*(uint8_t*)(((eiger_packet_header *)((char*)(buf + offset+k*1040)))->num3))); + cprintf(GREEN, "p0 num:%d - %d\n", k, (*(uint16_t*)(((eiger_packet_header *)((char*)(buf + offset+k*1040)))->num2))); k = 1; - cprintf(RED, "p2 fnum:0x%x\n", (*(unsigned int*)(((eiger_packet_header *)((char*)(buf + offset +k*1040)))->num1))); - cprintf(RED, "p2:0x%x\n", (*(uint8_t*)(((eiger_packet_header *)((char*)(buf + offset +k*1040)))->num3))); - cprintf(RED, "p1 num:%d - %d\n", k, (*(uint16_t*)(((eiger_packet_header *)((char*)(buf + offset +k*1040)))->num2))); + cprintf(GREEN, "p2 fnum:0x%x\n", (*(unsigned int*)(((eiger_packet_header *)((char*)(buf + offset +k*1040)))->num1))); + cprintf(GREEN, "p2:0x%x\n", (*(uint8_t*)(((eiger_packet_header *)((char*)(buf + offset +k*1040)))->num3))); + cprintf(GREEN, "p1 num:%d - %d\n", k, (*(uint16_t*)(((eiger_packet_header *)((char*)(buf + offset +k*1040)))->num2))); k = 2; - cprintf(RED, "p3 fnum:0x%x\n", (*(unsigned int*)(((eiger_packet_header *)((char*)(buf + offset + k*1040)))->num1))); - cprintf(RED, "p3:0x%x\n", (*(uint8_t*)(((eiger_packet_header *)((char*)(buf + offset +k*1040)))->num3))); - cprintf(RED, "p2 num:%d - %d\n", k, (*(uint16_t*)(((eiger_packet_header *)((char*)(buf + offset +k*1040)))->num2))); + cprintf(GREEN, "p3 fnum:0x%x\n", (*(unsigned int*)(((eiger_packet_header *)((char*)(buf + offset + k*1040)))->num1))); + cprintf(GREEN, "p3:0x%x\n", (*(uint8_t*)(((eiger_packet_header *)((char*)(buf + offset +k*1040)))->num3))); + cprintf(GREEN, "p2 num:%d - %d\n", k, (*(uint16_t*)(((eiger_packet_header *)((char*)(buf + offset +k*1040)))->num2))); k = 256; - cprintf(RED, "p257 fnum:0x%x\n", (*(unsigned int*)(((eiger_packet_header *)((char*)(buf + offset + k*1040)))->num1))); - cprintf(RED, "p257:0x%x\n", (*(uint8_t*)(((eiger_packet_header *)((char*)(buf + offset +k*1040)))->num3))); - cprintf(RED, "p256 num:%d - %d\n", k, (*(uint16_t*)(((eiger_packet_header *)((char*)(buf + offset +k*1040)))->num2))); + cprintf(GREEN, "p257 fnum:0x%x\n", (*(unsigned int*)(((eiger_packet_header *)((char*)(buf + offset + k*1040)))->num1))); + cprintf(GREEN, "p257:0x%x\n", (*(uint8_t*)(((eiger_packet_header *)((char*)(buf + offset +k*1040)))->num3))); + cprintf(GREEN, "p256 num:%d - %d\n", k, (*(uint16_t*)(((eiger_packet_header *)((char*)(buf + offset +k*1040)))->num2))); k = 512; - cprintf(RED, "p513 fnum:0x%x\n", (*(unsigned int*)(((eiger_packet_header *)((char*)(buf + offset + k*1040)))->num1))); - cprintf(RED, "p513:0x%x\n", (*(uint8_t*)(((eiger_packet_header *)((char*)(buf + offset +k*1040)))->num3))); - cprintf(RED, "p512 num:%d - %d\n", k, (*(uint16_t*)(((eiger_packet_header *)((char*)(buf + offset +k*1040)))->num2))); + cprintf(GREEN, "p513 fnum:0x%x\n", (*(unsigned int*)(((eiger_packet_header *)((char*)(buf + offset + k*1040)))->num1))); + cprintf(GREEN, "p513:0x%x\n", (*(uint8_t*)(((eiger_packet_header *)((char*)(buf + offset +k*1040)))->num3))); + cprintf(GREEN, "p512 num:%d - %d\n", k, (*(uint16_t*)(((eiger_packet_header *)((char*)(buf + offset +k*1040)))->num2))); k = 768; - cprintf(RED, "p769 fnum:0x%x\n", (*(unsigned int*)(((eiger_packet_header *)((char*)(buf + offset + k*1040)))->num1))); - cprintf(RED, "p769:0x%x\n", (*(uint8_t*)(((eiger_packet_header *)((char*)(buf + offset +k*1040)))->num3))); - cprintf(RED, "p768 num:%d - %d\n", k,(*(uint16_t*)(((eiger_packet_header *)((char*)(buf + offset +k*1040)))->num2))); + cprintf(GREEN, "p769 fnum:0x%x\n", (*(unsigned int*)(((eiger_packet_header *)((char*)(buf + offset + k*1040)))->num1))); + cprintf(GREEN, "p769:0x%x\n", (*(uint8_t*)(((eiger_packet_header *)((char*)(buf + offset +k*1040)))->num3))); + cprintf(GREEN, "p768 num:%d - %d\n", k,(*(uint16_t*)(((eiger_packet_header *)((char*)(buf + offset +k*1040)))->num2))); } } #endif @@ -2435,9 +2434,9 @@ void UDPStandardImplementation::writeToFile_withoutCompression(char* buf,int num if(tempframenum > currframenum) currframenum = tempframenum; } -#ifdef VERYDEBUG - cout << "tempframenum:" << dec << tempframenum << " curframenum:" << currframenum << endl; -#endif +//#ifdef VERYDEBUG + cprintf(GREEN,"tempframenum: %d curframenum: %d\n",tempframenum,currframenum); +//#endif //lock if(numWriterThreads > 1) @@ -2454,7 +2453,7 @@ void UDPStandardImplementation::writeToFile_withoutCompression(char* buf,int num packetsCaught += packetsToSave; totalPacketsCaught += packetsToSave; #ifdef VERYDEBUG - cout << "/totalPacketsCaught:" << dec << totalPacketsCaught <= maxPacketsPerFile){ @@ -2472,9 +2471,9 @@ void UDPStandardImplementation::writeToFile_withoutCompression(char* buf,int num if(tempframenum > currframenum) currframenum = tempframenum; } -#ifdef VERYDEBUG - cout << "tempframenum:" << dec << tempframenum << " curframenum:" << currframenum << endl; -#endif +//#ifdef VERYDEBUG + cprintf(GREEN,"tempframenum: %d curframenum: %d\n", tempframenum ,currframenum); +//#endif //create createNewFile(); } @@ -2503,87 +2502,102 @@ void UDPStandardImplementation::writeToFile_withoutCompression(char* buf,int num -int UDPStandardImplementation::handleWithoutDataCompression(int ithread, char* wbuffer[], int &npackets){ +void UDPStandardImplementation::handleWithoutDataCompression(int ithread, char* wbuffer[], int partialframe, int smaller){ int totalheader = HEADER_SIZE_NUM_TOT_PACKETS + EIGER_HEADER_LENGTH; - int i,j; + int i,j,npackets; if (cbAction < DO_EVERYTHING){ - for(i=0;i 0){ + else { for(j=0;j 0){ + #ifdef WRITE_HEADERS - if (myDetectorType == EIGER){ + if (myDetectorType == EIGER){ - for (i = 0; i < packetsPerFrame/2; i++){ - //overwriting frame number in header - (*(uint32_t*)(((eiger_packet_header *)((char*)(wbuffer[j] + totalheader + EIGER_ONE_GIGA_ONE_PACKET_SIZE*i)))->num1)) = currframenum; - //overwriting port number and dynamic range - if (!j) (*(uint8_t*)(((eiger_packet_header *)((char*)(wbuffer[j] + totalheader + EIGER_ONE_GIGA_ONE_PACKET_SIZE*i)))->num3)) = (dynamicRange<<2); - else (*(uint8_t*)(((eiger_packet_header *)((char*)(wbuffer[j] + totalheader + EIGER_ONE_GIGA_ONE_PACKET_SIZE*i)))->num3)) = ((dynamicRange<<2)|(0x1)); + for (i = 0; i < packetsPerFrame/2; i++){ + //overwriting frame number in header + (*(uint32_t*)(((eiger_packet_header *)((char*)(wbuffer[j] + totalheader + onePacketSize*i)))->num1)) = currframenum; + //overwriting port number and dynamic range + if (!j) (*(uint8_t*)(((eiger_packet_header *)((char*)(wbuffer[j] + totalheader + onePacketSize*i)))->num3)) = (dynamicRange<<2); + else (*(uint8_t*)(((eiger_packet_header *)((char*)(wbuffer[j] + totalheader + onePacketSize*i)))->num3)) = ((dynamicRange<<2)|(0x1)); #ifdef VERYDEBUG - cprintf(RED, "%d - 0x%x - %d\n", i, - (*(uint8_t*)(((eiger_packet_header *)((char*)(wbuffer[j] + totalheader +i*EIGER_ONE_GIGA_ONE_PACKET_SIZE)))->num3)), - (*(uint8_t*)(((eiger_packet_header *)((char*)(wbuffer[j] + totalheader +i*EIGER_ONE_GIGA_ONE_PACKET_SIZE)))->num4))); + cprintf(GREEN, "%d - 0x%x - %d\n", i, + (*(uint8_t*)(((eiger_packet_header *)((char*)(wbuffer[j] + totalheader +i*onePacketSize)))->num3)), + (*(uint8_t*)(((eiger_packet_header *)((char*)(wbuffer[j] + totalheader +i*onePacketSize)))->num4))); #endif - } - - //for 32 bit,port number needs to be changed and packet number reconstructed - if(dynamicRange == 32){ - for (i = 0; i < packetsPerFrame/4; i++){ - //new packet number that has space for 16 bit - (*(uint16_t*)(((eiger_packet_header *)((char*)(wbuffer[j] + totalheader + EIGER_ONE_GIGA_ONE_PACKET_SIZE*i)))->num2)) - = ((*(uint8_t*)(((eiger_packet_header *)((char*)(wbuffer[j] + totalheader + EIGER_ONE_GIGA_ONE_PACKET_SIZE*i)))->num4))); - -#ifdef VERYDEBUG - cprintf(RED, "%d - 0x%x - %d - %d\n", i, - (*(uint8_t*)(((eiger_packet_header *)((char*)(wbuffer[j] + totalheader +i*EIGER_ONE_GIGA_ONE_PACKET_SIZE)))->num3)), - (*(uint8_t*)(((eiger_packet_header *)((char*)(wbuffer[j] + totalheader +i*EIGER_ONE_GIGA_ONE_PACKET_SIZE)))->num4)), - (*(uint16_t*)(((eiger_packet_header *)((char*)(wbuffer[j] + totalheader +i*EIGER_ONE_GIGA_ONE_PACKET_SIZE)))->num2))); -#endif } - for (i = packetsPerFrame/4; i < packetsPerFrame/2; i++){ - //new packet number that has space for 16 bit - (*(uint16_t*)(((eiger_packet_header *)((char*)(wbuffer[j] + totalheader + EIGER_ONE_GIGA_ONE_PACKET_SIZE*i)))->num2)) - = ((*(uint8_t*)(((eiger_packet_header *)((char*)(wbuffer[j] + totalheader + EIGER_ONE_GIGA_ONE_PACKET_SIZE*i)))->num4))+(packetsPerFrame/4)); + + //for 32 bit,port number needs to be changed and packet number reconstructed + if(dynamicRange == 32){ + for (i = 0; i < packetsPerFrame/4; i++){ + //new packet number that has space for 16 bit + (*(uint16_t*)(((eiger_packet_header *)((char*)(wbuffer[j] + totalheader + onePacketSize*i)))->num2)) + = ((*(uint8_t*)(((eiger_packet_header *)((char*)(wbuffer[j] + totalheader + onePacketSize*i)))->num4))); #ifdef VERYDEBUG - cprintf(RED, "%d -0x%x - %d - %d\n", i, - (*(uint8_t*)(((eiger_packet_header *)((char*)(wbuffer[j] + totalheader +i*EIGER_ONE_GIGA_ONE_PACKET_SIZE)))->num3)), - (*(uint8_t*)(((eiger_packet_header *)((char*)(wbuffer[j] + totalheader +i*EIGER_ONE_GIGA_ONE_PACKET_SIZE)))->num4)), - (*(uint16_t*)(((eiger_packet_header *)((char*)(wbuffer[j] + totalheader +i*EIGER_ONE_GIGA_ONE_PACKET_SIZE)))->num2))); + cprintf(GREEN, "%d - 0x%x - %d - %d\n", i, + (*(uint8_t*)(((eiger_packet_header *)((char*)(wbuffer[j] + totalheader +i*onePacketSize)))->num3)), + (*(uint8_t*)(((eiger_packet_header *)((char*)(wbuffer[j] + totalheader +i*onePacketSize)))->num4)), + (*(uint16_t*)(((eiger_packet_header *)((char*)(wbuffer[j] + totalheader +i*onePacketSize)))->num2))); #endif + } + for (i = packetsPerFrame/4; i < packetsPerFrame/2; i++){ + //new packet number that has space for 16 bit + (*(uint16_t*)(((eiger_packet_header *)((char*)(wbuffer[j] + totalheader + onePacketSize*i)))->num2)) + = ((*(uint8_t*)(((eiger_packet_header *)((char*)(wbuffer[j] + totalheader + onePacketSize*i)))->num4))+(packetsPerFrame/4)); + +#ifdef VERYDEBUG + cprintf(GREEN, "%d -0x%x - %d - %d\n", i, + (*(uint8_t*)(((eiger_packet_header *)((char*)(wbuffer[j] + totalheader +i*onePacketSize)))->num3)), + (*(uint8_t*)(((eiger_packet_header *)((char*)(wbuffer[j] + totalheader +i*onePacketSize)))->num4)), + (*(uint16_t*)(((eiger_packet_header *)((char*)(wbuffer[j] + totalheader +i*onePacketSize)))->num2))); +#endif + } } } +#endif + + writeToFile_withoutCompression(wbuffer[j], npackets,currframenum); } -#endif - - writeToFile_withoutCompression(wbuffer[j], npackets,currframenum); } #ifdef VERYDEBUG - cprintf(BLUE,"written everyting\n"); + cprintf(GREEN,"written everyting\n"); #endif } if(myDetectorType == EIGER) { + if(!partialframe){ #ifdef VERYDEBUG - cprintf(BLUE,"gonna copy frame\n"); -#endif - copyFrameToGui(wbuffer,currframenum); -#ifdef VERYDEBUG - cprintf(BLUE,"copied frame\n"); + cprintf(GREEN,"gonna copy frame\n"); #endif + copyFrameToGui(wbuffer,currframenum); +//#ifdef VERYDEBUG + cprintf(GREEN,"copied frame\n"); +//#endif + } for(i=0;ipush(wbuffer[i])); #ifdef FIFO_DEBUG - cprintf(BLUE,"%d writer freed pushed into fifofree %x for listener %d\n",ithread, (void*)(wbuffer[i]),i); + cprintf(GREEN,"%d writer freed pushed into fifofree %x for listener %d\n",ithread, (void*)(wbuffer[i]),i); #endif } @@ -2600,7 +2614,7 @@ int UDPStandardImplementation::handleWithoutDataCompression(int ithread, char* w }//else cout << "unfinished buffersize" << endl; while(!fifoFree[0]->push(wbuffer[0])); #ifdef FIFO_DEBUG - cprintf(BLUE,"%d writer freed pushed into fifofree %x for listener 0\n",ithread, (void*)(wbuffer[0])); + cprintf(GREEN,"%d writer freed pushed into fifofree %x for listener 0\n",ithread, (void*)(wbuffer[0])); #endif } } @@ -2611,7 +2625,7 @@ int UDPStandardImplementation::handleWithoutDataCompression(int ithread, char* w -void UDPStandardImplementation::handleDataCompression(int ithread, char* wbuffer[], int &npackets, char* data, int xmax, int ymax, int &nf){ +void UDPStandardImplementation::handleDataCompression(int ithread, char* wbuffer[], char* data, int xmax, int ymax, int &nf){ FILE_LOG(logDEBUG) << __AT__ << " called"; #if defined(MYROOT1) && defined(ALLFILE_DEBUG) @@ -2621,6 +2635,7 @@ void UDPStandardImplementation::handleDataCompression(int ithread, char* wbuffer eventType thisEvent = PEDESTAL; int ndata; char* buff = 0; + int npackets = (uint16_t)(*((uint16_t*)wbuffer[0])); data = wbuffer[0]+ HEADER_SIZE_NUM_TOT_PACKETS; int remainingsize = npackets * onePacketSize; int np; @@ -2701,7 +2716,7 @@ void UDPStandardImplementation::handleDataCompression(int ithread, char* wbuffer while(!fifoFree[0]->push(wbuffer[0])); #ifdef FIFO_DEBUG - cprintf(BLUE,"%d writer compression free pushed into fifofree %x for listerner 0\n", ithread, (void*)(wbuffer[0])); + cprintf(GREEN,"%d writer compression free pushed into fifofree %x for listerner 0\n", ithread, (void*)(wbuffer[0])); #endif } diff --git a/slsReceiverSoftware/src/slsReceiver.cpp b/slsReceiverSoftware/src/slsReceiver.cpp index e43820613..5783e601c 100644 --- a/slsReceiverSoftware/src/slsReceiver.cpp +++ b/slsReceiverSoftware/src/slsReceiver.cpp @@ -162,7 +162,7 @@ void slsReceiver::closeFile(int p) { int64_t slsReceiver::getReceiverVersion(){ - tcpipInterface->getReceiverVersion(); + return tcpipInterface->getReceiverVersion(); } diff --git a/slsReceiverSoftware/src/slsReceiverTCPIPInterface.cpp b/slsReceiverSoftware/src/slsReceiverTCPIPInterface.cpp index 2c882b139..bcefc85d8 100644 --- a/slsReceiverSoftware/src/slsReceiverTCPIPInterface.cpp +++ b/slsReceiverSoftware/src/slsReceiverTCPIPInterface.cpp @@ -32,25 +32,25 @@ slsReceiverTCPIPInterface::~slsReceiverTCPIPInterface() { } slsReceiverTCPIPInterface::slsReceiverTCPIPInterface(int &success, UDPInterface* rbase, int pn, bool bot): - myDetectorType(GOTTHARD), - receiverBase(rbase), - ret(OK), - lockStatus(0), - shortFrame(-1), - packetsPerFrame(GOTTHARD_PACKETS_PER_FRAME), - dynamicrange(16), - socket(NULL), - killTCPServerThread(0), - tenGigaEnable(0), portNumber(DEFAULT_PORTNO+2), - bottom(bot){ + myDetectorType(GOTTHARD), + receiverBase(rbase), + ret(OK), + lockStatus(0), + shortFrame(-1), + packetsPerFrame(GOTTHARD_PACKETS_PER_FRAME), + dynamicrange(16), + socket(NULL), + killTCPServerThread(0), + tenGigaEnable(0), portNumber(DEFAULT_PORTNO+2), + bottom(bot){ - int port_no=portNumber; - if(receiverBase == NULL) receiverBase = 0; + int port_no=portNumber; + if(receiverBase == NULL) receiverBase = 0; - if (pn>0) - port_no = pn; + if (pn>0) + port_no = pn; - success=OK; + success=OK; //create socket if(success == OK){ @@ -65,58 +65,60 @@ slsReceiverTCPIPInterface::slsReceiverTCPIPInterface(int &success, UDPInterface* strcpy(socket->lastClientIP,"none"); strcpy(socket->thisClientIP,"none1"); strcpy(mess,"dummy message"); - + function_table(); #ifdef VERBOSE cout << "Function table assigned." << endl; #endif - + //Catch signal SIGINT to close files properly signal(SIGINT,staticCloseFile); } } - + } int slsReceiverTCPIPInterface::setPortNumber(int pn){ int p_number; - MySocketTCP *oldsocket=NULL;; - int sd=0; - if (pn>0) { - p_number = pn; - - if (p_number<1024) { - sprintf(mess,"Too low port number %d\n", p_number); - cout << mess << endl; - } else { - - oldsocket=socket; - socket = new MySocketTCP(p_number); - if(socket){ - sd = socket->getErrorStatus(); - if (!sd){ - portNumber=p_number; - delete oldsocket; - } else { - cout << "Could not bind port " << p_number << endl; - if (sd==-10) { - - cout << "Port "<< p_number << " already set" << endl; - } else { - delete socket; - socket=oldsocket; - } + MySocketTCP *oldsocket=NULL;; + int sd=0; + + if (pn>0) { + p_number = pn; + + if (p_number<1024) { + sprintf(mess,"Too low port number %d\n", p_number); + cout << mess << endl; + } else { + + oldsocket=socket; + socket = new MySocketTCP(p_number); + if(socket){ + sd = socket->getErrorStatus(); + if (!sd){ + portNumber=p_number; + strcpy(socket->lastClientIP,oldsocket->lastClientIP); + delete oldsocket; + } else { + cout << "Could not bind port " << p_number << endl; + if (sd==-10) { + + cout << "Port "<< p_number << " already set" << endl; + } else { + delete socket; + socket=oldsocket; + } + } + + } else { + socket=oldsocket; + } + } } - - } else { - socket=oldsocket; - } - } - } - return portNumber; + return portNumber; } @@ -142,7 +144,7 @@ void slsReceiverTCPIPInterface::stop(){ receiverBase->shutDownUDPSockets(); cout << "Closing Files... " << endl; - receiverBase->closeFile(); + receiverBase->closeFile(); cout<<"Shutting down TCP Socket and TCP thread"<differentClients){ @@ -426,7 +428,7 @@ int slsReceiverTCPIPInterface::set_file_name() { strcpy(mess,"Receiver not set up\n"); ret=FAIL; } - else + else strcpy(retval,receiverBase->setFileName(fName)); } #ifdef VERBOSE @@ -671,44 +673,44 @@ int slsReceiverTCPIPInterface::setup_udp(){ } else{ //set up udp port - sscanf(args[1],"%d",&udpport); - sscanf(args[2],"%d",&udpport2); - receiverBase->setUDPPortNo(udpport); - receiverBase->setUDPPortNo2(udpport2); - //setup udpip - //get ethernet interface or IP to listen to - cout << "Ethernet interface is " << args[0] << endl; - temp = genericSocket::ipToName(args[0]); - cout << temp << endl; - if(temp=="none"){ - ret = FAIL; - strcpy(mess, "failed to get ethernet interface or IP to listen to\n"); - } - else{ - strcpy(eth,temp.c_str()); - if (strchr(eth,'.')!=NULL) { - strcpy(eth,""); - ret = FAIL; - } - FILE_LOG(logDEBUG) << __FILE__ << "::" << __func__ << " " << eth; - receiverBase->setEthernetInterface(eth); + sscanf(args[1],"%d",&udpport); + sscanf(args[2],"%d",&udpport2); + receiverBase->setUDPPortNo(udpport); + receiverBase->setUDPPortNo2(udpport2); + //setup udpip + //get ethernet interface or IP to listen to + cout << "Ethernet interface is " << args[0] << endl; + temp = genericSocket::ipToName(args[0]); + cout << temp << endl; + if(temp=="none"){ + ret = FAIL; + strcpy(mess, "failed to get ethernet interface or IP to listen to\n"); + } + else{ + strcpy(eth,temp.c_str()); + if (strchr(eth,'.')!=NULL) { + strcpy(eth,""); + ret = FAIL; + } + FILE_LOG(logDEBUG) << __FILE__ << "::" << __func__ << " " << eth; + receiverBase->setEthernetInterface(eth); - cout << eth << endl; - //get mac address from ethernet interface - if (ret != FAIL) + cout << eth << endl; + //get mac address from ethernet interface + if (ret != FAIL) temp = genericSocket::nameToMac(eth); - - if ((temp=="00:00:00:00:00:00") || (ret == FAIL)){ - ret = FAIL; - strcpy(mess,"failed to get mac adddress to listen to\n"); - cout << "mess:" << mess << endl; - } - else{ - strcpy(retval,temp.c_str()); - cout<<"mac:"<> GOTTHARD_FRAME_INDEX_OFFSET); #ifdef VERBOSE - cout << "index1:" << hex << index << endl; - cout << "index2:" << hex << index << endl; + cout << "index1:" << hex << index << endl; + cout << "index2:" << hex << index << endl; #endif } @@ -1310,21 +1312,21 @@ int slsReceiverTCPIPInterface::gotthard_read_frame(){ /*//ignore if half frame is missing if ((bindex != 0xFFFFFFFF) && (bindex2 != 0xFFFFFFFF)){*/ - //should be same frame - if (index == index2){ - //ideal situation (should be odd, even(index+1)) - if(!pindex){ - memcpy(retval,((char*) origVal)+4, onedatasize); - memcpy((((char*)retval)+onedatasize), ((char*) origVal)+10+onedatasize, onedatasize); - } - //swap to even,odd - else{ - memcpy((((char*)retval)+onedatasize),((char*) origVal)+4, onedatasize); - memcpy(retval, ((char*) origVal)+10+onedatasize, onedatasize); - index=index2; - } - }else - cout << "different frames caught. frame1:"<< hex << index << ":"<initialize(hostname); + else{ + receiverBase->initialize(hostname); strcpy(retval,receiverBase->getDetectorHostname()); - } + } } #ifdef VERBOSE if(ret!=FAIL) @@ -1998,15 +2000,15 @@ int slsReceiverTCPIPInterface::set_dynamic_range() { } else if ((dr>0) && (myDetectorType == EIGER)){ switch(dr){ - case 4: - case 8: - case 16: - case 32:break; - default: - sprintf(mess,"This dynamic range does not exist for eiger: %d\n",dr); - cprintf(RED,"%s", mess); - ret=FAIL; - break; + case 4: + case 8: + case 16: + case 32:break; + default: + sprintf(mess,"This dynamic range does not exist for eiger: %d\n",dr); + cprintf(RED,"%s", mess); + ret=FAIL; + break; } } if(ret!=FAIL){ @@ -2247,6 +2249,7 @@ int slsReceiverTCPIPInterface::lock_receiver() { int slsReceiverTCPIPInterface::set_port() { ret=OK; MySocketTCP* mySocket=NULL; + char oldLastClientIP[INET_ADDRSTRLEN]; int sd=-1; enum runStatus p_type; /* just to get the input */ int p_number; @@ -2277,12 +2280,14 @@ int slsReceiverTCPIPInterface::set_port() { ret=FAIL; } cout << "set port " << p_type << " to " << p_number <lastClientIP); mySocket = new MySocketTCP(p_number); } if(mySocket){ sd = mySocket->getErrorStatus(); if (!sd){ ret=OK; + strcpy(socket->lastClientIP,oldLastClientIP); if (mySocket->differentClients) ret=FORCE_UPDATE; } else { diff --git a/slsReceiverSoftware/src/slsReceiverUsers.cpp b/slsReceiverSoftware/src/slsReceiverUsers.cpp index 9b1f147da..c27f1efc2 100644 --- a/slsReceiverSoftware/src/slsReceiverUsers.cpp +++ b/slsReceiverSoftware/src/slsReceiverUsers.cpp @@ -25,7 +25,7 @@ void slsReceiverUsers::closeFile(int p) { } int64_t slsReceiverUsers::getReceiverVersion(){ - slsReceiverUsers::receiver->getReceiverVersion(); + return slsReceiverUsers::receiver->getReceiverVersion(); } From ca9f195f0bd0de0d45e021e2d6cd3866efd53a3a Mon Sep 17 00:00:00 2001 From: Dhanya Maliakal Date: Thu, 16 Jul 2015 13:33:34 +0200 Subject: [PATCH 03/68] starting of a new change --- .../include/UDPBaseImplementation.h | 5 +- slsReceiverSoftware/include/genericSocket.h | 27 +- .../src/UDPBaseImplementation.cpp | 4 +- .../src/UDPStandardImplementation.cpp | 233 +++++++++++++----- 4 files changed, 185 insertions(+), 84 deletions(-) diff --git a/slsReceiverSoftware/include/UDPBaseImplementation.h b/slsReceiverSoftware/include/UDPBaseImplementation.h index 6a8c53bd3..3ece433dd 100644 --- a/slsReceiverSoftware/include/UDPBaseImplementation.h +++ b/slsReceiverSoftware/include/UDPBaseImplementation.h @@ -486,7 +486,10 @@ protected: /** structure of an eiger image header*/ typedef struct { - unsigned char header_before[20]; + //unsigned char header_before1[5]; + //unsigned char header_confirm[1]; + //unsigned char header_before2[14]; + unsigned char header_before[20]; unsigned char fnum[4]; unsigned char header_after[24]; } eiger_image_header; diff --git a/slsReceiverSoftware/include/genericSocket.h b/slsReceiverSoftware/include/genericSocket.h index 0ccc80adf..ed5d386a1 100644 --- a/slsReceiverSoftware/include/genericSocket.h +++ b/slsReceiverSoftware/include/genericSocket.h @@ -94,18 +94,11 @@ enum communicationProtocol{ typedef struct { - unsigned char header_before[20]; + unsigned char header_before[20]; unsigned char fnum[4]; unsigned char header_after[24]; } eiger_image_header; -typedef struct -{ - unsigned char header_before[19]; - unsigned char fnum[4]; - unsigned char header_after[25]; -} eiger_image_header32; - genericSocket(const char* const host_ip_or_name, unsigned short int const port_number, communicationProtocol p, int ps = DEFAULT_PACKET_SIZE) : // portno(port_number), protocol(p), @@ -581,24 +574,13 @@ typedef struct case UDP: if (socketDescriptor<0) return -1; -/* - cout <<"******listening inside genericsocket"<0){ nsending = (length>packet_size) ? packet_size:length; - - /* - +/* //created for debugging on 11.05.2015 nsending=5000; nsent = recvfrom(socketDescriptor,(char*)buf,nsending, 0, (struct sockaddr *) &clientAddress, &clientAddress_length); @@ -616,14 +598,9 @@ typedef struct k++; */ - nsent = recvfrom(socketDescriptor,(char*)buf+total_sent,nsending, 0, (struct sockaddr *) &clientAddress, &clientAddress_length); if(!nsent) break; - if(nsent == 16) { - //cout << "."; - continue; - } length-=nsent; total_sent+=nsent; } diff --git a/slsReceiverSoftware/src/UDPBaseImplementation.cpp b/slsReceiverSoftware/src/UDPBaseImplementation.cpp index b279147ae..e1a630103 100644 --- a/slsReceiverSoftware/src/UDPBaseImplementation.cpp +++ b/slsReceiverSoftware/src/UDPBaseImplementation.cpp @@ -624,7 +624,7 @@ void UDPBaseImplementation::setupFifoStructure(){ FILE_LOG(logDEBUG) << __AT__ < mem0[i]=(char*)malloc((bufferSize * numJobsPerThread + HEADER_SIZE_NUM_TOT_PACKETS)*fifosize); /** shud let the client know about this */ if (mem0[i]==NULL){ - cout<<"++++++++++++++++++++++ COULD NOT ALLOCATE MEMORY FOR LISTENING !!!!!!!+++++++++++++++++++++" << endl; + cprintf(BG_RED,"++++++++++++++++++++++ COULD NOT ALLOCATE MEMORY FOR LISTENING !!!!!!!+++++++++++++++++++++\n"); exit(-1); } buffer[i]=mem0[i]; @@ -1754,7 +1754,7 @@ int i; cerr << ithread << " recvfrom() failed:"<push(buffer[ithread]); exit(-1); } diff --git a/slsReceiverSoftware/src/UDPStandardImplementation.cpp b/slsReceiverSoftware/src/UDPStandardImplementation.cpp index cd4963e4b..5b6ca4bdf 100644 --- a/slsReceiverSoftware/src/UDPStandardImplementation.cpp +++ b/slsReceiverSoftware/src/UDPStandardImplementation.cpp @@ -839,14 +839,13 @@ void UDPStandardImplementation::setupFifoStructure(){ else fifosize = fifosize/numJobsPerThread; + //one packet per buffer + if(myDetectorType == EIGER) + fifosize *= (packetsPerFrame/(numListeningThreads)); cout << "Number of Frames per buffer:" << numJobsPerThread << endl; cout << "Fifo Size:" << fifosize << endl; - /* - //for testing - numJobsPerThread = 3; fifosize = 11; - */ for(int i=0;i(fifosize); fifo[i] = new CircularFifo(fifosize); //allocate memory - mem0[i]=(char*)malloc((bufferSize * numJobsPerThread + HEADER_SIZE_NUM_TOT_PACKETS)*fifosize); + //if eiger, allocate only one packet size per buffer + if(myDetectorType == EIGER) + mem0[i]=(char*)malloc((onePacketSize * numJobsPerThread)*fifosize); + else + mem0[i]=(char*)malloc((bufferSize * numJobsPerThread + HEADER_SIZE_NUM_TOT_PACKETS)*fifosize); + /** shud let the client know about this */ if (mem0[i]==NULL){ - cout<<"++++++++++++++++++++++ COULD NOT ALLOCATE MEMORY FOR LISTENING !!!!!!!+++++++++++++++++++++" << endl; + cprintf(BG_RED,"++++++++++++++++++++++ COULD NOT ALLOCATE MEMORY FOR LISTENING !!!!!!!+++++++++++++++++++++\n"); exit(-1); } buffer[i]=mem0[i]; + + //push the addresses into freed fifoFree and writingFifoFree - while (buffer[i]<(mem0[i]+(bufferSize * numJobsPerThread + HEADER_SIZE_NUM_TOT_PACKETS)*(fifosize-1))) { - fifoFree[i]->push(buffer[i]); + if(myDetectorType == EIGER){ + while (buffer[i]<(mem0[i]+(onePacketSize * numJobsPerThread)*(fifosize-1))) { + fifoFree[i]->push(buffer[i]); #ifdef FIFO_DEBUG - cprintf(CYAN,"%d fifostructure free pushed into fifofree %x\n", i, (void*)(buffer[i])); + cprintf(CYAN,"%d fifostructure free pushed into fifofree %x\n", i, (void*)(buffer[i])); #endif - buffer[i]+=(bufferSize * numJobsPerThread + HEADER_SIZE_NUM_TOT_PACKETS); + buffer[i]+=(onePacketSize * numJobsPerThread); + } } + else{ + while (buffer[i]<(mem0[i]+(bufferSize * numJobsPerThread + HEADER_SIZE_NUM_TOT_PACKETS)*(fifosize-1))) { + fifoFree[i]->push(buffer[i]); +#ifdef FIFO_DEBUG + cprintf(CYAN,"%d fifostructure free pushed into fifofree %x\n", i, (void*)(buffer[i])); +#endif + buffer[i]+=(bufferSize * numJobsPerThread + HEADER_SIZE_NUM_TOT_PACKETS); + } + } + } cout << "Fifo structure(s) reconstructed" << endl; } @@ -1674,17 +1693,8 @@ int UDPStandardImplementation::startListening(){ int total; int lastpacketoffset, expected, rc,packetcount, maxBufferSize, carryonBufferSize; - uint32_t lastframeheader, lastpacketheader;// for moench to check for all the packets in last frame + uint32_t lastframeheader = 0, lastpacketheader = -1, tempframenum = 0;// for moench to check for all the packets in last frame char* tempchar = NULL; - int last_packet_value = 0xff; - if(myDetectorType == EIGER){ - switch(dynamicRange){ - case 4: last_packet_value = 0x40; break; - case 8: last_packet_value = 0x80; break; - case 16: last_packet_value = 0xff; break; - default: last_packet_value = 0xff; break; // 32 bit mode currently gives pnum only upto 0xff and then resets - } - } while(1){ @@ -1692,10 +1702,12 @@ int UDPStandardImplementation::startListening(){ carryonBufferSize = 0; //if more than 1 listening thread, listen one packet at a time, else need to interleaved frame later maxBufferSize = bufferSize * numJobsPerThread; + #ifdef VERYDEBUG - cprintf(BLUE, "%d maxBufferSize:%d carryonBufferSize:%d\n", ithread, maxBufferSize,carryonBufferSize); + cprintf(BLUE, "%d listenTo:%d maxBufferSize:%d carryonBufferSize:%d\n", ithread,listenTo,maxBufferSize,carryonBufferSize); #endif + //temporary buffer to copy initial packets for next frames if(tempchar) {delete [] tempchar;tempchar = NULL;} if(myDetectorType != EIGER) tempchar = new char[onePacketSize * ((packetsPerFrame/numListeningThreads) - 1)]; //gotthard: 1packet size, moench:39 packet size @@ -1724,9 +1736,32 @@ int UDPStandardImplementation::startListening(){ #ifdef SOCKET_DEBUG if(!ithread){ #endif - rc = udpSocket[ithread]->ReceiveDataOnly(buffer[ithread] + HEADER_SIZE_NUM_TOT_PACKETS, maxBufferSize); - //cout<<"value:"<fnum)<ReceiveDataOnly(buffer[ithread]); + //headers or crazy byte size + while (rc != onePacketSize){ + //end of acquisition + if((rc == 0) && (status == TRANSMITTING)){ + stopListening(ithread,rc,packetcount,total); + continue; + } + //16 byte or crazy packet size + if(rc != EIGER_HEADER_LENGTH) + rc = udpSocket[ithread]->ReceiveDataOnly(buffer[ithread]); + //header + else{ + tempframenum = htonl(*(unsigned int*)((eiger_image_header *)((char*)(buffer[ithread])))->fnum); + rc = udpSocket[ithread]->ReceiveDataOnly(buffer[ithread]); + } + } + } + //other detectors + else{ + rc = udpSocket[ithread]->ReceiveDataOnly(buffer[ithread] + HEADER_SIZE_NUM_TOT_PACKETS, maxBufferSize); + //cout<<"value:"<fnum)< 0) && (!ithread)) + + if( (!measurementStarted) && (myDetectorType != EIGER) && (rc > 0) && (!ithread)) startFrameIndices(ithread); //problem in receiving or end of acquisition - if((rc < expected)||(rc <= 0)){ + //if(((rc < expected) && (status == TRANSMITTING)) || (rc<0)){ + if((status == TRANSMITTING)&& (myDetectorType != EIGER)) { /*if(myDetectorType != EIGER){ //start indices for each start of scan/acquisition - this should be done earlier for normal detectors if((!measurementStarted) && (rc > 0) && (!ithread)) @@ -1776,8 +1813,10 @@ int UDPStandardImplementation::startListening(){ */ //reset - packetcount = (packetsPerFrame/numListeningThreads) * numJobsPerThread; - carryonBufferSize = 0; + if (myDetectorType != EIGER){ + packetcount = (packetsPerFrame/numListeningThreads) * numJobsPerThread; + carryonBufferSize = 0; + } //check if last packet valid and calculate packet count @@ -1838,46 +1877,126 @@ int UDPStandardImplementation::startListening(){ case EIGER: - lastpacketoffset = (((numJobsPerThread * packetsPerFrame/numListeningThreads - 1) * onePacketSize) + EIGER_HEADER_LENGTH + HEADER_SIZE_NUM_TOT_PACKETS); -#ifdef VERYDEBUG - cprintf(BLUE,"%d fnum: 0x%x\n", ithread, htonl(*(unsigned int*)((eiger_image_header *)((char*)(buffer[ithread] + HEADER_SIZE_NUM_TOT_PACKETS)))->fnum)); - cprintf(BLUE,"%d 1st pnum: 0x%x\n", ithread, ((*(uint8_t*)(((eiger_packet_header *)((char*)(buffer[ithread] + EIGER_HEADER_LENGTH + HEADER_SIZE_NUM_TOT_PACKETS)))->num4)))); - cprintf(BLUE,"%d last packet offset: %d\n",ithread,lastpacketoffset); - cprintf(BLUE,"%d last pnum: 0x%x\n", ithread,((*(uint8_t*)(((eiger_packet_header *)((char*)(buffer[ithread] + lastpacketoffset)))->num4)))); -/*for 32 bit try to print 64 bit value of packet header to rule out no other byte changes value other than num4 */ -#endif - //if eiger last packet value is NOT as expected according to bit mode - cprintf(BLUE,"%d lastpacket value: %d\n",ithread,((*(uint8_t*)(((eiger_packet_header *)((char*)(buffer[ithread] + lastpacketoffset)))->num4)))); - cprintf(BLUE,"%d lastpacket value -1: %d\n",ithread,((*(uint8_t*)(((eiger_packet_header *)((char*)(buffer[ithread] + lastpacketoffset - onePacketSize)))->num4)))); - if( ((*(uint8_t*)(((eiger_packet_header *)((char*)(buffer[ithread] + lastpacketoffset)))->num4))) != last_packet_value){ -//#ifdef VERYDEBUG - cprintf(RED,"NOT full frame\n"); -//#endif + + //push missing packet if any by looking at last packetheader values + + + //packetnumber is smaller = different frame + if(lastpacketheader >= ((*(uint8_t*)(((eiger_packet_header *)((char*)(buffer[ithread])))->num4)))) + tempframenum++; + + + + + //tag framenumber to the packet + (*(uint32_t*)(((eiger_packet_header *)((char*)(buffer[ithread])))->num1)) = tempframenum; + //remember last packet value + lastpacketheader = ((*(uint8_t*)(((eiger_packet_header *)((char*)(buffer[ithread])))->num4))); + + + + + + + + + + //literally end of buffer + lastpacketoffset = rc + HEADER_SIZE_NUM_TOT_PACKETS; + + //extra header + //or less than 1 frame caught(end of acquisition) + if(rc < expected){ + cprintf(RED,"%d rc:%d expectted:%d\n", ithread, rc, expected); + //extra header, looking at last byte of buffer + if ((*((uint8_t*)((char*)buffer[ithread]+lastpacketoffset-1))) == 0x1){ + cprintf(RED,"%d extra header\n", ithread); + //copy extra header + lastpacketoffset-= EIGER_HEADER_LENGTH; + carryonBufferSize += EIGER_HEADER_LENGTH; + memcpy(tempchar, buffer[ithread]+(lastpacketoffset-EIGER_HEADER_LENGTH), EIGER_HEADER_LENGTH); + cprintf(RED,"%d lastpacketoffset:%d\n",ithread, lastpacketoffset); + } + + //less than 1 frame caught + else cprintf(RED,"%d less than 1 frame \n", ithread); + + //find number of packets from last packet number + lastpacketoffset -= onePacketSize; + cprintf(RED,"%d lastpacketoffset:%d\n",ithread, lastpacketoffset); + + for (k=0;k*1040num4)))); + } + + packetcount = ((*(uint8_t*)(((eiger_packet_header *)((char*)(buffer[ithread] + lastpacketoffset)))->num4)))+1; + cprintf(RED,"%d num packets caught:%d\n",ithread, packetcount); + + + + cout <<"EXITING"<< endl; + exit(-1); + + } + //more than 1 frame caught but missed the frame header packet + //or exactly 1 frame caught + else { + //points to last packet + lastpacketoffset = rc + HEADER_SIZE_NUM_TOT_PACKETS - onePacketSize; lastpacketheader = ((*(uint8_t*)(((eiger_packet_header *)((char*)(buffer[ithread] + lastpacketoffset)))->num4))); +#ifdef VERYDEBUG + cprintf(BLUE,"%d fnum: 0x%x\n", ithread, htonl(*(unsigned int*)((eiger_image_header *)((char*)(buffer[ithread] + HEADER_SIZE_NUM_TOT_PACKETS)))->fnum)); + cprintf(BLUE,"%d 1st pnum: 0x%x\n", ithread, ((*(uint8_t*)(((eiger_packet_header *)((char*)(buffer[ithread] + EIGER_HEADER_LENGTH + HEADER_SIZE_NUM_TOT_PACKETS)))->num4)))); + cprintf(BLUE,"%d last packet offset: %d\n",ithread,lastpacketoffset); + cprintf(BLUE,"%d last pnum: 0x%x\n", ithread,((*(uint8_t*)(((eiger_packet_header *)((char*)(buffer[ithread] + lastpacketoffset)))->num4)))); + //for 32 bit try to print 64 bit value of packet header to rule out no other byte changes value other than num4 +#endif + + //proper 1 frame + if((rc == expected) && (lastpacketheader == last_packet_value)){ + break; + } + + //incomplete frame, more than 1 frame caught, but missed header packet + cprintf(RED,"%d INCOMPLETE frame, rc:%d, expected:%d\n", ithread, rc, expected); + cprintf(RED,"%d fnum: 0x%x\n", ithread, htonl(*(unsigned int*)((eiger_image_header *)((char*)(buffer[ithread] + HEADER_SIZE_NUM_TOT_PACKETS)))->fnum)); + + //if eiger last packet value is NOT as expected according to bit mode carryonBufferSize += onePacketSize; - cprintf(BLUE,"%d lastpacket value: %d packet count: %d\n",ithread,lastpacketheader,packetcount); lastpacketoffset -= onePacketSize; --packetcount; - cprintf(BLUE,"%d lastpacket value -1: %d\n",ithread,((*(uint8_t*)(((eiger_packet_header *)((char*)(buffer[ithread] + lastpacketoffset - onePacketSize)))->num4)))); + cprintf(RED,"%d lastpacketheader:%d last packet value:%d packetcount: %d\n",ithread,lastpacketheader,((*(uint8_t*)(((eiger_packet_header *)((char*)(buffer[ithread] + lastpacketoffset)))->num4))), packetcount); //while last packet value is greater than current offset packet value (till we reach ff) while (lastpacketheader > ((*(uint8_t*)(((eiger_packet_header *)((char*)(buffer[ithread] + lastpacketoffset)))->num4))) ){ + lastpacketheader = ((*(uint8_t*)(((eiger_packet_header *)((char*)(buffer[ithread] + lastpacketoffset)))->num4))); carryonBufferSize += onePacketSize; - cprintf(BLUE,"%d check value: %d lastpacket value: %d packet count: %d\n",ithread,lastpacketheader,packetcount); lastpacketoffset -= onePacketSize; --packetcount; - cprintf(BLUE,"%d lastpacket value -1: %d\n",ithread,((*(uint8_t*)(((eiger_packet_header *)((char*)(buffer[ithread] + lastpacketoffset - onePacketSize)))->num4)))); + + cprintf(RED,"%d lastpacketheader:%d last packet value:%d packetcount: %d\n",ithread,lastpacketheader,((*(uint8_t*)(((eiger_packet_header *)((char*)(buffer[ithread] + lastpacketoffset)))->num4))), packetcount); } - memcpy(tempchar, buffer[ithread]+(lastpacketoffset+onePacketSize), carryonBufferSize); -//#ifdef VERYDEBUG - cprintf(BLUE,"%d tempchar 1st pnum: 0x%x\n", ithread, ((*(uint8_t*)(((eiger_packet_header *)((char*)(tempchar)))->num4)))); -//#endif + + cprintf(RED,"%d to copy: %d\n", ithread, carryonBufferSize); + cprintf(RED,"%d lastpacketheader:%d last packet value:%d packetcount: %d\n",ithread,lastpacketheader,((*(uint8_t*)(((eiger_packet_header *)((char*)(buffer[ithread] + lastpacketoffset+onePacketSize)))->num4))), packetcount); + + memcpy(tempchar , buffer[ithread]+(HEADER_SIZE_NUM_TOT_PACKETS), EIGER_HEADER_LENGTH); + memcpy((char*)(tempchar + EIGER_HEADER_LENGTH), buffer[ithread]+(lastpacketoffset+onePacketSize), carryonBufferSize); + (*(unsigned int*)((eiger_image_header *)((char*)(buffer[ithread] + HEADER_SIZE_NUM_TOT_PACKETS)))->fnum) = htonl(lastframeheader+1); + cprintf(RED,"%d copied\n", ithread); + //#ifdef VERYDEBUG + cprintf(RED,"%d tempchar 1st pnum: 0x%x\n", ithread, ((*(uint8_t*)(((eiger_packet_header *)((char*)(tempchar+EIGER_HEADER_LENGTH)))->num4)))); + //#endif + } + //when we lose frame header packet + lastframeheader = htonl(*(unsigned int*)((eiger_image_header *)((char*)(buffer[ithread] + HEADER_SIZE_NUM_TOT_PACKETS)))->fnum); + cprintf(RED,"%d lastframeheader : %d\n", ithread, lastframeheader); break; @@ -2208,7 +2327,7 @@ int i; cprintf(BLUE, "%d recvfrom() failed\n", ithread); #endif if(status != TRANSMITTING){ - cprintf(BLUE,"%d *** should never be here********* status not transmitting***********************\n", ithread);/**/ + cprintf(BG_RED,"%d *** should never be here********* status not transmitting***********************\n", ithread);/**/ fifoFree[ithread]->push(buffer[ithread]); #ifdef FIFO_DEBUG cprintf(BLUE,"%d listener not txm free pushed into fifofree %x\n", ithread,(void*)(buffer[ithread])); @@ -2257,9 +2376,9 @@ int i; cprintf(BLUE,"%d dummy buffer num packets:%d\n", ithread(*((uint16_t*)(buffer[ithread])))); #endif while(!fifo[ithread]->push(buffer[ithread])); -#ifdef FIFO_DEBUG +//#ifdef FIFO_DEBUG cprintf(BLUE,"%d listener pushed dummy buffer into fifo %x\n", ithread,(void*)(buffer[ithread])); -#endif +//#endif } //reset mask and exit loop @@ -2504,7 +2623,7 @@ void UDPStandardImplementation::writeToFile_withoutCompression(char* buf,int num void UDPStandardImplementation::handleWithoutDataCompression(int ithread, char* wbuffer[], int partialframe, int smaller){ int totalheader = HEADER_SIZE_NUM_TOT_PACKETS + EIGER_HEADER_LENGTH; - int i,j,npackets; + int i,j,npackets, ntotpackets=0; if (cbAction < DO_EVERYTHING){ @@ -2513,6 +2632,7 @@ void UDPStandardImplementation::handleWithoutDataCompression(int ithread, char* if(partialframe && (i!=smaller) ) continue; //for eiger 32 bit mode, currframenum like gotthard, does not start from 0 or 1 npackets = (uint16_t)(*((uint16_t*)wbuffer[i])); + ntotpackets += npackets; rawDataReadyCallBack(currframenum, wbuffer[i], npackets * onePacketSize, sfilefd, guiData,pRawDataReady); } } @@ -2523,6 +2643,7 @@ void UDPStandardImplementation::handleWithoutDataCompression(int ithread, char* if(partialframe && (j!=smaller) ) continue; npackets = (uint16_t)(*((uint16_t*)wbuffer[j])); + ntotpackets += npackets; if (npackets > 0){ #ifdef WRITE_HEADERS @@ -2583,7 +2704,7 @@ void UDPStandardImplementation::handleWithoutDataCompression(int ithread, char* if(myDetectorType == EIGER) { - if(!partialframe){ + if(ntotpackets >= packetsPerFrame ) { #ifdef VERYDEBUG cprintf(GREEN,"gonna copy frame\n"); #endif From 26a42d8f67d5714b74689a1c0d3e06c8d64e2691 Mon Sep 17 00:00:00 2001 From: Dhanya Maliakal Date: Fri, 17 Jul 2015 13:29:23 +0200 Subject: [PATCH 04/68] new way --- .../include/UDPBaseImplementation.h | 3 + .../src/UDPStandardImplementation.cpp | 136 ++++++++++++------ 2 files changed, 98 insertions(+), 41 deletions(-) diff --git a/slsReceiverSoftware/include/UDPBaseImplementation.h b/slsReceiverSoftware/include/UDPBaseImplementation.h index 3ece433dd..9daf2ab79 100644 --- a/slsReceiverSoftware/include/UDPBaseImplementation.h +++ b/slsReceiverSoftware/include/UDPBaseImplementation.h @@ -659,6 +659,9 @@ protected: /** Receiver buffer */ char *buffer[MAX_NUM_LISTENING_THREADS]; + /** Missing Packet */ + char *missingPacket; + /** number of writer threads */ int numListeningThreads; diff --git a/slsReceiverSoftware/src/UDPStandardImplementation.cpp b/slsReceiverSoftware/src/UDPStandardImplementation.cpp index 5b6ca4bdf..004ba1fb1 100644 --- a/slsReceiverSoftware/src/UDPStandardImplementation.cpp +++ b/slsReceiverSoftware/src/UDPStandardImplementation.cpp @@ -54,6 +54,7 @@ UDPStandardImplementation::UDPStandardImplementation() udpSocket[i] = NULL; server_port[i] = DEFAULT_UDP_PORTNO+i; mem0[i] = NULL; + missingPacket[i] = NULL; fifo[i] = NULL; fifoFree[i] = NULL; } @@ -163,6 +164,7 @@ void UDPStandardImplementation::initializeMembers(){ for(int i=0;inum4))); + numberofmissingpackets = 0; - //push missing packet if any by looking at last packetheader values - - - //packetnumber is smaller = different frame - if(lastpacketheader >= ((*(uint8_t*)(((eiger_packet_header *)((char*)(buffer[ithread])))->num4)))) + //update tempframenumber if header packet missed out, ie. if packetnumber is smaller = different frame + if(lastpacketheader >= currentpacketheader){ tempframenum++; + //add missing packets for previous frame + numberofmissingpackets += (LAST_PACKET_VALUE - lastpacketheader); + //add for missing frames + numberofmissingpackets += ((tempframenum-lastframeheader -1) * (packetsPerFrame/numListeningThreads)); + //add missing packets for current frame + numberofmissingpackets += (currentpacketheader); + } - //tag framenumber to the packet - (*(uint32_t*)(((eiger_packet_header *)((char*)(buffer[ithread])))->num1)) = tempframenum; //remember last packet value lastpacketheader = ((*(uint8_t*)(((eiger_packet_header *)((char*)(buffer[ithread])))->num4))); + lastframeheader = tempframenum; + + //temporarily store current buffer if there are missing packets + if(numberofmissingpackets) + tempchar = buffer[ithread]; + + for(i=0;inum1)) = tempframenum; +#ifdef VERYDEBUG + cprintf(BLUE,"%d listener going to push fifo: 0x%x\n", ithread,(void*)(buffer[ithread])); +#endif + while(!fifo[ithread]->push(buffer[ithread])); +#ifdef FIFO_DEBUG + //if(!ithread) + cprintf(BLUE, "%d listener pushed into fifo %x\n",ithread, (void*)(buffer[ithread])); +#endif +#ifdef VERYDEBUG + cprintf(BLUE, "%d waiting to pop out of listeningfifo\n",ithread); +#endif + //pop + fifoFree[ithread]->pop(buffer[ithread]); +#ifdef FIFO_DEBUG + cprintf(BLUE,"%d listener popped from fifofree %x\n", ithread, (void*)(buffer[ithread])); +#endif + } + + buffer[ithread] = tempchar; + //tag framenumber to the packet + (*(uint32_t*)(((eiger_packet_header *)((char*)(buffer[ithread])))->num1)) = tempframenum; + packetcount = 1; - - - - +/* //literally end of buffer lastpacketoffset = rc + HEADER_SIZE_NUM_TOT_PACKETS; @@ -1997,6 +2068,8 @@ int UDPStandardImplementation::startListening(){ //when we lose frame header packet lastframeheader = htonl(*(unsigned int*)((eiger_image_header *)((char*)(buffer[ithread] + HEADER_SIZE_NUM_TOT_PACKETS)))->fnum); cprintf(RED,"%d lastframeheader : %d\n", ithread, lastframeheader); + + */ break; @@ -2007,11 +2080,14 @@ int UDPStandardImplementation::startListening(){ + + //#ifdef VERYDEBUG cprintf(BLUE, "%d packetcount:%d carryonbuffer:%d\n", ithread, packetcount, carryonBufferSize); //#endif //write packet count and push - (*((uint16_t*)(buffer[ithread]))) = packetcount; + if(myDetectorType != EIGER) + (*((uint16_t*)(buffer[ithread]))) = packetcount; totalListeningFrameCount[ithread] += packetcount; #ifdef VERYDEBUG cprintf(BLUE,"%d listener going to push fifo: 0x%x\n", ithread,(void*)(buffer[ithread])); @@ -2067,8 +2143,7 @@ int UDPStandardImplementation::startWriting(){ int xmax=0,ymax=0; int ret,i; int packetsPerThread = packetsPerFrame/numListeningThreads; - int allDummyFramesPopped; - int smaller, onlyoneport=0; + while(1){ @@ -2099,16 +2174,10 @@ int UDPStandardImplementation::startWriting(){ while((1<push(wbuf[i])); -#ifdef FIFO_DEBUG - cprintf(GREEN,"%d writer free dummy pushed into fifofree %x for listener %d\n", ithread,(void*)(wbuf[i]),i); -#endif - - }else allDummyFramesPopped = 0; - } } - //if all last dummy frames popped - if(allDummyFramesPopped){ + if(numpackets[i] == 0xFFFF){ #ifdef VERYDEBUG cprintf(GREEN,"%d all dummy frames popped\n", ithread); #endif From 878c12d43ed874a217f448a64fc342f05d6bab27 Mon Sep 17 00:00:00 2001 From: Dhanya Maliakal Date: Tue, 21 Jul 2015 13:36:14 +0200 Subject: [PATCH 05/68] still long way to go --- .../include/UDPBaseImplementation.h | 11 +- .../include/UDPStandardImplementation.h | 4 +- slsReceiverSoftware/include/receiver_defs.h | 2 +- .../src/UDPStandardImplementation.cpp | 1008 ++++++++--------- 4 files changed, 503 insertions(+), 522 deletions(-) diff --git a/slsReceiverSoftware/include/UDPBaseImplementation.h b/slsReceiverSoftware/include/UDPBaseImplementation.h index 9daf2ab79..8db022a69 100644 --- a/slsReceiverSoftware/include/UDPBaseImplementation.h +++ b/slsReceiverSoftware/include/UDPBaseImplementation.h @@ -486,10 +486,10 @@ protected: /** structure of an eiger image header*/ typedef struct { - //unsigned char header_before1[5]; - //unsigned char header_confirm[1]; - //unsigned char header_before2[14]; - unsigned char header_before[20]; + unsigned char header_before1[5]; + unsigned char header_confirm[1]; + unsigned char header_before2[14]; + //unsigned char header_before[20]; unsigned char fnum[4]; unsigned char header_after[24]; } eiger_image_header; @@ -659,9 +659,6 @@ protected: /** Receiver buffer */ char *buffer[MAX_NUM_LISTENING_THREADS]; - /** Missing Packet */ - char *missingPacket; - /** number of writer threads */ int numListeningThreads; diff --git a/slsReceiverSoftware/include/UDPStandardImplementation.h b/slsReceiverSoftware/include/UDPStandardImplementation.h index 4c04265d4..42650e9bb 100644 --- a/slsReceiverSoftware/include/UDPStandardImplementation.h +++ b/slsReceiverSoftware/include/UDPStandardImplementation.h @@ -468,10 +468,8 @@ private: * Called by startWriting() * @param ithread writing thread number * @param wbuffer writer buffer - * @param partialframe is 1 if both ports of eiger dont have same frame - * @param smaller is which port is the smaller frame number if only partial frame received */ - void handleWithoutDataCompression(int ithread, char* wbuffer[], int partialframe = 0, int smaller = 0); + void handleWithoutDataCompression(int ithread, char* wbuffer[]); /** * data compression for each fifo output diff --git a/slsReceiverSoftware/include/receiver_defs.h b/slsReceiverSoftware/include/receiver_defs.h index 6f3b1acd3..6a28654b3 100755 --- a/slsReceiverSoftware/include/receiver_defs.h +++ b/slsReceiverSoftware/include/receiver_defs.h @@ -14,7 +14,7 @@ #define BUF_SIZE (16*1024*1024) //16mb #define SAMPLE_TIME_IN_NS 100000000//100ms #define MAX_JOBS_PER_THREAD 1000 -#define HEADER_SIZE_NUM_TOT_PACKETS 2 +#define HEADER_SIZE_NUM_TOT_PACKETS 4 #define HEADER_SIZE_NUM_FRAMES 2 #define HEADER_SIZE_NUM_PACKETS 1 diff --git a/slsReceiverSoftware/src/UDPStandardImplementation.cpp b/slsReceiverSoftware/src/UDPStandardImplementation.cpp index 004ba1fb1..84d1adcbc 100644 --- a/slsReceiverSoftware/src/UDPStandardImplementation.cpp +++ b/slsReceiverSoftware/src/UDPStandardImplementation.cpp @@ -1,10 +1,6 @@ /********************************************//** * @file UDPStandardImplementation.cpp * @short does all the functions for a receiver, set/get parameters, start/stop etc. - * update: 08 July 2015 - * startwriting assumes that for eiger numberoflisteningthreads is limited to 2. - * Otherwise logic to compare n number of frame numbers and store previous frames - * is more complicated compared to just 2 threads. ***********************************************/ @@ -54,7 +50,6 @@ UDPStandardImplementation::UDPStandardImplementation() udpSocket[i] = NULL; server_port[i] = DEFAULT_UDP_PORTNO+i; mem0[i] = NULL; - missingPacket[i] = NULL; fifo[i] = NULL; fifoFree[i] = NULL; } @@ -164,7 +159,6 @@ void UDPStandardImplementation::initializeMembers(){ for(int i=0;iisEmpty()) fifoFree[i]->pop(buffer[i]); #ifdef FIFO_DEBUG - cprintf(CYAN,"%d fifostructure popped from fifofree %x\n", i, (void*)(buffer[i])); + //cprintf(GREEN,"%d fifostructure popped from fifofree %x\n", i, (void*)(buffer[i])); #endif delete fifoFree[i]; } if(fifo[i]) delete fifo[i]; if(mem0[i]) free(mem0[i]); - fifoFree[i] = new CircularFifo(fifosize); fifo[i] = new CircularFifo(fifosize); //allocate memory - //if eiger, allocate only one packet size per buffer - if(myDetectorType == EIGER) - mem0[i]=(char*)malloc((onePacketSize * numJobsPerThread)*fifosize); - else - mem0[i]=(char*)malloc((bufferSize * numJobsPerThread + HEADER_SIZE_NUM_TOT_PACKETS)*fifosize); - + mem0[i]=(char*)malloc((bufferSize * numJobsPerThread + HEADER_SIZE_NUM_TOT_PACKETS)*fifosize); /** shud let the client know about this */ if (mem0[i]==NULL){ - cprintf(BG_RED,"++++++++++++++++++++++ COULD NOT ALLOCATE MEMORY FOR LISTENING !!!!!!!+++++++++++++++++++++\n"); + cout<<"++++++++++++++++++++++ COULD NOT ALLOCATE MEMORY FOR LISTENING !!!!!!!+++++++++++++++++++++" << endl; exit(-1); } buffer[i]=mem0[i]; - - //push the addresses into freed fifoFree and writingFifoFree - if(myDetectorType == EIGER){ - while (buffer[i]<(mem0[i]+(onePacketSize * numJobsPerThread)*(fifosize-1))) { - fifoFree[i]->push(buffer[i]); + while (buffer[i]<(mem0[i]+(bufferSize * numJobsPerThread + HEADER_SIZE_NUM_TOT_PACKETS)*(fifosize-1))) { + fifoFree[i]->push(buffer[i]); #ifdef FIFO_DEBUG - cprintf(CYAN,"%d fifostructure free pushed into fifofree %x\n", i, (void*)(buffer[i])); + cprintf(BLUE,"%d fifostructure free pushed into fifofree %x\n", i, (void*)(buffer[i])); #endif - buffer[i]+=(onePacketSize * numJobsPerThread); - } + buffer[i]+=(bufferSize * numJobsPerThread + HEADER_SIZE_NUM_TOT_PACKETS); } - else{ - while (buffer[i]<(mem0[i]+(bufferSize * numJobsPerThread + HEADER_SIZE_NUM_TOT_PACKETS)*(fifosize-1))) { - fifoFree[i]->push(buffer[i]); -#ifdef FIFO_DEBUG - cprintf(CYAN,"%d fifostructure free pushed into fifofree %x\n", i, (void*)(buffer[i])); -#endif - buffer[i]+=(bufferSize * numJobsPerThread + HEADER_SIZE_NUM_TOT_PACKETS); - } - } - } cout << "Fifo structure(s) reconstructed" << endl; - - - //missing packet - if(myDetectorType == EIGER){ - - if (missingPacket) - free(missingPacket); - - missingPacket=(char*)malloc(onePacketSize); - if (missingPacket==NULL){ - cprintf(BG_RED,"++++++++++++++++++++++ COULD NOT ALLOCATE MEMORY FOR missing packet !!!!!!!+++++++++++++++++++++\n"); - exit(-1); - } - //fill missing packet - else{ - - for(int j = 0; j < onePacketSize/4; j++) - (*((uint32_t*)(missingPacket + j))) = 0xffffffff; - - //to check - for(int j = 0; j < onePacketSize/4; j++) - cout << i << ":"<< (*((uint32_t*)(missingPacket + j))) << endl; - } - } } @@ -945,7 +893,7 @@ void UDPStandardImplementation::readFrame(char* c,char** raw, uint32_t &fnum, ui if (guiData == NULL){ guiData = latestData; #ifdef VERY_VERY_DEBUG - cprintf(MAGENTA,"gui data not null anymore\n"); + cprintf(CYAN,"gui data not null anymore\n"); #endif } @@ -959,14 +907,14 @@ void UDPStandardImplementation::readFrame(char* c,char** raw, uint32_t &fnum, ui //could not get gui data if(!guiDataReady){ #ifdef VERY_VERY_DEBUG - cprintf(MAGENTA,"gui data not ready\n"); + cprintf(CYAN,"gui data not ready\n"); #endif *raw = NULL; } //data ready, set guidata to receive new data else{ #ifdef VERY_VERY_DEBUG - cprintf(MAGENTA,"gui data ready\n"); + cprintf(CYAN,"gui data ready\n"); #endif *raw = guiData; guiData = NULL; @@ -976,14 +924,14 @@ void UDPStandardImplementation::readFrame(char* c,char** raw, uint32_t &fnum, ui pthread_mutex_unlock(&dataReadyMutex);*/ if((nFrameToGui) && (writerthreads_mask)){ #ifdef VERY_VERY_DEBUG - cprintf(MAGENTA,"gonna post\n"); + cprintf(CYAN,"gonna post\n"); #endif /*if(nFrameToGui){*/ //release after getting data sem_post(&smp); } #ifdef VERY_VERY_DEBUG - cprintf(MAGENTA,"done post\n"); + cprintf(CYAN,"done post\n"); #endif } } @@ -1419,9 +1367,6 @@ int UDPStandardImplementation::createNewFile(){ int gt = getFrameIndex(); if(gt==-1) gt=0; - //just because currframenum will start from 1, while getframeindex will start from 0 - else if(myDetectorType == EIGER) - gt++; //create file name if(frameIndexNeeded==-1) sprintf(savefilename, "%s/%s_%d.raw", filePath,fileName,fileIndex); @@ -1456,8 +1401,6 @@ int UDPStandardImplementation::createNewFile(){ if(!packetsCaught) cout << savefilename << endl; else{ - - cout << savefilename << "\tpacket loss " << setw(4)<pop(buffer[ithread]); #ifdef FIFO_DEBUG cprintf(BLUE,"%d listener popped from fifofree %x\n", ithread, (void*)(buffer[ithread])); #endif - //receive + + //ensure udpsocket exists if(udpSocket[ithread] == NULL){ rc = 0; - cout << ithread << "UDP Socket is NULL" << endl; + cprintf(BLUE, "%d UDP Socket is NULL\n",ithread); } + + //normal listening else if(!carryonBufferSize){ - #ifdef SOCKET_DEBUG - if(!ithread){ + if(!ithread){ #endif - if(myDetectorType == EIGER){ - //listen to only 1 packet at a time - rc = udpSocket[ithread]->ReceiveDataOnly(buffer[ithread]); - //headers or crazy byte size - while (rc != onePacketSize){ - //end of acquisition - if((rc == 0) && (status == TRANSMITTING)){ - stopListening(ithread,rc,packetcount,total); - continue; - } - //16 byte or crazy packet size - if(rc != EIGER_HEADER_LENGTH) - rc = udpSocket[ithread]->ReceiveDataOnly(buffer[ithread]); - //header - else{ - tempframenum = htonl(*(unsigned int*)((eiger_image_header *)((char*)(buffer[ithread])))->fnum); - rc = udpSocket[ithread]->ReceiveDataOnly(buffer[ithread]); - } - } - } - //other detectors - else{ rc = udpSocket[ithread]->ReceiveDataOnly(buffer[ithread] + HEADER_SIZE_NUM_TOT_PACKETS, maxBufferSize); - //cout<<"value:"<fnum)<> frameIndexOffset)<> frameIndexOffset)); + cprintf(BLUE, "%d tempchar packet:%d\n", ((((uint32_t)(*((uint32_t*)(tempchar))))) + & (packetIndexMask))); #endif - //if there is a packet from previous buffer, copy it and listen to n less frame memcpy(buffer[ithread] + HEADER_SIZE_NUM_TOT_PACKETS, tempchar, carryonBufferSize); rc = udpSocket[ithread]->ReceiveDataOnly((buffer[ithread] + HEADER_SIZE_NUM_TOT_PACKETS + carryonBufferSize),maxBufferSize - carryonBufferSize); expected = maxBufferSize - carryonBufferSize; } + #ifdef EIGER_DEBUG cprintf(BLUE, "%d rc: %d. expected: %d\n", ithread, rc, expected); #endif - //start indices for each start of scan/acquisition - eiger does it before - - if( (!measurementStarted) && (myDetectorType != EIGER) && (rc > 0) && (!ithread)) - startFrameIndices(ithread); + //start indices for each start of scan/acquisition + if((!measurementStarted) && (rc > 0)){ + pthread_mutex_lock(&progress_mutex); + startFrameIndices(ithread); + pthread_mutex_unlock(&progress_mutex); + } //problem in receiving or end of acquisition - //if(((rc < expected) && (status == TRANSMITTING)) || (rc<0)){ - if((status == TRANSMITTING)&& (myDetectorType != EIGER)) { - /*if(myDetectorType != EIGER){ - //start indices for each start of scan/acquisition - this should be done earlier for normal detectors - if((!measurementStarted) && (rc > 0) && (!ithread)) - startFrameIndices(ithread); - }*/ + if (status == TRANSMITTING){ stopListening(ithread,rc,packetcount,total); continue; } -/* other detectors do after - //eiger - start indices for each start of scan/acquisition - this should be done after to ignore first incomplete frames - if((!measurementStarted) && (rc > 0) && (!ithread)) - startFrameIndices(ithread); -*/ //reset - if (myDetectorType != EIGER){ - packetcount = (packetsPerFrame/numListeningThreads) * numJobsPerThread; - carryonBufferSize = 0; - } + packetcount = (packetsPerFrame/numListeningThreads) * numJobsPerThread; + carryonBufferSize = 0; + //check if last packet valid and calculate packet count switch(myDetectorType){ - case MOENCH: lastpacketoffset = (((numJobsPerThread * packetsPerFrame - 1) * onePacketSize) + HEADER_SIZE_NUM_TOT_PACKETS); #ifdef VERYDEBUG @@ -1887,216 +1794,62 @@ int UDPStandardImplementation::startListening(){ cout <<"tempchar packet:"<< ((((uint32_t)(*((uint32_t*)(tempchar))))) & (packetIndexMask)) << endl; #endif - } + } break; case GOTTHARD: if(shortFrame == -1){ lastpacketoffset = (((numJobsPerThread * packetsPerFrame - 1) * onePacketSize) + HEADER_SIZE_NUM_TOT_PACKETS); #ifdef VERYDEBUG - cout << "last packet offset:" << lastpacketoffset << endl; + cprintf(BLUE, "%d last packet offset:%d\n",ithread, lastpacketoffset); #endif - + //if not last packet if((unsigned int)(packetsPerFrame -1) != ((((uint32_t)(*((uint32_t*)(buffer[ithread]+lastpacketoffset))))+1) & (packetIndexMask))){ memcpy(tempchar,buffer[ithread]+lastpacketoffset, onePacketSize); #ifdef VERYDEBUG - cout << "tempchar header:" << (((((uint32_t)(*((uint32_t*)(tempchar))))+1) - & (frameIndexMask)) >> frameIndexOffset) << endl; + cprintf(BLUE, "%d tempchar header:%d\n",ithread,(((((uint32_t)(*((uint32_t*)(tempchar))))+1) + & (frameIndexMask)) >> frameIndexOffset)); #endif carryonBufferSize = onePacketSize; --packetcount; } } #ifdef VERYDEBUG - cout << "header:" << (((((uint32_t)(*((uint32_t*)(buffer[ithread] + HEADER_SIZE_NUM_TOT_PACKETS))))+1) - & (frameIndexMask)) >> frameIndexOffset) << endl; + cprintf(BLUE, "%d header:%d\n", (((((uint32_t)(*((uint32_t*)(buffer[ithread] + HEADER_SIZE_NUM_TOT_PACKETS))))+1) + & (frameIndexMask)) >> frameIndexOffset)); #endif break; + case EIGER: - - currentpacketheader = ((*(uint8_t*)(((eiger_packet_header *)((char*)(buffer[ithread])))->num4))); - numberofmissingpackets = 0; - - //update tempframenumber if header packet missed out, ie. if packetnumber is smaller = different frame - if(lastpacketheader >= currentpacketheader){ - tempframenum++; - - //add missing packets for previous frame - numberofmissingpackets += (LAST_PACKET_VALUE - lastpacketheader); - - //add for missing frames - numberofmissingpackets += ((tempframenum-lastframeheader -1) * (packetsPerFrame/numListeningThreads)); - - //add missing packets for current frame - numberofmissingpackets += (currentpacketheader); - } - - //remember last packet value - lastpacketheader = ((*(uint8_t*)(((eiger_packet_header *)((char*)(buffer[ithread])))->num4))); - lastframeheader = tempframenum; - - //temporarily store current buffer if there are missing packets - if(numberofmissingpackets) - tempchar = buffer[ithread]; - - for(i=0;inum1)) = tempframenum; -#ifdef VERYDEBUG - cprintf(BLUE,"%d listener going to push fifo: 0x%x\n", ithread,(void*)(buffer[ithread])); -#endif - while(!fifo[ithread]->push(buffer[ithread])); -#ifdef FIFO_DEBUG - //if(!ithread) - cprintf(BLUE, "%d listener pushed into fifo %x\n",ithread, (void*)(buffer[ithread])); -#endif -#ifdef VERYDEBUG - cprintf(BLUE, "%d waiting to pop out of listeningfifo\n",ithread); -#endif - //pop - fifoFree[ithread]->pop(buffer[ithread]); -#ifdef FIFO_DEBUG - cprintf(BLUE,"%d listener popped from fifofree %x\n", ithread, (void*)(buffer[ithread])); -#endif - } - - buffer[ithread] = tempchar; - //tag framenumber to the packet - (*(uint32_t*)(((eiger_packet_header *)((char*)(buffer[ithread])))->num1)) = tempframenum; - packetcount = 1; - - - - -/* - - //literally end of buffer - lastpacketoffset = rc + HEADER_SIZE_NUM_TOT_PACKETS; - - //extra header - //or less than 1 frame caught(end of acquisition) - if(rc < expected){ - cprintf(RED,"%d rc:%d expectted:%d\n", ithread, rc, expected); - //extra header, looking at last byte of buffer - if ((*((uint8_t*)((char*)buffer[ithread]+lastpacketoffset-1))) == 0x1){ - cprintf(RED,"%d extra header\n", ithread); - //copy extra header - lastpacketoffset-= EIGER_HEADER_LENGTH; - carryonBufferSize += EIGER_HEADER_LENGTH; - memcpy(tempchar, buffer[ithread]+(lastpacketoffset-EIGER_HEADER_LENGTH), EIGER_HEADER_LENGTH); - cprintf(RED,"%d lastpacketoffset:%d\n",ithread, lastpacketoffset); - } - - //less than 1 frame caught - else cprintf(RED,"%d less than 1 frame \n", ithread); - - //find number of packets from last packet number - lastpacketoffset -= onePacketSize; - cprintf(RED,"%d lastpacketoffset:%d\n",ithread, lastpacketoffset); - - for (k=0;k*1040num4)))); - } - - packetcount = ((*(uint8_t*)(((eiger_packet_header *)((char*)(buffer[ithread] + lastpacketoffset)))->num4)))+1; - cprintf(RED,"%d num packets caught:%d\n",ithread, packetcount); - - - - cout <<"EXITING"<< endl; - exit(-1); - - } - //more than 1 frame caught but missed the frame header packet - //or exactly 1 frame caught - else { - //points to last packet - lastpacketoffset = rc + HEADER_SIZE_NUM_TOT_PACKETS - onePacketSize; - lastpacketheader = ((*(uint8_t*)(((eiger_packet_header *)((char*)(buffer[ithread] + lastpacketoffset)))->num4))); -#ifdef VERYDEBUG - cprintf(BLUE,"%d fnum: 0x%x\n", ithread, htonl(*(unsigned int*)((eiger_image_header *)((char*)(buffer[ithread] + HEADER_SIZE_NUM_TOT_PACKETS)))->fnum)); - cprintf(BLUE,"%d 1st pnum: 0x%x\n", ithread, ((*(uint8_t*)(((eiger_packet_header *)((char*)(buffer[ithread] + EIGER_HEADER_LENGTH + HEADER_SIZE_NUM_TOT_PACKETS)))->num4)))); - cprintf(BLUE,"%d last packet offset: %d\n",ithread,lastpacketoffset); - cprintf(BLUE,"%d last pnum: 0x%x\n", ithread,((*(uint8_t*)(((eiger_packet_header *)((char*)(buffer[ithread] + lastpacketoffset)))->num4)))); - //for 32 bit try to print 64 bit value of packet header to rule out no other byte changes value other than num4 -#endif - - //proper 1 frame - if((rc == expected) && (lastpacketheader == last_packet_value)){ - break; - } - - //incomplete frame, more than 1 frame caught, but missed header packet - cprintf(RED,"%d INCOMPLETE frame, rc:%d, expected:%d\n", ithread, rc, expected); - cprintf(RED,"%d fnum: 0x%x\n", ithread, htonl(*(unsigned int*)((eiger_image_header *)((char*)(buffer[ithread] + HEADER_SIZE_NUM_TOT_PACKETS)))->fnum)); - - //if eiger last packet value is NOT as expected according to bit mode - carryonBufferSize += onePacketSize; - lastpacketoffset -= onePacketSize; - --packetcount; - - cprintf(RED,"%d lastpacketheader:%d last packet value:%d packetcount: %d\n",ithread,lastpacketheader,((*(uint8_t*)(((eiger_packet_header *)((char*)(buffer[ithread] + lastpacketoffset)))->num4))), packetcount); - - //while last packet value is greater than current offset packet value (till we reach ff) - while (lastpacketheader > ((*(uint8_t*)(((eiger_packet_header *)((char*)(buffer[ithread] + lastpacketoffset)))->num4))) ){ - - lastpacketheader = ((*(uint8_t*)(((eiger_packet_header *)((char*)(buffer[ithread] + lastpacketoffset)))->num4))); - carryonBufferSize += onePacketSize; - lastpacketoffset -= onePacketSize; - --packetcount; - - cprintf(RED,"%d lastpacketheader:%d last packet value:%d packetcount: %d\n",ithread,lastpacketheader,((*(uint8_t*)(((eiger_packet_header *)((char*)(buffer[ithread] + lastpacketoffset)))->num4))), packetcount); - - } - - cprintf(RED,"%d to copy: %d\n", ithread, carryonBufferSize); - cprintf(RED,"%d lastpacketheader:%d last packet value:%d packetcount: %d\n",ithread,lastpacketheader,((*(uint8_t*)(((eiger_packet_header *)((char*)(buffer[ithread] + lastpacketoffset+onePacketSize)))->num4))), packetcount); - - memcpy(tempchar , buffer[ithread]+(HEADER_SIZE_NUM_TOT_PACKETS), EIGER_HEADER_LENGTH); - memcpy((char*)(tempchar + EIGER_HEADER_LENGTH), buffer[ithread]+(lastpacketoffset+onePacketSize), carryonBufferSize); - (*(unsigned int*)((eiger_image_header *)((char*)(buffer[ithread] + HEADER_SIZE_NUM_TOT_PACKETS)))->fnum) = htonl(lastframeheader+1); - cprintf(RED,"%d copied\n", ithread); - //#ifdef VERYDEBUG - cprintf(RED,"%d tempchar 1st pnum: 0x%x\n", ithread, ((*(uint8_t*)(((eiger_packet_header *)((char*)(tempchar+EIGER_HEADER_LENGTH)))->num4)))); - //#endif - - - } - //when we lose frame header packet - lastframeheader = htonl(*(unsigned int*)((eiger_image_header *)((char*)(buffer[ithread] + HEADER_SIZE_NUM_TOT_PACKETS)))->fnum); - cprintf(RED,"%d lastframeheader : %d\n", ithread, lastframeheader); - - */ + //because even headers might be included, so not packet count + (*((uint32_t*)(buffer[ithread]))) = rc; break; - default: break; - } - - -//#ifdef VERYDEBUG - cprintf(BLUE, "%d packetcount:%d carryonbuffer:%d\n", ithread, packetcount, carryonBufferSize); -//#endif //write packet count and push +#ifdef VERYDEBUG + cprintf(BLUE, "%d packetcount:%d carryonbuffer:%d\n", ithread, packetcount, carryonBufferSize); +#endif if(myDetectorType != EIGER) - (*((uint16_t*)(buffer[ithread]))) = packetcount; + (*((uint32_t*)(buffer[ithread]))) = packetcount; totalListeningFrameCount[ithread] += packetcount; #ifdef VERYDEBUG cprintf(BLUE,"%d listener going to push fifo: 0x%x\n", ithread,(void*)(buffer[ithread])); #endif while(!fifo[ithread]->push(buffer[ithread])); #ifdef FIFO_DEBUG - //if(!ithread) cprintf(BLUE, "%d listener pushed into fifo %x\n",ithread, (void*)(buffer[ithread])); #endif + + + } sem_wait(&listensmp[ithread]); @@ -2136,20 +1889,29 @@ int UDPStandardImplementation::startWriting(){ thread_started = 1; - int numpackets[numListeningThreads],previousframe[numListeningThreads] ,nf; - uint32_t tempframenum, tempframenum2; + int totalheader = HEADER_SIZE_NUM_TOT_PACKETS + EIGER_HEADER_LENGTH; + int numpackets[numListeningThreads], popready[numListeningThreads], woffset[numListeningThreads], nf; + bool endofacquisition, startheader[numListeningThreads]; + uint32_t tempframenum[numListeningThreads]; + + uint32_t lastpacketheader[numListeningThreads], currentpacketheader[numListeningThreads]; + int numberofmissingpackets[numListeningThreads]; + char* tempbuffer[numListeningThreads] = NULL; + int tempoffset[numListeningThreads]; + int LAST_PACKET_VALUE; + bool fullframe; + + char* wbuf[numListeningThreads];//interleaved char *d=new char[bufferSize*numListeningThreads]; int xmax=0,ymax=0; - int ret,i; - int packetsPerThread = packetsPerFrame/numListeningThreads; + int ret,i,j; while(1){ nf = 0; - packetsPerThread = packetsPerFrame/numListeningThreads; if(myDetectorType == MOENCH){ xmax = MOENCH_PIXELS_IN_ONE_ROW-1; ymax = MOENCH_PIXELS_IN_ONE_ROW-1; @@ -2162,113 +1924,323 @@ int UDPStandardImplementation::startWriting(){ ymax = GOTTHARD_SHORT_PIXELS_IN_COL-1; } } - //checking for previous numpackets of that thread should be correct - for(i=0;ipop(wbuf[i]); #ifdef FIFO_DEBUG - cprintf(GREEN,"%d writer poped from fifo %x\n", ithread, (void*)(wbuf[i])); + cprintf(MAGENTA,"%d writer poped from fifo %x\n", ithread, (void*)(wbuf[i])); #endif - numpackets[i] = (uint16_t)(*((uint16_t*)wbuf[i])); -//#ifdef VERYDEBUG - cprintf(GREEN,"%d numpackets: %d for fifo :%d\n", ithread, numpackets[i], i); -//#endif + numpackets[i] = (uint32_t)(*((uint32_t*)wbuf[i])); +#ifdef VERYDEBUG + cout << i << " numpackets:" << dec << numpackets[i] << "for fifo :"<< i << endl; +#endif + //dont pop until ready + popready[i] = 0; + //reset offset + woffset[i] = 0; + } } - //if all last dummy frames popped - if(numpackets[i] == 0xFFFF){ + + //check for end of acquisition + endofacquisition = true; + for(i=0;ifnum); + for(i=0;ifnum); + //makes sure it doesnt add the finished thread packet all over again + if(tempframenum == currframenum) + while(woffset[i] <= numpackets[i]){ - //check if one of them is less than the other (both dummies wouldnt reach here) - if(tempframenum!=tempframenum2){ - //frame number of the smaller one - onlyoneport = 1; - smaller = (tempframenum > tempframenum2); - //dummy frame will always be bigger fnum,previousframe = 1 means dont pop out that fifo next time - previousframe[!smaller] = 1; - previousframe[smaller] = 0; + //offset outside boundaries to even check for header + if((woffset[i] + EIGER_HEADER_LENGTH)>= numpackets[i]){ + popready[i] = 1; + fullframe = false; + break; + } - //update only the smaller number - if (smaller) - tempframenum = tempframenum2; - tempframenum += (startFrameIndex-1); //eiger frame numbers start at 1, so need to -1 - } - //no leftover frames left when you write both - else{ - onlyoneport = 0; - previousframe[0] = 0; - previousframe[1] = 0; + //check if header + if( 0x01 == (*(uint16_t*)(((eiger_image_header *)((char*)(wbuf[i] + woffset[i])))->header_confirm))){ + //expected frame header -eiger frame numbers start at 1, so need to -1 + if(tempframenum[i] == (htonl(*(unsigned int*)((eiger_image_header *)((char*)(wbuf[ithread] + woffset[i])))->fnum)+(startFrameIndex-1))){ + woffset[i] += EIGER_HEADER_LENGTH; + startheader[i] = true; + numberofmissingpackets[i] = 0; + lastpacketheader[i] = -1; + tempoffset[i] = 0; + } + //wrong header - leave + else{ + numberofmissingpackets[i] += (LAST_PACKET_VALUE - lastpacketheader[i]); + tempframenum[i]++; + //add missing packets + for(j=0;jnum4))); + //last packet - leave + if(currentpacketheader[i] == LAST_PACKET_VALUE){ + //fill buffer + tempbuffer[i][tempoffset[i]] = wbuf[i] + woffset[i]; + woffset[i] += onePacketSize; + //reset + startheader[i] = false; + lastpacketheader[i] = -1; + tempoffset[i] = 0; + break; + } + //same frame packet + if(currentpacketheader[i] > lastpacketheader[i]){ + + if(!startheader[i]){ + tempframenum[i]++; + } + else + startheader[i] = false; + lastpacketheader[i] = -1; + numberofmissingpackets[i] = 0; + numberofmissingpackets[i] += (currentpacketheader[i] - lastpacketheader[i] -1); + //add missing packets + for(j=0;jnum1)) = currframenum; + //overwriting port number and dynamic range + if (!j) (*(uint8_t*)(((eiger_packet_header *)((char*)(tempoffset[j] + onePacketSize*i)))->num3)) = (dynamicRange<<2); + else (*(uint8_t*)(((eiger_packet_header *)((char*)(tempoffset[j] + onePacketSize*i)))->num3)) = ((dynamicRange<<2)|(0x1)); + + #ifdef VERYDEBUG + cprintf(GREEN, "%d - 0x%x - %d\n", i, + (*(uint8_t*)(((eiger_packet_header *)((char*)(tempoffset[j] + i*onePacketSize)))->num3)), + (*(uint8_t*)(((eiger_packet_header *)((char*)(tempoffset[j] + i*onePacketSize)))->num4))); + #endif + + } + + //for 32 bit,port number needs to be changed and packet number reconstructed + if(dynamicRange == 32){ + for (i = 0; i < packetsPerFrame/4; i++){ + //new packet number that has space for 16 bit + (*(uint16_t*)(((eiger_packet_header *)((char*)(tempoffset[j] + onePacketSize*i)))->num2)) + = ((*(uint8_t*)(((eiger_packet_header *)((char*)(tempoffset[j] + onePacketSize*i)))->num4))); + + #ifdef VERYDEBUG + cprintf(GREEN, "%d - 0x%x - %d - %d\n", i, + (*(uint8_t*)(((eiger_packet_header *)((char*)(tempoffset[j] + i*onePacketSize)))->num3)), + (*(uint8_t*)(((eiger_packet_header *)((char*)(tempoffset[j] + i*onePacketSize)))->num4)), + (*(uint16_t*)(((eiger_packet_header *)((char*)(tempoffset[j] + i*onePacketSize)))->num2))); + #endif + } + for (i = packetsPerFrame/4; i < packetsPerFrame/2; i++){ + //new packet number that has space for 16 bit + (*(uint16_t*)(((eiger_packet_header *)((char*)(tempoffset[j] + onePacketSize*i)))->num2)) + = ((*(uint8_t*)(((eiger_packet_header *)((char*)(tempoffset[j] + onePacketSize*i)))->num4))+(packetsPerFrame/4)); + + #ifdef VERYDEBUG + cprintf(GREEN, "%d -0x%x - %d - %d\n", i, + (*(uint8_t*)(((eiger_packet_header *)((char*)(tempoffset[j] + i*onePacketSize)))->num3)), + (*(uint8_t*)(((eiger_packet_header *)((char*)(tempoffset[j] + i*onePacketSize)))->num4)), + (*(uint16_t*)(((eiger_packet_header *)((char*)(tempoffset[j] + i*onePacketSize)))->num2))); + #endif + } + } - }else if ((myDetectorType == GOTTHARD) && (shortFrame == -1)) - tempframenum = (((((uint32_t)(*((uint32_t*)(wbuf[ithread] + HEADER_SIZE_NUM_TOT_PACKETS))))+1)& (frameIndexMask)) >> frameIndexOffset); - else - tempframenum = ((((uint32_t)(*((uint32_t*)(wbuf[ithread] + HEADER_SIZE_NUM_TOT_PACKETS))))& (frameIndexMask)) >> frameIndexOffset); - if(numWriterThreads == 1) - currframenum = tempframenum; - else{ - pthread_mutex_lock(&progress_mutex); - if(tempframenum > currframenum) - currframenum = tempframenum; - pthread_mutex_unlock(&progress_mutex); - } -#ifdef EIGER_DEBUG2 - cprintf(GREEN,"%d tempframenum:%d curframenum:%d\n",ithread, tempframenum, currframenum); #endif - //without datacompression: write datacall back, or write data, free fifo - if(!dataCompression) handleWithoutDataCompression(ithread,wbuf,onlyoneport,smaller); - //data compression - else handleDataCompression(ithread,wbuf,d, xmax, ymax, nf); + //writeToFile_withoutCompression(wbuffer[j], npackets,currframenum); + + + + + } + } + + +#ifdef VERYDEBUG + cprintf(GREEN,"gonna copy frame\n"); +#endif + copyFrameToGui(wbuffer,currframenum); +//#ifdef VERYDEBUG + cprintf(GREEN,"copied frame\n"); +//#endif + + for(i=0;ipush(tempoffset[i])); + #ifdef FIFO_DEBUG + cprintf(GREEN,"%d writer freed pushed into fifofree %x for listener %d\n",ithread, (void*)(tempoffset[i]),i); + #endif + } + + +#ifdef EIGER_DEBUG2 + cout << endl <> frameIndexOffset); + else + tempframenum[0] = ((((uint32_t)(*((uint32_t*)(wbuf[ithread] + HEADER_SIZE_NUM_TOT_PACKETS))))& (frameIndexMask)) >> frameIndexOffset); + + if(numWriterThreads == 1) + currframenum = tempframenum[0]; + else{ + pthread_mutex_lock(&progress_mutex); + if(tempframenum[0] > currframenum) + currframenum = tempframenum[0]; + pthread_mutex_unlock(&progress_mutex); + } + + + //without datacompression: write datacall back, or write data, free fifo + if(!dataCompression) handleWithoutDataCompression(ithread,wbuf); + //data compression + else handleDataCompression(ithread,wbuf,d, xmax, ymax, nf); + + } + } #ifdef VERYVERBOSE cprintf(GREEN,"%d gonna wait for 1st sem\n", ithread); @@ -2276,7 +2248,7 @@ int UDPStandardImplementation::startWriting(){ //wait sem_wait(&writersmp[ithread]); if(killAllWritingThreads){ - cout << ithread << " good bye writing thread" << endl; + cprintf(GREEN,"%d good bye writing thread\n", ithread); closeFile(ithread); pthread_exit(NULL); } @@ -2313,7 +2285,7 @@ int UDPStandardImplementation::startWriting(){ //wait sem_wait(&writersmp[ithread]); if(killAllWritingThreads){ - cout << ithread << " Goodbye thread" << endl; + cprintf(GREEN,"%d Goodbye thread\n", ithread); closeFile(ithread); pthread_exit(NULL); } @@ -2355,11 +2327,7 @@ void UDPStandardImplementation::startFrameIndices(int ithread){ } //for scans, cuz currfraenum resets else if (myDetectorType == EIGER){ - /*if(dynamicRange == 32) - startFrameIndex = (currframenum + 1);// to be added later for scans - else*/ - startFrameIndex += currframenum; - + startFrameIndex += currframenum; } @@ -2375,93 +2343,95 @@ void UDPStandardImplementation::stopListening(int ithread, int rc, int &pc, int FILE_LOG(logDEBUG) << __AT__ << " called"; -int i; + int i; #ifdef VERYVERBOSE - cprintf(BLUE, "%d recvfrom() failed\n", ithread); + cprintf(BLUE, "%d Stop Listening\n", ithread); #endif - if(status != TRANSMITTING){ - cprintf(BG_RED,"%d *** should never be here********* status not transmitting***********************\n", ithread);/**/ - fifoFree[ithread]->push(buffer[ithread]); + + + if(status != TRANSMITTING){ + cprintf(BG_RED,"%d *** udp socket not shut down from client ***********************\n", ithread); + while(!fifoFree[ithread]->push(buffer[ithread])); + exit(-1); + } + + + //free buffer + if(rc <= 0){ + cprintf(BLUE,"%d End of acquisition\n", ithread); + while(!fifoFree[ithread]->push(buffer[ithread])); #ifdef FIFO_DEBUG - cprintf(BLUE,"%d listener not txm free pushed into fifofree %x\n", ithread,(void*)(buffer[ithread])); + cprintf(BLUE,"%d listener empty buffer pushed into fifofree %x\n", ithread, (void*)(buffer[ithread])); #endif - exit(-1); - } - - //free buffer - if(rc <= 0){ - cprintf(BLUE,"%d End of acquisition\n", ithread); - fifoFree[ithread]->push(buffer[ithread]);/** why not while(!)*/ -#ifdef FIFO_DEBUG - cprintf(BLUE,"%d listener empty buffer pushed into fifofree %x\n", ithread, (void*)(buffer[ithread])); -#endif - } - //push the last buffer into fifo - else{ - - if (rc < (bufferSize * numJobsPerThread)) - cprintf(RED,"%d Pushing Incomplete frame into fifo\n", ithread); - //eiger (complete frames) + other detectors - pc = (rc/onePacketSize); -//#ifdef VERYDEBUG - cprintf(BLUE,"%d last rc:%d\n",ithread, rc); - cprintf(BLUE,"%d last packetcount:%d\n", ithread, pc); -//#endif - (*((uint16_t*)(buffer[ithread]))) = pc; - totalListeningFrameCount[ithread] += pc; - while(!fifo[ithread]->push(buffer[ithread])); -#ifdef FIFO_DEBUG - cprintf(BLUE,"%d listener last buffer pushed into fifo %x\n", ithread,(void*)(buffer[ithread])); -#endif - - } + } - - //push dummy buffer to all writer threads - for(i=0;ipop(buffer[ithread]); -#ifdef FIFO_DEBUG - cprintf(BLUE,"%d listener popped dummy buffer from fifofree %x\n", ithread,(void*)(buffer[ithread])); -#endif - (*((uint16_t*)(buffer[ithread]))) = 0xFFFF; + //push the last buffer into fifo + else{ + pc = (rc/onePacketSize); #ifdef VERYDEBUG - cprintf(BLUE,"%d dummy buffer num packets:%d\n", ithread(*((uint16_t*)(buffer[ithread])))); + cprintf(BLUE,"%d last rc:%d\n",ithread, rc); + cprintf(BLUE,"%d last packetcount:%d\n", ithread, pc); #endif - while(!fifo[ithread]->push(buffer[ithread])); -//#ifdef FIFO_DEBUG - cprintf(BLUE,"%d listener pushed dummy buffer into fifo %x\n", ithread,(void*)(buffer[ithread])); -//#endif - } + (*((uint32_t*)(buffer[ithread]))) = pc; + totalListeningFrameCount[ithread] += pc; + while(!fifo[ithread]->push(buffer[ithread])); +#ifdef FIFO_DEBUG + cprintf(BLUE,"%d listener last buffer pushed into fifo %x\n", ithread,(void*)(buffer[ithread])); +#endif + } - //reset mask and exit loop - pthread_mutex_lock(&status_mutex); - listeningthreads_mask^=(1<pop(buffer[ithread]); +#ifdef FIFO_DEBUG + cprintf(BLUE,"%d listener popped dummy buffer from fifofree %x\n", ithread,(void*)(buffer[ithread])); +#endif + (*((uint32_t*)(buffer[ithread]))) = 0x0; #ifdef VERYDEBUG - cprintf(BLUE,"%d Resetting mask of current listening thread. New Mask: 0x%x", ithread, listeningthreads_mask); + cprintf(BLUE,"%d dummy buffer num packets:%d\n", ithread(*((uint16_t*)(buffer[ithread])))); #endif - pthread_mutex_unlock(&(status_mutex)); + while(!fifo[ithread]->push(buffer[ithread])); +#ifdef FIFO_DEBUG + cprintf(BLUE,"%d listener pushed dummy buffer into fifo %x\n", ithread,(void*)(buffer[ithread])); +#endif + } -//#ifdef VERYDEBUG - cprintf(BLUE,"%d: Frames listened to %d\n",ithread, ((totalListeningFrameCount[ithread]*numListeningThreads)/packetsPerFrame)); -//#endif - //waiting for all listening threads to be done, to print final count of frames listened to - if(ithread == 0){ + + //reset mask and exit loop + pthread_mutex_lock(&status_mutex); + listeningthreads_mask^=(1< 1) - cprintf(BLUE,"%d Waiting for listening to be done.. current mask:0x%x\n", ithread, listeningthreads_mask); + cprintf(BLUE,"%d Resetting mask of current listening thread. New Mask: 0x%x", ithread, listeningthreads_mask); #endif - while(listeningthreads_mask) - usleep(5000); -//#ifdef VERYDEBUG - t = 0; - for(i=0;i 1) + cprintf(BLUE,"%d Waiting for listening to be done.. current mask:0x%x\n", ithread, listeningthreads_mask); +#endif + while(listeningthreads_mask) + usleep(5000); +#ifdef VERYDEBUG + t = 0; + for(i=0;ipush(wbuffer[i])); +#ifdef FIFO_DEBUG + cprintf(GREEN,"%d writer free dummy pushed into fifofree %x for listener %d\n", ithread,(void*)(wbuffer[i]),i); +#endif + } + + + //all threads need to close file, reset mask and exit loop closeFile(ithread); pthread_mutex_lock(&status_mutex); @@ -2551,42 +2536,42 @@ void UDPStandardImplementation::writeToFile_withoutCompression(char* buf,int num if(myDetectorType == EIGER){ int k = 0; if(dynamicRange != 32){ - cprintf(GREEN, "\np1 fnum:0x%x\n", (*(unsigned int*)(((eiger_packet_header *)((char*)(buf + offset+k*1040)))->num1))); - cprintf(GREEN, "p1:0x%x\n", (*(uint8_t*)(((eiger_packet_header *)((char*)(buf + offset+k*1040)))->num3))); - cprintf(GREEN, "p0 num:%d - %d\n", k, (*(uint8_t*)(((eiger_packet_header *)((char*)(buf + offset+k*1040)))->num4))); + cprintf(RED, "\np1 fnum:0x%x\n", (*(unsigned int*)(((eiger_packet_header *)((char*)(buf + offset+k*1040)))->num1))); + cprintf(RED, "p1:0x%x\n", (*(uint8_t*)(((eiger_packet_header *)((char*)(buf + offset+k*1040)))->num3))); + cprintf(RED, "p0 num:%d - %d\n", k, (*(uint8_t*)(((eiger_packet_header *)((char*)(buf + offset+k*1040)))->num4))); k = 1; - cprintf(GREEN, "p2 fnum:0x%x\n", (*(unsigned int*)(((eiger_packet_header *)((char*)(buf + offset +k*1040)))->num1))); - cprintf(GREEN, "p2:0x%x\n", (*(uint8_t*)(((eiger_packet_header *)((char*)(buf + offset +k*1040)))->num3))); - cprintf(GREEN, "p1 num:%d - %d\n", k,(*(uint8_t*)(((eiger_packet_header *)((char*)(buf + offset +k*1040)))->num4))); + cprintf(RED, "p2 fnum:0x%x\n", (*(unsigned int*)(((eiger_packet_header *)((char*)(buf + offset +k*1040)))->num1))); + cprintf(RED, "p2:0x%x\n", (*(uint8_t*)(((eiger_packet_header *)((char*)(buf + offset +k*1040)))->num3))); + cprintf(RED, "p1 num:%d - %d\n", k,(*(uint8_t*)(((eiger_packet_header *)((char*)(buf + offset +k*1040)))->num4))); k = 2; - cprintf(GREEN, "p3 fnum:0x%x\n", (*(unsigned int*)(((eiger_packet_header *)((char*)(buf + offset + k*1040)))->num1))); - cprintf(GREEN, "p3:0x%x\n", (*(uint8_t*)(((eiger_packet_header *)((char*)(buf + offset +k*1040)))->num3))); - cprintf(GREEN, "p2 num:%d - %d\n", k,(*(uint8_t*)(((eiger_packet_header *)((char*)(buf + offset +k*1040)))->num4))); + cprintf(RED, "p3 fnum:0x%x\n", (*(unsigned int*)(((eiger_packet_header *)((char*)(buf + offset + k*1040)))->num1))); + cprintf(RED, "p3:0x%x\n", (*(uint8_t*)(((eiger_packet_header *)((char*)(buf + offset +k*1040)))->num3))); + cprintf(RED, "p2 num:%d - %d\n", k,(*(uint8_t*)(((eiger_packet_header *)((char*)(buf + offset +k*1040)))->num4))); }else{ k = 0; - cprintf(GREEN, "\np1 fnum:0x%x\n", (*(unsigned int*)(((eiger_packet_header *)((char*)(buf + offset+k*1040)))->num1))); - cprintf(GREEN, "p1:0x%x\n", (*(uint8_t*)(((eiger_packet_header *)((char*)(buf + offset+k*1040)))->num3))); - cprintf(GREEN, "p0 num:%d - %d\n", k, (*(uint16_t*)(((eiger_packet_header *)((char*)(buf + offset+k*1040)))->num2))); + cprintf(RED, "\np1 fnum:0x%x\n", (*(unsigned int*)(((eiger_packet_header *)((char*)(buf + offset+k*1040)))->num1))); + cprintf(RED, "p1:0x%x\n", (*(uint8_t*)(((eiger_packet_header *)((char*)(buf + offset+k*1040)))->num3))); + cprintf(RED, "p0 num:%d - %d\n", k, (*(uint16_t*)(((eiger_packet_header *)((char*)(buf + offset+k*1040)))->num2))); k = 1; - cprintf(GREEN, "p2 fnum:0x%x\n", (*(unsigned int*)(((eiger_packet_header *)((char*)(buf + offset +k*1040)))->num1))); - cprintf(GREEN, "p2:0x%x\n", (*(uint8_t*)(((eiger_packet_header *)((char*)(buf + offset +k*1040)))->num3))); - cprintf(GREEN, "p1 num:%d - %d\n", k, (*(uint16_t*)(((eiger_packet_header *)((char*)(buf + offset +k*1040)))->num2))); + cprintf(RED, "p2 fnum:0x%x\n", (*(unsigned int*)(((eiger_packet_header *)((char*)(buf + offset +k*1040)))->num1))); + cprintf(RED, "p2:0x%x\n", (*(uint8_t*)(((eiger_packet_header *)((char*)(buf + offset +k*1040)))->num3))); + cprintf(RED, "p1 num:%d - %d\n", k, (*(uint16_t*)(((eiger_packet_header *)((char*)(buf + offset +k*1040)))->num2))); k = 2; - cprintf(GREEN, "p3 fnum:0x%x\n", (*(unsigned int*)(((eiger_packet_header *)((char*)(buf + offset + k*1040)))->num1))); - cprintf(GREEN, "p3:0x%x\n", (*(uint8_t*)(((eiger_packet_header *)((char*)(buf + offset +k*1040)))->num3))); - cprintf(GREEN, "p2 num:%d - %d\n", k, (*(uint16_t*)(((eiger_packet_header *)((char*)(buf + offset +k*1040)))->num2))); + cprintf(RED, "p3 fnum:0x%x\n", (*(unsigned int*)(((eiger_packet_header *)((char*)(buf + offset + k*1040)))->num1))); + cprintf(RED, "p3:0x%x\n", (*(uint8_t*)(((eiger_packet_header *)((char*)(buf + offset +k*1040)))->num3))); + cprintf(RED, "p2 num:%d - %d\n", k, (*(uint16_t*)(((eiger_packet_header *)((char*)(buf + offset +k*1040)))->num2))); k = 256; - cprintf(GREEN, "p257 fnum:0x%x\n", (*(unsigned int*)(((eiger_packet_header *)((char*)(buf + offset + k*1040)))->num1))); - cprintf(GREEN, "p257:0x%x\n", (*(uint8_t*)(((eiger_packet_header *)((char*)(buf + offset +k*1040)))->num3))); - cprintf(GREEN, "p256 num:%d - %d\n", k, (*(uint16_t*)(((eiger_packet_header *)((char*)(buf + offset +k*1040)))->num2))); + cprintf(RED, "p257 fnum:0x%x\n", (*(unsigned int*)(((eiger_packet_header *)((char*)(buf + offset + k*1040)))->num1))); + cprintf(RED, "p257:0x%x\n", (*(uint8_t*)(((eiger_packet_header *)((char*)(buf + offset +k*1040)))->num3))); + cprintf(RED, "p256 num:%d - %d\n", k, (*(uint16_t*)(((eiger_packet_header *)((char*)(buf + offset +k*1040)))->num2))); k = 512; - cprintf(GREEN, "p513 fnum:0x%x\n", (*(unsigned int*)(((eiger_packet_header *)((char*)(buf + offset + k*1040)))->num1))); - cprintf(GREEN, "p513:0x%x\n", (*(uint8_t*)(((eiger_packet_header *)((char*)(buf + offset +k*1040)))->num3))); - cprintf(GREEN, "p512 num:%d - %d\n", k, (*(uint16_t*)(((eiger_packet_header *)((char*)(buf + offset +k*1040)))->num2))); + cprintf(RED, "p513 fnum:0x%x\n", (*(unsigned int*)(((eiger_packet_header *)((char*)(buf + offset + k*1040)))->num1))); + cprintf(RED, "p513:0x%x\n", (*(uint8_t*)(((eiger_packet_header *)((char*)(buf + offset +k*1040)))->num3))); + cprintf(RED, "p512 num:%d - %d\n", k, (*(uint16_t*)(((eiger_packet_header *)((char*)(buf + offset +k*1040)))->num2))); k = 768; - cprintf(GREEN, "p769 fnum:0x%x\n", (*(unsigned int*)(((eiger_packet_header *)((char*)(buf + offset + k*1040)))->num1))); - cprintf(GREEN, "p769:0x%x\n", (*(uint8_t*)(((eiger_packet_header *)((char*)(buf + offset +k*1040)))->num3))); - cprintf(GREEN, "p768 num:%d - %d\n", k,(*(uint16_t*)(((eiger_packet_header *)((char*)(buf + offset +k*1040)))->num2))); + cprintf(RED, "p769 fnum:0x%x\n", (*(unsigned int*)(((eiger_packet_header *)((char*)(buf + offset + k*1040)))->num1))); + cprintf(RED, "p769:0x%x\n", (*(uint8_t*)(((eiger_packet_header *)((char*)(buf + offset +k*1040)))->num3))); + cprintf(RED, "p768 num:%d - %d\n", k,(*(uint16_t*)(((eiger_packet_header *)((char*)(buf + offset +k*1040)))->num2))); } } #endif @@ -2607,9 +2592,9 @@ void UDPStandardImplementation::writeToFile_withoutCompression(char* buf,int num if(tempframenum > currframenum) currframenum = tempframenum; } -//#ifdef VERYDEBUG - cprintf(GREEN,"tempframenum: %d curframenum: %d\n",tempframenum,currframenum); -//#endif +#ifdef VERYDEBUG + cout << "tempframenum:" << dec << tempframenum << " curframenum:" << currframenum << endl; +#endif //lock if(numWriterThreads > 1) @@ -2626,7 +2611,7 @@ void UDPStandardImplementation::writeToFile_withoutCompression(char* buf,int num packetsCaught += packetsToSave; totalPacketsCaught += packetsToSave; #ifdef VERYDEBUG - cprintf(GREEN,"%d totalPacketsCaught: %d\n", ithread, totalPacketsCaught); + cout << "/totalPacketsCaught:" << dec << totalPacketsCaught <= maxPacketsPerFile){ @@ -2644,9 +2629,9 @@ void UDPStandardImplementation::writeToFile_withoutCompression(char* buf,int num if(tempframenum > currframenum) currframenum = tempframenum; } -//#ifdef VERYDEBUG - cprintf(GREEN,"tempframenum: %d curframenum: %d\n", tempframenum ,currframenum); -//#endif +#ifdef VERYDEBUG + cout << "tempframenum:" << dec << tempframenum << " curframenum:" << currframenum << endl; +#endif //create createNewFile(); } @@ -2675,16 +2660,17 @@ void UDPStandardImplementation::writeToFile_withoutCompression(char* buf,int num -void UDPStandardImplementation::handleWithoutDataCompression(int ithread, char* wbuffer[], int partialframe, int smaller){ + + + + +void UDPStandardImplementation::handleWithoutDataCompression(int ithread, char* wbuffer[]){ int totalheader = HEADER_SIZE_NUM_TOT_PACKETS + EIGER_HEADER_LENGTH; int i,j,npackets, ntotpackets=0; if (cbAction < DO_EVERYTHING){ for(i=0;ipush(wbuffer[0])); #ifdef FIFO_DEBUG - cprintf(GREEN,"%d writer compression free pushed into fifofree %x for listerner 0\n", ithread, (void*)(wbuffer[0])); + cprintf(BLUE,"%d writer compression free pushed into fifofree %x for listerner 0\n", ithread, (void*)(wbuffer[0])); #endif } From f970baf1b827031ca32861a0f330594c4d60267a Mon Sep 17 00:00:00 2001 From: Dhanya Maliakal Date: Mon, 27 Jul 2015 12:36:45 +0200 Subject: [PATCH 06/68] write and copy to gui left --- .../include/UDPStandardImplementation.h | 3 +- .../src/UDPStandardImplementation.cpp | 370 +++++++----------- 2 files changed, 144 insertions(+), 229 deletions(-) diff --git a/slsReceiverSoftware/include/UDPStandardImplementation.h b/slsReceiverSoftware/include/UDPStandardImplementation.h index 42650e9bb..3462ded22 100644 --- a/slsReceiverSoftware/include/UDPStandardImplementation.h +++ b/slsReceiverSoftware/include/UDPStandardImplementation.h @@ -442,8 +442,9 @@ private: * Its called for the first packet of a scan or acquistion * Sets the startframeindices and the variables to know if acquisition started * @param ithread listening thread number + * @param numbytes number of bytes it listened to */ - void startFrameIndices(int ithread); + void startFrameIndices(int ithread, int numbytes); /** * This is called when udp socket is shut down diff --git a/slsReceiverSoftware/src/UDPStandardImplementation.cpp b/slsReceiverSoftware/src/UDPStandardImplementation.cpp index 84d1adcbc..ed0df1b47 100644 --- a/slsReceiverSoftware/src/UDPStandardImplementation.cpp +++ b/slsReceiverSoftware/src/UDPStandardImplementation.cpp @@ -828,15 +828,17 @@ void UDPStandardImplementation::setupFifoStructure(){ if(myDetectorType == MOENCH) fifosize = MOENCH_FIFO_SIZE; else if(myDetectorType == EIGER) - fifosize = EIGER_FIFO_SIZE; + fifosize = EIGER_FIFO_SIZE * packetsPerFrame; if(fifosize % numJobsPerThread) fifosize = (fifosize/numJobsPerThread)+1; else fifosize = fifosize/numJobsPerThread; - - cout << "Number of Frames per buffer:" << numJobsPerThread << endl; + if(myDetectorType == EIGER) + cout << "1 packet per buffer" << endl; + else + cout << "Number of Frames per buffer:" << numJobsPerThread << endl; cout << "Fifo Size:" << fifosize << endl; /* @@ -854,27 +856,32 @@ void UDPStandardImplementation::setupFifoStructure(){ #endif delete fifoFree[i]; } - if(fifo[i]) delete fifo[i]; + if(fifo[i]) delete fifo[i]; if(mem0[i]) free(mem0[i]); fifoFree[i] = new CircularFifo(fifosize); fifo[i] = new CircularFifo(fifosize); + int whatperbuffer = bufferSize; + if(myDetectorType == EIGER) + whatperbuffer = onePacketSize; + //allocate memory - mem0[i]=(char*)malloc((bufferSize * numJobsPerThread + HEADER_SIZE_NUM_TOT_PACKETS)*fifosize); + mem0[i]=(char*)malloc((whatperbuffer * numJobsPerThread + HEADER_SIZE_NUM_TOT_PACKETS)*fifosize); /** shud let the client know about this */ if (mem0[i]==NULL){ cout<<"++++++++++++++++++++++ COULD NOT ALLOCATE MEMORY FOR LISTENING !!!!!!!+++++++++++++++++++++" << endl; exit(-1); } + buffer[i]=mem0[i]; //push the addresses into freed fifoFree and writingFifoFree - while (buffer[i]<(mem0[i]+(bufferSize * numJobsPerThread + HEADER_SIZE_NUM_TOT_PACKETS)*(fifosize-1))) { + while (buffer[i]<(mem0[i]+(whatperbuffer * numJobsPerThread + HEADER_SIZE_NUM_TOT_PACKETS)*(fifosize-1))) { fifoFree[i]->push(buffer[i]); #ifdef FIFO_DEBUG cprintf(BLUE,"%d fifostructure free pushed into fifofree %x\n", i, (void*)(buffer[i])); #endif - buffer[i]+=(bufferSize * numJobsPerThread + HEADER_SIZE_NUM_TOT_PACKETS); + buffer[i]+=(whatperbuffer * numJobsPerThread + HEADER_SIZE_NUM_TOT_PACKETS); } } cout << "Fifo structure(s) reconstructed" << endl; @@ -1683,7 +1690,8 @@ int UDPStandardImplementation::startListening(){ if(tempchar) {delete [] tempchar;tempchar = NULL;} if(myDetectorType != EIGER) tempchar = new char[onePacketSize * ((packetsPerFrame/numListeningThreads) - 1)]; //gotthard: 1packet size, moench:39 packet size - + else + maxBufferSize = 0; @@ -1747,7 +1755,7 @@ int UDPStandardImplementation::startListening(){ //start indices for each start of scan/acquisition if((!measurementStarted) && (rc > 0)){ pthread_mutex_lock(&progress_mutex); - startFrameIndices(ithread); + startFrameIndices(ithread, rc); pthread_mutex_unlock(&progress_mutex); } @@ -1825,6 +1833,7 @@ int UDPStandardImplementation::startListening(){ case EIGER: //because even headers might be included, so not packet count (*((uint32_t*)(buffer[ithread]))) = rc; + packetcount = 1; break; default: @@ -1890,16 +1899,16 @@ int UDPStandardImplementation::startWriting(){ thread_started = 1; int totalheader = HEADER_SIZE_NUM_TOT_PACKETS + EIGER_HEADER_LENGTH; - int numpackets[numListeningThreads], popready[numListeningThreads], woffset[numListeningThreads], nf; - bool endofacquisition, startheader[numListeningThreads]; + int numpackets[numListeningThreads], popready[numListeningThreads], nf; + bool startdatapacket[numListeningThreads],fullframe[numListeningThreads]; uint32_t tempframenum[numListeningThreads]; uint32_t lastpacketheader[numListeningThreads], currentpacketheader[numListeningThreads]; int numberofmissingpackets[numListeningThreads]; - char* tempbuffer[numListeningThreads] = NULL; + char* tempbuffer = NULL; int tempoffset[numListeningThreads]; int LAST_PACKET_VALUE; - bool fullframe; + char* wbuf[numListeningThreads];//interleaved @@ -1930,31 +1939,33 @@ int UDPStandardImplementation::startWriting(){ //allow them all to be popped initially for(i=0;ipop(wbuf[i]); #ifdef FIFO_DEBUG @@ -1977,27 +1985,18 @@ int UDPStandardImplementation::startWriting(){ #endif numpackets[i] = (uint32_t)(*((uint32_t*)wbuf[i])); #ifdef VERYDEBUG - cout << i << " numpackets:" << dec << numpackets[i] << "for fifo :"<< i << endl; + cprintf(GREEN,"%d numpackets: %d for fifo :%d\n", ithread, numpackets[i], i); #endif - //dont pop until ready - popready[i] = 0; - //reset offset - woffset[i] = 0; + //dont pop again if dummy packet + if(!numpackets[i]) + popready[i] = 0; } } - //check for end of acquisition - endofacquisition = true; - for(i=0;i= numpackets[i]){ - popready[i] = 1; - fullframe = false; - break; - } + //header packet + if( 0x01 == (*(uint8_t*)(((eiger_image_header *)((char*)(wbuf[i])))->header_confirm))){ - //check if header - if( 0x01 == (*(uint16_t*)(((eiger_image_header *)((char*)(wbuf[i] + woffset[i])))->header_confirm))){ - //expected frame header -eiger frame numbers start at 1, so need to -1 - if(tempframenum[i] == (htonl(*(unsigned int*)((eiger_image_header *)((char*)(wbuf[ithread] + woffset[i])))->fnum)+(startFrameIndex-1))){ - woffset[i] += EIGER_HEADER_LENGTH; - startheader[i] = true; - numberofmissingpackets[i] = 0; - lastpacketheader[i] = -1; - tempoffset[i] = 0; - } - //wrong header - leave - else{ - numberofmissingpackets[i] += (LAST_PACKET_VALUE - lastpacketheader[i]); - tempframenum[i]++; - //add missing packets - for(j=0;jfnum)+(startFrameIndex-1); + //next frame, leave else{ - //update current packet - currentpacketheader[i] = ((*(uint8_t*)(((eiger_packet_header *)((char*)(wbuf[i] + woffset[i])))->num4))); - //last packet - leave - if(currentpacketheader[i] == LAST_PACKET_VALUE){ - //fill buffer - tempbuffer[i][tempoffset[i]] = wbuf[i] + woffset[i]; - woffset[i] += onePacketSize; - //reset - startheader[i] = false; - lastpacketheader[i] = -1; - tempoffset[i] = 0; - break; - } - //same frame packet - if(currentpacketheader[i] > lastpacketheader[i]){ - - if(!startheader[i]){ - tempframenum[i]++; - } - else - startheader[i] = false; - lastpacketheader[i] = -1; - numberofmissingpackets[i] = 0; - numberofmissingpackets[i] += (currentpacketheader[i] - lastpacketheader[i] -1); - //add missing packets - for(j=0;jnum4))); + //same frame packet - continue building frame + if(currentpacketheader[i] > lastpacketheader[i]){ + //add missing packets + numberofmissingpackets[i] += (currentpacketheader[i] - lastpacketheader[i] -1); + for(j=0;jnum1)) = currframenum; - //overwriting port number and dynamic range - if (!j) (*(uint8_t*)(((eiger_packet_header *)((char*)(tempoffset[j] + onePacketSize*i)))->num3)) = (dynamicRange<<2); - else (*(uint8_t*)(((eiger_packet_header *)((char*)(tempoffset[j] + onePacketSize*i)))->num3)) = ((dynamicRange<<2)|(0x1)); - - #ifdef VERYDEBUG - cprintf(GREEN, "%d - 0x%x - %d\n", i, - (*(uint8_t*)(((eiger_packet_header *)((char*)(tempoffset[j] + i*onePacketSize)))->num3)), - (*(uint8_t*)(((eiger_packet_header *)((char*)(tempoffset[j] + i*onePacketSize)))->num4))); - #endif - - } - - //for 32 bit,port number needs to be changed and packet number reconstructed - if(dynamicRange == 32){ - for (i = 0; i < packetsPerFrame/4; i++){ - //new packet number that has space for 16 bit - (*(uint16_t*)(((eiger_packet_header *)((char*)(tempoffset[j] + onePacketSize*i)))->num2)) - = ((*(uint8_t*)(((eiger_packet_header *)((char*)(tempoffset[j] + onePacketSize*i)))->num4))); - - #ifdef VERYDEBUG - cprintf(GREEN, "%d - 0x%x - %d - %d\n", i, - (*(uint8_t*)(((eiger_packet_header *)((char*)(tempoffset[j] + i*onePacketSize)))->num3)), - (*(uint8_t*)(((eiger_packet_header *)((char*)(tempoffset[j] + i*onePacketSize)))->num4)), - (*(uint16_t*)(((eiger_packet_header *)((char*)(tempoffset[j] + i*onePacketSize)))->num2))); - #endif - } - for (i = packetsPerFrame/4; i < packetsPerFrame/2; i++){ - //new packet number that has space for 16 bit - (*(uint16_t*)(((eiger_packet_header *)((char*)(tempoffset[j] + onePacketSize*i)))->num2)) - = ((*(uint8_t*)(((eiger_packet_header *)((char*)(tempoffset[j] + onePacketSize*i)))->num4))+(packetsPerFrame/4)); - - #ifdef VERYDEBUG - cprintf(GREEN, "%d -0x%x - %d - %d\n", i, - (*(uint8_t*)(((eiger_packet_header *)((char*)(tempoffset[j] + i*onePacketSize)))->num3)), - (*(uint8_t*)(((eiger_packet_header *)((char*)(tempoffset[j] + i*onePacketSize)))->num4)), - (*(uint16_t*)(((eiger_packet_header *)((char*)(tempoffset[j] + i*onePacketSize)))->num2))); - #endif + //next frame packet - leave + else{ + //add missing packets + numberofmissingpackets += (LAST_PACKET_VALUE = lastpacketheader[i]); + for(j=0;jpush(tempoffset[i])); - #ifdef FIFO_DEBUG - cprintf(GREEN,"%d writer freed pushed into fifofree %x for listener %d\n",ithread, (void*)(tempoffset[i]),i); - #endif - } + //check if a full frame received + if(fullframe[0] && fullframe[1]){ + for(int i=0;ifnum); + //check if its a header + if(EIGER_HEADER_LENGTH == numbytes) + startFrameIndex = (htonl(*(unsigned int*)((eiger_image_header *)((char*)(buffer[ithread] + HEADER_SIZE_NUM_TOT_PACKETS)))->fnum))-1; + //missed header packet, so default value + else + startFrameIndex = 0; } //gotthard has +1 for frame number and not a short frame else if ((myDetectorType == GOTTHARD) && (shortFrame == -1)) @@ -2321,13 +2229,13 @@ void UDPStandardImplementation::startFrameIndices(int ithread){ //start of acquisition if(!acqStarted){ startAcquisitionIndex=startFrameIndex; - currframenum = startAcquisitionIndex; + //currframenum = startAcquisitionIndex; acqStarted = true; cprintf(BLUE,"%d startAcquisitionIndex:%d\n", ithread, startAcquisitionIndex); } //for scans, cuz currfraenum resets else if (myDetectorType == EIGER){ - startFrameIndex += currframenum; + startFrameIndex += (currframenum+1); } @@ -2369,12 +2277,18 @@ void UDPStandardImplementation::stopListening(int ithread, int rc, int &pc, int //push the last buffer into fifo else{ - pc = (rc/onePacketSize); + if(myDetectorType == EIGER){ + (*((uint32_t*)(buffer[ithread]))) = rc; + pc = 1; + }else{ + pc = (rc/onePacketSize); + (*((uint32_t*)(buffer[ithread]))) = pc; + } #ifdef VERYDEBUG cprintf(BLUE,"%d last rc:%d\n",ithread, rc); cprintf(BLUE,"%d last packetcount:%d\n", ithread, pc); #endif - (*((uint32_t*)(buffer[ithread]))) = pc; + totalListeningFrameCount[ithread] += pc; while(!fifo[ithread]->push(buffer[ithread])); #ifdef FIFO_DEBUG From fa156f337ec3b51c9c4d78d03bc4359e2dca228e Mon Sep 17 00:00:00 2001 From: Dhanya Maliakal Date: Tue, 28 Jul 2015 18:15:09 +0200 Subject: [PATCH 07/68] sorta done without missing packet identifiers --- .../include/UDPBaseImplementation.h | 3 + .../include/UDPStandardImplementation.h | 4 +- .../include/sls_receiver_defs.h | 4 +- .../src/UDPStandardImplementation.cpp | 263 ++++++++++-------- 4 files changed, 154 insertions(+), 120 deletions(-) diff --git a/slsReceiverSoftware/include/UDPBaseImplementation.h b/slsReceiverSoftware/include/UDPBaseImplementation.h index 8db022a69..1e1c7bdf9 100644 --- a/slsReceiverSoftware/include/UDPBaseImplementation.h +++ b/slsReceiverSoftware/include/UDPBaseImplementation.h @@ -575,6 +575,9 @@ protected: /** Pckets currently in current file, starts new file when it reaches max */ int packetsInFile; + /** Number of missing packets in file (sometimes packetsinFile is incorrect due to padded packets for eiger)*/ + int numTotMissingPacketsInFile; + /** Frame index at start of an entire acquisition (including all scans) */ uint32_t startAcquisitionIndex; diff --git a/slsReceiverSoftware/include/UDPStandardImplementation.h b/slsReceiverSoftware/include/UDPStandardImplementation.h index 3462ded22..40c3ab54c 100644 --- a/slsReceiverSoftware/include/UDPStandardImplementation.h +++ b/slsReceiverSoftware/include/UDPStandardImplementation.h @@ -461,7 +461,7 @@ private: * When acquisition is over, this is called * @param ithread listening thread number */ - void stopWriting(int ithread); + void stopWriting(int ithread, char* wbuffer[]); /** * updates parameters and writes to file when not a dummy frame @@ -470,7 +470,7 @@ private: * @param ithread writing thread number * @param wbuffer writer buffer */ - void handleWithoutDataCompression(int ithread, char* wbuffer[]); + void handleWithoutDataCompression(int ithread, char* wbuffer); /** * data compression for each fifo output diff --git a/slsReceiverSoftware/include/sls_receiver_defs.h b/slsReceiverSoftware/include/sls_receiver_defs.h index 7ed6e0837..a9f6d30c2 100755 --- a/slsReceiverSoftware/include/sls_receiver_defs.h +++ b/slsReceiverSoftware/include/sls_receiver_defs.h @@ -19,8 +19,8 @@ typedef int int32_t; #define MAX_FRAMES_PER_FILE 20000 #define SHORT_MAX_FRAMES_PER_FILE 100000 #define MOENCH_MAX_FRAMES_PER_FILE 1000 -#define EIGER_MAX_FRAMES_PER_FILE 20 -#define JFCTB_MAX_FRAMES_PER_FILE 100000 +#define EIGER_MAX_FRAMES_PER_FILE 2000 +#define JFCTB_MAX_FRAMES_PER_FILE 100000 /** diff --git a/slsReceiverSoftware/src/UDPStandardImplementation.cpp b/slsReceiverSoftware/src/UDPStandardImplementation.cpp index ed0df1b47..48d53098e 100644 --- a/slsReceiverSoftware/src/UDPStandardImplementation.cpp +++ b/slsReceiverSoftware/src/UDPStandardImplementation.cpp @@ -122,6 +122,7 @@ void UDPStandardImplementation::initializeMembers(){ packetsCaught = 0; totalPacketsCaught = 0; packetsInFile = 0; + numTotMissingPacketsInFile = 0; startAcquisitionIndex = 0; acquisitionIndex = 0; packetsPerFrame = 0; @@ -1260,6 +1261,7 @@ int UDPStandardImplementation::setupWriter(){ //reset writing thread variables packetsInFile=0; + numTotMissingPacketsInFile = 0; packetsCaught=0; frameIndex=0; if(sfilefd) sfilefd=NULL; @@ -1377,6 +1379,8 @@ int UDPStandardImplementation::createNewFile(){ //create file name if(frameIndexNeeded==-1) sprintf(savefilename, "%s/%s_%d.raw", filePath,fileName,fileIndex); + else if (myDetectorType == EIGER) + sprintf(savefilename, "%s/%s_f%012d_%d.raw", filePath,fileName,currframenum,fileIndex); else sprintf(savefilename, "%s/%s_f%012d_%d.raw", filePath,fileName,(packetsCaught/packetsPerFrame),fileIndex); @@ -1411,11 +1415,11 @@ int UDPStandardImplementation::createNewFile(){ cout << savefilename << "\tpacket loss " << setw(4)<header_confirm))){ + if( 0x01 == (*(uint8_t*)(((eiger_image_header *)((char*)(wbuf[i] + HEADER_SIZE_NUM_TOT_PACKETS)))->header_confirm))){ //new frame (no datapacket received yet), update frame num and corrected for fnum reset for scans if(!startdatapacket[i]) - tempframenum[i] = htonl(*(unsigned int*)((eiger_image_header *)((char*)(wbuf[ithread] + woffset[i])))->fnum)+(startFrameIndex-1); + tempframenum[i] = htonl(*(unsigned int*)((eiger_image_header *)((char*)(wbuf[ithread] + HEADER_SIZE_NUM_TOT_PACKETS)))->fnum)+(startFrameIndex-1); //next frame, leave else{ //add missing packets - numberofmissingpackets += (LAST_PACKET_VALUE = lastpacketheader[i]); + numberofmissingpackets[i] = (LAST_PACKET_VALUE - lastpacketheader[i]); + //to decrement from packetsInFile to calculate packet loss + numTotMissingPacketsInFile += numberofmissingpackets[i]; for(j=0;jnum4))); + currentpacketheader[i] = ((*(uint8_t*)(((eiger_packet_header *)((char*)(wbuf[i] + HEADER_SIZE_NUM_TOT_PACKETS)))->num4))); //same frame packet - continue building frame if(currentpacketheader[i] > lastpacketheader[i]){ //add missing packets - numberofmissingpackets[i] += (currentpacketheader[i] - lastpacketheader[i] -1); + numberofmissingpackets[i] = (currentpacketheader[i] - lastpacketheader[i] -1); + //to decrement from packetsInFile to calculate packet loss + numTotMissingPacketsInFile += numberofmissingpackets[i]; for(j=0;jpush(wbuffer[i])); + if(myDetectorType == EIGER) { + //push every packet + for(j=0;jpush(wbuffer[i]+j*onePacketSize)); #ifdef FIFO_DEBUG - cprintf(GREEN,"%d writer free dummy pushed into fifofree %x for listener %d\n", ithread,(void*)(wbuffer[i]),i); + cprintf(GREEN,"%d writer freed pushed into fifofree %x for listener %d\n",ithread, (void*)(wbuffer[i]+j*onePacketSize)); #endif + } + }else{ + while(!fifoFree[i]->push(wbuffer[i])); +#ifdef FIFO_DEBUG + cprintf(GREEN,"%d writer free dummy pushed into fifofree %x for listener %d\n", ithread,(void*)(wbuffer[i]),i); +#endif + } } @@ -2444,7 +2490,6 @@ void UDPStandardImplementation::writeToFile_withoutCompression(char* buf,int num offset = HEADER_SIZE_NUM_TOT_PACKETS; if(myDetectorType == EIGER){ - offset += EIGER_HEADER_LENGTH; #ifdef WRITE_HEADERS #ifdef VERY_DEBUG if(myDetectorType == EIGER){ @@ -2531,7 +2576,7 @@ void UDPStandardImplementation::writeToFile_withoutCompression(char* buf,int num if(packetsInFile >= maxPacketsPerFile){ //for packet loss lastpacket = (((packetsToSave - 1) * onePacketSize) + offset); - if(myDetectorType == EIGER); + if(myDetectorType == EIGER);//because currframenum is the latest one for eiger else if ((myDetectorType == GOTTHARD) && (shortFrame == -1)) tempframenum = (((((uint32_t)(*((uint32_t*)(buf + lastpacket))))+1)& (frameIndexMask)) >> frameIndexOffset); else @@ -2578,79 +2623,67 @@ void UDPStandardImplementation::writeToFile_withoutCompression(char* buf,int num -void UDPStandardImplementation::handleWithoutDataCompression(int ithread, char* wbuffer[]){ - int totalheader = HEADER_SIZE_NUM_TOT_PACKETS + EIGER_HEADER_LENGTH; - int i,j,npackets, ntotpackets=0; +void UDPStandardImplementation::handleWithoutDataCompression(int ithread, char* wbuffer){ + int i,npackets; if (cbAction < DO_EVERYTHING){ - for(i=0;i 0){ + npackets = (uint32_t)(*((uint32_t*)wbuffer)); + if (npackets > 0){ #ifdef WRITE_HEADERS - if (myDetectorType == EIGER){ + if (myDetectorType == EIGER){ - for (i = 0; i < packetsPerFrame/2; i++){ - //overwriting frame number in header - (*(uint32_t*)(((eiger_packet_header *)((char*)(wbuffer[j] + totalheader + onePacketSize*i)))->num1)) = currframenum; - //overwriting port number and dynamic range - if (!j) (*(uint8_t*)(((eiger_packet_header *)((char*)(wbuffer[j] + totalheader + onePacketSize*i)))->num3)) = (dynamicRange<<2); - else (*(uint8_t*)(((eiger_packet_header *)((char*)(wbuffer[j] + totalheader + onePacketSize*i)))->num3)) = ((dynamicRange<<2)|(0x1)); + for (i = 0; i < packetsPerFrame; i++){ + //overwriting frame number in header + (*(uint32_t*)(((eiger_packet_header *)((char*)(wbuffer + HEADER_SIZE_NUM_TOT_PACKETS + onePacketSize*i)))->num1)) = currframenum; + //overwriting port number and dynamic range + if (i<(packetsPerFrame/2)) + (*(uint8_t*)(((eiger_packet_header *)((char*)(wbuffer + HEADER_SIZE_NUM_TOT_PACKETS + onePacketSize*i)))->num3)) = (dynamicRange<<2); + else + (*(uint8_t*)(((eiger_packet_header *)((char*)(wbuffer + HEADER_SIZE_NUM_TOT_PACKETS + onePacketSize*i)))->num3)) = ((dynamicRange<<2)|(0x1)); #ifdef VERYDEBUG - cprintf(GREEN, "%d - 0x%x - %d\n", i, - (*(uint8_t*)(((eiger_packet_header *)((char*)(wbuffer[j] + totalheader +i*onePacketSize)))->num3)), - (*(uint8_t*)(((eiger_packet_header *)((char*)(wbuffer[j] + totalheader +i*onePacketSize)))->num4))); + cprintf(GREEN, "%d - 0x%x - %d\n", i, + (*(uint8_t*)(((eiger_packet_header *)((char*)(wbuffer + HEADER_SIZE_NUM_TOT_PACKETS +i*onePacketSize)))->num3)), + (*(uint8_t*)(((eiger_packet_header *)((char*)(wbuffer + HEADER_SIZE_NUM_TOT_PACKETS +i*onePacketSize)))->num4))); #endif - } + } - //for 32 bit,port number needs to be changed and packet number reconstructed - if(dynamicRange == 32){ - for (i = 0; i < packetsPerFrame/4; i++){ + //for 32 bit,port number needs to be changed and packet number reconstructed + if(dynamicRange == 32){ + for (i = 0; i < packetsPerFrame; i++){ + if( (i < (packetsPerFrame/4)) || ((i > (packetsPerFrame/2)) && (i < (3*packetsPerFrame/4))) ){ //new packet number that has space for 16 bit - (*(uint16_t*)(((eiger_packet_header *)((char*)(wbuffer[j] + totalheader + onePacketSize*i)))->num2)) - = ((*(uint8_t*)(((eiger_packet_header *)((char*)(wbuffer[j] + totalheader + onePacketSize*i)))->num4))); - -#ifdef VERYDEBUG - cprintf(GREEN, "%d - 0x%x - %d - %d\n", i, - (*(uint8_t*)(((eiger_packet_header *)((char*)(wbuffer[j] + totalheader +i*onePacketSize)))->num3)), - (*(uint8_t*)(((eiger_packet_header *)((char*)(wbuffer[j] + totalheader +i*onePacketSize)))->num4)), - (*(uint16_t*)(((eiger_packet_header *)((char*)(wbuffer[j] + totalheader +i*onePacketSize)))->num2))); -#endif - } - for (i = packetsPerFrame/4; i < packetsPerFrame/2; i++){ + (*(uint16_t*)(((eiger_packet_header *)((char*)(wbuffer + HEADER_SIZE_NUM_TOT_PACKETS + onePacketSize*i)))->num2)) + = ((*(uint8_t*)(((eiger_packet_header *)((char*)(wbuffer + HEADER_SIZE_NUM_TOT_PACKETS + onePacketSize*i)))->num4))); + }else{ //new packet number that has space for 16 bit - (*(uint16_t*)(((eiger_packet_header *)((char*)(wbuffer[j] + totalheader + onePacketSize*i)))->num2)) - = ((*(uint8_t*)(((eiger_packet_header *)((char*)(wbuffer[j] + totalheader + onePacketSize*i)))->num4))+(packetsPerFrame/4)); + (*(uint16_t*)(((eiger_packet_header *)((char*)(wbuffer + HEADER_SIZE_NUM_TOT_PACKETS + onePacketSize*i)))->num2)) + = ((*(uint8_t*)(((eiger_packet_header *)((char*)(wbuffer + HEADER_SIZE_NUM_TOT_PACKETS + onePacketSize*i)))->num4))+(packetsPerFrame/4)); -#ifdef VERYDEBUG - cprintf(GREEN, "%d -0x%x - %d - %d\n", i, - (*(uint8_t*)(((eiger_packet_header *)((char*)(wbuffer[j] + totalheader +i*onePacketSize)))->num3)), - (*(uint8_t*)(((eiger_packet_header *)((char*)(wbuffer[j] + totalheader +i*onePacketSize)))->num4)), - (*(uint16_t*)(((eiger_packet_header *)((char*)(wbuffer[j] + totalheader +i*onePacketSize)))->num2))); -#endif } +#ifdef VERYDEBUG + cprintf(GREEN, "%d - 0x%x - %d - %d\n", i, + (*(uint8_t*)(((eiger_packet_header *)((char*)(wbuffer + HEADER_SIZE_NUM_TOT_PACKETS +i*onePacketSize)))->num3)), + (*(uint8_t*)(((eiger_packet_header *)((char*)(wbuffer + HEADER_SIZE_NUM_TOT_PACKETS +i*onePacketSize)))->num4)), + (*(uint16_t*)(((eiger_packet_header *)((char*)(wbuffer + HEADER_SIZE_NUM_TOT_PACKETS +i*onePacketSize)))->num2))); +#endif + } } + } #endif - writeToFile_withoutCompression(wbuffer[j], npackets,currframenum); - } + writeToFile_withoutCompression(wbuffer, npackets,currframenum); } + #ifdef VERYDEBUG cprintf(GREEN,"written everyting\n"); #endif @@ -2658,25 +2691,23 @@ void UDPStandardImplementation::handleWithoutDataCompression(int ithread, char* if(myDetectorType == EIGER) { - if(ntotpackets >= packetsPerFrame ) { + #ifdef VERYDEBUG - cprintf(GREEN,"gonna copy frame\n"); + cprintf(GREEN,"gonna copy frame\n"); #endif - copyFrameToGui(wbuffer,currframenum); -//#ifdef VERYDEBUG - cprintf(GREEN,"copied frame\n"); -//#endif - } - for(i=0;ipush(wbuffer[i])); + copyFrameToGui(wbuffer,currframenum); + //#ifdef VERYDEBUG + cprintf(GREEN,"copied frame\n"); + //#endif + + for(i=0;inum3)) != 0xFF) + while(!fifoFree[i]->push(wbuffer+i*onePacketSize)); #ifdef FIFO_DEBUG - cprintf(GREEN,"%d writer freed pushed into fifofree %x for listener %d\n",ithread, (void*)(wbuffer[i]),i); + cprintf(GREEN,"%d writer freed pushed into fifofree %x for listener %d\n",ithread, (void*)(wbuffer+i*onePacketSize)); #endif } - - } else{ //copy to gui From d49da66daefca78bcfc6459b335abfc0a22138d3 Mon Sep 17 00:00:00 2001 From: Dhanya Maliakal Date: Thu, 30 Jul 2015 10:42:10 +0200 Subject: [PATCH 08/68] almost done with changes --- .../include/UDPStandardImplementation.h | 5 +- .../src/UDPStandardImplementation.cpp | 278 +++++++++--------- 2 files changed, 148 insertions(+), 135 deletions(-) diff --git a/slsReceiverSoftware/include/UDPStandardImplementation.h b/slsReceiverSoftware/include/UDPStandardImplementation.h index 40c3ab54c..67443f21c 100644 --- a/slsReceiverSoftware/include/UDPStandardImplementation.h +++ b/slsReceiverSoftware/include/UDPStandardImplementation.h @@ -436,7 +436,7 @@ private: * @param numpackets is the number of packets * @param framenum current frame number */ - void writeToFile_withoutCompression(char* buf,int numpackets, uint32_t framenum); + void writeToFile_withoutCompression(char* buf[],int numpackets, uint32_t framenum); /** * Its called for the first packet of a scan or acquistion @@ -469,8 +469,9 @@ private: * Called by startWriting() * @param ithread writing thread number * @param wbuffer writer buffer + * @param npackets number of packets */ - void handleWithoutDataCompression(int ithread, char* wbuffer); + void handleWithoutDataCompression(int ithread, char* wbuffer[],int npackets); /** * data compression for each fifo output diff --git a/slsReceiverSoftware/src/UDPStandardImplementation.cpp b/slsReceiverSoftware/src/UDPStandardImplementation.cpp index 3f18ddea9..8e8c930b6 100644 --- a/slsReceiverSoftware/src/UDPStandardImplementation.cpp +++ b/slsReceiverSoftware/src/UDPStandardImplementation.cpp @@ -992,12 +992,8 @@ cout << "copyframe" << endl; #endif //eiger if(startbuf != NULL){ - int offset = 0; - int size = frameSize/EIGER_MAX_PORTS; - for(int j=0;jpop(wbuf[i]); #ifdef FIFO_DEBUG - cprintf(MAGENTA,"%d writer poped from fifo %x\n", ithread, (void*)(wbuf[i])); + cprintf(GREEN,"%d writer poped from fifo %x\n", ithread, (void*)(wbuf[i])); #endif numpackets[i] = (uint32_t)(*((uint32_t*)wbuf[i])); #ifdef VERYDEBUG @@ -2070,18 +2071,23 @@ int UDPStandardImplementation::startWriting(){ if( 0x01 == (*(uint8_t*)(((eiger_image_header *)((char*)(wbuf[i] + HEADER_SIZE_NUM_TOT_PACKETS)))->header_confirm))){ //new frame (no datapacket received yet), update frame num and corrected for fnum reset for scans - if(!startdatapacket[i]) + if(!startdatapacket[i]){ + tempframenum[i] = htonl(*(unsigned int*)((eiger_image_header *)((char*)(wbuf[ithread] + HEADER_SIZE_NUM_TOT_PACKETS)))->fnum)+(startFrameIndex-1); - //next frame, leave +//#ifdef VERYVERBOSE + cprintf(GREEN,"**tempfraemnum of %d: %d\n",i,tempframenum[i]); +//#endif + }//next frame, leave else{ + cprintf(RED,"**missing packets and got header\n"); //add missing packets numberofmissingpackets[i] = (LAST_PACKET_VALUE - lastpacketheader[i]); //to decrement from packetsInFile to calculate packet loss numTotMissingPacketsInFile += numberofmissingpackets[i]; for(j=0;jnum4))); +#ifdef VERYVERBOSE + cprintf(GREEN,"** got current packet header of %d: %d lastpacketheader %d\n",i,currentpacketheader[i],lastpacketheader[i]); +#endif //same frame packet - continue building frame if(currentpacketheader[i] > lastpacketheader[i]){ //add missing packets @@ -2100,30 +2109,31 @@ int UDPStandardImplementation::startWriting(){ numTotMissingPacketsInFile += numberofmissingpackets[i]; for(j=0;jpush(buffer[ithread])); #ifdef FIFO_DEBUG cprintf(BLUE,"%d listener empty buffer pushed into fifofree %x\n", ithread, (void*)(buffer[ithread])); @@ -2415,27 +2429,15 @@ void UDPStandardImplementation::stopListening(int ithread, int rc, int &pc, int void UDPStandardImplementation::stopWriting(int ithread, char* wbuffer[]){ FILE_LOG(logDEBUG) << __AT__ << " called"; - int i,j; -#ifdef VERBOSE - cprintf(GREEN,"%d End of Acquisition\n",ithread); -#endif + cprintf(GREEN,"%d End of Acquisition for Writing Thread\n",ithread); + int i,j; //free fifo for(i=0;ipush(wbuffer[i]+j*onePacketSize)); + while(!fifoFree[i]->push(wbuffer[i])); #ifdef FIFO_DEBUG - cprintf(GREEN,"%d writer freed pushed into fifofree %x for listener %d\n",ithread, (void*)(wbuffer[i]+j*onePacketSize)); + cprintf(GREEN,"%d writer free dummy pushed into fifofree %x for listener %d\n", ithread,(void*)(wbuffer[i]),i); #endif - } - }else{ - while(!fifoFree[i]->push(wbuffer[i])); -#ifdef FIFO_DEBUG - cprintf(GREEN,"%d writer free dummy pushed into fifofree %x for listener %d\n", ithread,(void*)(wbuffer[i]),i); -#endif - } } @@ -2497,10 +2499,10 @@ void UDPStandardImplementation::stopWriting(int ithread, char* wbuffer[]){ -void UDPStandardImplementation::writeToFile_withoutCompression(char* buf,int numpackets, uint32_t framenum){ +void UDPStandardImplementation::writeToFile_withoutCompression(char* buf[],int numpackets, uint32_t framenum){ FILE_LOG(logDEBUG) << __AT__ << " called"; - int packetsToSave, offset,lastpacket; + int packetsToSave, offset,lastpacket,i; uint32_t tempframenum = framenum; //file write @@ -2513,42 +2515,42 @@ void UDPStandardImplementation::writeToFile_withoutCompression(char* buf,int num if(myDetectorType == EIGER){ int k = 0; if(dynamicRange != 32){ - cprintf(RED, "\np1 fnum:0x%x\n", (*(unsigned int*)(((eiger_packet_header *)((char*)(buf + offset+k*1040)))->num1))); - cprintf(RED, "p1:0x%x\n", (*(uint8_t*)(((eiger_packet_header *)((char*)(buf + offset+k*1040)))->num3))); - cprintf(RED, "p0 num:%d - %d\n", k, (*(uint8_t*)(((eiger_packet_header *)((char*)(buf + offset+k*1040)))->num4))); + cprintf(RED, "\np1 fnum:0x%x\n", (*(unsigned int*)(((eiger_packet_header *)((char*)(buf[k])))->num1))); + cprintf(RED, "p1:0x%x\n", (*(uint8_t*)(((eiger_packet_header *)((char*)(buf[k])))->num3))); + cprintf(RED, "p0 num:%d - %d\n", k, (*(uint8_t*)(((eiger_packet_header *)((char*)(buf[k])))->num4))); k = 1; - cprintf(RED, "p2 fnum:0x%x\n", (*(unsigned int*)(((eiger_packet_header *)((char*)(buf + offset +k*1040)))->num1))); - cprintf(RED, "p2:0x%x\n", (*(uint8_t*)(((eiger_packet_header *)((char*)(buf + offset +k*1040)))->num3))); - cprintf(RED, "p1 num:%d - %d\n", k,(*(uint8_t*)(((eiger_packet_header *)((char*)(buf + offset +k*1040)))->num4))); + cprintf(RED, "p2 fnum:0x%x\n", (*(unsigned int*)(((eiger_packet_header *)((char*)(buf[k])))->num1))); + cprintf(RED, "p2:0x%x\n", (*(uint8_t*)(((eiger_packet_header *)((char*)(buf[k])))->num3))); + cprintf(RED, "p1 num:%d - %d\n", k,(*(uint8_t*)(((eiger_packet_header *)((char*)(buf[k])))->num4))); k = 2; - cprintf(RED, "p3 fnum:0x%x\n", (*(unsigned int*)(((eiger_packet_header *)((char*)(buf + offset + k*1040)))->num1))); - cprintf(RED, "p3:0x%x\n", (*(uint8_t*)(((eiger_packet_header *)((char*)(buf + offset +k*1040)))->num3))); - cprintf(RED, "p2 num:%d - %d\n", k,(*(uint8_t*)(((eiger_packet_header *)((char*)(buf + offset +k*1040)))->num4))); + cprintf(RED, "p3 fnum:0x%x\n", (*(unsigned int*)(((eiger_packet_header *)((char*)(buf[k])))->num1))); + cprintf(RED, "p3:0x%x\n", (*(uint8_t*)(((eiger_packet_header *)((char*)(buf[k])))->num3))); + cprintf(RED, "p2 num:%d - %d\n", k,(*(uint8_t*)(((eiger_packet_header *)((char*)(buf[k])))->num4))); }else{ k = 0; - cprintf(RED, "\np1 fnum:0x%x\n", (*(unsigned int*)(((eiger_packet_header *)((char*)(buf + offset+k*1040)))->num1))); - cprintf(RED, "p1:0x%x\n", (*(uint8_t*)(((eiger_packet_header *)((char*)(buf + offset+k*1040)))->num3))); - cprintf(RED, "p0 num:%d - %d\n", k, (*(uint16_t*)(((eiger_packet_header *)((char*)(buf + offset+k*1040)))->num2))); + cprintf(RED, "\np1 fnum:0x%x\n", (*(unsigned int*)(((eiger_packet_header *)((char*)(buf[k])))->num1))); + cprintf(RED, "p1:0x%x\n", (*(uint8_t*)(((eiger_packet_header *)((char*)(buf[k])))->num3))); + cprintf(RED, "p0 num:%d - %d\n", k, (*(uint16_t*)(((eiger_packet_header *)((char*)(buf[k])))->num2))); k = 1; - cprintf(RED, "p2 fnum:0x%x\n", (*(unsigned int*)(((eiger_packet_header *)((char*)(buf + offset +k*1040)))->num1))); - cprintf(RED, "p2:0x%x\n", (*(uint8_t*)(((eiger_packet_header *)((char*)(buf + offset +k*1040)))->num3))); - cprintf(RED, "p1 num:%d - %d\n", k, (*(uint16_t*)(((eiger_packet_header *)((char*)(buf + offset +k*1040)))->num2))); + cprintf(RED, "p2 fnum:0x%x\n", (*(unsigned int*)(((eiger_packet_header *)((char*)(buf[k])))->num1))); + cprintf(RED, "p2:0x%x\n", (*(uint8_t*)(((eiger_packet_header *)((char*)(buf[k])))->num3))); + cprintf(RED, "p1 num:%d - %d\n", k, (*(uint16_t*)(((eiger_packet_header *)((char*)(buf[k])))->num2))); k = 2; - cprintf(RED, "p3 fnum:0x%x\n", (*(unsigned int*)(((eiger_packet_header *)((char*)(buf + offset + k*1040)))->num1))); - cprintf(RED, "p3:0x%x\n", (*(uint8_t*)(((eiger_packet_header *)((char*)(buf + offset +k*1040)))->num3))); - cprintf(RED, "p2 num:%d - %d\n", k, (*(uint16_t*)(((eiger_packet_header *)((char*)(buf + offset +k*1040)))->num2))); + cprintf(RED, "p3 fnum:0x%x\n", (*(unsigned int*)(((eiger_packet_header *)((char*)(buf[k])))->num1))); + cprintf(RED, "p3:0x%x\n", (*(uint8_t*)(((eiger_packet_header *)((char*)(buf[k])))->num3))); + cprintf(RED, "p2 num:%d - %d\n", k, (*(uint16_t*)(((eiger_packet_header *)((char*)(buf[k])))->num2))); k = 256; - cprintf(RED, "p257 fnum:0x%x\n", (*(unsigned int*)(((eiger_packet_header *)((char*)(buf + offset + k*1040)))->num1))); - cprintf(RED, "p257:0x%x\n", (*(uint8_t*)(((eiger_packet_header *)((char*)(buf + offset +k*1040)))->num3))); - cprintf(RED, "p256 num:%d - %d\n", k, (*(uint16_t*)(((eiger_packet_header *)((char*)(buf + offset +k*1040)))->num2))); + cprintf(RED, "p257 fnum:0x%x\n", (*(unsigned int*)(((eiger_packet_header *)((char*)(buf[k])))->num1))); + cprintf(RED, "p257:0x%x\n", (*(uint8_t*)(((eiger_packet_header *)((char*)(buf[k])))->num3))); + cprintf(RED, "p256 num:%d - %d\n", k, (*(uint16_t*)(((eiger_packet_header *)((char*)(buf[k])))->num2))); k = 512; - cprintf(RED, "p513 fnum:0x%x\n", (*(unsigned int*)(((eiger_packet_header *)((char*)(buf + offset + k*1040)))->num1))); - cprintf(RED, "p513:0x%x\n", (*(uint8_t*)(((eiger_packet_header *)((char*)(buf + offset +k*1040)))->num3))); - cprintf(RED, "p512 num:%d - %d\n", k, (*(uint16_t*)(((eiger_packet_header *)((char*)(buf + offset +k*1040)))->num2))); + cprintf(RED, "p513 fnum:0x%x\n", (*(unsigned int*)(((eiger_packet_header *)((char*)(buf[k])))->num1))); + cprintf(RED, "p513:0x%x\n", (*(uint8_t*)(((eiger_packet_header *)((char*)(buf[k])))->num3))); + cprintf(RED, "p512 num:%d - %d\n", k, (*(uint16_t*)(((eiger_packet_header *)((char*)(buf[k])))->num2))); k = 768; - cprintf(RED, "p769 fnum:0x%x\n", (*(unsigned int*)(((eiger_packet_header *)((char*)(buf + offset + k*1040)))->num1))); - cprintf(RED, "p769:0x%x\n", (*(uint8_t*)(((eiger_packet_header *)((char*)(buf + offset +k*1040)))->num3))); - cprintf(RED, "p768 num:%d - %d\n", k,(*(uint16_t*)(((eiger_packet_header *)((char*)(buf + offset +k*1040)))->num2))); + cprintf(RED, "p769 fnum:0x%x\n", (*(unsigned int*)(((eiger_packet_header *)((char*)(buf[k])))->num1))); + cprintf(RED, "p769:0x%x\n", (*(uint8_t*)(((eiger_packet_header *)((char*)(buf[k])))->num3))); + cprintf(RED, "p768 num:%d - %d\n", k,(*(uint16_t*)(((eiger_packet_header *)((char*)(buf[k])))->num2))); } } #endif @@ -2559,9 +2561,9 @@ void UDPStandardImplementation::writeToFile_withoutCompression(char* buf,int num //for progress and packet loss calculation(new files) if(myDetectorType == EIGER); else if ((myDetectorType == PROPIX)||((myDetectorType == GOTTHARD) && (shortFrame == -1))) - tempframenum = (((((uint32_t)(*((uint32_t*)(buf + HEADER_SIZE_NUM_TOT_PACKETS))))+1)& (frameIndexMask)) >> frameIndexOffset); + tempframenum = (((((uint32_t)(*((uint32_t*)(buf[0] + HEADER_SIZE_NUM_TOT_PACKETS))))+1)& (frameIndexMask)) >> frameIndexOffset); else - tempframenum = ((((uint32_t)(*((uint32_t*)(buf + HEADER_SIZE_NUM_TOT_PACKETS))))& (frameIndexMask)) >> frameIndexOffset); + tempframenum = ((((uint32_t)(*((uint32_t*)(buf[0] + HEADER_SIZE_NUM_TOT_PACKETS))))& (frameIndexMask)) >> frameIndexOffset); if(numWriterThreads == 1) currframenum = tempframenum; @@ -2583,7 +2585,12 @@ void UDPStandardImplementation::writeToFile_withoutCompression(char* buf,int num if(packetsToSave > numpackets) packetsToSave = numpackets; /**next time offset is still plus header length*/ - fwrite(buf+offset, 1, packetsToSave * onePacketSize, sfilefd); + if(myDetectorType == EIGER) + for(i=0;i= maxPacketsPerFile){ - //for packet loss - lastpacket = (((packetsToSave - 1) * onePacketSize) + offset); - if(myDetectorType == EIGER);//because currframenum is the latest one for eiger - else if ((myDetectorType == PROPIX)||((myDetectorType == GOTTHARD) && (shortFrame == -1))) + //for packet loss, because currframenum is the latest one for eiger + if(myDetectorType != EIGER){ + lastpacket = (((packetsToSave - 1) * onePacketSize) + offset); - tempframenum = (((((uint32_t)(*((uint32_t*)(buf + lastpacket))))+1)& (frameIndexMask)) >> frameIndexOffset); - else - tempframenum = ((((uint32_t)(*((uint32_t*)(buf + lastpacket))))& (frameIndexMask)) >> frameIndexOffset); + if ((myDetectorType == PROPIX)||((myDetectorType == GOTTHARD) && (shortFrame == -1))) + tempframenum = (((((uint32_t)(*((uint32_t*)(buf[0] + lastpacket))))+1)& (frameIndexMask)) >> frameIndexOffset); + else + tempframenum = ((((uint32_t)(*((uint32_t*)(buf[0] + lastpacket))))& (frameIndexMask)) >> frameIndexOffset); + } if(numWriterThreads == 1) currframenum = tempframenum; else{ @@ -2619,8 +2627,8 @@ void UDPStandardImplementation::writeToFile_withoutCompression(char* buf,int num if(numWriterThreads > 1) pthread_mutex_unlock(&write_mutex); - - offset += (packetsToSave * onePacketSize); + if(myDetectorType != EIGER) + offset += (packetsToSave * onePacketSize); numpackets -= packetsToSave; } @@ -2643,17 +2651,19 @@ void UDPStandardImplementation::writeToFile_withoutCompression(char* buf,int num -void UDPStandardImplementation::handleWithoutDataCompression(int ithread, char* wbuffer){ - int i,npackets; +void UDPStandardImplementation::handleWithoutDataCompression(int ithread, char* wbuffer[],int npackets){ + int i,j; if (cbAction < DO_EVERYTHING){ - npackets = (uint32_t)(*((uint32_t*)wbuffer)); - rawDataReadyCallBack(currframenum, wbuffer + HEADER_SIZE_NUM_TOT_PACKETS, npackets * onePacketSize, sfilefd, guiData,pRawDataReady); + if (myDetectorType == EIGER){ + for(i=0;i 0){ #ifdef WRITE_HEADERS @@ -2661,17 +2671,17 @@ void UDPStandardImplementation::handleWithoutDataCompression(int ithread, char* for (i = 0; i < packetsPerFrame; i++){ //overwriting frame number in header - (*(uint32_t*)(((eiger_packet_header *)((char*)(wbuffer + HEADER_SIZE_NUM_TOT_PACKETS + onePacketSize*i)))->num1)) = currframenum; + (*(uint32_t*)(((eiger_packet_header *)((char*)(wbuffer[i])))->num1)) = currframenum; //overwriting port number and dynamic range if (i<(packetsPerFrame/2)) - (*(uint8_t*)(((eiger_packet_header *)((char*)(wbuffer + HEADER_SIZE_NUM_TOT_PACKETS + onePacketSize*i)))->num3)) = (dynamicRange<<2); + (*(uint8_t*)(((eiger_packet_header *)((char*)(wbuffer[i])))->num3)) = (dynamicRange<<2); else - (*(uint8_t*)(((eiger_packet_header *)((char*)(wbuffer + HEADER_SIZE_NUM_TOT_PACKETS + onePacketSize*i)))->num3)) = ((dynamicRange<<2)|(0x1)); + (*(uint8_t*)(((eiger_packet_header *)((char*)(wbuffer[i])))->num3)) = ((dynamicRange<<2)|(0x1)); #ifdef VERYDEBUG cprintf(GREEN, "%d - 0x%x - %d\n", i, - (*(uint8_t*)(((eiger_packet_header *)((char*)(wbuffer + HEADER_SIZE_NUM_TOT_PACKETS +i*onePacketSize)))->num3)), - (*(uint8_t*)(((eiger_packet_header *)((char*)(wbuffer + HEADER_SIZE_NUM_TOT_PACKETS +i*onePacketSize)))->num4))); + (*(uint8_t*)(((eiger_packet_header *)((char*)(wbuffer[i])))->num3)), + (*(uint8_t*)(((eiger_packet_header *)((char*)(wbuffer[i])))->num4))); #endif } @@ -2681,19 +2691,19 @@ void UDPStandardImplementation::handleWithoutDataCompression(int ithread, char* for (i = 0; i < packetsPerFrame; i++){ if( (i < (packetsPerFrame/4)) || ((i > (packetsPerFrame/2)) && (i < (3*packetsPerFrame/4))) ){ //new packet number that has space for 16 bit - (*(uint16_t*)(((eiger_packet_header *)((char*)(wbuffer + HEADER_SIZE_NUM_TOT_PACKETS + onePacketSize*i)))->num2)) - = ((*(uint8_t*)(((eiger_packet_header *)((char*)(wbuffer + HEADER_SIZE_NUM_TOT_PACKETS + onePacketSize*i)))->num4))); + (*(uint16_t*)(((eiger_packet_header *)((char*)(wbuffer[i])))->num2)) + = ((*(uint8_t*)(((eiger_packet_header *)((char*)(wbuffer[i])))->num4))); }else{ //new packet number that has space for 16 bit - (*(uint16_t*)(((eiger_packet_header *)((char*)(wbuffer + HEADER_SIZE_NUM_TOT_PACKETS + onePacketSize*i)))->num2)) - = ((*(uint8_t*)(((eiger_packet_header *)((char*)(wbuffer + HEADER_SIZE_NUM_TOT_PACKETS + onePacketSize*i)))->num4))+(packetsPerFrame/4)); + (*(uint16_t*)(((eiger_packet_header *)((char*)(wbuffer[i])))->num2)) + = ((*(uint8_t*)(((eiger_packet_header *)((char*)(wbuffer[i])))->num4))+(packetsPerFrame/4)); } #ifdef VERYDEBUG cprintf(GREEN, "%d - 0x%x - %d - %d\n", i, - (*(uint8_t*)(((eiger_packet_header *)((char*)(wbuffer + HEADER_SIZE_NUM_TOT_PACKETS +i*onePacketSize)))->num3)), - (*(uint8_t*)(((eiger_packet_header *)((char*)(wbuffer + HEADER_SIZE_NUM_TOT_PACKETS +i*onePacketSize)))->num4)), - (*(uint16_t*)(((eiger_packet_header *)((char*)(wbuffer + HEADER_SIZE_NUM_TOT_PACKETS +i*onePacketSize)))->num2))); + (*(uint8_t*)(((eiger_packet_header *)((char*)(wbuffer[i])))->num3)), + (*(uint8_t*)(((eiger_packet_header *)((char*)(wbuffer[i])))->num4)), + (*(uint16_t*)(((eiger_packet_header *)((char*)(wbuffer[i])))->num2))); #endif } @@ -2720,13 +2730,15 @@ void UDPStandardImplementation::handleWithoutDataCompression(int ithread, char* cprintf(GREEN,"copied frame\n"); //#endif - for(i=0;inum3)) != 0xFF) - while(!fifoFree[i]->push(wbuffer+i*onePacketSize)); + for(i=0;inum3)) != 0xFF) + while(!fifoFree[i]->push(wbuffer[j+i*(packetsPerFrame/2)])); #ifdef FIFO_DEBUG - cprintf(GREEN,"%d writer freed pushed into fifofree %x for listener %d\n",ithread, (void*)(wbuffer+i*onePacketSize)); + cprintf(GREEN,"%d writer freed pushed into fifofree %x for listener %d\n",ithread, (void*)(wbuffer[j+i*(packetsPerFrame/2)])); #endif + } } } else{ @@ -2752,13 +2764,13 @@ void UDPStandardImplementation::handleWithoutDataCompression(int ithread, char* -void UDPStandardImplementation::handleDataCompression(int ithread, char* wbuffer[], int &npackets, char* data, int xmax, int ymax, int &nf){ +void UDPStandardImplementation::handleDataCompression(int ithread, char* wbuffer[], char* data, int xmax, int ymax, int &nf){ FILE_LOG(logDEBUG) << __AT__ << " called"; #if defined(MYROOT1) && defined(ALLFILE_DEBUG) writeToFile_withoutCompression(wbuf[0], numpackets,currframenum); #endif - + int npackets = (uint32_t)(*((uint32_t*)wbuffer[0])); eventType thisEvent = PEDESTAL; int ndata; char* buff = 0; From 902ab367053a9c2bf552770a2583c0883abbce2e Mon Sep 17 00:00:00 2001 From: Dhanya Maliakal Date: Mon, 3 Aug 2015 16:29:59 +0200 Subject: [PATCH 09/68] almost done --- .../include/UDPBaseImplementation.h | 11 +- .../src/UDPStandardImplementation.cpp | 368 +++++++++++------- 2 files changed, 236 insertions(+), 143 deletions(-) diff --git a/slsReceiverSoftware/include/UDPBaseImplementation.h b/slsReceiverSoftware/include/UDPBaseImplementation.h index 1e1c7bdf9..4e29e0bc6 100644 --- a/slsReceiverSoftware/include/UDPBaseImplementation.h +++ b/slsReceiverSoftware/include/UDPBaseImplementation.h @@ -567,16 +567,19 @@ protected: uint32_t frameIndex; /** Frames Caught for each real time acquisition (eg. for each scan) */ - int packetsCaught; + uint32_t packetsCaught; /** Total packets caught for an entire acquisition (including all scans) */ - int totalPacketsCaught; + uint32_t totalPacketsCaught; /** Pckets currently in current file, starts new file when it reaches max */ - int packetsInFile; + uint32_t packetsInFile; /** Number of missing packets in file (sometimes packetsinFile is incorrect due to padded packets for eiger)*/ - int numTotMissingPacketsInFile; + uint32_t numTotMissingPacketsInFile; + + /** Number of missing packets in an acquisition(sometimes packetsinFile is incorrect due to padded packets for eiger)*/ + uint32_t numMissingPackets; /** Frame index at start of an entire acquisition (including all scans) */ uint32_t startAcquisitionIndex; diff --git a/slsReceiverSoftware/src/UDPStandardImplementation.cpp b/slsReceiverSoftware/src/UDPStandardImplementation.cpp index f53897625..3cd559b52 100644 --- a/slsReceiverSoftware/src/UDPStandardImplementation.cpp +++ b/slsReceiverSoftware/src/UDPStandardImplementation.cpp @@ -123,6 +123,7 @@ void UDPStandardImplementation::initializeMembers(){ totalPacketsCaught = 0; packetsInFile = 0; numTotMissingPacketsInFile = 0; + numMissingPackets = 0; startAcquisitionIndex = 0; acquisitionIndex = 0; packetsPerFrame = 0; @@ -1278,6 +1279,7 @@ int UDPStandardImplementation::setupWriter(){ //reset writing thread variables packetsInFile=0; numTotMissingPacketsInFile = 0; + numMissingPackets = 0; packetsCaught=0; frameIndex=0; if(sfilefd) sfilefd=NULL; @@ -1936,16 +1938,37 @@ int UDPStandardImplementation::startWriting(){ int ret,i,j; + char* tofree[packetsPerFrame] ; + int tofreeoffset[packetsPerFrame]; char* tempbuffer[packetsPerFrame]; char* blankframe[packetsPerFrame]; int blankoffset; int tempoffset[numListeningThreads]; - if(myDetectorType == EIGER) + if(myDetectorType == EIGER){ for(i=0;inum3)) != 0xFF) + cprintf(RED,"blank frame header is not FF\n"); + + cprintf(GREEN,"packet %d blank frame 0x%x\n",i,(void*)(blankframe[i])); } + //last packet numbers for different dynamic ranges + switch(dynamicRange){ + case 4: LAST_PACKET_VALUE = 0x40; break; + case 8: LAST_PACKET_VALUE = 0x80; break; + case 16: LAST_PACKET_VALUE = 0xff; break; + case 32: LAST_PACKET_VALUE = 0xff; break; + default: break; + } + + } + while(1){ @@ -1972,6 +1995,7 @@ int UDPStandardImplementation::startWriting(){ popready[i] = true; startdatapacket[i] = false; tempoffset[i] = (i*packetsPerFrame/numListeningThreads); + tofreeoffset[i] = (i*packetsPerFrame/numListeningThreads); blankoffset = 0; lastpacketheader[i] = -1; currentpacketheader[i] = -1; @@ -1983,34 +2007,6 @@ int UDPStandardImplementation::startWriting(){ - if(myDetectorType == EIGER){ - - for(i=0;ipop(wbuf[i]); #ifdef FIFO_DEBUG - cprintf(GREEN,"%d writer poped from fifo %x\n", ithread, (void*)(wbuf[i])); + cprintf(GREEN,"%d writer poped 0x%x from fifo %d\n", ithread, (void*)(wbuf[i]), i); #endif numpackets[i] = (uint32_t)(*((uint32_t*)wbuf[i])); #ifdef VERYDEBUG cprintf(GREEN,"%d numpackets: %d for fifo :%d\n", ithread, numpackets[i], i); #endif //dont pop again if dummy packet - if(!numpackets[i]) + if(!numpackets[i]){ popready[i] = false; + cprintf(RED,"%d dummy frame popped out of fifo %d",ithread, i); + }else{ + tofree[tofreeoffset[i]] = wbuf[i]; + tofreeoffset[i]++; + } + } } @@ -2040,11 +2042,31 @@ int UDPStandardImplementation::startWriting(){ //end of acquisition if((!numpackets[0])&& (!numpackets[1])){ -#ifdef VERYDEBUG - cprintf(GREEN,"%d End of Acquisition in Writing Thread\n", ithread); -#endif - stopWriting(ithread,wbuf); - continue; +//#ifdef VERYDEBUG + cprintf(GREEN,"%d Both dummy frames\n", ithread); +//#endif + //remaning packets to be written + if((myDetectorType == EIGER) && + ((tempoffset[0]!=0) || (tempoffset[1]!=(packetsPerFrame/numListeningThreads)))){ + cprintf(RED,"**missing packets and end of acquisition\n"); + for(i=0;iheader_confirm))){ - - //new frame (no datapacket received yet), update frame num and corrected for fnum reset for scans - if(!startdatapacket[i]){ - tempframenum[i] = htonl(*(unsigned int*)((eiger_image_header *)((char*)(wbuf[ithread] + HEADER_SIZE_NUM_TOT_PACKETS)))->fnum)+(startFrameIndex-1); -//#ifdef VERYVERBOSE - cprintf(GREEN,"**tempfraemnum of %d: %d\n",i,tempframenum[i]); -//#endif - }//next frame, leave - else{ - cprintf(RED,"**missing packets and got header\n"); - //add missing packets - numberofmissingpackets[i] = (LAST_PACKET_VALUE - lastpacketheader[i]); - //to decrement from packetsInFile to calculate packet loss - numTotMissingPacketsInFile += numberofmissingpackets[i]; - for(j=0;jnum4))); -#ifdef VERYVERBOSE - cprintf(GREEN,"** got current packet header of %d: %d lastpacketheader %d\n",i,currentpacketheader[i],lastpacketheader[i]); +#ifdef VERBOSE + else + cprintf(RED, "WARNING: Dummy packet: %d from fifo %d\n", numpackets[i],i); #endif - //same frame packet - continue building frame - if(currentpacketheader[i] > lastpacketheader[i]){ - //add missing packets - numberofmissingpackets[i] = (currentpacketheader[i] - lastpacketheader[i] -1); - //to decrement from packetsInFile to calculate packet loss - numTotMissingPacketsInFile += numberofmissingpackets[i]; - for(j=0;jpush((wbuf[i]))); +//#ifdef FIFO_DEBUG + cprintf(GREEN,"%d writer freed unknown length pushed into fifofree %x for listener %d\n",ithread, (void*)(wbuf[i]),i); +//#endif + } + continue; + } + + //not dummy buffer and not after getting a full frame + if(numpackets[i] && (!fullframe[i])){ + + //header packet + if( 0x01 == (*(uint8_t*)(((eiger_image_header *)((char*)(wbuf[i] + HEADER_SIZE_NUM_TOT_PACKETS)))->header_confirm))){ + + //new frame (no datapacket received yet), update frame num and corrected for fnum reset for scans + if(!startdatapacket[i]){ + tempframenum[i] = (htonl(*(unsigned int*)((eiger_image_header *)((char*)(wbuf[i] + HEADER_SIZE_NUM_TOT_PACKETS)))->fnum)); + if(!tempframenum[i]) + cprintf(RED,"**VERY WEIRD frame numbers for fifo %d: %d\n",i,tempframenum[i]); + tempframenum[i] += (startFrameIndex-1); + //#ifdef VERYVERBOSE + cprintf(GREEN,"**tempfraemnum of %d: %d\n",i,tempframenum[i]); + //#endif + }//next frame, leave + else{ + cprintf(RED,"**missing packets and got header\n"); + //add missing packets + numberofmissingpackets[i] = (LAST_PACKET_VALUE - lastpacketheader[i]); + //to decrement from packetsInFile to calculate packet loss + for(j=0;jnum4))); +#ifdef VERYVERBOSE + cprintf(GREEN,"**fifo:%d currentpacketheader: %d lastpacketheader %d\n",i,currentpacketheader[i],lastpacketheader[i]); +#endif + //same frame packet - continue building frame + if(currentpacketheader[i] > lastpacketheader[i]){ + //add missing packets + numberofmissingpackets[i] = (currentpacketheader[i] - lastpacketheader[i] -1); + //to decrement from packetsInFile to calculate packet loss + for(j=0;jpush(tofree[j])); +#ifdef FIFO_DEBUG + cprintf(GREEN,"%d writer freed pushed into fifofree %x for listener %d\n",ithread, (void*)(tofree[j]),0); +#endif + } + for(j=(packetsPerFrame/numListeningThreads);jpush(tofree[j])); +#ifdef FIFO_DEBUG + cprintf(GREEN,"%d writer freed pushed into fifofree %x for listener %d\n",ithread, (void*)(tofree[j]),1); +#endif + } + + + +//#ifdef VERYDEBUG + cprintf(GREEN,"finished freeing\n"); +//#endif //reset a few stuff for(int i=0;ipush(wbuffer[i])); -#ifdef FIFO_DEBUG +//#ifdef FIFO_DEBUG cprintf(GREEN,"%d writer free dummy pushed into fifofree %x for listener %d\n", ithread,(void*)(wbuffer[i]),i); -#endif +//#endif } @@ -2480,8 +2559,8 @@ void UDPStandardImplementation::stopWriting(int ithread, char* wbuffer[]){ cprintf(GREEN, "Status: Run Finished\n"); if(!totalPacketsCaught){ - cprintf(GREEN, "Total Packets Caught:%d\n", totalPacketsCaught); - cprintf(GREEN, "Total Frames Caught:%d\n",(totalPacketsCaught/packetsPerFrame)); + cprintf(RED, "Total Packets Caught: 0\n"); + cprintf(RED, "Total Frames Caught: 0\n"); }else{ cprintf(GREEN, "Total Packets Caught:%d\n", totalPacketsCaught); cprintf(GREEN, "Total Frames Caught:%d\n",(totalPacketsCaught/packetsPerFrame)); @@ -2505,7 +2584,7 @@ void UDPStandardImplementation::stopWriting(int ithread, char* wbuffer[]){ void UDPStandardImplementation::writeToFile_withoutCompression(char* buf[],int numpackets, uint32_t framenum){ FILE_LOG(logDEBUG) << __AT__ << " called"; - +cout<<"in write to file numpackets:"< numpackets) packetsToSave = numpackets; /**next time offset is still plus header length*/ - if(myDetectorType == EIGER) - for(i=0;i= maxPacketsPerFile){ @@ -2641,8 +2724,9 @@ void UDPStandardImplementation::writeToFile_withoutCompression(char* buf[],int n if(numWriterThreads > 1) pthread_mutex_lock(&write_mutex); packetsInFile += numpackets; - packetsCaught += numpackets; - totalPacketsCaught += numpackets; + packetsCaught += (numpackets - numMissingPackets); + totalPacketsCaught += (numpackets - numMissingPackets); + numMissingPackets = 0; if(numWriterThreads > 1) pthread_mutex_unlock(&write_mutex); } @@ -2734,16 +2818,22 @@ void UDPStandardImplementation::handleWithoutDataCompression(int ithread, char* cprintf(GREEN,"copied frame\n"); //#endif - for(i=0;inum3)) != 0xFF) - while(!fifoFree[i]->push(wbuffer[j+i*(packetsPerFrame/2)])); -#ifdef FIFO_DEBUG - cprintf(GREEN,"%d writer freed pushed into fifofree %x for listener %d\n",ithread, (void*)(wbuffer[j+i*(packetsPerFrame/2)])); -#endif - } +/* + for(j=0;jnum3)) != 0xFF){ + + while(!fifoFree[(j/(packetsPerFrame/2))]->push(&(wbuffer[j] - HEADER_SIZE_NUM_TOT_PACKETS))); + + //#ifdef FIFO_DEBUG + cprintf(GREEN,"%d writer freed pushed into fifofree %x for listener %d\n",ithread, (void*)(wbuffer[j]- HEADER_SIZE_NUM_TOT_PACKETS),(j/(packetsPerFrame/2))); + //#endif + }else cprintf(GREEN,"blank frame 0x%x\n",(void*)(wbuffer[j])); } + + //#ifdef VERYDEBUG + cprintf(GREEN,"finished freeing\n"); + //#endif + */ } else{ //copy to gui From 4fbfe186ef636f06bd9f17d651cc78da00bc6ade Mon Sep 17 00:00:00 2001 From: Dhanya Maliakal Date: Tue, 4 Aug 2015 15:20:00 +0200 Subject: [PATCH 10/68] done --- .../src/UDPStandardImplementation.cpp | 225 +++++++++--------- 1 file changed, 119 insertions(+), 106 deletions(-) diff --git a/slsReceiverSoftware/src/UDPStandardImplementation.cpp b/slsReceiverSoftware/src/UDPStandardImplementation.cpp index 3cd559b52..9f365d4b0 100644 --- a/slsReceiverSoftware/src/UDPStandardImplementation.cpp +++ b/slsReceiverSoftware/src/UDPStandardImplementation.cpp @@ -1922,43 +1922,34 @@ int UDPStandardImplementation::startWriting(){ thread_started = 1; - int numpackets[numListeningThreads], nf; - bool startdatapacket[numListeningThreads],fullframe[numListeningThreads],popready[numListeningThreads]; - uint32_t tempframenum[numListeningThreads]; - - int lastpacketheader[numListeningThreads], currentpacketheader[numListeningThreads]; - int numberofmissingpackets[numListeningThreads]; - int LAST_PACKET_VALUE; - - - char* wbuf[numListeningThreads];//interleaved char *d=new char[bufferSize*numListeningThreads]; int xmax=0,ymax=0; int ret,i,j; + int numpackets[numListeningThreads], nf; + bool startdatapacket[numListeningThreads],fullframe[numListeningThreads],popready[numListeningThreads]; + uint32_t tempframenum[numListeningThreads]; + int lastpacketheader[numListeningThreads], currentpacketheader[numListeningThreads]; + int numberofmissingpackets[numListeningThreads]; - char* tofree[packetsPerFrame] ; - int tofreeoffset[packetsPerFrame]; - char* tempbuffer[packetsPerFrame]; - char* blankframe[packetsPerFrame]; - int blankoffset; + int MAX_VALUE = 1024; + char* tofree[MAX_VALUE]; + char* tempbuffer[MAX_VALUE]; + char* blankframe[MAX_VALUE]; + int tofreeoffset[numListeningThreads]; int tempoffset[numListeningThreads]; + int blankoffset; + for(i=0;inum3)) != 0xFF) - cprintf(RED,"blank frame header is not FF\n"); - - cprintf(GREEN,"packet %d blank frame 0x%x\n",i,(void*)(blankframe[i])); - } - - //last packet numbers for different dynamic ranges switch(dynamicRange){ case 4: LAST_PACKET_VALUE = 0x40; break; case 8: LAST_PACKET_VALUE = 0x80; break; @@ -1966,9 +1957,10 @@ int UDPStandardImplementation::startWriting(){ case 32: LAST_PACKET_VALUE = 0xff; break; default: break; } - } + + while(1){ @@ -1989,6 +1981,20 @@ int UDPStandardImplementation::startWriting(){ //so that the first frame is always copied guiData = latestData; + //blank frame + if(myDetectorType == EIGER){ + for(i=0;ipush((wbuf[i]))); -//#ifdef FIFO_DEBUG - cprintf(GREEN,"%d writer freed unknown length pushed into fifofree %x for listener %d\n",ithread, (void*)(wbuf[i]),i); -//#endif - } continue; } //not dummy buffer and not after getting a full frame if(numpackets[i] && (!fullframe[i])){ - //header packet + //IMAGE HEADER PACKET if( 0x01 == (*(uint8_t*)(((eiger_image_header *)((char*)(wbuf[i] + HEADER_SIZE_NUM_TOT_PACKETS)))->header_confirm))){ //new frame (no datapacket received yet), update frame num and corrected for fnum reset for scans @@ -2114,12 +2115,37 @@ int UDPStandardImplementation::startWriting(){ if(!tempframenum[i]) cprintf(RED,"**VERY WEIRD frame numbers for fifo %d: %d\n",i,tempframenum[i]); tempframenum[i] += (startFrameIndex-1); - //#ifdef VERYVERBOSE - cprintf(GREEN,"**tempfraemnum of %d: %d\n",i,tempframenum[i]); - //#endif - }//next frame, leave + + //normal frame packet (also exception of tempnum 0 and currfnum 0) + if((tempframenum[i] == (currframenum+1))||(!tempframenum[i] && !currframenum)){ +#ifdef EIGER_DEBUG3 + cprintf(GREEN,"**tempfraemnum of %d: %d\n",i,tempframenum[i]); +#endif + } + //frame too far ahead + else{ +#ifdef EIGER_DEBUG3 + cprintf(RED,"frame number too far ahead, missing packets\n"); +#endif + tempframenum[i] = currframenum + 1; + //add missing packets + numberofmissingpackets[i] = (LAST_PACKET_VALUE); + //to decrement from packetsInFile to calculate packet loss + for(j=0;jpush(wbuffer[i])); -//#ifdef FIFO_DEBUG +#ifdef FIFO_DEBUG cprintf(GREEN,"%d writer free dummy pushed into fifofree %x for listener %d\n", ithread,(void*)(wbuffer[i]),i); -//#endif +#endif } @@ -2584,7 +2610,7 @@ void UDPStandardImplementation::stopWriting(int ithread, char* wbuffer[]){ void UDPStandardImplementation::writeToFile_withoutCompression(char* buf[],int numpackets, uint32_t framenum){ FILE_LOG(logDEBUG) << __AT__ << " called"; -cout<<"in write to file numpackets:"<= maxPacketsPerFile){ @@ -2814,28 +2842,10 @@ void UDPStandardImplementation::handleWithoutDataCompression(int ithread, char* cprintf(GREEN,"gonna copy frame\n"); #endif copyFrameToGui(wbuffer,currframenum); - //#ifdef VERYDEBUG +#ifdef VERYDEBUG cprintf(GREEN,"copied frame\n"); - //#endif - -/* - for(j=0;jnum3)) != 0xFF){ - - while(!fifoFree[(j/(packetsPerFrame/2))]->push(&(wbuffer[j] - HEADER_SIZE_NUM_TOT_PACKETS))); - - //#ifdef FIFO_DEBUG - cprintf(GREEN,"%d writer freed pushed into fifofree %x for listener %d\n",ithread, (void*)(wbuffer[j]- HEADER_SIZE_NUM_TOT_PACKETS),(j/(packetsPerFrame/2))); - //#endif - }else cprintf(GREEN,"blank frame 0x%x\n",(void*)(wbuffer[j])); - } - - //#ifdef VERYDEBUG - cprintf(GREEN,"finished freeing\n"); - //#endif - */ - } - else{ +#endif + }else{ //copy to gui if(npackets >= packetsPerFrame){//min 1 frame, but neednt be //if(npackets == packetsPerFrame * numJobsPerThread){ //only full frames @@ -2843,11 +2853,14 @@ void UDPStandardImplementation::handleWithoutDataCompression(int ithread, char* #ifdef VERYVERBOSE cout << ithread << " finished copying" << endl; #endif - }//else cout << "unfinished buffersize" << endl; + } + /* freeing now done at function call + //else cout << "unfinished buffersize" << endl; while(!fifoFree[0]->push(wbuffer[0])); #ifdef FIFO_DEBUG cprintf(GREEN,"%d writer freed pushed into fifofree %x for listener 0\n",ithread, (void*)(wbuffer[0])); #endif + */ } } From d2f53aaf64f6f603307debf3d8145bc86e21aece Mon Sep 17 00:00:00 2001 From: Dhanya Maliakal Date: Fri, 7 Aug 2015 12:06:10 +0200 Subject: [PATCH 11/68] bugs --- .../src/UDPStandardImplementation.cpp | 206 ++++++++++++------ 1 file changed, 137 insertions(+), 69 deletions(-) diff --git a/slsReceiverSoftware/src/UDPStandardImplementation.cpp b/slsReceiverSoftware/src/UDPStandardImplementation.cpp index ff275d805..0f05e0678 100644 --- a/slsReceiverSoftware/src/UDPStandardImplementation.cpp +++ b/slsReceiverSoftware/src/UDPStandardImplementation.cpp @@ -1987,8 +1987,14 @@ int UDPStandardImplementation::startWriting(){ for(i=0;inum3)) = 0xFE; + + for(j=0;j<(onePacketSize-16);++j) + (*((uint8_t*)((char*)(blankframe[i])+8+j))) = 0xFF; + if ((*(uint8_t*)(((eiger_packet_header *)((char*)(blankframe[i])))->num3)) != 0xFE){ + cprintf(RED,"blank frame not detected at %d: 0x%x\n",i,(*(uint8_t*)(((eiger_packet_header *)((char*)(blankframe[i])))->num3)) ); + exit(-1); + } #ifdef FIFO_DEBUG cprintf(GREEN,"packet %d blank frame 0x%x\n",i,(void*)(blankframe[i])); #endif @@ -2036,12 +2042,14 @@ int UDPStandardImplementation::startWriting(){ //dont pop again if dummy packet if(!numpackets[i]){ popready[i] = false; -#ifdef EIGER_DEBUG3 +//#ifdef EIGER_DEBUG3 cprintf(RED,"%d Dummy frame popped out of fifo %d",ithread, i); -#endif +//#endif }else{ - tofree[tofreeoffset[i]] = wbuf[i]; - tofreeoffset[i]++; + if(myDetectorType == EIGER){ + tofree[tofreeoffset[i]] = wbuf[i]; + tofreeoffset[i]++; + } } } @@ -2051,21 +2059,24 @@ int UDPStandardImplementation::startWriting(){ //END OF ACQUISITION if((!numpackets[0])&& (!numpackets[1])){ -#ifdef VERYDEBUG +//#ifdef VERYDEBUG cprintf(GREEN,"%d Both dummy frames\n", ithread); -#endif +//#endif //remaning packets to be written if((myDetectorType == EIGER) && ((tempoffset[0]!=0) || (tempoffset[1]!=(packetsPerFrame/numListeningThreads)))){ -#ifdef EIGER_DEBUG3 +//#ifdef EIGER_DEBUG3 cprintf(RED,"**End of Acquisition but didnt get last packet\n"); -#endif +//#endif for(i=0;inum3)) == 0xFE) + cprintf(RED,"1 fifo:%d missing packet added at pnum:%d\n",i,tempoffset[i]); + else cprintf(RED, "1 fifo:%d WEird at pnum:%d\n",i,tempoffset[i]); tempoffset[i] ++; blankoffset ++; } @@ -2097,10 +2108,10 @@ int UDPStandardImplementation::startWriting(){ if((numpackets[i] != EIGER_HEADER_LENGTH) && (numpackets[i] != onePacketSize)){ if(numpackets[i]) cprintf(RED, "WARNING: Got a weird packet size: %d from fifo %d\n", numpackets[i],i); -#ifdef VERBOSE +//#ifdef VERBOSE else cprintf(RED, "WARNING: Dummy packet: %d from fifo %d\n", numpackets[i],i); -#endif +//#endif continue; } @@ -2119,23 +2130,29 @@ int UDPStandardImplementation::startWriting(){ //normal frame packet (also exception of tempnum 0 and currfnum 0) if((tempframenum[i] == (currframenum+1))||(!tempframenum[i] && !currframenum)){ -#ifdef EIGER_DEBUG3 +//#ifdef EIGER_DEBUG3 cprintf(GREEN,"**tempfraemnum of %d: %d\n",i,tempframenum[i]); -#endif +//#endif } //frame too far ahead else{ -#ifdef EIGER_DEBUG3 +//#ifdef EIGER_DEBUG3 cprintf(RED,"frame number too far ahead, missing packets\n"); -#endif +//#endif tempframenum[i] = currframenum + 1; //add missing packets numberofmissingpackets[i] = (LAST_PACKET_VALUE); + if(numberofmissingpackets[i]>0) + cprintf(BG_RED,"fifo:%d missing packet from: %d\n",i,lastpacketheader[i]); //to decrement from packetsInFile to calculate packet loss for(j=0;jnum3)) == 0xFE) + cprintf(RED,"2 fifo:%d missing packet added at pnum:%d\n",i,tempoffset[i]); + else cprintf(RED, "2 fifo:%d WEird at pnum:%d\n",i,tempoffset[i]); tempoffset[i] ++; blankoffset ++; + } //set fullframe and dont let fifo pop over it until written fullframe[i] = true; @@ -2144,14 +2161,19 @@ int UDPStandardImplementation::startWriting(){ } }//two image headers at a time = next frame, leave else{ -#ifdef EIGER_DEBUG3 +//#ifdef EIGER_DEBUG3 cprintf(RED,"received frame header twice, missing packets\n"); -#endif +//#endif //add missing packets numberofmissingpackets[i] = (LAST_PACKET_VALUE - lastpacketheader[i]); + if(numberofmissingpackets[i]>0) + cprintf(BG_RED,"fifo:%d missing packet from: %d\n",i,lastpacketheader[i]); //to decrement from packetsInFile to calculate packet loss for(j=0;jnum3)) == 0xFE) + cprintf(RED,"3 fifo:%d missing packet added at pnum:%d\n",i,tempoffset[i]); + else cprintf(RED, "3 fifo:%d WEird at pnum:%d\n",i,tempoffset[i]); tempoffset[i] ++; blankoffset ++; } @@ -2165,16 +2187,21 @@ int UDPStandardImplementation::startWriting(){ startdatapacket[i] = true; //update current packet currentpacketheader[i] = ((*(uint8_t*)(((eiger_packet_header *)((char*)(wbuf[i] + HEADER_SIZE_NUM_TOT_PACKETS)))->num4))); -#ifdef VERYVERBOSE - cprintf(GREEN,"**fifo:%d currentpacketheader: %d lastpacketheader %d\n",i,currentpacketheader[i],lastpacketheader[i]); -#endif +//#ifdef VERYVERBOSE + cprintf(GREEN,"**fifo:%d currentpacketheader: %d lastpacketheader %d tempoffset:%d\n",i,currentpacketheader[i],lastpacketheader[i], tempoffset[i]); +//#endif //same frame packet - continue building frame if(currentpacketheader[i] > lastpacketheader[i]){ //add missing packets numberofmissingpackets[i] = (currentpacketheader[i] - lastpacketheader[i] -1); + if(numberofmissingpackets[i]>0) + cprintf(BG_RED,"fifo:%d missing packet from: %d now at :%d tempoffset:%d\n",i,lastpacketheader[i],currentpacketheader[i],tempoffset[i]); //to decrement from packetsInFile to calculate packet loss for(j=0;jnum3)) == 0xFE) + cprintf(RED,"4 fifo:%d missing packet added at pnum:%d\n",i,tempoffset[i]); + else cprintf(RED, "4 fifo:%d WEird at pnum:%d\n",i,tempoffset[i]); tempoffset[i] ++; blankoffset ++; } @@ -2185,24 +2212,29 @@ int UDPStandardImplementation::startWriting(){ lastpacketheader[i] = currentpacketheader[i]; //last frame got, this will save time and also for last frames, it doesnt wait for stop receiver if(currentpacketheader[i] == LAST_PACKET_VALUE){ -#ifdef EIGER_DEBUG3 +//#ifdef EIGER_DEBUG3 cprintf(GREEN, "Got last packet\n"); -#endif +//#endif fullframe[i] = true; popready[i] = false; } } //next frame packet - leave else{ -#ifdef EIGER_DEBUG3 - cprintf(RED,"packet from next frame, missing packets"<0) + cprintf(BG_RED,"fifo:%d missing packet from: %d now at :%d\n",i,lastpacketheader[i],currentpacketheader[i]); //to decrement from packetsInFile to calculate packet loss for(j=0;jnum3)) == 0xFE) + cprintf(RED,"5 fifo:%d missing packet added at pnum:%d\n",i,tempoffset[i]); + else cprintf(RED, "5 fifo:%d WEird at pnum:%d\n",i,tempoffset[i]); tempoffset[i] ++; blankoffset ++; } @@ -2231,17 +2263,22 @@ int UDPStandardImplementation::startWriting(){ numMissingPackets += (numberofmissingpackets[0]+numberofmissingpackets[1]); numTotMissingPacketsInFile += numMissingPackets; -#ifdef EIGER_DEBUG2 - cprintf(GREEN,"%d **fnum:%d**\n",currframenum); -#endif -#ifdef EIGER_DEBUG3 +//#ifdef EIGER_DEBUG2 + cprintf(GREEN,"**fnum:%d**\n",currframenum); +//#endif +//#ifdef EIGER_DEBUG3 if(numberofmissingpackets[0]) - cprintf(RED, "fifo 0 missing packets:%d\n",numberofmissingpackets[0]); + cprintf(RED, "fifo 0 missing packets:%d fnum:%d\n",numberofmissingpackets[0],currframenum); if(numberofmissingpackets[1]) - cprintf(RED, "fifo 1 missing packets:%d\n",numberofmissingpackets[1]); - if(numMissingPackets) - cprintf(RED, "numMissingPackets:%d\n",numMissingPackets); -#endif + cprintf(RED, "fifo 1 missing packets:%d fnum:%d\n",numberofmissingpackets[1],currframenum); + if(numMissingPackets){ + cprintf(RED, "numMissingPackets:%d fnum:%d\n",numMissingPackets,currframenum); + + for (j=0;jnum3)) == 0xFE) + cprintf(RED,"found the missing packet at pnum:%d\n",j); + } +//#endif //write and copy to gui @@ -2264,9 +2301,9 @@ int UDPStandardImplementation::startWriting(){ -#ifdef VERYDEBUG +//#ifdef VERYDEBUG cprintf(GREEN,"finished freeing\n"); -#endif +//#endif //reset a few stuff for(int i=0;inum1)) = currframenum; - //overwriting port number and dynamic range - if (i<(packetsPerFrame/2)) - (*(uint8_t*)(((eiger_packet_header *)((char*)(wbuffer[i])))->num3)) = (dynamicRange<<2); - else - (*(uint8_t*)(((eiger_packet_header *)((char*)(wbuffer[i])))->num3)) = ((dynamicRange<<2)|(0x1)); -#ifdef VERYDEBUG - cprintf(GREEN, "%d - 0x%x - %d\n", i, - (*(uint8_t*)(((eiger_packet_header *)((char*)(wbuffer[i])))->num3)), - (*(uint8_t*)(((eiger_packet_header *)((char*)(wbuffer[i])))->num4))); -#endif + //which port + if (i ==(packetsPerFrame/2)) + port = 1; + //missing packet + if ((*(uint8_t*)(((eiger_packet_header *)((char*)(wbuffer[i])))->num3)) == 0xFE){ + missingpacket = 1; + //add packet numbers + (*(uint16_t*)(((eiger_packet_header *)((char*)(wbuffer[i])))->num2)) = (i+1); + }else{ + missingpacket = 0; - } - - //for 32 bit,port number needs to be changed and packet number reconstructed - if(dynamicRange == 32){ - for (i = 0; i < packetsPerFrame; i++){ - if( (i < (packetsPerFrame/4)) || ((i > (packetsPerFrame/2)) && (i < (3*packetsPerFrame/4))) ){ - //new packet number that has space for 16 bit + if(dynamicRange != 32){ + //move packet numbers to num2, and compensate for port1 starting pnum from 0 + if(!port) + (*(uint16_t*)(((eiger_packet_header *)((char*)(wbuffer[i])))->num2)) = + ((*(uint8_t*)(((eiger_packet_header *)((char*)(wbuffer[i])))->num4))+1); + else + (*(uint16_t*)(((eiger_packet_header *)((char*)(wbuffer[i])))->num2)) = + ((*(uint8_t*)(((eiger_packet_header *)((char*)(wbuffer[i])))->num4))+(packetsPerFrame/2) +1); + } + //dr == 32 + else{ + if(i == 0) + pnuminc = 0; + else if(i == (packetsPerFrame/4)) + pnuminc = (packetsPerFrame/4); + else if(i == (packetsPerFrame/2)) + pnuminc = (packetsPerFrame/2); + else if(i == (3*packetsPerFrame/4)) + pnuminc = (3*packetsPerFrame/4); (*(uint16_t*)(((eiger_packet_header *)((char*)(wbuffer[i])))->num2)) - = ((*(uint8_t*)(((eiger_packet_header *)((char*)(wbuffer[i])))->num4))); - }else{ - //new packet number that has space for 16 bit - (*(uint16_t*)(((eiger_packet_header *)((char*)(wbuffer[i])))->num2)) - = ((*(uint8_t*)(((eiger_packet_header *)((char*)(wbuffer[i])))->num4))+(packetsPerFrame/4)); + = ((*(uint8_t*)(((eiger_packet_header *)((char*)(wbuffer[i])))->num4))+pnuminc+1); } + } + + + if((*(uint16_t*)(((eiger_packet_header *)((char*)(wbuffer[i])))->num2)) != (i+1)){ + cprintf(BG_RED, "pnum mismatch! i:%d pnum:%d fnum:%d\n",i,(*(uint16_t*)(((eiger_packet_header *)((char*)(wbuffer[i])))->num2)),currframenum); + if ((*(uint8_t*)(((eiger_packet_header *)((char*)(wbuffer[i])))->num3)) == 0xFE) + cprintf(BG_RED,"missing packet though\n"); + exit(-1); + } + + //overwriting port number and dynamic range + (*(uint8_t*)(((eiger_packet_header *)((char*)(wbuffer[i])))->num3)) = + ((dynamicRange<<2)|(missingpacket<<1)|(port)); + + //frame number + (*(uint32_t*)(((eiger_packet_header *)((char*)(wbuffer[i])))->num1)) = currframenum; + #ifdef VERYDEBUG - cprintf(GREEN, "%d - 0x%x - %d - %d\n", i, - (*(uint8_t*)(((eiger_packet_header *)((char*)(wbuffer[i])))->num3)), - (*(uint8_t*)(((eiger_packet_header *)((char*)(wbuffer[i])))->num4)), - (*(uint16_t*)(((eiger_packet_header *)((char*)(wbuffer[i])))->num2))); + if((i==0)||(i==1)){ + cprintf(GREEN, "%d packet header:0x%016llx num3:0x%x\n",i, + ((uint64_t)(*((uint64_t*)(wbuffer[i])))), + (uint8_t)(*(uint8_t*)(((eiger_packet_header *)((char*)(wbuffer[i])))->num3))); + } + cprintf(GREEN, "%d - 0x%x - %d - %d\n", i, + (*(uint8_t*)(((eiger_packet_header *)((char*)(wbuffer[i])))->num3)), + (*(uint8_t*)(((eiger_packet_header *)((char*)(wbuffer[i])))->num4)), + (*(uint16_t*)(((eiger_packet_header *)((char*)(wbuffer[i])))->num2))); #endif - } + + } } #endif @@ -2855,13 +2923,13 @@ void UDPStandardImplementation::handleWithoutDataCompression(int ithread, char* cout << ithread << " finished copying" << endl; #endif } - /* freeing now done at function call + //else cout << "unfinished buffersize" << endl; while(!fifoFree[0]->push(wbuffer[0])); #ifdef FIFO_DEBUG cprintf(GREEN,"%d writer freed pushed into fifofree %x for listener 0\n",ithread, (void*)(wbuffer[0])); #endif - */ + } } From 0a24778ff8f4629bb6dd564e13006989dc573d93 Mon Sep 17 00:00:00 2001 From: Dhanya Maliakal Date: Mon, 10 Aug 2015 14:45:43 +0200 Subject: [PATCH 12/68] missing packets should work now --- .../include/UDPBaseImplementation.h | 5 +- .../src/UDPStandardImplementation.cpp | 89 ++++++++++++------- 2 files changed, 60 insertions(+), 34 deletions(-) diff --git a/slsReceiverSoftware/include/UDPBaseImplementation.h b/slsReceiverSoftware/include/UDPBaseImplementation.h index 4e29e0bc6..05b992975 100644 --- a/slsReceiverSoftware/include/UDPBaseImplementation.h +++ b/slsReceiverSoftware/include/UDPBaseImplementation.h @@ -575,10 +575,13 @@ protected: /** Pckets currently in current file, starts new file when it reaches max */ uint32_t packetsInFile; + /** Number of missing packets in acquisition*/ + uint32_t numTotMissingPackets; + /** Number of missing packets in file (sometimes packetsinFile is incorrect due to padded packets for eiger)*/ uint32_t numTotMissingPacketsInFile; - /** Number of missing packets in an acquisition(sometimes packetsinFile is incorrect due to padded packets for eiger)*/ + /** Number of missing packets per buffer*/ uint32_t numMissingPackets; /** Frame index at start of an entire acquisition (including all scans) */ diff --git a/slsReceiverSoftware/src/UDPStandardImplementation.cpp b/slsReceiverSoftware/src/UDPStandardImplementation.cpp index 0f05e0678..87fc042e0 100644 --- a/slsReceiverSoftware/src/UDPStandardImplementation.cpp +++ b/slsReceiverSoftware/src/UDPStandardImplementation.cpp @@ -122,6 +122,7 @@ void UDPStandardImplementation::initializeMembers(){ packetsCaught = 0; totalPacketsCaught = 0; packetsInFile = 0; + numTotMissingPackets = 0; numTotMissingPacketsInFile = 0; numMissingPackets = 0; startAcquisitionIndex = 0; @@ -861,8 +862,9 @@ void UDPStandardImplementation::setupFifoStructure(){ cout << "1 packet per buffer" << endl; else cout << "Number of Frames per buffer:" << numJobsPerThread << endl; +#ifdef VERBOSE cout << "Fifo Size:" << fifosize << endl; - +#endif /* //for testing numJobsPerThread = 3; fifosize = 11; @@ -1279,6 +1281,7 @@ int UDPStandardImplementation::setupWriter(){ //reset writing thread variables packetsInFile=0; + numTotMissingPackets = 0; numTotMissingPacketsInFile = 0; numMissingPackets = 0; packetsCaught=0; @@ -2042,9 +2045,9 @@ int UDPStandardImplementation::startWriting(){ //dont pop again if dummy packet if(!numpackets[i]){ popready[i] = false; -//#ifdef EIGER_DEBUG3 - cprintf(RED,"%d Dummy frame popped out of fifo %d",ithread, i); -//#endif +#ifdef EIGER_DEBUG3 + cprintf(GREEN,"%d Dummy frame popped out of fifo %d",ithread, i); +#endif }else{ if(myDetectorType == EIGER){ tofree[tofreeoffset[i]] = wbuf[i]; @@ -2059,24 +2062,26 @@ int UDPStandardImplementation::startWriting(){ //END OF ACQUISITION if((!numpackets[0])&& (!numpackets[1])){ -//#ifdef VERYDEBUG +#ifdef VERYDEBUG cprintf(GREEN,"%d Both dummy frames\n", ithread); -//#endif +#endif //remaning packets to be written if((myDetectorType == EIGER) && ((tempoffset[0]!=0) || (tempoffset[1]!=(packetsPerFrame/numListeningThreads)))){ -//#ifdef EIGER_DEBUG3 +#ifdef EIGER_DEBUG3 cprintf(RED,"**End of Acquisition but didnt get last packet\n"); -//#endif +#endif for(i=0;inum3)) == 0xFE) cprintf(RED,"1 fifo:%d missing packet added at pnum:%d\n",i,tempoffset[i]); - else cprintf(RED, "1 fifo:%d WEird at pnum:%d\n",i,tempoffset[i]); + else cprintf(RED, "1 fifo:%d Weird at pnum:%d\n",i,tempoffset[i]); +#endif tempoffset[i] ++; blankoffset ++; } @@ -2106,12 +2111,12 @@ int UDPStandardImplementation::startWriting(){ //offset outside boundaries, also eliminates dummy packet if((numpackets[i] != EIGER_HEADER_LENGTH) && (numpackets[i] != onePacketSize)){ +#ifdef EIGER_DEBUG3 if(numpackets[i]) cprintf(RED, "WARNING: Got a weird packet size: %d from fifo %d\n", numpackets[i],i); -//#ifdef VERBOSE else cprintf(RED, "WARNING: Dummy packet: %d from fifo %d\n", numpackets[i],i); -//#endif +#endif continue; } @@ -2130,26 +2135,30 @@ int UDPStandardImplementation::startWriting(){ //normal frame packet (also exception of tempnum 0 and currfnum 0) if((tempframenum[i] == (currframenum+1))||(!tempframenum[i] && !currframenum)){ -//#ifdef EIGER_DEBUG3 +#ifdef EIGER_DEBUG3 cprintf(GREEN,"**tempfraemnum of %d: %d\n",i,tempframenum[i]); -//#endif +#endif } //frame too far ahead else{ -//#ifdef EIGER_DEBUG3 +#ifdef EIGER_DEBUG3 cprintf(RED,"frame number too far ahead, missing packets\n"); -//#endif +#endif tempframenum[i] = currframenum + 1; //add missing packets numberofmissingpackets[i] = (LAST_PACKET_VALUE); +#ifdef VERYDEBUG if(numberofmissingpackets[i]>0) cprintf(BG_RED,"fifo:%d missing packet from: %d\n",i,lastpacketheader[i]); +#endif //to decrement from packetsInFile to calculate packet loss for(j=0;jnum3)) == 0xFE) cprintf(RED,"2 fifo:%d missing packet added at pnum:%d\n",i,tempoffset[i]); else cprintf(RED, "2 fifo:%d WEird at pnum:%d\n",i,tempoffset[i]); +#endif tempoffset[i] ++; blankoffset ++; @@ -2161,19 +2170,23 @@ int UDPStandardImplementation::startWriting(){ } }//two image headers at a time = next frame, leave else{ -//#ifdef EIGER_DEBUG3 +#ifdef EIGER_DEBUG3 cprintf(RED,"received frame header twice, missing packets\n"); -//#endif +#endif //add missing packets numberofmissingpackets[i] = (LAST_PACKET_VALUE - lastpacketheader[i]); +#ifdef VERYDEBUG if(numberofmissingpackets[i]>0) cprintf(BG_RED,"fifo:%d missing packet from: %d\n",i,lastpacketheader[i]); +#endif //to decrement from packetsInFile to calculate packet loss for(j=0;jnum3)) == 0xFE) cprintf(RED,"3 fifo:%d missing packet added at pnum:%d\n",i,tempoffset[i]); else cprintf(RED, "3 fifo:%d WEird at pnum:%d\n",i,tempoffset[i]); +#endif tempoffset[i] ++; blankoffset ++; } @@ -2187,21 +2200,25 @@ int UDPStandardImplementation::startWriting(){ startdatapacket[i] = true; //update current packet currentpacketheader[i] = ((*(uint8_t*)(((eiger_packet_header *)((char*)(wbuf[i] + HEADER_SIZE_NUM_TOT_PACKETS)))->num4))); -//#ifdef VERYVERBOSE +#ifdef VERYVERBOSE cprintf(GREEN,"**fifo:%d currentpacketheader: %d lastpacketheader %d tempoffset:%d\n",i,currentpacketheader[i],lastpacketheader[i], tempoffset[i]); -//#endif +#endif //same frame packet - continue building frame if(currentpacketheader[i] > lastpacketheader[i]){ //add missing packets numberofmissingpackets[i] = (currentpacketheader[i] - lastpacketheader[i] -1); +#ifdef VERYDEBUG if(numberofmissingpackets[i]>0) cprintf(BG_RED,"fifo:%d missing packet from: %d now at :%d tempoffset:%d\n",i,lastpacketheader[i],currentpacketheader[i],tempoffset[i]); +#endif //to decrement from packetsInFile to calculate packet loss for(j=0;jnum3)) == 0xFE) cprintf(RED,"4 fifo:%d missing packet added at pnum:%d\n",i,tempoffset[i]); else cprintf(RED, "4 fifo:%d WEird at pnum:%d\n",i,tempoffset[i]); +#endif tempoffset[i] ++; blankoffset ++; } @@ -2212,29 +2229,33 @@ int UDPStandardImplementation::startWriting(){ lastpacketheader[i] = currentpacketheader[i]; //last frame got, this will save time and also for last frames, it doesnt wait for stop receiver if(currentpacketheader[i] == LAST_PACKET_VALUE){ -//#ifdef EIGER_DEBUG3 +#ifdef EIGER_DEBUG3 cprintf(GREEN, "Got last packet\n"); -//#endif +#endif fullframe[i] = true; popready[i] = false; } } //next frame packet - leave else{ -//#ifdef EIGER_DEBUG3 +#ifdef EIGER_DEBUG3 cprintf(RED,"packet from next frame, missing packets\n"); -//#endif +#endif //add missing packets numberofmissingpackets[i] = (LAST_PACKET_VALUE - lastpacketheader[i]); +#ifdef VERYDEBUG if(numberofmissingpackets[i]>0) cprintf(BG_RED,"fifo:%d missing packet from: %d now at :%d\n",i,lastpacketheader[i],currentpacketheader[i]); +#endif //to decrement from packetsInFile to calculate packet loss for(j=0;jnum3)) == 0xFE) cprintf(RED,"5 fifo:%d missing packet added at pnum:%d\n",i,tempoffset[i]); else cprintf(RED, "5 fifo:%d WEird at pnum:%d\n",i,tempoffset[i]); +#endif tempoffset[i] ++; blankoffset ++; } @@ -2262,11 +2283,11 @@ int UDPStandardImplementation::startWriting(){ tempframenum[1]++; numMissingPackets += (numberofmissingpackets[0]+numberofmissingpackets[1]); numTotMissingPacketsInFile += numMissingPackets; - -//#ifdef EIGER_DEBUG2 + numTotMissingPackets += numMissingPackets; +#ifdef EIGER_DEBUG2 cprintf(GREEN,"**fnum:%d**\n",currframenum); -//#endif -//#ifdef EIGER_DEBUG3 +#endif +#ifdef EIGER_DEBUG3 if(numberofmissingpackets[0]) cprintf(RED, "fifo 0 missing packets:%d fnum:%d\n",numberofmissingpackets[0],currframenum); if(numberofmissingpackets[1]) @@ -2278,7 +2299,7 @@ int UDPStandardImplementation::startWriting(){ if ((*(uint8_t*)(((eiger_packet_header *)((char*)(tempbuffer[j])))->num3)) == 0xFE) cprintf(RED,"found the missing packet at pnum:%d\n",j); } -//#endif +#endif //write and copy to gui @@ -2301,9 +2322,9 @@ int UDPStandardImplementation::startWriting(){ -//#ifdef VERYDEBUG +#ifdef VERYDEBUG cprintf(GREEN,"finished freeing\n"); -//#endif +#endif //reset a few stuff for(int i=0;i= 0){ @@ -3062,13 +3085,13 @@ int UDPStandardImplementation::enableTenGiga(int enable){ bufferSize = (frameSize/EIGER_MAX_PORTS) + EIGER_HEADER_LENGTH;//everything one port gets (img header plus packets) maxPacketsPerFile = EIGER_MAX_FRAMES_PER_FILE * packetsPerFrame; - +#ifdef VERBOSE cout<<"packetsPerFrame:"< Date: Thu, 13 Aug 2015 14:46:57 +0200 Subject: [PATCH 13/68] need to chek --- .../src/UDPStandardImplementation.cpp | 377 +++++++++--------- 1 file changed, 198 insertions(+), 179 deletions(-) diff --git a/slsReceiverSoftware/src/UDPStandardImplementation.cpp b/slsReceiverSoftware/src/UDPStandardImplementation.cpp index 87fc042e0..374322684 100644 --- a/slsReceiverSoftware/src/UDPStandardImplementation.cpp +++ b/slsReceiverSoftware/src/UDPStandardImplementation.cpp @@ -1702,7 +1702,7 @@ int UDPStandardImplementation::startListening(){ uint32_t lastframeheader;// for moench to check for all the packets in last frame char* tempchar = NULL; - + uint32_t prenum=0; while(1){ @@ -1720,7 +1720,7 @@ int UDPStandardImplementation::startListening(){ else maxBufferSize = 0; - + prenum=0; while((1<ReceiveDataOnly(buffer[ithread] + HEADER_SIZE_NUM_TOT_PACKETS, maxBufferSize); + if(rc == 1040){ + cprintf(YELLOW,"tempframenum[%d]:%d\n",ithread,((*(uint32_t*)(((eiger_packet_header *)((char*)(buffer[ithread] + HEADER_SIZE_NUM_TOT_PACKETS)))->num1)))); + cprintf(YELLOW,"packetnum[%d]:%d\n",ithread,((*(uint8_t*)(((eiger_packet_header *)((char*)(buffer[ithread] + HEADER_SIZE_NUM_TOT_PACKETS)))->num4)))); + + if(((*(uint32_t*)(((eiger_packet_header *)((char*)(buffer[ithread] + HEADER_SIZE_NUM_TOT_PACKETS)))->num1)))< prenum){ + cprintf(BG_RED, "framenumber weird:previous:%d\n",prenum); + exit(-1); + } + prenum = ((*(uint32_t*)(((eiger_packet_header *)((char*)(buffer[ithread] + HEADER_SIZE_NUM_TOT_PACKETS)))->num1))); + + } expected = maxBufferSize; #ifdef SOCKET_DEBUG }else{ @@ -1782,7 +1793,8 @@ int UDPStandardImplementation::startListening(){ //start indices for each start of scan/acquisition if((!measurementStarted) && (rc > 0)){ pthread_mutex_lock(&progress_mutex); - startFrameIndices(ithread, rc); + if(!measurementStarted) + startFrameIndices(ithread, rc); pthread_mutex_unlock(&progress_mutex); } @@ -1931,8 +1943,9 @@ int UDPStandardImplementation::startWriting(){ int xmax=0,ymax=0; int ret,i,j; + bool endofacquisition; int numpackets[numListeningThreads], nf; - bool startdatapacket[numListeningThreads],fullframe[numListeningThreads],popready[numListeningThreads]; + bool fullframe[numListeningThreads],popready[numListeningThreads]; uint32_t tempframenum[numListeningThreads]; int lastpacketheader[numListeningThreads], currentpacketheader[numListeningThreads]; int numberofmissingpackets[numListeningThreads]; @@ -1990,11 +2003,11 @@ int UDPStandardImplementation::startWriting(){ for(i=0;inum3)) = 0xFE; + (*(uint8_t*)(((eiger_packet_header *)((char*)(blankframe[i])))->num3)) = 0xFF; for(j=0;j<(onePacketSize-16);++j) (*((uint8_t*)((char*)(blankframe[i])+8+j))) = 0xFF; - if ((*(uint8_t*)(((eiger_packet_header *)((char*)(blankframe[i])))->num3)) != 0xFE){ + if ((*(uint8_t*)(((eiger_packet_header *)((char*)(blankframe[i])))->num3)) != 0xFF){ cprintf(RED,"blank frame not detected at %d: 0x%x\n",i,(*(uint8_t*)(((eiger_packet_header *)((char*)(blankframe[i])))->num3)) ); exit(-1); } @@ -2009,7 +2022,6 @@ int UDPStandardImplementation::startWriting(){ for(i=0;inum1)))); + cprintf(BLUE,"packetnum[%d]:%d\n",i,((*(uint8_t*)(((eiger_packet_header *)((char*)(wbuf[i] + HEADER_SIZE_NUM_TOT_PACKETS)))->num4)))); + + + }if(myDetectorType == EIGER){ tofree[tofreeoffset[i]] = wbuf[i]; tofreeoffset[i]++; } @@ -2061,36 +2080,15 @@ int UDPStandardImplementation::startWriting(){ //END OF ACQUISITION - if((!numpackets[0])&& (!numpackets[1])){ -#ifdef VERYDEBUG + if(endofacquisition){ +//#ifdef VERYDEBUG cprintf(GREEN,"%d Both dummy frames\n", ithread); -#endif - //remaning packets to be written +//#endif + //remaining packets to be written if((myDetectorType == EIGER) && - ((tempoffset[0]!=0) || (tempoffset[1]!=(packetsPerFrame/numListeningThreads)))){ -#ifdef EIGER_DEBUG3 - cprintf(RED,"**End of Acquisition but didnt get last packet\n"); -#endif - for(i=0;inum3)) == 0xFE) - cprintf(RED,"1 fifo:%d missing packet added at pnum:%d\n",i,tempoffset[i]); - else cprintf(RED, "1 fifo:%d Weird at pnum:%d\n",i,tempoffset[i]); -#endif - tempoffset[i] ++; - blankoffset ++; - } - //set fullframe and dont let fifo pop over it until written - fullframe[i] = true; - popready[i] = false; + ((tempoffset[0]!=0) || (tempoffset[1]!=(packetsPerFrame/numListeningThreads)))); + else{ - } - }else{ stopWriting(ithread,wbuf); continue; } @@ -2098,95 +2096,48 @@ int UDPStandardImplementation::startWriting(){ - - if(myDetectorType == EIGER){ - //trying to find a full frame + //NOT FULL FRAME if(!fullframe[0] || !fullframe[1]){ - - for(i=0;iheader_confirm))){ - - //new frame (no datapacket received yet), update frame num and corrected for fnum reset for scans - if(!startdatapacket[i]){ - tempframenum[i] = (htonl(*(unsigned int*)((eiger_image_header *)((char*)(wbuf[i] + HEADER_SIZE_NUM_TOT_PACKETS)))->fnum)); - if(!tempframenum[i]) - cprintf(RED,"**VERY WEIRD frame numbers for fifo %d: %d\n",i,tempframenum[i]); - tempframenum[i] += (startFrameIndex-1); - - //normal frame packet (also exception of tempnum 0 and currfnum 0) - if((tempframenum[i] == (currframenum+1))||(!tempframenum[i] && !currframenum)){ -#ifdef EIGER_DEBUG3 - cprintf(GREEN,"**tempfraemnum of %d: %d\n",i,tempframenum[i]); -#endif - } - //frame too far ahead - else{ -#ifdef EIGER_DEBUG3 - cprintf(RED,"frame number too far ahead, missing packets\n"); -#endif - tempframenum[i] = currframenum + 1; - //add missing packets - numberofmissingpackets[i] = (LAST_PACKET_VALUE); -#ifdef VERYDEBUG - if(numberofmissingpackets[i]>0) - cprintf(BG_RED,"fifo:%d missing packet from: %d\n",i,lastpacketheader[i]); -#endif - //to decrement from packetsInFile to calculate packet loss - for(j=0;jnum3)) == 0xFE) - cprintf(RED,"2 fifo:%d missing packet added at pnum:%d\n",i,tempoffset[i]); - else cprintf(RED, "2 fifo:%d WEird at pnum:%d\n",i,tempoffset[i]); -#endif - tempoffset[i] ++; - blankoffset ++; - - } - //set fullframe and dont let fifo pop over it until written - fullframe[i] = true; - popready[i] = false; - - } - }//two image headers at a time = next frame, leave - else{ -#ifdef EIGER_DEBUG3 - cprintf(RED,"received frame header twice, missing packets\n"); -#endif + //anything that is not a data packet of right size + if(numpackets[i] != onePacketSize){ + //header packet + if(numpackets[i] == EIGER_HEADER_LENGTH) continue; + //dummy packet + else if(!numpackets[i]){ +//#ifdef VERYDEBUG + cprintf(RED, "Dummy packet: %d from fifo %d\n", numpackets[i],i); +//#endif + cout<<"tempoffset["<0) - cprintf(BG_RED,"fifo:%d missing packet from: %d\n",i,lastpacketheader[i]); -#endif //to decrement from packetsInFile to calculate packet loss for(j=0;jnum3)) == 0xFE) - cprintf(RED,"3 fifo:%d missing packet added at pnum:%d\n",i,tempoffset[i]); - else cprintf(RED, "3 fifo:%d WEird at pnum:%d\n",i,tempoffset[i]); + if ((*(uint8_t*)(((eiger_packet_header *)((char*)(tempbuffer[tempoffset[i]])))->num3)) == 0xFF) + cprintf(RED,"1 fifo:%d missing packet added at pnum:%d\n",i,tempoffset[i]); + else cprintf(RED, "1 fifo:%d Weird at pnum:%d\n",i,tempoffset[i]); #endif + if ((*(uint8_t*)(((eiger_packet_header *)((char*)(tempbuffer[tempoffset[i]])))->num3)) != 0xFF){ + cprintf(BG_RED, "pnum mismatch num4 earlier2! i:%d pnum:%d fnum:%d num3:0x%x actual num3:0x%x\n", + i,tempoffset[i],tempframenum[i], + (*(uint8_t*)(((eiger_packet_header *)((char*)(tempbuffer[tempoffset[i]])))->num3)), + (*(uint8_t*)(((eiger_packet_header *)((char*)(blankframe[blankoffset])))->num3))); + exit(-1); + }else + cprintf(GREEN, "blank packet i:%d pnum:%d fnum:%d num3:0x%x\n",i,tempoffset[i],tempframenum[i],(*(uint8_t*)(((eiger_packet_header *)((char*)(tempbuffer[tempoffset[i]])))->num3))); + tempoffset[i] ++; blankoffset ++; } @@ -2195,83 +2146,142 @@ int UDPStandardImplementation::startWriting(){ popready[i] = false; } } - //DATA PACKET +//#ifdef EIGER_DEBUG3 else{ - startdatapacket[i] = true; - //update current packet - currentpacketheader[i] = ((*(uint8_t*)(((eiger_packet_header *)((char*)(wbuf[i] + HEADER_SIZE_NUM_TOT_PACKETS)))->num4))); -#ifdef VERYVERBOSE - cprintf(GREEN,"**fifo:%d currentpacketheader: %d lastpacketheader %d tempoffset:%d\n",i,currentpacketheader[i],lastpacketheader[i], tempoffset[i]); -#endif - //same frame packet - continue building frame - if(currentpacketheader[i] > lastpacketheader[i]){ - //add missing packets - numberofmissingpackets[i] = (currentpacketheader[i] - lastpacketheader[i] -1); -#ifdef VERYDEBUG - if(numberofmissingpackets[i]>0) - cprintf(BG_RED,"fifo:%d missing packet from: %d now at :%d tempoffset:%d\n",i,lastpacketheader[i],currentpacketheader[i],tempoffset[i]); -#endif - //to decrement from packetsInFile to calculate packet loss - for(j=0;jnum3)) == 0xFE) - cprintf(RED,"4 fifo:%d missing packet added at pnum:%d\n",i,tempoffset[i]); - else cprintf(RED, "4 fifo:%d WEird at pnum:%d\n",i,tempoffset[i]); -#endif - tempoffset[i] ++; - blankoffset ++; - } - //add current packet - tempbuffer[tempoffset[i]] = wbuf[i] + HEADER_SIZE_NUM_TOT_PACKETS; - tempoffset[i] ++; - //update last packet - lastpacketheader[i] = currentpacketheader[i]; - //last frame got, this will save time and also for last frames, it doesnt wait for stop receiver - if(currentpacketheader[i] == LAST_PACKET_VALUE){ -#ifdef EIGER_DEBUG3 - cprintf(GREEN, "Got last packet\n"); -#endif - fullframe[i] = true; - popready[i] = false; - } - } - //next frame packet - leave - else{ -#ifdef EIGER_DEBUG3 - cprintf(RED,"packet from next frame, missing packets\n"); -#endif + cprintf(RED, "WARNING: Got a weird packet size: %d from fifo %d\n", numpackets[i],i); + continue; + } +//#endif + } + + + + + //not a full frame + if(!fullframe[i]){ + + //update frame number + //tempframenum[i] = (htonl(*(uint32_t*)(((eiger_packet_header *)((char*)(wbuf[i] + HEADER_SIZE_NUM_TOT_PACKETS)))->num1))); + tempframenum[i] = ((*(uint32_t*)(((eiger_packet_header *)((char*)(wbuf[i] + HEADER_SIZE_NUM_TOT_PACKETS)))->num1))); + + + if(!tempframenum[i]) + cprintf(RED,"**VERY WEIRD frame numbers for fifo %d: %d\n",i,tempframenum[i]); + tempframenum[i] += (startFrameIndex-1); + + + //WRONG FRAME - leave (also includes exception of tempnum 0 and currfnum 0) + if((tempframenum[i] != (currframenum+1))&&(tempframenum[i] || currframenum)){cout<<"wrong packet"<num1))), + ((*(uint8_t*)(((eiger_packet_header *)((char*)(wbuf[i] + HEADER_SIZE_NUM_TOT_PACKETS)))->num4)))); +//#endif + tempframenum[i] = currframenum+1; //add missing packets numberofmissingpackets[i] = (LAST_PACKET_VALUE - lastpacketheader[i]); #ifdef VERYDEBUG if(numberofmissingpackets[i]>0) - cprintf(BG_RED,"fifo:%d missing packet from: %d now at :%d\n",i,lastpacketheader[i],currentpacketheader[i]); + cprintf(BG_RED,"fifo:%d missing packet from: %d now\n",i,lastpacketheader[i]); #endif //to decrement from packetsInFile to calculate packet loss for(j=0;jnum3)) == 0xFE) + if ((*(uint8_t*)(((eiger_packet_header *)((char*)(tempbuffer[tempoffset[i]])))->num3)) == 0xFF) cprintf(RED,"5 fifo:%d missing packet added at pnum:%d\n",i,tempoffset[i]); else cprintf(RED, "5 fifo:%d WEird at pnum:%d\n",i,tempoffset[i]); #endif + if ((*(uint8_t*)(((eiger_packet_header *)((char*)(tempbuffer[tempoffset[i]])))->num3)) != 0xFF){ + cprintf(BG_RED, "pnum mismatch num4 earlier2! i:%d pnum:%d fnum:%d num3:0x%x actual num3:0x%x\n", + i,tempoffset[i],tempframenum[i], + (*(uint8_t*)(((eiger_packet_header *)((char*)(tempbuffer[tempoffset[i]])))->num3)), + (*(uint8_t*)(((eiger_packet_header *)((char*)(blankframe[blankoffset])))->num3))); + exit(-1); + }else + cprintf(GREEN, "blank packet i:%d pnum:%d fnum:%d num3:0x%x\n",i,tempoffset[i],tempframenum[i],(*(uint8_t*)(((eiger_packet_header *)((char*)(tempbuffer[tempoffset[i]])))->num3))); + tempoffset[i] ++; blankoffset ++; } //set fullframe and dont let fifo pop over it until written fullframe[i] = true; popready[i] = false; + } + + + //CORRECT FRAME - continue building frame + else {cout<<"correct packet"<num4))); +//#ifdef VERYVERBOSE + cprintf(GREEN,"**fifo:%d currentpacketheader: %d lastpacketheader %d tempoffset:%d\n",i,currentpacketheader[i],lastpacketheader[i], tempoffset[i]); +//#endif + //add missing packets + numberofmissingpackets[i] = (currentpacketheader[i] - lastpacketheader[i] -1); +#ifdef VERYDEBUG + if(numberofmissingpackets[i]>0) + cprintf(BG_RED,"fifo:%d missing packet from: %d now at :%d tempoffset:%d\n",i,lastpacketheader[i],currentpacketheader[i],tempoffset[i]); +#endif + //to decrement from packetsInFile to calculate packet loss + for(j=0;jnum3)) == 0xFF) + cprintf(RED,"4 fifo:%d missing packet added at pnum:%d\n",i,tempoffset[i]); + else cprintf(RED, "4 fifo:%d WEird at pnum:%d\n",i,tempoffset[i]); +#endif + if ((*(uint8_t*)(((eiger_packet_header *)((char*)(tempbuffer[tempoffset[i]])))->num3)) != 0xFF){ + cprintf(BG_RED, "pnum mismatch num4 earlier2! i:%d pnum:%d fnum:%d num3:0x%x actual num3:0x%x\n", + i,tempoffset[i],tempframenum[i], + (*(uint8_t*)(((eiger_packet_header *)((char*)(tempbuffer[tempoffset[i]])))->num3)), + (*(uint8_t*)(((eiger_packet_header *)((char*)(blankframe[blankoffset])))->num3))); + exit(-1); + }else + cprintf(GREEN, "blank packet i:%d pnum:%d fnum:%d num3:0x%x\n",i,tempoffset[i],tempframenum[i],(*(uint8_t*)(((eiger_packet_header *)((char*)(tempbuffer[tempoffset[i]])))->num3))); + tempoffset[i] ++; + blankoffset ++; + } + //add current packet + + if(currentpacketheader[i] != (tempoffset[i]-(i*packetsPerFrame/numListeningThreads))){ + cprintf(BG_RED, "pnum mismatch earlier! tempoffset[%d]:%d pnum:%d fnum:%d\n",i,tempoffset[i],currentpacketheader[i],tempframenum[i]); + exit(-1); + } + tempbuffer[tempoffset[i]] = wbuf[i] + HEADER_SIZE_NUM_TOT_PACKETS; +#ifdef EIGER_DEBUG3 + cprintf(GREEN,"**fifo:%d currentpacketheader: %d tempoffset:%d\n",i,(*(uint8_t*)(((eiger_packet_header *)((char*)(tempbuffer[tempoffset[i]])))->num4)),tempoffset[i]); +#endif + if((*(uint8_t*)(((eiger_packet_header *)((char*)(tempbuffer[tempoffset[i]])))->num4)) != (tempoffset[i]-(i*packetsPerFrame/numListeningThreads))){ + cprintf(BG_RED, "pnum mismatch num4 earlier! i:%d pnum:%d fnum:%d\n",i,(*(uint8_t*)(((eiger_packet_header *)((char*)(tempbuffer[tempoffset[i]])))->num4)),tempframenum[i]); + exit(-1); + } + cprintf(GREEN, "normal packet i:%d pnum:%d fnum:%d num3:0x%x\n",i,tempoffset[i],tempframenum[i],(*(uint8_t*)(((eiger_packet_header *)((char*)(tempbuffer[tempoffset[i]])))->num3))); + tempoffset[i] ++; + //update last packet + lastpacketheader[i] = currentpacketheader[i]; + popready[i] = true; + //last frame got, this will save time and also for last frames, it doesnt wait for stop receiver + if(currentpacketheader[i] == LAST_PACKET_VALUE){ +#ifdef EIGER_DEBUG3 + cprintf(GREEN, "Got last packet\n"); +#endif + fullframe[i] = true; + popready[i] = false; } } } - } } - //check if a full frame received + //FULL FRAME if(fullframe[0] && fullframe[1]){ //determine frame number @@ -2284,9 +2294,9 @@ int UDPStandardImplementation::startWriting(){ numMissingPackets += (numberofmissingpackets[0]+numberofmissingpackets[1]); numTotMissingPacketsInFile += numMissingPackets; numTotMissingPackets += numMissingPackets; -#ifdef EIGER_DEBUG2 - cprintf(GREEN,"**fnum:%d**\n",currframenum); -#endif +//#ifdef EIGER_DEBUG2 + cprintf(GREEN,"**fnum:%d**\n",currframenum); +//#endif #ifdef EIGER_DEBUG3 if(numberofmissingpackets[0]) cprintf(RED, "fifo 0 missing packets:%d fnum:%d\n",numberofmissingpackets[0],currframenum); @@ -2296,7 +2306,7 @@ int UDPStandardImplementation::startWriting(){ cprintf(RED, "numMissingPackets:%d fnum:%d\n",numMissingPackets,currframenum); for (j=0;jnum3)) == 0xFE) + if ((*(uint8_t*)(((eiger_packet_header *)((char*)(tempbuffer[j])))->num3)) == 0xFF) cprintf(RED,"found the missing packet at pnum:%d\n",j); } #endif @@ -2319,12 +2329,10 @@ int UDPStandardImplementation::startWriting(){ cprintf(GREEN,"%d writer freed pushed into fifofree %x for listener %d\n",ithread, (void*)(tofree[j]),1); #endif } - - - -#ifdef VERYDEBUG +//#ifdef VERYDEBUG cprintf(GREEN,"finished freeing\n"); -#endif +//#endif + //reset a few stuff for(int i=0;ifnum))-1; //missed header packet, so default value else - startFrameIndex = 0; + startFrameIndex = ((*(uint32_t*)(((eiger_packet_header *)((char*)(buffer[ithread] + HEADER_SIZE_NUM_TOT_PACKETS)))->num1))-1); + cout<<"startFrameIndex["<push(wbuffer[i])); @@ -2853,14 +2862,23 @@ void UDPStandardImplementation::handleWithoutDataCompression(int ithread, char* //which port if (i ==(packetsPerFrame/2)) port = 1; + + + //missing packet - if ((*(uint8_t*)(((eiger_packet_header *)((char*)(wbuffer[i])))->num3)) == 0xFE){ + if ((*(uint8_t*)(((eiger_packet_header *)((char*)(wbuffer[i])))->num3)) == 0xFF){ missingpacket = 1; //add packet numbers (*(uint16_t*)(((eiger_packet_header *)((char*)(wbuffer[i])))->num2)) = (i+1); }else{ missingpacket = 0; + if((*(uint8_t*)(((eiger_packet_header *)((char*)(wbuffer[i])))->num4)) != (i-(port*packetsPerFrame/numListeningThreads))){ + cprintf(BG_RED, "pnum mismatch num4! i:%d pnum:%d fnum:%d\n",i,(*(uint8_t*)(((eiger_packet_header *)((char*)(wbuffer[i])))->num4)),currframenum); + exit(-1); + } + + if(dynamicRange != 32){ //move packet numbers to num2, and compensate for port1 starting pnum from 0 if(!port) @@ -2889,7 +2907,7 @@ void UDPStandardImplementation::handleWithoutDataCompression(int ithread, char* if((*(uint16_t*)(((eiger_packet_header *)((char*)(wbuffer[i])))->num2)) != (i+1)){ cprintf(BG_RED, "pnum mismatch! i:%d pnum:%d fnum:%d\n",i,(*(uint16_t*)(((eiger_packet_header *)((char*)(wbuffer[i])))->num2)),currframenum); - if ((*(uint8_t*)(((eiger_packet_header *)((char*)(wbuffer[i])))->num3)) == 0xFE) + if ((*(uint8_t*)(((eiger_packet_header *)((char*)(wbuffer[i])))->num3)) == 0xFF) cprintf(BG_RED,"missing packet though\n"); exit(-1); } @@ -2898,8 +2916,9 @@ void UDPStandardImplementation::handleWithoutDataCompression(int ithread, char* (*(uint8_t*)(((eiger_packet_header *)((char*)(wbuffer[i])))->num3)) = ((dynamicRange<<2)|(missingpacket<<1)|(port)); + //frame number - (*(uint32_t*)(((eiger_packet_header *)((char*)(wbuffer[i])))->num1)) = currframenum; + //(*(uint32_t*)(((eiger_packet_header *)((char*)(wbuffer[i])))->num1)) = currframenum; #ifdef VERYDEBUG if((i==0)||(i==1)){ From 80f33997d41d76652a8fbe2bcf56ddfa34562600 Mon Sep 17 00:00:00 2001 From: Dhanya Maliakal Date: Mon, 17 Aug 2015 15:37:28 +0200 Subject: [PATCH 14/68] almost works test stage still --- .../src/UDPStandardImplementation.cpp | 73 +++++++++---------- 1 file changed, 35 insertions(+), 38 deletions(-) diff --git a/slsReceiverSoftware/src/UDPStandardImplementation.cpp b/slsReceiverSoftware/src/UDPStandardImplementation.cpp index 374322684..3d3c1f4c9 100644 --- a/slsReceiverSoftware/src/UDPStandardImplementation.cpp +++ b/slsReceiverSoftware/src/UDPStandardImplementation.cpp @@ -894,7 +894,7 @@ void UDPStandardImplementation::setupFifoStructure(){ mem0[i]=(char*)malloc((whatperbuffer * numJobsPerThread + HEADER_SIZE_NUM_TOT_PACKETS)*fifosize); /** shud let the client know about this */ if (mem0[i]==NULL){ - cout<<"++++++++++++++++++++++ COULD NOT ALLOCATE MEMORY FOR LISTENING !!!!!!!+++++++++++++++++++++" << endl; + cprintf(BG_RED,"++++++++++++++++++++++ COULD NOT ALLOCATE MEMORY FOR LISTENING !!!!!!!+++++++++++++++++++++\n"); exit(-1); } @@ -1720,8 +1720,6 @@ int UDPStandardImplementation::startListening(){ else maxBufferSize = 0; - prenum=0; - while((1<ReceiveDataOnly(buffer[ithread] + HEADER_SIZE_NUM_TOT_PACKETS, maxBufferSize); - if(rc == 1040){ - cprintf(YELLOW,"tempframenum[%d]:%d\n",ithread,((*(uint32_t*)(((eiger_packet_header *)((char*)(buffer[ithread] + HEADER_SIZE_NUM_TOT_PACKETS)))->num1)))); - cprintf(YELLOW,"packetnum[%d]:%d\n",ithread,((*(uint8_t*)(((eiger_packet_header *)((char*)(buffer[ithread] + HEADER_SIZE_NUM_TOT_PACKETS)))->num4)))); - - if(((*(uint32_t*)(((eiger_packet_header *)((char*)(buffer[ithread] + HEADER_SIZE_NUM_TOT_PACKETS)))->num1)))< prenum){ - cprintf(BG_RED, "framenumber weird:previous:%d\n",prenum); - exit(-1); - } - prenum = ((*(uint32_t*)(((eiger_packet_header *)((char*)(buffer[ithread] + HEADER_SIZE_NUM_TOT_PACKETS)))->num1))); - + if(rc == EIGER_HEADER_LENGTH && myDetectorType == EIGER) { + while(rc == EIGER_HEADER_LENGTH) + rc = udpSocket[ithread]->ReceiveDataOnly(buffer[ithread] + HEADER_SIZE_NUM_TOT_PACKETS, maxBufferSize); } expected = maxBufferSize; #ifdef SOCKET_DEBUG @@ -1947,7 +1938,8 @@ int UDPStandardImplementation::startWriting(){ int numpackets[numListeningThreads], nf; bool fullframe[numListeningThreads],popready[numListeningThreads]; uint32_t tempframenum[numListeningThreads]; - int lastpacketheader[numListeningThreads], currentpacketheader[numListeningThreads]; + uint32_t presentframenum; + uint32_t lastpacketheader[numListeningThreads], currentpacketheader[numListeningThreads]; int numberofmissingpackets[numListeningThreads]; int MAX_VALUE = 1024; @@ -2033,7 +2025,7 @@ int UDPStandardImplementation::startWriting(){ tempframenum[i] = 0; } endofacquisition = false; - + presentframenum = 0; while((1<pop(wbuf[i]); #ifdef FIFO_DEBUG cprintf(GREEN,"%d writer poped 0x%x from fifo %d\n", ithread, (void*)(wbuf[i]), i); @@ -2055,8 +2044,12 @@ int UDPStandardImplementation::startWriting(){ #ifdef VERYDEBUG cprintf(GREEN,"%d numpackets: %d for fifo :%d\n", ithread, numpackets[i], i); #endif + if(numpackets < 0){ + cprintf(BG_RED,"negative numpackets[%d]%d\n",i,numpackets[i]); + exit(-1); + } //dont pop again if dummy packet - if(!numpackets[i]){ + else if(numpackets[i] == 0){ popready[i] = false; //#ifdef EIGER_DEBUG3 cprintf(GREEN,"%d Dummy frame popped out of fifo %d",ithread, i); @@ -2066,9 +2059,12 @@ int UDPStandardImplementation::startWriting(){ if(numpackets[i] == 1040){ cprintf(BLUE,"tempframenum[%d]:%d\n",i,((*(uint32_t*)(((eiger_packet_header *)((char*)(wbuf[i] + HEADER_SIZE_NUM_TOT_PACKETS)))->num1)))); cprintf(BLUE,"packetnum[%d]:%d\n",i,((*(uint8_t*)(((eiger_packet_header *)((char*)(wbuf[i] + HEADER_SIZE_NUM_TOT_PACKETS)))->num4)))); + }else if(numpackets[i] == EIGER_HEADER_LENGTH){ + cprintf(BG_RED, "got header in writer, weirdd packetsize:%d\n",numpackets[i]); + exit(-1); + } - - }if(myDetectorType == EIGER){ + if(myDetectorType == EIGER){ tofree[tofreeoffset[i]] = wbuf[i]; tofreeoffset[i]++; } @@ -2107,7 +2103,7 @@ int UDPStandardImplementation::startWriting(){ //anything that is not a data packet of right size if(numpackets[i] != onePacketSize){ //header packet - if(numpackets[i] == EIGER_HEADER_LENGTH) continue; + if(numpackets[i] == EIGER_HEADER_LENGTH) {cprintf(BG_RED,"weird, frame packet recieved\n"); exit(-1);} //dummy packet else if(!numpackets[i]){ //#ifdef VERYDEBUG @@ -2130,7 +2126,7 @@ int UDPStandardImplementation::startWriting(){ else cprintf(RED, "1 fifo:%d Weird at pnum:%d\n",i,tempoffset[i]); #endif if ((*(uint8_t*)(((eiger_packet_header *)((char*)(tempbuffer[tempoffset[i]])))->num3)) != 0xFF){ - cprintf(BG_RED, "pnum mismatch num4 earlier2! i:%d pnum:%d fnum:%d num3:0x%x actual num3:0x%x\n", + cprintf(BG_RED, "dummy blank mismatch num4 earlier2! i:%d pnum:%d fnum:%d num3:0x%x actual num3:0x%x\n", i,tempoffset[i],tempframenum[i], (*(uint8_t*)(((eiger_packet_header *)((char*)(tempbuffer[tempoffset[i]])))->num3)), (*(uint8_t*)(((eiger_packet_header *)((char*)(blankframe[blankoffset])))->num3))); @@ -2171,15 +2167,15 @@ int UDPStandardImplementation::startWriting(){ tempframenum[i] += (startFrameIndex-1); - //WRONG FRAME - leave (also includes exception of tempnum 0 and currfnum 0) - if((tempframenum[i] != (currframenum+1))&&(tempframenum[i] || currframenum)){cout<<"wrong packet"<num1))), ((*(uint8_t*)(((eiger_packet_header *)((char*)(wbuf[i] + HEADER_SIZE_NUM_TOT_PACKETS)))->num4)))); //#endif - tempframenum[i] = currframenum+1; + tempframenum[i] = presentframenum; //add missing packets numberofmissingpackets[i] = (LAST_PACKET_VALUE - lastpacketheader[i]); #ifdef VERYDEBUG @@ -2195,7 +2191,7 @@ int UDPStandardImplementation::startWriting(){ else cprintf(RED, "5 fifo:%d WEird at pnum:%d\n",i,tempoffset[i]); #endif if ((*(uint8_t*)(((eiger_packet_header *)((char*)(tempbuffer[tempoffset[i]])))->num3)) != 0xFF){ - cprintf(BG_RED, "pnum mismatch num4 earlier2! i:%d pnum:%d fnum:%d num3:0x%x actual num3:0x%x\n", + cprintf(BG_RED, "wrong blank mismatch num4 earlier2! i:%d pnum:%d fnum:%d num3:0x%x actual num3:0x%x\n", i,tempoffset[i],tempframenum[i], (*(uint8_t*)(((eiger_packet_header *)((char*)(tempbuffer[tempoffset[i]])))->num3)), (*(uint8_t*)(((eiger_packet_header *)((char*)(blankframe[blankoffset])))->num3))); @@ -2237,7 +2233,7 @@ int UDPStandardImplementation::startWriting(){ else cprintf(RED, "4 fifo:%d WEird at pnum:%d\n",i,tempoffset[i]); #endif if ((*(uint8_t*)(((eiger_packet_header *)((char*)(tempbuffer[tempoffset[i]])))->num3)) != 0xFF){ - cprintf(BG_RED, "pnum mismatch num4 earlier2! i:%d pnum:%d fnum:%d num3:0x%x actual num3:0x%x\n", + cprintf(BG_RED, "correct blank mismatch num4 earlier2! i:%d pnum:%d fnum:%d num3:0x%x actual num3:0x%x\n", i,tempoffset[i],tempframenum[i], (*(uint8_t*)(((eiger_packet_header *)((char*)(tempbuffer[tempoffset[i]])))->num3)), (*(uint8_t*)(((eiger_packet_header *)((char*)(blankframe[blankoffset])))->num3))); @@ -2250,7 +2246,7 @@ int UDPStandardImplementation::startWriting(){ //add current packet if(currentpacketheader[i] != (tempoffset[i]-(i*packetsPerFrame/numListeningThreads))){ - cprintf(BG_RED, "pnum mismatch earlier! tempoffset[%d]:%d pnum:%d fnum:%d\n",i,tempoffset[i],currentpacketheader[i],tempframenum[i]); + cprintf(BG_RED, "correct pnum mismatch earlier! tempoffset[%d]:%d pnum:%d fnum:%d rfnum:%d\n",i,tempoffset[i],currentpacketheader[i],tempframenum[i],(*(uint32_t*)(((eiger_packet_header *)((char*)(wbuf[i])))->num1))); exit(-1); } tempbuffer[tempoffset[i]] = wbuf[i] + HEADER_SIZE_NUM_TOT_PACKETS; @@ -2288,9 +2284,9 @@ int UDPStandardImplementation::startWriting(){ if(tempframenum[0] != tempframenum[1]) cprintf(RED,"Frame numbers mismatch!!! %d %d\n",tempframenum[0],tempframenum[1]); currframenum = tempframenum[0]; - //to resolve for missing frame packets + /*//to resolve for missing frame packets tempframenum[0]++; - tempframenum[1]++; + tempframenum[1]++;*/ numMissingPackets += (numberofmissingpackets[0]+numberofmissingpackets[1]); numTotMissingPacketsInFile += numMissingPackets; numTotMissingPackets += numMissingPackets; @@ -2335,10 +2331,11 @@ int UDPStandardImplementation::startWriting(){ //reset a few stuff + presentframenum = tempframenum[0]+1; for(int i=0;inum4)) != (i-(port*packetsPerFrame/numListeningThreads))){ cprintf(BG_RED, "pnum mismatch num4! i:%d pnum:%d fnum:%d\n",i,(*(uint8_t*)(((eiger_packet_header *)((char*)(wbuffer[i])))->num4)),currframenum); - exit(-1); + /* exit(-1);*/ } @@ -2909,7 +2906,7 @@ void UDPStandardImplementation::handleWithoutDataCompression(int ithread, char* cprintf(BG_RED, "pnum mismatch! i:%d pnum:%d fnum:%d\n",i,(*(uint16_t*)(((eiger_packet_header *)((char*)(wbuffer[i])))->num2)),currframenum); if ((*(uint8_t*)(((eiger_packet_header *)((char*)(wbuffer[i])))->num3)) == 0xFF) cprintf(BG_RED,"missing packet though\n"); - exit(-1); + /*exit(-1);*/ } //overwriting port number and dynamic range From e8a5f8108347081449eaf3231a7cba73ccd685ec Mon Sep 17 00:00:00 2001 From: Dhanya Maliakal Date: Wed, 19 Aug 2015 14:32:08 +0200 Subject: [PATCH 15/68] moving to fix another branch --- .../src/UDPStandardImplementation.cpp | 23 +++++++++++-------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/slsReceiverSoftware/src/UDPStandardImplementation.cpp b/slsReceiverSoftware/src/UDPStandardImplementation.cpp index 3d3c1f4c9..0d4eab84b 100644 --- a/slsReceiverSoftware/src/UDPStandardImplementation.cpp +++ b/slsReceiverSoftware/src/UDPStandardImplementation.cpp @@ -1751,7 +1751,11 @@ int UDPStandardImplementation::startListening(){ if(rc == EIGER_HEADER_LENGTH && myDetectorType == EIGER) { while(rc == EIGER_HEADER_LENGTH) rc = udpSocket[ithread]->ReceiveDataOnly(buffer[ithread] + HEADER_SIZE_NUM_TOT_PACKETS, maxBufferSize); - } + }/* + if(rc == 1040){ + cprintf(YELLOW,"tempframenum[%d]:%d\n",ithread,((*(uint32_t*)(((eiger_packet_header *)((char*)(buffer[ithread] + HEADER_SIZE_NUM_TOT_PACKETS)))->num1)))); + cprintf(YELLOW,"packetnum[%d]:%d\n",ithread,((*(uint8_t*)(((eiger_packet_header *)((char*)(buffer[ithread] + HEADER_SIZE_NUM_TOT_PACKETS)))->num4)))); + }*/ expected = maxBufferSize; #ifdef SOCKET_DEBUG }else{ @@ -2768,17 +2772,17 @@ void UDPStandardImplementation::writeToFile_withoutCompression(char* buf[],int n }else fwrite(buf[0]+offset, 1, packetsToSave * onePacketSize, sfilefd); packetsInFile += packetsToSave; -#ifdef EIGER_DEBUG3 +//#ifdef EIGER_DEBUG3 cprintf(GREEN,"packetscaught earlier:%d packetstosave:%d numMissingPackets:%d addingon:%d\n", packetsCaught,packetsToSave,numMissingPackets,(packetsToSave - numMissingPackets)); -#endif +//#endif packetsCaught += (packetsToSave - numMissingPackets); totalPacketsCaught += (packetsToSave - numMissingPackets); numMissingPackets = 0; -#ifdef EIGER_DEBUG3 +//#ifdef EIGER_DEBUG3 cprintf(GREEN,"packetscaught:%d\n", packetsCaught); cprintf(GREEN,"totalPacketsCaught:%d\n", totalPacketsCaught); -#endif +//#endif //new file if(packetsInFile >= maxPacketsPerFile){ @@ -2867,12 +2871,13 @@ void UDPStandardImplementation::handleWithoutDataCompression(int ithread, char* missingpacket = 1; //add packet numbers (*(uint16_t*)(((eiger_packet_header *)((char*)(wbuffer[i])))->num2)) = (i+1); + (*(uint32_t*)(((eiger_packet_header *)((char*)(wbuffer[i])))->num1)) = currframenum; }else{ missingpacket = 0; if((*(uint8_t*)(((eiger_packet_header *)((char*)(wbuffer[i])))->num4)) != (i-(port*packetsPerFrame/numListeningThreads))){ cprintf(BG_RED, "pnum mismatch num4! i:%d pnum:%d fnum:%d\n",i,(*(uint8_t*)(((eiger_packet_header *)((char*)(wbuffer[i])))->num4)),currframenum); - /* exit(-1);*/ + exit(-1); } @@ -2906,7 +2911,7 @@ void UDPStandardImplementation::handleWithoutDataCompression(int ithread, char* cprintf(BG_RED, "pnum mismatch! i:%d pnum:%d fnum:%d\n",i,(*(uint16_t*)(((eiger_packet_header *)((char*)(wbuffer[i])))->num2)),currframenum); if ((*(uint8_t*)(((eiger_packet_header *)((char*)(wbuffer[i])))->num3)) == 0xFF) cprintf(BG_RED,"missing packet though\n"); - /*exit(-1);*/ + exit(-1); } //overwriting port number and dynamic range @@ -2938,9 +2943,9 @@ void UDPStandardImplementation::handleWithoutDataCompression(int ithread, char* writeToFile_withoutCompression(wbuffer, npackets,currframenum); } -#ifdef VERYDEBUG +//#ifdef VERYDEBUG cprintf(GREEN,"written everyting\n"); -#endif +//#endif } From a29da27a42e83bb98090f5ada84cebc2d13812c7 Mon Sep 17 00:00:00 2001 From: Dhanya Maliakal Date: Thu, 20 Aug 2015 17:36:41 +0200 Subject: [PATCH 16/68] works without problems except bottom doesnt get much for acquire --- .../include/UDPBaseImplementation.h | 2 +- .../src/UDPStandardImplementation.cpp | 129 +++++++++++------- 2 files changed, 82 insertions(+), 49 deletions(-) diff --git a/slsReceiverSoftware/include/UDPBaseImplementation.h b/slsReceiverSoftware/include/UDPBaseImplementation.h index 05b992975..38adefe90 100644 --- a/slsReceiverSoftware/include/UDPBaseImplementation.h +++ b/slsReceiverSoftware/include/UDPBaseImplementation.h @@ -618,7 +618,7 @@ protected: uint32_t currframenum; /** Previous Frame number from buffer */ - uint32_t prevframenum; + int prevframenum; /** size of one frame */ int frameSize; diff --git a/slsReceiverSoftware/src/UDPStandardImplementation.cpp b/slsReceiverSoftware/src/UDPStandardImplementation.cpp index 0d4eab84b..5f68876a9 100644 --- a/slsReceiverSoftware/src/UDPStandardImplementation.cpp +++ b/slsReceiverSoftware/src/UDPStandardImplementation.cpp @@ -1749,12 +1749,16 @@ int UDPStandardImplementation::startListening(){ #endif rc = udpSocket[ithread]->ReceiveDataOnly(buffer[ithread] + HEADER_SIZE_NUM_TOT_PACKETS, maxBufferSize); if(rc == EIGER_HEADER_LENGTH && myDetectorType == EIGER) { - while(rc == EIGER_HEADER_LENGTH) + while(rc == EIGER_HEADER_LENGTH){ rc = udpSocket[ithread]->ReceiveDataOnly(buffer[ithread] + HEADER_SIZE_NUM_TOT_PACKETS, maxBufferSize); - }/* - if(rc == 1040){ - cprintf(YELLOW,"tempframenum[%d]:%d\n",ithread,((*(uint32_t*)(((eiger_packet_header *)((char*)(buffer[ithread] + HEADER_SIZE_NUM_TOT_PACKETS)))->num1)))); - cprintf(YELLOW,"packetnum[%d]:%d\n",ithread,((*(uint8_t*)(((eiger_packet_header *)((char*)(buffer[ithread] + HEADER_SIZE_NUM_TOT_PACKETS)))->num4)))); + /*cprintf(MAGENTA,"%d got a header*****************************\n",ithread); + cprintf(MAGENTA,"tempframenum[%d]:%d\n",ithread,(htonl(*(uint32_t*)(((eiger_image_header *)((char*)(buffer[ithread] + HEADER_SIZE_NUM_TOT_PACKETS)))->fnum)))); + */} + } + /* if(rc == 1040){ + cprintf(CYAN,"tempframenum[%d]:%d\n",ithread,((*(uint32_t*)(((eiger_packet_header *)((char*)(buffer[ithread] + HEADER_SIZE_NUM_TOT_PACKETS)))->num1)))); + cprintf(CYAN,"packetnum[%d]:%d\n",ithread,((*(uint8_t*)(((eiger_packet_header *)((char*)(buffer[ithread] + HEADER_SIZE_NUM_TOT_PACKETS)))->num4)))); + cprintf(CYAN,"add[%d]:0x%x\n",ithread,(void*)(buffer[ithread])); }*/ expected = maxBufferSize; #ifdef SOCKET_DEBUG @@ -1888,6 +1892,9 @@ int UDPStandardImplementation::startListening(){ cprintf(BLUE,"%d listener going to push fifo: 0x%x\n", ithread,(void*)(buffer[ithread])); #endif while(!fifo[ithread]->push(buffer[ithread])); + /*cprintf(YELLOW,"tempframenum[%d]:%d\n",ithread,((*(uint32_t*)(((eiger_packet_header *)((char*)(buffer[ithread] + HEADER_SIZE_NUM_TOT_PACKETS)))->num1)))); + cprintf(YELLOW,"packetnum[%d]:%d\n",ithread,((*(uint8_t*)(((eiger_packet_header *)((char*)(buffer[ithread] + HEADER_SIZE_NUM_TOT_PACKETS)))->num4)))); + cprintf(YELLOW,"add[%d]:0x%x\n",ithread,(void*)(buffer[ithread]));*/ #ifdef FIFO_DEBUG cprintf(BLUE, "%d listener pushed into fifo %x\n",ithread, (void*)(buffer[ithread])); #endif @@ -2007,9 +2014,9 @@ int UDPStandardImplementation::startWriting(){ cprintf(RED,"blank frame not detected at %d: 0x%x\n",i,(*(uint8_t*)(((eiger_packet_header *)((char*)(blankframe[i])))->num3)) ); exit(-1); } - #ifdef FIFO_DEBUG + //#ifdef FIFO_DEBUG cprintf(GREEN,"packet %d blank frame 0x%x\n",i,(void*)(blankframe[i])); - #endif + //#endif } } @@ -2061,9 +2068,9 @@ int UDPStandardImplementation::startWriting(){ }else{ endofacquisition = false; if(numpackets[i] == 1040){ - cprintf(BLUE,"tempframenum[%d]:%d\n",i,((*(uint32_t*)(((eiger_packet_header *)((char*)(wbuf[i] + HEADER_SIZE_NUM_TOT_PACKETS)))->num1)))); + /* cprintf(BLUE,"tempframenum[%d]:%d\n",i,((*(uint32_t*)(((eiger_packet_header *)((char*)(wbuf[i] + HEADER_SIZE_NUM_TOT_PACKETS)))->num1)))); cprintf(BLUE,"packetnum[%d]:%d\n",i,((*(uint8_t*)(((eiger_packet_header *)((char*)(wbuf[i] + HEADER_SIZE_NUM_TOT_PACKETS)))->num4)))); - }else if(numpackets[i] == EIGER_HEADER_LENGTH){ + */}else if(numpackets[i] == EIGER_HEADER_LENGTH){ cprintf(BG_RED, "got header in writer, weirdd packetsize:%d\n",numpackets[i]); exit(-1); } @@ -2125,19 +2132,19 @@ int UDPStandardImplementation::startWriting(){ for(j=0;jnum3)) == 0xFF) + if ((*(uint8_t*)(((eiger_packet_header *)((char*)(tempbuffer[tempoffset[i]])))->num3))&0x2) cprintf(RED,"1 fifo:%d missing packet added at pnum:%d\n",i,tempoffset[i]); else cprintf(RED, "1 fifo:%d Weird at pnum:%d\n",i,tempoffset[i]); #endif - if ((*(uint8_t*)(((eiger_packet_header *)((char*)(tempbuffer[tempoffset[i]])))->num3)) != 0xFF){ + if (!((*(uint8_t*)(((eiger_packet_header *)((char*)(tempbuffer[tempoffset[i]])))->num3))&0x2)){ cprintf(BG_RED, "dummy blank mismatch num4 earlier2! i:%d pnum:%d fnum:%d num3:0x%x actual num3:0x%x\n", i,tempoffset[i],tempframenum[i], (*(uint8_t*)(((eiger_packet_header *)((char*)(tempbuffer[tempoffset[i]])))->num3)), (*(uint8_t*)(((eiger_packet_header *)((char*)(blankframe[blankoffset])))->num3))); exit(-1); }else - cprintf(GREEN, "blank packet i:%d pnum:%d fnum:%d num3:0x%x\n",i,tempoffset[i],tempframenum[i],(*(uint8_t*)(((eiger_packet_header *)((char*)(tempbuffer[tempoffset[i]])))->num3))); - + /*cprintf(GREEN, "blank packet i:%d pnum:%d fnum:%d num3:0x%x\n",i,tempoffset[i],tempframenum[i],(*(uint8_t*)(((eiger_packet_header *)((char*)(tempbuffer[tempoffset[i]])))->num3))); +*/ tempoffset[i] ++; blankoffset ++; } @@ -2172,13 +2179,13 @@ int UDPStandardImplementation::startWriting(){ //WRONG FRAME - leave - if(tempframenum[i] != presentframenum){cout<<"wrong packet"<num1))), ((*(uint8_t*)(((eiger_packet_header *)((char*)(wbuf[i] + HEADER_SIZE_NUM_TOT_PACKETS)))->num4)))); -//#endif +#endif tempframenum[i] = presentframenum; //add missing packets numberofmissingpackets[i] = (LAST_PACKET_VALUE - lastpacketheader[i]); @@ -2190,18 +2197,23 @@ int UDPStandardImplementation::startWriting(){ for(j=0;jnum3)) == 0xFF) + if ((*(uint8_t*)(((eiger_packet_header *)((char*)(tempbuffer[tempoffset[i]])))->num3))&0x2) cprintf(RED,"5 fifo:%d missing packet added at pnum:%d\n",i,tempoffset[i]); else cprintf(RED, "5 fifo:%d WEird at pnum:%d\n",i,tempoffset[i]); #endif - if ((*(uint8_t*)(((eiger_packet_header *)((char*)(tempbuffer[tempoffset[i]])))->num3)) != 0xFF){ - cprintf(BG_RED, "wrong blank mismatch num4 earlier2! i:%d pnum:%d fnum:%d num3:0x%x actual num3:0x%x\n", + if (!((*(uint8_t*)(((eiger_packet_header *)((char*)(tempbuffer[tempoffset[i]])))->num3))&0x2)){ + cprintf(BG_RED, "wrong blank mismatch num4 earlier2! " + "i:%d pnum:%d fnum:%d num3:0x%x actual num3:0x%x add:0x%x\n", i,tempoffset[i],tempframenum[i], (*(uint8_t*)(((eiger_packet_header *)((char*)(tempbuffer[tempoffset[i]])))->num3)), - (*(uint8_t*)(((eiger_packet_header *)((char*)(blankframe[blankoffset])))->num3))); + (*(uint8_t*)(((eiger_packet_header *)((char*)(blankframe[blankoffset])))->num3)), + (void*)(tempbuffer[tempoffset[i]])); exit(-1); }else - cprintf(GREEN, "blank packet i:%d pnum:%d fnum:%d num3:0x%x\n",i,tempoffset[i],tempframenum[i],(*(uint8_t*)(((eiger_packet_header *)((char*)(tempbuffer[tempoffset[i]])))->num3))); + /*cprintf(GREEN, "blank packet i:%d pnum:%d fnum:%d num3:0x%x add:0x%x\n", + i,tempoffset[i],tempframenum[i], + (*(uint8_t*)(((eiger_packet_header *)((char*)(tempbuffer[tempoffset[i]])))->num3)), + (void*)(tempbuffer[tempoffset[i]]));*/ tempoffset[i] ++; blankoffset ++; @@ -2213,15 +2225,15 @@ int UDPStandardImplementation::startWriting(){ //CORRECT FRAME - continue building frame - else {cout<<"correct packet"<num4))); -//#ifdef VERYVERBOSE +#ifdef VERYVERBOSE cprintf(GREEN,"**fifo:%d currentpacketheader: %d lastpacketheader %d tempoffset:%d\n",i,currentpacketheader[i],lastpacketheader[i], tempoffset[i]); -//#endif +#endif //add missing packets numberofmissingpackets[i] = (currentpacketheader[i] - lastpacketheader[i] -1); #ifdef VERYDEBUG @@ -2232,25 +2244,32 @@ int UDPStandardImplementation::startWriting(){ for(j=0;jnum3)) == 0xFF) + if ((*(uint8_t*)(((eiger_packet_header *)((char*)(tempbuffer[tempoffset[i]])))->num3))&0x2) cprintf(RED,"4 fifo:%d missing packet added at pnum:%d\n",i,tempoffset[i]); else cprintf(RED, "4 fifo:%d WEird at pnum:%d\n",i,tempoffset[i]); #endif - if ((*(uint8_t*)(((eiger_packet_header *)((char*)(tempbuffer[tempoffset[i]])))->num3)) != 0xFF){ - cprintf(BG_RED, "correct blank mismatch num4 earlier2! i:%d pnum:%d fnum:%d num3:0x%x actual num3:0x%x\n", + if (!((*(uint8_t*)(((eiger_packet_header *)((char*)(tempbuffer[tempoffset[i]])))->num3))&0x2)){ + cprintf(BG_RED, "correct blank mismatch num4 earlier2! " + "i:%d pnum:%d fnum:%d num3:0x%x actual num3:0x%x add:0x%x\n", i,tempoffset[i],tempframenum[i], (*(uint8_t*)(((eiger_packet_header *)((char*)(tempbuffer[tempoffset[i]])))->num3)), - (*(uint8_t*)(((eiger_packet_header *)((char*)(blankframe[blankoffset])))->num3))); + (*(uint8_t*)(((eiger_packet_header *)((char*)(blankframe[blankoffset])))->num3)), + (void*)(tempbuffer[tempoffset[i]])); exit(-1); }else - cprintf(GREEN, "blank packet i:%d pnum:%d fnum:%d num3:0x%x\n",i,tempoffset[i],tempframenum[i],(*(uint8_t*)(((eiger_packet_header *)((char*)(tempbuffer[tempoffset[i]])))->num3))); + /* cprintf(GREEN, "blank packet i:%d pnum:%d fnum:%d num3:0x%x add:0x%x\n", + i,tempoffset[i],tempframenum[i], + (*(uint8_t*)(((eiger_packet_header *)((char*)(tempbuffer[tempoffset[i]])))->num3)), + (void*)(tempbuffer[tempoffset[i]]));*/ tempoffset[i] ++; blankoffset ++; } //add current packet if(currentpacketheader[i] != (tempoffset[i]-(i*packetsPerFrame/numListeningThreads))){ - cprintf(BG_RED, "correct pnum mismatch earlier! tempoffset[%d]:%d pnum:%d fnum:%d rfnum:%d\n",i,tempoffset[i],currentpacketheader[i],tempframenum[i],(*(uint32_t*)(((eiger_packet_header *)((char*)(wbuf[i])))->num1))); + cprintf(BG_RED, "correct pnum mismatch earlier! tempoffset[%d]:%d pnum:%d fnum:%d rfnum:%d\n", + i,tempoffset[i],currentpacketheader[i], + tempframenum[i],(*(uint32_t*)(((eiger_packet_header *)((char*)(wbuf[i]+ HEADER_SIZE_NUM_TOT_PACKETS)))->num1))); exit(-1); } tempbuffer[tempoffset[i]] = wbuf[i] + HEADER_SIZE_NUM_TOT_PACKETS; @@ -2258,10 +2277,15 @@ int UDPStandardImplementation::startWriting(){ cprintf(GREEN,"**fifo:%d currentpacketheader: %d tempoffset:%d\n",i,(*(uint8_t*)(((eiger_packet_header *)((char*)(tempbuffer[tempoffset[i]])))->num4)),tempoffset[i]); #endif if((*(uint8_t*)(((eiger_packet_header *)((char*)(tempbuffer[tempoffset[i]])))->num4)) != (tempoffset[i]-(i*packetsPerFrame/numListeningThreads))){ - cprintf(BG_RED, "pnum mismatch num4 earlier! i:%d pnum:%d fnum:%d\n",i,(*(uint8_t*)(((eiger_packet_header *)((char*)(tempbuffer[tempoffset[i]])))->num4)),tempframenum[i]); + cprintf(BG_RED, "pnum mismatch num4 earlier! i:%d pnum:%d fnum:%d add:0x%x\n", + i,(*(uint8_t*)(((eiger_packet_header *)((char*)(tempbuffer[tempoffset[i]])))->num4)), + tempframenum[i],(void*)(tempbuffer[tempoffset[i]])); exit(-1); } - cprintf(GREEN, "normal packet i:%d pnum:%d fnum:%d num3:0x%x\n",i,tempoffset[i],tempframenum[i],(*(uint8_t*)(((eiger_packet_header *)((char*)(tempbuffer[tempoffset[i]])))->num3))); + /*cprintf(GREEN, "normal packet i:%d pnum:%d fnum:%d num3:0x%x add:0x%x\n", + i,tempoffset[i],tempframenum[i], + (*(uint8_t*)(((eiger_packet_header *)((char*)(tempbuffer[tempoffset[i]])))->num3)), + (void*)(tempbuffer[tempoffset[i]]));*/ tempoffset[i] ++; //update last packet lastpacketheader[i] = currentpacketheader[i]; @@ -2306,7 +2330,7 @@ int UDPStandardImplementation::startWriting(){ cprintf(RED, "numMissingPackets:%d fnum:%d\n",numMissingPackets,currframenum); for (j=0;jnum3)) == 0xFF) + if ((*(uint8_t*)(((eiger_packet_header *)((char*)(tempbuffer[j])))->num3))&0x2) cprintf(RED,"found the missing packet at pnum:%d\n",j); } #endif @@ -2329,9 +2353,9 @@ int UDPStandardImplementation::startWriting(){ cprintf(GREEN,"%d writer freed pushed into fifofree %x for listener %d\n",ithread, (void*)(tofree[j]),1); #endif } -//#ifdef VERYDEBUG +#ifdef VERYDEBUG cprintf(GREEN,"finished freeing\n"); -//#endif +#endif //reset a few stuff @@ -2341,6 +2365,7 @@ int UDPStandardImplementation::startWriting(){ //no dummy packet and is the last packet (if not last packet, next frame, dont pop over it) if((numpackets[i]) && (currentpacketheader[i] == LAST_PACKET_VALUE)) popready[i] = true; + /*cprintf(GREEN,"popready[%d]:%d\n",i,popready[i]);*/ tempoffset[i] = (i*packetsPerFrame/numListeningThreads); tofreeoffset[i] = (i*packetsPerFrame/numListeningThreads); blankoffset = 0; @@ -2350,6 +2375,11 @@ int UDPStandardImplementation::startWriting(){ } } + /* for(int i=0;inum1)))); + cprintf(GREEN,"packetnum[%d]:%d\n",i,((*(uint8_t*)(((eiger_packet_header *)((char*)(wbuf[i] + HEADER_SIZE_NUM_TOT_PACKETS)))->num4)))); + }*/ } @@ -2772,17 +2802,17 @@ void UDPStandardImplementation::writeToFile_withoutCompression(char* buf[],int n }else fwrite(buf[0]+offset, 1, packetsToSave * onePacketSize, sfilefd); packetsInFile += packetsToSave; -//#ifdef EIGER_DEBUG3 +#ifdef EIGER_DEBUG3 cprintf(GREEN,"packetscaught earlier:%d packetstosave:%d numMissingPackets:%d addingon:%d\n", packetsCaught,packetsToSave,numMissingPackets,(packetsToSave - numMissingPackets)); -//#endif +#endif packetsCaught += (packetsToSave - numMissingPackets); totalPacketsCaught += (packetsToSave - numMissingPackets); numMissingPackets = 0; -//#ifdef EIGER_DEBUG3 +#ifdef EIGER_DEBUG3 cprintf(GREEN,"packetscaught:%d\n", packetsCaught); cprintf(GREEN,"totalPacketsCaught:%d\n", totalPacketsCaught); -//#endif +#endif //new file if(packetsInFile >= maxPacketsPerFile){ @@ -2867,11 +2897,11 @@ void UDPStandardImplementation::handleWithoutDataCompression(int ithread, char* //missing packet - if ((*(uint8_t*)(((eiger_packet_header *)((char*)(wbuffer[i])))->num3)) == 0xFF){ + if ((*(uint8_t*)(((eiger_packet_header *)((char*)(wbuffer[i])))->num3))&0x2){ missingpacket = 1; //add packet numbers (*(uint16_t*)(((eiger_packet_header *)((char*)(wbuffer[i])))->num2)) = (i+1); - (*(uint32_t*)(((eiger_packet_header *)((char*)(wbuffer[i])))->num1)) = currframenum; + (*(uint32_t*)(((eiger_packet_header *)((char*)(wbuffer[i])))->num1)) = currframenum+1; }else{ missingpacket = 0; @@ -2909,7 +2939,7 @@ void UDPStandardImplementation::handleWithoutDataCompression(int ithread, char* if((*(uint16_t*)(((eiger_packet_header *)((char*)(wbuffer[i])))->num2)) != (i+1)){ cprintf(BG_RED, "pnum mismatch! i:%d pnum:%d fnum:%d\n",i,(*(uint16_t*)(((eiger_packet_header *)((char*)(wbuffer[i])))->num2)),currframenum); - if ((*(uint8_t*)(((eiger_packet_header *)((char*)(wbuffer[i])))->num3)) == 0xFF) + if ((*(uint8_t*)(((eiger_packet_header *)((char*)(wbuffer[i])))->num3))&0x2) cprintf(BG_RED,"missing packet though\n"); exit(-1); } @@ -2933,8 +2963,11 @@ void UDPStandardImplementation::handleWithoutDataCompression(int ithread, char* (*(uint8_t*)(((eiger_packet_header *)((char*)(wbuffer[i])))->num4)), (*(uint16_t*)(((eiger_packet_header *)((char*)(wbuffer[i])))->num2))); #endif - - +/* + cprintf(GREEN,"at writing, fnum:%d, pnum:%d,num3:0x%x add:0x%x\n", + currframenum, i, (*(uint8_t*)(((eiger_packet_header *)((char*)(wbuffer[i])))->num3)), + (void*)(wbuffer[i])); +*/ } } @@ -2943,9 +2976,9 @@ void UDPStandardImplementation::handleWithoutDataCompression(int ithread, char* writeToFile_withoutCompression(wbuffer, npackets,currframenum); } -//#ifdef VERYDEBUG +#ifdef VERYDEBUG cprintf(GREEN,"written everyting\n"); -//#endif +#endif } From 4813d7b59830393b0e713ad695706009c508c025 Mon Sep 17 00:00:00 2001 From: Dhanya Maliakal Date: Fri, 21 Aug 2015 10:04:55 +0200 Subject: [PATCH 17/68] should work properly --- slsReceiverSoftware/src/UDPStandardImplementation.cpp | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/slsReceiverSoftware/src/UDPStandardImplementation.cpp b/slsReceiverSoftware/src/UDPStandardImplementation.cpp index 5f68876a9..769269721 100644 --- a/slsReceiverSoftware/src/UDPStandardImplementation.cpp +++ b/slsReceiverSoftware/src/UDPStandardImplementation.cpp @@ -1654,7 +1654,12 @@ void UDPStandardImplementation::startReadout(){ /********************************************/ //usleep(10000000); //usleep(2000000); - + int prev = totalPacketsCaught; + usleep(50000); + while(prev!=totalPacketsCaught){ + prev=totalPacketsCaught; + usleep(50000); + } pthread_mutex_lock(&status_mutex); status = TRANSMITTING; pthread_mutex_unlock(&status_mutex); @@ -2014,9 +2019,9 @@ int UDPStandardImplementation::startWriting(){ cprintf(RED,"blank frame not detected at %d: 0x%x\n",i,(*(uint8_t*)(((eiger_packet_header *)((char*)(blankframe[i])))->num3)) ); exit(-1); } - //#ifdef FIFO_DEBUG +#ifdef FIFO_DEBUG cprintf(GREEN,"packet %d blank frame 0x%x\n",i,(void*)(blankframe[i])); - //#endif +#endif } } From 8f6b8a847404262ab58f7cee2a3625f55188c818 Mon Sep 17 00:00:00 2001 From: Dhanya Maliakal Date: Fri, 21 Aug 2015 10:54:14 +0200 Subject: [PATCH 18/68] forgot to commit earlier --- .../src/UDPStandardImplementation.cpp | 31 +++++++++---------- 1 file changed, 14 insertions(+), 17 deletions(-) diff --git a/slsReceiverSoftware/src/UDPStandardImplementation.cpp b/slsReceiverSoftware/src/UDPStandardImplementation.cpp index 769269721..de95765a2 100644 --- a/slsReceiverSoftware/src/UDPStandardImplementation.cpp +++ b/slsReceiverSoftware/src/UDPStandardImplementation.cpp @@ -2067,9 +2067,9 @@ int UDPStandardImplementation::startWriting(){ //dont pop again if dummy packet else if(numpackets[i] == 0){ popready[i] = false; -//#ifdef EIGER_DEBUG3 +#ifdef EIGER_DEBUG3 cprintf(GREEN,"%d Dummy frame popped out of fifo %d",ithread, i); -//#endif +#endif }else{ endofacquisition = false; if(numpackets[i] == 1040){ @@ -2093,9 +2093,9 @@ int UDPStandardImplementation::startWriting(){ //END OF ACQUISITION if(endofacquisition){ -//#ifdef VERYDEBUG +#ifdef VERYDEBUG cprintf(GREEN,"%d Both dummy frames\n", ithread); -//#endif +#endif //remaining packets to be written if((myDetectorType == EIGER) && ((tempoffset[0]!=0) || (tempoffset[1]!=(packetsPerFrame/numListeningThreads)))); @@ -2122,15 +2122,15 @@ int UDPStandardImplementation::startWriting(){ if(numpackets[i] == EIGER_HEADER_LENGTH) {cprintf(BG_RED,"weird, frame packet recieved\n"); exit(-1);} //dummy packet else if(!numpackets[i]){ -//#ifdef VERYDEBUG +#ifdef VERYDEBUG cprintf(RED, "Dummy packet: %d from fifo %d\n", numpackets[i],i); -//#endif +#endif cout<<"tempoffset["<num3))); */ - tempoffset[i] ++; - blankoffset ++; + tempoffset[i]++; + blankoffset++; } //set fullframe and dont let fifo pop over it until written fullframe[i] = true; popready[i] = false; } } -//#ifdef EIGER_DEBUG3 +#ifdef EIGER_DEBUG3 else{ cprintf(RED, "WARNING: Got a weird packet size: %d from fifo %d\n", numpackets[i],i); continue; } -//#endif +#endif } @@ -2317,15 +2317,12 @@ int UDPStandardImplementation::startWriting(){ if(tempframenum[0] != tempframenum[1]) cprintf(RED,"Frame numbers mismatch!!! %d %d\n",tempframenum[0],tempframenum[1]); currframenum = tempframenum[0]; - /*//to resolve for missing frame packets - tempframenum[0]++; - tempframenum[1]++;*/ numMissingPackets += (numberofmissingpackets[0]+numberofmissingpackets[1]); numTotMissingPacketsInFile += numMissingPackets; numTotMissingPackets += numMissingPackets; -//#ifdef EIGER_DEBUG2 +#ifdef EIGER_DEBUG2 cprintf(GREEN,"**fnum:%d**\n",currframenum); -//#endif +#endif #ifdef EIGER_DEBUG3 if(numberofmissingpackets[0]) cprintf(RED, "fifo 0 missing packets:%d fnum:%d\n",numberofmissingpackets[0],currframenum); From 41a4a9b611f45198f227d1158e69e1e11680d534 Mon Sep 17 00:00:00 2001 From: Dhanya Maliakal Date: Wed, 26 Aug 2015 10:28:39 +0200 Subject: [PATCH 19/68] some changes for 8 and 16 bit --- .../src/UDPStandardImplementation.cpp | 99 +++++++++++-------- 1 file changed, 59 insertions(+), 40 deletions(-) diff --git a/slsReceiverSoftware/src/UDPStandardImplementation.cpp b/slsReceiverSoftware/src/UDPStandardImplementation.cpp index 7b56daa04..b654be331 100644 --- a/slsReceiverSoftware/src/UDPStandardImplementation.cpp +++ b/slsReceiverSoftware/src/UDPStandardImplementation.cpp @@ -1987,8 +1987,8 @@ int UDPStandardImplementation::startWriting(){ //last packet numbers for different dynamic ranges if(myDetectorType == EIGER){ switch(dynamicRange){ - case 4: LAST_PACKET_VALUE = 0x40; break; - case 8: LAST_PACKET_VALUE = 0x80; break; + case 4: LAST_PACKET_VALUE = 0x3f; break; + case 8: LAST_PACKET_VALUE = 0x7f; break; case 16: LAST_PACKET_VALUE = 0xff; break; case 32: LAST_PACKET_VALUE = 0xff; break; default: break; @@ -2084,11 +2084,14 @@ int UDPStandardImplementation::startWriting(){ }else{ endofacquisition = false; if(numpackets[i] == 1040){ - /* cprintf(BLUE,"tempframenum[%d]:%d\n",i,((*(uint32_t*)(((eiger_packet_header *)((char*)(wbuf[i] + HEADER_SIZE_NUM_TOT_PACKETS)))->num1)))); + cprintf(BLUE,"tempframenum[%d]:%d\n",i,((*(uint32_t*)(((eiger_packet_header *)((char*)(wbuf[i] + HEADER_SIZE_NUM_TOT_PACKETS)))->num1)))); cprintf(BLUE,"packetnum[%d]:%d\n",i,((*(uint8_t*)(((eiger_packet_header *)((char*)(wbuf[i] + HEADER_SIZE_NUM_TOT_PACKETS)))->num4)))); - */}else if(numpackets[i] == EIGER_HEADER_LENGTH){ + }else if(numpackets[i] == EIGER_HEADER_LENGTH){ cprintf(BG_RED, "got header in writer, weirdd packetsize:%d\n",numpackets[i]); exit(-1); + }else { + cprintf(BG_RED, "got weird in writer, weirdd packetsize:%d\n",numpackets[i]); + } if(myDetectorType == EIGER){ @@ -2104,9 +2107,9 @@ int UDPStandardImplementation::startWriting(){ //END OF ACQUISITION if(endofacquisition){ -#ifdef VERYDEBUG +//#ifdef VERYDEBUG cprintf(GREEN,"%d Both dummy frames\n", ithread); -#endif +//#endif //remaining packets to be written if((myDetectorType == EIGER) && ((tempoffset[0]!=0) || (tempoffset[1]!=(packetsPerFrame/numListeningThreads)))); @@ -2133,15 +2136,15 @@ int UDPStandardImplementation::startWriting(){ if(numpackets[i] == EIGER_HEADER_LENGTH) {cprintf(BG_RED,"weird, frame packet recieved\n"); exit(-1);} //dummy packet else if(!numpackets[i]){ -#ifdef VERYDEBUG +//#ifdef VERYDEBUG cprintf(RED, "Dummy packet: %d from fifo %d\n", numpackets[i],i); -#endif - cout<<"tempoffset["<num3))); exit(-1); }else - /*cprintf(GREEN, "blank packet i:%d pnum:%d fnum:%d num3:0x%x\n",i,tempoffset[i],tempframenum[i],(*(uint8_t*)(((eiger_packet_header *)((char*)(tempbuffer[tempoffset[i]])))->num3))); -*/ +//#ifdef PADDING + cprintf(GREEN, "blank packet i:%d pnum:%d fnum:%d num3:0x%x\n",i,tempoffset[i],tempframenum[i],(*(uint8_t*)(((eiger_packet_header *)((char*)(tempbuffer[tempoffset[i]])))->num3))); +//#endif tempoffset[i]++; blankoffset++; } @@ -2169,12 +2173,12 @@ int UDPStandardImplementation::startWriting(){ popready[i] = false; } } -#ifdef EIGER_DEBUG3 +//#ifdef EIGER_DEBUG3 else{ cprintf(RED, "WARNING: Got a weird packet size: %d from fifo %d\n", numpackets[i],i); continue; } -#endif +//#endif } @@ -2195,13 +2199,17 @@ int UDPStandardImplementation::startWriting(){ //WRONG FRAME - leave - if(tempframenum[i] != presentframenum){/*cout<<"wrong packet"<num1))), ((*(uint8_t*)(((eiger_packet_header *)((char*)(wbuf[i] + HEADER_SIZE_NUM_TOT_PACKETS)))->num4)))); -#endif +//#endif tempframenum[i] = presentframenum; //add missing packets numberofmissingpackets[i] = (LAST_PACKET_VALUE - lastpacketheader[i]); @@ -2226,11 +2234,12 @@ int UDPStandardImplementation::startWriting(){ (void*)(tempbuffer[tempoffset[i]])); exit(-1); }else - /*cprintf(GREEN, "blank packet i:%d pnum:%d fnum:%d num3:0x%x add:0x%x\n", +//#ifdef PADDING + cprintf(GREEN, "blank packet i:%d pnum:%d fnum:%d num3:0x%x add:0x%x\n", i,tempoffset[i],tempframenum[i], (*(uint8_t*)(((eiger_packet_header *)((char*)(tempbuffer[tempoffset[i]])))->num3)), - (void*)(tempbuffer[tempoffset[i]]));*/ - + (void*)(tempbuffer[tempoffset[i]])); +//#endif tempoffset[i] ++; blankoffset ++; } @@ -2241,10 +2250,13 @@ int UDPStandardImplementation::startWriting(){ //CORRECT FRAME - continue building frame - else {/*cout<<"correct packet"<num4))); #ifdef VERYVERBOSE @@ -2273,10 +2285,12 @@ int UDPStandardImplementation::startWriting(){ (void*)(tempbuffer[tempoffset[i]])); exit(-1); }else - /* cprintf(GREEN, "blank packet i:%d pnum:%d fnum:%d num3:0x%x add:0x%x\n", +//#ifdef PADDING + cprintf(GREEN, "blank packet i:%d pnum:%d fnum:%d num3:0x%x add:0x%x\n", i,tempoffset[i],tempframenum[i], (*(uint8_t*)(((eiger_packet_header *)((char*)(tempbuffer[tempoffset[i]])))->num3)), - (void*)(tempbuffer[tempoffset[i]]));*/ + (void*)(tempbuffer[tempoffset[i]])); +//#endif tempoffset[i] ++; blankoffset ++; } @@ -2298,10 +2312,12 @@ int UDPStandardImplementation::startWriting(){ tempframenum[i],(void*)(tempbuffer[tempoffset[i]])); exit(-1); } - /*cprintf(GREEN, "normal packet i:%d pnum:%d fnum:%d num3:0x%x add:0x%x\n", +//#ifdef PADDING + cprintf(GREEN, "normal packet i:%d pnum:%d fnum:%d num3:0x%x add:0x%x\n", i,tempoffset[i],tempframenum[i], (*(uint8_t*)(((eiger_packet_header *)((char*)(tempbuffer[tempoffset[i]])))->num3)), - (void*)(tempbuffer[tempoffset[i]]));*/ + (void*)(tempbuffer[tempoffset[i]])); +//#endif tempoffset[i] ++; //update last packet lastpacketheader[i] = currentpacketheader[i]; @@ -2331,10 +2347,10 @@ int UDPStandardImplementation::startWriting(){ numMissingPackets += (numberofmissingpackets[0]+numberofmissingpackets[1]); numTotMissingPacketsInFile += numMissingPackets; numTotMissingPackets += numMissingPackets; -#ifdef EIGER_DEBUG2 +//#ifdef EIGER_DEBUG2 cprintf(GREEN,"**fnum:%d**\n",currframenum); -#endif -#ifdef EIGER_DEBUG3 +//#endif +//#ifdef EIGER_DEBUG3 if(numberofmissingpackets[0]) cprintf(RED, "fifo 0 missing packets:%d fnum:%d\n",numberofmissingpackets[0],currframenum); if(numberofmissingpackets[1]) @@ -2346,7 +2362,7 @@ int UDPStandardImplementation::startWriting(){ if ((*(uint8_t*)(((eiger_packet_header *)((char*)(tempbuffer[j])))->num3))&0x2) cprintf(RED,"found the missing packet at pnum:%d\n",j); } -#endif +//#endif //write and copy to gui @@ -2366,9 +2382,9 @@ int UDPStandardImplementation::startWriting(){ cprintf(GREEN,"%d writer freed pushed into fifofree %x for listener %d\n",ithread, (void*)(tofree[j]),1); #endif } -#ifdef VERYDEBUG +//#ifdef VERYDEBUG cprintf(GREEN,"finished freeing\n"); -#endif +//#endif //reset a few stuff @@ -2388,11 +2404,13 @@ int UDPStandardImplementation::startWriting(){ } } - /* for(int i=0;inum1)))); cprintf(GREEN,"packetnum[%d]:%d\n",i,((*(uint8_t*)(((eiger_packet_header *)((char*)(wbuf[i] + HEADER_SIZE_NUM_TOT_PACKETS)))->num4)))); - }*/ + } +//#endif } @@ -2955,11 +2973,12 @@ void UDPStandardImplementation::handleWithoutDataCompression(int ithread, char* cprintf(GREEN, "%d packet header:0x%016llx num3:0x%x\n",i, ((uint64_t)(*((uint64_t*)(wbuffer[i])))), (uint8_t)(*(uint8_t*)(((eiger_packet_header *)((char*)(wbuffer[i])))->num3))); + + cprintf(GREEN, "%d - 0x%x - %d - %d\n", i, + (*(uint8_t*)(((eiger_packet_header *)((char*)(wbuffer[i])))->num3)), + (*(uint8_t*)(((eiger_packet_header *)((char*)(wbuffer[i])))->num4)), + (*(uint16_t*)(((eiger_packet_header *)((char*)(wbuffer[i])))->num2))); } - cprintf(GREEN, "%d - 0x%x - %d - %d\n", i, - (*(uint8_t*)(((eiger_packet_header *)((char*)(wbuffer[i])))->num3)), - (*(uint8_t*)(((eiger_packet_header *)((char*)(wbuffer[i])))->num4)), - (*(uint16_t*)(((eiger_packet_header *)((char*)(wbuffer[i])))->num2))); #endif /* cprintf(GREEN,"at writing, fnum:%d, pnum:%d,num3:0x%x add:0x%x\n", From 74366b3cfe326684a88dce83f3df813153838878 Mon Sep 17 00:00:00 2001 From: Dhanya Maliakal Date: Thu, 3 Sep 2015 12:00:37 +0200 Subject: [PATCH 20/68] halfway into new server --- .../include/UDPBaseImplementation.h | 33 +-- .../include/UDPStandardImplementation.h | 2 - .../src/UDPBaseImplementation.cpp | 91 ------- .../src/UDPStandardImplementation.cpp | 225 +++++++----------- .../src/slsReceiverTCPIPInterface.cpp | 1 - 5 files changed, 105 insertions(+), 247 deletions(-) diff --git a/slsReceiverSoftware/include/UDPBaseImplementation.h b/slsReceiverSoftware/include/UDPBaseImplementation.h index 38adefe90..3dd655f54 100644 --- a/slsReceiverSoftware/include/UDPBaseImplementation.h +++ b/slsReceiverSoftware/include/UDPBaseImplementation.h @@ -483,25 +483,25 @@ protected: //// Could be done more fine-grained... TODO // private: protected: - /** structure of an eiger image header*/ + /** structure of an eiger packet*/ typedef struct { - unsigned char header_before1[5]; - unsigned char header_confirm[1]; - unsigned char header_before2[14]; - //unsigned char header_before[20]; - unsigned char fnum[4]; - unsigned char header_after[24]; - } eiger_image_header; + unsigned char subframenum[4]; + unsigned char missingpacket[2]; + unsigned char portnum[1]; + unsigned char dynamicrange[1]; + } eiger_packet_header_t; - /** structure of an eiger image header*/ typedef struct { - unsigned char num1[4]; - unsigned char num2[2]; - unsigned char num3[1]; - unsigned char num4[1]; - } eiger_packet_header; + unsigned char framenum[6]; + unsigned char packetnum[2]; + } eiger_packet_footer_t; + + eiger_packet_header_t* eiger_packet_header; + unsigned char* eiger_packet_data; + eiger_packet_footer_t* eiger_packet_footer; + /** max number of listening threads */ const static int MAX_NUM_LISTENING_THREADS = EIGER_MAX_PORTS; @@ -626,9 +626,12 @@ protected: /** buffer size. different from framesize as we wait for one packet instead of frame for eiger */ int bufferSize; - /** oen buffer size */ + /** one buffer size */ int onePacketSize; + /** one buffer size */ + int oneDataSize; + /** latest data */ char* latestData; diff --git a/slsReceiverSoftware/include/UDPStandardImplementation.h b/slsReceiverSoftware/include/UDPStandardImplementation.h index 67443f21c..92092bead 100644 --- a/slsReceiverSoftware/include/UDPStandardImplementation.h +++ b/slsReceiverSoftware/include/UDPStandardImplementation.h @@ -485,8 +485,6 @@ private: void handleDataCompression(int ithread, char* wbuffer[], char* data, int xmax, int ymax, int &nf); - - public: diff --git a/slsReceiverSoftware/src/UDPBaseImplementation.cpp b/slsReceiverSoftware/src/UDPBaseImplementation.cpp index 40152f581..c59932b9d 100644 --- a/slsReceiverSoftware/src/UDPBaseImplementation.cpp +++ b/slsReceiverSoftware/src/UDPBaseImplementation.cpp @@ -1561,97 +1561,6 @@ int UDPBaseImplementation::startWriting(){ FILE_LOG(logDEBUG) << __AT__ << " sta while((1<pop(wbuf[i]); - numpackets = (uint16_t)(*((uint16_t*)wbuf[i])); -#ifdef VERYDEBUG - cout << ithread << " numpackets:" << dec << numpackets << endl; -#endif - } - -#ifdef VERYDEBUG - cout << ithread << " numpackets:" << dec << numpackets << endl; - cout << ithread << " *** writer popped from fifo " << (void*) wbuf[0]<< endl; - cout << ithread << " *** writer popped from fifo " << (void*) wbuf[1]<< endl; -#endif - - - //last dummy packet - if(numpackets == 0xFFFF){ - stopWriting(ithread,wbuf); - continue; - } - - - - - //for progress - if(myDetectorType == EIGER){ - tempframenum = htonl(*(unsigned int*)((eiger_image_header *)((char*)(wbuf[ithread] + HEADER_SIZE_NUM_TOT_PACKETS)))->fnum); - tempframenum += (startFrameIndex-1); //eiger frame numbers start at 1, so need to -1 - }else if ((myDetectorType == GOTTHARD) && (shortFrame == -1)) - tempframenum = (((((uint32_t)(*((uint32_t*)(wbuf[ithread] + HEADER_SIZE_NUM_TOT_PACKETS))))+1)& (frameIndexMask)) >> frameIndexOffset); - else - tempframenum = ((((uint32_t)(*((uint32_t*)(wbuf[ithread] + HEADER_SIZE_NUM_TOT_PACKETS))))& (frameIndexMask)) >> frameIndexOffset); - - if(numWriterThreads == 1) - currframenum = tempframenum; - else{ - pthread_mutex_lock(&progress_mutex); - if(tempframenum > currframenum) - currframenum = tempframenum; - pthread_mutex_unlock(&progress_mutex); - } -//#ifdef VERYDEBUG - if(myDetectorType == EIGER) - cout << endl < 0){ - for(i=0;ipush(wbuf[i])); -#ifdef VERYDEBUG - cout << ithread << ":" << i+j << " fifo freed:" << (void*)wbuf[i] << endl; -#endif - } - - - } - else{ - //copy to gui - copyFrameToGui(NULL,-1,wbuf[0]+HEADER_SIZE_NUM_TOT_PACKETS); -#ifdef VERYVERBOSE - cout << ithread << " finished copying" << endl; -#endif - while(!fifoFree[0]->push(wbuf[0])); -#ifdef VERYVERBOSE - cout<<"buf freed:"<<(void*)wbuf[0]< #include - +#include using namespace std; @@ -39,7 +39,6 @@ UDPStandardImplementation::UDPStandardImplementation() //guiFrameNumber(0), //tengigaEnable(0) { - thread_started = 0; eth = NULL; latestData = NULL; @@ -141,6 +140,7 @@ void UDPStandardImplementation::initializeMembers(){ frameSize = 0; bufferSize = 0; onePacketSize = 0; + oneDataSize = 0; guiDataReady = 0; nFrameToGui = 0; fifosize = 0; @@ -200,6 +200,7 @@ void UDPStandardImplementation::initializeMembers(){ //strcpy(fileName,"run"); + //status pthread_mutex_lock(&status_mutex); status = IDLE; @@ -246,6 +247,7 @@ void UDPStandardImplementation::deleteMembers(){ FILE_LOG(logDEBUG) << __AT__ < if(fifo[i]) {delete fifo[i]; fifo[i] = NULL;} if(fifoFree[i]) {delete fifoFree[i]; fifoFree[i] = NULL;} } + } @@ -323,6 +325,7 @@ int UDPStandardImplementation::setDetectorType(detectorType det){ FILE_LOG(logD fifosize = EIGER_FIFO_SIZE; packetsPerFrame = EIGER_ONE_GIGA_CONSTANT * dynamicRange * EIGER_MAX_PORTS; onePacketSize = EIGER_ONE_GIGA_ONE_PACKET_SIZE; + oneDataSize = EIGER_ONE_GIGA_ONE_DATA_SIZE; frameSize = onePacketSize * packetsPerFrame; bufferSize = (frameSize/EIGER_MAX_PORTS) + EIGER_HEADER_LENGTH;//everything one port gets (img header plus packets) maxPacketsPerFile = EIGER_MAX_FRAMES_PER_FILE * packetsPerFrame; @@ -337,6 +340,8 @@ int UDPStandardImplementation::setDetectorType(detectorType det){ FILE_LOG(logD createListeningThreads(true); numListeningThreads = MAX_NUM_LISTENING_THREADS; + + } else if(myDetectorType == JUNGFRAUCTB || myDetectorType == JUNGFRAU ){ fifosize = JCTB_FIFO_SIZE; packetsPerFrame = JCTB_PACKETS_PER_FRAME; @@ -1004,13 +1009,6 @@ cout << "copyframe" << endl; for(int j=0;jReceiveDataOnly(buffer[ithread] + HEADER_SIZE_NUM_TOT_PACKETS, maxBufferSize); - /*cprintf(MAGENTA,"%d got a header*****************************\n",ithread); - cprintf(MAGENTA,"tempframenum[%d]:%d\n",ithread,(htonl(*(uint32_t*)(((eiger_image_header *)((char*)(buffer[ithread] + HEADER_SIZE_NUM_TOT_PACKETS)))->fnum)))); - */} + } } - /* if(rc == 1040){ - cprintf(CYAN,"tempframenum[%d]:%d\n",ithread,((*(uint32_t*)(((eiger_packet_header *)((char*)(buffer[ithread] + HEADER_SIZE_NUM_TOT_PACKETS)))->num1)))); - cprintf(CYAN,"packetnum[%d]:%d\n",ithread,((*(uint8_t*)(((eiger_packet_header *)((char*)(buffer[ithread] + HEADER_SIZE_NUM_TOT_PACKETS)))->num4)))); - cprintf(CYAN,"add[%d]:0x%x\n",ithread,(void*)(buffer[ithread])); - }*/ expected = maxBufferSize; #ifdef SOCKET_DEBUG }else{ @@ -1908,9 +1899,6 @@ int UDPStandardImplementation::startListening(){ cprintf(BLUE,"%d listener going to push fifo: 0x%x\n", ithread,(void*)(buffer[ithread])); #endif while(!fifo[ithread]->push(buffer[ithread])); - /*cprintf(YELLOW,"tempframenum[%d]:%d\n",ithread,((*(uint32_t*)(((eiger_packet_header *)((char*)(buffer[ithread] + HEADER_SIZE_NUM_TOT_PACKETS)))->num1)))); - cprintf(YELLOW,"packetnum[%d]:%d\n",ithread,((*(uint8_t*)(((eiger_packet_header *)((char*)(buffer[ithread] + HEADER_SIZE_NUM_TOT_PACKETS)))->num4)))); - cprintf(YELLOW,"add[%d]:0x%x\n",ithread,(void*)(buffer[ithread]));*/ #ifdef FIFO_DEBUG cprintf(BLUE, "%d listener pushed into fifo %x\n",ithread, (void*)(buffer[ithread])); #endif @@ -2019,15 +2007,24 @@ int UDPStandardImplementation::startWriting(){ //blank frame if(myDetectorType == EIGER){ + for(i=0;inum3)) = 0xFF; - for(j=0;j<(onePacketSize-16);++j) - (*((uint8_t*)((char*)(blankframe[i])+8+j))) = 0xFF; - if ((*(uint8_t*)(((eiger_packet_header *)((char*)(blankframe[i])))->num3)) != 0xFF){ - cprintf(RED,"blank frame not detected at %d: 0x%x\n",i,(*(uint8_t*)(((eiger_packet_header *)((char*)(blankframe[i])))->num3)) ); + //blank frame for each packet + blankframe[i] = new char[onePacketSize]; + eiger_packet_header = (eiger_packet_header_t*) blankframe[i]; + //set missing packet to 0xff + *( (uint16_t*) eiger_packet_header->missingpacket) = 0xFF; + + //set each value inside blank frame to 0xff + for(j=0;j<(oneDataSize);++j){ + eiger_packet_data = blankframe[i] + sizeof(eiger_packet_header_t) + j; + *(eiger_packet_data) = 0xFF; + } + //verify + if (*( (uint16_t*) eiger_packet_header->missingpacket) != 0xFF){ + cprintf(RED,"blank frame not detected at %d: 0x%x\n",i,*( (uint16_t*) eiger_packet_header->missingpacket) ); exit(-1); } #ifdef FIFO_DEBUG @@ -2084,8 +2081,8 @@ int UDPStandardImplementation::startWriting(){ }else{ endofacquisition = false; if(numpackets[i] == 1040){ - cprintf(BLUE,"tempframenum[%d]:%d\n",i,((*(uint32_t*)(((eiger_packet_header *)((char*)(wbuf[i] + HEADER_SIZE_NUM_TOT_PACKETS)))->num1)))); - cprintf(BLUE,"packetnum[%d]:%d\n",i,((*(uint8_t*)(((eiger_packet_header *)((char*)(wbuf[i] + HEADER_SIZE_NUM_TOT_PACKETS)))->num4)))); + cprintf(BLUE,"tempframenum[%d]:%d\n",i,((*(uint32_t*)(((eiger_packet_1g *)((char*)(wbuf[i] + HEADER_SIZE_NUM_TOT_PACKETS)))->framenum)))); + cprintf(BLUE,"packetnum[%d]:%d\n",i,((*(uint16_t*)(((eiger_packet_1g *)((char*)(wbuf[i] + HEADER_SIZE_NUM_TOT_PACKETS)))->packetnum)))); }else if(numpackets[i] == EIGER_HEADER_LENGTH){ cprintf(BG_RED, "got header in writer, weirdd packetsize:%d\n",numpackets[i]); exit(-1); @@ -2151,19 +2148,19 @@ int UDPStandardImplementation::startWriting(){ for(j=0;jnum3))&0x2) + if (*(uint8_t*)(((eiger_packet_1g *)((char*)(tempbuffer[tempoffset[i]])))->missingpacket)) cprintf(RED,"1 fifo:%d missing packet added at pnum:%d\n",i,tempoffset[i]); else cprintf(RED, "1 fifo:%d Weird at pnum:%d\n",i,tempoffset[i]); #endif - if (!((*(uint8_t*)(((eiger_packet_header *)((char*)(tempbuffer[tempoffset[i]])))->num3))&0x2)){ - cprintf(BG_RED, "dummy blank mismatch num4 earlier2! i:%d pnum:%d fnum:%d num3:0x%x actual num3:0x%x\n", + if ((*(uint8_t*)(((eiger_packet_1g *)((char*)(tempbuffer[tempoffset[i]])))->missingpacket))!= 0xFF){ + cprintf(BG_RED, "dummy blank mismatch num4 earlier2! i:%d pnum:%d fnum:%d missingpacket:0x%x actual missingpacket:0x%x\n", i,tempoffset[i],tempframenum[i], - (*(uint8_t*)(((eiger_packet_header *)((char*)(tempbuffer[tempoffset[i]])))->num3)), - (*(uint8_t*)(((eiger_packet_header *)((char*)(blankframe[blankoffset])))->num3))); + (*(uint8_t*)(((eiger_packet_1g *)((char*)(tempbuffer[tempoffset[i]])))->missingpacket)), + (*(uint8_t*)(((eiger_packet_1g *)((char*)(blankframe[blankoffset])))->missingpacket))); exit(-1); }else //#ifdef PADDING - cprintf(GREEN, "blank packet i:%d pnum:%d fnum:%d num3:0x%x\n",i,tempoffset[i],tempframenum[i],(*(uint8_t*)(((eiger_packet_header *)((char*)(tempbuffer[tempoffset[i]])))->num3))); + cprintf(GREEN, "blank packet i:%d pnum:%d fnum:%d missingpacket:0x%x\n",i,tempoffset[i],tempframenum[i],(*(uint8_t*)(((eiger_packet_1g *)((char*)(tempbuffer[tempoffset[i]])))->missingpacket))); //#endif tempoffset[i]++; blankoffset++; @@ -2189,8 +2186,7 @@ int UDPStandardImplementation::startWriting(){ if(!fullframe[i]){ //update frame number - //tempframenum[i] = (htonl(*(uint32_t*)(((eiger_packet_header *)((char*)(wbuf[i] + HEADER_SIZE_NUM_TOT_PACKETS)))->num1))); - tempframenum[i] = ((*(uint32_t*)(((eiger_packet_header *)((char*)(wbuf[i] + HEADER_SIZE_NUM_TOT_PACKETS)))->num1))); + tempframenum[i] = ((*(uint32_t*)(((eiger_packet_1g *)((char*)(wbuf[i] + HEADER_SIZE_NUM_TOT_PACKETS)))->framenum))); if(!tempframenum[i]) @@ -2207,8 +2203,8 @@ int UDPStandardImplementation::startWriting(){ //#ifdef EIGER_DEBUG3 cprintf(RED,"fifo:%d packet from next frame %d, add missing packets to the right one %d\n",i,tempframenum[i],presentframenum ); cprintf(RED,"current wrong frame:%d wrong frame packet number:%d\n", - ((*(uint32_t*)(((eiger_packet_header *)((char*)(wbuf[i] + HEADER_SIZE_NUM_TOT_PACKETS)))->num1))), - ((*(uint8_t*)(((eiger_packet_header *)((char*)(wbuf[i] + HEADER_SIZE_NUM_TOT_PACKETS)))->num4)))); + ((*(uint32_t*)(((eiger_packet_1g *)((char*)(wbuf[i] + HEADER_SIZE_NUM_TOT_PACKETS)))->framenum))), + ((*(uint16_t*)(((eiger_packet_1g *)((char*)(wbuf[i] + HEADER_SIZE_NUM_TOT_PACKETS)))->packetnum)))); //#endif tempframenum[i] = presentframenum; //add missing packets @@ -2221,23 +2217,23 @@ int UDPStandardImplementation::startWriting(){ for(j=0;jnum3))&0x2) + if ((*(uint8_t*)(((eiger_packet_1g *)((char*)(tempbuffer[tempoffset[i]])))->missingpacket))== 0xFF) cprintf(RED,"5 fifo:%d missing packet added at pnum:%d\n",i,tempoffset[i]); else cprintf(RED, "5 fifo:%d WEird at pnum:%d\n",i,tempoffset[i]); #endif - if (!((*(uint8_t*)(((eiger_packet_header *)((char*)(tempbuffer[tempoffset[i]])))->num3))&0x2)){ + if ((*(uint8_t*)(((eiger_packet_1g *)((char*)(tempbuffer[tempoffset[i]])))->missingpacket))!= 0xFF){ cprintf(BG_RED, "wrong blank mismatch num4 earlier2! " - "i:%d pnum:%d fnum:%d num3:0x%x actual num3:0x%x add:0x%x\n", + "i:%d pnum:%d fnum:%d missingpacket:0x%x actual missingpacket:0x%x add:0x%x\n", i,tempoffset[i],tempframenum[i], - (*(uint8_t*)(((eiger_packet_header *)((char*)(tempbuffer[tempoffset[i]])))->num3)), - (*(uint8_t*)(((eiger_packet_header *)((char*)(blankframe[blankoffset])))->num3)), + (*(uint8_t*)(((eiger_packet_1g *)((char*)(tempbuffer[tempoffset[i]])))->missingpacket)), + (*(uint8_t*)(((eiger_packet_1g *)((char*)(blankframe[blankoffset])))->missingpacket)), (void*)(tempbuffer[tempoffset[i]])); exit(-1); }else //#ifdef PADDING - cprintf(GREEN, "blank packet i:%d pnum:%d fnum:%d num3:0x%x add:0x%x\n", + cprintf(GREEN, "blank packet i:%d pnum:%d fnum:%d missingpacket:0x%x add:0x%x\n", i,tempoffset[i],tempframenum[i], - (*(uint8_t*)(((eiger_packet_header *)((char*)(tempbuffer[tempoffset[i]])))->num3)), + (*(uint8_t*)(((eiger_packet_1g *)((char*)(tempbuffer[tempoffset[i]])))->missingpacket)), (void*)(tempbuffer[tempoffset[i]])); //#endif tempoffset[i] ++; @@ -2258,7 +2254,7 @@ int UDPStandardImplementation::startWriting(){ cprintf(GREEN,"**tempfraemnum of %d: %d\n",i,tempframenum[i]); //#endif //update current packet - currentpacketheader[i] = ((*(uint8_t*)(((eiger_packet_header *)((char*)(wbuf[i] + HEADER_SIZE_NUM_TOT_PACKETS)))->num4))); + currentpacketheader[i] = ((*(uint16_t*)(((eiger_packet_1g *)((char*)(wbuf[i] + HEADER_SIZE_NUM_TOT_PACKETS)))->packetnum))); #ifdef VERYVERBOSE cprintf(GREEN,"**fifo:%d currentpacketheader: %d lastpacketheader %d tempoffset:%d\n",i,currentpacketheader[i],lastpacketheader[i], tempoffset[i]); #endif @@ -2272,23 +2268,23 @@ int UDPStandardImplementation::startWriting(){ for(j=0;jnum3))&0x2) + if ((*(uint8_t*)(((eiger_packet_1g *)((char*)(tempbuffer[tempoffset[i]])))->missingpacket)) ==0xFF) cprintf(RED,"4 fifo:%d missing packet added at pnum:%d\n",i,tempoffset[i]); else cprintf(RED, "4 fifo:%d WEird at pnum:%d\n",i,tempoffset[i]); #endif - if (!((*(uint8_t*)(((eiger_packet_header *)((char*)(tempbuffer[tempoffset[i]])))->num3))&0x2)){ + if ((*(uint8_t*)(((eiger_packet_1g *)((char*)(tempbuffer[tempoffset[i]])))->missingpacket))!= 0xFF){ cprintf(BG_RED, "correct blank mismatch num4 earlier2! " - "i:%d pnum:%d fnum:%d num3:0x%x actual num3:0x%x add:0x%x\n", + "i:%d pnum:%d fnum:%d missingpacket:0x%x actual missingpacket:0x%x add:0x%x\n", i,tempoffset[i],tempframenum[i], - (*(uint8_t*)(((eiger_packet_header *)((char*)(tempbuffer[tempoffset[i]])))->num3)), - (*(uint8_t*)(((eiger_packet_header *)((char*)(blankframe[blankoffset])))->num3)), + (*(uint8_t*)(((eiger_packet_1g *)((char*)(tempbuffer[tempoffset[i]])))->missingpacket)), + (*(uint8_t*)(((eiger_packet_1g *)((char*)(blankframe[blankoffset])))->missingpacket)), (void*)(tempbuffer[tempoffset[i]])); exit(-1); }else //#ifdef PADDING - cprintf(GREEN, "blank packet i:%d pnum:%d fnum:%d num3:0x%x add:0x%x\n", + cprintf(GREEN, "blank packet i:%d pnum:%d fnum:%d missingpacket:0x%x add:0x%x\n", i,tempoffset[i],tempframenum[i], - (*(uint8_t*)(((eiger_packet_header *)((char*)(tempbuffer[tempoffset[i]])))->num3)), + (*(uint8_t*)(((eiger_packet_1g *)((char*)(tempbuffer[tempoffset[i]])))->missingpacket)), (void*)(tempbuffer[tempoffset[i]])); //#endif tempoffset[i] ++; @@ -2299,23 +2295,23 @@ int UDPStandardImplementation::startWriting(){ if(currentpacketheader[i] != (tempoffset[i]-(i*packetsPerFrame/numListeningThreads))){ cprintf(BG_RED, "correct pnum mismatch earlier! tempoffset[%d]:%d pnum:%d fnum:%d rfnum:%d\n", i,tempoffset[i],currentpacketheader[i], - tempframenum[i],(*(uint32_t*)(((eiger_packet_header *)((char*)(wbuf[i]+ HEADER_SIZE_NUM_TOT_PACKETS)))->num1))); + tempframenum[i],(*(uint32_t*)(((eiger_packet_1g *)((char*)(wbuf[i]+ HEADER_SIZE_NUM_TOT_PACKETS)))->framenum))); exit(-1); } tempbuffer[tempoffset[i]] = wbuf[i] + HEADER_SIZE_NUM_TOT_PACKETS; #ifdef EIGER_DEBUG3 - cprintf(GREEN,"**fifo:%d currentpacketheader: %d tempoffset:%d\n",i,(*(uint8_t*)(((eiger_packet_header *)((char*)(tempbuffer[tempoffset[i]])))->num4)),tempoffset[i]); + cprintf(GREEN,"**fifo:%d currentpacketheader: %d tempoffset:%d\n",i,(*(uint16_t*)(((eiger_packet_1g *)((char*)(tempbuffer[tempoffset[i]])))->packetnum)),tempoffset[i]); #endif - if((*(uint8_t*)(((eiger_packet_header *)((char*)(tempbuffer[tempoffset[i]])))->num4)) != (tempoffset[i]-(i*packetsPerFrame/numListeningThreads))){ + if((*(uint16_t*)(((eiger_packet_1g *)((char*)(tempbuffer[tempoffset[i]])))->packetnum)) != (tempoffset[i]-(i*packetsPerFrame/numListeningThreads))){ cprintf(BG_RED, "pnum mismatch num4 earlier! i:%d pnum:%d fnum:%d add:0x%x\n", - i,(*(uint8_t*)(((eiger_packet_header *)((char*)(tempbuffer[tempoffset[i]])))->num4)), + i,(*(uint16_t*)(((eiger_packet_1g *)((char*)(tempbuffer[tempoffset[i]])))->packetnum)), tempframenum[i],(void*)(tempbuffer[tempoffset[i]])); exit(-1); } //#ifdef PADDING - cprintf(GREEN, "normal packet i:%d pnum:%d fnum:%d num3:0x%x add:0x%x\n", + cprintf(GREEN, "normal packet i:%d pnum:%d fnum:%d missingpacket:0x%x add:0x%x\n", i,tempoffset[i],tempframenum[i], - (*(uint8_t*)(((eiger_packet_header *)((char*)(tempbuffer[tempoffset[i]])))->num3)), + (*(uint8_t*)(((eiger_packet_1g *)((char*)(tempbuffer[tempoffset[i]])))->missingpacket)), (void*)(tempbuffer[tempoffset[i]])); //#endif tempoffset[i] ++; @@ -2359,7 +2355,7 @@ int UDPStandardImplementation::startWriting(){ cprintf(RED, "numMissingPackets:%d fnum:%d\n",numMissingPackets,currframenum); for (j=0;jnum3))&0x2) + if ((*(uint8_t*)(((eiger_packet_1g *)((char*)(tempbuffer[j])))->missingpacket))==0xFF) cprintf(RED,"found the missing packet at pnum:%d\n",j); } //#endif @@ -2407,8 +2403,8 @@ int UDPStandardImplementation::startWriting(){ //#ifdef VERYDEBUG for(int i=0;inum1)))); - cprintf(GREEN,"packetnum[%d]:%d\n",i,((*(uint8_t*)(((eiger_packet_header *)((char*)(wbuf[i] + HEADER_SIZE_NUM_TOT_PACKETS)))->num4)))); + cprintf(GREEN,"tempframenum[%d]:%d\n",i,((*(uint32_t*)(((eiger_packet_1g *)((char*)(wbuf[i] + HEADER_SIZE_NUM_TOT_PACKETS)))->framenum)))); + cprintf(GREEN,"packetnum[%d]:%d\n",i,((*(uint16_t*)(((eiger_packet_1g *)((char*)(wbuf[i] + HEADER_SIZE_NUM_TOT_PACKETS)))->packetnum)))); } //#endif } @@ -2735,53 +2731,7 @@ void UDPStandardImplementation::writeToFile_withoutCompression(char* buf[],int n if((enableFileWrite) && (sfilefd)){ offset = HEADER_SIZE_NUM_TOT_PACKETS; - if(myDetectorType == EIGER){ -#ifdef WRITE_HEADERS -#ifdef VERY_DEBUG - if(myDetectorType == EIGER){ - int k = 0; - if(dynamicRange != 32){ - cprintf(RED, "\np1 fnum:0x%x\n", (*(unsigned int*)(((eiger_packet_header *)((char*)(buf[k])))->num1))); - cprintf(RED, "p1:0x%x\n", (*(uint8_t*)(((eiger_packet_header *)((char*)(buf[k])))->num3))); - cprintf(RED, "p0 num:%d - %d\n", k, (*(uint8_t*)(((eiger_packet_header *)((char*)(buf[k])))->num4))); - k = 1; - cprintf(RED, "p2 fnum:0x%x\n", (*(unsigned int*)(((eiger_packet_header *)((char*)(buf[k])))->num1))); - cprintf(RED, "p2:0x%x\n", (*(uint8_t*)(((eiger_packet_header *)((char*)(buf[k])))->num3))); - cprintf(RED, "p1 num:%d - %d\n", k,(*(uint8_t*)(((eiger_packet_header *)((char*)(buf[k])))->num4))); - k = 2; - cprintf(RED, "p3 fnum:0x%x\n", (*(unsigned int*)(((eiger_packet_header *)((char*)(buf[k])))->num1))); - cprintf(RED, "p3:0x%x\n", (*(uint8_t*)(((eiger_packet_header *)((char*)(buf[k])))->num3))); - cprintf(RED, "p2 num:%d - %d\n", k,(*(uint8_t*)(((eiger_packet_header *)((char*)(buf[k])))->num4))); - }else{ - k = 0; - cprintf(RED, "\np1 fnum:0x%x\n", (*(unsigned int*)(((eiger_packet_header *)((char*)(buf[k])))->num1))); - cprintf(RED, "p1:0x%x\n", (*(uint8_t*)(((eiger_packet_header *)((char*)(buf[k])))->num3))); - cprintf(RED, "p0 num:%d - %d\n", k, (*(uint16_t*)(((eiger_packet_header *)((char*)(buf[k])))->num2))); - k = 1; - cprintf(RED, "p2 fnum:0x%x\n", (*(unsigned int*)(((eiger_packet_header *)((char*)(buf[k])))->num1))); - cprintf(RED, "p2:0x%x\n", (*(uint8_t*)(((eiger_packet_header *)((char*)(buf[k])))->num3))); - cprintf(RED, "p1 num:%d - %d\n", k, (*(uint16_t*)(((eiger_packet_header *)((char*)(buf[k])))->num2))); - k = 2; - cprintf(RED, "p3 fnum:0x%x\n", (*(unsigned int*)(((eiger_packet_header *)((char*)(buf[k])))->num1))); - cprintf(RED, "p3:0x%x\n", (*(uint8_t*)(((eiger_packet_header *)((char*)(buf[k])))->num3))); - cprintf(RED, "p2 num:%d - %d\n", k, (*(uint16_t*)(((eiger_packet_header *)((char*)(buf[k])))->num2))); - k = 256; - cprintf(RED, "p257 fnum:0x%x\n", (*(unsigned int*)(((eiger_packet_header *)((char*)(buf[k])))->num1))); - cprintf(RED, "p257:0x%x\n", (*(uint8_t*)(((eiger_packet_header *)((char*)(buf[k])))->num3))); - cprintf(RED, "p256 num:%d - %d\n", k, (*(uint16_t*)(((eiger_packet_header *)((char*)(buf[k])))->num2))); - k = 512; - cprintf(RED, "p513 fnum:0x%x\n", (*(unsigned int*)(((eiger_packet_header *)((char*)(buf[k])))->num1))); - cprintf(RED, "p513:0x%x\n", (*(uint8_t*)(((eiger_packet_header *)((char*)(buf[k])))->num3))); - cprintf(RED, "p512 num:%d - %d\n", k, (*(uint16_t*)(((eiger_packet_header *)((char*)(buf[k])))->num2))); - k = 768; - cprintf(RED, "p769 fnum:0x%x\n", (*(unsigned int*)(((eiger_packet_header *)((char*)(buf[k])))->num1))); - cprintf(RED, "p769:0x%x\n", (*(uint8_t*)(((eiger_packet_header *)((char*)(buf[k])))->num3))); - cprintf(RED, "p768 num:%d - %d\n", k,(*(uint16_t*)(((eiger_packet_header *)((char*)(buf[k])))->num2))); - } - } -#endif -#endif - } + while(numpackets > 0){ //for progress and packet loss calculation(new files) @@ -2913,29 +2863,29 @@ void UDPStandardImplementation::handleWithoutDataCompression(int ithread, char* //missing packet - if ((*(uint8_t*)(((eiger_packet_header *)((char*)(wbuffer[i])))->num3))&0x2){ + if ((*(uint8_t*)(((eiger_packet_1g *)((char*)(wbuffer[i])))->missingpacket))==0xFF){ missingpacket = 1; //add packet numbers - (*(uint16_t*)(((eiger_packet_header *)((char*)(wbuffer[i])))->num2)) = (i+1); - (*(uint32_t*)(((eiger_packet_header *)((char*)(wbuffer[i])))->num1)) = currframenum+1; + (*(uint16_t*)(((eiger_packet_1g *)((char*)(wbuffer[i])))->packetnum)) = (i+1); + (*(uint32_t*)(((eiger_packet_1g *)((char*)(wbuffer[i])))->framenum)) = currframenum+1; }else{ missingpacket = 0; - if((*(uint8_t*)(((eiger_packet_header *)((char*)(wbuffer[i])))->num4)) != (i-(port*packetsPerFrame/numListeningThreads))){ - cprintf(BG_RED, "pnum mismatch num4! i:%d pnum:%d fnum:%d\n",i,(*(uint8_t*)(((eiger_packet_header *)((char*)(wbuffer[i])))->num4)),currframenum); + if((*(uint16_t*)(((eiger_packet_1g *)((char*)(wbuffer[i])))->packetnum)) != (i-(port*packetsPerFrame/numListeningThreads))){ + cprintf(BG_RED, "pnum mismatch num4! i:%d pnum:%d fnum:%d\n",i,(*(uint16_t*)(((eiger_packet_1g *)((char*)(wbuffer[i])))->packetnum)),currframenum); exit(-1); } - if(dynamicRange != 32){ + /* if(dynamicRange != 32){*/ //move packet numbers to num2, and compensate for port1 starting pnum from 0 if(!port) - (*(uint16_t*)(((eiger_packet_header *)((char*)(wbuffer[i])))->num2)) = - ((*(uint8_t*)(((eiger_packet_header *)((char*)(wbuffer[i])))->num4))+1); + (*(uint16_t*)(((eiger_packet_1g *)((char*)(wbuffer[i])))->packetnum)) = + ((*(uint16_t*)(((eiger_packet_1g *)((char*)(wbuffer[i])))->packetnum))+1); else - (*(uint16_t*)(((eiger_packet_header *)((char*)(wbuffer[i])))->num2)) = - ((*(uint8_t*)(((eiger_packet_header *)((char*)(wbuffer[i])))->num4))+(packetsPerFrame/2) +1); - } + (*(uint16_t*)(((eiger_packet_1g *)((char*)(wbuffer[i])))->packetnum)) = + ((*(uint16_t*)(((eiger_packet_1g *)((char*)(wbuffer[i])))->packetnum))+(packetsPerFrame/2) +1); + /*} //dr == 32 else{ if(i == 0) @@ -2946,43 +2896,42 @@ void UDPStandardImplementation::handleWithoutDataCompression(int ithread, char* pnuminc = (packetsPerFrame/2); else if(i == (3*packetsPerFrame/4)) pnuminc = (3*packetsPerFrame/4); - (*(uint16_t*)(((eiger_packet_header *)((char*)(wbuffer[i])))->num2)) - = ((*(uint8_t*)(((eiger_packet_header *)((char*)(wbuffer[i])))->num4))+pnuminc+1); + (*(uint16_t*)(((eiger_packet_1g *)((char*)(wbuffer[i])))->packetnum)) + = ((*(uint8_t*)(((eiger_packet_1g *)((char*)(wbuffer[i])))->packetnum,))+pnuminc+1); - } + }*/ } - if((*(uint16_t*)(((eiger_packet_header *)((char*)(wbuffer[i])))->num2)) != (i+1)){ - cprintf(BG_RED, "pnum mismatch! i:%d pnum:%d fnum:%d\n",i,(*(uint16_t*)(((eiger_packet_header *)((char*)(wbuffer[i])))->num2)),currframenum); - if ((*(uint8_t*)(((eiger_packet_header *)((char*)(wbuffer[i])))->num3))&0x2) + if((*(uint16_t*)(((eiger_packet_1g *)((char*)(wbuffer[i])))->packetnum)) != (i+1)){ + cprintf(BG_RED, "pnum mismatch! i:%d pnum:%d fnum:%d\n",i,(*(uint16_t*)(((eiger_packet_1g *)((char*)(wbuffer[i])))->packetnum)),currframenum); + if ((*(uint8_t*)(((eiger_packet_1g *)((char*)(wbuffer[i])))->missingpacket))==0xFF) cprintf(BG_RED,"missing packet though\n"); exit(-1); } //overwriting port number and dynamic range - (*(uint8_t*)(((eiger_packet_header *)((char*)(wbuffer[i])))->num3)) = + (*(uint8_t*)(((eiger_packet_1g *)((char*)(wbuffer[i])))->missingpacket)) = ((dynamicRange<<2)|(missingpacket<<1)|(port)); //frame number - //(*(uint32_t*)(((eiger_packet_header *)((char*)(wbuffer[i])))->num1)) = currframenum; + //(*(uint32_t*)(((eiger_packet_1g *)((char*)(wbuffer[i])))->framenum)) = currframenum; #ifdef VERYDEBUG if((i==0)||(i==1)){ - cprintf(GREEN, "%d packet header:0x%016llx num3:0x%x\n",i, + cprintf(GREEN, "%d packet header:0x%016llx missingpacket:0x%x\n",i, ((uint64_t)(*((uint64_t*)(wbuffer[i])))), - (uint8_t)(*(uint8_t*)(((eiger_packet_header *)((char*)(wbuffer[i])))->num3))); + (uint8_t)(*(uint8_t*)(((eiger_packet_1g *)((char*)(wbuffer[i])))->missingpacket))); - cprintf(GREEN, "%d - 0x%x - %d - %d\n", i, - (*(uint8_t*)(((eiger_packet_header *)((char*)(wbuffer[i])))->num3)), - (*(uint8_t*)(((eiger_packet_header *)((char*)(wbuffer[i])))->num4)), - (*(uint16_t*)(((eiger_packet_header *)((char*)(wbuffer[i])))->num2))); + cprintf(GREEN, "%d - 0x%x - %d\n", i, + (*(uint8_t*)(((eiger_packet_1g *)((char*)(wbuffer[i])))->missingpacket)), + (*(uint16_t*)(((eiger_packet_1g *)((char*)(wbuffer[i])))->packetnum))); } #endif /* - cprintf(GREEN,"at writing, fnum:%d, pnum:%d,num3:0x%x add:0x%x\n", - currframenum, i, (*(uint8_t*)(((eiger_packet_header *)((char*)(wbuffer[i])))->num3)), + cprintf(GREEN,"at writing, fnum:%d, pnum:%d,missingpacket:0x%x add:0x%x\n", + currframenum, i, (*(uint8_t*)(((eiger_packet_1g *)((char*)(wbuffer[i])))->missingpacket)), (void*)(wbuffer[i])); */ @@ -3148,9 +3097,11 @@ int UDPStandardImplementation::enableTenGiga(int enable){ if(!tengigaEnable){ packetsPerFrame = EIGER_ONE_GIGA_CONSTANT * dynamicRange * EIGER_MAX_PORTS; onePacketSize = EIGER_ONE_GIGA_ONE_PACKET_SIZE; + oneDataSize = EIGER_ONE_GIGA_ONE_DATA_SIZE; }else{ packetsPerFrame = EIGER_TEN_GIGA_CONSTANT * dynamicRange * EIGER_MAX_PORTS; onePacketSize = EIGER_TEN_GIGA_ONE_PACKET_SIZE; + oneDataSize = EIGER_TEN_GIGA_ONE_DATA_SIZE; } frameSize = onePacketSize * packetsPerFrame; bufferSize = (frameSize/EIGER_MAX_PORTS) + EIGER_HEADER_LENGTH;//everything one port gets (img header plus packets) @@ -3202,5 +3153,3 @@ int UDPStandardImplementation::enableTenGiga(int enable){ return tengigaEnable; } - - diff --git a/slsReceiverSoftware/src/slsReceiverTCPIPInterface.cpp b/slsReceiverSoftware/src/slsReceiverTCPIPInterface.cpp index 3d16a3c4f..ea0336895 100644 --- a/slsReceiverSoftware/src/slsReceiverTCPIPInterface.cpp +++ b/slsReceiverSoftware/src/slsReceiverTCPIPInterface.cpp @@ -1570,7 +1570,6 @@ int slsReceiverTCPIPInterface::eiger_read_frame(){ char fName[MAX_STR_LENGTH]=""; int acquisitionIndex = -1; int frameIndex= -1; - int i; uint32_t index=0; int frameSize = EIGER_ONE_GIGA_ONE_PACKET_SIZE * packetsPerFrame; From 572b6fe29f9422bbd46ecab4bd37c6539f216520 Mon Sep 17 00:00:00 2001 From: Dhanya Maliakal Date: Thu, 10 Sep 2015 14:05:10 +0200 Subject: [PATCH 21/68] f --- slsReceiverSoftware/include/UDPBaseImplementation.h | 4 ---- 1 file changed, 4 deletions(-) diff --git a/slsReceiverSoftware/include/UDPBaseImplementation.h b/slsReceiverSoftware/include/UDPBaseImplementation.h index 3dd655f54..d68f1c6d4 100644 --- a/slsReceiverSoftware/include/UDPBaseImplementation.h +++ b/slsReceiverSoftware/include/UDPBaseImplementation.h @@ -498,10 +498,6 @@ protected: unsigned char packetnum[2]; } eiger_packet_footer_t; - eiger_packet_header_t* eiger_packet_header; - unsigned char* eiger_packet_data; - eiger_packet_footer_t* eiger_packet_footer; - /** max number of listening threads */ const static int MAX_NUM_LISTENING_THREADS = EIGER_MAX_PORTS; From fe76ce96504d31f03ba89c5b9465ffdd338c65c6 Mon Sep 17 00:00:00 2001 From: Dhanya Maliakal Date: Tue, 15 Sep 2015 15:31:29 +0200 Subject: [PATCH 22/68] seems to run fine, only 16gb checked for fimware v 10 and software version v1.10.2 --- .../include/UDPBaseImplementation.h | 6 + slsReceiverSoftware/include/receiver_defs.h | 3 +- .../src/UDPBaseImplementation.cpp | 190 ----------- .../src/UDPStandardImplementation.cpp | 313 +++++++++--------- 4 files changed, 171 insertions(+), 341 deletions(-) diff --git a/slsReceiverSoftware/include/UDPBaseImplementation.h b/slsReceiverSoftware/include/UDPBaseImplementation.h index d68f1c6d4..d69e00b93 100644 --- a/slsReceiverSoftware/include/UDPBaseImplementation.h +++ b/slsReceiverSoftware/include/UDPBaseImplementation.h @@ -505,6 +505,9 @@ protected: /** max number of writer threads */ const static int MAX_NUM_WRITER_THREADS = 15; + /** missing packet identifier value */ + const static uint16_t missingPacketValue = 0xFFFF; + /** detector type */ detectorType myDetectorType; @@ -712,6 +715,9 @@ protected: /** 10Gbe enable*/ int tengigaEnable; + /** footer offset is different for 1g and 10g*/ + int footer_offset; + // TODO: not properly sure where to put these... /** structure of an eiger image header*/ diff --git a/slsReceiverSoftware/include/receiver_defs.h b/slsReceiverSoftware/include/receiver_defs.h index 701b4e382..206c8b92b 100755 --- a/slsReceiverSoftware/include/receiver_defs.h +++ b/slsReceiverSoftware/include/receiver_defs.h @@ -118,10 +118,11 @@ #define EIGER_ONE_GIGA_ONE_DATA_SIZE 1024 #define EIGER_TEN_GIGA_ONE_PACKET_SIZE 4112 #define EIGER_TEN_GIGA_ONE_DATA_SIZE 4096 +#define EIGER_PACKET_HEADER_SIZE 8 //#define EIGER_BUFFER_SIZE_CONSTANT (EIGER_ONE_PACKET_SIZE*EIGER_PACKETS_PER_FRAME_COSTANT)//1040*16*2//*bit mode //#define EIGER_DATA_BYTES_CONSTANT (EIGER_ONE_DATA_SIZE*EIGER_PACKETS_PER_FRAME_COSTANT) //1024*16*2//*bit mode -#define EIGER_FRAME_INDEX_MASK 0xFFFF +#define EIGER_FRAME_INDEX_MASK 0xFFFFFFFF //32 bit for now #define EIGER_FRAME_INDEX_OFFSET 0 #define EIGER_PACKET_INDEX_MASK 0x0 diff --git a/slsReceiverSoftware/src/UDPBaseImplementation.cpp b/slsReceiverSoftware/src/UDPBaseImplementation.cpp index c59932b9d..fb10ae106 100644 --- a/slsReceiverSoftware/src/UDPBaseImplementation.cpp +++ b/slsReceiverSoftware/src/UDPBaseImplementation.cpp @@ -558,83 +558,6 @@ void UDPBaseImplementation::setupFilter(){ FILE_LOG(logDEBUG) << __AT__ << " sta //LEO: it is not clear to me.. void UDPBaseImplementation::setupFifoStructure(){ FILE_LOG(logDEBUG) << __AT__ << " starting"; - int64_t i; - int oldn = numJobsPerThread; - - //if every nth frame mode - if(nFrameToGui) - numJobsPerThread = nFrameToGui; - - //random nth frame mode - else{ - if(!acquisitionPeriod) - i = SAMPLE_TIME_IN_NS; - else - i = SAMPLE_TIME_IN_NS/acquisitionPeriod; - if (i > MAX_JOBS_PER_THREAD) - numJobsPerThread = MAX_JOBS_PER_THREAD; - else if (i < 1) - numJobsPerThread = 1; - else - numJobsPerThread = i; - } - - //if same, return - if(oldn == numJobsPerThread) - return; - - if(myDetectorType == EIGER) - numJobsPerThread = 1; - - //otherwise memory too much if numjobsperthread is at max = 1000 - fifosize = GOTTHARD_FIFO_SIZE; - if(myDetectorType == MOENCH) - fifosize = MOENCH_FIFO_SIZE; - else if(myDetectorType == EIGER) - fifosize = EIGER_FIFO_SIZE; - - if(fifosize % numJobsPerThread) - fifosize = (fifosize/numJobsPerThread)+1; - else - fifosize = fifosize/numJobsPerThread; - - - cout << "Number of Frames per buffer:" << numJobsPerThread << endl; - cout << "Fifo Size:" << fifosize << endl; - - /* - //for testing - numJobsPerThread = 3; fifosize = 11; - */ - - for(int i=0;iisEmpty()) - fifoFree[i]->pop(buffer[i]); - delete fifoFree[i]; - } - if(fifo[i]) delete fifo[i]; - if(mem0[i]) free(mem0[i]); - fifoFree[i] = new CircularFifo(fifosize); - fifo[i] = new CircularFifo(fifosize); - - - //allocate memory - mem0[i]=(char*)malloc((bufferSize * numJobsPerThread + HEADER_SIZE_NUM_TOT_PACKETS)*fifosize); - /** shud let the client know about this */ - if (mem0[i]==NULL){ - cprintf(BG_RED,"++++++++++++++++++++++ COULD NOT ALLOCATE MEMORY FOR LISTENING !!!!!!!+++++++++++++++++++++\n"); - exit(-1); - } - buffer[i]=mem0[i]; - //push the addresses into freed fifoFree and writingFifoFree - while (buffer[i]<(mem0[i]+(bufferSize * numJobsPerThread + HEADER_SIZE_NUM_TOT_PACKETS)*(fifosize-1))) { - fifoFree[i]->push(buffer[i]); - buffer[i]+=(bufferSize * numJobsPerThread + HEADER_SIZE_NUM_TOT_PACKETS); - } - } - cout << "Fifo structure(s) reconstructed" << endl; } @@ -1529,93 +1452,6 @@ int UDPBaseImplementation::startWriting(){ FILE_LOG(logDEBUG) << __AT__ << " sta cout << ithread << "In startWriting()" <fnum); - //gotthard has +1 for frame number and not a short frame - else if ((myDetectorType == GOTTHARD) && (shortFrame == -1)) - startFrameIndex = (((((uint32_t)(*((uint32_t*)(buffer[ithread] + HEADER_SIZE_NUM_TOT_PACKETS))))+1) - & (frameIndexMask)) >> frameIndexOffset); - else - startFrameIndex = ((((uint32_t)(*((uint32_t*)(buffer[ithread]+HEADER_SIZE_NUM_TOT_PACKETS)))) - & (frameIndexMask)) >> frameIndexOffset); - //start of acquisition - if(!acqStarted){ - startAcquisitionIndex=startFrameIndex; - currframenum = startAcquisitionIndex; - acqStarted = true; - cout << "startAcquisitionIndex:" << startAcquisitionIndex<missingpacket) = 0xFF; + *( (uint16_t*) blankframe_header->missingpacket) = missingPacketValue; //set each value inside blank frame to 0xff for(j=0;j<(oneDataSize);++j){ - eiger_packet_data = blankframe[i] + sizeof(eiger_packet_header_t) + j; - *(eiger_packet_data) = 0xFF; + blankframe_data = (unsigned char*)blankframe[i] + sizeof(eiger_packet_header_t) + j; + *(blankframe_data) = 0xFF; } //verify - if (*( (uint16_t*) eiger_packet_header->missingpacket) != 0xFF){ - cprintf(RED,"blank frame not detected at %d: 0x%x\n",i,*( (uint16_t*) eiger_packet_header->missingpacket) ); + if (*( (uint16_t*) blankframe_header->missingpacket) != missingPacketValue){ + cprintf(RED,"blank frame not detected at %d: 0x%x\n",i,*( (uint16_t*) blankframe_header->missingpacket) ); exit(-1); } #ifdef FIFO_DEBUG @@ -2041,8 +2057,8 @@ int UDPStandardImplementation::startWriting(){ tempoffset[i] = (i*packetsPerFrame/numListeningThreads); tofreeoffset[i] = (i*packetsPerFrame/numListeningThreads); blankoffset = 0; - lastpacketheader[i] = -1; - currentpacketheader[i] = -1; + lastpacketheader[i] = 0; + currentpacketheader[i] = 0; numberofmissingpackets[i] = 0; numpackets[i] = 0; @@ -2065,6 +2081,7 @@ int UDPStandardImplementation::startWriting(){ cprintf(GREEN,"%d writer poped 0x%x from fifo %d\n", ithread, (void*)(wbuf[i]), i); #endif numpackets[i] = (uint32_t)(*((uint32_t*)wbuf[i])); + #ifdef VERYDEBUG cprintf(GREEN,"%d numpackets: %d for fifo :%d\n", ithread, numpackets[i], i); #endif @@ -2080,17 +2097,22 @@ int UDPStandardImplementation::startWriting(){ #endif }else{ endofacquisition = false; - if(numpackets[i] == 1040){ - cprintf(BLUE,"tempframenum[%d]:%d\n",i,((*(uint32_t*)(((eiger_packet_1g *)((char*)(wbuf[i] + HEADER_SIZE_NUM_TOT_PACKETS)))->framenum)))); - cprintf(BLUE,"packetnum[%d]:%d\n",i,((*(uint16_t*)(((eiger_packet_1g *)((char*)(wbuf[i] + HEADER_SIZE_NUM_TOT_PACKETS)))->packetnum)))); + if(numpackets[i] == 1040){; +#ifdef EIGER_DEBUG3 + wbuf_footer = (eiger_packet_footer_t*)(wbuf[i] + footer_offset + HEADER_SIZE_NUM_TOT_PACKETS); + //cprintf(BLUE,"footer value:0x%x\n",i,(uint64_t)(*( (uint64_t*) wbuf_footer))); + cprintf(BLUE,"tempframenum[%d]:%d\n",i,(uint32_t)(*( (uint64_t*) wbuf_footer))); + cprintf(BLUE,"packetnum[%d]:%d\n",i,*( (uint16_t*) wbuf_footer->packetnum)); +#endif }else if(numpackets[i] == EIGER_HEADER_LENGTH){ cprintf(BG_RED, "got header in writer, weirdd packetsize:%d\n",numpackets[i]); exit(-1); - }else { - cprintf(BG_RED, "got weird in writer, weirdd packetsize:%d\n",numpackets[i]); - } - +//#ifdef EIGER_DEBUG3 + else { + cprintf(BG_RED, "got weird in writer, weirdd packetsize:%d\n",numpackets[i]); + } +//#endif if(myDetectorType == EIGER){ tofree[tofreeoffset[i]] = wbuf[i]; tofreeoffset[i]++; @@ -2104,9 +2126,9 @@ int UDPStandardImplementation::startWriting(){ //END OF ACQUISITION if(endofacquisition){ -//#ifdef VERYDEBUG +#ifdef EIGER_DEBUG3 cprintf(GREEN,"%d Both dummy frames\n", ithread); -//#endif +#endif //remaining packets to be written if((myDetectorType == EIGER) && ((tempoffset[0]!=0) || (tempoffset[1]!=(packetsPerFrame/numListeningThreads)))); @@ -2121,6 +2143,8 @@ int UDPStandardImplementation::startWriting(){ if(myDetectorType == EIGER){ + + //NOT FULL FRAME if(!fullframe[0] || !fullframe[1]){ for(i=0;imissingpacket)) - cprintf(RED,"1 fifo:%d missing packet added at pnum:%d\n",i,tempoffset[i]); - else cprintf(RED, "1 fifo:%d Weird at pnum:%d\n",i,tempoffset[i]); -#endif - if ((*(uint8_t*)(((eiger_packet_1g *)((char*)(tempbuffer[tempoffset[i]])))->missingpacket))!= 0xFF){ - cprintf(BG_RED, "dummy blank mismatch num4 earlier2! i:%d pnum:%d fnum:%d missingpacket:0x%x actual missingpacket:0x%x\n", + + tempframe_header = (eiger_packet_header_t*) tempbuffer[tempoffset[i]]; + blankframe_header = (eiger_packet_header_t*) blankframe[blankoffset]; + if (*( (uint16_t*) tempframe_header->missingpacket)!= missingPacketValue){ + cprintf(BG_RED, "dummy blank mismatch num4 earlier2! " + "i:%d pnum:%d fnum:%d missingpacket:0x%x actual missingpacket:0x%x\n", i,tempoffset[i],tempframenum[i], - (*(uint8_t*)(((eiger_packet_1g *)((char*)(tempbuffer[tempoffset[i]])))->missingpacket)), - (*(uint8_t*)(((eiger_packet_1g *)((char*)(blankframe[blankoffset])))->missingpacket))); + *( (uint16_t*) tempframe_header->missingpacket), + *( (uint16_t*) blankframe_header->missingpacket)); exit(-1); }else -//#ifdef PADDING - cprintf(GREEN, "blank packet i:%d pnum:%d fnum:%d missingpacket:0x%x\n",i,tempoffset[i],tempframenum[i],(*(uint8_t*)(((eiger_packet_1g *)((char*)(tempbuffer[tempoffset[i]])))->missingpacket))); -//#endif +#ifdef PADDING + cprintf(GREEN, "blank packet i:%d pnum:%d fnum:%d missingpacket:0x%x\n",i, + tempoffset[i],tempframenum[i],*( (uint16_t*) tempframe_header->missingpacket)); +#endif tempoffset[i]++; blankoffset++; } @@ -2184,9 +2208,12 @@ int UDPStandardImplementation::startWriting(){ //not a full frame if(!fullframe[i]){ - + wbuf_footer = (eiger_packet_footer_t*)(wbuf[i] + footer_offset + HEADER_SIZE_NUM_TOT_PACKETS); +#ifdef EIGER_DEBUG3 + cprintf(GREEN,"**pnum of %d: %d\n",i,(*( (uint16_t*) wbuf_footer->packetnum))); +#endif //update frame number - tempframenum[i] = ((*(uint32_t*)(((eiger_packet_1g *)((char*)(wbuf[i] + HEADER_SIZE_NUM_TOT_PACKETS)))->framenum))); + tempframenum[i] =(uint32_t)(*( (uint64_t*) wbuf_footer)); if(!tempframenum[i]) @@ -2196,16 +2223,18 @@ int UDPStandardImplementation::startWriting(){ //WRONG FRAME - leave if(tempframenum[i] != presentframenum){ -//#ifdef PADDING +#ifdef PADDING cout<<"wrong packet"<framenum))), - ((*(uint16_t*)(((eiger_packet_1g *)((char*)(wbuf[i] + HEADER_SIZE_NUM_TOT_PACKETS)))->packetnum)))); -//#endif + (uint32_t)(*( (uint64_t*) wbuf_footer)), + *( (uint16_t*) wbuf_footer->packetnum)); + +#endif tempframenum[i] = presentframenum; //add missing packets numberofmissingpackets[i] = (LAST_PACKET_VALUE - lastpacketheader[i]); @@ -2216,26 +2245,24 @@ int UDPStandardImplementation::startWriting(){ //to decrement from packetsInFile to calculate packet loss for(j=0;jmissingpacket))== 0xFF) - cprintf(RED,"5 fifo:%d missing packet added at pnum:%d\n",i,tempoffset[i]); - else cprintf(RED, "5 fifo:%d WEird at pnum:%d\n",i,tempoffset[i]); -#endif - if ((*(uint8_t*)(((eiger_packet_1g *)((char*)(tempbuffer[tempoffset[i]])))->missingpacket))!= 0xFF){ + + tempframe_header = (eiger_packet_header_t*) tempbuffer[tempoffset[i]]; + blankframe_header = (eiger_packet_header_t*) blankframe[blankoffset]; + if (*( (uint16_t*) tempframe_header->missingpacket)!= missingPacketValue){ cprintf(BG_RED, "wrong blank mismatch num4 earlier2! " "i:%d pnum:%d fnum:%d missingpacket:0x%x actual missingpacket:0x%x add:0x%x\n", i,tempoffset[i],tempframenum[i], - (*(uint8_t*)(((eiger_packet_1g *)((char*)(tempbuffer[tempoffset[i]])))->missingpacket)), - (*(uint8_t*)(((eiger_packet_1g *)((char*)(blankframe[blankoffset])))->missingpacket)), + *( (uint16_t*) tempframe_header->missingpacket), + *( (uint16_t*) blankframe_header->missingpacket), (void*)(tempbuffer[tempoffset[i]])); exit(-1); }else -//#ifdef PADDING +#ifdef PADDING cprintf(GREEN, "blank packet i:%d pnum:%d fnum:%d missingpacket:0x%x add:0x%x\n", i,tempoffset[i],tempframenum[i], - (*(uint8_t*)(((eiger_packet_1g *)((char*)(tempbuffer[tempoffset[i]])))->missingpacket)), + *( (uint16_t*) tempframe_header->missingpacket), (void*)(tempbuffer[tempoffset[i]])); -//#endif +#endif tempoffset[i] ++; blankoffset ++; } @@ -2247,73 +2274,75 @@ int UDPStandardImplementation::startWriting(){ //CORRECT FRAME - continue building frame else { -//#ifdef PADDING +#ifdef PADDING cout<<"correct packet"<packetnum))); + currentpacketheader[i] = *( (uint16_t*) wbuf_footer->packetnum); #ifdef VERYVERBOSE - cprintf(GREEN,"**fifo:%d currentpacketheader: %d lastpacketheader %d tempoffset:%d\n",i,currentpacketheader[i],lastpacketheader[i], tempoffset[i]); + cprintf(GREEN,"**fifo:%d currentpacketheader: %d lastpacketheader %d tempoffset:%d\n", + i,currentpacketheader[i],lastpacketheader[i], tempoffset[i]); #endif //add missing packets numberofmissingpackets[i] = (currentpacketheader[i] - lastpacketheader[i] -1); #ifdef VERYDEBUG if(numberofmissingpackets[i]>0) - cprintf(BG_RED,"fifo:%d missing packet from: %d now at :%d tempoffset:%d\n",i,lastpacketheader[i],currentpacketheader[i],tempoffset[i]); + cprintf(BG_RED,"fifo:%d missing packet from: %d now at :%d tempoffset:%d\n", + i,lastpacketheader[i],currentpacketheader[i],tempoffset[i]); #endif //to decrement from packetsInFile to calculate packet loss for(j=0;jmissingpacket)) ==0xFF) - cprintf(RED,"4 fifo:%d missing packet added at pnum:%d\n",i,tempoffset[i]); - else cprintf(RED, "4 fifo:%d WEird at pnum:%d\n",i,tempoffset[i]); -#endif - if ((*(uint8_t*)(((eiger_packet_1g *)((char*)(tempbuffer[tempoffset[i]])))->missingpacket))!= 0xFF){ + + tempframe_header = (eiger_packet_header_t*) tempbuffer[tempoffset[i]]; + blankframe_header = (eiger_packet_header_t*) blankframe[blankoffset]; + if (*( (uint16_t*) tempframe_header->missingpacket)!= missingPacketValue){ cprintf(BG_RED, "correct blank mismatch num4 earlier2! " "i:%d pnum:%d fnum:%d missingpacket:0x%x actual missingpacket:0x%x add:0x%x\n", i,tempoffset[i],tempframenum[i], - (*(uint8_t*)(((eiger_packet_1g *)((char*)(tempbuffer[tempoffset[i]])))->missingpacket)), - (*(uint8_t*)(((eiger_packet_1g *)((char*)(blankframe[blankoffset])))->missingpacket)), + *( (uint16_t*) tempframe_header->missingpacket), + *( (uint16_t*) blankframe_header->missingpacket), (void*)(tempbuffer[tempoffset[i]])); exit(-1); }else -//#ifdef PADDING +#ifdef PADDING cprintf(GREEN, "blank packet i:%d pnum:%d fnum:%d missingpacket:0x%x add:0x%x\n", i,tempoffset[i],tempframenum[i], - (*(uint8_t*)(((eiger_packet_1g *)((char*)(tempbuffer[tempoffset[i]])))->missingpacket)), + *( (uint16_t*) tempframe_header->missingpacket), (void*)(tempbuffer[tempoffset[i]])); -//#endif +#endif tempoffset[i] ++; blankoffset ++; } //add current packet - - if(currentpacketheader[i] != (tempoffset[i]-(i*packetsPerFrame/numListeningThreads))){ + if(currentpacketheader[i] != (tempoffset[i]-(i*packetsPerFrame/numListeningThreads))+1){ cprintf(BG_RED, "correct pnum mismatch earlier! tempoffset[%d]:%d pnum:%d fnum:%d rfnum:%d\n", i,tempoffset[i],currentpacketheader[i], - tempframenum[i],(*(uint32_t*)(((eiger_packet_1g *)((char*)(wbuf[i]+ HEADER_SIZE_NUM_TOT_PACKETS)))->framenum))); + tempframenum[i],(uint32_t)(*( (uint64_t*) wbuf_footer))); exit(-1); } + tempbuffer[tempoffset[i]] = wbuf[i] + HEADER_SIZE_NUM_TOT_PACKETS; + tempframe_footer = (eiger_packet_footer_t*) (tempbuffer[tempoffset[i]] + footer_offset); #ifdef EIGER_DEBUG3 - cprintf(GREEN,"**fifo:%d currentpacketheader: %d tempoffset:%d\n",i,(*(uint16_t*)(((eiger_packet_1g *)((char*)(tempbuffer[tempoffset[i]])))->packetnum)),tempoffset[i]); + cprintf(GREEN,"**fifo:%d currentpacketheader: %d tempoffset:%d\n", + i,*( (uint16_t*) tempframe_footer->packetnum),tempoffset[i]); #endif - if((*(uint16_t*)(((eiger_packet_1g *)((char*)(tempbuffer[tempoffset[i]])))->packetnum)) != (tempoffset[i]-(i*packetsPerFrame/numListeningThreads))){ - cprintf(BG_RED, "pnum mismatch num4 earlier! i:%d pnum:%d fnum:%d add:0x%x\n", - i,(*(uint16_t*)(((eiger_packet_1g *)((char*)(tempbuffer[tempoffset[i]])))->packetnum)), + if(*( (uint16_t*) tempframe_footer->packetnum)!= (tempoffset[i]-(i*packetsPerFrame/numListeningThreads))+1){ + cprintf(BG_RED, "pnum mismatch num4 earlier! i:%d pnum:%d pnum orig:%d fnum:%d add:0x%x\n", + i,*( (uint16_t*) tempframe_footer->packetnum),*( (uint16_t*) wbuf_footer->packetnum), tempframenum[i],(void*)(tempbuffer[tempoffset[i]])); exit(-1); } -//#ifdef PADDING +#ifdef PADDING cprintf(GREEN, "normal packet i:%d pnum:%d fnum:%d missingpacket:0x%x add:0x%x\n", i,tempoffset[i],tempframenum[i], - (*(uint8_t*)(((eiger_packet_1g *)((char*)(tempbuffer[tempoffset[i]])))->missingpacket)), + *( (uint16_t*) tempframe_footer->packetnum), (void*)(tempbuffer[tempoffset[i]])); -//#endif +#endif tempoffset[i] ++; //update last packet lastpacketheader[i] = currentpacketheader[i]; @@ -2343,10 +2372,10 @@ int UDPStandardImplementation::startWriting(){ numMissingPackets += (numberofmissingpackets[0]+numberofmissingpackets[1]); numTotMissingPacketsInFile += numMissingPackets; numTotMissingPackets += numMissingPackets; -//#ifdef EIGER_DEBUG2 +#ifdef EIGER_DEBUG2 cprintf(GREEN,"**fnum:%d**\n",currframenum); -//#endif -//#ifdef EIGER_DEBUG3 +#endif +#ifdef EIGER_DEBUG3 if(numberofmissingpackets[0]) cprintf(RED, "fifo 0 missing packets:%d fnum:%d\n",numberofmissingpackets[0],currframenum); if(numberofmissingpackets[1]) @@ -2354,11 +2383,13 @@ int UDPStandardImplementation::startWriting(){ if(numMissingPackets){ cprintf(RED, "numMissingPackets:%d fnum:%d\n",numMissingPackets,currframenum); - for (j=0;jmissingpacket))==0xFF) + for (j=0;jmissingpacket)==missingPacketValue) cprintf(RED,"found the missing packet at pnum:%d\n",j); + } } -//#endif +#endif //write and copy to gui @@ -2378,9 +2409,9 @@ int UDPStandardImplementation::startWriting(){ cprintf(GREEN,"%d writer freed pushed into fifofree %x for listener %d\n",ithread, (void*)(tofree[j]),1); #endif } -//#ifdef VERYDEBUG +#ifdef VERYDEBUG cprintf(GREEN,"finished freeing\n"); -//#endif +#endif //reset a few stuff @@ -2394,19 +2425,20 @@ int UDPStandardImplementation::startWriting(){ tempoffset[i] = (i*packetsPerFrame/numListeningThreads); tofreeoffset[i] = (i*packetsPerFrame/numListeningThreads); blankoffset = 0; - lastpacketheader[i] = -1; - currentpacketheader[i] = -1; + lastpacketheader[i] = 0; + currentpacketheader[i] = 0; numberofmissingpackets[i] = 0; } } -//#ifdef VERYDEBUG +#ifdef VERYDEBUG for(int i=0;iframenum)))); - cprintf(GREEN,"packetnum[%d]:%d\n",i,((*(uint16_t*)(((eiger_packet_1g *)((char*)(wbuf[i] + HEADER_SIZE_NUM_TOT_PACKETS)))->packetnum)))); + cprintf(GREEN,"tempframenum[%d]:%d\n",i,(uint32_t)(*( (uint64_t*) wbuf_footer))); + cprintf(GREEN,"packetnum[%d]:%d\n",i,*( (uint16_t*) wbuf_footer->packetnum)); } -//#endif +#endif } @@ -2838,8 +2870,6 @@ void UDPStandardImplementation::handleWithoutDataCompression(int ithread, char* int i,j, missingpacket,port = 0, pnuminc; - - if (cbAction < DO_EVERYTHING){ if (myDetectorType == EIGER){ for(i=0;ipacketnum)); +#endif //which port if (i ==(packetsPerFrame/2)) port = 1; @@ -2863,77 +2902,51 @@ void UDPStandardImplementation::handleWithoutDataCompression(int ithread, char* //missing packet - if ((*(uint8_t*)(((eiger_packet_1g *)((char*)(wbuffer[i])))->missingpacket))==0xFF){ + if (*( (uint16_t*) wbuf_header->missingpacket)== missingPacketValue){ +#ifdef VERY_VERBOSE + cprintf(GREEN,"missing packet at %d\n", i+1); +#endif missingpacket = 1; - //add packet numbers - (*(uint16_t*)(((eiger_packet_1g *)((char*)(wbuffer[i])))->packetnum)) = (i+1); - (*(uint32_t*)(((eiger_packet_1g *)((char*)(wbuffer[i])))->framenum)) = currframenum+1; + //add frame and packet numbers + *( (uint64_t*) wbuf_footer) = (uint64_t)((currframenum+1)); + *( (uint16_t*) wbuf_footer->packetnum) = (i+1); }else{ missingpacket = 0; - if((*(uint16_t*)(((eiger_packet_1g *)((char*)(wbuffer[i])))->packetnum)) != (i-(port*packetsPerFrame/numListeningThreads))){ - cprintf(BG_RED, "pnum mismatch num4! i:%d pnum:%d fnum:%d\n",i,(*(uint16_t*)(((eiger_packet_1g *)((char*)(wbuffer[i])))->packetnum)),currframenum); + if(*( (uint16_t*) wbuf_footer->packetnum)!= (i-(port*packetsPerFrame/numListeningThreads))+1){ + cprintf(BG_RED, "pnum mismatch num4! i:%d pnum:%d fnum:%d\n", + i,*( (uint16_t*) wbuf_footer->packetnum),currframenum); exit(-1); } - - /* if(dynamicRange != 32){*/ //move packet numbers to num2, and compensate for port1 starting pnum from 0 - if(!port) - (*(uint16_t*)(((eiger_packet_1g *)((char*)(wbuffer[i])))->packetnum)) = - ((*(uint16_t*)(((eiger_packet_1g *)((char*)(wbuffer[i])))->packetnum))+1); - else - (*(uint16_t*)(((eiger_packet_1g *)((char*)(wbuffer[i])))->packetnum)) = - ((*(uint16_t*)(((eiger_packet_1g *)((char*)(wbuffer[i])))->packetnum))+(packetsPerFrame/2) +1); - /*} - //dr == 32 - else{ - if(i == 0) - pnuminc = 0; - else if(i == (packetsPerFrame/4)) - pnuminc = (packetsPerFrame/4); - else if(i == (packetsPerFrame/2)) - pnuminc = (packetsPerFrame/2); - else if(i == (3*packetsPerFrame/4)) - pnuminc = (3*packetsPerFrame/4); - (*(uint16_t*)(((eiger_packet_1g *)((char*)(wbuffer[i])))->packetnum)) - = ((*(uint8_t*)(((eiger_packet_1g *)((char*)(wbuffer[i])))->packetnum,))+pnuminc+1); - - }*/ + if(port) + *( (uint16_t*) wbuf_footer->packetnum) = (*( (uint16_t*) wbuf_footer->packetnum))+(packetsPerFrame/2); } - - if((*(uint16_t*)(((eiger_packet_1g *)((char*)(wbuffer[i])))->packetnum)) != (i+1)){ - cprintf(BG_RED, "pnum mismatch! i:%d pnum:%d fnum:%d\n",i,(*(uint16_t*)(((eiger_packet_1g *)((char*)(wbuffer[i])))->packetnum)),currframenum); - if ((*(uint8_t*)(((eiger_packet_1g *)((char*)(wbuffer[i])))->missingpacket))==0xFF) + if(*( (uint16_t*) wbuf_footer->packetnum) != (i+1)){ + cprintf(BG_RED, "pnum mismatch! i:%d pnum:%d fnum:%d\n", + i,*( (uint16_t*) wbuf_footer->packetnum),currframenum); + if (*( (uint16_t*) wbuf_header->missingpacket) == missingPacketValue) cprintf(BG_RED,"missing packet though\n"); exit(-1); } //overwriting port number and dynamic range - (*(uint8_t*)(((eiger_packet_1g *)((char*)(wbuffer[i])))->missingpacket)) = - ((dynamicRange<<2)|(missingpacket<<1)|(port)); + *( (uint8_t*) wbuf_header->portnum) = port; + *( (uint8_t*) wbuf_header->dynamicrange) = dynamicRange; - //frame number - //(*(uint32_t*)(((eiger_packet_1g *)((char*)(wbuffer[i])))->framenum)) = currframenum; #ifdef VERYDEBUG if((i==0)||(i==1)){ cprintf(GREEN, "%d packet header:0x%016llx missingpacket:0x%x\n",i, - ((uint64_t)(*((uint64_t*)(wbuffer[i])))), - (uint8_t)(*(uint8_t*)(((eiger_packet_1g *)((char*)(wbuffer[i])))->missingpacket))); + (uint64_t)()*( (uint64_t*) wbuf_header)), *( (uint16_t*) wbuf_header->missingpacket)); cprintf(GREEN, "%d - 0x%x - %d\n", i, - (*(uint8_t*)(((eiger_packet_1g *)((char*)(wbuffer[i])))->missingpacket)), - (*(uint16_t*)(((eiger_packet_1g *)((char*)(wbuffer[i])))->packetnum))); + *( (uint16_t*) wbuf_header->missingpacket), *( (uint16_t*) wbuf_footer->packetnum)); } #endif -/* - cprintf(GREEN,"at writing, fnum:%d, pnum:%d,missingpacket:0x%x add:0x%x\n", - currframenum, i, (*(uint8_t*)(((eiger_packet_1g *)((char*)(wbuffer[i])))->missingpacket)), - (void*)(wbuffer[i])); -*/ } } From c7017eef5b720f67723c00cfa6308f19a88b35d5 Mon Sep 17 00:00:00 2001 From: Dhanya Maliakal Date: Tue, 15 Sep 2015 15:41:58 +0200 Subject: [PATCH 23/68] 10g gui bottom offset bug fix --- slsReceiverSoftware/src/slsReceiverTCPIPInterface.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/slsReceiverSoftware/src/slsReceiverTCPIPInterface.cpp b/slsReceiverSoftware/src/slsReceiverTCPIPInterface.cpp index ea0336895..17ff75764 100644 --- a/slsReceiverSoftware/src/slsReceiverTCPIPInterface.cpp +++ b/slsReceiverSoftware/src/slsReceiverTCPIPInterface.cpp @@ -1630,11 +1630,12 @@ int slsReceiverTCPIPInterface::eiger_read_frame(){ int linesperpacket = (16*1/dynamicrange);// 16:1 line, 8:2 lines, 4:4 lines, 32: 0.5 int numbytesperlineperport=(EIGER_PIXELS_IN_ONE_ROW/EIGER_MAX_PORTS)*dynamicrange/8;//16:1024,8:512,4:256,32:2048 int datapacketlength = EIGER_ONE_GIGA_ONE_DATA_SIZE; - int total_num_bytes = 1040*(16*dynamicrange)*2; + int total_num_bytes = EIGER_ONE_GIGA_ONE_PACKET_SIZE *(EIGER_ONE_GIGA_CONSTANT *dynamicrange)*2; if(tenGigaEnable){ linesperpacket = (16*4/dynamicrange);// 16:4 line, 8:8 lines, 4:16 lines, 32: 2 datapacketlength = EIGER_TEN_GIGA_ONE_DATA_SIZE; + total_num_bytes = EIGER_TEN_GIGA_ONE_PACKET_SIZE*(EIGER_TEN_GIGA_CONSTANT*dynamicrange)*2; } //if 1GbE, one line is split into two packets for 32 bit mode, so its special else if(dynamicrange == 32){ From 1b471bc6759d6e9c49a32e627dbf843d7b5a7ee6 Mon Sep 17 00:00:00 2001 From: Dhanya Maliakal Date: Thu, 17 Sep 2015 09:14:00 +0200 Subject: [PATCH 24/68] partial_frames for 10g bug fixed specifzing literal 1024 for allowed packet size in startwritign --- slsReceiverSoftware/src/UDPStandardImplementation.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/slsReceiverSoftware/src/UDPStandardImplementation.cpp b/slsReceiverSoftware/src/UDPStandardImplementation.cpp index d55a1f1fc..8c68403b6 100644 --- a/slsReceiverSoftware/src/UDPStandardImplementation.cpp +++ b/slsReceiverSoftware/src/UDPStandardImplementation.cpp @@ -1962,7 +1962,7 @@ int UDPStandardImplementation::startWriting(){ uint32_t lastpacketheader[numListeningThreads], currentpacketheader[numListeningThreads]; int numberofmissingpackets[numListeningThreads]; - int MAX_VALUE = 1024; + int MAX_VALUE = 1024;//32 bit number of packets char* tofree[MAX_VALUE]; char* tempbuffer[MAX_VALUE]; char* blankframe[MAX_VALUE]; @@ -2097,7 +2097,7 @@ int UDPStandardImplementation::startWriting(){ #endif }else{ endofacquisition = false; - if(numpackets[i] == 1040){; + if(numpackets[i] == bufferSize){; #ifdef EIGER_DEBUG3 wbuf_footer = (eiger_packet_footer_t*)(wbuf[i] + footer_offset + HEADER_SIZE_NUM_TOT_PACKETS); //cprintf(BLUE,"footer value:0x%x\n",i,(uint64_t)(*( (uint64_t*) wbuf_footer))); From b3012acea2a1e26d23ae9a32cc0833f844fbc907 Mon Sep 17 00:00:00 2001 From: Dhanya Maliakal Date: Thu, 17 Sep 2015 12:03:11 +0200 Subject: [PATCH 25/68] bug fixxed for 10g writing filter, still debug mode --- .../src/UDPStandardImplementation.cpp | 81 ++++++++++--------- 1 file changed, 41 insertions(+), 40 deletions(-) diff --git a/slsReceiverSoftware/src/UDPStandardImplementation.cpp b/slsReceiverSoftware/src/UDPStandardImplementation.cpp index 8c68403b6..10ed49463 100644 --- a/slsReceiverSoftware/src/UDPStandardImplementation.cpp +++ b/slsReceiverSoftware/src/UDPStandardImplementation.cpp @@ -2092,18 +2092,18 @@ int UDPStandardImplementation::startWriting(){ //dont pop again if dummy packet else if(numpackets[i] == 0){ popready[i] = false; -#ifdef EIGER_DEBUG3 +//#ifdef EIGER_DEBUG3 cprintf(GREEN,"%d Dummy frame popped out of fifo %d",ithread, i); -#endif +//#endif }else{ endofacquisition = false; - if(numpackets[i] == bufferSize){; -#ifdef EIGER_DEBUG3 + if(numpackets[i] == onePacketSize){; +//#ifdef EIGER_DEBUG3 wbuf_footer = (eiger_packet_footer_t*)(wbuf[i] + footer_offset + HEADER_SIZE_NUM_TOT_PACKETS); //cprintf(BLUE,"footer value:0x%x\n",i,(uint64_t)(*( (uint64_t*) wbuf_footer))); cprintf(BLUE,"tempframenum[%d]:%d\n",i,(uint32_t)(*( (uint64_t*) wbuf_footer))); cprintf(BLUE,"packetnum[%d]:%d\n",i,*( (uint16_t*) wbuf_footer->packetnum)); -#endif +//#endif }else if(numpackets[i] == EIGER_HEADER_LENGTH){ cprintf(BG_RED, "got header in writer, weirdd packetsize:%d\n",numpackets[i]); exit(-1); @@ -2126,9 +2126,9 @@ int UDPStandardImplementation::startWriting(){ //END OF ACQUISITION if(endofacquisition){ -#ifdef EIGER_DEBUG3 +//#ifdef EIGER_DEBUG3 cprintf(GREEN,"%d Both dummy frames\n", ithread); -#endif +//#endif //remaining packets to be written if((myDetectorType == EIGER) && ((tempoffset[0]!=0) || (tempoffset[1]!=(packetsPerFrame/numListeningThreads)))); @@ -2157,15 +2157,15 @@ int UDPStandardImplementation::startWriting(){ if(numpackets[i] == EIGER_HEADER_LENGTH) {cprintf(BG_RED,"weird, frame packet recieved\n"); exit(-1);} //dummy packet else if(!numpackets[i]){ -#ifdef EIGER_DEBUG3 +//#ifdef EIGER_DEBUG3 cprintf(RED, "Dummy packet: %d from fifo %d\n", numpackets[i],i); -#endif +//#endif cout<<"tempoffset["<missingpacket)); exit(-1); }else -#ifdef PADDING +//#ifdef PADDING cprintf(GREEN, "blank packet i:%d pnum:%d fnum:%d missingpacket:0x%x\n",i, tempoffset[i],tempframenum[i],*( (uint16_t*) tempframe_header->missingpacket)); -#endif +//#endif tempoffset[i]++; blankoffset++; } @@ -2209,9 +2209,9 @@ int UDPStandardImplementation::startWriting(){ //not a full frame if(!fullframe[i]){ wbuf_footer = (eiger_packet_footer_t*)(wbuf[i] + footer_offset + HEADER_SIZE_NUM_TOT_PACKETS); -#ifdef EIGER_DEBUG3 +//#ifdef EIGER_DEBUG3 cprintf(GREEN,"**pnum of %d: %d\n",i,(*( (uint16_t*) wbuf_footer->packetnum))); -#endif +//#endif //update frame number tempframenum[i] =(uint32_t)(*( (uint64_t*) wbuf_footer)); @@ -2223,18 +2223,18 @@ int UDPStandardImplementation::startWriting(){ //WRONG FRAME - leave if(tempframenum[i] != presentframenum){ -#ifdef PADDING +//#ifdef PADDING cout<<"wrong packet"<packetnum)); -#endif +//#endif tempframenum[i] = presentframenum; //add missing packets numberofmissingpackets[i] = (LAST_PACKET_VALUE - lastpacketheader[i]); @@ -2257,12 +2257,12 @@ int UDPStandardImplementation::startWriting(){ (void*)(tempbuffer[tempoffset[i]])); exit(-1); }else -#ifdef PADDING +//#ifdef PADDING cprintf(GREEN, "blank packet i:%d pnum:%d fnum:%d missingpacket:0x%x add:0x%x\n", i,tempoffset[i],tempframenum[i], *( (uint16_t*) tempframe_header->missingpacket), (void*)(tempbuffer[tempoffset[i]])); -#endif +//#endif tempoffset[i] ++; blankoffset ++; } @@ -2274,12 +2274,12 @@ int UDPStandardImplementation::startWriting(){ //CORRECT FRAME - continue building frame else { -#ifdef PADDING +//#ifdef PADDING cout<<"correct packet"<packetnum); #ifdef VERYVERBOSE @@ -2308,12 +2308,12 @@ int UDPStandardImplementation::startWriting(){ (void*)(tempbuffer[tempoffset[i]])); exit(-1); }else -#ifdef PADDING +//#ifdef PADDING cprintf(GREEN, "blank packet i:%d pnum:%d fnum:%d missingpacket:0x%x add:0x%x\n", i,tempoffset[i],tempframenum[i], *( (uint16_t*) tempframe_header->missingpacket), (void*)(tempbuffer[tempoffset[i]])); -#endif +//#endif tempoffset[i] ++; blankoffset ++; } @@ -2326,32 +2326,33 @@ int UDPStandardImplementation::startWriting(){ } tempbuffer[tempoffset[i]] = wbuf[i] + HEADER_SIZE_NUM_TOT_PACKETS; + tempframe_header = (eiger_packet_header_t*) tempbuffer[tempoffset[i]]; tempframe_footer = (eiger_packet_footer_t*) (tempbuffer[tempoffset[i]] + footer_offset); -#ifdef EIGER_DEBUG3 +//#ifdef EIGER_DEBUG3 cprintf(GREEN,"**fifo:%d currentpacketheader: %d tempoffset:%d\n", i,*( (uint16_t*) tempframe_footer->packetnum),tempoffset[i]); -#endif +//#endif if(*( (uint16_t*) tempframe_footer->packetnum)!= (tempoffset[i]-(i*packetsPerFrame/numListeningThreads))+1){ cprintf(BG_RED, "pnum mismatch num4 earlier! i:%d pnum:%d pnum orig:%d fnum:%d add:0x%x\n", i,*( (uint16_t*) tempframe_footer->packetnum),*( (uint16_t*) wbuf_footer->packetnum), tempframenum[i],(void*)(tempbuffer[tempoffset[i]])); exit(-1); } -#ifdef PADDING +//#ifdef PADDING cprintf(GREEN, "normal packet i:%d pnum:%d fnum:%d missingpacket:0x%x add:0x%x\n", i,tempoffset[i],tempframenum[i], - *( (uint16_t*) tempframe_footer->packetnum), + *( (uint16_t*) tempframe_header->missingpacket), (void*)(tempbuffer[tempoffset[i]])); -#endif +//#endif tempoffset[i] ++; //update last packet lastpacketheader[i] = currentpacketheader[i]; popready[i] = true; //last frame got, this will save time and also for last frames, it doesnt wait for stop receiver if(currentpacketheader[i] == LAST_PACKET_VALUE){ -#ifdef EIGER_DEBUG3 +//#ifdef EIGER_DEBUG3 cprintf(GREEN, "Got last packet\n"); -#endif +//#endif fullframe[i] = true; popready[i] = false; } @@ -2372,10 +2373,10 @@ int UDPStandardImplementation::startWriting(){ numMissingPackets += (numberofmissingpackets[0]+numberofmissingpackets[1]); numTotMissingPacketsInFile += numMissingPackets; numTotMissingPackets += numMissingPackets; -#ifdef EIGER_DEBUG2 +//#ifdef EIGER_DEBUG2 cprintf(GREEN,"**fnum:%d**\n",currframenum); -#endif -#ifdef EIGER_DEBUG3 +//#endif +//#ifdef EIGER_DEBUG3 if(numberofmissingpackets[0]) cprintf(RED, "fifo 0 missing packets:%d fnum:%d\n",numberofmissingpackets[0],currframenum); if(numberofmissingpackets[1]) @@ -2389,7 +2390,7 @@ int UDPStandardImplementation::startWriting(){ cprintf(RED,"found the missing packet at pnum:%d\n",j); } } -#endif +//#endif //write and copy to gui @@ -2431,14 +2432,14 @@ int UDPStandardImplementation::startWriting(){ } } -#ifdef VERYDEBUG +//#ifdef EIGER_DEBUG3 for(int i=0;ipacketnum)); } -#endif +//#endif } From 5a4dfd128d9dbe58c106fc39d4ddf8cd3dda03d0 Mon Sep 17 00:00:00 2001 From: Dhanya Maliakal Date: Thu, 17 Sep 2015 12:29:16 +0200 Subject: [PATCH 26/68] 10g partial_frames should also work now --- .../src/UDPStandardImplementation.cpp | 97 +++++++++++-------- 1 file changed, 55 insertions(+), 42 deletions(-) diff --git a/slsReceiverSoftware/src/UDPStandardImplementation.cpp b/slsReceiverSoftware/src/UDPStandardImplementation.cpp index 10ed49463..b0a24ebc0 100644 --- a/slsReceiverSoftware/src/UDPStandardImplementation.cpp +++ b/slsReceiverSoftware/src/UDPStandardImplementation.cpp @@ -2047,9 +2047,21 @@ int UDPStandardImplementation::startWriting(){ cprintf(GREEN,"packet %d blank frame 0x%x\n",i,(void*)(blankframe[i])); #endif } + + if(tengigaEnable){ + switch(dynamicRange){ + case 4: LAST_PACKET_VALUE = 0x10; break; + case 8: LAST_PACKET_VALUE = 0x20; break; + case 16: LAST_PACKET_VALUE = 0x40; break; + case 32: LAST_PACKET_VALUE = 0x80; break; + default: break; + } + } } + + //allow them all to be popped initially for(i=0;ipacketnum)); -//#endif +#endif }else if(numpackets[i] == EIGER_HEADER_LENGTH){ cprintf(BG_RED, "got header in writer, weirdd packetsize:%d\n",numpackets[i]); exit(-1); } -//#ifdef EIGER_DEBUG3 +#ifdef EIGER_DEBUG3 else { cprintf(BG_RED, "got weird in writer, weirdd packetsize:%d\n",numpackets[i]); } -//#endif +#endif if(myDetectorType == EIGER){ tofree[tofreeoffset[i]] = wbuf[i]; tofreeoffset[i]++; @@ -2126,9 +2138,9 @@ int UDPStandardImplementation::startWriting(){ //END OF ACQUISITION if(endofacquisition){ -//#ifdef EIGER_DEBUG3 +#ifdef EIGER_DEBUG3 cprintf(GREEN,"%d Both dummy frames\n", ithread); -//#endif +#endif //remaining packets to be written if((myDetectorType == EIGER) && ((tempoffset[0]!=0) || (tempoffset[1]!=(packetsPerFrame/numListeningThreads)))); @@ -2157,15 +2169,16 @@ int UDPStandardImplementation::startWriting(){ if(numpackets[i] == EIGER_HEADER_LENGTH) {cprintf(BG_RED,"weird, frame packet recieved\n"); exit(-1);} //dummy packet else if(!numpackets[i]){ -//#ifdef EIGER_DEBUG3 +#ifdef EIGER_DEBUG3 cprintf(RED, "Dummy packet: %d from fifo %d\n", numpackets[i],i); -//#endif +#endif + cout<<"packetsperframe:"<missingpacket)); exit(-1); }else -//#ifdef PADDING +#ifdef PADDING cprintf(GREEN, "blank packet i:%d pnum:%d fnum:%d missingpacket:0x%x\n",i, tempoffset[i],tempframenum[i],*( (uint16_t*) tempframe_header->missingpacket)); -//#endif +#endif tempoffset[i]++; blankoffset++; } @@ -2194,12 +2207,12 @@ int UDPStandardImplementation::startWriting(){ popready[i] = false; } } -//#ifdef EIGER_DEBUG3 +#ifdef EIGER_DEBUG3 else{ cprintf(RED, "WARNING: Got a weird packet size: %d from fifo %d\n", numpackets[i],i); continue; } -//#endif +#endif } @@ -2209,9 +2222,9 @@ int UDPStandardImplementation::startWriting(){ //not a full frame if(!fullframe[i]){ wbuf_footer = (eiger_packet_footer_t*)(wbuf[i] + footer_offset + HEADER_SIZE_NUM_TOT_PACKETS); -//#ifdef EIGER_DEBUG3 +#ifdef EIGER_DEBUG3 cprintf(GREEN,"**pnum of %d: %d\n",i,(*( (uint16_t*) wbuf_footer->packetnum))); -//#endif +#endif //update frame number tempframenum[i] =(uint32_t)(*( (uint64_t*) wbuf_footer)); @@ -2223,18 +2236,18 @@ int UDPStandardImplementation::startWriting(){ //WRONG FRAME - leave if(tempframenum[i] != presentframenum){ -//#ifdef PADDING +#ifdef PADDING cout<<"wrong packet"<packetnum)); -//#endif +#endif tempframenum[i] = presentframenum; //add missing packets numberofmissingpackets[i] = (LAST_PACKET_VALUE - lastpacketheader[i]); @@ -2257,12 +2270,12 @@ int UDPStandardImplementation::startWriting(){ (void*)(tempbuffer[tempoffset[i]])); exit(-1); }else -//#ifdef PADDING +#ifdef PADDING cprintf(GREEN, "blank packet i:%d pnum:%d fnum:%d missingpacket:0x%x add:0x%x\n", i,tempoffset[i],tempframenum[i], *( (uint16_t*) tempframe_header->missingpacket), (void*)(tempbuffer[tempoffset[i]])); -//#endif +#endif tempoffset[i] ++; blankoffset ++; } @@ -2274,12 +2287,12 @@ int UDPStandardImplementation::startWriting(){ //CORRECT FRAME - continue building frame else { -//#ifdef PADDING +#ifdef PADDING cout<<"correct packet"<packetnum); #ifdef VERYVERBOSE @@ -2308,12 +2321,12 @@ int UDPStandardImplementation::startWriting(){ (void*)(tempbuffer[tempoffset[i]])); exit(-1); }else -//#ifdef PADDING +#ifdef PADDING cprintf(GREEN, "blank packet i:%d pnum:%d fnum:%d missingpacket:0x%x add:0x%x\n", i,tempoffset[i],tempframenum[i], *( (uint16_t*) tempframe_header->missingpacket), (void*)(tempbuffer[tempoffset[i]])); -//#endif +#endif tempoffset[i] ++; blankoffset ++; } @@ -2328,31 +2341,31 @@ int UDPStandardImplementation::startWriting(){ tempbuffer[tempoffset[i]] = wbuf[i] + HEADER_SIZE_NUM_TOT_PACKETS; tempframe_header = (eiger_packet_header_t*) tempbuffer[tempoffset[i]]; tempframe_footer = (eiger_packet_footer_t*) (tempbuffer[tempoffset[i]] + footer_offset); -//#ifdef EIGER_DEBUG3 +#ifdef EIGER_DEBUG3 cprintf(GREEN,"**fifo:%d currentpacketheader: %d tempoffset:%d\n", i,*( (uint16_t*) tempframe_footer->packetnum),tempoffset[i]); -//#endif +#endif if(*( (uint16_t*) tempframe_footer->packetnum)!= (tempoffset[i]-(i*packetsPerFrame/numListeningThreads))+1){ cprintf(BG_RED, "pnum mismatch num4 earlier! i:%d pnum:%d pnum orig:%d fnum:%d add:0x%x\n", i,*( (uint16_t*) tempframe_footer->packetnum),*( (uint16_t*) wbuf_footer->packetnum), tempframenum[i],(void*)(tempbuffer[tempoffset[i]])); exit(-1); } -//#ifdef PADDING +#ifdef PADDING cprintf(GREEN, "normal packet i:%d pnum:%d fnum:%d missingpacket:0x%x add:0x%x\n", i,tempoffset[i],tempframenum[i], *( (uint16_t*) tempframe_header->missingpacket), (void*)(tempbuffer[tempoffset[i]])); -//#endif +#endif tempoffset[i] ++; //update last packet lastpacketheader[i] = currentpacketheader[i]; popready[i] = true; //last frame got, this will save time and also for last frames, it doesnt wait for stop receiver if(currentpacketheader[i] == LAST_PACKET_VALUE){ -//#ifdef EIGER_DEBUG3 +#ifdef EIGER_DEBUG3 cprintf(GREEN, "Got last packet\n"); -//#endif +#endif fullframe[i] = true; popready[i] = false; } @@ -2373,10 +2386,10 @@ int UDPStandardImplementation::startWriting(){ numMissingPackets += (numberofmissingpackets[0]+numberofmissingpackets[1]); numTotMissingPacketsInFile += numMissingPackets; numTotMissingPackets += numMissingPackets; -//#ifdef EIGER_DEBUG2 +#ifdef EIGER_DEBUG2 cprintf(GREEN,"**fnum:%d**\n",currframenum); -//#endif -//#ifdef EIGER_DEBUG3 +#endif +#ifdef EIGER_DEBUG3 if(numberofmissingpackets[0]) cprintf(RED, "fifo 0 missing packets:%d fnum:%d\n",numberofmissingpackets[0],currframenum); if(numberofmissingpackets[1]) @@ -2390,7 +2403,7 @@ int UDPStandardImplementation::startWriting(){ cprintf(RED,"found the missing packet at pnum:%d\n",j); } } -//#endif +#endif //write and copy to gui @@ -2432,14 +2445,14 @@ int UDPStandardImplementation::startWriting(){ } } -//#ifdef EIGER_DEBUG3 +#ifdef EIGER_DEBUG3 for(int i=0;ipacketnum)); } -//#endif +#endif } From 30b83861a427b11b89e8008de79e59461d408738 Mon Sep 17 00:00:00 2001 From: Dhanya Maliakal Date: Thu, 17 Sep 2015 12:34:17 +0200 Subject: [PATCH 27/68] 10g partial_frames should also work now --- slsReceiverSoftware/src/UDPStandardImplementation.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/slsReceiverSoftware/src/UDPStandardImplementation.cpp b/slsReceiverSoftware/src/UDPStandardImplementation.cpp index b0a24ebc0..23bbe0b7a 100644 --- a/slsReceiverSoftware/src/UDPStandardImplementation.cpp +++ b/slsReceiverSoftware/src/UDPStandardImplementation.cpp @@ -2172,8 +2172,7 @@ int UDPStandardImplementation::startWriting(){ #ifdef EIGER_DEBUG3 cprintf(RED, "Dummy packet: %d from fifo %d\n", numpackets[i],i); #endif - cout<<"packetsperframe:"< Date: Tue, 22 Sep 2015 11:56:37 +0200 Subject: [PATCH 28/68] doesnt crash at frame number 0 --- slsReceiverSoftware/src/UDPStandardImplementation.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/slsReceiverSoftware/src/UDPStandardImplementation.cpp b/slsReceiverSoftware/src/UDPStandardImplementation.cpp index 23bbe0b7a..6f86b2416 100644 --- a/slsReceiverSoftware/src/UDPStandardImplementation.cpp +++ b/slsReceiverSoftware/src/UDPStandardImplementation.cpp @@ -2166,7 +2166,7 @@ int UDPStandardImplementation::startWriting(){ //anything that is not a data packet of right size if(numpackets[i] != onePacketSize){ //header packet - if(numpackets[i] == EIGER_HEADER_LENGTH) {cprintf(BG_RED,"weird, frame packet recieved\n"); exit(-1);} + if(numpackets[i] == EIGER_HEADER_LENGTH) {cprintf(BG_RED,"weird, header frame packet recieved. shouldnt\n"); exit(-1);} //dummy packet else if(!numpackets[i]){ #ifdef EIGER_DEBUG3 @@ -2225,11 +2225,11 @@ int UDPStandardImplementation::startWriting(){ cprintf(GREEN,"**pnum of %d: %d\n",i,(*( (uint16_t*) wbuf_footer->packetnum))); #endif //update frame number + if(!((uint32_t)(*( (uint64_t*) wbuf_footer)))){ + cprintf(BG_RED,"**VERY WEIRD frame numbers for fifo %d: %d\n",i,(uint32_t)(*( (uint64_t*) wbuf_footer))); + continue; + } tempframenum[i] =(uint32_t)(*( (uint64_t*) wbuf_footer)); - - - if(!tempframenum[i]) - cprintf(RED,"**VERY WEIRD frame numbers for fifo %d: %d\n",i,tempframenum[i]); tempframenum[i] += (startFrameIndex-1); From 71cd046bed1ea7b449b17fa673a1acf1c53532b4 Mon Sep 17 00:00:00 2001 From: Dhanya Maliakal Date: Tue, 22 Sep 2015 12:16:42 +0200 Subject: [PATCH 29/68] small change to ensure no crash at wrong frame read --- slsReceiverSoftware/src/UDPStandardImplementation.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/slsReceiverSoftware/src/UDPStandardImplementation.cpp b/slsReceiverSoftware/src/UDPStandardImplementation.cpp index 6f86b2416..5abb79fcc 100644 --- a/slsReceiverSoftware/src/UDPStandardImplementation.cpp +++ b/slsReceiverSoftware/src/UDPStandardImplementation.cpp @@ -2226,7 +2226,9 @@ int UDPStandardImplementation::startWriting(){ #endif //update frame number if(!((uint32_t)(*( (uint64_t*) wbuf_footer)))){ - cprintf(BG_RED,"**VERY WEIRD frame numbers for fifo %d: %d\n",i,(uint32_t)(*( (uint64_t*) wbuf_footer))); + cprintf(BG_RED,"%d VERY WEIRD frame number=%d and popready:%d\n", + i,(uint32_t)(*( (uint64_t*) wbuf_footer)),popready[i]); + popready[i]=true; continue; } tempframenum[i] =(uint32_t)(*( (uint64_t*) wbuf_footer)); From 7c0430572b731e8476f26fab2e7ebbdc2e8fa535 Mon Sep 17 00:00:00 2001 From: Dhanya Maliakal Date: Tue, 22 Sep 2015 16:21:41 +0200 Subject: [PATCH 30/68] included subframe into receiver and sends to gui --- .../include/UDPBaseImplementation.h | 9 +-- slsReceiverSoftware/include/UDPInterface.h | 3 +- .../include/UDPStandardImplementation.h | 5 +- .../src/UDPBaseImplementation.cpp | 56 ++----------------- .../src/UDPStandardImplementation.cpp | 26 +++------ .../src/slsReceiverTCPIPInterface.cpp | 56 +++++++++++++++---- 6 files changed, 63 insertions(+), 92 deletions(-) diff --git a/slsReceiverSoftware/include/UDPBaseImplementation.h b/slsReceiverSoftware/include/UDPBaseImplementation.h index d69e00b93..cbc4f386c 100644 --- a/slsReceiverSoftware/include/UDPBaseImplementation.h +++ b/slsReceiverSoftware/include/UDPBaseImplementation.h @@ -297,11 +297,10 @@ class UDPBaseImplementation : protected virtual slsReceiverDefs, public UDPInter * Returns the buffer-current frame read by receiver * @param c pointer to current file name * @param raw address of pointer, pointing to current frame to send to gui - * @param fnum frame number for eiger as it is not in the packet * @param startAcquisitionIndex is the start index of the acquisition * @param startFrameIndex is the start index of the scan */ - void readFrame(char* c,char** raw, uint32_t &fnum, uint32_t &startAcquisitionIndex, uint32_t &startFrameIndex); + void readFrame(char* c,char** raw, uint32_t &startAcquisitionIndex, uint32_t &startFrameIndex); /** * Closes all files @@ -359,7 +358,7 @@ protected: * Copy frames to gui * uses semaphore for nth frame mode */ - void copyFrameToGui(char* startbuf[], uint32_t fnum=-1, char* buf=NULL); + void copyFrameToGui(char* startbuf[], char* buf=NULL); /** * creates udp sockets @@ -483,6 +482,7 @@ protected: //// Could be done more fine-grained... TODO // private: protected: + /** structure of an eiger packet*/ typedef struct { @@ -643,9 +643,6 @@ protected: /** points to the filename to send to gui */ char* guiFileName; - /** temporary number for eiger frame number as its not included in the packet */ - uint32_t guiFrameNumber; - /** send every nth frame to gui or only upon gui request*/ int nFrameToGui; diff --git a/slsReceiverSoftware/include/UDPInterface.h b/slsReceiverSoftware/include/UDPInterface.h index 8952396f3..c1d30ec0b 100644 --- a/slsReceiverSoftware/include/UDPInterface.h +++ b/slsReceiverSoftware/include/UDPInterface.h @@ -338,11 +338,10 @@ class UDPInterface { * Returns the buffer-current frame read by receiver * @param c pointer to current file name * @param raw address of pointer, pointing to current frame to send to gui - * @param fnum frame number for eiger as it is not in the packet * @param startAcquisitionIndex is the start index of the acquisition * @param startFrameIndex is the start index of the scan */ - virtual void readFrame(char* c,char** raw, uint32_t &fnum, uint32_t &startAcquisitionIndex, uint32_t &startFrameIndex)=0; + virtual void readFrame(char* c,char** raw, uint32_t &startAcquisitionIndex, uint32_t &startFrameIndex)=0; /** set status to transmitting and * when fifo is empty later, sets status to run_finished diff --git a/slsReceiverSoftware/include/UDPStandardImplementation.h b/slsReceiverSoftware/include/UDPStandardImplementation.h index 92092bead..2916ee6b9 100644 --- a/slsReceiverSoftware/include/UDPStandardImplementation.h +++ b/slsReceiverSoftware/include/UDPStandardImplementation.h @@ -294,11 +294,10 @@ class UDPStandardImplementation: private virtual slsReceiverDefs, public UDPBase * Returns the buffer-current frame read by receiver * @param c pointer to current file name * @param raw address of pointer, pointing to current frame to send to gui - * @param fnum frame number for eiger as it is not in the packet * @param startAcquisitionIndex is the start index of the acquisition * @param startFrameIndex is the start index of the scan */ - void readFrame(char* c,char** raw, uint32_t &fnum, uint32_t &startAcquisitionIndex, uint32_t &startFrameIndex); + void readFrame(char* c,char** raw, uint32_t &startAcquisitionIndex, uint32_t &startFrameIndex); /** * Closes all files @@ -356,7 +355,7 @@ private: * Copy frames to gui * uses semaphore for nth frame mode */ - void copyFrameToGui(char* startbuf[], uint32_t fnum=-1, char* buf=NULL); + void copyFrameToGui(char* startbuf[], char* buf=NULL); /** * creates udp sockets diff --git a/slsReceiverSoftware/src/UDPBaseImplementation.cpp b/slsReceiverSoftware/src/UDPBaseImplementation.cpp index fb10ae106..20326bafd 100644 --- a/slsReceiverSoftware/src/UDPBaseImplementation.cpp +++ b/slsReceiverSoftware/src/UDPBaseImplementation.cpp @@ -567,7 +567,7 @@ void UDPBaseImplementation::setupFifoStructure(){ FILE_LOG(logDEBUG) << __AT__ < /** acquisition functions */ -void UDPBaseImplementation::readFrame(char* c,char** raw, uint32_t &fnum, uint32_t &startAcquisitionIndex, uint32_t &startFrameIndex){ +void UDPBaseImplementation::readFrame(char* c,char** raw,uint32_t &startAcquisitionIndex, uint32_t &startFrameIndex){ FILE_LOG(logDEBUG) << __AT__ << " called"; //point to gui data if (guiData == NULL){ @@ -576,7 +576,6 @@ void UDPBaseImplementation::readFrame(char* c,char** raw, uint32_t &fnum, uint32 //copy data and filename strcpy(c,guiFileName); - fnum = guiFrameNumber; startAcquisitionIndex = getStartAcquisitionIndex(); startFrameIndex = getStartFrameIndex(); @@ -601,55 +600,8 @@ void UDPBaseImplementation::readFrame(char* c,char** raw, uint32_t &fnum, uint32 -void UDPBaseImplementation::copyFrameToGui(char* startbuf[], uint32_t fnum, char* buf){ FILE_LOG(logDEBUG) << __AT__ << " starting"; +void UDPBaseImplementation::copyFrameToGui(char* startbuf[], char* buf){ FILE_LOG(logDEBUG) << __AT__ << " starting"; - //random read when gui not ready - if((!nFrameToGui) && (!guiData)){ - pthread_mutex_lock(&dataReadyMutex); - guiDataReady=0; - pthread_mutex_unlock(&dataReadyMutex); - } - - //random read or nth frame read, gui needs data now or it is the first frame - else{ - /* - //nth frame read, block current process if the guireader hasnt read it yet - if(nFrameToGui) - sem_wait(&smp); -*/ - pthread_mutex_lock(&dataReadyMutex); - guiDataReady=0; - //eiger - if(startbuf != NULL){ - int offset = 0; - int size = frameSize/EIGER_MAX_PORTS; - for(int j=0;j= packetsPerFrame){//min 1 frame, but neednt be //if(npackets == packetsPerFrame * numJobsPerThread){ //only full frames - copyFrameToGui(NULL,-1,wbuffer[0]+HEADER_SIZE_NUM_TOT_PACKETS); + copyFrameToGui(NULL,wbuffer[0]+HEADER_SIZE_NUM_TOT_PACKETS); #ifdef VERYVERBOSE cout << ithread << " finished copying" << endl; #endif @@ -3087,7 +3075,7 @@ void UDPStandardImplementation::handleDataCompression(int ithread, char* wbuffer #endif if(!once){ - copyFrameToGui(NULL,-1,buff); + copyFrameToGui(NULL,buff); once = 1; } } diff --git a/slsReceiverSoftware/src/slsReceiverTCPIPInterface.cpp b/slsReceiverSoftware/src/slsReceiverTCPIPInterface.cpp index 17ff75764..ffa3f5d8c 100644 --- a/slsReceiverSoftware/src/slsReceiverTCPIPInterface.cpp +++ b/slsReceiverSoftware/src/slsReceiverTCPIPInterface.cpp @@ -1068,7 +1068,7 @@ int slsReceiverTCPIPInterface::moench_read_frame(){ uint32_t startAcquisitionIndex=0; uint32_t startFrameIndex=0; - uint32_t index = 0,bindex = 0, offset=0; + uint32_t index = -1,bindex = 0, offset=0; strcpy(mess,"Could not read frame\n"); @@ -1088,7 +1088,7 @@ int slsReceiverTCPIPInterface::moench_read_frame(){ else{ ret = OK; /*startIndex=receiverBase->getStartFrameIndex();*/ - receiverBase->readFrame(fName,&raw,index,startAcquisitionIndex,startFrameIndex); + receiverBase->readFrame(fName,&raw,startAcquisitionIndex,startFrameIndex); /**send garbage with -1 index to try again*/ if (raw == NULL){ @@ -1253,7 +1253,7 @@ int slsReceiverTCPIPInterface::gotthard_read_frame(){ char* raw = new char[bufferSize]; - uint32_t index=0,index2=0; + uint32_t index=-1,index2=0; uint32_t pindex=0,pindex2=0; uint32_t bindex=0,bindex2=0; uint32_t startAcquisitionIndex=0; @@ -1277,7 +1277,7 @@ int slsReceiverTCPIPInterface::gotthard_read_frame(){ }else{ ret = OK; /*startIndex=receiverBase->getStartFrameIndex();*/ - receiverBase->readFrame(fName,&raw,index,startAcquisitionIndex,startFrameIndex); + receiverBase->readFrame(fName,&raw,startAcquisitionIndex,startFrameIndex); /**send garbage with -1 index to try again*/ if (raw == NULL){ @@ -1429,7 +1429,7 @@ int slsReceiverTCPIPInterface::propix_read_frame(){ for(i=0;igetStartFrameIndex();*/ - receiverBase->readFrame(fName,&raw,index,startAcquisitionIndex,startFrameIndex); + receiverBase->readFrame(fName,&raw,startAcquisitionIndex,startFrameIndex); /**send garbage with -1 index to try again*/ if (raw == NULL){ @@ -1567,16 +1567,36 @@ int slsReceiverTCPIPInterface::propix_read_frame(){ int slsReceiverTCPIPInterface::eiger_read_frame(){ ret=OK; + + /** structure of an eiger packet*/ + typedef struct + { + unsigned char subframenum[4]; + unsigned char missingpacket[2]; + unsigned char portnum[1]; + unsigned char dynamicrange[1]; + } eiger_packet_header_t; + + typedef struct + { + unsigned char framenum[6]; + unsigned char packetnum[2]; + } eiger_packet_footer_t; + + char fName[MAX_STR_LENGTH]=""; int acquisitionIndex = -1; int frameIndex= -1; uint32_t index=0; + uint32_t subframenumber=-1; int frameSize = EIGER_ONE_GIGA_ONE_PACKET_SIZE * packetsPerFrame; int dataSize = EIGER_ONE_GIGA_ONE_DATA_SIZE * packetsPerFrame; + int oneDataSize = EIGER_ONE_GIGA_ONE_DATA_SIZE; if(tenGigaEnable){ frameSize = EIGER_TEN_GIGA_ONE_PACKET_SIZE * packetsPerFrame; dataSize = EIGER_TEN_GIGA_ONE_DATA_SIZE * packetsPerFrame; + oneDataSize = EIGER_TEN_GIGA_ONE_DATA_SIZE; } char* raw = new char[frameSize]; char* origVal = new char[frameSize]; @@ -1605,10 +1625,8 @@ int slsReceiverTCPIPInterface::eiger_read_frame(){ else{ ret = OK; /** read a frame */ - receiverBase->readFrame(fName,&raw,index,startAcquisitionIndex,startFrameIndex); -#ifdef VERBOSE - cout << "index:" << dec << index << endl; -#endif + receiverBase->readFrame(fName,&raw,startAcquisitionIndex,startFrameIndex); + /**send garbage with -1 index to try again*/ if (raw == NULL){ startAcquisitionIndex = -1; @@ -1620,6 +1638,21 @@ int slsReceiverTCPIPInterface::eiger_read_frame(){ /**proper frame*/ else{//cout<<"**** got proper frame ******"<subframenum); + } + +#ifdef VERBOSE + cout << "index:" << dec << index << endl; + cout << "subframenumber:" << dec << subframenumber << endl; +#endif + memcpy(origVal,raw,frameSize); raw=NULL; @@ -1740,6 +1773,7 @@ int slsReceiverTCPIPInterface::eiger_read_frame(){ cout << "index:" << index << endl; cout << "startAcquisitionIndex:" << startAcquisitionIndex << endl; cout << "startFrameIndex:" << startFrameIndex << endl; + cout << "subframenumber:" << subframenumber << endl; #endif } } @@ -1751,6 +1785,7 @@ int slsReceiverTCPIPInterface::eiger_read_frame(){ cout << "frameIndex:" << frameIndex << endl; cout << "startAcquisitionIndex:" << startAcquisitionIndex << endl; cout << "startFrameIndex:" << startFrameIndex << endl; + cout << "subframenumber:" << subframenumber << endl; } #endif @@ -1773,6 +1808,7 @@ int slsReceiverTCPIPInterface::eiger_read_frame(){ socket->SendDataOnly(fName,MAX_STR_LENGTH); socket->SendDataOnly(&acquisitionIndex,sizeof(acquisitionIndex)); socket->SendDataOnly(&frameIndex,sizeof(frameIndex)); + socket->SendDataOnly(&subframenumber,sizeof(subframenumber)); socket->SendDataOnly(retval,dataSize); } From 06b38e591ced7837b36c64b56142781c6a40b573 Mon Sep 17 00:00:00 2001 From: Dhanya Maliakal Date: Wed, 23 Sep 2015 12:34:21 +0200 Subject: [PATCH 31/68] got rid of warnings --- slsReceiverSoftware/include/circularFifo.h | 2 +- .../src/UDPBaseImplementation.cpp | 185 ------------------ .../src/UDPStandardImplementation.cpp | 24 +-- .../src/slsReceiverTCPIPInterface.cpp | 7 +- 4 files changed, 14 insertions(+), 204 deletions(-) diff --git a/slsReceiverSoftware/include/circularFifo.h b/slsReceiverSoftware/include/circularFifo.h index 6f779aafc..1ba584cc4 100644 --- a/slsReceiverSoftware/include/circularFifo.h +++ b/slsReceiverSoftware/include/circularFifo.h @@ -79,7 +79,7 @@ template bool CircularFifo::push(Element*& item_) { - int nextTail = increment(tail); + unsigned int nextTail = increment(tail); if(nextTail != head) { array[tail] = item_; diff --git a/slsReceiverSoftware/src/UDPBaseImplementation.cpp b/slsReceiverSoftware/src/UDPBaseImplementation.cpp index 20326bafd..682c52980 100644 --- a/slsReceiverSoftware/src/UDPBaseImplementation.cpp +++ b/slsReceiverSoftware/src/UDPBaseImplementation.cpp @@ -1399,12 +1399,6 @@ int UDPBaseImplementation::startListening(){ FILE_LOG(logDEBUG) << __AT__ << " s int UDPBaseImplementation::startWriting(){ FILE_LOG(logDEBUG) << __AT__ << " starting"; - int ithread = currentWriterThreadIndex; -#ifdef VERYVERBOSE - cout << ithread << "In startWriting()" < 0){ - - //for progress and packet loss calculation(new files) - if(myDetectorType == EIGER); - else if ((myDetectorType == GOTTHARD) && (shortFrame == -1)) - tempframenum = (((((uint32_t)(*((uint32_t*)(buf + HEADER_SIZE_NUM_TOT_PACKETS))))+1)& (frameIndexMask)) >> frameIndexOffset); - else - tempframenum = ((((uint32_t)(*((uint32_t*)(buf + HEADER_SIZE_NUM_TOT_PACKETS))))& (frameIndexMask)) >> frameIndexOffset); - - if(numWriterThreads == 1) - currframenum = tempframenum; - else{ - if(tempframenum > currframenum) - currframenum = tempframenum; - } -#ifdef VERYDEBUG - cout << "tempframenum:" << dec << tempframenum << " curframenum:" << currframenum << endl; -#endif - - //lock - if(numWriterThreads > 1) - pthread_mutex_lock(&write_mutex); - - - //to create new file when max reached - packetsToSave = maxPacketsPerFile - packetsInFile; - if(packetsToSave > numpackets) - packetsToSave = numpackets; -/**next time offset is still plus header length*/ - fwrite(buf+offset, 1, packetsToSave * onePacketSize, sfilefd); - packetsInFile += packetsToSave; - packetsCaught += packetsToSave; - totalPacketsCaught += packetsToSave; - - - //new file - if(packetsInFile >= maxPacketsPerFile){ - //for packet loss - lastpacket = (((packetsToSave - 1) * onePacketSize) + offset); - if(myDetectorType == EIGER); - else if ((myDetectorType == GOTTHARD) && (shortFrame == -1)) - tempframenum = (((((uint32_t)(*((uint32_t*)(buf + lastpacket))))+1)& (frameIndexMask)) >> frameIndexOffset); - else - tempframenum = ((((uint32_t)(*((uint32_t*)(buf + lastpacket))))& (frameIndexMask)) >> frameIndexOffset); - - if(numWriterThreads == 1) - currframenum = tempframenum; - else{ - if(tempframenum > currframenum) - currframenum = tempframenum; - } -#ifdef VERYDEBUG - cout << "tempframenum:" << dec << tempframenum << " curframenum:" << currframenum << endl; -#endif - //create - createNewFile(); - } - - //unlock - if(numWriterThreads > 1) - pthread_mutex_unlock(&write_mutex); - - - offset += (packetsToSave * onePacketSize); - numpackets -= packetsToSave; - } - - } - else{ - if(numWriterThreads > 1) - pthread_mutex_lock(&write_mutex); - packetsInFile += numpackets; - packetsCaught += numpackets; - totalPacketsCaught += numpackets; - if(numWriterThreads > 1) - pthread_mutex_unlock(&write_mutex); - } } @@ -1675,97 +1581,6 @@ void UDPBaseImplementation::handleDataCompression(int ithread, char* wbuffer[], FILE_LOG(logDEBUG) << __FILE__ << "::" << __func__ << " starting"; -#if defined(MYROOT1) && defined(ALLFILE_DEBUG) - writeToFile_withoutCompression(wbuf[0], numpackets,currframenum); -#endif - - eventType thisEvent = PEDESTAL; - int ndata; - char* buff = 0; - int npackets = (uint16_t)(*((uint16_t*)wbuffer[0])); - data = wbuffer[0]+ HEADER_SIZE_NUM_TOT_PACKETS; - int remainingsize = npackets * onePacketSize; - int np; - int once = 0; - double tot, tl, tr, bl, br; - int xmin = 1, ymin = 1, ix, iy; - - - while(buff = receiverdata[ithread]->findNextFrame(data,ndata,remainingsize)){ - np = ndata/onePacketSize; - - //cout<<"buff framnum:"<> frameIndexOffset)<newFrame(); - - //only for moench - if(commonModeSubtractionEnable){ - for(ix = xmin - 1; ix < xmax+1; ix++){ - for(iy = ymin - 1; iy < ymax+1; iy++){ - thisEvent = singlePhotonDet[ithread]->getEventType(buff, ix, iy, 0); - } - } - } - - - for(ix = xmin - 1; ix < xmax+1; ix++) - for(iy = ymin - 1; iy < ymax+1; iy++){ - thisEvent=singlePhotonDet[ithread]->getEventType(buff, ix, iy, commonModeSubtractionEnable); - if (nf>1000) { - tot=0; - tl=0; - tr=0; - bl=0; - br=0; - if (thisEvent==PHOTON_MAX) { - receiverdata[ithread]->getFrameNumber(buff); - //iFrame=receiverdata[ithread]->getFrameNumber(buff); -#ifdef MYROOT1 - myTree[ithread]->Fill(); - //cout << "Fill in event: frmNr: " << iFrame << " ix " << ix << " iy " << iy << " type " << thisEvent << endl; -#else - pthread_mutex_lock(&write_mutex); - if((enableFileWrite) && (sfilefd)) - singlePhotonDet[ithread]->writeCluster(sfilefd); - pthread_mutex_unlock(&write_mutex); -#endif - } - } - } - - nf++; -#ifndef ALLFILE - pthread_mutex_lock(&progress_mutex); - packetsInFile += packetsPerFrame; - packetsCaught += packetsPerFrame; - totalPacketsCaught += packetsPerFrame; - if(packetsInFile >= maxPacketsPerFile) - createNewFile(); - pthread_mutex_unlock(&progress_mutex); - -#endif - if(!once){ - copyFrameToGui(NULL,buff); - once = 1; - } - } - - remainingsize -= ((buff + ndata) - data); - data = buff + ndata; - if(data > (wbuffer[0] + HEADER_SIZE_NUM_TOT_PACKETS + npackets * onePacketSize) ) - cout <<" **************ERROR SHOULD NOT COME HERE, Error 142536!"<push(wbuffer[0])); -#ifdef VERYVERBOSE - cout<<"buf freed:"<<(void*)wbuffer[0]<missingpacket)!= missingPacketValue){ cprintf(BG_RED, "wrong blank mismatch num4 earlier2! " - "i:%d pnum:%d fnum:%d missingpacket:0x%x actual missingpacket:0x%x add:0x%x\n", + "i:%d pnum:%d fnum:%d missingpacket:0x%x actual missingpacket:0x%x add:0x%p\n", i,tempoffset[i],tempframenum[i], *( (uint16_t*) tempframe_header->missingpacket), *( (uint16_t*) blankframe_header->missingpacket), @@ -2303,7 +2297,7 @@ int UDPStandardImplementation::startWriting(){ blankframe_header = (eiger_packet_header_t*) blankframe[blankoffset]; if (*( (uint16_t*) tempframe_header->missingpacket)!= missingPacketValue){ cprintf(BG_RED, "correct blank mismatch num4 earlier2! " - "i:%d pnum:%d fnum:%d missingpacket:0x%x actual missingpacket:0x%x add:0x%x\n", + "i:%d pnum:%d fnum:%d missingpacket:0x%x actual missingpacket:0x%x add:0x%p\n", i,tempoffset[i],tempframenum[i], *( (uint16_t*) tempframe_header->missingpacket), *( (uint16_t*) blankframe_header->missingpacket), @@ -2320,7 +2314,7 @@ int UDPStandardImplementation::startWriting(){ blankoffset ++; } //add current packet - if(currentpacketheader[i] != (tempoffset[i]-(i*packetsPerFrame/numListeningThreads))+1){ + if(currentpacketheader[i] != (uint32_t)(tempoffset[i]-(i*packetsPerFrame/numListeningThreads))+1){ cprintf(BG_RED, "correct pnum mismatch earlier! tempoffset[%d]:%d pnum:%d fnum:%d rfnum:%d\n", i,tempoffset[i],currentpacketheader[i], tempframenum[i],(uint32_t)(*( (uint64_t*) wbuf_footer))); @@ -2335,7 +2329,7 @@ int UDPStandardImplementation::startWriting(){ i,*( (uint16_t*) tempframe_footer->packetnum),tempoffset[i]); #endif if(*( (uint16_t*) tempframe_footer->packetnum)!= (tempoffset[i]-(i*packetsPerFrame/numListeningThreads))+1){ - cprintf(BG_RED, "pnum mismatch num4 earlier! i:%d pnum:%d pnum orig:%d fnum:%d add:0x%x\n", + cprintf(BG_RED, "pnum mismatch num4 earlier! i:%d pnum:%d pnum orig:%d fnum:%d add:0x%p\n", i,*( (uint16_t*) tempframe_footer->packetnum),*( (uint16_t*) wbuf_footer->packetnum), tempframenum[i],(void*)(tempbuffer[tempoffset[i]])); exit(-1); @@ -2815,7 +2809,7 @@ void UDPStandardImplementation::writeToFile_withoutCompression(char* buf[],int n cprintf(GREEN,"totalPacketsCaught:%d\n", totalPacketsCaught); #endif //new file - if(packetsInFile >= maxPacketsPerFile){ + if(packetsInFile >= (uint32_t)maxPacketsPerFile){ //for packet loss, because currframenum is the latest one for eiger if(myDetectorType != EIGER){ @@ -2870,7 +2864,7 @@ void UDPStandardImplementation::writeToFile_withoutCompression(char* buf[],int n void UDPStandardImplementation::handleWithoutDataCompression(int ithread, char* wbuffer[],int npackets){ - int i,j, missingpacket,port = 0, pnuminc; + int i, missingpacket,port = 0; if (cbAction < DO_EVERYTHING){ @@ -3069,7 +3063,7 @@ void UDPStandardImplementation::handleDataCompression(int ithread, char* wbuffer packetsInFile += packetsPerFrame; packetsCaught += packetsPerFrame; totalPacketsCaught += packetsPerFrame; - if(packetsInFile >= maxPacketsPerFile) + if(packetsInFile >= (uint32_t)maxPacketsPerFile) createNewFile(); pthread_mutex_unlock(&progress_mutex); diff --git a/slsReceiverSoftware/src/slsReceiverTCPIPInterface.cpp b/slsReceiverSoftware/src/slsReceiverTCPIPInterface.cpp index ffa3f5d8c..24e475c50 100644 --- a/slsReceiverSoftware/src/slsReceiverTCPIPInterface.cpp +++ b/slsReceiverSoftware/src/slsReceiverTCPIPInterface.cpp @@ -39,10 +39,11 @@ slsReceiverTCPIPInterface::slsReceiverTCPIPInterface(int &success, UDPInterface* shortFrame(-1), packetsPerFrame(GOTTHARD_PACKETS_PER_FRAME), dynamicrange(16), - socket(NULL), killTCPServerThread(0), - tenGigaEnable(0), portNumber(DEFAULT_PORTNO+2), - bottom(bot){ + tenGigaEnable(0), + portNumber(DEFAULT_PORTNO+2), + bottom(bot), + socket(NULL){ int port_no=portNumber; if(receiverBase == NULL) receiverBase = 0; From c392348def93499c7b67cd040343c9c3c0e5799e Mon Sep 17 00:00:00 2001 From: Dhanya Maliakal Date: Wed, 30 Sep 2015 11:40:39 +0200 Subject: [PATCH 32/68] big change half done --- .../include/UDPBaseImplementation.h | 1091 ++++------ slsReceiverSoftware/include/UDPInterface.h | 602 +++--- .../include/UDPStandardImplementation.h | 221 +- .../src/UDPBaseImplementation.cpp | 1915 +++-------------- slsReceiverSoftware/src/UDPInterface.cpp | 1 - .../src/UDPStandardImplementation.cpp | 4 +- .../src/slsReceiverTCPIPInterface.cpp | 360 +++- 7 files changed, 1560 insertions(+), 2634 deletions(-) diff --git a/slsReceiverSoftware/include/UDPBaseImplementation.h b/slsReceiverSoftware/include/UDPBaseImplementation.h index cbc4f386c..29d9dd009 100644 --- a/slsReceiverSoftware/include/UDPBaseImplementation.h +++ b/slsReceiverSoftware/include/UDPBaseImplementation.h @@ -8,25 +8,9 @@ #include "sls_receiver_defs.h" -#include "receiver_defs.h" -#include "genericSocket.h" -#include "circularFifo.h" -#include "singlePhotonDetector.h" -#include "slsReceiverData.h" -#include "moenchCommonMode.h" - #include "UDPInterface.h" - -#ifdef MYROOT1 -#include -#include -#endif - - #include -#include #include -#include /** * @short does all the functions for a receiver, set/get parameters, start/stop etc. @@ -35,6 +19,11 @@ class UDPBaseImplementation : protected virtual slsReceiverDefs, public UDPInterface { public: + + /************************************************************************* + * Constructor & Destructor ********************************************** + * They access local cache of configuration or detector parameters ******* + *************************************************************************/ /** * Constructor */ @@ -45,800 +34,538 @@ class UDPBaseImplementation : protected virtual slsReceiverDefs, public UDPInter */ virtual ~UDPBaseImplementation(); - void configure(map config_map); + /************************************************************************* + * Getters *************************************************************** + * They access local cache of configuration or detector parameters ******* + *************************************************************************/ - /** - * delete and free member parameters - */ - void deleteMembers(); - - /** - * initialize member parameters - */ - void initializeMembers(); - - /** - * Set receiver type - * @param det detector type - * Returns success or FAIL - */ - int setDetectorType(detectorType det); - - /** - * Set bottom to bot - * @param bot = 1 if bottom - */ - void setBottom(int bot); - - //Frame indices and numbers caught - /** - * Returns the frame index at start of entire acquisition (including all scans) - */ - uint32_t getStartAcquisitionIndex(); - - /** - * Returns current Frame Index Caught for an entire acquisition (including all scans) - */ - uint32_t getAcquisitionIndex(); - - /** - * Returns if acquisition started - */ - bool getAcquistionStarted(); - - /** - * Returns Frames Caught for each real time acquisition (eg. for each scan) - */ - int getFramesCaught(); - - /** - * Returns Total Frames Caught for an entire acquisition (including all scans) - */ - int getTotalFramesCaught(); - - /** - * Returns the frame index at start of each real time acquisition (eg. for each scan) - */ - uint32_t getStartFrameIndex(); - - /** - * Returns current Frame Index for each real time acquisition (eg. for each scan) - */ - uint32_t getFrameIndex(); - - /** - * Returns if measurement started - */ - bool getMeasurementStarted(); - - /** - * Resets the Total Frames Caught - * This is how the receiver differentiates between entire acquisitions - * Returns 0 - */ - void resetTotalFramesCaught(); - - - - - //file parameters - /** - * Returns File Path - */ - char* getFilePath() const; - - /** - * Set File Path - * @param c file path - */ - char* setFilePath(const char c[]); - - /** - * Returns File Name - */ - char* getFileName() const; - - /** - * Set File Name (without frame index, file index and extension) - * @param c file name - */ - char* setFileName(const char c[]); - - /** - * Returns File Index - */ - int getFileIndex(); - - /** - * Set File Index - * @param i file index - */ - int setFileIndex(int i); - - /** - * Set Frame Index Needed - * @param i frame index needed - */ - int setFrameIndexNeeded(int i); - - /** - * Set enable file write - * @param i file write enable - * Returns file write enable - */ - int setEnableFileWrite(int i); - - /** - * Enable/disable overwrite - * @param i enable - * Returns enable over write - */ - int setEnableOverwrite(int i); - - /** - * Returns file write enable - * 1: YES 0: NO - */ - int getEnableFileWrite() const; - - /** - * Returns file over write enable - * 1: YES 0: NO - */ - int getEnableOverwrite() const; - -//other parameters - - /** - * abort acquisition with minimum damage: close open files, cleanup. - * does nothing if state already is 'idle' - */ - void abort() {}; - - /** - * Returns status of receiver: idle, running or error - */ - runStatus getStatus() const; - - /** - * Set detector hostname - * @param c hostname - */ - void initialize(const char *detectorHostName); - - /* Returns detector hostname - /returns hostname - * caller needs to deallocate the returned char array. - * if uninitialized, it must return NULL + //**initial parameters*** + /* + * Get detector hostname + * @return NULL or hostname or NULL if uninitialized (max of 1000 characters) */ char *getDetectorHostname() const; + + //***file parameters*** /** - * Set Ethernet Interface or IP to listen to + * Get File Name Prefix (without frame index, file index and extension (_d0_f000000000000_8.raw)) + * @return NULL or file name prefix (max of 1000 characters) */ - void setEthernetInterface(char* c); + char *getFileName() const; /** - * Set UDP Port Number + * Get File Path + * @return NULL or file path (max of 1000 characters) */ - void setUDPPortNo(int p); - void setUDPPortNo2(int p); - - /* - * Returns number of frames to receive - * This is the number of frames to expect to receiver from the detector. - * The data receiver will change from running to idle when it got this number of frames - */ - int getNumberOfFrames() const; + char *getFilePath() const; /** - * set frame number if a positive number + * Get File Index + * @return file index of acquisition */ - int32_t setNumberOfFrames(int32_t fnum); + uint64_t getFileIndex() const; /** - * Returns scan tag + * Get Scan Tag + * @return scan tag //FIXME: needed? (unsigned integer?) */ int getScanTag() const; /** - * set scan tag if its is a positive number + * Get if Frame Index is enabled (acquisition of more than 1 frame adds '_f000000000000' to file name ) + * @return true if frame index needed, else false */ - int32_t setScanTag(int32_t stag); + bool getFrameIndexEnable() const; /** - * Returns the number of bits per pixel + * Get File Write Enable + * @return true if file write enabled, else false */ - int getDynamicRange() const; + bool getFileWriteEnable() const; /** - * set dynamic range if its is a positive number + * Get File Over Write Enable + * @return true if file over write enabled, else false */ - int32_t setDynamicRange(int32_t dr); + bool getOverwriteEnable() const; /** - * Set short frame - * @param i if shortframe i=1 + * Get data compression, by saving only hits (so far implemented only for Moench and Gotthard) + * @return true if data compression enabled, else false */ - int setShortFrame(int i); + bool getDataCompressionEnable() const; + + + //***acquisition count parameters*** + /** + * Get Total Frames Caught for an entire acquisition (including all scans) + * @return total number of frames caught for entire acquisition + */ + uint64_t getTotalFramesCaught() const; /** - * Set the variable to send every nth frame to gui - * or if 0,send frame only upon gui request + * Get Frames Caught for each real time acquisition (eg. for each scan) + * @return number of frames caught for each scan */ - int setNFrameToGui(int i); - - /** set acquisition period if a positive number - */ - int64_t setAcquisitionPeriod(int64_t index); - - /** get data compression, by saving only hits - */ - bool getDataCompression(); - - /** enabl data compression, by saving only hits - /returns if failed - */ - int enableDataCompression(bool enable); + uint64_t getFramesCaught() const; /** - * enable 10Gbe - @param enable 1 for 10Gbe or 0 for 1 Gbe, -1 to read out - \returns enable for 10Gbe + * Get Current Frame Index Caught for an entire acquisition (including all scans) + * @return current frame index (represents all scans too) */ - int enableTenGiga(int enable = -1); + int64_t getAcquisitionIndex() const; - -//other functions + //***connection parameters*** + /** + * Get UDP Port Number + * @return udp port number + */ + uint32_t getUDPPortNo() const; /** - * Returns the buffer-current frame read by receiver - * @param c pointer to current file name - * @param raw address of pointer, pointing to current frame to send to gui - * @param startAcquisitionIndex is the start index of the acquisition - * @param startFrameIndex is the start index of the scan + * Get Second UDP Port Number (eiger specific) + * @return second udp port number */ - void readFrame(char* c,char** raw, uint32_t &startAcquisitionIndex, uint32_t &startFrameIndex); + uint32_t getUDPPortNo2() const; /** - * Closes all files - * @param ithr thread index + * Get Ehernet Interface + * @ethernet interface. eg. eth0 or "" if listening to all (max of 1000 characters) */ - void closeFile(int ithr = -1); + char *getEthernetInterface() const; + + + //***acquisition parameters*** + /** + * Get Short Frame Enabled, later will be moved to getROI (so far only for gotthard) + * @return index of adc enabled, else -1 if all enabled + */ + int getShortFrameEnable() const; /** - * Starts Receiver - starts to listen for packets - * @param message is the error message if there is an error - * Returns success + * Get the Frequency of Frames Sent to GUI + * @return 0 for random frame requests, n for nth frame frequency */ - int startReceiver(char message[]); + uint32_t getFrameToGuiFrequency() const; /** - * Stops Receiver - stops listening for packets - * Returns success + * Get Acquisition Period + * @return acquisition period */ - int stopReceiver(); + uint64_t getAcquisitionPeriod() const; - /** set status to transmitting and - * when fifo is empty later, sets status to run_finished + /* + * Get Number of Frames expected by receiver from detector + * The data receiver status will change from running to idle when it gets this number of frames FIXME: (Not implemented) + * @return number of frames expected + */ + uint64_t getNumberOfFrames() const; + + /** + * Get Dynamic Range or Number of Bits Per Pixel + * @return dynamic range that is 4, 8, 16 or 32 + */ + uint32_t getDynamicRange() const; + + /** + * Get Ten Giga Enable + * @return true if 10Giga enabled, else false (1G enabled) + */ + bool getTenGigaEnable() const; + + //***receiver status*** + /** + * Get Listening Status of Receiver + * @return can be idle, listening or error depending on if the receiver is listening or not + */ + slsReceiverDefs::runStatus getStatus() const; + + + + + /************************************************************************* + * Setters *************************************************************** + * They modify the local cache of configuration or detector parameters *** + *************************************************************************/ + + //**initial parameters*** + /** + * Configure command line parameters + * @param config_map mapping of config parameters passed from command line arguments + */ + void configure(map config_map); + + /** + * Set Bottom Enable (eiger specific, should be moved to configure, and later from client via TCPIP) + * @param b is true for bottom enabled or false for bottom disabled + */ + void setBottomEnable(const bool b); + + + //***file parameters*** + /** + * Set File Name Prefix (without frame index, file index and extension (_d0_f000000000000_8.raw)) + * Does not check for file existence since it is created only at startReceiver + * @param c file name (max of 1000 characters) + */ + void setFileName(const char c[]); + + /** + * Set File Path + * Checks for file directory existence before setting file path, + * If it doesn't exist, it will set it blank + * @param c file path (max of 1000 characters) + */ + void setFilePath(const char c[]); + + /** + * Set File Index of acquisition + * @param i file index of acquisition + */ + void setFileIndex(const uint64_t i); + + /** + * Set Scan Tag + * @param i scan tag //FIXME: needed? (unsigned integer?) + */ + void setScanTag(const int i); + + /** + * Set Frame Index Enable (acquisition of more than 1 frame adds '_f000000000000' to file name ) + * @param b true for frame index enable, else false + */ + void setFrameIndexEnable(const bool b); + + /** + * Set File Write Enable + * @param b true for file write enable, else false + */ + void setFileWriteEnable(const bool b); + + /** + * Set File Overwrite Enable + * @param b true for file overwrite enable, else false + */ + void setOverwriteEnable(const bool b); + + /** + * Set data compression, by saving only hits (so far implemented only for Moench and Gotthard) + * @param b true for data compression enable, else false + */ + void setDataCompressionEnable(const bool b); + + + + //***connection parameters*** + /** + * Set UDP Port Number + * @param i udp port number + */ + void setUDPPortNo(const uint32_t i); + + /** + * Set Second UDP Port Number (eiger specific) + * @return second udp port number + */ + void setUDPPortNo2(const uint32_t i); + + /** + * Set Ethernet Interface to listen to + * @param c ethernet inerface eg. eth0 (max of 1000 characters) + */ + void setEthernetInterface(const char* c); + + + //***connection parameters*** + /** + * Set Short Frame Enabled, later will be moved to getROI (so far only for gotthard) + * @param i index of adc enabled, else -1 if all enabled + */ + void setShortFrameEnable(const int i); + + /** + * Set the Frequency of Frames Sent to GUI + * @param i 0 for random frame requests, n for nth frame frequency + */ + void setFrameToGuiFrequency(const uint32_t i); + + /** + * Set Acquisition Period + * @param i acquisition period + */ + void setAcquisitionPeriod(const uint64_t i); + + /** + * Set Number of Frames expected by receiver from detector + * The data receiver status will change from running to idle when it gets this number of frames FIXME: (Not implemented) + * @param i number of frames expected + */ + void setNumberOfFrames(const uint64_t i); + + /** + * Set Dynamic Range or Number of Bits Per Pixel + * @param i dynamic range that is 4, 8, 16 or 32 + */ + void setDynamicRange(const uint32_t i); + + /** + * Set Ten Giga Enable + * @param b true if 10Giga enabled, else false (1G enabled) + */ + void setTenGigaEnable(const bool b); + + + + /************************************************************************* + * Behavioral functions*************************************************** + * They may modify the status of the receiver **************************** + *************************************************************************/ + + //***initial functions*** + /** + * Set receiver type (and corresponding detector variables in derived STANDARD class) + * It is the first function called by the client when connecting to receiver + * @param d detector type + * @return OK or FAIL + */ + int setDetectorType(const slsReceiverDefs::detectorType d); + + /** + * Sets detector hostname (and corresponding detector variables in derived REST class) + * It is second function called by the client when connecting to receiver. + * you can call this function only once. //FIXME: is this still valid, this implemented in derived REST class? + * @param c detector hostname + */ + void initialize(const char *c); + + + //***acquisition functions*** + /** + * Reset acquisition parameters such as total frames caught for an entire acquisition (including all scans) + */ + void resetAcquisitionCount(); + + /** + * Start Listening for Packets by activating all configuration settings to receiver + * @param c error message if FAIL + * @return OK or FAIL + */ + int startReceiver(char *c=NULL); + + /** + * Stop Listening for Packets + * Calls startReadout(), which stops listening and sets status to Transmitting + * When it has read every frame in buffer,it returns with the status Run_Finished + */ + void stopReceiver(); + + /** + * Stop Listening to Packets + * and sets status to Transmitting */ void startReadout(); /** * shuts down the udp sockets - * \returns if success or fail + * \returns OK or FAIL */ int shutDownUDPSockets(); -protected: - - /* - void not_implemented(string method_name){ - std::cout << "[WARNING] Method " << method_name << " not implemented!" << std::endl; - }; - */ /** - * Deletes all the filter objects for single photon data + * Get the buffer-current frame read by receiver + * @param c pointer to current file name + * @param raw address of pointer, pointing to current frame to send to gui + * @param startAcquisitionIndex start index of the acquisition + * @param startFrameIndex start index of the scan */ - void deleteFilter(); + void readFrame(char* c,char** raw, uint64_t &startAcquisitionIndex, uint64_t &startFrameIndex); /** - * Constructs the filter for single photon data + * abort acquisition with minimum damage: close open files, cleanup. + * does nothing if state already is 'idle' */ - void setupFilter(); + void abort(); //FIXME: needed, isnt stopReceiver enough? /** - * set up fifo according to the new numjobsperthread + * Closes all files + * @param i thread index, -1 for all threads */ - void setupFifoStructure (); + void closeFile(int i = -1); - /** - * Copy frames to gui - * uses semaphore for nth frame mode - */ - void copyFrameToGui(char* startbuf[], char* buf=NULL); + //***callback functions*** /** - * creates udp sockets - * \returns if success or fail - */ - int createUDPSockets(); - - /** - * create listening thread - * @param destroy is true to kill all threads and start again - */ - int createListeningThreads(bool destroy = false); - - /** - * create writer threads - * @param destroy is true to kill all threads and start again - */ - int createWriterThreads(bool destroy = false); - - /** - * set thread priorities - */ - void setThreadPriorities(); - - /** - * initializes variables and creates the first file - * also does the startAcquisitionCallBack - * \returns FAIL or OK - */ - int setupWriter(); - - /** - * Creates new tree and file for compression - * @param ithr thread number - * @param iframe frame number - *\returns OK for succces or FAIL for failure - */ - int createCompressionFile(int ithr, int iframe); - - /** - * Creates new file - *\returns OK for succces or FAIL for failure - */ - int createNewFile(); - - /** - * Static function - Thread started which listens to packets. - * Called by startReceiver() - * @param this_pointer pointer to this object - */ - static void* startListeningThread(void *this_pointer); - - /** - * Static function - Thread started which writes packets to file. - * Called by startReceiver() - * @param this_pointer pointer to this object - */ - static void* startWritingThread(void *this_pointer); - - /** - * Thread started which listens to packets. - * Called by startReceiver() + * Call back for start acquisition + * callback arguments are + * filepath + * filename + * fileindex + * datasize * + * return value is the action which decides what the user and default responsibilities to save data are + * 0 callback takes care of open,close,wrie file + * 1 callback writes file, we have to open, close it + * 2 we open, close, write file, callback does not do anything */ - int startListening(); + void registerCallBackStartAcquisition(int (*func)(char*, char*,uint64_t, uint32_t, void*),void *arg); /** - * Thread started which writes packets to file. - * Called by startReceiver() - * + * Call back for acquisition finished + * callback argument is + * total frames caught */ - int startWriting(); + void registerCallBackAcquisitionFinished(void (*func)(uint64_t, void*),void *arg); /** - * Writing to file without compression - * @param buf is the address of buffer popped out of fifo - * @param numpackets is the number of packets - * @param framenum current frame number + * Call back for raw data + * args to raw data ready callback are + * framenum + * datapointer + * datasize in bytes + * file descriptor + * guidatapointer (NULL, no data required) */ - void writeToFile_withoutCompression(char* buf,int numpackets, uint32_t framenum); - - /** - * Its called for the first packet of a scan or acquistion - * Sets the startframeindices and the variables to know if acquisition started - * @param ithread listening thread number - */ - void startFrameIndices(int ithread); - - /** - * This is called when udp socket is shut down - * It pops ffff instead of packet number into fifo - * to inform writers about the end of listening session - * @param ithread listening thread number - * @param rc number of bytes received - * @param pc packet count - * @param t total packets listened to - */ - void stopListening(int ithread, int rc, int &pc, int &t); - - /** - * When acquisition is over, this is called - * @param ithread listening thread number - * @param wbuffer writer buffer - */ - void stopWriting(int ithread, char* wbuffer[]); - - - /** - * data compression for each fifo output - * @param ithread listening thread number - * @param wbuffer writer buffer - * @param data pointer to the next packet start - * @param xmax max pixels in x direction - * @param ymax max pixels in y direction - * @param nf nf - */ - void handleDataCompression(int ithread, char* wbuffer[], char* data, int xmax, int ymax, int &nf); + void registerCallBackRawDataReady(void (*func)(uint64_t, char*, uint32_t, FILE*, char*, void*),void *arg); + - //// Could be done more fine-grained... TODO - // private: protected: - /** structure of an eiger packet*/ - typedef struct - { + //**detector parameters*** + /** + * structure of an eiger packet header + * subframenum subframe number for 32 bit mode (already written by firmware) + * missingpacket explicitly put to 0xFF to recognize it in file read (written by software) + * portnum 0 for the first port and 1 for the second port (written by software to file) + * dynamicrange dynamic range or bits per pixel (written by software to file) + */ + typedef struct { unsigned char subframenum[4]; unsigned char missingpacket[2]; unsigned char portnum[1]; unsigned char dynamicrange[1]; } eiger_packet_header_t; - - typedef struct - { + /** + * structure of an eiger packet footer + * framenum 48 bit frame number (already written by firmware) + * packetnum packet number (already written by firmware) + */ + typedef struct { unsigned char framenum[6]; unsigned char packetnum[2]; } eiger_packet_footer_t; - /** max number of listening threads */ - const static int MAX_NUM_LISTENING_THREADS = EIGER_MAX_PORTS; - - /** max number of writer threads */ - const static int MAX_NUM_WRITER_THREADS = 15; - - /** missing packet identifier value */ - const static uint16_t missingPacketValue = 0xFFFF; - /** detector type */ detectorType myDetectorType; - /** detector hostname */ char detHostname[MAX_STR_LENGTH]; + /** Number of Packets per Frame*/ + uint64_t packetsPerFrame; + /** Acquisition Period */ + int64_t acquisitionPeriod; + /** Frame Number */ + int64_t numberOfFrames; + /** Dynamic Range */ + uint32_t dynamicRange; + /** Ten Giga Enable*/ + bool tengigaEnable; + /** Bottom Half Module Enable */ + bool bottomEnable; - /** status of receiver */ + //***receiver parameters*** + /** Maximum Number of Listening Threads/ UDP Ports */ + const static int MAX_NUM_LISTENING_THREADS = 2; + /** Receiver Status */ runStatus status; - /** UDP Socket between Receiver and Detector */ - genericSocket* udpSocket[MAX_NUM_LISTENING_THREADS]; + //***connection parameters*** + /** Ethernet Interface */ + char eth[MAX_STR_LENGTH]; + /** Server UDP Port Number*/ + uint32_t udpPortNum[MAX_NUM_LISTENING_THREADS]; - /** Server UDP Port*/ - int server_port[MAX_NUM_LISTENING_THREADS]; - - /** ethernet interface or IP to listen to */ - char *eth; - - /** max packets per file **/ - int maxPacketsPerFile; - - /** File write enable */ - int enableFileWrite; - - /** File over write enable */ - int overwrite; - - /** Complete File name */ - char savefilename[MAX_STR_LENGTH]; - - /** File Name without frame index, file index and extension*/ + //***file parameters*** + /** File Name without frame index, file index and extension (_d0_f000000000000_8.raw)*/ char fileName[MAX_STR_LENGTH]; - /** File Path */ char filePath[MAX_STR_LENGTH]; - /** File Index */ - int fileIndex; - - /** scan tag */ + uint64_t fileIndex; + /** Scan Tag */ int scanTag; + /** Frame Index Enable */ + bool frameIndexEnable; + /** File Write enable */ + bool fileWriteEnable; + /** Overwrite enable */ + bool overwriteEnable; + /** Data Compression Enable - save only hits */ + bool dataCompressionEnable; - /** if frame index required in file name */ - int frameIndexNeeded; - - /* Acquisition started */ - bool acqStarted; - - /* Measurement started */ - bool measurementStarted; - - /** Frame index at start of each real time acquisition (eg. for each scan) */ - uint32_t startFrameIndex; - - /** Actual current frame index of each time acquisition (eg. for each scan) */ - uint32_t frameIndex; - - /** Frames Caught for each real time acquisition (eg. for each scan) */ - uint32_t packetsCaught; - + //***acquisition count parameters*** /** Total packets caught for an entire acquisition (including all scans) */ - uint32_t totalPacketsCaught; - - /** Pckets currently in current file, starts new file when it reaches max */ - uint32_t packetsInFile; - - /** Number of missing packets in acquisition*/ - uint32_t numTotMissingPackets; - - /** Number of missing packets in file (sometimes packetsinFile is incorrect due to padded packets for eiger)*/ - uint32_t numTotMissingPacketsInFile; - - /** Number of missing packets per buffer*/ - uint32_t numMissingPackets; - - /** Frame index at start of an entire acquisition (including all scans) */ - uint32_t startAcquisitionIndex; + uint64_t totalPacketsCaught; + /** Frames Caught for each real time acquisition (eg. for each scan) */ + uint64_t packetsCaught; + //***acquisition indices parameters*** /** Actual current frame index of an entire acquisition (including all scans) */ - uint32_t acquisitionIndex; + uint64_t acquisitionIndex; - /** number of packets per frame*/ - int packetsPerFrame; - - /** frame index mask */ - uint32_t frameIndexMask; - - /** packet index mask */ - uint32_t packetIndexMask; - - /** frame index offset */ - int frameIndexOffset; - - /** acquisition period */ - int64_t acquisitionPeriod; - - /** frame number */ - int32_t numberOfFrames; - - /** dynamic range */ - int dynamicRange; - - /** short frames */ - int shortFrame; - - /** current frame number */ - uint32_t currframenum; - - /** Previous Frame number from buffer */ - int prevframenum; - - /** size of one frame */ - int frameSize; - - /** buffer size. different from framesize as we wait for one packet instead of frame for eiger */ - int bufferSize; - - /** one buffer size */ - int onePacketSize; - - /** one buffer size */ - int oneDataSize; - - /** latest data */ - char* latestData; - - /** gui data ready */ - int guiDataReady; - - /** points to the data to send to gui */ - char* guiData; - - /** points to the filename to send to gui */ - char* guiFileName; - - /** send every nth frame to gui or only upon gui request*/ - int nFrameToGui; - - /** fifo size */ - unsigned int fifosize; - - /** number of jobs per thread for data compression */ - int numJobsPerThread; - - /** datacompression - save only hits */ - bool dataCompression; - - /** memory allocated for the buffer */ - char *mem0[MAX_NUM_LISTENING_THREADS]; - - /** circular fifo to store addresses of data read */ - CircularFifo* fifo[MAX_NUM_LISTENING_THREADS]; - - /** circular fifo to store addresses of data already written and ready to be resued*/ - CircularFifo* fifoFree[MAX_NUM_LISTENING_THREADS]; - - /** Receiver buffer */ - char *buffer[MAX_NUM_LISTENING_THREADS]; - - /** number of writer threads */ - int numListeningThreads; - - /** number of writer threads */ - int numWriterThreads; - - /** to know if listening and writer threads created properly */ - int thread_started; - - /** current listening thread index*/ - int currentListeningThreadIndex; - - /** current writer thread index*/ - int currentWriterThreadIndex; - - /** thread listening to packets */ - pthread_t listening_thread[MAX_NUM_LISTENING_THREADS]; - - /** thread writing packets */ - pthread_t writing_thread[MAX_NUM_WRITER_THREADS]; - - /** total frame count the listening thread has listened to */ - int totalListeningFrameCount[MAX_NUM_LISTENING_THREADS]; - - /** mask showing which listening threads are running */ - volatile uint32_t listeningthreads_mask; - - /** mask showing which writer threads are running */ - volatile uint32_t writerthreads_mask; - - /** mask showing which threads have created files*/ - volatile uint32_t createfile_mask; - - /** OK if file created was successful */ - int ret_createfile; - - /** variable used to self terminate threads waiting for semaphores */ - int killAllListeningThreads; - - /** variable used to self terminate threads waiting for semaphores */ - int killAllWritingThreads; - - /** 10Gbe enable*/ - int tengigaEnable; - - /** footer offset is different for 1g and 10g*/ - int footer_offset; - - // TODO: not properly sure where to put these... - /** structure of an eiger image header*/ - - - - -//semaphores - /** semaphore to synchronize writer and guireader threads */ - sem_t smp; - /** semaphore to synchronize listener threads */ - sem_t listensmp[MAX_NUM_LISTENING_THREADS]; - /** semaphore to synchronize writer threads */ - sem_t writersmp[MAX_NUM_WRITER_THREADS]; - - -//mutex - /** guiDataReady mutex */ - pthread_mutex_t dataReadyMutex; - - /** mutex for status */ - pthread_mutex_t status_mutex; - - /** mutex for progress variable currframenum */ - pthread_mutex_t progress_mutex; - - /** mutex for writing data to file */ - pthread_mutex_t write_mutex; - - /** File Descriptor */ - FILE *sfilefd; - - //filter - singlePhotonDetector *singlePhotonDet[MAX_NUM_WRITER_THREADS]; - slsReceiverData *receiverdata[MAX_NUM_WRITER_THREADS]; - moenchCommonMode *cmSub; - bool commonModeSubtractionEnable; - -#ifdef MYROOT1 - /** Tree where the hits are stored */ - TTree *myTree[MAX_NUM_WRITER_THREADS]; - - /** File where the tree is saved */ - TFile *myFile[MAX_NUM_WRITER_THREADS]; -#endif + //***acquisition parameters*** + /* Short Frame Enable or index of adc enabled, else -1 if all enabled (gotthard specific) TODO: move to setROI */ + int shortFrameEnable; + /** Frequency of Frames sent to GUI */ + uint32_t FrameToGuiFrequency; + //***callback parameters*** /** - callback arguments are - filepath - filename - fileindex - data size - - return value is - 0 callback takes care of open,close,write file - 1 callback writes file, we have to open, close it - 2 we open, close, write file, callback does not do anything - - */ + * function being called back for start acquisition + * callback arguments are + * filepath + * filename + * fileindex + * datasize + * + * return value is + * 0 callback takes care of open,close,wrie file + * 1 callback writes file, we have to open, close it + * 2 we open, close, write file, callback does not do anything + */ int (*startAcquisitionCallBack)(char*, char*,int, int, void*); void *pStartAcquisition; /** - args to acquisition finished callback - total frames caught - - */ + * function being called back for acquisition finished + * callback argument is + * total frames caught + */ void (*acquisitionFinishedCallBack)(int, void*); void *pAcquisitionFinished; /** - args to raw data ready callback are - framenum - datapointer - datasize in bytes - file descriptor - guidatapointer (NULL, no data required) - */ + * function being called back for raw data + * args to raw data ready callback are + * framenum + * datapointer + * datasize in bytes + * file descriptor + * guidatapointer (NULL, no data required) + */ void (*rawDataReadyCallBack)(int, char*, int, FILE*, char*, void*); void *pRawDataReady; - /** The action which decides what the user and default responsibilites to save data are - * 0 raw data ready callback takes care of open,close,write file - * 1 callback writes file, we have to open, close it - * 2 we open, close, write file, callback does not do anything */ - int cbAction; - /** true if bottom half module for eiger */ - bool bottom; +private: -public: - - - /** - callback arguments are - filepath - filename - fileindex - datasize - - return value is - 0 callback takes care of open,close,wrie file - 1 callback writes file, we have to open, close it - 2 we open, close, write file, callback does not do anything - */ - void registerCallBackStartAcquisition(int (*func)(char*, char*,int, int, void*),void *arg){startAcquisitionCallBack=func; pStartAcquisition=arg;}; - - /** - callback argument is - toatal frames caught - */ - void registerCallBackAcquisitionFinished(void (*func)(int, void*),void *arg){acquisitionFinishedCallBack=func; pAcquisitionFinished=arg;}; - - /** - args to raw data ready callback are - framenum - datapointer - datasize in bytes - file descriptor - guidatapointer (NULL, no data required) - */ - void registerCallBackRawDataReady(void (*func)(int, char*, int, FILE*, char*, void*),void *arg){rawDataReadyCallBack=func; pRawDataReady=arg;}; }; diff --git a/slsReceiverSoftware/include/UDPInterface.h b/slsReceiverSoftware/include/UDPInterface.h index c1d30ec0b..2e89b59be 100644 --- a/slsReceiverSoftware/include/UDPInterface.h +++ b/slsReceiverSoftware/include/UDPInterface.h @@ -26,375 +26,471 @@ class UDPInterface { - /* abstract class that defines the UDP interface of an sls detector data receiver. + /* abstract class that defines the UDP interface of an sls detector data receiver. * - * Use the factory method UDPInterface::create() to get an instance: + * Use the factory method UDPInterface::create() to get an instance: + * + * UDPInterface *udp_interface = UDPInterface::create() * - * UDPInterface *udp_interface = UDPInterface::create() * * supported sequence of method-calls: * - * initialize() : once and only once after create() + * initialize() : once and only once after create() //FIXME: only once functionality implemented in the derived REST class, so not mention here? + * + * get*() : anytime after initialize(), multiples times * - * get*() : anytime after initialize(), multiples times * set*() : anytime after initialize(), multiple times * - * startReceiver(): anytime after initialize(). Will fail if state already is 'running' - * - * abort(), - * stopReceiver() : anytime after initialize(). Will do nothing if state already is idle. - * - * getStatus() returns the actual state of the data receiver - running or idle. All other - * get*() and set*() methods access the local cache of configuration values only and *do not* modify the data receiver settings. + * startReceiver(): anytime after initialize(). Will fail if state already is 'running': * * Only startReceiver() does change the data receiver configuration, it does pass the whole configuration cache to the data receiver. * - * get- and set-methods that return a char array (char *) allocate a new array at each call. The caller is responsible to free the allocated space: + * abort(), //FIXME: needed? + * + * stopReceiver() : anytime after initialize(). Will do nothing if state already is idle. + * + * getStatus() returns the actual state of the data receiver - idle, running or error, enum defined in include/sls_receiver_defs.h + * + * + * + * get*() and set*() methods access the local cache of configuration values only and *do not* modify the data receiver settings. + * + * set methods return nothing, use get methods to validate a set method success + * + * get-methods that return a char array (char *) allocate a new array at each call. The caller is responsible to free the allocated space: * * char *c = receiver->getFileName(); - * .... + * Or + * FIXME: so that the pointers are not shared external to the class, do the following way in the calling method? + * char *c = new char[MAX_STR_LENGTH]; + * strcpy(c,receiver->getFileName()); + * .... + * * delete[] c; * - * always: 1:YES 0:NO for int as bool-like arguments + * All pointers passed in externally will be allocated and freed by the calling function + * + * OK and FAIL are defined in include/sls_receiver_defs.h for functions implementing behavior * */ public: + /************************************************************************* + * Constructor & Destructor ********************************************** + * They access local cache of configuration or detector parameters ******* + *************************************************************************/ + /** + * Constructor + * Only non virtual function implemented in this class + * Factory create method to create a standard or REST object + * @param [in] receiver_type type can be standard or REST + * @return a UDPInterface reference to object depending on receiver type + */ + static UDPInterface *create(string receiver_type = "standard"); + /** * Destructor */ virtual ~UDPInterface() {}; - /** - * Factory create method + + + /************************************************************************* + * Getters *************************************************************** + * They access local cache of configuration or detector parameters ******* + *************************************************************************/ + + //**initial parameters*** + /* + * Get detector hostname + * @return hostname or NULL if uninitialized, must be released by calling function (max of 1000 characters) */ - static UDPInterface *create(string receiver_type = "standard"); + virtual char *getDetectorHostname() const = 0; - virtual void configure(map config_map) = 0; - - public: - + //***file parameters*** /** - * Initialize the Receiver - @param detectorHostName detector hostname - * you can call this function only once. You must call it before you call startReceiver() for the first time. - */ - virtual void initialize(const char *detectorHostName) = 0; - - - /* Returns detector hostname - /returns hostname - * caller needs to deallocate the returned char array. - * if uninitialized, it must return NULL - */ - virtual char *getDetectorHostname() const = 0; - - /** - * Returns status of receiver: idle, running or error - */ - virtual slsReceiverDefs::runStatus getStatus() const = 0; - - /** - * Returns File Name - * caller is responsible to deallocate the returned char array. + * Get File Name Prefix (without frame index, file index and extension (_d0_f000000000000_8.raw)) + * @return NULL or pointer to file name prefix, must be released by calling function (max of 1000 characters) */ virtual char *getFileName() const = 0; - /** - * Returns File Path - * caller is responsible to deallocate the returned char array + * Get File Path + * @return NULL or pointer to file path, must be released by calling function (max of 1000 characters) */ - virtual char *getFilePath() const = 0; //FIXME: Does the caller need to free() the returned pointer? - + virtual char *getFilePath() const = 0; /** - * Returns the number of bits per pixel + * Get File Index + * @return NULL or file index of acquisition */ - virtual int getDynamicRange() const = 0; + virtual uint64_t getFileIndex() const = 0; /** - * Returns scan tag + * Get Scan Tag + * @return scan tag //FIXME: needed? (unsigned integer?) */ virtual int getScanTag() const = 0; + /** + * Get if Frame Index is enabled (acquisition of more than 1 frame adds '_f000000000000' to file name ) + * @return true if frame index needed, else false + */ + virtual bool getFrameIndexEnable() const = 0; + + /** + * Get File Write Enable + * @return true if file write enabled, else false + */ + virtual bool getFileWriteEnable() const = 0; + + /** + * Get File Over Write Enable + * @return true if file over write enabled, else false + */ + virtual bool getOverwriteEnable() const = 0; + + /** + * Get data compression, by saving only hits (so far implemented only for Moench and Gotthard) + * @return true if data compression enabled, else false + */ + virtual bool getDataCompressionEnable() const = 0; + + + //***acquisition count parameters*** + /** + * Get Total Frames Caught for an entire acquisition (including all scans) + * @return total number of frames caught for entire acquisition + */ + virtual uint64_t getTotalFramesCaught() const = 0; + + /** + * Get Frames Caught for each real time acquisition (eg. for each scan) + * @return number of frames caught for each scan + */ + virtual uint64_t getFramesCaught() const = 0; + + /** + * Get Current Frame Index Caught for an entire acquisition (including all scans) + * @return current frame index (represents all scans too) or -1 if no packets caught + */ + virtual int64_t getAcquisitionIndex() const = 0; + + + //***connection parameters*** + /** + * Get UDP Port Number + * @return udp port number + */ + virtual uint32_t getUDPPortNo() const = 0; + + /** + * Get Second UDP Port Number (eiger specific) + * @return second udp port number + */ + virtual uint32_t getUDPPortNo2() const = 0; + + /** + * Get Ehernet Interface + * @return ethernet interface. eg. eth0 (max of 1000 characters) + */ + virtual char *getEthernetInterface() const = 0; + + + //***acquisition parameters*** + /** + * Get Short Frame Enabled, later will be moved to getROI (so far only for gotthard) + * @return index of adc enabled, else -1 if all enabled + */ + virtual int getShortFrameEnable() const = 0; + + /** + * Get the Frequency of Frames Sent to GUI + * @return 0 for random frame requests, n for nth frame frequency + */ + virtual uint32_t getFrameToGuiFrequency() const = 0; + + /** + * Get Acquisition Period + * @return acquisition period + */ + virtual uint64_t getAcquisitionPeriod() const = 0; + /* - * Returns number of frames to receive - * This is the number of frames to expect to receiver from the detector. - * The data receiver will change from running to idle when it got this number of frames + * Get Number of Frames expected by receiver from detector + * The data receiver status will change from running to idle when it gets this number of frames FIXME: (Not implemented) + * @return number of frames expected */ - virtual int getNumberOfFrames() const = 0; + virtual uint64_t getNumberOfFrames() const = 0; /** - * Returns file write enable - * 1: YES 0: NO - */ - virtual int getEnableFileWrite() const = 0; - - /** - * Returns file over write enable - * 1: YES 0: NO - */ - virtual int getEnableOverwrite() const = 0; - - /** - * Set File Name (without frame index, file index and extension) - @param c file name - /returns file name - * returns NULL on failure (like bad file name) - * does not check the existence of the file - we don't know which path we'll finally use, so no point to check. - * caller is responsible to deallocate the returned char array. + * Get Dynamic Range or Number of Bits Per Pixel + * @return dynamic range that is 4, 8, 16 or 32 */ - virtual char* setFileName(const char c[]) = 0; + virtual uint32_t getDynamicRange() const = 0; + + /** + * Get Ten Giga Enable + * @return true if 10Giga enabled, else false (1G enabled) + */ + virtual bool getTenGigaEnable() const = 0; + + //***receiver status*** + /** + * Get Listening Status of Receiver + * @return can be idle, listening or error depending on if the receiver is listening or not + */ + virtual slsReceiverDefs::runStatus getStatus() const = 0; + + + + + /************************************************************************* + * Setters *************************************************************** + * They modify the local cache of configuration or detector parameters *** + *************************************************************************/ + + //**initial parameters*** + /** + * Configure command line parameters + * @param config_map mapping of config parameters passed from command line arguments + */ + virtual void configure(map config_map) = 0; + + /** + * Set Bottom Enable (eiger specific, should be moved to configure, and later from client via TCPIP) + * @param b is true for bottom enabled or false for bottom disabled + */ + virtual void setBottomEnable(const bool b)= 0; + + + //***file parameters*** + /** + * Set File Name Prefix (without frame index, file index and extension (_d0_f000000000000_8.raw)) + * Does not check for file existence since it is created only at startReceiver + * @param c file name (max of 1000 characters) + */ + virtual void setFileName(const char c[]) = 0; /** * Set File Path - @param c file path - /returns file path - * checks the existence of the directory. returns NULL if directory does not exist or is not readable. - * caller is responsible to deallocate the returned char array. + * Checks for file directory existence before setting file path + * @param c file path (max of 1000 characters) */ - virtual char* setFilePath(const char c[]) = 0; + virtual void setFilePath(const char c[]) = 0; /** - * Returns the number of bits per pixel - @param dr sets dynamic range - /returns dynamic range - * returns -1 on failure - * FIXME: what are the allowd values - should we use an enum as argument? + * Set File Index of acquisition + * @param i file index of acquisition */ - virtual int setDynamicRange(const int dr) = 0; - + virtual void setFileIndex(const uint64_t i) = 0; /** - * Set scan tag - @param tag scan tag - /returns scan tag (always non-negative) - * FIXME: valid range - only positive? 16bit ore 32bit? - * returns -1 on failure + * Set Scan Tag + * @param i scan tag //FIXME: needed? (unsigned integer?) */ - virtual int setScanTag(const int tag) = 0; + virtual void setScanTag(const int i) = 0; /** - * Sets number of frames - @param fnum number of frames - /returns number of frames + * Set Frame Index Enable (acquisition of more than 1 frame adds '_f000000000000' to file name ) + * @param b true for frame index enable, else false */ - virtual int setNumberOfFrames(const int fnum) = 0; + virtual void setFrameIndexEnable(const bool b) = 0; /** - * Set enable file write - * @param i file write enable - /returns file write enable + * Set File Write Enable + * @param b true for file write enable, else false */ - virtual int setEnableFileWrite(const int i) = 0; + virtual void setFileWriteEnable(const bool b) = 0; /** - * Set enable file overwrite - * @param i file overwrite enable - /returns file overwrite enable + * Set File Overwrite Enable + * @param b true for file overwrite enable, else false */ - virtual int setEnableOverwrite(const int i) = 0; + virtual void setOverwriteEnable(const bool b) = 0; /** - * Starts Receiver - activate all configuration settings to the eiger receiver and start to listen for packets - @param message is the error message if there is an error - /returns 0 on success or -1 on failure + * Set data compression, by saving only hits (so far implemented only for Moench and Gotthard) + * @param b true for data compression enable, else false */ - //FIXME: success == 0 or success == 1? - virtual int startReceiver(char *message=NULL) = 0; //FIXME: who allocates message[]? - - /** - * Stops Receiver - stops listening for packets - /returns success - * same as abort(). Always returns 0. - */ - virtual int stopReceiver() = 0; - - /** - * abort acquisition with minimum damage: close open files, cleanup. - * does nothing if state already is 'idle' - */ - virtual void abort() = 0; + virtual void setDataCompressionEnable(const bool b) = 0; - -/******************************************************************************************************************* - **************************************** Added by Dhanya ********************************************************* - *******************************************************************************************************************/ - - /** - * Set bottom to bot - * @param bot = 1 if bottom - */ - virtual void setBottom(int bot)= 0; - - /** - * Returns File Index - */ - virtual int getFileIndex() = 0; - - /** - * Returns Total Frames Caught for an entire acquisition (including all scans) - */ - virtual int getTotalFramesCaught() = 0; - - /** - * Returns Frames Caught for each real time acquisition (eg. for each scan) - */ - virtual int getFramesCaught() = 0; - - /** - * Returns the frame index at start of entire acquisition (including all scans) - */ - virtual uint32_t getStartAcquisitionIndex()=0; - - /** - * Returns current Frame Index Caught for an entire acquisition (including all scans) - */ - virtual uint32_t getAcquisitionIndex() = 0; - - /** - * Returns the frame index at start of each real time acquisition (eg. for each scan) - */ - virtual uint32_t getStartFrameIndex() = 0; - - /** get data compression, by saving only hits - */ - virtual bool getDataCompression() = 0; - - /** - * Set receiver type - * @param det detector type - * Returns success or FAIL - */ - virtual int setDetectorType(slsReceiverDefs::detectorType det) = 0; - - /** - * Set File Index - * @param i file index - */ - virtual int setFileIndex(int i) = 0; - - /** set acquisition period if a positive number - */ - virtual int64_t setAcquisitionPeriod(int64_t index) = 0; - - /** - * Set Frame Index Needed - * @param i frame index needed - */ - virtual int setFrameIndexNeeded(int i) = 0; - + //***connection parameters*** /** * Set UDP Port Number + * @param i udp port number */ - virtual void setUDPPortNo(int p) = 0; + virtual void setUDPPortNo(const uint32_t i) = 0; /** - * Set UDP Port Number + * Set Second UDP Port Number (eiger specific) + * @return second udp port number */ - virtual void setUDPPortNo2(int p) = 0; + virtual void setUDPPortNo2(const uint32_t i) = 0; /** - * Set Ethernet Interface or IP to listen to + * Set Ethernet Interface to listen to + * @param c ethernet inerface eg. eth0 (max of 1000 characters) */ - virtual void setEthernetInterface(char* c) = 0; + virtual void setEthernetInterface(const char* c) = 0; + + + //***connection parameters*** + /** + * Set Short Frame Enabled, later will be moved to getROI (so far only for gotthard) + * @param i index of adc enabled, else -1 if all enabled + */ + virtual void setShortFrameEnable(const int i) = 0; /** - * Set short frame - * @param i if shortframe i=1 + * Set the Frequency of Frames Sent to GUI + * @param i 0 for random frame requests, n for nth frame frequency */ - virtual int setShortFrame(int i) = 0; + virtual void setFrameToGuiFrequency(const uint32_t i) = 0; /** - * Set the variable to send every nth frame to gui - * or if 0,send frame only upon gui request + * Set Acquisition Period + * @param i acquisition period */ - virtual int setNFrameToGui(int i) = 0; + virtual void setAcquisitionPeriod(const uint64_t i) = 0; /** - * Resets the Total Frames Caught - * This is how the receiver differentiates between entire acquisitions - * Returns 0 + * Set Number of Frames expected by receiver from detector + * The data receiver status will change from running to idle when it gets this number of frames FIXME: (Not implemented) + * @param i number of frames expected */ - virtual void resetTotalFramesCaught() = 0; - - /** enabl data compression, by saving only hits - /returns if failed - */ - virtual int enableDataCompression(bool enable) = 0; + virtual void setNumberOfFrames(const uint64_t i) = 0; /** - * enable 10Gbe - @param enable 1 for 10Gbe or 0 for 1 Gbe, -1 to read out - \returns enable for 10Gbe + * Set Dynamic Range or Number of Bits Per Pixel + * @param i dynamic range that is 4, 8, 16 or 32 */ - virtual int enableTenGiga(int enable = -1) = 0; + virtual void setDynamicRange(const uint32_t i) = 0; /** - * Returns the buffer-current frame read by receiver - * @param c pointer to current file name - * @param raw address of pointer, pointing to current frame to send to gui - * @param startAcquisitionIndex is the start index of the acquisition - * @param startFrameIndex is the start index of the scan + * Set Ten Giga Enable + * @param b true if 10Giga enabled, else false (1G enabled) */ - virtual void readFrame(char* c,char** raw, uint32_t &startAcquisitionIndex, uint32_t &startFrameIndex)=0; + virtual void setTenGigaEnable(const bool b) = 0; - /** set status to transmitting and - * when fifo is empty later, sets status to run_finished + + + /************************************************************************* + * Behavioral functions*************************************************** + * They may modify the status of the receiver **************************** + *************************************************************************/ + + //***initial functions*** + /** + * Set receiver type (and corresponding detector variables in derived STANDARD class) + * It is the first function called by the client when connecting to receiver + * @param d detector type + * @return OK or FAIL + */ + virtual int setDetectorType(const slsReceiverDefs::detectorType d) = 0; + + /** + * Sets detector hostname (and corresponding detector variables in derived REST class) + * It is second function called by the client when connecting to receiver. + * you can call this function only once. //FIXME: is this still valid, this implemented in derived REST class? + * @param c detector hostname + */ + virtual void initialize(const char *c) = 0; + + + //***acquisition functions*** + /** + * Reset acquisition parameters such as total frames caught for an entire acquisition (including all scans) + */ + void resetAcquisitionCount(); + + /** + * Start Listening for Packets by activating all configuration settings to receiver + * @param c error message if FAIL + * @return OK or FAIL + */ + virtual int startReceiver(char *c=NULL) = 0; + + /** + * Stop Listening for Packets + * Calls startReadout(), which stops listening and sets status to Transmitting + * When it has read every frame in buffer,it returns with the status Run_Finished + */ + virtual void stopReceiver() = 0; + + /** + * Stop Listening to Packets + * and sets status to Transmitting */ virtual void startReadout() = 0; /** * shuts down the udp sockets - * \returns if success or fail + * \returns OK or FAIL */ virtual int shutDownUDPSockets() = 0; /** - * Closes all files - * @param ithr thread index, -1 for all threads + * Get the buffer-current frame read by receiver + * @param c pointer to current file name + * @param raw address of pointer, pointing to current frame to send to gui + * @param startAcquisitionIndex start index of the acquisition + * @param startFrameIndex start index of the scan */ - virtual void closeFile(int ithr = -1) = 0; + virtual void readFrame(char* c,char** raw, uint64_t &startAcquisitionIndex, uint64_t &startFrameIndex)=0; /** - * Call back for start acquisition - callback arguments are - filepath - filename - fileindex - datasize + * abort acquisition with minimum damage: close open files, cleanup. + * does nothing if state already is 'idle' + */ + virtual void abort() = 0; //FIXME: needed, isnt stopReceiver enough? - return value is - 0 callback takes care of open,close,wrie file - 1 callback writes file, we have to open, close it - 2 we open, close, write file, callback does not do anything - */ - virtual void registerCallBackStartAcquisition(int (*func)(char*, char*,int, int, void*),void *arg) = 0; + /** + * Closes all files + * @param i thread index, -1 for all threads + */ + virtual void closeFile(int i = -1) = 0; + + + //***callback functions*** + /** + * Call back for start acquisition + * callback arguments are + * filepath + * filename + * fileindex + * datasize + * + * return value is + * 0 callback takes care of open,close,wrie file + * 1 callback writes file, we have to open, close it + * 2 we open, close, write file, callback does not do anything + */ + virtual void registerCallBackStartAcquisition(int (*func)(char*, char*,uint64_t, uint32_t, void*),void *arg) = 0; /** * Call back for acquisition finished - callback argument is - total frames caught - */ - virtual void registerCallBackAcquisitionFinished(void (*func)(int, void*),void *arg) = 0; + * callback argument is + * total frames caught + */ + virtual void registerCallBackAcquisitionFinished(void (*func)(uint64_t, void*),void *arg) = 0; /** * Call back for raw data - args to raw data ready callback are - framenum - datapointer - datasize in bytes - file descriptor - guidatapointer (NULL, no data required) - */ - virtual void registerCallBackRawDataReady(void (*func)(int, char*, int, FILE*, char*, void*),void *arg) = 0; - + * args to raw data ready callback are + * framenum + * datapointer + * datasize in bytes + * file descriptor + * guidatapointer (NULL, no data required) + */ + virtual void registerCallBackRawDataReady(void (*func)(uint64_t, char*, uint32_t, FILE*, char*, void*),void *arg) = 0; + + protected: - private: }; diff --git a/slsReceiverSoftware/include/UDPStandardImplementation.h b/slsReceiverSoftware/include/UDPStandardImplementation.h index 2916ee6b9..04bd7000e 100644 --- a/slsReceiverSoftware/include/UDPStandardImplementation.h +++ b/slsReceiverSoftware/include/UDPStandardImplementation.h @@ -24,6 +24,7 @@ #endif + #include #include #include @@ -199,7 +200,7 @@ class UDPStandardImplementation: private virtual slsReceiverDefs, public UDPBase * Set detector hostname * @param c hostname */ - void initialize(const char *detectorHostName); + void setDetectorHostname(const char *detectorHostName); /* Returns detector hostname /returns hostname @@ -484,6 +485,224 @@ private: void handleDataCompression(int ithread, char* wbuffer[], char* data, int xmax, int ymax, int &nf); + + + + + + + + + + + + + + + + + + + + + + + /** max number of writer threads */ + const static int MAX_NUM_WRITER_THREADS = 15; + + /** missing packet identifier value */ + const static uint16_t missingPacketValue = 0xFFFF; + + + /** UDP Socket between Receiver and Detector */ + genericSocket* udpSocket[MAX_NUM_LISTENING_THREADS]; + + /** max packets per file **/ + int maxPacketsPerFile; + + /** Frame Index at start of an entire acquisition (including all scans) */ + uint64_t startAcquisitionIndex; + /** Complete File name */ + char savefilename[MAX_STR_LENGTH]; + + /* Measurement started */ + bool measurementStarted; + /* Acquisition started */ + bool acqStarted; + /** Frame index at start of each real time acquisition (eg. for each scan) */ + uint32_t startFrameIndex; + + /** Actual current frame index of each time acquisition (eg. for each scan) */ + uint32_t frameIndex; + + /** Pckets currently in current file, starts new file when it reaches max */ + uint32_t packetsInFile; + + /** Number of missing packets in acquisition*/ + uint32_t numTotMissingPackets; + + /** Number of missing packets in file (sometimes packetsinFile is incorrect due to padded packets for eiger)*/ + uint32_t numTotMissingPacketsInFile; + + /** Number of missing packets per buffer*/ + uint32_t numMissingPackets; + + /** frame index mask */ + uint32_t frameIndexMask; + + /** packet index mask */ + uint32_t packetIndexMask; + + /** frame index offset */ + int frameIndexOffset; + /** Current Frame Number */ + uint64_t currframenum; + + /** Previous Frame number from buffer */ + int prevframenum; + + /** size of one frame */ + int frameSize; + + /** buffer size. different from framesize as we wait for one packet instead of frame for eiger */ + int bufferSize; + + /** one buffer size */ + int onePacketSize; + + /** one buffer size */ + int oneDataSize; + + /** latest data */ + char* latestData; + + /** gui data ready */ + int guiDataReady; + + /** points to the data to send to gui */ + char* guiData; + + /** points to the filename to send to gui */ + char* guiFileName; + + /** fifo size */ + unsigned int fifosize; + + /** number of jobs per thread for data compression */ + int numJobsPerThread; + + /** memory allocated for the buffer */ + char *mem0[MAX_NUM_LISTENING_THREADS]; + + /** circular fifo to store addresses of data read */ + CircularFifo* fifo[MAX_NUM_LISTENING_THREADS]; + + /** circular fifo to store addresses of data already written and ready to be resued*/ + CircularFifo* fifoFree[MAX_NUM_LISTENING_THREADS]; + + /** Receiver buffer */ + char *buffer[MAX_NUM_LISTENING_THREADS]; + + /** number of writer threads */ + int numListeningThreads; + + /** number of writer threads */ + int numWriterThreads; + + /** to know if listening and writer threads created properly */ + int thread_started; + + /** current listening thread index*/ + int currentListeningThreadIndex; + + /** current writer thread index*/ + int currentWriterThreadIndex; + + /** thread listening to packets */ + pthread_t listening_thread[MAX_NUM_LISTENING_THREADS]; + + /** thread writing packets */ + pthread_t writing_thread[MAX_NUM_WRITER_THREADS]; + + /** total frame count the listening thread has listened to */ + int totalListeningFrameCount[MAX_NUM_LISTENING_THREADS]; + + /** mask showing which listening threads are running */ + volatile uint32_t listeningthreads_mask; + + /** mask showing which writer threads are running */ + volatile uint32_t writerthreads_mask; + + /** mask showing which threads have created files*/ + volatile uint32_t createfile_mask; + + /** OK if file created was successful */ + int ret_createfile; + + /** variable used to self terminate threads waiting for semaphores */ + int killAllListeningThreads; + + /** variable used to self terminate threads waiting for semaphores */ + int killAllWritingThreads; + + + + /** footer offset is different for 1g and 10g*/ + int footer_offset; + + // TODO: not properly sure where to put these... + /** structure of an eiger image header*/ + + + + +//semaphores + /** semaphore to synchronize writer and guireader threads */ + sem_t smp; + /** semaphore to synchronize listener threads */ + sem_t listensmp[MAX_NUM_LISTENING_THREADS]; + /** semaphore to synchronize writer threads */ + sem_t writersmp[MAX_NUM_WRITER_THREADS]; + + +//mutex + /** guiDataReady mutex */ + pthread_mutex_t dataReadyMutex; + + /** mutex for status */ + pthread_mutex_t status_mutex; + + /** mutex for progress variable currframenum */ + pthread_mutex_t progress_mutex; + + /** mutex for writing data to file */ + pthread_mutex_t write_mutex; + + /** File Descriptor */ + FILE *sfilefd; + + //filter + singlePhotonDetector *singlePhotonDet[MAX_NUM_WRITER_THREADS]; + slsReceiverData *receiverdata[MAX_NUM_WRITER_THREADS]; + moenchCommonMode *cmSub; + bool commonModeSubtractionEnable; + +#ifdef MYROOT1 + /** Tree where the hits are stored */ + TTree *myTree[MAX_NUM_WRITER_THREADS]; + + /** File where the tree is saved */ + TFile *myFile[MAX_NUM_WRITER_THREADS]; +#endif + + + /** The action which decides what the user and default responsibilites to save data are + * 0 raw data ready callback takes care of open,close,write file + * 1 callback writes file, we have to open, close it + * 2 we open, close, write file, callback does not do anything */ + int cbAction; + + public: diff --git a/slsReceiverSoftware/src/UDPBaseImplementation.cpp b/slsReceiverSoftware/src/UDPBaseImplementation.cpp index 682c52980..e16060865 100644 --- a/slsReceiverSoftware/src/UDPBaseImplementation.cpp +++ b/slsReceiverSoftware/src/UDPBaseImplementation.cpp @@ -1,4 +1,4 @@ -#ifdef SLS_RECEIVER_UDP_FUNCTIONS +//#ifdef SLS_RECEIVER_UDP_FUNCTIONS /********************************************//** * @file UDPBaseImplementation.cpp * @short does all the functions for a receiver, set/get parameters, start/stop etc. @@ -23,178 +23,204 @@ #include #include -//#include "utilities.h" - using namespace std; +/************************************************************************* + * Constructor & Destructor ********************************************** + * They access local cache of configuration or detector parameters ******* + *************************************************************************/ UDPBaseImplementation::UDPBaseImplementation(){ -} + //**detector parameters*** + strcpy(detHostname,""); + packetsPerFrame = 0; + acquisitionPeriod = 0; + numberOfFrames = 0; + dynamicRange = 16; + tengigaEnable = false; + bottomEnable = false; + //***receiver parameters*** + status = IDLE; -UDPBaseImplementation::~UDPBaseImplementation(){} + //***connection parameters*** + strcpy(eth,""); + for(int i=0;i config_map){ - FILE_LOG(logWARNING) << __AT__ << "doing nothing..."; + //***acquisition count parameters*** + totalPacketsCaught = 0; + packetsCaught = 0; + + //***acquisition indices parameters*** + acquisitionIndex = 0; + + //***acquisition parameters*** + shortFrameEnable = -1; + FrameToGuiFrequency = 0; + + //***callback parameters*** + startAcquisitionCallBack = NULL; + pStartAcquisition = NULL; + acquisitionFinishedCallBack = NULL; + pAcquisitionFinished = NULL; + rawDataReadyCallBack = NULL; + pRawDataReady = NULL; }; +UDPBaseImplementation::~UDPBaseImplementation(){}; -void UDPBaseImplementation::deleteMembers(){ - FILE_LOG(logWARNING) << "[WARNING] This is a base implementation, " << __func__ << " could have no effects."; + +/************************************************************************* + * Getters *************************************************************** + * They access local cache of configuration or detector parameters ******* + *************************************************************************/ + +/**initial parameters***/ +char *UDPBaseImplementation::getDetectorHostname() const{ + FILE_LOG(logDEBUG) << __AT__ << " starting"; + + //not initialized + if(!strlen(detHostname)) + return NULL; + + char* output = new char[MAX_STR_LENGTH]; + strcpy(output,detHostname); + //freed by calling function + return output; } -void UDPBaseImplementation::initializeMembers(){ - FILE_LOG(logWARNING) << "[WARNING] This is a base implementation, " << __func__ << " could have no effects."; +/***file parameters***/ +char *UDPBaseImplementation::getFileName() const{ + FILE_LOG(logDEBUG) << __AT__ << " starting"; + + //not initialized + if(!strlen(fileName)) + return NULL; + + char* output = new char[MAX_STR_LENGTH]; + strcpy(output,fileName); + //freed by calling function + return output; } +char *UDPBaseImplementation::getFilePath() const{ + FILE_LOG(logDEBUG) << __AT__ << " starting"; -int UDPBaseImplementation::setDetectorType(detectorType det){ - cout << "[WARNING] This is a base implementation, " << __func__ << " not correctly implemented" << endl; - cout << "Setting Receiver Type " << endl; + //not initialized + if(!strlen(filePath)) + return NULL; - deleteMembers(); - initializeMembers(); - - myDetectorType = det; - - switch(myDetectorType){ - case GOTTHARD: - cout << endl << "***** This is a GOTTHARD Receiver *****" << endl << endl; - break; - case MOENCH: - cout << endl << "***** This is a MOENCH Receiver *****" << endl << endl; - break; - case EIGER: - cout << endl << "***** This is a EIGER Receiver *****" << endl << endl; - break; - default: - cout << endl << "***** Unknown Receiver *****" << endl << endl; - return FAIL; - break; - } - /* - //moench variables - if(myDetectorType == GOTTHARD){ - fifosize = GOTTHARD_FIFO_SIZE; - packetsPerFrame = GOTTHARD_PACKETS_PER_FRAME; - onePacketSize = GOTTHARD_ONE_PACKET_SIZE; - frameSize = GOTTHARD_BUFFER_SIZE; - bufferSize = GOTTHARD_BUFFER_SIZE; - maxPacketsPerFile = MAX_FRAMES_PER_FILE * GOTTHARD_PACKETS_PER_FRAME; - frameIndexMask = GOTTHARD_FRAME_INDEX_MASK; - frameIndexOffset = GOTTHARD_FRAME_INDEX_OFFSET; - packetIndexMask = GOTTHARD_PACKET_INDEX_MASK; - }else if(myDetectorType == MOENCH){ - fifosize = MOENCH_FIFO_SIZE; - packetsPerFrame = MOENCH_PACKETS_PER_FRAME; - onePacketSize = MOENCH_ONE_PACKET_SIZE; - frameSize = MOENCH_BUFFER_SIZE; - bufferSize = MOENCH_BUFFER_SIZE; - maxPacketsPerFile = MOENCH_MAX_FRAMES_PER_FILE * MOENCH_PACKETS_PER_FRAME; - frameIndexMask = MOENCH_FRAME_INDEX_MASK; - frameIndexOffset = MOENCH_FRAME_INDEX_OFFSET; - packetIndexMask = MOENCH_PACKET_INDEX_MASK; - } - else if(myDetectorType == EIGER){ - fifosize = EIGER_FIFO_SIZE; - packetsPerFrame = EIGER_ONE_GIGA_CONSTANT * dynamicRange * EIGER_MAX_PORTS; - onePacketSize = EIGER_ONE_GIGA_ONE_PACKET_SIZE; - frameSize = onePacketSize * packetsPerFrame; - bufferSize = (frameSize/EIGER_MAX_PORTS) + EIGER_HEADER_LENGTH;//everything one port gets (img header plus packets) - maxPacketsPerFile = EIGER_MAX_FRAMES_PER_FILE * packetsPerFrame; - frameIndexMask = EIGER_FRAME_INDEX_MASK; - frameIndexOffset = EIGER_FRAME_INDEX_OFFSET; - packetIndexMask = EIGER_PACKET_INDEX_MASK; - - pthread_mutex_lock(&status_mutex); - listeningthreads_mask = 0x0; - pthread_mutex_unlock(&(status_mutex)); - if(thread_started) - createListeningThreads(true); - - numListeningThreads = MAX_NUM_LISTENING_THREADS; - } - latestData = new char[frameSize]; - - - setupFifoStructure(); - - if(createListeningThreads() == FAIL){ - cout << "ERROR: Could not create listening thread" << endl; - exit (-1); - } - - if(createWriterThreads() == FAIL){ - cout << "ERROR: Could not create writer threads" << endl; - exit (-1); - } - - setThreadPriorities(); - - cout << "Ready..." << endl; - - return OK; - */ - return OK; + char* output = new char[MAX_STR_LENGTH]; + strcpy(output,filePath); + //freed by calling function + return output; } +uint32_t UDPBaseImplementation::getFileIndex() const{ FILE_LOG(logDEBUG) << __AT__ << " starting"; return fileIndex;} +int UDPBaseImplementation::getScanTag() const{ FILE_LOG(logDEBUG) << __AT__ << " starting"; return scanTag;} -void UDPBaseImplementation::setBottom(int bot){bottom=bot;}; +bool UDPBaseImplementation::getFrameIndexEnable() const{ FILE_LOG(logDEBUG) << __AT__ << " starting"; return frameIndexEnable;} -/*Frame indices and numbers caught*/ +bool UDPBaseImplementation::getFileWriteEnable() const{ FILE_LOG(logDEBUG) << __AT__ << " starting"; return fileWriteEnable;} -bool UDPBaseImplementation::getAcquistionStarted(){ FILE_LOG(logDEBUG) << __AT__ << " starting";return acqStarted;}; +bool UDPBaseImplementation::getOverwriteEnable() const{ FILE_LOG(logDEBUG) << __AT__ << " starting"; return overwriteEnable;} -bool UDPBaseImplementation::getMeasurementStarted(){ FILE_LOG(logDEBUG) << __AT__ << " starting";return measurementStarted;}; +bool UDPBaseImplementation::getDataCompressionEnable() const{ FILE_LOG(logDEBUG) << __AT__ << " starting"; return dataCompressionEnable;} -int UDPBaseImplementation::getFramesCaught(){ FILE_LOG(logDEBUG) << __AT__ << " starting";return (packetsCaught/packetsPerFrame);} +/***acquisition count parameters***/ +uint64_t UDPBaseImplementation::getTotalFramesCaught() const{ FILE_LOG(logDEBUG) << __AT__ << " starting"; return (totalPacketsCaught/packetsPerFrame);} -int UDPBaseImplementation::getTotalFramesCaught(){ FILE_LOG(logDEBUG) << __AT__ << " starting";return (totalPacketsCaught/packetsPerFrame);} +uint64_t UDPBaseImplementation::getFramesCaught() const{ FILE_LOG(logDEBUG) << __AT__ << " starting"; return (packetsCaught/packetsPerFrame);} -uint32_t UDPBaseImplementation::getStartAcquisitionIndex(){ FILE_LOG(logDEBUG) << __AT__ << " starting";return startAcquisitionIndex;} +int64_t UDPBaseImplementation::getAcquisitionIndex() const{ + FILE_LOG(logDEBUG) << __AT__ << " starting"; -uint32_t UDPBaseImplementation::getStartFrameIndex(){ FILE_LOG(logDEBUG) << __AT__ << " starting";return startFrameIndex;} - -uint32_t UDPBaseImplementation::getFrameIndex(){ FILE_LOG(logDEBUG) << __AT__ << " starting"; - if(!packetsCaught) - frameIndex=-1; - else - frameIndex = currframenum - startFrameIndex; - return frameIndex; -} - - -uint32_t UDPBaseImplementation::getAcquisitionIndex(){ FILE_LOG(logDEBUG) << __AT__ << " starting"; if(!totalPacketsCaught) - acquisitionIndex=-1; - else - acquisitionIndex = currframenum - startAcquisitionIndex; - //cout<<"acquisitionIndex:"< config_map){ + FILE_LOG(logWARNING) << __AT__ << " doing nothing..."; + FILE_LOG(logERROR) << __AT__ << " must be overridden by child classes"; } -inline char* UDPBaseImplementation::setFilePath(const char c[]){ FILE_LOG(logDEBUG) << __AT__ << " starting"; - FILE_LOG(logDEBUG) << __AT__ << "called"; +void UDPBaseImplementation::setBottomEnable(const bool b){ + FILE_LOG(logDEBUG) << __AT__ << " starting"; + + bottomEnable = b; + FILE_LOG(logINFO) << "Bottom Enable:" << bottomEnable; +} + + +/***file parameters***/ +void UDPBaseImplementation::setFileName(const char c[]){ + FILE_LOG(logDEBUG) << __AT__ << " starting"; + + if(strlen(c)) + strcpy(fileName, c); + FILE_LOG(logINFO) << "File name:" << fileName; +} + +void UDPBaseImplementation::setFilePath(const char c[]){ + FILE_LOG(logDEBUG) << __AT__ << " starting"; + if(strlen(c)){ //check if filepath exists struct stat st; @@ -204,1484 +230,209 @@ inline char* UDPBaseImplementation::setFilePath(const char c[]){ FILE_LOG(logDEB strcpy(filePath,""); FILE_LOG(logWARNING) << "FilePath does not exist:" << filePath; } + strcpy(filePath, c); } - FILE_LOG(logDEBUG) << __AT__ << getFilePath(); -#ifdef VERBOSE - cout << getFilePath() << " " << filePath << endl; -#endif - return getFilePath(); + FILE_LOG(logINFO) << "File path:" << filePath; +} + +void UDPBaseImplementation::setFileIndex(const uint32_t i){ + FILE_LOG(logDEBUG) << __AT__ << " starting"; + + fileIndex = i; + FILE_LOG(logINFO) << "File Index:" << fileIndex; +} + +//FIXME: needed? +void UDPBaseImplementation::setScanTag(const int i){ + FILE_LOG(logDEBUG) << __AT__ << " starting"; + + scanTag = i; + FILE_LOG(logINFO) << "Scan Tag:" << scanTag; + +} + +void UDPBaseImplementation::setFrameIndexEnable(const bool b){ + FILE_LOG(logDEBUG) << __AT__ << " starting"; + + frameIndexEnable = b; + FILE_LOG(logINFO) << "Frame Index Enable:" << frameIndexEnable; +} + +void UDPBaseImplementation::setFileWriteEnable(const bool b){ + FILE_LOG(logDEBUG) << __AT__ << " starting"; + + fileWriteEnable = b; + FILE_LOG(logINFO) << "File Write Enable:" << fileWriteEnable; +} + +void UDPBaseImplementation::setOverwriteEnable(const bool b){ + FILE_LOG(logDEBUG) << __AT__ << " starting"; + + overwriteEnable = b; + FILE_LOG(logINFO) << "Overwrite Enable:" << overwriteEnable; +} + +void UDPBaseImplementation::setDataCompressionEnable(const bool b){ + FILE_LOG(logDEBUG) << __AT__ << " starting"; + + dataCompressionEnable = b; + FILE_LOG(logINFO) << "Data Compression Enable:" << dataCompressionEnable; } -char* UDPBaseImplementation::getFileName() const{ - FILE_LOG(logDEBUG) << __FILE__ << "::" << __func__ << " starting"; - return (char*)fileName; +/***connection parameters***/ +void UDPBaseImplementation::setUDPPortNo(const uint32_t i){ + FILE_LOG(logDEBUG) << __AT__ << " starting"; + + udpPortNum[0] = i; + FILE_LOG(logINFO) << "udpPortNum[0]:" << udpPortNum[0]; } -inline char* UDPBaseImplementation::setFileName(const char c[]){ FILE_LOG(logDEBUG) << __AT__ << " starting"; - //cout << "[WARNING] This is a base implementation, " << __func__ << " could have no effects." << endl; - +void UDPBaseImplementation::setUDPPortNo2(const uint32_t i){ + FILE_LOG(logDEBUG) << __AT__ << " starting"; + + udpPortNum[1] = i; + FILE_LOG(logINFO) << "udpPortNum[1]:" << udpPortNum[1]; +} + +void UDPBaseImplementation::setEthernetInterface(const char* c){ + FILE_LOG(logDEBUG) << __AT__ << " starting"; + + strcpy(eth, c); + FILE_LOG(logINFO) << "Ethernet Interface:" << eth; +} + + +/***connection parameters***/ +void UDPBaseImplementation::setShortFrameEnable(const int i){ + FILE_LOG(logDEBUG) << __AT__ << " starting"; + + shortFrameEnable = i; + FILE_LOG(logINFO) << "Short Frame Enable:" << shortFrameEnable; +} + +void UDPBaseImplementation::setFrameToGuiFrequency(const uint32_t i){ + FILE_LOG(logDEBUG) << __AT__ << " starting"; + + FrameToGuiFrequency = i; + FILE_LOG(logINFO) << "Frame To Gui Frequency:" << FrameToGuiFrequency; +} + +void UDPBaseImplementation::setAcquisitionPeriod(const uint64_t i){ + FILE_LOG(logDEBUG) << __AT__ << " starting"; + + acquisitionPeriod = i; + FILE_LOG(logINFO) << "Acquisition Period:" << acquisitionPeriod; +} + +void UDPBaseImplementation::setNumberOfFrames(const uint64_t i){ + FILE_LOG(logDEBUG) << __AT__ << " starting"; + + numberOfFrames = i; + FILE_LOG(logINFO) << "Number of Frames:" << numberOfFrames; +} + +void UDPBaseImplementation::setDynamicRange(const uint32_t i){ + FILE_LOG(logDEBUG) << __AT__ << " starting"; + + dynamicRange = i; + FILE_LOG(logINFO) << "Dynamic Range:" << dynamicRange; +} + +void UDPBaseImplementation::setTenGigaEnable(const bool b){ + FILE_LOG(logDEBUG) << __AT__ << " starting"; + + tengigaEnable = b; + FILE_LOG(logINFO) << "Ten Giga Enable:" << tengigaEnable; +} + + + +/************************************************************************* + * Behavioral functions*************************************************** + * They may modify the status of the receiver **************************** + *************************************************************************/ + +/***initial functions***/ +int UDPBaseImplementation::setDetectorType(const slsReceiverDefs::detectorType d){ + FILE_LOG(logDEBUG) << __AT__ << " starting"; + + myDetectorType = d; + FILE_LOG(logINFO) << "Detector Type:" << slsDetectorBase::getDetectorType(d); + return OK; +} + +void UDPBaseImplementation::initialize(const char *c){ + FILE_LOG(logDEBUG) << __AT__ << " starting"; + if(strlen(c)) - strcpy(fileName,c); - - return getFileName(); + strcpy(detHostname, c); + FILE_LOG(logINFO) << "Detector Hostname:" << detHostname; } -int UDPBaseImplementation::getFileIndex(){ FILE_LOG(logDEBUG) << __AT__ << " starting"; - return fileIndex; +/***acquisition functions***/ +void UDPBaseImplementation::resetAcquisitionCount(){ + FILE_LOG(logDEBUG) << __AT__ << " starting"; + + totalPacketsCaught = 0; + FILE_LOG(logINFO) << "totalPacketsCaught:" << totalPacketsCaught << endl; } -int UDPBaseImplementation::setFileIndex(int i){ FILE_LOG(logDEBUG) << __AT__ << " starting"; - //cout << "[WARNING] This is a base implementation, " << __func__ << " could have no effects." << endl; - if(i>=0) - fileIndex = i; - return getFileIndex(); -} - - -int UDPBaseImplementation::setFrameIndexNeeded(int i){ FILE_LOG(logDEBUG) << __AT__ << " starting"; - //cout << "[WARNING] This is a base implementation, " << __func__ << " could have no effects." << endl; - frameIndexNeeded = i; - return frameIndexNeeded; -} - - -int UDPBaseImplementation::getEnableFileWrite() const{ - FILE_LOG(logDEBUG) << __FILE__ << "::" << __func__ << " starting"; - -return enableFileWrite; -} - -int UDPBaseImplementation::setEnableFileWrite(int i){ FILE_LOG(logDEBUG) << __AT__ << " starting"; - enableFileWrite=i; - return getEnableFileWrite(); -} - -int UDPBaseImplementation::getEnableOverwrite() const{ - FILE_LOG(logDEBUG) << __FILE__ << "::" << __func__ << " starting"; - - return overwrite; -} - -int UDPBaseImplementation::setEnableOverwrite(int i){ FILE_LOG(logDEBUG) << __AT__ << " starting"; - overwrite=i; - return getEnableOverwrite(); -} - - - - - -/*other parameters*/ - -slsReceiverDefs::runStatus UDPBaseImplementation::getStatus() const{ - return status; -} - - -void UDPBaseImplementation::initialize(const char *detectorHostName){ FILE_LOG(logDEBUG) << __AT__ << " starting"; - if(strlen(detectorHostName)) - strcpy(detHostname,detectorHostName); -} - - -char *UDPBaseImplementation::getDetectorHostname() const{ - return (char*)detHostname; -} - -void UDPBaseImplementation::setEthernetInterface(char* c){ FILE_LOG(logDEBUG) << __AT__ << " starting"; - strcpy(eth,c); -} - - -void UDPBaseImplementation::setUDPPortNo(int p){ - server_port[0] = p; -} - - -void UDPBaseImplementation::setUDPPortNo2(int p){ - server_port[1] = p; -} - - -int UDPBaseImplementation::getNumberOfFrames() const { - return numberOfFrames; -} - - -int32_t UDPBaseImplementation::setNumberOfFrames(int32_t fnum){ FILE_LOG(logDEBUG) << __AT__ << " starting"; - if(fnum >= 0) - numberOfFrames = fnum; - - return getNumberOfFrames(); -} - - -int UDPBaseImplementation::getScanTag() const{ - return scanTag; -} - - -int32_t UDPBaseImplementation::setScanTag(int32_t stag){ FILE_LOG(logDEBUG) << __AT__ << " starting"; - if(stag >= 0) - scanTag = stag; - - return getScanTag(); -} - - -int UDPBaseImplementation::getDynamicRange() const{ - return dynamicRange; -} - -int32_t UDPBaseImplementation::setDynamicRange(int32_t dr){ FILE_LOG(logDEBUG) << __AT__ << " starting"; - cout << "Setting Dynamic Range" << endl; - - int olddr = dynamicRange; - if(dr >= 0){ - dynamicRange = dr; - - if(myDetectorType == EIGER){ - - - if(!tengigaEnable) - packetsPerFrame = EIGER_ONE_GIGA_CONSTANT * dynamicRange * EIGER_MAX_PORTS; - else - packetsPerFrame = EIGER_TEN_GIGA_CONSTANT * dynamicRange * EIGER_MAX_PORTS; - frameSize = onePacketSize * packetsPerFrame; - bufferSize = (frameSize/EIGER_MAX_PORTS) + EIGER_HEADER_LENGTH;//everything one port gets (img header plus packets) - maxPacketsPerFile = EIGER_MAX_FRAMES_PER_FILE * packetsPerFrame; - - - - if(olddr != dr){ - - //del - if(thread_started){ - createListeningThreads(true); - createWriterThreads(true); - } - for(int i=0;i=0){ - nFrameToGui = i; - setupFifoStructure(); - } - return nFrameToGui; -} - - - -int64_t UDPBaseImplementation::setAcquisitionPeriod(int64_t index){ FILE_LOG(logDEBUG) << __AT__ << " starting"; - - if(index >= 0){ - if(index != acquisitionPeriod){ - acquisitionPeriod = index; - setupFifoStructure(); - } - } - return acquisitionPeriod; -} - - -bool UDPBaseImplementation::getDataCompression(){ FILE_LOG(logDEBUG) << __AT__ << " starting";return dataCompression;} - -int UDPBaseImplementation::enableDataCompression(bool enable){ FILE_LOG(logDEBUG) << __AT__ << " starting"; - cout << "Data compression "; - if(enable) - cout << "enabled" << endl; - else - cout << "disabled" << endl; -#ifdef MYROOT1 - cout << " WITH ROOT" << endl; -#else - cout << " WITHOUT ROOT" << endl; -#endif - //delete filter for the current number of threads - deleteFilter(); - - dataCompression = enable; - pthread_mutex_lock(&status_mutex); - writerthreads_mask = 0x0; - pthread_mutex_unlock(&(status_mutex)); - - createWriterThreads(true); - - if(enable) - numWriterThreads = MAX_NUM_WRITER_THREADS; - else - numWriterThreads = 1; - - if(createWriterThreads() == FAIL){ - cprintf(BG_RED,"ERROR: Could not create writer threads\n"); - return FAIL; - } - setThreadPriorities(); - - - if(enable) - setupFilter(); - +int UDPBaseImplementation::startReceiver(char *c=NULL){ + FILE_LOG(logWARNING) << __AT__ << " doing nothing..."; + FILE_LOG(logERROR) << __AT__ << " must be overridden by child classes"; return OK; } +void UDPBaseImplementation::stopReceiver(){ + FILE_LOG(logWARNING) << __AT__ << " doing nothing..."; + FILE_LOG(logERROR) << __AT__ << " must be overridden by child classes"; +} +void UDPBaseImplementation::startReadout(){ + FILE_LOG(logWARNING) << __AT__ << " doing nothing..."; + FILE_LOG(logERROR) << __AT__ << " must be overridden by child classes"; +} +int UDPBaseImplementation::shutDownUDPSockets(){ + FILE_LOG(logWARNING) << __AT__ << " doing nothing..."; + FILE_LOG(logERROR) << __AT__ << " must be overridden by child classes"; +} +void UDPBaseImplementation::readFrame(char* c,char** raw, uint64_t &startAcquisitionIndex, uint64_t &startFrameIndex){ + FILE_LOG(logWARNING) << __AT__ << " doing nothing..."; + FILE_LOG(logERROR) << __AT__ << " must be overridden by child classes"; +} +//FIXME: needed, isnt stopReceiver enough? +void UDPBaseImplementation::abort(){ + FILE_LOG(logWARNING) << __AT__ << " doing nothing..."; + FILE_LOG(logERROR) << __AT__ << " must be overridden by child classes"; +} - - - - - - -/*other functions*/ - - -void UDPBaseImplementation::deleteFilter(){ FILE_LOG(logDEBUG) << __AT__ << " starting"; - int i; - cmSub=NULL; - - for(i=0;i(receiverdata[i], csize, sigma, sign, cmSub); +void UDPBaseImplementation::registerCallBackAcquisitionFinished(void (*func)(int, void*),void *arg){ + acquisitionFinishedCallBack=func; + pAcquisitionFinished=arg; +} +void UDPBaseImplementation::registerCallBackRawDataReady(void (*func)(int, char*, int, FILE*, char*, void*),void *arg){ + rawDataReadyCallBack=func; + pRawDataReady=arg; } - -//LEO: it is not clear to me.. -void UDPBaseImplementation::setupFifoStructure(){ FILE_LOG(logDEBUG) << __AT__ << " starting"; - -} - - - - - - - -/** acquisition functions */ -void UDPBaseImplementation::readFrame(char* c,char** raw,uint32_t &startAcquisitionIndex, uint32_t &startFrameIndex){ - FILE_LOG(logDEBUG) << __AT__ << " called"; - //point to gui data - if (guiData == NULL){ - guiData = latestData; - } - - //copy data and filename - strcpy(c,guiFileName); - startAcquisitionIndex = getStartAcquisitionIndex(); - startFrameIndex = getStartFrameIndex(); - - - //could not get gui data - if(!guiDataReady){ - *raw = NULL; - } - //data ready, set guidata to receive new data - else{ - *raw = guiData; - guiData = NULL; - if((nFrameToGui) && (writerthreads_mask)){ - //release after getting data - sem_post(&smp); - } - } -} - - - - - - -void UDPBaseImplementation::copyFrameToGui(char* startbuf[], char* buf){ FILE_LOG(logDEBUG) << __AT__ << " starting"; - -} - - - - - -int UDPBaseImplementation::createUDPSockets(){ FILE_LOG(logDEBUG) << __AT__ << " starting"; - - //if eth is mistaken with ip address - if (strchr(eth,'.')!=NULL) - strcpy(eth,""); - - shutDownUDPSockets(); - - //if no eth, listen to all - if(!strlen(eth)){ - cout<<"warning:eth is empty.listening to all"<getErrorStatus(); - if(iret){ -#ifdef VERBOSE - cprintf(BG_RED,"Could not create UDP socket on port %d error: %d\n",server_port[i], iret); -#endif - return FAIL; - } - } - - return OK; -} - - - - - - - -int UDPBaseImplementation::shutDownUDPSockets(){ FILE_LOG(logDEBUG) << __AT__ << " starting"; - for(int i=0;iShutDownSocket(); - delete udpSocket[i]; - udpSocket[i] = NULL; - } - } - return OK; -} - - - - - -int UDPBaseImplementation::createListeningThreads(bool destroy){ FILE_LOG(logDEBUG) << __AT__ << " starting"; - int i; - void* status; - - killAllListeningThreads = 0; - - pthread_mutex_lock(&status_mutex); - listeningthreads_mask = 0x0; - pthread_mutex_unlock(&(status_mutex)); - - if(!destroy){ - - //start listening threads - cout << "Creating Listening Threads(s)"; - - currentListeningThreadIndex = -1; - - for(i = 0; i < numListeningThreads; ++i){ - sem_init(&listensmp[i],1,0); - thread_started = 0; - currentListeningThreadIndex = i; - if(pthread_create(&listening_thread[i], NULL,startListeningThread, (void*) this)){ - cout << "Could not create listening thread with index " << i << endl; - return FAIL; - } - while(!thread_started); - cout << "."; - cout << flush; - } -#ifdef VERBOSE - cout << "Listening thread(s) created successfully." << endl; -#else - cout << endl; -#endif - }else{ - cout<<"Destroying Listening Thread(s)"<initEventTree(temp, &iframe); - //resets the pedestalSubtraction array and the commonModeSubtraction - singlePhotonDet[ithr]->newDataSet(); - if(myFile[ithr]==NULL){ - cout<<"file null"<IsOpen()){ - cout<<"file not open"< DO_NOTHING){ - //close - if(sfilefd){ - fclose(sfilefd); - sfilefd = NULL; - } - //open file - if(!overwrite){ - if (NULL == (sfilefd = fopen((const char *) (savefilename), "wx"))){ - cout << "Error: Could not create new file " << savefilename << endl; - return FAIL; - } - }else if (NULL == (sfilefd = fopen((const char *) (savefilename), "w"))){ - cout << "Error: Could not creat dsdasdserwe file " << savefilename << endl; - return FAIL; - } - //setting buffer - setvbuf(sfilefd,NULL,_IOFBF,BUF_SIZE); - - //printing packet losses and file names - if(!packetsCaught) - cout << savefilename << endl; - else{ - cout << savefilename - << "\tpacket loss " - << setw(4)<GetCurrentFile(); - - if(myFile[ithr]->Write()) - //->Write(tall->GetName(),TObject::kOverwrite); - cout << "Thread " << ithr <<": wrote frames to file" << endl; - else - cout << "Thread " << ithr << ": could not write frames to file" << endl; - - }else - cout << "Thread " << ithr << ": could not write frames to file: No file or No Tree" << endl; - //close file - if(myTree[ithr] && myFile[ithr]) - myFile[ithr] = myTree[ithr]->GetCurrentFile(); - if(myFile[ithr] != NULL) - myFile[ithr]->Close(); - myFile[ithr] = NULL; - myTree[ithr] = NULL; - pthread_mutex_unlock(&write_mutex); - -#endif - } - */ - FILE_LOG(logDEBUG) << __AT__ << "exited"; - -} - - - - - -int UDPBaseImplementation::startReceiver(char message[]){ FILE_LOG(logDEBUG) << __AT__ << " starting"; - int i; - - -// #ifdef VERBOSE - cout << "Starting Receiver" << endl; //#endif - - - //reset listening thread variables - measurementStarted = false; - //should be set to zero as its added to get next start frame indices for scans for eiger - if(!acqStarted) currframenum = 0; - startFrameIndex = 0; - - for(int i = 0; i < numListeningThreads; ++i) - totalListeningFrameCount[i] = 0; - - //udp socket - if(createUDPSockets() == FAIL){ - strcpy(message,"Could not create UDP Socket(s).\n"); - cout << endl << message << endl; - return FAIL; - } - cout << "UDP socket(s) created successfully. 1st port " << server_port[0] << endl; - - - if(setupWriter() == FAIL){ - //stop udp socket - shutDownUDPSockets(); - - sprintf(message,"Could not create file %s.\n",savefilename); - return FAIL; - } - cout << "Successfully created file(s)" << endl; - - //done to give the gui some proper name instead of always the last file name - if(dataCompression) - sprintf(savefilename, "%s/%s_fxxx_%d_xx.root", filePath,fileName,fileIndex); - - //initialize semaphore - sem_init(&smp,1,0); - - //status - pthread_mutex_lock(&status_mutex); - status = RUNNING; - for(i=0;istartListening(); - - return this_pointer; -} - - - -void* UDPBaseImplementation::startWritingThread(void* this_pointer){ FILE_LOG(logDEBUG) << __AT__ << " starting"; - ((UDPBaseImplementation*)this_pointer)->startWriting(); - return this_pointer; -} - - - - - - -int UDPBaseImplementation::startListening(){ FILE_LOG(logDEBUG) << __AT__ << " starting"; - int ithread = currentListeningThreadIndex; -#ifdef VERYVERBOSE - cout << "In startListening() " << endl; -#endif - - thread_started = 1; - - int total; - int lastpacketoffset, expected, rc,packetcount, maxBufferSize, carryonBufferSize; - uint32_t lastframeheader;// for moench to check for all the packets in last frame - char* tempchar = NULL; - int imageheader = 0; - if(myDetectorType==EIGER) - imageheader = EIGER_IMAGE_HEADER_SIZE; - - - while(1){ - //variables that need to be checked/set before each acquisition - carryonBufferSize = 0; - //if more than 1 listening thread, listen one packet at a time, else need to interleaved frame later - maxBufferSize = bufferSize * numJobsPerThread; -#ifdef VERYDEBUG - cout << " maxBufferSize:" << maxBufferSize << ",carryonBufferSize:" << carryonBufferSize << endl; -#endif - - if(tempchar) {delete [] tempchar;tempchar = NULL;} - if(myDetectorType != EIGER) - tempchar = new char[onePacketSize * ((packetsPerFrame/numListeningThreads) - 1)]; //gotthard: 1packet size, moench:39 packet size - - - while((1<pop(buffer[ithread]); -#ifdef VERYDEBUG - cout << ithread << " *** popped from fifo free" << (void*)buffer[ithread] << endl; -#endif - - - //receive - if(udpSocket[ithread] == NULL){ - rc = 0; - cout << ithread << "UDP Socket is NULL" << endl; - } - //normal listening - else if(!carryonBufferSize){ - - rc = udpSocket[ithread]->ReceiveDataOnly(buffer[ithread] + HEADER_SIZE_NUM_TOT_PACKETS, maxBufferSize); - expected = maxBufferSize; - - } - //the remaining packets from previous buffer - else{ -#ifdef VERYDEBUG - cout << ithread << " ***carry on buffer" << carryonBufferSize << endl; - cout << ithread << " framennum in temochar:"<<((((uint32_t)(*((uint32_t*)tempchar))) - & (frameIndexMask)) >> frameIndexOffset)<ReceiveDataOnly((buffer[ithread] + HEADER_SIZE_NUM_TOT_PACKETS + carryonBufferSize),maxBufferSize - carryonBufferSize); - expected = maxBufferSize - carryonBufferSize; - } - -#ifdef VERYDEBUG - cout << ithread << " *** rc:" << dec << rc << ". expected:" << dec << expected << endl; -#endif - - - - - //start indices for each start of scan/acquisition - eiger does it before - if((!measurementStarted) && (rc > 0) && (!ithread)) - startFrameIndices(ithread); - - //problem in receiving or end of acquisition - if((rc < expected)||(rc <= 0)){ - stopListening(ithread,rc,packetcount,total); - continue; - } - - - - //reset - packetcount = (packetsPerFrame/numListeningThreads) * numJobsPerThread; - carryonBufferSize = 0; - - - - //check if last packet valid and calculate packet count - switch(myDetectorType){ - - case MOENCH: - lastpacketoffset = (((numJobsPerThread * packetsPerFrame - 1) * onePacketSize) + HEADER_SIZE_NUM_TOT_PACKETS); -#ifdef VERYDEBUG - cout <<"first packet:"<< ((((uint32_t)(*((uint32_t*)(buffer[ithread]+HEADER_SIZE_NUM_TOT_PACKETS))))) & (packetIndexMask)) << endl; - cout <<"first header:"<< (((((uint32_t)(*((uint32_t*)(buffer[ithread]+HEADER_SIZE_NUM_TOT_PACKETS))))) & (frameIndexMask)) >> frameIndexOffset) << endl; - cout << "last packet offset:" << lastpacketoffset << endl; - cout <<"last packet:"<< ((((uint32_t)(*((uint32_t*)(buffer[ithread]+lastpacketoffset))))) & (packetIndexMask)) << endl; - cout <<"last header:"<< (((((uint32_t)(*((uint32_t*)(buffer[ithread]+lastpacketoffset))))) & (frameIndexMask)) >> frameIndexOffset) << endl; -#endif - //moench last packet value is 0 - if( ((((uint32_t)(*((uint32_t*)(buffer[ithread]+lastpacketoffset))))) & (packetIndexMask))){ - lastframeheader = ((((uint32_t)(*((uint32_t*)(buffer[ithread]+lastpacketoffset))))) & (frameIndexMask)) >> frameIndexOffset; - carryonBufferSize += onePacketSize; - lastpacketoffset -= onePacketSize; - --packetcount; - while (lastframeheader == (((((uint32_t)(*((uint32_t*)(buffer[ithread]+lastpacketoffset))))) & (frameIndexMask)) >> frameIndexOffset)){ - carryonBufferSize += onePacketSize; - lastpacketoffset -= onePacketSize; - --packetcount; - } - memcpy(tempchar, buffer[ithread]+(lastpacketoffset+onePacketSize), carryonBufferSize); -#ifdef VERYDEBUG - cout << "tempchar header:" << (((((uint32_t)(*((uint32_t*)(tempchar))))) - & (frameIndexMask)) >> frameIndexOffset) << endl; - cout <<"tempchar packet:"<< ((((uint32_t)(*((uint32_t*)(tempchar))))) - & (packetIndexMask)) << endl; -#endif - } - break; - - case GOTTHARD: - if(shortFrame == -1){ - lastpacketoffset = (((numJobsPerThread * packetsPerFrame - 1) * onePacketSize) + HEADER_SIZE_NUM_TOT_PACKETS); -#ifdef VERYDEBUG - cout << "last packet offset:" << lastpacketoffset << endl; -#endif - - if((unsigned int)(packetsPerFrame -1) != ((((uint32_t)(*((uint32_t*)(buffer[ithread]+lastpacketoffset))))+1) & (packetIndexMask))){ - memcpy(tempchar,buffer[ithread]+lastpacketoffset, onePacketSize); -#ifdef VERYDEBUG - cout << "tempchar header:" << (((((uint32_t)(*((uint32_t*)(tempchar))))+1) - & (frameIndexMask)) >> frameIndexOffset) << endl; -#endif - carryonBufferSize = onePacketSize; - --packetcount; - } - } -#ifdef VERYDEBUG - cout << "header:" << (((((uint32_t)(*((uint32_t*)(buffer[ithread] + HEADER_SIZE_NUM_TOT_PACKETS))))+1) - & (frameIndexMask)) >> frameIndexOffset) << endl; -#endif - break; - default: - - break; - - } - - - // cout<<"*********** "<fnum)<push(buffer[ithread])); -#ifdef VERYDEBUG - if(!ithread) cout << ithread << " *** pushed into listening fifo" << endl; -#endif - } - - sem_wait(&listensmp[ithread]); - - //make sure its not exiting thread - if(killAllListeningThreads){ - cout << ithread << " good bye listening thread" << endl; - if(tempchar) {delete [] tempchar;tempchar = NULL;} - pthread_exit(NULL); - } - } - - return OK; -} - - - - - - - - - - - - - -int UDPBaseImplementation::startWriting(){ FILE_LOG(logDEBUG) << __AT__ << " starting"; - - return OK; -} - - - - -void UDPBaseImplementation::startFrameIndices(int ithread){ FILE_LOG(logDEBUG) << __AT__ << " starting"; - - - -} - - - -void UDPBaseImplementation::stopListening(int ithread, int rc, int &pc, int &t){ FILE_LOG(logDEBUG) << __AT__ << " starting"; -int i; - -#ifdef VERYVERBOSE - cerr << ithread << " recvfrom() failed:"<push(buffer[ithread]); - exit(-1); - } - //push the last buffer into fifo - if(rc > 0){ - pc = (rc/onePacketSize); -#ifdef VERYDEBUG - cout << ithread << " *** last packetcount:" << pc << endl; -#endif - (*((uint16_t*)(buffer[ithread]))) = pc; - totalListeningFrameCount[ithread] += pc; - while(!fifo[ithread]->push(buffer[ithread])); -#ifdef VERYDEBUG - cout << ithread << " *** last lbuf1:" << (void*)buffer[ithread] << endl; -#endif - } - - - //push dummy buffer to all writer threads - for(i=0;ipop(buffer[ithread]); - (*((uint16_t*)(buffer[ithread]))) = 0xFFFF; -#ifdef VERYDEBUG - cout << ithread << " going to push in dummy buffer:" << (void*)buffer[ithread] << " with num packets:"<< (*((uint16_t*)(buffer[ithread]))) << endl; -#endif - while(!fifo[ithread]->push(buffer[ithread])); -#ifdef VERYDEBUG - cout << ithread << " pushed in dummy buffer:" << (void*)buffer[ithread] << endl; -#endif - } - - //reset mask and exit loop - pthread_mutex_lock(&status_mutex); - listeningthreads_mask^=(1< 1) - cout << "Waiting for listening to be done.. current mask:" << hex << listeningthreads_mask << endl; -#endif - while(listeningthreads_mask) - usleep(5000); -#ifdef VERYDEBUG - t = 0; - for(i=0;ipush(wbuffer[i])); -#ifdef VERYDEBUG - cout << ithread << ":" << i<< " fifo freed:" << (void*)wbuffer[i] << endl; -#endif - } - - - - //all threads need to close file, reset mask and exit loop - closeFile(ithread); - pthread_mutex_lock(&status_mutex); - writerthreads_mask^=(1<= 0){ - - tengigaEnable = enable; - - if(myDetectorType == EIGER){ - - if(!tengigaEnable){ - packetsPerFrame = EIGER_ONE_GIGA_CONSTANT * dynamicRange * EIGER_MAX_PORTS; - onePacketSize = EIGER_ONE_GIGA_ONE_PACKET_SIZE; - maxPacketsPerFile = EIGER_MAX_FRAMES_PER_FILE * packetsPerFrame; - }else{ - packetsPerFrame = EIGER_TEN_GIGA_CONSTANT * dynamicRange * EIGER_MAX_PORTS; - onePacketSize = EIGER_TEN_GIGA_ONE_PACKET_SIZE; - maxPacketsPerFile = EIGER_MAX_FRAMES_PER_FILE * packetsPerFrame*4; - } - frameSize = onePacketSize * packetsPerFrame; - bufferSize = (frameSize/EIGER_MAX_PORTS) + EIGER_HEADER_LENGTH;//everything one port gets (img header plus packets) - //maxPacketsPerFile = EIGER_MAX_FRAMES_PER_FILE * packetsPerFrame; - - - cout<<"packetsPerFrame:"<*flist[fnum])(); if (ret==FAIL) - cout << "Error executing the function = " << fnum << endl; + cprintf(RED, "Error executing the function = %d\n",fnum); return ret; } @@ -358,7 +358,7 @@ void slsReceiverTCPIPInterface::staticCloseFile(int p){ int slsReceiverTCPIPInterface::set_detector_type(){ ret=OK; - int retval=FAIL; + detectorType retval=GENERIC; detectorType dr; strcpy(mess,"Could not set detector type range\n"); @@ -377,20 +377,35 @@ int slsReceiverTCPIPInterface::set_detector_type(){ ret=FAIL; } else{ - myDetectorType = dr; + + switch(dr){ + case GOTTHARD: + case PROPIX: + case MOENCH: + case EIGER: + case JUNGFRAUCTB: + case JUNGFRAU: + break; + default: + sprintf(mess,"Unknown detector type: %d\n", dr); + ret = FAIL; + break; + if(ret != FAIL){ #ifndef REST - receiverBase = UDPInterface::create("standard"); - receiverBase->setBottom(bottom); + receiverBase = UDPInterface::create("standard"); + receiverBase->setBottomEnable(bottom); #endif - ret=receiverBase->setDetectorType(dr); - retval = myDetectorType; + myDetectorType = dr; + ret=receiverBase->setDetectorType(myDetectorType); + retval = myDetectorType; + } + } } - } //#ifdef VERBOSE if(ret!=FAIL) cout << "detector type" << dr << endl; else - cout << mess << endl; + cprintf(RED, "%s\n", mess); //#endif #endif @@ -417,7 +432,8 @@ int slsReceiverTCPIPInterface::set_detector_type(){ int slsReceiverTCPIPInterface::set_file_name() { ret=OK; - char retval[MAX_STR_LENGTH]=""; + char* retval[MAX_STR_LENGTH] = NULL; + char defaultVal[MAX_STR_LENGTH] = ""; char fName[MAX_STR_LENGTH]; strcpy(mess,"Could not set file name"); @@ -439,8 +455,12 @@ int slsReceiverTCPIPInterface::set_file_name() { strcpy(mess,"Receiver not set up\n"); ret=FAIL; } - else - strcpy(retval,receiverBase->setFileName(fName)); + else{ + receiverBase->setFileName(fName); + retval = receiveBase->getFileName(); + if(retval == NULL) + ret = FAIL; + } } #ifdef VERBOSE if(ret!=FAIL) @@ -457,9 +477,15 @@ int slsReceiverTCPIPInterface::set_file_name() { // send answer socket->SendDataOnly(&ret,sizeof(ret)); - if(ret==FAIL) + if(ret==FAIL){ + cprintf(RED, "%s\n", mess); socket->SendDataOnly(mess,sizeof(mess)); - socket->SendDataOnly(retval,MAX_STR_LENGTH); + socket->SendDataOnly(defaultVal,MAX_STR_LENGTH); + }else + socket->SendDataOnly(retval,MAX_STR_LENGTH); + + //free + if(retval != NULL) delete[] retval; //return ok/fail return ret; @@ -472,7 +498,8 @@ int slsReceiverTCPIPInterface::set_file_name() { int slsReceiverTCPIPInterface::set_file_dir() { ret=OK; - char retval[MAX_STR_LENGTH]=""; + char* retval=NULL; + char defaultVal[MAX_STR_LENGTH] = ""; char fPath[MAX_STR_LENGTH]; strcpy(mess,"Could not set file path\n"); @@ -498,13 +525,12 @@ int slsReceiverTCPIPInterface::set_file_dir() { ret=FAIL; } else{ - strcpy(retval,receiverBase->setFilePath(fPath)); - // if file path doesnt exist - if(strlen(fPath)) - if (strcmp(retval,fPath)){ - strcpy(mess,"receiver file path does not exist\n"); - ret=FAIL; - } + receiverBase->setFilePath(fPath); + retval = receiveBase->getFilePath(); + if(reval == NULL){ + ret = FAIL; + strcpy(mess,"receiver file path does not exist\n"); + } } } @@ -523,9 +549,15 @@ int slsReceiverTCPIPInterface::set_file_dir() { // send answer socket->SendDataOnly(&ret,sizeof(ret)); - if(ret==FAIL) + if(ret==FAIL){ + cprintf(RED, "%s\n", mess); socket->SendDataOnly(mess,sizeof(mess)); - socket->SendDataOnly(retval,MAX_STR_LENGTH); + socket->SendDataOnly(defaultVal,MAX_STR_LENGTH); + }else + socket->SendDataOnly(retval,MAX_STR_LENGTH); + + //free + if(retval != NULL) delete[] retval; //return ok/fail return ret; @@ -560,8 +592,13 @@ int slsReceiverTCPIPInterface::set_file_index() { strcpy(mess,"Receiver not set up\n"); ret=FAIL; } - else - retval=receiverBase->setFileIndex(index); + else{ + if(index >= 0) + receiverBase->setFileIndex(index); + retval=receiverBase->getFileIndex(); + if(index>=0 && retval!=index) + ret = FAIL; + } } #ifdef VERBOSE if(ret!=FAIL) @@ -578,8 +615,10 @@ int slsReceiverTCPIPInterface::set_file_index() { // send answer socket->SendDataOnly(&ret,sizeof(ret)); - if(ret==FAIL) + if(ret==FAIL){ + cprintf(RED, "%s\n", mess); socket->SendDataOnly(mess,sizeof(mess)); + } socket->SendDataOnly(&retval,sizeof(retval)); //return ok/fail @@ -617,8 +656,22 @@ int slsReceiverTCPIPInterface::set_frame_index() { strcpy(mess,"Receiver not set up\n"); ret=FAIL; } - else - retval=receiverBase->setFrameIndexNeeded(index); + else{ + //client sets to 0, but for receiver it is just an enable + //client uses this value for other detectors not using receiver, + //so implement the interface here + + switch(index){ + case -1: index=0; break; + default: index=1; break; //value is 0 + } + receiverBase->setFrameIndexEnable(index); + retval=receiverBase->getFrameIndexEnable(); + switch(retval){ + case 0: retval=-1; break; + case 1: retval=0; break; + } + } } #ifdef VERBOSE if(ret!=FAIL) @@ -635,8 +688,10 @@ int slsReceiverTCPIPInterface::set_frame_index() { // send answer socket->SendDataOnly(&ret,sizeof(ret)); - if(ret==FAIL) + if(ret==FAIL){ + cprintf(RED, "%s\n", mess); socket->SendDataOnly(mess,sizeof(mess)); + } socket->SendDataOnly(&retval,sizeof(retval)); //return ok/fail @@ -652,7 +707,7 @@ int slsReceiverTCPIPInterface::set_frame_index() { int slsReceiverTCPIPInterface::setup_udp(){ ret=OK; strcpy(mess,"could not set up udp connection"); - char retval[MAX_STR_LENGTH]=""; + char retval[MAX_STR_LENGTH] = ""; char args[3][MAX_STR_LENGTH]; string temp; @@ -705,8 +760,8 @@ int slsReceiverTCPIPInterface::setup_udp(){ } FILE_LOG(logDEBUG) << __FILE__ << "::" << __func__ << " " << eth; receiverBase->setEthernetInterface(eth); - cout << eth << endl; + //get mac address from ethernet interface if (ret != FAIL) temp = genericSocket::nameToMac(eth); @@ -715,7 +770,7 @@ int slsReceiverTCPIPInterface::setup_udp(){ if ((temp=="00:00:00:00:00:00") || (ret == FAIL)){ ret = FAIL; strcpy(mess,"failed to get mac adddress to listen to\n"); - cout << "mess:" << mess << endl; + cprintf(RED,"%s\n",mess); } else{ strcpy(retval,temp.c_str()); @@ -733,8 +788,10 @@ int slsReceiverTCPIPInterface::setup_udp(){ // send answer socket->SendDataOnly(&ret,sizeof(ret)); - if(ret==FAIL) + if(ret==FAIL){ + cprintf(RED, "%s\n", mess); socket->SendDataOnly(mess,sizeof(mess)); + } socket->SendDataOnly(retval,MAX_STR_LENGTH); //return ok/fail @@ -749,8 +806,7 @@ int slsReceiverTCPIPInterface::setup_udp(){ int slsReceiverTCPIPInterface::start_receiver(){ ret=OK; ret=OK; - enum runStatus s; - char cstatus[15]; + enum runStatus s = ERROR; strcpy(mess,"Could not start receiver\n"); // execute action if the arguments correctly arrived @@ -771,22 +827,13 @@ int slsReceiverTCPIPInterface::start_receiver(){ } else { s = receiverBase->getStatus(); - switch (s) { - case ERROR: strcpy(cstatus,"error"); break; - case WAITING: strcpy(cstatus,"waiting"); break; - case RUNNING: strcpy(cstatus,"running"); break; - case TRANSMITTING: strcpy(cstatus,"data"); break; - case RUN_FINISHED: strcpy(cstatus,"finished"); break; - default: strcpy(cstatus,"idle"); break; - } if(s == IDLE) ret=receiverBase->startReceiver(mess); else{ - sprintf(mess,"Cannot start Receiver as it is in %s state\n",cstatus); + sprintf(mess,"Cannot start Receiver as it is in %s state\n",slsDetectorBase::runStatusType(s).c_str()); ret=FAIL; } } - #endif if(ret==OK && socket->differentClients){ @@ -797,6 +844,7 @@ int slsReceiverTCPIPInterface::start_receiver(){ // send answer socket->SendDataOnly(&ret,sizeof(ret)); if(ret==FAIL){ + cprintf(RED, "%s\n", mess); socket->SendDataOnly(mess,sizeof(mess)); } //return ok/fail @@ -808,7 +856,7 @@ int slsReceiverTCPIPInterface::start_receiver(){ int slsReceiverTCPIPInterface::stop_receiver(){ ret=OK; - + enum runStatus s = ERROR; strcpy(mess,"Could not stop receiver\n"); // execute action if the arguments correctly arrived @@ -821,8 +869,17 @@ int slsReceiverTCPIPInterface::stop_receiver(){ strcpy(mess,"Receiver not set up\n"); ret=FAIL; } - else if(receiverBase->getStatus()!=IDLE) - ret=receiverBase->stopReceiver(); + else{ + if(receiverBase->getStatus()!=IDLE) + receiverBase->stopReceiver(); + s = receiverBase->getStatus(); + if(s==IDLE) + ret = OK; + else{ + sprintf(mess,"Could not stop receiver. It is in %s state\n",slsDetectorBase::runStatusType(s).c_str()); + ret = FAIL; + } + } #endif if(ret==OK && socket->differentClients){ @@ -832,8 +889,10 @@ int slsReceiverTCPIPInterface::stop_receiver(){ // send answer socket->SendDataOnly(&ret,sizeof(ret)); - if(ret==FAIL) + if(ret==FAIL){ + cprintf(RED, "%s\n", mess); socket->SendDataOnly(mess,sizeof(mess)); + } //return ok/fail return ret; @@ -860,8 +919,10 @@ int slsReceiverTCPIPInterface::get_status(){ // send answer socket->SendDataOnly(&ret,sizeof(ret)); - if(ret==FAIL) + if(ret==FAIL){ + cprintf(RED, "%s\n", mess); socket->SendDataOnly(mess,sizeof(mess)); + } socket->SendDataOnly(&retval,sizeof(retval)); //return ok/fail return ret; @@ -888,8 +949,10 @@ int slsReceiverTCPIPInterface::get_frames_caught(){ // send answer socket->SendDataOnly(&ret,sizeof(ret)); - if(ret==FAIL) + if(ret==FAIL){ + cprintf(RED, "%s\n", mess); socket->SendDataOnly(mess,sizeof(mess)); + } socket->SendDataOnly(&retval,sizeof(retval)); //return ok/fail return ret; @@ -918,8 +981,10 @@ int slsReceiverTCPIPInterface::get_frame_index(){ // send answer socket->SendDataOnly(&ret,sizeof(ret)); - if(ret==FAIL) + if(ret==FAIL){ + cprintf(RED, "%s\n", mess); socket->SendDataOnly(mess,sizeof(mess)); + } socket->SendDataOnly(&retval,sizeof(retval)); //return ok/fail return ret; @@ -946,7 +1011,7 @@ int slsReceiverTCPIPInterface::reset_frames_caught(){ ret=FAIL; } else - receiverBase->resetTotalFramesCaught(); + receiverBase->resetAcquisitionCount(); } #endif @@ -957,9 +1022,10 @@ int slsReceiverTCPIPInterface::reset_frames_caught(){ // send answer socket->SendDataOnly(&ret,sizeof(ret)); - if(ret==FAIL) + if(ret==FAIL){ + cprintf(RED, "%s\n", mess); socket->SendDataOnly(mess,sizeof(mess)); - + } //return ok/fail return ret; @@ -1006,7 +1072,8 @@ int slsReceiverTCPIPInterface::set_short_frame() { ret=FAIL; } else{ - retval=receiverBase->setShortFrame(index); + receiverBase->setShortFrameEnable(index); + retval = receiverBase->getShortFrameEnable(); shortFrame = retval; if(shortFrame==-1) packetsPerFrame=GOTTHARD_PACKETS_PER_FRAME; @@ -1023,8 +1090,10 @@ int slsReceiverTCPIPInterface::set_short_frame() { // send answer socket->SendDataOnly(&ret,sizeof(ret)); - if(ret==FAIL) + if(ret==FAIL){ + cprintf(RED, "%s\n", mess); socket->SendDataOnly(mess,sizeof(mess)); + } socket->SendDataOnly(&retval,sizeof(retval)); //return ok/fail @@ -1088,7 +1157,6 @@ int slsReceiverTCPIPInterface::moench_read_frame(){ else{ ret = OK; - /*startIndex=receiverBase->getStartFrameIndex();*/ receiverBase->readFrame(fName,&raw,startAcquisitionIndex,startFrameIndex); /**send garbage with -1 index to try again*/ @@ -1203,7 +1271,7 @@ int slsReceiverTCPIPInterface::moench_read_frame(){ // send answer socket->SendDataOnly(&ret,sizeof(ret)); if(ret==FAIL){ - cout << "mess:" << mess << endl; + cprintf(RED,"%s\n",mess); socket->SendDataOnly(mess,sizeof(mess)); } else{ @@ -1277,7 +1345,6 @@ int slsReceiverTCPIPInterface::gotthard_read_frame(){ cout<<"haven't caught any frame yet"<getStartFrameIndex();*/ receiverBase->readFrame(fName,&raw,startAcquisitionIndex,startFrameIndex); /**send garbage with -1 index to try again*/ @@ -1385,7 +1452,7 @@ int slsReceiverTCPIPInterface::gotthard_read_frame(){ // send answer socket->SendDataOnly(&ret,sizeof(ret)); if(ret==FAIL){ - cout << "mess:" << mess << endl; + cprintf(RED,"%s\n",mess); socket->SendDataOnly(mess,sizeof(mess)); } else{ @@ -1453,7 +1520,6 @@ int slsReceiverTCPIPInterface::propix_read_frame(){ cout<<"haven't caught any frame yet"<getStartFrameIndex();*/ receiverBase->readFrame(fName,&raw,startAcquisitionIndex,startFrameIndex); /**send garbage with -1 index to try again*/ @@ -1540,7 +1606,7 @@ int slsReceiverTCPIPInterface::propix_read_frame(){ // send answer socket->SendDataOnly(&ret,sizeof(ret)); if(ret==FAIL){ - cout << "mess:" << mess << endl; + cprintf(RED,"%s\n",mess); socket->SendDataOnly(mess,sizeof(mess)); } else{ @@ -1802,7 +1868,7 @@ int slsReceiverTCPIPInterface::eiger_read_frame(){ // send answer socket->SendDataOnly(&ret,sizeof(ret)); if(ret==FAIL){ - cout << "mess:" << mess << endl; + cprintf(RED,"%s\n",mess); socket->SendDataOnly(mess,sizeof(mess)); } else{ @@ -1855,8 +1921,13 @@ int slsReceiverTCPIPInterface::set_read_frequency(){ ret = FAIL; strcpy(mess,"cannot set up receiver mode when receiver is running\n"); }*/ - else - retval=receiverBase->setNFrameToGui(index); + else{ + if(index >= 0) + receiverBase->setFrameToGuiFrequency(index); + retval=receiverBase->getFrameToGuiFrequency(); + if(index>=0 && retval!=index) + ret = FAIL; + } } #endif @@ -1868,8 +1939,10 @@ int slsReceiverTCPIPInterface::set_read_frequency(){ // send answer socket->SendDataOnly(&ret,sizeof(ret)); - if(ret==FAIL) + if(ret==FAIL){ + cprintf(RED,"%s\n",mess); socket->SendDataOnly(mess,sizeof(mess)); + } socket->SendDataOnly(&retval,sizeof(retval)); //return ok/fail @@ -1907,9 +1980,9 @@ int slsReceiverTCPIPInterface::enable_file_write(){ } else{ if(enable >= 0) - receiverBase->setEnableFileWrite(enable); - retval=receiverBase->getEnableFileWrite(); - if((enable!=-1)&&(enable!=retval)) + receiverBase->setFileWriteEnable(enable); + retval=receiverBase->getFileWriteEnable(); + if(enable>=0 && enable!=retval) ret=FAIL; } } @@ -1922,8 +1995,10 @@ int slsReceiverTCPIPInterface::enable_file_write(){ // send answer socket->SendDataOnly(&ret,sizeof(ret)); - if(ret==FAIL) + if(ret==FAIL){ + cprintf(RED,"%s\n",mess); socket->SendDataOnly(mess,sizeof(mess)); + } socket->SendDataOnly(&retval,sizeof(retval)); //return ok/fail @@ -1991,8 +2066,10 @@ int slsReceiverTCPIPInterface::start_readout(){ // send answer socket->SendDataOnly(&ret,sizeof(ret)); - if(ret==FAIL) + if(ret==FAIL){ + cprintf(RED,"%s\n",mess); socket->SendDataOnly(mess,sizeof(mess)); + } socket->SendDataOnly(&retval,sizeof(retval)); //return ok/fail return ret; @@ -2029,10 +2106,17 @@ int slsReceiverTCPIPInterface::set_timer() { ret=FAIL; } else{ - if(index[0] == slsReceiverDefs::FRAME_PERIOD) - retval=receiverBase->setAcquisitionPeriod(index[1]); - else - retval=receiverBase->setNumberOfFrames(index[1]); + if(index[0] == slsReceiverDefs::FRAME_PERIOD){ + if(index[1]>=0) + receiverBase->setAcquisitionPeriod(index[1]); + retval=receiverBase->getAcquisitionPeriod(); + }else{ + if(index[1]>=0) + receiverBase->setNumberOfFrames(index[1]); + retval=receiverBase->getNumberOfFrames(); + } + if(index[1]>=0 && retval!=index[1]) + ret = FAIL; } } #ifdef VERBOSE @@ -2053,8 +2137,10 @@ int slsReceiverTCPIPInterface::set_timer() { // send answer socket->SendDataOnly(&ret,sizeof(ret)); - if(ret==FAIL) + if(ret==FAIL){ + cprintf(RED,"%s\n",mess); socket->SendDataOnly(mess,sizeof(mess)); + } socket->SendDataOnly(&retval,sizeof(retval)); //return ok/fail @@ -2095,15 +2181,21 @@ int slsReceiverTCPIPInterface::enable_compression() { strcpy(mess,"Cannot enable/disable compression while status is running\n"); ret=FAIL; } - else - ret = receiverBase->enableDataCompression(enable); + else{ + if(enable >= 0) + receiverBase->setDataCompressionEnable(enable); + } } if (receiverBase == NULL){ strcpy(mess,"Receiver not set up\n"); ret=FAIL; - }else - retval=receiverBase->getDataCompression(); + }else{ + retval = receiverBase->getDataCompressionEnable(); + if(enable >= 0 && retval != enable) + ret = FAIL; + } + } #endif @@ -2114,8 +2206,10 @@ int slsReceiverTCPIPInterface::enable_compression() { // send answer socket->SendDataOnly(&ret,sizeof(ret)); - if(ret==FAIL) + if(ret==FAIL){ + cprintf(RED,"%s\n",mess); socket->SendDataOnly(mess,sizeof(mess)); + } socket->SendDataOnly(&retval,sizeof(retval)); //return ok/fail @@ -2127,7 +2221,8 @@ int slsReceiverTCPIPInterface::enable_compression() { int slsReceiverTCPIPInterface::set_detector_hostname() { ret=OK; - char retval[MAX_STR_LENGTH]=""; + char* retval = NULL; + char defaultVal[MAX_STR_LENGTH] = ""; char hostname[MAX_STR_LENGTH]=""; strcpy(mess,"Could not set detector hostname"); @@ -2151,7 +2246,10 @@ int slsReceiverTCPIPInterface::set_detector_hostname() { } else{ receiverBase->initialize(hostname); - strcpy(retval,receiverBase->getDetectorHostname()); + retval = receiverBase->getDetectorHostname(); + if(retval == NULL){ + ret = FAIL; + } } } #ifdef VERBOSE @@ -2169,9 +2267,14 @@ int slsReceiverTCPIPInterface::set_detector_hostname() { // send answer socket->SendDataOnly(&ret,sizeof(ret)); - if(ret==FAIL) + if(ret==FAIL){ + cprintf(RED,"%s\n",mess); socket->SendDataOnly(mess,sizeof(mess)); - socket->SendDataOnly(retval,MAX_STR_LENGTH); + socket->SendDataOnly(defaultVal,MAX_STR_LENGTH); + }else socket->SendDataOnly(retval,MAX_STR_LENGTH); + + //free + if(retval!=NULL) delete[] retval; //return ok/fail return ret; @@ -2203,14 +2306,14 @@ int slsReceiverTCPIPInterface::set_dynamic_range() { sprintf(mess,"Receiver locked by %s\n", socket->lastClientIP); ret=FAIL; } - else if ((dr>0) && (myDetectorType == EIGER)){ + else if (dr>0) { switch(dr){ case 4: case 8: case 16: case 32:break; default: - sprintf(mess,"This dynamic range does not exist for eiger: %d\n",dr); + sprintf(mess,"This dynamic range does not exist: %d\n",dr); cprintf(RED,"%s", mess); ret=FAIL; break; @@ -2221,14 +2324,19 @@ int slsReceiverTCPIPInterface::set_dynamic_range() { strcpy(mess,"Receiver not set up\n"); ret=FAIL; }else{ - if(dr > 0) receiverBase->setDynamicRange(dr); + if(dr > 0) + receiverBase->setDynamicRange(dr); retval = receiverBase->getDynamicRange(); - dynamicrange = retval; - if(myDetectorType == EIGER){ - if(!tenGigaEnable) - packetsPerFrame = EIGER_ONE_GIGA_CONSTANT * dynamicrange * EIGER_MAX_PORTS; - else - packetsPerFrame = EIGER_TEN_GIGA_CONSTANT * dynamicrange * EIGER_MAX_PORTS; + if(dr > 0 && retval != dr) + ret = FAIL; + else{ + dynamicrange = retval; + if(myDetectorType == EIGER){ + if(!tenGigaEnable) + packetsPerFrame = EIGER_ONE_GIGA_CONSTANT * dynamicrange * EIGER_MAX_PORTS; + else + packetsPerFrame = EIGER_TEN_GIGA_CONSTANT * dynamicrange * EIGER_MAX_PORTS; + } } } } @@ -2248,8 +2356,10 @@ int slsReceiverTCPIPInterface::set_dynamic_range() { // send answer socket->SendDataOnly(&ret,sizeof(ret)); - if(ret==FAIL) + if(ret==FAIL){ + cprintf(RED,"%s\n",mess); socket->SendDataOnly(mess,sizeof(mess)); + } socket->SendDataOnly(&retval,sizeof(retval)); //return ok/fail @@ -2288,8 +2398,10 @@ int slsReceiverTCPIPInterface::enable_overwrite() { } else{ if(index >= 0) - receiverBase->setEnableOverwrite(index); - retval=receiverBase->getEnableOverwrite(); + receiverBase->setOverwriteEnable(index); + retval=receiverBase->getOverwriteEnable(); + if(index >=0 && retval != index) + ret = FAIL; } } #ifdef VERBOSE @@ -2307,8 +2419,10 @@ int slsReceiverTCPIPInterface::enable_overwrite() { // send answer socket->SendDataOnly(&ret,sizeof(ret)); - if(ret==FAIL) + if(ret==FAIL){ + cprintf(RED,"%s\n",mess); socket->SendDataOnly(mess,sizeof(mess)); + } socket->SendDataOnly(&retval,sizeof(retval)); //return ok/fail @@ -2346,8 +2460,10 @@ int slsReceiverTCPIPInterface::enable_tengiga() { ret=FAIL; } else{ - retval=receiverBase->enableTenGiga(val); - if((val!=-1) && (val != retval)) + if(val >= 0) + receiverBase->setDataCompressionEnable(val); + retval=receiverBase->getDataCompressionEnable(); + if((val >= 0) && (val != retval)) ret = FAIL; else tenGigaEnable = retval; @@ -2368,8 +2484,10 @@ int slsReceiverTCPIPInterface::enable_tengiga() { // send answer socket->SendDataOnly(&ret,sizeof(ret)); - if(ret==FAIL) + if(ret==FAIL){ + cprintf(RED,"%s\n",mess); socket->SendDataOnly(mess,sizeof(mess)); + } socket->SendDataOnly(&retval,sizeof(retval)); //return ok/fail @@ -2436,8 +2554,10 @@ int slsReceiverTCPIPInterface::lock_receiver() { // send answer socket->SendDataOnly(&ret,sizeof(ret)); - if (ret==FAIL) + if(ret==FAIL){ + cprintf(RED,"%s\n",mess); socket->SendDataOnly(mess,sizeof(mess)); + } else socket->SendDataOnly(&lockStatus,sizeof(lockStatus)); @@ -2509,9 +2629,10 @@ int slsReceiverTCPIPInterface::set_port() { // send answer socket->SendDataOnly(&ret,sizeof(ret)); - if (ret==FAIL) { + if(ret==FAIL){ + cprintf(RED,"%s\n",mess); socket->SendDataOnly(mess,sizeof(mess)); - } else { + }else { socket->SendDataOnly(&p_number,sizeof(p_number)); if(sd>=0){ socket->Disconnect(); @@ -2550,7 +2671,8 @@ int slsReceiverTCPIPInterface::get_last_client_ip() { int slsReceiverTCPIPInterface::send_update() { ret=OK; int ind; - char path[MAX_STR_LENGTH]; + char defaultVal[MAX_STR_LENGTH]=""; + char* path = NULL; socket->SendDataOnly(socket->lastClientIP,sizeof(socket->lastClientIP)); @@ -2564,17 +2686,26 @@ int slsReceiverTCPIPInterface::send_update() { //filepath #ifdef SLS_RECEIVER_UDP_FUNCTIONS - strcpy(path,receiverBase->getFilePath()); + path = receiverBase->getFilePath(); #endif - socket->SendDataOnly(path,MAX_STR_LENGTH); + if(path == NULL) + socket->SendDataOnly(defaultVal,MAX_STR_LENGTH); + else{ + socket->SendDataOnly(path,MAX_STR_LENGTH); + delete[] path; + } //filename #ifdef SLS_RECEIVER_UDP_FUNCTIONS - strcpy(path,receiverBase->getFileName()); + path = receiverBase->getFileName(); #endif - socket->SendDataOnly(path,MAX_STR_LENGTH); - + if(path == NULL) + socket->SendDataOnly(defaultVal,MAX_STR_LENGTH); + else{ + socket->SendDataOnly(path,MAX_STR_LENGTH); + delete[] path; + } if (lockStatus==0) { strcpy(socket->lastClientIP,socket->thisClientIP); @@ -2597,7 +2728,8 @@ int slsReceiverTCPIPInterface::update_client() { ret=FAIL; } socket->SendDataOnly(&ret,sizeof(ret)); - if(ret == FAIL){ + if(ret==FAIL){ + cprintf(RED,"%s\n",mess); socket->SendDataOnly(mess,sizeof(mess)); return ret; } @@ -2616,7 +2748,7 @@ int slsReceiverTCPIPInterface::exit_server() { socket->SendDataOnly(&ret,sizeof(ret)); strcpy(mess,"closing server"); socket->SendDataOnly(mess,sizeof(mess)); - cout << mess << endl; + cprintf(RED,"%s\n",mess); return ret; } From 9148f6365ece80e42b83ed66f130686af13883cf Mon Sep 17 00:00:00 2001 From: Dhanya Maliakal Date: Fri, 2 Oct 2015 12:05:16 +0200 Subject: [PATCH 33/68] changed last packet value literal to expression, not big in functionality --- .../src/UDPStandardImplementation.cpp | 24 ++----------------- 1 file changed, 2 insertions(+), 22 deletions(-) diff --git a/slsReceiverSoftware/src/UDPStandardImplementation.cpp b/slsReceiverSoftware/src/UDPStandardImplementation.cpp index 609f4fea7..84a5fedba 100644 --- a/slsReceiverSoftware/src/UDPStandardImplementation.cpp +++ b/slsReceiverSoftware/src/UDPStandardImplementation.cpp @@ -1970,19 +1970,6 @@ int UDPStandardImplementation::startWriting(){ eiger_packet_header_t* blankframe_header=0; unsigned char* blankframe_data=0; - //last packet numbers for different dynamic ranges - if(myDetectorType == EIGER){ - switch(dynamicRange){ - case 4: LAST_PACKET_VALUE = 0x40; break; - case 8: LAST_PACKET_VALUE = 0x80; break; - case 16: LAST_PACKET_VALUE = 0x100; break; - case 32: LAST_PACKET_VALUE = 0x200; break; - default: break; - } - - } - - while(1){ @@ -2030,15 +2017,8 @@ int UDPStandardImplementation::startWriting(){ #endif } - if(tengigaEnable){ - switch(dynamicRange){ - case 4: LAST_PACKET_VALUE = 0x10; break; - case 8: LAST_PACKET_VALUE = 0x20; break; - case 16: LAST_PACKET_VALUE = 0x40; break; - case 32: LAST_PACKET_VALUE = 0x80; break; - default: break; - } - } + //last packet numbers for different dynamic ranges + LAST_PACKET_VALUE = (packetsPerFrame/numListeningThreads); } From a3e88f96d6d1cfd2ad050006dc632c88437c8715 Mon Sep 17 00:00:00 2001 From: Dhanya Maliakal Date: Thu, 8 Oct 2015 12:19:07 +0200 Subject: [PATCH 34/68] some more changes --- .../include/UDPBaseImplementation.h | 67 +- slsReceiverSoftware/include/UDPInterface.h | 30 +- .../include/UDPStandardImplementation.h | 694 ++++--- slsReceiverSoftware/include/receiver_defs.h | 8 +- slsReceiverSoftware/include/slsReceiver.h | 1 - .../include/sls_receiver_defs.h | 10 + .../src/UDPBaseImplementation.cpp | 91 +- slsReceiverSoftware/src/UDPInterface.cpp | 4 +- .../src/UDPStandardImplementation.cpp | 1838 ++++++++--------- .../src/slsReceiverTCPIPInterface.cpp | 43 +- 10 files changed, 1436 insertions(+), 1350 deletions(-) diff --git a/slsReceiverSoftware/include/UDPBaseImplementation.h b/slsReceiverSoftware/include/UDPBaseImplementation.h index 29d9dd009..293ac6763 100644 --- a/slsReceiverSoftware/include/UDPBaseImplementation.h +++ b/slsReceiverSoftware/include/UDPBaseImplementation.h @@ -7,13 +7,12 @@ ***********************************************/ -#include "sls_receiver_defs.h" +//#include "sls_receiver_defs.h" #include "UDPInterface.h" -#include -#include +//#include /** - * @short does all the functions for a receiver, set/get parameters, start/stop etc. + * @short does all the base functions for a receiver, set/get parameters, start/stop etc. */ class UDPBaseImplementation : protected virtual slsReceiverDefs, public UDPInterface { @@ -123,13 +122,13 @@ class UDPBaseImplementation : protected virtual slsReceiverDefs, public UDPInter * Get UDP Port Number * @return udp port number */ - uint32_t getUDPPortNo() const; + uint32_t getUDPPortNumber() const; /** * Get Second UDP Port Number (eiger specific) * @return second udp port number */ - uint32_t getUDPPortNo2() const; + uint32_t getUDPPortNumber2() const; /** * Get Ehernet Interface @@ -254,9 +253,9 @@ class UDPBaseImplementation : protected virtual slsReceiverDefs, public UDPInter /** * Set data compression, by saving only hits (so far implemented only for Moench and Gotthard) * @param b true for data compression enable, else false + * @return OK or FAIL */ - void setDataCompressionEnable(const bool b); - + int setDataCompressionEnable(const bool b); //***connection parameters*** @@ -264,13 +263,13 @@ class UDPBaseImplementation : protected virtual slsReceiverDefs, public UDPInter * Set UDP Port Number * @param i udp port number */ - void setUDPPortNo(const uint32_t i); + void setUDPPortNumber(const uint32_t i); /** * Set Second UDP Port Number (eiger specific) * @return second udp port number */ - void setUDPPortNo2(const uint32_t i); + void setUDPPortNumber2(const uint32_t i); /** * Set Ethernet Interface to listen to @@ -279,7 +278,7 @@ class UDPBaseImplementation : protected virtual slsReceiverDefs, public UDPInter void setEthernetInterface(const char* c); - //***connection parameters*** + //***acquisition parameters*** /** * Set Short Frame Enabled, later will be moved to getROI (so far only for gotthard) * @param i index of adc enabled, else -1 if all enabled @@ -289,14 +288,16 @@ class UDPBaseImplementation : protected virtual slsReceiverDefs, public UDPInter /** * Set the Frequency of Frames Sent to GUI * @param i 0 for random frame requests, n for nth frame frequency + * @return OK or FAIL */ - void setFrameToGuiFrequency(const uint32_t i); + int setFrameToGuiFrequency(const uint32_t i); /** * Set Acquisition Period * @param i acquisition period + * @return OK or FAIL */ - void setAcquisitionPeriod(const uint64_t i); + int setAcquisitionPeriod(const uint64_t i); /** * Set Number of Frames expected by receiver from detector @@ -308,15 +309,16 @@ class UDPBaseImplementation : protected virtual slsReceiverDefs, public UDPInter /** * Set Dynamic Range or Number of Bits Per Pixel * @param i dynamic range that is 4, 8, 16 or 32 + * @return OK or FAIL */ - void setDynamicRange(const uint32_t i); + int setDynamicRange(const uint32_t i); /** * Set Ten Giga Enable * @param b true if 10Giga enabled, else false (1G enabled) + * @return OK or FAIL */ - void setTenGigaEnable(const bool b); - + int setTenGigaEnable(const bool b); /************************************************************************* @@ -324,6 +326,7 @@ class UDPBaseImplementation : protected virtual slsReceiverDefs, public UDPInter * They may modify the status of the receiver **************************** *************************************************************************/ + //***initial functions*** /** * Set receiver type (and corresponding detector variables in derived STANDARD class) @@ -387,7 +390,7 @@ class UDPBaseImplementation : protected virtual slsReceiverDefs, public UDPInter * abort acquisition with minimum damage: close open files, cleanup. * does nothing if state already is 'idle' */ - void abort(); //FIXME: needed, isnt stopReceiver enough? + void abort(); //FIXME: needed, isn't stopReceiver enough? /** * Closes all files @@ -436,36 +439,12 @@ class UDPBaseImplementation : protected virtual slsReceiverDefs, public UDPInter protected: //**detector parameters*** - /** - * structure of an eiger packet header - * subframenum subframe number for 32 bit mode (already written by firmware) - * missingpacket explicitly put to 0xFF to recognize it in file read (written by software) - * portnum 0 for the first port and 1 for the second port (written by software to file) - * dynamicrange dynamic range or bits per pixel (written by software to file) - */ - typedef struct { - unsigned char subframenum[4]; - unsigned char missingpacket[2]; - unsigned char portnum[1]; - unsigned char dynamicrange[1]; - } eiger_packet_header_t; - /** - * structure of an eiger packet footer - * framenum 48 bit frame number (already written by firmware) - * packetnum packet number (already written by firmware) - */ - typedef struct { - unsigned char framenum[6]; - unsigned char packetnum[2]; - } eiger_packet_footer_t; - - /** detector type */ detectorType myDetectorType; /** detector hostname */ char detHostname[MAX_STR_LENGTH]; /** Number of Packets per Frame*/ - uint64_t packetsPerFrame; + uint32_t packetsPerFrame; /** Acquisition Period */ int64_t acquisitionPeriod; /** Frame Number */ @@ -479,7 +458,7 @@ class UDPBaseImplementation : protected virtual slsReceiverDefs, public UDPInter //***receiver parameters*** /** Maximum Number of Listening Threads/ UDP Ports */ - const static int MAX_NUM_LISTENING_THREADS = 2; + const static int MAX_NUMBER_OF_LISTENING_THREADS = 2; /** Receiver Status */ runStatus status; @@ -487,7 +466,7 @@ class UDPBaseImplementation : protected virtual slsReceiverDefs, public UDPInter /** Ethernet Interface */ char eth[MAX_STR_LENGTH]; /** Server UDP Port Number*/ - uint32_t udpPortNum[MAX_NUM_LISTENING_THREADS]; + uint32_t udpPortNum[MAX_NUMBER_OF_LISTENING_THREADS]; //***file parameters*** /** File Name without frame index, file index and extension (_d0_f000000000000_8.raw)*/ diff --git a/slsReceiverSoftware/include/UDPInterface.h b/slsReceiverSoftware/include/UDPInterface.h index 2e89b59be..65c275a29 100644 --- a/slsReceiverSoftware/include/UDPInterface.h +++ b/slsReceiverSoftware/include/UDPInterface.h @@ -17,8 +17,6 @@ #include "sls_receiver_defs.h" #include "receiver_defs.h" -#include "MySocketTCP.h" - #include "utilities.h" #include "logger.h" @@ -184,13 +182,13 @@ class UDPInterface { * Get UDP Port Number * @return udp port number */ - virtual uint32_t getUDPPortNo() const = 0; + virtual uint32_t getUDPPortNumber() const = 0; /** * Get Second UDP Port Number (eiger specific) * @return second udp port number */ - virtual uint32_t getUDPPortNo2() const = 0; + virtual uint32_t getUDPPortNumber2() const = 0; /** * Get Ehernet Interface @@ -314,22 +312,22 @@ class UDPInterface { /** * Set data compression, by saving only hits (so far implemented only for Moench and Gotthard) * @param b true for data compression enable, else false + * @return OK or FAIL */ - virtual void setDataCompressionEnable(const bool b) = 0; - + virtual int setDataCompressionEnable(const bool b) = 0; //***connection parameters*** /** * Set UDP Port Number * @param i udp port number */ - virtual void setUDPPortNo(const uint32_t i) = 0; + virtual void setUDPPortNumber(const uint32_t i) = 0; /** * Set Second UDP Port Number (eiger specific) * @return second udp port number */ - virtual void setUDPPortNo2(const uint32_t i) = 0; + virtual void setUDPPortNumber2(const uint32_t i) = 0; /** * Set Ethernet Interface to listen to @@ -338,7 +336,7 @@ class UDPInterface { virtual void setEthernetInterface(const char* c) = 0; - //***connection parameters*** + //***acquisition parameters*** /** * Set Short Frame Enabled, later will be moved to getROI (so far only for gotthard) * @param i index of adc enabled, else -1 if all enabled @@ -348,14 +346,16 @@ class UDPInterface { /** * Set the Frequency of Frames Sent to GUI * @param i 0 for random frame requests, n for nth frame frequency + * @return OK or FAIL */ - virtual void setFrameToGuiFrequency(const uint32_t i) = 0; + virtual int setFrameToGuiFrequency(const uint32_t i) = 0; /** * Set Acquisition Period * @param i acquisition period + * @return OK or FAIL */ - virtual void setAcquisitionPeriod(const uint64_t i) = 0; + virtual int setAcquisitionPeriod(const uint64_t i) = 0; /** * Set Number of Frames expected by receiver from detector @@ -367,15 +367,16 @@ class UDPInterface { /** * Set Dynamic Range or Number of Bits Per Pixel * @param i dynamic range that is 4, 8, 16 or 32 + * @return OK or FAIL */ - virtual void setDynamicRange(const uint32_t i) = 0; + virtual int setDynamicRange(const uint32_t i) = 0; /** * Set Ten Giga Enable * @param b true if 10Giga enabled, else false (1G enabled) + * @return OK or FAIL */ - virtual void setTenGigaEnable(const bool b) = 0; - + virtual int setTenGigaEnable(const bool b) = 0; /************************************************************************* @@ -383,6 +384,7 @@ class UDPInterface { * They may modify the status of the receiver **************************** *************************************************************************/ + //***initial functions*** /** * Set receiver type (and corresponding detector variables in derived STANDARD class) diff --git a/slsReceiverSoftware/include/UDPStandardImplementation.h b/slsReceiverSoftware/include/UDPStandardImplementation.h index 04bd7000e..747eaad34 100644 --- a/slsReceiverSoftware/include/UDPStandardImplementation.h +++ b/slsReceiverSoftware/include/UDPStandardImplementation.h @@ -6,25 +6,22 @@ * @short does all the functions for a receiver, set/get parameters, start/stop etc. ***********************************************/ +#include "UDPBaseImplementation.h" -#include "sls_receiver_defs.h" -#include "receiver_defs.h" +//#include "sls_receiver_defs.h" +//#include "receiver_defs.h" #include "genericSocket.h" #include "circularFifo.h" #include "singlePhotonDetector.h" #include "slsReceiverData.h" #include "moenchCommonMode.h" -//#include "UDPInterface.h" -#include "UDPBaseImplementation.h" #ifdef MYROOT1 #include #include #endif - - #include #include #include @@ -38,7 +35,13 @@ class UDPStandardImplementation: private virtual slsReceiverDefs, public UDPBaseImplementation { public: - /** + + + /************************************************************************* + * Constructor & Destructor ********************************************** + * They access local cache of configuration or detector parameters ******* + *************************************************************************/ + /** * Constructor */ UDPStandardImplementation(); @@ -48,17 +51,382 @@ class UDPStandardImplementation: private virtual slsReceiverDefs, public UDPBase */ virtual ~UDPStandardImplementation(); + + /************************************************************************* + * Getters *************************************************************** + * They access local cache of configuration or detector parameters ******* + *************************************************************************/ + + //***acquisition count parameters*** + + + /************************************************************************* + * Setters *************************************************************** + * They modify the local cache of configuration or detector parameters *** + *************************************************************************/ + + //**initial parameters*** + + /** + * Overridden method + * Configure command line parameters + * @param config_map mapping of config parameters passed from command line arguments + */ void configure(map config_map); + //*** file parameters*** /** - * delete and free member parameters + * Overridden method + * Set data compression, by saving only hits (so far implemented only for Moench and Gotthard) + * @param b true for data compression enable, else false */ - void deleteMembers(); + void setDataCompressionEnable(const bool b); + + //***acquisition parameters*** + /** + * Overridden method + * Set Short Frame Enabled, later will be moved to getROI (so far only for gotthard) + * @param i index of adc enabled, else -1 if all enabled + */ + void setShortFrameEnable(const int i); /** - * initialize member parameters + * Overridden method + * Set the Frequency of Frames Sent to GUI + * @param i 0 for random frame requests, n for nth frame frequency + * @return OK or FAIL + */ + int setFrameToGuiFrequency(const uint32_t i); + + /** + * Overridden method + * Set Acquisition Period + * @param i acquisition period + * @return OK or FAIL + */ + int setAcquisitionPeriod(const uint64_t i); + + /** + * Overridden method + * Set Dynamic Range or Number of Bits Per Pixel + * @param i dynamic range that is 4, 8, 16 or 32 + * @return OK or FAIL + */ + int setDynamicRange(const uint32_t i); + + /** + * Overridden method + * Set Ten Giga Enable + * @param b true if 10Giga enabled, else false (1G enabled) + * @return OK or FAIL + */ + int setTenGigaEnable(const bool b); + + + + /************************************************************************* + * Behavioral functions*************************************************** + * They may modify the status of the receiver **************************** + *************************************************************************/ + + //***initial functions*** + /** + * Overridden method + * Set receiver type (and corresponding detector variables in derived STANDARD class) + * It is the first function called by the client when connecting to receiver + * @param d detector type + * @return OK or FAIL + */ + int setDetectorType(const slsReceiverDefs::detectorType d); + + //***acquisition functions*** + /** + * Overridden method + * Reset acquisition parameters such as total frames caught for an entire acquisition (including all scans) + */ + void resetAcquisitionCount(); + + /** + * Overridden method + * Start Listening for Packets by activating all configuration settings to receiver + * @param c error message if FAIL + * @return OK or FAIL + */ + int startReceiver(char *c=NULL); + + + +private: + + /************************************************************************* + * Setters *************************************************************** + * They modify the local cache of configuration or detector parameters *** + *************************************************************************/ + //**initial parameters*** + + /** + * Delete and free base member parameters + */ + void deleteBaseMembers(); + + /** + * Delete and free member parameters + */ + void deleteMembers(); + + /** + * Deletes all the filter objects for single photon data + * Deals with data compression + */ + void deleteFilter(); + + /** + * Initialize base member parameters + */ + void initializeBaseMembers(); + + /** + * Initialize member parameters */ void initializeMembers(); + + /** + * Sets up all the filter objects for single photon data + * Deals with data compression + */ + void initializeFilter(); + + /** + * Create Listening Threads + * @param destroy is true to destroy all the threads + */ + int createListeningThreads(bool destroy = false); + + /** + * Create Writer Threads + * @param destroy is true to destroy all the threads + * @return OK or FAIL + */ + int createWriterThreads(bool destroy = false); + + /** + * Set Thread Priorities + */ + void setThreadPriorities(); + + /** + * Set up the Fifo Structure for processing buffers + * between listening and writer threads + * @return OK or FAIL + */ + int setupFifoStructure(); + + /** + * Creates UDP Sockets + * @return OK or FAIL + */ + int createUDPSockets(); + + + + //**detector parameters*** + /** + * structure of an eiger packet header + * subframenum subframe number for 32 bit mode (already written by firmware) + * missingpacket explicitly put to 0xFF to recognize it in file read (written by software) + * portnum 0 for the first port and 1 for the second port (written by software to file) + * dynamicrange dynamic range or bits per pixel (written by software to file) + */ + typedef struct { + unsigned char subFameNumber[4]; + unsigned char missingPacket[2]; + unsigned char portIndex[1]; + unsigned char dynamicRange[1]; + } eiger_packet_header_t; + /** + * structure of an eiger packet footer + * framenum 48 bit frame number (already written by firmware) + * packetnum packet number (already written by firmware) + */ + typedef struct { + unsigned char frameNumber[6]; + unsigned char packetNumber[2]; + } eiger_packet_footer_t; + + /** Size of 1 Frame including headers */ + int frameSize; + + /** Size of 1 buffer processed at a time */ + int bufferSize; + + /** One Packet Size including headers */ + int onePacketSize; + + /** One Packet Size without headers */ + int oneDataSize; + + /** Frame Index Mask */ + uint64_t frameIndexMask; + + /** Frame Index Offset */ + int frameIndexOffset; + + /** Packet Index Mask */ + uint64_t packetIndexMask; + + /** Footer offset from start of Packet*/ + int footerOffset; + + //***File parameters*** + /** Maximum Packets Per File **/ + int maxPacketsPerFile; + + + + //***acquisition indices parameters*** + /** Frame Number of First Frame of an Acquisition */ + uint64_t startAcquisitionIndex; + + /** Frame index at start of each real time acquisition (eg. for each scan) */ + uint64_t startFrameIndex; + + /** Current Frame Number */ + uint64_t currentFrameNumber; + + /* Acquisition started */ + bool acqStarted; + + /* Measurement started */ + bool measurementStarted; + + /** Total Frame Count listened to by listening threads */ + int totalListeningFrameCount[MAX_NUMBER_OF_LISTENING_THREADS]; + + + + + //***receiver parameters*** + /** Receiver Buffer */ + char *buffer[MAX_NUMBER_OF_LISTENING_THREADS]; + + /** Memory allocated */ + char *mem0[MAX_NUMBER_OF_LISTENING_THREADS]; + + /** Circular fifo to point to addresses of data listened to */ + CircularFifo* fifo[MAX_NUMBER_OF_LISTENING_THREADS]; + + /** Circular fifo to point to address already written and freed, to be reused */ + CircularFifo* fifoFree[MAX_NUMBER_OF_LISTENING_THREADS]; + + /** Number of Jobs Per Buffer */ + int numberofJobsPerBuffer; + + /** Fifo Depth */ + uint32_t fifoSize; + + /** Current Frame copied for Gui */ + char* latestData; + + + + //***general and listening thread parameters*** + /** Ensures if threads created successfully */ + bool threadStarted; + + /** Number of Listening Threads */ + int numberofListeningThreads; + + /** Listening Threads */ + pthread_t listeningThreads[MAX_NUMBER_OF_LISTENING_THREADS]; + + /** Semaphores Synchronizing Listening Threads */ + sem_t listenSemaphore[MAX_NUMBER_OF_LISTENING_THREADS]; + + /** Current Listening Thread Index*/ + int currentListeningThreadIndex; + + /** Mask with each bit indicating status of each listening thread */ + volatile uint32_t listeningThreadsMask; + + /** Set to self-terminate listening threads waiting for semaphores */ + bool killAllListeningThreads; + + + + //***writer thread parameters*** + /** Maximum Number of Writer Threads */ + const static int MAX_NUMBER_OF_WRITER_THREADS = 15; + + /** Number of Writer Threads */ + int numberofWriterThreads; + + /** Writer Threads */ + pthread_t writingThreads[MAX_NUMBER_OF_WRITER_THREADS]; + + /** Semaphores Synchronizing Writer Threads */ + sem_t writerSemaphore[MAX_NUMBER_OF_WRITER_THREADS]; + + /** Current Writer Thread Index*/ + int currentWriterThreadIndex; + + /** Mask with each bit indicating status of each writer thread */ + volatile uint32_t writerThreadsMask; + + /** Mask with each bit indicating file created for each writer thread*/ + volatile uint32_t createFileMask; + + /** Set to self-terminate writer threads waiting for semaphores */ + bool killAllWritingThreads; + + + + + + + //***filter parameters*** + /** Common Mode Subtraction Enable FIXME: Always false, only moench uses, Ask Anna */ + bool commonModeSubtractionEnable; + + /** Moench Common Mode Subtraction */ + moenchCommonMode *moenchCommonModeSubtraction; + + /** Single Photon Detector Object for each writer thread */ + singlePhotonDetector *singlePhotonDetectorObject[MAX_NUMBER_OF_WRITER_THREADS]; + + /** Receiver Data Object for each writer thread */ + slsReceiverData *receiverData[MAX_NUMBER_OF_WRITER_THREADS]; + + + + + //***mutex*** + /** mutex for status */ + pthread_mutex_t status_mutex; + + + + + + + + + + + + + + + + + + + + + + + + + /** * Set receiver type @@ -74,26 +442,11 @@ class UDPStandardImplementation: private virtual slsReceiverDefs, public UDPBase */ //uint32_t getStartAcquisitionIndex(); - /** - * Returns current Frame Index Caught for an entire acquisition (including all scans) - */ - //uint32_t getAcquisitionIndex(); - /** * Returns if acquisition started */ //bool getAcquistionStarted(); - /** - * Returns Frames Caught for each real time acquisition (eg. for each scan) - */ - //int getFramesCaught(); - - /** - * Returns Total Frames Caught for an entire acquisition (including all scans) - */ - //int getTotalFramesCaught(); - /** * Returns the frame index at start of each real time acquisition (eg. for each scan) */ @@ -117,71 +470,8 @@ class UDPStandardImplementation: private virtual slsReceiverDefs, public UDPBase //void resetTotalFramesCaught(); - //file parameters - /** - * Returns File Path - */ - //char* getFilePath() const; - /** - * Set File Path - * @param c file path - */ - //char* setFilePath(const char c[]); - /** - * Returns File Name - */ - //char* getFileName() const; - - /** - * Set File Name (without frame index, file index and extension) - * @param c file name - */ - //char* setFileName(const char c[]); - - /** - * Returns File Index - */ - //int getFileIndex(); - - /** - * Set File Index - * @param i file index - */ - //int setFileIndex(int i); - - /** - * Set Frame Index Needed - * @param i frame index needed - */ - //int setFrameIndexNeeded(int i); - - /** - * Set enable file write - * @param i file write enable - * Returns file write enable - */ - //int setEnableFileWrite(int i); - - /** - * Enable/disable overwrite - * @param i enable - * Returns enable over write - */ - //int setEnableOverwrite(int i); - - /** - * Returns file write enable - * 1: YES 0: NO - */ - //int getEnableFileWrite() const; - - /** - * Returns file over write enable - * 1: YES 0: NO - */ - //int getEnableOverwrite() const; //other parameters @@ -202,83 +492,7 @@ class UDPStandardImplementation: private virtual slsReceiverDefs, public UDPBase */ void setDetectorHostname(const char *detectorHostName); - /* Returns detector hostname - /returns hostname - * caller needs to deallocate the returned char array. - * if uninitialized, it must return NULL - */ - char *getDetectorHostname() const; - /** - * Set Ethernet Interface or IP to listen to - */ - void setEthernetInterface(char* c); - - /** - * Set UDP Port Number - */ - void setUDPPortNo(int p); - /** - * Set UDP Port Number - */ - void setUDPPortNo2(int p); - - /* - * Returns number of frames to receive - * This is the number of frames to expect to receiver from the detector. - * The data receiver will change from running to idle when it got this number of frames - */ - int getNumberOfFrames() const; - - /** - * set frame number if a positive number - */ - int32_t setNumberOfFrames(int32_t fnum); - - /** - * Returns scan tag - */ - int getScanTag() const; - - /** - * set scan tag if its is a positive number - */ - int32_t setScanTag(int32_t stag); - - /** - * Returns the number of bits per pixel - */ - int getDynamicRange() const; - - /** - * set dynamic range if its is a positive number - */ - int32_t setDynamicRange(int32_t dr); - - /** - * Set short frame - * @param i if shortframe i=1 - */ - int setShortFrame(int i); - - /** - * Set the variable to send every nth frame to gui - * or if 0,send frame only upon gui request - */ - int setNFrameToGui(int i); - - /** set acquisition period if a positive number - */ - int64_t setAcquisitionPeriod(int64_t index); - - /** get data compression, by saving only hits - */ - bool getDataCompression(); - - /** enabl data compression, by saving only hits - /returns if failed - */ - int enableDataCompression(bool enable); /** * enable 10Gbe @@ -337,20 +551,9 @@ private: std::cout << "[WARNING] Method " << method_name << " not implemented!" << std::endl; }; */ - /** - * Deletes all the filter objects for single photon data - */ - void deleteFilter(); - /** - * Constructs the filter for single photon data - */ - void setupFilter(); - /** - * set up fifo according to the new numjobsperthread - */ - void setupFifoStructure (); + /** * Copy frames to gui @@ -358,28 +561,6 @@ private: */ void copyFrameToGui(char* startbuf[], char* buf=NULL); - /** - * creates udp sockets - * \returns if success or fail - */ - int createUDPSockets(); - - /** - * create listening thread - * @param destroy is true to kill all threads and start again - */ - int createListeningThreads(bool destroy = false); - - /** - * create writer threads - * @param destroy is true to kill all threads and start again - */ - int createWriterThreads(bool destroy = false); - - /** - * set thread priorities - */ - void setThreadPriorities(); /** * initializes variables and creates the first file @@ -507,8 +688,7 @@ private: - /** max number of writer threads */ - const static int MAX_NUM_WRITER_THREADS = 15; + /** missing packet identifier value */ const static uint16_t missingPacketValue = 0xFFFF; @@ -517,21 +697,9 @@ private: /** UDP Socket between Receiver and Detector */ genericSocket* udpSocket[MAX_NUM_LISTENING_THREADS]; - /** max packets per file **/ - int maxPacketsPerFile; - - /** Frame Index at start of an entire acquisition (including all scans) */ - uint64_t startAcquisitionIndex; /** Complete File name */ char savefilename[MAX_STR_LENGTH]; - /* Measurement started */ - bool measurementStarted; - /* Acquisition started */ - bool acqStarted; - /** Frame index at start of each real time acquisition (eg. for each scan) */ - uint32_t startFrameIndex; - /** Actual current frame index of each time acquisition (eg. for each scan) */ uint32_t frameIndex; @@ -547,34 +715,9 @@ private: /** Number of missing packets per buffer*/ uint32_t numMissingPackets; - /** frame index mask */ - uint32_t frameIndexMask; - - /** packet index mask */ - uint32_t packetIndexMask; - - /** frame index offset */ - int frameIndexOffset; - /** Current Frame Number */ - uint64_t currframenum; - /** Previous Frame number from buffer */ int prevframenum; - /** size of one frame */ - int frameSize; - - /** buffer size. different from framesize as we wait for one packet instead of frame for eiger */ - int bufferSize; - - /** one buffer size */ - int onePacketSize; - - /** one buffer size */ - int oneDataSize; - - /** latest data */ - char* latestData; /** gui data ready */ int guiDataReady; @@ -585,71 +728,9 @@ private: /** points to the filename to send to gui */ char* guiFileName; - /** fifo size */ - unsigned int fifosize; - - /** number of jobs per thread for data compression */ - int numJobsPerThread; - - /** memory allocated for the buffer */ - char *mem0[MAX_NUM_LISTENING_THREADS]; - - /** circular fifo to store addresses of data read */ - CircularFifo* fifo[MAX_NUM_LISTENING_THREADS]; - - /** circular fifo to store addresses of data already written and ready to be resued*/ - CircularFifo* fifoFree[MAX_NUM_LISTENING_THREADS]; - - /** Receiver buffer */ - char *buffer[MAX_NUM_LISTENING_THREADS]; - - /** number of writer threads */ - int numListeningThreads; - - /** number of writer threads */ - int numWriterThreads; - - /** to know if listening and writer threads created properly */ - int thread_started; - - /** current listening thread index*/ - int currentListeningThreadIndex; - - /** current writer thread index*/ - int currentWriterThreadIndex; - - /** thread listening to packets */ - pthread_t listening_thread[MAX_NUM_LISTENING_THREADS]; - - /** thread writing packets */ - pthread_t writing_thread[MAX_NUM_WRITER_THREADS]; - - /** total frame count the listening thread has listened to */ - int totalListeningFrameCount[MAX_NUM_LISTENING_THREADS]; - - /** mask showing which listening threads are running */ - volatile uint32_t listeningthreads_mask; - - /** mask showing which writer threads are running */ - volatile uint32_t writerthreads_mask; - - /** mask showing which threads have created files*/ - volatile uint32_t createfile_mask; - - /** OK if file created was successful */ +/** OK if file created was successful */ int ret_createfile; - /** variable used to self terminate threads waiting for semaphores */ - int killAllListeningThreads; - - /** variable used to self terminate threads waiting for semaphores */ - int killAllWritingThreads; - - - - /** footer offset is different for 1g and 10g*/ - int footer_offset; - // TODO: not properly sure where to put these... /** structure of an eiger image header*/ @@ -659,19 +740,11 @@ private: //semaphores /** semaphore to synchronize writer and guireader threads */ sem_t smp; - /** semaphore to synchronize listener threads */ - sem_t listensmp[MAX_NUM_LISTENING_THREADS]; - /** semaphore to synchronize writer threads */ - sem_t writersmp[MAX_NUM_WRITER_THREADS]; - //mutex /** guiDataReady mutex */ pthread_mutex_t dataReadyMutex; - /** mutex for status */ - pthread_mutex_t status_mutex; - /** mutex for progress variable currframenum */ pthread_mutex_t progress_mutex; @@ -682,10 +755,7 @@ private: FILE *sfilefd; //filter - singlePhotonDetector *singlePhotonDet[MAX_NUM_WRITER_THREADS]; - slsReceiverData *receiverdata[MAX_NUM_WRITER_THREADS]; - moenchCommonMode *cmSub; - bool commonModeSubtractionEnable; + #ifdef MYROOT1 /** Tree where the hits are stored */ diff --git a/slsReceiverSoftware/include/receiver_defs.h b/slsReceiverSoftware/include/receiver_defs.h index 206c8b92b..bac0df2d6 100755 --- a/slsReceiverSoftware/include/receiver_defs.h +++ b/slsReceiverSoftware/include/receiver_defs.h @@ -27,8 +27,9 @@ /*#define GOTTHARD_ALIGNED_FRAME_SIZE 4096*/ #define GOTTHARD_PACKETS_PER_FRAME 2 #define GOTTHARD_ONE_PACKET_SIZE 1286 +#define GOTTHARD_ONE_DATA_SIZE 1280 #define GOTTHARD_BUFFER_SIZE (GOTTHARD_ONE_PACKET_SIZE*GOTTHARD_PACKETS_PER_FRAME) //1286*2 -#define GOTTHARD_DATA_BYTES (1280*GOTTHARD_PACKETS_PER_FRAME) //1280*2 +#define GOTTHARD_DATA_BYTES (GOTTHARD_ONE_DATA_SIZE*GOTTHARD_PACKETS_PER_FRAME) //1280*2 #define GOTTHARD_FRAME_INDEX_MASK 0xFFFFFFFE #define GOTTHARD_FRAME_INDEX_OFFSET 1 @@ -39,7 +40,7 @@ #define GOTTHARD_SHORT_PACKETS_PER_FRAME 1 -#define GOTTHARD_SHORT_ONE_PACKET_SIZE 518 +#define GOTTHARD_SHORT_ONE_PACKET_SIZE 518 #define GOTTHARD_SHORT_BUFFER_SIZE 518 #define GOTTHARD_SHORT_DATABYTES 512 #define GOTTHARD_SHORT_FRAME_INDEX_MASK 0xFFFFFFFF @@ -75,8 +76,9 @@ /*#define MOENCH_ALIGNED_FRAME_SIZE 65536*/ #define MOENCH_PACKETS_PER_FRAME 40 #define MOENCH_ONE_PACKET_SIZE 1286 +#define MOENCH_ONE_DATA_SIZE 1280 #define MOENCH_BUFFER_SIZE (MOENCH_ONE_PACKET_SIZE*MOENCH_PACKETS_PER_FRAME) //1286*40 -#define MOENCH_DATA_BYTES (1280*MOENCH_PACKETS_PER_FRAME) //1280*40 +#define MOENCH_DATA_BYTES (MOENCH_ONE_DATA_SIZE*MOENCH_PACKETS_PER_FRAME) //1280*40 #define MOENCH_FRAME_INDEX_MASK 0xFFFFFF00 #define MOENCH_FRAME_INDEX_OFFSET 8 diff --git a/slsReceiverSoftware/include/slsReceiver.h b/slsReceiverSoftware/include/slsReceiver.h index 4eb024776..e76ea7d1b 100644 --- a/slsReceiverSoftware/include/slsReceiver.h +++ b/slsReceiverSoftware/include/slsReceiver.h @@ -8,7 +8,6 @@ #include "slsReceiverTCPIPInterface.h" #include "UDPInterface.h" -//#include "UDPBaseImplementation.h" #include "receiver_defs.h" #include "MySocketTCP.h" diff --git a/slsReceiverSoftware/include/sls_receiver_defs.h b/slsReceiverSoftware/include/sls_receiver_defs.h index 11641334a..04b8b19fb 100755 --- a/slsReceiverSoftware/include/sls_receiver_defs.h +++ b/slsReceiverSoftware/include/sls_receiver_defs.h @@ -111,6 +111,16 @@ public: }; + /** returns string from enabled/disabled + \param b true or false + \returns string enabled, disabled + */ + static string stringEnable(bool b){\ + if(b) return string("enabled"); \ + else return string("disabled"); \ + }; + + #ifdef __cplusplus protected: diff --git a/slsReceiverSoftware/src/UDPBaseImplementation.cpp b/slsReceiverSoftware/src/UDPBaseImplementation.cpp index e16060865..0c1c30248 100644 --- a/slsReceiverSoftware/src/UDPBaseImplementation.cpp +++ b/slsReceiverSoftware/src/UDPBaseImplementation.cpp @@ -4,25 +4,12 @@ * @short does all the functions for a receiver, set/get parameters, start/stop etc. ***********************************************/ - #include "UDPBaseImplementation.h" -#include "moench02ModuleData.h" -#include "gotthardModuleData.h" -#include "gotthardShortModuleData.h" - - -#include // SIGINT #include // stat -#include // socket(), bind(), listen(), accept(), shut down -#include // sock_addr_in, htonl, INADDR_ANY -#include // exit() -#include //set precision -#include //munmap -#include #include - +#include using namespace std; @@ -32,7 +19,11 @@ using namespace std; * They access local cache of configuration or detector parameters ******* *************************************************************************/ UDPBaseImplementation::UDPBaseImplementation(){ + FILE_LOG(logDEBUG) << __AT__ << " starting"; + + cout << "Info: Initializing base members" << endl; //**detector parameters*** + myDetectorType = GENERIC; strcpy(detHostname,""); packetsPerFrame = 0; acquisitionPeriod = 0; @@ -51,7 +42,7 @@ UDPBaseImplementation::UDPBaseImplementation(){ } //***file parameters*** - strcpy(fileName,""); + strcpy(fileName,"run"); strcpy(filePath,""); fileIndex = 0; scanTag = 0; @@ -78,9 +69,17 @@ UDPBaseImplementation::UDPBaseImplementation(){ pAcquisitionFinished = NULL; rawDataReadyCallBack = NULL; pRawDataReady = NULL; -}; +} -UDPBaseImplementation::~UDPBaseImplementation(){}; +UDPBaseImplementation::~UDPBaseImplementation(){ + FILE_LOG(logDEBUG) << __AT__ << " starting"; + + cout << "Info: Deleting base member pointers" << endl; + if(detHostname) {delete [] detHostname; detHostname = NULL;} + if(eth) {delete [] eth; eth = NULL;} + if(fileName) {delete [] fileName; fileName = NULL;} + if(filePath) {delete [] filePath; filePath = NULL;} +} /************************************************************************* @@ -157,9 +156,9 @@ int64_t UDPBaseImplementation::getAcquisitionIndex() const{ /***connection parameters***/ -uint32_t UDPBaseImplementation::getUDPPortNo() const{ FILE_LOG(logDEBUG) << __AT__ << " starting"; return udpPortNum[0];} +uint32_t UDPBaseImplementation::getUDPPortNumber() const{ FILE_LOG(logDEBUG) << __AT__ << " starting"; return udpPortNum[0];} -uint32_t UDPBaseImplementation::getUDPPortNo2() const{ FILE_LOG(logDEBUG) << __AT__ << " starting"; return udpPortNum[1];} +uint32_t UDPBaseImplementation::getUDPPortNumber2() const{ FILE_LOG(logDEBUG) << __AT__ << " starting"; return udpPortNum[1];} char *UDPBaseImplementation::getEthernetInterface() const{ FILE_LOG(logDEBUG) << __AT__ << " starting"; @@ -205,7 +204,7 @@ void UDPBaseImplementation::setBottomEnable(const bool b){ FILE_LOG(logDEBUG) << __AT__ << " starting"; bottomEnable = b; - FILE_LOG(logINFO) << "Bottom Enable:" << bottomEnable; + FILE_LOG(logINFO) << "Bottom Enable: " << stringEnable(bottomEnable); } @@ -255,41 +254,46 @@ void UDPBaseImplementation::setFrameIndexEnable(const bool b){ FILE_LOG(logDEBUG) << __AT__ << " starting"; frameIndexEnable = b; - FILE_LOG(logINFO) << "Frame Index Enable:" << frameIndexEnable; + FILE_LOG(logINFO) << "Frame Index Enable: " << stringEnable(frameIndexEnable); } void UDPBaseImplementation::setFileWriteEnable(const bool b){ FILE_LOG(logDEBUG) << __AT__ << " starting"; fileWriteEnable = b; - FILE_LOG(logINFO) << "File Write Enable:" << fileWriteEnable; + FILE_LOG(logINFO) << "File Write Enable: " << stringEnable(fileWriteEnable); } void UDPBaseImplementation::setOverwriteEnable(const bool b){ FILE_LOG(logDEBUG) << __AT__ << " starting"; overwriteEnable = b; - FILE_LOG(logINFO) << "Overwrite Enable:" << overwriteEnable; + FILE_LOG(logINFO) << "Overwrite Enable: " << stringEnable(overwriteEnable); } -void UDPBaseImplementation::setDataCompressionEnable(const bool b){ +int UDPBaseImplementation::setDataCompressionEnable(const bool b){ FILE_LOG(logDEBUG) << __AT__ << " starting"; dataCompressionEnable = b; - FILE_LOG(logINFO) << "Data Compression Enable:" << dataCompressionEnable; -} + FILE_LOG(logINFO) << "Data Compression Enable: " << stringEnable(dataCompressionEnable); + //overridden methods might return FAIL + return OK; +} /***connection parameters***/ -void UDPBaseImplementation::setUDPPortNo(const uint32_t i){ +void UDPBaseImplementation::setUDPPortNumber(const uint32_t i){ FILE_LOG(logDEBUG) << __AT__ << " starting"; - udpPortNum[0] = i; + if(bottomEnable) + udpPortNum[1] = i; + else + udpPortNum[0] = i; FILE_LOG(logINFO) << "udpPortNum[0]:" << udpPortNum[0]; } -void UDPBaseImplementation::setUDPPortNo2(const uint32_t i){ +void UDPBaseImplementation::setUDPPortNumber2(const uint32_t i){ FILE_LOG(logDEBUG) << __AT__ << " starting"; udpPortNum[1] = i; @@ -304,26 +308,32 @@ void UDPBaseImplementation::setEthernetInterface(const char* c){ } -/***connection parameters***/ +/***acquisition parameters***/ void UDPBaseImplementation::setShortFrameEnable(const int i){ FILE_LOG(logDEBUG) << __AT__ << " starting"; shortFrameEnable = i; - FILE_LOG(logINFO) << "Short Frame Enable:" << shortFrameEnable; + FILE_LOG(logINFO) << "Short Frame Enable: " << stringEnable(shortFrameEnable); } -void UDPBaseImplementation::setFrameToGuiFrequency(const uint32_t i){ +int UDPBaseImplementation::setFrameToGuiFrequency(const uint32_t i){ FILE_LOG(logDEBUG) << __AT__ << " starting"; FrameToGuiFrequency = i; FILE_LOG(logINFO) << "Frame To Gui Frequency:" << FrameToGuiFrequency; + + //overrridden child classes might return FAIL + return OK; } -void UDPBaseImplementation::setAcquisitionPeriod(const uint64_t i){ +int UDPBaseImplementation::setAcquisitionPeriod(const uint64_t i){ FILE_LOG(logDEBUG) << __AT__ << " starting"; acquisitionPeriod = i; FILE_LOG(logINFO) << "Acquisition Period:" << acquisitionPeriod; + + //overrridden child classes might return FAIL + return OK; } void UDPBaseImplementation::setNumberOfFrames(const uint64_t i){ @@ -333,20 +343,25 @@ void UDPBaseImplementation::setNumberOfFrames(const uint64_t i){ FILE_LOG(logINFO) << "Number of Frames:" << numberOfFrames; } -void UDPBaseImplementation::setDynamicRange(const uint32_t i){ +int UDPBaseImplementation::setDynamicRange(const uint32_t i){ FILE_LOG(logDEBUG) << __AT__ << " starting"; dynamicRange = i; FILE_LOG(logINFO) << "Dynamic Range:" << dynamicRange; + + //overrridden child classes might return FAIL + return OK; } -void UDPBaseImplementation::setTenGigaEnable(const bool b){ +int UDPBaseImplementation::setTenGigaEnable(const bool b){ FILE_LOG(logDEBUG) << __AT__ << " starting"; tengigaEnable = b; - FILE_LOG(logINFO) << "Ten Giga Enable:" << tengigaEnable; -} + FILE_LOG(logINFO) << "Ten Giga Enable: " << stringEnable(tengigaEnable); + //overridden functions might return FAIL + return OK; +} /************************************************************************* @@ -354,11 +369,13 @@ void UDPBaseImplementation::setTenGigaEnable(const bool b){ * They may modify the status of the receiver **************************** *************************************************************************/ + /***initial functions***/ int UDPBaseImplementation::setDetectorType(const slsReceiverDefs::detectorType d){ FILE_LOG(logDEBUG) << __AT__ << " starting"; myDetectorType = d; + //if eiger, set numberofListeningThreads = 2; FILE_LOG(logINFO) << "Detector Type:" << slsDetectorBase::getDetectorType(d); return OK; } diff --git a/slsReceiverSoftware/src/UDPInterface.cpp b/slsReceiverSoftware/src/UDPInterface.cpp index 952098811..937035845 100644 --- a/slsReceiverSoftware/src/UDPInterface.cpp +++ b/slsReceiverSoftware/src/UDPInterface.cpp @@ -5,11 +5,11 @@ ***********************************************/ - -#include #include +#include using namespace std; + #include "UDPInterface.h" #include "UDPBaseImplementation.h" #include "UDPStandardImplementation.h" diff --git a/slsReceiverSoftware/src/UDPStandardImplementation.cpp b/slsReceiverSoftware/src/UDPStandardImplementation.cpp index dfbe51493..0f4290c9c 100644 --- a/slsReceiverSoftware/src/UDPStandardImplementation.cpp +++ b/slsReceiverSoftware/src/UDPStandardImplementation.cpp @@ -10,24 +10,920 @@ #include "gotthardModuleData.h" #include "gotthardShortModuleData.h" - -#include // SIGINT -#include // stat -#include // socket(), bind(), listen(), accept(), shut down -#include // sock_addr_in, htonl, INADDR_ANY +//#include // socket(), bind(), listen(), accept(), shut down +//#include // sock_addr_in, htonl, INADDR_ANY #include // exit() -#include //set precision -#include //munmap +#include //set precision for printing parameters for create new file +#include //map +//#include //munmap - - -#include #include +#include #include using namespace std; - #define WRITE_HEADERS + +/************************************************************************* + * Constructor & Destructor ********************************************** + * They access local cache of configuration or detector parameters ******* + *************************************************************************/ + +UDPStandardImplementation::UDPStandardImplementation(){ + FILE_LOG(logDEBUG) << __AT__ << " called"; + + initializeMembers(); +} + +UDPStandardImplementation::~UDPStandardImplementation(){ + FILE_LOG(logDEBUG) << __AT__ << " called"; + + deleteMembers(); +} + + +/************************************************************************* + * Setters *************************************************************** + * They modify the local cache of configuration or detector parameters *** + *************************************************************************/ + +/***initial parameters***/ +void UDPStandardImplementation::deleteBaseMembers(){ + FILE_LOG(logDEBUG) << __AT__ << " starting"; + + UDPBaseImplementation::~UDPBaseImplementation(); +} + +void UDPStandardImplementation::deleteMembers(){ + FILE_LOG(logDEBUG) << __AT__ << " starting"; + + cout << "Info: Deleting member pointers" << endl; + //filter + deleteFilter(); + //kill threads + if(threadStarted){ + createListeningThreads(true); + createWriterThreads(true); + } + //shutdownudpsockets + //close file + if(latestData) {delete[] latestData; latestData = NULL;} +} + +void UDPStandardImplementation::deleteFilter(){ + FILE_LOG(logDEBUG) << __AT__ << " starting"; + + moenchCommonModeSubtraction = NULL; + for(int i=0; i(receiverData[i], csize, sigma, sign, commonModeSubtractionEnable); +} + + + +int UDPStandardImplementation::createListeningThreads(bool destroy){ + FILE_LOG(logDEBUG) << __AT__ << " starting"; + + //reset masks + killAllListeningThreads = false; + pthread_mutex_lock(&status_mutex); + listeningThreadsMask = 0x0; + pthread_mutex_unlock(&(status_mutex)); + + //destroy + if(destroy){ + cout << "Info: Destroying Listening Thread(s)" << endl; + + killAllListeningThreads = true; + for(int i = 0; i < numberofListeningThreads; ++i){ + sem_post(&listenSemaphore[i]); + pthread_join(listeningThreads[i],NULL); + cout <<"."< MAX_JOBS_PER_THREAD) + numberofJobsPerBuffer = MAX_JOBS_PER_THREAD; + else if (i < 1) + numberofJobsPerBuffer = 1; + else + numberofJobsPerBuffer = i; + + } + cout << "Info: Number of Frames per buffer:" << numberofJobsPerBuffer << endl; + } + + //set fifo depth + //eiger listens to 1 packet at a time and size changes depending on packets per frame + if(myDetectorType == EIGER) + fifoSize = EIGER_FIFO_SIZE * packetsPerFrame; + else{ + fifoSize = GOTTHARD_FIFO_SIZE; + if(myDetectorType == MOENCH) + fifoSize = MOENCH_FIFO_SIZE; + else if(myDetectorType == PROPIX) + fifoSize = PROPIX_FIFO_SIZE; + //reduce fifo depth if more frames listened to at a time + if(fifoSize % numberofJobsPerBuffer) + fifoSize = (fifoSize/numberofJobsPerBuffer)+1; + else + fifoSize = fifoSize/numberofJobsPerBuffer; + } +#ifdef VERBOSE + cout << "Info: Fifo Depth:" << fifoSize << endl; +#endif + + + //do not rebuild fifo structure if it is the same + if((oldNumberofJobsPerBuffer == numberofJobsPerBuffer) && (oldFifoSize == fifoSize)) + return OK; + + + //set up fifo structure + for(int i=0;iisEmpty()) + fifoFree[i]->pop(buffer[i]); +#ifdef FIFO_DEBUG + cprintf(GREEN,"%d fifostructure popped from fifofree %p\n", i, (void*)(buffer[i])); +#endif + delete fifoFree[i]; + } + if(fifo[i]) delete fifo[i]; + if(mem0[i]) free(mem0[i]); + + //creating + fifoFree[i] = new CircularFifo(fifoSize); + fifo[i] = new CircularFifo(fifoSize); + + //allocate memory + mem0[i] = (char*)malloc((bufferSize * numberofJobsPerBuffer + HEADER_SIZE_NUM_TOT_PACKETS) * fifoSize); + if (mem0[i] == NULL){ + cprintf(BG_RED,"Error: Could not allocate memory for listening \n"); + return FAIL; + } + + //push free address into fifoFree + buffer[i]=mem0[i]; + while (buffer[i] < (mem0[i]+(bufferSize * numberofJobsPerBuffer + HEADER_SIZE_NUM_TOT_PACKETS) * (fifoSize-1))) { + fifoFree[i]->push(buffer[i]); +#ifdef FIFO_DEBUG + cprintf(BLUE,"%d fifostructure free pushed into fifofree %p\n", i, (void*)(buffer[i])); +#endif + buffer[i] += (bufferSize * numberofJobsPerBuffer + HEADER_SIZE_NUM_TOT_PACKETS); + } + } + cout << "Info: Fifo structure(s) reconstructed" << endl; +} + + + + +int UDPStandardImplementation::createUDPSockets(){ + FILE_LOG(logDEBUG) << __AT__ << " called"; + + + + + return OK; +} + + + + +void UDPStandardImplementation::configure(map config_map){ + FILE_LOG(logDEBUG) << __AT__ << " starting"; + + map::const_iterator pos; + pos = config_map.find("mode"); + if (pos != config_map.end() ){ + int b; + if(!sscanf(pos->second.c_str(), "%d", &b)){ + cout << "Warning: Could not parse mode. Assuming top mode." << endl; + b = 0; + } + bottomEnable = b!= 0; + cout << "Info: Bottom Enable: " << stringEnable(bottomEnable) << endl; + } + +} + + +/***file parameters***/ +int UDPStandardImplementation::setDataCompressionEnable(const bool b){ + FILE_LOG(logDEBUG) << __AT__ << " starting"; + + cout << "Info: Setting up Data Compression Enable to " << stringEnable(b); +#ifdef MYROOT1 + cout << " WITH ROOT" << endl; +#else + cout << " WITHOUT ROOT" << endl; +#endif + + //set data compression enable + dataCompressionEnable = b; + + //-- create writer threads depending on enable + pthread_mutex_lock(&status_mutex); + writerThreadsMask = 0x0; + pthread_mutex_unlock(&(status_mutex)); + + createWriterThreads(true); + if(b) + numberofWriterThreads = MAX_NUMBER_OF_WRITER_THREADS; + else + numberofWriterThreads = 1; + if(createWriterThreads() == FAIL){ + cprintf(BG_RED,"Error: Could not create writer threads\n"); + return FAIL; + } + //-- end of create writer threads + setThreadPriorities(); + + //filter + deleteFilter(); + if(b) + initializeFilter(); + + cout << "Info: Data Compression " << stringEnable(dataCompressionEnable) << endl; + + return OK; +} + + +/***acquisition parameters***/ +void UDPStandardImplementation::setShortFrameEnable(const int i){ + FILE_LOG(logDEBUG) << __AT__ << " called"; + + shortFrameEnable = i; + + if(shortFrameEnable!=-1){ + frameSize = GOTTHARD_SHORT_BUFFER_SIZE; + bufferSize = GOTTHARD_SHORT_BUFFER_SIZE; + onePacketSize = GOTTHARD_SHORT_BUFFER_SIZE; + oneDataSize = GOTTHARD_SHORT_DATABYTES; + maxPacketsPerFile = SHORT_MAX_FRAMES_PER_FILE * GOTTHARD_SHORT_PACKETS_PER_FRAME; + packetsPerFrame = GOTTHARD_SHORT_PACKETS_PER_FRAME; + frameIndexMask = GOTTHARD_SHORT_FRAME_INDEX_MASK; + frameIndexOffset = GOTTHARD_SHORT_FRAME_INDEX_OFFSET; + packetIndexMask = GOTTHARD_SHORT_PACKET_INDEX_MASK; + + }else{ + frameSize = GOTTHARD_BUFFER_SIZE; + bufferSize = GOTTHARD_BUFFER_SIZE; + onePacketSize = GOTTHARD_ONE_PACKET_SIZE; + oneDataSize = GOTTHARD_ONE_DATA_SIZE; + maxPacketsPerFile = MAX_FRAMES_PER_FILE * GOTTHARD_PACKETS_PER_FRAME; + packetsPerFrame = GOTTHARD_PACKETS_PER_FRAME; + frameIndexMask = GOTTHARD_FRAME_INDEX_MASK; + frameIndexOffset = GOTTHARD_FRAME_INDEX_OFFSET; + packetIndexMask = GOTTHARD_PACKET_INDEX_MASK; + } + + //filter + deleteFilter(); + if(dataCompressionEnable) + initializeFilter(); + + cout << "Info: Short Frame Enable set to " << shortFrameEnable << endl; +} + + +int UDPStandardImplementation::setFrameToGuiFrequency(const uint32_t i){ + FILE_LOG(logDEBUG) << __AT__ << " called"; + + if(i >= 0){ + FrameToGuiFrequency = i; + if(setupFifoStructure() == FAIL) + return FAIL; + } + + cout << "Info: Frame to Gui Frequency set to " << FrameToGuiFrequency << endl; + + return OK; +} + + +int UDPStandardImplementation::setAcquisitionPeriod(int64_t i){ + FILE_LOG(logDEBUG) << __AT__ << " called"; + + if(i >= 0){ + acquisitionPeriod = i; + if(setupFifoStructure() == FAIL) + return FAIL; + } + + cout << "Info: Acquisition Period set to " << acquisitionPeriod << endl; + + + return OK; +} + +int UDPStandardImplementation::setDynamicRange(const uint32_t i){ + FILE_LOG(logDEBUG) << __AT__ << " called"; + + int oldDynamicRange = dynamicRange; + + cout << "Info: Setting Dynamic Range to " << i << endl; + dynamicRange = i; + + if(myDetectorType == EIGER){ + + //set parameters depending on new dynamic range. + packetsPerFrame = (tengigaEnable ? EIGER_TEN_GIGA_CONSTANT : EIGER_ONE_GIGA_CONSTANT) + * dynamicRange * EIGER_MAX_PORTS; + frameSize = onePacketSize * packetsPerFrame; + maxPacketsPerFile = EIGER_MAX_FRAMES_PER_FILE * packetsPerFrame; + + //new dynamic range, then restart threads and resetup fifo structure + if(oldDynamicRange != dynamicRange){ + + //delete threads + if(threadStarted){ + createListeningThreads(true); + createWriterThreads(true); + } + + //gui buffer + if(latestData){delete[] latestData; latestData = NULL;} + latestData = new char[frameSize]; + + //restructure fifo + if(setupFifoStructure() == FAIL) + return FAIL; + + //create threads + if(createListeningThreads() == FAIL){ + cprintf(BG_RED,"Error: Could not create listening thread\n"); + return FAIL; + } + if(createWriterThreads() == FAIL){ + cprintf(BG_RED,"Error: Could not create writer threads\n"); + return FAIL; + } + setThreadPriorities(); + } + + } + + cout << "Info: Dynamic Range set to " << dynamicRange << endl; + + return OK; +} + + + +int UDPStandardImplementation::setTenGigaEnable(const bool b){ + FILE_LOG(logDEBUG) << __AT__ << " called"; + + cout << "Info: Setting Ten Giga to " << string(b) << endl; + bool oldTenGigaEnable = tengigaEnable; + tengigaEnable = b; + + if(myDetectorType == EIGER){ + + //set parameters depending on 10g + if(tengigaEnable){ + packetsPerFrame = EIGER_TEN_GIGA_CONSTANT * dynamicRange * EIGER_MAX_PORTS; + onePacketSize = EIGER_TEN_GIGA_ONE_PACKET_SIZE; + oneDataSize = EIGER_TEN_GIGA_ONE_DATA_SIZE; + }else{ + packetsPerFrame = EIGER_ONE_GIGA_CONSTANT * dynamicRange * EIGER_MAX_PORTS; + onePacketSize = EIGER_ONE_GIGA_ONE_PACKET_SIZE; + oneDataSize = EIGER_ONE_GIGA_ONE_DATA_SIZE; + } + frameSize = onePacketSize * packetsPerFrame; + bufferSize = onePacketSize; + maxPacketsPerFile = EIGER_MAX_FRAMES_PER_FILE * packetsPerFrame; + + FILE_LOG(logDEBUG1) << dec << + "packetsPerFrame:" << packetsPerFrame << + "\nonePacketSize:" << onePacketSize << + "\noneDataSize:" << oneDataSize << + "\nframesize:" << frameSize << + "\nbufferSize:" << bufferSize << + "\nmaxPacketsPerFile:" << maxPacketsPerFile << endl; + + + + //new enable, then restart threads and resetup fifo structure + if(oldTenGigaEnable != tengigaEnable){ + + //delete threads + if(threadStarted){ + createListeningThreads(true); + createWriterThreads(true); + } + + //gui buffer + if(latestData){delete[] latestData; latestData = NULL;} + latestData = new char[frameSize]; + + //restructure fifo + if(setupFifoStructure() == FAIL) + return FAIL; + + //create threads + if(createListeningThreads() == FAIL){ + cprintf(BG_RED,"Error: Could not create listening thread\n"); + return FAIL; + } + if(createWriterThreads() == FAIL){ + cprintf(BG_RED,"Error: Could not create writer threads\n"); + return FAIL; + } + setThreadPriorities(); + } + + } + + cout << "Info: Ten Giga " << string(tengigaEnable) << endl; + + return OK; +} + + + +/************************************************************************* + * Behavioral functions*************************************************** + * They may modify the status of the receiver **************************** + *************************************************************************/ + + +/***initial functions***/ +int UDPStandardImplementation::setDetectorType(const slsReceiverDefs::detectorType d){ + FILE_LOG(logDEBUG) << __AT__ << " called"; + + cout << "Setting receiver type ..." << endl; + + deleteBaseMembers(); + deleteMembers(); + initializeBaseMembers(); + initializeMembers(); + + myDetectorType = d; + switch(myDetectorType){ + case GOTTHARD: + case PROPIX: + case MOENCH: + case EIGER: + case JUNGFRAUCTB: + case JUNGFRAU: + cout << "Info: ***** This is a " << slsDetectorBase::getDetectorType(d) << " Receiver *****" << endl; + break; + default: + cout << "Error: This is an unknown receiver type " << (int)d << endl; + return FAIL; + } + + //set detector specific variables + switch(myDetectorType){ + case GOTTHARD: + packetsPerFrame = GOTTHARD_PACKETS_PER_FRAME; + onePacketSize = GOTTHARD_ONE_PACKET_SIZE; + oneDataSize = GOTTHARD_ONE_DATA_SIZE; + frameSize = GOTTHARD_BUFFER_SIZE; + bufferSize = GOTTHARD_BUFFER_SIZE; + frameIndexMask = GOTTHARD_FRAME_INDEX_MASK; + frameIndexOffset = GOTTHARD_FRAME_INDEX_OFFSET; + packetIndexMask = GOTTHARD_PACKET_INDEX_MASK; + maxPacketsPerFile = MAX_FRAMES_PER_FILE * GOTTHARD_PACKETS_PER_FRAME; + fifoSize = GOTTHARD_FIFO_SIZE; + //footerOffset = Not applicable; + break; + case PROPIX: + packetsPerFrame = PROPIX_PACKETS_PER_FRAME; + onePacketSize = PROPIX_ONE_PACKET_SIZE; + //oneDataSize = Not applicable; + frameSize = PROPIX_BUFFER_SIZE; + bufferSize = PROPIX_BUFFER_SIZE; + frameIndexMask = PROPIX_FRAME_INDEX_MASK; + frameIndexOffset = PROPIX_FRAME_INDEX_OFFSET; + packetIndexMask = PROPIX_PACKET_INDEX_MASK; + maxPacketsPerFile = MAX_FRAMES_PER_FILE * PROPIX_PACKETS_PER_FRAME; + fifoSize = PROPIX_FIFO_SIZE; + //footerOffset = Not applicable; + break; + case MOENCH: + packetsPerFrame = MOENCH_PACKETS_PER_FRAME; + onePacketSize = MOENCH_ONE_PACKET_SIZE; + oneDataSize = MOENCH_ONE_DATA_SIZE; + frameSize = MOENCH_BUFFER_SIZE; + bufferSize = MOENCH_BUFFER_SIZE; + frameIndexMask = MOENCH_FRAME_INDEX_MASK; + frameIndexOffset = MOENCH_FRAME_INDEX_OFFSET; + packetIndexMask = MOENCH_PACKET_INDEX_MASK; + maxPacketsPerFile = MOENCH_MAX_FRAMES_PER_FILE * MOENCH_PACKETS_PER_FRAME; + fifoSize = MOENCH_FIFO_SIZE; + //footerOffset = Not applicable; + break; + case EIGER: + //assuming 1G in the beginning + packetsPerFrame = EIGER_ONE_GIGA_CONSTANT * dynamicRange * EIGER_MAX_PORTS; + onePacketSize = EIGER_ONE_GIGA_ONE_PACKET_SIZE; + oneDataSize = EIGER_ONE_GIGA_ONE_DATA_SIZE; + frameSize = onePacketSize * packetsPerFrame; + bufferSize = onePacketSize; + frameIndexMask = EIGER_FRAME_INDEX_MASK; + frameIndexOffset = EIGER_FRAME_INDEX_OFFSET; + packetIndexMask = EIGER_PACKET_INDEX_MASK; + maxPacketsPerFile = EIGER_MAX_FRAMES_PER_FILE * packetsPerFrame; + fifoSize = EIGER_FIFO_SIZE; + footerOffset = EIGER_PACKET_HEADER_SIZE + oneDataSize; + break; + case JUNGFRAUCTB: + case JUNGFRAU: + packetsPerFrame = JCTB_PACKETS_PER_FRAME; + onePacketSize = JCTB_ONE_PACKET_SIZE; + //oneDataSize = Not applicable; + frameSize = JCTB_BUFFER_SIZE; + bufferSize = JCTB_BUFFER_SIZE; + frameIndexMask = JCTB_FRAME_INDEX_MASK; + frameIndexOffset = JCTB_FRAME_INDEX_OFFSET; + packetIndexMask = JCTB_PACKET_INDEX_MASK; + maxPacketsPerFile = JFCTB_MAX_FRAMES_PER_FILE * JCTB_PACKETS_PER_FRAME; + fifoSize = JCTB_FIFO_SIZE; + //footerOffset = Not applicable; + break; + } + + //delete threads and set number of listening threads + if(myDetectorType == EIGER){ + pthread_mutex_lock(&status_mutex); + listeningThreadsMask = 0x0; + pthread_mutex_unlock(&(status_mutex)); + if(threadStarted) + createListeningThreads(true); + numberofListeningThreads = MAX_NUMBER_OF_LISTENING_THREADS; + } + + //set up fifo structure -1 for numberofJobsPerBuffer ensure it is done + numberofJobsPerBuffer = -1; + setupFifoStructure(); + + //create threads + if(createListeningThreads() == FAIL){ + cprintf(BG_RED,"Error: Could not create listening thread\n"); + exit (-1); + } + if(createWriterThreads() == FAIL){ + cprintf(BG_RED,"Error: Could not create writer threads\n"); + exit (-1); + } + setThreadPriorities(); + + //allocate for latest data (frame copy for gui) + latestData = new char[frameSize]; + + cout << " Detector type set to " << slsDetectorBase::getDetectorType(d) << endl; + cout << "Ready..." << endl; + + return OK; +} + + +/***acquisition functions***/ +void UDPStandardImplementation::resetAcquisitionCount(){ + FILE_LOG(logDEBUG) << __AT__ << " starting"; + + totalPacketsCaught = 0; + acqStarted = false; + startAcquisitionIndex = 0; + + cout << "Info: Acquisition Count has been reset" << endl; +} + + +int UDPStandardImplementation::startReceiver(char *c=NULL){ + FILE_LOG(logDEBUG) << __AT__ << " called"; + + cout << "Info: Starting Receiver" << endl; + + //reset measurement variables + measurementStarted = false; + startFrameIndex = 0; + if(!acqStarted) + currentFrameNumber = 0; //has to be zero to add to startframeindex for each scan + for(int i = 0; i < numberofListeningThreads; ++i) + totalListeningFrameCount[i] = 0; + + //create UDP sockets + if(createUDPSockets() == FAIL){ + + } + + return OK; +} + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + UDPStandardImplementation::UDPStandardImplementation(){ @@ -36,7 +932,7 @@ UDPStandardImplementation::UDPStandardImplementation(){ latestData = NULL; guiFileName = NULL; tengigaEnable = 0; - footer_offset = 0; + for(int i=0;i config_map){ - FILE_LOG(logWARNING) << __AT__ << " called"; - - map::const_iterator pos; - pos = config_map.find("mode"); - if (pos != config_map.end() ){ - int b; - if(!sscanf(pos->second.c_str(), "%d", &b)){ - cout << "Warning: Could not parse mode. Assuming top mode." << endl; - b = 0; - } - bottom = b!= 0; - cout << "bottom:"<< bottom << endl; - } -}; void UDPStandardImplementation::initializeMembers(){ myDetectorType = GENERIC; - maxPacketsPerFile = 0; enableFileWrite = 1; overwrite = 1; fileIndex = 0; scanTag = 0; frameIndexNeeded = 0; - acqStarted = false; - measurementStarted = false; - startFrameIndex = 0; + + frameIndex = 0; packetsCaught = 0; totalPacketsCaught = 0; @@ -119,7 +998,7 @@ void UDPStandardImplementation::initializeMembers(){ numMissingPackets = 0; startAcquisitionIndex = 0; acquisitionIndex = 0; - packetsPerFrame = 0; + frameIndexMask = 0; packetIndexMask = 0; frameIndexOffset = 0; @@ -129,39 +1008,24 @@ void UDPStandardImplementation::initializeMembers(){ shortFrame = -1; currframenum = 0; prevframenum = 0; - frameSize = 0; - bufferSize = 0; - onePacketSize = 0; - oneDataSize = 0; + guiDataReady = 0; nFrameToGui = 0; - fifosize = 0; - numJobsPerThread = -1; dataCompression = false; numListeningThreads = 1; numWriterThreads = 1; thread_started = 0; - currentListeningThreadIndex = -1; - currentWriterThreadIndex = -1; - for(int i=0;i=0) - fileIndex = i; - return getFileIndex(); -} -*/ -/* -int UDPStandardImplementation::setFrameIndexNeeded(int i){ - frameIndexNeeded = i; - return frameIndexNeeded; -} -*/ -/* -int UDPStandardImplementation::getEnableFileWrite() const{ - return enableFileWrite; -} -*/ - -/* -int UDPStandardImplementation::setEnableFileWrite(int i){ - enableFileWrite=i; - return getEnableFileWrite(); -} -*/ - -/* -int UDPStandardImplementation::getEnableOverwrite() const{ - return overwrite; -} -*/ - -/* -int UDPStandardImplementation::setEnableOverwrite(int i){ - overwrite=i; - return getEnableOverwrite(); -} -*/ /*other parameters*/ -slsReceiverDefs::runStatus UDPStandardImplementation::getStatus() const{ - FILE_LOG(logDEBUG) << __AT__ << " called, status: " << status; - - - return status; -} - - -void UDPStandardImplementation::setDetectorHostname(const char *detectorHostName){ - if(strlen(detectorHostName)) - strcpy(detHostname,detectorHostName); -} - - -char *UDPStandardImplementation::getDetectorHostname() const{ - if(!strlen(detHostname)) - return NULL; - return (char*)detHostname; -} - -void UDPStandardImplementation::setEthernetInterface(char* c){ FILE_LOG(logDEBUG) << __AT__ << " called"; - - strcpy(eth,c); -} - - -void UDPStandardImplementation::setUDPPortNo(int p){ -FILE_LOG(logDEBUG) << __AT__ << " called"; - server_port[0] = p; -} - - -void UDPStandardImplementation::setUDPPortNo2(int p){ -FILE_LOG(logDEBUG) << __AT__ << " called"; - server_port[1] = p; -} - - -int UDPStandardImplementation::getNumberOfFrames() const { - return numberOfFrames; -} - - -int32_t UDPStandardImplementation::setNumberOfFrames(int32_t fnum){ FILE_LOG(logDEBUG) << __AT__ << " called"; - - if(fnum >= 0) - numberOfFrames = fnum; - - return getNumberOfFrames(); -} - -int UDPStandardImplementation::getScanTag() const{ - return scanTag; -} - - -int32_t UDPStandardImplementation::setScanTag(int32_t stag){ FILE_LOG(logDEBUG) << __AT__ << " called"; - - if(stag >= 0) - scanTag = stag; - - return getScanTag(); -} - - -int UDPStandardImplementation::getDynamicRange() const{ - return dynamicRange; -} - -int32_t UDPStandardImplementation::setDynamicRange(int32_t dr){ FILE_LOG(logDEBUG) << __AT__ << " called"; - - int olddr = dynamicRange; - - if(dr >= 0){ - cout << "Setting Dynamic Range to " << dr << endl; - - dynamicRange = dr; - - if(myDetectorType == EIGER){ - - - if(!tengigaEnable){ - packetsPerFrame = EIGER_ONE_GIGA_CONSTANT * dynamicRange * EIGER_MAX_PORTS; - onePacketSize = EIGER_ONE_GIGA_ONE_PACKET_SIZE; - oneDataSize = EIGER_ONE_GIGA_ONE_DATA_SIZE; - }else{ - packetsPerFrame = EIGER_TEN_GIGA_CONSTANT * dynamicRange * EIGER_MAX_PORTS; - onePacketSize = EIGER_TEN_GIGA_ONE_PACKET_SIZE; - oneDataSize = EIGER_TEN_GIGA_ONE_DATA_SIZE; - } - - footer_offset = EIGER_PACKET_HEADER_SIZE + oneDataSize; - frameSize = onePacketSize * packetsPerFrame; - bufferSize = (frameSize/EIGER_MAX_PORTS) + EIGER_HEADER_LENGTH;//everything one port gets (img header plus packets) - maxPacketsPerFile = EIGER_MAX_FRAMES_PER_FILE * packetsPerFrame; - - - - if(olddr != dr){ - - //del - if(thread_started){ - createListeningThreads(true); - createWriterThreads(true); - } - for(int i=0;i=0){ - nFrameToGui = i; - setupFifoStructure(); - } - return nFrameToGui; -} - - - -int64_t UDPStandardImplementation::setAcquisitionPeriod(int64_t index){ FILE_LOG(logDEBUG) << __AT__ << " called"; - - - if(index >= 0){ - if(index != acquisitionPeriod){ - acquisitionPeriod = index; - setupFifoStructure(); - } - } - return acquisitionPeriod; -} - - -bool UDPStandardImplementation::getDataCompression(){ FILE_LOG(logDEBUG) << __AT__ << " called"; -return dataCompression;} - -int UDPStandardImplementation::enableDataCompression(bool enable){ FILE_LOG(logDEBUG) << __AT__ << " called"; - - cout << "Data compression "; - if(enable) - cout << "enabled" << endl; - else - cout << "disabled" << endl; -#ifdef MYROOT1 - cout << " WITH ROOT" << endl; -#else - cout << " WITHOUT ROOT" << endl; -#endif - //delete filter for the current number of threads - deleteFilter(); - - dataCompression = enable; - pthread_mutex_lock(&status_mutex); - writerthreads_mask = 0x0; - pthread_mutex_unlock(&(status_mutex)); - - createWriterThreads(true); - - if(enable) - numWriterThreads = MAX_NUM_WRITER_THREADS; - else - numWriterThreads = 1; - - if(createWriterThreads() == FAIL){ - cprintf(BG_RED,"ERROR: Could not create writer threads\n"); - return FAIL; - } - setThreadPriorities(); - - - if(enable) - setupFilter(); - - return OK; -} - - - - - - - - - - - - -/*other functions*/ - - -void UDPStandardImplementation::deleteFilter(){ FILE_LOG(logDEBUG) << __AT__ << " called"; - - int i; - cmSub=NULL; - - for(i=0;i(receiverdata[i], csize, sigma, sign, cmSub); - -} - - - -//LEO: it is not clear to me.. -void UDPStandardImplementation::setupFifoStructure(){ - FILE_LOG(logDEBUG) << __AT__ << " called"; - - int64_t i; - int oldn = numJobsPerThread; - - //if every nth frame mode - if(nFrameToGui) - numJobsPerThread = nFrameToGui; - - //random nth frame mode - else{ - if(!acquisitionPeriod) - i = SAMPLE_TIME_IN_NS; - else - i = SAMPLE_TIME_IN_NS/acquisitionPeriod; - if (i > MAX_JOBS_PER_THREAD) - numJobsPerThread = MAX_JOBS_PER_THREAD; - else if (i < 1) - numJobsPerThread = 1; - else - numJobsPerThread = i; - } - - //if same, return - if(oldn == numJobsPerThread) - return; - - if(myDetectorType == EIGER) - numJobsPerThread = 1; - - //otherwise memory too much if numjobsperthread is at max = 1000 - fifosize = GOTTHARD_FIFO_SIZE; - if(myDetectorType == MOENCH) - fifosize = MOENCH_FIFO_SIZE; - if(myDetectorType == PROPIX) - fifosize = PROPIX_FIFO_SIZE; - else if(myDetectorType == EIGER) - fifosize = EIGER_FIFO_SIZE * packetsPerFrame; - - if(fifosize % numJobsPerThread) - fifosize = (fifosize/numJobsPerThread)+1; - else - fifosize = fifosize/numJobsPerThread; - - if(myDetectorType == EIGER) - cout << "1 packet per buffer" << endl; - else - cout << "Number of Frames per buffer:" << numJobsPerThread << endl; -#ifdef VERBOSE - cout << "Fifo Size:" << fifosize << endl; -#endif - /* - //for testing - numJobsPerThread = 3; fifosize = 11; - */ - - for(int i=0;iisEmpty()) - fifoFree[i]->pop(buffer[i]); -#ifdef FIFO_DEBUG - //cprintf(GREEN,"%d fifostructure popped from fifofree %x\n", i, (void*)(buffer[i])); -#endif - delete fifoFree[i]; - } - if(fifo[i]) delete fifo[i]; - if(mem0[i]) free(mem0[i]); - fifoFree[i] = new CircularFifo(fifosize); - fifo[i] = new CircularFifo(fifosize); - - - int whatperbuffer = bufferSize; - if(myDetectorType == EIGER) - whatperbuffer = onePacketSize; - - //allocate memory - mem0[i]=(char*)malloc((whatperbuffer * numJobsPerThread + HEADER_SIZE_NUM_TOT_PACKETS)*fifosize); - /** shud let the client know about this */ - if (mem0[i]==NULL){ - cprintf(BG_RED,"++++++++++++++++++++++ COULD NOT ALLOCATE MEMORY FOR LISTENING !!!!!!!+++++++++++++++++++++\n"); - exit(-1); - } - - buffer[i]=mem0[i]; - //push the addresses into freed fifoFree and writingFifoFree - while (buffer[i]<(mem0[i]+(whatperbuffer * numJobsPerThread + HEADER_SIZE_NUM_TOT_PACKETS)*(fifosize-1))) { - fifoFree[i]->push(buffer[i]); -#ifdef FIFO_DEBUG - cprintf(BLUE,"%d fifostructure free pushed into fifofree %x\n", i, (void*)(buffer[i])); -#endif - buffer[i]+=(whatperbuffer * numJobsPerThread + HEADER_SIZE_NUM_TOT_PACKETS); - } - } - cout << "Fifo structure(s) reconstructed" << endl; -} - - - - @@ -1113,164 +1342,6 @@ int UDPStandardImplementation::shutDownUDPSockets(){ -int UDPStandardImplementation::createListeningThreads(bool destroy){ - FILE_LOG(logDEBUG) << __AT__ << " called"; - - int i; - void* status; - - killAllListeningThreads = 0; - - pthread_mutex_lock(&status_mutex); - listeningthreads_mask = 0x0; - pthread_mutex_unlock(&(status_mutex)); - - FILE_LOG(logDEBUG) << "Starting " << __func__ << endl; - - if(!destroy){ - - //start listening threads - cout << "Creating Listening Threads(s)"; - - currentListeningThreadIndex = -1; - - for(i = 0; i < numListeningThreads; ++i){ - sem_init(&listensmp[i],1,0); - thread_started = 0; - currentListeningThreadIndex = i; - if(pthread_create(&listening_thread[i], NULL,startListeningThread, (void*) this)){ - cout << "Could not create listening thread with index " << i << endl; - return FAIL; - } - while(!thread_started); - cout << "."; - cout << flush; - } -#ifdef VERBOSE - cout << "Listening thread(s) created successfully." << endl; -#else - cout << endl; -#endif - }else{ - cout<<"Destroying Listening Thread(s)"<= 0){ - - tengigaEnable = enable; - - if(myDetectorType == EIGER){ - - if(!tengigaEnable){ - packetsPerFrame = EIGER_ONE_GIGA_CONSTANT * dynamicRange * EIGER_MAX_PORTS; - onePacketSize = EIGER_ONE_GIGA_ONE_PACKET_SIZE; - oneDataSize = EIGER_ONE_GIGA_ONE_DATA_SIZE; - }else{ - packetsPerFrame = EIGER_TEN_GIGA_CONSTANT * dynamicRange * EIGER_MAX_PORTS; - onePacketSize = EIGER_TEN_GIGA_ONE_PACKET_SIZE; - oneDataSize = EIGER_TEN_GIGA_ONE_DATA_SIZE; - } - frameSize = onePacketSize * packetsPerFrame; - bufferSize = (frameSize/EIGER_MAX_PORTS) + EIGER_HEADER_LENGTH;//everything one port gets (img header plus packets) - maxPacketsPerFile = EIGER_MAX_FRAMES_PER_FILE * packetsPerFrame; - -#ifdef VERBOSE - cout<<"packetsPerFrame:"<= 0) - receiverBase->setFrameToGuiFrequency(index); + if(index >= 0){ + ret = receiverBase->setFrameToGuiFrequency(index); + if(ret == FAIL) + strcpy(mess, "Could not allocate memory for listening fifo\n"); + } retval=receiverBase->getFrameToGuiFrequency(); if(index>=0 && retval!=index) ret = FAIL; @@ -2107,8 +2110,11 @@ int slsReceiverTCPIPInterface::set_timer() { } else{ if(index[0] == slsReceiverDefs::FRAME_PERIOD){ - if(index[1]>=0) - receiverBase->setAcquisitionPeriod(index[1]); + if(index[1]>=0){ + ret = receiverBase->setAcquisitionPeriod(index[1]); + if(ret == FAIL) + strcpy(mess,"Could not allocate memory for listening fifo\n") + } retval=receiverBase->getAcquisitionPeriod(); }else{ if(index[1]>=0) @@ -2183,17 +2189,19 @@ int slsReceiverTCPIPInterface::enable_compression() { } else{ if(enable >= 0) - receiverBase->setDataCompressionEnable(enable); + ret = receiverBase->setDataCompressionEnable(enable); } } - if (receiverBase == NULL){ - strcpy(mess,"Receiver not set up\n"); - ret=FAIL; - }else{ - retval = receiverBase->getDataCompressionEnable(); - if(enable >= 0 && retval != enable) - ret = FAIL; + if(ret != FAIL){ + if (receiverBase == NULL){ + strcpy(mess,"Receiver not set up\n"); + ret=FAIL; + }else{ + retval = receiverBase->getDataCompressionEnable(); + if(enable >= 0 && retval != enable) + ret = FAIL; + } } } @@ -2324,8 +2332,11 @@ int slsReceiverTCPIPInterface::set_dynamic_range() { strcpy(mess,"Receiver not set up\n"); ret=FAIL; }else{ - if(dr > 0) - receiverBase->setDynamicRange(dr); + if(dr > 0){ + ret = receiverBase->setDynamicRange(dr); + if(ret == FAIL) + strcpy(mess, "Could not allocate memory for fifo or could not start listening/writing threads\n"); + } retval = receiverBase->getDynamicRange(); if(dr > 0 && retval != dr) ret = FAIL; @@ -2461,8 +2472,8 @@ int slsReceiverTCPIPInterface::enable_tengiga() { } else{ if(val >= 0) - receiverBase->setDataCompressionEnable(val); - retval=receiverBase->getDataCompressionEnable(); + ret = receiverBase->setTenGigaEnable(val); + retval=receiverBase->getTenGigaEnable(); if((val >= 0) && (val != retval)) ret = FAIL; else From e915245c104c9cb66c002ab89cb3fb1de11b0f12 Mon Sep 17 00:00:00 2001 From: Dhanya Maliakal Date: Thu, 8 Oct 2015 17:09:43 +0200 Subject: [PATCH 35/68] additional change --- .../include/UDPBaseImplementation.h | 6 +- slsReceiverSoftware/include/UDPInterface.h | 6 +- .../include/UDPStandardImplementation.h | 220 +++----- .../src/UDPBaseImplementation.cpp | 5 +- .../src/UDPStandardImplementation.cpp | 497 ++++++++---------- 5 files changed, 297 insertions(+), 437 deletions(-) diff --git a/slsReceiverSoftware/include/UDPBaseImplementation.h b/slsReceiverSoftware/include/UDPBaseImplementation.h index 293ac6763..c1de8fa6f 100644 --- a/slsReceiverSoftware/include/UDPBaseImplementation.h +++ b/slsReceiverSoftware/include/UDPBaseImplementation.h @@ -111,7 +111,7 @@ class UDPBaseImplementation : protected virtual slsReceiverDefs, public UDPInter uint64_t getFramesCaught() const; /** - * Get Current Frame Index Caught for an entire acquisition (including all scans) + * Get Current Frame Index for an entire acquisition (including all scans) * @return current frame index (represents all scans too) */ int64_t getAcquisitionIndex() const; @@ -372,8 +372,8 @@ class UDPBaseImplementation : protected virtual slsReceiverDefs, public UDPInter void startReadout(); /** - * shuts down the udp sockets - * \returns OK or FAIL + * Shuts down and deletes UDP Sockets + * @return OK or FAIL */ int shutDownUDPSockets(); diff --git a/slsReceiverSoftware/include/UDPInterface.h b/slsReceiverSoftware/include/UDPInterface.h index 65c275a29..a3766b847 100644 --- a/slsReceiverSoftware/include/UDPInterface.h +++ b/slsReceiverSoftware/include/UDPInterface.h @@ -171,7 +171,7 @@ class UDPInterface { virtual uint64_t getFramesCaught() const = 0; /** - * Get Current Frame Index Caught for an entire acquisition (including all scans) + * Get Current Frame Index for an entire acquisition (including all scans) * @return current frame index (represents all scans too) or -1 if no packets caught */ virtual int64_t getAcquisitionIndex() const = 0; @@ -430,8 +430,8 @@ class UDPInterface { virtual void startReadout() = 0; /** - * shuts down the udp sockets - * \returns OK or FAIL + * Shuts down and deletes UDP Sockets + * @return OK or FAIL */ virtual int shutDownUDPSockets() = 0; diff --git a/slsReceiverSoftware/include/UDPStandardImplementation.h b/slsReceiverSoftware/include/UDPStandardImplementation.h index 747eaad34..825806e83 100644 --- a/slsReceiverSoftware/include/UDPStandardImplementation.h +++ b/slsReceiverSoftware/include/UDPStandardImplementation.h @@ -57,8 +57,6 @@ class UDPStandardImplementation: private virtual slsReceiverDefs, public UDPBase * They access local cache of configuration or detector parameters ******* *************************************************************************/ - //***acquisition count parameters*** - /************************************************************************* * Setters *************************************************************** @@ -154,14 +152,14 @@ class UDPStandardImplementation: private virtual slsReceiverDefs, public UDPBase */ int startReceiver(char *c=NULL); - + /** + * Shuts down and deletes UDP Sockets + * @return OK or FAIL + */ + int shutDownUDPSockets(); private: - /************************************************************************* - * Setters *************************************************************** - * They modify the local cache of configuration or detector parameters *** - *************************************************************************/ //**initial parameters*** /** @@ -227,6 +225,13 @@ private: */ int createUDPSockets(); + /** + * Initializes writer variables and creates the first file + * also does the startAcquisitionCallBack + * @return OK or FAIL + */ + int setupWriter(); + //**detector parameters*** @@ -277,19 +282,27 @@ private: /** Footer offset from start of Packet*/ int footerOffset; + //***File parameters*** /** Maximum Packets Per File **/ int maxPacketsPerFile; + /** If file created successfully for all Writer Threads */ + bool fileCreateSuccess; - //***acquisition indices parameters*** - /** Frame Number of First Frame of an Acquisition */ + + + //***acquisition indices/count parameters*** + /** Frame Number of First Frame of an entire Acquisition (including all scans) */ uint64_t startAcquisitionIndex; /** Frame index at start of each real time acquisition (eg. for each scan) */ uint64_t startFrameIndex; + /** Actual current frame index of each time acquisition (eg. for each scan) */ + uint64_t frameIndex; + /** Current Frame Number */ uint64_t currentFrameNumber; @@ -302,6 +315,19 @@ private: /** Total Frame Count listened to by listening threads */ int totalListeningFrameCount[MAX_NUMBER_OF_LISTENING_THREADS]; + /** Pckets currently in current file, starts new file when it reaches max */ + uint32_t packetsInFile; + + /** Number of Missing Packets per buffer*/ + uint32_t numMissingPackets; + + /** Total Number of Missing Packets in acquisition*/ + uint32_t numTotMissingPackets; + + /** Number of Missing Packets in file */ + uint32_t numTotMissingPacketsInFile; + + @@ -318,15 +344,37 @@ private: /** Circular fifo to point to address already written and freed, to be reused */ CircularFifo* fifoFree[MAX_NUMBER_OF_LISTENING_THREADS]; + /** UDP Sockets - Detector to Receiver */ + genericSocket* udpSocket[MAX_NUMBER_OF_LISTENING_THREADS]; + + /** File Descriptor */ + FILE *sfilefd; + /** Number of Jobs Per Buffer */ int numberofJobsPerBuffer; /** Fifo Depth */ uint32_t fifoSize; - /** Current Frame copied for Gui */ + + //***receiver to GUI parameters*** + /** Current Frame copied for GUI */ char* latestData; + /** If Data to be sent to GUI is ready */ + bool guiDataReady; + + /** Pointer to data to be sent to GUI */ + char* guiData; + + /** Pointer to file name to be sent to GUI */ + char guiFileName[MAX_STR_LENGTH]; + + /** Semaphore to synchronize Writer and GuiReader threads*/ + sem_t writerGuiSemaphore; + + + //***general and listening thread parameters*** @@ -382,7 +430,6 @@ private: - //***filter parameters*** /** Common Mode Subtraction Enable FIXME: Always false, only moench uses, Ask Anna */ bool commonModeSubtractionEnable; @@ -404,6 +451,12 @@ private: pthread_mutex_t status_mutex; + //***callback*** + /** The action which decides what the user and default responsibilities to save data are + * 0 raw data ready callback takes care of open,close,write file + * 1 callback writes file, we have to open, close it + * 2 we open, close, write file, callback does not do anything */ + int cbAction; @@ -422,89 +475,6 @@ private: - - - - - - - /** - * Set receiver type - * @param det detector type - * Returns success or FAIL - */ - int setDetectorType(detectorType det); - - - //Frame indices and numbers caught - /** - * Returns the frame index at start of entire acquisition (including all scans) - */ - //uint32_t getStartAcquisitionIndex(); - - /** - * Returns if acquisition started - */ - //bool getAcquistionStarted(); - - /** - * Returns the frame index at start of each real time acquisition (eg. for each scan) - */ - //uint32_t getStartFrameIndex(); - - /** - * Returns current Frame Index for each real time acquisition (eg. for each scan) - */ - //uint32_t getFrameIndex(); - - /** - * Returns if measurement started - */ - //bool getMeasurementStarted(); - - /** - * Resets the Total Frames Caught - * This is how the receiver differentiates between entire acquisitions - * Returns 0 - */ - //void resetTotalFramesCaught(); - - - - - -//other parameters - - /** - * abort acquisition with minimum damage: close open files, cleanup. - * does nothing if state already is 'idle' - */ - void abort() {}; - - /** - * Returns status of receiver: idle, running or error - */ - runStatus getStatus() const; - - /** - * Set detector hostname - * @param c hostname - */ - void setDetectorHostname(const char *detectorHostName); - - - - /** - * enable 10Gbe - @param enable 1 for 10Gbe or 0 for 1 Gbe, -1 to read out - \returns enable for 10Gbe - */ - int enableTenGiga(int enable = -1); - - - -//other functions - /** * Returns the buffer-current frame read by receiver * @param c pointer to current file name @@ -520,12 +490,6 @@ private: */ void closeFile(int ithr = -1); - /** - * Starts Receiver - starts to listen for packets - * @param message is the error message if there is an error - * Returns success - */ - int startReceiver(char message[]); /** * Stops Receiver - stops listening for packets @@ -538,21 +502,9 @@ private: */ void startReadout(); - /** - * shuts down the udp sockets - * \returns if success or fail - */ - int shutDownUDPSockets(); + private: - - /* - void not_implemented(string method_name){ - std::cout << "[WARNING] Method " << method_name << " not implemented!" << std::endl; - }; - */ - - /** @@ -562,12 +514,6 @@ private: void copyFrameToGui(char* startbuf[], char* buf=NULL); - /** - * initializes variables and creates the first file - * also does the startAcquisitionCallBack - * \returns FAIL or OK - */ - int setupWriter(); /** * Creates new tree and file for compression @@ -694,42 +640,18 @@ private: const static uint16_t missingPacketValue = 0xFFFF; - /** UDP Socket between Receiver and Detector */ - genericSocket* udpSocket[MAX_NUM_LISTENING_THREADS]; - - /** Complete File name */ +/** Complete File name */ char savefilename[MAX_STR_LENGTH]; - /** Actual current frame index of each time acquisition (eg. for each scan) */ - uint32_t frameIndex; - /** Pckets currently in current file, starts new file when it reaches max */ - uint32_t packetsInFile; - - /** Number of missing packets in acquisition*/ - uint32_t numTotMissingPackets; - - /** Number of missing packets in file (sometimes packetsinFile is incorrect due to padded packets for eiger)*/ - uint32_t numTotMissingPacketsInFile; - - /** Number of missing packets per buffer*/ - uint32_t numMissingPackets; /** Previous Frame number from buffer */ int prevframenum; - /** gui data ready */ - int guiDataReady; - /** points to the data to send to gui */ - char* guiData; - /** points to the filename to send to gui */ - char* guiFileName; -/** OK if file created was successful */ - int ret_createfile; // TODO: not properly sure where to put these... /** structure of an eiger image header*/ @@ -738,8 +660,7 @@ private: //semaphores - /** semaphore to synchronize writer and guireader threads */ - sem_t smp; + //mutex /** guiDataReady mutex */ @@ -751,8 +672,6 @@ private: /** mutex for writing data to file */ pthread_mutex_t write_mutex; - /** File Descriptor */ - FILE *sfilefd; //filter @@ -766,11 +685,6 @@ private: #endif - /** The action which decides what the user and default responsibilites to save data are - * 0 raw data ready callback takes care of open,close,write file - * 1 callback writes file, we have to open, close it - * 2 we open, close, write file, callback does not do anything */ - int cbAction; public: diff --git a/slsReceiverSoftware/src/UDPBaseImplementation.cpp b/slsReceiverSoftware/src/UDPBaseImplementation.cpp index 0c1c30248..ec5c27ad5 100644 --- a/slsReceiverSoftware/src/UDPBaseImplementation.cpp +++ b/slsReceiverSoftware/src/UDPBaseImplementation.cpp @@ -286,10 +286,7 @@ int UDPBaseImplementation::setDataCompressionEnable(const bool b){ void UDPBaseImplementation::setUDPPortNumber(const uint32_t i){ FILE_LOG(logDEBUG) << __AT__ << " starting"; - if(bottomEnable) - udpPortNum[1] = i; - else - udpPortNum[0] = i; + udpPortNum[0] = i; FILE_LOG(logINFO) << "udpPortNum[0]:" << udpPortNum[0]; } diff --git a/slsReceiverSoftware/src/UDPStandardImplementation.cpp b/slsReceiverSoftware/src/UDPStandardImplementation.cpp index 0f4290c9c..5901e96a3 100644 --- a/slsReceiverSoftware/src/UDPStandardImplementation.cpp +++ b/slsReceiverSoftware/src/UDPStandardImplementation.cpp @@ -58,16 +58,22 @@ void UDPStandardImplementation::deleteMembers(){ FILE_LOG(logDEBUG) << __AT__ << " starting"; cout << "Info: Deleting member pointers" << endl; + shutDownUDPSockets(); + closeFile(); //filter deleteFilter(); + for(int i=0; igetErrorStatus(); + if(!iret){ + cout << "Info: UDP port opened at port " << port[i] << endl; + }else{ +#ifdef VERBOSE + cprintf(BG_RED,"Error: Could not create UDP socket on port %d error: %d\n", port[i], iret); +#endif + shutDownUDPSockets(); + return FAIL; + } + } + + cout << "Info: UDP socket(s) created successfully." << endl; + cout << "Info: Listener Ready ..." << endl; return OK; } +int UDPStandardImplementation::setupWriter(){ + FILE_LOG(logDEBUG) << __AT__ << " starting"; + + //acquisition start call back returns enable write + cbAction = DO_EVERYTHING; + if (startAcquisitionCallBack) + cbAction=startAcquisitionCallBack(filePath,fileName,fileIndex,bufferSize,pStartAcquisition); + + if(cbAction < DO_EVERYTHING){ + cout << "Info: Call back activated. Data saving must be taken care of by user in call back." << endl; + if (rawDataReadyCallBack) + cout << "Info: Data Write has been defined externally" << endl; + }else if(!fileWriteEnable) + cout << "Info: Data will not be saved" << endl; + + + + //creating first file + //setting all value to 1 + pthread_mutex_lock(&status_mutex); + for(int i=0; i config_map){ FILE_LOG(logDEBUG) << __AT__ << " starting"; @@ -869,25 +984,113 @@ int UDPStandardImplementation::startReceiver(char *c=NULL){ cout << "Info: Starting Receiver" << endl; + + //RESET //reset measurement variables measurementStarted = false; startFrameIndex = 0; + frameIndex = 0; if(!acqStarted) currentFrameNumber = 0; //has to be zero to add to startframeindex for each scan for(int i = 0; i < numberofListeningThreads; ++i) totalListeningFrameCount[i] = 0; + packetsCaught = 0; + numMissingPackets = 0; + numTotMissingPackets = 0; + numTotMissingPacketsInFile = 0; + //reset file parameters + packetsInFile = 0; + if(sfilefd){ + fclose(sfilefd); + sfilefd = NULL; + } + //reset gui variables + guiData = NULL; + guiDataReady=0; + strcpy(guiFileName,""); + //reset masks + pthread_mutex_lock(&status_mutex); + writerThreadsMask = 0x0; + createFileMask = 0x0; + fileCreateSuccess = false; + pthread_mutex_unlock(&status_mutex); + + + //Print Receiver Configuration + cout << "Info: ***Receiver Configuration***" << endl; + cout << "Info: Max Packets Per File:" << maxPacketsPerFile << endl; + cout << "Info: Data Compression has been " << stringEnable(dataCompressionEnable) << endl; + if(myDetectorType != EIGER) + cout << "Info: Number of Jobs Per Buffer: " << numberofJobsPerBuffer << endl; + if(FrameToGuiFrequency) + cout << "Info: Frequency of frames sent to gui" << FrameToGuiFrequency << endl; + + //create UDP sockets if(createUDPSockets() == FAIL){ - + strcpy(c,"Could not create UDP Socket(s).\n"); + cout << endl; + cout << "Error: "<< c << endl; + return FAIL; } + if(setupWriter() == FAIL){ + //stop udp socket + shutDownUDPSockets(); + sprintf(c,"Could not create file %s.\n",savefilename); + cout << endl; + cout << "Error: "<< c << endl; + return FAIL; + } + + + //For compression, done to give the gui some proper name instead of always the last file name + if(dataCompressionEnable) + sprintf(savefilename, "%s/%s_fxxx_%d_xx.root", filePath,fileName,fileIndex); + + //initialize semaphore to synchronize between writer and gui reader threads + sem_init(&writerGuiSemaphore,1,0); + + //status and thread masks + pthread_mutex_lock(&status_mutex); + status = RUNNING; + for(int i=0;iShutDownSocket(); + delete udpSocket[i]; + udpSocket[i] = NULL; + } + } + return OK; +} @@ -929,16 +1132,13 @@ int UDPStandardImplementation::startReceiver(char *c=NULL){ UDPStandardImplementation::UDPStandardImplementation(){ thread_started = 0; eth = NULL; - latestData = NULL; - guiFileName = NULL; + tengigaEnable = 0; for(int i=0;igetErrorStatus(); - if(!iret){ - cout << "UDP port opened at port " << port[i] << endl; - }else{ -#ifdef VERBOSE - cprintf(BG_RED,"Could not create UDP socket on port %d error: %d\n", port[i], iret); -#endif - shutDownUDPSockets(); - return FAIL; - } - } - - - - return OK; -} - - - - - - - -int UDPStandardImplementation::shutDownUDPSockets(){ - FILE_LOG(logDEBUG) << __AT__ << " called"; - - for(int i=0;iShutDownSocket(); - delete udpSocket[i]; - udpSocket[i] = NULL; - } - } - return OK; -} - - - - - - - -int UDPStandardImplementation::setupWriter(){ - FILE_LOG(logDEBUG) << __AT__ << " called"; - - //reset writing thread variables - packetsInFile=0; - numTotMissingPackets = 0; - numTotMissingPacketsInFile = 0; - numMissingPackets = 0; - packetsCaught=0; - frameIndex=0; - if(sfilefd) {cprintf(RED,"**FILE not closed!\n");fclose(sfilefd);sfilefd=NULL;} - guiData = NULL; - guiDataReady=0; - strcpy(guiFileName,""); - cbAction = DO_EVERYTHING; - - pthread_mutex_lock(&status_mutex); - writerthreads_mask = 0x0; - createfile_mask = 0x0; - ret_createfile = OK; - pthread_mutex_unlock(&status_mutex); - - //printouts - cout << "Max Packets Per File:" << maxPacketsPerFile << endl; - if (rawDataReadyCallBack) - cout << "Note: Data Write has been defined exernally" << endl; - if (dataCompression) - cout << "Data Compression is enabled with " << numJobsPerThread << " number of jobs per thread" << endl; - if(nFrameToGui) - cout << "Sending every " << nFrameToGui << "th frame to gui" << endl; - - - - //acquisition start call back returns enable write - if (startAcquisitionCallBack) - cbAction=startAcquisitionCallBack(filePath,fileName,fileIndex,bufferSize,pStartAcquisition); - - if(cbAction < DO_EVERYTHING) - cout << endl << "Note: Call back activated. Data saving must be taken care of by user in call back." << endl; - else if(enableFileWrite==0) - cout << endl << "Note: Data will not be saved" << endl; - - - - //creating first file - - //mask - pthread_mutex_lock(&status_mutex); - for(int i=0;i Date: Tue, 13 Oct 2015 15:22:30 +0200 Subject: [PATCH 36/68] some more --- .../include/UDPBaseImplementation.h | 13 +- slsReceiverSoftware/include/UDPInterface.h | 10 +- .../include/UDPStandardImplementation.h | 371 ++- slsReceiverSoftware/include/logger.h | 6 + .../src/UDPBaseImplementation.cpp | 2 +- .../src/UDPStandardImplementation.cpp | 2256 ++++++++--------- 6 files changed, 1241 insertions(+), 1417 deletions(-) diff --git a/slsReceiverSoftware/include/UDPBaseImplementation.h b/slsReceiverSoftware/include/UDPBaseImplementation.h index c1de8fa6f..43f98b511 100644 --- a/slsReceiverSoftware/include/UDPBaseImplementation.h +++ b/slsReceiverSoftware/include/UDPBaseImplementation.h @@ -381,10 +381,10 @@ class UDPBaseImplementation : protected virtual slsReceiverDefs, public UDPInter * Get the buffer-current frame read by receiver * @param c pointer to current file name * @param raw address of pointer, pointing to current frame to send to gui - * @param startAcquisitionIndex start index of the acquisition - * @param startFrameIndex start index of the scan + * @param startAcq start index of the acquisition + * @param startFrame start index of the scan */ - void readFrame(char* c,char** raw, uint64_t &startAcquisitionIndex, uint64_t &startFrameIndex); + void readFrame(char* c,char** raw, uint64_t &startAcq, uint64_t &startFrame); /** * abort acquisition with minimum damage: close open files, cleanup. @@ -393,8 +393,8 @@ class UDPBaseImplementation : protected virtual slsReceiverDefs, public UDPInter void abort(); //FIXME: needed, isn't stopReceiver enough? /** - * Closes all files - * @param i thread index, -1 for all threads + * Closes file / all files(if multiple files) + * @param i thread index (if multiple files used eg. root files) -1 for all threads */ void closeFile(int i = -1); @@ -438,6 +438,9 @@ class UDPBaseImplementation : protected virtual slsReceiverDefs, public UDPInter protected: + /************************************************************************* + * Class Members ********************************************************* + *************************************************************************/ //**detector parameters*** /** detector type */ detectorType myDetectorType; diff --git a/slsReceiverSoftware/include/UDPInterface.h b/slsReceiverSoftware/include/UDPInterface.h index a3766b847..b62ad2eb0 100644 --- a/slsReceiverSoftware/include/UDPInterface.h +++ b/slsReceiverSoftware/include/UDPInterface.h @@ -439,10 +439,10 @@ class UDPInterface { * Get the buffer-current frame read by receiver * @param c pointer to current file name * @param raw address of pointer, pointing to current frame to send to gui - * @param startAcquisitionIndex start index of the acquisition - * @param startFrameIndex start index of the scan + * @param startAcq start index of the acquisition + * @param startFrame start index of the scan */ - virtual void readFrame(char* c,char** raw, uint64_t &startAcquisitionIndex, uint64_t &startFrameIndex)=0; + virtual void readFrame(char* c,char** raw, uint64_t &startAcq, uint64_t &startFrame)=0; /** * abort acquisition with minimum damage: close open files, cleanup. @@ -451,8 +451,8 @@ class UDPInterface { virtual void abort() = 0; //FIXME: needed, isnt stopReceiver enough? /** - * Closes all files - * @param i thread index, -1 for all threads + * Closes file / all files(if multiple files) + * @param i thread index (if multiple files used eg. root files) -1 for all threads */ virtual void closeFile(int i = -1) = 0; diff --git a/slsReceiverSoftware/include/UDPStandardImplementation.h b/slsReceiverSoftware/include/UDPStandardImplementation.h index 825806e83..cbd46d433 100644 --- a/slsReceiverSoftware/include/UDPStandardImplementation.h +++ b/slsReceiverSoftware/include/UDPStandardImplementation.h @@ -153,12 +153,63 @@ class UDPStandardImplementation: private virtual slsReceiverDefs, public UDPBase int startReceiver(char *c=NULL); /** + * Overridden method + * Stop Listening for Packets + * Calls startReadout(), which stops listening and sets status to Transmitting + * When it has read every frame in buffer,it returns with the status Run_Finished + * Pre: status is running, semaphores have been instantiated, + * Post: udp sockets shut down, status is idle, semaphores destroyed + */ + void stopReceiver(); + + /** + * Overridden method + * Stop Listening to Packets + * and sets status to Transmitting + * Pre: status is running, udp sockets have been initialized, stop receiver initiated + * Post:udp sockets closed, status is transmitting + */ + void startReadout(); + + /** + * Overridden method * Shuts down and deletes UDP Sockets * @return OK or FAIL */ int shutDownUDPSockets(); + /** + * Overridden method + * Get the buffer-current frame read by receiver + * @param c pointer to current file name + * @param raw address of pointer, pointing to current frame to send to gui + * @param startAcq start index of the acquisition + * @param startFrame start index of the scan + */ + void readFrame(char* c,char** raw, uint64_t &startAcq, uint64_t &startFrame); + + /** + * Overridden method + * Closes file / all files(data compression involves multiple files) + * @param i thread index valid for datacompression using root files, -1 for all threads + */ + void closeFile(int i = -1); + private: + /************************************************************************* + * Getters *************************************************************** + * They access local cache of configuration or detector parameters ******* + *************************************************************************/ + +/* + uint64_t (*getFrameNumber)(); + uint64_t eigerGetFrameNumber(); + uint64_t generalGetFrameNumber(); + getframenumber = &generalgetframenumber; + if(dettpe == eiger) getframenumber = &eigerGerFramenumber; + + call using getframenumber(); +*/ //**initial parameters*** @@ -194,6 +245,19 @@ private: */ void initializeFilter(); + /** + * Set up the Fifo Structure for processing buffers + * between listening and writer threads + * @return OK or FAIL + */ + int setupFifoStructure(); + + + + /************************************************************************* + * Listening and Writing Threads ***************************************** + *************************************************************************/ + /** * Create Listening Threads * @param destroy is true to destroy all the threads @@ -212,13 +276,6 @@ private: */ void setThreadPriorities(); - /** - * Set up the Fifo Structure for processing buffers - * between listening and writer threads - * @return OK or FAIL - */ - int setupFifoStructure(); - /** * Creates UDP Sockets * @return OK or FAIL @@ -232,7 +289,87 @@ private: */ int setupWriter(); + /** + * Creates new file + * @return OK or FAIL + */ + int createNewFile(); + /** + * Static function - Starts Listening Thread of this object + * @param this_pointer pointer to this object + */ + static void* startListeningThread(void *this_pointer); + + /** + * Static function - Starts Writing Thread of this object + * @param this_pointer pointer to this object + */ + static void* startWritingThread(void *this_pointer); + + /** + * Thread that listens to packets + * It pops the fifofree for free addresses, listens to packets and pushes them into the fifo + * This is continuously looped for each buffer in a nested loop, which is again looped for each acquisition + * Exits only for changing dynamic range, 10G parameters etc and recreated + * + */ + void startListening(); + + /** + * Thread started which writes packets to file. + * It pops the fifo, processes and writes packets to file and pushes the addresses into the fifoFree + * This is continuously looped for each buffer in a nested loop, which is again looped for each acquisition + * Exits only for changing dynamic range, 10G parameters etc and recreated + * + */ + void startWriting(); + + /** + * Called by startListening + * Listens to buffer, until packet(s) received or shutdownUDPsocket called by client + * Also copies carryovers from previous frame in front of buffer (gotthard and moench) + * For eiger, it ignores packets less than onePacketSize + * @param ithread listening thread index + * @param lSize number of bytes to listen to + * @param cSize number of bytes carried on from previous buffer + * @param temp temporary storage of previous buffer + * @return the number of bytes actually received + */ + int prepareAndListenBuffer(int ithread, int lSize, int cSize, char* temp); + + /** + * Called by startListening + * Its called for the first packet of a scan or acquistion + * Sets the startframeindices and the variables to know if acquisition started + * @param ithread listening thread number + */ + void startFrameIndices(int ithread); + + /** + * Called by prepareAndListenBuffer + * This is called when udp socket is shut down by client + * It pushes ffff instead of packet number into fifo + * to inform writers about the end of listening session + * Then sets the listening mask so that it stops listening and wait for next acquisition trigger + * @param ithread listening thread number + * @param numbytes number of bytes received + */ + void stopListening(int ithread, int numbytes); + + /* + * Called by startListening for gotthard and moench to handle split frames + * It processes listening thread buffers by ensuring split frames are in the same buffer + * @param ithread listening thread index + * @param cSize number of bytes carried over to the next buffer to reunite with split frame + * @param temp temporary buffer to store the split frame + * @return packet count + */ + uint32_t processListeningBuffer(int ithread, int cSize,char* temp); + + /************************************************************************* + * Class Members ********************************************************* + *************************************************************************/ //**detector parameters*** /** @@ -284,7 +421,18 @@ private: //***File parameters*** - /** Maximum Packets Per File **/ +#ifdef MYROOT1 + /** Tree where the hits are stored */ + TTree *myTree[MAX_NUMBER_OF_WRITER_THREADS]; + + /** File where the tree is saved */ + TFile *myFile[MAX_NUMBER_OF_WRITER_THREADS]; +#endif + + /** Complete File name */ + char completeFileName[MAX_STR_LENGTH]; + + /** Maximum Packets Per File **/ int maxPacketsPerFile; /** If file created successfully for all Writer Threads */ @@ -306,6 +454,9 @@ private: /** Current Frame Number */ uint64_t currentFrameNumber; + /** Previous Frame number from buffer to calculate loss */ + uint64_t previousFrameNumber; + /* Acquisition started */ bool acqStarted; @@ -356,6 +507,11 @@ private: /** Fifo Depth */ uint32_t fifoSize; + /** Missing Packet identifier value */ + const static uint16_t missingPacketValue = 0xFFFF; + + /** Dummy Packet identifier value */ + const static uint32_t dummyPacketValue = 0xFFFFFFFF; //***receiver to GUI parameters*** /** Current Frame copied for GUI */ @@ -381,6 +537,9 @@ private: /** Ensures if threads created successfully */ bool threadStarted; + /** Current Thread Index*/ + int currentThreadIndex; + /** Number of Listening Threads */ int numberofListeningThreads; @@ -414,9 +573,6 @@ private: /** Semaphores Synchronizing Writer Threads */ sem_t writerSemaphore[MAX_NUMBER_OF_WRITER_THREADS]; - /** Current Writer Thread Index*/ - int currentWriterThreadIndex; - /** Mask with each bit indicating status of each writer thread */ volatile uint32_t writerThreadsMask; @@ -447,9 +603,17 @@ private: //***mutex*** - /** mutex for status */ - pthread_mutex_t status_mutex; + /** Status mutex */ + pthread_mutex_t statusMutex; + /** Writing mutex */ + pthread_mutex_t writeMutex; + + /** GuiDataReady Mutex */ + pthread_mutex_t dataReadyMutex; + + /** Progress (currentFrameNumber) Mutex */ + pthread_mutex_t progressMutex; //***callback*** /** The action which decides what the user and default responsibilities to save data are @@ -475,32 +639,6 @@ private: - /** - * Returns the buffer-current frame read by receiver - * @param c pointer to current file name - * @param raw address of pointer, pointing to current frame to send to gui - * @param startAcquisitionIndex is the start index of the acquisition - * @param startFrameIndex is the start index of the scan - */ - void readFrame(char* c,char** raw, uint32_t &startAcquisitionIndex, uint32_t &startFrameIndex); - - /** - * Closes all files - * @param ithr thread index - */ - void closeFile(int ithr = -1); - - - /** - * Stops Receiver - stops listening for packets - * Returns success - */ - int stopReceiver(); - - /** set status to transmitting and - * when fifo is empty later, sets status to run_finished - */ - void startReadout(); @@ -513,8 +651,6 @@ private: */ void copyFrameToGui(char* startbuf[], char* buf=NULL); - - /** * Creates new tree and file for compression * @param ithr thread number @@ -523,40 +659,6 @@ private: */ int createCompressionFile(int ithr, int iframe); - /** - * Creates new file - *\returns OK for succces or FAIL for failure - */ - int createNewFile(); - - /** - * Static function - Thread started which listens to packets. - * Called by startReceiver() - * @param this_pointer pointer to this object - */ - static void* startListeningThread(void *this_pointer); - - /** - * Static function - Thread started which writes packets to file. - * Called by startReceiver() - * @param this_pointer pointer to this object - */ - static void* startWritingThread(void *this_pointer); - - /** - * Thread started which listens to packets. - * Called by startReceiver() - * - */ - int startListening(); - - /** - * Thread started which writes packets to file. - * Called by startReceiver() - * - */ - int startWriting(); - /** * Writing to file without compression * @param buf is the address of buffer popped out of fifo @@ -565,25 +667,6 @@ private: */ void writeToFile_withoutCompression(char* buf[],int numpackets, uint32_t framenum); - /** - * Its called for the first packet of a scan or acquistion - * Sets the startframeindices and the variables to know if acquisition started - * @param ithread listening thread number - * @param numbytes number of bytes it listened to - */ - void startFrameIndices(int ithread, int numbytes); - - /** - * This is called when udp socket is shut down - * It pops ffff instead of packet number into fifo - * to inform writers about the end of listening session - * @param ithread listening thread number - * @param rc number of bytes received - * @param pc packet count - * @param t total packets listened to - */ - void stopListening(int ithread, int rc, int &pc, int &t); - /** * When acquisition is over, this is called * @param ithread listening thread number @@ -615,110 +698,10 @@ private: - - - - - - - - - - - - - - - - - - - - - - /** missing packet identifier value */ - const static uint16_t missingPacketValue = 0xFFFF; - - -/** Complete File name */ - char savefilename[MAX_STR_LENGTH]; - - - - /** Previous Frame number from buffer */ - int prevframenum; - - - - - - - // TODO: not properly sure where to put these... - /** structure of an eiger image header*/ - - - - -//semaphores - - -//mutex - /** guiDataReady mutex */ - pthread_mutex_t dataReadyMutex; - - /** mutex for progress variable currframenum */ - pthread_mutex_t progress_mutex; - - /** mutex for writing data to file */ - pthread_mutex_t write_mutex; - //filter -#ifdef MYROOT1 - /** Tree where the hits are stored */ - TTree *myTree[MAX_NUM_WRITER_THREADS]; - - /** File where the tree is saved */ - TFile *myFile[MAX_NUM_WRITER_THREADS]; -#endif - - - - -public: - - - /** - callback arguments are - filepath - filename - fileindex - datasize - - return value is - 0 callback takes care of open,close,wrie file - 1 callback writes file, we have to open, close it - 2 we open, close, write file, callback does not do anything - */ - void registerCallBackStartAcquisition(int (*func)(char*, char*,int, int, void*),void *arg){startAcquisitionCallBack=func; pStartAcquisition=arg;}; - - /** - callback argument is - toatal frames caught - */ - void registerCallBackAcquisitionFinished(void (*func)(int, void*),void *arg){acquisitionFinishedCallBack=func; pAcquisitionFinished=arg;}; - - /** - args to raw data ready callback are - framenum - datapointer - datasize in bytes - file descriptor - guidatapointer (NULL, no data required) - */ - void registerCallBackRawDataReady(void (*func)(int, char*, int, FILE*, char*, void*),void *arg){rawDataReadyCallBack=func; pRawDataReady=arg;}; }; diff --git a/slsReceiverSoftware/include/logger.h b/slsReceiverSoftware/include/logger.h index cba284fb1..5e964da27 100644 --- a/slsReceiverSoftware/include/logger.h +++ b/slsReceiverSoftware/include/logger.h @@ -23,6 +23,12 @@ #define TOSTRING(x) STRINGIFY(x) #define MYCONCAT(x,y) #define __AT__ string(__FILE__) + string("::") + string(__func__) + string("(): ") +#define __SHORT_FORM_OF_FILE__ \ +(strrchr(__FILE__,'/') \ +? strrchr(__FILE__,'/')+1 \ +: __FILE__ \ +) +#define __SHORT_AT__ string(__SHORT_FORM_OF_FILE__) + string("::") + string(__func__) + string("(): ") //":" TOSTRING(__LINE__) diff --git a/slsReceiverSoftware/src/UDPBaseImplementation.cpp b/slsReceiverSoftware/src/UDPBaseImplementation.cpp index ec5c27ad5..75f7fa244 100644 --- a/slsReceiverSoftware/src/UDPBaseImplementation.cpp +++ b/slsReceiverSoftware/src/UDPBaseImplementation.cpp @@ -37,7 +37,7 @@ UDPBaseImplementation::UDPBaseImplementation(){ //***connection parameters*** strcpy(eth,""); - for(int i=0;i /proc/sys/net/core/rmem_max")) + cout << "Warning: No root permission to change socket receiver buffer size in file /proc/sys/net/core/rmem_max" << endl; + else if(system("echo 250000 > /proc/sys/net/core/netdev_max_backlog")) + cout << "Warning: No root permission to change max length of input queue in file /proc/sys/net/core/netdev_max_backlog" << endl; + /** permanent setting by heiner + net.core.rmem_max = 104857600 # 100MiB + net.core.netdev_max_backlog = 250000 + sysctl -p + // from the manual + sysctl -w net.core.rmem_max=16777216 + sysctl -w net.core.netdev_max_backlog=250000 + */ } UDPStandardImplementation::~UDPStandardImplementation(){ - FILE_LOG(logDEBUG) << __AT__ << " called"; + FILE_LOG(logDEBUG1) << __AT__ << " called"; deleteMembers(); } @@ -49,13 +69,13 @@ UDPStandardImplementation::~UDPStandardImplementation(){ /***initial parameters***/ void UDPStandardImplementation::deleteBaseMembers(){ - FILE_LOG(logDEBUG) << __AT__ << " starting"; + FILE_LOG(logDEBUG1) << __AT__ << " starting"; UDPBaseImplementation::~UDPBaseImplementation(); } void UDPStandardImplementation::deleteMembers(){ - FILE_LOG(logDEBUG) << __AT__ << " starting"; + FILE_LOG(logDEBUG1) << __AT__ << " starting"; cout << "Info: Deleting member pointers" << endl; shutDownUDPSockets(); @@ -77,7 +97,7 @@ void UDPStandardImplementation::deleteMembers(){ } void UDPStandardImplementation::deleteFilter(){ - FILE_LOG(logDEBUG) << __AT__ << " starting"; + FILE_LOG(logDEBUG1) << __AT__ << " starting"; moenchCommonModeSubtraction = NULL; for(int i=0; igetErrorStatus(); - if(!iret){ - cout << "Info: UDP port opened at port " << port[i] << endl; - }else{ -#ifdef VERBOSE - cprintf(BG_RED,"Error: Could not create UDP socket on port %d error: %d\n", port[i], iret); -#endif - shutDownUDPSockets(); - return FAIL; - } - } - - cout << "Info: UDP socket(s) created successfully." << endl; - cout << "Info: Listener Ready ..." << endl; - - return OK; -} - - - -int UDPStandardImplementation::setupWriter(){ - FILE_LOG(logDEBUG) << __AT__ << " starting"; - - //acquisition start call back returns enable write - cbAction = DO_EVERYTHING; - if (startAcquisitionCallBack) - cbAction=startAcquisitionCallBack(filePath,fileName,fileIndex,bufferSize,pStartAcquisition); - - if(cbAction < DO_EVERYTHING){ - cout << "Info: Call back activated. Data saving must be taken care of by user in call back." << endl; - if (rawDataReadyCallBack) - cout << "Info: Data Write has been defined externally" << endl; - }else if(!fileWriteEnable) - cout << "Info: Data will not be saved" << endl; - - - - //creating first file - //setting all value to 1 - pthread_mutex_lock(&status_mutex); - for(int i=0; i config_map){ - FILE_LOG(logDEBUG) << __AT__ << " starting"; + FILE_LOG(logDEBUG1) << __AT__ << " starting"; map::const_iterator pos; pos = config_map.find("mode"); @@ -596,7 +376,7 @@ void UDPStandardImplementation::configure(map config_map){ /***file parameters***/ int UDPStandardImplementation::setDataCompressionEnable(const bool b){ - FILE_LOG(logDEBUG) << __AT__ << " starting"; + FILE_LOG(logDEBUG1) << __AT__ << " starting"; cout << "Info: Setting up Data Compression Enable to " << stringEnable(b); #ifdef MYROOT1 @@ -609,9 +389,9 @@ int UDPStandardImplementation::setDataCompressionEnable(const bool b){ dataCompressionEnable = b; //-- create writer threads depending on enable - pthread_mutex_lock(&status_mutex); + pthread_mutex_lock(&statusMutex); writerThreadsMask = 0x0; - pthread_mutex_unlock(&(status_mutex)); + pthread_mutex_unlock(&(statusMutex)); createWriterThreads(true); if(b) @@ -638,7 +418,7 @@ int UDPStandardImplementation::setDataCompressionEnable(const bool b){ /***acquisition parameters***/ void UDPStandardImplementation::setShortFrameEnable(const int i){ - FILE_LOG(logDEBUG) << __AT__ << " called"; + FILE_LOG(logDEBUG1) << __AT__ << " called"; shortFrameEnable = i; @@ -675,7 +455,7 @@ void UDPStandardImplementation::setShortFrameEnable(const int i){ int UDPStandardImplementation::setFrameToGuiFrequency(const uint32_t i){ - FILE_LOG(logDEBUG) << __AT__ << " called"; + FILE_LOG(logDEBUG1) << __AT__ << " called"; if(i >= 0){ FrameToGuiFrequency = i; @@ -690,7 +470,7 @@ int UDPStandardImplementation::setFrameToGuiFrequency(const uint32_t i){ int UDPStandardImplementation::setAcquisitionPeriod(int64_t i){ - FILE_LOG(logDEBUG) << __AT__ << " called"; + FILE_LOG(logDEBUG1) << __AT__ << " called"; if(i >= 0){ acquisitionPeriod = i; @@ -705,7 +485,7 @@ int UDPStandardImplementation::setAcquisitionPeriod(int64_t i){ } int UDPStandardImplementation::setDynamicRange(const uint32_t i){ - FILE_LOG(logDEBUG) << __AT__ << " called"; + FILE_LOG(logDEBUG1) << __AT__ << " called"; int oldDynamicRange = dynamicRange; @@ -759,7 +539,7 @@ int UDPStandardImplementation::setDynamicRange(const uint32_t i){ int UDPStandardImplementation::setTenGigaEnable(const bool b){ - FILE_LOG(logDEBUG) << __AT__ << " called"; + FILE_LOG(logDEBUG1) << __AT__ << " called"; cout << "Info: Setting Ten Giga to " << string(b) << endl; bool oldTenGigaEnable = tengigaEnable; @@ -829,6 +609,10 @@ int UDPStandardImplementation::setTenGigaEnable(const bool b){ + + + + /************************************************************************* * Behavioral functions*************************************************** * They may modify the status of the receiver **************************** @@ -837,7 +621,7 @@ int UDPStandardImplementation::setTenGigaEnable(const bool b){ /***initial functions***/ int UDPStandardImplementation::setDetectorType(const slsReceiverDefs::detectorType d){ - FILE_LOG(logDEBUG) << __AT__ << " called"; + FILE_LOG(logDEBUG1) << __AT__ << " called"; cout << "Setting receiver type ..." << endl; @@ -857,7 +641,7 @@ int UDPStandardImplementation::setDetectorType(const slsReceiverDefs::detectorTy cout << "Info: ***** This is a " << slsDetectorBase::getDetectorType(d) << " Receiver *****" << endl; break; default: - cout << "Error: This is an unknown receiver type " << (int)d << endl; + cprintf(BG_RED, "Error: This is an unknown receiver type %d\n", (int)d); return FAIL; } @@ -934,9 +718,9 @@ int UDPStandardImplementation::setDetectorType(const slsReceiverDefs::detectorTy //delete threads and set number of listening threads if(myDetectorType == EIGER){ - pthread_mutex_lock(&status_mutex); + pthread_mutex_lock(&statusMutex); listeningThreadsMask = 0x0; - pthread_mutex_unlock(&(status_mutex)); + pthread_mutex_unlock(&(statusMutex)); if(threadStarted) createListeningThreads(true); numberofListeningThreads = MAX_NUMBER_OF_LISTENING_THREADS; @@ -949,11 +733,11 @@ int UDPStandardImplementation::setDetectorType(const slsReceiverDefs::detectorTy //create threads if(createListeningThreads() == FAIL){ cprintf(BG_RED,"Error: Could not create listening thread\n"); - exit (-1); + return FAIL; } if(createWriterThreads() == FAIL){ cprintf(BG_RED,"Error: Could not create writer threads\n"); - exit (-1); + return FAIL; } setThreadPriorities(); @@ -969,7 +753,7 @@ int UDPStandardImplementation::setDetectorType(const slsReceiverDefs::detectorTy /***acquisition functions***/ void UDPStandardImplementation::resetAcquisitionCount(){ - FILE_LOG(logDEBUG) << __AT__ << " starting"; + FILE_LOG(logDEBUG1) << __AT__ << " starting"; totalPacketsCaught = 0; acqStarted = false; @@ -980,7 +764,7 @@ void UDPStandardImplementation::resetAcquisitionCount(){ int UDPStandardImplementation::startReceiver(char *c=NULL){ - FILE_LOG(logDEBUG) << __AT__ << " called"; + FILE_LOG(logDEBUG1) << __AT__ << " called"; cout << "Info: Starting Receiver" << endl; @@ -1009,11 +793,11 @@ int UDPStandardImplementation::startReceiver(char *c=NULL){ guiDataReady=0; strcpy(guiFileName,""); //reset masks - pthread_mutex_lock(&status_mutex); + pthread_mutex_lock(&statusMutex); writerThreadsMask = 0x0; createFileMask = 0x0; fileCreateSuccess = false; - pthread_mutex_unlock(&status_mutex); + pthread_mutex_unlock(&statusMutex); //Print Receiver Configuration @@ -1024,6 +808,8 @@ int UDPStandardImplementation::startReceiver(char *c=NULL){ cout << "Info: Number of Jobs Per Buffer: " << numberofJobsPerBuffer << endl; if(FrameToGuiFrequency) cout << "Info: Frequency of frames sent to gui" << FrameToGuiFrequency << endl; + else + cout << "Info: Random frames sent to gui" << endl; @@ -1031,54 +817,84 @@ int UDPStandardImplementation::startReceiver(char *c=NULL){ if(createUDPSockets() == FAIL){ strcpy(c,"Could not create UDP Socket(s).\n"); cout << endl; - cout << "Error: "<< c << endl; + cprintf(BG_RED, "Error: %s\n",c); return FAIL; } if(setupWriter() == FAIL){ //stop udp socket shutDownUDPSockets(); - sprintf(c,"Could not create file %s.\n",savefilename); + sprintf(c,"Could not create file %s.\n",completeFileName); cout << endl; - cout << "Error: "<< c << endl; + cprintf(BG_RED, "Error: %s\n",c); return FAIL; } - //For compression, done to give the gui some proper name instead of always the last file name + //For compression, just for gui purposes if(dataCompressionEnable) - sprintf(savefilename, "%s/%s_fxxx_%d_xx.root", filePath,fileName,fileIndex); + sprintf(completeFileName, "%s/%s_fxxx_%d_xx.root", filePath,fileName,fileIndex); //initialize semaphore to synchronize between writer and gui reader threads sem_init(&writerGuiSemaphore,1,0); //status and thread masks - pthread_mutex_lock(&status_mutex); + pthread_mutex_lock(&statusMutex); status = RUNNING; - for(int i=0;i /proc/sys/net/core/rmem_max")) - cout << "\nWARNING: Could not change socket receiver buffer size in file /proc/sys/net/core/rmem_max" << endl; - else if(system("echo 250000 > /proc/sys/net/core/netdev_max_backlog")) - cout << "\nWARNING: Could not change max length of input queue in file /proc/sys/net/core/netdev_max_backlog" << endl; - - /** permanent setting heiner - net.core.rmem_max = 104857600 # 100MiB - net.core.netdev_max_backlog = 250000 - sysctl -p - // from the manual - sysctl -w net.core.rmem_max=16777216 - sysctl -w net.core.netdev_max_backlog=250000 - */ + if(status == RUNNING){ + //wait for all packets + uint64_t prev = totalPacketsCaught; + usleep(50000); + while(prev!=totalPacketsCaught){ + prev=totalPacketsCaught; + usleep(50000); } + //set status + pthread_mutex_lock(&statusMutex); + status = TRANSMITTING; + pthread_mutex_unlock(&statusMutex); + cout << "Info: Status: Transmitting" << endl; + } - -void UDPStandardImplementation::initializeMembers(){ - myDetectorType = GENERIC; - enableFileWrite = 1; - overwrite = 1; - fileIndex = 0; - scanTag = 0; - frameIndexNeeded = 0; + //shut down udp sockets and make listeners push dummy (end) packets for writers + shutDownUDPSockets(); +} - packetsCaught = 0; - totalPacketsCaught = 0; - startAcquisitionIndex = 0; - acquisitionIndex = 0; +void UDPStandardImplementation::readFrame(char* c,char** raw, uint64_t &startAcq, uint64_t &startFrame){ + FILE_LOG(logDEBUG1) << __AT__ << " called"; - frameIndexMask = 0; - packetIndexMask = 0; - frameIndexOffset = 0; - acquisitionPeriod = SAMPLE_TIME_IN_NS; - numberOfFrames = 0; - dynamicRange = 16; - shortFrame = -1; - currframenum = 0; - prevframenum = 0; + //point to gui data, to let writer thread know that gui is back for data + if (guiData == NULL){ + guiData = latestData; +#ifdef DEBUG4 + cprintf(CYAN,"Info: gui data not null anymore - ready to get data\n"); +#endif + } + + //copy data and filename + strcpy(c,guiFileName); + startAcq = startAcquisitionIndex; + startFrame = startFrameIndex; - nFrameToGui = 0; - dataCompression = false; - numListeningThreads = 1; - numWriterThreads = 1; - thread_started = 0; + //gui data not copied yet + if(!guiDataReady){ +#ifdef DEBUG4 + cprintf(CYAN,"Info: gui data not ready\n"); +#endif + *raw = NULL; + } + + //gui data ready, pass address to gui to copy the data + else{ +#ifdef DEBUG4 + cprintf(CYAN,"Info: gui data ready\n"); +#endif + *raw = guiData; + guiData = NULL; + + //for nth frame to gui, post semaphore so writer stops waiting + if((FrameToGuiFrequency) && (writerThreadsMask)){ +#ifdef DEBUG4 + cprintf(CYAN,"Info: gonna post\n"); +#endif + //release after getting data + sem_post(&smp); + } +#ifdef DEBUG4 + cprintf(CYAN,"Info: done post\n"); +#endif + + } +} - tengigaEnable = 0; +void UDPStandardImplementation::closeFile(int i){ + FILE_LOG(logDEBUG1) << __AT__ << " called for " << i ; + //normal + if(!dataCompressionEnable){ + if(sfilefd){ +#ifdef DEBUG4 + cprintf(YELLOW, "Going to close file:%d\n",fileno(sfilefd)); +#endif + fclose(sfilefd); + sfilefd = NULL; + } + } + //compression + else{ +#if (defined(MYROOT1) && defined(ALLFILE_DEBUG)) || !defined(MYROOT1) + if(sfilefd){ +#ifdef DEBUG4 + cout << "sfield:" << (int)sfilefd << endl; +#endif + fclose(sfilefd); + sfilefd = NULL; + } +#endif - eth = NULL; - - - - cmSub = NULL; - - - //diff threads - for(int i=0;iGetCurrentFile(); + + if(myFile[i]->Write()) + //->Write(tall->GetName(),TObject::kOverwrite); + cout << "Info: Thread " << i <<": wrote frames to file" << endl; + else + cout << "Info: Thread " << i << ": could not write frames to file" << endl; + + }else + cout << "Info: Thread " << i << ": could not write frames to file: No file or No Tree" << endl; + //close file + if(myTree[i] && myFile[i]) + myFile[i] = myTree[i]->GetCurrentFile(); + if(myFile[i] != NULL) + myFile[i]->Close(); + myFile[i] = NULL; + myTree[i] = NULL; + pthread_mutex_unlock(&writeMutex); + +#endif + } +} + + + + +/************************************************************************* + * Listening and Writing Threads ***************************************** + *************************************************************************/ + + +int UDPStandardImplementation::createListeningThreads(bool destroy){ + FILE_LOG(logDEBUG1) << __AT__ << " starting"; + + //reset masks + killAllListeningThreads = false; + pthread_mutex_lock(&statusMutex); + listeningThreadsMask = 0x0; + pthread_mutex_unlock(&(statusMutex)); + + //destroy + if(destroy){ + cout << "Info: Destroying Listening Thread(s)" << endl; + + killAllListeningThreads = true; + for(int i = 0; i < numberofListeningThreads; ++i){ + sem_post(&listenSemaphore[i]); + pthread_join(listeningThreads[i],NULL); + cout <<"."<getErrorStatus(); + if(!iret){ + cout << "Info: UDP port opened at port " << port[i] << endl; + }else{ +#ifdef VERBOSE + cprintf(BG_RED,"Error: Could not create UDP socket on port %d error: %d\n", port[i], iret); +#endif + shutDownUDPSockets(); + return FAIL; + } + } + + cout << "Info: UDP socket(s) created successfully." << endl; + cout << "Info: Listener Ready ..." << endl; + + return OK; +} + + + +int UDPStandardImplementation::setupWriter(){ + FILE_LOG(logDEBUG1) << __AT__ << " starting"; + + //acquisition start call back returns enable write + cbAction = DO_EVERYTHING; + if (startAcquisitionCallBack) + cbAction=startAcquisitionCallBack(filePath,fileName,fileIndex,bufferSize,pStartAcquisition); + + if(cbAction < DO_EVERYTHING){ + cout << "Info: Call back activated. Data saving must be taken care of by user in call back." << endl; + if (rawDataReadyCallBack) + cout << "Info: Data Write has been defined externally" << endl; + }else if(!fileWriteEnable) + cout << "Info: Data will not be saved" << endl; + + + + //creating first file + //setting all value to 1 + pthread_mutex_lock(&statusMutex); + for(int i=0; i DO_NOTHING){ + + //close file pointers + if(sfilefd){ + fclose(sfilefd); + sfilefd = NULL; + } + + //create file + if(!overwriteEnable){ + if (NULL == (sfilefd = fopen((const char *) (completeFileName), "wx"))){ + cprintf(BG_RED,"Error: Could not create/overwrite file %s\n",completeFileName); + return FAIL; + } + }else if (NULL == (sfilefd = fopen((const char *) (completeFileName), "w"))){ + cprintf(BG_RED,"Error: Could not create file %s\n",completeFileName); + return FAIL; + } + //setting file buffer size to 16mb + setvbuf(sfilefd,NULL,_IOFBF,BUF_SIZE); + + //Print packet loss and filenames + if(!packetsCaught){ + previousFrameNumber = -1; + cout << "Info: " << completeFileName << endl; + }else{ + cout << "Info:" << completeFileName + << "\tPacket Loss: " << setw(4)<startListening(); + return this_pointer; +} + + + +void* UDPStandardImplementation::startWritingThread(void* this_pointer){ + FILE_LOG(logDEBUG1) << __AT__ << " called"; + ((UDPStandardImplementation*)this_pointer)->startWriting(); + return this_pointer; +} + + + + +void UDPStandardImplementation::startListening(){ + FILE_LOG(logDEBUG1) << __AT__ << " called"; + + //set current thread value index + int ithread = currentThreadIndex; + //let calling function know thread started and obtained current + threadStarted = 1; + + + //variable definitions + int listenSize = 0; //listen to only 1 packet + uint32_t rc; //size of buffer received in bytes + //split frames + int carryonBufferSize; //from previous buffer to keep frames together in a buffer + char* tempBuffer = NULL; //temporary buffer to store split frames + if(myDetectorType != EIGER){ + listenSize = bufferSize * numberofJobsPerBuffer; //listen to more than 1 packet + tempBuffer = new char[onePacketSize * (packetsPerFrame - 1)]; //store maximum of 1 packets less in a frame + } + /* outer loop - loops once for each acquisition */ + //infinite loop, exited only to change dynamic range, 10G parameters etc (then recreated again) + while(true){ + + //reset parameters before acquisition + carryonBufferSize = 0; + + /* inner loop - loop for each buffer */ + //until mask unset (udp sockets shut down by client) + while((1 << ithread) & listeningThreadsMask){ + + //pop from fifo + fifoFree[ithread]->pop(buffer[ithread]); +#ifdef FIFODEBUG + cprintf(BLUE,"%d :Listener popped from fifofree %p\n", ithread, (void*)(buffer[ithread])); +#endif + + //udpsocket doesnt exist + if(udpSocket[ithread] == NULL){ + cprintf(RED, "Error: Thread %d :UDP Socket not created\n",ithread); + stopListening(ithread,0); + continue; + } + + rc = prepareAndListenBuffer(ithread, listenSize, carryonBufferSize, tempBuffer); + + //start indices for each start of scan/acquisition + if((!measurementStarted) && (rc > 0)){ + pthread_mutex_lock(&progressMutex); + if(!measurementStarted) + startFrameIndices(ithread); + pthread_mutex_unlock(&progressMutex); + } + + //problem in receiving or end of acquisition + if (status == TRANSMITTING){ + stopListening(ithread,rc); + continue; + } + + //write packet count to buffer + if(myDetectorType == EIGER) + (*((uint32_t*)(buffer[ithread]))) = 1; + //handling split frames and writing packet Count to buffer + else + (*((uint32_t*)(buffer[ithread]))) = processListeningBuffer(ithread, carryonBufferSize, tempBuffer); + + + //push buffer to FIFO + while(!fifo[ithread]->push(buffer[ithread])); +#ifdef FIFODEBUG + cprintf(BLUE,"Listening_Thread %d: Listener pushed into fifo %p\n",ithread, (void*)(buffer[ithread])); +#endif + + }/*--end of loop for each buffer (inner loop)*/ + + //end of acquisition, wait for next acquisition/change of parameters + sem_wait(&listenSemaphore[ithread]); + + //check to exit thread (for change of parameters) - only EXIT possibility + if(killAllListeningThreads){ + cprintf(GREEN,"Listening_Thread %d:Goodbye!\n",ithread); + //free resources at exit + if(tempBuffer) delete[] tempBuffer; + pthread_exit(NULL); + } + + }/*--end of loop for each acquisition (outer loop) */ +} + + + + + +int UDPStandardImplementation::prepareAndListenBuffer(int ithread, int lSize, int cSize, char* temp){ + FILE_LOG(logDEBUG1) << __AT__ << " called"; + + //listen to UDP packets + memcpy(buffer[ithread] + HEADER_SIZE_NUM_TOT_PACKETS, temp, cSize); + int receivedSize = udpSocket[ithread]->ReceiveDataOnly(buffer[ithread] + HEADER_SIZE_NUM_TOT_PACKETS + cSize, lSize + cSize); + + //throw away packets that is not one packet size, need to check status if socket is shut down + while(status != TRANSMITTING && myDetectorType == EIGER && receivedSize != onePacketSize) { + if(receivedSize != EIGER_HEADER_LENGTH) + cprintf(RED,"Listening_Thread %d: Listened to a weird packet size %d\n",receivedSize); +#ifdef DEBUG + else + cprintf(BLUE,"Listening_Thread %d: Listened to a header packet\n",ithread); +#endif + receivedSize = udpSocket[ithread]->ReceiveDataOnly(buffer[ithread] + HEADER_SIZE_NUM_TOT_PACKETS); + } + +#ifdef DEBUG + cprintf(BLUE, "Listening_Thread %d : Received bytes: %d. Expected bytes: %d\n", ithread, receivedSize, expected-cSize); +#endif + return receivedSize; +} + + +void UDPStandardImplementation::startFrameIndices(int ithread){ + FILE_LOG(logDEBUG1) << __AT__ << " called"; + + //determine startFrameIndex + switch(myDetectorType){ + case EIGER: + startFrameIndex = 0; //frame number always resets + break; + default: + if(shortFrameEnable < 0){ + startFrameIndex = (((((uint32_t)(*((uint32_t*)(buffer[ithread] + HEADER_SIZE_NUM_TOT_PACKETS))))+1) + & (frameIndexMask)) >> frameIndexOffset); + }else{ + startFrameIndex = ((((uint32_t)(*((uint32_t*)(buffer[ithread]+HEADER_SIZE_NUM_TOT_PACKETS)))) + & (frameIndexMask)) >> frameIndexOffset); + } + break; + } + + //start of entire acquisition + if(!acqStarted){ + startAcquisitionIndex = startFrameIndex; + acqStarted = true; + cprintf(BLUE,"Info: Thread %d: startAcquisitionIndex:%d\n",ithread,startAcquisitionIndex); + } + + //set start of scan/real time measurement + cprintf(BLUE,"Info: Thread %d: startFrameIndex: %d\n", ithread,startFrameIndex); + measurementStarted = true; +} + + + + + +void UDPStandardImplementation::stopListening(int ithread, int numbytes){ + FILE_LOG(logDEBUG1) << __AT__ << " called"; + + cout << "Info: Stop Listening. Status:" << slsDetectorBase::runStatusType(status) << endl; + + + //less than 1 packet size (especially for eiger), ignore the buffer (so that 2 dummy buffers are not sent with pc=0) + if(numbytes < onePacketSize) + numbytes = 0; + + + //free empty buffer + if(numbytes <= 0){ + cprintf(BLUE,"Info: Thread %d :End of Acquisition for Listening Thread\n", ithread); + while(!fifoFree[ithread]->push(buffer[ithread])); +#ifdef FIFODEBUG + cprintf(BLUE,"Listening_Thread %d :Listener push empty buffer into fifofree %p\n", ithread, (void*)(buffer[ithread])); #endif } - - - strcpy(savefilename,""); - - - //strcpy(filePath,""); - //strcpy(fileName,"run"); - - - - //status - pthread_mutex_lock(&status_mutex); - status = IDLE; - pthread_mutex_unlock(&(status_mutex)); - -} - - - -UDPStandardImplementation::~UDPStandardImplementation(){ FILE_LOG(logDEBUG) << __AT__ << " called"; - - createListeningThreads(true); - createWriterThreads(true); - deleteMembers(); -} - - - - -void UDPStandardImplementation::deleteMembers(){ FILE_LOG(logDEBUG) << __AT__ << " called"; - - //kill threads - if(thread_started){ - createListeningThreads(true); - createWriterThreads(true); + //push last non empty buffer into fifo + else{ + (*((uint32_t*)(buffer[ithread]))) = numbytes/onePacketSize; + totalListeningFrameCount[ithread] += (numbytes/onePacketSize); +#ifdef DEBUG + cprintf(BLUE,"Listening_Thread %d: Last Buffer numBytes:%d\n",ithread, numbytes); + cprintf(BLUE,"Listening_Thread %d: Last Buffer packet count:%d\n",ithread, numbytes/onePacketSize); +#endif + while(!fifo[ithread]->push(buffer[ithread])); +#ifdef FIFODEBUG + cprintf(BLUE,"Listening_Thread %d: Listener Last Buffer pushed into fifo %p\n", ithread,(void*)(buffer[ithread])); +#endif } - for(int i=0;ipop(buffer[ithread]); + //creating dummy-end buffer with pc=0xFFFF + (*((uint32_t*)(buffer[ithread]))) = dummyPacketValue; + while(!fifo[ithread]->push(buffer[ithread])); +#ifdef FIFODEBUG + cprintf(BLUE,"Listening_Thread %d: Listener pushed dummy-end buffer into fifo %p\n", ithread,(void*)(buffer[ithread])); +#endif + } + + + //reset mask and exit loop + pthread_mutex_lock(&statusMutex); + listeningThreadsMask^=(1< 1) + cprintf(BLUE,"Listening_Thread %d: Waiting for other listening threads to be done.. current mask:0x%x\n", ithread, listeningThreadsMask); +#endif + while(listeningThreadsMask) + usleep(5000); +#ifdef DEBUG4 + int t=0; + for(i=0;i> frameIndexOffset)); +#endif + cSize = onePacketSize; + --packetCount; + } } - if(receiverdata[i]){ - delete receiverdata[i]; - receiverdata[i] = NULL; - } - } - shutDownUDPSockets(); - if(eth) {delete [] eth; eth = NULL;} - if(latestData) {delete [] latestData; latestData = NULL;} +#ifdef DEBUG4 + cprintf(BLUE, "Listening_Thread %d: First Header:%d\n", (((((uint32_t)(*((uint32_t*)(buffer[ithread] + HEADER_SIZE_NUM_TOT_PACKETS))))+1) + & (frameIndexMask)) >> frameIndexOffset)); +#endif + break; - for(int i=0;i> frameIndexOffset), + ((((uint32_t)(*((uint32_t*)(buffer[ithread]+HEADER_SIZE_NUM_TOT_PACKETS))))) & (packetIndexMask)), + (((((uint32_t)(*((uint32_t*)(buffer[ithread]+lastpacketoffset))))) & (frameIndexMask)) >> frameIndexOffset), + ((((uint32_t)(*((uint32_t*)(buffer[ithread]+lastpacketoffset))))) & (packetIndexMask)), + lastPacketOffset); +#endif + //moench last packet value is 0, so find the last packet and store the others in a temp storage + if( ((((uint32_t)(*((uint32_t*)(buffer[ithread]+lastPacketOffset))))) & (packetIndexMask))){ + lastFrameHeader = ((((uint32_t)(*((uint32_t*)(buffer[ithread]+lastPacketOffset))))) + & (frameIndexMask)) >> frameIndexOffset; + cSize += onePacketSize; + lastPacketOffset -= onePacketSize; + --packetCount; + while (lastFrameHeader == (((((uint32_t)(*((uint32_t*)(buffer[ithread]+lastPacketOffset))))) & (frameIndexMask)) >> frameIndexOffset)){ + cSize += onePacketSize; + lastPacketOffset -= onePacketSize; + --packetCount; + } + memcpy(temp, buffer[ithread]+(lastPacketOffset+onePacketSize), cSize); +#ifdef DEBUG4 + cprintf(BLUE, "Listening_Thread %d: temp Header:%d\t temp Packet:%d\n", + (((((uint32_t)(*((uint32_t*)(temp)))))& (frameIndexMask)) >> frameIndexOffset), + ((((uint32_t)(*((uint32_t*)(temp))))) & (packetIndexMask))); +#endif + } + break; + + default: + cprintf(RED,"Listening_Thread %d: Error: This detector is not implemented in the receiver" + + slsDetectorBase::getDetectorType(myDetectorType).c_str() + "\n"); + break; } +#ifdef DEBUG4 + cprintf(BLUE,"Listening_Thread %d: PacketCount:%d CarryonBufferSize:%d\n",ithread, packetCount, cSize); +#endif + + return packetCount; +} + + + + + + +void UDPStandardImplementation::startWriting(){ + FILE_LOG(logDEBUG1) << __AT__ << " called"; + + //set current thread value index + int ithread = currentThreadIndex; + //let calling function know thread started and obtained current + threadStarted = 1; + + //variable definitions + char* wbuf[MAX_NUMBER_OF_LISTENING_THREADS] = NULL; + sfilefd = NULL; + + + /* outer loop - loops once for each acquisition */ + //infinite loop, exited only to change dynamic range, 10G parameters etc (then recreated again) + while(true){ + + //--reset parameters before acquisition + //--end of reset parameters before acquisition + + /* inner loop - loop for each buffer */ + //until mask unset (udp sockets shut down by client) + while((1 << ithread) & writerThreadsMask){ + + + + }/*--end of loop for each buffer (inner loop)*/ + + + //in case they are not closed already + closeFile(); +#ifdef DEBUG4 + cprintf(GREEN,"Writing_Thread %d: Done with acquisition. Waiting for 1st sem to create new file/change of parameters\n", ithread); +#endif + //end of acquisition, wait for file create/change of parameters + sem_wait(&writerSemaphore[ithread]); + //check to exit thread (for change of parameters) - only EXIT possibility + if(killAllWritingThreads){ + cprintf(GREEN,"Writing_Thread %d:Goodbye!\n",ithread); + //free resources at exit + for(int i=0; i DO_NOTHING){ - //close - if(sfilefd){ - if(fclose(sfilefd)){ - cprintf(RED, "file close problem %d\n",fileno(sfilefd)); - fclose(sfilefd); - } - sfilefd = NULL; - } - - //open file - if(!overwrite){ - if (NULL == (sfilefd = fopen((const char *) (savefilename), "wx"))){ - cprintf(BG_RED,"Error: Could not create new file %s\n",savefilename); - return FAIL; - } - }else if (NULL == (sfilefd = fopen((const char *) (savefilename), "w"))){ - cprintf(BG_RED,"Error: Could not create file %s\n",savefilename); - return FAIL; - } - //setting buffer - setvbuf(sfilefd,NULL,_IOFBF,BUF_SIZE); - - - //printing packet losses and file names - if(!packetsCaught) - cout << savefilename << endl; - else{ - cout << savefilename - << "\tpacket loss " - << setw(4)<GetCurrentFile(); - - if(myFile[ithr]->Write()) - //->Write(tall->GetName(),TObject::kOverwrite); - cout << "Thread " << ithr <<": wrote frames to file" << endl; - else - cout << "Thread " << ithr << ": could not write frames to file" << endl; - - }else - cout << "Thread " << ithr << ": could not write frames to file: No file or No Tree" << endl; - //close file - if(myTree[ithr] && myFile[ithr]) - myFile[ithr] = myTree[ithr]->GetCurrentFile(); - if(myFile[ithr] != NULL) - myFile[ithr]->Close(); - myFile[ithr] = NULL; - myTree[ithr] = NULL; - pthread_mutex_unlock(&write_mutex); - -#endif - } -} - - - - -/** - * Pre: status is running, semaphores have been instantiated, - * Post: udp sockets shut down, status is idle, sempahores destroyed - * */ - -int UDPStandardImplementation::stopReceiver(){ - FILE_LOG(logDEBUG) << __AT__ << " called"; - - if(status != IDLE){ - //#ifdef VERBOSE - cout << "Stopping Receiver" << endl; - //#endif - - startReadout(); - - while(status == TRANSMITTING){ - sem_post(&smp); - usleep(5000); - } - - //semaphore destroy - sem_destroy(&smp); - - //change status - pthread_mutex_lock(&status_mutex); - status = IDLE; - pthread_mutex_unlock(&(status_mutex)); - - cout << "Receiver Stopped.\nStatus:" << status << endl << endl; - }else cout <<" Not idle to stop receiver" << endl; - - - //sem_post(&smp); - - return OK; -} - - - - -/** - * Pre: status is running, udp sockets have been initialized, - * stop receiver initiated - * Post:udp sockets closed, status is transmitting - * */ -void UDPStandardImplementation::startReadout(){ - FILE_LOG(logDEBUG) << __AT__ << " called"; - - //#ifdef VERBOSE - cout << "Start Receiver Readout" << endl; - //#endif - - if(status == RUNNING){ - - //wait so that all packets which take time has arrived - usleep(5000); - - /********************************************/ - //usleep(10000000); - //usleep(2000000); - uint32_t prev = totalPacketsCaught; - usleep(50000); - while(prev!=totalPacketsCaught){ - prev=totalPacketsCaught; - usleep(50000); - } - pthread_mutex_lock(&status_mutex); - status = TRANSMITTING; - pthread_mutex_unlock(&status_mutex); - cout << "Status: Transmitting" << endl; - } - - //kill udp socket to tell the listening thread to push last packet - shutDownUDPSockets(); - -} - - - -void* UDPStandardImplementation::startListeningThread(void* this_pointer){ - FILE_LOG(logDEBUG) << __AT__ << " called"; - ((UDPStandardImplementation*)this_pointer)->startListening(); - - return this_pointer; -} - - - -void* UDPStandardImplementation::startWritingThread(void* this_pointer){ - FILE_LOG(logDEBUG) << __AT__ << " called"; - ((UDPStandardImplementation*)this_pointer)->startWriting(); - return this_pointer; -} - - - - - - -int UDPStandardImplementation::startListening(){ - FILE_LOG(logDEBUG) << __AT__ << " called"; - int ithread = currentListeningThreadIndex; -#ifdef VERYVERBOSE - cprintf(BLUE, "In startListening()\n "); -#endif - - thread_started = 1; - - int total; - int lastpacketoffset, expected, rc,packetcount, maxBufferSize, carryonBufferSize; - uint32_t lastframeheader;// for moench to check for all the packets in last frame - char* tempchar = NULL; - - while(1){ - //variables that need to be checked/set before each acquisition - carryonBufferSize = 0; - maxBufferSize = bufferSize * numJobsPerThread; -#ifdef VERYDEBUG - cprintf(BLUE, "%d maxBufferSize:%d carryonBufferSize:%d\n", ithread,maxBufferSize,carryonBufferSize); -#endif - - //missing packets compensation in listening thread - if(tempchar) {delete [] tempchar;tempchar = NULL;} - if(myDetectorType != EIGER) - tempchar = new char[onePacketSize * ((packetsPerFrame/numListeningThreads) - 1)]; //gotthard: 1packet size, moench:39 packet size - else - maxBufferSize = 0; - - - while((1<pop(buffer[ithread]); -#ifdef FIFO_DEBUG - cprintf(BLUE,"%d listener popped from fifofree %x\n", ithread, (void*)(buffer[ithread])); -#endif - - - - //ensure udpsocket exists - if(udpSocket[ithread] == NULL){ - rc = 0; - cprintf(BLUE, "%d UDP Socket is NULL\n",ithread); - } - - - //normal listening - else if(!carryonBufferSize){ -#ifdef SOCKET_DEBUG - if(!ithread){ -#endif - rc = udpSocket[ithread]->ReceiveDataOnly(buffer[ithread] + HEADER_SIZE_NUM_TOT_PACKETS, maxBufferSize); - if(rc == EIGER_HEADER_LENGTH && myDetectorType == EIGER) { - while(rc == EIGER_HEADER_LENGTH){ - rc = udpSocket[ithread]->ReceiveDataOnly(buffer[ithread] + HEADER_SIZE_NUM_TOT_PACKETS, maxBufferSize); - } - } - expected = maxBufferSize; -#ifdef SOCKET_DEBUG - }else{ - while(1) usleep(100000000); - } -#endif - } - - - //the remaining packets from previous buffer, copy it and listen to n less frame - else{ -#ifdef VERYDEBUG - cprintf(BLUE, "%d carry on buffer size:%d\n",ithread,carryonBufferSize); - cprintf(BLUE, "%d framennum in tempchar:%d\n",((((uint32_t)(*((uint32_t*)tempchar))) - & (frameIndexMask)) >> frameIndexOffset)); - cprintf(BLUE, "%d tempchar packet:%d\n", ((((uint32_t)(*((uint32_t*)(tempchar))))) - & (packetIndexMask))); -#endif - memcpy(buffer[ithread] + HEADER_SIZE_NUM_TOT_PACKETS, tempchar, carryonBufferSize); - rc = udpSocket[ithread]->ReceiveDataOnly((buffer[ithread] + HEADER_SIZE_NUM_TOT_PACKETS + carryonBufferSize),maxBufferSize - carryonBufferSize); - expected = maxBufferSize - carryonBufferSize; - } - - -#ifdef EIGER_DEBUG - cprintf(BLUE, "%d rc: %d. expected: %d\n", ithread, rc, expected); -#endif - - - //start indices for each start of scan/acquisition - if((!measurementStarted) && (rc > 0)){ - pthread_mutex_lock(&progress_mutex); - if(!measurementStarted) - startFrameIndices(ithread, rc); - pthread_mutex_unlock(&progress_mutex); - } - - - //problem in receiving or end of acquisition - if (status == TRANSMITTING){ - stopListening(ithread,rc,packetcount,total); - continue; - } - - - //reset - packetcount = (packetsPerFrame/numListeningThreads) * numJobsPerThread; - carryonBufferSize = 0; - - - - //check if last packet valid and calculate packet count - switch(myDetectorType){ - case MOENCH: - lastpacketoffset = (((numJobsPerThread * packetsPerFrame - 1) * onePacketSize) + HEADER_SIZE_NUM_TOT_PACKETS); -#ifdef VERYDEBUG - cout <<"first packet:"<< ((((uint32_t)(*((uint32_t*)(buffer[ithread]+HEADER_SIZE_NUM_TOT_PACKETS))))) & (packetIndexMask)) << endl; - cout <<"first header:"<< (((((uint32_t)(*((uint32_t*)(buffer[ithread]+HEADER_SIZE_NUM_TOT_PACKETS))))) & (frameIndexMask)) >> frameIndexOffset) << endl; - cout << "last packet offset:" << lastpacketoffset << endl; - cout <<"last packet:"<< ((((uint32_t)(*((uint32_t*)(buffer[ithread]+lastpacketoffset))))) & (packetIndexMask)) << endl; - cout <<"last header:"<< (((((uint32_t)(*((uint32_t*)(buffer[ithread]+lastpacketoffset))))) & (frameIndexMask)) >> frameIndexOffset) << endl; -#endif - //moench last packet value is 0 - if( ((((uint32_t)(*((uint32_t*)(buffer[ithread]+lastpacketoffset))))) & (packetIndexMask))){ - lastframeheader = ((((uint32_t)(*((uint32_t*)(buffer[ithread]+lastpacketoffset))))) & (frameIndexMask)) >> frameIndexOffset; - carryonBufferSize += onePacketSize; - lastpacketoffset -= onePacketSize; - --packetcount; - while (lastframeheader == (((((uint32_t)(*((uint32_t*)(buffer[ithread]+lastpacketoffset))))) & (frameIndexMask)) >> frameIndexOffset)){ - carryonBufferSize += onePacketSize; - lastpacketoffset -= onePacketSize; - --packetcount; - } - memcpy(tempchar, buffer[ithread]+(lastpacketoffset+onePacketSize), carryonBufferSize); -#ifdef VERYDEBUG - cout << "tempchar header:" << (((((uint32_t)(*((uint32_t*)(tempchar))))) - & (frameIndexMask)) >> frameIndexOffset) << endl; - cout <<"tempchar packet:"<< ((((uint32_t)(*((uint32_t*)(tempchar))))) - & (packetIndexMask)) << endl; -#endif - } - break; - - case GOTTHARD: - case PROPIX: - if(shortFrame == -1){ - lastpacketoffset = (((numJobsPerThread * packetsPerFrame - 1) * onePacketSize) + HEADER_SIZE_NUM_TOT_PACKETS); -#ifdef VERYDEBUG - cprintf(BLUE, "%d last packet offset:%d\n",ithread, lastpacketoffset); -#endif - //if not last packet - if((unsigned int)(packetsPerFrame -1) != ((((uint32_t)(*((uint32_t*)(buffer[ithread]+lastpacketoffset))))+1) & (packetIndexMask))){ - memcpy(tempchar,buffer[ithread]+lastpacketoffset, onePacketSize); -#ifdef VERYDEBUG - cprintf(BLUE, "%d tempchar header:%d\n",ithread,(((((uint32_t)(*((uint32_t*)(tempchar))))+1) - & (frameIndexMask)) >> frameIndexOffset)); -#endif - carryonBufferSize = onePacketSize; - --packetcount; - } - } -#ifdef VERYDEBUG - cprintf(BLUE, "%d header:%d\n", (((((uint32_t)(*((uint32_t*)(buffer[ithread] + HEADER_SIZE_NUM_TOT_PACKETS))))+1) - & (frameIndexMask)) >> frameIndexOffset)); -#endif - break; - - - - case EIGER: - //because even headers might be included, so not packet count - (*((uint32_t*)(buffer[ithread]))) = rc; - packetcount = 1; - break; - - default: - break; - } - - - - //write packet count and push -#ifdef VERYDEBUG - cprintf(BLUE, "%d packetcount:%d carryonbuffer:%d\n", ithread, packetcount, carryonBufferSize); -#endif - if(myDetectorType != EIGER) - (*((uint32_t*)(buffer[ithread]))) = packetcount; - totalListeningFrameCount[ithread] += packetcount; -#ifdef VERYDEBUG - cprintf(BLUE,"%d listener going to push fifo: 0x%x\n", ithread,(void*)(buffer[ithread])); -#endif - while(!fifo[ithread]->push(buffer[ithread])); -#ifdef FIFO_DEBUG - cprintf(BLUE, "%d listener pushed into fifo %x\n",ithread, (void*)(buffer[ithread])); -#endif - - - - } - - sem_wait(&listensmp[ithread]); - - //make sure its not exiting thread - if(killAllListeningThreads){ - cout << ithread << " good bye listening thread" << endl; - if(tempchar) {delete [] tempchar;tempchar = NULL;} - pthread_exit(NULL); - } - - if(tempchar) {delete [] tempchar;tempchar = NULL;} - } - - return OK; -} - - - - - - - @@ -1946,16 +1978,10 @@ int UDPStandardImplementation::startListening(){ int UDPStandardImplementation::startWriting(){ - FILE_LOG(logDEBUG) << __AT__ << " called"; + FILE_LOG(logDEBUG1) << __AT__ << " called"; - int ithread = currentWriterThreadIndex; -#ifdef VERYVERBOSE - cprintf(GREEN,"%d In startWriting()\n", ithread); -#endif - thread_started = 1; - char* wbuf[numListeningThreads];//interleaved char *d=new char[bufferSize*numListeningThreads]; int xmax=0,ymax=0; int ret,i,j; @@ -2468,66 +2494,9 @@ int UDPStandardImplementation::startWriting(){ } } -#ifdef VERYVERBOSE - cprintf(GREEN,"%d gonna wait for 1st sem\n", ithread); -#endif - //wait - sem_wait(&writersmp[ithread]); - if(killAllWritingThreads){ - for(i=0;i> frameIndexOffset); - else - startFrameIndex = ((((uint32_t)(*((uint32_t*)(buffer[ithread]+HEADER_SIZE_NUM_TOT_PACKETS)))) - & (frameIndexMask)) >> frameIndexOffset); - - - //start of acquisition - if(!acqStarted){ - startAcquisitionIndex=startFrameIndex; - //currframenum = startAcquisitionIndex; - acqStarted = true; - cprintf(BLUE,"%d startAcquisitionIndex:%d\n", ithread, startAcquisitionIndex); - } - - cprintf(BLUE,"%d startFrameIndex: %d\n", ithread,startFrameIndex); - prevframenum=startFrameIndex-1; //so that there is no packet loss, when currframenum(max,20) - prevframenum(1) - measurementStarted = true; - -} - - - -void UDPStandardImplementation::stopListening(int ithread, int rc, int &pc, int &t){ - FILE_LOG(logDEBUG) << __AT__ << " called"; - - - int i; - -#ifdef VERYVERBOSE - cprintf(BLUE, "%d Stop Listening\n", ithread); -#endif - - - if(status != TRANSMITTING){ - cprintf(BG_RED,"%d *** udp socket not shut down from client ***********************\n", ithread); - while(!fifoFree[ithread]->push(buffer[ithread])); - exit(-1); - } - - - //free buffer - if(rc <= 0){ - cprintf(BLUE,"%d End of acquisition for Listening Thread\n", ithread); - while(!fifoFree[ithread]->push(buffer[ithread])); -#ifdef FIFO_DEBUG - cprintf(BLUE,"%d listener empty buffer pushed into fifofree %x\n", ithread, (void*)(buffer[ithread])); -#endif - } - - - //push the last buffer into fifo - else{ - if(myDetectorType == EIGER){ - (*((uint32_t*)(buffer[ithread]))) = rc; - pc = 1; - }else{ - pc = (rc/onePacketSize); - (*((uint32_t*)(buffer[ithread]))) = pc; - } -#ifdef VERYDEBUG - cprintf(BLUE,"%d last rc:%d\n",ithread, rc); - cprintf(BLUE,"%d last packetcount:%d\n", ithread, pc); -#endif - - totalListeningFrameCount[ithread] += pc; - while(!fifo[ithread]->push(buffer[ithread])); -#ifdef FIFO_DEBUG - cprintf(BLUE,"%d listener last buffer pushed into fifo %x\n", ithread,(void*)(buffer[ithread])); -#endif - } - - - - - //push dummy buffer to all writer threads - for(i=0;ipop(buffer[ithread]); -#ifdef FIFO_DEBUG - cprintf(BLUE,"%d listener popped dummy buffer from fifofree %x\n", ithread,(void*)(buffer[ithread])); -#endif - (*((uint32_t*)(buffer[ithread]))) = 0x0; -#ifdef VERYDEBUG - cprintf(BLUE,"%d dummy buffer num packets:%d\n", ithread(*((uint16_t*)(buffer[ithread])))); -#endif - while(!fifo[ithread]->push(buffer[ithread])); -#ifdef FIFO_DEBUG - cprintf(BLUE,"%d listener pushed dummy buffer into fifo %x\n", ithread,(void*)(buffer[ithread])); -#endif - } - - - - //reset mask and exit loop - pthread_mutex_lock(&status_mutex); - listeningthreads_mask^=(1< 1) - cprintf(BLUE,"%d Waiting for listening to be done.. current mask:0x%x\n", ithread, listeningthreads_mask); -#endif - while(listeningthreads_mask) - usleep(5000); -#ifdef VERYDEBUG - t = 0; - for(i=0;i Date: Wed, 14 Oct 2015 09:11:40 +0200 Subject: [PATCH 37/68] again --- .../include/UDPStandardImplementation.h | 2 + .../src/UDPStandardImplementation.cpp | 110 +++++++++++++++--- 2 files changed, 93 insertions(+), 19 deletions(-) diff --git a/slsReceiverSoftware/include/UDPStandardImplementation.h b/slsReceiverSoftware/include/UDPStandardImplementation.h index cbd46d433..bbe526c40 100644 --- a/slsReceiverSoftware/include/UDPStandardImplementation.h +++ b/slsReceiverSoftware/include/UDPStandardImplementation.h @@ -367,6 +367,8 @@ private: */ uint32_t processListeningBuffer(int ithread, int cSize,char* temp); + bool popAndCheckEndofAcquisition(char* wbuffer[], bool ready[], uint32_t nP[],char* toFree[],int toFreeOffset[]); + /************************************************************************* * Class Members ********************************************************* *************************************************************************/ diff --git a/slsReceiverSoftware/src/UDPStandardImplementation.cpp b/slsReceiverSoftware/src/UDPStandardImplementation.cpp index 7fa6310df..f4d2d968f 100644 --- a/slsReceiverSoftware/src/UDPStandardImplementation.cpp +++ b/slsReceiverSoftware/src/UDPStandardImplementation.cpp @@ -20,6 +20,7 @@ #include #include #include +#include using namespace std; #define WRITE_HEADERS @@ -1718,8 +1719,15 @@ void UDPStandardImplementation::startWriting(){ threadStarted = 1; //variable definitions - char* wbuf[MAX_NUMBER_OF_LISTENING_THREADS] = NULL; - sfilefd = NULL; + char* wbuf[numberofListeningThreads]; //buffer popped from FIFO + sfilefd = NULL; //file pointer + bool popReady[numberofListeningThreads]; //if the FIFO can be popped + uint32_t numPackets[numberofListeningThreads]; //number of packets popped from the FIFO + //eiger specific + int MAX_NUM_PACKETS = 1024; //highest 32 bit has 1024 number of packets + char* toFreePointers[MAX_NUM_PACKETS]; //pointers to free for each frame + int toFreePointersOffset[numberofListeningThreads]; //offset of pointers to free added for each thread + /* outer loop - loops once for each acquisition */ @@ -1727,6 +1735,15 @@ void UDPStandardImplementation::startWriting(){ while(true){ //--reset parameters before acquisition + for(int i=0; ipop(wbuffer[i]); +#ifdef FIFODEBUG + cprintf(GREEN,"Writing_Thread %d: Popped %p from FIFO %d\n", ithread, (void*)(wbuffer[i]),i); +#endif + val = (uint32_t)(*((uint32_t*)wbuffer[i])); + if(val < 0) + cprintf(BG_RED,"Error: Negative packet numbers: %d for FIFO %d\n",val,i); + nP[i] = abs(val); +#ifdef DEBUG4 + cprintf(GREEN,"Writing_Thread %d: Number of Packets: %d for FIFO %d\n", ithread, nP[i], i); +#endif + //dummy-end buffer + if(nP[i] == dummyPacketValue){ + ready[i] = false; +#ifdef DEBUG3 + cprintf(GREEN,"Writing_Thread %d: Dummy frame popped out of FIFO %d",ithread, i); +#endif + } + //normal buffer popped out + else{ + endofAcquisition = false; +#ifdef DEBUG4 + switch(myDetectorType){ + case EIGER: + wbuf_footer = (eiger_packet_footer_t*)(wbuffer[i] + footerOffset + HEADER_SIZE_NUM_TOT_PACKETS); + //cprintf(BLUE,"footer value:0x%x\n",i,(uint64_t)(*( (uint64_t*) wbuf_footer))); + cprintf(BLUE,"Fnum[%d]:%d\n",i,(uint32_t)(*( (uint64_t*) wbuf_footer))); + cprintf(BLUE,"Pnum[%d]:%d\n",i,*( (uint16_t*) wbuf_footer->packetNumber)); + break; + default: break; + } +#endif + if(myDetectorType == EIGER){ + toFree[toFreeOffset[i]] = wbuffer[i]; + toFreeOffset[i]++; + } + } + } + } + + return endofAcquisition; +} @@ -1987,23 +2070,21 @@ int UDPStandardImplementation::startWriting(){ int ret,i,j; bool endofacquisition; - int numpackets[numListeningThreads], nf; - bool fullframe[numListeningThreads],popready[numListeningThreads]; + int nf; + bool fullframe[numListeningThreads]; volatile uint32_t tempframenum[numListeningThreads]; uint32_t presentframenum; uint32_t lastpacketheader[numListeningThreads], currentpacketheader[numListeningThreads]; int numberofmissingpackets[numListeningThreads]; - int MAX_VALUE = 1024;//32 bit number of packets - char* tofree[MAX_VALUE]; + + char* tempbuffer[MAX_VALUE]; char* blankframe[MAX_VALUE]; - int tofreeoffset[numListeningThreads]; int tempoffset[numListeningThreads]; int blankoffset; for(i=0;ipacketnum)); #endif - }else if(numpackets[i] == EIGER_HEADER_LENGTH){ - cprintf(BG_RED, "got header in writer, weirdd packetsize:%d\n",numpackets[i]); - exit(-1); } -#ifdef EIGER_DEBUG3 - else { - cprintf(BG_RED, "got weird in writer, weirdd packetsize:%d\n",numpackets[i]); - } -#endif + if(myDetectorType == EIGER){ tofree[tofreeoffset[i]] = wbuf[i]; tofreeoffset[i]++; From a3e12e795526213c352443734d67d64e7fb14b9b Mon Sep 17 00:00:00 2001 From: Dhanya Maliakal Date: Thu, 15 Oct 2015 12:11:06 +0200 Subject: [PATCH 38/68] somewhere --- .../include/UDPStandardImplementation.h | 37 ++++- .../include/sls_receiver_defs.h | 8 +- .../src/UDPBaseImplementation.cpp | 18 +- .../src/UDPStandardImplementation.cpp | 155 ++++++++---------- 4 files changed, 106 insertions(+), 112 deletions(-) diff --git a/slsReceiverSoftware/include/UDPStandardImplementation.h b/slsReceiverSoftware/include/UDPStandardImplementation.h index bbe526c40..0c1d4ac43 100644 --- a/slsReceiverSoftware/include/UDPStandardImplementation.h +++ b/slsReceiverSoftware/include/UDPStandardImplementation.h @@ -77,8 +77,9 @@ class UDPStandardImplementation: private virtual slsReceiverDefs, public UDPBase * Overridden method * Set data compression, by saving only hits (so far implemented only for Moench and Gotthard) * @param b true for data compression enable, else false + * @return OK or FAIL */ - void setDataCompressionEnable(const bool b); + int setDataCompressionEnable(const bool b); //***acquisition parameters*** /** @@ -367,7 +368,33 @@ private: */ uint32_t processListeningBuffer(int ithread, int cSize,char* temp); - bool popAndCheckEndofAcquisition(char* wbuffer[], bool ready[], uint32_t nP[],char* toFree[],int toFreeOffset[]); + /** + * Called by StartWriting + * Pops buffer from all the FIFOs and checks for dummy frames and end of acquisition + * @param ithread current thread index + * @param wbuffer the buffer array that is popped from all the FIFOs + * @param ready if that FIFO is allowed to pop (depends on if dummy buffer already popped/ waiting for other FIFO to finish a frame(eiger)) + * @param nP number of packets in the buffer popped out + * @param toFree array of addresses to pop into fifoFree (eiger specific) + * @param toFreeOffset the number of addresses to free for each FIFO (eiger specific) + * @return true if end of acquisition else false + */ + bool popAndCheckEndofAcquisition(int ithread, char* wbuffer[], bool ready[], uint32_t nP[],char* toFree[],int toFreeOffset[]); + + /** + * Called by StartWriting + * When dummy-end buffers are popped from all FIFOs (acquisition over), this is called + * It frees the FIFO addresses, closes all files + * For data compression, it waits for all threads to be done + * Changes the status to RUN_FINISHED and prints statistics + * @param ithread writing thread index + * @param wbuffer writing buffer popped out from FIFO + */ + void stopWriting(int ithread, char* wbuffer[]); + + void processWritingBuffer(int ithread, char* wbuffer[], uint32_t nP[]); + void processWritingBufferPacketByPacket(); + /************************************************************************* * Class Members ********************************************************* @@ -669,11 +696,7 @@ private: */ void writeToFile_withoutCompression(char* buf[],int numpackets, uint32_t framenum); - /** - * When acquisition is over, this is called - * @param ithread listening thread number - */ - void stopWriting(int ithread, char* wbuffer[]); + /** * updates parameters and writes to file when not a dummy frame diff --git a/slsReceiverSoftware/include/sls_receiver_defs.h b/slsReceiverSoftware/include/sls_receiver_defs.h index 04b8b19fb..fe0c715b1 100755 --- a/slsReceiverSoftware/include/sls_receiver_defs.h +++ b/slsReceiverSoftware/include/sls_receiver_defs.h @@ -8,8 +8,10 @@ #endif #include +#include #include "ansi.h" + typedef double double32_t; typedef float float32_t; typedef int int32_t; @@ -115,9 +117,9 @@ public: \param b true or false \returns string enabled, disabled */ - static string stringEnable(bool b){\ - if(b) return string("enabled"); \ - else return string("disabled"); \ + static std::string stringEnable(bool b){\ + if(b) return std::string("enabled"); \ + else return std::string("disabled"); \ }; diff --git a/slsReceiverSoftware/src/UDPBaseImplementation.cpp b/slsReceiverSoftware/src/UDPBaseImplementation.cpp index 75f7fa244..18e43edb5 100644 --- a/slsReceiverSoftware/src/UDPBaseImplementation.cpp +++ b/slsReceiverSoftware/src/UDPBaseImplementation.cpp @@ -5,9 +5,9 @@ ***********************************************/ #include "UDPBaseImplementation.h" +#include "genericSocket.h" #include // stat - #include #include using namespace std; @@ -75,10 +75,6 @@ UDPBaseImplementation::~UDPBaseImplementation(){ FILE_LOG(logDEBUG) << __AT__ << " starting"; cout << "Info: Deleting base member pointers" << endl; - if(detHostname) {delete [] detHostname; detHostname = NULL;} - if(eth) {delete [] eth; eth = NULL;} - if(fileName) {delete [] fileName; fileName = NULL;} - if(filePath) {delete [] filePath; filePath = NULL;} } @@ -129,7 +125,7 @@ char *UDPBaseImplementation::getFilePath() const{ return output; } -uint32_t UDPBaseImplementation::getFileIndex() const{ FILE_LOG(logDEBUG) << __AT__ << " starting"; return fileIndex;} +uint64_t UDPBaseImplementation::getFileIndex() const{ FILE_LOG(logDEBUG) << __AT__ << " starting"; return fileIndex;} int UDPBaseImplementation::getScanTag() const{ FILE_LOG(logDEBUG) << __AT__ << " starting"; return scanTag;} @@ -234,7 +230,7 @@ void UDPBaseImplementation::setFilePath(const char c[]){ FILE_LOG(logINFO) << "File path:" << filePath; } -void UDPBaseImplementation::setFileIndex(const uint32_t i){ +void UDPBaseImplementation::setFileIndex(const uint64_t i){ FILE_LOG(logDEBUG) << __AT__ << " starting"; fileIndex = i; @@ -394,7 +390,7 @@ void UDPBaseImplementation::resetAcquisitionCount(){ FILE_LOG(logINFO) << "totalPacketsCaught:" << totalPacketsCaught << endl; } -int UDPBaseImplementation::startReceiver(char *c=NULL){ +int UDPBaseImplementation::startReceiver(char *c){ FILE_LOG(logWARNING) << __AT__ << " doing nothing..."; FILE_LOG(logERROR) << __AT__ << " must be overridden by child classes"; return OK; @@ -433,17 +429,17 @@ void UDPBaseImplementation::closeFile(int i){ /***callback functions***/ -void UDPBaseImplementation::registerCallBackStartAcquisition(int (*func)(char*, char*,int, int, void*),void *arg){ +void UDPBaseImplementation::registerCallBackStartAcquisition(int (*func)(char*, char*,uint64_t, uint32_t, void*),void *arg){ startAcquisitionCallBack=func; pStartAcquisition=arg; } -void UDPBaseImplementation::registerCallBackAcquisitionFinished(void (*func)(int, void*),void *arg){ +void UDPBaseImplementation::registerCallBackAcquisitionFinished(void (*func)(uint64_t, void*),void *arg){ acquisitionFinishedCallBack=func; pAcquisitionFinished=arg; } -void UDPBaseImplementation::registerCallBackRawDataReady(void (*func)(int, char*, int, FILE*, char*, void*),void *arg){ +void UDPBaseImplementation::registerCallBackRawDataReady(void (*func)(uint64_t, char*, uint32_t, FILE*, char*, void*),void *arg){ rawDataReadyCallBack=func; pRawDataReady=arg; } diff --git a/slsReceiverSoftware/src/UDPStandardImplementation.cpp b/slsReceiverSoftware/src/UDPStandardImplementation.cpp index f4d2d968f..1d6a1eb23 100644 --- a/slsReceiverSoftware/src/UDPStandardImplementation.cpp +++ b/slsReceiverSoftware/src/UDPStandardImplementation.cpp @@ -764,7 +764,7 @@ void UDPStandardImplementation::resetAcquisitionCount(){ } -int UDPStandardImplementation::startReceiver(char *c=NULL){ +int UDPStandardImplementation::startReceiver(char *c){ FILE_LOG(logDEBUG1) << __AT__ << " called"; cout << "Info: Starting Receiver" << endl; @@ -1752,23 +1752,28 @@ void UDPStandardImplementation::startWriting(){ //pop fifo and if end of acquisition - if(popAndCheckEndofAcquisition(wbuf, popReady, numPackets,toFreePointers,toFreePointersOffset)){ + if(popAndCheckEndofAcquisition(ithread, wbuf, popReady, numPackets,toFreePointers,toFreePointersOffset)){ #ifdef DEBUG4 cprintf(GREEN,"Writing_Thread %d: All dummy-end buffers popped\n", ithread); #endif //finish missing packets - if(myDetectorType == EIGER - && ((tempoffset[0]!=0) || (tempoffset[1]!=(packetsPerFrame/numListeningThreads)))); + + if(myDetectorType == EIGER && + ((tempoffset[0]!=0) || (tempoffset[1]!=(packetsPerFrame/numberofListeningThreads)))); else{ stopWriting(ithread,wbuf); continue; } } - //eiger-processWritingPackets(); - //others-processWritingBuffer(); - - + switch(myDetectorType){ + case EIGER: + processWritingBufferPacketByPacket(); + break; + default: + processWritingBuffer(ithread, wbuf, numPackets); + break; + } }/*--end of loop for each buffer (inner loop)*/ @@ -1835,7 +1840,8 @@ void UDPStandardImplementation::startWriting(){ -bool UDPStandardImplementation::popAndCheckEndofAcquisition(char* wbuffer[], bool ready[], uint32_t nP[],char* toFree[],int toFreeOffset[]){ +bool UDPStandardImplementation::popAndCheckEndofAcquisition(int ithread, char* wbuffer[], bool ready[], uint32_t nP[],char* toFree[],int toFreeOffset[]){ + FILE_LOG(logDEBUG1) << __AT__ << " called"; bool endofAcquisition = true; int val; @@ -1866,7 +1872,7 @@ bool UDPStandardImplementation::popAndCheckEndofAcquisition(char* wbuffer[], boo #ifdef DEBUG4 switch(myDetectorType){ case EIGER: - wbuf_footer = (eiger_packet_footer_t*)(wbuffer[i] + footerOffset + HEADER_SIZE_NUM_TOT_PACKETS); + eiger_packet_footer_t* wbuf_footer = (eiger_packet_footer_t*)(wbuffer[i] + footerOffset + HEADER_SIZE_NUM_TOT_PACKETS); //cprintf(BLUE,"footer value:0x%x\n",i,(uint64_t)(*( (uint64_t*) wbuf_footer))); cprintf(BLUE,"Fnum[%d]:%d\n",i,(uint32_t)(*( (uint64_t*) wbuf_footer))); cprintf(BLUE,"Pnum[%d]:%d\n",i,*( (uint16_t*) wbuf_footer->packetNumber)); @@ -1887,6 +1893,54 @@ bool UDPStandardImplementation::popAndCheckEndofAcquisition(char* wbuffer[], boo +void UDPStandardImplementation::stopWriting(int ithread, char* wbuffer[]){ + FILE_LOG(logDEBUG1) << __AT__ << " called"; + + cprintf(GREEN,"Info: Writing_Thread %d: End of Acquisition\n",ithread); + + //free fifo + for(int i=0; ipush(wbuffer[i])); +#ifdef +} + +void UDPStandardImplementation::processWritingBuffer(int ithread, char* wbuffer[], uint32_t nP[]){ + FILE_LOG(logDEBUG1) << __AT__ << " called"; + + +} + + +void UDPStandardImplementation::processWritingBufferPacketByPacket(int ithread, char* wbuffer[], uint32_t nP[]){ + FILE_LOG(logDEBUG1) << __AT__ << " called"; + + uint64_t tempframenumber = ((uint32_t)(*((uint32_t*)(wbuffer[ithread] + HEADER_SIZE_NUM_TOT_PACKETS)))); + + //for gotthard and normal frame, increment frame number to separate fnum and pnum + if (myDetectorType == PROPIX ||(myDetectorType == GOTTHARD && shortFrameEnable == -1)) + tempframenumber++; + + //get frame number + tempframenumber = (tempframenumber & frameIndexMask) >> frameIndexOffset; + + //single thread, just assign and process without compression + if(!dataCompressionEnable){ + currentFrameNumber = tempframenumber; + handleWithoutDataCompression(ithread, wbuffer, nP[0]); + } + + //handling multiple threads + else{ + pthread_mutex_lock(&progressMutex); + if(tempframenumber > currentFrameNumber) + currentFrameNumber = tempframenumber; + pthread_mutex_unlock(&progressMutex); + handleDataCompression(ithread,wbuffer,d, xmax, ymax, nf); + } + + + +} @@ -2173,66 +2227,9 @@ int UDPStandardImplementation::startWriting(){ - //pop - endofacquisition = true; - for(i=0;ipop(wbuf[i]); -#ifdef FIFO_DEBUG - cprintf(GREEN,"%d writer poped 0x%x from fifo %d\n", ithread, (void*)(wbuf[i]), i); -#endif - numpackets[i] = (uint32_t)(*((uint32_t*)wbuf[i])); - -#ifdef VERYDEBUG - cprintf(GREEN,"%d numpackets: %d for fifo :%d\n", ithread, numpackets[i], i); -#endif - if(numpackets < 0){ - cprintf(BG_RED,"negative numpackets[%d]%d\n",i,numpackets[i]); - exit(-1); - } - //dont pop again if dummy packet - else if(numpackets[i] == 0){ - popready[i] = false; -#ifdef EIGER_DEBUG3 - cprintf(GREEN,"%d Dummy frame popped out of fifo %d",ithread, i); -#endif - }else{ - endofacquisition = false; - if(numpackets[i] == onePacketSize){ -#ifdef EIGER_DEBUG3 - wbuf_footer = (eiger_packet_footer_t*)(wbuf[i] + footer_offset + HEADER_SIZE_NUM_TOT_PACKETS); - //cprintf(BLUE,"footer value:0x%x\n",i,(uint64_t)(*( (uint64_t*) wbuf_footer))); - cprintf(BLUE,"tempframenum[%d]:%d\n",i,(uint32_t)(*( (uint64_t*) wbuf_footer))); - cprintf(BLUE,"packetnum[%d]:%d\n",i,*( (uint16_t*) wbuf_footer->packetnum)); -#endif - } - - if(myDetectorType == EIGER){ - tofree[tofreeoffset[i]] = wbuf[i]; - tofreeoffset[i]++; - } - } - - } - } - //END OF ACQUISITION - if(endofacquisition){ -#ifdef EIGER_DEBUG3 - cprintf(GREEN,"%d Both dummy frames\n", ithread); -#endif - //remaining packets to be written - if((myDetectorType == EIGER) && - ((tempoffset[0]!=0) || (tempoffset[1]!=(packetsPerFrame/numListeningThreads)))); - else{ - - stopWriting(ithread,wbuf); - continue; - } - } - if(myDetectorType == EIGER){ @@ -2539,31 +2536,7 @@ int UDPStandardImplementation::startWriting(){ } - //other detectors other than eiger - else{ - //frame number for progress - if ((myDetectorType == PROPIX) ||((myDetectorType == GOTTHARD) && (shortFrame == -1))) - tempframenum[0] = (((((uint32_t)(*((uint32_t*)(wbuf[ithread] + HEADER_SIZE_NUM_TOT_PACKETS))))+1)& (frameIndexMask)) >> frameIndexOffset); - else - tempframenum[0] = ((((uint32_t)(*((uint32_t*)(wbuf[ithread] + HEADER_SIZE_NUM_TOT_PACKETS))))& (frameIndexMask)) >> frameIndexOffset); - - if(numWriterThreads == 1) - currframenum = tempframenum[0]; - else{ - pthread_mutex_lock(&progress_mutex); - if(tempframenum[0] > currframenum) - currframenum = tempframenum[0]; - pthread_mutex_unlock(&progress_mutex); - } - - - //without datacompression: write datacall back, or write data, free fifo - if(!dataCompression) handleWithoutDataCompression(ithread,wbuf, numpackets[0]); - //data compression - else handleDataCompression(ithread,wbuf,d, xmax, ymax, nf); - - } } From 169a91b6aceb7b952815e08d73d5d63408d8a602 Mon Sep 17 00:00:00 2001 From: Dhanya Maliakal Date: Fri, 16 Oct 2015 10:47:21 +0200 Subject: [PATCH 39/68] some --- .../include/UDPStandardImplementation.h | 80 +- .../src/UDPStandardImplementation.cpp | 817 ++++++++---------- 2 files changed, 405 insertions(+), 492 deletions(-) diff --git a/slsReceiverSoftware/include/UDPStandardImplementation.h b/slsReceiverSoftware/include/UDPStandardImplementation.h index 0c1d4ac43..6b08fab2b 100644 --- a/slsReceiverSoftware/include/UDPStandardImplementation.h +++ b/slsReceiverSoftware/include/UDPStandardImplementation.h @@ -317,15 +317,6 @@ private: */ void startListening(); - /** - * Thread started which writes packets to file. - * It pops the fifo, processes and writes packets to file and pushes the addresses into the fifoFree - * This is continuously looped for each buffer in a nested loop, which is again looped for each acquisition - * Exits only for changing dynamic range, 10G parameters etc and recreated - * - */ - void startWriting(); - /** * Called by startListening * Listens to buffer, until packet(s) received or shutdownUDPsocket called by client @@ -368,6 +359,16 @@ private: */ uint32_t processListeningBuffer(int ithread, int cSize,char* temp); + /** + * Thread started which writes packets to file. + * It calls popAndCheckEndofAcquisition to pop fifo and check if it is a dummy end buffer + * It then calls a function to process and write packets to file and pushes the addresses into the fifoFree + * This is continuously looped for each buffer in a nested loop, which is again looped for each acquisition + * Exits only for changing dynamic range, 10G parameters etc and recreated + * + */ + void startWriting(); + /** * Called by StartWriting * Pops buffer from all the FIFOs and checks for dummy frames and end of acquisition @@ -392,9 +393,40 @@ private: */ void stopWriting(int ithread, char* wbuffer[]); - void processWritingBuffer(int ithread, char* wbuffer[], uint32_t nP[]); - void processWritingBufferPacketByPacket(); + /** + * Called by startWriting or processWritingBufferPacketByPacket upon reading a frame (for eiger) + * Updates parameters, (writes headers for eiger) and writes to file when not a dummy frame + * Copies data for gui display and frees addresses popped from FIFOs + * @param ithread writing thread index + * @param wbuffer writing buffer popped out from FIFO + * @param npackets number of packets + */ + void handleWithoutDataCompression(int ithread, char* wbuffer[],int npackets); + /** + * Calle by handleWithoutDataCompression + * Creating headers Writing to file without compression + * @param wbuffer is the address of buffer popped out of FIFO + * @param numpackets is the number of packets + */ + void writeFileWithoutCompression(char* wbuffer[],int numpackets); + + /** + * Called by writeToFileWithoutCompression() + * Create headers for file writing (at the moment, this is eiger specific) + * @param wbuffer writing buffer popped from FIFOs + */ + void createHeaders(char* wbuffer[]); + + /** + * Called by handleWithoutDataCompression and handleWithCompression after writing to file + * Copy frames for GUI and updates appropriate parameters for frequency frames to gui + * Uses semaphore for nth frame mode + * @param buffer buffer to copy + */ + void copyFrameToGui(char* buffer[]); + + void processWritingBufferPacketByPacket(); /************************************************************************* * Class Members ********************************************************* @@ -674,11 +706,7 @@ private: private: - /** - * Copy frames to gui - * uses semaphore for nth frame mode - */ - void copyFrameToGui(char* startbuf[], char* buf=NULL); + /** * Creates new tree and file for compression @@ -688,26 +716,6 @@ private: */ int createCompressionFile(int ithr, int iframe); - /** - * Writing to file without compression - * @param buf is the address of buffer popped out of fifo - * @param numpackets is the number of packets - * @param framenum current frame number - */ - void writeToFile_withoutCompression(char* buf[],int numpackets, uint32_t framenum); - - - - /** - * updates parameters and writes to file when not a dummy frame - * Also calls writeToFile_withoutCompression or handleDataCompression - * Called by startWriting() - * @param ithread writing thread number - * @param wbuffer writer buffer - * @param npackets number of packets - */ - void handleWithoutDataCompression(int ithread, char* wbuffer[],int npackets); - /** * data compression for each fifo output * @param ithread writing thread number diff --git a/slsReceiverSoftware/src/UDPStandardImplementation.cpp b/slsReceiverSoftware/src/UDPStandardImplementation.cpp index 1d6a1eb23..f01997cf8 100644 --- a/slsReceiverSoftware/src/UDPStandardImplementation.cpp +++ b/slsReceiverSoftware/src/UDPStandardImplementation.cpp @@ -775,8 +775,11 @@ int UDPStandardImplementation::startReceiver(char *c){ measurementStarted = false; startFrameIndex = 0; frameIndex = 0; - if(!acqStarted) + if(!acqStarted){ currentFrameNumber = 0; //has to be zero to add to startframeindex for each scan + acquisitionIndex = 0; + frameIndex = 0; + } for(int i = 0; i < numberofListeningThreads; ++i) totalListeningFrameCount[i] = 0; packetsCaught = 0; @@ -983,7 +986,7 @@ void UDPStandardImplementation::readFrame(char* c,char** raw, uint64_t &startAcq cprintf(CYAN,"Info: gonna post\n"); #endif //release after getting data - sem_post(&smp); + sem_post(&writerGuiSemaphore); } #ifdef DEBUG4 cprintf(CYAN,"Info: done post\n"); @@ -1771,7 +1774,10 @@ void UDPStandardImplementation::startWriting(){ processWritingBufferPacketByPacket(); break; default: - processWritingBuffer(ithread, wbuf, numPackets); + if(!dataCompressionEnable) + handleWithoutDataCompression(ithread, wbuf, numPackets[0]); + else + handleDataCompression(ithread,wbuf,d, xmax, ymax, nf); break; } @@ -1899,180 +1905,372 @@ void UDPStandardImplementation::stopWriting(int ithread, char* wbuffer[]){ cprintf(GREEN,"Info: Writing_Thread %d: End of Acquisition\n",ithread); //free fifo - for(int i=0; ipush(wbuffer[i])); -#ifdef -} - -void UDPStandardImplementation::processWritingBuffer(int ithread, char* wbuffer[], uint32_t nP[]){ - FILE_LOG(logDEBUG1) << __AT__ << " called"; - - -} - - -void UDPStandardImplementation::processWritingBufferPacketByPacket(int ithread, char* wbuffer[], uint32_t nP[]){ - FILE_LOG(logDEBUG1) << __AT__ << " called"; - - uint64_t tempframenumber = ((uint32_t)(*((uint32_t*)(wbuffer[ithread] + HEADER_SIZE_NUM_TOT_PACKETS)))); - - //for gotthard and normal frame, increment frame number to separate fnum and pnum - if (myDetectorType == PROPIX ||(myDetectorType == GOTTHARD && shortFrameEnable == -1)) - tempframenumber++; - - //get frame number - tempframenumber = (tempframenumber & frameIndexMask) >> frameIndexOffset; - - //single thread, just assign and process without compression - if(!dataCompressionEnable){ - currentFrameNumber = tempframenumber; - handleWithoutDataCompression(ithread, wbuffer, nP[0]); +#ifdef FIFODEBUG + cprintf(GREEN,"Writing_Thread %d: Freeing dummy-end buffer. Pushed into fifofree %p for listener %d\n", ithread,(void*)(wbuffer[i]),i); +#endif } - //handling multiple threads - else{ - pthread_mutex_lock(&progressMutex); - if(tempframenumber > currentFrameNumber) - currentFrameNumber = tempframenumber; - pthread_mutex_unlock(&progressMutex); - handleDataCompression(ithread,wbuffer,d, xmax, ymax, nf); + //all threads need to close file, reset mask and exit loop + closeFile(ithread); + pthread_mutex_lock(&statusMutex); + writerThreadsMask^=(1<> frameIndexOffset; + //set indices + acquisitionIndex = currentFrameNumber - startAcquisitionIndex; + frameIndex = currentFrameNumber - startFrameIndex; } - -} - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -/* - acquisitionIndex = currframenum - startAcquisitionIndex - frameIndex = currframenum - startFrameIndex; - -} -*/ - - - - -void UDPStandardImplementation::copyFrameToGui(char* startbuf[], char* buf){ - FILE_LOG(logDEBUG1) << __AT__ << " called"; -#ifdef VERY_VERY_DEBUG -cout << "copyframe" << endl; + //callback to write data + if (cbAction < DO_EVERYTHING){ + switch(myDetectorType){ + case EIGER: + for(i=0;i 0) + writeFileWithoutCompression(wbuffer, npackets); +#ifdef DEBUG4 + cprintf(GREEN,"Writing_Thread: Writing done\nGoing to copy frame\n"); #endif - //random read when gui not ready , also command line doesnt have nthframetogui - //else guidata always null as guidataready is always 1 after 1st frame, and seccond data never gets copied - if((!nFrameToGui) && (!guiData)){ -#ifdef VERY_VERY_DEBUG - cprintf(GREEN,"doing nothing\n"); + + //copy frame for gui + if(npackets >= packetsPerFrame) + copyFrameToGui(wbuffer); +#ifdef DEBUG4 + cprintf(GREEN,"Writing_Thread: Copied frame\n"); +#endif + + + //free fifo addresses (eiger frees for each packet later) + if(myDetectorType != EIGER){ + while(!fifoFree[0]->push(wbuffer[0])); +#ifdef FIFODEBUG + cprintf(GREEN,"Writing_Thread %d: Freed buffer, pushed into fifofree %p for listener 0\n",ithread, (void*)(wbuffer[0])); +#endif + } +} + + + + +void UDPStandardImplementation::writeFileWithoutCompression(char* wbuffer[],int numpackets){ + FILE_LOG(logDEBUG1) << __AT__ << " called"; + + int i; + + //create headers for eiger +#ifdef WRITE_HEADERS + if (myDetectorType == EIGER && cbAction == DO_EVERYTHING) + createHeaders(wbuffer); +#endif + + //if write enabled + if((fileWriteEnable) && (sfilefd)){ + int offset = HEADER_SIZE_NUM_TOT_PACKETS; //offset (not eiger) to keep track of how many packets saved + int packetsToSave; //how many packets to save at a time + volatile uint64_t tempframenumber; + int lastpacket; + + //loop to take care of creating new files when it reaches max packets per file + while(numpackets > 0){ + + //to create new file when max reached + packetsToSave = maxPacketsPerFile - packetsInFile; + if(packetsToSave > numpackets) + packetsToSave = numpackets; + + //write to file + if(cbAction == DO_EVERYTHING){ + switch(myDetectorType){ + case EIGER: + for(i=0; i= (uint32_t)maxPacketsPerFile){ + //for packet loss, because currframenum is the latest one for eiger + if(myDetectorType != EIGER){ + lastpacket = (((packetsToSave - 1) * onePacketSize) + offset); + + //get frame number (eiger already gets it when it does packet to packet processing) + tempframenumber = ((uint32_t)(*((uint32_t*)(wbuffer[0] + lastpacket)))); + //for gotthard and normal frame, increment frame number to separate fnum and pnum + if (myDetectorType == PROPIX ||(myDetectorType == GOTTHARD && shortFrameEnable == -1)) + tempframenumber++; + //get frame number + currentFrameNumber = (tempframenumber & frameIndexMask) >> frameIndexOffset; + //set indices + acquisitionIndex = currentFrameNumber - startAcquisitionIndex; + frameIndex = currentFrameNumber - startFrameIndex; + } +#ifdef DEBUG3 + cprintf(GREEN,"Writing_Thread: Current Frame Number:%d\n",currentFrameNumber); +#endif + createNewFile(); + } + + //increase offset + if(myDetectorType != EIGER) + offset += (packetsToSave * onePacketSize); + numpackets -= packetsToSave; + } + } + + //only update parameters + else{ + if(numberofWriterThreads > 1) pthread_mutex_lock(&writeMutex); + packetsInFile += numpackets; + packetsCaught += (numpackets - numMissingPackets); + totalPacketsCaught += (numpackets - numMissingPackets); + numMissingPackets = 0; + if(numberofWriterThreads > 1) pthread_mutex_unlock(&writeMutex); + } + +} + + + + + +void UDPStandardImplementation::createHeaders(char* wbuffer[]){ + + eiger_packet_header_t* wbuf_header=0; + eiger_packet_footer_t* wbuf_footer=0; + int port = 0, missingPacket; + + for (int i = 0; i < packetsPerFrame; i++){ + + wbuf_header = (eiger_packet_header_t*) wbuffer[i]; + wbuf_footer = (eiger_packet_footer_t*)(wbuffer[i] + footerOffset); +#ifdef DEBUG4 + cprintf(GREEN, "Loop index:%d Pnum:%d\n",i,*( (uint16_t*) wbuf_footer->packetNumber)); +#endif + //which port + if (i ==(packetsPerFrame/2)) port = 1; + + //missing packet + if (*( (uint16_t*) wbuf_header->missingPacket)== missingPacketValue){ +#ifdef DEBUG4 + cprintf(GREEN,"Missing packet at %d\n", i+1); +#endif + missingPacket = 1; + //add frame and packet numbers + *( (uint64_t*) wbuf_footer) = (uint64_t)((currentFrameNumber+1)); + *( (uint16_t*) wbuf_footer->packetNumber) = (i+1); + } + //normal packet + else{ + missingPacket = 0; + //correct the packet numbers of port2 so that port1 and 2 are not the same + if(port) *( (uint16_t*) wbuf_footer->packetNumber) = (*( (uint16_t*) wbuf_footer->packetNumber))+(packetsPerFrame/2); + } + //DEBUGGING + if(*( (uint16_t*) wbuf_footer->packetNumber) != (i+1)){ + cprintf(BG_RED, "Packet Number Mismatch! i:%d pnum:%d fnum:%d missingPacket:%d\n", + i,*( (uint16_t*) wbuf_footer->packetNumber),currentFrameNumber,*( (uint16_t*) wbuf_header->missingPacket)); + exit(-1); + } + //overwriting port number and dynamic range + *( (uint8_t*) wbuf_header->portIndex) = port; + *( (uint8_t*) wbuf_header->dynamicRange) = dynamicRange; + } +} + + +void UDPStandardImplementation::copyFrameToGui(char* buffer[]){ + FILE_LOG(logDEBUG1) << __AT__ << " called"; + + int i; + + //random read (gui not ready) + //need to toggle guiDataReady or the second frame wont be copied + if((!FrameToGuiFrequency) && (!guiData)){ +#ifdef DEBUG4 + cprintf(GREEN,"Writing_Thread: CopyingFrame: Resetting guiDataReady\n"); #endif pthread_mutex_lock(&dataReadyMutex); guiDataReady=0; pthread_mutex_unlock(&dataReadyMutex); } - //random read or nth frame read, gui needs data now or it is the first frame + //random read (gui ready) or nth frame read: gui needs data now or it is the first frame else{ -#ifdef VERY_VERY_DEBUG - cprintf(GREEN,"gui needs data now or 1st frame\n"); +#ifdef DEBUG4 + cprintf(GREEN,"Writing_Thread: CopyingFrame: Gui needs data now OR 1st frame\n"); #endif pthread_mutex_lock(&dataReadyMutex); guiDataReady=0; -#ifdef VERY_VERY_DEBUG - cprintf(GREEN,"guidataready is 0, copying data\n"); +#ifdef DEBUG4 + cprintf(GREEN,"Writing_Thread: CopyingFrame: guidataready is 0, Copying data\n"); #endif - //eiger - if(startbuf != NULL){ + switch(myDetectorType){ + case EIGER: + for(int i=0; ipush(wbuffer[i])); -#ifdef FIFO_DEBUG - cprintf(GREEN,"%d writer free dummy pushed into fifofree %x for listener %d\n", ithread,(void*)(wbuffer[i]),i); -#endif - } - - - - //all threads need to close file, reset mask and exit loop - closeFile(ithread); - pthread_mutex_lock(&statusMutex); - writerthreads_mask^=(1< 0){ - - //for progress and packet loss calculation(new files) - if(myDetectorType == EIGER); - else if ((myDetectorType == PROPIX)||((myDetectorType == GOTTHARD) && (shortFrame == -1))) - tempframenum = (((((uint32_t)(*((uint32_t*)(buf[0] + HEADER_SIZE_NUM_TOT_PACKETS))))+1)& (frameIndexMask)) >> frameIndexOffset); - else - tempframenum = ((((uint32_t)(*((uint32_t*)(buf[0] + HEADER_SIZE_NUM_TOT_PACKETS))))& (frameIndexMask)) >> frameIndexOffset); - - if(numWriterThreads == 1) - currframenum = tempframenum; - else{ - if(tempframenum > currframenum) - currframenum = tempframenum; - } -#ifdef VERYDEBUG - cout << "tempframenum:" << dec << tempframenum << " curframenum:" << currframenum << endl; -#endif - - //lock - if(numWriterThreads > 1) - pthread_mutex_lock(&write_mutex); - - - //to create new file when max reached - packetsToSave = maxPacketsPerFile - packetsInFile; - if(packetsToSave > numpackets) - packetsToSave = numpackets; -/**next time offset is still plus header length*/ - if(myDetectorType == EIGER){ - for(i=0;i= (uint32_t)maxPacketsPerFile){ - - //for packet loss, because currframenum is the latest one for eiger - if(myDetectorType != EIGER){ - lastpacket = (((packetsToSave - 1) * onePacketSize) + offset); - - if ((myDetectorType == PROPIX)||((myDetectorType == GOTTHARD) && (shortFrame == -1))) - - tempframenum = (((((uint32_t)(*((uint32_t*)(buf[0] + lastpacket))))+1)& (frameIndexMask)) >> frameIndexOffset); - else - tempframenum = ((((uint32_t)(*((uint32_t*)(buf[0] + lastpacket))))& (frameIndexMask)) >> frameIndexOffset); - } - if(numWriterThreads == 1) - currframenum = tempframenum; - else{ - if(tempframenum > currframenum) - currframenum = tempframenum; - } -#ifdef VERYDEBUG - cout << "tempframenum:" << dec << tempframenum << " curframenum:" << currframenum << endl; -#endif - //create - createNewFile(); - } - - //unlock - if(numWriterThreads > 1) - pthread_mutex_unlock(&write_mutex); - - if(myDetectorType != EIGER) - offset += (packetsToSave * onePacketSize); - numpackets -= packetsToSave; - } - - } - else{ - if(numWriterThreads > 1) - pthread_mutex_lock(&write_mutex); - packetsInFile += numpackets; - packetsCaught += (numpackets - numMissingPackets); - totalPacketsCaught += (numpackets - numMissingPackets); - numMissingPackets = 0; - if(numWriterThreads > 1) - pthread_mutex_unlock(&write_mutex); - } -} - - - - - - - - -void UDPStandardImplementation::handleWithoutDataCompression(int ithread, char* wbuffer[],int npackets){ - int i, missingpacket,port = 0; - - - if (cbAction < DO_EVERYTHING){ - if (myDetectorType == EIGER){ - for(i=0;i 0){ - -#ifdef WRITE_HEADERS - if (myDetectorType == EIGER){ - - eiger_packet_header_t* wbuf_header=0; - eiger_packet_footer_t* wbuf_footer=0; - - - for (i = 0; i < packetsPerFrame; i++){ - - wbuf_header = (eiger_packet_header_t*) wbuffer[i]; - wbuf_footer = (eiger_packet_footer_t*)(wbuffer[i] + footer_offset); -#ifdef EIGER_DEBUG3 - cprintf(GREEN, "i:%d pnum:%d \n",i,*( (uint16_t*) wbuf_footer->packetnum)); -#endif - //which port - if (i ==(packetsPerFrame/2)) - port = 1; - - - - //missing packet - if (*( (uint16_t*) wbuf_header->missingpacket)== missingPacketValue){ -#ifdef VERY_VERBOSE - cprintf(GREEN,"missing packet at %d\n", i+1); -#endif - missingpacket = 1; - //add frame and packet numbers - *( (uint64_t*) wbuf_footer) = (uint64_t)((currframenum+1)); - *( (uint16_t*) wbuf_footer->packetnum) = (i+1); - }else{ - missingpacket = 0; - - if(*( (uint16_t*) wbuf_footer->packetnum)!= (i-(port*packetsPerFrame/numListeningThreads))+1){ - cprintf(BG_RED, "pnum mismatch num4! i:%d pnum:%d fnum:%d\n", - i,*( (uint16_t*) wbuf_footer->packetnum),currframenum); - exit(-1); - } - - //move packet numbers to num2, and compensate for port1 starting pnum from 0 - if(port) - *( (uint16_t*) wbuf_footer->packetnum) = (*( (uint16_t*) wbuf_footer->packetnum))+(packetsPerFrame/2); - } - - if(*( (uint16_t*) wbuf_footer->packetnum) != (i+1)){ - cprintf(BG_RED, "pnum mismatch! i:%d pnum:%d fnum:%d\n", - i,*( (uint16_t*) wbuf_footer->packetnum),currframenum); - if (*( (uint16_t*) wbuf_header->missingpacket) == missingPacketValue) - cprintf(BG_RED,"missing packet though\n"); - exit(-1); - } - - //overwriting port number and dynamic range - *( (uint8_t*) wbuf_header->portnum) = port; - *( (uint8_t*) wbuf_header->dynamicrange) = dynamicRange; - - - -#ifdef VERYDEBUG - if((i==0)||(i==1)){ - cprintf(GREEN, "%d packet header:0x%016llx missingpacket:0x%x\n",i, - (uint64_t)()*( (uint64_t*) wbuf_header)), *( (uint16_t*) wbuf_header->missingpacket)); - - cprintf(GREEN, "%d - 0x%x - %d\n", i, - *( (uint16_t*) wbuf_header->missingpacket), *( (uint16_t*) wbuf_footer->packetnum)); - } -#endif - - } - } -#endif - - writeToFile_withoutCompression(wbuffer, npackets,currframenum); - } - -#ifdef VERYDEBUG - cprintf(GREEN,"written everyting\n"); -#endif - } - - - if(myDetectorType == EIGER) { - -#ifdef VERYDEBUG - cprintf(GREEN,"gonna copy frame\n"); -#endif - copyFrameToGui(wbuffer); -#ifdef VERYDEBUG - cprintf(GREEN,"copied frame\n"); -#endif - }else{ - //copy to gui - if(npackets >= packetsPerFrame){//min 1 frame, but neednt be - //if(npackets == packetsPerFrame * numJobsPerThread){ //only full frames - copyFrameToGui(NULL,wbuffer[0]+HEADER_SIZE_NUM_TOT_PACKETS); -#ifdef VERYVERBOSE - cout << ithread << " finished copying" << endl; -#endif - } - - //else cout << "unfinished buffersize" << endl; - while(!fifoFree[0]->push(wbuffer[0])); -#ifdef FIFO_DEBUG - cprintf(GREEN,"%d writer freed pushed into fifofree %x for listener 0\n",ithread, (void*)(wbuffer[0])); -#endif - - } -} @@ -2875,6 +2764,22 @@ void UDPStandardImplementation::handleWithoutDataCompression(int ithread, char* void UDPStandardImplementation::handleDataCompression(int ithread, char* wbuffer[], char* data, int xmax, int ymax, int &nf){ FILE_LOG(logDEBUG1) << __AT__ << " called"; + uint64_t tempframenumber = ((uint32_t)(*((uint32_t*)(wbuffer[ithread] + HEADER_SIZE_NUM_TOT_PACKETS)))); + //for gotthard and normal frame, increment frame number to separate fnum and pnum + if (myDetectorType == PROPIX ||(myDetectorType == GOTTHARD && shortFrameEnable == -1)) + tempframenumber++; + //get frame number + tempframenumber = (tempframenumber & frameIndexMask) >> frameIndexOffset; + + + pthread_mutex_lock(&progressMutex); + if(tempframenumber > currentFrameNumber) + currentFrameNumber = tempframenumber; + pthread_mutex_unlock(&progressMutex); + //set indices + acquisitionIndex = currentFrameNumber - startAcquisitionIndex; + frameIndex = currentFrameNumber - startFrameIndex; + #if defined(MYROOT1) && defined(ALLFILE_DEBUG) writeToFile_withoutCompression(wbuf[0], numpackets,currframenum); #endif From 253383331fe66ff38a1cbde12f5c3602b4e21dab Mon Sep 17 00:00:00 2001 From: Dhanya Maliakal Date: Mon, 19 Oct 2015 16:06:54 +0200 Subject: [PATCH 40/68] vg --- .../include/UDPStandardImplementation.h | 89 +-- .../src/UDPStandardImplementation.cpp | 632 ++++++++++-------- 2 files changed, 386 insertions(+), 335 deletions(-) diff --git a/slsReceiverSoftware/include/UDPStandardImplementation.h b/slsReceiverSoftware/include/UDPStandardImplementation.h index 6b08fab2b..430b5c5d1 100644 --- a/slsReceiverSoftware/include/UDPStandardImplementation.h +++ b/slsReceiverSoftware/include/UDPStandardImplementation.h @@ -291,11 +291,19 @@ private: int setupWriter(); /** - * Creates new file + * Creates new file and reset some parameters * @return OK or FAIL */ int createNewFile(); + /** + * Creates new tree and file for compression + * @param ithread thread number + * @param iframe frame number + * @return OK or FAIL + */ + int createCompressionFile(int ithread, int iframe); + /** * Static function - Starts Listening Thread of this object * @param this_pointer pointer to this object @@ -370,7 +378,7 @@ private: void startWriting(); /** - * Called by StartWriting + * Called by processWritingBuffer and processWritingBufferPacketByPacket * Pops buffer from all the FIFOs and checks for dummy frames and end of acquisition * @param ithread current thread index * @param wbuffer the buffer array that is popped from all the FIFOs @@ -383,7 +391,7 @@ private: bool popAndCheckEndofAcquisition(int ithread, char* wbuffer[], bool ready[], uint32_t nP[],char* toFree[],int toFreeOffset[]); /** - * Called by StartWriting + * Called by processWritingBuffer and processWritingBufferPacketByPacket * When dummy-end buffers are popped from all FIFOs (acquisition over), this is called * It frees the FIFO addresses, closes all files * For data compression, it waits for all threads to be done @@ -394,7 +402,7 @@ private: void stopWriting(int ithread, char* wbuffer[]); /** - * Called by startWriting or processWritingBufferPacketByPacket upon reading a frame (for eiger) + * Called by processWritingBuffer and processWritingBufferPacketByPacket * Updates parameters, (writes headers for eiger) and writes to file when not a dummy frame * Copies data for gui display and frees addresses popped from FIFOs * @param ithread writing thread index @@ -412,7 +420,7 @@ private: void writeFileWithoutCompression(char* wbuffer[],int numpackets); /** - * Called by writeToFileWithoutCompression() + * Called by writeToFileWithoutCompression * Create headers for file writing (at the moment, this is eiger specific) * @param wbuffer writing buffer popped from FIFOs */ @@ -426,7 +434,24 @@ private: */ void copyFrameToGui(char* buffer[]); - void processWritingBufferPacketByPacket(); + void processWritingBuffer(int ithread); + + void processWritingBufferPacketByPacket(int ithread); + + void waitWritingBufferForNextAcquisition(int ithread); + + /** + * Called by processWritingBuffer + * Processing fifo popped buffers for data compression + * Updates parameters and writes to file + * Copies data for gui display and frees addresses popped from FIFOs + * @param ithread writing thread number + * @param wbuffer writer buffer + * @param nf number of frames + */ + void handleDataCompression(int ithread, char* wbuffer[], int &nf); + + /************************************************************************* * Class Members ********************************************************* @@ -683,58 +708,6 @@ private: * 2 we open, close, write file, callback does not do anything */ int cbAction; - - - - - - - - - - - - - - - - - - - - -private: - - - - - /** - * Creates new tree and file for compression - * @param ithr thread number - * @param iframe frame number - *\returns OK for succces or FAIL for failure - */ - int createCompressionFile(int ithr, int iframe); - - /** - * data compression for each fifo output - * @param ithread writing thread number - * @param wbuffer writer buffer - * @param data pointer to the next packet start - * @param xmax max pixels in x direction - * @param ymax max pixels in y direction - * @param nf nf - */ - void handleDataCompression(int ithread, char* wbuffer[], char* data, int xmax, int ymax, int &nf); - - - - - - - //filter - - }; diff --git a/slsReceiverSoftware/src/UDPStandardImplementation.cpp b/slsReceiverSoftware/src/UDPStandardImplementation.cpp index f01997cf8..4b253966b 100644 --- a/slsReceiverSoftware/src/UDPStandardImplementation.cpp +++ b/slsReceiverSoftware/src/UDPStandardImplementation.cpp @@ -1382,6 +1382,36 @@ int UDPStandardImplementation::createNewFile(){ +int UDPStandardImplementation::createCompressionFile(int ithread, int iframe){ + FILE_LOG(logDEBUG1) << __AT__ << " called"; + +#ifdef MYROOT1 + char temp[MAX_STR_LENGTH]; + //create file name for gui purposes, and set up acquistion parameters + sprintf(temp, "%s/%s_fxxx_%d_%d.root", filePath,fileName,fileIndex,ithread); + //file + myFile[ithread] = new TFile(temp,"RECREATE");/** later return error if it exists */ + cprintf(GREEN,"Writing_Thread %d: Created Compression File: %s\n",ithread, temp); + //tree + sprintf(temp, "%s_fxxx_%d_%d",fileName,fileIndex,ithread); + myTree[ithread]=singlePhotonDetectorObject[ithread]->initEventTree(temp, &iframe); + //resets the pedestalSubtraction array and the commonModeSubtraction + singlePhotonDetectorObject[ithread]->newDataSet(); + if(myFile[ithread]==NULL){ + cprintf(BG_RED,"Error: File Null\n"); + return FAIL; + } + if(!myFile[ithread]->IsOpen()){ + cprintf(BG_RED,"Error: File Not Open\n") + return FAIL; + } + return OK; +#endif + return FAIL; +} + + + void* UDPStandardImplementation::startListeningThread(void* this_pointer){ FILE_LOG(logDEBUG1) << __AT__ << " called"; ((UDPStandardImplementation*)this_pointer)->startListening(); @@ -1399,6 +1429,8 @@ void* UDPStandardImplementation::startWritingThread(void* this_pointer){ + + void UDPStandardImplementation::startListening(){ FILE_LOG(logDEBUG1) << __AT__ << " called"; @@ -1517,6 +1549,10 @@ int UDPStandardImplementation::prepareAndListenBuffer(int ithread, int lSize, in } + + + + void UDPStandardImplementation::startFrameIndices(int ithread){ FILE_LOG(logDEBUG1) << __AT__ << " called"; @@ -1552,6 +1588,8 @@ void UDPStandardImplementation::startFrameIndices(int ithread){ + + void UDPStandardImplementation::stopListening(int ithread, int numbytes){ FILE_LOG(logDEBUG1) << __AT__ << " called"; @@ -1629,6 +1667,7 @@ void UDPStandardImplementation::stopListening(int ithread, int numbytes){ + uint32_t UDPStandardImplementation::processListeningBuffer(int ithread, int cSize, char* temp){ FILE_LOG(logDEBUG1) << __AT__ << " called"; @@ -1721,17 +1760,99 @@ void UDPStandardImplementation::startWriting(){ //let calling function know thread started and obtained current threadStarted = 1; + switch(myDetectorType){ + case EIGER: + processWritingBufferPacketByPacket(ithread); + break; + default: + processWritingBuffer(ithread); + break; + } + +} + + + +void UDPStandardImplementation::processWritingBuffer(int ithread, int &nf){ + FILE_LOG(logDEBUG1) << __AT__ << " called"; + + //variable definitions + char* wbuf[numberofListeningThreads]; //buffer popped from FIFO + sfilefd = NULL; //file pointer + + /* outer loop - loops once for each acquisition */ + //infinite loop, exited only to change dynamic range, 10G parameters etc (then recreated again) + while(true){ + + //--reset parameters before acquisition + nf = 0; + + /* inner loop - loop for each buffer */ + //until mask unset (udp sockets shut down by client) + while((1 << ithread) & writerThreadsMask){ + //pop + fifo[0]->pop(wbuf[0]); +#ifdef FIFODEBUG + cprintf(GREEN,"Writing_Thread %d: Popped %p from FIFO %d\n", ithread, (void*)(wbuf[0]),0); +#endif + int numPackets = (uint32_t)(*((uint32_t*)wbuf[0])); + if(numPackets < 0) + cprintf(BG_RED,"Error: Negative packet numbers: %d for FIFO %d\n",numPackets,0); +#ifdef DEBUG4 + cprintf(GREEN,"Writing_Thread %d: Number of Packets: %d for FIFO %d\n", ithread, numPackets, 0); +#endif + + + //dummy packet + if(numPackets == dummyPacketValue){ +#ifdef DEBUG3 + cprintf(GREEN,"Writing_Thread %d: Dummy frame popped out of FIFO %d",ithread, 0); +#endif + stopWriting(ithread,wbuf); + continue; + } + + + + //process + if(!dataCompressionEnable) + handleWithoutDataCompression(ithread, wbuf, numPackets); + else{ +#if defined(MYROOT1) && defined(ALLFILE_DEBUG) + if(npackets > 0) + writeFileWithoutCompression(wbuf, numPackets); +#endif + handleDataCompression(ithread,wbuf,nf); + } + }/*--end of loop for each buffer (inner loop)*/ + + waitWritingBufferForNextAcquisition(ithread); + + }/*--end of loop for each acquisition (outer loop) */ + + +} + + + + + + + + +void UDPStandardImplementation::processWritingBufferPacketByPacket(int ithread){ + FILE_LOG(logDEBUG1) << __AT__ << " called"; + + //variable definitions char* wbuf[numberofListeningThreads]; //buffer popped from FIFO sfilefd = NULL; //file pointer bool popReady[numberofListeningThreads]; //if the FIFO can be popped - uint32_t numPackets[numberofListeningThreads]; //number of packets popped from the FIFO - //eiger specific - int MAX_NUM_PACKETS = 1024; //highest 32 bit has 1024 number of packets - char* toFreePointers[MAX_NUM_PACKETS]; //pointers to free for each frame - int toFreePointersOffset[numberofListeningThreads]; //offset of pointers to free added for each thread - - + uint32_t numPackets[numberofListeningThreads]; //number of packets popped from the FIFO + //eiger specific + int MAX_NUM_PACKETS = 1024; //highest 32 bit has 1024 number of packets + char* toFreePointers[MAX_NUM_PACKETS]; //pointers to free for each frame + int toFreePointersOffset[numberofListeningThreads]; //offset of pointers to free added for each thread /* outer loop - loops once for each acquisition */ //infinite loop, exited only to change dynamic range, 10G parameters etc (then recreated again) @@ -1745,10 +1866,11 @@ void UDPStandardImplementation::startWriting(){ toFreePointersOffset[i] = (i*packetsPerFrame/numberofListeningThreads); } for(int i=0; i> frameIndexOffset; + //handle multi threads + pthread_mutex_lock(&progressMutex); + if(tempframenumber > currentFrameNumber) + currentFrameNumber = tempframenumber; + pthread_mutex_unlock(&progressMutex); + //set indices + acquisitionIndex = currentFrameNumber - startAcquisitionIndex; + frameIndex = currentFrameNumber - startFrameIndex; -} + //variable definitions + char* buff[2] = 0; //an array just to be compatible with copyframetogui + char* data = wbuffer[0]+ HEADER_SIZE_NUM_TOT_PACKETS; //data pointer to the next memory to be analysed + int ndata; //size of data returned + int np; //remaining number of packets returned + int npackets = (uint32_t)(*((uint32_t*)wbuffer[0])); //number of total packets + int remainingsize = npackets * onePacketSize; //size of the memory slot to be analyzed + + eventType thisEvent = PEDESTAL; + int once = 0; + int xmax = 0, ymax = 0; //max pixels in x and y direction + int xmin = 1, ymin = 1; //min pixels in x and y direction + double tot, tl, tr, bl, br; + + //determining xmax and ymax + switch(myDetectorType){ + case MOENCH: + xmax = MOENCH_PIXELS_IN_ONE_ROW-1; + ymax = MOENCH_PIXELS_IN_ONE_ROW-1; + break; + case GOTTHARD: + if(shortFrameEnable == -1){ + xmax = GOTTHARD_PIXELS_IN_ROW-1; + ymax = GOTTHARD_PIXELS_IN_COL-1; + }else{ + xmax = GOTTHARD_SHORT_PIXELS_IN_ROW-1; + ymax = GOTTHARD_SHORT_PIXELS_IN_COL-1; + } + break; + } + + while(buff[0] = receiverData[ithread]->findNextFrame(data,ndata,remainingsize)){ + + //remaining number of packets + np = ndata/onePacketSize; + + if ((np == packetsPerFrame) && (buff[0]!=NULL)){ + if(nf == 1000) + cprintf(GREEN, "Writing_Thread %d: pedestal done\n", ithread); + + singlePhotonDetectorObject[ithread]->newFrame(); + + //only for moench + if(commonModeSubtractionEnable){ + for(int ix = xmin - 1; ix < xmax+1; ix++){ + for(int iy = ymin - 1; iy < ymax+1; iy++){ + thisEvent = singlePhotonDetectorObject[ithread]->getEventType(buff[0], ix, iy, 0); + } + } + } - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -int UDPStandardImplementation::createCompressionFile(int ithr, int iframe){ - FILE_LOG(logDEBUG1) << __AT__ << " called"; - + for(int ix = xmin - 1; ix < xmax+1; ix++) + for(int iy = ymin - 1; iy < ymax+1; iy++){ + thisEvent=singlePhotonDetectorObject[ithread]->getEventType(buff[0], ix, iy, commonModeSubtractionEnable); + if (nf>1000) { + tot=0; + tl=0; + tr=0; + bl=0; + br=0; + if (thisEvent==PHOTON_MAX) { + receiverData[ithread]->getFrameNumber(buff[0]); + //iFrame=receiverdata[ithread]->getFrameNumber(buff); #ifdef MYROOT1 - char temp[MAX_STR_LENGTH]; - //create file name for gui purposes, and set up acquistion parameters - sprintf(temp, "%s/%s_fxxx_%d_%d.root", filePath,fileName,fileIndex,ithr); - //file - myFile[ithr] = new TFile(temp,"RECREATE");/** later return error if it exists */ - cout << "Thread " << ithr << ": created File: "<< temp << endl; - //tree - sprintf(temp, "%s_fxxx_%d_%d",fileName,fileIndex,ithr); - myTree[ithr]=singlePhotonDet[ithr]->initEventTree(temp, &iframe); - //resets the pedestalSubtraction array and the commonModeSubtraction - singlePhotonDet[ithr]->newDataSet(); - if(myFile[ithr]==NULL){ - cout<<"file null"<IsOpen()){ - cout<<"file not open"<Fill(); + //cout << "Fill in event: frmNr: " << iFrame << " ix " << ix << " iy " << iy << " type " << thisEvent << endl; +#else + pthread_mutex_lock(&writeMutex); + if((fileWriteEnable) && (sfilefd)) + singlePhotonDetectorObject[ithread]->writeCluster(sfilefd); + pthread_mutex_unlock(&writeMutex); +#endif + } + } + } + + nf++; +#ifndef ALLFILE + pthread_mutex_lock(&progressMutex); + packetsInFile += packetsPerFrame; + packetsCaught += packetsPerFrame; + totalPacketsCaught += packetsPerFrame; + if(packetsInFile >= (uint32_t)maxPacketsPerFile) + createNewFile(); + pthread_mutex_unlock(&progressMutex); + +#endif + if(!once){ + copyFrameToGui(buff); + once = 1; + } + } + + remainingsize -= ((buff[0] + ndata) - data); + data = buff[0] + ndata; + if(data > (wbuffer[0] + HEADER_SIZE_NUM_TOT_PACKETS + npackets * onePacketSize) ) + cprintf(BG_RED,"Writing_Thread %d: Error: Compression data goes out of bounds!\n", ithread); + } + + + while(!fifoFree[0]->push(wbuffer[0])); +#ifdef FIFODEBUG + cprintf(GREEN,"Writing_Thread %d: Compression free pushed into fifofree %p for listerner 0\n", ithread, (void*)(wbuffer[0])); #endif - return OK; } @@ -2312,13 +2481,49 @@ int UDPStandardImplementation::createCompressionFile(int ithr, int iframe){ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + int UDPStandardImplementation::startWriting(){ FILE_LOG(logDEBUG1) << __AT__ << " called"; - char *d=new char[bufferSize*numListeningThreads]; - int xmax=0,ymax=0; + int ret,i,j; bool endofacquisition; @@ -2355,19 +2560,7 @@ int UDPStandardImplementation::startWriting(){ while(1){ - nf = 0; - if(myDetectorType == MOENCH){ - xmax = MOENCH_PIXELS_IN_ONE_ROW-1; - ymax = MOENCH_PIXELS_IN_ONE_ROW-1; - }else{ - if(shortFrame == -1){ - xmax = GOTTHARD_PIXELS_IN_ROW-1; - ymax = GOTTHARD_PIXELS_IN_COL-1; - }else{ - xmax = GOTTHARD_SHORT_PIXELS_IN_ROW-1; - ymax = GOTTHARD_SHORT_PIXELS_IN_COL-1; - } - } + //so that the first frame is always copied guiData = latestData; @@ -2757,118 +2950,3 @@ int UDPStandardImplementation::startWriting(){ - - - - -void UDPStandardImplementation::handleDataCompression(int ithread, char* wbuffer[], char* data, int xmax, int ymax, int &nf){ - FILE_LOG(logDEBUG1) << __AT__ << " called"; - - uint64_t tempframenumber = ((uint32_t)(*((uint32_t*)(wbuffer[ithread] + HEADER_SIZE_NUM_TOT_PACKETS)))); - //for gotthard and normal frame, increment frame number to separate fnum and pnum - if (myDetectorType == PROPIX ||(myDetectorType == GOTTHARD && shortFrameEnable == -1)) - tempframenumber++; - //get frame number - tempframenumber = (tempframenumber & frameIndexMask) >> frameIndexOffset; - - - pthread_mutex_lock(&progressMutex); - if(tempframenumber > currentFrameNumber) - currentFrameNumber = tempframenumber; - pthread_mutex_unlock(&progressMutex); - //set indices - acquisitionIndex = currentFrameNumber - startAcquisitionIndex; - frameIndex = currentFrameNumber - startFrameIndex; - -#if defined(MYROOT1) && defined(ALLFILE_DEBUG) - writeToFile_withoutCompression(wbuf[0], numpackets,currframenum); -#endif - int npackets = (uint32_t)(*((uint32_t*)wbuffer[0])); - eventType thisEvent = PEDESTAL; - int ndata; - char* buff = 0; - data = wbuffer[0]+ HEADER_SIZE_NUM_TOT_PACKETS; - int remainingsize = npackets * onePacketSize; - int np; - int once = 0; - double tot, tl, tr, bl, br; - int xmin = 1, ymin = 1, ix, iy; - - - while(buff = receiverdata[ithread]->findNextFrame(data,ndata,remainingsize)){ - np = ndata/onePacketSize; - - //cout<<"buff framnum:"<> frameIndexOffset)<newFrame(); - - //only for moench - if(commonModeSubtractionEnable){ - for(ix = xmin - 1; ix < xmax+1; ix++){ - for(iy = ymin - 1; iy < ymax+1; iy++){ - thisEvent = singlePhotonDet[ithread]->getEventType(buff, ix, iy, 0); - } - } - } - - - for(ix = xmin - 1; ix < xmax+1; ix++) - for(iy = ymin - 1; iy < ymax+1; iy++){ - thisEvent=singlePhotonDet[ithread]->getEventType(buff, ix, iy, commonModeSubtractionEnable); - if (nf>1000) { - tot=0; - tl=0; - tr=0; - bl=0; - br=0; - if (thisEvent==PHOTON_MAX) { - receiverdata[ithread]->getFrameNumber(buff); - //iFrame=receiverdata[ithread]->getFrameNumber(buff); -#ifdef MYROOT1 - myTree[ithread]->Fill(); - //cout << "Fill in event: frmNr: " << iFrame << " ix " << ix << " iy " << iy << " type " << thisEvent << endl; -#else - pthread_mutex_lock(&write_mutex); - if((enableFileWrite) && (sfilefd)) - singlePhotonDet[ithread]->writeCluster(sfilefd); - pthread_mutex_unlock(&write_mutex); -#endif - } - } - } - - nf++; -#ifndef ALLFILE - pthread_mutex_lock(&progress_mutex); - packetsInFile += packetsPerFrame; - packetsCaught += packetsPerFrame; - totalPacketsCaught += packetsPerFrame; - if(packetsInFile >= (uint32_t)maxPacketsPerFile) - createNewFile(); - pthread_mutex_unlock(&progress_mutex); - -#endif - if(!once){ - copyFrameToGui(NULL,buff); - once = 1; - } - } - - remainingsize -= ((buff + ndata) - data); - data = buff + ndata; - if(data > (wbuffer[0] + HEADER_SIZE_NUM_TOT_PACKETS + npackets * onePacketSize) ) - cprintf(BG_RED,"ERROR SHOULD NOT COME HERE, Error 142536!\n"); - - } - - while(!fifoFree[0]->push(wbuffer[0])); -#ifdef FIFO_DEBUG - cprintf(BLUE,"%d writer compression free pushed into fifofree %x for listerner 0\n", ithread, (void*)(wbuffer[0])); -#endif - -} - From 6d6725c4e8d452830e227e40c62939bedb92d88a Mon Sep 17 00:00:00 2001 From: Dhanya Maliakal Date: Wed, 21 Oct 2015 11:03:57 +0200 Subject: [PATCH 41/68] df --- .../src/UDPStandardImplementation.cpp | 462 ++++++++---------- 1 file changed, 197 insertions(+), 265 deletions(-) diff --git a/slsReceiverSoftware/src/UDPStandardImplementation.cpp b/slsReceiverSoftware/src/UDPStandardImplementation.cpp index 4b253966b..34ee816cb 100644 --- a/slsReceiverSoftware/src/UDPStandardImplementation.cpp +++ b/slsReceiverSoftware/src/UDPStandardImplementation.cpp @@ -1773,12 +1773,14 @@ void UDPStandardImplementation::startWriting(){ -void UDPStandardImplementation::processWritingBuffer(int ithread, int &nf){ +void UDPStandardImplementation::processWritingBuffer(int ithread){ FILE_LOG(logDEBUG1) << __AT__ << " called"; //variable definitions char* wbuf[numberofListeningThreads]; //buffer popped from FIFO sfilefd = NULL; //file pointer + int nf; //for compression, number of frames + /* outer loop - loops once for each acquisition */ //infinite loop, exited only to change dynamic range, 10G parameters etc (then recreated again) @@ -1786,6 +1788,8 @@ void UDPStandardImplementation::processWritingBuffer(int ithread, int &nf){ //--reset parameters before acquisition nf = 0; + guiData = latestData; //so that the first frame is always copied + /* inner loop - loop for each buffer */ //until mask unset (udp sockets shut down by client) @@ -1803,7 +1807,7 @@ void UDPStandardImplementation::processWritingBuffer(int ithread, int &nf){ #endif - //dummy packet + //end of acquisition if(numPackets == dummyPacketValue){ #ifdef DEBUG3 cprintf(GREEN,"Writing_Thread %d: Dummy frame popped out of FIFO %d",ithread, 0); @@ -1829,8 +1833,6 @@ void UDPStandardImplementation::processWritingBuffer(int ithread, int &nf){ waitWritingBufferForNextAcquisition(ithread); }/*--end of loop for each acquisition (outer loop) */ - - } @@ -1843,32 +1845,72 @@ void UDPStandardImplementation::processWritingBuffer(int ithread, int &nf){ void UDPStandardImplementation::processWritingBufferPacketByPacket(int ithread){ FILE_LOG(logDEBUG1) << __AT__ << " called"; - //variable definitions - char* wbuf[numberofListeningThreads]; //buffer popped from FIFO + char* packetBuffer[numberofListeningThreads]; //buffer popped from FIFO sfilefd = NULL; //file pointer bool popReady[numberofListeningThreads]; //if the FIFO can be popped - uint32_t numPackets[numberofListeningThreads]; //number of packets popped from the FIFO - //eiger specific - int MAX_NUM_PACKETS = 1024; //highest 32 bit has 1024 number of packets - char* toFreePointers[MAX_NUM_PACKETS]; //pointers to free for each frame - int toFreePointersOffset[numberofListeningThreads]; //offset of pointers to free added for each thread + uint32_t numPackets[numberofListeningThreads]; //number of packets popped from the FIFO + + int MAX_NUM_PACKETS = 1024; //highest 32 bit has 1024 number of packets + uint32_t LAST_PACKET_VALUE; //last packet number + char* toFreePointers[MAX_NUM_PACKETS]; //pointers to free for each frame + int toFreePointersOffset[numberofListeningThreads]; //offset of pointers to free added for each thread + + char* frameBuffer[MAX_NUM_PACKETS]; //buffer offset created for a whole frame + int frameBufferoffset[numberofListeningThreads]; //buffer offset created for a whole frame for both listening threads + char* blankframe[MAX_NUM_PACKETS]; //blank buffer for a whole frame with missing packets + int blankoffset; //blank buffer offset + + bool fullframe[numberofListeningThreads]; //if full frame processed for each listening thread + volatile uint32_t threadFrameNumber[numberofListeningThreads]; //thread frame number for each listening thread buffer popped out + volatile uint32_t presentFrameNumber; //the current frame number aiming to be built + volatile uint32_t lastPacketNumber[numberofListeningThreads]; //last packet number got + volatile uint32_t currentPacketNumber[numberofListeningThreads];//current packet number + volatile int numberofMissingPackets[numberofListeningThreads]; // number of missing packets in this buffer + + eiger_packet_header_t* blankframe_header; + + for(int i=0; imissingPacket) = missingPacketValue; + //set each value inside blank frame to 0xff + for(int j=0;j<(oneDataSize);++j){ + blankframe_data = (unsigned char*)blankframe[i] + sizeof(eiger_packet_header_t) + j; + *(blankframe_data) = 0xFF; + } } - //--end of reset parameters before acquisition + guiData = latestData; //so that the first frame is always copied + LAST_PACKET_VALUE = (packetsPerFrame/numberofListeningThreads); + /* inner loop - loop for each buffer */ @@ -1877,22 +1919,147 @@ void UDPStandardImplementation::processWritingBufferPacketByPacket(int ithread){ //pop fifo and if end of acquisition - if(popAndCheckEndofAcquisition(ithread, wbuf, popReady, numPackets,toFreePointers,toFreePointersOffset)){ + if(popAndCheckEndofAcquisition(ithread, packetBuffer, popReady, numPackets,toFreePointers,toFreePointersOffset)){ #ifdef DEBUG4 - cprintf(GREEN,"Writing_Thread %d: All dummy-end buffers popped\n", ithread); + cprintf(GREEN,"All dummy-end buffers popped\n", ithread); #endif //finish missing packets - - if(myDetectorType == EIGER && - ((tempoffset[0]!=0) || (tempoffset[1]!=(packetsPerFrame/numberofListeningThreads)))); + if(((frameBufferoffset[0]!=0) || (frameBufferoffset[1]!=(packetsPerFrame/numberofListeningThreads)))); else{ - stopWriting(ithread,wbuf); + stopWriting(ithread,packetBuffer); continue; } } + for(int i=0;ipacketNumber),lastPacketNumber[i],frameBufferoffset[i] ); + cprintf(RED,"Fifo %d: Add missing packets to the right fnum %d\n", + i,presentFrameNumber); +#endif + numberofMissingPackets[i] = (LAST_PACKET_VALUE - lastPacketNumber[i]); + } + //correct packet (but never dummy frame)------------------------------------------- + else{ + //update current packet + eiger_packet_footer_t* packetBuffer_footer = (eiger_packet_footer_t*)(packetBuffer[i] + footerOffset + HEADER_SIZE_NUM_TOT_PACKETS); + currentPacketNumber[i] = *( (uint16_t*) packetBuffer_footer->packetNumber); +#ifdef DEBUG4 + cprintf(GREEN,"Fifo %d: Correct Packet has fnum %d, pnum %d, last_packet %d, pnum_offset\n", + i,threadFrameNumber[i],currentPacketNumber[i],lastPacketNumber[i],frameBufferoffset[i]); +#endif + numberofMissingPackets[i] = (currentPacketNumber[i] - lastPacketNumber[i] - 1); + + } + + + //add missing packets + for(int j=0;jmissingPacket)!= missingPacketValue){ + blankframe_header = (eiger_packet_header_t*) blankframe[blankoffset]; + cprintf(BG_RED, "Fifo %d: Missing Packet Error: Adding blank packets mismatch " + "pnum_offset %d, fnum_thread %d, missingpacket_buffer 0x%x, missingpacket_blank 0x%x\n", + i,frameBufferoffset[i],threadFrameNumber[i], + *( (uint16_t*) frameBuffer_header->missingPacket), + *( (uint16_t*) blankframe_header->missingPacket)); + exit(-1); + }else{ +#ifdef DEBUG4 + cprintf(GREEN, "Fifo %d: Missing Packet Adding blank packets success " + "pnum_offset %d, fnum_thread %d, missingpacket_buffer 0x%x\n", + i,frameBufferoffset[i],threadFrameNumber[i], + *( (uint16_t*) frameBuffer_header->missingPacket)); +#endif + frameBufferoffset[i]++; + blankoffset++; + } + if(threadFrameNumber[i] != presentFrameNumber){ + //set fullframe and dont let fifo pop over it + fullframe[i] = true; + popReady[i] = false; + } + } + + //add current packet + if(threadFrameNumber[i] == presentFrameNumber){ + if(currentPacketNumber[i] != (uint32_t)(frameBufferoffset[i]-(i*packetsPerFrame/numberofListeningThreads))+1){ + cprintf(BG_RED, "Fifo %d: Correct Packet Error:Adding current packet mismatch " + "pnum_offset %d,pnum %d fnum %d, (firmware fnum %d)\n", + i,frameBufferoffset[i],currentPacketNumber[i], + threadFrameNumber[i],(uint32_t)(*( (uint64_t*) packetBuffer_footer))); + exit(-1); + } + + frameBuffer[frameBufferoffset[i]] = packetBuffer[i] + HEADER_SIZE_NUM_TOT_PACKETS; + tempframe_header = (eiger_packet_header_t*) tempbuffer[tempoffset[i]]; + tempframe_footer = (eiger_packet_footer_t*) (tempbuffer[tempoffset[i]] + footer_offset); + } + + + + if(threadFrameNumber[i] != presentFrameNumber) + threadFrameNumber[i] = presentFrameNumber; + + + + + + + + + + } + + } + + + } + + @@ -1904,10 +2071,11 @@ void UDPStandardImplementation::processWritingBufferPacketByPacket(int ithread){ waitWritingBufferForNextAcquisition(ithread); }/*--end of loop for each acquisition (outer loop) */ - } + + void UDPStandardImplementation::waitWritingBufferForNextAcquisition(int ithread){ FILE_LOG(logDEBUG1) << __AT__ << " called"; @@ -2428,7 +2596,7 @@ void UDPStandardImplementation::handleDataCompression(int ithread, char* wbuffer br=0; if (thisEvent==PHOTON_MAX) { receiverData[ithread]->getFrameNumber(buff[0]); - //iFrame=receiverdata[ithread]->getFrameNumber(buff); + //iFrame=receiverData[ithread]->getFrameNumber(buff); #ifdef MYROOT1 myTree[ithread]->Fill(); //cout << "Fill in event: frmNr: " << iFrame << " ix " << ix << " iy " << iy << " type " << thisEvent << endl; @@ -2524,37 +2692,13 @@ int UDPStandardImplementation::startWriting(){ - int ret,i,j; - bool endofacquisition; - int nf; - bool fullframe[numListeningThreads]; - volatile uint32_t tempframenum[numListeningThreads]; - uint32_t presentframenum; - uint32_t lastpacketheader[numListeningThreads], currentpacketheader[numListeningThreads]; - int numberofmissingpackets[numListeningThreads]; - - - - char* tempbuffer[MAX_VALUE]; - char* blankframe[MAX_VALUE]; - int tempoffset[numListeningThreads]; - int blankoffset; - for(i=0;imissingpacket) = missingPacketValue; - - //set each value inside blank frame to 0xff - for(j=0;j<(oneDataSize);++j){ - blankframe_data = (unsigned char*)blankframe[i] + sizeof(eiger_packet_header_t) + j; - *(blankframe_data) = 0xFF; - } - //verify - if (*( (uint16_t*) blankframe_header->missingpacket) != missingPacketValue){ - cprintf(RED,"blank frame not detected at %d: 0x%x\n",i,*( (uint16_t*) blankframe_header->missingpacket) ); - exit(-1); - } -#ifdef FIFO_DEBUG - cprintf(GREEN,"packet %d blank frame 0x%x\n",i,(void*)(blankframe[i])); -#endif - } - - //last packet numbers for different dynamic ranges - LAST_PACKET_VALUE = (packetsPerFrame/numListeningThreads); - } - - - //allow them all to be popped initially - for(i=0;imissingpacket)!= missingPacketValue){ - cprintf(BG_RED, "dummy blank mismatch num4 earlier2! " - "i:%d pnum:%d fnum:%d missingpacket:0x%x actual missingpacket:0x%x\n", - i,tempoffset[i],tempframenum[i], - *( (uint16_t*) tempframe_header->missingpacket), - *( (uint16_t*) blankframe_header->missingpacket)); - exit(-1); - }else -#ifdef PADDING - cprintf(GREEN, "blank packet i:%d pnum:%d fnum:%d missingpacket:0x%x\n",i, - tempoffset[i],tempframenum[i],*( (uint16_t*) tempframe_header->missingpacket)); -#endif - tempoffset[i]++; - blankoffset++; - } - //set fullframe and dont let fifo pop over it until written - fullframe[i] = true; - popready[i] = false; - } - } -#ifdef EIGER_DEBUG3 - else{ - cprintf(RED, "WARNING: Got a weird packet size: %d from fifo %d\n", numpackets[i],i); - continue; - } -#endif - } - - - //not a full frame if(!fullframe[i]){ - wbuf_footer = (eiger_packet_footer_t*)(wbuf[i] + footer_offset + HEADER_SIZE_NUM_TOT_PACKETS); -#ifdef EIGER_DEBUG3 - cprintf(GREEN,"**pnum of %d: %d\n",i,(*( (uint16_t*) wbuf_footer->packetnum))); -#endif - //update frame number - if(!((uint32_t)(*( (uint64_t*) wbuf_footer)))){ - cprintf(BG_RED,"%d VERY WEIRD frame number=%d and popready:%d\n", - i,(uint32_t)(*( (uint64_t*) wbuf_footer)),popready[i]); - popready[i]=true; - continue; - } - tempframenum[i] =(uint32_t)(*( (uint64_t*) wbuf_footer)); - tempframenum[i] += (startFrameIndex-1); - //WRONG FRAME - leave - if(tempframenum[i] != presentframenum){ -#ifdef PADDING - cout<<"wrong packet"<packetnum)); - -#endif - tempframenum[i] = presentframenum; - //add missing packets - numberofmissingpackets[i] = (LAST_PACKET_VALUE - lastpacketheader[i]); -#ifdef VERYDEBUG - if(numberofmissingpackets[i]>0) - cprintf(BG_RED,"fifo:%d missing packet from: %d now\n",i,lastpacketheader[i]); -#endif - //to decrement from packetsInFile to calculate packet loss - for(j=0;jmissingpacket)!= missingPacketValue){ - cprintf(BG_RED, "wrong blank mismatch num4 earlier2! " - "i:%d pnum:%d fnum:%d missingpacket:0x%x actual missingpacket:0x%x add:0x%p\n", - i,tempoffset[i],tempframenum[i], - *( (uint16_t*) tempframe_header->missingpacket), - *( (uint16_t*) blankframe_header->missingpacket), - (void*)(tempbuffer[tempoffset[i]])); - exit(-1); - }else -#ifdef PADDING - cprintf(GREEN, "blank packet i:%d pnum:%d fnum:%d missingpacket:0x%x add:0x%x\n", - i,tempoffset[i],tempframenum[i], - *( (uint16_t*) tempframe_header->missingpacket), - (void*)(tempbuffer[tempoffset[i]])); -#endif - tempoffset[i] ++; - blankoffset ++; - } - //set fullframe and dont let fifo pop over it until written - fullframe[i] = true; - popready[i] = false; - } //CORRECT FRAME - continue building frame - else { -#ifdef PADDING - cout<<"correct packet"<packetnum); -#ifdef VERYVERBOSE - cprintf(GREEN,"**fifo:%d currentpacketheader: %d lastpacketheader %d tempoffset:%d\n", - i,currentpacketheader[i],lastpacketheader[i], tempoffset[i]); -#endif - //add missing packets - numberofmissingpackets[i] = (currentpacketheader[i] - lastpacketheader[i] -1); -#ifdef VERYDEBUG - if(numberofmissingpackets[i]>0) - cprintf(BG_RED,"fifo:%d missing packet from: %d now at :%d tempoffset:%d\n", - i,lastpacketheader[i],currentpacketheader[i],tempoffset[i]); -#endif - //to decrement from packetsInFile to calculate packet loss - for(j=0;jmissingpacket)!= missingPacketValue){ - cprintf(BG_RED, "correct blank mismatch num4 earlier2! " - "i:%d pnum:%d fnum:%d missingpacket:0x%x actual missingpacket:0x%x add:0x%p\n", - i,tempoffset[i],tempframenum[i], - *( (uint16_t*) tempframe_header->missingpacket), - *( (uint16_t*) blankframe_header->missingpacket), - (void*)(tempbuffer[tempoffset[i]])); - exit(-1); - }else -#ifdef PADDING - cprintf(GREEN, "blank packet i:%d pnum:%d fnum:%d missingpacket:0x%x add:0x%x\n", - i,tempoffset[i],tempframenum[i], - *( (uint16_t*) tempframe_header->missingpacket), - (void*)(tempbuffer[tempoffset[i]])); -#endif - tempoffset[i] ++; - blankoffset ++; - } - //add current packet - if(currentpacketheader[i] != (uint32_t)(tempoffset[i]-(i*packetsPerFrame/numListeningThreads))+1){ - cprintf(BG_RED, "correct pnum mismatch earlier! tempoffset[%d]:%d pnum:%d fnum:%d rfnum:%d\n", - i,tempoffset[i],currentpacketheader[i], - tempframenum[i],(uint32_t)(*( (uint64_t*) wbuf_footer))); - exit(-1); - } tempbuffer[tempoffset[i]] = wbuf[i] + HEADER_SIZE_NUM_TOT_PACKETS; tempframe_header = (eiger_packet_header_t*) tempbuffer[tempoffset[i]]; From 837d0dce03f184d5a8040fb92a0e9a415362f18e Mon Sep 17 00:00:00 2001 From: Dhanya Maliakal Date: Tue, 27 Oct 2015 09:31:08 +0100 Subject: [PATCH 42/68] dsg --- .../src/UDPStandardImplementation.cpp | 47 ++++++++++--------- 1 file changed, 26 insertions(+), 21 deletions(-) diff --git a/slsReceiverSoftware/src/UDPStandardImplementation.cpp b/slsReceiverSoftware/src/UDPStandardImplementation.cpp index 34ee816cb..a6833e57d 100644 --- a/slsReceiverSoftware/src/UDPStandardImplementation.cpp +++ b/slsReceiverSoftware/src/UDPStandardImplementation.cpp @@ -1935,7 +1935,9 @@ void UDPStandardImplementation::processWritingBufferPacketByPacket(int ithread){ for(int i=0;ipacketNumber); +#ifdef DEBUG4 + cprintf(GREEN,"Fifo %d: Packet has fnum %d, pnum %d, last_packet %d, pnum_offset\n", + i,threadFrameNumber[i],currentPacketNumber[i],lastPacketNumber[i],frameBufferoffset[i]); +#endif } @@ -1970,8 +1980,9 @@ void UDPStandardImplementation::processWritingBufferPacketByPacket(int ithread){ threadFrameNumber[i] = dummyPacketValue; } - //wrong packet (dummy (not full) or from next frame))-------------------------------- - else if (threadFrameNumber[i] != presentFrameNumber){ + /**check if next frame lastpacket number is actually +1*/ + //wrong packet & correct (dummy (not full) or from future packet))-------------------------------- + else{// if ((threadFrameNumber[i] != presentFrameNumber) ||(currentPacketNumber[i] != lastPacketNumber[i] + 1)){ #ifdef DEBUG4 cprintf(GREEN,"Fifo %d: Wrong Packet has fnum %d, (firmware fnum %d), pnum %d, last_packet %d, pnum_offset %d\n", i,presentFrameNumber[i],(uint32_t)(*( (uint64_t*) packetBuffer_footer)), @@ -1979,20 +1990,12 @@ void UDPStandardImplementation::processWritingBufferPacketByPacket(int ithread){ cprintf(RED,"Fifo %d: Add missing packets to the right fnum %d\n", i,presentFrameNumber); #endif - numberofMissingPackets[i] = (LAST_PACKET_VALUE - lastPacketNumber[i]); + if(threadFrameNumber[i] != presentFrameNumber) + numberofMissingPackets[i] = (LAST_PACKET_VALUE - lastPacketNumber[i]); + else + numberofMissingPackets[i] = (currentPacketNumber[i] - lastPacketNumber[i] - 1); } - //correct packet (but never dummy frame)------------------------------------------- - else{ - //update current packet - eiger_packet_footer_t* packetBuffer_footer = (eiger_packet_footer_t*)(packetBuffer[i] + footerOffset + HEADER_SIZE_NUM_TOT_PACKETS); - currentPacketNumber[i] = *( (uint16_t*) packetBuffer_footer->packetNumber); -#ifdef DEBUG4 - cprintf(GREEN,"Fifo %d: Correct Packet has fnum %d, pnum %d, last_packet %d, pnum_offset\n", - i,threadFrameNumber[i],currentPacketNumber[i],lastPacketNumber[i],frameBufferoffset[i]); -#endif - numberofMissingPackets[i] = (currentPacketNumber[i] - lastPacketNumber[i] - 1); - } //add missing packets @@ -2017,13 +2020,13 @@ void UDPStandardImplementation::processWritingBufferPacketByPacket(int ithread){ frameBufferoffset[i]++; blankoffset++; } - if(threadFrameNumber[i] != presentFrameNumber){ - //set fullframe and dont let fifo pop over it - fullframe[i] = true; - popReady[i] = false; - } - } + } + if((numPackets[i] == dummyPacketValue) ||(threadFrameNumber[i] != presentFrameNumber)){ + //set fullframe and dont let fifo pop over it + fullframe[i] = true; + popReady[i] = false; + } //add current packet if(threadFrameNumber[i] == presentFrameNumber){ if(currentPacketNumber[i] != (uint32_t)(frameBufferoffset[i]-(i*packetsPerFrame/numberofListeningThreads))+1){ @@ -2054,6 +2057,8 @@ void UDPStandardImplementation::processWritingBufferPacketByPacket(int ithread){ } + numMissingPackets += numberofMissingPackets[i]; + } From 5f3de2057cd718caa3b26d0b0fe787b750f760c2 Mon Sep 17 00:00:00 2001 From: Dhanya Maliakal Date: Tue, 27 Oct 2015 14:33:26 +0100 Subject: [PATCH 43/68] df --- slsReceiverSoftware/include/slsReceiver.h | 6 +- .../include/slsReceiverUsers.h | 6 +- .../src/UDPStandardImplementation.cpp | 441 ++++++------------ slsReceiverSoftware/src/slsReceiver.cpp | 6 +- .../src/slsReceiverTCPIPInterface.cpp | 14 +- slsReceiverSoftware/src/slsReceiverUsers.cpp | 6 +- 6 files changed, 153 insertions(+), 326 deletions(-) diff --git a/slsReceiverSoftware/include/slsReceiver.h b/slsReceiverSoftware/include/slsReceiver.h index e76ea7d1b..94548caed 100644 --- a/slsReceiverSoftware/include/slsReceiver.h +++ b/slsReceiverSoftware/include/slsReceiver.h @@ -62,14 +62,14 @@ class slsReceiver : private virtual slsReceiverDefs { @param func callback to be called when starting the acquisition. Its arguments are filepath filename fileindex data size \returns 0 callback takes care of open,close,write file; 1 callback writes file, we have to open, close it; 2 we open, close, write file, callback does not do anything */ - void registerCallBackStartAcquisition(int (*func)(char*, char*,int, int, void*),void *arg); + void registerCallBackStartAcquisition(int (*func)(char*, char*,uint64_t, uint32_t, void*),void *arg); /** callback argument is toatal farmes caught */ - void registerCallBackAcquisitionFinished(void (*func)(int, void*),void *arg); + void registerCallBackAcquisitionFinished(void (*func)(uint64_t, void*),void *arg); /** args to raw data ready callback are @@ -79,7 +79,7 @@ class slsReceiver : private virtual slsReceiverDefs { file descriptor guidatapointer (NULL, no data required) */ - void registerCallBackRawDataReady(void (*func)(int, char*, int, FILE*, char*, void*),void *arg); + void registerCallBackRawDataReady(void (*func)(uint64_t, char*, uint32_t, FILE*, char*, void*),void *arg); private: diff --git a/slsReceiverSoftware/include/slsReceiverUsers.h b/slsReceiverSoftware/include/slsReceiverUsers.h index 50d6f38fe..0d242d372 100644 --- a/slsReceiverSoftware/include/slsReceiverUsers.h +++ b/slsReceiverSoftware/include/slsReceiverUsers.h @@ -61,7 +61,7 @@ public: */ - void registerCallBackStartAcquisition(int (*func)(char* filepath, char* filename,int fileindex, int datasize, void*),void *arg); + void registerCallBackStartAcquisition(int (*func)(char* filepath, char* filename,uint64_t fileindex, uint32_t datasize, void*),void *arg); /** @@ -71,7 +71,7 @@ public: */ - void registerCallBackAcquisitionFinished(void (*func)(int nf, void*),void *arg); + void registerCallBackAcquisitionFinished(void (*func)(uint64_t nf, void*),void *arg); @@ -81,7 +81,7 @@ public: \returns nothing */ - void registerCallBackRawDataReady(void (*func)(int framenumber, char* datapointer, int datasize, FILE* filedescriptor, char* guidatapointer, void*),void *arg); + void registerCallBackRawDataReady(void (*func)(uint64_t framenumber, char* datapointer, uint32_t datasize, FILE* filedescriptor, char* guidatapointer, void*),void *arg); // made static to close thread files with ctrl+c static slsReceiver* receiver; diff --git a/slsReceiverSoftware/src/UDPStandardImplementation.cpp b/slsReceiverSoftware/src/UDPStandardImplementation.cpp index a6833e57d..b15a48cc4 100644 --- a/slsReceiverSoftware/src/UDPStandardImplementation.cpp +++ b/slsReceiverSoftware/src/UDPStandardImplementation.cpp @@ -1921,7 +1921,7 @@ void UDPStandardImplementation::processWritingBufferPacketByPacket(int ithread){ //pop fifo and if end of acquisition if(popAndCheckEndofAcquisition(ithread, packetBuffer, popReady, numPackets,toFreePointers,toFreePointersOffset)){ #ifdef DEBUG4 - cprintf(GREEN,"All dummy-end buffers popped\n", ithread); + cprintf(GREEN,"Writing_Thread All dummy-end buffers popped\n", ithread); #endif //finish missing packets if(((frameBufferoffset[0]!=0) || (frameBufferoffset[1]!=(packetsPerFrame/numberofListeningThreads)))); @@ -1932,22 +1932,25 @@ void UDPStandardImplementation::processWritingBufferPacketByPacket(int ithread){ } - + //get a full frame------------------------------------------------------------------------------------------------------- for(int i=0;ipacketNumber); -#ifdef DEBUG4 - cprintf(GREEN,"Fifo %d: Packet has fnum %d, pnum %d, last_packet %d, pnum_offset\n", - i,threadFrameNumber[i],currentPacketNumber[i],lastPacketNumber[i],frameBufferoffset[i]); -#endif } - - - //dummy not done ----------------------------- - if(numPackets[i] == dummyPacketValue){ + //calculate number of missing packets----------------------------------------------------- + numberofMissingPackets[i] = 0; #ifdef DEBUG4 - cprintf(RED, "Fifo %d: Dummy packet: Adding missing packets to the last frame\n", i); -#endif - numberofMissingPackets[i] = (LAST_PACKET_VALUE - lastPacketNumber[i]); - threadFrameNumber[i] = dummyPacketValue; - } - - /**check if next frame lastpacket number is actually +1*/ - //wrong packet & correct (dummy (not full) or from future packet))-------------------------------- - else{// if ((threadFrameNumber[i] != presentFrameNumber) ||(currentPacketNumber[i] != lastPacketNumber[i] + 1)){ -#ifdef DEBUG4 - cprintf(GREEN,"Fifo %d: Wrong Packet has fnum %d, (firmware fnum %d), pnum %d, last_packet %d, pnum_offset %d\n", + if(numPackets[i] == dummyPacketValue) + cprintf(GREEN, "Fifo %d: Dummy packet: Adding missing packets to the last frame\n", i); + else{ + cprintf(GREEN,"Fifo %d: fnum %d, (FW_fnum %d), pnum %d, last_pnum %d, pnum_offset %d\n" + "Fifo %d: Add missing packets to the right fnum %d\n", i,presentFrameNumber[i],(uint32_t)(*( (uint64_t*) packetBuffer_footer)), - *( (uint16_t*) packetBuffer_footer->packetNumber),lastPacketNumber[i],frameBufferoffset[i] ); - cprintf(RED,"Fifo %d: Add missing packets to the right fnum %d\n", + *( (uint16_t*) packetBuffer_footer->packetNumber),lastPacketNumber[i],frameBufferoffset[i], i,presentFrameNumber); -#endif - if(threadFrameNumber[i] != presentFrameNumber) - numberofMissingPackets[i] = (LAST_PACKET_VALUE - lastPacketNumber[i]); - else - numberofMissingPackets[i] = (currentPacketNumber[i] - lastPacketNumber[i] - 1); } +#endif + if((numPackets[i] == dummyPacketValue) || (threadFrameNumber[i] != presentFrameNumber)) + numberofMissingPackets[i] = (LAST_PACKET_VALUE - lastPacketNumber[i]); + else + numberofMissingPackets[i] = (currentPacketNumber[i] - lastPacketNumber[i] - 1); - //add missing packets + //add missing packets--------------------------------------------------------------------- for(int j=0;jmissingPacket)!= missingPacketValue){ blankframe_header = (eiger_packet_header_t*) blankframe[blankoffset]; cprintf(BG_RED, "Fifo %d: Missing Packet Error: Adding blank packets mismatch " - "pnum_offset %d, fnum_thread %d, missingpacket_buffer 0x%x, missingpacket_blank 0x%x\n", - i,frameBufferoffset[i],threadFrameNumber[i], + "pnum_offset %d, pnum %d, fnum_thread %d, missingpacket_buffer 0x%x, missingpacket_blank 0x%x\n", + i,frameBufferoffset[i],currentPacketNumber[i],threadFrameNumber[i], *( (uint16_t*) frameBuffer_header->missingPacket), *( (uint16_t*) blankframe_header->missingPacket)); exit(-1); }else{ #ifdef DEBUG4 - cprintf(GREEN, "Fifo %d: Missing Packet Adding blank packets success " - "pnum_offset %d, fnum_thread %d, missingpacket_buffer 0x%x\n", - i,frameBufferoffset[i],threadFrameNumber[i], + cprintf(RED, "Fifo %d: Missing Packet: Adding blank packets success " + "pnum_offset %d, pnum %d, fnum_thread %d, missingpacket_buffer 0x%x\n", + i,frameBufferoffset[i],currentPacketNumber[i],threadFrameNumber[i], *( (uint16_t*) frameBuffer_header->missingPacket)); #endif frameBufferoffset[i]++; blankoffset++; } + } - } - if((numPackets[i] == dummyPacketValue) ||(threadFrameNumber[i] != presentFrameNumber)){ - //set fullframe and dont let fifo pop over it - fullframe[i] = true; + //missed packets/future packet: do not pop over and determine fullframe-------------------- + if(numberofMissingPackets[i]){ popReady[i] = false; + if((numPackets[i] == dummyPacketValue) ||(threadFrameNumber[i] != presentFrameNumber)) + fullframe[i] = true; + else{ + fullframe[i] = false; + //update last packet + lastPacketNumber[i] = currentPacketNumber[i] - 1; + } + if(threadFrameNumber[i] != presentFrameNumber) + threadFrameNumber[i] = presentFrameNumber; + numMissingPackets += numberofMissingPackets[i]; } - //add current packet - if(threadFrameNumber[i] == presentFrameNumber){ + + //no missed packet: add current packet-------------------------------------------------------------- + else{ if(currentPacketNumber[i] != (uint32_t)(frameBufferoffset[i]-(i*packetsPerFrame/numberofListeningThreads))+1){ - cprintf(BG_RED, "Fifo %d: Correct Packet Error:Adding current packet mismatch " - "pnum_offset %d,pnum %d fnum %d, (firmware fnum %d)\n", + cprintf(BG_RED, "Fifo %d: Correct Packet Offset Error:Adding current packet mismatch " + "pnum_offset %d,pnum %d fnum_thread %d, (FW_fnum %d)\n", i,frameBufferoffset[i],currentPacketNumber[i], threadFrameNumber[i],(uint32_t)(*( (uint64_t*) packetBuffer_footer))); exit(-1); } frameBuffer[frameBufferoffset[i]] = packetBuffer[i] + HEADER_SIZE_NUM_TOT_PACKETS; - tempframe_header = (eiger_packet_header_t*) tempbuffer[tempoffset[i]]; - tempframe_footer = (eiger_packet_footer_t*) (tempbuffer[tempoffset[i]] + footer_offset); +#ifdef DEBUG4 + eiger_packet_header_t* frameBuffer_header = (eiger_packet_header_t*) frameBuffer[frameBufferoffset[i]]; + eiger_packet_footer_t* frameBuffer_footer = (eiger_packet_footer_t*) (frameBuffer[frameBufferoffset[i]] + footer_offset); + cprintf(GREEN, "Fifo %d: Current Packet added success:" + "pnum_offset %d, pnum %d, fnum_thread %d, missingpacket_buffer 0x%x\n", + i,frameBufferoffset[i],currentPacketNumber[i],threadFrameNumber[i], + *( (uint16_t*) frameBuffer_header->missingPacket)); +#endif + frameBufferoffset[i]++; + //update last packet + lastPacketNumber[i] = currentPacketNumber[i]; + popReady[i] = true; + fullframe[i] = false; + if(currentPacketNumber[i] == LAST_PACKET_VALUE){ +#ifdef DEBUG4 + cprintf(GREEN, "Fifo %d: Got last packet\n",i); +#endif + popReady[i] = false; + fullframe[i] = true; + } } + } + } + //full frame + if(fullframe[0] && fullframe[1]){ + currentPacketNumber = presentFrameNumber; + numTotMissingPacketsInFile += numMissingPackets; + numTotMissingPackets += numMissingPackets; +#ifdef FNUM_DEBUG + cprintf(GREEN,"**fnum:%d**\n",currframenum); +#endif +#ifdef MISSINGP_DEBUG + if(numberofMissingPackets[0]) + cprintf(RED, "Fifo 0 missing packets %d for fnum %d\n",numberofMissingPackets[0],currentPacketNumber); + if(numberofMissingPackets[1]) + cprintf(RED, "Fifo 1 missing packets%d for fnum %d\n",numberofMissingPackets[1],currentPacketNumber); + if(numMissingPackets){ + cprintf(RED, "Total missing packets %d for fnum %d\n",numMissingPackets,currentPacketNumber); + for (int j=0;jmissingPacket)==missingPacketValue) + cprintf(RED,"Found missing packet at pnum %d\n",j); + } + } +#endif - if(threadFrameNumber[i] != presentFrameNumber) - threadFrameNumber[i] = presentFrameNumber; - - - - - - - + //write and copy to gui + handleWithoutDataCompression(ithread,frameBuffer,packetsPerFrame); + + //freeing + for(int j=0;jpush(toFreePointers[j])); +#ifdef FIFODEBUG + cprintf(GREEN,"Fifo 0: Writing_Thread freed: pushed into fifofree %p\n",ithread, (void*)(toFreePointers[j])); +#endif + } + for(int j=(packetsPerFrame/numberofListeningThreads);jpush(toFreePointers[j])); +#ifdef FIFODEBUG + cprintf(GREEN,"Fifo 1: Writing_Thread freed: pushed into fifofree %p\n",ithread, (void*)(toFreePointers[j])); +#endif + } +#ifdef DEBUG4 + cprintf(GREEN,"Writing_Thread: finished freeing\n"); +#endif + //reset a few stuff + presentFrameNumber++; + for(int i=0; ipacketNumber), (void*)(packetBuffer[i])); + } +#endif @@ -2646,244 +2712,3 @@ void UDPStandardImplementation::handleDataCompression(int ithread, char* wbuffer } - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -int UDPStandardImplementation::startWriting(){ - FILE_LOG(logDEBUG1) << __AT__ << " called"; - - - - - - - eiger_packet_footer_t* wbuf_footer=0; - eiger_packet_header_t* tempframe_header=0; - eiger_packet_footer_t* tempframe_footer=0; - - - - - while(1){ - - - - - - - while((1<packetnum),tempoffset[i]); -#endif - if(*( (uint16_t*) tempframe_footer->packetnum)!= (tempoffset[i]-(i*packetsPerFrame/numListeningThreads))+1){ - cprintf(BG_RED, "pnum mismatch num4 earlier! i:%d pnum:%d pnum orig:%d fnum:%d add:0x%p\n", - i,*( (uint16_t*) tempframe_footer->packetnum),*( (uint16_t*) wbuf_footer->packetnum), - tempframenum[i],(void*)(tempbuffer[tempoffset[i]])); - exit(-1); - } -#ifdef PADDING - cprintf(GREEN, "normal packet i:%d pnum:%d fnum:%d missingpacket:0x%x add:0x%x\n", - i,tempoffset[i],tempframenum[i], - *( (uint16_t*) tempframe_header->missingpacket), - (void*)(tempbuffer[tempoffset[i]])); -#endif - tempoffset[i] ++; - //update last packet - lastpacketheader[i] = currentpacketheader[i]; - popready[i] = true; - //last frame got, this will save time and also for last frames, it doesnt wait for stop receiver - if(currentpacketheader[i] == LAST_PACKET_VALUE){ -#ifdef EIGER_DEBUG3 - cprintf(GREEN, "Got last packet\n"); -#endif - fullframe[i] = true; - popready[i] = false; - } - } - } - } - } - - - - //FULL FRAME - if(fullframe[0] && fullframe[1]){ - - //determine frame number - if(tempframenum[0] != tempframenum[1]) - cprintf(RED,"Frame numbers mismatch!!! %d %d\n",tempframenum[0],tempframenum[1]); - currframenum = tempframenum[0]; - numMissingPackets += (numberofmissingpackets[0]+numberofmissingpackets[1]); - numTotMissingPacketsInFile += numMissingPackets; - numTotMissingPackets += numMissingPackets; -#ifdef EIGER_DEBUG2 - cprintf(GREEN,"**fnum:%d**\n",currframenum); -#endif -#ifdef EIGER_DEBUG3 - if(numberofmissingpackets[0]) - cprintf(RED, "fifo 0 missing packets:%d fnum:%d\n",numberofmissingpackets[0],currframenum); - if(numberofmissingpackets[1]) - cprintf(RED, "fifo 1 missing packets:%d fnum:%d\n",numberofmissingpackets[1],currframenum); - if(numMissingPackets){ - cprintf(RED, "numMissingPackets:%d fnum:%d\n",numMissingPackets,currframenum); - - for (j=0;jmissingpacket)==missingPacketValue) - cprintf(RED,"found the missing packet at pnum:%d\n",j); - } - } -#endif - - - //write and copy to gui - handleWithoutDataCompression(ithread,tempbuffer,packetsPerFrame); - - - //freeing - for(j=0;jpush(tofree[j])); -#ifdef FIFO_DEBUG - cprintf(GREEN,"%d writer freed pushed into fifofree %x for listener %d\n",ithread, (void*)(tofree[j]),0); -#endif - } - for(j=(packetsPerFrame/numListeningThreads);jpush(tofree[j])); -#ifdef FIFO_DEBUG - cprintf(GREEN,"%d writer freed pushed into fifofree %x for listener %d\n",ithread, (void*)(tofree[j]),1); -#endif - } -#ifdef VERYDEBUG - cprintf(GREEN,"finished freeing\n"); -#endif - - - //reset a few stuff - presentframenum = tempframenum[0]+1; - for(int i=0;ipacketnum)); - } -#endif - } - - - - - } - - } - - - return OK; -} - - - - - - - - - - - - - - diff --git a/slsReceiverSoftware/src/slsReceiver.cpp b/slsReceiverSoftware/src/slsReceiver.cpp index 5783e601c..15149dde0 100644 --- a/slsReceiverSoftware/src/slsReceiver.cpp +++ b/slsReceiverSoftware/src/slsReceiver.cpp @@ -166,20 +166,20 @@ int64_t slsReceiver::getReceiverVersion(){ } -void slsReceiver::registerCallBackStartAcquisition(int (*func)(char*, char*,int, int, void*),void *arg){ +void slsReceiver::registerCallBackStartAcquisition(int (*func)(char*, char*,uint64_t, uint32_t, void*),void *arg){ //tcpipInterface udp_interface->registerCallBackStartAcquisition(func,arg); } -void slsReceiver::registerCallBackAcquisitionFinished(void (*func)(int, void*),void *arg){ +void slsReceiver::registerCallBackAcquisitionFinished(void (*func)(uint64_t, void*),void *arg){ //tcpipInterface udp_interface->registerCallBackAcquisitionFinished(func,arg); } -void slsReceiver::registerCallBackRawDataReady(void (*func)(int, char*, int, FILE*, char*, void*),void *arg){ +void slsReceiver::registerCallBackRawDataReady(void (*func)(uint64_t, char*, uint32_t, FILE*, char*, void*),void *arg){ //tcpipInterface udp_interface->registerCallBackRawDataReady(func,arg); } diff --git a/slsReceiverSoftware/src/slsReceiverTCPIPInterface.cpp b/slsReceiverSoftware/src/slsReceiverTCPIPInterface.cpp index cfab3e75d..5b4664e55 100644 --- a/slsReceiverSoftware/src/slsReceiverTCPIPInterface.cpp +++ b/slsReceiverSoftware/src/slsReceiverTCPIPInterface.cpp @@ -9,6 +9,7 @@ #include "slsReceiverUsers.h" #include "slsReceiver.h" + #include //SIGINT #include //EXIT @@ -401,6 +402,7 @@ int slsReceiverTCPIPInterface::set_detector_type(){ } } } + } //#ifdef VERBOSE if(ret!=FAIL) cout << "detector type" << dr << endl; @@ -432,7 +434,7 @@ int slsReceiverTCPIPInterface::set_detector_type(){ int slsReceiverTCPIPInterface::set_file_name() { ret=OK; - char* retval[MAX_STR_LENGTH] = NULL; + char* retval = NULL; char defaultVal[MAX_STR_LENGTH] = ""; char fName[MAX_STR_LENGTH]; strcpy(mess,"Could not set file name"); @@ -457,7 +459,7 @@ int slsReceiverTCPIPInterface::set_file_name() { } else{ receiverBase->setFileName(fName); - retval = receiveBase->getFileName(); + retval = receiverBase->getFileName(); if(retval == NULL) ret = FAIL; } @@ -526,8 +528,8 @@ int slsReceiverTCPIPInterface::set_file_dir() { } else{ receiverBase->setFilePath(fPath); - retval = receiveBase->getFilePath(); - if(reval == NULL){ + retval = receiverBase->getFilePath(); + if(retval == NULL){ ret = FAIL; strcpy(mess,"receiver file path does not exist\n"); } @@ -741,8 +743,8 @@ int slsReceiverTCPIPInterface::setup_udp(){ //set up udp port sscanf(args[1],"%d",&udpport); sscanf(args[2],"%d",&udpport2); - receiverBase->setUDPPortNo(udpport); - receiverBase->setUDPPortNo2(udpport2); + receiverBase->setUDPPortNumber(udpport); + receiverBase->setUDPPortNumber2(udpport2); //setup udpip //get ethernet interface or IP to listen to cout << "Ethernet interface is " << args[0] << endl; diff --git a/slsReceiverSoftware/src/slsReceiverUsers.cpp b/slsReceiverSoftware/src/slsReceiverUsers.cpp index c27f1efc2..1df35558c 100644 --- a/slsReceiverSoftware/src/slsReceiverUsers.cpp +++ b/slsReceiverSoftware/src/slsReceiverUsers.cpp @@ -29,18 +29,18 @@ int64_t slsReceiverUsers::getReceiverVersion(){ } -void slsReceiverUsers::registerCallBackStartAcquisition(int (*func)(char*, char*,int, int, void*),void *arg){ +void slsReceiverUsers::registerCallBackStartAcquisition(int (*func)(char*, char*,uint64_t, uint32_t, void*),void *arg){ slsReceiverUsers::receiver->registerCallBackStartAcquisition(func,arg); } -void slsReceiverUsers::registerCallBackAcquisitionFinished(void (*func)(int, void*),void *arg){ +void slsReceiverUsers::registerCallBackAcquisitionFinished(void (*func)(uint64_t, void*),void *arg){ slsReceiverUsers::receiver->registerCallBackAcquisitionFinished(func,arg); } -void slsReceiverUsers::registerCallBackRawDataReady(void (*func)(int, char*, int, FILE*, char*, void*),void *arg){ +void slsReceiverUsers::registerCallBackRawDataReady(void (*func)(uint64_t, char*, uint32_t, FILE*, char*, void*),void *arg){ slsReceiverUsers::receiver->registerCallBackRawDataReady(func,arg); } From 58bfa296beca9d19933de635caf5e622bd5721c1 Mon Sep 17 00:00:00 2001 From: l_msdetect Date: Wed, 28 Oct 2015 17:40:55 +0100 Subject: [PATCH 44/68] done --- .../include/UDPBaseImplementation.h | 14 +- slsReceiverSoftware/include/UDPInterface.h | 8 +- .../include/UDPStandardImplementation.h | 13 +- slsReceiverSoftware/include/slsReceiver.h | 6 +- .../include/slsReceiverUsers.h | 6 +- .../include/sls_receiver_defs.h | 49 +++++++ .../src/UDPBaseImplementation.cpp | 41 +++--- .../src/UDPStandardImplementation.cpp | 138 +++++++++--------- slsReceiverSoftware/src/slsReceiver.cpp | 6 +- .../src/slsReceiverTCPIPInterface.cpp | 28 ++-- slsReceiverSoftware/src/slsReceiverUsers.cpp | 6 +- 11 files changed, 182 insertions(+), 133 deletions(-) diff --git a/slsReceiverSoftware/include/UDPBaseImplementation.h b/slsReceiverSoftware/include/UDPBaseImplementation.h index 43f98b511..dfb7b0429 100644 --- a/slsReceiverSoftware/include/UDPBaseImplementation.h +++ b/slsReceiverSoftware/include/UDPBaseImplementation.h @@ -33,6 +33,10 @@ class UDPBaseImplementation : protected virtual slsReceiverDefs, public UDPInter */ virtual ~UDPBaseImplementation(); + /* + * Initialize class members + */ + void initializeMembers(); /************************************************************************* * Getters *************************************************************** @@ -180,7 +184,7 @@ class UDPBaseImplementation : protected virtual slsReceiverDefs, public UDPInter * Get Listening Status of Receiver * @return can be idle, listening or error depending on if the receiver is listening or not */ - slsReceiverDefs::runStatus getStatus() const; + runStatus getStatus() const; @@ -334,7 +338,7 @@ class UDPBaseImplementation : protected virtual slsReceiverDefs, public UDPInter * @param d detector type * @return OK or FAIL */ - int setDetectorType(const slsReceiverDefs::detectorType d); + int setDetectorType(const detectorType d); /** * Sets detector hostname (and corresponding detector variables in derived REST class) @@ -413,14 +417,14 @@ class UDPBaseImplementation : protected virtual slsReceiverDefs, public UDPInter * 1 callback writes file, we have to open, close it * 2 we open, close, write file, callback does not do anything */ - void registerCallBackStartAcquisition(int (*func)(char*, char*,uint64_t, uint32_t, void*),void *arg); + void registerCallBackStartAcquisition(int (*func)(char*, char*,int, int, void*),void *arg); /** * Call back for acquisition finished * callback argument is * total frames caught */ - void registerCallBackAcquisitionFinished(void (*func)(uint64_t, void*),void *arg); + void registerCallBackAcquisitionFinished(void (*func)(int, void*),void *arg); /** * Call back for raw data @@ -431,7 +435,7 @@ class UDPBaseImplementation : protected virtual slsReceiverDefs, public UDPInter * file descriptor * guidatapointer (NULL, no data required) */ - void registerCallBackRawDataReady(void (*func)(uint64_t, char*, uint32_t, FILE*, char*, void*),void *arg); + void registerCallBackRawDataReady(void (*func)(int, char*, int, FILE*, char*, void*),void *arg); diff --git a/slsReceiverSoftware/include/UDPInterface.h b/slsReceiverSoftware/include/UDPInterface.h index b62ad2eb0..1a6377653 100644 --- a/slsReceiverSoftware/include/UDPInterface.h +++ b/slsReceiverSoftware/include/UDPInterface.h @@ -407,7 +407,7 @@ class UDPInterface { /** * Reset acquisition parameters such as total frames caught for an entire acquisition (including all scans) */ - void resetAcquisitionCount(); + virtual void resetAcquisitionCount() = 0; /** * Start Listening for Packets by activating all configuration settings to receiver @@ -471,14 +471,14 @@ class UDPInterface { * 1 callback writes file, we have to open, close it * 2 we open, close, write file, callback does not do anything */ - virtual void registerCallBackStartAcquisition(int (*func)(char*, char*,uint64_t, uint32_t, void*),void *arg) = 0; + virtual void registerCallBackStartAcquisition(int (*func)(char*, char*,int, int, void*),void *arg) = 0; /** * Call back for acquisition finished * callback argument is * total frames caught */ - virtual void registerCallBackAcquisitionFinished(void (*func)(uint64_t, void*),void *arg) = 0; + virtual void registerCallBackAcquisitionFinished(void (*func)(int, void*),void *arg) = 0; /** * Call back for raw data @@ -489,7 +489,7 @@ class UDPInterface { * file descriptor * guidatapointer (NULL, no data required) */ - virtual void registerCallBackRawDataReady(void (*func)(uint64_t, char*, uint32_t, FILE*, char*, void*),void *arg) = 0; + virtual void registerCallBackRawDataReady(void (*func)(int, char*, int, FILE*, char*, void*),void *arg) = 0; protected: diff --git a/slsReceiverSoftware/include/UDPStandardImplementation.h b/slsReceiverSoftware/include/UDPStandardImplementation.h index 430b5c5d1..d478f0e7a 100644 --- a/slsReceiverSoftware/include/UDPStandardImplementation.h +++ b/slsReceiverSoftware/include/UDPStandardImplementation.h @@ -136,7 +136,7 @@ class UDPStandardImplementation: private virtual slsReceiverDefs, public UDPBase * @param d detector type * @return OK or FAIL */ - int setDetectorType(const slsReceiverDefs::detectorType d); + int setDetectorType(const detectorType d); //***acquisition functions*** /** @@ -214,11 +214,6 @@ private: //**initial parameters*** - /** - * Delete and free base member parameters - */ - void deleteBaseMembers(); - /** * Delete and free member parameters */ @@ -409,7 +404,7 @@ private: * @param wbuffer writing buffer popped out from FIFO * @param npackets number of packets */ - void handleWithoutDataCompression(int ithread, char* wbuffer[],int npackets); + void handleWithoutDataCompression(int ithread, char* wbuffer[],uint32_t npackets); /** * Calle by handleWithoutDataCompression @@ -417,7 +412,7 @@ private: * @param wbuffer is the address of buffer popped out of FIFO * @param numpackets is the number of packets */ - void writeFileWithoutCompression(char* wbuffer[],int numpackets); + void writeFileWithoutCompression(char* wbuffer[],uint32_t numpackets); /** * Called by writeToFileWithoutCompression @@ -449,7 +444,7 @@ private: * @param wbuffer writer buffer * @param nf number of frames */ - void handleDataCompression(int ithread, char* wbuffer[], int &nf); + void handleDataCompression(int ithread, char* wbuffer[], uint64_t &nf); diff --git a/slsReceiverSoftware/include/slsReceiver.h b/slsReceiverSoftware/include/slsReceiver.h index 94548caed..e76ea7d1b 100644 --- a/slsReceiverSoftware/include/slsReceiver.h +++ b/slsReceiverSoftware/include/slsReceiver.h @@ -62,14 +62,14 @@ class slsReceiver : private virtual slsReceiverDefs { @param func callback to be called when starting the acquisition. Its arguments are filepath filename fileindex data size \returns 0 callback takes care of open,close,write file; 1 callback writes file, we have to open, close it; 2 we open, close, write file, callback does not do anything */ - void registerCallBackStartAcquisition(int (*func)(char*, char*,uint64_t, uint32_t, void*),void *arg); + void registerCallBackStartAcquisition(int (*func)(char*, char*,int, int, void*),void *arg); /** callback argument is toatal farmes caught */ - void registerCallBackAcquisitionFinished(void (*func)(uint64_t, void*),void *arg); + void registerCallBackAcquisitionFinished(void (*func)(int, void*),void *arg); /** args to raw data ready callback are @@ -79,7 +79,7 @@ class slsReceiver : private virtual slsReceiverDefs { file descriptor guidatapointer (NULL, no data required) */ - void registerCallBackRawDataReady(void (*func)(uint64_t, char*, uint32_t, FILE*, char*, void*),void *arg); + void registerCallBackRawDataReady(void (*func)(int, char*, int, FILE*, char*, void*),void *arg); private: diff --git a/slsReceiverSoftware/include/slsReceiverUsers.h b/slsReceiverSoftware/include/slsReceiverUsers.h index 0d242d372..50d6f38fe 100644 --- a/slsReceiverSoftware/include/slsReceiverUsers.h +++ b/slsReceiverSoftware/include/slsReceiverUsers.h @@ -61,7 +61,7 @@ public: */ - void registerCallBackStartAcquisition(int (*func)(char* filepath, char* filename,uint64_t fileindex, uint32_t datasize, void*),void *arg); + void registerCallBackStartAcquisition(int (*func)(char* filepath, char* filename,int fileindex, int datasize, void*),void *arg); /** @@ -71,7 +71,7 @@ public: */ - void registerCallBackAcquisitionFinished(void (*func)(uint64_t nf, void*),void *arg); + void registerCallBackAcquisitionFinished(void (*func)(int nf, void*),void *arg); @@ -81,7 +81,7 @@ public: \returns nothing */ - void registerCallBackRawDataReady(void (*func)(uint64_t framenumber, char* datapointer, uint32_t datasize, FILE* filedescriptor, char* guidatapointer, void*),void *arg); + void registerCallBackRawDataReady(void (*func)(int framenumber, char* datapointer, int datasize, FILE* filedescriptor, char* guidatapointer, void*),void *arg); // made static to close thread files with ctrl+c static slsReceiver* receiver; diff --git a/slsReceiverSoftware/include/sls_receiver_defs.h b/slsReceiverSoftware/include/sls_receiver_defs.h index fe0c715b1..04f647f0a 100755 --- a/slsReceiverSoftware/include/sls_receiver_defs.h +++ b/slsReceiverSoftware/include/sls_receiver_defs.h @@ -122,6 +122,55 @@ public: else return std::string("disabled"); \ }; + /** returns detector type string from detector type index + \param t string can be Mythen, Pilatus, Eiger, Gotthard, Agipd, Unknown + \returns MYTHEN, PILATUS, EIGER, GOTTHARD, AGIPD, MÖNCH, GENERIC + */ + static std::string getDetectorType(detectorType t){ \ + switch (t) { \ + case MYTHEN: return std::string("Mythen"); \ + case PILATUS: return std::string("Pilatus"); \ + case EIGER: return std::string("Eiger"); \ + case GOTTHARD: return std::string("Gotthard"); \ + case AGIPD: return std::string("Agipd"); \ + case MOENCH: return std::string("Moench"); \ + case JUNGFRAU: return std::string("Jungfrau"); \ + case JUNGFRAUCTB: return std::string("JungfrauCTB"); \ + case PROPIX: return std::string("Propix"); \ + default: return std::string("Unknown"); \ + }}; + + /** returns detector type index from detector type string + \param type can be MYTHEN, PILATUS, EIGER, GOTTHARD, AGIPD, GENERIC + \returns Mythen, Pilatus, Eiger, Gotthard, Agipd, Mönch, Unknown + */ + static detectorType getDetectorType(std::string const type){\ + if (type=="Mythen") return MYTHEN; \ + if (type=="Pilatus") return PILATUS; \ + if (type=="Eiger") return EIGER; \ + if (type=="Gotthard") return GOTTHARD; \ + if (type=="Agipd") return AGIPD; \ + if (type=="Moench") return MOENCH; \ + if (type=="Jungfrau") return JUNGFRAU; \ + if (type=="JungfrauCTB") return JUNGFRAUCTB; \ + if (type=="Propix") return PROPIX; \ + return GENERIC; \ + }; + + + /** returns string from run status index + \param s can be ERROR, WAITING, RUNNING, TRANSMITTING, RUN_FINISHED + \returns string error, waiting, running, data, finished + */ + static std::string runStatusType(runStatus s){\ + switch (s) { \ + case ERROR: return std::string("error"); \ + case WAITING: return std::string("waiting"); \ + case RUNNING: return std::string("running"); \ + case TRANSMITTING: return std::string("data"); \ + case RUN_FINISHED: return std::string("finished"); \ + default: return std::string("idle"); \ + }}; #ifdef __cplusplus diff --git a/slsReceiverSoftware/src/UDPBaseImplementation.cpp b/slsReceiverSoftware/src/UDPBaseImplementation.cpp index 18e43edb5..0bfef5d71 100644 --- a/slsReceiverSoftware/src/UDPBaseImplementation.cpp +++ b/slsReceiverSoftware/src/UDPBaseImplementation.cpp @@ -21,6 +21,20 @@ using namespace std; UDPBaseImplementation::UDPBaseImplementation(){ FILE_LOG(logDEBUG) << __AT__ << " starting"; + initializeMembers(); + + //***callback parameters*** + startAcquisitionCallBack = NULL; + pStartAcquisition = NULL; + acquisitionFinishedCallBack = NULL; + pAcquisitionFinished = NULL; + rawDataReadyCallBack = NULL; + pRawDataReady = NULL; +} + +void UDPBaseImplementation::initializeMembers(){ + FILE_LOG(logDEBUG) << __AT__ << " starting"; + cout << "Info: Initializing base members" << endl; //**detector parameters*** myDetectorType = GENERIC; @@ -61,21 +75,9 @@ UDPBaseImplementation::UDPBaseImplementation(){ //***acquisition parameters*** shortFrameEnable = -1; FrameToGuiFrequency = 0; - - //***callback parameters*** - startAcquisitionCallBack = NULL; - pStartAcquisition = NULL; - acquisitionFinishedCallBack = NULL; - pAcquisitionFinished = NULL; - rawDataReadyCallBack = NULL; - pRawDataReady = NULL; } -UDPBaseImplementation::~UDPBaseImplementation(){ - FILE_LOG(logDEBUG) << __AT__ << " starting"; - - cout << "Info: Deleting base member pointers" << endl; -} +UDPBaseImplementation::~UDPBaseImplementation(){} /************************************************************************* @@ -364,12 +366,12 @@ int UDPBaseImplementation::setTenGigaEnable(const bool b){ /***initial functions***/ -int UDPBaseImplementation::setDetectorType(const slsReceiverDefs::detectorType d){ +int UDPBaseImplementation::setDetectorType(const detectorType d){ FILE_LOG(logDEBUG) << __AT__ << " starting"; myDetectorType = d; //if eiger, set numberofListeningThreads = 2; - FILE_LOG(logINFO) << "Detector Type:" << slsDetectorBase::getDetectorType(d); + FILE_LOG(logINFO) << "Detector Type:" << getDetectorType(d); return OK; } @@ -409,6 +411,9 @@ void UDPBaseImplementation::startReadout(){ int UDPBaseImplementation::shutDownUDPSockets(){ FILE_LOG(logWARNING) << __AT__ << " doing nothing..."; FILE_LOG(logERROR) << __AT__ << " must be overridden by child classes"; + + //overridden functions might return FAIL + return OK; } void UDPBaseImplementation::readFrame(char* c,char** raw, uint64_t &startAcquisitionIndex, uint64_t &startFrameIndex){ @@ -429,17 +434,17 @@ void UDPBaseImplementation::closeFile(int i){ /***callback functions***/ -void UDPBaseImplementation::registerCallBackStartAcquisition(int (*func)(char*, char*,uint64_t, uint32_t, void*),void *arg){ +void UDPBaseImplementation::registerCallBackStartAcquisition(int (*func)(char*, char*,int, int, void*),void *arg){ startAcquisitionCallBack=func; pStartAcquisition=arg; } -void UDPBaseImplementation::registerCallBackAcquisitionFinished(void (*func)(uint64_t, void*),void *arg){ +void UDPBaseImplementation::registerCallBackAcquisitionFinished(void (*func)(int, void*),void *arg){ acquisitionFinishedCallBack=func; pAcquisitionFinished=arg; } -void UDPBaseImplementation::registerCallBackRawDataReady(void (*func)(uint64_t, char*, uint32_t, FILE*, char*, void*),void *arg){ +void UDPBaseImplementation::registerCallBackRawDataReady(void (*func)(int, char*, int, FILE*, char*, void*),void *arg){ rawDataReadyCallBack=func; pRawDataReady=arg; } diff --git a/slsReceiverSoftware/src/UDPStandardImplementation.cpp b/slsReceiverSoftware/src/UDPStandardImplementation.cpp index b15a48cc4..e144585be 100644 --- a/slsReceiverSoftware/src/UDPStandardImplementation.cpp +++ b/slsReceiverSoftware/src/UDPStandardImplementation.cpp @@ -69,11 +69,6 @@ UDPStandardImplementation::~UDPStandardImplementation(){ *************************************************************************/ /***initial parameters***/ -void UDPStandardImplementation::deleteBaseMembers(){ - FILE_LOG(logDEBUG1) << __AT__ << " starting"; - - UDPBaseImplementation::~UDPBaseImplementation(); -} void UDPStandardImplementation::deleteMembers(){ FILE_LOG(logDEBUG1) << __AT__ << " starting"; @@ -116,7 +111,7 @@ void UDPStandardImplementation::deleteFilter(){ void UDPStandardImplementation::initializeBaseMembers(){ FILE_LOG(logDEBUG1) << __AT__ << " starting"; - UDPBaseImplementation::UDPBaseImplementation(); + UDPBaseImplementation::initializeMembers(); acquisitionPeriod = SAMPLE_TIME_IN_NS; } @@ -216,6 +211,7 @@ void UDPStandardImplementation::initializeFilter(){ int sign = 1, csize, i; //common mode initialization + moenchCommonModeSubtraction = NULL; if (commonModeSubtractionEnable){ if(myDetectorType == MOENCH) moenchCommonModeSubtraction=new moenchCommonMode(); @@ -244,7 +240,7 @@ void UDPStandardImplementation::initializeFilter(){ //single photon detector initialization for(i=0; i(receiverData[i], csize, sigma, sign, commonModeSubtractionEnable); + singlePhotonDetectorObject[i]=new singlePhotonDetector(receiverData[i], csize, sigma, sign, moenchCommonModeSubtraction); } @@ -255,7 +251,7 @@ int UDPStandardImplementation::setupFifoStructure(){ int64_t i; int oldNumberofJobsPerBuffer = numberofJobsPerBuffer; - int oldFifoSize = fifoSize; + uint32_t oldFifoSize = fifoSize; //eiger always listens to 1 packet at a time if(myDetectorType == EIGER){ @@ -349,6 +345,7 @@ int UDPStandardImplementation::setupFifoStructure(){ } } cout << "Info: Fifo structure(s) reconstructed" << endl; + return OK; } @@ -458,11 +455,9 @@ void UDPStandardImplementation::setShortFrameEnable(const int i){ int UDPStandardImplementation::setFrameToGuiFrequency(const uint32_t i){ FILE_LOG(logDEBUG1) << __AT__ << " called"; - if(i >= 0){ - FrameToGuiFrequency = i; - if(setupFifoStructure() == FAIL) - return FAIL; - } + FrameToGuiFrequency = i; + if(setupFifoStructure() == FAIL) + return FAIL; cout << "Info: Frame to Gui Frequency set to " << FrameToGuiFrequency << endl; @@ -470,14 +465,12 @@ int UDPStandardImplementation::setFrameToGuiFrequency(const uint32_t i){ } -int UDPStandardImplementation::setAcquisitionPeriod(int64_t i){ +int UDPStandardImplementation::setAcquisitionPeriod(const uint64_t i){ FILE_LOG(logDEBUG1) << __AT__ << " called"; - if(i >= 0){ - acquisitionPeriod = i; - if(setupFifoStructure() == FAIL) - return FAIL; - } + acquisitionPeriod = i; + if(setupFifoStructure() == FAIL) + return FAIL; cout << "Info: Acquisition Period set to " << acquisitionPeriod << endl; @@ -488,7 +481,7 @@ int UDPStandardImplementation::setAcquisitionPeriod(int64_t i){ int UDPStandardImplementation::setDynamicRange(const uint32_t i){ FILE_LOG(logDEBUG1) << __AT__ << " called"; - int oldDynamicRange = dynamicRange; + uint32_t oldDynamicRange = dynamicRange; cout << "Info: Setting Dynamic Range to " << i << endl; dynamicRange = i; @@ -542,7 +535,7 @@ int UDPStandardImplementation::setDynamicRange(const uint32_t i){ int UDPStandardImplementation::setTenGigaEnable(const bool b){ FILE_LOG(logDEBUG1) << __AT__ << " called"; - cout << "Info: Setting Ten Giga to " << string(b) << endl; + cout << "Info: Setting Ten Giga to " << stringEnable(b) << endl; bool oldTenGigaEnable = tengigaEnable; tengigaEnable = b; @@ -603,7 +596,7 @@ int UDPStandardImplementation::setTenGigaEnable(const bool b){ } - cout << "Info: Ten Giga " << string(tengigaEnable) << endl; + cout << "Info: Ten Giga " << stringEnable(tengigaEnable) << endl; return OK; } @@ -621,12 +614,11 @@ int UDPStandardImplementation::setTenGigaEnable(const bool b){ /***initial functions***/ -int UDPStandardImplementation::setDetectorType(const slsReceiverDefs::detectorType d){ +int UDPStandardImplementation::setDetectorType(const detectorType d){ FILE_LOG(logDEBUG1) << __AT__ << " called"; cout << "Setting receiver type ..." << endl; - deleteBaseMembers(); deleteMembers(); initializeBaseMembers(); initializeMembers(); @@ -639,7 +631,7 @@ int UDPStandardImplementation::setDetectorType(const slsReceiverDefs::detectorTy case EIGER: case JUNGFRAUCTB: case JUNGFRAU: - cout << "Info: ***** This is a " << slsDetectorBase::getDetectorType(d) << " Receiver *****" << endl; + cout << "Info: ***** This is a " << getDetectorType(d) << " Receiver *****" << endl; break; default: cprintf(BG_RED, "Error: This is an unknown receiver type %d\n", (int)d); @@ -715,6 +707,9 @@ int UDPStandardImplementation::setDetectorType(const slsReceiverDefs::detectorTy fifoSize = JCTB_FIFO_SIZE; //footerOffset = Not applicable; break; + default: + cprintf(BG_RED, "Error: This is an unknown receiver type %d\n", (int)d); + return FAIL; } //delete threads and set number of listening threads @@ -745,7 +740,7 @@ int UDPStandardImplementation::setDetectorType(const slsReceiverDefs::detectorTy //allocate for latest data (frame copy for gui) latestData = new char[frameSize]; - cout << " Detector type set to " << slsDetectorBase::getDetectorType(d) << endl; + cout << " Detector type set to " << getDetectorType(d) << endl; cout << "Ready..." << endl; return OK; @@ -837,7 +832,7 @@ int UDPStandardImplementation::startReceiver(char *c){ //For compression, just for gui purposes if(dataCompressionEnable) - sprintf(completeFileName, "%s/%s_fxxx_%d_xx.root", filePath,fileName,fileIndex); + sprintf(completeFileName, "%s/%s_fxxx_%lld_xx.root", filePath,fileName,(long long int)fileIndex); //initialize semaphore to synchronize between writer and gui reader threads sem_init(&writerGuiSemaphore,1,0); @@ -856,7 +851,7 @@ int UDPStandardImplementation::startReceiver(char *c){ //usleep(5000000); cout << "Info: Receiver Started." << endl; - cout << "Info: Status:" << slsDetectorBase::runStatusType(status) << endl; + cout << "Info: Status:" << runStatusType(status) << endl; return OK; } @@ -889,7 +884,7 @@ void UDPStandardImplementation::stopReceiver(){ pthread_mutex_unlock(&(statusMutex)); cout << "Info: Receiver Stopped" << endl; - cout << "Info: Status:" << slsDetectorBase::runStatusType(status) << endl; + cout << "Info: Status:" << runStatusType(status) << endl; cout << endl; } @@ -1210,8 +1205,10 @@ int UDPStandardImplementation::createUDPSockets(){ FILE_LOG(logDEBUG1) << __AT__ << " called"; //switching ports if bottom enabled - int port[2]; - port = udpPortNum; + uint32_t port[2]; + port[0]= udpPortNum[0]; + port[1]= udpPortNum[1]; + //port = udpPortNum; if(bottomEnable){ port[0] = udpPortNum[1]; port[1] = udpPortNum[0]; @@ -1266,7 +1263,7 @@ int UDPStandardImplementation::setupWriter(){ //acquisition start call back returns enable write cbAction = DO_EVERYTHING; if (startAcquisitionCallBack) - cbAction=startAcquisitionCallBack(filePath,fileName,fileIndex,bufferSize,pStartAcquisition); + cbAction=startAcquisitionCallBack(filePath,fileName,(int)fileIndex,bufferSize,pStartAcquisition); if(cbAction < DO_EVERYTHING){ cout << "Info: Call back activated. Data saving must be taken care of by user in call back." << endl; @@ -1318,11 +1315,11 @@ int UDPStandardImplementation::createNewFile(){ //create file name if(!frameIndexEnable) - sprintf(completeFileName, "%s/%s_%d.raw", filePath,fileName,fileIndex); + sprintf(completeFileName, "%s/%s_%lld.raw", filePath,fileName,(long long int)fileIndex); else if (myDetectorType == EIGER) - sprintf(completeFileName, "%s/%s_f%012d_%d.raw", filePath,fileName,currentFrameNumber,fileIndex); + sprintf(completeFileName, "%s/%s_f%012lld_%lld.raw", filePath,fileName,(long long int)currentFrameNumber,(long long int)fileIndex); else - sprintf(completeFileName, "%s/%s_f%012d_%d.raw", filePath,fileName,(packetsCaught/packetsPerFrame),fileIndex); + sprintf(completeFileName, "%s/%s_f%012lld_%lld.raw", filePath,fileName,(long long int)(packetsCaught/packetsPerFrame),(long long int)fileIndex); #ifdef DEBUG4 cout << "Info: " << completefileName << endl; @@ -1534,7 +1531,7 @@ int UDPStandardImplementation::prepareAndListenBuffer(int ithread, int lSize, in //throw away packets that is not one packet size, need to check status if socket is shut down while(status != TRANSMITTING && myDetectorType == EIGER && receivedSize != onePacketSize) { if(receivedSize != EIGER_HEADER_LENGTH) - cprintf(RED,"Listening_Thread %d: Listened to a weird packet size %d\n",receivedSize); + cprintf(RED,"Listening_Thread %d: Listened to a weird packet size %d\n",ithread, receivedSize); #ifdef DEBUG else cprintf(BLUE,"Listening_Thread %d: Listened to a header packet\n",ithread); @@ -1576,11 +1573,11 @@ void UDPStandardImplementation::startFrameIndices(int ithread){ if(!acqStarted){ startAcquisitionIndex = startFrameIndex; acqStarted = true; - cprintf(BLUE,"Info: Thread %d: startAcquisitionIndex:%d\n",ithread,startAcquisitionIndex); + cprintf(BLUE,"Info: Thread %d: startAcquisitionIndex:%lld\n",ithread,(long long int)startAcquisitionIndex); } //set start of scan/real time measurement - cprintf(BLUE,"Info: Thread %d: startFrameIndex: %d\n", ithread,startFrameIndex); + cprintf(BLUE,"Info: Thread %d: startFrameIndex: %lld\n", ithread,(long long int)startFrameIndex); measurementStarted = true; } @@ -1593,7 +1590,7 @@ void UDPStandardImplementation::startFrameIndices(int ithread){ void UDPStandardImplementation::stopListening(int ithread, int numbytes){ FILE_LOG(logDEBUG1) << __AT__ << " called"; - cout << "Info: Stop Listening. Status:" << slsDetectorBase::runStatusType(status) << endl; + cout << "Info: Stop Listening. Status:" << runStatusType(status) << endl; //less than 1 packet size (especially for eiger), ignore the buffer (so that 2 dummy buffers are not sent with pc=0) @@ -1672,7 +1669,7 @@ uint32_t UDPStandardImplementation::processListeningBuffer(int ithread, int cSiz FILE_LOG(logDEBUG1) << __AT__ << " called"; int lastPacketOffset; //the offset of the last packet - int lastFrameHeader; //frame number of last packet in buffer + uint32_t lastFrameHeader; //frame number of last packet in buffer uint32_t packetCount = (packetsPerFrame/numberofListeningThreads) * numberofJobsPerBuffer; //packets received cSize = 0; //reset size @@ -1735,8 +1732,8 @@ uint32_t UDPStandardImplementation::processListeningBuffer(int ithread, int cSiz break; default: - cprintf(RED,"Listening_Thread %d: Error: This detector is not implemented in the receiver" + - slsDetectorBase::getDetectorType(myDetectorType).c_str() + "\n"); + cprintf(RED,"Listening_Thread %d: Error: This detector %s is not implemented in the receiver\n", + ithread, getDetectorType(myDetectorType).c_str()); break; } @@ -1779,7 +1776,7 @@ void UDPStandardImplementation::processWritingBuffer(int ithread){ //variable definitions char* wbuf[numberofListeningThreads]; //buffer popped from FIFO sfilefd = NULL; //file pointer - int nf; //for compression, number of frames + uint64_t nf; //for compression, number of frames /* outer loop - loops once for each acquisition */ @@ -1799,7 +1796,7 @@ void UDPStandardImplementation::processWritingBuffer(int ithread){ #ifdef FIFODEBUG cprintf(GREEN,"Writing_Thread %d: Popped %p from FIFO %d\n", ithread, (void*)(wbuf[0]),0); #endif - int numPackets = (uint32_t)(*((uint32_t*)wbuf[0])); + uint32_t numPackets = (uint32_t)(*((uint32_t*)wbuf[0])); if(numPackets < 0) cprintf(BG_RED,"Error: Negative packet numbers: %d for FIFO %d\n",numPackets,0); #ifdef DEBUG4 @@ -1896,7 +1893,7 @@ void UDPStandardImplementation::processWritingBufferPacketByPacket(int ithread){ //blank frame - initializing with missing packet values blankoffset = 0; unsigned char* blankframe_data=0; - for(int i=0; ipacketNumber) != (i+1)){ - cprintf(BG_RED, "Packet Number Mismatch! i:%d pnum:%d fnum:%d missingPacket:%d\n", - i,*( (uint16_t*) wbuf_footer->packetNumber),currentFrameNumber,*( (uint16_t*) wbuf_header->missingPacket)); + cprintf(BG_RED, "Writing_Thread: Packet Number Mismatch! " + "i %d, pnum %d, fnum %lld, missingPacket 0x%x\n", + i,*( (uint16_t*) wbuf_footer->packetNumber),(long long int)currentFrameNumber,*( (uint16_t*) wbuf_header->missingPacket)); exit(-1); } //overwriting port number and dynamic range @@ -2526,7 +2521,6 @@ void UDPStandardImplementation::createHeaders(char* wbuffer[]){ void UDPStandardImplementation::copyFrameToGui(char* buffer[]){ FILE_LOG(logDEBUG1) << __AT__ << " called"; - int i; //random read (gui not ready) //need to toggle guiDataReady or the second frame wont be copied @@ -2551,7 +2545,7 @@ void UDPStandardImplementation::copyFrameToGui(char* buffer[]){ #endif switch(myDetectorType){ case EIGER: - for(int i=0; ifindNextFrame(data,ndata,remainingsize)){ diff --git a/slsReceiverSoftware/src/slsReceiver.cpp b/slsReceiverSoftware/src/slsReceiver.cpp index 15149dde0..5783e601c 100644 --- a/slsReceiverSoftware/src/slsReceiver.cpp +++ b/slsReceiverSoftware/src/slsReceiver.cpp @@ -166,20 +166,20 @@ int64_t slsReceiver::getReceiverVersion(){ } -void slsReceiver::registerCallBackStartAcquisition(int (*func)(char*, char*,uint64_t, uint32_t, void*),void *arg){ +void slsReceiver::registerCallBackStartAcquisition(int (*func)(char*, char*,int, int, void*),void *arg){ //tcpipInterface udp_interface->registerCallBackStartAcquisition(func,arg); } -void slsReceiver::registerCallBackAcquisitionFinished(void (*func)(uint64_t, void*),void *arg){ +void slsReceiver::registerCallBackAcquisitionFinished(void (*func)(int, void*),void *arg){ //tcpipInterface udp_interface->registerCallBackAcquisitionFinished(func,arg); } -void slsReceiver::registerCallBackRawDataReady(void (*func)(uint64_t, char*, uint32_t, FILE*, char*, void*),void *arg){ +void slsReceiver::registerCallBackRawDataReady(void (*func)(int, char*, int, FILE*, char*, void*),void *arg){ //tcpipInterface udp_interface->registerCallBackRawDataReady(func,arg); } diff --git a/slsReceiverSoftware/src/slsReceiverTCPIPInterface.cpp b/slsReceiverSoftware/src/slsReceiverTCPIPInterface.cpp index 5b4664e55..f94b47a01 100644 --- a/slsReceiverSoftware/src/slsReceiverTCPIPInterface.cpp +++ b/slsReceiverSoftware/src/slsReceiverTCPIPInterface.cpp @@ -185,7 +185,7 @@ void slsReceiverTCPIPInterface::startTCPServer(){ #ifdef VERYVERBOSE cout << "Starting Receiver TCP Server" << endl; #endif - int v=slsReceiverDefs::OK; + int v=OK; while(1) { #ifdef VERBOSE @@ -832,7 +832,7 @@ int slsReceiverTCPIPInterface::start_receiver(){ if(s == IDLE) ret=receiverBase->startReceiver(mess); else{ - sprintf(mess,"Cannot start Receiver as it is in %s state\n",slsDetectorBase::runStatusType(s).c_str()); + sprintf(mess,"Cannot start Receiver as it is in %s state\n",runStatusType(s).c_str()); ret=FAIL; } } @@ -878,7 +878,7 @@ int slsReceiverTCPIPInterface::stop_receiver(){ if(s==IDLE) ret = OK; else{ - sprintf(mess,"Could not stop receiver. It is in %s state\n",slsDetectorBase::runStatusType(s).c_str()); + sprintf(mess,"Could not stop receiver. It is in %s state\n",runStatusType(s).c_str()); ret = FAIL; } } @@ -1138,8 +1138,8 @@ int slsReceiverTCPIPInterface::moench_read_frame(){ char* raw = new char[bufferSize]; - uint32_t startAcquisitionIndex=0; - uint32_t startFrameIndex=0; + uint64_t startAcquisitionIndex=0; + uint64_t startFrameIndex=0; uint32_t index = -1,bindex = 0, offset=0; strcpy(mess,"Could not read frame\n"); @@ -1327,8 +1327,8 @@ int slsReceiverTCPIPInterface::gotthard_read_frame(){ uint32_t index=-1,index2=0; uint32_t pindex=0,pindex2=0; uint32_t bindex=0,bindex2=0; - uint32_t startAcquisitionIndex=0; - uint32_t startFrameIndex=0; + uint64_t startAcquisitionIndex=0; + uint64_t startFrameIndex=0; strcpy(mess,"Could not read frame\n"); @@ -1502,8 +1502,8 @@ int slsReceiverTCPIPInterface::propix_read_frame(){ uint32_t index=-1,index2=0; uint32_t pindex=0,pindex2=0; uint32_t bindex=0,bindex2=0; - uint32_t startAcquisitionIndex=0; - uint32_t startFrameIndex=0; + uint64_t startAcquisitionIndex=0; + uint64_t startFrameIndex=0; strcpy(mess,"Could not read frame\n"); @@ -1670,8 +1670,8 @@ int slsReceiverTCPIPInterface::eiger_read_frame(){ char* raw = new char[frameSize]; char* origVal = new char[frameSize]; char* retval = new char[dataSize]; - uint32_t startAcquisitionIndex=0; - uint32_t startFrameIndex=0; + uint64_t startAcquisitionIndex=0; + uint64_t startFrameIndex=0; strcpy(mess,"Could not read frame\n"); @@ -2111,11 +2111,11 @@ int slsReceiverTCPIPInterface::set_timer() { ret=FAIL; } else{ - if(index[0] == slsReceiverDefs::FRAME_PERIOD){ + if(index[0] == FRAME_PERIOD){ if(index[1]>=0){ ret = receiverBase->setAcquisitionPeriod(index[1]); if(ret == FAIL) - strcpy(mess,"Could not allocate memory for listening fifo\n") + strcpy(mess,"Could not allocate memory for listening fifo\n"); } retval=receiverBase->getAcquisitionPeriod(); }else{ @@ -2129,7 +2129,7 @@ int slsReceiverTCPIPInterface::set_timer() { } #ifdef VERBOSE if(ret!=FAIL){ - if(index[0] == slsReceiverDefs::FRAME_PERIOD) + if(index[0] == FRAME_PERIOD) cout << "acquisition period:" << retval << endl; else cout << "frame number:" << retval << endl; diff --git a/slsReceiverSoftware/src/slsReceiverUsers.cpp b/slsReceiverSoftware/src/slsReceiverUsers.cpp index 1df35558c..c27f1efc2 100644 --- a/slsReceiverSoftware/src/slsReceiverUsers.cpp +++ b/slsReceiverSoftware/src/slsReceiverUsers.cpp @@ -29,18 +29,18 @@ int64_t slsReceiverUsers::getReceiverVersion(){ } -void slsReceiverUsers::registerCallBackStartAcquisition(int (*func)(char*, char*,uint64_t, uint32_t, void*),void *arg){ +void slsReceiverUsers::registerCallBackStartAcquisition(int (*func)(char*, char*,int, int, void*),void *arg){ slsReceiverUsers::receiver->registerCallBackStartAcquisition(func,arg); } -void slsReceiverUsers::registerCallBackAcquisitionFinished(void (*func)(uint64_t, void*),void *arg){ +void slsReceiverUsers::registerCallBackAcquisitionFinished(void (*func)(int, void*),void *arg){ slsReceiverUsers::receiver->registerCallBackAcquisitionFinished(func,arg); } -void slsReceiverUsers::registerCallBackRawDataReady(void (*func)(uint64_t, char*, uint32_t, FILE*, char*, void*),void *arg){ +void slsReceiverUsers::registerCallBackRawDataReady(void (*func)(int, char*, int, FILE*, char*, void*),void *arg){ slsReceiverUsers::receiver->registerCallBackRawDataReady(func,arg); } From db54fbddde14443b4b64ef321bfb57a5e23c8ae6 Mon Sep 17 00:00:00 2001 From: Anna Bergamaschi Date: Thu, 29 Oct 2015 11:20:08 +0100 Subject: [PATCH 45/68] detector type bug fix --- .../src/slsReceiverTCPIPInterface.cpp | 21 ++++++++++--------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/slsReceiverSoftware/src/slsReceiverTCPIPInterface.cpp b/slsReceiverSoftware/src/slsReceiverTCPIPInterface.cpp index f94b47a01..be3242cd9 100644 --- a/slsReceiverSoftware/src/slsReceiverTCPIPInterface.cpp +++ b/slsReceiverSoftware/src/slsReceiverTCPIPInterface.cpp @@ -391,21 +391,22 @@ int slsReceiverTCPIPInterface::set_detector_type(){ sprintf(mess,"Unknown detector type: %d\n", dr); ret = FAIL; break; - if(ret != FAIL){ -#ifndef REST - receiverBase = UDPInterface::create("standard"); - receiverBase->setBottomEnable(bottom); -#endif - myDetectorType = dr; - ret=receiverBase->setDetectorType(myDetectorType); - retval = myDetectorType; - } } + if(ret != FAIL){ +#ifndef REST + receiverBase = UDPInterface::create("standard"); + receiverBase->setBottomEnable(bottom); +#endif + myDetectorType = dr; + ret=receiverBase->setDetectorType(myDetectorType); + retval = myDetectorType; + } + } } //#ifdef VERBOSE if(ret!=FAIL) - cout << "detector type" << dr << endl; + cout << "detector type " << dr << endl; else cprintf(RED, "%s\n", mess); //#endif From eb5f481faaf2b90891c45532a9b5f3a7093e49c9 Mon Sep 17 00:00:00 2001 From: Anna Bergamaschi Date: Thu, 29 Oct 2015 11:21:57 +0100 Subject: [PATCH 46/68] detector type bug fix --- slsReceiverSoftware/src/UDPStandardImplementation.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/slsReceiverSoftware/src/UDPStandardImplementation.cpp b/slsReceiverSoftware/src/UDPStandardImplementation.cpp index e144585be..fd4ab0c0c 100644 --- a/slsReceiverSoftware/src/UDPStandardImplementation.cpp +++ b/slsReceiverSoftware/src/UDPStandardImplementation.cpp @@ -1797,8 +1797,10 @@ void UDPStandardImplementation::processWritingBuffer(int ithread){ cprintf(GREEN,"Writing_Thread %d: Popped %p from FIFO %d\n", ithread, (void*)(wbuf[0]),0); #endif uint32_t numPackets = (uint32_t)(*((uint32_t*)wbuf[0])); - if(numPackets < 0) - cprintf(BG_RED,"Error: Negative packet numbers: %d for FIFO %d\n",numPackets,0); + cout<<"numpackets:"< Date: Thu, 29 Oct 2015 13:33:24 +0100 Subject: [PATCH 47/68] log --- .../src/UDPBaseImplementation.cpp | 10 +-- .../src/UDPStandardImplementation.cpp | 79 +++++++++---------- slsReceiverSoftware/src/main.cpp | 2 +- .../src/slsReceiverTCPIPInterface.cpp | 4 +- 4 files changed, 46 insertions(+), 49 deletions(-) diff --git a/slsReceiverSoftware/src/UDPBaseImplementation.cpp b/slsReceiverSoftware/src/UDPBaseImplementation.cpp index 0bfef5d71..94a39d07d 100644 --- a/slsReceiverSoftware/src/UDPBaseImplementation.cpp +++ b/slsReceiverSoftware/src/UDPBaseImplementation.cpp @@ -35,7 +35,7 @@ UDPBaseImplementation::UDPBaseImplementation(){ void UDPBaseImplementation::initializeMembers(){ FILE_LOG(logDEBUG) << __AT__ << " starting"; - cout << "Info: Initializing base members" << endl; + FILE_LOG(logDEBUG1) << "Info: Initializing base members" << endl; //**detector parameters*** myDetectorType = GENERIC; strcpy(detHostname,""); @@ -202,7 +202,7 @@ void UDPBaseImplementation::setBottomEnable(const bool b){ FILE_LOG(logDEBUG) << __AT__ << " starting"; bottomEnable = b; - FILE_LOG(logINFO) << "Bottom Enable: " << stringEnable(bottomEnable); + FILE_LOG(logINFO) << "Bottom - " << stringEnable(bottomEnable) << endl; } @@ -216,7 +216,7 @@ void UDPBaseImplementation::setFileName(const char c[]){ } void UDPBaseImplementation::setFilePath(const char c[]){ - FILE_LOG(logDEBUG) << __AT__ << " starting"; + FILE_LOG(logINFO) << __AT__ << " starting"; if(strlen(c)){ //check if filepath exists @@ -229,7 +229,7 @@ void UDPBaseImplementation::setFilePath(const char c[]){ } strcpy(filePath, c); } - FILE_LOG(logINFO) << "File path:" << filePath; + FILE_LOG(logDEBUG1) << "Info: File path:" << filePath; } void UDPBaseImplementation::setFileIndex(const uint64_t i){ @@ -273,7 +273,7 @@ int UDPBaseImplementation::setDataCompressionEnable(const bool b){ FILE_LOG(logDEBUG) << __AT__ << " starting"; dataCompressionEnable = b; - FILE_LOG(logINFO) << "Data Compression Enable: " << stringEnable(dataCompressionEnable); + FILE_LOG(logINFO) << "Data Compression : " << stringEnable(dataCompressionEnable); //overridden methods might return FAIL return OK; diff --git a/slsReceiverSoftware/src/UDPStandardImplementation.cpp b/slsReceiverSoftware/src/UDPStandardImplementation.cpp index fd4ab0c0c..bfe8c9eb7 100644 --- a/slsReceiverSoftware/src/UDPStandardImplementation.cpp +++ b/slsReceiverSoftware/src/UDPStandardImplementation.cpp @@ -42,10 +42,10 @@ UDPStandardImplementation::UDPStandardImplementation(){ pthread_mutex_init(&progressMutex,NULL); //to increase socket receiver buffer size and max length of input queue by changing kernel settings - if(system("echo $((100*1024*1024)) > /proc/sys/net/core/rmem_max")) - cout << "Warning: No root permission to change socket receiver buffer size in file /proc/sys/net/core/rmem_max" << endl; + if(system("echo $((100*1024*1024)) > /proc/sys/net/core/rmem_max")) + FILE_LOG(logDEBUG1) << "Warning: No root permission to change socket receiver buffer size in file /proc/sys/net/core/rmem_max" << endl; else if(system("echo 250000 > /proc/sys/net/core/netdev_max_backlog")) - cout << "Warning: No root permission to change max length of input queue in file /proc/sys/net/core/netdev_max_backlog" << endl; + FILE_LOG(logDEBUG1) << "Warning: No root permission to change max length of input queue in file /proc/sys/net/core/netdev_max_backlog" << endl; /** permanent setting by heiner net.core.rmem_max = 104857600 # 100MiB net.core.netdev_max_backlog = 250000 @@ -54,6 +54,7 @@ UDPStandardImplementation::UDPStandardImplementation(){ sysctl -w net.core.rmem_max=16777216 sysctl -w net.core.netdev_max_backlog=250000 */ + cout << endl; } UDPStandardImplementation::~UDPStandardImplementation(){ @@ -73,7 +74,7 @@ UDPStandardImplementation::~UDPStandardImplementation(){ void UDPStandardImplementation::deleteMembers(){ FILE_LOG(logDEBUG1) << __AT__ << " starting"; - cout << "Info: Deleting member pointers" << endl; + FILE_LOG(logDEBUG1) << "Info: Deleting member pointers" << endl; shutDownUDPSockets(); closeFile(); //filter @@ -119,7 +120,7 @@ void UDPStandardImplementation::initializeBaseMembers(){ void UDPStandardImplementation::initializeMembers(){ FILE_LOG(logDEBUG1) << __AT__ << " starting"; - cout << "Info: Initializing members" << endl; + FILE_LOG(logDEBUG1) << "Info: Initializing members" << endl; //***detector parameters*** frameSize = 0; @@ -256,7 +257,7 @@ int UDPStandardImplementation::setupFifoStructure(){ //eiger always listens to 1 packet at a time if(myDetectorType == EIGER){ numberofJobsPerBuffer = 1; - cout << "Info: 1 packet per buffer" << endl; + FILE_LOG(logDEBUG1) << "Info: 1 packet per buffer" << endl; } //else calculate best possible number of frames to listen to at a time (for fast readouts like gotthard) @@ -298,9 +299,8 @@ int UDPStandardImplementation::setupFifoStructure(){ else fifoSize = fifoSize/numberofJobsPerBuffer; } -#ifdef VERBOSE - cout << "Info: Fifo Depth:" << fifoSize << endl; -#endif + FILE_LOG(logDEBUG1) << "Info: Fifo Depth:" << fifoSize << endl; + //do not rebuild fifo structure if it is the same @@ -315,8 +315,8 @@ int UDPStandardImplementation::setupFifoStructure(){ if(fifoFree[i]){ while(!fifoFree[i]->isEmpty()) fifoFree[i]->pop(buffer[i]); -#ifdef FIFO_DEBUG - cprintf(GREEN,"%d fifostructure popped from fifofree %p\n", i, (void*)(buffer[i])); +#ifdef FIFODEBUG + cprintf(GREEN,"Info: %d fifostructure popped from fifofree %p\n", i, (void*)(buffer[i])); #endif delete fifoFree[i]; } @@ -338,13 +338,13 @@ int UDPStandardImplementation::setupFifoStructure(){ buffer[i]=mem0[i]; while (buffer[i] < (mem0[i]+(bufferSize * numberofJobsPerBuffer + HEADER_SIZE_NUM_TOT_PACKETS) * (fifoSize-1))) { fifoFree[i]->push(buffer[i]); -#ifdef FIFO_DEBUG - cprintf(BLUE,"%d fifostructure free pushed into fifofree %p\n", i, (void*)(buffer[i])); +#ifdef FIFODEBUG + cprintf(BLUE,"Info: %d fifostructure free pushed into fifofree %p\n", i, (void*)(buffer[i])); #endif buffer[i] += (bufferSize * numberofJobsPerBuffer + HEADER_SIZE_NUM_TOT_PACKETS); } } - cout << "Info: Fifo structure(s) reconstructed" << endl; + FILE_LOG(logDEBUG1) << "Info: Fifo structure(s) reconstructed" << endl; return OK; } @@ -366,7 +366,7 @@ void UDPStandardImplementation::configure(map config_map){ b = 0; } bottomEnable = b!= 0; - cout << "Info: Bottom Enable: " << stringEnable(bottomEnable) << endl; + cout << "Info: Bottom - " << stringEnable(bottomEnable) << endl; } } @@ -376,12 +376,14 @@ void UDPStandardImplementation::configure(map config_map){ int UDPStandardImplementation::setDataCompressionEnable(const bool b){ FILE_LOG(logDEBUG1) << __AT__ << " starting"; - cout << "Info: Setting up Data Compression Enable to " << stringEnable(b); + if(myDetectorType != EIGER){ + cout << "Info: Setting up Data Compression Enable to " << stringEnable(b); #ifdef MYROOT1 - cout << " WITH ROOT" << endl; + cout << " WITH ROOT" << endl; #else - cout << " WITHOUT ROOT" << endl; + cout << " WITHOUT ROOT" << endl; #endif + } //set data compression enable dataCompressionEnable = b; @@ -617,7 +619,7 @@ int UDPStandardImplementation::setTenGigaEnable(const bool b){ int UDPStandardImplementation::setDetectorType(const detectorType d){ FILE_LOG(logDEBUG1) << __AT__ << " called"; - cout << "Setting receiver type ..." << endl; + cout << "Info: Setting receiver type ..." << endl; deleteMembers(); initializeBaseMembers(); @@ -631,7 +633,7 @@ int UDPStandardImplementation::setDetectorType(const detectorType d){ case EIGER: case JUNGFRAUCTB: case JUNGFRAU: - cout << "Info: ***** This is a " << getDetectorType(d) << " Receiver *****" << endl; + FILE_LOG(logINFO) << " ***** This is a " << getDetectorType(d) << " Receiver *****" << endl; break; default: cprintf(BG_RED, "Error: This is an unknown receiver type %d\n", (int)d); @@ -761,7 +763,8 @@ void UDPStandardImplementation::resetAcquisitionCount(){ int UDPStandardImplementation::startReceiver(char *c){ FILE_LOG(logDEBUG1) << __AT__ << " called"; - + + cout << endl; cout << "Info: Starting Receiver" << endl; @@ -800,15 +803,16 @@ int UDPStandardImplementation::startReceiver(char *c){ //Print Receiver Configuration - cout << "Info: ***Receiver Configuration***" << endl; - cout << "Info: Max Packets Per File:" << maxPacketsPerFile << endl; - cout << "Info: Data Compression has been " << stringEnable(dataCompressionEnable) << endl; - if(myDetectorType != EIGER) + if(myDetectorType != EIGER){ + + cout << "Info: Data Compression has been " << stringEnable(dataCompressionEnable) << endl; cout << "Info: Number of Jobs Per Buffer: " << numberofJobsPerBuffer << endl; + cout << "Info: Max Packets Per File:" << maxPacketsPerFile << endl; + } if(FrameToGuiFrequency) - cout << "Info: Frequency of frames sent to gui" << FrameToGuiFrequency << endl; + cout << "Info: requency of frames sent to gui: " << FrameToGuiFrequency << endl; else - cout << "Info: Random frames sent to gui" << endl; + cout << "Info: Frequency of frames sent to gui: Random" << endl; @@ -895,7 +899,7 @@ void UDPStandardImplementation::stopReceiver(){ int UDPStandardImplementation::shutDownUDPSockets(){ FILE_LOG(logDEBUG1) << __AT__ << " called"; - cout << "Info: Shutting down UDP Socket(s)" << endl; + FILE_LOG(logDEBUG1) << "Info: Shutting down UDP Socket(s)" << endl; for(int i=0;istart() == slsReceiverDefs::OK){ - cout << "DONE!" << endl; + FILE_LOG(logDEBUG1) << "DONE!" << endl; string str; cin>>str; //wait and look for an exit keyword diff --git a/slsReceiverSoftware/src/slsReceiverTCPIPInterface.cpp b/slsReceiverSoftware/src/slsReceiverTCPIPInterface.cpp index be3242cd9..e0835df55 100644 --- a/slsReceiverSoftware/src/slsReceiverTCPIPInterface.cpp +++ b/slsReceiverSoftware/src/slsReceiverTCPIPInterface.cpp @@ -125,14 +125,14 @@ int slsReceiverTCPIPInterface::setPortNumber(int pn){ int slsReceiverTCPIPInterface::start(){ - cout << "Creating TCP Server Thread" << endl; + FILE_LOG(logDEBUG1) << "Creating TCP Server Thread" << endl; killTCPServerThread = 0; if(pthread_create(&TCPServer_thread, NULL,startTCPServerThread, (void*) this)){ cout << "Could not create TCP Server thread" << endl; return FAIL; } //#ifdef VERBOSE - cout << "TCP Server thread created successfully." << endl; + FILE_LOG(logDEBUG1) << "TCP Server thread created successfully." << endl; //#endif return OK; } From 963717215f346e7f06b4161b5ba3a88fec6e790f Mon Sep 17 00:00:00 2001 From: Dhanya Maliakal Date: Thu, 29 Oct 2015 17:23:39 +0100 Subject: [PATCH 48/68] done --- slsReceiverSoftware/include/ansi.h | 29 +- slsReceiverSoftware/include/logger.h | 43 ++- .../src/UDPBaseImplementation.cpp | 16 +- slsReceiverSoftware/src/UDPInterface.cpp | 2 +- .../src/UDPStandardImplementation.cpp | 257 ++++++++---------- .../src/slsReceiverTCPIPInterface.cpp | 77 +++--- 6 files changed, 221 insertions(+), 203 deletions(-) diff --git a/slsReceiverSoftware/include/ansi.h b/slsReceiverSoftware/include/ansi.h index 1a24d403e..210491373 100644 --- a/slsReceiverSoftware/include/ansi.h +++ b/slsReceiverSoftware/include/ansi.h @@ -1,17 +1,18 @@ -#define RED "\x1b[31m" -#define GREEN "\x1b[32m" -#define YELLOW "\x1b[33m" -#define BLUE "\x1b[34m" -#define MAGENTA "\x1b[35m" -#define CYAN "\x1b[36m" -#define BG_RED "\x1b[41m" -#define BG_GREEN "\x1b[42m" -#define BG_YELLOW "\x1b[43m" -#define BG_BLUE "\x1b[44m" -#define BG_MAGENTA "\x1b[45m" -#define BG_CYAN "\x1b[46m" -#define RESET "\x1b[0m" -#define BOLD "\x1b[1m" +#define RED "\x1b[31m" +#define GREEN "\x1b[32m" +#define YELLOW "\x1b[33m" +#define BLUE "\x1b[34m" +#define MAGENTA "\x1b[35m" +#define CYAN "\x1b[36m" +#define GRAY "\x1b[37m" +#define BG_RED "\x1b[41m" +#define BG_GREEN "\x1b[42m" +#define BG_YELLOW "\x1b[43m" +#define BG_BLUE "\x1b[44m" +#define BG_MAGENTA "\x1b[45m" +#define BG_CYAN "\x1b[46m" +#define RESET "\x1b[0m" +#define BOLD "\x1b[1m" #define cprintf(code, format, ...) printf(code format RESET, ##__VA_ARGS__) diff --git a/slsReceiverSoftware/include/logger.h b/slsReceiverSoftware/include/logger.h index 5e964da27..7732abffc 100644 --- a/slsReceiverSoftware/include/logger.h +++ b/slsReceiverSoftware/include/logger.h @@ -5,6 +5,7 @@ #include #include #include +#include #ifdef VERBOSE #define FILELOG_MAX_LEVEL logDEBUG @@ -14,6 +15,10 @@ #define FILELOG_MAX_LEVEL logDEBUG4 #endif +#ifdef FIFODEBUG +#define FILELOG_MAX_LEVEL logDEBUG5 +#endif + #ifndef FILELOG_MAX_LEVEL #define FILELOG_MAX_LEVEL logINFO #endif @@ -40,7 +45,7 @@ void error(const char *location, const char *msg){ inline std::string NowTime(); -enum TLogLevel {logERROR, logWARNING, logINFO, logDEBUG, logDEBUG1, logDEBUG2, logDEBUG3, logDEBUG4}; +enum TLogLevel {logERROR, logWARNING, logINFO, logDEBUG, logDEBUG1, logDEBUG2, logDEBUG3, logDEBUG4, logDEBUG5}; template class Log{ public: @@ -52,6 +57,7 @@ template class Log{ static TLogLevel FromString(const std::string& level); protected: std::ostringstream os; + TLogLevel lev; private: Log(const Log&); Log& operator =(const Log&); @@ -62,6 +68,7 @@ class Output2FILE { public: static FILE*& Stream(); static void Output(const std::string& msg); + static void Output(const std::string& msg, TLogLevel level); }; #if defined(WIN32) || defined(_WIN32) || defined(__WIN32__) @@ -79,10 +86,17 @@ public: class FILELOG_DECLSPEC FILELog : public Log {}; //typedef Log FILELog; +#ifdef REST #define FILE_LOG(level) \ if (level > FILELOG_MAX_LEVEL) ; \ else if (level > FILELog::ReportingLevel() || !Output2FILE::Stream()) ; \ else FILELog().Get(level) +#else + #define FILE_LOG(level) \ + if (level > FILELOG_MAX_LEVEL) ; \ + else if (level > FILELog::ReportingLevel() || !Output2FILE::Stream()) ; \ + else FILELog().Get(level) +#endif #if defined(WIN32) || defined(_WIN32) || defined(__WIN32__) @@ -126,10 +140,11 @@ inline std::string NowTime() #endif //WIN32 -template Log::Log(){} +template Log::Log():lev(logDEBUG){} template std::ostringstream& Log::Get(TLogLevel level) { + lev = level; os << "- " << NowTime(); os << " " << ToString(level) << ": "; os << std::string(level > logDEBUG ? level - logDEBUG : 0, '\t'); @@ -139,24 +154,30 @@ template std::ostringstream& Log::Get(TLogLevel level) template Log::~Log() { os << std::endl; +#ifdef REST T::Output( os.str()); +#else + T::Output( os.str(),lev); +#endif } template TLogLevel& Log::ReportingLevel() { - static TLogLevel reportingLevel = logDEBUG4; + static TLogLevel reportingLevel = logDEBUG5; return reportingLevel; } template std::string Log::ToString(TLogLevel level) { - static const char* const buffer[] = {"ERROR", "WARNING", "INFO", "DEBUG", "DEBUG1", "DEBUG2", "DEBUG3", "DEBUG4"}; + static const char* const buffer[] = {"ERROR", "WARNING", "INFO", "DEBUG", "DEBUG1", "DEBUG2", "DEBUG3", "DEBUG4","DEBUG5"}; return buffer[level]; } template TLogLevel Log::FromString(const std::string& level) { + if (level == "DEBUG5") + return logDEBUG5; if (level == "DEBUG4") return logDEBUG4; if (level == "DEBUG3") @@ -193,6 +214,20 @@ inline void Output2FILE::Output(const std::string& msg) fflush(pStream); } +inline void Output2FILE::Output(const std::string& msg, TLogLevel level) +{ + FILE* pStream = Stream(); + if (!pStream) + return; + switch(level){ + case logERROR: cprintf(RED BOLD,"%s",msg.c_str()); break; + case logWARNING: cprintf(YELLOW BOLD,"%s",msg.c_str()); break; + case logINFO: cprintf(GRAY,"%s",msg.c_str()); break; + default: fprintf(pStream,"%s",msg.c_str()); break; + } + fflush(pStream); +} + #if defined(WIN32) || defined(_WIN32) || defined(__WIN32__) # if defined (BUILDING_FILELOG_DLL) # define FILELOG_DECLSPEC __declspec (dllexport) diff --git a/slsReceiverSoftware/src/UDPBaseImplementation.cpp b/slsReceiverSoftware/src/UDPBaseImplementation.cpp index 94a39d07d..eaac8c8e9 100644 --- a/slsReceiverSoftware/src/UDPBaseImplementation.cpp +++ b/slsReceiverSoftware/src/UDPBaseImplementation.cpp @@ -35,7 +35,7 @@ UDPBaseImplementation::UDPBaseImplementation(){ void UDPBaseImplementation::initializeMembers(){ FILE_LOG(logDEBUG) << __AT__ << " starting"; - FILE_LOG(logDEBUG1) << "Info: Initializing base members" << endl; + FILE_LOG(logDEBUG) << "Info: Initializing base members"; //**detector parameters*** myDetectorType = GENERIC; strcpy(detHostname,""); @@ -202,7 +202,7 @@ void UDPBaseImplementation::setBottomEnable(const bool b){ FILE_LOG(logDEBUG) << __AT__ << " starting"; bottomEnable = b; - FILE_LOG(logINFO) << "Bottom - " << stringEnable(bottomEnable) << endl; + FILE_LOG(logINFO) << "Bottom - " << stringEnable(bottomEnable); } @@ -216,7 +216,7 @@ void UDPBaseImplementation::setFileName(const char c[]){ } void UDPBaseImplementation::setFilePath(const char c[]){ - FILE_LOG(logINFO) << __AT__ << " starting"; + FILE_LOG(logDEBUG) << __AT__ << " starting"; if(strlen(c)){ //check if filepath exists @@ -229,7 +229,7 @@ void UDPBaseImplementation::setFilePath(const char c[]){ } strcpy(filePath, c); } - FILE_LOG(logDEBUG1) << "Info: File path:" << filePath; + FILE_LOG(logDEBUG) << "Info: File path:" << filePath; } void UDPBaseImplementation::setFileIndex(const uint64_t i){ @@ -285,14 +285,14 @@ void UDPBaseImplementation::setUDPPortNumber(const uint32_t i){ FILE_LOG(logDEBUG) << __AT__ << " starting"; udpPortNum[0] = i; - FILE_LOG(logINFO) << "udpPortNum[0]:" << udpPortNum[0]; + FILE_LOG(logINFO) << "UDP Port Number[0]:" << udpPortNum[0]; } void UDPBaseImplementation::setUDPPortNumber2(const uint32_t i){ FILE_LOG(logDEBUG) << __AT__ << " starting"; udpPortNum[1] = i; - FILE_LOG(logINFO) << "udpPortNum[1]:" << udpPortNum[1]; + FILE_LOG(logINFO) << "UDP Port Number[1]:" << udpPortNum[1]; } void UDPBaseImplementation::setEthernetInterface(const char* c){ @@ -325,7 +325,7 @@ int UDPBaseImplementation::setAcquisitionPeriod(const uint64_t i){ FILE_LOG(logDEBUG) << __AT__ << " starting"; acquisitionPeriod = i; - FILE_LOG(logINFO) << "Acquisition Period:" << acquisitionPeriod; + FILE_LOG(logINFO) << "Acquisition Period:" << (double)acquisitionPeriod/(1E9) << "s"; //overrridden child classes might return FAIL return OK; @@ -389,7 +389,7 @@ void UDPBaseImplementation::resetAcquisitionCount(){ FILE_LOG(logDEBUG) << __AT__ << " starting"; totalPacketsCaught = 0; - FILE_LOG(logINFO) << "totalPacketsCaught:" << totalPacketsCaught << endl; + FILE_LOG(logINFO) << "totalPacketsCaught:" << totalPacketsCaught; } int UDPBaseImplementation::startReceiver(char *c){ diff --git a/slsReceiverSoftware/src/UDPInterface.cpp b/slsReceiverSoftware/src/UDPInterface.cpp index 937035845..17491bc3a 100644 --- a/slsReceiverSoftware/src/UDPInterface.cpp +++ b/slsReceiverSoftware/src/UDPInterface.cpp @@ -23,7 +23,7 @@ using namespace std; UDPInterface * UDPInterface::create(string receiver_type){ if (receiver_type == "standard"){ - cout << "Starting " << receiver_type << endl; + FILE_LOG(logINFO) << "Starting " << receiver_type; return new UDPStandardImplementation(); } #ifdef REST diff --git a/slsReceiverSoftware/src/UDPStandardImplementation.cpp b/slsReceiverSoftware/src/UDPStandardImplementation.cpp index bfe8c9eb7..346d6db9f 100644 --- a/slsReceiverSoftware/src/UDPStandardImplementation.cpp +++ b/slsReceiverSoftware/src/UDPStandardImplementation.cpp @@ -42,10 +42,11 @@ UDPStandardImplementation::UDPStandardImplementation(){ pthread_mutex_init(&progressMutex,NULL); //to increase socket receiver buffer size and max length of input queue by changing kernel settings - if(system("echo $((100*1024*1024)) > /proc/sys/net/core/rmem_max")) - FILE_LOG(logDEBUG1) << "Warning: No root permission to change socket receiver buffer size in file /proc/sys/net/core/rmem_max" << endl; + if(myDetectorType == EIGER); + else if(system("echo $((100*1024*1024)) > /proc/sys/net/core/rmem_max")) + FILE_LOG(logDEBUG) << "Warning: No root permission to change socket receiver buffer size in file /proc/sys/net/core/rmem_max"; else if(system("echo 250000 > /proc/sys/net/core/netdev_max_backlog")) - FILE_LOG(logDEBUG1) << "Warning: No root permission to change max length of input queue in file /proc/sys/net/core/netdev_max_backlog" << endl; + FILE_LOG(logDEBUG) << "Warning: No root permission to change max length of input queue in file /proc/sys/net/core/netdev_max_backlog"; /** permanent setting by heiner net.core.rmem_max = 104857600 # 100MiB net.core.netdev_max_backlog = 250000 @@ -53,8 +54,7 @@ UDPStandardImplementation::UDPStandardImplementation(){ // from the manual sysctl -w net.core.rmem_max=16777216 sysctl -w net.core.netdev_max_backlog=250000 - */ - cout << endl; + */ } UDPStandardImplementation::~UDPStandardImplementation(){ @@ -74,7 +74,7 @@ UDPStandardImplementation::~UDPStandardImplementation(){ void UDPStandardImplementation::deleteMembers(){ FILE_LOG(logDEBUG1) << __AT__ << " starting"; - FILE_LOG(logDEBUG1) << "Info: Deleting member pointers" << endl; + FILE_LOG(logDEBUG) << "Info: Deleting member pointers"; shutDownUDPSockets(); closeFile(); //filter @@ -120,7 +120,7 @@ void UDPStandardImplementation::initializeBaseMembers(){ void UDPStandardImplementation::initializeMembers(){ FILE_LOG(logDEBUG1) << __AT__ << " starting"; - FILE_LOG(logDEBUG1) << "Info: Initializing members" << endl; + FILE_LOG(logDEBUG) << "Info: Initializing members"; //***detector parameters*** frameSize = 0; @@ -257,7 +257,7 @@ int UDPStandardImplementation::setupFifoStructure(){ //eiger always listens to 1 packet at a time if(myDetectorType == EIGER){ numberofJobsPerBuffer = 1; - FILE_LOG(logDEBUG1) << "Info: 1 packet per buffer" << endl; + FILE_LOG(logDEBUG) << "Info: 1 packet per buffer"; } //else calculate best possible number of frames to listen to at a time (for fast readouts like gotthard) @@ -280,7 +280,7 @@ int UDPStandardImplementation::setupFifoStructure(){ numberofJobsPerBuffer = i; } - cout << "Info: Number of Frames per buffer:" << numberofJobsPerBuffer << endl; + FILE_LOG(logINFO) << "Number of Frames per buffer:" << numberofJobsPerBuffer << endl; } //set fifo depth @@ -299,7 +299,7 @@ int UDPStandardImplementation::setupFifoStructure(){ else fifoSize = fifoSize/numberofJobsPerBuffer; } - FILE_LOG(logDEBUG1) << "Info: Fifo Depth:" << fifoSize << endl; + FILE_LOG(logDEBUG) << "Info: Fifo Depth:" << fifoSize; @@ -315,8 +315,8 @@ int UDPStandardImplementation::setupFifoStructure(){ if(fifoFree[i]){ while(!fifoFree[i]->isEmpty()) fifoFree[i]->pop(buffer[i]); -#ifdef FIFODEBUG - cprintf(GREEN,"Info: %d fifostructure popped from fifofree %p\n", i, (void*)(buffer[i])); +#ifdef DEBUG5 + cprintf(BLUE,"Info: %d fifostructure popped from fifofree %p\n", i, (void*)(buffer[i])); #endif delete fifoFree[i]; } @@ -338,13 +338,13 @@ int UDPStandardImplementation::setupFifoStructure(){ buffer[i]=mem0[i]; while (buffer[i] < (mem0[i]+(bufferSize * numberofJobsPerBuffer + HEADER_SIZE_NUM_TOT_PACKETS) * (fifoSize-1))) { fifoFree[i]->push(buffer[i]); -#ifdef FIFODEBUG +#ifdef DEBUG5 cprintf(BLUE,"Info: %d fifostructure free pushed into fifofree %p\n", i, (void*)(buffer[i])); #endif buffer[i] += (bufferSize * numberofJobsPerBuffer + HEADER_SIZE_NUM_TOT_PACKETS); } } - FILE_LOG(logDEBUG1) << "Info: Fifo structure(s) reconstructed" << endl; + FILE_LOG(logDEBUG) << "Info: Fifo structure(s) reconstructed"; return OK; } @@ -366,7 +366,7 @@ void UDPStandardImplementation::configure(map config_map){ b = 0; } bottomEnable = b!= 0; - cout << "Info: Bottom - " << stringEnable(bottomEnable) << endl; + FILE_LOG(logINFO) << "Bottom: " << stringEnable(bottomEnable); } } @@ -410,7 +410,7 @@ int UDPStandardImplementation::setDataCompressionEnable(const bool b){ if(b) initializeFilter(); - cout << "Info: Data Compression " << stringEnable(dataCompressionEnable) << endl; + FILE_LOG(logINFO) << "Data Compression: " << stringEnable(dataCompressionEnable); return OK; } @@ -450,7 +450,7 @@ void UDPStandardImplementation::setShortFrameEnable(const int i){ if(dataCompressionEnable) initializeFilter(); - cout << "Info: Short Frame Enable set to " << shortFrameEnable << endl; + FILE_LOG(logINFO) << "Short Frame Enable: " << shortFrameEnable; } @@ -461,7 +461,7 @@ int UDPStandardImplementation::setFrameToGuiFrequency(const uint32_t i){ if(setupFifoStructure() == FAIL) return FAIL; - cout << "Info: Frame to Gui Frequency set to " << FrameToGuiFrequency << endl; + FILE_LOG(logINFO) << "Frame to Gui Frequency: " << FrameToGuiFrequency; return OK; } @@ -474,7 +474,7 @@ int UDPStandardImplementation::setAcquisitionPeriod(const uint64_t i){ if(setupFifoStructure() == FAIL) return FAIL; - cout << "Info: Acquisition Period set to " << acquisitionPeriod << endl; + FILE_LOG(logINFO) << "Acquisition Period: " << (double)acquisitionPeriod/(1E9) << "s"; return OK; @@ -485,7 +485,7 @@ int UDPStandardImplementation::setDynamicRange(const uint32_t i){ uint32_t oldDynamicRange = dynamicRange; - cout << "Info: Setting Dynamic Range to " << i << endl; + FILE_LOG(logDEBUG) << "Info: Setting Dynamic Range to " << i; dynamicRange = i; if(myDetectorType == EIGER){ @@ -515,11 +515,11 @@ int UDPStandardImplementation::setDynamicRange(const uint32_t i){ //create threads if(createListeningThreads() == FAIL){ - cprintf(BG_RED,"Error: Could not create listening thread\n"); + FILE_LOG(logERROR) << "Could not create listening thread"; return FAIL; } if(createWriterThreads() == FAIL){ - cprintf(BG_RED,"Error: Could not create writer threads\n"); + FILE_LOG(logERROR) << "Could not create writer threads"; return FAIL; } setThreadPriorities(); @@ -527,7 +527,7 @@ int UDPStandardImplementation::setDynamicRange(const uint32_t i){ } - cout << "Info: Dynamic Range set to " << dynamicRange << endl; + FILE_LOG(logINFO) << "Dynamic Range: " << dynamicRange; return OK; } @@ -537,7 +537,7 @@ int UDPStandardImplementation::setDynamicRange(const uint32_t i){ int UDPStandardImplementation::setTenGigaEnable(const bool b){ FILE_LOG(logDEBUG1) << __AT__ << " called"; - cout << "Info: Setting Ten Giga to " << stringEnable(b) << endl; + FILE_LOG(logDEBUG) << "Info: Setting Ten Giga to " << stringEnable(b); bool oldTenGigaEnable = tengigaEnable; tengigaEnable = b; @@ -557,13 +557,13 @@ int UDPStandardImplementation::setTenGigaEnable(const bool b){ bufferSize = onePacketSize; maxPacketsPerFile = EIGER_MAX_FRAMES_PER_FILE * packetsPerFrame; - FILE_LOG(logDEBUG1) << dec << + FILE_LOG(logDEBUG) << dec << "packetsPerFrame:" << packetsPerFrame << "\nonePacketSize:" << onePacketSize << "\noneDataSize:" << oneDataSize << "\nframesize:" << frameSize << "\nbufferSize:" << bufferSize << - "\nmaxPacketsPerFile:" << maxPacketsPerFile << endl; + "\nmaxPacketsPerFile:" << maxPacketsPerFile; @@ -586,11 +586,11 @@ int UDPStandardImplementation::setTenGigaEnable(const bool b){ //create threads if(createListeningThreads() == FAIL){ - cprintf(BG_RED,"Error: Could not create listening thread\n"); + FILE_LOG(logERROR) << "Could not create listening thread"; return FAIL; } if(createWriterThreads() == FAIL){ - cprintf(BG_RED,"Error: Could not create writer threads\n"); + FILE_LOG(logERROR) << "Could not create writer threads"; return FAIL; } setThreadPriorities(); @@ -598,7 +598,7 @@ int UDPStandardImplementation::setTenGigaEnable(const bool b){ } - cout << "Info: Ten Giga " << stringEnable(tengigaEnable) << endl; + FILE_LOG(logINFO) << "Ten Giga: " << stringEnable(tengigaEnable); return OK; } @@ -619,7 +619,7 @@ int UDPStandardImplementation::setTenGigaEnable(const bool b){ int UDPStandardImplementation::setDetectorType(const detectorType d){ FILE_LOG(logDEBUG1) << __AT__ << " called"; - cout << "Info: Setting receiver type ..." << endl; + FILE_LOG(logDEBUG) << "Setting receiver type"; deleteMembers(); initializeBaseMembers(); @@ -633,10 +633,10 @@ int UDPStandardImplementation::setDetectorType(const detectorType d){ case EIGER: case JUNGFRAUCTB: case JUNGFRAU: - FILE_LOG(logINFO) << " ***** This is a " << getDetectorType(d) << " Receiver *****" << endl; + FILE_LOG(logINFO) << " ***** This is a " << getDetectorType(d) << " Receiver *****"; break; default: - cprintf(BG_RED, "Error: This is an unknown receiver type %d\n", (int)d); + FILE_LOG(logERROR) << "This is an unknown receiver type " << (int)d; return FAIL; } @@ -710,7 +710,7 @@ int UDPStandardImplementation::setDetectorType(const detectorType d){ //footerOffset = Not applicable; break; default: - cprintf(BG_RED, "Error: This is an unknown receiver type %d\n", (int)d); + FILE_LOG(logERROR) << "This is an unknown receiver type " << (int)d; return FAIL; } @@ -730,11 +730,11 @@ int UDPStandardImplementation::setDetectorType(const detectorType d){ //create threads if(createListeningThreads() == FAIL){ - cprintf(BG_RED,"Error: Could not create listening thread\n"); + FILE_LOG(logERROR) << "Could not create listening thread"; return FAIL; } if(createWriterThreads() == FAIL){ - cprintf(BG_RED,"Error: Could not create writer threads\n"); + FILE_LOG(logERROR) << "Could not create writer threads"; return FAIL; } setThreadPriorities(); @@ -742,8 +742,7 @@ int UDPStandardImplementation::setDetectorType(const detectorType d){ //allocate for latest data (frame copy for gui) latestData = new char[frameSize]; - cout << " Detector type set to " << getDetectorType(d) << endl; - cout << "Ready..." << endl; + FILE_LOG(logDEBUG) << " Detector type set to " << getDetectorType(d); return OK; } @@ -757,15 +756,14 @@ void UDPStandardImplementation::resetAcquisitionCount(){ acqStarted = false; startAcquisitionIndex = 0; - cout << "Info: Acquisition Count has been reset" << endl; + FILE_LOG(logINFO) << "Acquisition Count has been reset"; } int UDPStandardImplementation::startReceiver(char *c){ FILE_LOG(logDEBUG1) << __AT__ << " called"; - cout << endl; - cout << "Info: Starting Receiver" << endl; + FILE_LOG(logINFO) << "Starting Receiver"; //RESET @@ -804,32 +802,29 @@ int UDPStandardImplementation::startReceiver(char *c){ //Print Receiver Configuration if(myDetectorType != EIGER){ - - cout << "Info: Data Compression has been " << stringEnable(dataCompressionEnable) << endl; - cout << "Info: Number of Jobs Per Buffer: " << numberofJobsPerBuffer << endl; - cout << "Info: Max Packets Per File:" << maxPacketsPerFile << endl; + FILE_LOG(logINFO) << "Data Compression has been " << stringEnable(dataCompressionEnable); + FILE_LOG(logINFO) << "Number of Jobs Per Buffer: " << numberofJobsPerBuffer; + FILE_LOG(logINFO) << "Max Packets Per File:" << maxPacketsPerFile; } if(FrameToGuiFrequency) - cout << "Info: requency of frames sent to gui: " << FrameToGuiFrequency << endl; + FILE_LOG(logINFO) << "Frequency of frames sent to gui: " << FrameToGuiFrequency; else - cout << "Info: Frequency of frames sent to gui: Random" << endl; + FILE_LOG(logINFO) << "Frequency of frames sent to gui: Random"; //create UDP sockets if(createUDPSockets() == FAIL){ - strcpy(c,"Could not create UDP Socket(s).\n"); - cout << endl; - cprintf(BG_RED, "Error: %s\n",c); + strcpy(c,"Could not create UDP Socket(s)."); + FILE_LOG(logERROR) << c; return FAIL; } if(setupWriter() == FAIL){ //stop udp socket shutDownUDPSockets(); - sprintf(c,"Could not create file %s.\n",completeFileName); - cout << endl; - cprintf(BG_RED, "Error: %s\n",c); + sprintf(c,"Could not create file %s.",completeFileName); + FILE_LOG(logERROR) << c; return FAIL; } @@ -854,8 +849,8 @@ int UDPStandardImplementation::startReceiver(char *c){ for(int i=0; i < numberofWriterThreads; i++) sem_post(&writerSemaphore[i]); //usleep(5000000); - cout << "Info: Receiver Started." << endl; - cout << "Info: Status:" << runStatusType(status) << endl; + FILE_LOG(logINFO) << "Receiver Started"; + FILE_LOG(logINFO) << "Status:" << runStatusType(status); return OK; } @@ -868,7 +863,7 @@ int UDPStandardImplementation::startReceiver(char *c){ void UDPStandardImplementation::stopReceiver(){ FILE_LOG(logDEBUG1) << __AT__ << " called"; - cout << "Info: Stopping Receiver" << endl; + FILE_LOG(logINFO) << "Stopping Receiver"; //set status to transmitting startReadout(); @@ -887,8 +882,8 @@ void UDPStandardImplementation::stopReceiver(){ status = IDLE; pthread_mutex_unlock(&(statusMutex)); - cout << "Info: Receiver Stopped" << endl; - cout << "Info: Status:" << runStatusType(status) << endl; + FILE_LOG(logINFO) << "Receiver Stopped"; + FILE_LOG(logINFO) << "Status:" << runStatusType(status); cout << endl; } @@ -899,7 +894,7 @@ void UDPStandardImplementation::stopReceiver(){ int UDPStandardImplementation::shutDownUDPSockets(){ FILE_LOG(logDEBUG1) << __AT__ << " called"; - FILE_LOG(logDEBUG1) << "Info: Shutting down UDP Socket(s)" << endl; + FILE_LOG(logDEBUG) << "Info: Shutting down UDP Socket(s)"; for(int i=0;iWrite()) //->Write(tall->GetName(),TObject::kOverwrite); - cout << "Info: Thread " << i <<": wrote frames to file" << endl; + FILE_LOG(logINFO) << "Thread " << i <<": wrote frames to file"; else - cout << "Info: Thread " << i << ": could not write frames to file" << endl; + FILE_LOG(logINFO) << "Thread " << i << ": could not write frames to file"; }else - cout << "Info: Thread " << i << ": could not write frames to file: No file or No Tree" << endl; + FILE_LOG(logINFO) << "Thread " << i << ": could not write frames to file: No file or No Tree"; //close file if(myTree[i] && myFile[i]) myFile[i] = myTree[i]->GetCurrentFile(); @@ -1068,23 +1063,22 @@ int UDPStandardImplementation::createListeningThreads(bool destroy){ //destroy if(destroy){ - FILE_LOG(logDEBUG) << "Info: Destroying Listening Thread(s)" << endl; + FILE_LOG(logDEBUG) << "Info: Destroying Listening Thread(s)"; killAllListeningThreads = true; for(int i = 0; i < numberofListeningThreads; ++i){ sem_post(&listenSemaphore[i]); pthread_join(listeningThreads[i],NULL); - cout <<"."<getErrorStatus(); if(!iret){ - cout << "Info: UDP port opened at port " << port[i] << endl; + FILE_LOG(logINFO) << "UDP port opened at port " << port[i]; }else{ -#ifdef VERBOSE - cprintf(BG_RED,"Error: Could not create UDP socket on port %d error: %d\n", port[i], iret); -#endif + FILE_LOG(logERROR) << "Could not create UDP socket on port " << port[i] << " error: " << iret; shutDownUDPSockets(); return FAIL; } } - cout << "Info: UDP socket(s) created successfully." << endl; - cout << "Info: Listener Ready ..." << endl; + FILE_LOG(logDEBUG) << "UDP socket(s) created successfully."; + FILE_LOG(logINFO) << "Listener Ready ..."; return OK; } @@ -1270,11 +1254,11 @@ int UDPStandardImplementation::setupWriter(){ cbAction=startAcquisitionCallBack(filePath,fileName,(int)fileIndex,bufferSize,pStartAcquisition); if(cbAction < DO_EVERYTHING){ - cout << "Info: Call back activated. Data saving must be taken care of by user in call back." << endl; + FILE_LOG(logINFO) << "Call back activated. Data saving must be taken care of by user in call back."; if (rawDataReadyCallBack) - cout << "Info: Data Write has been defined externally" << endl; + FILE_LOG(logINFO) << "Data Write has been defined externally"; }else if(!fileWriteEnable) - cout << "Info: Data will not be saved" << endl; + FILE_LOG(logINFO) << "Data will not be saved"; @@ -1285,7 +1269,7 @@ int UDPStandardImplementation::setupWriter(){ pthread_mutex_unlock(&statusMutex); for(int i=0; inewDataSet(); if(myFile[ithread]==NULL){ - cprintf(BG_RED,"Error: File Null\n"); + FILE_LOG(logERROR) << "File Null"; return FAIL; } if(!myFile[ithread]->IsOpen()){ - cprintf(BG_RED,"Error: File Not Open\n") + FILE_LOG(logERROR) << "File Not Open"; return FAIL; } return OK; @@ -1464,13 +1448,13 @@ void UDPStandardImplementation::startListening(){ //pop from fifo fifoFree[ithread]->pop(buffer[ithread]); -#ifdef FIFODEBUG - cprintf(BLUE,"%d :Listener popped from fifofree %p\n", ithread, (void*)(buffer[ithread])); +#ifdef DEBUG5 + cprintf(BLUE,"Listening_Thread %d :Listener popped from fifofree %p\n", ithread, (void*)(buffer[ithread])); #endif //udpsocket doesnt exist if(udpSocket[ithread] == NULL){ - cprintf(RED, "Error: Thread %d :UDP Socket not created\n",ithread); + FILE_LOG(logERROR) << "Listening_Thread " << ithread << ": UDP Socket not created"; stopListening(ithread,0); continue; } @@ -1501,7 +1485,7 @@ void UDPStandardImplementation::startListening(){ //push buffer to FIFO while(!fifo[ithread]->push(buffer[ithread])); -#ifdef FIFODEBUG +#ifdef DEBUG5 cprintf(BLUE,"Listening_Thread %d: Listener pushed into fifo %p\n",ithread, (void*)(buffer[ithread])); #endif @@ -1512,7 +1496,7 @@ void UDPStandardImplementation::startListening(){ //check to exit thread (for change of parameters) - only EXIT possibility if(killAllListeningThreads){ - cprintf(GREEN,"Listening_Thread %d:Goodbye!\n",ithread); + cprintf(BLUE,"Listening_Thread %d:Goodbye!\n",ithread); //free resources at exit if(tempBuffer) delete[] tempBuffer; pthread_exit(NULL); @@ -1544,7 +1528,7 @@ int UDPStandardImplementation::prepareAndListenBuffer(int ithread, int lSize, in } #ifdef DEBUG - cprintf(BLUE, "Listening_Thread %d : Received bytes: %d. Expected bytes: %d\n", ithread, receivedSize, expected-cSize); + cprintf(BLUE, "Listening_Thread %d : Received bytes: %d. Expected bytes: %d\n", ithread, receivedSize, bufferSize * numberofJobsPerBuffer-cSize); #endif return receivedSize; } @@ -1577,11 +1561,11 @@ void UDPStandardImplementation::startFrameIndices(int ithread){ if(!acqStarted){ startAcquisitionIndex = startFrameIndex; acqStarted = true; - cprintf(BLUE,"Info: Thread %d: startAcquisitionIndex:%lld\n",ithread,(long long int)startAcquisitionIndex); + cprintf(BLUE,"Listening_Thread %d: startAcquisitionIndex:%lld\n",ithread,(long long int)startAcquisitionIndex); } //set start of scan/real time measurement - cprintf(BLUE,"Info: Thread %d: startFrameIndex: %lld\n", ithread,(long long int)startFrameIndex); + cprintf(BLUE,"Listening_Thread %d: startFrameIndex: %lld\n", ithread,(long long int)startFrameIndex); measurementStarted = true; } @@ -1594,8 +1578,7 @@ void UDPStandardImplementation::startFrameIndices(int ithread){ void UDPStandardImplementation::stopListening(int ithread, int numbytes){ FILE_LOG(logDEBUG1) << __AT__ << " called"; - cout << "Info: Thread " << ithread << ": Stop Listening.\nStatus:" << runStatusType(status) << endl; - + cprintf(BLUE,"Listening_Thread %d: Stop Listening.\nStatus:%s\n", ithread, runStatusType(status).c_str()); //less than 1 packet size (especially for eiger), ignore the buffer (so that 2 dummy buffers are not sent with pc=0) if(numbytes < onePacketSize) @@ -1604,9 +1587,9 @@ void UDPStandardImplementation::stopListening(int ithread, int numbytes){ //free empty buffer if(numbytes <= 0){ - cprintf(BLUE,"Info: Thread %d :End of Acquisition for Listening Thread\n", ithread); + cprintf(BLUE,"Listening_Thread %d :End of Acquisition\n", ithread); while(!fifoFree[ithread]->push(buffer[ithread])); -#ifdef FIFODEBUG +#ifdef DEBUG5 cprintf(BLUE,"Listening_Thread %d :Listener push empty buffer into fifofree %p\n", ithread, (void*)(buffer[ithread])); #endif } @@ -1621,7 +1604,7 @@ void UDPStandardImplementation::stopListening(int ithread, int numbytes){ cprintf(BLUE,"Listening_Thread %d: Last Buffer packet count:%d\n",ithread, numbytes/onePacketSize); #endif while(!fifo[ithread]->push(buffer[ithread])); -#ifdef FIFODEBUG +#ifdef DEBUG5 cprintf(BLUE,"Listening_Thread %d: Listener Last Buffer pushed into fifo %p\n", ithread,(void*)(buffer[ithread])); #endif } @@ -1632,7 +1615,7 @@ void UDPStandardImplementation::stopListening(int ithread, int numbytes){ //creating dummy-end buffer with pc=0xFFFF (*((uint32_t*)(buffer[ithread]))) = dummyPacketValue; while(!fifo[ithread]->push(buffer[ithread])); -#ifdef FIFODEBUG +#ifdef DEBUG5 cprintf(BLUE,"Listening_Thread %d: Listener pushed dummy-end buffer into fifo %p\n", ithread,(void*)(buffer[ithread])); #endif } @@ -1797,7 +1780,7 @@ void UDPStandardImplementation::processWritingBuffer(int ithread){ while((1 << ithread) & writerThreadsMask){ //pop fifo[0]->pop(wbuf[0]); -#ifdef FIFODEBUG +#ifdef DEBUG5 cprintf(GREEN,"Writing_Thread %d: Popped %p from FIFO %d\n", ithread, (void*)(wbuf[0]),0); #endif uint32_t numPackets = (uint32_t)(*((uint32_t*)wbuf[0])); @@ -1952,7 +1935,7 @@ void UDPStandardImplementation::processWritingBufferPacketByPacket(int ithread){ //update frame number and packet number if(numPackets[i] != dummyPacketValue){ if(!((uint32_t)(*( (uint64_t*) packetBuffer_footer)))){ - cprintf(BG_RED,"Fifo %d: Error: Frame Number is zero from firmware. popready[%d]:%d\n",i,i,popReady[i]); + FILE_LOG(logERROR) << "Fifo "<< i << ": Frame Number is zero from firmware. popready[" << i << "]:" << popReady[i]; popReady[i]=true; continue; } @@ -2090,13 +2073,13 @@ void UDPStandardImplementation::processWritingBufferPacketByPacket(int ithread){ //freeing for(int j=0;jpush(toFreePointers[j])); -#ifdef FIFODEBUG +#ifdef DEBUG5 cprintf(GREEN,"Fifo 0: Writing_Thread freed: pushed into fifofree %p\n",ithread, (void*)(toFreePointers[j])); #endif } for(int j=(packetsPerFrame/numberofListeningThreads);jpush(toFreePointers[j])); -#ifdef FIFODEBUG +#ifdef DEBUG5 cprintf(GREEN,"Fifo 1: Writing_Thread freed: pushed into fifofree %p\n",ithread, (void*)(toFreePointers[j])); #endif } @@ -2210,7 +2193,7 @@ bool UDPStandardImplementation::popAndCheckEndofAcquisition(int ithread, char* w //pop if ready if(ready[i]){ fifo[i]->pop(wbuffer[i]); -#ifdef FIFODEBUG +#ifdef DEBUG5 cprintf(GREEN,"Writing_Thread %d: Popped %p from FIFO %d\n", ithread, (void*)(wbuffer[i]),i); #endif nP[i] = (uint32_t)(*((uint32_t*)wbuffer[i])); @@ -2259,7 +2242,7 @@ void UDPStandardImplementation::stopWriting(int ithread, char* wbuffer[]){ //free fifo for(int i=0; ipush(wbuffer[i])); -#ifdef FIFODEBUG +#ifdef DEBUG5 cprintf(GREEN,"Writing_Thread %d: Freeing dummy-end buffer. Pushed into fifofree %p for listener %d\n", ithread,(void*)(wbuffer[i]),i); #endif } @@ -2296,12 +2279,12 @@ void UDPStandardImplementation::stopWriting(int ithread, char* wbuffer[]){ //statistics cprintf(GREEN, "Status: Run Finished\n"); - if(!totalPacketsCaught){ - cprintf(RED, "Total Missing Packets padded:%d\n",numTotMissingPackets); - cprintf(RED, "Total Packets Caught: 0\n"); + if((long long int)(totalPacketsCaught/packetsPerFrame) == 0){ + cprintf(RED, "Total Missing Packets padded: %d\n",numTotMissingPackets); + cprintf(RED, "Total Packets Caught: %lld\n",(long long int)totalPacketsCaught); cprintf(RED, "Total Frames Caught: 0\n"); }else{ - cprintf(GREEN, "Total Missing Packets padded:%d\n",numTotMissingPackets); + cprintf(GREEN, "Total Missing Packets padded: %d\n",numTotMissingPackets); cprintf(GREEN, "Total Packets Caught:%lld\n", (long long int)totalPacketsCaught); cprintf(GREEN, "Total Frames Caught:%lld\n",(long long int)(totalPacketsCaught/packetsPerFrame)); } @@ -2365,7 +2348,7 @@ void UDPStandardImplementation::handleWithoutDataCompression(int ithread, char* //free fifo addresses (eiger frees for each packet later) if(myDetectorType != EIGER){ while(!fifoFree[0]->push(wbuffer[0])); -#ifdef FIFODEBUG +#ifdef DEBUG5 cprintf(GREEN,"Writing_Thread %d: Freed buffer, pushed into fifofree %p for listener 0\n",ithread, (void*)(wbuffer[0])); #endif } @@ -2701,7 +2684,7 @@ void UDPStandardImplementation::handleDataCompression(int ithread, char* wbuffer while(!fifoFree[0]->push(wbuffer[0])); -#ifdef FIFODEBUG +#ifdef DEBUG5 cprintf(GREEN,"Writing_Thread %d: Compression free pushed into fifofree %p for listerner 0\n", ithread, (void*)(wbuffer[0])); #endif } diff --git a/slsReceiverSoftware/src/slsReceiverTCPIPInterface.cpp b/slsReceiverSoftware/src/slsReceiverTCPIPInterface.cpp index e0835df55..d7e562f76 100644 --- a/slsReceiverSoftware/src/slsReceiverTCPIPInterface.cpp +++ b/slsReceiverSoftware/src/slsReceiverTCPIPInterface.cpp @@ -125,14 +125,14 @@ int slsReceiverTCPIPInterface::setPortNumber(int pn){ int slsReceiverTCPIPInterface::start(){ - FILE_LOG(logDEBUG1) << "Creating TCP Server Thread" << endl; + FILE_LOG(logDEBUG) << "Creating TCP Server Thread" << endl; killTCPServerThread = 0; if(pthread_create(&TCPServer_thread, NULL,startTCPServerThread, (void*) this)){ cout << "Could not create TCP Server thread" << endl; return FAIL; } //#ifdef VERBOSE - FILE_LOG(logDEBUG1) << "TCP Server thread created successfully." << endl; + FILE_LOG(logDEBUG) << "TCP Server thread created successfully." << endl; //#endif return OK; } @@ -395,25 +395,27 @@ int slsReceiverTCPIPInterface::set_detector_type(){ if(ret != FAIL){ #ifndef REST receiverBase = UDPInterface::create("standard"); - receiverBase->setBottomEnable(bottom); #endif myDetectorType = dr; ret=receiverBase->setDetectorType(myDetectorType); retval = myDetectorType; +#ifndef REST + receiverBase->setBottomEnable(bottom); +#endif } } } //#ifdef VERBOSE if(ret!=FAIL) - cout << "detector type " << dr << endl; + FILE_LOG(logDEBUG) << "detector type " << dr; else cprintf(RED, "%s\n", mess); //#endif #endif if(ret==OK && socket->differentClients){ - cout << "Force update" << endl; + FILE_LOG(logDEBUG) << "Force update"; ret=FORCE_UPDATE; } @@ -474,7 +476,7 @@ int slsReceiverTCPIPInterface::set_file_name() { #endif if(ret==OK && socket->differentClients){ - cout << "Force update" << endl; + FILE_LOG(logDEBUG) << "Force update"; ret=FORCE_UPDATE; } @@ -546,7 +548,7 @@ int slsReceiverTCPIPInterface::set_file_dir() { #endif if(ret==OK && socket->differentClients){ - cout << "Force update" << endl; + FILE_LOG(logDEBUG) << "Force update"; ret=FORCE_UPDATE; } @@ -612,7 +614,7 @@ int slsReceiverTCPIPInterface::set_file_index() { #endif if(ret==OK && socket->differentClients){ - cout << "Force update" << endl; + FILE_LOG(logDEBUG) << "Force update"; ret=FORCE_UPDATE; } @@ -685,7 +687,7 @@ int slsReceiverTCPIPInterface::set_frame_index() { #endif if(ret==OK && socket->differentClients){ - cout << "Force update" << endl; + FILE_LOG(logDEBUG) << "Force update"; ret=FORCE_UPDATE; } @@ -748,12 +750,12 @@ int slsReceiverTCPIPInterface::setup_udp(){ receiverBase->setUDPPortNumber2(udpport2); //setup udpip //get ethernet interface or IP to listen to - cout << "Ethernet interface is " << args[0] << endl; + FILE_LOG(logINFO) << "Receiver UDP IP: " << args[0]; temp = genericSocket::ipToName(args[0]); - cout << temp << endl; if(temp=="none"){ ret = FAIL; - strcpy(mess, "failed to get ethernet interface or IP to listen to\n"); + strcpy(mess, "Failed to get ethernet interface or IP\n"); + FILE_LOG(logERROR) << mess; } else{ strcpy(eth,temp.c_str()); @@ -761,9 +763,7 @@ int slsReceiverTCPIPInterface::setup_udp(){ strcpy(eth,""); ret = FAIL; } - FILE_LOG(logDEBUG) << __FILE__ << "::" << __func__ << " " << eth; receiverBase->setEthernetInterface(eth); - cout << eth << endl; //get mac address from ethernet interface if (ret != FAIL) @@ -773,11 +773,10 @@ int slsReceiverTCPIPInterface::setup_udp(){ if ((temp=="00:00:00:00:00:00") || (ret == FAIL)){ ret = FAIL; strcpy(mess,"failed to get mac adddress to listen to\n"); - cprintf(RED,"%s\n",mess); } else{ strcpy(retval,temp.c_str()); - cout<<"mac:"<differentClients){ - cout << "Force update" << endl; + FILE_LOG(logDEBUG) << "Force update"; ret=FORCE_UPDATE; } // send answer socket->SendDataOnly(&ret,sizeof(ret)); if(ret==FAIL){ - cprintf(RED, "%s\n", mess); + FILE_LOG(logERROR) << mess; socket->SendDataOnly(mess,sizeof(mess)); } socket->SendDataOnly(retval,MAX_STR_LENGTH); @@ -840,7 +839,7 @@ int slsReceiverTCPIPInterface::start_receiver(){ #endif if(ret==OK && socket->differentClients){ - cout << "Force update" << endl; + FILE_LOG(logDEBUG) << "Force update"; ret=FORCE_UPDATE; } @@ -886,7 +885,7 @@ int slsReceiverTCPIPInterface::stop_receiver(){ #endif if(ret==OK && socket->differentClients){ - cout << "Force update" << endl; + FILE_LOG(logDEBUG) << "Force update"; ret=FORCE_UPDATE; } @@ -916,7 +915,7 @@ int slsReceiverTCPIPInterface::get_status(){ #endif if(ret==OK && socket->differentClients){ - cout << "Force update" << endl; + FILE_LOG(logDEBUG) << "Force update"; ret=FORCE_UPDATE; } @@ -946,7 +945,7 @@ int slsReceiverTCPIPInterface::get_frames_caught(){ }else retval=receiverBase->getTotalFramesCaught(); #endif if(ret==OK && socket->differentClients){ - cout << "Force update" << endl; + FILE_LOG(logDEBUG) << "Force update"; ret=FORCE_UPDATE; } @@ -978,7 +977,7 @@ int slsReceiverTCPIPInterface::get_frame_index(){ #endif if(ret==OK && socket->differentClients){ - cout << "Force update" << endl; + FILE_LOG(logDEBUG) << "Force update"; ret=FORCE_UPDATE; } @@ -1019,7 +1018,7 @@ int slsReceiverTCPIPInterface::reset_frames_caught(){ #endif if(ret==OK && socket->differentClients){ - cout << "Force update" << endl; + FILE_LOG(logDEBUG) << "Force update"; ret=FORCE_UPDATE; } @@ -1087,7 +1086,7 @@ int slsReceiverTCPIPInterface::set_short_frame() { #endif if(ret==OK && socket->differentClients){ - cout << "Force update" << endl; + FILE_LOG(logDEBUG) << "Force update"; ret=FORCE_UPDATE; } @@ -1267,7 +1266,7 @@ int slsReceiverTCPIPInterface::moench_read_frame(){ #endif if(ret==OK && socket->differentClients){ - cout << "Force update" << endl; + FILE_LOG(logDEBUG) << "Force update"; ret=FORCE_UPDATE; } @@ -1448,7 +1447,7 @@ int slsReceiverTCPIPInterface::gotthard_read_frame(){ #endif if(ret==OK && socket->differentClients){ - cout << "Force update" << endl; + FILE_LOG(logDEBUG) << "Force update"; ret=FORCE_UPDATE; } @@ -1602,7 +1601,7 @@ int slsReceiverTCPIPInterface::propix_read_frame(){ #endif if(ret==OK && socket->differentClients){ - cout << "Force update" << endl; + FILE_LOG(logDEBUG) << "Force update"; ret=FORCE_UPDATE; } @@ -1864,7 +1863,7 @@ int slsReceiverTCPIPInterface::eiger_read_frame(){ #endif if(ret==OK && socket->differentClients){ - cout << "Force update" << endl; + FILE_LOG(logDEBUG) << "Force update"; ret=FORCE_UPDATE; } @@ -1939,7 +1938,7 @@ int slsReceiverTCPIPInterface::set_read_frequency(){ #endif if(ret==OK && socket->differentClients){ - cout << "Force update" << endl; + FILE_LOG(logDEBUG) << "Force update"; ret=FORCE_UPDATE; } @@ -1995,7 +1994,7 @@ int slsReceiverTCPIPInterface::enable_file_write(){ #endif if(ret==OK && socket->differentClients){ - cout << "Force update" << endl; + FILE_LOG(logDEBUG) << "Force update"; ret=FORCE_UPDATE; } @@ -2023,7 +2022,7 @@ int slsReceiverTCPIPInterface::get_id(){ #endif if(socket->differentClients){ - cout << "Force update" << endl; + FILE_LOG(logDEBUG) << "Force update"; ret=FORCE_UPDATE; } @@ -2066,7 +2065,7 @@ int slsReceiverTCPIPInterface::start_readout(){ #endif if(ret==OK && socket->differentClients){ - cout << "Force update" << endl; + FILE_LOG(logDEBUG) << "Force update"; ret=FORCE_UPDATE; } @@ -2140,7 +2139,7 @@ int slsReceiverTCPIPInterface::set_timer() { #endif if(ret==OK && socket->differentClients){ - cout << "Force update" << endl; + FILE_LOG(logDEBUG) << "Force update"; ret=FORCE_UPDATE; } @@ -2211,7 +2210,7 @@ int slsReceiverTCPIPInterface::enable_compression() { #endif if(ret==OK && socket->differentClients){ - cout << "Force update" << endl; + FILE_LOG(logDEBUG) << "Force update"; ret=FORCE_UPDATE; } @@ -2272,7 +2271,7 @@ int slsReceiverTCPIPInterface::set_detector_hostname() { #endif if(ret==OK && socket->differentClients){ - cout << "Force update" << endl; + FILE_LOG(logDEBUG) << "Force update"; ret=FORCE_UPDATE; } @@ -2364,7 +2363,7 @@ int slsReceiverTCPIPInterface::set_dynamic_range() { #endif if(ret==OK && socket->differentClients){ - cout << "Force update" << endl; + FILE_LOG(logDEBUG) << "Force update"; ret=FORCE_UPDATE; } @@ -2427,7 +2426,7 @@ int slsReceiverTCPIPInterface::enable_overwrite() { #endif if(ret==OK && socket->differentClients){ - cout << "Force update" << endl; + FILE_LOG(logDEBUG) << "Force update"; ret=FORCE_UPDATE; } @@ -2492,7 +2491,7 @@ int slsReceiverTCPIPInterface::enable_tengiga() { #endif if(ret==OK && socket->differentClients){ - cout << "Force update" << endl; + FILE_LOG(logDEBUG) << "Force update"; ret=FORCE_UPDATE; } From 4c85a27f10a207a21cfd5fdb04d468c4170882eb Mon Sep 17 00:00:00 2001 From: Dhanya Maliakal Date: Thu, 29 Oct 2015 17:34:19 +0100 Subject: [PATCH 49/68] done --- .../src/UDPBaseImplementation.cpp | 2 +- .../src/UDPStandardImplementation.cpp | 42 ++++++++++--------- 2 files changed, 23 insertions(+), 21 deletions(-) diff --git a/slsReceiverSoftware/src/UDPBaseImplementation.cpp b/slsReceiverSoftware/src/UDPBaseImplementation.cpp index eaac8c8e9..606208521 100644 --- a/slsReceiverSoftware/src/UDPBaseImplementation.cpp +++ b/slsReceiverSoftware/src/UDPBaseImplementation.cpp @@ -299,7 +299,7 @@ void UDPBaseImplementation::setEthernetInterface(const char* c){ FILE_LOG(logDEBUG) << __AT__ << " starting"; strcpy(eth, c); - FILE_LOG(logINFO) << "Ethernet Interface:" << eth; + FILE_LOG(logINFO) << "Ethernet Interface: " << eth; } diff --git a/slsReceiverSoftware/src/UDPStandardImplementation.cpp b/slsReceiverSoftware/src/UDPStandardImplementation.cpp index 346d6db9f..cf8779e75 100644 --- a/slsReceiverSoftware/src/UDPStandardImplementation.cpp +++ b/slsReceiverSoftware/src/UDPStandardImplementation.cpp @@ -763,7 +763,7 @@ void UDPStandardImplementation::resetAcquisitionCount(){ int UDPStandardImplementation::startReceiver(char *c){ FILE_LOG(logDEBUG1) << __AT__ << " called"; - FILE_LOG(logINFO) << "Starting Receiver"; + cout << "Starting Receiver" << endl; //RESET @@ -849,8 +849,8 @@ int UDPStandardImplementation::startReceiver(char *c){ for(int i=0; i < numberofWriterThreads; i++) sem_post(&writerSemaphore[i]); //usleep(5000000); - FILE_LOG(logINFO) << "Receiver Started"; - FILE_LOG(logINFO) << "Status:" << runStatusType(status); + cout << "Receiver Started" << endl; + cout << "Status:" << runStatusType(status) << endl; return OK; } @@ -863,7 +863,7 @@ int UDPStandardImplementation::startReceiver(char *c){ void UDPStandardImplementation::stopReceiver(){ FILE_LOG(logDEBUG1) << __AT__ << " called"; - FILE_LOG(logINFO) << "Stopping Receiver"; + cout << "Stopping Receiver" << endl; //set status to transmitting startReadout(); @@ -882,8 +882,8 @@ void UDPStandardImplementation::stopReceiver(){ status = IDLE; pthread_mutex_unlock(&(statusMutex)); - FILE_LOG(logINFO) << "Receiver Stopped"; - FILE_LOG(logINFO) << "Status:" << runStatusType(status); + cout << "Receiver Stopped" << endl; + cout << "Status:" << runStatusType(status) << endl; cout << endl; } @@ -931,7 +931,7 @@ void UDPStandardImplementation::startReadout(){ pthread_mutex_lock(&statusMutex); status = TRANSMITTING; pthread_mutex_unlock(&statusMutex); - FILE_LOG(logINFO) << "Status: Transmitting"; + cout << "Status: Transmitting" << endl; } //shut down udp sockets and make listeners push dummy (end) packets for writers @@ -1025,12 +1025,12 @@ void UDPStandardImplementation::closeFile(int i){ if(myFile[i]->Write()) //->Write(tall->GetName(),TObject::kOverwrite); - FILE_LOG(logINFO) << "Thread " << i <<": wrote frames to file"; + cout << "Thread " << i <<": wrote frames to file" << endl; else - FILE_LOG(logINFO) << "Thread " << i << ": could not write frames to file"; + cout << "Thread " << i << ": could not write frames to file" << endl; }else - FILE_LOG(logINFO) << "Thread " << i << ": could not write frames to file: No file or No Tree"; + cout << "Thread " << i << ": could not write frames to file: No file or No Tree" << endl; //close file if(myTree[i] && myFile[i]) myFile[i] = myTree[i]->GetCurrentFile(); @@ -1145,8 +1145,8 @@ int UDPStandardImplementation::createWriterThreads(bool destroy){ while(!threadStarted); FILE_LOG(logDEBUG) << "." << flush; } -#ifdef VERBOSE - FILE_LOG(logINFO) << "\nWriter thread(s) created successfully."; +#ifdef DEBUG + cout << "\nWriter thread(s) created successfully" << endl; #endif } @@ -1219,7 +1219,7 @@ int UDPStandardImplementation::createUDPSockets(){ } //normal socket else{ - FILE_LOG(logINFO) << "eth:" << eth << endl; + FILE_LOG(logINFO) << "Ethernet Interface:" << eth; for(int i=0;igetErrorStatus(); if(!iret){ - FILE_LOG(logINFO) << "UDP port opened at port " << port[i]; + cout << "UDP port opened at port " << port[i] << endl; }else{ FILE_LOG(logERROR) << "Could not create UDP socket on port " << port[i] << " error: " << iret; shutDownUDPSockets(); @@ -1238,7 +1238,7 @@ int UDPStandardImplementation::createUDPSockets(){ } FILE_LOG(logDEBUG) << "UDP socket(s) created successfully."; - FILE_LOG(logINFO) << "Listener Ready ..."; + cout << "Listener Ready ..." << endl; return OK; } @@ -1287,7 +1287,7 @@ int UDPStandardImplementation::setupWriter(){ } FILE_LOG(logDEBUG) << "Successfully created file(s)"; - FILE_LOG(logINFO) << "Writer Ready ..."; + cout << "Writer Ready ..." << endl; return fileCreateSuccess; } @@ -1338,9 +1338,9 @@ int UDPStandardImplementation::createNewFile(){ //Print packet loss and filenames if(!packetsCaught){ previousFrameNumber = -1; - FILE_LOG(logINFO) << "File: " << completeFileName; + cout << "File: " << completeFileName << endl; }else{ - FILE_LOG(logINFO) << completeFileName + cout << completeFileName << "\tPacket Loss: " << setw(4)< Date: Thu, 29 Oct 2015 17:38:31 +0100 Subject: [PATCH 50/68] done --- slsReceiverSoftware/src/UDPStandardImplementation.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/slsReceiverSoftware/src/UDPStandardImplementation.cpp b/slsReceiverSoftware/src/UDPStandardImplementation.cpp index cf8779e75..a55c3098a 100644 --- a/slsReceiverSoftware/src/UDPStandardImplementation.cpp +++ b/slsReceiverSoftware/src/UDPStandardImplementation.cpp @@ -850,7 +850,7 @@ int UDPStandardImplementation::startReceiver(char *c){ //usleep(5000000); cout << "Receiver Started" << endl; - cout << "Status:" << runStatusType(status) << endl; + cout << "Status: " << runStatusType(status) << endl; return OK; } @@ -883,7 +883,7 @@ void UDPStandardImplementation::stopReceiver(){ pthread_mutex_unlock(&(statusMutex)); cout << "Receiver Stopped" << endl; - cout << "Status:" << runStatusType(status) << endl; + cout << "Status: " << runStatusType(status) << endl; cout << endl; } @@ -1579,7 +1579,7 @@ void UDPStandardImplementation::stopListening(int ithread, int numbytes){ FILE_LOG(logDEBUG1) << __AT__ << " called"; #ifdef DEBUG4 - cprintf(BLUE,"Listening_Thread %d: Stop Listening\nStatus:%s\n", ithread, runStatusType(status).c_str()); + cprintf(BLUE,"Listening_Thread %d: Stop Listening\nStatus: %s\n", ithread, runStatusType(status).c_str()); #endif //less than 1 packet size (especially for eiger), ignore the buffer (so that 2 dummy buffers are not sent with pc=0) From 1c9d01ea1c01a72ee7b6e399d0bdb3f0203eb2e1 Mon Sep 17 00:00:00 2001 From: Dhanya Maliakal Date: Thu, 29 Oct 2015 17:39:47 +0100 Subject: [PATCH 51/68] done --- slsReceiverSoftware/src/UDPStandardImplementation.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/slsReceiverSoftware/src/UDPStandardImplementation.cpp b/slsReceiverSoftware/src/UDPStandardImplementation.cpp index a55c3098a..fffb38e87 100644 --- a/slsReceiverSoftware/src/UDPStandardImplementation.cpp +++ b/slsReceiverSoftware/src/UDPStandardImplementation.cpp @@ -884,7 +884,7 @@ void UDPStandardImplementation::stopReceiver(){ cout << "Receiver Stopped" << endl; cout << "Status: " << runStatusType(status) << endl; - cout << endl; + cout << endl << endl; } From 5c5e2edbf96d814d5740d441e73399aee8729260 Mon Sep 17 00:00:00 2001 From: Dhanya Maliakal Date: Thu, 29 Oct 2015 17:45:24 +0100 Subject: [PATCH 52/68] done --- slsReceiverSoftware/src/UDPStandardImplementation.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/slsReceiverSoftware/src/UDPStandardImplementation.cpp b/slsReceiverSoftware/src/UDPStandardImplementation.cpp index fffb38e87..fee4a16c0 100644 --- a/slsReceiverSoftware/src/UDPStandardImplementation.cpp +++ b/slsReceiverSoftware/src/UDPStandardImplementation.cpp @@ -2281,10 +2281,10 @@ void UDPStandardImplementation::stopWriting(int ithread, char* wbuffer[]){ //statistics cprintf(GREEN, "Status: Run Finished\n"); - if((long long int)(totalPacketsCaught/packetsPerFrame) == 0){ + if(numTotMissingPackets){ cprintf(RED, "Total Missing Packets padded: %d\n",numTotMissingPackets); cprintf(RED, "Total Packets Caught: %lld\n",(long long int)totalPacketsCaught); - cprintf(RED, "Total Frames Caught: 0\n"); + cprintf(RED, "Total Frames Caught: %lld\n",(long long int)(totalPacketsCaught/packetsPerFrame)); }else{ cprintf(GREEN, "Total Missing Packets padded: %d\n",numTotMissingPackets); cprintf(GREEN, "Total Packets Caught:%lld\n", (long long int)totalPacketsCaught); From f77b78b5c6a3c8615781641978ee75a9df7057cf Mon Sep 17 00:00:00 2001 From: Dhanya Maliakal Date: Mon, 2 Nov 2015 15:55:15 +0100 Subject: [PATCH 53/68] changes to compile server in defs file --- slsReceiverSoftware/include/sls_receiver_defs.h | 5 ++++- slsReceiverSoftware/src/UDPStandardImplementation.cpp | 5 +++-- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/slsReceiverSoftware/include/sls_receiver_defs.h b/slsReceiverSoftware/include/sls_receiver_defs.h index 04f647f0a..07566ab84 100755 --- a/slsReceiverSoftware/include/sls_receiver_defs.h +++ b/slsReceiverSoftware/include/sls_receiver_defs.h @@ -8,7 +8,9 @@ #endif #include +#ifdef __cplusplus #include +#endif #include "ansi.h" @@ -112,7 +114,7 @@ public: RUNNING /**< acquisition running, no data in memory */ }; - +#ifdef __cplusplus /** returns string from enabled/disabled \param b true or false \returns string enabled, disabled @@ -172,6 +174,7 @@ public: default: return std::string("idle"); \ }}; +#endif #ifdef __cplusplus protected: diff --git a/slsReceiverSoftware/src/UDPStandardImplementation.cpp b/slsReceiverSoftware/src/UDPStandardImplementation.cpp index fee4a16c0..2bafb96b1 100644 --- a/slsReceiverSoftware/src/UDPStandardImplementation.cpp +++ b/slsReceiverSoftware/src/UDPStandardImplementation.cpp @@ -43,10 +43,11 @@ UDPStandardImplementation::UDPStandardImplementation(){ //to increase socket receiver buffer size and max length of input queue by changing kernel settings if(myDetectorType == EIGER); - else if(system("echo $((100*1024*1024)) > /proc/sys/net/core/rmem_max")) + else if(system("echo $((100*1024*1024)) > /proc/sys/net/core/rmem_max")){ FILE_LOG(logDEBUG) << "Warning: No root permission to change socket receiver buffer size in file /proc/sys/net/core/rmem_max"; - else if(system("echo 250000 > /proc/sys/net/core/netdev_max_backlog")) + }else if(system("echo 250000 > /proc/sys/net/core/netdev_max_backlog")){ FILE_LOG(logDEBUG) << "Warning: No root permission to change max length of input queue in file /proc/sys/net/core/netdev_max_backlog"; + } /** permanent setting by heiner net.core.rmem_max = 104857600 # 100MiB net.core.netdev_max_backlog = 250000 From e9f51e2ef59dd2b231c0a38952c4b30adf0c6349 Mon Sep 17 00:00:00 2001 From: Dhanya Maliakal Date: Mon, 2 Nov 2015 17:33:10 +0100 Subject: [PATCH 54/68] put in the changes by Andrea to make it as static and remove as many destructors bugs --- .../include/slsReceiverTCPIPInterface.h | 3 -- .../include/slsReceiverUsers.h | 4 +- .../src/UDPStandardImplementation.cpp | 9 ++-- slsReceiverSoftware/src/main.cpp | 38 +++++++++-------- slsReceiverSoftware/src/slsReceiver.cpp | 6 ++- .../src/slsReceiverTCPIPInterface.cpp | 42 ++----------------- slsReceiverSoftware/src/slsReceiverUsers.cpp | 20 ++++----- 7 files changed, 46 insertions(+), 76 deletions(-) diff --git a/slsReceiverSoftware/include/slsReceiverTCPIPInterface.h b/slsReceiverSoftware/include/slsReceiverTCPIPInterface.h index 83d9416aa..49e5134f1 100644 --- a/slsReceiverSoftware/include/slsReceiverTCPIPInterface.h +++ b/slsReceiverSoftware/include/slsReceiverTCPIPInterface.h @@ -54,9 +54,6 @@ class slsReceiverTCPIPInterface : private virtual slsReceiverDefs { /** Close all threaded Files and exit */ void closeFile(int p); - /** Static function to call closeFile */ - static void staticCloseFile(int p); - /** gets version */ int64_t getReceiverVersion(); diff --git a/slsReceiverSoftware/include/slsReceiverUsers.h b/slsReceiverSoftware/include/slsReceiverUsers.h index 50d6f38fe..eea403560 100644 --- a/slsReceiverSoftware/include/slsReceiverUsers.h +++ b/slsReceiverSoftware/include/slsReceiverUsers.h @@ -83,8 +83,8 @@ public: void registerCallBackRawDataReady(void (*func)(int framenumber, char* datapointer, int datasize, FILE* filedescriptor, char* guidatapointer, void*),void *arg); - // made static to close thread files with ctrl+c - static slsReceiver* receiver; + //receiver object + slsReceiver* receiver; }; diff --git a/slsReceiverSoftware/src/UDPStandardImplementation.cpp b/slsReceiverSoftware/src/UDPStandardImplementation.cpp index 2bafb96b1..6149f0c10 100644 --- a/slsReceiverSoftware/src/UDPStandardImplementation.cpp +++ b/slsReceiverSoftware/src/UDPStandardImplementation.cpp @@ -60,7 +60,7 @@ UDPStandardImplementation::UDPStandardImplementation(){ UDPStandardImplementation::~UDPStandardImplementation(){ FILE_LOG(logDEBUG1) << __AT__ << " called"; - + closeFile(); deleteMembers(); } @@ -1184,9 +1184,9 @@ void UDPStandardImplementation::setThreadPriorities(){ if (pthread_setschedparam(pthread_self(),5 , &tcp_param) == EPERM) rights = false; - if(!rights) + if(!rights){ FILE_LOG(logWARNING) << "No root permission to prioritize threads."; - + } } @@ -1256,8 +1256,9 @@ int UDPStandardImplementation::setupWriter(){ if(cbAction < DO_EVERYTHING){ FILE_LOG(logINFO) << "Call back activated. Data saving must be taken care of by user in call back."; - if (rawDataReadyCallBack) + if (rawDataReadyCallBack){ FILE_LOG(logINFO) << "Data Write has been defined externally"; + } }else if(!fileWriteEnable) FILE_LOG(logINFO) << "Data will not be saved"; diff --git a/slsReceiverSoftware/src/main.cpp b/slsReceiverSoftware/src/main.cpp index 53a8bd110..1dc9a65c6 100644 --- a/slsReceiverSoftware/src/main.cpp +++ b/slsReceiverSoftware/src/main.cpp @@ -6,25 +6,38 @@ #include #include +#include //SIGINT #include "utilities.h" #include "logger.h" - using namespace std; +slsReceiverUsers *receiver; + +void deleteReceiver(slsReceiverUsers* r){ + if(r){delete r;r=0;} +} + +void closeFile(int p){ + deleteReceiver(receiver); +} int main(int argc, char *argv[]) { + + //Catch signal SIGINT to close files properly + signal(SIGINT,closeFile); + int ret = slsReceiverDefs::OK; + receiver = new slsReceiverUsers(argc, argv, ret); - slsReceiverUsers *user = new slsReceiverUsers(argc, argv, ret); - - if(ret==slsReceiverDefs::FAIL) + if(ret==slsReceiverDefs::FAIL){ + deleteReceiver(receiver); return -1; + } //register callbacks - /** callback arguments are filepath @@ -37,10 +50,8 @@ int main(int argc, char *argv[]) { 1 callback writes file, we have to open, close it 2 we open, close, write file, callback does not do anything - registerCallBackStartAcquisition(int (*func)(char*, char*,int, int, void*),void *arg); */ - //receiver->registerCallBackStartAcquisition(func,arg); @@ -49,32 +60,25 @@ int main(int argc, char *argv[]) { total farmes caught registerCallBackAcquisitionFinished(void (*func)(int, void*),void *arg); */ - - //receiver->registerCallBackAcquisitionFinished(func,arg); - /** args to raw data ready callback are framenum datapointer file descriptor guidatapointer (NULL, no data required) - NEVER DELETE THE DATA POINTER REMEMBER THAT THE CALLBACK IS BLOCKING - registerCallBackRawDataReady(void (*func)(int, char*, FILE*, char*, void*),void *arg); - */ - //receiver->registerCallBackRawDataReady(func,arg); //start tcp server thread - if(user->start() == slsReceiverDefs::OK){ + if(receiver->start() == slsReceiverDefs::OK){ FILE_LOG(logDEBUG1) << "DONE!" << endl; string str; cin>>str; @@ -82,10 +86,10 @@ int main(int argc, char *argv[]) { while(str.find("exit") == string::npos) cin>>str; //stop tcp server thread, stop udp socket - user->stop(); + receiver->stop(); } - delete user; + deleteReceiver(receiver); cout << "Goodbye!" << endl; return 0; } diff --git a/slsReceiverSoftware/src/slsReceiver.cpp b/slsReceiverSoftware/src/slsReceiver.cpp index 5783e601c..f23da65c5 100644 --- a/slsReceiverSoftware/src/slsReceiver.cpp +++ b/slsReceiverSoftware/src/slsReceiver.cpp @@ -29,6 +29,9 @@ slsReceiver::slsReceiver(int argc, char *argv[], int &success){ * @return */ + udp_interface = NULL; + tcpipInterface = NULL; + //creating base receiver map configuration_map; int tcpip_port_no = 1954; @@ -55,7 +58,8 @@ slsReceiver::slsReceiver(int argc, char *argv[], int &success){ }; /* getopt_long stores the option index here. */ int option_index = 0; - int c; + int c=0; + optind = 1; while ( c != -1 ){ c = getopt_long (argc, argv, "mbfhtr", long_options, &option_index); diff --git a/slsReceiverSoftware/src/slsReceiverTCPIPInterface.cpp b/slsReceiverSoftware/src/slsReceiverTCPIPInterface.cpp index d7e562f76..24ba62d99 100644 --- a/slsReceiverSoftware/src/slsReceiverTCPIPInterface.cpp +++ b/slsReceiverSoftware/src/slsReceiverTCPIPInterface.cpp @@ -9,10 +9,7 @@ #include "slsReceiverUsers.h" #include "slsReceiver.h" - -#include //SIGINT #include //EXIT - #include #include #include @@ -27,9 +24,8 @@ using namespace std; slsReceiverTCPIPInterface::~slsReceiverTCPIPInterface() { - closeFile(0); + stop(); if(socket) {delete socket; socket=NULL;} - if(receiverBase) {delete receiverBase; receiverBase=NULL;} } slsReceiverTCPIPInterface::slsReceiverTCPIPInterface(int &success, UDPInterface* rbase, int pn, bool bot): @@ -71,9 +67,6 @@ slsReceiverTCPIPInterface::slsReceiverTCPIPInterface(int &success, UDPInterface* #ifdef VERBOSE cout << "Function table assigned." << endl; #endif - - //Catch signal SIGINT to close files properly - signal(SIGINT,staticCloseFile); } } @@ -139,34 +132,13 @@ int slsReceiverTCPIPInterface::start(){ void slsReceiverTCPIPInterface::stop(){ - cout << "Shutting down UDP Socket" << endl; - if(receiverBase) - receiverBase->shutDownUDPSockets(); - - cout << "Closing Files... " << endl; - receiverBase->closeFile(); - - - cout<<"Shutting down TCP Socket and TCP thread"<shutDownUDPSockets(); - - cout << "Closing Files... " << endl; - receiverBase->closeFile(); - } - - killTCPServerThread = 1; - socket->ShutDownSocket(); - socket->exitServer(); + if(socket) socket->ShutDownSocket(); cout<<"Socket closed"<closeFile(p); + receiverBase->closeFile(); } diff --git a/slsReceiverSoftware/src/slsReceiverUsers.cpp b/slsReceiverSoftware/src/slsReceiverUsers.cpp index c27f1efc2..8a1d17f43 100644 --- a/slsReceiverSoftware/src/slsReceiverUsers.cpp +++ b/slsReceiverSoftware/src/slsReceiverUsers.cpp @@ -1,47 +1,45 @@ #include "slsReceiverUsers.h" #include "slsReceiver.h" -slsReceiver* slsReceiverUsers::receiver(NULL); - slsReceiverUsers::slsReceiverUsers(int argc, char *argv[], int &success) { - slsReceiverUsers::receiver=new slsReceiver(argc, argv, success); + receiver=new slsReceiver(argc, argv, success); } slsReceiverUsers::~slsReceiverUsers() { - delete slsReceiverUsers::receiver; + delete receiver; } int slsReceiverUsers::start() { - return slsReceiverUsers::receiver->start(); + return receiver->start(); } void slsReceiverUsers::stop() { - slsReceiverUsers::receiver->stop(); + receiver->stop(); } void slsReceiverUsers::closeFile(int p) { - slsReceiverUsers::receiver->closeFile(p); + receiver->closeFile(p); } int64_t slsReceiverUsers::getReceiverVersion(){ - return slsReceiverUsers::receiver->getReceiverVersion(); + return receiver->getReceiverVersion(); } void slsReceiverUsers::registerCallBackStartAcquisition(int (*func)(char*, char*,int, int, void*),void *arg){ - slsReceiverUsers::receiver->registerCallBackStartAcquisition(func,arg); + receiver->registerCallBackStartAcquisition(func,arg); } void slsReceiverUsers::registerCallBackAcquisitionFinished(void (*func)(int, void*),void *arg){ - slsReceiverUsers::receiver->registerCallBackAcquisitionFinished(func,arg); + receiver->registerCallBackAcquisitionFinished(func,arg); } void slsReceiverUsers::registerCallBackRawDataReady(void (*func)(int, char*, int, FILE*, char*, void*),void *arg){ - slsReceiverUsers::receiver->registerCallBackRawDataReady(func,arg); + receiver->registerCallBackRawDataReady(func,arg); } From 667c1c0304aa284f432274405e8470ac2eb2bb9a Mon Sep 17 00:00:00 2001 From: Dhanya Maliakal Date: Thu, 5 Nov 2015 12:05:31 +0100 Subject: [PATCH 55/68] some small changes --- .../src/UDPStandardImplementation.cpp | 115 ++++++++++-------- .../src/slsReceiverTCPIPInterface.cpp | 68 +++++------ 2 files changed, 98 insertions(+), 85 deletions(-) diff --git a/slsReceiverSoftware/src/UDPStandardImplementation.cpp b/slsReceiverSoftware/src/UDPStandardImplementation.cpp index 6149f0c10..86e533efa 100644 --- a/slsReceiverSoftware/src/UDPStandardImplementation.cpp +++ b/slsReceiverSoftware/src/UDPStandardImplementation.cpp @@ -31,7 +31,7 @@ using namespace std; *************************************************************************/ UDPStandardImplementation::UDPStandardImplementation(){ - FILE_LOG(logDEBUG1) << __AT__ << " called"; + FILE_LOG(logDEBUG) << __AT__ << " called"; initializeMembers(); @@ -59,7 +59,7 @@ UDPStandardImplementation::UDPStandardImplementation(){ } UDPStandardImplementation::~UDPStandardImplementation(){ - FILE_LOG(logDEBUG1) << __AT__ << " called"; + FILE_LOG(logDEBUG) << __AT__ << " called"; closeFile(); deleteMembers(); } @@ -73,7 +73,7 @@ UDPStandardImplementation::~UDPStandardImplementation(){ /***initial parameters***/ void UDPStandardImplementation::deleteMembers(){ - FILE_LOG(logDEBUG1) << __AT__ << " starting"; + FILE_LOG(logDEBUG) << __AT__ << " starting"; FILE_LOG(logDEBUG) << "Info: Deleting member pointers"; shutDownUDPSockets(); @@ -95,7 +95,7 @@ void UDPStandardImplementation::deleteMembers(){ } void UDPStandardImplementation::deleteFilter(){ - FILE_LOG(logDEBUG1) << __AT__ << " starting"; + FILE_LOG(logDEBUG) << __AT__ << " starting"; moenchCommonModeSubtraction = NULL; for(int i=0; i config_map){ - FILE_LOG(logDEBUG1) << __AT__ << " starting"; + FILE_LOG(logDEBUG) << __AT__ << " starting"; map::const_iterator pos; pos = config_map.find("mode"); @@ -375,7 +375,7 @@ void UDPStandardImplementation::configure(map config_map){ /***file parameters***/ int UDPStandardImplementation::setDataCompressionEnable(const bool b){ - FILE_LOG(logDEBUG1) << __AT__ << " starting"; + FILE_LOG(logDEBUG) << __AT__ << " starting"; if(myDetectorType != EIGER){ cout << "Info: Setting up Data Compression Enable to " << stringEnable(b); @@ -419,7 +419,7 @@ int UDPStandardImplementation::setDataCompressionEnable(const bool b){ /***acquisition parameters***/ void UDPStandardImplementation::setShortFrameEnable(const int i){ - FILE_LOG(logDEBUG1) << __AT__ << " called"; + FILE_LOG(logDEBUG) << __AT__ << " called"; shortFrameEnable = i; @@ -456,7 +456,7 @@ void UDPStandardImplementation::setShortFrameEnable(const int i){ int UDPStandardImplementation::setFrameToGuiFrequency(const uint32_t i){ - FILE_LOG(logDEBUG1) << __AT__ << " called"; + FILE_LOG(logDEBUG) << __AT__ << " called"; FrameToGuiFrequency = i; if(setupFifoStructure() == FAIL) @@ -469,7 +469,7 @@ int UDPStandardImplementation::setFrameToGuiFrequency(const uint32_t i){ int UDPStandardImplementation::setAcquisitionPeriod(const uint64_t i){ - FILE_LOG(logDEBUG1) << __AT__ << " called"; + FILE_LOG(logDEBUG) << __AT__ << " called"; acquisitionPeriod = i; if(setupFifoStructure() == FAIL) @@ -482,7 +482,7 @@ int UDPStandardImplementation::setAcquisitionPeriod(const uint64_t i){ } int UDPStandardImplementation::setDynamicRange(const uint32_t i){ - FILE_LOG(logDEBUG1) << __AT__ << " called"; + FILE_LOG(logDEBUG) << __AT__ << " called"; uint32_t oldDynamicRange = dynamicRange; @@ -536,7 +536,7 @@ int UDPStandardImplementation::setDynamicRange(const uint32_t i){ int UDPStandardImplementation::setTenGigaEnable(const bool b){ - FILE_LOG(logDEBUG1) << __AT__ << " called"; + FILE_LOG(logDEBUG) << __AT__ << " called"; FILE_LOG(logDEBUG) << "Info: Setting Ten Giga to " << stringEnable(b); bool oldTenGigaEnable = tengigaEnable; @@ -618,7 +618,7 @@ int UDPStandardImplementation::setTenGigaEnable(const bool b){ /***initial functions***/ int UDPStandardImplementation::setDetectorType(const detectorType d){ - FILE_LOG(logDEBUG1) << __AT__ << " called"; + FILE_LOG(logDEBUG) << __AT__ << " called"; FILE_LOG(logDEBUG) << "Setting receiver type"; @@ -751,7 +751,7 @@ int UDPStandardImplementation::setDetectorType(const detectorType d){ /***acquisition functions***/ void UDPStandardImplementation::resetAcquisitionCount(){ - FILE_LOG(logDEBUG1) << __AT__ << " starting"; + FILE_LOG(logDEBUG) << __AT__ << " starting"; totalPacketsCaught = 0; acqStarted = false; @@ -762,7 +762,7 @@ void UDPStandardImplementation::resetAcquisitionCount(){ int UDPStandardImplementation::startReceiver(char *c){ - FILE_LOG(logDEBUG1) << __AT__ << " called"; + FILE_LOG(logDEBUG) << __AT__ << " called"; cout << "Starting Receiver" << endl; @@ -862,7 +862,7 @@ int UDPStandardImplementation::startReceiver(char *c){ * Post: udp sockets shut down, status is idle, semaphores destroyed * */ void UDPStandardImplementation::stopReceiver(){ - FILE_LOG(logDEBUG1) << __AT__ << " called"; + FILE_LOG(logDEBUG) << __AT__ << " called"; cout << "Stopping Receiver" << endl; @@ -893,7 +893,7 @@ void UDPStandardImplementation::stopReceiver(){ int UDPStandardImplementation::shutDownUDPSockets(){ - FILE_LOG(logDEBUG1) << __AT__ << " called"; + FILE_LOG(logDEBUG) << __AT__ << " called"; FILE_LOG(logDEBUG) << "Info: Shutting down UDP Socket(s)"; @@ -915,7 +915,7 @@ int UDPStandardImplementation::shutDownUDPSockets(){ * Post:udp sockets closed, status is transmitting * */ void UDPStandardImplementation::startReadout(){ - FILE_LOG(logDEBUG1) << __AT__ << " called"; + FILE_LOG(logDEBUG) << __AT__ << " called"; FILE_LOG(logDEBUG) << "Info: Transmitting last data"; @@ -943,7 +943,7 @@ void UDPStandardImplementation::startReadout(){ void UDPStandardImplementation::readFrame(char* c,char** raw, uint64_t &startAcq, uint64_t &startFrame){ - FILE_LOG(logDEBUG1) << __AT__ << " called"; + FILE_LOG(logDEBUG) << __AT__ << " called"; //point to gui data, to let writer thread know that gui is back for data if (guiData == NULL){ @@ -993,7 +993,7 @@ void UDPStandardImplementation::readFrame(char* c,char** raw, uint64_t &startAcq void UDPStandardImplementation::closeFile(int i){ - FILE_LOG(logDEBUG1) << __AT__ << " called for " << i ; + FILE_LOG(logDEBUG) << __AT__ << " called for " << i ; //normal if(!dataCompressionEnable){ @@ -1054,7 +1054,7 @@ void UDPStandardImplementation::closeFile(int i){ int UDPStandardImplementation::createListeningThreads(bool destroy){ - FILE_LOG(logDEBUG1) << __AT__ << " starting"; + FILE_LOG(logDEBUG) << __AT__ << " starting"; //reset masks killAllListeningThreads = false; @@ -1104,7 +1104,7 @@ int UDPStandardImplementation::createListeningThreads(bool destroy){ int UDPStandardImplementation::createWriterThreads(bool destroy){ - FILE_LOG(logDEBUG1) << __AT__ << " starting"; + FILE_LOG(logDEBUG) << __AT__ << " starting"; //reset masks killAllWritingThreads = false; @@ -1157,7 +1157,7 @@ int UDPStandardImplementation::createWriterThreads(bool destroy){ void UDPStandardImplementation::setThreadPriorities(){ - FILE_LOG(logDEBUG1) << __AT__ << " called"; + FILE_LOG(logDEBUG) << __AT__ << " called"; struct sched_param tcp_param, listen_param, write_param; bool rights = true; @@ -1193,7 +1193,7 @@ void UDPStandardImplementation::setThreadPriorities(){ int UDPStandardImplementation::createUDPSockets(){ - FILE_LOG(logDEBUG1) << __AT__ << " called"; + FILE_LOG(logDEBUG) << __AT__ << " called"; //switching ports if bottom enabled uint32_t port[2]; @@ -1247,7 +1247,7 @@ int UDPStandardImplementation::createUDPSockets(){ int UDPStandardImplementation::setupWriter(){ - FILE_LOG(logDEBUG1) << __AT__ << " starting"; + FILE_LOG(logDEBUG) << __AT__ << " starting"; //acquisition start call back returns enable write cbAction = DO_EVERYTHING; @@ -1297,7 +1297,7 @@ int UDPStandardImplementation::setupWriter(){ int UDPStandardImplementation::createNewFile(){ - FILE_LOG(logDEBUG1) << __AT__ << " called"; + FILE_LOG(logDEBUG) << __AT__ << " called"; int index = 0; if(packetsCaught) @@ -1370,7 +1370,7 @@ int UDPStandardImplementation::createNewFile(){ int UDPStandardImplementation::createCompressionFile(int ithread, int iframe){ - FILE_LOG(logDEBUG1) << __AT__ << " called"; + FILE_LOG(logDEBUG) << __AT__ << " called"; #ifdef MYROOT1 char temp[MAX_STR_LENGTH]; @@ -1400,7 +1400,7 @@ int UDPStandardImplementation::createCompressionFile(int ithread, int iframe){ void* UDPStandardImplementation::startListeningThread(void* this_pointer){ - FILE_LOG(logDEBUG1) << __AT__ << " called"; + FILE_LOG(logDEBUG) << __AT__ << " called"; ((UDPStandardImplementation*)this_pointer)->startListening(); return this_pointer; } @@ -1408,7 +1408,7 @@ void* UDPStandardImplementation::startListeningThread(void* this_pointer){ void* UDPStandardImplementation::startWritingThread(void* this_pointer){ - FILE_LOG(logDEBUG1) << __AT__ << " called"; + FILE_LOG(logDEBUG) << __AT__ << " called"; ((UDPStandardImplementation*)this_pointer)->startWriting(); return this_pointer; } @@ -1419,7 +1419,7 @@ void* UDPStandardImplementation::startWritingThread(void* this_pointer){ void UDPStandardImplementation::startListening(){ - FILE_LOG(logDEBUG1) << __AT__ << " called"; + FILE_LOG(logDEBUG) << __AT__ << " called"; //set current thread value index int ithread = currentThreadIndex; @@ -1433,16 +1433,18 @@ void UDPStandardImplementation::startListening(){ //split frames int carryonBufferSize; //from previous buffer to keep frames together in a buffer char* tempBuffer = NULL; //temporary buffer to store split frames - if(myDetectorType != EIGER){ - listenSize = bufferSize * numberofJobsPerBuffer; //listen to more than 1 packet - tempBuffer = new char[onePacketSize * (packetsPerFrame - 1)]; //store maximum of 1 packets less in a frame - } + /* outer loop - loops once for each acquisition */ //infinite loop, exited only to change dynamic range, 10G parameters etc (then recreated again) while(true){ //reset parameters before acquisition carryonBufferSize = 0; + if(myDetectorType != EIGER){ + listenSize = bufferSize * numberofJobsPerBuffer; //listen to more than 1 packet + if(tempBuffer!=NULL){delete []tempBuffer;tempBuffer=NULL;} + tempBuffer = new char[onePacketSize * (packetsPerFrame - 1)]; //store maximum of 1 packets less in a frame + } /* inner loop - loop for each buffer */ //until mask unset (udp sockets shut down by client) @@ -1512,7 +1514,7 @@ void UDPStandardImplementation::startListening(){ int UDPStandardImplementation::prepareAndListenBuffer(int ithread, int lSize, int cSize, char* temp){ - FILE_LOG(logDEBUG1) << __AT__ << " called"; + FILE_LOG(logDEBUG) << __AT__ << " called"; //listen to UDP packets memcpy(buffer[ithread] + HEADER_SIZE_NUM_TOT_PACKETS, temp, cSize); @@ -1529,6 +1531,17 @@ int UDPStandardImplementation::prepareAndListenBuffer(int ithread, int lSize, in receivedSize = udpSocket[ithread]->ReceiveDataOnly(buffer[ithread] + HEADER_SIZE_NUM_TOT_PACKETS); } +#ifdef MANUALDEBUG + eiger_packet_header_t* header = (eiger_packet_header_t*) (buffer[ithread]+HEADER_SIZE_NUM_TOT_PACKETS); + eiger_packet_footer_t* footer = (eiger_packet_footer_t*)(buffer[ithread] + footerOffset + HEADER_SIZE_NUM_TOT_PACKETS); + cprintf(GREEN,"thread:%d subframenum:%d oldpacketnum:%d new pnum:%d\n", + ithread, + (*( (unsigned int*) header->subFameNumber)), + (*( (uint8_t*) header->dynamicRange)), + (*( (uint16_t*) footer->packetNumber))); +#endif + + #ifdef DEBUG cprintf(BLUE, "Listening_Thread %d : Received bytes: %d. Expected bytes: %d\n", ithread, receivedSize, bufferSize * numberofJobsPerBuffer-cSize); #endif @@ -1541,7 +1554,7 @@ int UDPStandardImplementation::prepareAndListenBuffer(int ithread, int lSize, in void UDPStandardImplementation::startFrameIndices(int ithread){ - FILE_LOG(logDEBUG1) << __AT__ << " called"; + FILE_LOG(logDEBUG) << __AT__ << " called"; //determine startFrameIndex switch(myDetectorType){ @@ -1578,7 +1591,7 @@ void UDPStandardImplementation::startFrameIndices(int ithread){ void UDPStandardImplementation::stopListening(int ithread, int numbytes){ - FILE_LOG(logDEBUG1) << __AT__ << " called"; + FILE_LOG(logDEBUG) << __AT__ << " called"; #ifdef DEBUG4 cprintf(BLUE,"Listening_Thread %d: Stop Listening\nStatus: %s\n", ithread, runStatusType(status).c_str()); @@ -1657,7 +1670,7 @@ void UDPStandardImplementation::stopListening(int ithread, int numbytes){ uint32_t UDPStandardImplementation::processListeningBuffer(int ithread, int cSize, char* temp){ - FILE_LOG(logDEBUG1) << __AT__ << " called"; + FILE_LOG(logDEBUG) << __AT__ << " called"; int lastPacketOffset; //the offset of the last packet uint32_t lastFrameHeader; //frame number of last packet in buffer @@ -1741,7 +1754,7 @@ uint32_t UDPStandardImplementation::processListeningBuffer(int ithread, int cSiz void UDPStandardImplementation::startWriting(){ - FILE_LOG(logDEBUG1) << __AT__ << " called"; + FILE_LOG(logDEBUG) << __AT__ << " called"; //set current thread value index int ithread = currentThreadIndex; @@ -1762,7 +1775,7 @@ void UDPStandardImplementation::startWriting(){ void UDPStandardImplementation::processWritingBuffer(int ithread){ - FILE_LOG(logDEBUG1) << __AT__ << " called"; + FILE_LOG(logDEBUG) << __AT__ << " called"; //variable definitions char* wbuf[numberofListeningThreads]; //buffer popped from FIFO @@ -1829,7 +1842,7 @@ void UDPStandardImplementation::processWritingBuffer(int ithread){ void UDPStandardImplementation::processWritingBufferPacketByPacket(int ithread){ - FILE_LOG(logDEBUG1) << __AT__ << " called"; + FILE_LOG(logDEBUG) << __AT__ << " called"; //variable definitions char* packetBuffer[numberofListeningThreads]; //buffer popped from FIFO @@ -2133,7 +2146,7 @@ void UDPStandardImplementation::processWritingBufferPacketByPacket(int ithread){ void UDPStandardImplementation::waitWritingBufferForNextAcquisition(int ithread){ - FILE_LOG(logDEBUG1) << __AT__ << " called"; + FILE_LOG(logDEBUG) << __AT__ << " called"; //in case they are not closed already closeFile(); @@ -2190,7 +2203,7 @@ void UDPStandardImplementation::waitWritingBufferForNextAcquisition(int ithread) bool UDPStandardImplementation::popAndCheckEndofAcquisition(int ithread, char* wbuffer[], bool ready[], uint32_t nP[],char* toFree[],int toFreeOffset[]){ - FILE_LOG(logDEBUG1) << __AT__ << " called"; + FILE_LOG(logDEBUG) << __AT__ << " called"; bool endofAcquisition = true; for(int i=0; ithisClientIP,"none1"); strcpy(mess,"dummy message"); function_table(); -#ifdef VERBOSE +#ifdef VERYVERBOSE cout << "Function table assigned." << endl; #endif } @@ -124,7 +124,7 @@ int slsReceiverTCPIPInterface::start(){ cout << "Could not create TCP Server thread" << endl; return FAIL; } - //#ifdef VERBOSE + //#ifdef VERYVERBOSE FILE_LOG(logDEBUG) << "TCP Server thread created successfully." << endl; //#endif return OK; @@ -160,7 +160,7 @@ void slsReceiverTCPIPInterface::startTCPServer(){ int v=OK; while(1) { -#ifdef VERBOSE +#ifdef VERYVERBOSE cout<< endl; #endif #ifdef VERY_VERBOSE @@ -254,7 +254,7 @@ int slsReceiverTCPIPInterface::function_table(){ flist[F_ENABLE_RECEIVER_TEN_GIGA] = &slsReceiverTCPIPInterface::enable_tengiga; -#ifdef VERBOSE +#ifdef VERYVERBOSE for (int i=0;iReceiveDataOnly(&fnum,sizeof(fnum)); if (n <= 0) { -#ifdef VERBOSE +#ifdef VERYVERBOSE cout << "ERROR reading from socket " << n << ", " << fnum << endl; #endif return FAIL; } -#ifdef VERBOSE +#ifdef VERYVERBOSE else cout << "size of data received " << n <> GOTTHARD_SHORT_FRAME_INDEX_OFFSET); -#ifdef VERBOSE +#ifdef VERYVERBOSE cout << "index:" << hex << index << endl; #endif }else{ @@ -1336,7 +1336,7 @@ int slsReceiverTCPIPInterface::gotthard_read_frame(){ bindex2 = ((uint32_t)(*((uint32_t*)((char*)(raw+onebuffersize)))))+1; pindex2 =(bindex2 & GOTTHARD_PACKET_INDEX_MASK); index2 =((bindex2 & GOTTHARD_FRAME_INDEX_MASK) >> GOTTHARD_FRAME_INDEX_OFFSET); -#ifdef VERBOSE +#ifdef VERYVERBOSE cout << "index1:" << hex << index << endl; cout << "index2:" << hex << index << endl; #endif @@ -1398,7 +1398,7 @@ int slsReceiverTCPIPInterface::gotthard_read_frame(){ } } -#ifdef VERBOSE +#ifdef VERYVERBOSE if(frameIndex!=-1){ cout << "fName:" << fName << endl; cout << "acquisitionIndex:" << acquisitionIndex << endl; @@ -1493,7 +1493,7 @@ int slsReceiverTCPIPInterface::propix_read_frame(){ /**send garbage with -1 index to try again*/ if (raw == NULL){ startAcquisitionIndex = -1; -#ifdef VERBOSE +#ifdef VERYVERBOSE cout<<"data not ready for gui yet"<> PROPIX_FRAME_INDEX_OFFSET); -#ifdef VERBOSE +#ifdef VERYVERBOSE cout << "index1:" << hex << index << endl; cout << "index2:" << hex << index << endl; #endif @@ -1552,7 +1552,7 @@ int slsReceiverTCPIPInterface::propix_read_frame(){ } } -#ifdef VERBOSE +#ifdef VERYVERBOSE if(frameIndex!=-1){ cout << "fName:" << fName << endl; cout << "acquisitionIndex:" << acquisitionIndex << endl; @@ -1652,7 +1652,7 @@ int slsReceiverTCPIPInterface::eiger_read_frame(){ /**send garbage with -1 index to try again*/ else if(!receiverBase->getFramesCaught()){ startAcquisitionIndex=-1; -#ifdef VERBOSE +#ifdef VERYVERBOSE cout<<"haven't caught any frame yet"<subframenum); } -#ifdef VERBOSE +#ifdef VERYVERBOSE cout << "index:" << dec << index << endl; cout << "subframenumber:" << dec << subframenumber << endl; #endif @@ -1813,7 +1813,7 @@ int slsReceiverTCPIPInterface::eiger_read_frame(){ } } -#ifdef VERBOSE +#ifdef VERYVERBOSE if(frameIndex!=-1){ cout << "fName:" << fName << endl; cout << "acquisitionIndex:" << acquisitionIndex << endl; @@ -2093,7 +2093,7 @@ int slsReceiverTCPIPInterface::set_timer() { ret = FAIL; } } -#ifdef VERBOSE +#ifdef VERYVERBOSE if(ret!=FAIL){ if(index[0] == FRAME_PERIOD) cout << "acquisition period:" << retval << endl; @@ -2228,7 +2228,7 @@ int slsReceiverTCPIPInterface::set_detector_hostname() { } } } -#ifdef VERBOSE +#ifdef VERYVERBOSE if(ret!=FAIL) cout << "hostname:" << retval << endl; else @@ -2320,7 +2320,7 @@ int slsReceiverTCPIPInterface::set_dynamic_range() { } } } -#ifdef VERBOSE +#ifdef VERYVERBOSE if(ret!=FAIL) cout << "dynamic range" << dr << endl; else @@ -2383,7 +2383,7 @@ int slsReceiverTCPIPInterface::enable_overwrite() { ret = FAIL; } } -#ifdef VERBOSE +#ifdef VERYVERBOSE if(ret!=FAIL) cout << "overwrite:" << retval << endl; else @@ -2448,7 +2448,7 @@ int slsReceiverTCPIPInterface::enable_tengiga() { tenGigaEnable = retval; } } -#ifdef VERBOSE +#ifdef VERYVERBOSE if(ret!=FAIL) cout << "10Gbe:" << val << endl; else @@ -2749,7 +2749,7 @@ int slsReceiverTCPIPInterface::exec_command() { // execute action if the arguments correctly arrived if (ret==OK) { -#ifdef VERBOSE +#ifdef VERYVERBOSE cout << "executing command " << cmd << endl; #endif if (lockStatus==0 || socket->differentClients==0) From 98ab99c53f744a44c7a6417c6f7c5f1f073ef441 Mon Sep 17 00:00:00 2001 From: Dhanya Maliakal Date: Fri, 6 Nov 2015 11:23:50 +0100 Subject: [PATCH 56/68] fixed a bug of both threads not popping out(due to wrong frame packet) and end of acquisition wrongly inferred --- slsReceiverSoftware/src/UDPStandardImplementation.cpp | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/slsReceiverSoftware/src/UDPStandardImplementation.cpp b/slsReceiverSoftware/src/UDPStandardImplementation.cpp index 86e533efa..12a176777 100644 --- a/slsReceiverSoftware/src/UDPStandardImplementation.cpp +++ b/slsReceiverSoftware/src/UDPStandardImplementation.cpp @@ -2244,6 +2244,11 @@ bool UDPStandardImplementation::popAndCheckEndofAcquisition(int ithread, char* w } } } + //when both are not popped but curretn frame number is being processed + else{ + if(nP[i] != dummyPacketValue) + endofAcquisition = false; + } } return endofAcquisition; From 455c9c5c8084a5159bfdeac345bd8262d7ef5a50 Mon Sep 17 00:00:00 2001 From: Dhanya Maliakal Date: Mon, 9 Nov 2015 17:16:24 +0100 Subject: [PATCH 57/68] some changes for memory leak --- .../src/UDPStandardImplementation.cpp | 36 +++++++++---------- 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/slsReceiverSoftware/src/UDPStandardImplementation.cpp b/slsReceiverSoftware/src/UDPStandardImplementation.cpp index 12a176777..b12826f16 100644 --- a/slsReceiverSoftware/src/UDPStandardImplementation.cpp +++ b/slsReceiverSoftware/src/UDPStandardImplementation.cpp @@ -1867,8 +1867,6 @@ void UDPStandardImplementation::processWritingBufferPacketByPacket(int ithread){ volatile uint32_t currentPacketNumber[numberofListeningThreads];//current packet number volatile int numberofMissingPackets[numberofListeningThreads]; // number of missing packets in this buffer - eiger_packet_header_t* blankframe_header; - for(int i=0; imissingPacket) = missingPacketValue; //set each value inside blank frame to 0xff for(int j=0;j<(oneDataSize);++j){ - blankframe_data = (unsigned char*)blankframe[i] + sizeof(eiger_packet_header_t) + j; + unsigned char* blankframe_data = (unsigned char*)blankframe[i] + sizeof(eiger_packet_header_t) + j; *(blankframe_data) = 0xFF; } } @@ -1945,12 +1947,11 @@ void UDPStandardImplementation::processWritingBufferPacketByPacket(int ithread){ //not full frame else if(!fullframe[i]){ - eiger_packet_footer_t* packetBuffer_footer = (eiger_packet_footer_t*)(packetBuffer[i] + footerOffset + HEADER_SIZE_NUM_TOT_PACKETS); - - //update frame number and packet number if(numPackets[i] != dummyPacketValue){ + eiger_packet_footer_t* packetBuffer_footer = (eiger_packet_footer_t*)(packetBuffer[i] + footerOffset + HEADER_SIZE_NUM_TOT_PACKETS); + if(!((uint32_t)(*( (uint64_t*) packetBuffer_footer)))){ FILE_LOG(logERROR) << "Fifo "<< i << ": Frame Number is zero from firmware. popready[" << i << "]:" << popReady[i]; popReady[i]=true; @@ -1972,10 +1973,10 @@ void UDPStandardImplementation::processWritingBufferPacketByPacket(int ithread){ if(numPackets[i] == dummyPacketValue) cprintf(GREEN, "Fifo %d: Dummy packet: Adding missing packets to the last frame\n", i); else{ - cprintf(GREEN,"Fifo %d: fnum %d, (FW_fnum %d), pnum %d, last_pnum %d, pnum_offset %d\n" + cprintf(GREEN,"Fifo %d: fnum %d, fnum_thread %d, pnum %d, last_pnum %d, pnum_offset %d\n" "Fifo %d: Add missing packets to the right fnum %d\n", - i,presentFrameNumber[i],(uint32_t)(*( (uint64_t*) packetBuffer_footer)), - *( (uint16_t*) packetBuffer_footer->packetNumber),lastPacketNumber[i],frameBufferoffset[i], + i,presentFrameNumber[i],threadFrameNumber[i], + currentPacketNumber[i],lastPacketNumber[i],frameBufferoffset[i], i,presentFrameNumber); } #endif @@ -1991,7 +1992,7 @@ void UDPStandardImplementation::processWritingBufferPacketByPacket(int ithread){ frameBuffer[frameBufferoffset[i]] = blankframe[blankoffset]; eiger_packet_header_t* frameBuffer_header = (eiger_packet_header_t*) frameBuffer[frameBufferoffset[i]]; if (*( (uint16_t*) frameBuffer_header->missingPacket)!= missingPacketValue){ - blankframe_header = (eiger_packet_header_t*) blankframe[blankoffset]; + eiger_packet_header_t* blankframe_header = (eiger_packet_header_t*) blankframe[blankoffset]; cprintf(BG_RED, "Fifo %d: Missing Packet Error: Adding blank packets mismatch " "pnum_offset %d, pnum %d, fnum_thread %d, missingpacket_buffer 0x%x, missingpacket_blank 0x%x\n", i,frameBufferoffset[i],currentPacketNumber[i],threadFrameNumber[i], @@ -2029,9 +2030,8 @@ void UDPStandardImplementation::processWritingBufferPacketByPacket(int ithread){ else{ if(currentPacketNumber[i] != (uint32_t)(frameBufferoffset[i]-(i*packetsPerFrame/numberofListeningThreads))+1){ cprintf(BG_RED, "Fifo %d: Correct Packet Offset Error:Adding current packet mismatch " - "pnum_offset %d,pnum %d fnum_thread %d, (FW_fnum %d)\n", - i,frameBufferoffset[i],currentPacketNumber[i], - threadFrameNumber[i],(uint32_t)(*( (uint64_t*) packetBuffer_footer))); + "pnum_offset %d,pnum %d fnum_thread %d\n", + i,frameBufferoffset[i],currentPacketNumber[i],threadFrameNumber[i]); exit(-1); } @@ -2066,9 +2066,9 @@ void UDPStandardImplementation::processWritingBufferPacketByPacket(int ithread){ currentFrameNumber = presentFrameNumber; numTotMissingPacketsInFile += numMissingPackets; numTotMissingPackets += numMissingPackets; -#ifdef FNUM_DEBUG - cprintf(GREEN,"**fnum:%d**\n",currframenum); -#endif +//#ifdef FNUM_DEBUG + cprintf(GREEN,"**fnum:%d**\n",currentFrameNumber); +//#endif #ifdef MISSINGP_DEBUG if(numberofMissingPackets[0]) cprintf(RED, "Fifo 0 missing packets %d for fnum %d\n",numberofMissingPackets[0],currentPacketNumber); From 0627668090724e368ddc1889d4fd2f111df8c774 Mon Sep 17 00:00:00 2001 From: Dhanya Maliakal Date: Wed, 11 Nov 2015 15:08:50 +0100 Subject: [PATCH 58/68] some changes for memory leak --- .../include/UDPStandardImplementation.h | 5 +- slsReceiverSoftware/include/genericSocket.h | 32 ++-- .../src/UDPStandardImplementation.cpp | 163 ++++++++++++------ .../src/slsReceiverTCPIPInterface.cpp | 30 ++-- 4 files changed, 146 insertions(+), 84 deletions(-) diff --git a/slsReceiverSoftware/include/UDPStandardImplementation.h b/slsReceiverSoftware/include/UDPStandardImplementation.h index d478f0e7a..a1cad30e9 100644 --- a/slsReceiverSoftware/include/UDPStandardImplementation.h +++ b/slsReceiverSoftware/include/UDPStandardImplementation.h @@ -379,11 +379,10 @@ private: * @param wbuffer the buffer array that is popped from all the FIFOs * @param ready if that FIFO is allowed to pop (depends on if dummy buffer already popped/ waiting for other FIFO to finish a frame(eiger)) * @param nP number of packets in the buffer popped out - * @param toFree array of addresses to pop into fifoFree (eiger specific) - * @param toFreeOffset the number of addresses to free for each FIFO (eiger specific) + * @param fifoTempFree circular fifo to save addresses of packets adding upto a frame before pushing into fifofree (eiger specific) * @return true if end of acquisition else false */ - bool popAndCheckEndofAcquisition(int ithread, char* wbuffer[], bool ready[], uint32_t nP[],char* toFree[],int toFreeOffset[]); + bool popAndCheckEndofAcquisition(int ithread, char* wbuffer[], bool ready[], uint32_t nP[],CircularFifo* fifoTempFree[]); /** * Called by processWritingBuffer and processWritingBufferPacketByPacket diff --git a/slsReceiverSoftware/include/genericSocket.h b/slsReceiverSoftware/include/genericSocket.h index de49d7860..b1b5e8f62 100644 --- a/slsReceiverSoftware/include/genericSocket.h +++ b/slsReceiverSoftware/include/genericSocket.h @@ -116,6 +116,11 @@ typedef struct // serverAddress = {0}; // clientAddress = {0}; // strcpy(hostname,host_ip_or_name); + + strcpy(lastClientIP,"none"); + strcpy(thisClientIP,"none1"); + strcpy(dummyClientIP,"dummy"); + struct hostent *hostInfo = gethostbyname(host_ip_or_name); if (hostInfo == NULL){ cerr << "Exiting: Problem interpreting host: " << host_ip_or_name << "\n"; @@ -170,16 +175,16 @@ typedef struct nsent(0), total_sent(0) { - //memset(&serverAddress, 0, sizeof(sockaddr_in)); - // memset(&clientAddress, 0, sizeof(sockaddr_in)); - // serverAddress = {0}; - // clientAddress = {0}; -/* // you can specify an IP address: */ -/* */ +/* // you can specify an IP address: */ /* // or you can let it automatically select one: */ /* myaddr.sin_addr.s_addr = INADDR_ANY; */ + + strcpy(lastClientIP,"none"); + strcpy(thisClientIP,"none1"); + strcpy(dummyClientIP,"dummy"); + if(serverAddress.sin_port == htons(port_number)){ socketDescriptor = -10; return; @@ -592,6 +597,15 @@ typedef struct length-=nsent; total_sent+=nsent; } + + if (total_sent>0) + strcpy(thisClientIP,dummyClientIP); + + if (strcmp(lastClientIP,thisClientIP)) + differentClients=1; + else + differentClients=0; + break; case UDP: if (socketDescriptor<0) return -1; @@ -641,13 +655,7 @@ typedef struct #ifdef VERY_VERBOSE cout << "sent "<< total_sent << " Bytes" << endl; #endif - if (total_sent>0) - strcpy(thisClientIP,dummyClientIP); - if (strcmp(lastClientIP,thisClientIP)) - differentClients=1; - else - differentClients=0; return total_sent; diff --git a/slsReceiverSoftware/src/UDPStandardImplementation.cpp b/slsReceiverSoftware/src/UDPStandardImplementation.cpp index b12826f16..266f3e38c 100644 --- a/slsReceiverSoftware/src/UDPStandardImplementation.cpp +++ b/slsReceiverSoftware/src/UDPStandardImplementation.cpp @@ -152,7 +152,7 @@ void UDPStandardImplementation::initializeMembers(){ previousFrameNumber = -1; acqStarted = false; measurementStarted = false; - for(int i = 0; i < numberofListeningThreads; ++i) + for(int i = 0; i < MAX_NUMBER_OF_LISTENING_THREADS; ++i) totalListeningFrameCount[i] = 0; packetsInFile = 0; numMissingPackets = 0; @@ -309,6 +309,7 @@ int UDPStandardImplementation::setupFifoStructure(){ return OK; + int count = 0; //set up fifo structure for(int i=0;iisEmpty()) + fifo[i]->pop(buffer[i]); + delete fifo[i]; + } if(mem0[i]) free(mem0[i]); //creating fifoFree[i] = new CircularFifo(fifoSize); fifo[i] = new CircularFifo(fifoSize); + //cout<<"buffersize:"<push(buffer[i]); -#ifdef DEBUG5 +//#ifdef DEBUG5 + + if(count==0 || count == 127998) cprintf(BLUE,"Info: %d fifostructure free pushed into fifofree %p\n", i, (void*)(buffer[i])); -#endif +//#endif buffer[i] += (bufferSize * numberofJobsPerBuffer + HEADER_SIZE_NUM_TOT_PACKETS); + count++; } + cout<pop(buffer[ithread]); -#ifdef DEBUG5 - cprintf(BLUE,"Listening_Thread %d :Listener popped from fifofree %p\n", ithread, (void*)(buffer[ithread])); +#ifdef CFIFODEBUG + if(ithread == 0) + cprintf(CYAN,"Listening_Thread %d :Listener popped from fifofree %p\n", ithread, (void*)(buffer[ithread])); + else + cprintf(YELLOW,"Listening_Thread %d :Listener popped from fifofree %p\n", ithread, (void*)(buffer[ithread])); #endif //udpsocket doesnt exist @@ -1489,8 +1504,12 @@ void UDPStandardImplementation::startListening(){ //push buffer to FIFO while(!fifo[ithread]->push(buffer[ithread])); -#ifdef DEBUG5 - cprintf(BLUE,"Listening_Thread %d: Listener pushed into fifo %p\n",ithread, (void*)(buffer[ithread])); +#ifdef CFIFODEBUG + if(ithread == 0) + cprintf(CYAN,"Listening_Thread %d: Listener pushed into fifo %p\n",ithread, (void*)(buffer[ithread])); + else + cprintf(YELLOW,"Listening_Thread %d: Listener pushed into fifo %p\n",ithread, (void*)(buffer[ithread])); + #endif }/*--end of loop for each buffer (inner loop)*/ @@ -1517,7 +1536,8 @@ int UDPStandardImplementation::prepareAndListenBuffer(int ithread, int lSize, in FILE_LOG(logDEBUG) << __AT__ << " called"; //listen to UDP packets - memcpy(buffer[ithread] + HEADER_SIZE_NUM_TOT_PACKETS, temp, cSize); + if(cSize) + memcpy(buffer[ithread] + HEADER_SIZE_NUM_TOT_PACKETS, temp, cSize); int receivedSize = udpSocket[ithread]->ReceiveDataOnly(buffer[ithread] + HEADER_SIZE_NUM_TOT_PACKETS + cSize, lSize + cSize); //throw away packets that is not one packet size, need to check status if socket is shut down @@ -1606,8 +1626,11 @@ void UDPStandardImplementation::stopListening(int ithread, int numbytes){ if(numbytes <= 0){ cprintf(BLUE,"Listening_Thread %d :End of Acquisition\n", ithread); while(!fifoFree[ithread]->push(buffer[ithread])); -#ifdef DEBUG5 - cprintf(BLUE,"Listening_Thread %d :Listener push empty buffer into fifofree %p\n", ithread, (void*)(buffer[ithread])); +#ifdef CFIFODEBUG + if(ithread == 0) + cprintf(CYAN,"Listening_Thread %d :Listener push empty buffer into fifofree %p\n", ithread, (void*)(buffer[ithread])); + else + cprintf(YELLOW,"Listening_Thread %d :Listener push empty buffer into fifofree %p\n", ithread, (void*)(buffer[ithread])); #endif } @@ -1621,19 +1644,31 @@ void UDPStandardImplementation::stopListening(int ithread, int numbytes){ cprintf(BLUE,"Listening_Thread %d: Last Buffer packet count:%d\n",ithread, numbytes/onePacketSize); #endif while(!fifo[ithread]->push(buffer[ithread])); -#ifdef DEBUG5 - cprintf(BLUE,"Listening_Thread %d: Listener Last Buffer pushed into fifo %p\n", ithread,(void*)(buffer[ithread])); +#ifdef CFIFODEBUG + if(ithread == 0) + cprintf(CYAN,"Listening_Thread %d: Listener Last Buffer pushed into fifo %p\n", ithread,(void*)(buffer[ithread])); + else + cprintf(YELLOW,"Listening_Thread %d: Listener Last Buffer pushed into fifo %p\n", ithread,(void*)(buffer[ithread])); #endif } //push dummy-end buffer into fifo for all writer threads for(int i=0; ipop(buffer[ithread]); +#ifdef CFIFODEBUG + if(ithread == 0) + cprintf(CYAN,"Listening_Thread %d: Popped Dummy from fifoFree %p\n", ithread,(void*)(buffer[ithread])); + else + cprintf(YELLOW,"Listening_Thread %d: Popped Dummy from fifoFree %p\n", ithread,(void*)(buffer[ithread])); +#endif //creating dummy-end buffer with pc=0xFFFF (*((uint32_t*)(buffer[ithread]))) = dummyPacketValue; while(!fifo[ithread]->push(buffer[ithread])); -#ifdef DEBUG5 - cprintf(BLUE,"Listening_Thread %d: Listener pushed dummy-end buffer into fifo %p\n", ithread,(void*)(buffer[ithread])); +#ifdef CFIFODEBUG + if(ithread == 0) + cprintf(CYAN,"Listening_Thread %d: Listener pushed dummy-end buffer into fifo %p\n", ithread,(void*)(buffer[ithread])); + else + cprintf(YELLOW,"Listening_Thread %d: Listener pushed dummy-end buffer into fifo %p\n", ithread,(void*)(buffer[ithread])); #endif } @@ -1852,8 +1887,9 @@ void UDPStandardImplementation::processWritingBufferPacketByPacket(int ithread){ int MAX_NUM_PACKETS = 1024; //highest 32 bit has 1024 number of packets uint32_t LAST_PACKET_VALUE; //last packet number - char* toFreePointers[MAX_NUM_PACKETS]; //pointers to free for each frame - int toFreePointersOffset[numberofListeningThreads]; //offset of pointers to free added for each thread + + CircularFifo* fifoTempFree[numberofListeningThreads];//ciruclar fifo to keep track of one frame packets to be freed and reused later + char* temp = NULL; char* frameBuffer[MAX_NUM_PACKETS]; //buffer offset created for a whole frame int frameBufferoffset[numberofListeningThreads]; //buffer offset created for a whole frame for both listening threads @@ -1868,34 +1904,42 @@ void UDPStandardImplementation::processWritingBufferPacketByPacket(int ithread){ volatile int numberofMissingPackets[numberofListeningThreads]; // number of missing packets in this buffer for(int i=0; iisEmpty()) + fifoTempFree[i]->pop(temp); + delete fifoTempFree[i]; + } + fifoTempFree[i] = new CircularFifo(MAX_NUM_PACKETS); } - presentFrameNumber = 0; - //blank frame - initializing with missing packet values - blankoffset = 0; for(uint32_t i=0; imissingPacket)==missingPacketValue) cprintf(RED,"Found missing packet at pnum %d\n",j); } } -#endif +//#endif //write and copy to gui handleWithoutDataCompression(ithread,frameBuffer,packetsPerFrame); //freeing - for(int j=0;jpush(toFreePointers[j])); -#ifdef DEBUG5 - cprintf(GREEN,"Fifo 0: Writing_Thread freed: pushed into fifofree %p\n",ithread, (void*)(toFreePointers[j])); -#endif - } - for(int j=(packetsPerFrame/numberofListeningThreads);jpush(toFreePointers[j])); -#ifdef DEBUG5 - cprintf(GREEN,"Fifo 1: Writing_Thread freed: pushed into fifofree %p\n",ithread, (void*)(toFreePointers[j])); + for(int i=0; iisEmpty()){ + fifoTempFree[i]->pop(temp); + fifoFree[i]->push(temp); + count++; +#ifdef CFIFODEBUG + if(i==0) + cprintf(CYAN,"Fifo %d: %d Writing_Thread freed: pushed into fifofree %p\n",i,count, (void*)(temp)); + else + cprintf(YELLOW,"Fifo %d: %d Writing_Thread freed: pushed into fifofree %p\n",i, count,(void*)(temp)); #endif + } } + + + #ifdef DEBUG4 cprintf(GREEN,"Writing_Thread: finished freeing\n"); #endif @@ -2113,7 +2158,6 @@ void UDPStandardImplementation::processWritingBufferPacketByPacket(int ithread){ if((numPackets[i] != dummyPacketValue) && (currentPacketNumber[i] == LAST_PACKET_VALUE)) popReady[i] = true; frameBufferoffset[i] = (i*packetsPerFrame/numberofListeningThreads); - toFreePointersOffset[i] = (i*packetsPerFrame/numberofListeningThreads); blankoffset = 0; lastPacketNumber[i] = 0; currentPacketNumber[i] = 0; @@ -2202,7 +2246,7 @@ void UDPStandardImplementation::waitWritingBufferForNextAcquisition(int ithread) } -bool UDPStandardImplementation::popAndCheckEndofAcquisition(int ithread, char* wbuffer[], bool ready[], uint32_t nP[],char* toFree[],int toFreeOffset[]){ +bool UDPStandardImplementation::popAndCheckEndofAcquisition(int ithread, char* wbuffer[], bool ready[], uint32_t nP[],CircularFifo* fifoTempFree[]){ FILE_LOG(logDEBUG) << __AT__ << " called"; bool endofAcquisition = true; @@ -2210,8 +2254,11 @@ bool UDPStandardImplementation::popAndCheckEndofAcquisition(int ithread, char* w //pop if ready if(ready[i]){ fifo[i]->pop(wbuffer[i]); -#ifdef DEBUG5 - cprintf(GREEN,"Writing_Thread %d: Popped %p from FIFO %d\n", ithread, (void*)(wbuffer[i]),i); +#ifdef CFIFODEBUG + if(i == 0) + cprintf(CYAN,"Writing_Thread %d: Popped %p from FIFO %d\n", ithread, (void*)(wbuffer[i]),i); + else + cprintf(YELLOW,"Writing_Thread %d: Popped %p from FIFO %d\n", ithread, (void*)(wbuffer[i]),i); #endif nP[i] = (uint32_t)(*((uint32_t*)wbuffer[i])); #ifdef DEBUG4 @@ -2239,8 +2286,7 @@ bool UDPStandardImplementation::popAndCheckEndofAcquisition(int ithread, char* w } #endif if(myDetectorType == EIGER){ - toFree[toFreeOffset[i]] = wbuffer[i]; - toFreeOffset[i]++; + while(!fifoTempFree[i]->push(wbuffer[i])); } } } @@ -2264,8 +2310,11 @@ void UDPStandardImplementation::stopWriting(int ithread, char* wbuffer[]){ //free fifo for(int i=0; ipush(wbuffer[i])); -#ifdef DEBUG5 - cprintf(GREEN,"Writing_Thread %d: Freeing dummy-end buffer. Pushed into fifofree %p for listener %d\n", ithread,(void*)(wbuffer[i]),i); +#ifdef CFIFODEBUG + if(i==0) + cprintf(CYAN,"Writing_Thread %d: Freeing dummy-end buffer. Pushed into fifofree %p for listener %d\n", ithread,(void*)(wbuffer[i]),i); + else + cprintf(YELLOW,"Writing_Thread %d: Freeing dummy-end buffer. Pushed into fifofree %p for listener %d\n", ithread,(void*)(wbuffer[i]),i); #endif } @@ -2478,14 +2527,14 @@ void UDPStandardImplementation::writeFileWithoutCompression(char* wbuffer[],uint void UDPStandardImplementation::createHeaders(char* wbuffer[]){ - eiger_packet_header_t* wbuf_header=0; - eiger_packet_footer_t* wbuf_footer=0; + int port = 0, missingPacket; for (uint32_t i = 0; i < packetsPerFrame; i++){ - wbuf_header = (eiger_packet_header_t*) wbuffer[i]; - wbuf_footer = (eiger_packet_footer_t*)(wbuffer[i] + footerOffset); + + eiger_packet_header_t* wbuf_header = (eiger_packet_header_t*) wbuffer[i]; + eiger_packet_footer_t* wbuf_footer = (eiger_packet_footer_t*)(wbuffer[i] + footerOffset); #ifdef DEBUG4 cprintf(GREEN, "Loop index:%d Pnum:%d\n",i,*( (uint16_t*) wbuf_footer->packetNumber)); #endif diff --git a/slsReceiverSoftware/src/slsReceiverTCPIPInterface.cpp b/slsReceiverSoftware/src/slsReceiverTCPIPInterface.cpp index 1a6f9860c..4e32516fa 100644 --- a/slsReceiverSoftware/src/slsReceiverTCPIPInterface.cpp +++ b/slsReceiverSoftware/src/slsReceiverTCPIPInterface.cpp @@ -441,6 +441,7 @@ int slsReceiverTCPIPInterface::set_file_name() { #endif #endif + if(ret==OK && socket->differentClients){ FILE_LOG(logDEBUG) << "Force update"; ret=FORCE_UPDATE; @@ -451,12 +452,14 @@ int slsReceiverTCPIPInterface::set_file_name() { if(ret==FAIL){ cprintf(RED, "%s\n", mess); socket->SendDataOnly(mess,sizeof(mess)); + } + if(retval == NULL) socket->SendDataOnly(defaultVal,MAX_STR_LENGTH); - }else + else{ socket->SendDataOnly(retval,MAX_STR_LENGTH); + delete[] retval; + } - //free - if(retval != NULL) delete[] retval; //return ok/fail return ret; @@ -523,12 +526,13 @@ int slsReceiverTCPIPInterface::set_file_dir() { if(ret==FAIL){ cprintf(RED, "%s\n", mess); socket->SendDataOnly(mess,sizeof(mess)); + } + if(retval == NULL) socket->SendDataOnly(defaultVal,MAX_STR_LENGTH); - }else + else{ socket->SendDataOnly(retval,MAX_STR_LENGTH); - - //free - if(retval != NULL) delete[] retval; + delete[] retval; + } //return ok/fail return ret; @@ -2244,13 +2248,15 @@ int slsReceiverTCPIPInterface::set_detector_hostname() { // send answer socket->SendDataOnly(&ret,sizeof(ret)); if(ret==FAIL){ - cprintf(RED,"%s\n",mess); + cprintf(RED, "%s\n", mess); socket->SendDataOnly(mess,sizeof(mess)); + } + if(retval == NULL) socket->SendDataOnly(defaultVal,MAX_STR_LENGTH); - }else socket->SendDataOnly(retval,MAX_STR_LENGTH); - - //free - if(retval!=NULL) delete[] retval; + else{ + socket->SendDataOnly(retval,MAX_STR_LENGTH); + delete[] retval; + } //return ok/fail return ret; From 24438419d55483768d36ab395f4a8c6411c5ddec Mon Sep 17 00:00:00 2001 From: Dhanya Maliakal Date: Wed, 11 Nov 2015 15:09:37 +0100 Subject: [PATCH 59/68] some changes for memory leak --- slsReceiverSoftware/src/UDPStandardImplementation.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/slsReceiverSoftware/src/UDPStandardImplementation.cpp b/slsReceiverSoftware/src/UDPStandardImplementation.cpp index 266f3e38c..8d74dfa90 100644 --- a/slsReceiverSoftware/src/UDPStandardImplementation.cpp +++ b/slsReceiverSoftware/src/UDPStandardImplementation.cpp @@ -355,7 +355,6 @@ int UDPStandardImplementation::setupFifoStructure(){ buffer[i] += (bufferSize * numberofJobsPerBuffer + HEADER_SIZE_NUM_TOT_PACKETS); count++; } - cout< Date: Thu, 12 Nov 2015 13:49:09 +0100 Subject: [PATCH 60/68] memory leak fixed --- slsReceiverSoftware/include/circularFifo.h | 11 +- slsReceiverSoftware/include/genericSocket.h | 114 ++++++++---------- slsReceiverSoftware/include/receiver_defs.h | 2 +- .../src/UDPStandardImplementation.cpp | 33 +++-- 4 files changed, 77 insertions(+), 83 deletions(-) diff --git a/slsReceiverSoftware/include/circularFifo.h b/slsReceiverSoftware/include/circularFifo.h index 1ba584cc4..4234a4d5d 100644 --- a/slsReceiverSoftware/include/circularFifo.h +++ b/slsReceiverSoftware/include/circularFifo.h @@ -78,8 +78,10 @@ int CircularFifo::getSemValue() template bool CircularFifo::push(Element*& item_) { - + //cout<<"*head:"<::push(Element*& item_) template bool CircularFifo::pop(Element*& item_) { - // if(head == tail) - // return false; // empty queue + //cout<<"-tail:"<0){ - nsending = (length>packet_size) ? packet_size:length; - nsent = read(file_des,(char*)buf+total_sent,nsending); - if(!nsent) break; - length-=nsent; - total_sent+=nsent; - } + if (buf==NULL) return -1; - if (total_sent>0) - strcpy(thisClientIP,dummyClientIP); - if (strcmp(lastClientIP,thisClientIP)) - differentClients=1; - else - differentClients=0; + total_sent=0; - break; - case UDP: - if (socketDescriptor<0) return -1; + switch(protocol) { + case TCP: + if (file_des<0) return -1; + while(length>0){ + nsending = (length>packet_size) ? packet_size:length; + nsent = read(file_des,(char*)buf+total_sent,nsending); + if(!nsent) break; + length-=nsent; + total_sent+=nsent; + } - //if length given, listens to length, else listens for packetsize till length is reached - if(length){ -/*int k = 0;*/ + if (total_sent>0) + strcpy(thisClientIP,dummyClientIP); - while(length>0){ - nsending = (length>packet_size) ? packet_size:length; -/* + if (strcmp(lastClientIP,thisClientIP)) + differentClients=1; + else + differentClients=0; + + break; + case UDP: + if (socketDescriptor<0) return -1; + + //if length given, listens to length, else listens for packetsize till length is reached + if(length){ + /*int k = 0;*/ + + while(length>0){ + nsending = (length>packet_size) ? packet_size:length; + /* //created for debugging on 11.05.2015 nsending=5000; nsent = recvfrom(socketDescriptor,(char*)buf,nsending, 0, (struct sockaddr *) &clientAddress, &clientAddress_length); @@ -632,33 +632,32 @@ typedef struct } else k++; - */ - - - nsent = recvfrom(socketDescriptor,(char*)buf+total_sent,nsending, 0, (struct sockaddr *) &clientAddress, &clientAddress_length); - if(!nsent) break; - length-=nsent; - total_sent+=nsent; - } - } - //listens to only 1 packet - else{ - //normal - nsending=packet_size; - nsent = recvfrom(socketDescriptor,(char*)buf+total_sent,nsending, 0, (struct sockaddr *) &clientAddress, &clientAddress_length); - total_sent+=nsent; - } - break; - default: - ; - } + */ + nsent = recvfrom(socketDescriptor,(char*)buf+total_sent,nsending, 0, (struct sockaddr *) &clientAddress, &clientAddress_length); + if(!nsent) break; + length-=nsent; + total_sent+=nsent; + } + } + //listens to only 1 packet + else{ + //normal + nsending=packet_size; + nsent = recvfrom(socketDescriptor,(char*)buf+total_sent,nsending, 0, (struct sockaddr *) &clientAddress, &clientAddress_length); + //nsent = 1040; + total_sent+=nsent; + } + break; + default: + ; + } #ifdef VERY_VERBOSE - cout << "sent "<< total_sent << " Bytes" << endl; + cout << "sent "<< total_sent << " Bytes" << endl; #endif - return total_sent; - + return total_sent; + } @@ -714,21 +713,12 @@ typedef struct protected: communicationProtocol protocol; - - - int is_a_server; - - int socketDescriptor; int file_des; - int packet_size; - struct sockaddr_in clientAddress, serverAddress; socklen_t clientAddress_length; - - char dummyClientIP[INET_ADDRSTRLEN]; diff --git a/slsReceiverSoftware/include/receiver_defs.h b/slsReceiverSoftware/include/receiver_defs.h index bac0df2d6..c11fe876d 100755 --- a/slsReceiverSoftware/include/receiver_defs.h +++ b/slsReceiverSoftware/include/receiver_defs.h @@ -111,7 +111,7 @@ #define EIGER_MAX_PORTS 2 #define EIGER_HEADER_LENGTH 48 -#define EIGER_FIFO_SIZE 250 //cannot be less than max jobs per thread = 1000 +#define EIGER_FIFO_SIZE 100 /*#define EIGER_ALIGNED_FRAME_SIZE 65536*/ #define EIGER_ONE_GIGA_CONSTANT 16 #define EIGER_TEN_GIGA_CONSTANT 4 diff --git a/slsReceiverSoftware/src/UDPStandardImplementation.cpp b/slsReceiverSoftware/src/UDPStandardImplementation.cpp index 8d74dfa90..68ba62a68 100644 --- a/slsReceiverSoftware/src/UDPStandardImplementation.cpp +++ b/slsReceiverSoftware/src/UDPStandardImplementation.cpp @@ -309,7 +309,6 @@ int UDPStandardImplementation::setupFifoStructure(){ return OK; - int count = 0; //set up fifo structure for(int i=0;ipush(buffer[i]); -//#ifdef DEBUG5 - - if(count==0 || count == 127998) + sprintf(buffer[i],"mem%d",i); +#ifdef DEBUG5 cprintf(BLUE,"Info: %d fifostructure free pushed into fifofree %p\n", i, (void*)(buffer[i])); -//#endif +#endif buffer[i] += (bufferSize * numberofJobsPerBuffer + HEADER_SIZE_NUM_TOT_PACKETS); - count++; } } FILE_LOG(logDEBUG) << "Info: Fifo structure(s) reconstructed"; @@ -1461,6 +1457,7 @@ void UDPStandardImplementation::startListening(){ //until mask unset (udp sockets shut down by client) while((1 << ithread) & listeningThreadsMask){ + //pop from fifo fifoFree[ithread]->pop(buffer[ithread]); #ifdef CFIFODEBUG @@ -1479,6 +1476,7 @@ void UDPStandardImplementation::startListening(){ rc = prepareAndListenBuffer(ithread, listenSize, carryonBufferSize, tempBuffer); + //start indices for each start of scan/acquisition if((!measurementStarted) && (rc > 0)){ pthread_mutex_lock(&progressMutex); @@ -1487,12 +1485,12 @@ void UDPStandardImplementation::startListening(){ pthread_mutex_unlock(&progressMutex); } + //problem in receiving or end of acquisition if (status == TRANSMITTING){ stopListening(ithread,rc); continue; } - //write packet count to buffer if(myDetectorType == EIGER) (*((uint32_t*)(buffer[ithread]))) = 1; @@ -1503,6 +1501,7 @@ void UDPStandardImplementation::startListening(){ //push buffer to FIFO while(!fifo[ithread]->push(buffer[ithread])); + #ifdef CFIFODEBUG if(ithread == 0) cprintf(CYAN,"Listening_Thread %d: Listener pushed into fifo %p\n",ithread, (void*)(buffer[ithread])); @@ -1511,6 +1510,7 @@ void UDPStandardImplementation::startListening(){ #endif + }/*--end of loop for each buffer (inner loop)*/ //end of acquisition, wait for next acquisition/change of parameters @@ -1537,6 +1537,7 @@ int UDPStandardImplementation::prepareAndListenBuffer(int ithread, int lSize, in //listen to UDP packets if(cSize) memcpy(buffer[ithread] + HEADER_SIZE_NUM_TOT_PACKETS, temp, cSize); + int receivedSize = udpSocket[ithread]->ReceiveDataOnly(buffer[ithread] + HEADER_SIZE_NUM_TOT_PACKETS + cSize, lSize + cSize); //throw away packets that is not one packet size, need to check status if socket is shut down @@ -1550,6 +1551,7 @@ int UDPStandardImplementation::prepareAndListenBuffer(int ithread, int lSize, in receivedSize = udpSocket[ithread]->ReceiveDataOnly(buffer[ithread] + HEADER_SIZE_NUM_TOT_PACKETS); } + #ifdef MANUALDEBUG eiger_packet_header_t* header = (eiger_packet_header_t*) (buffer[ithread]+HEADER_SIZE_NUM_TOT_PACKETS); eiger_packet_footer_t* footer = (eiger_packet_footer_t*)(buffer[ithread] + footerOffset + HEADER_SIZE_NUM_TOT_PACKETS); @@ -1961,7 +1963,6 @@ void UDPStandardImplementation::processWritingBufferPacketByPacket(int ithread){ //until mask unset (udp sockets shut down by client) while((1 << ithread) & writerThreadsMask){ - //pop fifo and if end of acquisition if(popAndCheckEndofAcquisition(ithread, packetBuffer, popReady, numPackets,fifoTempFree)){ #ifdef DEBUG4 @@ -2109,10 +2110,10 @@ void UDPStandardImplementation::processWritingBufferPacketByPacket(int ithread){ currentFrameNumber = presentFrameNumber; numTotMissingPacketsInFile += numMissingPackets; numTotMissingPackets += numMissingPackets; -//#ifdef FNUM_DEBUG +#ifdef FNUM_DEBUG cprintf(GREEN,"**fnum:%d**\n",currentFrameNumber); -//#endif -//#ifdef MISSINGP_DEBUG +#endif +#ifdef MISSINGP_DEBUG if(numMissingPackets){ cprintf(RED, "Total missing packets %d for fnum %d\n",numMissingPackets,currentFrameNumber); for (int j=0;jisEmpty()){ fifoTempFree[i]->pop(temp); fifoFree[i]->push(temp); - count++; #ifdef CFIFODEBUG if(i==0) - cprintf(CYAN,"Fifo %d: %d Writing_Thread freed: pushed into fifofree %p\n",i,count, (void*)(temp)); + cprintf(CYAN,"Fifo %d: Writing_Thread freed: pushed into fifofree %p\n",i, (void*)(temp)); else - cprintf(YELLOW,"Fifo %d: %d Writing_Thread freed: pushed into fifofree %p\n",i, count,(void*)(temp)); + cprintf(YELLOW,"Fifo %d: Writing_Thread freed: pushed into fifofree %p\n",i, (void*)(temp)); #endif } } From 113e5223990bbd22f5639409790f4b254314aa05 Mon Sep 17 00:00:00 2001 From: Dhanya Maliakal Date: Fri, 13 Nov 2015 17:55:11 +0100 Subject: [PATCH 61/68] refactoring and reducing overhead --- .../src/UDPStandardImplementation.cpp | 28 ++++++++++++++----- 1 file changed, 21 insertions(+), 7 deletions(-) diff --git a/slsReceiverSoftware/src/UDPStandardImplementation.cpp b/slsReceiverSoftware/src/UDPStandardImplementation.cpp index 68ba62a68..2b3068e08 100644 --- a/slsReceiverSoftware/src/UDPStandardImplementation.cpp +++ b/slsReceiverSoftware/src/UDPStandardImplementation.cpp @@ -856,7 +856,6 @@ int UDPStandardImplementation::startReceiver(char *c){ for(int i=0;i Date: Mon, 16 Nov 2015 11:48:50 +0100 Subject: [PATCH 62/68] fifodepth def change, and listening packets count right --- .../include/UDPStandardImplementation.h | 2 +- .../src/UDPStandardImplementation.cpp | 49 ++++++++++--------- 2 files changed, 26 insertions(+), 25 deletions(-) diff --git a/slsReceiverSoftware/include/UDPStandardImplementation.h b/slsReceiverSoftware/include/UDPStandardImplementation.h index a1cad30e9..605afc155 100644 --- a/slsReceiverSoftware/include/UDPStandardImplementation.h +++ b/slsReceiverSoftware/include/UDPStandardImplementation.h @@ -585,7 +585,7 @@ private: int numberofJobsPerBuffer; /** Fifo Depth */ - uint32_t fifoSize; + uint32_t fifoDepth; /** Missing Packet identifier value */ const static uint16_t missingPacketValue = 0xFFFF; diff --git a/slsReceiverSoftware/src/UDPStandardImplementation.cpp b/slsReceiverSoftware/src/UDPStandardImplementation.cpp index 2b3068e08..4c2574234 100644 --- a/slsReceiverSoftware/src/UDPStandardImplementation.cpp +++ b/slsReceiverSoftware/src/UDPStandardImplementation.cpp @@ -170,7 +170,7 @@ void UDPStandardImplementation::initializeMembers(){ } sfilefd = NULL; numberofJobsPerBuffer = -1; - fifoSize = 0; + fifoDepth = 0; //***receiver to GUI parameters*** latestData = NULL; @@ -253,7 +253,7 @@ int UDPStandardImplementation::setupFifoStructure(){ int64_t i; int oldNumberofJobsPerBuffer = numberofJobsPerBuffer; - uint32_t oldFifoSize = fifoSize; + uint32_t oldFifoSize = fifoDepth; //eiger always listens to 1 packet at a time if(myDetectorType == EIGER){ @@ -287,25 +287,25 @@ int UDPStandardImplementation::setupFifoStructure(){ //set fifo depth //eiger listens to 1 packet at a time and size changes depending on packets per frame if(myDetectorType == EIGER) - fifoSize = EIGER_FIFO_SIZE * packetsPerFrame; + fifoDepth = EIGER_FIFO_SIZE * packetsPerFrame; else{ - fifoSize = GOTTHARD_FIFO_SIZE; + fifoDepth = GOTTHARD_FIFO_SIZE; if(myDetectorType == MOENCH) - fifoSize = MOENCH_FIFO_SIZE; + fifoDepth = MOENCH_FIFO_SIZE; else if(myDetectorType == PROPIX) - fifoSize = PROPIX_FIFO_SIZE; + fifoDepth = PROPIX_FIFO_SIZE; //reduce fifo depth if more frames listened to at a time - if(fifoSize % numberofJobsPerBuffer) - fifoSize = (fifoSize/numberofJobsPerBuffer)+1; + if(fifoDepth % numberofJobsPerBuffer) + fifoDepth = (fifoDepth/numberofJobsPerBuffer)+1; else - fifoSize = fifoSize/numberofJobsPerBuffer; + fifoDepth = fifoDepth/numberofJobsPerBuffer; } - FILE_LOG(logDEBUG) << "Info: Fifo Depth:" << fifoSize; + FILE_LOG(logDEBUG) << "Info: Fifo Depth:" << fifoDepth; //do not rebuild fifo structure if it is the same - if((oldNumberofJobsPerBuffer == numberofJobsPerBuffer) && (oldFifoSize == fifoSize)) + if((oldNumberofJobsPerBuffer == numberofJobsPerBuffer) && (oldFifoSize == fifoDepth)) return OK; @@ -329,13 +329,13 @@ int UDPStandardImplementation::setupFifoStructure(){ if(mem0[i]) free(mem0[i]); //creating - fifoFree[i] = new CircularFifo(fifoSize); - fifo[i] = new CircularFifo(fifoSize); + fifoFree[i] = new CircularFifo(fifoDepth); + fifo[i] = new CircularFifo(fifoDepth); //cout<<"buffersize:"<push(buffer[i]); sprintf(buffer[i],"mem%d",i); #ifdef DEBUG5 @@ -660,7 +660,7 @@ int UDPStandardImplementation::setDetectorType(const detectorType d){ frameIndexOffset = GOTTHARD_FRAME_INDEX_OFFSET; packetIndexMask = GOTTHARD_PACKET_INDEX_MASK; maxPacketsPerFile = MAX_FRAMES_PER_FILE * GOTTHARD_PACKETS_PER_FRAME; - fifoSize = GOTTHARD_FIFO_SIZE; + fifoDepth = GOTTHARD_FIFO_SIZE; //footerOffset = Not applicable; break; case PROPIX: @@ -673,7 +673,7 @@ int UDPStandardImplementation::setDetectorType(const detectorType d){ frameIndexOffset = PROPIX_FRAME_INDEX_OFFSET; packetIndexMask = PROPIX_PACKET_INDEX_MASK; maxPacketsPerFile = MAX_FRAMES_PER_FILE * PROPIX_PACKETS_PER_FRAME; - fifoSize = PROPIX_FIFO_SIZE; + fifoDepth = PROPIX_FIFO_SIZE; //footerOffset = Not applicable; break; case MOENCH: @@ -686,7 +686,7 @@ int UDPStandardImplementation::setDetectorType(const detectorType d){ frameIndexOffset = MOENCH_FRAME_INDEX_OFFSET; packetIndexMask = MOENCH_PACKET_INDEX_MASK; maxPacketsPerFile = MOENCH_MAX_FRAMES_PER_FILE * MOENCH_PACKETS_PER_FRAME; - fifoSize = MOENCH_FIFO_SIZE; + fifoDepth = MOENCH_FIFO_SIZE; //footerOffset = Not applicable; break; case EIGER: @@ -700,7 +700,7 @@ int UDPStandardImplementation::setDetectorType(const detectorType d){ frameIndexOffset = EIGER_FRAME_INDEX_OFFSET; packetIndexMask = EIGER_PACKET_INDEX_MASK; maxPacketsPerFile = EIGER_MAX_FRAMES_PER_FILE * packetsPerFrame; - fifoSize = EIGER_FIFO_SIZE; + fifoDepth = EIGER_FIFO_SIZE; footerOffset = EIGER_PACKET_HEADER_SIZE + oneDataSize; break; case JUNGFRAUCTB: @@ -714,7 +714,7 @@ int UDPStandardImplementation::setDetectorType(const detectorType d){ frameIndexOffset = JCTB_FRAME_INDEX_OFFSET; packetIndexMask = JCTB_PACKET_INDEX_MASK; maxPacketsPerFile = JFCTB_MAX_FRAMES_PER_FILE * JCTB_PACKETS_PER_FRAME; - fifoSize = JCTB_FIFO_SIZE; + fifoDepth = JCTB_FIFO_SIZE; //footerOffset = Not applicable; break; default: @@ -934,18 +934,19 @@ void UDPStandardImplementation::startReadout(){ } //wait for all packets if(totalP!=numberOfFrames*packetsPerFrame){ + prev = -1; //wait as long as there is change from prev totalP while(prev != totalP){ - cprintf(MAGENTA,"waiting for all packets\n"); - usleep(1000);/* Need to find optimal time (exposure time and acquisition period) **/ + cprintf(MAGENTA,"waiting for all packets totalP:%d\n",totalP); + usleep(5000);/* Need to find optimal time (exposure time and acquisition period) **/ prev = totalP; totalP=0; for(i=0; iReceiveDataOnly(buffer[ithread] + HEADER_SIZE_NUM_TOT_PACKETS); } - + totalListeningFrameCount[ithread] += (receivedSize/onePacketSize); #ifdef MANUALDEBUG eiger_packet_header_t* header = (eiger_packet_header_t*) (buffer[ithread]+HEADER_SIZE_NUM_TOT_PACKETS); From 777f04331d28c06f0e5d6f6806b4e7ebd6929edf Mon Sep 17 00:00:00 2001 From: Dhanya Maliakal Date: Tue, 17 Nov 2015 10:31:09 +0100 Subject: [PATCH 63/68] implemented fifo depth configurable from client --- .../include/UDPBaseImplementation.h | 16 ++++ slsReceiverSoftware/include/UDPInterface.h | 13 +++ .../include/UDPStandardImplementation.h | 11 ++- .../include/slsReceiverTCPIPInterface.h | 3 + .../include/sls_receiver_funcs.h | 3 +- .../src/UDPBaseImplementation.cpp | 12 +++ .../src/UDPStandardImplementation.cpp | 88 +++++++++++-------- .../src/slsReceiverTCPIPInterface.cpp | 76 ++++++++++++++++ 8 files changed, 184 insertions(+), 38 deletions(-) diff --git a/slsReceiverSoftware/include/UDPBaseImplementation.h b/slsReceiverSoftware/include/UDPBaseImplementation.h index dfb7b0429..2c544759b 100644 --- a/slsReceiverSoftware/include/UDPBaseImplementation.h +++ b/slsReceiverSoftware/include/UDPBaseImplementation.h @@ -179,6 +179,13 @@ class UDPBaseImplementation : protected virtual slsReceiverDefs, public UDPInter */ bool getTenGigaEnable() const; + /** + * Get Fifo Depth + * @return fifo depth + */ + uint32_t getFifoDepth() const; + + //***receiver status*** /** * Get Listening Status of Receiver @@ -324,6 +331,13 @@ class UDPBaseImplementation : protected virtual slsReceiverDefs, public UDPInter */ int setTenGigaEnable(const bool b); + /** + * Set Fifo Depth + * @param i fifo depth value + * @return OK or FAIL + */ + int setFifoDepth(const uint32_t i); + /************************************************************************* * Behavioral functions*************************************************** @@ -460,6 +474,8 @@ class UDPBaseImplementation : protected virtual slsReceiverDefs, public UDPInter uint32_t dynamicRange; /** Ten Giga Enable*/ bool tengigaEnable; + /** Fifo Depth */ + uint32_t fifoDepth; /** Bottom Half Module Enable */ bool bottomEnable; diff --git a/slsReceiverSoftware/include/UDPInterface.h b/slsReceiverSoftware/include/UDPInterface.h index 1a6377653..798c45f6c 100644 --- a/slsReceiverSoftware/include/UDPInterface.h +++ b/slsReceiverSoftware/include/UDPInterface.h @@ -235,6 +235,12 @@ class UDPInterface { */ virtual bool getTenGigaEnable() const = 0; + /** + * Get Fifo Depth + * @return fifo depth + */ + virtual uint32_t getFifoDepth() const = 0; + //***receiver status*** /** * Get Listening Status of Receiver @@ -378,6 +384,13 @@ class UDPInterface { */ virtual int setTenGigaEnable(const bool b) = 0; + /** + * Set Fifo Depth + * @param i fifo depth value + * @return OK or FAIL + */ + virtual int setFifoDepth(const uint32_t i) = 0; + /************************************************************************* * Behavioral functions*************************************************** diff --git a/slsReceiverSoftware/include/UDPStandardImplementation.h b/slsReceiverSoftware/include/UDPStandardImplementation.h index 605afc155..3c256450a 100644 --- a/slsReceiverSoftware/include/UDPStandardImplementation.h +++ b/slsReceiverSoftware/include/UDPStandardImplementation.h @@ -122,6 +122,13 @@ class UDPStandardImplementation: private virtual slsReceiverDefs, public UDPBase int setTenGigaEnable(const bool b); + /** + * Overridden method + * Set Fifo Depth + * @param i fifo depth value + * @return OK or FAIL + */ + int setFifoDepth(const uint32_t i); /************************************************************************* * Behavioral functions*************************************************** @@ -584,8 +591,8 @@ private: /** Number of Jobs Per Buffer */ int numberofJobsPerBuffer; - /** Fifo Depth */ - uint32_t fifoDepth; + /** Total fifo size */ + uint32_t fifoSize; /** Missing Packet identifier value */ const static uint16_t missingPacketValue = 0xFFFF; diff --git a/slsReceiverSoftware/include/slsReceiverTCPIPInterface.h b/slsReceiverSoftware/include/slsReceiverTCPIPInterface.h index 49e5134f1..b71b705f6 100644 --- a/slsReceiverSoftware/include/slsReceiverTCPIPInterface.h +++ b/slsReceiverSoftware/include/slsReceiverTCPIPInterface.h @@ -207,6 +207,9 @@ private: /** enable 10Gbe */ int enable_tengiga(); + /** set fifo depth */ + int set_fifo_depth(); + //General Functions /** Locks Receiver */ int lock_receiver(); diff --git a/slsReceiverSoftware/include/sls_receiver_funcs.h b/slsReceiverSoftware/include/sls_receiver_funcs.h index 7f3842576..e1ef93040 100644 --- a/slsReceiverSoftware/include/sls_receiver_funcs.h +++ b/slsReceiverSoftware/include/sls_receiver_funcs.h @@ -48,7 +48,8 @@ enum { F_ENABLE_RECEIVER_COMPRESSION, /**< enable compression in receiver */ F_ENABLE_RECEIVER_OVERWRITE, /**< set overwrite flag in receiver */ - F_ENABLE_RECEIVER_TEN_GIGA /**< enable 10Gbe in receiver */ + F_ENABLE_RECEIVER_TEN_GIGA, /**< enable 10Gbe in receiver */ + F_SET_RECEIVER_FIFO_DEPTH /**< set receiver fifo depth */ /* Always append functions hereafter!!! */ }; diff --git a/slsReceiverSoftware/src/UDPBaseImplementation.cpp b/slsReceiverSoftware/src/UDPBaseImplementation.cpp index 606208521..9a9b1723a 100644 --- a/slsReceiverSoftware/src/UDPBaseImplementation.cpp +++ b/slsReceiverSoftware/src/UDPBaseImplementation.cpp @@ -44,6 +44,7 @@ void UDPBaseImplementation::initializeMembers(){ numberOfFrames = 0; dynamicRange = 16; tengigaEnable = false; + fifoDepth = 0; bottomEnable = false; //***receiver parameters*** @@ -181,6 +182,8 @@ uint32_t UDPBaseImplementation::getDynamicRange() const{ FILE_LOG(logDEBUG) << _ bool UDPBaseImplementation::getTenGigaEnable() const{ FILE_LOG(logDEBUG) << __AT__ << " starting"; return tengigaEnable;} +uint32_t UDPBaseImplementation::getFifoDepth() const{ FILE_LOG(logDEBUG) << __AT__ << " starting"; return fifoDepth;} + /***receiver status***/ slsReceiverDefs::runStatus UDPBaseImplementation::getStatus() const{ FILE_LOG(logDEBUG) << __AT__ << " starting"; return status;} @@ -358,6 +361,15 @@ int UDPBaseImplementation::setTenGigaEnable(const bool b){ return OK; } +int UDPBaseImplementation::setFifoDepth(const uint32_t i){ + FILE_LOG(logDEBUG) << __AT__ << " starting"; + + fifoDepth = i; + FILE_LOG(logINFO) << "Fifo Depth: " << i; + + //overridden functions might return FAIL + return OK; +} /************************************************************************* * Behavioral functions*************************************************** diff --git a/slsReceiverSoftware/src/UDPStandardImplementation.cpp b/slsReceiverSoftware/src/UDPStandardImplementation.cpp index 4c2574234..3a6a346e1 100644 --- a/slsReceiverSoftware/src/UDPStandardImplementation.cpp +++ b/slsReceiverSoftware/src/UDPStandardImplementation.cpp @@ -170,7 +170,7 @@ void UDPStandardImplementation::initializeMembers(){ } sfilefd = NULL; numberofJobsPerBuffer = -1; - fifoDepth = 0; + fifoSize = 0; //***receiver to GUI parameters*** latestData = NULL; @@ -251,16 +251,15 @@ void UDPStandardImplementation::initializeFilter(){ int UDPStandardImplementation::setupFifoStructure(){ FILE_LOG(logDEBUG) << __AT__ << " called"; + + //number of jobs per buffer int64_t i; int oldNumberofJobsPerBuffer = numberofJobsPerBuffer; - uint32_t oldFifoSize = fifoDepth; - //eiger always listens to 1 packet at a time if(myDetectorType == EIGER){ numberofJobsPerBuffer = 1; FILE_LOG(logDEBUG) << "Info: 1 packet per buffer"; } - //else calculate best possible number of frames to listen to at a time (for fast readouts like gotthard) else{ //if frequency to gui is not random (every nth frame), then listen to only n frames per buffer @@ -284,29 +283,41 @@ int UDPStandardImplementation::setupFifoStructure(){ FILE_LOG(logINFO) << "Number of Frames per buffer:" << numberofJobsPerBuffer << endl; } - //set fifo depth - //eiger listens to 1 packet at a time and size changes depending on packets per frame - if(myDetectorType == EIGER) - fifoDepth = EIGER_FIFO_SIZE * packetsPerFrame; - else{ - fifoDepth = GOTTHARD_FIFO_SIZE; - if(myDetectorType == MOENCH) - fifoDepth = MOENCH_FIFO_SIZE; - else if(myDetectorType == PROPIX) - fifoDepth = PROPIX_FIFO_SIZE; - //reduce fifo depth if more frames listened to at a time - if(fifoDepth % numberofJobsPerBuffer) - fifoDepth = (fifoDepth/numberofJobsPerBuffer)+1; - else - fifoDepth = fifoDepth/numberofJobsPerBuffer; + + + // fifo depth + uint32_t oldFifoSize = fifoSize; + //default + if(!fifoDepth){ + switch(myDetectorType){ + case GOTTHARD: fifoSize = GOTTHARD_FIFO_SIZE; break; + case MOENCH: fifoSize = MOENCH_FIFO_SIZE; break; + case PROPIX: fifoSize = PROPIX_FIFO_SIZE; break; + case EIGER: fifoSize = EIGER_FIFO_SIZE * packetsPerFrame; break;//listens to 1 packet at a time and size depends on packetsperframe + default: break; + } } - FILE_LOG(logDEBUG) << "Info: Fifo Depth:" << fifoDepth; + //change by user + else{ + if(myDetectorType == EIGER) + fifoSize = fifoDepth * packetsPerFrame; + else fifoSize = fifoDepth; + } + //reduce fifo depth if > 1 numberofJobsPerBuffer + if(fifoSize % numberofJobsPerBuffer) + fifoSize = (fifoSize/numberofJobsPerBuffer)+1; + else + fifoSize = fifoSize/numberofJobsPerBuffer; - //do not rebuild fifo structure if it is the same - if((oldNumberofJobsPerBuffer == numberofJobsPerBuffer) && (oldFifoSize == fifoDepth)) + //do not rebuild fifo structure if it is the same (oldfifosize differs only for different packetsperframe) + if((oldNumberofJobsPerBuffer == numberofJobsPerBuffer) && (oldFifoSize == fifoSize)) return OK; + FILE_LOG(logINFO) << "Info: Total Fifo Size:" << fifoSize; + + + //set up fifo structure @@ -329,13 +340,11 @@ int UDPStandardImplementation::setupFifoStructure(){ if(mem0[i]) free(mem0[i]); //creating - fifoFree[i] = new CircularFifo(fifoDepth); - fifo[i] = new CircularFifo(fifoDepth); - - //cout<<"buffersize:"<(fifoSize); + fifo[i] = new CircularFifo(fifoSize); //allocate memory - mem0[i] = (char*)malloc((bufferSize * numberofJobsPerBuffer + HEADER_SIZE_NUM_TOT_PACKETS) * fifoDepth); + mem0[i] = (char*)malloc((bufferSize * numberofJobsPerBuffer + HEADER_SIZE_NUM_TOT_PACKETS) * fifoSize); if (mem0[i] == NULL){ cprintf(BG_RED,"Error: Could not allocate memory for listening \n"); return FAIL; @@ -343,7 +352,7 @@ int UDPStandardImplementation::setupFifoStructure(){ //push free address into fifoFree buffer[i]=mem0[i]; - while (buffer[i] < (mem0[i]+(bufferSize * numberofJobsPerBuffer + HEADER_SIZE_NUM_TOT_PACKETS) * (fifoDepth-1))) { + while (buffer[i] < (mem0[i]+(bufferSize * numberofJobsPerBuffer + HEADER_SIZE_NUM_TOT_PACKETS) * (fifoSize-1))) { fifoFree[i]->push(buffer[i]); sprintf(buffer[i],"mem%d",i); #ifdef DEBUG5 @@ -352,7 +361,7 @@ int UDPStandardImplementation::setupFifoStructure(){ buffer[i] += (bufferSize * numberofJobsPerBuffer + HEADER_SIZE_NUM_TOT_PACKETS); } } - FILE_LOG(logDEBUG) << "Info: Fifo structure(s) reconstructed"; + cout << "Fifo structure(s) reconstructed" << endl; return OK; } @@ -612,7 +621,16 @@ int UDPStandardImplementation::setTenGigaEnable(const bool b){ } +int UDPStandardImplementation::setFifoDepth(const uint32_t i){ + FILE_LOG(logDEBUG) << __AT__ << " called"; + if(i != fifoDepth){ + FILE_LOG(logINFO) << "Fifo Depth: " << i << endl; + fifoDepth = i; + return setupFifoStructure(); + } + return OK; +} @@ -641,7 +659,7 @@ int UDPStandardImplementation::setDetectorType(const detectorType d){ case EIGER: case JUNGFRAUCTB: case JUNGFRAU: - FILE_LOG(logINFO) << " ***** This is a " << getDetectorType(d) << " Receiver *****"; + FILE_LOG(logINFO) << " ***** " << getDetectorType(d) << " Receiver *****"; break; default: FILE_LOG(logERROR) << "This is an unknown receiver type " << (int)d; @@ -660,7 +678,7 @@ int UDPStandardImplementation::setDetectorType(const detectorType d){ frameIndexOffset = GOTTHARD_FRAME_INDEX_OFFSET; packetIndexMask = GOTTHARD_PACKET_INDEX_MASK; maxPacketsPerFile = MAX_FRAMES_PER_FILE * GOTTHARD_PACKETS_PER_FRAME; - fifoDepth = GOTTHARD_FIFO_SIZE; + fifoSize = GOTTHARD_FIFO_SIZE; //footerOffset = Not applicable; break; case PROPIX: @@ -673,7 +691,7 @@ int UDPStandardImplementation::setDetectorType(const detectorType d){ frameIndexOffset = PROPIX_FRAME_INDEX_OFFSET; packetIndexMask = PROPIX_PACKET_INDEX_MASK; maxPacketsPerFile = MAX_FRAMES_PER_FILE * PROPIX_PACKETS_PER_FRAME; - fifoDepth = PROPIX_FIFO_SIZE; + fifoSize = PROPIX_FIFO_SIZE; //footerOffset = Not applicable; break; case MOENCH: @@ -686,7 +704,7 @@ int UDPStandardImplementation::setDetectorType(const detectorType d){ frameIndexOffset = MOENCH_FRAME_INDEX_OFFSET; packetIndexMask = MOENCH_PACKET_INDEX_MASK; maxPacketsPerFile = MOENCH_MAX_FRAMES_PER_FILE * MOENCH_PACKETS_PER_FRAME; - fifoDepth = MOENCH_FIFO_SIZE; + fifoSize = MOENCH_FIFO_SIZE; //footerOffset = Not applicable; break; case EIGER: @@ -700,7 +718,7 @@ int UDPStandardImplementation::setDetectorType(const detectorType d){ frameIndexOffset = EIGER_FRAME_INDEX_OFFSET; packetIndexMask = EIGER_PACKET_INDEX_MASK; maxPacketsPerFile = EIGER_MAX_FRAMES_PER_FILE * packetsPerFrame; - fifoDepth = EIGER_FIFO_SIZE; + fifoSize = EIGER_FIFO_SIZE; footerOffset = EIGER_PACKET_HEADER_SIZE + oneDataSize; break; case JUNGFRAUCTB: @@ -714,7 +732,7 @@ int UDPStandardImplementation::setDetectorType(const detectorType d){ frameIndexOffset = JCTB_FRAME_INDEX_OFFSET; packetIndexMask = JCTB_PACKET_INDEX_MASK; maxPacketsPerFile = JFCTB_MAX_FRAMES_PER_FILE * JCTB_PACKETS_PER_FRAME; - fifoDepth = JCTB_FIFO_SIZE; + fifoSize = JCTB_FIFO_SIZE; //footerOffset = Not applicable; break; default: diff --git a/slsReceiverSoftware/src/slsReceiverTCPIPInterface.cpp b/slsReceiverSoftware/src/slsReceiverTCPIPInterface.cpp index 4e32516fa..403aa7309 100644 --- a/slsReceiverSoftware/src/slsReceiverTCPIPInterface.cpp +++ b/slsReceiverSoftware/src/slsReceiverTCPIPInterface.cpp @@ -252,6 +252,7 @@ int slsReceiverTCPIPInterface::function_table(){ flist[F_ENABLE_RECEIVER_OVERWRITE] = &slsReceiverTCPIPInterface::enable_overwrite; flist[F_ENABLE_RECEIVER_TEN_GIGA] = &slsReceiverTCPIPInterface::enable_tengiga; + flist[F_SET_RECEIVER_FIFO_DEPTH] = &slsReceiverTCPIPInterface::set_fifo_depth; #ifdef VERYVERBOSE @@ -2484,6 +2485,81 @@ int slsReceiverTCPIPInterface::enable_tengiga() { +int slsReceiverTCPIPInterface::set_fifo_depth() { + ret=OK; + int value=-1; + int retval=-100; + strcpy(mess,"Could not set/get fifo depth for receiver\n"); + + // receive arguments + if(socket->ReceiveDataOnly(&value,sizeof(value)) < 0 ){ + strcpy(mess,"Error reading from socket\n"); + ret = FAIL; + } + + + // execute action if the arguments correctly arrived +#ifdef SLS_RECEIVER_UDP_FUNCTIONS + if (ret==OK) { + if(value >= 0){ + if (lockStatus==1 && socket->differentClients==1){ + sprintf(mess,"Receiver locked by %s\n", socket->lastClientIP); + ret=FAIL; + } + else if (receiverBase == NULL){ + strcpy(mess,"Receiver not set up\n"); + ret=FAIL; + } + else if(receiverBase->getStatus()==RUNNING){ + strcpy(mess,"Cannot set/get fifo depth while status is running\n"); + ret=FAIL; + } + else{ + if(value >= 0){ + ret = receiverBase->setFifoDepth(value); + } + } + } + + + if (receiverBase == NULL){ + strcpy(mess,"Receiver not set up\n"); + ret=FAIL; + }else{ + retval = receiverBase->getFifoDepth(); + if(value >= 0 && retval != value) + ret = FAIL; + } + + } +#endif + + if(ret==OK && socket->differentClients){ + FILE_LOG(logDEBUG) << "Force update"; + ret=FORCE_UPDATE; + } + + // send answer + socket->SendDataOnly(&ret,sizeof(ret)); + if(ret==FAIL){ + cprintf(RED,"%s\n",mess); + socket->SendDataOnly(mess,sizeof(mess)); + } + socket->SendDataOnly(&retval,sizeof(retval)); + + //return ok/fail + return ret; +} + + + + + + + + + + From 73f8d065b3cbd10e9d4f6471e4703be752e53348 Mon Sep 17 00:00:00 2001 From: Dhanya Maliakal Date: Tue, 17 Nov 2015 12:27:18 +0100 Subject: [PATCH 64/68] empty fifo at receiver start and comment waiting for packet --- slsReceiverSoftware/src/UDPStandardImplementation.cpp | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/slsReceiverSoftware/src/UDPStandardImplementation.cpp b/slsReceiverSoftware/src/UDPStandardImplementation.cpp index 3a6a346e1..cda3bebad 100644 --- a/slsReceiverSoftware/src/UDPStandardImplementation.cpp +++ b/slsReceiverSoftware/src/UDPStandardImplementation.cpp @@ -956,7 +956,9 @@ void UDPStandardImplementation::startReadout(){ prev = -1; //wait as long as there is change from prev totalP while(prev != totalP){ +#ifdef DEBUG5 cprintf(MAGENTA,"waiting for all packets totalP:%d\n",totalP); +#endif usleep(5000);/* Need to find optimal time (exposure time and acquisition period) **/ prev = totalP; totalP=0; @@ -2240,6 +2242,13 @@ void UDPStandardImplementation::waitWritingBufferForNextAcquisition(int ithread) #endif + //pop fifo so that its empty + char* temp; + while(!fifo[ithread]->isEmpty()){ + cout << ithread << ":emptied buffer in fifo" << endl; + fifo[ithread]->pop(temp); + } + //create file if((1< Date: Tue, 17 Nov 2015 15:27:52 +0100 Subject: [PATCH 65/68] just minor edit changes --- slsReceiverSoftware/src/UDPStandardImplementation.cpp | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/slsReceiverSoftware/src/UDPStandardImplementation.cpp b/slsReceiverSoftware/src/UDPStandardImplementation.cpp index cda3bebad..00b1283e2 100644 --- a/slsReceiverSoftware/src/UDPStandardImplementation.cpp +++ b/slsReceiverSoftware/src/UDPStandardImplementation.cpp @@ -959,6 +959,7 @@ void UDPStandardImplementation::startReadout(){ #ifdef DEBUG5 cprintf(MAGENTA,"waiting for all packets totalP:%d\n",totalP); #endif + usleep(5000);/* Need to find optimal time (exposure time and acquisition period) **/ prev = totalP; totalP=0; @@ -2315,14 +2316,11 @@ bool UDPStandardImplementation::popAndCheckEndofAcquisition(int ithread, char* w else{ endofAcquisition = false; #ifdef DEBUG4 - switch(myDetectorType){ - case EIGER: + if(myDetectorType == EIGER){ eiger_packet_footer_t* wbuf_footer = (eiger_packet_footer_t*)(wbuffer[i] + footerOffset + HEADER_SIZE_NUM_TOT_PACKETS); //cprintf(BLUE,"footer value:0x%x\n",i,(uint64_t)(*( (uint64_t*) wbuf_footer))); cprintf(BLUE,"Fnum[%d]:%d\n",i,(uint32_t)(*( (uint64_t*) wbuf_footer))); cprintf(BLUE,"Pnum[%d]:%d\n",i,*( (uint16_t*) wbuf_footer->packetNumber)); - break; - default: break; } #endif if(myDetectorType == EIGER){ From 6600d82fc7f3700d77a6c13ceeb5c4dd1a1d46e1 Mon Sep 17 00:00:00 2001 From: Dhanya Maliakal Date: Thu, 19 Nov 2015 11:18:35 +0100 Subject: [PATCH 66/68] some small unimportant changes such as removign eiger header structure form generic socket and initializign differentlclients --- slsReceiverSoftware/include/genericSocket.h | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/slsReceiverSoftware/include/genericSocket.h b/slsReceiverSoftware/include/genericSocket.h index aebdd8066..97cd3223e 100644 --- a/slsReceiverSoftware/include/genericSocket.h +++ b/slsReceiverSoftware/include/genericSocket.h @@ -93,12 +93,7 @@ enum communicationProtocol{ UDP /**< UDP */ }; -typedef struct -{ - unsigned char header_before[20]; - unsigned char fnum[4]; - unsigned char header_after[24]; -} eiger_image_header; + genericSocket(const char* const host_ip_or_name, unsigned short int const port_number, communicationProtocol p, int ps = DEFAULT_PACKET_SIZE) : // portno(port_number), @@ -120,6 +115,7 @@ typedef struct strcpy(lastClientIP,"none"); strcpy(thisClientIP,"none1"); strcpy(dummyClientIP,"dummy"); + differentClients = 0; struct hostent *hostInfo = gethostbyname(host_ip_or_name); if (hostInfo == NULL){ @@ -184,6 +180,7 @@ typedef struct strcpy(lastClientIP,"none"); strcpy(thisClientIP,"none1"); strcpy(dummyClientIP,"dummy"); + differentClients = 0; if(serverAddress.sin_port == htons(port_number)){ socketDescriptor = -10; From 8b0772abaec30e3d44482bf2479c947d1b7f4da0 Mon Sep 17 00:00:00 2001 From: Dhanya Maliakal Date: Thu, 19 Nov 2015 14:21:04 +0100 Subject: [PATCH 67/68] got rid of memory leak when using gui --- .../src/slsReceiverTCPIPInterface.cpp | 21 ++++++++++--------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/slsReceiverSoftware/src/slsReceiverTCPIPInterface.cpp b/slsReceiverSoftware/src/slsReceiverTCPIPInterface.cpp index 403aa7309..4af5e0424 100644 --- a/slsReceiverSoftware/src/slsReceiverTCPIPInterface.cpp +++ b/slsReceiverSoftware/src/slsReceiverTCPIPInterface.cpp @@ -1107,7 +1107,7 @@ int slsReceiverTCPIPInterface::moench_read_frame(){ for(i=0;igetFramesCaught()){ startAcquisitionIndex=-1; #ifdef VERYVERBOSE cout<<"haven't caught any frame yet"<readFrame(fName,&raw,startAcquisitionIndex,startFrameIndex); - - /**send garbage with -1 index to try again*/ + //send garbage with -1 index to try again if (raw == NULL){ startAcquisitionIndex = -1; #ifdef VERYVERBOSE @@ -1675,7 +1676,7 @@ int slsReceiverTCPIPInterface::eiger_read_frame(){ #endif } - /**proper frame*/ + //proper frame else{//cout<<"**** got proper frame ******"< Date: Mon, 23 Nov 2015 11:54:55 +0100 Subject: [PATCH 68/68] some cleanup for rest --- slsReceiverSoftware/include/UDPInterface.h | 6 +- .../include/UDPRESTImplementation.h | 864 +------ .../include/UDPStandardImplementation.h | 10 +- .../src/UDPRESTImplementation.cpp | 2104 +---------------- .../src/UDPStandardImplementation.cpp | 9 +- 5 files changed, 205 insertions(+), 2788 deletions(-) diff --git a/slsReceiverSoftware/include/UDPInterface.h b/slsReceiverSoftware/include/UDPInterface.h index 798c45f6c..b00f038cb 100644 --- a/slsReceiverSoftware/include/UDPInterface.h +++ b/slsReceiverSoftware/include/UDPInterface.h @@ -39,13 +39,17 @@ class UDPInterface { * * set*() : anytime after initialize(), multiple times * - * startReceiver(): anytime after initialize(). Will fail if state already is 'running': + * startReceiver(): anytime after initialize(). Will fail in TCPIP itself if state already is 'running': * * Only startReceiver() does change the data receiver configuration, it does pass the whole configuration cache to the data receiver. * * abort(), //FIXME: needed? * * stopReceiver() : anytime after initialize(). Will do nothing if state already is idle. + * Otherwise, sets status to transmitting when shutting down sockets + * then to run_finished when all data obtained + * then to idle when returning from this function + * * * getStatus() returns the actual state of the data receiver - idle, running or error, enum defined in include/sls_receiver_defs.h * diff --git a/slsReceiverSoftware/include/UDPRESTImplementation.h b/slsReceiverSoftware/include/UDPRESTImplementation.h index f335ba9d2..374199721 100644 --- a/slsReceiverSoftware/include/UDPRESTImplementation.h +++ b/slsReceiverSoftware/include/UDPRESTImplementation.h @@ -7,36 +7,21 @@ ***********************************************/ -#include "sls_receiver_defs.h" -#include "receiver_defs.h" -#include "genericSocket.h" -#include "circularFifo.h" -#include "singlePhotonDetector.h" -#include "slsReceiverData.h" -#include "moenchCommonMode.h" - #include "UDPBaseImplementation.h" - -#ifdef MYROOT1 -#include -#include -#endif - #include "RestHelper.h" - #include -#include #include -#include /** * @short does all the functions for a receiver, set/get parameters, start/stop etc. */ class UDPRESTImplementation : protected virtual slsReceiverDefs, public UDPBaseImplementation { - - public: +public: + /************************************************************************* + * Constructor & Destructor ********************************************** + *************************************************************************/ /** * Constructor */ @@ -49,787 +34,116 @@ class UDPRESTImplementation : protected virtual slsReceiverDefs, public UDPBaseI protected: - void initialize_REST(); + + /************************************************************************* + * Getters *************************************************************** + * They access local cache of configuration or detector parameters ******* + *************************************************************************/ + /** + * Get Rest State + */ int get_rest_state(RestHelper * rest, string *rest_state); + /************************************************************************* + * Setters *************************************************************** + * They modify the local cache of configuration or detector parameters *** + *************************************************************************/ + /** + * Initialize REST + */ + void initialize_REST(); + + + + public: + /************************************************************************* + * Getters *************************************************************** + * They access local cache of configuration or detector parameters ******* + *************************************************************************/ + + + /************************************************************************* + * Setters *************************************************************** + * They modify the local cache of configuration or detector parameters *** + *************************************************************************/ + + /** + * Overridden method + * Configure command line parameters + * @param config_map mapping of config parameters passed from command line arguments + */ void configure(map config_map); - /** - * delete and free member parameters - */ - void deleteMembers(); + + /************************************************************************* + * Behavioral functions*************************************************** + * They may modify the status of the receiver **************************** + *************************************************************************/ /** - * initialize member parameters + * Overridden method + * Start Listening for Packets by activating all configuration settings to receiver + * When this function returns, it has status RUNNING(upon SUCCESS) or IDLE (upon failure) + * @param c error message if FAIL + * @return OK or FAIL */ - //void initializeMembers(); + int startReceiver(char *c=NULL); /** - * Set detector hostname - * @param c hostname + * Overridden method + * Stop Listening for Packets + * Calls startReadout(), which stops listening and sets status to Transmitting + * When it has read every frame in buffer, the status changes to Run_Finished + * When this function returns, receiver has status IDLE + * Pre: status is running, semaphores have been instantiated, + * Post: udp sockets shut down, status is idle, semaphores destroyed */ - //void initialize(const char *detectorHostName); - - /* Returns detector hostname - /returns hostname - * caller needs to deallocate the returned char array. - * if uninitialized, it must return NULL - */ - //char *getDetectorHostname() const; - + void stopReceiver(); /** - * Set receiver type - * @param det detector type - * Returns success or FAIL - */ - //int setDetectorType(detectorType det); - - - //Frame indices and numbers caught - /** - * Returns the frame index at start of entire acquisition (including all scans) - */ - uint32_t getStartAcquisitionIndex(); - - /** - * Returns current Frame Index Caught for an entire acquisition (including all scans) - */ - uint32_t getAcquisitionIndex(); - - /** - * Returns if acquisition started - */ - bool getAcquistionStarted(); - - /** - * Returns Frames Caught for each real time acquisition (eg. for each scan) - */ - int getFramesCaught(); - - /** - * Returns Total Frames Caught for an entire acquisition (including all scans) - */ - int getTotalFramesCaught(); - - /** - * Returns the frame index at start of each real time acquisition (eg. for each scan) - */ - uint32_t getStartFrameIndex(); - - /** - * Returns current Frame Index for each real time acquisition (eg. for each scan) - */ - uint32_t getFrameIndex(); - - /** - * Returns if measurement started - */ - bool getMeasurementStarted(); - - /** - * Resets the Total Frames Caught - * This is how the receiver differentiates between entire acquisitions - * Returns 0 - */ - void resetTotalFramesCaught(); - - - - - //file parameters - /** - * Returns File Path - */ - //char* getFilePath() const; - - /** - * Set File Path - * @param c file path - */ - //char* setFilePath(const char c[]); - - /** - * Returns File Name - */ - //char* getFileName() const; - - /** - * Set File Name (without frame index, file index and extension) - * @param c file name - */ - //char* setFileName(const char c[]); - - /** - * Returns File Index - */ - int getFileIndex(); - - /** - * Set File Index - * @param i file index - */ - int setFileIndex(int i); - - /** - * Set Frame Index Needed - * @param i frame index needed - */ - int setFrameIndexNeeded(int i); - - /** - * Set enable file write - * @param i file write enable - * Returns file write enable - */ - //int setEnableFileWrite(int i); - - /** - * Enable/disable overwrite - * @param i enable - * Returns enable over write - */ - //int setEnableOverwrite(int i); - - /** - * Returns file write enable - * 1: YES 0: NO - */ - //int getEnableFileWrite() const; - - /** - * Returns file over write enable - * 1: YES 0: NO - */ - //int getEnableOverwrite() const; - -//other parameters - - /** - * abort acquisition with minimum damage: close open files, cleanup. - * does nothing if state already is 'idle' - */ - void abort() {}; - - /** - * Returns status of receiver: idle, running or error - */ - runStatus getStatus() const; - - - /** - * Set Ethernet Interface or IP to listen to - */ - void setEthernetInterface(char* c); - - /** - * Set UDP Port Number - */ - void setUDPPortNo(int p); - void setUDPPortNo2(int p); - - /* - * Returns number of frames to receive - * This is the number of frames to expect to receiver from the detector. - * The data receiver will change from running to idle when it got this number of frames - */ - - //int getNumberOfFrames() const; - - /** - * set frame number if a positive number - */ - //int32_t setNumberOfFrames(int32_t fnum); - - - /** - * Returns scan tag - */ - //int getScanTag() const; - - /** - * set scan tag if its is a positive number - */ - //int32_t setScanTag(int32_t stag); - - /** - * Returns the number of bits per pixel - */ - //int getDynamicRange() const; - - /** - * set dynamic range if its is a positive number - */ - int32_t setDynamicRange(int32_t dr); - - /** - * Set short frame - * @param i if shortframe i=1 - */ - int setShortFrame(int i); - - /** - * Set the variable to send every nth frame to gui - * or if 0,send frame only upon gui request - */ - int setNFrameToGui(int i); - - /** set acquisition period if a positive number - */ - int64_t setAcquisitionPeriod(int64_t index); - - /** get data compression, by saving only hits - */ - bool getDataCompression(); - - /** enabl data compression, by saving only hits - /returns if failed - */ - int enableDataCompression(bool enable); - - /** - * enable 10Gbe - @param enable 1 for 10Gbe or 0 for 1 Gbe, -1 to read out - \returns enable for 10Gbe - */ - int enableTenGiga(int enable = -1); - - - -//other functions - - /** - * Returns the buffer-current frame read by receiver - * @param c pointer to current file name - * @param raw address of pointer, pointing to current frame to send to gui - * @param fnum frame number for eiger as it is not in the packet - * @param startAcquisitionIndex is the start index of the acquisition - * @param startFrameIndex is the start index of the scan - */ - void readFrame(char* c,char** raw, uint32_t &fnum, uint32_t &startAcquisitionIndex, uint32_t &startFrameIndex); - - /** - * Closes all files - * @param ithr thread index - */ - void closeFile(int ithr = -1); - - /** - * Starts Receiver - starts to listen for packets - * @param message is the error message if there is an error - * Returns success - */ - int startReceiver(char message[]); - - /** - * Stops Receiver - stops listening for packets - * Returns success - */ - int stopReceiver(); - - /** set status to transmitting and - * when fifo is empty later, sets status to run_finished + * Overridden method + * Stop Listening to Packets + * and sets status to Transmitting + * Next step would be to get all data and stop receiver completely and return with idle state + * Pre: status is running, udp sockets have been initialized, stop receiver initiated + * Post:udp sockets closed, status is transmitting, */ void startReadout(); /** - * shuts down the udp sockets - * \returns if success or fail + * Overridden method + * Shuts down and deletes UDP Sockets + * TCPIPInterface can also call this in case of illegal shutdown of receiver + * @return OK or FAIL */ int shutDownUDPSockets(); + /** + * Overridden method + * Get the buffer-current frame read by receiver + * @param c pointer to current file name + * @param raw address of pointer, pointing to current frame to send to gui + * @param startAcq start index of the acquisition + * @param startFrame start index of the scan + */ + void readFrame(char* c,char** raw, uint64_t &startAcq, uint64_t &startFrame); + + /** + * Overridden method + * Closes file / all files(data compression involves multiple files) + * TCPIPInterface can also call this in case of illegal shutdown of receiver + * @param i thread index valid for datacompression using root files, -1 for all threads + */ + void closeFile(int i = -1); + private: - /* - void not_implemented(string method_name){ - std::cout << "[WARNING] Method " << method_name << " not implemented!" << std::endl; - }; - */ - /** - * Deletes all the filter objects for single photon data - */ - void deleteFilter(); - - /** - * Constructs the filter for single photon data - */ - void setupFilter(); - - /** - * set up fifo according to the new numjobsperthread - */ - void setupFifoStructure (); - - /** - * Copy frames to gui - * uses semaphore for nth frame mode - */ - void copyFrameToGui(char* startbuf[], uint32_t fnum=-1, char* buf=NULL); - - /** - * creates udp sockets - * \returns if success or fail - */ - int createUDPSockets(); - - /** - * create listening thread - * @param destroy is true to kill all threads and start again - */ - int createListeningThreads(bool destroy = false); - - /** - * create writer threads - * @param destroy is true to kill all threads and start again - */ - int createWriterThreads(bool destroy = false); - - /** - * set thread priorities - */ - void setThreadPriorities(); - - /** - * initializes variables and creates the first file - * also does the startAcquisitionCallBack - * \returns FAIL or OK - */ - int setupWriter(); - - /** - * Creates new tree and file for compression - * @param ithr thread number - * @param iframe frame number - *\returns OK for succces or FAIL for failure - */ - int createCompressionFile(int ithr, int iframe); - - /** - * Creates new file - *\returns OK for succces or FAIL for failure - */ - int createNewFile(); - - /** - * Static function - Thread started which listens to packets. - * Called by startReceiver() - * @param this_pointer pointer to this object - */ - static void* startListeningThread(void *this_pointer); - - /** - * Static function - Thread started which writes packets to file. - * Called by startReceiver() - * @param this_pointer pointer to this object - */ - static void* startWritingThread(void *this_pointer); - - /** - * Thread started which listens to packets. - * Called by startReceiver() - * - */ - int startListening(); - - /** - * Thread started which writes packets to file. - * Called by startReceiver() - * - */ - int startWriting(); - - /** - * Writing to file without compression - * @param buf is the address of buffer popped out of fifo - * @param numpackets is the number of packets - * @param framenum current frame number - */ - void writeToFile_withoutCompression(char* buf,int numpackets, uint32_t framenum); - - /** - * Its called for the first packet of a scan or acquistion - * Sets the startframeindices and the variables to know if acquisition started - * @param ithread listening thread number - */ - void startFrameIndices(int ithread); - - /** - * This is called when udp socket is shut down - * It pops ffff instead of packet number into fifo - * to inform writers about the end of listening session - * @param ithread listening thread number - * @param rc number of bytes received - * @param pc packet count - * @param t total packets listened to - */ - void stopListening(int ithread, int rc, int &pc, int &t); - - /** - * When acquisition is over, this is called - * @param ithread listening thread number - * @param wbuffer writer buffer - */ - void stopWriting(int ithread, char* wbuffer[]); - - - /** - * data compression for each fifo output - * @param ithread listening thread number - * @param wbuffer writer buffer - * @param npackets number of packets from the fifo - * @param data pointer to the next packet start - * @param xmax max pixels in x direction - * @param ymax max pixels in y direction - * @param nf nf - */ - void handleDataCompression(int ithread, char* wbuffer[], int &npackets, char* data, int xmax, int ymax, int &nf); - - - /** structure of an eiger image header*/ - typedef struct - { - unsigned char header_before[20]; - unsigned char fnum[4]; - unsigned char header_after[24]; - } eiger_image_header; - - - /** structure of an eiger image header*/ - typedef struct - { - unsigned char num1[4]; - unsigned char num2[4]; - } eiger_packet_header; - - /** max number of listening threads */ - const static int MAX_NUM_LISTENING_THREADS = EIGER_MAX_PORTS; - - /** max number of writer threads */ - const static int MAX_NUM_WRITER_THREADS = 15; - - /** detector type */ - //detectorType myDetectorType; - - /** detector hostname */ - //char detHostname[MAX_STR_LENGTH]; - - /** status of receiver */ - //runStatus status; - - /** UDP Socket between Receiver and Detector */ - //genericSocket* udpSocket[MAX_NUM_LISTENING_THREADS]; - - /** Server UDP Port*/ - //int server_port[MAX_NUM_LISTENING_THREADS]; - - /** ethernet interface or IP to listen to */ - //char *eth; - - /** max packets per file **/ - //int maxPacketsPerFile; - - /** File write enable */ - //int enableFileWrite; - - /** File over write enable */ - //int overwrite; - - /** Complete File name */ - //char savefilename[MAX_STR_LENGTH]; - - /** File Name without frame index, file index and extension*/ - //char fileName[MAX_STR_LENGTH]; - - /** File Path */ - //char filePath[MAX_STR_LENGTH]; - - /** File Index */ - //int fileIndex; - - /** scan tag */ - //int scanTag; - - /** if frame index required in file name */ - //int frameIndexNeeded; - - /* Acquisition started */ - //bool acqStarted; - - /* Measurement started */ - //bool measurementStarted; - - /** Frame index at start of each real time acquisition (eg. for each scan) */ - //uint32_t startFrameIndex; - - /** Actual current frame index of each time acquisition (eg. for each scan) */ - //uint32_t frameIndex; - - /** Frames Caught for each real time acquisition (eg. for each scan) */ - //int packetsCaught; - - /** Total packets caught for an entire acquisition (including all scans) */ - //int totalPacketsCaught; - - /** Pckets currently in current file, starts new file when it reaches max */ - //int packetsInFile; - - /** Frame index at start of an entire acquisition (including all scans) */ - //uint32_t startAcquisitionIndex; - - /** Actual current frame index of an entire acquisition (including all scans) */ - //uint32_t acquisitionIndex; - - /** number of packets per frame*/ - //int packetsPerFrame; - - /** frame index mask */ - //uint32_t frameIndexMask; - - /** packet index mask */ - //uint32_t packetIndexMask; - - /** frame index offset */ - //int frameIndexOffset; - - /** acquisition period */ - //int64_t acquisitionPeriod; - - /** frame number */ - //int32_t numberOfFrames; - - /** dynamic range */ - //int dynamicRange; - - /** short frames */ - //int shortFrame; - - /** current frame number */ - //uint32_t currframenum; - - /** Previous Frame number from buffer */ - //uint32_t prevframenum; - - /** size of one frame */ - //int frameSize; - - /** buffer size. different from framesize as we wait for one packet instead of frame for eiger */ - //int bufferSize; - - /** oen buffer size */ - //int onePacketSize; - - /** latest data */ - //char* latestData; - - /** gui data ready */ - //int guiDataReady; - - /** points to the data to send to gui */ - //char* guiData; - - /** points to the filename to send to gui */ - //char* guiFileName; - - /** temporary number for eiger frame number as its not included in the packet */ - //uint32_t guiFrameNumber; - - /** send every nth frame to gui or only upon gui request*/ - //int nFrameToGui; - - /** fifo size */ - //unsigned int fifosize; - - /** number of jobs per thread for data compression */ - //int numJobsPerThread; - - /** datacompression - save only hits */ - //bool dataCompression; - - /** memory allocated for the buffer */ - //char *mem0[MAX_NUM_LISTENING_THREADS]; - - /** circular fifo to store addresses of data read */ - //CircularFifo* fifo[MAX_NUM_LISTENING_THREADS]; - - /** circular fifo to store addresses of data already written and ready to be resued*/ - //CircularFifo* fifoFree[MAX_NUM_LISTENING_THREADS]; - - /** Receiver buffer */ - //char *buffer[MAX_NUM_LISTENING_THREADS]; - - /** number of writer threads */ - //intt numListeningThreads; - - /** number of writer threads */ - //int numWriterThreads; - - /** to know if listening and writer threads created properly */ - //int thread_started; - - /** current listening thread index*/ - //int currentListeningThreadIndex; - - /** current writer thread index*/ - //int currentWriterThreadIndex; - - /** thread listening to packets */ - //pthread_t listening_thread[MAX_NUM_LISTENING_THREADS]; - - /** thread writing packets */ - //pthread_t writing_thread[MAX_NUM_WRITER_THREADS]; - - /** total frame count the listening thread has listened to */ - //int totalListeningFrameCount[MAX_NUM_LISTENING_THREADS]; - - /** mask showing which listening threads are running */ - //volatile uint32_t listeningthreads_mask; - - /** mask showing which writer threads are running */ - //volatile uint32_t writerthreads_mask; - - /** mask showing which threads have created files*/ - //volatile uint32_t createfile_mask; - - /** OK if file created was successful */ - //int ret_createfile; - - /** variable used to self terminate threads waiting for semaphores */ - //int killAllListeningThreads; - - /** variable used to self terminate threads waiting for semaphores */ - //int killAllWritingThreads; - - /** 10Gbe enable*/ - //int tengigaEnable; - - - - -//semaphores - /** semaphore to synchronize writer and guireader threads */ - //sem_t smp; - /** semaphore to synchronize listener threads */ - //sem_t listensmp[MAX_NUM_LISTENING_THREADS]; - /** semaphore to synchronize writer threads */ - //sem_t writersmp[MAX_NUM_WRITER_THREADS]; - - -//mutex - /** guiDataReady mutex */ - //pthread_mutex_t dataReadyMutex; - - /** mutex for status */ - //pthread_mutex_t status_mutex; - - /** mutex for progress variable currframenum */ - //pthread_mutex_t progress_mutex; - - /** mutex for writing data to file */ - //pthread_mutex_t write_mutex; - - /** File Descriptor */ - //FILE *sfilefd; - - //filter - //singlePhotonDetector *singlePhotonDet[MAX_NUM_WRITER_THREADS]; - //slsReceiverData *receiverdata[MAX_NUM_WRITER_THREADS]; - //moenchCommonMode *cmSub; - //bool commonModeSubtractionEnable; - -#ifdef MYROOT1 - /** Tree where the hits are stored */ - TTree *myTree[MAX_NUM_WRITER_THREADS]; - - /** File where the tree is saved */ - TFile *myFile[MAX_NUM_WRITER_THREADS]; -#endif - - - - /** - callback arguments are - filepath - filename - fileindex - data size - - return value is - 0 callback takes care of open,close,write file - 1 callback writes file, we have to open, close it - 2 we open, close, write file, callback does not do anything - - */ - int (*startAcquisitionCallBack)(char*, char*,int, int, void*); - void *pStartAcquisition; - - /** - args to acquisition finished callback - total frames caught - - */ - void (*acquisitionFinishedCallBack)(int, void*); - void *pAcquisitionFinished; - - - /** - args to raw data ready callback are - framenum - datapointer - datasize in bytes - file descriptor - guidatapointer (NULL, no data required) - */ - void (*rawDataReadyCallBack)(int, char*, int, FILE*, char*, void*); - void *pRawDataReady; - - /** The action which decides what the user and default responsibilites to save data are - * 0 raw data ready callback takes care of open,close,write file - * 1 callback writes file, we have to open, close it - * 2 we open, close, write file, callback does not do anything */ - int cbAction; - - -public: - - - /** - callback arguments are - filepath - filename - fileindex - datasize - - return value is - 0 callback takes care of open,close,wrie file - 1 callback writes file, we have to open, close it - 2 we open, close, write file, callback does not do anything - */ - void registerCallBackStartAcquisition(int (*func)(char*, char*,int, int, void*),void *arg){startAcquisitionCallBack=func; pStartAcquisition=arg;}; - - /** - callback argument is - toatal frames caught - */ - void registerCallBackAcquisitionFinished(void (*func)(int, void*),void *arg){acquisitionFinishedCallBack=func; pAcquisitionFinished=arg;}; - - /** - args to raw data ready callback are - framenum - datapointer - datasize in bytes - file descriptor - guidatapointer (NULL, no data required) - */ - void registerCallBackRawDataReady(void (*func)(int, char*, int, FILE*, char*, void*),void *arg){rawDataReadyCallBack=func; pRawDataReady=arg;}; - - - //REST specific bool isInitialized; RestHelper * rest ; - int rest_port; // receiver backend port - string rest_hostname; // receiver hostname + int rest_port; // receiver backend port + string rest_hostname; // receiver hostname }; diff --git a/slsReceiverSoftware/include/UDPStandardImplementation.h b/slsReceiverSoftware/include/UDPStandardImplementation.h index 3c256450a..7ec6672aa 100644 --- a/slsReceiverSoftware/include/UDPStandardImplementation.h +++ b/slsReceiverSoftware/include/UDPStandardImplementation.h @@ -8,8 +8,6 @@ #include "UDPBaseImplementation.h" -//#include "sls_receiver_defs.h" -//#include "receiver_defs.h" #include "genericSocket.h" #include "circularFifo.h" #include "singlePhotonDetector.h" @@ -39,7 +37,6 @@ class UDPStandardImplementation: private virtual slsReceiverDefs, public UDPBase /************************************************************************* * Constructor & Destructor ********************************************** - * They access local cache of configuration or detector parameters ******* *************************************************************************/ /** * Constructor @@ -155,6 +152,7 @@ class UDPStandardImplementation: private virtual slsReceiverDefs, public UDPBase /** * Overridden method * Start Listening for Packets by activating all configuration settings to receiver + * When this function returns, it has status RUNNING(upon SUCCESS) or IDLE (upon failure) * @param c error message if FAIL * @return OK or FAIL */ @@ -164,7 +162,8 @@ class UDPStandardImplementation: private virtual slsReceiverDefs, public UDPBase * Overridden method * Stop Listening for Packets * Calls startReadout(), which stops listening and sets status to Transmitting - * When it has read every frame in buffer,it returns with the status Run_Finished + * When it has read every frame in buffer, the status changes to Run_Finished + * When this function returns, receiver has status IDLE * Pre: status is running, semaphores have been instantiated, * Post: udp sockets shut down, status is idle, semaphores destroyed */ @@ -174,6 +173,7 @@ class UDPStandardImplementation: private virtual slsReceiverDefs, public UDPBase * Overridden method * Stop Listening to Packets * and sets status to Transmitting + * Next step would be to get all data and stop receiver completely and return with idle state * Pre: status is running, udp sockets have been initialized, stop receiver initiated * Post:udp sockets closed, status is transmitting */ @@ -182,6 +182,7 @@ class UDPStandardImplementation: private virtual slsReceiverDefs, public UDPBase /** * Overridden method * Shuts down and deletes UDP Sockets + * TCPIPInterface can also call this in case of illegal shutdown of receiver * @return OK or FAIL */ int shutDownUDPSockets(); @@ -199,6 +200,7 @@ class UDPStandardImplementation: private virtual slsReceiverDefs, public UDPBase /** * Overridden method * Closes file / all files(data compression involves multiple files) + * TCPIPInterface can also call this in case of illegal shutdown of receiver * @param i thread index valid for datacompression using root files, -1 for all threads */ void closeFile(int i = -1); diff --git a/slsReceiverSoftware/src/UDPRESTImplementation.cpp b/slsReceiverSoftware/src/UDPRESTImplementation.cpp index 4b2b67e4b..ab650257f 100644 --- a/slsReceiverSoftware/src/UDPRESTImplementation.cpp +++ b/slsReceiverSoftware/src/UDPRESTImplementation.cpp @@ -7,32 +7,21 @@ #include "UDPRESTImplementation.h" -#include "moench02ModuleData.h" -#include "gotthardModuleData.h" -#include "gotthardShortModuleData.h" - - -#include // SIGINT -#include // stat -#include // socket(), bind(), listen(), accept(), shut down -#include // sock_addr_in, htonl, INADDR_ANY #include // exit() #include // set precision -#include // munmap - -#include +#include // map #include +#include +#include #include - //#include "utilities.h" - using namespace std; /* TODO + filePath != getFilePath + better state handling. Now it is only IDLE - RUNNING - IDLE -*/ + */ UDPRESTImplementation::UDPRESTImplementation(){ @@ -40,6 +29,8 @@ UDPRESTImplementation::UDPRESTImplementation(){ //TODO I do not really know what to do with bottom... // Default values + isInitialized = false; + rest = NULL; rest_hostname = "localhost"; rest_port = 8081; } @@ -69,9 +60,9 @@ void UDPRESTImplementation::configure(map config_map){ for(map::const_iterator i=config_map.begin(); i != config_map.end(); i++){ std::cout << i->first << " " << i->second<< std::endl; } - */ + */ -}; +} int UDPRESTImplementation::get_rest_state(RestHelper * rest, string *rest_state){ @@ -84,13 +75,14 @@ int UDPRESTImplementation::get_rest_state(RestHelper * rest, string *rest_state) } return code; -}; +} + void UDPRESTImplementation::initialize_REST(){ - + FILE_LOG(logDEBUG) << __AT__ << " called"; FILE_LOG(logDEBUG) << __AT__ << " REST status is initialized: " << isInitialized; - + if (rest_hostname.empty()) { FILE_LOG(logDEBUG) << __AT__ <<"can't initialize with empty string or NULL for detectorHostname"; } @@ -99,7 +91,7 @@ void UDPRESTImplementation::initialize_REST(){ } else { FILE_LOG(logDEBUG) << __AT__ << "with receiverHostName=" << rest_hostname << ":" << rest_port; - + rest = new RestHelper() ; std::string answer; int code; @@ -107,7 +99,7 @@ void UDPRESTImplementation::initialize_REST(){ rest->init(rest_hostname, rest_port); code = get_rest_state(rest, &answer); std::cout << "AAAAAAAa " << answer << std::endl; - + if (code != 0){ FILE_LOG(logERROR) << __AT__ << " REST state returned: " << answer; @@ -123,21 +115,21 @@ void UDPRESTImplementation::initialize_REST(){ FILE_LOG(logERROR) << __func__ << ": " << e; throw; } - + //JsonBox::Object json_object; //json_object["configfile"] = JsonBox::Value("FILENAME"); JsonBox::Value json_request; //json_request["configfile"] = "config.py"; json_request["path"] = filePath; - + stringstream ss; string test; //std::cout << "GetSTring: " << json_request << std::endl; json_request.writeToStream(ss, false); //ss << json_request; ss >> test; - - + + code = rest->get_json("state", &answer); FILE_LOG(logDEBUG) << __AT__ << " state got " << code << " " << answer << "\n"; if (answer != "INITIALIZED"){ @@ -151,8 +143,8 @@ void UDPRESTImplementation::initialize_REST(){ FILE_LOG(logDEBUG) << __AT__ << " state/configure got " << code; code = rest->get_json("state", &answer); FILE_LOG(logDEBUG) << __AT__ << " state got " << code << " " << answer << "\n"; - - + + /* std::std::cout << string << std::endl; << "---- REST test 3: true, json object "<< std::endl; JsonBox::Value json_value; @@ -160,566 +152,53 @@ void UDPRESTImplementation::initialize_REST(){ std::cout << "JSON " << json_value["status"] << std::endl; */ } - + FILE_LOG(logDEBUG) << __func__ << ": initialize() done"; } -/* -int UDPRESTImplementation::setDetectorType(detectorType det){ - cout << "[WARNING] This is a base implementation, " << __func__ << " not correctly implemented" << endl; - return OK; -} -*/ - - -/*Frame indices and numbers caught*/ - -bool UDPRESTImplementation::getAcquistionStarted(){ - FILE_LOG(logDEBUG) << __AT__ << " called"; - return acqStarted; -}; - -bool UDPRESTImplementation::getMeasurementStarted(){ - FILE_LOG(logDEBUG) << __AT__ << " called"; - return measurementStarted; -}; - -int UDPRESTImplementation::getFramesCaught(){ - FILE_LOG(logDEBUG) << __AT__ << " called"; - return (packetsCaught/packetsPerFrame); -} - -int UDPRESTImplementation::getTotalFramesCaught(){ - FILE_LOG(logDEBUG) << __AT__ << " called"; - if (packetsPerFrame == 0){ - FILE_LOG(logWARNING) << __AT__ << " packetsPerFrame is 0!!!"; - return 0; - } - return (totalPacketsCaught/packetsPerFrame); -} - -uint32_t UDPRESTImplementation::getStartAcquisitionIndex(){ - FILE_LOG(logDEBUG) << __AT__ << " called"; - return startAcquisitionIndex; -} - -uint32_t UDPRESTImplementation::getStartFrameIndex(){ - FILE_LOG(logDEBUG) << __AT__ << " called"; - return startFrameIndex; -} - -uint32_t UDPRESTImplementation::getFrameIndex(){ - FILE_LOG(logDEBUG) << __AT__ << " called"; - - if(!packetsCaught) - frameIndex=-1; - else - frameIndex = currframenum - startFrameIndex; - return frameIndex; -} - - -uint32_t UDPRESTImplementation::getAcquisitionIndex(){ - //FILE_LOG(logDEBUG) << __AT__ << " called, idx: " << acquisitionIndex; - if(!totalPacketsCaught) - acquisitionIndex = -1; - else - acquisitionIndex = currframenum - startAcquisitionIndex; - - //FILE_LOG(logDEBUG) << __AT__ << " idx: " << acquisitionIndex - // << " currframenum: " << currframenum - // << " startAcqIdx: " << startAcquisitionIndex; - - return acquisitionIndex; -} - - -void UDPRESTImplementation::resetTotalFramesCaught(){ - FILE_LOG(logDEBUG) << __AT__ << " called"; - acqStarted = false; - startAcquisitionIndex = 0; - totalPacketsCaught = 0; -} - - -/*file parameters*/ -int UDPRESTImplementation::getFileIndex(){ - FILE_LOG(logDEBUG) << __AT__ << " called"; - return fileIndex; -} - -int UDPRESTImplementation::setFileIndex(int i){ - FILE_LOG(logDEBUG) << __AT__ << " called"; - - if(i>=0) - fileIndex = i; - - return getFileIndex(); -} - - -int UDPRESTImplementation::setFrameIndexNeeded(int i){ - FILE_LOG(logDEBUG) << __AT__ << " called"; - frameIndexNeeded = i; - return frameIndexNeeded; -} - - -/* -int UDPRESTImplementation::getEnableFileWrite() const{ - return enableFileWrite; -} - -int UDPRESTImplementation::setEnableFileWrite(int i){ - enableFileWrite=i; - return getEnableFileWrite(); -} - -int UDPRESTImplementation::getEnableOverwrite() const{ - return overwrite; -} - -int UDPRESTImplementation::setEnableOverwrite(int i){ - overwrite=i; - return getEnableOverwrite(); -} -*/ - - - - -/*other parameters*/ - -slsReceiverDefs::runStatus UDPRESTImplementation::getStatus() const{ - FILE_LOG(logDEBUG) << __AT__ << " called, status: " << status; - return status; -} - - - -/* -char *UDPRESTImplementation::getDetectorHostname() const{ - return (char*)detHostname; -} -*/ - -void UDPRESTImplementation::setEthernetInterface(char* c){ - FILE_LOG(logDEBUG) << __FILE__ << "::" << __func__ << " starting"; - - // TODO: this segfaults - //strcpy(eth,c); - //FILE_LOG(logDEBUG) << __FILE__ << "::" << __func__ << " done"; -} - -/* -void UDPRESTImplementation::setUDPPortNo(int p){ - FILE_LOG(logDEBUG) << __AT__ << " called"; - for(int i=0;i= 0) - numberOfFrames = fnum; - - return getNumberOfFrames(); -} -*/ -/* -int UDPRESTImplementation::getScanTag() const{ - return scanTag; -} -*/ - -/* -int32_t UDPRESTImplementation::setScanTag(int32_t stag){ - if(stag >= 0) - scanTag = stag; - - return getScanTag(); -} -*/ - -int32_t UDPRESTImplementation::setDynamicRange(int32_t dr){ - FILE_LOG(logDEBUG) << __FILE__ << "::" << __func__ << " starting"; - - int olddr = dynamicRange; - if(dr >= 0){ - dynamicRange = dr; - } - - FILE_LOG(logDEBUG) << __FILE__ << "::" << __func__ << " " << getDynamicRange(); - return getDynamicRange(); - - -} - -/* -int32_t UDPRESTImplementation::getDynamicRange() const{ - FILE_LOG(logDEBUG) << __FILE__ << "::" << __func__ << " starting"; - - return dynamicRange; -} -*/ - -int UDPRESTImplementation::setShortFrame(int i){ - FILE_LOG(logDEBUG) << __AT__ << " called"; - shortFrame=i; - - if(shortFrame!=-1){ - bufferSize = GOTTHARD_SHORT_ONE_PACKET_SIZE; - frameSize = GOTTHARD_SHORT_BUFFER_SIZE; - maxPacketsPerFile = SHORT_MAX_FRAMES_PER_FILE * GOTTHARD_SHORT_PACKETS_PER_FRAME; - packetsPerFrame = GOTTHARD_SHORT_PACKETS_PER_FRAME; - frameIndexMask = GOTTHARD_SHORT_FRAME_INDEX_MASK; - frameIndexOffset = GOTTHARD_SHORT_FRAME_INDEX_OFFSET; - - }else{ - onePacketSize = GOTTHARD_ONE_PACKET_SIZE; - bufferSize = GOTTHARD_BUFFER_SIZE; - frameSize = GOTTHARD_BUFFER_SIZE; - maxPacketsPerFile = MAX_FRAMES_PER_FILE * GOTTHARD_PACKETS_PER_FRAME; - packetsPerFrame = GOTTHARD_PACKETS_PER_FRAME; - frameIndexMask = GOTTHARD_FRAME_INDEX_MASK; - frameIndexOffset = GOTTHARD_FRAME_INDEX_OFFSET; - } - - - deleteFilter(); - if(dataCompression) - setupFilter(); - - return shortFrame; -} - - -int UDPRESTImplementation::setNFrameToGui(int i){ - FILE_LOG(logDEBUG) << __AT__ << " called"; - if(i>=0){ - nFrameToGui = i; - setupFifoStructure(); - } - return nFrameToGui; -} - - - -int64_t UDPRESTImplementation::setAcquisitionPeriod(int64_t index){ - FILE_LOG(logDEBUG) << __AT__ << " called"; - if(index >= 0){ - if(index != acquisitionPeriod){ - acquisitionPeriod = index; - setupFifoStructure(); - } - } - return acquisitionPeriod; -} - - -bool UDPRESTImplementation::getDataCompression(){ - FILE_LOG(logDEBUG) << __AT__ << " called"; - return dataCompression; -} - -int UDPRESTImplementation::enableDataCompression(bool enable){ - FILE_LOG(logDEBUG) << __AT__ << " called, doing nothing"; - return OK; -} - - - -/*other functions*/ - - -void UDPRESTImplementation::deleteFilter(){ - FILE_LOG(logDEBUG) << __AT__ << " called"; - int i; - cmSub=NULL; - - for(i=0;i(receiverdata[i], csize, sigma, sign, cmSub); - -} - - - -//LEO: it is not clear to me.. -void UDPRESTImplementation::setupFifoStructure(){ - FILE_LOG(logDEBUG) << __AT__ << " called, doing nothing"; -} -/* -void UDPRESTImplementation::setupFifoStructure(){ - FILE_LOG(logDEBUG) << __AT__ << " called"; - - int64_t i; - int oldn = numJobsPerThread; - - //if every nth frame mode - if(nFrameToGui) - numJobsPerThread = nFrameToGui; - - //random nth frame mode - else{ - if(!acquisitionPeriod) - i = SAMPLE_TIME_IN_NS; - else - i = SAMPLE_TIME_IN_NS/acquisitionPeriod; - if (i > MAX_JOBS_PER_THREAD) - numJobsPerThread = MAX_JOBS_PER_THREAD; - else if (i < 1) - numJobsPerThread = 1; - else - numJobsPerThread = i; - } - - //if same, return - if(oldn == numJobsPerThread) - return; - - if(myDetectorType == EIGER) - numJobsPerThread = 1; - - //otherwise memory too much if numjobsperthread is at max = 1000 - fifosize = GOTTHARD_FIFO_SIZE; - if(myDetectorType == MOENCH) - fifosize = MOENCH_FIFO_SIZE; - else if(myDetectorType == EIGER) - fifosize = EIGER_FIFO_SIZE; - - if(fifosize % numJobsPerThread) - fifosize = (fifosize/numJobsPerThread)+1; - else - fifosize = fifosize/numJobsPerThread; - - - cout << "Number of Frames per buffer:" << numJobsPerThread << endl; - cout << "Fifo Size:" << fifosize << endl; - - - for(int i=0;iisEmpty()) - fifoFree[i]->pop(buffer[i]); - delete fifoFree[i]; - } - if(fifo[i]) delete fifo[i]; - if(mem0[i]) free(mem0[i]); - fifoFree[i] = new CircularFifo(fifosize); - fifo[i] = new CircularFifo(fifosize); - - - //allocate memory - mem0[i]=(char*)malloc((bufferSize * numJobsPerThread + HEADER_SIZE_NUM_TOT_PACKETS)*fifosize); - // shud let the client know about this - if (mem0[i]==NULL){ - cout<<"++++++++++++++++++++++ COULD NOT ALLOCATE MEMORY FOR LISTENING !!!!!!!+++++++++++++++++++++" << endl; - exit(-1); - } - buffer[i]=mem0[i]; - //push the addresses into freed fifoFree and writingFifoFree - while (buffer[i]<(mem0[i]+(bufferSize * numJobsPerThread + HEADER_SIZE_NUM_TOT_PACKETS)*(fifosize-1))) { - fifoFree[i]->push(buffer[i]); - buffer[i]+=(bufferSize * numJobsPerThread + HEADER_SIZE_NUM_TOT_PACKETS); - } - } - cout << "Fifo structure(s) reconstructed" << endl; -} -*/ - - - /** acquisition functions */ -void UDPRESTImplementation::readFrame(char* c,char** raw, uint32_t &fnum, uint32_t &startAcquisitionIndex, uint32_t &startFrameIndex){ - FILE_LOG(logDEBUG) << __AT__ << " called"; - //point to gui data - if (guiData == NULL){ - guiData = latestData; - } - - //copy data and filename - strcpy(c,guiFileName); - fnum = guiFrameNumber; - startAcquisitionIndex = getStartAcquisitionIndex(); - startFrameIndex = getStartFrameIndex(); - //could not get gui data - if(!guiDataReady){ - *raw = NULL; - } - //data ready, set guidata to receive new data - else{ - *raw = guiData; - guiData = NULL; - if((nFrameToGui) && (writerthreads_mask)){ - //release after getting data - sem_post(&smp); - } - } -} - - - - - -void UDPRESTImplementation::copyFrameToGui(char* startbuf[], uint32_t fnum, char* buf){ - FILE_LOG(logDEBUG) << __AT__ << " called"; - - //random read when gui not ready - if((!nFrameToGui) && (!guiData)){ - pthread_mutex_lock(&dataReadyMutex); - guiDataReady=0; - pthread_mutex_unlock(&dataReadyMutex); - } - - //random read or nth frame read, gui needs data now - else{ - /* - //nth frame read, block current process if the guireader hasnt read it yet - if(nFrameToGui) - sem_wait(&smp); -*/ - pthread_mutex_lock(&dataReadyMutex); - guiDataReady=0; - //eiger - if(startbuf != NULL){ - int offset = 0; - int size = frameSize/EIGER_MAX_PORTS; - for(int j=0;jpost_json("state/configure", &answer, request_body); + code = rest->get_json("state", &answer); + FILE_LOG(logDEBUG) << __FILE__ << "::" << " got: " << answer; - //error - int iret; - for(int i=0;igetErrorStatus(); - if(iret){ -#ifdef VERBOSE - cout << "Could not create UDP socket on port " << server_port[i] << " error:" << iret << endl; -#endif - return FAIL; - } - } + //code = rest->post_json("state/open", &answer); + //code = rest->get_json("state", &answer); + + status = RUNNING; return OK; } @@ -727,9 +206,46 @@ int UDPRESTImplementation::createUDPSockets(){ +void UDPRESTImplementation::stopReceiver(){ + + FILE_LOG(logDEBUG) << __AT__ << "called"; + + if(status == RUNNING) + startReadout(); + + while(status == TRANSMITTING) + usleep(5000); + + //change status + status = IDLE; + + FILE_LOG(logDEBUG) << __AT__ << "exited, status " << endl; + +} + + +void UDPRESTImplementation::startReadout(){ + FILE_LOG(logDEBUG) << __AT__ << " starting"; + + status = TRANSMITTING; + + //kill udp socket to tell the listening thread to push last packet + shutDownUDPSockets(); + FILE_LOG(logDEBUG) << __FILE__ << "::" << __func__ << " done"; + +} + + + + + +/* FIXME + * Its also called by TCP in case of illegal shut down such as Ctrl + c. + * Upto you what you want to do with it. + */ int UDPRESTImplementation::shutDownUDPSockets(){ FILE_LOG(logDEBUG) << __AT__ << "called"; @@ -755,19 +271,19 @@ int UDPRESTImplementation::shutDownUDPSockets(){ } // getting the state - FILE_LOG(logWARNING) << "PLEASE WAIT WHILE CHECKING AND SHUTTING DOWN ALL CONNECTIONS!"; + FILE_LOG(logWARNING) << "PLEASE WAIT WHILE CHECKING AND SHUTTING DOWN ALL CONNECTIONS!"; code = rest->get_json("state", &answer); be_state = answer["state"].getString(); // LEO: this is probably wrong if (be_state == "OPEN"){ while (be_state != "TRANSIENT"){ - code = rest->get_json("state", &answer); - be_state = answer["state"].getString(); - cout << "be_State: " << be_state << endl; - usleep(10000); + code = rest->get_json("state", &answer); + be_state = answer["state"].getString(); + cout << "be_State: " << be_state << endl; + usleep(10000); } - + code = rest->post_json("state/close", &answer); std::cout <post_json("state/reset", &answer); @@ -787,1443 +303,29 @@ int UDPRESTImplementation::shutDownUDPSockets(){ - - -int UDPRESTImplementation::createListeningThreads(bool destroy){ - +/* FIXME + * do you really need this, this is called if registerDataCallback() is activated + * in your gui to get data from receiver. you probably have a different way + * of reconstructing complete data set from all receivers + */ +void UDPRESTImplementation::readFramee(char* c,char** raw, uint64_t &startAcq, uint64_t &startFrame){ FILE_LOG(logDEBUG) << __AT__ << " called"; - int i; - void* status; - - killAllListeningThreads = 0; - - pthread_mutex_lock(&status_mutex); - listeningthreads_mask = 0x0; - pthread_mutex_unlock(&(status_mutex)); - - if(!destroy){ - - //start listening threads - cout << "Creating Listening Threads(s)"; - - currentListeningThreadIndex = -1; - - for(i = 0; i < numListeningThreads; ++i){ - sem_init(&listensmp[i],1,0); - thread_started = 0; - currentListeningThreadIndex = i; - if(pthread_create(&listening_thread[i], NULL,startListeningThread, (void*) this)){ - cout << "Could not create listening thread with index " << i << endl; - return FAIL; - } - while(!thread_started); - cout << "."; - cout << flush; - } -#ifdef VERBOSE - cout << "Listening thread(s) created successfully." << endl; -#else - cout << endl; -#endif - }else{ - cout<<"Destroying Listening Thread(s)"<initEventTree(temp, &iframe); - //resets the pedestalSubtraction array and the commonModeSubtraction - singlePhotonDet[ithr]->newDataSet(); - if(myFile[ithr]==NULL){ - cout<<"file null"<IsOpen()){ - cout<<"file not open"< DO_NOTHING){ - //close - if(sfilefd){ - fclose(sfilefd); - sfilefd = NULL; - } - //open file - if(!overwrite){ - if (NULL == (sfilefd = fopen((const char *) (savefilename), "wx"))){ - cout << "Error: Could not create new file " << savefilename << endl; - return FAIL; - } - }else if (NULL == (sfilefd = fopen((const char *) (savefilename), "w"))){ - cout << "Error: Could not create file " << savefilename << endl; - return FAIL; - } - //setting buffer - setvbuf(sfilefd,NULL,_IOFBF,BUF_SIZE); - - //printing packet losses and file names - if(!packetsCaught) - cout << savefilename << endl; - else{ - cout << savefilename - << "\tpacket loss " - << setw(4)<GetCurrentFile(); - - if(myFile[ithr]->Write()) - //->Write(tall->GetName(),TObject::kOverwrite); - cout << "Thread " << ithr <<": wrote frames to file" << endl; - else - cout << "Thread " << ithr << ": could not write frames to file" << endl; - - }else - cout << "Thread " << ithr << ": could not write frames to file: No file or No Tree" << endl; - //close file - if(myTree[ithr] && myFile[ithr]) - myFile[ithr] = myTree[ithr]->GetCurrentFile(); - if(myFile[ithr] != NULL) - myFile[ithr]->Close(); - myFile[ithr] = NULL; - myTree[ithr] = NULL; - pthread_mutex_unlock(&write_mutex); - -#endif - } - FILE_LOG(logDEBUG) << __AT__ << "exited for thread " << ithr; } - - -int UDPRESTImplementation::startReceiver(char message[]){ - int i; - - FILE_LOG(logDEBUG) << __FILE__ << "::" << __func__ << " starting"; - initialize_REST(); - FILE_LOG(logDEBUG) << __FILE__ << "::" << __func__ << " initialized"; - - cout << "Starting Receiver" << endl; - - std::string answer; - int code; - //char *intStr = itoa(a); - //string str = string(intStr); - // TODO: remove hardcode!!! - stringstream ss; - ss << getDynamicRange(); - string str_dr = ss.str(); - stringstream ss2; - ss2 << getNumberOfFrames(); - string str_n = ss2.str(); - - - cout << "Starting Receiver" << endl; - - std::string request_body = "{\"settings\": {\"bit_depth\": " + str_dr + ", \"nimages\": " + str_n + "}}"; - //std::string request_body = "{\"settings\": {\"nimages\":1, \"scanid\":999, \"bit_depth\":16}}"; - FILE_LOG(logDEBUG) << __FILE__ << "::" << " sending this configuration body: " << request_body; - code = rest->post_json("state/configure", &answer, request_body); - code = rest->get_json("state", &answer); - FILE_LOG(logDEBUG) << __FILE__ << "::" << " got: " << answer; - - //code = rest->post_json("state/open", &answer); - //code = rest->get_json("state", &answer); - - status = RUNNING; - - //reset listening thread variables - /* - measurementStarted = false; - //should be set to zero as its added to get next start frame indices for scans for eiger - if(!acqStarted) currframenum = 0; - startFrameIndex = 0; - - for(int i = 0; i < numListeningThreads; ++i) - totalListeningFrameCount[i] = 0; - */ - //udp socket - /* - if(createUDPSockets() == FAIL){ - strcpy(message,"Could not create UDP Socket(s).\n"); - cout << endl << message << endl; - return FAIL; - } - cout << "UDP socket(s) created successfully. 1st port " << server_port[0] << endl; - - */ - /* - if(setupWriter() == FAIL){ - //stop udp socket - shutDownUDPSockets(); - - sprintf(message,"Could not create file %s.\n",savefilename); - return FAIL; - } - cout << "Successfully created file(s)" << endl; - - //done to give the gui some proper name instead of always the last file name - if(dataCompression) - sprintf(savefilename, "%s/%s_fxxx_%d_xx.root", filePath,fileName,fileIndex); - - //initialize semaphore - sem_init(&smp,1,0); - - //status - pthread_mutex_lock(&status_mutex); - status = RUNNING; - for(i=0;istartListening(); - - return this_pointer; -} - - - -void* UDPRESTImplementation::startWritingThread(void* this_pointer){ - FILE_LOG(logDEBUG) << __AT__ << " called"; - FILE_LOG(logDEBUG) << __AT__ << " doing a big bunch of nothing"; - - //((UDPRESTImplementation*)this_pointer)->startWriting(); - return this_pointer; -} - - - - - - -int UDPRESTImplementation::startListening(){ - FILE_LOG(logDEBUG) << __AT__ << " called"; - FILE_LOG(logDEBUG) << __AT__ << " doing a big bunch of nothing"; - - /* - int ithread = currentListeningThreadIndex; -#ifdef VERYVERBOSE - cout << "In startListening() " << endl; -#endif - - thread_started = 1; - - int i,total; - int lastpacketoffset, expected, rc, rc1,packetcount, maxBufferSize, carryonBufferSize; - uint32_t lastframeheader;// for moench to check for all the packets in last frame - char* tempchar = NULL; - int imageheader = 0; - if(myDetectorType==EIGER) - imageheader = EIGER_IMAGE_HEADER_SIZE; - - - while(1){ - //variables that need to be checked/set before each acquisition - carryonBufferSize = 0; - //if more than 1 listening thread, listen one packet at a time, else need to interleaved frame later - maxBufferSize = bufferSize * numJobsPerThread; -#ifdef VERYDEBUG - cout << " maxBufferSize:" << maxBufferSize << ",carryonBufferSize:" << carryonBufferSize << endl; -#endif - - if(tempchar) {delete [] tempchar;tempchar = NULL;} - if(myDetectorType != EIGER) - tempchar = new char[onePacketSize * ((packetsPerFrame/numListeningThreads) - 1)]; //gotthard: 1packet size, moench:39 packet size - - - while((1<pop(buffer[ithread]); -#ifdef VERYDEBUG - cout << ithread << " *** popped from fifo free" << (void*)buffer[ithread] << endl; -#endif - - - //receive - if(udpSocket[ithread] == NULL){ - rc = 0; - cout << ithread << "UDP Socket is NULL" << endl; - } - //normal listening - else if(!carryonBufferSize){ - - rc = udpSocket[ithread]->ReceiveDataOnly(buffer[ithread] + HEADER_SIZE_NUM_TOT_PACKETS, maxBufferSize); - expected = maxBufferSize; - - } - //the remaining packets from previous buffer - else{ -#ifdef VERYDEBUG - cout << ithread << " ***carry on buffer" << carryonBufferSize << endl; - cout << ithread << " framennum in temochar:"<<((((uint32_t)(*((uint32_t*)tempchar))) - & (frameIndexMask)) >> frameIndexOffset)<ReceiveDataOnly((buffer[ithread] + HEADER_SIZE_NUM_TOT_PACKETS + carryonBufferSize),maxBufferSize - carryonBufferSize); - expected = maxBufferSize - carryonBufferSize; - } - -#ifdef VERYDEBUG - cout << ithread << " *** rc:" << dec << rc << ". expected:" << dec << expected << endl; -#endif - - - - - //start indices for each start of scan/acquisition - eiger does it before - if((!measurementStarted) && (rc > 0) && (!ithread)) - startFrameIndices(ithread); - - //problem in receiving or end of acquisition - if((rc < expected)||(rc <= 0)){ - stopListening(ithread,rc,packetcount,total); - continue; - } - - - - //reset - packetcount = (packetsPerFrame/numListeningThreads) * numJobsPerThread; - carryonBufferSize = 0; - - - - //check if last packet valid and calculate packet count - switch(myDetectorType){ - - case MOENCH: - lastpacketoffset = (((numJobsPerThread * packetsPerFrame - 1) * onePacketSize) + HEADER_SIZE_NUM_TOT_PACKETS); -#ifdef VERYDEBUG - cout <<"first packet:"<< ((((uint32_t)(*((uint32_t*)(buffer[ithread]+HEADER_SIZE_NUM_TOT_PACKETS))))) & (packetIndexMask)) << endl; - cout <<"first header:"<< (((((uint32_t)(*((uint32_t*)(buffer[ithread]+HEADER_SIZE_NUM_TOT_PACKETS))))) & (frameIndexMask)) >> frameIndexOffset) << endl; - cout << "last packet offset:" << lastpacketoffset << endl; - cout <<"last packet:"<< ((((uint32_t)(*((uint32_t*)(buffer[ithread]+lastpacketoffset))))) & (packetIndexMask)) << endl; - cout <<"last header:"<< (((((uint32_t)(*((uint32_t*)(buffer[ithread]+lastpacketoffset))))) & (frameIndexMask)) >> frameIndexOffset) << endl; -#endif - //moench last packet value is 0 - if( ((((uint32_t)(*((uint32_t*)(buffer[ithread]+lastpacketoffset))))) & (packetIndexMask))){ - lastframeheader = ((((uint32_t)(*((uint32_t*)(buffer[ithread]+lastpacketoffset))))) & (frameIndexMask)) >> frameIndexOffset; - carryonBufferSize += onePacketSize; - lastpacketoffset -= onePacketSize; - --packetcount; - while (lastframeheader == (((((uint32_t)(*((uint32_t*)(buffer[ithread]+lastpacketoffset))))) & (frameIndexMask)) >> frameIndexOffset)){ - carryonBufferSize += onePacketSize; - lastpacketoffset -= onePacketSize; - --packetcount; - } - memcpy(tempchar, buffer[ithread]+(lastpacketoffset+onePacketSize), carryonBufferSize); -#ifdef VERYDEBUG - cout << "tempchar header:" << (((((uint32_t)(*((uint32_t*)(tempchar))))) - & (frameIndexMask)) >> frameIndexOffset) << endl; - cout <<"tempchar packet:"<< ((((uint32_t)(*((uint32_t*)(tempchar))))) - & (packetIndexMask)) << endl; -#endif - } - break; - - case GOTTHARD: - if(shortFrame == -1){ - lastpacketoffset = (((numJobsPerThread * packetsPerFrame - 1) * onePacketSize) + HEADER_SIZE_NUM_TOT_PACKETS); -#ifdef VERYDEBUG - cout << "last packet offset:" << lastpacketoffset << endl; -#endif - - if((unsigned int)(packetsPerFrame -1) != ((((uint32_t)(*((uint32_t*)(buffer[ithread]+lastpacketoffset))))+1) & (packetIndexMask))){ - memcpy(tempchar,buffer[ithread]+lastpacketoffset, onePacketSize); -#ifdef VERYDEBUG - cout << "tempchar header:" << (((((uint32_t)(*((uint32_t*)(tempchar))))+1) - & (frameIndexMask)) >> frameIndexOffset) << endl; -#endif - carryonBufferSize = onePacketSize; - --packetcount; - } - } -#ifdef VERYDEBUG - cout << "header:" << (((((uint32_t)(*((uint32_t*)(buffer[ithread] + HEADER_SIZE_NUM_TOT_PACKETS))))+1) - & (frameIndexMask)) >> frameIndexOffset) << endl; -#endif - break; - default: - - break; - - } - - - // cout<<"*********** "<fnum)<push(buffer[ithread])); -#ifdef VERYDEBUG - if(!ithread) cout << ithread << " *** pushed into listening fifo" << endl; -#endif - } - - sem_wait(&listensmp[ithread]); - - //make sure its not exiting thread - if(killAllListeningThreads){ - cout << ithread << " good bye listening thread" << endl; - if(tempchar) {delete [] tempchar;tempchar = NULL;} - pthread_exit(NULL); - } - } - */ - return OK; -} - - - - - - - - - - - - - -int UDPRESTImplementation::startWriting(){ - FILE_LOG(logDEBUG) << __AT__ << " called"; - FILE_LOG(logDEBUG) << __AT__ << " doing a big bunch of nothing"; - /* - int ithread = currentWriterThreadIndex; -#ifdef VERYVERBOSE - cout << ithread << "In startWriting()" <pop(wbuf[i]); - numpackets = (uint16_t)(*((uint16_t*)wbuf[i])); -#ifdef VERYDEBUG - cout << ithread << " numpackets:" << dec << numpackets << endl; -#endif - } - -#ifdef VERYDEBUG - cout << ithread << " numpackets:" << dec << numpackets << endl; - cout << ithread << " *** writer popped from fifo " << (void*) wbuf[0]<< endl; - cout << ithread << " *** writer popped from fifo " << (void*) wbuf[1]<< endl; -#endif - - - //last dummy packet - if(numpackets == 0xFFFF){ - stopWriting(ithread,wbuf); - continue; - } - - - - - //for progress - if(myDetectorType == EIGER){ - tempframenum = htonl(*(unsigned int*)((eiger_image_header *)((char*)(wbuf[ithread] + HEADER_SIZE_NUM_TOT_PACKETS)))->fnum); - tempframenum += (startFrameIndex-1); //eiger frame numbers start at 1, so need to -1 - }else if ((myDetectorType == GOTTHARD) && (shortFrame == -1)) - tempframenum = (((((uint32_t)(*((uint32_t*)(wbuf[ithread] + HEADER_SIZE_NUM_TOT_PACKETS))))+1)& (frameIndexMask)) >> frameIndexOffset); - else - tempframenum = ((((uint32_t)(*((uint32_t*)(wbuf[ithread] + HEADER_SIZE_NUM_TOT_PACKETS))))& (frameIndexMask)) >> frameIndexOffset); - - if(numWriterThreads == 1) - currframenum = tempframenum; - else{ - pthread_mutex_lock(&progress_mutex); - if(tempframenum > currframenum) - currframenum = tempframenum; - pthread_mutex_unlock(&progress_mutex); - } -//#ifdef VERYDEBUG - if(myDetectorType == EIGER) - cout << endl < 0){ - for(i=0;ipush(wbuf[i])); -#ifdef VERYDEBUG - cout << ithread << ":" << i+j << " fifo freed:" << (void*)wbuf[i] << endl; -#endif - } - - - } - else{ - //copy to gui - copyFrameToGui(NULL,-1,wbuf[0]+HEADER_SIZE_NUM_TOT_PACKETS); -#ifdef VERYVERBOSE - cout << ithread << " finished copying" << endl; -#endif - while(!fifoFree[0]->push(wbuf[0])); -#ifdef VERYVERBOSE - cout<<"buf freed:"<<(void*)wbuf[0]<fnum); - //gotthard has +1 for frame number and not a short frame - else if ((myDetectorType == GOTTHARD) && (shortFrame == -1)) - startFrameIndex = (((((uint32_t)(*((uint32_t*)(buffer[ithread] + HEADER_SIZE_NUM_TOT_PACKETS))))+1) - & (frameIndexMask)) >> frameIndexOffset); - else - startFrameIndex = ((((uint32_t)(*((uint32_t*)(buffer[ithread]+HEADER_SIZE_NUM_TOT_PACKETS)))) - & (frameIndexMask)) >> frameIndexOffset); - - - //start of acquisition - if(!acqStarted){ - startAcquisitionIndex=startFrameIndex; - currframenum = startAcquisitionIndex; - acqStarted = true; - cout << "startAcquisitionIndex:" << startAcquisitionIndex<push(buffer[ithread]); - exit(-1); - } - //push the last buffer into fifo - if(rc > 0){ - pc = (rc/onePacketSize); -#ifdef VERYDEBUG - cout << ithread << " *** last packetcount:" << pc << endl; -#endif - (*((uint16_t*)(buffer[ithread]))) = pc; - totalListeningFrameCount[ithread] += pc; - while(!fifo[ithread]->push(buffer[ithread])); -#ifdef VERYDEBUG - cout << ithread << " *** last lbuf1:" << (void*)buffer[ithread] << endl; -#endif - } - - - //push dummy buffer to all writer threads - for(i=0;ipop(buffer[ithread]); - (*((uint16_t*)(buffer[ithread]))) = 0xFFFF; -#ifdef VERYDEBUG - cout << ithread << " going to push in dummy buffer:" << (void*)buffer[ithread] << " with num packets:"<< (*((uint16_t*)(buffer[ithread]))) << endl; -#endif - while(!fifo[ithread]->push(buffer[ithread])); -#ifdef VERYDEBUG - cout << ithread << " pushed in dummy buffer:" << (void*)buffer[ithread] << endl; -#endif - } - - //reset mask and exit loop - pthread_mutex_lock(&status_mutex); - listeningthreads_mask^=(1< 1) - cout << "Waiting for listening to be done.. current mask:" << hex << listeningthreads_mask << endl; -#endif - while(listeningthreads_mask) - usleep(5000); -#ifdef VERYDEBUG - t = 0; - for(i=0;ipush(wbuffer[i])); -#ifdef VERYDEBUG - cout << ithread << ":" << i<< " fifo freed:" << (void*)wbuffer[i] << endl; -#endif - } - - - - //all threads need to close file, reset mask and exit loop - closeFile(ithread); - pthread_mutex_lock(&status_mutex); - writerthreads_mask^=(1< 0){ - - //for progress and packet loss calculation(new files) - if(myDetectorType == EIGER); - else if ((myDetectorType == GOTTHARD) && (shortFrame == -1)) - tempframenum = (((((uint32_t)(*((uint32_t*)(buf + HEADER_SIZE_NUM_TOT_PACKETS))))+1)& (frameIndexMask)) >> frameIndexOffset); - else - tempframenum = ((((uint32_t)(*((uint32_t*)(buf + HEADER_SIZE_NUM_TOT_PACKETS))))& (frameIndexMask)) >> frameIndexOffset); - - if(numWriterThreads == 1) - currframenum = tempframenum; - else{ - if(tempframenum > currframenum) - currframenum = tempframenum; - } -#ifdef VERYDEBUG - cout << "tempframenum:" << dec << tempframenum << " curframenum:" << currframenum << endl; -#endif - - //lock - if(numWriterThreads > 1) - pthread_mutex_lock(&write_mutex); - - - //to create new file when max reached - packetsToSave = maxPacketsPerFile - packetsInFile; - if(packetsToSave > numpackets) - packetsToSave = numpackets; -/**next time offset is still plus header length*/ - fwrite(buf+offset, 1, packetsToSave * onePacketSize, sfilefd); - packetsInFile += packetsToSave; - packetsCaught += packetsToSave; - totalPacketsCaught += packetsToSave; - - - //new file - if(packetsInFile >= maxPacketsPerFile){ - //for packet loss - lastpacket = (((packetsToSave - 1) * onePacketSize) + offset); - if(myDetectorType == EIGER); - else if ((myDetectorType == GOTTHARD) && (shortFrame == -1)) - tempframenum = (((((uint32_t)(*((uint32_t*)(buf + lastpacket))))+1)& (frameIndexMask)) >> frameIndexOffset); - else - tempframenum = ((((uint32_t)(*((uint32_t*)(buf + lastpacket))))& (frameIndexMask)) >> frameIndexOffset); - - if(numWriterThreads == 1) - currframenum = tempframenum; - else{ - if(tempframenum > currframenum) - currframenum = tempframenum; - } -#ifdef VERYDEBUG - cout << "tempframenum:" << dec << tempframenum << " curframenum:" << currframenum << endl; -#endif - //create - createNewFile(); - } - - //unlock - if(numWriterThreads > 1) - pthread_mutex_unlock(&write_mutex); - - - offset += (packetsToSave * onePacketSize); - numpackets -= packetsToSave; - } - - } - else{ - if(numWriterThreads > 1) - pthread_mutex_lock(&write_mutex); - packetsInFile += numpackets; - packetsCaught += numpackets; - totalPacketsCaught += numpackets; - if(numWriterThreads > 1) - pthread_mutex_unlock(&write_mutex); - } -} - - - - - - - - - - - - - - -void UDPRESTImplementation::handleDataCompression(int ithread, char* wbuffer[], int &npackets, char* data, int xmax, int ymax, int &nf){ - - FILE_LOG(logDEBUG) << __AT__ << " called"; - -#if defined(MYROOT1) && defined(ALLFILE_DEBUG) - writeToFile_withoutCompression(wbuf[0], numpackets,currframenum); -#endif - - eventType thisEvent = PEDESTAL; - int ndata; - char* buff = 0; - data = wbuffer[0]+ HEADER_SIZE_NUM_TOT_PACKETS; - int remainingsize = npackets * onePacketSize; - int np; - int once = 0; - double tot, tl, tr, bl, br; - int xmin = 1, ymin = 1, ix, iy; - - - while(buff = receiverdata[ithread]->findNextFrame(data,ndata,remainingsize)){ - np = ndata/onePacketSize; - - //cout<<"buff framnum:"<> frameIndexOffset)<newFrame(); - - //only for moench - if(commonModeSubtractionEnable){ - for(ix = xmin - 1; ix < xmax+1; ix++){ - for(iy = ymin - 1; iy < ymax+1; iy++){ - thisEvent = singlePhotonDet[ithread]->getEventType(buff, ix, iy, 0); - } - } - } - - - for(ix = xmin - 1; ix < xmax+1; ix++) - for(iy = ymin - 1; iy < ymax+1; iy++){ - thisEvent=singlePhotonDet[ithread]->getEventType(buff, ix, iy, commonModeSubtractionEnable); - if (nf>1000) { - tot=0; - tl=0; - tr=0; - bl=0; - br=0; - if (thisEvent==PHOTON_MAX) { - receiverdata[ithread]->getFrameNumber(buff); - //iFrame=receiverdata[ithread]->getFrameNumber(buff); -#ifdef MYROOT1 - myTree[ithread]->Fill(); - //cout << "Fill in event: frmNr: " << iFrame << " ix " << ix << " iy " << iy << " type " << thisEvent << endl; -#else - pthread_mutex_lock(&write_mutex); - if((enableFileWrite) && (sfilefd)) - singlePhotonDet[ithread]->writeCluster(sfilefd); - pthread_mutex_unlock(&write_mutex); -#endif - } - } - } - - nf++; -#ifndef ALLFILE - pthread_mutex_lock(&progress_mutex); - packetsInFile += packetsPerFrame; - packetsCaught += packetsPerFrame; - totalPacketsCaught += packetsPerFrame; - if(packetsInFile >= maxPacketsPerFile) - createNewFile(); - pthread_mutex_unlock(&progress_mutex); - -#endif - if(!once){ - copyFrameToGui(NULL,-1,buff); - once = 1; - } - } - - remainingsize -= ((buff + ndata) - data); - data = buff + ndata; - if(data > (wbuffer[0] + HEADER_SIZE_NUM_TOT_PACKETS + npackets * onePacketSize) ) - cout <<" **************ERROR SHOULD NOT COME HERE, Error 142536!"<push(wbuffer[0])); -#ifdef VERYVERBOSE - cout<<"buf freed:"<<(void*)wbuffer[0]<= 0){ - - tengigaEnable = enable; - - if(myDetectorType == EIGER){ - - if(!tengigaEnable){ - packetsPerFrame = EIGER_ONE_GIGA_CONSTANT * dynamicRange * EIGER_MAX_PORTS; - onePacketSize = EIGER_ONE_GIGA_ONE_PACKET_SIZE; - maxPacketsPerFile = EIGER_MAX_FRAMES_PER_FILE * packetsPerFrame; - }else{ - packetsPerFrame = EIGER_TEN_GIGA_CONSTANT * dynamicRange * EIGER_MAX_PORTS; - onePacketSize = EIGER_TEN_GIGA_ONE_PACKET_SIZE; - maxPacketsPerFile = EIGER_MAX_FRAMES_PER_FILE * packetsPerFrame*4; - } - frameSize = onePacketSize * packetsPerFrame; - bufferSize = (frameSize/EIGER_MAX_PORTS) + EIGER_HEADER_LENGTH;//everything one port gets (img header plus packets) - //maxPacketsPerFile = EIGER_MAX_FRAMES_PER_FILE * packetsPerFrame; - - - cout<<"packetsPerFrame:"< // socket(), bind(), listen(), accept(), shut down -//#include // sock_addr_in, htonl, INADDR_ANY #include // exit() #include //set precision for printing parameters for create new file #include //map -//#include //munmap - #include #include #include -#include using namespace std; #define WRITE_HEADERS @@ -789,7 +784,7 @@ void UDPStandardImplementation::resetAcquisitionCount(){ int UDPStandardImplementation::startReceiver(char *c){ FILE_LOG(logDEBUG) << __AT__ << " called"; - cout << "Starting Receiver" << endl; + FILE_LOG(logINFO) << "Stopping Receiver"; //RESET @@ -888,7 +883,7 @@ int UDPStandardImplementation::startReceiver(char *c){ void UDPStandardImplementation::stopReceiver(){ FILE_LOG(logDEBUG) << __AT__ << " called"; - cout << "Stopping Receiver" << endl; + FILE_LOG(logINFO) << "Stopping Receiver"; //set status to transmitting startReadout();