diff --git a/slsDetectorSoftware/commonFiles/error_defs.h b/slsDetectorSoftware/commonFiles/error_defs.h index 740125b06..880a9e154 100644 --- a/slsDetectorSoftware/commonFiles/error_defs.h +++ b/slsDetectorSoftware/commonFiles/error_defs.h @@ -51,6 +51,7 @@ #define PREPARE_ACQUISITION 0x0000100000000000ULL #define CLEANUP_ACQUISITION 0x0000080000000000ULL #define REGISER_WRITE_READ 0x0000040000000000ULL +#define VERSION_COMPATIBILITY 0x0000020000000000ULL // 0xFFFFFF0000000000ULL // 0x000000FFFFFFFFFFULL @@ -170,6 +171,9 @@ public: if(slsErrorMask®ISER_WRITE_READ) retval.append("Could not read/write register in detector\n"); + if(slsErrorMask&VERSION_COMPATIBILITY) + retval.append("Incompatible versions with detector or receiver. Please check log for more details.\n"); + if(slsErrorMask&COULD_NOT_CONFIGURE_MAC) diff --git a/slsDetectorSoftware/commonFiles/sls_detector_defs.h b/slsDetectorSoftware/commonFiles/sls_detector_defs.h index 465ee4956..292a2f415 100755 --- a/slsDetectorSoftware/commonFiles/sls_detector_defs.h +++ b/slsDetectorSoftware/commonFiles/sls_detector_defs.h @@ -291,7 +291,9 @@ enum idMode{ DETECTOR_SOFTWARE_VERSION, /** REQUIRED_FIRMWARE_VERSION){ - cprintf(RED,"FATAL ERROR: This software version is incompatible.\n" - "Please update it to be compatible with this firmware\n\n"); - cprintf(RED,"Exiting Server. Goodbye!\n\n"); - exit(-1); + sprintf(firmware_message, + "FATAL ERROR: This detector software software version (%lld) is incompatible.\n" + "Please update detector software (min. %lld) to be compatible with this firmware.\n", + (long long int)sw_fw_apiversion, + (long long int)REQUIRED_FIRMWARE_VERSION); + cprintf(RED,"%s\n\n", firmware_message); + firmware_compatibility = FAIL; + firmware_check_done = 1; + return; } //check for firmware compatibility - old firmware if( REQUIRED_FIRMWARE_VERSION > fwversion){ - cprintf(RED,"FATAL ERROR: This firmware version is incompatible.\n" - "Please update it to v%d to be compatible with this server\n\n", REQUIRED_FIRMWARE_VERSION); - cprintf(RED,"Exiting Server. Goodbye!\n\n"); - exit(-1); + sprintf(firmware_message, + "FATAL ERROR: This firmware version (%lld) is incompatible.\n" + "Please update firmware (min. %lld) to be compatible with this server.\n", + (long long int)fwversion, + (long long int)REQUIRED_FIRMWARE_VERSION); + cprintf(RED,"%s\n\n", firmware_message); + firmware_compatibility = FAIL; + firmware_check_done = 1; + return; } + printf("Compatibility - success\n"); + firmware_check_done = 1; } @@ -175,6 +215,8 @@ int64_t getDetectorId(enum idMode arg){ return (int64_t)Beb_GetFirmwareSoftwareAPIVersion(); case DETECTOR_SOFTWARE_VERSION: return (GITDATE & 0xFFFFFF); + case CLIENT_SOFTWARE_API_VERSION: + return APIEIGER; default: break; } diff --git a/slsDetectorSoftware/eigerDetectorServer/updateAPIVersion.sh b/slsDetectorSoftware/eigerDetectorServer/updateAPIVersion.sh index 2dbea8493..618a9b601 100755 --- a/slsDetectorSoftware/eigerDetectorServer/updateAPIVersion.sh +++ b/slsDetectorSoftware/eigerDetectorServer/updateAPIVersion.sh @@ -1,7 +1,7 @@ SRCFILE=gitInfoEiger.h -DSTFILE=../commonFiles/versionAPI.h +DSTFILE=versionAPI.h SRCPATTERN=GITDATE DSTPATTERN=APIEIGER -awk -v a="$SRCFILE" -v b="$DSTFILE" -v c="$SRCPATTERN" -v d="$DSTPATTERN" 'FNR==NR&&$2==c{x=$3} NR!=FNR{if($2==d){$3=x}print > b}' $SRCFILE $DSTFILE \ No newline at end of file +awk -v a="$SRCFILE" -v b="$DSTFILE" -v c="$SRCPATTERN" -v d="$DSTPATTERN" 'FNR==NR&&$2==c{x=$3} NR!=FNR{if($2==d){$3="0x"substr(x,5)}print > b}' $SRCFILE $DSTFILE \ No newline at end of file diff --git a/slsDetectorSoftware/eigerDetectorServer/versionAPI.h b/slsDetectorSoftware/eigerDetectorServer/versionAPI.h new file mode 120000 index 000000000..d3bf8d6cf --- /dev/null +++ b/slsDetectorSoftware/eigerDetectorServer/versionAPI.h @@ -0,0 +1 @@ +../commonFiles/versionAPI.h \ No newline at end of file diff --git a/slsDetectorSoftware/gotthardDetectorServer/updateAPIVersion.sh b/slsDetectorSoftware/gotthardDetectorServer/updateAPIVersion.sh index 3d1b12d3a..2d5d8d04d 100755 --- a/slsDetectorSoftware/gotthardDetectorServer/updateAPIVersion.sh +++ b/slsDetectorSoftware/gotthardDetectorServer/updateAPIVersion.sh @@ -1,7 +1,7 @@ SRCFILE=gitInfoGotthard.h -DSTFILE=../commonFiles/versionAPI.h +DSTFILE=versionAPI.h SRCPATTERN=GITDATE DSTPATTERN=APIGOTTHARD -awk -v a="$SRCFILE" -v b="$DSTFILE" -v c="$SRCPATTERN" -v d="$DSTPATTERN" 'FNR==NR&&$2==c{x=$3} NR!=FNR{if($2==d){$3=x}print > b}' $SRCFILE $DSTFILE \ No newline at end of file +awk -v a="$SRCFILE" -v b="$DSTFILE" -v c="$SRCPATTERN" -v d="$DSTPATTERN" 'FNR==NR&&$2==c{x=$3} NR!=FNR{if($2==d){$3="0x"substr(x,5)}print > b}' $SRCFILE $DSTFILE \ No newline at end of file diff --git a/slsDetectorSoftware/gotthardDetectorServer/versionAPI.h b/slsDetectorSoftware/gotthardDetectorServer/versionAPI.h new file mode 120000 index 000000000..d3bf8d6cf --- /dev/null +++ b/slsDetectorSoftware/gotthardDetectorServer/versionAPI.h @@ -0,0 +1 @@ +../commonFiles/versionAPI.h \ No newline at end of file diff --git a/slsDetectorSoftware/jungfrauDetectorServer/bin/jungfrauDetectorServer_developer b/slsDetectorSoftware/jungfrauDetectorServer/bin/jungfrauDetectorServer_developer index c47cd1c9a..a3822e486 100755 Binary files a/slsDetectorSoftware/jungfrauDetectorServer/bin/jungfrauDetectorServer_developer and b/slsDetectorSoftware/jungfrauDetectorServer/bin/jungfrauDetectorServer_developer differ diff --git a/slsDetectorSoftware/jungfrauDetectorServer/gitInfo.txt b/slsDetectorSoftware/jungfrauDetectorServer/gitInfo.txt index 9afd00334..251eb1723 100644 --- a/slsDetectorSoftware/jungfrauDetectorServer/gitInfo.txt +++ b/slsDetectorSoftware/jungfrauDetectorServer/gitInfo.txt @@ -1,9 +1,9 @@ Path: slsDetectorsPackage/slsDetectorSoftware/jungfrauDetectorServer URL: origin git@github.com:slsdetectorgroup/slsDetectorPackage.git Repository Root: origin git@github.com:slsdetectorgroup/slsDetectorPackage.git -Repsitory UUID: cb635d800a5e1de6cf3330f03a98ffc382879cf3 -Revision: 151 -Branch: mergevirtual +Repsitory UUID: 4d4e4a4ce7a91af094251ed0903575ba7e73ef5f +Revision: 153 +Branch: versioning Last Changed Author: Dhanya_Thattil -Last Changed Rev: 3832 -Last Changed Date: 2018-05-23 14:42:26.000000002 +0200 ./Makefile.virtual +Last Changed Rev: 3847 +Last Changed Date: 2018-05-28 18:02:50.000000002 +0200 ./RegisterDefs.h diff --git a/slsDetectorSoftware/jungfrauDetectorServer/gitInfoJungfrau.h b/slsDetectorSoftware/jungfrauDetectorServer/gitInfoJungfrau.h index 5f8f69d4f..4b229b7c6 100644 --- a/slsDetectorSoftware/jungfrauDetectorServer/gitInfoJungfrau.h +++ b/slsDetectorSoftware/jungfrauDetectorServer/gitInfoJungfrau.h @@ -1,6 +1,6 @@ #define GITURL "git@github.com:slsdetectorgroup/slsDetectorPackage.git" -#define GITREPUUID "cb635d800a5e1de6cf3330f03a98ffc382879cf3" +#define GITREPUUID "4d4e4a4ce7a91af094251ed0903575ba7e73ef5f" #define GITAUTH "Dhanya_Thattil" -#define GITREV 0x3832 -#define GITDATE 0x20180523 -#define GITBRANCH "mergevirtual" +#define GITREV 0x3847 +#define GITDATE 0x20180528 +#define GITBRANCH "versioning" diff --git a/slsDetectorSoftware/jungfrauDetectorServer/slsDetectorFunctionList.c b/slsDetectorSoftware/jungfrauDetectorServer/slsDetectorFunctionList.c index 5f0449d8b..1fba10512 100644 --- a/slsDetectorSoftware/jungfrauDetectorServer/slsDetectorFunctionList.c +++ b/slsDetectorSoftware/jungfrauDetectorServer/slsDetectorFunctionList.c @@ -5,7 +5,7 @@ #include "gitInfoJungfrau.h" #include "AD9257.h" // include "commonServerFunctions.h", which in turn includes "blackfin.h" #include "programfpga.h" - +#include "versionAPI.h" #ifdef VIRTUAL #include @@ -33,6 +33,19 @@ int virtual_stop = 0; /* basic tests */ +int firmware_compatibility = OK; +int firmware_check_done = 0; +char firmware_message[MAX_STR_LENGTH]; + +int isFirmwareCheckDone() { + return firmware_check_done; +} + +int getFirmwareCheckResult(char** mess) { + *mess = firmware_message; + return firmware_compatibility; +} + void checkFirmwareCompatibility(int flag) { #ifdef VIRTUAL cprintf(BLUE,"\n\n" @@ -40,23 +53,36 @@ void checkFirmwareCompatibility(int flag) { "************** Jungfrau Virtual Server *****************\n" "********************************************************\n\n"); if (mapCSP0() == FAIL) { - cprintf(BG_RED, "Dangerous to continue. Goodbye!\n"); - exit(EXIT_FAILURE); + strcpy(firmware_message, + "FATAL ERROR: Could not map to memory. Dangerous to continue.\n"); + cprintf(RED,"%s\n\n", firmware_message); + firmware_compatibility = FAIL; + firmware_check_done = 1; + return; } + firmware_check_done = 1; return; #endif defineGPIOpins(); resetFPGA(); if (mapCSP0() == FAIL) { - cprintf(BG_RED, "Dangerous to continue. Goodbye!\n"); - exit(EXIT_FAILURE); + strcpy(firmware_message, + "FATAL ERROR: Could not map to memory. Dangerous to continue.\n"); + cprintf(RED,"%s\n\n", firmware_message); + firmware_compatibility = FAIL; + firmware_check_done = 1; + return; } // does check only if flag is 0 (by default), set by command line if ((!flag) && ((checkType() == FAIL) || (testFpga() == FAIL) || (testBus() == FAIL))) { - cprintf(BG_RED, "Dangerous to continue. Goodbye!\n"); - exit(EXIT_FAILURE); + strcpy(firmware_message, + "FATAL ERROR: Could not pass basic tests of FPGA and bus. Dangerous to continue.\n"); + cprintf(RED,"%s\n\n", firmware_message); + firmware_compatibility = FAIL; + firmware_check_done = 1; + return; } uint16_t hversion = getHardwareVersionNumber(); @@ -66,6 +92,9 @@ void checkFirmwareCompatibility(int flag) { int64_t fwversion = getDetectorId(DETECTOR_FIRMWARE_VERSION); int64_t swversion = getDetectorId(DETECTOR_SOFTWARE_VERSION); int64_t sw_fw_apiversion = 0; + int64_t client_sw_apiversion = getDetectorId(CLIENT_SOFTWARE_API_VERSION); + + if (fwversion >= MIN_REQRD_VRSN_T_RD_API) sw_fw_apiversion = getDetectorId(SOFTWARE_FIRMWARE_API_VERSION); cprintf(BLUE,"\n\n" @@ -82,6 +111,7 @@ void checkFirmwareCompatibility(int flag) { "Software Version:\t\t 0x%llx\n" "F/w-S/w API Version:\t\t 0x%llx\n" "Required Firmware Version:\t 0x%x\n" + "Client-Software API Version:\t 0x%llx\n" "\n" "********************************************************\n", hversion, hsnumber, @@ -90,38 +120,55 @@ void checkFirmwareCompatibility(int flag) { (long long int)fwversion, (long long int)swversion, (long long int)sw_fw_apiversion, - REQRD_FRMWR_VRSN + REQRD_FRMWR_VRSN, + (long long int)client_sw_apiversion ); // return if flag is not zero, debug mode - if (flag) - return; + if (flag) { + firmware_check_done = 1; + return; + } //cant read versions printf("Testing Firmware-software compatibility ...\n"); if(!fwversion || !sw_fw_apiversion){ - cprintf(RED,"FATAL ERROR: Cant read versions from FPGA. Please update firmware\n"); - cprintf(RED,"Exiting Server. Goodbye!\n\n"); - exit(EXIT_FAILURE); + strcpy(firmware_message, + "FATAL ERROR: Cant read versions from FPGA. Please update firmware.\n"); + cprintf(RED,"%s\n\n", firmware_message); + firmware_compatibility = FAIL; + firmware_check_done = 1; + return; } //check for API compatibility - old server if(sw_fw_apiversion > REQRD_FRMWR_VRSN){ - cprintf(RED,"FATAL ERROR: This software version is incompatible.\n" - "Please update it to be compatible with this firmware\n\n"); - cprintf(RED,"Exiting Server. Goodbye!\n\n"); - exit(EXIT_FAILURE); + sprintf(firmware_message, + "FATAL ERROR: This detector software software version (0x%llx) is incompatible.\n" + "Please update detector software (min. 0x%llx) to be compatible with this firmware.\n", + (long long int)sw_fw_apiversion, + (long long int)REQRD_FRMWR_VRSN); + cprintf(RED,"%s\n\n", firmware_message); + firmware_compatibility = FAIL; + firmware_check_done = 1; + return; } //check for firmware compatibility - old firmware if( REQRD_FRMWR_VRSN > fwversion){ - cprintf(RED,"FATAL ERROR: This firmware version is incompatible.\n" - "Please update it to v%d to be compatible with this server\n\n", REQRD_FRMWR_VRSN); - cprintf(RED,"Exiting Server. Goodbye!\n\n"); - exit(EXIT_FAILURE); + sprintf(firmware_message, + "FATAL ERROR: This firmware version (0x%llx) is incompatible.\n" + "Please update firmware (min. 0x%llx) to be compatible with this server.\n", + (long long int)fwversion, + (long long int)REQRD_FRMWR_VRSN); + cprintf(RED,"%s\n\n", firmware_message); + firmware_compatibility = FAIL; + firmware_check_done = 1; + return; } printf("Compatibility - success\n"); + firmware_check_done = 1; } @@ -222,6 +269,8 @@ int64_t getDetectorId(enum idMode arg){ return getFirmwareAPIVersion(); case DETECTOR_SOFTWARE_VERSION: return (GITDATE & 0xFFFFFF); + case CLIENT_SOFTWARE_API_VERSION: + return APIJUNGFRAU; default: return retval; } diff --git a/slsDetectorSoftware/jungfrauDetectorServer/slsDetectorServer_defs.h b/slsDetectorSoftware/jungfrauDetectorServer/slsDetectorServer_defs.h index e98896d43..3fd667120 100644 --- a/slsDetectorSoftware/jungfrauDetectorServer/slsDetectorServer_defs.h +++ b/slsDetectorSoftware/jungfrauDetectorServer/slsDetectorServer_defs.h @@ -10,7 +10,7 @@ #define GOODBYE (-200) #define PROGRAMMING_MODE (-200) #define MIN_REQRD_VRSN_T_RD_API 0x171220 -#define REQRD_FRMWR_VRSN 0x180226 +#define REQRD_FRMWR_VRSN 0x20180226 /* Struct Definitions */ diff --git a/slsDetectorSoftware/jungfrauDetectorServer/updateAPIVersion.sh b/slsDetectorSoftware/jungfrauDetectorServer/updateAPIVersion.sh index b671637c6..ef65ec7e7 100755 --- a/slsDetectorSoftware/jungfrauDetectorServer/updateAPIVersion.sh +++ b/slsDetectorSoftware/jungfrauDetectorServer/updateAPIVersion.sh @@ -1,7 +1,7 @@ SRCFILE=gitInfoJungfrau.h -DSTFILE=../commonFiles/versionAPI.h +DSTFILE=versionAPI.h SRCPATTERN=GITDATE DSTPATTERN=APIJUNGFRAU -awk -v a="$SRCFILE" -v b="$DSTFILE" -v c="$SRCPATTERN" -v d="$DSTPATTERN" 'FNR==NR&&$2==c{x=$3} NR!=FNR{if($2==d){$3=x}print > b}' $SRCFILE $DSTFILE \ No newline at end of file +awk -v a="$SRCFILE" -v b="$DSTFILE" -v c="$SRCPATTERN" -v d="$DSTPATTERN" 'FNR==NR&&$2==c{x=$3} NR!=FNR{if($2==d){$3="0x"substr(x,5)}print > b}' $SRCFILE $DSTFILE \ No newline at end of file diff --git a/slsDetectorSoftware/jungfrauDetectorServer/versionAPI.h b/slsDetectorSoftware/jungfrauDetectorServer/versionAPI.h new file mode 120000 index 000000000..d3bf8d6cf --- /dev/null +++ b/slsDetectorSoftware/jungfrauDetectorServer/versionAPI.h @@ -0,0 +1 @@ +../commonFiles/versionAPI.h \ No newline at end of file diff --git a/slsDetectorSoftware/multiSlsDetector/multiSlsDetector.cpp b/slsDetectorSoftware/multiSlsDetector/multiSlsDetector.cpp index bea8ff9ef..bce099245 100644 --- a/slsDetectorSoftware/multiSlsDetector/multiSlsDetector.cpp +++ b/slsDetectorSoftware/multiSlsDetector/multiSlsDetector.cpp @@ -7021,3 +7021,42 @@ bool multiSlsDetector::isAcquireReady() { thisMultiDetector->acquiringFlag = true; return OK; } + + + +int multiSlsDetector::checkVersionCompatibility(portType t) { + int ret=-100; + + if(!threadpool){ + cout << "Error in creating threadpool. Exiting" << endl; + return -1; + }else{ + //return storage values + int* iret[thisMultiDetector->numberOfDetectors]; + for(int idet=0; idetnumberOfDetectors; ++idet){ + if(detectors[idet]){ + iret[idet]= new int(-1); + Task* task = new Task(new func1_t(&slsDetector::checkVersionCompatibility, + detectors[idet],t,iret[idet])); + threadpool->add_task(task); + } + } + threadpool->startExecuting(); + threadpool->wait_for_tasks_to_complete(); + for(int idet=0; idetnumberOfDetectors; ++idet){ + if(detectors[idet]){ + if(iret[idet] != NULL){ + if (ret==-100) + ret=*iret[idet]; + else if (ret!=*iret[idet]) + ret=-1; + delete iret[idet]; + }else ret=-1; + if(detectors[idet]->getErrorMask()) + setErrorMask(getErrorMask()|(1< #include #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; iaactionScript[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; +} diff --git a/slsDetectorSoftware/slsDetector/slsDetector.h b/slsDetectorSoftware/slsDetector/slsDetector.h index 5bf6bd447..bcab250c8 100644 --- a/slsDetectorSoftware/slsDetector/slsDetector.h +++ b/slsDetectorSoftware/slsDetector/slsDetector.h @@ -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: diff --git a/slsDetectorSoftware/slsDetector/slsDetectorCommand.cpp b/slsDetectorSoftware/slsDetector/slsDetectorCommand.cpp index aa71dd50d..fea9b7cbf 100644 --- a/slsDetectorSoftware/slsDetector/slsDetectorCommand.cpp +++ b/slsDetectorSoftware/slsDetector/slsDetectorCommand.cpp @@ -507,6 +507,22 @@ slsDetectorCommand::slsDetectorCommand(slsDetectorUtils *det) { Commands to check versions of each subsystem */ + /*! \page config + - checkdetversion 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 + - checkrecversion 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 - moduleversion:[i] 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; diff --git a/slsDetectorSoftware/slsDetector/slsDetectorUtils.h b/slsDetectorSoftware/slsDetector/slsDetectorUtils.h index ba183e275..1dbf5840e 100644 --- a/slsDetectorSoftware/slsDetector/slsDetectorUtils.h +++ b/slsDetectorSoftware/slsDetector/slsDetectorUtils.h @@ -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: diff --git a/slsDetectorSoftware/slsDetectorServer/slsDetectorFunctionList.h b/slsDetectorSoftware/slsDetectorServer/slsDetectorFunctionList.h index 8611ffbcd..6c990b5f6 100644 --- a/slsDetectorSoftware/slsDetectorServer/slsDetectorFunctionList.h +++ b/slsDetectorSoftware/slsDetectorServer/slsDetectorFunctionList.h @@ -17,6 +17,11 @@ Here are the definitions, but the actual implementation should be done for each // basic tests +#if defined(EIGERD) || defined(JUNGFRAUD) || defined(GOTTHARD) +int isFirmwareCheckDone(); +int getFirmwareCheckResult(char** mess); +#endif + void checkFirmwareCompatibility(int flag); #if defined(MYTHEN3D) || defined(JUNGFRAUD) int checkType(); diff --git a/slsDetectorSoftware/slsDetectorServer/slsDetectorServer_funcs.c b/slsDetectorSoftware/slsDetectorServer/slsDetectorServer_funcs.c index 98387b19f..0fb87ea2e 100755 --- a/slsDetectorSoftware/slsDetectorServer/slsDetectorServer_funcs.c +++ b/slsDetectorSoftware/slsDetectorServer/slsDetectorServer_funcs.c @@ -209,6 +209,7 @@ const char* getFunctionName(enum detFuncs func) { case F_TEMP_EVENT: return "F_TEMP_EVENT"; case F_AUTO_COMP_DISABLE: return "F_AUTO_COMP_DISABLE"; case F_STORAGE_CELL_START: return "F_STORAGE_CELL_START"; + case F_CHECK_VERSION: return "F_CHECK_VERSION"; default: return "Unknown Function"; } @@ -293,6 +294,7 @@ void function_table() { flist[F_TEMP_EVENT] = &temp_event; flist[F_AUTO_COMP_DISABLE] = &auto_comp_disable; flist[F_STORAGE_CELL_START] = &storage_cell_start; + flist[F_CHECK_VERSION] = &check_version; // check if (NUM_DET_FUNCTIONS >= TOO_MANY_FUNCTIONS_DEFINED) { @@ -5146,9 +5148,10 @@ int program_fpga(int file_des) { printf("Done with program receiving command\n"); #endif - if (isControlServer) + if (isControlServer) { basictests(debugflag); - init_detector(isControlServer); + initControlServer(); + } } #endif if (ret==OK) @@ -5760,3 +5763,97 @@ int storage_cell_start(int file_des) { return ret; } + + + +int check_version(int file_des) { + int ret=OK,ret1=OK; + int n=0; + sprintf(mess,"check version failed\n"); + +#if !defined(EIGERD) && !defined(JUNGFRAUD) && !defined(GOTTHARD) + //to receive any arguments + while (n > 0) + n = receiveData(file_des,mess,MAX_STR_LENGTH,OTHER); + ret=FAIL; + sprintf(mess,"Function (Check Version Compatibility) is not implemented for this detector\n"); + cprintf(RED, "Warning: %s", mess); +#else + + // receive arguments + int64_t arg=-1; + n = receiveData(file_des,&arg,sizeof(arg),INT64); + if (n < 0) return printSocketReadError(); + + // execute action +#ifdef SLS_DETECTOR_FUNCTION_LIST + + // check software- firmware compatibility and basic tests + if (isControlServer) { +#ifdef VERBOSE + printf("Checking software-firmware compatibility and basic test result\n"); +#endif + // check if firmware check is done + if (!isFirmwareCheckDone()) { + usleep(3 * 1000 * 1000); + if (!isFirmwareCheckDone()) { + ret = FAIL; + strcpy(mess,"Firmware Software Compatibility Check (Server Initialization) " + "still not done done in server. Unexpected.\n"); + cprintf(RED, "Warning: %s", mess); + } + } + // check firmware check result + if (ret == OK) { + char* firmware_message = NULL; + if (getFirmwareCheckResult(&firmware_message) == FAIL) { + ret = FAIL; + strcpy(mess, firmware_message); + cprintf(RED, "Warning: %s", mess); + } + } + } + + if (ret == OK) { +#ifdef VERBOSE + printf("Checking versioning compatibility with value %d\n",arg); +#endif + int64_t client_requiredVersion = arg; + int64_t det_apiVersion = getDetectorId(CLIENT_SOFTWARE_API_VERSION); + int64_t det_version = getDetectorId(DETECTOR_SOFTWARE_VERSION); + + // old client + if (det_apiVersion > client_requiredVersion) { + ret = FAIL; + sprintf(mess,"Client's detector SW API version: (0x%llx). " + "Detector's SW API Version: (0x%llx). " + "Incompatible, update client!\n", + client_requiredVersion, det_apiVersion); + cprintf(RED, "Warning: %s", mess); + } + + // old software + else if (client_requiredVersion > det_version) { + ret = FAIL; + sprintf(mess,"Detector SW Version: (0x%llx). " + "Client's detector SW API Version: (0x%llx). " + "Incompatible, update detector software!\n", + det_version, client_requiredVersion); + cprintf(RED, "Warning: %s", mess); + } + } +#endif +#endif + + // ret could be swapped during sendData + ret1 = ret; + // send ok / fail + n = sendData(file_des,&ret1,sizeof(ret),INT32); + // send return argument + if (ret==FAIL) { + n += sendData(file_des,mess,sizeof(mess),OTHER); + } + + // return ok / fail + return ret; +} diff --git a/slsDetectorSoftware/slsDetectorServer/slsDetectorServer_funcs.h b/slsDetectorSoftware/slsDetectorServer/slsDetectorServer_funcs.h index b80a9712f..a8ab6b927 100755 --- a/slsDetectorSoftware/slsDetectorServer/slsDetectorServer_funcs.h +++ b/slsDetectorSoftware/slsDetectorServer/slsDetectorServer_funcs.h @@ -95,5 +95,6 @@ int temp_control(int); int temp_event(int); int auto_comp_disable(int); int storage_cell_start(int); +int check_version(int); #endif diff --git a/slsDetectorSoftware/slsReceiverInterface/receiverInterface.cpp b/slsDetectorSoftware/slsReceiverInterface/receiverInterface.cpp index bd5e1cc4a..a8bbd4a0b 100644 --- a/slsDetectorSoftware/slsReceiverInterface/receiverInterface.cpp +++ b/slsDetectorSoftware/slsReceiverInterface/receiverInterface.cpp @@ -21,7 +21,8 @@ receiverInterface::~receiverInterface(){} int receiverInterface::sendString(int fnum, char retval[], char arg[]){ int ret = slsDetectorDefs::FAIL; - char mess[MAX_STR_LENGTH] = ""; + char mess[MAX_STR_LENGTH]; + memset(mess, 0, MAX_STR_LENGTH); dataSocket->SendDataOnly(&fnum,sizeof(fnum)); dataSocket->SendDataOnly(arg,MAX_STR_LENGTH); @@ -30,7 +31,8 @@ int receiverInterface::sendString(int fnum, char retval[], char arg[]){ dataSocket->ReceiveDataOnly(mess,sizeof(mess)); cprintf(RED, "Receiver returned error: %s", mess); } - dataSocket->ReceiveDataOnly(retval,MAX_STR_LENGTH); + if(strstr(mess,"Unrecognized Function")==NULL) + dataSocket->ReceiveDataOnly(retval,MAX_STR_LENGTH); return ret; } @@ -40,7 +42,8 @@ int receiverInterface::sendString(int fnum, char retval[], char arg[]){ int receiverInterface::sendUDPDetails(int fnum, char retval[], char arg[3][MAX_STR_LENGTH]){ char args[3][MAX_STR_LENGTH]; int ret = slsDetectorDefs::FAIL; - char mess[MAX_STR_LENGTH] = ""; + char mess[MAX_STR_LENGTH]; + memset(mess, 0, MAX_STR_LENGTH); dataSocket->SendDataOnly(&fnum,sizeof(fnum)); dataSocket->SendDataOnly(arg,sizeof(args)); @@ -58,7 +61,8 @@ int receiverInterface::sendUDPDetails(int fnum, char retval[], char arg[3][MAX_S int receiverInterface::sendInt(int fnum, int &retval, int arg){ int ret = slsDetectorDefs::FAIL; - char mess[MAX_STR_LENGTH] = ""; + char mess[MAX_STR_LENGTH]; + memset(mess, 0, MAX_STR_LENGTH); dataSocket->SendDataOnly(&fnum,sizeof(fnum)); dataSocket->SendDataOnly(&arg,sizeof(arg)); @@ -67,7 +71,8 @@ int receiverInterface::sendInt(int fnum, int &retval, int arg){ dataSocket->ReceiveDataOnly(mess,sizeof(mess)); cprintf(RED, "Receiver returned error: %s", mess); } - dataSocket->ReceiveDataOnly(&retval,sizeof(retval)); + if(strstr(mess,"Unrecognized Function")==NULL) + dataSocket->ReceiveDataOnly(&retval,sizeof(retval)); return ret; } @@ -76,7 +81,8 @@ int receiverInterface::sendInt(int fnum, int &retval, int arg){ int receiverInterface::getInt(int fnum, int &retval){ int ret = slsDetectorDefs::FAIL; - char mess[MAX_STR_LENGTH] = ""; + char mess[MAX_STR_LENGTH]; + memset(mess, 0, MAX_STR_LENGTH); dataSocket->SendDataOnly(&fnum,sizeof(fnum)); dataSocket->ReceiveDataOnly(&ret,sizeof(ret)); @@ -84,7 +90,8 @@ int receiverInterface::getInt(int fnum, int &retval){ dataSocket->ReceiveDataOnly(mess,sizeof(mess)); cprintf(RED, "Receiver returned error: %s", mess); } - dataSocket->ReceiveDataOnly(&retval,sizeof(retval)); + if(strstr(mess,"Unrecognized Function")==NULL) + dataSocket->ReceiveDataOnly(&retval,sizeof(retval)); return ret; } @@ -93,7 +100,8 @@ int receiverInterface::getInt(int fnum, int &retval){ int receiverInterface::sendInt(int fnum, int64_t &retval, int64_t arg){ int ret = slsDetectorDefs::FAIL; - char mess[MAX_STR_LENGTH] = ""; + char mess[MAX_STR_LENGTH]; + memset(mess, 0, MAX_STR_LENGTH); dataSocket->SendDataOnly(&fnum,sizeof(fnum)); dataSocket->SendDataOnly(&arg,sizeof(arg)); @@ -102,7 +110,8 @@ int receiverInterface::sendInt(int fnum, int64_t &retval, int64_t arg){ dataSocket->ReceiveDataOnly(mess,sizeof(mess)); cprintf(RED, "Receiver returned error: %s", mess); } - dataSocket->ReceiveDataOnly(&retval,sizeof(retval)); + if(strstr(mess,"Unrecognized Function")==NULL) + dataSocket->ReceiveDataOnly(&retval,sizeof(retval)); return ret; } @@ -111,16 +120,18 @@ int receiverInterface::sendInt(int fnum, int64_t &retval, int64_t arg){ int receiverInterface::sendIntArray(int fnum, int64_t &retval, int64_t arg[2], char mess[]){ int64_t args[2]; - char messs[MAX_STR_LENGTH]; int ret = slsDetectorDefs::FAIL; + memset(mess, 0, MAX_STR_LENGTH); + dataSocket->SendDataOnly(&fnum,sizeof(fnum)); dataSocket->SendDataOnly(arg,sizeof(args)); dataSocket->ReceiveDataOnly(&ret,sizeof(ret)); if (ret==slsDetectorDefs::FAIL){ - dataSocket->ReceiveDataOnly(mess,sizeof(messs)); + dataSocket->ReceiveDataOnly(mess,MAX_STR_LENGTH); cprintf(RED, "Receiver returned error: %s", mess); } - dataSocket->ReceiveDataOnly(&retval,sizeof(retval)); + if(strstr(mess,"Unrecognized Function")==NULL) + dataSocket->ReceiveDataOnly(&retval,sizeof(retval)); return ret; } @@ -130,7 +141,9 @@ int receiverInterface::sendIntArray(int fnum, int64_t &retval, int64_t arg[2], c int receiverInterface::sendIntArray(int fnum, int &retval, int arg[2]){ int args[2]; int ret = slsDetectorDefs::FAIL; - char mess[MAX_STR_LENGTH] = ""; + char mess[MAX_STR_LENGTH]; + memset(mess, 0, MAX_STR_LENGTH); + dataSocket->SendDataOnly(&fnum,sizeof(fnum)); dataSocket->SendDataOnly(arg,sizeof(args)); dataSocket->ReceiveDataOnly(&ret,sizeof(ret)); @@ -138,7 +151,8 @@ int receiverInterface::sendIntArray(int fnum, int &retval, int arg[2]){ dataSocket->ReceiveDataOnly(mess,sizeof(mess)); cprintf(RED, "Receiver returned error: %s", mess); } - dataSocket->ReceiveDataOnly(&retval,sizeof(retval)); + if(strstr(mess,"Unrecognized Function")==NULL) + dataSocket->ReceiveDataOnly(&retval,sizeof(retval)); return ret; } @@ -170,6 +184,7 @@ int receiverInterface::getLastClientIP(int fnum, char retval[]){ int receiverInterface::executeFunction(int fnum,char mess[]){ int ret = slsDetectorDefs::FAIL; + memset(mess, 0, MAX_STR_LENGTH); dataSocket->SendDataOnly(&fnum,sizeof(fnum)); dataSocket->ReceiveDataOnly(&ret,sizeof(ret)); diff --git a/slsDetectorSoftware/threadFiles/Task.h b/slsDetectorSoftware/threadFiles/Task.h index b9d6177a5..cbb4118f9 100644 --- a/slsDetectorSoftware/threadFiles/Task.h +++ b/slsDetectorSoftware/threadFiles/Task.h @@ -105,7 +105,7 @@ private: class SuperTask: public virtual slsDetectorDefs { public: SuperTask(): - m1(0),m2(0),m3(0),m4(0),m5(0),m6(0),m7(0),m8(0),m9(0),m10(0),m11(0),m12(0),m13(0),m14(0),m15(0),m16(0),m17(0),m18(0){}; + m1(0),m2(0),m3(0),m4(0),m5(0),m6(0),m7(0),m8(0),m9(0),m10(0),m11(0),m12(0),m13(0),m14(0),m15(0),m16(0),m17(0),m18(0),m19(0){}; virtual ~SuperTask(){}; protected: /** Function signature defined @@ -129,6 +129,7 @@ protected: func4_t * m16; func4_t * m17; func4_t * m18; + func1_t * m19; }; class Task: public virtual SuperTask { @@ -154,6 +155,7 @@ public: Task(func4_t * t): SuperTask(),fnum(16){m16 = t;}; Task(func4_t * t): SuperTask(),fnum(17){m17 = t;}; Task(func4_t * t): SuperTask(),fnum(18){m18 = t;}; + Task(func1_t * t): SuperTask(),fnum(19){m19 = t;}; virtual ~Task(){ switch(fnum) { @@ -175,6 +177,7 @@ public: case 16: delete m16; break; case 17: delete m17; break; case 18: delete m18; break; + case 19: delete m19; break; default: cprintf(RED, "Error: Task not defined. Abort!\n"); break; @@ -202,6 +205,7 @@ public: case 16: (*m16)(); break; case 17: (*m17)(); break; case 18: (*m18)(); break; + case 19: (*m19)(); break; default: cprintf(RED, "Error: Task not defined. Abort!\n"); break; diff --git a/slsReceiverSoftware/include/slsReceiverTCPIPInterface.h b/slsReceiverSoftware/include/slsReceiverTCPIPInterface.h index 42e2e980a..3d48f01d0 100644 --- a/slsReceiverSoftware/include/slsReceiverTCPIPInterface.h +++ b/slsReceiverSoftware/include/slsReceiverTCPIPInterface.h @@ -309,6 +309,10 @@ class slsReceiverTCPIPInterface : private virtual slsReceiverDefs { /** set frames per file */ int set_frames_per_file(); + + /** check version compatibility */ + int check_version_compatibility(); + /** detector type */ detectorType myDetectorType; diff --git a/slsReceiverSoftware/include/sls_receiver_funcs.h b/slsReceiverSoftware/include/sls_receiver_funcs.h index da113cfd5..3f1c06664 100644 --- a/slsReceiverSoftware/include/sls_receiver_funcs.h +++ b/slsReceiverSoftware/include/sls_receiver_funcs.h @@ -67,7 +67,7 @@ enum recFuncs{ F_RECEIVER_UDP_SOCK_BUF_SIZE, /** < UDP socket buffer size */ F_RECEIVER_REAL_UDP_SOCK_BUF_SIZE, /** < real UDP socket buffer size */ F_SET_RECEIVER_FRAMES_PER_FILE, /** < receiver frames per file */ - + F_RECEIVER_CHECK_VERSION, /** < check receiver version compatibility */ /* Always append functions hereafter!!! */ diff --git a/slsReceiverSoftware/include/versionAPI.h b/slsReceiverSoftware/include/versionAPI.h new file mode 120000 index 000000000..a4d75aa2a --- /dev/null +++ b/slsReceiverSoftware/include/versionAPI.h @@ -0,0 +1 @@ +../../slsDetectorSoftware/commonFiles/versionAPI.h \ No newline at end of file diff --git a/slsReceiverSoftware/src/UDPStandardImplementation.cpp b/slsReceiverSoftware/src/UDPStandardImplementation.cpp index 20ab92b03..bef70a6dd 100644 --- a/slsReceiverSoftware/src/UDPStandardImplementation.cpp +++ b/slsReceiverSoftware/src/UDPStandardImplementation.cpp @@ -674,7 +674,7 @@ void UDPStandardImplementation::SetLocalNetworkParameters() { "[/proc/sys/net/core/netdev_max_backlog] modified to %d\n", MAX_SOCKET_INPUT_PACKET_QUEUE); } else { - const char *msg = "Could not change max length of" + const char *msg = "Could not change max length of " "input packet queue [net.core.netdev_max_backlog]. (No Root Privileges?)"; FILE_LOG(logWARNING) << msg; } diff --git a/slsReceiverSoftware/src/slsReceiverTCPIPInterface.cpp b/slsReceiverSoftware/src/slsReceiverTCPIPInterface.cpp index 5b3d2c482..e79590bf6 100644 --- a/slsReceiverSoftware/src/slsReceiverTCPIPInterface.cpp +++ b/slsReceiverSoftware/src/slsReceiverTCPIPInterface.cpp @@ -8,6 +8,7 @@ #include "gitInfoReceiver.h" #include "slsReceiverUsers.h" #include "slsReceiver.h" +#include "versionAPI.h" #include //EXIT #include @@ -153,7 +154,7 @@ void slsReceiverTCPIPInterface::stop(){ int64_t slsReceiverTCPIPInterface::getReceiverVersion(){ - int64_t retval = GITDATE; + int64_t retval = GITDATE & 0xFFFFFF; return retval; } @@ -297,6 +298,7 @@ const char* slsReceiverTCPIPInterface::getFunctionName(enum recFuncs func) { case F_RECEIVER_UDP_SOCK_BUF_SIZE: return "F_RECEIVER_UDP_SOCK_BUF_SIZE"; case F_RECEIVER_REAL_UDP_SOCK_BUF_SIZE: return "F_RECEIVER_REAL_UDP_SOCK_BUF_SIZE"; case F_SET_RECEIVER_FRAMES_PER_FILE:return "F_SET_RECEIVER_FRAMES_PER_FILE"; + case F_RECEIVER_CHECK_VERSION: return "F_RECEIVER_CHECK_VERSION"; default: return "Unknown Function"; } @@ -350,6 +352,7 @@ int slsReceiverTCPIPInterface::function_table(){ flist[F_RECEIVER_UDP_SOCK_BUF_SIZE] = &slsReceiverTCPIPInterface::set_udp_socket_buffer_size; flist[F_RECEIVER_REAL_UDP_SOCK_BUF_SIZE]= &slsReceiverTCPIPInterface::get_real_udp_socket_buffer_size; flist[F_SET_RECEIVER_FRAMES_PER_FILE] = &slsReceiverTCPIPInterface::set_frames_per_file; + flist[F_RECEIVER_CHECK_VERSION] = &slsReceiverTCPIPInterface::check_version_compatibility; #ifdef VERYVERBOSE for (int i = 0; i < NUM_REC_FUNCTIONS ; i++) { @@ -367,20 +370,22 @@ int slsReceiverTCPIPInterface::decode_function(){ ret = FAIL; #ifdef VERYVERBOSE cprintf(RESET,"\n"); - FILE_LOG(logDEBUG1) << "waiting to receive data"; #endif + FILE_LOG(logDEBUG1) << "waiting to receive data"; int n = mySock->ReceiveDataOnly(&fnum,sizeof(fnum)); if (n <= 0) { -#ifdef VERYVERBOSE - FILE_LOG(logDEBUG1) << "ERROR reading from socket. Received " << n << " bytes, fd: " << file_des << " fnum:" << fnum << " (" << getFunctionName((enum recFuncs)fnum) << ")"; -#endif + FILE_LOG(logDEBUG1) << "ERROR reading from socket. " + "Received " << n << " bytes," << + "fnum:" << fnum << " " + "(" << getFunctionName((enum recFuncs)fnum) << ")"; return FAIL; } -#ifdef VERYVERBOSE else FILE_LOG(logDEBUG1) << "Received " << n << " bytes"; - FILE_LOG(logDEBUG1) << "calling function fnum: "<< fnum << " (" << getFunctionName((enum recFuncs)fnum) << ") located at " << flist[fnum]; -#endif + + FILE_LOG(logDEBUG1) << "calling function fnum: "<< fnum << " " + "(" << getFunctionName((enum recFuncs)fnum) << ") " + "located at " << flist[fnum]; if (fnum < REC_FUNC_START_INDEX || fnum >= NUM_REC_FUNCTIONS) { FILE_LOG(logERROR) << "Unknown function enum " << fnum; @@ -429,7 +434,7 @@ void slsReceiverTCPIPInterface::functionNotImplemented() { } -int slsReceiverTCPIPInterface::M_nofunc(){ +int slsReceiverTCPIPInterface::M_nofunc(){printf("111 \n"); ret = FAIL; memset(mess, 0, sizeof(mess)); int n = 0; @@ -438,7 +443,7 @@ int slsReceiverTCPIPInterface::M_nofunc(){ while (n > 0) n = mySock->ReceiveDataOnly(mess,MAX_STR_LENGTH); - sprintf(mess,"Unrecognized Function\n"); + strcpy(mess,"Unrecognized Function. Please do not proceed.\n"); FILE_LOG(logERROR) << mess; // send ok / fail @@ -2758,3 +2763,60 @@ int slsReceiverTCPIPInterface::set_frames_per_file() { return ret; } + + + + + +int slsReceiverTCPIPInterface::check_version_compatibility() { + ret = OK; + memset(mess, 0, sizeof(mess)); + int64_t arg = -1; + int64_t retval = -1; + + // receive arguments + if (mySock->ReceiveDataOnly(&arg,sizeof(arg)) < 0 ) + return printSocketReadError(); + + + // execute action + FILE_LOG(logDEBUG1) << "Checking versioning compatibility with value " << arg; + + int64_t client_requiredVersion = arg; + int64_t rx_apiVersion = APIRECEIVER; + int64_t rx_version = getReceiverVersion(); + + // old client + if (rx_apiVersion > client_requiredVersion) { + ret = FAIL; + sprintf(mess,"This client is incompatible.\n" + "Client's receiver API Version: (0x%llx). Receiver API Version: (0x%llx).\n" + "Incompatible, update client!\n", + client_requiredVersion, rx_apiVersion); + FILE_LOG(logERROR) << mess; + } + + // old software + else if (client_requiredVersion > rx_version) { + ret = FAIL; + sprintf(mess,"This receiver is incompatible.\n" + "Receiver Version: (0x%llx). Client's receiver API Version: (0x%llx).\n" + "Incompatible, update receiver!\n", + rx_version, client_requiredVersion); + FILE_LOG(logERROR) << mess; + } + else FILE_LOG(logINFO) << "Compatibility with Client: Successful"; + + if (ret == OK && mySock->differentClients) + ret = FORCE_UPDATE; + + // send answer + mySock->SendDataOnly(&ret,sizeof(ret)); + if (ret == FAIL) + mySock->SendDataOnly(mess,sizeof(mess)); + mySock->SendDataOnly(&retval,sizeof(retval)); // sending crap (because of thisReceiver interface) + + // return ok/fail + return ret; +} + diff --git a/slsReceiverSoftware/updateAPIVersion.sh b/slsReceiverSoftware/updateAPIVersion.sh new file mode 100755 index 000000000..389b2929e --- /dev/null +++ b/slsReceiverSoftware/updateAPIVersion.sh @@ -0,0 +1,7 @@ +SRCFILE=include/gitInfoReceiver.h +DSTFILE=include/versionAPI.h + +SRCPATTERN=GITDATE +DSTPATTERN=APIRECEIVER + +awk -v a="$SRCFILE" -v b="$DSTFILE" -v c="$SRCPATTERN" -v d="$DSTPATTERN" 'FNR==NR&&$2==c{x=$3} NR!=FNR{if($2==d){$3="0x"substr(x,5)}print > b}' $SRCFILE $DSTFILE \ No newline at end of file