diff --git a/mission/system/tree/acsModeTree.cpp b/mission/system/tree/acsModeTree.cpp index 0474d0a1..55b4ac70 100644 --- a/mission/system/tree/acsModeTree.cpp +++ b/mission/system/tree/acsModeTree.cpp @@ -94,7 +94,7 @@ auto ACS_TABLE_PTG_TARGET_INERTIAL_TGT = auto ACS_TABLE_PTG_TARGET_INERTIAL_TRANS_1 = std::make_pair((acs::AcsMode::PTG_INERTIAL << 24) | 3, FixedArrayList()); -void satsystem::acs::init() { +Subsystem& satsystem::acs::init() { ModeListEntry entry; const char* ctxc = "satsystem::acs::init: generic target"; // Insert Helper Table @@ -123,6 +123,7 @@ void satsystem::acs::init() { buildTargetPtNadirSequence(ACS_SUBSYSTEM, entry); buildTargetPtInertialSequence(ACS_SUBSYSTEM, entry); ACS_SUBSYSTEM.setInitialMode(::acs::AcsMode::SAFE); + return ACS_SUBSYSTEM; } namespace { diff --git a/mission/system/tree/acsModeTree.h b/mission/system/tree/acsModeTree.h index 134a86a7..27236fba 100644 --- a/mission/system/tree/acsModeTree.h +++ b/mission/system/tree/acsModeTree.h @@ -4,7 +4,7 @@ namespace satsystem { namespace acs { extern AcsSubsystem ACS_SUBSYSTEM; -void init(); +Subsystem& init(); } // namespace acs } // namespace satsystem diff --git a/mission/system/tree/comModeTree.cpp b/mission/system/tree/comModeTree.cpp index e08ba5ba..4474cc62 100644 --- a/mission/system/tree/comModeTree.cpp +++ b/mission/system/tree/comModeTree.cpp @@ -62,13 +62,14 @@ void buildTxAndRxDefaultRateSequence(Subsystem& ss, ModeListEntry& eh); } // namespace -void satsystem::com::init() { +Subsystem& satsystem::com::init() { ModeListEntry entry; buildRxOnlySequence(SUBSYSTEM, entry); buildTxAndRxLowRateSequence(SUBSYSTEM, entry); buildTxAndRxHighRateSequence(SUBSYSTEM, entry); buildTxAndRxDefaultRateSequence(SUBSYSTEM, entry); SUBSYSTEM.setInitialMode(NML, ::com::Submode::RX_ONLY); + return SUBSYSTEM; } namespace { diff --git a/mission/system/tree/comModeTree.h b/mission/system/tree/comModeTree.h index ccc7f15f..f4648598 100644 --- a/mission/system/tree/comModeTree.h +++ b/mission/system/tree/comModeTree.h @@ -8,7 +8,7 @@ namespace satsystem { namespace com { extern ComSubsystem SUBSYSTEM; -void init(); +Subsystem& init(); } // namespace com } // namespace satsystem diff --git a/mission/system/tree/payloadModeTree.cpp b/mission/system/tree/payloadModeTree.cpp index ccb3dd2c..5262c61e 100644 --- a/mission/system/tree/payloadModeTree.cpp +++ b/mission/system/tree/payloadModeTree.cpp @@ -20,7 +20,7 @@ void initEarthObsvSequence(Subsystem& ss, ModeListEntry& eh); void initScexSequence(Subsystem& ss, ModeListEntry& eh); } // namespace -Subsystem satsystem::pl::SUBSYSTEM = Subsystem(objects::PL_SUBSYSTEM, 12, 24); +PayloadSubsystem satsystem::pl::SUBSYSTEM = PayloadSubsystem(objects::PL_SUBSYSTEM, 12, 24); const auto check = subsystem::checkInsert; static const auto OFF = HasModesIF::MODE_OFF; @@ -77,7 +77,7 @@ auto PL_TABLE_SCEX_TGT = auto PL_TABLE_SCEX_TRANS_0 = std::make_pair((payload::Mode::SCEX << 24) | 2, FixedArrayList()); -void satsystem::pl::init() { +Subsystem& satsystem::pl::init() { ModeListEntry entry; initOffSequence(SUBSYSTEM, entry); initPlMpsocStreamSequence(SUBSYSTEM, entry); @@ -86,6 +86,7 @@ void satsystem::pl::init() { initEarthObsvSequence(SUBSYSTEM, entry); initScexSequence(SUBSYSTEM, entry); SUBSYSTEM.setInitialMode(OFF); + return SUBSYSTEM; } namespace { diff --git a/mission/system/tree/payloadModeTree.h b/mission/system/tree/payloadModeTree.h index d1eae4d7..55cd6991 100644 --- a/mission/system/tree/payloadModeTree.h +++ b/mission/system/tree/payloadModeTree.h @@ -1,15 +1,15 @@ #ifndef MISSION_SYSTEM_TREE_PAYLOADMODETREE_H_ #define MISSION_SYSTEM_TREE_PAYLOADMODETREE_H_ -#include +#include namespace satsystem { namespace pl { -extern Subsystem SUBSYSTEM; +extern PayloadSubsystem SUBSYSTEM; -void init(); +Subsystem& init(); } // namespace pl } // namespace satsystem diff --git a/mission/system/tree/system.cpp b/mission/system/tree/system.cpp index bf6cea9d..b176efe6 100644 --- a/mission/system/tree/system.cpp +++ b/mission/system/tree/system.cpp @@ -1,13 +1,99 @@ #include "system.h" +#include +#include +#include + #include "acsModeTree.h" #include "comModeTree.h" +#include "eive/objects.h" #include "payloadModeTree.h" #include "tcsModeTree.h" +#include "util.h" + +namespace { +// Alias for checker function +const auto check = subsystem::checkInsert; + +void buildSafeSequence(Subsystem& ss, ModeListEntry& eh); +} // namespace + +static const auto OFF = HasModesIF::MODE_OFF; +static const auto NML = DeviceHandlerIF::MODE_NORMAL; void satsystem::init() { - acs::init(); - pl::init(); - tcs::init(); - com::init(); + auto& acsSubsystem = acs::init(); + acsSubsystem.connectModeTreeParent(EIVE_SYSTEM); + auto& payloadSubsystem = pl::init(); + payloadSubsystem.connectModeTreeParent(EIVE_SYSTEM); + auto& tcsSubsystem = tcs::init(); + tcsSubsystem.connectModeTreeParent(EIVE_SYSTEM); + auto& comSubsystem = com::init(); + comSubsystem.connectModeTreeParent(EIVE_SYSTEM); + ModeListEntry entry; + buildSafeSequence(EIVE_SYSTEM, entry); } + +EiveSystem satsystem::EIVE_SYSTEM = EiveSystem(objects::EIVE_SYSTEM, 12, 24); + +auto EIVE_SEQUENCE_SAFE = std::make_pair(acs::AcsMode::SAFE, FixedArrayList()); +auto EIVE_TABLE_SAFE_TGT = + std::make_pair((acs::AcsMode::SAFE << 24) | 1, FixedArrayList()); +auto EIVE_TABLE_SAFE_TRANS_0 = + std::make_pair((acs::AcsMode::SAFE << 24) | 2, FixedArrayList()); +auto EIVE_TABLE_SAFE_TRANS_1 = + std::make_pair((acs::AcsMode::SAFE << 24) | 3, FixedArrayList()); + +auto EIVE_SEQUENCE_IDLE = + std::make_pair(acs::AcsMode::PTG_IDLE, FixedArrayList()); +auto EIVE_TABLE_IDLE_TGT = + std::make_pair((acs::AcsMode::PTG_IDLE << 24) | 1, FixedArrayList()); +auto EIVE_TABLE_IDLE_TRANS_0 = + std::make_pair((acs::AcsMode::PTG_IDLE << 24) | 2, FixedArrayList()); + +namespace { + +void buildSafeSequence(Subsystem& ss, ModeListEntry& eh) { + std::string context = "satsystem::buildSafeSequence"; + auto ctxc = context.c_str(); + // Insert Helper Table + auto iht = [&](object_id_t obj, Mode_t mode, Submode_t submode, ArrayList& table) { + eh.setObject(obj); + eh.setMode(mode); + eh.setSubmode(submode); + check(table.insert(eh), ctxc); + }; + // Insert Helper Sequence + auto ihs = [&](ArrayList& sequence, Mode_t tableId, uint32_t waitSeconds, + bool checkSuccess) { + eh.setTableId(tableId); + eh.setWaitSeconds(waitSeconds); + eh.setCheckSuccess(checkSuccess); + check(sequence.insert(eh), ctxc); + }; + + // Only tracks that payload is off + iht(objects::PL_SUBSYSTEM, OFF, 0, EIVE_TABLE_SAFE_TGT.second); + check(ss.addTable(TableEntry(EIVE_TABLE_IDLE_TGT.first, &EIVE_TABLE_IDLE_TGT.second)), ctxc); + + // Build SAFE transition 0 + iht(objects::TCS_SUBSYSTEM, NML, 0, EIVE_TABLE_SAFE_TRANS_0.second); + check(ss.addTable(TableEntry(EIVE_TABLE_SAFE_TRANS_0.first, &EIVE_TABLE_SAFE_TRANS_0.second)), + ctxc); + + // Build SAFE transition 1 + iht(objects::PL_SUBSYSTEM, OFF, 0, EIVE_TABLE_SAFE_TRANS_1.second); + iht(objects::ACS_SUBSYSTEM, acs::AcsMode::SAFE, 0, EIVE_TABLE_SAFE_TRANS_1.second); + check(ss.addTable(TableEntry(EIVE_TABLE_SAFE_TRANS_1.first, &EIVE_TABLE_SAFE_TRANS_1.second)), + ctxc); + + // Build Safe sequence + ihs(EIVE_SEQUENCE_SAFE.second, EIVE_TABLE_SAFE_TGT.first, 0, false); + ihs(EIVE_SEQUENCE_SAFE.second, EIVE_TABLE_SAFE_TRANS_0.first, 0, false); + ihs(EIVE_SEQUENCE_SAFE.second, EIVE_TABLE_SAFE_TRANS_1.first, 2, false); + check(ss.addSequence(SequenceEntry(EIVE_SEQUENCE_SAFE.first, &EIVE_SEQUENCE_SAFE.second, + EIVE_SEQUENCE_SAFE.first)), + ctxc); +} + +} // namespace diff --git a/mission/system/tree/system.h b/mission/system/tree/system.h index a8599121..b1c90c82 100644 --- a/mission/system/tree/system.h +++ b/mission/system/tree/system.h @@ -1,10 +1,14 @@ #ifndef MISSION_SYSTEM_TREE_SYSTEM_H_ #define MISSION_SYSTEM_TREE_SYSTEM_H_ +#include + namespace satsystem { void init(); -} +extern EiveSystem EIVE_SYSTEM; + +} // namespace satsystem #endif /* MISSION_SYSTEM_TREE_SYSTEM_H_ */ diff --git a/mission/system/tree/tcsModeTree.cpp b/mission/system/tree/tcsModeTree.cpp index 51b0ec79..96b936bf 100644 --- a/mission/system/tree/tcsModeTree.cpp +++ b/mission/system/tree/tcsModeTree.cpp @@ -27,11 +27,12 @@ auto TCS_TABLE_NORMAL_TGT = std::make_pair((NML << 24) | 1, FixedArrayList()); auto TCS_TABLE_NORMAL_TRANS_1 = std::make_pair((NML << 24) | 3, FixedArrayList()); -void satsystem::tcs::init() { +Subsystem& satsystem::tcs::init() { ModeListEntry entry; buildOffSequence(SUBSYSTEM, entry); buildNormalSequence(SUBSYSTEM, entry); SUBSYSTEM.setInitialMode(OFF); + return SUBSYSTEM; } namespace { diff --git a/mission/system/tree/tcsModeTree.h b/mission/system/tree/tcsModeTree.h index 33fe7701..af10e60b 100644 --- a/mission/system/tree/tcsModeTree.h +++ b/mission/system/tree/tcsModeTree.h @@ -6,7 +6,7 @@ namespace satsystem { namespace tcs { extern Subsystem SUBSYSTEM; -void init(); +Subsystem& init(); } // namespace tcs } // namespace satsystem diff --git a/tmtc b/tmtc index 8d23f29f..6db34aac 160000 --- a/tmtc +++ b/tmtc @@ -1 +1 @@ -Subproject commit 8d23f29f947e2a4f79e1fc0910cd9ad59a4fc346 +Subproject commit 6db34aacaabedf69f05b330d71e25cc7cedb5632