From c6276fca11207167d756d6bf20d4ecb6c3bf9b36 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Fri, 16 Sep 2022 17:02:35 +0200 Subject: [PATCH] add cfdp components to generic factory --- example/CMakeLists.txt | 1 + example/cfdp/CMakeLists.txt | 1 + example/cfdp/Config.h | 56 +++++++++++++++++++++++++++++++++ example/core/GenericFactory.cpp | 40 +++++++++++++++++++++-- example/core/GenericFactory.h | 11 ++++++- 5 files changed, 106 insertions(+), 3 deletions(-) create mode 100644 example/cfdp/CMakeLists.txt create mode 100644 example/cfdp/Config.h diff --git a/example/CMakeLists.txt b/example/CMakeLists.txt index 441e867..65f6c1a 100644 --- a/example/CMakeLists.txt +++ b/example/CMakeLists.txt @@ -3,3 +3,4 @@ add_subdirectory(core) add_subdirectory(devices) add_subdirectory(test) add_subdirectory(utility) +add_subdirectory(cfdp) diff --git a/example/cfdp/CMakeLists.txt b/example/cfdp/CMakeLists.txt new file mode 100644 index 0000000..8b13789 --- /dev/null +++ b/example/cfdp/CMakeLists.txt @@ -0,0 +1 @@ + diff --git a/example/cfdp/Config.h b/example/cfdp/Config.h new file mode 100644 index 0000000..3abf353 --- /dev/null +++ b/example/cfdp/Config.h @@ -0,0 +1,56 @@ +#ifndef FSFW_EXAMPLE_HOSTED_CONFIG_H +#define FSFW_EXAMPLE_HOSTED_CONFIG_H + +#include "fsfw/cfdp.h" + +namespace cfdp { + +class ExampleUserHandler : public UserBase { + public: + explicit ExampleUserHandler(HasFileSystemIF& vfs) : cfdp::UserBase(vfs) {} + + void transactionIndication(const cfdp::TransactionId& id) override {} + void eofSentIndication(const cfdp::TransactionId& id) override {} + void transactionFinishedIndication(const cfdp::TransactionFinishedParams& params) override { + sif::info << "File transaction finished for transaction with " << params.id << std::endl; + } + void metadataRecvdIndication(const cfdp::MetadataRecvdParams& params) override { + sif::info << "Metadata received for transaction with " << params.id << std::endl; + } + void fileSegmentRecvdIndication(const cfdp::FileSegmentRecvdParams& params) override {} + void reportIndication(const cfdp::TransactionId& id, cfdp::StatusReportIF& report) override {} + void suspendedIndication(const cfdp::TransactionId& id, cfdp::ConditionCode code) override {} + void resumedIndication(const cfdp::TransactionId& id, size_t progress) override {} + void faultIndication(const cfdp::TransactionId& id, cfdp::ConditionCode code, + size_t progress) override {} + void abandonedIndication(const cfdp::TransactionId& id, cfdp::ConditionCode code, + size_t progress) override {} + void eofRecvIndication(const cfdp::TransactionId& id) override { + sif::info << "EOF PDU received for transaction with " << id << std::endl; + } +}; + +class ExampleFaultHandler : public cfdp::FaultHandlerBase { + public: + void noticeOfSuspensionCb(cfdp::TransactionId& id, cfdp::ConditionCode code) override { + sif::warning << "Notice of suspension detected for transaction " << id + << " with condition code: " << cfdp::getConditionCodeString(code) << std::endl; + } + void noticeOfCancellationCb(cfdp::TransactionId& id, cfdp::ConditionCode code) override { + sif::warning << "Notice of suspension detected for transaction " << id + << " with condition code: " << cfdp::getConditionCodeString(code) << std::endl; + } + void abandonCb(cfdp::TransactionId& id, cfdp::ConditionCode code) override { + sif::warning << "Transaction " << id + << " was abandoned, condition code : " << cfdp::getConditionCodeString(code) + << std::endl; + } + void ignoreCb(cfdp::TransactionId& id, cfdp::ConditionCode code) override { + sif::warning << "Fault ignored for transaction " << id + << ", condition code: " << cfdp::getConditionCodeString(code) << std::endl; + } +}; + +} // namespace cfdp + +#endif // FSFW_EXAMPLE_HOSTED_CONFIG_H diff --git a/example/core/GenericFactory.cpp b/example/core/GenericFactory.cpp index d51cf9c..4c70e90 100644 --- a/example/core/GenericFactory.cpp +++ b/example/core/GenericFactory.cpp @@ -1,12 +1,13 @@ #include "GenericFactory.h" -#include "OBSWConfig.h" #include "common/definitions.h" #include "definitions.h" +#include "example/cfdp/Config.h" #include "example/test/FsfwExampleTask.h" #include "example/test/FsfwReaderTask.h" #include "example/utility/TmFunnel.h" #include "fsfw/FSFW.h" +#include "fsfw/cfdp.h" #include "fsfw/cfdp/CfdpDistributor.h" #include "fsfw/devicehandlers/CookieIF.h" #include "fsfw/events/EventManager.h" @@ -27,6 +28,7 @@ #include "fsfw/tcdistribution/PusDistributor.h" #include "fsfw/timemanager/CdsShortTimeStamper.h" #include "fsfw/tmtcservices/VerificationReporter.h" +#include "fsfw_hal/host/HostFilesystem.h" #include "fsfw_tests/integration/assemblies/TestAssembly.h" #include "fsfw_tests/integration/controller/TestController.h" #include "fsfw_tests/integration/devices/TestCookie.h" @@ -35,8 +37,19 @@ #include "fsfw_tests/internal/InternalUnitTester.h" #include "objects/systemObjectList.h" +#if OBSW_ADD_CFDP_COMPONENTS == 1 +namespace cfdp { +EntityId REMOTE_CFDP_ID(cfdp::WidthInBytes::TWO_BYTES, common::COMMON_CFDP_CLIENT_ENTITY_ID); +RemoteEntityCfg GROUND_REMOTE_CFG(REMOTE_CFDP_ID); +OneRemoteConfigProvider REMOTE_CFG_PROVIDER(GROUND_REMOTE_CFG); +HostFilesystem HOST_FS; +ExampleUserHandler USER_HANDLER(HOST_FS); +ExampleFaultHandler EXAMPLE_FAULT_HANDLER; +} // namespace cfdp +#endif + void ObjectFactory::produceGenericObjects(TmFunnel **tmFunnel, CcsdsDistributor **ccsdsDistrib, - StorageManagerIF &tcStore) { + StorageManagerIF &tcStore, StorageManagerIF &tmStore) { #if OBSW_ADD_CORE_COMPONENTS == 1 /* Framework objects */ new EventManager(objects::EVENT_MANAGER); @@ -141,6 +154,29 @@ void ObjectFactory::produceGenericObjects(TmFunnel **tmFunnel, CcsdsDistributor InternalUnitTester unittester; unittester.performTests(testCfg); #endif /* OBSW_PERFORM_INTERNAL_UNITTEST == 1 */ + +#if OBSW_ADD_CFDP_COMPONENTS == 1 + using namespace cfdp; + auto *msgQueue = QueueFactory::instance()->createMessageQueue(32); + UnsignedByteField remoteEntityId(common::COMMON_CFDP_CLIENT_ENTITY_ID); + cfdp::EntityId remoteId(remoteEntityId); + cfdp::RemoteEntityCfg remoteCfg(remoteId); + remoteCfg.defaultChecksum = cfdp::ChecksumType::CRC_32; + FsfwHandlerParams params(objects::CFDP_HANDLER, HOST_FS, **tmFunnel, tcStore, tmStore, *msgQueue); + cfdp::IndicationCfg indicationCfg; + UnsignedByteField apid(common::COMMON_CFDP_APID); + cfdp::EntityId localId(apid); + GROUND_REMOTE_CFG.defaultChecksum = cfdp::ChecksumType::CRC_32; + if (PACKET_LIST_PTR == nullptr or LOST_SEGMENTS_PTR == nullptr) { + sif::error << "CFDP: No packet list or lost segments container set" << std::endl; + } + CfdpHandlerCfg cfdpCfg(localId, indicationCfg, USER_HANDLER, EXAMPLE_FAULT_HANDLER, + *PACKET_LIST_PTR, *LOST_SEGMENTS_PTR, REMOTE_CFG_PROVIDER); + auto *cfdpHandler = new CfdpHandler(params, cfdpCfg); + CcsdsDistributorIF::DestInfo info("CFDP Destination", common::COMMON_CFDP_APID, + cfdpHandler->getRequestQueue(), true); + (*ccsdsDistrib)->registerApplication(info); +#endif } void Factory::setStaticFrameworkObjectIds() { diff --git a/example/core/GenericFactory.h b/example/core/GenericFactory.h index 7f33d7e..1500736 100644 --- a/example/core/GenericFactory.h +++ b/example/core/GenericFactory.h @@ -1,13 +1,22 @@ #ifndef MISSION_CORE_GENERICFACTORY_H_ #define MISSION_CORE_GENERICFACTORY_H_ +#include "OBSWConfig.h" #include +#include "fsfw/cfdp/handler/DestHandler.h" #include "fsfw/storagemanager/StorageManagerIF.h" class TmFunnel; class CcsdsDistributor; +#if OBSW_ADD_CFDP_COMPONENTS == 1 +namespace cfdp { +extern PacketInfoListBase* PACKET_LIST_PTR; +extern LostSegmentsListBase* LOST_SEGMENTS_PTR; +} // namespace cfdp +#endif + namespace ObjectFactory { /** @@ -15,7 +24,7 @@ namespace ObjectFactory { * object factory. */ void produceGenericObjects(TmFunnel** funnel, CcsdsDistributor** ccsdsDistributor, - StorageManagerIF& tcStore); + StorageManagerIF& tcStore, StorageManagerIF& tmStore); } // namespace ObjectFactory