From e831ba11d20b5bedb62d99e34f6b165c64821d76 Mon Sep 17 00:00:00 2001 From: Ulrich Mohr Date: Mon, 19 Jun 2023 17:27:25 +0200 Subject: [PATCH] breaking everything, WIP --- src/fsfw/action/ActionHelper.cpp | 11 +- src/fsfw/action/ActionHelper.h | 2 +- src/fsfw/action/ActionMessage.cpp | 6 +- src/fsfw/action/ActionMessage.h | 4 +- src/fsfw/devicehandlers/DeviceHandlerBase.cpp | 8 +- src/fsfw/devicehandlers/DeviceHandlerBase.h | 31 +---- .../integration/devices/TestDeviceHandler.cpp | 126 +++++++++--------- .../integration/devices/TestDeviceHandler.h | 6 +- 8 files changed, 86 insertions(+), 108 deletions(-) diff --git a/src/fsfw/action/ActionHelper.cpp b/src/fsfw/action/ActionHelper.cpp index 64f902844..75edb4a50 100644 --- a/src/fsfw/action/ActionHelper.cpp +++ b/src/fsfw/action/ActionHelper.cpp @@ -10,8 +10,7 @@ ActionHelper::~ActionHelper() = default; ReturnValue_t ActionHelper::handleActionMessage(CommandMessage* command) { if (command->getCommand() == ActionMessage::EXECUTE_ACTION) { - ActionId_t currentAction = ActionMessage::getActionId(command); - prepareExecution(command->getSender(), currentAction, ActionMessage::getStoreId(command)); + prepareExecution(command->getSender(), ActionMessage::getOffset(command), ActionMessage::getStoreId(command)); return returnvalue::OK; } else { return CommandMessage::UNKNOWN_COMMAND; @@ -61,7 +60,7 @@ MessageQueueIF const * ActionHelper::getQueue() const { return queueToUse; } -void ActionHelper::prepareExecution(MessageQueueId_t commandedBy, ActionId_t actionId, +void ActionHelper::prepareExecution(MessageQueueId_t commandedBy, size_t offset, store_address_t dataAddress) { const uint8_t* dataPtr = nullptr; size_t size = 0; @@ -73,6 +72,10 @@ void ActionHelper::prepareExecution(MessageQueueId_t commandedBy, ActionId_t act ipcStore->deleteData(dataAddress); return; } + + //add offset, deserialize action + + auto actionIter = actionMap.find(actionId); if (actionIter == actionMap.end()){ CommandMessage reply; @@ -82,6 +85,8 @@ void ActionHelper::prepareExecution(MessageQueueId_t commandedBy, ActionId_t act return; } Action* action = actionIter->second; + dataPtr +=6; + size -=6; result = action->deSerialize(&dataPtr, &size, SerializeIF::Endianness::NETWORK); if ((result != returnvalue::OK) || (size != 0)){ //TODO write unittest for second condition CommandMessage reply; diff --git a/src/fsfw/action/ActionHelper.h b/src/fsfw/action/ActionHelper.h index 8d57e7533..20323ddff 100644 --- a/src/fsfw/action/ActionHelper.h +++ b/src/fsfw/action/ActionHelper.h @@ -127,7 +127,7 @@ class ActionHelper { * @param actionId ID of action to be done * @param dataAddress Address of additional data in IPC Store */ - virtual void prepareExecution(MessageQueueId_t commandedBy, ActionId_t actionId, + virtual void prepareExecution(MessageQueueId_t commandedBy, size_t offset, store_address_t dataAddress); /** * @brief Default implementation is empty. diff --git a/src/fsfw/action/ActionMessage.cpp b/src/fsfw/action/ActionMessage.cpp index 330880553..ee7c79a04 100644 --- a/src/fsfw/action/ActionMessage.cpp +++ b/src/fsfw/action/ActionMessage.cpp @@ -6,14 +6,14 @@ ActionMessage::ActionMessage() = default; ActionMessage::~ActionMessage() = default; -void ActionMessage::setCommand(CommandMessage* message, ActionId_t fid, +void ActionMessage::setCommand(CommandMessage* message, size_t offset, store_address_t parameters) { message->setCommand(EXECUTE_ACTION); - message->setParameter(fid); + message->setParameter(offset); message->setParameter2(parameters.raw); } -ActionId_t ActionMessage::getActionId(const CommandMessage* message) { +size_t ActionMessage::getOffset(const CommandMessage* message) { return ActionId_t(message->getParameter()); } diff --git a/src/fsfw/action/ActionMessage.h b/src/fsfw/action/ActionMessage.h index 38e3aa999..28ff98ce0 100644 --- a/src/fsfw/action/ActionMessage.h +++ b/src/fsfw/action/ActionMessage.h @@ -27,9 +27,9 @@ class ActionMessage { static const Command_t COMPLETION_FAILED = MAKE_COMMAND_ID(6); virtual ~ActionMessage(); - static void setCommand(CommandMessage* message, ActionId_t fid, store_address_t parameters); + static void setCommand(CommandMessage* message, size_t offset, store_address_t parameters); - static ActionId_t getActionId(const CommandMessage* message); + static size_t getOffset(const CommandMessage* message); static store_address_t getStoreId(const CommandMessage* message); static void setStepReply(CommandMessage* message, ActionId_t fid, uint8_t step, diff --git a/src/fsfw/devicehandlers/DeviceHandlerBase.cpp b/src/fsfw/devicehandlers/DeviceHandlerBase.cpp index 1d8a9faaa..6be29934f 100644 --- a/src/fsfw/devicehandlers/DeviceHandlerBase.cpp +++ b/src/fsfw/devicehandlers/DeviceHandlerBase.cpp @@ -216,10 +216,10 @@ ReturnValue_t DeviceHandlerBase::initialize() { return result; } - result = poolManager.initialize(commandQueue); - if (result != returnvalue::OK) { - return result; - } + // result = poolManager.initialize(commandQueue); + // if (result != returnvalue::OK) { + // return result; + // } fillCommandAndReplyMap(); diff --git a/src/fsfw/devicehandlers/DeviceHandlerBase.h b/src/fsfw/devicehandlers/DeviceHandlerBase.h index b6a638fc3..ca1e1cc04 100644 --- a/src/fsfw/devicehandlers/DeviceHandlerBase.h +++ b/src/fsfw/devicehandlers/DeviceHandlerBase.h @@ -312,37 +312,10 @@ class DeviceHandlerBase : public DeviceHandlerIF, * - Anything else triggers an even with the returnvalue as a parameter */ virtual ReturnValue_t buildTransitionDeviceCommand(DeviceCommandId_t *id) = 0; - - //TODO Remove and update documentation - /** - * @brief Build a device command packet from data supplied by a direct - * command (PUS Service 8) - * @details - * This will be called if an functional command via PUS Service 8 is received and is - * the primary interface for functional command instead of #executeAction for users. The - * supplied ActionId_t action ID will be converted to a DeviceCommandId_t command ID after - * an internal check whether the action ID is a key in the device command map. - * - * #rawPacket and #rawPacketLen should be set by this method to the packet to be sent. - * The existence of the command in the command map and the command size check against 0 are - * done by the base class. - * - * @param deviceCommand The command to build, already checked against deviceCommandMap - * @param commandData Pointer to the data from the direct command - * @param commandDataLen Length of commandData - * @return - * - @c returnvalue::OK to send command after #rawPacket and #rawPacketLen - * have been set. - * - @c HasActionsIF::EXECUTION_COMPLETE to generate a finish reply immediately. This can - * be used if no reply is expected - * - Anything else triggers an event with the return code as a parameter as well as a - * step reply failed with the return code - */ - virtual ReturnValue_t buildCommandFromCommand(DeviceCommandId_t deviceCommand, - const uint8_t *commandData, - size_t commandDataLen) {return returnvalue::FAILED;} /* Reply handling */ + //TODO add way to say, not enough data in buffer, try again later + //ComIF needs to decide if buffer will be appended or overwritten /** * @brief Scans a buffer for a valid reply. * @details diff --git a/src/fsfw_tests/integration/devices/TestDeviceHandler.cpp b/src/fsfw_tests/integration/devices/TestDeviceHandler.cpp index fdf02a707..a87bb02cd 100644 --- a/src/fsfw_tests/integration/devices/TestDeviceHandler.cpp +++ b/src/fsfw_tests/integration/devices/TestDeviceHandler.cpp @@ -61,7 +61,7 @@ ReturnValue_t TestDevice::buildNormalDeviceCommand(DeviceCommandId_t* id) { if (DeviceHandlerBase::isAwaitingReply()) { return NOTHING_TO_SEND; } - return buildCommandFromCommand(*id, nullptr, 0); + return 0; //buildCommandFromCommand(*id, nullptr, 0); } ReturnValue_t TestDevice::buildTransitionDeviceCommand(DeviceCommandId_t* id) { @@ -135,74 +135,74 @@ void TestDevice::doTransition(Mode_t modeFrom, Submode_t submodeFrom) { } } -ReturnValue_t TestDevice::buildCommandFromCommand(DeviceCommandId_t deviceCommand, - const uint8_t* commandData, - size_t commandDataLen) { - using namespace testdevice; - ReturnValue_t result = returnvalue::OK; - switch (deviceCommand) { - case (TEST_NORMAL_MODE_CMD): { - commandSent = true; - result = buildNormalModeCommand(deviceCommand, commandData, commandDataLen); - break; - } +// ReturnValue_t TestDevice::buildCommandFromCommand(DeviceCommandId_t deviceCommand, +// const uint8_t* commandData, +// size_t commandDataLen) { +// using namespace testdevice; +// ReturnValue_t result = returnvalue::OK; +// switch (deviceCommand) { +// case (TEST_NORMAL_MODE_CMD): { +// commandSent = true; +// result = buildNormalModeCommand(deviceCommand, commandData, commandDataLen); +// break; +// } - case (TEST_COMMAND_0): { - commandSent = true; - result = buildTestCommand0(deviceCommand, commandData, commandDataLen); - break; - } +// case (TEST_COMMAND_0): { +// commandSent = true; +// result = buildTestCommand0(deviceCommand, commandData, commandDataLen); +// break; +// } - case (TEST_COMMAND_1): { - commandSent = true; - result = buildTestCommand1(deviceCommand, commandData, commandDataLen); - break; - } - case (TEST_NOTIF_SNAPSHOT_VAR): { - if (changingDatasets) { - changingDatasets = false; - } +// case (TEST_COMMAND_1): { +// commandSent = true; +// result = buildTestCommand1(deviceCommand, commandData, commandDataLen); +// break; +// } +// case (TEST_NOTIF_SNAPSHOT_VAR): { +// if (changingDatasets) { +// changingDatasets = false; +// } - PoolReadGuard readHelper(&dataset.testUint8Var); - if (deviceIdx == testdevice::DeviceIndex::DEVICE_0) { - /* This will trigger a variable notification to the demo controller */ - dataset.testUint8Var = 220; - dataset.testUint8Var.setValid(true); - } else if (deviceIdx == testdevice::DeviceIndex::DEVICE_1) { - /* This will trigger a variable snapshot to the demo controller */ - dataset.testUint8Var = 30; - dataset.testUint8Var.setValid(true); - } +// PoolReadGuard readHelper(&dataset.testUint8Var); +// if (deviceIdx == testdevice::DeviceIndex::DEVICE_0) { +// /* This will trigger a variable notification to the demo controller */ +// dataset.testUint8Var = 220; +// dataset.testUint8Var.setValid(true); +// } else if (deviceIdx == testdevice::DeviceIndex::DEVICE_1) { +// /* This will trigger a variable snapshot to the demo controller */ +// dataset.testUint8Var = 30; +// dataset.testUint8Var.setValid(true); +// } - break; - } - case (TEST_NOTIF_SNAPSHOT_SET): { - if (changingDatasets) { - changingDatasets = false; - } +// break; +// } +// case (TEST_NOTIF_SNAPSHOT_SET): { +// if (changingDatasets) { +// changingDatasets = false; +// } - PoolReadGuard readHelper(&dataset.testFloat3Vec); +// PoolReadGuard readHelper(&dataset.testFloat3Vec); - if (deviceIdx == testdevice::DeviceIndex::DEVICE_0) { - /* This will trigger a variable notification to the demo controller */ - dataset.testFloat3Vec.value[0] = 60; - dataset.testFloat3Vec.value[1] = 70; - dataset.testFloat3Vec.value[2] = 55; - dataset.testFloat3Vec.setValid(true); - } else if (deviceIdx == testdevice::DeviceIndex::DEVICE_1) { - /* This will trigger a variable notification to the demo controller */ - dataset.testFloat3Vec.value[0] = -60; - dataset.testFloat3Vec.value[1] = -70; - dataset.testFloat3Vec.value[2] = -55; - dataset.testFloat3Vec.setValid(true); - } - break; - } - default: - result = DeviceHandlerIF::COMMAND_NOT_SUPPORTED; - } - return result; -} +// if (deviceIdx == testdevice::DeviceIndex::DEVICE_0) { +// /* This will trigger a variable notification to the demo controller */ +// dataset.testFloat3Vec.value[0] = 60; +// dataset.testFloat3Vec.value[1] = 70; +// dataset.testFloat3Vec.value[2] = 55; +// dataset.testFloat3Vec.setValid(true); +// } else if (deviceIdx == testdevice::DeviceIndex::DEVICE_1) { +// /* This will trigger a variable notification to the demo controller */ +// dataset.testFloat3Vec.value[0] = -60; +// dataset.testFloat3Vec.value[1] = -70; +// dataset.testFloat3Vec.value[2] = -55; +// dataset.testFloat3Vec.setValid(true); +// } +// break; +// } +// default: +// result = DeviceHandlerIF::COMMAND_NOT_SUPPORTED; +// } +// return result; +// } ReturnValue_t TestDevice::buildNormalModeCommand(DeviceCommandId_t deviceCommand, const uint8_t* commandData, diff --git a/src/fsfw_tests/integration/devices/TestDeviceHandler.h b/src/fsfw_tests/integration/devices/TestDeviceHandler.h index 31931dad4..941d0dbb0 100644 --- a/src/fsfw_tests/integration/devices/TestDeviceHandler.h +++ b/src/fsfw_tests/integration/devices/TestDeviceHandler.h @@ -72,9 +72,9 @@ class TestDevice : public DeviceHandlerBase { virtual ReturnValue_t buildNormalDeviceCommand(DeviceCommandId_t* id) override; virtual ReturnValue_t buildTransitionDeviceCommand(DeviceCommandId_t* id) override; - virtual ReturnValue_t buildCommandFromCommand(DeviceCommandId_t deviceCommand, - const uint8_t* commandData, - size_t commandDataLen) override; + // virtual ReturnValue_t buildCommandFromCommand(DeviceCommandId_t deviceCommand, + // const uint8_t* commandData, + // size_t commandDataLen) override; virtual void fillCommandAndReplyMap() override;