mirror of
https://github.com/slsdetectorgroup/slsDetectorPackage.git
synced 2025-06-23 18:17:59 +02:00
client connecting to gui serveR done
git-svn-id: file:///afs/psi.ch/project/sls_det_software/svn/slsDetectorGui@150 af1100a4-978c-4157-bff7-07162d2ba061
This commit is contained in:
@ -11,6 +11,7 @@
|
||||
#include "slsDetectorBase.h"
|
||||
// C++ Include Headers
|
||||
#include <iostream>
|
||||
#include <sstream>
|
||||
using namespace std;
|
||||
|
||||
|
||||
@ -49,55 +50,129 @@ int qClient::executeLine(int narg, char *args[]){
|
||||
char answer[100];
|
||||
string retval = "";
|
||||
string cmd = args[0];
|
||||
string argument;
|
||||
|
||||
|
||||
//validate command structure
|
||||
if(narg<1){
|
||||
cout << "Error: no command parsed" << endl;
|
||||
return slsDetectorDefs::FAIL;
|
||||
return FAIL;
|
||||
}
|
||||
|
||||
|
||||
//help
|
||||
if (cmd == "help"){
|
||||
retval = printCommands();
|
||||
}
|
||||
|
||||
//file name
|
||||
if (cmd == "status"){
|
||||
else if (cmd == "status"){
|
||||
|
||||
if(narg>1){
|
||||
argument = args[1];
|
||||
//start acquisition
|
||||
if(argument == "start")
|
||||
sendToGuiServer(F_START_ACQUISITION);
|
||||
else if (argument == "stop")
|
||||
sendToGuiServer(F_STOP_ACQUISITION);
|
||||
else{
|
||||
cout << "Error: could not parse arguments: " << argument << endl;
|
||||
printCommands();
|
||||
return FAIL;
|
||||
}
|
||||
}
|
||||
retval = getStatus();
|
||||
}
|
||||
|
||||
|
||||
else if (cmd == "acquire"){
|
||||
sendToGuiServer(F_START_AND_READ_ALL);
|
||||
retval = getStatus();
|
||||
}
|
||||
|
||||
|
||||
else if (cmd == "exit"){
|
||||
if (sendToGuiServer(F_EXIT_SERVER) == OK)
|
||||
retval = "Gui Server Exited successfully.";
|
||||
else
|
||||
retval = "Gui Server could not exit successfully";
|
||||
}
|
||||
|
||||
|
||||
//unrecognized command
|
||||
else{
|
||||
cout << "Error: unrecognized command" << endl;
|
||||
return slsDetectorDefs::FAIL;
|
||||
return FAIL;
|
||||
}
|
||||
|
||||
|
||||
//print result
|
||||
cout << cmd << ": " << retval << endl;
|
||||
|
||||
return slsDetectorDefs::OK;
|
||||
return OK;
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
|
||||
string qClient::printCommands(){
|
||||
ostringstream os;
|
||||
os << "\nexit \t exits server in gui" << std::endl;
|
||||
os << "status \t gets status of acquisition in gui. - can be running or idle" << std::endl;
|
||||
os << "status i starts/stops acquistion in gui-non blocking. i is start or stop" << std::endl;
|
||||
os << "acquire starts acquistion in gui-blocking" << std::endl;
|
||||
return os.str();
|
||||
}
|
||||
|
||||
|
||||
//-------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
|
||||
string qClient::getStatus(){
|
||||
int fnum = slsDetectorDefs::F_GET_RUN_STATUS;
|
||||
int ret = slsDetectorDefs::FAIL;
|
||||
int retval = -1;
|
||||
slsDetectorDefs::runStatus s=slsDetectorDefs::ERROR;
|
||||
int fnum = F_GET_RUN_STATUS;
|
||||
int ret = FAIL;
|
||||
runStatus retval=ERROR;
|
||||
int progress = 0;
|
||||
char answer[100];
|
||||
|
||||
if (mySocket->Connect() >= 0) {
|
||||
mySocket->SendDataOnly(&fnum,sizeof(fnum));
|
||||
mySocket->ReceiveDataOnly(&ret,sizeof(ret));
|
||||
mySocket->ReceiveDataOnly(&retval,sizeof(retval));
|
||||
}
|
||||
mySocket->Disconnect();
|
||||
mySocket->ReceiveDataOnly(&progress,sizeof(progress));
|
||||
mySocket->Disconnect();
|
||||
}else
|
||||
exit(-1);
|
||||
|
||||
if(retval==-1)
|
||||
retval=slsDetectorDefs::ERROR;
|
||||
|
||||
return slsDetectorBase::runStatusType((slsDetectorDefs::runStatus)retval);
|
||||
sprintf(answer,"%d%% ",progress);
|
||||
strcat(answer,slsDetectorBase::runStatusType((runStatus)retval).c_str());
|
||||
|
||||
return string(answer);
|
||||
}
|
||||
|
||||
|
||||
//-------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
|
||||
int qClient::sendToGuiServer(int fnum){
|
||||
int ret = FAIL;
|
||||
char mess[100] = "";
|
||||
|
||||
if (mySocket->Connect() >= 0) {
|
||||
mySocket->SendDataOnly(&fnum,sizeof(fnum));
|
||||
mySocket->ReceiveDataOnly(&ret,sizeof(ret));
|
||||
if (ret == FAIL){
|
||||
mySocket->ReceiveDataOnly(mess,sizeof(mess));
|
||||
std::cout<< "Gui returned error: " << mess << std::endl;
|
||||
}
|
||||
mySocket->Disconnect();
|
||||
}else
|
||||
exit(-1);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
//-------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
|
@ -9,7 +9,6 @@
|
||||
|
||||
|
||||
/** Qt Project Class Headers */
|
||||
//#include "qDefs.h"
|
||||
/** Project Class Headers */
|
||||
class MySocketTCP;
|
||||
#include "sls_detector_defs.h"
|
||||
@ -34,6 +33,12 @@ public:
|
||||
int executeLine(int narg, char *args[]);
|
||||
|
||||
private:
|
||||
/** Print list of commands */
|
||||
string printCommands();
|
||||
|
||||
/** Send to Gui Server */
|
||||
int sendToGuiServer(int fnum);
|
||||
|
||||
/** Gets run status */
|
||||
string getStatus();
|
||||
|
||||
|
Reference in New Issue
Block a user