mirror of
https://github.com/slsdetectorgroup/slsDetectorPackage.git
synced 2026-01-17 04:07:46 +01:00
slsReceiver, slsDetector, eiger and jungfrau server: client checks firmware and software an dreceiver compatibility for each time shared memory is cleaned up
This commit is contained in:
@@ -10,6 +10,8 @@
|
||||
#include <cstdlib>
|
||||
#include <math.h>
|
||||
#include "gitInfoLib.h"
|
||||
#include "versionAPI.h"
|
||||
|
||||
|
||||
using namespace std;
|
||||
int slsDetector::initSharedMemory(detectorType type, int id) {
|
||||
@@ -806,6 +808,10 @@ int slsDetector::initializeDetectorSize(detectorType type) {
|
||||
thisDetector->receiver_read_freq = 0;
|
||||
thisDetector->receiver_framesPerFile = -1;
|
||||
|
||||
thisDetector->detectorControlAPIVersion = 0;
|
||||
thisDetector->detectorStopAPIVersion = 0;
|
||||
thisDetector->receiverAPIVersion = 0;
|
||||
|
||||
for (int ia=0; ia<MAX_ACTIONS; ++ia) {
|
||||
strcpy(thisDetector->actionScript[ia],"none");
|
||||
strcpy(thisDetector->actionParameter[ia],"none");
|
||||
@@ -1430,7 +1436,6 @@ int slsDetector::activate(int const enable){
|
||||
*/
|
||||
|
||||
int slsDetector::setTCPSocket(string const name, int const control_port, int const stop_port){
|
||||
|
||||
char thisName[MAX_STR_LENGTH];
|
||||
int thisCP, thisSP;
|
||||
int retval=OK;
|
||||
@@ -1511,6 +1516,22 @@ int slsDetector::setTCPSocket(string const name, int const control_port, int con
|
||||
}
|
||||
if (retval!=FAIL) {
|
||||
checkOnline();
|
||||
|
||||
// check for version compatibility
|
||||
switch (thisDetector->myDetectorType) {
|
||||
case EIGER:
|
||||
case JUNGFRAU:
|
||||
case GOTTHARD:
|
||||
if ((thisDetector->detectorControlAPIVersion == 0) ||
|
||||
(thisDetector->detectorStopAPIVersion == 0)) {
|
||||
if (checkVersionCompatibility(CONTROL_PORT) == FAIL)
|
||||
thisDetector->onlineFlag=OFFLINE_FLAG;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
} else {
|
||||
thisDetector->onlineFlag=OFFLINE_FLAG;
|
||||
#ifdef VERBOSE
|
||||
@@ -8364,15 +8385,28 @@ int slsDetector::setReceiverTCPSocket(string const name, int const receiver_port
|
||||
}
|
||||
//check if it connects
|
||||
if (retval!=FAIL) {
|
||||
if(checkReceiverOnline().empty())
|
||||
retval=FAIL;
|
||||
checkReceiverOnline();
|
||||
thisReceiver->setSocket(dataSocket);
|
||||
// check for version compatibility
|
||||
switch (thisDetector->myDetectorType) {
|
||||
case EIGER:
|
||||
case JUNGFRAU:
|
||||
case GOTTHARD:
|
||||
if (thisDetector->receiverAPIVersion == 0){
|
||||
if (checkVersionCompatibility(DATA_PORT) == FAIL)
|
||||
thisDetector->receiverOnlineFlag=OFFLINE_FLAG;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
} else {
|
||||
thisDetector->receiverOnlineFlag=OFFLINE_FLAG;
|
||||
#ifdef VERBOSE
|
||||
std::cout<< "offline!" << std::endl;
|
||||
#endif
|
||||
}
|
||||
thisReceiver->setSocket(dataSocket);
|
||||
return retval;
|
||||
};
|
||||
|
||||
@@ -9821,3 +9855,99 @@ int slsDetector::restreamStopFromReceiver(){
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
int slsDetector::checkVersionCompatibility(portType t) {
|
||||
int fnum = F_CHECK_VERSION;
|
||||
if (t == DATA_PORT)
|
||||
fnum = F_RECEIVER_CHECK_VERSION;
|
||||
int ret = FAIL;
|
||||
char mess[MAX_STR_LENGTH];
|
||||
memset(mess, 0, MAX_STR_LENGTH);
|
||||
int64_t arg = 0;
|
||||
|
||||
// detector
|
||||
if (t == CONTROL_PORT) {
|
||||
|
||||
switch (thisDetector->myDetectorType) {
|
||||
case EIGER: arg = APIEIGER; break;
|
||||
case JUNGFRAU: arg = APIJUNGFRAU; break;
|
||||
case GOTTHARD: arg = APIGOTTHARD; break;
|
||||
default:
|
||||
std::cout<< "Check version compatibility is not implemented for this detector" << std::endl;
|
||||
setErrorMask((getErrorMask())|(VERSION_COMPATIBILITY));
|
||||
return FAIL;
|
||||
}
|
||||
|
||||
#ifdef VERBOSE
|
||||
std::cout<< std::endl<< "Checking version compatibility with detector with value " << hex << arg << std::endl;
|
||||
#endif
|
||||
if (thisDetector->onlineFlag==ONLINE_FLAG) {
|
||||
// control port
|
||||
if (connectControl() == OK){
|
||||
controlSocket->SendDataOnly(&fnum,sizeof(fnum));
|
||||
controlSocket->SendDataOnly(&arg,sizeof(arg));
|
||||
controlSocket->ReceiveDataOnly(&ret,sizeof(ret));
|
||||
if (ret == FAIL) {
|
||||
controlSocket->ReceiveDataOnly(mess,sizeof(mess));
|
||||
cprintf(RED, "Detector returned error: (Control Server) %s", mess);
|
||||
if(strstr(mess,"Unrecognized Function")!=NULL)
|
||||
std::cout << "The detector server is too old to get API version. Please update detector server!" << std::endl;
|
||||
setErrorMask((getErrorMask())|(VERSION_COMPATIBILITY));
|
||||
thisDetector->detectorControlAPIVersion = 0;
|
||||
} else {
|
||||
thisDetector->detectorControlAPIVersion = arg;
|
||||
}
|
||||
disconnectControl();
|
||||
}
|
||||
if (ret!= FAIL) {
|
||||
ret = FAIL;
|
||||
|
||||
// stop port
|
||||
if (connectStop() == OK){
|
||||
stopSocket->SendDataOnly(&fnum,sizeof(fnum));
|
||||
stopSocket->SendDataOnly(&arg,sizeof(arg));
|
||||
stopSocket->ReceiveDataOnly(&ret,sizeof(ret));
|
||||
if (ret == FAIL) {
|
||||
stopSocket->ReceiveDataOnly(mess,sizeof(mess));
|
||||
cprintf(RED, "Detector returned error: (Stop Server) %s", mess);
|
||||
if(strstr(mess,"Unrecognized Function")!=NULL)
|
||||
std::cout << "The detector server is too old to get API version. Please update detector server!" << std::endl;
|
||||
setErrorMask((getErrorMask())|(VERSION_COMPATIBILITY));
|
||||
thisDetector->detectorStopAPIVersion = 0;
|
||||
} else {
|
||||
thisDetector->detectorStopAPIVersion = arg;
|
||||
}
|
||||
disconnectStop();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// receiver
|
||||
else {
|
||||
arg = APIRECEIVER;
|
||||
#ifdef VERBOSE
|
||||
std::cout<< std::endl<< "Checking version compatibility with receiver with value " << hex << arg << std::endl;
|
||||
#endif
|
||||
if (thisDetector->receiverOnlineFlag==ONLINE_FLAG) {
|
||||
// data port
|
||||
if (connectData() == OK){
|
||||
// ignoring retval
|
||||
int64_t retval = -1;
|
||||
ret=thisReceiver->sendInt(fnum,retval,arg);
|
||||
if (ret==FAIL){
|
||||
setErrorMask((getErrorMask())|(VERSION_COMPATIBILITY));
|
||||
if(strstr(mess,"Unrecognized Function")!=NULL)
|
||||
std::cout << "The receiver software is too old to get API version. Please update receiver software!" << std::endl;
|
||||
thisDetector->receiverAPIVersion = 0;
|
||||
} else {
|
||||
thisDetector->receiverAPIVersion = arg;
|
||||
}
|
||||
disconnectData();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
@@ -290,11 +290,12 @@ class slsDetector : public slsDetectorUtils, public energyConversion {
|
||||
/** frames per file in receiver */
|
||||
int receiver_framesPerFile;
|
||||
|
||||
/** detector software API version */
|
||||
int detector_software_api_version;
|
||||
|
||||
/** receiver API version */
|
||||
int receiver_api_version;
|
||||
/** detector control server software API version */
|
||||
int64_t detectorControlAPIVersion;
|
||||
/** detector stop server software API version */
|
||||
int64_t detectorStopAPIVersion;
|
||||
/** receiver server software API version */
|
||||
int64_t receiverAPIVersion;
|
||||
|
||||
|
||||
} sharedSlsDetector;
|
||||
@@ -2059,6 +2060,14 @@ class slsDetector : public slsDetectorUtils, public energyConversion {
|
||||
*/
|
||||
int restreamStopFromReceiver();
|
||||
|
||||
/**
|
||||
* Check version compatibility with detector/receiver software
|
||||
* (if hostname/rx_hostname has been set/ sockets created)
|
||||
* \param p port type control port or receiver port
|
||||
* \returns FAIL for incompatibility, OK for compatibility
|
||||
*/
|
||||
int checkVersionCompatibility(portType t);
|
||||
|
||||
|
||||
protected:
|
||||
|
||||
|
||||
@@ -507,6 +507,22 @@ slsDetectorCommand::slsDetectorCommand(slsDetectorUtils *det) {
|
||||
Commands to check versions of each subsystem
|
||||
*/
|
||||
|
||||
/*! \page config
|
||||
- <b>checkdetversion</b> Checks the version compatibility with detector software (if hostname is in shared memory). Only get! Only for Eiger, Jungfrau & Gotthard. \c Returns \c ("compatible", "incompatible")
|
||||
*/
|
||||
descrToFuncMap[i].m_pFuncName="checkdetversion"; //
|
||||
descrToFuncMap[i].m_pFuncPtr=&slsDetectorCommand::cmdSN;
|
||||
++i;
|
||||
|
||||
|
||||
/*! \page config
|
||||
- <b>checkrecversion</b> Checks the version compatibility with receiver software (if rx_hostname is in shared memory). Only get! Only for Eiger, Jungfrau & Gotthard. \c Returns \c ("compatible", "incompatible")
|
||||
*/
|
||||
descrToFuncMap[i].m_pFuncName="checkrecversion"; //
|
||||
descrToFuncMap[i].m_pFuncPtr=&slsDetectorCommand::cmdSN;
|
||||
++i;
|
||||
|
||||
|
||||
/*! \page config
|
||||
- <b>moduleversion:[i]</b> Gets the firmware version of module i. Used for MYTHEN only. Only get! \c Returns \c (long int) in hexadecimal or "undefined module number"
|
||||
*/
|
||||
@@ -4895,6 +4911,24 @@ string slsDetectorCommand::cmdSN(int narg, char *args[], int action) {
|
||||
sprintf(answer,"0x%lx", retval);
|
||||
return string(answer);
|
||||
}
|
||||
|
||||
if (cmd=="checkdetversion") {
|
||||
int retval = myDet->checkVersionCompatibility(CONTROL_PORT);
|
||||
if (retval < 0)
|
||||
sprintf(answer, "%d", -1);
|
||||
sprintf(answer,"%s", retval == OK ? "compatible" : "incompatible");
|
||||
return string(answer);
|
||||
}
|
||||
|
||||
if (cmd=="checkrecversion") {
|
||||
myDet->setReceiverOnline(ONLINE_FLAG);
|
||||
int retval = myDet->checkVersionCompatibility(DATA_PORT);
|
||||
if (retval < 0)
|
||||
sprintf(answer, "%d", -1);
|
||||
sprintf(answer,"%s", retval == OK ? "compatible" : "incompatible");
|
||||
return string(answer);
|
||||
}
|
||||
|
||||
return string("unknown id mode ")+cmd;
|
||||
|
||||
}
|
||||
@@ -4903,6 +4937,8 @@ string slsDetectorCommand::helpSN(int narg, char *args[], int action) {
|
||||
|
||||
ostringstream os;
|
||||
if (action==GET_ACTION || action==HELP_ACTION) {
|
||||
os << "checkdetversion \n gets the version compatibility with detector software (if hostname is in shared memory). Only for Eiger, Jungfrau & Gotthard. Prints compatible/ incompatible."<< std::endl;
|
||||
os << "checkrecversion \n gets the version compatibility with receiver software (if rx_hostname is in shared memory). Only for Eiger, Jungfrau & Gotthard. Prints compatible/ incompatible."<< std::endl;
|
||||
os << "moduleversion:i \n gets the firmwareversion of the module i"<< std::endl;
|
||||
os << "modulenumber:i \n gets the serial number of the module i"<< std::endl;
|
||||
os << "detectornumber \n gets the serial number of the detector (MAC)"<< std::endl;
|
||||
|
||||
@@ -1029,6 +1029,14 @@ virtual int setReceiverSilentMode(int i = -1)=0;
|
||||
virtual bool isAcquireReady() = 0;
|
||||
|
||||
|
||||
/**
|
||||
* Check version compatibility with detector/receiver software
|
||||
* (if hostname/rx_hostname has been set/ sockets created)
|
||||
* \param p port type control port or data (receiver) port
|
||||
* \returns FAIL for incompatibility, OK for compatibility
|
||||
*/
|
||||
virtual int checkVersionCompatibility(portType t) = 0;
|
||||
|
||||
protected:
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user