diff --git a/common/config/commonSubsystemIds.h b/common/config/commonSubsystemIds.h index 554f4812..0e64e634 100644 --- a/common/config/commonSubsystemIds.h +++ b/common/config/commonSubsystemIds.h @@ -21,6 +21,7 @@ enum: uint8_t { STR_HELPER = 120, PL_PCDU_HANDLER = 121, ACS_BOARD_ASS = 122, + SUS_BOARD_ASS = 123, COMMON_SUBSYSTEM_ID_END }; } diff --git a/mission/system/AcsBoardAssembly.cpp b/mission/system/AcsBoardAssembly.cpp index 76e2d916..903202b3 100644 --- a/mission/system/AcsBoardAssembly.cpp +++ b/mission/system/AcsBoardAssembly.cpp @@ -201,14 +201,6 @@ ReturnValue_t AcsBoardAssembly::handleNormalOrOnModeCmd(Mode_t mode, Submode_t s return result; } -ReturnValue_t AcsBoardAssembly::isModeCombinationValid(Mode_t mode, Submode_t submode) { - using namespace duallane; - if (submode != A_SIDE and submode != B_SIDE and submode != DUAL_MODE) { - return HasReturnvaluesIF::RETURN_FAILED; - } - return HasReturnvaluesIF::RETURN_OK; -} - void AcsBoardAssembly::handleChildrenLostMode(ReturnValue_t result) { using namespace duallane; // Some ACS board components are required for Safe-Mode. It would be good if the software diff --git a/mission/system/AcsBoardAssembly.h b/mission/system/AcsBoardAssembly.h index 20b8d748..788a7227 100644 --- a/mission/system/AcsBoardAssembly.h +++ b/mission/system/AcsBoardAssembly.h @@ -115,7 +115,6 @@ class AcsBoardAssembly : public DualLaneAssemblyBase { // AssemblyBase overrides ReturnValue_t commandChildren(Mode_t mode, Submode_t submode) override; ReturnValue_t checkChildrenStateOn(Mode_t wantedMode, Submode_t wantedSubmode) override; - ReturnValue_t isModeCombinationValid(Mode_t mode, Submode_t submode) override; void handleModeTransitionFailed(ReturnValue_t result) override; void handleChildrenLostMode(ReturnValue_t result) override; diff --git a/mission/system/DualLaneAssemblyBase.cpp b/mission/system/DualLaneAssemblyBase.cpp index 8ed549b1..24759f58 100644 --- a/mission/system/DualLaneAssemblyBase.cpp +++ b/mission/system/DualLaneAssemblyBase.cpp @@ -79,6 +79,14 @@ ReturnValue_t DualLaneAssemblyBase::pwrStateMachineWrapper() { return RETURN_OK; } +ReturnValue_t DualLaneAssemblyBase::isModeCombinationValid(Mode_t mode, Submode_t submode) { + using namespace duallane; + if (submode != A_SIDE and submode != B_SIDE and submode != DUAL_MODE) { + return HasReturnvaluesIF::RETURN_FAILED; + } + return HasReturnvaluesIF::RETURN_OK; +} + void DualLaneAssemblyBase::handleModeReached() { using namespace duallane; if (targetMode == MODE_OFF) { diff --git a/mission/system/DualLaneAssemblyBase.h b/mission/system/DualLaneAssemblyBase.h index 79037efa..78d47437 100644 --- a/mission/system/DualLaneAssemblyBase.h +++ b/mission/system/DualLaneAssemblyBase.h @@ -14,9 +14,6 @@ class DualLaneAssemblyBase : public AssemblyBase { pcduSwitches::Switches switch1, pcduSwitches::Switches switch2, Event pwrSwitchTimeoutEvent); - virtual void performChildOperation() override; - virtual void startTransition(Mode_t mode, Submode_t submode) override; - protected: // This helper object complete encapsulates power switching DualLanePowerStateMachine pwrStateMachine; @@ -37,6 +34,9 @@ class DualLaneAssemblyBase : public AssemblyBase { * @param submode */ virtual ReturnValue_t pwrStateMachineWrapper(); + virtual ReturnValue_t isModeCombinationValid(Mode_t mode, Submode_t submode) override; + virtual void performChildOperation() override; + virtual void startTransition(Mode_t mode, Submode_t submode) override; virtual void handleModeReached(); /** diff --git a/mission/system/SusAssembly.cpp b/mission/system/SusAssembly.cpp index 5da464fb..7f41f159 100644 --- a/mission/system/SusAssembly.cpp +++ b/mission/system/SusAssembly.cpp @@ -6,10 +6,13 @@ SusAssembly::SusAssembly(object_id_t objectId, object_id_t parentId, PowerSwitchIF* pwrSwitcher, SusAssHelper helper) - : AssemblyBase(objectId, parentId), helper(helper), pwrSwitcher(pwrSwitcher) { + : DualLaneAssemblyBase(objectId, parentId, pwrSwitcher, SWITCH_NOM, SWITCH_RED, + POWER_STATE_MACHINE_TIMEOUT), + helper(helper), + pwrSwitcher(pwrSwitcher) { ModeListEntry entry; for (uint8_t idx = 0; idx < NUMBER_SUN_SENSORS; idx++) { - initModeTableEntry(helper.susIds[idx], entry); + initModeTableEntry(helper.susIds[idx], entry, modeTable); } } @@ -34,6 +37,7 @@ ReturnValue_t SusAssembly::commandChildren(Mode_t mode, Submode_t submode) { } ReturnValue_t SusAssembly::handleNormalOrOnModeCmd(Mode_t mode, Submode_t submode) { + using namespace duallane; ReturnValue_t result = RETURN_OK; auto cmdSeq = [&](object_id_t objectId, uint8_t tableIdx) { if (mode == DeviceHandlerIF::MODE_NORMAL) { @@ -55,7 +59,7 @@ ReturnValue_t SusAssembly::handleNormalOrOnModeCmd(Mode_t mode, Submode_t submod } }; switch (submode) { - case (NOMINAL): { + case (A_SIDE): { for (uint8_t idx = 0; idx < NUMBER_SUN_SENSORS_ONE_SIDE; idx++) { cmdSeq(helper.susIds[idx], idx); // Switch off devices on redundant side @@ -64,7 +68,7 @@ ReturnValue_t SusAssembly::handleNormalOrOnModeCmd(Mode_t mode, Submode_t submod } return result; } - case (REDUNDANT): { + case (B_SIDE): { for (uint8_t idx = NUMBER_SUN_SENSORS_ONE_SIDE; idx < NUMBER_SUN_SENSORS; idx++) { cmdSeq(helper.susIds[idx], idx); // Switch devices on nominal side @@ -84,15 +88,16 @@ ReturnValue_t SusAssembly::handleNormalOrOnModeCmd(Mode_t mode, Submode_t submod } ReturnValue_t SusAssembly::checkChildrenStateOn(Mode_t wantedMode, Submode_t wantedSubmode) { + using namespace duallane; refreshHelperModes(); - if (wantedSubmode == NOMINAL) { + if (wantedSubmode == A_SIDE) { for (uint8_t idx = 0; idx < NUMBER_SUN_SENSORS_ONE_SIDE; idx++) { if (helper.susModes[idx] != wantedMode) { return NOT_ENOUGH_CHILDREN_IN_CORRECT_STATE; } } return RETURN_OK; - } else if (wantedSubmode == REDUNDANT) { + } else if (wantedSubmode == B_SIDE) { for (uint8_t idx = NUMBER_SUN_SENSORS_ONE_SIDE; idx < NUMBER_SUN_SENSORS; idx++) { if (helper.susModes[idx] != wantedMode) { return NOT_ENOUGH_CHILDREN_IN_CORRECT_STATE; @@ -108,13 +113,6 @@ ReturnValue_t SusAssembly::checkChildrenStateOn(Mode_t wantedMode, Submode_t wan return RETURN_OK; } -ReturnValue_t SusAssembly::isModeCombinationValid(Mode_t mode, Submode_t submode) { - if (submode != NOMINAL and submode != REDUNDANT and submode != DUAL_MODE) { - return HasReturnvaluesIF::RETURN_FAILED; - } - return HasReturnvaluesIF::RETURN_OK; -} - ReturnValue_t SusAssembly::initialize() { ReturnValue_t result = RETURN_OK; for (const auto& id : helper.susIds) { @@ -142,92 +140,13 @@ bool SusAssembly::isUseable(object_id_t object, Mode_t mode) { return false; } -void SusAssembly::powerStateMachine(Mode_t mode, Submode_t submode) { - ReturnValue_t switchStateNom = RETURN_OK; - ReturnValue_t switchStateRed = RETURN_OK; - if (state == States::IDLE or state == States::SWITCHING_POWER) { - switchStateNom = pwrSwitcher->getSwitchState(SWITCH_NOM); - switchStateRed = pwrSwitcher->getSwitchState(SWITCH_RED); - } else { - return; - } - if (mode == MODE_OFF) { - if (switchStateNom == PowerSwitchIF::SWITCH_OFF and - switchStateRed == PowerSwitchIF::SWITCH_OFF) { - state = States::MODE_COMMANDING; - return; - } - } else { - if (state == States::IDLE) { - if (mode == MODE_OFF) { - if (switchStateNom != PowerSwitchIF::SWITCH_OFF) { - pwrSwitcher->sendSwitchCommand(SWITCH_NOM, false); - } - if (switchStateRed != PowerSwitchIF::SWITCH_OFF) { - pwrSwitcher->sendSwitchCommand(SWITCH_RED, false); - } - } else { - switch (submode) { - case (NOMINAL): { - if (switchStateNom != PowerSwitchIF::SWITCH_ON) { - pwrSwitcher->sendSwitchCommand(SWITCH_NOM, true); - } - if (switchStateRed != PowerSwitchIF::SWITCH_OFF) { - pwrSwitcher->sendSwitchCommand(SWITCH_RED, false); - } - break; - } - case (REDUNDANT): { - if (switchStateRed != PowerSwitchIF::SWITCH_OFF) { - pwrSwitcher->sendSwitchCommand(SWITCH_RED, false); - } - if (switchStateNom != PowerSwitchIF::SWITCH_ON) { - pwrSwitcher->sendSwitchCommand(SWITCH_NOM, true); - } - break; - } - case (DUAL_MODE): { - if (switchStateNom != PowerSwitchIF::SWITCH_ON) { - pwrSwitcher->sendSwitchCommand(SWITCH_NOM, true); - } - if (switchStateRed != PowerSwitchIF::SWITCH_ON) { - pwrSwitcher->sendSwitchCommand(SWITCH_RED, true); - } - break; - } - } - } - state = States::SWITCHING_POWER; - } - if (state == States::SWITCHING_POWER) { - // TODO: Could check for a timeout (temporal or cycles) here and resend command - } - } -} - void SusAssembly::handleModeReached() { AssemblyBase::handleModeReached(); state = States::IDLE; } -void SusAssembly::handleModeTransitionFailed(ReturnValue_t result) { - // The sun-sensors are required for the Safe-Mode. It would be good if the software - // transitions from nominal side to redundant side and from redundant side to dual mode - // autonomously to ensure that that enough sensors are available witout an operators intervention. - // Therefore, the failure handler is overriden to perform these steps. - // TODO: Implement transitions mentioned above -} - void SusAssembly::refreshHelperModes() { for (uint8_t idx = 0; idx < helper.susModes.size(); idx++) { helper.susModes[idx] = childrenMap[helper.susIds[idx]].mode; } } - -void SusAssembly::initModeTableEntry(object_id_t id, ModeListEntry& entry) { - entry.setObject(id); - entry.setMode(MODE_OFF); - entry.setSubmode(SUBMODE_NONE); - entry.setInheritSubmode(false); - modeTable.insert(entry); -} diff --git a/mission/system/SusAssembly.h b/mission/system/SusAssembly.h index b4941724..37f3d3a5 100644 --- a/mission/system/SusAssembly.h +++ b/mission/system/SusAssembly.h @@ -4,6 +4,8 @@ #include #include +#include "DualLaneAssemblyBase.h" + struct SusAssHelper { public: SusAssHelper(std::array susIds) : susIds(susIds) {} @@ -13,14 +15,18 @@ struct SusAssHelper { class PowerSwitchIF; -class SusAssembly : AssemblyBase { +class SusAssembly : DualLaneAssemblyBase { public: static constexpr uint8_t NUMBER_SUN_SENSORS_ONE_SIDE = 6; static constexpr uint8_t NUMBER_SUN_SENSORS = 12; - static constexpr Submode_t NOMINAL = 0; - static constexpr Submode_t REDUNDANT = 1; - static constexpr Submode_t DUAL_MODE = 2; + static constexpr uint8_t SUBSYSTEM_ID = SUBSYSTEM_ID::SUS_BOARD_ASS; + static constexpr Event TRANSITION_OTHER_SIDE_FAILED = + event::makeEvent(SUBSYSTEM_ID, TRANSITION_OTHER_SIDE_FAILED_ID, severity::HIGH); + static constexpr Event NOT_ENOUGH_DEVICES_DUAL_MODE = + event::makeEvent(SUBSYSTEM_ID, NOT_ENOUGH_DEVICES_DUAL_MODE_ID, severity::HIGH); + static constexpr Event POWER_STATE_MACHINE_TIMEOUT = + event::makeEvent(SUBSYSTEM_ID, POWER_STATE_MACHINE_TIMEOUT_ID, severity::MEDIUM); SusAssembly(object_id_t objectId, object_id_t parentId, PowerSwitchIF* pwrSwitcher, SusAssHelper helper); @@ -54,7 +60,6 @@ class SusAssembly : AssemblyBase { bool isUseable(object_id_t object, Mode_t mode); void powerStateMachine(Mode_t mode, Submode_t submode); ReturnValue_t handleNormalOrOnModeCmd(Mode_t mode, Submode_t submode); - void initModeTableEntry(object_id_t id, ModeListEntry& entry); void refreshHelperModes(); };