From 949401e2470a2256531d7984557c122c21a056ad Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Tue, 21 Nov 2023 12:51:39 +0100 Subject: [PATCH] less trashy mode checker --- fsfw | 2 +- mission/payload/PayloadPcduHandler.cpp | 76 ++++++++++++++++---------- mission/payload/PayloadPcduHandler.h | 11 +++- 3 files changed, 57 insertions(+), 32 deletions(-) diff --git a/fsfw b/fsfw index cc3e64e7..41d67bff 160000 --- a/fsfw +++ b/fsfw @@ -1 +1 @@ -Subproject commit cc3e64e70d90f6a2b5c59215b2569c1771e890f0 +Subproject commit 41d67bff639192afa2e18a23db6801c75b4fea88 diff --git a/mission/payload/PayloadPcduHandler.cpp b/mission/payload/PayloadPcduHandler.cpp index 06c93842..5530e459 100644 --- a/mission/payload/PayloadPcduHandler.cpp +++ b/mission/payload/PayloadPcduHandler.cpp @@ -4,6 +4,7 @@ #include "OBSWConfig.h" #include "fsfw/thermal/tcsDefinitions.h" +#include "mission/payload/payloadPcduDefinitions.h" #ifdef XIPHOS_Q7S #include @@ -576,6 +577,7 @@ void PayloadPcduHandler::performOperationHook() { checkJsonFileInit(); } ReturnValue_t PayloadPcduHandler::checkModeCommand(Mode_t commandedMode, Submode_t commandedSubmode, uint32_t* msToReachTheMode) { + using namespace plpcdu; if (commandedMode != MODE_OFF) { PoolReadGuard pg(&enablePl); if (pg.getReadResult() == returnvalue::OK) { @@ -584,48 +586,62 @@ ReturnValue_t PayloadPcduHandler::checkModeCommand(Mode_t commandedMode, Submode } } } - return DeviceHandlerBase::checkModeCommand(commandedMode, commandedSubmode, msToReachTheMode); -} - -ReturnValue_t PayloadPcduHandler::isModeCombinationValid(Mode_t mode, Submode_t submode) { - using namespace plpcdu; - if (mode == MODE_NORMAL) { + if (commandedMode == MODE_NORMAL) { + uint8_t dhbSubmode = getSubmode(); + diffMask = commandedSubmode ^ dhbSubmode; + // For all higher level modes, SSR needs to be on. This is to ensure we have valid ADC + // measurements + if ((droOnForSubmode(commandedSubmode) or x8OnForSubmode(commandedSubmode) or + txOnForSubmode(commandedSubmode) or mpaOnForSubmode(commandedSubmode) or + hpaOnForSubmode(commandedSubmode)) and + not ssrOnForSubmode(dhbSubmode)) { + } if (disableChannelOrderCheck) { return returnvalue::OK; } - uint8_t dhbSubmode = getSubmode(); - diffMask = submode ^ dhbSubmode; - // Also deals with the case where the mode is MODE_ON, submode should be 0 here - if ((((submode >> SOLID_STATE_RELAYS_ADC_ON) & 0b1) == SOLID_STATE_RELAYS_ADC_ON) and - (getMode() == MODE_NORMAL and dhbSubmode != ALL_OFF_SUBMODE)) { + if (x8OnForSubmode(commandedSubmode) and not droOnForSubmode(dhbSubmode)) { return TRANS_NOT_ALLOWED; } - if (((((submode >> DRO_ON) & 1) == 1) and - ((dhbSubmode & 0b1) != (1 << SOLID_STATE_RELAYS_ADC_ON)))) { + if (txOnForSubmode(commandedSubmode) and + (not droOnForSubmode(dhbSubmode) or not x8OnForSubmode(dhbSubmode))) { return TRANS_NOT_ALLOWED; } - if ((((submode >> X8_ON) & 1) == 1) and - ((dhbSubmode & 0b11) != ((1 << SOLID_STATE_RELAYS_ADC_ON) | (1 << DRO_ON)))) { + if (txOnForSubmode(commandedSubmode) and + (not droOnForSubmode(dhbSubmode) or not x8OnForSubmode(dhbSubmode) or + not txOnForSubmode(dhbSubmode))) { return TRANS_NOT_ALLOWED; } - if (((((submode >> TX_ON) & 1) == 1) and - ((dhbSubmode & 0b111) != - ((1 << X8_ON) | (1 << DRO_ON) | (1 << SOLID_STATE_RELAYS_ADC_ON))))) { - return TRANS_NOT_ALLOWED; - } - if ((((submode >> MPA_ON) & 1) == 1 and - ((dhbSubmode & 0b1111) != - ((1 << TX_ON) | (1 << X8_ON) | (1 << DRO_ON) | (1 << SOLID_STATE_RELAYS_ADC_ON))))) { - return TRANS_NOT_ALLOWED; - } - if ((((submode >> HPA_ON) & 1) == 1 and - ((dhbSubmode & 0b11111) != ((1 << MPA_ON) | (1 << TX_ON) | (1 << X8_ON) | (1 << DRO_ON) | - (1 << SOLID_STATE_RELAYS_ADC_ON))))) { + if (hpaOnForSubmode(commandedSubmode) and + (not droOnForSubmode(dhbSubmode) or not x8OnForSubmode(dhbSubmode) or + not txOnForSubmode(dhbSubmode) or not mpaOnForSubmode(dhbSubmode))) { return TRANS_NOT_ALLOWED; } return returnvalue::OK; } - return DeviceHandlerBase::isModeCombinationValid(mode, submode); + return DeviceHandlerBase::checkModeCommand(commandedMode, commandedSubmode, msToReachTheMode); +} + +bool PayloadPcduHandler::ssrOnForSubmode(uint8_t submode) { + return (submode & plpcdu::SOLID_STATE_RELAYS_ADC_ON) == plpcdu::SOLID_STATE_RELAYS_ADC_ON; +} +bool PayloadPcduHandler::droOnForSubmode(uint8_t submode) { + return (submode & plpcdu::DRO_ON) == plpcdu::DRO_ON; +} + +bool PayloadPcduHandler::x8OnForSubmode(uint8_t submode) { + return (submode & plpcdu::X8_ON) == plpcdu::X8_ON; +} + +bool PayloadPcduHandler::txOnForSubmode(uint8_t submode) { + return (submode & plpcdu::TX_ON) == plpcdu::TX_ON; +} + +bool PayloadPcduHandler::mpaOnForSubmode(uint8_t submode) { + return (submode & plpcdu::MPA_ON) == plpcdu::MPA_ON; +} + +bool PayloadPcduHandler::hpaOnForSubmode(uint8_t submode) { + return (submode & plpcdu::HPA_ON) == plpcdu::HPA_ON; } ReturnValue_t PayloadPcduHandler::serializeFloat(uint32_t& param, float val) { @@ -696,7 +712,7 @@ ReturnValue_t PayloadPcduHandler::getParameter(uint8_t domainId, uint8_t uniqueI if (result != returnvalue::OK) { return result; } - if(newValue > 1) { + if (newValue > 1) { return HasParametersIF::INVALID_VALUE; } parameterWrapper->set(&disableChannelOrderCheck); diff --git a/mission/payload/PayloadPcduHandler.h b/mission/payload/PayloadPcduHandler.h index 088ef8b9..da9da1e1 100644 --- a/mission/payload/PayloadPcduHandler.h +++ b/mission/payload/PayloadPcduHandler.h @@ -137,6 +137,10 @@ class PayloadPcduHandler : public DeviceHandlerBase { PoolEntry({0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0}); PoolEntry tempC = PoolEntry({0.0}); + /** + * This parameter disables all checks for the channels except the SSR on check. The SSR on check + * is kept to ensure that there is a common start point where the ADC is enabled. + */ uint8_t disableChannelOrderCheck = false; void updateSwitchGpio(gpioId_t id, gpio::Levels level); @@ -157,7 +161,6 @@ class PayloadPcduHandler : public DeviceHandlerBase { uint32_t getTransitionDelayMs(Mode_t modeFrom, Mode_t modeTo) override; ReturnValue_t initializeLocalDataPool(localpool::DataPool& localDataPoolMap, LocalDataPoolManager& poolManager) override; - ReturnValue_t isModeCombinationValid(Mode_t mode, Submode_t submode) override; ReturnValue_t getParameter(uint8_t domainId, uint8_t uniqueId, ParameterWrapper* parameterWrapper, const ParameterWrapper* newValues, uint16_t startAtIndex) override; @@ -179,6 +182,12 @@ class PayloadPcduHandler : public DeviceHandlerBase { pwrctrl::EnablePl enablePl = pwrctrl::EnablePl(objects::POWER_CONTROLLER); ReturnValue_t checkModeCommand(Mode_t commandedMode, Submode_t commandedSubmode, uint32_t* msToReachTheMode) override; + static bool ssrOnForSubmode(uint8_t submode); + static bool droOnForSubmode(uint8_t submode); + static bool x8OnForSubmode(uint8_t submode); + static bool txOnForSubmode(uint8_t submode); + static bool mpaOnForSubmode(uint8_t submode); + static bool hpaOnForSubmode(uint8_t submode); }; #endif /* LINUX_DEVICES_PLPCDUHANDLER_H_ */