mirror of
https://github.com/slsdetectorgroup/slsDetectorPackage.git
synced 2025-04-21 19:30:03 +02:00
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:
parent
91e5e35c73
commit
bb5ae3d2ab
@ -33,11 +33,12 @@ const enum detectorType myDetectorType=GENERIC;
|
||||
|
||||
|
||||
//define in communication_funcs
|
||||
/*
|
||||
extern int lockStatus;
|
||||
extern char lastClientIP[INET_ADDRSTRLEN];
|
||||
extern char thisClientIP[INET_ADDRSTRLEN];
|
||||
extern int differentClients;
|
||||
|
||||
*/
|
||||
|
||||
|
||||
/* global variables for optimized readout */
|
||||
|
@ -536,7 +536,7 @@ enum angleConversionParameter {
|
||||
//} angleConversionConstant;
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
#ifdef MYROOT
|
||||
protected:
|
||||
#endif
|
||||
|
||||
@ -546,7 +546,7 @@ enum angleConversionParameter {
|
||||
#include "sls_detector_funcs.h"
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
#ifdef MYROOT
|
||||
};
|
||||
#endif
|
||||
;
|
||||
|
@ -52,7 +52,9 @@ slsReceiverFunctionList::slsReceiverFunctionList():
|
||||
shortFrame(-1),
|
||||
bufferSize(BUFFER_SIZE),
|
||||
packetsPerFrame(2),
|
||||
guiRequiresData(0),
|
||||
guiDataReady(0),
|
||||
guiData(NULL),
|
||||
guiFileName(NULL),
|
||||
currframenum(0),
|
||||
writeReceiverData(0),
|
||||
pwriteReceiverDataArg(0),
|
||||
@ -67,15 +69,12 @@ slsReceiverFunctionList::slsReceiverFunctionList():
|
||||
strcpy(savefilename,"");
|
||||
strcpy(filePath,"");
|
||||
strcpy(fileName,"run");
|
||||
guiFileName = new char[MAX_STR_LENGTH];
|
||||
eth = new char[MAX_STR_LENGTH];
|
||||
strcpy(eth,"");
|
||||
// dataWriteFrame = new dataStruct;
|
||||
|
||||
latestData = new char[bufferSize];
|
||||
|
||||
|
||||
fifofree = new CircularFifo<char,FIFO_SIZE>();
|
||||
|
||||
// fifo = new CircularFifo<dataStruct,FIFO_SIZE>();
|
||||
fifo = new CircularFifo<char,FIFO_SIZE>();
|
||||
|
||||
|
||||
@ -195,7 +194,6 @@ int slsReceiverFunctionList::startReceiver(){
|
||||
if(err){
|
||||
listening_thread_running=0;
|
||||
status = IDLE;
|
||||
// if(fifo) delete fifo;
|
||||
cout << "Cant create writing thread. Status:" << status << endl << endl;
|
||||
return FAIL;
|
||||
}
|
||||
@ -211,7 +209,6 @@ int slsReceiverFunctionList::startReceiver(){
|
||||
status = IDLE;
|
||||
//stop writing thread
|
||||
pthread_join(writing_thread,NULL);
|
||||
// if(fifo) delete fifo;
|
||||
cout << endl << "Cant create listening thread. Status:" << status << endl << endl;
|
||||
return FAIL;
|
||||
}
|
||||
@ -249,8 +246,6 @@ int slsReceiverFunctionList::stopReceiver(){
|
||||
|
||||
//stop writing thread
|
||||
pthread_join(writing_thread,NULL);
|
||||
// if(fifo) delete fifo;
|
||||
//if(latestData) delete latestData;/**new*/
|
||||
}
|
||||
cout << "Receiver Stoppped.\nStatus:" << status << endl;
|
||||
|
||||
@ -396,7 +391,7 @@ int slsReceiverFunctionList::startWriting(){
|
||||
|
||||
// Variable and structure definitions
|
||||
int ret,sleepnumber=0;
|
||||
char *guiData;
|
||||
//char *guiData;
|
||||
//reset variables for each acquisition
|
||||
framesInFile=0;
|
||||
framesCaught=0;
|
||||
@ -471,11 +466,6 @@ int slsReceiverFunctionList::startWriting(){
|
||||
framesCaught++;
|
||||
totalFramesCaught++;
|
||||
currframenum = (int)(*((int*)wbuf));
|
||||
if(guiRequiresData) {
|
||||
guiData=latestData;
|
||||
} else {
|
||||
guiData=NULL;
|
||||
}
|
||||
|
||||
//write data
|
||||
if(enableFileWrite){
|
||||
@ -490,12 +480,15 @@ int slsReceiverFunctionList::startWriting(){
|
||||
|
||||
}
|
||||
|
||||
if(guiRequiresData){
|
||||
if (cbAction>=2)
|
||||
memcpy(latestData,wbuf,bufferSize);
|
||||
//memcpy(latestData,wbuf,bufferSize);
|
||||
guiRequiresData=0;
|
||||
}
|
||||
//copies gui data and sets/resets guiDataReady
|
||||
if(guiData){
|
||||
//if (cbAction>=2)
|
||||
memcpy(latestData,wbuf,bufferSize);
|
||||
strcpy(guiFileName,savefilename);
|
||||
guiDataReady=1;
|
||||
}else
|
||||
guiDataReady=0;
|
||||
|
||||
|
||||
framesInFile++;
|
||||
// delete [] dataWriteFrame->buffer;
|
||||
@ -532,26 +525,31 @@ int slsReceiverFunctionList::startWriting(){
|
||||
|
||||
|
||||
|
||||
char* slsReceiverFunctionList::readFrame(char* c){
|
||||
//ask for data
|
||||
guiRequiresData=1;
|
||||
void slsReceiverFunctionList::readFrame(char* c,char** raw){
|
||||
|
||||
//wait for it to be ready, not indefinitely
|
||||
int i=0;
|
||||
for(i=0;i<10;i++){
|
||||
if(guiRequiresData)
|
||||
//point to gui data
|
||||
if (guiData == NULL){
|
||||
guiData = latestData;
|
||||
}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);
|
||||
else
|
||||
break;
|
||||
}
|
||||
|
||||
//reset it back if not already reset
|
||||
guiRequiresData=0;
|
||||
//could not get gui data
|
||||
if(!guiDataReady)
|
||||
guiData = NULL;
|
||||
|
||||
//if no more data //if(guiRequiresData) // retun NULL;
|
||||
//cout<<"latestdata:"<<(int)(*(int*)latestData)<<endl;
|
||||
strcpy(c,savefilename);
|
||||
return latestData;
|
||||
//copy data and filename
|
||||
strcpy(c,guiFileName);
|
||||
*raw = guiData;
|
||||
|
||||
guiData = NULL;
|
||||
}
|
||||
|
||||
|
||||
|
@ -173,8 +173,10 @@ public:
|
||||
|
||||
/**
|
||||
* 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
|
||||
@ -283,8 +285,14 @@ private:
|
||||
/** number of packets per frame*/
|
||||
int packetsPerFrame;
|
||||
|
||||
/** gui wants data */
|
||||
int guiRequiresData;
|
||||
/** gui data ready */
|
||||
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 */
|
||||
int currframenum;
|
||||
@ -306,8 +314,6 @@ private:
|
||||
2 we open, close, write file, callback does not do anything
|
||||
|
||||
*/
|
||||
|
||||
|
||||
int (*startAcquisitionCallBack)(char*, char*,int, int, void*);
|
||||
void *pStartAcquisition;
|
||||
|
||||
@ -316,8 +322,6 @@ private:
|
||||
total frames caught
|
||||
|
||||
*/
|
||||
|
||||
|
||||
void (*acquisitionFinishedCallBack)(int, void*);
|
||||
void *pAcquisitionFinished;
|
||||
|
||||
@ -329,12 +333,13 @@ private:
|
||||
file descriptor
|
||||
guidatapointer (NULL, no data required)
|
||||
*/
|
||||
|
||||
|
||||
void (*rawDataReadyCallBack)(int, char*, FILE*, char*, void*);
|
||||
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;
|
||||
|
||||
public:
|
||||
@ -344,11 +349,6 @@ public:
|
||||
/** if the listening thread is running*/
|
||||
static int listening_thread_running;
|
||||
|
||||
|
||||
// dataStruct *dataWriteFrame;
|
||||
|
||||
|
||||
|
||||
/**
|
||||
callback arguments are
|
||||
filepath
|
||||
@ -362,7 +362,6 @@ public:
|
||||
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;};
|
||||
|
||||
|
||||
@ -371,8 +370,6 @@ public:
|
||||
toatal frames caught
|
||||
|
||||
*/
|
||||
|
||||
|
||||
int registerCallBackAcquisitionFinished(void (*func)(int, void*),void *arg){acquisitionFinishedCallBack=func; pAcquisitionFinished=arg;};
|
||||
|
||||
|
||||
@ -384,18 +381,11 @@ public:
|
||||
file descriptor
|
||||
guidatapointer (NULL, no data required)
|
||||
*/
|
||||
|
||||
int registerCallBackRawDataReady(void (*func)(int, char*, FILE*, char*, void*),void *arg){rawDataReadyCallBack=func; pRawDataReady=arg;};
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
@ -799,47 +799,55 @@ int slsReceiverFuncs::read_frame(){
|
||||
|
||||
//got atleast first frame, read buffer
|
||||
if(ret==OK){
|
||||
if(shortFrame!=-1){;
|
||||
if(shortFrame!=-1){
|
||||
//get frame
|
||||
raw=slsReceiverList->readFrame(fName);
|
||||
index=(int)(*(int*)raw);
|
||||
memcpy(origVal,raw,bufferSize);
|
||||
raw=NULL;
|
||||
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);
|
||||
memcpy(origVal,raw,bufferSize);
|
||||
raw=NULL;
|
||||
|
||||
//copy only the adc part
|
||||
memcpy((((char*)retval)+(SHORT_DATABYTES*shortFrame)),((char*) origVal)+4, SHORT_DATABYTES);
|
||||
//copy only the adc part
|
||||
memcpy((((char*)retval)+(SHORT_DATABYTES*shortFrame)),((char*) origVal)+4, SHORT_DATABYTES);
|
||||
}
|
||||
|
||||
}else{
|
||||
//for full frames
|
||||
while(count<20){
|
||||
//get frame
|
||||
raw=slsReceiverList->readFrame(fName);
|
||||
index=(int)(*(int*)raw);
|
||||
index2= (int)(*((int*)((char*)(raw+onebuffersize))));
|
||||
memcpy(origVal,raw,bufferSize);
|
||||
raw=NULL;
|
||||
//cout<<"funcs\tindex:"<<index<<"\tindex2:"<<index2<<endl;
|
||||
slsReceiverList->readFrame(fName,&raw);
|
||||
if (raw != NULL){
|
||||
index=(int)(*(int*)raw);
|
||||
index2= (int)(*((int*)((char*)(raw+onebuffersize))));
|
||||
memcpy(origVal,raw,bufferSize);
|
||||
raw=NULL;
|
||||
//cout<<"funcs\tindex:"<<index<<"\tindex2:"<<index2<<endl;
|
||||
|
||||
|
||||
//1 odd, 1 even
|
||||
if((index%2)!=index2%2){
|
||||
//ideal situation (should be odd, even(index+1))
|
||||
if(index%2){
|
||||
memcpy(retval,((char*) origVal)+4, onedatasize);
|
||||
memcpy((((char*)retval)+onedatasize), ((char*) origVal)+10+onedatasize, onedatasize);
|
||||
break;
|
||||
//1 odd, 1 even
|
||||
if((index%2)!=index2%2){
|
||||
//ideal situation (should be odd, even(index+1))
|
||||
if(index%2){
|
||||
memcpy(retval,((char*) origVal)+4, onedatasize);
|
||||
memcpy((((char*)retval)+onedatasize), ((char*) origVal)+10+onedatasize, onedatasize);
|
||||
break;
|
||||
}
|
||||
|
||||
//swap to even,odd
|
||||
if(index2%2){
|
||||
memcpy((((char*)retval)+onedatasize),((char*) origVal)+4, onedatasize);
|
||||
memcpy(retval, ((char*) origVal)+10+onedatasize, onedatasize);
|
||||
index=index2;
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
//swap to even,odd
|
||||
if(index2%2){
|
||||
memcpy((((char*)retval)+onedatasize),((char*) origVal)+4, onedatasize);
|
||||
memcpy(retval, ((char*) origVal)+10+onedatasize, onedatasize);
|
||||
index=index2;
|
||||
break;
|
||||
}
|
||||
|
||||
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);
|
||||
count++;
|
||||
}
|
||||
@ -847,6 +855,7 @@ int slsReceiverFuncs::read_frame(){
|
||||
if(count==20){
|
||||
cout << "same type: index:" << index << "\tindex2:" << index2 << endl;
|
||||
/**send garbage with -1 index to try again*/
|
||||
index = startIndex;
|
||||
memcpy(retval,((char*) origVal)+4, onedatasize);
|
||||
memcpy((((char*)retval)+onedatasize), ((char*) origVal)+10+onedatasize, onedatasize);
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user