mirror of
https://github.com/slsdetectorgroup/slsDetectorPackage.git
synced 2025-04-28 17:10:03 +02:00
gotthard receiver works so far without cpu file write and tcp generic socket lock
git-svn-id: file:///afs/psi.ch/project/sls_det_software/svn/slsDetectorSoftware@337 951219d9-93cf-4727-9268-0efd64621fa3
This commit is contained in:
parent
6ee21ba810
commit
8f7872d056
@ -16,6 +16,8 @@
|
|||||||
#define MAXMODS 24
|
#define MAXMODS 24
|
||||||
/** maxmimum number of detectors ina multidetector structure*/
|
/** maxmimum number of detectors ina multidetector structure*/
|
||||||
#define MAXDET 100
|
#define MAXDET 100
|
||||||
|
/** header length for data :gotthard*/
|
||||||
|
#define HEADERLENGTH 12
|
||||||
|
|
||||||
typedef double double32_t;
|
typedef double double32_t;
|
||||||
typedef float float32_t;
|
typedef float float32_t;
|
||||||
@ -503,6 +505,8 @@ enum angleConversionParameter {
|
|||||||
SAMPLE_Y /**< sample displacement orthogonal to the beam */
|
SAMPLE_Y /**< sample displacement orthogonal to the beam */
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
//typedef struct {
|
//typedef struct {
|
||||||
//float center; /**< center of the module (channel at which the radius is perpendicular to the module surface) */
|
//float center; /**< center of the module (channel at which the radius is perpendicular to the module surface) */
|
||||||
//float ecenter; /**< error in the center determination */
|
//float ecenter; /**< error in the center determination */
|
||||||
|
@ -124,7 +124,9 @@ enum {
|
|||||||
|
|
||||||
F_LOCK_RECEIVER, /**< locks receiver */
|
F_LOCK_RECEIVER, /**< locks receiver */
|
||||||
|
|
||||||
F_GET_FRAME_INDEX /**< gets the frame index */
|
F_GET_FRAME_INDEX, /**< gets the frame index */
|
||||||
|
|
||||||
|
F_RESET_FRAMES_CAUGHT /**< resets the frames caught */
|
||||||
|
|
||||||
/* Always append functions hereafter!!! */
|
/* Always append functions hereafter!!! */
|
||||||
|
|
||||||
|
@ -1939,7 +1939,7 @@ int read_frame(int file_des) {
|
|||||||
return OK;
|
return OK;
|
||||||
} else {
|
} else {
|
||||||
//might add delay????
|
//might add delay????
|
||||||
if(getFrames()>-2) {printf("in hereeee: frames:%d\n",getFrames());
|
if(getFrames()>-2) {
|
||||||
dataret=FAIL;
|
dataret=FAIL;
|
||||||
sprintf(mess,"no data and run stopped: %d frames left\n",(int)(getFrames()+2));
|
sprintf(mess,"no data and run stopped: %d frames left\n",(int)(getFrames()+2));
|
||||||
printf("%s\n",mess);
|
printf("%s\n",mess);
|
||||||
|
@ -123,7 +123,8 @@ multiSlsDetector::multiSlsDetector(int id) : slsDetectorUtils(), shmId(-1)
|
|||||||
strcpy(thisMultiDetector->fileName,"run");
|
strcpy(thisMultiDetector->fileName,"run");
|
||||||
/** set fileIndex to default to 0*/
|
/** set fileIndex to default to 0*/
|
||||||
thisMultiDetector->fileIndex=0;
|
thisMultiDetector->fileIndex=0;
|
||||||
|
/** set frames per file to default to 1*/
|
||||||
|
thisMultiDetector->framesPerFile=1;
|
||||||
|
|
||||||
/** set progress Index to default to 0*/
|
/** set progress Index to default to 0*/
|
||||||
thisMultiDetector->progressIndex=0;
|
thisMultiDetector->progressIndex=0;
|
||||||
@ -229,7 +230,7 @@ multiSlsDetector::multiSlsDetector(int id) : slsDetectorUtils(), shmId(-1)
|
|||||||
filePath=thisMultiDetector->filePath;
|
filePath=thisMultiDetector->filePath;
|
||||||
fileName=thisMultiDetector->fileName;
|
fileName=thisMultiDetector->fileName;
|
||||||
fileIndex=&thisMultiDetector->fileIndex;
|
fileIndex=&thisMultiDetector->fileIndex;
|
||||||
|
framesPerFile=&thisMultiDetector->framesPerFile;
|
||||||
|
|
||||||
|
|
||||||
for (int i=0; i<thisMultiDetector->numberOfDetectors; i++) {
|
for (int i=0; i<thisMultiDetector->numberOfDetectors; i++) {
|
||||||
@ -3714,6 +3715,52 @@ int multiSlsDetector::getCurrentFrameIndex() {
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
int multiSlsDetector::resetFramesCaught(int index) {
|
||||||
|
int ret=-100, ret1;
|
||||||
|
for (int i=0; i<thisMultiDetector->numberOfDetectors; i++){
|
||||||
|
if (detectors[i]){
|
||||||
|
ret1=detectors[i]->resetFramesCaught(index);
|
||||||
|
if (ret==-100)
|
||||||
|
ret=ret1;
|
||||||
|
else if (ret!=ret1)
|
||||||
|
ret=-1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
int* multiSlsDetector::readFrameFromReceiver(){
|
||||||
|
int nel=(thisMultiDetector->dataBytes)/sizeof(int);
|
||||||
|
int n;
|
||||||
|
int* retval=new int[nel];
|
||||||
|
int *retdet, *p=retval;
|
||||||
|
|
||||||
|
for (int id=0; id<thisMultiDetector->numberOfDetectors; id++) {
|
||||||
|
if (detectors[id]) {
|
||||||
|
retdet=detectors[id]->readFrameFromReceiver();
|
||||||
|
if (retdet) {
|
||||||
|
n=detectors[id]->getDataBytes();
|
||||||
|
memcpy(p,retdet,n);
|
||||||
|
delete [] retdet;
|
||||||
|
p+=n/sizeof(int);
|
||||||
|
}else {
|
||||||
|
#ifdef VERBOSE
|
||||||
|
cout << "Receiver for detector " << id << " does not have data left " << endl;
|
||||||
|
#endif
|
||||||
|
delete [] retval;
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return retval;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
int multiSlsDetector::lockReceiver(int lock) {
|
int multiSlsDetector::lockReceiver(int lock) {
|
||||||
|
|
||||||
int ret=-100, ret1;
|
int ret=-100, ret1;
|
||||||
|
@ -111,6 +111,8 @@ class multiSlsDetector : public slsDetectorUtils {
|
|||||||
char fileName[MAX_STR_LENGTH];
|
char fileName[MAX_STR_LENGTH];
|
||||||
/** path of the output files */
|
/** path of the output files */
|
||||||
char filePath[MAX_STR_LENGTH];
|
char filePath[MAX_STR_LENGTH];
|
||||||
|
/** max frames per file */
|
||||||
|
int framesPerFile;
|
||||||
|
|
||||||
/** corrections to be applied to the data \see ::correctionFlags */
|
/** corrections to be applied to the data \see ::correctionFlags */
|
||||||
int correctionMask;
|
int correctionMask;
|
||||||
@ -1084,6 +1086,17 @@ class multiSlsDetector : public slsDetectorUtils {
|
|||||||
*/
|
*/
|
||||||
int getCurrentFrameIndex();
|
int getCurrentFrameIndex();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* resets framescaught
|
||||||
|
* @param index frames caught by receiver
|
||||||
|
* @param index if frame index is needed
|
||||||
|
*/
|
||||||
|
int resetFramesCaught(int index=-1);
|
||||||
|
|
||||||
|
/**
|
||||||
|
/returns a frame read from recever
|
||||||
|
*/
|
||||||
|
int* readFrameFromReceiver();
|
||||||
|
|
||||||
/** Locks/Unlocks the connection to the receiver
|
/** Locks/Unlocks the connection to the receiver
|
||||||
/param lock sets (1), usets (0), gets (-1) the lock
|
/param lock sets (1), usets (0), gets (-1) the lock
|
||||||
|
@ -674,6 +674,9 @@ int slsDetector::initializeDetectorSize(detectorType type) {
|
|||||||
filePath=thisDetector->filePath;
|
filePath=thisDetector->filePath;
|
||||||
fileName=parentDet->fileName;
|
fileName=parentDet->fileName;
|
||||||
fileIndex=parentDet->fileIndex;
|
fileIndex=parentDet->fileIndex;
|
||||||
|
framesPerFile=parentDet->framesPerFile;
|
||||||
|
if(thisDetector->myDetectorType==GOTTHARD)
|
||||||
|
setFramesPerFile(20000);
|
||||||
|
|
||||||
thisReceiver = new receiverInterface(dataSocket);
|
thisReceiver = new receiverInterface(dataSocket);
|
||||||
|
|
||||||
@ -5557,12 +5560,6 @@ int slsDetector::stopReceiver(){
|
|||||||
ret=updateReceiver();
|
ret=updateReceiver();
|
||||||
}
|
}
|
||||||
|
|
||||||
//increment file index
|
|
||||||
if(ret==OK){
|
|
||||||
fileIO::setFileIndex(fileIO::getFileIndex()+1);
|
|
||||||
setFileIndex(fileIO::getFileIndex());
|
|
||||||
}
|
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -5665,6 +5662,81 @@ int slsDetector::getCurrentFrameIndex(){
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
int slsDetector::resetFramesCaught(int index){
|
||||||
|
int fnum=F_RESET_FRAMES_CAUGHT;
|
||||||
|
int ret = FAIL;
|
||||||
|
int retval=-1;
|
||||||
|
int arg=index;
|
||||||
|
|
||||||
|
if (setReceiverOnline(ONLINE_FLAG)==ONLINE_FLAG) {
|
||||||
|
#ifdef VERBOSE
|
||||||
|
std::cout << "Reset Frames Caught by Receiver:" << arg << std::endl;
|
||||||
|
#endif
|
||||||
|
ret=thisReceiver->sendInt(fnum,retval,arg);
|
||||||
|
if(ret==FORCE_UPDATE)
|
||||||
|
ret=updateReceiver();
|
||||||
|
}
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
int* slsDetector::readFrameFromReceiver(){
|
||||||
|
int fnum=F_READ_FRAME;
|
||||||
|
int nel=(thisDetector->dataBytes+HEADERLENGTH)/sizeof(int);//2572/
|
||||||
|
int* retval=new int[nel];
|
||||||
|
int* origVal=new int[nel];
|
||||||
|
int ret=FAIL;
|
||||||
|
int n;
|
||||||
|
char mess[100]="Nothing";
|
||||||
|
|
||||||
|
|
||||||
|
if (setReceiverOnline(ONLINE_FLAG)==ONLINE_FLAG) {
|
||||||
|
#ifdef VERBOSE
|
||||||
|
std::cout<< "slsDetector: Reading frame from receiver "<< thisDetector->dataBytes+HEADERLENGTH << " " <<nel <<std::endl;
|
||||||
|
#endif
|
||||||
|
if (dataSocket) {
|
||||||
|
if (dataSocket->Connect()>=0) {
|
||||||
|
dataSocket->SendDataOnly(&fnum,sizeof(fnum));
|
||||||
|
dataSocket->ReceiveDataOnly(&ret,sizeof(ret));
|
||||||
|
|
||||||
|
if (ret==FAIL) {
|
||||||
|
n= dataSocket->ReceiveDataOnly(mess,sizeof(mess));
|
||||||
|
std::cout<< "Detector returned: " << mess << " " << n << std::endl;
|
||||||
|
delete [] origVal;
|
||||||
|
delete [] retval;
|
||||||
|
return NULL;
|
||||||
|
} else {
|
||||||
|
n=dataSocket->ReceiveDataOnly(origVal,thisDetector->dataBytes+HEADERLENGTH);
|
||||||
|
#ifdef VERBOSE
|
||||||
|
std::cout<< "Received "<< n << " data bytes" << std::endl;
|
||||||
|
#endif
|
||||||
|
if (n!=thisDetector->dataBytes+HEADERLENGTH) {
|
||||||
|
std::cout<<endl<< "wrong data size received: received " << n << " but expected " << thisDetector->dataBytes+HEADERLENGTH << std::endl;
|
||||||
|
ret=FAIL;
|
||||||
|
delete [] origVal;
|
||||||
|
delete [] retval;
|
||||||
|
return NULL;
|
||||||
|
}//worked
|
||||||
|
else{
|
||||||
|
memcpy(retval,((char*) origVal)+2, getDataBytes()/2);
|
||||||
|
memcpy((((char*)retval)+getDataBytes()/2), ((char*) origVal)+8+getDataBytes()/2, getDataBytes()/2);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
dataSocket->Disconnect();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
delete [] origVal;
|
||||||
|
return retval;//(retval+HEADERLENGTH/sizeof(int));
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
int slsDetector::lockReceiver(int lock){
|
int slsDetector::lockReceiver(int lock){
|
||||||
int fnum=F_LOCK_RECEIVER;
|
int fnum=F_LOCK_RECEIVER;
|
||||||
int ret = FAIL;
|
int ret = FAIL;
|
||||||
|
@ -1459,6 +1459,18 @@ class slsDetector : public slsDetectorUtils, public energyConversion {
|
|||||||
*/
|
*/
|
||||||
int getCurrentFrameIndex();
|
int getCurrentFrameIndex();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* resets framescaught
|
||||||
|
* @param index frames caught by receiver
|
||||||
|
* @param index if frame index is needed
|
||||||
|
*/
|
||||||
|
int resetFramesCaught(int index=-1);
|
||||||
|
|
||||||
|
/**
|
||||||
|
/returns a frame read from recever
|
||||||
|
*/
|
||||||
|
int* readFrameFromReceiver();
|
||||||
|
|
||||||
/** Locks/Unlocks the connection to the receiver
|
/** Locks/Unlocks the connection to the receiver
|
||||||
/param lock sets (1), usets (0), gets (-1) the lock
|
/param lock sets (1), usets (0), gets (-1) the lock
|
||||||
/returns lock status of the receiver
|
/returns lock status of the receiver
|
||||||
|
@ -462,6 +462,11 @@ class slsDetectorBase : public virtual slsDetectorDefs {
|
|||||||
virtual int lockReceiver(int lock=-1)=0;
|
virtual int lockReceiver(int lock=-1)=0;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
/returns a frame read from recever
|
||||||
|
*/
|
||||||
|
virtual int* readFrameFromReceiver()=0;
|
||||||
|
|
||||||
/** returns detector type string from detector type index
|
/** returns detector type string from detector type index
|
||||||
\param t string can be Mythen, Pilatus, Eiger, Gotthard, Agipd, Unknown
|
\param t string can be Mythen, Pilatus, Eiger, Gotthard, Agipd, Unknown
|
||||||
\returns MYTHEN, PILATUS, EIGER, GOTTHARD, AGIPD, GENERIC
|
\returns MYTHEN, PILATUS, EIGER, GOTTHARD, AGIPD, GENERIC
|
||||||
|
@ -778,19 +778,8 @@ string slsDetectorCommand::cmdAcquire(int narg, char *args[], int action) {
|
|||||||
|
|
||||||
|
|
||||||
myDet->setOnline(ONLINE_FLAG);
|
myDet->setOnline(ONLINE_FLAG);
|
||||||
bool receiver=(myDet->setReceiverOnline()==ONLINE_FLAG);
|
|
||||||
|
|
||||||
if(receiver)
|
|
||||||
if(myDet->startReceiver()==OK)
|
|
||||||
usleep(2000000);
|
|
||||||
else return string("could not start receiver");
|
|
||||||
|
|
||||||
myDet->acquire();
|
myDet->acquire();
|
||||||
|
|
||||||
if(receiver)
|
|
||||||
myDet->stopReceiver();
|
|
||||||
|
|
||||||
|
|
||||||
return string("");
|
return string("");
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -41,6 +41,8 @@ slsDetectorUtils::slsDetectorUtils() {
|
|||||||
|
|
||||||
void slsDetectorUtils::acquire(int delflag){
|
void slsDetectorUtils::acquire(int delflag){
|
||||||
|
|
||||||
|
bool receiver = (setReceiverOnline()==ONLINE_FLAG);
|
||||||
|
|
||||||
// setTotalProgress();
|
// setTotalProgress();
|
||||||
//moved these 2 here for measurement change
|
//moved these 2 here for measurement change
|
||||||
progressIndex=0;
|
progressIndex=0;
|
||||||
@ -109,6 +111,25 @@ void slsDetectorUtils::acquire(int delflag){
|
|||||||
ns1=1;
|
ns1=1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(receiver){
|
||||||
|
if(getReceiverStatus()!=IDLE)
|
||||||
|
stopReceiver();
|
||||||
|
if(setReceiverOnline()==OFFLINE_FLAG)
|
||||||
|
*stoppedFlag=1;
|
||||||
|
|
||||||
|
|
||||||
|
//resets frames caught in receiver
|
||||||
|
if ((timerValue[FRAME_NUMBER]*timerValue[CYCLES_NUMBER])>1)
|
||||||
|
resetFramesCaught(1);
|
||||||
|
else
|
||||||
|
resetFramesCaught(0);
|
||||||
|
|
||||||
|
if(setReceiverOnline()==OFFLINE_FLAG)
|
||||||
|
*stoppedFlag=1;
|
||||||
|
else
|
||||||
|
setReceiverAcquiring(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
if (*threadedProcessing) {
|
if (*threadedProcessing) {
|
||||||
startThread(delflag);
|
startThread(delflag);
|
||||||
@ -192,9 +213,6 @@ void slsDetectorUtils::acquire(int delflag){
|
|||||||
if (*stoppedFlag==0) {
|
if (*stoppedFlag==0) {
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
executeAction(headerBefore);
|
executeAction(headerBefore);
|
||||||
|
|
||||||
if (*correctionMask&(1<< ANGULAR_CONVERSION) || aclog || eclog) {
|
if (*correctionMask&(1<< ANGULAR_CONVERSION) || aclog || eclog) {
|
||||||
@ -206,12 +224,10 @@ void slsDetectorUtils::acquire(int delflag){
|
|||||||
if (aclog)
|
if (aclog)
|
||||||
aclog->addStep(getCurrentPosition(), getCurrentFileName());
|
aclog->addStep(getCurrentPosition(), getCurrentFileName());
|
||||||
|
|
||||||
|
|
||||||
if (eclog)
|
if (eclog)
|
||||||
eclog->addStep(setDAC(-1,THRESHOLD), getCurrentFileName());
|
eclog->addStep(setDAC(-1,THRESHOLD), getCurrentFileName());
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
if (*correctionMask&(1<< I0_NORMALIZATION)) {
|
if (*correctionMask&(1<< I0_NORMALIZATION)) {
|
||||||
if (get_i0)
|
if (get_i0)
|
||||||
get_i0(0, IOarg);
|
get_i0(0, IOarg);
|
||||||
@ -223,6 +239,24 @@ void slsDetectorUtils::acquire(int delflag){
|
|||||||
setFrameIndex(-1);
|
setFrameIndex(-1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(receiver){
|
||||||
|
//send receiver file name
|
||||||
|
pthread_mutex_lock(&mp);
|
||||||
|
createFileName();
|
||||||
|
pthread_mutex_unlock(&mp);
|
||||||
|
setFileName(fileIO::getFileName());
|
||||||
|
if(setReceiverOnline()==OFFLINE_FLAG){
|
||||||
|
stopReceiver();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
//start receiver
|
||||||
|
startReceiver();
|
||||||
|
if(setReceiverOnline()==OFFLINE_FLAG){
|
||||||
|
stopReceiver();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
startAndReadAll();
|
startAndReadAll();
|
||||||
#ifdef VERBOSE
|
#ifdef VERBOSE
|
||||||
cout << "returned! " << endl;
|
cout << "returned! " << endl;
|
||||||
@ -249,13 +283,14 @@ void slsDetectorUtils::acquire(int delflag){
|
|||||||
#ifdef VERBOSE
|
#ifdef VERBOSE
|
||||||
cout << "start unthreaded process data " << endl;
|
cout << "start unthreaded process data " << endl;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
processData(delflag);
|
processData(delflag);
|
||||||
}
|
}
|
||||||
|
|
||||||
} else
|
} else
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
if(setReceiverOnline()==OFFLINE_FLAG){
|
||||||
// wait until data processing thread has finished the data
|
// wait until data processing thread has finished the data
|
||||||
|
|
||||||
#ifdef VERBOSE
|
#ifdef VERBOSE
|
||||||
@ -268,17 +303,25 @@ void slsDetectorUtils::acquire(int delflag){
|
|||||||
usleep(100000);
|
usleep(100000);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if((*correctionMask)&(1<<WRITE_FILE))
|
||||||
closeDataFile();
|
closeDataFile();
|
||||||
|
|
||||||
|
}else{
|
||||||
|
while(stopReceiver()!=OK);
|
||||||
|
}
|
||||||
|
|
||||||
pthread_mutex_lock(&mp);
|
pthread_mutex_lock(&mp);
|
||||||
if (*stoppedFlag==0) {
|
if (*stoppedFlag==0) {
|
||||||
executeAction(headerAfter);
|
executeAction(headerAfter);
|
||||||
|
|
||||||
|
pthread_mutex_unlock(&mp);
|
||||||
// setLastIndex(*fileIndex);
|
// setLastIndex(*fileIndex);
|
||||||
} else {
|
} else {
|
||||||
// setLastIndex(*fileIndex);
|
// setLastIndex(*fileIndex);
|
||||||
|
|
||||||
|
pthread_mutex_unlock(&mp);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
pthread_mutex_unlock(&mp);
|
|
||||||
|
|
||||||
|
|
||||||
if (*stoppedFlag) {
|
if (*stoppedFlag) {
|
||||||
@ -345,7 +388,7 @@ void slsDetectorUtils::acquire(int delflag){
|
|||||||
#endif
|
#endif
|
||||||
if(*correctionMask&(1<<WRITE_FILE))
|
if(*correctionMask&(1<<WRITE_FILE))
|
||||||
IncrementFileIndex();
|
IncrementFileIndex();
|
||||||
|
setFileIndex(fileIO::getFileIndex());
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@ -360,6 +403,8 @@ void slsDetectorUtils::acquire(int delflag){
|
|||||||
// loop measurements
|
// loop measurements
|
||||||
}
|
}
|
||||||
|
|
||||||
|
setReceiverAcquiring(0);
|
||||||
|
|
||||||
// waiting for the data processing thread to finish!
|
// waiting for the data processing thread to finish!
|
||||||
if (*threadedProcessing) {
|
if (*threadedProcessing) {
|
||||||
setJoinThread(1);
|
setJoinThread(1);
|
||||||
@ -378,7 +423,6 @@ void slsDetectorUtils::acquire(int delflag){
|
|||||||
if (eclog)
|
if (eclog)
|
||||||
delete eclog;
|
delete eclog;
|
||||||
|
|
||||||
|
|
||||||
if (acquisition_finished)
|
if (acquisition_finished)
|
||||||
acquisition_finished(getCurrentProgress(),getDetectorStatus(),acqFinished_p);
|
acquisition_finished(getCurrentProgress(),getDetectorStatus(),acqFinished_p);
|
||||||
|
|
||||||
@ -542,87 +586,6 @@ void slsDetectorUtils::incrementProgress(int i) {
|
|||||||
|
|
||||||
|
|
||||||
int slsDetectorUtils::testFunction(int times) {
|
int slsDetectorUtils::testFunction(int times) {
|
||||||
int i,count=0;
|
|
||||||
runStatus s;
|
|
||||||
char controlval[1000];
|
|
||||||
char statusval[1000];
|
|
||||||
|
|
||||||
int nchans = getTotalNumberOfChannels();
|
|
||||||
short int dataVals[nchans];
|
|
||||||
|
|
||||||
for(i=0;i<times;i++){
|
|
||||||
sprintf(statusval,"%x",readRegister(0x25));
|
|
||||||
std::cout<<std::endl<<dec<<i+1<<": stat:\t"<<statusval<<"\t";
|
|
||||||
sprintf(controlval,"%x",readRegister(0x24));
|
|
||||||
std::cout<<"cont:"<<controlval<<"\t"<<std::endl;
|
|
||||||
|
|
||||||
startAcquisition();
|
|
||||||
|
|
||||||
sprintf(controlval,"%x",readRegister(0x24));
|
|
||||||
std::cout<<"cont:"<<controlval<<"\t"<<std::endl;
|
|
||||||
//sprintf(statusval,"%x",readRegister(0x25));
|
|
||||||
//std::cout<<statusval<<std::endl;
|
|
||||||
s = getRunStatus();
|
|
||||||
if(s==IDLE){
|
|
||||||
std::cout<<"IDLE\t"<<std::endl;
|
|
||||||
s = getRunStatus();
|
|
||||||
if(s==IDLE){
|
|
||||||
std::cout<<"IDLE"<<std::endl;
|
|
||||||
exit(-1);
|
|
||||||
}
|
|
||||||
;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
if (s==RUNNING){
|
|
||||||
count=0;
|
|
||||||
while(s==RUNNING){
|
|
||||||
count++;//std::cout<<"count:"<<count<<std::endl;
|
|
||||||
if(count==4){
|
|
||||||
sprintf(statusval,"%x",readRegister(0x25));
|
|
||||||
|
|
||||||
|
|
||||||
std::cout<<"STUCK: stat"<<statusval<<std::endl;
|
|
||||||
exit(-1);
|
|
||||||
}
|
|
||||||
usleep(50000);
|
|
||||||
//val=readRegister(0x25);
|
|
||||||
s = getRunStatus();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
/* else{
|
|
||||||
std::cout<<"\nWeird Status. "<<runStatusType(s)<<" Exit\n";
|
|
||||||
exit(-1);
|
|
||||||
}*/
|
|
||||||
system("rm ~/wORKSPACE/scratch/run* ");
|
|
||||||
//system("more ~/wORKSPACE/scratch/run* ");
|
|
||||||
usleep(1000000);
|
|
||||||
|
|
||||||
setFileIndex(0);
|
|
||||||
int b;
|
|
||||||
|
|
||||||
b=setThreadedProcessing(-1);
|
|
||||||
setThreadedProcessing(0);
|
|
||||||
readAll();
|
|
||||||
processData(1);
|
|
||||||
setThreadedProcessing(b);
|
|
||||||
|
|
||||||
|
|
||||||
if(!readDataFile("/home/l_maliakal_d/wORKSPACE/scratch/run_1.raw",dataVals)){
|
|
||||||
std::cout<< "Could not open file "<< std::endl;
|
|
||||||
exit(-1);
|
|
||||||
}
|
|
||||||
|
|
||||||
std::cout<<std::endl;
|
|
||||||
for(int j=1277;j< (nchans);j++)
|
|
||||||
std::cout<<"\t"<<j<<":"<<dataVals[j];
|
|
||||||
|
|
||||||
if(dataVals[1278]!=2558){
|
|
||||||
std::cout<< "DATA ERROR!! "<< std::endl;
|
|
||||||
exit(-1);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
std::cout<<std::endl;
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -621,6 +621,19 @@ class slsDetectorUtils : public slsDetectorActions, public postProcessing {
|
|||||||
*/
|
*/
|
||||||
virtual int getCurrentFrameIndex()=0;
|
virtual int getCurrentFrameIndex()=0;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* resets framescaught
|
||||||
|
* @param index frames caught by receiver
|
||||||
|
* @param index if frame index is needed
|
||||||
|
*/
|
||||||
|
virtual int resetFramesCaught(int index=-1)=0;
|
||||||
|
|
||||||
|
/**
|
||||||
|
/returns a frame read from recever
|
||||||
|
*/
|
||||||
|
virtual int* readFrameFromReceiver()=0;
|
||||||
|
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|
||||||
static const int64_t thisSoftwareVersion=0x20120124;
|
static const int64_t thisSoftwareVersion=0x20120124;
|
||||||
|
@ -80,36 +80,50 @@ int fileIO::writeDataFile(ofstream &outfile, int *data, int offset){
|
|||||||
|
|
||||||
|
|
||||||
int fileIO::writeDataFile(void *data, int iframe) {
|
int fileIO::writeDataFile(void *data, int iframe) {
|
||||||
if (iframe>=0)
|
cout <<"iframe " << iframe << endl;
|
||||||
frameIndex=iframe;
|
|
||||||
|
|
||||||
if (*framesPerFile<2)
|
if (iframe<0)
|
||||||
frameIndex=-1;
|
iframe=frameIndex;
|
||||||
|
//if (iframe>=0)
|
||||||
|
// frameIndex=iframe;
|
||||||
|
|
||||||
if ((frameIndex%(*framesPerFile))==0 || (frameIndex<0)) {
|
if ((*framesPerFile)<2)
|
||||||
|
iframe=-1;
|
||||||
|
//frameIndex=-1;
|
||||||
|
if ((iframe%(*framesPerFile))==0 || (iframe<0)) {
|
||||||
|
//if ((frameIndex%(*framesPerFile))==0 || (frameIndex<0)) {
|
||||||
createFileName();
|
createFileName();
|
||||||
filefd = fopen(currentFileName.c_str(), "w");
|
filefd = fopen((currentFileName+string(".raw")).c_str(), "w");
|
||||||
}
|
}
|
||||||
if (filefd){
|
if (filefd){
|
||||||
if (iframe%(*framesPerFile)) {
|
//if (iframe%(*framesPerFile)) {
|
||||||
fileIOStatic::writeBinaryDataFile(filefd,getDataBytes() , data);
|
/*if(setDynamicRange(-1)==16){
|
||||||
frameIndex++;
|
fileIOStatic::writeBinaryDataFile(filefd,getDataBytes()*2, data);
|
||||||
|
frameIndex+=2;
|
||||||
}
|
}
|
||||||
|
else{*/
|
||||||
|
fileIOStatic::writeBinaryDataFile(filefd,getDataBytes(), data);cout<<"write frameIndex:"<<iframe<<endl;
|
||||||
|
//}
|
||||||
|
iframe++;
|
||||||
|
//frameIndex++;
|
||||||
|
//}
|
||||||
}
|
}
|
||||||
if ((frameIndex%(*framesPerFile)==0) || (frameIndex<0)) {
|
if ((iframe%(*framesPerFile)==0) || (iframe<0)) {
|
||||||
|
//if ((frameIndex%(*framesPerFile)==0) || (frameIndex<0)) {
|
||||||
if (filefd)
|
if (filefd)
|
||||||
fclose(filefd);
|
fclose(filefd);
|
||||||
filefd=NULL;
|
filefd=NULL;
|
||||||
}
|
}
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
int fileIO::closeDataFile() {
|
int fileIO::closeDataFile() {fflush(stdout);
|
||||||
if (filefd)
|
if (filefd)
|
||||||
fclose(filefd);
|
fclose(filefd);
|
||||||
filefd=NULL;
|
filefd=NULL;
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -65,14 +65,14 @@ void postProcessing::processFrame(int *myData, int delflag) {
|
|||||||
|
|
||||||
/** decode data */
|
/** decode data */
|
||||||
|
|
||||||
if (getDetectorsType()==MYTHEN) {
|
// if (getDetectorsType()==MYTHEN) {
|
||||||
fdata=decodeData(myData, fdata);
|
fdata=decodeData(myData, fdata);
|
||||||
|
|
||||||
#ifdef VERBOSE
|
#ifdef VERBOSE
|
||||||
cout << "decode"<< endl;
|
cout << "decode"<< endl;
|
||||||
#endif
|
#endif
|
||||||
} else
|
//} else
|
||||||
fdata=NULL;
|
// fdata=NULL;
|
||||||
|
|
||||||
if (rawDataReady) {
|
if (rawDataReady) {
|
||||||
//#ifdef VERBOSE
|
//#ifdef VERBOSE
|
||||||
@ -99,22 +99,22 @@ void postProcessing::processFrame(int *myData, int delflag) {
|
|||||||
cout << "writing raw data " << endl;
|
cout << "writing raw data " << endl;
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
if (fdata) {
|
if (getDetectorsType()==MYTHEN){
|
||||||
|
// if (fdata) {
|
||||||
//uses static function?!?!?!?
|
//uses static function?!?!?!?
|
||||||
writeDataFile (fname+string(".raw"),fdata, NULL, NULL, 'i');
|
writeDataFile (fname+string(".raw"),fdata, NULL, NULL, 'i');
|
||||||
} else {
|
} else {
|
||||||
writeDataFile ((void*)myData);
|
writeDataFile ((void*)myData, frameIndex);
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef VERBOSE
|
#ifdef VERBOSE
|
||||||
cout << "done " << endl;
|
cout << "done " << endl;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((*correctionMask) & ~(1<<WRITE_FILE)) {
|
if ((*correctionMask) & ~(1<<WRITE_FILE)) {
|
||||||
doProcessing(fdata,delflag, fname);
|
doProcessing(fdata,delflag, fname);
|
||||||
} else
|
} else
|
||||||
if (dataReady) {
|
if (dataReady){
|
||||||
thisData=new detectorData(fdata,NULL,NULL,getCurrentProgress(),(fname+string(".raw")).c_str(),getTotalNumberOfChannels());
|
thisData=new detectorData(fdata,NULL,NULL,getCurrentProgress(),(fname+string(".raw")).c_str(),getTotalNumberOfChannels());
|
||||||
dataReady(thisData, pCallbackArg);
|
dataReady(thisData, pCallbackArg);
|
||||||
delete thisData;
|
delete thisData;
|
||||||
@ -131,6 +131,7 @@ void postProcessing::processFrame(int *myData, int delflag) {
|
|||||||
incrementFrameIndex();
|
incrementFrameIndex();
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
delete [] myData;
|
delete [] myData;
|
||||||
if (fdata)
|
if (fdata)
|
||||||
delete [] fdata;
|
delete [] fdata;
|
||||||
@ -376,24 +377,33 @@ void* postProcessing::processData(int delflag) {
|
|||||||
else{
|
else{
|
||||||
int prevCaught=getCurrentFrameIndex();
|
int prevCaught=getCurrentFrameIndex();
|
||||||
int caught=0;
|
int caught=0;
|
||||||
while(getRunStatus()!=IDLE){
|
while(1){
|
||||||
|
if (checkJoinThread()) break;
|
||||||
|
usleep(200000);
|
||||||
caught=getCurrentFrameIndex();
|
caught=getCurrentFrameIndex();
|
||||||
incrementProgress(caught-prevCaught);
|
incrementProgress(caught-prevCaught);
|
||||||
prevCaught=caught;
|
prevCaught=caught;
|
||||||
usleep(1000000);
|
if (checkJoinThread()) break;
|
||||||
if(progress_call)
|
//if(progress_call)
|
||||||
progress_call(getCurrentProgress(),pProgressCallArg);
|
// progress_call(getCurrentProgress(),pProgressCallArg);
|
||||||
}
|
|
||||||
/*
|
int* receiverData = readFrameFromReceiver();
|
||||||
|
if(!receiverData)
|
||||||
|
return 0;
|
||||||
|
fdata=decodeData(receiverData);
|
||||||
|
delete [] receiverData;
|
||||||
|
if(fdata){
|
||||||
if (dataReady) {
|
if (dataReady) {
|
||||||
// can add get frame from receiver and send it to GUI
|
thisData=new detectorData(fdata,NULL,NULL,getCurrentProgress(),(getCurrentFileName()+string(".raw")).c_str(),getTotalNumberOfChannels());
|
||||||
thisData=new detectorData(val,err,ang,getCurrentProgress(),(fname+ext).c_str(),np);
|
|
||||||
dataReady(thisData, pCallbackArg);
|
dataReady(thisData, pCallbackArg);
|
||||||
delete thisData;
|
delete thisData;
|
||||||
|
fdata=NULL;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
*/
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -323,6 +323,7 @@ s
|
|||||||
|
|
||||||
int arraySize;
|
int arraySize;
|
||||||
|
|
||||||
|
void setReceiverAcquiring(int acq){receiverAcquiring=acq;};
|
||||||
|
|
||||||
private:
|
private:
|
||||||
double *fdata;
|
double *fdata;
|
||||||
@ -348,7 +349,7 @@ s
|
|||||||
int numberOfChannels;
|
int numberOfChannels;
|
||||||
|
|
||||||
|
|
||||||
|
int receiverAcquiring;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -40,7 +40,10 @@ int err = 0;
|
|||||||
pthread_t gui_acquisition_thread;
|
pthread_t gui_acquisition_thread;
|
||||||
|
|
||||||
|
|
||||||
char buffer[BUFFER_LENGTH];
|
char buffer[BUFFER_LENGTH*2];
|
||||||
|
char sendbuffer[BUFFER_LENGTH*2];
|
||||||
|
|
||||||
|
char onebuffer[BUFFER_LENGTH];
|
||||||
int sd = -1;
|
int sd = -1;
|
||||||
int sockfd, sfilefd;
|
int sockfd, sfilefd;
|
||||||
|
|
||||||
@ -49,11 +52,24 @@ int sockfd, sfilefd;
|
|||||||
char filePath[MAX_STR_LENGTH]="";
|
char filePath[MAX_STR_LENGTH]="";
|
||||||
char fileName[MAX_STR_LENGTH]="run";
|
char fileName[MAX_STR_LENGTH]="run";
|
||||||
int fileIndex=0;
|
int fileIndex=0;
|
||||||
|
int frameIndexNeeded=1;
|
||||||
|
|
||||||
|
//for each scan
|
||||||
int frameIndex=0;
|
int frameIndex=0;
|
||||||
int startFrameIndex=-1;
|
int startFrameIndex=-1;
|
||||||
int framesInFile=0;
|
|
||||||
int framesCaught=0;
|
int framesCaught=0;
|
||||||
|
|
||||||
|
//for each acquisition
|
||||||
|
int acquisitionIndex=0;
|
||||||
|
int startAcquisitionIndex=-1;//to remember progress for scans
|
||||||
|
int totalFramesCaught=0;
|
||||||
|
|
||||||
|
int framesInFile=0;//to know when to start next file
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
enum runStatus status = IDLE;
|
enum runStatus status = IDLE;
|
||||||
|
|
||||||
|
|
||||||
@ -124,9 +140,7 @@ int setFileIndex(int index){
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
int getFramesCaught(){
|
|
||||||
return framesCaught;
|
|
||||||
}
|
|
||||||
|
|
||||||
int getFrameIndex(){
|
int getFrameIndex(){
|
||||||
if(startFrameIndex==-1)
|
if(startFrameIndex==-1)
|
||||||
@ -137,6 +151,33 @@ int getFrameIndex(){
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
int getAcquisitionIndex(){
|
||||||
|
if(startAcquisitionIndex==-1)
|
||||||
|
acquisitionIndex=0;
|
||||||
|
else
|
||||||
|
acquisitionIndex=((int)(*((int*)buffer)) - startAcquisitionIndex)/2;
|
||||||
|
return acquisitionIndex;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
int getFramesCaught(){
|
||||||
|
return framesCaught;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
int getTotalFramesCaught(){
|
||||||
|
return totalFramesCaught;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
int resetTotalFramesCaught(int index){
|
||||||
|
startAcquisitionIndex=-1;
|
||||||
|
totalFramesCaught=0;
|
||||||
|
frameIndexNeeded=index;
|
||||||
|
return frameIndexNeeded;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void* startListening(void *arg){
|
void* startListening(void *arg){
|
||||||
@ -149,16 +190,17 @@ void* startListening(void *arg){
|
|||||||
sd = -1;
|
sd = -1;
|
||||||
int rc1, rc2, rc;
|
int rc1, rc2, rc;
|
||||||
int currframenum, prevframenum;
|
int currframenum, prevframenum;
|
||||||
char buffer2[BUFFER_LENGTH];
|
// char buffer2[BUFFER_LENGTH];
|
||||||
char savefilename[128];
|
char savefilename[128];
|
||||||
struct sockaddr_in serveraddr;
|
struct sockaddr_in serveraddr;
|
||||||
struct sockaddr_in clientaddr;
|
struct sockaddr_in clientaddr;
|
||||||
|
|
||||||
int clientaddrlen = sizeof(clientaddr);
|
int clientaddrlen = sizeof(clientaddr);
|
||||||
framesInFile=0;
|
framesInFile=0;
|
||||||
framesCaught=0;
|
frameIndex=0;
|
||||||
frameIndex = 0;
|
|
||||||
startFrameIndex=-1;
|
startFrameIndex=-1;
|
||||||
|
framesCaught=0;
|
||||||
|
|
||||||
|
|
||||||
/***********************************************************************/
|
/***********************************************************************/
|
||||||
/* Catch signal SIGINT to close files properly */
|
/* Catch signal SIGINT to close files properly */
|
||||||
@ -167,7 +209,10 @@ void* startListening(void *arg){
|
|||||||
|
|
||||||
|
|
||||||
//create file name
|
//create file name
|
||||||
sprintf(savefilename, "%s/%s_f%09d_%d.dat", filePath,fileName,frameIndex,fileIndex);
|
if(!frameIndexNeeded)
|
||||||
|
sprintf(savefilename, "%s/%s_%d.dat", filePath,fileName,fileIndex);
|
||||||
|
else
|
||||||
|
sprintf(savefilename, "%s/%s_f%012d_%d.dat", filePath,fileName,framesCaught,fileIndex);
|
||||||
|
|
||||||
/***********************************************************************/
|
/***********************************************************************/
|
||||||
/* A do/while(FALSE) loop is used to make error cleanup easier. The */
|
/* A do/while(FALSE) loop is used to make error cleanup easier. The */
|
||||||
@ -221,7 +266,11 @@ void* startListening(void *arg){
|
|||||||
|
|
||||||
currframenum=(int)(*((int*)buffer));
|
currframenum=(int)(*((int*)buffer));
|
||||||
getFrameIndex();
|
getFrameIndex();
|
||||||
sprintf(savefilename, "%s/%s_f%09d_%d.dat", filePath,fileName,frameIndex,fileIndex);
|
//create file name
|
||||||
|
if(!frameIndexNeeded)
|
||||||
|
sprintf(savefilename, "%s/%s_%d.dat", filePath,fileName,fileIndex);
|
||||||
|
else
|
||||||
|
sprintf(savefilename, "%s/%s_f%012d_%d.dat", filePath,fileName,framesCaught,fileIndex);
|
||||||
|
|
||||||
printf("saving to %s\t\tpacket loss %f \%\t\tframenum %d\n", savefilename,((currframenum-prevframenum-(2*framesInFile))/(double)(2*framesInFile))*100.000,currframenum);
|
printf("saving to %s\t\tpacket loss %f \%\t\tframenum %d\n", savefilename,((currframenum-prevframenum-(2*framesInFile))/(double)(2*framesInFile))*100.000,currframenum);
|
||||||
sfilefd = fopen((const char *) (savefilename), "w");
|
sfilefd = fopen((const char *) (savefilename), "w");
|
||||||
@ -230,16 +279,22 @@ void* startListening(void *arg){
|
|||||||
}
|
}
|
||||||
status = RUNNING;
|
status = RUNNING;
|
||||||
|
|
||||||
rc1 = recvfrom(sd, buffer, sizeof(buffer), 0,
|
rc1 = recvfrom(sd, buffer, sizeof(onebuffer), 0,
|
||||||
(struct sockaddr *) &clientaddr, &clientaddrlen);
|
(struct sockaddr *) &clientaddr, &clientaddrlen);
|
||||||
//printf("rc1 done\n");
|
//printf("rc1 done\n");
|
||||||
rc2 = recvfrom(sd, buffer2, sizeof(buffer2), 0,
|
rc2 = recvfrom(sd, buffer+sizeof(onebuffer), sizeof(onebuffer), 0,
|
||||||
(struct sockaddr *) &clientaddr, &clientaddrlen);
|
(struct sockaddr *) &clientaddr, &clientaddrlen);
|
||||||
|
|
||||||
|
|
||||||
|
//for each scan
|
||||||
if(startFrameIndex==-1){
|
if(startFrameIndex==-1){
|
||||||
startFrameIndex=(int)(*((int*)buffer))-2;
|
startFrameIndex=(int)(*((int*)buffer))-2;
|
||||||
prevframenum=startFrameIndex;
|
prevframenum=startFrameIndex;
|
||||||
}
|
}
|
||||||
|
//start of acquisition
|
||||||
|
if(startAcquisitionIndex==-1)
|
||||||
|
startAcquisitionIndex=startFrameIndex;
|
||||||
|
|
||||||
//printf("rc2 done\n");
|
//printf("rc2 done\n");
|
||||||
if ((rc1 < 0) || (rc2 < 0)) {
|
if ((rc1 < 0) || (rc2 < 0)) {
|
||||||
perror("recvfrom() failed");
|
perror("recvfrom() failed");
|
||||||
@ -249,9 +304,10 @@ void* startListening(void *arg){
|
|||||||
//so that it doesnt write the last frame twice
|
//so that it doesnt write the last frame twice
|
||||||
if(gui_acquisition_thread_running){
|
if(gui_acquisition_thread_running){
|
||||||
fwrite(buffer, 1, rc1, sfilefd);
|
fwrite(buffer, 1, rc1, sfilefd);
|
||||||
fwrite(buffer2, 1, rc2, sfilefd);
|
fwrite(buffer+sizeof(onebuffer), 1, rc2, sfilefd);
|
||||||
framesInFile++;
|
framesInFile++;
|
||||||
framesCaught++;
|
framesCaught++;
|
||||||
|
totalFramesCaught++;
|
||||||
//printf("saving\n");
|
//printf("saving\n");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -332,6 +388,22 @@ int stopReceiver(){
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
char* readFrame(){
|
||||||
|
// volatile char* now_ptr=NULL;
|
||||||
|
//u_int32_t* ram_values=NULL;
|
||||||
|
|
||||||
|
// now_ptr=(char*)ram_values;
|
||||||
|
|
||||||
|
//memcpy(now_ptr,buffer ,sizeof(buffer));
|
||||||
|
|
||||||
|
// memcpy(sendbuffer,buffer ,sizeof(buffer));
|
||||||
|
|
||||||
|
while (((int)*((int*)buffer))%2==0) ;//usleep(20000);
|
||||||
|
|
||||||
|
// memcpy(sendbuffer,buffer ,sizeof(buffer));
|
||||||
|
|
||||||
|
//printf("freamenum%d\n",*((int*) sendbuffer));
|
||||||
|
return buffer;
|
||||||
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -13,13 +13,17 @@ char* getFilePath();
|
|||||||
char* setFilePath(char fName[]);
|
char* setFilePath(char fName[]);
|
||||||
int getFileIndex();
|
int getFileIndex();
|
||||||
int setFileIndex(int index);
|
int setFileIndex(int index);
|
||||||
int getFramesCaught();
|
|
||||||
int getFrameIndex();
|
int getFrameIndex();
|
||||||
|
int getAcquisitionIndex();
|
||||||
|
int getFramesCaught();
|
||||||
|
int getTotalFramesCaught();
|
||||||
|
int resetTotalFramesCaught(int index);
|
||||||
|
|
||||||
void* startListening(void *arg);
|
void* startListening(void *arg);
|
||||||
|
|
||||||
int startReceiver();
|
int startReceiver();
|
||||||
int stopReceiver();
|
int stopReceiver();
|
||||||
|
|
||||||
|
char* readFrame();
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -105,6 +105,8 @@ int function_table() {
|
|||||||
flist[F_GET_RECEIVER_STATUS]=&get_receiver_status;
|
flist[F_GET_RECEIVER_STATUS]=&get_receiver_status;
|
||||||
flist[F_GET_FRAMES_CAUGHT]=&get_frames_caught;
|
flist[F_GET_FRAMES_CAUGHT]=&get_frames_caught;
|
||||||
flist[F_GET_FRAME_INDEX]=&get_frame_index;
|
flist[F_GET_FRAME_INDEX]=&get_frame_index;
|
||||||
|
flist[F_RESET_FRAMES_CAUGHT]=&reset_frames_caught;
|
||||||
|
flist[F_READ_FRAME]=&read_frame;
|
||||||
|
|
||||||
flist[F_LOCK_RECEIVER]=&lock_receiver;
|
flist[F_LOCK_RECEIVER]=&lock_receiver;
|
||||||
flist[F_SET_PORT]=&set_port;
|
flist[F_SET_PORT]=&set_port;
|
||||||
@ -148,11 +150,11 @@ int set_file_name(int file_des) {
|
|||||||
sprintf(mess,"Receiver locked by %s\n", lastClientIP);
|
sprintf(mess,"Receiver locked by %s\n", lastClientIP);
|
||||||
ret=FAIL;
|
ret=FAIL;
|
||||||
}
|
}
|
||||||
else if((strlen(fName))&&(getReceiverStatus()==RUNNING)){
|
/* else if((strlen(fName))&&(getReceiverStatus()==RUNNING)){
|
||||||
strcpy(mess,"Can not set file name while receiver running");
|
strcpy(mess,"Can not set file name while receiver running");
|
||||||
ret = FAIL;
|
ret = FAIL;
|
||||||
}
|
}
|
||||||
else
|
*/ else
|
||||||
strcpy(retval,setFileName(fName));
|
strcpy(retval,setFileName(fName));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -275,11 +277,11 @@ int set_file_index(int file_des) {
|
|||||||
sprintf(mess,"Receiver locked by %s\n", lastClientIP);
|
sprintf(mess,"Receiver locked by %s\n", lastClientIP);
|
||||||
ret=FAIL;
|
ret=FAIL;
|
||||||
}
|
}
|
||||||
else if((index>=0)&&(getReceiverStatus()==RUNNING)){
|
/* else if((index>=0)&&(getReceiverStatus()==RUNNING)){
|
||||||
strcpy(mess,"Can not set file index while receiver running\n");
|
strcpy(mess,"Can not set file index while receiver running\n");
|
||||||
ret = FAIL;
|
ret = FAIL;
|
||||||
}
|
}
|
||||||
else
|
*/ else
|
||||||
retval=setFileIndex(index);
|
retval=setFileIndex(index);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -423,7 +425,7 @@ int get_frames_caught(int file_des) {
|
|||||||
|
|
||||||
/* execute action if the arguments correctly arrived*/
|
/* execute action if the arguments correctly arrived*/
|
||||||
#ifdef SLS_RECEIVER_FUNCTION_LIST
|
#ifdef SLS_RECEIVER_FUNCTION_LIST
|
||||||
retval=getFramesCaught();
|
retval=getTotalFramesCaught();
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if(ret==OK && differentClients){
|
if(ret==OK && differentClients){
|
||||||
@ -447,14 +449,14 @@ int get_frames_caught(int file_des) {
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
int get_frame_index(int file_des) {
|
int get_frame_index(int file_des) {printf("Getting frame Index\n");fflush(stdout);
|
||||||
int ret=OK;
|
int ret=OK;
|
||||||
int n=0;
|
int n=0;
|
||||||
int retval=-1;
|
int retval=-1;
|
||||||
|
|
||||||
/* execute action if the arguments correctly arrived*/
|
/* execute action if the arguments correctly arrived*/
|
||||||
#ifdef SLS_RECEIVER_FUNCTION_LIST
|
#ifdef SLS_RECEIVER_FUNCTION_LIST
|
||||||
retval=getFrameIndex();
|
retval=getAcquisitionIndex();
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if(ret==OK && differentClients){
|
if(ret==OK && differentClients){
|
||||||
@ -465,6 +467,55 @@ int get_frame_index(int file_des) {
|
|||||||
/* send answer */
|
/* send answer */
|
||||||
n = sendDataOnly(file_des,&ret,sizeof(ret));
|
n = sendDataOnly(file_des,&ret,sizeof(ret));
|
||||||
n = sendDataOnly(file_des,&retval,sizeof(retval));
|
n = sendDataOnly(file_des,&retval,sizeof(retval));
|
||||||
|
printf("returnrdf:%d\n",retval);
|
||||||
|
/*return ok/fail*/
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
int reset_frames_caught(int file_des) {
|
||||||
|
int ret=OK;
|
||||||
|
int n=0;
|
||||||
|
int retval=-1;
|
||||||
|
int index=-1;
|
||||||
|
|
||||||
|
strcpy(mess,"Could not reset frames caught\n");
|
||||||
|
|
||||||
|
|
||||||
|
/* receive arguments */
|
||||||
|
n = receiveDataOnly(file_des,&index,sizeof(index));
|
||||||
|
if (n < 0) {
|
||||||
|
sprintf(mess,"Error reading from socket\n");
|
||||||
|
ret=FAIL;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (ret==OK) {
|
||||||
|
/* execute action if the arguments correctly arrived*/
|
||||||
|
#ifdef SLS_RECEIVER_FUNCTION_LIST
|
||||||
|
if (lockStatus==1 && differentClients==1){//necessary???
|
||||||
|
sprintf(mess,"Receiver locked by %s\n", lastClientIP);
|
||||||
|
ret=FAIL;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
retval=resetTotalFramesCaught(index);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
if(ret==OK && differentClients){
|
||||||
|
printf("Force update\n");
|
||||||
|
ret=FORCE_UPDATE;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* send answer */
|
||||||
|
n = sendDataOnly(file_des,&ret,sizeof(ret));
|
||||||
|
if(ret==FAIL)
|
||||||
|
n = sendDataOnly(file_des,mess,sizeof(mess));
|
||||||
|
n = sendDataOnly(file_des,&retval,sizeof(retval));
|
||||||
/*return ok/fail*/
|
/*return ok/fail*/
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
@ -475,6 +526,37 @@ int get_frame_index(int file_des) {
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
int read_frame(int file_des) {
|
||||||
|
int ret=OK;
|
||||||
|
int n=0;
|
||||||
|
char* retval=NULL;
|
||||||
|
char buffer[1286*2];
|
||||||
|
|
||||||
|
strcpy(mess,"Could not read frame\n");
|
||||||
|
|
||||||
|
|
||||||
|
/* execute action if the arguments correctly arrived*/
|
||||||
|
#ifdef SLS_RECEIVER_FUNCTION_LIST
|
||||||
|
retval=readFrame();
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
if(ret==OK && differentClients){
|
||||||
|
printf("Force update\n");
|
||||||
|
ret=FORCE_UPDATE;
|
||||||
|
}
|
||||||
|
if(getReceiverStatus==IDLE){
|
||||||
|
ret=FAIL;
|
||||||
|
printf("*************STOPPPED***\n");
|
||||||
|
}
|
||||||
|
/* send answer */
|
||||||
|
n = sendDataOnly(file_des,&ret,sizeof(ret));
|
||||||
|
if(ret==FAIL)
|
||||||
|
n = sendDataOnly(file_des,mess,sizeof(mess));
|
||||||
|
n = sendDataOnly(file_des,retval,sizeof(buffer));
|
||||||
|
/*return ok/fail*/
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -36,6 +36,9 @@ int stop_receiver(int);
|
|||||||
int get_receiver_status(int);
|
int get_receiver_status(int);
|
||||||
int get_frames_caught(int);
|
int get_frames_caught(int);
|
||||||
int get_frame_index(int);
|
int get_frame_index(int);
|
||||||
|
int reset_frame_index(int);
|
||||||
|
int reset_frames_caught(int);
|
||||||
|
int read_frame(int);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -118,141 +118,7 @@ int receiverInterface::executeFunction(int fnum){
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
/*
|
|
||||||
set or read the acquisition timers
|
|
||||||
enum timerIndex {
|
|
||||||
FRAME_NUMBER,
|
|
||||||
ACQUISITION_TIME,
|
|
||||||
FRAME_PERIOD,
|
|
||||||
DELAY_AFTER_TRIGGER,
|
|
||||||
GATES_NUMBER,
|
|
||||||
PROBES_NUMBER
|
|
||||||
CYCLES_NUMBER,
|
|
||||||
GATE_INTEGRATED_TIME
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
/*
|
|
||||||
int64_t receiverInterface::setTimer(timerIndex index, int64_t t){
|
|
||||||
|
|
||||||
|
|
||||||
int fnum=F_SET_TIMER;
|
|
||||||
int64_t retval;
|
|
||||||
uint64_t ut;
|
|
||||||
char mess[100];
|
|
||||||
int ret=OK;
|
|
||||||
int n=0;
|
|
||||||
|
|
||||||
if (index!=MEASUREMENTS_NUMBER) {
|
|
||||||
|
|
||||||
|
|
||||||
#ifdef VERBOSE
|
|
||||||
std::cout<< "Setting timer "<< index << " to " << t << "ns" << std::endl;
|
|
||||||
#endif
|
|
||||||
ut=t;
|
|
||||||
if (thisDetector->onlineFlag==ONLINE_FLAG) {
|
|
||||||
if (controlSocket) {
|
|
||||||
if (controlSocket->Connect()>=0) {
|
|
||||||
controlSocket->SendDataOnly(&fnum,sizeof(fnum));
|
|
||||||
controlSocket->SendDataOnly(&index,sizeof(index));
|
|
||||||
n=controlSocket->SendDataOnly(&t,sizeof(t));
|
|
||||||
controlSocket->ReceiveDataOnly(&ret,sizeof(ret));
|
|
||||||
if (ret==slsDetectorDefs::FAIL) {
|
|
||||||
controlSocket->ReceiveDataOnly(mess,sizeof(mess));
|
|
||||||
std::cout<< "Detector returned error: " << mess << std::endl;
|
|
||||||
} else {
|
|
||||||
controlSocket->ReceiveDataOnly(&retval,sizeof(retval));
|
|
||||||
thisDetector->timerValue[index]=retval;
|
|
||||||
}
|
|
||||||
controlSocket->Disconnect();
|
|
||||||
if (ret==FORCE_UPDATE) {
|
|
||||||
updateDetector();
|
|
||||||
#ifdef VERBOSE
|
|
||||||
std::cout<< "Updated!" << std::endl;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
//std::cout<< "offline " << std::endl;
|
|
||||||
if (t>=0)
|
|
||||||
thisDetector->timerValue[index]=t;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
if (t>=0)
|
|
||||||
thisDetector->timerValue[index]=t;
|
|
||||||
}
|
|
||||||
#ifdef VERBOSE
|
|
||||||
std::cout<< "Timer " << index << " set to "<< thisDetector->timerValue[index] << "ns" << std::endl;
|
|
||||||
#endif
|
|
||||||
if (index==PROBES_NUMBER) {
|
|
||||||
setDynamicRange();
|
|
||||||
//cout << "Changing probes: data size = " << thisDetector->dataBytes <<endl;
|
|
||||||
}
|
|
||||||
|
|
||||||
// set progress
|
|
||||||
if ((index==FRAME_NUMBER) || (index==CYCLES_NUMBER)) {
|
|
||||||
|
|
||||||
setTotalProgress();
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
return thisDetector->timerValue[index];
|
|
||||||
|
|
||||||
};
|
|
||||||
|
|
||||||
*/
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
int64_t receiverInterface::getTimeLeft(timerIndex index){
|
|
||||||
|
|
||||||
|
|
||||||
int fnum=F_GET_TIME_LEFT;
|
|
||||||
int64_t retval;
|
|
||||||
char mess[100];
|
|
||||||
int ret=OK;
|
|
||||||
|
|
||||||
#ifdef VERBOSE
|
|
||||||
std::cout<< "Getting timer "<< index << std::endl;
|
|
||||||
#endif
|
|
||||||
if (thisDetector->onlineFlag==ONLINE_FLAG) {
|
|
||||||
if (stopSocket) {
|
|
||||||
if (stopSocket->Connect()>=0) {
|
|
||||||
stopSocket->SendDataOnly(&fnum,sizeof(fnum));
|
|
||||||
stopSocket->SendDataOnly(&index,sizeof(index));
|
|
||||||
stopSocket->ReceiveDataOnly(&ret,sizeof(ret));
|
|
||||||
if (ret==slsDetectorDefs::FAIL) {
|
|
||||||
stopSocket->ReceiveDataOnly(mess,sizeof(mess));
|
|
||||||
std::cout<< "Detector returned error: " << mess << std::endl;
|
|
||||||
} else {
|
|
||||||
stopSocket->ReceiveDataOnly(&retval,sizeof(retval));
|
|
||||||
}
|
|
||||||
stopSocket->Disconnect();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
#ifdef VERBOSE
|
|
||||||
std::cout<< "Time left is "<< retval << std::endl;
|
|
||||||
#endif
|
|
||||||
return retval;
|
|
||||||
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
int receiverInterface::exitServer(){
|
int receiverInterface::exitServer(){
|
||||||
|
|
||||||
|
@ -53,7 +53,7 @@ public:
|
|||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Send a string to receiver
|
* Send an integer to receiver
|
||||||
* @param fnum function enum to determine what parameter
|
* @param fnum function enum to determine what parameter
|
||||||
* @param retval return value
|
* @param retval return value
|
||||||
* @param arg value to send
|
* @param arg value to send
|
||||||
@ -63,7 +63,7 @@ public:
|
|||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Send a string to receiver
|
* Get an integer value from receiver
|
||||||
* @param fnum function enum to determine what parameter
|
* @param fnum function enum to determine what parameter
|
||||||
* @param retval return value
|
* @param retval return value
|
||||||
* \returns success of operation
|
* \returns success of operation
|
||||||
@ -72,7 +72,7 @@ public:
|
|||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Send a string to receiver
|
* Get last client ip connected to receiver
|
||||||
* @param fnum function enum to get last client up
|
* @param fnum function enum to get last client up
|
||||||
* @param retval return value
|
* @param retval return value
|
||||||
* \returns success of operation
|
* \returns success of operation
|
||||||
@ -81,7 +81,7 @@ public:
|
|||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Send a string to receiver
|
* Send a function number to execute function
|
||||||
* @param fnum function enum to determine which function to execute
|
* @param fnum function enum to determine which function to execute
|
||||||
* \returns success of operation
|
* \returns success of operation
|
||||||
*/
|
*/
|
||||||
|
Loading…
x
Reference in New Issue
Block a user