eive-obsw/mission/system/systemTree.cpp

198 lines
8.1 KiB
C++
Raw Normal View History

2023-04-06 16:50:33 +02:00
#include "systemTree.h"
2022-04-25 13:36:11 +02:00
2023-02-10 17:52:46 +01:00
#include <fsfw/devicehandlers/DeviceHandlerIF.h>
#include <fsfw/subsystem/Subsystem.h>
2023-03-24 20:50:33 +01:00
#include <mission/acs/defs.h>
2023-03-14 14:44:32 +01:00
#include <mission/sysDefs.h>
2023-03-24 20:50:33 +01:00
#include <mission/system/com/comModeTree.h>
2023-02-22 19:45:41 +01:00
2023-04-06 17:49:34 +02:00
#include <atomic>
2023-02-10 17:52:46 +01:00
#include "eive/objects.h"
2023-03-24 19:37:03 +01:00
#include "mission/com/defs.h"
2023-03-24 20:50:33 +01:00
#include "mission/system/acs/acsModeTree.h"
2023-04-13 23:54:23 +02:00
#include "mission/system/tcs/tcsModeTree.h"
2023-04-06 16:50:33 +02:00
#include "mission/system/tree/payloadModeTree.h"
#include "treeUtil.h"
2023-02-10 17:52:46 +01:00
namespace {
// Alias for checker function
const auto check = subsystem::checkInsert;
2023-03-14 14:44:32 +01:00
void buildBootSequence(Subsystem& ss, ModeListEntry& eh);
2023-02-10 17:52:46 +01:00
void buildSafeSequence(Subsystem& ss, ModeListEntry& eh);
2023-02-10 17:59:16 +01:00
void buildIdleSequence(Subsystem& ss, ModeListEntry& eh);
2023-02-10 17:52:46 +01:00
} // namespace
static const auto OFF = HasModesIF::MODE_OFF;
static const auto NML = DeviceHandlerIF::MODE_NORMAL;
2022-04-25 13:36:11 +02:00
void satsystem::init() {
2023-02-10 17:52:46 +01:00
auto& acsSubsystem = acs::init();
acsSubsystem.connectModeTreeParent(EIVE_SYSTEM);
2023-03-14 11:21:37 +01:00
auto& payloadSubsystem = payload::init();
2023-02-10 17:52:46 +01:00
payloadSubsystem.connectModeTreeParent(EIVE_SYSTEM);
auto& tcsSubsystem = tcs::init();
tcsSubsystem.connectModeTreeParent(EIVE_SYSTEM);
auto& comSubsystem = com::init();
comSubsystem.connectModeTreeParent(EIVE_SYSTEM);
ModeListEntry entry;
2023-03-14 14:44:32 +01:00
buildBootSequence(EIVE_SYSTEM, entry);
2023-02-10 17:52:46 +01:00
buildSafeSequence(EIVE_SYSTEM, entry);
2023-02-10 17:59:16 +01:00
buildIdleSequence(EIVE_SYSTEM, entry);
2023-03-14 14:44:32 +01:00
EIVE_SYSTEM.setInitialMode(satsystem::Mode::BOOT, 0);
2022-04-25 13:36:11 +02:00
}
2023-02-10 17:52:46 +01:00
2023-04-06 17:49:34 +02:00
EiveSystem satsystem::EIVE_SYSTEM = EiveSystem(objects::EIVE_SYSTEM, 12, 24, I2C_FATAL_ERRORS);
2023-02-10 17:52:46 +01:00
2023-03-14 14:44:32 +01:00
auto EIVE_SEQUENCE_BOOT = std::make_pair(satsystem::Mode::BOOT, FixedArrayList<ModeListEntry, 5>());
auto EIVE_TABLE_BOOT_TGT =
std::make_pair((satsystem::Mode::BOOT << 24) | 1, FixedArrayList<ModeListEntry, 5>());
auto EIVE_TABLE_BOOT_TRANS_0 =
std::make_pair((satsystem::Mode::BOOT << 24) | 2, FixedArrayList<ModeListEntry, 5>());
auto EIVE_SEQUENCE_SAFE = std::make_pair(satsystem::Mode::SAFE, FixedArrayList<ModeListEntry, 5>());
2023-02-10 17:52:46 +01:00
auto EIVE_TABLE_SAFE_TGT =
2023-03-14 14:44:32 +01:00
std::make_pair((satsystem::Mode::SAFE << 24) | 1, FixedArrayList<ModeListEntry, 5>());
2023-02-10 17:52:46 +01:00
auto EIVE_TABLE_SAFE_TRANS_0 =
2023-03-14 14:44:32 +01:00
std::make_pair((satsystem::Mode::SAFE << 24) | 2, FixedArrayList<ModeListEntry, 5>());
2023-02-10 17:52:46 +01:00
auto EIVE_TABLE_SAFE_TRANS_1 =
2023-03-14 14:44:32 +01:00
std::make_pair((satsystem::Mode::SAFE << 24) | 3, FixedArrayList<ModeListEntry, 5>());
2023-02-10 17:52:46 +01:00
auto EIVE_SEQUENCE_IDLE =
2023-03-14 14:44:32 +01:00
std::make_pair(satsystem::Mode::PTG_IDLE, FixedArrayList<ModeListEntry, 5>());
2023-02-10 17:52:46 +01:00
auto EIVE_TABLE_IDLE_TGT =
2023-03-14 14:44:32 +01:00
std::make_pair((satsystem::Mode::PTG_IDLE << 24) | 1, FixedArrayList<ModeListEntry, 5>());
2023-02-10 17:52:46 +01:00
auto EIVE_TABLE_IDLE_TRANS_0 =
2023-03-14 14:44:32 +01:00
std::make_pair((satsystem::Mode::PTG_IDLE << 24) | 2, FixedArrayList<ModeListEntry, 5>());
2023-02-10 17:59:16 +01:00
auto EIVE_TABLE_IDLE_TRANS_1 =
2023-03-14 14:44:32 +01:00
std::make_pair((satsystem::Mode::PTG_IDLE << 24) | 3, FixedArrayList<ModeListEntry, 5>());
2023-02-10 17:52:46 +01:00
namespace {
void buildSafeSequence(Subsystem& ss, ModeListEntry& eh) {
std::string context = "satsystem::buildSafeSequence";
auto ctxc = context.c_str();
// Insert Helper Table
2023-03-08 18:09:50 +01:00
auto iht = [&](object_id_t obj, Mode_t mode, Submode_t submode, ArrayList<ModeListEntry>& table,
bool allowAllSubmodes = false) {
2023-02-10 17:52:46 +01:00
eh.setObject(obj);
eh.setMode(mode);
eh.setSubmode(submode);
2023-03-08 18:09:50 +01:00
if (allowAllSubmodes) {
eh.allowAllSubmodes();
}
2023-02-10 17:52:46 +01:00
check(table.insert(eh), ctxc);
};
// Insert Helper Sequence
auto ihs = [&](ArrayList<ModeListEntry>& sequence, Mode_t tableId, uint32_t waitSeconds,
bool checkSuccess) {
eh.setTableId(tableId);
eh.setWaitSeconds(waitSeconds);
eh.setCheckSuccess(checkSuccess);
check(sequence.insert(eh), ctxc);
};
2023-03-10 13:17:46 +01:00
// Do no track submode to allow transitions to DETUMBLE submode.
iht(objects::ACS_SUBSYSTEM, acs::AcsMode::SAFE, 0, EIVE_TABLE_SAFE_TGT.second, true);
2023-02-10 17:52:46 +01:00
iht(objects::PL_SUBSYSTEM, OFF, 0, EIVE_TABLE_SAFE_TGT.second);
2023-02-10 17:59:16 +01:00
check(ss.addTable(TableEntry(EIVE_TABLE_SAFE_TGT.first, &EIVE_TABLE_SAFE_TGT.second)), ctxc);
2023-02-10 17:52:46 +01:00
2023-03-14 11:21:37 +01:00
// Build SAFE transition 0.
2023-02-10 17:52:46 +01:00
iht(objects::TCS_SUBSYSTEM, NML, 0, EIVE_TABLE_SAFE_TRANS_0.second);
2023-03-01 19:03:18 +01:00
iht(objects::PL_SUBSYSTEM, OFF, 0, EIVE_TABLE_SAFE_TRANS_0.second);
2023-03-08 18:09:50 +01:00
iht(objects::ACS_SUBSYSTEM, acs::AcsMode::SAFE, 0, EIVE_TABLE_SAFE_TRANS_0.second, true);
2023-02-10 17:52:46 +01:00
check(ss.addTable(TableEntry(EIVE_TABLE_SAFE_TRANS_0.first, &EIVE_TABLE_SAFE_TRANS_0.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);
check(ss.addSequence(SequenceEntry(EIVE_SEQUENCE_SAFE.first, &EIVE_SEQUENCE_SAFE.second,
EIVE_SEQUENCE_SAFE.first)),
ctxc);
}
2023-02-10 17:59:16 +01:00
void buildIdleSequence(Subsystem& ss, ModeListEntry& eh) {
std::string context = "satsystem::buildIdleSequence";
auto ctxc = context.c_str();
// Insert Helper Table
auto iht = [&](object_id_t obj, Mode_t mode, Submode_t submode, ArrayList<ModeListEntry>& table) {
eh.setObject(obj);
eh.setMode(mode);
eh.setSubmode(submode);
check(table.insert(eh), ctxc);
};
// Insert Helper Sequence
auto ihs = [&](ArrayList<ModeListEntry>& sequence, Mode_t tableId, uint32_t waitSeconds,
bool checkSuccess) {
eh.setTableId(tableId);
eh.setWaitSeconds(waitSeconds);
eh.setCheckSuccess(checkSuccess);
check(sequence.insert(eh), ctxc);
};
iht(objects::ACS_SUBSYSTEM, acs::AcsMode::PTG_IDLE, 0, EIVE_TABLE_IDLE_TGT.second);
check(ss.addTable(TableEntry(EIVE_TABLE_IDLE_TGT.first, &EIVE_TABLE_IDLE_TGT.second)), ctxc);
2023-03-08 18:09:50 +01:00
// Build IDLE transition 0
2023-02-10 17:59:16 +01:00
iht(objects::TCS_SUBSYSTEM, NML, 0, EIVE_TABLE_IDLE_TRANS_0.second);
2023-03-08 18:09:50 +01:00
iht(objects::PL_SUBSYSTEM, OFF, 0, EIVE_TABLE_IDLE_TRANS_0.second);
iht(objects::ACS_SUBSYSTEM, acs::AcsMode::PTG_IDLE, 0, EIVE_TABLE_IDLE_TRANS_0.second);
2023-02-10 17:59:16 +01:00
check(ss.addTable(TableEntry(EIVE_TABLE_IDLE_TRANS_0.first, &EIVE_TABLE_IDLE_TRANS_0.second)),
ctxc);
2023-03-08 18:09:50 +01:00
// Build IDLE sequence
2023-02-10 17:59:16 +01:00
ihs(EIVE_SEQUENCE_IDLE.second, EIVE_TABLE_IDLE_TGT.first, 0, false);
ihs(EIVE_SEQUENCE_IDLE.second, EIVE_TABLE_IDLE_TRANS_0.first, 0, false);
check(ss.addSequence(SequenceEntry(EIVE_SEQUENCE_IDLE.first, &EIVE_SEQUENCE_IDLE.second,
2023-02-10 17:59:37 +01:00
EIVE_SEQUENCE_SAFE.first)),
2023-02-10 17:59:16 +01:00
ctxc);
}
2023-03-14 14:44:32 +01:00
void buildBootSequence(Subsystem& ss, ModeListEntry& eh) {
std::string context = "satsystem::buildBootSequence";
auto ctxc = context.c_str();
// Insert Helper Table
auto iht = [&](object_id_t obj, Mode_t mode, Submode_t submode, ArrayList<ModeListEntry>& table,
bool allowAllSubmodes = false) {
eh.setObject(obj);
eh.setMode(mode);
eh.setSubmode(submode);
if (allowAllSubmodes) {
eh.allowAllSubmodes();
}
check(table.insert(eh), ctxc);
};
// Insert Helper Sequence
auto ihs = [&](ArrayList<ModeListEntry>& sequence, Mode_t tableId, uint32_t waitSeconds,
bool checkSuccess) {
eh.setTableId(tableId);
eh.setWaitSeconds(waitSeconds);
eh.setCheckSuccess(checkSuccess);
check(sequence.insert(eh), ctxc);
};
iht(objects::ACS_SUBSYSTEM, acs::AcsMode::OFF, 0, EIVE_TABLE_BOOT_TGT.second, true);
iht(objects::PL_SUBSYSTEM, OFF, 0, EIVE_TABLE_BOOT_TGT.second);
2023-03-15 16:21:05 +01:00
iht(objects::COM_SUBSYSTEM, com::RX_ONLY, 0, EIVE_TABLE_BOOT_TGT.second);
iht(objects::TCS_SUBSYSTEM, OFF, 0, EIVE_TABLE_BOOT_TGT.second);
2023-03-14 14:44:32 +01:00
check(ss.addTable(TableEntry(EIVE_TABLE_BOOT_TGT.first, &EIVE_TABLE_BOOT_TGT.second)), ctxc);
// Build SAFE transition 0.
iht(objects::TCS_SUBSYSTEM, OFF, 0, EIVE_TABLE_BOOT_TRANS_0.second);
iht(objects::COM_SUBSYSTEM, com::RX_ONLY, 0, EIVE_TABLE_BOOT_TRANS_0.second);
iht(objects::PL_SUBSYSTEM, OFF, 0, EIVE_TABLE_BOOT_TRANS_0.second);
iht(objects::ACS_SUBSYSTEM, acs::AcsMode::OFF, 0, EIVE_TABLE_BOOT_TRANS_0.second, true);
check(ss.addTable(TableEntry(EIVE_TABLE_BOOT_TRANS_0.first, &EIVE_TABLE_BOOT_TRANS_0.second)),
ctxc);
// Build Safe sequence
ihs(EIVE_SEQUENCE_BOOT.second, EIVE_TABLE_BOOT_TGT.first, 0, false);
ihs(EIVE_SEQUENCE_BOOT.second, EIVE_TABLE_BOOT_TRANS_0.first, 0, false);
check(ss.addSequence(SequenceEntry(EIVE_SEQUENCE_BOOT.first, &EIVE_SEQUENCE_BOOT.second,
EIVE_SEQUENCE_SAFE.first)),
ctxc);
2023-03-14 15:08:56 +01:00
}
2023-02-10 17:52:46 +01:00
} // namespace