From 11a4b276423ac287f5522cdbf913a81e1ee3d347 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Wed, 7 Sep 2022 18:20:38 +0200 Subject: [PATCH] allow deferred init --- src/fsfw/cfdp/handler/DestHandler.cpp | 12 +++++++++++- src/fsfw/cfdp/handler/DestHandler.h | 10 ++++++---- unittests/cfdp/handler/testDestHandler.cpp | 2 +- 3 files changed, 18 insertions(+), 6 deletions(-) diff --git a/src/fsfw/cfdp/handler/DestHandler.cpp b/src/fsfw/cfdp/handler/DestHandler.cpp index cd3cc3b4..3660f75c 100644 --- a/src/fsfw/cfdp/handler/DestHandler.cpp +++ b/src/fsfw/cfdp/handler/DestHandler.cpp @@ -116,6 +116,10 @@ ReturnValue_t cfdp::DestHandler::initialize() { return FAILED; } } + + if (fp.msgQueue == nullptr) { + return FAILED; + } return OK; } @@ -421,7 +425,7 @@ ReturnValue_t cfdp::DestHandler::sendFinishedPdu() { return result; } TmTcMessage msg(storeId); - result = fp.msgQueue.sendMessage(fp.packetDest.getReportReceptionQueue(), &msg); + result = fp.msgQueue->sendMessage(fp.packetDest.getReportReceptionQueue(), &msg); if (result != OK) { // TODO: Error handling and event, this is a non CFDP specific error (most likely store is full) return result; @@ -451,3 +455,9 @@ void cfdp::DestHandler::checkAndHandleError(ReturnValue_t result, uint8_t& error errorIdx++; } } + +void cfdp::DestHandler::setMsgQueue(MessageQueueIF& queue) { fp.msgQueue = &queue; } + +void cfdp::DestHandler::setEventReporter(EventReportingProxyIF& reporter) { + fp.eventReporter = &reporter; +} diff --git a/src/fsfw/cfdp/handler/DestHandler.h b/src/fsfw/cfdp/handler/DestHandler.h index 8d2fc6e9..5507045f 100644 --- a/src/fsfw/cfdp/handler/DestHandler.h +++ b/src/fsfw/cfdp/handler/DestHandler.h @@ -62,12 +62,12 @@ struct DestHandlerParams { }; struct FsfwParams { - FsfwParams(AcceptsTelemetryIF& packetDest, MessageQueueIF& msgQueue, - EventReportingProxyIF& eventReporter) + FsfwParams(AcceptsTelemetryIF& packetDest, MessageQueueIF* msgQueue, + EventReportingProxyIF* eventReporter) : packetDest(packetDest), msgQueue(msgQueue), eventReporter(eventReporter) {} AcceptsTelemetryIF& packetDest; - MessageQueueIF& msgQueue; - EventReportingProxyIF& eventReporter; + MessageQueueIF* msgQueue; + EventReportingProxyIF* eventReporter = nullptr; StorageManagerIF* tcStore = nullptr; StorageManagerIF* tmStore = nullptr; }; @@ -116,6 +116,8 @@ class DestHandler { * - @c CALL_FSM_AGAIN State machine should be called again. */ const FsmResult& performStateMachine(); + void setMsgQueue(MessageQueueIF& queue); + void setEventReporter(EventReportingProxyIF& reporter); ReturnValue_t passPacket(PacketInfo packet); diff --git a/unittests/cfdp/handler/testDestHandler.cpp b/unittests/cfdp/handler/testDestHandler.cpp index 404d8eed..20ddf678 100644 --- a/unittests/cfdp/handler/testDestHandler.cpp +++ b/unittests/cfdp/handler/testDestHandler.cpp @@ -38,7 +38,7 @@ TEST_CASE("CFDP Dest Handler", "[cfdp]") { LocalPool::LocalPoolConfig storeCfg = {{10, 32}, {10, 64}, {10, 128}, {10, 1024}}; StorageManagerMock tcStore(2, storeCfg); StorageManagerMock tmStore(3, storeCfg); - FsfwParams fp(tmReceiver, mqMock, eventReporterMock); + FsfwParams fp(tmReceiver, &mqMock, &eventReporterMock); RemoteEntityCfg cfg; cfg.remoteId = remoteId; remoteCfgTableMock.addRemoteConfig(cfg);