connected command to execute command in receiver pc

This commit is contained in:
2018-10-10 12:23:55 +02:00
parent 5e7e7d3c33
commit b981fe78ef
6 changed files with 73 additions and 3 deletions

View File

@ -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<int>(OK)) ? OK : FAIL;
}
std::string multiSlsDetector::getFilePath(int detPos) {
// single
if (detPos >= 0) {

View File

@ -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

View File

@ -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,
}

View File

@ -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

View File

@ -112,6 +112,13 @@ slsDetectorCommand::slsDetectorCommand(multiSlsDetector *det) {
descrToFuncMap[i].m_pFuncPtr=&slsDetectorCommand::cmdExitServer;
++i;
/*! \page test
- <b>rx_execcommand</b> 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
- <b>flippeddatay [i]</b> 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();
}

View File

@ -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;