From 8538604c0f3aaf8c86940e04232cc00754424037 Mon Sep 17 00:00:00 2001 From: Dhanya Maliakal Date: Thu, 23 Nov 2017 14:53:37 +0100 Subject: [PATCH 1/3] somewhere --- .../multiSlsDetector/multiSlsDetector.cpp | 34 +++++++++++++------ 1 file changed, 23 insertions(+), 11 deletions(-) diff --git a/slsDetectorSoftware/multiSlsDetector/multiSlsDetector.cpp b/slsDetectorSoftware/multiSlsDetector/multiSlsDetector.cpp index 0fe6a90fa..47fe81eca 100644 --- a/slsDetectorSoftware/multiSlsDetector/multiSlsDetector.cpp +++ b/slsDetectorSoftware/multiSlsDetector/multiSlsDetector.cpp @@ -3694,14 +3694,12 @@ string multiSlsDetector::setNetworkParameter(networkParameter p, string s){ // disable data streaming before changing zmq port (but only if they were on) int prev_streaming = 0; switch (p) { - case RECEIVER_STREAMING_PORT: - prev_streaming = enableDataStreamingFromReceiver(); - enableDataStreamingFromReceiver(0); - enableDataStreamingToClient(0); - break; case CLIENT_STREAMING_PORT: prev_streaming = enableDataStreamingToClient(); enableDataStreamingToClient(0); + break; + case RECEIVER_STREAMING_PORT: + prev_streaming = enableDataStreamingFromReceiver(); enableDataStreamingFromReceiver(0); break; default: break; @@ -3763,12 +3761,10 @@ string multiSlsDetector::setNetworkParameter(networkParameter p, string s){ //enable data streaming if it was on if (prev_streaming) { switch (p) { - case RECEIVER_STREAMING_PORT: - enableDataStreamingFromReceiver(1); - enableDataStreamingToClient(1); - break; case CLIENT_STREAMING_PORT: enableDataStreamingToClient(1); + break; + case RECEIVER_STREAMING_PORT: enableDataStreamingFromReceiver(1); break; default: break; @@ -5812,6 +5808,8 @@ void multiSlsDetector::readFrameFromReceiver(){ int nch; bool runningList[numSockets]; + bool connectList[numSockets]; + int numRunning = 0; //wait for real time acquisition to start @@ -5820,8 +5818,17 @@ void multiSlsDetector::readFrameFromReceiver(){ if(checkJoinThread()) running = false; - for(int i = 0; i < numSockets; ++i) - runningList[i] = true; + for(int i = 0; i < numSockets; ++i) { + if(!zmqSocket[i]->Connect()) { + connectList[i] = true; + runningList[i] = true; + } else { + connectList[i] = false; + cprintf(RED,"Error: Could not connect to socket %s\n",zmqSocket[i]->GetZmqServerAddress()); + runningList[i] = false; + } + } + numRunning = numSockets; @@ -5904,6 +5911,11 @@ void multiSlsDetector::readFrameFromReceiver(){ running = true; } + // Disconnect resources + for (int i = 0; i < numSockets; ++i) + if (connectList[i]) + zmqSocket[i]->Disconnect(); + //free resources delete [] image; delete[] multiframe; From 386ef7766cc3064c985b021507000544275860b4 Mon Sep 17 00:00:00 2001 From: Dhanya Maliakal Date: Mon, 27 Nov 2017 16:01:12 +0100 Subject: [PATCH 2/3] zmq streaming should work with external gui now --- slsDetectorSoftware/gitInfo.txt | 10 ++--- .../multiSlsDetector/multiSlsDetector.cpp | 42 ++++--------------- .../multiSlsDetector/multiSlsDetector.h | 13 +++++- slsDetectorSoftware/slsDetector/gitInfoLib.h | 8 ++-- .../slsDetector/slsDetector.cpp | 8 ++-- slsDetectorSoftware/slsDetector/slsDetector.h | 15 ++++++- .../slsDetector/slsDetectorBase.h | 8 +++- .../slsDetector/slsDetectorCommand.cpp | 42 +++++++++---------- .../slsDetector/slsDetectorUtils.h | 12 +++++- .../slsDetectorAnalysis/postProcessing.cpp | 6 +-- .../slsDetectorAnalysis/postProcessing.h | 2 +- 11 files changed, 83 insertions(+), 83 deletions(-) diff --git a/slsDetectorSoftware/gitInfo.txt b/slsDetectorSoftware/gitInfo.txt index 3321a278b..0040aef5b 100644 --- a/slsDetectorSoftware/gitInfo.txt +++ b/slsDetectorSoftware/gitInfo.txt @@ -1,9 +1,9 @@ Path: slsDetectorsPackage/slsDetectorSoftware URL: origin git@git.psi.ch:sls_detectors_software/sls_detector_software.git Repository Root: origin git@git.psi.ch:sls_detectors_software/sls_detector_software.git -Repsitory UUID: 1fd03e9cdd01efd75e3ab8641be71d61b2e1aa10 -Revision: 1566 -Branch: 3.0.1 +Repsitory UUID: ea284699983c3811852b1bcea3708d952803020d +Revision: 1611 +Branch: zmqchange Last Changed Author: Dhanya_Maliakal -Last Changed Rev: 1571 -Last Changed Date: 2017-10-03 14:12:22.000000002 +0200 ./slsDetector/slsDetector.cpp +Last Changed Rev: 1619 +Last Changed Date: 2017-11-27 14:45:39.000000002 +0100 ./slsDetector/slsDetectorBase.h diff --git a/slsDetectorSoftware/multiSlsDetector/multiSlsDetector.cpp b/slsDetectorSoftware/multiSlsDetector/multiSlsDetector.cpp index f064ee538..d9bd9325a 100644 --- a/slsDetectorSoftware/multiSlsDetector/multiSlsDetector.cpp +++ b/slsDetectorSoftware/multiSlsDetector/multiSlsDetector.cpp @@ -208,7 +208,7 @@ multiSlsDetector::multiSlsDetector(int id) : slsDetectorUtils(), shmId(-1) thisMultiDetector->acquiringFlag = false; thisMultiDetector->externalgui = false; - thisMultiDetector->receiver_datastream = false; + thisMultiDetector->receiver_upstream = false; thisMultiDetector->alreadyExisting=1; } @@ -274,7 +274,7 @@ multiSlsDetector::multiSlsDetector(int id) : slsDetectorUtils(), shmId(-1) getNMods(); getMaxMods(); - client_datastream = false; + client_downstream = false; for(int i=0;iGetZmqServerAddress()); } - client_datastream = true; + client_downstream = true; cout << "Receiving Data Socket(s) created" << endl; return OK; } @@ -6192,7 +6164,7 @@ int multiSlsDetector::enableDataStreamingToClient(int enable) { } } } - return client_datastream; + return client_downstream; } int multiSlsDetector::enableDataStreamingFromReceiver(int enable){ @@ -6228,10 +6200,10 @@ int multiSlsDetector::enableDataStreamingFromReceiver(int enable){ } } } - thisMultiDetector->receiver_datastream = ret; + thisMultiDetector->receiver_upstream = ret; } - return thisMultiDetector->receiver_datastream; + return thisMultiDetector->receiver_upstream; } int multiSlsDetector::enableReceiverCompression(int i){ diff --git a/slsDetectorSoftware/multiSlsDetector/multiSlsDetector.h b/slsDetectorSoftware/multiSlsDetector/multiSlsDetector.h index 1ef7c625d..ff37f29ae 100644 --- a/slsDetectorSoftware/multiSlsDetector/multiSlsDetector.h +++ b/slsDetectorSoftware/multiSlsDetector/multiSlsDetector.h @@ -205,7 +205,7 @@ class multiSlsDetector : public slsDetectorUtils { int receiverOnlineFlag; /** data streaming (up stream) enable in receiver */ - bool receiver_datastream; + bool receiver_upstream; } sharedMultiSlsDetector; @@ -998,6 +998,15 @@ class multiSlsDetector : public slsDetectorUtils { string getNetworkParameter(networkParameter); + + /** + sets the network parameters + must restart streaming in client/receiver if to do with zmq after calling this function + \param i network parameter type + \param s value to be set + \returns parameter + + */ string setNetworkParameter(networkParameter, std::string); int setPort(portType, int); int lockServer(int); @@ -1490,7 +1499,7 @@ private: /** data streaming (down stream) enabled in client (zmq sckets created) */ - bool client_datastream; + bool client_downstream; /** ZMQ Socket - Receiver to Client */ ZmqSocket* zmqSocket[MAXDET]; diff --git a/slsDetectorSoftware/slsDetector/gitInfoLib.h b/slsDetectorSoftware/slsDetector/gitInfoLib.h index e2528c4b3..634e08943 100644 --- a/slsDetectorSoftware/slsDetector/gitInfoLib.h +++ b/slsDetectorSoftware/slsDetector/gitInfoLib.h @@ -1,11 +1,11 @@ //#define SVNPATH "" #define SVNURLLIB "git@git.psi.ch:sls_detectors_software/sls_detector_software.git" //#define SVNREPPATH "" -#define SVNREPUUIDLIB "1fd03e9cdd01efd75e3ab8641be71d61b2e1aa10" -//#define SVNREV 0x1571 +#define SVNREPUUIDLIB "ea284699983c3811852b1bcea3708d952803020d" +//#define SVNREV 0x1619 //#define SVNKIND "" //#define SVNSCHED "" #define SVNAUTHLIB "Dhanya_Maliakal" -#define SVNREVLIB 0x1571 -#define SVNDATELIB 0x20171003 +#define SVNREVLIB 0x1619 +#define SVNDATELIB 0x20171127 // diff --git a/slsDetectorSoftware/slsDetector/slsDetector.cpp b/slsDetectorSoftware/slsDetector/slsDetector.cpp index 705c687ee..88e8a1443 100644 --- a/slsDetectorSoftware/slsDetector/slsDetector.cpp +++ b/slsDetectorSoftware/slsDetector/slsDetector.cpp @@ -779,7 +779,7 @@ int slsDetector::initializeDetectorSize(detectorType type) { thisDetector->flippedData[1] = 0; thisDetector->zmqport = 0; thisDetector->receiver_zmqport = 0; - thisDetector->receiver_datastream = false; + thisDetector->receiver_upstream = false; thisDetector->receiver_read_freq = 0; for (int ia=0; iaReceiveDataOnly(&ind,sizeof(ind)); - thisDetector->receiver_datastream = ind; + thisDetector->receiver_upstream = ind; if (!n) printf("n: %d\n", n); @@ -8599,14 +8599,14 @@ int slsDetector::enableDataStreamingFromReceiver(int enable){ cout << "could not set data streaming in receiver to " << enable <<" Returned:" << retval << endl; setErrorMask((getErrorMask())|(DATA_STREAMING)); } else { - thisDetector->receiver_datastream = retval; + thisDetector->receiver_upstream = retval; if(ret==FORCE_UPDATE) updateReceiver(); } } } - return thisDetector->receiver_datastream; + return thisDetector->receiver_upstream; } diff --git a/slsDetectorSoftware/slsDetector/slsDetector.h b/slsDetectorSoftware/slsDetector/slsDetector.h index ebeb6624e..5464bdfa7 100644 --- a/slsDetectorSoftware/slsDetector/slsDetector.h +++ b/slsDetectorSoftware/slsDetector/slsDetector.h @@ -274,7 +274,7 @@ class slsDetector : public slsDetectorUtils, public energyConversion { /** tcp port from receiver to gui/different process (only data) */ int receiver_zmqport; /** data streaming (up stream) enable in receiver */ - bool receiver_datastream; + bool receiver_upstream; /* Receiver read frequency */ int receiver_read_freq; @@ -446,7 +446,8 @@ class slsDetector : public slsDetectorUtils, public energyConversion { /** sets the network parameters - \param i network parameter type can be RECEIVER_IP, RECEIVER_MAC, SERVER_MAC + must restart streaming in client/receiver if to do with zmq after calling this function + \param i network parameter type \param s value to be set \returns parameter @@ -1781,6 +1782,16 @@ class slsDetector : public slsDetectorUtils, public energyConversion { */ int setReceiverReadTimer(int time_in_ms=500); + /** + * Enable data streaming to client + * @param enable 0 to disable, 1 to enable, -1 to get the value + * @returns data streaming to client enable + */ + int enableDataStreamingToClient(int enable=-1) { + cprintf(RED,"ERROR: Must be called from the multi Detector level\n"); + return 0; + } + /** Enable or disable streaming data from receiver to client * @param enable 0 to disable 1 to enable -1 to only get the value * @returns data streaming from receiver enable diff --git a/slsDetectorSoftware/slsDetector/slsDetectorBase.h b/slsDetectorSoftware/slsDetector/slsDetectorBase.h index b31ccabeb..219353535 100644 --- a/slsDetectorSoftware/slsDetector/slsDetectorBase.h +++ b/slsDetectorSoftware/slsDetector/slsDetectorBase.h @@ -574,9 +574,15 @@ class slsDetectorBase : public virtual slsDetectorDefs, public virtual errorDef /** Reads frames from receiver through a constant socket */ - // virtual int* readFrameFromReceiver(char* fName, int &acquisitionIndex, int &frameIndex, int &subFrameIndex)=0; virtual void readFrameFromReceiver()=0; +/** + * Enable data streaming to client + * @param enable 0 to disable, 1 to enable, -1 to get the value + * @returns data streaming to client enable + */ +virtual int enableDataStreamingToClient(int enable=-1)=0; + /** Sets the read receiver frequency if data required from receiver randomly readRxrFrequency=0, else every nth frame to be sent to gui diff --git a/slsDetectorSoftware/slsDetector/slsDetectorCommand.cpp b/slsDetectorSoftware/slsDetector/slsDetectorCommand.cpp index f517f9119..e773dbd10 100644 --- a/slsDetectorSoftware/slsDetector/slsDetectorCommand.cpp +++ b/slsDetectorSoftware/slsDetector/slsDetectorCommand.cpp @@ -1887,14 +1887,14 @@ slsDetectorCommand::slsDetectorCommand(slsDetectorUtils *det) { ++i; /*! \page network - - zmqport [port] sets/gets the 0MQ (TCP) port of the client to where final data is streamed to (eg. for GUI). Use single-detector command to set individually or multi-detector command to calculate based on \c port for the rest. \c Returns \c (int) + - zmqport [port] sets/gets the 0MQ (TCP) port of the client to where final data is streamed to (eg. for GUI). Use single-detector command to set individually or multi-detector command to calculate based on \c port for the rest. Must restart zmq client streaming in gui/external gui \c Returns \c (int) */ descrToFuncMap[i].m_pFuncName="zmqport"; // descrToFuncMap[i].m_pFuncPtr=&slsDetectorCommand::cmdNetworkParameter; ++i; /*! \page network - - rx_zmqport [port] sets/gets the 0MQ (TCP) port of the receiver from where data is streamed from (eg. to GUI or another process for further processing). Use single-detector command to set individually or multi-detector command to calculate based on \c port for the rest. \c Returns \c (int) + - rx_zmqport [port] sets/gets the 0MQ (TCP) port of the receiver from where data is streamed from (eg. to GUI or another process for further processing). Use single-detector command to set individually or multi-detector command to calculate based on \c port for the rest. put restarts streaming in receiver with new port. \c Returns \c (int) */ descrToFuncMap[i].m_pFuncName="rx_zmqport"; // descrToFuncMap[i].m_pFuncPtr=&slsDetectorCommand::cmdNetworkParameter; @@ -2316,15 +2316,6 @@ string slsDetectorCommand::cmdAcquire(int narg, char *args[], int action) { myDet->setOnline(ONLINE_FLAG); int r_online = myDet->setReceiverOnline(ONLINE_FLAG); - // switch off data streaming to prevent extra images in zmq gui buffer - if (r_online == ONLINE_FLAG) { - if (myDet->enableDataStreamingFromReceiver() != 0) { - if (myDet->enableDataStreamingFromReceiver(0) != 0) { - std::cout << "Error: Unable to switch off data streaming in receiver. If GUI on, extra image(s) in zmq GUI buffer" << std::endl; - } - } - } - if(myDet->acquire() == FAIL) return string("acquire unsuccessful"); if(r_online){ @@ -3892,6 +3883,7 @@ string slsDetectorCommand::cmdNetworkParameter(int narg, char *args[], int actio networkParameter t; int i; + int prev_streaming = 0; if (action==HELP_ACTION) return helpNetworkParameter(narg,args,action); @@ -3955,11 +3947,19 @@ string slsDetectorCommand::cmdNetworkParameter(int narg, char *args[], int actio if (action==PUT_ACTION){ if (!(sscanf(args[1],"%d",&i))) return ("cannot parse argument") + string(args[1]); + // if streaming, switch it off + prev_streaming = myDet->enableDataStreamingFromReceiver(); + if (prev_streaming) myDet->enableDataStreamingFromReceiver(0); } }else return ("unknown network parameter")+cmd; - if (action==PUT_ACTION) + if (action==PUT_ACTION) { myDet->setNetworkParameter(t, args[1]); + // switch it back on, if it had been switched on + if (prev_streaming && t == RECEIVER_STREAMING_PORT) + myDet->enableDataStreamingFromReceiver(1); + + } return myDet->getNetworkParameter(t); } @@ -3981,8 +3981,12 @@ string slsDetectorCommand::helpNetworkParameter(int narg, char *args[], int acti os << "txndelay_right port \n sets detector transmission delay of the right port"<< std::endl; os << "txndelay_frame port \n sets detector transmission delay of the entire frame"<< std::endl; os << "flowcontrol_10g port \n sets flow control for 10g for eiger"<< std::endl; - os << "zmqport port \n sets zmq port (data to client from receiver/different process); setting via multidetector command calculates port for individual detectors"<< std::endl; - os << "rx_zmqport port \n sets zmq port (data from receiver to client/different process); setting via multidetector command calculates port for individual detectors"<< std::endl; + os << "zmqport port \n sets zmq port (data to client from receiver/different process); \n" + "setting via multidetector command calculates port for individual detectors\n" + "must restart streaming in client with new port from gui/external gui"<< std::endl; + os << "rx_zmqport port \n sets zmq port (data from receiver to client/different process); \n" + "setting via multidetector command calculates port for individual detectors\n" + "restarts streaming in receiver with new port"<< std::endl; } if (action==GET_ACTION || action==HELP_ACTION) { os << "detectormac \n gets detector mac "<< std::endl; @@ -5891,19 +5895,11 @@ string slsDetectorCommand::cmdReceiver(int narg, char *args[], int action) { myDet->setOnline(ONLINE_FLAG); - int r_online = myDet->setReceiverOnline(ONLINE_FLAG); + myDet->setReceiverOnline(ONLINE_FLAG); if(cmd=="receiver"){ if (action==PUT_ACTION) { if(!strcasecmp(args[1],"start")) { - // switch off data streaming to prevent extra images in zmq gui buffer - if (r_online == ONLINE_FLAG) { - if (myDet->enableDataStreamingFromReceiver() != 0) { - if (myDet->enableDataStreamingFromReceiver(0) != 0) { - std::cout << "Error: Unable to switch off data streaming in receiver. If GUI on, extra image(s) in zmq GUI buffer" << std::endl; - } - } - } myDet->startReceiver(); } else if(!strcasecmp(args[1],"stop")) diff --git a/slsDetectorSoftware/slsDetector/slsDetectorUtils.h b/slsDetectorSoftware/slsDetector/slsDetectorUtils.h index 8142197cc..abe88f241 100644 --- a/slsDetectorSoftware/slsDetector/slsDetectorUtils.h +++ b/slsDetectorSoftware/slsDetector/slsDetectorUtils.h @@ -200,8 +200,9 @@ class slsDetectorUtils : public slsDetectorActions, public postProcessing { virtual string getNetworkParameter(networkParameter i)=0; /** - sets the network parameters (implemented for gotthard) - \param i network parameter type can be RECEIVER_IP, RECEIVER_MAC, SERVER_MAC + sets the network parameters + must restart streaming in client/receiver if to do with zmq after calling this function + \param i network parameter type \param s value to be set \returns parameter @@ -773,6 +774,13 @@ virtual ROI* getROI(int &n)=0; */ virtual int setReadReceiverFrequency(int freq=-1)=0; +/** + * Enable data streaming to client + * @param enable 0 to disable, 1 to enable, -1 to get the value + * @returns data streaming to client enable + */ +virtual int enableDataStreamingToClient(int enable=-1)=0; + /** Enable or disable streaming data from receiver to client * @param enable 0 to disable 1 to enable -1 to only get the value * @returns data streaming from receiver enable diff --git a/slsDetectorSoftware/slsDetectorAnalysis/postProcessing.cpp b/slsDetectorSoftware/slsDetectorAnalysis/postProcessing.cpp index 4911a8991..1cc761757 100644 --- a/slsDetectorSoftware/slsDetectorAnalysis/postProcessing.cpp +++ b/slsDetectorSoftware/slsDetectorAnalysis/postProcessing.cpp @@ -509,11 +509,9 @@ void* postProcessing::processData(int delflag) { pthread_mutex_unlock(&mg); //cprintf(RED,"In post processing threads\n"); - - if(dataReady){ + if(dataReady) { readFrameFromReceiver(); - } - + } //only update progress else{ int caught = -1; diff --git a/slsDetectorSoftware/slsDetectorAnalysis/postProcessing.h b/slsDetectorSoftware/slsDetectorAnalysis/postProcessing.h index 02e305f4f..d68d253b2 100644 --- a/slsDetectorSoftware/slsDetectorAnalysis/postProcessing.h +++ b/slsDetectorSoftware/slsDetectorAnalysis/postProcessing.h @@ -238,7 +238,7 @@ s void ResetPositionIndex(){pthread_mutex_lock(&mp); resetPositionIndex(); pthread_mutex_unlock(&mp);}; - void registerDataCallback(int( *userCallback)(detectorData*, int, int, void*), void *pArg) {dataReady = userCallback; pCallbackArg = pArg;}; + void registerDataCallback(int( *userCallback)(detectorData*, int, int, void*), void *pArg) {dataReady = userCallback; pCallbackArg = pArg;enableDataStreamingToClient(1);}; void registerRawDataCallback(int( *userCallback)(double*, int, void*), void *pArg) {rawDataReady = userCallback; pRawDataArg = pArg;}; From c0a114345b8b987d595e2bbc3865f1a7e59dd2f7 Mon Sep 17 00:00:00 2001 From: Dhanya Maliakal Date: Mon, 27 Nov 2017 16:11:33 +0100 Subject: [PATCH 3/3] bug fix set error mask when setting wrong settings --- slsDetectorSoftware/slsDetector/slsDetector.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/slsDetectorSoftware/slsDetector/slsDetector.cpp b/slsDetectorSoftware/slsDetector/slsDetector.cpp index 88e8a1443..8e368142b 100644 --- a/slsDetectorSoftware/slsDetector/slsDetector.cpp +++ b/slsDetectorSoftware/slsDetector/slsDetector.cpp @@ -3556,6 +3556,8 @@ slsDetectorDefs::detectorSettings slsDetector::setSettings( detectorSettings ise break; default: printf("Unknown settings %s for this detector!\n", getDetectorSettings(isettings).c_str()); + setErrorMask((getErrorMask())|(SETTINGS_NOT_SET)); + break; } return thisDetector->currentSettings; } @@ -3681,7 +3683,8 @@ slsDetectorDefs::detectorSettings slsDetector::setSettings( detectorSettings ise if (isettings != thisDetector->currentSettings) { - std::cout<< "Unknown settings for this detector!" << std::endl; + printf("Unknown settings %s for this detector!\n", getDetectorSettings(isettings).c_str()); + setErrorMask((getErrorMask())|(SETTINGS_NOT_SET)); }else{ if (imod<0) { modmi=0;