From ded92fdf7ab4a7d1590bbef9460e5e56ce5ed90f Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Wed, 19 Jan 2022 18:51:44 +0100 Subject: [PATCH] call param callback twice --- mission/devices/GomspaceDeviceHandler.cpp | 15 ++++++++------- mission/devices/GomspaceDeviceHandler.h | 11 ++++++++++- mission/devices/PDU1Handler.cpp | 5 ++++- mission/devices/PDU1Handler.h | 2 +- mission/devices/PDU2Handler.cpp | 5 ++++- mission/devices/PDU2Handler.h | 2 +- 6 files changed, 28 insertions(+), 12 deletions(-) diff --git a/mission/devices/GomspaceDeviceHandler.cpp b/mission/devices/GomspaceDeviceHandler.cpp index c2abd330..ce86d13a 100644 --- a/mission/devices/GomspaceDeviceHandler.cpp +++ b/mission/devices/GomspaceDeviceHandler.cpp @@ -170,6 +170,7 @@ ReturnValue_t GomspaceDeviceHandler::interpretDeviceReply(DeviceCommandId_t id, if (*packet != PARAM_SET_OK) { return HasReturnvaluesIF::RETURN_FAILED; } + setParamCallback(setParamCacher, true); break; } case (GOMSPACE::REQUEST_HK_TABLE): { @@ -186,8 +187,7 @@ void GomspaceDeviceHandler::setNormalDatapoolEntriesInvalid() {} ReturnValue_t GomspaceDeviceHandler::generateSetParamCommand(const uint8_t* commandData, size_t commandDataLen) { - SetParamMessageUnpacker setParamMessageUnpacker; - ReturnValue_t result = setParamMessageUnpacker.deSerialize(&commandData, &commandDataLen, + ReturnValue_t result = setParamCacher.deSerialize(&commandData, &commandDataLen, SerializeIF::Endianness::BIG); if (result != HasReturnvaluesIF::RETURN_OK) { sif::error << "GomspaceDeviceHandler: Failed to deserialize set parameter " @@ -195,12 +195,12 @@ ReturnValue_t GomspaceDeviceHandler::generateSetParamCommand(const uint8_t* comm << std::endl; return result; } - result = setParamCallback(setParamMessageUnpacker); + result = setParamCallback(setParamCacher, false); if (result != HasReturnvaluesIF::RETURN_OK) { return result; } /* Get and check address */ - uint16_t address = setParamMessageUnpacker.getAddress(); + uint16_t address = setParamCacher.getAddress(); if (address > maxConfigTableAddress) { sif::error << "GomspaceDeviceHandler: Invalid address for set parameter " << "action" << std::endl; @@ -211,8 +211,8 @@ ReturnValue_t GomspaceDeviceHandler::generateSetParamCommand(const uint8_t* comm uint16_t total = 0; /* CSP reply only contains the transaction state */ uint16_t querySize = 1; - const uint8_t* parameterPtr = setParamMessageUnpacker.getParameter(); - uint8_t parameterSize = setParamMessageUnpacker.getParameterSize(); + const uint8_t* parameterPtr = setParamCacher.getParameter(); + uint8_t parameterSize = setParamCacher.getParameterSize(); uint16_t payloadlength = sizeof(address) + parameterSize; /* Generate command for CspComIF */ @@ -345,7 +345,8 @@ ReturnValue_t GomspaceDeviceHandler::childCommandHook(DeviceCommandId_t cmd, return DeviceHandlerIF::COMMAND_NOT_IMPLEMENTED; } -ReturnValue_t GomspaceDeviceHandler::setParamCallback(SetParamMessageUnpacker& unpacker) { +ReturnValue_t GomspaceDeviceHandler::setParamCallback(SetParamMessageUnpacker& unpacker, + bool afterExecution) { return HasReturnvaluesIF::RETURN_OK; } diff --git a/mission/devices/GomspaceDeviceHandler.h b/mission/devices/GomspaceDeviceHandler.h index 22b97ef7..efe18ee5 100644 --- a/mission/devices/GomspaceDeviceHandler.h +++ b/mission/devices/GomspaceDeviceHandler.h @@ -111,13 +111,22 @@ class GomspaceDeviceHandler : public DeviceHandlerBase { size_t commandDataLen); private: + SetParamMessageUnpacker setParamCacher; /** * @brief Function to generate the command to set a parameter. Command * will be sent to the ComIF over the rawPacket buffer. */ ReturnValue_t generateSetParamCommand(const uint8_t *commandData, size_t commandDataLen); - virtual ReturnValue_t setParamCallback(SetParamMessageUnpacker &unpacker); + /** + * Callback is called on a parameter set command. It is called before executing it and after + * after successful execution + * @param unpacker Passed before + * @param beforeSet False for callback before execution, true if called after successful + * execution + * @return + */ + virtual ReturnValue_t setParamCallback(SetParamMessageUnpacker& unpacker, bool afterExecution); /** * @brief Function to generate the command to get a parameter from a diff --git a/mission/devices/PDU1Handler.cpp b/mission/devices/PDU1Handler.cpp index 6f2fd01e..d1276c7f 100644 --- a/mission/devices/PDU1Handler.cpp +++ b/mission/devices/PDU1Handler.cpp @@ -73,9 +73,12 @@ void PDU1Handler::assignChannelHookFunction(GOMSPACE::ChannelSwitchHook hook, vo this->hookArgs = args; } -ReturnValue_t PDU1Handler::setParamCallback(SetParamMessageUnpacker &unpacker) { +ReturnValue_t PDU1Handler::setParamCallback(SetParamMessageUnpacker &unpacker, bool afterExecution) { using namespace PDU1; GOMSPACE::Pdu pdu = GOMSPACE::Pdu::PDU1; + if(not afterExecution) { + return HasReturnvaluesIF::RETURN_OK; + } if (channelSwitchHook != nullptr and unpacker.getParameterSize() == 1) { switch (unpacker.getAddress()) { case (CONFIG_ADDRESS_OUT_EN_TCS_BOARD_3V3): { diff --git a/mission/devices/PDU1Handler.h b/mission/devices/PDU1Handler.h index 9b60e7e9..c140648b 100644 --- a/mission/devices/PDU1Handler.h +++ b/mission/devices/PDU1Handler.h @@ -37,7 +37,7 @@ class PDU1Handler : public GomspaceDeviceHandler { virtual void letChildHandleHkReply(DeviceCommandId_t id, const uint8_t* packet) override; ReturnValue_t printStatus(DeviceCommandId_t cmd) override; - ReturnValue_t setParamCallback(SetParamMessageUnpacker& unpacker) override; + ReturnValue_t setParamCallback(SetParamMessageUnpacker& unpacker, bool afterExectuion) override; private: /** Dataset for the housekeeping table of the PDU1 */ diff --git a/mission/devices/PDU2Handler.cpp b/mission/devices/PDU2Handler.cpp index d2d879f8..61e9bb6a 100644 --- a/mission/devices/PDU2Handler.cpp +++ b/mission/devices/PDU2Handler.cpp @@ -427,9 +427,12 @@ void PDU2Handler::printHkTable() { << std::endl; } -ReturnValue_t PDU2Handler::setParamCallback(SetParamMessageUnpacker &unpacker) { +ReturnValue_t PDU2Handler::setParamCallback(SetParamMessageUnpacker &unpacker, bool afterExecution) { using namespace PDU2; GOMSPACE::Pdu pdu = GOMSPACE::Pdu::PDU2; + if(not afterExecution) { + return HasReturnvaluesIF::RETURN_OK; + } if (channelSwitchHook != nullptr and unpacker.getParameterSize() == 1) { switch (unpacker.getAddress()) { case (CONFIG_ADDRESS_OUT_EN_Q7S): { diff --git a/mission/devices/PDU2Handler.h b/mission/devices/PDU2Handler.h index b721ce58..f2323615 100644 --- a/mission/devices/PDU2Handler.h +++ b/mission/devices/PDU2Handler.h @@ -35,7 +35,7 @@ class PDU2Handler : public GomspaceDeviceHandler { virtual ReturnValue_t buildNormalDeviceCommand(DeviceCommandId_t* id) override; virtual void letChildHandleHkReply(DeviceCommandId_t id, const uint8_t* packet) override; ReturnValue_t printStatus(DeviceCommandId_t cmd) override; - ReturnValue_t setParamCallback(SetParamMessageUnpacker& unpacker) override; + ReturnValue_t setParamCallback(SetParamMessageUnpacker& unpacker, bool afterExecution) override; private: /** Dataset for the housekeeping table of the PDU2 */