From 5a1b2470f0b3194bc88af0c80f8fafa0ab6199de Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Thu, 7 Sep 2023 16:07:59 +0200 Subject: [PATCH] some structure clean up --- mission/acs/SusHandler.cpp | 59 +++++++++++++++++++------------------- 1 file changed, 30 insertions(+), 29 deletions(-) diff --git a/mission/acs/SusHandler.cpp b/mission/acs/SusHandler.cpp index 287e4d2e..f61dc3a0 100644 --- a/mission/acs/SusHandler.cpp +++ b/mission/acs/SusHandler.cpp @@ -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(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; }