checkOnline works properly now and calls tcpsocket if controlsocket not defined

git-svn-id: file:///afs/psi.ch/project/sls_det_software/svn/slsDetectorSoftware@245 951219d9-93cf-4727-9268-0efd64621fa3
This commit is contained in:
l_maliakal_d 2012-09-10 15:15:43 +00:00
parent 2cfdc2b108
commit 5cb68d870e
7 changed files with 62 additions and 35 deletions

View File

@ -885,19 +885,18 @@ int multiSlsDetector::setOnline(int off) {
int multiSlsDetector::checkOnline() { string multiSlsDetector::checkOnline() {
int ret1=-100,ret; string retval1 = "",retval;
for (int idet=0; idet<thisMultiDetector->numberOfDetectors; idet++) { for (int idet=0; idet<thisMultiDetector->numberOfDetectors; idet++) {
if (detectors[idet]) { if (detectors[idet]) {
ret=detectors[idet]->checkOnline(); retval=detectors[idet]->checkOnline();
cout<<"ret:"<<ret<<endl; if(!retval.empty()){
if (ret1==-100) retval1.append(retval);
ret1=ret; retval1.append("+");
else if (ret!=ret1) }
ret1=-1;
} }
} }
return ret1; return retval1;
}; };

View File

@ -360,7 +360,7 @@ class multiSlsDetector : public slsDetectorUtils {
/** checks if each of the detectors are online /** checks if each of the detectors are online
\returns online/offline status and -1 if any of the detector's online status is different from the other \returns online/offline status and -1 if any of the detector's online status is different from the other
*/ */
int checkOnline(); string checkOnline();
/** /**

View File

@ -1,4 +1,3 @@
#include "slsDetector.h" #include "slsDetector.h"
#include "usersFunctions.h" #include "usersFunctions.h"
#include "slsDetectorCommand.h" #include "slsDetectorCommand.h"
@ -908,26 +907,35 @@ int slsDetector::setOnline(int off) {
int slsDetector::checkOnline() { string slsDetector::checkOnline() {
int retval=ONLINE_FLAG; string retval = "";
if(!controlSocket) if(!controlSocket){
controlSocket= new MySocketTCP(thisDetector->hostname, thisDetector->controlPort); //this already sets the online/offline flag
if (controlSocket->Connect()<0) { setTCPSocket();
controlSocket->SetTimeOut(5); if(thisDetector->onlineFlag==OFFLINE_FLAG)
thisDetector->onlineFlag=OFFLINE_FLAG; return string(thisDetector->hostname);
delete controlSocket; else
controlSocket=NULL; return string("");
retval=OFFLINE_FLAG; }
//still cannot connect to socket, controlSocket=0
if(controlSocket){
if (controlSocket->Connect()<0) {
controlSocket->SetTimeOut(5);
thisDetector->onlineFlag=OFFLINE_FLAG;
delete controlSocket;
controlSocket=NULL;
retval = thisDetector->hostname;
#ifdef VERBOSE #ifdef VERBOSE
std::cout<< "offline!" << std::endl; std::cout<< "offline!" << std::endl;
#endif #endif
} else { } else {
thisDetector->onlineFlag=ONLINE_FLAG; thisDetector->onlineFlag=ONLINE_FLAG;
controlSocket->SetTimeOut(100); controlSocket->SetTimeOut(100);
controlSocket->Disconnect(); controlSocket->Disconnect();
#ifdef VERBOSE #ifdef VERBOSE
std::cout<< "online!" << std::endl; std::cout<< "online!" << std::endl;
#endif #endif
}
} }
return retval; return retval;
} }
@ -970,7 +978,7 @@ int slsDetector::setTCPSocket(string const name, int const control_port, int con
} }
} else } else
strcpy(thisName,thisDetector->hostname); strcpy(thisName,thisDetector->hostname);
if (control_port>0) { if (control_port>0) {
#ifdef VERBOSE #ifdef VERBOSE
std::cout<< "setting control port" << std::endl; std::cout<< "setting control port" << std::endl;

View File

@ -284,7 +284,7 @@ typedef struct sharedSlsDetector {
int setOnline(int const online=GET_ONLINE_FLAG); int setOnline(int const online=GET_ONLINE_FLAG);
int checkOnline(); string checkOnline();
/** returns if the detector already existed /** returns if the detector already existed
\returns 1 if the detector structure has already be initlialized, 0 otherwise */ \returns 1 if the detector structure has already be initlialized, 0 otherwise */

View File

@ -183,6 +183,10 @@ slsDetectorCommand::slsDetectorCommand(slsDetectorUtils *det) {
descrToFuncMap[i].m_pFuncPtr=&slsDetectorCommand::cmdOnline; descrToFuncMap[i].m_pFuncPtr=&slsDetectorCommand::cmdOnline;
i++; i++;
descrToFuncMap[i].m_pFuncName="checkonline"; //
descrToFuncMap[i].m_pFuncPtr=&slsDetectorCommand::cmdOnline;
i++;
descrToFuncMap[i].m_pFuncName="enablefwrite"; // descrToFuncMap[i].m_pFuncName="enablefwrite"; //
descrToFuncMap[i].m_pFuncPtr=&slsDetectorCommand::cmdEnablefwrite; descrToFuncMap[i].m_pFuncPtr=&slsDetectorCommand::cmdEnablefwrite;
i++; i++;
@ -2233,13 +2237,23 @@ string slsDetectorCommand::cmdOnline(int narg, char *args[], int action) {
} }
int ival; int ival;
char ans[1000]; char ans[1000];
if (action==PUT_ACTION) {
if (sscanf(args[1],"%d",&ival)) if(cmd=="online"){
myDet->setOnline(ival); if (action==PUT_ACTION) {
else if (sscanf(args[1],"%d",&ival))
return string("Could not scan online mode ")+string(args[1]); myDet->setOnline(ival);
else
return string("Could not scan online mode ")+string(args[1]);
}
sprintf(ans,"%d",myDet->setOnline());
}//"checkonline"
else{
strcpy(ans,myDet->checkOnline().c_str());
if(!strlen(ans))
strcpy(ans,"All online");
else
strcat(ans," :not online");
} }
sprintf(ans,"%d",myDet->setOnline());
return ans; return ans;
} }

View File

@ -194,6 +194,12 @@ class slsDetectorUtils : public slsDetectorActions, public postProcessing {
virtual int64_t getId(idMode mode, int imod=0)=0; virtual int64_t getId(idMode mode, int imod=0)=0;
/** /**
checks if the detector(s) are online/offline
\returns hostname if offline
*/
virtual string checkOnline()=0;
/**
Digital test of the modules Digital test of the modules
\param mode test mode \param mode test mode
\param imod module number for chip test or module firmware test \param imod module number for chip test or module firmware test