From bc593c938d4001f579f899931011fcd5b9ebaad5 Mon Sep 17 00:00:00 2001 From: Ulrich Mohr Date: Fri, 26 Aug 2022 09:56:49 +0200 Subject: [PATCH] some more mode introspection --- src/fsfw/devicehandlers/DeviceHandlerBase.cpp | 12 ++++-- src/fsfw/devicehandlers/DeviceHandlerBase.h | 4 +- src/fsfw/devicehandlers/DeviceHandlerIF.h | 40 +++++++++++-------- src/fsfw/modes/HasModesIF.h | 10 +++-- 4 files changed, 42 insertions(+), 24 deletions(-) diff --git a/src/fsfw/devicehandlers/DeviceHandlerBase.cpp b/src/fsfw/devicehandlers/DeviceHandlerBase.cpp index 740113ee..a4ee74a7 100644 --- a/src/fsfw/devicehandlers/DeviceHandlerBase.cpp +++ b/src/fsfw/devicehandlers/DeviceHandlerBase.cpp @@ -1263,11 +1263,9 @@ void DeviceHandlerBase::handleDeviceTM(SerializeIF* dataSet, DeviceCommandId_t r } } -ActionHelper *DeviceHandlerBase::getActionHelper() { - return &actionHelper; -} +ActionHelper* DeviceHandlerBase::getActionHelper() { return &actionHelper; } -ReturnValue_t DeviceHandlerBase::executeAction(Action *action) { +ReturnValue_t DeviceHandlerBase::executeAction(Action* action) { ReturnValue_t result = acceptExternalDeviceCommands(); if (result != HasReturnvaluesIF::RETURN_OK) { return result; @@ -1508,3 +1506,9 @@ MessageQueueId_t DeviceHandlerBase::getCommanderQueueId(DeviceCommandId_t replyI } return commandIter->second.sendReplyTo; } + +ModeHelper const* DeviceHandlerBase::getModeHelper() const { return &modeHelper; } + +ModeDefinitionHelper DeviceHandlerBase::getModeDefinitionHelper() { + return ModeDefinitionHelper::create(); +} \ No newline at end of file diff --git a/src/fsfw/devicehandlers/DeviceHandlerBase.h b/src/fsfw/devicehandlers/DeviceHandlerBase.h index bb93a7db..9f3ed949 100644 --- a/src/fsfw/devicehandlers/DeviceHandlerBase.h +++ b/src/fsfw/devicehandlers/DeviceHandlerBase.h @@ -207,7 +207,9 @@ class DeviceHandlerBase : public DeviceHandlerIF, Mode_t getTransitionSourceMode() const; Submode_t getTransitionSourceSubMode() const; - virtual void getMode(Mode_t *mode, Submode_t *submode); + void getMode(Mode_t *mode, Submode_t *submode) override; + ModeHelper const * getModeHelper() const override; + ModeDefinitionHelper getModeDefinitionHelper() override; HealthState getHealth(); ReturnValue_t setHealth(HealthState health); virtual ReturnValue_t getParameter(uint8_t domainId, uint8_t uniqueId, diff --git a/src/fsfw/devicehandlers/DeviceHandlerIF.h b/src/fsfw/devicehandlers/DeviceHandlerIF.h index 1fc63d3b..ed23b887 100644 --- a/src/fsfw/devicehandlers/DeviceHandlerIF.h +++ b/src/fsfw/devicehandlers/DeviceHandlerIF.h @@ -4,6 +4,7 @@ #include "../action/HasActionsIF.h" #include "../datapoollocal/localPoolDefinitions.h" #include "../events/Event.h" +#include "../introspection/ClasslessEnum.h" #include "../ipc/MessageQueueSenderIF.h" #include "../modes/HasModesIF.h" #include "DeviceHandlerMessage.h" @@ -37,23 +38,30 @@ class DeviceHandlerIF { * The mode of the device itself is transparent to the user but related to the mode of the * handler. MODE_ON and MODE_OFF are included in hasModesIF.h */ + FSFW_CLASSLESS_ENUM( + DeviceHandlerMode, Mode_t, + //! The device is powered and ready to perform operations. In this mode, no + //! commands are sent by the device handler itself, but direct commands can be + //! commanded and will be executed/forwarded to the device + //! This is an alias of MODE_ON to have the FSFW_ENUM complete for introspection + ((DEVICEHANDLER_MODE_ON, HasModesIF::MODE_ON, "On")) + //! The device is powered off. The only command accepted in this + //! mode is a mode change to on. + //! This is an alias of MODE_OFF to have the FSFW_ENUM complete for introspection + ((DEVICEHANDLER_MODE_OFF, HasModesIF::MODE_OFF, "Off")) + //! The device is powered on and the device handler periodically sends + //! commands. The commands to be sent are selected by the handler + //! according to the submode. + ((MODE_NORMAL, 2, "Normal")) + //! The device is powered on and ready to perform operations. In this mode, + //! raw commands can be sent. The device handler will send all replies + //! received from the command back to the commanding object as raw TM + ((MODE_RAW, 3, "Raw")) + //! The device is shut down but the switch could not be turned off, so the + //! device still is powered. In this mode, only a mode change to @c MODE_OFF + //! can be commanded, which tries to switch off the device again. + ((MODE_ERROR_ON, 4, "Error"))) - // MODE_ON = 0, //!< The device is powered and ready to perform operations. In this mode, no - // commands are sent by the device handler itself, but direct commands van be commanded and will - // be interpreted MODE_OFF = 1, //!< The device is powered off. The only command accepted in this - // mode is a mode change to on. - //! The device is powered on and the device handler periodically sends - //! commands. The commands to be sent are selected by the handler - //! according to the submode. - static const Mode_t MODE_NORMAL = 2; - //! The device is powered on and ready to perform operations. In this mode, - //! raw commands can be sent. The device handler will send all replies - //! received from the command back to the commanding object. - static const Mode_t MODE_RAW = 3; - //! The device is shut down but the switch could not be turned off, so the - //! device still is powered. In this mode, only a mode change to @c MODE_OFF - //! can be commanded, which tries to switch off the device again. - static const Mode_t MODE_ERROR_ON = 4; //! This is a transitional state which can not be commanded. The device //! handler performs all commands to get the device in a state ready to //! perform commands. When this is completed, the mode changes to @c MODE_ON. diff --git a/src/fsfw/modes/HasModesIF.h b/src/fsfw/modes/HasModesIF.h index 56adc1e1..84a37427 100644 --- a/src/fsfw/modes/HasModesIF.h +++ b/src/fsfw/modes/HasModesIF.h @@ -4,9 +4,10 @@ #include #include "../events/Event.h" +#include "../introspection/ClasslessEnum.h" #include "../returnvalues/HasReturnvaluesIF.h" -#include "ModeHelper.h" #include "ModeDefinitionHelper.h" +#include "ModeHelper.h" #include "ModeMessage.h" class HasModesIF { @@ -45,11 +46,14 @@ class HasModesIF { //!< interpreted static const Mode_t MODE_OFF = 0; //!< The device is powered off. The only command accepted in //!< this mode is a mode change to on. - static const Submode_t SUBMODE_NONE = 0; //!< To avoid checks against magic number "0". + FSFW_CLASSLESS_ENUM(DefaultSubmode, Submode_t, + ((SUBMODE_NONE, 0, + "Default"))) //!< To avoid checks against magic number "0". virtual ~HasModesIF() {} virtual MessageQueueId_t getCommandQueue() const = 0; - virtual ModeDefinitionHelper getModeDefinitionHelper()= 0; + virtual const ModeHelper * getModeHelper() const = 0; + virtual ModeDefinitionHelper getModeDefinitionHelper() = 0; virtual void getMode(Mode_t *mode, Submode_t *submode) = 0; protected: