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]++;