mirror of
https://github.com/slsdetectorgroup/slsDetectorPackage.git
synced 2025-04-23 23:10:02 +02:00
added receiver functions
git-svn-id: file:///afs/psi.ch/project/sls_det_software/svn/slsDetectorSoftware@276 951219d9-93cf-4727-9268-0efd64621fa3
This commit is contained in:
parent
d77f4a679a
commit
d5a092c2e8
@ -446,9 +446,9 @@ int slsDetector::initializeDetectorSize(detectorType type) {
|
||||
strcpy(thisDetector->hostname,DEFAULT_HOSTNAME);
|
||||
|
||||
/** set client ip address */
|
||||
strcpy(thisDetector->clientIP,"none");
|
||||
strcpy(thisDetector->receiverIP,"none");
|
||||
/** set client mac address */
|
||||
strcpy(thisDetector->clientMAC,"none");
|
||||
strcpy(thisDetector->receiverMAC,"none");
|
||||
/** set server mac address */
|
||||
strcpy(thisDetector->serverMAC,"00:aa:bb:cc:dd:ee");
|
||||
|
||||
@ -591,6 +591,9 @@ int slsDetector::initializeDetectorSize(detectorType type) {
|
||||
thisDetector->scanPrecision[iscan]=0;
|
||||
}
|
||||
|
||||
/* receiver*/
|
||||
/** sets receiver onlineFlag to OFFLINE_FLAG */
|
||||
thisDetector->receiverOnlineFlag=OFFLINE_FLAG;
|
||||
|
||||
|
||||
/** calculates the memory offsets for flat field coefficients and errors, module structures, dacs, adcs, chips and channels */
|
||||
@ -951,7 +954,7 @@ string slsDetector::checkOnline() {
|
||||
|
||||
*/
|
||||
|
||||
int slsDetector::setTCPSocket(string const name, int const control_port, int const stop_port, int const data_port){
|
||||
int slsDetector::setTCPSocket(string const name, int const control_port, int const stop_port){
|
||||
|
||||
|
||||
char thisName[MAX_STR_LENGTH];
|
||||
@ -1006,20 +1009,6 @@ int slsDetector::setTCPSocket(string const name, int const control_port, int con
|
||||
thisSP=thisDetector->stopPort;
|
||||
|
||||
|
||||
if (data_port>0) {
|
||||
#ifdef VERBOSE
|
||||
std::cout<< "setting data port" << std::endl;
|
||||
#endif
|
||||
thisDP=data_port;
|
||||
thisDetector->dataPort=thisDP;
|
||||
if (dataSocket){
|
||||
delete dataSocket;
|
||||
dataSocket=NULL;
|
||||
}
|
||||
} else
|
||||
thisDP=thisDetector->dataPort;
|
||||
|
||||
|
||||
if (!controlSocket) {
|
||||
controlSocket= new MySocketTCP(thisName, thisCP);
|
||||
if (controlSocket->getErrorStatus()){
|
||||
@ -3467,13 +3456,13 @@ int slsDetector::setPort(portType index, int num){
|
||||
retval=thisDetector->controlPort;
|
||||
#ifdef VERBOSE
|
||||
cout << "s="<< s<< endl;
|
||||
cout << thisDetector->controlPort<< " " << thisDetector->dataPort << " " << thisDetector->stopPort << endl;
|
||||
cout << thisDetector->controlPort<< " " << " " << thisDetector->stopPort << endl;
|
||||
#endif
|
||||
if (s==NULL) {
|
||||
|
||||
#ifdef VERBOSE
|
||||
cout << "s=NULL"<< endl;
|
||||
cout << thisDetector->controlPort<< " " << thisDetector->dataPort << " " << thisDetector->stopPort << endl;
|
||||
cout << thisDetector->controlPort<< " " << " " << thisDetector->stopPort << endl;
|
||||
#endif
|
||||
setTCPSocket("",DEFAULT_PORTNO);
|
||||
}
|
||||
@ -3482,7 +3471,7 @@ int slsDetector::setPort(portType index, int num){
|
||||
} else {
|
||||
#ifdef VERBOSE
|
||||
cout << "still cannot connect!"<< endl;
|
||||
cout << thisDetector->controlPort<< " " << thisDetector->dataPort << " " << thisDetector->stopPort << endl;
|
||||
cout << thisDetector->controlPort<< " " << " " << thisDetector->stopPort << endl;
|
||||
#endif
|
||||
|
||||
|
||||
@ -3493,9 +3482,9 @@ int slsDetector::setPort(portType index, int num){
|
||||
case DATA_PORT:
|
||||
s=dataSocket;
|
||||
retval=thisDetector->dataPort;
|
||||
if (s==NULL) setTCPSocket("",-1,-1,DEFAULT_PORTNO+2);
|
||||
if (s==NULL) setReceiverTCPSocket("",DEFAULT_PORTNO+2);
|
||||
if (dataSocket) s=dataSocket;
|
||||
else setTCPSocket("",-1,-1,retval);
|
||||
else setReceiverTCPSocket("",retval);
|
||||
break;
|
||||
case STOP_PORT:
|
||||
s=stopSocket;
|
||||
@ -4432,11 +4421,11 @@ int slsDetector::exitServer(){
|
||||
char* slsDetector::setNetworkParameter(networkParameter index, string value) {
|
||||
|
||||
switch (index) {
|
||||
case CLIENT_IP:
|
||||
return setClientIP(value);
|
||||
case RECEIVER_IP:
|
||||
return setReceiverIP(value);
|
||||
break;
|
||||
case CLIENT_MAC:
|
||||
return setClientMAC(value);
|
||||
case RECEIVER_MAC:
|
||||
return setReceiverMAC(value);
|
||||
break;
|
||||
case SERVER_MAC:
|
||||
return setServerMAC(value);
|
||||
@ -4450,11 +4439,11 @@ char* slsDetector::setNetworkParameter(networkParameter index, string value) {
|
||||
char* slsDetector::getNetworkParameter(networkParameter index) {
|
||||
|
||||
switch (index) {
|
||||
case CLIENT_IP:
|
||||
return getClientIP();
|
||||
case RECEIVER_IP:
|
||||
return getReceiverIP();
|
||||
break;
|
||||
case CLIENT_MAC:
|
||||
return getClientMAC();
|
||||
case RECEIVER_MAC:
|
||||
return getReceiverMAC();
|
||||
break;
|
||||
case SERVER_MAC:
|
||||
return getServerMAC();
|
||||
@ -4470,38 +4459,43 @@ char* slsDetector::getNetworkParameter(networkParameter index) {
|
||||
|
||||
|
||||
|
||||
char* slsDetector::setClientIP(string clientIP){
|
||||
int wrongFormat=1;
|
||||
char* slsDetector::setReceiverIP(string receiverIP){
|
||||
int wrongFormat=1;
|
||||
|
||||
struct sockaddr_in sa;
|
||||
if(receiverIP.length()<16){
|
||||
if((receiverIP[3]=='.')&&(receiverIP[7]=='.')&&(receiverIP[11]=='.')){
|
||||
int result = inet_pton(AF_INET, receiverIP.c_str(), &(sa.sin_addr));
|
||||
if(result!=0){
|
||||
sprintf(thisDetector->receiverIP,receiverIP.c_str());
|
||||
wrongFormat=0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(wrongFormat)
|
||||
return ("IP Address should be VALID and in xxx.xxx.xxx.xxx format");
|
||||
|
||||
if(setReceiverTCPSocket()==FAIL)
|
||||
return("Connection to Receiver failed.");
|
||||
|
||||
return thisDetector->receiverIP;
|
||||
|
||||
struct sockaddr_in sa;
|
||||
if(clientIP.length()<16){
|
||||
if((clientIP[3]=='.')&&(clientIP[7]=='.')&&(clientIP[11]=='.')){
|
||||
int result = inet_pton(AF_INET, clientIP.c_str(), &(sa.sin_addr));
|
||||
if(result!=0){
|
||||
sprintf(thisDetector->clientIP,clientIP.c_str());
|
||||
wrongFormat=0;
|
||||
}
|
||||
}
|
||||
}
|
||||
if(!wrongFormat)
|
||||
return thisDetector->clientIP;
|
||||
else
|
||||
return ("IP Address should be VALID and in xxx.xxx.xxx.xxx format");
|
||||
}
|
||||
|
||||
|
||||
char* slsDetector::setClientMAC(string clientMAC){
|
||||
if(clientMAC.length()==17){
|
||||
if((clientMAC[2]==':')&&(clientMAC[5]==':')&&(clientMAC[8]==':')&&
|
||||
(clientMAC[11]==':')&&(clientMAC[14]==':'))
|
||||
sprintf(thisDetector->clientMAC,clientMAC.c_str());
|
||||
char* slsDetector::setReceiverMAC(string receiverMAC){
|
||||
if(receiverMAC.length()==17){
|
||||
if((receiverMAC[2]==':')&&(receiverMAC[5]==':')&&(receiverMAC[8]==':')&&
|
||||
(receiverMAC[11]==':')&&(receiverMAC[14]==':'))
|
||||
sprintf(thisDetector->receiverMAC,receiverMAC.c_str());
|
||||
else
|
||||
return("MAC Address should be in xx:xx:xx:xx:xx:xx format");
|
||||
}
|
||||
else
|
||||
return("MAC Address should be in xx:xx:xx:xx:xx:xx format");
|
||||
|
||||
return thisDetector->clientMAC;
|
||||
return thisDetector->receiverMAC;
|
||||
};
|
||||
|
||||
|
||||
@ -4528,8 +4522,8 @@ int slsDetector::configureMAC(){
|
||||
char arg[3][50];
|
||||
char cword[50]="", *pcword;
|
||||
string sword;
|
||||
strcpy(arg[0],getClientIP());
|
||||
strcpy(arg[1],getClientMAC());
|
||||
strcpy(arg[0],getReceiverIP());
|
||||
strcpy(arg[1],getReceiverMAC());
|
||||
strcpy(arg[2],getServerMAC());
|
||||
|
||||
|
||||
@ -5000,8 +4994,8 @@ int slsDetector::writeConfigurationFile(ofstream &outfile, int id){
|
||||
|
||||
switch (thisDetector->myDetectorType) {
|
||||
case GOTTHARD:
|
||||
names[9]="clientip";
|
||||
names[10]="clientmac";
|
||||
names[9]="receiverip";
|
||||
names[10]="receivermac";
|
||||
names[11]="servermac";
|
||||
nvar=12;
|
||||
break;
|
||||
@ -5320,94 +5314,332 @@ slsDetectorDefs::synchronizationMode slsDetector::setSynchronization(synchroniza
|
||||
|
||||
|
||||
|
||||
string slsDetector::setupReceiver(string fileName) {
|
||||
int fnum=F_SETUP_RECEIVER;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/*receiver*/
|
||||
int slsDetector::setReceiverOnline(int off) {
|
||||
if (off!=GET_ONLINE_FLAG) {
|
||||
thisDetector->receiverOnlineFlag=off;
|
||||
if (thisDetector->receiverOnlineFlag==ONLINE_FLAG)
|
||||
setReceiverTCPSocket();
|
||||
}
|
||||
return thisDetector->receiverOnlineFlag;
|
||||
}
|
||||
|
||||
|
||||
|
||||
string slsDetector::checkReceiverOnline() {
|
||||
string retval = "";
|
||||
//if it doesnt exits, create data socket
|
||||
if(!dataSocket){
|
||||
//this already sets the online/offline flag
|
||||
setReceiverTCPSocket();
|
||||
if(thisDetector->receiverOnlineFlag==OFFLINE_FLAG)
|
||||
return string(thisDetector->receiverIP);
|
||||
else
|
||||
return string("");
|
||||
}
|
||||
//still cannot connect to socket, dataSocket=0
|
||||
if(dataSocket){
|
||||
if (dataSocket->Connect()<0) {
|
||||
dataSocket->SetTimeOut(5);
|
||||
thisDetector->receiverOnlineFlag=OFFLINE_FLAG;
|
||||
delete dataSocket;
|
||||
dataSocket=NULL;
|
||||
retval = thisDetector->receiverIP;
|
||||
#ifdef VERBOSE
|
||||
std::cout<< "receiver offline!" << std::endl;
|
||||
#endif
|
||||
} else {
|
||||
thisDetector->receiverOnlineFlag=ONLINE_FLAG;
|
||||
dataSocket->SetTimeOut(100);
|
||||
dataSocket->Disconnect();
|
||||
#ifdef VERBOSE
|
||||
std::cout<< "receiver online!" << std::endl;
|
||||
#endif
|
||||
}
|
||||
}
|
||||
return retval;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*
|
||||
configure the socket communication and check that the receiver exists
|
||||
enum communicationProtocol{
|
||||
TCP,
|
||||
UDP
|
||||
}{};
|
||||
|
||||
*/
|
||||
|
||||
int slsDetector::setReceiverTCPSocket(string const name, int const data_port){
|
||||
|
||||
char thisName[MAX_STR_LENGTH];
|
||||
int thisDP;
|
||||
int retval=OK;
|
||||
|
||||
//if receiver ip given
|
||||
if (strcmp(name.c_str(),"")!=0) {
|
||||
#ifdef VERBOSE
|
||||
std::cout<< "setting receiver" << std::endl;
|
||||
#endif
|
||||
strcpy(thisName,name.c_str());
|
||||
strcpy(thisDetector->receiverIP,thisName);
|
||||
if (dataSocket){
|
||||
delete dataSocket;
|
||||
dataSocket=NULL;
|
||||
}
|
||||
} else
|
||||
strcpy(thisName,thisDetector->receiverIP);
|
||||
|
||||
//if dataport given
|
||||
if (data_port>0) {
|
||||
#ifdef VERBOSE
|
||||
std::cout<< "setting data port" << std::endl;
|
||||
#endif
|
||||
thisDP=data_port;
|
||||
thisDetector->dataPort=thisDP;
|
||||
if (dataSocket){
|
||||
delete dataSocket;
|
||||
dataSocket=NULL;
|
||||
}
|
||||
} else
|
||||
thisDP=thisDetector->dataPort;
|
||||
|
||||
//create data socket
|
||||
if (!dataSocket) {
|
||||
dataSocket=new MySocketTCP(thisName, thisDP);
|
||||
if (dataSocket->getErrorStatus()){
|
||||
#ifdef VERBOSE
|
||||
std::cout<< "Could not connect Data socket "<<thisName << " " << thisDP << std::endl;
|
||||
#endif
|
||||
delete dataSocket;
|
||||
dataSocket=NULL;
|
||||
retval=FAIL;
|
||||
}
|
||||
#ifdef VERYVERBOSE
|
||||
else
|
||||
std::cout<< "Data socket connected "<< thisName << " " << thisDP << std::endl;
|
||||
#endif
|
||||
}
|
||||
//check if it connects
|
||||
if (retval!=FAIL) {
|
||||
if(checkReceiverOnline().empty())
|
||||
retval=FAIL;
|
||||
} else {
|
||||
thisDetector->receiverOnlineFlag=OFFLINE_FLAG;
|
||||
#ifdef VERBOSE
|
||||
std::cout<< "offline!" << std::endl;
|
||||
#endif
|
||||
}
|
||||
return retval;
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
string slsDetector::setReceiverFileName(string fileName) {
|
||||
int fnum=F_SET_RECEIVER_FILE_NAME;
|
||||
int ret = FAIL;
|
||||
char mess[100];
|
||||
char arg[MAX_STR_LENGTH];
|
||||
|
||||
char arg[MAX_STR_LENGTH],retval[MAX_STR_LENGTH]="";
|
||||
strcpy(arg,fileName.c_str());
|
||||
|
||||
MySocketTCP *receiverSocket = new MySocketTCP(thisDetector->clientIP,thisDetector->dataPort);
|
||||
|
||||
if (receiverSocket->getErrorStatus()){
|
||||
#ifdef VERBOSE
|
||||
std::cout<< "Could not connect Control socket " << thisDetector->clientIP << " " << thisDetector->dataPort << std::endl;
|
||||
std::cout << "Sending file name to receiver " << arg << std::endl;
|
||||
#endif
|
||||
delete receiverSocket;
|
||||
receiverSocket=NULL;
|
||||
}
|
||||
else{
|
||||
if(receiverSocket){
|
||||
if (receiverSocket->Connect()>=0){
|
||||
if (receiverSocket->SendDataOnly(&fnum,sizeof(fnum))>=0)
|
||||
if (receiverSocket->SendDataOnly(arg,MAX_STR_LENGTH)>=0){
|
||||
receiverSocket->ReceiveDataOnly(&ret,sizeof(ret));
|
||||
if(ret==FAIL){
|
||||
receiverSocket->ReceiveDataOnly(mess,sizeof(mess));
|
||||
std::cout<< "Receiver returned error: " << mess << std::endl;
|
||||
}
|
||||
}
|
||||
receiverSocket->Disconnect();
|
||||
|
||||
if (thisDetector->receiverOnlineFlag==ONLINE_FLAG) {
|
||||
if (dataSocket) {
|
||||
if (dataSocket->Connect()>=0) {
|
||||
dataSocket->SendDataOnly(&fnum,sizeof(fnum));
|
||||
dataSocket->SendDataOnly(arg,MAX_STR_LENGTH);
|
||||
dataSocket->ReceiveDataOnly(&ret,sizeof(ret));
|
||||
if (ret==FAIL){
|
||||
dataSocket->ReceiveDataOnly(mess,sizeof(mess));
|
||||
std::cout<< "Receiver returned error: " << mess << std::endl;
|
||||
}else
|
||||
dataSocket->ReceiveDataOnly(retval,MAX_STR_LENGTH);
|
||||
}
|
||||
else strcpy(thisDetector->clientIP,"none");
|
||||
delete receiverSocket;//should I include also for good connection? cuz setTCPSocket() still uses it?
|
||||
receiverSocket=NULL;//should I include also for good connection? cuz setTCPSocket() still uses it?
|
||||
dataSocket->Disconnect();
|
||||
/*if (ret==FORCE_UPDATE)
|
||||
updateReceiver();*/
|
||||
}
|
||||
}
|
||||
/**if force update, updateReceiver?*/
|
||||
if(ret==OK) return fileName;
|
||||
return string("");
|
||||
|
||||
return string(retval);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
string slsDetector::setReceiverFileDir(string fileDir) {
|
||||
int fnum=F_SET_RECEIVER_FILE_DIR;
|
||||
int ret = FAIL;
|
||||
char mess[100];
|
||||
|
||||
slsDetectorDefs::runStatus slsDetector::startReceiver(string status,int index){
|
||||
char arg[MAX_STR_LENGTH],retval[MAX_STR_LENGTH]="";
|
||||
strcpy(arg,fileDir.c_str());
|
||||
|
||||
#ifdef VERBOSE
|
||||
std::cout << "Sending file dir to receiver " << arg << std::endl;
|
||||
#endif
|
||||
|
||||
if (thisDetector->receiverOnlineFlag==ONLINE_FLAG) {
|
||||
if (dataSocket) {
|
||||
if (dataSocket->Connect()>=0) {
|
||||
dataSocket->SendDataOnly(&fnum,sizeof(fnum));
|
||||
dataSocket->SendDataOnly(arg,MAX_STR_LENGTH);
|
||||
dataSocket->ReceiveDataOnly(&ret,sizeof(ret));
|
||||
if (ret==FAIL){
|
||||
dataSocket->ReceiveDataOnly(mess,sizeof(mess));
|
||||
std::cout<< "Receiver returned error: " << mess << std::endl;
|
||||
}else
|
||||
dataSocket->ReceiveDataOnly(retval,MAX_STR_LENGTH);
|
||||
}
|
||||
dataSocket->Disconnect();
|
||||
/*if (ret==FORCE_UPDATE)
|
||||
updateReceiver();*/
|
||||
}
|
||||
}
|
||||
|
||||
return string(retval);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
int slsDetector::setReceiverFileIndex(int fileIndex) {
|
||||
int fnum=F_SET_RECEIVER_FILE_INDEX;
|
||||
int ret = FAIL;
|
||||
char mess[100];
|
||||
int retval=-1;
|
||||
|
||||
int arg = fileIndex;
|
||||
|
||||
#ifdef VERBOSE
|
||||
std::cout << "Sending file dir to receiver " << arg << 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(mess,sizeof(mess));
|
||||
std::cout<< "Receiver returned error: " << mess << std::endl;
|
||||
}else
|
||||
dataSocket->ReceiveDataOnly(&retval,sizeof(retval));
|
||||
}
|
||||
dataSocket->Disconnect();
|
||||
/*if (ret==FORCE_UPDATE)
|
||||
updateReceiver();*/
|
||||
}
|
||||
}
|
||||
|
||||
return retval;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
int slsDetector::startReceiver(){
|
||||
int fnum=F_START_RECEIVER;
|
||||
int ret = FAIL;
|
||||
char mess[100];
|
||||
runStatus retval=ERROR;
|
||||
int arg[2];
|
||||
arg[1] = index;
|
||||
|
||||
//start=1,stop=0,get=-1
|
||||
arg[0] = -1;
|
||||
if(status=="start") arg[0] = 1;
|
||||
else if(status=="stop") arg[0] = 0;
|
||||
|
||||
|
||||
MySocketTCP *receiverSocket = new MySocketTCP(thisDetector->clientIP,thisDetector->dataPort);
|
||||
|
||||
if (receiverSocket->getErrorStatus()){
|
||||
#ifdef VERBOSE
|
||||
std::cout<< "Could not connect Control socket " << thisDetector->clientIP << " " << thisDetector->dataPort << std::endl;
|
||||
std::cout << "Starting Receiver " << std::endl;
|
||||
#endif
|
||||
delete receiverSocket;
|
||||
receiverSocket=NULL;
|
||||
}
|
||||
else{
|
||||
if(receiverSocket){
|
||||
if (receiverSocket->Connect()>=0){
|
||||
if (receiverSocket->SendDataOnly(&fnum,sizeof(fnum))>=0)
|
||||
if (receiverSocket->SendDataOnly(arg,sizeof(arg))>=0){
|
||||
receiverSocket->ReceiveDataOnly(&ret,sizeof(ret));
|
||||
if(ret!=FAIL){
|
||||
receiverSocket->ReceiveDataOnly(&retval,sizeof(retval));
|
||||
}
|
||||
else{
|
||||
receiverSocket->ReceiveDataOnly(mess,sizeof(mess));
|
||||
std::cout<< "Receiver returned error: " << mess << std::endl;
|
||||
}
|
||||
}
|
||||
receiverSocket->Disconnect();
|
||||
|
||||
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(mess,sizeof(mess));
|
||||
std::cout<< "Receiver returned error: " << mess << std::endl;
|
||||
}
|
||||
dataSocket->Disconnect();
|
||||
/*if (ret==FORCE_UPDATE)
|
||||
updateReceiver();*/
|
||||
}
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
int slsDetector::stopReceiver(){
|
||||
int fnum=F_STOP_RECEIVER;
|
||||
int ret = FAIL;
|
||||
char mess[100];
|
||||
|
||||
#ifdef VERBOSE
|
||||
std::cout << "Stopping 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(mess,sizeof(mess));
|
||||
std::cout<< "Receiver returned error: " << mess << std::endl;
|
||||
}
|
||||
|
||||
dataSocket->Disconnect();
|
||||
/*if (ret==FORCE_UPDATE)
|
||||
updateReceiver();*/
|
||||
}
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
slsDetectorDefs::runStatus slsDetector::getReceiverStatus(){
|
||||
int fnum=F_GET_RECEIVER_STATUS;
|
||||
int ret = FAIL;
|
||||
char mess[100];
|
||||
runStatus retval=ERROR;
|
||||
|
||||
#ifdef VERBOSE
|
||||
std::cout << "Getting Receiver Status" << 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(mess,sizeof(mess));
|
||||
std::cout<< "Receiver returned error: " << mess << std::endl;
|
||||
}else
|
||||
stopSocket->ReceiveDataOnly(&retval,sizeof(retval));
|
||||
|
||||
dataSocket->Disconnect();
|
||||
}
|
||||
else strcpy(thisDetector->clientIP,"none");
|
||||
delete receiverSocket;//should I include also for good connection? cuz setTCPSocket() still uses it?
|
||||
receiverSocket=NULL;//should I include also for good connection? cuz setTCPSocket() still uses it?
|
||||
}
|
||||
}
|
||||
/**if force update, updateReceiver?*/
|
||||
return retval;
|
||||
}
|
||||
|
||||
|
@ -304,11 +304,11 @@ slsDetectorCommand::slsDetectorCommand(slsDetectorUtils *det) {
|
||||
|
||||
/* communication configuration */
|
||||
|
||||
descrToFuncMap[i].m_pFuncName="clientip"; //
|
||||
descrToFuncMap[i].m_pFuncName="receiverip"; //
|
||||
descrToFuncMap[i].m_pFuncPtr=&slsDetectorCommand::cmdNetworkParameter;
|
||||
i++;
|
||||
|
||||
descrToFuncMap[i].m_pFuncName="clientmac"; //
|
||||
descrToFuncMap[i].m_pFuncName="receivermac"; //
|
||||
descrToFuncMap[i].m_pFuncPtr=&slsDetectorCommand::cmdNetworkParameter;
|
||||
i++;
|
||||
|
||||
@ -643,6 +643,15 @@ slsDetectorCommand::slsDetectorCommand(slsDetectorUtils *det) {
|
||||
descrToFuncMap[i].m_pFuncPtr=&slsDetectorCommand::cmdReceiver;
|
||||
i++;
|
||||
|
||||
descrToFuncMap[i].m_pFuncName="r_online";
|
||||
descrToFuncMap[i].m_pFuncPtr=&slsDetectorCommand::cmdOnline;
|
||||
i++;
|
||||
|
||||
descrToFuncMap[i].m_pFuncName="r_checkonline";
|
||||
descrToFuncMap[i].m_pFuncPtr=&slsDetectorCommand::cmdOnline;
|
||||
i++;
|
||||
|
||||
|
||||
|
||||
numberOfCommands=i;
|
||||
|
||||
@ -1288,14 +1297,26 @@ string slsDetectorCommand::helpTrimEn(int narg, char *args[], int action) {
|
||||
|
||||
|
||||
string slsDetectorCommand::cmdOutDir(int narg, char *args[], int action){
|
||||
bool receiver = false;
|
||||
|
||||
if (action==HELP_ACTION) {
|
||||
return helpOutDir(narg, args, action);
|
||||
}
|
||||
if (action==PUT_ACTION) {
|
||||
myDet->setFilePath(string(args[1]));
|
||||
}
|
||||
return string(myDet->getFilePath());
|
||||
if (action==HELP_ACTION) {
|
||||
return helpOutDir(narg, args, action);
|
||||
}
|
||||
|
||||
if(myDet->getNetworkParameter(RECEIVER_IP)!="none")
|
||||
if(myDet->setReceiverOnline(ONLINE_FLAG)==ONLINE_FLAG)
|
||||
receiver = true;
|
||||
|
||||
if (action==PUT_ACTION) {
|
||||
myDet->setFilePath(string(args[1]));
|
||||
if(receiver)
|
||||
myDet->setReceiverFileDir(string(args[1]));
|
||||
}
|
||||
|
||||
if(receiver)
|
||||
return myDet->setReceiverFileDir();
|
||||
else
|
||||
return string(myDet->getFilePath());
|
||||
}
|
||||
|
||||
|
||||
@ -1313,14 +1334,26 @@ string slsDetectorCommand::helpOutDir(int narg, char *args[], int action){
|
||||
|
||||
|
||||
string slsDetectorCommand::cmdFileName(int narg, char *args[], int action){
|
||||
bool receiver = false;
|
||||
|
||||
if (action==HELP_ACTION) {
|
||||
return helpFileName(narg, args, action);
|
||||
}
|
||||
if (action==PUT_ACTION) {
|
||||
myDet->setFileName(string(args[1]));
|
||||
}
|
||||
return string(myDet->getFileName());
|
||||
if (action==HELP_ACTION) {
|
||||
return helpFileName(narg, args, action);
|
||||
}
|
||||
|
||||
if(myDet->getNetworkParameter(RECEIVER_IP)!="none")
|
||||
if(myDet->setReceiverOnline(ONLINE_FLAG)==ONLINE_FLAG)
|
||||
receiver = true;
|
||||
|
||||
if (action==PUT_ACTION) {
|
||||
myDet->setFileName(string(args[1]));
|
||||
if(receiver)
|
||||
myDet->setReceiverFileName(string(args[1]));
|
||||
}
|
||||
|
||||
if(receiver)
|
||||
return myDet->setReceiverFileName();
|
||||
else
|
||||
return string(myDet->getFileName());
|
||||
}
|
||||
|
||||
|
||||
@ -1368,18 +1401,32 @@ string slsDetectorCommand::helpEnablefwrite(int narg, char *args[], int action){
|
||||
}
|
||||
|
||||
string slsDetectorCommand::cmdFileIndex(int narg, char *args[], int action){
|
||||
bool receiver = false;
|
||||
int i;
|
||||
char ans[100];
|
||||
|
||||
int i;
|
||||
char ans[100];
|
||||
if (action==HELP_ACTION) {
|
||||
return helpFileName(narg, args, action);
|
||||
}
|
||||
if (action==PUT_ACTION) {
|
||||
if (sscanf(args[1],"%d",&i))
|
||||
myDet->setFileIndex(i);
|
||||
}
|
||||
sprintf(ans,"%d", myDet->getFileIndex());
|
||||
return string(ans);
|
||||
if (action==HELP_ACTION) {
|
||||
return helpFileName(narg, args, action);
|
||||
}
|
||||
|
||||
if(myDet->getNetworkParameter(RECEIVER_IP)!="none")
|
||||
if(myDet->setReceiverOnline(ONLINE_FLAG)==ONLINE_FLAG)
|
||||
receiver = true;
|
||||
|
||||
if (action==PUT_ACTION) {
|
||||
if (sscanf(args[1],"%d",&i)){
|
||||
myDet->setFileIndex(i);
|
||||
if(receiver)
|
||||
myDet->setReceiverFileIndex(i);
|
||||
}
|
||||
}
|
||||
|
||||
if(receiver)
|
||||
sprintf(ans,"%d", myDet->setReceiverFileIndex());
|
||||
else
|
||||
sprintf(ans,"%d", myDet->getFileIndex());
|
||||
|
||||
return string(ans);
|
||||
}
|
||||
|
||||
|
||||
@ -2082,24 +2129,32 @@ string slsDetectorCommand::cmdNetworkParameter(int narg, char *args[], int actio
|
||||
|
||||
networkParameter t;
|
||||
|
||||
string fileName = myDet->getFilePath()+string("/")+myDet->getFileName()+string("_");
|
||||
|
||||
if (action==HELP_ACTION)
|
||||
return helpNetworkParameter(narg,args,action);
|
||||
|
||||
if (cmd=="clientip") {
|
||||
t=CLIENT_IP;
|
||||
} else if (cmd=="clientmac") {
|
||||
t=CLIENT_MAC;
|
||||
if (cmd=="receiverip") {
|
||||
t=RECEIVER_IP;
|
||||
} else if (cmd=="receivermac") {
|
||||
t=RECEIVER_MAC;
|
||||
} else if (cmd=="servermac") {
|
||||
t=SERVER_MAC;
|
||||
} else return ("unknown network parameter")+cmd;
|
||||
|
||||
if (action==PUT_ACTION){
|
||||
if(!strcmp(myDet->setNetworkParameter(t, args[1]),args[1])){
|
||||
if(t==CLIENT_IP)
|
||||
if(myDet->setupReceiver(fileName).empty())
|
||||
return string("could not set up receiver file name.");
|
||||
if(t==RECEIVER_IP){
|
||||
if(myDet->setReceiverOnline(ONLINE_FLAG)!=ONLINE_FLAG)
|
||||
return string("receiver not online");
|
||||
//outdir
|
||||
if(myDet->setReceiverFileDir(myDet->getFilePath())!=myDet->getFilePath())
|
||||
return string("could not set up receiver file outdir");
|
||||
//fname
|
||||
if(myDet->setReceiverFileName(myDet->getFileName())!=myDet->getFileName())
|
||||
return string("could not set up receiver file name");
|
||||
//index
|
||||
if(myDet->setReceiverFileIndex(myDet->getFileIndex())!=myDet->getFileIndex())
|
||||
return string("could not set up receiver file index");
|
||||
}
|
||||
}
|
||||
}
|
||||
return myDet->getNetworkParameter(t);
|
||||
@ -2112,14 +2167,14 @@ string slsDetectorCommand::helpNetworkParameter(int narg, char *args[], int acti
|
||||
|
||||
ostringstream os;
|
||||
if (action==PUT_ACTION || action==HELP_ACTION) {
|
||||
os << "clientip ip \n sets client ip to ip"<< std::endl;
|
||||
os << "clientmac mac \n sets client mac to mac"<< std::endl;
|
||||
os << "receiverip ip \n sets receiver ip to ip"<< std::endl;
|
||||
os << "receivermac mac \n sets receiver mac to mac"<< std::endl;
|
||||
os << "servermac mac \n sets server mac to mac"<< std::endl;
|
||||
|
||||
}
|
||||
if (action==GET_ACTION || action==HELP_ACTION) {
|
||||
os << "clientip \n gets client ip "<< std::endl;
|
||||
os << "clientmac \n gets client mac "<< std::endl;
|
||||
os << "receiverip \n gets receiver ip "<< std::endl;
|
||||
os << "receivermac \n gets receiver mac "<< std::endl;
|
||||
os << "servermac \n gets server mac "<< std::endl;
|
||||
}
|
||||
return os.str();
|
||||
@ -2250,31 +2305,50 @@ string slsDetectorCommand::helpLastClient(int narg, char *args[], int action) {
|
||||
|
||||
string slsDetectorCommand::cmdOnline(int narg, char *args[], int action) {
|
||||
|
||||
if (action==HELP_ACTION) {
|
||||
return helpOnline(narg,args,action);
|
||||
}
|
||||
int ival;
|
||||
char ans[1000];
|
||||
if (action==HELP_ACTION) {
|
||||
return helpOnline(narg,args,action);
|
||||
}
|
||||
int ival;
|
||||
char ans[1000];
|
||||
|
||||
if(cmd=="online"){
|
||||
if (action==PUT_ACTION) {
|
||||
if (sscanf(args[1],"%d",&ival))
|
||||
myDet->setOnline(ival);
|
||||
else
|
||||
return string("Could not scan online mode ")+string(args[1]);
|
||||
}
|
||||
sprintf(ans,"%d",myDet->setOnline());
|
||||
}//"checkonline"
|
||||
else{
|
||||
if (action==PUT_ACTION)
|
||||
return string("cannot set");
|
||||
strcpy(ans,myDet->checkOnline().c_str());
|
||||
if(!strlen(ans))
|
||||
strcpy(ans,"All online");
|
||||
else
|
||||
strcat(ans," :Not online");
|
||||
}
|
||||
return ans;
|
||||
if(cmd=="online"){
|
||||
if (action==PUT_ACTION) {
|
||||
if (sscanf(args[1],"%d",&ival))
|
||||
myDet->setOnline(ival);
|
||||
else
|
||||
return string("Could not scan online mode ")+string(args[1]);
|
||||
}
|
||||
sprintf(ans,"%d",myDet->setOnline());
|
||||
}
|
||||
else if(cmd=="checkonline"){
|
||||
if (action==PUT_ACTION)
|
||||
return string("cannot set");
|
||||
strcpy(ans,myDet->checkOnline().c_str());
|
||||
if(!strlen(ans))
|
||||
strcpy(ans,"All online");
|
||||
else
|
||||
strcat(ans," :Not online");
|
||||
}
|
||||
else if(cmd=="r_online"){
|
||||
if (action==PUT_ACTION) {
|
||||
if (sscanf(args[1],"%d",&ival))
|
||||
myDet->setReceiverOnline(ival);
|
||||
else
|
||||
return string("Could not scan online mode ")+string(args[1]);
|
||||
}
|
||||
sprintf(ans,"%d",myDet->setReceiverOnline());
|
||||
}
|
||||
else{
|
||||
if (action==PUT_ACTION)
|
||||
return string("cannot set");
|
||||
strcpy(ans,myDet->checkReceiverOnline().c_str());
|
||||
if(!strlen(ans))
|
||||
strcpy(ans,"All receiver online");
|
||||
else
|
||||
strcat(ans," :Not receiver online");
|
||||
}
|
||||
|
||||
return ans;
|
||||
}
|
||||
|
||||
string slsDetectorCommand::helpOnline(int narg, char *args[], int action) {
|
||||
@ -2282,11 +2356,13 @@ string slsDetectorCommand::helpOnline(int narg, char *args[], int action) {
|
||||
ostringstream os;
|
||||
if (action==PUT_ACTION || action==HELP_ACTION) {
|
||||
os << "online i \n sets the detector in online (1) or offline (0) mode"<< std::endl;
|
||||
|
||||
os << "r_online i \n sets the receiver in online (1) or offline (0) mode"<< std::endl;
|
||||
}
|
||||
if (action==GET_ACTION || action==HELP_ACTION) {
|
||||
os << "online \n gets the detector online (1) or offline (0) mode"<< std::endl;
|
||||
os << "checkonline \n returns the hostnames of all detectors in offline mode"<< std::endl;
|
||||
os << "r_online \n gets the receiver online (1) or offline (0) mode"<< std::endl;
|
||||
os << "r_checkonline \n returns the hostnames of all receiver in offline mode"<< std::endl;
|
||||
}
|
||||
return os.str();
|
||||
|
||||
@ -3393,23 +3469,38 @@ string slsDetectorCommand::helpConfiguration(int narg, char *args[], int action)
|
||||
|
||||
|
||||
string slsDetectorCommand::cmdReceiver(int narg, char *args[], int action) {
|
||||
runStatus s;
|
||||
if (action==HELP_ACTION)
|
||||
return helpReceiver(narg, args, action);
|
||||
|
||||
if(myDet->setReceiverOnline(ONLINE_FLAG)!=ONLINE_FLAG)
|
||||
return string("receiver not online");
|
||||
|
||||
if (action==PUT_ACTION) {
|
||||
if((strcasecmp(args[1],"start"))&&(strcasecmp(args[1],"stop")))
|
||||
return helpReceiver(narg, args, action);
|
||||
s = myDet->startReceiver(string(args[1]),myDet->getFileIndex());
|
||||
//increment index by 1 if stopped successfully
|
||||
if((!strcasecmp(args[1],"stop"))&&(s!=ERROR))
|
||||
myDet->setFileIndex(myDet->getFileIndex()+1);
|
||||
|
||||
if(strcasecmp(args[1],"start")){
|
||||
//update receiver index
|
||||
if(myDet->setReceiverFileIndex(myDet->getFileIndex())==-1)
|
||||
return string("could not set receiver file index");
|
||||
myDet->startReceiver();
|
||||
}
|
||||
|
||||
else if(strcasecmp(args[1],"stop")){
|
||||
if(myDet->stopReceiver()!=FAIL){
|
||||
//update index
|
||||
int index = myDet->setReceiverFileIndex();
|
||||
if(index==-1)
|
||||
return string("could not get receiver file index");
|
||||
myDet->setFileIndex(index);
|
||||
}
|
||||
}else
|
||||
return helpReceiver(narg, args, action);
|
||||
}
|
||||
|
||||
return myDet->runStatusType(myDet->startReceiver());
|
||||
return myDet->runStatusType(myDet->getReceiverStatus());
|
||||
}
|
||||
|
||||
|
||||
|
||||
string slsDetectorCommand::helpReceiver(int narg, char *args[], int action) {
|
||||
|
||||
ostringstream os;
|
||||
|
Loading…
x
Reference in New Issue
Block a user