From ae2823ba2d4f8e961427e9559534bbce294551e6 Mon Sep 17 00:00:00 2001 From: Ulrich Mohr Date: Wed, 12 Jul 2023 14:19:58 +0200 Subject: [PATCH] tm path --- src/fsfw/action/ActionHelper.cpp | 23 +------- src/fsfw/housekeeping/HousekeepingHelper.h | 6 +- src/fsfw/housekeeping/HousekeepingSet.cpp | 11 +++- src/fsfw/housekeeping/HousekeepingSet.h | 10 +++- src/fsfw/tmtc/FsfwProtocolHeader.h | 13 +++-- src/fsfw/tmtc/TmManager.cpp | 64 +++++++++++++++++++++- src/fsfw/tmtc/TmManager.h | 35 ++++++++---- 7 files changed, 113 insertions(+), 49 deletions(-) diff --git a/src/fsfw/action/ActionHelper.cpp b/src/fsfw/action/ActionHelper.cpp index 0c2b061a5..2f24641fb 100644 --- a/src/fsfw/action/ActionHelper.cpp +++ b/src/fsfw/action/ActionHelper.cpp @@ -118,29 +118,12 @@ void ActionHelper::prepareExecution(MessageQueueId_t commandedBy, size_t offset, action->commandedBy = commandedBy; result = owner->executeAction(action); - TmManager::protocolInformation information; - result = tmManager->getProtocolInformation(dataAddress, &information); + result = + tmManager->sendTmPacket(0xff, HasActionsIF::INTERFACE_ID, 0x13, action, dataAddress, offset); if (result != returnvalue::OK) { - // HTF did we get here? + sif::error << "replying action failed " << std::hex << result << std::dec << std::endl; } - store_address_t replyStoreId; - uint8_t* replyPointer; - result = ipcStore->getFreeElement(&replyStoreId, information.offset + 4, &replyPointer); - - if (result != returnvalue::OK) { - return; - } - - memset(replyPointer, 0xfd, 4); - - CommandMessage message; - - ipcStore->deleteData(dataAddress); - TmMessage::setCommand(&message, replyStoreId, store_address_t()); - - queueToUse->sendMessage(information.reportingQueue, &message); - // ipcStore->deleteData(dataAddress); if (result == HasActionsIF::EXECUTION_FINISHED) { CommandMessage reply; diff --git a/src/fsfw/housekeeping/HousekeepingHelper.h b/src/fsfw/housekeeping/HousekeepingHelper.h index a92ef5d32..d2cfcc500 100644 --- a/src/fsfw/housekeeping/HousekeepingHelper.h +++ b/src/fsfw/housekeeping/HousekeepingHelper.h @@ -8,7 +8,7 @@ #include "HousekeepingSet.h" class HousekeepingHelper { - friend class HousekeepingHelper; + friend class HousekeepingSet; public: HousekeepingHelper(); @@ -20,10 +20,10 @@ class HousekeepingHelper { return &housekeepingSets; } + protected: void registerSet(HousekeepingSet* set); - protected: - ReturnValue_t reportHousekeeping(SerializeIF* data, const Action* action = nullptr); + ReturnValue_t reportHousekeeping(HousekeepingSet* set, const Action* action = nullptr); private: std::map housekeepingSets; diff --git a/src/fsfw/housekeeping/HousekeepingSet.cpp b/src/fsfw/housekeeping/HousekeepingSet.cpp index 9a5f7468a..1cd07d9ee 100644 --- a/src/fsfw/housekeeping/HousekeepingSet.cpp +++ b/src/fsfw/housekeeping/HousekeepingSet.cpp @@ -4,7 +4,8 @@ #ifdef FSFW_INTROSPECTION HousekeepingSet::HousekeepingSet(GeneratesHousekeepingIF* owner, HousekeepingSetId_t id) { - owner->getHelper()->registerSet(this); + helper = owner->getHelper(); + helper->registerSet(this); } void HousekeepingSet::setEnum(EnumIF* theEnum) { @@ -13,13 +14,17 @@ void HousekeepingSet::setEnum(EnumIF* theEnum) { } #else HousekeepingSet::HousekeepingSet(GeneratesHousekeepingIF* owner, HousekeepingSetId_t id) : id(id) { - owner->getHelper()->registerSet(this); + helper = owner->getHelper(); + helper->registerSet(this); } #endif +void HousekeepingSet::report(const Action* action) { + helper->reportHousekeeping(this, action); +} + void HousekeepingSet::registerParameter(ParameterIF* parameter) { parameterList.push_back(parameter); } - std::vector const* HousekeepingSet::getParameters() { return ¶meterList; } diff --git a/src/fsfw/housekeeping/HousekeepingSet.h b/src/fsfw/housekeeping/HousekeepingSet.h index 6ed9788dd..7d3c9ceb1 100644 --- a/src/fsfw/housekeeping/HousekeepingSet.h +++ b/src/fsfw/housekeeping/HousekeepingSet.h @@ -4,6 +4,7 @@ #include #include #include +#include #include @@ -12,20 +13,21 @@ class GeneratesHousekeepingIF; using HousekeepingSetId_t = uint32_t; -class HousekeepingSet : public HasTmTcParametersIF { +class HousekeepingSet : public HasTmTcParametersIF, public SerializeIF { + friend class ParameterIF; + public: #ifdef FSFW_INTROSPECTION HousekeepingSet(GeneratesHousekeepingIF* owner); void setEnum(EnumIF* theEnum); #else - HousekeepingSet(GeneratesHousekeepingIF *owner, HousekeepingSetId_t id); + HousekeepingSet(GeneratesHousekeepingIF* owner, HousekeepingSetId_t id); #endif HousekeepingSetId_t getId() const { return id; } void report(const Action* action = nullptr); - void registerParameter(ParameterIF* parameter) override; std::vector const* getParameters() override; protected: @@ -35,4 +37,6 @@ class HousekeepingSet : public HasTmTcParametersIF { const char* description; #endif std::vector parameterList; + + void registerParameter(ParameterIF* parameter) override; }; \ No newline at end of file diff --git a/src/fsfw/tmtc/FsfwProtocolHeader.h b/src/fsfw/tmtc/FsfwProtocolHeader.h index 14a5c30f7..d1c4c4cf9 100644 --- a/src/fsfw/tmtc/FsfwProtocolHeader.h +++ b/src/fsfw/tmtc/FsfwProtocolHeader.h @@ -5,10 +5,13 @@ class FsfwProtocolHeader : public SerializeIF { public: + using InterfaceType_t = uint8_t; + using FunctionType_t = uint8_t; + static const size_t HEADER_SIZE = 6; FsfwProtocolHeader(); - FsfwProtocolHeader(object_id_t objectID, uint8_t interface, uint8_t function); + FsfwProtocolHeader(object_id_t objectID, InterfaceType_t interface, FunctionType_t function); ~FsfwProtocolHeader() override; ReturnValue_t serialize(uint8_t **buffer, size_t *size, size_t maxSize, @@ -20,11 +23,11 @@ class FsfwProtocolHeader : public SerializeIF { Endianness streamEndianness) override; object_id_t getObjectId() const; - uint8_t getInterface() const; - uint8_t getFunction() const; + InterfaceType_t getInterface() const; + FunctionType_t getFunction() const; private: object_id_t objectId; - uint8_t interface; - uint8_t function; + InterfaceType_t interface; + FunctionType_t function; }; \ No newline at end of file diff --git a/src/fsfw/tmtc/TmManager.cpp b/src/fsfw/tmtc/TmManager.cpp index 25e4f7f12..1bfb4d469 100644 --- a/src/fsfw/tmtc/TmManager.cpp +++ b/src/fsfw/tmtc/TmManager.cpp @@ -1,7 +1,10 @@ #include "TmManager.h" +#include #include +#include "TmMessage.h" + TmManager::TmManager(object_id_t setObjectId) : SystemObject(setObjectId) {} ReturnValue_t TmManager::initialize() { @@ -18,8 +21,62 @@ ReturnValue_t TmManager::initialize() { return returnvalue::OK; } +ReturnValue_t TmManager::sendTmPacket(object_id_t objectId, + FsfwProtocolHeader::InterfaceType_t interface, + FsfwProtocolHeader::FunctionType_t function, + SerializeIF* applicationData, store_address_t tc, + size_t tcOffset) { + ProtocolInformation information; + + ReturnValue_t result = getProtocolInformation(tc, &information); + if (result != returnvalue::OK) { + return result; + } + + const FsfwProtocolHeader tmHeader = FsfwProtocolHeader(objectId, interface, function); + + const size_t storedTcSize = + information.offset + tmHeader.getSerializedSize() + applicationData->getSerializedSize(); + + store_address_t tm; + uint8_t* dataPointer; + result = IPCStore->getFreeElement(&tm, storedTcSize, &dataPointer); + if (result != returnvalue::OK) { + return result; + } + + *dataPointer = information.protocol; + + size_t serializedSize = information.offset; + dataPointer += information.offset; + + result = tmHeader.serialize(&dataPointer, &serializedSize, storedTcSize, + SerializeIF::Endianness::NETWORK); + if (result != returnvalue::OK) { + IPCStore->deleteData(tm); + return result; + } + result = applicationData->serialize(&dataPointer, &serializedSize, storedTcSize, + SerializeIF::Endianness::NETWORK); + if (result != returnvalue::OK) { + IPCStore->deleteData(tm); + return result; + } + + CommandMessage tmMessage; + TmMessage::setCommand(&tmMessage, tm, tc); + + result = MessageQueueSenderIF::sendMessage(information.reportingQueue, &tmMessage); + if (result != returnvalue::OK) { + IPCStore->deleteData(tm); + return result; + } + + return returnvalue::OK; +} + ReturnValue_t TmManager::getProtocolInformation(store_address_t tc, - protocolInformation* information) const { + ProtocolInformation* information) const { const uint8_t* tcData; size_t tcDataSize; ReturnValue_t result = IPCStore->getData(tc, &tcData, &tcDataSize); @@ -47,12 +104,13 @@ ReturnValue_t TmManager::registerNetworkProtocolInterface(AcceptsTelemetryIF2* o return returnvalue::FAILED; } - protocolMap.emplace(protocol, ProtocolInformation({object->getReportReceptionQueue(), offset})); + protocolMap.emplace(protocol, + StoredProtocolInformation({object->getReportReceptionQueue(), offset})); return returnvalue::OK; } -ReturnValue_t TmManager::getDefaultProtocolInformation(protocolInformation* information) const { +ReturnValue_t TmManager::getDefaultProtocolInformation(ProtocolInformation* information) const { if (protocolMap.empty()) { return returnvalue::FAILED; } diff --git a/src/fsfw/tmtc/TmManager.h b/src/fsfw/tmtc/TmManager.h index 43173e45c..ee9cae9c8 100644 --- a/src/fsfw/tmtc/TmManager.h +++ b/src/fsfw/tmtc/TmManager.h @@ -6,18 +6,19 @@ #include #include "AcceptsTelemetryIF.h" +#include "FsfwProtocolHeader.h" #include "FsfwProtocols.h" // TODO handle VCs and backpressure +// TODO trailing space? class TmManager : public SystemObject { public: - struct protocolInformation { - neither_type protocol; - size_t offset; - MessageQueueId_t reportingQueue; - }; - + struct ProtocolInformation { + neither_type protocol; + size_t offset; + MessageQueueId_t reportingQueue; + }; TmManager(object_id_t setObjectId); @@ -25,32 +26,42 @@ class TmManager : public SystemObject { ReturnValue_t initialize() override; + /** + * send a tm packet + * + * + */ + ReturnValue_t sendTmPacket(object_id_t objectId, FsfwProtocolHeader::InterfaceType_t interface, + FsfwProtocolHeader::FunctionType_t function, + SerializeIF *applicationData, + store_address_t tc = store_address_t(), size_t tcOffset = 0); + /** * returns the offset which the application data should start at, using the same network layer as * the tc, as well as the protocol type which should be the first byte of the tm * */ - ReturnValue_t getProtocolInformation(store_address_t tc, protocolInformation *information) const; + ReturnValue_t getProtocolInformation(store_address_t tc, ProtocolInformation *information) const; /** * If tm is unrequested, get Default path */ - ReturnValue_t getDefaultProtocolInformation(protocolInformation *information) const; + ReturnValue_t getDefaultProtocolInformation(ProtocolInformation *information) const; /** - * Offset is where application data should start in a preset zero-copy packet. If no fixed value, - * report 0 and allocate and copy yourself + * Offset is where application data should start in a preallocated zero-copy packet. If no fixed + * value, report 0 and allocate and copy yourself */ ReturnValue_t registerNetworkProtocolInterface(AcceptsTelemetryIF2 *object, neither_type protocol, size_t offset); protected: - struct ProtocolInformation { + struct StoredProtocolInformation { MessageQueueId_t queue; size_t offset; }; StorageManagerIF *IPCStore; - std::map protocolMap; + std::map protocolMap; }; \ No newline at end of file