From 476d1b452f61a1212c8eaf39d90fd28bd5ab89e1 Mon Sep 17 00:00:00 2001 From: Dhanya Maliakal Date: Fri, 10 Jul 2015 16:04:29 +0200 Subject: [PATCH] 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(); }