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
This commit is contained in:
l_maliakal_d
2013-05-07 14:20:01 +00:00
parent f29358992d
commit 1eae11a87a
10 changed files with 100 additions and 65 deletions

View File

@ -4667,3 +4667,11 @@ int multiSlsDetector::setReadReceiverFrequency(int i){
return ret; return ret;
} }
void multiSlsDetector::waitForReceiverReadToFinish(){
for (int idet=0; idet<thisMultiDetector->numberOfDetectors; idet++)
if (detectors[idet])
detectors[idet]->waitForReceiverReadToFinish();
}

View File

@ -1197,6 +1197,11 @@ class multiSlsDetector : public slsDetectorUtils {
/** updates the multidetector offsets */ /** updates the multidetector offsets */
void updateOffsets(); void updateOffsets();
/**
* Waits for receiver read to finish after stopping acquisition
*/
void waitForReceiverReadToFinish();
protected: protected:

View File

@ -5862,6 +5862,7 @@ int slsDetector::setFileIndex(int i) {
int retval=-1; int retval=-1;
int arg = i; int arg = i;
if(thisDetector->receiverOnlineFlag==OFFLINE_FLAG){ if(thisDetector->receiverOnlineFlag==OFFLINE_FLAG){
if(i>=0) if(i>=0)
fileIO::setFileIndex(i); fileIO::setFileIndex(i);
@ -6340,3 +6341,10 @@ int slsDetector::setReadReceiverFrequency(int i){
} }
return retval; return retval;
} }
void slsDetector::waitForReceiverReadToFinish(){
if(dataSocket)
while(dataSocket->getsocketDescriptor() >= 0)
usleep(1000);
}

View File

@ -1600,6 +1600,11 @@ class slsDetector : public slsDetectorUtils, public energyConversion {
*/ */
int setReadReceiverFrequency(int i=-1); int setReadReceiverFrequency(int i=-1);
/**
* Waits for receiver read to finish after stopping acquisition
*/
void waitForReceiverReadToFinish();
protected: protected:

View File

@ -318,9 +318,9 @@ void slsDetectorUtils::acquire(int delflag){
closeDataFile(); closeDataFile();
} }
}else{ }else
while(stopReceiver()!=OK); stopReceiver();
}
pthread_mutex_unlock(&mg); pthread_mutex_unlock(&mg);

View File

@ -680,6 +680,12 @@ virtual ROI* getROI(int &n)=0;
virtual int setReadReceiverFrequency(int i=-1)=0; virtual int setReadReceiverFrequency(int i=-1)=0;
/**
* Waits for receiver read to finish after stopping acquisition
*/
virtual void waitForReceiverReadToFinish()=0;
protected: protected:

View File

@ -210,7 +210,7 @@ void postProcessing::doProcessing(double *lfdata, int delflag, string fname) {
if (GetCurrentPositionIndex()<=1 || npos<2) { if (GetCurrentPositionIndex()<=1 || npos<2) {
#ifdef VERBOSE #ifdef VERBOSE
cout << "init dataset" << endl; cout << "init dataset" << endl;
#endif #endif
if (*correctionMask&(1<< ANGULAR_CONVERSION)) if (*correctionMask&(1<< ANGULAR_CONVERSION))
@ -243,12 +243,12 @@ void postProcessing::doProcessing(double *lfdata, int delflag, string fname) {
fname=createFileName(); fname=createFileName();
pthread_mutex_unlock(&mp); pthread_mutex_unlock(&mp);
//} //}
if((*correctionMask)&(1<<WRITE_FILE)) { if((*correctionMask)&(1<<WRITE_FILE)) {
writeDataFile (fname+ext,np,val, err,ang,'f'); writeDataFile (fname+ext,np,val, err,ang,'f');
} }
if (dataReady) { if (dataReady) {
thisData=new detectorData(val,err,ang,getCurrentProgress(),(fname+ext).c_str(),np); thisData=new detectorData(val,err,ang,getCurrentProgress(),(fname+ext).c_str(),np);
dataReady(thisData, currentFrameIndex, pCallbackArg); dataReady(thisData, currentFrameIndex, pCallbackArg);
@ -426,31 +426,38 @@ void* postProcessing::processData(int delflag) {
bool newData=false; bool newData=false;
char currentfName[MAX_STR_LENGTH]=""; char currentfName[MAX_STR_LENGTH]="";
int currentfIndex=0; int currentfIndex=0;
while(1){ while(1){
cout.flush(); cout.flush();
cout<<flush; cout<<flush;
//if (checkJoinThread()) break;
usleep(200000); usleep(200000);
//get progress
pthread_mutex_lock(&mg); pthread_mutex_lock(&mg);
caught=getReceiverCurrentFrameIndex(); caught=getReceiverCurrentFrameIndex();
pthread_mutex_unlock(&mg); pthread_mutex_unlock(&mg);
if(setReceiverOnline()==OFFLINE_FLAG)
caught=prevCaught;
incrementProgress(caught-prevCaught); incrementProgress(caught-prevCaught);
if(caught-prevCaught) newData=true; if(caught-prevCaught) newData=true;
else newData=false; else newData=false;
prevCaught=caught; prevCaught=caught;
if (checkJoinThread()) break; if (checkJoinThread()) break;
//read frame if new data
if(newData){ if(newData){
strcpy(currentfName,""); strcpy(currentfName,"");
pthread_mutex_lock(&mg); pthread_mutex_lock(&mg);
int* receiverData = readFrameFromReceiver(currentfName,currentfIndex); int* receiverData = readFrameFromReceiver(currentfName,currentfIndex);
pthread_mutex_unlock(&mg); pthread_mutex_unlock(&mg);
if(setReceiverOnline()==OFFLINE_FLAG)
receiverData = NULL;
if(receiverData == NULL){ if(receiverData == NULL){
currentfIndex = -1;
cout<<"****Detector Data returned is NULL***"<<endl; cout<<"****Detector Data returned is NULL***"<<endl;
return 0;
} }
//not garbage frame
if(currentfIndex>=0){ if(currentfIndex>=0){
fdata=decodeData(receiverData); fdata=decodeData(receiverData);
delete [] receiverData; delete [] receiverData;

View File

@ -34,8 +34,8 @@
#define MOENCH_DATA_BYTES (1280*MOENCH_PACKETS_PER_FRAME) #define MOENCH_DATA_BYTES (1280*MOENCH_PACKETS_PER_FRAME)
#define MOENCH_BYTES_PER_ADC (40*2) #define MOENCH_BYTES_PER_ADC (40*2)
#define MOENCH_PIXELS_IN_ONE_DIMENSION 160 #define MOENCH_PIXELS_IN_ONE_ROW 160
#define MOENCH_BYTES_IN_ONE_DIMENSION (MOENCH_PIXELS_IN_ONE_DIMENSION*2) #define MOENCH_BYTES_IN_ONE_ROW (MOENCH_PIXELS_IN_ONE_ROW*2)
#define MOENCH_FRAME_INDEX_MASK 0xFFFFFF00 #define MOENCH_FRAME_INDEX_MASK 0xFFFFFF00

View File

@ -138,6 +138,8 @@ void slsReceiverFunctionList::setEthernetInterface(char* c){
int slsReceiverFunctionList::getFrameIndex(){ int slsReceiverFunctionList::getFrameIndex(){
if(startFrameIndex==-1) if(startFrameIndex==-1)
frameIndex=0; frameIndex=0;
else if(myDetectorType == MOENCH)
frameIndex=currframenum - startFrameIndex;
else else
frameIndex=(currframenum - startFrameIndex)/packetsPerFrame; frameIndex=(currframenum - startFrameIndex)/packetsPerFrame;
return frameIndex; return frameIndex;
@ -148,12 +150,11 @@ int slsReceiverFunctionList::getFrameIndex(){
int slsReceiverFunctionList::getAcquisitionIndex(){ int slsReceiverFunctionList::getAcquisitionIndex(){
if(startAcquisitionIndex==-1) if(startAcquisitionIndex==-1)
acquisitionIndex=0; acquisitionIndex=0;
else{ else if(myDetectorType == MOENCH)
if(myDetectorType == MOENCH) acquisitionIndex=currframenum - startAcquisitionIndex;
acquisitionIndex=(currframenum - startAcquisitionIndex); else
else
acquisitionIndex=(currframenum - startAcquisitionIndex)/packetsPerFrame; acquisitionIndex=(currframenum - startAcquisitionIndex)/packetsPerFrame;
}
return acquisitionIndex; return acquisitionIndex;
} }
@ -364,8 +365,6 @@ int slsReceiverFunctionList::startListening(){
else else
startFrameIndex = ((((int)(*((int*)buffer))) & (frameIndexMask)) >> frameIndexOffset)-1; startFrameIndex = ((((int)(*((int*)buffer))) & (frameIndexMask)) >> frameIndexOffset)-1;
//startFrameIndex -= packetsPerFrame;
// startFrameIndex -=1;
//cout<<"startFrameIndex:"<<startFrameIndex<<endl; //cout<<"startFrameIndex:"<<startFrameIndex<<endl;
prevframenum=startFrameIndex; prevframenum=startFrameIndex;
} }
@ -373,7 +372,7 @@ int slsReceiverFunctionList::startListening(){
//start of acquisition //start of acquisition
if(startAcquisitionIndex==-1){ if(startAcquisitionIndex==-1){
startAcquisitionIndex=startFrameIndex; startAcquisitionIndex=startFrameIndex;
currframenum =startAcquisitionIndex; currframenum = startAcquisitionIndex;
cout<<"startAcquisitionIndex:"<<startAcquisitionIndex<<endl; cout<<"startAcquisitionIndex:"<<startAcquisitionIndex<<endl;
} }
@ -515,7 +514,7 @@ int slsReceiverFunctionList::startWriting(){
else else
currframenum = (((int)(*((int*)wbuf))) & (frameIndexMask)) >> frameIndexOffset; currframenum = (((int)(*((int*)wbuf))) & (frameIndexMask)) >> frameIndexOffset;
//currframenum = (int)(*((int*)wbuf)); //currframenum = (int)(*((int*)wbuf));
cout<<"**************curreframenm:"<<currframenum<<endl; //cout<<"**************curreframenm:"<<currframenum<<endl;
//write data //write data
if(enableFileWrite){ if(enableFileWrite){

View File

@ -961,7 +961,7 @@ int slsReceiverFuncs::moench_read_frame(){
//get frame //get frame
slsReceiverList->readFrame(fName,&raw); slsReceiverList->readFrame(fName,&raw);
if (raw == NULL){ if (raw == NULL){
index = startIndex; index = startIndex-1;
cout << "didnt get data. Gui will try again" << endl; cout << "didnt get data. Gui will try again" << endl;
}else{ }else{
//upto 40 indices, look at just index1 and index2 for now //upto 40 indices, look at just index1 and index2 for now
@ -977,11 +977,11 @@ int slsReceiverFuncs::moench_read_frame(){
count = 0; count = 0;
offset = 4; offset = 4;
j=0; j=0;
for(x=0;x<(MOENCH_BYTES_IN_ONE_DIMENSION/MOENCH_BYTES_PER_ADC);x++){ for(x=0;x<(MOENCH_BYTES_IN_ONE_ROW/MOENCH_BYTES_PER_ADC);x++){
for(y=0;y<MOENCH_PIXELS_IN_ONE_DIMENSION;y++){ for(y=0;y<MOENCH_PIXELS_IN_ONE_ROW;y++){
memcpy((((char*)retval) + memcpy((((char*)retval) +
y * MOENCH_BYTES_IN_ONE_DIMENSION + y * MOENCH_BYTES_IN_ONE_ROW +
x * MOENCH_BYTES_PER_ADC), x * MOENCH_BYTES_PER_ADC),
(((char*) origVal) + (((char*) origVal) +
offset + offset +
@ -1004,47 +1004,48 @@ int slsReceiverFuncs::moench_read_frame(){
else{ else{
int numPackets = MOENCH_PACKETS_PER_FRAME; //40 int numPackets = MOENCH_PACKETS_PER_FRAME; //40
int onePacketSize = MOENCH_DATA_BYTES / MOENCH_PACKETS_PER_FRAME; //1280*40 / 40 = 1280 int onePacketSize = MOENCH_DATA_BYTES / MOENCH_PACKETS_PER_FRAME; //1280*40 / 40 = 1280
int packetDatabytes_row = onePacketSize * (MOENCH_BYTES_IN_ONE_ROW / MOENCH_BYTES_PER_ADC); //1280 * 4 = 5120
int partsPerFrame = onePacketSize / MOENCH_BYTES_PER_ADC; // 1280 / 80 = 16 int partsPerFrame = onePacketSize / MOENCH_BYTES_PER_ADC; // 1280 / 80 = 16
offset = 4;
int packetOffset = 0; int packetOffset = 0;
int thisFrameNumber = (index & (MOENCH_FRAME_INDEX_MASK)) >> MOENCH_FRAME_INDEX_OFFSET; int thisFrameNumber = (index & (MOENCH_FRAME_INDEX_MASK)) >> MOENCH_FRAME_INDEX_OFFSET;
//cout<<"this frame number:"<<thisFrameNumber<<endl;
int packetIndex,x,y; int packetIndex,x,y;
int iPacket = 0; int iPacket = 0;
offset = 4; offset = 4;
//cout<<"this frame number:"<<thisFrameNumber<<endl;
while (iPacket < numPackets){printf("iPacketr:%d\n",iPacket); while (iPacket < numPackets){
//read packet index printf("iPacket:%d\n",iPacket);cout << endl;
cout << endl;
//cout <<"buffer:"<<hex<<(*((int*)(((char*)origVal)+packetOffset)))<<endl; packetIndex = (*((int*)(((char*)origVal)+packetOffset))) & MOENCH_PACKET_INDEX_MASK;
packetIndex = (*((int*)(((char*)origVal)+packetOffset))) & MOENCH_PACKET_INDEX_MASK; //the first packet is placed in the end
packetIndex--;
packetIndex--; if(packetIndex ==-1)
if(packetIndex ==-1) packetIndex = 39; packetIndex = 39;
//cout<<"packet index:"<<hex<<packetIndex<<endl<<dec;
// cout << "buffer size: " << bufferSize << " packetOffset: " << packetOffset << endl; //check validity
//if its valid if ((packetIndex >= 40) && (packetIndex < 0))
if ((packetIndex < 40) && (packetIndex >= 0)){
// if(packetIndex == 1){
x = packetIndex / 10;
y = packetIndex % 10;cout<<"x:"<<x<<"\t y:"<<y<<endl;
//copy 16 times 80 bytes
for (i = 0; i < partsPerFrame; i++) {
memcpy((((char*)retval) +
y * 16 * MOENCH_BYTES_IN_ONE_DIMENSION +
i * MOENCH_BYTES_IN_ONE_DIMENSION +
x * MOENCH_BYTES_PER_ADC),
// &i,4);
(((char*) origVal) +
iPacket * offset +
iPacket * onePacketSize +
i * MOENCH_BYTES_PER_ADC + 4) ,
MOENCH_BYTES_PER_ADC);
//y++;
}
}else
cout << "cannot decode packet index:" << packetIndex << endl; cout << "cannot decode packet index:" << packetIndex << endl;
else{
x = packetIndex / 10;
y = packetIndex % 10;
cout<<"x:"<<x<<" y:"<<y<<endl;
//copy 16 times 80 bytes
for (i = 0; i < partsPerFrame; i++) {
memcpy((((char*)retval) +
y * packetDatabytes_row +
i * MOENCH_BYTES_IN_ONE_ROW +
x * MOENCH_BYTES_PER_ADC),
(((char*) origVal) +
iPacket * offset +
iPacket * onePacketSize +
i * MOENCH_BYTES_PER_ADC + 4) ,
MOENCH_BYTES_PER_ADC);
}
}
//increment //increment
offset=6; offset=6;
@ -1061,16 +1062,16 @@ int slsReceiverFuncs::moench_read_frame(){
iPacket++; iPacket++;
packetOffset = packetOffset + offset + onePacketSize; packetOffset = packetOffset + offset + onePacketSize;
}*/ }*/
//cout<<"found or exited"<<endl;
} }
cout<<"******************* exited loop"<<endl;
} }
//******************************************************** //********************************************************
arg=((index - startIndex)/MOENCH_PACKETS_PER_FRAME)-1; arg=index - startIndex;
#ifdef VERBOSE #ifdef VERBOSE
cout << "\nstartIndex:" << startIndex << endl; cout << "\nstartIndex:" << startIndex << endl;
cout << "fName:" << fName << endl; cout << "fName:" << fName << endl;
@ -1099,7 +1100,6 @@ cout<<"******************* exited loop"<<endl;
} }
//return ok/fail //return ok/fail
///ADDED BY ANNA?!?!?!? //?????????FOR GOTTHARD AS WELL?????
delete [] origVal; delete [] origVal;
delete [] retval; delete [] retval;
@ -1261,13 +1261,10 @@ int slsReceiverFuncs::gotthard_read_frame(){
socket->SendDataOnly(&arg,sizeof(arg)); socket->SendDataOnly(&arg,sizeof(arg));
socket->SendDataOnly(retval,GOTTHARD_DATA_BYTES); socket->SendDataOnly(retval,GOTTHARD_DATA_BYTES);
} }
//return ok/fail
///ADDED BY ANNA?!?!?!?
delete [] retval; delete [] retval;
delete [] origVal; delete [] origVal;
return ret; return ret;
} }