From 2b0d07387abbad6b33432a6dd8474fae8cbef427 Mon Sep 17 00:00:00 2001 From: Dhanya Maliakal Date: Wed, 15 Nov 2017 17:16:47 +0100 Subject: [PATCH] in between separating datastreaming in client and receiver --- .../multiSlsDetector/multiSlsDetector.h | 19 ++++-- .../slsDetector/slsDetector.cpp | 25 ++------ slsDetectorSoftware/slsDetector/slsDetector.h | 7 +- .../slsDetector/slsDetectorCommand.cpp | 64 ++++--------------- .../slsDetector/slsDetectorUtils.h | 6 +- 5 files changed, 40 insertions(+), 81 deletions(-) diff --git a/slsDetectorSoftware/multiSlsDetector/multiSlsDetector.h b/slsDetectorSoftware/multiSlsDetector/multiSlsDetector.h index 2d0ff72a5..96d35eb28 100644 --- a/slsDetectorSoftware/multiSlsDetector/multiSlsDetector.h +++ b/slsDetectorSoftware/multiSlsDetector/multiSlsDetector.h @@ -207,6 +207,9 @@ class multiSlsDetector : public slsDetectorUtils { /** receiver online flag - is set if the receiver is connected, unset if socket connection is not possible */ int receiverOnlineFlag; + /** data streaming (up stream) enable in receiver */ + bool receiver_datastream; + } sharedMultiSlsDetector; @@ -1342,17 +1345,19 @@ class multiSlsDetector : public slsDetectorUtils { /** - * Get Streaming sockets created in client from reciever - /returns 1 if sockets created, else 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 */ - int getStreamingSocketsCreatedInClient(); + int enableDataStreamingToClient(int enable=-1); /** 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 + * @param enable 0 to disable 1 to enable -1 to only get the value + * @returns data streaming to receiver enable */ int enableDataStreamingFromReceiver(int enable=-1); + /** updates the multidetector offsets */ void updateOffsets(); @@ -1489,8 +1494,8 @@ private: int getData(const int isocket, const bool masking, int* image, const int size, uint64_t &acqIndex, uint64_t &frameIndex, uint32_t &subframeIndex, string &filename); - /** Ensures if sockets created successfully */ - bool dataSocketsStarted; + /** data streaming (down stream) enabled in client (zmq sckets created) */ + bool client_datastream; /** ZMQ Socket - Receiver to Client */ ZmqSocket* zmqSocket[MAXDET]; diff --git a/slsDetectorSoftware/slsDetector/slsDetector.cpp b/slsDetectorSoftware/slsDetector/slsDetector.cpp index ced0c34e5..a61be6d5e 100644 --- a/slsDetectorSoftware/slsDetector/slsDetector.cpp +++ b/slsDetectorSoftware/slsDetector/slsDetector.cpp @@ -777,7 +777,8 @@ int slsDetector::initializeDetectorSize(detectorType type) { thisDetector->acquiringFlag = false; thisDetector->flippedData[0] = 0; thisDetector->flippedData[1] = 0; - thisDetector->zmqport = 0; + thisDetector->zmqport = DEFAULT_ZMQ_CL_PORTNO + (posId * (thisDetector->myDetectorType == EIGER) ? 2 : 1); + thisDetector->receiver_zmqport = DEFAULT_ZMQ_RX_PORTNO + (posId * (thisDetector->myDetectorType == EIGER) ? 2 : 1); for (int ia=0; iaactionScript[ia],"none"); @@ -6067,7 +6068,7 @@ string slsDetector::setReceiver(string receiverIP){ std::cout << "dynamic range:" << thisDetector->dynamicRange << endl << endl; std::cout << "flippeddatax:" << thisDetector->flippedData[d] << endl; std::cout << "10GbE:" << thisDetector->tenGigaEnable << endl << endl; - std::cout << "streaming port:" << thisDetector->zmqport << endl; + std::cout << "rx streaming port:" << thisDetector->receiver_zmqport << endl; //std::cout << "dataStreaming:" << enableDataStreamingFromReceiver(-1) << endl << endl; /** enable compresison, */ @@ -6113,19 +6114,7 @@ string slsDetector::setReceiver(string receiverIP){ // data streaming setReceiverStreamingPort(getReceiverStreamingPort()); - int clientSockets = parentDet->getStreamingSocketsCreatedInClient(); - int recSockets = enableDataStreamingFromReceiver(-1); - if(clientSockets != recSockets) { - pthread_mutex_lock(&ms); - if(clientSockets) - printf("Enabling Data Streaming\n"); - else - printf("Disabling Data Streaming\n"); - // push client state to receiver - /*parentDet->enableDataStreamingFromReceiver(clientSockets);*/ - enableDataStreamingFromReceiver(clientSockets); - pthread_mutex_unlock(&ms); - } + enableDataStreamingFromReceiver(enableDataStreamingFromReceiver(-1)); } } @@ -6224,7 +6213,7 @@ int slsDetector::setReceiverUDPPort2(int udpport){ } -int slsDetector::setReceiverStreamingPort(string port) { +int slsDetector::setClientStreamingPort(string port) { int defaultport = 0; int numsockets = (thisDetector->myDetectorType == EIGER) ? 2:1; int arg = 0; @@ -8268,9 +8257,9 @@ int slsDetector::updateReceiverNoWait() { parentDet->enableOverwriteMask(ind); pthread_mutex_unlock(&ms); - // streaming port + // receiver streaming port n += dataSocket->ReceiveDataOnly(&ind,sizeof(ind)); - thisDetector->zmqport = ind; + thisDetector->receiver_zmqport = ind; if (!n) printf("n: %d\n", n); diff --git a/slsDetectorSoftware/slsDetector/slsDetector.h b/slsDetectorSoftware/slsDetector/slsDetector.h index 728041162..0ec9c4a99 100644 --- a/slsDetectorSoftware/slsDetector/slsDetector.h +++ b/slsDetectorSoftware/slsDetector/slsDetector.h @@ -273,7 +273,8 @@ class slsDetector : public slsDetectorUtils, public energyConversion { int zmqport; /** tcp port from receiver to gui/different process (only data) */ int receiver_zmqport; - + /** data streaming (up stream) enable in receiver */ + bool receiver_datastream; } sharedSlsDetector; @@ -1781,8 +1782,8 @@ class slsDetector : public slsDetectorUtils, public energyConversion { int setReceiverReadTimer(int time_in_ms=500); /** 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 + * @param enable 0 to disable 1 to enable -1 to only get the value + * @returns data streaming to receiver enable */ int enableDataStreamingFromReceiver(int enable=-1); diff --git a/slsDetectorSoftware/slsDetector/slsDetectorCommand.cpp b/slsDetectorSoftware/slsDetector/slsDetectorCommand.cpp index 1d91e41d8..a45a19363 100644 --- a/slsDetectorSoftware/slsDetector/slsDetectorCommand.cpp +++ b/slsDetectorSoftware/slsDetector/slsDetectorCommand.cpp @@ -255,13 +255,6 @@ slsDetectorCommand::slsDetectorCommand(slsDetectorUtils *det) { commands to configure detector data structure */ - /*! \page config - - externalgui sets/gets external gui flag. 1 sets and enables the 0MQ data stream (0MQ threads created) from receiver to client, while 0 unsets and disables. \c Returns \c (int) - */ - descrToFuncMap[i].m_pFuncName="externalgui"; // - descrToFuncMap[i].m_pFuncPtr=&slsDetectorCommand::cmdDataStream; - ++i; - /*! \page config - \b free Free shared memory on the control PC */ @@ -1907,6 +1900,13 @@ slsDetectorCommand::slsDetectorCommand(slsDetectorUtils *det) { descrToFuncMap[i].m_pFuncPtr=&slsDetectorCommand::cmdNetworkParameter; ++i; + /*! \page network + - rx_datastream enables/disables data streaming from receiver. 1 enables 0MQ data stream from receiver (creates streamer threads), while 0 disables (destroys streamer threads). \c Returns \c (int) + */ + descrToFuncMap[i].m_pFuncName="rx_datastream"; // + descrToFuncMap[i].m_pFuncPtr=&slsDetectorCommand::cmdDataStream; + ++i; + /*! \page network - configuremac [i] configures the MAC of the detector with these parameters: detectorip, detectormac, rx_udpip, rx_udpmac, rx_udpport, rx_udpport2 (if applicable). This command is already included in \c rx_hsotname. Only put!. \c Returns \c (int) */ @@ -2316,16 +2316,6 @@ string slsDetectorCommand::cmdAcquire(int narg, char *args[], int action) { myDet->setOnline(ONLINE_FLAG); int r_online = myDet->setReceiverOnline(ONLINE_FLAG); - if ((!myDet->getExternalGuiFlag()) && (r_online == ONLINE_FLAG)) { - // command line: must be off, if receiver on or there was -1, then - if (myDet->enableDataStreamingFromReceiver(-1) != 0){ - //switch it off, if error - if (myDet->enableDataStreamingFromReceiver(0) != 0) { - return string("could not disable data streaming in receiver\n"); - } - } - } - if(myDet->acquire() == FAIL) return string("acquire unsuccessful"); if(r_online){ @@ -2490,18 +2480,11 @@ string slsDetectorCommand::cmdDataStream(int narg, char *args[], int action) { if (action==PUT_ACTION) { if (!sscanf(args[1],"%d",&ival)) - return string ("cannot scan externalgui mode"); - myDet->setExternalGuiFlag(ival>0?true:false); + return string ("cannot scan rx_datastream mode"); myDet->enableDataStreamingFromReceiver(ival); } - int retval = myDet->getExternalGuiFlag(); - //if external gui on and datastreaming off - if (retval && !myDet->enableDataStreamingFromReceiver()) { - retval=-1; - printf("Error: data streaming in receiver is switched off while external gui flag in shared memory is off.\n"); - } - sprintf(ans,"%d",myDet->getExternalGuiFlag()); + sprintf(ans,"%d",myDet->enableDataStreamingFromReceiver()); return string(ans); } @@ -2510,9 +2493,9 @@ string slsDetectorCommand::helpDataStream(int narg, char *args[], int action) { ostringstream os; if (action==GET_ACTION || action==HELP_ACTION) - os << string("externalgui \t gets external gui flag. 1/0 means the 0MQ data stream (0MQ threads created) from receiver to client is enabled/disabled. -1 for inconsistency. \n"); + os << string("rx_datastream \t enables/disables data streaming from receiver. 1 is 0MQ data stream from receiver enabled, while 0 is 0MQ disabled. -1 for inconsistency between multiple receivers. \n"); if (action==PUT_ACTION || action==HELP_ACTION) - os << string("externalgui i\t sets external gui flag. 1/0 means the 0MQ data stream (0MQ threads created) from receiver to client is enabled/disabled. \n"); + os << string("rx_datastream i\t enables/disables data streaming from receiver. i is 1 enables 0MQ data stream from receiver (creates streamer threads), while 0 disables (destroys streamer threads). \n"); return os.str(); } @@ -5899,33 +5882,14 @@ string slsDetectorCommand::cmdReceiver(int narg, char *args[], int action) { myDet->setOnline(ONLINE_FLAG); - int receivers = myDet->setReceiverOnline(ONLINE_FLAG); + myDet->setReceiverOnline(ONLINE_FLAG); if(cmd=="receiver"){ if (action==PUT_ACTION) { - if(!strcasecmp(args[1],"start")) { - //to ensure data streaming enable is the same across client and receiver - if ((!myDet->getExternalGuiFlag()) && (receivers == ONLINE_FLAG)) { - //if it was not off - if (myDet->enableDataStreamingFromReceiver(-1) != 0){ - //switch it off, if error - if (myDet->enableDataStreamingFromReceiver(0) != 0) { - return string("could not disable data streaming in receiver\n"); - } - } - } + if(!strcasecmp(args[1],"start")) myDet->startReceiver(); - } - else if(!strcasecmp(args[1],"stop")){ - //myDet->stopReceiver(); - // myDet->startReceiverReadout(); - /*runStatus s = myDet->getReceiverStatus(); - while(s != RUN_FINISHED){ - usleep(50000); - s = myDet->getReceiverStatus(); - }*/ + else if(!strcasecmp(args[1],"stop")) myDet->stopReceiver(); - } else return helpReceiver(narg, args, action); } diff --git a/slsDetectorSoftware/slsDetector/slsDetectorUtils.h b/slsDetectorSoftware/slsDetector/slsDetectorUtils.h index d297cfe27..faa4b473d 100644 --- a/slsDetectorSoftware/slsDetector/slsDetectorUtils.h +++ b/slsDetectorSoftware/slsDetector/slsDetectorUtils.h @@ -749,9 +749,9 @@ virtual ROI* getROI(int &n)=0; */ virtual int setReadReceiverFrequency(int getFromReceiver, int freq=-1)=0; -/** Enable or disable streaming of data from receiver to client - * @param enable 0 to disable 1 to enable -1 to only get the value - * @returns data streaming +/** 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 to receiver enable */ virtual int enableDataStreamingFromReceiver(int enable=-1)=0;