guiDataReady introduced so that both tcp and writing thread handshakes properly with their own variables

git-svn-id: file:///afs/psi.ch/project/sls_det_software/svn/slsDetectorSoftware@486 951219d9-93cf-4727-9268-0efd64621fa3
This commit is contained in:
l_maliakal_d 2013-03-07 16:49:47 +00:00
parent 91e5e35c73
commit bb5ae3d2ab
5 changed files with 91 additions and 93 deletions

View File

@ -33,11 +33,12 @@ const enum detectorType myDetectorType=GENERIC;
//define in communication_funcs //define in communication_funcs
/*
extern int lockStatus; extern int lockStatus;
extern char lastClientIP[INET_ADDRSTRLEN]; extern char lastClientIP[INET_ADDRSTRLEN];
extern char thisClientIP[INET_ADDRSTRLEN]; extern char thisClientIP[INET_ADDRSTRLEN];
extern int differentClients; extern int differentClients;
*/
/* global variables for optimized readout */ /* global variables for optimized readout */

View File

@ -536,7 +536,7 @@ enum angleConversionParameter {
//} angleConversionConstant; //} angleConversionConstant;
#ifdef __cplusplus #ifdef MYROOT
protected: protected:
#endif #endif
@ -546,7 +546,7 @@ enum angleConversionParameter {
#include "sls_detector_funcs.h" #include "sls_detector_funcs.h"
#endif #endif
#ifdef __cplusplus #ifdef MYROOT
}; };
#endif #endif
; ;

View File

@ -52,7 +52,9 @@ slsReceiverFunctionList::slsReceiverFunctionList():
shortFrame(-1), shortFrame(-1),
bufferSize(BUFFER_SIZE), bufferSize(BUFFER_SIZE),
packetsPerFrame(2), packetsPerFrame(2),
guiRequiresData(0), guiDataReady(0),
guiData(NULL),
guiFileName(NULL),
currframenum(0), currframenum(0),
writeReceiverData(0), writeReceiverData(0),
pwriteReceiverDataArg(0), pwriteReceiverDataArg(0),
@ -67,15 +69,12 @@ slsReceiverFunctionList::slsReceiverFunctionList():
strcpy(savefilename,""); strcpy(savefilename,"");
strcpy(filePath,""); strcpy(filePath,"");
strcpy(fileName,"run"); strcpy(fileName,"run");
guiFileName = new char[MAX_STR_LENGTH];
eth = new char[MAX_STR_LENGTH]; eth = new char[MAX_STR_LENGTH];
strcpy(eth,""); strcpy(eth,"");
// dataWriteFrame = new dataStruct;
latestData = new char[bufferSize]; latestData = new char[bufferSize];
fifofree = new CircularFifo<char,FIFO_SIZE>(); fifofree = new CircularFifo<char,FIFO_SIZE>();
// fifo = new CircularFifo<dataStruct,FIFO_SIZE>();
fifo = new CircularFifo<char,FIFO_SIZE>(); fifo = new CircularFifo<char,FIFO_SIZE>();
@ -195,7 +194,6 @@ int slsReceiverFunctionList::startReceiver(){
if(err){ if(err){
listening_thread_running=0; listening_thread_running=0;
status = IDLE; status = IDLE;
// if(fifo) delete fifo;
cout << "Cant create writing thread. Status:" << status << endl << endl; cout << "Cant create writing thread. Status:" << status << endl << endl;
return FAIL; return FAIL;
} }
@ -211,7 +209,6 @@ int slsReceiverFunctionList::startReceiver(){
status = IDLE; status = IDLE;
//stop writing thread //stop writing thread
pthread_join(writing_thread,NULL); pthread_join(writing_thread,NULL);
// if(fifo) delete fifo;
cout << endl << "Cant create listening thread. Status:" << status << endl << endl; cout << endl << "Cant create listening thread. Status:" << status << endl << endl;
return FAIL; return FAIL;
} }
@ -249,8 +246,6 @@ int slsReceiverFunctionList::stopReceiver(){
//stop writing thread //stop writing thread
pthread_join(writing_thread,NULL); pthread_join(writing_thread,NULL);
// if(fifo) delete fifo;
//if(latestData) delete latestData;/**new*/
} }
cout << "Receiver Stoppped.\nStatus:" << status << endl; cout << "Receiver Stoppped.\nStatus:" << status << endl;
@ -396,7 +391,7 @@ int slsReceiverFunctionList::startWriting(){
// Variable and structure definitions // Variable and structure definitions
int ret,sleepnumber=0; int ret,sleepnumber=0;
char *guiData; //char *guiData;
//reset variables for each acquisition //reset variables for each acquisition
framesInFile=0; framesInFile=0;
framesCaught=0; framesCaught=0;
@ -471,11 +466,6 @@ int slsReceiverFunctionList::startWriting(){
framesCaught++; framesCaught++;
totalFramesCaught++; totalFramesCaught++;
currframenum = (int)(*((int*)wbuf)); currframenum = (int)(*((int*)wbuf));
if(guiRequiresData) {
guiData=latestData;
} else {
guiData=NULL;
}
//write data //write data
if(enableFileWrite){ if(enableFileWrite){
@ -490,12 +480,15 @@ int slsReceiverFunctionList::startWriting(){
} }
if(guiRequiresData){ //copies gui data and sets/resets guiDataReady
if (cbAction>=2) if(guiData){
//if (cbAction>=2)
memcpy(latestData,wbuf,bufferSize); memcpy(latestData,wbuf,bufferSize);
//memcpy(latestData,wbuf,bufferSize); strcpy(guiFileName,savefilename);
guiRequiresData=0; guiDataReady=1;
} }else
guiDataReady=0;
framesInFile++; framesInFile++;
// delete [] dataWriteFrame->buffer; // delete [] dataWriteFrame->buffer;
@ -532,26 +525,31 @@ int slsReceiverFunctionList::startWriting(){
char* slsReceiverFunctionList::readFrame(char* c){ void slsReceiverFunctionList::readFrame(char* c,char** raw){
//ask for data
guiRequiresData=1;
//wait for it to be ready, not indefinitely //point to gui data
int i=0; if (guiData == NULL){
for(i=0;i<10;i++){ guiData = latestData;
if(guiRequiresData) }else
cout<<"gui data was not null" << endl;
//wait for gui data to be ready, not indefinitely
for(int i=0;i<10;i++){
if(!guiDataReady)
usleep(100000); usleep(100000);
else else
break; break;
} }
//reset it back if not already reset //could not get gui data
guiRequiresData=0; if(!guiDataReady)
guiData = NULL;
//if no more data //if(guiRequiresData) // retun NULL; //copy data and filename
//cout<<"latestdata:"<<(int)(*(int*)latestData)<<endl; strcpy(c,guiFileName);
strcpy(c,savefilename); *raw = guiData;
return latestData;
guiData = NULL;
} }

View File

@ -173,8 +173,10 @@ public:
/** /**
* Returns the buffer-current frame read by receiver * Returns the buffer-current frame read by receiver
* @param c pointer to current file name
* @param raw address of pointer, pointing to current frame to send to gui
*/ */
char* readFrame(char* c); void readFrame(char* c,char** raw);
/** /**
* Set short frame * Set short frame
@ -283,8 +285,14 @@ private:
/** number of packets per frame*/ /** number of packets per frame*/
int packetsPerFrame; int packetsPerFrame;
/** gui wants data */ /** gui data ready */
int guiRequiresData; int guiDataReady;
/** points to the data to send to gui */
char* guiData;
/** points to the filename to send to gui */
char* guiFileName;
/** current frame number */ /** current frame number */
int currframenum; int currframenum;
@ -306,8 +314,6 @@ private:
2 we open, close, write file, callback does not do anything 2 we open, close, write file, callback does not do anything
*/ */
int (*startAcquisitionCallBack)(char*, char*,int, int, void*); int (*startAcquisitionCallBack)(char*, char*,int, int, void*);
void *pStartAcquisition; void *pStartAcquisition;
@ -316,8 +322,6 @@ private:
total frames caught total frames caught
*/ */
void (*acquisitionFinishedCallBack)(int, void*); void (*acquisitionFinishedCallBack)(int, void*);
void *pAcquisitionFinished; void *pAcquisitionFinished;
@ -329,12 +333,13 @@ private:
file descriptor file descriptor
guidatapointer (NULL, no data required) guidatapointer (NULL, no data required)
*/ */
void (*rawDataReadyCallBack)(int, char*, FILE*, char*, void*); void (*rawDataReadyCallBack)(int, char*, FILE*, char*, void*);
void *pRawDataReady; void *pRawDataReady;
/** The action which decides what the user and default responsibilites to save data are
* 0 raw data ready callback takes care of open,close,write file
* 1 callback writes file, we have to open, close it
* 2 we open, close, write file, callback does not do anything */
int cbAction; int cbAction;
public: public:
@ -344,11 +349,6 @@ public:
/** if the listening thread is running*/ /** if the listening thread is running*/
static int listening_thread_running; static int listening_thread_running;
// dataStruct *dataWriteFrame;
/** /**
callback arguments are callback arguments are
filepath filepath
@ -362,7 +362,6 @@ public:
2 we open, close, write file, callback does not do anything 2 we open, close, write file, callback does not do anything
*/ */
void registerCallBackStartAcquisition(int (*func)(char*, char*,int, int, void*),void *arg){startAcquisitionCallBack=func; pStartAcquisition=arg;}; void registerCallBackStartAcquisition(int (*func)(char*, char*,int, int, void*),void *arg){startAcquisitionCallBack=func; pStartAcquisition=arg;};
@ -371,8 +370,6 @@ public:
toatal frames caught toatal frames caught
*/ */
int registerCallBackAcquisitionFinished(void (*func)(int, void*),void *arg){acquisitionFinishedCallBack=func; pAcquisitionFinished=arg;}; int registerCallBackAcquisitionFinished(void (*func)(int, void*),void *arg){acquisitionFinishedCallBack=func; pAcquisitionFinished=arg;};
@ -384,18 +381,11 @@ public:
file descriptor file descriptor
guidatapointer (NULL, no data required) guidatapointer (NULL, no data required)
*/ */
int registerCallBackRawDataReady(void (*func)(int, char*, FILE*, char*, void*),void *arg){rawDataReadyCallBack=func; pRawDataReady=arg;}; int registerCallBackRawDataReady(void (*func)(int, char*, FILE*, char*, void*),void *arg){rawDataReadyCallBack=func; pRawDataReady=arg;};
}; };

View File

@ -799,21 +799,28 @@ int slsReceiverFuncs::read_frame(){
//got atleast first frame, read buffer //got atleast first frame, read buffer
if(ret==OK){ if(ret==OK){
if(shortFrame!=-1){; if(shortFrame!=-1){
//get frame //get frame
raw=slsReceiverList->readFrame(fName); slsReceiverList->readFrame(fName,&raw);
//sending garbage values with index = -1 to try again
if (raw == NULL){
index = startIndex;
memcpy((((char*)retval)+(SHORT_DATABYTES*shortFrame)),((char*) origVal)+4, SHORT_DATABYTES);
}else{
index=(int)(*(int*)raw); index=(int)(*(int*)raw);
memcpy(origVal,raw,bufferSize); memcpy(origVal,raw,bufferSize);
raw=NULL; raw=NULL;
//copy only the adc part //copy only the adc part
memcpy((((char*)retval)+(SHORT_DATABYTES*shortFrame)),((char*) origVal)+4, SHORT_DATABYTES); memcpy((((char*)retval)+(SHORT_DATABYTES*shortFrame)),((char*) origVal)+4, SHORT_DATABYTES);
}
}else{ }else{
//for full frames //for full frames
while(count<20){ while(count<20){
//get frame //get frame
raw=slsReceiverList->readFrame(fName); slsReceiverList->readFrame(fName,&raw);
if (raw != NULL){
index=(int)(*(int*)raw); index=(int)(*(int*)raw);
index2= (int)(*((int*)((char*)(raw+onebuffersize)))); index2= (int)(*((int*)((char*)(raw+onebuffersize))));
memcpy(origVal,raw,bufferSize); memcpy(origVal,raw,bufferSize);
@ -840,6 +847,7 @@ int slsReceiverFuncs::read_frame(){
} }
strcpy(mess,"could not read frame due to more than 20 mismatched indices\n"); strcpy(mess,"could not read frame due to more than 20 mismatched indices\n");
}
usleep(100000); usleep(100000);
count++; count++;
} }
@ -847,6 +855,7 @@ int slsReceiverFuncs::read_frame(){
if(count==20){ if(count==20){
cout << "same type: index:" << index << "\tindex2:" << index2 << endl; cout << "same type: index:" << index << "\tindex2:" << index2 << endl;
/**send garbage with -1 index to try again*/ /**send garbage with -1 index to try again*/
index = startIndex;
memcpy(retval,((char*) origVal)+4, onedatasize); memcpy(retval,((char*) origVal)+4, onedatasize);
memcpy((((char*)retval)+onedatasize), ((char*) origVal)+10+onedatasize, onedatasize); memcpy((((char*)retval)+onedatasize), ((char*) origVal)+10+onedatasize, onedatasize);
} }