diff --git a/slsDetectorSoftware/commonFiles/sls_detector_funcs.h b/slsDetectorSoftware/commonFiles/sls_detector_funcs.h index 636d11b72..f1007ee08 100644 --- a/slsDetectorSoftware/commonFiles/sls_detector_funcs.h +++ b/slsDetectorSoftware/commonFiles/sls_detector_funcs.h @@ -105,6 +105,9 @@ enum { F_RESET_COUNTER_BLOCK, /**< resets the counter block memory for gotthard */ + + //receiver + F_SET_RECEIVER_FILE_NAME, /**< sets receiver file name */ F_SET_RECEIVER_FILE_DIR, /**< sets receiver file directory */ @@ -117,7 +120,9 @@ enum { F_GET_RECEIVER_STATUS, /**< gets the status of receiver listening mode */ - F_GET_FRAMES_CAUGHT /**< gets the number of frames caught by receiver */ + F_GET_FRAMES_CAUGHT, /**< gets the number of frames caught by receiver */ + + F_LOCK_RECEIVER, /**< locks receiver */ /* Always append functions hereafter!!! */ diff --git a/slsDetectorSoftware/multiSlsDetector/multiSlsDetector.cpp b/slsDetectorSoftware/multiSlsDetector/multiSlsDetector.cpp index 674752d5a..b067bbd6d 100644 --- a/slsDetectorSoftware/multiSlsDetector/multiSlsDetector.cpp +++ b/slsDetectorSoftware/multiSlsDetector/multiSlsDetector.cpp @@ -3736,3 +3736,50 @@ int multiSlsDetector::getFramesCaughtByReciver() { + +int multiSlsDetector::lockReceiver(int lock) { + + int ret=-100, ret1; + + for (int idet=0; idetnumberOfDetectors; idet++) { + if (detectors[idet]) { + ret1=detectors[idet]->lockReceiver(lock); + if (ret==-100) + ret=ret1; + else if (ret!=ret1) + ret=-1; + } + } + + return ret; + +} + + + + + +string multiSlsDetector::getReceiverLastClientIP() { + string s0="", s1="",s ; + + for (int idet=0; idetnumberOfDetectors; idet++) { + if (detectors[idet]) { + s=detectors[idet]->getReceiverLastClientIP(); + + if (s0=="") + s0=s; + else + s0+=string("+")+s; + if (s1=="") + s1=s; + else if (s1!=s) + s1="bad"; + } + } + if (s1=="bad") + return s0; + else + return s1; +} + + diff --git a/slsDetectorSoftware/multiSlsDetector/multiSlsDetector.h b/slsDetectorSoftware/multiSlsDetector/multiSlsDetector.h index 4a476bc2d..97078bff4 100644 --- a/slsDetectorSoftware/multiSlsDetector/multiSlsDetector.h +++ b/slsDetectorSoftware/multiSlsDetector/multiSlsDetector.h @@ -1063,6 +1063,18 @@ class multiSlsDetector : public slsDetectorUtils { */ int getFramesCaughtByReciver(); + /** Locks/Unlocks the connection to the receiver + /param lock sets (1), usets (0), gets (-1) the lock + /returns lock status of the receiver + */ + int lockReceiver(int lock=-1); + + /** + Returns the IP of the last client connecting to the receiver + */ + string getReceiverLastClientIP(); + + protected: diff --git a/slsDetectorSoftware/slsDetector/slsDetector.cpp b/slsDetectorSoftware/slsDetector/slsDetector.cpp index bb16873da..a349d6792 100644 --- a/slsDetectorSoftware/slsDetector/slsDetector.cpp +++ b/slsDetectorSoftware/slsDetector/slsDetector.cpp @@ -5470,8 +5470,8 @@ string slsDetector::setReceiverFileName(string fileName) { dataSocket->ReceiveDataOnly(retval,MAX_STR_LENGTH); } dataSocket->Disconnect(); - /*if (ret==FORCE_UPDATE) - updateReceiver();*/ + if (ret==FORCE_UPDATE) + updateReceiver(); } } @@ -5507,8 +5507,8 @@ string slsDetector::setReceiverFileDir(string fileDir) { dataSocket->ReceiveDataOnly(retval,MAX_STR_LENGTH); } dataSocket->Disconnect(); - /*if (ret==FORCE_UPDATE) - updateReceiver();*/ + if (ret==FORCE_UPDATE) + updateReceiver(); } } return string(retval); @@ -5542,8 +5542,8 @@ int slsDetector::setReceiverFileIndex(int fileIndex) { dataSocket->ReceiveDataOnly(&retval,sizeof(retval)); } dataSocket->Disconnect(); - /*if (ret==FORCE_UPDATE) - updateReceiver();*/ + if (ret==FORCE_UPDATE) + updateReceiver(); } } @@ -5572,8 +5572,8 @@ int slsDetector::startReceiver(){ std::cout<< "Receiver returned error: " << mess << std::endl; } dataSocket->Disconnect(); - /*if (ret==FORCE_UPDATE) - updateReceiver();*/ + if (ret==FORCE_UPDATE) + updateReceiver(); } } } @@ -5603,8 +5603,8 @@ int slsDetector::stopReceiver(){ } dataSocket->Disconnect(); - /*if (ret==FORCE_UPDATE) - updateReceiver();*/ + if (ret==FORCE_UPDATE) + updateReceiver(); } } } @@ -5636,6 +5636,8 @@ slsDetectorDefs::runStatus slsDetector::getReceiverStatus(){ dataSocket->ReceiveDataOnly(&retval,sizeof(retval)); dataSocket->Disconnect(); + if (ret==FORCE_UPDATE) + updateReceiver(); } } } @@ -5652,7 +5654,7 @@ int slsDetector::getFramesCaughtByReciver(){ int retval=-1; #ifdef VERBOSE - std::cout << "Starting Receiver " << std::endl; + std::cout << "Getting Frames Caught by Receiver " << std::endl; #endif if (thisDetector->receiverOnlineFlag==ONLINE_FLAG) { @@ -5667,11 +5669,140 @@ int slsDetector::getFramesCaughtByReciver(){ std::cout<< "Receiver returned error: " << mess << std::endl; } dataSocket->Disconnect(); - /*if (ret==FORCE_UPDATE) - updateReceiver();*/ + if (ret==FORCE_UPDATE) + updateReceiver(); } } } return retval; } + + + +int slsDetector::lockReceiver(int lock){ + int fnum=F_LOCK_RECEIVER; + int ret = FAIL; + int retval=-1; + char mess[100]; + + int arg= lock; + +#ifdef VERBOSE + std::cout << "Locking or Unlocking Receiver " << std::endl; +#endif + + if (thisDetector->receiverOnlineFlag==ONLINE_FLAG) { + if (dataSocket) { + if (dataSocket->Connect()>=0) { + dataSocket->SendDataOnly(&fnum,sizeof(fnum)); + dataSocket->SendDataOnly(&arg,sizeof(arg)); + dataSocket->ReceiveDataOnly(&ret,sizeof(ret)); + if (ret!=FAIL) + dataSocket->ReceiveDataOnly(&retval,sizeof(retval)); + else{ + dataSocket->ReceiveDataOnly(mess,sizeof(mess)); + std::cout<< "Receiver returned error: " << mess << std::endl; + } + + dataSocket->Disconnect(); + if (ret==FORCE_UPDATE) + updateReceiver(); + } + } + } + return retval; +} + + + + + + +string slsDetector::getReceiverLastClientIP(){ + int fnum=F_GET_LAST_CLIENT_IP; + int ret = FAIL; + char retval[INET_ADDRSTRLEN]; + char mess[100]; + + +#ifdef VERBOSE + std::cout << "Geting Last Client IP connected to Receiver " << std::endl; +#endif + + if (thisDetector->receiverOnlineFlag==ONLINE_FLAG) { + if (dataSocket) { + if (dataSocket->Connect()>=0) { + dataSocket->SendDataOnly(&fnum,sizeof(fnum)); + dataSocket->ReceiveDataOnly(&ret,sizeof(ret)); + if (ret!=FAIL) + dataSocket->ReceiveDataOnly(retval,sizeof(retval)); + else{ + dataSocket->ReceiveDataOnly(mess,sizeof(mess)); + std::cout<< "Receiver returned error: " << mess << std::endl; + } + + dataSocket->Disconnect(); + if (ret==FORCE_UPDATE) + updateReceiver(); + } + } + } + return string(retval); +} + + + + + +int slsDetector::updateReceiverNoWait() { + + int n,ind; + char path[MAX_STR_LENGTH]; + char lastClientIP[INET_ADDRSTRLEN]; + + n = dataSocket->ReceiveDataOnly(lastClientIP,sizeof(lastClientIP)); +#ifdef VERBOSE + cout << "Updating receiver last modified by " << lastClientIP << std::endl; +#endif + + n = dataSocket->ReceiveDataOnly(&ind,sizeof(ind)); cout<<"index:"<xx=xx;update file index how? + n = dataSocket->ReceiveDataOnly(path,MAX_STR_LENGTH); cout<<"path:"<xx=xx;update file index how? + n = dataSocket->ReceiveDataOnly(path,MAX_STR_LENGTH); cout<<"name:"<xx=xx;update file index how? + return OK; + +} + + + + + +int slsDetector::updateReceiver() { + int fnum=F_UPDATE_CLIENT; + int ret=OK; + char mess[100]; + + if (thisDetector->receiverOnlineFlag==ONLINE_FLAG) { + if (dataSocket) { + if (dataSocket->Connect()>=0) { + dataSocket->SendDataOnly(&fnum,sizeof(fnum)); + dataSocket->ReceiveDataOnly(&ret,sizeof(ret)); + if (ret!=FAIL) + updateReceiverNoWait(); + else{ + dataSocket->ReceiveDataOnly(mess,sizeof(mess)); + std::cout<< "Receiver returned error: " << mess << std::endl; + } + + dataSocket->Disconnect(); + } + } + } + + return ret; +} + + diff --git a/slsDetectorSoftware/slsDetector/slsDetector.h b/slsDetectorSoftware/slsDetector/slsDetector.h index 0c700e1ab..158d68b78 100644 --- a/slsDetectorSoftware/slsDetector/slsDetector.h +++ b/slsDetectorSoftware/slsDetector/slsDetector.h @@ -1429,6 +1429,29 @@ typedef struct sharedSlsDetector { */ int getFramesCaughtByReciver(); + /** Locks/Unlocks the connection to the receiver + /param lock sets (1), usets (0), gets (-1) the lock + /returns lock status of the receiver + */ + int lockReceiver(int lock=-1); + + /** + Returns the IP of the last client connecting to the receiver + */ + string getReceiverLastClientIP(); + + /** + updates the shared memory receiving the data from the detector (without asking and closing the connection + /returns OK + */ + int updateReceiverNoWait(); + + /** + updates the shared memory receiving the data from the detector + /returns OK + */ + int updateReceiver(); + protected: diff --git a/slsDetectorSoftware/slsDetector/slsDetectorBase.h b/slsDetectorSoftware/slsDetector/slsDetectorBase.h index c8a11d86c..6f6c15f9b 100644 --- a/slsDetectorSoftware/slsDetector/slsDetectorBase.h +++ b/slsDetectorSoftware/slsDetector/slsDetectorBase.h @@ -477,6 +477,12 @@ int64_t setNumberOfCycles(int64_t t=-1){return setTimer(CYCLES_NUMBER,t);}; */ virtual int getFramesCaughtByReciver()=0; + /** Locks/Unlocks the connection to the receiver + /param lock sets (1), usets (0), gets (-1) the lock + /returns lock status of the receiver + */ + virtual int lockReceiver(int lock=-1)=0; + /** returns detector type string from detector type index \param t string can be Mythen, Pilatus, Eiger, Gotthard, Agipd, Unknown diff --git a/slsDetectorSoftware/slsDetector/slsDetectorCommand.cpp b/slsDetectorSoftware/slsDetector/slsDetectorCommand.cpp index c1eeec828..7c69592e9 100644 --- a/slsDetectorSoftware/slsDetector/slsDetectorCommand.cpp +++ b/slsDetectorSoftware/slsDetector/slsDetectorCommand.cpp @@ -655,6 +655,13 @@ slsDetectorCommand::slsDetectorCommand(slsDetectorUtils *det) { descrToFuncMap[i].m_pFuncPtr=&slsDetectorCommand::cmdReceiver; i++; + descrToFuncMap[i].m_pFuncName="r_lock"; // + descrToFuncMap[i].m_pFuncPtr=&slsDetectorCommand::cmdLock; + i++; + + descrToFuncMap[i].m_pFuncName="r_lastclient"; // + descrToFuncMap[i].m_pFuncPtr=&slsDetectorCommand::cmdLastClient; + i++; numberOfCommands=i; @@ -2265,15 +2272,37 @@ string slsDetectorCommand::cmdLock(int narg, char *args[], int action) { int val;//, ret; char ans[1000]; - myDet->setOnline(ONLINE_FLAG); - if (action==PUT_ACTION) { - if (sscanf(args[1],"%d",&val)) - myDet->lockServer(val); - else - return string("could not lock status")+string(args[1]); + if(cmd=="lock"){ + myDet->setOnline(ONLINE_FLAG); + if (action==PUT_ACTION) { + if (sscanf(args[1],"%d",&val)) + myDet->lockServer(val); + else + return string("could not lock status")+string(args[1]); + } + + sprintf(ans,"%d",myDet->lockServer()); } - - sprintf(ans,"%d",myDet->lockServer()); + + + else if(cmd=="r_lock"){ + if(myDet->setReceiverOnline(ONLINE_FLAG)!=ONLINE_FLAG) + return string("could not connect to receiver"); + + if (action==PUT_ACTION) { + if (!sscanf(args[1],"%d",&val)) + return string("could not decode lock status")+string(args[1]); + + if(myDet->lockReceiver(val)!=val) + return string("could not lock/unlock receiver"); + } + sprintf(ans,"%d",myDet->lockReceiver()); + } + + + else + return string("could not decode command"); + return string(ans); } @@ -2285,10 +2314,11 @@ string slsDetectorCommand::helpLock(int narg, char *args[], int action) { ostringstream os; if (action==PUT_ACTION || action==HELP_ACTION) { os << "lock i \n locks (1) or unlocks (0) the detector to communicate to this client"<< std::endl; - + os << "r_lock i \n locks (1) or unlocks (0) the receiver to communicate to this client"<< std::endl; } if (action==GET_ACTION || action==HELP_ACTION) { os << "lock \n returns the detector lock status"<< std::endl; + os << "r_lock \n returns the receiver lock status"<< std::endl; } return os.str(); @@ -2301,13 +2331,21 @@ string slsDetectorCommand::cmdLastClient(int narg, char *args[], int action) { if (action==HELP_ACTION) return helpLastClient(narg,args,action); - myDet->setOnline(ONLINE_FLAG); - if (action==PUT_ACTION) - return string("cannot set"); - - return myDet->getLastClientIP(); + return string("cannot set"); + if(cmd=="lastclient"){ + myDet->setOnline(ONLINE_FLAG); + + return myDet->getLastClientIP(); + } + + else if(cmd=="r_lastclient"){ + if(myDet->setReceiverOnline(ONLINE_FLAG)!=ONLINE_FLAG) + return string("could not connect to receiver"); + + return myDet->getReceiverLastClientIP(); + } } string slsDetectorCommand::helpLastClient(int narg, char *args[], int action) { @@ -2316,6 +2354,7 @@ string slsDetectorCommand::helpLastClient(int narg, char *args[], int action) { ostringstream os; if (action==GET_ACTION || action==HELP_ACTION) { os << "lastclient \n returns the last client communicating with the detector"<< std::endl; + os << "r_lastclient \n returns the last client communicating with the receiver"<< std::endl; } return os.str(); diff --git a/slsDetectorSoftware/slsDetector/slsDetectorUtils.h b/slsDetectorSoftware/slsDetector/slsDetectorUtils.h index 15f23166b..eccefd212 100644 --- a/slsDetectorSoftware/slsDetector/slsDetectorUtils.h +++ b/slsDetectorSoftware/slsDetector/slsDetectorUtils.h @@ -162,7 +162,7 @@ class slsDetectorUtils : public slsDetectorActions, public postProcessing { /** gets the network parameters (implemented for gotthard) - \param i network parameter type can be CLIENT_IP, CLIENT_MAC, SERVER_MAC + \param i network parameter type can be RECEIVER_IP, RECEIVER_MAC, SERVER_MAC \returns parameter */ @@ -170,7 +170,7 @@ class slsDetectorUtils : public slsDetectorActions, public postProcessing { /** sets the network parameters (implemented for gotthard) - \param i network parameter type can be CLIENT_IP, CLIENT_MAC, SERVER_MAC + \param i network parameter type can be RECEIVER_IP, RECEIVER_MAC, SERVER_MAC \param s value to be set \returns parameter @@ -581,6 +581,10 @@ class slsDetectorUtils : public slsDetectorActions, public postProcessing { */ virtual string checkReceiverOnline()=0; + /** + Returns the IP of the last client connecting to the receiver + */ + virtual string getReceiverLastClientIP()=0; protected: