From f56646d2c30b7b118b3cafc1a2d59b4c62e258a4 Mon Sep 17 00:00:00 2001 From: Ulrich Mohr Date: Wed, 20 Jul 2022 16:59:42 +0200 Subject: [PATCH] changed action handling slightly --- src/fsfw/action/Action.h | 3 +++ src/fsfw/action/ActionHelper.cpp | 6 +++--- src/fsfw/action/HasActionsIF.h | 2 +- src/fsfw/controller/ExtendedControllerBase.cpp | 2 +- src/fsfw/controller/ExtendedControllerBase.h | 2 +- src/fsfw/devicehandlers/DeviceHandlerBase.cpp | 4 ++-- src/fsfw/devicehandlers/DeviceHandlerBase.h | 2 +- tests/src/fsfw_tests/unit/action/TestActionHelper.h | 2 +- 8 files changed, 13 insertions(+), 10 deletions(-) diff --git a/src/fsfw/action/Action.h b/src/fsfw/action/Action.h index b55593c6..4b256d3b 100644 --- a/src/fsfw/action/Action.h +++ b/src/fsfw/action/Action.h @@ -24,6 +24,8 @@ class Action: public SerializeIF { #endif ActionId_t getId(); + MessageQueueId_t commandedBy; + virtual ReturnValue_t handle() = 0; void registerParameter(ParameterIF *parameter); @@ -40,6 +42,7 @@ class Action: public SerializeIF { private: ActionId_t id; + #ifdef FSFW_INTROSPECTION const char *name; #endif diff --git a/src/fsfw/action/ActionHelper.cpp b/src/fsfw/action/ActionHelper.cpp index 503e8080..8c68ea63 100644 --- a/src/fsfw/action/ActionHelper.cpp +++ b/src/fsfw/action/ActionHelper.cpp @@ -73,7 +73,6 @@ void ActionHelper::prepareExecution(MessageQueueId_t commandedBy, ActionId_t act } auto actionIter = actionMap.find(actionId); if (actionIter == actionMap.end()){ - puts("end"); CommandMessage reply; ActionMessage::setStepReply(&reply, actionId, 0, HasActionsIF::INVALID_ACTION_ID); queueToUse->sendMessage(commandedBy, &reply); @@ -83,14 +82,15 @@ void ActionHelper::prepareExecution(MessageQueueId_t commandedBy, ActionId_t act Action* action = actionIter->second; result = action->deSerialize(&dataPtr, &size, SerializeIF::Endianness::NETWORK); if ((result != HasReturnvaluesIF::RETURN_OK) || (size != 0)){ //TODO write unittest for second condition - printf("serialze %i, %x\n", size, result); CommandMessage reply; ActionMessage::setStepReply(&reply, actionId, 0, HasActionsIF::INVALID_PARAMETERS); queueToUse->sendMessage(commandedBy, &reply); ipcStore->deleteData(dataAddress); return; } - result = action->handle(); + //TODO call action->check() + action->commandedBy = commandedBy; + result = owner->executeAction(action); ipcStore->deleteData(dataAddress); if (result == HasActionsIF::EXECUTION_FINISHED) { CommandMessage reply; diff --git a/src/fsfw/action/HasActionsIF.h b/src/fsfw/action/HasActionsIF.h index bede4955..d01ac8f1 100644 --- a/src/fsfw/action/HasActionsIF.h +++ b/src/fsfw/action/HasActionsIF.h @@ -58,7 +58,7 @@ class HasActionsIF { * -@c EXECUTION_FINISHED Finish reply will be generated * -@c Not RETURN_OK Step failure reply will be generated */ - virtual ReturnValue_t executeAction(Action* action, MessageQueueId_t commandedBy) = 0; + virtual ReturnValue_t executeAction(Action* action) = 0; }; #endif /* FSFW_ACTION_HASACTIONSIF_H_ */ diff --git a/src/fsfw/controller/ExtendedControllerBase.cpp b/src/fsfw/controller/ExtendedControllerBase.cpp index 78b9b03e..5057aac2 100644 --- a/src/fsfw/controller/ExtendedControllerBase.cpp +++ b/src/fsfw/controller/ExtendedControllerBase.cpp @@ -8,7 +8,7 @@ ExtendedControllerBase::ExtendedControllerBase(object_id_t objectId, object_id_t ExtendedControllerBase::~ExtendedControllerBase() {} -ReturnValue_t ExtendedControllerBase::executeAction(Action *action, MessageQueueId_t commandedBy) { +ReturnValue_t ExtendedControllerBase::executeAction(Action *action) { /* Needs to be overriden and implemented by child class. */ return HasReturnvaluesIF::RETURN_OK; } diff --git a/src/fsfw/controller/ExtendedControllerBase.h b/src/fsfw/controller/ExtendedControllerBase.h index 99d4eb04..f1ed0e9f 100644 --- a/src/fsfw/controller/ExtendedControllerBase.h +++ b/src/fsfw/controller/ExtendedControllerBase.h @@ -50,7 +50,7 @@ class ExtendedControllerBase : public ControllerBase, void handleQueue() override; /* HasActionsIF overrides */ - virtual ReturnValue_t executeAction(Action* actionId, MessageQueueId_t commandedBy) override; + virtual ReturnValue_t executeAction(Action* actionId) override; /* HasLocalDatapoolIF overrides */ virtual LocalDataPoolManager* getHkManagerHandle() override; diff --git a/src/fsfw/devicehandlers/DeviceHandlerBase.cpp b/src/fsfw/devicehandlers/DeviceHandlerBase.cpp index 0aadc360..d3706300 100644 --- a/src/fsfw/devicehandlers/DeviceHandlerBase.cpp +++ b/src/fsfw/devicehandlers/DeviceHandlerBase.cpp @@ -1263,7 +1263,7 @@ void DeviceHandlerBase::handleDeviceTM(SerializeIF* dataSet, DeviceCommandId_t r } } -ReturnValue_t DeviceHandlerBase::executeAction(Action *action, MessageQueueId_t commandedBy) { +ReturnValue_t DeviceHandlerBase::executeAction(Action *action) { ReturnValue_t result = acceptExternalDeviceCommands(); if (result != HasReturnvaluesIF::RETURN_OK) { return result; @@ -1277,7 +1277,7 @@ ReturnValue_t DeviceHandlerBase::executeAction(Action *action, MessageQueueId_t result = action->handle(); } if (result == RETURN_OK) { - iter->second.sendReplyTo = commandedBy; + iter->second.sendReplyTo = action->commandedBy; iter->second.isExecuting = true; cookieInfo.pendingCommand = iter; cookieInfo.state = COOKIE_WRITE_READY; diff --git a/src/fsfw/devicehandlers/DeviceHandlerBase.h b/src/fsfw/devicehandlers/DeviceHandlerBase.h index d4c83cb1..902f4923 100644 --- a/src/fsfw/devicehandlers/DeviceHandlerBase.h +++ b/src/fsfw/devicehandlers/DeviceHandlerBase.h @@ -202,7 +202,7 @@ class DeviceHandlerBase : public DeviceHandlerIF, virtual void setParentQueue(MessageQueueId_t parentQueueId); /** @brief Implementation required for HasActionIF */ - ReturnValue_t executeAction(Action *action, MessageQueueId_t commandedBy) override; + ReturnValue_t executeAction(Action *action) override; Mode_t getTransitionSourceMode() const; Submode_t getTransitionSourceSubMode() const; diff --git a/tests/src/fsfw_tests/unit/action/TestActionHelper.h b/tests/src/fsfw_tests/unit/action/TestActionHelper.h index 55786a77..d1699f41 100644 --- a/tests/src/fsfw_tests/unit/action/TestActionHelper.h +++ b/tests/src/fsfw_tests/unit/action/TestActionHelper.h @@ -37,7 +37,7 @@ class ActionHelperOwnerMockBase : public HasActionsIF { ActionHelper* getActionHelper() override { return &actionHelper; } - ReturnValue_t executeAction(Action* action, MessageQueueId_t commandedBy) override { + ReturnValue_t executeAction(Action* action) override { executeActionCalled = true; if (size > MAX_SIZE) { return 0xAFFE;