From 8a4ce91501b36e60dd484387772feb182187ae71 Mon Sep 17 00:00:00 2001 From: tomatze Date: Sun, 4 Jul 2021 15:39:07 +0200 Subject: [PATCH 1/3] fixed copied comment --- tcdistribution/CFDPDistributorIF.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tcdistribution/CFDPDistributorIF.h b/tcdistribution/CFDPDistributorIF.h index dd017c97..5f70e542 100644 --- a/tcdistribution/CFDPDistributorIF.h +++ b/tcdistribution/CFDPDistributorIF.h @@ -16,7 +16,7 @@ public: virtual ~CFDPDistributorIF() { } /** - * With this method, Services can register themselves at the PUS Distributor. + * With this method, Services can register themselves at the CFDP Distributor. * @param service A pointer to the registering Service. * @return - @c RETURN_OK on success, * - @c RETURN_FAILED on failure. From 4860d984f348ea2ae77f1fe2f128ef05bb542012 Mon Sep 17 00:00:00 2001 From: tomatze Date: Sun, 4 Jul 2021 16:20:26 +0200 Subject: [PATCH 2/3] refactored TcPacketCheck into TcPacketCheckIF to implement a CFDP packet checker --- tcdistribution/CFDPDistributor.h | 5 ++- tcdistribution/CMakeLists.txt | 3 +- tcdistribution/PUSDistributor.h | 5 ++- tcdistribution/TcPacketCheckCFDP.cpp | 13 +++++++ tcdistribution/TcPacketCheckCFDP.h | 35 +++++++++++++++++++ tcdistribution/TcPacketCheckIF.h | 32 +++++++++++++++++ ...TcPacketCheck.cpp => TcPacketCheckPUS.cpp} | 8 ++--- .../{TcPacketCheck.h => TcPacketCheckPUS.h} | 25 ++++++------- 8 files changed, 101 insertions(+), 25 deletions(-) create mode 100644 tcdistribution/TcPacketCheckCFDP.cpp create mode 100644 tcdistribution/TcPacketCheckCFDP.h create mode 100644 tcdistribution/TcPacketCheckIF.h rename tcdistribution/{TcPacketCheck.cpp => TcPacketCheckPUS.cpp} (85%) rename tcdistribution/{TcPacketCheck.h => TcPacketCheckPUS.h} (75%) diff --git a/tcdistribution/CFDPDistributor.h b/tcdistribution/CFDPDistributor.h index d61357b2..3b4c31f2 100644 --- a/tcdistribution/CFDPDistributor.h +++ b/tcdistribution/CFDPDistributor.h @@ -1,10 +1,9 @@ #ifndef FSFW_TCDISTRIBUTION_CFDPDISTRIBUTOR_H_ #define FSFW_TCDISTRIBUTION_CFDPDISTRIBUTOR_H_ +#include "TcPacketCheckCFDP.h" #include "CFDPDistributorIF.h" #include "TcDistributor.h" -#include "TcPacketCheck.h" - #include "../tmtcpacket/pus/tc.h" #include "../returnvalues/HasReturnvaluesIF.h" #include "../tmtcservices/AcceptsTelecommandsIF.h" @@ -43,7 +42,7 @@ protected: /** * This attribute contains the class, that performs a formal packet check. */ - TcPacketCheck checker; + TcPacketCheckCFDP checker; /** * With this class, verification messages are sent to the * TC Verification service. diff --git a/tcdistribution/CMakeLists.txt b/tcdistribution/CMakeLists.txt index 359b8a81..7118c38c 100644 --- a/tcdistribution/CMakeLists.txt +++ b/tcdistribution/CMakeLists.txt @@ -2,7 +2,8 @@ target_sources(${LIB_FSFW_NAME} PRIVATE CCSDSDistributor.cpp PUSDistributor.cpp TcDistributor.cpp - TcPacketCheck.cpp + TcPacketCheckPUS.cpp + TcPacketCheckCFDP.cpp CFDPDistributor.cpp ) diff --git a/tcdistribution/PUSDistributor.h b/tcdistribution/PUSDistributor.h index db93fbb3..1c9d4dfc 100644 --- a/tcdistribution/PUSDistributor.h +++ b/tcdistribution/PUSDistributor.h @@ -1,10 +1,9 @@ #ifndef FSFW_TCDISTRIBUTION_PUSDISTRIBUTOR_H_ #define FSFW_TCDISTRIBUTION_PUSDISTRIBUTOR_H_ +#include "TcPacketCheckPUS.h" #include "PUSDistributorIF.h" #include "TcDistributor.h" -#include "TcPacketCheck.h" - #include "../tmtcpacket/pus/tc.h" #include "../returnvalues/HasReturnvaluesIF.h" #include "../tmtcservices/AcceptsTelecommandsIF.h" @@ -43,7 +42,7 @@ protected: /** * This attribute contains the class, that performs a formal packet check. */ - TcPacketCheck checker; + TcPacketCheckPUS checker; /** * With this class, verification messages are sent to the * TC Verification service. diff --git a/tcdistribution/TcPacketCheckCFDP.cpp b/tcdistribution/TcPacketCheckCFDP.cpp new file mode 100644 index 00000000..2b0e3d32 --- /dev/null +++ b/tcdistribution/TcPacketCheckCFDP.cpp @@ -0,0 +1,13 @@ +#include "TcPacketCheckCFDP.h" + + +TcPacketCheckCFDP::TcPacketCheckCFDP(uint16_t setApid): apid(setApid) { +} + +ReturnValue_t TcPacketCheckCFDP::checkPacket(TcPacketStoredBase* currentPacket) { + return RETURN_OK; +} + +uint16_t TcPacketCheckCFDP::getApid() const { + return apid; +} diff --git a/tcdistribution/TcPacketCheckCFDP.h b/tcdistribution/TcPacketCheckCFDP.h new file mode 100644 index 00000000..41a65f08 --- /dev/null +++ b/tcdistribution/TcPacketCheckCFDP.h @@ -0,0 +1,35 @@ +#ifndef FSFW_TCDISTRIBUTION_TCPACKETCHECKCFDP_H_ +#define FSFW_TCDISTRIBUTION_TCPACKETCHECKCFDP_H_ + +#include "TcPacketCheckIF.h" + +#include "../FSFW.h" + +class TcPacketStoredBase; + +/** + * This class performs a formal packet check for incoming CFDP Packets. + * @ingroup tc_distribution + */ +class TcPacketCheckCFDP : + public TcPacketCheckIF, + public HasReturnvaluesIF { +protected: + /** + * The packet id each correct packet should have. + * It is composed of the APID and some static fields. + */ + uint16_t apid; +public: + /** + * The constructor only sets the APID attribute. + * @param set_apid The APID to set. + */ + TcPacketCheckCFDP(uint16_t setApid); + + ReturnValue_t checkPacket(TcPacketStoredBase* currentPacket) override; + + uint16_t getApid() const; +}; + +#endif /* FSFW_TCDISTRIBUTION_TCPACKETCHECKCFDP_H_ */ diff --git a/tcdistribution/TcPacketCheckIF.h b/tcdistribution/TcPacketCheckIF.h new file mode 100644 index 00000000..58c17021 --- /dev/null +++ b/tcdistribution/TcPacketCheckIF.h @@ -0,0 +1,32 @@ +#ifndef FSFW_TCDISTRIBUTION_TCPACKETCHECKIF_H_ +#define FSFW_TCDISTRIBUTION_TCPACKETCHECKIF_H_ + +#include "../returnvalues/HasReturnvaluesIF.h" + +// TODO TcPacketStoredBase is currently only for PUS packets. not for CFDP packets +class TcPacketStoredBase; + +/** + * This interface is used by PacketCheckers for PUS packets and CFDP packets . + * @ingroup tc_distribution + */ +class TcPacketCheckIF { +public: + /** + * The empty virtual destructor. + */ + virtual ~TcPacketCheckIF() { + } + + /** + * This is the actual method to formally check a certain Packet. + * The packet's Application Data can not be checked here. + * @param current_packet The packet to check + * @return - @c RETURN_OK on success. + * - @c INCORRECT_CHECKSUM if checksum is invalid. + * - @c ILLEGAL_APID if APID does not match. + */ + virtual ReturnValue_t checkPacket(TcPacketStoredBase* currentPacket) = 0; +}; + +#endif /* FSFW_TCDISTRIBUTION_TCPACKETCHECKIF_H_ */ diff --git a/tcdistribution/TcPacketCheck.cpp b/tcdistribution/TcPacketCheckPUS.cpp similarity index 85% rename from tcdistribution/TcPacketCheck.cpp rename to tcdistribution/TcPacketCheckPUS.cpp index b3a025a4..a338585e 100644 --- a/tcdistribution/TcPacketCheck.cpp +++ b/tcdistribution/TcPacketCheckPUS.cpp @@ -1,4 +1,4 @@ -#include "TcPacketCheck.h" +#include "TcPacketCheckPUS.h" #include "../globalfunctions/CRC.h" #include "../tmtcpacket/pus/tc/TcPacketBase.h" @@ -7,10 +7,10 @@ #include "../storagemanager/StorageManagerIF.h" #include "../tmtcservices/VerificationCodes.h" -TcPacketCheck::TcPacketCheck(uint16_t setApid): apid(setApid) { +TcPacketCheckPUS::TcPacketCheckPUS(uint16_t setApid): apid(setApid) { } -ReturnValue_t TcPacketCheck::checkPacket(TcPacketStoredBase* currentPacket) { +ReturnValue_t TcPacketCheckPUS::checkPacket(TcPacketStoredBase* currentPacket) { TcPacketBase* tcPacketBase = currentPacket->getPacketBase(); if(tcPacketBase == nullptr) { return RETURN_FAILED; @@ -41,6 +41,6 @@ ReturnValue_t TcPacketCheck::checkPacket(TcPacketStoredBase* currentPacket) { return RETURN_OK; } -uint16_t TcPacketCheck::getApid() const { +uint16_t TcPacketCheckPUS::getApid() const { return apid; } diff --git a/tcdistribution/TcPacketCheck.h b/tcdistribution/TcPacketCheckPUS.h similarity index 75% rename from tcdistribution/TcPacketCheck.h rename to tcdistribution/TcPacketCheckPUS.h index 7106b7e4..85b30378 100644 --- a/tcdistribution/TcPacketCheck.h +++ b/tcdistribution/TcPacketCheckPUS.h @@ -1,5 +1,7 @@ -#ifndef FSFW_TCDISTRIBUTION_TCPACKETCHECK_H_ -#define FSFW_TCDISTRIBUTION_TCPACKETCHECK_H_ +#ifndef FSFW_TCDISTRIBUTION_TCPACKETCHECKPUS_H_ +#define FSFW_TCDISTRIBUTION_TCPACKETCHECKPUS_H_ + +#include "TcPacketCheckIF.h" #include "../FSFW.h" #include "../returnvalues/HasReturnvaluesIF.h" @@ -12,7 +14,9 @@ class TcPacketStoredBase; * Currently, it only checks if the APID and CRC are correct. * @ingroup tc_distribution */ -class TcPacketCheck : public HasReturnvaluesIF { +class TcPacketCheckPUS : + public TcPacketCheckIF, + public HasReturnvaluesIF { protected: /** * Describes the version number a packet must have to pass. @@ -49,18 +53,11 @@ public: * The constructor only sets the APID attribute. * @param set_apid The APID to set. */ - TcPacketCheck(uint16_t setApid); - /** - * This is the actual method to formally check a certain Telecommand Packet. - * The packet's Application Data can not be checked here. - * @param current_packet The packt to check - * @return - @c RETURN_OK on success. - * - @c INCORRECT_CHECKSUM if checksum is invalid. - * - @c ILLEGAL_APID if APID does not match. - */ - ReturnValue_t checkPacket(TcPacketStoredBase* currentPacket); + TcPacketCheckPUS(uint16_t setApid); + + ReturnValue_t checkPacket(TcPacketStoredBase* currentPacket) override; uint16_t getApid() const; }; -#endif /* FSFW_TCDISTRIBUTION_TCPACKETCHECK_H_ */ +#endif /* FSFW_TCDISTRIBUTION_TCPACKETCHECKPUS_H_ */ From 974d25dbb1862eb02689a354c5ef5c72c8769002 Mon Sep 17 00:00:00 2001 From: tomatze Date: Sun, 18 Jul 2021 20:36:47 +0200 Subject: [PATCH 3/3] added CFDPHandler (not working yet) --- inc/fsfw/cfdp/CFDPHandler.h | 63 ++++++++++++++ inc/fsfw/objectmanager/frameworkObjects.h | 3 + inc/fsfw/tcdistribution/CFDPDistributor.h | 19 ++--- inc/fsfw/tcdistribution/CFDPDistributorIF.h | 14 +-- inc/fsfw/tmtcpacket/cfdp/CFDPPacket.h | 27 ++++++ inc/fsfw/tmtcpacket/cfdp/CFDPPacketStored.h | 64 ++++++++++++++ src/core/CMakeLists.txt | 1 + src/core/cfdp/CFDPHandler.cpp | 59 +++++++++++++ src/core/cfdp/CMakeLists.txt | 4 + src/core/tcdistribution/CFDPDistributor.cpp | 78 ++++++++--------- src/core/tmtcpacket/CMakeLists.txt | 1 + src/core/tmtcpacket/cfdp/CFDPPacket.cpp | 20 +++++ src/core/tmtcpacket/cfdp/CFDPPacketStored.cpp | 85 +++++++++++++++++++ src/core/tmtcpacket/cfdp/CMakeLists.txt | 4 + 14 files changed, 377 insertions(+), 65 deletions(-) create mode 100644 inc/fsfw/cfdp/CFDPHandler.h create mode 100644 inc/fsfw/tmtcpacket/cfdp/CFDPPacket.h create mode 100644 inc/fsfw/tmtcpacket/cfdp/CFDPPacketStored.h create mode 100644 src/core/cfdp/CFDPHandler.cpp create mode 100644 src/core/cfdp/CMakeLists.txt create mode 100644 src/core/tmtcpacket/cfdp/CFDPPacket.cpp create mode 100644 src/core/tmtcpacket/cfdp/CFDPPacketStored.cpp create mode 100644 src/core/tmtcpacket/cfdp/CMakeLists.txt diff --git a/inc/fsfw/cfdp/CFDPHandler.h b/inc/fsfw/cfdp/CFDPHandler.h new file mode 100644 index 00000000..ad561af7 --- /dev/null +++ b/inc/fsfw/cfdp/CFDPHandler.h @@ -0,0 +1,63 @@ +#ifndef FSFW_CFDP_CFDPHANDLER_H_ +#define FSFW_CFDP_CFDPHANDLER_H_ + +#include "fsfw/tmtcservices/AcceptsTelecommandsIF.h" +#include "fsfw/objectmanager/SystemObject.h" +#include "fsfw/returnvalues/HasReturnvaluesIF.h" +#include "fsfw/tasks/ExecutableObjectIF.h" +#include "fsfw/tcdistribution/CFDPDistributor.h" + +#include "fsfw/ipc/MessageQueueIF.h" + +namespace Factory{ +void setStaticFrameworkObjectIds(); +} + +class CFDPHandler : + public ExecutableObjectIF, + public AcceptsTelecommandsIF, + public SystemObject, + public HasReturnvaluesIF { + friend void (Factory::setStaticFrameworkObjectIds)(); +public: + CFDPHandler(object_id_t setObjectId, CFDPDistributor* distributor); + /** + * The destructor is empty. + */ + virtual ~CFDPHandler(); + + virtual ReturnValue_t handleRequest(uint8_t subservice); + + virtual ReturnValue_t performService(); + virtual ReturnValue_t initialize() override; + virtual uint16_t getIdentifier() override; + MessageQueueId_t getRequestQueue() override; + ReturnValue_t performOperation(uint8_t opCode) override; +protected: + /** + * This is a complete instance of the telecommand reception queue + * of the class. It is initialized on construction of the class. + */ + MessageQueueIF* requestQueue = nullptr; + + CFDPDistributor* distributor = nullptr; + + /** + * The current CFDP packet to be processed. + * It is deleted after handleRequest was executed. + */ + CFDPPacketStored currentPacket; + + static object_id_t packetSource; + + static object_id_t packetDestination; +private: + /** + * This constant sets the maximum number of packets accepted per call. + * Remember that one packet must be completely handled in one + * #handleRequest call. + */ + static const uint8_t CFDP_HANDLER_MAX_RECEPTION = 10; +}; + +#endif /* FSFW_CFDP_CFDPHANDLER_H_ */ diff --git a/inc/fsfw/objectmanager/frameworkObjects.h b/inc/fsfw/objectmanager/frameworkObjects.h index 36010807..acbb5f01 100644 --- a/inc/fsfw/objectmanager/frameworkObjects.h +++ b/inc/fsfw/objectmanager/frameworkObjects.h @@ -19,6 +19,9 @@ enum framework_objects: object_id_t { PUS_SERVICE_200_MODE_MGMT = 0x53000200, PUS_SERVICE_201_HEALTH = 0x53000201, + /* CFDP Distributer */ + CFDP_PACKET_DISTRIBUTOR = 0x53001000, + //Generic IDs for IPC, modes, health, events HEALTH_TABLE = 0x53010000, // MODE_STORE = 0x53010100, diff --git a/inc/fsfw/tcdistribution/CFDPDistributor.h b/inc/fsfw/tcdistribution/CFDPDistributor.h index 3b4c31f2..12436be2 100644 --- a/inc/fsfw/tcdistribution/CFDPDistributor.h +++ b/inc/fsfw/tcdistribution/CFDPDistributor.h @@ -1,10 +1,9 @@ #ifndef FSFW_TCDISTRIBUTION_CFDPDISTRIBUTOR_H_ #define FSFW_TCDISTRIBUTION_CFDPDISTRIBUTOR_H_ -#include "TcPacketCheckCFDP.h" #include "CFDPDistributorIF.h" #include "TcDistributor.h" -#include "../tmtcpacket/pus/tc.h" +#include "../tmtcpacket/cfdp/CFDPPacketStored.h" #include "../returnvalues/HasReturnvaluesIF.h" #include "../tmtcservices/AcceptsTelecommandsIF.h" #include "../tmtcservices/VerificationReporter.h" @@ -33,25 +32,17 @@ public: * The destructor is empty. */ virtual ~CFDPDistributor(); - ReturnValue_t registerService(AcceptsTelecommandsIF* service) override; + ReturnValue_t registerHandler(AcceptsTelecommandsIF* handler) override; MessageQueueId_t getRequestQueue() override; ReturnValue_t initialize() override; uint16_t getIdentifier() override; protected: - /** - * This attribute contains the class, that performs a formal packet check. - */ - TcPacketCheckCFDP checker; - /** - * With this class, verification messages are sent to the - * TC Verification service. - */ - VerificationReporter verifyChannel; + uint16_t apid; /** * The currently handled packet is stored here. */ - TcPacketStoredPus* currentPacket = nullptr; + CFDPPacketStored* currentPacket = nullptr; /** * With this variable, the current check status is stored to generate * acceptance messages later. @@ -73,7 +64,7 @@ protected: * The callback here handles the generation of acceptance * success/failure messages. */ - ReturnValue_t callbackAfterSending(ReturnValue_t queueStatus) override; + //ReturnValue_t callbackAfterSending(ReturnValue_t queueStatus) override; }; #endif /* FSFW_TCDISTRIBUTION_CFDPDISTRIBUTOR_H_ */ diff --git a/inc/fsfw/tcdistribution/CFDPDistributorIF.h b/inc/fsfw/tcdistribution/CFDPDistributorIF.h index 5f70e542..f1c85772 100644 --- a/inc/fsfw/tcdistribution/CFDPDistributorIF.h +++ b/inc/fsfw/tcdistribution/CFDPDistributorIF.h @@ -15,13 +15,13 @@ public: */ virtual ~CFDPDistributorIF() { } -/** - * With this method, Services can register themselves at the CFDP Distributor. - * @param service A pointer to the registering Service. - * @return - @c RETURN_OK on success, - * - @c RETURN_FAILED on failure. - */ - virtual ReturnValue_t registerService( AcceptsTelecommandsIF* service ) = 0; + /** + * With this method, Handlers can register themselves at the CFDP Distributor. + * @param handler A pointer to the registering Handler. + * @return - @c RETURN_OK on success, + * - @c RETURN_FAILED on failure. + */ + virtual ReturnValue_t registerHandler(AcceptsTelecommandsIF* handler) = 0; }; #endif /* FSFW_TCDISTRIBUTION_CFDPDISTRIBUTORIF_H_ */ diff --git a/inc/fsfw/tmtcpacket/cfdp/CFDPPacket.h b/inc/fsfw/tmtcpacket/cfdp/CFDPPacket.h new file mode 100644 index 00000000..f288a8ae --- /dev/null +++ b/inc/fsfw/tmtcpacket/cfdp/CFDPPacket.h @@ -0,0 +1,27 @@ +#ifndef FSFW_INC_FSFW_TMTCPACKET_CFDP_CFDPPACKET_H_ +#define FSFW_INC_FSFW_TMTCPACKET_CFDP_CFDPPACKET_H_ + +#include "fsfw/tmtcpacket/SpacePacketBase.h" + +class CFDPPacket : public SpacePacketBase { +public: + /** + * This is the default constructor. + * It sets its internal data pointer to the address passed and also + * forwards the data pointer to the parent SpacePacketBase class. + * @param setData The position where the packet data lies. + */ + CFDPPacket( const uint8_t* setData ); + /** + * This is the empty default destructor. + */ + virtual ~CFDPPacket(); + + /** + * This is a debugging helper method that prints the whole packet content + * to the screen. + */ + void print(); +}; + +#endif /* FSFW_INC_FSFW_TMTCPACKET_CFDP_CFDPPACKET_H_ */ diff --git a/inc/fsfw/tmtcpacket/cfdp/CFDPPacketStored.h b/inc/fsfw/tmtcpacket/cfdp/CFDPPacketStored.h new file mode 100644 index 00000000..8bc0f281 --- /dev/null +++ b/inc/fsfw/tmtcpacket/cfdp/CFDPPacketStored.h @@ -0,0 +1,64 @@ +#ifndef FSFW_INC_FSFW_TMTCPACKET_CFDP_CFDPPACKETSTORED_H_ +#define FSFW_INC_FSFW_TMTCPACKET_CFDP_CFDPPACKETSTORED_H_ + +#include "../pus/tc/TcPacketStoredBase.h" +#include "CFDPPacket.h" + +class CFDPPacketStored: + public CFDPPacket { +public: + /** + * Create stored packet with existing data. + * @param data + * @param size + */ + CFDPPacketStored(const uint8_t* data, size_t size); + /** + * Create stored packet from existing packet in store + * @param setAddress + */ + CFDPPacketStored(store_address_t setAddress); + CFDPPacketStored(); + + /** + * Getter function for the raw data. + * @param dataPtr [out] Pointer to the data pointer to set + * @param dataSize [out] Address of size to set. + * @return -@c RETURN_OK if data was retrieved successfully. + */ + ReturnValue_t getData(const uint8_t ** dataPtr, size_t* dataSize); + + void setStoreAddress(store_address_t setAddress); + + store_address_t getStoreAddress(); + + ReturnValue_t deletePacket(); + +private: + + bool isSizeCorrect(); +protected: + /** + * This is a pointer to the store all instances of the class use. + * If the store is not yet set (i.e. @c store is NULL), every constructor + * call tries to set it and throws an error message in case of failures. + * The default store is objects::TC_STORE. + */ + static StorageManagerIF* store; + /** + * The address where the packet data of the object instance is stored. + */ + store_address_t storeAddress; + /** + * A helper method to check if a store is assigned to the class. + * If not, the method tries to retrieve the store from the global + * ObjectManager. + * @return @li @c true if the store is linked or could be created. + * @li @c false otherwise. + */ + bool checkAndSetStore(); +}; + + + +#endif /* FSFW_INC_FSFW_TMTCPACKET_CFDP_CFDPPACKETSTORED_H_ */ diff --git a/src/core/CMakeLists.txt b/src/core/CMakeLists.txt index 4a2f7a2c..f769d95c 100644 --- a/src/core/CMakeLists.txt +++ b/src/core/CMakeLists.txt @@ -1,4 +1,5 @@ add_subdirectory(action) +add_subdirectory(cfdp) add_subdirectory(container) add_subdirectory(controller) add_subdirectory(datapool) diff --git a/src/core/cfdp/CFDPHandler.cpp b/src/core/cfdp/CFDPHandler.cpp new file mode 100644 index 00000000..d1c40546 --- /dev/null +++ b/src/core/cfdp/CFDPHandler.cpp @@ -0,0 +1,59 @@ +#include "fsfw/cfdp/CFDPHandler.h" + +#include "fsfw/tmtcservices/AcceptsTelemetryIF.h" +#include "fsfw/ipc/QueueFactory.h" +#include "fsfw/objectmanager/ObjectManager.h" + +object_id_t CFDPHandler::packetSource = 0; +object_id_t CFDPHandler::packetDestination = 0; + +CFDPHandler::CFDPHandler(object_id_t setObjectId, CFDPDistributor* dist) : SystemObject(setObjectId) { + requestQueue = QueueFactory::instance()->createMessageQueue(CFDP_HANDLER_MAX_RECEPTION); + distributor = dist; +} + +CFDPHandler::~CFDPHandler() {} + +ReturnValue_t CFDPHandler::initialize() { + ReturnValue_t result = SystemObject::initialize(); + if (result != RETURN_OK) { + return result; + } + this->distributor->registerHandler(this); + return HasReturnvaluesIF::RETURN_OK; +} + +ReturnValue_t CFDPHandler::handleRequest(uint8_t subservice) { +#if FSFW_VERBOSE_LEVEL >= 1 +#if FSFW_CPP_OSTREAM_ENABLED == 1 + sif::debug << "CFDPHandler::handleRequest" << std::endl; +#else + sif::printDebug("CFDPHandler::handleRequest"); +#endif /* !FSFW_CPP_OSTREAM_ENABLED == 1 */ +#endif + return RETURN_OK; +} + +ReturnValue_t CFDPHandler::performOperation(uint8_t opCode) { + ReturnValue_t result = this->performService(); + return result; +} + +ReturnValue_t CFDPHandler::performService() { +#if FSFW_VERBOSE_LEVEL >= 1 +#if FSFW_CPP_OSTREAM_ENABLED == 1 + sif::debug << "CFDPHandler::performService" << std::endl; +#else + sif::printDebug("CFDPHandler::performService"); +#endif /* !FSFW_CPP_OSTREAM_ENABLED == 1 */ +#endif + return RETURN_OK; +} + +uint16_t CFDPHandler::getIdentifier() { + return 0; +} + +MessageQueueId_t CFDPHandler::getRequestQueue() { + return this->requestQueue->getId(); +} diff --git a/src/core/cfdp/CMakeLists.txt b/src/core/cfdp/CMakeLists.txt new file mode 100644 index 00000000..9410743f --- /dev/null +++ b/src/core/cfdp/CMakeLists.txt @@ -0,0 +1,4 @@ +target_sources(${LIB_FSFW_NAME} + PRIVATE + CFDPHandler.cpp +) diff --git a/src/core/tcdistribution/CFDPDistributor.cpp b/src/core/tcdistribution/CFDPDistributor.cpp index 9266a7fa..37294988 100644 --- a/src/core/tcdistribution/CFDPDistributor.cpp +++ b/src/core/tcdistribution/CFDPDistributor.cpp @@ -1,15 +1,18 @@ #include "fsfw/tcdistribution/CCSDSDistributorIF.h" #include "fsfw/tcdistribution/CFDPDistributor.h" +#include "fsfw/tmtcpacket/cfdp/CFDPPacketStored.h" + #include "fsfw/objectmanager/ObjectManager.h" -#include "fsfw/serviceinterface/ServiceInterface.h" #define CFDP_DISTRIBUTOR_DEBUGGING 0 CFDPDistributor::CFDPDistributor(uint16_t setApid, object_id_t setObjectId, object_id_t setPacketSource) : - TcDistributor(setObjectId), checker(setApid), verifyChannel(), - tcStatus(RETURN_FAILED), packetSource(setPacketSource) {} + TcDistributor(setObjectId), + tcStatus(RETURN_FAILED), packetSource(setPacketSource) { + this->apid = setApid; +} CFDPDistributor::~CFDPDistributor() {} @@ -30,20 +33,7 @@ CFDPDistributor::TcMqMapIter CFDPDistributor::selectDestination() { } this->currentPacket->setStoreAddress(this->currentMessage.getStorageId()); if (currentPacket->getWholeData() != nullptr) { - tcStatus = checker.checkPacket(currentPacket); - if(tcStatus != HasReturnvaluesIF::RETURN_OK) { -#if FSFW_VERBOSE_LEVEL >= 1 -#if FSFW_CPP_OSTREAM_ENABLED == 1 - sif::debug << "CFDPDistributor::handlePacket: Packet format invalid, code " << - static_cast(tcStatus) << std::endl; -#else - sif::printDebug("CFDPDistributor::handlePacket: Packet format invalid, code %d\n", - static_cast(tcStatus)); -#endif -#endif - } - uint32_t queue_id = currentPacket->getService(); - queueMapIt = this->queueMap.find(queue_id); + queueMapIt = this->queueMap.find(0); } else { tcStatus = PACKET_LOST; @@ -70,24 +60,24 @@ CFDPDistributor::TcMqMapIter CFDPDistributor::selectDestination() { } -ReturnValue_t CFDPDistributor::registerService(AcceptsTelecommandsIF* service) { - uint16_t serviceId = service->getIdentifier(); +ReturnValue_t CFDPDistributor::registerHandler(AcceptsTelecommandsIF* handler) { + uint16_t handlerId = handler->getIdentifier(); //should be 0, because CFDPHandler does not set a set a service-ID #if CFDP_DISTRIBUTOR_DEBUGGING == 1 #if FSFW_CPP_OSTREAM_ENABLED == 1 - sif::info << "Service ID: " << static_cast(serviceId) << std::endl; + sif::info << "CFDPDistributor::registerHandler: Handler ID: " << static_cast(handlerId) << std::endl; #else - sif::printInfo("Service ID: %d\n", static_cast(serviceId)); + sif::printInfo("CFDPDistributor::registerHandler: Handler ID: %d\n", static_cast(handlerId)); #endif #endif - MessageQueueId_t queue = service->getRequestQueue(); - auto returnPair = queueMap.emplace(serviceId, queue); + MessageQueueId_t queue = handler->getRequestQueue(); + auto returnPair = queueMap.emplace(handlerId, queue); if (not returnPair.second) { #if FSFW_VERBOSE_LEVEL >= 1 #if FSFW_CPP_OSTREAM_ENABLED == 1 - sif::error << "CFDPDistributor::registerService: Service ID already" + sif::error << "CFDPDistributor::registerHandler: Service ID already" " exists in map" << std::endl; #else - sif::printError("CFDPDistributor::registerService: Service ID already exists in map\n"); + sif::printError("CFDPDistributor::registerHandler: Service ID already exists in map\n"); #endif #endif return SERVICE_ID_ALREADY_EXISTS; @@ -99,30 +89,30 @@ MessageQueueId_t CFDPDistributor::getRequestQueue() { return tcQueue->getId(); } -ReturnValue_t CFDPDistributor::callbackAfterSending(ReturnValue_t queueStatus) { - if (queueStatus != RETURN_OK) { - tcStatus = queueStatus; - } - if (tcStatus != RETURN_OK) { - this->verifyChannel.sendFailureReport(tc_verification::ACCEPTANCE_FAILURE, - currentPacket, tcStatus); - // A failed packet is deleted immediately after reporting, - // otherwise it will block memory. - currentPacket->deletePacket(); - return RETURN_FAILED; - } else { - this->verifyChannel.sendSuccessReport(tc_verification::ACCEPTANCE_SUCCESS, - currentPacket); - return RETURN_OK; - } -} +//ReturnValue_t CFDPDistributor::callbackAfterSending(ReturnValue_t queueStatus) { +// if (queueStatus != RETURN_OK) { +// tcStatus = queueStatus; +// } +// if (tcStatus != RETURN_OK) { +// this->verifyChannel.sendFailureReport(tc_verification::ACCEPTANCE_FAILURE, +// currentPacket, tcStatus); +// // A failed packet is deleted immediately after reporting, +// // otherwise it will block memory. +// currentPacket->deletePacket(); +// return RETURN_FAILED; +// } else { +// this->verifyChannel.sendSuccessReport(tc_verification::ACCEPTANCE_SUCCESS, +// currentPacket); +// return RETURN_OK; +// } +//} uint16_t CFDPDistributor::getIdentifier() { - return checker.getApid(); + return this->apid; } ReturnValue_t CFDPDistributor::initialize() { - currentPacket = new TcPacketStoredPus(); + currentPacket = new CFDPPacketStored(); if(currentPacket == nullptr) { // Should not happen, memory allocation failed! return ObjectManagerIF::CHILD_INIT_FAILED; diff --git a/src/core/tmtcpacket/CMakeLists.txt b/src/core/tmtcpacket/CMakeLists.txt index fdc884ec..e1deaba9 100644 --- a/src/core/tmtcpacket/CMakeLists.txt +++ b/src/core/tmtcpacket/CMakeLists.txt @@ -3,5 +3,6 @@ target_sources(${LIB_FSFW_NAME} PRIVATE SpacePacketBase.cpp ) +add_subdirectory(cfdp) add_subdirectory(packetmatcher) add_subdirectory(pus) \ No newline at end of file diff --git a/src/core/tmtcpacket/cfdp/CFDPPacket.cpp b/src/core/tmtcpacket/cfdp/CFDPPacket.cpp new file mode 100644 index 00000000..6172201e --- /dev/null +++ b/src/core/tmtcpacket/cfdp/CFDPPacket.cpp @@ -0,0 +1,20 @@ +#include "fsfw/tmtcpacket/cfdp/CFDPPacket.h" + +#include "fsfw/globalfunctions/CRC.h" +#include "fsfw/globalfunctions/arrayprinter.h" +#include "fsfw/serviceinterface/ServiceInterface.h" + +#include + +CFDPPacket::CFDPPacket(const uint8_t* setData): SpacePacketBase(setData) {} + +CFDPPacket::~CFDPPacket() {} + +void CFDPPacket::print() { +#if FSFW_CPP_OSTREAM_ENABLED == 1 + sif::info << "CFDPPacket::print:" << std::endl; +#else + sif::printInfo("CFDPPacket::print:\n"); +#endif + arrayprinter::print(getWholeData(), getFullSize()); +} diff --git a/src/core/tmtcpacket/cfdp/CFDPPacketStored.cpp b/src/core/tmtcpacket/cfdp/CFDPPacketStored.cpp new file mode 100644 index 00000000..f0160e3b --- /dev/null +++ b/src/core/tmtcpacket/cfdp/CFDPPacketStored.cpp @@ -0,0 +1,85 @@ +#include "fsfw/tmtcpacket/cfdp/CFDPPacketStored.h" +#include "fsfw/objectmanager/ObjectManager.h" + +StorageManagerIF* CFDPPacketStored::store = nullptr; + +CFDPPacketStored::CFDPPacketStored(): CFDPPacket(nullptr) { +} + +CFDPPacketStored::CFDPPacketStored(store_address_t setAddress): CFDPPacket(nullptr) { + this->setStoreAddress(setAddress); +} + +CFDPPacketStored::CFDPPacketStored(const uint8_t* data, size_t size): CFDPPacket(data) { + if (this->getFullSize() != size) { + return; + } + if (this->checkAndSetStore()) { + ReturnValue_t status = store->addData(&storeAddress, data, size); + if (status != HasReturnvaluesIF::RETURN_OK) { + this->setData(nullptr); + } + const uint8_t* storePtr = nullptr; + // Repoint base data pointer to the data in the store. + store->getData(storeAddress, &storePtr, &size); + this->setData(storePtr); + } +} + +ReturnValue_t CFDPPacketStored::deletePacket() { + ReturnValue_t result = this->store->deleteData(this->storeAddress); + this->storeAddress.raw = StorageManagerIF::INVALID_ADDRESS; + this->setData(nullptr); + return result; +} + +//CFDPPacket* CFDPPacketStored::getPacketBase() { +// return this; +//} +void CFDPPacketStored::setStoreAddress(store_address_t setAddress) { + this->storeAddress = setAddress; + const uint8_t* tempData = nullptr; + size_t tempSize; + ReturnValue_t status = StorageManagerIF::RETURN_FAILED; + if (this->checkAndSetStore()) { + status = this->store->getData(this->storeAddress, &tempData, &tempSize); + } + if (status == StorageManagerIF::RETURN_OK) { + this->setData(tempData); + } + else { + this->setData(nullptr); + this->storeAddress.raw = StorageManagerIF::INVALID_ADDRESS; + } +} + +store_address_t CFDPPacketStored::getStoreAddress() { + return this->storeAddress; +} + +bool CFDPPacketStored::checkAndSetStore() { + if (this->store == nullptr) { + this->store = ObjectManager::instance()->get(objects::TC_STORE); + if (this->store == nullptr) { +#if FSFW_CPP_OSTREAM_ENABLED == 1 + sif::error << "CFDPPacketStored::CFDPPacketStored: TC Store not found!" + << std::endl; +#endif + return false; + } + } + return true; +} + +bool CFDPPacketStored::isSizeCorrect() { + const uint8_t* temp_data = nullptr; + size_t temp_size; + ReturnValue_t status = this->store->getData(this->storeAddress, &temp_data, + &temp_size); + if (status == StorageManagerIF::RETURN_OK) { + if (this->getFullSize() == temp_size) { + return true; + } + } + return false; +} diff --git a/src/core/tmtcpacket/cfdp/CMakeLists.txt b/src/core/tmtcpacket/cfdp/CMakeLists.txt new file mode 100644 index 00000000..0b7ab18a --- /dev/null +++ b/src/core/tmtcpacket/cfdp/CMakeLists.txt @@ -0,0 +1,4 @@ +target_sources(${LIB_FSFW_NAME} PRIVATE + CFDPPacket.cpp + CFDPPacketStored.cpp +)