some structure clean up
All checks were successful
EIVE/eive-obsw/pipeline/pr-main This commit looks good

This commit is contained in:
Robin Müller 2023-09-07 16:07:59 +02:00
parent c51fbb9074
commit 5a1b2470f0
Signed by: muellerr
GPG Key ID: FCE0B2BD2195142F

View File

@ -86,36 +86,37 @@ ReturnValue_t SusHandler::scanForReply(const uint8_t *start, size_t len, DeviceC
}
ReturnValue_t SusHandler::interpretDeviceReply(DeviceCommandId_t id, const uint8_t *packet) {
const auto *reply = reinterpret_cast<const acs::SusReply *>(packet);
if (reply->dataWasSet) {
if (internalState == InternalState::STARTUP) {
commandExecuted = true;
}
PoolReadGuard pg(&dataset);
// Simple FDIR variant to make the handler more robust to invalid messages which
// appear sometimes for the SUS device: Allow invalid message up to a certain threshold
// before triggering FDIR reactions.
if (reply->tempRaw == 0xfff and not waitingForRecovery) {
if (invalidMsgCounter == 0) {
triggerEvent(TEMPERATURE_ALL_ONES_START);
} else if (invalidMsgCounter == susMax1227::MAX_INVALID_MSG_COUNT) {
triggerEvent(DeviceHandlerIF::DEVICE_WANTS_HARD_REBOOT);
waitingForRecovery = true;
} else {
invalidMsgCounter++;
}
dataset.setValidity(false, true);
dataset.tempC = thermal::INVALID_TEMPERATURE;
std::memset(dataset.channels.value, 0, sizeof(dataset.channels.value));
} else {
if (invalidMsgCounter > 0) {
triggerEvent(TEMPERATURE_ALL_ONES_RECOVERY, invalidMsgCounter);
invalidMsgCounter = 0;
}
dataset.setValidity(true, true);
dataset.tempC = max1227::getTemperature(reply->tempRaw);
std::memcpy(dataset.channels.value, reply->channelsRaw, sizeof(reply->channelsRaw));
}
if (!reply->dataWasSet) {
return returnvalue::OK;
}
if (internalState == InternalState::STARTUP) {
commandExecuted = true;
}
PoolReadGuard pg(&dataset);
// Simple FDIR variant to make the handler more robust to invalid messages which
// appear sometimes for the SUS device: Allow invalid message up to a certain threshold
// before triggering FDIR reactions.
if (reply->tempRaw == 0xfff and not waitingForRecovery) {
if (invalidMsgCounter == 0) {
triggerEvent(TEMPERATURE_ALL_ONES_START);
} else if (invalidMsgCounter == susMax1227::MAX_INVALID_MSG_COUNT) {
triggerEvent(DeviceHandlerIF::DEVICE_WANTS_HARD_REBOOT);
waitingForRecovery = true;
} else {
invalidMsgCounter++;
}
dataset.setValidity(false, true);
dataset.tempC = thermal::INVALID_TEMPERATURE;
std::memset(dataset.channels.value, 0, sizeof(dataset.channels.value));
return returnvalue::OK;
}
if (invalidMsgCounter > 0) {
triggerEvent(TEMPERATURE_ALL_ONES_RECOVERY, invalidMsgCounter);
invalidMsgCounter = 0;
}
dataset.setValidity(true, true);
dataset.tempC = max1227::getTemperature(reply->tempRaw);
std::memcpy(dataset.channels.value, reply->channelsRaw, sizeof(reply->channelsRaw));
return returnvalue::OK;
}