copy first frame to latest data no matter what and also copy only if more than packets per frame

This commit is contained in:
Dhanya Maliakal 2015-03-10 15:04:50 +01:00
parent 2f82469531
commit 6063c712f7
3 changed files with 45 additions and 36 deletions

View File

@ -688,7 +688,7 @@ void UDPBaseImplementation::copyFrameToGui(char* startbuf[], uint32_t fnum, char
pthread_mutex_unlock(&dataReadyMutex); pthread_mutex_unlock(&dataReadyMutex);
} }
//random read or nth frame read, gui needs data now //random read or nth frame read, gui needs data now or it is the first frame
else{ else{
/* /*
//nth frame read, block current process if the guireader hasnt read it yet //nth frame read, block current process if the guireader hasnt read it yet

View File

@ -921,25 +921,31 @@ void UDPStandardImplementation::readFrame(char* c,char** raw, uint32_t &fnum, ui
void UDPStandardImplementation::copyFrameToGui(char* startbuf[], uint32_t fnum, char* buf){ void UDPStandardImplementation::copyFrameToGui(char* startbuf[], uint32_t fnum, char* buf){
FILE_LOG(logDEBUG) << __AT__ << " called"; FILE_LOG(logDEBUG) << __AT__ << " called";
#ifdef VERY_VERY_DEBUG
cout << "copyframe" << endl;
#endif
//random read when gui not ready , also command line doesnt have nthframetogui //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)){ if((!nFrameToGui) && (!guiData)){
#ifdef VERY_VERY_DEBUG
cout << "doing nothing" << endl;
#endif
pthread_mutex_lock(&dataReadyMutex); pthread_mutex_lock(&dataReadyMutex);
guiDataReady=0; guiDataReady=0;
pthread_mutex_unlock(&dataReadyMutex); pthread_mutex_unlock(&dataReadyMutex);
} }
//random read or nth frame read, gui needs data now //random read or nth frame read, gui needs data now or it is the first frame
else{ else{
//cout <<"gui needs data now"<<endl; #ifdef VERY_VERY_DEBUG
/* cout << "gui needs data now or 1st frame" << endl;
//nth frame read, block current process if the guireader hasnt read it yet #endif
if(nFrameToGui)
sem_wait(&smp);
*/
pthread_mutex_lock(&dataReadyMutex); pthread_mutex_lock(&dataReadyMutex);
guiDataReady=0; guiDataReady=0;
#ifdef VERY_VERY_DEBUG
cout << "guidataready is 0, copying data" << endl;
#endif
//eiger //eiger
if(startbuf != NULL){ if(startbuf != NULL){
int offset = 0; int offset = 0;
@ -956,7 +962,6 @@ void UDPStandardImplementation::copyFrameToGui(char* startbuf[], uint32_t fnum,
cout<<"startbuf:"<<dec<<i<<hex<<":\t0x"<<((uint16_t)(*((uint16_t*)(startbuf[1] + 2+ 48+ j*1040+8+ i))))<<endl; cout<<"startbuf:"<<dec<<i<<hex<<":\t0x"<<((uint16_t)(*((uint16_t*)(startbuf[1] + 2+ 48+ j*1040+8+ i))))<<endl;
*/ */
guiFrameNumber = fnum; guiFrameNumber = fnum;
}else//other detectors }else//other detectors
memcpy(latestData,buf,bufferSize); memcpy(latestData,buf,bufferSize);
@ -965,7 +970,9 @@ void UDPStandardImplementation::copyFrameToGui(char* startbuf[], uint32_t fnum,
strcpy(guiFileName,savefilename); strcpy(guiFileName,savefilename);
guiDataReady=1; guiDataReady=1;
pthread_mutex_unlock(&dataReadyMutex); pthread_mutex_unlock(&dataReadyMutex);
#ifdef VERY_VERY_DEBUG
cout << "guidataready = 1" << endl;
#endif
//nth frame read, block current process if the guireader hasnt read it yet //nth frame read, block current process if the guireader hasnt read it yet
if(nFrameToGui){ if(nFrameToGui){
//cout<<"waiting after copying"<<endl; //cout<<"waiting after copying"<<endl;
@ -1693,9 +1700,9 @@ int UDPStandardImplementation::startListening(){
expected = maxBufferSize - carryonBufferSize; expected = maxBufferSize - carryonBufferSize;
} }
//#ifdef VERDEBUG #ifdef EIGER_DEBUG
cout << ithread << " *** rc:" << dec << rc << ". expected:" << dec << expected << endl; cout << ithread << " *** rc:" << dec << rc << ". expected:" << dec << expected << endl;
//#endif #endif
/* /*
//start indices for each start of scan/acquisition - eiger does it before //start indices for each start of scan/acquisition - eiger does it before
@ -1871,7 +1878,8 @@ int UDPStandardImplementation::startWriting(){
} }
} }
//so that the first frame is always copied
guiData = latestData;
while((1<<ithread)&writerthreads_mask){ while((1<<ithread)&writerthreads_mask){
@ -1896,15 +1904,15 @@ int UDPStandardImplementation::startWriting(){
//last dummy packet //last dummy packet
if(numpackets == 0xFFFF){ if(numpackets == 0xFFFF){
//#ifdef VERYDEBUG #ifdef VERYDEBUG
cout << "**LAST dummy packet" << endl; cout << "**LAST dummy packet" << endl;
//#endif #endif
stopWriting(ithread,wbuf); stopWriting(ithread,wbuf);
continue; continue;
} }
//#ifdef VERYDEBUG #ifdef VERYDEBUG
else cout <<"**NOT a dummy packet"<<endl; else cout <<"**NOT a dummy packet"<<endl;
//#endif #endif
@ -1969,7 +1977,8 @@ int UDPStandardImplementation::startWriting(){
} }
else{ else{
//copy to gui //copy to gui
if(numpackets == packetsPerFrame * numJobsPerThread){ //only full frames 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); copyFrameToGui(NULL,-1,wbuf[0]+HEADER_SIZE_NUM_TOT_PACKETS);
#ifdef VERYVERBOSE #ifdef VERYVERBOSE
cout << ithread << " finished copying" << endl; cout << ithread << " finished copying" << endl;
@ -2108,8 +2117,16 @@ int i;
exit(-1); exit(-1);
} }
//free buffer
if(rc <= 0){
cout << ithread << "Discarding empty frame" << endl;
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 //push the last buffer into fifo
if(rc > 0){ else{
//eiger (incomplete frames) - throw away //eiger (incomplete frames) - throw away
if((myDetectorType == EIGER) && (rc < (bufferSize * numJobsPerThread)) ){ if((myDetectorType == EIGER) && (rc < (bufferSize * numJobsPerThread)) ){
if(rc == 266240) if(rc == 266240)
@ -2135,14 +2152,6 @@ int i;
#endif #endif
} }
} }
//free buffer
else{
cout << ithread << "Discarding empty frame" << endl;
fifoFree[ithread]->push(buffer[ithread]);
#ifdef FIFO_DEBUG
cprintf(BLUE,"%d listener empty buffer pushed into fifofree %x\n", ithread, (void*)(buffer[ithread]));
#endif
}

View File

@ -1252,10 +1252,10 @@ int slsReceiverTCPIPInterface::gotthard_read_frame(){
} }
#ifdef VERBOSE #ifdef VERBOSE
if(arg!=-1){ //if(arg!=-1){
cout << "fName:" << fName << endl; cout << "fName:" << fName << endl;
cout << "findex:" << arg << endl; cout << "findex:" << arg << endl;
} //}
#endif #endif