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;
}
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 */
void updateOffsets();
/**
* Waits for receiver read to finish after stopping acquisition
*/
void waitForReceiverReadToFinish();
protected:

View File

@ -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);
}

View File

@ -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:

View File

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

View File

@ -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:

View File

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

View File

@ -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

View File

@ -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:"<<startFrameIndex<<endl;
prevframenum=startFrameIndex;
}
@ -373,7 +372,7 @@ int slsReceiverFunctionList::startListening(){
//start of acquisition
if(startAcquisitionIndex==-1){
startAcquisitionIndex=startFrameIndex;
currframenum =startAcquisitionIndex;
currframenum = startAcquisitionIndex;
cout<<"startAcquisitionIndex:"<<startAcquisitionIndex<<endl;
}
@ -515,7 +514,7 @@ int slsReceiverFunctionList::startWriting(){
else
currframenum = (((int)(*((int*)wbuf))) & (frameIndexMask)) >> frameIndexOffset;
//currframenum = (int)(*((int*)wbuf));
cout<<"**************curreframenm:"<<currframenum<<endl;
//cout<<"**************curreframenm:"<<currframenum<<endl;
//write data
if(enableFileWrite){

View File

@ -961,7 +961,7 @@ int slsReceiverFuncs::moench_read_frame(){
//get frame
slsReceiverList->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_PIXELS_IN_ONE_DIMENSION;y++){
for(x=0;x<(MOENCH_BYTES_IN_ONE_ROW/MOENCH_BYTES_PER_ADC);x++){
for(y=0;y<MOENCH_PIXELS_IN_ONE_ROW;y++){
memcpy((((char*)retval) +
y * MOENCH_BYTES_IN_ONE_DIMENSION +
y * MOENCH_BYTES_IN_ONE_ROW +
x * MOENCH_BYTES_PER_ADC),
(((char*) origVal) +
offset +
@ -1004,47 +1004,48 @@ int slsReceiverFuncs::moench_read_frame(){
else{
int numPackets = MOENCH_PACKETS_PER_FRAME; //40
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
offset = 4;
int packetOffset = 0;
int thisFrameNumber = (index & (MOENCH_FRAME_INDEX_MASK)) >> MOENCH_FRAME_INDEX_OFFSET;
//cout<<"this frame number:"<<thisFrameNumber<<endl;
int packetIndex,x,y;
int iPacket = 0;
offset = 4;
//cout<<"this frame number:"<<thisFrameNumber<<endl;
while (iPacket < numPackets){printf("iPacketr:%d\n",iPacket);
//read packet index
cout << endl;
//cout <<"buffer:"<<hex<<(*((int*)(((char*)origVal)+packetOffset)))<<endl;
packetIndex = (*((int*)(((char*)origVal)+packetOffset))) & MOENCH_PACKET_INDEX_MASK;
packetIndex--;
if(packetIndex ==-1) packetIndex = 39;
//cout<<"packet index:"<<hex<<packetIndex<<endl<<dec;
// cout << "buffer size: " << bufferSize << " packetOffset: " << packetOffset << endl;
//if its valid
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
while (iPacket < numPackets){
printf("iPacket:%d\n",iPacket);cout << endl;
packetIndex = (*((int*)(((char*)origVal)+packetOffset))) & MOENCH_PACKET_INDEX_MASK;
//the first packet is placed in the end
packetIndex--;
if(packetIndex ==-1)
packetIndex = 39;
//check validity
if ((packetIndex >= 40) && (packetIndex < 0))
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
offset=6;
@ -1061,16 +1062,16 @@ int slsReceiverFuncs::moench_read_frame(){
iPacket++;
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
cout << "\nstartIndex:" << startIndex << endl;
cout << "fName:" << fName << endl;
@ -1099,7 +1100,6 @@ cout<<"******************* exited loop"<<endl;
}
//return ok/fail
///ADDED BY ANNA?!?!?!? //?????????FOR GOTTHARD AS WELL?????
delete [] origVal;
delete [] retval;
@ -1261,13 +1261,10 @@ int slsReceiverFuncs::gotthard_read_frame(){
socket->SendDataOnly(&arg,sizeof(arg));
socket->SendDataOnly(retval,GOTTHARD_DATA_BYTES);
}
//return ok/fail
///ADDED BY ANNA?!?!?!?
delete [] retval;
delete [] origVal;
return ret;
}