From 1eae11a87a322b1d418f30aafeb394c9e275642a Mon Sep 17 00:00:00 2001 From: l_maliakal_d Date: Tue, 7 May 2013 14:20:01 +0000 Subject: [PATCH] fixed the undefined state of gui when acquisition stopped git-svn-id: file:///afs/psi.ch/project/sls_det_software/svn/slsDetectorSoftware@545 951219d9-93cf-4727-9268-0efd64621fa3 --- .../multiSlsDetector/multiSlsDetector.cpp | 8 ++ .../multiSlsDetector/multiSlsDetector.h | 5 ++ .../slsDetector/slsDetector.cpp | 8 ++ slsDetectorSoftware/slsDetector/slsDetector.h | 5 ++ .../slsDetector/slsDetectorUtils.cpp | 6 +- .../slsDetector/slsDetectorUtils.h | 6 ++ .../slsDetectorAnalysis/postProcessing.cpp | 23 +++-- .../slsReceiver/receiver_defs.h | 4 +- .../slsReceiver/slsReceiverFunctionList.cpp | 17 ++-- .../slsReceiver/slsReceiver_funcs.cpp | 83 +++++++++---------- 10 files changed, 100 insertions(+), 65 deletions(-) diff --git a/slsDetectorSoftware/multiSlsDetector/multiSlsDetector.cpp b/slsDetectorSoftware/multiSlsDetector/multiSlsDetector.cpp index 42fe9b2e9..6304988f0 100644 --- a/slsDetectorSoftware/multiSlsDetector/multiSlsDetector.cpp +++ b/slsDetectorSoftware/multiSlsDetector/multiSlsDetector.cpp @@ -4667,3 +4667,11 @@ int multiSlsDetector::setReadReceiverFrequency(int i){ return ret; } + + + +void multiSlsDetector::waitForReceiverReadToFinish(){ + for (int idet=0; idetnumberOfDetectors; idet++) + if (detectors[idet]) + detectors[idet]->waitForReceiverReadToFinish(); +} diff --git a/slsDetectorSoftware/multiSlsDetector/multiSlsDetector.h b/slsDetectorSoftware/multiSlsDetector/multiSlsDetector.h index 147b3e0b0..3aafa7fc1 100644 --- a/slsDetectorSoftware/multiSlsDetector/multiSlsDetector.h +++ b/slsDetectorSoftware/multiSlsDetector/multiSlsDetector.h @@ -1197,6 +1197,11 @@ class multiSlsDetector : public slsDetectorUtils { /** updates the multidetector offsets */ void updateOffsets(); + /** + * Waits for receiver read to finish after stopping acquisition + */ + void waitForReceiverReadToFinish(); + protected: diff --git a/slsDetectorSoftware/slsDetector/slsDetector.cpp b/slsDetectorSoftware/slsDetector/slsDetector.cpp index 217913328..adde92ef5 100644 --- a/slsDetectorSoftware/slsDetector/slsDetector.cpp +++ b/slsDetectorSoftware/slsDetector/slsDetector.cpp @@ -5862,6 +5862,7 @@ int slsDetector::setFileIndex(int i) { int retval=-1; int arg = i; + if(thisDetector->receiverOnlineFlag==OFFLINE_FLAG){ if(i>=0) fileIO::setFileIndex(i); @@ -6340,3 +6341,10 @@ int slsDetector::setReadReceiverFrequency(int i){ } return retval; } + + +void slsDetector::waitForReceiverReadToFinish(){ + if(dataSocket) + while(dataSocket->getsocketDescriptor() >= 0) + usleep(1000); +} diff --git a/slsDetectorSoftware/slsDetector/slsDetector.h b/slsDetectorSoftware/slsDetector/slsDetector.h index 8a70194f2..c5a5570b9 100644 --- a/slsDetectorSoftware/slsDetector/slsDetector.h +++ b/slsDetectorSoftware/slsDetector/slsDetector.h @@ -1600,6 +1600,11 @@ class slsDetector : public slsDetectorUtils, public energyConversion { */ int setReadReceiverFrequency(int i=-1); + /** + * Waits for receiver read to finish after stopping acquisition + */ + void waitForReceiverReadToFinish(); + protected: diff --git a/slsDetectorSoftware/slsDetector/slsDetectorUtils.cpp b/slsDetectorSoftware/slsDetector/slsDetectorUtils.cpp index 749b6c0b0..e07c3afda 100644 --- a/slsDetectorSoftware/slsDetector/slsDetectorUtils.cpp +++ b/slsDetectorSoftware/slsDetector/slsDetectorUtils.cpp @@ -318,9 +318,9 @@ void slsDetectorUtils::acquire(int delflag){ closeDataFile(); } - }else{ - while(stopReceiver()!=OK); - } + }else + stopReceiver(); + pthread_mutex_unlock(&mg); diff --git a/slsDetectorSoftware/slsDetector/slsDetectorUtils.h b/slsDetectorSoftware/slsDetector/slsDetectorUtils.h index d6819b264..e3ae9701d 100644 --- a/slsDetectorSoftware/slsDetector/slsDetectorUtils.h +++ b/slsDetectorSoftware/slsDetector/slsDetectorUtils.h @@ -680,6 +680,12 @@ virtual ROI* getROI(int &n)=0; virtual int setReadReceiverFrequency(int i=-1)=0; +/** + * Waits for receiver read to finish after stopping acquisition +*/ +virtual void waitForReceiverReadToFinish()=0; + + protected: diff --git a/slsDetectorSoftware/slsDetectorAnalysis/postProcessing.cpp b/slsDetectorSoftware/slsDetectorAnalysis/postProcessing.cpp index e77ef2c97..2f2282056 100644 --- a/slsDetectorSoftware/slsDetectorAnalysis/postProcessing.cpp +++ b/slsDetectorSoftware/slsDetectorAnalysis/postProcessing.cpp @@ -210,7 +210,7 @@ void postProcessing::doProcessing(double *lfdata, int delflag, string fname) { if (GetCurrentPositionIndex()<=1 || npos<2) { #ifdef VERBOSE cout << "init dataset" << endl; -#endif +#endif if (*correctionMask&(1<< ANGULAR_CONVERSION)) @@ -243,12 +243,12 @@ void postProcessing::doProcessing(double *lfdata, int delflag, string fname) { fname=createFileName(); pthread_mutex_unlock(&mp); //} - + if((*correctionMask)&(1<=0){ fdata=decodeData(receiverData); delete [] receiverData; diff --git a/slsDetectorSoftware/slsReceiver/receiver_defs.h b/slsDetectorSoftware/slsReceiver/receiver_defs.h index 32cfbc2aa..a2cc1aaf6 100755 --- a/slsDetectorSoftware/slsReceiver/receiver_defs.h +++ b/slsDetectorSoftware/slsReceiver/receiver_defs.h @@ -34,8 +34,8 @@ #define MOENCH_DATA_BYTES (1280*MOENCH_PACKETS_PER_FRAME) #define MOENCH_BYTES_PER_ADC (40*2) -#define MOENCH_PIXELS_IN_ONE_DIMENSION 160 -#define MOENCH_BYTES_IN_ONE_DIMENSION (MOENCH_PIXELS_IN_ONE_DIMENSION*2) +#define MOENCH_PIXELS_IN_ONE_ROW 160 +#define MOENCH_BYTES_IN_ONE_ROW (MOENCH_PIXELS_IN_ONE_ROW*2) #define MOENCH_FRAME_INDEX_MASK 0xFFFFFF00 diff --git a/slsDetectorSoftware/slsReceiver/slsReceiverFunctionList.cpp b/slsDetectorSoftware/slsReceiver/slsReceiverFunctionList.cpp index c872982bf..b40a4484b 100644 --- a/slsDetectorSoftware/slsReceiver/slsReceiverFunctionList.cpp +++ b/slsDetectorSoftware/slsReceiver/slsReceiverFunctionList.cpp @@ -138,6 +138,8 @@ void slsReceiverFunctionList::setEthernetInterface(char* c){ int slsReceiverFunctionList::getFrameIndex(){ if(startFrameIndex==-1) frameIndex=0; + else if(myDetectorType == MOENCH) + frameIndex=currframenum - startFrameIndex; else frameIndex=(currframenum - startFrameIndex)/packetsPerFrame; return frameIndex; @@ -148,12 +150,11 @@ int slsReceiverFunctionList::getFrameIndex(){ int slsReceiverFunctionList::getAcquisitionIndex(){ if(startAcquisitionIndex==-1) acquisitionIndex=0; - else{ - if(myDetectorType == MOENCH) - acquisitionIndex=(currframenum - startAcquisitionIndex); -else + else if(myDetectorType == MOENCH) + acquisitionIndex=currframenum - startAcquisitionIndex; + else acquisitionIndex=(currframenum - startAcquisitionIndex)/packetsPerFrame; - } + return acquisitionIndex; } @@ -364,8 +365,6 @@ int slsReceiverFunctionList::startListening(){ else startFrameIndex = ((((int)(*((int*)buffer))) & (frameIndexMask)) >> frameIndexOffset)-1; - //startFrameIndex -= packetsPerFrame; - // startFrameIndex -=1; //cout<<"startFrameIndex:"<> frameIndexOffset; //currframenum = (int)(*((int*)wbuf)); - cout<<"**************curreframenm:"<readFrame(fName,&raw); if (raw == NULL){ - index = startIndex; + index = startIndex-1; cout << "didnt get data. Gui will try again" << endl; }else{ //upto 40 indices, look at just index1 and index2 for now @@ -977,11 +977,11 @@ int slsReceiverFuncs::moench_read_frame(){ count = 0; offset = 4; j=0; - for(x=0;x<(MOENCH_BYTES_IN_ONE_DIMENSION/MOENCH_BYTES_PER_ADC);x++){ - for(y=0;y> MOENCH_FRAME_INDEX_OFFSET; - //cout<<"this frame number:"<= 0)){ - // if(packetIndex == 1){ - x = packetIndex / 10; - y = packetIndex % 10;cout<<"x:"<= 40) && (packetIndex < 0)) cout << "cannot decode packet index:" << packetIndex << endl; + else{ + + x = packetIndex / 10; + y = packetIndex % 10; + cout<<"x:"<SendDataOnly(&arg,sizeof(arg)); socket->SendDataOnly(retval,GOTTHARD_DATA_BYTES); } - //return ok/fail - ///ADDED BY ANNA?!?!?!? delete [] retval; delete [] origVal; - return ret; }