diff --git a/slsDetectorSoftware/commonFiles/error_defs.h b/slsDetectorSoftware/commonFiles/error_defs.h index 7b4dd8760..5b05ff71b 100644 --- a/slsDetectorSoftware/commonFiles/error_defs.h +++ b/slsDetectorSoftware/commonFiles/error_defs.h @@ -40,6 +40,8 @@ using namespace std; #define SETTINGS_FILE_NOT_OPEN 0x0000000000000020ULL #define COULDNOT_START_RECEIVER 0x0000000000000040ULL // default error like starting threads #define COULDNOT_STOP_RECEIVER 0x0000000000000080ULL +#define DETECTOR_TIMER_VALUE_NOT_SET 0x0000000000000100ULL +#define RECEIVER_ACQ_PERIOD_NOT_SET 0x0000000000000200ULL /** @short class returning all error messages for error mask */ class errorDefs { @@ -109,6 +111,12 @@ public: if(slsErrorMask&COULDNOT_STOP_RECEIVER) retval.append("Could not stop receiver.\n"); + if(slsErrorMask&DETECTOR_TIMER_VALUE_NOT_SET) + retval.append("Could not set one of timer values in detector.\n"); + + if(slsErrorMask&RECEIVER_ACQ_PERIOD_NOT_SET) + retval.append("Could not set acquisition period in receiver.\n"); + return retval; diff --git a/slsDetectorSoftware/multiSlsDetector/multiSlsDetector.cpp b/slsDetectorSoftware/multiSlsDetector/multiSlsDetector.cpp index 688f3f142..cb54e8117 100644 --- a/slsDetectorSoftware/multiSlsDetector/multiSlsDetector.cpp +++ b/slsDetectorSoftware/multiSlsDetector/multiSlsDetector.cpp @@ -4362,30 +4362,31 @@ int multiSlsDetector::stopReceiver(){ slsDetectorDefs::runStatus multiSlsDetector::startReceiverReadout(){ + int i=0; + runStatus s,s1; + i=thisMultiDetector->masterPosition; + if (thisMultiDetector->masterPosition>=0) { + if (detectors[i]) { + s1=detectors[i]->startReceiverReadout(); + if(detectors[i]->getErrorMask()) + setErrorMask(getErrorMask()|(1<numberOfDetectors; i++) { + if (detectors[i]) { + s=detectors[i]->startReceiverReadout(); + if(detectors[i]->getErrorMask()) + setErrorMask(getErrorMask()|(1<masterPosition>=0) - if (detectors[thisMultiDetector->masterPosition]){ - s = detectors[thisMultiDetector->masterPosition]->startReceiverReadout(); - if(detectors[thisMultiDetector->masterPosition]->getErrorMask()) - setErrorMask(getErrorMask()|(1<masterPosition)); - return s; - } - - if (detectors[0]) s=detectors[0]->startReceiverReadout(); - - for (int i=0; inumberOfDetectors; i++) { - s1=detectors[i]->startReceiverReadout(); - if(detectors[i]->getErrorMask()) - setErrorMask(getErrorMask()|(1<onlineFlag==ONLINE_FLAG) { if (connectControl() == OK){ controlSocket->SendDataOnly(&fnum,sizeof(fnum)); @@ -3486,6 +3485,7 @@ int64_t slsDetector::setTimer(timerIndex index, int64_t t){ if (ret==FAIL) { controlSocket->ReceiveDataOnly(mess,sizeof(mess)); std::cout<< "Detector returned error: " << mess << std::endl; + setErrorMask((getErrorMask())|(DETECTOR_TIMER_VALUE_NOT_SET)); } else { controlSocket->ReceiveDataOnly(&retval,sizeof(retval)); thisDetector->timerValue[index]=retval; @@ -3524,6 +3524,26 @@ int64_t slsDetector::setTimer(timerIndex index, int64_t t){ setTotalProgress(); } + //send acquisiton period to receiver + if((index==FRAME_PERIOD) && (ret != FAIL) && (t != -1) && (setReceiverOnline(ONLINE_FLAG)==ONLINE_FLAG)){ + //if acquisition period is zero, then #frames/buffer depends on exposure time and not acq period + if(!retval) + retval = timerValue[ACQUISITION_TIME]; +#ifdef VERBOSE + std::cout << "Sending/Getting acquisition period to/from receiver " << retval << std::endl; +#endif + if (connectData() == OK) + ret=thisReceiver->sendInt(fnum,ut,retval); + if(ut != retval){ + ret = FAIL; + cout << "ERROR:Acquisition Period in receiver set incorrectly to " << ut << " instead of " << retval << endl; + } + if(ret==FAIL) + setErrorMask((getErrorMask())|(RECEIVER_ACQ_PERIOD_NOT_SET)); + if(ret==FORCE_UPDATE) + updateReceiver(); + } + return thisDetector->timerValue[index]; }; @@ -4793,13 +4813,21 @@ char* slsDetector::setDetectorIP(string detectorIP){ char* slsDetector::setReceiver(string receiverIP){ - if(getRunStatus()==RUNNING) stopAcquisition(); strcpy(thisDetector->receiver_hostname,receiverIP.c_str()); if(setReceiverOnline(ONLINE_FLAG)==ONLINE_FLAG){ +#ifdef VERBOSE + std::cout << "Setting up receiver with" << endl << + "file path:" << fileIO::getFilePath() << endl << + "file name:" << fileIO::getFileName() << endl << + "file index:" << fileIO::getFileIndex() << endl << + "frame index needed:" << ((setTimer(FRAME_NUMBER,-1)*setTimer(CYCLES_NUMBER,-1))>1) << endl << + "write enable:" << parentDet->enableWriteToFileMask() << endl << + "frame period:" << setTimer(FRAME_PERIOD,-1) << endl << endl; +#endif setFilePath(fileIO::getFilePath()); setFileName(fileIO::getFileName()); setFileIndex(fileIO::getFileIndex()); @@ -4808,6 +4836,7 @@ char* slsDetector::setReceiver(string receiverIP){ else setFrameIndex(-1); enableWriteToFile(parentDet->enableWriteToFileMask()); + setTimer(FRAME_PERIOD,setTimer(FRAME_PERIOD,-1)); setUDPConnection(); } diff --git a/slsDetectorSoftware/slsDetector/slsDetectorCommand.cpp b/slsDetectorSoftware/slsDetector/slsDetectorCommand.cpp index 552c0ef25..5b09c029d 100644 --- a/slsDetectorSoftware/slsDetector/slsDetectorCommand.cpp +++ b/slsDetectorSoftware/slsDetector/slsDetectorCommand.cpp @@ -3965,8 +3965,12 @@ string slsDetectorCommand::cmdReceiver(int narg, char *args[], int action) { if (action==PUT_ACTION) { if(!strcasecmp(args[1],"start")) myDet->startReceiver(); - else if(!strcasecmp(args[1],"stop")) + else if(!strcasecmp(args[1],"stop")){ + myDet->startReceiverReadout(); + while(myDet->getReceiverStatus() != RUN_FINISHED) + usleep(50000); myDet->stopReceiver(); + } else return helpReceiver(narg, args, action); } diff --git a/slsDetectorSoftware/slsDetector/slsDetectorUtils.cpp b/slsDetectorSoftware/slsDetector/slsDetectorUtils.cpp index 6547d6f67..d77b6bc84 100644 --- a/slsDetectorSoftware/slsDetector/slsDetectorUtils.cpp +++ b/slsDetectorSoftware/slsDetector/slsDetectorUtils.cpp @@ -336,13 +336,13 @@ void slsDetectorUtils::acquire(int delflag){ pthread_mutex_unlock(&mg); }else{ pthread_mutex_lock(&mg); - if(startReceiverReadout() == TRANSMITTING){ - while(getReceiverStatus() != RUN_FINISHED){ - pthread_mutex_unlock(&mg); - usleep(50000); - pthread_mutex_lock(&mg); - } - } + startReceiverReadout(); + while(getReceiverStatus() != RUN_FINISHED){ + pthread_mutex_unlock(&mg); + usleep(50000); + pthread_mutex_lock(&mg); + } + stopReceiver(); pthread_mutex_unlock(&mg); } diff --git a/slsDetectorSoftware/slsDetectorAnalysis/fileIOStatic.h b/slsDetectorSoftware/slsDetectorAnalysis/fileIOStatic.h index 6b4afa8ee..9bc8d7267 100644 --- a/slsDetectorSoftware/slsDetectorAnalysis/fileIOStatic.h +++ b/slsDetectorSoftware/slsDetectorAnalysis/fileIOStatic.h @@ -133,7 +133,7 @@ class fileIOStatic { if (sscanf( s.substr(uscore+1,s.size()-uscore-1).c_str(),"f%d",&i)) \ if(i==-1)return 0; \ else return i; \ - cout << "******************************** cannot parse frame index" << endl; \ + /*cout << "******************************** cannot parse frame index" << endl; \*/ return 0; \ }; diff --git a/slsDetectorSoftware/slsDetectorAnalysis/singlePhotonFilter.cpp b/slsDetectorSoftware/slsDetectorAnalysis/singlePhotonFilter.cpp index 6b24e84c9..1b7159b70 100644 --- a/slsDetectorSoftware/slsDetectorAnalysis/singlePhotonFilter.cpp +++ b/slsDetectorSoftware/slsDetectorAnalysis/singlePhotonFilter.cpp @@ -7,11 +7,13 @@ #define BUF_SIZE (16*1024*1024) //16mb +#define HEADER_SIZE_NUM_FRAMES 2 +#define HEADER_SIZE_NUM_PACKETS 1 singlePhotonFilter::singlePhotonFilter(int nx, int ny, int fmask, int pmask, int foffset, int poffset, int pperf, int iValue, - int16_t *m, int16_t *s, CircularFifo* f, int d): + int16_t *m, int16_t *s, CircularFifo* f, int d, int* tfcaught, int* fcaught): #ifdef MYROOT1 myTree(NULL), myFile(NULL), @@ -52,8 +54,11 @@ singlePhotonFilter::singlePhotonFilter(int nx, int ny, currentThread(-1), thisThreadIndex(-1), fileIndex(0), - fifo(f){ - + fifo(f), + totalFramesCaught(tfcaught), + framesCaught(fcaught), + freeFifoCallBack(NULL), + pFreeFifo(NULL){ #ifndef MYROOT1 photonHitList = new single_photon_hit[nChannelsX*nChannelsY]; #endif @@ -216,6 +221,7 @@ int singlePhotonFilter::writeToFile(){ if(myFile){ /*cout<<"writing "<< nHitsPerFrame << " hits to file" << endl;*/ fwrite((void*)(photonHitList), 1, sizeof(single_photon_hit)*nHitsPerFrame, myFile); + /*framesInFile += nHitsPerFrame;*/ nHitsPerFrame = 0; //cout<<"Exiting writeToFile"<>frame_index_offset) - f0; + (*framesCaught)++; + (*totalFramesCaught)++; + isData += HEADER_SIZE_NUM_PACKETS; + clusteriframe = (((uint32_t)(*((uint32_t*)(isData)))& frame_index_mask) >>frame_index_offset); +#ifdef VERYVERBOSE + cout << "scurrframnum:" << clusteriframe << endl; +#endif + clusteriframe -= f0; + myData = (int16_t*)isData; + //for each pixel for (ir=0; irCalc((double)nHitsPerFrame); - + //write for each frame, not packet pthread_mutex_lock(&write_mutex); writeToFile(); - fifo->push(isData); + //fifo->push(isData); pthread_mutex_unlock(&write_mutex); - isData += 4096; - myData += 2048; + //increment offset + isData += dataSize; -/* + /* if ((clusteriframe%1000 == 0) && (clusteriframe != 0) ){ cout << dec << "Frame: " << clusteriframe << " Hit Avg over last frames: " << nHitStat->Mean() << " .. "<StandardDeviation() << endl; cout<<"writing "<< nHitsPerFrame << " hits to file" << endl; } -*/ - - + */ } + pthread_mutex_lock(&write_mutex); + if(freeFifoCallBack) + freeFifoCallBack(freeData,pFreeFifo); + //fifo->push(freeData);//fifo->push(isData); + pthread_mutex_unlock(&write_mutex); + + //thread not running pthread_mutex_lock(&running_mutex); threads_mask^=(1<* f, - int d); + int d, + int* tfcaught, + int* fcaught); /** virtual destructor */ virtual ~singlePhotonFilter(); @@ -167,10 +171,24 @@ public: /** reconstruct the frame with all the right packets * @param inData the data from socket to be verified - * returns 0 if still waiting for next packet of same frame, - * 1 if end of complete frame, -1 if end of incomplete frame, - * -2 first packet of next frame, so push previous one; -3 last packet of current frame, push both frames - * */ + * returns + * 0: waiting for next packet of new frame + * 1: finished with full frame, + * start new frame + * -1: last packet of current frame, + * invalidate remaining packets, + * start new frame + * -2: first packet of new frame, + * invalidate remaining packets, + * check buffer needs to be pushed, + * start new frame with the current packet, + * then ret = 0 + * -3: last packet of new frame, + * invalidate remaining packets, + * check buffer needs to be pushed, + * start new frame with current packet, + * then ret = -1 (invalidate remaining packets and start a new frame) + */ int verifyFrame(char *inData); /** @@ -200,6 +218,13 @@ public: * */ int checkIfJobsDone(); + /** + * call back to free fifo + * call back arguments are + * fbuffer buffer address to be freed + */ + void registerCallBackFreeFifo(void (*func)(char*, void*),void *arg){freeFifoCallBack=func; pFreeFifo=arg;}; + private: @@ -227,7 +252,7 @@ private: int nHitsPerFrame; /** Maximum Number of hits written to file */ - const static int MAX_HITS_PER_FILE = 200000; + const static int MAX_HITS_PER_FILE = 2000000; /** Number of Channels in X direction */ int nChannelsX; @@ -376,6 +401,18 @@ private: /** circular fifo buffer to be freed */ CircularFifo* fifo; + + /**total frames caught */ + int* totalFramesCaught; + + /** frames caught */ + int* framesCaught; + + /** call back function */ + void (*freeFifoCallBack)(char*, void*); + + /** call back arguments */ + void *pFreeFifo; }; diff --git a/slsDetectorSoftware/slsReceiver/circularFifo.h b/slsDetectorSoftware/slsReceiver/circularFifo.h index e57a59192..645168c35 100644 --- a/slsDetectorSoftware/slsReceiver/circularFifo.h +++ b/slsDetectorSoftware/slsReceiver/circularFifo.h @@ -16,7 +16,7 @@ #define CIRCULARFIFO_H_ //#include "sls_detector_defs.h" - +#include #include using namespace std; @@ -35,6 +35,7 @@ public: CircularFifo(unsigned int Size) : tail(0), head(0){ Capacity = Size + 1; array.resize(Capacity); + sem_init(&free_mutex,0,0); } virtual ~CircularFifo() {} @@ -49,6 +50,7 @@ private: vector array; volatile unsigned int head; // output index unsigned int Capacity; + sem_t free_mutex; unsigned int increment(unsigned int idx_) const; }; @@ -70,6 +72,7 @@ bool CircularFifo::push(Element*& item_) { array[tail] = item_; tail = nextTail; + sem_post(&free_mutex); return true; } @@ -86,8 +89,9 @@ bool CircularFifo::push(Element*& item_) template bool CircularFifo::pop(Element*& item_) { - if(head == tail) - return false; // empty queue + // if(head == tail) + // return false; // empty queue + sem_wait(&free_mutex); item_ = array[head]; head = increment(head); diff --git a/slsDetectorSoftware/slsReceiver/receiver_defs.h b/slsDetectorSoftware/slsReceiver/receiver_defs.h index a9c800e21..3231385ee 100755 --- a/slsDetectorSoftware/slsReceiver/receiver_defs.h +++ b/slsDetectorSoftware/slsReceiver/receiver_defs.h @@ -11,15 +11,18 @@ #define CREATE_FILES 1 #define DO_EVERYTHING 2 -#define BUF_SIZE (16*1024*1024) //16mb +#define BUF_SIZE (16*1024*1024) //16mb +#define SAMPLE_TIME_IN_NS 100000000//100ms +#define MAX_JOBS_PER_THREAD 1000 +#define HEADER_SIZE_NUM_FRAMES 2 +#define HEADER_SIZE_NUM_PACKETS 1 + //all max frames defined in sls_detector_defs.h. 20000 gotthard, 100000 for short gotthard, 1000 for moench - -//#define GOTTHARD_FIFO_SIZE 25000 -#define GOTTHARD_FIFO_SIZE 11 -#define GOTTHARD_ALIGNED_FRAME_SIZE 4096 +#define GOTTHARD_FIFO_SIZE 25000 //cannot be less than max jobs per thread = 1000 +/*#define GOTTHARD_ALIGNED_FRAME_SIZE 4096*/ #define GOTTHARD_PACKETS_PER_FRAME 2 #define GOTTHARD_ONE_PACKET_SIZE 1286 #define GOTTHARD_BUFFER_SIZE (GOTTHARD_ONE_PACKET_SIZE*GOTTHARD_PACKETS_PER_FRAME) //1286*2 @@ -37,13 +40,9 @@ #define GOTTHARD_PACKET_INDEX_MASK 0x1 -//#define GOTTHARD_NUM_JOBS_P_THREAD 5000//20000 -#define GOTTHARD_NUM_JOBS_P_THREAD 3//with 25 frames -#define GOTTHARD_SHORT_NUM_JOBS_P_THREAD 2500//40000 -#define MOENCH_NUM_JOBS_P_THREAD 1000//10000 -#define MOENCH_FIFO_SIZE 2500 -#define MOENCH_ALIGNED_FRAME_SIZE 65536 +#define MOENCH_FIFO_SIZE 2500 //cannot be less than max jobs per thread = 1000 +/*#define MOENCH_ALIGNED_FRAME_SIZE 65536*/ #define MOENCH_PACKETS_PER_FRAME 40 #define MOENCH_ONE_PACKET_SIZE 1286 #define MOENCH_BUFFER_SIZE (MOENCH_ONE_PACKET_SIZE*MOENCH_PACKETS_PER_FRAME) //1286*40 diff --git a/slsDetectorSoftware/slsReceiver/slsReceiverFunctionList.cpp b/slsDetectorSoftware/slsReceiver/slsReceiverFunctionList.cpp index a5db702c3..419ebc5d2 100644 --- a/slsDetectorSoftware/slsReceiver/slsReceiverFunctionList.cpp +++ b/slsDetectorSoftware/slsReceiver/slsReceiverFunctionList.cpp @@ -37,9 +37,9 @@ slsReceiverFunctionList::slsReceiverFunctionList(detectorType det): frameIndex(0), totalFramesCaught(0), totalPacketsCaught(0), + framesInFile(0), startAcquisitionIndex(0), acquisitionIndex(0), - packetsInFile(0), prevframenum(0), listening_thread_running(0), writing_thread_running(0), @@ -61,8 +61,8 @@ slsReceiverFunctionList::slsReceiverFunctionList(detectorType det): frameIndexMask(GOTTHARD_FRAME_INDEX_MASK), frameIndexOffset(GOTTHARD_FRAME_INDEX_OFFSET), dataCompression(false), - numJobsPerThread(GOTTHARD_NUM_JOBS_P_THREAD), - userDefinedNumJobsPerThread(0), + numJobsPerThread(-1), + acquisitionPeriod(SAMPLE_TIME_IN_NS), startAcquisitionCallBack(NULL), pStartAcquisition(NULL), acquisitionFinishedCallBack(NULL), @@ -73,23 +73,16 @@ slsReceiverFunctionList::slsReceiverFunctionList(detectorType det): { - int aligned_frame_size = GOTTHARD_ALIGNED_FRAME_SIZE; if(myDetectorType == MOENCH){ - aligned_frame_size = MOENCH_ALIGNED_FRAME_SIZE; fifosize = MOENCH_FIFO_SIZE; maxFramesPerFile = MOENCH_MAX_FRAMES_PER_FILE; bufferSize = MOENCH_BUFFER_SIZE; packetsPerFrame = MOENCH_PACKETS_PER_FRAME; frameIndexMask = MOENCH_FRAME_INDEX_MASK; frameIndexOffset = MOENCH_FRAME_INDEX_OFFSET; - numJobsPerThread = MOENCH_NUM_JOBS_P_THREAD; } - if(userDefinedNumJobsPerThread) - numJobsPerThread = userDefinedNumJobsPerThread; - - oneBufferSize = bufferSize/packetsPerFrame; strcpy(savefilename,""); @@ -101,22 +94,12 @@ slsReceiverFunctionList::slsReceiverFunctionList(detectorType det): strcpy(eth,""); latestData = new char[bufferSize]; - fifofree = new CircularFifo(fifosize); - fifo = new CircularFifo(fifosize); - - mem0=(char*)malloc(aligned_frame_size*fifosize); - if (mem0==NULL) { - cout<<"++++++++++++++++++++++ COULD NOT ALLOCATE MEMORY!!!!!!!+++++++++++++++++++++" << endl; - } - buffer=mem0; - while (buffer<(mem0+aligned_frame_size*(fifosize-1))) { - fifofree->push(buffer); - buffer+=aligned_frame_size; - } + setupFifoStructure(); + //for the filter int16_t* map; int16_t* mask; int initial_offset = 2; @@ -172,7 +155,7 @@ slsReceiverFunctionList::slsReceiverFunctionList(detectorType det): filter = new singlePhotonFilter(x,y, MOENCH_FRAME_INDEX_MASK, MOENCH_PACKET_INDEX_MASK, MOENCH_FRAME_INDEX_OFFSET, - 0, MOENCH_PACKETS_PER_FRAME, 0,map, mask,fifofree,MOENCH_BUFFER_SIZE); + 0, MOENCH_PACKETS_PER_FRAME, 0,map, mask,fifofree,MOENCH_BUFFER_SIZE,&totalFramesCaught,&framesCaught); break; default: x = 1; @@ -197,21 +180,21 @@ slsReceiverFunctionList::slsReceiverFunctionList(detectorType det): offset += 1; } map[i*y+j] = offset; - /*cout<<"offset["<registerCallBackFreeFifo(&(freeFifoBufferCallBack),this); + dataCompression = false; } @@ -305,9 +288,9 @@ void slsReceiverFunctionList::resetTotalFramesCaught(){ int slsReceiverFunctionList::startReceiver(char message[]){ -#ifdef VERBOSE +//#ifdef VERBOSE cout << "Starting Receiver" << endl; -#endif +//#endif cout << endl; int err = 0; @@ -406,14 +389,15 @@ int slsReceiverFunctionList::startReceiver(char message[]){ listen_param.sched_priority = 99; write_param.sched_priority = 90; - - if (pthread_setschedparam(listening_thread, policy, &listen_param) == EPERM) - cout << "WARNING: Could not prioritize threads. You need to be super user for that." << endl; - if (pthread_setschedparam(writing_thread, policy, &write_param) == EPERM) - cout << "WARNING: Could not prioritize threads. You need to be super user for that." << endl; - if (pthread_setschedparam(pthread_self(),5 , &tcp_param) == EPERM) - cout << "WARNING: Could not prioritize threads. You need to be super user for that." << endl; - + /*** ???????????????????????????*/ + if(!dataCompression){ + if (pthread_setschedparam(listening_thread, policy, &listen_param) == EPERM) + cout << "WARNING: Could not prioritize threads. You need to be super user for that." << endl; + if (pthread_setschedparam(writing_thread, policy, &write_param) == EPERM) + cout << "WARNING: Could not prioritize threads. You need to be super user for that." << endl; + if (pthread_setschedparam(pthread_self(),5 , &tcp_param) == EPERM) + cout << "WARNING: Could not prioritize threads. You need to be super user for that." << endl; + } //pthread_getschedparam(pthread_self(),&policy,&tcp_param); //cout << "current priority of main tcp thread is " << tcp_param.sched_priority << endl; @@ -436,19 +420,21 @@ int slsReceiverFunctionList::stopReceiver(){ //#endif if(receiver_threads_running){ -//#ifdef VERBOSE +#ifdef VERBOSE cout << "Stopping new acquisition thread" << endl; -//#endif +#endif //stop listening thread pthread_mutex_lock(&status_mutex); receiver_threads_running=0; pthread_mutex_unlock(&(status_mutex)); - if(udpSocket) udpSocket->ShutDownSocket(); - pthread_join(listening_thread,NULL); - pthread_join(writing_thread,NULL); - /*if(dataCompression) - filter->enableCompression(false);*/ + if(listening_thread_running == 1){ + if(udpSocket) udpSocket->ShutDownSocket(); + pthread_join(listening_thread,NULL); + } + if(writing_thread_running == 1) + pthread_join(writing_thread,NULL); + } //change status pthread_mutex_lock(&status_mutex); @@ -488,11 +474,17 @@ int slsReceiverFunctionList::startListening(){ int rc=0; measurementStarted = false; startFrameIndex = 0; + int offset=0; + int frameStartOffset = 0; int ret=1; int i=0; + int framesCount = -1; + int packetsCount = 0; char *tempchar = new char[oneBufferSize]; - +#ifdef VERYVERBOSE + int totalcount = 0; +#endif //to increase socket receiver buffer size and max length of input queue by changing kernel settings if(system("echo $((100*1024*1024)) > /proc/sys/net/core/rmem_max")) @@ -533,120 +525,194 @@ int slsReceiverFunctionList::startListening(){ return 0; }else{ - /*filter->setupAcquisitionParameters();*/ - - while (receiver_threads_running) { - if (!fifofree->isEmpty()) { - if (ret!=0) - while(!fifofree->pop(buffer)); + //push buffer + if(framesCount >= numJobsPerThread){ + //write frame count for each buffer + (*((uint16_t*)buffer)) = framesCount; + while(!fifo->push(buffer)); +#ifdef VERYVERBOSE + cout << "lbuf1:" << (void*)buffer << endl; +#endif + } - if(ret == -3){ - memcpy(buffer,tempchar,oneBufferSize); - offset = oneBufferSize; - //set all the new frame header and remaining headers invalid - for(i = offset; i < bufferSize; i += oneBufferSize) - (*((uint32_t*)(buffer+i))) = 0xFFFFFFFF; - //start from beginning - offset = 0; - ret = 0; + //pop freefifo + if((framesCount >= numJobsPerThread) || (framesCount == -1)){ + //reset frame count and packet count + framesCount = 0; + packetsCount = 0; + //pop freefifo + if(!fifofree->isEmpty()) + fifofree->pop(buffer); + //increment offsets + offset = HEADER_SIZE_NUM_FRAMES; + offset += HEADER_SIZE_NUM_PACKETS; + frameStartOffset = HEADER_SIZE_NUM_FRAMES; + } + + //let tcp thread know this thread is in working condition + if(!startFrameIndex){ + if(!listening_thread_running){ + pthread_mutex_lock(&status_mutex); + listening_thread_running = 1; + pthread_mutex_unlock(&(status_mutex)); } - else{ - if(ret == -2){/** for moench, in between nxt, means ots -1*/ - memcpy(buffer,tempchar,oneBufferSize); - offset = oneBufferSize; - ret = 0; + } + + + //ret -2, remaining, start new frame with curent packet, then progress to ret = 0 (waiting for next packet) + if(ret == -2){ + memcpy(buffer+offset,tempchar,oneBufferSize); + ret = 0; + } + + //ret = -3, remaning: start new frame with current packet, progress to ret = -1 (invalidate remaining packets, start new frame) + else if(ret == -3){ + memcpy(buffer+offset,tempchar,oneBufferSize); + ret = -1; + } + + + + else{ + //receive 1 packet + rc = udpSocket->ReceiveDataOnly(buffer+offset,oneBufferSize); + if( rc <= 0){ + //#ifdef VERYVERBOSE + cerr << "recvfrom() failed:"< 0){ + (*((uint16_t*)buffer)) = framesCount; + fifo->push(buffer); +#ifdef VERYVERBOSE + cout <<" last lbuf1:" << (void*)buffer << endl; +#endif } + //push in dummy packet + while(fifofree->isEmpty()); + fifofree->pop(buffer); + (*((uint16_t*)buffer)) = 0xFFFF; + fifo->push(buffer); +#ifdef VERYVERBOSE + cout << "pushed in dummy buffer:" << (void*)buffer << endl; +#endif + + break; } - //receiver 2 half frames / 1 short frame / 40 moench frames - rc = udpSocket->ReceiveDataOnly(buffer+offset,oneBufferSize); - if( rc <= 0){ - //#ifdef VERYVERBOSE - cerr << "recvfrom() failed:"<push(buffer); - cout<<"***************buffer pushed!!"<<(void*)buffer<verifyFrame(buffer+offset); - - //start for each scan - if(!measurementStarted){ - startFrameIndex = ((((uint32_t)(*((uint32_t*)buffer))) & (frameIndexMask)) >> frameIndexOffset); - cout<<"startFrameIndex:"<> frameIndexOffset); + cout<<"startFrameIndex:"<isFull())){ - fifo->push(buffer); + //start of acquisition + if(!acqStarted){ + startAcquisitionIndex=startFrameIndex; + currframenum = startAcquisitionIndex; + acqStarted = true; + cout<<"startAcquisitionIndex:"<verifyFrame(buffer+offset); + /* + rets + case 0: waiting for next packet of new frame + case 1: finished with full frame, + start new frame + case -1: last packet of current frame, + invalidate remaining packets, + start new frame + case -2: first packet of new frame, + invalidate remaining packets, + check buffer needs to be pushed, + start new frame with the current packet, + then ret = 0 + case -3: last packet of new frame, + invalidate remaining packets, + check buffer needs to be pushed, + start new frame with current packet, + then ret = -1 (invalidate remaining packets and start a new frame) + */ + } + + + //for each packet + packetsCount++; + + //ret = 0, so just increment offset and continue + if(ret == 0){ + offset += oneBufferSize; + continue; + } + + + //ret -2, -3, copy the current packet temporarily + if(ret < -1){ + memcpy(tempchar, buffer+offset, oneBufferSize); + packetsCount --; + } + //ret -1, change needed only for the remaining packets + else if (ret == -1){ + offset += oneBufferSize; + ret = 1; + } + + //ret = -1, -2, -3, invalidate remaining packets + if(ret < 0){ + for( i = offset; i < bufferSize; i += oneBufferSize) + (*((uint32_t*)(buffer+i))) = 0xFFFFFFFF; + } + + + + //for each frame + //write packet count + (*((uint8_t*)(buffer+frameStartOffset))) = packetsCount; + //reset packet count + packetsCount = 0; + //increment frame count + framesCount++; +#ifdef VERYVERBOSE + totalcount++; + cout<<"lcurrframnum:"<< dec<< + (((uint32_t)(*((uint32_t*)(buffer+offset))) & frameIndexMask) >> frameIndexOffset)<<"*"<setupAcquisitionParameters(filePath,fileName,fileIndex); + // if(enableFileWrite && cbAction > DO_NOTHING) + // This commented option doesnt exist as we save and do ebverything for data compression + //create file + i = filter->initTree(); + } + //file/tree not created + if(i == FAIL){ + cout << " Error: Could not create file " << savefilename << endl; + pthread_mutex_lock(&status_mutex); + writing_thread_running = -1; + pthread_mutex_unlock(&(status_mutex)); + } - //will always run till acquisition over and then runs till fifo is empty - while(receiver_threads_running || (!fifo->isEmpty())){ + else{ + //let tcp thread know it started successfully + pthread_mutex_lock(&status_mutex); + writing_thread_running = 1; + pthread_mutex_unlock(&(status_mutex)); - //start a new file - if ((strlen(savefilename) == 0) || ((packetsInFile/packetsPerFrame) >= maxFramesPerFile)){ - - //create file name - if(!dataCompression){ - if(frameIndexNeeded==-1) - sprintf(savefilename, "%s/%s_%d.raw", filePath,fileName,fileIndex); - else - sprintf(savefilename, "%s/%s_f%012d_%d.raw", filePath,fileName,framesCaught,fileIndex); - } - - //only for gui display - else if(strlen(savefilename) == 0){ - sprintf(savefilename, "%s/%s_fxxx_%d.raw", filePath,fileName,fileIndex); - filter->setupAcquisitionParameters(filePath,fileName,fileIndex); - } - - - - if(enableFileWrite && cbAction > DO_NOTHING){ - if (dataCompression){ - //only the first time - if ((!framesCaught) && (filter->initTree()== FAIL)){ - cout << " Error: Could not create file " << savefilename << endl; - pthread_mutex_lock(&status_mutex); - writing_thread_running = -1; - pthread_mutex_unlock(&(status_mutex)); - break; - } - } - - - //standard way - else{ - //close and open file - if(sfilefd){ - fclose(sfilefd); - sfilefd = NULL; - } - if (NULL == (sfilefd = fopen((const char *) (savefilename), "w"))){ - cout << "Error: Could not create file " << savefilename << endl; - pthread_mutex_lock(&status_mutex); - writing_thread_running = -1; - pthread_mutex_unlock(&(status_mutex)); - break; - } - //setting buffer - setvbuf(sfilefd,NULL,_IOFBF,BUF_SIZE); - - - //printing packet losses and file names - if(!framesCaught) - cout << savefilename << endl; - else{ - cout << savefilename - << "\tpacket loss " - << setw(4)<isEmpty()){ + cout << "Ready!" << endl; + //will always run till acquisition over and then runs till fifo is empty + while(receiver_threads_running || (!fifo->isEmpty())){ + //pop fifo if(fifo->pop(wbuf)){ - currframenum = ((uint32_t)(*((uint32_t*)wbuf))& frameIndexMask) >>frameIndexOffset; - //cout<<"currframenum2:"<<((((uint32_t)(*((uint32_t*)((char*)(wbuf+oneBufferSize)))))& frameIndexMask) >> frameIndexOffset)<= (fifosize-1)){ - /*cout<<"*** sending not normally "<assignJobsForThread(startingmem,iJob); - startingmem = mem0; - iJob = 0; - pointinfifo = 0; - /*cout<<"***************1trialmem:"<<(void*)startingmem<=(numJobsPerThread)){ - /*cout<<"*** sending normally "< - filter->assignJobsForThread(startingmem,numJobsPerThread); - iJob = -2; - } - } - - - //standard way - else{ - //find number of packets received - for(i=0,p=0; i < bufferSize; i+=oneBufferSize,++p){ - if(((uint32_t)(*((uint32_t*)((wbuf+i))))) == 0xFFFFFFFF){ - break; - } - } - //increment counters - totalPacketsCaught += p; - packetsInFile += p; - if(p == packetsPerFrame){ - framesCaught++; - totalFramesCaught++; - } - //write to file - if(sfilefd) - fwrite(wbuf, 1, p*oneBufferSize, sfilefd); - else{ - cout << "You do not have permissions to overwrite: " << savefilename << endl; - usleep(50000); - } - } - } + //number of frames per buffer + numFrames = (uint16_t)(*((uint16_t*)wbuf)); - //does not read every frame - if(!nFrameToGui){ - if((guiData) && (p == packetsPerFrame)){/*change it in funcs*/ - /* if(guiData){*/ - pthread_mutex_lock(&dataReadyMutex); - guiDataReady=0; - pthread_mutex_unlock(&dataReadyMutex); - memcpy(latestData,wbuf,bufferSize); - strcpy(guiFileName,savefilename); - pthread_mutex_lock(&dataReadyMutex); - guiDataReady=1; - pthread_mutex_unlock(&dataReadyMutex); - }else{ - pthread_mutex_lock(&dataReadyMutex); - guiDataReady=0; - pthread_mutex_unlock(&dataReadyMutex); - } - } - //reads every nth frame - else{ - if (p != packetsPerFrame)//so no 1 packet frame writing over previous 2 packet frame - ; - else if(frameFactor){ - frameFactor--; - }else{ - frameFactor = nFrameToGui-1; - //block current process if the guireader hasnt read it yet - sem_wait(&smp); - //copy data and set guidataready - pthread_mutex_lock(&dataReadyMutex); - guiDataReady=0; - pthread_mutex_unlock(&dataReadyMutex); - memcpy(latestData,wbuf,bufferSize); - strcpy(guiFileName,savefilename); - pthread_mutex_lock(&dataReadyMutex); - guiDataReady = 1; - pthread_mutex_unlock(&dataReadyMutex); - - } - } - - - if(!dataCompression) + //last dummy packet + if(numFrames == 0xFFFF){ +#ifdef VERYVERBOSE + cout << "popped last dummy frame:" << (void*)wbuf << endl; +#endif fifofree->push(wbuf); - } - } - else{//cout<<"************************fifo empty**********************************"<0){ - cout<<"sending at the end "<assignJobsForThread(startingmem,iJob); - iJob = -2; - } - //no more popped data - else{ - //all jobs done - if(filter->checkIfJobsDone()){ - if(fifo->isEmpty()){ - //its all done - pthread_mutex_lock(&status_mutex); - status = RUN_FINISHED; - pthread_mutex_unlock(&(status_mutex)); - cout << "Status: Run Finished" << endl; - } +/* + cout <<"fifofree is full?:" << fifofree->isFull()<isEmpty()<isEmpty() && status == TRANSMITTING){ + cout<<"inside transmitting"<checkIfJobsDone()) + usleep(50000); } +/* + cout <<"fifofree is full?:" << fifofree->isFull()<isEmpty()<isEmpty()){ + cout<<"popped:"<pop(buffer)<>frameIndexOffset); +#ifdef VERYVERBOSE + cout << "currframnum:" << dec << currframenum << endl; +#endif + + //send it for writing and data compression + if(dataCompression) + filter->assignJobsForThread(wbuf, numFrames); + //standard way else{ - pthread_mutex_lock(&status_mutex); - status = RUN_FINISHED; - pthread_mutex_unlock(&(status_mutex)); - cout << "***** Status: Run Finished *****" << endl; + //write data call back + if (cbAction < DO_EVERYTHING) { + rawDataReadyCallBack(currframenum, wbuf, numFrames * bufferSize, sfilefd, guiData,pRawDataReady); + } + else { + offset = HEADER_SIZE_NUM_FRAMES; + + while(numFrames > 0){ + //to make sure, we write according to max frames per file + numFramesToBeSaved = maxFramesPerFile - framesInFile; + if(numFramesToBeSaved > numFrames) + numFramesToBeSaved = numFrames; + + //write packets to file + for(i = 0; i < numFramesToBeSaved; i++){ + //determine number of packets + npackets = (uint8_t)(*((uint8_t*)(wbuf + offset))); + totalPacketsCaught += npackets; + offset += HEADER_SIZE_NUM_PACKETS; + //write to file + if(enableFileWrite){ + if(sfilefd) + fwrite(wbuf+offset, 1, npackets * oneBufferSize, sfilefd); + else{ + if(!totalPacketsCaught) + cout << "ERROR: You do not have permissions to overwrite: " << savefilename << endl; + } + } + + + //increment offset + offset += bufferSize; + } + + + + //increment/decrement counters + framesInFile += numFramesToBeSaved; + framesCaught += numFramesToBeSaved; + totalFramesCaught += numFramesToBeSaved; + numFrames -= numFramesToBeSaved; + //create new file + if(framesInFile >= maxFramesPerFile) + createNewFile(); + + } + } + } + + + copyFrameToGui(wbuf + HEADER_SIZE_NUM_FRAMES + HEADER_SIZE_NUM_PACKETS); + + + if(!dataCompression){ + fifofree->push(wbuf); +#ifdef VERYVERBOSE + cout<<"buf freed:"<<(void*)wbuf< DO_NOTHING){ + //close + if(sfilefd){ + fclose(sfilefd); + sfilefd = NULL; + } + //open file + if (NULL == (sfilefd = fopen((const char *) (savefilename), "w"))){ + cout << "Error: Could not create file " << savefilename << endl; + pthread_mutex_lock(&status_mutex); + writing_thread_running = -1; + pthread_mutex_unlock(&(status_mutex)); + return FAIL; + } + //setting buffer + setvbuf(sfilefd,NULL,_IOFBF,BUF_SIZE); + //printing packet losses and file names + if(!framesCaught) + cout << savefilename << endl; + else{ + cout << savefilename + << "\tpacket loss " + << setw(4)<ShutDownSocket(); } #endif + + + +int slsReceiverFunctionList::setNFrameToGui(int i){ + if(i>=0){ + nFrameToGui = i; + setupFifoStructure(); + } + return nFrameToGui; +}; + + +int64_t slsReceiverFunctionList::setAcquisitionPeriod(int64_t index){ + if(index >= 0){ + if(index != acquisitionPeriod){ + acquisitionPeriod = index; + setupFifoStructure(); + } + } + return acquisitionPeriod; +}; + + + +void slsReceiverFunctionList::setupFifoStructure(){ + int64_t i; + int oldn = numJobsPerThread; + + //if every nth frame mode + if(nFrameToGui) + numJobsPerThread = nFrameToGui; + + //random nth frame mode + else{ + if(!acquisitionPeriod) + i = SAMPLE_TIME_IN_NS; + else + i = SAMPLE_TIME_IN_NS/acquisitionPeriod; + if (i > MAX_JOBS_PER_THREAD) + numJobsPerThread = MAX_JOBS_PER_THREAD; + else if (i < 1) + numJobsPerThread = 1; + else + numJobsPerThread = i; + } + + + //if same, return + if(oldn == numJobsPerThread) + return; + + + //deleting old structure and creating fifo structure + if(fifofree){ + while(!fifofree->isEmpty()) + fifofree->pop(buffer); + delete fifofree; + } + if(fifo) delete fifo; + if(mem0) free(mem0); + fifofree = new CircularFifo(fifosize); + fifo = new CircularFifo(fifosize); + + + //otherwise memory too much if numjobsperthread is at max = 1000 + fifosize = GOTTHARD_FIFO_SIZE; + if(myDetectorType == MOENCH) + fifosize = MOENCH_FIFO_SIZE; + + if(fifosize % numJobsPerThread) + fifosize = (fifosize/numJobsPerThread)+1; + else + fifosize = fifosize/numJobsPerThread; + + + /* + fifosize = 11; + numJobsPerThread = 3; +*/ + //allocate memory + mem0=(char*)malloc(((bufferSize+HEADER_SIZE_NUM_PACKETS)*numJobsPerThread+HEADER_SIZE_NUM_FRAMES)*fifosize); + + if (mem0==NULL) /** shud let the client know about this */ + cout<<"++++++++++++++++++++++ COULD NOT ALLOCATE MEMORY!!!!!!!+++++++++++++++++++++" << endl; + buffer=mem0; + + //push the addresses into freed fifo + while (buffer<(mem0+((bufferSize+HEADER_SIZE_NUM_PACKETS)*numJobsPerThread+HEADER_SIZE_NUM_FRAMES)*(fifosize-1))) { + fifofree->push(buffer); + buffer+=((bufferSize+HEADER_SIZE_NUM_PACKETS)*numJobsPerThread+HEADER_SIZE_NUM_FRAMES); + } + + cout<<"Number of Frames per buffer:"<=0) nFrameToGui = i; return nFrameToGui;}; - /** set status to transmitting and * when fifo is empty later, sets status to run_finished */ void startReadout(); /** enabl data compression, by saving only hits */ - void enableDataCompression(bool enable){dataCompression = enable;filter->enableCompression(enable);}; + void enableDataCompression(bool enable){dataCompression = enable;if(filter)filter->enableCompression(enable);}; /** get data compression, by saving only hits */ bool getDataCompression(){ return dataCompression;}; - /** Set Number of Jobs Per Thread */ - void setNumberOfJobsPerThread(int i){userDefinedNumJobsPerThread = i; numJobsPerThread = i;}; + /** + * Set the variable to send every nth frame to gui + * or if 0,send frame only upon gui request + */ + int setNFrameToGui(int i); + + /** set acquisition period if a positive number */ + int64_t setAcquisitionPeriod(int64_t index); + + /** set up fifo according to the new numjobsperthread */ + void setupFifoStructure (); + + /** free fifo buffer, called back from single photon filter */ + static void freeFifoBufferCallBack (char* fbuffer, void *this_pointer){((slsReceiverFunctionList*)this_pointer)->freeFifoBuffer(fbuffer);}; + void freeFifoBuffer(char* fbuffer){fifofree->push(fbuffer);}; + + private: @@ -264,15 +285,15 @@ private: /** Total packets caught for an entire acquisition (including all scans) */ int totalPacketsCaught; + /** Frames currently in current file, starts new file when it reaches max */ + int framesInFile; + /** Frame index at start of an entire acquisition (including all scans) */ uint32_t startAcquisitionIndex; /** Actual current frame index of an entire acquisition (including all scans) */ uint32_t acquisitionIndex; - /** Packets currently in current file, starts new file when it reaches max */ - int packetsInFile; - /** Previous Frame number from buffer */ uint32_t prevframenum; @@ -375,8 +396,8 @@ private: /** Number of jobs per thread for data compression */ int numJobsPerThread; - /** user defined number of jobs per thread for data compression */ - int userDefinedNumJobsPerThread; + /** acquisition period */ + int64_t acquisitionPeriod; /** callback arguments are diff --git a/slsDetectorSoftware/slsReceiver/slsReceiver_funcs.cpp b/slsDetectorSoftware/slsReceiver/slsReceiver_funcs.cpp index d34038a13..67607b7b8 100644 --- a/slsDetectorSoftware/slsReceiver/slsReceiver_funcs.cpp +++ b/slsDetectorSoftware/slsReceiver/slsReceiver_funcs.cpp @@ -41,7 +41,7 @@ slsReceiverFuncs::slsReceiverFuncs(int argc, char *argv[], int &success): string sLine,sargname; int iline = 0; bool dcompr = false; - int jobthread = -1; + /*int jobthread = -1;*/ success=OK; @@ -67,7 +67,7 @@ slsReceiverFuncs::slsReceiverFuncs(int argc, char *argv[], int &success): getline(infile,sLine); iline++; #ifdef VERBOSE - cout << str << endl; + cout << sLine << endl; #endif if(sLine.find('#')!=string::npos){ #ifdef VERBOSE @@ -184,7 +184,7 @@ slsReceiverFuncs::slsReceiverFuncs(int argc, char *argv[], int &success): } } } - //jobstothread + /*//jobstothread else if(!strcasecmp(argv[iarg],"-jobthread")){ if(iarg+1==argc){ cout << "no value given after -jobthread in command line. Exiting." << endl; @@ -197,7 +197,7 @@ slsReceiverFuncs::slsReceiverFuncs(int argc, char *argv[], int &success): success=FAIL; } } - } + }*/ else{ cout << "Unknown argument:" << argv[iarg] << endl; success=FAIL; @@ -227,8 +227,8 @@ slsReceiverFuncs::slsReceiverFuncs(int argc, char *argv[], int &success): cout << "Help Commands " << endl; cout << "type:\t\t Type of receiver. Default: Gotthard. Options: Moench" << endl; cout << "rx_tcpport:\t TCP Communication Port with the client. Default:1954. " << endl; - cout << "compression:\t Data Compression. Saving only hits. Option:yes, no" << endl; - cout << "jobthread:\t Number of jobs given to a thread for compression." << endl << endl; + cout << "compression:\t Data Compression. Saving only hits. Option:yes, no" << endl << endl;; + /*cout << "jobthread:\t Number of jobs given to a thread for compression." << endl << endl;*/ } @@ -250,7 +250,7 @@ slsReceiverFuncs::slsReceiverFuncs(int argc, char *argv[], int &success): slsReceiverList = new slsReceiverFunctionList(myDetectorType); if(dcompr) slsReceiverList->enableDataCompression(dcompr); - if(jobthread!=-1) slsReceiverList->setNumberOfJobsPerThread(jobthread); + /*if(jobthread!=-1) slsReceiverList->setNumberOfJobsPerThread(jobthread);*/ #ifdef VERBOSE cout << "Function table assigned." << endl; @@ -318,6 +318,8 @@ int slsReceiverFuncs::function_table(){ flist[F_GET_ID] = &slsReceiverFuncs::get_version; flist[F_CONFIGURE_MAC] = &slsReceiverFuncs::set_short_frame; flist[F_START_READOUT] = &slsReceiverFuncs::start_readout; + flist[F_SET_TIMER] = &slsReceiverFuncs::set_acquisition_period; + //General Functions flist[F_LOCK_SERVER] = &slsReceiverFuncs::lock_receiver; @@ -1427,6 +1429,55 @@ int slsReceiverFuncs::start_readout(){ +int slsReceiverFuncs::set_acquisition_period() { + ret=OK; + int64_t retval = -1; + int64_t index = -1; + strcpy(mess,"Could not set acquisition period in receiver\n"); + + + // receive arguments + if(socket->ReceiveDataOnly(&index,sizeof(index)) < 0 ){ + strcpy(mess,"Error reading from socket\n"); + ret = FAIL; + } + + // execute action if the arguments correctly arrived +#ifdef SLS_RECEIVER_FUNCTION_LIST + if (ret==OK) { + if (lockStatus==1 && socket->differentClients==1){//necessary??? + sprintf(mess,"Receiver locked by %s\n", socket->lastClientIP); + ret=FAIL; + } + else + retval=slsReceiverList->setAcquisitionPeriod(index); + } +#ifdef VERBOSE + if(ret!=FAIL) + cout << "acquisition period:" << retval << endl; + else + cout << mess << endl; +#endif +#endif + + if(ret==OK && socket->differentClients){ + cout << "Force update" << endl; + ret=FORCE_UPDATE; + } + + // send answer + socket->SendDataOnly(&ret,sizeof(ret)); + if(ret==FAIL) + socket->SendDataOnly(mess,sizeof(mess)); + socket->SendDataOnly(&retval,sizeof(retval)); + + //return ok/fail + return ret; +} + + + + diff --git a/slsDetectorSoftware/slsReceiver/slsReceiver_funcs.h b/slsDetectorSoftware/slsReceiver/slsReceiver_funcs.h index 221dd854e..6652a5c63 100644 --- a/slsDetectorSoftware/slsReceiver/slsReceiver_funcs.h +++ b/slsDetectorSoftware/slsReceiver/slsReceiver_funcs.h @@ -147,6 +147,9 @@ public: * when fifo is empty later, sets status to run_finished */ int start_readout(); + /** set acquisition period to find the value of n */ + int set_acquisition_period(); + //General Functions /** Locks Receiver */ diff --git a/slsDetectorSoftware/slsReceiverInterface/receiverInterface.cpp b/slsDetectorSoftware/slsReceiverInterface/receiverInterface.cpp index 47df5045f..1cbfe9191 100644 --- a/slsDetectorSoftware/slsReceiverInterface/receiverInterface.cpp +++ b/slsDetectorSoftware/slsReceiverInterface/receiverInterface.cpp @@ -92,6 +92,25 @@ int receiverInterface::getInt(int fnum, int &retval){ +int receiverInterface::sendInt(int fnum, int64_t &retval, int64_t arg){ + int ret = slsDetectorDefs::FAIL; + char mess[100] = ""; + + dataSocket->SendDataOnly(&fnum,sizeof(fnum)); + dataSocket->SendDataOnly(&arg,sizeof(arg)); + dataSocket->ReceiveDataOnly(&ret,sizeof(ret)); + if (ret==slsDetectorDefs::FAIL){ + dataSocket->ReceiveDataOnly(mess,sizeof(mess)); + std::cout<< "Receiver returned error: " << mess << std::endl; + } + dataSocket->ReceiveDataOnly(&retval,sizeof(retval)); + dataSocket->Disconnect(); + + return ret; +} + + + int receiverInterface::getInt(int fnum, int64_t &retval){ int ret = slsDetectorDefs::FAIL; diff --git a/slsDetectorSoftware/slsReceiverInterface/receiverInterface.h b/slsDetectorSoftware/slsReceiverInterface/receiverInterface.h index 8f848ef73..52f7738e0 100644 --- a/slsDetectorSoftware/slsReceiverInterface/receiverInterface.h +++ b/slsDetectorSoftware/slsReceiverInterface/receiverInterface.h @@ -77,6 +77,15 @@ public: */ int getInt(int fnum, int &retval); + /** + * Send an integer to receiver + * @param fnum function enum to determine what parameter + * @param retval return value + * @param arg value to send + * \returns success of operation + */ + int sendInt(int fnum, int64_t &retval, int64_t arg); + /** * Get an integer value from receiver * @param fnum function enum to determine what parameter