From 18cc870c8ebc3ff0565b3b8f5ed85e9a54685358 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Thu, 9 Nov 2023 11:04:45 +0100 Subject: [PATCH] add FDIR handling --- .../devicehandlers/FreshDeviceHandlerBase.cpp | 39 ++++++++++++++++++- .../devicehandlers/FreshDeviceHandlerBase.h | 36 ++++++++++++++++- 2 files changed, 72 insertions(+), 3 deletions(-) diff --git a/src/fsfw/devicehandlers/FreshDeviceHandlerBase.cpp b/src/fsfw/devicehandlers/FreshDeviceHandlerBase.cpp index bc3cf1a6..8de20494 100644 --- a/src/fsfw/devicehandlers/FreshDeviceHandlerBase.cpp +++ b/src/fsfw/devicehandlers/FreshDeviceHandlerBase.cpp @@ -1,5 +1,6 @@ #include "FreshDeviceHandlerBase.h" +#include "fsfw/devicehandlers/DeviceHandlerFailureIsolation.h" #include "fsfw/ipc/QueueFactory.h" #include "fsfw/subsystem/helper.h" @@ -8,13 +9,17 @@ FreshDeviceHandlerBase::FreshDeviceHandlerBase(DhbConfig config) actionHelper(this, nullptr), modeHelper(this), healthHelper(this, getObjectId()), - poolManager(this, nullptr) { + poolManager(this, nullptr), + defaultFdirParent(config.defaultFdirParent) { auto mqArgs = MqArgs(config.objectId, static_cast(this)); messageQueue = QueueFactory::instance()->createMessageQueue( config.msgQueueDepth, MessageQueueMessage::MAX_MESSAGE_SIZE, &mqArgs); } FreshDeviceHandlerBase::~FreshDeviceHandlerBase() { QueueFactory::instance()->deleteMessageQueue(messageQueue); + if (not hasCustomFdir) { + delete fdirInstance; + } } [[nodiscard]] object_id_t FreshDeviceHandlerBase::getObjectId() const { @@ -118,6 +123,17 @@ ReturnValue_t FreshDeviceHandlerBase::setHealth(HasHealthIF::HealthState health) return returnvalue::OK; } +void FreshDeviceHandlerBase::triggerEvent(Event event, uint32_t parameter1, uint32_t parameter2) { + fdirInstance->triggerEvent(event, parameter1, parameter2); +} + +void FreshDeviceHandlerBase::forwardEvent(Event event, uint32_t parameter1, + uint32_t parameter2) const { + fdirInstance->triggerEvent(event, parameter1, parameter2); +} + +void FreshDeviceHandlerBase::setToExternalControl() { setHealth(HealthState::EXTERNAL_CONTROL); } + // System Object overrides. ReturnValue_t FreshDeviceHandlerBase::initialize() { ReturnValue_t result = modeHelper.initialize(); @@ -137,6 +153,25 @@ ReturnValue_t FreshDeviceHandlerBase::initialize() { if (result != returnvalue::OK) { return result; } + if (fdirInstance == nullptr) { + hasCustomFdir = false; + fdirInstance = new DeviceHandlerFailureIsolation(getObjectId(), defaultFdirParent); + } + + result = fdirInstance->initialize(); + if (result != returnvalue::OK) { + return result; + } return SystemObject::initialize(); } -void FreshDeviceHandlerBase::setToExternalControl() { setHealth(HealthState::EXTERNAL_CONTROL); } +ReturnValue_t FreshDeviceHandlerBase::getParameter(uint8_t domainId, uint8_t uniqueId, + ParameterWrapper* parameterWrapper, + const ParameterWrapper* newValues, + uint16_t startAtIndex) { + ReturnValue_t result = + fdirInstance->getParameter(domainId, uniqueId, parameterWrapper, newValues, startAtIndex); + if (result != INVALID_DOMAIN_ID) { + return result; + } + return INVALID_DOMAIN_ID; +} diff --git a/src/fsfw/devicehandlers/FreshDeviceHandlerBase.h b/src/fsfw/devicehandlers/FreshDeviceHandlerBase.h index 24b23a79..c6002699 100644 --- a/src/fsfw/devicehandlers/FreshDeviceHandlerBase.h +++ b/src/fsfw/devicehandlers/FreshDeviceHandlerBase.h @@ -4,6 +4,7 @@ #include "fsfw/datapoollocal/HasLocalDataPoolIF.h" #include "fsfw/datapoollocal/LocalDataPoolManager.h" #include "fsfw/devicehandlers/DeviceHandlerIF.h" +#include "fsfw/fdir/FailureIsolationBase.h" #include "fsfw/health/HasHealthIF.h" #include "fsfw/health/HealthHelper.h" #include "fsfw/modes/HasModesIF.h" @@ -16,8 +17,9 @@ struct DhbConfig { explicit DhbConfig(object_id_t objectId) : objectId(objectId) {} - object_id_t objectId; + FailureIsolationBase* fdirInstance = nullptr; + object_id_t defaultFdirParent = objects::NO_OBJECT; uint32_t msgQueueDepth = 10; }; class FreshDeviceHandlerBase : public SystemObject, @@ -28,6 +30,7 @@ class FreshDeviceHandlerBase : public SystemObject, public ModeTreeChildIF, public ModeTreeConnectionIF, public HasActionsIF, + public HasParametersIF, public HasLocalDataPoolIF { public: explicit FreshDeviceHandlerBase(DhbConfig config); @@ -68,6 +71,10 @@ class FreshDeviceHandlerBase : public SystemObject, HealthHelper healthHelper; LocalDataPoolManager poolManager; + bool hasCustomFdir = false; + FailureIsolationBase* fdirInstance; + object_id_t defaultFdirParent; + /** * Pointer to the task which executes this component, * is invalid before setTaskIF was called. @@ -107,6 +114,33 @@ class FreshDeviceHandlerBase : public SystemObject, ReturnValue_t performOperation(uint8_t opCode) override; ReturnValue_t initializeAfterTaskCreation() override; + /** + * This calls the FDIR instance event trigger function. + * @param event + * @param parameter1 + * @param parameter2 + */ + void triggerEvent(Event event, uint32_t parameter1, uint32_t parameter2) override; + /** + * This calls the FDIR instance event forward function. + * @param event + * @param parameter1 + * @param parameter2 + */ + void forwardEvent(Event event, uint32_t parameter1, uint32_t parameter2) const override; + /** + * This implementation handles the FDIR parameters. The user can override this to handle + * custom parameters. + * @param domainId + * @param uniqueId + * @param parameterWrapper + * @param newValues + * @param startAtIndex + * @return + */ + ReturnValue_t getParameter(uint8_t domainId, uint8_t uniqueId, ParameterWrapper* parameterWrapper, + const ParameterWrapper* newValues, uint16_t startAtIndex) override; + private: // Executable Overrides. void setTaskIF(PeriodicTaskIF* task) override;