From 500a5602bd81d4530b7ae1e75f318f640d58a390 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Tue, 26 Jul 2022 11:09:57 +0200 Subject: [PATCH] added additional TM store and send helper --- src/fsfw/pus/CService200ModeCommanding.cpp | 6 +-- src/fsfw/pus/Service17Test.cpp | 10 ++-- src/fsfw/pus/Service17Test.h | 4 +- .../pus/Service1TelecommandVerification.cpp | 7 +-- .../pus/Service1TelecommandVerification.h | 2 + src/fsfw/pus/Service20ParameterManagement.cpp | 6 +-- src/fsfw/pus/Service2DeviceAccess.cpp | 2 +- src/fsfw/pus/Service5EventReporting.cpp | 7 ++- src/fsfw/pus/Service5EventReporting.h | 3 +- src/fsfw/pus/Service8FunctionManagement.cpp | 2 +- src/fsfw/pus/Service8FunctionManagement.h | 2 +- src/fsfw/tmtcpacket/pus/PusIF.h | 4 +- src/fsfw/tmtcpacket/pus/tm/PusTmCreator.cpp | 8 +++ src/fsfw/tmtcpacket/pus/tm/PusTmCreator.h | 2 + .../tmtcservices/CommandingServiceBase.cpp | 26 ++-------- src/fsfw/tmtcservices/CommandingServiceBase.h | 35 +++---------- src/fsfw/tmtcservices/TmSendHelper.h | 3 +- .../tmtcservices/TmStoreAndSendHelper.cpp | 50 ++++++++++++++++++- src/fsfw/tmtcservices/TmStoreAndSendHelper.h | 46 +++++++++++++++-- src/fsfw/tmtcservices/TmStoreHelper.cpp | 4 ++ src/fsfw/tmtcservices/TmStoreHelper.h | 2 + src/fsfw/tmtcservices/tmHelpers.cpp | 15 ------ src/fsfw_hal/linux/CommandExecutor.h | 14 +++--- unittests/tmtcservices/testSendHelper.cpp | 5 -- 24 files changed, 154 insertions(+), 111 deletions(-) diff --git a/src/fsfw/pus/CService200ModeCommanding.cpp b/src/fsfw/pus/CService200ModeCommanding.cpp index 9990280c..2e8e78a3 100644 --- a/src/fsfw/pus/CService200ModeCommanding.cpp +++ b/src/fsfw/pus/CService200ModeCommanding.cpp @@ -96,13 +96,13 @@ ReturnValue_t CService200ModeCommanding::handleReply(const CommandMessage *reply ReturnValue_t CService200ModeCommanding::prepareModeReply(const CommandMessage *reply, object_id_t objectId) { ModePacket modeReplyPacket(objectId, ModeMessage::getMode(reply), ModeMessage::getSubmode(reply)); - return sendTmPacket(Subservice::REPLY_MODE_REPLY, modeReplyPacket); + return tmHelper.sendTmPacket(Subservice::REPLY_MODE_REPLY, modeReplyPacket); } ReturnValue_t CService200ModeCommanding::prepareWrongModeReply(const CommandMessage *reply, object_id_t objectId) { ModePacket wrongModeReply(objectId, ModeMessage::getMode(reply), ModeMessage::getSubmode(reply)); - ReturnValue_t result = sendTmPacket(Subservice::REPLY_WRONG_MODE_REPLY, wrongModeReply); + ReturnValue_t result = tmHelper.sendTmPacket(Subservice::REPLY_WRONG_MODE_REPLY, wrongModeReply); if (result == RETURN_OK) { // We want to produce an error here in any case because the mode was not correct return RETURN_FAILED; @@ -113,7 +113,7 @@ ReturnValue_t CService200ModeCommanding::prepareWrongModeReply(const CommandMess ReturnValue_t CService200ModeCommanding::prepareCantReachModeReply(const CommandMessage *reply, object_id_t objectId) { CantReachModePacket cantReachModePacket(objectId, ModeMessage::getCantReachModeReason(reply)); - ReturnValue_t result = sendTmPacket(Subservice::REPLY_CANT_REACH_MODE, cantReachModePacket); + ReturnValue_t result = tmHelper.sendTmPacket(Subservice::REPLY_CANT_REACH_MODE, cantReachModePacket); if (result == RETURN_OK) { // We want to produce an error here in any case because the mode was not reached return RETURN_FAILED; diff --git a/src/fsfw/pus/Service17Test.cpp b/src/fsfw/pus/Service17Test.cpp index 631cf939..b40d2d70 100644 --- a/src/fsfw/pus/Service17Test.cpp +++ b/src/fsfw/pus/Service17Test.cpp @@ -6,20 +6,20 @@ #include "fsfw/tmtcservices/tmHelpers.h" Service17Test::Service17Test(object_id_t objectId, uint16_t apid, uint8_t serviceId) - : PusServiceBase(objectId, apid, serviceId), storeHelper(apid), packetSubCounter(0) {} + : PusServiceBase(objectId, apid, serviceId), + storeHelper(apid), + tmHelper(serviceId, storeHelper, sendHelper) {} Service17Test::~Service17Test() = default; ReturnValue_t Service17Test::handleRequest(uint8_t subservice) { switch (subservice) { case Subservice::CONNECTION_TEST: { - storeHelper.preparePacket(serviceId, Subservice::CONNECTION_TEST_REPORT, packetSubCounter); - return telemetry::storeAndSendTmPacket(storeHelper, sendHelper); + return tmHelper.sendTmPacket(Subservice::CONNECTION_TEST_REPORT); } case Subservice::EVENT_TRIGGER_TEST: { - storeHelper.preparePacket(serviceId, Subservice::CONNECTION_TEST_REPORT, packetSubCounter++); triggerEvent(TEST, 1234, 5678); - return telemetry::storeAndSendTmPacket(storeHelper, sendHelper); + return tmHelper.sendTmPacket(Subservice::EVENT_TRIGGER_TEST); } default: return AcceptsTelecommandsIF::INVALID_SUBSERVICE; diff --git a/src/fsfw/pus/Service17Test.h b/src/fsfw/pus/Service17Test.h index 54efcaa5..771fbe55 100644 --- a/src/fsfw/pus/Service17Test.h +++ b/src/fsfw/pus/Service17Test.h @@ -4,6 +4,7 @@ #include "fsfw/objectmanager/SystemObject.h" #include "fsfw/tmtcservices/PusServiceBase.h" #include "fsfw/tmtcservices/TmStoreHelper.h" +#include "fsfw/tmtcservices/TmStoreAndSendHelper.h" /** * @brief Test Service @@ -45,8 +46,7 @@ class Service17Test : public PusServiceBase { protected: TmStoreHelper storeHelper; TmSendHelper sendHelper; - - uint16_t packetSubCounter = 0; + TmStoreAndSendWrapper tmHelper; }; #endif /* FSFW_PUS_SERVICE17TEST_H_ */ diff --git a/src/fsfw/pus/Service1TelecommandVerification.cpp b/src/fsfw/pus/Service1TelecommandVerification.cpp index 7b5e7973..102ae5a0 100644 --- a/src/fsfw/pus/Service1TelecommandVerification.cpp +++ b/src/fsfw/pus/Service1TelecommandVerification.cpp @@ -15,7 +15,8 @@ Service1TelecommandVerification::Service1TelecommandVerification(object_id_t obj apid(apid), serviceId(serviceId), targetDestination(targetDestination), - storeHelper(apid) { + storeHelper(apid), + tmHelper(serviceId, storeHelper, sendHelper) { tmQueue = QueueFactory::instance()->createMessageQueue(messageQueueDepth); } @@ -69,7 +70,7 @@ ReturnValue_t Service1TelecommandVerification::generateFailureReport( message->getParameter1(), message->getParameter2()); storeHelper.preparePacket(serviceId, message->getReportId(), packetSubCounter++); storeHelper.setSourceDataSerializable(report); - return telemetry::storeAndSendTmPacket(storeHelper, sendHelper); + return tmHelper.storeAndSendTmPacket(); } ReturnValue_t Service1TelecommandVerification::generateSuccessReport( @@ -78,7 +79,7 @@ ReturnValue_t Service1TelecommandVerification::generateSuccessReport( message->getTcSequenceControl(), message->getStep()); storeHelper.preparePacket(serviceId, message->getReportId(), packetSubCounter++); storeHelper.setSourceDataSerializable(report); - return telemetry::storeAndSendTmPacket(storeHelper, sendHelper); + return tmHelper.storeAndSendTmPacket(); } ReturnValue_t Service1TelecommandVerification::initialize() { diff --git a/src/fsfw/pus/Service1TelecommandVerification.h b/src/fsfw/pus/Service1TelecommandVerification.h index a87acdfe..5709e6a9 100644 --- a/src/fsfw/pus/Service1TelecommandVerification.h +++ b/src/fsfw/pus/Service1TelecommandVerification.h @@ -9,6 +9,7 @@ #include "fsfw/tmtcservices/PusVerificationReport.h" #include "fsfw/tmtcservices/TmSendHelper.h" #include "fsfw/tmtcservices/TmStoreHelper.h" +#include "fsfw/tmtcservices/TmStoreAndSendHelper.h" /** * @brief Verify TC acceptance, start, progress and execution. @@ -84,6 +85,7 @@ class Service1TelecommandVerification : public AcceptsVerifyMessageIF, TmSendHelper sendHelper; TmStoreHelper storeHelper; + TmStoreAndSendWrapper tmHelper; StorageManagerIF* tmStore = nullptr; MessageQueueIF* tmQueue = nullptr; diff --git a/src/fsfw/pus/Service20ParameterManagement.cpp b/src/fsfw/pus/Service20ParameterManagement.cpp index 0922793c..ccb5a3b5 100644 --- a/src/fsfw/pus/Service20ParameterManagement.cpp +++ b/src/fsfw/pus/Service20ParameterManagement.cpp @@ -14,7 +14,7 @@ Service20ParameterManagement::Service20ParameterManagement(object_id_t objectId, : CommandingServiceBase(objectId, apid, serviceId, numberOfParallelCommands, commandTimeoutSeconds) {} -Service20ParameterManagement::~Service20ParameterManagement() {} +Service20ParameterManagement::~Service20ParameterManagement() = default; ReturnValue_t Service20ParameterManagement::isValidSubservice(uint8_t subservice) { switch (static_cast(subservice)) { @@ -64,7 +64,7 @@ ReturnValue_t Service20ParameterManagement::checkAndAcquireTargetID(object_id_t* ReturnValue_t Service20ParameterManagement::checkInterfaceAndAcquireMessageQueue( MessageQueueId_t* messageQueueToSet, object_id_t* objectId) { // check ReceivesParameterMessagesIF property of target - ReceivesParameterMessagesIF* possibleTarget = + auto* possibleTarget = ObjectManager::instance()->get(*objectId); if (possibleTarget == nullptr) { #if FSFW_CPP_OSTREAM_ENABLED == 1 @@ -177,7 +177,7 @@ ReturnValue_t Service20ParameterManagement::handleReply(const CommandMessage* re ParameterId_t parameterId = ParameterMessage::getParameterId(reply); ParameterDumpReply parameterReply(objectId, parameterId, parameterData.second.data(), parameterData.second.size()); - sendTmPacket(static_cast(Subservice::PARAMETER_DUMP_REPLY), parameterReply); + tmHelper.sendTmPacket(static_cast(Subservice::PARAMETER_DUMP_REPLY), parameterReply); return HasReturnvaluesIF::RETURN_OK; } default: diff --git a/src/fsfw/pus/Service2DeviceAccess.cpp b/src/fsfw/pus/Service2DeviceAccess.cpp index 8060b2b6..008d8128 100644 --- a/src/fsfw/pus/Service2DeviceAccess.cpp +++ b/src/fsfw/pus/Service2DeviceAccess.cpp @@ -148,7 +148,7 @@ void Service2DeviceAccess::sendWiretappingTm(CommandMessage* reply, uint8_t subs // Init our dummy packet and correct endianness of object ID before // sending it back. WiretappingPacket tmPacket(DeviceHandlerMessage::getDeviceObjectId(reply), data); - sendTmPacket(subservice, tmPacket.objectId, tmPacket.data, size); + tmHelper.sendTmPacket(subservice, tmPacket.objectId, tmPacket.data, size); } MessageQueueId_t Service2DeviceAccess::getDeviceQueue() { return commandQueue->getId(); } diff --git a/src/fsfw/pus/Service5EventReporting.cpp b/src/fsfw/pus/Service5EventReporting.cpp index 44f7861a..a895ad0d 100644 --- a/src/fsfw/pus/Service5EventReporting.cpp +++ b/src/fsfw/pus/Service5EventReporting.cpp @@ -12,6 +12,7 @@ Service5EventReporting::Service5EventReporting(object_id_t objectId, uint16_t ap uint32_t messageQueueDepth) : PusServiceBase(objectId, apid, serviceId), storeHelper(apid), + tmHelper(serviceId, storeHelper, sendHelper), maxNumberReportsPerCycle(maxNumberReportsPerCycle) { eventQueue = QueueFactory::instance()->createMessageQueue(messageQueueDepth); } @@ -46,9 +47,9 @@ ReturnValue_t Service5EventReporting::performService() { ReturnValue_t Service5EventReporting::generateEventReport(EventMessage message) { EventReport report(message.getEventId(), message.getReporter(), message.getParameter1(), message.getParameter2()); - storeHelper.preparePacket(serviceId, message.getSeverity(), packetSubCounter); + storeHelper.preparePacket(serviceId, message.getSeverity(), tmHelper.sendCounter); storeHelper.setSourceDataSerializable(report); - ReturnValue_t result = telemetry::storeAndSendTmPacket(storeHelper, sendHelper); + ReturnValue_t result = tmHelper.storeAndSendTmPacket(); if (result != HasReturnvaluesIF::RETURN_OK) { #if FSFW_CPP_OSTREAM_ENABLED == 1 sif::warning << "Service5EventReporting::generateEventReport: " @@ -59,8 +60,6 @@ ReturnValue_t Service5EventReporting::generateEventReport(EventMessage message) "Service5EventReporting::generateEventReport: " "Could not send TM packet\n"); #endif - } else { - packetSubCounter++; } return result; } diff --git a/src/fsfw/pus/Service5EventReporting.h b/src/fsfw/pus/Service5EventReporting.h index a357e5fc..fcbdcb6b 100644 --- a/src/fsfw/pus/Service5EventReporting.h +++ b/src/fsfw/pus/Service5EventReporting.h @@ -2,6 +2,7 @@ #define FSFW_PUS_SERVICE5EVENTREPORTING_H_ #include "fsfw/events/EventMessage.h" +#include "fsfw/tmtcservices/TmStoreAndSendHelper.h" #include "fsfw/tmtcservices/PusServiceBase.h" /** @@ -74,11 +75,11 @@ class Service5EventReporting : public PusServiceBase { }; private: - uint16_t packetSubCounter = 0; MessageQueueIF* eventQueue = nullptr; bool enableEventReport = true; TmSendHelper sendHelper; TmStoreHelper storeHelper; + TmStoreAndSendWrapper tmHelper; const uint8_t maxNumberReportsPerCycle; ReturnValue_t generateEventReport(EventMessage message); diff --git a/src/fsfw/pus/Service8FunctionManagement.cpp b/src/fsfw/pus/Service8FunctionManagement.cpp index c9da6d58..cec4e423 100644 --- a/src/fsfw/pus/Service8FunctionManagement.cpp +++ b/src/fsfw/pus/Service8FunctionManagement.cpp @@ -138,7 +138,7 @@ ReturnValue_t Service8FunctionManagement::handleDataReply(const CommandMessage* return result; } DataReply dataReply(objectId, actionId, buffer, size); - result = sendTmPacket(static_cast(Subservice::REPLY_DIRECT_COMMANDING_DATA), dataReply); + result = tmHelper.sendTmPacket(static_cast(Subservice::REPLY_DIRECT_COMMANDING_DATA), dataReply); auto deletionResult = ipcStore->deleteData(storeId); if (deletionResult != HasReturnvaluesIF::RETURN_OK) { diff --git a/src/fsfw/pus/Service8FunctionManagement.h b/src/fsfw/pus/Service8FunctionManagement.h index 649b3257..38aaf4f4 100644 --- a/src/fsfw/pus/Service8FunctionManagement.h +++ b/src/fsfw/pus/Service8FunctionManagement.h @@ -32,7 +32,7 @@ class Service8FunctionManagement : public CommandingServiceBase { public: Service8FunctionManagement(object_id_t objectId, uint16_t apid, uint8_t serviceId, uint8_t numParallelCommands = 4, uint16_t commandTimeoutSeconds = 60); - virtual ~Service8FunctionManagement(); + ~Service8FunctionManagement() override; protected: /* CSB abstract functions implementation . See CSB documentation. */ diff --git a/src/fsfw/tmtcpacket/pus/PusIF.h b/src/fsfw/tmtcpacket/pus/PusIF.h index 8c346b1d..93223ba8 100644 --- a/src/fsfw/tmtcpacket/pus/PusIF.h +++ b/src/fsfw/tmtcpacket/pus/PusIF.h @@ -10,9 +10,9 @@ class PusIF : public SpacePacketIF { public: static constexpr uint8_t INTERFACE_ID = CLASS_ID::PUS_IF; static constexpr ReturnValue_t INVALID_PUS_VERSION = - HasReturnvaluesIF::makeReturnCode(INTERFACE_ID, 0); + retval::makeCode(INTERFACE_ID, 0); static constexpr ReturnValue_t INVALID_CRC_16 = - HasReturnvaluesIF::makeReturnCode(INTERFACE_ID, 1); + retval::makeCode(INTERFACE_ID, 1); ~PusIF() override = default; /** diff --git a/src/fsfw/tmtcpacket/pus/tm/PusTmCreator.cpp b/src/fsfw/tmtcpacket/pus/tm/PusTmCreator.cpp index 662e74be..71149613 100644 --- a/src/fsfw/tmtcpacket/pus/tm/PusTmCreator.cpp +++ b/src/fsfw/tmtcpacket/pus/tm/PusTmCreator.cpp @@ -133,3 +133,11 @@ ReturnValue_t PusTmCreator::setSerializableUserData(SerializeIF& serializable) { updateSpLengthField(); return HasReturnvaluesIF::RETURN_OK; } + +void PusTmCreator::setService(uint8_t service) { + pusParams.secHeader.service = service; +} + +void PusTmCreator::setSubservice(uint8_t subservice) { + pusParams.secHeader.subservice = subservice; +} diff --git a/src/fsfw/tmtcpacket/pus/tm/PusTmCreator.h b/src/fsfw/tmtcpacket/pus/tm/PusTmCreator.h index 7df760ce..41f72c38 100644 --- a/src/fsfw/tmtcpacket/pus/tm/PusTmCreator.h +++ b/src/fsfw/tmtcpacket/pus/tm/PusTmCreator.h @@ -49,6 +49,8 @@ class PusTmCreator : public SerializeIF, public PusTmIF, public CustomUserDataIF SpacePacketParams& getSpParams(); void setApid(uint16_t apid); void setDestId(uint16_t destId); + void setService(uint8_t service); + void setSubservice(uint8_t subservice); void setMessageTypeCounter(uint16_t messageTypeCounter); PusTmParams& getParams(); void updateSpLengthField(); diff --git a/src/fsfw/tmtcservices/CommandingServiceBase.cpp b/src/fsfw/tmtcservices/CommandingServiceBase.cpp index 10cc2689..7839aa87 100644 --- a/src/fsfw/tmtcservices/CommandingServiceBase.cpp +++ b/src/fsfw/tmtcservices/CommandingServiceBase.cpp @@ -21,6 +21,7 @@ CommandingServiceBase::CommandingServiceBase(object_id_t setObjectId, uint16_t a service(service), timeoutSeconds(commandTimeoutSeconds), tmStoreHelper(apid), + tmHelper(service, tmStoreHelper, tmSendHelper), commandMap(numberOfParallelCommands) { commandQueue = QueueFactory::instance()->createMessageQueue(queueDepth); requestQueue = QueueFactory::instance()->createMessageQueue(queueDepth); @@ -286,35 +287,16 @@ void CommandingServiceBase::handleRequestQueue() { ReturnValue_t CommandingServiceBase::sendTmPacket(uint8_t subservice, const uint8_t* sourceData, size_t sourceDataLen) { - tmStoreHelper.preparePacket(service, subservice, tmPacketCounter); - tmStoreHelper.setSourceDataRaw(sourceData, sourceDataLen); - ReturnValue_t result = telemetry::storeAndSendTmPacket(tmStoreHelper, tmSendHelper); - if (result == HasReturnvaluesIF::RETURN_OK) { - this->tmPacketCounter++; - } - return result; + return tmHelper.sendTmPacket(subservice, sourceData, sourceDataLen); } ReturnValue_t CommandingServiceBase::sendTmPacket(uint8_t subservice, object_id_t objectId, const uint8_t* data, size_t dataLen) { - telemetry::DataWithObjectIdPrefix dataWithObjId(objectId, data, dataLen); - tmStoreHelper.preparePacket(service, subservice, tmPacketCounter); - tmStoreHelper.setSourceDataSerializable(dataWithObjId); - ReturnValue_t result = telemetry::storeAndSendTmPacket(tmStoreHelper, tmSendHelper); - if (result == HasReturnvaluesIF::RETURN_OK) { - this->tmPacketCounter++; - } - return result; + return tmHelper.sendTmPacket(subservice, objectId, data, dataLen); } ReturnValue_t CommandingServiceBase::sendTmPacket(uint8_t subservice, SerializeIF& sourceData) { - tmStoreHelper.preparePacket(service, subservice, tmPacketCounter); - tmStoreHelper.setSourceDataSerializable(sourceData); - ReturnValue_t result = telemetry::storeAndSendTmPacket(tmStoreHelper, tmSendHelper); - if (result == HasReturnvaluesIF::RETURN_OK) { - this->tmPacketCounter++; - } - return result; + return tmHelper.sendTmPacket(subservice, sourceData); } void CommandingServiceBase::startExecution(store_address_t storeId, CommandMapIter iter) { diff --git a/src/fsfw/tmtcservices/CommandingServiceBase.h b/src/fsfw/tmtcservices/CommandingServiceBase.h index 48575724..e96c02d7 100644 --- a/src/fsfw/tmtcservices/CommandingServiceBase.h +++ b/src/fsfw/tmtcservices/CommandingServiceBase.h @@ -6,6 +6,7 @@ #include "TmStoreHelper.h" #include "VerificationReporter.h" #include "fsfw/FSFW.h" +#include "fsfw/tmtcservices/TmStoreAndSendHelper.h" #include "fsfw/container/FIFO.h" #include "fsfw/container/FixedMap.h" #include "fsfw/ipc/CommandMessage.h" @@ -251,18 +252,15 @@ class CommandingServiceBase : public SystemObject, const uint16_t timeoutSeconds; - uint8_t tmPacketCounter = 0; - - StorageManagerIF* ipcStore = nullptr; - PusTcReader tcReader; TmStoreHelper tmStoreHelper; TmSendHelper tmSendHelper; + TmStoreAndSendWrapper tmHelper; StorageManagerIF* tcStore = nullptr; + StorageManagerIF* ipcStore = nullptr; MessageQueueIF* commandQueue = nullptr; - MessageQueueIF* requestQueue = nullptr; VerificationReporter verificationReporter; @@ -286,33 +284,12 @@ class CommandingServiceBase : public SystemObject, */ PeriodicTaskIF* executingTask = nullptr; - /** - * @brief Send TM data from pointer to data. - * If a header is supplied it is added before data - * @param subservice Number of subservice - * @param sourceData Custom source data - * @param sourceDataLen Lenght of data in the Packet - */ + [[deprecated("Use function with same name provided by tmHelper")]] ReturnValue_t sendTmPacket(uint8_t subservice, const uint8_t* sourceData, size_t sourceDataLen); - - /** - * @brief To send TM packets of objects that still need to be serialized - * and consist of an object ID with appended data. - * @param subservice Number of subservice - * @param objectId ObjectId is placed before data - * @param data Data to append to the packet - * @param dataLen Length of Data - */ + [[deprecated("Use function with same name provided by tmHelper")]] ReturnValue_t sendTmPacket(uint8_t subservice, object_id_t objectId, const uint8_t* data, size_t dataLen); - - /** - * @brief To send packets which are contained inside a class implementing - * SerializeIF. - * @param subservice Number of subservice - * @param content This is a pointer to the serialized packet - * @param header Serialize IF header which will be placed before content - */ + [[deprecated("Use function with same name provided by tmHelper")]] ReturnValue_t sendTmPacket(uint8_t subservice, SerializeIF& sourceData); void checkAndExecuteFifo(CommandMapIter& iter); diff --git a/src/fsfw/tmtcservices/TmSendHelper.h b/src/fsfw/tmtcservices/TmSendHelper.h index dee5a495..c4bec886 100644 --- a/src/fsfw/tmtcservices/TmSendHelper.h +++ b/src/fsfw/tmtcservices/TmSendHelper.h @@ -16,7 +16,7 @@ class TmSendHelper { explicit TmSendHelper(InternalErrorReporterIF& reporter); void setMsgQueue(MessageQueueIF& queue); - MessageQueueIF* getMsgQueue() const; + [[nodiscard]] MessageQueueIF* getMsgQueue() const; void setDefaultDestination(MessageQueueId_t msgDest); [[nodiscard]] MessageQueueId_t getDefaultDestination() const; @@ -28,6 +28,7 @@ class TmSendHelper { ReturnValue_t sendPacket(MessageQueueId_t dest, const store_address_t& storeId); ReturnValue_t sendPacket(const store_address_t& storeId); + private: MessageQueueId_t defaultDest = MessageQueueIF::NO_QUEUE; bool ignoreFault = false; diff --git a/src/fsfw/tmtcservices/TmStoreAndSendHelper.cpp b/src/fsfw/tmtcservices/TmStoreAndSendHelper.cpp index 9e858ed6..f10bea32 100644 --- a/src/fsfw/tmtcservices/TmStoreAndSendHelper.cpp +++ b/src/fsfw/tmtcservices/TmStoreAndSendHelper.cpp @@ -1,3 +1,51 @@ #include "TmStoreAndSendHelper.h" +#include "tmHelpers.h" -StoreAndSendWrapper::StoreAndSendWrapper(TmStoreHelper& storeHelper, TmSendHelper& sendHelper) {} +TmStoreAndSendWrapper::TmStoreAndSendWrapper( + uint8_t defaultService, TmStoreHelper& storeHelper, TmSendHelper& sendHelper) + : storeHelper(storeHelper), sendHelper(sendHelper), defaultService(defaultService){} + +ReturnValue_t TmStoreAndSendWrapper::storeAndSendTmPacket() { + ReturnValue_t result = storeHelper.addPacketToStore(); + if (result != HasReturnvaluesIF::RETURN_OK) { + return result; + } + result = sendHelper.sendPacket(storeHelper.getCurrentAddr()); + if (result != HasReturnvaluesIF::RETURN_OK) { + if (delOnFailure) { + storeHelper.deletePacket(); + } + return result; + } + if(incrementSendCounter) { + sendCounter++; + } + return result; +} + +ReturnValue_t TmStoreAndSendWrapper::sendTmPacket(uint8_t subservice, const uint8_t* sourceData, + size_t sourceDataLen) { + storeHelper.preparePacket(defaultService, subservice, sendCounter); + storeHelper.setSourceDataRaw(sourceData, sourceDataLen); + return storeAndSendTmPacket(); +} + +ReturnValue_t TmStoreAndSendWrapper::sendTmPacket(uint8_t subservice, object_id_t objectId, + const uint8_t* data, size_t dataLen) { + telemetry::DataWithObjectIdPrefix dataWithObjId(objectId, data, dataLen); + storeHelper.preparePacket(defaultService, subservice, sendCounter); + storeHelper.setSourceDataSerializable(dataWithObjId); + return storeAndSendTmPacket(); +} + +ReturnValue_t TmStoreAndSendWrapper::sendTmPacket(uint8_t subservice, SerializeIF& sourceData) { + storeHelper.preparePacket(defaultService, subservice, sendCounter); + storeHelper.setSourceDataSerializable(sourceData); + return storeAndSendTmPacket(); +} + +ReturnValue_t TmStoreAndSendWrapper::sendTmPacket(uint8_t subservice) { + storeHelper.preparePacket(defaultService, subservice, sendCounter); + storeHelper.setSourceDataRaw(nullptr, 0); + return storeAndSendTmPacket(); +} diff --git a/src/fsfw/tmtcservices/TmStoreAndSendHelper.h b/src/fsfw/tmtcservices/TmStoreAndSendHelper.h index d75d6839..44ad1799 100644 --- a/src/fsfw/tmtcservices/TmStoreAndSendHelper.h +++ b/src/fsfw/tmtcservices/TmStoreAndSendHelper.h @@ -4,15 +4,51 @@ #include "TmSendHelper.h" #include "TmStoreHelper.h" -class StoreAndSendWrapper { +/** + * Wrapper class intended to help with PUS TM handling. This wrapper class also caches the current packet count + * and the service ID + */ +class TmStoreAndSendWrapper { public: - StoreAndSendWrapper(TmStoreHelper& storeHelper, TmSendHelper& sendHelper) - : storeHelper(storeHelper), sendHelper(sendHelper) {} - ReturnValue_t storeAndSendTmPacket(TmStoreHelper& storeHelper, TmSendHelper& sendHelper, - bool delOnFailure = true); + TmStoreAndSendWrapper(uint8_t defaultService, TmStoreHelper& storeHelper, TmSendHelper& sendHelper); + ReturnValue_t storeAndSendTmPacket(); + + ReturnValue_t sendTmPacket(uint8_t subservice); + /** + * @brief Send TM data from pointer to data. + * If a header is supplied it is added before data + * @param subservice Number of subservice + * @param sourceData Custom source data + * @param sourceDataLen Lenght of data in the Packet + */ + ReturnValue_t sendTmPacket(uint8_t subservice, const uint8_t* sourceData, size_t sourceDataLen); + + /** + * @brief To send TM packets of objects that still need to be serialized + * and consist of an object ID with appended data. + * @param subservice Number of subservice + * @param objectId ObjectId is placed before data + * @param data Data to append to the packet + * @param dataLen Length of Data + */ + ReturnValue_t sendTmPacket(uint8_t subservice, object_id_t objectId, const uint8_t* data, + size_t dataLen); + + /** + * @brief To send packets which are contained inside a class implementing + * SerializeIF. + * @param subservice Number of subservice + * @param content This is a pointer to the serialized packet + * @param header Serialize IF header which will be placed before content + */ + ReturnValue_t sendTmPacket(uint8_t subservice, SerializeIF& sourceData); + + bool incrementSendCounter = true; TmStoreHelper& storeHelper; TmSendHelper& sendHelper; bool delOnFailure = true; + uint8_t defaultService = 0; + uint16_t sendCounter = 0; }; #endif // FSFW_TMTCSERVICES_TMSTOREANDSENDHELPER_H diff --git a/src/fsfw/tmtcservices/TmStoreHelper.cpp b/src/fsfw/tmtcservices/TmStoreHelper.cpp index eb538518..a8105ae0 100644 --- a/src/fsfw/tmtcservices/TmStoreHelper.cpp +++ b/src/fsfw/tmtcservices/TmStoreHelper.cpp @@ -71,3 +71,7 @@ PusTmCreator& TmStoreHelper::getCreatorRef() { return creator; } TimeStamperIF* TmStoreHelper::getTimeStamper() const { return creator.getTimestamper(); } uint16_t TmStoreHelper::getApid() const { return creator.getApid(); } + +ReturnValue_t TmStoreHelper::setService(uint8_t service) { creator.setService(service); } + +ReturnValue_t TmStoreHelper::setSubservice(uint8_t subservice) { creator.setSubservice(subservice); } diff --git a/src/fsfw/tmtcservices/TmStoreHelper.h b/src/fsfw/tmtcservices/TmStoreHelper.h index 3a868d97..6c18ac7f 100644 --- a/src/fsfw/tmtcservices/TmStoreHelper.h +++ b/src/fsfw/tmtcservices/TmStoreHelper.h @@ -27,6 +27,8 @@ class TmStoreHelper { [[nodiscard]] uint16_t getApid() const; [[nodiscard]] const store_address_t& getCurrentAddr() const; + ReturnValue_t setService(uint8_t service); + ReturnValue_t setSubservice(uint8_t subservice); ReturnValue_t setSourceDataRaw(const uint8_t* data, size_t len); ReturnValue_t setSourceDataSerializable(SerializeIF& serializable); diff --git a/src/fsfw/tmtcservices/tmHelpers.cpp b/src/fsfw/tmtcservices/tmHelpers.cpp index 50b40c76..abe2ae78 100644 --- a/src/fsfw/tmtcservices/tmHelpers.cpp +++ b/src/fsfw/tmtcservices/tmHelpers.cpp @@ -1,16 +1 @@ #include "tmHelpers.h" - -ReturnValue_t telemetry::storeAndSendTmPacket(TmStoreHelper &storeHelper, TmSendHelper &sendHelper, - bool delOnFailure) { - ReturnValue_t result = storeHelper.addPacketToStore(); - if (result != HasReturnvaluesIF::RETURN_OK) { - return result; - } - result = sendHelper.sendPacket(storeHelper.getCurrentAddr()); - if (result != HasReturnvaluesIF::RETURN_OK) { - if (delOnFailure) { - storeHelper.deletePacket(); - } - } - return result; -} diff --git a/src/fsfw_hal/linux/CommandExecutor.h b/src/fsfw_hal/linux/CommandExecutor.h index 90662c0f..f5c7a803 100644 --- a/src/fsfw_hal/linux/CommandExecutor.h +++ b/src/fsfw_hal/linux/CommandExecutor.h @@ -32,26 +32,26 @@ class CommandExecutor { //! [EXPORT] : [COMMENT] Execution of the current command has finished static constexpr ReturnValue_t EXECUTION_FINISHED = - HasReturnvaluesIF::makeReturnCode(CLASS_ID, 0); + retval::makeCode(CLASS_ID, 0); //! [EXPORT] : [COMMENT] Command is pending. This will also be returned if the user tries //! to load another command but a command is still pending - static constexpr ReturnValue_t COMMAND_PENDING = HasReturnvaluesIF::makeReturnCode(CLASS_ID, 1); + static constexpr ReturnValue_t COMMAND_PENDING = retval::makeCode(CLASS_ID, 1); //! [EXPORT] : [COMMENT] Some bytes have been read from the executing process - static constexpr ReturnValue_t BYTES_READ = HasReturnvaluesIF::makeReturnCode(CLASS_ID, 2); + static constexpr ReturnValue_t BYTES_READ = retval::makeCode(CLASS_ID, 2); //! [EXPORT] : [COMMENT] Command execution failed - static constexpr ReturnValue_t COMMAND_ERROR = HasReturnvaluesIF::makeReturnCode(CLASS_ID, 3); + static constexpr ReturnValue_t COMMAND_ERROR = retval::makeCode(CLASS_ID, 3); //! [EXPORT] : [COMMENT] static constexpr ReturnValue_t NO_COMMAND_LOADED_OR_PENDING = - HasReturnvaluesIF::makeReturnCode(CLASS_ID, 4); - static constexpr ReturnValue_t PCLOSE_CALL_ERROR = HasReturnvaluesIF::makeReturnCode(CLASS_ID, 6); + retval::makeCode(CLASS_ID, 4); + static constexpr ReturnValue_t PCLOSE_CALL_ERROR =retval::makeCode(CLASS_ID, 6); /** * Constructor. Is initialized with maximum size of internal buffer to read data from the * executed process. * @param maxSize */ - CommandExecutor(const size_t maxSize); + explicit CommandExecutor(size_t maxSize); /** * Load a new command which should be executed diff --git a/unittests/tmtcservices/testSendHelper.cpp b/unittests/tmtcservices/testSendHelper.cpp index 17a1d990..4271f192 100644 --- a/unittests/tmtcservices/testSendHelper.cpp +++ b/unittests/tmtcservices/testSendHelper.cpp @@ -68,11 +68,6 @@ TEST_CASE("TM Send Helper", "[tm-send-helper]") { storeId = storeHelper.getCurrentAddr(); REQUIRE(sendHelper.sendPacket(storeId) == HasReturnvaluesIF::RETURN_OK); } - SECTION("Helper Wrapper") { - REQUIRE(telemetry::storeAndSendTmPacket(storeHelper, sendHelper) == - HasReturnvaluesIF::RETURN_OK); - storeId = storeHelper.getCurrentAddr(); - } REQUIRE(msgQueue.wasMessageSent()); REQUIRE(msgQueue.numberOfSentMessagesToDefault() == 1); TmTcMessage msg;