diff --git a/slsDetectorSoftware/multiSlsDetector/multiSlsDetector.cpp b/slsDetectorSoftware/multiSlsDetector/multiSlsDetector.cpp index ed2e44a0a..739bf18cb 100644 --- a/slsDetectorSoftware/multiSlsDetector/multiSlsDetector.cpp +++ b/slsDetectorSoftware/multiSlsDetector/multiSlsDetector.cpp @@ -2724,6 +2724,18 @@ int multiSlsDetector::exitReceiver(int detPos) { } +int multiSlsDetector::execReceiverCommand(std::string cmd, int detPos) { + // single + if (detPos >= 0) { + return detectors[detPos]->execReceiverCommand(cmd); + } + + // multi + auto r = parallelCall(&slsDetector::execReceiverCommand, cmd); + return sls::allEqualTo(r, static_cast(OK)) ? OK : FAIL; +} + + std::string multiSlsDetector::getFilePath(int detPos) { // single if (detPos >= 0) { diff --git a/slsDetectorSoftware/multiSlsDetector/multiSlsDetector.h b/slsDetectorSoftware/multiSlsDetector/multiSlsDetector.h index fb66a14db..46a4a1787 100644 --- a/slsDetectorSoftware/multiSlsDetector/multiSlsDetector.h +++ b/slsDetectorSoftware/multiSlsDetector/multiSlsDetector.h @@ -1229,6 +1229,15 @@ public: */ int exitReceiver(int detPos = -1); + /** + * Executes a system command on the receiver server + * e.g. mount an nfs disk, reboot and returns answer etc. + * @param cmd command to be executed + * @param detPos -1 for all detectors in list or specific detector position + * @returns OK or FAIL + */ + int execReceiverCommand(std::string cmd, int detPos = -1); + /** * Returns output file directory * @param detPos -1 for all detectors in list or specific detector position diff --git a/slsDetectorSoftware/slsDetector/slsDetector.cpp b/slsDetectorSoftware/slsDetector/slsDetector.cpp index 7ad201c57..822f8fb41 100644 --- a/slsDetectorSoftware/slsDetector/slsDetector.cpp +++ b/slsDetectorSoftware/slsDetector/slsDetector.cpp @@ -5990,6 +5990,30 @@ int slsDetector::exitReceiver() { } +int slsDetector::execReceiverCommand(std::string cmd) { + + int fnum=F_EXEC_RECEIVER_COMMAND; + int ret=FAIL; + char arg[MAX_STR_LENGTH]; + memset(arg,0,sizeof(arg)); + char retval[MAX_STR_LENGTH]; + memset(retval,0, sizeof(retval)); + + strcpy(arg,cmd.c_str()); + + if (thisDetector->receiverOnlineFlag==ONLINE_FLAG) { +#ifdef VERBOSE + std::cout << "Sending to receiver the command: " << arg << std::endl; +#endif + if (connectData() == OK){ + ret=thisReceiver->SendString(fnum,retval,arg); + disconnectData(); + } + } + return ret; +} + + int slsDetector::updateReceiverNoWait() { @@ -7506,3 +7530,5 @@ int slsDetector::writeSettingsFile(std::string fname, sls_detector_module mod, } + + diff --git a/slsDetectorSoftware/slsDetector/slsDetector.h b/slsDetectorSoftware/slsDetector/slsDetector.h index 368b34d52..d280c6682 100644 --- a/slsDetectorSoftware/slsDetector/slsDetector.h +++ b/slsDetectorSoftware/slsDetector/slsDetector.h @@ -1377,6 +1377,14 @@ public: */ int exitReceiver(); + /** + * Executes a system command on the receiver server + * e.g. mount an nfs disk, reboot and returns answer etc. + * @param cmd command to be executed + * @returns OK or FAIL + */ + int execReceiverCommand(std::string cmd); + /** updates the shared memory receiving the data from the detector (without asking and closing the connection /returns OK diff --git a/slsDetectorSoftware/slsDetector/slsDetectorCommand.cpp b/slsDetectorSoftware/slsDetector/slsDetectorCommand.cpp index 68823a18c..ffc9de7a3 100644 --- a/slsDetectorSoftware/slsDetector/slsDetectorCommand.cpp +++ b/slsDetectorSoftware/slsDetector/slsDetectorCommand.cpp @@ -112,6 +112,13 @@ slsDetectorCommand::slsDetectorCommand(multiSlsDetector *det) { descrToFuncMap[i].m_pFuncPtr=&slsDetectorCommand::cmdExitServer; ++i; + /*! \page test + - rx_execcommand Executes a command on the receiver server. Don't use it!!!! + */ + descrToFuncMap[i].m_pFuncName="rx_execcommand";//OK + descrToFuncMap[i].m_pFuncPtr=&slsDetectorCommand::cmdExitServer; + ++i; + /*! \page test - flippeddatay [i] enables/disables data being flipped across y axis. 1 enables, 0 disables. Not implemented. */ @@ -2437,7 +2444,13 @@ string slsDetectorCommand::cmdExitServer(int narg, char *args[], int action, int if(myDet->execCommand(std::string(args[1]), detPos)==OK) return string("Command executed successfully\n"); else - + return string("Command failed\n"); + } + else if (cmd=="rx_execcommand"){ + myDet->setReceiverOnline(ONLINE_FLAG, detPos); + if(myDet->execReceiverCommand(std::string(args[1]), detPos)==OK) + return string("Command executed successfully\n"); + else return string("Command failed\n"); } else return("cannot decode command\n"); @@ -2451,6 +2464,7 @@ string slsDetectorCommand::helpExitServer(int action){ os << string("exitserver \t shuts down all the detector servers. Don't use it!!!!\n"); os << string("exitreceiver \t shuts down all the receiver servers.\n"); os << string("execcommand \t executes command in detector server. Don't use it if you do not know what you are doing.\n"); + os << string("rx_execcommand \t executes command in receiver server. Don't use it if you do not know what you are doing.\n"); return os.str(); } diff --git a/slsReceiverSoftware/src/slsReceiverTCPIPInterface.cpp b/slsReceiverSoftware/src/slsReceiverTCPIPInterface.cpp index 6130ded10..a7886f341 100644 --- a/slsReceiverSoftware/src/slsReceiverTCPIPInterface.cpp +++ b/slsReceiverSoftware/src/slsReceiverTCPIPInterface.cpp @@ -426,7 +426,7 @@ int slsReceiverTCPIPInterface::exec_command() { sysret=system(cmd); //should be replaced by popen if (sysret == 0) { - sprintf(mess,"Succeeded\n"); + ret = OK; } else { ret = FAIL; sprintf(mess,"Executing Command failed\n"); @@ -436,7 +436,8 @@ int slsReceiverTCPIPInterface::exec_command() { // send answer mySock->SendDataOnly(&ret,sizeof(ret)); - mySock->SendDataOnly(mess,MAX_STR_LENGTH); + if (ret == FAIL) + mySock->SendDataOnly(mess,MAX_STR_LENGTH); // return ok/fail return ret;