From 6d43fa891108be4a11db820d1b2174c28910fa5f Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Thu, 8 Sep 2022 11:26:29 +0200 Subject: [PATCH] continue handler implementation --- bsp_hosted/core/CfdpHandler.cpp | 51 +++++++++++++++++++++++++++------ bsp_hosted/core/CfdpHandler.h | 34 +++++++++++++--------- fsfw | 2 +- 3 files changed, 64 insertions(+), 23 deletions(-) diff --git a/bsp_hosted/core/CfdpHandler.cpp b/bsp_hosted/core/CfdpHandler.cpp index 1e15e41..691190d 100644 --- a/bsp_hosted/core/CfdpHandler.cpp +++ b/bsp_hosted/core/CfdpHandler.cpp @@ -1,16 +1,19 @@ #include "CfdpHandler.h" +#include "fsfw/cfdp/pdu/PduHeaderReader.h" #include "fsfw/ipc/QueueFactory.h" +#include "fsfw/tmtcservices/TmTcMessage.h" using namespace returnvalue; using namespace cfdp; -CfdpHandler::CfdpHandler(const HandlerCfg& cfg) - : SystemObject(cfg.objectId), - UserBase(cfg.vfs), - destHandler( - DestHandlerParams(cfg.cfg, *this, *this, cfg.packetInfoList, cfg.lostSegmentsList), - FsfwParams(cfg.packetDest, nullptr, this)) { +CfdpHandler::CfdpHandler(const FsfwHandlerParams& fsfwParams, const CfdpHandlerCfg& cfdpCfg) + : SystemObject(fsfwParams.objectId), + UserBase(fsfwParams.vfs), + destHandler(DestHandlerParams(cfdpCfg.cfg, *this, *this, cfdpCfg.packetInfoList, + cfdpCfg.lostSegmentsList), + FsfwParams(fsfwParams.packetDest, nullptr, this, fsfwParams.tcStore, + fsfwParams.tmStore)) { // TODO: Make queue params configurable, or better yet, expect it to be passed externally msgQueue = QueueFactory::instance()->createMessageQueue(); destHandler.setMsgQueue(*msgQueue); @@ -19,8 +22,7 @@ CfdpHandler::CfdpHandler(const HandlerCfg& cfg) [[nodiscard]] const char* CfdpHandler::getName() const { return "CFDP Handler"; } [[nodiscard]] uint32_t CfdpHandler::getIdentifier() const { - // TODO: Return local entity ID? Which will probably be equal to APID - return 0; + return destHandler.getDestHandlerParams().cfg.localId.getValue(); } [[nodiscard]] MessageQueueId_t CfdpHandler::getRequestQueue() const { return msgQueue->getId(); } @@ -30,13 +32,26 @@ ReturnValue_t CfdpHandler::initialize() { if (result != OK) { return result; } + tcStore = destHandler.getTcStore(); + tmStore = destHandler.getTmStore(); + return SystemObject::initialize(); } ReturnValue_t CfdpHandler::performOperation(uint8_t operationCode) { // TODO: Receive TC packets and route them to source and dest handler, depending on which is // correct or more appropriate - return OK; + ReturnValue_t status; + ReturnValue_t result = OK; + TmTcMessage tmtcMsg; + for (status = msgQueue->receiveMessage(&tmtcMsg); status == returnvalue::OK; + status = msgQueue->receiveMessage(&tmtcMsg)) { + result = handleCfdpPacket(tmtcMsg); + if (result != OK) { + status = result; + } + } + return status; } void CfdpHandler::transactionIndication(const cfdp::TransactionId& id) {} @@ -56,3 +71,21 @@ void CfdpHandler::eofRecvIndication(const cfdp::TransactionId& id) {} bool CfdpHandler::getRemoteCfg(const cfdp::EntityId& remoteId, cfdp::RemoteEntityCfg** cfg) { return false; } + +ReturnValue_t CfdpHandler::handleCfdpPacket(TmTcMessage& msg) { + auto accessorPair = tcStore->getData(msg.getStorageId()); + PduHeaderReader reader(accessorPair.second.data(), accessorPair.second.size()); + ReturnValue_t result = reader.parseData(); + if (result != returnvalue::OK) { + return result; + } + // The CFDP distributor should have taken care of ensuring the destination ID is correct + PduTypes type = reader.getPduType(); + // Only the destination handler can process these PDUs + if (type == PduTypes::FILE_DATA) { + } else { + // Route depending on directive type. Retrieve directive type from raw stream for better + // performance (with size check) + } + return OK; +} diff --git a/bsp_hosted/core/CfdpHandler.h b/bsp_hosted/core/CfdpHandler.h index 45c8b10..d409964 100644 --- a/bsp_hosted/core/CfdpHandler.h +++ b/bsp_hosted/core/CfdpHandler.h @@ -7,23 +7,27 @@ #include "fsfw/objectmanager/SystemObject.h" #include "fsfw/tasks/ExecutableObjectIF.h" #include "fsfw/tmtcservices/AcceptsTelecommandsIF.h" +#include "fsfw/tmtcservices/TmTcMessage.h" -struct HandlerCfg { - HandlerCfg(object_id_t objectId, cfdp::LocalEntityCfg cfg, HasFileSystemIF& vfs, - AcceptsTelemetryIF& packetDest, cfdp::PacketInfoListBase& packetInfo, - cfdp::LostSegmentsListBase& lostSegmentsList) - : objectId(objectId), - cfg(std::move(cfg)), - vfs(vfs), - packetInfoList(packetInfo), - lostSegmentsList(lostSegmentsList), - packetDest(packetDest) {} +struct FsfwHandlerParams { + FsfwHandlerParams(object_id_t objectId, HasFileSystemIF& vfs, AcceptsTelemetryIF& packetDest, + StorageManagerIF& tcStore, StorageManagerIF& tmStore) + : objectId(objectId), vfs(vfs), packetDest(packetDest), tcStore(tcStore), tmStore(tmStore) {} object_id_t objectId{}; - cfdp::LocalEntityCfg cfg; HasFileSystemIF& vfs; + AcceptsTelemetryIF& packetDest; + StorageManagerIF& tcStore; + StorageManagerIF& tmStore; +}; + +struct CfdpHandlerCfg { + CfdpHandlerCfg(cfdp::LocalEntityCfg cfg, cfdp::PacketInfoListBase& packetInfo, + cfdp::LostSegmentsListBase& lostSegmentsList) + : cfg(std::move(cfg)), packetInfoList(packetInfo), lostSegmentsList(lostSegmentsList) {} + + cfdp::LocalEntityCfg cfg; cfdp::PacketInfoListBase& packetInfoList; cfdp::LostSegmentsListBase& lostSegmentsList; - AcceptsTelemetryIF& packetDest; }; class CfdpHandler : public SystemObject, @@ -32,7 +36,7 @@ class CfdpHandler : public SystemObject, public ExecutableObjectIF, public AcceptsTelecommandsIF { public: - explicit CfdpHandler(const HandlerCfg& cfg); + explicit CfdpHandler(const FsfwHandlerParams& fsfwParams, const CfdpHandlerCfg& cfdpCfg); [[nodiscard]] const char* getName() const override; [[nodiscard]] uint32_t getIdentifier() const override; @@ -62,6 +66,10 @@ class CfdpHandler : public SystemObject, private: MessageQueueIF* msgQueue = nullptr; cfdp::DestHandler destHandler; + StorageManagerIF* tcStore = nullptr; + StorageManagerIF* tmStore = nullptr; + + ReturnValue_t handleCfdpPacket(TmTcMessage& msg); }; #endif // FSFW_EXAMPLE_HOSTED_CFDPHANDLER_H diff --git a/fsfw b/fsfw index 11a4b27..c87667c 160000 --- a/fsfw +++ b/fsfw @@ -1 +1 @@ -Subproject commit 11a4b276423ac287f5522cdbf913a81e1ee3d347 +Subproject commit c87667c03f82f2be88e2a684b98a25be4cdae26b