setonline, setreceiveronline was never really setting offline flag, so was never really updating detector first time

This commit is contained in:
2019-03-19 18:42:45 +01:00
parent ce6289afda
commit 685fcc31b6

View File

@ -96,31 +96,29 @@ int slsDetector::checkDetectorVersionCompatibility() {
// control server // control server
if (detector_shm()->onlineFlag == ONLINE_FLAG) { if (detector_shm()->onlineFlag == ONLINE_FLAG) {
// in case it throws
detector_shm()->detectorControlAPIVersion = 0;
detector_shm()->detectorStopAPIVersion = 0;
detector_shm()->onlineFlag = OFFLINE_FLAG;
auto client = DetectorSocket(detector_shm()->hostname, detector_shm()->controlPort); auto client = DetectorSocket(detector_shm()->hostname, detector_shm()->controlPort);
ret = client.sendCommandThenRead(fnum, &arg, sizeof(arg), nullptr, 0); ret = client.sendCommandThenRead(fnum, &arg, sizeof(arg), nullptr, 0);
if (ret == FAIL) {
detector_shm()->detectorControlAPIVersion = 0;
// stop server
} else {
detector_shm()->detectorControlAPIVersion = arg;
ret = FAIL;
auto stop = DetectorSocket(detector_shm()->hostname, detector_shm()->stopPort); auto stop = DetectorSocket(detector_shm()->hostname, detector_shm()->stopPort);
ret = stop.sendCommandThenRead(fnum, &arg, sizeof(arg), nullptr, 0); ret = stop.sendCommandThenRead(fnum, &arg, sizeof(arg), nullptr, 0);
if (ret == FAIL) {
detector_shm()->detectorStopAPIVersion = 0; // success
} else { detector_shm()->detectorControlAPIVersion = arg;
detector_shm()->detectorStopAPIVersion = arg; detector_shm()->detectorStopAPIVersion = arg;
detector_shm()->onlineFlag = ONLINE_FLAG;
} }
}
} // pointless
if (ret == FAIL) { // if (ret == FAIL) {
setErrorMask((getErrorMask()) | (VERSION_COMPATIBILITY)); // setErrorMask((getErrorMask()) | (VERSION_COMPATIBILITY));
// if (strstr(mess, "Unrecognized Function") != nullptr) {
// FILE_LOG(logERROR) << "The " << ((t == CONTROL_PORT) ? "detector" : "receiver") << " server is too old to get API version. Please update detector server!";
// } // }
}
return ret; return ret;
} }
@ -136,21 +134,23 @@ int slsDetector::checkReceiverVersionCompatibility() {
<< std::hex << arg << std::dec; << std::hex << arg << std::dec;
if (detector_shm()->receiverOnlineFlag == ONLINE_FLAG) { if (detector_shm()->receiverOnlineFlag == ONLINE_FLAG) {
// in case it throws
detector_shm()->receiverAPIVersion = 0;
detector_shm()->receiverOnlineFlag = OFFLINE_FLAG;
auto receiver = ReceiverSocket(detector_shm()->receiver_hostname, detector_shm()->receiverTCPPort); auto receiver = ReceiverSocket(detector_shm()->receiver_hostname, detector_shm()->receiverTCPPort);
ret = receiver.sendCommandThenRead(fnum, &arg, sizeof(arg), nullptr, 0); ret = receiver.sendCommandThenRead(fnum, &arg, sizeof(arg), nullptr, 0);
if (ret == FAIL) {
detector_shm()->receiverAPIVersion = 0; // success
} else {
detector_shm()->receiverAPIVersion = arg; detector_shm()->receiverAPIVersion = arg;
} detector_shm()->receiverOnlineFlag = ONLINE_FLAG;
} }
if (ret == FAIL) { // pointless
setErrorMask((getErrorMask()) | (VERSION_COMPATIBILITY)); // if (ret == FAIL) {
// if (strstr(mess, "Unrecognized Function") != nullptr) { // setErrorMask((getErrorMask()) | (VERSION_COMPATIBILITY));
// FILE_LOG(logERROR) << "The " << ((t == CONTROL_PORT) ? "detector" : "receiver") << " server is too old to get API version. Please update detector server!";
// } // }
}
return ret; return ret;
} }
@ -698,22 +698,35 @@ void slsDetector::updateMultiSize(int detx, int dety) {
int slsDetector::setOnline(int value) { int slsDetector::setOnline(int value) {
if (value != GET_ONLINE_FLAG) { if (value != GET_ONLINE_FLAG) {
// set offline
if (value == OFFLINE_FLAG) {
detector_shm()->onlineFlag = value; detector_shm()->onlineFlag = value;
}
// set online // set online
if (detector_shm()->onlineFlag == ONLINE_FLAG) { else {
int old = detector_shm()->onlineFlag; int old = detector_shm()->onlineFlag;
// connect and set offline flag (set it to fail in case it throws)
detector_shm()->onlineFlag = OFFLINE_FLAG;
auto client = DetectorSocket(detector_shm()->hostname, detector_shm()->controlPort);
client.close();
detector_shm()->onlineFlag = ONLINE_FLAG;
// connecting first time // connecting first time
if (detector_shm()->onlineFlag == ONLINE_FLAG && old == OFFLINE_FLAG) { if (detector_shm()->onlineFlag == ONLINE_FLAG && old == OFFLINE_FLAG) {
auto client = DetectorSocket(detector_shm()->hostname, detector_shm()->controlPort); // check version compatibility (first time)
if ((detector_shm()->detectorControlAPIVersion == 0) ||
(detector_shm()->detectorStopAPIVersion == 0)) {
checkDetectorVersionCompatibility();
}
// check detector version could set it offline
if (detector_shm()->onlineFlag == ONLINE_FLAG) {
FILE_LOG(logINFO) << "Detector connecting for the first time - updating!"; FILE_LOG(logINFO) << "Detector connecting for the first time - updating!";
client.close();
updateDetector(); updateDetector();
} }
// error
else if (detector_shm()->onlineFlag == OFFLINE_FLAG) {
FILE_LOG(logERROR) << "Cannot connect to detector";
setErrorMask((getErrorMask()) | (CANNOT_CONNECT_TO_DETECTOR));
} }
} }
} }
@ -4010,16 +4023,26 @@ int slsDetector::setReceiverOnline(int value) {
// no receiver // no receiver
if (!strcmp(detector_shm()->receiver_hostname, "none")) { if (!strcmp(detector_shm()->receiver_hostname, "none")) {
detector_shm()->receiverOnlineFlag = OFFLINE_FLAG; detector_shm()->receiverOnlineFlag = OFFLINE_FLAG;
} else { }
else {
// set offline
if (value == OFFLINE_FLAG) {
detector_shm()->receiverOnlineFlag = value; detector_shm()->receiverOnlineFlag = value;
} }
// set online // set online
if (detector_shm()->receiverOnlineFlag == ONLINE_FLAG) { else {
// setReceiverTCPSocket(); // connect and set offline flag
// error in connecting detector_shm()->receiverOnlineFlag = OFFLINE_FLAG;
if (detector_shm()->receiverOnlineFlag == OFFLINE_FLAG) { auto receiver = ReceiverSocket(detector_shm()->receiver_hostname, detector_shm()->receiverTCPPort);
FILE_LOG(logERROR) << "Cannot connect to receiver"; receiver.close();
setErrorMask((getErrorMask()) | (CANNOT_CONNECT_TO_RECEIVER)); detector_shm()->receiverOnlineFlag = ONLINE_FLAG;
// check for version compatibility
if (detector_shm()->receiverAPIVersion == 0) {
checkReceiverVersionCompatibility();
}
} }
} }
} }