From ce8253b9401377ac92df5555f1ca926ca7a32370 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Tue, 22 Mar 2022 15:49:22 +0100 Subject: [PATCH] TCS subsystem continued --- bsp_q7s/core/ObjectFactory.cpp | 70 +++++++++----------- bsp_q7s/core/ObjectFactory.h | 3 +- fsfw | 2 +- mission/system/CMakeLists.txt | 1 + mission/system/DualLaneAssemblyBase.cpp | 10 +-- mission/system/DualLanePowerStateMachine.cpp | 61 +++++------------ mission/system/DualLanePowerStateMachine.h | 17 ++--- mission/system/PowerStateMachineBase.cpp | 33 +++++++++ mission/system/PowerStateMachineBase.h | 31 +++++++++ mission/system/TcsSubsystem.cpp | 35 ++++++---- mission/system/TcsSubsystem.h | 22 +++--- mission/system/definitions.h | 9 ++- 12 files changed, 167 insertions(+), 127 deletions(-) create mode 100644 mission/system/PowerStateMachineBase.cpp create mode 100644 mission/system/PowerStateMachineBase.h diff --git a/bsp_q7s/core/ObjectFactory.cpp b/bsp_q7s/core/ObjectFactory.cpp index a9923a9d..4d190b0b 100644 --- a/bsp_q7s/core/ObjectFactory.cpp +++ b/bsp_q7s/core/ObjectFactory.cpp @@ -324,7 +324,8 @@ void ObjectFactory::createRadSensorComponent(LinuxLibgpioIF* gpioComIF) { #endif } -void ObjectFactory::createSunSensorComponents(LinuxLibgpioIF* gpioComIF, SpiComIF* spiComIF, PowerSwitchIF* pwrSwitcher) { +void ObjectFactory::createSunSensorComponents(LinuxLibgpioIF* gpioComIF, SpiComIF* spiComIF, + PowerSwitchIF* pwrSwitcher) { using namespace gpio; GpioCookie* gpioCookieSus = new GpioCookie(); GpioCallback* susgpio = nullptr; @@ -379,96 +380,85 @@ void ObjectFactory::createSunSensorComponents(LinuxLibgpioIF* gpioComIF, SpiComI susHandlers[0]->setParent(objects::SUS_BOARD_ASS); susHandlers[0]->setCustomFdir(fdir); - spiCookie = - new SpiCookie(addresses::SUS_1, gpioIds::CS_SUS_1, q7s::SPI_DEFAULT_DEV, SUS::MAX_CMD_SIZE, - spi::SUS_MAX_1227_MODE, spi::SUS_MAX1227_SPI_FREQ); + spiCookie = new SpiCookie(addresses::SUS_1, gpioIds::CS_SUS_1, q7s::SPI_DEFAULT_DEV, + SUS::MAX_CMD_SIZE, spi::SUS_MAX_1227_MODE, spi::SUS_MAX1227_SPI_FREQ); susHandlers[1] = new SusHandler(objects::SUS_1, 1, objects::SPI_COM_IF, spiCookie); fdir = new SusFdir(objects::SUS_1); susHandlers[1]->setParent(objects::SUS_BOARD_ASS); susHandlers[1]->setCustomFdir(fdir); - spiCookie = - new SpiCookie(addresses::SUS_2, gpioIds::CS_SUS_2, q7s::SPI_DEFAULT_DEV, SUS::MAX_CMD_SIZE, - spi::SUS_MAX_1227_MODE, spi::SUS_MAX1227_SPI_FREQ); + spiCookie = new SpiCookie(addresses::SUS_2, gpioIds::CS_SUS_2, q7s::SPI_DEFAULT_DEV, + SUS::MAX_CMD_SIZE, spi::SUS_MAX_1227_MODE, spi::SUS_MAX1227_SPI_FREQ); susHandlers[2] = new SusHandler(objects::SUS_2, 2, objects::SPI_COM_IF, spiCookie); fdir = new SusFdir(objects::SUS_2); susHandlers[2]->setParent(objects::SUS_BOARD_ASS); susHandlers[2]->setCustomFdir(fdir); - spiCookie = - new SpiCookie(addresses::SUS_3, gpioIds::CS_SUS_3, std::string(q7s::SPI_DEFAULT_DEV), - SUS::MAX_CMD_SIZE, spi::SUS_MAX_1227_MODE, spi::SUS_MAX1227_SPI_FREQ); + spiCookie = new SpiCookie(addresses::SUS_3, gpioIds::CS_SUS_3, std::string(q7s::SPI_DEFAULT_DEV), + SUS::MAX_CMD_SIZE, spi::SUS_MAX_1227_MODE, spi::SUS_MAX1227_SPI_FREQ); susHandlers[3] = new SusHandler(objects::SUS_3, 3, objects::SPI_COM_IF, spiCookie); fdir = new SusFdir(objects::SUS_3); susHandlers[3]->setParent(objects::SUS_BOARD_ASS); susHandlers[3]->setCustomFdir(fdir); - spiCookie = - new SpiCookie(addresses::SUS_4, gpioIds::CS_SUS_4, std::string(q7s::SPI_DEFAULT_DEV), - SUS::MAX_CMD_SIZE, spi::SUS_MAX_1227_MODE, spi::SUS_MAX1227_SPI_FREQ); + spiCookie = new SpiCookie(addresses::SUS_4, gpioIds::CS_SUS_4, std::string(q7s::SPI_DEFAULT_DEV), + SUS::MAX_CMD_SIZE, spi::SUS_MAX_1227_MODE, spi::SUS_MAX1227_SPI_FREQ); susHandlers[4] = new SusHandler(objects::SUS_4, 4, objects::SPI_COM_IF, spiCookie); fdir = new SusFdir(objects::SUS_4); susHandlers[4]->setParent(objects::SUS_BOARD_ASS); susHandlers[4]->setCustomFdir(fdir); - spiCookie = - new SpiCookie(addresses::SUS_5, gpioIds::CS_SUS_5, std::string(q7s::SPI_DEFAULT_DEV), - SUS::MAX_CMD_SIZE, spi::SUS_MAX_1227_MODE, spi::SUS_MAX1227_SPI_FREQ); + spiCookie = new SpiCookie(addresses::SUS_5, gpioIds::CS_SUS_5, std::string(q7s::SPI_DEFAULT_DEV), + SUS::MAX_CMD_SIZE, spi::SUS_MAX_1227_MODE, spi::SUS_MAX1227_SPI_FREQ); susHandlers[5] = new SusHandler(objects::SUS_5, 5, objects::SPI_COM_IF, spiCookie); fdir = new SusFdir(objects::SUS_5); susHandlers[5]->setParent(objects::SUS_BOARD_ASS); susHandlers[5]->setCustomFdir(fdir); - spiCookie = - new SpiCookie(addresses::SUS_6, gpioIds::CS_SUS_6, q7s::SPI_DEFAULT_DEV, SUS::MAX_CMD_SIZE, - spi::SUS_MAX_1227_MODE, spi::SUS_MAX1227_SPI_FREQ); + spiCookie = new SpiCookie(addresses::SUS_6, gpioIds::CS_SUS_6, q7s::SPI_DEFAULT_DEV, + SUS::MAX_CMD_SIZE, spi::SUS_MAX_1227_MODE, spi::SUS_MAX1227_SPI_FREQ); susHandlers[6] = new SusHandler(objects::SUS_6, 6, objects::SPI_COM_IF, spiCookie); fdir = new SusFdir(objects::SUS_6); susHandlers[6]->setParent(objects::SUS_BOARD_ASS); susHandlers[6]->setCustomFdir(fdir); - spiCookie = - new SpiCookie(addresses::SUS_7, gpioIds::CS_SUS_7, q7s::SPI_DEFAULT_DEV, SUS::MAX_CMD_SIZE, - spi::SUS_MAX_1227_MODE, spi::SUS_MAX1227_SPI_FREQ); - susHandlers[7] = new SusHandler(objects::SUS_7, 7, objects::SPI_COM_IF, spiCookie); + spiCookie = new SpiCookie(addresses::SUS_7, gpioIds::CS_SUS_7, q7s::SPI_DEFAULT_DEV, + SUS::MAX_CMD_SIZE, spi::SUS_MAX_1227_MODE, spi::SUS_MAX1227_SPI_FREQ); + susHandlers[7] = new SusHandler(objects::SUS_7, 7, objects::SPI_COM_IF, spiCookie); fdir = new SusFdir(objects::SUS_7); susHandlers[7]->setParent(objects::SUS_BOARD_ASS); susHandlers[7]->setCustomFdir(fdir); - spiCookie = - new SpiCookie(addresses::SUS_8, gpioIds::CS_SUS_8, q7s::SPI_DEFAULT_DEV, SUS::MAX_CMD_SIZE, - spi::SUS_MAX_1227_MODE, spi::SUS_MAX1227_SPI_FREQ); + spiCookie = new SpiCookie(addresses::SUS_8, gpioIds::CS_SUS_8, q7s::SPI_DEFAULT_DEV, + SUS::MAX_CMD_SIZE, spi::SUS_MAX_1227_MODE, spi::SUS_MAX1227_SPI_FREQ); susHandlers[8] = new SusHandler(objects::SUS_8, 8, objects::SPI_COM_IF, spiCookie); fdir = new SusFdir(objects::SUS_8); susHandlers[8]->setParent(objects::SUS_BOARD_ASS); susHandlers[8]->setCustomFdir(fdir); - spiCookie = - new SpiCookie(addresses::SUS_9, gpioIds::CS_SUS_9, q7s::SPI_DEFAULT_DEV, SUS::MAX_CMD_SIZE, - spi::SUS_MAX_1227_MODE, spi::SUS_MAX1227_SPI_FREQ); - susHandlers[9] = new SusHandler(objects::SUS_9, 9, objects::SPI_COM_IF, spiCookie); + spiCookie = new SpiCookie(addresses::SUS_9, gpioIds::CS_SUS_9, q7s::SPI_DEFAULT_DEV, + SUS::MAX_CMD_SIZE, spi::SUS_MAX_1227_MODE, spi::SUS_MAX1227_SPI_FREQ); + susHandlers[9] = new SusHandler(objects::SUS_9, 9, objects::SPI_COM_IF, spiCookie); fdir = new SusFdir(objects::SUS_9); susHandlers[9]->setParent(objects::SUS_BOARD_ASS); susHandlers[9]->setCustomFdir(fdir); - spiCookie = - new SpiCookie(addresses::SUS_10, gpioIds::CS_SUS_10, q7s::SPI_DEFAULT_DEV, SUS::MAX_CMD_SIZE, - spi::SUS_MAX_1227_MODE, spi::SUS_MAX1227_SPI_FREQ); - susHandlers[10] = new SusHandler(objects::SUS_10, 10, objects::SPI_COM_IF, spiCookie); + spiCookie = new SpiCookie(addresses::SUS_10, gpioIds::CS_SUS_10, q7s::SPI_DEFAULT_DEV, + SUS::MAX_CMD_SIZE, spi::SUS_MAX_1227_MODE, spi::SUS_MAX1227_SPI_FREQ); + susHandlers[10] = new SusHandler(objects::SUS_10, 10, objects::SPI_COM_IF, spiCookie); fdir = new SusFdir(objects::SUS_10); susHandlers[10]->setParent(objects::SUS_BOARD_ASS); susHandlers[10]->setCustomFdir(fdir); - spiCookie = - new SpiCookie(addresses::SUS_11, gpioIds::CS_SUS_11, q7s::SPI_DEFAULT_DEV, SUS::MAX_CMD_SIZE, - spi::SUS_MAX_1227_MODE, spi::SUS_MAX1227_SPI_FREQ); + spiCookie = new SpiCookie(addresses::SUS_11, gpioIds::CS_SUS_11, q7s::SPI_DEFAULT_DEV, + SUS::MAX_CMD_SIZE, spi::SUS_MAX_1227_MODE, spi::SUS_MAX1227_SPI_FREQ); susHandlers[11] = new SusHandler(objects::SUS_11, 11, objects::SPI_COM_IF, spiCookie); fdir = new SusFdir(objects::SUS_11); susHandlers[11]->setParent(objects::SUS_BOARD_ASS); susHandlers[11]->setCustomFdir(fdir); - for(auto& sus: susHandlers) { - if(sus != nullptr) { + for (auto& sus : susHandlers) { + if (sus != nullptr) { #if OBSW_TEST_SUS == 1 sus->setStartUpImmediately(); sus->setToGoToNormalMode(true); @@ -485,7 +475,7 @@ void ObjectFactory::createSunSensorComponents(LinuxLibgpioIF* gpioComIF, SpiComI SusAssHelper susAssHelper = SusAssHelper(susIds); auto susAss = new SusAssembly(objects::SUS_BOARD_ASS, objects::NO_OBJECT, pwrSwitcher, susAssHelper); - static_cast(susAss); + static_cast(susAss); #endif /* OBSW_ADD_SUN_SENSORS == 1 */ } diff --git a/bsp_q7s/core/ObjectFactory.h b/bsp_q7s/core/ObjectFactory.h index fc5fc1d8..a3ee6a7a 100644 --- a/bsp_q7s/core/ObjectFactory.h +++ b/bsp_q7s/core/ObjectFactory.h @@ -18,7 +18,8 @@ void createPcduComponents(LinuxLibgpioIF* gpioComIF, PowerSwitchIF** pwrSwitcher void createPlPcduComponents(LinuxLibgpioIF* gpioComIF, SpiComIF* spiComIF); void createTmpComponents(); void createRadSensorComponent(LinuxLibgpioIF* gpioComIF); -void createSunSensorComponents(LinuxLibgpioIF* gpioComIF, SpiComIF* spiComIF, PowerSwitchIF* pwrSwitcher); +void createSunSensorComponents(LinuxLibgpioIF* gpioComIF, SpiComIF* spiComIF, + PowerSwitchIF* pwrSwitcher); void createAcsBoardComponents(LinuxLibgpioIF* gpioComIF, UartComIF* uartComIF, PowerSwitchIF* pwrSwitcher); void createHeaterComponents(); diff --git a/fsfw b/fsfw index 16f2fa93..d791fc87 160000 --- a/fsfw +++ b/fsfw @@ -1 +1 @@ -Subproject commit 16f2fa9327393ba8848817cc5a22497201c41d13 +Subproject commit d791fc87b7bba11c1baa68d544cd991028ff3330 diff --git a/mission/system/CMakeLists.txt b/mission/system/CMakeLists.txt index f29f5336..6c284620 100644 --- a/mission/system/CMakeLists.txt +++ b/mission/system/CMakeLists.txt @@ -7,6 +7,7 @@ target_sources(${LIB_EIVE_MISSION} PRIVATE ComSubsystem.cpp TcsSubsystem.cpp DualLanePowerStateMachine.cpp + PowerStateMachineBase.cpp DualLaneAssemblyBase.cpp AcsBoardFdir.cpp diff --git a/mission/system/DualLaneAssemblyBase.cpp b/mission/system/DualLaneAssemblyBase.cpp index 3460d44f..fbd69d8f 100644 --- a/mission/system/DualLaneAssemblyBase.cpp +++ b/mission/system/DualLaneAssemblyBase.cpp @@ -63,8 +63,8 @@ bool DualLaneAssemblyBase::isUseable(object_id_t object, Mode_t mode) { } ReturnValue_t DualLaneAssemblyBase::pwrStateMachineWrapper() { - using namespace duallane; - OpCodes opCode = pwrStateMachine.powerStateMachine(); + using namespace power; + OpCodes opCode = pwrStateMachine.fsm(); if (customRecoveryStates == RecoveryCustomStates::IDLE) { if (opCode == OpCodes::NONE) { return RETURN_OK; @@ -163,7 +163,7 @@ void DualLaneAssemblyBase::handleModeTransitionFailed(ReturnValue_t result) { } bool DualLaneAssemblyBase::checkAndHandleRecovery() { - using namespace duallane; + using namespace power; OpCodes opCode = OpCodes::NONE; if (recoveryState == RECOVERY_IDLE) { return AssemblyBase::checkAndHandleRecovery(); @@ -173,14 +173,14 @@ bool DualLaneAssemblyBase::checkAndHandleRecovery() { customRecoveryStates = RecoveryCustomStates::POWER_SWITCHING_OFF; } if (customRecoveryStates == POWER_SWITCHING_OFF) { - opCode = pwrStateMachine.powerStateMachine(); + opCode = pwrStateMachine.fsm(); if (opCode == OpCodes::TO_OFF_DONE or opCode == OpCodes::TIMEOUT_OCCURED) { customRecoveryStates = RecoveryCustomStates::POWER_SWITCHING_ON; pwrStateMachine.start(targetMode, targetSubmode); } } if (customRecoveryStates == POWER_SWITCHING_ON) { - opCode = pwrStateMachine.powerStateMachine(); + opCode = pwrStateMachine.fsm(); if (opCode == OpCodes::TO_NOT_OFF_DONE or opCode == OpCodes::TIMEOUT_OCCURED) { customRecoveryStates = RecoveryCustomStates::DONE; } diff --git a/mission/system/DualLanePowerStateMachine.cpp b/mission/system/DualLanePowerStateMachine.cpp index e69f0310..666e1d1e 100644 --- a/mission/system/DualLanePowerStateMachine.cpp +++ b/mission/system/DualLanePowerStateMachine.cpp @@ -7,37 +7,16 @@ DualLanePowerStateMachine::DualLanePowerStateMachine(pcduSwitches::Switches swit pcduSwitches::Switches switchB, PowerSwitchIF* pwrSwitcher, dur_millis_t checkTimeout) - : SWITCH_A(switchA), SWITCH_B(switchB), pwrSwitcher(pwrSwitcher), checkTimeout(checkTimeout) {} + : PowerStateMachineBase(pwrSwitcher, checkTimeout), SWITCH_A(switchA), SWITCH_B(switchB) {} -void DualLanePowerStateMachine::setCheckTimeout(dur_millis_t timeout) { - checkTimeout.setTimeout(timeout); -} - -void DualLanePowerStateMachine::start(Mode_t mode, Submode_t submode) { - reset(); - checkTimeout.resetTimer(); - targetMode = mode; - targetSubmode = submode; - state = duallane::PwrStates::SWITCHING_POWER; -} - -duallane::PwrStates DualLanePowerStateMachine::getState() const { return state; } - -bool DualLanePowerStateMachine::active() { - if (state == duallane::PwrStates::IDLE or state == duallane::PwrStates::MODE_COMMANDING) { - return false; - } - return true; -} - -duallane::OpCodes DualLanePowerStateMachine::powerStateMachine() { +power::OpCodes DualLanePowerStateMachine::fsm() { using namespace duallane; ReturnValue_t switchStateA = RETURN_OK; ReturnValue_t switchStateB = RETURN_OK; - if (state == PwrStates::IDLE or state == PwrStates::MODE_COMMANDING) { + if (state == power::States::IDLE or state == power::States::MODE_COMMANDING) { return opResult; } - if (state == PwrStates::SWITCHING_POWER or state == PwrStates::CHECKING_POWER) { + if (state == power::States::SWITCHING_POWER or state == power::States::CHECKING_POWER) { switchStateA = pwrSwitcher->getSwitchState(SWITCH_A); switchStateB = pwrSwitcher->getSwitchState(SWITCH_B); } else { @@ -45,8 +24,8 @@ duallane::OpCodes DualLanePowerStateMachine::powerStateMachine() { } if (targetMode == HasModesIF::MODE_OFF) { if (switchStateA == PowerSwitchIF::SWITCH_OFF and switchStateB == PowerSwitchIF::SWITCH_OFF) { - state = PwrStates::IDLE; - opResult = OpCodes::TO_OFF_DONE; + state = power::States::IDLE; + opResult = power::OpCodes::TO_OFF_DONE; return opResult; } } else { @@ -54,8 +33,8 @@ duallane::OpCodes DualLanePowerStateMachine::powerStateMachine() { case (A_SIDE): { if (switchStateA == PowerSwitchIF::SWITCH_ON and switchStateB == PowerSwitchIF::SWITCH_OFF) { - state = PwrStates::MODE_COMMANDING; - opResult = OpCodes::TO_NOT_OFF_DONE; + state = power::States::MODE_COMMANDING; + opResult = power::OpCodes::TO_NOT_OFF_DONE; return opResult; } break; @@ -63,22 +42,22 @@ duallane::OpCodes DualLanePowerStateMachine::powerStateMachine() { case (B_SIDE): { if (switchStateA == PowerSwitchIF::SWITCH_OFF and switchStateB == PowerSwitchIF::SWITCH_ON) { - state = PwrStates::MODE_COMMANDING; - opResult = OpCodes::TO_NOT_OFF_DONE; + state = power::States::MODE_COMMANDING; + opResult = power::OpCodes::TO_NOT_OFF_DONE; return opResult; } break; } case (DUAL_MODE): { if (switchStateA == PowerSwitchIF::SWITCH_ON and switchStateB == PowerSwitchIF::SWITCH_ON) { - state = PwrStates::MODE_COMMANDING; - opResult = OpCodes::TO_NOT_OFF_DONE; + state = power::States::MODE_COMMANDING; + opResult = power::OpCodes::TO_NOT_OFF_DONE; return opResult; } } } } - if (state == PwrStates::SWITCHING_POWER) { + if (state == power::States::SWITCHING_POWER) { if (targetMode == HasModesIF::MODE_OFF) { if (switchStateA != PowerSwitchIF::SWITCH_OFF) { pwrSwitcher->sendSwitchCommand(SWITCH_A, PowerSwitchIF::SWITCH_OFF); @@ -121,20 +100,12 @@ duallane::OpCodes DualLanePowerStateMachine::powerStateMachine() { } } } - state = PwrStates::CHECKING_POWER; + state = power::States::CHECKING_POWER; } - if (state == PwrStates::CHECKING_POWER) { + if (state == power::States::CHECKING_POWER) { if (checkTimeout.hasTimedOut()) { - return OpCodes::TIMEOUT_OCCURED; + return power::OpCodes::TIMEOUT_OCCURED; } } return opResult; } - -void DualLanePowerStateMachine::reset() { - state = duallane::PwrStates::IDLE; - opResult = duallane::OpCodes::NONE; - targetMode = HasModesIF::MODE_OFF; - targetSubmode = 0; - checkTimeout.resetTimer(); -} diff --git a/mission/system/DualLanePowerStateMachine.h b/mission/system/DualLanePowerStateMachine.h index bf8679c4..e22e7ae4 100644 --- a/mission/system/DualLanePowerStateMachine.h +++ b/mission/system/DualLanePowerStateMachine.h @@ -3,32 +3,23 @@ #include #include +#include #include "definitions.h" class AssemblyBase; class PowerSwitchIF; -class DualLanePowerStateMachine : public HasReturnvaluesIF { +class DualLanePowerStateMachine : public PowerStateMachineBase { public: DualLanePowerStateMachine(pcduSwitches::Switches switchA, pcduSwitches::Switches switchB, PowerSwitchIF* pwrSwitcher, dur_millis_t checkTimeout = 5000); - void setCheckTimeout(dur_millis_t timeout); - void reset(); - void start(Mode_t mode, Submode_t submode); - bool active(); - duallane::PwrStates getState() const; - duallane::OpCodes powerStateMachine(); + power::OpCodes fsm() override; + const pcduSwitches::Switches SWITCH_A; const pcduSwitches::Switches SWITCH_B; private: - duallane::OpCodes opResult = duallane::OpCodes::NONE; - duallane::PwrStates state = duallane::PwrStates::IDLE; - PowerSwitchIF* pwrSwitcher = nullptr; - Mode_t targetMode = HasModesIF::MODE_OFF; - Submode_t targetSubmode = 0; - Countdown checkTimeout; }; #endif /* MISSION_SYSTEM_DUALLANEPOWERSTATEMACHINE_H_ */ diff --git a/mission/system/PowerStateMachineBase.cpp b/mission/system/PowerStateMachineBase.cpp new file mode 100644 index 00000000..37bd91f2 --- /dev/null +++ b/mission/system/PowerStateMachineBase.cpp @@ -0,0 +1,33 @@ +#include "PowerStateMachineBase.h" + +PowerStateMachineBase::PowerStateMachineBase(PowerSwitchIF *pwrSwitcher, dur_millis_t checkTimeout) + : pwrSwitcher(pwrSwitcher), checkTimeout(checkTimeout) {} + +void PowerStateMachineBase::reset() { + state = power::States::IDLE; + opResult = power::OpCodes::NONE; + targetMode = HasModesIF::MODE_OFF; + targetSubmode = 0; + checkTimeout.resetTimer(); +} + +void PowerStateMachineBase::setCheckTimeout(dur_millis_t timeout) { + checkTimeout.setTimeout(timeout); +} + +void PowerStateMachineBase::start(Mode_t mode, Submode_t submode) { + reset(); + checkTimeout.resetTimer(); + targetMode = mode; + targetSubmode = submode; + state = power::States::SWITCHING_POWER; +} + +power::States PowerStateMachineBase::getState() const { return state; } + +bool PowerStateMachineBase::active() { + if (state == power::States::IDLE or state == power::States::MODE_COMMANDING) { + return false; + } + return true; +} diff --git a/mission/system/PowerStateMachineBase.h b/mission/system/PowerStateMachineBase.h new file mode 100644 index 00000000..3adeebb6 --- /dev/null +++ b/mission/system/PowerStateMachineBase.h @@ -0,0 +1,31 @@ +#ifndef MISSION_SYSTEM_POWERSTATEMACHINE_H_ +#define MISSION_SYSTEM_POWERSTATEMACHINE_H_ + +#include +#include +#include + +#include "definitions.h" + +class PowerStateMachineBase : public HasReturnvaluesIF { + public: + PowerStateMachineBase(PowerSwitchIF* pwrSwitcher, dur_millis_t checkTimeout); + + virtual power::OpCodes fsm() = 0; + + void setCheckTimeout(dur_millis_t timeout); + void reset(); + void start(Mode_t mode, Submode_t submode); + bool active(); + power::States getState() const; + + protected: + power::OpCodes opResult = power::OpCodes::NONE; + power::States state = power::States::IDLE; + PowerSwitchIF* pwrSwitcher = nullptr; + Mode_t targetMode = HasModesIF::MODE_OFF; + Submode_t targetSubmode = 0; + Countdown checkTimeout; +}; + +#endif /* MISSION_SYSTEM_POWERSTATEMACHINE_H_ */ diff --git a/mission/system/TcsSubsystem.cpp b/mission/system/TcsSubsystem.cpp index 0ff26c65..71b22c2d 100644 --- a/mission/system/TcsSubsystem.cpp +++ b/mission/system/TcsSubsystem.cpp @@ -1,23 +1,34 @@ #include "TcsSubsystem.h" -TcsSubsystem::TcsSubsystem(object_id_t objectId, object_id_t parentId, TcsBoardHelper helper) - : SubsystemBase(objectId, parentId, MODE_OFF, 24), helper(helper) { -} +#include -ReturnValue_t TcsSubsystem::handleCommandMessage(CommandMessage *message) { - return RETURN_OK; -} +TcsSubsystem::TcsSubsystem(object_id_t objectId, object_id_t parentId, PowerSwitchIF* pwrSwitcher, + power::Switch_t theSwitch, TcsBoardHelper helper) + : SubsystemBase(objectId, parentId, MODE_OFF, 24), + switcher(pwrSwitcher, theSwitch), + helper(helper) {} -void TcsSubsystem::performChildOperation() { -} +ReturnValue_t TcsSubsystem::handleCommandMessage(CommandMessage* message) { return RETURN_OK; } + +void TcsSubsystem::performChildOperation() {} ReturnValue_t TcsSubsystem::checkModeCommand(Mode_t mode, Submode_t submode, - uint32_t *msToReachTheMode) { - return RETURN_OK; + uint32_t* msToReachTheMode) { + if (mode == MODE_ON or mode == MODE_OFF or mode == DeviceHandlerIF::MODE_NORMAL) { + return RETURN_OK; + } + return HasModesIF::INVALID_MODE; } ReturnValue_t TcsSubsystem::initialize() { + ReturnValue_t result = RETURN_OK; + for (const auto& obj : helper.rtdIds) { + result = registerChild(obj); + if (result != HasReturnvaluesIF::RETURN_OK) { + return result; + } + } + return SubsystemBase::initialize(); } -void TcsSubsystem::startTransition(Mode_t mode, Submode_t submode) { -} +void TcsSubsystem::startTransition(Mode_t mode, Submode_t submode) {} diff --git a/mission/system/TcsSubsystem.h b/mission/system/TcsSubsystem.h index f6c2481f..7ccf51cf 100644 --- a/mission/system/TcsSubsystem.h +++ b/mission/system/TcsSubsystem.h @@ -1,31 +1,37 @@ #ifndef MISSION_SYSTEM_TCSSUBSYSTEM_H_ #define MISSION_SYSTEM_TCSSUBSYSTEM_H_ +#include +#include #include struct TcsBoardHelper { - TcsBoardHelper(std::array rtdIds): rtdIds(rtdIds) {} + TcsBoardHelper(std::array rtdIds) : rtdIds(rtdIds) {} std::array rtdIds = {}; }; -class TcsSubsystem: public SubsystemBase { -public: - TcsSubsystem(object_id_t objectId, object_id_t parentId, TcsBoardHelper helper); +class TcsSubsystem : public SubsystemBase { + public: + TcsSubsystem(object_id_t objectId, object_id_t parentId, PowerSwitchIF *pwrSwitcher, + power::Switch_t switcher, TcsBoardHelper helper); ReturnValue_t initialize() override; -private: + private: + static constexpr uint8_t NUMBER_RTDS = 16; + PowerSwitcher switcher; + TcsBoardHelper helper; + FixedArrayList modeTable; + ReturnValue_t handleCommandMessage(CommandMessage *message) override; void performChildOperation() override; ReturnValue_t checkModeCommand(Mode_t mode, Submode_t submode, - uint32_t *msToReachTheMode) override; + uint32_t *msToReachTheMode) override; void startTransition(Mode_t mode, Submode_t submode) override; - - TcsBoardHelper helper; }; #endif /* MISSION_SYSTEM_TCSSUBSYSTEM_H_ */ diff --git a/mission/system/definitions.h b/mission/system/definitions.h index 8b22e1f4..aee127bb 100644 --- a/mission/system/definitions.h +++ b/mission/system/definitions.h @@ -3,10 +3,15 @@ #include +namespace power { + +enum class States { IDLE, SWITCHING_POWER, CHECKING_POWER, MODE_COMMANDING }; +enum class OpCodes { NONE, TO_OFF_DONE, TO_NOT_OFF_DONE, TIMEOUT_OCCURED }; + +} // namespace power + namespace duallane { -enum class PwrStates { IDLE, SWITCHING_POWER, CHECKING_POWER, MODE_COMMANDING }; -enum class OpCodes { NONE, TO_OFF_DONE, TO_NOT_OFF_DONE, TIMEOUT_OCCURED }; enum Submodes : Submode_t { A_SIDE = 0, B_SIDE = 1, DUAL_MODE = 2 }; } // namespace duallane