diff --git a/src/fsfw/controller/ControllerBase.cpp b/src/fsfw/controller/ControllerBase.cpp index ee1dba46..7c2456af 100644 --- a/src/fsfw/controller/ControllerBase.cpp +++ b/src/fsfw/controller/ControllerBase.cpp @@ -102,6 +102,10 @@ const HasHealthIF* ControllerBase::getOptHealthIF() const { return this; } const HasModesIF& ControllerBase::getModeIF() const { return *this; } +ModeTreeChildIF& ControllerBase::getModeTreeChildIF() { + return *this; +} + ReturnValue_t ControllerBase::connectModeTreeParent(HasModeTreeChildrenIF& parent) { return modetree::connectModeTreeParent(parent, *this, healthHelper, modeHelper); } diff --git a/src/fsfw/controller/ControllerBase.h b/src/fsfw/controller/ControllerBase.h index 6d9e2937..0250cd89 100644 --- a/src/fsfw/controller/ControllerBase.h +++ b/src/fsfw/controller/ControllerBase.h @@ -8,7 +8,7 @@ #include "fsfw/objectmanager/SystemObject.h" #include "fsfw/subsystem/HasModeTreeChildrenIF.h" #include "fsfw/subsystem/ModeTreeChildIF.h" -#include "fsfw/subsystem/modes/ModeTreeConnectionIF.h" +#include "fsfw/subsystem/ModeTreeConnectionIF.h" #include "fsfw/tasks/ExecutableObjectIF.h" #include "fsfw/tasks/PeriodicTaskIF.h" @@ -31,6 +31,7 @@ class ControllerBase : public HasModesIF, ~ControllerBase() override; ReturnValue_t connectModeTreeParent(HasModeTreeChildrenIF &parent) override; + ModeTreeChildIF& getModeTreeChildIF() override; /** SystemObject override */ ReturnValue_t initialize() override; diff --git a/src/fsfw/devicehandlers/ChildHandlerBase.cpp b/src/fsfw/devicehandlers/ChildHandlerBase.cpp index 50d7b765..37af39dc 100644 --- a/src/fsfw/devicehandlers/ChildHandlerBase.cpp +++ b/src/fsfw/devicehandlers/ChildHandlerBase.cpp @@ -3,11 +3,11 @@ #include "fsfw/subsystem/SubsystemBase.h" ChildHandlerBase::ChildHandlerBase(object_id_t setObjectId, object_id_t deviceCommunication, - CookieIF* cookie, object_id_t parent, + CookieIF* cookie, HasModeTreeChildrenIF& parent, FailureIsolationBase* customFdir, size_t cmdQueueSize) : DeviceHandlerBase(setObjectId, deviceCommunication, cookie, (customFdir == nullptr ? &childHandlerFdir : customFdir), cmdQueueSize), - parentId(parent), + parent(parent), childHandlerFdir(setObjectId) {} ChildHandlerBase::~ChildHandlerBase() {} @@ -18,22 +18,5 @@ ReturnValue_t ChildHandlerBase::initialize() { return result; } - // TODO: Fix this - // MessageQueueId_t parentQueue = 0; - // - // if (parentId != objects::NO_OBJECT) { - // SubsystemBase* parent = ObjectManager::instance()->get(parentId); - // if (parent == NULL) { - // return returnvalue::FAILED; - // } - // parentQueue = parent->getCommandQueue(); - // - // parent->registerChild(getObjectId()); - // } - // - // healthHelper.setParentQueue(parentQueue); - // - // modeHelper.setParentQueue(parentQueue); - - return returnvalue::OK; + return DeviceHandlerBase::connectModeTreeParent(parent); } diff --git a/src/fsfw/devicehandlers/ChildHandlerBase.h b/src/fsfw/devicehandlers/ChildHandlerBase.h index 8145c391..b9f991d6 100644 --- a/src/fsfw/devicehandlers/ChildHandlerBase.h +++ b/src/fsfw/devicehandlers/ChildHandlerBase.h @@ -1,13 +1,14 @@ #ifndef FSFW_DEVICEHANDLER_CHILDHANDLERBASE_H_ #define FSFW_DEVICEHANDLER_CHILDHANDLERBASE_H_ +#include #include "ChildHandlerFDIR.h" #include "DeviceHandlerBase.h" class ChildHandlerBase : public DeviceHandlerBase { public: ChildHandlerBase(object_id_t setObjectId, object_id_t deviceCommunication, CookieIF* cookie, - object_id_t parent = objects::NO_OBJECT, + HasModeTreeChildrenIF& parent, FailureIsolationBase* customFdir = nullptr, size_t cmdQueueSize = 20); virtual ~ChildHandlerBase(); @@ -15,7 +16,7 @@ class ChildHandlerBase : public DeviceHandlerBase { virtual ReturnValue_t initialize(); protected: - const uint32_t parentId; + HasModeTreeChildrenIF& parent; ChildHandlerFDIR childHandlerFdir; }; diff --git a/src/fsfw/devicehandlers/DeviceHandlerBase.cpp b/src/fsfw/devicehandlers/DeviceHandlerBase.cpp index 851fb6ec..cdfec03b 100644 --- a/src/fsfw/devicehandlers/DeviceHandlerBase.cpp +++ b/src/fsfw/devicehandlers/DeviceHandlerBase.cpp @@ -1,5 +1,6 @@ -#include "fsfw/devicehandlers/DeviceHandlerBase.h" +#include "DeviceHandlerBase.h" +#include "fsfw/subsystem/helper.h" #include "fsfw/datapoollocal/LocalPoolVariable.h" #include "fsfw/devicehandlers/AcceptsDeviceResponsesIF.h" #include "fsfw/devicehandlers/DeviceTmReportingWrapper.h" @@ -1591,3 +1592,19 @@ void DeviceHandlerBase::disableCommandsAndReplies() { } } } + +ReturnValue_t DeviceHandlerBase::connectModeTreeParent(HasModeTreeChildrenIF &parent) { + return modetree::connectModeTreeParent(parent, *this, healthHelper, modeHelper); +} + +const HasHealthIF* DeviceHandlerBase::getOptHealthIF() const { + return this; +} + +const HasModesIF& DeviceHandlerBase::getModeIF() const { + return *this; +} + +ModeTreeChildIF& DeviceHandlerBase::getModeTreeChildIF() { + return *this; +} diff --git a/src/fsfw/devicehandlers/DeviceHandlerBase.h b/src/fsfw/devicehandlers/DeviceHandlerBase.h index 52ae473b..f9c776e0 100644 --- a/src/fsfw/devicehandlers/DeviceHandlerBase.h +++ b/src/fsfw/devicehandlers/DeviceHandlerBase.h @@ -11,6 +11,7 @@ #include "fsfw/action/HasActionsIF.h" #include "fsfw/datapool/PoolVariableIF.h" #include "fsfw/datapoollocal/HasLocalDataPoolIF.h" +#include "fsfw/subsystem/ModeTreeConnectionIF.h" #include "fsfw/datapoollocal/LocalDataPoolManager.h" #include "fsfw/health/HealthHelper.h" #include "fsfw/ipc/MessageQueueIF.h" @@ -84,6 +85,8 @@ class DeviceHandlerBase : public DeviceHandlerIF, public HasModesIF, public HasHealthIF, public HasActionsIF, + public ModeTreeChildIF, + public ModeTreeConnectionIF, public ReceivesParameterMessagesIF, public HasLocalDataPoolIF { friend void(Factory::setStaticFrameworkObjectIds)(); @@ -120,6 +123,10 @@ class DeviceHandlerBase : public DeviceHandlerIF, lp_id_t thermalStatePoolId = DeviceHandlerIF::DEFAULT_THERMAL_STATE_POOL_ID, lp_id_t thermalRequestPoolId = DeviceHandlerIF::DEFAULT_THERMAL_HEATING_REQUEST_POOL_ID, uint32_t thermalSetId = DeviceHandlerIF::DEFAULT_THERMAL_SET_ID); + + ReturnValue_t connectModeTreeParent(HasModeTreeChildrenIF &parent) override; + ModeTreeChildIF& getModeTreeChildIF() override; + /** * @brief Helper function to ease device handler development. * This will instruct the transition to MODE_ON immediately @@ -165,7 +172,7 @@ class DeviceHandlerBase : public DeviceHandlerIF, * @param counter Specifies which Action to perform * @return returnvalue::OK for successful execution */ - virtual ReturnValue_t performOperation(uint8_t counter) override; + ReturnValue_t performOperation(uint8_t counter) override; /** * @brief Initializes the device handler @@ -175,14 +182,14 @@ class DeviceHandlerBase : public DeviceHandlerIF, * Calls fillCommandAndReplyMap(). * @return */ - virtual ReturnValue_t initialize() override; + ReturnValue_t initialize() override; /** * @brief Intialization steps performed after all tasks have been created. * This function will be called by the executing task. * @return */ - virtual ReturnValue_t initializeAfterTaskCreation() override; + ReturnValue_t initializeAfterTaskCreation() override; /** Destructor. */ virtual ~DeviceHandlerBase(); @@ -960,6 +967,9 @@ class DeviceHandlerBase : public DeviceHandlerIF, */ LocalDataPoolManager *getHkManagerHandle() override; + const HasHealthIF* getOptHealthIF() const override; + const HasModesIF& getModeIF() const override; + /** * Returns the delay cycle count of a reply. * A count != 0 indicates that the command is already executed. diff --git a/src/fsfw/subsystem/modes/ModeTreeConnectionIF.h b/src/fsfw/subsystem/ModeTreeConnectionIF.h similarity index 88% rename from src/fsfw/subsystem/modes/ModeTreeConnectionIF.h rename to src/fsfw/subsystem/ModeTreeConnectionIF.h index b86fc10f..78e22435 100644 --- a/src/fsfw/subsystem/modes/ModeTreeConnectionIF.h +++ b/src/fsfw/subsystem/ModeTreeConnectionIF.h @@ -7,6 +7,7 @@ class ModeTreeConnectionIF { public: virtual ~ModeTreeConnectionIF() = default; virtual ReturnValue_t connectModeTreeParent(HasModeTreeChildrenIF &parent) = 0; + virtual ModeTreeChildIF& getModeTreeChildIF() = 0; }; #endif /* FSFW_SRC_FSFW_SUBSYSTEM_MODES_MODETREECONNECTIONIF_H_ */ diff --git a/src/fsfw/subsystem/SubsystemBase.cpp b/src/fsfw/subsystem/SubsystemBase.cpp index 058bcca9..b303e323 100644 --- a/src/fsfw/subsystem/SubsystemBase.cpp +++ b/src/fsfw/subsystem/SubsystemBase.cpp @@ -300,4 +300,10 @@ ReturnValue_t SubsystemBase::registerChild(const ModeTreeChildIF& child) { const HasHealthIF* SubsystemBase::getOptHealthIF() const { return this; } -const HasModesIF& SubsystemBase::getModeIF() const { return *this; } +const HasModesIF& SubsystemBase::getModeIF() const { + return *this; +} + +ModeTreeChildIF& SubsystemBase::getModeTreeChildIF() { + return *this; +} diff --git a/src/fsfw/subsystem/SubsystemBase.h b/src/fsfw/subsystem/SubsystemBase.h index 84b89a12..d3ee34f9 100644 --- a/src/fsfw/subsystem/SubsystemBase.h +++ b/src/fsfw/subsystem/SubsystemBase.h @@ -1,13 +1,12 @@ #ifndef FSFW_SUBSYSTEM_SUBSYSTEMBASE_H_ #define FSFW_SUBSYSTEM_SUBSYSTEMBASE_H_ -#include - #include #include "fsfw/container/HybridIterator.h" #include "fsfw/health/HasHealthIF.h" #include "fsfw/health/HealthHelper.h" +#include "fsfw/subsystem/ModeTreeConnectionIF.h" #include "fsfw/ipc/MessageQueueIF.h" #include "fsfw/modes/HasModesIF.h" #include "fsfw/objectmanager/SystemObject.h" @@ -48,6 +47,7 @@ class SubsystemBase : public SystemObject, virtual MessageQueueId_t getCommandQueue() const override; ReturnValue_t connectModeTreeParent(HasModeTreeChildrenIF &parent) override; + ModeTreeChildIF& getModeTreeChildIF() override; /** * Function to register the child objects. diff --git a/src/fsfw_tests/integration/assemblies/TestAssembly.cpp b/src/fsfw_tests/integration/assemblies/TestAssembly.cpp index 0d72257a..793e591f 100644 --- a/src/fsfw_tests/integration/assemblies/TestAssembly.cpp +++ b/src/fsfw_tests/integration/assemblies/TestAssembly.cpp @@ -2,19 +2,19 @@ #include -TestAssembly::TestAssembly(object_id_t objectId, object_id_t parentId, object_id_t testDevice0, - object_id_t testDevice1) +TestAssembly::TestAssembly(object_id_t objectId, object_id_t parentId, ModeTreeChildIF& testDevice0, + ModeTreeChildIF& testDevice1) : AssemblyBase(objectId, parentId), - deviceHandler0Id(testDevice0), - deviceHandler1Id(testDevice1) { + deviceHandler0(testDevice0), + deviceHandler1(testDevice1) { ModeListEntry newModeListEntry; - newModeListEntry.setObject(testDevice0); + newModeListEntry.setObject(testDevice0.getObjectId()); newModeListEntry.setMode(MODE_OFF); newModeListEntry.setSubmode(SUBMODE_NONE); commandTable.insert(newModeListEntry); - newModeListEntry.setObject(testDevice1); + newModeListEntry.setObject(testDevice1.getObjectId()); newModeListEntry.setMode(MODE_OFF); newModeListEntry.setSubmode(SUBMODE_NONE); @@ -43,8 +43,8 @@ ReturnValue_t TestAssembly::commandChildren(Mode_t mode, Submode_t submode) { commandTable[1].setMode(MODE_OFF); commandTable[1].setSubmode(SUBMODE_NONE); // We try to prefer 0 here but we try to switch to 1 even if it might fail - if (isDeviceAvailable(deviceHandler0Id)) { - if (childrenMap[deviceHandler0Id].mode == MODE_ON) { + if (isDeviceAvailable(deviceHandler0.getObjectId())) { + if (childrenMap[deviceHandler0.getObjectId()].mode == MODE_ON) { commandTable[0].setMode(mode); commandTable[0].setSubmode(SUBMODE_NONE); } else { @@ -53,7 +53,7 @@ ReturnValue_t TestAssembly::commandChildren(Mode_t mode, Submode_t submode) { result = NEED_SECOND_STEP; } } else { - if (childrenMap[deviceHandler1Id].mode == MODE_ON) { + if (childrenMap[deviceHandler1.getObjectId()].mode == MODE_ON) { commandTable[1].setMode(mode); commandTable[1].setSubmode(SUBMODE_NONE); } else { @@ -64,7 +64,7 @@ ReturnValue_t TestAssembly::commandChildren(Mode_t mode, Submode_t submode) { } } else { // Dual Mode Normal - if (childrenMap[deviceHandler0Id].mode == MODE_ON) { + if (childrenMap[deviceHandler0.getObjectId()].mode == MODE_ON) { commandTable[0].setMode(mode); commandTable[0].setSubmode(SUBMODE_NONE); } else { @@ -72,7 +72,7 @@ ReturnValue_t TestAssembly::commandChildren(Mode_t mode, Submode_t submode) { commandTable[0].setSubmode(SUBMODE_NONE); result = NEED_SECOND_STEP; } - if (childrenMap[deviceHandler1Id].mode == MODE_ON) { + if (childrenMap[deviceHandler1.getObjectId()].mode == MODE_ON) { commandTable[1].setMode(mode); commandTable[1].setSubmode(SUBMODE_NONE); } else { @@ -89,7 +89,7 @@ ReturnValue_t TestAssembly::commandChildren(Mode_t mode, Submode_t submode) { commandTable[1].setMode(MODE_OFF); commandTable[1].setSubmode(SUBMODE_NONE); // We try to prefer 0 here but we try to switch to 1 even if it might fail - if (isDeviceAvailable(deviceHandler0Id)) { + if (isDeviceAvailable(deviceHandler0.getObjectId())) { commandTable[0].setMode(MODE_ON); commandTable[0].setSubmode(SUBMODE_NONE); } else { @@ -133,24 +133,14 @@ ReturnValue_t TestAssembly::initialize() { if (result != returnvalue::OK) { return result; } - handler0 = ObjectManager::instance()->get(deviceHandler0Id); - handler1 = ObjectManager::instance()->get(deviceHandler1Id); + auto* handler0 = ObjectManager::instance()->get(deviceHandler0.getObjectId()); + auto* handler1 = ObjectManager::instance()->get(deviceHandler1.getObjectId()); if ((handler0 == nullptr) or (handler1 == nullptr)) { return returnvalue::FAILED; } - handler0->setParentQueue(this->getCommandQueue()); - handler1->setParentQueue(this->getCommandQueue()); - - // TODO: Fix this - // result = registerChild(deviceHandler0Id); - // if (result != returnvalue::OK) { - // return result; - // } - // result = registerChild(deviceHandler1Id); - // if (result != returnvalue::OK) { - // return result; - // } + handler0->connectModeTreeParent(*this); + handler1->connectModeTreeParent(*this); return result; } diff --git a/src/fsfw_tests/integration/assemblies/TestAssembly.h b/src/fsfw_tests/integration/assemblies/TestAssembly.h index 91ffbf60..86b4fb07 100644 --- a/src/fsfw_tests/integration/assemblies/TestAssembly.h +++ b/src/fsfw_tests/integration/assemblies/TestAssembly.h @@ -7,8 +7,8 @@ class TestAssembly : public AssemblyBase { public: - TestAssembly(object_id_t objectId, object_id_t parentId, object_id_t testDevice0, - object_id_t testDevice1); + TestAssembly(object_id_t objectId, object_id_t parentId, ModeTreeChildIF& testDevice0, + ModeTreeChildIF& testDevice1); virtual ~TestAssembly(); ReturnValue_t initialize() override; @@ -41,10 +41,8 @@ class TestAssembly : public AssemblyBase { private: FixedArrayList commandTable; - object_id_t deviceHandler0Id = 0; - object_id_t deviceHandler1Id = 0; - TestDevice* handler0 = nullptr; - TestDevice* handler1 = nullptr; + ModeTreeChildIF& deviceHandler0; + ModeTreeChildIF& deviceHandler1; bool isDeviceAvailable(object_id_t object); };