From 778cd973171f09775bdbac56f8efb17ed002bd22 Mon Sep 17 00:00:00 2001 From: l_maliakal_d Date: Thu, 11 Apr 2013 12:00:44 +0000 Subject: [PATCH] started the basics for sending every nth frame from receiver to gui.incomplete and will be implemented later git-svn-id: file:///afs/psi.ch/project/sls_det_software/svn/slsDetectorSoftware@506 951219d9-93cf-4727-9268-0efd64621fa3 --- .../commonFiles/sls_detector_funcs.h | 4 +- .../multiSlsDetector/multiSlsDetector.cpp | 17 ++++++ .../multiSlsDetector/multiSlsDetector.h | 6 ++ .../slsDetector/slsDetector.cpp | 22 ++++++++ slsDetectorSoftware/slsDetector/slsDetector.h | 7 +++ .../slsDetector/slsDetectorCommand.cpp | 18 +++++- .../slsDetector/slsDetectorUtils.h | 8 +++ .../slsDetectorAnalysis/postProcessing.cpp | 12 ++-- .../slsReceiver/slsReceiverFunctionList.cpp | 10 +++- .../slsReceiver/slsReceiverFunctionList.h | 24 +++++--- .../slsReceiver/slsReceiver_funcs.cpp | 56 ++++++++++++++++++- .../slsReceiver/slsReceiver_funcs.h | 6 ++ 12 files changed, 174 insertions(+), 16 deletions(-) diff --git a/slsDetectorSoftware/commonFiles/sls_detector_funcs.h b/slsDetectorSoftware/commonFiles/sls_detector_funcs.h index e03669351..0b494bb96 100644 --- a/slsDetectorSoftware/commonFiles/sls_detector_funcs.h +++ b/slsDetectorSoftware/commonFiles/sls_detector_funcs.h @@ -132,7 +132,9 @@ enum { F_SET_FRAME_INDEX, /**< sets the receiver frame index */ - F_CALIBRATE_PEDESTAL /**< starts acquistion, calibrates pedestal and write back to fpga */ + F_CALIBRATE_PEDESTAL, /**< starts acquistion, calibrates pedestal and write back to fpga */ + + F_READ_RECEIVER_FREQUENCY /**< sets the frequency of receiver sending frames to gui */ /* Always append functions hereafter!!! */ }; diff --git a/slsDetectorSoftware/multiSlsDetector/multiSlsDetector.cpp b/slsDetectorSoftware/multiSlsDetector/multiSlsDetector.cpp index c9765f4f1..b26885f19 100644 --- a/slsDetectorSoftware/multiSlsDetector/multiSlsDetector.cpp +++ b/slsDetectorSoftware/multiSlsDetector/multiSlsDetector.cpp @@ -4610,3 +4610,20 @@ int multiSlsDetector::calibratePedestal(int frames){ return ret; } +int multiSlsDetector::setReadReceiverFrequency(int i){ + int ret=-100, ret1; + + for (int idet=0; idetnumberOfDetectors; idet++) { + if (detectors[idet]) { + ret1=detectors[idet]->setReadReceiverFrequency(i); + if(detectors[idet]->getErrorMask()) + setErrorMask(getErrorMask()|(1<ReceiveDataOnly(mess,sizeof(mess)); std::cout<< "Detector returned: " << mess << " " << n << std::endl; delete [] retval; + dataSocket->Disconnect(); return NULL; } else { n=dataSocket->ReceiveDataOnly(fName,MAX_STR_LENGTH); @@ -6027,6 +6028,7 @@ int* slsDetector::readFrameFromReceiver(char* fName, int &fIndex){ std::cout<dataBytes << std::endl; ret=FAIL; delete [] retval; + dataSocket->Disconnect(); return NULL; } } @@ -6264,3 +6266,23 @@ int64_t slsDetector::clearAllErrorMask(){ } + +int slsDetector::setReadReceiverFrequency(int i){ + int fnum=F_READ_RECEIVER_FREQUENCY; + int ret = FAIL; + int retval=-1; + int arg = i; + + if(setReceiverOnline(ONLINE_FLAG)==ONLINE_FLAG){ +#ifdef VERBOSE + std::cout << "Sending read frequency to receiver " << arg << std::endl; +#endif + if (connectData() == OK) + ret=thisReceiver->sendInt(fnum,retval,arg); + if(ret==FAIL) + retval = -1; + if(ret==FORCE_UPDATE) + updateReceiver(); + } + return retval; +} diff --git a/slsDetectorSoftware/slsDetector/slsDetector.h b/slsDetectorSoftware/slsDetector/slsDetector.h index 30e8189ca..d4a8886c2 100644 --- a/slsDetectorSoftware/slsDetector/slsDetector.h +++ b/slsDetectorSoftware/slsDetector/slsDetector.h @@ -1581,6 +1581,13 @@ class slsDetector : public slsDetectorUtils, public energyConversion { /** sets the receiver udp port \sa sharedSlsDetector */ int setReceiverUDPPort(int udpport); + /** Sets the variable readRxrFrequency. + if Receiver read upon gui request, readRxrFrequency=0, + else every nth frame to be sent to gui + /returns read receiver frequency + */ + int setReadReceiverFrequency(int i=-1); + protected: diff --git a/slsDetectorSoftware/slsDetector/slsDetectorCommand.cpp b/slsDetectorSoftware/slsDetector/slsDetectorCommand.cpp index d0dcd0870..57615755b 100644 --- a/slsDetectorSoftware/slsDetector/slsDetectorCommand.cpp +++ b/slsDetectorSoftware/slsDetector/slsDetectorCommand.cpp @@ -707,6 +707,9 @@ slsDetectorCommand::slsDetectorCommand(slsDetectorUtils *det) { descrToFuncMap[i].m_pFuncPtr=&slsDetectorCommand::cmdLastClient; i++; + descrToFuncMap[i].m_pFuncName="r_readfreq"; // + descrToFuncMap[i].m_pFuncPtr=&slsDetectorCommand::cmdReceiver; + i++; numberOfCommands=i; @@ -3634,6 +3637,7 @@ string slsDetectorCommand::helpConfiguration(int narg, char *args[], int action) string slsDetectorCommand::cmdReceiver(int narg, char *args[], int action) { char answer[100]; + int ival = -1; if (action==HELP_ACTION) return helpReceiver(narg, args, action); @@ -3670,10 +3674,20 @@ string slsDetectorCommand::cmdReceiver(int narg, char *args[], int action) { sprintf(answer,"%d",myDet->getReceiverCurrentFrameIndex()); return string(answer); } + } + else if(cmd=="r_readfreq"){ + if (action==PUT_ACTION){ + if (!sscanf(args[1],"%d",&ival)) + return string("Could not scan read frequency mode ")+string(args[1]); + if(ival>=0) + myDet->setReadReceiverFrequency(ival); + } + sprintf(answer,"%d",myDet->setReadReceiverFrequency()); + return string(answer); + } - else return string("could not decode command"); } @@ -3685,10 +3699,12 @@ string slsDetectorCommand::helpReceiver(int narg, char *args[], int action) { ostringstream os; if (action==PUT_ACTION || action==HELP_ACTION) os << "receiver [status] \t starts/stops the receiver to listen to detector packets. - can be start or stop" << std::endl; + os << "r_readfreq \t sets the gui read frequency of the receiver, 0 if gui requests frame, >0 if receiver sends every nth frame to gui" << std::endl; if (action==GET_ACTION || action==HELP_ACTION){ os << "receiver \t returns the status of receiver - can be running or idle" << std::endl; os << "framescaught \t returns the number of frames caught by receiver(average for multi)" << std::endl; os << "frameindex \t returns the current frame index of receiver(average for multi)" << std::endl; + os << "r_readfreq \t returns the gui read frequency of the receiver" << std::endl; } return os.str(); diff --git a/slsDetectorSoftware/slsDetector/slsDetectorUtils.h b/slsDetectorSoftware/slsDetector/slsDetectorUtils.h index 341ef3bba..d6819b264 100644 --- a/slsDetectorSoftware/slsDetector/slsDetectorUtils.h +++ b/slsDetectorSoftware/slsDetector/slsDetectorUtils.h @@ -672,6 +672,14 @@ virtual int setROI(int n=-1,ROI roiLimits[]=NULL)=0; */ virtual ROI* getROI(int &n)=0; +/** Sets the variable readRxrFrequency. + if Receiver read upon gui request, readRxrFrequency=0, + else every nth frame to be sent to gui + /returns read receiver frequency + */ +virtual int setReadReceiverFrequency(int i=-1)=0; + + protected: diff --git a/slsDetectorSoftware/slsDetectorAnalysis/postProcessing.cpp b/slsDetectorSoftware/slsDetectorAnalysis/postProcessing.cpp index 5f6ca626c..1d9f36c38 100644 --- a/slsDetectorSoftware/slsDetectorAnalysis/postProcessing.cpp +++ b/slsDetectorSoftware/slsDetectorAnalysis/postProcessing.cpp @@ -398,11 +398,14 @@ void* postProcessing::processData(int delflag) { if (checkJoinThread()) break; usleep(200000); } - */ + */ + /*if(setReadReceiverFrequency()>0)) ******Not implemented yet ******** + * else + */ - pthread_mutex_lock(&mg); + pthread_mutex_lock(&mg); int prevCaught=getReceiverCurrentFrameIndex(); - pthread_mutex_unlock(&mg); + pthread_mutex_unlock(&mg); int caught=0; bool newData=false; @@ -446,10 +449,11 @@ void* postProcessing::processData(int delflag) { } } else{ - cout<<"****Detector returned mismatched indeices***"<=2) @@ -501,6 +508,7 @@ int slsReceiverFunctionList::startWriting(){ guiDataReady=0; + framesInFile++; // delete [] dataWriteFrame->buffer; fifofree->push(wbuf); diff --git a/slsDetectorSoftware/slsReceiver/slsReceiverFunctionList.h b/slsDetectorSoftware/slsReceiver/slsReceiverFunctionList.h index 039e9040d..cc6cae02f 100644 --- a/slsDetectorSoftware/slsReceiver/slsReceiverFunctionList.h +++ b/slsDetectorSoftware/slsReceiver/slsReceiverFunctionList.h @@ -13,10 +13,12 @@ #include "genericSocket.h" #include "circularFifo.h" + #include #include #include + /** * @short does all the functions for a receiver, set/get parameters, start/stop etc. */ @@ -185,6 +187,12 @@ public: */ int setShortFrame(int i); + /** + * Set the variable to send every nth frame to gui + * or if 0,send frame only upon gui request + */ + int setNFrameToGui(int i){if(i>=0) nFrameToGui = i; return nFrameToGui;}; + /** * Register call back function to write receiver data */ @@ -298,6 +306,11 @@ private: /** current frame number */ int currframenum; + /** send every nth frame to gui or only upon gui request*/ + int nFrameToGui; + + + /** register for call back to get data */ int (*writeReceiverData)(char*,int,FILE*,void*); void *pwriteReceiverDataArg; @@ -343,6 +356,9 @@ private: * 2 we open, close, write file, callback does not do anything */ int cbAction; + + + public: /** File Descriptor */ static FILE *sfilefd; @@ -350,6 +366,7 @@ public: /** if the listening thread is running*/ static int listening_thread_running; + /** callback arguments are filepath @@ -365,7 +382,6 @@ public: */ void registerCallBackStartAcquisition(int (*func)(char*, char*,int, int, void*),void *arg){startAcquisitionCallBack=func; pStartAcquisition=arg;}; - /** callback argument is toatal frames caught @@ -373,8 +389,6 @@ public: */ void registerCallBackAcquisitionFinished(void (*func)(int, void*),void *arg){acquisitionFinishedCallBack=func; pAcquisitionFinished=arg;}; - - /** args to raw data ready callback are framenum @@ -383,10 +397,6 @@ public: guidatapointer (NULL, no data required) */ void registerCallBackRawDataReady(void (*func)(int, char*, FILE*, char*, void*),void *arg){rawDataReadyCallBack=func; pRawDataReady=arg;}; - - - - }; diff --git a/slsDetectorSoftware/slsReceiver/slsReceiver_funcs.cpp b/slsDetectorSoftware/slsReceiver/slsReceiver_funcs.cpp index da0a6f7af..dd12b8072 100644 --- a/slsDetectorSoftware/slsReceiver/slsReceiver_funcs.cpp +++ b/slsDetectorSoftware/slsReceiver/slsReceiver_funcs.cpp @@ -181,6 +181,8 @@ int slsReceiverFuncs::function_table(){ flist[F_GET_FRAME_INDEX] = &slsReceiverFuncs::get_frame_index; flist[F_RESET_FRAMES_CAUGHT] = &slsReceiverFuncs::reset_frames_caught; flist[F_READ_FRAME] = &slsReceiverFuncs::read_frame; + flist[F_READ_ALL] = &slsReceiverFuncs::read_all; + flist[F_READ_RECEIVER_FREQUENCY]= &slsReceiverFuncs::set_read_frequency; flist[F_ENABLE_FILE_WRITE] = &slsReceiverFuncs::enable_file_write; flist[F_GET_ID] = &slsReceiverFuncs::get_version; flist[F_CONFIGURE_MAC] = &slsReceiverFuncs::set_short_frame; @@ -860,8 +862,8 @@ int slsReceiverFuncs::read_frame(){ count++; } - if ((count==20) || (count == -1)){ - if (count == -20) + if ((count==10) || (count == -1)){ + if (count == -10) cout << "same type: index:" << index << "\tindex2:" << index2 << endl; else cout << "no data to read for gui" << endl; @@ -914,6 +916,56 @@ int slsReceiverFuncs::read_frame(){ +int slsReceiverFuncs::set_read_frequency(){ + ret=OK; + int retval=-1; + int index; + strcpy(mess,"Could not set receiver read frequency\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->setNFrameToGui(index); + } + +#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; +} + + + + +/**needs to be implemented */ +int slsReceiverFuncs::read_all(){ + return ret; +} + + diff --git a/slsDetectorSoftware/slsReceiver/slsReceiver_funcs.h b/slsDetectorSoftware/slsReceiver/slsReceiver_funcs.h index 7dd6a6193..78fec20a0 100644 --- a/slsDetectorSoftware/slsReceiver/slsReceiver_funcs.h +++ b/slsDetectorSoftware/slsReceiver/slsReceiver_funcs.h @@ -124,6 +124,12 @@ public: /** Reads Frame/ buffer */ int read_frame(); + /** Sets the receiver to send every nth frame to gui, or only upon gui request */ + int set_read_frequency(); + + /** Reads every nth frame, sends them to gui without closing socket */ + int read_all(); + /** Enable File Write*/ int enable_file_write();