diff --git a/fsfw b/fsfw index e6130263..6ea1eabb 160000 --- a/fsfw +++ b/fsfw @@ -1 +1 @@ -Subproject commit e6130263ef144c5b1f6eafef734a0150a92d6cda +Subproject commit 6ea1eabb2dd3688f2c7db484cd141f15c9f4fe49 diff --git a/mission/devices/PayloadPcduHandler.cpp b/mission/devices/PayloadPcduHandler.cpp index e21c1467..b6c8a6a6 100644 --- a/mission/devices/PayloadPcduHandler.cpp +++ b/mission/devices/PayloadPcduHandler.cpp @@ -28,17 +28,39 @@ void PayloadPcduHandler::doStartUp() { // Config error sif::error << "PayloadPcduHandler::doStartUp: Invalid state" << std::endl; } - // TODO: Handle switching power on here - // TODO: Go to on mode here instead, indicating that the power is on - // We are now in ON mode - setMode(_MODE_TO_ON); + if (pwrStateMachine.getState() == power::States::IDLE) { + pwrStateMachine.start(MODE_ON, pwrSubmode); + } + auto opCode = pwrStateMachine.fsm(); + if (opCode == power::OpCodes::TO_NOT_OFF_DONE or opCode == power::OpCodes::TIMEOUT_OCCURED) { + pwrStateMachine.reset(); + quickTransitionAlreadyCalled = false; + setMode(_MODE_TO_ON); + } +} + +void PayloadPcduHandler::doShutDown() { + if (not quickTransitionAlreadyCalled) { + quickTransitionBackToOff(false, false); + quickTransitionAlreadyCalled = true; + } + if (pwrStateMachine.getState() == power::States::IDLE) { + pwrStateMachine.start(MODE_OFF, 0); + } + auto opCode = pwrStateMachine.fsm(); + if (opCode == power::OpCodes::TO_OFF_DONE or opCode == power::OpCodes::TIMEOUT_OCCURED) { + pwrStateMachine.reset(); + // No need to set mode _MODE_POWER_DOWN, power switching was already handled + setMode(MODE_OFF); + } } void PayloadPcduHandler::stateMachineToNormal(Mode_t modeFrom, Submode_t subModeFrom) { using namespace plpcdu; if (submode == plpcdu::NORMAL_ALL_ON or submode == plpcdu::NORMAL_ADC_ONLY) { if (state == States::PL_PCDU_OFF) { - // TODO: Config error, emit error printout + sif::error << "PayloadPcduHandler::stateMachineToNormal: Unexpected state PL_PCDU_OFF" + << "detected" << std::endl; setMode(MODE_OFF); } if (state == States::POWER_CHANNELS_ON) { @@ -215,11 +237,11 @@ void PayloadPcduHandler::stateMachineToNormal(Mode_t modeFrom, Submode_t subMode void PayloadPcduHandler::doTransition(Mode_t modeFrom, Submode_t subModeFrom) { if (mode == _MODE_TO_NORMAL) { stateMachineToNormal(modeFrom, subModeFrom); + return; } + DeviceHandlerBase::doTransition(modeFrom, subModeFrom); } -void PayloadPcduHandler::doShutDown() { transitionBackToOff(false); } - ReturnValue_t PayloadPcduHandler::buildNormalDeviceCommand(DeviceCommandId_t* id) { switch (adcState) { case (AdcStates::SEND_SETUP): { @@ -402,7 +424,7 @@ void PayloadPcduHandler::enablePeriodicPrintout(bool enable, uint8_t divider) { opDivider.setDivider(divider); } -void PayloadPcduHandler::transitionBackToOff(bool notifyFdir) { +void PayloadPcduHandler::quickTransitionBackToOff(bool startTransitionToOff, bool notifyFdir) { States currentState = state; gpioIF->pullLow(gpioIds::PLPCDU_ENB_HPA); gpioIF->pullLow(gpioIds::PLPCDU_ENB_MPA); @@ -414,7 +436,9 @@ void PayloadPcduHandler::transitionBackToOff(bool notifyFdir) { gpioIF->pullLow(gpioIds::PLPCDU_ENB_VBAT1); state = States::PL_PCDU_OFF; adcState = AdcStates::OFF; - setMode(MODE_OFF); + if (startTransitionToOff) { + startTransition(MODE_OFF, 0); + } if (notifyFdir) { triggerEvent(TRANSITION_BACK_TO_OFF, static_cast(currentState)); } @@ -568,7 +592,8 @@ bool PayloadPcduHandler::checkVoltage(float val, float lowerBound, float upperBo serializeFloat(p2, val); triggerEvent(event, tooLarge, p2); transitionOk = false; - transitionBackToOff(true); + quickTransitionBackToOff(true, true); + quickTransitionAlreadyCalled = true; return false; } return true; @@ -580,7 +605,8 @@ bool PayloadPcduHandler::checkCurrent(float val, float upperBound, Event event) serializeFloat(p2, val); triggerEvent(event, true, p2); transitionOk = false; - transitionBackToOff(true); + quickTransitionBackToOff(true, true); + quickTransitionAlreadyCalled = true; return false; } return true; @@ -670,7 +696,8 @@ void PayloadPcduHandler::handleFailureInjection(std::string output, Event event) << std::endl; triggerEvent(event, 0, 0); transitionOk = false; - transitionBackToOff(true); + quickTransitionBackToOff(true, true); + quickTransitionAlreadyCalled = true; droToX8InjectionRequested = false; } diff --git a/mission/devices/PayloadPcduHandler.h b/mission/devices/PayloadPcduHandler.h index 7a30e297..62c6f728 100644 --- a/mission/devices/PayloadPcduHandler.h +++ b/mission/devices/PayloadPcduHandler.h @@ -4,13 +4,14 @@ #include #include #include -#include #include "events/subsystemIdRanges.h" #include "fsfw/FSFW.h" #include "fsfw_hal/common/gpio/GpioIF.h" #include "mission/devices/devicedefinitions/payloadPcduDefinitions.h" #include "mission/memory/SdCardMountedIF.h" +#include "mission/system/DualLanePowerStateMachine.h" +#include "mission/system/definitions.h" #ifdef FSFW_OSAL_LINUX class SpiComIF; @@ -98,6 +99,8 @@ class PayloadPcduHandler : public DeviceHandlerBase { PL_PCDU_ON, } state = States::PL_PCDU_OFF; + duallane::Submodes pwrSubmode = duallane::Submodes::A_SIDE; + enum class AdcMode { EXT_CONV, INT_CONV } adcMode = AdcMode::INT_CONV; enum class MonitoringMode { NONE, CLOSE_TO_ZERO, NEGATIVE } monMode = MonitoringMode::NONE; @@ -130,6 +133,7 @@ class PayloadPcduHandler : public DeviceHandlerBase { GpioIF* gpioIF; SdCardMountedIF* sdcMan; plpcdu::PlPcduParameter params; + bool quickTransitionAlreadyCalled = true; PoolEntry channelValues = PoolEntry({0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}); PoolEntry processedValues = @@ -141,7 +145,7 @@ class PayloadPcduHandler : public DeviceHandlerBase { void doStartUp() override; void doShutDown() override; // Main FDIR function which goes from any PL PCDU state back to all off - void transitionBackToOff(bool notifyFdir); + void quickTransitionBackToOff(bool startTransitionToOff, bool notifyFdir); ReturnValue_t buildNormalDeviceCommand(DeviceCommandId_t* id) override; ReturnValue_t buildTransitionDeviceCommand(DeviceCommandId_t* id) override; void fillCommandAndReplyMap() override;