From 6c5bbfa080ad9bf70d714d686095d08478340502 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Fri, 29 Jul 2022 12:03:14 +0200 Subject: [PATCH 001/169] some renaming --- src/fsfw/cfdp/CfdpHandler.cpp | 2 +- src/fsfw/cfdp/CfdpHandler.h | 6 ++--- src/fsfw/tcdistribution/CMakeLists.txt | 4 ++-- ...DSDistributor.cpp => CcsdsDistributor.cpp} | 20 ++++++++--------- ...{CCSDSDistributor.h => CcsdsDistributor.h} | 12 +++++----- ...DSDistributorIF.h => CcsdsDistributorIF.h} | 4 ++-- ...FDPDistributor.cpp => CfdpDistributor.cpp} | 22 +++++++++---------- .../{CFDPDistributor.h => CfdpDistributor.h} | 12 +++++----- ...FDPDistributorIF.h => CfdpDistributorIF.h} | 4 ++-- src/fsfw/tcdistribution/PusDistributor.cpp | 6 ++--- src/fsfw/tcdistribution/PusDistributor.h | 12 +++++----- ...{PUSDistributorIF.h => PusDistributorIF.h} | 4 ++-- src/fsfw/tcdistribution/TcDistributor.h | 14 ++++++------ .../tmtcservices/CommandingServiceBase.cpp | 4 ++-- src/fsfw/tmtcservices/PusServiceBase.cpp | 6 ++--- src/fsfw/tmtcservices/PusServiceBase.h | 6 ++--- unittests/mocks/PusDistributorMock.h | 4 ++-- 17 files changed, 71 insertions(+), 71 deletions(-) rename src/fsfw/tcdistribution/{CCSDSDistributor.cpp => CcsdsDistributor.cpp} (85%) rename src/fsfw/tcdistribution/{CCSDSDistributor.h => CcsdsDistributor.h} (88%) rename src/fsfw/tcdistribution/{CCSDSDistributorIF.h => CcsdsDistributorIF.h} (95%) rename src/fsfw/tcdistribution/{CFDPDistributor.cpp => CfdpDistributor.cpp} (87%) rename src/fsfw/tcdistribution/{CFDPDistributor.h => CfdpDistributor.h} (88%) rename src/fsfw/tcdistribution/{CFDPDistributorIF.h => CfdpDistributorIF.h} (91%) rename src/fsfw/tcdistribution/{PUSDistributorIF.h => PusDistributorIF.h} (91%) diff --git a/src/fsfw/cfdp/CfdpHandler.cpp b/src/fsfw/cfdp/CfdpHandler.cpp index caa64f56..cb13bca6 100644 --- a/src/fsfw/cfdp/CfdpHandler.cpp +++ b/src/fsfw/cfdp/CfdpHandler.cpp @@ -10,7 +10,7 @@ object_id_t CfdpHandler::packetSource = 0; object_id_t CfdpHandler::packetDestination = 0; -CfdpHandler::CfdpHandler(object_id_t setObjectId, CFDPDistributor* dist) +CfdpHandler::CfdpHandler(object_id_t setObjectId, CfdpDistributor* dist) : SystemObject(setObjectId) { requestQueue = QueueFactory::instance()->createMessageQueue(CFDP_HANDLER_MAX_RECEPTION); distributor = dist; diff --git a/src/fsfw/cfdp/CfdpHandler.h b/src/fsfw/cfdp/CfdpHandler.h index 01399e98..03424d64 100644 --- a/src/fsfw/cfdp/CfdpHandler.h +++ b/src/fsfw/cfdp/CfdpHandler.h @@ -5,7 +5,7 @@ #include "fsfw/objectmanager/SystemObject.h" #include "fsfw/returnvalues/HasReturnvaluesIF.h" #include "fsfw/tasks/ExecutableObjectIF.h" -#include "fsfw/tcdistribution/CFDPDistributor.h" +#include "fsfw/tcdistribution/CfdpDistributor.h" #include "fsfw/tmtcservices/AcceptsTelecommandsIF.h" namespace Factory { @@ -19,7 +19,7 @@ class CfdpHandler : public ExecutableObjectIF, friend void(Factory::setStaticFrameworkObjectIds)(); public: - CfdpHandler(object_id_t setObjectId, CFDPDistributor* distributor); + CfdpHandler(object_id_t setObjectId, CfdpDistributor* distributor); /** * The destructor is empty. */ @@ -39,7 +39,7 @@ class CfdpHandler : public ExecutableObjectIF, */ MessageQueueIF* requestQueue = nullptr; - CFDPDistributor* distributor = nullptr; + CfdpDistributor* distributor = nullptr; /** * The current CFDP packet to be processed. diff --git a/src/fsfw/tcdistribution/CMakeLists.txt b/src/fsfw/tcdistribution/CMakeLists.txt index 532ba2ca..f1762ff4 100644 --- a/src/fsfw/tcdistribution/CMakeLists.txt +++ b/src/fsfw/tcdistribution/CMakeLists.txt @@ -1,9 +1,9 @@ target_sources( ${LIB_FSFW_NAME} - PRIVATE CCSDSDistributor.cpp + PRIVATE CcsdsDistributor.cpp PusDistributor.cpp TcDistributor.cpp PusPacketChecker.cpp TcPacketCheckCFDP.cpp - CFDPDistributor.cpp + CfdpDistributor.cpp CcsdsPacketChecker.cpp) diff --git a/src/fsfw/tcdistribution/CCSDSDistributor.cpp b/src/fsfw/tcdistribution/CcsdsDistributor.cpp similarity index 85% rename from src/fsfw/tcdistribution/CCSDSDistributor.cpp rename to src/fsfw/tcdistribution/CcsdsDistributor.cpp index 7c2974a4..d263d68a 100644 --- a/src/fsfw/tcdistribution/CCSDSDistributor.cpp +++ b/src/fsfw/tcdistribution/CcsdsDistributor.cpp @@ -1,4 +1,4 @@ -#include "fsfw/tcdistribution/CCSDSDistributor.h" +#include "fsfw/tcdistribution/CcsdsDistributor.h" #include "fsfw/objectmanager/ObjectManager.h" #include "fsfw/serviceinterface/ServiceInterface.h" @@ -6,13 +6,13 @@ #define CCSDS_DISTRIBUTOR_DEBUGGING 0 -CCSDSDistributor::CCSDSDistributor(uint16_t setDefaultApid, object_id_t setObjectId, +CcsdsDistributor::CcsdsDistributor(uint16_t setDefaultApid, object_id_t setObjectId, CcsdsPacketCheckIF* packetChecker) : TcDistributor(setObjectId), defaultApid(setDefaultApid), packetChecker(packetChecker) {} -CCSDSDistributor::~CCSDSDistributor() = default; +CcsdsDistributor::~CcsdsDistributor() = default; -TcDistributor::TcMqMapIter CCSDSDistributor::selectDestination() { +TcDistributor::TcMqMapIter CcsdsDistributor::selectDestination() { #if CCSDS_DISTRIBUTOR_DEBUGGING == 1 #if FSFW_CPP_OSTREAM_ENABLED == 1 sif::debug << "CCSDSDistributor::selectDestination received: " @@ -59,9 +59,9 @@ TcDistributor::TcMqMapIter CCSDSDistributor::selectDestination() { } } -MessageQueueId_t CCSDSDistributor::getRequestQueue() { return tcQueue->getId(); } +MessageQueueId_t CcsdsDistributor::getRequestQueue() { return tcQueue->getId(); } -ReturnValue_t CCSDSDistributor::registerApplication(AcceptsTelecommandsIF* application) { +ReturnValue_t CcsdsDistributor::registerApplication(AcceptsTelecommandsIF* application) { ReturnValue_t returnValue = RETURN_OK; auto insertPair = this->queueMap.emplace(application->getIdentifier(), application->getRequestQueue()); @@ -71,7 +71,7 @@ ReturnValue_t CCSDSDistributor::registerApplication(AcceptsTelecommandsIF* appli return returnValue; } -ReturnValue_t CCSDSDistributor::registerApplication(uint16_t apid, MessageQueueId_t id) { +ReturnValue_t CcsdsDistributor::registerApplication(uint16_t apid, MessageQueueId_t id) { ReturnValue_t returnValue = RETURN_OK; auto insertPair = this->queueMap.emplace(apid, id); if (not insertPair.second) { @@ -80,9 +80,9 @@ ReturnValue_t CCSDSDistributor::registerApplication(uint16_t apid, MessageQueueI return returnValue; } -uint16_t CCSDSDistributor::getIdentifier() { return 0; } +uint16_t CcsdsDistributor::getIdentifier() { return 0; } -ReturnValue_t CCSDSDistributor::initialize() { +ReturnValue_t CcsdsDistributor::initialize() { if (packetChecker == nullptr) { packetChecker = new CcsdsPacketChecker(ccsds::PacketType::TC); } @@ -105,7 +105,7 @@ ReturnValue_t CCSDSDistributor::initialize() { return status; } -ReturnValue_t CCSDSDistributor::callbackAfterSending(ReturnValue_t queueStatus) { +ReturnValue_t CcsdsDistributor::callbackAfterSending(ReturnValue_t queueStatus) { if (queueStatus != RETURN_OK) { tcStore->deleteData(currentMessage.getStorageId()); } diff --git a/src/fsfw/tcdistribution/CCSDSDistributor.h b/src/fsfw/tcdistribution/CcsdsDistributor.h similarity index 88% rename from src/fsfw/tcdistribution/CCSDSDistributor.h rename to src/fsfw/tcdistribution/CcsdsDistributor.h index d6e4f0e7..ea7ad7e2 100644 --- a/src/fsfw/tcdistribution/CCSDSDistributor.h +++ b/src/fsfw/tcdistribution/CcsdsDistributor.h @@ -3,21 +3,21 @@ #include "fsfw/objectmanager/ObjectManagerIF.h" #include "fsfw/storagemanager/StorageManagerIF.h" -#include "fsfw/tcdistribution/CCSDSDistributorIF.h" +#include "fsfw/tcdistribution/CcsdsDistributorIF.h" #include "fsfw/tcdistribution/CcsdsPacketChecker.h" #include "fsfw/tcdistribution/TcDistributor.h" #include "fsfw/tmtcservices/AcceptsTelecommandsIF.h" /** - * @brief An instantiation of the CCSDSDistributorIF. + * @brief An instantiation of the CcsdsDistributorIF. * @details * It receives Space Packets, and selects a destination depending on the * APID of the telecommands. * The Secondary Header (with Service/Subservice) is ignored. * @ingroup tc_distribution */ -class CCSDSDistributor : public TcDistributor, - public CCSDSDistributorIF, +class CcsdsDistributor : public TcDistributor, + public CcsdsDistributorIF, public AcceptsTelecommandsIF { public: /** @@ -28,12 +28,12 @@ class CCSDSDistributor : public TcDistributor, * @param unknownApid The default APID, where packets with unknown * destination are sent to. */ - CCSDSDistributor(uint16_t unknownApid, object_id_t setObjectId, + CcsdsDistributor(uint16_t unknownApid, object_id_t setObjectId, CcsdsPacketCheckIF* packetChecker = nullptr); /** * The destructor is empty. */ - ~CCSDSDistributor() override; + ~CcsdsDistributor() override; MessageQueueId_t getRequestQueue() override; ReturnValue_t registerApplication(uint16_t apid, MessageQueueId_t id) override; diff --git a/src/fsfw/tcdistribution/CCSDSDistributorIF.h b/src/fsfw/tcdistribution/CcsdsDistributorIF.h similarity index 95% rename from src/fsfw/tcdistribution/CCSDSDistributorIF.h rename to src/fsfw/tcdistribution/CcsdsDistributorIF.h index da4a943f..d5a26bef 100644 --- a/src/fsfw/tcdistribution/CCSDSDistributorIF.h +++ b/src/fsfw/tcdistribution/CcsdsDistributorIF.h @@ -11,7 +11,7 @@ * to route the TC's to. * @ingroup tc_distribution */ -class CCSDSDistributorIF { +class CcsdsDistributorIF { public: /** * With this call, a class implementing the CCSDSApplicationIF can register @@ -34,7 +34,7 @@ class CCSDSDistributorIF { /** * The empty virtual destructor. */ - virtual ~CCSDSDistributorIF() = default; + virtual ~CcsdsDistributorIF() = default; }; #endif /* FSFW_TCDISTRIBUTION_CCSDSDISTRIBUTORIF_H_ */ diff --git a/src/fsfw/tcdistribution/CFDPDistributor.cpp b/src/fsfw/tcdistribution/CfdpDistributor.cpp similarity index 87% rename from src/fsfw/tcdistribution/CFDPDistributor.cpp rename to src/fsfw/tcdistribution/CfdpDistributor.cpp index d7a02793..1f380530 100644 --- a/src/fsfw/tcdistribution/CFDPDistributor.cpp +++ b/src/fsfw/tcdistribution/CfdpDistributor.cpp @@ -1,14 +1,14 @@ -#include "fsfw/tcdistribution/CFDPDistributor.h" +#include "fsfw/tcdistribution/CfdpDistributor.h" #include "fsfw/objectmanager/ObjectManager.h" -#include "fsfw/tcdistribution/CCSDSDistributorIF.h" +#include "fsfw/tcdistribution/CcsdsDistributorIF.h" #include "fsfw/tmtcpacket/cfdp/CfdpPacketStored.h" #ifndef FSFW_CFDP_DISTRIBUTOR_DEBUGGING #define FSFW_CFDP_DISTRIBUTOR_DEBUGGING 1 #endif -CFDPDistributor::CFDPDistributor(uint16_t setApid, object_id_t setObjectId, +CfdpDistributor::CfdpDistributor(uint16_t setApid, object_id_t setObjectId, object_id_t setPacketSource) : TcDistributor(setObjectId), apid(setApid), @@ -16,9 +16,9 @@ CFDPDistributor::CFDPDistributor(uint16_t setApid, object_id_t setObjectId, tcStatus(RETURN_FAILED), packetSource(setPacketSource) {} -CFDPDistributor::~CFDPDistributor() = default; +CfdpDistributor::~CfdpDistributor() = default; -CFDPDistributor::TcMqMapIter CFDPDistributor::selectDestination() { +CfdpDistributor::TcMqMapIter CfdpDistributor::selectDestination() { #if FSFW_CFDP_DISTRIBUTOR_DEBUGGING == 1 store_address_t storeId = this->currentMessage.getStorageId(); #if FSFW_CPP_OSTREAM_ENABLED == 1 @@ -70,7 +70,7 @@ CFDPDistributor::TcMqMapIter CFDPDistributor::selectDestination() { } } -ReturnValue_t CFDPDistributor::registerHandler(AcceptsTelecommandsIF* handler) { +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 FSFW_CFDP_DISTRIBUTOR_DEBUGGING == 1 @@ -98,7 +98,7 @@ ReturnValue_t CFDPDistributor::registerHandler(AcceptsTelecommandsIF* handler) { return HasReturnvaluesIF::RETURN_OK; } -MessageQueueId_t CFDPDistributor::getRequestQueue() { return tcQueue->getId(); } +MessageQueueId_t CfdpDistributor::getRequestQueue() { return tcQueue->getId(); } // ReturnValue_t CFDPDistributor::callbackAfterSending(ReturnValue_t queueStatus) { // if (queueStatus != RETURN_OK) { @@ -118,23 +118,23 @@ MessageQueueId_t CFDPDistributor::getRequestQueue() { return tcQueue->getId(); } // } // } -uint16_t CFDPDistributor::getIdentifier() { return this->apid; } +uint16_t CfdpDistributor::getIdentifier() { return this->apid; } -ReturnValue_t CFDPDistributor::initialize() { +ReturnValue_t CfdpDistributor::initialize() { currentPacket = new CfdpPacketStored(); if (currentPacket == nullptr) { // Should not happen, memory allocation failed! return ObjectManagerIF::CHILD_INIT_FAILED; } - auto* ccsdsDistributor = ObjectManager::instance()->get(packetSource); + auto* ccsdsDistributor = ObjectManager::instance()->get(packetSource); if (ccsdsDistributor == nullptr) { #if FSFW_CPP_OSTREAM_ENABLED == 1 sif::error << "CFDPDistributor::initialize: Packet source invalid" << std::endl; sif::error << " Make sure it exists and implements CCSDSDistributorIF!" << std::endl; #else sif::printError("CFDPDistributor::initialize: Packet source invalid\n"); - sif::printError("Make sure it exists and implements CCSDSDistributorIF\n"); + sif::printError("Make sure it exists and implements CcsdsDistributorIF\n"); #endif return RETURN_FAILED; } diff --git a/src/fsfw/tcdistribution/CFDPDistributor.h b/src/fsfw/tcdistribution/CfdpDistributor.h similarity index 88% rename from src/fsfw/tcdistribution/CFDPDistributor.h rename to src/fsfw/tcdistribution/CfdpDistributor.h index e7776f1b..181d3613 100644 --- a/src/fsfw/tcdistribution/CFDPDistributor.h +++ b/src/fsfw/tcdistribution/CfdpDistributor.h @@ -7,7 +7,7 @@ #include "../tmtcpacket/cfdp/CfdpPacketStored.h" #include "../tmtcservices/AcceptsTelecommandsIF.h" #include "../tmtcservices/VerificationReporter.h" -#include "CFDPDistributorIF.h" +#include "CfdpDistributorIF.h" #include "TcDistributor.h" /** @@ -15,8 +15,8 @@ * services. * @ingroup tc_distribution */ -class CFDPDistributor : public TcDistributor, - public CFDPDistributorIF, +class CfdpDistributor : public TcDistributor, + public CfdpDistributorIF, public AcceptsTelecommandsIF { public: /** @@ -25,13 +25,13 @@ class CFDPDistributor : public TcDistributor, * @param setApid The APID of this receiving Application. * @param setObjectId Object ID of the distributor itself * @param setPacketSource Object ID of the source of TC packets. - * Must implement CCSDSDistributorIF. + * Must implement CcsdsDistributorIF. */ - CFDPDistributor(uint16_t setApid, object_id_t setObjectId, object_id_t setPacketSource); + CfdpDistributor(uint16_t setApid, object_id_t setObjectId, object_id_t setPacketSource); /** * The destructor is empty. */ - ~CFDPDistributor() override; + ~CfdpDistributor() override; ReturnValue_t registerHandler(AcceptsTelecommandsIF* handler) override; MessageQueueId_t getRequestQueue() override; ReturnValue_t initialize() override; diff --git a/src/fsfw/tcdistribution/CFDPDistributorIF.h b/src/fsfw/tcdistribution/CfdpDistributorIF.h similarity index 91% rename from src/fsfw/tcdistribution/CFDPDistributorIF.h rename to src/fsfw/tcdistribution/CfdpDistributorIF.h index 3f048bbf..660a9709 100644 --- a/src/fsfw/tcdistribution/CFDPDistributorIF.h +++ b/src/fsfw/tcdistribution/CfdpDistributorIF.h @@ -8,12 +8,12 @@ * This interface allows CFDP Services to register themselves at a CFDP Distributor. * @ingroup tc_distribution */ -class CFDPDistributorIF { +class CfdpDistributorIF { public: /** * The empty virtual destructor. */ - virtual ~CFDPDistributorIF() = default; + virtual ~CfdpDistributorIF() = default; /** * With this method, Handlers can register themselves at the CFDP Distributor. * @param handler A pointer to the registering Handler. diff --git a/src/fsfw/tcdistribution/PusDistributor.cpp b/src/fsfw/tcdistribution/PusDistributor.cpp index ade49201..8a9ebb89 100644 --- a/src/fsfw/tcdistribution/PusDistributor.cpp +++ b/src/fsfw/tcdistribution/PusDistributor.cpp @@ -3,13 +3,13 @@ #include "definitions.h" #include "fsfw/objectmanager/ObjectManager.h" #include "fsfw/serviceinterface/ServiceInterface.h" -#include "fsfw/tcdistribution/CCSDSDistributorIF.h" +#include "fsfw/tcdistribution/CcsdsDistributorIF.h" #include "fsfw/tmtcservices/PusVerificationReport.h" #define PUS_DISTRIBUTOR_DEBUGGING 0 PusDistributor::PusDistributor(uint16_t setApid, object_id_t setObjectId, - CCSDSDistributorIF* distributor, StorageManagerIF* store_) + CcsdsDistributorIF* distributor, StorageManagerIF* store_) : TcDistributor(setObjectId), store(store_), checker(setApid, ccsds::PacketType::TC), @@ -132,7 +132,7 @@ ReturnValue_t PusDistributor::initialize() { sif::error << " Make sure it exists and implements CCSDSDistributorIF!" << std::endl; #else sif::printError("PusDistributor::initialize: Packet source invalid\n"); - sif::printError("Make sure it exists and implements CCSDSDistributorIF\n"); + sif::printError("Make sure it exists and implements CcsdsDistributorIF\n"); #endif return ObjectManagerIF::CHILD_INIT_FAILED; } diff --git a/src/fsfw/tcdistribution/PusDistributor.h b/src/fsfw/tcdistribution/PusDistributor.h index 7daf5d83..6acefd02 100644 --- a/src/fsfw/tcdistribution/PusDistributor.h +++ b/src/fsfw/tcdistribution/PusDistributor.h @@ -1,7 +1,7 @@ #ifndef FSFW_TCDISTRIBUTION_PUSDISTRIBUTOR_H_ #define FSFW_TCDISTRIBUTION_PUSDISTRIBUTOR_H_ -#include "PUSDistributorIF.h" +#include "PusDistributorIF.h" #include "PusPacketChecker.h" #include "TcDistributor.h" #include "fsfw/returnvalues/HasReturnvaluesIF.h" @@ -9,7 +9,7 @@ #include "fsfw/tmtcservices/AcceptsTelecommandsIF.h" #include "fsfw/tmtcservices/VerificationReporter.h" -class CCSDSDistributorIF; +class CcsdsDistributorIF; /** * This class accepts PUS Telecommands and forwards them to Application @@ -17,7 +17,7 @@ class CCSDSDistributorIF; * sends acceptance success or failure messages. * @ingroup tc_distribution */ -class PusDistributor : public TcDistributor, public PUSDistributorIF, public AcceptsTelecommandsIF { +class PusDistributor : public TcDistributor, public PusDistributorIF, public AcceptsTelecommandsIF { public: /** * The ctor passes @c set_apid to the checker class and calls the @@ -25,9 +25,9 @@ class PusDistributor : public TcDistributor, public PUSDistributorIF, public Acc * @param setApid The APID of this receiving Application. * @param setObjectId Object ID of the distributor itself * @param setPacketSource Object ID of the source of TC packets. - * Must implement CCSDSDistributorIF. + * Must implement CcsdsDistributorIF. */ - PusDistributor(uint16_t setApid, object_id_t setObjectId, CCSDSDistributorIF* packetSource, + PusDistributor(uint16_t setApid, object_id_t setObjectId, CcsdsDistributorIF* packetSource, StorageManagerIF* store = nullptr); /** * The destructor is empty. @@ -50,7 +50,7 @@ class PusDistributor : public TcDistributor, public PUSDistributorIF, public Acc */ VerificationReporterIF* verifyChannel = nullptr; //! Cached for initialization - CCSDSDistributorIF* ccsdsDistributor = nullptr; + CcsdsDistributorIF* ccsdsDistributor = nullptr; PusTcReader reader; /** diff --git a/src/fsfw/tcdistribution/PUSDistributorIF.h b/src/fsfw/tcdistribution/PusDistributorIF.h similarity index 91% rename from src/fsfw/tcdistribution/PUSDistributorIF.h rename to src/fsfw/tcdistribution/PusDistributorIF.h index da6db283..45a5571f 100644 --- a/src/fsfw/tcdistribution/PUSDistributorIF.h +++ b/src/fsfw/tcdistribution/PusDistributorIF.h @@ -8,12 +8,12 @@ * This interface allows PUS Services to register themselves at a PUS Distributor. * @ingroup tc_distribution */ -class PUSDistributorIF { +class PusDistributorIF { public: /** * The empty virtual destructor. */ - virtual ~PUSDistributorIF() {} + virtual ~PusDistributorIF() = default; /** * With this method, Services can register themselves at the PUS Distributor. * @param service A pointer to the registering Service. diff --git a/src/fsfw/tcdistribution/TcDistributor.h b/src/fsfw/tcdistribution/TcDistributor.h index 1b783ff4..e9e1fc97 100644 --- a/src/fsfw/tcdistribution/TcDistributor.h +++ b/src/fsfw/tcdistribution/TcDistributor.h @@ -18,11 +18,11 @@ */ /** - * This is the base class to implement distributors for Space Packets. - * Typically, the distribution is required to forward Telecommand packets + * This is the base class to implement distributors for telecommands. + * Typically, the distribution is required to forward telecommand packets * over the satellite applications and services. The class receives - * Space Packets over a message queue and holds a map that links other - * message queue ids to some identifier. The process of unpacking the + * TC packets over a message queue and holds a map that links other + * message queue IDs to some identifier. The process of unpacking the * destination information from the packet is handled by the child class * implementations. * @ingroup tc_distribution @@ -43,12 +43,12 @@ class TcDistributor : public SystemObject, public ExecutableObjectIF, public Has * @param set_object_id This id is assigned to the distributor * implementation. */ - TcDistributor(object_id_t objectId); + explicit TcDistributor(object_id_t objectId); /** * The destructor is empty, the message queues are not in the vicinity of * this class. */ - virtual ~TcDistributor(); + ~TcDistributor() override; /** * The method is called cyclically and fetches new incoming packets from * the message queue. @@ -56,7 +56,7 @@ class TcDistributor : public SystemObject, public ExecutableObjectIF, public Has * with distribution. * @return The error code of the message queue call. */ - ReturnValue_t performOperation(uint8_t opCode); + ReturnValue_t performOperation(uint8_t opCode) override; /** * A simple debug print, that prints all distribution information stored in * queueMap. diff --git a/src/fsfw/tmtcservices/CommandingServiceBase.cpp b/src/fsfw/tmtcservices/CommandingServiceBase.cpp index d7e3b514..37810fca 100644 --- a/src/fsfw/tmtcservices/CommandingServiceBase.cpp +++ b/src/fsfw/tmtcservices/CommandingServiceBase.cpp @@ -3,7 +3,7 @@ #include "fsfw/ipc/QueueFactory.h" #include "fsfw/objectmanager/ObjectManager.h" #include "fsfw/serviceinterface/ServiceInterface.h" -#include "fsfw/tcdistribution/PUSDistributorIF.h" +#include "fsfw/tcdistribution/PusDistributorIF.h" #include "fsfw/tmtcpacket/pus/tc.h" #include "fsfw/tmtcservices/AcceptsTelemetryIF.h" #include "fsfw/tmtcservices/TmTcMessage.h" @@ -68,7 +68,7 @@ ReturnValue_t CommandingServiceBase::initialize() { if (packetSource == objects::NO_OBJECT) { packetSource = defaultPacketSource; } - auto* distributor = ObjectManager::instance()->get(packetSource); + auto* distributor = ObjectManager::instance()->get(packetSource); if (packetForwarding == nullptr or distributor == nullptr) { #if FSFW_CPP_OSTREAM_ENABLED == 1 diff --git a/src/fsfw/tmtcservices/PusServiceBase.cpp b/src/fsfw/tmtcservices/PusServiceBase.cpp index b555449b..aabe2192 100644 --- a/src/fsfw/tmtcservices/PusServiceBase.cpp +++ b/src/fsfw/tmtcservices/PusServiceBase.cpp @@ -3,7 +3,7 @@ #include "fsfw/ipc/QueueFactory.h" #include "fsfw/objectmanager/ObjectManager.h" #include "fsfw/serviceinterface/ServiceInterface.h" -#include "fsfw/tcdistribution/PUSDistributorIF.h" +#include "fsfw/tcdistribution/PusDistributorIF.h" #include "fsfw/timemanager/CdsShortTimeStamper.h" #include "fsfw/tmtcservices/AcceptsTelemetryIF.h" #include "fsfw/tmtcservices/PusVerificationReport.h" @@ -111,7 +111,7 @@ ReturnValue_t PusServiceBase::initialize() { } if (psbParams.pusDistributor == nullptr) { - psbParams.pusDistributor = ObjectManager::instance()->get(PUS_DISTRIBUTOR); + psbParams.pusDistributor = ObjectManager::instance()->get(PUS_DISTRIBUTOR); if (psbParams.pusDistributor != nullptr) { registerService(*psbParams.pusDistributor); } @@ -193,7 +193,7 @@ void PusServiceBase::setVerificationReporter(VerificationReporterIF& reporter) { psbParams.verifReporter = &reporter; } -ReturnValue_t PusServiceBase::registerService(PUSDistributorIF& distributor) { +ReturnValue_t PusServiceBase::registerService(PusDistributorIF& distributor) { return distributor.registerService(this); } diff --git a/src/fsfw/tmtcservices/PusServiceBase.h b/src/fsfw/tmtcservices/PusServiceBase.h index 86d8ea1a..829ff03c 100644 --- a/src/fsfw/tmtcservices/PusServiceBase.h +++ b/src/fsfw/tmtcservices/PusServiceBase.h @@ -12,7 +12,7 @@ #include "fsfw/objectmanager/SystemObject.h" #include "fsfw/returnvalues/HasReturnvaluesIF.h" #include "fsfw/tasks/ExecutableObjectIF.h" -#include "fsfw/tcdistribution/PUSDistributorIF.h" +#include "fsfw/tcdistribution/PusDistributorIF.h" class StorageManagerIF; @@ -64,7 +64,7 @@ struct PsbParams { * a suitable global distributor with the static ID @PusServiceBase::pusDistributor and * register itself at that object. */ - PUSDistributorIF* pusDistributor = nullptr; + PusDistributorIF* pusDistributor = nullptr; TimeStamperIF* timeStamper = nullptr; }; @@ -116,7 +116,7 @@ class PusServiceBase : public ExecutableObjectIF, */ ~PusServiceBase() override; - ReturnValue_t registerService(PUSDistributorIF& distributor); + ReturnValue_t registerService(PusDistributorIF& distributor); /** * Set the request queue which is used to receive requests. If none is set, the initialize * function will create one diff --git a/unittests/mocks/PusDistributorMock.h b/unittests/mocks/PusDistributorMock.h index d5c7d96f..e19820f3 100644 --- a/unittests/mocks/PusDistributorMock.h +++ b/unittests/mocks/PusDistributorMock.h @@ -2,9 +2,9 @@ #define FSFW_TESTS_PUSDISTRIBUTORMOCK_H #include "fsfw/objectmanager/SystemObject.h" -#include "fsfw/tcdistribution/PUSDistributorIF.h" +#include "fsfw/tcdistribution/PusDistributorIF.h" -class PusDistributorMock : public SystemObject, public PUSDistributorIF { +class PusDistributorMock : public SystemObject, public PusDistributorIF { public: PusDistributorMock(); explicit PusDistributorMock(object_id_t registeredId); From c7b4dc349a6c10154002df56672852aafcfa6c31 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Fri, 29 Jul 2022 15:53:39 +0200 Subject: [PATCH 002/169] using uint32_t for getIdentifier of AcceptsTcIF --- src/fsfw/cfdp/CfdpHandler.cpp | 2 +- src/fsfw/cfdp/CfdpHandler.h | 2 +- src/fsfw/tcdistribution/CMakeLists.txt | 3 ++- src/fsfw/tcdistribution/CcsdsDistributor.cpp | 2 +- src/fsfw/tcdistribution/CcsdsDistributor.h | 2 +- src/fsfw/tcdistribution/CcsdsUnpacker.cpp | 7 +++++++ src/fsfw/tcdistribution/CcsdsUnpacker.h | 16 ++++++++++++++++ src/fsfw/tcdistribution/CfdpDistributor.cpp | 2 +- src/fsfw/tcdistribution/CfdpDistributor.h | 2 +- src/fsfw/tcdistribution/PusDistributor.cpp | 2 +- src/fsfw/tcdistribution/PusDistributor.h | 2 +- src/fsfw/tmtcservices/AcceptsTelecommandsIF.h | 12 ++++++------ src/fsfw/tmtcservices/CommandingServiceBase.cpp | 2 +- src/fsfw/tmtcservices/CommandingServiceBase.h | 2 +- src/fsfw/tmtcservices/PusServiceBase.cpp | 2 +- src/fsfw/tmtcservices/PusServiceBase.h | 2 +- src/fsfw/tmtcservices/TmTcBridge.cpp | 2 +- src/fsfw/tmtcservices/TmTcBridge.h | 2 +- 18 files changed, 45 insertions(+), 21 deletions(-) create mode 100644 src/fsfw/tcdistribution/CcsdsUnpacker.cpp create mode 100644 src/fsfw/tcdistribution/CcsdsUnpacker.h diff --git a/src/fsfw/cfdp/CfdpHandler.cpp b/src/fsfw/cfdp/CfdpHandler.cpp index cb13bca6..5db6bed3 100644 --- a/src/fsfw/cfdp/CfdpHandler.cpp +++ b/src/fsfw/cfdp/CfdpHandler.cpp @@ -52,6 +52,6 @@ ReturnValue_t CfdpHandler::performOperation(uint8_t opCode) { return RETURN_OK; } -uint16_t CfdpHandler::getIdentifier() { return 0; } +uint32_t CfdpHandler::getIdentifier() { return 0; } MessageQueueId_t CfdpHandler::getRequestQueue() { return this->requestQueue->getId(); } diff --git a/src/fsfw/cfdp/CfdpHandler.h b/src/fsfw/cfdp/CfdpHandler.h index 03424d64..f55ebf73 100644 --- a/src/fsfw/cfdp/CfdpHandler.h +++ b/src/fsfw/cfdp/CfdpHandler.h @@ -28,7 +28,7 @@ class CfdpHandler : public ExecutableObjectIF, virtual ReturnValue_t handleRequest(store_address_t storeId); virtual ReturnValue_t initialize() override; - virtual uint16_t getIdentifier() override; + virtual uint32_t getIdentifier() override; MessageQueueId_t getRequestQueue() override; ReturnValue_t performOperation(uint8_t opCode) override; diff --git a/src/fsfw/tcdistribution/CMakeLists.txt b/src/fsfw/tcdistribution/CMakeLists.txt index f1762ff4..2d1a74f6 100644 --- a/src/fsfw/tcdistribution/CMakeLists.txt +++ b/src/fsfw/tcdistribution/CMakeLists.txt @@ -6,4 +6,5 @@ target_sources( PusPacketChecker.cpp TcPacketCheckCFDP.cpp CfdpDistributor.cpp - CcsdsPacketChecker.cpp) + CcsdsPacketChecker.cpp + CcsdsUnpacker.cpp) diff --git a/src/fsfw/tcdistribution/CcsdsDistributor.cpp b/src/fsfw/tcdistribution/CcsdsDistributor.cpp index d263d68a..3a6d8729 100644 --- a/src/fsfw/tcdistribution/CcsdsDistributor.cpp +++ b/src/fsfw/tcdistribution/CcsdsDistributor.cpp @@ -80,7 +80,7 @@ ReturnValue_t CcsdsDistributor::registerApplication(uint16_t apid, MessageQueueI return returnValue; } -uint16_t CcsdsDistributor::getIdentifier() { return 0; } +uint32_t CcsdsDistributor::getIdentifier() { return 0; } ReturnValue_t CcsdsDistributor::initialize() { if (packetChecker == nullptr) { diff --git a/src/fsfw/tcdistribution/CcsdsDistributor.h b/src/fsfw/tcdistribution/CcsdsDistributor.h index ea7ad7e2..f3af87e3 100644 --- a/src/fsfw/tcdistribution/CcsdsDistributor.h +++ b/src/fsfw/tcdistribution/CcsdsDistributor.h @@ -38,7 +38,7 @@ class CcsdsDistributor : public TcDistributor, MessageQueueId_t getRequestQueue() override; ReturnValue_t registerApplication(uint16_t apid, MessageQueueId_t id) override; ReturnValue_t registerApplication(AcceptsTelecommandsIF* application) override; - uint16_t getIdentifier() override; + uint32_t getIdentifier() override; ReturnValue_t initialize() override; protected: diff --git a/src/fsfw/tcdistribution/CcsdsUnpacker.cpp b/src/fsfw/tcdistribution/CcsdsUnpacker.cpp new file mode 100644 index 00000000..2f8e9f27 --- /dev/null +++ b/src/fsfw/tcdistribution/CcsdsUnpacker.cpp @@ -0,0 +1,7 @@ +#include "CcsdsUnpacker.h" + +CcsdsUnpacker::CcsdsUnpacker() {} + +ReturnValue_t CcsdsUnpacker::performOperation(uint8_t operationCode) { return 0; } +uint32_t CcsdsUnpacker::getIdentifier() { return 0; } +MessageQueueId_t CcsdsUnpacker::getRequestQueue() { return 0; } diff --git a/src/fsfw/tcdistribution/CcsdsUnpacker.h b/src/fsfw/tcdistribution/CcsdsUnpacker.h new file mode 100644 index 00000000..b9b90d70 --- /dev/null +++ b/src/fsfw/tcdistribution/CcsdsUnpacker.h @@ -0,0 +1,16 @@ +#ifndef FSFW_TCDISTRIBUTION_CCSDSUNPACKER_H +#define FSFW_TCDISTRIBUTION_CCSDSUNPACKER_H + +#include "fsfw/tasks/ExecutableObjectIF.h" +#include "fsfw/tmtcservices/AcceptsTelecommandsIF.h" + +class CcsdsUnpacker: public ExecutableObjectIF, public AcceptsTelecommandsIF { + public: + CcsdsUnpacker(); + ReturnValue_t performOperation(uint8_t operationCode) override; + uint32_t getIdentifier() override; + MessageQueueId_t getRequestQueue() override; + + private: +}; +#endif // FSFW_TCDISTRIBUTION_CCSDSUNPACKER_H diff --git a/src/fsfw/tcdistribution/CfdpDistributor.cpp b/src/fsfw/tcdistribution/CfdpDistributor.cpp index 1f380530..26d7948d 100644 --- a/src/fsfw/tcdistribution/CfdpDistributor.cpp +++ b/src/fsfw/tcdistribution/CfdpDistributor.cpp @@ -118,7 +118,7 @@ MessageQueueId_t CfdpDistributor::getRequestQueue() { return tcQueue->getId(); } // } // } -uint16_t CfdpDistributor::getIdentifier() { return this->apid; } +uint32_t CfdpDistributor::getIdentifier() { return this->apid; } ReturnValue_t CfdpDistributor::initialize() { currentPacket = new CfdpPacketStored(); diff --git a/src/fsfw/tcdistribution/CfdpDistributor.h b/src/fsfw/tcdistribution/CfdpDistributor.h index 181d3613..7a69b3d0 100644 --- a/src/fsfw/tcdistribution/CfdpDistributor.h +++ b/src/fsfw/tcdistribution/CfdpDistributor.h @@ -35,7 +35,7 @@ class CfdpDistributor : public TcDistributor, ReturnValue_t registerHandler(AcceptsTelecommandsIF* handler) override; MessageQueueId_t getRequestQueue() override; ReturnValue_t initialize() override; - uint16_t getIdentifier() override; + uint32_t getIdentifier() override; protected: uint16_t apid; diff --git a/src/fsfw/tcdistribution/PusDistributor.cpp b/src/fsfw/tcdistribution/PusDistributor.cpp index 8a9ebb89..f8c28447 100644 --- a/src/fsfw/tcdistribution/PusDistributor.cpp +++ b/src/fsfw/tcdistribution/PusDistributor.cpp @@ -117,7 +117,7 @@ ReturnValue_t PusDistributor::callbackAfterSending(ReturnValue_t queueStatus) { } } -uint16_t PusDistributor::getIdentifier() { return checker.getApid(); } +uint32_t PusDistributor::getIdentifier() { return checker.getApid(); } ReturnValue_t PusDistributor::initialize() { if (store == nullptr) { diff --git a/src/fsfw/tcdistribution/PusDistributor.h b/src/fsfw/tcdistribution/PusDistributor.h index 6acefd02..f9ade4e2 100644 --- a/src/fsfw/tcdistribution/PusDistributor.h +++ b/src/fsfw/tcdistribution/PusDistributor.h @@ -36,7 +36,7 @@ class PusDistributor : public TcDistributor, public PusDistributorIF, public Acc ReturnValue_t registerService(AcceptsTelecommandsIF* service) override; MessageQueueId_t getRequestQueue() override; ReturnValue_t initialize() override; - uint16_t getIdentifier() override; + uint32_t getIdentifier() override; protected: StorageManagerIF* store; diff --git a/src/fsfw/tmtcservices/AcceptsTelecommandsIF.h b/src/fsfw/tmtcservices/AcceptsTelecommandsIF.h index e18a4f3a..a0fb23d1 100644 --- a/src/fsfw/tmtcservices/AcceptsTelecommandsIF.h +++ b/src/fsfw/tmtcservices/AcceptsTelecommandsIF.h @@ -22,13 +22,13 @@ class AcceptsTelecommandsIF { */ virtual ~AcceptsTelecommandsIF() = default; /** - * @brief Getter for the service id. - * @details Any receiving service (at least any PUS service) shall have a - * service ID. If the receiver can handle Telecommands, but for - * some reason has no service id, it shall return 0. - * @return The service ID or 0. + * @brief Getter for a generic identifier ID. + * @details Any receiving service (at least any PUS service) shall have an identifier. For + * example, this could be the APID for a receiver expecting generic PUS packets, or a PUS + * service for a component expecting specific PUS service packets. + * @return The identifier. */ - virtual uint16_t getIdentifier() = 0; + virtual uint32_t getIdentifier() = 0; /** * @brief This method returns the message queue id of the telecommand * receiving message queue. diff --git a/src/fsfw/tmtcservices/CommandingServiceBase.cpp b/src/fsfw/tmtcservices/CommandingServiceBase.cpp index 37810fca..fc9c0685 100644 --- a/src/fsfw/tmtcservices/CommandingServiceBase.cpp +++ b/src/fsfw/tmtcservices/CommandingServiceBase.cpp @@ -50,7 +50,7 @@ ReturnValue_t CommandingServiceBase::performOperation(uint8_t opCode) { return RETURN_OK; } -uint16_t CommandingServiceBase::getIdentifier() { return service; } +uint32_t CommandingServiceBase::getIdentifier() { return service; } MessageQueueId_t CommandingServiceBase::getRequestQueue() { return requestQueue->getId(); } diff --git a/src/fsfw/tmtcservices/CommandingServiceBase.h b/src/fsfw/tmtcservices/CommandingServiceBase.h index c16d9ded..07f7179a 100644 --- a/src/fsfw/tmtcservices/CommandingServiceBase.h +++ b/src/fsfw/tmtcservices/CommandingServiceBase.h @@ -106,7 +106,7 @@ class CommandingServiceBase : public SystemObject, */ ReturnValue_t performOperation(uint8_t opCode) override; - uint16_t getIdentifier() override; + uint32_t getIdentifier() override; /** * Returns the requestQueue MessageQueueId_t diff --git a/src/fsfw/tmtcservices/PusServiceBase.cpp b/src/fsfw/tmtcservices/PusServiceBase.cpp index aabe2192..d777d03e 100644 --- a/src/fsfw/tmtcservices/PusServiceBase.cpp +++ b/src/fsfw/tmtcservices/PusServiceBase.cpp @@ -82,7 +82,7 @@ void PusServiceBase::handleRequestQueue() { } } -uint16_t PusServiceBase::getIdentifier() { return psbParams.serviceId; } +uint32_t PusServiceBase::getIdentifier() { return psbParams.serviceId; } MessageQueueId_t PusServiceBase::getRequestQueue() { if (psbParams.reqQueue == nullptr) { diff --git a/src/fsfw/tmtcservices/PusServiceBase.h b/src/fsfw/tmtcservices/PusServiceBase.h index 829ff03c..34483fe7 100644 --- a/src/fsfw/tmtcservices/PusServiceBase.h +++ b/src/fsfw/tmtcservices/PusServiceBase.h @@ -188,7 +188,7 @@ class PusServiceBase : public ExecutableObjectIF, * @c RETURN_FAILED else. */ ReturnValue_t performOperation(uint8_t opCode) override; - uint16_t getIdentifier() override; + uint32_t getIdentifier() override; MessageQueueId_t getRequestQueue() override; ReturnValue_t initialize() override; diff --git a/src/fsfw/tmtcservices/TmTcBridge.cpp b/src/fsfw/tmtcservices/TmTcBridge.cpp index 6af03600..7190d771 100644 --- a/src/fsfw/tmtcservices/TmTcBridge.cpp +++ b/src/fsfw/tmtcservices/TmTcBridge.cpp @@ -247,7 +247,7 @@ MessageQueueId_t TmTcBridge::getReportReceptionQueue(uint8_t virtualChannel) { void TmTcBridge::printData(uint8_t* data, size_t dataLen) { arrayprinter::print(data, dataLen); } -uint16_t TmTcBridge::getIdentifier() { +uint32_t TmTcBridge::getIdentifier() { // This is no PUS service, so we just return 0 return 0; } diff --git a/src/fsfw/tmtcservices/TmTcBridge.h b/src/fsfw/tmtcservices/TmTcBridge.h index 237f1f3e..c4bc4062 100644 --- a/src/fsfw/tmtcservices/TmTcBridge.h +++ b/src/fsfw/tmtcservices/TmTcBridge.h @@ -69,7 +69,7 @@ class TmTcBridge : public AcceptsTelemetryIF, virtual MessageQueueId_t getReportReceptionQueue(uint8_t virtualChannel = 0) override; /** AcceptsTelecommandsIF override */ - virtual uint16_t getIdentifier() override; + virtual uint32_t getIdentifier() override; virtual MessageQueueId_t getRequestQueue() override; protected: From f4beef8c9f394085896204f64ce873c7676fd80c Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Fri, 29 Jul 2022 15:54:17 +0200 Subject: [PATCH 003/169] run auto-formatter --- src/fsfw/tcdistribution/CcsdsUnpacker.h | 2 +- src/fsfw/util/ObjectId.h | 53 ++++++++---------------- src/fsfw/util/UnsignedByteField.h | 35 +++++++--------- unittests/util/testObjectId.cpp | 36 ++++++++-------- unittests/util/testUnsignedByteField.cpp | 12 +++--- 5 files changed, 58 insertions(+), 80 deletions(-) diff --git a/src/fsfw/tcdistribution/CcsdsUnpacker.h b/src/fsfw/tcdistribution/CcsdsUnpacker.h index b9b90d70..a134de33 100644 --- a/src/fsfw/tcdistribution/CcsdsUnpacker.h +++ b/src/fsfw/tcdistribution/CcsdsUnpacker.h @@ -4,7 +4,7 @@ #include "fsfw/tasks/ExecutableObjectIF.h" #include "fsfw/tmtcservices/AcceptsTelecommandsIF.h" -class CcsdsUnpacker: public ExecutableObjectIF, public AcceptsTelecommandsIF { +class CcsdsUnpacker : public ExecutableObjectIF, public AcceptsTelecommandsIF { public: CcsdsUnpacker(); ReturnValue_t performOperation(uint8_t operationCode) override; diff --git a/src/fsfw/util/ObjectId.h b/src/fsfw/util/ObjectId.h index b51f63e6..a6716fe8 100644 --- a/src/fsfw/util/ObjectId.h +++ b/src/fsfw/util/ObjectId.h @@ -1,57 +1,38 @@ #ifndef FSFW_UTIL_OBJECTID_H #define FSFW_UTIL_OBJECTID_H -#include "fsfw/objectmanager.h" -#include "UnsignedByteField.h" - #include -class ObjectId: public UnsignedByteField { +#include "UnsignedByteField.h" +#include "fsfw/objectmanager.h" + +class ObjectId : public UnsignedByteField { public: - ObjectId(object_id_t id, const char* name): UnsignedByteField(id), name_(name) {} + ObjectId(object_id_t id, const char* name) : UnsignedByteField(id), name_(name) {} - [[nodiscard]] const char* name() const { - return name_; - } + [[nodiscard]] const char* name() const { return name_; } - [[nodiscard]] object_id_t id() const { - return getValue(); - } + [[nodiscard]] object_id_t id() const { return getValue(); } - bool operator==(const ObjectId& other) const { - return id() == other.id(); - } + bool operator==(const ObjectId& other) const { return id() == other.id(); } - bool operator!=(const ObjectId& other) const { - return id() != other.id(); - } + bool operator!=(const ObjectId& other) const { return id() != other.id(); } - bool operator<(const ObjectId& other) const { - return id() < other.id(); - } + bool operator<(const ObjectId& other) const { return id() < other.id(); } - bool operator>(const ObjectId& other) const { - return id() > other.id(); - } + bool operator>(const ObjectId& other) const { return id() > other.id(); } - bool operator>=(const ObjectId& other) const { - return id() >= other.id(); - } + bool operator>=(const ObjectId& other) const { return id() >= other.id(); } + + bool operator<=(const ObjectId& other) const { return id() <= other.id(); } - bool operator<=(const ObjectId& other) const { - return id() <= other.id(); - } private: const char* name_; }; -template<> -struct std::hash -{ - std::size_t operator()(ObjectId const& s) const noexcept - { - return std::hash{}(s.id()); - } +template <> +struct std::hash { + std::size_t operator()(ObjectId const& s) const noexcept { return std::hash{}(s.id()); } }; #endif // FSFW_UTIL_OBJECTID_H diff --git a/src/fsfw/util/UnsignedByteField.h b/src/fsfw/util/UnsignedByteField.h index b02e8b3a..3f4ee791 100644 --- a/src/fsfw/util/UnsignedByteField.h +++ b/src/fsfw/util/UnsignedByteField.h @@ -3,50 +3,45 @@ #include "fsfw/serialize.h" -template -class UnsignedByteField: public SerializeIF { +template +class UnsignedByteField : public SerializeIF { public: static_assert(std::is_unsigned::value); - explicit UnsignedByteField(T value): value(value) {} + explicit UnsignedByteField(T value) : value(value) {} [[nodiscard]] ReturnValue_t serialize(uint8_t **buffer, size_t *size, size_t maxSize, - Endianness streamEndianness) const override { + Endianness streamEndianness) const override { return SerializeAdapter::serialize(&value, buffer, size, maxSize, streamEndianness); } ReturnValue_t deSerialize(const uint8_t **buffer, size_t *size, - Endianness streamEndianness) override { + Endianness streamEndianness) override { return SerializeAdapter::deSerialize(&value, buffer, size, streamEndianness); } - [[nodiscard]] size_t getSerializedSize() const override { - return sizeof(T); - } + [[nodiscard]] size_t getSerializedSize() const override { return sizeof(T); } - [[nodiscard]] T getValue() const { - return value; - } + [[nodiscard]] T getValue() const { return value; } + + void setValue(T value_) { value = value_; } - void setValue(T value_) { - value = value_; - } private: T value; }; -class U32ByteField: public UnsignedByteField { +class U32ByteField : public UnsignedByteField { public: - explicit U32ByteField(uint32_t value): UnsignedByteField(value) {} + explicit U32ByteField(uint32_t value) : UnsignedByteField(value) {} }; -class U16ByteField: public UnsignedByteField { +class U16ByteField : public UnsignedByteField { public: - explicit U16ByteField(uint16_t value): UnsignedByteField(value) {} + explicit U16ByteField(uint16_t value) : UnsignedByteField(value) {} }; -class U8ByteField: public UnsignedByteField { +class U8ByteField : public UnsignedByteField { public: - explicit U8ByteField(uint8_t value): UnsignedByteField(value) {} + explicit U8ByteField(uint8_t value) : UnsignedByteField(value) {} }; #endif // FSFW_UTIL_UNSIGNEDBYTEFIELD_H diff --git a/unittests/util/testObjectId.cpp b/unittests/util/testObjectId.cpp index cead2c15..ce8761f5 100644 --- a/unittests/util/testObjectId.cpp +++ b/unittests/util/testObjectId.cpp @@ -1,26 +1,26 @@ +#include #include #include "fsfw/util/ObjectId.h" -#include TEST_CASE("Object Id", "[object-id]") { - auto objectId = ObjectId(10, "TEST_ID"); - std::map testMap; + auto objectId = ObjectId(10, "TEST_ID"); + std::map testMap; - SECTION("State") { - CHECK(objectId.id() == 10); - CHECK(std::strcmp(objectId.name(), "TEST_ID") == 0); - } + SECTION("State") { + CHECK(objectId.id() == 10); + CHECK(std::strcmp(objectId.name(), "TEST_ID") == 0); + } - SECTION("ID as map key") { - auto insertPair = testMap.emplace(objectId, 10); - CHECK(insertPair.second); - auto iter = testMap.find(objectId); - CHECK(iter != testMap.end()); - CHECK(std::strcmp(iter->first.name(), "TEST_ID") == 0); - CHECK(iter->second == 10); - auto otherIdSameName = ObjectId(12, "TEST_ID"); - insertPair = testMap.emplace(otherIdSameName, 10); - CHECK(insertPair.second); - } + SECTION("ID as map key") { + auto insertPair = testMap.emplace(objectId, 10); + CHECK(insertPair.second); + auto iter = testMap.find(objectId); + CHECK(iter != testMap.end()); + CHECK(std::strcmp(iter->first.name(), "TEST_ID") == 0); + CHECK(iter->second == 10); + auto otherIdSameName = ObjectId(12, "TEST_ID"); + insertPair = testMap.emplace(otherIdSameName, 10); + CHECK(insertPair.second); + } } \ No newline at end of file diff --git a/unittests/util/testUnsignedByteField.cpp b/unittests/util/testUnsignedByteField.cpp index 9a67c092..83ffd3c6 100644 --- a/unittests/util/testUnsignedByteField.cpp +++ b/unittests/util/testUnsignedByteField.cpp @@ -1,10 +1,9 @@ +#include #include #include "fsfw/util/UnsignedByteField.h" -#include - TEST_CASE("Unsigned Byte Field", "[unsigned-byte-field]") { auto testByteField = UnsignedByteField(10); auto u32ByteField = U32ByteField(10); @@ -28,7 +27,8 @@ TEST_CASE("Unsigned Byte Field", "[unsigned-byte-field]") { } SECTION("Serialize U32") { - CHECK(testByteField.serializeBe(buf.data(), serLen, buf.size()) == HasReturnvaluesIF::RETURN_OK); + CHECK(testByteField.serializeBe(buf.data(), serLen, buf.size()) == + HasReturnvaluesIF::RETURN_OK); CHECK(serLen == 4); CHECK(buf[0] == 0); CHECK(buf[3] == 10); @@ -60,7 +60,8 @@ TEST_CASE("Unsigned Byte Field", "[unsigned-byte-field]") { buf[2] = 0x30; buf[3] = 0x20; size_t deserLen = 0; - CHECK(testByteField.deSerializeBe(buf.data(), deserLen, buf.size()) == HasReturnvaluesIF::RETURN_OK); + CHECK(testByteField.deSerializeBe(buf.data(), deserLen, buf.size()) == + HasReturnvaluesIF::RETURN_OK); CHECK(testByteField.getValue() == 0x50403020); } @@ -68,7 +69,8 @@ TEST_CASE("Unsigned Byte Field", "[unsigned-byte-field]") { buf[0] = 0x50; buf[1] = 0x40; size_t deserLen = 0; - CHECK(u16ByteField.deSerializeBe(buf.data(), deserLen, buf.size()) == HasReturnvaluesIF::RETURN_OK); + CHECK(u16ByteField.deSerializeBe(buf.data(), deserLen, buf.size()) == + HasReturnvaluesIF::RETURN_OK); CHECK(u16ByteField.getValue() == 0x5040); } } \ No newline at end of file From 83d71548ec52e5fdbeda55660de066a40c8bcb43 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Fri, 29 Jul 2022 16:32:50 +0200 Subject: [PATCH 004/169] CCSDS unpacker implementation --- src/fsfw/tcdistribution/CcsdsUnpacker.cpp | 59 +++++++++++++++++++++-- src/fsfw/tcdistribution/CcsdsUnpacker.h | 9 +++- 2 files changed, 64 insertions(+), 4 deletions(-) diff --git a/src/fsfw/tcdistribution/CcsdsUnpacker.cpp b/src/fsfw/tcdistribution/CcsdsUnpacker.cpp index 2f8e9f27..226b857b 100644 --- a/src/fsfw/tcdistribution/CcsdsUnpacker.cpp +++ b/src/fsfw/tcdistribution/CcsdsUnpacker.cpp @@ -1,7 +1,60 @@ #include "CcsdsUnpacker.h" -CcsdsUnpacker::CcsdsUnpacker() {} +#include "fsfw/tmtcservices/TmTcMessage.h" + +CcsdsUnpacker::CcsdsUnpacker(MessageQueueIF& msgQueue, AcceptsTelecommandsIF& receiver, + StorageManagerIF& sourceStore) + : sourceStore(sourceStore), msgQueue(msgQueue), receiver(receiver) { + msgQueue.setDefaultDestination(receiver.getRequestQueue()); +} + +ReturnValue_t CcsdsUnpacker::performOperation(uint8_t operationCode) { + TmTcMessage msg; + ReturnValue_t result; + for (result = msgQueue.receiveMessage(&msg); result == HasReturnvaluesIF::RETURN_OK; + result = msgQueue.receiveMessage(&msg)) { + auto resultPair = sourceStore.getData(msg.getStorageId()); + if(resultPair.first != HasReturnvaluesIF::RETURN_OK) { + continue; + } + if(resultPair.second.size() < 6) { + // TODO: This is a config error. Does it make sense to forward the message? + result = msgQueue.sendToDefault(&msg); + if(result != HasReturnvaluesIF::RETURN_OK) { + + } + continue; + } + StorageManagerIF* tgtStore; + if(targetStore != nullptr) { + tgtStore = targetStore; + } else { + tgtStore = &sourceStore; + } + store_address_t newId; + uint8_t* ptr; + result = tgtStore->getFreeElement(&newId, resultPair.second.size(), &ptr); + if(result != HasReturnvaluesIF::RETURN_OK) { + // TODO: Implement error handling + } + std::memcpy(ptr, resultPair.second.data() + 6, resultPair.second.size() - 6); + result = sourceStore.deleteData(msg.getStorageId()); + if(result != HasReturnvaluesIF::RETURN_OK) { + // TODO: Implement error handling (though this really should not happen) + } + TmTcMessage newMsg(newId); + result = msgQueue.sendToDefault(&newMsg); + if(result != HasReturnvaluesIF::RETURN_OK) { + + } + } + return result; +} -ReturnValue_t CcsdsUnpacker::performOperation(uint8_t operationCode) { return 0; } uint32_t CcsdsUnpacker::getIdentifier() { return 0; } -MessageQueueId_t CcsdsUnpacker::getRequestQueue() { return 0; } + +MessageQueueId_t CcsdsUnpacker::getRequestQueue() { return msgQueue.getId(); } + +void CcsdsUnpacker::setDifferentTargetStore(StorageManagerIF& otherTargetStore) { + targetStore = &otherTargetStore; +} diff --git a/src/fsfw/tcdistribution/CcsdsUnpacker.h b/src/fsfw/tcdistribution/CcsdsUnpacker.h index a134de33..c4eb7da4 100644 --- a/src/fsfw/tcdistribution/CcsdsUnpacker.h +++ b/src/fsfw/tcdistribution/CcsdsUnpacker.h @@ -1,16 +1,23 @@ #ifndef FSFW_TCDISTRIBUTION_CCSDSUNPACKER_H #define FSFW_TCDISTRIBUTION_CCSDSUNPACKER_H +#include "fsfw/storagemanager/StorageManagerIF.h" #include "fsfw/tasks/ExecutableObjectIF.h" #include "fsfw/tmtcservices/AcceptsTelecommandsIF.h" class CcsdsUnpacker : public ExecutableObjectIF, public AcceptsTelecommandsIF { public: - CcsdsUnpacker(); + CcsdsUnpacker(MessageQueueIF& msgQueue, AcceptsTelecommandsIF& receiver, StorageManagerIF& sourceStore); + + void setDifferentTargetStore(StorageManagerIF& otherTargetStore); ReturnValue_t performOperation(uint8_t operationCode) override; uint32_t getIdentifier() override; MessageQueueId_t getRequestQueue() override; private: + StorageManagerIF& sourceStore; + StorageManagerIF* targetStore = nullptr; + MessageQueueIF& msgQueue; + AcceptsTelecommandsIF& receiver; }; #endif // FSFW_TCDISTRIBUTION_CCSDSUNPACKER_H From 458fe460eb7b330901cc7444c0c8d5981e269338 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Mon, 1 Aug 2022 11:00:36 +0200 Subject: [PATCH 005/169] TMTC Routing Refactoring 1. Make TcDistributor less powerful / more flexible and rename it to TcDistributorBase 2. Require AcceptsTelecommandsIF to have an abstract function returning the name 3. Allows the CCSDS distributor to remove the CCSDS header before rerouting. This is useful for protocols like CFDP which are CCSDS agnostic. WIP: Still need to implement the removal of the CCSDS header --- src/fsfw/cfdp/CfdpHandler.cpp | 4 +- src/fsfw/cfdp/CfdpHandler.h | 4 +- src/fsfw/osal/common/TcpTmTcBridge.cpp | 2 +- src/fsfw/osal/common/UdpTmTcBridge.cpp | 2 +- src/fsfw/pus/CService200ModeCommanding.cpp | 4 +- src/fsfw/pus/CService201HealthCommanding.cpp | 4 +- .../pus/Service11TelecommandScheduling.tpp | 4 +- src/fsfw/pus/Service17Test.cpp | 4 +- src/fsfw/pus/Service20ParameterManagement.cpp | 4 +- src/fsfw/pus/Service2DeviceAccess.cpp | 4 +- src/fsfw/pus/Service3Housekeeping.cpp | 2 +- src/fsfw/pus/Service5EventReporting.cpp | 1 + src/fsfw/pus/Service8FunctionManagement.cpp | 4 +- src/fsfw/pus/Service9TimeManagement.cpp | 4 +- src/fsfw/tcdistribution/CcsdsDistributor.cpp | 77 +++++-- src/fsfw/tcdistribution/CcsdsDistributor.h | 22 +- src/fsfw/tcdistribution/CcsdsDistributorIF.h | 46 +++-- src/fsfw/tcdistribution/CcsdsUnpacker.cpp | 4 +- src/fsfw/tcdistribution/CcsdsUnpacker.h | 4 +- src/fsfw/tcdistribution/CfdpDistributor.cpp | 192 +++++++++--------- src/fsfw/tcdistribution/CfdpDistributor.h | 10 +- src/fsfw/tcdistribution/PusDistributor.cpp | 89 ++++---- src/fsfw/tcdistribution/PusDistributor.h | 27 ++- src/fsfw/tcdistribution/PusDistributorIF.h | 2 +- src/fsfw/tcdistribution/TcDistributor.cpp | 34 ++-- .../{TcDistributor.h => TcDistributorBase.h} | 24 +-- src/fsfw/tmtcservices/AcceptsTelecommandsIF.h | 6 +- .../tmtcservices/CommandingServiceBase.cpp | 14 +- src/fsfw/tmtcservices/CommandingServiceBase.h | 9 +- src/fsfw/tmtcservices/PusServiceBase.cpp | 8 +- src/fsfw/tmtcservices/PusServiceBase.h | 12 +- src/fsfw/tmtcservices/TmTcBridge.cpp | 14 +- src/fsfw/tmtcservices/TmTcBridge.h | 19 +- 33 files changed, 368 insertions(+), 292 deletions(-) rename src/fsfw/tcdistribution/{TcDistributor.h => TcDistributorBase.h} (83%) diff --git a/src/fsfw/cfdp/CfdpHandler.cpp b/src/fsfw/cfdp/CfdpHandler.cpp index 5db6bed3..35e5b2bc 100644 --- a/src/fsfw/cfdp/CfdpHandler.cpp +++ b/src/fsfw/cfdp/CfdpHandler.cpp @@ -52,6 +52,6 @@ ReturnValue_t CfdpHandler::performOperation(uint8_t opCode) { return RETURN_OK; } -uint32_t CfdpHandler::getIdentifier() { return 0; } +uint32_t CfdpHandler::getIdentifier() const { return 0; } -MessageQueueId_t CfdpHandler::getRequestQueue() { return this->requestQueue->getId(); } +MessageQueueId_t CfdpHandler::getRequestQueue() const { return this->requestQueue->getId(); } diff --git a/src/fsfw/cfdp/CfdpHandler.h b/src/fsfw/cfdp/CfdpHandler.h index f55ebf73..8730f3eb 100644 --- a/src/fsfw/cfdp/CfdpHandler.h +++ b/src/fsfw/cfdp/CfdpHandler.h @@ -28,8 +28,8 @@ class CfdpHandler : public ExecutableObjectIF, virtual ReturnValue_t handleRequest(store_address_t storeId); virtual ReturnValue_t initialize() override; - virtual uint32_t getIdentifier() override; - MessageQueueId_t getRequestQueue() override; + virtual uint32_t getIdentifier() const override; + MessageQueueId_t getRequestQueue() const override; ReturnValue_t performOperation(uint8_t opCode) override; protected: diff --git a/src/fsfw/osal/common/TcpTmTcBridge.cpp b/src/fsfw/osal/common/TcpTmTcBridge.cpp index 4b2bea73..7bd53380 100644 --- a/src/fsfw/osal/common/TcpTmTcBridge.cpp +++ b/src/fsfw/osal/common/TcpTmTcBridge.cpp @@ -18,7 +18,7 @@ TcpTmTcBridge::TcpTmTcBridge(object_id_t objectId, object_id_t tcDestination, object_id_t tmStoreId, object_id_t tcStoreId) - : TmTcBridge(objectId, tcDestination, tmStoreId, tcStoreId) { + : TmTcBridge("TCP TMTC Bridge", objectId, tcDestination, tmStoreId, tcStoreId) { mutex = MutexFactory::instance()->createMutex(); // Connection is always up, TM is requested by connecting to server and receiving packets registerCommConnect(); diff --git a/src/fsfw/osal/common/UdpTmTcBridge.cpp b/src/fsfw/osal/common/UdpTmTcBridge.cpp index e3cad58f..3f2d04b5 100644 --- a/src/fsfw/osal/common/UdpTmTcBridge.cpp +++ b/src/fsfw/osal/common/UdpTmTcBridge.cpp @@ -22,7 +22,7 @@ const std::string UdpTmTcBridge::DEFAULT_SERVER_PORT = tcpip::DEFAULT_SERVER_POR UdpTmTcBridge::UdpTmTcBridge(object_id_t objectId, object_id_t tcDestination, const std::string &udpServerPort_, object_id_t tmStoreId, object_id_t tcStoreId) - : TmTcBridge(objectId, tcDestination, tmStoreId, tcStoreId) { + : TmTcBridge("UDP TMTC Bridge", objectId, tcDestination, tmStoreId, tcStoreId) { if (udpServerPort_.empty()) { udpServerPort = DEFAULT_SERVER_PORT; } else { diff --git a/src/fsfw/pus/CService200ModeCommanding.cpp b/src/fsfw/pus/CService200ModeCommanding.cpp index 9990280c..4a02ea3d 100644 --- a/src/fsfw/pus/CService200ModeCommanding.cpp +++ b/src/fsfw/pus/CService200ModeCommanding.cpp @@ -10,8 +10,8 @@ CService200ModeCommanding::CService200ModeCommanding(object_id_t objectId, uint16_t apid, uint8_t serviceId, uint8_t numParallelCommands, uint16_t commandTimeoutSeconds) - : CommandingServiceBase(objectId, apid, serviceId, numParallelCommands, commandTimeoutSeconds) { -} + : CommandingServiceBase(objectId, apid, "PUS 200 Mode MGMT", serviceId, numParallelCommands, + commandTimeoutSeconds) {} CService200ModeCommanding::~CService200ModeCommanding() {} diff --git a/src/fsfw/pus/CService201HealthCommanding.cpp b/src/fsfw/pus/CService201HealthCommanding.cpp index c668ea52..a53a4ead 100644 --- a/src/fsfw/pus/CService201HealthCommanding.cpp +++ b/src/fsfw/pus/CService201HealthCommanding.cpp @@ -10,8 +10,8 @@ CService201HealthCommanding::CService201HealthCommanding(object_id_t objectId, u uint8_t serviceId, uint8_t numParallelCommands, uint16_t commandTimeoutSeconds) - : CommandingServiceBase(objectId, apid, serviceId, numParallelCommands, commandTimeoutSeconds) { -} + : CommandingServiceBase(objectId, apid, "PUS 201 Health MGMT", serviceId, numParallelCommands, + commandTimeoutSeconds) {} ReturnValue_t CService201HealthCommanding::isValidSubservice(uint8_t subservice) { switch (subservice) { diff --git a/src/fsfw/pus/Service11TelecommandScheduling.tpp b/src/fsfw/pus/Service11TelecommandScheduling.tpp index 83713266..1cc9b7fe 100644 --- a/src/fsfw/pus/Service11TelecommandScheduling.tpp +++ b/src/fsfw/pus/Service11TelecommandScheduling.tpp @@ -16,7 +16,9 @@ inline Service11TelecommandScheduling::Service11TelecommandScheduli : PusServiceBase(params), RELEASE_TIME_MARGIN_SECONDS(releaseTimeMarginSeconds), debugMode(debugMode), - tcRecipient(tcRecipient) {} + tcRecipient(tcRecipient) { + params.name = "PUS 11 TC Scheduling"; +} template inline Service11TelecommandScheduling::~Service11TelecommandScheduling() = default; diff --git a/src/fsfw/pus/Service17Test.cpp b/src/fsfw/pus/Service17Test.cpp index 14257334..0ef71fe1 100644 --- a/src/fsfw/pus/Service17Test.cpp +++ b/src/fsfw/pus/Service17Test.cpp @@ -8,7 +8,9 @@ Service17Test::Service17Test(PsbParams params) : PusServiceBase(params), storeHelper(params.apid), - tmHelper(params.serviceId, storeHelper, sendHelper) {} + tmHelper(params.serviceId, storeHelper, sendHelper) { + params.name = "PUS 17 Test"; +} Service17Test::~Service17Test() = default; diff --git a/src/fsfw/pus/Service20ParameterManagement.cpp b/src/fsfw/pus/Service20ParameterManagement.cpp index 6d6ca339..747c1ccf 100644 --- a/src/fsfw/pus/Service20ParameterManagement.cpp +++ b/src/fsfw/pus/Service20ParameterManagement.cpp @@ -11,8 +11,8 @@ Service20ParameterManagement::Service20ParameterManagement(object_id_t objectId, uint8_t serviceId, uint8_t numberOfParallelCommands, uint16_t commandTimeoutSeconds) - : CommandingServiceBase(objectId, apid, serviceId, numberOfParallelCommands, - commandTimeoutSeconds) {} + : CommandingServiceBase(objectId, apid, "PUS 20 Parameter MGMT", serviceId, + numberOfParallelCommands, commandTimeoutSeconds) {} Service20ParameterManagement::~Service20ParameterManagement() = default; diff --git a/src/fsfw/pus/Service2DeviceAccess.cpp b/src/fsfw/pus/Service2DeviceAccess.cpp index 414f0812..71fc4938 100644 --- a/src/fsfw/pus/Service2DeviceAccess.cpp +++ b/src/fsfw/pus/Service2DeviceAccess.cpp @@ -14,8 +14,8 @@ Service2DeviceAccess::Service2DeviceAccess(object_id_t objectId, uint16_t apid, uint8_t serviceId, uint8_t numberOfParallelCommands, uint16_t commandTimeoutSeconds) - : CommandingServiceBase(objectId, apid, serviceId, numberOfParallelCommands, - commandTimeoutSeconds) {} + : CommandingServiceBase(objectId, apid, "PUS 2 Raw Commanding", serviceId, + numberOfParallelCommands, commandTimeoutSeconds) {} Service2DeviceAccess::~Service2DeviceAccess() {} diff --git a/src/fsfw/pus/Service3Housekeeping.cpp b/src/fsfw/pus/Service3Housekeeping.cpp index 7ef5636d..6edd9d4b 100644 --- a/src/fsfw/pus/Service3Housekeeping.cpp +++ b/src/fsfw/pus/Service3Housekeeping.cpp @@ -5,7 +5,7 @@ #include "fsfw/pus/servicepackets/Service3Packets.h" Service3Housekeeping::Service3Housekeeping(object_id_t objectId, uint16_t apid, uint8_t serviceId) - : CommandingServiceBase(objectId, apid, serviceId, NUM_OF_PARALLEL_COMMANDS, + : CommandingServiceBase(objectId, apid, "PUS 3 HK", serviceId, NUM_OF_PARALLEL_COMMANDS, COMMAND_TIMEOUT_SECONDS) {} Service3Housekeeping::~Service3Housekeeping() {} diff --git a/src/fsfw/pus/Service5EventReporting.cpp b/src/fsfw/pus/Service5EventReporting.cpp index fa518d0f..adba396e 100644 --- a/src/fsfw/pus/Service5EventReporting.cpp +++ b/src/fsfw/pus/Service5EventReporting.cpp @@ -13,6 +13,7 @@ Service5EventReporting::Service5EventReporting(PsbParams params, size_t maxNumbe storeHelper(params.apid), tmHelper(params.serviceId, storeHelper, sendHelper), maxNumberReportsPerCycle(maxNumberReportsPerCycle) { + psbParams.name = "PUS 5 Event Reporting"; eventQueue = QueueFactory::instance()->createMessageQueue(messageQueueDepth); } diff --git a/src/fsfw/pus/Service8FunctionManagement.cpp b/src/fsfw/pus/Service8FunctionManagement.cpp index c9da6d58..de0ec9cf 100644 --- a/src/fsfw/pus/Service8FunctionManagement.cpp +++ b/src/fsfw/pus/Service8FunctionManagement.cpp @@ -12,8 +12,8 @@ Service8FunctionManagement::Service8FunctionManagement(object_id_t objectId, uin uint8_t serviceId, uint8_t numParallelCommands, uint16_t commandTimeoutSeconds) - : CommandingServiceBase(objectId, apid, serviceId, numParallelCommands, commandTimeoutSeconds) { -} + : CommandingServiceBase(objectId, apid, "PUS 8 Functional Commanding", serviceId, + numParallelCommands, commandTimeoutSeconds) {} Service8FunctionManagement::~Service8FunctionManagement() {} diff --git a/src/fsfw/pus/Service9TimeManagement.cpp b/src/fsfw/pus/Service9TimeManagement.cpp index 4a26f993..6e85e709 100644 --- a/src/fsfw/pus/Service9TimeManagement.cpp +++ b/src/fsfw/pus/Service9TimeManagement.cpp @@ -5,7 +5,9 @@ #include "fsfw/serviceinterface/ServiceInterface.h" #include "fsfw/timemanager/CCSDSTime.h" -Service9TimeManagement::Service9TimeManagement(PsbParams params) : PusServiceBase(params) {} +Service9TimeManagement::Service9TimeManagement(PsbParams params) : PusServiceBase(params) { + params.name = "PUS 9 Time MGMT"; +} Service9TimeManagement::~Service9TimeManagement() = default; diff --git a/src/fsfw/tcdistribution/CcsdsDistributor.cpp b/src/fsfw/tcdistribution/CcsdsDistributor.cpp index 3a6d8729..8e6f9eeb 100644 --- a/src/fsfw/tcdistribution/CcsdsDistributor.cpp +++ b/src/fsfw/tcdistribution/CcsdsDistributor.cpp @@ -1,5 +1,6 @@ #include "fsfw/tcdistribution/CcsdsDistributor.h" +#include "definitions.h" #include "fsfw/objectmanager/ObjectManager.h" #include "fsfw/serviceinterface/ServiceInterface.h" #include "fsfw/tmtcpacket/ccsds/SpacePacketReader.h" @@ -8,11 +9,11 @@ CcsdsDistributor::CcsdsDistributor(uint16_t setDefaultApid, object_id_t setObjectId, CcsdsPacketCheckIF* packetChecker) - : TcDistributor(setObjectId), defaultApid(setDefaultApid), packetChecker(packetChecker) {} + : TcDistributorBase(setObjectId), defaultApid(setDefaultApid), packetChecker(packetChecker) {} CcsdsDistributor::~CcsdsDistributor() = default; -TcDistributor::TcMqMapIter CcsdsDistributor::selectDestination() { +ReturnValue_t CcsdsDistributor::selectDestination(MessageQueueId_t& destId) { #if CCSDS_DISTRIBUTOR_DEBUGGING == 1 #if FSFW_CPP_OSTREAM_ENABLED == 1 sif::debug << "CCSDSDistributor::selectDestination received: " @@ -39,54 +40,72 @@ TcDistributor::TcMqMapIter CcsdsDistributor::selectDestination() { " store failed!\n"); #endif #endif - return queueMap.end(); + return result; } SpacePacketReader currentPacket(packet, size); result = packetChecker->checkPacket(currentPacket, size); if (result != HasReturnvaluesIF::RETURN_OK) { + handlePacketCheckFailure(result); + return result; } #if FSFW_CPP_OSTREAM_ENABLED == 1 && CCSDS_DISTRIBUTOR_DEBUGGING == 1 sif::info << "CCSDSDistributor::selectDestination has packet with APID 0x" << std::hex << currentPacket.getApid() << std::dec << std::endl; #endif - auto position = this->queueMap.find(currentPacket.getApid()); - if (position != this->queueMap.end()) { - return position; + auto position = receiverMap.find(currentPacket.getApid()); + if (position != receiverMap.end()) { + destId = position->second.destId; } else { // The APID was not found. Forward packet to main SW-APID anyway to // create acceptance failure report. - return queueMap.find(this->defaultApid); + auto iter = receiverMap.find(defaultApid); + if (iter != receiverMap.end()) { + destId = iter->second.destId; + } else { + return DESTINATION_NOT_FOUND; + } } + return HasReturnvaluesIF::RETURN_OK; } -MessageQueueId_t CcsdsDistributor::getRequestQueue() { return tcQueue->getId(); } +void CcsdsDistributor::handlePacketCheckFailure(ReturnValue_t result) { + const char* reason = "Unknown reason"; + if (result == tcdistrib::INVALID_CCSDS_VERSION) { + reason = "Invalid CCSDS version"; + } else if (result == tcdistrib::INCOMPLETE_PACKET) { + reason = "Size missmatch between CCSDS data length and packet length"; + } else if (result == tcdistrib::INVALID_APID) { + reason = "No valid handler APID found"; + } else if (result == tcdistrib::INVALID_PACKET_TYPE) { + reason = "Invalid Packet Type TM detected"; + } +#if FSFW_VERBOSE_LEVEL >= 1 +#if FSFW_CPP_OSTREAM_ENABLED == 1 + sif::warning << "CCSDS packet check failed: " << reason << std::endl; +#else + sif::printWarning("CCSDS packet check failed: %s\n", reason); +#endif +#endif +} -ReturnValue_t CcsdsDistributor::registerApplication(AcceptsTelecommandsIF* application) { +MessageQueueId_t CcsdsDistributor::getRequestQueue() const { return tcQueue->getId(); } + +ReturnValue_t CcsdsDistributor::registerApplication(DestInfo info) { ReturnValue_t returnValue = RETURN_OK; - auto insertPair = - this->queueMap.emplace(application->getIdentifier(), application->getRequestQueue()); + auto insertPair = receiverMap.emplace(info.apid, info); if (not insertPair.second) { returnValue = RETURN_FAILED; } return returnValue; } -ReturnValue_t CcsdsDistributor::registerApplication(uint16_t apid, MessageQueueId_t id) { - ReturnValue_t returnValue = RETURN_OK; - auto insertPair = this->queueMap.emplace(apid, id); - if (not insertPair.second) { - returnValue = RETURN_FAILED; - } - return returnValue; -} - -uint32_t CcsdsDistributor::getIdentifier() { return 0; } +uint32_t CcsdsDistributor::getIdentifier() const { return 0; } ReturnValue_t CcsdsDistributor::initialize() { if (packetChecker == nullptr) { packetChecker = new CcsdsPacketChecker(ccsds::PacketType::TC); } - ReturnValue_t status = this->TcDistributor::initialize(); + ReturnValue_t status = this->TcDistributorBase::initialize(); this->tcStore = ObjectManager::instance()->get(objects::TC_STORE); if (this->tcStore == nullptr) { #if FSFW_VERBOSE_LEVEL >= 1 @@ -111,3 +130,17 @@ ReturnValue_t CcsdsDistributor::callbackAfterSending(ReturnValue_t queueStatus) } return RETURN_OK; } + +void CcsdsDistributor::print() { +#if FSFW_CPP_OSTREAM_ENABLED == 1 + sif::debug << "Distributor content is: " << std::endl << "ID\t| Message Queue ID" << std::endl; + sif::debug << std::setfill('0') << std::setw(8) << std::hex; + for (const auto& iter : receiverMap) { + sif::debug << iter.first << "\t| 0x" << iter.second.destId + << ", Header Removed: " << std::boolalpha << iter.second.removeHeader << std::endl; + } + sif::debug << std::setfill(' ') << std::dec; +#endif +} + +const char* CcsdsDistributor::getName() const { return "CCSDS Distributor"; } diff --git a/src/fsfw/tcdistribution/CcsdsDistributor.h b/src/fsfw/tcdistribution/CcsdsDistributor.h index f3af87e3..cd010ad5 100644 --- a/src/fsfw/tcdistribution/CcsdsDistributor.h +++ b/src/fsfw/tcdistribution/CcsdsDistributor.h @@ -1,11 +1,13 @@ #ifndef FRAMEWORK_TCDISTRIBUTION_CCSDSDISTRIBUTOR_H_ #define FRAMEWORK_TCDISTRIBUTION_CCSDSDISTRIBUTOR_H_ +#include + #include "fsfw/objectmanager/ObjectManagerIF.h" #include "fsfw/storagemanager/StorageManagerIF.h" #include "fsfw/tcdistribution/CcsdsDistributorIF.h" #include "fsfw/tcdistribution/CcsdsPacketChecker.h" -#include "fsfw/tcdistribution/TcDistributor.h" +#include "fsfw/tcdistribution/TcDistributorBase.h" #include "fsfw/tmtcservices/AcceptsTelecommandsIF.h" /** @@ -16,7 +18,7 @@ * The Secondary Header (with Service/Subservice) is ignored. * @ingroup tc_distribution */ -class CcsdsDistributor : public TcDistributor, +class CcsdsDistributor : public TcDistributorBase, public CcsdsDistributorIF, public AcceptsTelecommandsIF { public: @@ -35,13 +37,16 @@ class CcsdsDistributor : public TcDistributor, */ ~CcsdsDistributor() override; - MessageQueueId_t getRequestQueue() override; - ReturnValue_t registerApplication(uint16_t apid, MessageQueueId_t id) override; - ReturnValue_t registerApplication(AcceptsTelecommandsIF* application) override; - uint32_t getIdentifier() override; + MessageQueueId_t getRequestQueue() const override; + ReturnValue_t registerApplication(DestInfo info) override; + uint32_t getIdentifier() const override; ReturnValue_t initialize() override; + [[nodiscard]] const char* getName() const override; protected: + using CcsdsReceiverMap = std::map; + CcsdsReceiverMap receiverMap; + /** * This implementation checks if an application with fitting APID has * registered and forwards the packet to the according message queue. @@ -49,13 +54,16 @@ class CcsdsDistributor : public TcDistributor, * where a Acceptance Failure message should be generated. * @return Iterator to map entry of found APID or iterator to default APID. */ - TcMqMapIter selectDestination() override; + ReturnValue_t selectDestination(MessageQueueId_t& destId) override; /** * The callback here handles the generation of acceptance * success/failure messages. */ ReturnValue_t callbackAfterSending(ReturnValue_t queueStatus) override; + static void handlePacketCheckFailure(ReturnValue_t result); + + void print(); /** * The default APID, where packets with unknown APID are sent to. */ diff --git a/src/fsfw/tcdistribution/CcsdsDistributorIF.h b/src/fsfw/tcdistribution/CcsdsDistributorIF.h index d5a26bef..aee9d46d 100644 --- a/src/fsfw/tcdistribution/CcsdsDistributorIF.h +++ b/src/fsfw/tcdistribution/CcsdsDistributorIF.h @@ -1,8 +1,9 @@ #ifndef FSFW_TCDISTRIBUTION_CCSDSDISTRIBUTORIF_H_ #define FSFW_TCDISTRIBUTION_CCSDSDISTRIBUTORIF_H_ -#include "../ipc/MessageQueueSenderIF.h" -#include "../tmtcservices/AcceptsTelecommandsIF.h" +#include "fsfw/ipc/MessageQueueSenderIF.h" +#include "fsfw/tmtcservices/AcceptsTelecommandsIF.h" + /** * This is the Interface to a CCSDS Distributor. * On a CCSDS Distributor, Applications (in terms of CCSDS) may register @@ -13,24 +14,37 @@ */ class CcsdsDistributorIF { public: - /** - * With this call, a class implementing the CCSDSApplicationIF can register - * at the distributor. - * @param application A pointer to the Application to register. - * @return - @c RETURN_OK on success, - * - @c RETURN_FAILED on failure. - */ - virtual ReturnValue_t registerApplication(AcceptsTelecommandsIF* application) = 0; + struct DestInfo { + DestInfo(const char* name, uint16_t apid, MessageQueueId_t destId, bool removeHeader) + : name(name), apid(apid), destId(destId), removeHeader(removeHeader) {} + DestInfo(const char* name, AcceptsTelecommandsIF& ccsdsReceiver, bool removeHeader_) + : name(name) { + apid = ccsdsReceiver.getIdentifier(); + destId = ccsdsReceiver.getRequestQueue(); + removeHeader = removeHeader_; + } + const char* name; + uint16_t apid; + MessageQueueId_t destId; + bool removeHeader; + }; + /** * With this call, other Applications can register to the CCSDS distributor. * This is done by passing an APID and a MessageQueueId to the method. - * @param apid The APID to register. - * @param id The MessageQueueId of the message queue to send the - * TC Packets to. - * @return - @c RETURN_OK on success, - * - @c RETURN_FAILED on failure. + * @param info Contains all necessary info to register an application. + * @return + * - @c RETURN_OK on success, + * - @c RETURN_FAILED or tcdistrib error code on failure. + * - @c tcdistrib::INVALID_CCSDS_VERSION + * - @c tcdistrib::INVALID_APID No APID available to handle this packet + * - @c tcdistrib::INVALID_PACKET_TYPE Packet type TM detected + * - @c tcdistrib::INCORRECT_PRIMARY_HEADER Something other wrong with primary header + * - @c tcdistrib::INCOMPLETE_PACKET Size missmatch between data length field and actual + * length */ - virtual ReturnValue_t registerApplication(uint16_t apid, MessageQueueId_t id) = 0; + virtual ReturnValue_t registerApplication(DestInfo info) = 0; + /** * The empty virtual destructor. */ diff --git a/src/fsfw/tcdistribution/CcsdsUnpacker.cpp b/src/fsfw/tcdistribution/CcsdsUnpacker.cpp index 2f8e9f27..289f601e 100644 --- a/src/fsfw/tcdistribution/CcsdsUnpacker.cpp +++ b/src/fsfw/tcdistribution/CcsdsUnpacker.cpp @@ -3,5 +3,5 @@ CcsdsUnpacker::CcsdsUnpacker() {} ReturnValue_t CcsdsUnpacker::performOperation(uint8_t operationCode) { return 0; } -uint32_t CcsdsUnpacker::getIdentifier() { return 0; } -MessageQueueId_t CcsdsUnpacker::getRequestQueue() { return 0; } +uint32_t CcsdsUnpacker::getIdentifier() const { return 0; } +MessageQueueId_t CcsdsUnpacker::getRequestQueue() const { return 0; } diff --git a/src/fsfw/tcdistribution/CcsdsUnpacker.h b/src/fsfw/tcdistribution/CcsdsUnpacker.h index a134de33..88545311 100644 --- a/src/fsfw/tcdistribution/CcsdsUnpacker.h +++ b/src/fsfw/tcdistribution/CcsdsUnpacker.h @@ -8,8 +8,8 @@ class CcsdsUnpacker : public ExecutableObjectIF, public AcceptsTelecommandsIF { public: CcsdsUnpacker(); ReturnValue_t performOperation(uint8_t operationCode) override; - uint32_t getIdentifier() override; - MessageQueueId_t getRequestQueue() override; + uint32_t getIdentifier() const override; + MessageQueueId_t getRequestQueue() const override; private: }; diff --git a/src/fsfw/tcdistribution/CfdpDistributor.cpp b/src/fsfw/tcdistribution/CfdpDistributor.cpp index 26d7948d..abbad748 100644 --- a/src/fsfw/tcdistribution/CfdpDistributor.cpp +++ b/src/fsfw/tcdistribution/CfdpDistributor.cpp @@ -10,7 +10,7 @@ CfdpDistributor::CfdpDistributor(uint16_t setApid, object_id_t setObjectId, object_id_t setPacketSource) - : TcDistributor(setObjectId), + : TcDistributorBase(setObjectId), apid(setApid), checker(setApid), tcStatus(RETURN_FAILED), @@ -18,87 +18,89 @@ CfdpDistributor::CfdpDistributor(uint16_t setApid, object_id_t setObjectId, CfdpDistributor::~CfdpDistributor() = default; -CfdpDistributor::TcMqMapIter CfdpDistributor::selectDestination() { -#if FSFW_CFDP_DISTRIBUTOR_DEBUGGING == 1 - store_address_t storeId = this->currentMessage.getStorageId(); -#if FSFW_CPP_OSTREAM_ENABLED == 1 - sif::debug << "CFDPDistributor::handlePacket received: " << storeId.poolIndex << ", " - << storeId.packetIndex << std::endl; -#else - sif::printDebug("CFDPDistributor::handlePacket received: %d, %d\n", storeId.poolIndex, - storeId.packetIndex); -#endif -#endif - auto queueMapIt = this->queueMap.end(); - if (this->currentPacket == nullptr) { - return queueMapIt; - } - this->currentPacket->setStoreAddress(this->currentMessage.getStorageId()); - if (currentPacket->getFullData() != nullptr) { - tcStatus = checker.checkPacket(*currentPacket, currentPacket->getFullPacketLen()); - 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 - } - queueMapIt = this->queueMap.find(0); - } else { - tcStatus = PACKET_LOST; - } - - if (queueMapIt == this->queueMap.end()) { - tcStatus = DESTINATION_NOT_FOUND; -#if FSFW_VERBOSE_LEVEL >= 1 -#if FSFW_CPP_OSTREAM_ENABLED == 1 - sif::debug << "CFDPDistributor::handlePacket: Destination not found" << std::endl; -#else - sif::printDebug("CFDPDistributor::handlePacket: Destination not found\n"); -#endif /* !FSFW_CPP_OSTREAM_ENABLED == 1 */ -#endif - } - - if (tcStatus != RETURN_OK) { - return this->queueMap.end(); - } else { - return queueMapIt; - } +ReturnValue_t CfdpDistributor::selectDestination(MessageQueueId_t& destId) { + //#if FSFW_CFDP_DISTRIBUTOR_DEBUGGING == 1 + // store_address_t storeId = this->currentMessage.getStorageId(); + //#if FSFW_CPP_OSTREAM_ENABLED == 1 + // sif::debug << "CFDPDistributor::handlePacket received: " << storeId.poolIndex << ", " + // << storeId.packetIndex << std::endl; + //#else + // sif::printDebug("CFDPDistributor::handlePacket received: %d, %d\n", storeId.poolIndex, + // storeId.packetIndex); + //#endif + //#endif + // auto queueMapIt = this->queueMap.end(); + // if (this->currentPacket == nullptr) { + // return queueMapIt; + // } + // this->currentPacket->setStoreAddress(this->currentMessage.getStorageId()); + // if (currentPacket->getFullData() != nullptr) { + // tcStatus = checker.checkPacket(*currentPacket, currentPacket->getFullPacketLen()); + // 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 + // } + // queueMapIt = this->queueMap.find(0); + // } else { + // tcStatus = PACKET_LOST; + // } + // + // if (queueMapIt == this->queueMap.end()) { + // tcStatus = DESTINATION_NOT_FOUND; + //#if FSFW_VERBOSE_LEVEL >= 1 + //#if FSFW_CPP_OSTREAM_ENABLED == 1 + // sif::debug << "CFDPDistributor::handlePacket: Destination not found" << std::endl; + //#else + // sif::printDebug("CFDPDistributor::handlePacket: Destination not found\n"); + //#endif /* !FSFW_CPP_OSTREAM_ENABLED == 1 */ + //#endif + // } + // + // if (tcStatus != RETURN_OK) { + // return this->queueMap.end(); + // } else { + // return queueMapIt; + // } } 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 FSFW_CFDP_DISTRIBUTOR_DEBUGGING == 1 -#if FSFW_CPP_OSTREAM_ENABLED == 1 - sif::info << "CFDPDistributor::registerHandler: Handler ID: " << static_cast(handlerId) - << std::endl; -#else - sif::printInfo("CFDPDistributor::registerHandler: Handler ID: %d\n", static_cast(handlerId)); -#endif -#endif - 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::registerHandler: Service ID already" - " exists in map" - << std::endl; -#else - sif::printError("CFDPDistributor::registerHandler: Service ID already exists in map\n"); -#endif -#endif - return SERVICE_ID_ALREADY_EXISTS; - } + // uint16_t handlerId = + // handler->getIdentifier(); // should be 0, because CfdpHandler does not set a set a + // service-ID + //#if FSFW_CFDP_DISTRIBUTOR_DEBUGGING == 1 + //#if FSFW_CPP_OSTREAM_ENABLED == 1 + // sif::info << "CFDPDistributor::registerHandler: Handler ID: " << static_cast(handlerId) + // << std::endl; + //#else + // sif::printInfo("CFDPDistributor::registerHandler: Handler ID: %d\n", + // static_cast(handlerId)); + //#endif + //#endif + // 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::registerHandler: Service ID already" + // " exists in map" + // << std::endl; + //#else + // sif::printError("CFDPDistributor::registerHandler: Service ID already exists in map\n"); + //#endif + //#endif + // return SERVICE_ID_ALREADY_EXISTS; + // } return HasReturnvaluesIF::RETURN_OK; } -MessageQueueId_t CfdpDistributor::getRequestQueue() { return tcQueue->getId(); } +MessageQueueId_t CfdpDistributor::getRequestQueue() const { return tcQueue->getId(); } // ReturnValue_t CFDPDistributor::callbackAfterSending(ReturnValue_t queueStatus) { // if (queueStatus != RETURN_OK) { @@ -118,25 +120,25 @@ MessageQueueId_t CfdpDistributor::getRequestQueue() { return tcQueue->getId(); } // } // } -uint32_t CfdpDistributor::getIdentifier() { return this->apid; } +uint32_t CfdpDistributor::getIdentifier() const { return this->apid; } ReturnValue_t CfdpDistributor::initialize() { - currentPacket = new CfdpPacketStored(); - if (currentPacket == nullptr) { - // Should not happen, memory allocation failed! - return ObjectManagerIF::CHILD_INIT_FAILED; - } - - auto* ccsdsDistributor = ObjectManager::instance()->get(packetSource); - if (ccsdsDistributor == nullptr) { -#if FSFW_CPP_OSTREAM_ENABLED == 1 - sif::error << "CFDPDistributor::initialize: Packet source invalid" << std::endl; - sif::error << " Make sure it exists and implements CCSDSDistributorIF!" << std::endl; -#else - sif::printError("CFDPDistributor::initialize: Packet source invalid\n"); - sif::printError("Make sure it exists and implements CcsdsDistributorIF\n"); -#endif - return RETURN_FAILED; - } - return ccsdsDistributor->registerApplication(this); + // currentPacket = new CfdpPacketStored(); + // if (currentPacket == nullptr) { + // // Should not happen, memory allocation failed! + // return ObjectManagerIF::CHILD_INIT_FAILED; + // } + // + // auto* ccsdsDistributor = ObjectManager::instance()->get(packetSource); + // if (ccsdsDistributor == nullptr) { + //#if FSFW_CPP_OSTREAM_ENABLED == 1 + // sif::error << "CFDPDistributor::initialize: Packet source invalid" << std::endl; + // sif::error << " Make sure it exists and implements CCSDSDistributorIF!" << std::endl; + //#else + // sif::printError("CFDPDistributor::initialize: Packet source invalid\n"); + // sif::printError("Make sure it exists and implements CcsdsDistributorIF\n"); + //#endif + // return RETURN_FAILED; + // } + // return ccsdsDistributor->registerApplication(this); } diff --git a/src/fsfw/tcdistribution/CfdpDistributor.h b/src/fsfw/tcdistribution/CfdpDistributor.h index 7a69b3d0..7bfaee7b 100644 --- a/src/fsfw/tcdistribution/CfdpDistributor.h +++ b/src/fsfw/tcdistribution/CfdpDistributor.h @@ -8,14 +8,14 @@ #include "../tmtcservices/AcceptsTelecommandsIF.h" #include "../tmtcservices/VerificationReporter.h" #include "CfdpDistributorIF.h" -#include "TcDistributor.h" +#include "TcDistributorBase.h" /** * This class accepts CFDP Telecommands and forwards them to Application * services. * @ingroup tc_distribution */ -class CfdpDistributor : public TcDistributor, +class CfdpDistributor : public TcDistributorBase, public CfdpDistributorIF, public AcceptsTelecommandsIF { public: @@ -33,9 +33,9 @@ class CfdpDistributor : public TcDistributor, */ ~CfdpDistributor() override; ReturnValue_t registerHandler(AcceptsTelecommandsIF* handler) override; - MessageQueueId_t getRequestQueue() override; + MessageQueueId_t getRequestQueue() const override; ReturnValue_t initialize() override; - uint32_t getIdentifier() override; + uint32_t getIdentifier() const override; protected: uint16_t apid; @@ -60,7 +60,7 @@ class CfdpDistributor : public TcDistributor, * @return Iterator to map entry of found service id * or iterator to @c map.end(). */ - TcMqMapIter selectDestination() override; + ReturnValue_t selectDestination(MessageQueueId_t& destId) override; /** * The callback here handles the generation of acceptance * success/failure messages. diff --git a/src/fsfw/tcdistribution/PusDistributor.cpp b/src/fsfw/tcdistribution/PusDistributor.cpp index f8c28447..e85a6047 100644 --- a/src/fsfw/tcdistribution/PusDistributor.cpp +++ b/src/fsfw/tcdistribution/PusDistributor.cpp @@ -10,7 +10,7 @@ PusDistributor::PusDistributor(uint16_t setApid, object_id_t setObjectId, CcsdsDistributorIF* distributor, StorageManagerIF* store_) - : TcDistributor(setObjectId), + : TcDistributorBase(setObjectId), store(store_), checker(setApid, ccsds::PacketType::TC), ccsdsDistributor(distributor), @@ -18,62 +18,59 @@ PusDistributor::PusDistributor(uint16_t setApid, object_id_t setObjectId, PusDistributor::~PusDistributor() = default; -PusDistributor::TcMqMapIter PusDistributor::selectDestination() { +ReturnValue_t PusDistributor::selectDestination(MessageQueueId_t& destId) { #if FSFW_CPP_OSTREAM_ENABLED == 1 && PUS_DISTRIBUTOR_DEBUGGING == 1 store_address_t storeId = currentMessage.getStorageId(); sif::debug << "PUSDistributor::handlePacket received: " << storeId.poolIndex << ", " << storeId.packetIndex << std::endl; #endif - auto queueMapIt = queueMap.end(); // TODO: Need to set the data const uint8_t* packetPtr = nullptr; size_t packetLen = 0; - if (store->getData(currentMessage.getStorageId(), &packetPtr, &packetLen) != - HasReturnvaluesIF::RETURN_OK) { - return queueMapIt; - } - ReturnValue_t result = reader.setReadOnlyData(packetPtr, packetLen); + ReturnValue_t result = store->getData(currentMessage.getStorageId(), &packetPtr, &packetLen) != + HasReturnvaluesIF::RETURN_OK; if (result != HasReturnvaluesIF::RETURN_OK) { tcStatus = PACKET_LOST; - return queueMapIt; + return result; + } + result = reader.setReadOnlyData(packetPtr, packetLen); + if (result != HasReturnvaluesIF::RETURN_OK) { + tcStatus = PACKET_LOST; + return result; } // CRC check done by checker result = reader.parseDataWithoutCrcCheck(); if (result != HasReturnvaluesIF::RETURN_OK) { tcStatus = PACKET_LOST; - return queueMapIt; + return result; } + if (reader.getFullData() != nullptr) { tcStatus = checker.checkPacket(reader, reader.getFullPacketLen()); if (tcStatus != HasReturnvaluesIF::RETURN_OK) { checkerFailurePrinter(); } - uint32_t queue_id = reader.getService(); - queueMapIt = queueMap.find(queue_id); + uint8_t pusId = reader.getService(); + auto iter = receiverMap.find(pusId); + if (iter == receiverMap.end()) { + tcStatus = DESTINATION_NOT_FOUND; +#if FSFW_VERBOSE_LEVEL >= 1 +#if FSFW_CPP_OSTREAM_ENABLED == 1 + sif::debug << "PUSDistributor::handlePacket: Destination not found" << std::endl; +#else + sif::printDebug("PUSDistributor::handlePacket: Destination not found\n"); +#endif /* !FSFW_CPP_OSTREAM_ENABLED == 1 */ +#endif + } + destId = iter->second.destId; } else { tcStatus = PACKET_LOST; } - - if (queueMapIt == this->queueMap.end()) { - tcStatus = DESTINATION_NOT_FOUND; -#if FSFW_VERBOSE_LEVEL >= 1 -#if FSFW_CPP_OSTREAM_ENABLED == 1 - sif::debug << "PUSDistributor::handlePacket: Destination not found" << std::endl; -#else - sif::printDebug("PUSDistributor::handlePacket: Destination not found\n"); -#endif /* !FSFW_CPP_OSTREAM_ENABLED == 1 */ -#endif - } - - if (tcStatus != RETURN_OK) { - return this->queueMap.end(); - } else { - return queueMapIt; - } + return tcStatus; } -ReturnValue_t PusDistributor::registerService(AcceptsTelecommandsIF* service) { - uint16_t serviceId = service->getIdentifier(); +ReturnValue_t PusDistributor::registerService(const AcceptsTelecommandsIF& service) { + uint16_t serviceId = service.getIdentifier(); #if PUS_DISTRIBUTOR_DEBUGGING == 1 #if FSFW_CPP_OSTREAM_ENABLED == 1 sif::info << "Service ID: " << static_cast(serviceId) << std::endl; @@ -81,8 +78,8 @@ ReturnValue_t PusDistributor::registerService(AcceptsTelecommandsIF* service) { sif::printInfo("Service ID: %d\n", static_cast(serviceId)); #endif #endif - MessageQueueId_t queue = service->getRequestQueue(); - auto returnPair = queueMap.emplace(serviceId, queue); + MessageQueueId_t queue = service.getRequestQueue(); + auto returnPair = receiverMap.emplace(serviceId, ServiceInfo(service.getName(), queue)); if (not returnPair.second) { #if FSFW_VERBOSE_LEVEL >= 1 #if FSFW_CPP_OSTREAM_ENABLED == 1 @@ -98,7 +95,7 @@ ReturnValue_t PusDistributor::registerService(AcceptsTelecommandsIF* service) { return HasReturnvaluesIF::RETURN_OK; } -MessageQueueId_t PusDistributor::getRequestQueue() { return tcQueue->getId(); } +MessageQueueId_t PusDistributor::getRequestQueue() const { return tcQueue->getId(); } ReturnValue_t PusDistributor::callbackAfterSending(ReturnValue_t queueStatus) { if (queueStatus != RETURN_OK) { @@ -117,7 +114,7 @@ ReturnValue_t PusDistributor::callbackAfterSending(ReturnValue_t queueStatus) { } } -uint32_t PusDistributor::getIdentifier() { return checker.getApid(); } +uint32_t PusDistributor::getIdentifier() const { return checker.getApid(); } ReturnValue_t PusDistributor::initialize() { if (store == nullptr) { @@ -142,28 +139,30 @@ ReturnValue_t PusDistributor::initialize() { return ObjectManagerIF::CHILD_INIT_FAILED; } } - return ccsdsDistributor->registerApplication(this); + return ccsdsDistributor->registerApplication( + CcsdsDistributorIF::DestInfo(getName(), *this, false)); } void PusDistributor::checkerFailurePrinter() const { #if FSFW_VERBOSE_LEVEL >= 1 - const char* keyword = "unnamed error"; + const char* reason = "Unknown reason"; if (tcStatus == tcdistrib::INCORRECT_CHECKSUM) { - keyword = "checksum"; + reason = "Checksum Error"; } else if (tcStatus == tcdistrib::INCORRECT_PRIMARY_HEADER) { - keyword = "incorrect primary header"; + reason = "Incorrect Primary Header"; } else if (tcStatus == tcdistrib::INVALID_APID) { - keyword = "illegal APID"; + reason = "Illegal APID"; } else if (tcStatus == tcdistrib::INCORRECT_SECONDARY_HEADER) { - keyword = "incorrect secondary header"; + reason = "Incorrect Secondary Header"; } else if (tcStatus == tcdistrib::INCOMPLETE_PACKET) { - keyword = "incomplete packet"; + reason = "Incomplete packet"; } #if FSFW_CPP_OSTREAM_ENABLED == 1 - sif::warning << "PUSDistributor::handlePacket: Packet format invalid, " << keyword << " error" - << std::endl; + sif::warning << "PUSDistributor::handlePacket: Check failed: " << reason << std::endl; #else - sif::printWarning("PUSDistributor::handlePacket: Packet format invalid, %s error\n", keyword); + sif::printWarning("PUSDistributor::handlePacket: Check failed: %s\n", reason); #endif #endif } + +const char* PusDistributor::getName() const { return "PUS Distributor"; } diff --git a/src/fsfw/tcdistribution/PusDistributor.h b/src/fsfw/tcdistribution/PusDistributor.h index f9ade4e2..6b88ccad 100644 --- a/src/fsfw/tcdistribution/PusDistributor.h +++ b/src/fsfw/tcdistribution/PusDistributor.h @@ -1,9 +1,11 @@ #ifndef FSFW_TCDISTRIBUTION_PUSDISTRIBUTOR_H_ #define FSFW_TCDISTRIBUTION_PUSDISTRIBUTOR_H_ +#include + #include "PusDistributorIF.h" #include "PusPacketChecker.h" -#include "TcDistributor.h" +#include "TcDistributorBase.h" #include "fsfw/returnvalues/HasReturnvaluesIF.h" #include "fsfw/tmtcpacket/pus/tc.h" #include "fsfw/tmtcservices/AcceptsTelecommandsIF.h" @@ -17,7 +19,9 @@ class CcsdsDistributorIF; * sends acceptance success or failure messages. * @ingroup tc_distribution */ -class PusDistributor : public TcDistributor, public PusDistributorIF, public AcceptsTelecommandsIF { +class PusDistributor : public TcDistributorBase, + public PusDistributorIF, + public AcceptsTelecommandsIF { public: /** * The ctor passes @c set_apid to the checker class and calls the @@ -29,16 +33,27 @@ class PusDistributor : public TcDistributor, public PusDistributorIF, public Acc */ PusDistributor(uint16_t setApid, object_id_t setObjectId, CcsdsDistributorIF* packetSource, StorageManagerIF* store = nullptr); + [[nodiscard]] const char* getName() const override; /** * The destructor is empty. */ ~PusDistributor() override; - ReturnValue_t registerService(AcceptsTelecommandsIF* service) override; - MessageQueueId_t getRequestQueue() override; + ReturnValue_t registerService(const AcceptsTelecommandsIF& service) override; + [[nodiscard]] MessageQueueId_t getRequestQueue() const override; ReturnValue_t initialize() override; - uint32_t getIdentifier() override; + [[nodiscard]] uint32_t getIdentifier() const override; protected: + struct ServiceInfo { + ServiceInfo(const char* name, MessageQueueId_t destId) : name(name), destId(destId) {} + + const char* name; + MessageQueueId_t destId; + }; + /// PUS recipient map. The key value will generally be the PUS Service + using PusReceiverMap = std::map; + + PusReceiverMap receiverMap; StorageManagerIF* store; /** * This attribute contains the class, that performs a formal packet check. @@ -67,7 +82,7 @@ class PusDistributor : public TcDistributor, public PusDistributorIF, public Acc * @return Iterator to map entry of found service id * or iterator to @c map.end(). */ - TcMqMapIter selectDestination() override; + ReturnValue_t selectDestination(MessageQueueId_t& destId) override; /** * The callback here handles the generation of acceptance * success/failure messages. diff --git a/src/fsfw/tcdistribution/PusDistributorIF.h b/src/fsfw/tcdistribution/PusDistributorIF.h index 45a5571f..c8288cc9 100644 --- a/src/fsfw/tcdistribution/PusDistributorIF.h +++ b/src/fsfw/tcdistribution/PusDistributorIF.h @@ -20,7 +20,7 @@ class PusDistributorIF { * @return - @c RETURN_OK on success, * - @c RETURN_FAILED on failure. */ - virtual ReturnValue_t registerService(AcceptsTelecommandsIF* service) = 0; + virtual ReturnValue_t registerService(const AcceptsTelecommandsIF& service) = 0; }; #endif /* FSFW_TCDISTRIBUTION_PUSDISTRIBUTORIF_H_ */ diff --git a/src/fsfw/tcdistribution/TcDistributor.cpp b/src/fsfw/tcdistribution/TcDistributor.cpp index 4ec85ed9..2133c961 100644 --- a/src/fsfw/tcdistribution/TcDistributor.cpp +++ b/src/fsfw/tcdistribution/TcDistributor.cpp @@ -1,16 +1,14 @@ -#include "fsfw/tcdistribution/TcDistributor.h" - #include "fsfw/ipc/QueueFactory.h" -#include "fsfw/serviceinterface/ServiceInterface.h" +#include "fsfw/tcdistribution/TcDistributorBase.h" #include "fsfw/tmtcservices/TmTcMessage.h" -TcDistributor::TcDistributor(object_id_t objectId) : SystemObject(objectId) { +TcDistributorBase::TcDistributorBase(object_id_t objectId) : SystemObject(objectId) { tcQueue = QueueFactory::instance()->createMessageQueue(DISTRIBUTER_MAX_PACKETS); } -TcDistributor::~TcDistributor() { QueueFactory::instance()->deleteMessageQueue(tcQueue); } +TcDistributorBase::~TcDistributorBase() { QueueFactory::instance()->deleteMessageQueue(tcQueue); } -ReturnValue_t TcDistributor::performOperation(uint8_t opCode) { +ReturnValue_t TcDistributorBase::performOperation(uint8_t opCode) { ReturnValue_t status; for (status = tcQueue->receiveMessage(¤tMessage); status == RETURN_OK; status = tcQueue->receiveMessage(¤tMessage)) { @@ -22,24 +20,16 @@ ReturnValue_t TcDistributor::performOperation(uint8_t opCode) { return status; } -ReturnValue_t TcDistributor::handlePacket() { - auto queueMapIt = selectDestination(); - ReturnValue_t result = HasReturnvaluesIF::RETURN_FAILED; - if (queueMapIt != queueMap.end()) { - result = tcQueue->sendMessage(queueMapIt->second, ¤tMessage); +ReturnValue_t TcDistributorBase::handlePacket() { + MessageQueueId_t destId; + ReturnValue_t result = selectDestination(destId); + if (result != HasReturnvaluesIF::RETURN_OK) { + return result; } + result = tcQueue->sendMessage(destId, ¤tMessage); return callbackAfterSending(result); } -void TcDistributor::print() { -#if FSFW_CPP_OSTREAM_ENABLED == 1 - sif::debug << "Distributor content is: " << std::endl << "ID\t| Message Queue ID" << std::endl; - sif::debug << std::setfill('0') << std::setw(8) << std::hex; - for (const auto& queueMapIter : queueMap) { - sif::debug << queueMapIter.first << "\t| 0x" << queueMapIter.second << std::endl; - } - sif::debug << std::setfill(' ') << std::dec; -#endif +ReturnValue_t TcDistributorBase::callbackAfterSending(ReturnValue_t queueStatus) { + return RETURN_OK; } - -ReturnValue_t TcDistributor::callbackAfterSending(ReturnValue_t queueStatus) { return RETURN_OK; } diff --git a/src/fsfw/tcdistribution/TcDistributor.h b/src/fsfw/tcdistribution/TcDistributorBase.h similarity index 83% rename from src/fsfw/tcdistribution/TcDistributor.h rename to src/fsfw/tcdistribution/TcDistributorBase.h index e9e1fc97..c1fd4531 100644 --- a/src/fsfw/tcdistribution/TcDistributor.h +++ b/src/fsfw/tcdistribution/TcDistributorBase.h @@ -27,11 +27,8 @@ * implementations. * @ingroup tc_distribution */ -class TcDistributor : public SystemObject, public ExecutableObjectIF, public HasReturnvaluesIF { +class TcDistributorBase : public SystemObject, public ExecutableObjectIF, public HasReturnvaluesIF { public: - using TcMessageQueueMap = std::map; - using TcMqMapIter = std::map::iterator; - static constexpr uint8_t INTERFACE_ID = CLASS_ID::PACKET_DISTRIBUTION; static constexpr ReturnValue_t PACKET_LOST = MAKE_RETURN_CODE(1); static constexpr ReturnValue_t DESTINATION_NOT_FOUND = MAKE_RETURN_CODE(2); @@ -43,12 +40,12 @@ class TcDistributor : public SystemObject, public ExecutableObjectIF, public Has * @param set_object_id This id is assigned to the distributor * implementation. */ - explicit TcDistributor(object_id_t objectId); + explicit TcDistributorBase(object_id_t objectId); /** * The destructor is empty, the message queues are not in the vicinity of * this class. */ - ~TcDistributor() override; + ~TcDistributorBase() override; /** * The method is called cyclically and fetches new incoming packets from * the message queue. @@ -57,11 +54,6 @@ class TcDistributor : public SystemObject, public ExecutableObjectIF, public Has * @return The error code of the message queue call. */ ReturnValue_t performOperation(uint8_t opCode) override; - /** - * A simple debug print, that prints all distribution information stored in - * queueMap. - */ - void print(); protected: /** @@ -77,19 +69,13 @@ class TcDistributor : public SystemObject, public ExecutableObjectIF, public Has * is not tried to unpack the packet information within this class. */ TmTcMessage currentMessage; - /** - * The map that links certain packet information to a destination. - * The packet information may be the APID of the packet or the service - * identifier. Filling of the map is under control of the different child - * classes. - */ - TcMessageQueueMap queueMap; + /** * This method shall unpack the routing information from the incoming * packet and select the map entry which represents the packet's target. * @return An iterator to the map element to forward to or queuMap.end(). */ - virtual TcMqMapIter selectDestination() = 0; + virtual ReturnValue_t selectDestination(MessageQueueId_t& destId) = 0; /** * The handlePacket method calls the child class's selectDestination method * and forwards the packet to its destination, if found. diff --git a/src/fsfw/tmtcservices/AcceptsTelecommandsIF.h b/src/fsfw/tmtcservices/AcceptsTelecommandsIF.h index a0fb23d1..6c214b0f 100644 --- a/src/fsfw/tmtcservices/AcceptsTelecommandsIF.h +++ b/src/fsfw/tmtcservices/AcceptsTelecommandsIF.h @@ -21,6 +21,8 @@ class AcceptsTelecommandsIF { * @brief The virtual destructor as it is mandatory for C++ interfaces. */ virtual ~AcceptsTelecommandsIF() = default; + [[nodiscard]] virtual const char* getName() const = 0; + /** * @brief Getter for a generic identifier ID. * @details Any receiving service (at least any PUS service) shall have an identifier. For @@ -28,13 +30,13 @@ class AcceptsTelecommandsIF { * service for a component expecting specific PUS service packets. * @return The identifier. */ - virtual uint32_t getIdentifier() = 0; + [[nodiscard]] virtual uint32_t getIdentifier() const = 0; /** * @brief This method returns the message queue id of the telecommand * receiving message queue. * @return The telecommand reception message queue id. */ - virtual MessageQueueId_t getRequestQueue() = 0; + [[nodiscard]] virtual MessageQueueId_t getRequestQueue() const = 0; }; #endif /* FRAMEWORK_TMTCSERVICES_ACCEPTSTELECOMMANDSIF_H_ */ diff --git a/src/fsfw/tmtcservices/CommandingServiceBase.cpp b/src/fsfw/tmtcservices/CommandingServiceBase.cpp index fc9c0685..b13c22b6 100644 --- a/src/fsfw/tmtcservices/CommandingServiceBase.cpp +++ b/src/fsfw/tmtcservices/CommandingServiceBase.cpp @@ -14,7 +14,8 @@ object_id_t CommandingServiceBase::defaultPacketSource = objects::NO_OBJECT; object_id_t CommandingServiceBase::defaultPacketDestination = objects::NO_OBJECT; CommandingServiceBase::CommandingServiceBase(object_id_t setObjectId, uint16_t apid, - uint8_t service, uint8_t numberOfParallelCommands, + const char* name, uint8_t service, + uint8_t numberOfParallelCommands, uint16_t commandTimeoutSeconds, size_t queueDepth, VerificationReporterIF* verificationReporter) : SystemObject(setObjectId), @@ -24,7 +25,8 @@ CommandingServiceBase::CommandingServiceBase(object_id_t setObjectId, uint16_t a tmStoreHelper(apid), tmHelper(service, tmStoreHelper, tmSendHelper), verificationReporter(verificationReporter), - commandMap(numberOfParallelCommands) { + commandMap(numberOfParallelCommands), + name(name) { commandQueue = QueueFactory::instance()->createMessageQueue(queueDepth); requestQueue = QueueFactory::instance()->createMessageQueue(queueDepth); } @@ -50,9 +52,9 @@ ReturnValue_t CommandingServiceBase::performOperation(uint8_t opCode) { return RETURN_OK; } -uint32_t CommandingServiceBase::getIdentifier() { return service; } +uint32_t CommandingServiceBase::getIdentifier() const { return service; } -MessageQueueId_t CommandingServiceBase::getRequestQueue() { return requestQueue->getId(); } +MessageQueueId_t CommandingServiceBase::getRequestQueue() const { return requestQueue->getId(); } ReturnValue_t CommandingServiceBase::initialize() { ReturnValue_t result = SystemObject::initialize(); @@ -79,7 +81,7 @@ ReturnValue_t CommandingServiceBase::initialize() { return ObjectManagerIF::CHILD_INIT_FAILED; } - distributor->registerService(this); + distributor->registerService(*this); requestQueue->setDefaultDestination(packetForwarding->getReportReceptionQueue()); ipcStore = ObjectManager::instance()->get(objects::IPC_STORE); @@ -489,3 +491,5 @@ void CommandingServiceBase::prepareVerificationSuccessWithFullInfo( successParams.tcPsc = tcInfo.tcSequenceControl; successParams.ackFlags = tcInfo.ackFlags; } + +const char* CommandingServiceBase::getName() const { return name; } diff --git a/src/fsfw/tmtcservices/CommandingServiceBase.h b/src/fsfw/tmtcservices/CommandingServiceBase.h index 07f7179a..3346939c 100644 --- a/src/fsfw/tmtcservices/CommandingServiceBase.h +++ b/src/fsfw/tmtcservices/CommandingServiceBase.h @@ -76,7 +76,7 @@ class CommandingServiceBase : public SystemObject, * @param setPacketDestination * @param queueDepth */ - CommandingServiceBase(object_id_t setObjectId, uint16_t apid, uint8_t service, + CommandingServiceBase(object_id_t setObjectId, uint16_t apid, const char* name, uint8_t service, uint8_t numberOfParallelCommands, uint16_t commandTimeoutSeconds, size_t queueDepth = 20, VerificationReporterIF* reporter = nullptr); ~CommandingServiceBase() override; @@ -106,7 +106,7 @@ class CommandingServiceBase : public SystemObject, */ ReturnValue_t performOperation(uint8_t opCode) override; - uint32_t getIdentifier() override; + uint32_t getIdentifier() const override; /** * Returns the requestQueue MessageQueueId_t @@ -115,7 +115,7 @@ class CommandingServiceBase : public SystemObject, * * @return requestQueue messageQueueId_t */ - MessageQueueId_t getRequestQueue() override; + MessageQueueId_t getRequestQueue() const override; /** * Returns the commandQueue MessageQueueId_t @@ -134,6 +134,7 @@ class CommandingServiceBase : public SystemObject, * @param task Pointer to the taskIF of this task */ void setTaskIF(PeriodicTaskIF* task) override; + const char* getName() const override; protected: /** @@ -284,6 +285,8 @@ class CommandingServiceBase : public SystemObject, uint32_t failureParameter1 = 0; uint32_t failureParameter2 = 0; + const char* name = ""; + static object_id_t defaultPacketSource; object_id_t packetSource = objects::NO_OBJECT; static object_id_t defaultPacketDestination; diff --git a/src/fsfw/tmtcservices/PusServiceBase.cpp b/src/fsfw/tmtcservices/PusServiceBase.cpp index d777d03e..8fc340f4 100644 --- a/src/fsfw/tmtcservices/PusServiceBase.cpp +++ b/src/fsfw/tmtcservices/PusServiceBase.cpp @@ -82,9 +82,9 @@ void PusServiceBase::handleRequestQueue() { } } -uint32_t PusServiceBase::getIdentifier() { return psbParams.serviceId; } +uint32_t PusServiceBase::getIdentifier() const { return psbParams.serviceId; } -MessageQueueId_t PusServiceBase::getRequestQueue() { +MessageQueueId_t PusServiceBase::getRequestQueue() const { if (psbParams.reqQueue == nullptr) { return MessageQueueIF::NO_QUEUE; } @@ -194,7 +194,7 @@ void PusServiceBase::setVerificationReporter(VerificationReporterIF& reporter) { } ReturnValue_t PusServiceBase::registerService(PusDistributorIF& distributor) { - return distributor.registerService(this); + return distributor.registerService(*this); } void PusServiceBase::setTmReceiver(AcceptsTelemetryIF& tmReceiver_) { @@ -202,3 +202,5 @@ void PusServiceBase::setTmReceiver(AcceptsTelemetryIF& tmReceiver_) { } void PusServiceBase::setRequestQueue(MessageQueueIF& reqQueue) { psbParams.reqQueue = &reqQueue; } + +const char* PusServiceBase::getName() const { return psbParams.name; } diff --git a/src/fsfw/tmtcservices/PusServiceBase.h b/src/fsfw/tmtcservices/PusServiceBase.h index 34483fe7..4622b175 100644 --- a/src/fsfw/tmtcservices/PusServiceBase.h +++ b/src/fsfw/tmtcservices/PusServiceBase.h @@ -22,9 +22,13 @@ class StorageManagerIF; struct PsbParams { PsbParams() = default; PsbParams(uint16_t apid, AcceptsTelemetryIF* tmReceiver) : apid(apid), tmReceiver(tmReceiver) {} + PsbParams(const char* name, uint16_t apid, AcceptsTelemetryIF* tmReceiver) + : name(name), apid(apid), tmReceiver(tmReceiver) {} PsbParams(object_id_t objectId, uint16_t apid, uint8_t serviceId) : objectId(objectId), apid(apid), serviceId(serviceId) {} - + PsbParams(const char* name, object_id_t objectId, uint16_t apid, uint8_t serviceId) + : name(name), objectId(objectId), apid(apid), serviceId(serviceId) {} + const char* name = ""; object_id_t objectId = objects::NO_OBJECT; uint16_t apid = 0; uint8_t serviceId = 0; @@ -188,11 +192,12 @@ class PusServiceBase : public ExecutableObjectIF, * @c RETURN_FAILED else. */ ReturnValue_t performOperation(uint8_t opCode) override; - uint32_t getIdentifier() override; - MessageQueueId_t getRequestQueue() override; + uint32_t getIdentifier() const override; + MessageQueueId_t getRequestQueue() const override; ReturnValue_t initialize() override; void setTaskIF(PeriodicTaskIF* taskHandle) override; + [[nodiscard]] const char* getName() const override; protected: /** @@ -201,6 +206,7 @@ class PusServiceBase : public ExecutableObjectIF, * Will be set by setTaskIF(), which is called on task creation. */ PeriodicTaskIF* taskHandle = nullptr; + /** * One of two error parameters for additional error information. */ diff --git a/src/fsfw/tmtcservices/TmTcBridge.cpp b/src/fsfw/tmtcservices/TmTcBridge.cpp index 7190d771..d1569af5 100644 --- a/src/fsfw/tmtcservices/TmTcBridge.cpp +++ b/src/fsfw/tmtcservices/TmTcBridge.cpp @@ -7,9 +7,10 @@ #define TMTCBRIDGE_WIRETAPPING 0 -TmTcBridge::TmTcBridge(object_id_t objectId, object_id_t tcDestination, object_id_t tmStoreId, - object_id_t tcStoreId) +TmTcBridge::TmTcBridge(const char* name, object_id_t objectId, object_id_t tcDestination, + object_id_t tmStoreId, object_id_t tcStoreId) : SystemObject(objectId), + name(name), tmStoreId(tmStoreId), tcStoreId(tcStoreId), tcDestination(tcDestination) @@ -67,8 +68,7 @@ ReturnValue_t TmTcBridge::initialize() { #endif return ObjectManagerIF::CHILD_INIT_FAILED; } - AcceptsTelecommandsIF* tcDistributor = - ObjectManager::instance()->get(tcDestination); + auto* tcDistributor = ObjectManager::instance()->get(tcDestination); if (tcDistributor == nullptr) { #if FSFW_CPP_OSTREAM_ENABLED == 1 sif::error << "TmTcBridge::initialize: TC Distributor invalid" << std::endl; @@ -247,14 +247,16 @@ MessageQueueId_t TmTcBridge::getReportReceptionQueue(uint8_t virtualChannel) { void TmTcBridge::printData(uint8_t* data, size_t dataLen) { arrayprinter::print(data, dataLen); } -uint32_t TmTcBridge::getIdentifier() { +uint32_t TmTcBridge::getIdentifier() const { // This is no PUS service, so we just return 0 return 0; } -MessageQueueId_t TmTcBridge::getRequestQueue() { +MessageQueueId_t TmTcBridge::getRequestQueue() const { // Default implementation: Relay TC messages to TC distributor directly. return tmTcReceptionQueue->getDefaultDestination(); } void TmTcBridge::setFifoToOverwriteOldData(bool overwriteOld) { this->overwriteOld = overwriteOld; } + +const char* TmTcBridge::getName() const { return name; } diff --git a/src/fsfw/tmtcservices/TmTcBridge.h b/src/fsfw/tmtcservices/TmTcBridge.h index c4bc4062..e0535585 100644 --- a/src/fsfw/tmtcservices/TmTcBridge.h +++ b/src/fsfw/tmtcservices/TmTcBridge.h @@ -23,9 +23,9 @@ class TmTcBridge : public AcceptsTelemetryIF, static constexpr uint8_t DEFAULT_STORED_DATA_SENT_PER_CYCLE = 5; static constexpr uint8_t DEFAULT_DOWNLINK_PACKETS_STORED = 10; - TmTcBridge(object_id_t objectId, object_id_t tcDestination, object_id_t tmStoreId, - object_id_t tcStoreId); - virtual ~TmTcBridge(); + TmTcBridge(const char* name, object_id_t objectId, object_id_t tcDestination, + object_id_t tmStoreId, object_id_t tcStoreId); + ~TmTcBridge() override; /** * Set number of packets sent per performOperation().Please note that this @@ -58,21 +58,24 @@ class TmTcBridge : public AcceptsTelemetryIF, * Initializes necessary FSFW components for the TMTC Bridge * @return */ - virtual ReturnValue_t initialize() override; + ReturnValue_t initialize() override; /** * @brief Handles TMTC reception */ - virtual ReturnValue_t performOperation(uint8_t operationCode = 0) override; + ReturnValue_t performOperation(uint8_t operationCode = 0) override; /** AcceptsTelemetryIF override */ - virtual MessageQueueId_t getReportReceptionQueue(uint8_t virtualChannel = 0) override; + MessageQueueId_t getReportReceptionQueue(uint8_t virtualChannel = 0) override; /** AcceptsTelecommandsIF override */ - virtual uint32_t getIdentifier() override; - virtual MessageQueueId_t getRequestQueue() override; + uint32_t getIdentifier() const override; + MessageQueueId_t getRequestQueue() const override; + const char* getName() const override; protected: + const char* name = ""; + //! Cached for initialize function. object_id_t tmStoreId = objects::NO_OBJECT; object_id_t tcStoreId = objects::NO_OBJECT; From 4334106ad12b02323ed0b99a1b48e93e0306834f Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Mon, 1 Aug 2022 11:05:46 +0200 Subject: [PATCH 006/169] applied auto-formatter --- src/fsfw/tcdistribution/CMakeLists.txt | 2 +- .../{TcDistributor.cpp => TcDistributorBase.cpp} | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) rename src/fsfw/tcdistribution/{TcDistributor.cpp => TcDistributorBase.cpp} (99%) diff --git a/src/fsfw/tcdistribution/CMakeLists.txt b/src/fsfw/tcdistribution/CMakeLists.txt index 2d1a74f6..5501f4af 100644 --- a/src/fsfw/tcdistribution/CMakeLists.txt +++ b/src/fsfw/tcdistribution/CMakeLists.txt @@ -2,7 +2,7 @@ target_sources( ${LIB_FSFW_NAME} PRIVATE CcsdsDistributor.cpp PusDistributor.cpp - TcDistributor.cpp + TcDistributorBase.cpp PusPacketChecker.cpp TcPacketCheckCFDP.cpp CfdpDistributor.cpp diff --git a/src/fsfw/tcdistribution/TcDistributor.cpp b/src/fsfw/tcdistribution/TcDistributorBase.cpp similarity index 99% rename from src/fsfw/tcdistribution/TcDistributor.cpp rename to src/fsfw/tcdistribution/TcDistributorBase.cpp index 2133c961..70388b99 100644 --- a/src/fsfw/tcdistribution/TcDistributor.cpp +++ b/src/fsfw/tcdistribution/TcDistributorBase.cpp @@ -1,5 +1,6 @@ -#include "fsfw/ipc/QueueFactory.h" #include "fsfw/tcdistribution/TcDistributorBase.h" + +#include "fsfw/ipc/QueueFactory.h" #include "fsfw/tmtcservices/TmTcMessage.h" TcDistributorBase::TcDistributorBase(object_id_t objectId) : SystemObject(objectId) { From bf540ebb4967dfac1e0fb08789e39a5c6ded5fb7 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Mon, 1 Aug 2022 14:23:52 +0200 Subject: [PATCH 007/169] use sanitized include file --- src/fsfw/datapoollocal/HasLocalDataPoolIF.h | 8 ++--- .../serviceinterface/ServiceInterfaceBuffer.h | 4 +-- .../serviceinterface/ServiceInterfaceStream.h | 2 +- src/fsfw/tcdistribution/CcsdsDistributor.cpp | 31 +++++++++++++++---- src/fsfw/tcdistribution/CcsdsDistributor.h | 5 +-- src/fsfw/tcdistribution/CcsdsDistributorIF.h | 2 +- src/fsfw/tcdistribution/CcsdsUnpacker.cpp | 2 +- src/fsfw/tcdistribution/TcDistributorBase.h | 7 +++-- unittests/CatchDefinitions.cpp | 1 + unittests/CatchDefinitions.h | 1 + unittests/CatchSetup.cpp | 1 + unittests/mocks/PusDistributorMock.cpp | 4 +-- unittests/mocks/PusDistributorMock.h | 6 ++-- .../PollingSequenceFactory.cpp | 3 +- unittests/tmtcservices/testPsb.cpp | 2 +- 15 files changed, 53 insertions(+), 26 deletions(-) diff --git a/src/fsfw/datapoollocal/HasLocalDataPoolIF.h b/src/fsfw/datapoollocal/HasLocalDataPoolIF.h index b7a6198e..b987e760 100644 --- a/src/fsfw/datapoollocal/HasLocalDataPoolIF.h +++ b/src/fsfw/datapoollocal/HasLocalDataPoolIF.h @@ -3,10 +3,10 @@ #include -#include "../datapool/PoolEntryIF.h" -#include "../housekeeping/HousekeepingMessage.h" -#include "../ipc/MessageQueueSenderIF.h" -#include "../serviceinterface/ServiceInterface.h" +#include "fsfw/datapool/PoolEntryIF.h" +#include "fsfw/housekeeping/HousekeepingMessage.h" +#include "fsfw/ipc/MessageQueueSenderIF.h" +#include "fsfw/serviceinterface.h" #include "LocalDataPoolManager.h" #include "localPoolDefinitions.h" diff --git a/src/fsfw/serviceinterface/ServiceInterfaceBuffer.h b/src/fsfw/serviceinterface/ServiceInterfaceBuffer.h index 9cda75c6..6832e809 100644 --- a/src/fsfw/serviceinterface/ServiceInterfaceBuffer.h +++ b/src/fsfw/serviceinterface/ServiceInterfaceBuffer.h @@ -1,9 +1,9 @@ #ifndef FRAMEWORK_SERVICEINTERFACE_SERVICEINTERFACEBUFFER_H_ #define FRAMEWORK_SERVICEINTERFACE_SERVICEINTERFACEBUFFER_H_ -#include +#include "fsfw/FSFW.h" -#include "../returnvalues/HasReturnvaluesIF.h" +#include "fsfw/returnvalues/HasReturnvaluesIF.h" #if FSFW_CPP_OSTREAM_ENABLED == 1 diff --git a/src/fsfw/serviceinterface/ServiceInterfaceStream.h b/src/fsfw/serviceinterface/ServiceInterfaceStream.h index 0b3d6745..bf3424a6 100644 --- a/src/fsfw/serviceinterface/ServiceInterfaceStream.h +++ b/src/fsfw/serviceinterface/ServiceInterfaceStream.h @@ -1,7 +1,7 @@ #ifndef FRAMEWORK_SERVICEINTERFACE_SERVICEINTERFACESTREAM_H_ #define FRAMEWORK_SERVICEINTERFACE_SERVICEINTERFACESTREAM_H_ -#include +#include "fsfw/FSFW.h" #include "ServiceInterfaceBuffer.h" diff --git a/src/fsfw/tcdistribution/CcsdsDistributor.cpp b/src/fsfw/tcdistribution/CcsdsDistributor.cpp index 8e6f9eeb..816d3037 100644 --- a/src/fsfw/tcdistribution/CcsdsDistributor.cpp +++ b/src/fsfw/tcdistribution/CcsdsDistributor.cpp @@ -1,3 +1,4 @@ +#include "fsfw/FSFW.h" #include "fsfw/tcdistribution/CcsdsDistributor.h" #include "definitions.h" @@ -9,7 +10,9 @@ CcsdsDistributor::CcsdsDistributor(uint16_t setDefaultApid, object_id_t setObjectId, CcsdsPacketCheckIF* packetChecker) - : TcDistributorBase(setObjectId), defaultApid(setDefaultApid), packetChecker(packetChecker) {} + : TcDistributorBase(setObjectId), + defaultApid(setDefaultApid), + packetChecker(packetChecker) {} CcsdsDistributor::~CcsdsDistributor() = default; @@ -52,13 +55,16 @@ ReturnValue_t CcsdsDistributor::selectDestination(MessageQueueId_t& destId) { sif::info << "CCSDSDistributor::selectDestination has packet with APID 0x" << std::hex << currentPacket.getApid() << std::dec << std::endl; #endif - auto position = receiverMap.find(currentPacket.getApid()); - if (position != receiverMap.end()) { - destId = position->second.destId; + auto iter = receiverMap.find(currentPacket.getApid()); + if (iter != receiverMap.end()) { + destId = iter->second.destId; + if (iter->second.removeHeader) { + handleCcsdsHeaderRemoval(); + } } else { // The APID was not found. Forward packet to main SW-APID anyway to // create acceptance failure report. - auto iter = receiverMap.find(defaultApid); + iter = receiverMap.find(defaultApid); if (iter != receiverMap.end()) { destId = iter->second.destId; } else { @@ -69,6 +75,7 @@ ReturnValue_t CcsdsDistributor::selectDestination(MessageQueueId_t& destId) { } void CcsdsDistributor::handlePacketCheckFailure(ReturnValue_t result) { +#if FSFW_VERBOSE_LEVEL >= 1 const char* reason = "Unknown reason"; if (result == tcdistrib::INVALID_CCSDS_VERSION) { reason = "Invalid CCSDS version"; @@ -79,7 +86,6 @@ void CcsdsDistributor::handlePacketCheckFailure(ReturnValue_t result) { } else if (result == tcdistrib::INVALID_PACKET_TYPE) { reason = "Invalid Packet Type TM detected"; } -#if FSFW_VERBOSE_LEVEL >= 1 #if FSFW_CPP_OSTREAM_ENABLED == 1 sif::warning << "CCSDS packet check failed: " << reason << std::endl; #else @@ -144,3 +150,16 @@ void CcsdsDistributor::print() { } const char* CcsdsDistributor::getName() const { return "CCSDS Distributor"; } + +ReturnValue_t CcsdsDistributor::handleCcsdsHeaderRemoval() { + currentMessage; + auto accessorPair = tcStore->getData(currentMessage.getStorageId()); + if(accessorPair.first != HasReturnvaluesIF::RETURN_OK) { +#if FSFW_CPP_OSTREAM_ENABLED == 1 + sif::error << __func__ << ": Getting TC data failed" << std::endl; +#else + sif::printError("%s: Getting TC data failed\n", __func__); +#endif + return accessorPair.first; + } +} diff --git a/src/fsfw/tcdistribution/CcsdsDistributor.h b/src/fsfw/tcdistribution/CcsdsDistributor.h index cd010ad5..542625eb 100644 --- a/src/fsfw/tcdistribution/CcsdsDistributor.h +++ b/src/fsfw/tcdistribution/CcsdsDistributor.h @@ -37,9 +37,9 @@ class CcsdsDistributor : public TcDistributorBase, */ ~CcsdsDistributor() override; - MessageQueueId_t getRequestQueue() const override; + [[nodiscard]] MessageQueueId_t getRequestQueue() const override; ReturnValue_t registerApplication(DestInfo info) override; - uint32_t getIdentifier() const override; + [[nodiscard]] uint32_t getIdentifier() const override; ReturnValue_t initialize() override; [[nodiscard]] const char* getName() const override; @@ -63,6 +63,7 @@ class CcsdsDistributor : public TcDistributorBase, static void handlePacketCheckFailure(ReturnValue_t result); + ReturnValue_t handleCcsdsHeaderRemoval(); void print(); /** * The default APID, where packets with unknown APID are sent to. diff --git a/src/fsfw/tcdistribution/CcsdsDistributorIF.h b/src/fsfw/tcdistribution/CcsdsDistributorIF.h index aee9d46d..7e7a586d 100644 --- a/src/fsfw/tcdistribution/CcsdsDistributorIF.h +++ b/src/fsfw/tcdistribution/CcsdsDistributorIF.h @@ -17,7 +17,7 @@ class CcsdsDistributorIF { struct DestInfo { DestInfo(const char* name, uint16_t apid, MessageQueueId_t destId, bool removeHeader) : name(name), apid(apid), destId(destId), removeHeader(removeHeader) {} - DestInfo(const char* name, AcceptsTelecommandsIF& ccsdsReceiver, bool removeHeader_) + DestInfo(const char* name, const AcceptsTelecommandsIF& ccsdsReceiver, bool removeHeader_) : name(name) { apid = ccsdsReceiver.getIdentifier(); destId = ccsdsReceiver.getRequestQueue(); diff --git a/src/fsfw/tcdistribution/CcsdsUnpacker.cpp b/src/fsfw/tcdistribution/CcsdsUnpacker.cpp index d3524c17..42a7cd28 100644 --- a/src/fsfw/tcdistribution/CcsdsUnpacker.cpp +++ b/src/fsfw/tcdistribution/CcsdsUnpacker.cpp @@ -55,6 +55,6 @@ ReturnValue_t CcsdsUnpacker::performOperation(uint8_t operationCode) { void CcsdsUnpacker::setDifferentTargetStore(StorageManagerIF& otherTargetStore) { targetStore = &otherTargetStore; } -ReturnValue_t CcsdsUnpacker::performOperation(uint8_t operationCode) { return 0; } + uint32_t CcsdsUnpacker::getIdentifier() const { return 0; } MessageQueueId_t CcsdsUnpacker::getRequestQueue() const { return 0; } diff --git a/src/fsfw/tcdistribution/TcDistributorBase.h b/src/fsfw/tcdistribution/TcDistributorBase.h index c1fd4531..08b72823 100644 --- a/src/fsfw/tcdistribution/TcDistributorBase.h +++ b/src/fsfw/tcdistribution/TcDistributorBase.h @@ -65,15 +65,16 @@ class TcDistributorBase : public SystemObject, public ExecutableObjectIF, public * The last received incoming packet information is stored in this * member. * As different child classes unpack the incoming packet differently - * (i.e. as a CCSDS Space Packet or as a PUS Telecommand Packet), it - * is not tried to unpack the packet information within this class. + * (i.e. as a CCSDS Space Packet or as a PUS Telecommand Packet), no unpacking will be + * done in this class. */ TmTcMessage currentMessage; /** * This method shall unpack the routing information from the incoming * packet and select the map entry which represents the packet's target. - * @return An iterator to the map element to forward to or queuMap.end(). + * @return + * - @c RETURN_OK if a desitnation was selected successfully */ virtual ReturnValue_t selectDestination(MessageQueueId_t& destId) = 0; /** diff --git a/unittests/CatchDefinitions.cpp b/unittests/CatchDefinitions.cpp index 85e3aad0..15ff1de9 100644 --- a/unittests/CatchDefinitions.cpp +++ b/unittests/CatchDefinitions.cpp @@ -1,3 +1,4 @@ +#include "fsfw/FSFW.h" #include "CatchDefinitions.h" #include diff --git a/unittests/CatchDefinitions.h b/unittests/CatchDefinitions.h index dbe3848b..be49e6e8 100644 --- a/unittests/CatchDefinitions.h +++ b/unittests/CatchDefinitions.h @@ -1,6 +1,7 @@ #ifndef FSFW_UNITTEST_CORE_CATCHDEFINITIONS_H_ #define FSFW_UNITTEST_CORE_CATCHDEFINITIONS_H_ +#include "fsfw/FSFW.h" #include #include #include diff --git a/unittests/CatchSetup.cpp b/unittests/CatchSetup.cpp index 9206c2e1..848af5e7 100644 --- a/unittests/CatchSetup.cpp +++ b/unittests/CatchSetup.cpp @@ -1,3 +1,4 @@ +#include "fsfw/FSFW.h" #include "CatchDefinitions.h" #include "CatchFactory.h" diff --git a/unittests/mocks/PusDistributorMock.cpp b/unittests/mocks/PusDistributorMock.cpp index cb9aed32..6dbba967 100644 --- a/unittests/mocks/PusDistributorMock.cpp +++ b/unittests/mocks/PusDistributorMock.cpp @@ -5,8 +5,8 @@ PusDistributorMock::PusDistributorMock() : SystemObject(objects::NO_OBJECT, fals PusDistributorMock::PusDistributorMock(object_id_t registeredId) : SystemObject(registeredId, true) {} -ReturnValue_t PusDistributorMock::registerService(AcceptsTelecommandsIF *service) { +ReturnValue_t PusDistributorMock::registerService(const AcceptsTelecommandsIF& service) { registerCallCount++; - lastServiceArg = service; + registeredServies.push_back(&service); return HasReturnvaluesIF::RETURN_OK; } diff --git a/unittests/mocks/PusDistributorMock.h b/unittests/mocks/PusDistributorMock.h index e19820f3..d85030c9 100644 --- a/unittests/mocks/PusDistributorMock.h +++ b/unittests/mocks/PusDistributorMock.h @@ -4,13 +4,15 @@ #include "fsfw/objectmanager/SystemObject.h" #include "fsfw/tcdistribution/PusDistributorIF.h" +#include + class PusDistributorMock : public SystemObject, public PusDistributorIF { public: PusDistributorMock(); explicit PusDistributorMock(object_id_t registeredId); unsigned int registerCallCount = 0; - AcceptsTelecommandsIF* lastServiceArg = nullptr; - ReturnValue_t registerService(AcceptsTelecommandsIF* service) override; + std::vector registeredServies; + ReturnValue_t registerService(const AcceptsTelecommandsIF& service) override; }; #endif // FSFW_TESTS_PUSDISTRIBUTORMOCK_H diff --git a/unittests/testcfg/pollingsequence/PollingSequenceFactory.cpp b/unittests/testcfg/pollingsequence/PollingSequenceFactory.cpp index 0c44f6a2..34a8cfbd 100644 --- a/unittests/testcfg/pollingsequence/PollingSequenceFactory.cpp +++ b/unittests/testcfg/pollingsequence/PollingSequenceFactory.cpp @@ -1,3 +1,4 @@ +#include "fsfw/FSFW.h" #include "PollingSequenceFactory.h" #include @@ -20,7 +21,7 @@ ReturnValue_t pst::pollingSequenceInitDefault(FixedTimeslotTaskIF *thisSequence) if (thisSequence->checkSequence() == HasReturnvaluesIF::RETURN_OK) { return HasReturnvaluesIF::RETURN_OK; } else { -#if FSFW_CPP_OSTREAM_ENABLED +#if FSFW_CPP_OSTREAM_ENABLED == 1 sif::error << "pst::pollingSequenceInitDefault: Sequence invalid!" << std::endl; #else sif::printError("pst::pollingSequenceInitDefault: Sequence invalid!"); diff --git a/unittests/tmtcservices/testPsb.cpp b/unittests/tmtcservices/testPsb.cpp index 464fb3da..0240223a 100644 --- a/unittests/tmtcservices/testPsb.cpp +++ b/unittests/tmtcservices/testPsb.cpp @@ -192,7 +192,7 @@ TEST_CASE("Pus Service Base", "[pus-service-base]") { REQUIRE(PsbMock::getStaticPusDistributor() == distributorId); REQUIRE(psb2.initialize() == result::OK); REQUIRE(pusDistrib.registerCallCount == 1); - REQUIRE(pusDistrib.lastServiceArg == &psb2); + REQUIRE(pusDistrib.registeredServies.front() == &psb2); } SECTION("Auto Initialize Packet Destination") { From 902a4bfa9ce3228c6d14d96c00cd0f410a47141d Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Mon, 1 Aug 2022 17:16:37 +0200 Subject: [PATCH 008/169] unittests for TC and CCSDS distributor --- CMakeLists.txt | 4 +- src/fsfw/datapoollocal/HasLocalDataPoolIF.h | 2 +- src/fsfw/events/fwSubsystemIdRanges.h | 1 + .../serviceinterface/ServiceInterfaceBuffer.h | 1 - .../serviceinterface/ServiceInterfaceStream.h | 3 +- src/fsfw/tcdistribution/CcsdsDistributor.cpp | 69 ++++++----- src/fsfw/tcdistribution/CcsdsDistributor.h | 3 +- src/fsfw/tcdistribution/CcsdsDistributorIF.h | 4 +- src/fsfw/tcdistribution/CcsdsUnpacker.cpp | 21 ++-- src/fsfw/tcdistribution/CcsdsUnpacker.h | 3 +- src/fsfw/tcdistribution/CfdpDistributor.cpp | 2 + src/fsfw/tcdistribution/PusDistributor.cpp | 3 +- src/fsfw/tcdistribution/TcDistributorBase.cpp | 25 +++- src/fsfw/tcdistribution/TcDistributorBase.h | 8 +- .../tmtcpacket/ccsds/SpacePacketReader.cpp | 5 +- unittests/CMakeLists.txt | 1 + unittests/CatchDefinitions.cpp | 3 +- unittests/CatchDefinitions.h | 3 +- unittests/CatchSetup.cpp | 2 +- unittests/mocks/AcceptsTcMock.cpp | 8 ++ unittests/mocks/AcceptsTcMock.h | 20 ++++ unittests/mocks/CMakeLists.txt | 2 + unittests/mocks/CcsdsCheckerMock.cpp | 10 ++ unittests/mocks/CcsdsCheckerMock.h | 16 +++ unittests/mocks/PusDistributorMock.h | 4 +- unittests/tcdistributor/CMakeLists.txt | 3 + .../tcdistributor/testCcsdsDistributor.cpp | 113 ++++++++++++++++++ .../PollingSequenceFactory.cpp | 2 +- unittests/tmtcpacket/testCcsdsReader.cpp | 2 +- 29 files changed, 277 insertions(+), 66 deletions(-) create mode 100644 unittests/mocks/AcceptsTcMock.cpp create mode 100644 unittests/mocks/AcceptsTcMock.h create mode 100644 unittests/mocks/CcsdsCheckerMock.cpp create mode 100644 unittests/mocks/CcsdsCheckerMock.h create mode 100644 unittests/tcdistributor/CMakeLists.txt create mode 100644 unittests/tcdistributor/testCcsdsDistributor.cpp diff --git a/CMakeLists.txt b/CMakeLists.txt index cfae2acb..c9c267f2 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -104,7 +104,8 @@ if(FSFW_GENERATE_SECTIONS) option(FSFW_REMOVE_UNUSED_CODE "Remove unused code" ON) endif() -option(FSFW_BUILD_TESTS "Build unittest binary in addition to static library" +option(FSFW_BUILD_TESTS + "Build unittest binary in addition to static library. Requires Catch2" OFF) option(FSFW_CICD_BUILD "Build for CI/CD. This can disable problematic test" OFF) option(FSFW_BUILD_DOCS "Build documentation with Sphinx and Doxygen" OFF) @@ -115,7 +116,6 @@ endif() option(FSFW_WARNING_SHADOW_LOCAL_GCC "Enable -Wshadow=local warning in GCC" ON) # Options to exclude parts of the FSFW from compilation. option(FSFW_ADD_INTERNAL_TESTS "Add internal unit tests" ON) -option(FSFW_ADD_UNITTESTS "Add regular unittests. Requires Catch2" OFF) option(FSFW_ADD_HAL "Add Hardware Abstraction Layer" ON) # Optional sources diff --git a/src/fsfw/datapoollocal/HasLocalDataPoolIF.h b/src/fsfw/datapoollocal/HasLocalDataPoolIF.h index b987e760..a0f8b03a 100644 --- a/src/fsfw/datapoollocal/HasLocalDataPoolIF.h +++ b/src/fsfw/datapoollocal/HasLocalDataPoolIF.h @@ -3,11 +3,11 @@ #include +#include "LocalDataPoolManager.h" #include "fsfw/datapool/PoolEntryIF.h" #include "fsfw/housekeeping/HousekeepingMessage.h" #include "fsfw/ipc/MessageQueueSenderIF.h" #include "fsfw/serviceinterface.h" -#include "LocalDataPoolManager.h" #include "localPoolDefinitions.h" class AccessPoolManagerIF; diff --git a/src/fsfw/events/fwSubsystemIdRanges.h b/src/fsfw/events/fwSubsystemIdRanges.h index fa4351e9..a09c935c 100644 --- a/src/fsfw/events/fwSubsystemIdRanges.h +++ b/src/fsfw/events/fwSubsystemIdRanges.h @@ -19,6 +19,7 @@ enum : uint8_t { HK = 73, SYSTEM_MANAGER = 74, SYSTEM_MANAGER_1 = 75, + TC_DISTRIBUTION = 76, SYSTEM_1 = 79, PUS_SERVICE_1 = 80, PUS_SERVICE_2 = 82, diff --git a/src/fsfw/serviceinterface/ServiceInterfaceBuffer.h b/src/fsfw/serviceinterface/ServiceInterfaceBuffer.h index 6832e809..9e692a05 100644 --- a/src/fsfw/serviceinterface/ServiceInterfaceBuffer.h +++ b/src/fsfw/serviceinterface/ServiceInterfaceBuffer.h @@ -2,7 +2,6 @@ #define FRAMEWORK_SERVICEINTERFACE_SERVICEINTERFACEBUFFER_H_ #include "fsfw/FSFW.h" - #include "fsfw/returnvalues/HasReturnvaluesIF.h" #if FSFW_CPP_OSTREAM_ENABLED == 1 diff --git a/src/fsfw/serviceinterface/ServiceInterfaceStream.h b/src/fsfw/serviceinterface/ServiceInterfaceStream.h index bf3424a6..ca746e7d 100644 --- a/src/fsfw/serviceinterface/ServiceInterfaceStream.h +++ b/src/fsfw/serviceinterface/ServiceInterfaceStream.h @@ -1,9 +1,8 @@ #ifndef FRAMEWORK_SERVICEINTERFACE_SERVICEINTERFACESTREAM_H_ #define FRAMEWORK_SERVICEINTERFACE_SERVICEINTERFACESTREAM_H_ -#include "fsfw/FSFW.h" - #include "ServiceInterfaceBuffer.h" +#include "fsfw/FSFW.h" #if FSFW_CPP_OSTREAM_ENABLED == 1 diff --git a/src/fsfw/tcdistribution/CcsdsDistributor.cpp b/src/fsfw/tcdistribution/CcsdsDistributor.cpp index 816d3037..f168e20a 100644 --- a/src/fsfw/tcdistribution/CcsdsDistributor.cpp +++ b/src/fsfw/tcdistribution/CcsdsDistributor.cpp @@ -1,7 +1,7 @@ -#include "fsfw/FSFW.h" #include "fsfw/tcdistribution/CcsdsDistributor.h" #include "definitions.h" +#include "fsfw/FSFW.h" #include "fsfw/objectmanager/ObjectManager.h" #include "fsfw/serviceinterface/ServiceInterface.h" #include "fsfw/tmtcpacket/ccsds/SpacePacketReader.h" @@ -9,9 +9,11 @@ #define CCSDS_DISTRIBUTOR_DEBUGGING 0 CcsdsDistributor::CcsdsDistributor(uint16_t setDefaultApid, object_id_t setObjectId, + StorageManagerIF* tcStore, MessageQueueIF* queue, CcsdsPacketCheckIF* packetChecker) - : TcDistributorBase(setObjectId), + : TcDistributorBase(setObjectId, queue), defaultApid(setDefaultApid), + tcStore(tcStore), packetChecker(packetChecker) {} CcsdsDistributor::~CcsdsDistributor() = default; @@ -28,9 +30,8 @@ ReturnValue_t CcsdsDistributor::selectDestination(MessageQueueId_t& destId) { currentMessage.getStorageId().packetIndex); #endif #endif - const uint8_t* packet = nullptr; - size_t size = 0; - ReturnValue_t result = tcStore->getData(currentMessage.getStorageId(), &packet, &size); + auto accessorPair = tcStore->getData(currentMessage.getStorageId()); + ReturnValue_t result = accessorPair.first; if (result != HasReturnvaluesIF::RETURN_OK) { #if FSFW_VERBOSE_LEVEL >= 1 #if FSFW_CPP_OSTREAM_ENABLED == 1 @@ -45,8 +46,11 @@ ReturnValue_t CcsdsDistributor::selectDestination(MessageQueueId_t& destId) { #endif return result; } - SpacePacketReader currentPacket(packet, size); - result = packetChecker->checkPacket(currentPacket, size); + if (accessorPair.second.size() < ccsds::HEADER_LEN) { + return SerializeIF::STREAM_TOO_SHORT; + } + SpacePacketReader currentPacket(accessorPair.second.data(), accessorPair.second.size()); + result = packetChecker->checkPacket(currentPacket, accessorPair.second.size()); if (result != HasReturnvaluesIF::RETURN_OK) { handlePacketCheckFailure(result); return result; @@ -59,11 +63,12 @@ ReturnValue_t CcsdsDistributor::selectDestination(MessageQueueId_t& destId) { if (iter != receiverMap.end()) { destId = iter->second.destId; if (iter->second.removeHeader) { - handleCcsdsHeaderRemoval(); + // Do not call accessor release method here to ensure the old packet gets deleted. + return handleCcsdsHeaderRemoval(accessorPair.second); } } else { // The APID was not found. Forward packet to main SW-APID anyway to - // create acceptance failure report. + // create acceptance failure report. iter = receiverMap.find(defaultApid); if (iter != receiverMap.end()) { destId = iter->second.destId; @@ -71,6 +76,7 @@ ReturnValue_t CcsdsDistributor::selectDestination(MessageQueueId_t& destId) { return DESTINATION_NOT_FOUND; } } + accessorPair.second.release(); return HasReturnvaluesIF::RETURN_OK; } @@ -111,23 +117,28 @@ ReturnValue_t CcsdsDistributor::initialize() { if (packetChecker == nullptr) { packetChecker = new CcsdsPacketChecker(ccsds::PacketType::TC); } - ReturnValue_t status = this->TcDistributorBase::initialize(); - this->tcStore = ObjectManager::instance()->get(objects::TC_STORE); - if (this->tcStore == nullptr) { + ReturnValue_t result = TcDistributorBase::initialize(); + if (result != HasReturnvaluesIF::RETURN_OK) { + return result; + } + if (tcStore == nullptr) { + tcStore = ObjectManager::instance()->get(objects::TC_STORE); + if (tcStore == nullptr) { #if FSFW_VERBOSE_LEVEL >= 1 #if FSFW_CPP_OSTREAM_ENABLED == 1 - sif::error << "CCSDSDistributor::initialize: Could not initialize" - " TC store!" - << std::endl; + sif::error << "CCSDSDistributor::initialize: Could not initialize" + " TC store!" + << std::endl; #else - sif::printError( - "CCSDSDistributor::initialize: Could not initialize" - " TC store!\n"); + sif::printError( + "CCSDSDistributor::initialize: Could not initialize" + " TC store!\n"); #endif #endif - status = RETURN_FAILED; + return ObjectManagerIF::CHILD_INIT_FAILED; + } } - return status; + return result; } ReturnValue_t CcsdsDistributor::callbackAfterSending(ReturnValue_t queueStatus) { @@ -151,15 +162,19 @@ void CcsdsDistributor::print() { const char* CcsdsDistributor::getName() const { return "CCSDS Distributor"; } -ReturnValue_t CcsdsDistributor::handleCcsdsHeaderRemoval() { - currentMessage; - auto accessorPair = tcStore->getData(currentMessage.getStorageId()); - if(accessorPair.first != HasReturnvaluesIF::RETURN_OK) { +ReturnValue_t CcsdsDistributor::handleCcsdsHeaderRemoval(ConstStorageAccessor& accessor) { + store_address_t newStoreId; + ReturnValue_t result = tcStore->addData(&newStoreId, accessor.data() + ccsds::HEADER_LEN, + accessor.size() - ccsds::HEADER_LEN); + if (result != HasReturnvaluesIF::RETURN_OK) { #if FSFW_CPP_OSTREAM_ENABLED == 1 - sif::error << __func__ << ": Getting TC data failed" << std::endl; + sif::error << __func__ << ": TC store full" << std::endl; #else - sif::printError("%s: Getting TC data failed\n", __func__); + sif::printError("%s: TC store full\n", __func__); #endif - return accessorPair.first; + return result; } + currentMessage.setStorageId(newStoreId); + // The const accessor will delete the old data automatically + return HasReturnvaluesIF::RETURN_OK; } diff --git a/src/fsfw/tcdistribution/CcsdsDistributor.h b/src/fsfw/tcdistribution/CcsdsDistributor.h index 542625eb..c2ada02d 100644 --- a/src/fsfw/tcdistribution/CcsdsDistributor.h +++ b/src/fsfw/tcdistribution/CcsdsDistributor.h @@ -31,6 +31,7 @@ class CcsdsDistributor : public TcDistributorBase, * destination are sent to. */ CcsdsDistributor(uint16_t unknownApid, object_id_t setObjectId, + StorageManagerIF* tcStore = nullptr, MessageQueueIF* msgQueue = nullptr, CcsdsPacketCheckIF* packetChecker = nullptr); /** * The destructor is empty. @@ -63,7 +64,7 @@ class CcsdsDistributor : public TcDistributorBase, static void handlePacketCheckFailure(ReturnValue_t result); - ReturnValue_t handleCcsdsHeaderRemoval(); + ReturnValue_t handleCcsdsHeaderRemoval(ConstStorageAccessor& accessor); void print(); /** * The default APID, where packets with unknown APID are sent to. diff --git a/src/fsfw/tcdistribution/CcsdsDistributorIF.h b/src/fsfw/tcdistribution/CcsdsDistributorIF.h index 7e7a586d..6deb1c67 100644 --- a/src/fsfw/tcdistribution/CcsdsDistributorIF.h +++ b/src/fsfw/tcdistribution/CcsdsDistributorIF.h @@ -17,8 +17,8 @@ class CcsdsDistributorIF { struct DestInfo { DestInfo(const char* name, uint16_t apid, MessageQueueId_t destId, bool removeHeader) : name(name), apid(apid), destId(destId), removeHeader(removeHeader) {} - DestInfo(const char* name, const AcceptsTelecommandsIF& ccsdsReceiver, bool removeHeader_) - : name(name) { + DestInfo(const AcceptsTelecommandsIF& ccsdsReceiver, bool removeHeader_) + : name(ccsdsReceiver.getName()) { apid = ccsdsReceiver.getIdentifier(); destId = ccsdsReceiver.getRequestQueue(); removeHeader = removeHeader_; diff --git a/src/fsfw/tcdistribution/CcsdsUnpacker.cpp b/src/fsfw/tcdistribution/CcsdsUnpacker.cpp index 42a7cd28..9b212d2e 100644 --- a/src/fsfw/tcdistribution/CcsdsUnpacker.cpp +++ b/src/fsfw/tcdistribution/CcsdsUnpacker.cpp @@ -4,29 +4,28 @@ CcsdsUnpacker::CcsdsUnpacker(MessageQueueIF& msgQueue, AcceptsTelecommandsIF& receiver, StorageManagerIF& sourceStore) - : sourceStore(sourceStore), msgQueue(msgQueue), receiver(receiver) { + : sourceStore(sourceStore), msgQueue(msgQueue), receiver(receiver) { msgQueue.setDefaultDestination(receiver.getRequestQueue()); } ReturnValue_t CcsdsUnpacker::performOperation(uint8_t operationCode) { TmTcMessage msg; ReturnValue_t result; - for (result = msgQueue.receiveMessage(&msg); result == HasReturnvaluesIF::RETURN_OK; + for (result = msgQueue.receiveMessage(&msg); result == HasReturnvaluesIF::RETURN_OK; result = msgQueue.receiveMessage(&msg)) { auto resultPair = sourceStore.getData(msg.getStorageId()); - if(resultPair.first != HasReturnvaluesIF::RETURN_OK) { + if (resultPair.first != HasReturnvaluesIF::RETURN_OK) { continue; } - if(resultPair.second.size() < 6) { + if (resultPair.second.size() < 6) { // TODO: This is a config error. Does it make sense to forward the message? result = msgQueue.sendToDefault(&msg); - if(result != HasReturnvaluesIF::RETURN_OK) { - + if (result != HasReturnvaluesIF::RETURN_OK) { } continue; } StorageManagerIF* tgtStore; - if(targetStore != nullptr) { + if (targetStore != nullptr) { tgtStore = targetStore; } else { tgtStore = &sourceStore; @@ -34,24 +33,22 @@ ReturnValue_t CcsdsUnpacker::performOperation(uint8_t operationCode) { store_address_t newId; uint8_t* ptr; result = tgtStore->getFreeElement(&newId, resultPair.second.size(), &ptr); - if(result != HasReturnvaluesIF::RETURN_OK) { + if (result != HasReturnvaluesIF::RETURN_OK) { // TODO: Implement error handling } std::memcpy(ptr, resultPair.second.data() + 6, resultPair.second.size() - 6); result = sourceStore.deleteData(msg.getStorageId()); - if(result != HasReturnvaluesIF::RETURN_OK) { + if (result != HasReturnvaluesIF::RETURN_OK) { // TODO: Implement error handling (though this really should not happen) } TmTcMessage newMsg(newId); result = msgQueue.sendToDefault(&newMsg); - if(result != HasReturnvaluesIF::RETURN_OK) { - + if (result != HasReturnvaluesIF::RETURN_OK) { } } return result; } - void CcsdsUnpacker::setDifferentTargetStore(StorageManagerIF& otherTargetStore) { targetStore = &otherTargetStore; } diff --git a/src/fsfw/tcdistribution/CcsdsUnpacker.h b/src/fsfw/tcdistribution/CcsdsUnpacker.h index d8c5e8b5..267b8e64 100644 --- a/src/fsfw/tcdistribution/CcsdsUnpacker.h +++ b/src/fsfw/tcdistribution/CcsdsUnpacker.h @@ -7,7 +7,8 @@ class CcsdsUnpacker : public ExecutableObjectIF, public AcceptsTelecommandsIF { public: - CcsdsUnpacker(MessageQueueIF& msgQueue, AcceptsTelecommandsIF& receiver, StorageManagerIF& sourceStore); + CcsdsUnpacker(MessageQueueIF& msgQueue, AcceptsTelecommandsIF& receiver, + StorageManagerIF& sourceStore); void setDifferentTargetStore(StorageManagerIF& otherTargetStore); ReturnValue_t performOperation(uint8_t operationCode) override; diff --git a/src/fsfw/tcdistribution/CfdpDistributor.cpp b/src/fsfw/tcdistribution/CfdpDistributor.cpp index abbad748..3b1d1538 100644 --- a/src/fsfw/tcdistribution/CfdpDistributor.cpp +++ b/src/fsfw/tcdistribution/CfdpDistributor.cpp @@ -68,6 +68,7 @@ ReturnValue_t CfdpDistributor::selectDestination(MessageQueueId_t& destId) { // } else { // return queueMapIt; // } + return HasReturnvaluesIF::RETURN_OK; } ReturnValue_t CfdpDistributor::registerHandler(AcceptsTelecommandsIF* handler) { @@ -141,4 +142,5 @@ ReturnValue_t CfdpDistributor::initialize() { // return RETURN_FAILED; // } // return ccsdsDistributor->registerApplication(this); + return HasReturnvaluesIF::RETURN_OK; } diff --git a/src/fsfw/tcdistribution/PusDistributor.cpp b/src/fsfw/tcdistribution/PusDistributor.cpp index e85a6047..7be0810d 100644 --- a/src/fsfw/tcdistribution/PusDistributor.cpp +++ b/src/fsfw/tcdistribution/PusDistributor.cpp @@ -139,8 +139,7 @@ ReturnValue_t PusDistributor::initialize() { return ObjectManagerIF::CHILD_INIT_FAILED; } } - return ccsdsDistributor->registerApplication( - CcsdsDistributorIF::DestInfo(getName(), *this, false)); + return ccsdsDistributor->registerApplication(CcsdsDistributorIF::DestInfo(*this, false)); } void PusDistributor::checkerFailurePrinter() const { diff --git a/src/fsfw/tcdistribution/TcDistributorBase.cpp b/src/fsfw/tcdistribution/TcDistributorBase.cpp index 70388b99..33c779eb 100644 --- a/src/fsfw/tcdistribution/TcDistributorBase.cpp +++ b/src/fsfw/tcdistribution/TcDistributorBase.cpp @@ -3,22 +3,35 @@ #include "fsfw/ipc/QueueFactory.h" #include "fsfw/tmtcservices/TmTcMessage.h" -TcDistributorBase::TcDistributorBase(object_id_t objectId) : SystemObject(objectId) { - tcQueue = QueueFactory::instance()->createMessageQueue(DISTRIBUTER_MAX_PACKETS); +TcDistributorBase::TcDistributorBase(object_id_t objectId, MessageQueueIF* tcQueue_) + : SystemObject(objectId), tcQueue(tcQueue_) { + if (tcQueue == nullptr) { + ownedQueue = true; + tcQueue = QueueFactory::instance()->createMessageQueue(DISTRIBUTER_MAX_PACKETS); + } } -TcDistributorBase::~TcDistributorBase() { QueueFactory::instance()->deleteMessageQueue(tcQueue); } +TcDistributorBase::~TcDistributorBase() { + if (ownedQueue) { + QueueFactory::instance()->deleteMessageQueue(tcQueue); + } +} ReturnValue_t TcDistributorBase::performOperation(uint8_t opCode) { ReturnValue_t status; + ReturnValue_t result = HasReturnvaluesIF::RETURN_OK; for (status = tcQueue->receiveMessage(¤tMessage); status == RETURN_OK; status = tcQueue->receiveMessage(¤tMessage)) { - status = handlePacket(); + ReturnValue_t packetResult = handlePacket(); + if (packetResult != HasReturnvaluesIF::RETURN_OK) { + result = packetResult; + triggerEvent(HANDLE_PACKET_FAILED, packetResult, __LINE__); + } } if (status == MessageQueueIF::EMPTY) { - return RETURN_OK; + return result; } - return status; + return result; } ReturnValue_t TcDistributorBase::handlePacket() { diff --git a/src/fsfw/tcdistribution/TcDistributorBase.h b/src/fsfw/tcdistribution/TcDistributorBase.h index 08b72823..c2bee0b9 100644 --- a/src/fsfw/tcdistribution/TcDistributorBase.h +++ b/src/fsfw/tcdistribution/TcDistributorBase.h @@ -3,6 +3,7 @@ #include +#include "fsfw/events/Event.h" #include "fsfw/ipc/MessageQueueIF.h" #include "fsfw/objectmanager/ObjectManagerIF.h" #include "fsfw/objectmanager/SystemObject.h" @@ -33,6 +34,10 @@ class TcDistributorBase : public SystemObject, public ExecutableObjectIF, public static constexpr ReturnValue_t PACKET_LOST = MAKE_RETURN_CODE(1); static constexpr ReturnValue_t DESTINATION_NOT_FOUND = MAKE_RETURN_CODE(2); static constexpr ReturnValue_t SERVICE_ID_ALREADY_EXISTS = MAKE_RETURN_CODE(3); + + static constexpr uint8_t SUBSYSTEM_ID = SUBSYSTEM_ID::TC_DISTRIBUTION; + //! P1: Returnvalue, P2: Line number + static constexpr Event HANDLE_PACKET_FAILED = event::makeEvent(SUBSYSTEM_ID, 0, severity::LOW); /** * Within the default constructor, the SystemObject id is set and the * message queue is initialized. @@ -40,7 +45,7 @@ class TcDistributorBase : public SystemObject, public ExecutableObjectIF, public * @param set_object_id This id is assigned to the distributor * implementation. */ - explicit TcDistributorBase(object_id_t objectId); + explicit TcDistributorBase(object_id_t objectId, MessageQueueIF* tcQueue = nullptr); /** * The destructor is empty, the message queues are not in the vicinity of * this class. @@ -56,6 +61,7 @@ class TcDistributorBase : public SystemObject, public ExecutableObjectIF, public ReturnValue_t performOperation(uint8_t opCode) override; protected: + bool ownedQueue = false; /** * This is the receiving queue for incoming Telecommands. * The child classes must make its queue id public. diff --git a/src/fsfw/tmtcpacket/ccsds/SpacePacketReader.cpp b/src/fsfw/tmtcpacket/ccsds/SpacePacketReader.cpp index b6f03de9..4a140dac 100644 --- a/src/fsfw/tmtcpacket/ccsds/SpacePacketReader.cpp +++ b/src/fsfw/tmtcpacket/ccsds/SpacePacketReader.cpp @@ -35,8 +35,11 @@ uint16_t SpacePacketReader::getPacketDataLen() const { return ccsds::getPacketLe ReturnValue_t SpacePacketReader::setInternalFields(const uint8_t* data, size_t maxSize_) { bufSize = maxSize_; + if (maxSize_ < ccsds::HEADER_LEN) { + return SerializeIF::STREAM_TOO_SHORT; + } spHeader = reinterpret_cast(data); - if (maxSize_ > 6) { + if (maxSize_ > ccsds::HEADER_LEN) { packetDataField = data + ccsds::HEADER_LEN; } return checkSize(); diff --git a/unittests/CMakeLists.txt b/unittests/CMakeLists.txt index fc03a728..595d9553 100644 --- a/unittests/CMakeLists.txt +++ b/unittests/CMakeLists.txt @@ -13,6 +13,7 @@ target_sources(${FSFW_TEST_TGT} PRIVATE add_subdirectory(testcfg) add_subdirectory(mocks) +add_subdirectory(tcdistributor) add_subdirectory(action) add_subdirectory(power) add_subdirectory(util) diff --git a/unittests/CatchDefinitions.cpp b/unittests/CatchDefinitions.cpp index 15ff1de9..3c76fd88 100644 --- a/unittests/CatchDefinitions.cpp +++ b/unittests/CatchDefinitions.cpp @@ -1,9 +1,10 @@ -#include "fsfw/FSFW.h" #include "CatchDefinitions.h" #include #include +#include "fsfw/FSFW.h" + StorageManagerIF* tglob::getIpcStoreHandle() { if (ObjectManager::instance() != nullptr) { return ObjectManager::instance()->get(objects::IPC_STORE); diff --git a/unittests/CatchDefinitions.h b/unittests/CatchDefinitions.h index be49e6e8..7ffad55a 100644 --- a/unittests/CatchDefinitions.h +++ b/unittests/CatchDefinitions.h @@ -1,11 +1,12 @@ #ifndef FSFW_UNITTEST_CORE_CATCHDEFINITIONS_H_ #define FSFW_UNITTEST_CORE_CATCHDEFINITIONS_H_ -#include "fsfw/FSFW.h" #include #include #include +#include "fsfw/FSFW.h" + namespace tconst { static constexpr MessageQueueId_t testQueueId = 42; } diff --git a/unittests/CatchSetup.cpp b/unittests/CatchSetup.cpp index 848af5e7..4f2a4a54 100644 --- a/unittests/CatchSetup.cpp +++ b/unittests/CatchSetup.cpp @@ -1,6 +1,6 @@ -#include "fsfw/FSFW.h" #include "CatchDefinitions.h" #include "CatchFactory.h" +#include "fsfw/FSFW.h" #ifdef GCOV #include diff --git a/unittests/mocks/AcceptsTcMock.cpp b/unittests/mocks/AcceptsTcMock.cpp new file mode 100644 index 00000000..a9afafd9 --- /dev/null +++ b/unittests/mocks/AcceptsTcMock.cpp @@ -0,0 +1,8 @@ +#include "AcceptsTcMock.h" + +AcceptsTcMock::AcceptsTcMock(const char* name, uint32_t id, MessageQueueId_t queueId) + : name(name), id(id), queueId(queueId) {} + +const char* AcceptsTcMock::getName() const { return name; } +uint32_t AcceptsTcMock::getIdentifier() const { return id; } +MessageQueueId_t AcceptsTcMock::getRequestQueue() const { return queueId; } diff --git a/unittests/mocks/AcceptsTcMock.h b/unittests/mocks/AcceptsTcMock.h new file mode 100644 index 00000000..028b68cd --- /dev/null +++ b/unittests/mocks/AcceptsTcMock.h @@ -0,0 +1,20 @@ +#ifndef FSFW_TESTS_ACCEPTSTCMOCK_H +#define FSFW_TESTS_ACCEPTSTCMOCK_H + +#include "fsfw/tmtcservices/AcceptsTelecommandsIF.h" + +class AcceptsTcMock : public AcceptsTelecommandsIF { + public: + AcceptsTcMock(const char* name, uint32_t id, MessageQueueId_t queueId); + [[nodiscard]] const char* getName() const override; + [[nodiscard]] uint32_t getIdentifier() const override; + [[nodiscard]] MessageQueueId_t getRequestQueue() const override; + + const char* name; + uint32_t id; + MessageQueueId_t queueId; + + private: +}; + +#endif // FSFW_TESTS_ACCEPTSTCMOCK_H diff --git a/unittests/mocks/CMakeLists.txt b/unittests/mocks/CMakeLists.txt index f3b50f62..3a8c8d18 100644 --- a/unittests/mocks/CMakeLists.txt +++ b/unittests/mocks/CMakeLists.txt @@ -11,4 +11,6 @@ target_sources(${FSFW_TEST_TGT} PRIVATE PusServiceBaseMock.cpp AcceptsTmMock.cpp PusDistributorMock.cpp + CcsdsCheckerMock.cpp + AcceptsTcMock.cpp ) diff --git a/unittests/mocks/CcsdsCheckerMock.cpp b/unittests/mocks/CcsdsCheckerMock.cpp new file mode 100644 index 00000000..18c5fb4e --- /dev/null +++ b/unittests/mocks/CcsdsCheckerMock.cpp @@ -0,0 +1,10 @@ +#include "CcsdsCheckerMock.h" + +CcsdsCheckerMock::CcsdsCheckerMock() = default; + +ReturnValue_t CcsdsCheckerMock::checkPacket(const SpacePacketReader& currentPacket, + size_t packetLen) { + checkCallCount++; + checkedPacketLen = packetLen; + return nextResult; +} diff --git a/unittests/mocks/CcsdsCheckerMock.h b/unittests/mocks/CcsdsCheckerMock.h new file mode 100644 index 00000000..a9388ae5 --- /dev/null +++ b/unittests/mocks/CcsdsCheckerMock.h @@ -0,0 +1,16 @@ +#ifndef FSFW_TESTS_CCSDSCHECKERMOCK_H +#define FSFW_TESTS_CCSDSCHECKERMOCK_H + +#include "fsfw/tcdistribution/CcsdsPacketCheckIF.h" +class CcsdsCheckerMock : public CcsdsPacketCheckIF { + public: + CcsdsCheckerMock(); + unsigned int checkCallCount = 0; + size_t checkedPacketLen = 0; + ReturnValue_t nextResult = HasReturnvaluesIF::RETURN_OK; + ReturnValue_t checkPacket(const SpacePacketReader& currentPacket, size_t packetLen) override; + + private: +}; + +#endif // FSFW_TESTS_CCSDSCHECKERMOCK_H diff --git a/unittests/mocks/PusDistributorMock.h b/unittests/mocks/PusDistributorMock.h index d85030c9..417ae448 100644 --- a/unittests/mocks/PusDistributorMock.h +++ b/unittests/mocks/PusDistributorMock.h @@ -1,11 +1,11 @@ #ifndef FSFW_TESTS_PUSDISTRIBUTORMOCK_H #define FSFW_TESTS_PUSDISTRIBUTORMOCK_H +#include + #include "fsfw/objectmanager/SystemObject.h" #include "fsfw/tcdistribution/PusDistributorIF.h" -#include - class PusDistributorMock : public SystemObject, public PusDistributorIF { public: PusDistributorMock(); diff --git a/unittests/tcdistributor/CMakeLists.txt b/unittests/tcdistributor/CMakeLists.txt new file mode 100644 index 00000000..d4182326 --- /dev/null +++ b/unittests/tcdistributor/CMakeLists.txt @@ -0,0 +1,3 @@ +target_sources(${FSFW_TEST_TGT} PRIVATE + testCcsdsDistributor.cpp +) diff --git a/unittests/tcdistributor/testCcsdsDistributor.cpp b/unittests/tcdistributor/testCcsdsDistributor.cpp new file mode 100644 index 00000000..8aa248fa --- /dev/null +++ b/unittests/tcdistributor/testCcsdsDistributor.cpp @@ -0,0 +1,113 @@ +#include +#include + +#include "fsfw/storagemanager/LocalPool.h" +#include "fsfw/tcdistribution/CcsdsDistributor.h" +#include "fsfw/tmtcpacket/ccsds/SpacePacketCreator.h" +#include "mocks/AcceptsTcMock.h" +#include "mocks/CcsdsCheckerMock.h" +#include "mocks/MessageQueueMock.h" + +TEST_CASE("CCSDS Distributor", "[ccsds-distrib]") { + LocalPool::LocalPoolConfig cfg = {{5, 32}, {2, 64}}; + LocalPool pool(objects::NO_OBJECT, cfg); + auto queue = MessageQueueMock(1); + auto checkerMock = CcsdsCheckerMock(); + uint16_t unregisteredApid = 0; + uint16_t defaultApid = 4; + MessageQueueId_t defaultQueueId = 5; + auto ccsdsDistrib = CcsdsDistributor(defaultApid, 1, &pool, &queue, &checkerMock); + uint32_t tcAcceptorApid = 1; + MessageQueueId_t tcAcceptorQueueId = 3; + + auto tcAcceptorMock = AcceptsTcMock("TC Receiver Dummy", tcAcceptorApid, tcAcceptorQueueId); + auto defReceiverMock = AcceptsTcMock("Default Receiver Dummy", defaultApid, defaultQueueId); + auto packetId = PacketId(ccsds::PacketType::TC, true, 0); + auto psc = PacketSeqCtrl(ccsds::SequenceFlags::FIRST_SEGMENT, 0x34); + auto spParams = SpacePacketParams(packetId, psc, 0x16); + SpacePacketCreator spCreator(spParams); + std::array buf{}; + + auto createSpacePacket = [&](uint16_t apid, TmTcMessage& msg) { + store_address_t storeId{}; + spCreator.setApid(tcAcceptorApid); + uint8_t* dataPtr; + REQUIRE(pool.getFreeElement(&storeId, spCreator.getSerializedSize(), &dataPtr) == result::OK); + size_t serLen = 0; + REQUIRE(spCreator.SerializeIF::serializeBe(dataPtr, serLen, ccsds::HEADER_LEN) == result::OK); + REQUIRE(spCreator.SerializeIF::serializeBe(buf.data(), serLen, ccsds::HEADER_LEN) == + result::OK); + msg.setStorageId(storeId); + }; + + SECTION("State") { + CHECK(ccsdsDistrib.initialize() == result::OK); + CHECK(ccsdsDistrib.getRequestQueue() == 1); + CHECK(ccsdsDistrib.getIdentifier() == 0); + CHECK(ccsdsDistrib.getObjectId() == 1); + REQUIRE(ccsdsDistrib.getName() != nullptr); + CHECK(std::strcmp(ccsdsDistrib.getName(), "CCSDS Distributor") == 0); + } + + SECTION("Basic Forwarding") { + CcsdsDistributor::DestInfo info(tcAcceptorMock, false); + REQUIRE(ccsdsDistrib.registerApplication(info) == result::OK); + TmTcMessage message; + createSpacePacket(tcAcceptorApid, message); + store_address_t storeId = message.getStorageId(); + queue.addReceivedMessage(message); + REQUIRE(ccsdsDistrib.performOperation(0) == result::OK); + CHECK(checkerMock.checkedPacketLen == 6); + CHECK(checkerMock.checkCallCount == 1); + CHECK(queue.wasMessageSent()); + CHECK(queue.numberOfSentMessages() == 1); + // The packet is forwarded, with no need to delete the data + CHECK(pool.hasDataAtId(storeId)); + TmTcMessage sentMsg; + CHECK(queue.getNextSentMessage(tcAcceptorQueueId, sentMsg) == result::OK); + CHECK(sentMsg.getStorageId() == storeId); + auto accessor = pool.getData(storeId); + CHECK(accessor.first == result::OK); + CHECK(accessor.second.size() == ccsds::HEADER_LEN); + for (size_t i = 0; i < ccsds::HEADER_LEN; i++) { + CHECK(accessor.second.data()[i] == buf[i]); + } + } + + SECTION("Forwarding to Default Destination, but not registered") { + TmTcMessage message; + createSpacePacket(unregisteredApid, message); + store_address_t storeId = message.getStorageId(); + message.setStorageId(storeId); + queue.addReceivedMessage(message); + REQUIRE(ccsdsDistrib.performOperation(0) == TcDistributorBase::DESTINATION_NOT_FOUND); + } + + SECTION("Forward to Default Handler") { + CcsdsDistributor::DestInfo info(defReceiverMock, false); + ccsdsDistrib.registerApplication(info); + TmTcMessage message; + createSpacePacket(defaultApid, message); + store_address_t storeId = message.getStorageId(); + message.setStorageId(storeId); + queue.addReceivedMessage(message); + REQUIRE(ccsdsDistrib.performOperation(0) == result::OK); + CHECK(checkerMock.checkedPacketLen == 6); + CHECK(checkerMock.checkCallCount == 1); + CHECK(queue.wasMessageSent()); + CHECK(queue.numberOfSentMessages() == 1); + // The packet is forwarded, with no need to delete the data + CHECK(pool.hasDataAtId(storeId)); + TmTcMessage sentMsg; + CHECK(queue.getNextSentMessage(defaultQueueId, sentMsg) == result::OK); + CHECK(sentMsg.getStorageId() == storeId); + auto accessor = pool.getData(storeId); + CHECK(accessor.first == result::OK); + CHECK(accessor.second.size() == ccsds::HEADER_LEN); + for (size_t i = 0; i < ccsds::HEADER_LEN; i++) { + CHECK(accessor.second.data()[i] == buf[i]); + } + } + + SECTION("Remove CCSDS header") {} +} \ No newline at end of file diff --git a/unittests/testcfg/pollingsequence/PollingSequenceFactory.cpp b/unittests/testcfg/pollingsequence/PollingSequenceFactory.cpp index 34a8cfbd..cdf40d89 100644 --- a/unittests/testcfg/pollingsequence/PollingSequenceFactory.cpp +++ b/unittests/testcfg/pollingsequence/PollingSequenceFactory.cpp @@ -1,10 +1,10 @@ -#include "fsfw/FSFW.h" #include "PollingSequenceFactory.h" #include #include #include +#include "fsfw/FSFW.h" #include "tests/TestsConfig.h" ReturnValue_t pst::pollingSequenceInitDefault(FixedTimeslotTaskIF *thisSequence) { diff --git a/unittests/tmtcpacket/testCcsdsReader.cpp b/unittests/tmtcpacket/testCcsdsReader.cpp index 75b4af87..61c4dd55 100644 --- a/unittests/tmtcpacket/testCcsdsReader.cpp +++ b/unittests/tmtcpacket/testCcsdsReader.cpp @@ -64,7 +64,7 @@ TEST_CASE("CCSDS Reader", "[ccsds-reader]") { SECTION("Invalid Size") { for (size_t i = 0; i < 5; i++) { REQUIRE(reader.setReadOnlyData(buf.data(), i) == SerializeIF::STREAM_TOO_SHORT); - REQUIRE(not reader.isNull()); + REQUIRE(reader.isNull()); REQUIRE(reader.getPacketData() == nullptr); } } From a426aef7c73247634929b5dbb9a3919328591807 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Wed, 3 Aug 2022 11:33:10 +0200 Subject: [PATCH 009/169] add some more tests for CCSDS distributor --- src/fsfw/tcdistribution/CcsdsDistributor.cpp | 21 ++++-- src/fsfw/tcdistribution/CcsdsDistributor.h | 4 +- src/fsfw/tcdistribution/TcDistributorBase.cpp | 3 +- .../tmtcpacket/ccsds/SpacePacketCreator.cpp | 10 ++- .../tmtcpacket/ccsds/SpacePacketCreator.h | 33 ++++++++- src/fsfw/tmtcpacket/pus/tc/PusTcCreator.cpp | 5 +- src/fsfw/tmtcpacket/pus/tm/PusTmCreator.cpp | 6 +- unittests/cfdp/testTlvsLvs.cpp | 10 +-- .../tcdistributor/testCcsdsDistributor.cpp | 69 +++++++++++++++++-- unittests/tmtcpacket/testCcsdsCreator.cpp | 14 +++- 10 files changed, 142 insertions(+), 33 deletions(-) diff --git a/src/fsfw/tcdistribution/CcsdsDistributor.cpp b/src/fsfw/tcdistribution/CcsdsDistributor.cpp index f168e20a..2e09e71f 100644 --- a/src/fsfw/tcdistribution/CcsdsDistributor.cpp +++ b/src/fsfw/tcdistribution/CcsdsDistributor.cpp @@ -46,7 +46,16 @@ ReturnValue_t CcsdsDistributor::selectDestination(MessageQueueId_t& destId) { #endif return result; } - if (accessorPair.second.size() < ccsds::HEADER_LEN) { + // Minimum length of a space packet + if (accessorPair.second.size() < ccsds::HEADER_LEN + 1) { +#if FSFW_VERBOSE_LEVEL >= 1 +#if FSFW_CPP_OSTREAM_ENABLED == 1 + sif::error << __func__ << ": SP with length" << accessorPair.second.size() << " too short" + << std::endl; +#else + sif::printError("%s: SP with length %d too short\n", __func__, accessorPair.second.size()); +#endif +#endif return SerializeIF::STREAM_TOO_SHORT; } SpacePacketReader currentPacket(accessorPair.second.data(), accessorPair.second.size()); @@ -62,11 +71,7 @@ ReturnValue_t CcsdsDistributor::selectDestination(MessageQueueId_t& destId) { auto iter = receiverMap.find(currentPacket.getApid()); if (iter != receiverMap.end()) { destId = iter->second.destId; - if (iter->second.removeHeader) { - // Do not call accessor release method here to ensure the old packet gets deleted. - return handleCcsdsHeaderRemoval(accessorPair.second); - } - } else { + } else if (iter == receiverMap.end()) { // The APID was not found. Forward packet to main SW-APID anyway to // create acceptance failure report. iter = receiverMap.find(defaultApid); @@ -76,6 +81,10 @@ ReturnValue_t CcsdsDistributor::selectDestination(MessageQueueId_t& destId) { return DESTINATION_NOT_FOUND; } } + if (iter->second.removeHeader) { + // Do not call accessor release method here to ensure the old packet gets deleted. + return handleCcsdsHeaderRemoval(accessorPair.second); + } accessorPair.second.release(); return HasReturnvaluesIF::RETURN_OK; } diff --git a/src/fsfw/tcdistribution/CcsdsDistributor.h b/src/fsfw/tcdistribution/CcsdsDistributor.h index c2ada02d..0444a868 100644 --- a/src/fsfw/tcdistribution/CcsdsDistributor.h +++ b/src/fsfw/tcdistribution/CcsdsDistributor.h @@ -53,7 +53,9 @@ class CcsdsDistributor : public TcDistributorBase, * registered and forwards the packet to the according message queue. * If the packet is not found, it returns the queue to @c defaultApid, * where a Acceptance Failure message should be generated. - * @return Iterator to map entry of found APID or iterator to default APID. + * @return + * - @c RETURN_OK if a valid desintation was found, error code otherwise + * - @c SerializeIF::STREAM_TOO_SHORT: Packet too short to be a space packet */ ReturnValue_t selectDestination(MessageQueueId_t& destId) override; /** diff --git a/src/fsfw/tcdistribution/TcDistributorBase.cpp b/src/fsfw/tcdistribution/TcDistributorBase.cpp index 33c779eb..e673d628 100644 --- a/src/fsfw/tcdistribution/TcDistributorBase.cpp +++ b/src/fsfw/tcdistribution/TcDistributorBase.cpp @@ -40,8 +40,7 @@ ReturnValue_t TcDistributorBase::handlePacket() { if (result != HasReturnvaluesIF::RETURN_OK) { return result; } - result = tcQueue->sendMessage(destId, ¤tMessage); - return callbackAfterSending(result); + return callbackAfterSending(tcQueue->sendMessage(destId, ¤tMessage)); } ReturnValue_t TcDistributorBase::callbackAfterSending(ReturnValue_t queueStatus) { diff --git a/src/fsfw/tmtcpacket/ccsds/SpacePacketCreator.cpp b/src/fsfw/tmtcpacket/ccsds/SpacePacketCreator.cpp index ee27cc9b..a946650b 100644 --- a/src/fsfw/tmtcpacket/ccsds/SpacePacketCreator.cpp +++ b/src/fsfw/tmtcpacket/ccsds/SpacePacketCreator.cpp @@ -40,7 +40,13 @@ ReturnValue_t SpacePacketCreator::serialize(uint8_t **buffer, size_t *size, size return SerializeAdapter::serialize(¶ms.dataLen, buffer, size, maxSize, streamEndianness); } -size_t SpacePacketCreator::getSerializedSize() const { return 6; } +void SpacePacketCreator::setCcsdsLenFromTotalDataFieldLen(size_t actualLength) { + if (actualLength == 0) { + return; + } + setDataLenField(actualLength - 1); +} +size_t SpacePacketCreator::getSerializedSize() const { return ccsds::HEADER_LEN; } ReturnValue_t SpacePacketCreator::deSerialize(const uint8_t **buffer, size_t *size, SerializeIF::Endianness streamEndianness) { @@ -64,7 +70,7 @@ void SpacePacketCreator::setSeqCount(uint16_t seqCount) { void SpacePacketCreator::setSeqFlags(ccsds::SequenceFlags flags) { params.packetSeqCtrl.seqFlags = flags; } -void SpacePacketCreator::setDataLen(uint16_t dataLen_) { params.dataLen = dataLen_; } +void SpacePacketCreator::setDataLenField(uint16_t dataLen_) { params.dataLen = dataLen_; } void SpacePacketCreator::checkFieldValidity() { valid = true; if (params.packetId.apid > ccsds::LIMIT_APID or diff --git a/src/fsfw/tmtcpacket/ccsds/SpacePacketCreator.h b/src/fsfw/tmtcpacket/ccsds/SpacePacketCreator.h index 5869560d..59234a1b 100644 --- a/src/fsfw/tmtcpacket/ccsds/SpacePacketCreator.h +++ b/src/fsfw/tmtcpacket/ccsds/SpacePacketCreator.h @@ -38,24 +38,51 @@ class SpacePacketCreator : public SpacePacketIF, public SerializeIF { [[nodiscard]] uint16_t getPacketDataLen() const override; SpacePacketParams &getParams(); + /** + * Sets the CCSDS data length field from the actual data field length. The field will contain + * the actual length minus one. This means that the minimum allowed size is one, as is also + * specified in 4.1.4.1.2 of the standard. Values of 0 will be ignored. + * @param dataFieldLen + */ + void setCcsdsLenFromTotalDataFieldLen(size_t dataFieldLen); void setParams(SpacePacketParams params); void setSecHeaderFlag(); void setPacketType(ccsds::PacketType type); void setApid(uint16_t apid); void setSeqCount(uint16_t seqCount); void setSeqFlags(ccsds::SequenceFlags flags); - void setDataLen(uint16_t dataLen); + void setDataLenField(uint16_t dataLen); + /** + * Please note that this method will only serialize the header part of the space packet. + * @param buffer + * @param size + * @param maxSize + * @param streamEndianness + * @return + */ ReturnValue_t serialize(uint8_t **buffer, size_t *size, size_t maxSize, Endianness streamEndianness) const override; + /** + * This will always return 6 or ccsds::HEADER_LEN + * @return + */ [[nodiscard]] size_t getSerializedSize() const override; - ReturnValue_t deSerialize(const uint8_t **buffer, size_t *size, - Endianness streamEndianness) override; private: void checkFieldValidity(); bool valid{}; SpacePacketParams params{}; + + /** + * Forbidden to call and always return HasReturnvaluesIF::RETURN_FAILED + * @param buffer + * @param size + * @param streamEndianness + * @return + */ + ReturnValue_t deSerialize(const uint8_t **buffer, size_t *size, + Endianness streamEndianness) override; }; #endif // FSFW_TMTCPACKET_SPACEPACKETCREATOR_H diff --git a/src/fsfw/tmtcpacket/pus/tc/PusTcCreator.cpp b/src/fsfw/tmtcpacket/pus/tc/PusTcCreator.cpp index 2e786e6e..b40724ba 100644 --- a/src/fsfw/tmtcpacket/pus/tc/PusTcCreator.cpp +++ b/src/fsfw/tmtcpacket/pus/tc/PusTcCreator.cpp @@ -58,8 +58,9 @@ ReturnValue_t PusTcCreator::serialize(uint8_t **buffer, size_t *size, size_t max } void PusTcCreator::updateSpLengthField() { - spCreator.setDataLen(ecss::PusTcDataFieldHeader::MIN_SIZE + pusParams.dataWrapper.getLength() + - 1); + spCreator.setCcsdsLenFromTotalDataFieldLen(ecss::PusTcDataFieldHeader::MIN_SIZE + + pusParams.dataWrapper.getLength() + + sizeof(ecss::PusChecksumT)); } size_t PusTcCreator::getSerializedSize() const { return spCreator.getFullPacketLen(); } diff --git a/src/fsfw/tmtcpacket/pus/tm/PusTmCreator.cpp b/src/fsfw/tmtcpacket/pus/tm/PusTmCreator.cpp index 64dbbfeb..eefcbec7 100644 --- a/src/fsfw/tmtcpacket/pus/tm/PusTmCreator.cpp +++ b/src/fsfw/tmtcpacket/pus/tm/PusTmCreator.cpp @@ -111,12 +111,12 @@ TimeStamperIF* PusTmCreator::getTimestamper() const { return pusParams.secHeader SpacePacketParams& PusTmCreator::getSpParams() { return spCreator.getParams(); } void PusTmCreator::updateSpLengthField() { - size_t headerLen = PusTmIF::MIN_SEC_HEADER_LEN + pusParams.dataWrapper.getLength() + - sizeof(ecss::PusChecksumT) - 1; + size_t headerLen = + PusTmIF::MIN_SEC_HEADER_LEN + pusParams.dataWrapper.getLength() + sizeof(ecss::PusChecksumT); if (pusParams.secHeader.timeStamper != nullptr) { headerLen += pusParams.secHeader.timeStamper->getSerializedSize(); } - spCreator.setDataLen(headerLen); + spCreator.setCcsdsLenFromTotalDataFieldLen(headerLen); } void PusTmCreator::setApid(uint16_t apid) { spCreator.setApid(apid); } diff --git a/unittests/cfdp/testTlvsLvs.cpp b/unittests/cfdp/testTlvsLvs.cpp index c251fd15..98dec980 100644 --- a/unittests/cfdp/testTlvsLvs.cpp +++ b/unittests/cfdp/testTlvsLvs.cpp @@ -16,15 +16,15 @@ TEST_CASE("CFDP TLV LV", "[CfdpTlvLv]") { using namespace cfdp; - int result = HasReturnvaluesIF::RETURN_OK; - std::array rawBuf; + ReturnValue_t result; + std::array rawBuf{}; uint8_t* serPtr = rawBuf.data(); const uint8_t* deserPtr = rawBuf.data(); size_t deserSize = 0; cfdp::EntityId sourceId = EntityId(cfdp::WidthInBytes::TWO_BYTES, 0x0ff0); SECTION("TLV Serialization") { - std::array tlvRawBuf; + std::array tlvRawBuf{}; serPtr = tlvRawBuf.data(); result = sourceId.serialize(&serPtr, &deserSize, tlvRawBuf.size(), SerializeIF::Endianness::NETWORK); @@ -88,7 +88,7 @@ TEST_CASE("CFDP TLV LV", "[CfdpTlvLv]") { SECTION("TLV Deserialization") { // Serialization was tested before, generate raw data now - std::array tlvRawBuf; + std::array tlvRawBuf{}; serPtr = tlvRawBuf.data(); result = sourceId.serialize(&serPtr, &deserSize, tlvRawBuf.size(), SerializeIF::Endianness::NETWORK); @@ -136,7 +136,7 @@ TEST_CASE("CFDP TLV LV", "[CfdpTlvLv]") { } SECTION("LV Serialization") { - std::array lvRawBuf; + std::array lvRawBuf{}; serPtr = lvRawBuf.data(); result = sourceId.serialize(&serPtr, &deserSize, lvRawBuf.size(), SerializeIF::Endianness::NETWORK); diff --git a/unittests/tcdistributor/testCcsdsDistributor.cpp b/unittests/tcdistributor/testCcsdsDistributor.cpp index 8aa248fa..30e96945 100644 --- a/unittests/tcdistributor/testCcsdsDistributor.cpp +++ b/unittests/tcdistributor/testCcsdsDistributor.cpp @@ -28,15 +28,25 @@ TEST_CASE("CCSDS Distributor", "[ccsds-distrib]") { SpacePacketCreator spCreator(spParams); std::array buf{}; - auto createSpacePacket = [&](uint16_t apid, TmTcMessage& msg) { + auto createSpacePacket = [&](uint16_t apid, TmTcMessage& msg, uint8_t* dataField = nullptr, + size_t dataFieldLen = 1) { store_address_t storeId{}; spCreator.setApid(tcAcceptorApid); + spCreator.setCcsdsLenFromTotalDataFieldLen(dataFieldLen); uint8_t* dataPtr; - REQUIRE(pool.getFreeElement(&storeId, spCreator.getSerializedSize(), &dataPtr) == result::OK); + REQUIRE(pool.getFreeElement(&storeId, spCreator.getSerializedSize() + dataFieldLen, &dataPtr) == + result::OK); size_t serLen = 0; REQUIRE(spCreator.SerializeIF::serializeBe(dataPtr, serLen, ccsds::HEADER_LEN) == result::OK); REQUIRE(spCreator.SerializeIF::serializeBe(buf.data(), serLen, ccsds::HEADER_LEN) == result::OK); + if (dataField == nullptr) { + dataPtr[ccsds::HEADER_LEN] = 0; + buf[ccsds::HEADER_LEN] = 0; + } else { + std::memcpy(dataPtr + ccsds::HEADER_LEN, dataField, dataFieldLen); + std::memcpy(buf.data() + ccsds::HEADER_LEN, dataField, dataFieldLen); + } msg.setStorageId(storeId); }; @@ -57,7 +67,7 @@ TEST_CASE("CCSDS Distributor", "[ccsds-distrib]") { store_address_t storeId = message.getStorageId(); queue.addReceivedMessage(message); REQUIRE(ccsdsDistrib.performOperation(0) == result::OK); - CHECK(checkerMock.checkedPacketLen == 6); + CHECK(checkerMock.checkedPacketLen == 7); CHECK(checkerMock.checkCallCount == 1); CHECK(queue.wasMessageSent()); CHECK(queue.numberOfSentMessages() == 1); @@ -68,7 +78,7 @@ TEST_CASE("CCSDS Distributor", "[ccsds-distrib]") { CHECK(sentMsg.getStorageId() == storeId); auto accessor = pool.getData(storeId); CHECK(accessor.first == result::OK); - CHECK(accessor.second.size() == ccsds::HEADER_LEN); + CHECK(accessor.second.size() == ccsds::HEADER_LEN + 1); for (size_t i = 0; i < ccsds::HEADER_LEN; i++) { CHECK(accessor.second.data()[i] == buf[i]); } @@ -92,7 +102,7 @@ TEST_CASE("CCSDS Distributor", "[ccsds-distrib]") { message.setStorageId(storeId); queue.addReceivedMessage(message); REQUIRE(ccsdsDistrib.performOperation(0) == result::OK); - CHECK(checkerMock.checkedPacketLen == 6); + CHECK(checkerMock.checkedPacketLen == 7); CHECK(checkerMock.checkCallCount == 1); CHECK(queue.wasMessageSent()); CHECK(queue.numberOfSentMessages() == 1); @@ -103,11 +113,56 @@ TEST_CASE("CCSDS Distributor", "[ccsds-distrib]") { CHECK(sentMsg.getStorageId() == storeId); auto accessor = pool.getData(storeId); CHECK(accessor.first == result::OK); - CHECK(accessor.second.size() == ccsds::HEADER_LEN); + CHECK(accessor.second.size() == ccsds::HEADER_LEN + 1); for (size_t i = 0; i < ccsds::HEADER_LEN; i++) { CHECK(accessor.second.data()[i] == buf[i]); } } - SECTION("Remove CCSDS header") {} + SECTION("Remove CCSDS header") { + uint16_t tgtApid = 0; + MessageQueueId_t tgtQueueId = MessageQueueIF::NO_QUEUE; + SECTION("Default destination") { + CcsdsDistributor::DestInfo info(defReceiverMock, true); + tgtApid = defaultApid; + tgtQueueId = defaultQueueId; + REQUIRE(ccsdsDistrib.registerApplication(info) == result::OK); + } + SECTION("Specific destination") { + CcsdsDistributor::DestInfo info(tcAcceptorMock, true); + tgtApid = tcAcceptorApid; + tgtQueueId = tcAcceptorQueueId; + REQUIRE(ccsdsDistrib.registerApplication(info) == result::OK); + } + TmTcMessage message; + std::array dataField = {0, 1, 2, 3, 4}; + createSpacePacket(tgtApid, message, dataField.data(), 5); + store_address_t storeId = message.getStorageId(); + message.setStorageId(storeId); + queue.addReceivedMessage(message); + REQUIRE(ccsdsDistrib.performOperation(0) == result::OK); + CHECK(checkerMock.checkedPacketLen == 11); + CHECK(checkerMock.checkCallCount == 1); + // Data was deleted from old slot to re-store without the header + CHECK(not pool.hasDataAtId(storeId)); + TmTcMessage sentMsg; + CHECK(queue.getNextSentMessage(tgtQueueId, sentMsg) == result::OK); + CHECK(sentMsg.getStorageId() != storeId); + auto accessor = pool.getData(sentMsg.getStorageId()); + CHECK(accessor.first == result::OK); + CHECK(accessor.second.size() == 5); + // Verify correctness of data field + for (size_t i = 0; i < 5; i++) { + CHECK(accessor.second.data()[i] == i); + } + } + + SECTION("Invalid Space Packet, Too Short") { + store_address_t storeId{}; + std::array data = {1, 2, 3, 4}; + pool.addData(&storeId, data.data(), data.size()); + TmTcMessage message(storeId); + queue.addReceivedMessage(message); + REQUIRE(ccsdsDistrib.performOperation(0) == SerializeIF::STREAM_TOO_SHORT); + } } \ No newline at end of file diff --git a/unittests/tmtcpacket/testCcsdsCreator.cpp b/unittests/tmtcpacket/testCcsdsCreator.cpp index 465e6475..b4a089d0 100644 --- a/unittests/tmtcpacket/testCcsdsCreator.cpp +++ b/unittests/tmtcpacket/testCcsdsCreator.cpp @@ -39,7 +39,8 @@ TEST_CASE("CCSDS Creator", "[ccsds-creator]") { SECTION("Deserialization Fails") { serLen = 6; const uint8_t* readOnlyPtr = buf.data(); - REQUIRE(base.deSerialize(&readOnlyPtr, &serLen, SerializeIF::Endianness::BIG) == + SerializeIF& ser = dynamic_cast(base); + REQUIRE(ser.deSerialize(&readOnlyPtr, &serLen, SerializeIF::Endianness::BIG) == HasReturnvaluesIF::RETURN_FAILED); } @@ -64,7 +65,7 @@ TEST_CASE("CCSDS Creator", "[ccsds-creator]") { base.setApid(static_cast(std::pow(2, 11)) - 1); base.setSeqCount(static_cast(std::pow(2, 14)) - 1); base.setSeqFlags(ccsds::SequenceFlags::UNSEGMENTED); - base.setDataLen(static_cast(std::pow(2, 16)) - 1); + base.setDataLenField(static_cast(std::pow(2, 16)) - 1); REQUIRE(base.isValid()); REQUIRE(base.serializeBe(&bufPtr, &serLen, buf.size()) == HasReturnvaluesIF::RETURN_OK); CHECK(buf[0] == 0x1F); @@ -75,6 +76,15 @@ TEST_CASE("CCSDS Creator", "[ccsds-creator]") { CHECK(buf[5] == 0xFF); } + SECTION("Setting data length 0 is ignored") { + SpacePacketCreator creator = SpacePacketCreator( + ccsds::PacketType::TC, true, 0xFFFF, ccsds::SequenceFlags::FIRST_SEGMENT, 0x34, 0x22); + creator.setCcsdsLenFromTotalDataFieldLen(0); + REQUIRE(creator.getPacketDataLen() == 0x22); + creator.setCcsdsLenFromTotalDataFieldLen(1); + REQUIRE(creator.getPacketDataLen() == 0x00); + } + SECTION("Invalid APID") { SpacePacketCreator creator = SpacePacketCreator( ccsds::PacketType::TC, true, 0xFFFF, ccsds::SequenceFlags::FIRST_SEGMENT, 0x34, 0x16); From b0c479cab9bffedfcf5529727b72be673d3282d5 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Wed, 3 Aug 2022 11:34:30 +0200 Subject: [PATCH 010/169] remove some shadowing warnings --- unittests/cfdp/testTlvsLvs.cpp | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/unittests/cfdp/testTlvsLvs.cpp b/unittests/cfdp/testTlvsLvs.cpp index 98dec980..90dd688c 100644 --- a/unittests/cfdp/testTlvsLvs.cpp +++ b/unittests/cfdp/testTlvsLvs.cpp @@ -153,10 +153,10 @@ TEST_CASE("CFDP TLV LV", "[CfdpTlvLv]") { REQUIRE(result == HasReturnvaluesIF::RETURN_OK); REQUIRE(deserSize == 3); REQUIRE(rawBuf[0] == 2); - uint16_t sourceId = 0; - result = SerializeAdapter::deSerialize(&sourceId, rawBuf.data() + 1, &deserSize, + uint16_t sourceIdRaw = 0; + result = SerializeAdapter::deSerialize(&sourceIdRaw, rawBuf.data() + 1, &deserSize, SerializeIF::Endianness::BIG); - REQUIRE(sourceId == 0x0ff0); + REQUIRE(sourceIdRaw == 0x0ff0); auto lvEmpty = Lv(nullptr, 0); REQUIRE(lvEmpty.getSerializedSize() == 1); @@ -169,7 +169,7 @@ TEST_CASE("CFDP TLV LV", "[CfdpTlvLv]") { } SECTION("LV Deserialization") { - std::array lvRawBuf; + std::array lvRawBuf{}; serPtr = lvRawBuf.data(); result = sourceId.serialize(&serPtr, &deserSize, lvRawBuf.size(), SerializeIF::Endianness::NETWORK); @@ -186,10 +186,10 @@ TEST_CASE("CFDP TLV LV", "[CfdpTlvLv]") { REQUIRE(result == HasReturnvaluesIF::RETURN_OK); REQUIRE(uninitLv.getSerializedSize() == 3); const uint8_t* storedValue = uninitLv.getValue(nullptr); - uint16_t sourceId = 0; - result = SerializeAdapter::deSerialize(&sourceId, storedValue, &deserSize, + uint16_t sourceIdRaw = 0; + result = SerializeAdapter::deSerialize(&sourceIdRaw, storedValue, &deserSize, SerializeIF::Endianness::BIG); - REQUIRE(sourceId == 0x0ff0); + REQUIRE(sourceIdRaw == 0x0ff0); auto lvEmpty = Lv(nullptr, 0); REQUIRE(lvEmpty.getSerializedSize() == 1); @@ -306,7 +306,7 @@ TEST_CASE("CFDP TLV LV", "[CfdpTlvLv]") { FaultHandlerOverrideTlv faultOverrideTlv(cfdp::ConditionCode::FILESTORE_REJECTION, cfdp::FaultHandlerCode::NOTICE_OF_CANCELLATION); size_t sz = 0; - ReturnValue_t result = + result = faultOverrideTlv.serialize(&serPtr, &sz, rawBuf.size(), SerializeIF::Endianness::NETWORK); REQUIRE(faultOverrideTlv.getSerializedSize() == 3); REQUIRE(sz == 3); From df690b9628251b0515ef39637bb2159ae16dc9a6 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Wed, 3 Aug 2022 11:36:56 +0200 Subject: [PATCH 011/169] some re-ordering --- src/fsfw/tcdistribution/CcsdsDistributor.cpp | 13 +++++++++---- src/fsfw/tcdistribution/CcsdsDistributor.h | 1 + 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/src/fsfw/tcdistribution/CcsdsDistributor.cpp b/src/fsfw/tcdistribution/CcsdsDistributor.cpp index 2e09e71f..0ec5ed5c 100644 --- a/src/fsfw/tcdistribution/CcsdsDistributor.cpp +++ b/src/fsfw/tcdistribution/CcsdsDistributor.cpp @@ -16,7 +16,11 @@ CcsdsDistributor::CcsdsDistributor(uint16_t setDefaultApid, object_id_t setObjec tcStore(tcStore), packetChecker(packetChecker) {} -CcsdsDistributor::~CcsdsDistributor() = default; +CcsdsDistributor::~CcsdsDistributor() { + if (ownedPacketChecker) { + delete packetChecker; + } +} ReturnValue_t CcsdsDistributor::selectDestination(MessageQueueId_t& destId) { #if CCSDS_DISTRIBUTOR_DEBUGGING == 1 @@ -123,13 +127,14 @@ ReturnValue_t CcsdsDistributor::registerApplication(DestInfo info) { uint32_t CcsdsDistributor::getIdentifier() const { return 0; } ReturnValue_t CcsdsDistributor::initialize() { - if (packetChecker == nullptr) { - packetChecker = new CcsdsPacketChecker(ccsds::PacketType::TC); - } ReturnValue_t result = TcDistributorBase::initialize(); if (result != HasReturnvaluesIF::RETURN_OK) { return result; } + if (packetChecker == nullptr) { + ownedPacketChecker = true; + packetChecker = new CcsdsPacketChecker(ccsds::PacketType::TC); + } if (tcStore == nullptr) { tcStore = ObjectManager::instance()->get(objects::TC_STORE); if (tcStore == nullptr) { diff --git a/src/fsfw/tcdistribution/CcsdsDistributor.h b/src/fsfw/tcdistribution/CcsdsDistributor.h index 0444a868..83199646 100644 --- a/src/fsfw/tcdistribution/CcsdsDistributor.h +++ b/src/fsfw/tcdistribution/CcsdsDistributor.h @@ -78,6 +78,7 @@ class CcsdsDistributor : public TcDistributorBase, */ StorageManagerIF* tcStore = nullptr; + bool ownedPacketChecker = false; CcsdsPacketCheckIF* packetChecker = nullptr; }; From 60ea9a9a7cee194cc3faee7d5122bae4c60c334d Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Wed, 3 Aug 2022 13:15:49 +0200 Subject: [PATCH 012/169] clean up a few tests --- scripts/auto-formatter.sh | 3 +- src/fsfw/cfdp/definitions.h | 14 ++++---- src/fsfw/cfdp/pdu/PduConfig.cpp | 12 ++++--- src/fsfw/cfdp/pdu/PduConfig.h | 4 +-- src/fsfw/cfdp/pdu/VarLenField.cpp | 7 ++++ src/fsfw/cfdp/pdu/VarLenField.h | 12 ++++--- unittests/CMakeLists.txt | 13 ++----- unittests/action/CMakeLists.txt | 4 +-- unittests/cfdp/CMakeLists.txt | 25 ++++++------- unittests/cfdp/testAckPdu.cpp | 46 ++++++++++++------------ unittests/cfdp/testCfdp.cpp | 25 ++++++------- unittests/cfdp/testCfdpHeader.cpp | 3 ++ unittests/cfdp/testEofPdu.cpp | 2 +- unittests/cfdp/testFileData.cpp | 2 +- unittests/cfdp/testFinishedPdu.cpp | 2 +- unittests/cfdp/testKeepAlivePdu.cpp | 2 +- unittests/cfdp/testMetadataPdu.cpp | 2 +- unittests/cfdp/testNakPdu.cpp | 2 +- unittests/cfdp/testPromptPdu.cpp | 4 +-- unittests/container/CMakeLists.txt | 20 +++++------ unittests/datapoollocal/CMakeLists.txt | 9 ++--- unittests/devicehandler/CMakeLists.txt | 6 ++-- unittests/globalfunctions/CMakeLists.txt | 10 ++---- unittests/hal/CMakeLists.txt | 4 +-- unittests/internalerror/CMakeLists.txt | 4 +-- unittests/mocks/CMakeLists.txt | 32 ++++++++--------- unittests/osal/CMakeLists.txt | 7 ++-- unittests/power/CMakeLists.txt | 4 +-- unittests/serialize/CMakeLists.txt | 9 ++--- unittests/storagemanager/CMakeLists.txt | 5 +-- unittests/tcdistributor/CMakeLists.txt | 4 +-- unittests/testcfg/CMakeLists.txt | 21 ++++------- unittests/timemanager/CMakeLists.txt | 5 +-- unittests/tmtcpacket/CMakeLists.txt | 20 +++++------ unittests/tmtcservices/CMakeLists.txt | 8 ++--- unittests/util/CMakeLists.txt | 6 ++-- 36 files changed, 160 insertions(+), 198 deletions(-) create mode 100644 unittests/cfdp/testCfdpHeader.cpp diff --git a/scripts/auto-formatter.sh b/scripts/auto-formatter.sh index c0ae7099..97b4bcc1 100755 --- a/scripts/auto-formatter.sh +++ b/scripts/auto-formatter.sh @@ -7,7 +7,8 @@ cmake_fmt="cmake-format" file_selectors="-iname CMakeLists.txt" if command -v ${cmake_fmt} &> /dev/null; then ${cmake_fmt} -i CMakeLists.txt - find ./src ${file_selectors} | xargs ${cmake_fmt} -i + find ./src ${file_selectors} | xargs ${cmake_fmt} -i + find ./unittests ${file_selectors} | xargs ${cmake_fmt} -i else echo "No ${cmake_fmt} tool found, not formatting CMake files" fi diff --git a/src/fsfw/cfdp/definitions.h b/src/fsfw/cfdp/definitions.h index 772b3ae3..6b3b11e3 100644 --- a/src/fsfw/cfdp/definitions.h +++ b/src/fsfw/cfdp/definitions.h @@ -42,17 +42,17 @@ enum ChecksumType { NULL_CHECKSUM = 15 }; -enum PduType : bool { FILE_DIRECTIVE = 0, FILE_DATA = 1 }; +enum PduType : uint8_t { FILE_DIRECTIVE = 0, FILE_DATA = 1 }; -enum TransmissionModes : bool { ACKNOWLEDGED = 0, UNACKNOWLEDGED = 1 }; +enum TransmissionModes : uint8_t { ACKNOWLEDGED = 0, UNACKNOWLEDGED = 1 }; -enum SegmentMetadataFlag : bool { NOT_PRESENT = 0, PRESENT = 1 }; +enum SegmentMetadataFlag : bool { NOT_PRESENT = false, PRESENT = true }; -enum Direction : bool { TOWARDS_RECEIVER = 0, TOWARDS_SENDER = 1 }; +enum Direction : uint8_t { TOWARDS_RECEIVER = 0, TOWARDS_SENDER = 1 }; enum SegmentationControl : bool { - NO_RECORD_BOUNDARIES_PRESERVATION = 0, - RECORD_BOUNDARIES_PRESERVATION = 1 + NO_RECORD_BOUNDARIES_PRESERVATION = false, + RECORD_BOUNDARIES_PRESERVATION = true }; enum WidthInBytes : uint8_t { @@ -106,7 +106,7 @@ enum FinishedFileStatus { FILE_STATUS_UNREPORTED = 3 }; -enum PromptResponseRequired : bool { PROMPT_NAK = 0, PROMPT_KEEP_ALIVE = 1 }; +enum PromptResponseRequired : uint8_t { PROMPT_NAK = 0, PROMPT_KEEP_ALIVE = 1 }; enum TlvTypes : uint8_t { FILESTORE_REQUEST = 0x00, diff --git a/src/fsfw/cfdp/pdu/PduConfig.cpp b/src/fsfw/cfdp/pdu/PduConfig.cpp index d495f864..dd04e986 100644 --- a/src/fsfw/cfdp/pdu/PduConfig.cpp +++ b/src/fsfw/cfdp/pdu/PduConfig.cpp @@ -1,12 +1,14 @@ #include "PduConfig.h" -PduConfig::PduConfig(cfdp::TransmissionModes mode, cfdp::TransactionSeqNum seqNum, - cfdp::EntityId sourceId, cfdp::EntityId destId, bool crcFlag, bool largeFile, +#include + +PduConfig::PduConfig(cfdp::EntityId sourceId, cfdp::EntityId destId, cfdp::TransmissionModes mode, + cfdp::TransactionSeqNum seqNum, bool crcFlag, bool largeFile, cfdp::Direction direction) : mode(mode), - seqNum(seqNum), - sourceId(sourceId), - destId(destId), + seqNum(std::move(seqNum)), + sourceId(std::move(sourceId)), + destId(std::move(destId)), crcFlag(crcFlag), largeFile(largeFile), direction(direction) {} diff --git a/src/fsfw/cfdp/pdu/PduConfig.h b/src/fsfw/cfdp/pdu/PduConfig.h index e5b52e52..f92b25fc 100644 --- a/src/fsfw/cfdp/pdu/PduConfig.h +++ b/src/fsfw/cfdp/pdu/PduConfig.h @@ -21,8 +21,8 @@ struct TransactionSeqNum : public VarLenField { class PduConfig { public: - PduConfig(cfdp::TransmissionModes mode, cfdp::TransactionSeqNum seqNum, cfdp::EntityId sourceId, - cfdp::EntityId destId, bool crcFlag = false, bool largeFile = false, + PduConfig(cfdp::EntityId sourceId, cfdp::EntityId destId, cfdp::TransmissionModes mode, + cfdp::TransactionSeqNum seqNum, bool crcFlag = false, bool largeFile = false, cfdp::Direction direction = cfdp::Direction::TOWARDS_RECEIVER); cfdp::TransmissionModes mode; cfdp::TransactionSeqNum seqNum; diff --git a/src/fsfw/cfdp/pdu/VarLenField.cpp b/src/fsfw/cfdp/pdu/VarLenField.cpp index b11c3b09..cb72735e 100644 --- a/src/fsfw/cfdp/pdu/VarLenField.cpp +++ b/src/fsfw/cfdp/pdu/VarLenField.cpp @@ -118,3 +118,10 @@ ReturnValue_t cfdp::VarLenField::deSerialize(const uint8_t **buffer, size_t *siz } } } + +template +cfdp::VarLenField::VarLenField(UnsignedByteField byteField) + : width(static_cast(sizeof(T))) { + static_assert((sizeof(T) % 2) == 0); + value = byteField.getValue(); +} diff --git a/src/fsfw/cfdp/pdu/VarLenField.h b/src/fsfw/cfdp/pdu/VarLenField.h index 590c2dd5..3b7ccc5a 100644 --- a/src/fsfw/cfdp/pdu/VarLenField.h +++ b/src/fsfw/cfdp/pdu/VarLenField.h @@ -4,9 +4,9 @@ #include #include -#include "../definitions.h" +#include "fsfw/cfdp/definitions.h" #include "fsfw/serialize/SerializeIF.h" - +#include "fsfw/util/UnsignedByteField.h" namespace cfdp { class VarLenField : public SerializeIF { @@ -19,6 +19,8 @@ class VarLenField : public SerializeIF { }; VarLenField(); + template + explicit VarLenField(UnsignedByteField byteField); VarLenField(cfdp::WidthInBytes width, size_t value); ReturnValue_t setValue(cfdp::WidthInBytes, size_t value); @@ -26,13 +28,13 @@ class VarLenField : public SerializeIF { ReturnValue_t serialize(uint8_t **buffer, size_t *size, size_t maxSize, Endianness streamEndianness) const override; - size_t getSerializedSize() const override; + [[nodiscard]] size_t getSerializedSize() const override; ReturnValue_t deSerialize(cfdp::WidthInBytes width, const uint8_t **buffer, size_t *size, Endianness streamEndianness); - cfdp::WidthInBytes getWidth() const; - size_t getValue() const; + [[nodiscard]] cfdp::WidthInBytes getWidth() const; + [[nodiscard]] size_t getValue() const; private: ReturnValue_t deSerialize(const uint8_t **buffer, size_t *size, diff --git a/unittests/CMakeLists.txt b/unittests/CMakeLists.txt index 595d9553..1f52a52e 100644 --- a/unittests/CMakeLists.txt +++ b/unittests/CMakeLists.txt @@ -1,14 +1,7 @@ -target_sources(${FSFW_TEST_TGT} PRIVATE - CatchDefinitions.cpp - CatchFactory.cpp - printChar.cpp - testVersion.cpp -) +target_sources(${FSFW_TEST_TGT} PRIVATE CatchDefinitions.cpp CatchFactory.cpp + printChar.cpp testVersion.cpp) -target_sources(${FSFW_TEST_TGT} PRIVATE - CatchRunner.cpp - CatchSetup.cpp -) +target_sources(${FSFW_TEST_TGT} PRIVATE CatchRunner.cpp CatchSetup.cpp) add_subdirectory(testcfg) add_subdirectory(mocks) diff --git a/unittests/action/CMakeLists.txt b/unittests/action/CMakeLists.txt index 659f251a..99941357 100644 --- a/unittests/action/CMakeLists.txt +++ b/unittests/action/CMakeLists.txt @@ -1,3 +1 @@ -target_sources(${FSFW_TEST_TGT} PRIVATE - TestActionHelper.cpp -) +target_sources(${FSFW_TEST_TGT} PRIVATE TestActionHelper.cpp) diff --git a/unittests/cfdp/CMakeLists.txt b/unittests/cfdp/CMakeLists.txt index 8e18cd3b..fcae5bba 100644 --- a/unittests/cfdp/CMakeLists.txt +++ b/unittests/cfdp/CMakeLists.txt @@ -1,12 +1,13 @@ -target_sources(${FSFW_TEST_TGT} PRIVATE - testCfdp.cpp - testTlvsLvs.cpp - testAckPdu.cpp - testEofPdu.cpp - testNakPdu.cpp - testFinishedPdu.cpp - testPromptPdu.cpp - testKeepAlivePdu.cpp - testMetadataPdu.cpp - testFileData.cpp -) +target_sources( + ${FSFW_TEST_TGT} + PRIVATE testCfdp.cpp + testTlvsLvs.cpp + testAckPdu.cpp + testEofPdu.cpp + testNakPdu.cpp + testFinishedPdu.cpp + testPromptPdu.cpp + testKeepAlivePdu.cpp + testMetadataPdu.cpp + testFileData.cpp + testCfdpHeader.cpp) diff --git a/unittests/cfdp/testAckPdu.cpp b/unittests/cfdp/testAckPdu.cpp index e5668799..70451aa0 100644 --- a/unittests/cfdp/testAckPdu.cpp +++ b/unittests/cfdp/testAckPdu.cpp @@ -7,7 +7,7 @@ TEST_CASE("ACK PDU", "[AckPdu]") { using namespace cfdp; - ReturnValue_t result = HasReturnvaluesIF::RETURN_OK; + ReturnValue_t result; std::array buf = {}; uint8_t* bufptr = buf.data(); size_t maxsz = buf.size(); @@ -15,7 +15,7 @@ TEST_CASE("ACK PDU", "[AckPdu]") { auto seqNum = TransactionSeqNum(WidthInBytes::TWO_BYTES, 15); auto sourceId = EntityId(WidthInBytes::TWO_BYTES, 1); auto destId = EntityId(WidthInBytes::TWO_BYTES, 2); - auto pduConf = PduConfig(TransmissionModes::ACKNOWLEDGED, seqNum, sourceId, destId); + auto pduConf = PduConfig(sourceId, destId, TransmissionModes::ACKNOWLEDGED, seqNum); AckInfo ackInfo(FileDirectives::EOF_DIRECTIVE, ConditionCode::NO_ERROR, AckTransactionStatus::ACTIVE); auto ackSerializer = AckPduSerializer(ackInfo, pduConf); @@ -23,10 +23,10 @@ TEST_CASE("ACK PDU", "[AckPdu]") { REQUIRE(result == HasReturnvaluesIF::RETURN_OK); SECTION("Serialize") { - REQUIRE(buf.data()[sz - 3] == cfdp::FileDirectives::ACK); - REQUIRE((buf.data()[sz - 2] >> 4) == FileDirectives::EOF_DIRECTIVE); - REQUIRE((buf.data()[sz - 2] & 0x0f) == 0); - REQUIRE(buf.data()[sz - 1] == AckTransactionStatus::ACTIVE); + REQUIRE(buf[sz - 3] == cfdp::FileDirectives::ACK); + REQUIRE((buf[sz - 2] >> 4) == FileDirectives::EOF_DIRECTIVE); + REQUIRE((buf[sz - 2] & 0x0f) == 0); + REQUIRE(buf[sz - 1] == AckTransactionStatus::ACTIVE); ackInfo.setAckedDirective(FileDirectives::FINISH); ackInfo.setAckedConditionCode(ConditionCode::FILESTORE_REJECTION); ackInfo.setTransactionStatus(AckTransactionStatus::TERMINATED); @@ -35,11 +35,11 @@ TEST_CASE("ACK PDU", "[AckPdu]") { sz = 0; result = ackSerializer2.serialize(&bufptr, &sz, maxsz, SerializeIF::Endianness::NETWORK); REQUIRE(result == HasReturnvaluesIF::RETURN_OK); - REQUIRE(buf.data()[sz - 3] == cfdp::FileDirectives::ACK); - REQUIRE((buf.data()[sz - 2] >> 4) == FileDirectives::FINISH); - REQUIRE((buf.data()[sz - 2] & 0x0f) == 0b0001); - REQUIRE((buf.data()[sz - 1] >> 4) == ConditionCode::FILESTORE_REJECTION); - REQUIRE((buf.data()[sz - 1] & 0b11) == AckTransactionStatus::TERMINATED); + REQUIRE(buf[sz - 3] == cfdp::FileDirectives::ACK); + REQUIRE((buf[sz - 2] >> 4) == FileDirectives::FINISH); + REQUIRE((buf[sz - 2] & 0x0f) == 0b0001); + REQUIRE((buf[sz - 1] >> 4) == ConditionCode::FILESTORE_REJECTION); + REQUIRE((buf[sz - 1] & 0b11) == AckTransactionStatus::TERMINATED); bufptr = buf.data(); sz = 0; @@ -56,14 +56,14 @@ TEST_CASE("ACK PDU", "[AckPdu]") { } SECTION("Deserialize") { - AckInfo ackInfo; - auto reader = AckPduDeserializer(buf.data(), sz, ackInfo); + AckInfo ackInfo2; + auto reader = AckPduDeserializer(buf.data(), sz, ackInfo2); result = reader.parseData(); REQUIRE(result == HasReturnvaluesIF::RETURN_OK); - REQUIRE(ackInfo.getAckedDirective() == FileDirectives::EOF_DIRECTIVE); - REQUIRE(ackInfo.getAckedConditionCode() == ConditionCode::NO_ERROR); - REQUIRE(ackInfo.getDirectiveSubtypeCode() == 0); - REQUIRE(ackInfo.getTransactionStatus() == AckTransactionStatus::ACTIVE); + REQUIRE(ackInfo2.getAckedDirective() == FileDirectives::EOF_DIRECTIVE); + REQUIRE(ackInfo2.getAckedConditionCode() == ConditionCode::NO_ERROR); + REQUIRE(ackInfo2.getDirectiveSubtypeCode() == 0); + REQUIRE(ackInfo2.getTransactionStatus() == AckTransactionStatus::ACTIVE); AckInfo newInfo = AckInfo(FileDirectives::FINISH, ConditionCode::FILESTORE_REJECTION, AckTransactionStatus::TERMINATED); @@ -73,13 +73,13 @@ TEST_CASE("ACK PDU", "[AckPdu]") { result = ackSerializer2.serialize(&bufptr, &sz, maxsz, SerializeIF::Endianness::NETWORK); REQUIRE(result == HasReturnvaluesIF::RETURN_OK); - auto reader2 = AckPduDeserializer(buf.data(), sz, ackInfo); + auto reader2 = AckPduDeserializer(buf.data(), sz, ackInfo2); result = reader2.parseData(); REQUIRE(result == HasReturnvaluesIF::RETURN_OK); - REQUIRE(ackInfo.getAckedDirective() == FileDirectives::FINISH); - REQUIRE(ackInfo.getAckedConditionCode() == ConditionCode::FILESTORE_REJECTION); - REQUIRE(ackInfo.getDirectiveSubtypeCode() == 0b0001); - REQUIRE(ackInfo.getTransactionStatus() == AckTransactionStatus::TERMINATED); + REQUIRE(ackInfo2.getAckedDirective() == FileDirectives::FINISH); + REQUIRE(ackInfo2.getAckedConditionCode() == ConditionCode::FILESTORE_REJECTION); + REQUIRE(ackInfo2.getDirectiveSubtypeCode() == 0b0001); + REQUIRE(ackInfo2.getTransactionStatus() == AckTransactionStatus::TERMINATED); uint8_t prevVal = buf[sz - 2]; buf[sz - 2] = FileDirectives::INVALID_DIRECTIVE << 4; @@ -93,7 +93,7 @@ TEST_CASE("ACK PDU", "[AckPdu]") { result = reader2.parseData(); REQUIRE(result == cfdp::INVALID_DIRECTIVE_FIELDS); buf[sz - 3] = cfdp::FileDirectives::ACK; - auto maxSizeTooSmall = AckPduDeserializer(buf.data(), sz - 2, ackInfo); + auto maxSizeTooSmall = AckPduDeserializer(buf.data(), sz - 2, ackInfo2); result = maxSizeTooSmall.parseData(); REQUIRE(result == SerializeIF::STREAM_TOO_SHORT); } diff --git a/unittests/cfdp/testCfdp.cpp b/unittests/cfdp/testCfdp.cpp index e7acab01..9184156c 100644 --- a/unittests/cfdp/testCfdp.cpp +++ b/unittests/cfdp/testCfdp.cpp @@ -13,13 +13,13 @@ TEST_CASE("CFDP Base", "[CfdpBase]") { using namespace cfdp; - std::array serBuf; + std::array serBuf{}; ReturnValue_t result = HasReturnvaluesIF::RETURN_OK; cfdp::TransactionSeqNum seqNum = TransactionSeqNum(cfdp::WidthInBytes::ONE_BYTE, 2); cfdp::EntityId sourceId = EntityId(cfdp::WidthInBytes::ONE_BYTE, 0); cfdp::EntityId destId = EntityId(cfdp::WidthInBytes::ONE_BYTE, 1); PduConfig pduConf = - PduConfig(cfdp::TransmissionModes::ACKNOWLEDGED, seqNum, sourceId, destId, false); + PduConfig(sourceId, destId, cfdp::TransmissionModes::ACKNOWLEDGED, seqNum, false); uint8_t* serTarget = serBuf.data(); const uint8_t* deserTarget = serTarget; size_t serSize = 0; @@ -79,8 +79,7 @@ TEST_CASE("CFDP Base", "[CfdpBase]") { REQUIRE(serBuf[6] == 1); for (uint8_t idx = 0; idx < 7; idx++) { - ReturnValue_t result = - headerSerializer.serialize(&serTarget, &serSize, idx, SerializeIF::Endianness::BIG); + result = headerSerializer.serialize(&serTarget, &serSize, idx, SerializeIF::Endianness::BIG); REQUIRE(result == static_cast(SerializeIF::BUFFER_TOO_SHORT)); } @@ -123,8 +122,7 @@ TEST_CASE("CFDP Base", "[CfdpBase]") { SerializeIF::Endianness::BIG); for (uint8_t idx = 0; idx < 14; idx++) { - ReturnValue_t result = - headerSerializer.serialize(&serTarget, &serSize, idx, SerializeIF::Endianness::BIG); + result = headerSerializer.serialize(&serTarget, &serSize, idx, SerializeIF::Endianness::BIG); REQUIRE(result == static_cast(SerializeIF::BUFFER_TOO_SHORT)); } REQUIRE(headerSerializer.getCrcFlag() == true); @@ -144,11 +142,11 @@ TEST_CASE("CFDP Base", "[CfdpBase]") { SerializeIF::Endianness::NETWORK); REQUIRE(deSerSize == 4); REQUIRE(entityId == 0xff00ff00); - uint16_t seqNum = 0; - SerializeAdapter::deSerialize(&seqNum, serBuf.data() + 8, &deSerSize, + uint16_t seqNumRaw = 0; + SerializeAdapter::deSerialize(&seqNumRaw, serBuf.data() + 8, &deSerSize, SerializeIF::Endianness::NETWORK); REQUIRE(deSerSize == 2); - REQUIRE(seqNum == 0x0fff); + REQUIRE(seqNumRaw == 0x0fff); SerializeAdapter::deSerialize(&entityId, serBuf.data() + 10, &deSerSize, SerializeIF::Endianness::NETWORK); REQUIRE(deSerSize == 4); @@ -195,8 +193,8 @@ TEST_CASE("CFDP Base", "[CfdpBase]") { // We unittested the serializer before, so we can use it now to generate valid raw CFDP // data auto headerSerializer = HeaderSerializer(pduConf, cfdp::PduType::FILE_DIRECTIVE, 0); - ReturnValue_t result = headerSerializer.serialize(&serTarget, &serSize, serBuf.size(), - SerializeIF::Endianness::BIG); + result = headerSerializer.serialize(&serTarget, &serSize, serBuf.size(), + SerializeIF::Endianness::BIG); REQUIRE(result == result::OK); REQUIRE(serBuf[1] == 0); REQUIRE(serBuf[2] == 0); @@ -272,7 +270,7 @@ TEST_CASE("CFDP Base", "[CfdpBase]") { size_t deSerSize = headerDeser.getWholePduSize(); serTarget = serBuf.data(); - const uint8_t** serTargetConst = const_cast(&serTarget); + const auto** serTargetConst = const_cast(&serTarget); result = headerDeser.parseData(); REQUIRE(result == result::OK); @@ -356,8 +354,7 @@ TEST_CASE("CFDP Base", "[CfdpBase]") { cfdp::FileSize fss; REQUIRE(fss.getSize() == 0); fss.setFileSize(0x20, false); - ReturnValue_t result = - fss.serialize(&buffer, &size, fssBuf.size(), SerializeIF::Endianness::MACHINE); + result = fss.serialize(&buffer, &size, fssBuf.size(), SerializeIF::Endianness::MACHINE); REQUIRE(result == HasReturnvaluesIF::RETURN_OK); uint32_t fileSize = 0; result = SerializeAdapter::deSerialize(&fileSize, fssBuf.data(), nullptr, diff --git a/unittests/cfdp/testCfdpHeader.cpp b/unittests/cfdp/testCfdpHeader.cpp new file mode 100644 index 00000000..77579bd4 --- /dev/null +++ b/unittests/cfdp/testCfdpHeader.cpp @@ -0,0 +1,3 @@ +// +// Created by rmueller on 8/3/22. +// diff --git a/unittests/cfdp/testEofPdu.cpp b/unittests/cfdp/testEofPdu.cpp index d400af5a..44e21bdf 100644 --- a/unittests/cfdp/testEofPdu.cpp +++ b/unittests/cfdp/testEofPdu.cpp @@ -20,7 +20,7 @@ TEST_CASE("EOF PDU", "[EofPdu]") { TransactionSeqNum seqNum(WidthInBytes::TWO_BYTES, 15); EntityId sourceId(WidthInBytes::TWO_BYTES, 1); - PduConfig pduConf(TransmissionModes::ACKNOWLEDGED, seqNum, sourceId, destId); + PduConfig pduConf(sourceId, destId, TransmissionModes::ACKNOWLEDGED, seqNum); auto eofSerializer = EofPduSerializer(pduConf, eofInfo); SECTION("Serialize") { diff --git a/unittests/cfdp/testFileData.cpp b/unittests/cfdp/testFileData.cpp index 1f6a09e9..fcf586eb 100644 --- a/unittests/cfdp/testFileData.cpp +++ b/unittests/cfdp/testFileData.cpp @@ -17,7 +17,7 @@ TEST_CASE("File Data PDU", "[FileDataPdu]") { EntityId destId(WidthInBytes::TWO_BYTES, 2); TransactionSeqNum seqNum(WidthInBytes::TWO_BYTES, 15); EntityId sourceId(WidthInBytes::TWO_BYTES, 1); - PduConfig pduConf(TransmissionModes::ACKNOWLEDGED, seqNum, sourceId, destId); + PduConfig pduConf(sourceId, destId, TransmissionModes::ACKNOWLEDGED, seqNum); for (uint8_t idx = 0; idx < 10; idx++) { fileBuffer[idx] = idx; diff --git a/unittests/cfdp/testFinishedPdu.cpp b/unittests/cfdp/testFinishedPdu.cpp index 143eaf2a..f581ee0b 100644 --- a/unittests/cfdp/testFinishedPdu.cpp +++ b/unittests/cfdp/testFinishedPdu.cpp @@ -14,7 +14,7 @@ TEST_CASE("Finished PDU", "[FinishedPdu]") { EntityId destId(WidthInBytes::TWO_BYTES, 2); TransactionSeqNum seqNum(WidthInBytes::TWO_BYTES, 15); EntityId sourceId(WidthInBytes::TWO_BYTES, 1); - PduConfig pduConf(TransmissionModes::ACKNOWLEDGED, seqNum, sourceId, destId); + PduConfig pduConf(sourceId, destId, TransmissionModes::ACKNOWLEDGED, seqNum); cfdp::Lv emptyFsMsg; FinishedInfo info(cfdp::ConditionCode::INACTIVITY_DETECTED, diff --git a/unittests/cfdp/testKeepAlivePdu.cpp b/unittests/cfdp/testKeepAlivePdu.cpp index 8ec8c66c..e6eb919e 100644 --- a/unittests/cfdp/testKeepAlivePdu.cpp +++ b/unittests/cfdp/testKeepAlivePdu.cpp @@ -14,7 +14,7 @@ TEST_CASE("Keep Alive PDU", "[KeepAlivePdu]") { EntityId destId(WidthInBytes::TWO_BYTES, 2); TransactionSeqNum seqNum(WidthInBytes::TWO_BYTES, 15); EntityId sourceId(WidthInBytes::TWO_BYTES, 1); - PduConfig pduConf(TransmissionModes::ACKNOWLEDGED, seqNum, sourceId, destId); + PduConfig pduConf(sourceId, destId, TransmissionModes::ACKNOWLEDGED, seqNum); FileSize progress(0x50); diff --git a/unittests/cfdp/testMetadataPdu.cpp b/unittests/cfdp/testMetadataPdu.cpp index 331d64a9..71749af3 100644 --- a/unittests/cfdp/testMetadataPdu.cpp +++ b/unittests/cfdp/testMetadataPdu.cpp @@ -17,7 +17,7 @@ TEST_CASE("Metadata PDU", "[MetadataPdu]") { EntityId destId(WidthInBytes::TWO_BYTES, 2); TransactionSeqNum seqNum(WidthInBytes::TWO_BYTES, 15); EntityId sourceId(WidthInBytes::TWO_BYTES, 1); - PduConfig pduConf(TransmissionModes::ACKNOWLEDGED, seqNum, sourceId, destId); + PduConfig pduConf(sourceId, destId, TransmissionModes::ACKNOWLEDGED, seqNum); std::string firstFileName = "hello.txt"; cfdp::Lv sourceFileName(reinterpret_cast(firstFileName.data()), diff --git a/unittests/cfdp/testNakPdu.cpp b/unittests/cfdp/testNakPdu.cpp index 38b45300..eb112402 100644 --- a/unittests/cfdp/testNakPdu.cpp +++ b/unittests/cfdp/testNakPdu.cpp @@ -15,7 +15,7 @@ TEST_CASE("NAK PDU", "[NakPdu]") { EntityId destId(WidthInBytes::TWO_BYTES, 2); TransactionSeqNum seqNum(WidthInBytes::TWO_BYTES, 15); EntityId sourceId(WidthInBytes::TWO_BYTES, 1); - PduConfig pduConf(TransmissionModes::ACKNOWLEDGED, seqNum, sourceId, destId); + PduConfig pduConf(sourceId, destId, TransmissionModes::ACKNOWLEDGED, seqNum); FileSize startOfScope(50); FileSize endOfScope(1050); diff --git a/unittests/cfdp/testPromptPdu.cpp b/unittests/cfdp/testPromptPdu.cpp index 9f406aec..d8e33441 100644 --- a/unittests/cfdp/testPromptPdu.cpp +++ b/unittests/cfdp/testPromptPdu.cpp @@ -14,7 +14,7 @@ TEST_CASE("Prompt PDU", "[PromptPdu]") { EntityId destId(WidthInBytes::TWO_BYTES, 2); TransactionSeqNum seqNum(WidthInBytes::TWO_BYTES, 15); EntityId sourceId(WidthInBytes::TWO_BYTES, 1); - PduConfig pduConf(TransmissionModes::ACKNOWLEDGED, seqNum, sourceId, destId); + PduConfig pduConf(sourceId, destId, TransmissionModes::ACKNOWLEDGED, seqNum); SECTION("Serialize") { PromptPduSerializer serializer(pduConf, cfdp::PromptResponseRequired::PROMPT_KEEP_ALIVE); @@ -24,7 +24,7 @@ TEST_CASE("Prompt PDU", "[PromptPdu]") { REQUIRE(sz == 12); REQUIRE(serializer.getPduDataFieldLen() == 2); REQUIRE(rawBuf[10] == FileDirectives::PROMPT); - REQUIRE((rawBuf[sz - 1] >> 7) & 0x01 == cfdp::PromptResponseRequired::PROMPT_KEEP_ALIVE); + REQUIRE(((rawBuf[sz - 1] >> 7) & 0x01) == cfdp::PromptResponseRequired::PROMPT_KEEP_ALIVE); for (size_t invalidMaxSz = 0; invalidMaxSz < sz; invalidMaxSz++) { uint8_t* buffer = rawBuf.data(); diff --git a/unittests/container/CMakeLists.txt b/unittests/container/CMakeLists.txt index 5dae974c..d65e5993 100644 --- a/unittests/container/CMakeLists.txt +++ b/unittests/container/CMakeLists.txt @@ -1,10 +1,10 @@ -target_sources(${FSFW_TEST_TGT} PRIVATE - RingBufferTest.cpp - TestArrayList.cpp - TestDynamicFifo.cpp - TestFifo.cpp - TestFixedArrayList.cpp - TestFixedMap.cpp - TestFixedOrderedMultimap.cpp - TestPlacementFactory.cpp -) +target_sources( + ${FSFW_TEST_TGT} + PRIVATE RingBufferTest.cpp + TestArrayList.cpp + TestDynamicFifo.cpp + TestFifo.cpp + TestFixedArrayList.cpp + TestFixedMap.cpp + TestFixedOrderedMultimap.cpp + TestPlacementFactory.cpp) diff --git a/unittests/datapoollocal/CMakeLists.txt b/unittests/datapoollocal/CMakeLists.txt index 016645fd..2c7a573f 100644 --- a/unittests/datapoollocal/CMakeLists.txt +++ b/unittests/datapoollocal/CMakeLists.txt @@ -1,6 +1,3 @@ -target_sources(${FSFW_TEST_TGT} PRIVATE - testLocalPoolVariable.cpp - testLocalPoolVector.cpp - testDataSet.cpp - testLocalPoolManager.cpp -) +target_sources( + ${FSFW_TEST_TGT} PRIVATE testLocalPoolVariable.cpp testLocalPoolVector.cpp + testDataSet.cpp testLocalPoolManager.cpp) diff --git a/unittests/devicehandler/CMakeLists.txt b/unittests/devicehandler/CMakeLists.txt index 5d4d9b06..068e0dd4 100644 --- a/unittests/devicehandler/CMakeLists.txt +++ b/unittests/devicehandler/CMakeLists.txt @@ -1,4 +1,2 @@ -target_sources(${FSFW_TEST_TGT} PRIVATE - DeviceHandlerCommander.cpp - TestDeviceHandlerBase.cpp -) +target_sources(${FSFW_TEST_TGT} PRIVATE DeviceHandlerCommander.cpp + TestDeviceHandlerBase.cpp) diff --git a/unittests/globalfunctions/CMakeLists.txt b/unittests/globalfunctions/CMakeLists.txt index 348b99fc..ee94ca77 100644 --- a/unittests/globalfunctions/CMakeLists.txt +++ b/unittests/globalfunctions/CMakeLists.txt @@ -1,7 +1,3 @@ -target_sources(${FSFW_TEST_TGT} PRIVATE - testDleEncoder.cpp - testOpDivider.cpp - testBitutil.cpp - testCRC.cpp - testTimevalOperations.cpp -) +target_sources( + ${FSFW_TEST_TGT} PRIVATE testDleEncoder.cpp testOpDivider.cpp testBitutil.cpp + testCRC.cpp testTimevalOperations.cpp) diff --git a/unittests/hal/CMakeLists.txt b/unittests/hal/CMakeLists.txt index ee14a3aa..152bb39f 100644 --- a/unittests/hal/CMakeLists.txt +++ b/unittests/hal/CMakeLists.txt @@ -1,3 +1 @@ -target_sources(${FSFW_TEST_TGT} PRIVATE - testCommandExecutor.cpp -) +target_sources(${FSFW_TEST_TGT} PRIVATE testCommandExecutor.cpp) diff --git a/unittests/internalerror/CMakeLists.txt b/unittests/internalerror/CMakeLists.txt index d49ce006..c02cbafc 100644 --- a/unittests/internalerror/CMakeLists.txt +++ b/unittests/internalerror/CMakeLists.txt @@ -1,3 +1 @@ -target_sources(${FSFW_TEST_TGT} PRIVATE - TestInternalErrorReporter.cpp -) +target_sources(${FSFW_TEST_TGT} PRIVATE TestInternalErrorReporter.cpp) diff --git a/unittests/mocks/CMakeLists.txt b/unittests/mocks/CMakeLists.txt index 3a8c8d18..0294af31 100644 --- a/unittests/mocks/CMakeLists.txt +++ b/unittests/mocks/CMakeLists.txt @@ -1,16 +1,16 @@ -target_sources(${FSFW_TEST_TGT} PRIVATE - PowerSwitcherMock.cpp - DeviceHandlerMock.cpp - DeviceFdirMock.cpp - CookieIFMock.cpp - ComIFMock.cpp - MessageQueueMock.cpp - InternalErrorReporterMock.cpp - LocalPoolOwnerBase.cpp - PusVerificationReporterMock.cpp - PusServiceBaseMock.cpp - AcceptsTmMock.cpp - PusDistributorMock.cpp - CcsdsCheckerMock.cpp - AcceptsTcMock.cpp -) +target_sources( + ${FSFW_TEST_TGT} + PRIVATE PowerSwitcherMock.cpp + DeviceHandlerMock.cpp + DeviceFdirMock.cpp + CookieIFMock.cpp + ComIFMock.cpp + MessageQueueMock.cpp + InternalErrorReporterMock.cpp + LocalPoolOwnerBase.cpp + PusVerificationReporterMock.cpp + PusServiceBaseMock.cpp + AcceptsTmMock.cpp + PusDistributorMock.cpp + CcsdsCheckerMock.cpp + AcceptsTcMock.cpp) diff --git a/unittests/osal/CMakeLists.txt b/unittests/osal/CMakeLists.txt index 0c93eba1..90eea2c7 100644 --- a/unittests/osal/CMakeLists.txt +++ b/unittests/osal/CMakeLists.txt @@ -1,5 +1,2 @@ -target_sources(${FSFW_TEST_TGT} PRIVATE - testMq.cpp - TestSemaphore.cpp - TestClock.cpp -) +target_sources(${FSFW_TEST_TGT} PRIVATE testMq.cpp TestSemaphore.cpp + TestClock.cpp) diff --git a/unittests/power/CMakeLists.txt b/unittests/power/CMakeLists.txt index 667e6f51..78c33b42 100644 --- a/unittests/power/CMakeLists.txt +++ b/unittests/power/CMakeLists.txt @@ -1,3 +1 @@ -target_sources(${FSFW_TEST_TGT} PRIVATE - testPowerSwitcher.cpp -) +target_sources(${FSFW_TEST_TGT} PRIVATE testPowerSwitcher.cpp) diff --git a/unittests/serialize/CMakeLists.txt b/unittests/serialize/CMakeLists.txt index be4301db..b42be1d5 100644 --- a/unittests/serialize/CMakeLists.txt +++ b/unittests/serialize/CMakeLists.txt @@ -1,6 +1,3 @@ -target_sources(${FSFW_TEST_TGT} PRIVATE - testSerialBufferAdapter.cpp - testSerializeAdapter.cpp - testSerialLinkedPacket.cpp - testSerializeIF.cpp -) +target_sources( + ${FSFW_TEST_TGT} PRIVATE testSerialBufferAdapter.cpp testSerializeAdapter.cpp + testSerialLinkedPacket.cpp testSerializeIF.cpp) diff --git a/unittests/storagemanager/CMakeLists.txt b/unittests/storagemanager/CMakeLists.txt index d2bb4dbc..19e84233 100644 --- a/unittests/storagemanager/CMakeLists.txt +++ b/unittests/storagemanager/CMakeLists.txt @@ -1,4 +1 @@ -target_sources(${FSFW_TEST_TGT} PRIVATE - testAccessor.cpp - testPool.cpp -) +target_sources(${FSFW_TEST_TGT} PRIVATE testAccessor.cpp testPool.cpp) diff --git a/unittests/tcdistributor/CMakeLists.txt b/unittests/tcdistributor/CMakeLists.txt index d4182326..1743440a 100644 --- a/unittests/tcdistributor/CMakeLists.txt +++ b/unittests/tcdistributor/CMakeLists.txt @@ -1,3 +1 @@ -target_sources(${FSFW_TEST_TGT} PRIVATE - testCcsdsDistributor.cpp -) +target_sources(${FSFW_TEST_TGT} PRIVATE testCcsdsDistributor.cpp) diff --git a/unittests/testcfg/CMakeLists.txt b/unittests/testcfg/CMakeLists.txt index f840e38b..3edb59f6 100644 --- a/unittests/testcfg/CMakeLists.txt +++ b/unittests/testcfg/CMakeLists.txt @@ -1,23 +1,16 @@ -target_sources(${FSFW_TEST_TGT} PRIVATE - ipc/MissionMessageTypes.cpp - pollingsequence/PollingSequenceFactory.cpp -) +target_sources( + ${FSFW_TEST_TGT} PRIVATE ipc/MissionMessageTypes.cpp + pollingsequence/PollingSequenceFactory.cpp) # Add include paths for the executable -target_include_directories(${FSFW_TEST_TGT} PRIVATE - ${CMAKE_CURRENT_SOURCE_DIR} -) +target_include_directories(${FSFW_TEST_TGT} PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}) # If a special translation file for object IDs exists, compile it. if(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/objects/translateObjects.cpp") - target_sources(${FSFW_TEST_TGT} PRIVATE - objects/translateObjects.cpp - ) + target_sources(${FSFW_TEST_TGT} PRIVATE objects/translateObjects.cpp) endif() # If a special translation file for events exists, compile it. if(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/objects/translateObjects.cpp") - target_sources(${FSFW_TEST_TGT} PRIVATE - events/translateEvents.cpp - ) -endif() \ No newline at end of file + target_sources(${FSFW_TEST_TGT} PRIVATE events/translateEvents.cpp) +endif() diff --git a/unittests/timemanager/CMakeLists.txt b/unittests/timemanager/CMakeLists.txt index 4b1693a9..ad9cae23 100644 --- a/unittests/timemanager/CMakeLists.txt +++ b/unittests/timemanager/CMakeLists.txt @@ -1,4 +1 @@ -target_sources(${FSFW_TEST_TGT} PRIVATE - TestCountdown.cpp - TestCCSDSTime.cpp -) +target_sources(${FSFW_TEST_TGT} PRIVATE TestCountdown.cpp TestCCSDSTime.cpp) diff --git a/unittests/tmtcpacket/CMakeLists.txt b/unittests/tmtcpacket/CMakeLists.txt index 5b53328f..4415685e 100644 --- a/unittests/tmtcpacket/CMakeLists.txt +++ b/unittests/tmtcpacket/CMakeLists.txt @@ -1,10 +1,10 @@ -target_sources(${FSFW_TEST_TGT} PRIVATE - testCcsdsCreator.cpp - testCcsdsReader.cpp - testPusTcCreator.cpp - testPusTcReader.cpp - testPusTmCreator.cpp - testPusTmReader.cpp - testCcsds.cpp - testZcTmWriter.cpp -) +target_sources( + ${FSFW_TEST_TGT} + PRIVATE testCcsdsCreator.cpp + testCcsdsReader.cpp + testPusTcCreator.cpp + testPusTcReader.cpp + testPusTmCreator.cpp + testPusTmReader.cpp + testCcsds.cpp + testZcTmWriter.cpp) diff --git a/unittests/tmtcservices/CMakeLists.txt b/unittests/tmtcservices/CMakeLists.txt index 9e60ced1..1004a5f9 100644 --- a/unittests/tmtcservices/CMakeLists.txt +++ b/unittests/tmtcservices/CMakeLists.txt @@ -1,6 +1,2 @@ -target_sources(${FSFW_TEST_TGT} PRIVATE - testStoreHelper.cpp - testSendHelper.cpp - testStoreAndSendHelper.cpp - testPsb.cpp -) +target_sources(${FSFW_TEST_TGT} PRIVATE testStoreHelper.cpp testSendHelper.cpp + testStoreAndSendHelper.cpp testPsb.cpp) diff --git a/unittests/util/CMakeLists.txt b/unittests/util/CMakeLists.txt index b79b77db..672670b8 100644 --- a/unittests/util/CMakeLists.txt +++ b/unittests/util/CMakeLists.txt @@ -1,4 +1,2 @@ -target_sources(${FSFW_TEST_TGT} PRIVATE - testUnsignedByteField.cpp - testObjectId.cpp -) +target_sources(${FSFW_TEST_TGT} PRIVATE testUnsignedByteField.cpp + testObjectId.cpp) From cc98512caf7b431401679ce77549f0ff02cce726 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Wed, 3 Aug 2022 13:23:49 +0200 Subject: [PATCH 013/169] use tags properly --- unittests/cfdp/CMakeLists.txt | 3 +- unittests/cfdp/testCfdp.cpp | 276 +---------------- unittests/cfdp/testCfdpHeader.cpp | 292 +++++++++++++++++- unittests/cfdp/testEofPdu.cpp | 2 +- unittests/cfdp/testFileData.cpp | 2 +- unittests/cfdp/testFileDirective.cpp | 73 +++++ unittests/cfdp/testFinishedPdu.cpp | 2 +- unittests/cfdp/testKeepAlivePdu.cpp | 2 +- unittests/cfdp/testMetadataPdu.cpp | 2 +- unittests/cfdp/testNakPdu.cpp | 2 +- unittests/cfdp/testPromptPdu.cpp | 2 +- unittests/cfdp/testTlvsLvs.cpp | 2 +- .../tcdistributor/testCcsdsDistributor.cpp | 2 +- 13 files changed, 375 insertions(+), 287 deletions(-) create mode 100644 unittests/cfdp/testFileDirective.cpp diff --git a/unittests/cfdp/CMakeLists.txt b/unittests/cfdp/CMakeLists.txt index fcae5bba..9cc2726e 100644 --- a/unittests/cfdp/CMakeLists.txt +++ b/unittests/cfdp/CMakeLists.txt @@ -10,4 +10,5 @@ target_sources( testKeepAlivePdu.cpp testMetadataPdu.cpp testFileData.cpp - testCfdpHeader.cpp) + testCfdpHeader.cpp + testFileDirective.cpp) diff --git a/unittests/cfdp/testCfdp.cpp b/unittests/cfdp/testCfdp.cpp index 9184156c..8cfdbca4 100644 --- a/unittests/cfdp/testCfdp.cpp +++ b/unittests/cfdp/testCfdp.cpp @@ -2,19 +2,16 @@ #include #include -#include "CatchDefinitions.h" #include "fsfw/cfdp/FileSize.h" #include "fsfw/cfdp/pdu/FileDirectiveDeserializer.h" #include "fsfw/cfdp/pdu/FileDirectiveSerializer.h" -#include "fsfw/cfdp/pdu/HeaderDeserializer.h" -#include "fsfw/cfdp/pdu/HeaderSerializer.h" #include "fsfw/globalfunctions/arrayprinter.h" #include "fsfw/serialize/SerializeAdapter.h" -TEST_CASE("CFDP Base", "[CfdpBase]") { +TEST_CASE("CFDP Base", "[cfdp]") { using namespace cfdp; std::array serBuf{}; - ReturnValue_t result = HasReturnvaluesIF::RETURN_OK; + ReturnValue_t result; cfdp::TransactionSeqNum seqNum = TransactionSeqNum(cfdp::WidthInBytes::ONE_BYTE, 2); cfdp::EntityId sourceId = EntityId(cfdp::WidthInBytes::ONE_BYTE, 0); cfdp::EntityId destId = EntityId(cfdp::WidthInBytes::ONE_BYTE, 1); @@ -24,275 +21,6 @@ TEST_CASE("CFDP Base", "[CfdpBase]") { const uint8_t* deserTarget = serTarget; size_t serSize = 0; - SECTION("Header Serialization") { - auto headerSerializer = HeaderSerializer(pduConf, cfdp::PduType::FILE_DIRECTIVE, 0); - const uint8_t** dummyPtr = nullptr; - ReturnValue_t deserResult = - headerSerializer.deSerialize(dummyPtr, &serSize, SerializeIF::Endianness::NETWORK); - REQUIRE(deserResult == result::FAILED); - deserResult = headerSerializer.serialize(nullptr, &serSize, serBuf.size(), - SerializeIF::Endianness::NETWORK); - REQUIRE(deserResult == result::FAILED); - REQUIRE(seqNum.getSerializedSize() == 1); - - REQUIRE(headerSerializer.getPduDataFieldLen() == 0); - REQUIRE(headerSerializer.getSerializedSize() == 7); - REQUIRE(headerSerializer.getWholePduSize() == 7); - REQUIRE(headerSerializer.getCrcFlag() == false); - REQUIRE(headerSerializer.getDirection() == cfdp::Direction::TOWARDS_RECEIVER); - REQUIRE(headerSerializer.getLargeFileFlag() == false); - REQUIRE(headerSerializer.getLenEntityIds() == 1); - REQUIRE(headerSerializer.getLenSeqNum() == 1); - REQUIRE(headerSerializer.getPduType() == cfdp::PduType::FILE_DIRECTIVE); - REQUIRE(headerSerializer.getSegmentMetadataFlag() == cfdp::SegmentMetadataFlag::NOT_PRESENT); - REQUIRE(headerSerializer.getSegmentationControl() == false); - REQUIRE(headerSerializer.getTransmissionMode() == cfdp::TransmissionModes::ACKNOWLEDGED); - - cfdp::TransactionSeqNum seqNumLocal; - headerSerializer.getTransactionSeqNum(seqNumLocal); - REQUIRE(seqNumLocal.getWidth() == cfdp::WidthInBytes::ONE_BYTE); - REQUIRE(seqNumLocal.getValue() == 2); - cfdp::EntityId sourceDestId; - headerSerializer.getSourceId(sourceDestId); - REQUIRE(sourceDestId.getWidth() == cfdp::WidthInBytes::ONE_BYTE); - REQUIRE(sourceDestId.getValue() == 0); - headerSerializer.getDestId(sourceDestId); - REQUIRE(sourceDestId.getWidth() == cfdp::WidthInBytes::ONE_BYTE); - REQUIRE(sourceDestId.getValue() == 1); - - result = headerSerializer.serialize(&serTarget, &serSize, serBuf.size(), - SerializeIF::Endianness::BIG); - REQUIRE(result == result::OK); - REQUIRE(serSize == 7); - // Only version bits are set - REQUIRE(serBuf[0] == 0b00100000); - // PDU data field length is 0 - REQUIRE(serBuf[1] == 0); - REQUIRE(serBuf[2] == 0); - // Entity and Transaction Sequence number are 1 byte large - REQUIRE(serBuf[3] == 0b00010001); - // Source ID - REQUIRE(serBuf[4] == 0); - // Transaction Seq Number - REQUIRE(serBuf[5] == 2); - // Dest ID - REQUIRE(serBuf[6] == 1); - - for (uint8_t idx = 0; idx < 7; idx++) { - result = headerSerializer.serialize(&serTarget, &serSize, idx, SerializeIF::Endianness::BIG); - REQUIRE(result == static_cast(SerializeIF::BUFFER_TOO_SHORT)); - } - - // Set PDU data field len - headerSerializer.setPduDataFieldLen(0x0ff0); - REQUIRE(headerSerializer.getPduDataFieldLen() == 0x0ff0); - REQUIRE(headerSerializer.getSerializedSize() == 7); - REQUIRE(headerSerializer.getWholePduSize() == 7 + 0x0ff0); - serTarget = serBuf.data(); - serSize = 0; - result = headerSerializer.serialize(&serTarget, &serSize, serBuf.size(), - SerializeIF::Endianness::BIG); - REQUIRE(serBuf[1] == 0x0f); - REQUIRE(serBuf[2] == 0xf0); - - pduConf.crcFlag = true; - pduConf.largeFile = true; - pduConf.direction = cfdp::Direction::TOWARDS_SENDER; - pduConf.mode = cfdp::TransmissionModes::UNACKNOWLEDGED; - headerSerializer.setSegmentationControl( - cfdp::SegmentationControl::RECORD_BOUNDARIES_PRESERVATION); - headerSerializer.setPduType(cfdp::PduType::FILE_DATA); - headerSerializer.setSegmentMetadataFlag(cfdp::SegmentMetadataFlag::PRESENT); - serTarget = serBuf.data(); - serSize = 0; - result = headerSerializer.serialize(&serTarget, &serSize, serBuf.size(), - SerializeIF::Endianness::BIG); - - // Everything except version bit flipped to one now - REQUIRE(serBuf[0] == 0x3f); - REQUIRE(serBuf[3] == 0x99); - pduConf.seqNum.setValue(cfdp::WidthInBytes::TWO_BYTES, 0x0fff); - pduConf.sourceId.setValue(cfdp::WidthInBytes::FOUR_BYTES, 0xff00ff00); - pduConf.destId.setValue(cfdp::WidthInBytes::FOUR_BYTES, 0x00ff00ff); - REQUIRE(pduConf.sourceId.getSerializedSize() == 4); - REQUIRE(headerSerializer.getSerializedSize() == 14); - serTarget = serBuf.data(); - serSize = 0; - result = headerSerializer.serialize(&serTarget, &serSize, serBuf.size(), - SerializeIF::Endianness::BIG); - - for (uint8_t idx = 0; idx < 14; idx++) { - result = headerSerializer.serialize(&serTarget, &serSize, idx, SerializeIF::Endianness::BIG); - REQUIRE(result == static_cast(SerializeIF::BUFFER_TOO_SHORT)); - } - REQUIRE(headerSerializer.getCrcFlag() == true); - REQUIRE(headerSerializer.getDirection() == cfdp::Direction::TOWARDS_SENDER); - REQUIRE(headerSerializer.getLargeFileFlag() == true); - REQUIRE(headerSerializer.getLenEntityIds() == 4); - REQUIRE(headerSerializer.getLenSeqNum() == 2); - REQUIRE(headerSerializer.getPduType() == cfdp::PduType::FILE_DATA); - REQUIRE(headerSerializer.getSegmentMetadataFlag() == cfdp::SegmentMetadataFlag::PRESENT); - REQUIRE(headerSerializer.getTransmissionMode() == cfdp::TransmissionModes::UNACKNOWLEDGED); - REQUIRE(headerSerializer.getSegmentationControl() == true); - // Last three bits are 2 now (length of seq number) and bit 1 to bit 3 is 4 (len entity IDs) - REQUIRE(serBuf[3] == 0b11001010); - uint32_t entityId = 0; - size_t deSerSize = 0; - SerializeAdapter::deSerialize(&entityId, serBuf.data() + 4, &deSerSize, - SerializeIF::Endianness::NETWORK); - REQUIRE(deSerSize == 4); - REQUIRE(entityId == 0xff00ff00); - uint16_t seqNumRaw = 0; - SerializeAdapter::deSerialize(&seqNumRaw, serBuf.data() + 8, &deSerSize, - SerializeIF::Endianness::NETWORK); - REQUIRE(deSerSize == 2); - REQUIRE(seqNumRaw == 0x0fff); - SerializeAdapter::deSerialize(&entityId, serBuf.data() + 10, &deSerSize, - SerializeIF::Endianness::NETWORK); - REQUIRE(deSerSize == 4); - REQUIRE(entityId == 0x00ff00ff); - - result = pduConf.sourceId.setValue(cfdp::WidthInBytes::ONE_BYTE, 0xfff); - REQUIRE(result == result::FAILED); - result = pduConf.sourceId.setValue(cfdp::WidthInBytes::TWO_BYTES, 0xfffff); - REQUIRE(result == result::FAILED); - result = pduConf.sourceId.setValue(cfdp::WidthInBytes::FOUR_BYTES, 0xfffffffff); - REQUIRE(result == result::FAILED); - uint8_t oneByteSourceId = 32; - serTarget = &oneByteSourceId; - size_t deserLen = 1; - pduConf.sourceId.deSerialize(cfdp::WidthInBytes::ONE_BYTE, - const_cast(&serTarget), &deserLen, - SerializeIF::Endianness::MACHINE); - REQUIRE(pduConf.sourceId.getValue() == 32); - - uint16_t twoByteSourceId = 0xf0f0; - serTarget = reinterpret_cast(&twoByteSourceId); - deserLen = 2; - pduConf.sourceId.deSerialize(cfdp::WidthInBytes::TWO_BYTES, - const_cast(&serTarget), &deserLen, - SerializeIF::Endianness::MACHINE); - REQUIRE(pduConf.sourceId.getValue() == 0xf0f0); - - uint32_t fourByteSourceId = 0xf0f0f0f0; - serTarget = reinterpret_cast(&fourByteSourceId); - deserLen = 4; - pduConf.sourceId.deSerialize(cfdp::WidthInBytes::FOUR_BYTES, - const_cast(&serTarget), &deserLen, - SerializeIF::Endianness::MACHINE); - REQUIRE(pduConf.sourceId.getValue() == 0xf0f0f0f0); - - pduConf.sourceId.setValue(cfdp::WidthInBytes::ONE_BYTE, 1); - serTarget = serBuf.data(); - serSize = 1; - result = pduConf.sourceId.serialize(&serTarget, &serSize, 1, SerializeIF::Endianness::MACHINE); - REQUIRE(result == static_cast(SerializeIF::BUFFER_TOO_SHORT)); - } - - SECTION("Header Deserialization") { - // We unittested the serializer before, so we can use it now to generate valid raw CFDP - // data - auto headerSerializer = HeaderSerializer(pduConf, cfdp::PduType::FILE_DIRECTIVE, 0); - result = headerSerializer.serialize(&serTarget, &serSize, serBuf.size(), - SerializeIF::Endianness::BIG); - REQUIRE(result == result::OK); - REQUIRE(serBuf[1] == 0); - REQUIRE(serBuf[2] == 0); - // Entity and Transaction Sequence number are 1 byte large - REQUIRE(serBuf[3] == 0b00010001); - REQUIRE(serSize == 7); - // Deser call not strictly necessary - auto headerDeser = HeaderDeserializer(serBuf.data(), serBuf.size()); - - ReturnValue_t serResult = headerDeser.parseData(); - REQUIRE(serResult == result::OK); - REQUIRE(headerDeser.getPduDataFieldLen() == 0); - REQUIRE(headerDeser.getHeaderSize() == 7); - REQUIRE(headerDeser.getWholePduSize() == 7); - REQUIRE(headerDeser.getCrcFlag() == false); - REQUIRE(headerDeser.getDirection() == cfdp::Direction::TOWARDS_RECEIVER); - REQUIRE(headerDeser.getLargeFileFlag() == false); - REQUIRE(headerDeser.getLenEntityIds() == 1); - REQUIRE(headerDeser.getLenSeqNum() == 1); - REQUIRE(headerDeser.getPduType() == cfdp::PduType::FILE_DIRECTIVE); - REQUIRE(headerDeser.getSegmentMetadataFlag() == cfdp::SegmentMetadataFlag::NOT_PRESENT); - REQUIRE(headerDeser.getSegmentationControl() == false); - REQUIRE(headerDeser.getTransmissionMode() == cfdp::TransmissionModes::ACKNOWLEDGED); - - pduConf.crcFlag = true; - pduConf.largeFile = true; - pduConf.direction = cfdp::Direction::TOWARDS_SENDER; - pduConf.mode = cfdp::TransmissionModes::UNACKNOWLEDGED; - headerSerializer.setSegmentationControl( - cfdp::SegmentationControl::RECORD_BOUNDARIES_PRESERVATION); - headerSerializer.setPduType(cfdp::PduType::FILE_DATA); - headerSerializer.setSegmentMetadataFlag(cfdp::SegmentMetadataFlag::PRESENT); - result = pduConf.seqNum.setValue(cfdp::WidthInBytes::TWO_BYTES, 0x0fff); - REQUIRE(result == result::OK); - result = pduConf.sourceId.setValue(cfdp::WidthInBytes::FOUR_BYTES, 0xff00ff00); - REQUIRE(result == result::OK); - result = pduConf.destId.setValue(cfdp::WidthInBytes::FOUR_BYTES, 0x00ff00ff); - REQUIRE(result == result::OK); - serTarget = serBuf.data(); - serSize = 0; - result = headerSerializer.serialize(&serTarget, &serSize, serBuf.size(), - SerializeIF::Endianness::BIG); - headerDeser = HeaderDeserializer(serBuf.data(), serBuf.size()); - - result = headerDeser.parseData(); - REQUIRE(result == result::OK); - // Everything except version bit flipped to one now - REQUIRE(serBuf[0] == 0x3f); - REQUIRE(serBuf[3] == 0b11001010); - REQUIRE(headerDeser.getWholePduSize() == 14); - - REQUIRE(headerDeser.getCrcFlag() == true); - REQUIRE(headerDeser.getDirection() == cfdp::Direction::TOWARDS_SENDER); - REQUIRE(headerDeser.getLargeFileFlag() == true); - REQUIRE(headerDeser.getLenEntityIds() == 4); - REQUIRE(headerDeser.getLenSeqNum() == 2); - REQUIRE(headerDeser.getPduType() == cfdp::PduType::FILE_DATA); - REQUIRE(headerDeser.getSegmentMetadataFlag() == cfdp::SegmentMetadataFlag::PRESENT); - REQUIRE(headerDeser.getSegmentationControl() == true); - REQUIRE(headerDeser.getTransmissionMode() == cfdp::TransmissionModes::UNACKNOWLEDGED); - - cfdp::TransactionSeqNum seqNumLocal; - headerDeser.getTransactionSeqNum(seqNumLocal); - REQUIRE(seqNumLocal.getWidth() == cfdp::WidthInBytes::TWO_BYTES); - REQUIRE(seqNumLocal.getValue() == 0x0fff); - cfdp::EntityId sourceDestId; - headerDeser.getSourceId(sourceDestId); - REQUIRE(sourceDestId.getWidth() == cfdp::WidthInBytes::FOUR_BYTES); - REQUIRE(sourceDestId.getValue() == 0xff00ff00); - headerDeser.getDestId(sourceDestId); - REQUIRE(sourceDestId.getWidth() == cfdp::WidthInBytes::FOUR_BYTES); - REQUIRE(sourceDestId.getValue() == 0x00ff00ff); - - size_t deSerSize = headerDeser.getWholePduSize(); - serTarget = serBuf.data(); - const auto** serTargetConst = const_cast(&serTarget); - result = headerDeser.parseData(); - REQUIRE(result == result::OK); - - headerDeser.setData(nullptr, -1); - REQUIRE(headerDeser.getHeaderSize() == 0); - headerDeser.setData(serBuf.data(), serBuf.size()); - - serTarget = serBuf.data(); - serSize = 0; - pduConf.sourceId.setValue(cfdp::WidthInBytes::ONE_BYTE, 22); - pduConf.destId.setValue(cfdp::WidthInBytes::ONE_BYTE, 48); - result = headerSerializer.serialize(&serTarget, &serSize, serBuf.size(), - SerializeIF::Endianness::BIG); - REQUIRE(result == result::OK); - REQUIRE(headerDeser.getWholePduSize() == 8); - headerDeser.setData(serBuf.data(), serBuf.size()); - - headerDeser.getSourceId(sourceDestId); - REQUIRE(sourceDestId.getWidth() == cfdp::WidthInBytes::ONE_BYTE); - REQUIRE(sourceDestId.getValue() == 22); - } - SECTION("File Directive") { auto fdSer = FileDirectiveSerializer(pduConf, FileDirectives::ACK, 4); REQUIRE(fdSer.getSerializedSize() == 8); diff --git a/unittests/cfdp/testCfdpHeader.cpp b/unittests/cfdp/testCfdpHeader.cpp index 77579bd4..3e9cfccd 100644 --- a/unittests/cfdp/testCfdpHeader.cpp +++ b/unittests/cfdp/testCfdpHeader.cpp @@ -1,3 +1,289 @@ -// -// Created by rmueller on 8/3/22. -// +#include +#include + +#include "fsfw/cfdp/pdu/HeaderDeserializer.h" +#include "fsfw/cfdp/pdu/HeaderSerializer.h" +#include "fsfw/returnvalues/HasReturnvaluesIF.h" + +TEST_CASE("CFDP Header", "[cfdp]") { + using namespace cfdp; + std::array serBuf{}; + ReturnValue_t result; + cfdp::TransactionSeqNum seqNum = TransactionSeqNum(cfdp::WidthInBytes::ONE_BYTE, 2); + cfdp::EntityId sourceId = EntityId(cfdp::WidthInBytes::ONE_BYTE, 0); + cfdp::EntityId destId = EntityId(cfdp::WidthInBytes::ONE_BYTE, 1); + PduConfig pduConf = + PduConfig(sourceId, destId, cfdp::TransmissionModes::ACKNOWLEDGED, seqNum, false); + uint8_t* serTarget = serBuf.data(); + const uint8_t* deserTarget = serTarget; + size_t serSize = 0; + + SECTION("Header Serialization") { + auto headerSerializer = HeaderSerializer(pduConf, cfdp::PduType::FILE_DIRECTIVE, 0); + const uint8_t** dummyPtr = nullptr; + ReturnValue_t deserResult = + headerSerializer.deSerialize(dummyPtr, &serSize, SerializeIF::Endianness::NETWORK); + REQUIRE(deserResult == result::FAILED); + deserResult = headerSerializer.serialize(nullptr, &serSize, serBuf.size(), + SerializeIF::Endianness::NETWORK); + REQUIRE(deserResult == result::FAILED); + REQUIRE(seqNum.getSerializedSize() == 1); + + REQUIRE(headerSerializer.getPduDataFieldLen() == 0); + REQUIRE(headerSerializer.getSerializedSize() == 7); + REQUIRE(headerSerializer.getWholePduSize() == 7); + REQUIRE(headerSerializer.getCrcFlag() == false); + REQUIRE(headerSerializer.getDirection() == cfdp::Direction::TOWARDS_RECEIVER); + REQUIRE(headerSerializer.getLargeFileFlag() == false); + REQUIRE(headerSerializer.getLenEntityIds() == 1); + REQUIRE(headerSerializer.getLenSeqNum() == 1); + REQUIRE(headerSerializer.getPduType() == cfdp::PduType::FILE_DIRECTIVE); + REQUIRE(headerSerializer.getSegmentMetadataFlag() == cfdp::SegmentMetadataFlag::NOT_PRESENT); + REQUIRE(headerSerializer.getSegmentationControl() == false); + REQUIRE(headerSerializer.getTransmissionMode() == cfdp::TransmissionModes::ACKNOWLEDGED); + + cfdp::TransactionSeqNum seqNumLocal; + headerSerializer.getTransactionSeqNum(seqNumLocal); + REQUIRE(seqNumLocal.getWidth() == cfdp::WidthInBytes::ONE_BYTE); + REQUIRE(seqNumLocal.getValue() == 2); + cfdp::EntityId sourceDestId; + headerSerializer.getSourceId(sourceDestId); + REQUIRE(sourceDestId.getWidth() == cfdp::WidthInBytes::ONE_BYTE); + REQUIRE(sourceDestId.getValue() == 0); + headerSerializer.getDestId(sourceDestId); + REQUIRE(sourceDestId.getWidth() == cfdp::WidthInBytes::ONE_BYTE); + REQUIRE(sourceDestId.getValue() == 1); + + result = headerSerializer.serialize(&serTarget, &serSize, serBuf.size(), + SerializeIF::Endianness::BIG); + REQUIRE(result == result::OK); + REQUIRE(serSize == 7); + // Only version bits are set + REQUIRE(serBuf[0] == 0b00100000); + // PDU data field length is 0 + REQUIRE(serBuf[1] == 0); + REQUIRE(serBuf[2] == 0); + // Entity and Transaction Sequence number are 1 byte large + REQUIRE(serBuf[3] == 0b00010001); + // Source ID + REQUIRE(serBuf[4] == 0); + // Transaction Seq Number + REQUIRE(serBuf[5] == 2); + // Dest ID + REQUIRE(serBuf[6] == 1); + + for (uint8_t idx = 0; idx < 7; idx++) { + result = headerSerializer.serialize(&serTarget, &serSize, idx, SerializeIF::Endianness::BIG); + REQUIRE(result == static_cast(SerializeIF::BUFFER_TOO_SHORT)); + } + + // Set PDU data field len + headerSerializer.setPduDataFieldLen(0x0ff0); + REQUIRE(headerSerializer.getPduDataFieldLen() == 0x0ff0); + REQUIRE(headerSerializer.getSerializedSize() == 7); + REQUIRE(headerSerializer.getWholePduSize() == 7 + 0x0ff0); + serTarget = serBuf.data(); + serSize = 0; + result = headerSerializer.serialize(&serTarget, &serSize, serBuf.size(), + SerializeIF::Endianness::BIG); + REQUIRE(serBuf[1] == 0x0f); + REQUIRE(serBuf[2] == 0xf0); + + pduConf.crcFlag = true; + pduConf.largeFile = true; + pduConf.direction = cfdp::Direction::TOWARDS_SENDER; + pduConf.mode = cfdp::TransmissionModes::UNACKNOWLEDGED; + headerSerializer.setSegmentationControl( + cfdp::SegmentationControl::RECORD_BOUNDARIES_PRESERVATION); + headerSerializer.setPduType(cfdp::PduType::FILE_DATA); + headerSerializer.setSegmentMetadataFlag(cfdp::SegmentMetadataFlag::PRESENT); + serTarget = serBuf.data(); + serSize = 0; + result = headerSerializer.serialize(&serTarget, &serSize, serBuf.size(), + SerializeIF::Endianness::BIG); + + // Everything except version bit flipped to one now + REQUIRE(serBuf[0] == 0x3f); + REQUIRE(serBuf[3] == 0x99); + pduConf.seqNum.setValue(cfdp::WidthInBytes::TWO_BYTES, 0x0fff); + pduConf.sourceId.setValue(cfdp::WidthInBytes::FOUR_BYTES, 0xff00ff00); + pduConf.destId.setValue(cfdp::WidthInBytes::FOUR_BYTES, 0x00ff00ff); + REQUIRE(pduConf.sourceId.getSerializedSize() == 4); + REQUIRE(headerSerializer.getSerializedSize() == 14); + serTarget = serBuf.data(); + serSize = 0; + result = headerSerializer.serialize(&serTarget, &serSize, serBuf.size(), + SerializeIF::Endianness::BIG); + + for (uint8_t idx = 0; idx < 14; idx++) { + result = headerSerializer.serialize(&serTarget, &serSize, idx, SerializeIF::Endianness::BIG); + REQUIRE(result == static_cast(SerializeIF::BUFFER_TOO_SHORT)); + } + REQUIRE(headerSerializer.getCrcFlag() == true); + REQUIRE(headerSerializer.getDirection() == cfdp::Direction::TOWARDS_SENDER); + REQUIRE(headerSerializer.getLargeFileFlag() == true); + REQUIRE(headerSerializer.getLenEntityIds() == 4); + REQUIRE(headerSerializer.getLenSeqNum() == 2); + REQUIRE(headerSerializer.getPduType() == cfdp::PduType::FILE_DATA); + REQUIRE(headerSerializer.getSegmentMetadataFlag() == cfdp::SegmentMetadataFlag::PRESENT); + REQUIRE(headerSerializer.getTransmissionMode() == cfdp::TransmissionModes::UNACKNOWLEDGED); + REQUIRE(headerSerializer.getSegmentationControl() == true); + // Last three bits are 2 now (length of seq number) and bit 1 to bit 3 is 4 (len entity IDs) + REQUIRE(serBuf[3] == 0b11001010); + uint32_t entityId = 0; + size_t deSerSize = 0; + SerializeAdapter::deSerialize(&entityId, serBuf.data() + 4, &deSerSize, + SerializeIF::Endianness::NETWORK); + REQUIRE(deSerSize == 4); + REQUIRE(entityId == 0xff00ff00); + uint16_t seqNumRaw = 0; + SerializeAdapter::deSerialize(&seqNumRaw, serBuf.data() + 8, &deSerSize, + SerializeIF::Endianness::NETWORK); + REQUIRE(deSerSize == 2); + REQUIRE(seqNumRaw == 0x0fff); + SerializeAdapter::deSerialize(&entityId, serBuf.data() + 10, &deSerSize, + SerializeIF::Endianness::NETWORK); + REQUIRE(deSerSize == 4); + REQUIRE(entityId == 0x00ff00ff); + + result = pduConf.sourceId.setValue(cfdp::WidthInBytes::ONE_BYTE, 0xfff); + REQUIRE(result == result::FAILED); + result = pduConf.sourceId.setValue(cfdp::WidthInBytes::TWO_BYTES, 0xfffff); + REQUIRE(result == result::FAILED); + result = pduConf.sourceId.setValue(cfdp::WidthInBytes::FOUR_BYTES, 0xfffffffff); + REQUIRE(result == result::FAILED); + uint8_t oneByteSourceId = 32; + serTarget = &oneByteSourceId; + size_t deserLen = 1; + pduConf.sourceId.deSerialize(cfdp::WidthInBytes::ONE_BYTE, + const_cast(&serTarget), &deserLen, + SerializeIF::Endianness::MACHINE); + REQUIRE(pduConf.sourceId.getValue() == 32); + + uint16_t twoByteSourceId = 0xf0f0; + serTarget = reinterpret_cast(&twoByteSourceId); + deserLen = 2; + pduConf.sourceId.deSerialize(cfdp::WidthInBytes::TWO_BYTES, + const_cast(&serTarget), &deserLen, + SerializeIF::Endianness::MACHINE); + REQUIRE(pduConf.sourceId.getValue() == 0xf0f0); + + uint32_t fourByteSourceId = 0xf0f0f0f0; + serTarget = reinterpret_cast(&fourByteSourceId); + deserLen = 4; + pduConf.sourceId.deSerialize(cfdp::WidthInBytes::FOUR_BYTES, + const_cast(&serTarget), &deserLen, + SerializeIF::Endianness::MACHINE); + REQUIRE(pduConf.sourceId.getValue() == 0xf0f0f0f0); + + pduConf.sourceId.setValue(cfdp::WidthInBytes::ONE_BYTE, 1); + serTarget = serBuf.data(); + serSize = 1; + result = pduConf.sourceId.serialize(&serTarget, &serSize, 1, SerializeIF::Endianness::MACHINE); + REQUIRE(result == static_cast(SerializeIF::BUFFER_TOO_SHORT)); + } + + SECTION("Header Deserialization") { + // We unittested the serializer before, so we can use it now to generate valid raw CFDP + // data + auto headerSerializer = HeaderSerializer(pduConf, cfdp::PduType::FILE_DIRECTIVE, 0); + result = headerSerializer.serialize(&serTarget, &serSize, serBuf.size(), + SerializeIF::Endianness::BIG); + REQUIRE(result == result::OK); + REQUIRE(serBuf[1] == 0); + REQUIRE(serBuf[2] == 0); + // Entity and Transaction Sequence number are 1 byte large + REQUIRE(serBuf[3] == 0b00010001); + REQUIRE(serSize == 7); + // Deser call not strictly necessary + auto headerDeser = HeaderDeserializer(serBuf.data(), serBuf.size()); + + ReturnValue_t serResult = headerDeser.parseData(); + REQUIRE(serResult == result::OK); + REQUIRE(headerDeser.getPduDataFieldLen() == 0); + REQUIRE(headerDeser.getHeaderSize() == 7); + REQUIRE(headerDeser.getWholePduSize() == 7); + REQUIRE(headerDeser.getCrcFlag() == false); + REQUIRE(headerDeser.getDirection() == cfdp::Direction::TOWARDS_RECEIVER); + REQUIRE(headerDeser.getLargeFileFlag() == false); + REQUIRE(headerDeser.getLenEntityIds() == 1); + REQUIRE(headerDeser.getLenSeqNum() == 1); + REQUIRE(headerDeser.getPduType() == cfdp::PduType::FILE_DIRECTIVE); + REQUIRE(headerDeser.getSegmentMetadataFlag() == cfdp::SegmentMetadataFlag::NOT_PRESENT); + REQUIRE(headerDeser.getSegmentationControl() == false); + REQUIRE(headerDeser.getTransmissionMode() == cfdp::TransmissionModes::ACKNOWLEDGED); + + pduConf.crcFlag = true; + pduConf.largeFile = true; + pduConf.direction = cfdp::Direction::TOWARDS_SENDER; + pduConf.mode = cfdp::TransmissionModes::UNACKNOWLEDGED; + headerSerializer.setSegmentationControl( + cfdp::SegmentationControl::RECORD_BOUNDARIES_PRESERVATION); + headerSerializer.setPduType(cfdp::PduType::FILE_DATA); + headerSerializer.setSegmentMetadataFlag(cfdp::SegmentMetadataFlag::PRESENT); + result = pduConf.seqNum.setValue(cfdp::WidthInBytes::TWO_BYTES, 0x0fff); + REQUIRE(result == result::OK); + result = pduConf.sourceId.setValue(cfdp::WidthInBytes::FOUR_BYTES, 0xff00ff00); + REQUIRE(result == result::OK); + result = pduConf.destId.setValue(cfdp::WidthInBytes::FOUR_BYTES, 0x00ff00ff); + REQUIRE(result == result::OK); + serTarget = serBuf.data(); + serSize = 0; + result = headerSerializer.serialize(&serTarget, &serSize, serBuf.size(), + SerializeIF::Endianness::BIG); + headerDeser = HeaderDeserializer(serBuf.data(), serBuf.size()); + + result = headerDeser.parseData(); + REQUIRE(result == result::OK); + // Everything except version bit flipped to one now + REQUIRE(serBuf[0] == 0x3f); + REQUIRE(serBuf[3] == 0b11001010); + REQUIRE(headerDeser.getWholePduSize() == 14); + + REQUIRE(headerDeser.getCrcFlag() == true); + REQUIRE(headerDeser.getDirection() == cfdp::Direction::TOWARDS_SENDER); + REQUIRE(headerDeser.getLargeFileFlag() == true); + REQUIRE(headerDeser.getLenEntityIds() == 4); + REQUIRE(headerDeser.getLenSeqNum() == 2); + REQUIRE(headerDeser.getPduType() == cfdp::PduType::FILE_DATA); + REQUIRE(headerDeser.getSegmentMetadataFlag() == cfdp::SegmentMetadataFlag::PRESENT); + REQUIRE(headerDeser.getSegmentationControl() == true); + REQUIRE(headerDeser.getTransmissionMode() == cfdp::TransmissionModes::UNACKNOWLEDGED); + + cfdp::TransactionSeqNum seqNumLocal; + headerDeser.getTransactionSeqNum(seqNumLocal); + REQUIRE(seqNumLocal.getWidth() == cfdp::WidthInBytes::TWO_BYTES); + REQUIRE(seqNumLocal.getValue() == 0x0fff); + cfdp::EntityId sourceDestId; + headerDeser.getSourceId(sourceDestId); + REQUIRE(sourceDestId.getWidth() == cfdp::WidthInBytes::FOUR_BYTES); + REQUIRE(sourceDestId.getValue() == 0xff00ff00); + headerDeser.getDestId(sourceDestId); + REQUIRE(sourceDestId.getWidth() == cfdp::WidthInBytes::FOUR_BYTES); + REQUIRE(sourceDestId.getValue() == 0x00ff00ff); + + size_t deSerSize = headerDeser.getWholePduSize(); + serTarget = serBuf.data(); + const auto** serTargetConst = const_cast(&serTarget); + result = headerDeser.parseData(); + REQUIRE(result == result::OK); + + headerDeser.setData(nullptr, -1); + REQUIRE(headerDeser.getHeaderSize() == 0); + headerDeser.setData(serBuf.data(), serBuf.size()); + + serTarget = serBuf.data(); + serSize = 0; + pduConf.sourceId.setValue(cfdp::WidthInBytes::ONE_BYTE, 22); + pduConf.destId.setValue(cfdp::WidthInBytes::ONE_BYTE, 48); + result = headerSerializer.serialize(&serTarget, &serSize, serBuf.size(), + SerializeIF::Endianness::BIG); + REQUIRE(result == result::OK); + REQUIRE(headerDeser.getWholePduSize() == 8); + headerDeser.setData(serBuf.data(), serBuf.size()); + + headerDeser.getSourceId(sourceDestId); + REQUIRE(sourceDestId.getWidth() == cfdp::WidthInBytes::ONE_BYTE); + REQUIRE(sourceDestId.getValue() == 22); + } +} diff --git a/unittests/cfdp/testEofPdu.cpp b/unittests/cfdp/testEofPdu.cpp index 44e21bdf..b6eb88d7 100644 --- a/unittests/cfdp/testEofPdu.cpp +++ b/unittests/cfdp/testEofPdu.cpp @@ -5,7 +5,7 @@ #include "fsfw/cfdp/pdu/EofPduSerializer.h" #include "fsfw/globalfunctions/arrayprinter.h" -TEST_CASE("EOF PDU", "[EofPdu]") { +TEST_CASE("EOF PDU", "[cfdp][pdu]") { using namespace cfdp; ReturnValue_t result = HasReturnvaluesIF::RETURN_OK; diff --git a/unittests/cfdp/testFileData.cpp b/unittests/cfdp/testFileData.cpp index fcf586eb..272cea47 100644 --- a/unittests/cfdp/testFileData.cpp +++ b/unittests/cfdp/testFileData.cpp @@ -6,7 +6,7 @@ #include "fsfw/globalfunctions/arrayprinter.h" #include "fsfw/serviceinterface.h" -TEST_CASE("File Data PDU", "[FileDataPdu]") { +TEST_CASE("File Data PDU", "[cfdp][pdu]") { using namespace cfdp; ReturnValue_t result = HasReturnvaluesIF::RETURN_OK; diff --git a/unittests/cfdp/testFileDirective.cpp b/unittests/cfdp/testFileDirective.cpp new file mode 100644 index 00000000..31053d01 --- /dev/null +++ b/unittests/cfdp/testFileDirective.cpp @@ -0,0 +1,73 @@ +#include +#include + +#include "fsfw/cfdp/pdu/FileDirectiveDeserializer.h" +#include "fsfw/cfdp/pdu/FileDirectiveSerializer.h" + +TEST_CASE("CFDP File Directive", "[cfdp]") { + using namespace cfdp; + std::array serBuf{}; + ReturnValue_t result; + cfdp::TransactionSeqNum seqNum = TransactionSeqNum(cfdp::WidthInBytes::ONE_BYTE, 2); + cfdp::EntityId sourceId = EntityId(cfdp::WidthInBytes::ONE_BYTE, 0); + cfdp::EntityId destId = EntityId(cfdp::WidthInBytes::ONE_BYTE, 1); + PduConfig pduConf = + PduConfig(sourceId, destId, cfdp::TransmissionModes::ACKNOWLEDGED, seqNum, false); + uint8_t* serTarget = serBuf.data(); + const uint8_t* deserTarget = serTarget; + size_t serSize = 0; + + SECTION("File Directive") { + auto fdSer = FileDirectiveSerializer(pduConf, FileDirectives::ACK, 4); + REQUIRE(fdSer.getSerializedSize() == 8); + serTarget = serBuf.data(); + serSize = 0; + result = fdSer.serialize(&serTarget, &serSize, serBuf.size(), SerializeIF::Endianness::NETWORK); + REQUIRE(result == HasReturnvaluesIF::RETURN_OK); + // Only version bits are set + REQUIRE(serBuf[0] == 0b00100000); + // PDU data field length is 5 (4 + Directive code octet) + REQUIRE(serBuf[1] == 0); + REQUIRE(serBuf[2] == 5); + // Entity and Transaction Sequence number are 1 byte large + REQUIRE(serBuf[3] == 0b00010001); + // Source ID + REQUIRE(serBuf[4] == 0); + // Transaction Seq Number + REQUIRE(serBuf[5] == 2); + // Dest ID + REQUIRE(serBuf[6] == 1); + REQUIRE(serBuf[7] == FileDirectives::ACK); + + serTarget = serBuf.data(); + size_t deserSize = 20; + serSize = 0; + REQUIRE(fdSer.deSerialize(&deserTarget, &deserSize, SerializeIF::Endianness::NETWORK) == + HasReturnvaluesIF::RETURN_FAILED); + REQUIRE(fdSer.serialize(nullptr, nullptr, 85, SerializeIF::Endianness::NETWORK) == + HasReturnvaluesIF::RETURN_FAILED); + for (uint8_t idx = 0; idx < 8; idx++) { + serTarget = serBuf.data(); + serSize = 0; + REQUIRE(fdSer.serialize(&serTarget, &serSize, idx, SerializeIF::Endianness::NETWORK) == + SerializeIF::BUFFER_TOO_SHORT); + } + + deserTarget = serBuf.data(); + deserSize = 0; + auto fdDeser = FileDirectiveDeserializer(deserTarget, serBuf.size()); + REQUIRE(fdDeser.getEndianness() == SerializeIF::Endianness::NETWORK); + fdDeser.setEndianness(SerializeIF::Endianness::MACHINE); + REQUIRE(fdDeser.getEndianness() == SerializeIF::Endianness::MACHINE); + fdDeser.setEndianness(SerializeIF::Endianness::NETWORK); + REQUIRE(fdDeser.parseData() == HasReturnvaluesIF::RETURN_OK); + REQUIRE(fdDeser.getFileDirective() == FileDirectives::ACK); + REQUIRE(fdDeser.getPduDataFieldLen() == 5); + REQUIRE(fdDeser.getHeaderSize() == 8); + REQUIRE(fdDeser.getPduType() == cfdp::PduType::FILE_DIRECTIVE); + + serBuf[7] = 0xff; + // Invalid file directive + REQUIRE(fdDeser.parseData() == cfdp::INVALID_DIRECTIVE_FIELDS); + } +} \ No newline at end of file diff --git a/unittests/cfdp/testFinishedPdu.cpp b/unittests/cfdp/testFinishedPdu.cpp index f581ee0b..c2aa3bb1 100644 --- a/unittests/cfdp/testFinishedPdu.cpp +++ b/unittests/cfdp/testFinishedPdu.cpp @@ -5,7 +5,7 @@ #include "fsfw/cfdp/pdu/FinishedPduSerializer.h" #include "fsfw/globalfunctions/arrayprinter.h" -TEST_CASE("Finished PDU", "[FinishedPdu]") { +TEST_CASE("Finished PDU", "[cfdp][pdu]") { using namespace cfdp; ReturnValue_t result = HasReturnvaluesIF::RETURN_OK; std::array fnBuffer = {}; diff --git a/unittests/cfdp/testKeepAlivePdu.cpp b/unittests/cfdp/testKeepAlivePdu.cpp index e6eb919e..876b71f6 100644 --- a/unittests/cfdp/testKeepAlivePdu.cpp +++ b/unittests/cfdp/testKeepAlivePdu.cpp @@ -5,7 +5,7 @@ #include "fsfw/cfdp/pdu/KeepAlivePduSerializer.h" #include "fsfw/globalfunctions/arrayprinter.h" -TEST_CASE("Keep Alive PDU", "[KeepAlivePdu]") { +TEST_CASE("Keep Alive PDU", "[cfdp][pdu]") { using namespace cfdp; ReturnValue_t result = HasReturnvaluesIF::RETURN_OK; std::array kaBuffer = {}; diff --git a/unittests/cfdp/testMetadataPdu.cpp b/unittests/cfdp/testMetadataPdu.cpp index 71749af3..b54d8f79 100644 --- a/unittests/cfdp/testMetadataPdu.cpp +++ b/unittests/cfdp/testMetadataPdu.cpp @@ -8,7 +8,7 @@ #include "fsfw/cfdp/tlv/FilestoreResponseTlv.h" #include "fsfw/globalfunctions/arrayprinter.h" -TEST_CASE("Metadata PDU", "[MetadataPdu]") { +TEST_CASE("Metadata PDU", "[cfdp][pdu]") { using namespace cfdp; ReturnValue_t result = HasReturnvaluesIF::RETURN_OK; std::array mdBuffer = {}; diff --git a/unittests/cfdp/testNakPdu.cpp b/unittests/cfdp/testNakPdu.cpp index eb112402..5eee60a4 100644 --- a/unittests/cfdp/testNakPdu.cpp +++ b/unittests/cfdp/testNakPdu.cpp @@ -6,7 +6,7 @@ #include "fsfw/cfdp/pdu/PduConfig.h" #include "fsfw/globalfunctions/arrayprinter.h" -TEST_CASE("NAK PDU", "[NakPdu]") { +TEST_CASE("NAK PDU", "[cfdp][pdu]") { using namespace cfdp; ReturnValue_t result = HasReturnvaluesIF::RETURN_OK; std::array nakBuffer = {}; diff --git a/unittests/cfdp/testPromptPdu.cpp b/unittests/cfdp/testPromptPdu.cpp index d8e33441..88dc8ac9 100644 --- a/unittests/cfdp/testPromptPdu.cpp +++ b/unittests/cfdp/testPromptPdu.cpp @@ -5,7 +5,7 @@ #include "fsfw/cfdp/pdu/PromptPduSerializer.h" #include "fsfw/globalfunctions/arrayprinter.h" -TEST_CASE("Prompt PDU", "[PromptPdu]") { +TEST_CASE("Prompt PDU", "[cfdp][pdu]") { using namespace cfdp; ReturnValue_t result = HasReturnvaluesIF::RETURN_OK; std::array rawBuf = {}; diff --git a/unittests/cfdp/testTlvsLvs.cpp b/unittests/cfdp/testTlvsLvs.cpp index 90dd688c..e311b5d6 100644 --- a/unittests/cfdp/testTlvsLvs.cpp +++ b/unittests/cfdp/testTlvsLvs.cpp @@ -14,7 +14,7 @@ #include "fsfw/cfdp/tlv/Tlv.h" #include "fsfw/globalfunctions/arrayprinter.h" -TEST_CASE("CFDP TLV LV", "[CfdpTlvLv]") { +TEST_CASE("CFDP TLV LV", "[cfdp]") { using namespace cfdp; ReturnValue_t result; std::array rawBuf{}; diff --git a/unittests/tcdistributor/testCcsdsDistributor.cpp b/unittests/tcdistributor/testCcsdsDistributor.cpp index 30e96945..b283b3bd 100644 --- a/unittests/tcdistributor/testCcsdsDistributor.cpp +++ b/unittests/tcdistributor/testCcsdsDistributor.cpp @@ -8,7 +8,7 @@ #include "mocks/CcsdsCheckerMock.h" #include "mocks/MessageQueueMock.h" -TEST_CASE("CCSDS Distributor", "[ccsds-distrib]") { +TEST_CASE("CCSDS Distributor", "[ccsds][tcdistrib]") { LocalPool::LocalPoolConfig cfg = {{5, 32}, {2, 64}}; LocalPool pool(objects::NO_OBJECT, cfg); auto queue = MessageQueueMock(1); From 29bcaee19653a4e99b763e7877dffabc8ffd44f1 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Wed, 3 Aug 2022 13:34:49 +0200 Subject: [PATCH 014/169] some tests for new var len field --- src/fsfw/cfdp/pdu/VarLenField.cpp | 25 +++++++++---------------- src/fsfw/cfdp/pdu/VarLenField.h | 9 ++++++++- unittests/cfdp/testCfdp.cpp | 14 +++++++++++++- 3 files changed, 30 insertions(+), 18 deletions(-) diff --git a/src/fsfw/cfdp/pdu/VarLenField.cpp b/src/fsfw/cfdp/pdu/VarLenField.cpp index cb72735e..7713ed11 100644 --- a/src/fsfw/cfdp/pdu/VarLenField.cpp +++ b/src/fsfw/cfdp/pdu/VarLenField.cpp @@ -21,27 +21,27 @@ cfdp::VarLenField::VarLenField() : width(cfdp::WidthInBytes::ONE_BYTE) { value.o cfdp::WidthInBytes cfdp::VarLenField::getWidth() const { return width; } -ReturnValue_t cfdp::VarLenField::setValue(cfdp::WidthInBytes widthInBytes, size_t value) { +ReturnValue_t cfdp::VarLenField::setValue(cfdp::WidthInBytes widthInBytes, size_t value_) { switch (widthInBytes) { case (cfdp::WidthInBytes::ONE_BYTE): { - if (value > UINT8_MAX) { + if (value_ > UINT8_MAX) { return HasReturnvaluesIF::RETURN_FAILED; } - this->value.oneByte = value; + this->value.oneByte = value_; break; } case (cfdp::WidthInBytes::TWO_BYTES): { - if (value > UINT16_MAX) { + if (value_ > UINT16_MAX) { return HasReturnvaluesIF::RETURN_FAILED; } - this->value.twoBytes = value; + this->value.twoBytes = value_; break; } case (cfdp::WidthInBytes::FOUR_BYTES): { - if (value > UINT32_MAX) { + if (value_ > UINT32_MAX) { return HasReturnvaluesIF::RETURN_FAILED; } - this->value.fourBytes = value; + this->value.fourBytes = value_; break; } default: { @@ -93,9 +93,9 @@ ReturnValue_t cfdp::VarLenField::serialize(uint8_t **buffer, size_t *size, size_ size_t cfdp::VarLenField::getSerializedSize() const { return width; } -ReturnValue_t cfdp::VarLenField::deSerialize(cfdp::WidthInBytes width, const uint8_t **buffer, +ReturnValue_t cfdp::VarLenField::deSerialize(cfdp::WidthInBytes width_, const uint8_t **buffer, size_t *size, Endianness streamEndianness) { - this->width = width; + this->width = width_; return deSerialize(buffer, size, streamEndianness); } @@ -118,10 +118,3 @@ ReturnValue_t cfdp::VarLenField::deSerialize(const uint8_t **buffer, size_t *siz } } } - -template -cfdp::VarLenField::VarLenField(UnsignedByteField byteField) - : width(static_cast(sizeof(T))) { - static_assert((sizeof(T) % 2) == 0); - value = byteField.getValue(); -} diff --git a/src/fsfw/cfdp/pdu/VarLenField.h b/src/fsfw/cfdp/pdu/VarLenField.h index 3b7ccc5a..dfc6b195 100644 --- a/src/fsfw/cfdp/pdu/VarLenField.h +++ b/src/fsfw/cfdp/pdu/VarLenField.h @@ -41,9 +41,16 @@ class VarLenField : public SerializeIF { Endianness streamEndianness) override; cfdp::WidthInBytes width; - LengthFieldLen value; + LengthFieldLen value{}; }; +template +cfdp::VarLenField::VarLenField(UnsignedByteField byteField) + : width(static_cast(sizeof(T))) { + static_assert((sizeof(T) % 2) == 0); + setValue(width, byteField.getValue()); +} + } // namespace cfdp #endif /* FSFW_SRC_FSFW_CFDP_PDU_VARLENFIELD_H_ */ diff --git a/unittests/cfdp/testCfdp.cpp b/unittests/cfdp/testCfdp.cpp index 8cfdbca4..475322a2 100644 --- a/unittests/cfdp/testCfdp.cpp +++ b/unittests/cfdp/testCfdp.cpp @@ -75,7 +75,7 @@ TEST_CASE("CFDP Base", "[cfdp]") { REQUIRE(fdDeser.parseData() == cfdp::INVALID_DIRECTIVE_FIELDS); } - SECTION("FileSize") { + SECTION("File Size") { std::array fssBuf = {}; uint8_t* buffer = fssBuf.data(); size_t size = 0; @@ -90,4 +90,16 @@ TEST_CASE("CFDP Base", "[cfdp]") { REQUIRE(result == HasReturnvaluesIF::RETURN_OK); REQUIRE(fileSize == 0x20); } + + SECTION("Var Length Field") { + VarLenField defaultField; + CHECK(defaultField.getValue() == 0); + CHECK(defaultField.getWidth() == WidthInBytes::ONE_BYTE); + VarLenField explicitField(WidthInBytes::FOUR_BYTES, 12); + CHECK(explicitField.getWidth() == WidthInBytes::FOUR_BYTES); + CHECK(explicitField.getValue() == 12); + VarLenField fromUnsignedByteField(UnsignedByteField(12)); + CHECK(fromUnsignedByteField.getWidth() == WidthInBytes::TWO_BYTES); + CHECK(fromUnsignedByteField.getValue() == 12); + } } From b20e8a9679b7b46dfec43d3716bdd36c4313e68e Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Wed, 3 Aug 2022 15:12:29 +0200 Subject: [PATCH 015/169] continue new cfdp router --- src/fsfw/cfdp/CMakeLists.txt | 3 +- src/fsfw/cfdp/CfdpDistributor.cpp | 144 +++++++++++++++++ src/fsfw/cfdp/CfdpHandler.cpp | 111 +++++++------ src/fsfw/cfdp/CfdpHandler.h | 126 +++++++-------- src/fsfw/cfdp/CfdpRouter.cpp | 65 ++++++++ src/fsfw/cfdp/CfdpRouter.h | 74 +++++++++ .../CfdpRouterIF.h} | 16 +- src/fsfw/cfdp/pdu/VarLenField.cpp | 8 + src/fsfw/cfdp/pdu/VarLenField.h | 3 + src/fsfw/events/fwSubsystemIdRanges.h | 2 +- src/fsfw/tcdistribution/CMakeLists.txt | 10 +- src/fsfw/tcdistribution/CcsdsDistributor.cpp | 6 +- src/fsfw/tcdistribution/CcsdsDistributorIF.h | 12 +- .../tcdistribution/CcsdsPacketChecker.cpp | 8 +- src/fsfw/tcdistribution/CcsdsUnpacker.cpp | 57 ------- src/fsfw/tcdistribution/CcsdsUnpacker.h | 24 --- src/fsfw/tcdistribution/CfdpDistributor.cpp | 146 ------------------ src/fsfw/tcdistribution/CfdpDistributor.h | 71 --------- src/fsfw/tcdistribution/PusDistributor.cpp | 8 +- src/fsfw/tcdistribution/PusPacketChecker.cpp | 8 +- src/fsfw/tcdistribution/TcDistributorBase.cpp | 3 +- src/fsfw/tcdistribution/TcDistributorBase.h | 4 - src/fsfw/tcdistribution/definitions.h | 10 +- src/fsfw/tmtcservices/AcceptsTelemetryIF.h | 2 + unittests/mocks/AcceptsTmMock.cpp | 2 + unittests/mocks/AcceptsTmMock.h | 1 + .../tcdistributor/testCcsdsDistributor.cpp | 2 +- 27 files changed, 464 insertions(+), 462 deletions(-) create mode 100644 src/fsfw/cfdp/CfdpDistributor.cpp create mode 100644 src/fsfw/cfdp/CfdpRouter.cpp create mode 100644 src/fsfw/cfdp/CfdpRouter.h rename src/fsfw/{tcdistribution/CfdpDistributorIF.h => cfdp/CfdpRouterIF.h} (51%) delete mode 100644 src/fsfw/tcdistribution/CcsdsUnpacker.cpp delete mode 100644 src/fsfw/tcdistribution/CcsdsUnpacker.h delete mode 100644 src/fsfw/tcdistribution/CfdpDistributor.cpp delete mode 100644 src/fsfw/tcdistribution/CfdpDistributor.h diff --git a/src/fsfw/cfdp/CMakeLists.txt b/src/fsfw/cfdp/CMakeLists.txt index f2affbb4..2d58e190 100644 --- a/src/fsfw/cfdp/CMakeLists.txt +++ b/src/fsfw/cfdp/CMakeLists.txt @@ -1,4 +1,5 @@ -target_sources(${LIB_FSFW_NAME} PRIVATE CfdpHandler.cpp CfdpMessage.cpp) +target_sources(${LIB_FSFW_NAME} PRIVATE CfdpMessage.cpp CfdpRouter.cpp) +# CfdpDistributor.cpp CfdpHandler.cpp add_subdirectory(pdu) add_subdirectory(tlv) diff --git a/src/fsfw/cfdp/CfdpDistributor.cpp b/src/fsfw/cfdp/CfdpDistributor.cpp new file mode 100644 index 00000000..fa221822 --- /dev/null +++ b/src/fsfw/cfdp/CfdpDistributor.cpp @@ -0,0 +1,144 @@ +//#include "CfdpRouter.h" +//#include "fsfw/tcdistribution/CcsdsDistributorIF.h" +//#include "fsfw/tmtcpacket/cfdp/CfdpPacketStored.h" +// +//#ifndef FSFW_CFDP_DISTRIBUTOR_DEBUGGING +//#define FSFW_CFDP_DISTRIBUTOR_DEBUGGING 1 +//#endif +// +// CfdpHandler::CfdpHandler(uint16_t setApid, object_id_t setObjectId, +// object_id_t setPacketSource) +// : TcDistributorBase(setObjectId), +// apid(setApid), +// checker(setApid), +// tcStatus(RETURN_FAILED), +// packetSource(setPacketSource) {} +// +// CfdpHandler::~CfdpHandler() = default; +// +// ReturnValue_t CfdpHandler::selectDestination(MessageQueueId_t& destId) { +// //#if FSFW_CFDP_DISTRIBUTOR_DEBUGGING == 1 +// // store_address_t storeId = this->currentMessage.getStorageId(); +// //#if FSFW_CPP_OSTREAM_ENABLED == 1 +// // sif::debug << "CFDPDistributor::handlePacket received: " << storeId.poolIndex << ", " +// // << storeId.packetIndex << std::endl; +// //#else +// // sif::printDebug("CFDPDistributor::handlePacket received: %d, %d\n", storeId.poolIndex, +// // storeId.packetIndex); +// //#endif +// //#endif +// // auto queueMapIt = this->queueMap.end(); +// // if (this->currentPacket == nullptr) { +// // return queueMapIt; +// // } +// // this->currentPacket->setStoreAddress(this->currentMessage.getStorageId()); +// // if (currentPacket->getFullData() != nullptr) { +// // tcStatus = checker.checkPacket(*currentPacket, currentPacket->getFullPacketLen()); +// // 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 +// // } +// // queueMapIt = this->queueMap.find(0); +// // } else { +// // tcStatus = PACKET_LOST; +// // } +// // +// // if (queueMapIt == this->queueMap.end()) { +// // tcStatus = DESTINATION_NOT_FOUND; +// //#if FSFW_VERBOSE_LEVEL >= 1 +// //#if FSFW_CPP_OSTREAM_ENABLED == 1 +// // sif::debug << "CFDPDistributor::handlePacket: Destination not found" << std::endl; +// //#else +// // sif::printDebug("CFDPDistributor::handlePacket: Destination not found\n"); +// //#endif /* !FSFW_CPP_OSTREAM_ENABLED == 1 */ +// //#endif +// // } +// // +// // if (tcStatus != RETURN_OK) { +// // return this->queueMap.end(); +// // } else { +// // return queueMapIt; +// // } +// return HasReturnvaluesIF::RETURN_OK; +//} +// +// ReturnValue_t CfdpHandler::registerHandler(AcceptsTelecommandsIF* handler) { +// // uint16_t handlerId = +// // handler->getIdentifier(); // should be 0, because CfdpHandler does not set a set a +// // service-ID +// //#if FSFW_CFDP_DISTRIBUTOR_DEBUGGING == 1 +// //#if FSFW_CPP_OSTREAM_ENABLED == 1 +// // sif::info << "CFDPDistributor::registerHandler: Handler ID: " << static_cast(handlerId) +// // << std::endl; +// //#else +// // sif::printInfo("CFDPDistributor::registerHandler: Handler ID: %d\n", +// // static_cast(handlerId)); +// //#endif +// //#endif +// // 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::registerHandler: Service ID already" +// // " exists in map" +// // << std::endl; +// //#else +// // sif::printError("CFDPDistributor::registerHandler: Service ID already exists in map\n"); +// //#endif +// //#endif +// // return SERVICE_ID_ALREADY_EXISTS; +// // } +// return HasReturnvaluesIF::RETURN_OK; +//} +// +// MessageQueueId_t CfdpHandler::getRequestQueue() const { 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; +//// } +//// } +// +// uint32_t CfdpHandler::getIdentifier() const { return this->apid; } +// +// ReturnValue_t CfdpHandler::initialize() { +// // currentPacket = new CfdpPacketStored(); +// // if (currentPacket == nullptr) { +// // // Should not happen, memory allocation failed! +// // return ObjectManagerIF::CHILD_INIT_FAILED; +// // } +// // +// // auto* ccsdsDistributor = ObjectManager::instance()->get(packetSource); +// // if (ccsdsDistributor == nullptr) { +// //#if FSFW_CPP_OSTREAM_ENABLED == 1 +// // sif::error << "CFDPDistributor::initialize: Packet source invalid" << std::endl; +// // sif::error << " Make sure it exists and implements CCSDSDistributorIF!" << std::endl; +// //#else +// // sif::printError("CFDPDistributor::initialize: Packet source invalid\n"); +// // sif::printError("Make sure it exists and implements CcsdsDistributorIF\n"); +// //#endif +// // return RETURN_FAILED; +// // } +// // return ccsdsDistributor->registerApplication(this); +// return HasReturnvaluesIF::RETURN_OK; +//} diff --git a/src/fsfw/cfdp/CfdpHandler.cpp b/src/fsfw/cfdp/CfdpHandler.cpp index 35e5b2bc..1bf03e10 100644 --- a/src/fsfw/cfdp/CfdpHandler.cpp +++ b/src/fsfw/cfdp/CfdpHandler.cpp @@ -1,57 +1,54 @@ -#include "fsfw/cfdp/CfdpHandler.h" - -#include "fsfw/cfdp/CfdpMessage.h" -#include "fsfw/ipc/CommandMessage.h" -#include "fsfw/ipc/QueueFactory.h" -#include "fsfw/objectmanager/ObjectManager.h" -#include "fsfw/storagemanager/storeAddress.h" -#include "fsfw/tmtcservices/AcceptsTelemetryIF.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() = default; - -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(store_address_t storeId) { -#if FSFW_VERBOSE_LEVEL >= 1 -#if FSFW_CPP_OSTREAM_ENABLED == 1 - sif::debug << "CFDPHandler::handleRequest" << std::endl; -#else - sif::printDebug("CFDPHandler::handleRequest\n"); -#endif /* !FSFW_CPP_OSTREAM_ENABLED == 1 */ -#endif - - // TODO read out packet from store using storeId - - return RETURN_OK; -} - -ReturnValue_t CfdpHandler::performOperation(uint8_t opCode) { - ReturnValue_t status = RETURN_OK; - CommandMessage currentMessage; - for (status = this->requestQueue->receiveMessage(¤tMessage); status == RETURN_OK; - status = this->requestQueue->receiveMessage(¤tMessage)) { - store_address_t storeId = CfdpMessage::getStoreId(¤tMessage); - this->handleRequest(storeId); - } - return RETURN_OK; -} - -uint32_t CfdpHandler::getIdentifier() const { return 0; } - -MessageQueueId_t CfdpHandler::getRequestQueue() const { return this->requestQueue->getId(); } +//#include "fsfw/cfdp/CfdpHandler.h" +// +//#include "fsfw/cfdp/CfdpMessage.h" +//#include "fsfw/ipc/CommandMessage.h" +//#include "fsfw/ipc/QueueFactory.h" +//#include "fsfw/objectmanager/ObjectManager.h" +//#include "fsfw/storagemanager/storeAddress.h" +//#include "fsfw/tmtcservices/AcceptsTelemetryIF.h" +// +// CfdpHandler::CfdpHandler(object_id_t setObjectId, CfdpHandler* dist) +// : SystemObject(setObjectId) { +// requestQueue = QueueFactory::instance()->createMessageQueue(CFDP_HANDLER_MAX_RECEPTION); +// distributor = dist; +//} +// +// CfdpHandler::~CfdpHandler() = default; +// +// 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(store_address_t storeId) { +//#if FSFW_VERBOSE_LEVEL >= 1 +//#if FSFW_CPP_OSTREAM_ENABLED == 1 +// sif::debug << "CFDPHandler::handleRequest" << std::endl; +//#else +// sif::printDebug("CFDPHandler::handleRequest\n"); +//#endif /* !FSFW_CPP_OSTREAM_ENABLED == 1 */ +//#endif +// +// // TODO read out packet from store using storeId +// +// return RETURN_OK; +//} +// +// ReturnValue_t CfdpHandler::performOperation(uint8_t opCode) { +// ReturnValue_t status = RETURN_OK; +// CommandMessage currentMessage; +// for (status = this->requestQueue->receiveMessage(¤tMessage); status == RETURN_OK; +// status = this->requestQueue->receiveMessage(¤tMessage)) { +// store_address_t storeId = CfdpMessage::getStoreId(¤tMessage); +// this->handleRequest(storeId); +// } +// return RETURN_OK; +//} +// +// uint32_t CfdpHandler::getIdentifier() const { return 0; } +// +// MessageQueueId_t CfdpHandler::getRequestQueue() const { return this->requestQueue->getId(); } diff --git a/src/fsfw/cfdp/CfdpHandler.h b/src/fsfw/cfdp/CfdpHandler.h index 8730f3eb..8c2827ec 100644 --- a/src/fsfw/cfdp/CfdpHandler.h +++ b/src/fsfw/cfdp/CfdpHandler.h @@ -1,63 +1,63 @@ -#ifndef FSFW_CFDP_CFDPHANDLER_H_ -#define FSFW_CFDP_CFDPHANDLER_H_ - -#include "fsfw/ipc/MessageQueueIF.h" -#include "fsfw/objectmanager/SystemObject.h" -#include "fsfw/returnvalues/HasReturnvaluesIF.h" -#include "fsfw/tasks/ExecutableObjectIF.h" -#include "fsfw/tcdistribution/CfdpDistributor.h" -#include "fsfw/tmtcservices/AcceptsTelecommandsIF.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(store_address_t storeId); - - virtual ReturnValue_t initialize() override; - virtual uint32_t getIdentifier() const override; - MessageQueueId_t getRequestQueue() const 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 = 100; -}; - -#endif /* FSFW_CFDP_CFDPHANDLER_H_ */ +//#ifndef FSFW_CFDP_CFDPHANDLER_H_ +//#define FSFW_CFDP_CFDPHANDLER_H_ +// +//#include "fsfw/ipc/MessageQueueIF.h" +//#include "fsfw/objectmanager/SystemObject.h" +//#include "fsfw/returnvalues/HasReturnvaluesIF.h" +//#include "fsfw/storagemanager/storeAddress.h" +//#include "fsfw/tasks/ExecutableObjectIF.h" +//#include "fsfw/tmtcservices/AcceptsTelecommandsIF.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, CfdpHandler* distributor); +// /** +// * The destructor is empty. +// */ +// virtual ~CfdpHandler(); +// +// virtual ReturnValue_t handleRequest(store_address_t storeId); +// +// virtual ReturnValue_t initialize() override; +// virtual uint32_t getIdentifier() const override; +// MessageQueueId_t getRequestQueue() const 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; +// +// CfdpHandler* 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 = 100; +//}; +// +//#endif /* FSFW_CFDP_CFDPHANDLER_H_ */ diff --git a/src/fsfw/cfdp/CfdpRouter.cpp b/src/fsfw/cfdp/CfdpRouter.cpp new file mode 100644 index 00000000..9e4f623e --- /dev/null +++ b/src/fsfw/cfdp/CfdpRouter.cpp @@ -0,0 +1,65 @@ +#include "CfdpRouter.h" + +#include + +#include "fsfw/tcdistribution/definitions.h" + +CfdpRouter::CfdpRouter(CfdpRouterCfg cfg) : TcDistributorBase(cfg.objectId), tmQueue(cfg.tmQueue) {} + +ReturnValue_t CfdpRouter::registerTmSink(cfdp::EntityId address, AcceptsTelemetryIF& tmDest) { + for (const auto& dest : tmDestinations) { + if (dest.id == address) { + return HasReturnvaluesIF::RETURN_FAILED; + } + } + tmDestinations.emplace_back(address, tmDest.getName(), tmDest.getReportReceptionQueue()); + return HasReturnvaluesIF::RETURN_OK; +} +ReturnValue_t CfdpRouter::registerTcDestination(cfdp::EntityId address, + AcceptsTelecommandsIF& tcDest) { + for (const auto& dest : tcDestinations) { + if (dest.id == address) { + return HasReturnvaluesIF::RETURN_FAILED; + } + } + tcDestinations.emplace_back(address, tcDest.getName(), tcDest.getRequestQueue()); + return HasReturnvaluesIF::RETURN_OK; +} + +ReturnValue_t CfdpRouter::selectDestination(MessageQueueId_t& destId) { return 0; } + +const char* CfdpRouter::getName() const { return "CFDP Router"; } + +uint32_t CfdpRouter::getIdentifier() const { return 0; } + +MessageQueueId_t CfdpRouter::getRequestQueue() const { return tcQueue->getId(); } + +MessageQueueId_t CfdpRouter::getReportReceptionQueue(uint8_t virtualChannel) { + return tmQueue.getId(); +} + +ReturnValue_t CfdpRouter::performOperation(uint8_t opCode) { + lastTcError = TcDistributorBase::performOperation(opCode); + lastTmError = performTmHandling(); + if (lastTcError != HasReturnvaluesIF::RETURN_OK or lastTmError != HasReturnvaluesIF::RETURN_OK) { + return HasReturnvaluesIF::RETURN_FAILED; + } + return HasReturnvaluesIF::RETURN_OK; +} + +ReturnValue_t CfdpRouter::performTmHandling() { + ReturnValue_t status; + ReturnValue_t result = HasReturnvaluesIF::RETURN_OK; + for (status = tmQueue.receiveMessage(¤tMessage); status == RETURN_OK; + status = tmQueue.receiveMessage(¤tMessage)) { + ReturnValue_t packetResult = handlePacket(); + if (packetResult != HasReturnvaluesIF::RETURN_OK) { + result = packetResult; + triggerEvent(tmtcdistrib::HANDLE_PACKET_FAILED, packetResult, ccsds::PacketType::TM); + } + } + if (status == MessageQueueIF::EMPTY) { + return result; + } + return result; +} diff --git a/src/fsfw/cfdp/CfdpRouter.h b/src/fsfw/cfdp/CfdpRouter.h new file mode 100644 index 00000000..178f0177 --- /dev/null +++ b/src/fsfw/cfdp/CfdpRouter.h @@ -0,0 +1,74 @@ +#ifndef FSFW_TCDISTRIBUTION_CFDPDISTRIBUTOR_H_ +#define FSFW_TCDISTRIBUTION_CFDPDISTRIBUTOR_H_ + +#include +#include + +#include "CfdpRouterIF.h" +#include "fsfw/returnvalues/HasReturnvaluesIF.h" +#include "fsfw/tcdistribution/CfdpPacketChecker.h" +#include "fsfw/tcdistribution/TcDistributorBase.h" +#include "fsfw/tmtcpacket/cfdp/CfdpPacketStored.h" +#include "fsfw/tmtcservices/AcceptsTelecommandsIF.h" +#include "fsfw/tmtcservices/VerificationReporter.h" + +struct CfdpRouterCfg { + CfdpRouterCfg(object_id_t objectId, MessageQueueIF& tmQueue) + : objectId(objectId), tmQueue(tmQueue) {} + + object_id_t objectId; + MessageQueueIF& tmQueue; +}; +/** + * This will be the primary component to perform PDU forwading procedures. This includes forwarding + * CFDP TC packets to registered source or destination handlers, and forwarding all telemetry + * generated by them to registered TM sinks. + * @ingroup tc_distribution + */ +class CfdpRouter : public TcDistributorBase, + public CfdpRouterIF, + public AcceptsTelecommandsIF, + public AcceptsTelemetryIF { + public: + /** + * The ctor passes @c set_apid to the checker class and calls the + * TcDistribution ctor with a certain object id. + * @param setApid The APID of this receiving Application. + * @param setObjectId Object ID of the distributor itself + * @param setPacketSource Object ID of the source of TC packets. + * Must implement CcsdsDistributorIF. + */ + explicit CfdpRouter(CfdpRouterCfg cfg); + + ReturnValue_t performOperation(uint8_t opCode) override; + ReturnValue_t performTmHandling(); + [[nodiscard]] const char* getName() const override; + [[nodiscard]] uint32_t getIdentifier() const override; + [[nodiscard]] MessageQueueId_t getRequestQueue() const override; + MessageQueueId_t getReportReceptionQueue(uint8_t virtualChannel) override; + ReturnValue_t registerTmSink(cfdp::EntityId address, AcceptsTelemetryIF& tmDest) override; + ReturnValue_t registerTcDestination(cfdp::EntityId address, + AcceptsTelecommandsIF& tcDest) override; + + protected: + struct EntityInfo { + EntityInfo(cfdp::EntityId id, const char* name, MessageQueueId_t queueId) + : id(std::move(id)), name(name), queueId(queueId) {} + cfdp::EntityId id; + const char* name; + MessageQueueId_t queueId; + }; + ReturnValue_t lastTcError = HasReturnvaluesIF::RETURN_OK; + ReturnValue_t lastTmError = HasReturnvaluesIF::RETURN_OK; + // I don't think a regular OBSW will have more than 1 or 2 of these destinations, so I think + // it is okay to accept the overhead here + std::vector tmDestinations; + std::vector tcDestinations; + MessageQueueIF& tmQueue; + + ReturnValue_t selectDestination(MessageQueueId_t& destId) override; + + private: +}; + +#endif /* FSFW_TCDISTRIBUTION_CFDPDISTRIBUTOR_H_ */ diff --git a/src/fsfw/tcdistribution/CfdpDistributorIF.h b/src/fsfw/cfdp/CfdpRouterIF.h similarity index 51% rename from src/fsfw/tcdistribution/CfdpDistributorIF.h rename to src/fsfw/cfdp/CfdpRouterIF.h index 660a9709..0c630407 100644 --- a/src/fsfw/tcdistribution/CfdpDistributorIF.h +++ b/src/fsfw/cfdp/CfdpRouterIF.h @@ -1,26 +1,32 @@ #ifndef FSFW_TCDISTRIBUTION_CFDPDISTRIBUTORIF_H_ #define FSFW_TCDISTRIBUTION_CFDPDISTRIBUTORIF_H_ -#include "../ipc/MessageQueueSenderIF.h" -#include "../tmtcservices/AcceptsTelecommandsIF.h" +#include "fsfw/cfdp/definitions.h" +#include "fsfw/cfdp/pdu/PduHeaderIF.h" +#include "fsfw/ipc/MessageQueueSenderIF.h" +#include "fsfw/tmtcservices/AcceptsTelecommandsIF.h" +#include "fsfw/tmtcservices/AcceptsTelemetryIF.h" /** * This interface allows CFDP Services to register themselves at a CFDP Distributor. * @ingroup tc_distribution */ -class CfdpDistributorIF { +class CfdpRouterIF { public: /** * The empty virtual destructor. */ - virtual ~CfdpDistributorIF() = default; + virtual ~CfdpRouterIF() = default; + + virtual ReturnValue_t registerTmSink(cfdp::EntityId address, AcceptsTelemetryIF& tmDest) = 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; + virtual ReturnValue_t registerTcDestination(cfdp::EntityId address, + AcceptsTelecommandsIF& tcDest) = 0; }; #endif /* FSFW_TCDISTRIBUTION_CFDPDISTRIBUTORIF_H_ */ diff --git a/src/fsfw/cfdp/pdu/VarLenField.cpp b/src/fsfw/cfdp/pdu/VarLenField.cpp index 7713ed11..a403534b 100644 --- a/src/fsfw/cfdp/pdu/VarLenField.cpp +++ b/src/fsfw/cfdp/pdu/VarLenField.cpp @@ -118,3 +118,11 @@ ReturnValue_t cfdp::VarLenField::deSerialize(const uint8_t **buffer, size_t *siz } } } + +bool cfdp::VarLenField::operator<(const cfdp::VarLenField &other) const { + return getValue() < other.getValue(); +} + +bool cfdp::VarLenField::operator==(const cfdp::VarLenField &other) const { + return getValue() == other.getValue(); +} diff --git a/src/fsfw/cfdp/pdu/VarLenField.h b/src/fsfw/cfdp/pdu/VarLenField.h index dfc6b195..7f8a1acb 100644 --- a/src/fsfw/cfdp/pdu/VarLenField.h +++ b/src/fsfw/cfdp/pdu/VarLenField.h @@ -23,6 +23,9 @@ class VarLenField : public SerializeIF { explicit VarLenField(UnsignedByteField byteField); VarLenField(cfdp::WidthInBytes width, size_t value); + bool operator==(const VarLenField &other) const; + bool operator<(const VarLenField &other) const; + ReturnValue_t setValue(cfdp::WidthInBytes, size_t value); ReturnValue_t serialize(uint8_t **buffer, size_t *size, size_t maxSize, diff --git a/src/fsfw/events/fwSubsystemIdRanges.h b/src/fsfw/events/fwSubsystemIdRanges.h index a09c935c..d8e4ade6 100644 --- a/src/fsfw/events/fwSubsystemIdRanges.h +++ b/src/fsfw/events/fwSubsystemIdRanges.h @@ -19,7 +19,7 @@ enum : uint8_t { HK = 73, SYSTEM_MANAGER = 74, SYSTEM_MANAGER_1 = 75, - TC_DISTRIBUTION = 76, + TMTC_DISTRIBUTION = 76, SYSTEM_1 = 79, PUS_SERVICE_1 = 80, PUS_SERVICE_2 = 82, diff --git a/src/fsfw/tcdistribution/CMakeLists.txt b/src/fsfw/tcdistribution/CMakeLists.txt index 5501f4af..bcad563a 100644 --- a/src/fsfw/tcdistribution/CMakeLists.txt +++ b/src/fsfw/tcdistribution/CMakeLists.txt @@ -1,10 +1,4 @@ target_sources( ${LIB_FSFW_NAME} - PRIVATE CcsdsDistributor.cpp - PusDistributor.cpp - TcDistributorBase.cpp - PusPacketChecker.cpp - TcPacketCheckCFDP.cpp - CfdpDistributor.cpp - CcsdsPacketChecker.cpp - CcsdsUnpacker.cpp) + PRIVATE CcsdsDistributor.cpp PusDistributor.cpp TcDistributorBase.cpp + PusPacketChecker.cpp TcPacketCheckCFDP.cpp CcsdsPacketChecker.cpp) diff --git a/src/fsfw/tcdistribution/CcsdsDistributor.cpp b/src/fsfw/tcdistribution/CcsdsDistributor.cpp index 0ec5ed5c..6932d2d3 100644 --- a/src/fsfw/tcdistribution/CcsdsDistributor.cpp +++ b/src/fsfw/tcdistribution/CcsdsDistributor.cpp @@ -96,13 +96,13 @@ ReturnValue_t CcsdsDistributor::selectDestination(MessageQueueId_t& destId) { void CcsdsDistributor::handlePacketCheckFailure(ReturnValue_t result) { #if FSFW_VERBOSE_LEVEL >= 1 const char* reason = "Unknown reason"; - if (result == tcdistrib::INVALID_CCSDS_VERSION) { + if (result == tmtcdistrib::INVALID_CCSDS_VERSION) { reason = "Invalid CCSDS version"; } else if (result == tcdistrib::INCOMPLETE_PACKET) { reason = "Size missmatch between CCSDS data length and packet length"; - } else if (result == tcdistrib::INVALID_APID) { + } else if (result == tmtcdistrib::INVALID_APID) { reason = "No valid handler APID found"; - } else if (result == tcdistrib::INVALID_PACKET_TYPE) { + } else if (result == tmtcdistrib::INVALID_PACKET_TYPE) { reason = "Invalid Packet Type TM detected"; } #if FSFW_CPP_OSTREAM_ENABLED == 1 diff --git a/src/fsfw/tcdistribution/CcsdsDistributorIF.h b/src/fsfw/tcdistribution/CcsdsDistributorIF.h index 6deb1c67..f70a2ef9 100644 --- a/src/fsfw/tcdistribution/CcsdsDistributorIF.h +++ b/src/fsfw/tcdistribution/CcsdsDistributorIF.h @@ -35,12 +35,12 @@ class CcsdsDistributorIF { * @param info Contains all necessary info to register an application. * @return * - @c RETURN_OK on success, - * - @c RETURN_FAILED or tcdistrib error code on failure. - * - @c tcdistrib::INVALID_CCSDS_VERSION - * - @c tcdistrib::INVALID_APID No APID available to handle this packet - * - @c tcdistrib::INVALID_PACKET_TYPE Packet type TM detected - * - @c tcdistrib::INCORRECT_PRIMARY_HEADER Something other wrong with primary header - * - @c tcdistrib::INCOMPLETE_PACKET Size missmatch between data length field and actual + * - @c RETURN_FAILED or tmtcdistrib error code on failure. + * - @c tmtcdistrib::INVALID_CCSDS_VERSION + * - @c tmtcdistrib::INVALID_APID No APID available to handle this packet + * - @c tmtcdistrib::INVALID_PACKET_TYPE Packet type TM detected + * - @c tmtcdistrib::INCORRECT_PRIMARY_HEADER Something other wrong with primary header + * - @c tmtcdistrib::INCOMPLETE_PACKET Size missmatch between data length field and actual * length */ virtual ReturnValue_t registerApplication(DestInfo info) = 0; diff --git a/src/fsfw/tcdistribution/CcsdsPacketChecker.cpp b/src/fsfw/tcdistribution/CcsdsPacketChecker.cpp index 394f5a57..ea2bd9d1 100644 --- a/src/fsfw/tcdistribution/CcsdsPacketChecker.cpp +++ b/src/fsfw/tcdistribution/CcsdsPacketChecker.cpp @@ -10,19 +10,19 @@ ReturnValue_t CcsdsPacketChecker::checkPacket(const SpacePacketReader& currentPa size_t packetLen) { if (checkApid) { if (currentPacket.getApid() != apid) { - return tcdistrib::INVALID_APID; + return tmtcdistrib::INVALID_APID; } } if (currentPacket.getVersion() != ccsdsVersion) { - return tcdistrib::INVALID_CCSDS_VERSION; + return tmtcdistrib::INVALID_CCSDS_VERSION; } if (currentPacket.getPacketType() != packetType) { - return tcdistrib::INVALID_PACKET_TYPE; + return tmtcdistrib::INVALID_PACKET_TYPE; } // This assumes that the getFullPacketLen version uses the space packet data length field if (currentPacket.getFullPacketLen() != packetLen) { - return tcdistrib::INCOMPLETE_PACKET; + return tmtcdistrib::INCOMPLETE_PACKET; } return HasReturnvaluesIF::RETURN_OK; } diff --git a/src/fsfw/tcdistribution/CcsdsUnpacker.cpp b/src/fsfw/tcdistribution/CcsdsUnpacker.cpp deleted file mode 100644 index 9b212d2e..00000000 --- a/src/fsfw/tcdistribution/CcsdsUnpacker.cpp +++ /dev/null @@ -1,57 +0,0 @@ -#include "CcsdsUnpacker.h" - -#include "fsfw/tmtcservices/TmTcMessage.h" - -CcsdsUnpacker::CcsdsUnpacker(MessageQueueIF& msgQueue, AcceptsTelecommandsIF& receiver, - StorageManagerIF& sourceStore) - : sourceStore(sourceStore), msgQueue(msgQueue), receiver(receiver) { - msgQueue.setDefaultDestination(receiver.getRequestQueue()); -} - -ReturnValue_t CcsdsUnpacker::performOperation(uint8_t operationCode) { - TmTcMessage msg; - ReturnValue_t result; - for (result = msgQueue.receiveMessage(&msg); result == HasReturnvaluesIF::RETURN_OK; - result = msgQueue.receiveMessage(&msg)) { - auto resultPair = sourceStore.getData(msg.getStorageId()); - if (resultPair.first != HasReturnvaluesIF::RETURN_OK) { - continue; - } - if (resultPair.second.size() < 6) { - // TODO: This is a config error. Does it make sense to forward the message? - result = msgQueue.sendToDefault(&msg); - if (result != HasReturnvaluesIF::RETURN_OK) { - } - continue; - } - StorageManagerIF* tgtStore; - if (targetStore != nullptr) { - tgtStore = targetStore; - } else { - tgtStore = &sourceStore; - } - store_address_t newId; - uint8_t* ptr; - result = tgtStore->getFreeElement(&newId, resultPair.second.size(), &ptr); - if (result != HasReturnvaluesIF::RETURN_OK) { - // TODO: Implement error handling - } - std::memcpy(ptr, resultPair.second.data() + 6, resultPair.second.size() - 6); - result = sourceStore.deleteData(msg.getStorageId()); - if (result != HasReturnvaluesIF::RETURN_OK) { - // TODO: Implement error handling (though this really should not happen) - } - TmTcMessage newMsg(newId); - result = msgQueue.sendToDefault(&newMsg); - if (result != HasReturnvaluesIF::RETURN_OK) { - } - } - return result; -} - -void CcsdsUnpacker::setDifferentTargetStore(StorageManagerIF& otherTargetStore) { - targetStore = &otherTargetStore; -} - -uint32_t CcsdsUnpacker::getIdentifier() const { return 0; } -MessageQueueId_t CcsdsUnpacker::getRequestQueue() const { return 0; } diff --git a/src/fsfw/tcdistribution/CcsdsUnpacker.h b/src/fsfw/tcdistribution/CcsdsUnpacker.h deleted file mode 100644 index 267b8e64..00000000 --- a/src/fsfw/tcdistribution/CcsdsUnpacker.h +++ /dev/null @@ -1,24 +0,0 @@ -#ifndef FSFW_TCDISTRIBUTION_CCSDSUNPACKER_H -#define FSFW_TCDISTRIBUTION_CCSDSUNPACKER_H - -#include "fsfw/storagemanager/StorageManagerIF.h" -#include "fsfw/tasks/ExecutableObjectIF.h" -#include "fsfw/tmtcservices/AcceptsTelecommandsIF.h" - -class CcsdsUnpacker : public ExecutableObjectIF, public AcceptsTelecommandsIF { - public: - CcsdsUnpacker(MessageQueueIF& msgQueue, AcceptsTelecommandsIF& receiver, - StorageManagerIF& sourceStore); - - void setDifferentTargetStore(StorageManagerIF& otherTargetStore); - ReturnValue_t performOperation(uint8_t operationCode) override; - uint32_t getIdentifier() const override; - MessageQueueId_t getRequestQueue() const override; - - private: - StorageManagerIF& sourceStore; - StorageManagerIF* targetStore = nullptr; - MessageQueueIF& msgQueue; - AcceptsTelecommandsIF& receiver; -}; -#endif // FSFW_TCDISTRIBUTION_CCSDSUNPACKER_H diff --git a/src/fsfw/tcdistribution/CfdpDistributor.cpp b/src/fsfw/tcdistribution/CfdpDistributor.cpp deleted file mode 100644 index 3b1d1538..00000000 --- a/src/fsfw/tcdistribution/CfdpDistributor.cpp +++ /dev/null @@ -1,146 +0,0 @@ -#include "fsfw/tcdistribution/CfdpDistributor.h" - -#include "fsfw/objectmanager/ObjectManager.h" -#include "fsfw/tcdistribution/CcsdsDistributorIF.h" -#include "fsfw/tmtcpacket/cfdp/CfdpPacketStored.h" - -#ifndef FSFW_CFDP_DISTRIBUTOR_DEBUGGING -#define FSFW_CFDP_DISTRIBUTOR_DEBUGGING 1 -#endif - -CfdpDistributor::CfdpDistributor(uint16_t setApid, object_id_t setObjectId, - object_id_t setPacketSource) - : TcDistributorBase(setObjectId), - apid(setApid), - checker(setApid), - tcStatus(RETURN_FAILED), - packetSource(setPacketSource) {} - -CfdpDistributor::~CfdpDistributor() = default; - -ReturnValue_t CfdpDistributor::selectDestination(MessageQueueId_t& destId) { - //#if FSFW_CFDP_DISTRIBUTOR_DEBUGGING == 1 - // store_address_t storeId = this->currentMessage.getStorageId(); - //#if FSFW_CPP_OSTREAM_ENABLED == 1 - // sif::debug << "CFDPDistributor::handlePacket received: " << storeId.poolIndex << ", " - // << storeId.packetIndex << std::endl; - //#else - // sif::printDebug("CFDPDistributor::handlePacket received: %d, %d\n", storeId.poolIndex, - // storeId.packetIndex); - //#endif - //#endif - // auto queueMapIt = this->queueMap.end(); - // if (this->currentPacket == nullptr) { - // return queueMapIt; - // } - // this->currentPacket->setStoreAddress(this->currentMessage.getStorageId()); - // if (currentPacket->getFullData() != nullptr) { - // tcStatus = checker.checkPacket(*currentPacket, currentPacket->getFullPacketLen()); - // 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 - // } - // queueMapIt = this->queueMap.find(0); - // } else { - // tcStatus = PACKET_LOST; - // } - // - // if (queueMapIt == this->queueMap.end()) { - // tcStatus = DESTINATION_NOT_FOUND; - //#if FSFW_VERBOSE_LEVEL >= 1 - //#if FSFW_CPP_OSTREAM_ENABLED == 1 - // sif::debug << "CFDPDistributor::handlePacket: Destination not found" << std::endl; - //#else - // sif::printDebug("CFDPDistributor::handlePacket: Destination not found\n"); - //#endif /* !FSFW_CPP_OSTREAM_ENABLED == 1 */ - //#endif - // } - // - // if (tcStatus != RETURN_OK) { - // return this->queueMap.end(); - // } else { - // return queueMapIt; - // } - return HasReturnvaluesIF::RETURN_OK; -} - -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 FSFW_CFDP_DISTRIBUTOR_DEBUGGING == 1 - //#if FSFW_CPP_OSTREAM_ENABLED == 1 - // sif::info << "CFDPDistributor::registerHandler: Handler ID: " << static_cast(handlerId) - // << std::endl; - //#else - // sif::printInfo("CFDPDistributor::registerHandler: Handler ID: %d\n", - // static_cast(handlerId)); - //#endif - //#endif - // 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::registerHandler: Service ID already" - // " exists in map" - // << std::endl; - //#else - // sif::printError("CFDPDistributor::registerHandler: Service ID already exists in map\n"); - //#endif - //#endif - // return SERVICE_ID_ALREADY_EXISTS; - // } - return HasReturnvaluesIF::RETURN_OK; -} - -MessageQueueId_t CfdpDistributor::getRequestQueue() const { 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; -// } -// } - -uint32_t CfdpDistributor::getIdentifier() const { return this->apid; } - -ReturnValue_t CfdpDistributor::initialize() { - // currentPacket = new CfdpPacketStored(); - // if (currentPacket == nullptr) { - // // Should not happen, memory allocation failed! - // return ObjectManagerIF::CHILD_INIT_FAILED; - // } - // - // auto* ccsdsDistributor = ObjectManager::instance()->get(packetSource); - // if (ccsdsDistributor == nullptr) { - //#if FSFW_CPP_OSTREAM_ENABLED == 1 - // sif::error << "CFDPDistributor::initialize: Packet source invalid" << std::endl; - // sif::error << " Make sure it exists and implements CCSDSDistributorIF!" << std::endl; - //#else - // sif::printError("CFDPDistributor::initialize: Packet source invalid\n"); - // sif::printError("Make sure it exists and implements CcsdsDistributorIF\n"); - //#endif - // return RETURN_FAILED; - // } - // return ccsdsDistributor->registerApplication(this); - return HasReturnvaluesIF::RETURN_OK; -} diff --git a/src/fsfw/tcdistribution/CfdpDistributor.h b/src/fsfw/tcdistribution/CfdpDistributor.h deleted file mode 100644 index 7bfaee7b..00000000 --- a/src/fsfw/tcdistribution/CfdpDistributor.h +++ /dev/null @@ -1,71 +0,0 @@ -#ifndef FSFW_TCDISTRIBUTION_CFDPDISTRIBUTOR_H_ -#define FSFW_TCDISTRIBUTION_CFDPDISTRIBUTOR_H_ - -#include - -#include "../returnvalues/HasReturnvaluesIF.h" -#include "../tmtcpacket/cfdp/CfdpPacketStored.h" -#include "../tmtcservices/AcceptsTelecommandsIF.h" -#include "../tmtcservices/VerificationReporter.h" -#include "CfdpDistributorIF.h" -#include "TcDistributorBase.h" - -/** - * This class accepts CFDP Telecommands and forwards them to Application - * services. - * @ingroup tc_distribution - */ -class CfdpDistributor : public TcDistributorBase, - public CfdpDistributorIF, - public AcceptsTelecommandsIF { - public: - /** - * The ctor passes @c set_apid to the checker class and calls the - * TcDistribution ctor with a certain object id. - * @param setApid The APID of this receiving Application. - * @param setObjectId Object ID of the distributor itself - * @param setPacketSource Object ID of the source of TC packets. - * Must implement CcsdsDistributorIF. - */ - CfdpDistributor(uint16_t setApid, object_id_t setObjectId, object_id_t setPacketSource); - /** - * The destructor is empty. - */ - ~CfdpDistributor() override; - ReturnValue_t registerHandler(AcceptsTelecommandsIF* handler) override; - MessageQueueId_t getRequestQueue() const override; - ReturnValue_t initialize() override; - uint32_t getIdentifier() const override; - - protected: - uint16_t apid; - /** - * The currently handled packet is stored here. - */ - CfdpPacketStored* currentPacket = nullptr; - CfdpPacketChecker checker; - /** - * With this variable, the current check status is stored to generate - * acceptance messages later. - */ - ReturnValue_t tcStatus; - - const object_id_t packetSource; - - /** - * This method reads the packet service, checks if such a service is - * registered and forwards the packet to the destination. - * It also initiates the formal packet check and sending of verification - * messages. - * @return Iterator to map entry of found service id - * or iterator to @c map.end(). - */ - ReturnValue_t selectDestination(MessageQueueId_t& destId) override; - /** - * The callback here handles the generation of acceptance - * success/failure messages. - */ - // ReturnValue_t callbackAfterSending(ReturnValue_t queueStatus) override; -}; - -#endif /* FSFW_TCDISTRIBUTION_CFDPDISTRIBUTOR_H_ */ diff --git a/src/fsfw/tcdistribution/PusDistributor.cpp b/src/fsfw/tcdistribution/PusDistributor.cpp index 7be0810d..f719b50f 100644 --- a/src/fsfw/tcdistribution/PusDistributor.cpp +++ b/src/fsfw/tcdistribution/PusDistributor.cpp @@ -147,13 +147,13 @@ void PusDistributor::checkerFailurePrinter() const { const char* reason = "Unknown reason"; if (tcStatus == tcdistrib::INCORRECT_CHECKSUM) { reason = "Checksum Error"; - } else if (tcStatus == tcdistrib::INCORRECT_PRIMARY_HEADER) { + } else if (tcStatus == tmtcdistrib::INCORRECT_PRIMARY_HEADER) { reason = "Incorrect Primary Header"; - } else if (tcStatus == tcdistrib::INVALID_APID) { + } else if (tcStatus == tmtcdistrib::INVALID_APID) { reason = "Illegal APID"; - } else if (tcStatus == tcdistrib::INCORRECT_SECONDARY_HEADER) { + } else if (tcStatus == tmtcdistrib::INCORRECT_SECONDARY_HEADER) { reason = "Incorrect Secondary Header"; - } else if (tcStatus == tcdistrib::INCOMPLETE_PACKET) { + } else if (tcStatus == tmtcdistrib::INCOMPLETE_PACKET) { reason = "Incomplete packet"; } #if FSFW_CPP_OSTREAM_ENABLED == 1 diff --git a/src/fsfw/tcdistribution/PusPacketChecker.cpp b/src/fsfw/tcdistribution/PusPacketChecker.cpp index 8ea8b6a8..52f7f77e 100644 --- a/src/fsfw/tcdistribution/PusPacketChecker.cpp +++ b/src/fsfw/tcdistribution/PusPacketChecker.cpp @@ -12,17 +12,17 @@ PusPacketChecker::PusPacketChecker(uint16_t apid, ccsds::PacketType packetType_, ReturnValue_t PusPacketChecker::checkPacket(const PusTcReader& pusPacket, size_t packetLen) { // Other primary header fields are checked by base class if (not pusPacket.hasSecHeader()) { - return tcdistrib::INVALID_SEC_HEADER_FIELD; + return tmtcdistrib::INVALID_SEC_HEADER_FIELD; } uint16_t calculated_crc = CRC::crc16ccitt(pusPacket.getFullData(), pusPacket.getFullPacketLen()); if (calculated_crc != 0) { - return tcdistrib::INCORRECT_CHECKSUM; + return tmtcdistrib::INCORRECT_CHECKSUM; } if (pusPacket.getApid() != apid) { - return tcdistrib::INVALID_APID; + return tmtcdistrib::INVALID_APID; } if (pusPacket.getPusVersion() != pusVersion) { - return tcdistrib::INVALID_PUS_VERSION; + return tmtcdistrib::INVALID_PUS_VERSION; } return HasReturnvaluesIF::RETURN_OK; } diff --git a/src/fsfw/tcdistribution/TcDistributorBase.cpp b/src/fsfw/tcdistribution/TcDistributorBase.cpp index e673d628..230c97fb 100644 --- a/src/fsfw/tcdistribution/TcDistributorBase.cpp +++ b/src/fsfw/tcdistribution/TcDistributorBase.cpp @@ -1,5 +1,6 @@ #include "fsfw/tcdistribution/TcDistributorBase.h" +#include "definitions.h" #include "fsfw/ipc/QueueFactory.h" #include "fsfw/tmtcservices/TmTcMessage.h" @@ -25,7 +26,7 @@ ReturnValue_t TcDistributorBase::performOperation(uint8_t opCode) { ReturnValue_t packetResult = handlePacket(); if (packetResult != HasReturnvaluesIF::RETURN_OK) { result = packetResult; - triggerEvent(HANDLE_PACKET_FAILED, packetResult, __LINE__); + triggerEvent(tmtcdistrib::HANDLE_PACKET_FAILED, packetResult, 1); } } if (status == MessageQueueIF::EMPTY) { diff --git a/src/fsfw/tcdistribution/TcDistributorBase.h b/src/fsfw/tcdistribution/TcDistributorBase.h index c2bee0b9..81132fbd 100644 --- a/src/fsfw/tcdistribution/TcDistributorBase.h +++ b/src/fsfw/tcdistribution/TcDistributorBase.h @@ -34,10 +34,6 @@ class TcDistributorBase : public SystemObject, public ExecutableObjectIF, public static constexpr ReturnValue_t PACKET_LOST = MAKE_RETURN_CODE(1); static constexpr ReturnValue_t DESTINATION_NOT_FOUND = MAKE_RETURN_CODE(2); static constexpr ReturnValue_t SERVICE_ID_ALREADY_EXISTS = MAKE_RETURN_CODE(3); - - static constexpr uint8_t SUBSYSTEM_ID = SUBSYSTEM_ID::TC_DISTRIBUTION; - //! P1: Returnvalue, P2: Line number - static constexpr Event HANDLE_PACKET_FAILED = event::makeEvent(SUBSYSTEM_ID, 0, severity::LOW); /** * Within the default constructor, the SystemObject id is set and the * message queue is initialized. diff --git a/src/fsfw/tcdistribution/definitions.h b/src/fsfw/tcdistribution/definitions.h index ce640308..8cae639e 100644 --- a/src/fsfw/tcdistribution/definitions.h +++ b/src/fsfw/tcdistribution/definitions.h @@ -3,10 +3,12 @@ #include +#include "fsfw/events/Event.h" +#include "fsfw/events/fwSubsystemIdRanges.h" #include "fsfw/returnvalues/FwClassIds.h" #include "fsfw/returnvalues/HasReturnvaluesIF.h" -namespace tcdistrib { +namespace tmtcdistrib { static const uint8_t INTERFACE_ID = CLASS_ID::PACKET_CHECK; static constexpr ReturnValue_t INVALID_CCSDS_VERSION = MAKE_RETURN_CODE(0); static constexpr ReturnValue_t INVALID_APID = MAKE_RETURN_CODE(1); @@ -20,5 +22,9 @@ static constexpr ReturnValue_t INCORRECT_CHECKSUM = MAKE_RETURN_CODE(7); static constexpr ReturnValue_t ILLEGAL_PACKET_SUBTYPE = MAKE_RETURN_CODE(8); static constexpr ReturnValue_t INCORRECT_SECONDARY_HEADER = MAKE_RETURN_CODE(9); -}; // namespace tcdistrib +static constexpr uint8_t SUBSYSTEM_ID = SUBSYSTEM_ID::TMTC_DISTRIBUTION; +//! P1: Returnvalue, P2: 0 for TM issues, 1 for TC issues +static constexpr Event HANDLE_PACKET_FAILED = event::makeEvent(SUBSYSTEM_ID, 0, severity::LOW); + +}; // namespace tmtcdistrib #endif // FSFW_TMTCPACKET_DEFINITIONS_H diff --git a/src/fsfw/tmtcservices/AcceptsTelemetryIF.h b/src/fsfw/tmtcservices/AcceptsTelemetryIF.h index 6f8a6226..c3e3eff3 100644 --- a/src/fsfw/tmtcservices/AcceptsTelemetryIF.h +++ b/src/fsfw/tmtcservices/AcceptsTelemetryIF.h @@ -14,6 +14,8 @@ class AcceptsTelemetryIF { * @brief The virtual destructor as it is mandatory for C++ interfaces. */ virtual ~AcceptsTelemetryIF() = default; + + [[nodiscard]] virtual const char* getName() const = 0; /** * @brief This method returns the message queue id of the telemetry * receiving message queue. diff --git a/unittests/mocks/AcceptsTmMock.cpp b/unittests/mocks/AcceptsTmMock.cpp index 5b1e0d05..7b997047 100644 --- a/unittests/mocks/AcceptsTmMock.cpp +++ b/unittests/mocks/AcceptsTmMock.cpp @@ -9,3 +9,5 @@ AcceptsTmMock::AcceptsTmMock(MessageQueueId_t queueToReturn) MessageQueueId_t AcceptsTmMock::getReportReceptionQueue(uint8_t virtualChannel) { return returnedQueue; } + +const char* AcceptsTmMock::getName() const { return "TM Acceptor Mock"; } diff --git a/unittests/mocks/AcceptsTmMock.h b/unittests/mocks/AcceptsTmMock.h index a9422eb4..d6cc7f85 100644 --- a/unittests/mocks/AcceptsTmMock.h +++ b/unittests/mocks/AcceptsTmMock.h @@ -10,6 +10,7 @@ class AcceptsTmMock : public SystemObject, public AcceptsTelemetryIF { explicit AcceptsTmMock(MessageQueueId_t queueToReturn); MessageQueueId_t getReportReceptionQueue(uint8_t virtualChannel) override; + const char* getName() const override; MessageQueueId_t returnedQueue; }; diff --git a/unittests/tcdistributor/testCcsdsDistributor.cpp b/unittests/tcdistributor/testCcsdsDistributor.cpp index b283b3bd..ce96a425 100644 --- a/unittests/tcdistributor/testCcsdsDistributor.cpp +++ b/unittests/tcdistributor/testCcsdsDistributor.cpp @@ -8,7 +8,7 @@ #include "mocks/CcsdsCheckerMock.h" #include "mocks/MessageQueueMock.h" -TEST_CASE("CCSDS Distributor", "[ccsds][tcdistrib]") { +TEST_CASE("CCSDS Distributor", "[ccsds][tmtcdistrib]") { LocalPool::LocalPoolConfig cfg = {{5, 32}, {2, 64}}; LocalPool pool(objects::NO_OBJECT, cfg); auto queue = MessageQueueMock(1); From 7fb9e14555ee14910b11d5087aa1c1e503eb2e36 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Wed, 3 Aug 2022 15:22:39 +0200 Subject: [PATCH 016/169] better names for CFDP components --- src/fsfw/cfdp/CfdpRouter.cpp | 2 - src/fsfw/cfdp/pdu/CMakeLists.txt | 4 +- src/fsfw/cfdp/pdu/FileDataDeserializer.cpp | 8 +- src/fsfw/cfdp/pdu/FileDataDeserializer.h | 4 +- src/fsfw/cfdp/pdu/FileDataSerializer.cpp | 7 +- src/fsfw/cfdp/pdu/FileDataSerializer.h | 4 +- .../cfdp/pdu/FileDirectiveDeserializer.cpp | 8 +- src/fsfw/cfdp/pdu/FileDirectiveDeserializer.h | 4 +- src/fsfw/cfdp/pdu/FileDirectiveSerializer.cpp | 8 +- src/fsfw/cfdp/pdu/FileDirectiveSerializer.h | 4 +- src/fsfw/cfdp/pdu/HeaderCreator.cpp | 114 +++++++++++++++++ .../{HeaderSerializer.h => HeaderCreator.h} | 4 +- ...eaderDeserializer.cpp => HeaderReader.cpp} | 56 +++++---- .../{HeaderDeserializer.h => HeaderReader.h} | 45 ++++--- src/fsfw/cfdp/pdu/HeaderSerializer.cpp | 117 ------------------ src/fsfw/cfdp/pdu/PduHeaderIF.h | 26 ++-- src/fsfw/cfdp/pdu/PromptPduDeserializer.h | 2 +- unittests/cfdp/testCfdpHeader.cpp | 12 +- 18 files changed, 217 insertions(+), 212 deletions(-) create mode 100644 src/fsfw/cfdp/pdu/HeaderCreator.cpp rename src/fsfw/cfdp/pdu/{HeaderSerializer.h => HeaderCreator.h} (96%) rename src/fsfw/cfdp/pdu/{HeaderDeserializer.cpp => HeaderReader.cpp} (63%) rename src/fsfw/cfdp/pdu/{HeaderDeserializer.h => HeaderReader.h} (61%) delete mode 100644 src/fsfw/cfdp/pdu/HeaderSerializer.cpp diff --git a/src/fsfw/cfdp/CfdpRouter.cpp b/src/fsfw/cfdp/CfdpRouter.cpp index 9e4f623e..dfe910e6 100644 --- a/src/fsfw/cfdp/CfdpRouter.cpp +++ b/src/fsfw/cfdp/CfdpRouter.cpp @@ -1,7 +1,5 @@ #include "CfdpRouter.h" -#include - #include "fsfw/tcdistribution/definitions.h" CfdpRouter::CfdpRouter(CfdpRouterCfg cfg) : TcDistributorBase(cfg.objectId), tmQueue(cfg.tmQueue) {} diff --git a/src/fsfw/cfdp/pdu/CMakeLists.txt b/src/fsfw/cfdp/pdu/CMakeLists.txt index 4f345bdc..0d49217b 100644 --- a/src/fsfw/cfdp/pdu/CMakeLists.txt +++ b/src/fsfw/cfdp/pdu/CMakeLists.txt @@ -2,8 +2,8 @@ target_sources( ${LIB_FSFW_NAME} PRIVATE PduConfig.cpp VarLenField.cpp - HeaderSerializer.cpp - HeaderDeserializer.cpp + HeaderCreator.cpp + HeaderReader.cpp FileDirectiveDeserializer.cpp FileDirectiveSerializer.cpp AckInfo.cpp diff --git a/src/fsfw/cfdp/pdu/FileDataDeserializer.cpp b/src/fsfw/cfdp/pdu/FileDataDeserializer.cpp index 240c4188..2b3171a8 100644 --- a/src/fsfw/cfdp/pdu/FileDataDeserializer.cpp +++ b/src/fsfw/cfdp/pdu/FileDataDeserializer.cpp @@ -2,16 +2,16 @@ FileDataDeserializer::FileDataDeserializer(const uint8_t* pduBuf, size_t maxSize, FileDataInfo& info) - : HeaderDeserializer(pduBuf, maxSize), info(info) {} + : HeaderReader(pduBuf, maxSize), info(info) {} ReturnValue_t FileDataDeserializer::parseData() { - ReturnValue_t result = HeaderDeserializer::parseData(); + ReturnValue_t result = HeaderReader::parseData(); if (result != HasReturnvaluesIF::RETURN_OK) { return result; } - size_t currentIdx = HeaderDeserializer::getHeaderSize(); + size_t currentIdx = HeaderReader::getHeaderSize(); const uint8_t* buf = rawPtr + currentIdx; - size_t remSize = HeaderDeserializer::getWholePduSize() - currentIdx; + size_t remSize = HeaderReader::getWholePduSize() - currentIdx; if (remSize < 1) { return SerializeIF::STREAM_TOO_SHORT; } diff --git a/src/fsfw/cfdp/pdu/FileDataDeserializer.h b/src/fsfw/cfdp/pdu/FileDataDeserializer.h index 833c0561..f6723fec 100644 --- a/src/fsfw/cfdp/pdu/FileDataDeserializer.h +++ b/src/fsfw/cfdp/pdu/FileDataDeserializer.h @@ -3,9 +3,9 @@ #include "../definitions.h" #include "FileDataInfo.h" -#include "HeaderDeserializer.h" +#include "HeaderReader.h" -class FileDataDeserializer : public HeaderDeserializer { +class FileDataDeserializer : public HeaderReader { public: FileDataDeserializer(const uint8_t* pduBuf, size_t maxSize, FileDataInfo& info); diff --git a/src/fsfw/cfdp/pdu/FileDataSerializer.cpp b/src/fsfw/cfdp/pdu/FileDataSerializer.cpp index 837b418b..2e86a255 100644 --- a/src/fsfw/cfdp/pdu/FileDataSerializer.cpp +++ b/src/fsfw/cfdp/pdu/FileDataSerializer.cpp @@ -3,8 +3,7 @@ #include FileDataSerializer::FileDataSerializer(PduConfig& conf, FileDataInfo& info) - : HeaderSerializer(conf, cfdp::PduType::FILE_DATA, 0, info.getSegmentMetadataFlag()), - info(info) { + : HeaderCreator(conf, cfdp::PduType::FILE_DATA, 0, info.getSegmentMetadataFlag()), info(info) { update(); } @@ -16,7 +15,7 @@ void FileDataSerializer::update() { ReturnValue_t FileDataSerializer::serialize(uint8_t** buffer, size_t* size, size_t maxSize, Endianness streamEndianness) const { - ReturnValue_t result = HeaderSerializer::serialize(buffer, size, maxSize, streamEndianness); + ReturnValue_t result = HeaderCreator::serialize(buffer, size, maxSize, streamEndianness); if (result != HasReturnvaluesIF::RETURN_OK) { return result; } @@ -51,5 +50,5 @@ ReturnValue_t FileDataSerializer::serialize(uint8_t** buffer, size_t* size, size } size_t FileDataSerializer::getSerializedSize() const { - return HeaderSerializer::getSerializedSize() + info.getSerializedSize(this->getLargeFileFlag()); + return HeaderCreator::getSerializedSize() + info.getSerializedSize(this->getLargeFileFlag()); } diff --git a/src/fsfw/cfdp/pdu/FileDataSerializer.h b/src/fsfw/cfdp/pdu/FileDataSerializer.h index 662b9b4d..17d72e2e 100644 --- a/src/fsfw/cfdp/pdu/FileDataSerializer.h +++ b/src/fsfw/cfdp/pdu/FileDataSerializer.h @@ -3,9 +3,9 @@ #include "../definitions.h" #include "FileDataInfo.h" -#include "HeaderSerializer.h" +#include "HeaderCreator.h" -class FileDataSerializer : public HeaderSerializer { +class FileDataSerializer : public HeaderCreator { public: FileDataSerializer(PduConfig& conf, FileDataInfo& info); diff --git a/src/fsfw/cfdp/pdu/FileDirectiveDeserializer.cpp b/src/fsfw/cfdp/pdu/FileDirectiveDeserializer.cpp index 3c0552f7..162312d3 100644 --- a/src/fsfw/cfdp/pdu/FileDirectiveDeserializer.cpp +++ b/src/fsfw/cfdp/pdu/FileDirectiveDeserializer.cpp @@ -1,12 +1,12 @@ #include "FileDirectiveDeserializer.h" FileDirectiveDeserializer::FileDirectiveDeserializer(const uint8_t *pduBuf, size_t maxSize) - : HeaderDeserializer(pduBuf, maxSize) {} + : HeaderReader(pduBuf, maxSize) {} cfdp::FileDirectives FileDirectiveDeserializer::getFileDirective() const { return fileDirective; } ReturnValue_t FileDirectiveDeserializer::parseData() { - ReturnValue_t result = HeaderDeserializer::parseData(); + ReturnValue_t result = HeaderReader::parseData(); if (result != HasReturnvaluesIF::RETURN_OK) { return result; } @@ -16,7 +16,7 @@ ReturnValue_t FileDirectiveDeserializer::parseData() { if (FileDirectiveDeserializer::getWholePduSize() > maxSize) { return SerializeIF::STREAM_TOO_SHORT; } - size_t currentIdx = HeaderDeserializer::getHeaderSize(); + size_t currentIdx = HeaderReader::getHeaderSize(); if (not checkFileDirective(rawPtr[currentIdx])) { return cfdp::INVALID_DIRECTIVE_FIELDS; } @@ -26,7 +26,7 @@ ReturnValue_t FileDirectiveDeserializer::parseData() { size_t FileDirectiveDeserializer::getHeaderSize() const { // return size of header plus the directive byte - return HeaderDeserializer::getHeaderSize() + 1; + return HeaderReader::getHeaderSize() + 1; } bool FileDirectiveDeserializer::checkFileDirective(uint8_t rawByte) { diff --git a/src/fsfw/cfdp/pdu/FileDirectiveDeserializer.h b/src/fsfw/cfdp/pdu/FileDirectiveDeserializer.h index 064cb64a..193a71f3 100644 --- a/src/fsfw/cfdp/pdu/FileDirectiveDeserializer.h +++ b/src/fsfw/cfdp/pdu/FileDirectiveDeserializer.h @@ -2,7 +2,7 @@ #define FSFW_SRC_FSFW_CFDP_PDU_FILEDIRECTIVEDESERIALIZER_H_ #include "../definitions.h" -#include "fsfw/cfdp/pdu/HeaderDeserializer.h" +#include "fsfw/cfdp/pdu/HeaderReader.h" /** * @brief This class is used to deserialize a PDU file directive header from raw memory. @@ -11,7 +11,7 @@ * This is a zero-copy implementation and #parseData needs to be called to ensure the data is * valid. */ -class FileDirectiveDeserializer : public HeaderDeserializer { +class FileDirectiveDeserializer : public HeaderReader { public: FileDirectiveDeserializer(const uint8_t* pduBuf, size_t maxSize); diff --git a/src/fsfw/cfdp/pdu/FileDirectiveSerializer.cpp b/src/fsfw/cfdp/pdu/FileDirectiveSerializer.cpp index 98b2d0a2..e70b8b83 100644 --- a/src/fsfw/cfdp/pdu/FileDirectiveSerializer.cpp +++ b/src/fsfw/cfdp/pdu/FileDirectiveSerializer.cpp @@ -3,11 +3,11 @@ FileDirectiveSerializer::FileDirectiveSerializer(PduConfig &pduConf, cfdp::FileDirectives directiveCode, size_t directiveParamFieldLen) - : HeaderSerializer(pduConf, cfdp::PduType::FILE_DIRECTIVE, directiveParamFieldLen + 1), + : HeaderCreator(pduConf, cfdp::PduType::FILE_DIRECTIVE, directiveParamFieldLen + 1), directiveCode(directiveCode) {} size_t FileDirectiveSerializer::getSerializedSize() const { - return HeaderSerializer::getSerializedSize() + 1; + return HeaderCreator::getSerializedSize() + 1; } ReturnValue_t FileDirectiveSerializer::serialize(uint8_t **buffer, size_t *size, size_t maxSize, @@ -18,7 +18,7 @@ ReturnValue_t FileDirectiveSerializer::serialize(uint8_t **buffer, size_t *size, if (FileDirectiveSerializer::getWholePduSize() > maxSize) { return BUFFER_TOO_SHORT; } - ReturnValue_t result = HeaderSerializer::serialize(buffer, size, maxSize, streamEndianness); + ReturnValue_t result = HeaderCreator::serialize(buffer, size, maxSize, streamEndianness); if (result != HasReturnvaluesIF::RETURN_OK) { return result; } @@ -34,5 +34,5 @@ ReturnValue_t FileDirectiveSerializer::serialize(uint8_t **buffer, size_t *size, void FileDirectiveSerializer::setDirectiveDataFieldLen(size_t len) { // Set length of data field plus 1 byte for the directive octet - HeaderSerializer::setPduDataFieldLen(len + 1); + HeaderCreator::setPduDataFieldLen(len + 1); } diff --git a/src/fsfw/cfdp/pdu/FileDirectiveSerializer.h b/src/fsfw/cfdp/pdu/FileDirectiveSerializer.h index 8f86a5e1..ffe34412 100644 --- a/src/fsfw/cfdp/pdu/FileDirectiveSerializer.h +++ b/src/fsfw/cfdp/pdu/FileDirectiveSerializer.h @@ -1,9 +1,9 @@ #ifndef FSFW_SRC_FSFW_CFDP_PDU_FILEDIRECTIVESERIALIZER_H_ #define FSFW_SRC_FSFW_CFDP_PDU_FILEDIRECTIVESERIALIZER_H_ -#include "fsfw/cfdp/pdu/HeaderSerializer.h" +#include "fsfw/cfdp/pdu/HeaderCreator.h" -class FileDirectiveSerializer : public HeaderSerializer { +class FileDirectiveSerializer : public HeaderCreator { public: FileDirectiveSerializer(PduConfig& pduConf, cfdp::FileDirectives directiveCode, size_t directiveParamFieldLen); diff --git a/src/fsfw/cfdp/pdu/HeaderCreator.cpp b/src/fsfw/cfdp/pdu/HeaderCreator.cpp new file mode 100644 index 00000000..debeedeb --- /dev/null +++ b/src/fsfw/cfdp/pdu/HeaderCreator.cpp @@ -0,0 +1,114 @@ +#include "HeaderCreator.h" + +#include "HeaderReader.h" + +HeaderCreator::HeaderCreator(PduConfig &pduConf, cfdp::PduType pduType, size_t initPduDataFieldLen, + cfdp::SegmentMetadataFlag segmentMetadataFlag, + cfdp::SegmentationControl segCtrl) + : pduType(pduType), + segmentMetadataFlag(segmentMetadataFlag), + segmentationCtrl(segCtrl), + pduDataFieldLen(initPduDataFieldLen), + pduConf(pduConf) {} + +ReturnValue_t HeaderCreator::serialize(uint8_t **buffer, size_t *size, size_t maxSize, + Endianness streamEndianness) const { + if (buffer == nullptr or size == nullptr) { + return HasReturnvaluesIF::RETURN_FAILED; + } + if (maxSize < this->getSerializedSize()) { + return BUFFER_TOO_SHORT; + } + **buffer = cfdp::VERSION_BITS | this->pduType << 4 | pduConf.direction << 3 | pduConf.mode << 2 | + pduConf.crcFlag << 1 | pduConf.largeFile; + *buffer += 1; + **buffer = (pduDataFieldLen & 0xff00) >> 8; + *buffer += 1; + **buffer = pduDataFieldLen & 0x00ff; + *buffer += 1; + **buffer = segmentationCtrl << 7 | pduConf.sourceId.getWidth() << 4 | segmentMetadataFlag << 3 | + pduConf.seqNum.getWidth(); + *buffer += 1; + *size += 4; + ReturnValue_t result = pduConf.sourceId.serialize(buffer, size, maxSize, streamEndianness); + if (result != HasReturnvaluesIF::RETURN_OK) { + return result; + } + result = pduConf.seqNum.serialize(buffer, size, maxSize, streamEndianness); + if (result != HasReturnvaluesIF::RETURN_OK) { + return result; + } + result = pduConf.destId.serialize(buffer, size, maxSize, streamEndianness); + if (result != HasReturnvaluesIF::RETURN_OK) { + return result; + } + + return HasReturnvaluesIF::RETURN_OK; +} + +size_t HeaderCreator::getSerializedSize() const { + size_t shit = pduConf.seqNum.getWidth() + pduConf.sourceId.getWidth() * 2 + 4; + return shit; +} + +ReturnValue_t HeaderCreator::deSerialize(const uint8_t **buffer, size_t *size, + Endianness streamEndianness) { + // We could implement this, but I prefer dedicated classes + return HasReturnvaluesIF::RETURN_FAILED; +} + +size_t HeaderCreator::getWholePduSize() const { + // Return size of header plus the PDU data field length + return pduDataFieldLen + HeaderCreator::getSerializedSize(); +} + +size_t HeaderCreator::getPduDataFieldLen() const { return pduDataFieldLen; } + +void HeaderCreator::setPduDataFieldLen(size_t pduDataFieldLen_) { + pduDataFieldLen = pduDataFieldLen_; +} + +void HeaderCreator::setPduType(cfdp::PduType pduType_) { pduType = pduType_; } + +void HeaderCreator::setSegmentMetadataFlag(cfdp::SegmentMetadataFlag segmentMetadataFlag_) { + segmentMetadataFlag = segmentMetadataFlag_; +} + +cfdp::PduType HeaderCreator::getPduType() const { return pduType; } + +cfdp::Direction HeaderCreator::getDirection() const { return pduConf.direction; } + +cfdp::TransmissionModes HeaderCreator::getTransmissionMode() const { return pduConf.mode; } + +bool HeaderCreator::getCrcFlag() const { return pduConf.crcFlag; } + +bool HeaderCreator::getLargeFileFlag() const { return pduConf.largeFile; } + +cfdp::SegmentationControl HeaderCreator::getSegmentationControl() const { return segmentationCtrl; } + +cfdp::WidthInBytes HeaderCreator::getLenEntityIds() const { return pduConf.sourceId.getWidth(); } + +cfdp::WidthInBytes HeaderCreator::getLenSeqNum() const { return pduConf.seqNum.getWidth(); } + +cfdp::SegmentMetadataFlag HeaderCreator::getSegmentMetadataFlag() const { + return segmentMetadataFlag; +} + +void HeaderCreator::getSourceId(cfdp::EntityId &sourceId) const { sourceId = pduConf.sourceId; } + +void HeaderCreator::getDestId(cfdp::EntityId &destId) const { destId = pduConf.destId; } + +void HeaderCreator::setSegmentationControl(cfdp::SegmentationControl segmentationControl) { + this->segmentationCtrl = segmentationControl; +} + +void HeaderCreator::getTransactionSeqNum(cfdp::TransactionSeqNum &seqNum) const { + seqNum = pduConf.seqNum; +} + +bool HeaderCreator::hasSegmentMetadataFlag() const { + if (this->segmentMetadataFlag == cfdp::SegmentMetadataFlag::PRESENT) { + return true; + } + return false; +} diff --git a/src/fsfw/cfdp/pdu/HeaderSerializer.h b/src/fsfw/cfdp/pdu/HeaderCreator.h similarity index 96% rename from src/fsfw/cfdp/pdu/HeaderSerializer.h rename to src/fsfw/cfdp/pdu/HeaderCreator.h index 1de97d63..a9f9b581 100644 --- a/src/fsfw/cfdp/pdu/HeaderSerializer.h +++ b/src/fsfw/cfdp/pdu/HeaderCreator.h @@ -6,9 +6,9 @@ #include "PduHeaderIF.h" #include "fsfw/serialize/SerializeIF.h" -class HeaderSerializer : public SerializeIF, public PduHeaderIF { +class HeaderCreator : public SerializeIF, public PduHeaderIF { public: - HeaderSerializer( + HeaderCreator( PduConfig& pduConf, cfdp::PduType pduType, size_t initPduDataFieldLen, cfdp::SegmentMetadataFlag segmentMetadataFlag = cfdp::SegmentMetadataFlag::NOT_PRESENT, cfdp::SegmentationControl segCtrl = diff --git a/src/fsfw/cfdp/pdu/HeaderDeserializer.cpp b/src/fsfw/cfdp/pdu/HeaderReader.cpp similarity index 63% rename from src/fsfw/cfdp/pdu/HeaderDeserializer.cpp rename to src/fsfw/cfdp/pdu/HeaderReader.cpp index 70f397f8..7aec3f49 100644 --- a/src/fsfw/cfdp/pdu/HeaderDeserializer.cpp +++ b/src/fsfw/cfdp/pdu/HeaderReader.cpp @@ -1,20 +1,20 @@ -#include "HeaderDeserializer.h" +#include "HeaderReader.h" #include #include -HeaderDeserializer::HeaderDeserializer(const uint8_t *pduBuf, size_t maxSize) +HeaderReader::HeaderReader(const uint8_t *pduBuf, size_t maxSize) : rawPtr(pduBuf), maxSize(maxSize) {} -ReturnValue_t HeaderDeserializer::parseData() { +ReturnValue_t HeaderReader::parseData() { if (maxSize < 7) { return SerializeIF::STREAM_TOO_SHORT; } return setData(const_cast(rawPtr), maxSize); } -ReturnValue_t HeaderDeserializer::setData(uint8_t *dataPtr, size_t maxSize, void *args) { +ReturnValue_t HeaderReader::setData(uint8_t *dataPtr, size_t maxSize_, void *args) { if (dataPtr == nullptr) { // Allowed for now this->fixedHeader = nullptr; @@ -26,76 +26,74 @@ ReturnValue_t HeaderDeserializer::setData(uint8_t *dataPtr, size_t maxSize, void cfdp::WidthInBytes widthSeqNum = getLenSeqNum(); seqNumRaw = static_cast(sourceIdRaw) + static_cast(widthEntityIds); destIdRaw = static_cast(seqNumRaw) + static_cast(widthSeqNum); - this->maxSize = maxSize; + maxSize = maxSize_; return HasReturnvaluesIF::RETURN_OK; } -size_t HeaderDeserializer::getHeaderSize() const { +size_t HeaderReader::getHeaderSize() const { if (fixedHeader != nullptr) { return getLenEntityIds() * 2 + getLenSeqNum() + 4; } return 0; } -size_t HeaderDeserializer::getPduDataFieldLen() const { +size_t HeaderReader::getPduDataFieldLen() const { uint16_t pduFiedlLen = (fixedHeader->pduDataFieldLenH << 8) | fixedHeader->pduDataFieldLenL; return pduFiedlLen; } -size_t HeaderDeserializer::getWholePduSize() const { - return getPduDataFieldLen() + getHeaderSize(); -} +size_t HeaderReader::getWholePduSize() const { return getPduDataFieldLen() + getHeaderSize(); } -cfdp::PduType HeaderDeserializer::getPduType() const { +cfdp::PduType HeaderReader::getPduType() const { return static_cast((fixedHeader->firstByte >> 4) & 0x01); } -cfdp::Direction HeaderDeserializer::getDirection() const { +cfdp::Direction HeaderReader::getDirection() const { return static_cast((fixedHeader->firstByte >> 3) & 0x01); } -cfdp::TransmissionModes HeaderDeserializer::getTransmissionMode() const { +cfdp::TransmissionModes HeaderReader::getTransmissionMode() const { return static_cast((fixedHeader->firstByte >> 2) & 0x01); } -bool HeaderDeserializer::getCrcFlag() const { return (fixedHeader->firstByte >> 1) & 0x01; } +bool HeaderReader::getCrcFlag() const { return (fixedHeader->firstByte >> 1) & 0x01; } -bool HeaderDeserializer::getLargeFileFlag() const { return fixedHeader->firstByte & 0x01; } +bool HeaderReader::getLargeFileFlag() const { return fixedHeader->firstByte & 0x01; } -cfdp::SegmentationControl HeaderDeserializer::getSegmentationControl() const { +cfdp::SegmentationControl HeaderReader::getSegmentationControl() const { return static_cast((fixedHeader->fourthByte >> 7) & 0x01); } -cfdp::WidthInBytes HeaderDeserializer::getLenEntityIds() const { +cfdp::WidthInBytes HeaderReader::getLenEntityIds() const { return static_cast((fixedHeader->fourthByte >> 4) & 0x07); } -cfdp::WidthInBytes HeaderDeserializer::getLenSeqNum() const { +cfdp::WidthInBytes HeaderReader::getLenSeqNum() const { return static_cast(fixedHeader->fourthByte & 0x07); } -cfdp::SegmentMetadataFlag HeaderDeserializer::getSegmentMetadataFlag() const { +cfdp::SegmentMetadataFlag HeaderReader::getSegmentMetadataFlag() const { return static_cast((fixedHeader->fourthByte >> 3) & 0x01); } -void HeaderDeserializer::getSourceId(cfdp::EntityId &sourceId) const { +void HeaderReader::getSourceId(cfdp::EntityId &sourceId) const { assignVarLenField(dynamic_cast(&sourceId), getLenEntityIds(), this->sourceIdRaw); } -void HeaderDeserializer::getDestId(cfdp::EntityId &destId) const { +void HeaderReader::getDestId(cfdp::EntityId &destId) const { assignVarLenField(dynamic_cast(&destId), getLenEntityIds(), this->destIdRaw); } -void HeaderDeserializer::getTransactionSeqNum(cfdp::TransactionSeqNum &seqNum) const { +void HeaderReader::getTransactionSeqNum(cfdp::TransactionSeqNum &seqNum) const { assignVarLenField(dynamic_cast(&seqNum), getLenSeqNum(), this->seqNumRaw); } -void HeaderDeserializer::assignVarLenField(cfdp::VarLenField *field, cfdp::WidthInBytes width, - void *sourcePtr) const { +void HeaderReader::assignVarLenField(cfdp::VarLenField *field, cfdp::WidthInBytes width, + void *sourcePtr) const { switch (width) { case (cfdp::WidthInBytes::ONE_BYTE): { - uint8_t *fieldTyped = static_cast(sourcePtr); + auto *fieldTyped = static_cast(sourcePtr); field->setValue(width, *fieldTyped); break; } @@ -118,11 +116,15 @@ void HeaderDeserializer::assignVarLenField(cfdp::VarLenField *field, cfdp::Width } } -size_t HeaderDeserializer::getMaxSize() const { return maxSize; } +size_t HeaderReader::getMaxSize() const { return maxSize; } -bool HeaderDeserializer::hasSegmentMetadataFlag() const { +bool HeaderReader::hasSegmentMetadataFlag() const { if (this->getSegmentMetadataFlag() == cfdp::SegmentMetadataFlag::PRESENT) { return true; } return false; } + +ReturnValue_t HeaderReader::setData(const uint8_t *dataPtr, size_t maxSize_) { + return setData(const_cast(dataPtr), maxSize_, nullptr); +} diff --git a/src/fsfw/cfdp/pdu/HeaderDeserializer.h b/src/fsfw/cfdp/pdu/HeaderReader.h similarity index 61% rename from src/fsfw/cfdp/pdu/HeaderDeserializer.h rename to src/fsfw/cfdp/pdu/HeaderReader.h index ed033697..997828b6 100644 --- a/src/fsfw/cfdp/pdu/HeaderDeserializer.h +++ b/src/fsfw/cfdp/pdu/HeaderReader.h @@ -23,7 +23,7 @@ struct PduHeaderFixedStruct { * This is a zero-copy implementation and #parseData needs to be called to ensure the data is * valid. */ -class HeaderDeserializer : public RedirectableDataPointerIF, public PduHeaderIF { +class HeaderReader : public RedirectableDataPointerIF, public PduHeaderIF { public: /** * Initialize a PDU header from raw data. This is a zero-copy implementation and #parseData @@ -31,7 +31,7 @@ class HeaderDeserializer : public RedirectableDataPointerIF, public PduHeaderIF * @param pduBuf * @param maxSize */ - HeaderDeserializer(const uint8_t* pduBuf, size_t maxSize); + HeaderReader(const uint8_t* pduBuf, size_t maxSize); /** * This needs to be called before accessing the PDU fields to avoid segmentation faults. @@ -41,21 +41,21 @@ class HeaderDeserializer : public RedirectableDataPointerIF, public PduHeaderIF * - SerializeIF::BUFFER_TOO_SHORT if buffer is shorter than expected */ virtual ReturnValue_t parseData(); - size_t getHeaderSize() const; + [[nodiscard]] size_t getHeaderSize() const; - size_t getPduDataFieldLen() const override; - size_t getWholePduSize() const override; + [[nodiscard]] size_t getPduDataFieldLen() const override; + [[nodiscard]] size_t getWholePduSize() const override; - cfdp::PduType getPduType() const override; - cfdp::Direction getDirection() const override; - cfdp::TransmissionModes getTransmissionMode() const override; - bool getCrcFlag() const override; - bool getLargeFileFlag() const override; - cfdp::SegmentationControl getSegmentationControl() const override; - cfdp::WidthInBytes getLenEntityIds() const override; - cfdp::WidthInBytes getLenSeqNum() const override; - cfdp::SegmentMetadataFlag getSegmentMetadataFlag() const override; - bool hasSegmentMetadataFlag() const override; + [[nodiscard]] cfdp::PduType getPduType() const override; + [[nodiscard]] cfdp::Direction getDirection() const override; + [[nodiscard]] cfdp::TransmissionModes getTransmissionMode() const override; + [[nodiscard]] bool getCrcFlag() const override; + [[nodiscard]] bool getLargeFileFlag() const override; + [[nodiscard]] cfdp::SegmentationControl getSegmentationControl() const override; + [[nodiscard]] cfdp::WidthInBytes getLenEntityIds() const override; + [[nodiscard]] cfdp::WidthInBytes getLenSeqNum() const override; + [[nodiscard]] cfdp::SegmentMetadataFlag getSegmentMetadataFlag() const override; + [[nodiscard]] bool hasSegmentMetadataFlag() const override; void getSourceId(cfdp::EntityId& sourceId) const override; void getDestId(cfdp::EntityId& destId) const override; @@ -63,6 +63,8 @@ class HeaderDeserializer : public RedirectableDataPointerIF, public PduHeaderIF ReturnValue_t deserResult = HasReturnvaluesIF::RETURN_OK; + [[nodiscard]] size_t getMaxSize() const; + /** * Can also be used to reset the pointer to a nullptr, but the getter functions will not * perform nullptr checks! @@ -71,9 +73,7 @@ class HeaderDeserializer : public RedirectableDataPointerIF, public PduHeaderIF * @param args * @return */ - ReturnValue_t setData(uint8_t* dataPtr, size_t maxSize, void* args = nullptr) override; - - size_t getMaxSize() const; + ReturnValue_t setData(const uint8_t* dataPtr, size_t maxSize); protected: PduHeaderFixedStruct* fixedHeader = nullptr; @@ -81,6 +81,15 @@ class HeaderDeserializer : public RedirectableDataPointerIF, public PduHeaderIF size_t maxSize = 0; private: + /** + * Can also be used to reset the pointer to a nullptr, but the getter functions will not + * perform nullptr checks! + * @param dataPtr + * @param maxSize + * @param args + * @return + */ + ReturnValue_t setData(uint8_t* dataPtr, size_t maxSize, void* args) override; void assignVarLenField(cfdp::VarLenField* field, cfdp::WidthInBytes width, void* sourcePtr) const; void* sourceIdRaw = nullptr; void* seqNumRaw = nullptr; diff --git a/src/fsfw/cfdp/pdu/HeaderSerializer.cpp b/src/fsfw/cfdp/pdu/HeaderSerializer.cpp deleted file mode 100644 index 041fb714..00000000 --- a/src/fsfw/cfdp/pdu/HeaderSerializer.cpp +++ /dev/null @@ -1,117 +0,0 @@ -#include "HeaderSerializer.h" - -#include "HeaderDeserializer.h" - -HeaderSerializer::HeaderSerializer(PduConfig &pduConf, cfdp::PduType pduType, - size_t initPduDataFieldLen, - cfdp::SegmentMetadataFlag segmentMetadataFlag, - cfdp::SegmentationControl segCtrl) - : pduType(pduType), - segmentMetadataFlag(segmentMetadataFlag), - segmentationCtrl(segCtrl), - pduDataFieldLen(initPduDataFieldLen), - pduConf(pduConf) {} - -ReturnValue_t HeaderSerializer::serialize(uint8_t **buffer, size_t *size, size_t maxSize, - Endianness streamEndianness) const { - if (buffer == nullptr or size == nullptr) { - return HasReturnvaluesIF::RETURN_FAILED; - } - if (maxSize < this->getSerializedSize()) { - return BUFFER_TOO_SHORT; - } - **buffer = cfdp::VERSION_BITS | this->pduType << 4 | pduConf.direction << 3 | pduConf.mode << 2 | - pduConf.crcFlag << 1 | pduConf.largeFile; - *buffer += 1; - **buffer = (pduDataFieldLen & 0xff00) >> 8; - *buffer += 1; - **buffer = pduDataFieldLen & 0x00ff; - *buffer += 1; - **buffer = segmentationCtrl << 7 | pduConf.sourceId.getWidth() << 4 | segmentMetadataFlag << 3 | - pduConf.seqNum.getWidth(); - *buffer += 1; - *size += 4; - ReturnValue_t result = pduConf.sourceId.serialize(buffer, size, maxSize, streamEndianness); - if (result != HasReturnvaluesIF::RETURN_OK) { - return result; - } - result = pduConf.seqNum.serialize(buffer, size, maxSize, streamEndianness); - if (result != HasReturnvaluesIF::RETURN_OK) { - return result; - } - result = pduConf.destId.serialize(buffer, size, maxSize, streamEndianness); - if (result != HasReturnvaluesIF::RETURN_OK) { - return result; - } - - return HasReturnvaluesIF::RETURN_OK; -} - -size_t HeaderSerializer::getSerializedSize() const { - size_t shit = pduConf.seqNum.getWidth() + pduConf.sourceId.getWidth() * 2 + 4; - return shit; -} - -ReturnValue_t HeaderSerializer::deSerialize(const uint8_t **buffer, size_t *size, - Endianness streamEndianness) { - // We could implement this, but I prefer dedicated classes - return HasReturnvaluesIF::RETURN_FAILED; -} - -size_t HeaderSerializer::getWholePduSize() const { - // Return size of header plus the PDU data field length - return pduDataFieldLen + HeaderSerializer::getSerializedSize(); -} - -size_t HeaderSerializer::getPduDataFieldLen() const { return pduDataFieldLen; } - -void HeaderSerializer::setPduDataFieldLen(size_t pduDataFieldLen) { - this->pduDataFieldLen = pduDataFieldLen; -} - -void HeaderSerializer::setPduType(cfdp::PduType pduType) { this->pduType = pduType; } - -void HeaderSerializer::setSegmentMetadataFlag(cfdp::SegmentMetadataFlag segmentMetadataFlag) { - this->segmentMetadataFlag = segmentMetadataFlag; -} - -cfdp::PduType HeaderSerializer::getPduType() const { return pduType; } - -cfdp::Direction HeaderSerializer::getDirection() const { return pduConf.direction; } - -cfdp::TransmissionModes HeaderSerializer::getTransmissionMode() const { return pduConf.mode; } - -bool HeaderSerializer::getCrcFlag() const { return pduConf.crcFlag; } - -bool HeaderSerializer::getLargeFileFlag() const { return pduConf.largeFile; } - -cfdp::SegmentationControl HeaderSerializer::getSegmentationControl() const { - return segmentationCtrl; -} - -cfdp::WidthInBytes HeaderSerializer::getLenEntityIds() const { return pduConf.sourceId.getWidth(); } - -cfdp::WidthInBytes HeaderSerializer::getLenSeqNum() const { return pduConf.seqNum.getWidth(); } - -cfdp::SegmentMetadataFlag HeaderSerializer::getSegmentMetadataFlag() const { - return segmentMetadataFlag; -} - -void HeaderSerializer::getSourceId(cfdp::EntityId &sourceId) const { sourceId = pduConf.sourceId; } - -void HeaderSerializer::getDestId(cfdp::EntityId &destId) const { destId = pduConf.destId; } - -void HeaderSerializer::setSegmentationControl(cfdp::SegmentationControl segmentationControl) { - this->segmentationCtrl = segmentationControl; -} - -void HeaderSerializer::getTransactionSeqNum(cfdp::TransactionSeqNum &seqNum) const { - seqNum = pduConf.seqNum; -} - -bool HeaderSerializer::hasSegmentMetadataFlag() const { - if (this->segmentMetadataFlag == cfdp::SegmentMetadataFlag::PRESENT) { - return true; - } - return false; -} diff --git a/src/fsfw/cfdp/pdu/PduHeaderIF.h b/src/fsfw/cfdp/pdu/PduHeaderIF.h index f05d95a4..86956ff0 100644 --- a/src/fsfw/cfdp/pdu/PduHeaderIF.h +++ b/src/fsfw/cfdp/pdu/PduHeaderIF.h @@ -13,20 +13,20 @@ */ class PduHeaderIF { public: - virtual ~PduHeaderIF(){}; + virtual ~PduHeaderIF() = default; - virtual size_t getWholePduSize() const = 0; - virtual size_t getPduDataFieldLen() const = 0; - virtual cfdp::PduType getPduType() const = 0; - virtual cfdp::Direction getDirection() const = 0; - virtual cfdp::TransmissionModes getTransmissionMode() const = 0; - virtual bool getCrcFlag() const = 0; - virtual bool getLargeFileFlag() const = 0; - virtual cfdp::SegmentationControl getSegmentationControl() const = 0; - virtual cfdp::WidthInBytes getLenEntityIds() const = 0; - virtual cfdp::WidthInBytes getLenSeqNum() const = 0; - virtual cfdp::SegmentMetadataFlag getSegmentMetadataFlag() const = 0; - virtual bool hasSegmentMetadataFlag() const = 0; + [[nodiscard]] virtual size_t getWholePduSize() const = 0; + [[nodiscard]] virtual size_t getPduDataFieldLen() const = 0; + [[nodiscard]] virtual cfdp::PduType getPduType() const = 0; + [[nodiscard]] virtual cfdp::Direction getDirection() const = 0; + [[nodiscard]] virtual cfdp::TransmissionModes getTransmissionMode() const = 0; + [[nodiscard]] virtual bool getCrcFlag() const = 0; + [[nodiscard]] virtual bool getLargeFileFlag() const = 0; + [[nodiscard]] virtual cfdp::SegmentationControl getSegmentationControl() const = 0; + [[nodiscard]] virtual cfdp::WidthInBytes getLenEntityIds() const = 0; + [[nodiscard]] virtual cfdp::WidthInBytes getLenSeqNum() const = 0; + [[nodiscard]] virtual cfdp::SegmentMetadataFlag getSegmentMetadataFlag() const = 0; + [[nodiscard]] virtual bool hasSegmentMetadataFlag() const = 0; virtual void getSourceId(cfdp::EntityId& sourceId) const = 0; virtual void getDestId(cfdp::EntityId& destId) const = 0; virtual void getTransactionSeqNum(cfdp::TransactionSeqNum& seqNum) const = 0; diff --git a/src/fsfw/cfdp/pdu/PromptPduDeserializer.h b/src/fsfw/cfdp/pdu/PromptPduDeserializer.h index 9441f364..2f75033b 100644 --- a/src/fsfw/cfdp/pdu/PromptPduDeserializer.h +++ b/src/fsfw/cfdp/pdu/PromptPduDeserializer.h @@ -7,7 +7,7 @@ class PromptPduDeserializer : public FileDirectiveDeserializer { public: PromptPduDeserializer(const uint8_t *pduBuf, size_t maxSize); - cfdp::PromptResponseRequired getPromptResponseRequired() const; + [[nodiscard]] cfdp::PromptResponseRequired getPromptResponseRequired() const; ReturnValue_t parseData() override; private: diff --git a/unittests/cfdp/testCfdpHeader.cpp b/unittests/cfdp/testCfdpHeader.cpp index 3e9cfccd..6453b809 100644 --- a/unittests/cfdp/testCfdpHeader.cpp +++ b/unittests/cfdp/testCfdpHeader.cpp @@ -1,8 +1,8 @@ #include #include -#include "fsfw/cfdp/pdu/HeaderDeserializer.h" -#include "fsfw/cfdp/pdu/HeaderSerializer.h" +#include "fsfw/cfdp/pdu/HeaderCreator.h" +#include "fsfw/cfdp/pdu/HeaderReader.h" #include "fsfw/returnvalues/HasReturnvaluesIF.h" TEST_CASE("CFDP Header", "[cfdp]") { @@ -19,7 +19,7 @@ TEST_CASE("CFDP Header", "[cfdp]") { size_t serSize = 0; SECTION("Header Serialization") { - auto headerSerializer = HeaderSerializer(pduConf, cfdp::PduType::FILE_DIRECTIVE, 0); + auto headerSerializer = HeaderCreator(pduConf, cfdp::PduType::FILE_DIRECTIVE, 0); const uint8_t** dummyPtr = nullptr; ReturnValue_t deserResult = headerSerializer.deSerialize(dummyPtr, &serSize, SerializeIF::Endianness::NETWORK); @@ -186,7 +186,7 @@ TEST_CASE("CFDP Header", "[cfdp]") { SECTION("Header Deserialization") { // We unittested the serializer before, so we can use it now to generate valid raw CFDP // data - auto headerSerializer = HeaderSerializer(pduConf, cfdp::PduType::FILE_DIRECTIVE, 0); + auto headerSerializer = HeaderCreator(pduConf, cfdp::PduType::FILE_DIRECTIVE, 0); result = headerSerializer.serialize(&serTarget, &serSize, serBuf.size(), SerializeIF::Endianness::BIG); REQUIRE(result == result::OK); @@ -196,7 +196,7 @@ TEST_CASE("CFDP Header", "[cfdp]") { REQUIRE(serBuf[3] == 0b00010001); REQUIRE(serSize == 7); // Deser call not strictly necessary - auto headerDeser = HeaderDeserializer(serBuf.data(), serBuf.size()); + auto headerDeser = HeaderReader(serBuf.data(), serBuf.size()); ReturnValue_t serResult = headerDeser.parseData(); REQUIRE(serResult == result::OK); @@ -231,7 +231,7 @@ TEST_CASE("CFDP Header", "[cfdp]") { serSize = 0; result = headerSerializer.serialize(&serTarget, &serSize, serBuf.size(), SerializeIF::Endianness::BIG); - headerDeser = HeaderDeserializer(serBuf.data(), serBuf.size()); + headerDeser = HeaderReader(serBuf.data(), serBuf.size()); result = headerDeser.parseData(); REQUIRE(result == result::OK); From acf5c2a56de9f0754ee974267351b3104ea6904b Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Wed, 3 Aug 2022 16:00:48 +0200 Subject: [PATCH 017/169] better names --- src/fsfw/cfdp/pdu/AckPduDeserializer.cpp | 6 ++--- src/fsfw/cfdp/pdu/AckPduDeserializer.h | 4 ++-- src/fsfw/cfdp/pdu/AckPduSerializer.cpp | 7 +++--- src/fsfw/cfdp/pdu/AckPduSerializer.h | 6 ++--- src/fsfw/cfdp/pdu/CMakeLists.txt | 8 +++---- src/fsfw/cfdp/pdu/EofPduDeserializer.cpp | 6 ++--- src/fsfw/cfdp/pdu/EofPduDeserializer.h | 4 ++-- src/fsfw/cfdp/pdu/EofPduSerializer.cpp | 7 +++--- src/fsfw/cfdp/pdu/EofPduSerializer.h | 4 ++-- ...DataSerializer.cpp => FileDataCreator.cpp} | 12 +++++----- src/fsfw/cfdp/pdu/FileDataCreator.h | 23 ++++++++++++++++++ ...ataDeserializer.cpp => FileDataReader.cpp} | 13 +++++----- ...ileDataDeserializer.h => FileDataReader.h} | 8 +++---- src/fsfw/cfdp/pdu/FileDataSerializer.h | 23 ------------------ ...erializer.cpp => FileDirectiveCreator.cpp} | 17 +++++++------ ...iveSerializer.h => FileDirectiveCreator.h} | 10 ++++---- ...serializer.cpp => FileDirectiveReader.cpp} | 24 +++++++++---------- ...veDeserializer.h => FileDirectiveReader.h} | 14 +++++------ src/fsfw/cfdp/pdu/FinishedPduDeserializer.cpp | 10 ++++---- src/fsfw/cfdp/pdu/FinishedPduDeserializer.h | 4 ++-- src/fsfw/cfdp/pdu/FinishedPduSerializer.cpp | 5 ++-- src/fsfw/cfdp/pdu/FinishedPduSerializer.h | 6 ++--- src/fsfw/cfdp/pdu/HeaderCreator.cpp | 3 +-- src/fsfw/cfdp/pdu/HeaderReader.cpp | 7 +++--- src/fsfw/cfdp/pdu/HeaderReader.h | 2 +- .../cfdp/pdu/KeepAlivePduDeserializer.cpp | 8 +++---- src/fsfw/cfdp/pdu/KeepAlivePduDeserializer.h | 4 ++-- src/fsfw/cfdp/pdu/KeepAlivePduSerializer.cpp | 7 +++--- src/fsfw/cfdp/pdu/KeepAlivePduSerializer.h | 4 ++-- src/fsfw/cfdp/pdu/MetadataPduDeserializer.cpp | 8 +++---- src/fsfw/cfdp/pdu/MetadataPduDeserializer.h | 4 ++-- src/fsfw/cfdp/pdu/MetadataPduSerializer.cpp | 7 +++--- src/fsfw/cfdp/pdu/MetadataPduSerializer.h | 4 ++-- src/fsfw/cfdp/pdu/NakInfo.cpp | 2 +- src/fsfw/cfdp/pdu/NakPduDeserializer.cpp | 8 +++---- src/fsfw/cfdp/pdu/NakPduDeserializer.h | 4 ++-- src/fsfw/cfdp/pdu/NakPduSerializer.cpp | 7 +++--- src/fsfw/cfdp/pdu/NakPduSerializer.h | 4 ++-- src/fsfw/cfdp/pdu/PromptPduDeserializer.cpp | 10 ++++---- src/fsfw/cfdp/pdu/PromptPduDeserializer.h | 4 ++-- src/fsfw/cfdp/pdu/PromptPduSerializer.cpp | 9 ++++--- src/fsfw/cfdp/pdu/PromptPduSerializer.h | 6 ++--- unittests/cfdp/testCfdp.cpp | 8 +++---- unittests/cfdp/testFileData.cpp | 10 ++++---- unittests/cfdp/testFileDirective.cpp | 8 +++---- unittests/cfdp/testNakPdu.cpp | 2 +- unittests/cfdp/testPromptPdu.cpp | 2 ++ 47 files changed, 178 insertions(+), 185 deletions(-) rename src/fsfw/cfdp/pdu/{FileDataSerializer.cpp => FileDataCreator.cpp} (81%) create mode 100644 src/fsfw/cfdp/pdu/FileDataCreator.h rename src/fsfw/cfdp/pdu/{FileDataDeserializer.cpp => FileDataReader.cpp} (73%) rename src/fsfw/cfdp/pdu/{FileDataDeserializer.h => FileDataReader.h} (67%) delete mode 100644 src/fsfw/cfdp/pdu/FileDataSerializer.h rename src/fsfw/cfdp/pdu/{FileDirectiveSerializer.cpp => FileDirectiveCreator.cpp} (53%) rename src/fsfw/cfdp/pdu/{FileDirectiveSerializer.h => FileDirectiveCreator.h} (66%) rename src/fsfw/cfdp/pdu/{FileDirectiveDeserializer.cpp => FileDirectiveReader.cpp} (53%) rename src/fsfw/cfdp/pdu/{FileDirectiveDeserializer.h => FileDirectiveReader.h} (71%) diff --git a/src/fsfw/cfdp/pdu/AckPduDeserializer.cpp b/src/fsfw/cfdp/pdu/AckPduDeserializer.cpp index f5babf4b..1217344e 100644 --- a/src/fsfw/cfdp/pdu/AckPduDeserializer.cpp +++ b/src/fsfw/cfdp/pdu/AckPduDeserializer.cpp @@ -1,14 +1,14 @@ #include "AckPduDeserializer.h" AckPduDeserializer::AckPduDeserializer(const uint8_t* pduBuf, size_t maxSize, AckInfo& info) - : FileDirectiveDeserializer(pduBuf, maxSize), info(info) {} + : FileDirectiveReader(pduBuf, maxSize), info(info) {} ReturnValue_t AckPduDeserializer::parseData() { - ReturnValue_t result = FileDirectiveDeserializer::parseData(); + ReturnValue_t result = FileDirectiveReader::parseData(); if (result != HasReturnvaluesIF::RETURN_OK) { return result; } - size_t currentIdx = FileDirectiveDeserializer::getHeaderSize(); + size_t currentIdx = FileDirectiveReader::getHeaderSize(); if (currentIdx + 2 > this->maxSize) { return SerializeIF::BUFFER_TOO_SHORT; } diff --git a/src/fsfw/cfdp/pdu/AckPduDeserializer.h b/src/fsfw/cfdp/pdu/AckPduDeserializer.h index 0bb95071..4da50261 100644 --- a/src/fsfw/cfdp/pdu/AckPduDeserializer.h +++ b/src/fsfw/cfdp/pdu/AckPduDeserializer.h @@ -2,9 +2,9 @@ #define FSFW_SRC_FSFW_CFDP_PDU_ACKPDUDESERIALIZER_H_ #include "AckInfo.h" -#include "fsfw/cfdp/pdu/FileDirectiveDeserializer.h" +#include "fsfw/cfdp/pdu/FileDirectiveReader.h" -class AckPduDeserializer : public FileDirectiveDeserializer { +class AckPduDeserializer : public FileDirectiveReader { public: AckPduDeserializer(const uint8_t* pduBuf, size_t maxSize, AckInfo& info); diff --git a/src/fsfw/cfdp/pdu/AckPduSerializer.cpp b/src/fsfw/cfdp/pdu/AckPduSerializer.cpp index d19418f1..5405f96c 100644 --- a/src/fsfw/cfdp/pdu/AckPduSerializer.cpp +++ b/src/fsfw/cfdp/pdu/AckPduSerializer.cpp @@ -1,16 +1,15 @@ #include "AckPduSerializer.h" AckPduSerializer::AckPduSerializer(AckInfo &ackInfo, PduConfig &pduConf) - : FileDirectiveSerializer(pduConf, cfdp::FileDirectives::ACK, 2), ackInfo(ackInfo) {} + : FileDirectiveCreator(pduConf, cfdp::FileDirectives::ACK, 2), ackInfo(ackInfo) {} size_t AckPduSerializer::getSerializedSize() const { - return FileDirectiveSerializer::getWholePduSize(); + return FileDirectiveCreator::getWholePduSize(); } ReturnValue_t AckPduSerializer::serialize(uint8_t **buffer, size_t *size, size_t maxSize, Endianness streamEndianness) const { - ReturnValue_t result = - FileDirectiveSerializer::serialize(buffer, size, maxSize, streamEndianness); + ReturnValue_t result = FileDirectiveCreator::serialize(buffer, size, maxSize, streamEndianness); if (result != HasReturnvaluesIF::RETURN_OK) { return result; } diff --git a/src/fsfw/cfdp/pdu/AckPduSerializer.h b/src/fsfw/cfdp/pdu/AckPduSerializer.h index 68a049e2..92014e4e 100644 --- a/src/fsfw/cfdp/pdu/AckPduSerializer.h +++ b/src/fsfw/cfdp/pdu/AckPduSerializer.h @@ -2,10 +2,10 @@ #define FSFW_SRC_FSFW_CFDP_PDU_ACKPDUSERIALIZER_H_ #include "AckInfo.h" -#include "FileDirectiveDeserializer.h" -#include "FileDirectiveSerializer.h" +#include "FileDirectiveCreator.h" +#include "FileDirectiveReader.h" -class AckPduSerializer : public FileDirectiveSerializer { +class AckPduSerializer : public FileDirectiveCreator { public: /** * @brief Serializer to pack ACK PDUs diff --git a/src/fsfw/cfdp/pdu/CMakeLists.txt b/src/fsfw/cfdp/pdu/CMakeLists.txt index 0d49217b..21fe0820 100644 --- a/src/fsfw/cfdp/pdu/CMakeLists.txt +++ b/src/fsfw/cfdp/pdu/CMakeLists.txt @@ -4,8 +4,8 @@ target_sources( VarLenField.cpp HeaderCreator.cpp HeaderReader.cpp - FileDirectiveDeserializer.cpp - FileDirectiveSerializer.cpp + FileDirectiveReader.cpp + FileDirectiveCreator.cpp AckInfo.cpp AckPduSerializer.cpp AckPduDeserializer.cpp @@ -25,6 +25,6 @@ target_sources( KeepAlivePduDeserializer.cpp PromptPduSerializer.cpp PromptPduDeserializer.cpp - FileDataSerializer.cpp - FileDataDeserializer.cpp + FileDataCreator.cpp + FileDataReader.cpp FileDataInfo.cpp) diff --git a/src/fsfw/cfdp/pdu/EofPduDeserializer.cpp b/src/fsfw/cfdp/pdu/EofPduDeserializer.cpp index e1ab8dc9..e532419f 100644 --- a/src/fsfw/cfdp/pdu/EofPduDeserializer.cpp +++ b/src/fsfw/cfdp/pdu/EofPduDeserializer.cpp @@ -4,10 +4,10 @@ #include "fsfw/serviceinterface.h" EofPduDeserializer::EofPduDeserializer(const uint8_t* pduBuf, size_t maxSize, EofInfo& eofInfo) - : FileDirectiveDeserializer(pduBuf, maxSize), info(eofInfo) {} + : FileDirectiveReader(pduBuf, maxSize), info(eofInfo) {} ReturnValue_t EofPduDeserializer::parseData() { - ReturnValue_t result = FileDirectiveDeserializer::parseData(); + ReturnValue_t result = FileDirectiveReader::parseData(); if (result != HasReturnvaluesIF::RETURN_OK) { return result; } @@ -17,7 +17,7 @@ ReturnValue_t EofPduDeserializer::parseData() { if (this->getLargeFileFlag()) { expectedFileFieldLen = 8; } - size_t currentIdx = FileDirectiveDeserializer::getHeaderSize(); + size_t currentIdx = FileDirectiveReader::getHeaderSize(); size_t deserLen = maxSize; if (maxSize < currentIdx + 5 + expectedFileFieldLen) { return SerializeIF::STREAM_TOO_SHORT; diff --git a/src/fsfw/cfdp/pdu/EofPduDeserializer.h b/src/fsfw/cfdp/pdu/EofPduDeserializer.h index 8f62b25a..ce918475 100644 --- a/src/fsfw/cfdp/pdu/EofPduDeserializer.h +++ b/src/fsfw/cfdp/pdu/EofPduDeserializer.h @@ -2,9 +2,9 @@ #define FSFW_SRC_FSFW_CFDP_PDU_EOFPDUDESERIALIZER_H_ #include "EofInfo.h" -#include "fsfw/cfdp/pdu/FileDirectiveDeserializer.h" +#include "fsfw/cfdp/pdu/FileDirectiveReader.h" -class EofPduDeserializer : public FileDirectiveDeserializer { +class EofPduDeserializer : public FileDirectiveReader { public: EofPduDeserializer(const uint8_t* pduBuf, size_t maxSize, EofInfo& eofInfo); diff --git a/src/fsfw/cfdp/pdu/EofPduSerializer.cpp b/src/fsfw/cfdp/pdu/EofPduSerializer.cpp index e9fe0ca0..f6dc343c 100644 --- a/src/fsfw/cfdp/pdu/EofPduSerializer.cpp +++ b/src/fsfw/cfdp/pdu/EofPduSerializer.cpp @@ -4,18 +4,17 @@ #include "fsfw/serviceinterface.h" EofPduSerializer::EofPduSerializer(PduConfig &conf, EofInfo &info) - : FileDirectiveSerializer(conf, cfdp::FileDirectives::EOF_DIRECTIVE, 9), info(info) { + : FileDirectiveCreator(conf, cfdp::FileDirectives::EOF_DIRECTIVE, 9), info(info) { setDirectiveDataFieldLen(info.getSerializedSize(getLargeFileFlag())); } size_t EofPduSerializer::getSerializedSize() const { - return FileDirectiveSerializer::getWholePduSize(); + return FileDirectiveCreator::getWholePduSize(); } ReturnValue_t EofPduSerializer::serialize(uint8_t **buffer, size_t *size, size_t maxSize, Endianness streamEndianness) const { - ReturnValue_t result = - FileDirectiveSerializer::serialize(buffer, size, maxSize, streamEndianness); + ReturnValue_t result = FileDirectiveCreator::serialize(buffer, size, maxSize, streamEndianness); if (result != HasReturnvaluesIF::RETURN_OK) { return result; } diff --git a/src/fsfw/cfdp/pdu/EofPduSerializer.h b/src/fsfw/cfdp/pdu/EofPduSerializer.h index fbdcfe67..737e8dee 100644 --- a/src/fsfw/cfdp/pdu/EofPduSerializer.h +++ b/src/fsfw/cfdp/pdu/EofPduSerializer.h @@ -2,10 +2,10 @@ #define FSFW_SRC_FSFW_CFDP_PDU_EOFPDUSERIALIZER_H_ #include "EofInfo.h" -#include "fsfw/cfdp/pdu/FileDirectiveSerializer.h" +#include "fsfw/cfdp/pdu/FileDirectiveCreator.h" #include "fsfw/cfdp/tlv/EntityIdTlv.h" -class EofPduSerializer : public FileDirectiveSerializer { +class EofPduSerializer : public FileDirectiveCreator { public: EofPduSerializer(PduConfig& conf, EofInfo& info); diff --git a/src/fsfw/cfdp/pdu/FileDataSerializer.cpp b/src/fsfw/cfdp/pdu/FileDataCreator.cpp similarity index 81% rename from src/fsfw/cfdp/pdu/FileDataSerializer.cpp rename to src/fsfw/cfdp/pdu/FileDataCreator.cpp index 2e86a255..39d3838a 100644 --- a/src/fsfw/cfdp/pdu/FileDataSerializer.cpp +++ b/src/fsfw/cfdp/pdu/FileDataCreator.cpp @@ -1,20 +1,20 @@ -#include "FileDataSerializer.h" +#include "FileDataCreator.h" #include -FileDataSerializer::FileDataSerializer(PduConfig& conf, FileDataInfo& info) +FileDataCreator::FileDataCreator(PduConfig& conf, FileDataInfo& info) : HeaderCreator(conf, cfdp::PduType::FILE_DATA, 0, info.getSegmentMetadataFlag()), info(info) { update(); } -void FileDataSerializer::update() { +void FileDataCreator::update() { this->setSegmentMetadataFlag(info.getSegmentMetadataFlag()); this->setSegmentationControl(info.getSegmentationControl()); setPduDataFieldLen(info.getSerializedSize(this->getLargeFileFlag())); } -ReturnValue_t FileDataSerializer::serialize(uint8_t** buffer, size_t* size, size_t maxSize, - Endianness streamEndianness) const { +ReturnValue_t FileDataCreator::serialize(uint8_t** buffer, size_t* size, size_t maxSize, + Endianness streamEndianness) const { ReturnValue_t result = HeaderCreator::serialize(buffer, size, maxSize, streamEndianness); if (result != HasReturnvaluesIF::RETURN_OK) { return result; @@ -49,6 +49,6 @@ ReturnValue_t FileDataSerializer::serialize(uint8_t** buffer, size_t* size, size return HasReturnvaluesIF::RETURN_OK; } -size_t FileDataSerializer::getSerializedSize() const { +size_t FileDataCreator::getSerializedSize() const { return HeaderCreator::getSerializedSize() + info.getSerializedSize(this->getLargeFileFlag()); } diff --git a/src/fsfw/cfdp/pdu/FileDataCreator.h b/src/fsfw/cfdp/pdu/FileDataCreator.h new file mode 100644 index 00000000..774baf00 --- /dev/null +++ b/src/fsfw/cfdp/pdu/FileDataCreator.h @@ -0,0 +1,23 @@ +#ifndef FSFW_CFDP_PDU_FILEDATASERIALIZER_H_ +#define FSFW_CFDP_PDU_FILEDATASERIALIZER_H_ + +#include "../definitions.h" +#include "FileDataInfo.h" +#include "HeaderCreator.h" + +class FileDataCreator : public HeaderCreator { + public: + FileDataCreator(PduConfig& conf, FileDataInfo& info); + + void update(); + + ReturnValue_t serialize(uint8_t** buffer, size_t* size, size_t maxSize, + Endianness streamEndianness) const override; + + [[nodiscard]] size_t getSerializedSize() const override; + + private: + FileDataInfo& info; +}; + +#endif /* FSFW_CFDP_PDU_FILEDATASERIALIZER_H_ */ diff --git a/src/fsfw/cfdp/pdu/FileDataDeserializer.cpp b/src/fsfw/cfdp/pdu/FileDataReader.cpp similarity index 73% rename from src/fsfw/cfdp/pdu/FileDataDeserializer.cpp rename to src/fsfw/cfdp/pdu/FileDataReader.cpp index 2b3171a8..30581da4 100644 --- a/src/fsfw/cfdp/pdu/FileDataDeserializer.cpp +++ b/src/fsfw/cfdp/pdu/FileDataReader.cpp @@ -1,10 +1,9 @@ -#include "FileDataDeserializer.h" +#include "FileDataReader.h" -FileDataDeserializer::FileDataDeserializer(const uint8_t* pduBuf, size_t maxSize, - FileDataInfo& info) +FileDataReader::FileDataReader(const uint8_t* pduBuf, size_t maxSize, FileDataInfo& info) : HeaderReader(pduBuf, maxSize), info(info) {} -ReturnValue_t FileDataDeserializer::parseData() { +ReturnValue_t FileDataReader::parseData() { ReturnValue_t result = HeaderReader::parseData(); if (result != HasReturnvaluesIF::RETURN_OK) { return result; @@ -41,8 +40,8 @@ ReturnValue_t FileDataDeserializer::parseData() { return HasReturnvaluesIF::RETURN_OK; } -SerializeIF::Endianness FileDataDeserializer::getEndianness() const { return endianness; } +SerializeIF::Endianness FileDataReader::getEndianness() const { return endianness; } -void FileDataDeserializer::setEndianness(SerializeIF::Endianness endianness) { - this->endianness = endianness; +void FileDataReader::setEndianness(SerializeIF::Endianness endianness_) { + endianness = endianness_; } diff --git a/src/fsfw/cfdp/pdu/FileDataDeserializer.h b/src/fsfw/cfdp/pdu/FileDataReader.h similarity index 67% rename from src/fsfw/cfdp/pdu/FileDataDeserializer.h rename to src/fsfw/cfdp/pdu/FileDataReader.h index f6723fec..62e0f89b 100644 --- a/src/fsfw/cfdp/pdu/FileDataDeserializer.h +++ b/src/fsfw/cfdp/pdu/FileDataReader.h @@ -5,12 +5,12 @@ #include "FileDataInfo.h" #include "HeaderReader.h" -class FileDataDeserializer : public HeaderReader { +class FileDataReader : public HeaderReader { public: - FileDataDeserializer(const uint8_t* pduBuf, size_t maxSize, FileDataInfo& info); + FileDataReader(const uint8_t* pduBuf, size_t maxSize, FileDataInfo& info); - ReturnValue_t parseData(); - SerializeIF::Endianness getEndianness() const; + ReturnValue_t parseData() override; + [[nodiscard]] SerializeIF::Endianness getEndianness() const; void setEndianness(SerializeIF::Endianness endianness = SerializeIF::Endianness::NETWORK); private: diff --git a/src/fsfw/cfdp/pdu/FileDataSerializer.h b/src/fsfw/cfdp/pdu/FileDataSerializer.h deleted file mode 100644 index 17d72e2e..00000000 --- a/src/fsfw/cfdp/pdu/FileDataSerializer.h +++ /dev/null @@ -1,23 +0,0 @@ -#ifndef FSFW_SRC_FSFW_CFDP_PDU_FILEDATASERIALIZER_H_ -#define FSFW_SRC_FSFW_CFDP_PDU_FILEDATASERIALIZER_H_ - -#include "../definitions.h" -#include "FileDataInfo.h" -#include "HeaderCreator.h" - -class FileDataSerializer : public HeaderCreator { - public: - FileDataSerializer(PduConfig& conf, FileDataInfo& info); - - void update(); - - ReturnValue_t serialize(uint8_t** buffer, size_t* size, size_t maxSize, - Endianness streamEndianness) const override; - - size_t getSerializedSize() const override; - - private: - FileDataInfo& info; -}; - -#endif /* FSFW_SRC_FSFW_CFDP_PDU_FILEDATADESERIALIZER_H_ */ diff --git a/src/fsfw/cfdp/pdu/FileDirectiveSerializer.cpp b/src/fsfw/cfdp/pdu/FileDirectiveCreator.cpp similarity index 53% rename from src/fsfw/cfdp/pdu/FileDirectiveSerializer.cpp rename to src/fsfw/cfdp/pdu/FileDirectiveCreator.cpp index e70b8b83..169c2d5f 100644 --- a/src/fsfw/cfdp/pdu/FileDirectiveSerializer.cpp +++ b/src/fsfw/cfdp/pdu/FileDirectiveCreator.cpp @@ -1,21 +1,20 @@ -#include "FileDirectiveSerializer.h" +#include "FileDirectiveCreator.h" -FileDirectiveSerializer::FileDirectiveSerializer(PduConfig &pduConf, - cfdp::FileDirectives directiveCode, - size_t directiveParamFieldLen) +FileDirectiveCreator::FileDirectiveCreator(PduConfig &pduConf, cfdp::FileDirectives directiveCode, + size_t directiveParamFieldLen) : HeaderCreator(pduConf, cfdp::PduType::FILE_DIRECTIVE, directiveParamFieldLen + 1), directiveCode(directiveCode) {} -size_t FileDirectiveSerializer::getSerializedSize() const { +size_t FileDirectiveCreator::getSerializedSize() const { return HeaderCreator::getSerializedSize() + 1; } -ReturnValue_t FileDirectiveSerializer::serialize(uint8_t **buffer, size_t *size, size_t maxSize, - Endianness streamEndianness) const { +ReturnValue_t FileDirectiveCreator::serialize(uint8_t **buffer, size_t *size, size_t maxSize, + Endianness streamEndianness) const { if (buffer == nullptr or size == nullptr) { return HasReturnvaluesIF::RETURN_FAILED; } - if (FileDirectiveSerializer::getWholePduSize() > maxSize) { + if (FileDirectiveCreator::getWholePduSize() > maxSize) { return BUFFER_TOO_SHORT; } ReturnValue_t result = HeaderCreator::serialize(buffer, size, maxSize, streamEndianness); @@ -32,7 +31,7 @@ ReturnValue_t FileDirectiveSerializer::serialize(uint8_t **buffer, size_t *size, return HasReturnvaluesIF::RETURN_OK; } -void FileDirectiveSerializer::setDirectiveDataFieldLen(size_t len) { +void FileDirectiveCreator::setDirectiveDataFieldLen(size_t len) { // Set length of data field plus 1 byte for the directive octet HeaderCreator::setPduDataFieldLen(len + 1); } diff --git a/src/fsfw/cfdp/pdu/FileDirectiveSerializer.h b/src/fsfw/cfdp/pdu/FileDirectiveCreator.h similarity index 66% rename from src/fsfw/cfdp/pdu/FileDirectiveSerializer.h rename to src/fsfw/cfdp/pdu/FileDirectiveCreator.h index ffe34412..566ae3cc 100644 --- a/src/fsfw/cfdp/pdu/FileDirectiveSerializer.h +++ b/src/fsfw/cfdp/pdu/FileDirectiveCreator.h @@ -3,18 +3,18 @@ #include "fsfw/cfdp/pdu/HeaderCreator.h" -class FileDirectiveSerializer : public HeaderCreator { +class FileDirectiveCreator : public HeaderCreator { public: - FileDirectiveSerializer(PduConfig& pduConf, cfdp::FileDirectives directiveCode, - size_t directiveParamFieldLen); + FileDirectiveCreator(PduConfig& pduConf, cfdp::FileDirectives directiveCode, + size_t directiveParamFieldLen); /** * This only returns the size of the PDU header + 1 for the directive code octet. - * Use FileDirectiveSerializer::getWholePduSize to get the full packet length, assuming + * Use FileDirectiveCreator::getWholePduSize to get the full packet length, assuming * the length fields was set correctly * @return */ - size_t getSerializedSize() const override; + [[nodiscard]] size_t getSerializedSize() const override; ReturnValue_t serialize(uint8_t** buffer, size_t* size, size_t maxSize, Endianness streamEndianness) const override; diff --git a/src/fsfw/cfdp/pdu/FileDirectiveDeserializer.cpp b/src/fsfw/cfdp/pdu/FileDirectiveReader.cpp similarity index 53% rename from src/fsfw/cfdp/pdu/FileDirectiveDeserializer.cpp rename to src/fsfw/cfdp/pdu/FileDirectiveReader.cpp index 162312d3..d51846b8 100644 --- a/src/fsfw/cfdp/pdu/FileDirectiveDeserializer.cpp +++ b/src/fsfw/cfdp/pdu/FileDirectiveReader.cpp @@ -1,11 +1,11 @@ -#include "FileDirectiveDeserializer.h" +#include "FileDirectiveReader.h" -FileDirectiveDeserializer::FileDirectiveDeserializer(const uint8_t *pduBuf, size_t maxSize) +FileDirectiveReader::FileDirectiveReader(const uint8_t *pduBuf, size_t maxSize) : HeaderReader(pduBuf, maxSize) {} -cfdp::FileDirectives FileDirectiveDeserializer::getFileDirective() const { return fileDirective; } +cfdp::FileDirectives FileDirectiveReader::getFileDirective() const { return fileDirective; } -ReturnValue_t FileDirectiveDeserializer::parseData() { +ReturnValue_t FileDirectiveReader::parseData() { ReturnValue_t result = HeaderReader::parseData(); if (result != HasReturnvaluesIF::RETURN_OK) { return result; @@ -13,7 +13,7 @@ ReturnValue_t FileDirectiveDeserializer::parseData() { if (this->getPduDataFieldLen() < 1) { return cfdp::INVALID_PDU_DATAFIELD_LEN; } - if (FileDirectiveDeserializer::getWholePduSize() > maxSize) { + if (FileDirectiveReader::getWholePduSize() > maxSize) { return SerializeIF::STREAM_TOO_SHORT; } size_t currentIdx = HeaderReader::getHeaderSize(); @@ -24,12 +24,12 @@ ReturnValue_t FileDirectiveDeserializer::parseData() { return HasReturnvaluesIF::RETURN_OK; } -size_t FileDirectiveDeserializer::getHeaderSize() const { +size_t FileDirectiveReader::getHeaderSize() const { // return size of header plus the directive byte return HeaderReader::getHeaderSize() + 1; } -bool FileDirectiveDeserializer::checkFileDirective(uint8_t rawByte) { +bool FileDirectiveReader::checkFileDirective(uint8_t rawByte) { if (rawByte < cfdp::FileDirectives::EOF_DIRECTIVE or (rawByte > cfdp::FileDirectives::PROMPT and rawByte != cfdp::FileDirectives::KEEP_ALIVE)) { // Invalid directive field. TODO: Custom returnvalue @@ -38,12 +38,12 @@ bool FileDirectiveDeserializer::checkFileDirective(uint8_t rawByte) { return true; } -void FileDirectiveDeserializer::setFileDirective(cfdp::FileDirectives fileDirective) { - this->fileDirective = fileDirective; +void FileDirectiveReader::setFileDirective(cfdp::FileDirectives fileDirective_) { + fileDirective = fileDirective_; } -void FileDirectiveDeserializer::setEndianness(SerializeIF::Endianness endianness) { - this->endianness = endianness; +void FileDirectiveReader::setEndianness(SerializeIF::Endianness endianness_) { + endianness = endianness_; } -SerializeIF::Endianness FileDirectiveDeserializer::getEndianness() const { return endianness; } +SerializeIF::Endianness FileDirectiveReader::getEndianness() const { return endianness; } diff --git a/src/fsfw/cfdp/pdu/FileDirectiveDeserializer.h b/src/fsfw/cfdp/pdu/FileDirectiveReader.h similarity index 71% rename from src/fsfw/cfdp/pdu/FileDirectiveDeserializer.h rename to src/fsfw/cfdp/pdu/FileDirectiveReader.h index 193a71f3..69dd44cd 100644 --- a/src/fsfw/cfdp/pdu/FileDirectiveDeserializer.h +++ b/src/fsfw/cfdp/pdu/FileDirectiveReader.h @@ -11,24 +11,24 @@ * This is a zero-copy implementation and #parseData needs to be called to ensure the data is * valid. */ -class FileDirectiveDeserializer : public HeaderReader { +class FileDirectiveReader : public HeaderReader { public: - FileDirectiveDeserializer(const uint8_t* pduBuf, size_t maxSize); + FileDirectiveReader(const uint8_t* pduBuf, size_t maxSize); /** * This needs to be called before accessing the PDU fields to avoid segmentation faults. * @return */ - virtual ReturnValue_t parseData(); - size_t getHeaderSize() const; + ReturnValue_t parseData() override; + [[nodiscard]] size_t getHeaderSize() const override; - cfdp::FileDirectives getFileDirective() const; + [[nodiscard]] cfdp::FileDirectives getFileDirective() const; void setEndianness(SerializeIF::Endianness endianness); - SerializeIF::Endianness getEndianness() const; + [[nodiscard]] SerializeIF::Endianness getEndianness() const; protected: - bool checkFileDirective(uint8_t rawByte); + static bool checkFileDirective(uint8_t rawByte); private: void setFileDirective(cfdp::FileDirectives fileDirective); diff --git a/src/fsfw/cfdp/pdu/FinishedPduDeserializer.cpp b/src/fsfw/cfdp/pdu/FinishedPduDeserializer.cpp index feeca617..4209af65 100644 --- a/src/fsfw/cfdp/pdu/FinishedPduDeserializer.cpp +++ b/src/fsfw/cfdp/pdu/FinishedPduDeserializer.cpp @@ -2,21 +2,21 @@ FinishPduDeserializer::FinishPduDeserializer(const uint8_t* pduBuf, size_t maxSize, FinishedInfo& info) - : FileDirectiveDeserializer(pduBuf, maxSize), finishedInfo(info) {} + : FileDirectiveReader(pduBuf, maxSize), finishedInfo(info) {} ReturnValue_t FinishPduDeserializer::parseData() { - ReturnValue_t result = FileDirectiveDeserializer::parseData(); + ReturnValue_t result = FileDirectiveReader::parseData(); if (result != HasReturnvaluesIF::RETURN_OK) { return result; } - size_t currentIdx = FileDirectiveDeserializer::getHeaderSize(); + size_t currentIdx = FileDirectiveReader::getHeaderSize(); const uint8_t* buf = rawPtr + currentIdx; - size_t remSize = FileDirectiveDeserializer::getWholePduSize() - currentIdx; + size_t remSize = FileDirectiveReader::getWholePduSize() - currentIdx; if (remSize < 1) { return SerializeIF::STREAM_TOO_SHORT; } uint8_t firstByte = *buf; - cfdp::ConditionCode condCode = static_cast((firstByte >> 4) & 0x0f); + auto condCode = static_cast((firstByte >> 4) & 0x0f); finishedInfo.setConditionCode(condCode); finishedInfo.setDeliveryCode(static_cast(firstByte >> 2 & 0b1)); finishedInfo.setFileStatus(static_cast(firstByte & 0b11)); diff --git a/src/fsfw/cfdp/pdu/FinishedPduDeserializer.h b/src/fsfw/cfdp/pdu/FinishedPduDeserializer.h index a34fc4cb..1a13cad5 100644 --- a/src/fsfw/cfdp/pdu/FinishedPduDeserializer.h +++ b/src/fsfw/cfdp/pdu/FinishedPduDeserializer.h @@ -1,10 +1,10 @@ #ifndef FSFW_SRC_FSFW_CFDP_PDU_FINISHEDPDUDESERIALIZER_H_ #define FSFW_SRC_FSFW_CFDP_PDU_FINISHEDPDUDESERIALIZER_H_ -#include "fsfw/cfdp/pdu/FileDirectiveDeserializer.h" +#include "fsfw/cfdp/pdu/FileDirectiveReader.h" #include "fsfw/cfdp/pdu/FinishedInfo.h" -class FinishPduDeserializer : public FileDirectiveDeserializer { +class FinishPduDeserializer : public FileDirectiveReader { public: FinishPduDeserializer(const uint8_t* pduBuf, size_t maxSize, FinishedInfo& info); diff --git a/src/fsfw/cfdp/pdu/FinishedPduSerializer.cpp b/src/fsfw/cfdp/pdu/FinishedPduSerializer.cpp index 115a2c9c..de71d9d2 100644 --- a/src/fsfw/cfdp/pdu/FinishedPduSerializer.cpp +++ b/src/fsfw/cfdp/pdu/FinishedPduSerializer.cpp @@ -1,7 +1,7 @@ #include "FinishedPduSerializer.h" FinishPduSerializer::FinishPduSerializer(PduConfig &conf, FinishedInfo &finishInfo) - : FileDirectiveSerializer(conf, cfdp::FileDirectives::FINISH, 0), finishInfo(finishInfo) { + : FileDirectiveCreator(conf, cfdp::FileDirectives::FINISH, 0), finishInfo(finishInfo) { updateDirectiveFieldLen(); } @@ -15,8 +15,7 @@ void FinishPduSerializer::updateDirectiveFieldLen() { ReturnValue_t FinishPduSerializer::serialize(uint8_t **buffer, size_t *size, size_t maxSize, Endianness streamEndianness) const { - ReturnValue_t result = - FileDirectiveSerializer::serialize(buffer, size, maxSize, streamEndianness); + ReturnValue_t result = FileDirectiveCreator::serialize(buffer, size, maxSize, streamEndianness); if (result != HasReturnvaluesIF::RETURN_OK) { return result; } diff --git a/src/fsfw/cfdp/pdu/FinishedPduSerializer.h b/src/fsfw/cfdp/pdu/FinishedPduSerializer.h index d66b25f2..eb162c94 100644 --- a/src/fsfw/cfdp/pdu/FinishedPduSerializer.h +++ b/src/fsfw/cfdp/pdu/FinishedPduSerializer.h @@ -2,10 +2,10 @@ #define FSFW_SRC_FSFW_CFDP_PDU_FINISHEDPDUSERIALIZER_H_ #include "FinishedInfo.h" -#include "fsfw/cfdp/pdu/FileDataSerializer.h" -#include "fsfw/cfdp/pdu/FileDirectiveSerializer.h" +#include "fsfw/cfdp/pdu/FileDataCreator.h" +#include "fsfw/cfdp/pdu/FileDirectiveCreator.h" -class FinishPduSerializer : public FileDirectiveSerializer { +class FinishPduSerializer : public FileDirectiveCreator { public: FinishPduSerializer(PduConfig& pduConf, FinishedInfo& finishInfo); diff --git a/src/fsfw/cfdp/pdu/HeaderCreator.cpp b/src/fsfw/cfdp/pdu/HeaderCreator.cpp index debeedeb..d70e8270 100644 --- a/src/fsfw/cfdp/pdu/HeaderCreator.cpp +++ b/src/fsfw/cfdp/pdu/HeaderCreator.cpp @@ -47,8 +47,7 @@ ReturnValue_t HeaderCreator::serialize(uint8_t **buffer, size_t *size, size_t ma } size_t HeaderCreator::getSerializedSize() const { - size_t shit = pduConf.seqNum.getWidth() + pduConf.sourceId.getWidth() * 2 + 4; - return shit; + return pduConf.seqNum.getWidth() + pduConf.sourceId.getWidth() * 2 + 4; } ReturnValue_t HeaderCreator::deSerialize(const uint8_t **buffer, size_t *size, diff --git a/src/fsfw/cfdp/pdu/HeaderReader.cpp b/src/fsfw/cfdp/pdu/HeaderReader.cpp index 7aec3f49..cd8667b2 100644 --- a/src/fsfw/cfdp/pdu/HeaderReader.cpp +++ b/src/fsfw/cfdp/pdu/HeaderReader.cpp @@ -38,11 +38,12 @@ size_t HeaderReader::getHeaderSize() const { } size_t HeaderReader::getPduDataFieldLen() const { - uint16_t pduFiedlLen = (fixedHeader->pduDataFieldLenH << 8) | fixedHeader->pduDataFieldLenL; - return pduFiedlLen; + return (fixedHeader->pduDataFieldLenH << 8) | fixedHeader->pduDataFieldLenL; } -size_t HeaderReader::getWholePduSize() const { return getPduDataFieldLen() + getHeaderSize(); } +size_t HeaderReader::getWholePduSize() const { + return getPduDataFieldLen() + HeaderReader::getHeaderSize(); +} cfdp::PduType HeaderReader::getPduType() const { return static_cast((fixedHeader->firstByte >> 4) & 0x01); diff --git a/src/fsfw/cfdp/pdu/HeaderReader.h b/src/fsfw/cfdp/pdu/HeaderReader.h index 997828b6..1543a71b 100644 --- a/src/fsfw/cfdp/pdu/HeaderReader.h +++ b/src/fsfw/cfdp/pdu/HeaderReader.h @@ -41,7 +41,7 @@ class HeaderReader : public RedirectableDataPointerIF, public PduHeaderIF { * - SerializeIF::BUFFER_TOO_SHORT if buffer is shorter than expected */ virtual ReturnValue_t parseData(); - [[nodiscard]] size_t getHeaderSize() const; + [[nodiscard]] virtual size_t getHeaderSize() const; [[nodiscard]] size_t getPduDataFieldLen() const override; [[nodiscard]] size_t getWholePduSize() const override; diff --git a/src/fsfw/cfdp/pdu/KeepAlivePduDeserializer.cpp b/src/fsfw/cfdp/pdu/KeepAlivePduDeserializer.cpp index 15f80549..3acf26a1 100644 --- a/src/fsfw/cfdp/pdu/KeepAlivePduDeserializer.cpp +++ b/src/fsfw/cfdp/pdu/KeepAlivePduDeserializer.cpp @@ -2,15 +2,15 @@ KeepAlivePduDeserializer::KeepAlivePduDeserializer(const uint8_t* pduBuf, size_t maxSize, cfdp::FileSize& progress) - : FileDirectiveDeserializer(pduBuf, maxSize), progress(progress) {} + : FileDirectiveReader(pduBuf, maxSize), progress(progress) {} ReturnValue_t KeepAlivePduDeserializer::parseData() { - ReturnValue_t result = FileDirectiveDeserializer::parseData(); + ReturnValue_t result = FileDirectiveReader::parseData(); if (result != HasReturnvaluesIF::RETURN_OK) { return result; } - size_t currentIdx = FileDirectiveDeserializer::getHeaderSize(); - size_t remLen = FileDirectiveDeserializer::getWholePduSize() - currentIdx; + size_t currentIdx = FileDirectiveReader::getHeaderSize(); + size_t remLen = FileDirectiveReader::getWholePduSize() - currentIdx; const uint8_t* buffer = rawPtr + currentIdx; return progress.deSerialize(&buffer, &remLen, getEndianness()); } diff --git a/src/fsfw/cfdp/pdu/KeepAlivePduDeserializer.h b/src/fsfw/cfdp/pdu/KeepAlivePduDeserializer.h index e8b83ad6..1a8ca14d 100644 --- a/src/fsfw/cfdp/pdu/KeepAlivePduDeserializer.h +++ b/src/fsfw/cfdp/pdu/KeepAlivePduDeserializer.h @@ -2,9 +2,9 @@ #define FSFW_SRC_FSFW_CFDP_PDU_KEEPALIVEPDUDESERIALIZER_H_ #include "fsfw/cfdp/FileSize.h" -#include "fsfw/cfdp/pdu/FileDirectiveDeserializer.h" +#include "fsfw/cfdp/pdu/FileDirectiveReader.h" -class KeepAlivePduDeserializer : public FileDirectiveDeserializer { +class KeepAlivePduDeserializer : public FileDirectiveReader { public: KeepAlivePduDeserializer(const uint8_t* pduBuf, size_t maxSize, cfdp::FileSize& progress); diff --git a/src/fsfw/cfdp/pdu/KeepAlivePduSerializer.cpp b/src/fsfw/cfdp/pdu/KeepAlivePduSerializer.cpp index e635ce06..d257eb3d 100644 --- a/src/fsfw/cfdp/pdu/KeepAlivePduSerializer.cpp +++ b/src/fsfw/cfdp/pdu/KeepAlivePduSerializer.cpp @@ -1,12 +1,12 @@ #include "KeepAlivePduSerializer.h" KeepAlivePduSerializer::KeepAlivePduSerializer(PduConfig &conf, cfdp::FileSize &progress) - : FileDirectiveSerializer(conf, cfdp::FileDirectives::KEEP_ALIVE, 4), progress(progress) { + : FileDirectiveCreator(conf, cfdp::FileDirectives::KEEP_ALIVE, 4), progress(progress) { updateDirectiveFieldLen(); } size_t KeepAlivePduSerializer::getSerializedSize() const { - return FileDirectiveSerializer::getWholePduSize(); + return FileDirectiveCreator::getWholePduSize(); } void KeepAlivePduSerializer::updateDirectiveFieldLen() { @@ -17,8 +17,7 @@ void KeepAlivePduSerializer::updateDirectiveFieldLen() { ReturnValue_t KeepAlivePduSerializer::serialize(uint8_t **buffer, size_t *size, size_t maxSize, Endianness streamEndianness) const { - ReturnValue_t result = - FileDirectiveSerializer::serialize(buffer, size, maxSize, streamEndianness); + ReturnValue_t result = FileDirectiveCreator::serialize(buffer, size, maxSize, streamEndianness); if (result != HasReturnvaluesIF::RETURN_OK) { return result; } diff --git a/src/fsfw/cfdp/pdu/KeepAlivePduSerializer.h b/src/fsfw/cfdp/pdu/KeepAlivePduSerializer.h index d2499a79..0fabeb0a 100644 --- a/src/fsfw/cfdp/pdu/KeepAlivePduSerializer.h +++ b/src/fsfw/cfdp/pdu/KeepAlivePduSerializer.h @@ -2,9 +2,9 @@ #define FSFW_SRC_FSFW_CFDP_PDU_KEEPALIVEPDUSERIALIZER_H_ #include "fsfw/cfdp/FileSize.h" -#include "fsfw/cfdp/pdu/FileDirectiveSerializer.h" +#include "fsfw/cfdp/pdu/FileDirectiveCreator.h" -class KeepAlivePduSerializer : public FileDirectiveSerializer { +class KeepAlivePduSerializer : public FileDirectiveCreator { public: KeepAlivePduSerializer(PduConfig& conf, cfdp::FileSize& progress); diff --git a/src/fsfw/cfdp/pdu/MetadataPduDeserializer.cpp b/src/fsfw/cfdp/pdu/MetadataPduDeserializer.cpp index 161eb63a..00111303 100644 --- a/src/fsfw/cfdp/pdu/MetadataPduDeserializer.cpp +++ b/src/fsfw/cfdp/pdu/MetadataPduDeserializer.cpp @@ -2,16 +2,16 @@ MetadataPduDeserializer::MetadataPduDeserializer(const uint8_t* pduBuf, size_t maxSize, MetadataInfo& info) - : FileDirectiveDeserializer(pduBuf, maxSize), info(info) {} + : FileDirectiveReader(pduBuf, maxSize), info(info) {} ReturnValue_t MetadataPduDeserializer::parseData() { - ReturnValue_t result = FileDirectiveDeserializer::parseData(); + ReturnValue_t result = FileDirectiveReader::parseData(); if (result != HasReturnvaluesIF::RETURN_OK) { return result; } - size_t currentIdx = FileDirectiveDeserializer::getHeaderSize(); + size_t currentIdx = FileDirectiveReader::getHeaderSize(); const uint8_t* buf = rawPtr + currentIdx; - size_t remSize = FileDirectiveDeserializer::getWholePduSize() - currentIdx; + size_t remSize = FileDirectiveReader::getWholePduSize() - currentIdx; if (remSize < 1) { return SerializeIF::STREAM_TOO_SHORT; } diff --git a/src/fsfw/cfdp/pdu/MetadataPduDeserializer.h b/src/fsfw/cfdp/pdu/MetadataPduDeserializer.h index 1a8f9315..dcbb2c55 100644 --- a/src/fsfw/cfdp/pdu/MetadataPduDeserializer.h +++ b/src/fsfw/cfdp/pdu/MetadataPduDeserializer.h @@ -1,10 +1,10 @@ #ifndef FSFW_SRC_FSFW_CFDP_PDU_METADATAPDUDESERIALIZER_H_ #define FSFW_SRC_FSFW_CFDP_PDU_METADATAPDUDESERIALIZER_H_ -#include "fsfw/cfdp/pdu/FileDirectiveDeserializer.h" +#include "fsfw/cfdp/pdu/FileDirectiveReader.h" #include "fsfw/cfdp/pdu/MetadataInfo.h" -class MetadataPduDeserializer : public FileDirectiveDeserializer { +class MetadataPduDeserializer : public FileDirectiveReader { public: MetadataPduDeserializer(const uint8_t* pduBuf, size_t maxSize, MetadataInfo& info); diff --git a/src/fsfw/cfdp/pdu/MetadataPduSerializer.cpp b/src/fsfw/cfdp/pdu/MetadataPduSerializer.cpp index f5c4de0a..a08b3214 100644 --- a/src/fsfw/cfdp/pdu/MetadataPduSerializer.cpp +++ b/src/fsfw/cfdp/pdu/MetadataPduSerializer.cpp @@ -1,7 +1,7 @@ #include "MetadataPduSerializer.h" MetadataPduSerializer::MetadataPduSerializer(PduConfig &conf, MetadataInfo &info) - : FileDirectiveSerializer(conf, cfdp::FileDirectives::METADATA, 5), info(info) { + : FileDirectiveCreator(conf, cfdp::FileDirectives::METADATA, 5), info(info) { updateDirectiveFieldLen(); } @@ -10,13 +10,12 @@ void MetadataPduSerializer::updateDirectiveFieldLen() { } size_t MetadataPduSerializer::getSerializedSize() const { - return FileDirectiveSerializer::getWholePduSize(); + return FileDirectiveCreator::getWholePduSize(); } ReturnValue_t MetadataPduSerializer::serialize(uint8_t **buffer, size_t *size, size_t maxSize, Endianness streamEndianness) const { - ReturnValue_t result = - FileDirectiveSerializer::serialize(buffer, size, maxSize, streamEndianness); + ReturnValue_t result = FileDirectiveCreator::serialize(buffer, size, maxSize, streamEndianness); if (result != HasReturnvaluesIF::RETURN_OK) { return result; } diff --git a/src/fsfw/cfdp/pdu/MetadataPduSerializer.h b/src/fsfw/cfdp/pdu/MetadataPduSerializer.h index cacf8a52..a6514783 100644 --- a/src/fsfw/cfdp/pdu/MetadataPduSerializer.h +++ b/src/fsfw/cfdp/pdu/MetadataPduSerializer.h @@ -1,10 +1,10 @@ #ifndef FSFW_SRC_FSFW_CFDP_PDU_METADATAPDUSERIALIZER_H_ #define FSFW_SRC_FSFW_CFDP_PDU_METADATAPDUSERIALIZER_H_ -#include "fsfw/cfdp/pdu/FileDirectiveSerializer.h" +#include "fsfw/cfdp/pdu/FileDirectiveCreator.h" #include "fsfw/cfdp/pdu/MetadataInfo.h" -class MetadataPduSerializer : public FileDirectiveSerializer { +class MetadataPduSerializer : public FileDirectiveCreator { public: MetadataPduSerializer(PduConfig& conf, MetadataInfo& info); diff --git a/src/fsfw/cfdp/pdu/NakInfo.cpp b/src/fsfw/cfdp/pdu/NakInfo.cpp index 795004a9..14d06cb0 100644 --- a/src/fsfw/cfdp/pdu/NakInfo.cpp +++ b/src/fsfw/cfdp/pdu/NakInfo.cpp @@ -26,7 +26,7 @@ bool NakInfo::hasSegmentRequests() const { } bool NakInfo::canHoldSegmentRequests() const { - if (this->segmentRequests != nullptr and maxSegmentRequestsLen > 0) { + if (segmentRequests != nullptr and maxSegmentRequestsLen > 0) { return true; } return false; diff --git a/src/fsfw/cfdp/pdu/NakPduDeserializer.cpp b/src/fsfw/cfdp/pdu/NakPduDeserializer.cpp index 9d5f074c..a7f23996 100644 --- a/src/fsfw/cfdp/pdu/NakPduDeserializer.cpp +++ b/src/fsfw/cfdp/pdu/NakPduDeserializer.cpp @@ -1,16 +1,16 @@ #include "NakPduDeserializer.h" NakPduDeserializer::NakPduDeserializer(const uint8_t* pduBuf, size_t maxSize, NakInfo& info) - : FileDirectiveDeserializer(pduBuf, maxSize), nakInfo(info) {} + : FileDirectiveReader(pduBuf, maxSize), nakInfo(info) {} ReturnValue_t NakPduDeserializer::parseData() { - ReturnValue_t result = FileDirectiveDeserializer::parseData(); + ReturnValue_t result = FileDirectiveReader::parseData(); if (result != HasReturnvaluesIF::RETURN_OK) { return result; } - size_t currentIdx = FileDirectiveDeserializer::getHeaderSize(); + size_t currentIdx = FileDirectiveReader::getHeaderSize(); const uint8_t* buffer = rawPtr + currentIdx; - size_t remSize = FileDirectiveDeserializer::getWholePduSize() - currentIdx; + size_t remSize = FileDirectiveReader::getWholePduSize() - currentIdx; if (remSize < 1) { return SerializeIF::STREAM_TOO_SHORT; } diff --git a/src/fsfw/cfdp/pdu/NakPduDeserializer.h b/src/fsfw/cfdp/pdu/NakPduDeserializer.h index f0f43158..c119564d 100644 --- a/src/fsfw/cfdp/pdu/NakPduDeserializer.h +++ b/src/fsfw/cfdp/pdu/NakPduDeserializer.h @@ -1,10 +1,10 @@ #ifndef FSFW_SRC_FSFW_CFDP_PDU_NAKPDUDESERIALIZER_H_ #define FSFW_SRC_FSFW_CFDP_PDU_NAKPDUDESERIALIZER_H_ -#include "fsfw/cfdp/pdu/FileDirectiveDeserializer.h" +#include "fsfw/cfdp/pdu/FileDirectiveReader.h" #include "fsfw/cfdp/pdu/NakInfo.h" -class NakPduDeserializer : public FileDirectiveDeserializer { +class NakPduDeserializer : public FileDirectiveReader { public: NakPduDeserializer(const uint8_t* pduBuf, size_t maxSize, NakInfo& info); diff --git a/src/fsfw/cfdp/pdu/NakPduSerializer.cpp b/src/fsfw/cfdp/pdu/NakPduSerializer.cpp index 95f1bc98..767b2310 100644 --- a/src/fsfw/cfdp/pdu/NakPduSerializer.cpp +++ b/src/fsfw/cfdp/pdu/NakPduSerializer.cpp @@ -1,7 +1,7 @@ #include "NakPduSerializer.h" NakPduSerializer::NakPduSerializer(PduConfig &pduConf, NakInfo &nakInfo) - : FileDirectiveSerializer(pduConf, cfdp::FileDirectives::NAK, 0), nakInfo(nakInfo) { + : FileDirectiveCreator(pduConf, cfdp::FileDirectives::NAK, 0), nakInfo(nakInfo) { updateDirectiveFieldLen(); } @@ -10,13 +10,12 @@ void NakPduSerializer::updateDirectiveFieldLen() { } size_t NakPduSerializer::getSerializedSize() const { - return FileDirectiveSerializer::getWholePduSize(); + return FileDirectiveCreator::getWholePduSize(); } ReturnValue_t NakPduSerializer::serialize(uint8_t **buffer, size_t *size, size_t maxSize, Endianness streamEndianness) const { - ReturnValue_t result = - FileDirectiveSerializer::serialize(buffer, size, maxSize, streamEndianness); + ReturnValue_t result = FileDirectiveCreator::serialize(buffer, size, maxSize, streamEndianness); if (result != HasReturnvaluesIF::RETURN_OK) { return result; } diff --git a/src/fsfw/cfdp/pdu/NakPduSerializer.h b/src/fsfw/cfdp/pdu/NakPduSerializer.h index 4009884b..12e1bae2 100644 --- a/src/fsfw/cfdp/pdu/NakPduSerializer.h +++ b/src/fsfw/cfdp/pdu/NakPduSerializer.h @@ -6,9 +6,9 @@ #include "NakInfo.h" #include "fsfw/cfdp/FileSize.h" #include "fsfw/cfdp/definitions.h" -#include "fsfw/cfdp/pdu/FileDirectiveSerializer.h" +#include "fsfw/cfdp/pdu/FileDirectiveCreator.h" -class NakPduSerializer : public FileDirectiveSerializer { +class NakPduSerializer : public FileDirectiveCreator { public: /** * diff --git a/src/fsfw/cfdp/pdu/PromptPduDeserializer.cpp b/src/fsfw/cfdp/pdu/PromptPduDeserializer.cpp index 6a6f5505..833c9232 100644 --- a/src/fsfw/cfdp/pdu/PromptPduDeserializer.cpp +++ b/src/fsfw/cfdp/pdu/PromptPduDeserializer.cpp @@ -1,21 +1,21 @@ #include "PromptPduDeserializer.h" PromptPduDeserializer::PromptPduDeserializer(const uint8_t *pduBuf, size_t maxSize) - : FileDirectiveDeserializer(pduBuf, maxSize) {} + : FileDirectiveReader(pduBuf, maxSize) {} cfdp::PromptResponseRequired PromptPduDeserializer::getPromptResponseRequired() const { return responseRequired; } ReturnValue_t PromptPduDeserializer::parseData() { - ReturnValue_t result = FileDirectiveDeserializer::parseData(); + ReturnValue_t result = FileDirectiveReader::parseData(); if (result != HasReturnvaluesIF::RETURN_OK) { return result; } - size_t currentIdx = FileDirectiveDeserializer::getHeaderSize(); - if (FileDirectiveDeserializer::getWholePduSize() - currentIdx < 1) { + if (FileDirectiveReader::getWholePduSize() <= FileDirectiveReader::getHeaderSize()) { return SerializeIF::STREAM_TOO_SHORT; } - responseRequired = static_cast((rawPtr[currentIdx] >> 7) & 0x01); + responseRequired = static_cast( + (rawPtr[FileDirectiveReader::getHeaderSize()] >> 7) & 0x01); return HasReturnvaluesIF::RETURN_OK; } diff --git a/src/fsfw/cfdp/pdu/PromptPduDeserializer.h b/src/fsfw/cfdp/pdu/PromptPduDeserializer.h index 2f75033b..91ed5a9a 100644 --- a/src/fsfw/cfdp/pdu/PromptPduDeserializer.h +++ b/src/fsfw/cfdp/pdu/PromptPduDeserializer.h @@ -1,9 +1,9 @@ #ifndef FSFW_SRC_FSFW_CFDP_PDU_PROMPTPDUDESERIALIZER_H_ #define FSFW_SRC_FSFW_CFDP_PDU_PROMPTPDUDESERIALIZER_H_ -#include "fsfw/cfdp/pdu/FileDirectiveDeserializer.h" +#include "fsfw/cfdp/pdu/FileDirectiveReader.h" -class PromptPduDeserializer : public FileDirectiveDeserializer { +class PromptPduDeserializer : public FileDirectiveReader { public: PromptPduDeserializer(const uint8_t *pduBuf, size_t maxSize); diff --git a/src/fsfw/cfdp/pdu/PromptPduSerializer.cpp b/src/fsfw/cfdp/pdu/PromptPduSerializer.cpp index a7287563..cb0f1fec 100644 --- a/src/fsfw/cfdp/pdu/PromptPduSerializer.cpp +++ b/src/fsfw/cfdp/pdu/PromptPduSerializer.cpp @@ -2,24 +2,23 @@ PromptPduSerializer::PromptPduSerializer(PduConfig &conf, cfdp::PromptResponseRequired responseRequired) - : FileDirectiveSerializer(conf, cfdp::FileDirectives::PROMPT, 1), + : FileDirectiveCreator(conf, cfdp::FileDirectives::PROMPT, 1), responseRequired(responseRequired) {} size_t PromptPduSerializer::getSerializedSize() const { - return FileDirectiveSerializer::getWholePduSize(); + return FileDirectiveCreator::getWholePduSize(); } ReturnValue_t PromptPduSerializer::serialize(uint8_t **buffer, size_t *size, size_t maxSize, Endianness streamEndianness) const { - ReturnValue_t result = - FileDirectiveSerializer::serialize(buffer, size, maxSize, streamEndianness); + ReturnValue_t result = FileDirectiveCreator::serialize(buffer, size, maxSize, streamEndianness); if (result != HasReturnvaluesIF::RETURN_OK) { return result; } if (*size + 1 > maxSize) { return SerializeIF::BUFFER_TOO_SHORT; } - **buffer = this->responseRequired << 7; + **buffer = responseRequired << 7; *buffer += 1; *size += 1; return result; diff --git a/src/fsfw/cfdp/pdu/PromptPduSerializer.h b/src/fsfw/cfdp/pdu/PromptPduSerializer.h index 51500224..1abe362e 100644 --- a/src/fsfw/cfdp/pdu/PromptPduSerializer.h +++ b/src/fsfw/cfdp/pdu/PromptPduSerializer.h @@ -1,13 +1,13 @@ #ifndef FSFW_SRC_FSFW_CFDP_PDU_PROMPTPDUSERIALIZER_H_ #define FSFW_SRC_FSFW_CFDP_PDU_PROMPTPDUSERIALIZER_H_ -#include "fsfw/cfdp/pdu/FileDirectiveSerializer.h" +#include "fsfw/cfdp/pdu/FileDirectiveCreator.h" -class PromptPduSerializer : public FileDirectiveSerializer { +class PromptPduSerializer : public FileDirectiveCreator { public: PromptPduSerializer(PduConfig& conf, cfdp::PromptResponseRequired responseRequired); - size_t getSerializedSize() const override; + [[nodiscard]] size_t getSerializedSize() const override; ReturnValue_t serialize(uint8_t** buffer, size_t* size, size_t maxSize, Endianness streamEndianness) const override; diff --git a/unittests/cfdp/testCfdp.cpp b/unittests/cfdp/testCfdp.cpp index 475322a2..f3d36cdd 100644 --- a/unittests/cfdp/testCfdp.cpp +++ b/unittests/cfdp/testCfdp.cpp @@ -3,8 +3,8 @@ #include #include "fsfw/cfdp/FileSize.h" -#include "fsfw/cfdp/pdu/FileDirectiveDeserializer.h" -#include "fsfw/cfdp/pdu/FileDirectiveSerializer.h" +#include "fsfw/cfdp/pdu/FileDirectiveCreator.h" +#include "fsfw/cfdp/pdu/FileDirectiveReader.h" #include "fsfw/globalfunctions/arrayprinter.h" #include "fsfw/serialize/SerializeAdapter.h" @@ -22,7 +22,7 @@ TEST_CASE("CFDP Base", "[cfdp]") { size_t serSize = 0; SECTION("File Directive") { - auto fdSer = FileDirectiveSerializer(pduConf, FileDirectives::ACK, 4); + auto fdSer = FileDirectiveCreator(pduConf, FileDirectives::ACK, 4); REQUIRE(fdSer.getSerializedSize() == 8); serTarget = serBuf.data(); serSize = 0; @@ -59,7 +59,7 @@ TEST_CASE("CFDP Base", "[cfdp]") { deserTarget = serBuf.data(); deserSize = 0; - auto fdDeser = FileDirectiveDeserializer(deserTarget, serBuf.size()); + auto fdDeser = FileDirectiveReader(deserTarget, serBuf.size()); REQUIRE(fdDeser.getEndianness() == SerializeIF::Endianness::NETWORK); fdDeser.setEndianness(SerializeIF::Endianness::MACHINE); REQUIRE(fdDeser.getEndianness() == SerializeIF::Endianness::MACHINE); diff --git a/unittests/cfdp/testFileData.cpp b/unittests/cfdp/testFileData.cpp index 272cea47..943b6ddc 100644 --- a/unittests/cfdp/testFileData.cpp +++ b/unittests/cfdp/testFileData.cpp @@ -1,8 +1,8 @@ #include #include -#include "fsfw/cfdp/pdu/FileDataDeserializer.h" -#include "fsfw/cfdp/pdu/FileDataSerializer.h" +#include "fsfw/cfdp/pdu/FileDataCreator.h" +#include "fsfw/cfdp/pdu/FileDataReader.h" #include "fsfw/globalfunctions/arrayprinter.h" #include "fsfw/serviceinterface.h" @@ -26,7 +26,7 @@ TEST_CASE("File Data PDU", "[cfdp][pdu]") { FileDataInfo info(offset, fileBuffer.data(), 10); SECTION("Serialization") { - FileDataSerializer serializer(pduConf, info); + FileDataCreator serializer(pduConf, info); result = serializer.serialize(&buffer, &sz, fileDataBuffer.size(), SerializeIF::Endianness::NETWORK); REQUIRE(result == HasReturnvaluesIF::RETURN_OK); @@ -102,14 +102,14 @@ TEST_CASE("File Data PDU", "[cfdp][pdu]") { } SECTION("Deserialization") { - FileDataSerializer serializer(pduConf, info); + FileDataCreator serializer(pduConf, info); result = serializer.serialize(&buffer, &sz, fileDataBuffer.size(), SerializeIF::Endianness::NETWORK); REQUIRE(result == HasReturnvaluesIF::RETURN_OK); FileSize emptyOffset; FileDataInfo emptyInfo(emptyOffset); - FileDataDeserializer deserializer(fileDataBuffer.data(), fileDataBuffer.size(), emptyInfo); + FileDataReader deserializer(fileDataBuffer.data(), fileDataBuffer.size(), emptyInfo); result = deserializer.parseData(); REQUIRE(result == HasReturnvaluesIF::RETURN_OK); REQUIRE(deserializer.getWholePduSize() == 24); diff --git a/unittests/cfdp/testFileDirective.cpp b/unittests/cfdp/testFileDirective.cpp index 31053d01..3a4818ec 100644 --- a/unittests/cfdp/testFileDirective.cpp +++ b/unittests/cfdp/testFileDirective.cpp @@ -1,8 +1,8 @@ #include #include -#include "fsfw/cfdp/pdu/FileDirectiveDeserializer.h" -#include "fsfw/cfdp/pdu/FileDirectiveSerializer.h" +#include "fsfw/cfdp/pdu/FileDirectiveCreator.h" +#include "fsfw/cfdp/pdu/FileDirectiveReader.h" TEST_CASE("CFDP File Directive", "[cfdp]") { using namespace cfdp; @@ -18,7 +18,7 @@ TEST_CASE("CFDP File Directive", "[cfdp]") { size_t serSize = 0; SECTION("File Directive") { - auto fdSer = FileDirectiveSerializer(pduConf, FileDirectives::ACK, 4); + auto fdSer = FileDirectiveCreator(pduConf, FileDirectives::ACK, 4); REQUIRE(fdSer.getSerializedSize() == 8); serTarget = serBuf.data(); serSize = 0; @@ -55,7 +55,7 @@ TEST_CASE("CFDP File Directive", "[cfdp]") { deserTarget = serBuf.data(); deserSize = 0; - auto fdDeser = FileDirectiveDeserializer(deserTarget, serBuf.size()); + auto fdDeser = FileDirectiveReader(deserTarget, serBuf.size()); REQUIRE(fdDeser.getEndianness() == SerializeIF::Endianness::NETWORK); fdDeser.setEndianness(SerializeIF::Endianness::MACHINE); REQUIRE(fdDeser.getEndianness() == SerializeIF::Endianness::MACHINE); diff --git a/unittests/cfdp/testNakPdu.cpp b/unittests/cfdp/testNakPdu.cpp index 5eee60a4..0ef329ff 100644 --- a/unittests/cfdp/testNakPdu.cpp +++ b/unittests/cfdp/testNakPdu.cpp @@ -25,7 +25,7 @@ TEST_CASE("NAK PDU", "[cfdp][pdu]") { result = serializer.serialize(&buffer, &sz, nakBuffer.size(), SerializeIF::Endianness::NETWORK); REQUIRE(result == HasReturnvaluesIF::RETURN_OK); REQUIRE(serializer.getSerializedSize() == 19); - REQUIRE(serializer.FileDirectiveSerializer::getSerializedSize() == 11); + REQUIRE(serializer.FileDirectiveCreator::getSerializedSize() == 11); REQUIRE(sz == 19); REQUIRE(serializer.getPduDataFieldLen() == 9); REQUIRE(((nakBuffer[1] << 8) | nakBuffer[2]) == 0x09); diff --git a/unittests/cfdp/testPromptPdu.cpp b/unittests/cfdp/testPromptPdu.cpp index 88dc8ac9..868f7140 100644 --- a/unittests/cfdp/testPromptPdu.cpp +++ b/unittests/cfdp/testPromptPdu.cpp @@ -51,8 +51,10 @@ TEST_CASE("Prompt PDU", "[cfdp][pdu]") { REQUIRE(deserializer.getPromptResponseRequired() == cfdp::PromptResponseRequired::PROMPT_KEEP_ALIVE); sz = deserializer.getWholePduSize(); + // Set invalid size rawBuf[2] = 1; result = deserializer.parseData(); + size_t sz2 = deserializer.getWholePduSize(); REQUIRE(result == SerializeIF::STREAM_TOO_SHORT); rawBuf[2] = 2; From c6a7a0fec8340efcdb905e9cad504a2592c1de9d Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Wed, 3 Aug 2022 18:14:49 +0200 Subject: [PATCH 018/169] use distributor instead of router --- src/fsfw/cfdp/CMakeLists.txt | 2 +- src/fsfw/cfdp/CfdpDistributor.cpp | 197 +++++------------- .../cfdp/{CfdpRouter.h => CfdpDistributor.h} | 28 ++- src/fsfw/cfdp/CfdpRouter.cpp | 63 ------ src/fsfw/cfdp/CfdpRouterIF.h | 32 --- src/fsfw/cfdp/pdu/HeaderReader.h | 1 + 6 files changed, 67 insertions(+), 256 deletions(-) rename src/fsfw/cfdp/{CfdpRouter.h => CfdpDistributor.h} (70%) delete mode 100644 src/fsfw/cfdp/CfdpRouter.cpp delete mode 100644 src/fsfw/cfdp/CfdpRouterIF.h diff --git a/src/fsfw/cfdp/CMakeLists.txt b/src/fsfw/cfdp/CMakeLists.txt index 2d58e190..9bd54fc8 100644 --- a/src/fsfw/cfdp/CMakeLists.txt +++ b/src/fsfw/cfdp/CMakeLists.txt @@ -1,4 +1,4 @@ -target_sources(${LIB_FSFW_NAME} PRIVATE CfdpMessage.cpp CfdpRouter.cpp) +target_sources(${LIB_FSFW_NAME} PRIVATE CfdpMessage.cpp CfdpDistributor.cpp) # CfdpDistributor.cpp CfdpHandler.cpp add_subdirectory(pdu) diff --git a/src/fsfw/cfdp/CfdpDistributor.cpp b/src/fsfw/cfdp/CfdpDistributor.cpp index fa221822..14e0180c 100644 --- a/src/fsfw/cfdp/CfdpDistributor.cpp +++ b/src/fsfw/cfdp/CfdpDistributor.cpp @@ -1,144 +1,53 @@ -//#include "CfdpRouter.h" -//#include "fsfw/tcdistribution/CcsdsDistributorIF.h" -//#include "fsfw/tmtcpacket/cfdp/CfdpPacketStored.h" -// -//#ifndef FSFW_CFDP_DISTRIBUTOR_DEBUGGING -//#define FSFW_CFDP_DISTRIBUTOR_DEBUGGING 1 -//#endif -// -// CfdpHandler::CfdpHandler(uint16_t setApid, object_id_t setObjectId, -// object_id_t setPacketSource) -// : TcDistributorBase(setObjectId), -// apid(setApid), -// checker(setApid), -// tcStatus(RETURN_FAILED), -// packetSource(setPacketSource) {} -// -// CfdpHandler::~CfdpHandler() = default; -// -// ReturnValue_t CfdpHandler::selectDestination(MessageQueueId_t& destId) { -// //#if FSFW_CFDP_DISTRIBUTOR_DEBUGGING == 1 -// // store_address_t storeId = this->currentMessage.getStorageId(); -// //#if FSFW_CPP_OSTREAM_ENABLED == 1 -// // sif::debug << "CFDPDistributor::handlePacket received: " << storeId.poolIndex << ", " -// // << storeId.packetIndex << std::endl; -// //#else -// // sif::printDebug("CFDPDistributor::handlePacket received: %d, %d\n", storeId.poolIndex, -// // storeId.packetIndex); -// //#endif -// //#endif -// // auto queueMapIt = this->queueMap.end(); -// // if (this->currentPacket == nullptr) { -// // return queueMapIt; -// // } -// // this->currentPacket->setStoreAddress(this->currentMessage.getStorageId()); -// // if (currentPacket->getFullData() != nullptr) { -// // tcStatus = checker.checkPacket(*currentPacket, currentPacket->getFullPacketLen()); -// // 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 -// // } -// // queueMapIt = this->queueMap.find(0); -// // } else { -// // tcStatus = PACKET_LOST; -// // } -// // -// // if (queueMapIt == this->queueMap.end()) { -// // tcStatus = DESTINATION_NOT_FOUND; -// //#if FSFW_VERBOSE_LEVEL >= 1 -// //#if FSFW_CPP_OSTREAM_ENABLED == 1 -// // sif::debug << "CFDPDistributor::handlePacket: Destination not found" << std::endl; -// //#else -// // sif::printDebug("CFDPDistributor::handlePacket: Destination not found\n"); -// //#endif /* !FSFW_CPP_OSTREAM_ENABLED == 1 */ -// //#endif -// // } -// // -// // if (tcStatus != RETURN_OK) { -// // return this->queueMap.end(); -// // } else { -// // return queueMapIt; -// // } -// return HasReturnvaluesIF::RETURN_OK; -//} -// -// ReturnValue_t CfdpHandler::registerHandler(AcceptsTelecommandsIF* handler) { -// // uint16_t handlerId = -// // handler->getIdentifier(); // should be 0, because CfdpHandler does not set a set a -// // service-ID -// //#if FSFW_CFDP_DISTRIBUTOR_DEBUGGING == 1 -// //#if FSFW_CPP_OSTREAM_ENABLED == 1 -// // sif::info << "CFDPDistributor::registerHandler: Handler ID: " << static_cast(handlerId) -// // << std::endl; -// //#else -// // sif::printInfo("CFDPDistributor::registerHandler: Handler ID: %d\n", -// // static_cast(handlerId)); -// //#endif -// //#endif -// // 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::registerHandler: Service ID already" -// // " exists in map" -// // << std::endl; -// //#else -// // sif::printError("CFDPDistributor::registerHandler: Service ID already exists in map\n"); -// //#endif -// //#endif -// // return SERVICE_ID_ALREADY_EXISTS; -// // } -// return HasReturnvaluesIF::RETURN_OK; -//} -// -// MessageQueueId_t CfdpHandler::getRequestQueue() const { 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; -//// } -//// } -// -// uint32_t CfdpHandler::getIdentifier() const { return this->apid; } -// -// ReturnValue_t CfdpHandler::initialize() { -// // currentPacket = new CfdpPacketStored(); -// // if (currentPacket == nullptr) { -// // // Should not happen, memory allocation failed! -// // return ObjectManagerIF::CHILD_INIT_FAILED; -// // } -// // -// // auto* ccsdsDistributor = ObjectManager::instance()->get(packetSource); -// // if (ccsdsDistributor == nullptr) { -// //#if FSFW_CPP_OSTREAM_ENABLED == 1 -// // sif::error << "CFDPDistributor::initialize: Packet source invalid" << std::endl; -// // sif::error << " Make sure it exists and implements CCSDSDistributorIF!" << std::endl; -// //#else -// // sif::printError("CFDPDistributor::initialize: Packet source invalid\n"); -// // sif::printError("Make sure it exists and implements CcsdsDistributorIF\n"); -// //#endif -// // return RETURN_FAILED; -// // } -// // return ccsdsDistributor->registerApplication(this); -// return HasReturnvaluesIF::RETURN_OK; -//} +#include "CfdpDistributor.h" + +#include "fsfw/tcdistribution/definitions.h" + +CfdpDistributor::CfdpDistributor(CfdpRouterCfg cfg) : TcDistributorBase(cfg.objectId), cfg(cfg) {} + +ReturnValue_t CfdpDistributor::registerTcDestination(const cfdp::EntityId& address, + AcceptsTelecommandsIF& tcDest) { + for (const auto& dest : tcDestinations) { + if (dest.id == address) { + return HasReturnvaluesIF::RETURN_FAILED; + } + } + tcDestinations.emplace_back(address, tcDest.getName(), tcDest.getRequestQueue()); + return HasReturnvaluesIF::RETURN_OK; +} + +ReturnValue_t CfdpDistributor::selectDestination(MessageQueueId_t& destId) { + auto accessorPair = cfg.tcStore.getData(currentMessage.getStorageId()); + if (accessorPair.first != HasReturnvaluesIF::RETURN_OK) { + return accessorPair.first; + } + ReturnValue_t result = pduReader.setData(accessorPair.second.data(), accessorPair.second.size()); + if (result != HasReturnvaluesIF::RETURN_OK) { + return result; + } + result = pduReader.parseData(); + if (result != HasReturnvaluesIF::RETURN_OK) { + return result; + } + cfdp::EntityId foundId; + pduReader.getDestId(foundId); + bool destFound = false; + for (const auto& dest : tcDestinations) { + if (dest.id == foundId) { + destId = dest.queueId; + destFound = true; + } + } + if (not destFound) { + // TODO: Warning and event? + return HasReturnvaluesIF::RETURN_FAILED; + } + // Packet was forwarded successfully, so do not delete it. + accessorPair.second.release(); + return HasReturnvaluesIF::RETURN_OK; +} + +const char* CfdpDistributor::getName() const { return "CFDP Router"; } + +uint32_t CfdpDistributor::getIdentifier() const { return 0; } + +MessageQueueId_t CfdpDistributor::getRequestQueue() const { return tcQueue->getId(); } diff --git a/src/fsfw/cfdp/CfdpRouter.h b/src/fsfw/cfdp/CfdpDistributor.h similarity index 70% rename from src/fsfw/cfdp/CfdpRouter.h rename to src/fsfw/cfdp/CfdpDistributor.h index 178f0177..cfb31f2b 100644 --- a/src/fsfw/cfdp/CfdpRouter.h +++ b/src/fsfw/cfdp/CfdpDistributor.h @@ -4,7 +4,7 @@ #include #include -#include "CfdpRouterIF.h" +#include "fsfw/cfdp/pdu/HeaderReader.h" #include "fsfw/returnvalues/HasReturnvaluesIF.h" #include "fsfw/tcdistribution/CfdpPacketChecker.h" #include "fsfw/tcdistribution/TcDistributorBase.h" @@ -13,22 +13,23 @@ #include "fsfw/tmtcservices/VerificationReporter.h" struct CfdpRouterCfg { - CfdpRouterCfg(object_id_t objectId, MessageQueueIF& tmQueue) - : objectId(objectId), tmQueue(tmQueue) {} + CfdpRouterCfg(object_id_t objectId, MessageQueueIF& tmQueue, StorageManagerIF& tcStore, + StorageManagerIF& tmStore) + : objectId(objectId), tmQueue(tmQueue), tcStore(tcStore), tmStore(tmStore) {} object_id_t objectId; MessageQueueIF& tmQueue; + StorageManagerIF& tcStore; + StorageManagerIF& tmStore; }; + /** * This will be the primary component to perform PDU forwading procedures. This includes forwarding * CFDP TC packets to registered source or destination handlers, and forwarding all telemetry * generated by them to registered TM sinks. * @ingroup tc_distribution */ -class CfdpRouter : public TcDistributorBase, - public CfdpRouterIF, - public AcceptsTelecommandsIF, - public AcceptsTelemetryIF { +class CfdpDistributor : public TcDistributorBase, public AcceptsTelecommandsIF { public: /** * The ctor passes @c set_apid to the checker class and calls the @@ -38,17 +39,12 @@ class CfdpRouter : public TcDistributorBase, * @param setPacketSource Object ID of the source of TC packets. * Must implement CcsdsDistributorIF. */ - explicit CfdpRouter(CfdpRouterCfg cfg); + explicit CfdpDistributor(CfdpRouterCfg cfg); - ReturnValue_t performOperation(uint8_t opCode) override; - ReturnValue_t performTmHandling(); [[nodiscard]] const char* getName() const override; [[nodiscard]] uint32_t getIdentifier() const override; [[nodiscard]] MessageQueueId_t getRequestQueue() const override; - MessageQueueId_t getReportReceptionQueue(uint8_t virtualChannel) override; - ReturnValue_t registerTmSink(cfdp::EntityId address, AcceptsTelemetryIF& tmDest) override; - ReturnValue_t registerTcDestination(cfdp::EntityId address, - AcceptsTelecommandsIF& tcDest) override; + ReturnValue_t registerTcDestination(const cfdp::EntityId& address, AcceptsTelecommandsIF& tcDest); protected: struct EntityInfo { @@ -58,13 +54,13 @@ class CfdpRouter : public TcDistributorBase, const char* name; MessageQueueId_t queueId; }; + HeaderReader pduReader; ReturnValue_t lastTcError = HasReturnvaluesIF::RETURN_OK; ReturnValue_t lastTmError = HasReturnvaluesIF::RETURN_OK; // I don't think a regular OBSW will have more than 1 or 2 of these destinations, so I think // it is okay to accept the overhead here - std::vector tmDestinations; std::vector tcDestinations; - MessageQueueIF& tmQueue; + CfdpRouterCfg cfg; ReturnValue_t selectDestination(MessageQueueId_t& destId) override; diff --git a/src/fsfw/cfdp/CfdpRouter.cpp b/src/fsfw/cfdp/CfdpRouter.cpp deleted file mode 100644 index dfe910e6..00000000 --- a/src/fsfw/cfdp/CfdpRouter.cpp +++ /dev/null @@ -1,63 +0,0 @@ -#include "CfdpRouter.h" - -#include "fsfw/tcdistribution/definitions.h" - -CfdpRouter::CfdpRouter(CfdpRouterCfg cfg) : TcDistributorBase(cfg.objectId), tmQueue(cfg.tmQueue) {} - -ReturnValue_t CfdpRouter::registerTmSink(cfdp::EntityId address, AcceptsTelemetryIF& tmDest) { - for (const auto& dest : tmDestinations) { - if (dest.id == address) { - return HasReturnvaluesIF::RETURN_FAILED; - } - } - tmDestinations.emplace_back(address, tmDest.getName(), tmDest.getReportReceptionQueue()); - return HasReturnvaluesIF::RETURN_OK; -} -ReturnValue_t CfdpRouter::registerTcDestination(cfdp::EntityId address, - AcceptsTelecommandsIF& tcDest) { - for (const auto& dest : tcDestinations) { - if (dest.id == address) { - return HasReturnvaluesIF::RETURN_FAILED; - } - } - tcDestinations.emplace_back(address, tcDest.getName(), tcDest.getRequestQueue()); - return HasReturnvaluesIF::RETURN_OK; -} - -ReturnValue_t CfdpRouter::selectDestination(MessageQueueId_t& destId) { return 0; } - -const char* CfdpRouter::getName() const { return "CFDP Router"; } - -uint32_t CfdpRouter::getIdentifier() const { return 0; } - -MessageQueueId_t CfdpRouter::getRequestQueue() const { return tcQueue->getId(); } - -MessageQueueId_t CfdpRouter::getReportReceptionQueue(uint8_t virtualChannel) { - return tmQueue.getId(); -} - -ReturnValue_t CfdpRouter::performOperation(uint8_t opCode) { - lastTcError = TcDistributorBase::performOperation(opCode); - lastTmError = performTmHandling(); - if (lastTcError != HasReturnvaluesIF::RETURN_OK or lastTmError != HasReturnvaluesIF::RETURN_OK) { - return HasReturnvaluesIF::RETURN_FAILED; - } - return HasReturnvaluesIF::RETURN_OK; -} - -ReturnValue_t CfdpRouter::performTmHandling() { - ReturnValue_t status; - ReturnValue_t result = HasReturnvaluesIF::RETURN_OK; - for (status = tmQueue.receiveMessage(¤tMessage); status == RETURN_OK; - status = tmQueue.receiveMessage(¤tMessage)) { - ReturnValue_t packetResult = handlePacket(); - if (packetResult != HasReturnvaluesIF::RETURN_OK) { - result = packetResult; - triggerEvent(tmtcdistrib::HANDLE_PACKET_FAILED, packetResult, ccsds::PacketType::TM); - } - } - if (status == MessageQueueIF::EMPTY) { - return result; - } - return result; -} diff --git a/src/fsfw/cfdp/CfdpRouterIF.h b/src/fsfw/cfdp/CfdpRouterIF.h deleted file mode 100644 index 0c630407..00000000 --- a/src/fsfw/cfdp/CfdpRouterIF.h +++ /dev/null @@ -1,32 +0,0 @@ -#ifndef FSFW_TCDISTRIBUTION_CFDPDISTRIBUTORIF_H_ -#define FSFW_TCDISTRIBUTION_CFDPDISTRIBUTORIF_H_ - -#include "fsfw/cfdp/definitions.h" -#include "fsfw/cfdp/pdu/PduHeaderIF.h" -#include "fsfw/ipc/MessageQueueSenderIF.h" -#include "fsfw/tmtcservices/AcceptsTelecommandsIF.h" -#include "fsfw/tmtcservices/AcceptsTelemetryIF.h" - -/** - * This interface allows CFDP Services to register themselves at a CFDP Distributor. - * @ingroup tc_distribution - */ -class CfdpRouterIF { - public: - /** - * The empty virtual destructor. - */ - virtual ~CfdpRouterIF() = default; - - virtual ReturnValue_t registerTmSink(cfdp::EntityId address, AcceptsTelemetryIF& tmDest) = 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 registerTcDestination(cfdp::EntityId address, - AcceptsTelecommandsIF& tcDest) = 0; -}; - -#endif /* FSFW_TCDISTRIBUTION_CFDPDISTRIBUTORIF_H_ */ diff --git a/src/fsfw/cfdp/pdu/HeaderReader.h b/src/fsfw/cfdp/pdu/HeaderReader.h index 1543a71b..67a0470a 100644 --- a/src/fsfw/cfdp/pdu/HeaderReader.h +++ b/src/fsfw/cfdp/pdu/HeaderReader.h @@ -25,6 +25,7 @@ struct PduHeaderFixedStruct { */ class HeaderReader : public RedirectableDataPointerIF, public PduHeaderIF { public: + HeaderReader() = default; /** * Initialize a PDU header from raw data. This is a zero-copy implementation and #parseData * needs to be called to ensure the data is valid From 269a3052ca769a2931af62180b87823fe558b159 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Wed, 3 Aug 2022 18:18:01 +0200 Subject: [PATCH 019/169] added stubs for source and dest handler --- src/fsfw/cfdp/CMakeLists.txt | 4 +++- src/fsfw/cfdp/CfdpDestHandler.cpp | 1 + src/fsfw/cfdp/CfdpDestHandler.h | 6 ++++++ src/fsfw/cfdp/CfdpSourceHandler.cpp | 1 + src/fsfw/cfdp/CfdpSourceHandler.h | 6 ++++++ 5 files changed, 17 insertions(+), 1 deletion(-) create mode 100644 src/fsfw/cfdp/CfdpDestHandler.cpp create mode 100644 src/fsfw/cfdp/CfdpDestHandler.h create mode 100644 src/fsfw/cfdp/CfdpSourceHandler.cpp create mode 100644 src/fsfw/cfdp/CfdpSourceHandler.h diff --git a/src/fsfw/cfdp/CMakeLists.txt b/src/fsfw/cfdp/CMakeLists.txt index 9bd54fc8..3d35ea69 100644 --- a/src/fsfw/cfdp/CMakeLists.txt +++ b/src/fsfw/cfdp/CMakeLists.txt @@ -1,4 +1,6 @@ -target_sources(${LIB_FSFW_NAME} PRIVATE CfdpMessage.cpp CfdpDistributor.cpp) +target_sources( + ${LIB_FSFW_NAME} PRIVATE CfdpMessage.cpp CfdpDistributor.cpp + CfdpSourceHandler.cpp CfdpDestHandler.cpp) # CfdpDistributor.cpp CfdpHandler.cpp add_subdirectory(pdu) diff --git a/src/fsfw/cfdp/CfdpDestHandler.cpp b/src/fsfw/cfdp/CfdpDestHandler.cpp new file mode 100644 index 00000000..f3eb657a --- /dev/null +++ b/src/fsfw/cfdp/CfdpDestHandler.cpp @@ -0,0 +1 @@ +#include "CfdpDestHandler.h" diff --git a/src/fsfw/cfdp/CfdpDestHandler.h b/src/fsfw/cfdp/CfdpDestHandler.h new file mode 100644 index 00000000..69d40ed3 --- /dev/null +++ b/src/fsfw/cfdp/CfdpDestHandler.h @@ -0,0 +1,6 @@ +#ifndef FSFW_CFDP_CFDPDESTHANDLER_H +#define FSFW_CFDP_CFDPDESTHANDLER_H + +class CfdpDestHandler {}; + +#endif // FSFW_CFDP_CFDPDESTHANDLER_H diff --git a/src/fsfw/cfdp/CfdpSourceHandler.cpp b/src/fsfw/cfdp/CfdpSourceHandler.cpp new file mode 100644 index 00000000..c4b42d55 --- /dev/null +++ b/src/fsfw/cfdp/CfdpSourceHandler.cpp @@ -0,0 +1 @@ +#include "CfdpSourceHandler.h" diff --git a/src/fsfw/cfdp/CfdpSourceHandler.h b/src/fsfw/cfdp/CfdpSourceHandler.h new file mode 100644 index 00000000..b343a6ed --- /dev/null +++ b/src/fsfw/cfdp/CfdpSourceHandler.h @@ -0,0 +1,6 @@ +#ifndef FSFW_CFDP_CFDPSOURCEHANDLER_H +#define FSFW_CFDP_CFDPSOURCEHANDLER_H + +class CfdpSourceHandler {}; + +#endif // FSFW_CFDP_CFDPSOURCEHANDLER_H From fdb0cc0e4495ab458ba66816376cf55ccb29ccd8 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Mon, 8 Aug 2022 12:31:19 +0200 Subject: [PATCH 020/169] tweaks for CFDP distributor --- src/fsfw/cfdp/CfdpDistributor.cpp | 3 ++- src/fsfw/cfdp/CfdpDistributor.h | 8 +++----- src/fsfw/tcdistribution/CcsdsDistributor.cpp | 2 +- src/fsfw/tcdistribution/PusDistributor.cpp | 2 +- 4 files changed, 7 insertions(+), 8 deletions(-) diff --git a/src/fsfw/cfdp/CfdpDistributor.cpp b/src/fsfw/cfdp/CfdpDistributor.cpp index 14e0180c..0b522d2d 100644 --- a/src/fsfw/cfdp/CfdpDistributor.cpp +++ b/src/fsfw/cfdp/CfdpDistributor.cpp @@ -2,7 +2,8 @@ #include "fsfw/tcdistribution/definitions.h" -CfdpDistributor::CfdpDistributor(CfdpRouterCfg cfg) : TcDistributorBase(cfg.objectId), cfg(cfg) {} +CfdpDistributor::CfdpDistributor(CfdpRouterCfg cfg) + : TcDistributorBase(cfg.objectId, cfg.tcQueue), cfg(cfg) {} ReturnValue_t CfdpDistributor::registerTcDestination(const cfdp::EntityId& address, AcceptsTelecommandsIF& tcDest) { diff --git a/src/fsfw/cfdp/CfdpDistributor.h b/src/fsfw/cfdp/CfdpDistributor.h index cfb31f2b..bf66df5e 100644 --- a/src/fsfw/cfdp/CfdpDistributor.h +++ b/src/fsfw/cfdp/CfdpDistributor.h @@ -13,14 +13,12 @@ #include "fsfw/tmtcservices/VerificationReporter.h" struct CfdpRouterCfg { - CfdpRouterCfg(object_id_t objectId, MessageQueueIF& tmQueue, StorageManagerIF& tcStore, - StorageManagerIF& tmStore) - : objectId(objectId), tmQueue(tmQueue), tcStore(tcStore), tmStore(tmStore) {} + CfdpRouterCfg(object_id_t objectId, StorageManagerIF& tcStore, MessageQueueIF* tcQueue) + : objectId(objectId), tcStore(tcStore), tcQueue(tcQueue) {} object_id_t objectId; - MessageQueueIF& tmQueue; StorageManagerIF& tcStore; - StorageManagerIF& tmStore; + MessageQueueIF* tcQueue; }; /** diff --git a/src/fsfw/tcdistribution/CcsdsDistributor.cpp b/src/fsfw/tcdistribution/CcsdsDistributor.cpp index 6932d2d3..a2080ea8 100644 --- a/src/fsfw/tcdistribution/CcsdsDistributor.cpp +++ b/src/fsfw/tcdistribution/CcsdsDistributor.cpp @@ -98,7 +98,7 @@ void CcsdsDistributor::handlePacketCheckFailure(ReturnValue_t result) { const char* reason = "Unknown reason"; if (result == tmtcdistrib::INVALID_CCSDS_VERSION) { reason = "Invalid CCSDS version"; - } else if (result == tcdistrib::INCOMPLETE_PACKET) { + } else if (result == tmtcdistrib::INCOMPLETE_PACKET) { reason = "Size missmatch between CCSDS data length and packet length"; } else if (result == tmtcdistrib::INVALID_APID) { reason = "No valid handler APID found"; diff --git a/src/fsfw/tcdistribution/PusDistributor.cpp b/src/fsfw/tcdistribution/PusDistributor.cpp index f719b50f..5384b34c 100644 --- a/src/fsfw/tcdistribution/PusDistributor.cpp +++ b/src/fsfw/tcdistribution/PusDistributor.cpp @@ -145,7 +145,7 @@ ReturnValue_t PusDistributor::initialize() { void PusDistributor::checkerFailurePrinter() const { #if FSFW_VERBOSE_LEVEL >= 1 const char* reason = "Unknown reason"; - if (tcStatus == tcdistrib::INCORRECT_CHECKSUM) { + if (tcStatus == tmtcdistrib::INCORRECT_CHECKSUM) { reason = "Checksum Error"; } else if (tcStatus == tmtcdistrib::INCORRECT_PRIMARY_HEADER) { reason = "Incorrect Primary Header"; From 65a47c7c5749fc4c6f1460feb58cca037763aef1 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Mon, 8 Aug 2022 12:34:54 +0200 Subject: [PATCH 021/169] add distributor test stub --- unittests/cfdp/CMakeLists.txt | 3 ++- unittests/cfdp/testAckPdu.cpp | 2 +- unittests/cfdp/testDistributor.cpp | 5 +++++ 3 files changed, 8 insertions(+), 2 deletions(-) create mode 100644 unittests/cfdp/testDistributor.cpp diff --git a/unittests/cfdp/CMakeLists.txt b/unittests/cfdp/CMakeLists.txt index 9cc2726e..31acb186 100644 --- a/unittests/cfdp/CMakeLists.txt +++ b/unittests/cfdp/CMakeLists.txt @@ -11,4 +11,5 @@ target_sources( testMetadataPdu.cpp testFileData.cpp testCfdpHeader.cpp - testFileDirective.cpp) + testFileDirective.cpp + testDistributor.cpp) diff --git a/unittests/cfdp/testAckPdu.cpp b/unittests/cfdp/testAckPdu.cpp index 70451aa0..49c81803 100644 --- a/unittests/cfdp/testAckPdu.cpp +++ b/unittests/cfdp/testAckPdu.cpp @@ -5,7 +5,7 @@ #include "fsfw/cfdp/pdu/AckPduSerializer.h" #include "fsfw/globalfunctions/arrayprinter.h" -TEST_CASE("ACK PDU", "[AckPdu]") { +TEST_CASE("ACK PDU", "[cfdp][pdu]") { using namespace cfdp; ReturnValue_t result; std::array buf = {}; diff --git a/unittests/cfdp/testDistributor.cpp b/unittests/cfdp/testDistributor.cpp new file mode 100644 index 00000000..ba66f99a --- /dev/null +++ b/unittests/cfdp/testDistributor.cpp @@ -0,0 +1,5 @@ +#include + +TEST_CASE("CFDP Distributor", "[cfdp][distributor]") { + +} \ No newline at end of file From 43fb6ef5cb96b153feae3f409eb4fbaf513f6fcd Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Mon, 8 Aug 2022 12:35:58 +0200 Subject: [PATCH 022/169] some tag replacements --- unittests/action/TestActionHelper.cpp | 2 +- unittests/container/RingBufferTest.cpp | 2 +- unittests/container/TestArrayList.cpp | 2 +- unittests/container/TestDynamicFifo.cpp | 2 +- unittests/container/TestFifo.cpp | 2 +- unittests/container/TestFixedArrayList.cpp | 2 +- unittests/container/TestFixedMap.cpp | 2 +- unittests/container/TestFixedOrderedMultimap.cpp | 2 +- unittests/container/TestPlacementFactory.cpp | 2 +- 9 files changed, 9 insertions(+), 9 deletions(-) diff --git a/unittests/action/TestActionHelper.cpp b/unittests/action/TestActionHelper.cpp index a6eea048..30edf397 100644 --- a/unittests/action/TestActionHelper.cpp +++ b/unittests/action/TestActionHelper.cpp @@ -8,7 +8,7 @@ #include "mocks/MessageQueueMock.h" -TEST_CASE("Action Helper", "[ActionHelper]") { +TEST_CASE("Action Helper", "[action]") { ActionHelperOwnerMockBase testDhMock; // TODO: Setting another number here breaks the test. Find out why MessageQueueMock testMqMock(MessageQueueIF::NO_QUEUE); diff --git a/unittests/container/RingBufferTest.cpp b/unittests/container/RingBufferTest.cpp index edabfd55..e621731c 100644 --- a/unittests/container/RingBufferTest.cpp +++ b/unittests/container/RingBufferTest.cpp @@ -5,7 +5,7 @@ #include "CatchDefinitions.h" -TEST_CASE("Ring Buffer Test", "[RingBufferTest]") { +TEST_CASE("Ring Buffer Test", "[containers]") { uint8_t testData[13] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12}; uint8_t readBuffer[10] = {13, 13, 13, 13, 13, 13, 13, 13, 13, 13}; SimpleRingBuffer ringBuffer(10, false, 5); diff --git a/unittests/container/TestArrayList.cpp b/unittests/container/TestArrayList.cpp index 4daf59d4..2c0eefdf 100644 --- a/unittests/container/TestArrayList.cpp +++ b/unittests/container/TestArrayList.cpp @@ -8,7 +8,7 @@ /** * @brief Array List test */ -TEST_CASE("Array List", "[ArrayListTest]") { +TEST_CASE("Array List", "[containers]") { // perform set-up here ArrayList list(20); struct TestClass { diff --git a/unittests/container/TestDynamicFifo.cpp b/unittests/container/TestDynamicFifo.cpp index 6769c247..cd800677 100644 --- a/unittests/container/TestDynamicFifo.cpp +++ b/unittests/container/TestDynamicFifo.cpp @@ -6,7 +6,7 @@ #include "CatchDefinitions.h" -TEST_CASE("Dynamic Fifo Tests", "[TestDynamicFifo]") { +TEST_CASE("Dynamic Fifo Tests", "[containers]") { INFO("Dynamic Fifo Tests"); struct Test { uint64_t number1; diff --git a/unittests/container/TestFifo.cpp b/unittests/container/TestFifo.cpp index 0b4b41af..b173ac46 100644 --- a/unittests/container/TestFifo.cpp +++ b/unittests/container/TestFifo.cpp @@ -6,7 +6,7 @@ #include "CatchDefinitions.h" -TEST_CASE("Static Fifo Tests", "[TestFifo]") { +TEST_CASE("Static Fifo Tests", "[containers]") { INFO("Fifo Tests"); struct Test { uint64_t number1; diff --git a/unittests/container/TestFixedArrayList.cpp b/unittests/container/TestFixedArrayList.cpp index 6beb8d5d..06f52cc7 100644 --- a/unittests/container/TestFixedArrayList.cpp +++ b/unittests/container/TestFixedArrayList.cpp @@ -5,7 +5,7 @@ #include "CatchDefinitions.h" -TEST_CASE("FixedArrayList Tests", "[TestFixedArrayList]") { +TEST_CASE("FixedArrayList Tests", "[containers]") { INFO("FixedArrayList Tests"); using testList = FixedArrayList; testList list; diff --git a/unittests/container/TestFixedMap.cpp b/unittests/container/TestFixedMap.cpp index d3c65760..49cc0c35 100644 --- a/unittests/container/TestFixedMap.cpp +++ b/unittests/container/TestFixedMap.cpp @@ -7,7 +7,7 @@ template class FixedMap; -TEST_CASE("FixedMap Tests", "[TestFixedMap]") { +TEST_CASE("FixedMap Tests", "[containers]") { INFO("FixedMap Tests"); FixedMap map(30); diff --git a/unittests/container/TestFixedOrderedMultimap.cpp b/unittests/container/TestFixedOrderedMultimap.cpp index 88b32694..361f19dc 100644 --- a/unittests/container/TestFixedOrderedMultimap.cpp +++ b/unittests/container/TestFixedOrderedMultimap.cpp @@ -5,7 +5,7 @@ #include "CatchDefinitions.h" -TEST_CASE("FixedOrderedMultimap Tests", "[TestFixedOrderedMultimap]") { +TEST_CASE("FixedOrderedMultimap Tests", "[containers]") { INFO("FixedOrderedMultimap Tests"); FixedOrderedMultimap map(30); diff --git a/unittests/container/TestPlacementFactory.cpp b/unittests/container/TestPlacementFactory.cpp index 1333567e..d599c708 100644 --- a/unittests/container/TestPlacementFactory.cpp +++ b/unittests/container/TestPlacementFactory.cpp @@ -7,7 +7,7 @@ #include "CatchDefinitions.h" -TEST_CASE("PlacementFactory Tests", "[TestPlacementFactory]") { +TEST_CASE("PlacementFactory Tests", "[containers]") { INFO("PlacementFactory Tests"); LocalPool::LocalPoolConfig poolCfg = { From 37c60d1dd095647257238eeffd65ef53545c5902 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Mon, 8 Aug 2022 12:41:05 +0200 Subject: [PATCH 023/169] add source and dest test stubs --- unittests/cfdp/CMakeLists.txt | 4 +++- unittests/cfdp/testDestHandler.cpp | 5 +++++ unittests/cfdp/testSourceHandler.cpp | 5 +++++ 3 files changed, 13 insertions(+), 1 deletion(-) create mode 100644 unittests/cfdp/testDestHandler.cpp create mode 100644 unittests/cfdp/testSourceHandler.cpp diff --git a/unittests/cfdp/CMakeLists.txt b/unittests/cfdp/CMakeLists.txt index 31acb186..ac4672fa 100644 --- a/unittests/cfdp/CMakeLists.txt +++ b/unittests/cfdp/CMakeLists.txt @@ -12,4 +12,6 @@ target_sources( testFileData.cpp testCfdpHeader.cpp testFileDirective.cpp - testDistributor.cpp) + testDistributor.cpp + testDestHandler.cpp + testSourceHandler.cpp) diff --git a/unittests/cfdp/testDestHandler.cpp b/unittests/cfdp/testDestHandler.cpp new file mode 100644 index 00000000..fb09d595 --- /dev/null +++ b/unittests/cfdp/testDestHandler.cpp @@ -0,0 +1,5 @@ +#include + +TEST_CASE("CFDP Dest Handler", "[cfdp]") { + +} \ No newline at end of file diff --git a/unittests/cfdp/testSourceHandler.cpp b/unittests/cfdp/testSourceHandler.cpp new file mode 100644 index 00000000..5738fbba --- /dev/null +++ b/unittests/cfdp/testSourceHandler.cpp @@ -0,0 +1,5 @@ +#include + +TEST_CASE("CFDP Source Handler", "[cfdp]") { + +} \ No newline at end of file From 202d9341d8d7686259e7143e2c219a2e23736db0 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Mon, 8 Aug 2022 17:53:42 +0200 Subject: [PATCH 024/169] add CFDP unit tests --- src/fsfw/cfdp/CfdpDistributor.cpp | 4 +- src/fsfw/cfdp/CfdpDistributor.h | 8 ++-- src/fsfw/cfdp/pdu/CMakeLists.txt | 4 +- src/fsfw/cfdp/pdu/MetadataInfo.cpp | 42 +++++++++---------- src/fsfw/cfdp/pdu/MetadataInfo.h | 15 +++---- ...uSerializer.cpp => MetadataPduCreator.cpp} | 12 +++--- src/fsfw/cfdp/pdu/MetadataPduCreator.h | 22 ++++++++++ src/fsfw/cfdp/pdu/MetadataPduDeserializer.h | 17 -------- ...Deserializer.cpp => MetadataPduReader.cpp} | 7 ++-- src/fsfw/cfdp/pdu/MetadataPduReader.h | 17 ++++++++ src/fsfw/cfdp/pdu/MetadataPduSerializer.h | 22 ---------- src/fsfw/cfdp/pdu/PduConfig.h | 4 ++ unittests/cfdp/testDestHandler.cpp | 4 +- unittests/cfdp/testDistributor.cpp | 27 +++++++++++- unittests/cfdp/testMetadataPdu.cpp | 22 +++++----- unittests/cfdp/testSourceHandler.cpp | 4 +- 16 files changed, 128 insertions(+), 103 deletions(-) rename src/fsfw/cfdp/pdu/{MetadataPduSerializer.cpp => MetadataPduCreator.cpp} (77%) create mode 100644 src/fsfw/cfdp/pdu/MetadataPduCreator.h delete mode 100644 src/fsfw/cfdp/pdu/MetadataPduDeserializer.h rename src/fsfw/cfdp/pdu/{MetadataPduDeserializer.cpp => MetadataPduReader.cpp} (87%) create mode 100644 src/fsfw/cfdp/pdu/MetadataPduReader.h delete mode 100644 src/fsfw/cfdp/pdu/MetadataPduSerializer.h diff --git a/src/fsfw/cfdp/CfdpDistributor.cpp b/src/fsfw/cfdp/CfdpDistributor.cpp index 0b522d2d..4aa9c797 100644 --- a/src/fsfw/cfdp/CfdpDistributor.cpp +++ b/src/fsfw/cfdp/CfdpDistributor.cpp @@ -2,7 +2,7 @@ #include "fsfw/tcdistribution/definitions.h" -CfdpDistributor::CfdpDistributor(CfdpRouterCfg cfg) +CfdpDistributor::CfdpDistributor(CfdpDistribCfg cfg) : TcDistributorBase(cfg.objectId, cfg.tcQueue), cfg(cfg) {} ReturnValue_t CfdpDistributor::registerTcDestination(const cfdp::EntityId& address, @@ -47,7 +47,7 @@ ReturnValue_t CfdpDistributor::selectDestination(MessageQueueId_t& destId) { return HasReturnvaluesIF::RETURN_OK; } -const char* CfdpDistributor::getName() const { return "CFDP Router"; } +const char* CfdpDistributor::getName() const { return "CFDP Distributor"; } uint32_t CfdpDistributor::getIdentifier() const { return 0; } diff --git a/src/fsfw/cfdp/CfdpDistributor.h b/src/fsfw/cfdp/CfdpDistributor.h index bf66df5e..8fece981 100644 --- a/src/fsfw/cfdp/CfdpDistributor.h +++ b/src/fsfw/cfdp/CfdpDistributor.h @@ -12,8 +12,8 @@ #include "fsfw/tmtcservices/AcceptsTelecommandsIF.h" #include "fsfw/tmtcservices/VerificationReporter.h" -struct CfdpRouterCfg { - CfdpRouterCfg(object_id_t objectId, StorageManagerIF& tcStore, MessageQueueIF* tcQueue) +struct CfdpDistribCfg { + CfdpDistribCfg(object_id_t objectId, StorageManagerIF& tcStore, MessageQueueIF* tcQueue) : objectId(objectId), tcStore(tcStore), tcQueue(tcQueue) {} object_id_t objectId; @@ -37,7 +37,7 @@ class CfdpDistributor : public TcDistributorBase, public AcceptsTelecommandsIF { * @param setPacketSource Object ID of the source of TC packets. * Must implement CcsdsDistributorIF. */ - explicit CfdpDistributor(CfdpRouterCfg cfg); + explicit CfdpDistributor(CfdpDistribCfg cfg); [[nodiscard]] const char* getName() const override; [[nodiscard]] uint32_t getIdentifier() const override; @@ -58,7 +58,7 @@ class CfdpDistributor : public TcDistributorBase, public AcceptsTelecommandsIF { // I don't think a regular OBSW will have more than 1 or 2 of these destinations, so I think // it is okay to accept the overhead here std::vector tcDestinations; - CfdpRouterCfg cfg; + CfdpDistribCfg cfg; ReturnValue_t selectDestination(MessageQueueId_t& destId) override; diff --git a/src/fsfw/cfdp/pdu/CMakeLists.txt b/src/fsfw/cfdp/pdu/CMakeLists.txt index 21fe0820..33b05eec 100644 --- a/src/fsfw/cfdp/pdu/CMakeLists.txt +++ b/src/fsfw/cfdp/pdu/CMakeLists.txt @@ -19,8 +19,8 @@ target_sources( FinishedPduSerializer.cpp FinishedPduDeserializer.cpp MetadataInfo.cpp - MetadataPduSerializer.cpp - MetadataPduDeserializer.cpp + MetadataPduCreator.cpp + MetadataPduReader.cpp KeepAlivePduSerializer.cpp KeepAlivePduDeserializer.cpp PromptPduSerializer.cpp diff --git a/src/fsfw/cfdp/pdu/MetadataInfo.cpp b/src/fsfw/cfdp/pdu/MetadataInfo.cpp index a2ca6972..5f66b776 100644 --- a/src/fsfw/cfdp/pdu/MetadataInfo.cpp +++ b/src/fsfw/cfdp/pdu/MetadataInfo.cpp @@ -9,41 +9,41 @@ MetadataInfo::MetadataInfo(bool closureRequested, cfdp::ChecksumType checksumTyp sourceFileName(sourceFileName), destFileName(destFileName) {} -void MetadataInfo::setOptionsArray(cfdp::Tlv** optionsArray, size_t* optionsLen, - size_t* maxOptionsLen) { - this->optionsArray = optionsArray; - if (maxOptionsLen != nullptr) { - this->maxOptionsLen = *maxOptionsLen; +void MetadataInfo::setOptionsArray(cfdp::Tlv** optionsArray_, const size_t* optionsLen_, + const size_t* maxOptionsLen_) { + this->optionsArray = optionsArray_; + if (maxOptionsLen_ != nullptr) { + this->maxOptionsLen = *maxOptionsLen_; } - if (optionsLen != nullptr) { - this->optionsLen = *optionsLen; + if (optionsLen_ != nullptr) { + this->optionsLen = *optionsLen_; } } cfdp::ChecksumType MetadataInfo::getChecksumType() const { return checksumType; } -void MetadataInfo::setChecksumType(cfdp::ChecksumType checksumType) { - this->checksumType = checksumType; +void MetadataInfo::setChecksumType(cfdp::ChecksumType checksumType_) { + checksumType = checksumType_; } bool MetadataInfo::isClosureRequested() const { return closureRequested; } -void MetadataInfo::setClosureRequested(bool closureRequested) { - this->closureRequested = closureRequested; +void MetadataInfo::setClosureRequested(bool closureRequested_) { + closureRequested = closureRequested_; } cfdp::Lv& MetadataInfo::getDestFileName() { return destFileName; } cfdp::FileSize& MetadataInfo::getFileSize() { return fileSize; } -ReturnValue_t MetadataInfo::getOptions(cfdp::Tlv*** optionsArray, size_t* optionsLen, +ReturnValue_t MetadataInfo::getOptions(cfdp::Tlv*** optionsArray_, size_t* optionsLen_, size_t* maxOptsLen) { - if (optionsArray == nullptr or this->optionsArray == nullptr) { + if (optionsArray_ == nullptr or optionsArray == nullptr) { return HasReturnvaluesIF::RETURN_FAILED; } - *optionsArray = this->optionsArray; - if (optionsLen != nullptr) { - *optionsLen = this->optionsLen; + *optionsArray_ = optionsArray; + if (optionsLen_ != nullptr) { + *optionsLen_ = this->optionsLen; } if (maxOptsLen != nullptr) { *maxOptsLen = this->maxOptionsLen; @@ -81,18 +81,18 @@ size_t MetadataInfo::getSerializedSize(bool fssLarge) { return size; } -void MetadataInfo::setDestFileName(cfdp::Lv& destFileName) { this->destFileName = destFileName; } +void MetadataInfo::setDestFileName(cfdp::Lv& destFileName_) { this->destFileName = destFileName_; } -void MetadataInfo::setSourceFileName(cfdp::Lv& sourceFileName) { - this->sourceFileName = sourceFileName; +void MetadataInfo::setSourceFileName(cfdp::Lv& sourceFileName_) { + this->sourceFileName = sourceFileName_; } size_t MetadataInfo::getMaxOptionsLen() const { return maxOptionsLen; } -void MetadataInfo::setMaxOptionsLen(size_t maxOptionsLen) { this->maxOptionsLen = maxOptionsLen; } +void MetadataInfo::setMaxOptionsLen(size_t maxOptionsLen_) { this->maxOptionsLen = maxOptionsLen_; } size_t MetadataInfo::getOptionsLen() const { return optionsLen; } -void MetadataInfo::setOptionsLen(size_t optionsLen) { this->optionsLen = optionsLen; } +void MetadataInfo::setOptionsLen(size_t optionsLen_) { this->optionsLen = optionsLen_; } cfdp::Lv& MetadataInfo::getSourceFileName() { return sourceFileName; } diff --git a/src/fsfw/cfdp/pdu/MetadataInfo.h b/src/fsfw/cfdp/pdu/MetadataInfo.h index 9b90138c..f71eb2f4 100644 --- a/src/fsfw/cfdp/pdu/MetadataInfo.h +++ b/src/fsfw/cfdp/pdu/MetadataInfo.h @@ -13,10 +13,11 @@ class MetadataInfo { size_t getSerializedSize(bool fssLarge = false); - void setOptionsArray(cfdp::Tlv** optionsArray, size_t* optionsLen, size_t* maxOptionsLen); - cfdp::ChecksumType getChecksumType() const; + void setOptionsArray(cfdp::Tlv** optionsArray, const size_t* optionsLen, + const size_t* maxOptionsLen); + [[nodiscard]] cfdp::ChecksumType getChecksumType() const; void setChecksumType(cfdp::ChecksumType checksumType); - bool isClosureRequested() const; + [[nodiscard]] bool isClosureRequested() const; void setClosureRequested(bool closureRequested = false); void setDestFileName(cfdp::Lv& destFileName); @@ -26,13 +27,13 @@ class MetadataInfo { cfdp::Lv& getSourceFileName(); cfdp::FileSize& getFileSize(); - bool hasOptions() const; - bool canHoldOptions() const; + [[nodiscard]] bool hasOptions() const; + [[nodiscard]] bool canHoldOptions() const; ReturnValue_t getOptions(cfdp::Tlv*** optionsArray, size_t* optionsLen, size_t* maxOptsLen); void setOptionsLen(size_t optionsLen); - size_t getOptionsLen() const; + [[nodiscard]] size_t getOptionsLen() const; void setMaxOptionsLen(size_t maxOptionsLen); - size_t getMaxOptionsLen() const; + [[nodiscard]] size_t getMaxOptionsLen() const; private: bool closureRequested = false; diff --git a/src/fsfw/cfdp/pdu/MetadataPduSerializer.cpp b/src/fsfw/cfdp/pdu/MetadataPduCreator.cpp similarity index 77% rename from src/fsfw/cfdp/pdu/MetadataPduSerializer.cpp rename to src/fsfw/cfdp/pdu/MetadataPduCreator.cpp index a08b3214..5dcdabd2 100644 --- a/src/fsfw/cfdp/pdu/MetadataPduSerializer.cpp +++ b/src/fsfw/cfdp/pdu/MetadataPduCreator.cpp @@ -1,20 +1,20 @@ -#include "MetadataPduSerializer.h" +#include "MetadataPduCreator.h" -MetadataPduSerializer::MetadataPduSerializer(PduConfig &conf, MetadataInfo &info) +MetadataPduCreator::MetadataPduCreator(PduConfig &conf, MetadataInfo &info) : FileDirectiveCreator(conf, cfdp::FileDirectives::METADATA, 5), info(info) { updateDirectiveFieldLen(); } -void MetadataPduSerializer::updateDirectiveFieldLen() { +void MetadataPduCreator::updateDirectiveFieldLen() { setDirectiveDataFieldLen(info.getSerializedSize(getLargeFileFlag())); } -size_t MetadataPduSerializer::getSerializedSize() const { +size_t MetadataPduCreator::getSerializedSize() const { return FileDirectiveCreator::getWholePduSize(); } -ReturnValue_t MetadataPduSerializer::serialize(uint8_t **buffer, size_t *size, size_t maxSize, - Endianness streamEndianness) const { +ReturnValue_t MetadataPduCreator::serialize(uint8_t **buffer, size_t *size, size_t maxSize, + Endianness streamEndianness) const { ReturnValue_t result = FileDirectiveCreator::serialize(buffer, size, maxSize, streamEndianness); if (result != HasReturnvaluesIF::RETURN_OK) { return result; diff --git a/src/fsfw/cfdp/pdu/MetadataPduCreator.h b/src/fsfw/cfdp/pdu/MetadataPduCreator.h new file mode 100644 index 00000000..2c2f35f8 --- /dev/null +++ b/src/fsfw/cfdp/pdu/MetadataPduCreator.h @@ -0,0 +1,22 @@ +#ifndef FSFW_CFDP_PDU_METADATAPDUCREATOR_H_ +#define FSFW_CFDP_PDU_METADATAPDUCREATOR_H_ + +#include "fsfw/cfdp/pdu/FileDirectiveCreator.h" +#include "fsfw/cfdp/pdu/MetadataInfo.h" + +class MetadataPduCreator : public FileDirectiveCreator { + public: + MetadataPduCreator(PduConfig& conf, MetadataInfo& info); + + void updateDirectiveFieldLen(); + + [[nodiscard]] size_t getSerializedSize() const override; + + ReturnValue_t serialize(uint8_t** buffer, size_t* size, size_t maxSize, + Endianness streamEndianness) const override; + + private: + MetadataInfo& info; +}; + +#endif /* FSFW_CFDP_PDU_METADATAPDUCREATOR_H_ */ diff --git a/src/fsfw/cfdp/pdu/MetadataPduDeserializer.h b/src/fsfw/cfdp/pdu/MetadataPduDeserializer.h deleted file mode 100644 index dcbb2c55..00000000 --- a/src/fsfw/cfdp/pdu/MetadataPduDeserializer.h +++ /dev/null @@ -1,17 +0,0 @@ -#ifndef FSFW_SRC_FSFW_CFDP_PDU_METADATAPDUDESERIALIZER_H_ -#define FSFW_SRC_FSFW_CFDP_PDU_METADATAPDUDESERIALIZER_H_ - -#include "fsfw/cfdp/pdu/FileDirectiveReader.h" -#include "fsfw/cfdp/pdu/MetadataInfo.h" - -class MetadataPduDeserializer : public FileDirectiveReader { - public: - MetadataPduDeserializer(const uint8_t* pduBuf, size_t maxSize, MetadataInfo& info); - - ReturnValue_t parseData() override; - - private: - MetadataInfo& info; -}; - -#endif /* FSFW_SRC_FSFW_CFDP_PDU_METADATAPDUDESERIALIZER_H_ */ diff --git a/src/fsfw/cfdp/pdu/MetadataPduDeserializer.cpp b/src/fsfw/cfdp/pdu/MetadataPduReader.cpp similarity index 87% rename from src/fsfw/cfdp/pdu/MetadataPduDeserializer.cpp rename to src/fsfw/cfdp/pdu/MetadataPduReader.cpp index 00111303..29dc2e15 100644 --- a/src/fsfw/cfdp/pdu/MetadataPduDeserializer.cpp +++ b/src/fsfw/cfdp/pdu/MetadataPduReader.cpp @@ -1,10 +1,9 @@ -#include "MetadataPduDeserializer.h" +#include "MetadataPduReader.h" -MetadataPduDeserializer::MetadataPduDeserializer(const uint8_t* pduBuf, size_t maxSize, - MetadataInfo& info) +MetadataPduReader::MetadataPduReader(const uint8_t* pduBuf, size_t maxSize, MetadataInfo& info) : FileDirectiveReader(pduBuf, maxSize), info(info) {} -ReturnValue_t MetadataPduDeserializer::parseData() { +ReturnValue_t MetadataPduReader::parseData() { ReturnValue_t result = FileDirectiveReader::parseData(); if (result != HasReturnvaluesIF::RETURN_OK) { return result; diff --git a/src/fsfw/cfdp/pdu/MetadataPduReader.h b/src/fsfw/cfdp/pdu/MetadataPduReader.h new file mode 100644 index 00000000..3e8c0f30 --- /dev/null +++ b/src/fsfw/cfdp/pdu/MetadataPduReader.h @@ -0,0 +1,17 @@ +#ifndef FSFW_CFDP_PDU_METADATAPDUREADER_H_ +#define FSFW_CFDP_PDU_METADATAPDUREADER_H_ + +#include "fsfw/cfdp/pdu/FileDirectiveReader.h" +#include "fsfw/cfdp/pdu/MetadataInfo.h" + +class MetadataPduReader : public FileDirectiveReader { + public: + MetadataPduReader(const uint8_t* pduBuf, size_t maxSize, MetadataInfo& info); + + ReturnValue_t parseData() override; + + private: + MetadataInfo& info; +}; + +#endif /* FSFW_CFDP_PDU_METADATAPDUREADER_H_ */ diff --git a/src/fsfw/cfdp/pdu/MetadataPduSerializer.h b/src/fsfw/cfdp/pdu/MetadataPduSerializer.h deleted file mode 100644 index a6514783..00000000 --- a/src/fsfw/cfdp/pdu/MetadataPduSerializer.h +++ /dev/null @@ -1,22 +0,0 @@ -#ifndef FSFW_SRC_FSFW_CFDP_PDU_METADATAPDUSERIALIZER_H_ -#define FSFW_SRC_FSFW_CFDP_PDU_METADATAPDUSERIALIZER_H_ - -#include "fsfw/cfdp/pdu/FileDirectiveCreator.h" -#include "fsfw/cfdp/pdu/MetadataInfo.h" - -class MetadataPduSerializer : public FileDirectiveCreator { - public: - MetadataPduSerializer(PduConfig& conf, MetadataInfo& info); - - void updateDirectiveFieldLen(); - - size_t getSerializedSize() const override; - - ReturnValue_t serialize(uint8_t** buffer, size_t* size, size_t maxSize, - Endianness streamEndianness) const override; - - private: - MetadataInfo& info; -}; - -#endif /* FSFW_SRC_FSFW_CFDP_PDU_METADATAPDUSERIALIZER_H_ */ diff --git a/src/fsfw/cfdp/pdu/PduConfig.h b/src/fsfw/cfdp/pdu/PduConfig.h index f92b25fc..858176ff 100644 --- a/src/fsfw/cfdp/pdu/PduConfig.h +++ b/src/fsfw/cfdp/pdu/PduConfig.h @@ -8,12 +8,16 @@ namespace cfdp { struct EntityId : public VarLenField { public: EntityId() : VarLenField() {} + template + explicit EntityId(UnsignedByteField byteField) : VarLenField(byteField) {} EntityId(cfdp::WidthInBytes width, size_t entityId) : VarLenField(width, entityId) {} }; struct TransactionSeqNum : public VarLenField { public: TransactionSeqNum() : VarLenField() {} + template + explicit TransactionSeqNum(UnsignedByteField byteField) : VarLenField(byteField) {} TransactionSeqNum(cfdp::WidthInBytes width, size_t seqNum) : VarLenField(width, seqNum) {} }; diff --git a/unittests/cfdp/testDestHandler.cpp b/unittests/cfdp/testDestHandler.cpp index fb09d595..bb2a5ac4 100644 --- a/unittests/cfdp/testDestHandler.cpp +++ b/unittests/cfdp/testDestHandler.cpp @@ -1,5 +1,3 @@ #include -TEST_CASE("CFDP Dest Handler", "[cfdp]") { - -} \ No newline at end of file +TEST_CASE("CFDP Dest Handler", "[cfdp]") {} \ No newline at end of file diff --git a/unittests/cfdp/testDistributor.cpp b/unittests/cfdp/testDistributor.cpp index ba66f99a..4b8be8fe 100644 --- a/unittests/cfdp/testDistributor.cpp +++ b/unittests/cfdp/testDistributor.cpp @@ -1,5 +1,30 @@ #include -TEST_CASE("CFDP Distributor", "[cfdp][distributor]") { +#include "fsfw/cfdp/CfdpDistributor.h" +#include "fsfw/cfdp/pdu/MetadataPduCreator.h" +#include "fsfw/storagemanager/LocalPool.h" +#include "mocks/AcceptsTcMock.h" +#include "mocks/MessageQueueMock.h" +TEST_CASE("CFDP Distributor", "[cfdp][distributor]") { + LocalPool::LocalPoolConfig cfg = {{5, 32}, {2, 64}}; + LocalPool pool(objects::NO_OBJECT, cfg); + auto queue = MessageQueueMock(1); + CfdpDistribCfg distribCfg(1, pool, &queue); + auto distributor = CfdpDistributor(distribCfg); + auto entityId = cfdp::EntityId(UnsignedByteField(2)); + MessageQueueId_t acceptorQueueId = 3; + auto tcAcceptor = AcceptsTcMock("TC Acceptor", 0, acceptorQueueId); + SECTION("State") { + CHECK(distributor.initialize() == result::OK); + CHECK(std::strcmp(distributor.getName(), "CFDP Distributor") == 0); + CHECK(distributor.getIdentifier() == 0); + CHECK(distributor.getRequestQueue() == queue.getId()); + } + + SECTION("Register Listener") { + CHECK(distributor.initialize() == result::OK); + CHECK(distributor.registerTcDestination(entityId, tcAcceptor)); + // queue.addReceivedMessage() + } } \ No newline at end of file diff --git a/unittests/cfdp/testMetadataPdu.cpp b/unittests/cfdp/testMetadataPdu.cpp index b54d8f79..0992a3c2 100644 --- a/unittests/cfdp/testMetadataPdu.cpp +++ b/unittests/cfdp/testMetadataPdu.cpp @@ -3,8 +3,8 @@ #include #include -#include "fsfw/cfdp/pdu/MetadataPduDeserializer.h" -#include "fsfw/cfdp/pdu/MetadataPduSerializer.h" +#include "fsfw/cfdp/pdu/MetadataPduCreator.h" +#include "fsfw/cfdp/pdu/MetadataPduReader.h" #include "fsfw/cfdp/tlv/FilestoreResponseTlv.h" #include "fsfw/globalfunctions/arrayprinter.h" @@ -39,7 +39,7 @@ TEST_CASE("Metadata PDU", "[cfdp][pdu]") { REQUIRE(options[1]->getSerializedSize() == 5); SECTION("Serialize") { - MetadataPduSerializer serializer(pduConf, info); + MetadataPduCreator serializer(pduConf, info); result = serializer.serialize(&buffer, &sz, mdBuffer.size(), SerializeIF::Endianness::NETWORK); REQUIRE(result == HasReturnvaluesIF::RETURN_OK); REQUIRE(serializer.getWholePduSize() == 27); @@ -72,7 +72,7 @@ TEST_CASE("Metadata PDU", "[cfdp][pdu]") { otherFileName.size()); info.setSourceFileName(otherFileNameLv); size_t sizeOfOptions = options.size(); - info.setOptionsArray(options.data(), &sizeOfOptions, &sizeOfOptions); + info.setOptionsArray(*options.data(), &sizeOfOptions, &sizeOfOptions); REQUIRE(info.getMaxOptionsLen() == 2); info.setMaxOptionsLen(3); REQUIRE(info.getMaxOptionsLen() == 3); @@ -115,22 +115,22 @@ TEST_CASE("Metadata PDU", "[cfdp][pdu]") { } SECTION("Deserialize") { - MetadataPduSerializer serializer(pduConf, info); + MetadataPduCreator serializer(pduConf, info); result = serializer.serialize(&buffer, &sz, mdBuffer.size(), SerializeIF::Endianness::NETWORK); REQUIRE(result == HasReturnvaluesIF::RETURN_OK); - MetadataPduDeserializer deserializer(mdBuffer.data(), mdBuffer.size(), info); + MetadataPduReader deserializer(mdBuffer.data(), mdBuffer.size(), info); result = deserializer.parseData(); REQUIRE(result == HasReturnvaluesIF::RETURN_OK); size_t fullSize = deserializer.getWholePduSize(); for (size_t maxSz = 0; maxSz < fullSize; maxSz++) { - MetadataPduDeserializer invalidSzDeser(mdBuffer.data(), maxSz, info); + MetadataPduReader invalidSzDeser(mdBuffer.data(), maxSz, info); result = invalidSzDeser.parseData(); REQUIRE(result != HasReturnvaluesIF::RETURN_OK); } size_t sizeOfOptions = options.size(); size_t maxSize = 4; - info.setOptionsArray(options.data(), &sizeOfOptions, &maxSize); + info.setOptionsArray(reinterpret_cast(options.data()), &sizeOfOptions, &maxSize); REQUIRE(info.getOptionsLen() == 2); info.setChecksumType(cfdp::ChecksumType::CRC_32C); info.setClosureRequested(true); @@ -142,7 +142,7 @@ TEST_CASE("Metadata PDU", "[cfdp][pdu]") { result = serializer.serialize(&buffer, &sz, mdBuffer.size(), SerializeIF::Endianness::NETWORK); REQUIRE(result == HasReturnvaluesIF::RETURN_OK); - MetadataPduDeserializer deserializer2(mdBuffer.data(), mdBuffer.size(), info); + MetadataPduReader deserializer2(mdBuffer.data(), mdBuffer.size(), info); result = deserializer2.parseData(); REQUIRE(result == HasReturnvaluesIF::RETURN_OK); REQUIRE(options[0]->getType() == cfdp::TlvTypes::FILESTORE_RESPONSE); @@ -169,9 +169,9 @@ TEST_CASE("Metadata PDU", "[cfdp][pdu]") { mdBuffer[2] = 36 & 0xff; info.setOptionsArray(nullptr, nullptr, nullptr); REQUIRE(deserializer2.parseData() == cfdp::METADATA_CANT_PARSE_OPTIONS); - info.setOptionsArray(options.data(), &sizeOfOptions, nullptr); + info.setOptionsArray(reinterpret_cast(options.data()), &sizeOfOptions, nullptr); for (size_t maxSz = 0; maxSz < 46; maxSz++) { - MetadataPduDeserializer invalidSzDeser(mdBuffer.data(), maxSz, info); + MetadataPduReader invalidSzDeser(mdBuffer.data(), maxSz, info); result = invalidSzDeser.parseData(); REQUIRE(result == SerializeIF::STREAM_TOO_SHORT); } diff --git a/unittests/cfdp/testSourceHandler.cpp b/unittests/cfdp/testSourceHandler.cpp index 5738fbba..570ecb08 100644 --- a/unittests/cfdp/testSourceHandler.cpp +++ b/unittests/cfdp/testSourceHandler.cpp @@ -1,5 +1,3 @@ #include -TEST_CASE("CFDP Source Handler", "[cfdp]") { - -} \ No newline at end of file +TEST_CASE("CFDP Source Handler", "[cfdp]") {} \ No newline at end of file From 904abfba28f55d4f2985c81cf8954e92015db321 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Mon, 8 Aug 2022 18:29:32 +0200 Subject: [PATCH 025/169] clean up CFDP stack a bit --- src/fsfw/cfdp/FileSize.h | 12 ++--- src/fsfw/cfdp/pdu/AckPduDeserializer.cpp | 2 +- src/fsfw/cfdp/pdu/EofPduDeserializer.cpp | 2 +- src/fsfw/cfdp/pdu/FileDataReader.cpp | 2 +- src/fsfw/cfdp/pdu/FileDirectiveReader.cpp | 4 +- src/fsfw/cfdp/pdu/FinishedPduDeserializer.cpp | 2 +- src/fsfw/cfdp/pdu/HeaderReader.cpp | 54 ++++++++++--------- src/fsfw/cfdp/pdu/HeaderReader.h | 11 +++- .../cfdp/pdu/KeepAlivePduDeserializer.cpp | 2 +- src/fsfw/cfdp/pdu/MetadataPduReader.cpp | 2 +- src/fsfw/cfdp/pdu/NakPduDeserializer.cpp | 2 +- src/fsfw/cfdp/pdu/PromptPduDeserializer.cpp | 2 +- src/fsfw/cfdp/tlv/Lv.cpp | 7 +++ src/fsfw/cfdp/tlv/Lv.h | 3 +- src/fsfw/storagemanager/LocalPool.h | 2 +- unittests/cfdp/testDistributor.cpp | 28 ++++++++-- unittests/cfdp/testMetadataPdu.cpp | 8 +-- unittests/cfdp/testTlvsLvs.cpp | 4 +- 18 files changed, 96 insertions(+), 53 deletions(-) diff --git a/src/fsfw/cfdp/FileSize.h b/src/fsfw/cfdp/FileSize.h index 6dae9683..521d5a6f 100644 --- a/src/fsfw/cfdp/FileSize.h +++ b/src/fsfw/cfdp/FileSize.h @@ -1,5 +1,5 @@ -#ifndef FSFW_SRC_FSFW_CFDP_FILESIZE_H_ -#define FSFW_SRC_FSFW_CFDP_FILESIZE_H_ +#ifndef FSFW_CFDP_FILESIZE_H_ +#define FSFW_CFDP_FILESIZE_H_ #include "fsfw/serialize/SerializeAdapter.h" #include "fsfw/serialize/SerializeIF.h" @@ -10,7 +10,7 @@ struct FileSize : public SerializeIF { public: FileSize() : largeFile(false){}; - FileSize(uint64_t fileSize, bool isLarge = false) { setFileSize(fileSize, isLarge); }; + explicit FileSize(uint64_t fileSize, bool isLarge = false) { setFileSize(fileSize, isLarge); }; ReturnValue_t serialize(bool isLarge, uint8_t **buffer, size_t *size, size_t maxSize, Endianness streamEndianness) { @@ -27,7 +27,7 @@ struct FileSize : public SerializeIF { return SerializeAdapter::serialize(&fileSize, buffer, size, maxSize, streamEndianness); } - size_t getSerializedSize() const override { + [[nodiscard]] size_t getSerializedSize() const override { if (largeFile) { return 8; } else { @@ -60,7 +60,7 @@ struct FileSize : public SerializeIF { return HasReturnvaluesIF::RETURN_OK; } - bool isLargeFile() const { return largeFile; } + [[nodiscard]] bool isLargeFile() const { return largeFile; } uint64_t getSize(bool *largeFile = nullptr) const { if (largeFile != nullptr) { *largeFile = this->largeFile; @@ -75,4 +75,4 @@ struct FileSize : public SerializeIF { } // namespace cfdp -#endif /* FSFW_SRC_FSFW_CFDP_FILESIZE_H_ */ +#endif /* FSFW_CFDP_FILESIZE_H_ */ diff --git a/src/fsfw/cfdp/pdu/AckPduDeserializer.cpp b/src/fsfw/cfdp/pdu/AckPduDeserializer.cpp index 1217344e..9d7c981d 100644 --- a/src/fsfw/cfdp/pdu/AckPduDeserializer.cpp +++ b/src/fsfw/cfdp/pdu/AckPduDeserializer.cpp @@ -12,7 +12,7 @@ ReturnValue_t AckPduDeserializer::parseData() { if (currentIdx + 2 > this->maxSize) { return SerializeIF::BUFFER_TOO_SHORT; } - if (not checkAndSetCodes(rawPtr[currentIdx], rawPtr[currentIdx + 1])) { + if (not checkAndSetCodes(pointers.rawPtr[currentIdx], pointers.rawPtr[currentIdx + 1])) { return cfdp::INVALID_ACK_DIRECTIVE_FIELDS; } return HasReturnvaluesIF::RETURN_OK; diff --git a/src/fsfw/cfdp/pdu/EofPduDeserializer.cpp b/src/fsfw/cfdp/pdu/EofPduDeserializer.cpp index e532419f..4de67a0e 100644 --- a/src/fsfw/cfdp/pdu/EofPduDeserializer.cpp +++ b/src/fsfw/cfdp/pdu/EofPduDeserializer.cpp @@ -12,7 +12,7 @@ ReturnValue_t EofPduDeserializer::parseData() { return result; } - const uint8_t* bufPtr = rawPtr; + const uint8_t* bufPtr = pointers.rawPtr; size_t expectedFileFieldLen = 4; if (this->getLargeFileFlag()) { expectedFileFieldLen = 8; diff --git a/src/fsfw/cfdp/pdu/FileDataReader.cpp b/src/fsfw/cfdp/pdu/FileDataReader.cpp index 30581da4..e620636f 100644 --- a/src/fsfw/cfdp/pdu/FileDataReader.cpp +++ b/src/fsfw/cfdp/pdu/FileDataReader.cpp @@ -9,7 +9,7 @@ ReturnValue_t FileDataReader::parseData() { return result; } size_t currentIdx = HeaderReader::getHeaderSize(); - const uint8_t* buf = rawPtr + currentIdx; + const uint8_t* buf = pointers.rawPtr + currentIdx; size_t remSize = HeaderReader::getWholePduSize() - currentIdx; if (remSize < 1) { return SerializeIF::STREAM_TOO_SHORT; diff --git a/src/fsfw/cfdp/pdu/FileDirectiveReader.cpp b/src/fsfw/cfdp/pdu/FileDirectiveReader.cpp index d51846b8..bc06a9d7 100644 --- a/src/fsfw/cfdp/pdu/FileDirectiveReader.cpp +++ b/src/fsfw/cfdp/pdu/FileDirectiveReader.cpp @@ -17,10 +17,10 @@ ReturnValue_t FileDirectiveReader::parseData() { return SerializeIF::STREAM_TOO_SHORT; } size_t currentIdx = HeaderReader::getHeaderSize(); - if (not checkFileDirective(rawPtr[currentIdx])) { + if (not checkFileDirective(pointers.rawPtr[currentIdx])) { return cfdp::INVALID_DIRECTIVE_FIELDS; } - setFileDirective(static_cast(rawPtr[currentIdx])); + setFileDirective(static_cast(pointers.rawPtr[currentIdx])); return HasReturnvaluesIF::RETURN_OK; } diff --git a/src/fsfw/cfdp/pdu/FinishedPduDeserializer.cpp b/src/fsfw/cfdp/pdu/FinishedPduDeserializer.cpp index 4209af65..7776778b 100644 --- a/src/fsfw/cfdp/pdu/FinishedPduDeserializer.cpp +++ b/src/fsfw/cfdp/pdu/FinishedPduDeserializer.cpp @@ -10,7 +10,7 @@ ReturnValue_t FinishPduDeserializer::parseData() { return result; } size_t currentIdx = FileDirectiveReader::getHeaderSize(); - const uint8_t* buf = rawPtr + currentIdx; + const uint8_t* buf = pointers.rawPtr + currentIdx; size_t remSize = FileDirectiveReader::getWholePduSize() - currentIdx; if (remSize < 1) { return SerializeIF::STREAM_TOO_SHORT; diff --git a/src/fsfw/cfdp/pdu/HeaderReader.cpp b/src/fsfw/cfdp/pdu/HeaderReader.cpp index cd8667b2..c946ce27 100644 --- a/src/fsfw/cfdp/pdu/HeaderReader.cpp +++ b/src/fsfw/cfdp/pdu/HeaderReader.cpp @@ -4,41 +4,42 @@ #include -HeaderReader::HeaderReader(const uint8_t *pduBuf, size_t maxSize) - : rawPtr(pduBuf), maxSize(maxSize) {} +HeaderReader::HeaderReader(const uint8_t *pduBuf, size_t maxSize) { setData(pduBuf, maxSize); } ReturnValue_t HeaderReader::parseData() { + if (isNull()) { + return HasReturnvaluesIF::RETURN_FAILED; + } if (maxSize < 7) { return SerializeIF::STREAM_TOO_SHORT; } - return setData(const_cast(rawPtr), maxSize); -} - -ReturnValue_t HeaderReader::setData(uint8_t *dataPtr, size_t maxSize_, void *args) { - if (dataPtr == nullptr) { - // Allowed for now - this->fixedHeader = nullptr; - return HasReturnvaluesIF::RETURN_OK; - } - this->fixedHeader = reinterpret_cast(const_cast(dataPtr)); - sourceIdRaw = static_cast(&fixedHeader->variableFieldsStart); + sourceIdRaw = static_cast(&pointers.fixedHeader->variableFieldsStart); cfdp::WidthInBytes widthEntityIds = getLenEntityIds(); cfdp::WidthInBytes widthSeqNum = getLenSeqNum(); seqNumRaw = static_cast(sourceIdRaw) + static_cast(widthEntityIds); destIdRaw = static_cast(seqNumRaw) + static_cast(widthSeqNum); + return HasReturnvaluesIF::RETURN_OK; +} + +ReturnValue_t HeaderReader::setData(uint8_t *dataPtr, size_t maxSize_, void *args) { + if (maxSize_ < 7) { + return SerializeIF::STREAM_TOO_SHORT; + } + pointers.rawPtr = dataPtr; + pointers.fixedHeader = reinterpret_cast(const_cast(dataPtr)); maxSize = maxSize_; return HasReturnvaluesIF::RETURN_OK; } size_t HeaderReader::getHeaderSize() const { - if (fixedHeader != nullptr) { + if (pointers.fixedHeader != nullptr) { return getLenEntityIds() * 2 + getLenSeqNum() + 4; } return 0; } size_t HeaderReader::getPduDataFieldLen() const { - return (fixedHeader->pduDataFieldLenH << 8) | fixedHeader->pduDataFieldLenL; + return (pointers.fixedHeader->pduDataFieldLenH << 8) | pointers.fixedHeader->pduDataFieldLenL; } size_t HeaderReader::getWholePduSize() const { @@ -46,35 +47,35 @@ size_t HeaderReader::getWholePduSize() const { } cfdp::PduType HeaderReader::getPduType() const { - return static_cast((fixedHeader->firstByte >> 4) & 0x01); + return static_cast((pointers.fixedHeader->firstByte >> 4) & 0x01); } cfdp::Direction HeaderReader::getDirection() const { - return static_cast((fixedHeader->firstByte >> 3) & 0x01); + return static_cast((pointers.fixedHeader->firstByte >> 3) & 0x01); } cfdp::TransmissionModes HeaderReader::getTransmissionMode() const { - return static_cast((fixedHeader->firstByte >> 2) & 0x01); + return static_cast((pointers.fixedHeader->firstByte >> 2) & 0x01); } -bool HeaderReader::getCrcFlag() const { return (fixedHeader->firstByte >> 1) & 0x01; } +bool HeaderReader::getCrcFlag() const { return (pointers.fixedHeader->firstByte >> 1) & 0x01; } -bool HeaderReader::getLargeFileFlag() const { return fixedHeader->firstByte & 0x01; } +bool HeaderReader::getLargeFileFlag() const { return pointers.fixedHeader->firstByte & 0x01; } cfdp::SegmentationControl HeaderReader::getSegmentationControl() const { - return static_cast((fixedHeader->fourthByte >> 7) & 0x01); + return static_cast((pointers.fixedHeader->fourthByte >> 7) & 0x01); } cfdp::WidthInBytes HeaderReader::getLenEntityIds() const { - return static_cast((fixedHeader->fourthByte >> 4) & 0x07); + return static_cast((pointers.fixedHeader->fourthByte >> 4) & 0x07); } cfdp::WidthInBytes HeaderReader::getLenSeqNum() const { - return static_cast(fixedHeader->fourthByte & 0x07); + return static_cast(pointers.fixedHeader->fourthByte & 0x07); } cfdp::SegmentMetadataFlag HeaderReader::getSegmentMetadataFlag() const { - return static_cast((fixedHeader->fourthByte >> 3) & 0x01); + return static_cast((pointers.fixedHeader->fourthByte >> 3) & 0x01); } void HeaderReader::getSourceId(cfdp::EntityId &sourceId) const { @@ -129,3 +130,8 @@ bool HeaderReader::hasSegmentMetadataFlag() const { ReturnValue_t HeaderReader::setData(const uint8_t *dataPtr, size_t maxSize_) { return setData(const_cast(dataPtr), maxSize_, nullptr); } +bool HeaderReader::isNull() const { + return pointers.rawPtr == nullptr or pointers.fixedHeader == nullptr; +} + +HeaderReader::operator bool() const { return isNull(); } diff --git a/src/fsfw/cfdp/pdu/HeaderReader.h b/src/fsfw/cfdp/pdu/HeaderReader.h index 67a0470a..a973a12e 100644 --- a/src/fsfw/cfdp/pdu/HeaderReader.h +++ b/src/fsfw/cfdp/pdu/HeaderReader.h @@ -42,6 +42,9 @@ class HeaderReader : public RedirectableDataPointerIF, public PduHeaderIF { * - SerializeIF::BUFFER_TOO_SHORT if buffer is shorter than expected */ virtual ReturnValue_t parseData(); + explicit operator bool() const; + [[nodiscard]] bool isNull() const; + [[nodiscard]] virtual size_t getHeaderSize() const; [[nodiscard]] size_t getPduDataFieldLen() const override; @@ -77,8 +80,12 @@ class HeaderReader : public RedirectableDataPointerIF, public PduHeaderIF { ReturnValue_t setData(const uint8_t* dataPtr, size_t maxSize); protected: - PduHeaderFixedStruct* fixedHeader = nullptr; - const uint8_t* rawPtr = nullptr; + struct Pointers { + PduHeaderFixedStruct* fixedHeader = nullptr; + const uint8_t* rawPtr = nullptr; + }; + + Pointers pointers; size_t maxSize = 0; private: diff --git a/src/fsfw/cfdp/pdu/KeepAlivePduDeserializer.cpp b/src/fsfw/cfdp/pdu/KeepAlivePduDeserializer.cpp index 3acf26a1..0b712fe1 100644 --- a/src/fsfw/cfdp/pdu/KeepAlivePduDeserializer.cpp +++ b/src/fsfw/cfdp/pdu/KeepAlivePduDeserializer.cpp @@ -11,7 +11,7 @@ ReturnValue_t KeepAlivePduDeserializer::parseData() { } size_t currentIdx = FileDirectiveReader::getHeaderSize(); size_t remLen = FileDirectiveReader::getWholePduSize() - currentIdx; - const uint8_t* buffer = rawPtr + currentIdx; + const uint8_t* buffer = pointers.rawPtr + currentIdx; return progress.deSerialize(&buffer, &remLen, getEndianness()); } diff --git a/src/fsfw/cfdp/pdu/MetadataPduReader.cpp b/src/fsfw/cfdp/pdu/MetadataPduReader.cpp index 29dc2e15..a7fc6d78 100644 --- a/src/fsfw/cfdp/pdu/MetadataPduReader.cpp +++ b/src/fsfw/cfdp/pdu/MetadataPduReader.cpp @@ -9,7 +9,7 @@ ReturnValue_t MetadataPduReader::parseData() { return result; } size_t currentIdx = FileDirectiveReader::getHeaderSize(); - const uint8_t* buf = rawPtr + currentIdx; + const uint8_t* buf = pointers.rawPtr + currentIdx; size_t remSize = FileDirectiveReader::getWholePduSize() - currentIdx; if (remSize < 1) { return SerializeIF::STREAM_TOO_SHORT; diff --git a/src/fsfw/cfdp/pdu/NakPduDeserializer.cpp b/src/fsfw/cfdp/pdu/NakPduDeserializer.cpp index a7f23996..089dc612 100644 --- a/src/fsfw/cfdp/pdu/NakPduDeserializer.cpp +++ b/src/fsfw/cfdp/pdu/NakPduDeserializer.cpp @@ -9,7 +9,7 @@ ReturnValue_t NakPduDeserializer::parseData() { return result; } size_t currentIdx = FileDirectiveReader::getHeaderSize(); - const uint8_t* buffer = rawPtr + currentIdx; + const uint8_t* buffer = pointers.rawPtr + currentIdx; size_t remSize = FileDirectiveReader::getWholePduSize() - currentIdx; if (remSize < 1) { return SerializeIF::STREAM_TOO_SHORT; diff --git a/src/fsfw/cfdp/pdu/PromptPduDeserializer.cpp b/src/fsfw/cfdp/pdu/PromptPduDeserializer.cpp index 833c9232..db57664d 100644 --- a/src/fsfw/cfdp/pdu/PromptPduDeserializer.cpp +++ b/src/fsfw/cfdp/pdu/PromptPduDeserializer.cpp @@ -16,6 +16,6 @@ ReturnValue_t PromptPduDeserializer::parseData() { return SerializeIF::STREAM_TOO_SHORT; } responseRequired = static_cast( - (rawPtr[FileDirectiveReader::getHeaderSize()] >> 7) & 0x01); + (pointers.rawPtr[FileDirectiveReader::getHeaderSize()] >> 7) & 0x01); return HasReturnvaluesIF::RETURN_OK; } diff --git a/src/fsfw/cfdp/tlv/Lv.cpp b/src/fsfw/cfdp/tlv/Lv.cpp index 1bb16301..09075094 100644 --- a/src/fsfw/cfdp/tlv/Lv.cpp +++ b/src/fsfw/cfdp/tlv/Lv.cpp @@ -6,6 +6,13 @@ cfdp::Lv::Lv(const uint8_t* value, size_t size) : value(value, size, true) { } } +cfdp::Lv::Lv(const char* value, size_t size) + : value(reinterpret_cast(value), size, true) { + if (size > 0) { + zeroLen = false; + } +} + cfdp::Lv::Lv() : value(static_cast(nullptr), 0, true) {} cfdp::Lv::Lv(const Lv& other) diff --git a/src/fsfw/cfdp/tlv/Lv.h b/src/fsfw/cfdp/tlv/Lv.h index 29764433..4a110f90 100644 --- a/src/fsfw/cfdp/tlv/Lv.h +++ b/src/fsfw/cfdp/tlv/Lv.h @@ -13,6 +13,7 @@ namespace cfdp { class Lv : public SerializeIF { public: Lv(const uint8_t* value, size_t size); + Lv(const char* value, size_t size); Lv(); // Delete copy ctor and assingment ctor for now because this class contains a reference to @@ -23,7 +24,7 @@ class Lv : public SerializeIF { ReturnValue_t serialize(uint8_t** buffer, size_t* size, size_t maxSize, Endianness streamEndianness) const override; - size_t getSerializedSize() const override; + [[nodiscard]] size_t getSerializedSize() const override; /** * @brief Deserialize a LV field from a raw buffer diff --git a/src/fsfw/storagemanager/LocalPool.h b/src/fsfw/storagemanager/LocalPool.h index 1c1d4006..bf7ef92e 100644 --- a/src/fsfw/storagemanager/LocalPool.h +++ b/src/fsfw/storagemanager/LocalPool.h @@ -88,7 +88,7 @@ class LocalPool : public SystemObject, public StorageManagerIF { */ ReturnValue_t addData(store_address_t* storeId, const uint8_t* data, size_t size, bool ignoreFault = false) override; - ReturnValue_t getFreeElement(store_address_t* storeId, const size_t size, uint8_t** pData, + ReturnValue_t getFreeElement(store_address_t* storeId, size_t size, uint8_t** pData, bool ignoreFault = false) override; ConstAccessorPair getData(store_address_t storeId) override; diff --git a/unittests/cfdp/testDistributor.cpp b/unittests/cfdp/testDistributor.cpp index 4b8be8fe..9848bb73 100644 --- a/unittests/cfdp/testDistributor.cpp +++ b/unittests/cfdp/testDistributor.cpp @@ -12,9 +12,24 @@ TEST_CASE("CFDP Distributor", "[cfdp][distributor]") { auto queue = MessageQueueMock(1); CfdpDistribCfg distribCfg(1, pool, &queue); auto distributor = CfdpDistributor(distribCfg); - auto entityId = cfdp::EntityId(UnsignedByteField(2)); + auto obswEntityId = cfdp::EntityId(UnsignedByteField(2)); + auto groundEntityId = cfdp::EntityId(UnsignedByteField(1)); MessageQueueId_t acceptorQueueId = 3; auto tcAcceptor = AcceptsTcMock("TC Acceptor", 0, acceptorQueueId); + cfdp::FileSize fileSize(12); + const cfdp::EntityId& sourceId(groundEntityId); + const cfdp::EntityId& destId(obswEntityId); + cfdp::TransactionSeqNum seqNum(UnsignedByteField(12)); + auto pduConf = PduConfig(sourceId, destId, cfdp::TransmissionModes::UNACKNOWLEDGED, seqNum); + std::string sourceFileString = "hello.txt"; + cfdp::Lv sourceFileName(sourceFileString.c_str(), sourceFileString.size()); + std::string destFileString = "hello2.txt"; + cfdp::Lv destFileName(destFileString.c_str(), sourceFileString.size()); + MetadataInfo metadataInfo(false, cfdp::ChecksumType::CRC_32, fileSize, sourceFileName, + destFileName); + MetadataPduCreator creator(pduConf, metadataInfo); + uint8_t* dataPtr = nullptr; + SECTION("State") { CHECK(distributor.initialize() == result::OK); CHECK(std::strcmp(distributor.getName(), "CFDP Distributor") == 0); @@ -24,7 +39,14 @@ TEST_CASE("CFDP Distributor", "[cfdp][distributor]") { SECTION("Register Listener") { CHECK(distributor.initialize() == result::OK); - CHECK(distributor.registerTcDestination(entityId, tcAcceptor)); - // queue.addReceivedMessage() + CHECK(distributor.registerTcDestination(obswEntityId, tcAcceptor) == result::OK); + size_t serLen = 0; + store_address_t storeId; + CHECK(pool.getFreeElement(&storeId, creator.getSerializedSize(), &dataPtr) == result::OK); + REQUIRE(creator.SerializeIF::serializeBe(dataPtr, serLen, creator.getSerializedSize()) == + result::OK); + TmTcMessage msg(storeId); + queue.addReceivedMessage(msg); + CHECK(distributor.performOperation(0) == result::OK); } } \ No newline at end of file diff --git a/unittests/cfdp/testMetadataPdu.cpp b/unittests/cfdp/testMetadataPdu.cpp index 0992a3c2..19586604 100644 --- a/unittests/cfdp/testMetadataPdu.cpp +++ b/unittests/cfdp/testMetadataPdu.cpp @@ -22,7 +22,7 @@ TEST_CASE("Metadata PDU", "[cfdp][pdu]") { std::string firstFileName = "hello.txt"; cfdp::Lv sourceFileName(reinterpret_cast(firstFileName.data()), firstFileName.size()); - cfdp::Lv destFileName(nullptr, 0); + cfdp::Lv destFileName; FileSize fileSize(35); MetadataInfo info(false, ChecksumType::MODULAR, fileSize, sourceFileName, destFileName); @@ -72,7 +72,7 @@ TEST_CASE("Metadata PDU", "[cfdp][pdu]") { otherFileName.size()); info.setSourceFileName(otherFileNameLv); size_t sizeOfOptions = options.size(); - info.setOptionsArray(*options.data(), &sizeOfOptions, &sizeOfOptions); + info.setOptionsArray(options.data(), &sizeOfOptions, &sizeOfOptions); REQUIRE(info.getMaxOptionsLen() == 2); info.setMaxOptionsLen(3); REQUIRE(info.getMaxOptionsLen() == 3); @@ -130,7 +130,7 @@ TEST_CASE("Metadata PDU", "[cfdp][pdu]") { } size_t sizeOfOptions = options.size(); size_t maxSize = 4; - info.setOptionsArray(reinterpret_cast(options.data()), &sizeOfOptions, &maxSize); + info.setOptionsArray(options.data(), &sizeOfOptions, &maxSize); REQUIRE(info.getOptionsLen() == 2); info.setChecksumType(cfdp::ChecksumType::CRC_32C); info.setClosureRequested(true); @@ -169,7 +169,7 @@ TEST_CASE("Metadata PDU", "[cfdp][pdu]") { mdBuffer[2] = 36 & 0xff; info.setOptionsArray(nullptr, nullptr, nullptr); REQUIRE(deserializer2.parseData() == cfdp::METADATA_CANT_PARSE_OPTIONS); - info.setOptionsArray(reinterpret_cast(options.data()), &sizeOfOptions, nullptr); + info.setOptionsArray(options.data(), &sizeOfOptions, nullptr); for (size_t maxSz = 0; maxSz < 46; maxSz++) { MetadataPduReader invalidSzDeser(mdBuffer.data(), maxSz, info); result = invalidSzDeser.parseData(); diff --git a/unittests/cfdp/testTlvsLvs.cpp b/unittests/cfdp/testTlvsLvs.cpp index e311b5d6..acee9cce 100644 --- a/unittests/cfdp/testTlvsLvs.cpp +++ b/unittests/cfdp/testTlvsLvs.cpp @@ -158,7 +158,7 @@ TEST_CASE("CFDP TLV LV", "[cfdp]") { SerializeIF::Endianness::BIG); REQUIRE(sourceIdRaw == 0x0ff0); - auto lvEmpty = Lv(nullptr, 0); + auto lvEmpty = Lv(); REQUIRE(lvEmpty.getSerializedSize() == 1); serPtr = rawBuf.data(); deserSize = 0; @@ -191,7 +191,7 @@ TEST_CASE("CFDP TLV LV", "[cfdp]") { SerializeIF::Endianness::BIG); REQUIRE(sourceIdRaw == 0x0ff0); - auto lvEmpty = Lv(nullptr, 0); + auto lvEmpty = Lv(); REQUIRE(lvEmpty.getSerializedSize() == 1); serPtr = rawBuf.data(); deserSize = 0; From 4f1fe39182b34d48b964926989843da6dff35dda Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Mon, 8 Aug 2022 18:36:10 +0200 Subject: [PATCH 026/169] fix unittests --- unittests/cfdp/testKeepAlivePdu.cpp | 8 +++++--- unittests/cfdp/testMetadataPdu.cpp | 7 +++++-- unittests/cfdp/testPromptPdu.cpp | 8 +++++--- 3 files changed, 15 insertions(+), 8 deletions(-) diff --git a/unittests/cfdp/testKeepAlivePdu.cpp b/unittests/cfdp/testKeepAlivePdu.cpp index 876b71f6..127d8a8c 100644 --- a/unittests/cfdp/testKeepAlivePdu.cpp +++ b/unittests/cfdp/testKeepAlivePdu.cpp @@ -71,9 +71,11 @@ TEST_CASE("Keep Alive PDU", "[cfdp][pdu]") { // invalid max size for (size_t invalidMaxSz = 0; invalidMaxSz < sz; invalidMaxSz++) { - deserializer.setData(kaBuffer.data(), invalidMaxSz); - result = deserializer.parseData(); - REQUIRE(result != HasReturnvaluesIF::RETURN_OK); + ReturnValue_t setResult = deserializer.setData(kaBuffer.data(), invalidMaxSz); + if (setResult == HasReturnvaluesIF::RETURN_OK) { + result = deserializer.parseData(); + REQUIRE(result != HasReturnvaluesIF::RETURN_OK); + } } } } diff --git a/unittests/cfdp/testMetadataPdu.cpp b/unittests/cfdp/testMetadataPdu.cpp index 19586604..4ea15451 100644 --- a/unittests/cfdp/testMetadataPdu.cpp +++ b/unittests/cfdp/testMetadataPdu.cpp @@ -2,6 +2,7 @@ #include #include +#include #include "fsfw/cfdp/pdu/MetadataPduCreator.h" #include "fsfw/cfdp/pdu/MetadataPduReader.h" @@ -172,8 +173,10 @@ TEST_CASE("Metadata PDU", "[cfdp][pdu]") { info.setOptionsArray(options.data(), &sizeOfOptions, nullptr); for (size_t maxSz = 0; maxSz < 46; maxSz++) { MetadataPduReader invalidSzDeser(mdBuffer.data(), maxSz, info); - result = invalidSzDeser.parseData(); - REQUIRE(result == SerializeIF::STREAM_TOO_SHORT); + if (not invalidSzDeser.isNull()) { + result = invalidSzDeser.parseData(); + REQUIRE(result == SerializeIF::STREAM_TOO_SHORT); + } } } } diff --git a/unittests/cfdp/testPromptPdu.cpp b/unittests/cfdp/testPromptPdu.cpp index 868f7140..93cb9a5d 100644 --- a/unittests/cfdp/testPromptPdu.cpp +++ b/unittests/cfdp/testPromptPdu.cpp @@ -59,9 +59,11 @@ TEST_CASE("Prompt PDU", "[cfdp][pdu]") { rawBuf[2] = 2; for (size_t invalidMaxSz = 0; invalidMaxSz < sz; invalidMaxSz++) { - deserializer.setData(rawBuf.data(), invalidMaxSz); - result = deserializer.parseData(); - REQUIRE(result != HasReturnvaluesIF::RETURN_OK); + ReturnValue_t setResult = deserializer.setData(rawBuf.data(), invalidMaxSz); + if (setResult == result::OK) { + result = deserializer.parseData(); + REQUIRE(result != HasReturnvaluesIF::RETURN_OK); + } } } } From 06bea2f621def14c75bfcda436d496cd6701360a Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Tue, 9 Aug 2022 10:59:24 +0200 Subject: [PATCH 027/169] test inNull and bool operator --- src/fsfw/cfdp/pdu/HeaderReader.cpp | 2 +- unittests/cfdp/testFileDirective.cpp | 26 ++++++++++++++++++-------- 2 files changed, 19 insertions(+), 9 deletions(-) diff --git a/src/fsfw/cfdp/pdu/HeaderReader.cpp b/src/fsfw/cfdp/pdu/HeaderReader.cpp index c946ce27..06a40347 100644 --- a/src/fsfw/cfdp/pdu/HeaderReader.cpp +++ b/src/fsfw/cfdp/pdu/HeaderReader.cpp @@ -134,4 +134,4 @@ bool HeaderReader::isNull() const { return pointers.rawPtr == nullptr or pointers.fixedHeader == nullptr; } -HeaderReader::operator bool() const { return isNull(); } +HeaderReader::operator bool() const { return not isNull(); } diff --git a/unittests/cfdp/testFileDirective.cpp b/unittests/cfdp/testFileDirective.cpp index 3a4818ec..d7c35456 100644 --- a/unittests/cfdp/testFileDirective.cpp +++ b/unittests/cfdp/testFileDirective.cpp @@ -16,9 +16,9 @@ TEST_CASE("CFDP File Directive", "[cfdp]") { uint8_t* serTarget = serBuf.data(); const uint8_t* deserTarget = serTarget; size_t serSize = 0; + auto fdSer = FileDirectiveCreator(pduConf, FileDirectives::ACK, 4); - SECTION("File Directive") { - auto fdSer = FileDirectiveCreator(pduConf, FileDirectives::ACK, 4); + SECTION("Serialization") { REQUIRE(fdSer.getSerializedSize() == 8); serTarget = serBuf.data(); serSize = 0; @@ -38,24 +38,34 @@ TEST_CASE("CFDP File Directive", "[cfdp]") { // Dest ID REQUIRE(serBuf[6] == 1); REQUIRE(serBuf[7] == FileDirectives::ACK); + } - serTarget = serBuf.data(); - size_t deserSize = 20; - serSize = 0; - REQUIRE(fdSer.deSerialize(&deserTarget, &deserSize, SerializeIF::Endianness::NETWORK) == - HasReturnvaluesIF::RETURN_FAILED); + SECTION("Serialization fails") { REQUIRE(fdSer.serialize(nullptr, nullptr, 85, SerializeIF::Endianness::NETWORK) == HasReturnvaluesIF::RETURN_FAILED); + } + + SECTION("Buffer Too Short") { for (uint8_t idx = 0; idx < 8; idx++) { serTarget = serBuf.data(); serSize = 0; REQUIRE(fdSer.serialize(&serTarget, &serSize, idx, SerializeIF::Endianness::NETWORK) == SerializeIF::BUFFER_TOO_SHORT); } + } + SECTION("Deserialize") { + CHECK(fdSer.serialize(&serTarget, &serSize, serBuf.size(), SerializeIF::Endianness::NETWORK) == + result::OK); + serTarget = serBuf.data(); + + REQUIRE(fdSer.deSerialize(&deserTarget, &serSize, SerializeIF::Endianness::NETWORK) == + HasReturnvaluesIF::RETURN_FAILED); deserTarget = serBuf.data(); - deserSize = 0; + CHECK(serSize == 8); auto fdDeser = FileDirectiveReader(deserTarget, serBuf.size()); + REQUIRE(not fdDeser.isNull()); + REQUIRE(fdDeser); REQUIRE(fdDeser.getEndianness() == SerializeIF::Endianness::NETWORK); fdDeser.setEndianness(SerializeIF::Endianness::MACHINE); REQUIRE(fdDeser.getEndianness() == SerializeIF::Endianness::MACHINE); From 2f8020baacf8c146271b549bae48e275eb45507b Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Tue, 9 Aug 2022 11:03:22 +0200 Subject: [PATCH 028/169] move parsing steps into parse function --- src/fsfw/cfdp/pdu/HeaderReader.cpp | 8 ++++++-- unittests/cfdp/testCfdpHeader.cpp | 4 ++-- unittests/cfdp/testFileDirective.cpp | 6 ++++-- 3 files changed, 12 insertions(+), 6 deletions(-) diff --git a/src/fsfw/cfdp/pdu/HeaderReader.cpp b/src/fsfw/cfdp/pdu/HeaderReader.cpp index 06a40347..1fd40b78 100644 --- a/src/fsfw/cfdp/pdu/HeaderReader.cpp +++ b/src/fsfw/cfdp/pdu/HeaderReader.cpp @@ -7,12 +7,14 @@ HeaderReader::HeaderReader(const uint8_t *pduBuf, size_t maxSize) { setData(pduBuf, maxSize); } ReturnValue_t HeaderReader::parseData() { - if (isNull()) { + if (pointers.rawPtr == nullptr) { return HasReturnvaluesIF::RETURN_FAILED; } if (maxSize < 7) { return SerializeIF::STREAM_TOO_SHORT; } + pointers.fixedHeader = + reinterpret_cast(const_cast(pointers.rawPtr)); sourceIdRaw = static_cast(&pointers.fixedHeader->variableFieldsStart); cfdp::WidthInBytes widthEntityIds = getLenEntityIds(); cfdp::WidthInBytes widthSeqNum = getLenSeqNum(); @@ -22,11 +24,13 @@ ReturnValue_t HeaderReader::parseData() { } ReturnValue_t HeaderReader::setData(uint8_t *dataPtr, size_t maxSize_, void *args) { + if (dataPtr == nullptr) { + return HasReturnvaluesIF::RETURN_FAILED; + } if (maxSize_ < 7) { return SerializeIF::STREAM_TOO_SHORT; } pointers.rawPtr = dataPtr; - pointers.fixedHeader = reinterpret_cast(const_cast(dataPtr)); maxSize = maxSize_; return HasReturnvaluesIF::RETURN_OK; } diff --git a/unittests/cfdp/testCfdpHeader.cpp b/unittests/cfdp/testCfdpHeader.cpp index 6453b809..0b131669 100644 --- a/unittests/cfdp/testCfdpHeader.cpp +++ b/unittests/cfdp/testCfdpHeader.cpp @@ -268,8 +268,8 @@ TEST_CASE("CFDP Header", "[cfdp]") { result = headerDeser.parseData(); REQUIRE(result == result::OK); - headerDeser.setData(nullptr, -1); - REQUIRE(headerDeser.getHeaderSize() == 0); + CHECK(headerDeser.setData(nullptr, -1) != result::OK); + REQUIRE(headerDeser.getHeaderSize() == 14); headerDeser.setData(serBuf.data(), serBuf.size()); serTarget = serBuf.data(); diff --git a/unittests/cfdp/testFileDirective.cpp b/unittests/cfdp/testFileDirective.cpp index d7c35456..b694cd68 100644 --- a/unittests/cfdp/testFileDirective.cpp +++ b/unittests/cfdp/testFileDirective.cpp @@ -64,13 +64,15 @@ TEST_CASE("CFDP File Directive", "[cfdp]") { deserTarget = serBuf.data(); CHECK(serSize == 8); auto fdDeser = FileDirectiveReader(deserTarget, serBuf.size()); - REQUIRE(not fdDeser.isNull()); - REQUIRE(fdDeser); + REQUIRE(fdDeser.isNull()); + REQUIRE(not fdDeser); REQUIRE(fdDeser.getEndianness() == SerializeIF::Endianness::NETWORK); fdDeser.setEndianness(SerializeIF::Endianness::MACHINE); REQUIRE(fdDeser.getEndianness() == SerializeIF::Endianness::MACHINE); fdDeser.setEndianness(SerializeIF::Endianness::NETWORK); REQUIRE(fdDeser.parseData() == HasReturnvaluesIF::RETURN_OK); + REQUIRE(not fdDeser.isNull()); + REQUIRE(fdDeser); REQUIRE(fdDeser.getFileDirective() == FileDirectives::ACK); REQUIRE(fdDeser.getPduDataFieldLen() == 5); REQUIRE(fdDeser.getHeaderSize() == 8); From c832bffdb0d6e69638c57671f1558b640a63ea95 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Tue, 9 Aug 2022 11:17:57 +0200 Subject: [PATCH 029/169] clean up header test --- unittests/cfdp/testCfdpHeader.cpp | 221 +++++++++++++++++------------- 1 file changed, 124 insertions(+), 97 deletions(-) diff --git a/unittests/cfdp/testCfdpHeader.cpp b/unittests/cfdp/testCfdpHeader.cpp index 0b131669..a01325fa 100644 --- a/unittests/cfdp/testCfdpHeader.cpp +++ b/unittests/cfdp/testCfdpHeader.cpp @@ -17,18 +17,10 @@ TEST_CASE("CFDP Header", "[cfdp]") { uint8_t* serTarget = serBuf.data(); const uint8_t* deserTarget = serTarget; size_t serSize = 0; + auto headerSerializer = HeaderCreator(pduConf, cfdp::PduType::FILE_DIRECTIVE, 0); - SECTION("Header Serialization") { - auto headerSerializer = HeaderCreator(pduConf, cfdp::PduType::FILE_DIRECTIVE, 0); - const uint8_t** dummyPtr = nullptr; - ReturnValue_t deserResult = - headerSerializer.deSerialize(dummyPtr, &serSize, SerializeIF::Endianness::NETWORK); - REQUIRE(deserResult == result::FAILED); - deserResult = headerSerializer.serialize(nullptr, &serSize, serBuf.size(), - SerializeIF::Endianness::NETWORK); - REQUIRE(deserResult == result::FAILED); + SECTION("Header State") { REQUIRE(seqNum.getSerializedSize() == 1); - REQUIRE(headerSerializer.getPduDataFieldLen() == 0); REQUIRE(headerSerializer.getSerializedSize() == 7); REQUIRE(headerSerializer.getWholePduSize() == 7); @@ -41,7 +33,6 @@ TEST_CASE("CFDP Header", "[cfdp]") { REQUIRE(headerSerializer.getSegmentMetadataFlag() == cfdp::SegmentMetadataFlag::NOT_PRESENT); REQUIRE(headerSerializer.getSegmentationControl() == false); REQUIRE(headerSerializer.getTransmissionMode() == cfdp::TransmissionModes::ACKNOWLEDGED); - cfdp::TransactionSeqNum seqNumLocal; headerSerializer.getTransactionSeqNum(seqNumLocal); REQUIRE(seqNumLocal.getWidth() == cfdp::WidthInBytes::ONE_BYTE); @@ -53,7 +44,127 @@ TEST_CASE("CFDP Header", "[cfdp]") { headerSerializer.getDestId(sourceDestId); REQUIRE(sourceDestId.getWidth() == cfdp::WidthInBytes::ONE_BYTE); REQUIRE(sourceDestId.getValue() == 1); + } + SECTION("Deserialization fails") { + const uint8_t** dummyPtr = nullptr; + REQUIRE(headerSerializer.deSerialize(dummyPtr, &serSize, SerializeIF::Endianness::NETWORK) == + result::FAILED); + } + + SECTION("Serialization fails") { + REQUIRE(headerSerializer.serialize(nullptr, &serSize, serBuf.size(), + SerializeIF::Endianness::NETWORK) == result::FAILED); + } + + SECTION("Buffer Too Short") { + for (uint8_t idx = 0; idx < 7; idx++) { + result = headerSerializer.serialize(&serTarget, &serSize, idx, SerializeIF::Endianness::BIG); + REQUIRE(result == static_cast(SerializeIF::BUFFER_TOO_SHORT)); + } + } + + SECTION("Set Data Field Len") { + // Set PDU data field len + headerSerializer.setPduDataFieldLen(0x0ff0); + REQUIRE(headerSerializer.getPduDataFieldLen() == 0x0ff0); + REQUIRE(headerSerializer.getSerializedSize() == 7); + REQUIRE(headerSerializer.getWholePduSize() == 7 + 0x0ff0); + serTarget = serBuf.data(); + serSize = 0; + result = headerSerializer.serialize(&serTarget, &serSize, serBuf.size(), + SerializeIF::Endianness::BIG); + REQUIRE(serBuf[1] == 0x0f); + REQUIRE(serBuf[2] == 0xf0); + } + + SECTION("Serialize with Fields Flipped") { + pduConf.crcFlag = true; + pduConf.largeFile = true; + pduConf.direction = cfdp::Direction::TOWARDS_SENDER; + pduConf.mode = cfdp::TransmissionModes::UNACKNOWLEDGED; + headerSerializer.setSegmentationControl( + cfdp::SegmentationControl::RECORD_BOUNDARIES_PRESERVATION); + headerSerializer.setPduType(cfdp::PduType::FILE_DATA); + headerSerializer.setSegmentMetadataFlag(cfdp::SegmentMetadataFlag::PRESENT); + serTarget = serBuf.data(); + serSize = 0; + + SECTION("Regular") { + // Everything except version bit flipped to one now + REQUIRE(headerSerializer.serialize(&serTarget, &serSize, serBuf.size(), + SerializeIF::Endianness::BIG) == result::OK); + CHECK(serBuf[0] == 0x3f); + CHECK(serBuf[3] == 0x99); + REQUIRE(headerSerializer.getCrcFlag() == true); + REQUIRE(headerSerializer.getDirection() == cfdp::Direction::TOWARDS_SENDER); + REQUIRE(headerSerializer.getLargeFileFlag() == true); + REQUIRE(headerSerializer.getLenEntityIds() == 1); + REQUIRE(headerSerializer.getLenSeqNum() == 1); + REQUIRE(headerSerializer.getPduType() == cfdp::PduType::FILE_DATA); + REQUIRE(headerSerializer.getSegmentMetadataFlag() == cfdp::SegmentMetadataFlag::PRESENT); + REQUIRE(headerSerializer.getTransmissionMode() == cfdp::TransmissionModes::UNACKNOWLEDGED); + REQUIRE(headerSerializer.getSegmentationControl() == true); + } + + SECTION("Other variable sized fields") { + pduConf.seqNum.setValue(cfdp::WidthInBytes::TWO_BYTES, 0x0fff); + pduConf.sourceId.setValue(cfdp::WidthInBytes::FOUR_BYTES, 0xff00ff00); + pduConf.destId.setValue(cfdp::WidthInBytes::FOUR_BYTES, 0x00ff00ff); + REQUIRE(pduConf.sourceId.getSerializedSize() == 4); + REQUIRE(headerSerializer.getSerializedSize() == 14); + REQUIRE(headerSerializer.serialize(&serTarget, &serSize, serBuf.size(), + SerializeIF::Endianness::BIG) == result::OK); + REQUIRE(headerSerializer.getCrcFlag() == true); + REQUIRE(headerSerializer.getDirection() == cfdp::Direction::TOWARDS_SENDER); + REQUIRE(headerSerializer.getLargeFileFlag() == true); + REQUIRE(headerSerializer.getLenEntityIds() == 4); + REQUIRE(headerSerializer.getLenSeqNum() == 2); + REQUIRE(headerSerializer.getPduType() == cfdp::PduType::FILE_DATA); + REQUIRE(headerSerializer.getSegmentMetadataFlag() == cfdp::SegmentMetadataFlag::PRESENT); + REQUIRE(headerSerializer.getTransmissionMode() == cfdp::TransmissionModes::UNACKNOWLEDGED); + REQUIRE(headerSerializer.getSegmentationControl() == true); + // Last three bits are 2 now (length of seq number) and bit 1 to bit 3 is 4 (len entity IDs) + REQUIRE(serBuf[3] == 0b11001010); + uint32_t entityId = 0; + size_t deSerSize = 0; + SerializeAdapter::deSerialize(&entityId, serBuf.data() + 4, &deSerSize, + SerializeIF::Endianness::NETWORK); + CHECK(deSerSize == 4); + CHECK(entityId == 0xff00ff00); + uint16_t seqNumRaw = 0; + SerializeAdapter::deSerialize(&seqNumRaw, serBuf.data() + 8, &deSerSize, + SerializeIF::Endianness::NETWORK); + CHECK(deSerSize == 2); + CHECK(seqNumRaw == 0x0fff); + SerializeAdapter::deSerialize(&entityId, serBuf.data() + 10, &deSerSize, + SerializeIF::Endianness::NETWORK); + CHECK(deSerSize == 4); + CHECK(entityId == 0x00ff00ff); + } + + SECTION("Buffer Too Short") { + pduConf.seqNum.setValue(cfdp::WidthInBytes::TWO_BYTES, 0x0fff); + pduConf.sourceId.setValue(cfdp::WidthInBytes::FOUR_BYTES, 0xff00ff00); + pduConf.destId.setValue(cfdp::WidthInBytes::FOUR_BYTES, 0x00ff00ff); + for (uint8_t idx = 0; idx < 14; idx++) { + REQUIRE( + headerSerializer.serialize(&serTarget, &serSize, idx, SerializeIF::Endianness::BIG) == + SerializeIF::BUFFER_TOO_SHORT); + } + } + } + + SECTION("Invalid Variable Sized Fields") { + result = pduConf.sourceId.setValue(cfdp::WidthInBytes::ONE_BYTE, 0xfff); + REQUIRE(result == result::FAILED); + result = pduConf.sourceId.setValue(cfdp::WidthInBytes::TWO_BYTES, 0xfffff); + REQUIRE(result == result::FAILED); + result = pduConf.sourceId.setValue(cfdp::WidthInBytes::FOUR_BYTES, 0xfffffffff); + REQUIRE(result == result::FAILED); + } + + SECTION("Header Serialization") { result = headerSerializer.serialize(&serTarget, &serSize, serBuf.size(), SerializeIF::Endianness::BIG); REQUIRE(result == result::OK); @@ -72,86 +183,6 @@ TEST_CASE("CFDP Header", "[cfdp]") { // Dest ID REQUIRE(serBuf[6] == 1); - for (uint8_t idx = 0; idx < 7; idx++) { - result = headerSerializer.serialize(&serTarget, &serSize, idx, SerializeIF::Endianness::BIG); - REQUIRE(result == static_cast(SerializeIF::BUFFER_TOO_SHORT)); - } - - // Set PDU data field len - headerSerializer.setPduDataFieldLen(0x0ff0); - REQUIRE(headerSerializer.getPduDataFieldLen() == 0x0ff0); - REQUIRE(headerSerializer.getSerializedSize() == 7); - REQUIRE(headerSerializer.getWholePduSize() == 7 + 0x0ff0); - serTarget = serBuf.data(); - serSize = 0; - result = headerSerializer.serialize(&serTarget, &serSize, serBuf.size(), - SerializeIF::Endianness::BIG); - REQUIRE(serBuf[1] == 0x0f); - REQUIRE(serBuf[2] == 0xf0); - - pduConf.crcFlag = true; - pduConf.largeFile = true; - pduConf.direction = cfdp::Direction::TOWARDS_SENDER; - pduConf.mode = cfdp::TransmissionModes::UNACKNOWLEDGED; - headerSerializer.setSegmentationControl( - cfdp::SegmentationControl::RECORD_BOUNDARIES_PRESERVATION); - headerSerializer.setPduType(cfdp::PduType::FILE_DATA); - headerSerializer.setSegmentMetadataFlag(cfdp::SegmentMetadataFlag::PRESENT); - serTarget = serBuf.data(); - serSize = 0; - result = headerSerializer.serialize(&serTarget, &serSize, serBuf.size(), - SerializeIF::Endianness::BIG); - - // Everything except version bit flipped to one now - REQUIRE(serBuf[0] == 0x3f); - REQUIRE(serBuf[3] == 0x99); - pduConf.seqNum.setValue(cfdp::WidthInBytes::TWO_BYTES, 0x0fff); - pduConf.sourceId.setValue(cfdp::WidthInBytes::FOUR_BYTES, 0xff00ff00); - pduConf.destId.setValue(cfdp::WidthInBytes::FOUR_BYTES, 0x00ff00ff); - REQUIRE(pduConf.sourceId.getSerializedSize() == 4); - REQUIRE(headerSerializer.getSerializedSize() == 14); - serTarget = serBuf.data(); - serSize = 0; - result = headerSerializer.serialize(&serTarget, &serSize, serBuf.size(), - SerializeIF::Endianness::BIG); - - for (uint8_t idx = 0; idx < 14; idx++) { - result = headerSerializer.serialize(&serTarget, &serSize, idx, SerializeIF::Endianness::BIG); - REQUIRE(result == static_cast(SerializeIF::BUFFER_TOO_SHORT)); - } - REQUIRE(headerSerializer.getCrcFlag() == true); - REQUIRE(headerSerializer.getDirection() == cfdp::Direction::TOWARDS_SENDER); - REQUIRE(headerSerializer.getLargeFileFlag() == true); - REQUIRE(headerSerializer.getLenEntityIds() == 4); - REQUIRE(headerSerializer.getLenSeqNum() == 2); - REQUIRE(headerSerializer.getPduType() == cfdp::PduType::FILE_DATA); - REQUIRE(headerSerializer.getSegmentMetadataFlag() == cfdp::SegmentMetadataFlag::PRESENT); - REQUIRE(headerSerializer.getTransmissionMode() == cfdp::TransmissionModes::UNACKNOWLEDGED); - REQUIRE(headerSerializer.getSegmentationControl() == true); - // Last three bits are 2 now (length of seq number) and bit 1 to bit 3 is 4 (len entity IDs) - REQUIRE(serBuf[3] == 0b11001010); - uint32_t entityId = 0; - size_t deSerSize = 0; - SerializeAdapter::deSerialize(&entityId, serBuf.data() + 4, &deSerSize, - SerializeIF::Endianness::NETWORK); - REQUIRE(deSerSize == 4); - REQUIRE(entityId == 0xff00ff00); - uint16_t seqNumRaw = 0; - SerializeAdapter::deSerialize(&seqNumRaw, serBuf.data() + 8, &deSerSize, - SerializeIF::Endianness::NETWORK); - REQUIRE(deSerSize == 2); - REQUIRE(seqNumRaw == 0x0fff); - SerializeAdapter::deSerialize(&entityId, serBuf.data() + 10, &deSerSize, - SerializeIF::Endianness::NETWORK); - REQUIRE(deSerSize == 4); - REQUIRE(entityId == 0x00ff00ff); - - result = pduConf.sourceId.setValue(cfdp::WidthInBytes::ONE_BYTE, 0xfff); - REQUIRE(result == result::FAILED); - result = pduConf.sourceId.setValue(cfdp::WidthInBytes::TWO_BYTES, 0xfffff); - REQUIRE(result == result::FAILED); - result = pduConf.sourceId.setValue(cfdp::WidthInBytes::FOUR_BYTES, 0xfffffffff); - REQUIRE(result == result::FAILED); uint8_t oneByteSourceId = 32; serTarget = &oneByteSourceId; size_t deserLen = 1; @@ -184,12 +215,8 @@ TEST_CASE("CFDP Header", "[cfdp]") { } SECTION("Header Deserialization") { - // We unittested the serializer before, so we can use it now to generate valid raw CFDP - // data - auto headerSerializer = HeaderCreator(pduConf, cfdp::PduType::FILE_DIRECTIVE, 0); - result = headerSerializer.serialize(&serTarget, &serSize, serBuf.size(), - SerializeIF::Endianness::BIG); - REQUIRE(result == result::OK); + REQUIRE(headerSerializer.serialize(&serTarget, &serSize, serBuf.size(), + SerializeIF::Endianness::BIG) == result::OK); REQUIRE(serBuf[1] == 0); REQUIRE(serBuf[2] == 0); // Entity and Transaction Sequence number are 1 byte large From 1c0b77884864c5c09e6dd1da19602c719a3762b4 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Tue, 9 Aug 2022 12:13:10 +0200 Subject: [PATCH 030/169] continue CFDP distrib unittests --- unittests/cfdp/testDistributor.cpp | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/unittests/cfdp/testDistributor.cpp b/unittests/cfdp/testDistributor.cpp index 9848bb73..9eb3838c 100644 --- a/unittests/cfdp/testDistributor.cpp +++ b/unittests/cfdp/testDistributor.cpp @@ -14,8 +14,8 @@ TEST_CASE("CFDP Distributor", "[cfdp][distributor]") { auto distributor = CfdpDistributor(distribCfg); auto obswEntityId = cfdp::EntityId(UnsignedByteField(2)); auto groundEntityId = cfdp::EntityId(UnsignedByteField(1)); - MessageQueueId_t acceptorQueueId = 3; - auto tcAcceptor = AcceptsTcMock("TC Acceptor", 0, acceptorQueueId); + MessageQueueId_t receiverQueueId = 3; + auto tcAcceptor = AcceptsTcMock("CFDP Receiver", 0, receiverQueueId); cfdp::FileSize fileSize(12); const cfdp::EntityId& sourceId(groundEntityId); const cfdp::EntityId& destId(obswEntityId); @@ -48,5 +48,12 @@ TEST_CASE("CFDP Distributor", "[cfdp][distributor]") { TmTcMessage msg(storeId); queue.addReceivedMessage(msg); CHECK(distributor.performOperation(0) == result::OK); + CHECK(queue.wasMessageSent()); + CHECK(queue.numberOfSentMessages() == 1); + // The packet is forwarded, with no need to delete the data + CHECK(pool.hasDataAtId(storeId)); + TmTcMessage sentMsg; + CHECK(queue.getNextSentMessage(receiverQueueId, sentMsg) == result::OK); + CHECK(sentMsg.getStorageId() == storeId); } } \ No newline at end of file From bddf5bded1f3ff400b7cfa457515948ff8e37a92 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Tue, 9 Aug 2022 12:36:29 +0200 Subject: [PATCH 031/169] move some storage manager impl to IF - Add StorageManagerMock --- src/fsfw/cfdp/CfdpDistributor.cpp | 2 +- src/fsfw/returnvalues/FwClassIds.h | 2 +- .../storagemanager/ConstStorageAccessor.cpp | 8 +-- .../storagemanager/ConstStorageAccessor.h | 13 +++-- src/fsfw/storagemanager/LocalPool.cpp | 58 +++++++++---------- src/fsfw/storagemanager/LocalPool.h | 22 +++---- src/fsfw/storagemanager/StorageAccessor.cpp | 4 +- src/fsfw/storagemanager/StorageAccessor.h | 7 ++- src/fsfw/storagemanager/StorageManagerIF.h | 53 +++++++++++++---- src/fsfw/tcdistribution/definitions.h | 13 +++-- unittests/cfdp/testDistributor.cpp | 2 +- unittests/mocks/CMakeLists.txt | 3 +- unittests/mocks/StorageManagerMock.cpp | 32 ++++++++++ unittests/mocks/StorageManagerMock.h | 24 ++++++++ unittests/storagemanager/testAccessor.cpp | 48 +++++++-------- 15 files changed, 190 insertions(+), 101 deletions(-) create mode 100644 unittests/mocks/StorageManagerMock.cpp create mode 100644 unittests/mocks/StorageManagerMock.h diff --git a/src/fsfw/cfdp/CfdpDistributor.cpp b/src/fsfw/cfdp/CfdpDistributor.cpp index 4aa9c797..e2377024 100644 --- a/src/fsfw/cfdp/CfdpDistributor.cpp +++ b/src/fsfw/cfdp/CfdpDistributor.cpp @@ -40,7 +40,7 @@ ReturnValue_t CfdpDistributor::selectDestination(MessageQueueId_t& destId) { } if (not destFound) { // TODO: Warning and event? - return HasReturnvaluesIF::RETURN_FAILED; + return tmtcdistrib::NO_DESTINATION_FOUND; } // Packet was forwarded successfully, so do not delete it. accessorPair.second.release(); diff --git a/src/fsfw/returnvalues/FwClassIds.h b/src/fsfw/returnvalues/FwClassIds.h index 1dfe1cc8..9a5cc812 100644 --- a/src/fsfw/returnvalues/FwClassIds.h +++ b/src/fsfw/returnvalues/FwClassIds.h @@ -34,7 +34,7 @@ enum : uint8_t { FIFO_CLASS, // FF MESSAGE_PROXY, // MQP TRIPLE_REDUNDACY_CHECK, // TRC - PACKET_CHECK, // TCC + TMTC_DISTRIBUTION, // TCC PACKET_DISTRIBUTION, // TCD ACCEPTS_TELECOMMANDS_IF, // ATC PUS_IF, // PUS diff --git a/src/fsfw/storagemanager/ConstStorageAccessor.cpp b/src/fsfw/storagemanager/ConstStorageAccessor.cpp index df2fc750..5b0e98c3 100644 --- a/src/fsfw/storagemanager/ConstStorageAccessor.cpp +++ b/src/fsfw/storagemanager/ConstStorageAccessor.cpp @@ -19,7 +19,7 @@ ConstStorageAccessor::~ConstStorageAccessor() { } } -ConstStorageAccessor::ConstStorageAccessor(ConstStorageAccessor&& other) +ConstStorageAccessor::ConstStorageAccessor(ConstStorageAccessor&& other) noexcept : constDataPointer(other.constDataPointer), storeId(other.storeId), size_(other.size_), @@ -30,7 +30,7 @@ ConstStorageAccessor::ConstStorageAccessor(ConstStorageAccessor&& other) other.store = nullptr; } -ConstStorageAccessor& ConstStorageAccessor::operator=(ConstStorageAccessor&& other) { +ConstStorageAccessor& ConstStorageAccessor::operator=(ConstStorageAccessor&& other) noexcept { constDataPointer = other.constDataPointer; storeId = other.storeId; store = other.store; @@ -84,7 +84,7 @@ void ConstStorageAccessor::print() const { arrayprinter::print(constDataPointer, size_); } -void ConstStorageAccessor::assignStore(StorageManagerIF* store) { +void ConstStorageAccessor::assignStore(StorageManagerIF* store_) { internalState = AccessState::ASSIGNED; - this->store = store; + store = store_; } diff --git a/src/fsfw/storagemanager/ConstStorageAccessor.h b/src/fsfw/storagemanager/ConstStorageAccessor.h index a2ddad6c..e70d3f40 100644 --- a/src/fsfw/storagemanager/ConstStorageAccessor.h +++ b/src/fsfw/storagemanager/ConstStorageAccessor.h @@ -23,6 +23,7 @@ class ConstStorageAccessor { //! StorageManager classes have exclusive access to private variables. friend class PoolManager; friend class LocalPool; + friend class StorageManagerIF; public: /** @@ -30,7 +31,7 @@ class ConstStorageAccessor { * entry to access. * @param storeId */ - ConstStorageAccessor(store_address_t storeId); + explicit ConstStorageAccessor(store_address_t storeId); ConstStorageAccessor(store_address_t storeId, StorageManagerIF* store); /** @@ -43,7 +44,7 @@ class ConstStorageAccessor { * @brief Returns a pointer to the read-only data * @return */ - const uint8_t* data() const; + [[nodiscard]] const uint8_t* data() const; /** * @brief Copies the read-only data to the supplied pointer @@ -61,13 +62,13 @@ class ConstStorageAccessor { * Get the size of the data * @return */ - size_t size() const; + [[nodiscard]] size_t size() const; /** * Get the storage ID. * @return */ - store_address_t getId() const; + [[nodiscard]] store_address_t getId() const; void print() const; @@ -79,8 +80,8 @@ class ConstStorageAccessor { * @param * @return */ - ConstStorageAccessor& operator=(ConstStorageAccessor&&); - ConstStorageAccessor(ConstStorageAccessor&&); + ConstStorageAccessor& operator=(ConstStorageAccessor&&) noexcept ; + ConstStorageAccessor(ConstStorageAccessor&&) noexcept ; //! The copy ctor and copy assignemnt should be deleted implicitely //! according to https://foonathan.net/2019/02/special-member-functions/ diff --git a/src/fsfw/storagemanager/LocalPool.cpp b/src/fsfw/storagemanager/LocalPool.cpp index f8b2bdb3..e40315ed 100644 --- a/src/fsfw/storagemanager/LocalPool.cpp +++ b/src/fsfw/storagemanager/LocalPool.cpp @@ -29,7 +29,7 @@ LocalPool::LocalPool(object_id_t setObjectId, const LocalPoolConfig& poolConfig, } } -LocalPool::~LocalPool(void) {} +LocalPool::~LocalPool() = default; ReturnValue_t LocalPool::addData(store_address_t* storageId, const uint8_t* data, size_t size, bool ignoreFault) { @@ -48,22 +48,6 @@ ReturnValue_t LocalPool::getData(store_address_t packetId, const uint8_t** packe return status; } -ReturnValue_t LocalPool::getData(store_address_t storeId, ConstStorageAccessor& storeAccessor) { - uint8_t* tempData = nullptr; - ReturnValue_t status = modifyData(storeId, &tempData, &storeAccessor.size_); - storeAccessor.assignStore(this); - storeAccessor.constDataPointer = tempData; - return status; -} - -ConstAccessorPair LocalPool::getData(store_address_t storeId) { - uint8_t* tempData = nullptr; - ConstStorageAccessor constAccessor(storeId, this); - ReturnValue_t status = modifyData(storeId, &tempData, &constAccessor.size_); - constAccessor.constDataPointer = tempData; - return ConstAccessorPair(status, std::move(constAccessor)); -} - ReturnValue_t LocalPool::getFreeElement(store_address_t* storageId, const size_t size, uint8_t** pData, bool ignoreFault) { ReturnValue_t status = reserveSpace(size, storageId, ignoreFault); @@ -75,20 +59,6 @@ ReturnValue_t LocalPool::getFreeElement(store_address_t* storageId, const size_t return status; } -AccessorPair LocalPool::modifyData(store_address_t storeId) { - StorageAccessor accessor(storeId, this); - ReturnValue_t status = modifyData(storeId, &accessor.dataPointer, &accessor.size_); - accessor.assignConstPointer(); - return AccessorPair(status, std::move(accessor)); -} - -ReturnValue_t LocalPool::modifyData(store_address_t storeId, StorageAccessor& storeAccessor) { - storeAccessor.assignStore(this); - ReturnValue_t status = modifyData(storeId, &storeAccessor.dataPointer, &storeAccessor.size_); - storeAccessor.assignConstPointer(); - return status; -} - ReturnValue_t LocalPool::modifyData(store_address_t storeId, uint8_t** packetPtr, size_t* size) { ReturnValue_t status = RETURN_FAILED; if (storeId.poolIndex >= NUMBER_OF_SUBPOOLS) { @@ -197,7 +167,7 @@ void LocalPool::clearStore() { } } -ReturnValue_t LocalPool::reserveSpace(const size_t size, store_address_t* storeId, +ReturnValue_t LocalPool::reserveSpace(size_t size, store_address_t* storeId, bool ignoreFault) { ReturnValue_t status = getSubPoolIndex(size, &storeId->poolIndex); if (status != RETURN_OK) { @@ -349,3 +319,27 @@ bool LocalPool::hasDataAtId(store_address_t storeId) const { } return false; } + +ReturnValue_t LocalPool::getFreeElement(store_address_t* storeId, size_t size, uint8_t** pData) { + return StorageManagerIF::getFreeElement(storeId, size, pData); +} + +ConstAccessorPair LocalPool::getData(store_address_t storeId) { + return StorageManagerIF::getData(storeId); +} + +ReturnValue_t LocalPool::addData(store_address_t* storeId, const uint8_t* data, size_t size) { + return StorageManagerIF::addData(storeId, data, size); +} + +ReturnValue_t LocalPool::getData(store_address_t storeId, ConstStorageAccessor& accessor) { + return StorageManagerIF::getData(storeId, accessor); +} + +ReturnValue_t LocalPool::modifyData(store_address_t storeId, StorageAccessor& accessor) { + return StorageManagerIF::modifyData(storeId, accessor); +} + +AccessorPair LocalPool::modifyData(store_address_t storeId) { + return StorageManagerIF::modifyData(storeId); +} diff --git a/src/fsfw/storagemanager/LocalPool.h b/src/fsfw/storagemanager/LocalPool.h index bf7ef92e..5ee2e66e 100644 --- a/src/fsfw/storagemanager/LocalPool.h +++ b/src/fsfw/storagemanager/LocalPool.h @@ -87,21 +87,23 @@ class LocalPool : public SystemObject, public StorageManagerIF { * Documentation: See StorageManagerIF.h */ ReturnValue_t addData(store_address_t* storeId, const uint8_t* data, size_t size, - bool ignoreFault = false) override; + bool ignoreFault) override; + ReturnValue_t addData(store_address_t* storeId, const uint8_t* data, size_t size) override; + + ReturnValue_t getFreeElement(store_address_t* storeId, size_t size, uint8_t** pData) override; ReturnValue_t getFreeElement(store_address_t* storeId, size_t size, uint8_t** pData, - bool ignoreFault = false) override; + bool ignoreFault) override; ConstAccessorPair getData(store_address_t storeId) override; - ReturnValue_t getData(store_address_t storeId, ConstStorageAccessor& constAccessor) override; + ReturnValue_t getData(store_address_t storeId, ConstStorageAccessor& accessor) override; ReturnValue_t getData(store_address_t storeId, const uint8_t** packet_ptr, size_t* size) override; AccessorPair modifyData(store_address_t storeId) override; - ReturnValue_t modifyData(store_address_t storeId, StorageAccessor& storeAccessor) override; ReturnValue_t modifyData(store_address_t storeId, uint8_t** packet_ptr, size_t* size) override; + ReturnValue_t modifyData(store_address_t storeId, StorageAccessor& accessor) override; - virtual ReturnValue_t deleteData(store_address_t storeId) override; - virtual ReturnValue_t deleteData(uint8_t* ptr, size_t size, - store_address_t* storeId = nullptr) override; + ReturnValue_t deleteData(store_address_t storeId) override; + ReturnValue_t deleteData(uint8_t* ptr, size_t size, store_address_t* storeId) override; /** * Get the total size of allocated memory for pool data. @@ -131,8 +133,8 @@ class LocalPool : public SystemObject, public StorageManagerIF { * Get number sub pools. Each pool has pages with a specific bucket size. * @return */ - max_subpools_t getNumberOfSubPools() const override; - bool hasDataAtId(store_address_t storeId) const override; + [[nodiscard]] max_subpools_t getNumberOfSubPools() const override; + [[nodiscard]] bool hasDataAtId(store_address_t storeId) const override; protected: /** @@ -142,7 +144,7 @@ class LocalPool : public SystemObject, public StorageManagerIF { * @return - #RETURN_OK on success, * - the return codes of #getPoolIndex or #findEmpty otherwise. */ - virtual ReturnValue_t reserveSpace(const size_t size, store_address_t* address, bool ignoreFault); + virtual ReturnValue_t reserveSpace(size_t size, store_address_t* address, bool ignoreFault); private: /** diff --git a/src/fsfw/storagemanager/StorageAccessor.cpp b/src/fsfw/storagemanager/StorageAccessor.cpp index b8096c1e..5010b64a 100644 --- a/src/fsfw/storagemanager/StorageAccessor.cpp +++ b/src/fsfw/storagemanager/StorageAccessor.cpp @@ -10,7 +10,7 @@ StorageAccessor::StorageAccessor(store_address_t storeId) : ConstStorageAccessor StorageAccessor::StorageAccessor(store_address_t storeId, StorageManagerIF* store) : ConstStorageAccessor(storeId, store) {} -StorageAccessor& StorageAccessor::operator=(StorageAccessor&& other) { +StorageAccessor& StorageAccessor::operator=(StorageAccessor&& other) noexcept { // Call the parent move assignment and also assign own member. dataPointer = other.dataPointer; ConstStorageAccessor::operator=(std::move(other)); @@ -18,7 +18,7 @@ StorageAccessor& StorageAccessor::operator=(StorageAccessor&& other) { } // Call the parent move ctor and also transfer own member. -StorageAccessor::StorageAccessor(StorageAccessor&& other) +StorageAccessor::StorageAccessor(StorageAccessor&& other) noexcept : ConstStorageAccessor(std::move(other)), dataPointer(other.dataPointer) {} ReturnValue_t StorageAccessor::getDataCopy(uint8_t* pointer, size_t maxSize) { diff --git a/src/fsfw/storagemanager/StorageAccessor.h b/src/fsfw/storagemanager/StorageAccessor.h index 5e8b25e4..f51ba7e6 100644 --- a/src/fsfw/storagemanager/StorageAccessor.h +++ b/src/fsfw/storagemanager/StorageAccessor.h @@ -12,9 +12,10 @@ class StorageAccessor : public ConstStorageAccessor { //! StorageManager classes have exclusive access to private variables. friend class PoolManager; friend class LocalPool; + friend class StorageManagerIF; public: - StorageAccessor(store_address_t storeId); + explicit StorageAccessor(store_address_t storeId); StorageAccessor(store_address_t storeId, StorageManagerIF* store); /** @@ -25,8 +26,8 @@ class StorageAccessor : public ConstStorageAccessor { * @param * @return */ - StorageAccessor& operator=(StorageAccessor&&); - StorageAccessor(StorageAccessor&&); + StorageAccessor& operator=(StorageAccessor&&) noexcept ; + StorageAccessor(StorageAccessor&&) noexcept ; ReturnValue_t write(uint8_t* data, size_t size, uint16_t offset = 0); uint8_t* data(); diff --git a/src/fsfw/storagemanager/StorageManagerIF.h b/src/fsfw/storagemanager/StorageManagerIF.h index 90ea4587..36ad5370 100644 --- a/src/fsfw/storagemanager/StorageManagerIF.h +++ b/src/fsfw/storagemanager/StorageManagerIF.h @@ -68,7 +68,12 @@ class StorageManagerIF : public HasReturnvaluesIF { * storageId is unchanged then. */ virtual ReturnValue_t addData(store_address_t* storageId, const uint8_t* data, size_t size, - bool ignoreFault = false) = 0; + bool ignoreFault) = 0; + + virtual ReturnValue_t addData(store_address_t* storageId, const uint8_t* data, size_t size) { + return addData(storageId, data, size, false); + } + /** * @brief With deleteData, the storageManager frees the memory region * identified by packet_id. @@ -88,8 +93,10 @@ class StorageManagerIF : public HasReturnvaluesIF { * @li failure code if deletion did not work */ virtual ReturnValue_t deleteData(uint8_t* buffer, size_t size, - store_address_t* storeId = nullptr) = 0; - + store_address_t* storeId) = 0; + virtual ReturnValue_t deleteData(uint8_t* buffer, size_t size) { + return deleteData(buffer, size, nullptr); + } /** * @brief Access the data by supplying a store ID. * @details @@ -98,7 +105,13 @@ class StorageManagerIF : public HasReturnvaluesIF { * @param storeId * @return Pair of return value and a ConstStorageAccessor instance */ - virtual ConstAccessorPair getData(store_address_t storeId) = 0; + virtual ConstAccessorPair getData(store_address_t storeId) { + uint8_t* tempData = nullptr; + ConstStorageAccessor constAccessor(storeId, this); + ReturnValue_t status = modifyData(storeId, &tempData, &constAccessor.size_); + constAccessor.constDataPointer = tempData; + return {status, std::move(constAccessor)}; + } /** * @brief Access the data by supplying a store ID and a helper @@ -107,7 +120,13 @@ class StorageManagerIF : public HasReturnvaluesIF { * @param constAccessor Wrapper function to access store data. * @return */ - virtual ReturnValue_t getData(store_address_t storeId, ConstStorageAccessor& constAccessor) = 0; + virtual ReturnValue_t getData(store_address_t storeId, ConstStorageAccessor& accessor) { + uint8_t* tempData = nullptr; + ReturnValue_t status = modifyData(storeId, &tempData, &accessor.size_); + accessor.assignStore(this); + accessor.constDataPointer = tempData; + return status; + } /** * @brief getData returns an address to data and the size of the data @@ -128,7 +147,12 @@ class StorageManagerIF : public HasReturnvaluesIF { * @param storeId * @return Pair of return value and StorageAccessor helper */ - virtual AccessorPair modifyData(store_address_t storeId) = 0; + virtual AccessorPair modifyData(store_address_t storeId) { + StorageAccessor accessor(storeId, this); + ReturnValue_t status = modifyData(storeId, &accessor.dataPointer, &accessor.size_); + accessor.assignConstPointer(); + return {status, std::move(accessor)}; + } /** * Modify data by supplying a store ID and a StorageAccessor helper instance. @@ -136,7 +160,12 @@ class StorageManagerIF : public HasReturnvaluesIF { * @param accessor Helper class to access the modifiable data. * @return */ - virtual ReturnValue_t modifyData(store_address_t storeId, StorageAccessor& accessor) = 0; + virtual ReturnValue_t modifyData(store_address_t storeId, StorageAccessor& accessor) { + accessor.assignStore(this); + ReturnValue_t status = modifyData(storeId, &accessor.dataPointer, &accessor.size_); + accessor.assignConstPointer(); + return status; + } /** * Get pointer and size of modifiable data by supplying the storeId @@ -155,13 +184,17 @@ class StorageManagerIF : public HasReturnvaluesIF { * written to p_data! * @param storageId A pointer to the storageId to retrieve. * @param size The size of the space to be reserved. - * @param p_data A pointer to the element data is returned here. + * @param dataPtr A pointer to the element data is returned here. * @return Returns @li RETURN_OK if data was added. * @li RETURN_FAILED if data could not be added. * storageId is unchanged then. */ - virtual ReturnValue_t getFreeElement(store_address_t* storageId, size_t size, uint8_t** p_data, - bool ignoreFault = false) = 0; + virtual ReturnValue_t getFreeElement(store_address_t* storageId, size_t size, uint8_t** dataPtr, + bool ignoreFault) = 0; + + virtual ReturnValue_t getFreeElement(store_address_t* storageId, size_t size, uint8_t** dataPtr) { + return getFreeElement(storageId, size, dataPtr, false); + } [[nodiscard]] virtual bool hasDataAtId(store_address_t storeId) const = 0; diff --git a/src/fsfw/tcdistribution/definitions.h b/src/fsfw/tcdistribution/definitions.h index 8cae639e..04c2569c 100644 --- a/src/fsfw/tcdistribution/definitions.h +++ b/src/fsfw/tcdistribution/definitions.h @@ -9,12 +9,13 @@ #include "fsfw/returnvalues/HasReturnvaluesIF.h" namespace tmtcdistrib { -static const uint8_t INTERFACE_ID = CLASS_ID::PACKET_CHECK; -static constexpr ReturnValue_t INVALID_CCSDS_VERSION = MAKE_RETURN_CODE(0); -static constexpr ReturnValue_t INVALID_APID = MAKE_RETURN_CODE(1); -static constexpr ReturnValue_t INVALID_PACKET_TYPE = MAKE_RETURN_CODE(2); -static constexpr ReturnValue_t INVALID_SEC_HEADER_FIELD = MAKE_RETURN_CODE(3); -static constexpr ReturnValue_t INCORRECT_PRIMARY_HEADER = MAKE_RETURN_CODE(4); +static const uint8_t INTERFACE_ID = CLASS_ID::TMTC_DISTRIBUTION; +static constexpr ReturnValue_t NO_DESTINATION_FOUND = result::makeCode(INTERFACE_ID, 0); +static constexpr ReturnValue_t INVALID_CCSDS_VERSION = MAKE_RETURN_CODE(1); +static constexpr ReturnValue_t INVALID_APID = MAKE_RETURN_CODE(2); +static constexpr ReturnValue_t INVALID_PACKET_TYPE = MAKE_RETURN_CODE(3); +static constexpr ReturnValue_t INVALID_SEC_HEADER_FIELD = MAKE_RETURN_CODE(4); +static constexpr ReturnValue_t INCORRECT_PRIMARY_HEADER = MAKE_RETURN_CODE(5); static constexpr ReturnValue_t INCOMPLETE_PACKET = MAKE_RETURN_CODE(5); static constexpr ReturnValue_t INVALID_PUS_VERSION = MAKE_RETURN_CODE(6); diff --git a/unittests/cfdp/testDistributor.cpp b/unittests/cfdp/testDistributor.cpp index 9eb3838c..b65f6816 100644 --- a/unittests/cfdp/testDistributor.cpp +++ b/unittests/cfdp/testDistributor.cpp @@ -37,7 +37,7 @@ TEST_CASE("CFDP Distributor", "[cfdp][distributor]") { CHECK(distributor.getRequestQueue() == queue.getId()); } - SECTION("Register Listener") { + SECTION("Packet Forwarding") { CHECK(distributor.initialize() == result::OK); CHECK(distributor.registerTcDestination(obswEntityId, tcAcceptor) == result::OK); size_t serLen = 0; diff --git a/unittests/mocks/CMakeLists.txt b/unittests/mocks/CMakeLists.txt index 0294af31..bc5649de 100644 --- a/unittests/mocks/CMakeLists.txt +++ b/unittests/mocks/CMakeLists.txt @@ -13,4 +13,5 @@ target_sources( AcceptsTmMock.cpp PusDistributorMock.cpp CcsdsCheckerMock.cpp - AcceptsTcMock.cpp) + AcceptsTcMock.cpp + StorageManagerMock.cpp) diff --git a/unittests/mocks/StorageManagerMock.cpp b/unittests/mocks/StorageManagerMock.cpp new file mode 100644 index 00000000..5172ecb5 --- /dev/null +++ b/unittests/mocks/StorageManagerMock.cpp @@ -0,0 +1,32 @@ +#include "StorageManagerMock.h" + +ReturnValue_t StorageManagerMock::addData(store_address_t *storageId, const uint8_t *data, + size_t size, bool ignoreFault) { + return 0; +} +ReturnValue_t StorageManagerMock::deleteData(store_address_t packet_id) { return 0; } + +ReturnValue_t StorageManagerMock::deleteData(uint8_t *buffer, size_t size, + store_address_t *storeId) { + return 0; +} + +ReturnValue_t StorageManagerMock::getData(store_address_t packet_id, const uint8_t **packet_ptr, + size_t *size) { + return 0; +} + +ReturnValue_t StorageManagerMock::modifyData(store_address_t packet_id, uint8_t **packet_ptr, + size_t *size) { + return 0; +} +ReturnValue_t StorageManagerMock::getFreeElement(store_address_t *storageId, size_t size, + uint8_t **p_data, bool ignoreFault) { + return 0; +} +bool StorageManagerMock::hasDataAtId(store_address_t storeId) const { return false; } +void StorageManagerMock::clearStore() {} +void StorageManagerMock::clearSubPool(uint8_t poolIndex) {} +void StorageManagerMock::getFillCount(uint8_t *buffer, uint8_t *bytesWritten) {} +size_t StorageManagerMock::getTotalSize(size_t *additionalSize) { return 0; } +StorageManagerIF::max_subpools_t StorageManagerMock::getNumberOfSubPools() const { return 0; } diff --git a/unittests/mocks/StorageManagerMock.h b/unittests/mocks/StorageManagerMock.h new file mode 100644 index 00000000..3f2bf92c --- /dev/null +++ b/unittests/mocks/StorageManagerMock.h @@ -0,0 +1,24 @@ +#ifndef FSFW_TESTS_STORAGEMANAGERMOCK_H +#define FSFW_TESTS_STORAGEMANAGERMOCK_H + +#include "fsfw/storagemanager/StorageManagerIF.h" + +class StorageManagerMock: public StorageManagerIF { + public: + ReturnValue_t addData(store_address_t *storageId, const uint8_t *data, size_t size, + bool ignoreFault) override; + ReturnValue_t deleteData(store_address_t packet_id) override; + ReturnValue_t deleteData(uint8_t *buffer, size_t size, store_address_t *storeId) override; + ReturnValue_t getData(store_address_t packet_id, const uint8_t **packet_ptr, + size_t *size) override; + ReturnValue_t modifyData(store_address_t packet_id, uint8_t **packet_ptr, size_t *size) override; + ReturnValue_t getFreeElement(store_address_t *storageId, size_t size, uint8_t **p_data, + bool ignoreFault) override; + [[nodiscard]] bool hasDataAtId(store_address_t storeId) const override; + void clearStore() override; + void clearSubPool(uint8_t poolIndex) override; + void getFillCount(uint8_t *buffer, uint8_t *bytesWritten) override; + size_t getTotalSize(size_t *additionalSize) override; + [[nodiscard]] max_subpools_t getNumberOfSubPools() const override; +}; +#endif // FSFW_TESTS_STORAGEMANAGERMOCK_H diff --git a/unittests/storagemanager/testAccessor.cpp b/unittests/storagemanager/testAccessor.cpp index 56ab411c..e28d979b 100644 --- a/unittests/storagemanager/testAccessor.cpp +++ b/unittests/storagemanager/testAccessor.cpp @@ -8,7 +8,7 @@ TEST_CASE("Pool Accessor", "[pool-accessor]") { LocalPool::LocalPoolConfig poolCfg = {{1, 10}}; - LocalPool SimplePool = LocalPool(0, poolCfg); + LocalPool simplePool = LocalPool(0, poolCfg); std::array testDataArray{}; std::array receptionArray{}; store_address_t testStoreId; @@ -20,9 +20,9 @@ TEST_CASE("Pool Accessor", "[pool-accessor]") { size_t size = 10; SECTION("Simple tests getter functions") { - result = SimplePool.addData(&testStoreId, testDataArray.data(), size); + result = simplePool.addData(&testStoreId, testDataArray.data(), size); REQUIRE(result == result::OK); - auto resultPair = SimplePool.getData(testStoreId); + auto resultPair = simplePool.getData(testStoreId); REQUIRE(resultPair.first == result::OK); resultPair.second.getDataCopy(receptionArray.data(), 20); CHECK(resultPair.second.getId() == testStoreId); @@ -38,18 +38,18 @@ TEST_CASE("Pool Accessor", "[pool-accessor]") { } { - auto resultPairLoc = SimplePool.getData(testStoreId); + auto resultPairLoc = simplePool.getData(testStoreId); REQUIRE(resultPairLoc.first == result::OK); // data should be deleted when accessor goes out of scope. } - resultPair = SimplePool.getData(testStoreId); + resultPair = simplePool.getData(testStoreId); REQUIRE(resultPair.first == (int)StorageManagerIF::DATA_DOES_NOT_EXIST); - result = SimplePool.addData(&testStoreId, testDataArray.data(), size); + result = simplePool.addData(&testStoreId, testDataArray.data(), size); REQUIRE(result == result::OK); { ConstStorageAccessor constAccessor(testStoreId); - result = SimplePool.getData(testStoreId, constAccessor); + result = simplePool.getData(testStoreId, constAccessor); REQUIRE(result == result::OK); constAccessor.getDataCopy(receptionArray.data(), 20); for (size_t i = 0; i < size; i++) { @@ -57,17 +57,17 @@ TEST_CASE("Pool Accessor", "[pool-accessor]") { } // likewise, data should be deleted when accessor gets out of scope. } - resultPair = SimplePool.getData(testStoreId); + resultPair = simplePool.getData(testStoreId); REQUIRE(resultPair.first == (int)StorageManagerIF::DATA_DOES_NOT_EXIST); - result = SimplePool.addData(&testStoreId, testDataArray.data(), size); + result = simplePool.addData(&testStoreId, testDataArray.data(), size); { - resultPair = SimplePool.getData(testStoreId); + resultPair = simplePool.getData(testStoreId); REQUIRE(resultPair.first == result::OK); resultPair.second.release(); // now data should not be deleted anymore } - resultPair = SimplePool.getData(testStoreId); + resultPair = simplePool.getData(testStoreId); REQUIRE(resultPair.first == result::OK); resultPair.second.getDataCopy(receptionArray.data(), 20); for (size_t i = 0; i < size; i++) { @@ -76,11 +76,11 @@ TEST_CASE("Pool Accessor", "[pool-accessor]") { } SECTION("Simple tests modify functions") { - result = SimplePool.addData(&testStoreId, testDataArray.data(), size); + result = simplePool.addData(&testStoreId, testDataArray.data(), size); REQUIRE(result == result::OK); { StorageAccessor accessor(testStoreId); - result = SimplePool.modifyData(testStoreId, accessor); + result = simplePool.modifyData(testStoreId, accessor); REQUIRE(result == result::OK); CHECK(accessor.getId() == testStoreId); CHECK(accessor.size() == 10); @@ -94,13 +94,13 @@ TEST_CASE("Pool Accessor", "[pool-accessor]") { } // data should be deleted when accessor goes out of scope } - auto resultPair = SimplePool.getData(testStoreId); + auto resultPair = simplePool.getData(testStoreId); REQUIRE(resultPair.first == (int)StorageManagerIF::DATA_DOES_NOT_EXIST); - result = SimplePool.addData(&testStoreId, testDataArray.data(), size); + result = simplePool.addData(&testStoreId, testDataArray.data(), size); REQUIRE(result == result::OK); { - auto resultPairLoc = SimplePool.modifyData(testStoreId); + auto resultPairLoc = simplePool.modifyData(testStoreId); REQUIRE(resultPairLoc.first == result::OK); CHECK(resultPairLoc.second.getId() == testStoreId); CHECK(resultPairLoc.second.size() == 10); @@ -116,22 +116,22 @@ TEST_CASE("Pool Accessor", "[pool-accessor]") { resultPairLoc.second.release(); // data should not be deleted when accessor goes out of scope } - resultPair = SimplePool.getData(testStoreId); + resultPair = simplePool.getData(testStoreId); REQUIRE(resultPair.first == result::OK); } SECTION("Write tests") { - result = SimplePool.addData(&testStoreId, testDataArray.data(), size); + result = simplePool.addData(&testStoreId, testDataArray.data(), size); REQUIRE(result == result::OK); { - auto resultPair = SimplePool.modifyData(testStoreId); + auto resultPair = simplePool.modifyData(testStoreId); REQUIRE(resultPair.first == result::OK); testDataArray[9] = 42; resultPair.second.write(testDataArray.data(), 10, 0); // now data should not be deleted resultPair.second.release(); } - auto resultConstPair = SimplePool.getData(testStoreId); + auto resultConstPair = simplePool.getData(testStoreId); REQUIRE(resultConstPair.first == result::OK); resultConstPair.second.getDataCopy(receptionArray.data(), 10); @@ -140,7 +140,7 @@ TEST_CASE("Pool Accessor", "[pool-accessor]") { } CHECK(receptionArray[9] == 42); - auto resultPair = SimplePool.modifyData(testStoreId); + auto resultPair = simplePool.modifyData(testStoreId); REQUIRE(resultPair.first == result::OK); result = resultPair.second.write(testDataArray.data(), 20, 0); REQUIRE(result == result::FAILED); @@ -150,7 +150,7 @@ TEST_CASE("Pool Accessor", "[pool-accessor]") { std::memset(testDataArray.data(), 42, 5); result = resultPair.second.write(testDataArray.data(), 5, 5); REQUIRE(result == result::OK); - resultConstPair = SimplePool.getData(testStoreId); + resultConstPair = simplePool.getData(testStoreId); resultPair.second.getDataCopy(receptionArray.data(), 20); for (size_t i = 5; i < 10; i++) { CHECK(receptionArray[i] == 42); @@ -158,7 +158,7 @@ TEST_CASE("Pool Accessor", "[pool-accessor]") { } SECTION("Operators") { - result = SimplePool.addData(&testStoreId, testDataArray.data(), size); + result = simplePool.addData(&testStoreId, testDataArray.data(), size); REQUIRE(result == result::OK); { StorageAccessor accessor(testStoreId); @@ -169,7 +169,7 @@ TEST_CASE("Pool Accessor", "[pool-accessor]") { size_t size = 6; result = accessor.write(data.data(), data.size()); REQUIRE(result == HasReturnvaluesIF::RETURN_FAILED); - result = SimplePool.modifyData(testStoreId, accessor2); + result = simplePool.modifyData(testStoreId, accessor2); REQUIRE(result == HasReturnvaluesIF::RETURN_OK); CHECK(accessor2.getId() == testStoreId); CHECK(accessor2.size() == 10); From 22e1555f5097cae82413976cee55921aba0ac3ee Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Tue, 9 Aug 2022 12:45:05 +0200 Subject: [PATCH 032/169] basic storage manager mock --- unittests/mocks/StorageManagerMock.cpp | 67 +++++++++++++++++++++----- unittests/mocks/StorageManagerMock.h | 10 +++- 2 files changed, 65 insertions(+), 12 deletions(-) diff --git a/unittests/mocks/StorageManagerMock.cpp b/unittests/mocks/StorageManagerMock.cpp index 5172ecb5..fc517953 100644 --- a/unittests/mocks/StorageManagerMock.cpp +++ b/unittests/mocks/StorageManagerMock.cpp @@ -2,31 +2,76 @@ ReturnValue_t StorageManagerMock::addData(store_address_t *storageId, const uint8_t *data, size_t size, bool ignoreFault) { - return 0; + if (nextAddDataCallFails.first) { + return nextAddDataCallFails.second; + } + return LocalPool::addData(storageId, data, size, ignoreFault); +} +ReturnValue_t StorageManagerMock::deleteData(store_address_t packet_id) { + if(nextDeleteDataCallFails.first) { + return nextDeleteDataCallFails.second; + } + return LocalPool::deleteData(packet_id); } -ReturnValue_t StorageManagerMock::deleteData(store_address_t packet_id) { return 0; } ReturnValue_t StorageManagerMock::deleteData(uint8_t *buffer, size_t size, store_address_t *storeId) { - return 0; + if(nextDeleteDataCallFails.first) { + return nextDeleteDataCallFails.second; + } + return LocalPool::deleteData(buffer, size, storeId); } ReturnValue_t StorageManagerMock::getData(store_address_t packet_id, const uint8_t **packet_ptr, size_t *size) { - return 0; + if (nextGetDataCallFails.first) { + return nextGetDataCallFails.second; + } + return LocalPool::getData(packet_id, packet_ptr, size); } ReturnValue_t StorageManagerMock::modifyData(store_address_t packet_id, uint8_t **packet_ptr, size_t *size) { - return 0; + if (nextModifyDataCallFails.first) { + return nextModifyDataCallFails.second; + } + return LocalPool::modifyData(packet_id, packet_ptr, size); } ReturnValue_t StorageManagerMock::getFreeElement(store_address_t *storageId, size_t size, uint8_t **p_data, bool ignoreFault) { return 0; } -bool StorageManagerMock::hasDataAtId(store_address_t storeId) const { return false; } -void StorageManagerMock::clearStore() {} -void StorageManagerMock::clearSubPool(uint8_t poolIndex) {} -void StorageManagerMock::getFillCount(uint8_t *buffer, uint8_t *bytesWritten) {} -size_t StorageManagerMock::getTotalSize(size_t *additionalSize) { return 0; } -StorageManagerIF::max_subpools_t StorageManagerMock::getNumberOfSubPools() const { return 0; } +bool StorageManagerMock::hasDataAtId(store_address_t storeId) const { + return LocalPool::hasDataAtId(storeId); +} +void StorageManagerMock::clearStore() { + return LocalPool::clearStore(); +} + +void StorageManagerMock::clearSubPool(uint8_t poolIndex) { + return LocalPool::clearSubPool(poolIndex); +} + +void StorageManagerMock::getFillCount(uint8_t *buffer, uint8_t *bytesWritten) { + return LocalPool::getFillCount(buffer, bytesWritten); +} + +size_t StorageManagerMock::getTotalSize(size_t *additionalSize) { + return LocalPool::getTotalSize(additionalSize); +} + +StorageManagerIF::max_subpools_t StorageManagerMock::getNumberOfSubPools() const { + return LocalPool::getNumberOfSubPools(); +} + +void StorageManagerMock::reset() { + clearStore(); + nextAddDataCallFails.first = false; + nextAddDataCallFails.second = result::OK; + nextModifyDataCallFails.first = false; + nextModifyDataCallFails.second = result::OK; + nextGetDataCallFails.first = false; + nextGetDataCallFails.second = result::OK; + nextDeleteDataCallFails.first = false; + nextDeleteDataCallFails.second = result::OK; +} diff --git a/unittests/mocks/StorageManagerMock.h b/unittests/mocks/StorageManagerMock.h index 3f2bf92c..40bb88cc 100644 --- a/unittests/mocks/StorageManagerMock.h +++ b/unittests/mocks/StorageManagerMock.h @@ -1,9 +1,10 @@ #ifndef FSFW_TESTS_STORAGEMANAGERMOCK_H #define FSFW_TESTS_STORAGEMANAGERMOCK_H +#include "fsfw/storagemanager/LocalPool.h" #include "fsfw/storagemanager/StorageManagerIF.h" -class StorageManagerMock: public StorageManagerIF { +class StorageManagerMock: public LocalPool { public: ReturnValue_t addData(store_address_t *storageId, const uint8_t *data, size_t size, bool ignoreFault) override; @@ -20,5 +21,12 @@ class StorageManagerMock: public StorageManagerIF { void getFillCount(uint8_t *buffer, uint8_t *bytesWritten) override; size_t getTotalSize(size_t *additionalSize) override; [[nodiscard]] max_subpools_t getNumberOfSubPools() const override; + + std::pair nextAddDataCallFails; + std::pair nextModifyDataCallFails; + std::pair nextGetDataCallFails; + std::pair nextDeleteDataCallFails; + + void reset(); }; #endif // FSFW_TESTS_STORAGEMANAGERMOCK_H From 192956c2c78a51d4433f7052b1d45985b26ded9d Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Tue, 9 Aug 2022 12:50:50 +0200 Subject: [PATCH 033/169] use new storage manager mock --- unittests/cfdp/testDistributor.cpp | 5 +++-- unittests/mocks/StorageManagerMock.cpp | 14 +++++++++++++- unittests/mocks/StorageManagerMock.h | 4 +++- 3 files changed, 19 insertions(+), 4 deletions(-) diff --git a/unittests/cfdp/testDistributor.cpp b/unittests/cfdp/testDistributor.cpp index b65f6816..c5ed9948 100644 --- a/unittests/cfdp/testDistributor.cpp +++ b/unittests/cfdp/testDistributor.cpp @@ -5,10 +5,11 @@ #include "fsfw/storagemanager/LocalPool.h" #include "mocks/AcceptsTcMock.h" #include "mocks/MessageQueueMock.h" +#include "mocks/StorageManagerMock.h" TEST_CASE("CFDP Distributor", "[cfdp][distributor]") { LocalPool::LocalPoolConfig cfg = {{5, 32}, {2, 64}}; - LocalPool pool(objects::NO_OBJECT, cfg); + StorageManagerMock pool(objects::NO_OBJECT, cfg); auto queue = MessageQueueMock(1); CfdpDistribCfg distribCfg(1, pool, &queue); auto distributor = CfdpDistributor(distribCfg); @@ -42,7 +43,7 @@ TEST_CASE("CFDP Distributor", "[cfdp][distributor]") { CHECK(distributor.registerTcDestination(obswEntityId, tcAcceptor) == result::OK); size_t serLen = 0; store_address_t storeId; - CHECK(pool.getFreeElement(&storeId, creator.getSerializedSize(), &dataPtr) == result::OK); + CHECK(pool.LocalPool::getFreeElement(&storeId, creator.getSerializedSize(), &dataPtr) == result::OK); REQUIRE(creator.SerializeIF::serializeBe(dataPtr, serLen, creator.getSerializedSize()) == result::OK); TmTcMessage msg(storeId); diff --git a/unittests/mocks/StorageManagerMock.cpp b/unittests/mocks/StorageManagerMock.cpp index fc517953..13f513e6 100644 --- a/unittests/mocks/StorageManagerMock.cpp +++ b/unittests/mocks/StorageManagerMock.cpp @@ -37,10 +37,15 @@ ReturnValue_t StorageManagerMock::modifyData(store_address_t packet_id, uint8_t } return LocalPool::modifyData(packet_id, packet_ptr, size); } + ReturnValue_t StorageManagerMock::getFreeElement(store_address_t *storageId, size_t size, uint8_t **p_data, bool ignoreFault) { - return 0; + if (nextFreeElementCallFails.first) { + return nextFreeElementCallFails.second; + } + return LocalPool::getFreeElement(storageId, size, p_data, ignoreFault); } + bool StorageManagerMock::hasDataAtId(store_address_t storeId) const { return LocalPool::hasDataAtId(storeId); } @@ -74,4 +79,11 @@ void StorageManagerMock::reset() { nextGetDataCallFails.second = result::OK; nextDeleteDataCallFails.first = false; nextDeleteDataCallFails.second = result::OK; + nextFreeElementCallFails.first = false; + nextFreeElementCallFails.second = result::OK; +} + +StorageManagerMock::StorageManagerMock(object_id_t setObjectId, + const LocalPool::LocalPoolConfig &poolConfig) + : LocalPool(setObjectId, poolConfig) { } diff --git a/unittests/mocks/StorageManagerMock.h b/unittests/mocks/StorageManagerMock.h index 40bb88cc..be2b7982 100644 --- a/unittests/mocks/StorageManagerMock.h +++ b/unittests/mocks/StorageManagerMock.h @@ -6,6 +6,8 @@ class StorageManagerMock: public LocalPool { public: + StorageManagerMock(object_id_t setObjectId, const LocalPoolConfig& poolConfig); + ReturnValue_t addData(store_address_t *storageId, const uint8_t *data, size_t size, bool ignoreFault) override; ReturnValue_t deleteData(store_address_t packet_id) override; @@ -26,7 +28,7 @@ class StorageManagerMock: public LocalPool { std::pair nextModifyDataCallFails; std::pair nextGetDataCallFails; std::pair nextDeleteDataCallFails; - + std::pair nextFreeElementCallFails; void reset(); }; #endif // FSFW_TESTS_STORAGEMANAGERMOCK_H From 0d26a0f54bdb00eabdffa7b6964377c6d0ba1b77 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Tue, 9 Aug 2022 13:04:23 +0200 Subject: [PATCH 034/169] fnish CFDP distributor unittests --- src/fsfw/cfdp/CfdpDistributor.h | 8 ++++ .../storagemanager/ConstStorageAccessor.h | 4 +- src/fsfw/storagemanager/LocalPool.cpp | 3 +- src/fsfw/storagemanager/PoolManager.h | 8 ++-- src/fsfw/storagemanager/StorageAccessor.h | 4 +- src/fsfw/storagemanager/StorageManagerIF.h | 3 +- unittests/cfdp/testDistributor.cpp | 40 ++++++++++++++++++- unittests/mocks/StorageManagerMock.cpp | 16 ++------ unittests/mocks/StorageManagerMock.h | 9 +++-- 9 files changed, 66 insertions(+), 29 deletions(-) diff --git a/src/fsfw/cfdp/CfdpDistributor.h b/src/fsfw/cfdp/CfdpDistributor.h index 8fece981..64c5ca9f 100644 --- a/src/fsfw/cfdp/CfdpDistributor.h +++ b/src/fsfw/cfdp/CfdpDistributor.h @@ -42,6 +42,14 @@ class CfdpDistributor : public TcDistributorBase, public AcceptsTelecommandsIF { [[nodiscard]] const char* getName() const override; [[nodiscard]] uint32_t getIdentifier() const override; [[nodiscard]] MessageQueueId_t getRequestQueue() const override; + + /** + * Register a new CFDP entity which can receive PDUs. + * @param address + * @param tcDest + * @return + * - @c RETURN_FAILED: Entry already exists for the given address + */ ReturnValue_t registerTcDestination(const cfdp::EntityId& address, AcceptsTelecommandsIF& tcDest); protected: diff --git a/src/fsfw/storagemanager/ConstStorageAccessor.h b/src/fsfw/storagemanager/ConstStorageAccessor.h index e70d3f40..a935e467 100644 --- a/src/fsfw/storagemanager/ConstStorageAccessor.h +++ b/src/fsfw/storagemanager/ConstStorageAccessor.h @@ -80,8 +80,8 @@ class ConstStorageAccessor { * @param * @return */ - ConstStorageAccessor& operator=(ConstStorageAccessor&&) noexcept ; - ConstStorageAccessor(ConstStorageAccessor&&) noexcept ; + ConstStorageAccessor& operator=(ConstStorageAccessor&&) noexcept; + ConstStorageAccessor(ConstStorageAccessor&&) noexcept; //! The copy ctor and copy assignemnt should be deleted implicitely //! according to https://foonathan.net/2019/02/special-member-functions/ diff --git a/src/fsfw/storagemanager/LocalPool.cpp b/src/fsfw/storagemanager/LocalPool.cpp index e40315ed..bcb1bea6 100644 --- a/src/fsfw/storagemanager/LocalPool.cpp +++ b/src/fsfw/storagemanager/LocalPool.cpp @@ -167,8 +167,7 @@ void LocalPool::clearStore() { } } -ReturnValue_t LocalPool::reserveSpace(size_t size, store_address_t* storeId, - bool ignoreFault) { +ReturnValue_t LocalPool::reserveSpace(size_t size, store_address_t* storeId, bool ignoreFault) { ReturnValue_t status = getSubPoolIndex(size, &storeId->poolIndex); if (status != RETURN_OK) { #if FSFW_CPP_OSTREAM_ENABLED == 1 diff --git a/src/fsfw/storagemanager/PoolManager.h b/src/fsfw/storagemanager/PoolManager.h index 0951a518..eaa978ef 100644 --- a/src/fsfw/storagemanager/PoolManager.h +++ b/src/fsfw/storagemanager/PoolManager.h @@ -27,7 +27,7 @@ class PoolManager : public LocalPool { * @brief In the PoolManager's destructor all allocated memory * is freed. */ - virtual ~PoolManager(); + ~PoolManager() override; /** * Set the default mutex timeout for internal calls. @@ -40,8 +40,7 @@ class PoolManager : public LocalPool { * which wraps LocalPool calls with a mutex protection. */ ReturnValue_t deleteData(store_address_t) override; - ReturnValue_t deleteData(uint8_t* buffer, size_t size, - store_address_t* storeId = nullptr) override; + ReturnValue_t deleteData(uint8_t* buffer, size_t size, store_address_t* storeId) override; /** * The developer is allowed to lock the mutex in case the lock needs @@ -58,8 +57,7 @@ class PoolManager : public LocalPool { //! Default mutex timeout value to prevent permanent blocking. uint32_t mutexTimeoutMs = 20; - ReturnValue_t reserveSpace(const size_t size, store_address_t* address, - bool ignoreFault) override; + ReturnValue_t reserveSpace(size_t size, store_address_t* address, bool ignoreFault) override; /** * @brief The mutex is created in the constructor and makes diff --git a/src/fsfw/storagemanager/StorageAccessor.h b/src/fsfw/storagemanager/StorageAccessor.h index f51ba7e6..b6c5dc14 100644 --- a/src/fsfw/storagemanager/StorageAccessor.h +++ b/src/fsfw/storagemanager/StorageAccessor.h @@ -26,8 +26,8 @@ class StorageAccessor : public ConstStorageAccessor { * @param * @return */ - StorageAccessor& operator=(StorageAccessor&&) noexcept ; - StorageAccessor(StorageAccessor&&) noexcept ; + StorageAccessor& operator=(StorageAccessor&&) noexcept; + StorageAccessor(StorageAccessor&&) noexcept; ReturnValue_t write(uint8_t* data, size_t size, uint16_t offset = 0); uint8_t* data(); diff --git a/src/fsfw/storagemanager/StorageManagerIF.h b/src/fsfw/storagemanager/StorageManagerIF.h index 36ad5370..502348de 100644 --- a/src/fsfw/storagemanager/StorageManagerIF.h +++ b/src/fsfw/storagemanager/StorageManagerIF.h @@ -92,8 +92,7 @@ class StorageManagerIF : public HasReturnvaluesIF { * @return @li RETURN_OK on success. * @li failure code if deletion did not work */ - virtual ReturnValue_t deleteData(uint8_t* buffer, size_t size, - store_address_t* storeId) = 0; + virtual ReturnValue_t deleteData(uint8_t* buffer, size_t size, store_address_t* storeId) = 0; virtual ReturnValue_t deleteData(uint8_t* buffer, size_t size) { return deleteData(buffer, size, nullptr); } diff --git a/unittests/cfdp/testDistributor.cpp b/unittests/cfdp/testDistributor.cpp index c5ed9948..2e94a55e 100644 --- a/unittests/cfdp/testDistributor.cpp +++ b/unittests/cfdp/testDistributor.cpp @@ -3,6 +3,7 @@ #include "fsfw/cfdp/CfdpDistributor.h" #include "fsfw/cfdp/pdu/MetadataPduCreator.h" #include "fsfw/storagemanager/LocalPool.h" +#include "fsfw/tcdistribution/definitions.h" #include "mocks/AcceptsTcMock.h" #include "mocks/MessageQueueMock.h" #include "mocks/StorageManagerMock.h" @@ -17,6 +18,8 @@ TEST_CASE("CFDP Distributor", "[cfdp][distributor]") { auto groundEntityId = cfdp::EntityId(UnsignedByteField(1)); MessageQueueId_t receiverQueueId = 3; auto tcAcceptor = AcceptsTcMock("CFDP Receiver", 0, receiverQueueId); + + // Set up Metadata PDU for generate test data. cfdp::FileSize fileSize(12); const cfdp::EntityId& sourceId(groundEntityId); const cfdp::EntityId& destId(obswEntityId); @@ -43,7 +46,8 @@ TEST_CASE("CFDP Distributor", "[cfdp][distributor]") { CHECK(distributor.registerTcDestination(obswEntityId, tcAcceptor) == result::OK); size_t serLen = 0; store_address_t storeId; - CHECK(pool.LocalPool::getFreeElement(&storeId, creator.getSerializedSize(), &dataPtr) == result::OK); + CHECK(pool.LocalPool::getFreeElement(&storeId, creator.getSerializedSize(), &dataPtr) == + result::OK); REQUIRE(creator.SerializeIF::serializeBe(dataPtr, serLen, creator.getSerializedSize()) == result::OK); TmTcMessage msg(storeId); @@ -57,4 +61,38 @@ TEST_CASE("CFDP Distributor", "[cfdp][distributor]") { CHECK(queue.getNextSentMessage(receiverQueueId, sentMsg) == result::OK); CHECK(sentMsg.getStorageId() == storeId); } + + SECTION("No Destination found") { + CHECK(distributor.initialize() == result::OK); + size_t serLen = 0; + store_address_t storeId; + CHECK(pool.LocalPool::getFreeElement(&storeId, creator.getSerializedSize(), &dataPtr) == + result::OK); + REQUIRE(creator.SerializeIF::serializeBe(dataPtr, serLen, creator.getSerializedSize()) == + result::OK); + TmTcMessage msg(storeId); + queue.addReceivedMessage(msg); + CHECK(distributor.performOperation(0) == tmtcdistrib::NO_DESTINATION_FOUND); + } + + SECTION("Getting data fails") { + pool.nextModifyDataCallFails.first = true; + pool.nextModifyDataCallFails.second = StorageManagerIF::DATA_DOES_NOT_EXIST; + size_t serLen = 0; + store_address_t storeId; + CHECK(distributor.registerTcDestination(obswEntityId, tcAcceptor) == result::OK); + CHECK(pool.LocalPool::getFreeElement(&storeId, creator.getSerializedSize(), &dataPtr) == + result::OK); + REQUIRE(creator.SerializeIF::serializeBe(dataPtr, serLen, creator.getSerializedSize()) == + result::OK); + TmTcMessage msg(storeId); + queue.addReceivedMessage(msg); + CHECK(distributor.performOperation(0) == StorageManagerIF::DATA_DOES_NOT_EXIST); + } + + SECTION("Duplicate registration") { + CHECK(distributor.initialize() == result::OK); + CHECK(distributor.registerTcDestination(obswEntityId, tcAcceptor) == result::OK); + CHECK(distributor.registerTcDestination(obswEntityId, tcAcceptor) == result::FAILED); + } } \ No newline at end of file diff --git a/unittests/mocks/StorageManagerMock.cpp b/unittests/mocks/StorageManagerMock.cpp index 13f513e6..387b5b17 100644 --- a/unittests/mocks/StorageManagerMock.cpp +++ b/unittests/mocks/StorageManagerMock.cpp @@ -8,7 +8,7 @@ ReturnValue_t StorageManagerMock::addData(store_address_t *storageId, const uint return LocalPool::addData(storageId, data, size, ignoreFault); } ReturnValue_t StorageManagerMock::deleteData(store_address_t packet_id) { - if(nextDeleteDataCallFails.first) { + if (nextDeleteDataCallFails.first) { return nextDeleteDataCallFails.second; } return LocalPool::deleteData(packet_id); @@ -16,7 +16,7 @@ ReturnValue_t StorageManagerMock::deleteData(store_address_t packet_id) { ReturnValue_t StorageManagerMock::deleteData(uint8_t *buffer, size_t size, store_address_t *storeId) { - if(nextDeleteDataCallFails.first) { + if (nextDeleteDataCallFails.first) { return nextDeleteDataCallFails.second; } return LocalPool::deleteData(buffer, size, storeId); @@ -24,9 +24,6 @@ ReturnValue_t StorageManagerMock::deleteData(uint8_t *buffer, size_t size, ReturnValue_t StorageManagerMock::getData(store_address_t packet_id, const uint8_t **packet_ptr, size_t *size) { - if (nextGetDataCallFails.first) { - return nextGetDataCallFails.second; - } return LocalPool::getData(packet_id, packet_ptr, size); } @@ -49,9 +46,7 @@ ReturnValue_t StorageManagerMock::getFreeElement(store_address_t *storageId, siz bool StorageManagerMock::hasDataAtId(store_address_t storeId) const { return LocalPool::hasDataAtId(storeId); } -void StorageManagerMock::clearStore() { - return LocalPool::clearStore(); -} +void StorageManagerMock::clearStore() { return LocalPool::clearStore(); } void StorageManagerMock::clearSubPool(uint8_t poolIndex) { return LocalPool::clearSubPool(poolIndex); @@ -75,8 +70,6 @@ void StorageManagerMock::reset() { nextAddDataCallFails.second = result::OK; nextModifyDataCallFails.first = false; nextModifyDataCallFails.second = result::OK; - nextGetDataCallFails.first = false; - nextGetDataCallFails.second = result::OK; nextDeleteDataCallFails.first = false; nextDeleteDataCallFails.second = result::OK; nextFreeElementCallFails.first = false; @@ -85,5 +78,4 @@ void StorageManagerMock::reset() { StorageManagerMock::StorageManagerMock(object_id_t setObjectId, const LocalPool::LocalPoolConfig &poolConfig) - : LocalPool(setObjectId, poolConfig) { -} + : LocalPool(setObjectId, poolConfig) {} diff --git a/unittests/mocks/StorageManagerMock.h b/unittests/mocks/StorageManagerMock.h index be2b7982..f33ba19b 100644 --- a/unittests/mocks/StorageManagerMock.h +++ b/unittests/mocks/StorageManagerMock.h @@ -4,9 +4,9 @@ #include "fsfw/storagemanager/LocalPool.h" #include "fsfw/storagemanager/StorageManagerIF.h" -class StorageManagerMock: public LocalPool { +class StorageManagerMock : public LocalPool { public: - StorageManagerMock(object_id_t setObjectId, const LocalPoolConfig& poolConfig); + StorageManagerMock(object_id_t setObjectId, const LocalPoolConfig &poolConfig); ReturnValue_t addData(store_address_t *storageId, const uint8_t *data, size_t size, bool ignoreFault) override; @@ -25,8 +25,11 @@ class StorageManagerMock: public LocalPool { [[nodiscard]] max_subpools_t getNumberOfSubPools() const override; std::pair nextAddDataCallFails; + /** + * This can be used to make both the modify and get API call fail. This is because generally, + * the pool implementation get functions will use the modify API internally. + */ std::pair nextModifyDataCallFails; - std::pair nextGetDataCallFails; std::pair nextDeleteDataCallFails; std::pair nextFreeElementCallFails; void reset(); From 7fb906a0ac3746de8a8cf577787f2bdd5b9360a0 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Tue, 9 Aug 2022 14:05:43 +0200 Subject: [PATCH 035/169] add first fault handler base class --- src/fsfw/cfdp/CMakeLists.txt | 5 ++-- src/fsfw/cfdp/CfdpDestHandler.h | 11 ++++++- src/fsfw/cfdp/FaultHandlerBase.cpp | 5 ++++ src/fsfw/cfdp/FaultHandlerBase.h | 29 +++++++++++++++++++ src/fsfw/cfdp/definitions.h | 23 +++++++++++++++ src/fsfw/cfdp/pdu/FinishedInfo.h | 14 ++++----- src/fsfw/cfdp/tlv/FaultHandlerOverrideTlv.cpp | 6 ++-- src/fsfw/cfdp/tlv/FaultHandlerOverrideTlv.h | 22 ++++---------- unittests/cfdp/testTlvsLvs.cpp | 2 +- 9 files changed, 86 insertions(+), 31 deletions(-) create mode 100644 src/fsfw/cfdp/FaultHandlerBase.cpp create mode 100644 src/fsfw/cfdp/FaultHandlerBase.h diff --git a/src/fsfw/cfdp/CMakeLists.txt b/src/fsfw/cfdp/CMakeLists.txt index 3d35ea69..df83bd7f 100644 --- a/src/fsfw/cfdp/CMakeLists.txt +++ b/src/fsfw/cfdp/CMakeLists.txt @@ -1,6 +1,7 @@ target_sources( - ${LIB_FSFW_NAME} PRIVATE CfdpMessage.cpp CfdpDistributor.cpp - CfdpSourceHandler.cpp CfdpDestHandler.cpp) + ${LIB_FSFW_NAME} + PRIVATE CfdpMessage.cpp CfdpDistributor.cpp CfdpSourceHandler.cpp + CfdpDestHandler.cpp FaultHandlerBase.cpp) # CfdpDistributor.cpp CfdpHandler.cpp add_subdirectory(pdu) diff --git a/src/fsfw/cfdp/CfdpDestHandler.h b/src/fsfw/cfdp/CfdpDestHandler.h index 69d40ed3..e317cc4f 100644 --- a/src/fsfw/cfdp/CfdpDestHandler.h +++ b/src/fsfw/cfdp/CfdpDestHandler.h @@ -1,6 +1,15 @@ #ifndef FSFW_CFDP_CFDPDESTHANDLER_H #define FSFW_CFDP_CFDPDESTHANDLER_H -class CfdpDestHandler {}; +#include + +#include "fsfw/cfdp/pdu/PduConfig.h" + +class CfdpDestHandler { + public: + CfdpDestHandler(); + + private: +}; #endif // FSFW_CFDP_CFDPDESTHANDLER_H diff --git a/src/fsfw/cfdp/FaultHandlerBase.cpp b/src/fsfw/cfdp/FaultHandlerBase.cpp new file mode 100644 index 00000000..b56e52d5 --- /dev/null +++ b/src/fsfw/cfdp/FaultHandlerBase.cpp @@ -0,0 +1,5 @@ +#include "FaultHandlerBase.h" + +CfdpFaultHandlerBase::CfdpFaultHandlerBase() {} + +CfdpFaultHandlerBase::~CfdpFaultHandlerBase() = default; diff --git a/src/fsfw/cfdp/FaultHandlerBase.h b/src/fsfw/cfdp/FaultHandlerBase.h new file mode 100644 index 00000000..0db0743f --- /dev/null +++ b/src/fsfw/cfdp/FaultHandlerBase.h @@ -0,0 +1,29 @@ +#ifndef FSFW_CFDP_FAULTHANDLERBASE_H +#define FSFW_CFDP_FAULTHANDLERBASE_H + +#include + +#include "definitions.h" + +class CfdpFaultHandlerBase { + public: + virtual ~CfdpFaultHandlerBase(); + CfdpFaultHandlerBase(); + + private: + etl::flat_map handleMap = { + etl::pair{cfdp::ConditionCode::POSITIVE_ACK_LIMIT_REACHED, + cfdp::FaultHandlerCodes::IGNORE_ERROR}, + etl::pair{cfdp::ConditionCode::KEEP_ALIVE_LIMIT_REACHED, + cfdp::FaultHandlerCodes::IGNORE_ERROR}, + etl::pair{cfdp::ConditionCode::INVALID_TRANSMISSION_MODE, + cfdp::FaultHandlerCodes::IGNORE_ERROR}, + etl::pair{cfdp::ConditionCode::FILE_CHECKSUM_FAILURE, cfdp::FaultHandlerCodes::IGNORE_ERROR}, + etl::pair{cfdp::ConditionCode::FILE_SIZE_ERROR, cfdp::FaultHandlerCodes::IGNORE_ERROR}, + etl::pair{cfdp::ConditionCode::NAK_LIMIT_REACHED, cfdp::FaultHandlerCodes::IGNORE_ERROR}, + etl::pair{cfdp::ConditionCode::INACTIVITY_DETECTED, cfdp::FaultHandlerCodes::IGNORE_ERROR}, + etl::pair{cfdp::ConditionCode::UNSUPPORTED_CHECKSUM_TYPE, + cfdp::FaultHandlerCodes::IGNORE_ERROR}}; +}; + +#endif // FSFW_CFDP_FAULTHANDLERBASE_H diff --git a/src/fsfw/cfdp/definitions.h b/src/fsfw/cfdp/definitions.h index 6b3b11e3..67e1edd4 100644 --- a/src/fsfw/cfdp/definitions.h +++ b/src/fsfw/cfdp/definitions.h @@ -6,6 +6,7 @@ #include #include +#include "fsfw/cfdp/pdu/PduHeaderIF.h" #include "fsfw/returnvalues/FwClassIds.h" #include "fsfw/returnvalues/HasReturnvaluesIF.h" @@ -90,6 +91,14 @@ enum ConditionCode : uint8_t { CANCEL_REQUEST_RECEIVED = 0b1111 }; +enum FaultHandlerCodes { + RESERVED = 0b0000, + NOTICE_OF_CANCELLATION = 0b0001, + NOTICE_OF_SUSPENSION = 0b0010, + IGNORE_ERROR = 0b0011, + ABANDON_TRANSACTION = 0b0100 +}; + enum AckTransactionStatus { UNDEFINED = 0b00, ACTIVE = 0b01, @@ -125,6 +134,20 @@ enum RecordContinuationState { CONTAINS_START_AND_END = 0b11 }; +struct IndicationCfg { + bool eofSentIndicRequired = true; + bool eofRecvIndicRequired = true; + bool fileSegmentRecvIndicRequired = true; + bool transactionFinishedIndicRequired = true; + bool suspendedIndicRequired = true; + bool resumedIndicRequired = true; +}; + +struct LocalEntityCfg { + EntityId localId; + IndicationCfg indicCfg; +}; + } // namespace cfdp #endif /* FSFW_SRC_FSFW_CFDP_PDU_DEFINITIONS_H_ */ diff --git a/src/fsfw/cfdp/pdu/FinishedInfo.h b/src/fsfw/cfdp/pdu/FinishedInfo.h index 5768a298..3f1758e8 100644 --- a/src/fsfw/cfdp/pdu/FinishedInfo.h +++ b/src/fsfw/cfdp/pdu/FinishedInfo.h @@ -11,10 +11,10 @@ class FinishedInfo { FinishedInfo(cfdp::ConditionCode conditionCode, cfdp::FinishedDeliveryCode deliveryCode, cfdp::FinishedFileStatus fileStatus); - size_t getSerializedSize() const; + [[nodiscard]] size_t getSerializedSize() const; - bool hasFsResponses() const; - bool canHoldFsResponses() const; + [[nodiscard]] bool hasFsResponses() const; + [[nodiscard]] bool canHoldFsResponses() const; ReturnValue_t setFilestoreResponsesArray(FilestoreResponseTlv** fsResponses, size_t* fsResponsesLen, const size_t* maxFsResponseLen); @@ -22,14 +22,14 @@ class FinishedInfo { ReturnValue_t getFilestoreResonses(FilestoreResponseTlv*** fsResponses, size_t* fsResponsesLen, size_t* fsResponsesMaxLen); - size_t getFsResponsesLen() const; + [[nodiscard]] size_t getFsResponsesLen() const; void setFilestoreResponsesArrayLen(size_t fsResponsesLen); ReturnValue_t getFaultLocation(EntityIdTlv** entityId); - cfdp::ConditionCode getConditionCode() const; + [[nodiscard]] cfdp::ConditionCode getConditionCode() const; void setConditionCode(cfdp::ConditionCode conditionCode); - cfdp::FinishedDeliveryCode getDeliveryCode() const; + [[nodiscard]] cfdp::FinishedDeliveryCode getDeliveryCode() const; void setDeliveryCode(cfdp::FinishedDeliveryCode deliveryCode); - cfdp::FinishedFileStatus getFileStatus() const; + [[nodiscard]] cfdp::FinishedFileStatus getFileStatus() const; void setFileStatus(cfdp::FinishedFileStatus fileStatus); private: diff --git a/src/fsfw/cfdp/tlv/FaultHandlerOverrideTlv.cpp b/src/fsfw/cfdp/tlv/FaultHandlerOverrideTlv.cpp index f5f777ea..73dc389c 100644 --- a/src/fsfw/cfdp/tlv/FaultHandlerOverrideTlv.cpp +++ b/src/fsfw/cfdp/tlv/FaultHandlerOverrideTlv.cpp @@ -1,10 +1,10 @@ #include "FaultHandlerOverrideTlv.h" FaultHandlerOverrideTlv::FaultHandlerOverrideTlv(cfdp::ConditionCode conditionCode, - cfdp::FaultHandlerCode handlerCode) + cfdp::FaultHandlerCodes handlerCode) : conditionCode(conditionCode), handlerCode(handlerCode) {} -FaultHandlerOverrideTlv::FaultHandlerOverrideTlv() {} +FaultHandlerOverrideTlv::FaultHandlerOverrideTlv() = default; uint8_t FaultHandlerOverrideTlv::getLengthField() const { return 1; } @@ -45,7 +45,7 @@ ReturnValue_t FaultHandlerOverrideTlv::deSerialize(const uint8_t **buffer, size_ *buffer += 1; *size += 1; this->conditionCode = static_cast((**buffer >> 4) & 0x0f); - this->handlerCode = static_cast(**buffer & 0x0f); + this->handlerCode = static_cast(**buffer & 0x0f); *buffer += 1; *size += 1; return HasReturnvaluesIF::RETURN_OK; diff --git a/src/fsfw/cfdp/tlv/FaultHandlerOverrideTlv.h b/src/fsfw/cfdp/tlv/FaultHandlerOverrideTlv.h index 9f2adbb3..a9cee9e6 100644 --- a/src/fsfw/cfdp/tlv/FaultHandlerOverrideTlv.h +++ b/src/fsfw/cfdp/tlv/FaultHandlerOverrideTlv.h @@ -3,36 +3,24 @@ #include "TlvIF.h" -namespace cfdp { - -enum FaultHandlerCode { - RESERVED = 0b0000, - NOTICE_OF_CANCELLATION = 0b0001, - NOTICE_OF_SUSPENSION = 0b0010, - IGNORE_ERROR = 0b0011, - ABANDON_TRANSACTION = 0b0100 -}; - -} - class FaultHandlerOverrideTlv : public TlvIF { public: FaultHandlerOverrideTlv(); - FaultHandlerOverrideTlv(cfdp::ConditionCode conditionCode, cfdp::FaultHandlerCode handlerCode); + FaultHandlerOverrideTlv(cfdp::ConditionCode conditionCode, cfdp::FaultHandlerCodes handlerCode); ReturnValue_t serialize(uint8_t **buffer, size_t *size, size_t maxSize, Endianness streamEndianness) const override; - size_t getSerializedSize() const override; + [[nodiscard]] size_t getSerializedSize() const override; ReturnValue_t deSerialize(const uint8_t **buffer, size_t *size, Endianness streamEndianness) override; - uint8_t getLengthField() const override; - cfdp::TlvTypes getType() const override; + [[nodiscard]] uint8_t getLengthField() const override; + [[nodiscard]] cfdp::TlvTypes getType() const override; private: cfdp::ConditionCode conditionCode = cfdp::ConditionCode::NO_CONDITION_FIELD; - cfdp::FaultHandlerCode handlerCode = cfdp::FaultHandlerCode::RESERVED; + cfdp::FaultHandlerCodes handlerCode = cfdp::FaultHandlerCodes::RESERVED; }; #endif /* FSFW_SRC_FSFW_CFDP_TLV_FAULTHANDLEROVERRIDETLV_H_ */ diff --git a/unittests/cfdp/testTlvsLvs.cpp b/unittests/cfdp/testTlvsLvs.cpp index acee9cce..7536069f 100644 --- a/unittests/cfdp/testTlvsLvs.cpp +++ b/unittests/cfdp/testTlvsLvs.cpp @@ -304,7 +304,7 @@ TEST_CASE("CFDP TLV LV", "[cfdp]") { FlowLabelTlv flowLabelTlv(&flowLabel, 1); FaultHandlerOverrideTlv faultOverrideTlv(cfdp::ConditionCode::FILESTORE_REJECTION, - cfdp::FaultHandlerCode::NOTICE_OF_CANCELLATION); + cfdp::FaultHandlerCodes::NOTICE_OF_CANCELLATION); size_t sz = 0; result = faultOverrideTlv.serialize(&serPtr, &sz, rawBuf.size(), SerializeIF::Endianness::NETWORK); From eccb629ba8ff8761ec6b382481d0ce6262940dbf Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Tue, 9 Aug 2022 14:39:03 +0200 Subject: [PATCH 036/169] fnished fault handler base --- src/fsfw/cfdp/FaultHandlerBase.cpp | 38 ++++++++++++++++++++++++++++- src/fsfw/cfdp/FaultHandlerBase.h | 22 ++++++++++++++++- src/fsfw/cfdp/definitions.h | 15 ------------ src/fsfw/cfdp/mib.h | 19 +++++++++++++++ src/fsfw/cfdp/pdu/HeaderCreator.cpp | 2 -- src/fsfw/cfdp/pdu/HeaderCreator.h | 28 ++++++++++----------- src/fsfw/cfdp/pdu/PduConfig.h | 3 ++- src/fsfw/cfdp/pdu/PduHeaderIF.h | 2 +- src/fsfw/cfdp/pdu/VarLenField.cpp | 1 - src/fsfw/cfdp/pdu/VarLenField.h | 10 +++++--- 10 files changed, 100 insertions(+), 40 deletions(-) create mode 100644 src/fsfw/cfdp/mib.h diff --git a/src/fsfw/cfdp/FaultHandlerBase.cpp b/src/fsfw/cfdp/FaultHandlerBase.cpp index b56e52d5..06edabd6 100644 --- a/src/fsfw/cfdp/FaultHandlerBase.cpp +++ b/src/fsfw/cfdp/FaultHandlerBase.cpp @@ -1,5 +1,41 @@ #include "FaultHandlerBase.h" -CfdpFaultHandlerBase::CfdpFaultHandlerBase() {} +CfdpFaultHandlerBase::CfdpFaultHandlerBase() = default; + +bool CfdpFaultHandlerBase::getFaultHandler( + cfdp::ConditionCode code, cfdp::FaultHandlerCodes& handler) const { + auto iter = faultHandlerMap.find(code); + if(iter == faultHandlerMap.end()) { + return false; + } + handler = iter->second; + return true; +} + +bool CfdpFaultHandlerBase::setFaultHandler(cfdp::ConditionCode code, + cfdp::FaultHandlerCodes handler) { + if (not faultHandlerMap.contains(code)) { + return false; + } + faultHandlerMap[code] = handler; + return true; +} + +bool CfdpFaultHandlerBase::faultCallback(cfdp::ConditionCode code) { + if (not faultHandlerMap.contains(code)) { + return false; + } + cfdp::FaultHandlerCodes fh = faultHandlerMap[code]; + if (fh == cfdp::FaultHandlerCodes::IGNORE_ERROR) { + ignoreCb(code); + } else if(fh == cfdp::FaultHandlerCodes::ABANDON_TRANSACTION) { + abandonCb(code); + } else if(fh == cfdp::FaultHandlerCodes::NOTICE_OF_CANCELLATION) { + noticeOfCancellationCb(code); + } else { + noticeOfSuspensionCb(code); + } + return true; +} CfdpFaultHandlerBase::~CfdpFaultHandlerBase() = default; diff --git a/src/fsfw/cfdp/FaultHandlerBase.h b/src/fsfw/cfdp/FaultHandlerBase.h index 0db0743f..fc18f1c7 100644 --- a/src/fsfw/cfdp/FaultHandlerBase.h +++ b/src/fsfw/cfdp/FaultHandlerBase.h @@ -10,8 +10,28 @@ class CfdpFaultHandlerBase { virtual ~CfdpFaultHandlerBase(); CfdpFaultHandlerBase(); + /** + * Get the fault handler code for the given condition code + * @param code + * @param handler [out] Will be set to the approrpiate handler for the condition code if + * it is valid + * @return + * - true if the condition code is valid + * - false otherwise + */ + bool getFaultHandler(cfdp::ConditionCode code, cfdp::FaultHandlerCodes& handler) const; + + bool setFaultHandler(cfdp::ConditionCode code, cfdp::FaultHandlerCodes handler); + + bool faultCallback(cfdp::ConditionCode code); + + virtual void noticeOfSuspensionCb(cfdp::ConditionCode code) = 0; + virtual void noticeOfCancellationCb(cfdp::ConditionCode code) = 0; + virtual void abandonCb(cfdp::ConditionCode code) = 0; + virtual void ignoreCb(cfdp::ConditionCode code) = 0; + private: - etl::flat_map handleMap = { + etl::flat_map faultHandlerMap = { etl::pair{cfdp::ConditionCode::POSITIVE_ACK_LIMIT_REACHED, cfdp::FaultHandlerCodes::IGNORE_ERROR}, etl::pair{cfdp::ConditionCode::KEEP_ALIVE_LIMIT_REACHED, diff --git a/src/fsfw/cfdp/definitions.h b/src/fsfw/cfdp/definitions.h index 67e1edd4..b97b9b27 100644 --- a/src/fsfw/cfdp/definitions.h +++ b/src/fsfw/cfdp/definitions.h @@ -6,7 +6,6 @@ #include #include -#include "fsfw/cfdp/pdu/PduHeaderIF.h" #include "fsfw/returnvalues/FwClassIds.h" #include "fsfw/returnvalues/HasReturnvaluesIF.h" @@ -134,20 +133,6 @@ enum RecordContinuationState { CONTAINS_START_AND_END = 0b11 }; -struct IndicationCfg { - bool eofSentIndicRequired = true; - bool eofRecvIndicRequired = true; - bool fileSegmentRecvIndicRequired = true; - bool transactionFinishedIndicRequired = true; - bool suspendedIndicRequired = true; - bool resumedIndicRequired = true; -}; - -struct LocalEntityCfg { - EntityId localId; - IndicationCfg indicCfg; -}; - } // namespace cfdp #endif /* FSFW_SRC_FSFW_CFDP_PDU_DEFINITIONS_H_ */ diff --git a/src/fsfw/cfdp/mib.h b/src/fsfw/cfdp/mib.h new file mode 100644 index 00000000..3a8c96d5 --- /dev/null +++ b/src/fsfw/cfdp/mib.h @@ -0,0 +1,19 @@ +#ifndef FSFW_CFDP_MIB_H +#define FSFW_CFDP_MIB_H + +struct IndicationCfg { + bool eofSentIndicRequired = true; + bool eofRecvIndicRequired = true; + bool fileSegmentRecvIndicRequired = true; + bool transactionFinishedIndicRequired = true; + bool suspendedIndicRequired = true; + bool resumedIndicRequired = true; +}; + +struct LocalEntityCfg { + cfdp::EntityId localId; + IndicationCfg indicCfg; +}; + + +#endif // FSFW_CFDP_MIB_H diff --git a/src/fsfw/cfdp/pdu/HeaderCreator.cpp b/src/fsfw/cfdp/pdu/HeaderCreator.cpp index d70e8270..1a7afe0d 100644 --- a/src/fsfw/cfdp/pdu/HeaderCreator.cpp +++ b/src/fsfw/cfdp/pdu/HeaderCreator.cpp @@ -1,7 +1,5 @@ #include "HeaderCreator.h" -#include "HeaderReader.h" - HeaderCreator::HeaderCreator(PduConfig &pduConf, cfdp::PduType pduType, size_t initPduDataFieldLen, cfdp::SegmentMetadataFlag segmentMetadataFlag, cfdp::SegmentationControl segCtrl) diff --git a/src/fsfw/cfdp/pdu/HeaderCreator.h b/src/fsfw/cfdp/pdu/HeaderCreator.h index a9f9b581..bbb4a518 100644 --- a/src/fsfw/cfdp/pdu/HeaderCreator.h +++ b/src/fsfw/cfdp/pdu/HeaderCreator.h @@ -1,9 +1,9 @@ #ifndef FSFW_SRC_FSFW_CFDP_PDU_HEADERSERIALIZER_H_ #define FSFW_SRC_FSFW_CFDP_PDU_HEADERSERIALIZER_H_ -#include "../definitions.h" #include "PduConfig.h" #include "PduHeaderIF.h" +#include "fsfw/cfdp/definitions.h" #include "fsfw/serialize/SerializeIF.h" class HeaderCreator : public SerializeIF, public PduHeaderIF { @@ -23,7 +23,7 @@ class HeaderCreator : public SerializeIF, public PduHeaderIF { * data field length was not properly. * @return */ - size_t getSerializedSize() const override; + [[nodiscard]] size_t getSerializedSize() const override; ReturnValue_t deSerialize(const uint8_t** buffer, size_t* size, Endianness streamEndianness) override; @@ -32,19 +32,19 @@ class HeaderCreator : public SerializeIF, public PduHeaderIF { void setPduType(cfdp::PduType pduType); void setSegmentMetadataFlag(cfdp::SegmentMetadataFlag); - size_t getPduDataFieldLen() const override; - size_t getWholePduSize() const override; + [[nodiscard]] size_t getPduDataFieldLen() const override; + [[nodiscard]] size_t getWholePduSize() const override; - cfdp::PduType getPduType() const override; - cfdp::Direction getDirection() const override; - cfdp::TransmissionModes getTransmissionMode() const override; - bool getCrcFlag() const override; - bool getLargeFileFlag() const override; - cfdp::SegmentationControl getSegmentationControl() const override; - cfdp::WidthInBytes getLenEntityIds() const override; - cfdp::WidthInBytes getLenSeqNum() const override; - cfdp::SegmentMetadataFlag getSegmentMetadataFlag() const override; - bool hasSegmentMetadataFlag() const override; + [[nodiscard]] cfdp::PduType getPduType() const override; + [[nodiscard]] cfdp::Direction getDirection() const override; + [[nodiscard]] cfdp::TransmissionModes getTransmissionMode() const override; + [[nodiscard]] bool getCrcFlag() const override; + [[nodiscard]] bool getLargeFileFlag() const override; + [[nodiscard]] cfdp::SegmentationControl getSegmentationControl() const override; + [[nodiscard]] cfdp::WidthInBytes getLenEntityIds() const override; + [[nodiscard]] cfdp::WidthInBytes getLenSeqNum() const override; + [[nodiscard]] cfdp::SegmentMetadataFlag getSegmentMetadataFlag() const override; + [[nodiscard]] bool hasSegmentMetadataFlag() const override; void setSegmentationControl(cfdp::SegmentationControl); void getSourceId(cfdp::EntityId& sourceId) const override; diff --git a/src/fsfw/cfdp/pdu/PduConfig.h b/src/fsfw/cfdp/pdu/PduConfig.h index 858176ff..a008f18d 100644 --- a/src/fsfw/cfdp/pdu/PduConfig.h +++ b/src/fsfw/cfdp/pdu/PduConfig.h @@ -1,6 +1,7 @@ #ifndef FSFW_SRC_FSFW_CFDP_PDU_PDUCONFIG_H_ #define FSFW_SRC_FSFW_CFDP_PDU_PDUCONFIG_H_ +#include "fsfw/cfdp/definitions.h" #include "VarLenField.h" namespace cfdp { @@ -21,7 +22,7 @@ struct TransactionSeqNum : public VarLenField { TransactionSeqNum(cfdp::WidthInBytes width, size_t seqNum) : VarLenField(width, seqNum) {} }; -} // namespace cfdp +} class PduConfig { public: diff --git a/src/fsfw/cfdp/pdu/PduHeaderIF.h b/src/fsfw/cfdp/pdu/PduHeaderIF.h index 86956ff0..a8d007b6 100644 --- a/src/fsfw/cfdp/pdu/PduHeaderIF.h +++ b/src/fsfw/cfdp/pdu/PduHeaderIF.h @@ -3,8 +3,8 @@ #include -#include "../definitions.h" #include "PduConfig.h" +#include "fsfw/cfdp/definitions.h" /** * @brief Generic interface to access all fields of a PDU header diff --git a/src/fsfw/cfdp/pdu/VarLenField.cpp b/src/fsfw/cfdp/pdu/VarLenField.cpp index a403534b..1f4d2429 100644 --- a/src/fsfw/cfdp/pdu/VarLenField.cpp +++ b/src/fsfw/cfdp/pdu/VarLenField.cpp @@ -1,6 +1,5 @@ #include "VarLenField.h" -#include "fsfw/FSFW.h" #include "fsfw/serialize/SerializeAdapter.h" #include "fsfw/serviceinterface.h" diff --git a/src/fsfw/cfdp/pdu/VarLenField.h b/src/fsfw/cfdp/pdu/VarLenField.h index 7f8a1acb..819e8ccd 100644 --- a/src/fsfw/cfdp/pdu/VarLenField.h +++ b/src/fsfw/cfdp/pdu/VarLenField.h @@ -1,5 +1,5 @@ -#ifndef FSFW_SRC_FSFW_CFDP_PDU_VARLENFIELD_H_ -#define FSFW_SRC_FSFW_CFDP_PDU_VARLENFIELD_H_ +#ifndef FSFW_CFDP_PDU_VARLENFIELD_H_ +#define FSFW_CFDP_PDU_VARLENFIELD_H_ #include #include @@ -7,6 +7,7 @@ #include "fsfw/cfdp/definitions.h" #include "fsfw/serialize/SerializeIF.h" #include "fsfw/util/UnsignedByteField.h" + namespace cfdp { class VarLenField : public SerializeIF { @@ -21,6 +22,7 @@ class VarLenField : public SerializeIF { VarLenField(); template explicit VarLenField(UnsignedByteField byteField); + VarLenField(cfdp::WidthInBytes width, size_t value); bool operator==(const VarLenField &other) const; @@ -49,11 +51,11 @@ class VarLenField : public SerializeIF { template cfdp::VarLenField::VarLenField(UnsignedByteField byteField) - : width(static_cast(sizeof(T))) { + : width(static_cast(sizeof(T))) { static_assert((sizeof(T) % 2) == 0); setValue(width, byteField.getValue()); } } // namespace cfdp -#endif /* FSFW_SRC_FSFW_CFDP_PDU_VARLENFIELD_H_ */ +#endif /* FSFW_CFDP_PDU_VARLENFIELD_H_ */ From dba3f9960ef56db30011f9ff73bf6a3aa5e07549 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Tue, 9 Aug 2022 14:55:08 +0200 Subject: [PATCH 037/169] add CFDP fault handler mock --- src/fsfw/cfdp/FaultHandlerBase.cpp | 23 +++++------ src/fsfw/cfdp/FaultHandlerBase.h | 10 +++-- src/fsfw/cfdp/mib.h | 1 - src/fsfw/cfdp/pdu/PduConfig.h | 4 +- unittests/cfdp/CMakeLists.txt | 22 +++-------- unittests/cfdp/handler/CMakeLists.txt | 1 + .../cfdp/{ => handler}/testDestHandler.cpp | 0 .../cfdp/{ => handler}/testDistributor.cpp | 0 unittests/cfdp/pdu/CMakeLists.txt | 13 +++++++ unittests/cfdp/{ => pdu}/testAckPdu.cpp | 0 unittests/cfdp/{ => pdu}/testCfdpHeader.cpp | 0 unittests/cfdp/{ => pdu}/testEofPdu.cpp | 0 unittests/cfdp/{ => pdu}/testFileData.cpp | 0 .../cfdp/{ => pdu}/testFileDirective.cpp | 0 unittests/cfdp/{ => pdu}/testFinishedPdu.cpp | 0 unittests/cfdp/{ => pdu}/testKeepAlivePdu.cpp | 0 unittests/cfdp/{ => pdu}/testMetadataPdu.cpp | 3 +- unittests/cfdp/{ => pdu}/testNakPdu.cpp | 0 unittests/cfdp/{ => pdu}/testPromptPdu.cpp | 0 unittests/mocks/CMakeLists.txt | 3 +- unittests/mocks/CfdpFaultHandlerMock.cpp | 38 +++++++++++++++++++ unittests/mocks/CfdpFaultHandlerMock.h | 32 ++++++++++++++++ 22 files changed, 113 insertions(+), 37 deletions(-) create mode 100644 unittests/cfdp/handler/CMakeLists.txt rename unittests/cfdp/{ => handler}/testDestHandler.cpp (100%) rename unittests/cfdp/{ => handler}/testDistributor.cpp (100%) create mode 100644 unittests/cfdp/pdu/CMakeLists.txt rename unittests/cfdp/{ => pdu}/testAckPdu.cpp (100%) rename unittests/cfdp/{ => pdu}/testCfdpHeader.cpp (100%) rename unittests/cfdp/{ => pdu}/testEofPdu.cpp (100%) rename unittests/cfdp/{ => pdu}/testFileData.cpp (100%) rename unittests/cfdp/{ => pdu}/testFileDirective.cpp (100%) rename unittests/cfdp/{ => pdu}/testFinishedPdu.cpp (100%) rename unittests/cfdp/{ => pdu}/testKeepAlivePdu.cpp (100%) rename unittests/cfdp/{ => pdu}/testMetadataPdu.cpp (99%) rename unittests/cfdp/{ => pdu}/testNakPdu.cpp (100%) rename unittests/cfdp/{ => pdu}/testPromptPdu.cpp (100%) create mode 100644 unittests/mocks/CfdpFaultHandlerMock.cpp create mode 100644 unittests/mocks/CfdpFaultHandlerMock.h diff --git a/src/fsfw/cfdp/FaultHandlerBase.cpp b/src/fsfw/cfdp/FaultHandlerBase.cpp index 06edabd6..91c3afe4 100644 --- a/src/fsfw/cfdp/FaultHandlerBase.cpp +++ b/src/fsfw/cfdp/FaultHandlerBase.cpp @@ -1,19 +1,21 @@ #include "FaultHandlerBase.h" -CfdpFaultHandlerBase::CfdpFaultHandlerBase() = default; +namespace cfdp { -bool CfdpFaultHandlerBase::getFaultHandler( - cfdp::ConditionCode code, cfdp::FaultHandlerCodes& handler) const { +FaultHandlerBase::FaultHandlerBase() = default; +FaultHandlerBase::~FaultHandlerBase() = default; + +bool FaultHandlerBase::getFaultHandler(cfdp::ConditionCode code, + cfdp::FaultHandlerCodes& handler) const { auto iter = faultHandlerMap.find(code); - if(iter == faultHandlerMap.end()) { + if (iter == faultHandlerMap.end()) { return false; } handler = iter->second; return true; } -bool CfdpFaultHandlerBase::setFaultHandler(cfdp::ConditionCode code, - cfdp::FaultHandlerCodes handler) { +bool FaultHandlerBase::setFaultHandler(cfdp::ConditionCode code, cfdp::FaultHandlerCodes handler) { if (not faultHandlerMap.contains(code)) { return false; } @@ -21,21 +23,20 @@ bool CfdpFaultHandlerBase::setFaultHandler(cfdp::ConditionCode code, return true; } -bool CfdpFaultHandlerBase::faultCallback(cfdp::ConditionCode code) { +bool FaultHandlerBase::faultCallback(cfdp::ConditionCode code) { if (not faultHandlerMap.contains(code)) { return false; } cfdp::FaultHandlerCodes fh = faultHandlerMap[code]; if (fh == cfdp::FaultHandlerCodes::IGNORE_ERROR) { ignoreCb(code); - } else if(fh == cfdp::FaultHandlerCodes::ABANDON_TRANSACTION) { + } else if (fh == cfdp::FaultHandlerCodes::ABANDON_TRANSACTION) { abandonCb(code); - } else if(fh == cfdp::FaultHandlerCodes::NOTICE_OF_CANCELLATION) { + } else if (fh == cfdp::FaultHandlerCodes::NOTICE_OF_CANCELLATION) { noticeOfCancellationCb(code); } else { noticeOfSuspensionCb(code); } return true; } - -CfdpFaultHandlerBase::~CfdpFaultHandlerBase() = default; +} // namespace cfdp diff --git a/src/fsfw/cfdp/FaultHandlerBase.h b/src/fsfw/cfdp/FaultHandlerBase.h index fc18f1c7..6a4abc8b 100644 --- a/src/fsfw/cfdp/FaultHandlerBase.h +++ b/src/fsfw/cfdp/FaultHandlerBase.h @@ -5,10 +5,12 @@ #include "definitions.h" -class CfdpFaultHandlerBase { +namespace cfdp { + +class FaultHandlerBase { public: - virtual ~CfdpFaultHandlerBase(); - CfdpFaultHandlerBase(); + virtual ~FaultHandlerBase(); + FaultHandlerBase(); /** * Get the fault handler code for the given condition code @@ -46,4 +48,6 @@ class CfdpFaultHandlerBase { cfdp::FaultHandlerCodes::IGNORE_ERROR}}; }; +} // namespace cfdp + #endif // FSFW_CFDP_FAULTHANDLERBASE_H diff --git a/src/fsfw/cfdp/mib.h b/src/fsfw/cfdp/mib.h index 3a8c96d5..c40034d4 100644 --- a/src/fsfw/cfdp/mib.h +++ b/src/fsfw/cfdp/mib.h @@ -15,5 +15,4 @@ struct LocalEntityCfg { IndicationCfg indicCfg; }; - #endif // FSFW_CFDP_MIB_H diff --git a/src/fsfw/cfdp/pdu/PduConfig.h b/src/fsfw/cfdp/pdu/PduConfig.h index a008f18d..48f3993b 100644 --- a/src/fsfw/cfdp/pdu/PduConfig.h +++ b/src/fsfw/cfdp/pdu/PduConfig.h @@ -1,8 +1,8 @@ #ifndef FSFW_SRC_FSFW_CFDP_PDU_PDUCONFIG_H_ #define FSFW_SRC_FSFW_CFDP_PDU_PDUCONFIG_H_ -#include "fsfw/cfdp/definitions.h" #include "VarLenField.h" +#include "fsfw/cfdp/definitions.h" namespace cfdp { @@ -22,7 +22,7 @@ struct TransactionSeqNum : public VarLenField { TransactionSeqNum(cfdp::WidthInBytes width, size_t seqNum) : VarLenField(width, seqNum) {} }; -} +} // namespace cfdp class PduConfig { public: diff --git a/unittests/cfdp/CMakeLists.txt b/unittests/cfdp/CMakeLists.txt index ac4672fa..4a574af2 100644 --- a/unittests/cfdp/CMakeLists.txt +++ b/unittests/cfdp/CMakeLists.txt @@ -1,17 +1,5 @@ -target_sources( - ${FSFW_TEST_TGT} - PRIVATE testCfdp.cpp - testTlvsLvs.cpp - testAckPdu.cpp - testEofPdu.cpp - testNakPdu.cpp - testFinishedPdu.cpp - testPromptPdu.cpp - testKeepAlivePdu.cpp - testMetadataPdu.cpp - testFileData.cpp - testCfdpHeader.cpp - testFileDirective.cpp - testDistributor.cpp - testDestHandler.cpp - testSourceHandler.cpp) +target_sources(${FSFW_TEST_TGT} PRIVATE testCfdp.cpp testTlvsLvs.cpp + testSourceHandler.cpp) + +add_subdirectory(handler) +add_subdirectory(pdu) diff --git a/unittests/cfdp/handler/CMakeLists.txt b/unittests/cfdp/handler/CMakeLists.txt new file mode 100644 index 00000000..a209b995 --- /dev/null +++ b/unittests/cfdp/handler/CMakeLists.txt @@ -0,0 +1 @@ +target_sources(${FSFW_TEST_TGT} PRIVATE testDistributor.cpp testDestHandler.cpp) diff --git a/unittests/cfdp/testDestHandler.cpp b/unittests/cfdp/handler/testDestHandler.cpp similarity index 100% rename from unittests/cfdp/testDestHandler.cpp rename to unittests/cfdp/handler/testDestHandler.cpp diff --git a/unittests/cfdp/testDistributor.cpp b/unittests/cfdp/handler/testDistributor.cpp similarity index 100% rename from unittests/cfdp/testDistributor.cpp rename to unittests/cfdp/handler/testDistributor.cpp diff --git a/unittests/cfdp/pdu/CMakeLists.txt b/unittests/cfdp/pdu/CMakeLists.txt new file mode 100644 index 00000000..02981217 --- /dev/null +++ b/unittests/cfdp/pdu/CMakeLists.txt @@ -0,0 +1,13 @@ +target_sources( + ${FSFW_TEST_TGT} + PRIVATE testAckPdu.cpp + testAckPdu.cpp + testEofPdu.cpp + testNakPdu.cpp + testFinishedPdu.cpp + testPromptPdu.cpp + testKeepAlivePdu.cpp + testMetadataPdu.cpp + testFileData.cpp + testCfdpHeader.cpp + testFileDirective.cpp) diff --git a/unittests/cfdp/testAckPdu.cpp b/unittests/cfdp/pdu/testAckPdu.cpp similarity index 100% rename from unittests/cfdp/testAckPdu.cpp rename to unittests/cfdp/pdu/testAckPdu.cpp diff --git a/unittests/cfdp/testCfdpHeader.cpp b/unittests/cfdp/pdu/testCfdpHeader.cpp similarity index 100% rename from unittests/cfdp/testCfdpHeader.cpp rename to unittests/cfdp/pdu/testCfdpHeader.cpp diff --git a/unittests/cfdp/testEofPdu.cpp b/unittests/cfdp/pdu/testEofPdu.cpp similarity index 100% rename from unittests/cfdp/testEofPdu.cpp rename to unittests/cfdp/pdu/testEofPdu.cpp diff --git a/unittests/cfdp/testFileData.cpp b/unittests/cfdp/pdu/testFileData.cpp similarity index 100% rename from unittests/cfdp/testFileData.cpp rename to unittests/cfdp/pdu/testFileData.cpp diff --git a/unittests/cfdp/testFileDirective.cpp b/unittests/cfdp/pdu/testFileDirective.cpp similarity index 100% rename from unittests/cfdp/testFileDirective.cpp rename to unittests/cfdp/pdu/testFileDirective.cpp diff --git a/unittests/cfdp/testFinishedPdu.cpp b/unittests/cfdp/pdu/testFinishedPdu.cpp similarity index 100% rename from unittests/cfdp/testFinishedPdu.cpp rename to unittests/cfdp/pdu/testFinishedPdu.cpp diff --git a/unittests/cfdp/testKeepAlivePdu.cpp b/unittests/cfdp/pdu/testKeepAlivePdu.cpp similarity index 100% rename from unittests/cfdp/testKeepAlivePdu.cpp rename to unittests/cfdp/pdu/testKeepAlivePdu.cpp diff --git a/unittests/cfdp/testMetadataPdu.cpp b/unittests/cfdp/pdu/testMetadataPdu.cpp similarity index 99% rename from unittests/cfdp/testMetadataPdu.cpp rename to unittests/cfdp/pdu/testMetadataPdu.cpp index 4ea15451..dec3b479 100644 --- a/unittests/cfdp/testMetadataPdu.cpp +++ b/unittests/cfdp/pdu/testMetadataPdu.cpp @@ -1,5 +1,3 @@ -#include - #include #include #include @@ -7,6 +5,7 @@ #include "fsfw/cfdp/pdu/MetadataPduCreator.h" #include "fsfw/cfdp/pdu/MetadataPduReader.h" #include "fsfw/cfdp/tlv/FilestoreResponseTlv.h" +#include "fsfw/cfdp/tlv/MessageToUserTlv.h" #include "fsfw/globalfunctions/arrayprinter.h" TEST_CASE("Metadata PDU", "[cfdp][pdu]") { diff --git a/unittests/cfdp/testNakPdu.cpp b/unittests/cfdp/pdu/testNakPdu.cpp similarity index 100% rename from unittests/cfdp/testNakPdu.cpp rename to unittests/cfdp/pdu/testNakPdu.cpp diff --git a/unittests/cfdp/testPromptPdu.cpp b/unittests/cfdp/pdu/testPromptPdu.cpp similarity index 100% rename from unittests/cfdp/testPromptPdu.cpp rename to unittests/cfdp/pdu/testPromptPdu.cpp diff --git a/unittests/mocks/CMakeLists.txt b/unittests/mocks/CMakeLists.txt index bc5649de..0ee7bf1e 100644 --- a/unittests/mocks/CMakeLists.txt +++ b/unittests/mocks/CMakeLists.txt @@ -14,4 +14,5 @@ target_sources( PusDistributorMock.cpp CcsdsCheckerMock.cpp AcceptsTcMock.cpp - StorageManagerMock.cpp) + StorageManagerMock.cpp + CfdpFaultHandlerMock.cpp) diff --git a/unittests/mocks/CfdpFaultHandlerMock.cpp b/unittests/mocks/CfdpFaultHandlerMock.cpp new file mode 100644 index 00000000..3f7c8896 --- /dev/null +++ b/unittests/mocks/CfdpFaultHandlerMock.cpp @@ -0,0 +1,38 @@ +#include "CfdpFaultHandlerMock.h" + +void CfdpFaultHandlerMock::noticeOfSuspensionCb(cfdp::ConditionCode code) { + auto& info = fhInfoMap.at(cfdp::FaultHandlerCodes::NOTICE_OF_SUSPENSION); + info.callCount++; + info.condCodes.push(code); +} + +void CfdpFaultHandlerMock::noticeOfCancellationCb(cfdp::ConditionCode code) { + auto& info = fhInfoMap.at(cfdp::FaultHandlerCodes::NOTICE_OF_CANCELLATION); + info.callCount++; + info.condCodes.push(code); +} + +void CfdpFaultHandlerMock::abandonCb(cfdp::ConditionCode code) { + auto& info = fhInfoMap.at(cfdp::FaultHandlerCodes::ABANDON_TRANSACTION); + info.callCount++; + info.condCodes.push(code); +} + +void CfdpFaultHandlerMock::ignoreCb(cfdp::ConditionCode code) { + auto& info = fhInfoMap.at(cfdp::FaultHandlerCodes::IGNORE_ERROR); + info.callCount++; + info.condCodes.push(code); +} + +CfdpFaultHandlerMock::FaultInfo& CfdpFaultHandlerMock::getFhInfo(cfdp::FaultHandlerCodes fhCode) { + return fhInfoMap.at(fhCode); +} + +void CfdpFaultHandlerMock::reset() { fhInfoMap.clear(); } + +bool CfdpFaultHandlerMock::faultCbWasCalled() const { + return std::any_of(fhInfoMap.begin(), fhInfoMap.end(), + [](const std::pair& pair) { + return pair.second.callCount > 0; + }); +} diff --git a/unittests/mocks/CfdpFaultHandlerMock.h b/unittests/mocks/CfdpFaultHandlerMock.h new file mode 100644 index 00000000..8003798e --- /dev/null +++ b/unittests/mocks/CfdpFaultHandlerMock.h @@ -0,0 +1,32 @@ +#ifndef FSFW_TESTS_CFDPFAULTHANDLERMOCK_H +#define FSFW_TESTS_CFDPFAULTHANDLERMOCK_H + +#include +#include + +#include "fsfw/cfdp/FaultHandlerBase.h" + +class CfdpFaultHandlerMock : public cfdp::FaultHandlerBase { + public: + struct FaultInfo { + size_t callCount = 0; + std::queue condCodes; + }; + + void noticeOfSuspensionCb(cfdp::ConditionCode code) override; + void noticeOfCancellationCb(cfdp::ConditionCode code) override; + void abandonCb(cfdp::ConditionCode code) override; + void ignoreCb(cfdp::ConditionCode code) override; + + FaultInfo& getFhInfo(cfdp::FaultHandlerCodes fhCode); + bool faultCbWasCalled() const; + void reset(); + + private: + std::map fhInfoMap = { + std::pair{cfdp::FaultHandlerCodes::IGNORE_ERROR, FaultInfo()}, + std::pair{cfdp::FaultHandlerCodes::NOTICE_OF_CANCELLATION, FaultInfo()}, + std::pair{cfdp::FaultHandlerCodes::NOTICE_OF_SUSPENSION, FaultInfo()}, + std::pair{cfdp::FaultHandlerCodes::ABANDON_TRANSACTION, FaultInfo()}}; +}; +#endif // FSFW_TESTS_CFDPFAULTHANDLERMOCK_H From 7f9401cf63e8ff932fa78ad28eea39b82714ceed Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Tue, 9 Aug 2022 15:09:43 +0200 Subject: [PATCH 038/169] some bugfixes --- src/fsfw/cfdp/FaultHandlerBase.cpp | 2 +- src/fsfw/cfdp/FaultHandlerBase.h | 8 +++-- unittests/cfdp/CMakeLists.txt | 3 +- unittests/cfdp/handler/CMakeLists.txt | 4 ++- unittests/cfdp/handler/testFaultHandler.cpp | 36 +++++++++++++++++++ .../cfdp/{ => handler}/testSourceHandler.cpp | 0 unittests/cfdp/pdu/testFileDirective.cpp | 2 +- unittests/mocks/CfdpFaultHandlerMock.h | 2 +- 8 files changed, 48 insertions(+), 9 deletions(-) create mode 100644 unittests/cfdp/handler/testFaultHandler.cpp rename unittests/cfdp/{ => handler}/testSourceHandler.cpp (100%) diff --git a/src/fsfw/cfdp/FaultHandlerBase.cpp b/src/fsfw/cfdp/FaultHandlerBase.cpp index 91c3afe4..443a1a92 100644 --- a/src/fsfw/cfdp/FaultHandlerBase.cpp +++ b/src/fsfw/cfdp/FaultHandlerBase.cpp @@ -23,7 +23,7 @@ bool FaultHandlerBase::setFaultHandler(cfdp::ConditionCode code, cfdp::FaultHand return true; } -bool FaultHandlerBase::faultCallback(cfdp::ConditionCode code) { +bool FaultHandlerBase::reportFault(cfdp::ConditionCode code) { if (not faultHandlerMap.contains(code)) { return false; } diff --git a/src/fsfw/cfdp/FaultHandlerBase.h b/src/fsfw/cfdp/FaultHandlerBase.h index 6a4abc8b..ba816161 100644 --- a/src/fsfw/cfdp/FaultHandlerBase.h +++ b/src/fsfw/cfdp/FaultHandlerBase.h @@ -25,7 +25,7 @@ class FaultHandlerBase { bool setFaultHandler(cfdp::ConditionCode code, cfdp::FaultHandlerCodes handler); - bool faultCallback(cfdp::ConditionCode code); + bool reportFault(cfdp::ConditionCode code); virtual void noticeOfSuspensionCb(cfdp::ConditionCode code) = 0; virtual void noticeOfCancellationCb(cfdp::ConditionCode code) = 0; @@ -33,7 +33,7 @@ class FaultHandlerBase { virtual void ignoreCb(cfdp::ConditionCode code) = 0; private: - etl::flat_map faultHandlerMap = { + etl::flat_map faultHandlerMap = { etl::pair{cfdp::ConditionCode::POSITIVE_ACK_LIMIT_REACHED, cfdp::FaultHandlerCodes::IGNORE_ERROR}, etl::pair{cfdp::ConditionCode::KEEP_ALIVE_LIMIT_REACHED, @@ -45,7 +45,9 @@ class FaultHandlerBase { etl::pair{cfdp::ConditionCode::NAK_LIMIT_REACHED, cfdp::FaultHandlerCodes::IGNORE_ERROR}, etl::pair{cfdp::ConditionCode::INACTIVITY_DETECTED, cfdp::FaultHandlerCodes::IGNORE_ERROR}, etl::pair{cfdp::ConditionCode::UNSUPPORTED_CHECKSUM_TYPE, - cfdp::FaultHandlerCodes::IGNORE_ERROR}}; + cfdp::FaultHandlerCodes::IGNORE_ERROR}, + etl::pair{cfdp::ConditionCode::FILESTORE_REJECTION, cfdp::FaultHandlerCodes::IGNORE_ERROR}, + etl::pair{cfdp::ConditionCode::CHECK_LIMIT_REACHED, cfdp::FaultHandlerCodes::IGNORE_ERROR}}; }; } // namespace cfdp diff --git a/unittests/cfdp/CMakeLists.txt b/unittests/cfdp/CMakeLists.txt index 4a574af2..402381f4 100644 --- a/unittests/cfdp/CMakeLists.txt +++ b/unittests/cfdp/CMakeLists.txt @@ -1,5 +1,4 @@ -target_sources(${FSFW_TEST_TGT} PRIVATE testCfdp.cpp testTlvsLvs.cpp - testSourceHandler.cpp) +target_sources(${FSFW_TEST_TGT} PRIVATE testCfdp.cpp testTlvsLvs.cpp) add_subdirectory(handler) add_subdirectory(pdu) diff --git a/unittests/cfdp/handler/CMakeLists.txt b/unittests/cfdp/handler/CMakeLists.txt index a209b995..f70e5dfb 100644 --- a/unittests/cfdp/handler/CMakeLists.txt +++ b/unittests/cfdp/handler/CMakeLists.txt @@ -1 +1,3 @@ -target_sources(${FSFW_TEST_TGT} PRIVATE testDistributor.cpp testDestHandler.cpp) +target_sources( + ${FSFW_TEST_TGT} PRIVATE testDistributor.cpp testDestHandler.cpp + testSourceHandler.cpp testFaultHandler.cpp) diff --git a/unittests/cfdp/handler/testFaultHandler.cpp b/unittests/cfdp/handler/testFaultHandler.cpp new file mode 100644 index 00000000..bea16889 --- /dev/null +++ b/unittests/cfdp/handler/testFaultHandler.cpp @@ -0,0 +1,36 @@ +#include + +#include "mocks/CfdpFaultHandlerMock.h" + +TEST_CASE("CFDP Fault Handler", "[cfdp]") { + using namespace cfdp; + auto fhMock = CfdpFaultHandlerMock(); + cfdp::FaultHandlerCodes fhCode; + SECTION("State") { + // Verify initial condition + CHECK(fhMock.getFaultHandler(ConditionCode::UNSUPPORTED_CHECKSUM_TYPE, fhCode)); + CHECK(fhCode == FaultHandlerCodes::IGNORE_ERROR); + CHECK(fhMock.getFaultHandler(ConditionCode::POSITIVE_ACK_LIMIT_REACHED, fhCode)); + CHECK(fhCode == FaultHandlerCodes::IGNORE_ERROR); + CHECK(fhMock.getFaultHandler(ConditionCode::KEEP_ALIVE_LIMIT_REACHED, fhCode)); + CHECK(fhCode == FaultHandlerCodes::IGNORE_ERROR); + CHECK(fhMock.getFaultHandler(ConditionCode::INVALID_TRANSMISSION_MODE, fhCode)); + CHECK(fhCode == FaultHandlerCodes::IGNORE_ERROR); + CHECK(fhMock.getFaultHandler(ConditionCode::FILESTORE_REJECTION, fhCode)); + CHECK(fhCode == FaultHandlerCodes::IGNORE_ERROR); + CHECK(fhMock.getFaultHandler(ConditionCode::FILE_CHECKSUM_FAILURE, fhCode)); + CHECK(fhCode == FaultHandlerCodes::IGNORE_ERROR); + CHECK(fhMock.getFaultHandler(ConditionCode::FILE_SIZE_ERROR, fhCode)); + CHECK(fhCode == FaultHandlerCodes::IGNORE_ERROR); + CHECK(fhMock.getFaultHandler(ConditionCode::NAK_LIMIT_REACHED, fhCode)); + CHECK(fhCode == FaultHandlerCodes::IGNORE_ERROR); + CHECK(fhMock.getFaultHandler(ConditionCode::INACTIVITY_DETECTED, fhCode)); + CHECK(fhCode == FaultHandlerCodes::IGNORE_ERROR); + CHECK(fhMock.getFaultHandler(ConditionCode::CHECK_LIMIT_REACHED, fhCode)); + CHECK(fhCode == FaultHandlerCodes::IGNORE_ERROR); + } + + SECTION("Call Handler") { + fhMock.reportFault(ConditionCode::CHECK_LIMIT_REACHED); + } +} \ No newline at end of file diff --git a/unittests/cfdp/testSourceHandler.cpp b/unittests/cfdp/handler/testSourceHandler.cpp similarity index 100% rename from unittests/cfdp/testSourceHandler.cpp rename to unittests/cfdp/handler/testSourceHandler.cpp diff --git a/unittests/cfdp/pdu/testFileDirective.cpp b/unittests/cfdp/pdu/testFileDirective.cpp index b694cd68..3dfaaa57 100644 --- a/unittests/cfdp/pdu/testFileDirective.cpp +++ b/unittests/cfdp/pdu/testFileDirective.cpp @@ -4,7 +4,7 @@ #include "fsfw/cfdp/pdu/FileDirectiveCreator.h" #include "fsfw/cfdp/pdu/FileDirectiveReader.h" -TEST_CASE("CFDP File Directive", "[cfdp]") { +TEST_CASE("CFDP File Directive", "[cfdp][pdu]") { using namespace cfdp; std::array serBuf{}; ReturnValue_t result; diff --git a/unittests/mocks/CfdpFaultHandlerMock.h b/unittests/mocks/CfdpFaultHandlerMock.h index 8003798e..ae7b251e 100644 --- a/unittests/mocks/CfdpFaultHandlerMock.h +++ b/unittests/mocks/CfdpFaultHandlerMock.h @@ -19,7 +19,7 @@ class CfdpFaultHandlerMock : public cfdp::FaultHandlerBase { void ignoreCb(cfdp::ConditionCode code) override; FaultInfo& getFhInfo(cfdp::FaultHandlerCodes fhCode); - bool faultCbWasCalled() const; + [[nodiscard]] bool faultCbWasCalled() const; void reset(); private: From 4ee01e395bd4dc72f1aec1fc0dbb7880af5fef4f Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Tue, 9 Aug 2022 15:29:22 +0200 Subject: [PATCH 039/169] finished fault handler unit tests --- src/fsfw/cfdp/FaultHandlerBase.cpp | 11 ++++- unittests/cfdp/handler/testFaultHandler.cpp | 55 ++++++++++++++++++++- 2 files changed, 63 insertions(+), 3 deletions(-) diff --git a/src/fsfw/cfdp/FaultHandlerBase.cpp b/src/fsfw/cfdp/FaultHandlerBase.cpp index 443a1a92..1dbfce0d 100644 --- a/src/fsfw/cfdp/FaultHandlerBase.cpp +++ b/src/fsfw/cfdp/FaultHandlerBase.cpp @@ -19,6 +19,12 @@ bool FaultHandlerBase::setFaultHandler(cfdp::ConditionCode code, cfdp::FaultHand if (not faultHandlerMap.contains(code)) { return false; } + if (handler != FaultHandlerCodes::NOTICE_OF_SUSPENSION and + handler != FaultHandlerCodes::ABANDON_TRANSACTION and + handler != FaultHandlerCodes::NOTICE_OF_CANCELLATION and + handler != FaultHandlerCodes::IGNORE_ERROR) { + return false; + } faultHandlerMap[code] = handler; return true; } @@ -34,8 +40,11 @@ bool FaultHandlerBase::reportFault(cfdp::ConditionCode code) { abandonCb(code); } else if (fh == cfdp::FaultHandlerCodes::NOTICE_OF_CANCELLATION) { noticeOfCancellationCb(code); - } else { + } else if (fh == cfdp::FaultHandlerCodes::NOTICE_OF_SUSPENSION) { noticeOfSuspensionCb(code); + } else { + // Should never happen, but use defensive programming + return false; } return true; } diff --git a/unittests/cfdp/handler/testFaultHandler.cpp b/unittests/cfdp/handler/testFaultHandler.cpp index bea16889..e6fb4547 100644 --- a/unittests/cfdp/handler/testFaultHandler.cpp +++ b/unittests/cfdp/handler/testFaultHandler.cpp @@ -6,6 +6,7 @@ TEST_CASE("CFDP Fault Handler", "[cfdp]") { using namespace cfdp; auto fhMock = CfdpFaultHandlerMock(); cfdp::FaultHandlerCodes fhCode; + SECTION("State") { // Verify initial condition CHECK(fhMock.getFaultHandler(ConditionCode::UNSUPPORTED_CHECKSUM_TYPE, fhCode)); @@ -30,7 +31,57 @@ TEST_CASE("CFDP Fault Handler", "[cfdp]") { CHECK(fhCode == FaultHandlerCodes::IGNORE_ERROR); } - SECTION("Call Handler") { - fhMock.reportFault(ConditionCode::CHECK_LIMIT_REACHED); + SECTION("Call Handler, Ignore Fault") { + auto& info = fhMock.getFhInfo(FaultHandlerCodes::IGNORE_ERROR); + CHECK(fhMock.reportFault(ConditionCode::CHECK_LIMIT_REACHED)); + CHECK(info.callCount == 1); + CHECK(info.condCodes.back() == ConditionCode::CHECK_LIMIT_REACHED); + fhMock.reportFault(ConditionCode::FILE_CHECKSUM_FAILURE); + CHECK(info.callCount == 2); + CHECK(info.condCodes.back() == ConditionCode::FILE_CHECKSUM_FAILURE); + } + + SECTION("Invalid Reported Code") { CHECK(not fhMock.reportFault(ConditionCode::NO_ERROR)); } + + SECTION("Invalid FH code"){ + CHECK(not fhMock.setFaultHandler(ConditionCode::KEEP_ALIVE_LIMIT_REACHED, FaultHandlerCodes::RESERVED)); + CHECK(fhMock.getFaultHandler(ConditionCode::KEEP_ALIVE_LIMIT_REACHED, fhCode)); + CHECK(fhCode == FaultHandlerCodes::IGNORE_ERROR); + CHECK(not fhMock.setFaultHandler(ConditionCode::NO_ERROR, FaultHandlerCodes::IGNORE_ERROR)); + CHECK(not fhMock.getFaultHandler(ConditionCode::NO_ERROR, fhCode)); + } + + SECTION("Set Other Fault Handler") { + CHECK(fhMock.setFaultHandler(ConditionCode::FILE_CHECKSUM_FAILURE, + FaultHandlerCodes::NOTICE_OF_CANCELLATION)); + CHECK(fhMock.setFaultHandler(ConditionCode::INACTIVITY_DETECTED, + FaultHandlerCodes::ABANDON_TRANSACTION)); + CHECK(fhMock.setFaultHandler(ConditionCode::KEEP_ALIVE_LIMIT_REACHED, + FaultHandlerCodes::NOTICE_OF_SUSPENSION)); + auto& ignoreInfo = fhMock.getFhInfo(FaultHandlerCodes::IGNORE_ERROR); + auto& cancellationInfo = fhMock.getFhInfo(FaultHandlerCodes::NOTICE_OF_CANCELLATION); + auto& suspensionInfo = fhMock.getFhInfo(FaultHandlerCodes::NOTICE_OF_SUSPENSION); + auto& abandonInfo = fhMock.getFhInfo(FaultHandlerCodes::ABANDON_TRANSACTION); + + CHECK(fhMock.reportFault(ConditionCode::FILE_CHECKSUM_FAILURE)); + CHECK(cancellationInfo.callCount == 1); + CHECK(cancellationInfo.condCodes.back() == ConditionCode::FILE_CHECKSUM_FAILURE); + CHECK(ignoreInfo.callCount == 0); + CHECK(suspensionInfo.callCount == 0); + CHECK(abandonInfo.callCount == 0); + + CHECK(fhMock.reportFault(ConditionCode::INACTIVITY_DETECTED)); + CHECK(cancellationInfo.callCount == 1); + CHECK(ignoreInfo.callCount == 0); + CHECK(suspensionInfo.callCount == 0); + CHECK(abandonInfo.callCount == 1); + CHECK(abandonInfo.condCodes.back() == ConditionCode::INACTIVITY_DETECTED); + + CHECK(fhMock.reportFault(ConditionCode::KEEP_ALIVE_LIMIT_REACHED)); + CHECK(cancellationInfo.callCount == 1); + CHECK(ignoreInfo.callCount == 0); + CHECK(suspensionInfo.callCount == 1); + CHECK(suspensionInfo.condCodes.back() == ConditionCode::KEEP_ALIVE_LIMIT_REACHED); + CHECK(abandonInfo.callCount == 1); } } \ No newline at end of file From dce1ebcf65765cf19383dbbdf29d84c687f73696 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Tue, 9 Aug 2022 15:46:42 +0200 Subject: [PATCH 040/169] add CFDP user base --- src/fsfw/cfdp.h | 8 ++++++++ src/fsfw/cfdp/CMakeLists.txt | 7 ++----- src/fsfw/cfdp/CfdpDestHandler.cpp | 1 - src/fsfw/cfdp/CfdpDestHandler.h | 15 --------------- src/fsfw/cfdp/CfdpSourceHandler.cpp | 1 - src/fsfw/cfdp/handler/CMakeLists.txt | 2 ++ src/fsfw/cfdp/handler/DestHandler.cpp | 5 +++++ src/fsfw/cfdp/handler/DestHandler.h | 19 +++++++++++++++++++ .../cfdp/{ => handler}/FaultHandlerBase.cpp | 0 .../cfdp/{ => handler}/FaultHandlerBase.h | 2 +- src/fsfw/cfdp/handler/SourceHandler.cpp | 1 + .../SourceHandler.h} | 2 +- src/fsfw/cfdp/handler/UserBase.cpp | 3 +++ src/fsfw/cfdp/handler/UserBase.h | 18 ++++++++++++++++++ src/fsfw/cfdp/{ => handler}/mib.h | 14 +++++++++++++- unittests/cfdp/handler/testDestHandler.cpp | 10 +++++++++- unittests/cfdp/handler/testFaultHandler.cpp | 13 +++++++------ unittests/mocks/CfdpFaultHandlerMock.h | 2 +- 18 files changed, 90 insertions(+), 33 deletions(-) create mode 100644 src/fsfw/cfdp.h delete mode 100644 src/fsfw/cfdp/CfdpDestHandler.cpp delete mode 100644 src/fsfw/cfdp/CfdpDestHandler.h delete mode 100644 src/fsfw/cfdp/CfdpSourceHandler.cpp create mode 100644 src/fsfw/cfdp/handler/CMakeLists.txt create mode 100644 src/fsfw/cfdp/handler/DestHandler.cpp create mode 100644 src/fsfw/cfdp/handler/DestHandler.h rename src/fsfw/cfdp/{ => handler}/FaultHandlerBase.cpp (100%) rename src/fsfw/cfdp/{ => handler}/FaultHandlerBase.h (98%) create mode 100644 src/fsfw/cfdp/handler/SourceHandler.cpp rename src/fsfw/cfdp/{CfdpSourceHandler.h => handler/SourceHandler.h} (80%) create mode 100644 src/fsfw/cfdp/handler/UserBase.cpp create mode 100644 src/fsfw/cfdp/handler/UserBase.h rename src/fsfw/cfdp/{ => handler}/mib.h (56%) diff --git a/src/fsfw/cfdp.h b/src/fsfw/cfdp.h new file mode 100644 index 00000000..421a7fe1 --- /dev/null +++ b/src/fsfw/cfdp.h @@ -0,0 +1,8 @@ +#ifndef FSFW_CFDP_H +#define FSFW_CFDP_H + +#include "cfdp/definitions.h" +#include "cfdp/handler/DestHandler.h" +#include "cfdp/handler/FaultHandlerBase.h" + +#endif // FSFW_CFDP_H diff --git a/src/fsfw/cfdp/CMakeLists.txt b/src/fsfw/cfdp/CMakeLists.txt index df83bd7f..72324a53 100644 --- a/src/fsfw/cfdp/CMakeLists.txt +++ b/src/fsfw/cfdp/CMakeLists.txt @@ -1,8 +1,5 @@ -target_sources( - ${LIB_FSFW_NAME} - PRIVATE CfdpMessage.cpp CfdpDistributor.cpp CfdpSourceHandler.cpp - CfdpDestHandler.cpp FaultHandlerBase.cpp) +target_sources(${LIB_FSFW_NAME} PRIVATE CfdpMessage.cpp CfdpDistributor.cpp) -# CfdpDistributor.cpp CfdpHandler.cpp add_subdirectory(pdu) add_subdirectory(tlv) +add_subdirectory(handler) diff --git a/src/fsfw/cfdp/CfdpDestHandler.cpp b/src/fsfw/cfdp/CfdpDestHandler.cpp deleted file mode 100644 index f3eb657a..00000000 --- a/src/fsfw/cfdp/CfdpDestHandler.cpp +++ /dev/null @@ -1 +0,0 @@ -#include "CfdpDestHandler.h" diff --git a/src/fsfw/cfdp/CfdpDestHandler.h b/src/fsfw/cfdp/CfdpDestHandler.h deleted file mode 100644 index e317cc4f..00000000 --- a/src/fsfw/cfdp/CfdpDestHandler.h +++ /dev/null @@ -1,15 +0,0 @@ -#ifndef FSFW_CFDP_CFDPDESTHANDLER_H -#define FSFW_CFDP_CFDPDESTHANDLER_H - -#include - -#include "fsfw/cfdp/pdu/PduConfig.h" - -class CfdpDestHandler { - public: - CfdpDestHandler(); - - private: -}; - -#endif // FSFW_CFDP_CFDPDESTHANDLER_H diff --git a/src/fsfw/cfdp/CfdpSourceHandler.cpp b/src/fsfw/cfdp/CfdpSourceHandler.cpp deleted file mode 100644 index c4b42d55..00000000 --- a/src/fsfw/cfdp/CfdpSourceHandler.cpp +++ /dev/null @@ -1 +0,0 @@ -#include "CfdpSourceHandler.h" diff --git a/src/fsfw/cfdp/handler/CMakeLists.txt b/src/fsfw/cfdp/handler/CMakeLists.txt new file mode 100644 index 00000000..7ad995c0 --- /dev/null +++ b/src/fsfw/cfdp/handler/CMakeLists.txt @@ -0,0 +1,2 @@ +target_sources(${LIB_FSFW_NAME} PRIVATE SourceHandler.cpp DestHandler.cpp + FaultHandlerBase.cpp UserBase.cpp) diff --git a/src/fsfw/cfdp/handler/DestHandler.cpp b/src/fsfw/cfdp/handler/DestHandler.cpp new file mode 100644 index 00000000..72f7951e --- /dev/null +++ b/src/fsfw/cfdp/handler/DestHandler.cpp @@ -0,0 +1,5 @@ +#include "DestHandler.h" + +#include + +cfdp::DestHandler::DestHandler(LocalEntityCfg cfg) : cfg(std::move(cfg)) {} diff --git a/src/fsfw/cfdp/handler/DestHandler.h b/src/fsfw/cfdp/handler/DestHandler.h new file mode 100644 index 00000000..e934fc9c --- /dev/null +++ b/src/fsfw/cfdp/handler/DestHandler.h @@ -0,0 +1,19 @@ +#ifndef FSFW_CFDP_CFDPDESTHANDLER_H +#define FSFW_CFDP_CFDPDESTHANDLER_H + +#include "fsfw/cfdp/handler/mib.h" +#include "fsfw/cfdp/pdu/PduConfig.h" + +namespace cfdp { + +class DestHandler { + public: + DestHandler(LocalEntityCfg cfg /*, CfdpUserBase& user, RemoteConfigTableIF& remoteConfigTable*/); + + private: + LocalEntityCfg cfg; +}; + +} // namespace cfdp + +#endif // FSFW_CFDP_CFDPDESTHANDLER_H diff --git a/src/fsfw/cfdp/FaultHandlerBase.cpp b/src/fsfw/cfdp/handler/FaultHandlerBase.cpp similarity index 100% rename from src/fsfw/cfdp/FaultHandlerBase.cpp rename to src/fsfw/cfdp/handler/FaultHandlerBase.cpp diff --git a/src/fsfw/cfdp/FaultHandlerBase.h b/src/fsfw/cfdp/handler/FaultHandlerBase.h similarity index 98% rename from src/fsfw/cfdp/FaultHandlerBase.h rename to src/fsfw/cfdp/handler/FaultHandlerBase.h index ba816161..2383f849 100644 --- a/src/fsfw/cfdp/FaultHandlerBase.h +++ b/src/fsfw/cfdp/handler/FaultHandlerBase.h @@ -3,7 +3,7 @@ #include -#include "definitions.h" +#include "fsfw/cfdp/definitions.h" namespace cfdp { diff --git a/src/fsfw/cfdp/handler/SourceHandler.cpp b/src/fsfw/cfdp/handler/SourceHandler.cpp new file mode 100644 index 00000000..513b25f3 --- /dev/null +++ b/src/fsfw/cfdp/handler/SourceHandler.cpp @@ -0,0 +1 @@ +#include "SourceHandler.h" diff --git a/src/fsfw/cfdp/CfdpSourceHandler.h b/src/fsfw/cfdp/handler/SourceHandler.h similarity index 80% rename from src/fsfw/cfdp/CfdpSourceHandler.h rename to src/fsfw/cfdp/handler/SourceHandler.h index b343a6ed..319cf258 100644 --- a/src/fsfw/cfdp/CfdpSourceHandler.h +++ b/src/fsfw/cfdp/handler/SourceHandler.h @@ -1,6 +1,6 @@ #ifndef FSFW_CFDP_CFDPSOURCEHANDLER_H #define FSFW_CFDP_CFDPSOURCEHANDLER_H -class CfdpSourceHandler {}; +class SourceHandler {}; #endif // FSFW_CFDP_CFDPSOURCEHANDLER_H diff --git a/src/fsfw/cfdp/handler/UserBase.cpp b/src/fsfw/cfdp/handler/UserBase.cpp new file mode 100644 index 00000000..212396fb --- /dev/null +++ b/src/fsfw/cfdp/handler/UserBase.cpp @@ -0,0 +1,3 @@ +#include "UserBase.h" + +cfdp::UserBase::UserBase(HasFileSystemIF& vfs) : vfs(vfs) {} diff --git a/src/fsfw/cfdp/handler/UserBase.h b/src/fsfw/cfdp/handler/UserBase.h new file mode 100644 index 00000000..c928789c --- /dev/null +++ b/src/fsfw/cfdp/handler/UserBase.h @@ -0,0 +1,18 @@ +#ifndef FSFW_CFDP_USERBASE_H +#define FSFW_CFDP_USERBASE_H + +#include "fsfw/memory/HasFileSystemIF.h" + +namespace cfdp { + +class UserBase { + public: + explicit UserBase(HasFileSystemIF& vfs); + + private: + HasFileSystemIF& vfs; +}; + +} // namespace cfdp + +#endif // FSFW_CFDP_USERBASE_H diff --git a/src/fsfw/cfdp/mib.h b/src/fsfw/cfdp/handler/mib.h similarity index 56% rename from src/fsfw/cfdp/mib.h rename to src/fsfw/cfdp/handler/mib.h index c40034d4..e78b0f4f 100644 --- a/src/fsfw/cfdp/mib.h +++ b/src/fsfw/cfdp/handler/mib.h @@ -1,6 +1,12 @@ #ifndef FSFW_CFDP_MIB_H #define FSFW_CFDP_MIB_H +#include + +#include "FaultHandlerBase.h" + +namespace cfdp { + struct IndicationCfg { bool eofSentIndicRequired = true; bool eofRecvIndicRequired = true; @@ -11,8 +17,14 @@ struct IndicationCfg { }; struct LocalEntityCfg { - cfdp::EntityId localId; + LocalEntityCfg(EntityId localId, IndicationCfg indicationCfg, FaultHandlerBase& fhBase) + : localId(std::move(localId)), indicCfg(indicationCfg), fhBase(fhBase) {} + + EntityId localId; IndicationCfg indicCfg; + FaultHandlerBase& fhBase; }; +} // namespace cfdp + #endif // FSFW_CFDP_MIB_H diff --git a/unittests/cfdp/handler/testDestHandler.cpp b/unittests/cfdp/handler/testDestHandler.cpp index bb2a5ac4..e2f95388 100644 --- a/unittests/cfdp/handler/testDestHandler.cpp +++ b/unittests/cfdp/handler/testDestHandler.cpp @@ -1,3 +1,11 @@ #include -TEST_CASE("CFDP Dest Handler", "[cfdp]") {} \ No newline at end of file +#include "fsfw/cfdp.h" + +TEST_CASE("CFDP Dest Handler", "[cfdp]") { + using namespace cfdp; + // auto localEntityCfg = LocalEntityCfg(); + // auto destHandler = DestHandler(); + + SECTION("State") {} +} \ No newline at end of file diff --git a/unittests/cfdp/handler/testFaultHandler.cpp b/unittests/cfdp/handler/testFaultHandler.cpp index e6fb4547..945e09b8 100644 --- a/unittests/cfdp/handler/testFaultHandler.cpp +++ b/unittests/cfdp/handler/testFaultHandler.cpp @@ -43,12 +43,13 @@ TEST_CASE("CFDP Fault Handler", "[cfdp]") { SECTION("Invalid Reported Code") { CHECK(not fhMock.reportFault(ConditionCode::NO_ERROR)); } - SECTION("Invalid FH code"){ - CHECK(not fhMock.setFaultHandler(ConditionCode::KEEP_ALIVE_LIMIT_REACHED, FaultHandlerCodes::RESERVED)); - CHECK(fhMock.getFaultHandler(ConditionCode::KEEP_ALIVE_LIMIT_REACHED, fhCode)); - CHECK(fhCode == FaultHandlerCodes::IGNORE_ERROR); - CHECK(not fhMock.setFaultHandler(ConditionCode::NO_ERROR, FaultHandlerCodes::IGNORE_ERROR)); - CHECK(not fhMock.getFaultHandler(ConditionCode::NO_ERROR, fhCode)); + SECTION("Invalid FH code") { + CHECK(not fhMock.setFaultHandler(ConditionCode::KEEP_ALIVE_LIMIT_REACHED, + FaultHandlerCodes::RESERVED)); + CHECK(fhMock.getFaultHandler(ConditionCode::KEEP_ALIVE_LIMIT_REACHED, fhCode)); + CHECK(fhCode == FaultHandlerCodes::IGNORE_ERROR); + CHECK(not fhMock.setFaultHandler(ConditionCode::NO_ERROR, FaultHandlerCodes::IGNORE_ERROR)); + CHECK(not fhMock.getFaultHandler(ConditionCode::NO_ERROR, fhCode)); } SECTION("Set Other Fault Handler") { diff --git a/unittests/mocks/CfdpFaultHandlerMock.h b/unittests/mocks/CfdpFaultHandlerMock.h index ae7b251e..721cf7e0 100644 --- a/unittests/mocks/CfdpFaultHandlerMock.h +++ b/unittests/mocks/CfdpFaultHandlerMock.h @@ -4,7 +4,7 @@ #include #include -#include "fsfw/cfdp/FaultHandlerBase.h" +#include "fsfw/cfdp/handler/FaultHandlerBase.h" class CfdpFaultHandlerMock : public cfdp::FaultHandlerBase { public: From 7a204123053c4a80697d1c33d9ee6904bb1df1af Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Tue, 9 Aug 2022 15:51:01 +0200 Subject: [PATCH 041/169] add user base documentation --- src/fsfw/cfdp/handler/UserBase.h | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/fsfw/cfdp/handler/UserBase.h b/src/fsfw/cfdp/handler/UserBase.h index c928789c..6c0f372e 100644 --- a/src/fsfw/cfdp/handler/UserBase.h +++ b/src/fsfw/cfdp/handler/UserBase.h @@ -7,6 +7,12 @@ namespace cfdp { class UserBase { public: + /** + * Create a user base class which is used to provides a user interface to interact with CFDP + * handlers. It is also used to pass the Virtual Filestore (VFS) Implementation to the CFDP + * handlers so the filestore operations can be mapped to the underlying filestore. + * @param vfs Virtual Filestore Object. Will be used for all file operations + */ explicit UserBase(HasFileSystemIF& vfs); private: From bba2d883b64675adf77ea0da3928e144b1d6aa54 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Tue, 9 Aug 2022 16:18:45 +0200 Subject: [PATCH 042/169] added some documentation --- src/fsfw/cfdp/handler/FaultHandlerBase.h | 21 +++++++++++++++++++++ src/fsfw/cfdp/handler/UserBase.h | 11 +++++++++-- 2 files changed, 30 insertions(+), 2 deletions(-) diff --git a/src/fsfw/cfdp/handler/FaultHandlerBase.h b/src/fsfw/cfdp/handler/FaultHandlerBase.h index 2383f849..48b9c42e 100644 --- a/src/fsfw/cfdp/handler/FaultHandlerBase.h +++ b/src/fsfw/cfdp/handler/FaultHandlerBase.h @@ -7,6 +7,27 @@ namespace cfdp { +/** + * @brief Provides a way to implement the fault handling procedures as specified + * in chapter 4.8 of the CFDP standard. + * + * @details + * It is passed into the CFDP handlers as part of the local entity configuration and provides + * a way to specify custom user error handlers. + * + * It does so by mapping each applicable CFDP condition code to a fault handler which + * is denoted by the four @cfdp::FaultHandlerCodes. This code is used to dispatch + * to a user-provided callback function: + * + * 1. @FaultHandlerCodes::IGNORE_ERROR -> @ignore_cb + * 2. @FaultHandlerCodes::NOTICE_OF_CANCELLATION` -> @notice_of_cancellation_cb + * 3. @FaultHandlerCodes::NOTICE_OF_SUSPENSION` -> @notice_of_suspension_cb + * 4. @FaultHandlerCodes::ABANDON_TRANSACTION` -> @abandon_transaction_cb + * + * For each error reported by @reportError, the appropriate fault handler callback + * will be called. The user provides the callbacks by providing a custom class which implements + * these base class and all abstract fault handler callbacks. + */ class FaultHandlerBase { public: virtual ~FaultHandlerBase(); diff --git a/src/fsfw/cfdp/handler/UserBase.h b/src/fsfw/cfdp/handler/UserBase.h index 6c0f372e..282db9e2 100644 --- a/src/fsfw/cfdp/handler/UserBase.h +++ b/src/fsfw/cfdp/handler/UserBase.h @@ -8,9 +8,16 @@ namespace cfdp { class UserBase { public: /** - * Create a user base class which is used to provides a user interface to interact with CFDP - * handlers. It is also used to pass the Virtual Filestore (VFS) Implementation to the CFDP + * @brief Base class which provides a user interface to interact with CFDP handlers. + * + * @details + * This class is also used to pass the Virtual Filestore (VFS) Implementation to the CFDP * handlers so the filestore operations can be mapped to the underlying filestore. + * + * It is used by implementing it in a child class and then passing it to the CFDP + * handler objects. The base class provides default implementation for the user indication + * primitives specified in the CFDP standard. The user can override these implementations + * to provide custom indication handlers. * @param vfs Virtual Filestore Object. Will be used for all file operations */ explicit UserBase(HasFileSystemIF& vfs); From 5bea92d2a41ab25a542de15809cb7e27cd4296e6 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Tue, 9 Aug 2022 16:26:37 +0200 Subject: [PATCH 043/169] some doc updates --- docs/api.rst | 1 + docs/api/cfdp.rst | 8 ++++++++ docs/highlevel.rst | 14 ++++++++------ src/fsfw/cfdp/handler/mib.h | 1 + 4 files changed, 18 insertions(+), 6 deletions(-) create mode 100644 docs/api/cfdp.rst diff --git a/docs/api.rst b/docs/api.rst index d2ee6c69..dc73c2c7 100644 --- a/docs/api.rst +++ b/docs/api.rst @@ -4,6 +4,7 @@ API .. toctree:: :maxdepth: 4 + api/cfdp api/objectmanager api/task api/ipc diff --git a/docs/api/cfdp.rst b/docs/api/cfdp.rst new file mode 100644 index 00000000..335a2025 --- /dev/null +++ b/docs/api/cfdp.rst @@ -0,0 +1,8 @@ +CFDP API +================= + +``UserBase`` +----------------- + +.. doxygenclass:: cfdp::UserBase + :members: \ No newline at end of file diff --git a/docs/highlevel.rst b/docs/highlevel.rst index 04eb5e7b..78ad53ff 100644 --- a/docs/highlevel.rst +++ b/docs/highlevel.rst @@ -7,12 +7,14 @@ Structure ---------- The general structure is driven by the usage of interfaces provided by objects. -The FSFW uses C++11 as baseline. The intention behind this is that this C++ Standard should be -widely available, even with older compilers. -The FSFW uses dynamic allocation during the initialization but provides static containers during runtime. -This simplifies the instantiation of objects and allows the usage of some standard containers. -Dynamic Allocation after initialization is discouraged and different solutions are provided in the -FSFW to achieve that. The fsfw uses run-time type information but exceptions are not allowed. +The FSFW uses C++17 as baseline. +It also uses dynamic allocation during the initialization but provides +static containers during runtime. +This simplifies the instantiation of objects and allows the usage of some +standard containers. +Dynamic Allocation after initialization is discouraged and different solutions +are provided in the FSFW to achieve that. The fsfw uses run-time type +information but will not throw exceptions. Failure Handling ----------------- diff --git a/src/fsfw/cfdp/handler/mib.h b/src/fsfw/cfdp/handler/mib.h index e78b0f4f..d5e687b4 100644 --- a/src/fsfw/cfdp/handler/mib.h +++ b/src/fsfw/cfdp/handler/mib.h @@ -3,6 +3,7 @@ #include +#include "fsfw/cfdp/pdu/PduConfig.h" #include "FaultHandlerBase.h" namespace cfdp { From 8c059f8f32e9a53cd3c43cd8192cba4432ec5fc4 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Tue, 9 Aug 2022 16:36:35 +0200 Subject: [PATCH 044/169] new filesystem module --- src/fsfw/CMakeLists.txt | 1 + src/fsfw/cfdp/handler/DestHandler.cpp | 3 ++- src/fsfw/cfdp/handler/DestHandler.h | 4 +++- src/fsfw/cfdp/handler/UserBase.h | 2 +- src/fsfw/cfdp/handler/mib.h | 2 +- src/fsfw/filesystem.h | 7 +++++++ src/fsfw/filesystem/CMakeLists.txt | 1 + src/fsfw/{memory => filesystem}/FileSystemArgsIF.h | 0 .../{memory => filesystem}/GenericFileSystemMessage.cpp | 2 +- src/fsfw/{memory => filesystem}/GenericFileSystemMessage.h | 0 src/fsfw/{memory => filesystem}/HasFileSystemIF.h | 0 src/fsfw/ipc/CommandMessageCleaner.cpp | 3 +-- src/fsfw/memory/CMakeLists.txt | 3 +-- unittests/cfdp/handler/testDestHandler.cpp | 5 ++++- 14 files changed, 23 insertions(+), 10 deletions(-) create mode 100644 src/fsfw/filesystem.h create mode 100644 src/fsfw/filesystem/CMakeLists.txt rename src/fsfw/{memory => filesystem}/FileSystemArgsIF.h (100%) rename src/fsfw/{memory => filesystem}/GenericFileSystemMessage.cpp (99%) rename src/fsfw/{memory => filesystem}/GenericFileSystemMessage.h (100%) rename src/fsfw/{memory => filesystem}/HasFileSystemIF.h (100%) diff --git a/src/fsfw/CMakeLists.txt b/src/fsfw/CMakeLists.txt index 1daad714..e645d34f 100644 --- a/src/fsfw/CMakeLists.txt +++ b/src/fsfw/CMakeLists.txt @@ -31,6 +31,7 @@ add_subdirectory(thermal) add_subdirectory(timemanager) add_subdirectory(tmtcpacket) add_subdirectory(tmtcservices) +add_subdirectory(filesystem) # Optional diff --git a/src/fsfw/cfdp/handler/DestHandler.cpp b/src/fsfw/cfdp/handler/DestHandler.cpp index 72f7951e..cd1886f3 100644 --- a/src/fsfw/cfdp/handler/DestHandler.cpp +++ b/src/fsfw/cfdp/handler/DestHandler.cpp @@ -2,4 +2,5 @@ #include -cfdp::DestHandler::DestHandler(LocalEntityCfg cfg) : cfg(std::move(cfg)) {} +cfdp::DestHandler::DestHandler(LocalEntityCfg cfg, UserBase& user) + : cfg(std::move(cfg)), user(user) {} diff --git a/src/fsfw/cfdp/handler/DestHandler.h b/src/fsfw/cfdp/handler/DestHandler.h index e934fc9c..3b56e2c7 100644 --- a/src/fsfw/cfdp/handler/DestHandler.h +++ b/src/fsfw/cfdp/handler/DestHandler.h @@ -1,6 +1,7 @@ #ifndef FSFW_CFDP_CFDPDESTHANDLER_H #define FSFW_CFDP_CFDPDESTHANDLER_H +#include "UserBase.h" #include "fsfw/cfdp/handler/mib.h" #include "fsfw/cfdp/pdu/PduConfig.h" @@ -8,10 +9,11 @@ namespace cfdp { class DestHandler { public: - DestHandler(LocalEntityCfg cfg /*, CfdpUserBase& user, RemoteConfigTableIF& remoteConfigTable*/); + DestHandler(LocalEntityCfg cfg, UserBase& user /*, RemoteConfigTableIF& remoteConfigTable*/); private: LocalEntityCfg cfg; + UserBase& user; }; } // namespace cfdp diff --git a/src/fsfw/cfdp/handler/UserBase.h b/src/fsfw/cfdp/handler/UserBase.h index 282db9e2..07d281b0 100644 --- a/src/fsfw/cfdp/handler/UserBase.h +++ b/src/fsfw/cfdp/handler/UserBase.h @@ -1,7 +1,7 @@ #ifndef FSFW_CFDP_USERBASE_H #define FSFW_CFDP_USERBASE_H -#include "fsfw/memory/HasFileSystemIF.h" +#include "fsfw/filesystem/HasFileSystemIF.h" namespace cfdp { diff --git a/src/fsfw/cfdp/handler/mib.h b/src/fsfw/cfdp/handler/mib.h index d5e687b4..79e6d895 100644 --- a/src/fsfw/cfdp/handler/mib.h +++ b/src/fsfw/cfdp/handler/mib.h @@ -3,8 +3,8 @@ #include -#include "fsfw/cfdp/pdu/PduConfig.h" #include "FaultHandlerBase.h" +#include "fsfw/cfdp/pdu/PduConfig.h" namespace cfdp { diff --git a/src/fsfw/filesystem.h b/src/fsfw/filesystem.h new file mode 100644 index 00000000..c4a6ebc6 --- /dev/null +++ b/src/fsfw/filesystem.h @@ -0,0 +1,7 @@ +#ifndef FSFW_FILESYSTEM_H +#define FSFW_FILESYSTEM_H + +#include "filesystem/FileSystemArgsIF.h" +#include "filesystem/HasFileSystemIF.h" + +#endif // FSFW_FILESYSTEM_H diff --git a/src/fsfw/filesystem/CMakeLists.txt b/src/fsfw/filesystem/CMakeLists.txt new file mode 100644 index 00000000..a0618d97 --- /dev/null +++ b/src/fsfw/filesystem/CMakeLists.txt @@ -0,0 +1 @@ +target_sources(${LIB_FSFW_NAME} PRIVATE GenericFileSystemMessage.cpp) diff --git a/src/fsfw/memory/FileSystemArgsIF.h b/src/fsfw/filesystem/FileSystemArgsIF.h similarity index 100% rename from src/fsfw/memory/FileSystemArgsIF.h rename to src/fsfw/filesystem/FileSystemArgsIF.h diff --git a/src/fsfw/memory/GenericFileSystemMessage.cpp b/src/fsfw/filesystem/GenericFileSystemMessage.cpp similarity index 99% rename from src/fsfw/memory/GenericFileSystemMessage.cpp rename to src/fsfw/filesystem/GenericFileSystemMessage.cpp index 805c7dcc..3bcd8cf0 100644 --- a/src/fsfw/memory/GenericFileSystemMessage.cpp +++ b/src/fsfw/filesystem/GenericFileSystemMessage.cpp @@ -1,4 +1,4 @@ -#include "fsfw/memory/GenericFileSystemMessage.h" +#include "GenericFileSystemMessage.h" #include "fsfw/objectmanager/ObjectManager.h" #include "fsfw/storagemanager/StorageManagerIF.h" diff --git a/src/fsfw/memory/GenericFileSystemMessage.h b/src/fsfw/filesystem/GenericFileSystemMessage.h similarity index 100% rename from src/fsfw/memory/GenericFileSystemMessage.h rename to src/fsfw/filesystem/GenericFileSystemMessage.h diff --git a/src/fsfw/memory/HasFileSystemIF.h b/src/fsfw/filesystem/HasFileSystemIF.h similarity index 100% rename from src/fsfw/memory/HasFileSystemIF.h rename to src/fsfw/filesystem/HasFileSystemIF.h diff --git a/src/fsfw/ipc/CommandMessageCleaner.cpp b/src/fsfw/ipc/CommandMessageCleaner.cpp index 328441e6..0a43774b 100644 --- a/src/fsfw/ipc/CommandMessageCleaner.cpp +++ b/src/fsfw/ipc/CommandMessageCleaner.cpp @@ -1,10 +1,9 @@ #include "fsfw/ipc/CommandMessageCleaner.h" -#include "fsfw/FSFW.h" #include "fsfw/devicehandlers/DeviceHandlerMessage.h" +#include "fsfw/filesystem/GenericFileSystemMessage.h" #include "fsfw/health/HealthMessage.h" #include "fsfw/housekeeping/HousekeepingMessage.h" -#include "fsfw/memory/GenericFileSystemMessage.h" #include "fsfw/memory/MemoryMessage.h" #include "fsfw/modes/ModeMessage.h" #include "fsfw/monitoring/MonitoringMessage.h" diff --git a/src/fsfw/memory/CMakeLists.txt b/src/fsfw/memory/CMakeLists.txt index 9e591bae..9d9c90c4 100644 --- a/src/fsfw/memory/CMakeLists.txt +++ b/src/fsfw/memory/CMakeLists.txt @@ -1,2 +1 @@ -target_sources(${LIB_FSFW_NAME} PRIVATE MemoryHelper.cpp MemoryMessage.cpp - GenericFileSystemMessage.cpp) +target_sources(${LIB_FSFW_NAME} PRIVATE MemoryHelper.cpp MemoryMessage.cpp) diff --git a/unittests/cfdp/handler/testDestHandler.cpp b/unittests/cfdp/handler/testDestHandler.cpp index e2f95388..8d971361 100644 --- a/unittests/cfdp/handler/testDestHandler.cpp +++ b/unittests/cfdp/handler/testDestHandler.cpp @@ -1,10 +1,13 @@ #include #include "fsfw/cfdp.h" +#include "mocks/CfdpFaultHandlerMock.h" TEST_CASE("CFDP Dest Handler", "[cfdp]") { using namespace cfdp; - // auto localEntityCfg = LocalEntityCfg(); + EntityId localId = EntityId(UnsignedByteField(2)); + auto fhMock = CfdpFaultHandlerMock(); + auto localEntityCfg = LocalEntityCfg(localId, IndicationCfg(), fhMock); // auto destHandler = DestHandler(); SECTION("State") {} From d45108e3c210c1687718a1db61c486e8d3eab2a9 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Tue, 9 Aug 2022 18:51:44 +0200 Subject: [PATCH 045/169] add remote config table provider class --- src/fsfw/cfdp/CMakeLists.txt | 3 +- .../{pdu/VarLenField.cpp => VarLenFields.cpp} | 12 ++++++-- .../{pdu/VarLenField.h => VarLenFields.h} | 29 +++++++++++++++++++ src/fsfw/cfdp/definitions.h | 6 +++- src/fsfw/cfdp/handler/DestHandler.cpp | 5 ++-- src/fsfw/cfdp/handler/DestHandler.h | 4 ++- src/fsfw/cfdp/handler/RemoteConfigTableIF.h | 15 ++++++++++ src/fsfw/cfdp/handler/UserBase.h | 15 ++++++++++ src/fsfw/cfdp/handler/mib.h | 10 +++++++ src/fsfw/cfdp/pdu/CMakeLists.txt | 1 - src/fsfw/cfdp/pdu/PduConfig.h | 22 +------------- 11 files changed, 92 insertions(+), 30 deletions(-) rename src/fsfw/cfdp/{pdu/VarLenField.cpp => VarLenFields.cpp} (93%) rename src/fsfw/cfdp/{pdu/VarLenField.h => VarLenFields.h} (64%) create mode 100644 src/fsfw/cfdp/handler/RemoteConfigTableIF.h diff --git a/src/fsfw/cfdp/CMakeLists.txt b/src/fsfw/cfdp/CMakeLists.txt index 72324a53..30a7c700 100644 --- a/src/fsfw/cfdp/CMakeLists.txt +++ b/src/fsfw/cfdp/CMakeLists.txt @@ -1,4 +1,5 @@ -target_sources(${LIB_FSFW_NAME} PRIVATE CfdpMessage.cpp CfdpDistributor.cpp) +target_sources(${LIB_FSFW_NAME} PRIVATE CfdpMessage.cpp CfdpDistributor.cpp + VarLenFields.cpp) add_subdirectory(pdu) add_subdirectory(tlv) diff --git a/src/fsfw/cfdp/pdu/VarLenField.cpp b/src/fsfw/cfdp/VarLenFields.cpp similarity index 93% rename from src/fsfw/cfdp/pdu/VarLenField.cpp rename to src/fsfw/cfdp/VarLenFields.cpp index 1f4d2429..c70d90ec 100644 --- a/src/fsfw/cfdp/pdu/VarLenField.cpp +++ b/src/fsfw/cfdp/VarLenFields.cpp @@ -1,4 +1,4 @@ -#include "VarLenField.h" +#include "VarLenFields.h" #include "fsfw/serialize/SerializeAdapter.h" #include "fsfw/serviceinterface.h" @@ -119,9 +119,15 @@ ReturnValue_t cfdp::VarLenField::deSerialize(const uint8_t **buffer, size_t *siz } bool cfdp::VarLenField::operator<(const cfdp::VarLenField &other) const { - return getValue() < other.getValue(); + if (getWidth() < other.getWidth()) { + return true; + } else if (getWidth() == other.getWidth()) { + return getValue() < other.getValue(); + } else { + return false; + } } bool cfdp::VarLenField::operator==(const cfdp::VarLenField &other) const { - return getValue() == other.getValue(); + return getWidth() == other.getWidth() and getValue() == other.getValue(); } diff --git a/src/fsfw/cfdp/pdu/VarLenField.h b/src/fsfw/cfdp/VarLenFields.h similarity index 64% rename from src/fsfw/cfdp/pdu/VarLenField.h rename to src/fsfw/cfdp/VarLenFields.h index 819e8ccd..2b862d66 100644 --- a/src/fsfw/cfdp/pdu/VarLenField.h +++ b/src/fsfw/cfdp/VarLenFields.h @@ -3,6 +3,7 @@ #include #include +#include #include "fsfw/cfdp/definitions.h" #include "fsfw/serialize/SerializeIF.h" @@ -56,6 +57,34 @@ cfdp::VarLenField::VarLenField(UnsignedByteField byteField) setValue(width, byteField.getValue()); } +struct EntityId : public VarLenField { + public: + EntityId() : VarLenField() {} + template + explicit EntityId(UnsignedByteField byteField) : VarLenField(byteField) {} + EntityId(cfdp::WidthInBytes width, size_t entityId) : VarLenField(width, entityId) {} +}; + +struct TransactionSeqNum : public VarLenField { + public: + TransactionSeqNum() : VarLenField() {} + template + explicit TransactionSeqNum(UnsignedByteField byteField) : VarLenField(byteField) {} + TransactionSeqNum(cfdp::WidthInBytes width, size_t seqNum) : VarLenField(width, seqNum) {} +}; + +struct TransactionId { + TransactionId(EntityId entityId, TransactionSeqNum seqNum) + : entityId(std::move(entityId)), seqNum(std::move(seqNum)) {} + + bool operator==(const TransactionId &other) { + return entityId == other.entityId and seqNum == other.seqNum; + } + + EntityId entityId; + TransactionSeqNum seqNum; +}; + } // namespace cfdp #endif /* FSFW_CFDP_PDU_VARLENFIELD_H_ */ diff --git a/src/fsfw/cfdp/definitions.h b/src/fsfw/cfdp/definitions.h index b97b9b27..4bd149e2 100644 --- a/src/fsfw/cfdp/definitions.h +++ b/src/fsfw/cfdp/definitions.h @@ -11,7 +11,11 @@ namespace cfdp { -static constexpr uint8_t VERSION_BITS = 0b00100000; +static constexpr char CFDP_VERSION_2_NAME[] = "CCSDS 727.0-B-5"; + +// Second version of the protocol, only this one is supported here +static constexpr uint8_t CFDP_VERSION_2 = 0b001; +static constexpr uint8_t VERSION_BITS = CFDP_VERSION_2 << 5; static constexpr uint8_t CFDP_CLASS_ID = CLASS_ID::CFDP; diff --git a/src/fsfw/cfdp/handler/DestHandler.cpp b/src/fsfw/cfdp/handler/DestHandler.cpp index cd1886f3..d2b672c9 100644 --- a/src/fsfw/cfdp/handler/DestHandler.cpp +++ b/src/fsfw/cfdp/handler/DestHandler.cpp @@ -2,5 +2,6 @@ #include -cfdp::DestHandler::DestHandler(LocalEntityCfg cfg, UserBase& user) - : cfg(std::move(cfg)), user(user) {} +cfdp::DestHandler::DestHandler(LocalEntityCfg cfg, UserBase& user, + RemoteConfigTableIF& remoteCfgTable) + : cfg(std::move(cfg)), user(user), remoteCfgTable(remoteCfgTable) {} diff --git a/src/fsfw/cfdp/handler/DestHandler.h b/src/fsfw/cfdp/handler/DestHandler.h index 3b56e2c7..0032c7b8 100644 --- a/src/fsfw/cfdp/handler/DestHandler.h +++ b/src/fsfw/cfdp/handler/DestHandler.h @@ -1,6 +1,7 @@ #ifndef FSFW_CFDP_CFDPDESTHANDLER_H #define FSFW_CFDP_CFDPDESTHANDLER_H +#include "RemoteConfigTableIF.h" #include "UserBase.h" #include "fsfw/cfdp/handler/mib.h" #include "fsfw/cfdp/pdu/PduConfig.h" @@ -9,11 +10,12 @@ namespace cfdp { class DestHandler { public: - DestHandler(LocalEntityCfg cfg, UserBase& user /*, RemoteConfigTableIF& remoteConfigTable*/); + DestHandler(LocalEntityCfg cfg, UserBase& user, RemoteConfigTableIF& remoteCfgTable); private: LocalEntityCfg cfg; UserBase& user; + RemoteConfigTableIF& remoteCfgTable; }; } // namespace cfdp diff --git a/src/fsfw/cfdp/handler/RemoteConfigTableIF.h b/src/fsfw/cfdp/handler/RemoteConfigTableIF.h new file mode 100644 index 00000000..c757fe7e --- /dev/null +++ b/src/fsfw/cfdp/handler/RemoteConfigTableIF.h @@ -0,0 +1,15 @@ +#ifndef FSFW_CFDP_HANDLER_REMOTECONFIGTABLEIF_H +#define FSFW_CFDP_HANDLER_REMOTECONFIGTABLEIF_H + +#include "fsfw/cfdp/handler/mib.h" + +namespace cfdp { + +class RemoteConfigTableIF { + virtual ~RemoteConfigTableIF() = default; + virtual bool getRemoteCfg(EntityId remoteId, RemoteEntityCfg* cfg) = 0; +}; + +} // namespace cfdp + +#endif // FSFW_CFDP_HANDLER_REMOTECONFIGTABLEIF_H diff --git a/src/fsfw/cfdp/handler/UserBase.h b/src/fsfw/cfdp/handler/UserBase.h index 07d281b0..dd3c7424 100644 --- a/src/fsfw/cfdp/handler/UserBase.h +++ b/src/fsfw/cfdp/handler/UserBase.h @@ -1,6 +1,7 @@ #ifndef FSFW_CFDP_USERBASE_H #define FSFW_CFDP_USERBASE_H +#include "fsfw/cfdp/VarLenFields.h" #include "fsfw/filesystem/HasFileSystemIF.h" namespace cfdp { @@ -22,6 +23,20 @@ class UserBase { */ explicit UserBase(HasFileSystemIF& vfs); + virtual void transactionIndication(TransactionId id) = 0; + virtual void eofSentIndication(TransactionId id) = 0; + + virtual void abandonedIndication(TransactionId id, ConditionCode code, uint64_t progress) = 0; + virtual void eofRecvIndication(TransactionId id) = 0; + + // TODO: Parameters + virtual void transactionFinishedIndication() = 0; + virtual void metadataRecvdIndication() = 0; + virtual void fileSegmentRecvdIndication() = 0; + virtual void reportIndication() = 0; + virtual void suspendedIndication() = 0; + virtual void resumedIndication() = 0; + private: HasFileSystemIF& vfs; }; diff --git a/src/fsfw/cfdp/handler/mib.h b/src/fsfw/cfdp/handler/mib.h index 79e6d895..7ba15cd3 100644 --- a/src/fsfw/cfdp/handler/mib.h +++ b/src/fsfw/cfdp/handler/mib.h @@ -26,6 +26,16 @@ struct LocalEntityCfg { FaultHandlerBase& fhBase; }; +struct RemoteEntityCfg { + EntityId remoteId; + size_t maxFileSegmentLen; + bool closureRequested; + bool crcOnTransmission; + TransmissionModes defaultTransmissionMode; + ChecksumType defaultChecksum; + const uint8_t version = CFDP_VERSION_2; +}; + } // namespace cfdp #endif // FSFW_CFDP_MIB_H diff --git a/src/fsfw/cfdp/pdu/CMakeLists.txt b/src/fsfw/cfdp/pdu/CMakeLists.txt index 33b05eec..91b5ad2e 100644 --- a/src/fsfw/cfdp/pdu/CMakeLists.txt +++ b/src/fsfw/cfdp/pdu/CMakeLists.txt @@ -1,7 +1,6 @@ target_sources( ${LIB_FSFW_NAME} PRIVATE PduConfig.cpp - VarLenField.cpp HeaderCreator.cpp HeaderReader.cpp FileDirectiveReader.cpp diff --git a/src/fsfw/cfdp/pdu/PduConfig.h b/src/fsfw/cfdp/pdu/PduConfig.h index 48f3993b..2e513159 100644 --- a/src/fsfw/cfdp/pdu/PduConfig.h +++ b/src/fsfw/cfdp/pdu/PduConfig.h @@ -1,29 +1,9 @@ #ifndef FSFW_SRC_FSFW_CFDP_PDU_PDUCONFIG_H_ #define FSFW_SRC_FSFW_CFDP_PDU_PDUCONFIG_H_ -#include "VarLenField.h" +#include "fsfw/cfdp/VarLenFields.h" #include "fsfw/cfdp/definitions.h" -namespace cfdp { - -struct EntityId : public VarLenField { - public: - EntityId() : VarLenField() {} - template - explicit EntityId(UnsignedByteField byteField) : VarLenField(byteField) {} - EntityId(cfdp::WidthInBytes width, size_t entityId) : VarLenField(width, entityId) {} -}; - -struct TransactionSeqNum : public VarLenField { - public: - TransactionSeqNum() : VarLenField() {} - template - explicit TransactionSeqNum(UnsignedByteField byteField) : VarLenField(byteField) {} - TransactionSeqNum(cfdp::WidthInBytes width, size_t seqNum) : VarLenField(width, seqNum) {} -}; - -} // namespace cfdp - class PduConfig { public: PduConfig(cfdp::EntityId sourceId, cfdp::EntityId destId, cfdp::TransmissionModes mode, From 0cb15e901eee6ebd1482c2cdfd8ae4f6dfa677b2 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Tue, 9 Aug 2022 19:00:47 +0200 Subject: [PATCH 046/169] new cfdp mock folder, added additional cfdp mocks --- src/fsfw/cfdp/handler/RemoteConfigTableIF.h | 1 + unittests/cfdp/handler/testDestHandler.cpp | 4 +-- unittests/cfdp/handler/testFaultHandler.cpp | 4 +-- unittests/mocks/CMakeLists.txt | 5 ++-- unittests/mocks/cfdp/CMakeLists.txt | 1 + .../FaultHandlerMock.cpp} | 20 +++++++++------ .../FaultHandlerMock.h} | 23 ++++++++++------- .../mocks/cfdp/RemoteConfigTableMock.cpp | 6 +++++ unittests/mocks/cfdp/RemoteConfigTableMock.h | 15 +++++++++++ unittests/mocks/cfdp/UserMock.cpp | 16 ++++++++++++ unittests/mocks/cfdp/UserMock.h | 25 +++++++++++++++++++ 11 files changed, 97 insertions(+), 23 deletions(-) create mode 100644 unittests/mocks/cfdp/CMakeLists.txt rename unittests/mocks/{CfdpFaultHandlerMock.cpp => cfdp/FaultHandlerMock.cpp} (59%) rename unittests/mocks/{CfdpFaultHandlerMock.h => cfdp/FaultHandlerMock.h} (56%) create mode 100644 unittests/mocks/cfdp/RemoteConfigTableMock.cpp create mode 100644 unittests/mocks/cfdp/RemoteConfigTableMock.h create mode 100644 unittests/mocks/cfdp/UserMock.cpp create mode 100644 unittests/mocks/cfdp/UserMock.h diff --git a/src/fsfw/cfdp/handler/RemoteConfigTableIF.h b/src/fsfw/cfdp/handler/RemoteConfigTableIF.h index c757fe7e..767492d5 100644 --- a/src/fsfw/cfdp/handler/RemoteConfigTableIF.h +++ b/src/fsfw/cfdp/handler/RemoteConfigTableIF.h @@ -6,6 +6,7 @@ namespace cfdp { class RemoteConfigTableIF { + public: virtual ~RemoteConfigTableIF() = default; virtual bool getRemoteCfg(EntityId remoteId, RemoteEntityCfg* cfg) = 0; }; diff --git a/unittests/cfdp/handler/testDestHandler.cpp b/unittests/cfdp/handler/testDestHandler.cpp index 8d971361..d963b6c7 100644 --- a/unittests/cfdp/handler/testDestHandler.cpp +++ b/unittests/cfdp/handler/testDestHandler.cpp @@ -1,12 +1,12 @@ #include #include "fsfw/cfdp.h" -#include "mocks/CfdpFaultHandlerMock.h" +#include "mocks/cfdp/FaultHandlerMock.h" TEST_CASE("CFDP Dest Handler", "[cfdp]") { using namespace cfdp; EntityId localId = EntityId(UnsignedByteField(2)); - auto fhMock = CfdpFaultHandlerMock(); + auto fhMock = FaultHandlerMock(); auto localEntityCfg = LocalEntityCfg(localId, IndicationCfg(), fhMock); // auto destHandler = DestHandler(); diff --git a/unittests/cfdp/handler/testFaultHandler.cpp b/unittests/cfdp/handler/testFaultHandler.cpp index 945e09b8..559744d7 100644 --- a/unittests/cfdp/handler/testFaultHandler.cpp +++ b/unittests/cfdp/handler/testFaultHandler.cpp @@ -1,10 +1,10 @@ #include -#include "mocks/CfdpFaultHandlerMock.h" +#include "mocks/cfdp/FaultHandlerMock.h" TEST_CASE("CFDP Fault Handler", "[cfdp]") { using namespace cfdp; - auto fhMock = CfdpFaultHandlerMock(); + auto fhMock = FaultHandlerMock(); cfdp::FaultHandlerCodes fhCode; SECTION("State") { diff --git a/unittests/mocks/CMakeLists.txt b/unittests/mocks/CMakeLists.txt index 0ee7bf1e..e15f3d71 100644 --- a/unittests/mocks/CMakeLists.txt +++ b/unittests/mocks/CMakeLists.txt @@ -14,5 +14,6 @@ target_sources( PusDistributorMock.cpp CcsdsCheckerMock.cpp AcceptsTcMock.cpp - StorageManagerMock.cpp - CfdpFaultHandlerMock.cpp) + StorageManagerMock.cpp) + +add_subdirectory(cfdp) diff --git a/unittests/mocks/cfdp/CMakeLists.txt b/unittests/mocks/cfdp/CMakeLists.txt new file mode 100644 index 00000000..0fa0890c --- /dev/null +++ b/unittests/mocks/cfdp/CMakeLists.txt @@ -0,0 +1 @@ +target_sources(${FSFW_TEST_TGT} PRIVATE FaultHandlerMock.cpp UserMock.cpp RemoteConfigTableMock.cpp) diff --git a/unittests/mocks/CfdpFaultHandlerMock.cpp b/unittests/mocks/cfdp/FaultHandlerMock.cpp similarity index 59% rename from unittests/mocks/CfdpFaultHandlerMock.cpp rename to unittests/mocks/cfdp/FaultHandlerMock.cpp index 3f7c8896..26bebda5 100644 --- a/unittests/mocks/CfdpFaultHandlerMock.cpp +++ b/unittests/mocks/cfdp/FaultHandlerMock.cpp @@ -1,38 +1,42 @@ -#include "CfdpFaultHandlerMock.h" +#include "FaultHandlerMock.h" -void CfdpFaultHandlerMock::noticeOfSuspensionCb(cfdp::ConditionCode code) { +namespace cfdp { + +void FaultHandlerMock::noticeOfSuspensionCb(cfdp::ConditionCode code) { auto& info = fhInfoMap.at(cfdp::FaultHandlerCodes::NOTICE_OF_SUSPENSION); info.callCount++; info.condCodes.push(code); } -void CfdpFaultHandlerMock::noticeOfCancellationCb(cfdp::ConditionCode code) { +void FaultHandlerMock::noticeOfCancellationCb(cfdp::ConditionCode code) { auto& info = fhInfoMap.at(cfdp::FaultHandlerCodes::NOTICE_OF_CANCELLATION); info.callCount++; info.condCodes.push(code); } -void CfdpFaultHandlerMock::abandonCb(cfdp::ConditionCode code) { +void FaultHandlerMock::abandonCb(cfdp::ConditionCode code) { auto& info = fhInfoMap.at(cfdp::FaultHandlerCodes::ABANDON_TRANSACTION); info.callCount++; info.condCodes.push(code); } -void CfdpFaultHandlerMock::ignoreCb(cfdp::ConditionCode code) { +void FaultHandlerMock::ignoreCb(cfdp::ConditionCode code) { auto& info = fhInfoMap.at(cfdp::FaultHandlerCodes::IGNORE_ERROR); info.callCount++; info.condCodes.push(code); } -CfdpFaultHandlerMock::FaultInfo& CfdpFaultHandlerMock::getFhInfo(cfdp::FaultHandlerCodes fhCode) { +FaultHandlerMock::FaultInfo& FaultHandlerMock::getFhInfo(cfdp::FaultHandlerCodes fhCode) { return fhInfoMap.at(fhCode); } -void CfdpFaultHandlerMock::reset() { fhInfoMap.clear(); } +void FaultHandlerMock::reset() { fhInfoMap.clear(); } -bool CfdpFaultHandlerMock::faultCbWasCalled() const { +bool FaultHandlerMock::faultCbWasCalled() const { return std::any_of(fhInfoMap.begin(), fhInfoMap.end(), [](const std::pair& pair) { return pair.second.callCount > 0; }); } + +} // namespace cfdp diff --git a/unittests/mocks/CfdpFaultHandlerMock.h b/unittests/mocks/cfdp/FaultHandlerMock.h similarity index 56% rename from unittests/mocks/CfdpFaultHandlerMock.h rename to unittests/mocks/cfdp/FaultHandlerMock.h index 721cf7e0..a35d3d2b 100644 --- a/unittests/mocks/CfdpFaultHandlerMock.h +++ b/unittests/mocks/cfdp/FaultHandlerMock.h @@ -1,24 +1,26 @@ -#ifndef FSFW_TESTS_CFDPFAULTHANDLERMOCK_H -#define FSFW_TESTS_CFDPFAULTHANDLERMOCK_H +#ifndef FSFW_TESTS_FAULTHANDLERMOCK_H +#define FSFW_TESTS_FAULTHANDLERMOCK_H #include #include #include "fsfw/cfdp/handler/FaultHandlerBase.h" -class CfdpFaultHandlerMock : public cfdp::FaultHandlerBase { +namespace cfdp { + +class FaultHandlerMock : public FaultHandlerBase { public: struct FaultInfo { size_t callCount = 0; std::queue condCodes; }; - void noticeOfSuspensionCb(cfdp::ConditionCode code) override; - void noticeOfCancellationCb(cfdp::ConditionCode code) override; - void abandonCb(cfdp::ConditionCode code) override; - void ignoreCb(cfdp::ConditionCode code) override; + void noticeOfSuspensionCb(ConditionCode code) override; + void noticeOfCancellationCb(ConditionCode code) override; + void abandonCb(ConditionCode code) override; + void ignoreCb(ConditionCode code) override; - FaultInfo& getFhInfo(cfdp::FaultHandlerCodes fhCode); + FaultInfo& getFhInfo(FaultHandlerCodes fhCode); [[nodiscard]] bool faultCbWasCalled() const; void reset(); @@ -29,4 +31,7 @@ class CfdpFaultHandlerMock : public cfdp::FaultHandlerBase { std::pair{cfdp::FaultHandlerCodes::NOTICE_OF_SUSPENSION, FaultInfo()}, std::pair{cfdp::FaultHandlerCodes::ABANDON_TRANSACTION, FaultInfo()}}; }; -#endif // FSFW_TESTS_CFDPFAULTHANDLERMOCK_H + +} // namespace cfdp + +#endif // FSFW_TESTS_FAULTHANDLERMOCK_H diff --git a/unittests/mocks/cfdp/RemoteConfigTableMock.cpp b/unittests/mocks/cfdp/RemoteConfigTableMock.cpp new file mode 100644 index 00000000..83827a36 --- /dev/null +++ b/unittests/mocks/cfdp/RemoteConfigTableMock.cpp @@ -0,0 +1,6 @@ +#include "RemoteConfigTableMock.h" + +bool cfdp::RemoteConfigTableMock::getRemoteCfg(cfdp::EntityId remoteId, + cfdp::RemoteEntityCfg *cfg) { + return false; +} diff --git a/unittests/mocks/cfdp/RemoteConfigTableMock.h b/unittests/mocks/cfdp/RemoteConfigTableMock.h new file mode 100644 index 00000000..7ac25ba7 --- /dev/null +++ b/unittests/mocks/cfdp/RemoteConfigTableMock.h @@ -0,0 +1,15 @@ +#ifndef FSFW_TESTS_CFDP_REMOTCONFIGTABLEMOCK_H +#define FSFW_TESTS_CFDP_REMOTCONFIGTABLEMOCK_H + +#include "fsfw/cfdp/handler/RemoteConfigTableIF.h" + +namespace cfdp { + +class RemoteConfigTableMock: public RemoteConfigTableIF { + public: + bool getRemoteCfg(EntityId remoteId, RemoteEntityCfg *cfg) override; +}; + +} + +#endif // FSFW_TESTS_CFDP_REMOTCONFIGTABLEMOCK_H diff --git a/unittests/mocks/cfdp/UserMock.cpp b/unittests/mocks/cfdp/UserMock.cpp new file mode 100644 index 00000000..c8b3b940 --- /dev/null +++ b/unittests/mocks/cfdp/UserMock.cpp @@ -0,0 +1,16 @@ +#include "UserMock.h" + +cfdp::UserMock::UserMock(HasFileSystemIF& vfs) : UserBase(vfs) {} + +void cfdp::UserMock::transactionIndication(cfdp::TransactionId id) {} +void cfdp::UserMock::eofSentIndication(cfdp::TransactionId id) {} +void cfdp::UserMock::abandonedIndication(cfdp::TransactionId id, cfdp::ConditionCode code, + uint64_t progress) {} +void cfdp::UserMock::eofRecvIndication(cfdp::TransactionId id) {} +void cfdp::UserMock::transactionFinishedIndication() {} +void cfdp::UserMock::metadataRecvdIndication() {} +void cfdp::UserMock::fileSegmentRecvdIndication() {} +void cfdp::UserMock::reportIndication() {} +void cfdp::UserMock::suspendedIndication() {} +void cfdp::UserMock::resumedIndication() {} + diff --git a/unittests/mocks/cfdp/UserMock.h b/unittests/mocks/cfdp/UserMock.h new file mode 100644 index 00000000..b32e698a --- /dev/null +++ b/unittests/mocks/cfdp/UserMock.h @@ -0,0 +1,25 @@ +#ifndef FSFW_TESTS_CFDP_USERMOCK_H +#define FSFW_TESTS_CFDP_USERMOCK_H + +#include "fsfw/cfdp/handler/UserBase.h" + +namespace cfdp { + +class UserMock: public UserBase { + explicit UserMock(HasFileSystemIF& vfs); + public: + void transactionIndication(TransactionId id) override; + void eofSentIndication(TransactionId id) override; + void abandonedIndication(TransactionId id, ConditionCode code, uint64_t progress) override; + void eofRecvIndication(TransactionId id) override; + void transactionFinishedIndication() override; + void metadataRecvdIndication() override; + void fileSegmentRecvdIndication() override; + void reportIndication() override; + void suspendedIndication() override; + void resumedIndication() override; +}; + +} + +#endif // FSFW_TESTS_CFDP_USERMOCK_H From 507c6ddff124604d15a542a8b640541b69f45701 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Tue, 9 Aug 2022 21:03:56 +0200 Subject: [PATCH 047/169] added some param structs --- src/fsfw/cfdp/definitions.h | 4 +- src/fsfw/cfdp/handler/StatusReportIF.h | 12 ++++++ src/fsfw/cfdp/handler/UserBase.h | 42 +++++++++++++++++-- src/fsfw/cfdp/pdu/FinishedInfo.cpp | 13 +++--- src/fsfw/cfdp/pdu/FinishedInfo.h | 16 +++---- src/fsfw/cfdp/pdu/FinishedPduDeserializer.cpp | 4 +- src/fsfw/cfdp/tlv/Tlv.h | 16 +++---- unittests/cfdp/pdu/testFinishedPdu.cpp | 20 ++++----- unittests/mocks/cfdp/CMakeLists.txt | 3 +- unittests/mocks/cfdp/RemoteConfigTableMock.h | 4 +- unittests/mocks/cfdp/UserMock.cpp | 5 +-- unittests/mocks/cfdp/UserMock.h | 10 ++--- 12 files changed, 98 insertions(+), 51 deletions(-) create mode 100644 src/fsfw/cfdp/handler/StatusReportIF.h diff --git a/src/fsfw/cfdp/definitions.h b/src/fsfw/cfdp/definitions.h index 4bd149e2..80eb7340 100644 --- a/src/fsfw/cfdp/definitions.h +++ b/src/fsfw/cfdp/definitions.h @@ -109,9 +109,9 @@ enum AckTransactionStatus { UNRECOGNIZED = 0b11 }; -enum FinishedDeliveryCode { DATA_COMPLETE = 0, DATA_INCOMPLETE = 1 }; +enum FileDeliveryCode { DATA_COMPLETE = 0, DATA_INCOMPLETE = 1 }; -enum FinishedFileStatus { +enum FileDeliveryStatus { DISCARDED_DELIBERATELY = 0, DISCARDED_FILESTORE_REJECTION = 1, RETAINED_IN_FILESTORE = 2, diff --git a/src/fsfw/cfdp/handler/StatusReportIF.h b/src/fsfw/cfdp/handler/StatusReportIF.h new file mode 100644 index 00000000..1bf98628 --- /dev/null +++ b/src/fsfw/cfdp/handler/StatusReportIF.h @@ -0,0 +1,12 @@ +#ifndef FSFW_CFDP_HANDLER_STATUSREPORTIF_H +#define FSFW_CFDP_HANDLER_STATUSREPORTIF_H + +namespace cfdp { + +class StatusReportIF { + virtual ~StatusReportIF() = default; +}; + +} // namespace cfdp + +#endif // FSFW_CFDP_HANDLER_STATUSREPORTIF_H diff --git a/src/fsfw/cfdp/handler/UserBase.h b/src/fsfw/cfdp/handler/UserBase.h index dd3c7424..6835600c 100644 --- a/src/fsfw/cfdp/handler/UserBase.h +++ b/src/fsfw/cfdp/handler/UserBase.h @@ -1,11 +1,47 @@ #ifndef FSFW_CFDP_USERBASE_H #define FSFW_CFDP_USERBASE_H +#include +#include + +#include "StatusReportIF.h" #include "fsfw/cfdp/VarLenFields.h" +#include "fsfw/cfdp/tlv/FilestoreResponseTlv.h" +#include "fsfw/cfdp/tlv/MessageToUserTlv.h" #include "fsfw/filesystem/HasFileSystemIF.h" namespace cfdp { +struct TransactionFinishedParams { + TransactionFinishedParams(TransactionId id, ConditionCode code, FileDeliveryStatus status, + FileDeliveryCode delivCode) + : id(std::move(id)), condCode(code), status(status), deliveryCode(delivCode) {} + + TransactionId id; + ConditionCode condCode; + FileDeliveryStatus status; + FileDeliveryCode deliveryCode; + std::pair fsResponses; + StatusReportIF* statusReport = nullptr; +}; + +struct MetadataRecvParams { + TransactionId id; + EntityId sourceId; + size_t fileSize; + const char* sourceFileName; + const char* destFileName; + std::pair msgsToUser; +}; + +struct FileSegmentRecvdParams { + TransactionId id; + size_t offset; + size_t length; + std::optional recContState = std::nullopt; + std::pair segmentMetadata; +}; + class UserBase { public: /** @@ -30,9 +66,9 @@ class UserBase { virtual void eofRecvIndication(TransactionId id) = 0; // TODO: Parameters - virtual void transactionFinishedIndication() = 0; - virtual void metadataRecvdIndication() = 0; - virtual void fileSegmentRecvdIndication() = 0; + virtual void transactionFinishedIndication(TransactionFinishedParams params) = 0; + virtual void metadataRecvdIndication(MetadataRecvParams params) = 0; + virtual void fileSegmentRecvdIndication(FileSegmentRecvdParams params) = 0; virtual void reportIndication() = 0; virtual void suspendedIndication() = 0; virtual void resumedIndication() = 0; diff --git a/src/fsfw/cfdp/pdu/FinishedInfo.cpp b/src/fsfw/cfdp/pdu/FinishedInfo.cpp index c32372a1..ca16768b 100644 --- a/src/fsfw/cfdp/pdu/FinishedInfo.cpp +++ b/src/fsfw/cfdp/pdu/FinishedInfo.cpp @@ -2,9 +2,8 @@ FinishedInfo::FinishedInfo() {} -FinishedInfo::FinishedInfo(cfdp::ConditionCode conditionCode, - cfdp::FinishedDeliveryCode deliveryCode, - cfdp::FinishedFileStatus fileStatus) +FinishedInfo::FinishedInfo(cfdp::ConditionCode conditionCode, cfdp::FileDeliveryCode deliveryCode, + cfdp::FileDeliveryStatus fileStatus) : conditionCode(conditionCode), deliveryCode(deliveryCode), fileStatus(fileStatus) {} size_t FinishedInfo::getSerializedSize() const { @@ -83,13 +82,13 @@ void FinishedInfo::setConditionCode(cfdp::ConditionCode conditionCode) { this->conditionCode = conditionCode; } -cfdp::FinishedDeliveryCode FinishedInfo::getDeliveryCode() const { return deliveryCode; } +cfdp::FileDeliveryCode FinishedInfo::getDeliveryCode() const { return deliveryCode; } -void FinishedInfo::setDeliveryCode(cfdp::FinishedDeliveryCode deliveryCode) { +void FinishedInfo::setDeliveryCode(cfdp::FileDeliveryCode deliveryCode) { this->deliveryCode = deliveryCode; } -cfdp::FinishedFileStatus FinishedInfo::getFileStatus() const { return fileStatus; } +cfdp::FileDeliveryStatus FinishedInfo::getFileStatus() const { return fileStatus; } void FinishedInfo::setFilestoreResponsesArrayLen(size_t fsResponsesLen) { this->fsResponsesLen = fsResponsesLen; @@ -97,6 +96,6 @@ void FinishedInfo::setFilestoreResponsesArrayLen(size_t fsResponsesLen) { size_t FinishedInfo::getFsResponsesLen() const { return fsResponsesLen; } -void FinishedInfo::setFileStatus(cfdp::FinishedFileStatus fileStatus) { +void FinishedInfo::setFileStatus(cfdp::FileDeliveryStatus fileStatus) { this->fileStatus = fileStatus; } diff --git a/src/fsfw/cfdp/pdu/FinishedInfo.h b/src/fsfw/cfdp/pdu/FinishedInfo.h index 3f1758e8..49d7c64d 100644 --- a/src/fsfw/cfdp/pdu/FinishedInfo.h +++ b/src/fsfw/cfdp/pdu/FinishedInfo.h @@ -8,8 +8,8 @@ class FinishedInfo { public: FinishedInfo(); - FinishedInfo(cfdp::ConditionCode conditionCode, cfdp::FinishedDeliveryCode deliveryCode, - cfdp::FinishedFileStatus fileStatus); + FinishedInfo(cfdp::ConditionCode conditionCode, cfdp::FileDeliveryCode deliveryCode, + cfdp::FileDeliveryStatus fileStatus); [[nodiscard]] size_t getSerializedSize() const; @@ -27,15 +27,15 @@ class FinishedInfo { ReturnValue_t getFaultLocation(EntityIdTlv** entityId); [[nodiscard]] cfdp::ConditionCode getConditionCode() const; void setConditionCode(cfdp::ConditionCode conditionCode); - [[nodiscard]] cfdp::FinishedDeliveryCode getDeliveryCode() const; - void setDeliveryCode(cfdp::FinishedDeliveryCode deliveryCode); - [[nodiscard]] cfdp::FinishedFileStatus getFileStatus() const; - void setFileStatus(cfdp::FinishedFileStatus fileStatus); + [[nodiscard]] cfdp::FileDeliveryCode getDeliveryCode() const; + void setDeliveryCode(cfdp::FileDeliveryCode deliveryCode); + [[nodiscard]] cfdp::FileDeliveryStatus getFileStatus() const; + void setFileStatus(cfdp::FileDeliveryStatus fileStatus); private: cfdp::ConditionCode conditionCode = cfdp::ConditionCode::NO_CONDITION_FIELD; - cfdp::FinishedDeliveryCode deliveryCode = cfdp::FinishedDeliveryCode::DATA_COMPLETE; - cfdp::FinishedFileStatus fileStatus = cfdp::FinishedFileStatus::DISCARDED_DELIBERATELY; + cfdp::FileDeliveryCode deliveryCode = cfdp::FileDeliveryCode::DATA_COMPLETE; + cfdp::FileDeliveryStatus fileStatus = cfdp::FileDeliveryStatus::DISCARDED_DELIBERATELY; FilestoreResponseTlv** fsResponses = nullptr; size_t fsResponsesLen = 0; size_t fsResponsesMaxLen = 0; diff --git a/src/fsfw/cfdp/pdu/FinishedPduDeserializer.cpp b/src/fsfw/cfdp/pdu/FinishedPduDeserializer.cpp index 7776778b..6eec494e 100644 --- a/src/fsfw/cfdp/pdu/FinishedPduDeserializer.cpp +++ b/src/fsfw/cfdp/pdu/FinishedPduDeserializer.cpp @@ -18,8 +18,8 @@ ReturnValue_t FinishPduDeserializer::parseData() { uint8_t firstByte = *buf; auto condCode = static_cast((firstByte >> 4) & 0x0f); finishedInfo.setConditionCode(condCode); - finishedInfo.setDeliveryCode(static_cast(firstByte >> 2 & 0b1)); - finishedInfo.setFileStatus(static_cast(firstByte & 0b11)); + finishedInfo.setDeliveryCode(static_cast(firstByte >> 2 & 0b1)); + finishedInfo.setFileStatus(static_cast(firstByte & 0b11)); buf += 1; remSize -= 1; currentIdx += 1; diff --git a/src/fsfw/cfdp/tlv/Tlv.h b/src/fsfw/cfdp/tlv/Tlv.h index a67c6dd1..2bdc56f5 100644 --- a/src/fsfw/cfdp/tlv/Tlv.h +++ b/src/fsfw/cfdp/tlv/Tlv.h @@ -27,10 +27,10 @@ class Tlv : public TlvIF { * - INVALID_TLV_TYPE * - SerializeIF returncode on wrong serialization parameters */ - virtual ReturnValue_t serialize(uint8_t **buffer, size_t *size, size_t maxSize, - Endianness streamEndianness) const override; + ReturnValue_t serialize(uint8_t **buffer, size_t *size, size_t maxSize, + Endianness streamEndianness) const override; - virtual size_t getSerializedSize() const override; + [[nodiscard]] size_t getSerializedSize() const override; /** * @brief Deserialize a LV field from a raw buffer. Zero-copy implementation @@ -41,15 +41,15 @@ class Tlv : public TlvIF { * - INVALID_TLV_TYPE * - SerializeIF returncode on wrong deserialization parameters */ - virtual ReturnValue_t deSerialize(const uint8_t **buffer, size_t *size, - Endianness streamEndianness) override; + ReturnValue_t deSerialize(const uint8_t **buffer, size_t *size, + Endianness streamEndianness) override; void setValue(uint8_t *value, size_t len); - const uint8_t *getValue() const; + [[nodiscard]] const uint8_t *getValue() const; void setType(TlvTypes type); - TlvTypes getType() const override; - uint8_t getLengthField() const override; + [[nodiscard]] TlvTypes getType() const override; + [[nodiscard]] uint8_t getLengthField() const override; private: bool checkType(uint8_t rawType); diff --git a/unittests/cfdp/pdu/testFinishedPdu.cpp b/unittests/cfdp/pdu/testFinishedPdu.cpp index c2aa3bb1..d117ed58 100644 --- a/unittests/cfdp/pdu/testFinishedPdu.cpp +++ b/unittests/cfdp/pdu/testFinishedPdu.cpp @@ -18,8 +18,8 @@ TEST_CASE("Finished PDU", "[cfdp][pdu]") { cfdp::Lv emptyFsMsg; FinishedInfo info(cfdp::ConditionCode::INACTIVITY_DETECTED, - cfdp::FinishedDeliveryCode::DATA_INCOMPLETE, - cfdp::FinishedFileStatus::DISCARDED_DELIBERATELY); + cfdp::FileDeliveryCode::DATA_INCOMPLETE, + cfdp::FileDeliveryStatus::DISCARDED_DELIBERATELY); SECTION("Serialize") { FinishPduSerializer serializer(pduConf, info); @@ -29,8 +29,8 @@ TEST_CASE("Finished PDU", "[cfdp][pdu]") { REQUIRE(((fnBuffer[1] << 8) | fnBuffer[2]) == 2); REQUIRE(fnBuffer[10] == cfdp::FileDirectives::FINISH); REQUIRE(((fnBuffer[sz - 1] >> 4) & 0x0f) == cfdp::ConditionCode::INACTIVITY_DETECTED); - REQUIRE(((fnBuffer[sz - 1] >> 2) & 0x01) == cfdp::FinishedDeliveryCode::DATA_INCOMPLETE); - REQUIRE((fnBuffer[sz - 1] & 0b11) == cfdp::FinishedFileStatus::DISCARDED_DELIBERATELY); + REQUIRE(((fnBuffer[sz - 1] >> 2) & 0x01) == cfdp::FileDeliveryCode::DATA_INCOMPLETE); + REQUIRE((fnBuffer[sz - 1] & 0b11) == cfdp::FileDeliveryStatus::DISCARDED_DELIBERATELY); REQUIRE(sz == 12); // Add a filestore response @@ -73,10 +73,10 @@ TEST_CASE("Finished PDU", "[cfdp][pdu]") { info.setConditionCode(cfdp::ConditionCode::FILESTORE_REJECTION); REQUIRE(serializer.getSerializedSize() == 12 + 14 + 15 + 4); REQUIRE(sz == 12 + 14 + 15 + 4); - info.setFileStatus(cfdp::FinishedFileStatus::DISCARDED_FILESTORE_REJECTION); - REQUIRE(info.getFileStatus() == cfdp::FinishedFileStatus::DISCARDED_FILESTORE_REJECTION); - info.setDeliveryCode(cfdp::FinishedDeliveryCode::DATA_INCOMPLETE); - REQUIRE(info.getDeliveryCode() == cfdp::FinishedDeliveryCode::DATA_INCOMPLETE); + info.setFileStatus(cfdp::FileDeliveryStatus::DISCARDED_FILESTORE_REJECTION); + REQUIRE(info.getFileStatus() == cfdp::FileDeliveryStatus::DISCARDED_FILESTORE_REJECTION); + info.setDeliveryCode(cfdp::FileDeliveryCode::DATA_INCOMPLETE); + REQUIRE(info.getDeliveryCode() == cfdp::FileDeliveryCode::DATA_INCOMPLETE); for (size_t maxSz = 0; maxSz < 45; maxSz++) { sz = 0; buffer = fnBuffer.data(); @@ -93,9 +93,9 @@ TEST_CASE("Finished PDU", "[cfdp][pdu]") { FinishPduDeserializer deserializer(fnBuffer.data(), fnBuffer.size(), emptyInfo); result = deserializer.parseData(); REQUIRE(result == HasReturnvaluesIF::RETURN_OK); - REQUIRE(emptyInfo.getFileStatus() == cfdp::FinishedFileStatus::DISCARDED_DELIBERATELY); + REQUIRE(emptyInfo.getFileStatus() == cfdp::FileDeliveryStatus::DISCARDED_DELIBERATELY); REQUIRE(emptyInfo.getConditionCode() == cfdp::ConditionCode::INACTIVITY_DETECTED); - REQUIRE(emptyInfo.getDeliveryCode() == cfdp::FinishedDeliveryCode::DATA_INCOMPLETE); + REQUIRE(emptyInfo.getDeliveryCode() == cfdp::FileDeliveryCode::DATA_INCOMPLETE); // Add a filestore response sz = 0; diff --git a/unittests/mocks/cfdp/CMakeLists.txt b/unittests/mocks/cfdp/CMakeLists.txt index 0fa0890c..769e06ae 100644 --- a/unittests/mocks/cfdp/CMakeLists.txt +++ b/unittests/mocks/cfdp/CMakeLists.txt @@ -1 +1,2 @@ -target_sources(${FSFW_TEST_TGT} PRIVATE FaultHandlerMock.cpp UserMock.cpp RemoteConfigTableMock.cpp) +target_sources(${FSFW_TEST_TGT} PRIVATE FaultHandlerMock.cpp UserMock.cpp + RemoteConfigTableMock.cpp) diff --git a/unittests/mocks/cfdp/RemoteConfigTableMock.h b/unittests/mocks/cfdp/RemoteConfigTableMock.h index 7ac25ba7..e3e954e4 100644 --- a/unittests/mocks/cfdp/RemoteConfigTableMock.h +++ b/unittests/mocks/cfdp/RemoteConfigTableMock.h @@ -5,11 +5,11 @@ namespace cfdp { -class RemoteConfigTableMock: public RemoteConfigTableIF { +class RemoteConfigTableMock : public RemoteConfigTableIF { public: bool getRemoteCfg(EntityId remoteId, RemoteEntityCfg *cfg) override; }; -} +} // namespace cfdp #endif // FSFW_TESTS_CFDP_REMOTCONFIGTABLEMOCK_H diff --git a/unittests/mocks/cfdp/UserMock.cpp b/unittests/mocks/cfdp/UserMock.cpp index c8b3b940..8037b21f 100644 --- a/unittests/mocks/cfdp/UserMock.cpp +++ b/unittests/mocks/cfdp/UserMock.cpp @@ -7,10 +7,9 @@ void cfdp::UserMock::eofSentIndication(cfdp::TransactionId id) {} void cfdp::UserMock::abandonedIndication(cfdp::TransactionId id, cfdp::ConditionCode code, uint64_t progress) {} void cfdp::UserMock::eofRecvIndication(cfdp::TransactionId id) {} -void cfdp::UserMock::transactionFinishedIndication() {} -void cfdp::UserMock::metadataRecvdIndication() {} +void cfdp::UserMock::transactionFinishedIndication(TransactionFinishedParams finishedParams) {} +void cfdp::UserMock::metadataRecvdIndication(MetadataRecvParams params) {} void cfdp::UserMock::fileSegmentRecvdIndication() {} void cfdp::UserMock::reportIndication() {} void cfdp::UserMock::suspendedIndication() {} void cfdp::UserMock::resumedIndication() {} - diff --git a/unittests/mocks/cfdp/UserMock.h b/unittests/mocks/cfdp/UserMock.h index b32e698a..9a67073d 100644 --- a/unittests/mocks/cfdp/UserMock.h +++ b/unittests/mocks/cfdp/UserMock.h @@ -2,24 +2,24 @@ #define FSFW_TESTS_CFDP_USERMOCK_H #include "fsfw/cfdp/handler/UserBase.h" - namespace cfdp { -class UserMock: public UserBase { +class UserMock : public UserBase { explicit UserMock(HasFileSystemIF& vfs); + public: void transactionIndication(TransactionId id) override; void eofSentIndication(TransactionId id) override; void abandonedIndication(TransactionId id, ConditionCode code, uint64_t progress) override; void eofRecvIndication(TransactionId id) override; - void transactionFinishedIndication() override; - void metadataRecvdIndication() override; + void transactionFinishedIndication(TransactionFinishedParams params) override; + void metadataRecvdIndication(MetadataRecvParams params) override; void fileSegmentRecvdIndication() override; void reportIndication() override; void suspendedIndication() override; void resumedIndication() override; }; -} +} // namespace cfdp #endif // FSFW_TESTS_CFDP_USERMOCK_H From 96dfe46e2552e069e29fed0b9d5483aa43f6355b Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Wed, 10 Aug 2022 09:39:57 +0200 Subject: [PATCH 048/169] added string LV tests --- src/fsfw/cfdp.h | 3 + src/fsfw/cfdp/handler/UserBase.cpp | 12 + src/fsfw/cfdp/handler/UserBase.h | 6 +- src/fsfw/cfdp/tlv/CMakeLists.txt | 1 + src/fsfw/cfdp/tlv/Lv.cpp | 11 +- src/fsfw/cfdp/tlv/Lv.h | 12 +- src/fsfw/cfdp/tlv/MessageToUserTlv.cpp | 5 +- src/fsfw/cfdp/tlv/MessageToUserTlv.h | 3 + src/fsfw/cfdp/tlv/StringLv.cpp | 7 + src/fsfw/cfdp/tlv/StringLv.h | 18 ++ src/fsfw/serialize/SerialBufferAdapter.cpp | 27 +- src/fsfw/serialize/SerialBufferAdapter.h | 18 +- unittests/cfdp/CMakeLists.txt | 3 +- unittests/cfdp/handler/testDestHandler.cpp | 1 + unittests/cfdp/handler/testDistributor.cpp | 5 +- unittests/cfdp/testLvs.cpp | 105 +++++++ unittests/cfdp/testOtherTlvs.cpp | 137 +++++++++ unittests/cfdp/testTlv.cpp | 130 ++++++++ unittests/cfdp/testTlvsLvs.cpp | 330 --------------------- unittests/mocks/cfdp/UserMock.cpp | 2 +- unittests/mocks/cfdp/UserMock.h | 2 +- 21 files changed, 466 insertions(+), 372 deletions(-) create mode 100644 src/fsfw/cfdp/tlv/StringLv.cpp create mode 100644 src/fsfw/cfdp/tlv/StringLv.h create mode 100644 unittests/cfdp/testLvs.cpp create mode 100644 unittests/cfdp/testOtherTlvs.cpp create mode 100644 unittests/cfdp/testTlv.cpp delete mode 100644 unittests/cfdp/testTlvsLvs.cpp diff --git a/src/fsfw/cfdp.h b/src/fsfw/cfdp.h index 421a7fe1..28ddfec2 100644 --- a/src/fsfw/cfdp.h +++ b/src/fsfw/cfdp.h @@ -4,5 +4,8 @@ #include "cfdp/definitions.h" #include "cfdp/handler/DestHandler.h" #include "cfdp/handler/FaultHandlerBase.h" +#include "cfdp/tlv/Lv.h" +#include "cfdp/tlv/StringLv.h" +#include "cfdp/tlv/Tlv.h" #endif // FSFW_CFDP_H diff --git a/src/fsfw/cfdp/handler/UserBase.cpp b/src/fsfw/cfdp/handler/UserBase.cpp index 212396fb..1cb726fe 100644 --- a/src/fsfw/cfdp/handler/UserBase.cpp +++ b/src/fsfw/cfdp/handler/UserBase.cpp @@ -1,3 +1,15 @@ #include "UserBase.h" +#include +#include +void cfdp::testFunc() { + std::vector testVec; + testVec.reserve(10); + std::array customMsg = {1, 2, 3, 4}; + MessageToUserTlv tlv0(customMsg.data(), customMsg.size()); + std::cout << testVec.size() << std::endl; + testVec[0] = &tlv0; + FilestoreResponseTlv tlv1(); +} + cfdp::UserBase::UserBase(HasFileSystemIF& vfs) : vfs(vfs) {} diff --git a/src/fsfw/cfdp/handler/UserBase.h b/src/fsfw/cfdp/handler/UserBase.h index 6835600c..333c7b6b 100644 --- a/src/fsfw/cfdp/handler/UserBase.h +++ b/src/fsfw/cfdp/handler/UserBase.h @@ -3,6 +3,7 @@ #include #include +#include #include "StatusReportIF.h" #include "fsfw/cfdp/VarLenFields.h" @@ -12,6 +13,8 @@ namespace cfdp { +void testFunc(); + struct TransactionFinishedParams { TransactionFinishedParams(TransactionId id, ConditionCode code, FileDeliveryStatus status, FileDeliveryCode delivCode) @@ -31,7 +34,8 @@ struct MetadataRecvParams { size_t fileSize; const char* sourceFileName; const char* destFileName; - std::pair msgsToUser; + std::vector msgsToUser; + // std::pair msgsToUser; }; struct FileSegmentRecvdParams { diff --git a/src/fsfw/cfdp/tlv/CMakeLists.txt b/src/fsfw/cfdp/tlv/CMakeLists.txt index cdf7b44a..617b1b0f 100644 --- a/src/fsfw/cfdp/tlv/CMakeLists.txt +++ b/src/fsfw/cfdp/tlv/CMakeLists.txt @@ -5,6 +5,7 @@ target_sources( FilestoreResponseTlv.cpp Lv.cpp Tlv.cpp + StringLv.cpp FlowLabelTlv.cpp MessageToUserTlv.cpp FaultHandlerOverrideTlv.cpp) diff --git a/src/fsfw/cfdp/tlv/Lv.cpp b/src/fsfw/cfdp/tlv/Lv.cpp index 09075094..1f7ecefd 100644 --- a/src/fsfw/cfdp/tlv/Lv.cpp +++ b/src/fsfw/cfdp/tlv/Lv.cpp @@ -6,9 +6,8 @@ cfdp::Lv::Lv(const uint8_t* value, size_t size) : value(value, size, true) { } } -cfdp::Lv::Lv(const char* value, size_t size) - : value(reinterpret_cast(value), size, true) { - if (size > 0) { +cfdp::Lv::Lv(const std::vector& data) : value(data.data(), data.size(), true) { + if (!data.empty()) { zeroLen = false; } } @@ -24,11 +23,11 @@ cfdp::Lv::Lv(const Lv& other) cfdp::Lv& cfdp::Lv::operator=(const Lv& other) { size_t otherSize = 0; - uint8_t* value = const_cast(other.getValue(&otherSize)); - if (value == nullptr or otherSize == 0) { + auto* otherVal = const_cast(other.getValue(&otherSize)); + if (otherVal == nullptr or otherSize == 0) { this->zeroLen = true; } - this->value.setBuffer(value, otherSize); + this->value.setBuffer(otherVal, otherSize); return *this; } diff --git a/src/fsfw/cfdp/tlv/Lv.h b/src/fsfw/cfdp/tlv/Lv.h index 4a110f90..efabfdef 100644 --- a/src/fsfw/cfdp/tlv/Lv.h +++ b/src/fsfw/cfdp/tlv/Lv.h @@ -1,5 +1,7 @@ -#ifndef FSFW_SRC_FSFW_CFDP_LV_H_ -#define FSFW_SRC_FSFW_CFDP_LV_H_ +#ifndef FSFW_CFDP_LV_H_ +#define FSFW_CFDP_LV_H_ + +#include #include "fsfw/serialize/SerialBufferAdapter.h" @@ -12,12 +14,10 @@ namespace cfdp { */ class Lv : public SerializeIF { public: + explicit Lv(const std::vector& data); Lv(const uint8_t* value, size_t size); - Lv(const char* value, size_t size); Lv(); - // Delete copy ctor and assingment ctor for now because this class contains a reference to - // data Lv(const Lv&); Lv& operator=(const Lv&); @@ -51,4 +51,4 @@ class Lv : public SerializeIF { } // namespace cfdp -#endif /* FSFW_SRC_FSFW_CFDP_LV_H_ */ +#endif /* FSFW_CFDP_LV_H_ */ diff --git a/src/fsfw/cfdp/tlv/MessageToUserTlv.cpp b/src/fsfw/cfdp/tlv/MessageToUserTlv.cpp index 9034552b..c6bf3633 100644 --- a/src/fsfw/cfdp/tlv/MessageToUserTlv.cpp +++ b/src/fsfw/cfdp/tlv/MessageToUserTlv.cpp @@ -1,6 +1,9 @@ #include "MessageToUserTlv.h" -MessageToUserTlv::MessageToUserTlv(uint8_t *value, size_t size) +MessageToUserTlv::MessageToUserTlv(uint8_t* value, size_t size) : Tlv(cfdp::TlvTypes::MSG_TO_USER, value, size) {} MessageToUserTlv::MessageToUserTlv() : Tlv() {} + +MessageToUserTlv::MessageToUserTlv(const std::vector& data) + : Tlv(cfdp::TlvTypes::MSG_TO_USER, data.data(), data.size()) {} diff --git a/src/fsfw/cfdp/tlv/MessageToUserTlv.h b/src/fsfw/cfdp/tlv/MessageToUserTlv.h index 1d00bf31..e7f63ed2 100644 --- a/src/fsfw/cfdp/tlv/MessageToUserTlv.h +++ b/src/fsfw/cfdp/tlv/MessageToUserTlv.h @@ -1,12 +1,15 @@ #ifndef FSFW_SRC_FSFW_CFDP_TLV_MESSAGETOUSERTLV_H_ #define FSFW_SRC_FSFW_CFDP_TLV_MESSAGETOUSERTLV_H_ +#include + #include "Tlv.h" class MessageToUserTlv : public cfdp::Tlv { public: MessageToUserTlv(); MessageToUserTlv(uint8_t* value, size_t size); + explicit MessageToUserTlv(const std::vector& data); private: }; diff --git a/src/fsfw/cfdp/tlv/StringLv.cpp b/src/fsfw/cfdp/tlv/StringLv.cpp new file mode 100644 index 00000000..abbdb34a --- /dev/null +++ b/src/fsfw/cfdp/tlv/StringLv.cpp @@ -0,0 +1,7 @@ +#include "StringLv.h" + +cfdp::StringLv::StringLv(const std::string& fileName) + : Lv(reinterpret_cast(fileName.data()), fileName.size()) {} + +cfdp::StringLv::StringLv(const char* filename, size_t len) + : Lv(reinterpret_cast(filename), len) {} diff --git a/src/fsfw/cfdp/tlv/StringLv.h b/src/fsfw/cfdp/tlv/StringLv.h new file mode 100644 index 00000000..86c2d738 --- /dev/null +++ b/src/fsfw/cfdp/tlv/StringLv.h @@ -0,0 +1,18 @@ +#ifndef FSFW_CFDP_STRINGLV_H +#define FSFW_CFDP_STRINGLV_H + +#include + +#include "Lv.h" + +namespace cfdp { + +class StringLv : public Lv { + public: + explicit StringLv(const std::string& fileName); + explicit StringLv(const char* filename, size_t len); +}; + +} // namespace cfdp + +#endif // FSFW_CFDP_STRINGLV_H diff --git a/src/fsfw/serialize/SerialBufferAdapter.cpp b/src/fsfw/serialize/SerialBufferAdapter.cpp index 83129982..86e20e25 100644 --- a/src/fsfw/serialize/SerialBufferAdapter.cpp +++ b/src/fsfw/serialize/SerialBufferAdapter.cpp @@ -21,15 +21,15 @@ SerialBufferAdapter::SerialBufferAdapter(uint8_t* buffer, count_t buffe bufferLength(bufferLength) {} template -SerialBufferAdapter::~SerialBufferAdapter() {} +SerialBufferAdapter::~SerialBufferAdapter() = default; template -ReturnValue_t SerialBufferAdapter::serialize(uint8_t** buffer, size_t* size, +ReturnValue_t SerialBufferAdapter::serialize(uint8_t** buffer_, size_t* size, size_t maxSize, Endianness streamEndianness) const { if (serializeLength) { ReturnValue_t result = - SerializeAdapter::serialize(&bufferLength, buffer, size, maxSize, streamEndianness); + SerializeAdapter::serialize(&bufferLength, buffer_, size, maxSize, streamEndianness); if (result != HasReturnvaluesIF::RETURN_OK) { return result; } @@ -40,16 +40,16 @@ ReturnValue_t SerialBufferAdapter::serialize(uint8_t** buffer, size_t* } if (this->constBuffer != nullptr) { - std::memcpy(*buffer, this->constBuffer, bufferLength); + std::memcpy(*buffer_, this->constBuffer, bufferLength); } else if (this->buffer != nullptr) { // This will propably be never reached, constBuffer should always be // set if non-const buffer is set. - std::memcpy(*buffer, this->buffer, bufferLength); + std::memcpy(*buffer_, this->buffer, bufferLength); } else { return HasReturnvaluesIF::RETURN_FAILED; } *size += bufferLength; - (*buffer) += bufferLength; + (*buffer_) += bufferLength; return HasReturnvaluesIF::RETURN_OK; } @@ -63,7 +63,7 @@ size_t SerialBufferAdapter::getSerializedSize() const { } template -ReturnValue_t SerialBufferAdapter::deSerialize(const uint8_t** buffer, size_t* size, +ReturnValue_t SerialBufferAdapter::deSerialize(const uint8_t** buffer_, size_t* size, Endianness streamEndianness) { if (this->buffer == nullptr) { return HasReturnvaluesIF::RETURN_FAILED; @@ -72,7 +72,7 @@ ReturnValue_t SerialBufferAdapter::deSerialize(const uint8_t** buffer, if (serializeLength) { count_t lengthField = 0; ReturnValue_t result = - SerializeAdapter::deSerialize(&lengthField, buffer, size, streamEndianness); + SerializeAdapter::deSerialize(&lengthField, buffer_, size, streamEndianness); if (result != HasReturnvaluesIF::RETURN_OK) { return result; } @@ -84,8 +84,8 @@ ReturnValue_t SerialBufferAdapter::deSerialize(const uint8_t** buffer, if (bufferLength <= *size) { *size -= bufferLength; - std::memcpy(this->buffer, *buffer, bufferLength); - (*buffer) += bufferLength; + std::memcpy(this->buffer, *buffer_, bufferLength); + (*buffer_) += bufferLength; return HasReturnvaluesIF::RETURN_OK; } else { return STREAM_TOO_SHORT; @@ -119,10 +119,9 @@ const uint8_t* SerialBufferAdapter::getConstBuffer() const { } template -void SerialBufferAdapter::setBuffer(uint8_t* buffer, count_t bufferLength) { - this->buffer = buffer; - this->constBuffer = buffer; - this->bufferLength = bufferLength; +void SerialBufferAdapter::setBuffer(const uint8_t* data, count_t len) { + this->constBuffer = data; + this->bufferLength = len; } // forward Template declaration for linker diff --git a/src/fsfw/serialize/SerialBufferAdapter.h b/src/fsfw/serialize/SerialBufferAdapter.h index 3b95fa20..7859135a 100644 --- a/src/fsfw/serialize/SerialBufferAdapter.h +++ b/src/fsfw/serialize/SerialBufferAdapter.h @@ -40,12 +40,12 @@ class SerialBufferAdapter : public SerializeIF { */ SerialBufferAdapter(uint8_t* buffer, count_t bufferLength, bool serializeLength = false); - virtual ~SerialBufferAdapter(); + ~SerialBufferAdapter() override; - virtual ReturnValue_t serialize(uint8_t** buffer, size_t* size, size_t maxSize, - Endianness streamEndianness) const override; + ReturnValue_t serialize(uint8_t** buffer_, size_t* size, size_t maxSize, + Endianness streamEndianness) const override; - virtual size_t getSerializedSize() const override; + [[nodiscard]] size_t getSerializedSize() const override; /** * @brief This function deserializes a buffer into the member buffer. @@ -53,18 +53,18 @@ class SerialBufferAdapter : public SerializeIF { * If a length field is present, it is ignored, as the size should have * been set in the constructor. If the size is not known beforehand, * consider using SerialFixedArrayListAdapter instead. - * @param buffer [out] Resulting buffer + * @param buffer_ [out] Resulting buffer * @param size remaining size to deserialize, should be larger than buffer * + size field size * @param bigEndian * @return */ - virtual ReturnValue_t deSerialize(const uint8_t** buffer, size_t* size, - Endianness streamEndianness) override; + ReturnValue_t deSerialize(const uint8_t** buffer_, size_t* size, + Endianness streamEndianness) override; uint8_t* getBuffer(); - const uint8_t* getConstBuffer() const; - void setBuffer(uint8_t* buffer, count_t bufferLength); + [[nodiscard]] const uint8_t* getConstBuffer() const; + void setBuffer(const uint8_t* buffer, count_t bufferLength); private: bool serializeLength = false; diff --git a/unittests/cfdp/CMakeLists.txt b/unittests/cfdp/CMakeLists.txt index 402381f4..1867a534 100644 --- a/unittests/cfdp/CMakeLists.txt +++ b/unittests/cfdp/CMakeLists.txt @@ -1,4 +1,5 @@ -target_sources(${FSFW_TEST_TGT} PRIVATE testCfdp.cpp testTlvsLvs.cpp) +target_sources(${FSFW_TEST_TGT} PRIVATE testCfdp.cpp testOtherTlvs.cpp + testTlv.cpp testLvs.cpp) add_subdirectory(handler) add_subdirectory(pdu) diff --git a/unittests/cfdp/handler/testDestHandler.cpp b/unittests/cfdp/handler/testDestHandler.cpp index d963b6c7..7d641a38 100644 --- a/unittests/cfdp/handler/testDestHandler.cpp +++ b/unittests/cfdp/handler/testDestHandler.cpp @@ -9,6 +9,7 @@ TEST_CASE("CFDP Dest Handler", "[cfdp]") { auto fhMock = FaultHandlerMock(); auto localEntityCfg = LocalEntityCfg(localId, IndicationCfg(), fhMock); // auto destHandler = DestHandler(); + cfdp::testFunc(); SECTION("State") {} } \ No newline at end of file diff --git a/unittests/cfdp/handler/testDistributor.cpp b/unittests/cfdp/handler/testDistributor.cpp index 2e94a55e..161e21cc 100644 --- a/unittests/cfdp/handler/testDistributor.cpp +++ b/unittests/cfdp/handler/testDistributor.cpp @@ -2,6 +2,7 @@ #include "fsfw/cfdp/CfdpDistributor.h" #include "fsfw/cfdp/pdu/MetadataPduCreator.h" +#include "fsfw/cfdp/tlv/StringLv.h" #include "fsfw/storagemanager/LocalPool.h" #include "fsfw/tcdistribution/definitions.h" #include "mocks/AcceptsTcMock.h" @@ -26,9 +27,9 @@ TEST_CASE("CFDP Distributor", "[cfdp][distributor]") { cfdp::TransactionSeqNum seqNum(UnsignedByteField(12)); auto pduConf = PduConfig(sourceId, destId, cfdp::TransmissionModes::UNACKNOWLEDGED, seqNum); std::string sourceFileString = "hello.txt"; - cfdp::Lv sourceFileName(sourceFileString.c_str(), sourceFileString.size()); + cfdp::StringLv sourceFileName(sourceFileString); std::string destFileString = "hello2.txt"; - cfdp::Lv destFileName(destFileString.c_str(), sourceFileString.size()); + cfdp::StringLv destFileName(destFileString); MetadataInfo metadataInfo(false, cfdp::ChecksumType::CRC_32, fileSize, sourceFileName, destFileName); MetadataPduCreator creator(pduConf, metadataInfo); diff --git a/unittests/cfdp/testLvs.cpp b/unittests/cfdp/testLvs.cpp new file mode 100644 index 00000000..b93458ed --- /dev/null +++ b/unittests/cfdp/testLvs.cpp @@ -0,0 +1,105 @@ +#include +#include + +#include "fsfw/cfdp.h" + +TEST_CASE("CFDP TLV", "[cfdp][lv]") { + using namespace cfdp; + ReturnValue_t result; + std::array rawBuf{}; + uint8_t* serPtr = rawBuf.data(); + const uint8_t* deserPtr = rawBuf.data(); + size_t deserSize = 0; + cfdp::EntityId sourceId = EntityId(cfdp::WidthInBytes::TWO_BYTES, 0x0ff0); + + SECTION("LV Serialization") { + std::array lvRawBuf{}; + serPtr = lvRawBuf.data(); + REQUIRE(sourceId.serialize(&serPtr, &deserSize, lvRawBuf.size(), + SerializeIF::Endianness::NETWORK) == result::OK); + REQUIRE(result == HasReturnvaluesIF::RETURN_OK); + REQUIRE(deserSize == 2); + + auto lv = cfdp::Lv(lvRawBuf.data(), 2); + REQUIRE(lv.getSerializedSize() == 3); + + SECTION("Copy") { + auto lvCopy = cfdp::Lv(lv); + REQUIRE(lvCopy.getSerializedSize() == 3); + REQUIRE(lv.getValue(nullptr) == lvCopy.getValue(nullptr)); + } + + serPtr = rawBuf.data(); + deserSize = 0; + REQUIRE(lv.serialize(&serPtr, &deserSize, rawBuf.size(), SerializeIF::Endianness::NETWORK) == + result::OK); + REQUIRE(deserSize == 3); + REQUIRE(rawBuf[0] == 2); + uint16_t sourceIdRaw = 0; + REQUIRE(SerializeAdapter::deSerialize(&sourceIdRaw, rawBuf.data() + 1, &deserSize, + SerializeIF::Endianness::BIG) == result::OK); + REQUIRE(sourceIdRaw == 0x0ff0); + } + + SECTION("Empty Serialization") { + auto lvEmpty = Lv(); + REQUIRE(lvEmpty.getSerializedSize() == 1); + serPtr = rawBuf.data(); + deserSize = 0; + result = + lvEmpty.serialize(&serPtr, &deserSize, rawBuf.size(), SerializeIF::Endianness::NETWORK); + REQUIRE(result == HasReturnvaluesIF::RETURN_OK); + REQUIRE(deserSize == 1); + deserPtr = rawBuf.data(); + result = lvEmpty.deSerialize(&deserPtr, &deserSize, SerializeIF::Endianness::BIG); + REQUIRE(result == HasReturnvaluesIF::RETURN_OK); + REQUIRE(lvEmpty.getSerializedSize() == 1); + } + + SECTION("Uninit LV") { + std::array lvRawBuf{}; + serPtr = lvRawBuf.data(); + REQUIRE(sourceId.serialize(&serPtr, &deserSize, lvRawBuf.size(), + SerializeIF::Endianness::NETWORK) == result::OK); + auto lv = cfdp::Lv(lvRawBuf.data(), 2); + serPtr = rawBuf.data(); + deserSize = 0; + result = lv.serialize(&serPtr, &deserSize, rawBuf.size(), SerializeIF::Endianness::NETWORK); + REQUIRE(result == HasReturnvaluesIF::RETURN_OK); + Lv uninitLv; + deserPtr = rawBuf.data(); + deserSize = 3; + result = uninitLv.deSerialize(&deserPtr, &deserSize, SerializeIF::Endianness::BIG); + REQUIRE(result == HasReturnvaluesIF::RETURN_OK); + REQUIRE(uninitLv.getSerializedSize() == 3); + const uint8_t* storedValue = uninitLv.getValue(nullptr); + uint16_t sourceIdRaw = 0; + REQUIRE(SerializeAdapter::deSerialize(&sourceIdRaw, storedValue, &deserSize, + SerializeIF::Endianness::BIG) == result::OK); + REQUIRE(sourceIdRaw == 0x0ff0); + } + + SECTION("Invalid Input") { + Lv uninitLv; + REQUIRE(uninitLv.deSerialize(nullptr, nullptr, SerializeIF::Endianness::BIG) == + HasReturnvaluesIF::RETURN_FAILED); + serPtr = rawBuf.data(); + deserSize = 0; + REQUIRE(uninitLv.serialize(&serPtr, &deserSize, 0, SerializeIF::Endianness::BIG) == + SerializeIF::BUFFER_TOO_SHORT); + REQUIRE(uninitLv.serialize(nullptr, nullptr, 12, SerializeIF::Endianness::BIG)); + deserSize = 0; + REQUIRE(uninitLv.deSerialize(&deserPtr, &deserSize, SerializeIF::Endianness::BIG) == + SerializeIF::STREAM_TOO_SHORT); + } + + SECTION("String LV") { + std::string filename = "hello.txt"; + StringLv sourceFileName(filename); + REQUIRE(sourceFileName.getSerializedSize() == 1 + filename.size()); + REQUIRE(sourceFileName.serializeBe(rawBuf.data(), deserSize, rawBuf.size()) == result::OK); + REQUIRE(rawBuf[0] == filename.size()); + std::string filenameFromRaw(reinterpret_cast(rawBuf.data() + 1), filename.size()); + REQUIRE(filenameFromRaw == filename); + } +} diff --git a/unittests/cfdp/testOtherTlvs.cpp b/unittests/cfdp/testOtherTlvs.cpp new file mode 100644 index 00000000..3551fcdf --- /dev/null +++ b/unittests/cfdp/testOtherTlvs.cpp @@ -0,0 +1,137 @@ +#include +#include +#include +#include +#include +#include + +#include +#include +#include + +#include "fsfw/cfdp/pdu/PduConfig.h" +#include "fsfw/cfdp/tlv/Lv.h" +#include "fsfw/cfdp/tlv/Tlv.h" +#include "fsfw/globalfunctions/arrayprinter.h" + +TEST_CASE("CFDP LV", "[cfdp][lv]") { + using namespace cfdp; + ReturnValue_t result; + std::array rawBuf{}; + uint8_t* serPtr = rawBuf.data(); + const uint8_t* deserPtr = rawBuf.data(); + size_t deserSize = 0; + cfdp::EntityId sourceId = EntityId(cfdp::WidthInBytes::TWO_BYTES, 0x0ff0); + + SECTION("Filestore Response TLV") { + std::string name = "hello.txt"; + cfdp::Lv firstName(reinterpret_cast(name.data()), name.size()); + std::string name2 = "hello2.txt"; + cfdp::Lv secondName(reinterpret_cast(name2.data()), name2.size()); + std::string msg = "12345"; + cfdp::Lv fsMsg(reinterpret_cast(msg.data()), msg.size()); + FilestoreResponseTlv response(cfdp::FilestoreActionCode::APPEND_FILE, cfdp::FSR_SUCCESS, + firstName, &fsMsg); + response.setSecondFileName(&secondName); + REQUIRE(response.getLengthField() == 10 + 11 + 6 + 1); + REQUIRE(response.getSerializedSize() == response.getLengthField() + 2); + + cfdp::Tlv rawResponse; + std::array serBuf = {}; + result = response.convertToTlv(rawResponse, serBuf.data(), serBuf.size(), + SerializeIF::Endianness::NETWORK); + REQUIRE(result == HasReturnvaluesIF::RETURN_OK); + REQUIRE(rawResponse.getType() == cfdp::TlvTypes::FILESTORE_RESPONSE); + cfdp::Lv emptyMsg; + cfdp::Lv emptySecondName; + FilestoreResponseTlv emptyTlv(firstName, &emptyMsg); + emptyTlv.setSecondFileName(&emptySecondName); + result = emptyTlv.deSerialize(rawResponse, SerializeIF::Endianness::NETWORK); + REQUIRE(result == HasReturnvaluesIF::RETURN_OK); + REQUIRE(emptyTlv.getActionCode() == cfdp::FilestoreActionCode::APPEND_FILE); + REQUIRE(emptyTlv.getStatusCode() == cfdp::FSR_SUCCESS); + size_t firstNameLen = 0; + const char* firstNamePtr = + reinterpret_cast(emptyTlv.getFirstFileName().getValue(&firstNameLen)); + auto helloString = std::string(firstNamePtr, firstNameLen); + REQUIRE(helloString == "hello.txt"); + } + + SECTION("Filestore Request TLV") { + std::string name = "hello.txt"; + cfdp::Lv firstName(reinterpret_cast(name.data()), name.size()); + std::string name2 = "hello2.txt"; + cfdp::Lv secondName(reinterpret_cast(name2.data()), name2.size()); + FilestoreRequestTlv request(cfdp::FilestoreActionCode::APPEND_FILE, firstName); + + // second name not set yet + REQUIRE(request.getLengthField() == 10 + 1); + REQUIRE(request.getSerializedSize() == request.getLengthField() + 2); + + std::array serBuf = {}; + uint8_t* ptr = serBuf.data(); + size_t sz = 0; + result = request.serialize(&ptr, &sz, serBuf.size(), SerializeIF::Endianness::NETWORK); + REQUIRE(result == cfdp::FILESTORE_REQUIRES_SECOND_FILE); + + ptr = serBuf.data(); + sz = 0; + request.setSecondFileName(&secondName); + size_t expectedSz = request.getLengthField(); + REQUIRE(expectedSz == 10 + 11 + 1); + REQUIRE(request.getSerializedSize() == expectedSz + 2); + result = request.serialize(&ptr, &sz, serBuf.size(), SerializeIF::Endianness::NETWORK); + REQUIRE(result == HasReturnvaluesIF::RETURN_OK); + REQUIRE(sz == expectedSz + 2); + + FilestoreRequestTlv emptyRequest(firstName); + emptyRequest.setSecondFileName(&secondName); + const uint8_t* constptr = serBuf.data(); + result = emptyRequest.deSerialize(&constptr, &sz, SerializeIF::Endianness::NETWORK); + REQUIRE(result == HasReturnvaluesIF::RETURN_OK); + + cfdp::Tlv rawRequest; + ptr = serBuf.data(); + sz = 0; + result = request.convertToTlv(rawRequest, serBuf.data(), serBuf.size(), + SerializeIF::Endianness::NETWORK); + REQUIRE(result == HasReturnvaluesIF::RETURN_OK); + REQUIRE(rawRequest.getType() == cfdp::TlvTypes::FILESTORE_REQUEST); + + emptyRequest.setActionCode(cfdp::FilestoreActionCode::DELETE_FILE); + result = emptyRequest.deSerialize(rawRequest, SerializeIF::Endianness::NETWORK); + REQUIRE(result == HasReturnvaluesIF::RETURN_OK); + REQUIRE(emptyRequest.getType() == cfdp::TlvTypes::FILESTORE_REQUEST); + REQUIRE(emptyRequest.getActionCode() == cfdp::FilestoreActionCode::APPEND_FILE); + } + + SECTION("Other") { + MessageToUserTlv emptyTlv; + uint8_t flowLabel = 1; + FlowLabelTlv flowLabelTlv(&flowLabel, 1); + + FaultHandlerOverrideTlv faultOverrideTlv(cfdp::ConditionCode::FILESTORE_REJECTION, + cfdp::FaultHandlerCodes::NOTICE_OF_CANCELLATION); + size_t sz = 0; + result = + faultOverrideTlv.serialize(&serPtr, &sz, rawBuf.size(), SerializeIF::Endianness::NETWORK); + REQUIRE(faultOverrideTlv.getSerializedSize() == 3); + REQUIRE(sz == 3); + REQUIRE(result == HasReturnvaluesIF::RETURN_OK); + + FaultHandlerOverrideTlv emptyOverrideTlv; + result = emptyOverrideTlv.deSerialize(&deserPtr, &sz, SerializeIF::Endianness::NETWORK); + REQUIRE(result == HasReturnvaluesIF::RETURN_OK); + + EntityId entId(cfdp::WidthInBytes::TWO_BYTES, 0x42); + EntityId emptyId; + EntityIdTlv idTlv(emptyId); + serPtr = rawBuf.data(); + result = idTlv.serialize(&serPtr, &deserSize, rawBuf.size(), SerializeIF::Endianness::NETWORK); + cfdp::Tlv rawTlv(cfdp::TlvTypes::ENTITY_ID, rawBuf.data() + 2, 2); + REQUIRE(result == HasReturnvaluesIF::RETURN_OK); + deserPtr = rawBuf.data(); + result = idTlv.deSerialize(rawTlv, SerializeIF::Endianness::NETWORK); + REQUIRE(result == HasReturnvaluesIF::RETURN_OK); + } +} diff --git a/unittests/cfdp/testTlv.cpp b/unittests/cfdp/testTlv.cpp new file mode 100644 index 00000000..5b6e0a63 --- /dev/null +++ b/unittests/cfdp/testTlv.cpp @@ -0,0 +1,130 @@ +#include +#include + +#include "fsfw/cfdp.h" + +TEST_CASE("CFDP TLV", "[cfdp][tlv]") { + using namespace cfdp; + ReturnValue_t result; + std::array rawBuf{}; + uint8_t* serPtr = rawBuf.data(); + const uint8_t* deserPtr = rawBuf.data(); + size_t deserSize = 0; + cfdp::EntityId sourceId = EntityId(cfdp::WidthInBytes::TWO_BYTES, 0x0ff0); + + SECTION("Entity ID Serialization") { + REQUIRE(sourceId.serialize(&serPtr, &deserSize, rawBuf.size(), + SerializeIF::Endianness::NETWORK) == result::OK); + REQUIRE(deserSize == 2); + } + + SECTION("TLV Serialization") { + std::array tlvBuf{}; + REQUIRE(sourceId.serializeBe(tlvBuf.data(), deserSize, tlvBuf.size()) == result::OK); + auto tlv = Tlv(TlvTypes::ENTITY_ID, tlvBuf.data(), deserSize); + REQUIRE(tlv.getSerializedSize() == 4); + REQUIRE(tlv.getLengthField() == 2); + deserSize = 0; + REQUIRE(tlv.serialize(&serPtr, &deserSize, rawBuf.size(), SerializeIF::Endianness::NETWORK) == + result::OK); + REQUIRE(deserSize == 4); + REQUIRE(rawBuf[0] == TlvTypes::ENTITY_ID); + REQUIRE(rawBuf[1] == 2); + uint16_t entityId = 0; + REQUIRE(SerializeAdapter::deSerialize(&entityId, rawBuf.data() + 2, &deserSize, + SerializeIF::Endianness::NETWORK) == result::OK); + REQUIRE(entityId == 0x0ff0); + } + + SECTION("TLV Other Value") { + auto tlv = Tlv(TlvTypes::ENTITY_ID, rawBuf.data(), deserSize); + // Set new value + sourceId.setValue(cfdp::WidthInBytes::FOUR_BYTES, 12); + REQUIRE(sourceId.serialize(&serPtr, &deserSize, rawBuf.size(), + SerializeIF::Endianness::NETWORK) == result::OK); + tlv.setValue(rawBuf.data(), cfdp::WidthInBytes::FOUR_BYTES); + serPtr = rawBuf.data(); + deserSize = 0; + result = tlv.serialize(&serPtr, &deserSize, rawBuf.size(), SerializeIF::Endianness::NETWORK); + REQUIRE(result == HasReturnvaluesIF::RETURN_OK); + REQUIRE(rawBuf[0] == TlvTypes::ENTITY_ID); + REQUIRE(rawBuf[1] == 4); + + REQUIRE(result == HasReturnvaluesIF::RETURN_OK); + } + + SECTION("TLV Invalid") { + auto tlvInvalid = Tlv(cfdp::TlvTypes::INVALID_TLV, rawBuf.data(), 0); + REQUIRE(tlvInvalid.serialize(&serPtr, &deserSize, rawBuf.size(), + SerializeIF::Endianness::NETWORK) != HasReturnvaluesIF::RETURN_OK); + tlvInvalid = Tlv(cfdp::TlvTypes::ENTITY_ID, nullptr, 3); + REQUIRE(tlvInvalid.serialize(&serPtr, &deserSize, rawBuf.size(), + SerializeIF::Endianness::NETWORK) != HasReturnvaluesIF::RETURN_OK); + REQUIRE(tlvInvalid.serialize(&serPtr, &deserSize, 0, SerializeIF::Endianness::NETWORK) != + HasReturnvaluesIF::RETURN_OK); + REQUIRE(tlvInvalid.getSerializedSize() == 0); + REQUIRE(tlvInvalid.serialize(nullptr, nullptr, 0, SerializeIF::Endianness::NETWORK) != + HasReturnvaluesIF::RETURN_OK); + } + + SECTION("TLV Zero Length Field") { + Tlv zeroLenField(TlvTypes::FAULT_HANDLER, nullptr, 0); + REQUIRE(zeroLenField.getSerializedSize() == 2); + serPtr = rawBuf.data(); + deserSize = 0; + REQUIRE(zeroLenField.serialize(&serPtr, &deserSize, rawBuf.size(), + SerializeIF::Endianness::NETWORK) == + HasReturnvaluesIF::RETURN_OK); + REQUIRE(rawBuf[0] == TlvTypes::FAULT_HANDLER); + REQUIRE(rawBuf[1] == 0); + } + + SECTION("TLV Deserialization") { + // Serialization was tested before, generate raw data now + std::array tlvRawBuf{}; + serPtr = tlvRawBuf.data(); + result = + sourceId.serialize(&serPtr, &deserSize, tlvRawBuf.size(), SerializeIF::Endianness::NETWORK); + auto tlvSerialization = Tlv(TlvTypes::ENTITY_ID, tlvRawBuf.data(), deserSize); + serPtr = rawBuf.data(); + deserSize = 0; + result = tlvSerialization.serialize(&serPtr, &deserSize, rawBuf.size(), + SerializeIF::Endianness::NETWORK); + Tlv tlv; + deserPtr = rawBuf.data(); + result = tlv.deSerialize(&deserPtr, &deserSize, SerializeIF::Endianness::NETWORK); + REQUIRE(result == HasReturnvaluesIF::RETURN_OK); + REQUIRE(tlv.getSerializedSize() == 4); + REQUIRE(tlv.getType() == TlvTypes::ENTITY_ID); + deserPtr = tlv.getValue(); + uint16_t entityId = 0; + deserSize = 0; + SerializeAdapter::deSerialize(&entityId, deserPtr, &deserSize, + SerializeIF::Endianness::NETWORK); + REQUIRE(entityId == 0x0ff0); + + REQUIRE(tlv.deSerialize(nullptr, nullptr, SerializeIF::Endianness::NETWORK) != + HasReturnvaluesIF::RETURN_OK); + deserPtr = rawBuf.data(); + deserSize = 0; + REQUIRE(tlv.deSerialize(&deserPtr, &deserSize, SerializeIF::Endianness::NETWORK) == + SerializeIF::STREAM_TOO_SHORT); + // Set invalid TLV + rawBuf[0] = TlvTypes::INVALID_TLV; + deserSize = 4; + REQUIRE(tlv.deSerialize(&deserPtr, &deserSize, SerializeIF::Endianness::NETWORK) != + HasReturnvaluesIF::RETURN_OK); + + Tlv zeroLenField(TlvTypes::FAULT_HANDLER, nullptr, 0); + serPtr = rawBuf.data(); + deserSize = 0; + REQUIRE(zeroLenField.serialize(&serPtr, &deserSize, rawBuf.size(), + SerializeIF::Endianness::NETWORK) == + HasReturnvaluesIF::RETURN_OK); + deserPtr = rawBuf.data(); + result = zeroLenField.deSerialize(&deserPtr, &deserSize, SerializeIF::Endianness::NETWORK); + REQUIRE(result == HasReturnvaluesIF::RETURN_OK); + REQUIRE(zeroLenField.getSerializedSize() == 2); + REQUIRE(deserSize == 0); + } +} diff --git a/unittests/cfdp/testTlvsLvs.cpp b/unittests/cfdp/testTlvsLvs.cpp deleted file mode 100644 index 7536069f..00000000 --- a/unittests/cfdp/testTlvsLvs.cpp +++ /dev/null @@ -1,330 +0,0 @@ -#include -#include -#include -#include -#include -#include - -#include -#include -#include - -#include "fsfw/cfdp/pdu/PduConfig.h" -#include "fsfw/cfdp/tlv/Lv.h" -#include "fsfw/cfdp/tlv/Tlv.h" -#include "fsfw/globalfunctions/arrayprinter.h" - -TEST_CASE("CFDP TLV LV", "[cfdp]") { - using namespace cfdp; - ReturnValue_t result; - std::array rawBuf{}; - uint8_t* serPtr = rawBuf.data(); - const uint8_t* deserPtr = rawBuf.data(); - size_t deserSize = 0; - cfdp::EntityId sourceId = EntityId(cfdp::WidthInBytes::TWO_BYTES, 0x0ff0); - - SECTION("TLV Serialization") { - std::array tlvRawBuf{}; - serPtr = tlvRawBuf.data(); - result = - sourceId.serialize(&serPtr, &deserSize, tlvRawBuf.size(), SerializeIF::Endianness::NETWORK); - REQUIRE(result == HasReturnvaluesIF::RETURN_OK); - REQUIRE(deserSize == 2); - auto tlv = Tlv(TlvTypes::ENTITY_ID, tlvRawBuf.data(), deserSize); - REQUIRE(tlv.getSerializedSize() == 4); - REQUIRE(tlv.getLengthField() == 2); - serPtr = rawBuf.data(); - deserSize = 0; - result = tlv.serialize(&serPtr, &deserSize, rawBuf.size(), SerializeIF::Endianness::NETWORK); - REQUIRE(result == HasReturnvaluesIF::RETURN_OK); - REQUIRE(deserSize == 4); - REQUIRE(rawBuf[0] == TlvTypes::ENTITY_ID); - REQUIRE(rawBuf[1] == 2); - uint16_t entityId = 0; - SerializeAdapter::deSerialize(&entityId, rawBuf.data() + 2, &deserSize, - SerializeIF::Endianness::NETWORK); - REQUIRE(entityId == 0x0ff0); - - // Set new value - sourceId.setValue(cfdp::WidthInBytes::FOUR_BYTES, 12); - serPtr = tlvRawBuf.data(); - deserSize = 0; - result = - sourceId.serialize(&serPtr, &deserSize, tlvRawBuf.size(), SerializeIF::Endianness::NETWORK); - tlv.setValue(tlvRawBuf.data(), cfdp::WidthInBytes::FOUR_BYTES); - serPtr = rawBuf.data(); - deserSize = 0; - result = tlv.serialize(&serPtr, &deserSize, rawBuf.size(), SerializeIF::Endianness::NETWORK); - REQUIRE(result == HasReturnvaluesIF::RETURN_OK); - REQUIRE(rawBuf[0] == TlvTypes::ENTITY_ID); - REQUIRE(rawBuf[1] == 4); - - REQUIRE(result == HasReturnvaluesIF::RETURN_OK); - - serPtr = rawBuf.data(); - deserSize = 0; - auto tlvInvalid = Tlv(cfdp::TlvTypes::INVALID_TLV, tlvRawBuf.data(), 0); - REQUIRE(tlvInvalid.serialize(&serPtr, &deserSize, rawBuf.size(), - SerializeIF::Endianness::NETWORK) != HasReturnvaluesIF::RETURN_OK); - tlvInvalid = Tlv(cfdp::TlvTypes::ENTITY_ID, nullptr, 3); - REQUIRE(tlvInvalid.serialize(&serPtr, &deserSize, rawBuf.size(), - SerializeIF::Endianness::NETWORK) != HasReturnvaluesIF::RETURN_OK); - REQUIRE(tlvInvalid.serialize(&serPtr, &deserSize, 0, SerializeIF::Endianness::NETWORK) != - HasReturnvaluesIF::RETURN_OK); - REQUIRE(tlvInvalid.getSerializedSize() == 0); - REQUIRE(tlvInvalid.serialize(nullptr, nullptr, 0, SerializeIF::Endianness::NETWORK) != - HasReturnvaluesIF::RETURN_OK); - - Tlv zeroLenField(TlvTypes::FAULT_HANDLER, nullptr, 0); - REQUIRE(zeroLenField.getSerializedSize() == 2); - serPtr = rawBuf.data(); - deserSize = 0; - REQUIRE(zeroLenField.serialize(&serPtr, &deserSize, rawBuf.size(), - SerializeIF::Endianness::NETWORK) == - HasReturnvaluesIF::RETURN_OK); - REQUIRE(rawBuf[0] == TlvTypes::FAULT_HANDLER); - REQUIRE(rawBuf[1] == 0); - } - - SECTION("TLV Deserialization") { - // Serialization was tested before, generate raw data now - std::array tlvRawBuf{}; - serPtr = tlvRawBuf.data(); - result = - sourceId.serialize(&serPtr, &deserSize, tlvRawBuf.size(), SerializeIF::Endianness::NETWORK); - auto tlvSerialization = Tlv(TlvTypes::ENTITY_ID, tlvRawBuf.data(), deserSize); - serPtr = rawBuf.data(); - deserSize = 0; - result = tlvSerialization.serialize(&serPtr, &deserSize, rawBuf.size(), - SerializeIF::Endianness::NETWORK); - Tlv tlv; - deserPtr = rawBuf.data(); - result = tlv.deSerialize(&deserPtr, &deserSize, SerializeIF::Endianness::NETWORK); - REQUIRE(result == HasReturnvaluesIF::RETURN_OK); - REQUIRE(tlv.getSerializedSize() == 4); - REQUIRE(tlv.getType() == TlvTypes::ENTITY_ID); - deserPtr = tlv.getValue(); - uint16_t entityId = 0; - deserSize = 0; - SerializeAdapter::deSerialize(&entityId, deserPtr, &deserSize, - SerializeIF::Endianness::NETWORK); - REQUIRE(entityId == 0x0ff0); - - REQUIRE(tlv.deSerialize(nullptr, nullptr, SerializeIF::Endianness::NETWORK) != - HasReturnvaluesIF::RETURN_OK); - deserPtr = rawBuf.data(); - deserSize = 0; - REQUIRE(tlv.deSerialize(&deserPtr, &deserSize, SerializeIF::Endianness::NETWORK) == - SerializeIF::STREAM_TOO_SHORT); - // Set invalid TLV - rawBuf[0] = TlvTypes::INVALID_TLV; - deserSize = 4; - REQUIRE(tlv.deSerialize(&deserPtr, &deserSize, SerializeIF::Endianness::NETWORK) != - HasReturnvaluesIF::RETURN_OK); - - Tlv zeroLenField(TlvTypes::FAULT_HANDLER, nullptr, 0); - serPtr = rawBuf.data(); - deserSize = 0; - REQUIRE(zeroLenField.serialize(&serPtr, &deserSize, rawBuf.size(), - SerializeIF::Endianness::NETWORK) == - HasReturnvaluesIF::RETURN_OK); - deserPtr = rawBuf.data(); - result = zeroLenField.deSerialize(&deserPtr, &deserSize, SerializeIF::Endianness::NETWORK); - REQUIRE(result == HasReturnvaluesIF::RETURN_OK); - REQUIRE(zeroLenField.getSerializedSize() == 2); - REQUIRE(deserSize == 0); - } - - SECTION("LV Serialization") { - std::array lvRawBuf{}; - serPtr = lvRawBuf.data(); - result = - sourceId.serialize(&serPtr, &deserSize, lvRawBuf.size(), SerializeIF::Endianness::NETWORK); - REQUIRE(result == HasReturnvaluesIF::RETURN_OK); - REQUIRE(deserSize == 2); - auto lv = cfdp::Lv(lvRawBuf.data(), 2); - auto lvCopy = cfdp::Lv(lv); - REQUIRE(lv.getSerializedSize() == 3); - REQUIRE(lvCopy.getSerializedSize() == 3); - REQUIRE(lv.getValue(nullptr) == lvCopy.getValue(nullptr)); - serPtr = rawBuf.data(); - deserSize = 0; - result = lv.serialize(&serPtr, &deserSize, rawBuf.size(), SerializeIF::Endianness::NETWORK); - REQUIRE(result == HasReturnvaluesIF::RETURN_OK); - REQUIRE(deserSize == 3); - REQUIRE(rawBuf[0] == 2); - uint16_t sourceIdRaw = 0; - result = SerializeAdapter::deSerialize(&sourceIdRaw, rawBuf.data() + 1, &deserSize, - SerializeIF::Endianness::BIG); - REQUIRE(sourceIdRaw == 0x0ff0); - - auto lvEmpty = Lv(); - REQUIRE(lvEmpty.getSerializedSize() == 1); - serPtr = rawBuf.data(); - deserSize = 0; - result = - lvEmpty.serialize(&serPtr, &deserSize, rawBuf.size(), SerializeIF::Endianness::NETWORK); - REQUIRE(result == HasReturnvaluesIF::RETURN_OK); - REQUIRE(deserSize == 1); - } - - SECTION("LV Deserialization") { - std::array lvRawBuf{}; - serPtr = lvRawBuf.data(); - result = - sourceId.serialize(&serPtr, &deserSize, lvRawBuf.size(), SerializeIF::Endianness::NETWORK); - auto lv = cfdp::Lv(lvRawBuf.data(), 2); - serPtr = rawBuf.data(); - deserSize = 0; - result = lv.serialize(&serPtr, &deserSize, rawBuf.size(), SerializeIF::Endianness::NETWORK); - REQUIRE(result == HasReturnvaluesIF::RETURN_OK); - - Lv uninitLv; - deserPtr = rawBuf.data(); - deserSize = 3; - result = uninitLv.deSerialize(&deserPtr, &deserSize, SerializeIF::Endianness::BIG); - REQUIRE(result == HasReturnvaluesIF::RETURN_OK); - REQUIRE(uninitLv.getSerializedSize() == 3); - const uint8_t* storedValue = uninitLv.getValue(nullptr); - uint16_t sourceIdRaw = 0; - result = SerializeAdapter::deSerialize(&sourceIdRaw, storedValue, &deserSize, - SerializeIF::Endianness::BIG); - REQUIRE(sourceIdRaw == 0x0ff0); - - auto lvEmpty = Lv(); - REQUIRE(lvEmpty.getSerializedSize() == 1); - serPtr = rawBuf.data(); - deserSize = 0; - result = - lvEmpty.serialize(&serPtr, &deserSize, rawBuf.size(), SerializeIF::Endianness::NETWORK); - REQUIRE(result == HasReturnvaluesIF::RETURN_OK); - REQUIRE(deserSize == 1); - deserPtr = rawBuf.data(); - result = uninitLv.deSerialize(&deserPtr, &deserSize, SerializeIF::Endianness::BIG); - REQUIRE(result == HasReturnvaluesIF::RETURN_OK); - REQUIRE(uninitLv.getSerializedSize() == 1); - - REQUIRE(uninitLv.deSerialize(nullptr, nullptr, SerializeIF::Endianness::BIG) == - HasReturnvaluesIF::RETURN_FAILED); - serPtr = rawBuf.data(); - deserSize = 0; - REQUIRE(uninitLv.serialize(&serPtr, &deserSize, 0, SerializeIF::Endianness::BIG) == - SerializeIF::BUFFER_TOO_SHORT); - REQUIRE(uninitLv.serialize(nullptr, nullptr, 12, SerializeIF::Endianness::BIG)); - deserSize = 0; - REQUIRE(uninitLv.deSerialize(&deserPtr, &deserSize, SerializeIF::Endianness::BIG) == - SerializeIF::STREAM_TOO_SHORT); - } - - SECTION("Filestore Response TLV") { - std::string name = "hello.txt"; - cfdp::Lv firstName(reinterpret_cast(name.data()), name.size()); - std::string name2 = "hello2.txt"; - cfdp::Lv secondName(reinterpret_cast(name2.data()), name2.size()); - std::string msg = "12345"; - cfdp::Lv fsMsg(reinterpret_cast(msg.data()), msg.size()); - FilestoreResponseTlv response(cfdp::FilestoreActionCode::APPEND_FILE, cfdp::FSR_SUCCESS, - firstName, &fsMsg); - response.setSecondFileName(&secondName); - REQUIRE(response.getLengthField() == 10 + 11 + 6 + 1); - REQUIRE(response.getSerializedSize() == response.getLengthField() + 2); - - cfdp::Tlv rawResponse; - std::array serBuf = {}; - result = response.convertToTlv(rawResponse, serBuf.data(), serBuf.size(), - SerializeIF::Endianness::NETWORK); - REQUIRE(result == HasReturnvaluesIF::RETURN_OK); - REQUIRE(rawResponse.getType() == cfdp::TlvTypes::FILESTORE_RESPONSE); - cfdp::Lv emptyMsg; - cfdp::Lv emptySecondName; - FilestoreResponseTlv emptyTlv(firstName, &emptyMsg); - emptyTlv.setSecondFileName(&emptySecondName); - result = emptyTlv.deSerialize(rawResponse, SerializeIF::Endianness::NETWORK); - REQUIRE(result == HasReturnvaluesIF::RETURN_OK); - REQUIRE(emptyTlv.getActionCode() == cfdp::FilestoreActionCode::APPEND_FILE); - REQUIRE(emptyTlv.getStatusCode() == cfdp::FSR_SUCCESS); - size_t firstNameLen = 0; - const char* firstNamePtr = - reinterpret_cast(emptyTlv.getFirstFileName().getValue(&firstNameLen)); - auto helloString = std::string(firstNamePtr, firstNameLen); - REQUIRE(helloString == "hello.txt"); - } - - SECTION("Filestore Request TLV") { - std::string name = "hello.txt"; - cfdp::Lv firstName(reinterpret_cast(name.data()), name.size()); - std::string name2 = "hello2.txt"; - cfdp::Lv secondName(reinterpret_cast(name2.data()), name2.size()); - FilestoreRequestTlv request(cfdp::FilestoreActionCode::APPEND_FILE, firstName); - - // second name not set yet - REQUIRE(request.getLengthField() == 10 + 1); - REQUIRE(request.getSerializedSize() == request.getLengthField() + 2); - - std::array serBuf = {}; - uint8_t* ptr = serBuf.data(); - size_t sz = 0; - result = request.serialize(&ptr, &sz, serBuf.size(), SerializeIF::Endianness::NETWORK); - REQUIRE(result == cfdp::FILESTORE_REQUIRES_SECOND_FILE); - - ptr = serBuf.data(); - sz = 0; - request.setSecondFileName(&secondName); - size_t expectedSz = request.getLengthField(); - REQUIRE(expectedSz == 10 + 11 + 1); - REQUIRE(request.getSerializedSize() == expectedSz + 2); - result = request.serialize(&ptr, &sz, serBuf.size(), SerializeIF::Endianness::NETWORK); - REQUIRE(result == HasReturnvaluesIF::RETURN_OK); - REQUIRE(sz == expectedSz + 2); - - FilestoreRequestTlv emptyRequest(firstName); - emptyRequest.setSecondFileName(&secondName); - const uint8_t* constptr = serBuf.data(); - result = emptyRequest.deSerialize(&constptr, &sz, SerializeIF::Endianness::NETWORK); - REQUIRE(result == HasReturnvaluesIF::RETURN_OK); - - cfdp::Tlv rawRequest; - ptr = serBuf.data(); - sz = 0; - result = request.convertToTlv(rawRequest, serBuf.data(), serBuf.size(), - SerializeIF::Endianness::NETWORK); - REQUIRE(result == HasReturnvaluesIF::RETURN_OK); - REQUIRE(rawRequest.getType() == cfdp::TlvTypes::FILESTORE_REQUEST); - - emptyRequest.setActionCode(cfdp::FilestoreActionCode::DELETE_FILE); - result = emptyRequest.deSerialize(rawRequest, SerializeIF::Endianness::NETWORK); - REQUIRE(result == HasReturnvaluesIF::RETURN_OK); - REQUIRE(emptyRequest.getType() == cfdp::TlvTypes::FILESTORE_REQUEST); - REQUIRE(emptyRequest.getActionCode() == cfdp::FilestoreActionCode::APPEND_FILE); - } - - SECTION("Other") { - MessageToUserTlv emptyTlv; - uint8_t flowLabel = 1; - FlowLabelTlv flowLabelTlv(&flowLabel, 1); - - FaultHandlerOverrideTlv faultOverrideTlv(cfdp::ConditionCode::FILESTORE_REJECTION, - cfdp::FaultHandlerCodes::NOTICE_OF_CANCELLATION); - size_t sz = 0; - result = - faultOverrideTlv.serialize(&serPtr, &sz, rawBuf.size(), SerializeIF::Endianness::NETWORK); - REQUIRE(faultOverrideTlv.getSerializedSize() == 3); - REQUIRE(sz == 3); - REQUIRE(result == HasReturnvaluesIF::RETURN_OK); - - FaultHandlerOverrideTlv emptyOverrideTlv; - result = emptyOverrideTlv.deSerialize(&deserPtr, &sz, SerializeIF::Endianness::NETWORK); - REQUIRE(result == HasReturnvaluesIF::RETURN_OK); - - EntityId entId(cfdp::WidthInBytes::TWO_BYTES, 0x42); - EntityId emptyId; - EntityIdTlv idTlv(emptyId); - serPtr = rawBuf.data(); - result = idTlv.serialize(&serPtr, &deserSize, rawBuf.size(), SerializeIF::Endianness::NETWORK); - cfdp::Tlv rawTlv(cfdp::TlvTypes::ENTITY_ID, rawBuf.data() + 2, 2); - REQUIRE(result == HasReturnvaluesIF::RETURN_OK); - deserPtr = rawBuf.data(); - result = idTlv.deSerialize(rawTlv, SerializeIF::Endianness::NETWORK); - REQUIRE(result == HasReturnvaluesIF::RETURN_OK); - } -} diff --git a/unittests/mocks/cfdp/UserMock.cpp b/unittests/mocks/cfdp/UserMock.cpp index 8037b21f..a38ceefc 100644 --- a/unittests/mocks/cfdp/UserMock.cpp +++ b/unittests/mocks/cfdp/UserMock.cpp @@ -9,7 +9,7 @@ void cfdp::UserMock::abandonedIndication(cfdp::TransactionId id, cfdp::Condition void cfdp::UserMock::eofRecvIndication(cfdp::TransactionId id) {} void cfdp::UserMock::transactionFinishedIndication(TransactionFinishedParams finishedParams) {} void cfdp::UserMock::metadataRecvdIndication(MetadataRecvParams params) {} -void cfdp::UserMock::fileSegmentRecvdIndication() {} +void cfdp::UserMock::fileSegmentRecvdIndication(FileSegmentRecvdParams params) {} void cfdp::UserMock::reportIndication() {} void cfdp::UserMock::suspendedIndication() {} void cfdp::UserMock::resumedIndication() {} diff --git a/unittests/mocks/cfdp/UserMock.h b/unittests/mocks/cfdp/UserMock.h index 9a67073d..bcdff3c9 100644 --- a/unittests/mocks/cfdp/UserMock.h +++ b/unittests/mocks/cfdp/UserMock.h @@ -14,7 +14,7 @@ class UserMock : public UserBase { void eofRecvIndication(TransactionId id) override; void transactionFinishedIndication(TransactionFinishedParams params) override; void metadataRecvdIndication(MetadataRecvParams params) override; - void fileSegmentRecvdIndication() override; + void fileSegmentRecvdIndication(FileSegmentRecvdParams params) override; void reportIndication() override; void suspendedIndication() override; void resumedIndication() override; From e45a99143cdaf58175e20f9bcc896c5d66295ee7 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Wed, 10 Aug 2022 09:45:24 +0200 Subject: [PATCH 049/169] added const char* test --- unittests/cfdp/testLvs.cpp | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/unittests/cfdp/testLvs.cpp b/unittests/cfdp/testLvs.cpp index b93458ed..c3f19d9c 100644 --- a/unittests/cfdp/testLvs.cpp +++ b/unittests/cfdp/testLvs.cpp @@ -93,7 +93,7 @@ TEST_CASE("CFDP TLV", "[cfdp][lv]") { SerializeIF::STREAM_TOO_SHORT); } - SECTION("String LV") { + SECTION("String LV String") { std::string filename = "hello.txt"; StringLv sourceFileName(filename); REQUIRE(sourceFileName.getSerializedSize() == 1 + filename.size()); @@ -102,4 +102,15 @@ TEST_CASE("CFDP TLV", "[cfdp][lv]") { std::string filenameFromRaw(reinterpret_cast(rawBuf.data() + 1), filename.size()); REQUIRE(filenameFromRaw == filename); } + + SECTION("String LV Const Char") { + const char filename[] = "hello.txt"; + StringLv sourceFileName(filename, sizeof(filename) - 1); + REQUIRE(sourceFileName.getSerializedSize() == 1 + sizeof(filename) - 1); + REQUIRE(sourceFileName.serializeBe(rawBuf.data(), deserSize, rawBuf.size()) == result::OK); + REQUIRE(rawBuf[0] == sizeof(filename) - 1); + rawBuf[deserSize] = '\0'; + const char* filenameFromRaw = reinterpret_cast(rawBuf.data() + 1); + REQUIRE(std::strcmp(filename, filenameFromRaw) == 0); + } } From 3e1fd15613a5311a5e98f40216be21ce0bb5f0d6 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Wed, 10 Aug 2022 10:34:02 +0200 Subject: [PATCH 050/169] completed all indication parameters --- src/fsfw/cfdp/handler/UserBase.cpp | 9 --------- src/fsfw/cfdp/handler/UserBase.h | 23 +++++++++------------- src/fsfw/cfdp/tlv/FilestoreRequestTlv.cpp | 4 ++-- src/fsfw/cfdp/tlv/FilestoreRequestTlv.h | 8 ++++---- src/fsfw/cfdp/tlv/FilestoreResponseTlv.cpp | 12 +++++------ src/fsfw/cfdp/tlv/FilestoreResponseTlv.h | 15 +++++++------- src/fsfw/cfdp/tlv/FilestoreTlvBase.h | 17 ++++++++-------- src/fsfw/cfdp/tlv/StringLv.cpp | 2 ++ src/fsfw/cfdp/tlv/StringLv.h | 1 + unittests/cfdp/handler/testDestHandler.cpp | 2 -- unittests/cfdp/pdu/testFinishedPdu.cpp | 8 ++++---- unittests/cfdp/pdu/testMetadataPdu.cpp | 3 +-- unittests/cfdp/testOtherTlvs.cpp | 12 +++++------ unittests/mocks/cfdp/UserMock.cpp | 10 ++++++---- unittests/mocks/cfdp/UserMock.h | 11 ++++++----- 15 files changed, 64 insertions(+), 73 deletions(-) diff --git a/src/fsfw/cfdp/handler/UserBase.cpp b/src/fsfw/cfdp/handler/UserBase.cpp index 1cb726fe..9e757896 100644 --- a/src/fsfw/cfdp/handler/UserBase.cpp +++ b/src/fsfw/cfdp/handler/UserBase.cpp @@ -2,14 +2,5 @@ #include #include -void cfdp::testFunc() { - std::vector testVec; - testVec.reserve(10); - std::array customMsg = {1, 2, 3, 4}; - MessageToUserTlv tlv0(customMsg.data(), customMsg.size()); - std::cout << testVec.size() << std::endl; - testVec[0] = &tlv0; - FilestoreResponseTlv tlv1(); -} cfdp::UserBase::UserBase(HasFileSystemIF& vfs) : vfs(vfs) {} diff --git a/src/fsfw/cfdp/handler/UserBase.h b/src/fsfw/cfdp/handler/UserBase.h index 333c7b6b..34af89a5 100644 --- a/src/fsfw/cfdp/handler/UserBase.h +++ b/src/fsfw/cfdp/handler/UserBase.h @@ -13,8 +13,6 @@ namespace cfdp { -void testFunc(); - struct TransactionFinishedParams { TransactionFinishedParams(TransactionId id, ConditionCode code, FileDeliveryStatus status, FileDeliveryCode delivCode) @@ -24,18 +22,17 @@ struct TransactionFinishedParams { ConditionCode condCode; FileDeliveryStatus status; FileDeliveryCode deliveryCode; - std::pair fsResponses; + std::vector fsResponses; StatusReportIF* statusReport = nullptr; }; -struct MetadataRecvParams { +struct MetadataRecvdParams { TransactionId id; EntityId sourceId; size_t fileSize; const char* sourceFileName; const char* destFileName; std::vector msgsToUser; - // std::pair msgsToUser; }; struct FileSegmentRecvdParams { @@ -65,17 +62,15 @@ class UserBase { virtual void transactionIndication(TransactionId id) = 0; virtual void eofSentIndication(TransactionId id) = 0; - - virtual void abandonedIndication(TransactionId id, ConditionCode code, uint64_t progress) = 0; - virtual void eofRecvIndication(TransactionId id) = 0; - - // TODO: Parameters virtual void transactionFinishedIndication(TransactionFinishedParams params) = 0; - virtual void metadataRecvdIndication(MetadataRecvParams params) = 0; + virtual void metadataRecvdIndication(MetadataRecvdParams params) = 0; virtual void fileSegmentRecvdIndication(FileSegmentRecvdParams params) = 0; - virtual void reportIndication() = 0; - virtual void suspendedIndication() = 0; - virtual void resumedIndication() = 0; + virtual void reportIndication(TransactionId id, StatusReportIF& report) = 0; + virtual void suspendedIndication(TransactionId id, ConditionCode code) = 0; + virtual void resumedIndication(TransactionId id, size_t progress) = 0; + virtual void faultIndication(TransactionId id, ConditionCode code, size_t progress) = 0; + virtual void abandonedIndication(TransactionId id, ConditionCode code, size_t progress) = 0; + virtual void eofRecvIndication(TransactionId id) = 0; private: HasFileSystemIF& vfs; diff --git a/src/fsfw/cfdp/tlv/FilestoreRequestTlv.cpp b/src/fsfw/cfdp/tlv/FilestoreRequestTlv.cpp index 9ad7c645..eb7a2cd2 100644 --- a/src/fsfw/cfdp/tlv/FilestoreRequestTlv.cpp +++ b/src/fsfw/cfdp/tlv/FilestoreRequestTlv.cpp @@ -3,10 +3,10 @@ #include "fsfw/FSFW.h" FilestoreRequestTlv::FilestoreRequestTlv(cfdp::FilestoreActionCode actionCode, - cfdp::Lv &firstFileName) + cfdp::StringLv &firstFileName) : FilestoreTlvBase(actionCode, firstFileName) {} -FilestoreRequestTlv::FilestoreRequestTlv(cfdp::Lv &firstFileName) +FilestoreRequestTlv::FilestoreRequestTlv(cfdp::StringLv &firstFileName) : FilestoreTlvBase(cfdp::FilestoreActionCode::INVALID, firstFileName) {} void FilestoreRequestTlv::setSecondFileName(cfdp::Lv *secondFileName) { diff --git a/src/fsfw/cfdp/tlv/FilestoreRequestTlv.h b/src/fsfw/cfdp/tlv/FilestoreRequestTlv.h index 5acb0ef4..94faaa07 100644 --- a/src/fsfw/cfdp/tlv/FilestoreRequestTlv.h +++ b/src/fsfw/cfdp/tlv/FilestoreRequestTlv.h @@ -9,9 +9,9 @@ class FilestoreRequestTlv : public cfdp::FilestoreTlvBase { public: - FilestoreRequestTlv(cfdp::FilestoreActionCode actionCode, cfdp::Lv &firstFileName); + FilestoreRequestTlv(cfdp::FilestoreActionCode actionCode, cfdp::StringLv &firstFileName); - FilestoreRequestTlv(cfdp::Lv &firstFileName); + explicit FilestoreRequestTlv(cfdp::StringLv &firstFileName); void setSecondFileName(cfdp::Lv *secondFileName); @@ -29,8 +29,8 @@ class FilestoreRequestTlv : public cfdp::FilestoreTlvBase { ReturnValue_t deSerialize(const uint8_t **buffer, size_t *size, Endianness streamEndianness) override; - uint8_t getLengthField() const override; - cfdp::TlvTypes getType() const override; + [[nodiscard]] uint8_t getLengthField() const override; + [[nodiscard]] cfdp::TlvTypes getType() const override; private: cfdp::Lv *secondFileName = nullptr; diff --git a/src/fsfw/cfdp/tlv/FilestoreResponseTlv.cpp b/src/fsfw/cfdp/tlv/FilestoreResponseTlv.cpp index 36945725..c4c72702 100644 --- a/src/fsfw/cfdp/tlv/FilestoreResponseTlv.cpp +++ b/src/fsfw/cfdp/tlv/FilestoreResponseTlv.cpp @@ -1,10 +1,10 @@ #include "FilestoreResponseTlv.h" FilestoreResponseTlv::FilestoreResponseTlv(cfdp::FilestoreActionCode actionCode, uint8_t statusCode, - cfdp::Lv &firstFileName, cfdp::Lv *fsMsg) + cfdp::StringLv &firstFileName, cfdp::Lv *fsMsg) : FilestoreTlvBase(actionCode, firstFileName), statusCode(statusCode), filestoreMsg(fsMsg) {} -FilestoreResponseTlv::FilestoreResponseTlv(cfdp::Lv &firstFileName, cfdp::Lv *fsMsg) +FilestoreResponseTlv::FilestoreResponseTlv(cfdp::StringLv &firstFileName, cfdp::Lv *fsMsg) : FilestoreTlvBase(firstFileName), statusCode(0), filestoreMsg(fsMsg) {} uint8_t FilestoreResponseTlv::getLengthField() const { @@ -20,12 +20,12 @@ uint8_t FilestoreResponseTlv::getLengthField() const { return 1 + firstFileName.getSerializedSize() + optFieldsLen; } -void FilestoreResponseTlv::setSecondFileName(cfdp::Lv *secondFileName) { - this->secondFileName = secondFileName; +void FilestoreResponseTlv::setSecondFileName(cfdp::StringLv *secondFileName_) { + this->secondFileName = secondFileName_; } -void FilestoreResponseTlv::setFilestoreMessage(cfdp::Lv *filestoreMsg) { - this->filestoreMsg = filestoreMsg; +void FilestoreResponseTlv::setFilestoreMessage(cfdp::Lv *filestoreMsg_) { + this->filestoreMsg = filestoreMsg_; } ReturnValue_t FilestoreResponseTlv::serialize(uint8_t **buffer, size_t *size, size_t maxSize, diff --git a/src/fsfw/cfdp/tlv/FilestoreResponseTlv.h b/src/fsfw/cfdp/tlv/FilestoreResponseTlv.h index 7b68ba57..47868693 100644 --- a/src/fsfw/cfdp/tlv/FilestoreResponseTlv.h +++ b/src/fsfw/cfdp/tlv/FilestoreResponseTlv.h @@ -4,17 +4,18 @@ #include "Lv.h" #include "TlvIF.h" #include "fsfw/cfdp/tlv/FilestoreTlvBase.h" +#include "fsfw/cfdp/tlv/StringLv.h" #include "fsfw/cfdp/tlv/Tlv.h" class FilestoreResponseTlv : public cfdp::FilestoreTlvBase { public: - FilestoreResponseTlv(cfdp::Lv& firstFileName, cfdp::Lv* fsMsg); + FilestoreResponseTlv(cfdp::StringLv& firstFileName, cfdp::Lv* fsMsg); FilestoreResponseTlv(cfdp::FilestoreActionCode actionCode, uint8_t statusCode, - cfdp::Lv& firstFileName, cfdp::Lv* fsMsg); + cfdp::StringLv& firstFileName, cfdp::Lv* fsMsg); - uint8_t getStatusCode() const; - void setSecondFileName(cfdp::Lv* secondFileName); + [[nodiscard]] uint8_t getStatusCode() const; + void setSecondFileName(cfdp::StringLv* secondFileName); void setFilestoreMessage(cfdp::Lv* filestoreMsg); ReturnValue_t serialize(uint8_t** buffer, size_t* size, size_t maxSize, @@ -31,12 +32,12 @@ class FilestoreResponseTlv : public cfdp::FilestoreTlvBase { ReturnValue_t deSerialize(const uint8_t** buffer, size_t* size, Endianness streamEndianness) override; - uint8_t getLengthField() const override; - cfdp::TlvTypes getType() const override; + [[nodiscard]] uint8_t getLengthField() const override; + [[nodiscard]] cfdp::TlvTypes getType() const override; private: uint8_t statusCode; - cfdp::Lv* secondFileName = nullptr; + cfdp::StringLv* secondFileName = nullptr; cfdp::Lv* filestoreMsg = nullptr; ReturnValue_t deSerializeFromValue(const uint8_t** buffer, size_t* size, diff --git a/src/fsfw/cfdp/tlv/FilestoreTlvBase.h b/src/fsfw/cfdp/tlv/FilestoreTlvBase.h index 04012cda..2db08946 100644 --- a/src/fsfw/cfdp/tlv/FilestoreTlvBase.h +++ b/src/fsfw/cfdp/tlv/FilestoreTlvBase.h @@ -11,6 +11,7 @@ #include #include +#include "StringLv.h" #include "fsfw/FSFW.h" namespace cfdp { @@ -65,8 +66,8 @@ static constexpr uint8_t FSR_DENY_DIR_NOT_ALLOWED = 0b0010; class FilestoreTlvBase : public TlvIF { public: - FilestoreTlvBase(cfdp::Lv& firstFileName) : firstFileName(firstFileName){}; - FilestoreTlvBase(FilestoreActionCode actionCode, cfdp::Lv& firstFileName) + explicit FilestoreTlvBase(cfdp::StringLv& firstFileName) : firstFileName(firstFileName){}; + FilestoreTlvBase(FilestoreActionCode actionCode, cfdp::StringLv& firstFileName) : actionCode(actionCode), firstFileName(firstFileName){}; ReturnValue_t commonSerialize(uint8_t** buffer, size_t* size, size_t maxSize, @@ -101,7 +102,7 @@ class FilestoreTlvBase : public TlvIF { if (*size < 3) { return SerializeIF::STREAM_TOO_SHORT; } - cfdp::TlvTypes type = static_cast(**buffer); + auto type = static_cast(**buffer); if (type != getType()) { return cfdp::INVALID_TLV_TYPE; } @@ -117,7 +118,7 @@ class FilestoreTlvBase : public TlvIF { return HasReturnvaluesIF::RETURN_OK; } - bool requiresSecondFileName() const { + [[nodiscard]] bool requiresSecondFileName() const { using namespace cfdp; if (actionCode == FilestoreActionCode::RENAME_FILE or actionCode == FilestoreActionCode::APPEND_FILE or @@ -141,9 +142,9 @@ class FilestoreTlvBase : public TlvIF { #endif } - FilestoreActionCode getActionCode() const { return actionCode; } + [[nodiscard]] FilestoreActionCode getActionCode() const { return actionCode; } - void setActionCode(FilestoreActionCode actionCode) { this->actionCode = actionCode; } + void setActionCode(FilestoreActionCode actionCode_) { this->actionCode = actionCode_; } cfdp::Lv& getFirstFileName() { return firstFileName; } @@ -160,11 +161,11 @@ class FilestoreTlvBase : public TlvIF { return result; } - size_t getSerializedSize() const override { return getLengthField() + 2; } + [[nodiscard]] size_t getSerializedSize() const override { return getLengthField() + 2; } protected: FilestoreActionCode actionCode = FilestoreActionCode::INVALID; - cfdp::Lv& firstFileName; + cfdp::StringLv& firstFileName; }; } // namespace cfdp diff --git a/src/fsfw/cfdp/tlv/StringLv.cpp b/src/fsfw/cfdp/tlv/StringLv.cpp index abbdb34a..60c278a7 100644 --- a/src/fsfw/cfdp/tlv/StringLv.cpp +++ b/src/fsfw/cfdp/tlv/StringLv.cpp @@ -5,3 +5,5 @@ cfdp::StringLv::StringLv(const std::string& fileName) cfdp::StringLv::StringLv(const char* filename, size_t len) : Lv(reinterpret_cast(filename), len) {} + +cfdp::StringLv::StringLv() : Lv() {} diff --git a/src/fsfw/cfdp/tlv/StringLv.h b/src/fsfw/cfdp/tlv/StringLv.h index 86c2d738..a6cc8e20 100644 --- a/src/fsfw/cfdp/tlv/StringLv.h +++ b/src/fsfw/cfdp/tlv/StringLv.h @@ -9,6 +9,7 @@ namespace cfdp { class StringLv : public Lv { public: + StringLv(); explicit StringLv(const std::string& fileName); explicit StringLv(const char* filename, size_t len); }; diff --git a/unittests/cfdp/handler/testDestHandler.cpp b/unittests/cfdp/handler/testDestHandler.cpp index 7d641a38..32ed606d 100644 --- a/unittests/cfdp/handler/testDestHandler.cpp +++ b/unittests/cfdp/handler/testDestHandler.cpp @@ -8,8 +8,6 @@ TEST_CASE("CFDP Dest Handler", "[cfdp]") { EntityId localId = EntityId(UnsignedByteField(2)); auto fhMock = FaultHandlerMock(); auto localEntityCfg = LocalEntityCfg(localId, IndicationCfg(), fhMock); - // auto destHandler = DestHandler(); - cfdp::testFunc(); SECTION("State") {} } \ No newline at end of file diff --git a/unittests/cfdp/pdu/testFinishedPdu.cpp b/unittests/cfdp/pdu/testFinishedPdu.cpp index d117ed58..d5d17124 100644 --- a/unittests/cfdp/pdu/testFinishedPdu.cpp +++ b/unittests/cfdp/pdu/testFinishedPdu.cpp @@ -35,7 +35,7 @@ TEST_CASE("Finished PDU", "[cfdp][pdu]") { // Add a filestore response std::string firstName = "hello.txt"; - cfdp::Lv firstNameLv(reinterpret_cast(firstName.data()), firstName.size()); + cfdp::StringLv firstNameLv(firstName); FilestoreResponseTlv response(cfdp::FilestoreActionCode::DELETE_FILE, cfdp::FSR_APPEND_FILE_1_NOT_EXISTS, firstNameLv, nullptr); FilestoreResponseTlv* responsePtr = &response; @@ -53,7 +53,7 @@ TEST_CASE("Finished PDU", "[cfdp][pdu]") { // Add two filestore responses and a fault location parameter std::string secondName = "hello2.txt"; - cfdp::Lv secondNameLv(reinterpret_cast(secondName.data()), secondName.size()); + cfdp::StringLv secondNameLv(secondName); FilestoreResponseTlv response2(cfdp::FilestoreActionCode::DENY_FILE, cfdp::FSR_SUCCESS, secondNameLv, nullptr); REQUIRE(response2.getSerializedSize() == 15); @@ -101,7 +101,7 @@ TEST_CASE("Finished PDU", "[cfdp][pdu]") { sz = 0; buffer = fnBuffer.data(); std::string firstName = "hello.txt"; - cfdp::Lv firstNameLv(reinterpret_cast(firstName.data()), firstName.size()); + cfdp::StringLv firstNameLv(firstName); FilestoreResponseTlv response(cfdp::FilestoreActionCode::DELETE_FILE, cfdp::FSR_NOT_PERFORMED, firstNameLv, nullptr); FilestoreResponseTlv* responsePtr = &response; @@ -130,7 +130,7 @@ TEST_CASE("Finished PDU", "[cfdp][pdu]") { // Add two filestore responses and a fault location parameter std::string secondName = "hello2.txt"; - cfdp::Lv secondNameLv(reinterpret_cast(secondName.data()), secondName.size()); + cfdp::StringLv secondNameLv(secondName); FilestoreResponseTlv response2(cfdp::FilestoreActionCode::DENY_FILE, cfdp::FSR_SUCCESS, secondNameLv, nullptr); REQUIRE(response2.getSerializedSize() == 15); diff --git a/unittests/cfdp/pdu/testMetadataPdu.cpp b/unittests/cfdp/pdu/testMetadataPdu.cpp index dec3b479..0dbc4a70 100644 --- a/unittests/cfdp/pdu/testMetadataPdu.cpp +++ b/unittests/cfdp/pdu/testMetadataPdu.cpp @@ -20,8 +20,7 @@ TEST_CASE("Metadata PDU", "[cfdp][pdu]") { PduConfig pduConf(sourceId, destId, TransmissionModes::ACKNOWLEDGED, seqNum); std::string firstFileName = "hello.txt"; - cfdp::Lv sourceFileName(reinterpret_cast(firstFileName.data()), - firstFileName.size()); + cfdp::StringLv sourceFileName(firstFileName); cfdp::Lv destFileName; FileSize fileSize(35); MetadataInfo info(false, ChecksumType::MODULAR, fileSize, sourceFileName, destFileName); diff --git a/unittests/cfdp/testOtherTlvs.cpp b/unittests/cfdp/testOtherTlvs.cpp index 3551fcdf..d8167e87 100644 --- a/unittests/cfdp/testOtherTlvs.cpp +++ b/unittests/cfdp/testOtherTlvs.cpp @@ -25,9 +25,9 @@ TEST_CASE("CFDP LV", "[cfdp][lv]") { SECTION("Filestore Response TLV") { std::string name = "hello.txt"; - cfdp::Lv firstName(reinterpret_cast(name.data()), name.size()); + cfdp::StringLv firstName(name); std::string name2 = "hello2.txt"; - cfdp::Lv secondName(reinterpret_cast(name2.data()), name2.size()); + cfdp::StringLv secondName(name2); std::string msg = "12345"; cfdp::Lv fsMsg(reinterpret_cast(msg.data()), msg.size()); FilestoreResponseTlv response(cfdp::FilestoreActionCode::APPEND_FILE, cfdp::FSR_SUCCESS, @@ -42,8 +42,8 @@ TEST_CASE("CFDP LV", "[cfdp][lv]") { SerializeIF::Endianness::NETWORK); REQUIRE(result == HasReturnvaluesIF::RETURN_OK); REQUIRE(rawResponse.getType() == cfdp::TlvTypes::FILESTORE_RESPONSE); - cfdp::Lv emptyMsg; - cfdp::Lv emptySecondName; + cfdp::StringLv emptyMsg; + cfdp::StringLv emptySecondName; FilestoreResponseTlv emptyTlv(firstName, &emptyMsg); emptyTlv.setSecondFileName(&emptySecondName); result = emptyTlv.deSerialize(rawResponse, SerializeIF::Endianness::NETWORK); @@ -59,9 +59,9 @@ TEST_CASE("CFDP LV", "[cfdp][lv]") { SECTION("Filestore Request TLV") { std::string name = "hello.txt"; - cfdp::Lv firstName(reinterpret_cast(name.data()), name.size()); + cfdp::StringLv firstName(name); std::string name2 = "hello2.txt"; - cfdp::Lv secondName(reinterpret_cast(name2.data()), name2.size()); + cfdp::StringLv secondName(name2); FilestoreRequestTlv request(cfdp::FilestoreActionCode::APPEND_FILE, firstName); // second name not set yet diff --git a/unittests/mocks/cfdp/UserMock.cpp b/unittests/mocks/cfdp/UserMock.cpp index a38ceefc..bcef4e68 100644 --- a/unittests/mocks/cfdp/UserMock.cpp +++ b/unittests/mocks/cfdp/UserMock.cpp @@ -8,8 +8,10 @@ void cfdp::UserMock::abandonedIndication(cfdp::TransactionId id, cfdp::Condition uint64_t progress) {} void cfdp::UserMock::eofRecvIndication(cfdp::TransactionId id) {} void cfdp::UserMock::transactionFinishedIndication(TransactionFinishedParams finishedParams) {} -void cfdp::UserMock::metadataRecvdIndication(MetadataRecvParams params) {} +void cfdp::UserMock::metadataRecvdIndication(MetadataRecvdParams params) {} void cfdp::UserMock::fileSegmentRecvdIndication(FileSegmentRecvdParams params) {} -void cfdp::UserMock::reportIndication() {} -void cfdp::UserMock::suspendedIndication() {} -void cfdp::UserMock::resumedIndication() {} +void cfdp::UserMock::reportIndication(TransactionId id, StatusReportIF& report) {} +void cfdp::UserMock::suspendedIndication(TransactionId id, ConditionCode code) {} +void cfdp::UserMock::resumedIndication(TransactionId id, size_t progress) {} +void cfdp::UserMock::faultIndication(cfdp::TransactionId id, cfdp::ConditionCode code, + size_t progress) {} diff --git a/unittests/mocks/cfdp/UserMock.h b/unittests/mocks/cfdp/UserMock.h index bcdff3c9..7106a844 100644 --- a/unittests/mocks/cfdp/UserMock.h +++ b/unittests/mocks/cfdp/UserMock.h @@ -10,14 +10,15 @@ class UserMock : public UserBase { public: void transactionIndication(TransactionId id) override; void eofSentIndication(TransactionId id) override; - void abandonedIndication(TransactionId id, ConditionCode code, uint64_t progress) override; + void abandonedIndication(TransactionId id, ConditionCode code, size_t progress) override; void eofRecvIndication(TransactionId id) override; void transactionFinishedIndication(TransactionFinishedParams params) override; - void metadataRecvdIndication(MetadataRecvParams params) override; + void metadataRecvdIndication(MetadataRecvdParams params) override; void fileSegmentRecvdIndication(FileSegmentRecvdParams params) override; - void reportIndication() override; - void suspendedIndication() override; - void resumedIndication() override; + void reportIndication(TransactionId id, StatusReportIF& report) override; + void suspendedIndication(TransactionId id, ConditionCode code) override; + void resumedIndication(TransactionId id, size_t progress) override; + void faultIndication(TransactionId id, ConditionCode code, size_t progress) override; }; } // namespace cfdp From 28c8248f26bdee6f81f8bfed2f6f31af678b1c89 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Wed, 10 Aug 2022 11:09:07 +0200 Subject: [PATCH 051/169] add FS mock and improve HasFilesystemIF --- src/fsfw/cfdp/handler/UserBase.cpp | 3 - src/fsfw/filesystem/HasFileSystemIF.h | 88 +++++++++++++++------- unittests/cfdp/handler/testDestHandler.cpp | 3 +- unittests/mocks/CMakeLists.txt | 3 +- unittests/mocks/FilesystemMock.cpp | 22 ++++++ unittests/mocks/FilesystemMock.h | 19 +++++ 6 files changed, 106 insertions(+), 32 deletions(-) create mode 100644 unittests/mocks/FilesystemMock.cpp create mode 100644 unittests/mocks/FilesystemMock.h diff --git a/src/fsfw/cfdp/handler/UserBase.cpp b/src/fsfw/cfdp/handler/UserBase.cpp index 9e757896..212396fb 100644 --- a/src/fsfw/cfdp/handler/UserBase.cpp +++ b/src/fsfw/cfdp/handler/UserBase.cpp @@ -1,6 +1,3 @@ #include "UserBase.h" -#include -#include - cfdp::UserBase::UserBase(HasFileSystemIF& vfs) : vfs(vfs) {} diff --git a/src/fsfw/filesystem/HasFileSystemIF.h b/src/fsfw/filesystem/HasFileSystemIF.h index 88a7db83..4fc8a941 100644 --- a/src/fsfw/filesystem/HasFileSystemIF.h +++ b/src/fsfw/filesystem/HasFileSystemIF.h @@ -4,10 +4,25 @@ #include #include "FileSystemArgsIF.h" +#include "fsfw/ipc/MessageQueueIF.h" #include "fsfw/ipc/messageQueueDefinitions.h" #include "fsfw/returnvalues/FwClassIds.h" #include "fsfw/returnvalues/HasReturnvaluesIF.h" +struct FilesystemParams { + explicit FilesystemParams(const char* path) : path(path) {} + + const char* path; + FileSystemArgsIF* args = nullptr; +}; + +struct FileOpParams : public FilesystemParams { + FileOpParams(const char* path, size_t size) : FilesystemParams(path), size(size) {} + + size_t size; + size_t offset = 0; +}; + /** * @brief Generic interface for objects which expose a file system to enable * message based file handling. @@ -37,30 +52,47 @@ class HasFileSystemIF { //! [EXPORT] : P1: Sequence number missing static constexpr ReturnValue_t SEQUENCE_PACKET_MISSING_READ = MAKE_RETURN_CODE(16); - virtual ~HasFileSystemIF() {} + virtual ~HasFileSystemIF() = default; /** * Function to get the MessageQueueId_t of the implementing object * @return MessageQueueId_t of the object */ - virtual MessageQueueId_t getCommandQueue() const = 0; + [[nodiscard]] virtual MessageQueueId_t getCommandQueue() const { + return MessageQueueIF::NO_QUEUE; + } /** * @brief Generic function to append to file. - * @param dirname Directory of the file - * @param filename The filename of the file + * @param fileOpInfo General information: File name, size to write, offset, additional arguments * @param data The data to write to the file - * @param size The size of the data to write - * @param packetNumber Current packet number. Can be used to verify that - * there are no missing packets. - * @param args Any other arguments which an implementation might require. - * @param bytesWritten Actual bytes written to file - * For large files the write procedure must be split in multiple calls - * to writeToFile */ - virtual ReturnValue_t appendToFile(const char* repositoryPath, const char* filename, - const uint8_t* data, size_t size, uint16_t packetNumber, - FileSystemArgsIF* args = nullptr) = 0; + virtual ReturnValue_t writeToFile(FileOpParams params, const uint8_t* data) = 0; + + /** + * @brief Generic function to read from a file. This variant takes a pointer to a buffer and + * performs pointer arithmetic by incrementing the pointer by the read size + * @param fileOpInfo General information: File name, size to write, offset, additional arguments + * @param buffer [in/out] Data will be read into the provided buffer, and the pointer will be + * incremented by the read length + * @param readSize [out] Will be incremented by the read length + * @param maxSize Maximum size of the provided buffer + * @param args + * @return + */ + virtual ReturnValue_t readFromFile(FileOpParams fileOpInfo, uint8_t** buffer, size_t& readSize, + size_t maxSize) = 0; + /** + * Variant of the @readFromFile which does not perform pointer arithmetic. + * @param fileOpInfo General information: File name, size to write, offset, additional arguments + * @param buf + * @param maxSize + * @return + */ + virtual ReturnValue_t readFromFile(FileOpParams fileOpInfo, uint8_t* buf, size_t maxSize) { + size_t dummy = 0; + return readFromFile(fileOpInfo, &buf, dummy, maxSize); + } /** * @brief Generic function to create a new file. @@ -71,9 +103,10 @@ class HasFileSystemIF { * @param args Any other arguments which an implementation might require * @return */ - virtual ReturnValue_t createFile(const char* repositoryPath, const char* filename, - const uint8_t* data = nullptr, size_t size = 0, - FileSystemArgsIF* args = nullptr) = 0; + virtual ReturnValue_t createFile(FilesystemParams params) { + return createFile(params, nullptr, 0); + } + virtual ReturnValue_t createFile(FilesystemParams params, const uint8_t* data, size_t size) = 0; /** * @brief Generic function to delete a file. @@ -82,8 +115,8 @@ class HasFileSystemIF { * @param args Any other arguments which an implementation might require * @return */ - virtual ReturnValue_t removeFile(const char* repositoryPath, const char* filename, - FileSystemArgsIF* args = nullptr) = 0; + virtual ReturnValue_t removeFile(const char* path, FileSystemArgsIF* args) = 0; + virtual ReturnValue_t removeFile(const char* path) { return removeFile(path, nullptr); } /** * @brief Generic function to create a directory @@ -93,21 +126,22 @@ class HasFileSystemIF { * @param args Any other arguments which an implementation might require * @return */ - virtual ReturnValue_t createDirectory(const char* repositoryPath, const char* dirname, - bool createParentDirs, - FileSystemArgsIF* args = nullptr) = 0; + virtual ReturnValue_t createDirectory(FilesystemParams params, bool createParentDirs) = 0; /** * @brief Generic function to remove a directory * @param repositoryPath * @param args Any other arguments which an implementation might require */ - virtual ReturnValue_t removeDirectory(const char* repositoryPath, const char* dirname, - bool deleteRecurively = false, - FileSystemArgsIF* args = nullptr) = 0; + virtual ReturnValue_t removeDirectory(FilesystemParams params, bool deleteRecurively) = 0; + virtual ReturnValue_t removeDirectory(FilesystemParams params) { + return removeDirectory(params, false); + } - virtual ReturnValue_t renameFile(const char* repositoryPath, const char* oldFilename, - const char* newFilename, FileSystemArgsIF* args = nullptr) = 0; + virtual ReturnValue_t renameFile(const char* oldPath, char* newPath) { + return renameFile(oldPath, newPath, nullptr); + } + virtual ReturnValue_t renameFile(const char* oldPath, char* newPath, FileSystemArgsIF* args) = 0; }; #endif /* FSFW_MEMORY_HASFILESYSTEMIF_H_ */ diff --git a/unittests/cfdp/handler/testDestHandler.cpp b/unittests/cfdp/handler/testDestHandler.cpp index 32ed606d..fc8ebc41 100644 --- a/unittests/cfdp/handler/testDestHandler.cpp +++ b/unittests/cfdp/handler/testDestHandler.cpp @@ -2,12 +2,13 @@ #include "fsfw/cfdp.h" #include "mocks/cfdp/FaultHandlerMock.h" - +#include "mocks/cfdp/UserMock.h" TEST_CASE("CFDP Dest Handler", "[cfdp]") { using namespace cfdp; EntityId localId = EntityId(UnsignedByteField(2)); auto fhMock = FaultHandlerMock(); auto localEntityCfg = LocalEntityCfg(localId, IndicationCfg(), fhMock); + // auto userMock = UserMock(); SECTION("State") {} } \ No newline at end of file diff --git a/unittests/mocks/CMakeLists.txt b/unittests/mocks/CMakeLists.txt index e15f3d71..c40a727a 100644 --- a/unittests/mocks/CMakeLists.txt +++ b/unittests/mocks/CMakeLists.txt @@ -14,6 +14,7 @@ target_sources( PusDistributorMock.cpp CcsdsCheckerMock.cpp AcceptsTcMock.cpp - StorageManagerMock.cpp) + StorageManagerMock.cpp + FilesystemMock.cpp) add_subdirectory(cfdp) diff --git a/unittests/mocks/FilesystemMock.cpp b/unittests/mocks/FilesystemMock.cpp new file mode 100644 index 00000000..fe870155 --- /dev/null +++ b/unittests/mocks/FilesystemMock.cpp @@ -0,0 +1,22 @@ +#include "FilesystemMock.h" + +ReturnValue_t FilesystemMock::writeToFile(FileOpParams params, const uint8_t *data) { return 0; } +ReturnValue_t FilesystemMock::readFromFile(FileOpParams fileOpInfo, uint8_t **buffer, + size_t &readSize, size_t maxSize) { + return 0; +} +ReturnValue_t FilesystemMock::createFile(FilesystemParams params, const uint8_t *data, + size_t size) { + return 0; +} +ReturnValue_t FilesystemMock::removeFile(const char *path, FileSystemArgsIF *args) { return 0; } +ReturnValue_t FilesystemMock::createDirectory(FilesystemParams params, bool createParentDirs) { + return 0; +} +ReturnValue_t FilesystemMock::removeDirectory(FilesystemParams params, bool deleteRecurively) { + return 0; +} +ReturnValue_t FilesystemMock::renameFile(const char *oldPath, char *newPath, + FileSystemArgsIF *args) { + return 0; +} diff --git a/unittests/mocks/FilesystemMock.h b/unittests/mocks/FilesystemMock.h new file mode 100644 index 00000000..fa173bf5 --- /dev/null +++ b/unittests/mocks/FilesystemMock.h @@ -0,0 +1,19 @@ +#ifndef FSFW_MOCKS_FILESYSTEMMOCK_H +#define FSFW_MOCKS_FILESYSTEMMOCK_H + +#include "fsfw/filesystem.h" + +class FilesystemMock : public HasFileSystemIF { + public: + MessageQueueId_t getCommandQueue() const override; + ReturnValue_t writeToFile(FileOpParams params, const uint8_t *data) override; + ReturnValue_t readFromFile(FileOpParams fileOpInfo, uint8_t **buffer, size_t &readSize, + size_t maxSize) override; + ReturnValue_t createFile(FilesystemParams params, const uint8_t *data, size_t size) override; + ReturnValue_t removeFile(const char *path, FileSystemArgsIF *args) override; + ReturnValue_t createDirectory(FilesystemParams params, bool createParentDirs) override; + ReturnValue_t removeDirectory(FilesystemParams params, bool deleteRecurively) override; + ReturnValue_t renameFile(const char *oldPath, char *newPath, FileSystemArgsIF *args) override; +}; + +#endif // FSFW_MOCKS_FILESYSTEMMOCK_H From a2e0646ed4d0e1b9932acbae3d973de16a160aa2 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Wed, 10 Aug 2022 13:05:07 +0200 Subject: [PATCH 052/169] fix duplicate naming error --- unittests/cfdp/testLvs.cpp | 2 +- unittests/cfdp/testOtherTlvs.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/unittests/cfdp/testLvs.cpp b/unittests/cfdp/testLvs.cpp index c3f19d9c..27a9dad7 100644 --- a/unittests/cfdp/testLvs.cpp +++ b/unittests/cfdp/testLvs.cpp @@ -3,7 +3,7 @@ #include "fsfw/cfdp.h" -TEST_CASE("CFDP TLV", "[cfdp][lv]") { +TEST_CASE("CFDP LV", "[cfdp][lv]") { using namespace cfdp; ReturnValue_t result; std::array rawBuf{}; diff --git a/unittests/cfdp/testOtherTlvs.cpp b/unittests/cfdp/testOtherTlvs.cpp index d8167e87..6393c230 100644 --- a/unittests/cfdp/testOtherTlvs.cpp +++ b/unittests/cfdp/testOtherTlvs.cpp @@ -14,7 +14,7 @@ #include "fsfw/cfdp/tlv/Tlv.h" #include "fsfw/globalfunctions/arrayprinter.h" -TEST_CASE("CFDP LV", "[cfdp][lv]") { +TEST_CASE("CFDP Other TLVs", "[cfdp][tlv]") { using namespace cfdp; ReturnValue_t result; std::array rawBuf{}; From 46a4203d00e74986939d57694a6fff6c3e671339 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Wed, 10 Aug 2022 13:36:41 +0200 Subject: [PATCH 053/169] testLvs fix --- unittests/cfdp/testLvs.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/unittests/cfdp/testLvs.cpp b/unittests/cfdp/testLvs.cpp index 27a9dad7..2adc84b8 100644 --- a/unittests/cfdp/testLvs.cpp +++ b/unittests/cfdp/testLvs.cpp @@ -5,7 +5,7 @@ TEST_CASE("CFDP LV", "[cfdp][lv]") { using namespace cfdp; - ReturnValue_t result; + ReturnValue_t result = result::OK; std::array rawBuf{}; uint8_t* serPtr = rawBuf.data(); const uint8_t* deserPtr = rawBuf.data(); @@ -17,7 +17,6 @@ TEST_CASE("CFDP LV", "[cfdp][lv]") { serPtr = lvRawBuf.data(); REQUIRE(sourceId.serialize(&serPtr, &deserSize, lvRawBuf.size(), SerializeIF::Endianness::NETWORK) == result::OK); - REQUIRE(result == HasReturnvaluesIF::RETURN_OK); REQUIRE(deserSize == 2); auto lv = cfdp::Lv(lvRawBuf.data(), 2); From 3df116156048d68ee8fce50f4fa43b281804e11d Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Wed, 10 Aug 2022 15:03:53 +0200 Subject: [PATCH 054/169] this should do the job --- unittests/cfdp/handler/testDestHandler.cpp | 1 + unittests/mocks/FilesystemMock.cpp | 27 +++++++++++++++++++++- unittests/mocks/FilesystemMock.h | 24 ++++++++++++++++++- 3 files changed, 50 insertions(+), 2 deletions(-) diff --git a/unittests/cfdp/handler/testDestHandler.cpp b/unittests/cfdp/handler/testDestHandler.cpp index fc8ebc41..0d9fe9f5 100644 --- a/unittests/cfdp/handler/testDestHandler.cpp +++ b/unittests/cfdp/handler/testDestHandler.cpp @@ -3,6 +3,7 @@ #include "fsfw/cfdp.h" #include "mocks/cfdp/FaultHandlerMock.h" #include "mocks/cfdp/UserMock.h" + TEST_CASE("CFDP Dest Handler", "[cfdp]") { using namespace cfdp; EntityId localId = EntityId(UnsignedByteField(2)); diff --git a/unittests/mocks/FilesystemMock.cpp b/unittests/mocks/FilesystemMock.cpp index fe870155..5cf833c0 100644 --- a/unittests/mocks/FilesystemMock.cpp +++ b/unittests/mocks/FilesystemMock.cpp @@ -1,6 +1,31 @@ #include "FilesystemMock.h" -ReturnValue_t FilesystemMock::writeToFile(FileOpParams params, const uint8_t *data) { return 0; } +ReturnValue_t FilesystemMock::writeToFile(FileOpParams params, const uint8_t *data) { + std::string filename(params.path); + auto iter = fileMap.find(filename); + if (iter == fileMap.end()) { + FileSegmentQueue queue; + queue.push(FileWriteInfo(filename, params.offset, data, params.size)); + FileInfo info; + info.fileSegQueue = queue; + info.fileRaw.insert(info.fileRaw.end(), data, data + params.size); + fileMap.emplace(filename, info); + } else { + FileInfo& info = iter->second; + info.fileSegQueue.push(FileWriteInfo(filename, params.offset, data, params.size)); + // Easiest case: append data to the end + if(params.offset == info.fileRaw.size()) { + info.fileRaw.insert(info.fileRaw.end(), data, data + params.size); + } else { + size_t totalNewLen = params.offset + params.size; + if(totalNewLen > info.fileRaw.size()) { + info.fileRaw.resize(params.offset + params.size); + } + std::copy(data, data + params.size, info.fileRaw.begin() + static_cast(params.offset)); + } + } + return HasReturnvaluesIF::RETURN_OK; +} ReturnValue_t FilesystemMock::readFromFile(FileOpParams fileOpInfo, uint8_t **buffer, size_t &readSize, size_t maxSize) { return 0; diff --git a/unittests/mocks/FilesystemMock.h b/unittests/mocks/FilesystemMock.h index fa173bf5..fbd157b0 100644 --- a/unittests/mocks/FilesystemMock.h +++ b/unittests/mocks/FilesystemMock.h @@ -1,11 +1,33 @@ #ifndef FSFW_MOCKS_FILESYSTEMMOCK_H #define FSFW_MOCKS_FILESYSTEMMOCK_H +#include +#include +#include +#include + #include "fsfw/filesystem.h" class FilesystemMock : public HasFileSystemIF { public: - MessageQueueId_t getCommandQueue() const override; + struct FileWriteInfo { + FileWriteInfo(std::string filename, size_t offset, const uint8_t* data, size_t len) + : filename(std::move(filename)), offset(offset) { + this->data.insert(this->data.end(), data, data + len); + } + std::string filename; + size_t offset; + std::vector data; + }; + using FileSegmentQueue = std::queue; + + struct FileInfo { + FileSegmentQueue fileSegQueue; + std::vector fileRaw; + }; + + std::map fileMap; + ReturnValue_t writeToFile(FileOpParams params, const uint8_t *data) override; ReturnValue_t readFromFile(FileOpParams fileOpInfo, uint8_t **buffer, size_t &readSize, size_t maxSize) override; From aca8b53a59f80215a8bbba4f140aa2dec3aeca3d Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Wed, 10 Aug 2022 17:03:23 +0200 Subject: [PATCH 055/169] start host FS impl --- src/fsfw_hal/CMakeLists.txt | 1 + src/fsfw_hal/host/CMakeLists.txt | 2 +- src/fsfw_hal/host/HostFilesystem.cpp | 99 +++++++++++++++++++++++ src/fsfw_hal/host/HostFilesystem.h | 24 ++++++ unittests/hal/CMakeLists.txt | 3 +- unittests/hal/testCommandExecutor.cpp | 2 +- unittests/hal/testHostFilesystem.cpp | 5 ++ unittests/mocks/FilesystemMock.cpp | 109 ++++++++++++++++++++------ unittests/mocks/FilesystemMock.h | 38 ++++++++- 9 files changed, 252 insertions(+), 31 deletions(-) create mode 100644 src/fsfw_hal/host/HostFilesystem.cpp create mode 100644 src/fsfw_hal/host/HostFilesystem.h create mode 100644 unittests/hal/testHostFilesystem.cpp diff --git a/src/fsfw_hal/CMakeLists.txt b/src/fsfw_hal/CMakeLists.txt index 057ab3a6..24d712aa 100644 --- a/src/fsfw_hal/CMakeLists.txt +++ b/src/fsfw_hal/CMakeLists.txt @@ -1,5 +1,6 @@ add_subdirectory(devicehandlers) add_subdirectory(common) +add_subdirectory(host) if(UNIX) add_subdirectory(linux) diff --git a/src/fsfw_hal/host/CMakeLists.txt b/src/fsfw_hal/host/CMakeLists.txt index 8b137891..95b79675 100644 --- a/src/fsfw_hal/host/CMakeLists.txt +++ b/src/fsfw_hal/host/CMakeLists.txt @@ -1 +1 @@ - +target_sources(${LIB_FSFW_NAME} PUBLIC HostFilesystem.cpp) diff --git a/src/fsfw_hal/host/HostFilesystem.cpp b/src/fsfw_hal/host/HostFilesystem.cpp new file mode 100644 index 00000000..879b9377 --- /dev/null +++ b/src/fsfw_hal/host/HostFilesystem.cpp @@ -0,0 +1,99 @@ +#include "HostFilesystem.h" + +#include +#include + +#include "fsfw/serialize.h" + +using namespace std::filesystem; +using namespace std; + +HostFilesystem::HostFilesystem() = default; + +ReturnValue_t HostFilesystem::writeToFile(FileOpParams params, const uint8_t *data) { + if (params.path == nullptr) { + return HasReturnvaluesIF::RETURN_FAILED; + } + path path(params.path); + if (not exists(path)) { + return HasFileSystemIF::FILE_DOES_NOT_EXIST; + } + ofstream file(path, ios::binary | ios::out); + if (file.fail()) { + return HasFileSystemIF::GENERIC_FILE_ERROR; + } + file.seekp(static_cast(params.offset)); + file.write(reinterpret_cast(data), static_cast(params.size)); + return HasReturnvaluesIF::RETURN_OK; +} + +ReturnValue_t HostFilesystem::readFromFile(FileOpParams params, uint8_t **buffer, size_t &readSize, + size_t maxSize) { + if (params.path == nullptr) { + return HasReturnvaluesIF::RETURN_FAILED; + } + path path(params.path); + if (not exists(path)) { + return HasFileSystemIF::FILE_DOES_NOT_EXIST; + } + ifstream file(path); + if (file.fail()) { + return HasFileSystemIF::GENERIC_FILE_ERROR; + } + auto readLen = static_cast(params.offset); + file.seekg(readLen); + if (readSize + params.size > maxSize) { + return SerializeIF::BUFFER_TOO_SHORT; + } + file.read(reinterpret_cast(*buffer), readLen); + readSize += readLen; + *buffer += readLen; + return HasReturnvaluesIF::RETURN_OK; +} + +ReturnValue_t HostFilesystem::createFile(FilesystemParams params, const uint8_t *data, + size_t size) { + if (params.path == nullptr) { + return HasReturnvaluesIF::RETURN_FAILED; + } + path path(params.path); + if (exists(path)) { + return HasFileSystemIF::FILE_ALREADY_EXISTS; + } + ofstream file(path); + if (file.fail()) { + return HasFileSystemIF::GENERIC_FILE_ERROR; + } + return HasReturnvaluesIF::RETURN_OK; +} + +ReturnValue_t HostFilesystem::removeFile(const char *path_, FileSystemArgsIF *args) { + if (path_ == nullptr) { + return HasReturnvaluesIF::RETURN_FAILED; + } + path path(path_); + if (not exists(path)) { + return HasFileSystemIF::FILE_DOES_NOT_EXIST; + } + if (remove(path, errorCode)) { + return HasReturnvaluesIF::RETURN_OK; + } + return HasFileSystemIF::GENERIC_FILE_ERROR; +} +ReturnValue_t HostFilesystem::createDirectory(FilesystemParams params, bool createParentDirs) { + if (params.path == nullptr) { + return HasReturnvaluesIF::RETURN_FAILED; + } + path dirPath(params.path); + if (createParentDirs) { + create_directories(dirPath, errorCode); + } + return 0; +} +ReturnValue_t HostFilesystem::removeDirectory(FilesystemParams params, bool deleteRecurively) { + return 0; +} +ReturnValue_t HostFilesystem::renameFile(const char *oldPath, char *newPath, + FileSystemArgsIF *args) { + return 0; +} diff --git a/src/fsfw_hal/host/HostFilesystem.h b/src/fsfw_hal/host/HostFilesystem.h new file mode 100644 index 00000000..2dd8f2f5 --- /dev/null +++ b/src/fsfw_hal/host/HostFilesystem.h @@ -0,0 +1,24 @@ +#ifndef FSFW_HAL_HOSTFILESYSTEM_H +#define FSFW_HAL_HOSTFILESYSTEM_H + +#include + +#include "fsfw/filesystem/HasFileSystemIF.h" + +class HostFilesystem : public HasFileSystemIF { + public: + HostFilesystem(); + ReturnValue_t writeToFile(FileOpParams params, const uint8_t *data) override; + ReturnValue_t readFromFile(FileOpParams fileOpInfo, uint8_t **buffer, size_t &readSize, + size_t maxSize) override; + ReturnValue_t createFile(FilesystemParams params, const uint8_t *data, size_t size) override; + ReturnValue_t removeFile(const char *path, FileSystemArgsIF *args) override; + ReturnValue_t createDirectory(FilesystemParams params, bool createParentDirs) override; + ReturnValue_t removeDirectory(FilesystemParams params, bool deleteRecurively) override; + ReturnValue_t renameFile(const char *oldPath, char *newPath, FileSystemArgsIF *args) override; + + std::error_code errorCode; + + private: +}; +#endif // FSFW_HAL_HOSTFILESYSTEM_H diff --git a/unittests/hal/CMakeLists.txt b/unittests/hal/CMakeLists.txt index 152bb39f..5e2887b2 100644 --- a/unittests/hal/CMakeLists.txt +++ b/unittests/hal/CMakeLists.txt @@ -1 +1,2 @@ -target_sources(${FSFW_TEST_TGT} PRIVATE testCommandExecutor.cpp) +target_sources(${FSFW_TEST_TGT} PRIVATE testCommandExecutor.cpp + testHostFilesystem.cpp) diff --git a/unittests/hal/testCommandExecutor.cpp b/unittests/hal/testCommandExecutor.cpp index d34f67aa..6c2bb1fe 100644 --- a/unittests/hal/testCommandExecutor.cpp +++ b/unittests/hal/testCommandExecutor.cpp @@ -15,7 +15,7 @@ static const char TEST_FILE_NAME[] = "/tmp/fsfw-unittest-test.txt"; -TEST_CASE("Command Executor", "[cmd-exec]") { +TEST_CASE("Command Executor", "[hal][linux]") { // Check blocking mode first CommandExecutor cmdExecutor(1024); std::string cmd = "echo \"test\" >> " + std::string(TEST_FILE_NAME); diff --git a/unittests/hal/testHostFilesystem.cpp b/unittests/hal/testHostFilesystem.cpp new file mode 100644 index 00000000..19af1c6b --- /dev/null +++ b/unittests/hal/testHostFilesystem.cpp @@ -0,0 +1,5 @@ +#include + +#include "fsfw_hal/host/HostFilesystem.h" + +TEST_CASE("Host Filesystem", "[hal][host]") { auto hostFs = HostFilesystem(); } \ No newline at end of file diff --git a/unittests/mocks/FilesystemMock.cpp b/unittests/mocks/FilesystemMock.cpp index 5cf833c0..e4efd086 100644 --- a/unittests/mocks/FilesystemMock.cpp +++ b/unittests/mocks/FilesystemMock.cpp @@ -1,6 +1,76 @@ #include "FilesystemMock.h" +#include "fsfw/serialize/SerializeIF.h" + ReturnValue_t FilesystemMock::writeToFile(FileOpParams params, const uint8_t *data) { + createOrAddToFile(params, data); + return HasReturnvaluesIF::RETURN_OK; +} + +ReturnValue_t FilesystemMock::readFromFile(FileOpParams params, uint8_t **buffer, size_t &readSize, + size_t maxSize) { + std::string filename(params.path); + auto iter = fileMap.find(filename); + if (iter == fileMap.end()) { + return HasFileSystemIF::FILE_DOES_NOT_EXIST; + } else { + FileInfo &info = iter->second; + size_t readLen = params.size; + if (params.offset + params.size > info.fileRaw.size()) { + if (params.offset > info.fileRaw.size()) { + return HasReturnvaluesIF::RETURN_OK; + } + readLen = info.fileRaw.size() - params.offset; + } + if (readSize + readLen > maxSize) { + return SerializeIF::STREAM_TOO_SHORT; + } + std::copy(info.fileRaw.data() + params.offset, info.fileRaw.data() + readLen, *buffer); + *buffer += readLen; + readSize += readLen; + } + return HasReturnvaluesIF::RETURN_OK; +} + +ReturnValue_t FilesystemMock::createFile(FilesystemParams params, const uint8_t *data, + size_t size) { + FileOpParams params2(params.path, size); + createOrAddToFile(params2, data); + return HasReturnvaluesIF::RETURN_OK; +} + +ReturnValue_t FilesystemMock::removeFile(const char *path, FileSystemArgsIF *args) { + std::string filename(path); + auto iter = fileMap.find(filename); + if (iter == fileMap.end()) { + return HasFileSystemIF::FILE_DOES_NOT_EXIST; + } else { + fileMap.erase(iter); + return HasReturnvaluesIF::RETURN_OK; + } +} + +ReturnValue_t FilesystemMock::createDirectory(FilesystemParams params, bool createParentDirs) { + std::string dirPath = params.path; + dirMap[dirPath].createCallCount++; + dirMap[dirPath].wihParentDir.push(createParentDirs); + return HasReturnvaluesIF::RETURN_OK; +} + +ReturnValue_t FilesystemMock::removeDirectory(FilesystemParams params, bool deleteRecurively) { + std::string dirPath = params.path; + dirMap[dirPath].delCallCount++; + dirMap[dirPath].recursiveDeletion.push(deleteRecurively); + return HasReturnvaluesIF::RETURN_OK; +} + +ReturnValue_t FilesystemMock::renameFile(const char *oldPath, char *newPath, + FileSystemArgsIF *args) { + renameQueue.push(RenameInfo(oldPath, newPath)); + return HasReturnvaluesIF::RETURN_OK; +} + +void FilesystemMock::createOrAddToFile(FileOpParams params, const uint8_t *data) { std::string filename(params.path); auto iter = fileMap.find(filename); if (iter == fileMap.end()) { @@ -8,40 +78,31 @@ ReturnValue_t FilesystemMock::writeToFile(FileOpParams params, const uint8_t *da queue.push(FileWriteInfo(filename, params.offset, data, params.size)); FileInfo info; info.fileSegQueue = queue; - info.fileRaw.insert(info.fileRaw.end(), data, data + params.size); + if (data != nullptr) { + info.fileRaw.insert(info.fileRaw.end(), data, data + params.size); + } fileMap.emplace(filename, info); } else { - FileInfo& info = iter->second; + FileInfo &info = iter->second; info.fileSegQueue.push(FileWriteInfo(filename, params.offset, data, params.size)); + if (data == nullptr) { + return; + } // Easiest case: append data to the end - if(params.offset == info.fileRaw.size()) { + if (params.offset == info.fileRaw.size()) { info.fileRaw.insert(info.fileRaw.end(), data, data + params.size); } else { size_t totalNewLen = params.offset + params.size; - if(totalNewLen > info.fileRaw.size()) { + if (totalNewLen > info.fileRaw.size()) { info.fileRaw.resize(params.offset + params.size); } - std::copy(data, data + params.size, info.fileRaw.begin() + static_cast(params.offset)); + std::copy(data, data + params.size, + info.fileRaw.begin() + static_cast(params.offset)); } } - return HasReturnvaluesIF::RETURN_OK; } -ReturnValue_t FilesystemMock::readFromFile(FileOpParams fileOpInfo, uint8_t **buffer, - size_t &readSize, size_t maxSize) { - return 0; -} -ReturnValue_t FilesystemMock::createFile(FilesystemParams params, const uint8_t *data, - size_t size) { - return 0; -} -ReturnValue_t FilesystemMock::removeFile(const char *path, FileSystemArgsIF *args) { return 0; } -ReturnValue_t FilesystemMock::createDirectory(FilesystemParams params, bool createParentDirs) { - return 0; -} -ReturnValue_t FilesystemMock::removeDirectory(FilesystemParams params, bool deleteRecurively) { - return 0; -} -ReturnValue_t FilesystemMock::renameFile(const char *oldPath, char *newPath, - FileSystemArgsIF *args) { - return 0; + +void FilesystemMock::reset() { + fileMap.clear(); + dirMap.clear(); } diff --git a/unittests/mocks/FilesystemMock.h b/unittests/mocks/FilesystemMock.h index fbd157b0..b02928c7 100644 --- a/unittests/mocks/FilesystemMock.h +++ b/unittests/mocks/FilesystemMock.h @@ -1,18 +1,26 @@ #ifndef FSFW_MOCKS_FILESYSTEMMOCK_H #define FSFW_MOCKS_FILESYSTEMMOCK_H +#include #include #include -#include #include #include "fsfw/filesystem.h" +/** + * This mock models a filesystem in the RAM. It can be used to verify correct behaviour of + * a component using a filesystem without relying on an actual OS filesystem implementation. + * + * Please note that this object does not actually check paths for validity. The file API was + * built in a way to allow reading a file back after it was written while also remembering + * the specific file segments which were inserted in write calls. + */ class FilesystemMock : public HasFileSystemIF { public: struct FileWriteInfo { - FileWriteInfo(std::string filename, size_t offset, const uint8_t* data, size_t len) - : filename(std::move(filename)), offset(offset) { + FileWriteInfo(std::string filename, size_t offset, const uint8_t *data, size_t len) + : filename(std::move(filename)), offset(offset) { this->data.insert(this->data.end(), data, data + len); } std::string filename; @@ -28,14 +36,36 @@ class FilesystemMock : public HasFileSystemIF { std::map fileMap; + struct DirInfo { + size_t createCallCount = 0; + size_t delCallCount = 0; + std::queue wihParentDir; + std::queue recursiveDeletion; + }; + std::map dirMap; + + struct RenameInfo { + RenameInfo(std::string oldName, std::string newName) + : oldName(std::move(oldName)), newName(std::move(newName)) {} + + std::string oldName; + std::string newName; + }; + std::queue renameQueue; + ReturnValue_t writeToFile(FileOpParams params, const uint8_t *data) override; - ReturnValue_t readFromFile(FileOpParams fileOpInfo, uint8_t **buffer, size_t &readSize, + ReturnValue_t readFromFile(FileOpParams params, uint8_t **buffer, size_t &readSize, size_t maxSize) override; ReturnValue_t createFile(FilesystemParams params, const uint8_t *data, size_t size) override; ReturnValue_t removeFile(const char *path, FileSystemArgsIF *args) override; ReturnValue_t createDirectory(FilesystemParams params, bool createParentDirs) override; ReturnValue_t removeDirectory(FilesystemParams params, bool deleteRecurively) override; ReturnValue_t renameFile(const char *oldPath, char *newPath, FileSystemArgsIF *args) override; + + void reset(); + + private: + void createOrAddToFile(FileOpParams params, const uint8_t *data); }; #endif // FSFW_MOCKS_FILESYSTEMMOCK_H From 20eee2c469425d94537e6429ea2481760658bf58 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Thu, 11 Aug 2022 09:32:18 +0200 Subject: [PATCH 056/169] finished host FS impl --- src/fsfw/filesystem/HasFileSystemIF.h | 25 ++++++----- src/fsfw_hal/host/HostFilesystem.cpp | 62 ++++++++++++++++++++++++--- src/fsfw_hal/host/HostFilesystem.h | 2 +- unittests/mocks/FilesystemMock.cpp | 3 +- unittests/mocks/FilesystemMock.h | 2 +- 5 files changed, 73 insertions(+), 21 deletions(-) diff --git a/src/fsfw/filesystem/HasFileSystemIF.h b/src/fsfw/filesystem/HasFileSystemIF.h index 4fc8a941..a9f2b8ea 100644 --- a/src/fsfw/filesystem/HasFileSystemIF.h +++ b/src/fsfw/filesystem/HasFileSystemIF.h @@ -34,18 +34,23 @@ class HasFileSystemIF { //! [EXPORT] : P1: Can be file system specific error code static constexpr ReturnValue_t GENERIC_FILE_ERROR = MAKE_RETURN_CODE(0); + static constexpr ReturnValue_t GENERIC_DIR_ERROR = MAKE_RETURN_CODE(1); + static constexpr ReturnValue_t GENERIC_RENAME_ERROR = MAKE_RETURN_CODE(3); + //! [EXPORT] : File system is currently busy - static constexpr ReturnValue_t IS_BUSY = MAKE_RETURN_CODE(1); + static constexpr ReturnValue_t IS_BUSY = MAKE_RETURN_CODE(4); //! [EXPORT] : Invalid parameters like file name or repository path - static constexpr ReturnValue_t INVALID_PARAMETERS = MAKE_RETURN_CODE(2); + static constexpr ReturnValue_t INVALID_PARAMETERS = MAKE_RETURN_CODE(5); - static constexpr ReturnValue_t FILE_DOES_NOT_EXIST = MAKE_RETURN_CODE(5); - static constexpr ReturnValue_t FILE_ALREADY_EXISTS = MAKE_RETURN_CODE(6); - static constexpr ReturnValue_t FILE_LOCKED = MAKE_RETURN_CODE(7); + static constexpr ReturnValue_t FILE_DOES_NOT_EXIST = MAKE_RETURN_CODE(7); + static constexpr ReturnValue_t FILE_ALREADY_EXISTS = MAKE_RETURN_CODE(8); + static constexpr ReturnValue_t NOT_A_FILE = MAKE_RETURN_CODE(9); + static constexpr ReturnValue_t FILE_LOCKED = MAKE_RETURN_CODE(10); - static constexpr ReturnValue_t DIRECTORY_DOES_NOT_EXIST = MAKE_RETURN_CODE(10); - static constexpr ReturnValue_t DIRECTORY_ALREADY_EXISTS = MAKE_RETURN_CODE(11); - static constexpr ReturnValue_t DIRECTORY_NOT_EMPTY = MAKE_RETURN_CODE(12); + static constexpr ReturnValue_t DIRECTORY_DOES_NOT_EXIST = MAKE_RETURN_CODE(15); + static constexpr ReturnValue_t DIRECTORY_ALREADY_EXISTS = MAKE_RETURN_CODE(16); + static constexpr ReturnValue_t NOT_A_DIRECTORY = MAKE_RETURN_CODE(17); + static constexpr ReturnValue_t DIRECTORY_NOT_EMPTY = MAKE_RETURN_CODE(18); //! [EXPORT] : P1: Sequence number missing static constexpr ReturnValue_t SEQUENCE_PACKET_MISSING_WRITE = MAKE_RETURN_CODE(15); @@ -139,9 +144,9 @@ class HasFileSystemIF { } virtual ReturnValue_t renameFile(const char* oldPath, char* newPath) { - return renameFile(oldPath, newPath, nullptr); + return rename(oldPath, newPath, nullptr); } - virtual ReturnValue_t renameFile(const char* oldPath, char* newPath, FileSystemArgsIF* args) = 0; + virtual ReturnValue_t rename(const char* oldPath, char* newPath, FileSystemArgsIF* args) = 0; }; #endif /* FSFW_MEMORY_HASFILESYSTEMIF_H_ */ diff --git a/src/fsfw_hal/host/HostFilesystem.cpp b/src/fsfw_hal/host/HostFilesystem.cpp index 879b9377..c4a00baf 100644 --- a/src/fsfw_hal/host/HostFilesystem.cpp +++ b/src/fsfw_hal/host/HostFilesystem.cpp @@ -80,20 +80,68 @@ ReturnValue_t HostFilesystem::removeFile(const char *path_, FileSystemArgsIF *ar } return HasFileSystemIF::GENERIC_FILE_ERROR; } + ReturnValue_t HostFilesystem::createDirectory(FilesystemParams params, bool createParentDirs) { if (params.path == nullptr) { return HasReturnvaluesIF::RETURN_FAILED; } path dirPath(params.path); - if (createParentDirs) { - create_directories(dirPath, errorCode); + + if (exists(dirPath)) { + return HasFileSystemIF::DIRECTORY_ALREADY_EXISTS; } - return 0; + if (is_regular_file(dirPath)) { + return HasFileSystemIF::NOT_A_DIRECTORY; + } + if (createParentDirs) { + if (create_directories(dirPath, errorCode)) { + return HasReturnvaluesIF::RETURN_OK; + } + return HasFileSystemIF::GENERIC_DIR_ERROR; + } + if (create_directory(dirPath, errorCode)) { + return HasReturnvaluesIF::RETURN_OK; + } + return HasFileSystemIF::GENERIC_DIR_ERROR; } + ReturnValue_t HostFilesystem::removeDirectory(FilesystemParams params, bool deleteRecurively) { - return 0; + if (params.path == nullptr) { + return HasReturnvaluesIF::RETURN_FAILED; + } + path dirPath(params.path); + if (not exists(dirPath)) { + return HasFileSystemIF::DIRECTORY_DOES_NOT_EXIST; + } + if (is_regular_file(dirPath)) { + return HasFileSystemIF::NOT_A_DIRECTORY; + } + if (deleteRecurively) { + if (remove_all(dirPath, errorCode)) { + return HasReturnvaluesIF::RETURN_OK; + } + } else { + if (remove(dirPath, errorCode)) { + return HasReturnvaluesIF::RETURN_OK; + } + } + // Error handling + if (errorCode == std::errc::directory_not_empty) { + return HasFileSystemIF::DIRECTORY_NOT_EMPTY; + } + return HasFileSystemIF::GENERIC_DIR_ERROR; } -ReturnValue_t HostFilesystem::renameFile(const char *oldPath, char *newPath, - FileSystemArgsIF *args) { - return 0; + +ReturnValue_t HostFilesystem::rename(const char *oldPath_, char *newPath_, FileSystemArgsIF *args) { + if (oldPath_ == nullptr or newPath_ == nullptr) { + return HasReturnvaluesIF::RETURN_FAILED; + } + path oldPath(oldPath_); + path newPath(newPath_); + errorCode.clear(); + std::filesystem::rename(oldPath, newPath, errorCode); + if (errorCode) { + return HasFileSystemIF::GENERIC_RENAME_ERROR; + } + return HasReturnvaluesIF::RETURN_OK; } diff --git a/src/fsfw_hal/host/HostFilesystem.h b/src/fsfw_hal/host/HostFilesystem.h index 2dd8f2f5..01e37f08 100644 --- a/src/fsfw_hal/host/HostFilesystem.h +++ b/src/fsfw_hal/host/HostFilesystem.h @@ -15,7 +15,7 @@ class HostFilesystem : public HasFileSystemIF { ReturnValue_t removeFile(const char *path, FileSystemArgsIF *args) override; ReturnValue_t createDirectory(FilesystemParams params, bool createParentDirs) override; ReturnValue_t removeDirectory(FilesystemParams params, bool deleteRecurively) override; - ReturnValue_t renameFile(const char *oldPath, char *newPath, FileSystemArgsIF *args) override; + ReturnValue_t rename(const char *oldPath, char *newPath, FileSystemArgsIF *args) override; std::error_code errorCode; diff --git a/unittests/mocks/FilesystemMock.cpp b/unittests/mocks/FilesystemMock.cpp index e4efd086..b52c744f 100644 --- a/unittests/mocks/FilesystemMock.cpp +++ b/unittests/mocks/FilesystemMock.cpp @@ -64,8 +64,7 @@ ReturnValue_t FilesystemMock::removeDirectory(FilesystemParams params, bool dele return HasReturnvaluesIF::RETURN_OK; } -ReturnValue_t FilesystemMock::renameFile(const char *oldPath, char *newPath, - FileSystemArgsIF *args) { +ReturnValue_t FilesystemMock::rename(const char *oldPath, char *newPath, FileSystemArgsIF *args) { renameQueue.push(RenameInfo(oldPath, newPath)); return HasReturnvaluesIF::RETURN_OK; } diff --git a/unittests/mocks/FilesystemMock.h b/unittests/mocks/FilesystemMock.h index b02928c7..a1af45f0 100644 --- a/unittests/mocks/FilesystemMock.h +++ b/unittests/mocks/FilesystemMock.h @@ -60,7 +60,7 @@ class FilesystemMock : public HasFileSystemIF { ReturnValue_t removeFile(const char *path, FileSystemArgsIF *args) override; ReturnValue_t createDirectory(FilesystemParams params, bool createParentDirs) override; ReturnValue_t removeDirectory(FilesystemParams params, bool deleteRecurively) override; - ReturnValue_t renameFile(const char *oldPath, char *newPath, FileSystemArgsIF *args) override; + ReturnValue_t rename(const char *oldPath, char *newPath, FileSystemArgsIF *args) override; void reset(); From e796e025b6d5fca1adc2ad81752aa290dc926a3f Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Thu, 11 Aug 2022 09:59:14 +0200 Subject: [PATCH 057/169] continue host fs unittests --- src/fsfw_hal/host/HostFilesystem.h | 3 ++- unittests/hal/testHostFilesystem.cpp | 25 ++++++++++++++++++++++++- 2 files changed, 26 insertions(+), 2 deletions(-) diff --git a/src/fsfw_hal/host/HostFilesystem.h b/src/fsfw_hal/host/HostFilesystem.h index 01e37f08..4dda3ff7 100644 --- a/src/fsfw_hal/host/HostFilesystem.h +++ b/src/fsfw_hal/host/HostFilesystem.h @@ -18,7 +18,8 @@ class HostFilesystem : public HasFileSystemIF { ReturnValue_t rename(const char *oldPath, char *newPath, FileSystemArgsIF *args) override; std::error_code errorCode; - + using HasFileSystemIF::createFile; + using HasFileSystemIF::removeFile; private: }; #endif // FSFW_HAL_HOSTFILESYSTEM_H diff --git a/unittests/hal/testHostFilesystem.cpp b/unittests/hal/testHostFilesystem.cpp index 19af1c6b..a7166b01 100644 --- a/unittests/hal/testHostFilesystem.cpp +++ b/unittests/hal/testHostFilesystem.cpp @@ -1,5 +1,28 @@ #include #include "fsfw_hal/host/HostFilesystem.h" +#include -TEST_CASE("Host Filesystem", "[hal][host]") { auto hostFs = HostFilesystem(); } \ No newline at end of file +TEST_CASE("Host Filesystem", "[hal][host]") { + namespace fs = std::filesystem; + auto hostFs = HostFilesystem(); + auto tmpDir = fs::temp_directory_path(); + + SECTION("Create file") { + fs::path file = tmpDir / "hello.txt"; + FilesystemParams params(file.c_str()); + REQUIRE(hostFs.createFile(params) == result::OK); + REQUIRE(fs::exists(file)); + REQUIRE_NOTHROW(fs::remove(file)); + } + + SECTION("Remove File") { + fs::path file = tmpDir / "hello.txt"; + FilesystemParams params(file.c_str()); + REQUIRE(hostFs.createFile(params) == result::OK); + REQUIRE(fs::exists(file)); + REQUIRE(hostFs.removeFile(file.c_str()) == result::OK); + REQUIRE(not fs::exists(file)); + } + +} \ No newline at end of file From 8aaabc5d73bb2d9a555afaa94672823d224aa5b3 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Thu, 11 Aug 2022 10:10:05 +0200 Subject: [PATCH 058/169] basic host FS unittests --- src/fsfw/filesystem/HasFileSystemIF.h | 8 ++++-- src/fsfw_hal/host/HostFilesystem.cpp | 3 ++- src/fsfw_hal/host/HostFilesystem.h | 6 ++++- unittests/hal/testHostFilesystem.cpp | 36 ++++++++++++++++++++++++++- unittests/mocks/FilesystemMock.cpp | 3 ++- unittests/mocks/FilesystemMock.h | 2 +- 6 files changed, 51 insertions(+), 7 deletions(-) diff --git a/src/fsfw/filesystem/HasFileSystemIF.h b/src/fsfw/filesystem/HasFileSystemIF.h index a9f2b8ea..9771dda0 100644 --- a/src/fsfw/filesystem/HasFileSystemIF.h +++ b/src/fsfw/filesystem/HasFileSystemIF.h @@ -132,6 +132,9 @@ class HasFileSystemIF { * @return */ virtual ReturnValue_t createDirectory(FilesystemParams params, bool createParentDirs) = 0; + virtual ReturnValue_t createDirectory(FilesystemParams params) { + return createDirectory(params, false); + } /** * @brief Generic function to remove a directory @@ -143,10 +146,11 @@ class HasFileSystemIF { return removeDirectory(params, false); } - virtual ReturnValue_t renameFile(const char* oldPath, char* newPath) { + virtual ReturnValue_t rename(const char* oldPath, const char* newPath) { return rename(oldPath, newPath, nullptr); } - virtual ReturnValue_t rename(const char* oldPath, char* newPath, FileSystemArgsIF* args) = 0; + virtual ReturnValue_t rename(const char* oldPath, const char* newPath, + FileSystemArgsIF* args) = 0; }; #endif /* FSFW_MEMORY_HASFILESYSTEMIF_H_ */ diff --git a/src/fsfw_hal/host/HostFilesystem.cpp b/src/fsfw_hal/host/HostFilesystem.cpp index c4a00baf..8a861d47 100644 --- a/src/fsfw_hal/host/HostFilesystem.cpp +++ b/src/fsfw_hal/host/HostFilesystem.cpp @@ -132,7 +132,8 @@ ReturnValue_t HostFilesystem::removeDirectory(FilesystemParams params, bool dele return HasFileSystemIF::GENERIC_DIR_ERROR; } -ReturnValue_t HostFilesystem::rename(const char *oldPath_, char *newPath_, FileSystemArgsIF *args) { +ReturnValue_t HostFilesystem::rename(const char *oldPath_, const char *newPath_, + FileSystemArgsIF *args) { if (oldPath_ == nullptr or newPath_ == nullptr) { return HasReturnvaluesIF::RETURN_FAILED; } diff --git a/src/fsfw_hal/host/HostFilesystem.h b/src/fsfw_hal/host/HostFilesystem.h index 4dda3ff7..c35e0fda 100644 --- a/src/fsfw_hal/host/HostFilesystem.h +++ b/src/fsfw_hal/host/HostFilesystem.h @@ -15,11 +15,15 @@ class HostFilesystem : public HasFileSystemIF { ReturnValue_t removeFile(const char *path, FileSystemArgsIF *args) override; ReturnValue_t createDirectory(FilesystemParams params, bool createParentDirs) override; ReturnValue_t removeDirectory(FilesystemParams params, bool deleteRecurively) override; - ReturnValue_t rename(const char *oldPath, char *newPath, FileSystemArgsIF *args) override; + ReturnValue_t rename(const char *oldPath, const char *newPath, FileSystemArgsIF *args) override; std::error_code errorCode; + using HasFileSystemIF::createDirectory; using HasFileSystemIF::createFile; + using HasFileSystemIF::removeDirectory; using HasFileSystemIF::removeFile; + using HasFileSystemIF::rename; + private: }; #endif // FSFW_HAL_HOSTFILESYSTEM_H diff --git a/unittests/hal/testHostFilesystem.cpp b/unittests/hal/testHostFilesystem.cpp index a7166b01..d3fd880a 100644 --- a/unittests/hal/testHostFilesystem.cpp +++ b/unittests/hal/testHostFilesystem.cpp @@ -1,17 +1,22 @@ #include +#include #include "fsfw_hal/host/HostFilesystem.h" -#include TEST_CASE("Host Filesystem", "[hal][host]") { namespace fs = std::filesystem; auto hostFs = HostFilesystem(); auto tmpDir = fs::temp_directory_path(); + fs::path file0 = tmpDir / "hello.txt"; + fs::path file1 = tmpDir / "hello.txt"; + REQUIRE_NOTHROW(fs::remove(file0)); + REQUIRE_NOTHROW(fs::remove(file1)); SECTION("Create file") { fs::path file = tmpDir / "hello.txt"; FilesystemParams params(file.c_str()); REQUIRE(hostFs.createFile(params) == result::OK); + CHECK(fs::is_regular_file(file)); REQUIRE(fs::exists(file)); REQUIRE_NOTHROW(fs::remove(file)); } @@ -20,9 +25,38 @@ TEST_CASE("Host Filesystem", "[hal][host]") { fs::path file = tmpDir / "hello.txt"; FilesystemParams params(file.c_str()); REQUIRE(hostFs.createFile(params) == result::OK); + CHECK(fs::is_regular_file(file)); REQUIRE(fs::exists(file)); REQUIRE(hostFs.removeFile(file.c_str()) == result::OK); REQUIRE(not fs::exists(file)); } + SECTION("Create Directory") { + fs::path dirPath = tmpDir / "test_dir"; + FilesystemParams params(dirPath.c_str()); + REQUIRE(hostFs.createDirectory(params) == result::OK); + CHECK(fs::is_directory(dirPath)); + REQUIRE(fs::exists(dirPath)); + REQUIRE_NOTHROW(fs::remove(dirPath)); + } + + SECTION("Remove Directory") { + fs::path dirPath = tmpDir / "test_dir"; + FilesystemParams params(dirPath.c_str()); + REQUIRE(hostFs.createDirectory(params) == result::OK); + REQUIRE(fs::exists(dirPath)); + REQUIRE(hostFs.removeDirectory(params) == result::OK); + REQUIRE(not fs::exists(dirPath)); + } + + SECTION("Rename File") { + fs::path file = tmpDir / "hello.txt"; + fs::path newFile = tmpDir / "hello2.txt"; + FilesystemParams params(file.c_str()); + REQUIRE(hostFs.createFile(params) == result::OK); + CHECK(fs::is_regular_file(file)); + REQUIRE(fs::exists(file)); + REQUIRE(hostFs.rename(file.c_str(), newFile.c_str()) == result::OK); + REQUIRE_NOTHROW(fs::remove(newFile)); + } } \ No newline at end of file diff --git a/unittests/mocks/FilesystemMock.cpp b/unittests/mocks/FilesystemMock.cpp index b52c744f..5b195ffc 100644 --- a/unittests/mocks/FilesystemMock.cpp +++ b/unittests/mocks/FilesystemMock.cpp @@ -64,7 +64,8 @@ ReturnValue_t FilesystemMock::removeDirectory(FilesystemParams params, bool dele return HasReturnvaluesIF::RETURN_OK; } -ReturnValue_t FilesystemMock::rename(const char *oldPath, char *newPath, FileSystemArgsIF *args) { +ReturnValue_t FilesystemMock::rename(const char *oldPath, const char *newPath, + FileSystemArgsIF *args) { renameQueue.push(RenameInfo(oldPath, newPath)); return HasReturnvaluesIF::RETURN_OK; } diff --git a/unittests/mocks/FilesystemMock.h b/unittests/mocks/FilesystemMock.h index a1af45f0..f7c53eda 100644 --- a/unittests/mocks/FilesystemMock.h +++ b/unittests/mocks/FilesystemMock.h @@ -60,7 +60,7 @@ class FilesystemMock : public HasFileSystemIF { ReturnValue_t removeFile(const char *path, FileSystemArgsIF *args) override; ReturnValue_t createDirectory(FilesystemParams params, bool createParentDirs) override; ReturnValue_t removeDirectory(FilesystemParams params, bool deleteRecurively) override; - ReturnValue_t rename(const char *oldPath, char *newPath, FileSystemArgsIF *args) override; + ReturnValue_t rename(const char *oldPath, const char *newPath, FileSystemArgsIF *args) override; void reset(); From c12492df03da5cb529190336bd8269bd75bc6ba0 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Thu, 11 Aug 2022 10:19:25 +0200 Subject: [PATCH 059/169] continued host FS test --- src/fsfw/filesystem/HasFileSystemIF.h | 13 +++++- src/fsfw_hal/host/HostFilesystem.cpp | 8 ++-- unittests/hal/testHostFilesystem.cpp | 67 ++++++++++++++++----------- unittests/mocks/FilesystemMock.cpp | 4 +- 4 files changed, 56 insertions(+), 36 deletions(-) diff --git a/src/fsfw/filesystem/HasFileSystemIF.h b/src/fsfw/filesystem/HasFileSystemIF.h index 9771dda0..2f262285 100644 --- a/src/fsfw/filesystem/HasFileSystemIF.h +++ b/src/fsfw/filesystem/HasFileSystemIF.h @@ -16,9 +16,18 @@ struct FilesystemParams { FileSystemArgsIF* args = nullptr; }; -struct FileOpParams : public FilesystemParams { - FileOpParams(const char* path, size_t size) : FilesystemParams(path), size(size) {} +struct FileOpParams { + FileOpParams(const char* path, size_t size) : fsParams(path), size(size) {} + [[nodiscard]] const char* path() const { + return fsParams.path; + } + + [[nodiscard]] FileSystemArgsIF* args() const { + return fsParams.args; + } + + FilesystemParams fsParams; size_t size; size_t offset = 0; }; diff --git a/src/fsfw_hal/host/HostFilesystem.cpp b/src/fsfw_hal/host/HostFilesystem.cpp index 8a861d47..72cff2ed 100644 --- a/src/fsfw_hal/host/HostFilesystem.cpp +++ b/src/fsfw_hal/host/HostFilesystem.cpp @@ -11,10 +11,10 @@ using namespace std; HostFilesystem::HostFilesystem() = default; ReturnValue_t HostFilesystem::writeToFile(FileOpParams params, const uint8_t *data) { - if (params.path == nullptr) { + if (params.path() == nullptr) { return HasReturnvaluesIF::RETURN_FAILED; } - path path(params.path); + path path(params.path()); if (not exists(path)) { return HasFileSystemIF::FILE_DOES_NOT_EXIST; } @@ -29,10 +29,10 @@ ReturnValue_t HostFilesystem::writeToFile(FileOpParams params, const uint8_t *da ReturnValue_t HostFilesystem::readFromFile(FileOpParams params, uint8_t **buffer, size_t &readSize, size_t maxSize) { - if (params.path == nullptr) { + if (params.path() == nullptr) { return HasReturnvaluesIF::RETURN_FAILED; } - path path(params.path); + path path(params.path()); if (not exists(path)) { return HasFileSystemIF::FILE_DOES_NOT_EXIST; } diff --git a/unittests/hal/testHostFilesystem.cpp b/unittests/hal/testHostFilesystem.cpp index d3fd880a..ba3b1338 100644 --- a/unittests/hal/testHostFilesystem.cpp +++ b/unittests/hal/testHostFilesystem.cpp @@ -8,55 +8,66 @@ TEST_CASE("Host Filesystem", "[hal][host]") { auto hostFs = HostFilesystem(); auto tmpDir = fs::temp_directory_path(); fs::path file0 = tmpDir / "hello.txt"; - fs::path file1 = tmpDir / "hello.txt"; + fs::path file1 = tmpDir / "hello2.txt"; + fs::path dir0 = tmpDir / "test_dir"; REQUIRE_NOTHROW(fs::remove(file0)); REQUIRE_NOTHROW(fs::remove(file1)); + REQUIRE_NOTHROW(fs::remove(dir0)); SECTION("Create file") { - fs::path file = tmpDir / "hello.txt"; - FilesystemParams params(file.c_str()); + FilesystemParams params(file0.c_str()); REQUIRE(hostFs.createFile(params) == result::OK); - CHECK(fs::is_regular_file(file)); - REQUIRE(fs::exists(file)); - REQUIRE_NOTHROW(fs::remove(file)); + CHECK(fs::is_regular_file(file0)); + REQUIRE(fs::exists(file0)); + REQUIRE_NOTHROW(fs::remove(file0)); } SECTION("Remove File") { - fs::path file = tmpDir / "hello.txt"; - FilesystemParams params(file.c_str()); + FilesystemParams params(file0.c_str()); REQUIRE(hostFs.createFile(params) == result::OK); - CHECK(fs::is_regular_file(file)); - REQUIRE(fs::exists(file)); - REQUIRE(hostFs.removeFile(file.c_str()) == result::OK); - REQUIRE(not fs::exists(file)); + CHECK(fs::is_regular_file(file0)); + REQUIRE(fs::exists(file0)); + REQUIRE(hostFs.removeFile(file0.c_str()) == result::OK); + REQUIRE(not fs::exists(file0)); } SECTION("Create Directory") { - fs::path dirPath = tmpDir / "test_dir"; - FilesystemParams params(dirPath.c_str()); + FilesystemParams params(dir0.c_str()); REQUIRE(hostFs.createDirectory(params) == result::OK); - CHECK(fs::is_directory(dirPath)); - REQUIRE(fs::exists(dirPath)); - REQUIRE_NOTHROW(fs::remove(dirPath)); + CHECK(fs::is_directory(dir0)); + REQUIRE(fs::exists(dir0)); + REQUIRE_NOTHROW(fs::remove(dir0)); } SECTION("Remove Directory") { - fs::path dirPath = tmpDir / "test_dir"; - FilesystemParams params(dirPath.c_str()); + FilesystemParams params(dir0.c_str()); REQUIRE(hostFs.createDirectory(params) == result::OK); - REQUIRE(fs::exists(dirPath)); + REQUIRE(fs::exists(dir0)); REQUIRE(hostFs.removeDirectory(params) == result::OK); - REQUIRE(not fs::exists(dirPath)); + REQUIRE(not fs::exists(dir0)); } SECTION("Rename File") { - fs::path file = tmpDir / "hello.txt"; - fs::path newFile = tmpDir / "hello2.txt"; - FilesystemParams params(file.c_str()); + FilesystemParams params(file0.c_str()); REQUIRE(hostFs.createFile(params) == result::OK); - CHECK(fs::is_regular_file(file)); - REQUIRE(fs::exists(file)); - REQUIRE(hostFs.rename(file.c_str(), newFile.c_str()) == result::OK); - REQUIRE_NOTHROW(fs::remove(newFile)); + CHECK(fs::is_regular_file(file0)); + REQUIRE(fs::exists(file0)); + REQUIRE(hostFs.rename(file0.c_str(), file1.c_str()) == result::OK); + REQUIRE_NOTHROW(fs::remove(file1)); } + + SECTION("Write To File") { + std::string data = "hello world!"; + FileOpParams params(file0.c_str(), data.size()); + REQUIRE(hostFs.createFile(params.fsParams) == result::OK); + CHECK(fs::is_regular_file(file0)); + REQUIRE(fs::exists(file0)); + hostFs.writeToFile(params, reinterpret_cast(data.c_str())); + // TODO: Read back file and verify content + REQUIRE_NOTHROW(fs::remove(file1)); + } + + REQUIRE_NOTHROW(fs::remove(file0)); + REQUIRE_NOTHROW(fs::remove(file1)); + REQUIRE_NOTHROW(fs::remove(dir0)); } \ No newline at end of file diff --git a/unittests/mocks/FilesystemMock.cpp b/unittests/mocks/FilesystemMock.cpp index 5b195ffc..02620fd5 100644 --- a/unittests/mocks/FilesystemMock.cpp +++ b/unittests/mocks/FilesystemMock.cpp @@ -9,7 +9,7 @@ ReturnValue_t FilesystemMock::writeToFile(FileOpParams params, const uint8_t *da ReturnValue_t FilesystemMock::readFromFile(FileOpParams params, uint8_t **buffer, size_t &readSize, size_t maxSize) { - std::string filename(params.path); + std::string filename(params.path()); auto iter = fileMap.find(filename); if (iter == fileMap.end()) { return HasFileSystemIF::FILE_DOES_NOT_EXIST; @@ -71,7 +71,7 @@ ReturnValue_t FilesystemMock::rename(const char *oldPath, const char *newPath, } void FilesystemMock::createOrAddToFile(FileOpParams params, const uint8_t *data) { - std::string filename(params.path); + std::string filename(params.path()); auto iter = fileMap.find(filename); if (iter == fileMap.end()) { FileSegmentQueue queue; From 23f514039aa4587d4dd49065ad00308297dc707e Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Wed, 17 Aug 2022 11:39:15 +0200 Subject: [PATCH 060/169] host filesystem continued --- src/fsfw/filesystem/HasFileSystemIF.h | 8 ++--- src/fsfw/tcdistribution/PusDistributor.cpp | 3 +- src/fsfw_hal/host/HostFilesystem.cpp | 12 ++++---- unittests/hal/testHostFilesystem.cpp | 36 ++++++++++++++++++++-- unittests/util/CMakeLists.txt | 4 +-- 5 files changed, 44 insertions(+), 19 deletions(-) diff --git a/src/fsfw/filesystem/HasFileSystemIF.h b/src/fsfw/filesystem/HasFileSystemIF.h index 2f262285..078de7c0 100644 --- a/src/fsfw/filesystem/HasFileSystemIF.h +++ b/src/fsfw/filesystem/HasFileSystemIF.h @@ -19,13 +19,9 @@ struct FilesystemParams { struct FileOpParams { FileOpParams(const char* path, size_t size) : fsParams(path), size(size) {} - [[nodiscard]] const char* path() const { - return fsParams.path; - } + [[nodiscard]] const char* path() const { return fsParams.path; } - [[nodiscard]] FileSystemArgsIF* args() const { - return fsParams.args; - } + [[nodiscard]] FileSystemArgsIF* args() const { return fsParams.args; } FilesystemParams fsParams; size_t size; diff --git a/src/fsfw/tcdistribution/PusDistributor.cpp b/src/fsfw/tcdistribution/PusDistributor.cpp index d827d5b6..982a99bf 100644 --- a/src/fsfw/tcdistribution/PusDistributor.cpp +++ b/src/fsfw/tcdistribution/PusDistributor.cpp @@ -134,7 +134,8 @@ ReturnValue_t PusDistributor::initialize() { return ObjectManagerIF::CHILD_INIT_FAILED; } if (verifyChannel == nullptr) { - verifyChannel = ObjectManager::instance()->get(objects::VERIFICATION_REPORTER); + verifyChannel = + ObjectManager::instance()->get(objects::VERIFICATION_REPORTER); if (verifyChannel == nullptr) { return ObjectManagerIF::CHILD_INIT_FAILED; } diff --git a/src/fsfw_hal/host/HostFilesystem.cpp b/src/fsfw_hal/host/HostFilesystem.cpp index 72cff2ed..ebe60444 100644 --- a/src/fsfw_hal/host/HostFilesystem.cpp +++ b/src/fsfw_hal/host/HostFilesystem.cpp @@ -40,14 +40,14 @@ ReturnValue_t HostFilesystem::readFromFile(FileOpParams params, uint8_t **buffer if (file.fail()) { return HasFileSystemIF::GENERIC_FILE_ERROR; } - auto readLen = static_cast(params.offset); - file.seekg(readLen); - if (readSize + params.size > maxSize) { + auto sizeToRead = static_cast(params.size); + file.seekg(static_cast(params.offset)); + if (readSize + sizeToRead > maxSize) { return SerializeIF::BUFFER_TOO_SHORT; } - file.read(reinterpret_cast(*buffer), readLen); - readSize += readLen; - *buffer += readLen; + file.read(reinterpret_cast(*buffer), sizeToRead); + readSize += sizeToRead; + *buffer += sizeToRead; return HasReturnvaluesIF::RETURN_OK; } diff --git a/unittests/hal/testHostFilesystem.cpp b/unittests/hal/testHostFilesystem.cpp index ba3b1338..bf2d49d5 100644 --- a/unittests/hal/testHostFilesystem.cpp +++ b/unittests/hal/testHostFilesystem.cpp @@ -1,10 +1,13 @@ #include #include +#include #include "fsfw_hal/host/HostFilesystem.h" +using namespace std; + TEST_CASE("Host Filesystem", "[hal][host]") { - namespace fs = std::filesystem; + namespace fs = filesystem; auto hostFs = HostFilesystem(); auto tmpDir = fs::temp_directory_path(); fs::path file0 = tmpDir / "hello.txt"; @@ -62,8 +65,35 @@ TEST_CASE("Host Filesystem", "[hal][host]") { REQUIRE(hostFs.createFile(params.fsParams) == result::OK); CHECK(fs::is_regular_file(file0)); REQUIRE(fs::exists(file0)); - hostFs.writeToFile(params, reinterpret_cast(data.c_str())); - // TODO: Read back file and verify content + CHECK(hostFs.writeToFile(params, reinterpret_cast(data.c_str())) == + HasReturnvaluesIF::RETURN_OK); + CHECK(fs::file_size(file0) == data.size()); + ifstream ifile(file0); + char readBuf[524]{}; + ifile.read(readBuf, sizeof(readBuf)); + std::string readBackString(readBuf); + CHECK(data == readBackString); + REQUIRE_NOTHROW(fs::remove(file1)); + } + + SECTION("Read From File") { + std::string data = "hello world!"; + FileOpParams params(file0.c_str(), data.size()); + REQUIRE(hostFs.createFile(params.fsParams) == result::OK); + CHECK(fs::is_regular_file(file0)); + ofstream of(file0); + of.write(data.c_str(), static_cast(data.size())); + of.close(); + CHECK(fs::file_size(file0) == data.size()); + REQUIRE(fs::exists(file0)); + std::array readBuf{}; + uint8_t* readPtr = readBuf.data(); + size_t readSize = 0; + CHECK(hostFs.readFromFile(params, &readPtr, readSize, readBuf.size()) == + HasReturnvaluesIF::RETURN_OK); + std::string readBackString(reinterpret_cast(readBuf.data())); + CHECK(readSize == data.size()); + CHECK(data == readBackString); REQUIRE_NOTHROW(fs::remove(file1)); } diff --git a/unittests/util/CMakeLists.txt b/unittests/util/CMakeLists.txt index d4caa4d5..fb660d54 100644 --- a/unittests/util/CMakeLists.txt +++ b/unittests/util/CMakeLists.txt @@ -1,3 +1 @@ -target_sources(${FSFW_TEST_TGT} PRIVATE - testUnsignedByteField.cpp -) +target_sources(${FSFW_TEST_TGT} PRIVATE testUnsignedByteField.cpp) From 12c452e7cef8caeb725d473cd56e11d812471174 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Wed, 17 Aug 2022 16:10:52 +0200 Subject: [PATCH 061/169] finished host FS unittests --- src/fsfw_hal/host/HostFilesystem.cpp | 4 +- unittests/hal/testHostFilesystem.cpp | 112 +++++++++++++++++++++++++-- 2 files changed, 106 insertions(+), 10 deletions(-) diff --git a/src/fsfw_hal/host/HostFilesystem.cpp b/src/fsfw_hal/host/HostFilesystem.cpp index ebe60444..7ebe5df8 100644 --- a/src/fsfw_hal/host/HostFilesystem.cpp +++ b/src/fsfw_hal/host/HostFilesystem.cpp @@ -90,9 +90,7 @@ ReturnValue_t HostFilesystem::createDirectory(FilesystemParams params, bool crea if (exists(dirPath)) { return HasFileSystemIF::DIRECTORY_ALREADY_EXISTS; } - if (is_regular_file(dirPath)) { - return HasFileSystemIF::NOT_A_DIRECTORY; - } + if (createParentDirs) { if (create_directories(dirPath, errorCode)) { return HasReturnvaluesIF::RETURN_OK; diff --git a/unittests/hal/testHostFilesystem.cpp b/unittests/hal/testHostFilesystem.cpp index bf2d49d5..2da185da 100644 --- a/unittests/hal/testHostFilesystem.cpp +++ b/unittests/hal/testHostFilesystem.cpp @@ -2,6 +2,7 @@ #include #include +#include "fsfw/serialize/SerializeIF.h" #include "fsfw_hal/host/HostFilesystem.h" using namespace std; @@ -13,16 +14,18 @@ TEST_CASE("Host Filesystem", "[hal][host]") { fs::path file0 = tmpDir / "hello.txt"; fs::path file1 = tmpDir / "hello2.txt"; fs::path dir0 = tmpDir / "test_dir"; + fs::path fileInDir0 = dir0 / "hello.txt"; + fs::path dirWithParent = dir0 / "test_dir"; + REQUIRE_NOTHROW(fs::remove(file0)); REQUIRE_NOTHROW(fs::remove(file1)); - REQUIRE_NOTHROW(fs::remove(dir0)); + REQUIRE_NOTHROW(fs::remove_all(dir0)); SECTION("Create file") { FilesystemParams params(file0.c_str()); REQUIRE(hostFs.createFile(params) == result::OK); CHECK(fs::is_regular_file(file0)); REQUIRE(fs::exists(file0)); - REQUIRE_NOTHROW(fs::remove(file0)); } SECTION("Remove File") { @@ -39,7 +42,6 @@ TEST_CASE("Host Filesystem", "[hal][host]") { REQUIRE(hostFs.createDirectory(params) == result::OK); CHECK(fs::is_directory(dir0)); REQUIRE(fs::exists(dir0)); - REQUIRE_NOTHROW(fs::remove(dir0)); } SECTION("Remove Directory") { @@ -56,7 +58,6 @@ TEST_CASE("Host Filesystem", "[hal][host]") { CHECK(fs::is_regular_file(file0)); REQUIRE(fs::exists(file0)); REQUIRE(hostFs.rename(file0.c_str(), file1.c_str()) == result::OK); - REQUIRE_NOTHROW(fs::remove(file1)); } SECTION("Write To File") { @@ -73,7 +74,6 @@ TEST_CASE("Host Filesystem", "[hal][host]") { ifile.read(readBuf, sizeof(readBuf)); std::string readBackString(readBuf); CHECK(data == readBackString); - REQUIRE_NOTHROW(fs::remove(file1)); } SECTION("Read From File") { @@ -94,10 +94,108 @@ TEST_CASE("Host Filesystem", "[hal][host]") { std::string readBackString(reinterpret_cast(readBuf.data())); CHECK(readSize == data.size()); CHECK(data == readBackString); - REQUIRE_NOTHROW(fs::remove(file1)); + } + + SECTION("Invalid Input does not crash") { + FileOpParams params(nullptr, 10); + REQUIRE(hostFs.createFile(params.fsParams) != result::OK); + REQUIRE(hostFs.createDirectory(params.fsParams) != result::OK); + REQUIRE(hostFs.createFile(params.fsParams) != result::OK); + REQUIRE(hostFs.removeDirectory(params.fsParams) != result::OK); + REQUIRE(hostFs.removeFile(nullptr) != result::OK); + REQUIRE(hostFs.rename(nullptr, nullptr) != result::OK); + REQUIRE(hostFs.writeToFile(params, nullptr) != result::OK); + size_t readLen = 0; + REQUIRE(hostFs.readFromFile(params, nullptr, readLen, 20) != result::OK); + } + + SECTION("Create File but already exists") { + FilesystemParams params(file0.c_str()); + REQUIRE(hostFs.createFile(params) == result::OK); + REQUIRE(hostFs.createFile(params) == HasFileSystemIF::FILE_ALREADY_EXISTS); + } + + SECTION("Remove File but does not exist") { + REQUIRE(hostFs.removeFile(file0.c_str()) == HasFileSystemIF::FILE_DOES_NOT_EXIST); + } + + SECTION("Create Directory but already exists") { + FileOpParams params(file0.c_str(), 12); + REQUIRE(hostFs.createDirectory(params.fsParams) == HasReturnvaluesIF::RETURN_OK); + REQUIRE(hostFs.createDirectory(params.fsParams) == HasFileSystemIF::DIRECTORY_ALREADY_EXISTS); + } + + SECTION("Remove Directory but does not exist") { + FilesystemParams params(dir0.c_str()); + REQUIRE(hostFs.removeDirectory(params) == HasFileSystemIF::DIRECTORY_DOES_NOT_EXIST); + } + + SECTION("Remove Directory but is file") { + ofstream of(file0); + FilesystemParams params(file0.c_str()); + REQUIRE(hostFs.removeDirectory(params) == HasFileSystemIF::NOT_A_DIRECTORY); + } + + SECTION("Read from file but does not exist") { + std::string data = "hello world!"; + FileOpParams params(file0.c_str(), data.size()); + std::array readBuf{}; + uint8_t* readPtr = readBuf.data(); + size_t readSize = 0; + CHECK(hostFs.readFromFile(params, &readPtr, readSize, readBuf.size()) == + HasFileSystemIF::FILE_DOES_NOT_EXIST); + } + + SECTION("Write to file but does not exist") { + std::string data = "hello world!"; + FileOpParams params(file0.c_str(), data.size()); + CHECK(hostFs.writeToFile(params, reinterpret_cast(data.c_str())) == + HasFileSystemIF::FILE_DOES_NOT_EXIST); + } + + SECTION("Remove recursively") { + fs::create_directory(dir0.c_str()); + ofstream of(fileInDir0); + CHECK(fs::is_directory(dir0)); + CHECK(fs::is_regular_file(fileInDir0)); + REQUIRE(hostFs.removeDirectory(FilesystemParams(dir0.c_str()), true) == result::OK); + CHECK(not fs::is_directory(dir0)); + CHECK(not fs::is_regular_file(fileInDir0)); + } + + SECTION("Non-Recursive Removal Fails") { + fs::create_directory(dir0.c_str()); + ofstream of(fileInDir0); + CHECK(fs::is_directory(dir0)); + CHECK(fs::is_regular_file(fileInDir0)); + REQUIRE(hostFs.removeDirectory(FilesystemParams(dir0.c_str())) == + HasFileSystemIF::DIRECTORY_NOT_EMPTY); + } + + SECTION("Create directory with parent directory") { + CHECK(hostFs.createDirectory(FilesystemParams(dirWithParent.c_str()), true) == result::OK); + CHECK(fs::is_directory(dir0)); + CHECK(fs::is_directory(dirWithParent)); + } + + SECTION("Read but provided buffer too small") { + std::string data = "hello world!"; + FileOpParams params(file0.c_str(), data.size()); + ofstream of(file0); + of.write(data.c_str(), static_cast(data.size())); + of.close(); + CHECK(fs::file_size(file0) == data.size()); + REQUIRE(fs::exists(file0)); + std::array readBuf{}; + uint8_t* readPtr = readBuf.data(); + size_t readSize = 0; + CHECK(hostFs.readFromFile(params, &readPtr, readSize, 5) == SerializeIF::BUFFER_TOO_SHORT); + readSize = 10; + CHECK(hostFs.readFromFile(params, &readPtr, readSize, readBuf.size()) == + SerializeIF::BUFFER_TOO_SHORT); } REQUIRE_NOTHROW(fs::remove(file0)); REQUIRE_NOTHROW(fs::remove(file1)); - REQUIRE_NOTHROW(fs::remove(dir0)); + REQUIRE_NOTHROW(fs::remove_all(dir0)); } \ No newline at end of file From 0bb82e0da290418cad3d860ade67ae9c630ced15 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Wed, 17 Aug 2022 16:47:46 +0200 Subject: [PATCH 062/169] add fs mock feed function --- unittests/hal/CMakeLists.txt | 2 +- unittests/hal/testFsMock.cpp | 49 ++++++++++++++++++++++++++++++ unittests/mocks/FilesystemMock.cpp | 20 +++++++++++- unittests/mocks/FilesystemMock.h | 6 ++++ 4 files changed, 75 insertions(+), 2 deletions(-) create mode 100644 unittests/hal/testFsMock.cpp diff --git a/unittests/hal/CMakeLists.txt b/unittests/hal/CMakeLists.txt index 5e2887b2..5d1c7846 100644 --- a/unittests/hal/CMakeLists.txt +++ b/unittests/hal/CMakeLists.txt @@ -1,2 +1,2 @@ target_sources(${FSFW_TEST_TGT} PRIVATE testCommandExecutor.cpp - testHostFilesystem.cpp) + testHostFilesystem.cpp testFsMock.cpp) diff --git a/unittests/hal/testFsMock.cpp b/unittests/hal/testFsMock.cpp new file mode 100644 index 00000000..7040e734 --- /dev/null +++ b/unittests/hal/testFsMock.cpp @@ -0,0 +1,49 @@ +#include + +#include "fsfw/serialize/SerializeIF.h" +#include "mocks/FilesystemMock.h" + +using namespace std; + +TEST_CASE("Filesystem Mock", "[mocks]") { + auto fsMock = FilesystemMock(); + + SECTION("Create File") { + FilesystemParams params("hello.txt"); + CHECK(fsMock.createFile(params) == result::OK); + auto iter = fsMock.fileMap.find("hello.txt"); + REQUIRE(iter != fsMock.fileMap.end()); + FilesystemMock::FileInfo &stats = iter->second; + CHECK(stats.fileSegQueue.empty()); + CHECK(stats.fileRaw.empty()); + } + + SECTION("Write to File") { + std::string testData = "test data"; + FileOpParams params("hello.txt", testData.size()); + CHECK(fsMock.writeToFile(params, reinterpret_cast(testData.data())) == + HasReturnvaluesIF::RETURN_OK); + auto iter = fsMock.fileMap.find("hello.txt"); + REQUIRE(iter != fsMock.fileMap.end()); + FilesystemMock::FileInfo &stats = iter->second; + CHECK(not stats.fileSegQueue.empty()); + CHECK(not stats.fileRaw.empty()); + auto &segment = stats.fileSegQueue.back(); + CHECK(segment.offset == 0); + CHECK(std::string(reinterpret_cast(segment.data.data()), segment.data.size()) == + testData); + CHECK(std::string(reinterpret_cast(stats.fileRaw.data()), segment.data.size()) == + testData); + } + + SECTION("Create Directory") { + FilesystemParams params("hello"); + CHECK(fsMock.createDirectory(params) == result::OK); + REQUIRE(not fsMock.dirMap.empty()); + auto iter = fsMock.dirMap.find("hello"); + REQUIRE(iter != fsMock.dirMap.end()); + auto &dirInfo = iter->second; + CHECK(dirInfo.createCallCount == 1); + CHECK(dirInfo.delCallCount == 0); + } +} \ No newline at end of file diff --git a/unittests/mocks/FilesystemMock.cpp b/unittests/mocks/FilesystemMock.cpp index 02620fd5..8f9e3f8f 100644 --- a/unittests/mocks/FilesystemMock.cpp +++ b/unittests/mocks/FilesystemMock.cpp @@ -1,7 +1,21 @@ #include "FilesystemMock.h" +#include + #include "fsfw/serialize/SerializeIF.h" +ReturnValue_t FilesystemMock::feedFile(const std::string &filename, std::ifstream &file) { + if (not std::filesystem::exists(filename)) { + return HasReturnvaluesIF::RETURN_FAILED; + } + size_t fileSize = std::filesystem::file_size(filename); + FileOpParams params(filename.c_str(), fileSize); + std::vector rawData(fileSize); + file.read(reinterpret_cast(rawData.data()), static_cast(rawData.size())); + createOrAddToFile(params, rawData.data()); + return HasReturnvaluesIF::RETURN_OK; +} + ReturnValue_t FilesystemMock::writeToFile(FileOpParams params, const uint8_t *data) { createOrAddToFile(params, data); return HasReturnvaluesIF::RETURN_OK; @@ -75,7 +89,9 @@ void FilesystemMock::createOrAddToFile(FileOpParams params, const uint8_t *data) auto iter = fileMap.find(filename); if (iter == fileMap.end()) { FileSegmentQueue queue; - queue.push(FileWriteInfo(filename, params.offset, data, params.size)); + if (params.size > 0) { + queue.push(FileWriteInfo(filename, params.offset, data, params.size)); + } FileInfo info; info.fileSegQueue = queue; if (data != nullptr) { @@ -105,4 +121,6 @@ void FilesystemMock::createOrAddToFile(FileOpParams params, const uint8_t *data) void FilesystemMock::reset() { fileMap.clear(); dirMap.clear(); + std::queue empty; + std::swap(renameQueue, empty); } diff --git a/unittests/mocks/FilesystemMock.h b/unittests/mocks/FilesystemMock.h index f7c53eda..19d4d38c 100644 --- a/unittests/mocks/FilesystemMock.h +++ b/unittests/mocks/FilesystemMock.h @@ -1,6 +1,7 @@ #ifndef FSFW_MOCKS_FILESYSTEMMOCK_H #define FSFW_MOCKS_FILESYSTEMMOCK_H +#include #include #include #include @@ -53,6 +54,7 @@ class FilesystemMock : public HasFileSystemIF { }; std::queue renameQueue; + ReturnValue_t feedFile(const std::string &filename, std::ifstream &file); ReturnValue_t writeToFile(FileOpParams params, const uint8_t *data) override; ReturnValue_t readFromFile(FileOpParams params, uint8_t **buffer, size_t &readSize, size_t maxSize) override; @@ -64,6 +66,10 @@ class FilesystemMock : public HasFileSystemIF { void reset(); + using HasFileSystemIF::createDirectory; + using HasFileSystemIF::createFile; + using HasFileSystemIF::readFromFile; + private: void createOrAddToFile(FileOpParams params, const uint8_t *data); }; From 6930656d4e5bc52c429bfdd9669e052cf18aaec1 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Wed, 17 Aug 2022 17:09:39 +0200 Subject: [PATCH 063/169] added some more basic tests --- src/fsfw/cfdp/handler/RemoteConfigTableIF.h | 2 +- unittests/cfdp/handler/testDestHandler.cpp | 7 ++++++- unittests/mocks/cfdp/RemoteConfigTableMock.cpp | 15 ++++++++++++--- unittests/mocks/cfdp/RemoteConfigTableMock.h | 7 ++++++- unittests/mocks/cfdp/UserMock.h | 2 +- 5 files changed, 26 insertions(+), 7 deletions(-) diff --git a/src/fsfw/cfdp/handler/RemoteConfigTableIF.h b/src/fsfw/cfdp/handler/RemoteConfigTableIF.h index 767492d5..1cd1ec1d 100644 --- a/src/fsfw/cfdp/handler/RemoteConfigTableIF.h +++ b/src/fsfw/cfdp/handler/RemoteConfigTableIF.h @@ -8,7 +8,7 @@ namespace cfdp { class RemoteConfigTableIF { public: virtual ~RemoteConfigTableIF() = default; - virtual bool getRemoteCfg(EntityId remoteId, RemoteEntityCfg* cfg) = 0; + virtual bool getRemoteCfg(const cfdp::EntityId& remoteId, cfdp::RemoteEntityCfg** cfg) = 0; }; } // namespace cfdp diff --git a/unittests/cfdp/handler/testDestHandler.cpp b/unittests/cfdp/handler/testDestHandler.cpp index 0d9fe9f5..8189096d 100644 --- a/unittests/cfdp/handler/testDestHandler.cpp +++ b/unittests/cfdp/handler/testDestHandler.cpp @@ -1,7 +1,9 @@ #include #include "fsfw/cfdp.h" +#include "mocks/FilesystemMock.h" #include "mocks/cfdp/FaultHandlerMock.h" +#include "mocks/cfdp/RemoteConfigTableMock.h" #include "mocks/cfdp/UserMock.h" TEST_CASE("CFDP Dest Handler", "[cfdp]") { @@ -9,7 +11,10 @@ TEST_CASE("CFDP Dest Handler", "[cfdp]") { EntityId localId = EntityId(UnsignedByteField(2)); auto fhMock = FaultHandlerMock(); auto localEntityCfg = LocalEntityCfg(localId, IndicationCfg(), fhMock); - // auto userMock = UserMock(); + auto fsMock = FilesystemMock(); + auto userMock = UserMock(fsMock); + auto remoteCfgTableMock = RemoteConfigTableMock(); + auto destHandler = DestHandler(localEntityCfg, userMock, remoteCfgTableMock); SECTION("State") {} } \ No newline at end of file diff --git a/unittests/mocks/cfdp/RemoteConfigTableMock.cpp b/unittests/mocks/cfdp/RemoteConfigTableMock.cpp index 83827a36..9cb0b77c 100644 --- a/unittests/mocks/cfdp/RemoteConfigTableMock.cpp +++ b/unittests/mocks/cfdp/RemoteConfigTableMock.cpp @@ -1,6 +1,15 @@ #include "RemoteConfigTableMock.h" -bool cfdp::RemoteConfigTableMock::getRemoteCfg(cfdp::EntityId remoteId, - cfdp::RemoteEntityCfg *cfg) { - return false; +void cfdp::RemoteConfigTableMock::addRemoteConfig(const cfdp::RemoteEntityCfg& cfg) { + remoteCfgTable.emplace(cfg.remoteId, cfg); +} + +bool cfdp::RemoteConfigTableMock::getRemoteCfg(const cfdp::EntityId& remoteId, + cfdp::RemoteEntityCfg** cfg) { + auto iter = remoteCfgTable.find(remoteId); + if (iter == remoteCfgTable.end()) { + return false; + } + *cfg = &iter->second; + return true; } diff --git a/unittests/mocks/cfdp/RemoteConfigTableMock.h b/unittests/mocks/cfdp/RemoteConfigTableMock.h index e3e954e4..70891836 100644 --- a/unittests/mocks/cfdp/RemoteConfigTableMock.h +++ b/unittests/mocks/cfdp/RemoteConfigTableMock.h @@ -1,13 +1,18 @@ #ifndef FSFW_TESTS_CFDP_REMOTCONFIGTABLEMOCK_H #define FSFW_TESTS_CFDP_REMOTCONFIGTABLEMOCK_H +#include + #include "fsfw/cfdp/handler/RemoteConfigTableIF.h" namespace cfdp { class RemoteConfigTableMock : public RemoteConfigTableIF { public: - bool getRemoteCfg(EntityId remoteId, RemoteEntityCfg *cfg) override; + void addRemoteConfig(const RemoteEntityCfg& cfg); + bool getRemoteCfg(const cfdp::EntityId& remoteId, cfdp::RemoteEntityCfg** cfg) override; + + std::map remoteCfgTable; }; } // namespace cfdp diff --git a/unittests/mocks/cfdp/UserMock.h b/unittests/mocks/cfdp/UserMock.h index 7106a844..d9d05336 100644 --- a/unittests/mocks/cfdp/UserMock.h +++ b/unittests/mocks/cfdp/UserMock.h @@ -5,9 +5,9 @@ namespace cfdp { class UserMock : public UserBase { + public: explicit UserMock(HasFileSystemIF& vfs); - public: void transactionIndication(TransactionId id) override; void eofSentIndication(TransactionId id) override; void abandonedIndication(TransactionId id, ConditionCode code, size_t progress) override; From 11a699c3ced6717a39e45ef53bdd287f3015c21a Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Wed, 17 Aug 2022 18:49:51 +0200 Subject: [PATCH 064/169] a list should do the job --- src/fsfw/cfdp/handler/DestHandler.cpp | 51 ++++++++++++++++-- src/fsfw/cfdp/handler/DestHandler.h | 60 ++++++++++++++++++++-- src/fsfw/container/DynamicFIFO.h | 3 +- src/fsfw/container/FIFOBase.h | 4 +- unittests/cfdp/handler/testDestHandler.cpp | 2 +- 5 files changed, 109 insertions(+), 11 deletions(-) diff --git a/src/fsfw/cfdp/handler/DestHandler.cpp b/src/fsfw/cfdp/handler/DestHandler.cpp index d2b672c9..f04a4b12 100644 --- a/src/fsfw/cfdp/handler/DestHandler.cpp +++ b/src/fsfw/cfdp/handler/DestHandler.cpp @@ -2,6 +2,51 @@ #include -cfdp::DestHandler::DestHandler(LocalEntityCfg cfg, UserBase& user, - RemoteConfigTableIF& remoteCfgTable) - : cfg(std::move(cfg)), user(user), remoteCfgTable(remoteCfgTable) {} +#include "fsfw/objectmanager.h" + +cfdp::DestHandler::DestHandler(DestHandlerParams params) : p(std::move(params)) {} + +ReturnValue_t cfdp::DestHandler::performStateMachine() { + switch (step) { + case TransactionStep::IDLE: { + for (const auto& info : p.packetListRef) { + } + } + case TransactionStep::TRANSACTION_START: + break; + case TransactionStep::RECEIVING_FILE_DATA_PDUS: + break; + case TransactionStep::SENDING_ACK_PDU: + break; + case TransactionStep::TRANSFER_COMPLETION: + break; + case TransactionStep::SENDING_FINISHED_PDU: + break; + } + return HasReturnvaluesIF::RETURN_OK; +} + +ReturnValue_t cfdp::DestHandler::passPacket(PacketInfo packet) { + if (p.packetListRef.full()) { + return HasReturnvaluesIF::RETURN_FAILED; + } + p.packetListRef.push_back(packet); + return HasReturnvaluesIF::RETURN_OK; +} + +ReturnValue_t cfdp::DestHandler::initialize() { + if (p.tmStore == nullptr) { + p.tmStore = ObjectManager::instance()->get(objects::TM_STORE); + if (p.tmStore == nullptr) { + return HasReturnvaluesIF::RETURN_FAILED; + } + } + + if (p.tcStore == nullptr) { + p.tcStore = ObjectManager::instance()->get(objects::TC_STORE); + if (p.tcStore == nullptr) { + return HasReturnvaluesIF::RETURN_FAILED; + } + } + return HasReturnvaluesIF::RETURN_OK; +} diff --git a/src/fsfw/cfdp/handler/DestHandler.h b/src/fsfw/cfdp/handler/DestHandler.h index 0032c7b8..c3e30721 100644 --- a/src/fsfw/cfdp/handler/DestHandler.h +++ b/src/fsfw/cfdp/handler/DestHandler.h @@ -1,21 +1,73 @@ #ifndef FSFW_CFDP_CFDPDESTHANDLER_H #define FSFW_CFDP_CFDPDESTHANDLER_H +#include + +#include + #include "RemoteConfigTableIF.h" #include "UserBase.h" #include "fsfw/cfdp/handler/mib.h" #include "fsfw/cfdp/pdu/PduConfig.h" +#include "fsfw/container/DynamicFIFO.h" +#include "fsfw/storagemanager/StorageManagerIF.h" +#include "fsfw/storagemanager/storeAddress.h" +#include "fsfw/tmtcservices/AcceptsTelemetryIF.h" namespace cfdp { -class DestHandler { - public: - DestHandler(LocalEntityCfg cfg, UserBase& user, RemoteConfigTableIF& remoteCfgTable); +struct PacketInfo { + PacketInfo(PduType type, FileDirectives directive, store_address_t storeId) + : pduType(type), directiveType(directive), storeId(storeId) {} + + PduType pduType = PduType::FILE_DATA; + FileDirectives directiveType = FileDirectives::INVALID_DIRECTIVE; + store_address_t storeId = store_address_t::invalid(); + PacketInfo() = default; +}; + +struct DestHandlerParams { + DestHandlerParams(LocalEntityCfg cfg, UserBase& user, RemoteConfigTableIF& remoteCfgTable, + AcceptsTelemetryIF& packetDest, MessageQueueIF& msgQueue, + etl::ilist& packetList) + : cfg(std::move(cfg)), + user(user), + remoteCfgTable(remoteCfgTable), + packetDest(packetDest), + msgQueue(msgQueue), + packetListRef(packetList) {} - private: LocalEntityCfg cfg; UserBase& user; RemoteConfigTableIF& remoteCfgTable; + AcceptsTelemetryIF& packetDest; + MessageQueueIF& msgQueue; + StorageManagerIF* tcStore = nullptr; + StorageManagerIF* tmStore = nullptr; + etl::ilist& packetListRef; +}; + +class DestHandler { + public: + explicit DestHandler(DestHandlerParams params); + + ReturnValue_t performStateMachine(); + + ReturnValue_t passPacket(PacketInfo packet); + + ReturnValue_t initialize(); + + private: + DestHandlerParams p; + enum class TransactionStep { + IDLE = 0, + TRANSACTION_START = 1, + RECEIVING_FILE_DATA_PDUS = 2, + SENDING_ACK_PDU = 3, + TRANSFER_COMPLETION = 4, + SENDING_FINISHED_PDU = 5 + }; + TransactionStep step = TransactionStep::IDLE; }; } // namespace cfdp diff --git a/src/fsfw/container/DynamicFIFO.h b/src/fsfw/container/DynamicFIFO.h index 96f55938..5d1d46e7 100644 --- a/src/fsfw/container/DynamicFIFO.h +++ b/src/fsfw/container/DynamicFIFO.h @@ -18,7 +18,8 @@ template class DynamicFIFO : public FIFOBase { public: - DynamicFIFO(size_t maxCapacity) : FIFOBase(nullptr, maxCapacity), fifoVector(maxCapacity) { + explicit DynamicFIFO(size_t maxCapacity) + : FIFOBase(nullptr, maxCapacity), fifoVector(maxCapacity) { // trying to pass the pointer of the uninitialized vector // to the FIFOBase constructor directly lead to a super evil bug. // So we do it like this now. diff --git a/src/fsfw/container/FIFOBase.h b/src/fsfw/container/FIFOBase.h index 25c75515..db98a3f1 100644 --- a/src/fsfw/container/FIFOBase.h +++ b/src/fsfw/container/FIFOBase.h @@ -15,7 +15,7 @@ class FIFOBase { /** Default ctor, takes pointer to first entry of underlying container * and maximum capacity */ - FIFOBase(T* values, const size_t maxCapacity); + FIFOBase(T* values, size_t maxCapacity); /** * Insert value into FIFO @@ -60,7 +60,7 @@ class FIFOBase { * Get maximal capacity of fifo * @return size_t with max capacity of this fifo */ - size_t getMaxCapacity() const; + [[nodiscard]] size_t getMaxCapacity() const; protected: void setContainer(T* data); diff --git a/unittests/cfdp/handler/testDestHandler.cpp b/unittests/cfdp/handler/testDestHandler.cpp index 8189096d..1b2de95e 100644 --- a/unittests/cfdp/handler/testDestHandler.cpp +++ b/unittests/cfdp/handler/testDestHandler.cpp @@ -14,7 +14,7 @@ TEST_CASE("CFDP Dest Handler", "[cfdp]") { auto fsMock = FilesystemMock(); auto userMock = UserMock(fsMock); auto remoteCfgTableMock = RemoteConfigTableMock(); - auto destHandler = DestHandler(localEntityCfg, userMock, remoteCfgTableMock); + // auto destHandler = DestHandler(localEntityCfg, userMock, remoteCfgTableMock); SECTION("State") {} } \ No newline at end of file From d12c59c8acd9f7a59dfdfea04dbfe76dcae41836 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Mon, 22 Aug 2022 16:35:53 +0200 Subject: [PATCH 065/169] all retval replacements --- src/fsfw/cfdp/CfdpDistributor.cpp | 12 ++--- src/fsfw/cfdp/CfdpDistributor.h | 6 +-- src/fsfw/cfdp/CfdpHandler.h | 1 - src/fsfw/cfdp/handler/DestHandler.cpp | 12 ++--- src/fsfw/cfdp/pdu/AckPduDeserializer.cpp | 1 + src/fsfw/cfdp/pdu/FileDirectiveCreator.cpp | 6 +-- src/fsfw/cfdp/pdu/FileDirectiveReader.cpp | 4 +- src/fsfw/cfdp/pdu/HeaderCreator.cpp | 12 ++--- src/fsfw/cfdp/pdu/HeaderReader.cpp | 8 +-- src/fsfw/filesystem/HasFileSystemIF.h | 2 +- src/fsfw/tcdistribution/CcsdsDistributor.cpp | 20 ++++---- src/fsfw/tcdistribution/PusDistributor.cpp | 4 +- src/fsfw/tcdistribution/TcDistributorBase.cpp | 10 ++-- src/fsfw/tcdistribution/definitions.h | 2 +- src/fsfw_hal/host/HostFilesystem.cpp | 32 ++++++------ unittests/cfdp/handler/testDistributor.cpp | 32 ++++++------ unittests/cfdp/pdu/testCfdpHeader.cpp | 36 +++++++------- unittests/cfdp/pdu/testFileDirective.cpp | 10 ++-- unittests/cfdp/testLvs.cpp | 26 +++++----- unittests/cfdp/testOtherTlvs.cpp | 20 ++++---- unittests/cfdp/testTlv.cpp | 37 +++++++------- unittests/hal/testFsMock.cpp | 6 +-- unittests/hal/testHostFilesystem.cpp | 49 +++++++++---------- unittests/mocks/CcsdsCheckerMock.h | 2 +- unittests/mocks/FilesystemMock.cpp | 20 ++++---- unittests/mocks/StorageManagerMock.cpp | 8 +-- .../tcdistributor/testCcsdsDistributor.cpp | 33 +++++++------ 27 files changed, 204 insertions(+), 207 deletions(-) diff --git a/src/fsfw/cfdp/CfdpDistributor.cpp b/src/fsfw/cfdp/CfdpDistributor.cpp index e2377024..d0237959 100644 --- a/src/fsfw/cfdp/CfdpDistributor.cpp +++ b/src/fsfw/cfdp/CfdpDistributor.cpp @@ -9,24 +9,24 @@ ReturnValue_t CfdpDistributor::registerTcDestination(const cfdp::EntityId& addre AcceptsTelecommandsIF& tcDest) { for (const auto& dest : tcDestinations) { if (dest.id == address) { - return HasReturnvaluesIF::RETURN_FAILED; + return returnvalue::FAILED; } } tcDestinations.emplace_back(address, tcDest.getName(), tcDest.getRequestQueue()); - return HasReturnvaluesIF::RETURN_OK; + return returnvalue::OK; } ReturnValue_t CfdpDistributor::selectDestination(MessageQueueId_t& destId) { auto accessorPair = cfg.tcStore.getData(currentMessage.getStorageId()); - if (accessorPair.first != HasReturnvaluesIF::RETURN_OK) { + if (accessorPair.first != returnvalue::OK) { return accessorPair.first; } ReturnValue_t result = pduReader.setData(accessorPair.second.data(), accessorPair.second.size()); - if (result != HasReturnvaluesIF::RETURN_OK) { + if (result != returnvalue::OK) { return result; } result = pduReader.parseData(); - if (result != HasReturnvaluesIF::RETURN_OK) { + if (result != returnvalue::OK) { return result; } cfdp::EntityId foundId; @@ -44,7 +44,7 @@ ReturnValue_t CfdpDistributor::selectDestination(MessageQueueId_t& destId) { } // Packet was forwarded successfully, so do not delete it. accessorPair.second.release(); - return HasReturnvaluesIF::RETURN_OK; + return returnvalue::OK; } const char* CfdpDistributor::getName() const { return "CFDP Distributor"; } diff --git a/src/fsfw/cfdp/CfdpDistributor.h b/src/fsfw/cfdp/CfdpDistributor.h index 64c5ca9f..39ce0d27 100644 --- a/src/fsfw/cfdp/CfdpDistributor.h +++ b/src/fsfw/cfdp/CfdpDistributor.h @@ -5,7 +5,7 @@ #include #include "fsfw/cfdp/pdu/HeaderReader.h" -#include "fsfw/returnvalues/HasReturnvaluesIF.h" +#include "fsfw/returnvalues/returnvalue.h" #include "fsfw/tcdistribution/CfdpPacketChecker.h" #include "fsfw/tcdistribution/TcDistributorBase.h" #include "fsfw/tmtcpacket/cfdp/CfdpPacketStored.h" @@ -61,8 +61,8 @@ class CfdpDistributor : public TcDistributorBase, public AcceptsTelecommandsIF { MessageQueueId_t queueId; }; HeaderReader pduReader; - ReturnValue_t lastTcError = HasReturnvaluesIF::RETURN_OK; - ReturnValue_t lastTmError = HasReturnvaluesIF::RETURN_OK; + ReturnValue_t lastTcError = returnvalue::OK; + ReturnValue_t lastTmError = returnvalue::OK; // I don't think a regular OBSW will have more than 1 or 2 of these destinations, so I think // it is okay to accept the overhead here std::vector tcDestinations; diff --git a/src/fsfw/cfdp/CfdpHandler.h b/src/fsfw/cfdp/CfdpHandler.h index c81a6cf7..8c2827ec 100644 --- a/src/fsfw/cfdp/CfdpHandler.h +++ b/src/fsfw/cfdp/CfdpHandler.h @@ -61,4 +61,3 @@ //}; // //#endif /* FSFW_CFDP_CFDPHANDLER_H_ */ - diff --git a/src/fsfw/cfdp/handler/DestHandler.cpp b/src/fsfw/cfdp/handler/DestHandler.cpp index f04a4b12..85ef03f4 100644 --- a/src/fsfw/cfdp/handler/DestHandler.cpp +++ b/src/fsfw/cfdp/handler/DestHandler.cpp @@ -23,30 +23,30 @@ ReturnValue_t cfdp::DestHandler::performStateMachine() { case TransactionStep::SENDING_FINISHED_PDU: break; } - return HasReturnvaluesIF::RETURN_OK; + return returnvalue::OK; } ReturnValue_t cfdp::DestHandler::passPacket(PacketInfo packet) { if (p.packetListRef.full()) { - return HasReturnvaluesIF::RETURN_FAILED; + return returnvalue::FAILED; } p.packetListRef.push_back(packet); - return HasReturnvaluesIF::RETURN_OK; + return returnvalue::OK; } ReturnValue_t cfdp::DestHandler::initialize() { if (p.tmStore == nullptr) { p.tmStore = ObjectManager::instance()->get(objects::TM_STORE); if (p.tmStore == nullptr) { - return HasReturnvaluesIF::RETURN_FAILED; + return returnvalue::FAILED; } } if (p.tcStore == nullptr) { p.tcStore = ObjectManager::instance()->get(objects::TC_STORE); if (p.tcStore == nullptr) { - return HasReturnvaluesIF::RETURN_FAILED; + return returnvalue::FAILED; } } - return HasReturnvaluesIF::RETURN_OK; + return returnvalue::OK; } diff --git a/src/fsfw/cfdp/pdu/AckPduDeserializer.cpp b/src/fsfw/cfdp/pdu/AckPduDeserializer.cpp index 7e92ef9a..f09db97e 100644 --- a/src/fsfw/cfdp/pdu/AckPduDeserializer.cpp +++ b/src/fsfw/cfdp/pdu/AckPduDeserializer.cpp @@ -6,6 +6,7 @@ AckPduDeserializer::AckPduDeserializer(const uint8_t* pduBuf, size_t maxSize, Ac ReturnValue_t AckPduDeserializer::parseData() { ReturnValue_t result = FileDirectiveReader::parseData(); if (result != returnvalue::OK) { + return result; } size_t currentIdx = FileDirectiveReader::getHeaderSize(); if (currentIdx + 2 > this->maxSize) { diff --git a/src/fsfw/cfdp/pdu/FileDirectiveCreator.cpp b/src/fsfw/cfdp/pdu/FileDirectiveCreator.cpp index 169c2d5f..86c1ad92 100644 --- a/src/fsfw/cfdp/pdu/FileDirectiveCreator.cpp +++ b/src/fsfw/cfdp/pdu/FileDirectiveCreator.cpp @@ -12,13 +12,13 @@ size_t FileDirectiveCreator::getSerializedSize() const { ReturnValue_t FileDirectiveCreator::serialize(uint8_t **buffer, size_t *size, size_t maxSize, Endianness streamEndianness) const { if (buffer == nullptr or size == nullptr) { - return HasReturnvaluesIF::RETURN_FAILED; + return returnvalue::FAILED; } if (FileDirectiveCreator::getWholePduSize() > maxSize) { return BUFFER_TOO_SHORT; } ReturnValue_t result = HeaderCreator::serialize(buffer, size, maxSize, streamEndianness); - if (result != HasReturnvaluesIF::RETURN_OK) { + if (result != returnvalue::OK) { return result; } @@ -28,7 +28,7 @@ ReturnValue_t FileDirectiveCreator::serialize(uint8_t **buffer, size_t *size, si **buffer = directiveCode; *buffer += 1; *size += 1; - return HasReturnvaluesIF::RETURN_OK; + return returnvalue::OK; } void FileDirectiveCreator::setDirectiveDataFieldLen(size_t len) { diff --git a/src/fsfw/cfdp/pdu/FileDirectiveReader.cpp b/src/fsfw/cfdp/pdu/FileDirectiveReader.cpp index bc06a9d7..4099efd9 100644 --- a/src/fsfw/cfdp/pdu/FileDirectiveReader.cpp +++ b/src/fsfw/cfdp/pdu/FileDirectiveReader.cpp @@ -7,7 +7,7 @@ cfdp::FileDirectives FileDirectiveReader::getFileDirective() const { return file ReturnValue_t FileDirectiveReader::parseData() { ReturnValue_t result = HeaderReader::parseData(); - if (result != HasReturnvaluesIF::RETURN_OK) { + if (result != returnvalue::OK) { return result; } if (this->getPduDataFieldLen() < 1) { @@ -21,7 +21,7 @@ ReturnValue_t FileDirectiveReader::parseData() { return cfdp::INVALID_DIRECTIVE_FIELDS; } setFileDirective(static_cast(pointers.rawPtr[currentIdx])); - return HasReturnvaluesIF::RETURN_OK; + return returnvalue::OK; } size_t FileDirectiveReader::getHeaderSize() const { diff --git a/src/fsfw/cfdp/pdu/HeaderCreator.cpp b/src/fsfw/cfdp/pdu/HeaderCreator.cpp index 1a7afe0d..e64f8481 100644 --- a/src/fsfw/cfdp/pdu/HeaderCreator.cpp +++ b/src/fsfw/cfdp/pdu/HeaderCreator.cpp @@ -12,7 +12,7 @@ HeaderCreator::HeaderCreator(PduConfig &pduConf, cfdp::PduType pduType, size_t i ReturnValue_t HeaderCreator::serialize(uint8_t **buffer, size_t *size, size_t maxSize, Endianness streamEndianness) const { if (buffer == nullptr or size == nullptr) { - return HasReturnvaluesIF::RETURN_FAILED; + return returnvalue::FAILED; } if (maxSize < this->getSerializedSize()) { return BUFFER_TOO_SHORT; @@ -29,19 +29,19 @@ ReturnValue_t HeaderCreator::serialize(uint8_t **buffer, size_t *size, size_t ma *buffer += 1; *size += 4; ReturnValue_t result = pduConf.sourceId.serialize(buffer, size, maxSize, streamEndianness); - if (result != HasReturnvaluesIF::RETURN_OK) { + if (result != returnvalue::OK) { return result; } result = pduConf.seqNum.serialize(buffer, size, maxSize, streamEndianness); - if (result != HasReturnvaluesIF::RETURN_OK) { + if (result != returnvalue::OK) { return result; } result = pduConf.destId.serialize(buffer, size, maxSize, streamEndianness); - if (result != HasReturnvaluesIF::RETURN_OK) { + if (result != returnvalue::OK) { return result; } - return HasReturnvaluesIF::RETURN_OK; + return returnvalue::OK; } size_t HeaderCreator::getSerializedSize() const { @@ -51,7 +51,7 @@ size_t HeaderCreator::getSerializedSize() const { ReturnValue_t HeaderCreator::deSerialize(const uint8_t **buffer, size_t *size, Endianness streamEndianness) { // We could implement this, but I prefer dedicated classes - return HasReturnvaluesIF::RETURN_FAILED; + return returnvalue::FAILED; } size_t HeaderCreator::getWholePduSize() const { diff --git a/src/fsfw/cfdp/pdu/HeaderReader.cpp b/src/fsfw/cfdp/pdu/HeaderReader.cpp index 1fd40b78..f220ccd3 100644 --- a/src/fsfw/cfdp/pdu/HeaderReader.cpp +++ b/src/fsfw/cfdp/pdu/HeaderReader.cpp @@ -8,7 +8,7 @@ HeaderReader::HeaderReader(const uint8_t *pduBuf, size_t maxSize) { setData(pduB ReturnValue_t HeaderReader::parseData() { if (pointers.rawPtr == nullptr) { - return HasReturnvaluesIF::RETURN_FAILED; + return returnvalue::FAILED; } if (maxSize < 7) { return SerializeIF::STREAM_TOO_SHORT; @@ -20,19 +20,19 @@ ReturnValue_t HeaderReader::parseData() { cfdp::WidthInBytes widthSeqNum = getLenSeqNum(); seqNumRaw = static_cast(sourceIdRaw) + static_cast(widthEntityIds); destIdRaw = static_cast(seqNumRaw) + static_cast(widthSeqNum); - return HasReturnvaluesIF::RETURN_OK; + return returnvalue::OK; } ReturnValue_t HeaderReader::setData(uint8_t *dataPtr, size_t maxSize_, void *args) { if (dataPtr == nullptr) { - return HasReturnvaluesIF::RETURN_FAILED; + return returnvalue::FAILED; } if (maxSize_ < 7) { return SerializeIF::STREAM_TOO_SHORT; } pointers.rawPtr = dataPtr; maxSize = maxSize_; - return HasReturnvaluesIF::RETURN_OK; + return returnvalue::OK; } size_t HeaderReader::getHeaderSize() const { diff --git a/src/fsfw/filesystem/HasFileSystemIF.h b/src/fsfw/filesystem/HasFileSystemIF.h index 078de7c0..e7e2a529 100644 --- a/src/fsfw/filesystem/HasFileSystemIF.h +++ b/src/fsfw/filesystem/HasFileSystemIF.h @@ -7,7 +7,7 @@ #include "fsfw/ipc/MessageQueueIF.h" #include "fsfw/ipc/messageQueueDefinitions.h" #include "fsfw/returnvalues/FwClassIds.h" -#include "fsfw/returnvalues/HasReturnvaluesIF.h" +#include "fsfw/returnvalues/returnvalue.h" struct FilesystemParams { explicit FilesystemParams(const char* path) : path(path) {} diff --git a/src/fsfw/tcdistribution/CcsdsDistributor.cpp b/src/fsfw/tcdistribution/CcsdsDistributor.cpp index a2080ea8..4668a3bc 100644 --- a/src/fsfw/tcdistribution/CcsdsDistributor.cpp +++ b/src/fsfw/tcdistribution/CcsdsDistributor.cpp @@ -36,7 +36,7 @@ ReturnValue_t CcsdsDistributor::selectDestination(MessageQueueId_t& destId) { #endif auto accessorPair = tcStore->getData(currentMessage.getStorageId()); ReturnValue_t result = accessorPair.first; - if (result != HasReturnvaluesIF::RETURN_OK) { + if (result != returnvalue::OK) { #if FSFW_VERBOSE_LEVEL >= 1 #if FSFW_CPP_OSTREAM_ENABLED == 1 sif::error << "CCSDSDistributor::selectDestination: Getting data from" @@ -64,7 +64,7 @@ ReturnValue_t CcsdsDistributor::selectDestination(MessageQueueId_t& destId) { } SpacePacketReader currentPacket(accessorPair.second.data(), accessorPair.second.size()); result = packetChecker->checkPacket(currentPacket, accessorPair.second.size()); - if (result != HasReturnvaluesIF::RETURN_OK) { + if (result != returnvalue::OK) { handlePacketCheckFailure(result); return result; } @@ -90,7 +90,7 @@ ReturnValue_t CcsdsDistributor::selectDestination(MessageQueueId_t& destId) { return handleCcsdsHeaderRemoval(accessorPair.second); } accessorPair.second.release(); - return HasReturnvaluesIF::RETURN_OK; + return returnvalue::OK; } void CcsdsDistributor::handlePacketCheckFailure(ReturnValue_t result) { @@ -116,10 +116,10 @@ void CcsdsDistributor::handlePacketCheckFailure(ReturnValue_t result) { MessageQueueId_t CcsdsDistributor::getRequestQueue() const { return tcQueue->getId(); } ReturnValue_t CcsdsDistributor::registerApplication(DestInfo info) { - ReturnValue_t returnValue = RETURN_OK; + ReturnValue_t returnValue = returnvalue::OK; auto insertPair = receiverMap.emplace(info.apid, info); if (not insertPair.second) { - returnValue = RETURN_FAILED; + returnValue = returnvalue::FAILED; } return returnValue; } @@ -128,7 +128,7 @@ uint32_t CcsdsDistributor::getIdentifier() const { return 0; } ReturnValue_t CcsdsDistributor::initialize() { ReturnValue_t result = TcDistributorBase::initialize(); - if (result != HasReturnvaluesIF::RETURN_OK) { + if (result != returnvalue::OK) { return result; } if (packetChecker == nullptr) { @@ -156,10 +156,10 @@ ReturnValue_t CcsdsDistributor::initialize() { } ReturnValue_t CcsdsDistributor::callbackAfterSending(ReturnValue_t queueStatus) { - if (queueStatus != RETURN_OK) { + if (queueStatus != returnvalue::OK) { tcStore->deleteData(currentMessage.getStorageId()); } - return RETURN_OK; + return returnvalue::OK; } void CcsdsDistributor::print() { @@ -180,7 +180,7 @@ ReturnValue_t CcsdsDistributor::handleCcsdsHeaderRemoval(ConstStorageAccessor& a store_address_t newStoreId; ReturnValue_t result = tcStore->addData(&newStoreId, accessor.data() + ccsds::HEADER_LEN, accessor.size() - ccsds::HEADER_LEN); - if (result != HasReturnvaluesIF::RETURN_OK) { + if (result != returnvalue::OK) { #if FSFW_CPP_OSTREAM_ENABLED == 1 sif::error << __func__ << ": TC store full" << std::endl; #else @@ -190,5 +190,5 @@ ReturnValue_t CcsdsDistributor::handleCcsdsHeaderRemoval(ConstStorageAccessor& a } currentMessage.setStorageId(newStoreId); // The const accessor will delete the old data automatically - return HasReturnvaluesIF::RETURN_OK; + return returnvalue::OK; } diff --git a/src/fsfw/tcdistribution/PusDistributor.cpp b/src/fsfw/tcdistribution/PusDistributor.cpp index 352e32ff..7599114b 100644 --- a/src/fsfw/tcdistribution/PusDistributor.cpp +++ b/src/fsfw/tcdistribution/PusDistributor.cpp @@ -27,8 +27,8 @@ ReturnValue_t PusDistributor::selectDestination(MessageQueueId_t& destId) { // TODO: Need to set the data const uint8_t* packetPtr = nullptr; size_t packetLen = 0; - ReturnValue_t result = store->getData(currentMessage.getStorageId(), &packetPtr, &packetLen) != - returnvalue::OK; + ReturnValue_t result = + store->getData(currentMessage.getStorageId(), &packetPtr, &packetLen) != returnvalue::OK; if (result != returnvalue::OK) { tcStatus = PACKET_LOST; return result; diff --git a/src/fsfw/tcdistribution/TcDistributorBase.cpp b/src/fsfw/tcdistribution/TcDistributorBase.cpp index 230c97fb..f87993f8 100644 --- a/src/fsfw/tcdistribution/TcDistributorBase.cpp +++ b/src/fsfw/tcdistribution/TcDistributorBase.cpp @@ -20,11 +20,11 @@ TcDistributorBase::~TcDistributorBase() { ReturnValue_t TcDistributorBase::performOperation(uint8_t opCode) { ReturnValue_t status; - ReturnValue_t result = HasReturnvaluesIF::RETURN_OK; - for (status = tcQueue->receiveMessage(¤tMessage); status == RETURN_OK; + ReturnValue_t result = returnvalue::OK; + for (status = tcQueue->receiveMessage(¤tMessage); status == returnvalue::OK; status = tcQueue->receiveMessage(¤tMessage)) { ReturnValue_t packetResult = handlePacket(); - if (packetResult != HasReturnvaluesIF::RETURN_OK) { + if (packetResult != returnvalue::OK) { result = packetResult; triggerEvent(tmtcdistrib::HANDLE_PACKET_FAILED, packetResult, 1); } @@ -38,12 +38,12 @@ ReturnValue_t TcDistributorBase::performOperation(uint8_t opCode) { ReturnValue_t TcDistributorBase::handlePacket() { MessageQueueId_t destId; ReturnValue_t result = selectDestination(destId); - if (result != HasReturnvaluesIF::RETURN_OK) { + if (result != returnvalue::OK) { return result; } return callbackAfterSending(tcQueue->sendMessage(destId, ¤tMessage)); } ReturnValue_t TcDistributorBase::callbackAfterSending(ReturnValue_t queueStatus) { - return RETURN_OK; + return returnvalue::OK; } diff --git a/src/fsfw/tcdistribution/definitions.h b/src/fsfw/tcdistribution/definitions.h index d28f9d40..01fc3085 100644 --- a/src/fsfw/tcdistribution/definitions.h +++ b/src/fsfw/tcdistribution/definitions.h @@ -10,7 +10,7 @@ namespace tmtcdistrib { static const uint8_t INTERFACE_ID = CLASS_ID::TMTC_DISTRIBUTION; -static constexpr ReturnValue_t NO_DESTINATION_FOUND = result::makeCode(INTERFACE_ID, 0); +static constexpr ReturnValue_t NO_DESTINATION_FOUND = returnvalue::makeCode(INTERFACE_ID, 0); static constexpr ReturnValue_t INVALID_CCSDS_VERSION = MAKE_RETURN_CODE(1); static constexpr ReturnValue_t INVALID_APID = MAKE_RETURN_CODE(2); static constexpr ReturnValue_t INVALID_PACKET_TYPE = MAKE_RETURN_CODE(3); diff --git a/src/fsfw_hal/host/HostFilesystem.cpp b/src/fsfw_hal/host/HostFilesystem.cpp index 7ebe5df8..20678a8c 100644 --- a/src/fsfw_hal/host/HostFilesystem.cpp +++ b/src/fsfw_hal/host/HostFilesystem.cpp @@ -12,7 +12,7 @@ HostFilesystem::HostFilesystem() = default; ReturnValue_t HostFilesystem::writeToFile(FileOpParams params, const uint8_t *data) { if (params.path() == nullptr) { - return HasReturnvaluesIF::RETURN_FAILED; + return returnvalue::FAILED; } path path(params.path()); if (not exists(path)) { @@ -24,13 +24,13 @@ ReturnValue_t HostFilesystem::writeToFile(FileOpParams params, const uint8_t *da } file.seekp(static_cast(params.offset)); file.write(reinterpret_cast(data), static_cast(params.size)); - return HasReturnvaluesIF::RETURN_OK; + return returnvalue::OK; } ReturnValue_t HostFilesystem::readFromFile(FileOpParams params, uint8_t **buffer, size_t &readSize, size_t maxSize) { if (params.path() == nullptr) { - return HasReturnvaluesIF::RETURN_FAILED; + return returnvalue::FAILED; } path path(params.path()); if (not exists(path)) { @@ -48,13 +48,13 @@ ReturnValue_t HostFilesystem::readFromFile(FileOpParams params, uint8_t **buffer file.read(reinterpret_cast(*buffer), sizeToRead); readSize += sizeToRead; *buffer += sizeToRead; - return HasReturnvaluesIF::RETURN_OK; + return returnvalue::OK; } ReturnValue_t HostFilesystem::createFile(FilesystemParams params, const uint8_t *data, size_t size) { if (params.path == nullptr) { - return HasReturnvaluesIF::RETURN_FAILED; + return returnvalue::FAILED; } path path(params.path); if (exists(path)) { @@ -64,26 +64,26 @@ ReturnValue_t HostFilesystem::createFile(FilesystemParams params, const uint8_t if (file.fail()) { return HasFileSystemIF::GENERIC_FILE_ERROR; } - return HasReturnvaluesIF::RETURN_OK; + return returnvalue::OK; } ReturnValue_t HostFilesystem::removeFile(const char *path_, FileSystemArgsIF *args) { if (path_ == nullptr) { - return HasReturnvaluesIF::RETURN_FAILED; + return returnvalue::FAILED; } path path(path_); if (not exists(path)) { return HasFileSystemIF::FILE_DOES_NOT_EXIST; } if (remove(path, errorCode)) { - return HasReturnvaluesIF::RETURN_OK; + return returnvalue::OK; } return HasFileSystemIF::GENERIC_FILE_ERROR; } ReturnValue_t HostFilesystem::createDirectory(FilesystemParams params, bool createParentDirs) { if (params.path == nullptr) { - return HasReturnvaluesIF::RETURN_FAILED; + return returnvalue::FAILED; } path dirPath(params.path); @@ -93,19 +93,19 @@ ReturnValue_t HostFilesystem::createDirectory(FilesystemParams params, bool crea if (createParentDirs) { if (create_directories(dirPath, errorCode)) { - return HasReturnvaluesIF::RETURN_OK; + return returnvalue::OK; } return HasFileSystemIF::GENERIC_DIR_ERROR; } if (create_directory(dirPath, errorCode)) { - return HasReturnvaluesIF::RETURN_OK; + return returnvalue::OK; } return HasFileSystemIF::GENERIC_DIR_ERROR; } ReturnValue_t HostFilesystem::removeDirectory(FilesystemParams params, bool deleteRecurively) { if (params.path == nullptr) { - return HasReturnvaluesIF::RETURN_FAILED; + return returnvalue::FAILED; } path dirPath(params.path); if (not exists(dirPath)) { @@ -116,11 +116,11 @@ ReturnValue_t HostFilesystem::removeDirectory(FilesystemParams params, bool dele } if (deleteRecurively) { if (remove_all(dirPath, errorCode)) { - return HasReturnvaluesIF::RETURN_OK; + return returnvalue::OK; } } else { if (remove(dirPath, errorCode)) { - return HasReturnvaluesIF::RETURN_OK; + return returnvalue::OK; } } // Error handling @@ -133,7 +133,7 @@ ReturnValue_t HostFilesystem::removeDirectory(FilesystemParams params, bool dele ReturnValue_t HostFilesystem::rename(const char *oldPath_, const char *newPath_, FileSystemArgsIF *args) { if (oldPath_ == nullptr or newPath_ == nullptr) { - return HasReturnvaluesIF::RETURN_FAILED; + return returnvalue::FAILED; } path oldPath(oldPath_); path newPath(newPath_); @@ -142,5 +142,5 @@ ReturnValue_t HostFilesystem::rename(const char *oldPath_, const char *newPath_, if (errorCode) { return HasFileSystemIF::GENERIC_RENAME_ERROR; } - return HasReturnvaluesIF::RETURN_OK; + return returnvalue::OK; } diff --git a/unittests/cfdp/handler/testDistributor.cpp b/unittests/cfdp/handler/testDistributor.cpp index 161e21cc..368ca9c0 100644 --- a/unittests/cfdp/handler/testDistributor.cpp +++ b/unittests/cfdp/handler/testDistributor.cpp @@ -36,41 +36,41 @@ TEST_CASE("CFDP Distributor", "[cfdp][distributor]") { uint8_t* dataPtr = nullptr; SECTION("State") { - CHECK(distributor.initialize() == result::OK); + CHECK(distributor.initialize() == returnvalue::OK); CHECK(std::strcmp(distributor.getName(), "CFDP Distributor") == 0); CHECK(distributor.getIdentifier() == 0); CHECK(distributor.getRequestQueue() == queue.getId()); } SECTION("Packet Forwarding") { - CHECK(distributor.initialize() == result::OK); - CHECK(distributor.registerTcDestination(obswEntityId, tcAcceptor) == result::OK); + CHECK(distributor.initialize() == returnvalue::OK); + CHECK(distributor.registerTcDestination(obswEntityId, tcAcceptor) == returnvalue::OK); size_t serLen = 0; store_address_t storeId; CHECK(pool.LocalPool::getFreeElement(&storeId, creator.getSerializedSize(), &dataPtr) == - result::OK); + returnvalue::OK); REQUIRE(creator.SerializeIF::serializeBe(dataPtr, serLen, creator.getSerializedSize()) == - result::OK); + returnvalue::OK); TmTcMessage msg(storeId); queue.addReceivedMessage(msg); - CHECK(distributor.performOperation(0) == result::OK); + CHECK(distributor.performOperation(0) == returnvalue::OK); CHECK(queue.wasMessageSent()); CHECK(queue.numberOfSentMessages() == 1); // The packet is forwarded, with no need to delete the data CHECK(pool.hasDataAtId(storeId)); TmTcMessage sentMsg; - CHECK(queue.getNextSentMessage(receiverQueueId, sentMsg) == result::OK); + CHECK(queue.getNextSentMessage(receiverQueueId, sentMsg) == returnvalue::OK); CHECK(sentMsg.getStorageId() == storeId); } SECTION("No Destination found") { - CHECK(distributor.initialize() == result::OK); + CHECK(distributor.initialize() == returnvalue::OK); size_t serLen = 0; store_address_t storeId; CHECK(pool.LocalPool::getFreeElement(&storeId, creator.getSerializedSize(), &dataPtr) == - result::OK); + returnvalue::OK); REQUIRE(creator.SerializeIF::serializeBe(dataPtr, serLen, creator.getSerializedSize()) == - result::OK); + returnvalue::OK); TmTcMessage msg(storeId); queue.addReceivedMessage(msg); CHECK(distributor.performOperation(0) == tmtcdistrib::NO_DESTINATION_FOUND); @@ -81,19 +81,19 @@ TEST_CASE("CFDP Distributor", "[cfdp][distributor]") { pool.nextModifyDataCallFails.second = StorageManagerIF::DATA_DOES_NOT_EXIST; size_t serLen = 0; store_address_t storeId; - CHECK(distributor.registerTcDestination(obswEntityId, tcAcceptor) == result::OK); + CHECK(distributor.registerTcDestination(obswEntityId, tcAcceptor) == returnvalue::OK); CHECK(pool.LocalPool::getFreeElement(&storeId, creator.getSerializedSize(), &dataPtr) == - result::OK); + returnvalue::OK); REQUIRE(creator.SerializeIF::serializeBe(dataPtr, serLen, creator.getSerializedSize()) == - result::OK); + returnvalue::OK); TmTcMessage msg(storeId); queue.addReceivedMessage(msg); CHECK(distributor.performOperation(0) == StorageManagerIF::DATA_DOES_NOT_EXIST); } SECTION("Duplicate registration") { - CHECK(distributor.initialize() == result::OK); - CHECK(distributor.registerTcDestination(obswEntityId, tcAcceptor) == result::OK); - CHECK(distributor.registerTcDestination(obswEntityId, tcAcceptor) == result::FAILED); + CHECK(distributor.initialize() == returnvalue::OK); + CHECK(distributor.registerTcDestination(obswEntityId, tcAcceptor) == returnvalue::OK); + CHECK(distributor.registerTcDestination(obswEntityId, tcAcceptor) == returnvalue::FAILED); } } \ No newline at end of file diff --git a/unittests/cfdp/pdu/testCfdpHeader.cpp b/unittests/cfdp/pdu/testCfdpHeader.cpp index a01325fa..99a0c470 100644 --- a/unittests/cfdp/pdu/testCfdpHeader.cpp +++ b/unittests/cfdp/pdu/testCfdpHeader.cpp @@ -3,7 +3,7 @@ #include "fsfw/cfdp/pdu/HeaderCreator.h" #include "fsfw/cfdp/pdu/HeaderReader.h" -#include "fsfw/returnvalues/HasReturnvaluesIF.h" +#include "fsfw/returnvalues/returnvalue.h" TEST_CASE("CFDP Header", "[cfdp]") { using namespace cfdp; @@ -49,12 +49,12 @@ TEST_CASE("CFDP Header", "[cfdp]") { SECTION("Deserialization fails") { const uint8_t** dummyPtr = nullptr; REQUIRE(headerSerializer.deSerialize(dummyPtr, &serSize, SerializeIF::Endianness::NETWORK) == - result::FAILED); + returnvalue::FAILED); } SECTION("Serialization fails") { REQUIRE(headerSerializer.serialize(nullptr, &serSize, serBuf.size(), - SerializeIF::Endianness::NETWORK) == result::FAILED); + SerializeIF::Endianness::NETWORK) == returnvalue::FAILED); } SECTION("Buffer Too Short") { @@ -93,7 +93,7 @@ TEST_CASE("CFDP Header", "[cfdp]") { SECTION("Regular") { // Everything except version bit flipped to one now REQUIRE(headerSerializer.serialize(&serTarget, &serSize, serBuf.size(), - SerializeIF::Endianness::BIG) == result::OK); + SerializeIF::Endianness::BIG) == returnvalue::OK); CHECK(serBuf[0] == 0x3f); CHECK(serBuf[3] == 0x99); REQUIRE(headerSerializer.getCrcFlag() == true); @@ -114,7 +114,7 @@ TEST_CASE("CFDP Header", "[cfdp]") { REQUIRE(pduConf.sourceId.getSerializedSize() == 4); REQUIRE(headerSerializer.getSerializedSize() == 14); REQUIRE(headerSerializer.serialize(&serTarget, &serSize, serBuf.size(), - SerializeIF::Endianness::BIG) == result::OK); + SerializeIF::Endianness::BIG) == returnvalue::OK); REQUIRE(headerSerializer.getCrcFlag() == true); REQUIRE(headerSerializer.getDirection() == cfdp::Direction::TOWARDS_SENDER); REQUIRE(headerSerializer.getLargeFileFlag() == true); @@ -157,17 +157,17 @@ TEST_CASE("CFDP Header", "[cfdp]") { SECTION("Invalid Variable Sized Fields") { result = pduConf.sourceId.setValue(cfdp::WidthInBytes::ONE_BYTE, 0xfff); - REQUIRE(result == result::FAILED); + REQUIRE(result == returnvalue::FAILED); result = pduConf.sourceId.setValue(cfdp::WidthInBytes::TWO_BYTES, 0xfffff); - REQUIRE(result == result::FAILED); + REQUIRE(result == returnvalue::FAILED); result = pduConf.sourceId.setValue(cfdp::WidthInBytes::FOUR_BYTES, 0xfffffffff); - REQUIRE(result == result::FAILED); + REQUIRE(result == returnvalue::FAILED); } SECTION("Header Serialization") { result = headerSerializer.serialize(&serTarget, &serSize, serBuf.size(), SerializeIF::Endianness::BIG); - REQUIRE(result == result::OK); + REQUIRE(result == returnvalue::OK); REQUIRE(serSize == 7); // Only version bits are set REQUIRE(serBuf[0] == 0b00100000); @@ -216,7 +216,7 @@ TEST_CASE("CFDP Header", "[cfdp]") { SECTION("Header Deserialization") { REQUIRE(headerSerializer.serialize(&serTarget, &serSize, serBuf.size(), - SerializeIF::Endianness::BIG) == result::OK); + SerializeIF::Endianness::BIG) == returnvalue::OK); REQUIRE(serBuf[1] == 0); REQUIRE(serBuf[2] == 0); // Entity and Transaction Sequence number are 1 byte large @@ -226,7 +226,7 @@ TEST_CASE("CFDP Header", "[cfdp]") { auto headerDeser = HeaderReader(serBuf.data(), serBuf.size()); ReturnValue_t serResult = headerDeser.parseData(); - REQUIRE(serResult == result::OK); + REQUIRE(serResult == returnvalue::OK); REQUIRE(headerDeser.getPduDataFieldLen() == 0); REQUIRE(headerDeser.getHeaderSize() == 7); REQUIRE(headerDeser.getWholePduSize() == 7); @@ -249,11 +249,11 @@ TEST_CASE("CFDP Header", "[cfdp]") { headerSerializer.setPduType(cfdp::PduType::FILE_DATA); headerSerializer.setSegmentMetadataFlag(cfdp::SegmentMetadataFlag::PRESENT); result = pduConf.seqNum.setValue(cfdp::WidthInBytes::TWO_BYTES, 0x0fff); - REQUIRE(result == result::OK); + REQUIRE(result == returnvalue::OK); result = pduConf.sourceId.setValue(cfdp::WidthInBytes::FOUR_BYTES, 0xff00ff00); - REQUIRE(result == result::OK); + REQUIRE(result == returnvalue::OK); result = pduConf.destId.setValue(cfdp::WidthInBytes::FOUR_BYTES, 0x00ff00ff); - REQUIRE(result == result::OK); + REQUIRE(result == returnvalue::OK); serTarget = serBuf.data(); serSize = 0; result = headerSerializer.serialize(&serTarget, &serSize, serBuf.size(), @@ -261,7 +261,7 @@ TEST_CASE("CFDP Header", "[cfdp]") { headerDeser = HeaderReader(serBuf.data(), serBuf.size()); result = headerDeser.parseData(); - REQUIRE(result == result::OK); + REQUIRE(result == returnvalue::OK); // Everything except version bit flipped to one now REQUIRE(serBuf[0] == 0x3f); REQUIRE(serBuf[3] == 0b11001010); @@ -293,9 +293,9 @@ TEST_CASE("CFDP Header", "[cfdp]") { serTarget = serBuf.data(); const auto** serTargetConst = const_cast(&serTarget); result = headerDeser.parseData(); - REQUIRE(result == result::OK); + REQUIRE(result == returnvalue::OK); - CHECK(headerDeser.setData(nullptr, -1) != result::OK); + CHECK(headerDeser.setData(nullptr, -1) != returnvalue::OK); REQUIRE(headerDeser.getHeaderSize() == 14); headerDeser.setData(serBuf.data(), serBuf.size()); @@ -305,7 +305,7 @@ TEST_CASE("CFDP Header", "[cfdp]") { pduConf.destId.setValue(cfdp::WidthInBytes::ONE_BYTE, 48); result = headerSerializer.serialize(&serTarget, &serSize, serBuf.size(), SerializeIF::Endianness::BIG); - REQUIRE(result == result::OK); + REQUIRE(result == returnvalue::OK); REQUIRE(headerDeser.getWholePduSize() == 8); headerDeser.setData(serBuf.data(), serBuf.size()); diff --git a/unittests/cfdp/pdu/testFileDirective.cpp b/unittests/cfdp/pdu/testFileDirective.cpp index 3dfaaa57..3af8b966 100644 --- a/unittests/cfdp/pdu/testFileDirective.cpp +++ b/unittests/cfdp/pdu/testFileDirective.cpp @@ -23,7 +23,7 @@ TEST_CASE("CFDP File Directive", "[cfdp][pdu]") { serTarget = serBuf.data(); serSize = 0; result = fdSer.serialize(&serTarget, &serSize, serBuf.size(), SerializeIF::Endianness::NETWORK); - REQUIRE(result == HasReturnvaluesIF::RETURN_OK); + REQUIRE(result == returnvalue::OK); // Only version bits are set REQUIRE(serBuf[0] == 0b00100000); // PDU data field length is 5 (4 + Directive code octet) @@ -42,7 +42,7 @@ TEST_CASE("CFDP File Directive", "[cfdp][pdu]") { SECTION("Serialization fails") { REQUIRE(fdSer.serialize(nullptr, nullptr, 85, SerializeIF::Endianness::NETWORK) == - HasReturnvaluesIF::RETURN_FAILED); + returnvalue::FAILED); } SECTION("Buffer Too Short") { @@ -56,11 +56,11 @@ TEST_CASE("CFDP File Directive", "[cfdp][pdu]") { SECTION("Deserialize") { CHECK(fdSer.serialize(&serTarget, &serSize, serBuf.size(), SerializeIF::Endianness::NETWORK) == - result::OK); + returnvalue::OK); serTarget = serBuf.data(); REQUIRE(fdSer.deSerialize(&deserTarget, &serSize, SerializeIF::Endianness::NETWORK) == - HasReturnvaluesIF::RETURN_FAILED); + returnvalue::FAILED); deserTarget = serBuf.data(); CHECK(serSize == 8); auto fdDeser = FileDirectiveReader(deserTarget, serBuf.size()); @@ -70,7 +70,7 @@ TEST_CASE("CFDP File Directive", "[cfdp][pdu]") { fdDeser.setEndianness(SerializeIF::Endianness::MACHINE); REQUIRE(fdDeser.getEndianness() == SerializeIF::Endianness::MACHINE); fdDeser.setEndianness(SerializeIF::Endianness::NETWORK); - REQUIRE(fdDeser.parseData() == HasReturnvaluesIF::RETURN_OK); + REQUIRE(fdDeser.parseData() == returnvalue::OK); REQUIRE(not fdDeser.isNull()); REQUIRE(fdDeser); REQUIRE(fdDeser.getFileDirective() == FileDirectives::ACK); diff --git a/unittests/cfdp/testLvs.cpp b/unittests/cfdp/testLvs.cpp index 2adc84b8..062281e5 100644 --- a/unittests/cfdp/testLvs.cpp +++ b/unittests/cfdp/testLvs.cpp @@ -5,7 +5,7 @@ TEST_CASE("CFDP LV", "[cfdp][lv]") { using namespace cfdp; - ReturnValue_t result = result::OK; + ReturnValue_t result = returnvalue::OK; std::array rawBuf{}; uint8_t* serPtr = rawBuf.data(); const uint8_t* deserPtr = rawBuf.data(); @@ -16,7 +16,7 @@ TEST_CASE("CFDP LV", "[cfdp][lv]") { std::array lvRawBuf{}; serPtr = lvRawBuf.data(); REQUIRE(sourceId.serialize(&serPtr, &deserSize, lvRawBuf.size(), - SerializeIF::Endianness::NETWORK) == result::OK); + SerializeIF::Endianness::NETWORK) == returnvalue::OK); REQUIRE(deserSize == 2); auto lv = cfdp::Lv(lvRawBuf.data(), 2); @@ -31,12 +31,12 @@ TEST_CASE("CFDP LV", "[cfdp][lv]") { serPtr = rawBuf.data(); deserSize = 0; REQUIRE(lv.serialize(&serPtr, &deserSize, rawBuf.size(), SerializeIF::Endianness::NETWORK) == - result::OK); + returnvalue::OK); REQUIRE(deserSize == 3); REQUIRE(rawBuf[0] == 2); uint16_t sourceIdRaw = 0; REQUIRE(SerializeAdapter::deSerialize(&sourceIdRaw, rawBuf.data() + 1, &deserSize, - SerializeIF::Endianness::BIG) == result::OK); + SerializeIF::Endianness::BIG) == returnvalue::OK); REQUIRE(sourceIdRaw == 0x0ff0); } @@ -47,11 +47,11 @@ TEST_CASE("CFDP LV", "[cfdp][lv]") { deserSize = 0; result = lvEmpty.serialize(&serPtr, &deserSize, rawBuf.size(), SerializeIF::Endianness::NETWORK); - REQUIRE(result == HasReturnvaluesIF::RETURN_OK); + REQUIRE(result == returnvalue::OK); REQUIRE(deserSize == 1); deserPtr = rawBuf.data(); result = lvEmpty.deSerialize(&deserPtr, &deserSize, SerializeIF::Endianness::BIG); - REQUIRE(result == HasReturnvaluesIF::RETURN_OK); + REQUIRE(result == returnvalue::OK); REQUIRE(lvEmpty.getSerializedSize() == 1); } @@ -59,29 +59,29 @@ TEST_CASE("CFDP LV", "[cfdp][lv]") { std::array lvRawBuf{}; serPtr = lvRawBuf.data(); REQUIRE(sourceId.serialize(&serPtr, &deserSize, lvRawBuf.size(), - SerializeIF::Endianness::NETWORK) == result::OK); + SerializeIF::Endianness::NETWORK) == returnvalue::OK); auto lv = cfdp::Lv(lvRawBuf.data(), 2); serPtr = rawBuf.data(); deserSize = 0; result = lv.serialize(&serPtr, &deserSize, rawBuf.size(), SerializeIF::Endianness::NETWORK); - REQUIRE(result == HasReturnvaluesIF::RETURN_OK); + REQUIRE(result == returnvalue::OK); Lv uninitLv; deserPtr = rawBuf.data(); deserSize = 3; result = uninitLv.deSerialize(&deserPtr, &deserSize, SerializeIF::Endianness::BIG); - REQUIRE(result == HasReturnvaluesIF::RETURN_OK); + REQUIRE(result == returnvalue::OK); REQUIRE(uninitLv.getSerializedSize() == 3); const uint8_t* storedValue = uninitLv.getValue(nullptr); uint16_t sourceIdRaw = 0; REQUIRE(SerializeAdapter::deSerialize(&sourceIdRaw, storedValue, &deserSize, - SerializeIF::Endianness::BIG) == result::OK); + SerializeIF::Endianness::BIG) == returnvalue::OK); REQUIRE(sourceIdRaw == 0x0ff0); } SECTION("Invalid Input") { Lv uninitLv; REQUIRE(uninitLv.deSerialize(nullptr, nullptr, SerializeIF::Endianness::BIG) == - HasReturnvaluesIF::RETURN_FAILED); + returnvalue::FAILED); serPtr = rawBuf.data(); deserSize = 0; REQUIRE(uninitLv.serialize(&serPtr, &deserSize, 0, SerializeIF::Endianness::BIG) == @@ -96,7 +96,7 @@ TEST_CASE("CFDP LV", "[cfdp][lv]") { std::string filename = "hello.txt"; StringLv sourceFileName(filename); REQUIRE(sourceFileName.getSerializedSize() == 1 + filename.size()); - REQUIRE(sourceFileName.serializeBe(rawBuf.data(), deserSize, rawBuf.size()) == result::OK); + REQUIRE(sourceFileName.serializeBe(rawBuf.data(), deserSize, rawBuf.size()) == returnvalue::OK); REQUIRE(rawBuf[0] == filename.size()); std::string filenameFromRaw(reinterpret_cast(rawBuf.data() + 1), filename.size()); REQUIRE(filenameFromRaw == filename); @@ -106,7 +106,7 @@ TEST_CASE("CFDP LV", "[cfdp][lv]") { const char filename[] = "hello.txt"; StringLv sourceFileName(filename, sizeof(filename) - 1); REQUIRE(sourceFileName.getSerializedSize() == 1 + sizeof(filename) - 1); - REQUIRE(sourceFileName.serializeBe(rawBuf.data(), deserSize, rawBuf.size()) == result::OK); + REQUIRE(sourceFileName.serializeBe(rawBuf.data(), deserSize, rawBuf.size()) == returnvalue::OK); REQUIRE(rawBuf[0] == sizeof(filename) - 1); rawBuf[deserSize] = '\0'; const char* filenameFromRaw = reinterpret_cast(rawBuf.data() + 1); diff --git a/unittests/cfdp/testOtherTlvs.cpp b/unittests/cfdp/testOtherTlvs.cpp index 6393c230..4eb51a7c 100644 --- a/unittests/cfdp/testOtherTlvs.cpp +++ b/unittests/cfdp/testOtherTlvs.cpp @@ -40,14 +40,14 @@ TEST_CASE("CFDP Other TLVs", "[cfdp][tlv]") { std::array serBuf = {}; result = response.convertToTlv(rawResponse, serBuf.data(), serBuf.size(), SerializeIF::Endianness::NETWORK); - REQUIRE(result == HasReturnvaluesIF::RETURN_OK); + REQUIRE(result == returnvalue::OK); REQUIRE(rawResponse.getType() == cfdp::TlvTypes::FILESTORE_RESPONSE); cfdp::StringLv emptyMsg; cfdp::StringLv emptySecondName; FilestoreResponseTlv emptyTlv(firstName, &emptyMsg); emptyTlv.setSecondFileName(&emptySecondName); result = emptyTlv.deSerialize(rawResponse, SerializeIF::Endianness::NETWORK); - REQUIRE(result == HasReturnvaluesIF::RETURN_OK); + REQUIRE(result == returnvalue::OK); REQUIRE(emptyTlv.getActionCode() == cfdp::FilestoreActionCode::APPEND_FILE); REQUIRE(emptyTlv.getStatusCode() == cfdp::FSR_SUCCESS); size_t firstNameLen = 0; @@ -81,26 +81,26 @@ TEST_CASE("CFDP Other TLVs", "[cfdp][tlv]") { REQUIRE(expectedSz == 10 + 11 + 1); REQUIRE(request.getSerializedSize() == expectedSz + 2); result = request.serialize(&ptr, &sz, serBuf.size(), SerializeIF::Endianness::NETWORK); - REQUIRE(result == HasReturnvaluesIF::RETURN_OK); + REQUIRE(result == returnvalue::OK); REQUIRE(sz == expectedSz + 2); FilestoreRequestTlv emptyRequest(firstName); emptyRequest.setSecondFileName(&secondName); const uint8_t* constptr = serBuf.data(); result = emptyRequest.deSerialize(&constptr, &sz, SerializeIF::Endianness::NETWORK); - REQUIRE(result == HasReturnvaluesIF::RETURN_OK); + REQUIRE(result == returnvalue::OK); cfdp::Tlv rawRequest; ptr = serBuf.data(); sz = 0; result = request.convertToTlv(rawRequest, serBuf.data(), serBuf.size(), SerializeIF::Endianness::NETWORK); - REQUIRE(result == HasReturnvaluesIF::RETURN_OK); + REQUIRE(result == returnvalue::OK); REQUIRE(rawRequest.getType() == cfdp::TlvTypes::FILESTORE_REQUEST); emptyRequest.setActionCode(cfdp::FilestoreActionCode::DELETE_FILE); result = emptyRequest.deSerialize(rawRequest, SerializeIF::Endianness::NETWORK); - REQUIRE(result == HasReturnvaluesIF::RETURN_OK); + REQUIRE(result == returnvalue::OK); REQUIRE(emptyRequest.getType() == cfdp::TlvTypes::FILESTORE_REQUEST); REQUIRE(emptyRequest.getActionCode() == cfdp::FilestoreActionCode::APPEND_FILE); } @@ -117,11 +117,11 @@ TEST_CASE("CFDP Other TLVs", "[cfdp][tlv]") { faultOverrideTlv.serialize(&serPtr, &sz, rawBuf.size(), SerializeIF::Endianness::NETWORK); REQUIRE(faultOverrideTlv.getSerializedSize() == 3); REQUIRE(sz == 3); - REQUIRE(result == HasReturnvaluesIF::RETURN_OK); + REQUIRE(result == returnvalue::OK); FaultHandlerOverrideTlv emptyOverrideTlv; result = emptyOverrideTlv.deSerialize(&deserPtr, &sz, SerializeIF::Endianness::NETWORK); - REQUIRE(result == HasReturnvaluesIF::RETURN_OK); + REQUIRE(result == returnvalue::OK); EntityId entId(cfdp::WidthInBytes::TWO_BYTES, 0x42); EntityId emptyId; @@ -129,9 +129,9 @@ TEST_CASE("CFDP Other TLVs", "[cfdp][tlv]") { serPtr = rawBuf.data(); result = idTlv.serialize(&serPtr, &deserSize, rawBuf.size(), SerializeIF::Endianness::NETWORK); cfdp::Tlv rawTlv(cfdp::TlvTypes::ENTITY_ID, rawBuf.data() + 2, 2); - REQUIRE(result == HasReturnvaluesIF::RETURN_OK); + REQUIRE(result == returnvalue::OK); deserPtr = rawBuf.data(); result = idTlv.deSerialize(rawTlv, SerializeIF::Endianness::NETWORK); - REQUIRE(result == HasReturnvaluesIF::RETURN_OK); + REQUIRE(result == returnvalue::OK); } } diff --git a/unittests/cfdp/testTlv.cpp b/unittests/cfdp/testTlv.cpp index 5b6e0a63..3e7435cd 100644 --- a/unittests/cfdp/testTlv.cpp +++ b/unittests/cfdp/testTlv.cpp @@ -14,25 +14,25 @@ TEST_CASE("CFDP TLV", "[cfdp][tlv]") { SECTION("Entity ID Serialization") { REQUIRE(sourceId.serialize(&serPtr, &deserSize, rawBuf.size(), - SerializeIF::Endianness::NETWORK) == result::OK); + SerializeIF::Endianness::NETWORK) == returnvalue::OK); REQUIRE(deserSize == 2); } SECTION("TLV Serialization") { std::array tlvBuf{}; - REQUIRE(sourceId.serializeBe(tlvBuf.data(), deserSize, tlvBuf.size()) == result::OK); + REQUIRE(sourceId.serializeBe(tlvBuf.data(), deserSize, tlvBuf.size()) == returnvalue::OK); auto tlv = Tlv(TlvTypes::ENTITY_ID, tlvBuf.data(), deserSize); REQUIRE(tlv.getSerializedSize() == 4); REQUIRE(tlv.getLengthField() == 2); deserSize = 0; REQUIRE(tlv.serialize(&serPtr, &deserSize, rawBuf.size(), SerializeIF::Endianness::NETWORK) == - result::OK); + returnvalue::OK); REQUIRE(deserSize == 4); REQUIRE(rawBuf[0] == TlvTypes::ENTITY_ID); REQUIRE(rawBuf[1] == 2); uint16_t entityId = 0; REQUIRE(SerializeAdapter::deSerialize(&entityId, rawBuf.data() + 2, &deserSize, - SerializeIF::Endianness::NETWORK) == result::OK); + SerializeIF::Endianness::NETWORK) == returnvalue::OK); REQUIRE(entityId == 0x0ff0); } @@ -41,30 +41,30 @@ TEST_CASE("CFDP TLV", "[cfdp][tlv]") { // Set new value sourceId.setValue(cfdp::WidthInBytes::FOUR_BYTES, 12); REQUIRE(sourceId.serialize(&serPtr, &deserSize, rawBuf.size(), - SerializeIF::Endianness::NETWORK) == result::OK); + SerializeIF::Endianness::NETWORK) == returnvalue::OK); tlv.setValue(rawBuf.data(), cfdp::WidthInBytes::FOUR_BYTES); serPtr = rawBuf.data(); deserSize = 0; result = tlv.serialize(&serPtr, &deserSize, rawBuf.size(), SerializeIF::Endianness::NETWORK); - REQUIRE(result == HasReturnvaluesIF::RETURN_OK); + REQUIRE(result == returnvalue::OK); REQUIRE(rawBuf[0] == TlvTypes::ENTITY_ID); REQUIRE(rawBuf[1] == 4); - REQUIRE(result == HasReturnvaluesIF::RETURN_OK); + REQUIRE(result == returnvalue::OK); } SECTION("TLV Invalid") { auto tlvInvalid = Tlv(cfdp::TlvTypes::INVALID_TLV, rawBuf.data(), 0); REQUIRE(tlvInvalid.serialize(&serPtr, &deserSize, rawBuf.size(), - SerializeIF::Endianness::NETWORK) != HasReturnvaluesIF::RETURN_OK); + SerializeIF::Endianness::NETWORK) != returnvalue::OK); tlvInvalid = Tlv(cfdp::TlvTypes::ENTITY_ID, nullptr, 3); REQUIRE(tlvInvalid.serialize(&serPtr, &deserSize, rawBuf.size(), - SerializeIF::Endianness::NETWORK) != HasReturnvaluesIF::RETURN_OK); + SerializeIF::Endianness::NETWORK) != returnvalue::OK); REQUIRE(tlvInvalid.serialize(&serPtr, &deserSize, 0, SerializeIF::Endianness::NETWORK) != - HasReturnvaluesIF::RETURN_OK); + returnvalue::OK); REQUIRE(tlvInvalid.getSerializedSize() == 0); REQUIRE(tlvInvalid.serialize(nullptr, nullptr, 0, SerializeIF::Endianness::NETWORK) != - HasReturnvaluesIF::RETURN_OK); + returnvalue::OK); } SECTION("TLV Zero Length Field") { @@ -73,8 +73,7 @@ TEST_CASE("CFDP TLV", "[cfdp][tlv]") { serPtr = rawBuf.data(); deserSize = 0; REQUIRE(zeroLenField.serialize(&serPtr, &deserSize, rawBuf.size(), - SerializeIF::Endianness::NETWORK) == - HasReturnvaluesIF::RETURN_OK); + SerializeIF::Endianness::NETWORK) == returnvalue::OK); REQUIRE(rawBuf[0] == TlvTypes::FAULT_HANDLER); REQUIRE(rawBuf[1] == 0); } @@ -93,7 +92,7 @@ TEST_CASE("CFDP TLV", "[cfdp][tlv]") { Tlv tlv; deserPtr = rawBuf.data(); result = tlv.deSerialize(&deserPtr, &deserSize, SerializeIF::Endianness::NETWORK); - REQUIRE(result == HasReturnvaluesIF::RETURN_OK); + REQUIRE(result == returnvalue::OK); REQUIRE(tlv.getSerializedSize() == 4); REQUIRE(tlv.getType() == TlvTypes::ENTITY_ID); deserPtr = tlv.getValue(); @@ -103,8 +102,7 @@ TEST_CASE("CFDP TLV", "[cfdp][tlv]") { SerializeIF::Endianness::NETWORK); REQUIRE(entityId == 0x0ff0); - REQUIRE(tlv.deSerialize(nullptr, nullptr, SerializeIF::Endianness::NETWORK) != - HasReturnvaluesIF::RETURN_OK); + REQUIRE(tlv.deSerialize(nullptr, nullptr, SerializeIF::Endianness::NETWORK) != returnvalue::OK); deserPtr = rawBuf.data(); deserSize = 0; REQUIRE(tlv.deSerialize(&deserPtr, &deserSize, SerializeIF::Endianness::NETWORK) == @@ -113,17 +111,16 @@ TEST_CASE("CFDP TLV", "[cfdp][tlv]") { rawBuf[0] = TlvTypes::INVALID_TLV; deserSize = 4; REQUIRE(tlv.deSerialize(&deserPtr, &deserSize, SerializeIF::Endianness::NETWORK) != - HasReturnvaluesIF::RETURN_OK); + returnvalue::OK); Tlv zeroLenField(TlvTypes::FAULT_HANDLER, nullptr, 0); serPtr = rawBuf.data(); deserSize = 0; REQUIRE(zeroLenField.serialize(&serPtr, &deserSize, rawBuf.size(), - SerializeIF::Endianness::NETWORK) == - HasReturnvaluesIF::RETURN_OK); + SerializeIF::Endianness::NETWORK) == returnvalue::OK); deserPtr = rawBuf.data(); result = zeroLenField.deSerialize(&deserPtr, &deserSize, SerializeIF::Endianness::NETWORK); - REQUIRE(result == HasReturnvaluesIF::RETURN_OK); + REQUIRE(result == returnvalue::OK); REQUIRE(zeroLenField.getSerializedSize() == 2); REQUIRE(deserSize == 0); } diff --git a/unittests/hal/testFsMock.cpp b/unittests/hal/testFsMock.cpp index 7040e734..2ebcd231 100644 --- a/unittests/hal/testFsMock.cpp +++ b/unittests/hal/testFsMock.cpp @@ -10,7 +10,7 @@ TEST_CASE("Filesystem Mock", "[mocks]") { SECTION("Create File") { FilesystemParams params("hello.txt"); - CHECK(fsMock.createFile(params) == result::OK); + CHECK(fsMock.createFile(params) == returnvalue::OK); auto iter = fsMock.fileMap.find("hello.txt"); REQUIRE(iter != fsMock.fileMap.end()); FilesystemMock::FileInfo &stats = iter->second; @@ -22,7 +22,7 @@ TEST_CASE("Filesystem Mock", "[mocks]") { std::string testData = "test data"; FileOpParams params("hello.txt", testData.size()); CHECK(fsMock.writeToFile(params, reinterpret_cast(testData.data())) == - HasReturnvaluesIF::RETURN_OK); + returnvalue::OK); auto iter = fsMock.fileMap.find("hello.txt"); REQUIRE(iter != fsMock.fileMap.end()); FilesystemMock::FileInfo &stats = iter->second; @@ -38,7 +38,7 @@ TEST_CASE("Filesystem Mock", "[mocks]") { SECTION("Create Directory") { FilesystemParams params("hello"); - CHECK(fsMock.createDirectory(params) == result::OK); + CHECK(fsMock.createDirectory(params) == returnvalue::OK); REQUIRE(not fsMock.dirMap.empty()); auto iter = fsMock.dirMap.find("hello"); REQUIRE(iter != fsMock.dirMap.end()); diff --git a/unittests/hal/testHostFilesystem.cpp b/unittests/hal/testHostFilesystem.cpp index 2da185da..3873d5e9 100644 --- a/unittests/hal/testHostFilesystem.cpp +++ b/unittests/hal/testHostFilesystem.cpp @@ -23,51 +23,51 @@ TEST_CASE("Host Filesystem", "[hal][host]") { SECTION("Create file") { FilesystemParams params(file0.c_str()); - REQUIRE(hostFs.createFile(params) == result::OK); + REQUIRE(hostFs.createFile(params) == returnvalue::OK); CHECK(fs::is_regular_file(file0)); REQUIRE(fs::exists(file0)); } SECTION("Remove File") { FilesystemParams params(file0.c_str()); - REQUIRE(hostFs.createFile(params) == result::OK); + REQUIRE(hostFs.createFile(params) == returnvalue::OK); CHECK(fs::is_regular_file(file0)); REQUIRE(fs::exists(file0)); - REQUIRE(hostFs.removeFile(file0.c_str()) == result::OK); + REQUIRE(hostFs.removeFile(file0.c_str()) == returnvalue::OK); REQUIRE(not fs::exists(file0)); } SECTION("Create Directory") { FilesystemParams params(dir0.c_str()); - REQUIRE(hostFs.createDirectory(params) == result::OK); + REQUIRE(hostFs.createDirectory(params) == returnvalue::OK); CHECK(fs::is_directory(dir0)); REQUIRE(fs::exists(dir0)); } SECTION("Remove Directory") { FilesystemParams params(dir0.c_str()); - REQUIRE(hostFs.createDirectory(params) == result::OK); + REQUIRE(hostFs.createDirectory(params) == returnvalue::OK); REQUIRE(fs::exists(dir0)); - REQUIRE(hostFs.removeDirectory(params) == result::OK); + REQUIRE(hostFs.removeDirectory(params) == returnvalue::OK); REQUIRE(not fs::exists(dir0)); } SECTION("Rename File") { FilesystemParams params(file0.c_str()); - REQUIRE(hostFs.createFile(params) == result::OK); + REQUIRE(hostFs.createFile(params) == returnvalue::OK); CHECK(fs::is_regular_file(file0)); REQUIRE(fs::exists(file0)); - REQUIRE(hostFs.rename(file0.c_str(), file1.c_str()) == result::OK); + REQUIRE(hostFs.rename(file0.c_str(), file1.c_str()) == returnvalue::OK); } SECTION("Write To File") { std::string data = "hello world!"; FileOpParams params(file0.c_str(), data.size()); - REQUIRE(hostFs.createFile(params.fsParams) == result::OK); + REQUIRE(hostFs.createFile(params.fsParams) == returnvalue::OK); CHECK(fs::is_regular_file(file0)); REQUIRE(fs::exists(file0)); CHECK(hostFs.writeToFile(params, reinterpret_cast(data.c_str())) == - HasReturnvaluesIF::RETURN_OK); + returnvalue::OK); CHECK(fs::file_size(file0) == data.size()); ifstream ifile(file0); char readBuf[524]{}; @@ -79,7 +79,7 @@ TEST_CASE("Host Filesystem", "[hal][host]") { SECTION("Read From File") { std::string data = "hello world!"; FileOpParams params(file0.c_str(), data.size()); - REQUIRE(hostFs.createFile(params.fsParams) == result::OK); + REQUIRE(hostFs.createFile(params.fsParams) == returnvalue::OK); CHECK(fs::is_regular_file(file0)); ofstream of(file0); of.write(data.c_str(), static_cast(data.size())); @@ -89,8 +89,7 @@ TEST_CASE("Host Filesystem", "[hal][host]") { std::array readBuf{}; uint8_t* readPtr = readBuf.data(); size_t readSize = 0; - CHECK(hostFs.readFromFile(params, &readPtr, readSize, readBuf.size()) == - HasReturnvaluesIF::RETURN_OK); + CHECK(hostFs.readFromFile(params, &readPtr, readSize, readBuf.size()) == returnvalue::OK); std::string readBackString(reinterpret_cast(readBuf.data())); CHECK(readSize == data.size()); CHECK(data == readBackString); @@ -98,20 +97,20 @@ TEST_CASE("Host Filesystem", "[hal][host]") { SECTION("Invalid Input does not crash") { FileOpParams params(nullptr, 10); - REQUIRE(hostFs.createFile(params.fsParams) != result::OK); - REQUIRE(hostFs.createDirectory(params.fsParams) != result::OK); - REQUIRE(hostFs.createFile(params.fsParams) != result::OK); - REQUIRE(hostFs.removeDirectory(params.fsParams) != result::OK); - REQUIRE(hostFs.removeFile(nullptr) != result::OK); - REQUIRE(hostFs.rename(nullptr, nullptr) != result::OK); - REQUIRE(hostFs.writeToFile(params, nullptr) != result::OK); + REQUIRE(hostFs.createFile(params.fsParams) != returnvalue::OK); + REQUIRE(hostFs.createDirectory(params.fsParams) != returnvalue::OK); + REQUIRE(hostFs.createFile(params.fsParams) != returnvalue::OK); + REQUIRE(hostFs.removeDirectory(params.fsParams) != returnvalue::OK); + REQUIRE(hostFs.removeFile(nullptr) != returnvalue::OK); + REQUIRE(hostFs.rename(nullptr, nullptr) != returnvalue::OK); + REQUIRE(hostFs.writeToFile(params, nullptr) != returnvalue::OK); size_t readLen = 0; - REQUIRE(hostFs.readFromFile(params, nullptr, readLen, 20) != result::OK); + REQUIRE(hostFs.readFromFile(params, nullptr, readLen, 20) != returnvalue::OK); } SECTION("Create File but already exists") { FilesystemParams params(file0.c_str()); - REQUIRE(hostFs.createFile(params) == result::OK); + REQUIRE(hostFs.createFile(params) == returnvalue::OK); REQUIRE(hostFs.createFile(params) == HasFileSystemIF::FILE_ALREADY_EXISTS); } @@ -121,7 +120,7 @@ TEST_CASE("Host Filesystem", "[hal][host]") { SECTION("Create Directory but already exists") { FileOpParams params(file0.c_str(), 12); - REQUIRE(hostFs.createDirectory(params.fsParams) == HasReturnvaluesIF::RETURN_OK); + REQUIRE(hostFs.createDirectory(params.fsParams) == returnvalue::OK); REQUIRE(hostFs.createDirectory(params.fsParams) == HasFileSystemIF::DIRECTORY_ALREADY_EXISTS); } @@ -158,7 +157,7 @@ TEST_CASE("Host Filesystem", "[hal][host]") { ofstream of(fileInDir0); CHECK(fs::is_directory(dir0)); CHECK(fs::is_regular_file(fileInDir0)); - REQUIRE(hostFs.removeDirectory(FilesystemParams(dir0.c_str()), true) == result::OK); + REQUIRE(hostFs.removeDirectory(FilesystemParams(dir0.c_str()), true) == returnvalue::OK); CHECK(not fs::is_directory(dir0)); CHECK(not fs::is_regular_file(fileInDir0)); } @@ -173,7 +172,7 @@ TEST_CASE("Host Filesystem", "[hal][host]") { } SECTION("Create directory with parent directory") { - CHECK(hostFs.createDirectory(FilesystemParams(dirWithParent.c_str()), true) == result::OK); + CHECK(hostFs.createDirectory(FilesystemParams(dirWithParent.c_str()), true) == returnvalue::OK); CHECK(fs::is_directory(dir0)); CHECK(fs::is_directory(dirWithParent)); } diff --git a/unittests/mocks/CcsdsCheckerMock.h b/unittests/mocks/CcsdsCheckerMock.h index a9388ae5..bdcd491a 100644 --- a/unittests/mocks/CcsdsCheckerMock.h +++ b/unittests/mocks/CcsdsCheckerMock.h @@ -7,7 +7,7 @@ class CcsdsCheckerMock : public CcsdsPacketCheckIF { CcsdsCheckerMock(); unsigned int checkCallCount = 0; size_t checkedPacketLen = 0; - ReturnValue_t nextResult = HasReturnvaluesIF::RETURN_OK; + ReturnValue_t nextResult = returnvalue::OK; ReturnValue_t checkPacket(const SpacePacketReader& currentPacket, size_t packetLen) override; private: diff --git a/unittests/mocks/FilesystemMock.cpp b/unittests/mocks/FilesystemMock.cpp index 8f9e3f8f..3d18e3cb 100644 --- a/unittests/mocks/FilesystemMock.cpp +++ b/unittests/mocks/FilesystemMock.cpp @@ -6,19 +6,19 @@ ReturnValue_t FilesystemMock::feedFile(const std::string &filename, std::ifstream &file) { if (not std::filesystem::exists(filename)) { - return HasReturnvaluesIF::RETURN_FAILED; + return returnvalue::FAILED; } size_t fileSize = std::filesystem::file_size(filename); FileOpParams params(filename.c_str(), fileSize); std::vector rawData(fileSize); file.read(reinterpret_cast(rawData.data()), static_cast(rawData.size())); createOrAddToFile(params, rawData.data()); - return HasReturnvaluesIF::RETURN_OK; + return returnvalue::OK; } ReturnValue_t FilesystemMock::writeToFile(FileOpParams params, const uint8_t *data) { createOrAddToFile(params, data); - return HasReturnvaluesIF::RETURN_OK; + return returnvalue::OK; } ReturnValue_t FilesystemMock::readFromFile(FileOpParams params, uint8_t **buffer, size_t &readSize, @@ -32,7 +32,7 @@ ReturnValue_t FilesystemMock::readFromFile(FileOpParams params, uint8_t **buffer size_t readLen = params.size; if (params.offset + params.size > info.fileRaw.size()) { if (params.offset > info.fileRaw.size()) { - return HasReturnvaluesIF::RETURN_OK; + return returnvalue::OK; } readLen = info.fileRaw.size() - params.offset; } @@ -43,14 +43,14 @@ ReturnValue_t FilesystemMock::readFromFile(FileOpParams params, uint8_t **buffer *buffer += readLen; readSize += readLen; } - return HasReturnvaluesIF::RETURN_OK; + return returnvalue::OK; } ReturnValue_t FilesystemMock::createFile(FilesystemParams params, const uint8_t *data, size_t size) { FileOpParams params2(params.path, size); createOrAddToFile(params2, data); - return HasReturnvaluesIF::RETURN_OK; + return returnvalue::OK; } ReturnValue_t FilesystemMock::removeFile(const char *path, FileSystemArgsIF *args) { @@ -60,7 +60,7 @@ ReturnValue_t FilesystemMock::removeFile(const char *path, FileSystemArgsIF *arg return HasFileSystemIF::FILE_DOES_NOT_EXIST; } else { fileMap.erase(iter); - return HasReturnvaluesIF::RETURN_OK; + return returnvalue::OK; } } @@ -68,20 +68,20 @@ ReturnValue_t FilesystemMock::createDirectory(FilesystemParams params, bool crea std::string dirPath = params.path; dirMap[dirPath].createCallCount++; dirMap[dirPath].wihParentDir.push(createParentDirs); - return HasReturnvaluesIF::RETURN_OK; + return returnvalue::OK; } ReturnValue_t FilesystemMock::removeDirectory(FilesystemParams params, bool deleteRecurively) { std::string dirPath = params.path; dirMap[dirPath].delCallCount++; dirMap[dirPath].recursiveDeletion.push(deleteRecurively); - return HasReturnvaluesIF::RETURN_OK; + return returnvalue::OK; } ReturnValue_t FilesystemMock::rename(const char *oldPath, const char *newPath, FileSystemArgsIF *args) { renameQueue.push(RenameInfo(oldPath, newPath)); - return HasReturnvaluesIF::RETURN_OK; + return returnvalue::OK; } void FilesystemMock::createOrAddToFile(FileOpParams params, const uint8_t *data) { diff --git a/unittests/mocks/StorageManagerMock.cpp b/unittests/mocks/StorageManagerMock.cpp index 387b5b17..5cd3a575 100644 --- a/unittests/mocks/StorageManagerMock.cpp +++ b/unittests/mocks/StorageManagerMock.cpp @@ -67,13 +67,13 @@ StorageManagerIF::max_subpools_t StorageManagerMock::getNumberOfSubPools() const void StorageManagerMock::reset() { clearStore(); nextAddDataCallFails.first = false; - nextAddDataCallFails.second = result::OK; + nextAddDataCallFails.second = returnvalue::OK; nextModifyDataCallFails.first = false; - nextModifyDataCallFails.second = result::OK; + nextModifyDataCallFails.second = returnvalue::OK; nextDeleteDataCallFails.first = false; - nextDeleteDataCallFails.second = result::OK; + nextDeleteDataCallFails.second = returnvalue::OK; nextFreeElementCallFails.first = false; - nextFreeElementCallFails.second = result::OK; + nextFreeElementCallFails.second = returnvalue::OK; } StorageManagerMock::StorageManagerMock(object_id_t setObjectId, diff --git a/unittests/tcdistributor/testCcsdsDistributor.cpp b/unittests/tcdistributor/testCcsdsDistributor.cpp index ce96a425..c8aa81f7 100644 --- a/unittests/tcdistributor/testCcsdsDistributor.cpp +++ b/unittests/tcdistributor/testCcsdsDistributor.cpp @@ -35,11 +35,12 @@ TEST_CASE("CCSDS Distributor", "[ccsds][tmtcdistrib]") { spCreator.setCcsdsLenFromTotalDataFieldLen(dataFieldLen); uint8_t* dataPtr; REQUIRE(pool.getFreeElement(&storeId, spCreator.getSerializedSize() + dataFieldLen, &dataPtr) == - result::OK); + returnvalue::OK); size_t serLen = 0; - REQUIRE(spCreator.SerializeIF::serializeBe(dataPtr, serLen, ccsds::HEADER_LEN) == result::OK); + REQUIRE(spCreator.SerializeIF::serializeBe(dataPtr, serLen, ccsds::HEADER_LEN) == + returnvalue::OK); REQUIRE(spCreator.SerializeIF::serializeBe(buf.data(), serLen, ccsds::HEADER_LEN) == - result::OK); + returnvalue::OK); if (dataField == nullptr) { dataPtr[ccsds::HEADER_LEN] = 0; buf[ccsds::HEADER_LEN] = 0; @@ -51,7 +52,7 @@ TEST_CASE("CCSDS Distributor", "[ccsds][tmtcdistrib]") { }; SECTION("State") { - CHECK(ccsdsDistrib.initialize() == result::OK); + CHECK(ccsdsDistrib.initialize() == returnvalue::OK); CHECK(ccsdsDistrib.getRequestQueue() == 1); CHECK(ccsdsDistrib.getIdentifier() == 0); CHECK(ccsdsDistrib.getObjectId() == 1); @@ -61,12 +62,12 @@ TEST_CASE("CCSDS Distributor", "[ccsds][tmtcdistrib]") { SECTION("Basic Forwarding") { CcsdsDistributor::DestInfo info(tcAcceptorMock, false); - REQUIRE(ccsdsDistrib.registerApplication(info) == result::OK); + REQUIRE(ccsdsDistrib.registerApplication(info) == returnvalue::OK); TmTcMessage message; createSpacePacket(tcAcceptorApid, message); store_address_t storeId = message.getStorageId(); queue.addReceivedMessage(message); - REQUIRE(ccsdsDistrib.performOperation(0) == result::OK); + REQUIRE(ccsdsDistrib.performOperation(0) == returnvalue::OK); CHECK(checkerMock.checkedPacketLen == 7); CHECK(checkerMock.checkCallCount == 1); CHECK(queue.wasMessageSent()); @@ -74,10 +75,10 @@ TEST_CASE("CCSDS Distributor", "[ccsds][tmtcdistrib]") { // The packet is forwarded, with no need to delete the data CHECK(pool.hasDataAtId(storeId)); TmTcMessage sentMsg; - CHECK(queue.getNextSentMessage(tcAcceptorQueueId, sentMsg) == result::OK); + CHECK(queue.getNextSentMessage(tcAcceptorQueueId, sentMsg) == returnvalue::OK); CHECK(sentMsg.getStorageId() == storeId); auto accessor = pool.getData(storeId); - CHECK(accessor.first == result::OK); + CHECK(accessor.first == returnvalue::OK); CHECK(accessor.second.size() == ccsds::HEADER_LEN + 1); for (size_t i = 0; i < ccsds::HEADER_LEN; i++) { CHECK(accessor.second.data()[i] == buf[i]); @@ -101,7 +102,7 @@ TEST_CASE("CCSDS Distributor", "[ccsds][tmtcdistrib]") { store_address_t storeId = message.getStorageId(); message.setStorageId(storeId); queue.addReceivedMessage(message); - REQUIRE(ccsdsDistrib.performOperation(0) == result::OK); + REQUIRE(ccsdsDistrib.performOperation(0) == returnvalue::OK); CHECK(checkerMock.checkedPacketLen == 7); CHECK(checkerMock.checkCallCount == 1); CHECK(queue.wasMessageSent()); @@ -109,10 +110,10 @@ TEST_CASE("CCSDS Distributor", "[ccsds][tmtcdistrib]") { // The packet is forwarded, with no need to delete the data CHECK(pool.hasDataAtId(storeId)); TmTcMessage sentMsg; - CHECK(queue.getNextSentMessage(defaultQueueId, sentMsg) == result::OK); + CHECK(queue.getNextSentMessage(defaultQueueId, sentMsg) == returnvalue::OK); CHECK(sentMsg.getStorageId() == storeId); auto accessor = pool.getData(storeId); - CHECK(accessor.first == result::OK); + CHECK(accessor.first == returnvalue::OK); CHECK(accessor.second.size() == ccsds::HEADER_LEN + 1); for (size_t i = 0; i < ccsds::HEADER_LEN; i++) { CHECK(accessor.second.data()[i] == buf[i]); @@ -126,13 +127,13 @@ TEST_CASE("CCSDS Distributor", "[ccsds][tmtcdistrib]") { CcsdsDistributor::DestInfo info(defReceiverMock, true); tgtApid = defaultApid; tgtQueueId = defaultQueueId; - REQUIRE(ccsdsDistrib.registerApplication(info) == result::OK); + REQUIRE(ccsdsDistrib.registerApplication(info) == returnvalue::OK); } SECTION("Specific destination") { CcsdsDistributor::DestInfo info(tcAcceptorMock, true); tgtApid = tcAcceptorApid; tgtQueueId = tcAcceptorQueueId; - REQUIRE(ccsdsDistrib.registerApplication(info) == result::OK); + REQUIRE(ccsdsDistrib.registerApplication(info) == returnvalue::OK); } TmTcMessage message; std::array dataField = {0, 1, 2, 3, 4}; @@ -140,16 +141,16 @@ TEST_CASE("CCSDS Distributor", "[ccsds][tmtcdistrib]") { store_address_t storeId = message.getStorageId(); message.setStorageId(storeId); queue.addReceivedMessage(message); - REQUIRE(ccsdsDistrib.performOperation(0) == result::OK); + REQUIRE(ccsdsDistrib.performOperation(0) == returnvalue::OK); CHECK(checkerMock.checkedPacketLen == 11); CHECK(checkerMock.checkCallCount == 1); // Data was deleted from old slot to re-store without the header CHECK(not pool.hasDataAtId(storeId)); TmTcMessage sentMsg; - CHECK(queue.getNextSentMessage(tgtQueueId, sentMsg) == result::OK); + CHECK(queue.getNextSentMessage(tgtQueueId, sentMsg) == returnvalue::OK); CHECK(sentMsg.getStorageId() != storeId); auto accessor = pool.getData(sentMsg.getStorageId()); - CHECK(accessor.first == result::OK); + CHECK(accessor.first == returnvalue::OK); CHECK(accessor.second.size() == 5); // Verify correctness of data field for (size_t i = 0; i < 5; i++) { From 9441b4a70e4cc1aaef9cd5e680b3cd6388b99eaf Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Tue, 23 Aug 2022 19:37:30 +0200 Subject: [PATCH 066/169] continue dest handler --- src/fsfw/cfdp/handler/DestHandler.cpp | 96 ++++++++++++++++++++++--- src/fsfw/cfdp/handler/DestHandler.h | 25 +++++-- src/fsfw/cfdp/pdu/MetadataInfo.cpp | 39 +++++----- src/fsfw/cfdp/pdu/MetadataInfo.h | 25 ++++--- src/fsfw/events/EventReportingProxyIF.h | 2 +- unittests/cfdp/pdu/testMetadataPdu.cpp | 13 ++-- 6 files changed, 148 insertions(+), 52 deletions(-) diff --git a/src/fsfw/cfdp/handler/DestHandler.cpp b/src/fsfw/cfdp/handler/DestHandler.cpp index 85ef03f4..2d5c6aa0 100644 --- a/src/fsfw/cfdp/handler/DestHandler.cpp +++ b/src/fsfw/cfdp/handler/DestHandler.cpp @@ -2,15 +2,31 @@ #include +#include "fsfw/cfdp/pdu/HeaderReader.h" +#include "fsfw/cfdp/pdu/MetadataPduReader.h" #include "fsfw/objectmanager.h" +#include "fsfw/serviceinterface.h" -cfdp::DestHandler::DestHandler(DestHandlerParams params) : p(std::move(params)) {} +using namespace returnvalue; + +cfdp::DestHandler::DestHandler(DestHandlerParams params, FsfwParams fsfwParams) + : dp(std::move(params)), fp(fsfwParams), tlvVec(params.maxTlvsInOnePdu) {} ReturnValue_t cfdp::DestHandler::performStateMachine() { switch (step) { case TransactionStep::IDLE: { - for (const auto& info : p.packetListRef) { + ReturnValue_t status = returnvalue::OK; + ReturnValue_t result; + for (const auto& info : dp.packetListRef) { + if (info.pduType == PduType::FILE_DIRECTIVE and + info.directiveType == FileDirectives::METADATA) { + result = handleMetadataPdu(info); + if (result != OK) { + status = result; + } + } } + return status; } case TransactionStep::TRANSACTION_START: break; @@ -27,26 +43,86 @@ ReturnValue_t cfdp::DestHandler::performStateMachine() { } ReturnValue_t cfdp::DestHandler::passPacket(PacketInfo packet) { - if (p.packetListRef.full()) { + if (dp.packetListRef.full()) { return returnvalue::FAILED; } - p.packetListRef.push_back(packet); + dp.packetListRef.push_back(packet); return returnvalue::OK; } ReturnValue_t cfdp::DestHandler::initialize() { - if (p.tmStore == nullptr) { - p.tmStore = ObjectManager::instance()->get(objects::TM_STORE); - if (p.tmStore == nullptr) { + if (fp.tmStore == nullptr) { + fp.tmStore = ObjectManager::instance()->get(objects::TM_STORE); + if (fp.tmStore == nullptr) { return returnvalue::FAILED; } } - if (p.tcStore == nullptr) { - p.tcStore = ObjectManager::instance()->get(objects::TC_STORE); - if (p.tcStore == nullptr) { + if (fp.tcStore == nullptr) { + fp.tcStore = ObjectManager::instance()->get(objects::TC_STORE); + if (fp.tcStore == nullptr) { return returnvalue::FAILED; } } return returnvalue::OK; } +ReturnValue_t cfdp::DestHandler::handleMetadataPdu(const PacketInfo& info) { + // Process metadata PDU + auto constAccessorPair = fp.tcStore->getData(info.storeId); + if (constAccessorPair.first != OK) { + // TODO: This is not a CFDP error. Event and/or warning? + return constAccessorPair.first; + } + cfdp::FileSize fileSize; + cfdp::StringLv sourceFileName; + cfdp::StringLv destFileName; + MetadataInfo metadataInfo(fileSize, sourceFileName, destFileName); + cfdp::Tlv* tlvArrayAsPtr = tlvVec.data(); + metadataInfo.setOptionsArray(&tlvArrayAsPtr, std::nullopt, tlvVec.size()); + MetadataPduReader reader(constAccessorPair.second.data(), constAccessorPair.second.size(), + metadataInfo); + ReturnValue_t result = reader.parseData(); + // TODO: The standard does not really specify what happens if this kind of error happens + // I think it might be a good idea to cache some sort of error code, which + // is translated into a warning and/or event by an upper layer + if (result != OK) { + return handleMetadataParseError(constAccessorPair.second.data(), + constAccessorPair.second.size()); + } + return result; +} + +ReturnValue_t cfdp::DestHandler::handleMetadataParseError(const uint8_t* rawData, size_t maxSize) { + // TODO: try to extract destination ID for error + // TODO: Invalid metadata PDU. +#if FSFW_CPP_OSTREAM_ENABLED == 1 + sif::warning << "Parsing Metadata PDU failed with code " << result << std::endl; +#else +#endif + HeaderReader headerReader(rawData, maxSize); + ReturnValue_t result = headerReader.parseData(); + if (result != OK) { + // TODO: Now this really should not happen. Warning or error, + // yield or cache appropriate returnvalue +#if FSFW_CPP_OSTREAM_ENABLED == 1 + sif::warning << "Parsing Header failed" << std::endl; +#else +#endif + // TODO: Trigger appropriate event + return result; + } + cfdp::EntityId destId; + headerReader.getDestId(destId); + RemoteEntityCfg* remoteCfg; + if (not dp.remoteCfgTable.getRemoteCfg(destId, &remoteCfg)) { +// TODO: No remote config for dest ID. I consider this a configuration error. +// Warning or error, yield or cache appropriate returnvalue +#if FSFW_CPP_OSTREAM_ENABLED == 1 + sif::warning << "No remote config exists for destination ID" << std::endl; +#else +#endif + // TODO: Trigger appropriate event + } + // TODO: Appropriate returnvalue? + return returnvalue::FAILED; +} diff --git a/src/fsfw/cfdp/handler/DestHandler.h b/src/fsfw/cfdp/handler/DestHandler.h index c3e30721..d979f09b 100644 --- a/src/fsfw/cfdp/handler/DestHandler.h +++ b/src/fsfw/cfdp/handler/DestHandler.h @@ -28,28 +28,34 @@ struct PacketInfo { struct DestHandlerParams { DestHandlerParams(LocalEntityCfg cfg, UserBase& user, RemoteConfigTableIF& remoteCfgTable, - AcceptsTelemetryIF& packetDest, MessageQueueIF& msgQueue, - etl::ilist& packetList) + etl::ilist& packetList, uint8_t maxTlvsInOnePdu) : cfg(std::move(cfg)), user(user), remoteCfgTable(remoteCfgTable), - packetDest(packetDest), - msgQueue(msgQueue), packetListRef(packetList) {} LocalEntityCfg cfg; UserBase& user; RemoteConfigTableIF& remoteCfgTable; + + etl::ilist& packetListRef; + uint8_t maxTlvsInOnePdu; +}; + +struct FsfwParams { + FsfwParams(AcceptsTelemetryIF& packetDest, MessageQueueIF& msgQueue, + EventReportingProxyIF& eventReporter) + : packetDest(packetDest), msgQueue(msgQueue), eventReporter(eventReporter) {} AcceptsTelemetryIF& packetDest; MessageQueueIF& msgQueue; + EventReportingProxyIF& eventReporter; StorageManagerIF* tcStore = nullptr; StorageManagerIF* tmStore = nullptr; - etl::ilist& packetListRef; }; class DestHandler { public: - explicit DestHandler(DestHandlerParams params); + explicit DestHandler(DestHandlerParams handlerParams, FsfwParams fsfwParams); ReturnValue_t performStateMachine(); @@ -57,8 +63,12 @@ class DestHandler { ReturnValue_t initialize(); + ReturnValue_t handleMetadataPdu(const PacketInfo& info); + ReturnValue_t handleMetadataParseError(const uint8_t* rawData, size_t maxSize); + private: - DestHandlerParams p; + DestHandlerParams dp; + FsfwParams fp; enum class TransactionStep { IDLE = 0, TRANSACTION_START = 1, @@ -68,6 +78,7 @@ class DestHandler { SENDING_FINISHED_PDU = 5 }; TransactionStep step = TransactionStep::IDLE; + std::vector tlvVec; }; } // namespace cfdp diff --git a/src/fsfw/cfdp/pdu/MetadataInfo.cpp b/src/fsfw/cfdp/pdu/MetadataInfo.cpp index daa03473..d88bdd87 100644 --- a/src/fsfw/cfdp/pdu/MetadataInfo.cpp +++ b/src/fsfw/cfdp/pdu/MetadataInfo.cpp @@ -1,22 +1,25 @@ #include "MetadataInfo.h" MetadataInfo::MetadataInfo(bool closureRequested, cfdp::ChecksumType checksumType, - cfdp::FileSize& fileSize, cfdp::Lv& sourceFileName, - cfdp::Lv& destFileName) - : closureRequested(closureRequested), - checksumType(checksumType), - fileSize(fileSize), - sourceFileName(sourceFileName), - destFileName(destFileName) {} + cfdp::FileSize& fileSize, cfdp::StringLv& sourceFileName, + cfdp::StringLv& destFileName) + : MetadataInfo(fileSize, sourceFileName, destFileName) { + this->closureRequested = closureRequested; + this->checksumType = checksumType; +} -void MetadataInfo::setOptionsArray(cfdp::Tlv** optionsArray_, const size_t* optionsLen_, - const size_t* maxOptionsLen_) { +MetadataInfo::MetadataInfo(cfdp::FileSize& fileSize, cfdp::StringLv& sourceFileName, + cfdp::StringLv& destFileName) + : fileSize(fileSize), sourceFileName(sourceFileName), destFileName(destFileName) {} + +void MetadataInfo::setOptionsArray(cfdp::Tlv** optionsArray_, std::optional optionsLen_, + std::optional maxOptionsLen_) { this->optionsArray = optionsArray_; - if (maxOptionsLen_ != nullptr) { - this->maxOptionsLen = *maxOptionsLen_; + if (maxOptionsLen_) { + this->maxOptionsLen = maxOptionsLen_.value(); } - if (optionsLen_ != nullptr) { - this->optionsLen = *optionsLen_; + if (optionsLen_) { + this->optionsLen = optionsLen_.value(); } } @@ -32,7 +35,7 @@ void MetadataInfo::setClosureRequested(bool closureRequested_) { closureRequested = closureRequested_; } -cfdp::Lv& MetadataInfo::getDestFileName() { return destFileName; } +cfdp::StringLv& MetadataInfo::getDestFileName() { return destFileName; } cfdp::FileSize& MetadataInfo::getFileSize() { return fileSize; } @@ -81,9 +84,11 @@ size_t MetadataInfo::getSerializedSize(bool fssLarge) { return size; } -void MetadataInfo::setDestFileName(cfdp::Lv& destFileName_) { this->destFileName = destFileName_; } +void MetadataInfo::setDestFileName(cfdp::StringLv& destFileName_) { + this->destFileName = destFileName_; +} -void MetadataInfo::setSourceFileName(cfdp::Lv& sourceFileName_) { +void MetadataInfo::setSourceFileName(cfdp::StringLv& sourceFileName_) { this->sourceFileName = sourceFileName_; } @@ -95,4 +100,4 @@ size_t MetadataInfo::getOptionsLen() const { return optionsLen; } void MetadataInfo::setOptionsLen(size_t optionsLen_) { this->optionsLen = optionsLen_; } -cfdp::Lv& MetadataInfo::getSourceFileName() { return sourceFileName; } +cfdp::StringLv& MetadataInfo::getSourceFileName() { return sourceFileName; } diff --git a/src/fsfw/cfdp/pdu/MetadataInfo.h b/src/fsfw/cfdp/pdu/MetadataInfo.h index f71eb2f4..95f4544a 100644 --- a/src/fsfw/cfdp/pdu/MetadataInfo.h +++ b/src/fsfw/cfdp/pdu/MetadataInfo.h @@ -1,30 +1,35 @@ #ifndef FSFW_SRC_FSFW_CFDP_PDU_METADATAINFO_H_ #define FSFW_SRC_FSFW_CFDP_PDU_METADATAINFO_H_ +#include + #include "fsfw/cfdp/FileSize.h" #include "fsfw/cfdp/definitions.h" #include "fsfw/cfdp/tlv/Lv.h" +#include "fsfw/cfdp/tlv/StringLv.h" #include "fsfw/cfdp/tlv/Tlv.h" class MetadataInfo { public: + MetadataInfo(cfdp::FileSize& fileSize, cfdp::StringLv& sourceFileName, + cfdp::StringLv& destFileName); MetadataInfo(bool closureRequested, cfdp::ChecksumType checksumType, cfdp::FileSize& fileSize, - cfdp::Lv& sourceFileName, cfdp::Lv& destFileName); + cfdp::StringLv& sourceFileName, cfdp::StringLv& destFileName); size_t getSerializedSize(bool fssLarge = false); - void setOptionsArray(cfdp::Tlv** optionsArray, const size_t* optionsLen, - const size_t* maxOptionsLen); + void setOptionsArray(cfdp::Tlv** optionsArray, std::optional optionsLen, + std::optional maxOptionsLen); [[nodiscard]] cfdp::ChecksumType getChecksumType() const; void setChecksumType(cfdp::ChecksumType checksumType); [[nodiscard]] bool isClosureRequested() const; void setClosureRequested(bool closureRequested = false); - void setDestFileName(cfdp::Lv& destFileName); - void setSourceFileName(cfdp::Lv& sourceFileName); + void setDestFileName(cfdp::StringLv& destFileName); + void setSourceFileName(cfdp::StringLv& sourceFileName); - cfdp::Lv& getDestFileName(); - cfdp::Lv& getSourceFileName(); + cfdp::StringLv& getDestFileName(); + cfdp::StringLv& getSourceFileName(); cfdp::FileSize& getFileSize(); [[nodiscard]] bool hasOptions() const; @@ -37,10 +42,10 @@ class MetadataInfo { private: bool closureRequested = false; - cfdp::ChecksumType checksumType; + cfdp::ChecksumType checksumType = cfdp::ChecksumType::NULL_CHECKSUM; cfdp::FileSize& fileSize; - cfdp::Lv& sourceFileName; - cfdp::Lv& destFileName; + cfdp::StringLv& sourceFileName; + cfdp::StringLv& destFileName; cfdp::Tlv** optionsArray = nullptr; size_t optionsLen = 0; diff --git a/src/fsfw/events/EventReportingProxyIF.h b/src/fsfw/events/EventReportingProxyIF.h index c6034c9f..51f8ed1d 100644 --- a/src/fsfw/events/EventReportingProxyIF.h +++ b/src/fsfw/events/EventReportingProxyIF.h @@ -5,7 +5,7 @@ class EventReportingProxyIF { public: - virtual ~EventReportingProxyIF() {} + virtual ~EventReportingProxyIF() = default; virtual void forwardEvent(Event event, uint32_t parameter1 = 0, uint32_t parameter2 = 0) const = 0; diff --git a/unittests/cfdp/pdu/testMetadataPdu.cpp b/unittests/cfdp/pdu/testMetadataPdu.cpp index cfe24fc6..49f1deb4 100644 --- a/unittests/cfdp/pdu/testMetadataPdu.cpp +++ b/unittests/cfdp/pdu/testMetadataPdu.cpp @@ -21,7 +21,7 @@ TEST_CASE("Metadata PDU", "[cfdp][pdu]") { std::string firstFileName = "hello.txt"; cfdp::StringLv sourceFileName(firstFileName); - cfdp::Lv destFileName; + cfdp::StringLv destFileName; FileSize fileSize(35); MetadataInfo info(false, ChecksumType::MODULAR, fileSize, sourceFileName, destFileName); @@ -67,11 +67,10 @@ TEST_CASE("Metadata PDU", "[cfdp][pdu]") { REQUIRE(mdBuffer[26] == 0); std::string otherFileName = "hello2.txt"; - cfdp::Lv otherFileNameLv(reinterpret_cast(otherFileName.data()), - otherFileName.size()); + cfdp::StringLv otherFileNameLv(otherFileName.data(), otherFileName.size()); info.setSourceFileName(otherFileNameLv); size_t sizeOfOptions = options.size(); - info.setOptionsArray(options.data(), &sizeOfOptions, &sizeOfOptions); + info.setOptionsArray(options.data(), sizeOfOptions, sizeOfOptions); REQUIRE(info.getMaxOptionsLen() == 2); info.setMaxOptionsLen(3); REQUIRE(info.getMaxOptionsLen() == 3); @@ -129,7 +128,7 @@ TEST_CASE("Metadata PDU", "[cfdp][pdu]") { } size_t sizeOfOptions = options.size(); size_t maxSize = 4; - info.setOptionsArray(options.data(), &sizeOfOptions, &maxSize); + info.setOptionsArray(options.data(), sizeOfOptions, maxSize); REQUIRE(info.getOptionsLen() == 2); info.setChecksumType(cfdp::ChecksumType::CRC_32C); info.setClosureRequested(true); @@ -166,9 +165,9 @@ TEST_CASE("Metadata PDU", "[cfdp][pdu]") { } mdBuffer[1] = (36 >> 8) & 0xff; mdBuffer[2] = 36 & 0xff; - info.setOptionsArray(nullptr, nullptr, nullptr); + info.setOptionsArray(nullptr, std::nullopt, std::nullopt); REQUIRE(deserializer2.parseData() == cfdp::METADATA_CANT_PARSE_OPTIONS); - info.setOptionsArray(options.data(), &sizeOfOptions, nullptr); + info.setOptionsArray(options.data(), sizeOfOptions, std::nullopt); for (size_t maxSz = 0; maxSz < 46; maxSz++) { MetadataPduReader invalidSzDeser(mdBuffer.data(), maxSz, info); if (not invalidSzDeser.isNull()) { From b1bd63132236d35a92c605fa86d36067fd1fddf6 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Tue, 23 Aug 2022 20:30:41 +0200 Subject: [PATCH 067/169] implemented metadata handler --- src/fsfw/cfdp/VarLenFields.h | 1 + src/fsfw/cfdp/handler/DestHandler.cpp | 55 ++++++++++++++++++++++++--- src/fsfw/cfdp/handler/DestHandler.h | 30 +++++++++++++-- src/fsfw/cfdp/handler/defs.h | 9 +++++ src/fsfw/cfdp/pdu/HeaderReader.cpp | 10 +++++ src/fsfw/cfdp/pdu/HeaderReader.h | 6 +++ src/fsfw/cfdp/pdu/PduConfig.h | 10 +++-- 7 files changed, 108 insertions(+), 13 deletions(-) create mode 100644 src/fsfw/cfdp/handler/defs.h diff --git a/src/fsfw/cfdp/VarLenFields.h b/src/fsfw/cfdp/VarLenFields.h index 2b862d66..7f369e0c 100644 --- a/src/fsfw/cfdp/VarLenFields.h +++ b/src/fsfw/cfdp/VarLenFields.h @@ -74,6 +74,7 @@ struct TransactionSeqNum : public VarLenField { }; struct TransactionId { + TransactionId() = default; TransactionId(EntityId entityId, TransactionSeqNum seqNum) : entityId(std::move(entityId)), seqNum(std::move(seqNum)) {} diff --git a/src/fsfw/cfdp/handler/DestHandler.cpp b/src/fsfw/cfdp/handler/DestHandler.cpp index 2d5c6aa0..aefa1aa3 100644 --- a/src/fsfw/cfdp/handler/DestHandler.cpp +++ b/src/fsfw/cfdp/handler/DestHandler.cpp @@ -3,14 +3,19 @@ #include #include "fsfw/cfdp/pdu/HeaderReader.h" -#include "fsfw/cfdp/pdu/MetadataPduReader.h" #include "fsfw/objectmanager.h" #include "fsfw/serviceinterface.h" using namespace returnvalue; cfdp::DestHandler::DestHandler(DestHandlerParams params, FsfwParams fsfwParams) - : dp(std::move(params)), fp(fsfwParams), tlvVec(params.maxTlvsInOnePdu) {} + : tlvVec(params.maxTlvsInOnePdu), + userTlvVec(params.maxTlvsInOnePdu), + dp(std::move(params)), + fp(fsfwParams), + tp(params.maxFilenameLen) { + tp.pduConf.direction = cfdp::Direction::TOWARDS_SENDER; +} ReturnValue_t cfdp::DestHandler::performStateMachine() { switch (step) { @@ -73,10 +78,9 @@ ReturnValue_t cfdp::DestHandler::handleMetadataPdu(const PacketInfo& info) { // TODO: This is not a CFDP error. Event and/or warning? return constAccessorPair.first; } - cfdp::FileSize fileSize; cfdp::StringLv sourceFileName; cfdp::StringLv destFileName; - MetadataInfo metadataInfo(fileSize, sourceFileName, destFileName); + MetadataInfo metadataInfo(tp.fileSize, sourceFileName, destFileName); cfdp::Tlv* tlvArrayAsPtr = tlvVec.data(); metadataInfo.setOptionsArray(&tlvArrayAsPtr, std::nullopt, tlvVec.size()); MetadataPduReader reader(constAccessorPair.second.data(), constAccessorPair.second.size(), @@ -89,7 +93,7 @@ ReturnValue_t cfdp::DestHandler::handleMetadataPdu(const PacketInfo& info) { return handleMetadataParseError(constAccessorPair.second.data(), constAccessorPair.second.size()); } - return result; + return startTransaction(reader, metadataInfo); } ReturnValue_t cfdp::DestHandler::handleMetadataParseError(const uint8_t* rawData, size_t maxSize) { @@ -126,3 +130,44 @@ ReturnValue_t cfdp::DestHandler::handleMetadataParseError(const uint8_t* rawData // TODO: Appropriate returnvalue? return returnvalue::FAILED; } + +ReturnValue_t cfdp::DestHandler::startTransaction(MetadataPduReader& reader, MetadataInfo& info) { + if (cfdpState != CfdpStates::IDLE) { + // According to standard, discard metadata PDU if we are busy + return returnvalue::OK; + } + step = TransactionStep::TRANSACTION_START; + if (reader.getTransmissionMode() == TransmissionModes::UNACKNOWLEDGED) { + cfdpState = CfdpStates::BUSY_CLASS_1_NACKED; + } else if (reader.getTransmissionMode() == TransmissionModes::ACKNOWLEDGED) { + cfdpState = CfdpStates::BUSY_CLASS_2_ACKED; + } + tp.checksumType = info.getChecksumType(); + tp.closureRequested = info.isClosureRequested(); + size_t sourceNameSize = 0; + const uint8_t* sourceNamePtr = info.getSourceFileName().getValue(&sourceNameSize); + if (sourceNameSize > tp.sourceName.size()) { + // TODO: Warning, event etc. + return FAILED; + } + std::memcpy(tp.sourceName.data(), sourceNamePtr, sourceNameSize); + tp.sourceName[sourceNameSize] = '\0'; + size_t destNameSize = 0; + const uint8_t* destNamePtr = info.getDestFileName().getValue(&destNameSize); + if (destNameSize > tp.destName.size()) { + // TODO: Warning, event etc. + return FAILED; + } + std::memcpy(tp.destName.data(), destNamePtr, destNameSize); + tp.destName[destNameSize] = '\0'; + reader.fillConfig(tp.pduConf); + tp.pduConf.direction = Direction::TOWARDS_SENDER; + tp.transactionId.entityId = tp.pduConf.sourceId; + tp.transactionId.seqNum = tp.pduConf.seqNum; + if (not dp.remoteCfgTable.getRemoteCfg(tp.pduConf.destId, &tp.remoteCfg)) { + // TODO: Warning, event etc. + return FAILED; + } + step = TransactionStep::RECEIVING_FILE_DATA_PDUS; + return OK; +} diff --git a/src/fsfw/cfdp/handler/DestHandler.h b/src/fsfw/cfdp/handler/DestHandler.h index d979f09b..706752b2 100644 --- a/src/fsfw/cfdp/handler/DestHandler.h +++ b/src/fsfw/cfdp/handler/DestHandler.h @@ -7,7 +7,9 @@ #include "RemoteConfigTableIF.h" #include "UserBase.h" +#include "defs.h" #include "fsfw/cfdp/handler/mib.h" +#include "fsfw/cfdp/pdu/MetadataPduReader.h" #include "fsfw/cfdp/pdu/PduConfig.h" #include "fsfw/container/DynamicFIFO.h" #include "fsfw/storagemanager/StorageManagerIF.h" @@ -28,7 +30,7 @@ struct PacketInfo { struct DestHandlerParams { DestHandlerParams(LocalEntityCfg cfg, UserBase& user, RemoteConfigTableIF& remoteCfgTable, - etl::ilist& packetList, uint8_t maxTlvsInOnePdu) + etl::ilist& packetList) : cfg(std::move(cfg)), user(user), remoteCfgTable(remoteCfgTable), @@ -39,7 +41,8 @@ struct DestHandlerParams { RemoteConfigTableIF& remoteCfgTable; etl::ilist& packetListRef; - uint8_t maxTlvsInOnePdu; + uint8_t maxTlvsInOnePdu = 10; + size_t maxFilenameLen = 255; }; struct FsfwParams { @@ -67,8 +70,6 @@ class DestHandler { ReturnValue_t handleMetadataParseError(const uint8_t* rawData, size_t maxSize); private: - DestHandlerParams dp; - FsfwParams fp; enum class TransactionStep { IDLE = 0, TRANSACTION_START = 1, @@ -77,8 +78,29 @@ class DestHandler { TRANSFER_COMPLETION = 4, SENDING_FINISHED_PDU = 5 }; + struct TransactionParams { + explicit TransactionParams(size_t maxFileNameLen) + : sourceName(maxFileNameLen), destName(maxFileNameLen) {} + + ChecksumType checksumType = ChecksumType::NULL_CHECKSUM; + bool closureRequested{}; + std::vector sourceName; + std::vector destName; + cfdp::FileSize fileSize; + TransactionId transactionId; + PduConfig pduConf; + RemoteEntityCfg* remoteCfg; + }; + TransactionStep step = TransactionStep::IDLE; + CfdpStates cfdpState = CfdpStates::IDLE; std::vector tlvVec; + std::vector userTlvVec; + DestHandlerParams dp; + FsfwParams fp; + TransactionParams tp; + + ReturnValue_t startTransaction(MetadataPduReader& reader, MetadataInfo& info); }; } // namespace cfdp diff --git a/src/fsfw/cfdp/handler/defs.h b/src/fsfw/cfdp/handler/defs.h new file mode 100644 index 00000000..9e837a96 --- /dev/null +++ b/src/fsfw/cfdp/handler/defs.h @@ -0,0 +1,9 @@ +#ifndef FSFW_CFDP_HANDLER_DEFS_H +#define FSFW_CFDP_HANDLER_DEFS_H + +namespace cfdp { + +enum class CfdpStates { IDLE, BUSY_CLASS_1_NACKED, BUSY_CLASS_2_ACKED, SUSPENDED }; + +} +#endif // FSFW_CFDP_HANDLER_DEFS_H diff --git a/src/fsfw/cfdp/pdu/HeaderReader.cpp b/src/fsfw/cfdp/pdu/HeaderReader.cpp index f220ccd3..e2f070db 100644 --- a/src/fsfw/cfdp/pdu/HeaderReader.cpp +++ b/src/fsfw/cfdp/pdu/HeaderReader.cpp @@ -139,3 +139,13 @@ bool HeaderReader::isNull() const { } HeaderReader::operator bool() const { return not isNull(); } + +void HeaderReader::fillConfig(PduConfig &cfg) const { + cfg.largeFile = getLargeFileFlag(); + cfg.crcFlag = getCrcFlag(); + cfg.mode = getTransmissionMode(); + cfg.direction = getDirection(); + getTransactionSeqNum(cfg.seqNum); + getSourceId(cfg.sourceId); + getDestId(cfg.destId); +} diff --git a/src/fsfw/cfdp/pdu/HeaderReader.h b/src/fsfw/cfdp/pdu/HeaderReader.h index 9bf740a8..533320b7 100644 --- a/src/fsfw/cfdp/pdu/HeaderReader.h +++ b/src/fsfw/cfdp/pdu/HeaderReader.h @@ -45,6 +45,12 @@ class HeaderReader : public RedirectableDataPointerIF, public PduHeaderIF { explicit operator bool() const; [[nodiscard]] bool isNull() const; + /** + * Fill the provided PDU configuration from the fields detected by this reader. + * @param cfg + */ + void fillConfig(PduConfig& cfg) const; + [[nodiscard]] virtual size_t getHeaderSize() const; [[nodiscard]] size_t getPduDataFieldLen() const override; diff --git a/src/fsfw/cfdp/pdu/PduConfig.h b/src/fsfw/cfdp/pdu/PduConfig.h index 2e513159..368999cc 100644 --- a/src/fsfw/cfdp/pdu/PduConfig.h +++ b/src/fsfw/cfdp/pdu/PduConfig.h @@ -6,16 +6,18 @@ class PduConfig { public: + PduConfig() = default; PduConfig(cfdp::EntityId sourceId, cfdp::EntityId destId, cfdp::TransmissionModes mode, cfdp::TransactionSeqNum seqNum, bool crcFlag = false, bool largeFile = false, cfdp::Direction direction = cfdp::Direction::TOWARDS_RECEIVER); - cfdp::TransmissionModes mode; + + cfdp::TransmissionModes mode = cfdp::TransmissionModes::ACKNOWLEDGED; cfdp::TransactionSeqNum seqNum; cfdp::EntityId sourceId; cfdp::EntityId destId; - bool crcFlag; - bool largeFile; - cfdp::Direction direction; + bool crcFlag = false; + bool largeFile = false; + cfdp::Direction direction = cfdp::Direction::TOWARDS_RECEIVER; }; #endif /* FSFW_SRC_FSFW_CFDP_PDU_PDUCONFIG_H_ */ From 26ea6606bf271ef8dc9ce52e624f026296b07015 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Tue, 23 Aug 2022 20:56:09 +0200 Subject: [PATCH 068/169] metadata recvd indication --- src/fsfw/cfdp/handler/DestHandler.cpp | 9 +++++++++ src/fsfw/cfdp/handler/UserBase.h | 19 +++++++++++++++---- 2 files changed, 24 insertions(+), 4 deletions(-) diff --git a/src/fsfw/cfdp/handler/DestHandler.cpp b/src/fsfw/cfdp/handler/DestHandler.cpp index aefa1aa3..a52af18e 100644 --- a/src/fsfw/cfdp/handler/DestHandler.cpp +++ b/src/fsfw/cfdp/handler/DestHandler.cpp @@ -169,5 +169,14 @@ ReturnValue_t cfdp::DestHandler::startTransaction(MetadataPduReader& reader, Met return FAILED; } step = TransactionStep::RECEIVING_FILE_DATA_PDUS; + MetadataRecvdParams params; + params.sourceId = tp.pduConf.sourceId; + params.fileSize = tp.fileSize.getSize(); + params.destFileName = tp.destName.data(); + params.sourceFileName = tp.sourceName.data(); + params.id = tp.transactionId; + params.msgsToUserArray = dynamic_cast(userTlvVec.data()); + params.msgsToUserLen = info.getOptionsLen(); + dp.user.metadataRecvdIndication(params); return OK; } diff --git a/src/fsfw/cfdp/handler/UserBase.h b/src/fsfw/cfdp/handler/UserBase.h index 34af89a5..0003decf 100644 --- a/src/fsfw/cfdp/handler/UserBase.h +++ b/src/fsfw/cfdp/handler/UserBase.h @@ -29,10 +29,11 @@ struct TransactionFinishedParams { struct MetadataRecvdParams { TransactionId id; EntityId sourceId; - size_t fileSize; - const char* sourceFileName; - const char* destFileName; - std::vector msgsToUser; + uint64_t fileSize; + const char* sourceFileName = ""; + const char* destFileName = ""; + size_t msgsToUserLen = 0; + const MessageToUserTlv* msgsToUserArray = nullptr; }; struct FileSegmentRecvdParams { @@ -63,6 +64,16 @@ class UserBase { virtual void transactionIndication(TransactionId id) = 0; virtual void eofSentIndication(TransactionId id) = 0; virtual void transactionFinishedIndication(TransactionFinishedParams params) = 0; + /** + * Will be called if metadata was received. + * + * IMPORTANT: The passed struct contains the messages to the user in form of a raw C array. + * The TLVs in these arrays are zero-copy types, which means that they point to the raw data + * inside the metadata packet directly. The metadata packet will be deleted from the TC store + * shortly after it was processed. If some of the data is to be cached and/or used after the + * function call, it needs to be copied into another user-provided buffer. + * @param params + */ virtual void metadataRecvdIndication(MetadataRecvdParams params) = 0; virtual void fileSegmentRecvdIndication(FileSegmentRecvdParams params) = 0; virtual void reportIndication(TransactionId id, StatusReportIF& report) = 0; From eb29b79467dbb72cd5234d1d18cadca8745a2c17 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Wed, 24 Aug 2022 08:44:20 +0200 Subject: [PATCH 069/169] some more docs --- src/fsfw/cfdp/handler/DestHandler.cpp | 4 +-- src/fsfw/cfdp/handler/UserBase.h | 39 ++++++++++++++++----------- 2 files changed, 24 insertions(+), 19 deletions(-) diff --git a/src/fsfw/cfdp/handler/DestHandler.cpp b/src/fsfw/cfdp/handler/DestHandler.cpp index a52af18e..3d0a4500 100644 --- a/src/fsfw/cfdp/handler/DestHandler.cpp +++ b/src/fsfw/cfdp/handler/DestHandler.cpp @@ -169,12 +169,10 @@ ReturnValue_t cfdp::DestHandler::startTransaction(MetadataPduReader& reader, Met return FAILED; } step = TransactionStep::RECEIVING_FILE_DATA_PDUS; - MetadataRecvdParams params; - params.sourceId = tp.pduConf.sourceId; + MetadataRecvdParams params(tp.transactionId, tp.pduConf.sourceId); params.fileSize = tp.fileSize.getSize(); params.destFileName = tp.destName.data(); params.sourceFileName = tp.sourceName.data(); - params.id = tp.transactionId; params.msgsToUserArray = dynamic_cast(userTlvVec.data()); params.msgsToUserLen = info.getOptionsLen(); dp.user.metadataRecvdIndication(params); diff --git a/src/fsfw/cfdp/handler/UserBase.h b/src/fsfw/cfdp/handler/UserBase.h index 0003decf..eff03d43 100644 --- a/src/fsfw/cfdp/handler/UserBase.h +++ b/src/fsfw/cfdp/handler/UserBase.h @@ -27,9 +27,11 @@ struct TransactionFinishedParams { }; struct MetadataRecvdParams { - TransactionId id; - EntityId sourceId; - uint64_t fileSize; + MetadataRecvdParams(const TransactionId& id, const EntityId& sourceId): + id(id), sourceId(sourceId) {} + const TransactionId& id; + const EntityId& sourceId; + uint64_t fileSize = 0; const char* sourceFileName = ""; const char* destFileName = ""; size_t msgsToUserLen = 0; @@ -44,21 +46,26 @@ struct FileSegmentRecvdParams { std::pair segmentMetadata; }; +/** + * @brief Base class which provides a user interface to interact with CFDP handlers. + * + * @details + * This class is also used to pass the Virtual Filestore (VFS) Implementation to the CFDP + * handlers so the filestore operations can be mapped to the underlying filestore. + * + * It is used by implementing it in a child class and then passing it to the CFDP + * handler objects. The base class provides default implementation for the user indication + * primitives specified in the CFDP standard. The user can override these implementations + * to provide custom indication handlers. + * + * Please note that for all indication callbacks, the passed transaction ID reference will + * become invalid shortly after the function has been executed. If the transaction ID is to be + * cached or used, create an own copy of it. + * @param vfs Virtual Filestore Object. Will be used for all file operations + */ class UserBase { public: - /** - * @brief Base class which provides a user interface to interact with CFDP handlers. - * - * @details - * This class is also used to pass the Virtual Filestore (VFS) Implementation to the CFDP - * handlers so the filestore operations can be mapped to the underlying filestore. - * - * It is used by implementing it in a child class and then passing it to the CFDP - * handler objects. The base class provides default implementation for the user indication - * primitives specified in the CFDP standard. The user can override these implementations - * to provide custom indication handlers. - * @param vfs Virtual Filestore Object. Will be used for all file operations - */ + explicit UserBase(HasFileSystemIF& vfs); virtual void transactionIndication(TransactionId id) = 0; From 2c730c86325a828d41feb650cbb93040bad1cc19 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Wed, 24 Aug 2022 12:11:03 +0200 Subject: [PATCH 070/169] use const struct ref instead --- src/fsfw/cfdp/handler/UserBase.h | 2 +- unittests/mocks/cfdp/UserMock.cpp | 2 +- unittests/mocks/cfdp/UserMock.h | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/fsfw/cfdp/handler/UserBase.h b/src/fsfw/cfdp/handler/UserBase.h index eff03d43..50a00a2d 100644 --- a/src/fsfw/cfdp/handler/UserBase.h +++ b/src/fsfw/cfdp/handler/UserBase.h @@ -81,7 +81,7 @@ class UserBase { * function call, it needs to be copied into another user-provided buffer. * @param params */ - virtual void metadataRecvdIndication(MetadataRecvdParams params) = 0; + virtual void metadataRecvdIndication(const MetadataRecvdParams& params) = 0; virtual void fileSegmentRecvdIndication(FileSegmentRecvdParams params) = 0; virtual void reportIndication(TransactionId id, StatusReportIF& report) = 0; virtual void suspendedIndication(TransactionId id, ConditionCode code) = 0; diff --git a/unittests/mocks/cfdp/UserMock.cpp b/unittests/mocks/cfdp/UserMock.cpp index bcef4e68..2281184e 100644 --- a/unittests/mocks/cfdp/UserMock.cpp +++ b/unittests/mocks/cfdp/UserMock.cpp @@ -8,7 +8,7 @@ void cfdp::UserMock::abandonedIndication(cfdp::TransactionId id, cfdp::Condition uint64_t progress) {} void cfdp::UserMock::eofRecvIndication(cfdp::TransactionId id) {} void cfdp::UserMock::transactionFinishedIndication(TransactionFinishedParams finishedParams) {} -void cfdp::UserMock::metadataRecvdIndication(MetadataRecvdParams params) {} +void cfdp::UserMock::metadataRecvdIndication(const MetadataRecvdParams& params) {} void cfdp::UserMock::fileSegmentRecvdIndication(FileSegmentRecvdParams params) {} void cfdp::UserMock::reportIndication(TransactionId id, StatusReportIF& report) {} void cfdp::UserMock::suspendedIndication(TransactionId id, ConditionCode code) {} diff --git a/unittests/mocks/cfdp/UserMock.h b/unittests/mocks/cfdp/UserMock.h index d9d05336..c58210f6 100644 --- a/unittests/mocks/cfdp/UserMock.h +++ b/unittests/mocks/cfdp/UserMock.h @@ -13,7 +13,7 @@ class UserMock : public UserBase { void abandonedIndication(TransactionId id, ConditionCode code, size_t progress) override; void eofRecvIndication(TransactionId id) override; void transactionFinishedIndication(TransactionFinishedParams params) override; - void metadataRecvdIndication(MetadataRecvdParams params) override; + void metadataRecvdIndication(const MetadataRecvdParams& params) override; void fileSegmentRecvdIndication(FileSegmentRecvdParams params) override; void reportIndication(TransactionId id, StatusReportIF& report) override; void suspendedIndication(TransactionId id, ConditionCode code) override; From 267466be9dc9502d900354be315aabbaed50c7cc Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Wed, 24 Aug 2022 15:43:58 +0200 Subject: [PATCH 071/169] pass const references to user handler now --- src/fsfw/cfdp/handler/DestHandler.h | 2 +- src/fsfw/cfdp/handler/UserBase.h | 20 ++++++++++---------- unittests/mocks/cfdp/UserMock.cpp | 26 +++++++++++++++----------- unittests/mocks/cfdp/UserMock.h | 20 ++++++++++---------- 4 files changed, 36 insertions(+), 32 deletions(-) diff --git a/src/fsfw/cfdp/handler/DestHandler.h b/src/fsfw/cfdp/handler/DestHandler.h index 706752b2..fdf79633 100644 --- a/src/fsfw/cfdp/handler/DestHandler.h +++ b/src/fsfw/cfdp/handler/DestHandler.h @@ -89,7 +89,7 @@ class DestHandler { cfdp::FileSize fileSize; TransactionId transactionId; PduConfig pduConf; - RemoteEntityCfg* remoteCfg; + RemoteEntityCfg* remoteCfg = nullptr; }; TransactionStep step = TransactionStep::IDLE; diff --git a/src/fsfw/cfdp/handler/UserBase.h b/src/fsfw/cfdp/handler/UserBase.h index 50a00a2d..bd26ae0d 100644 --- a/src/fsfw/cfdp/handler/UserBase.h +++ b/src/fsfw/cfdp/handler/UserBase.h @@ -68,9 +68,9 @@ class UserBase { explicit UserBase(HasFileSystemIF& vfs); - virtual void transactionIndication(TransactionId id) = 0; - virtual void eofSentIndication(TransactionId id) = 0; - virtual void transactionFinishedIndication(TransactionFinishedParams params) = 0; + virtual void transactionIndication(const TransactionId& id) = 0; + virtual void eofSentIndication(const TransactionId& id) = 0; + virtual void transactionFinishedIndication(const TransactionFinishedParams& params) = 0; /** * Will be called if metadata was received. * @@ -82,13 +82,13 @@ class UserBase { * @param params */ virtual void metadataRecvdIndication(const MetadataRecvdParams& params) = 0; - virtual void fileSegmentRecvdIndication(FileSegmentRecvdParams params) = 0; - virtual void reportIndication(TransactionId id, StatusReportIF& report) = 0; - virtual void suspendedIndication(TransactionId id, ConditionCode code) = 0; - virtual void resumedIndication(TransactionId id, size_t progress) = 0; - virtual void faultIndication(TransactionId id, ConditionCode code, size_t progress) = 0; - virtual void abandonedIndication(TransactionId id, ConditionCode code, size_t progress) = 0; - virtual void eofRecvIndication(TransactionId id) = 0; + virtual void fileSegmentRecvdIndication(const FileSegmentRecvdParams& params) = 0; + virtual void reportIndication(const TransactionId& id, StatusReportIF& report) = 0; + virtual void suspendedIndication(const TransactionId& id, ConditionCode code) = 0; + virtual void resumedIndication(const TransactionId& id, size_t progress) = 0; + virtual void faultIndication(const TransactionId& id, ConditionCode code, size_t progress) = 0; + virtual void abandonedIndication(const TransactionId& id, ConditionCode code, size_t progress) = 0; + virtual void eofRecvIndication(const TransactionId& id) = 0; private: HasFileSystemIF& vfs; diff --git a/unittests/mocks/cfdp/UserMock.cpp b/unittests/mocks/cfdp/UserMock.cpp index 2281184e..a6b6ed48 100644 --- a/unittests/mocks/cfdp/UserMock.cpp +++ b/unittests/mocks/cfdp/UserMock.cpp @@ -1,17 +1,21 @@ #include "UserMock.h" +namespace cfdp { + cfdp::UserMock::UserMock(HasFileSystemIF& vfs) : UserBase(vfs) {} -void cfdp::UserMock::transactionIndication(cfdp::TransactionId id) {} -void cfdp::UserMock::eofSentIndication(cfdp::TransactionId id) {} -void cfdp::UserMock::abandonedIndication(cfdp::TransactionId id, cfdp::ConditionCode code, +void UserMock::transactionIndication(const TransactionId& id) {} +void UserMock::eofSentIndication(const TransactionId& id) {} +void UserMock::abandonedIndication(const TransactionId& id, cfdp::ConditionCode code, uint64_t progress) {} -void cfdp::UserMock::eofRecvIndication(cfdp::TransactionId id) {} -void cfdp::UserMock::transactionFinishedIndication(TransactionFinishedParams finishedParams) {} -void cfdp::UserMock::metadataRecvdIndication(const MetadataRecvdParams& params) {} -void cfdp::UserMock::fileSegmentRecvdIndication(FileSegmentRecvdParams params) {} -void cfdp::UserMock::reportIndication(TransactionId id, StatusReportIF& report) {} -void cfdp::UserMock::suspendedIndication(TransactionId id, ConditionCode code) {} -void cfdp::UserMock::resumedIndication(TransactionId id, size_t progress) {} -void cfdp::UserMock::faultIndication(cfdp::TransactionId id, cfdp::ConditionCode code, +void UserMock::eofRecvIndication(const TransactionId& id) {} +void UserMock::transactionFinishedIndication(const TransactionFinishedParams& finishedParams) {} +void UserMock::metadataRecvdIndication(const MetadataRecvdParams& params) {} +void UserMock::fileSegmentRecvdIndication(const FileSegmentRecvdParams& params) {} +void UserMock::reportIndication(const TransactionId& id, StatusReportIF& report) {} +void UserMock::suspendedIndication(const TransactionId& id, ConditionCode code) {} +void UserMock::resumedIndication(const TransactionId& id, size_t progress) {} +void UserMock::faultIndication(const TransactionId& id, cfdp::ConditionCode code, size_t progress) {} + +} diff --git a/unittests/mocks/cfdp/UserMock.h b/unittests/mocks/cfdp/UserMock.h index c58210f6..f3a5bfd9 100644 --- a/unittests/mocks/cfdp/UserMock.h +++ b/unittests/mocks/cfdp/UserMock.h @@ -8,17 +8,17 @@ class UserMock : public UserBase { public: explicit UserMock(HasFileSystemIF& vfs); - void transactionIndication(TransactionId id) override; - void eofSentIndication(TransactionId id) override; - void abandonedIndication(TransactionId id, ConditionCode code, size_t progress) override; - void eofRecvIndication(TransactionId id) override; - void transactionFinishedIndication(TransactionFinishedParams params) override; + void transactionIndication(const TransactionId& id) override; + void eofSentIndication(const TransactionId& id) override; + void abandonedIndication(const TransactionId& id, ConditionCode code, size_t progress) override; + void eofRecvIndication(const TransactionId& id) override; + void transactionFinishedIndication(const TransactionFinishedParams& params) override; void metadataRecvdIndication(const MetadataRecvdParams& params) override; - void fileSegmentRecvdIndication(FileSegmentRecvdParams params) override; - void reportIndication(TransactionId id, StatusReportIF& report) override; - void suspendedIndication(TransactionId id, ConditionCode code) override; - void resumedIndication(TransactionId id, size_t progress) override; - void faultIndication(TransactionId id, ConditionCode code, size_t progress) override; + void fileSegmentRecvdIndication(const FileSegmentRecvdParams& params) override; + void reportIndication(const TransactionId& id, StatusReportIF& report) override; + void suspendedIndication(const TransactionId& id, ConditionCode code) override; + void resumedIndication(const TransactionId& id, size_t progress) override; + void faultIndication(const TransactionId& id, ConditionCode code, size_t progress) override; }; } // namespace cfdp From 81a7c21cd13a6d10ea5080ac393f4d8f80852573 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Wed, 24 Aug 2022 17:31:26 +0200 Subject: [PATCH 072/169] continued router component --- src/fsfw/cfdp/handler/DestHandler.cpp | 50 +++++++++++++++------------ src/fsfw/cfdp/handler/DestHandler.h | 12 +++++++ src/fsfw/cfdp/handler/UserBase.h | 8 ++--- unittests/mocks/cfdp/UserMock.cpp | 8 ++--- 4 files changed, 48 insertions(+), 30 deletions(-) diff --git a/src/fsfw/cfdp/handler/DestHandler.cpp b/src/fsfw/cfdp/handler/DestHandler.cpp index 3d0a4500..7271c19c 100644 --- a/src/fsfw/cfdp/handler/DestHandler.cpp +++ b/src/fsfw/cfdp/handler/DestHandler.cpp @@ -18,31 +18,35 @@ cfdp::DestHandler::DestHandler(DestHandlerParams params, FsfwParams fsfwParams) } ReturnValue_t cfdp::DestHandler::performStateMachine() { - switch (step) { - case TransactionStep::IDLE: { - ReturnValue_t status = returnvalue::OK; - ReturnValue_t result; - for (const auto& info : dp.packetListRef) { - if (info.pduType == PduType::FILE_DIRECTIVE and - info.directiveType == FileDirectives::METADATA) { - result = handleMetadataPdu(info); - if (result != OK) { - status = result; - } + if (step == TransactionStep::IDLE) { + ReturnValue_t status = returnvalue::OK; + ReturnValue_t result; + for (const auto& info : dp.packetListRef) { + if (info.pduType == PduType::FILE_DIRECTIVE and + info.directiveType == FileDirectives::METADATA) { + result = handleMetadataPdu(info); + if (result != OK) { + status = result; } } - return status; } - case TransactionStep::TRANSACTION_START: - break; - case TransactionStep::RECEIVING_FILE_DATA_PDUS: - break; - case TransactionStep::SENDING_ACK_PDU: - break; - case TransactionStep::TRANSFER_COMPLETION: - break; - case TransactionStep::SENDING_FINISHED_PDU: - break; + if (step != TransactionStep::IDLE) { + return CALL_FSM_AGAIN; + } + return status; + } + if (cfdpState == CfdpStates::BUSY_CLASS_1_NACKED) { + for (const auto& info : dp.packetListRef) { + if (info.pduType == PduType::FILE_DATA) { + } + } + return returnvalue::OK; + } + if (cfdpState == CfdpStates::BUSY_CLASS_2_ACKED) { + // TODO: Will be implemented at a later stage +#if FSFW_CPP_OSTREAM_ENABLED == 1 + sif::warning << "CFDP state machine for acknowledged mode not implemented yet" << std::endl; +#endif } return returnvalue::OK; } @@ -178,3 +182,5 @@ ReturnValue_t cfdp::DestHandler::startTransaction(MetadataPduReader& reader, Met dp.user.metadataRecvdIndication(params); return OK; } + +cfdp::CfdpStates cfdp::DestHandler::getCfdpState() const { return cfdpState; } diff --git a/src/fsfw/cfdp/handler/DestHandler.h b/src/fsfw/cfdp/handler/DestHandler.h index fdf79633..74668638 100644 --- a/src/fsfw/cfdp/handler/DestHandler.h +++ b/src/fsfw/cfdp/handler/DestHandler.h @@ -58,8 +58,18 @@ struct FsfwParams { class DestHandler { public: + /** + * Will be returned if it is advisable to call the state machine operation call again + */ + ReturnValue_t CALL_FSM_AGAIN = returnvalue::makeCode(1, 0); explicit DestHandler(DestHandlerParams handlerParams, FsfwParams fsfwParams); + /** + * + * @return + * - @c returnvalue::OK State machine OK for this execution cycle + * - @c CALL_FSM_AGAIN State machine should be called again. + */ ReturnValue_t performStateMachine(); ReturnValue_t passPacket(PacketInfo packet); @@ -69,6 +79,8 @@ class DestHandler { ReturnValue_t handleMetadataPdu(const PacketInfo& info); ReturnValue_t handleMetadataParseError(const uint8_t* rawData, size_t maxSize); + [[nodiscard]] CfdpStates getCfdpState() const; + private: enum class TransactionStep { IDLE = 0, diff --git a/src/fsfw/cfdp/handler/UserBase.h b/src/fsfw/cfdp/handler/UserBase.h index bd26ae0d..b6c35570 100644 --- a/src/fsfw/cfdp/handler/UserBase.h +++ b/src/fsfw/cfdp/handler/UserBase.h @@ -27,8 +27,8 @@ struct TransactionFinishedParams { }; struct MetadataRecvdParams { - MetadataRecvdParams(const TransactionId& id, const EntityId& sourceId): - id(id), sourceId(sourceId) {} + MetadataRecvdParams(const TransactionId& id, const EntityId& sourceId) + : id(id), sourceId(sourceId) {} const TransactionId& id; const EntityId& sourceId; uint64_t fileSize = 0; @@ -65,7 +65,6 @@ struct FileSegmentRecvdParams { */ class UserBase { public: - explicit UserBase(HasFileSystemIF& vfs); virtual void transactionIndication(const TransactionId& id) = 0; @@ -87,7 +86,8 @@ class UserBase { virtual void suspendedIndication(const TransactionId& id, ConditionCode code) = 0; virtual void resumedIndication(const TransactionId& id, size_t progress) = 0; virtual void faultIndication(const TransactionId& id, ConditionCode code, size_t progress) = 0; - virtual void abandonedIndication(const TransactionId& id, ConditionCode code, size_t progress) = 0; + virtual void abandonedIndication(const TransactionId& id, ConditionCode code, + size_t progress) = 0; virtual void eofRecvIndication(const TransactionId& id) = 0; private: diff --git a/unittests/mocks/cfdp/UserMock.cpp b/unittests/mocks/cfdp/UserMock.cpp index a6b6ed48..876c2e81 100644 --- a/unittests/mocks/cfdp/UserMock.cpp +++ b/unittests/mocks/cfdp/UserMock.cpp @@ -7,7 +7,7 @@ cfdp::UserMock::UserMock(HasFileSystemIF& vfs) : UserBase(vfs) {} void UserMock::transactionIndication(const TransactionId& id) {} void UserMock::eofSentIndication(const TransactionId& id) {} void UserMock::abandonedIndication(const TransactionId& id, cfdp::ConditionCode code, - uint64_t progress) {} + uint64_t progress) {} void UserMock::eofRecvIndication(const TransactionId& id) {} void UserMock::transactionFinishedIndication(const TransactionFinishedParams& finishedParams) {} void UserMock::metadataRecvdIndication(const MetadataRecvdParams& params) {} @@ -15,7 +15,7 @@ void UserMock::fileSegmentRecvdIndication(const FileSegmentRecvdParams& params) void UserMock::reportIndication(const TransactionId& id, StatusReportIF& report) {} void UserMock::suspendedIndication(const TransactionId& id, ConditionCode code) {} void UserMock::resumedIndication(const TransactionId& id, size_t progress) {} -void UserMock::faultIndication(const TransactionId& id, cfdp::ConditionCode code, - size_t progress) {} - +void UserMock::faultIndication(const TransactionId& id, cfdp::ConditionCode code, size_t progress) { } + +} // namespace cfdp From 9a9085b9e61640b79286bd5edc4021cd8bc27f1e Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Mon, 29 Aug 2022 20:08:59 +0200 Subject: [PATCH 073/169] avoid duplicate code --- src/fsfw/ipc/MessageQueueMessage.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/fsfw/ipc/MessageQueueMessage.cpp b/src/fsfw/ipc/MessageQueueMessage.cpp index 6e841c7f..b0ce090f 100644 --- a/src/fsfw/ipc/MessageQueueMessage.cpp +++ b/src/fsfw/ipc/MessageQueueMessage.cpp @@ -12,7 +12,7 @@ MessageQueueMessage::MessageQueueMessage() : messageSize(getMinimumMessageSize() MessageQueueMessage::MessageQueueMessage(uint8_t* data, size_t size) : messageSize(MessageQueueMessage::HEADER_SIZE + size) { if (size <= MessageQueueMessage::MAX_DATA_SIZE) { - std::memcpy(internalBuffer + MessageQueueMessage::HEADER_SIZE, data, size); + std::memcpy(MessageQueueMessage::getData(), data, size); this->messageSize = MessageQueueMessage::HEADER_SIZE + size; } else { #if FSFW_CPP_OSTREAM_ENABLED == 1 From 0de7b66218959595826cd8962171167908c6fd87 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Wed, 31 Aug 2022 13:26:44 +0200 Subject: [PATCH 074/169] new retval for permission errors --- src/fsfw/cfdp/handler/mib.h | 10 +++++----- src/fsfw/filesystem/HasFileSystemIF.h | 21 +++++++++++---------- 2 files changed, 16 insertions(+), 15 deletions(-) diff --git a/src/fsfw/cfdp/handler/mib.h b/src/fsfw/cfdp/handler/mib.h index 7ba15cd3..11f403dd 100644 --- a/src/fsfw/cfdp/handler/mib.h +++ b/src/fsfw/cfdp/handler/mib.h @@ -28,11 +28,11 @@ struct LocalEntityCfg { struct RemoteEntityCfg { EntityId remoteId; - size_t maxFileSegmentLen; - bool closureRequested; - bool crcOnTransmission; - TransmissionModes defaultTransmissionMode; - ChecksumType defaultChecksum; + size_t maxFileSegmentLen = 2048; + bool closureRequested = false; + bool crcOnTransmission = false; + TransmissionModes defaultTransmissionMode = TransmissionModes::UNACKNOWLEDGED; + ChecksumType defaultChecksum = ChecksumType::NULL_CHECKSUM; const uint8_t version = CFDP_VERSION_2; }; diff --git a/src/fsfw/filesystem/HasFileSystemIF.h b/src/fsfw/filesystem/HasFileSystemIF.h index e7e2a529..f206d53c 100644 --- a/src/fsfw/filesystem/HasFileSystemIF.h +++ b/src/fsfw/filesystem/HasFileSystemIF.h @@ -47,20 +47,21 @@ class HasFileSystemIF { //! [EXPORT] : Invalid parameters like file name or repository path static constexpr ReturnValue_t INVALID_PARAMETERS = MAKE_RETURN_CODE(5); - static constexpr ReturnValue_t FILE_DOES_NOT_EXIST = MAKE_RETURN_CODE(7); - static constexpr ReturnValue_t FILE_ALREADY_EXISTS = MAKE_RETURN_CODE(8); - static constexpr ReturnValue_t NOT_A_FILE = MAKE_RETURN_CODE(9); - static constexpr ReturnValue_t FILE_LOCKED = MAKE_RETURN_CODE(10); + static constexpr ReturnValue_t FILE_DOES_NOT_EXIST = MAKE_RETURN_CODE(10); + static constexpr ReturnValue_t FILE_ALREADY_EXISTS = MAKE_RETURN_CODE(11); + static constexpr ReturnValue_t NOT_A_FILE = MAKE_RETURN_CODE(12); + static constexpr ReturnValue_t FILE_LOCKED = MAKE_RETURN_CODE(13); + static constexpr ReturnValue_t PERMISSION_DENIED = MAKE_RETURN_CODE(14); - static constexpr ReturnValue_t DIRECTORY_DOES_NOT_EXIST = MAKE_RETURN_CODE(15); - static constexpr ReturnValue_t DIRECTORY_ALREADY_EXISTS = MAKE_RETURN_CODE(16); - static constexpr ReturnValue_t NOT_A_DIRECTORY = MAKE_RETURN_CODE(17); - static constexpr ReturnValue_t DIRECTORY_NOT_EMPTY = MAKE_RETURN_CODE(18); + static constexpr ReturnValue_t DIRECTORY_DOES_NOT_EXIST = MAKE_RETURN_CODE(21); + static constexpr ReturnValue_t DIRECTORY_ALREADY_EXISTS = MAKE_RETURN_CODE(22); + static constexpr ReturnValue_t NOT_A_DIRECTORY = MAKE_RETURN_CODE(23); + static constexpr ReturnValue_t DIRECTORY_NOT_EMPTY = MAKE_RETURN_CODE(24); //! [EXPORT] : P1: Sequence number missing - static constexpr ReturnValue_t SEQUENCE_PACKET_MISSING_WRITE = MAKE_RETURN_CODE(15); + static constexpr ReturnValue_t SEQUENCE_PACKET_MISSING_WRITE = MAKE_RETURN_CODE(30); //! [EXPORT] : P1: Sequence number missing - static constexpr ReturnValue_t SEQUENCE_PACKET_MISSING_READ = MAKE_RETURN_CODE(16); + static constexpr ReturnValue_t SEQUENCE_PACKET_MISSING_READ = MAKE_RETURN_CODE(31); virtual ~HasFileSystemIF() = default; From db84dcd3ce04bff9af952a693640a6722ed4b2d5 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Fri, 2 Sep 2022 11:12:16 +0200 Subject: [PATCH 075/169] afmt --- src/fsfw/pus/Service11TelecommandScheduling.tpp | 4 ++-- src/fsfw/tmtcservices/SpacePacketParser.h | 5 +---- unittests/datapoollocal/CMakeLists.txt | 9 +++------ unittests/pus/CMakeLists.txt | 4 +--- unittests/pus/testService11.cpp | 4 ++-- 5 files changed, 9 insertions(+), 17 deletions(-) diff --git a/src/fsfw/pus/Service11TelecommandScheduling.tpp b/src/fsfw/pus/Service11TelecommandScheduling.tpp index aa096855..9016af80 100644 --- a/src/fsfw/pus/Service11TelecommandScheduling.tpp +++ b/src/fsfw/pus/Service11TelecommandScheduling.tpp @@ -566,7 +566,7 @@ inline ReturnValue_t Service11TelecommandScheduling::getMapFilterFr if (result != returnvalue::OK) { return result; } - if(fromTimestamp > toTimestamp) { + if (fromTimestamp > toTimestamp) { return INVALID_TIME_WINDOW; } itBegin = telecommandMap.begin(); @@ -575,7 +575,7 @@ inline ReturnValue_t Service11TelecommandScheduling::getMapFilterFr itBegin++; } - //start looking for end beginning at begin + // start looking for end beginning at begin itEnd = itBegin; while (itEnd->first <= toTimestamp && itEnd != telecommandMap.end()) { itEnd++; diff --git a/src/fsfw/tmtcservices/SpacePacketParser.h b/src/fsfw/tmtcservices/SpacePacketParser.h index 3a1b4d16..ea0a2feb 100644 --- a/src/fsfw/tmtcservices/SpacePacketParser.h +++ b/src/fsfw/tmtcservices/SpacePacketParser.h @@ -17,7 +17,6 @@ */ class SpacePacketParser { public: - struct FoundPacketInfo { size_t startIdx = 0; size_t sizeFound = 0; @@ -51,9 +50,7 @@ class SpacePacketParser { ReturnValue_t parseSpacePackets(const uint8_t** buffer, const size_t maxSize, FoundPacketInfo& packetInfo); - size_t getAmountRead() { - return amountRead; - } + size_t getAmountRead() { return amountRead; } void reset() { nextStartIdx = 0; diff --git a/unittests/datapoollocal/CMakeLists.txt b/unittests/datapoollocal/CMakeLists.txt index 016645fd..2c7a573f 100644 --- a/unittests/datapoollocal/CMakeLists.txt +++ b/unittests/datapoollocal/CMakeLists.txt @@ -1,6 +1,3 @@ -target_sources(${FSFW_TEST_TGT} PRIVATE - testLocalPoolVariable.cpp - testLocalPoolVector.cpp - testDataSet.cpp - testLocalPoolManager.cpp -) +target_sources( + ${FSFW_TEST_TGT} PRIVATE testLocalPoolVariable.cpp testLocalPoolVector.cpp + testDataSet.cpp testLocalPoolManager.cpp) diff --git a/unittests/pus/CMakeLists.txt b/unittests/pus/CMakeLists.txt index ecd7fb49..7f615a50 100644 --- a/unittests/pus/CMakeLists.txt +++ b/unittests/pus/CMakeLists.txt @@ -1,3 +1 @@ -target_sources(${FSFW_TEST_TGT} PRIVATE - testService11.cpp -) +target_sources(${FSFW_TEST_TGT} PRIVATE testService11.cpp) diff --git a/unittests/pus/testService11.cpp b/unittests/pus/testService11.cpp index 54279543..bd3b22ad 100644 --- a/unittests/pus/testService11.cpp +++ b/unittests/pus/testService11.cpp @@ -7,8 +7,8 @@ #include "tmtc/pusIds.h" TEST_CASE("PUS Service 11", "[pus-srvc11]") { - Service11TelecommandScheduling<13> pusService11({objects::PUS_SERVICE_11_TC_SCHEDULER, - apid::DEFAULT_APID, pus::PUS_SERVICE_11}, nullptr); + Service11TelecommandScheduling<13> pusService11( + {objects::PUS_SERVICE_11_TC_SCHEDULER, apid::DEFAULT_APID, pus::PUS_SERVICE_11}, nullptr); // TODO test something... } \ No newline at end of file From dc79b7ba00ba568e25f0c18f68ea3928149c9ce2 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Fri, 2 Sep 2022 11:38:46 +0200 Subject: [PATCH 076/169] delete metadata after processing --- src/fsfw/cfdp/handler/DestHandler.cpp | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/fsfw/cfdp/handler/DestHandler.cpp b/src/fsfw/cfdp/handler/DestHandler.cpp index 7271c19c..e7d14db0 100644 --- a/src/fsfw/cfdp/handler/DestHandler.cpp +++ b/src/fsfw/cfdp/handler/DestHandler.cpp @@ -21,13 +21,15 @@ ReturnValue_t cfdp::DestHandler::performStateMachine() { if (step == TransactionStep::IDLE) { ReturnValue_t status = returnvalue::OK; ReturnValue_t result; - for (const auto& info : dp.packetListRef) { - if (info.pduType == PduType::FILE_DIRECTIVE and - info.directiveType == FileDirectives::METADATA) { - result = handleMetadataPdu(info); + for(auto infoIter = dp.packetListRef.begin(); infoIter != dp.packetListRef.end();) { + if (infoIter->pduType == PduType::FILE_DIRECTIVE and + infoIter->directiveType == FileDirectives::METADATA) { + result = handleMetadataPdu(*infoIter); if (result != OK) { status = result; } + fp.tcStore->deleteData(infoIter->storeId); + dp.packetListRef.erase(infoIter++); } } if (step != TransactionStep::IDLE) { From eae75b29e7966afc0ef11fc2fdc4a0c6d7558bc3 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Fri, 2 Sep 2022 11:58:16 +0200 Subject: [PATCH 077/169] start file data pdu processing --- src/fsfw/cfdp/handler/DestHandler.cpp | 40 +++++++++++++++++++++++---- src/fsfw/cfdp/handler/DestHandler.h | 1 + src/fsfw/cfdp/pdu/FileDataInfo.h | 14 +++++----- 3 files changed, 42 insertions(+), 13 deletions(-) diff --git a/src/fsfw/cfdp/handler/DestHandler.cpp b/src/fsfw/cfdp/handler/DestHandler.cpp index e7d14db0..54e3753e 100644 --- a/src/fsfw/cfdp/handler/DestHandler.cpp +++ b/src/fsfw/cfdp/handler/DestHandler.cpp @@ -2,6 +2,7 @@ #include +#include "fsfw/cfdp/pdu/FileDataReader.h" #include "fsfw/cfdp/pdu/HeaderReader.h" #include "fsfw/objectmanager.h" #include "fsfw/serviceinterface.h" @@ -18,28 +19,41 @@ cfdp::DestHandler::DestHandler(DestHandlerParams params, FsfwParams fsfwParams) } ReturnValue_t cfdp::DestHandler::performStateMachine() { + ReturnValue_t result; + ReturnValue_t status = returnvalue::OK; if (step == TransactionStep::IDLE) { - ReturnValue_t status = returnvalue::OK; - ReturnValue_t result; - for(auto infoIter = dp.packetListRef.begin(); infoIter != dp.packetListRef.end();) { + for (auto infoIter = dp.packetListRef.begin(); infoIter != dp.packetListRef.end();) { if (infoIter->pduType == PduType::FILE_DIRECTIVE and infoIter->directiveType == FileDirectives::METADATA) { result = handleMetadataPdu(*infoIter); if (result != OK) { status = result; } - fp.tcStore->deleteData(infoIter->storeId); + // metadata packet was deleted in metadata handler because a store guard is used dp.packetListRef.erase(infoIter++); } } + if (step == TransactionStep::IDLE) { + // To decrease the already high complexity of the software, all packets arriving before + // a metadata PDU are deleted. + for (auto infoIter = dp.packetListRef.begin(); infoIter != dp.packetListRef.end();) { + fp.tcStore->deleteData(infoIter->storeId); + } + dp.packetListRef.clear(); + } + if (step != TransactionStep::IDLE) { return CALL_FSM_AGAIN; } return status; } if (cfdpState == CfdpStates::BUSY_CLASS_1_NACKED) { - for (const auto& info : dp.packetListRef) { - if (info.pduType == PduType::FILE_DATA) { + for (auto infoIter = dp.packetListRef.begin(); infoIter != dp.packetListRef.end();) { + if (infoIter->pduType == PduType::FILE_DATA) { + result = handleFileDataPdu(*infoIter); + if (result != OK) { + status = result; + } } } return returnvalue::OK; @@ -77,6 +91,7 @@ ReturnValue_t cfdp::DestHandler::initialize() { } return returnvalue::OK; } + ReturnValue_t cfdp::DestHandler::handleMetadataPdu(const PacketInfo& info) { // Process metadata PDU auto constAccessorPair = fp.tcStore->getData(info.storeId); @@ -102,6 +117,19 @@ ReturnValue_t cfdp::DestHandler::handleMetadataPdu(const PacketInfo& info) { return startTransaction(reader, metadataInfo); } +ReturnValue_t cfdp::DestHandler::handleFileDataPdu(const cfdp::PacketInfo& info) { + // Process file data PDU + auto constAccessorPair = fp.tcStore->getData(info.storeId); + if (constAccessorPair.first != OK) { + // TODO: This is not a CFDP error. Event and/or warning? + cfdp::FileSize offset; + FileDataInfo fdInfo(offset); + FileDataReader reader(constAccessorPair.second.data(), constAccessorPair.second.size(), fdInfo); + return constAccessorPair.first; + } + return returnvalue::OK; +} + ReturnValue_t cfdp::DestHandler::handleMetadataParseError(const uint8_t* rawData, size_t maxSize) { // TODO: try to extract destination ID for error // TODO: Invalid metadata PDU. diff --git a/src/fsfw/cfdp/handler/DestHandler.h b/src/fsfw/cfdp/handler/DestHandler.h index 74668638..40bf655c 100644 --- a/src/fsfw/cfdp/handler/DestHandler.h +++ b/src/fsfw/cfdp/handler/DestHandler.h @@ -77,6 +77,7 @@ class DestHandler { ReturnValue_t initialize(); ReturnValue_t handleMetadataPdu(const PacketInfo& info); + ReturnValue_t handleFileDataPdu(const PacketInfo& info); ReturnValue_t handleMetadataParseError(const uint8_t* rawData, size_t maxSize); [[nodiscard]] CfdpStates getCfdpState() const; diff --git a/src/fsfw/cfdp/pdu/FileDataInfo.h b/src/fsfw/cfdp/pdu/FileDataInfo.h index 7fd573db..36908d8b 100644 --- a/src/fsfw/cfdp/pdu/FileDataInfo.h +++ b/src/fsfw/cfdp/pdu/FileDataInfo.h @@ -6,25 +6,25 @@ class FileDataInfo { public: - FileDataInfo(cfdp::FileSize& offset); + explicit FileDataInfo(cfdp::FileSize& offset); FileDataInfo(cfdp::FileSize& offset, const uint8_t* fileData, size_t fileSize); - size_t getSerializedSize(bool largeFile = false) const; + [[nodiscard]] size_t getSerializedSize(bool largeFile = false) const; cfdp::FileSize& getOffset(); const uint8_t* getFileData(size_t* fileSize = nullptr) const; void setFileData(const uint8_t* fileData, size_t fileSize); - cfdp::SegmentMetadataFlag getSegmentMetadataFlag() const; - cfdp::SegmentationControl getSegmentationControl() const; - cfdp::RecordContinuationState getRecordContinuationState() const; + [[nodiscard]] cfdp::SegmentMetadataFlag getSegmentMetadataFlag() const; + [[nodiscard]] cfdp::SegmentationControl getSegmentationControl() const; + [[nodiscard]] cfdp::RecordContinuationState getRecordContinuationState() const; void setRecordContinuationState(cfdp::RecordContinuationState recContState); void setSegmentationControl(cfdp::SegmentationControl segCtrl); - size_t getSegmentMetadataLen() const; + [[nodiscard]] size_t getSegmentMetadataLen() const; void setSegmentMetadataLen(size_t len); void setSegmentMetadata(const uint8_t* ptr); - bool hasSegmentMetadata() const; + [[nodiscard]] bool hasSegmentMetadata() const; void setSegmentMetadataFlag(bool enable); ReturnValue_t addSegmentMetadataInfo(cfdp::RecordContinuationState recContState, const uint8_t* segmentMetadata, size_t segmentMetadataLen); From c90d1c8071bf1284393668ada5930180724a4fd7 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Fri, 2 Sep 2022 14:39:53 +0200 Subject: [PATCH 078/169] continue dest handler impl --- docs/conf.py | 18 ++--- scripts/helper.py | 14 +++- src/fsfw/cfdp/FileSize.h | 16 ++-- src/fsfw/cfdp/handler/DestHandler.cpp | 75 ++++++++++++++++--- src/fsfw/cfdp/handler/DestHandler.h | 11 +-- src/fsfw/cfdp/handler/UserBase.h | 2 + src/fsfw/cfdp/pdu/CMakeLists.txt | 4 +- src/fsfw/cfdp/pdu/EofInfo.h | 8 +- ...EofPduSerializer.cpp => EofPduCreator.cpp} | 15 ++-- .../{EofPduSerializer.h => EofPduCreator.h} | 6 +- ...ofPduDeserializer.cpp => EofPduReader.cpp} | 6 +- .../{EofPduDeserializer.h => EofPduReader.h} | 6 +- src/fsfw/cfdp/pdu/FileDataInfo.cpp | 12 +-- unittests/cfdp/pdu/testEofPdu.cpp | 16 ++-- 14 files changed, 135 insertions(+), 74 deletions(-) rename src/fsfw/cfdp/pdu/{EofPduSerializer.cpp => EofPduCreator.cpp} (71%) rename src/fsfw/cfdp/pdu/{EofPduSerializer.h => EofPduCreator.h} (74%) rename src/fsfw/cfdp/pdu/{EofPduDeserializer.cpp => EofPduReader.cpp} (92%) rename src/fsfw/cfdp/pdu/{EofPduDeserializer.h => EofPduReader.h} (60%) diff --git a/docs/conf.py b/docs/conf.py index 62b17192..a2cb73be 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -17,12 +17,12 @@ # -- Project information ----------------------------------------------------- -project = 'Flight Software Framework' -copyright = '2021, Institute of Space Systems (IRS)' -author = 'Institute of Space Systems (IRS)' +project = "Flight Software Framework" +copyright = "2021, Institute of Space Systems (IRS)" +author = "Institute of Space Systems (IRS)" # The full version, including alpha/beta/rc tags -release = '2.0.1' +release = "2.0.1" # -- General configuration --------------------------------------------------- @@ -30,17 +30,17 @@ release = '2.0.1' # Add any Sphinx extension module names here, as strings. They can be # extensions coming with Sphinx (named 'sphinx.ext.*') or your custom # ones. -extensions = [ "breathe" ] +extensions = ["breathe"] breathe_default_project = "fsfw" # Add any paths that contain templates here, relative to this directory. -templates_path = ['_templates'] +templates_path = ["_templates"] # List of patterns, relative to source directory, that match files and # directories to ignore when looking for source files. # This pattern also affects html_static_path and html_extra_path. -exclude_patterns = ['_build', 'Thumbs.db', '.DS_Store'] +exclude_patterns = ["_build", "Thumbs.db", ".DS_Store"] # -- Options for HTML output ------------------------------------------------- @@ -48,9 +48,9 @@ exclude_patterns = ['_build', 'Thumbs.db', '.DS_Store'] # The theme to use for HTML and HTML Help pages. See the documentation for # a list of builtin themes. # -html_theme = 'alabaster' +html_theme = "alabaster" # Add any paths that contain custom static files (such as style sheets) here, # relative to this directory. They are copied after the builtin static files, # so a file named "default.css" will overwrite the builtin "default.css". -html_static_path = [] \ No newline at end of file +html_static_path = [] diff --git a/scripts/helper.py b/scripts/helper.py index 0ced7186..484e5227 100755 --- a/scripts/helper.py +++ b/scripts/helper.py @@ -51,7 +51,7 @@ def main(): parser.add_argument( "-g", "--generators", - default = "Ninja", + default="Ninja", action="store", help="CMake generators", ) @@ -165,10 +165,18 @@ def create_tests_build_cfg(args): os.mkdir(UNITTEST_FOLDER_NAME) os.chdir(UNITTEST_FOLDER_NAME) if args.windows: - cmake_cmd = 'cmake -G "' + args.generators + '" -DFSFW_OSAL=host -DFSFW_BUILD_TESTS=ON \ + cmake_cmd = ( + 'cmake -G "' + + args.generators + + '" -DFSFW_OSAL=host -DFSFW_BUILD_TESTS=ON \ -DGCOVR_PATH="py -m gcovr" ..' + ) else: - cmake_cmd = 'cmake -G "' + args.generators + '" -DFSFW_OSAL=host -DFSFW_BUILD_TESTS=ON ..' + cmake_cmd = ( + 'cmake -G "' + + args.generators + + '" -DFSFW_OSAL=host -DFSFW_BUILD_TESTS=ON ..' + ) cmd_runner(cmake_cmd) os.chdir("..") diff --git a/src/fsfw/cfdp/FileSize.h b/src/fsfw/cfdp/FileSize.h index 377d08ce..227555e6 100644 --- a/src/fsfw/cfdp/FileSize.h +++ b/src/fsfw/cfdp/FileSize.h @@ -8,10 +8,12 @@ namespace cfdp { struct FileSize : public SerializeIF { public: - FileSize() : largeFile(false){}; + FileSize() = default; explicit FileSize(uint64_t fileSize, bool isLarge = false) { setFileSize(fileSize, isLarge); }; + [[nodiscard]] uint64_t value() const { return fileSize; } + ReturnValue_t serialize(bool isLarge, uint8_t **buffer, size_t *size, size_t maxSize, Endianness streamEndianness) { this->largeFile = isLarge; @@ -50,20 +52,20 @@ struct FileSize : public SerializeIF { } } - ReturnValue_t setFileSize(uint64_t fileSize, bool largeFile) { + ReturnValue_t setFileSize(uint64_t fileSize_, bool largeFile_) { if (not largeFile and fileSize > UINT32_MAX) { // TODO: emit warning here return returnvalue::FAILED; } - this->fileSize = fileSize; - this->largeFile = largeFile; + this->fileSize = fileSize_; + this->largeFile = largeFile_; return returnvalue::OK; } [[nodiscard]] bool isLargeFile() const { return largeFile; } - uint64_t getSize(bool *largeFile = nullptr) const { - if (largeFile != nullptr) { - *largeFile = this->largeFile; + uint64_t getSize(bool *largeFile_ = nullptr) const { + if (largeFile_ != nullptr) { + *largeFile_ = this->largeFile; } return fileSize; } diff --git a/src/fsfw/cfdp/handler/DestHandler.cpp b/src/fsfw/cfdp/handler/DestHandler.cpp index 54e3753e..6aeac040 100644 --- a/src/fsfw/cfdp/handler/DestHandler.cpp +++ b/src/fsfw/cfdp/handler/DestHandler.cpp @@ -2,10 +2,11 @@ #include +#include "fsfw/FSFW.h" +#include "fsfw/cfdp/pdu/EofPduReader.h" #include "fsfw/cfdp/pdu/FileDataReader.h" #include "fsfw/cfdp/pdu/HeaderReader.h" #include "fsfw/objectmanager.h" -#include "fsfw/serviceinterface.h" using namespace returnvalue; @@ -29,7 +30,7 @@ ReturnValue_t cfdp::DestHandler::performStateMachine() { if (result != OK) { status = result; } - // metadata packet was deleted in metadata handler because a store guard is used + // Store data was deleted in PDU handler because a store guard is used dp.packetListRef.erase(infoIter++); } } @@ -54,9 +55,15 @@ ReturnValue_t cfdp::DestHandler::performStateMachine() { if (result != OK) { status = result; } + // Store data was deleted in PDU handler because a store guard is used + dp.packetListRef.erase(infoIter++); + } + if (infoIter->pduType == PduType::FILE_DIRECTIVE and + infoIter->directiveType == FileDirectives::EOF_DIRECTIVE) { + result = handleEofPdu(*infoIter); } } - return returnvalue::OK; + return OK; } if (cfdpState == CfdpStates::BUSY_CLASS_2_ACKED) { // TODO: Will be implemented at a later stage @@ -64,32 +71,32 @@ ReturnValue_t cfdp::DestHandler::performStateMachine() { sif::warning << "CFDP state machine for acknowledged mode not implemented yet" << std::endl; #endif } - return returnvalue::OK; + return OK; } ReturnValue_t cfdp::DestHandler::passPacket(PacketInfo packet) { if (dp.packetListRef.full()) { - return returnvalue::FAILED; + return FAILED; } dp.packetListRef.push_back(packet); - return returnvalue::OK; + return OK; } ReturnValue_t cfdp::DestHandler::initialize() { if (fp.tmStore == nullptr) { fp.tmStore = ObjectManager::instance()->get(objects::TM_STORE); if (fp.tmStore == nullptr) { - return returnvalue::FAILED; + return FAILED; } } if (fp.tcStore == nullptr) { fp.tcStore = ObjectManager::instance()->get(objects::TC_STORE); if (fp.tcStore == nullptr) { - return returnvalue::FAILED; + return FAILED; } } - return returnvalue::OK; + return OK; } ReturnValue_t cfdp::DestHandler::handleMetadataPdu(const PacketInfo& info) { @@ -122,11 +129,55 @@ ReturnValue_t cfdp::DestHandler::handleFileDataPdu(const cfdp::PacketInfo& info) auto constAccessorPair = fp.tcStore->getData(info.storeId); if (constAccessorPair.first != OK) { // TODO: This is not a CFDP error. Event and/or warning? - cfdp::FileSize offset; - FileDataInfo fdInfo(offset); - FileDataReader reader(constAccessorPair.second.data(), constAccessorPair.second.size(), fdInfo); return constAccessorPair.first; } + cfdp::FileSize offset; + FileDataInfo fdInfo(offset); + FileDataReader reader(constAccessorPair.second.data(), constAccessorPair.second.size(), fdInfo); + ReturnValue_t result = reader.parseData(); + if (result != OK) { + return result; + } + size_t fileSegmentLen = 0; + const uint8_t* fileData = fdInfo.getFileData(&fileSegmentLen); + FileOpParams fileOpParams(tp.sourceName.data(), fileSegmentLen); + result = dp.user.vfs.writeToFile(fileOpParams, fileData); + if (dp.cfg.indicCfg.fileSegmentRecvIndicRequired) { + FileSegmentRecvdParams segParams; + segParams.offset = offset.value(); + segParams.id = tp.transactionId; + segParams.length = fileSegmentLen; + segParams.recContState = fdInfo.getRecordContinuationState(); + size_t segmentMetadatLen = 0; + auto* segMetadata = fdInfo.getSegmentMetadata(&segmentMetadatLen); + segParams.segmentMetadata = {segMetadata, segmentMetadatLen}; + dp.user.fileSegmentRecvdIndication(segParams); + } + if (result != returnvalue::OK) { + // TODO: Proper Error handling +#if FSFW_CPP_OSTREAM_ENABLED == 1 + sif::error << "File write error" << std::endl; +#endif + } + return result; +} + +ReturnValue_t cfdp::DestHandler::handleEofPdu(const cfdp::PacketInfo& info) { + // Process EOF PDU + auto constAccessorPair = fp.tcStore->getData(info.storeId); + if (constAccessorPair.first != OK) { + // TODO: This is not a CFDP error. Event and/or warning? + return constAccessorPair.first; + } + EofInfo eofInfo(nullptr); + EofPduReader reader(constAccessorPair.second.data(), constAccessorPair.second.size(), eofInfo); + ReturnValue_t result = reader.parseData(); + if (result != OK) { + return result; + } + if (eofInfo.getConditionCode() == ConditionCode::NO_ERROR) { + tp.crc = eofInfo.getChecksum(); + } return returnvalue::OK; } diff --git a/src/fsfw/cfdp/handler/DestHandler.h b/src/fsfw/cfdp/handler/DestHandler.h index 40bf655c..8215d22d 100644 --- a/src/fsfw/cfdp/handler/DestHandler.h +++ b/src/fsfw/cfdp/handler/DestHandler.h @@ -76,10 +76,6 @@ class DestHandler { ReturnValue_t initialize(); - ReturnValue_t handleMetadataPdu(const PacketInfo& info); - ReturnValue_t handleFileDataPdu(const PacketInfo& info); - ReturnValue_t handleMetadataParseError(const uint8_t* rawData, size_t maxSize); - [[nodiscard]] CfdpStates getCfdpState() const; private: @@ -96,12 +92,13 @@ class DestHandler { : sourceName(maxFileNameLen), destName(maxFileNameLen) {} ChecksumType checksumType = ChecksumType::NULL_CHECKSUM; - bool closureRequested{}; + bool closureRequested = false; std::vector sourceName; std::vector destName; cfdp::FileSize fileSize; TransactionId transactionId; PduConfig pduConf; + uint32_t crc = 0; RemoteEntityCfg* remoteCfg = nullptr; }; @@ -114,6 +111,10 @@ class DestHandler { TransactionParams tp; ReturnValue_t startTransaction(MetadataPduReader& reader, MetadataInfo& info); + ReturnValue_t handleMetadataPdu(const PacketInfo& info); + ReturnValue_t handleFileDataPdu(const PacketInfo& info); + ReturnValue_t handleEofPdu(const PacketInfo& info); + ReturnValue_t handleMetadataParseError(const uint8_t* rawData, size_t maxSize); }; } // namespace cfdp diff --git a/src/fsfw/cfdp/handler/UserBase.h b/src/fsfw/cfdp/handler/UserBase.h index b6c35570..f9db4f49 100644 --- a/src/fsfw/cfdp/handler/UserBase.h +++ b/src/fsfw/cfdp/handler/UserBase.h @@ -64,6 +64,8 @@ struct FileSegmentRecvdParams { * @param vfs Virtual Filestore Object. Will be used for all file operations */ class UserBase { + friend class DestHandler; + public: explicit UserBase(HasFileSystemIF& vfs); diff --git a/src/fsfw/cfdp/pdu/CMakeLists.txt b/src/fsfw/cfdp/pdu/CMakeLists.txt index 91b5ad2e..77386d20 100644 --- a/src/fsfw/cfdp/pdu/CMakeLists.txt +++ b/src/fsfw/cfdp/pdu/CMakeLists.txt @@ -9,8 +9,8 @@ target_sources( AckPduSerializer.cpp AckPduDeserializer.cpp EofInfo.cpp - EofPduSerializer.cpp - EofPduDeserializer.cpp + EofPduCreator.cpp + EofPduReader.cpp NakInfo.cpp NakPduSerializer.cpp NakPduDeserializer.cpp diff --git a/src/fsfw/cfdp/pdu/EofInfo.h b/src/fsfw/cfdp/pdu/EofInfo.h index fa8adfd9..4b4fb057 100644 --- a/src/fsfw/cfdp/pdu/EofInfo.h +++ b/src/fsfw/cfdp/pdu/EofInfo.h @@ -7,16 +7,16 @@ struct EofInfo { public: - EofInfo(EntityIdTlv* faultLoc = nullptr); + explicit EofInfo(EntityIdTlv* faultLoc = nullptr); EofInfo(cfdp::ConditionCode conditionCode, uint32_t checksum, cfdp::FileSize fileSize, EntityIdTlv* faultLoc = nullptr); size_t getSerializedSize(bool fssLarge = false); - uint32_t getChecksum() const; - cfdp::ConditionCode getConditionCode() const; + [[nodiscard]] uint32_t getChecksum() const; + [[nodiscard]] cfdp::ConditionCode getConditionCode() const; - EntityIdTlv* getFaultLoc() const; + [[nodiscard]] EntityIdTlv* getFaultLoc() const; cfdp::FileSize& getFileSize(); void setChecksum(uint32_t checksum); void setConditionCode(cfdp::ConditionCode conditionCode); diff --git a/src/fsfw/cfdp/pdu/EofPduSerializer.cpp b/src/fsfw/cfdp/pdu/EofPduCreator.cpp similarity index 71% rename from src/fsfw/cfdp/pdu/EofPduSerializer.cpp rename to src/fsfw/cfdp/pdu/EofPduCreator.cpp index 94dee640..20b8c64a 100644 --- a/src/fsfw/cfdp/pdu/EofPduSerializer.cpp +++ b/src/fsfw/cfdp/pdu/EofPduCreator.cpp @@ -1,19 +1,16 @@ -#include "EofPduSerializer.h" +#include "EofPduCreator.h" #include "fsfw/FSFW.h" -#include "fsfw/serviceinterface.h" -EofPduSerializer::EofPduSerializer(PduConfig &conf, EofInfo &info) +EofPduCreator::EofPduCreator(PduConfig &conf, EofInfo &info) : FileDirectiveCreator(conf, cfdp::FileDirectives::EOF_DIRECTIVE, 9), info(info) { - setDirectiveDataFieldLen(info.getSerializedSize(getLargeFileFlag())); + setDirectiveDataFieldLen(info.getSerializedSize(HeaderCreator::getLargeFileFlag())); } -size_t EofPduSerializer::getSerializedSize() const { - return FileDirectiveCreator::getWholePduSize(); -} +size_t EofPduCreator::getSerializedSize() const { return FileDirectiveCreator::getWholePduSize(); } -ReturnValue_t EofPduSerializer::serialize(uint8_t **buffer, size_t *size, size_t maxSize, - Endianness streamEndianness) const { +ReturnValue_t EofPduCreator::serialize(uint8_t **buffer, size_t *size, size_t maxSize, + Endianness streamEndianness) const { ReturnValue_t result = FileDirectiveCreator::serialize(buffer, size, maxSize, streamEndianness); if (result != returnvalue::OK) { return result; diff --git a/src/fsfw/cfdp/pdu/EofPduSerializer.h b/src/fsfw/cfdp/pdu/EofPduCreator.h similarity index 74% rename from src/fsfw/cfdp/pdu/EofPduSerializer.h rename to src/fsfw/cfdp/pdu/EofPduCreator.h index 737e8dee..7f7a25ab 100644 --- a/src/fsfw/cfdp/pdu/EofPduSerializer.h +++ b/src/fsfw/cfdp/pdu/EofPduCreator.h @@ -5,11 +5,11 @@ #include "fsfw/cfdp/pdu/FileDirectiveCreator.h" #include "fsfw/cfdp/tlv/EntityIdTlv.h" -class EofPduSerializer : public FileDirectiveCreator { +class EofPduCreator : public FileDirectiveCreator { public: - EofPduSerializer(PduConfig& conf, EofInfo& info); + EofPduCreator(PduConfig& conf, EofInfo& info); - size_t getSerializedSize() const override; + [[nodiscard]] size_t getSerializedSize() const override; ReturnValue_t serialize(uint8_t** buffer, size_t* size, size_t maxSize, Endianness streamEndianness) const override; diff --git a/src/fsfw/cfdp/pdu/EofPduDeserializer.cpp b/src/fsfw/cfdp/pdu/EofPduReader.cpp similarity index 92% rename from src/fsfw/cfdp/pdu/EofPduDeserializer.cpp rename to src/fsfw/cfdp/pdu/EofPduReader.cpp index 890d7e9a..c80c501c 100644 --- a/src/fsfw/cfdp/pdu/EofPduDeserializer.cpp +++ b/src/fsfw/cfdp/pdu/EofPduReader.cpp @@ -1,12 +1,12 @@ -#include "EofPduDeserializer.h" +#include "EofPduReader.h" #include "fsfw/FSFW.h" #include "fsfw/serviceinterface.h" -EofPduDeserializer::EofPduDeserializer(const uint8_t* pduBuf, size_t maxSize, EofInfo& eofInfo) +EofPduReader::EofPduReader(const uint8_t* pduBuf, size_t maxSize, EofInfo& eofInfo) : FileDirectiveReader(pduBuf, maxSize), info(eofInfo) {} -ReturnValue_t EofPduDeserializer::parseData() { +ReturnValue_t EofPduReader::parseData() { ReturnValue_t result = FileDirectiveReader::parseData(); if (result != returnvalue::OK) { return result; diff --git a/src/fsfw/cfdp/pdu/EofPduDeserializer.h b/src/fsfw/cfdp/pdu/EofPduReader.h similarity index 60% rename from src/fsfw/cfdp/pdu/EofPduDeserializer.h rename to src/fsfw/cfdp/pdu/EofPduReader.h index ce918475..456ea0dc 100644 --- a/src/fsfw/cfdp/pdu/EofPduDeserializer.h +++ b/src/fsfw/cfdp/pdu/EofPduReader.h @@ -4,11 +4,11 @@ #include "EofInfo.h" #include "fsfw/cfdp/pdu/FileDirectiveReader.h" -class EofPduDeserializer : public FileDirectiveReader { +class EofPduReader : public FileDirectiveReader { public: - EofPduDeserializer(const uint8_t* pduBuf, size_t maxSize, EofInfo& eofInfo); + EofPduReader(const uint8_t* pduBuf, size_t maxSize, EofInfo& eofInfo); - virtual ReturnValue_t parseData() override; + ReturnValue_t parseData() override; private: EofInfo& info; diff --git a/src/fsfw/cfdp/pdu/FileDataInfo.cpp b/src/fsfw/cfdp/pdu/FileDataInfo.cpp index 39b6472d..19fc00cd 100644 --- a/src/fsfw/cfdp/pdu/FileDataInfo.cpp +++ b/src/fsfw/cfdp/pdu/FileDataInfo.cpp @@ -57,16 +57,16 @@ ReturnValue_t FileDataInfo::addSegmentMetadataInfo(cfdp::RecordContinuationState return returnvalue::OK; } -const uint8_t *FileDataInfo::getFileData(size_t *fileSize) const { - if (fileSize != nullptr) { - *fileSize = this->fileSize; +const uint8_t *FileDataInfo::getFileData(size_t *fileSize_) const { + if (fileSize_ != nullptr) { + *fileSize_ = this->fileSize; } return fileData; } -const uint8_t *FileDataInfo::getSegmentMetadata(size_t *segmentMetadataLen) { - if (segmentMetadataLen != nullptr) { - *segmentMetadataLen = this->segmentMetadataLen; +const uint8_t *FileDataInfo::getSegmentMetadata(size_t *segmentMetadataLen_) { + if (segmentMetadataLen_ != nullptr) { + *segmentMetadataLen_ = this->segmentMetadataLen; } return segmentMetadata; } diff --git a/unittests/cfdp/pdu/testEofPdu.cpp b/unittests/cfdp/pdu/testEofPdu.cpp index 332035d0..c6718e20 100644 --- a/unittests/cfdp/pdu/testEofPdu.cpp +++ b/unittests/cfdp/pdu/testEofPdu.cpp @@ -1,8 +1,8 @@ #include #include -#include "fsfw/cfdp/pdu/EofPduDeserializer.h" -#include "fsfw/cfdp/pdu/EofPduSerializer.h" +#include "fsfw/cfdp/pdu/EofPduCreator.h" +#include "fsfw/cfdp/pdu/EofPduReader.h" #include "fsfw/globalfunctions/arrayprinter.h" TEST_CASE("EOF PDU", "[cfdp][pdu]") { @@ -22,7 +22,7 @@ TEST_CASE("EOF PDU", "[cfdp][pdu]") { PduConfig pduConf(sourceId, destId, TransmissionModes::ACKNOWLEDGED, seqNum); - auto eofSerializer = EofPduSerializer(pduConf, eofInfo); + auto eofSerializer = EofPduCreator(pduConf, eofInfo); SECTION("Serialize") { result = eofSerializer.serialize(&bufPtr, &sz, buf.size(), SerializeIF::Endianness::NETWORK); REQUIRE(result == returnvalue::OK); @@ -45,7 +45,7 @@ TEST_CASE("EOF PDU", "[cfdp][pdu]") { eofInfo.setFileSize(0x10ffffff10, true); pduConf.largeFile = true; // Should serialize with fault location now - auto serializeWithFaultLocation = EofPduSerializer(pduConf, eofInfo); + auto serializeWithFaultLocation = EofPduCreator(pduConf, eofInfo); bufPtr = buf.data(); sz = 0; result = serializeWithFaultLocation.serialize(&bufPtr, &sz, buf.size(), @@ -83,7 +83,7 @@ TEST_CASE("EOF PDU", "[cfdp][pdu]") { REQUIRE(result == returnvalue::OK); EntityIdTlv tlv(destId); EofInfo emptyInfo(&tlv); - auto deserializer = EofPduDeserializer(buf.data(), buf.size(), emptyInfo); + auto deserializer = EofPduReader(buf.data(), buf.size(), emptyInfo); result = deserializer.parseData(); REQUIRE(result == returnvalue::OK); REQUIRE(emptyInfo.getConditionCode() == cfdp::ConditionCode::NO_ERROR); @@ -94,12 +94,12 @@ TEST_CASE("EOF PDU", "[cfdp][pdu]") { eofInfo.setFileSize(0x10ffffff10, true); pduConf.largeFile = true; // Should serialize with fault location now - auto serializeWithFaultLocation = EofPduSerializer(pduConf, eofInfo); + auto serializeWithFaultLocation = EofPduCreator(pduConf, eofInfo); bufPtr = buf.data(); sz = 0; result = serializeWithFaultLocation.serialize(&bufPtr, &sz, buf.size(), SerializeIF::Endianness::NETWORK); - auto deserializer2 = EofPduDeserializer(buf.data(), buf.size(), emptyInfo); + auto deserializer2 = EofPduReader(buf.data(), buf.size(), emptyInfo); result = deserializer2.parseData(); REQUIRE(result == returnvalue::OK); REQUIRE(emptyInfo.getConditionCode() == cfdp::ConditionCode::FILESTORE_REJECTION); @@ -110,7 +110,7 @@ TEST_CASE("EOF PDU", "[cfdp][pdu]") { uint16_t destId = emptyInfo.getFaultLoc()->getEntityId().getValue(); REQUIRE(destId == 2); for (size_t maxSz = 0; maxSz < deserializer2.getWholePduSize() - 1; maxSz++) { - auto invalidDeser = EofPduDeserializer(buf.data(), maxSz, emptyInfo); + auto invalidDeser = EofPduReader(buf.data(), maxSz, emptyInfo); result = invalidDeser.parseData(); REQUIRE(result != returnvalue::OK); } From 108e7737e25a18ddef19adc06e5067c840e7bf8f Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Fri, 2 Sep 2022 17:54:25 +0200 Subject: [PATCH 079/169] continued dest handler --- src/fsfw/cfdp/FileSize.h | 8 +++-- src/fsfw/cfdp/handler/DestHandler.cpp | 46 ++++++++++++++++++++------- src/fsfw/cfdp/handler/DestHandler.h | 12 +++++-- 3 files changed, 50 insertions(+), 16 deletions(-) diff --git a/src/fsfw/cfdp/FileSize.h b/src/fsfw/cfdp/FileSize.h index 227555e6..b0b48452 100644 --- a/src/fsfw/cfdp/FileSize.h +++ b/src/fsfw/cfdp/FileSize.h @@ -1,6 +1,8 @@ #ifndef FSFW_CFDP_FILESIZE_H_ #define FSFW_CFDP_FILESIZE_H_ +#include + #include "fsfw/serialize/SerializeAdapter.h" #include "fsfw/serialize/SerializeIF.h" @@ -52,13 +54,15 @@ struct FileSize : public SerializeIF { } } - ReturnValue_t setFileSize(uint64_t fileSize_, bool largeFile_) { + ReturnValue_t setFileSize(uint64_t fileSize_, std::optional largeFile_) { + if (largeFile_) { + largeFile = largeFile_.value(); + } if (not largeFile and fileSize > UINT32_MAX) { // TODO: emit warning here return returnvalue::FAILED; } this->fileSize = fileSize_; - this->largeFile = largeFile_; return returnvalue::OK; } diff --git a/src/fsfw/cfdp/handler/DestHandler.cpp b/src/fsfw/cfdp/handler/DestHandler.cpp index 6aeac040..e152cbd5 100644 --- a/src/fsfw/cfdp/handler/DestHandler.cpp +++ b/src/fsfw/cfdp/handler/DestHandler.cpp @@ -49,20 +49,32 @@ ReturnValue_t cfdp::DestHandler::performStateMachine() { return status; } if (cfdpState == CfdpStates::BUSY_CLASS_1_NACKED) { - for (auto infoIter = dp.packetListRef.begin(); infoIter != dp.packetListRef.end();) { - if (infoIter->pduType == PduType::FILE_DATA) { - result = handleFileDataPdu(*infoIter); - if (result != OK) { - status = result; + if (step == TransactionStep::RECEIVING_FILE_DATA_PDUS) { + for (auto infoIter = dp.packetListRef.begin(); infoIter != dp.packetListRef.end();) { + if (infoIter->pduType == PduType::FILE_DATA) { + result = handleFileDataPdu(*infoIter); + if (result != OK) { + status = result; + } + // Store data was deleted in PDU handler because a store guard is used + dp.packetListRef.erase(infoIter++); + } + // TODO: Support for check timer missing + if (infoIter->pduType == PduType::FILE_DIRECTIVE and + infoIter->directiveType == FileDirectives::EOF_DIRECTIVE) { + result = handleEofPdu(*infoIter); + if (result != OK) { + status = result; + } + // Store data was deleted in PDU handler because a store guard is used + dp.packetListRef.erase(infoIter++); } - // Store data was deleted in PDU handler because a store guard is used - dp.packetListRef.erase(infoIter++); - } - if (infoIter->pduType == PduType::FILE_DIRECTIVE and - infoIter->directiveType == FileDirectives::EOF_DIRECTIVE) { - result = handleEofPdu(*infoIter); } } + if (step == TransactionStep::TRANSFER_COMPLETION) { + } + if (step == TransactionStep::SENDING_FINISHED_PDU) { + } return OK; } if (cfdpState == CfdpStates::BUSY_CLASS_2_ACKED) { @@ -141,7 +153,6 @@ ReturnValue_t cfdp::DestHandler::handleFileDataPdu(const cfdp::PacketInfo& info) size_t fileSegmentLen = 0; const uint8_t* fileData = fdInfo.getFileData(&fileSegmentLen); FileOpParams fileOpParams(tp.sourceName.data(), fileSegmentLen); - result = dp.user.vfs.writeToFile(fileOpParams, fileData); if (dp.cfg.indicCfg.fileSegmentRecvIndicRequired) { FileSegmentRecvdParams segParams; segParams.offset = offset.value(); @@ -153,6 +164,10 @@ ReturnValue_t cfdp::DestHandler::handleFileDataPdu(const cfdp::PacketInfo& info) segParams.segmentMetadata = {segMetadata, segmentMetadatLen}; dp.user.fileSegmentRecvdIndication(segParams); } + result = dp.user.vfs.writeToFile(fileOpParams, fileData); + if (offset.value() + fileSegmentLen > tp.progress) { + tp.progress = offset.value() + fileSegmentLen; + } if (result != returnvalue::OK) { // TODO: Proper Error handling #if FSFW_CPP_OSTREAM_ENABLED == 1 @@ -175,8 +190,15 @@ ReturnValue_t cfdp::DestHandler::handleEofPdu(const cfdp::PacketInfo& info) { if (result != OK) { return result; } + // TODO: Error handling if (eofInfo.getConditionCode() == ConditionCode::NO_ERROR) { tp.crc = eofInfo.getChecksum(); + uint64_t fileSizeFromEof = eofInfo.getFileSize().value(); + // CFDP 4.6.1.2.9: Declare file size error if progress exceeds file size + if (fileSizeFromEof > tp.progress) { + // TODO: File size error + } + tp.fileSize.setFileSize(fileSizeFromEof, std::nullopt); } return returnvalue::OK; } diff --git a/src/fsfw/cfdp/handler/DestHandler.h b/src/fsfw/cfdp/handler/DestHandler.h index 8215d22d..b24a35bc 100644 --- a/src/fsfw/cfdp/handler/DestHandler.h +++ b/src/fsfw/cfdp/handler/DestHandler.h @@ -2,6 +2,7 @@ #define FSFW_CFDP_CFDPDESTHANDLER_H #include +#include #include @@ -30,17 +31,23 @@ struct PacketInfo { struct DestHandlerParams { DestHandlerParams(LocalEntityCfg cfg, UserBase& user, RemoteConfigTableIF& remoteCfgTable, - etl::ilist& packetList) + etl::ilist& packetList, + // TODO: This container can potentially take tons of space. For a better + // memory efficient implementation, an additional abstraction could be + // be used so users can use uint32_t as the pair type + etl::iset>& lostSegmentsContainer) : cfg(std::move(cfg)), user(user), remoteCfgTable(remoteCfgTable), - packetListRef(packetList) {} + packetListRef(packetList), + lostSegmentsContainer(lostSegmentsContainer) {} LocalEntityCfg cfg; UserBase& user; RemoteConfigTableIF& remoteCfgTable; etl::ilist& packetListRef; + etl::iset>& lostSegmentsContainer; uint8_t maxTlvsInOnePdu = 10; size_t maxFilenameLen = 255; }; @@ -99,6 +106,7 @@ class DestHandler { TransactionId transactionId; PduConfig pduConf; uint32_t crc = 0; + uint64_t progress = 0; RemoteEntityCfg* remoteCfg = nullptr; }; From 3147f67fbdde039fa3d98e9646fcb419b5842f25 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Fri, 2 Sep 2022 18:03:52 +0200 Subject: [PATCH 080/169] basic dest handler framework almost complete --- src/fsfw/cfdp/handler/DestHandler.cpp | 30 ++++++++++++++++++++++++++- src/fsfw/cfdp/handler/DestHandler.h | 2 ++ 2 files changed, 31 insertions(+), 1 deletion(-) diff --git a/src/fsfw/cfdp/handler/DestHandler.cpp b/src/fsfw/cfdp/handler/DestHandler.cpp index e152cbd5..33947dcd 100644 --- a/src/fsfw/cfdp/handler/DestHandler.cpp +++ b/src/fsfw/cfdp/handler/DestHandler.cpp @@ -72,10 +72,14 @@ ReturnValue_t cfdp::DestHandler::performStateMachine() { } } if (step == TransactionStep::TRANSFER_COMPLETION) { + result = handleTransferCompletion(); + if (result != OK) { + status = result; + } } if (step == TransactionStep::SENDING_FINISHED_PDU) { } - return OK; + return status; } if (cfdpState == CfdpStates::BUSY_CLASS_2_ACKED) { // TODO: Will be implemented at a later stage @@ -200,6 +204,13 @@ ReturnValue_t cfdp::DestHandler::handleEofPdu(const cfdp::PacketInfo& info) { } tp.fileSize.setFileSize(fileSizeFromEof, std::nullopt); } + if (step == TransactionStep::RECEIVING_FILE_DATA_PDUS) { + if (cfdpState == CfdpStates::BUSY_CLASS_1_NACKED) { + step = TransactionStep::TRANSFER_COMPLETION; + } else if (cfdpState == CfdpStates::BUSY_CLASS_2_ACKED) { + step = TransactionStep::SENDING_ACK_PDU; + } + } return returnvalue::OK; } @@ -287,3 +298,20 @@ ReturnValue_t cfdp::DestHandler::startTransaction(MetadataPduReader& reader, Met } cfdp::CfdpStates cfdp::DestHandler::getCfdpState() const { return cfdpState; } + +ReturnValue_t cfdp::DestHandler::handleTransferCompletion() { + // TODO: Checksum verification and notice of completion + if (cfdpState == CfdpStates::BUSY_CLASS_1_NACKED) { + if (tp.closureRequested) { + step = TransactionStep::SENDING_FINISHED_PDU; + } else { + finish(); + } + } else if (cfdpState == CfdpStates::BUSY_CLASS_2_ACKED) { + step = TransactionStep::SENDING_FINISHED_PDU; + } +} + +void cfdp::DestHandler::finish() { + // TODO: Clear PDU list, reset state to be ready for next transfer +} diff --git a/src/fsfw/cfdp/handler/DestHandler.h b/src/fsfw/cfdp/handler/DestHandler.h index b24a35bc..9b607d65 100644 --- a/src/fsfw/cfdp/handler/DestHandler.h +++ b/src/fsfw/cfdp/handler/DestHandler.h @@ -123,6 +123,8 @@ class DestHandler { ReturnValue_t handleFileDataPdu(const PacketInfo& info); ReturnValue_t handleEofPdu(const PacketInfo& info); ReturnValue_t handleMetadataParseError(const uint8_t* rawData, size_t maxSize); + ReturnValue_t handleTransferCompletion(); + void finish(); }; } // namespace cfdp From 134d5a1411dcdf3394dbdb85228d08f10e5066df Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Mon, 5 Sep 2022 10:26:35 +0200 Subject: [PATCH 081/169] basic impl which allows naked no closure file transfer --- src/fsfw/cfdp/definitions.h | 2 +- src/fsfw/cfdp/handler/DestHandler.cpp | 71 +++++++++++++++++++++- src/fsfw/cfdp/handler/DestHandler.h | 23 ++++++- src/fsfw/cfdp/handler/UserBase.h | 8 +-- src/fsfw/cfdp/handler/mib.h | 2 +- src/fsfw/cfdp/pdu/MetadataInfo.cpp | 6 +- src/fsfw/cfdp/pdu/MetadataInfo.h | 8 +-- src/fsfw/cfdp/pdu/MetadataPduReader.cpp | 2 +- unittests/cfdp/handler/testDistributor.cpp | 2 +- unittests/cfdp/pdu/testMetadataPdu.cpp | 10 +-- 10 files changed, 111 insertions(+), 23 deletions(-) diff --git a/src/fsfw/cfdp/definitions.h b/src/fsfw/cfdp/definitions.h index fc117581..635ead17 100644 --- a/src/fsfw/cfdp/definitions.h +++ b/src/fsfw/cfdp/definitions.h @@ -40,7 +40,7 @@ static constexpr ReturnValue_t FILESTORE_RESPONSE_CANT_PARSE_FS_MESSAGE = //! Checksum types according to the SANA Checksum Types registry //! https://sanaregistry.org/r/checksum_identifiers/ -enum ChecksumType { +enum ChecksumTypes { // Modular legacy checksum MODULAR = 0, CRC_32_PROXIMITY_1 = 1, diff --git a/src/fsfw/cfdp/handler/DestHandler.cpp b/src/fsfw/cfdp/handler/DestHandler.cpp index 33947dcd..b6c42601 100644 --- a/src/fsfw/cfdp/handler/DestHandler.cpp +++ b/src/fsfw/cfdp/handler/DestHandler.cpp @@ -1,5 +1,7 @@ #include "DestHandler.h" +#include + #include #include "fsfw/FSFW.h" @@ -177,6 +179,8 @@ ReturnValue_t cfdp::DestHandler::handleFileDataPdu(const cfdp::PacketInfo& info) #if FSFW_CPP_OSTREAM_ENABLED == 1 sif::error << "File write error" << std::endl; #endif + } else { + tp.deliveryStatus = FileDeliveryStatus::RETAINED_IN_FILESTORE; } return result; } @@ -300,7 +304,18 @@ ReturnValue_t cfdp::DestHandler::startTransaction(MetadataPduReader& reader, Met cfdp::CfdpStates cfdp::DestHandler::getCfdpState() const { return cfdpState; } ReturnValue_t cfdp::DestHandler::handleTransferCompletion() { - // TODO: Checksum verification and notice of completion + ReturnValue_t result; + if (tp.checksumType != ChecksumTypes::NULL_CHECKSUM) { + result = checksumVerification(); + if (result != OK) { + // TODO: Warning / error handling? + } + } else { + tp.conditionCode = ConditionCode::NO_ERROR; + } + result = noticeOfCompletion(); + if (result != OK) { + } if (cfdpState == CfdpStates::BUSY_CLASS_1_NACKED) { if (tp.closureRequested) { step = TransactionStep::SENDING_FINISHED_PDU; @@ -310,8 +325,60 @@ ReturnValue_t cfdp::DestHandler::handleTransferCompletion() { } else if (cfdpState == CfdpStates::BUSY_CLASS_2_ACKED) { step = TransactionStep::SENDING_FINISHED_PDU; } + return OK; } void cfdp::DestHandler::finish() { - // TODO: Clear PDU list, reset state to be ready for next transfer + tp.reset(); + dp.packetListRef.clear(); + cfdpState = CfdpStates::IDLE; + step = TransactionStep::IDLE; +} + +ReturnValue_t cfdp::DestHandler::checksumVerification() { + std::array buf{}; + // TODO: Checksum verification and notice of completion + etl::crc32 crcCalc; + uint64_t currentOffset = 0; + FileOpParams params(tp.sourceName.data(), buf.size()); + while (currentOffset < tp.fileSize.value()) { + uint64_t readLen = 0; + if (currentOffset + buf.size() > tp.fileSize.value()) { + readLen = tp.fileSize.value() - currentOffset; + } else { + readLen = buf.size(); + } + if (readLen > 0) { + params.offset = currentOffset; + params.size = readLen; + auto result = dp.user.vfs.readFromFile(params, buf.data(), buf.size()); + if (result != OK) { + // TODO: Better error handling + return FAILED; + } + crcCalc.add(buf.begin(), buf.begin() + readLen); + } + currentOffset += readLen; + } + + uint32_t value = crcCalc.value(); + if (value == tp.crc) { + tp.conditionCode = ConditionCode::NO_ERROR; + tp.deliveryCode = FileDeliveryCode::DATA_COMPLETE; + } else { + // TODO: Proper error handling +#if FSFW_CPP_OSTREAM_ENABLED == 1 + sif::error << "CRC check for file " << tp.sourceName.data() << " failed" << std::endl; +#endif + tp.conditionCode = ConditionCode::FILE_CHECKSUM_FAILURE; + } + return OK; +} +ReturnValue_t cfdp::DestHandler::noticeOfCompletion() { + if (dp.cfg.indicCfg.transactionFinishedIndicRequired) { + TransactionFinishedParams params(tp.transactionId, tp.conditionCode, tp.deliveryCode, + tp.deliveryStatus); + dp.user.transactionFinishedIndication(params); + } + return OK; } diff --git a/src/fsfw/cfdp/handler/DestHandler.h b/src/fsfw/cfdp/handler/DestHandler.h index 9b607d65..289407c5 100644 --- a/src/fsfw/cfdp/handler/DestHandler.h +++ b/src/fsfw/cfdp/handler/DestHandler.h @@ -98,13 +98,32 @@ class DestHandler { explicit TransactionParams(size_t maxFileNameLen) : sourceName(maxFileNameLen), destName(maxFileNameLen) {} - ChecksumType checksumType = ChecksumType::NULL_CHECKSUM; + void reset() { + pduConf = PduConfig(); + transactionId = TransactionId(); + std::fill(sourceName.begin(), sourceName.end(), '\0'); + std::fill(destName.begin(), destName.end(), '\0'); + fileSize.setFileSize(0, false); + conditionCode = ConditionCode::NO_ERROR; + deliveryCode = FileDeliveryCode::DATA_INCOMPLETE; + deliveryStatus = FileDeliveryStatus::DISCARDED_DELIBERATELY; + crc = 0; + progress = 0; + remoteCfg = nullptr; + closureRequested = false; + checksumType = ChecksumTypes::NULL_CHECKSUM; + } + + ChecksumTypes checksumType = ChecksumTypes::NULL_CHECKSUM; bool closureRequested = false; std::vector sourceName; std::vector destName; cfdp::FileSize fileSize; TransactionId transactionId; PduConfig pduConf; + ConditionCode conditionCode = ConditionCode::NO_ERROR; + FileDeliveryCode deliveryCode = FileDeliveryCode::DATA_INCOMPLETE; + FileDeliveryStatus deliveryStatus = FileDeliveryStatus::DISCARDED_DELIBERATELY; uint32_t crc = 0; uint64_t progress = 0; RemoteEntityCfg* remoteCfg = nullptr; @@ -124,6 +143,8 @@ class DestHandler { ReturnValue_t handleEofPdu(const PacketInfo& info); ReturnValue_t handleMetadataParseError(const uint8_t* rawData, size_t maxSize); ReturnValue_t handleTransferCompletion(); + ReturnValue_t noticeOfCompletion(); + ReturnValue_t checksumVerification(); void finish(); }; diff --git a/src/fsfw/cfdp/handler/UserBase.h b/src/fsfw/cfdp/handler/UserBase.h index f9db4f49..e367b4a8 100644 --- a/src/fsfw/cfdp/handler/UserBase.h +++ b/src/fsfw/cfdp/handler/UserBase.h @@ -14,11 +14,11 @@ namespace cfdp { struct TransactionFinishedParams { - TransactionFinishedParams(TransactionId id, ConditionCode code, FileDeliveryStatus status, - FileDeliveryCode delivCode) - : id(std::move(id)), condCode(code), status(status), deliveryCode(delivCode) {} + TransactionFinishedParams(const TransactionId& id, ConditionCode code, FileDeliveryCode delivCode, + FileDeliveryStatus status) + : id(id), condCode(code), status(status), deliveryCode(delivCode) {} - TransactionId id; + const TransactionId& id; ConditionCode condCode; FileDeliveryStatus status; FileDeliveryCode deliveryCode; diff --git a/src/fsfw/cfdp/handler/mib.h b/src/fsfw/cfdp/handler/mib.h index 11f403dd..3b4c95e4 100644 --- a/src/fsfw/cfdp/handler/mib.h +++ b/src/fsfw/cfdp/handler/mib.h @@ -32,7 +32,7 @@ struct RemoteEntityCfg { bool closureRequested = false; bool crcOnTransmission = false; TransmissionModes defaultTransmissionMode = TransmissionModes::UNACKNOWLEDGED; - ChecksumType defaultChecksum = ChecksumType::NULL_CHECKSUM; + ChecksumTypes defaultChecksum = ChecksumTypes::NULL_CHECKSUM; const uint8_t version = CFDP_VERSION_2; }; diff --git a/src/fsfw/cfdp/pdu/MetadataInfo.cpp b/src/fsfw/cfdp/pdu/MetadataInfo.cpp index d88bdd87..e1eb3ad8 100644 --- a/src/fsfw/cfdp/pdu/MetadataInfo.cpp +++ b/src/fsfw/cfdp/pdu/MetadataInfo.cpp @@ -1,6 +1,6 @@ #include "MetadataInfo.h" -MetadataInfo::MetadataInfo(bool closureRequested, cfdp::ChecksumType checksumType, +MetadataInfo::MetadataInfo(bool closureRequested, cfdp::ChecksumTypes checksumType, cfdp::FileSize& fileSize, cfdp::StringLv& sourceFileName, cfdp::StringLv& destFileName) : MetadataInfo(fileSize, sourceFileName, destFileName) { @@ -23,9 +23,9 @@ void MetadataInfo::setOptionsArray(cfdp::Tlv** optionsArray_, std::optional optionsLen, std::optional maxOptionsLen); - [[nodiscard]] cfdp::ChecksumType getChecksumType() const; - void setChecksumType(cfdp::ChecksumType checksumType); + [[nodiscard]] cfdp::ChecksumTypes getChecksumType() const; + void setChecksumType(cfdp::ChecksumTypes checksumType); [[nodiscard]] bool isClosureRequested() const; void setClosureRequested(bool closureRequested = false); @@ -42,7 +42,7 @@ class MetadataInfo { private: bool closureRequested = false; - cfdp::ChecksumType checksumType = cfdp::ChecksumType::NULL_CHECKSUM; + cfdp::ChecksumTypes checksumType = cfdp::ChecksumTypes::NULL_CHECKSUM; cfdp::FileSize& fileSize; cfdp::StringLv& sourceFileName; cfdp::StringLv& destFileName; diff --git a/src/fsfw/cfdp/pdu/MetadataPduReader.cpp b/src/fsfw/cfdp/pdu/MetadataPduReader.cpp index 66025140..caf8287b 100644 --- a/src/fsfw/cfdp/pdu/MetadataPduReader.cpp +++ b/src/fsfw/cfdp/pdu/MetadataPduReader.cpp @@ -15,7 +15,7 @@ ReturnValue_t MetadataPduReader::parseData() { return SerializeIF::STREAM_TOO_SHORT; } info.setClosureRequested((*buf >> 6) & 0x01); - info.setChecksumType(static_cast(*buf & 0x0f)); + info.setChecksumType(static_cast(*buf & 0x0f)); remSize -= 1; buf += 1; auto endianness = getEndianness(); diff --git a/unittests/cfdp/handler/testDistributor.cpp b/unittests/cfdp/handler/testDistributor.cpp index 368ca9c0..f33e1115 100644 --- a/unittests/cfdp/handler/testDistributor.cpp +++ b/unittests/cfdp/handler/testDistributor.cpp @@ -30,7 +30,7 @@ TEST_CASE("CFDP Distributor", "[cfdp][distributor]") { cfdp::StringLv sourceFileName(sourceFileString); std::string destFileString = "hello2.txt"; cfdp::StringLv destFileName(destFileString); - MetadataInfo metadataInfo(false, cfdp::ChecksumType::CRC_32, fileSize, sourceFileName, + MetadataInfo metadataInfo(false, cfdp::ChecksumTypes::CRC_32, fileSize, sourceFileName, destFileName); MetadataPduCreator creator(pduConf, metadataInfo); uint8_t* dataPtr = nullptr; diff --git a/unittests/cfdp/pdu/testMetadataPdu.cpp b/unittests/cfdp/pdu/testMetadataPdu.cpp index 49f1deb4..18b60409 100644 --- a/unittests/cfdp/pdu/testMetadataPdu.cpp +++ b/unittests/cfdp/pdu/testMetadataPdu.cpp @@ -23,7 +23,7 @@ TEST_CASE("Metadata PDU", "[cfdp][pdu]") { cfdp::StringLv sourceFileName(firstFileName); cfdp::StringLv destFileName; FileSize fileSize(35); - MetadataInfo info(false, ChecksumType::MODULAR, fileSize, sourceFileName, destFileName); + MetadataInfo info(false, ChecksumTypes::MODULAR, fileSize, sourceFileName, destFileName); FilestoreResponseTlv response(FilestoreActionCode::CREATE_DIRECTORY, FSR_CREATE_NOT_ALLOWED, sourceFileName, nullptr); @@ -74,7 +74,7 @@ TEST_CASE("Metadata PDU", "[cfdp][pdu]") { REQUIRE(info.getMaxOptionsLen() == 2); info.setMaxOptionsLen(3); REQUIRE(info.getMaxOptionsLen() == 3); - info.setChecksumType(cfdp::ChecksumType::CRC_32C); + info.setChecksumType(cfdp::ChecksumTypes::CRC_32C); info.setClosureRequested(true); uint8_t* buffer = mdBuffer.data(); size_t sz = 0; @@ -83,8 +83,8 @@ TEST_CASE("Metadata PDU", "[cfdp][pdu]") { result = serializer.serialize(&buffer, &sz, mdBuffer.size(), SerializeIF::Endianness::NETWORK); REQUIRE(result == returnvalue::OK); REQUIRE((mdBuffer[1] << 8 | mdBuffer[2]) == 37); - auto checksumType = static_cast(mdBuffer[11] & 0x0f); - REQUIRE(checksumType == cfdp::ChecksumType::CRC_32C); + auto checksumType = static_cast(mdBuffer[11] & 0x0f); + REQUIRE(checksumType == cfdp::ChecksumTypes::CRC_32C); bool closureRequested = mdBuffer[11] >> 6 & 0x01; REQUIRE(closureRequested == true); // The size of the two options is 19. Summing up: @@ -130,7 +130,7 @@ TEST_CASE("Metadata PDU", "[cfdp][pdu]") { size_t maxSize = 4; info.setOptionsArray(options.data(), sizeOfOptions, maxSize); REQUIRE(info.getOptionsLen() == 2); - info.setChecksumType(cfdp::ChecksumType::CRC_32C); + info.setChecksumType(cfdp::ChecksumTypes::CRC_32C); info.setClosureRequested(true); uint8_t* buffer = mdBuffer.data(); size_t sz = 0; From b984128de5ce7cad1b941886c62fb7a83314d507 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Mon, 5 Sep 2022 10:30:55 +0200 Subject: [PATCH 082/169] stub for creating finished PDU --- src/fsfw/cfdp/handler/DestHandler.cpp | 7 +++++++ src/fsfw/cfdp/handler/DestHandler.h | 1 + 2 files changed, 8 insertions(+) diff --git a/src/fsfw/cfdp/handler/DestHandler.cpp b/src/fsfw/cfdp/handler/DestHandler.cpp index b6c42601..90e106a8 100644 --- a/src/fsfw/cfdp/handler/DestHandler.cpp +++ b/src/fsfw/cfdp/handler/DestHandler.cpp @@ -80,6 +80,11 @@ ReturnValue_t cfdp::DestHandler::performStateMachine() { } } if (step == TransactionStep::SENDING_FINISHED_PDU) { + result = sendFinishedPdu(); + if (result != OK) { + status = result; + } + finish(); } return status; } @@ -382,3 +387,5 @@ ReturnValue_t cfdp::DestHandler::noticeOfCompletion() { } return OK; } + +ReturnValue_t cfdp::DestHandler::sendFinishedPdu() { return 0; } diff --git a/src/fsfw/cfdp/handler/DestHandler.h b/src/fsfw/cfdp/handler/DestHandler.h index 289407c5..6b0493ad 100644 --- a/src/fsfw/cfdp/handler/DestHandler.h +++ b/src/fsfw/cfdp/handler/DestHandler.h @@ -143,6 +143,7 @@ class DestHandler { ReturnValue_t handleEofPdu(const PacketInfo& info); ReturnValue_t handleMetadataParseError(const uint8_t* rawData, size_t maxSize); ReturnValue_t handleTransferCompletion(); + ReturnValue_t sendFinishedPdu(); ReturnValue_t noticeOfCompletion(); ReturnValue_t checksumVerification(); void finish(); From 3dfc8822266e6e90e78ebaa1647bbfab53a58fb9 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Mon, 5 Sep 2022 11:03:25 +0200 Subject: [PATCH 083/169] impl finish PDU sending --- src/fsfw/cfdp/handler/DestHandler.cpp | 29 ++++++++++++++++++- src/fsfw/cfdp/pdu/CMakeLists.txt | 4 +-- src/fsfw/cfdp/pdu/FileDirectiveCreator.h | 4 +++ ...uSerializer.cpp => FinishedPduCreator.cpp} | 14 ++++----- src/fsfw/cfdp/pdu/FinishedPduCreator.h | 24 +++++++++++++++ ...Deserializer.cpp => FinishedPduReader.cpp} | 13 ++++----- ...dPduDeserializer.h => FinishedPduReader.h} | 10 +++---- src/fsfw/cfdp/pdu/FinishedPduSerializer.h | 23 --------------- unittests/cfdp/pdu/testFinishedPdu.cpp | 16 +++++----- 9 files changed, 83 insertions(+), 54 deletions(-) rename src/fsfw/cfdp/pdu/{FinishedPduSerializer.cpp => FinishedPduCreator.cpp} (72%) create mode 100644 src/fsfw/cfdp/pdu/FinishedPduCreator.h rename src/fsfw/cfdp/pdu/{FinishedPduDeserializer.cpp => FinishedPduReader.cpp} (85%) rename src/fsfw/cfdp/pdu/{FinishedPduDeserializer.h => FinishedPduReader.h} (52%) delete mode 100644 src/fsfw/cfdp/pdu/FinishedPduSerializer.h diff --git a/src/fsfw/cfdp/handler/DestHandler.cpp b/src/fsfw/cfdp/handler/DestHandler.cpp index 90e106a8..fcad9c79 100644 --- a/src/fsfw/cfdp/handler/DestHandler.cpp +++ b/src/fsfw/cfdp/handler/DestHandler.cpp @@ -7,8 +7,10 @@ #include "fsfw/FSFW.h" #include "fsfw/cfdp/pdu/EofPduReader.h" #include "fsfw/cfdp/pdu/FileDataReader.h" +#include "fsfw/cfdp/pdu/FinishedPduCreator.h" #include "fsfw/cfdp/pdu/HeaderReader.h" #include "fsfw/objectmanager.h" +#include "fsfw/tmtcservices/TmTcMessage.h" using namespace returnvalue; @@ -379,6 +381,7 @@ ReturnValue_t cfdp::DestHandler::checksumVerification() { } return OK; } + ReturnValue_t cfdp::DestHandler::noticeOfCompletion() { if (dp.cfg.indicCfg.transactionFinishedIndicRequired) { TransactionFinishedParams params(tp.transactionId, tp.conditionCode, tp.deliveryCode, @@ -388,4 +391,28 @@ ReturnValue_t cfdp::DestHandler::noticeOfCompletion() { return OK; } -ReturnValue_t cfdp::DestHandler::sendFinishedPdu() { return 0; } +ReturnValue_t cfdp::DestHandler::sendFinishedPdu() { + FinishedInfo info(tp.conditionCode, tp.deliveryCode, tp.deliveryStatus); + FinishPduCreator finishedPdu(tp.pduConf, info); + store_address_t storeId; + uint8_t* dataPtr = nullptr; + ReturnValue_t result = + fp.tcStore->getFreeElement(&storeId, finishedPdu.getSerializedSize(), &dataPtr); + if (result != OK) { + // TODO: Error handling and event, this is a non CFDP specific error (most likely store is full) + return result; + } + size_t serLen = 0; + result = finishedPdu.serialize(dataPtr, serLen, finishedPdu.getSerializedSize()); + if (result != OK) { + // TODO: Error printout, this really should not happen + return result; + } + TmTcMessage msg(storeId); + 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; + } + return OK; +} diff --git a/src/fsfw/cfdp/pdu/CMakeLists.txt b/src/fsfw/cfdp/pdu/CMakeLists.txt index 77386d20..a8f0b5a9 100644 --- a/src/fsfw/cfdp/pdu/CMakeLists.txt +++ b/src/fsfw/cfdp/pdu/CMakeLists.txt @@ -15,8 +15,8 @@ target_sources( NakPduSerializer.cpp NakPduDeserializer.cpp FinishedInfo.cpp - FinishedPduSerializer.cpp - FinishedPduDeserializer.cpp + FinishedPduCreator.cpp + FinishedPduReader.cpp MetadataInfo.cpp MetadataPduCreator.cpp MetadataPduReader.cpp diff --git a/src/fsfw/cfdp/pdu/FileDirectiveCreator.h b/src/fsfw/cfdp/pdu/FileDirectiveCreator.h index 566ae3cc..6068fe64 100644 --- a/src/fsfw/cfdp/pdu/FileDirectiveCreator.h +++ b/src/fsfw/cfdp/pdu/FileDirectiveCreator.h @@ -16,6 +16,10 @@ class FileDirectiveCreator : public HeaderCreator { */ [[nodiscard]] size_t getSerializedSize() const override; + [[nodiscard]] ReturnValue_t serialize(uint8_t* buffer, size_t& serLen, size_t maxSize) const { + return SerializeIF::serialize(buffer, serLen, maxSize, SerializeIF::Endianness::NETWORK); + } + ReturnValue_t serialize(uint8_t** buffer, size_t* size, size_t maxSize, Endianness streamEndianness) const override; diff --git a/src/fsfw/cfdp/pdu/FinishedPduSerializer.cpp b/src/fsfw/cfdp/pdu/FinishedPduCreator.cpp similarity index 72% rename from src/fsfw/cfdp/pdu/FinishedPduSerializer.cpp rename to src/fsfw/cfdp/pdu/FinishedPduCreator.cpp index b6f793f7..88f4491c 100644 --- a/src/fsfw/cfdp/pdu/FinishedPduSerializer.cpp +++ b/src/fsfw/cfdp/pdu/FinishedPduCreator.cpp @@ -1,20 +1,18 @@ -#include "FinishedPduSerializer.h" +#include "FinishedPduCreator.h" -FinishPduSerializer::FinishPduSerializer(PduConfig &conf, FinishedInfo &finishInfo) +FinishPduCreator::FinishPduCreator(PduConfig &conf, FinishedInfo &finishInfo) : FileDirectiveCreator(conf, cfdp::FileDirectives::FINISH, 0), finishInfo(finishInfo) { updateDirectiveFieldLen(); } -size_t FinishPduSerializer::getSerializedSize() const { - return FinishPduSerializer::getWholePduSize(); -} +size_t FinishPduCreator::getSerializedSize() const { return FinishPduCreator::getWholePduSize(); } -void FinishPduSerializer::updateDirectiveFieldLen() { +void FinishPduCreator::updateDirectiveFieldLen() { setDirectiveDataFieldLen(finishInfo.getSerializedSize()); } -ReturnValue_t FinishPduSerializer::serialize(uint8_t **buffer, size_t *size, size_t maxSize, - Endianness streamEndianness) const { +ReturnValue_t FinishPduCreator::serialize(uint8_t **buffer, size_t *size, size_t maxSize, + Endianness streamEndianness) const { ReturnValue_t result = FileDirectiveCreator::serialize(buffer, size, maxSize, streamEndianness); if (result != returnvalue::OK) { return result; diff --git a/src/fsfw/cfdp/pdu/FinishedPduCreator.h b/src/fsfw/cfdp/pdu/FinishedPduCreator.h new file mode 100644 index 00000000..bef59ada --- /dev/null +++ b/src/fsfw/cfdp/pdu/FinishedPduCreator.h @@ -0,0 +1,24 @@ +#ifndef FSFW_CFDP_PDU_FINISHEDPDUSERIALIZER_H_ +#define FSFW_CFDP_PDU_FINISHEDPDUSERIALIZER_H_ + +#include "FinishedInfo.h" +#include "fsfw/cfdp/pdu/FileDataCreator.h" +#include "fsfw/cfdp/pdu/FileDirectiveCreator.h" + +class FinishPduCreator : public FileDirectiveCreator { + public: + FinishPduCreator(PduConfig& pduConf, FinishedInfo& finishInfo); + + void updateDirectiveFieldLen(); + + [[nodiscard]] size_t getSerializedSize() const override; + + ReturnValue_t serialize(uint8_t** buffer, size_t* size, size_t maxSize, + Endianness streamEndianness) const override; + using FileDirectiveCreator::serialize; + + private: + FinishedInfo& finishInfo; +}; + +#endif /* FSFW_CFDP_PDU_FINISHEDPDUSERIALIZER_H_ */ diff --git a/src/fsfw/cfdp/pdu/FinishedPduDeserializer.cpp b/src/fsfw/cfdp/pdu/FinishedPduReader.cpp similarity index 85% rename from src/fsfw/cfdp/pdu/FinishedPduDeserializer.cpp rename to src/fsfw/cfdp/pdu/FinishedPduReader.cpp index 1f3eee18..475942e0 100644 --- a/src/fsfw/cfdp/pdu/FinishedPduDeserializer.cpp +++ b/src/fsfw/cfdp/pdu/FinishedPduReader.cpp @@ -1,10 +1,9 @@ -#include "FinishedPduDeserializer.h" +#include "FinishedPduReader.h" -FinishPduDeserializer::FinishPduDeserializer(const uint8_t* pduBuf, size_t maxSize, - FinishedInfo& info) +FinishPduReader::FinishPduReader(const uint8_t* pduBuf, size_t maxSize, FinishedInfo& info) : FileDirectiveReader(pduBuf, maxSize), finishedInfo(info) {} -ReturnValue_t FinishPduDeserializer::parseData() { +ReturnValue_t FinishPduReader::parseData() { ReturnValue_t result = FileDirectiveReader::parseData(); if (result != returnvalue::OK) { return result; @@ -29,10 +28,10 @@ ReturnValue_t FinishPduDeserializer::parseData() { return result; } -FinishedInfo& FinishPduDeserializer::getInfo() { return finishedInfo; } +FinishedInfo& FinishPduReader::getInfo() { return finishedInfo; } -ReturnValue_t FinishPduDeserializer::parseTlvs(size_t remLen, size_t currentIdx, const uint8_t* buf, - cfdp::ConditionCode conditionCode) { +ReturnValue_t FinishPduReader::parseTlvs(size_t remLen, size_t currentIdx, const uint8_t* buf, + cfdp::ConditionCode conditionCode) { ReturnValue_t result = returnvalue::OK; size_t fsResponsesIdx = 0; auto endianness = getEndianness(); diff --git a/src/fsfw/cfdp/pdu/FinishedPduDeserializer.h b/src/fsfw/cfdp/pdu/FinishedPduReader.h similarity index 52% rename from src/fsfw/cfdp/pdu/FinishedPduDeserializer.h rename to src/fsfw/cfdp/pdu/FinishedPduReader.h index 1a13cad5..791a2ef4 100644 --- a/src/fsfw/cfdp/pdu/FinishedPduDeserializer.h +++ b/src/fsfw/cfdp/pdu/FinishedPduReader.h @@ -1,12 +1,12 @@ -#ifndef FSFW_SRC_FSFW_CFDP_PDU_FINISHEDPDUDESERIALIZER_H_ -#define FSFW_SRC_FSFW_CFDP_PDU_FINISHEDPDUDESERIALIZER_H_ +#ifndef FSFW_CFDP_PDU_FINISHEDPDUDESERIALIZER_H_ +#define FSFW_CFDP_PDU_FINISHEDPDUDESERIALIZER_H_ #include "fsfw/cfdp/pdu/FileDirectiveReader.h" #include "fsfw/cfdp/pdu/FinishedInfo.h" -class FinishPduDeserializer : public FileDirectiveReader { +class FinishPduReader : public FileDirectiveReader { public: - FinishPduDeserializer(const uint8_t* pduBuf, size_t maxSize, FinishedInfo& info); + FinishPduReader(const uint8_t* pduBuf, size_t maxSize, FinishedInfo& info); ReturnValue_t parseData() override; @@ -19,4 +19,4 @@ class FinishPduDeserializer : public FileDirectiveReader { cfdp::ConditionCode conditionCode); }; -#endif /* FSFW_SRC_FSFW_CFDP_PDU_FINISHEDPDUDESERIALIZER_H_ */ +#endif /* FSFW_CFDP_PDU_FINISHEDPDUDESERIALIZER_H_ */ diff --git a/src/fsfw/cfdp/pdu/FinishedPduSerializer.h b/src/fsfw/cfdp/pdu/FinishedPduSerializer.h deleted file mode 100644 index eb162c94..00000000 --- a/src/fsfw/cfdp/pdu/FinishedPduSerializer.h +++ /dev/null @@ -1,23 +0,0 @@ -#ifndef FSFW_SRC_FSFW_CFDP_PDU_FINISHEDPDUSERIALIZER_H_ -#define FSFW_SRC_FSFW_CFDP_PDU_FINISHEDPDUSERIALIZER_H_ - -#include "FinishedInfo.h" -#include "fsfw/cfdp/pdu/FileDataCreator.h" -#include "fsfw/cfdp/pdu/FileDirectiveCreator.h" - -class FinishPduSerializer : public FileDirectiveCreator { - public: - FinishPduSerializer(PduConfig& pduConf, FinishedInfo& finishInfo); - - void updateDirectiveFieldLen(); - - size_t getSerializedSize() const override; - - ReturnValue_t serialize(uint8_t** buffer, size_t* size, size_t maxSize, - Endianness streamEndianness) const override; - - private: - FinishedInfo& finishInfo; -}; - -#endif /* FSFW_SRC_FSFW_CFDP_PDU_FINISHEDPDUSERIALIZER_H_ */ diff --git a/unittests/cfdp/pdu/testFinishedPdu.cpp b/unittests/cfdp/pdu/testFinishedPdu.cpp index 2f3c466e..194e4252 100644 --- a/unittests/cfdp/pdu/testFinishedPdu.cpp +++ b/unittests/cfdp/pdu/testFinishedPdu.cpp @@ -1,8 +1,8 @@ #include #include -#include "fsfw/cfdp/pdu/FinishedPduDeserializer.h" -#include "fsfw/cfdp/pdu/FinishedPduSerializer.h" +#include "fsfw/cfdp/pdu/FinishedPduCreator.h" +#include "fsfw/cfdp/pdu/FinishedPduReader.h" #include "fsfw/globalfunctions/arrayprinter.h" TEST_CASE("Finished PDU", "[cfdp][pdu]") { @@ -22,7 +22,7 @@ TEST_CASE("Finished PDU", "[cfdp][pdu]") { cfdp::FileDeliveryStatus::DISCARDED_DELIBERATELY); SECTION("Serialize") { - FinishPduSerializer serializer(pduConf, info); + FinishPduCreator serializer(pduConf, info); result = serializer.serialize(&buffer, &sz, fnBuffer.size(), SerializeIF::Endianness::NETWORK); REQUIRE(result == returnvalue::OK); REQUIRE(serializer.getSerializedSize() == 12); @@ -87,10 +87,10 @@ TEST_CASE("Finished PDU", "[cfdp][pdu]") { SECTION("Deserialize") { FinishedInfo emptyInfo; - FinishPduSerializer serializer(pduConf, info); + FinishPduCreator serializer(pduConf, info); result = serializer.serialize(&buffer, &sz, fnBuffer.size(), SerializeIF::Endianness::NETWORK); REQUIRE(result == returnvalue::OK); - FinishPduDeserializer deserializer(fnBuffer.data(), fnBuffer.size(), emptyInfo); + FinishPduReader deserializer(fnBuffer.data(), fnBuffer.size(), emptyInfo); result = deserializer.parseData(); REQUIRE(result == returnvalue::OK); REQUIRE(emptyInfo.getFileStatus() == cfdp::FileDeliveryStatus::DISCARDED_DELIBERATELY); @@ -114,7 +114,7 @@ TEST_CASE("Finished PDU", "[cfdp][pdu]") { FilestoreResponseTlv emptyResponse(firstNameLv, nullptr); responsePtr = &emptyResponse; emptyInfo.setFilestoreResponsesArray(&responsePtr, nullptr, &len); - FinishPduDeserializer deserializer2(fnBuffer.data(), fnBuffer.size(), emptyInfo); + FinishPduReader deserializer2(fnBuffer.data(), fnBuffer.size(), emptyInfo); result = deserializer2.parseData(); REQUIRE(result == returnvalue::OK); REQUIRE(emptyInfo.getFsResponsesLen() == 1); @@ -152,7 +152,7 @@ TEST_CASE("Finished PDU", "[cfdp][pdu]") { response.setFilestoreMessage(&emptyFsMsg); emptyInfo.setFilestoreResponsesArray(responses.data(), &len, &len); response2.setFilestoreMessage(&emptyFsMsg); - FinishPduDeserializer deserializer3(fnBuffer.data(), fnBuffer.size(), emptyInfo); + FinishPduReader deserializer3(fnBuffer.data(), fnBuffer.size(), emptyInfo); result = deserializer3.parseData(); REQUIRE(result == returnvalue::OK); auto& infoRef = deserializer3.getInfo(); @@ -181,7 +181,7 @@ TEST_CASE("Finished PDU", "[cfdp][pdu]") { REQUIRE(result == cfdp::INVALID_TLV_TYPE); for (size_t maxSz = 0; maxSz < 45; maxSz++) { - FinishPduDeserializer faultyDeser(fnBuffer.data(), maxSz, emptyInfo); + FinishPduReader faultyDeser(fnBuffer.data(), maxSz, emptyInfo); result = faultyDeser.parseData(); REQUIRE(result != returnvalue::OK); } From 0dd2b5ddd48f83383a73b1decd5e27dc68301512 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Mon, 5 Sep 2022 11:19:23 +0200 Subject: [PATCH 084/169] need an event reporter proxy --- src/fsfw/cfdp/handler/DestHandler.h | 15 +++++++++++---- unittests/cfdp/handler/testDestHandler.cpp | 12 +++++++++++- 2 files changed, 22 insertions(+), 5 deletions(-) diff --git a/src/fsfw/cfdp/handler/DestHandler.h b/src/fsfw/cfdp/handler/DestHandler.h index 6b0493ad..f3e73f32 100644 --- a/src/fsfw/cfdp/handler/DestHandler.h +++ b/src/fsfw/cfdp/handler/DestHandler.h @@ -29,13 +29,20 @@ struct PacketInfo { PacketInfo() = default; }; +template +using LostSegmentsList = etl::set, SIZE>; +template +using PacketInfoList = etl::list; +using LostSegmentsListBase = etl::iset>; +using PacketInfoListBase = etl::ilist; + struct DestHandlerParams { DestHandlerParams(LocalEntityCfg cfg, UserBase& user, RemoteConfigTableIF& remoteCfgTable, - etl::ilist& packetList, + PacketInfoListBase& packetList, // TODO: This container can potentially take tons of space. For a better // memory efficient implementation, an additional abstraction could be // be used so users can use uint32_t as the pair type - etl::iset>& lostSegmentsContainer) + LostSegmentsListBase& lostSegmentsContainer) : cfg(std::move(cfg)), user(user), remoteCfgTable(remoteCfgTable), @@ -46,8 +53,8 @@ struct DestHandlerParams { UserBase& user; RemoteConfigTableIF& remoteCfgTable; - etl::ilist& packetListRef; - etl::iset>& lostSegmentsContainer; + PacketInfoListBase& packetListRef; + LostSegmentsListBase& lostSegmentsContainer; uint8_t maxTlvsInOnePdu = 10; size_t maxFilenameLen = 255; }; diff --git a/unittests/cfdp/handler/testDestHandler.cpp b/unittests/cfdp/handler/testDestHandler.cpp index 1b2de95e..9d6274e0 100644 --- a/unittests/cfdp/handler/testDestHandler.cpp +++ b/unittests/cfdp/handler/testDestHandler.cpp @@ -1,20 +1,30 @@ #include #include "fsfw/cfdp.h" +#include "mocks/AcceptsTmMock.h" #include "mocks/FilesystemMock.h" +#include "mocks/MessageQueueMock.h" #include "mocks/cfdp/FaultHandlerMock.h" #include "mocks/cfdp/RemoteConfigTableMock.h" #include "mocks/cfdp/UserMock.h" TEST_CASE("CFDP Dest Handler", "[cfdp]") { using namespace cfdp; + MessageQueueId_t destQueueId = 2; + AcceptsTmMock tmReceiver(destQueueId); + MessageQueueMock mqMock(destQueueId); EntityId localId = EntityId(UnsignedByteField(2)); auto fhMock = FaultHandlerMock(); auto localEntityCfg = LocalEntityCfg(localId, IndicationCfg(), fhMock); auto fsMock = FilesystemMock(); auto userMock = UserMock(fsMock); auto remoteCfgTableMock = RemoteConfigTableMock(); - // auto destHandler = DestHandler(localEntityCfg, userMock, remoteCfgTableMock); + PacketInfoList<64> packetInfoList; + LostSegmentsList<128> lostSegmentsList; + DestHandlerParams dp(localEntityCfg, userMock, remoteCfgTableMock, packetInfoList, + lostSegmentsList); + // FsfwParams fp(destQueueId, mqMock); + // auto destHandler = DestHandler(); SECTION("State") {} } \ No newline at end of file From d2c4d546c305c53d8f814e1b3c811256b1ec155d Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Mon, 5 Sep 2022 11:37:41 +0200 Subject: [PATCH 085/169] first dest handler unittests - Add new mock class for event reporting proxies - Add basic setup for unittesting the CFDP destination handler --- src/fsfw/cfdp/handler/DestHandler.cpp | 2 ++ src/fsfw/cfdp/handler/DestHandler.h | 17 +++++++++-------- unittests/cfdp/handler/testDestHandler.cpp | 19 ++++++++++++++++--- unittests/mocks/CMakeLists.txt | 3 ++- unittests/mocks/EventReportingProxyMock.cpp | 6 ++++++ unittests/mocks/EventReportingProxyMock.h | 21 +++++++++++++++++++++ 6 files changed, 56 insertions(+), 12 deletions(-) create mode 100644 unittests/mocks/EventReportingProxyMock.cpp create mode 100644 unittests/mocks/EventReportingProxyMock.h diff --git a/src/fsfw/cfdp/handler/DestHandler.cpp b/src/fsfw/cfdp/handler/DestHandler.cpp index fcad9c79..a153682d 100644 --- a/src/fsfw/cfdp/handler/DestHandler.cpp +++ b/src/fsfw/cfdp/handler/DestHandler.cpp @@ -416,3 +416,5 @@ ReturnValue_t cfdp::DestHandler::sendFinishedPdu() { } return OK; } + +cfdp::DestHandler::TransactionStep cfdp::DestHandler::getTransactionStep() const { return step; } diff --git a/src/fsfw/cfdp/handler/DestHandler.h b/src/fsfw/cfdp/handler/DestHandler.h index f3e73f32..9b45c60c 100644 --- a/src/fsfw/cfdp/handler/DestHandler.h +++ b/src/fsfw/cfdp/handler/DestHandler.h @@ -72,6 +72,14 @@ struct FsfwParams { class DestHandler { public: + enum class TransactionStep { + IDLE = 0, + TRANSACTION_START = 1, + RECEIVING_FILE_DATA_PDUS = 2, + SENDING_ACK_PDU = 3, + TRANSFER_COMPLETION = 4, + SENDING_FINISHED_PDU = 5 + }; /** * Will be returned if it is advisable to call the state machine operation call again */ @@ -91,16 +99,9 @@ class DestHandler { ReturnValue_t initialize(); [[nodiscard]] CfdpStates getCfdpState() const; + [[nodiscard]] TransactionStep getTransactionStep() const; private: - enum class TransactionStep { - IDLE = 0, - TRANSACTION_START = 1, - RECEIVING_FILE_DATA_PDUS = 2, - SENDING_ACK_PDU = 3, - TRANSFER_COMPLETION = 4, - SENDING_FINISHED_PDU = 5 - }; struct TransactionParams { explicit TransactionParams(size_t maxFileNameLen) : sourceName(maxFileNameLen), destName(maxFileNameLen) {} diff --git a/unittests/cfdp/handler/testDestHandler.cpp b/unittests/cfdp/handler/testDestHandler.cpp index 9d6274e0..d1191534 100644 --- a/unittests/cfdp/handler/testDestHandler.cpp +++ b/unittests/cfdp/handler/testDestHandler.cpp @@ -2,14 +2,17 @@ #include "fsfw/cfdp.h" #include "mocks/AcceptsTmMock.h" +#include "mocks/EventReportingProxyMock.h" #include "mocks/FilesystemMock.h" #include "mocks/MessageQueueMock.h" +#include "mocks/StorageManagerMock.h" #include "mocks/cfdp/FaultHandlerMock.h" #include "mocks/cfdp/RemoteConfigTableMock.h" #include "mocks/cfdp/UserMock.h" TEST_CASE("CFDP Dest Handler", "[cfdp]") { using namespace cfdp; + using namespace returnvalue; MessageQueueId_t destQueueId = 2; AcceptsTmMock tmReceiver(destQueueId); MessageQueueMock mqMock(destQueueId); @@ -23,8 +26,18 @@ TEST_CASE("CFDP Dest Handler", "[cfdp]") { LostSegmentsList<128> lostSegmentsList; DestHandlerParams dp(localEntityCfg, userMock, remoteCfgTableMock, packetInfoList, lostSegmentsList); - // FsfwParams fp(destQueueId, mqMock); - // auto destHandler = DestHandler(); + EventReportingProxyMock eventReporterMock; + LocalPool::LocalPoolConfig storeCfg = {{10, 32}, {10, 64}, {10, 128}, {10, 1024}}; + StorageManagerMock tcStore(2, storeCfg); + StorageManagerMock tmStore(3, storeCfg); + FsfwParams fp(tmReceiver, mqMock, eventReporterMock); + fp.tcStore = &tcStore; + fp.tmStore = &tmStore; + auto destHandler = DestHandler(dp, fp); + CHECK(destHandler.initialize() == OK); - SECTION("State") {} + SECTION("State") { + CHECK(destHandler.getCfdpState() == CfdpStates::IDLE); + CHECK(destHandler.getTransactionStep() == DestHandler::TransactionStep::IDLE); + } } \ No newline at end of file diff --git a/unittests/mocks/CMakeLists.txt b/unittests/mocks/CMakeLists.txt index c40a727a..bd093da8 100644 --- a/unittests/mocks/CMakeLists.txt +++ b/unittests/mocks/CMakeLists.txt @@ -15,6 +15,7 @@ target_sources( CcsdsCheckerMock.cpp AcceptsTcMock.cpp StorageManagerMock.cpp - FilesystemMock.cpp) + FilesystemMock.cpp + EventReportingProxyMock.cpp) add_subdirectory(cfdp) diff --git a/unittests/mocks/EventReportingProxyMock.cpp b/unittests/mocks/EventReportingProxyMock.cpp new file mode 100644 index 00000000..cb4f6d93 --- /dev/null +++ b/unittests/mocks/EventReportingProxyMock.cpp @@ -0,0 +1,6 @@ +#include "EventReportingProxyMock.h" + +void EventReportingProxyMock::forwardEvent(Event event, uint32_t parameter1, + uint32_t parameter2) const { + eventQueue.emplace(event, parameter1, parameter2); +} diff --git a/unittests/mocks/EventReportingProxyMock.h b/unittests/mocks/EventReportingProxyMock.h new file mode 100644 index 00000000..c04942c3 --- /dev/null +++ b/unittests/mocks/EventReportingProxyMock.h @@ -0,0 +1,21 @@ +#ifndef FSFW_TESTS_EVENTREPORTPROXYMOCK_H +#define FSFW_TESTS_EVENTREPORTPROXYMOCK_H + +#include + +#include "fsfw/events/EventReportingProxyIF.h" + +class EventReportingProxyMock : public EventReportingProxyIF { + public: + void forwardEvent(Event event, uint32_t parameter1, uint32_t parameter2) const override; + + struct EventInfo { + EventInfo(Event event, uint32_t p1, uint32_t p2) : event(event), p1(p1), p2(p2) {} + + Event event; + uint32_t p1; + uint32_t p2; + }; + mutable std::queue eventQueue; +}; +#endif // FSFW_TESTS_EVENTREPORTPROXYMOCK_H From 52802f127b83eaeaa4741cab9725297ce08d8ad2 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Mon, 5 Sep 2022 11:40:22 +0200 Subject: [PATCH 086/169] basic test stubs --- unittests/cfdp/handler/testDestHandler.cpp | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/unittests/cfdp/handler/testDestHandler.cpp b/unittests/cfdp/handler/testDestHandler.cpp index d1191534..bc5aabea 100644 --- a/unittests/cfdp/handler/testDestHandler.cpp +++ b/unittests/cfdp/handler/testDestHandler.cpp @@ -40,4 +40,16 @@ TEST_CASE("CFDP Dest Handler", "[cfdp]") { CHECK(destHandler.getCfdpState() == CfdpStates::IDLE); CHECK(destHandler.getTransactionStep() == DestHandler::TransactionStep::IDLE); } + + SECTION("Empty File Transfer") { + + } + + SECTION("Small File Transfer") { + + } + + SECTION("Segmented File Transfer") { + + } } \ No newline at end of file From 5ce1e76723ce34d9e129326d908e0ffb1b25b356 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Mon, 5 Sep 2022 14:20:01 +0200 Subject: [PATCH 087/169] init dest handler unittests --- src/fsfw/cfdp/handler/DestHandler.cpp | 3 ++ src/fsfw/cfdp/handler/DestHandler.h | 3 +- src/fsfw/cfdp/pdu/FileDirectiveCreator.cpp | 2 ++ src/fsfw/cfdp/pdu/FileDirectiveCreator.h | 2 ++ src/fsfw/cfdp/pdu/MetadataPduCreator.h | 1 + src/fsfw/cfdp/tlv/StringLv.h | 3 ++ unittests/cfdp/handler/testDestHandler.cpp | 35 +++++++++++++++++----- unittests/mocks/StorageManagerMock.h | 3 ++ 8 files changed, 44 insertions(+), 8 deletions(-) diff --git a/src/fsfw/cfdp/handler/DestHandler.cpp b/src/fsfw/cfdp/handler/DestHandler.cpp index a153682d..487ee817 100644 --- a/src/fsfw/cfdp/handler/DestHandler.cpp +++ b/src/fsfw/cfdp/handler/DestHandler.cpp @@ -37,12 +37,14 @@ ReturnValue_t cfdp::DestHandler::performStateMachine() { // Store data was deleted in PDU handler because a store guard is used dp.packetListRef.erase(infoIter++); } + infoIter++; } if (step == TransactionStep::IDLE) { // To decrease the already high complexity of the software, all packets arriving before // a metadata PDU are deleted. for (auto infoIter = dp.packetListRef.begin(); infoIter != dp.packetListRef.end();) { fp.tcStore->deleteData(infoIter->storeId); + infoIter++; } dp.packetListRef.clear(); } @@ -73,6 +75,7 @@ ReturnValue_t cfdp::DestHandler::performStateMachine() { // Store data was deleted in PDU handler because a store guard is used dp.packetListRef.erase(infoIter++); } + infoIter++; } } if (step == TransactionStep::TRANSFER_COMPLETION) { diff --git a/src/fsfw/cfdp/handler/DestHandler.h b/src/fsfw/cfdp/handler/DestHandler.h index 9b45c60c..1b4bed75 100644 --- a/src/fsfw/cfdp/handler/DestHandler.h +++ b/src/fsfw/cfdp/handler/DestHandler.h @@ -103,8 +103,9 @@ class DestHandler { private: struct TransactionParams { + // Initialize char vectors with length + 1 for 0 termination explicit TransactionParams(size_t maxFileNameLen) - : sourceName(maxFileNameLen), destName(maxFileNameLen) {} + : sourceName(maxFileNameLen + 1), destName(maxFileNameLen + 1) {} void reset() { pduConf = PduConfig(); diff --git a/src/fsfw/cfdp/pdu/FileDirectiveCreator.cpp b/src/fsfw/cfdp/pdu/FileDirectiveCreator.cpp index 86c1ad92..474a1cc3 100644 --- a/src/fsfw/cfdp/pdu/FileDirectiveCreator.cpp +++ b/src/fsfw/cfdp/pdu/FileDirectiveCreator.cpp @@ -35,3 +35,5 @@ void FileDirectiveCreator::setDirectiveDataFieldLen(size_t len) { // Set length of data field plus 1 byte for the directive octet HeaderCreator::setPduDataFieldLen(len + 1); } + +cfdp::FileDirectives FileDirectiveCreator::getDirectiveCode() const { return directiveCode; } diff --git a/src/fsfw/cfdp/pdu/FileDirectiveCreator.h b/src/fsfw/cfdp/pdu/FileDirectiveCreator.h index 6068fe64..a3b676b0 100644 --- a/src/fsfw/cfdp/pdu/FileDirectiveCreator.h +++ b/src/fsfw/cfdp/pdu/FileDirectiveCreator.h @@ -8,6 +8,8 @@ class FileDirectiveCreator : public HeaderCreator { FileDirectiveCreator(PduConfig& pduConf, cfdp::FileDirectives directiveCode, size_t directiveParamFieldLen); + [[nodiscard]] cfdp::FileDirectives getDirectiveCode() const; + /** * This only returns the size of the PDU header + 1 for the directive code octet. * Use FileDirectiveCreator::getWholePduSize to get the full packet length, assuming diff --git a/src/fsfw/cfdp/pdu/MetadataPduCreator.h b/src/fsfw/cfdp/pdu/MetadataPduCreator.h index 2c2f35f8..4486a79c 100644 --- a/src/fsfw/cfdp/pdu/MetadataPduCreator.h +++ b/src/fsfw/cfdp/pdu/MetadataPduCreator.h @@ -14,6 +14,7 @@ class MetadataPduCreator : public FileDirectiveCreator { ReturnValue_t serialize(uint8_t** buffer, size_t* size, size_t maxSize, Endianness streamEndianness) const override; + using FileDirectiveCreator::serialize; private: MetadataInfo& info; diff --git a/src/fsfw/cfdp/tlv/StringLv.h b/src/fsfw/cfdp/tlv/StringLv.h index a6cc8e20..6c200b8b 100644 --- a/src/fsfw/cfdp/tlv/StringLv.h +++ b/src/fsfw/cfdp/tlv/StringLv.h @@ -12,6 +12,9 @@ class StringLv : public Lv { StringLv(); explicit StringLv(const std::string& fileName); explicit StringLv(const char* filename, size_t len); + + // Delete the move constructor to avoid passing in a temporary + StringLv(const std::string&&) = delete; }; } // namespace cfdp diff --git a/unittests/cfdp/handler/testDestHandler.cpp b/unittests/cfdp/handler/testDestHandler.cpp index bc5aabea..47f17f2d 100644 --- a/unittests/cfdp/handler/testDestHandler.cpp +++ b/unittests/cfdp/handler/testDestHandler.cpp @@ -1,6 +1,7 @@ #include #include "fsfw/cfdp.h" +#include "fsfw/cfdp/pdu/MetadataPduCreator.h" #include "mocks/AcceptsTmMock.h" #include "mocks/EventReportingProxyMock.h" #include "mocks/FilesystemMock.h" @@ -17,6 +18,7 @@ TEST_CASE("CFDP Dest Handler", "[cfdp]") { AcceptsTmMock tmReceiver(destQueueId); MessageQueueMock mqMock(destQueueId); EntityId localId = EntityId(UnsignedByteField(2)); + EntityId remoteId = EntityId(UnsignedByteField(3)); auto fhMock = FaultHandlerMock(); auto localEntityCfg = LocalEntityCfg(localId, IndicationCfg(), fhMock); auto fsMock = FilesystemMock(); @@ -41,15 +43,34 @@ TEST_CASE("CFDP Dest Handler", "[cfdp]") { CHECK(destHandler.getTransactionStep() == DestHandler::TransactionStep::IDLE); } + SECTION("Idle State Machine Iteration") { + CHECK(destHandler.performStateMachine() == OK); + CHECK(destHandler.getCfdpState() == CfdpStates::IDLE); + CHECK(destHandler.getTransactionStep() == DestHandler::TransactionStep::IDLE); + } + SECTION("Empty File Transfer") { - + CHECK(destHandler.performStateMachine() == OK); + FileSize size(0); + std::string srcNameString = "hello.txt"; + std::string destNameString = "hello-cpy.txt"; + StringLv srcName(srcNameString); + StringLv destName(destNameString); + MetadataInfo info(false, cfdp::ChecksumTypes::NULL_CHECKSUM, size, srcName, destName); + auto seqNum = TransactionSeqNum(UnsignedByteField(1)); + PduConfig conf(remoteId, localId, TransmissionModes::UNACKNOWLEDGED, seqNum); + MetadataPduCreator metadataPdu(conf, info); + store_address_t storeId; + uint8_t* ptr; + CHECK(tcStore.getFreeElement(&storeId, metadataPdu.getSerializedSize(), &ptr) == OK); + size_t serLen = 0; + CHECK(metadataPdu.serialize(ptr, serLen, metadataPdu.getSerializedSize()) == OK); + PacketInfo packetInfo(metadataPdu.getPduType(), metadataPdu.getDirectiveCode(), storeId); + packetInfoList.push_back(packetInfo); + CHECK(destHandler.performStateMachine() == OK); } - SECTION("Small File Transfer") { + SECTION("Small File Transfer") {} - } - - SECTION("Segmented File Transfer") { - - } + SECTION("Segmented File Transfer") {} } \ No newline at end of file diff --git a/unittests/mocks/StorageManagerMock.h b/unittests/mocks/StorageManagerMock.h index f33ba19b..a52e46db 100644 --- a/unittests/mocks/StorageManagerMock.h +++ b/unittests/mocks/StorageManagerMock.h @@ -32,6 +32,9 @@ class StorageManagerMock : public LocalPool { std::pair nextModifyDataCallFails; std::pair nextDeleteDataCallFails; std::pair nextFreeElementCallFails; + + using LocalPool::getFreeElement; + void reset(); }; #endif // FSFW_TESTS_STORAGEMANAGERMOCK_H From ece5ae59e4b7ab50e98d1f7b86e332366ab0c941 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Mon, 5 Sep 2022 16:22:41 +0200 Subject: [PATCH 088/169] compile fixes --- src/fsfw/serialize/SerialBufferAdapter.cpp | 3 ++- src/fsfw/tmtcservices/PusServiceBase.h | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/src/fsfw/serialize/SerialBufferAdapter.cpp b/src/fsfw/serialize/SerialBufferAdapter.cpp index f87d0812..36c0cef3 100644 --- a/src/fsfw/serialize/SerialBufferAdapter.cpp +++ b/src/fsfw/serialize/SerialBufferAdapter.cpp @@ -119,7 +119,8 @@ const uint8_t* SerialBufferAdapter::getConstBuffer() const { } template -void SerialBufferAdapter::setBuffer(const uint8_t* data, count_t len) { +void SerialBufferAdapter::setBuffer(uint8_t* data, count_t len) { + this->buffer = data; this->constBuffer = data; this->bufferLength = len; } diff --git a/src/fsfw/tmtcservices/PusServiceBase.h b/src/fsfw/tmtcservices/PusServiceBase.h index afad9e03..92ce0d99 100644 --- a/src/fsfw/tmtcservices/PusServiceBase.h +++ b/src/fsfw/tmtcservices/PusServiceBase.h @@ -68,7 +68,7 @@ struct PsbParams { * a suitable global distributor with the static ID @PusServiceBase::pusDistributor and * register itself at that object. */ - PUSDistributorIF* pusDistributor = nullptr; + PusDistributorIF* pusDistributor = nullptr; TimeWriterIF* timeStamper = nullptr; }; From afc48726b96d8f8294f1e139aee131ca1007c09f Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Mon, 5 Sep 2022 16:23:13 +0200 Subject: [PATCH 089/169] comment out check --- unittests/cfdp/handler/testDestHandler.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/unittests/cfdp/handler/testDestHandler.cpp b/unittests/cfdp/handler/testDestHandler.cpp index 47f17f2d..79491bf9 100644 --- a/unittests/cfdp/handler/testDestHandler.cpp +++ b/unittests/cfdp/handler/testDestHandler.cpp @@ -67,7 +67,7 @@ TEST_CASE("CFDP Dest Handler", "[cfdp]") { CHECK(metadataPdu.serialize(ptr, serLen, metadataPdu.getSerializedSize()) == OK); PacketInfo packetInfo(metadataPdu.getPduType(), metadataPdu.getDirectiveCode(), storeId); packetInfoList.push_back(packetInfo); - CHECK(destHandler.performStateMachine() == OK); + //CHECK(destHandler.performStateMachine() == OK); } SECTION("Small File Transfer") {} From 5a3f05fa7996a0261b7ccb6a6b47153dae949e19 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Mon, 5 Sep 2022 17:20:29 +0200 Subject: [PATCH 090/169] return struct ref instead of code --- src/fsfw/cfdp/handler/DestHandler.cpp | 62 +++++++++++++++------- src/fsfw/cfdp/handler/DestHandler.h | 20 +++++-- unittests/cfdp/handler/testDestHandler.cpp | 14 +++-- 3 files changed, 70 insertions(+), 26 deletions(-) diff --git a/src/fsfw/cfdp/handler/DestHandler.cpp b/src/fsfw/cfdp/handler/DestHandler.cpp index 487ee817..5142731d 100644 --- a/src/fsfw/cfdp/handler/DestHandler.cpp +++ b/src/fsfw/cfdp/handler/DestHandler.cpp @@ -23,16 +23,19 @@ cfdp::DestHandler::DestHandler(DestHandlerParams params, FsfwParams fsfwParams) tp.pduConf.direction = cfdp::Direction::TOWARDS_SENDER; } -ReturnValue_t cfdp::DestHandler::performStateMachine() { +const cfdp::DestFsmResult& cfdp::DestHandler::performStateMachine() { ReturnValue_t result; - ReturnValue_t status = returnvalue::OK; + uint8_t errorIdx = 0; + fsmRes.callStatus = CallStatus::CALL_AFTER_DELAY; + fsmRes.result = OK; if (step == TransactionStep::IDLE) { for (auto infoIter = dp.packetListRef.begin(); infoIter != dp.packetListRef.end();) { if (infoIter->pduType == PduType::FILE_DIRECTIVE and infoIter->directiveType == FileDirectives::METADATA) { result = handleMetadataPdu(*infoIter); - if (result != OK) { - status = result; + if (result != OK and errorIdx < 3) { + fsmRes.errorCodes[errorIdx] = result; + errorIdx++; } // Store data was deleted in PDU handler because a store guard is used dp.packetListRef.erase(infoIter++); @@ -50,17 +53,18 @@ ReturnValue_t cfdp::DestHandler::performStateMachine() { } if (step != TransactionStep::IDLE) { - return CALL_FSM_AGAIN; + fsmRes.callStatus = CallStatus::CALL_AGAIN; } - return status; + return updateFsmRes(errorIdx); } if (cfdpState == CfdpStates::BUSY_CLASS_1_NACKED) { if (step == TransactionStep::RECEIVING_FILE_DATA_PDUS) { for (auto infoIter = dp.packetListRef.begin(); infoIter != dp.packetListRef.end();) { if (infoIter->pduType == PduType::FILE_DATA) { result = handleFileDataPdu(*infoIter); - if (result != OK) { - status = result; + if (result != OK and errorIdx < 3) { + fsmRes.errorCodes[errorIdx] = result; + errorIdx++; } // Store data was deleted in PDU handler because a store guard is used dp.packetListRef.erase(infoIter++); @@ -69,8 +73,9 @@ ReturnValue_t cfdp::DestHandler::performStateMachine() { if (infoIter->pduType == PduType::FILE_DIRECTIVE and infoIter->directiveType == FileDirectives::EOF_DIRECTIVE) { result = handleEofPdu(*infoIter); - if (result != OK) { - status = result; + if (result != OK and errorIdx < 3) { + fsmRes.errorCodes[errorIdx] = result; + errorIdx++; } // Store data was deleted in PDU handler because a store guard is used dp.packetListRef.erase(infoIter++); @@ -80,18 +85,20 @@ ReturnValue_t cfdp::DestHandler::performStateMachine() { } if (step == TransactionStep::TRANSFER_COMPLETION) { result = handleTransferCompletion(); - if (result != OK) { - status = result; + if (result != OK and errorIdx < 3) { + fsmRes.errorCodes[errorIdx] = result; + errorIdx++; } } if (step == TransactionStep::SENDING_FINISHED_PDU) { result = sendFinishedPdu(); - if (result != OK) { - status = result; + if (result != OK and errorIdx < 3) { + fsmRes.errorCodes[errorIdx] = result; + errorIdx++; } finish(); } - return status; + return updateFsmRes(errorIdx); } if (cfdpState == CfdpStates::BUSY_CLASS_2_ACKED) { // TODO: Will be implemented at a later stage @@ -99,7 +106,7 @@ ReturnValue_t cfdp::DestHandler::performStateMachine() { sif::warning << "CFDP state machine for acknowledged mode not implemented yet" << std::endl; #endif } - return OK; + return updateFsmRes(errorIdx); } ReturnValue_t cfdp::DestHandler::passPacket(PacketInfo packet) { @@ -146,7 +153,7 @@ ReturnValue_t cfdp::DestHandler::handleMetadataPdu(const PacketInfo& info) { // I think it might be a good idea to cache some sort of error code, which // is translated into a warning and/or event by an upper layer if (result != OK) { - return handleMetadataParseError(constAccessorPair.second.data(), + return handleMetadataParseError(result, constAccessorPair.second.data(), constAccessorPair.second.size()); } return startTransaction(reader, metadataInfo); @@ -228,7 +235,8 @@ ReturnValue_t cfdp::DestHandler::handleEofPdu(const cfdp::PacketInfo& info) { return returnvalue::OK; } -ReturnValue_t cfdp::DestHandler::handleMetadataParseError(const uint8_t* rawData, size_t maxSize) { +ReturnValue_t cfdp::DestHandler::handleMetadataParseError(ReturnValue_t result, + const uint8_t* rawData, size_t maxSize) { // TODO: try to extract destination ID for error // TODO: Invalid metadata PDU. #if FSFW_CPP_OSTREAM_ENABLED == 1 @@ -236,7 +244,7 @@ ReturnValue_t cfdp::DestHandler::handleMetadataParseError(const uint8_t* rawData #else #endif HeaderReader headerReader(rawData, maxSize); - ReturnValue_t result = headerReader.parseData(); + result = headerReader.parseData(); if (result != OK) { // TODO: Now this really should not happen. Warning or error, // yield or cache appropriate returnvalue @@ -296,8 +304,13 @@ ReturnValue_t cfdp::DestHandler::startTransaction(MetadataPduReader& reader, Met tp.pduConf.direction = Direction::TOWARDS_SENDER; tp.transactionId.entityId = tp.pduConf.sourceId; tp.transactionId.seqNum = tp.pduConf.seqNum; - if (not dp.remoteCfgTable.getRemoteCfg(tp.pduConf.destId, &tp.remoteCfg)) { + if (not dp.remoteCfgTable.getRemoteCfg(tp.pduConf.sourceId, &tp.remoteCfg)) { // TODO: Warning, event etc. +#if FSFW_CPP_OSTREAM_ENABLED == 1 + sif::warning << "cfdp::DestHandler" << __func__ + << ": No remote configuration found for destination ID " + << tp.pduConf.destId.getValue() << std::endl; +#endif return FAILED; } step = TransactionStep::RECEIVING_FILE_DATA_PDUS; @@ -421,3 +434,12 @@ ReturnValue_t cfdp::DestHandler::sendFinishedPdu() { } cfdp::DestHandler::TransactionStep cfdp::DestHandler::getTransactionStep() const { return step; } + +const cfdp::DestFsmResult& cfdp::DestHandler::updateFsmRes(uint8_t errors) { + fsmRes.errors = errors; + fsmRes.result = OK; + if (fsmRes.errors > 0) { + fsmRes.result = FAILED; + } + return fsmRes; +} diff --git a/src/fsfw/cfdp/handler/DestHandler.h b/src/fsfw/cfdp/handler/DestHandler.h index 1b4bed75..30806153 100644 --- a/src/fsfw/cfdp/handler/DestHandler.h +++ b/src/fsfw/cfdp/handler/DestHandler.h @@ -70,6 +70,16 @@ struct FsfwParams { StorageManagerIF* tmStore = nullptr; }; +enum class CallStatus { DONE, CALL_AFTER_DELAY, CALL_AGAIN }; + +struct DestFsmResult { + ReturnValue_t result = returnvalue::OK; + CallStatus callStatus = CallStatus::CALL_AFTER_DELAY; + uint32_t packetsSent = 0; + uint8_t errors = 0; + std::array errorCodes = {}; +}; + class DestHandler { public: enum class TransactionStep { @@ -83,7 +93,8 @@ class DestHandler { /** * Will be returned if it is advisable to call the state machine operation call again */ - ReturnValue_t CALL_FSM_AGAIN = returnvalue::makeCode(1, 0); + ReturnValue_t PARTIAL_SUCCESS = returnvalue::makeCode(0, 2); + ReturnValue_t FAILURE = returnvalue::makeCode(0, 3); explicit DestHandler(DestHandlerParams handlerParams, FsfwParams fsfwParams); /** @@ -92,7 +103,7 @@ class DestHandler { * - @c returnvalue::OK State machine OK for this execution cycle * - @c CALL_FSM_AGAIN State machine should be called again. */ - ReturnValue_t performStateMachine(); + const DestFsmResult& performStateMachine(); ReturnValue_t passPacket(PacketInfo packet); @@ -145,16 +156,19 @@ class DestHandler { DestHandlerParams dp; FsfwParams fp; TransactionParams tp; + DestFsmResult fsmRes; ReturnValue_t startTransaction(MetadataPduReader& reader, MetadataInfo& info); ReturnValue_t handleMetadataPdu(const PacketInfo& info); ReturnValue_t handleFileDataPdu(const PacketInfo& info); ReturnValue_t handleEofPdu(const PacketInfo& info); - ReturnValue_t handleMetadataParseError(const uint8_t* rawData, size_t maxSize); + ReturnValue_t handleMetadataParseError(ReturnValue_t result, const uint8_t* rawData, + size_t maxSize); ReturnValue_t handleTransferCompletion(); ReturnValue_t sendFinishedPdu(); ReturnValue_t noticeOfCompletion(); ReturnValue_t checksumVerification(); + const DestFsmResult& updateFsmRes(uint8_t errors); void finish(); }; diff --git a/unittests/cfdp/handler/testDestHandler.cpp b/unittests/cfdp/handler/testDestHandler.cpp index 79491bf9..1873a081 100644 --- a/unittests/cfdp/handler/testDestHandler.cpp +++ b/unittests/cfdp/handler/testDestHandler.cpp @@ -33,6 +33,9 @@ TEST_CASE("CFDP Dest Handler", "[cfdp]") { StorageManagerMock tcStore(2, storeCfg); StorageManagerMock tmStore(3, storeCfg); FsfwParams fp(tmReceiver, mqMock, eventReporterMock); + RemoteEntityCfg cfg; + cfg.remoteId = remoteId; + remoteCfgTableMock.addRemoteConfig(cfg); fp.tcStore = &tcStore; fp.tmStore = &tmStore; auto destHandler = DestHandler(dp, fp); @@ -44,13 +47,17 @@ TEST_CASE("CFDP Dest Handler", "[cfdp]") { } SECTION("Idle State Machine Iteration") { - CHECK(destHandler.performStateMachine() == OK); + auto res = destHandler.performStateMachine(); + CHECK(res.result == OK); + CHECK(res.callStatus == CallStatus::CALL_AFTER_DELAY); + CHECK(res.errors == 0); CHECK(destHandler.getCfdpState() == CfdpStates::IDLE); CHECK(destHandler.getTransactionStep() == DestHandler::TransactionStep::IDLE); } SECTION("Empty File Transfer") { - CHECK(destHandler.performStateMachine() == OK); + const DestFsmResult& res = destHandler.performStateMachine(); + CHECK(res.result == OK); FileSize size(0); std::string srcNameString = "hello.txt"; std::string destNameString = "hello-cpy.txt"; @@ -67,7 +74,8 @@ TEST_CASE("CFDP Dest Handler", "[cfdp]") { CHECK(metadataPdu.serialize(ptr, serLen, metadataPdu.getSerializedSize()) == OK); PacketInfo packetInfo(metadataPdu.getPduType(), metadataPdu.getDirectiveCode(), storeId); packetInfoList.push_back(packetInfo); - //CHECK(destHandler.performStateMachine() == OK); + destHandler.performStateMachine(); + CHECK(res.result == OK); } SECTION("Small File Transfer") {} From 2e4cdb73661426a6909cd95c1b731ddb64379681 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Mon, 5 Sep 2022 17:42:56 +0200 Subject: [PATCH 091/169] additional filesystem abstractions --- src/fsfw/cfdp/handler/DestHandler.cpp | 62 +++++++++++----------- src/fsfw/cfdp/handler/DestHandler.h | 34 +++++++----- src/fsfw/filesystem/FileSystemArgsIF.h | 2 +- src/fsfw/filesystem/HasFileSystemIF.h | 9 ++++ src/fsfw_hal/host/HostFilesystem.cpp | 14 +++++ src/fsfw_hal/host/HostFilesystem.h | 3 ++ unittests/cfdp/handler/testDestHandler.cpp | 4 +- unittests/mocks/FilesystemMock.cpp | 14 +++++ unittests/mocks/FilesystemMock.h | 6 ++- 9 files changed, 102 insertions(+), 46 deletions(-) diff --git a/src/fsfw/cfdp/handler/DestHandler.cpp b/src/fsfw/cfdp/handler/DestHandler.cpp index 5142731d..23852272 100644 --- a/src/fsfw/cfdp/handler/DestHandler.cpp +++ b/src/fsfw/cfdp/handler/DestHandler.cpp @@ -23,12 +23,11 @@ cfdp::DestHandler::DestHandler(DestHandlerParams params, FsfwParams fsfwParams) tp.pduConf.direction = cfdp::Direction::TOWARDS_SENDER; } -const cfdp::DestFsmResult& cfdp::DestHandler::performStateMachine() { +const cfdp::DestHandler::FsmResult& cfdp::DestHandler::performStateMachine() { ReturnValue_t result; uint8_t errorIdx = 0; - fsmRes.callStatus = CallStatus::CALL_AFTER_DELAY; - fsmRes.result = OK; - if (step == TransactionStep::IDLE) { + fsmRes.resetOfIteration(); + if (fsmRes.step == TransactionStep::IDLE) { for (auto infoIter = dp.packetListRef.begin(); infoIter != dp.packetListRef.end();) { if (infoIter->pduType == PduType::FILE_DIRECTIVE and infoIter->directiveType == FileDirectives::METADATA) { @@ -42,7 +41,7 @@ const cfdp::DestFsmResult& cfdp::DestHandler::performStateMachine() { } infoIter++; } - if (step == TransactionStep::IDLE) { + if (fsmRes.step == TransactionStep::IDLE) { // To decrease the already high complexity of the software, all packets arriving before // a metadata PDU are deleted. for (auto infoIter = dp.packetListRef.begin(); infoIter != dp.packetListRef.end();) { @@ -52,13 +51,13 @@ const cfdp::DestFsmResult& cfdp::DestHandler::performStateMachine() { dp.packetListRef.clear(); } - if (step != TransactionStep::IDLE) { + if (fsmRes.step != TransactionStep::IDLE) { fsmRes.callStatus = CallStatus::CALL_AGAIN; } return updateFsmRes(errorIdx); } - if (cfdpState == CfdpStates::BUSY_CLASS_1_NACKED) { - if (step == TransactionStep::RECEIVING_FILE_DATA_PDUS) { + if (fsmRes.state == CfdpStates::BUSY_CLASS_1_NACKED) { + if (fsmRes.step == TransactionStep::RECEIVING_FILE_DATA_PDUS) { for (auto infoIter = dp.packetListRef.begin(); infoIter != dp.packetListRef.end();) { if (infoIter->pduType == PduType::FILE_DATA) { result = handleFileDataPdu(*infoIter); @@ -83,14 +82,14 @@ const cfdp::DestFsmResult& cfdp::DestHandler::performStateMachine() { infoIter++; } } - if (step == TransactionStep::TRANSFER_COMPLETION) { + if (fsmRes.step == TransactionStep::TRANSFER_COMPLETION) { result = handleTransferCompletion(); if (result != OK and errorIdx < 3) { fsmRes.errorCodes[errorIdx] = result; errorIdx++; } } - if (step == TransactionStep::SENDING_FINISHED_PDU) { + if (fsmRes.step == TransactionStep::SENDING_FINISHED_PDU) { result = sendFinishedPdu(); if (result != OK and errorIdx < 3) { fsmRes.errorCodes[errorIdx] = result; @@ -100,7 +99,7 @@ const cfdp::DestFsmResult& cfdp::DestHandler::performStateMachine() { } return updateFsmRes(errorIdx); } - if (cfdpState == CfdpStates::BUSY_CLASS_2_ACKED) { + if (fsmRes.state == CfdpStates::BUSY_CLASS_2_ACKED) { // TODO: Will be implemented at a later stage #if FSFW_CPP_OSTREAM_ENABLED == 1 sif::warning << "CFDP state machine for acknowledged mode not implemented yet" << std::endl; @@ -225,11 +224,11 @@ ReturnValue_t cfdp::DestHandler::handleEofPdu(const cfdp::PacketInfo& info) { } tp.fileSize.setFileSize(fileSizeFromEof, std::nullopt); } - if (step == TransactionStep::RECEIVING_FILE_DATA_PDUS) { - if (cfdpState == CfdpStates::BUSY_CLASS_1_NACKED) { - step = TransactionStep::TRANSFER_COMPLETION; - } else if (cfdpState == CfdpStates::BUSY_CLASS_2_ACKED) { - step = TransactionStep::SENDING_ACK_PDU; + if (fsmRes.step == TransactionStep::RECEIVING_FILE_DATA_PDUS) { + if (fsmRes.state == CfdpStates::BUSY_CLASS_1_NACKED) { + fsmRes.step = TransactionStep::TRANSFER_COMPLETION; + } else if (fsmRes.state == CfdpStates::BUSY_CLASS_2_ACKED) { + fsmRes.step = TransactionStep::SENDING_ACK_PDU; } } return returnvalue::OK; @@ -272,15 +271,15 @@ ReturnValue_t cfdp::DestHandler::handleMetadataParseError(ReturnValue_t result, } ReturnValue_t cfdp::DestHandler::startTransaction(MetadataPduReader& reader, MetadataInfo& info) { - if (cfdpState != CfdpStates::IDLE) { + if (fsmRes.state != CfdpStates::IDLE) { // According to standard, discard metadata PDU if we are busy return returnvalue::OK; } - step = TransactionStep::TRANSACTION_START; + fsmRes.step = TransactionStep::TRANSACTION_START; if (reader.getTransmissionMode() == TransmissionModes::UNACKNOWLEDGED) { - cfdpState = CfdpStates::BUSY_CLASS_1_NACKED; + fsmRes.state = CfdpStates::BUSY_CLASS_1_NACKED; } else if (reader.getTransmissionMode() == TransmissionModes::ACKNOWLEDGED) { - cfdpState = CfdpStates::BUSY_CLASS_2_ACKED; + fsmRes.state = CfdpStates::BUSY_CLASS_2_ACKED; } tp.checksumType = info.getChecksumType(); tp.closureRequested = info.isClosureRequested(); @@ -313,7 +312,7 @@ ReturnValue_t cfdp::DestHandler::startTransaction(MetadataPduReader& reader, Met #endif return FAILED; } - step = TransactionStep::RECEIVING_FILE_DATA_PDUS; + fsmRes.step = TransactionStep::RECEIVING_FILE_DATA_PDUS; MetadataRecvdParams params(tp.transactionId, tp.pduConf.sourceId); params.fileSize = tp.fileSize.getSize(); params.destFileName = tp.destName.data(); @@ -324,7 +323,7 @@ ReturnValue_t cfdp::DestHandler::startTransaction(MetadataPduReader& reader, Met return OK; } -cfdp::CfdpStates cfdp::DestHandler::getCfdpState() const { return cfdpState; } +cfdp::CfdpStates cfdp::DestHandler::getCfdpState() const { return fsmRes.state; } ReturnValue_t cfdp::DestHandler::handleTransferCompletion() { ReturnValue_t result; @@ -339,14 +338,14 @@ ReturnValue_t cfdp::DestHandler::handleTransferCompletion() { result = noticeOfCompletion(); if (result != OK) { } - if (cfdpState == CfdpStates::BUSY_CLASS_1_NACKED) { + if (fsmRes.state == CfdpStates::BUSY_CLASS_1_NACKED) { if (tp.closureRequested) { - step = TransactionStep::SENDING_FINISHED_PDU; + fsmRes.step = TransactionStep::SENDING_FINISHED_PDU; } else { finish(); } - } else if (cfdpState == CfdpStates::BUSY_CLASS_2_ACKED) { - step = TransactionStep::SENDING_FINISHED_PDU; + } else if (fsmRes.state == CfdpStates::BUSY_CLASS_2_ACKED) { + fsmRes.step = TransactionStep::SENDING_FINISHED_PDU; } return OK; } @@ -354,8 +353,8 @@ ReturnValue_t cfdp::DestHandler::handleTransferCompletion() { void cfdp::DestHandler::finish() { tp.reset(); dp.packetListRef.clear(); - cfdpState = CfdpStates::IDLE; - step = TransactionStep::IDLE; + fsmRes.state = CfdpStates::IDLE; + fsmRes.step = TransactionStep::IDLE; } ReturnValue_t cfdp::DestHandler::checksumVerification() { @@ -430,12 +429,15 @@ ReturnValue_t cfdp::DestHandler::sendFinishedPdu() { // TODO: Error handling and event, this is a non CFDP specific error (most likely store is full) return result; } + fsmRes.packetsSent++; return OK; } -cfdp::DestHandler::TransactionStep cfdp::DestHandler::getTransactionStep() const { return step; } +cfdp::DestHandler::TransactionStep cfdp::DestHandler::getTransactionStep() const { + return fsmRes.step; +} -const cfdp::DestFsmResult& cfdp::DestHandler::updateFsmRes(uint8_t errors) { +const cfdp::DestHandler::FsmResult& cfdp::DestHandler::updateFsmRes(uint8_t errors) { fsmRes.errors = errors; fsmRes.result = OK; if (fsmRes.errors > 0) { diff --git a/src/fsfw/cfdp/handler/DestHandler.h b/src/fsfw/cfdp/handler/DestHandler.h index 30806153..ba4bcbe3 100644 --- a/src/fsfw/cfdp/handler/DestHandler.h +++ b/src/fsfw/cfdp/handler/DestHandler.h @@ -72,14 +72,6 @@ struct FsfwParams { enum class CallStatus { DONE, CALL_AFTER_DELAY, CALL_AGAIN }; -struct DestFsmResult { - ReturnValue_t result = returnvalue::OK; - CallStatus callStatus = CallStatus::CALL_AFTER_DELAY; - uint32_t packetsSent = 0; - uint8_t errors = 0; - std::array errorCodes = {}; -}; - class DestHandler { public: enum class TransactionStep { @@ -90,6 +82,24 @@ class DestHandler { TRANSFER_COMPLETION = 4, SENDING_FINISHED_PDU = 5 }; + + struct FsmResult { + public: + ReturnValue_t result = returnvalue::OK; + CallStatus callStatus = CallStatus::CALL_AFTER_DELAY; + TransactionStep step = TransactionStep::IDLE; + CfdpStates state = CfdpStates::IDLE; + uint32_t packetsSent = 0; + uint8_t errors = 0; + std::array errorCodes = {}; + void resetOfIteration() { + result = returnvalue::OK; + callStatus = CallStatus::CALL_AFTER_DELAY; + packetsSent = 0; + errors = 0; + errorCodes.fill(returnvalue::OK); + } + }; /** * Will be returned if it is advisable to call the state machine operation call again */ @@ -103,7 +113,7 @@ class DestHandler { * - @c returnvalue::OK State machine OK for this execution cycle * - @c CALL_FSM_AGAIN State machine should be called again. */ - const DestFsmResult& performStateMachine(); + const FsmResult& performStateMachine(); ReturnValue_t passPacket(PacketInfo packet); @@ -149,14 +159,12 @@ class DestHandler { RemoteEntityCfg* remoteCfg = nullptr; }; - TransactionStep step = TransactionStep::IDLE; - CfdpStates cfdpState = CfdpStates::IDLE; std::vector tlvVec; std::vector userTlvVec; DestHandlerParams dp; FsfwParams fp; TransactionParams tp; - DestFsmResult fsmRes; + FsmResult fsmRes; ReturnValue_t startTransaction(MetadataPduReader& reader, MetadataInfo& info); ReturnValue_t handleMetadataPdu(const PacketInfo& info); @@ -168,7 +176,7 @@ class DestHandler { ReturnValue_t sendFinishedPdu(); ReturnValue_t noticeOfCompletion(); ReturnValue_t checksumVerification(); - const DestFsmResult& updateFsmRes(uint8_t errors); + const FsmResult& updateFsmRes(uint8_t errors); void finish(); }; diff --git a/src/fsfw/filesystem/FileSystemArgsIF.h b/src/fsfw/filesystem/FileSystemArgsIF.h index f1617f62..656764fa 100644 --- a/src/fsfw/filesystem/FileSystemArgsIF.h +++ b/src/fsfw/filesystem/FileSystemArgsIF.h @@ -7,7 +7,7 @@ */ class FileSystemArgsIF { public: - virtual ~FileSystemArgsIF(){}; + virtual ~FileSystemArgsIF() = default; }; #endif /* FSFW_SRC_FSFW_MEMORY_FILESYSTEMARGS_H_ */ diff --git a/src/fsfw/filesystem/HasFileSystemIF.h b/src/fsfw/filesystem/HasFileSystemIF.h index f206d53c..ee8c5f91 100644 --- a/src/fsfw/filesystem/HasFileSystemIF.h +++ b/src/fsfw/filesystem/HasFileSystemIF.h @@ -73,6 +73,15 @@ class HasFileSystemIF { return MessageQueueIF::NO_QUEUE; } + virtual bool fileExists(FilesystemParams params) = 0; + + /** + * Truncate a file, deleting its contents and setting its size to 0 accordingly. + * @param params + * @return + */ + virtual ReturnValue_t truncateFile(FilesystemParams params) = 0; + /** * @brief Generic function to append to file. * @param fileOpInfo General information: File name, size to write, offset, additional arguments diff --git a/src/fsfw_hal/host/HostFilesystem.cpp b/src/fsfw_hal/host/HostFilesystem.cpp index 20678a8c..6dc099b1 100644 --- a/src/fsfw_hal/host/HostFilesystem.cpp +++ b/src/fsfw_hal/host/HostFilesystem.cpp @@ -144,3 +144,17 @@ ReturnValue_t HostFilesystem::rename(const char *oldPath_, const char *newPath_, } return returnvalue::OK; } + +bool HostFilesystem::fileExists(FilesystemParams params) { + path path(params.path); + return filesystem::exists(path); +} + +ReturnValue_t HostFilesystem::truncateFile(FilesystemParams params) { + path path(params.path); + if (not filesystem::exists(path)) { + return FILE_DOES_NOT_EXIST; + } + ofstream of(path); + return returnvalue::OK; +} diff --git a/src/fsfw_hal/host/HostFilesystem.h b/src/fsfw_hal/host/HostFilesystem.h index c35e0fda..7b865e2d 100644 --- a/src/fsfw_hal/host/HostFilesystem.h +++ b/src/fsfw_hal/host/HostFilesystem.h @@ -8,6 +8,9 @@ class HostFilesystem : public HasFileSystemIF { public: HostFilesystem(); + + bool fileExists(FilesystemParams params) override; + ReturnValue_t truncateFile(FilesystemParams params) override; ReturnValue_t writeToFile(FileOpParams params, const uint8_t *data) override; ReturnValue_t readFromFile(FileOpParams fileOpInfo, uint8_t **buffer, size_t &readSize, size_t maxSize) override; diff --git a/unittests/cfdp/handler/testDestHandler.cpp b/unittests/cfdp/handler/testDestHandler.cpp index 1873a081..3fc8f472 100644 --- a/unittests/cfdp/handler/testDestHandler.cpp +++ b/unittests/cfdp/handler/testDestHandler.cpp @@ -56,7 +56,7 @@ TEST_CASE("CFDP Dest Handler", "[cfdp]") { } SECTION("Empty File Transfer") { - const DestFsmResult& res = destHandler.performStateMachine(); + const DestHandler::FsmResult& res = destHandler.performStateMachine(); CHECK(res.result == OK); FileSize size(0); std::string srcNameString = "hello.txt"; @@ -76,6 +76,8 @@ TEST_CASE("CFDP Dest Handler", "[cfdp]") { packetInfoList.push_back(packetInfo); destHandler.performStateMachine(); CHECK(res.result == OK); + CHECK(res.callStatus == CallStatus::CALL_AGAIN); + destHandler.performStateMachine(); } SECTION("Small File Transfer") {} diff --git a/unittests/mocks/FilesystemMock.cpp b/unittests/mocks/FilesystemMock.cpp index 3d18e3cb..bf0c3bf6 100644 --- a/unittests/mocks/FilesystemMock.cpp +++ b/unittests/mocks/FilesystemMock.cpp @@ -124,3 +124,17 @@ void FilesystemMock::reset() { std::queue empty; std::swap(renameQueue, empty); } + +bool FilesystemMock::fileExists(FilesystemParams params) { + std::string filename(params.path); + auto iter = fileMap.find(filename); + if (iter == fileMap.end()) { + return false; + } + return true; +} + +ReturnValue_t FilesystemMock::truncateFile(FilesystemParams params) { + truncateCalledOnFile = params.path; + return returnvalue::OK; +} diff --git a/unittests/mocks/FilesystemMock.h b/unittests/mocks/FilesystemMock.h index 19d4d38c..74221d70 100644 --- a/unittests/mocks/FilesystemMock.h +++ b/unittests/mocks/FilesystemMock.h @@ -53,8 +53,12 @@ class FilesystemMock : public HasFileSystemIF { std::string newName; }; std::queue renameQueue; - + std::string truncateCalledOnFile; ReturnValue_t feedFile(const std::string &filename, std::ifstream &file); + + bool fileExists(FilesystemParams params) override; + ReturnValue_t truncateFile(FilesystemParams params) override; + ReturnValue_t writeToFile(FileOpParams params, const uint8_t *data) override; ReturnValue_t readFromFile(FileOpParams params, uint8_t **buffer, size_t &readSize, size_t maxSize) override; From 7b97c8a1823a5acd1813769d2b0e8116edc2e913 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Tue, 6 Sep 2022 11:56:05 +0200 Subject: [PATCH 092/169] continue tests --- src/fsfw/cfdp/handler/DestHandler.cpp | 7 ++++++ src/fsfw/cfdp/pdu/EofPduCreator.h | 2 ++ unittests/cfdp/handler/testDestHandler.cpp | 25 ++++++++++++++++------ 3 files changed, 28 insertions(+), 6 deletions(-) diff --git a/src/fsfw/cfdp/handler/DestHandler.cpp b/src/fsfw/cfdp/handler/DestHandler.cpp index 23852272..ed529cc0 100644 --- a/src/fsfw/cfdp/handler/DestHandler.cpp +++ b/src/fsfw/cfdp/handler/DestHandler.cpp @@ -319,6 +319,13 @@ ReturnValue_t cfdp::DestHandler::startTransaction(MetadataPduReader& reader, Met params.sourceFileName = tp.sourceName.data(); params.msgsToUserArray = dynamic_cast(userTlvVec.data()); params.msgsToUserLen = info.getOptionsLen(); + FilesystemParams fparams(tp.destName.data()); + // TODO: Filesystem errors? + if (dp.user.vfs.fileExists(fparams)) { + dp.user.vfs.truncateFile(fparams); + } else { + dp.user.vfs.createFile(fparams); + } dp.user.metadataRecvdIndication(params); return OK; } diff --git a/src/fsfw/cfdp/pdu/EofPduCreator.h b/src/fsfw/cfdp/pdu/EofPduCreator.h index 7f7a25ab..f098a5d2 100644 --- a/src/fsfw/cfdp/pdu/EofPduCreator.h +++ b/src/fsfw/cfdp/pdu/EofPduCreator.h @@ -14,6 +14,8 @@ class EofPduCreator : public FileDirectiveCreator { ReturnValue_t serialize(uint8_t** buffer, size_t* size, size_t maxSize, Endianness streamEndianness) const override; + using FileDirectiveCreator::serialize; + private: EofInfo& info; }; diff --git a/unittests/cfdp/handler/testDestHandler.cpp b/unittests/cfdp/handler/testDestHandler.cpp index 3fc8f472..82f6db45 100644 --- a/unittests/cfdp/handler/testDestHandler.cpp +++ b/unittests/cfdp/handler/testDestHandler.cpp @@ -2,6 +2,7 @@ #include "fsfw/cfdp.h" #include "fsfw/cfdp/pdu/MetadataPduCreator.h" +#include "fsfw/cfdp/pdu/EofPduCreator.h" #include "mocks/AcceptsTmMock.h" #include "mocks/EventReportingProxyMock.h" #include "mocks/FilesystemMock.h" @@ -63,21 +64,33 @@ TEST_CASE("CFDP Dest Handler", "[cfdp]") { std::string destNameString = "hello-cpy.txt"; StringLv srcName(srcNameString); StringLv destName(destNameString); + FileSize cfdpFileSize(0); MetadataInfo info(false, cfdp::ChecksumTypes::NULL_CHECKSUM, size, srcName, destName); auto seqNum = TransactionSeqNum(UnsignedByteField(1)); PduConfig conf(remoteId, localId, TransmissionModes::UNACKNOWLEDGED, seqNum); - MetadataPduCreator metadataPdu(conf, info); + MetadataPduCreator metadataCreator(conf, info); store_address_t storeId; uint8_t* ptr; - CHECK(tcStore.getFreeElement(&storeId, metadataPdu.getSerializedSize(), &ptr) == OK); + REQUIRE(tcStore.getFreeElement(&storeId, metadataCreator.getSerializedSize(), &ptr) == OK); size_t serLen = 0; - CHECK(metadataPdu.serialize(ptr, serLen, metadataPdu.getSerializedSize()) == OK); - PacketInfo packetInfo(metadataPdu.getPduType(), metadataPdu.getDirectiveCode(), storeId); + REQUIRE(metadataCreator.serialize(ptr, serLen, metadataCreator.getSerializedSize()) == OK); + PacketInfo packetInfo(metadataCreator.getPduType(), metadataCreator.getDirectiveCode(), storeId); packetInfoList.push_back(packetInfo); destHandler.performStateMachine(); - CHECK(res.result == OK); - CHECK(res.callStatus == CallStatus::CALL_AGAIN); + REQUIRE(res.result == OK); + REQUIRE(res.callStatus == CallStatus::CALL_AGAIN); + // Assert that the packet was deleted after handling + REQUIRE(not tcStore.hasDataAtId(storeId)); destHandler.performStateMachine(); + REQUIRE(fsMock.fileMap.find("hello-cpy.txt") != fsMock.fileMap.end()); + REQUIRE(res.result == OK); + REQUIRE(res.callStatus == CallStatus::CALL_AFTER_DELAY); + REQUIRE(res.state == CfdpStates::BUSY_CLASS_1_NACKED); + REQUIRE(res.step == DestHandler::TransactionStep::RECEIVING_FILE_DATA_PDUS); + EofInfo eofInfo(cfdp::ConditionCode::NO_ERROR, 0, cfdpFileSize); + EofPduCreator eofCreator(conf, eofInfo); + REQUIRE(tcStore.getFreeElement(&storeId, eofCreator.getSerializedSize(), &ptr) == OK); + REQUIRE(eofCreator.serialize(ptr, serLen, eofCreator.getSerializedSize()) == OK); } SECTION("Small File Transfer") {} From 806ae9b41af257886101fb266f82f34c0bbfaf02 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Tue, 6 Sep 2022 13:16:00 +0200 Subject: [PATCH 093/169] check that indication was called --- src/fsfw/cfdp/VarLenFields.h | 2 +- src/fsfw/cfdp/handler/DestHandler.cpp | 2 ++ src/fsfw/cfdp/handler/DestHandler.h | 1 + unittests/cfdp/handler/testDestHandler.cpp | 22 +++++++++++++++------- unittests/mocks/cfdp/UserMock.cpp | 12 +++++++++++- unittests/mocks/cfdp/UserMock.h | 6 ++++++ 6 files changed, 36 insertions(+), 9 deletions(-) diff --git a/src/fsfw/cfdp/VarLenFields.h b/src/fsfw/cfdp/VarLenFields.h index 7f369e0c..03664995 100644 --- a/src/fsfw/cfdp/VarLenFields.h +++ b/src/fsfw/cfdp/VarLenFields.h @@ -78,7 +78,7 @@ struct TransactionId { TransactionId(EntityId entityId, TransactionSeqNum seqNum) : entityId(std::move(entityId)), seqNum(std::move(seqNum)) {} - bool operator==(const TransactionId &other) { + bool operator==(const TransactionId &other) const { return entityId == other.entityId and seqNum == other.seqNum; } diff --git a/src/fsfw/cfdp/handler/DestHandler.cpp b/src/fsfw/cfdp/handler/DestHandler.cpp index ed529cc0..6cda227e 100644 --- a/src/fsfw/cfdp/handler/DestHandler.cpp +++ b/src/fsfw/cfdp/handler/DestHandler.cpp @@ -452,3 +452,5 @@ const cfdp::DestHandler::FsmResult& cfdp::DestHandler::updateFsmRes(uint8_t erro } return fsmRes; } + +const cfdp::TransactionId& cfdp::DestHandler::getTransactionId() const { return tp.transactionId; } diff --git a/src/fsfw/cfdp/handler/DestHandler.h b/src/fsfw/cfdp/handler/DestHandler.h index ba4bcbe3..b1c56721 100644 --- a/src/fsfw/cfdp/handler/DestHandler.h +++ b/src/fsfw/cfdp/handler/DestHandler.h @@ -121,6 +121,7 @@ class DestHandler { [[nodiscard]] CfdpStates getCfdpState() const; [[nodiscard]] TransactionStep getTransactionStep() const; + const TransactionId& getTransactionId() const; private: struct TransactionParams { diff --git a/unittests/cfdp/handler/testDestHandler.cpp b/unittests/cfdp/handler/testDestHandler.cpp index 82f6db45..388f766d 100644 --- a/unittests/cfdp/handler/testDestHandler.cpp +++ b/unittests/cfdp/handler/testDestHandler.cpp @@ -1,8 +1,8 @@ #include #include "fsfw/cfdp.h" -#include "fsfw/cfdp/pdu/MetadataPduCreator.h" #include "fsfw/cfdp/pdu/EofPduCreator.h" +#include "fsfw/cfdp/pdu/MetadataPduCreator.h" #include "mocks/AcceptsTmMock.h" #include "mocks/EventReportingProxyMock.h" #include "mocks/FilesystemMock.h" @@ -20,11 +20,11 @@ TEST_CASE("CFDP Dest Handler", "[cfdp]") { MessageQueueMock mqMock(destQueueId); EntityId localId = EntityId(UnsignedByteField(2)); EntityId remoteId = EntityId(UnsignedByteField(3)); - auto fhMock = FaultHandlerMock(); - auto localEntityCfg = LocalEntityCfg(localId, IndicationCfg(), fhMock); - auto fsMock = FilesystemMock(); - auto userMock = UserMock(fsMock); - auto remoteCfgTableMock = RemoteConfigTableMock(); + FaultHandlerMock fhMock; + LocalEntityCfg localEntityCfg(localId, IndicationCfg(), fhMock); + FilesystemMock fsMock; + UserMock userMock(fsMock); + RemoteConfigTableMock remoteCfgTableMock; PacketInfoList<64> packetInfoList; LostSegmentsList<128> lostSegmentsList; DestHandlerParams dp(localEntityCfg, userMock, remoteCfgTableMock, packetInfoList, @@ -74,7 +74,8 @@ TEST_CASE("CFDP Dest Handler", "[cfdp]") { REQUIRE(tcStore.getFreeElement(&storeId, metadataCreator.getSerializedSize(), &ptr) == OK); size_t serLen = 0; REQUIRE(metadataCreator.serialize(ptr, serLen, metadataCreator.getSerializedSize()) == OK); - PacketInfo packetInfo(metadataCreator.getPduType(), metadataCreator.getDirectiveCode(), storeId); + PacketInfo packetInfo(metadataCreator.getPduType(), metadataCreator.getDirectiveCode(), + storeId); packetInfoList.push_back(packetInfo); destHandler.performStateMachine(); REQUIRE(res.result == OK); @@ -82,6 +83,13 @@ TEST_CASE("CFDP Dest Handler", "[cfdp]") { // Assert that the packet was deleted after handling REQUIRE(not tcStore.hasDataAtId(storeId)); destHandler.performStateMachine(); + REQUIRE(userMock.metadataRecvd.size() == 1); + MetadataRecvdParams& params = userMock.metadataRecvd.back(); + REQUIRE(params.id == destHandler.getTransactionId()); + REQUIRE(params.sourceId.getValue() == 3); + REQUIRE(params.fileSize == 0); + REQUIRE(strcmp(params.destFileName, "hello-cpy.txt") == 0); + REQUIRE(strcmp(params.sourceFileName, "hello.txt") == 0); REQUIRE(fsMock.fileMap.find("hello-cpy.txt") != fsMock.fileMap.end()); REQUIRE(res.result == OK); REQUIRE(res.callStatus == CallStatus::CALL_AFTER_DELAY); diff --git a/unittests/mocks/cfdp/UserMock.cpp b/unittests/mocks/cfdp/UserMock.cpp index 876c2e81..f701a28b 100644 --- a/unittests/mocks/cfdp/UserMock.cpp +++ b/unittests/mocks/cfdp/UserMock.cpp @@ -10,7 +10,12 @@ void UserMock::abandonedIndication(const TransactionId& id, cfdp::ConditionCode uint64_t progress) {} void UserMock::eofRecvIndication(const TransactionId& id) {} void UserMock::transactionFinishedIndication(const TransactionFinishedParams& finishedParams) {} -void UserMock::metadataRecvdIndication(const MetadataRecvdParams& params) {} + +void UserMock::metadataRecvdIndication(const MetadataRecvdParams& params) { + MetadataRecvdParams copy = params; + metadataRecvd.push(copy); +} + void UserMock::fileSegmentRecvdIndication(const FileSegmentRecvdParams& params) {} void UserMock::reportIndication(const TransactionId& id, StatusReportIF& report) {} void UserMock::suspendedIndication(const TransactionId& id, ConditionCode code) {} @@ -18,4 +23,9 @@ void UserMock::resumedIndication(const TransactionId& id, size_t progress) {} void UserMock::faultIndication(const TransactionId& id, cfdp::ConditionCode code, size_t progress) { } +void UserMock::reset() { + auto empty = std::queue(); + metadataRecvd.swap(empty); +} + } // namespace cfdp diff --git a/unittests/mocks/cfdp/UserMock.h b/unittests/mocks/cfdp/UserMock.h index f3a5bfd9..523392bd 100644 --- a/unittests/mocks/cfdp/UserMock.h +++ b/unittests/mocks/cfdp/UserMock.h @@ -1,7 +1,10 @@ #ifndef FSFW_TESTS_CFDP_USERMOCK_H #define FSFW_TESTS_CFDP_USERMOCK_H +#include + #include "fsfw/cfdp/handler/UserBase.h" + namespace cfdp { class UserMock : public UserBase { @@ -19,6 +22,9 @@ class UserMock : public UserBase { void suspendedIndication(const TransactionId& id, ConditionCode code) override; void resumedIndication(const TransactionId& id, size_t progress) override; void faultIndication(const TransactionId& id, ConditionCode code, size_t progress) override; + + std::queue metadataRecvd; + void reset(); }; } // namespace cfdp From 428da017bae2d83310fa3bc142253afe73990497 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Tue, 6 Sep 2022 13:45:43 +0200 Subject: [PATCH 094/169] empty file transfer unittest almost done --- src/fsfw/cfdp/handler/DestHandler.cpp | 3 +++ unittests/cfdp/handler/testDestHandler.cpp | 18 +++++++++++++++++- unittests/mocks/cfdp/UserMock.cpp | 8 +++++--- unittests/mocks/cfdp/UserMock.h | 1 + 4 files changed, 26 insertions(+), 4 deletions(-) diff --git a/src/fsfw/cfdp/handler/DestHandler.cpp b/src/fsfw/cfdp/handler/DestHandler.cpp index 6cda227e..e1578c9b 100644 --- a/src/fsfw/cfdp/handler/DestHandler.cpp +++ b/src/fsfw/cfdp/handler/DestHandler.cpp @@ -224,6 +224,9 @@ ReturnValue_t cfdp::DestHandler::handleEofPdu(const cfdp::PacketInfo& info) { } tp.fileSize.setFileSize(fileSizeFromEof, std::nullopt); } + if (dp.cfg.indicCfg.eofRecvIndicRequired) { + dp.user.eofRecvIndication(getTransactionId()); + } if (fsmRes.step == TransactionStep::RECEIVING_FILE_DATA_PDUS) { if (fsmRes.state == CfdpStates::BUSY_CLASS_1_NACKED) { fsmRes.step = TransactionStep::TRANSFER_COMPLETION; diff --git a/unittests/cfdp/handler/testDestHandler.cpp b/unittests/cfdp/handler/testDestHandler.cpp index 388f766d..7a3253a2 100644 --- a/unittests/cfdp/handler/testDestHandler.cpp +++ b/unittests/cfdp/handler/testDestHandler.cpp @@ -66,7 +66,7 @@ TEST_CASE("CFDP Dest Handler", "[cfdp]") { StringLv destName(destNameString); FileSize cfdpFileSize(0); MetadataInfo info(false, cfdp::ChecksumTypes::NULL_CHECKSUM, size, srcName, destName); - auto seqNum = TransactionSeqNum(UnsignedByteField(1)); + TransactionSeqNum seqNum(UnsignedByteField(1)); PduConfig conf(remoteId, localId, TransmissionModes::UNACKNOWLEDGED, seqNum); MetadataPduCreator metadataCreator(conf, info); store_address_t storeId; @@ -82,6 +82,7 @@ TEST_CASE("CFDP Dest Handler", "[cfdp]") { REQUIRE(res.callStatus == CallStatus::CALL_AGAIN); // Assert that the packet was deleted after handling REQUIRE(not tcStore.hasDataAtId(storeId)); + REQUIRE(packetInfoList.empty()); destHandler.performStateMachine(); REQUIRE(userMock.metadataRecvd.size() == 1); MetadataRecvdParams& params = userMock.metadataRecvd.back(); @@ -90,6 +91,7 @@ TEST_CASE("CFDP Dest Handler", "[cfdp]") { REQUIRE(params.fileSize == 0); REQUIRE(strcmp(params.destFileName, "hello-cpy.txt") == 0); REQUIRE(strcmp(params.sourceFileName, "hello.txt") == 0); + userMock.metadataRecvd.pop(); REQUIRE(fsMock.fileMap.find("hello-cpy.txt") != fsMock.fileMap.end()); REQUIRE(res.result == OK); REQUIRE(res.callStatus == CallStatus::CALL_AFTER_DELAY); @@ -99,6 +101,20 @@ TEST_CASE("CFDP Dest Handler", "[cfdp]") { EofPduCreator eofCreator(conf, eofInfo); REQUIRE(tcStore.getFreeElement(&storeId, eofCreator.getSerializedSize(), &ptr) == OK); REQUIRE(eofCreator.serialize(ptr, serLen, eofCreator.getSerializedSize()) == OK); + packetInfo = PacketInfo(eofCreator.getPduType(), eofCreator.getDirectiveCode(), storeId); + packetInfoList.push_back(packetInfo); + auto transactionId = destHandler.getTransactionId(); + // After EOF, operation is done because no closure was requested + destHandler.performStateMachine(); + REQUIRE(res.result == OK); + REQUIRE(res.state == CfdpStates::IDLE); + REQUIRE(res.step == DestHandler::TransactionStep::IDLE); + // Assert that the packet was deleted after handling + REQUIRE(not tcStore.hasDataAtId(storeId)); + REQUIRE(packetInfoList.empty()); + REQUIRE(userMock.eofsRevd.size() == 1); + auto& eofId = userMock.eofsRevd.back(); + CHECK(eofId == transactionId); } SECTION("Small File Transfer") {} diff --git a/unittests/mocks/cfdp/UserMock.cpp b/unittests/mocks/cfdp/UserMock.cpp index f701a28b..04d9f4f4 100644 --- a/unittests/mocks/cfdp/UserMock.cpp +++ b/unittests/mocks/cfdp/UserMock.cpp @@ -8,7 +8,9 @@ void UserMock::transactionIndication(const TransactionId& id) {} void UserMock::eofSentIndication(const TransactionId& id) {} void UserMock::abandonedIndication(const TransactionId& id, cfdp::ConditionCode code, uint64_t progress) {} -void UserMock::eofRecvIndication(const TransactionId& id) {} + +void UserMock::eofRecvIndication(const TransactionId& id) { eofsRevd.push(id); } + void UserMock::transactionFinishedIndication(const TransactionFinishedParams& finishedParams) {} void UserMock::metadataRecvdIndication(const MetadataRecvdParams& params) { @@ -24,8 +26,8 @@ void UserMock::faultIndication(const TransactionId& id, cfdp::ConditionCode code } void UserMock::reset() { - auto empty = std::queue(); - metadataRecvd.swap(empty); + std::queue().swap(eofsRevd); + std::queue().swap(metadataRecvd); } } // namespace cfdp diff --git a/unittests/mocks/cfdp/UserMock.h b/unittests/mocks/cfdp/UserMock.h index 523392bd..7d9cfef8 100644 --- a/unittests/mocks/cfdp/UserMock.h +++ b/unittests/mocks/cfdp/UserMock.h @@ -24,6 +24,7 @@ class UserMock : public UserBase { void faultIndication(const TransactionId& id, ConditionCode code, size_t progress) override; std::queue metadataRecvd; + std::queue eofsRevd; void reset(); }; From ba046cebd9b5142283536cd66f4745673a43c636 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Tue, 6 Sep 2022 14:06:22 +0200 Subject: [PATCH 095/169] empty file unittest complete --- unittests/cfdp/handler/testDestHandler.cpp | 16 ++++++++++------ unittests/mocks/cfdp/UserMock.cpp | 10 ++++++---- unittests/mocks/cfdp/UserMock.h | 3 ++- 3 files changed, 18 insertions(+), 11 deletions(-) diff --git a/unittests/cfdp/handler/testDestHandler.cpp b/unittests/cfdp/handler/testDestHandler.cpp index 7a3253a2..5bce49d3 100644 --- a/unittests/cfdp/handler/testDestHandler.cpp +++ b/unittests/cfdp/handler/testDestHandler.cpp @@ -85,12 +85,12 @@ TEST_CASE("CFDP Dest Handler", "[cfdp]") { REQUIRE(packetInfoList.empty()); destHandler.performStateMachine(); REQUIRE(userMock.metadataRecvd.size() == 1); - MetadataRecvdParams& params = userMock.metadataRecvd.back(); - REQUIRE(params.id == destHandler.getTransactionId()); - REQUIRE(params.sourceId.getValue() == 3); - REQUIRE(params.fileSize == 0); - REQUIRE(strcmp(params.destFileName, "hello-cpy.txt") == 0); - REQUIRE(strcmp(params.sourceFileName, "hello.txt") == 0); + auto& idMetadataPair = userMock.metadataRecvd.back(); + REQUIRE(idMetadataPair.first == destHandler.getTransactionId()); + REQUIRE(idMetadataPair.second.sourceId.getValue() == 3); + REQUIRE(idMetadataPair.second.fileSize == 0); + REQUIRE(strcmp(idMetadataPair.second.destFileName, "hello-cpy.txt") == 0); + REQUIRE(strcmp(idMetadataPair.second.sourceFileName, "hello.txt") == 0); userMock.metadataRecvd.pop(); REQUIRE(fsMock.fileMap.find("hello-cpy.txt") != fsMock.fileMap.end()); REQUIRE(res.result == OK); @@ -115,6 +115,10 @@ TEST_CASE("CFDP Dest Handler", "[cfdp]") { REQUIRE(userMock.eofsRevd.size() == 1); auto& eofId = userMock.eofsRevd.back(); CHECK(eofId == transactionId); + REQUIRE(userMock.finishedRecvd.size() == 1); + auto& idParamPair = userMock.finishedRecvd.back(); + CHECK(idParamPair.first == transactionId); + CHECK(idParamPair.second.condCode == ConditionCode::NO_ERROR); } SECTION("Small File Transfer") {} diff --git a/unittests/mocks/cfdp/UserMock.cpp b/unittests/mocks/cfdp/UserMock.cpp index 04d9f4f4..ca15a5e6 100644 --- a/unittests/mocks/cfdp/UserMock.cpp +++ b/unittests/mocks/cfdp/UserMock.cpp @@ -11,11 +11,12 @@ void UserMock::abandonedIndication(const TransactionId& id, cfdp::ConditionCode void UserMock::eofRecvIndication(const TransactionId& id) { eofsRevd.push(id); } -void UserMock::transactionFinishedIndication(const TransactionFinishedParams& finishedParams) {} +void UserMock::transactionFinishedIndication(const TransactionFinishedParams& finishedParams) { + finishedRecvd.push({finishedParams.id, finishedParams}); +} void UserMock::metadataRecvdIndication(const MetadataRecvdParams& params) { - MetadataRecvdParams copy = params; - metadataRecvd.push(copy); + metadataRecvd.push({params.id, params}); } void UserMock::fileSegmentRecvdIndication(const FileSegmentRecvdParams& params) {} @@ -27,7 +28,8 @@ void UserMock::faultIndication(const TransactionId& id, cfdp::ConditionCode code void UserMock::reset() { std::queue().swap(eofsRevd); - std::queue().swap(metadataRecvd); + std::queue>().swap(metadataRecvd); + std::queue>().swap(finishedRecvd); } } // namespace cfdp diff --git a/unittests/mocks/cfdp/UserMock.h b/unittests/mocks/cfdp/UserMock.h index 7d9cfef8..e2a4a483 100644 --- a/unittests/mocks/cfdp/UserMock.h +++ b/unittests/mocks/cfdp/UserMock.h @@ -23,8 +23,9 @@ class UserMock : public UserBase { void resumedIndication(const TransactionId& id, size_t progress) override; void faultIndication(const TransactionId& id, ConditionCode code, size_t progress) override; - std::queue metadataRecvd; + std::queue> metadataRecvd; std::queue eofsRevd; + std::queue> finishedRecvd; void reset(); }; From 94c9800fae11ec78d676f9ae0e976ac917e6ad0c Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Tue, 6 Sep 2022 14:33:01 +0200 Subject: [PATCH 096/169] refactored out generic metadata part --- unittests/cfdp/handler/testDestHandler.cpp | 102 +++++++++++++-------- 1 file changed, 65 insertions(+), 37 deletions(-) diff --git a/unittests/cfdp/handler/testDestHandler.cpp b/unittests/cfdp/handler/testDestHandler.cpp index 5bce49d3..c6be9c14 100644 --- a/unittests/cfdp/handler/testDestHandler.cpp +++ b/unittests/cfdp/handler/testDestHandler.cpp @@ -1,3 +1,5 @@ +#include + #include #include "fsfw/cfdp.h" @@ -39,9 +41,50 @@ TEST_CASE("CFDP Dest Handler", "[cfdp]") { remoteCfgTableMock.addRemoteConfig(cfg); fp.tcStore = &tcStore; fp.tmStore = &tmStore; + uint8_t* buf = nullptr; + size_t serLen = 0; auto destHandler = DestHandler(dp, fp); CHECK(destHandler.initialize() == OK); + auto metadataPreparation = [&](PduConfig& conf, FileSize cfdpFileSize, store_address_t& storeId) { + std::string srcNameString = "hello.txt"; + std::string destNameString = "hello-cpy.txt"; + StringLv srcName(srcNameString); + StringLv destName(destNameString); + MetadataInfo info(false, cfdp::ChecksumTypes::NULL_CHECKSUM, cfdpFileSize, srcName, destName); + TransactionSeqNum seqNum(UnsignedByteField(1)); + conf.sourceId = remoteId; + conf.destId = localId; + conf.mode = TransmissionModes::UNACKNOWLEDGED; + conf.seqNum = seqNum; + MetadataPduCreator metadataCreator(conf, info); + REQUIRE(tcStore.getFreeElement(&storeId, metadataCreator.getSerializedSize(), &buf) == OK); + REQUIRE(metadataCreator.serialize(buf, serLen, metadataCreator.getSerializedSize()) == OK); + PacketInfo packetInfo(metadataCreator.getPduType(), metadataCreator.getDirectiveCode(), + storeId); + packetInfoList.push_back(packetInfo); + }; + + auto metadataCheck = [&](const cfdp::DestHandler::FsmResult& res, store_address_t storeId, const char* sourceName, const char* destName) { + REQUIRE(res.result == OK); + REQUIRE(res.callStatus == CallStatus::CALL_AGAIN); + // Assert that the packet was deleted after handling + REQUIRE(not tcStore.hasDataAtId(storeId)); + REQUIRE(packetInfoList.empty()); + REQUIRE(userMock.metadataRecvd.size() == 1); + auto& idMetadataPair = userMock.metadataRecvd.back(); + REQUIRE(idMetadataPair.first == destHandler.getTransactionId()); + REQUIRE(idMetadataPair.second.sourceId.getValue() == 3); + REQUIRE(idMetadataPair.second.fileSize == 0); + REQUIRE(strcmp(idMetadataPair.second.destFileName, destName) == 0); + REQUIRE(strcmp(idMetadataPair.second.sourceFileName, sourceName) == 0); + userMock.metadataRecvd.pop(); + REQUIRE(fsMock.fileMap.find(destName) != fsMock.fileMap.end()); + REQUIRE(res.result == OK); + REQUIRE(res.state == CfdpStates::BUSY_CLASS_1_NACKED); + REQUIRE(res.step == DestHandler::TransactionStep::RECEIVING_FILE_DATA_PDUS); + }; + SECTION("State") { CHECK(destHandler.getCfdpState() == CfdpStates::IDLE); CHECK(destHandler.getTransactionStep() == DestHandler::TransactionStep::IDLE); @@ -59,49 +102,19 @@ TEST_CASE("CFDP Dest Handler", "[cfdp]") { SECTION("Empty File Transfer") { const DestHandler::FsmResult& res = destHandler.performStateMachine(); CHECK(res.result == OK); - FileSize size(0); - std::string srcNameString = "hello.txt"; - std::string destNameString = "hello-cpy.txt"; - StringLv srcName(srcNameString); - StringLv destName(destNameString); FileSize cfdpFileSize(0); - MetadataInfo info(false, cfdp::ChecksumTypes::NULL_CHECKSUM, size, srcName, destName); - TransactionSeqNum seqNum(UnsignedByteField(1)); - PduConfig conf(remoteId, localId, TransmissionModes::UNACKNOWLEDGED, seqNum); - MetadataPduCreator metadataCreator(conf, info); store_address_t storeId; - uint8_t* ptr; - REQUIRE(tcStore.getFreeElement(&storeId, metadataCreator.getSerializedSize(), &ptr) == OK); - size_t serLen = 0; - REQUIRE(metadataCreator.serialize(ptr, serLen, metadataCreator.getSerializedSize()) == OK); - PacketInfo packetInfo(metadataCreator.getPduType(), metadataCreator.getDirectiveCode(), - storeId); - packetInfoList.push_back(packetInfo); + PduConfig conf; + metadataPreparation(conf, cfdpFileSize, storeId); destHandler.performStateMachine(); - REQUIRE(res.result == OK); - REQUIRE(res.callStatus == CallStatus::CALL_AGAIN); - // Assert that the packet was deleted after handling - REQUIRE(not tcStore.hasDataAtId(storeId)); - REQUIRE(packetInfoList.empty()); + metadataCheck(res, storeId, "hello.txt", "hello-cpy.txt"); destHandler.performStateMachine(); - REQUIRE(userMock.metadataRecvd.size() == 1); - auto& idMetadataPair = userMock.metadataRecvd.back(); - REQUIRE(idMetadataPair.first == destHandler.getTransactionId()); - REQUIRE(idMetadataPair.second.sourceId.getValue() == 3); - REQUIRE(idMetadataPair.second.fileSize == 0); - REQUIRE(strcmp(idMetadataPair.second.destFileName, "hello-cpy.txt") == 0); - REQUIRE(strcmp(idMetadataPair.second.sourceFileName, "hello.txt") == 0); - userMock.metadataRecvd.pop(); - REQUIRE(fsMock.fileMap.find("hello-cpy.txt") != fsMock.fileMap.end()); - REQUIRE(res.result == OK); REQUIRE(res.callStatus == CallStatus::CALL_AFTER_DELAY); - REQUIRE(res.state == CfdpStates::BUSY_CLASS_1_NACKED); - REQUIRE(res.step == DestHandler::TransactionStep::RECEIVING_FILE_DATA_PDUS); EofInfo eofInfo(cfdp::ConditionCode::NO_ERROR, 0, cfdpFileSize); EofPduCreator eofCreator(conf, eofInfo); - REQUIRE(tcStore.getFreeElement(&storeId, eofCreator.getSerializedSize(), &ptr) == OK); - REQUIRE(eofCreator.serialize(ptr, serLen, eofCreator.getSerializedSize()) == OK); - packetInfo = PacketInfo(eofCreator.getPduType(), eofCreator.getDirectiveCode(), storeId); + REQUIRE(tcStore.getFreeElement(&storeId, eofCreator.getSerializedSize(), &buf) == OK); + REQUIRE(eofCreator.serialize(buf, serLen, eofCreator.getSerializedSize()) == OK); + PacketInfo packetInfo(eofCreator.getPduType(), eofCreator.getDirectiveCode(), storeId); packetInfoList.push_back(packetInfo); auto transactionId = destHandler.getTransactionId(); // After EOF, operation is done because no closure was requested @@ -121,7 +134,22 @@ TEST_CASE("CFDP Dest Handler", "[cfdp]") { CHECK(idParamPair.second.condCode == ConditionCode::NO_ERROR); } - SECTION("Small File Transfer") {} + SECTION("Small File Transfer") { + const DestHandler::FsmResult& res = destHandler.performStateMachine(); + CHECK(res.result == OK); + std::string fileData = "hello test data"; + etl::crc32 crcCalc; + crcCalc.add(fileData.begin(), fileData.end()); + uint32_t crc32 = crcCalc.value(); + FileSize cfdpFileSize(0); + store_address_t storeId; + PduConfig conf; + metadataPreparation(conf, cfdpFileSize, storeId); + destHandler.performStateMachine(); + metadataCheck(res, storeId, "hello.txt", "hello-cpy.txt"); + destHandler.performStateMachine(); + REQUIRE(res.callStatus == CallStatus::CALL_AFTER_DELAY); + } SECTION("Segmented File Transfer") {} } \ No newline at end of file From af851165b475fb34dd022a3ee6c54e18cb68e2b9 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Tue, 6 Sep 2022 15:45:51 +0200 Subject: [PATCH 097/169] continue basic small file transfer unittest --- src/fsfw/cfdp/handler/DestHandler.cpp | 6 +- src/fsfw/cfdp/handler/DestHandler.h | 8 +- src/fsfw/cfdp/pdu/FileDataCreator.cpp | 10 ++- src/fsfw/cfdp/pdu/FileDataCreator.h | 4 + unittests/cfdp/handler/testDestHandler.cpp | 91 ++++++++++++++-------- 5 files changed, 76 insertions(+), 43 deletions(-) diff --git a/src/fsfw/cfdp/handler/DestHandler.cpp b/src/fsfw/cfdp/handler/DestHandler.cpp index e1578c9b..ac773cfc 100644 --- a/src/fsfw/cfdp/handler/DestHandler.cpp +++ b/src/fsfw/cfdp/handler/DestHandler.cpp @@ -174,7 +174,7 @@ ReturnValue_t cfdp::DestHandler::handleFileDataPdu(const cfdp::PacketInfo& info) } size_t fileSegmentLen = 0; const uint8_t* fileData = fdInfo.getFileData(&fileSegmentLen); - FileOpParams fileOpParams(tp.sourceName.data(), fileSegmentLen); + FileOpParams fileOpParams(tp.destName.data(), fileSegmentLen); if (dp.cfg.indicCfg.fileSegmentRecvIndicRequired) { FileSegmentRecvdParams segParams; segParams.offset = offset.value(); @@ -372,9 +372,9 @@ ReturnValue_t cfdp::DestHandler::checksumVerification() { // TODO: Checksum verification and notice of completion etl::crc32 crcCalc; uint64_t currentOffset = 0; - FileOpParams params(tp.sourceName.data(), buf.size()); + FileOpParams params(tp.destName.data(), tp.fileSize.value()); while (currentOffset < tp.fileSize.value()) { - uint64_t readLen = 0; + uint64_t readLen; if (currentOffset + buf.size() > tp.fileSize.value()) { readLen = tp.fileSize.value() - currentOffset; } else { diff --git a/src/fsfw/cfdp/handler/DestHandler.h b/src/fsfw/cfdp/handler/DestHandler.h index b1c56721..71214fcb 100644 --- a/src/fsfw/cfdp/handler/DestHandler.h +++ b/src/fsfw/cfdp/handler/DestHandler.h @@ -4,6 +4,7 @@ #include #include +#include #include #include "RemoteConfigTableIF.h" @@ -20,11 +21,12 @@ namespace cfdp { struct PacketInfo { - PacketInfo(PduType type, FileDirectives directive, store_address_t storeId) + PacketInfo(PduType type, store_address_t storeId, + std::optional directive = std::nullopt) : pduType(type), directiveType(directive), storeId(storeId) {} PduType pduType = PduType::FILE_DATA; - FileDirectives directiveType = FileDirectives::INVALID_DIRECTIVE; + std::optional directiveType = FileDirectives::INVALID_DIRECTIVE; store_address_t storeId = store_address_t::invalid(); PacketInfo() = default; }; @@ -121,7 +123,7 @@ class DestHandler { [[nodiscard]] CfdpStates getCfdpState() const; [[nodiscard]] TransactionStep getTransactionStep() const; - const TransactionId& getTransactionId() const; + [[nodiscard]] const TransactionId& getTransactionId() const; private: struct TransactionParams { diff --git a/src/fsfw/cfdp/pdu/FileDataCreator.cpp b/src/fsfw/cfdp/pdu/FileDataCreator.cpp index 0ef8f862..956752fb 100644 --- a/src/fsfw/cfdp/pdu/FileDataCreator.cpp +++ b/src/fsfw/cfdp/pdu/FileDataCreator.cpp @@ -15,13 +15,17 @@ void FileDataCreator::update() { ReturnValue_t FileDataCreator::serialize(uint8_t** buffer, size_t* size, size_t maxSize, Endianness streamEndianness) const { + if (buffer == nullptr or size == nullptr) { + return returnvalue::FAILED; + } + if (*size + getSerializedSize() > maxSize) { + return SerializeIF::BUFFER_TOO_SHORT; + } ReturnValue_t result = HeaderCreator::serialize(buffer, size, maxSize, streamEndianness); if (result != returnvalue::OK) { return result; } - if (*size + this->getSerializedSize() > maxSize) { - return SerializeIF::BUFFER_TOO_SHORT; - } + const uint8_t* readOnlyPtr = nullptr; if (this->hasSegmentMetadataFlag()) { size_t segmentMetadataLen = info.getSegmentMetadataLen(); diff --git a/src/fsfw/cfdp/pdu/FileDataCreator.h b/src/fsfw/cfdp/pdu/FileDataCreator.h index 774baf00..2ce8989d 100644 --- a/src/fsfw/cfdp/pdu/FileDataCreator.h +++ b/src/fsfw/cfdp/pdu/FileDataCreator.h @@ -11,6 +11,10 @@ class FileDataCreator : public HeaderCreator { void update(); + ReturnValue_t serialize(uint8_t* buf, size_t& serLen, size_t maxSize) const { + return SerializeIF::serialize(buf, serLen, maxSize, SerializeIF::Endianness::NETWORK); + } + ReturnValue_t serialize(uint8_t** buffer, size_t* size, size_t maxSize, Endianness streamEndianness) const override; diff --git a/unittests/cfdp/handler/testDestHandler.cpp b/unittests/cfdp/handler/testDestHandler.cpp index c6be9c14..23d88352 100644 --- a/unittests/cfdp/handler/testDestHandler.cpp +++ b/unittests/cfdp/handler/testDestHandler.cpp @@ -1,9 +1,11 @@ #include #include +#include #include "fsfw/cfdp.h" #include "fsfw/cfdp/pdu/EofPduCreator.h" +#include "fsfw/cfdp/pdu/FileDataCreator.h" #include "fsfw/cfdp/pdu/MetadataPduCreator.h" #include "mocks/AcceptsTmMock.h" #include "mocks/EventReportingProxyMock.h" @@ -43,15 +45,17 @@ TEST_CASE("CFDP Dest Handler", "[cfdp]") { fp.tmStore = &tmStore; uint8_t* buf = nullptr; size_t serLen = 0; + store_address_t storeId; + PduConfig conf; auto destHandler = DestHandler(dp, fp); CHECK(destHandler.initialize() == OK); - auto metadataPreparation = [&](PduConfig& conf, FileSize cfdpFileSize, store_address_t& storeId) { + auto metadataPreparation = [&](FileSize cfdpFileSize, ChecksumTypes checksumType) { std::string srcNameString = "hello.txt"; std::string destNameString = "hello-cpy.txt"; StringLv srcName(srcNameString); StringLv destName(destNameString); - MetadataInfo info(false, cfdp::ChecksumTypes::NULL_CHECKSUM, cfdpFileSize, srcName, destName); + MetadataInfo info(false, checksumType, cfdpFileSize, srcName, destName); TransactionSeqNum seqNum(UnsignedByteField(1)); conf.sourceId = remoteId; conf.destId = localId; @@ -60,12 +64,13 @@ TEST_CASE("CFDP Dest Handler", "[cfdp]") { MetadataPduCreator metadataCreator(conf, info); REQUIRE(tcStore.getFreeElement(&storeId, metadataCreator.getSerializedSize(), &buf) == OK); REQUIRE(metadataCreator.serialize(buf, serLen, metadataCreator.getSerializedSize()) == OK); - PacketInfo packetInfo(metadataCreator.getPduType(), metadataCreator.getDirectiveCode(), - storeId); + PacketInfo packetInfo(metadataCreator.getPduType(), storeId, + metadataCreator.getDirectiveCode()); packetInfoList.push_back(packetInfo); }; - auto metadataCheck = [&](const cfdp::DestHandler::FsmResult& res, store_address_t storeId, const char* sourceName, const char* destName) { + auto metadataCheck = [&](const cfdp::DestHandler::FsmResult& res, const char* sourceName, + const char* destName, size_t fileLen) { REQUIRE(res.result == OK); REQUIRE(res.callStatus == CallStatus::CALL_AGAIN); // Assert that the packet was deleted after handling @@ -75,7 +80,7 @@ TEST_CASE("CFDP Dest Handler", "[cfdp]") { auto& idMetadataPair = userMock.metadataRecvd.back(); REQUIRE(idMetadataPair.first == destHandler.getTransactionId()); REQUIRE(idMetadataPair.second.sourceId.getValue() == 3); - REQUIRE(idMetadataPair.second.fileSize == 0); + REQUIRE(idMetadataPair.second.fileSize == fileLen); REQUIRE(strcmp(idMetadataPair.second.destFileName, destName) == 0); REQUIRE(strcmp(idMetadataPair.second.sourceFileName, sourceName) == 0); userMock.metadataRecvd.pop(); @@ -85,6 +90,31 @@ TEST_CASE("CFDP Dest Handler", "[cfdp]") { REQUIRE(res.step == DestHandler::TransactionStep::RECEIVING_FILE_DATA_PDUS); }; + auto eofPreparation = [&](FileSize cfdpFileSize, uint32_t crc) { + EofInfo eofInfo(cfdp::ConditionCode::NO_ERROR, crc, std::move(cfdpFileSize)); + EofPduCreator eofCreator(conf, eofInfo); + REQUIRE(tcStore.getFreeElement(&storeId, eofCreator.getSerializedSize(), &buf) == OK); + REQUIRE(eofCreator.serialize(buf, serLen, eofCreator.getSerializedSize()) == OK); + PacketInfo packetInfo(eofCreator.getPduType(), storeId, eofCreator.getDirectiveCode()); + packetInfoList.push_back(packetInfo); + }; + + auto eofCheck = [&](const cfdp::DestHandler::FsmResult& res, const TransactionId& id) { + REQUIRE(res.result == OK); + REQUIRE(res.state == CfdpStates::IDLE); + REQUIRE(res.step == DestHandler::TransactionStep::IDLE); + // Assert that the packet was deleted after handling + REQUIRE(not tcStore.hasDataAtId(storeId)); + REQUIRE(packetInfoList.empty()); + REQUIRE(userMock.eofsRevd.size() == 1); + auto& eofId = userMock.eofsRevd.back(); + CHECK(eofId == id); + REQUIRE(userMock.finishedRecvd.size() == 1); + auto& idParamPair = userMock.finishedRecvd.back(); + CHECK(idParamPair.first == id); + CHECK(idParamPair.second.condCode == ConditionCode::NO_ERROR); + }; + SECTION("State") { CHECK(destHandler.getCfdpState() == CfdpStates::IDLE); CHECK(destHandler.getTransactionStep() == DestHandler::TransactionStep::IDLE); @@ -103,35 +133,16 @@ TEST_CASE("CFDP Dest Handler", "[cfdp]") { const DestHandler::FsmResult& res = destHandler.performStateMachine(); CHECK(res.result == OK); FileSize cfdpFileSize(0); - store_address_t storeId; - PduConfig conf; - metadataPreparation(conf, cfdpFileSize, storeId); + metadataPreparation(cfdpFileSize, ChecksumTypes::NULL_CHECKSUM); destHandler.performStateMachine(); - metadataCheck(res, storeId, "hello.txt", "hello-cpy.txt"); + metadataCheck(res, "hello.txt", "hello-cpy.txt", 0); destHandler.performStateMachine(); REQUIRE(res.callStatus == CallStatus::CALL_AFTER_DELAY); - EofInfo eofInfo(cfdp::ConditionCode::NO_ERROR, 0, cfdpFileSize); - EofPduCreator eofCreator(conf, eofInfo); - REQUIRE(tcStore.getFreeElement(&storeId, eofCreator.getSerializedSize(), &buf) == OK); - REQUIRE(eofCreator.serialize(buf, serLen, eofCreator.getSerializedSize()) == OK); - PacketInfo packetInfo(eofCreator.getPduType(), eofCreator.getDirectiveCode(), storeId); - packetInfoList.push_back(packetInfo); auto transactionId = destHandler.getTransactionId(); + eofPreparation(cfdpFileSize, 0); // After EOF, operation is done because no closure was requested destHandler.performStateMachine(); - REQUIRE(res.result == OK); - REQUIRE(res.state == CfdpStates::IDLE); - REQUIRE(res.step == DestHandler::TransactionStep::IDLE); - // Assert that the packet was deleted after handling - REQUIRE(not tcStore.hasDataAtId(storeId)); - REQUIRE(packetInfoList.empty()); - REQUIRE(userMock.eofsRevd.size() == 1); - auto& eofId = userMock.eofsRevd.back(); - CHECK(eofId == transactionId); - REQUIRE(userMock.finishedRecvd.size() == 1); - auto& idParamPair = userMock.finishedRecvd.back(); - CHECK(idParamPair.first == transactionId); - CHECK(idParamPair.second.condCode == ConditionCode::NO_ERROR); + eofCheck(res, transactionId); } SECTION("Small File Transfer") { @@ -141,14 +152,26 @@ TEST_CASE("CFDP Dest Handler", "[cfdp]") { etl::crc32 crcCalc; crcCalc.add(fileData.begin(), fileData.end()); uint32_t crc32 = crcCalc.value(); - FileSize cfdpFileSize(0); - store_address_t storeId; - PduConfig conf; - metadataPreparation(conf, cfdpFileSize, storeId); + FileSize cfdpFileSize(fileData.size()); + metadataPreparation(cfdpFileSize, ChecksumTypes::CRC_32); destHandler.performStateMachine(); - metadataCheck(res, storeId, "hello.txt", "hello-cpy.txt"); + metadataCheck(res, "hello.txt", "hello-cpy.txt", fileData.size()); destHandler.performStateMachine(); REQUIRE(res.callStatus == CallStatus::CALL_AFTER_DELAY); + auto transactionId = destHandler.getTransactionId(); + FileSize offset(0); + FileDataInfo fdPduInfo(offset, reinterpret_cast(fileData.data()), + fileData.size()); + FileDataCreator fdPduCreator(conf, fdPduInfo); + REQUIRE(tcStore.getFreeElement(&storeId, fdPduCreator.getSerializedSize(), &buf) == OK); + REQUIRE(fdPduCreator.serialize(buf, serLen, fdPduCreator.getSerializedSize()) == OK); + PacketInfo packetInfo(fdPduCreator.getPduType(), storeId, std::nullopt); + packetInfoList.push_back(packetInfo); + destHandler.performStateMachine(); + eofPreparation(cfdpFileSize, crc32); + // After EOF, operation is done because no closure was requested + destHandler.performStateMachine(); + eofCheck(res, transactionId); } SECTION("Segmented File Transfer") {} From 67439b428587c573dfe45b35ad1c7c9d8e04ed2b Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Tue, 6 Sep 2022 16:03:26 +0200 Subject: [PATCH 098/169] refactor away some duplication --- src/fsfw/cfdp/handler/DestHandler.cpp | 32 ++++++++-------------- src/fsfw/cfdp/handler/DestHandler.h | 1 + unittests/cfdp/handler/testDestHandler.cpp | 5 ++++ 3 files changed, 18 insertions(+), 20 deletions(-) diff --git a/src/fsfw/cfdp/handler/DestHandler.cpp b/src/fsfw/cfdp/handler/DestHandler.cpp index ac773cfc..4bc7134c 100644 --- a/src/fsfw/cfdp/handler/DestHandler.cpp +++ b/src/fsfw/cfdp/handler/DestHandler.cpp @@ -32,10 +32,7 @@ const cfdp::DestHandler::FsmResult& cfdp::DestHandler::performStateMachine() { if (infoIter->pduType == PduType::FILE_DIRECTIVE and infoIter->directiveType == FileDirectives::METADATA) { result = handleMetadataPdu(*infoIter); - if (result != OK and errorIdx < 3) { - fsmRes.errorCodes[errorIdx] = result; - errorIdx++; - } + checkAndHandleError(result, errorIdx); // Store data was deleted in PDU handler because a store guard is used dp.packetListRef.erase(infoIter++); } @@ -61,10 +58,7 @@ const cfdp::DestHandler::FsmResult& cfdp::DestHandler::performStateMachine() { for (auto infoIter = dp.packetListRef.begin(); infoIter != dp.packetListRef.end();) { if (infoIter->pduType == PduType::FILE_DATA) { result = handleFileDataPdu(*infoIter); - if (result != OK and errorIdx < 3) { - fsmRes.errorCodes[errorIdx] = result; - errorIdx++; - } + checkAndHandleError(result, errorIdx); // Store data was deleted in PDU handler because a store guard is used dp.packetListRef.erase(infoIter++); } @@ -72,10 +66,7 @@ const cfdp::DestHandler::FsmResult& cfdp::DestHandler::performStateMachine() { if (infoIter->pduType == PduType::FILE_DIRECTIVE and infoIter->directiveType == FileDirectives::EOF_DIRECTIVE) { result = handleEofPdu(*infoIter); - if (result != OK and errorIdx < 3) { - fsmRes.errorCodes[errorIdx] = result; - errorIdx++; - } + checkAndHandleError(result, errorIdx); // Store data was deleted in PDU handler because a store guard is used dp.packetListRef.erase(infoIter++); } @@ -84,17 +75,11 @@ const cfdp::DestHandler::FsmResult& cfdp::DestHandler::performStateMachine() { } if (fsmRes.step == TransactionStep::TRANSFER_COMPLETION) { result = handleTransferCompletion(); - if (result != OK and errorIdx < 3) { - fsmRes.errorCodes[errorIdx] = result; - errorIdx++; - } + checkAndHandleError(result, errorIdx); } if (fsmRes.step == TransactionStep::SENDING_FINISHED_PDU) { result = sendFinishedPdu(); - if (result != OK and errorIdx < 3) { - fsmRes.errorCodes[errorIdx] = result; - errorIdx++; - } + checkAndHandleError(result, errorIdx); finish(); } return updateFsmRes(errorIdx); @@ -457,3 +442,10 @@ const cfdp::DestHandler::FsmResult& cfdp::DestHandler::updateFsmRes(uint8_t erro } const cfdp::TransactionId& cfdp::DestHandler::getTransactionId() const { return tp.transactionId; } + +void cfdp::DestHandler::checkAndHandleError(ReturnValue_t result, uint8_t& errorIdx) { + if (result != OK and errorIdx < 3) { + fsmRes.errorCodes[errorIdx] = result; + errorIdx++; + } +} diff --git a/src/fsfw/cfdp/handler/DestHandler.h b/src/fsfw/cfdp/handler/DestHandler.h index 71214fcb..8d2fc6e9 100644 --- a/src/fsfw/cfdp/handler/DestHandler.h +++ b/src/fsfw/cfdp/handler/DestHandler.h @@ -180,6 +180,7 @@ class DestHandler { ReturnValue_t noticeOfCompletion(); ReturnValue_t checksumVerification(); const FsmResult& updateFsmRes(uint8_t errors); + void checkAndHandleError(ReturnValue_t result, uint8_t& errorIdx); void finish(); }; diff --git a/unittests/cfdp/handler/testDestHandler.cpp b/unittests/cfdp/handler/testDestHandler.cpp index 23d88352..85cbf23e 100644 --- a/unittests/cfdp/handler/testDestHandler.cpp +++ b/unittests/cfdp/handler/testDestHandler.cpp @@ -168,6 +168,11 @@ TEST_CASE("CFDP Dest Handler", "[cfdp]") { PacketInfo packetInfo(fdPduCreator.getPduType(), storeId, std::nullopt); packetInfoList.push_back(packetInfo); destHandler.performStateMachine(); + REQUIRE(res.result == OK); + REQUIRE(res.state == CfdpStates::BUSY_CLASS_1_NACKED); + REQUIRE(res.step == DestHandler::TransactionStep::RECEIVING_FILE_DATA_PDUS); + REQUIRE(not tcStore.hasDataAtId(storeId)); + REQUIRE(packetInfoList.empty()); eofPreparation(cfdpFileSize, crc32); // After EOF, operation is done because no closure was requested destHandler.performStateMachine(); From aebd401d5b9de69c57dbff14ac9b3412f7f09219 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Tue, 6 Sep 2022 16:14:39 +0200 Subject: [PATCH 099/169] start segmentes file unittest --- unittests/cfdp/handler/testDestHandler.cpp | 39 ++++++++++++++++++---- 1 file changed, 33 insertions(+), 6 deletions(-) diff --git a/unittests/cfdp/handler/testDestHandler.cpp b/unittests/cfdp/handler/testDestHandler.cpp index 85cbf23e..cdf8e104 100644 --- a/unittests/cfdp/handler/testDestHandler.cpp +++ b/unittests/cfdp/handler/testDestHandler.cpp @@ -2,6 +2,7 @@ #include #include +#include #include "fsfw/cfdp.h" #include "fsfw/cfdp/pdu/EofPduCreator.h" @@ -73,6 +74,7 @@ TEST_CASE("CFDP Dest Handler", "[cfdp]") { const char* destName, size_t fileLen) { REQUIRE(res.result == OK); REQUIRE(res.callStatus == CallStatus::CALL_AGAIN); + REQUIRE(res.errors == 0); // Assert that the packet was deleted after handling REQUIRE(not tcStore.hasDataAtId(storeId)); REQUIRE(packetInfoList.empty()); @@ -102,6 +104,7 @@ TEST_CASE("CFDP Dest Handler", "[cfdp]") { auto eofCheck = [&](const cfdp::DestHandler::FsmResult& res, const TransactionId& id) { REQUIRE(res.result == OK); REQUIRE(res.state == CfdpStates::IDLE); + REQUIRE(res.errors == 0); REQUIRE(res.step == DestHandler::TransactionStep::IDLE); // Assert that the packet was deleted after handling REQUIRE(not tcStore.hasDataAtId(storeId)); @@ -115,6 +118,14 @@ TEST_CASE("CFDP Dest Handler", "[cfdp]") { CHECK(idParamPair.second.condCode == ConditionCode::NO_ERROR); }; + auto fileDataPduCheck = [&](const cfdp::DestHandler::FsmResult& res) { + REQUIRE(res.result == OK); + REQUIRE(res.state == CfdpStates::BUSY_CLASS_1_NACKED); + REQUIRE(res.step == DestHandler::TransactionStep::RECEIVING_FILE_DATA_PDUS); + REQUIRE(not tcStore.hasDataAtId(storeId)); + REQUIRE(packetInfoList.empty()); + }; + SECTION("State") { CHECK(destHandler.getCfdpState() == CfdpStates::IDLE); CHECK(destHandler.getTransactionStep() == DestHandler::TransactionStep::IDLE); @@ -168,16 +179,32 @@ TEST_CASE("CFDP Dest Handler", "[cfdp]") { PacketInfo packetInfo(fdPduCreator.getPduType(), storeId, std::nullopt); packetInfoList.push_back(packetInfo); destHandler.performStateMachine(); - REQUIRE(res.result == OK); - REQUIRE(res.state == CfdpStates::BUSY_CLASS_1_NACKED); - REQUIRE(res.step == DestHandler::TransactionStep::RECEIVING_FILE_DATA_PDUS); - REQUIRE(not tcStore.hasDataAtId(storeId)); - REQUIRE(packetInfoList.empty()); + fileDataPduCheck(res); eofPreparation(cfdpFileSize, crc32); // After EOF, operation is done because no closure was requested destHandler.performStateMachine(); eofCheck(res, transactionId); } - SECTION("Segmented File Transfer") {} + SECTION("Segmented File Transfer") { + const DestHandler::FsmResult& res = destHandler.performStateMachine(); + CHECK(res.result == OK); + std::random_device dev; + std::mt19937 rng(dev()); + std::uniform_int_distribution distU8(0, 255); + std::array largerFileData{}; + for(auto& val: largerFileData) { + val = distU8(rng); + } + etl::crc32 crcCalc; + crcCalc.add(largerFileData.begin(), largerFileData.end()); + uint32_t crc32 = crcCalc.value(); + FileSize cfdpFileSize(largerFileData.size()); + metadataPreparation(cfdpFileSize, ChecksumTypes::CRC_32); + destHandler.performStateMachine(); + metadataCheck(res, "hello.txt", "hello-cpy.txt", largerFileData.size()); + destHandler.performStateMachine(); + REQUIRE(res.callStatus == CallStatus::CALL_AFTER_DELAY); + auto transactionId = destHandler.getTransactionId(); + } } \ No newline at end of file From c54caf134a860c376187e7730341d399f4ae89df Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Tue, 6 Sep 2022 16:33:38 +0200 Subject: [PATCH 100/169] segmented file transfer working --- src/fsfw/cfdp/handler/DestHandler.cpp | 14 ++++--- unittests/cfdp/handler/testDestHandler.cpp | 45 +++++++++++++++++++--- 2 files changed, 48 insertions(+), 11 deletions(-) diff --git a/src/fsfw/cfdp/handler/DestHandler.cpp b/src/fsfw/cfdp/handler/DestHandler.cpp index 4bc7134c..cd3cc3b4 100644 --- a/src/fsfw/cfdp/handler/DestHandler.cpp +++ b/src/fsfw/cfdp/handler/DestHandler.cpp @@ -35,8 +35,9 @@ const cfdp::DestHandler::FsmResult& cfdp::DestHandler::performStateMachine() { checkAndHandleError(result, errorIdx); // Store data was deleted in PDU handler because a store guard is used dp.packetListRef.erase(infoIter++); + } else { + infoIter++; } - infoIter++; } if (fsmRes.step == TransactionStep::IDLE) { // To decrease the already high complexity of the software, all packets arriving before @@ -61,16 +62,16 @@ const cfdp::DestHandler::FsmResult& cfdp::DestHandler::performStateMachine() { checkAndHandleError(result, errorIdx); // Store data was deleted in PDU handler because a store guard is used dp.packetListRef.erase(infoIter++); - } - // TODO: Support for check timer missing - if (infoIter->pduType == PduType::FILE_DIRECTIVE and - infoIter->directiveType == FileDirectives::EOF_DIRECTIVE) { + } else if (infoIter->pduType == PduType::FILE_DIRECTIVE and + infoIter->directiveType == FileDirectives::EOF_DIRECTIVE) { + // TODO: Support for check timer missing result = handleEofPdu(*infoIter); checkAndHandleError(result, errorIdx); // Store data was deleted in PDU handler because a store guard is used dp.packetListRef.erase(infoIter++); + } else { + infoIter++; } - infoIter++; } } if (fsmRes.step == TransactionStep::TRANSFER_COMPLETION) { @@ -160,6 +161,7 @@ ReturnValue_t cfdp::DestHandler::handleFileDataPdu(const cfdp::PacketInfo& info) size_t fileSegmentLen = 0; const uint8_t* fileData = fdInfo.getFileData(&fileSegmentLen); FileOpParams fileOpParams(tp.destName.data(), fileSegmentLen); + fileOpParams.offset = offset.value(); if (dp.cfg.indicCfg.fileSegmentRecvIndicRequired) { FileSegmentRecvdParams segParams; segParams.offset = offset.value(); diff --git a/unittests/cfdp/handler/testDestHandler.cpp b/unittests/cfdp/handler/testDestHandler.cpp index cdf8e104..404d8eed 100644 --- a/unittests/cfdp/handler/testDestHandler.cpp +++ b/unittests/cfdp/handler/testDestHandler.cpp @@ -1,8 +1,8 @@ #include #include -#include #include +#include #include "fsfw/cfdp.h" #include "fsfw/cfdp/pdu/EofPduCreator.h" @@ -118,11 +118,14 @@ TEST_CASE("CFDP Dest Handler", "[cfdp]") { CHECK(idParamPair.second.condCode == ConditionCode::NO_ERROR); }; - auto fileDataPduCheck = [&](const cfdp::DestHandler::FsmResult& res) { + auto fileDataPduCheck = [&](const cfdp::DestHandler::FsmResult& res, + const std::vector& idsToCheck) { REQUIRE(res.result == OK); REQUIRE(res.state == CfdpStates::BUSY_CLASS_1_NACKED); REQUIRE(res.step == DestHandler::TransactionStep::RECEIVING_FILE_DATA_PDUS); - REQUIRE(not tcStore.hasDataAtId(storeId)); + for (const auto id : idsToCheck) { + REQUIRE(not tcStore.hasDataAtId(id)); + } REQUIRE(packetInfoList.empty()); }; @@ -179,7 +182,7 @@ TEST_CASE("CFDP Dest Handler", "[cfdp]") { PacketInfo packetInfo(fdPduCreator.getPduType(), storeId, std::nullopt); packetInfoList.push_back(packetInfo); destHandler.performStateMachine(); - fileDataPduCheck(res); + fileDataPduCheck(res, {storeId}); eofPreparation(cfdpFileSize, crc32); // After EOF, operation is done because no closure was requested destHandler.performStateMachine(); @@ -193,7 +196,7 @@ TEST_CASE("CFDP Dest Handler", "[cfdp]") { std::mt19937 rng(dev()); std::uniform_int_distribution distU8(0, 255); std::array largerFileData{}; - for(auto& val: largerFileData) { + for (auto& val : largerFileData) { val = distU8(rng); } etl::crc32 crcCalc; @@ -206,5 +209,37 @@ TEST_CASE("CFDP Dest Handler", "[cfdp]") { destHandler.performStateMachine(); REQUIRE(res.callStatus == CallStatus::CALL_AFTER_DELAY); auto transactionId = destHandler.getTransactionId(); + + std::vector idsToCheck; + { + FileSize offset(0); + FileDataInfo fdPduInfo(offset, reinterpret_cast(largerFileData.data()), + largerFileData.size() / 2); + FileDataCreator fdPduCreator(conf, fdPduInfo); + REQUIRE(tcStore.getFreeElement(&storeId, fdPduCreator.getSerializedSize(), &buf) == OK); + REQUIRE(fdPduCreator.serialize(buf, serLen, fdPduCreator.getSerializedSize()) == OK); + PacketInfo packetInfo(fdPduCreator.getPduType(), storeId, std::nullopt); + idsToCheck.push_back(storeId); + packetInfoList.push_back(packetInfo); + } + + { + FileSize offset(512); + FileDataInfo fdPduInfo(offset, reinterpret_cast(largerFileData.data() + 512), + largerFileData.size() / 2); + FileDataCreator fdPduCreator(conf, fdPduInfo); + REQUIRE(tcStore.getFreeElement(&storeId, fdPduCreator.getSerializedSize(), &buf) == OK); + REQUIRE(fdPduCreator.serialize(buf, serLen, fdPduCreator.getSerializedSize()) == OK); + PacketInfo packetInfo(fdPduCreator.getPduType(), storeId, std::nullopt); + idsToCheck.push_back(storeId); + packetInfoList.push_back(packetInfo); + } + + destHandler.performStateMachine(); + fileDataPduCheck(res, idsToCheck); + eofPreparation(cfdpFileSize, crc32); + // After EOF, operation is done because no closure was requested + destHandler.performStateMachine(); + eofCheck(res, transactionId); } } \ No newline at end of file From 8971eb386ed8985fcfb5eb6aa1dc157b20c2d897 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Wed, 7 Sep 2022 17:40:22 +0200 Subject: [PATCH 101/169] retval replacement --- src/fsfw_tests/integration/devices/TestDeviceHandler.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/fsfw_tests/integration/devices/TestDeviceHandler.cpp b/src/fsfw_tests/integration/devices/TestDeviceHandler.cpp index 01f0494b..fdf02a70 100644 --- a/src/fsfw_tests/integration/devices/TestDeviceHandler.cpp +++ b/src/fsfw_tests/integration/devices/TestDeviceHandler.cpp @@ -646,7 +646,7 @@ ReturnValue_t TestDevice::initializeLocalDataPool(localpool::DataPool& localData /* Subscribe for periodic HK packets but do not enable reporting for now. Non-diangostic with a period of one second */ poolManager.subscribeForRegularPeriodicPacket({sid, false, 1.0}); - return HasReturnvaluesIF::RETURN_OK; + return returnvalue::OK; } ReturnValue_t TestDevice::getParameter(uint8_t domainId, uint8_t uniqueId, From 770463e61857dbd323818d40abde662e91c28aca Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Wed, 7 Sep 2022 18:04:46 +0200 Subject: [PATCH 102/169] remove old code --- src/fsfw/cfdp/CfdpHandler.cpp | 54 ------------------------------ src/fsfw/cfdp/CfdpHandler.h | 63 ----------------------------------- 2 files changed, 117 deletions(-) delete mode 100644 src/fsfw/cfdp/CfdpHandler.cpp delete mode 100644 src/fsfw/cfdp/CfdpHandler.h diff --git a/src/fsfw/cfdp/CfdpHandler.cpp b/src/fsfw/cfdp/CfdpHandler.cpp deleted file mode 100644 index 1bf03e10..00000000 --- a/src/fsfw/cfdp/CfdpHandler.cpp +++ /dev/null @@ -1,54 +0,0 @@ -//#include "fsfw/cfdp/CfdpHandler.h" -// -//#include "fsfw/cfdp/CfdpMessage.h" -//#include "fsfw/ipc/CommandMessage.h" -//#include "fsfw/ipc/QueueFactory.h" -//#include "fsfw/objectmanager/ObjectManager.h" -//#include "fsfw/storagemanager/storeAddress.h" -//#include "fsfw/tmtcservices/AcceptsTelemetryIF.h" -// -// CfdpHandler::CfdpHandler(object_id_t setObjectId, CfdpHandler* dist) -// : SystemObject(setObjectId) { -// requestQueue = QueueFactory::instance()->createMessageQueue(CFDP_HANDLER_MAX_RECEPTION); -// distributor = dist; -//} -// -// CfdpHandler::~CfdpHandler() = default; -// -// 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(store_address_t storeId) { -//#if FSFW_VERBOSE_LEVEL >= 1 -//#if FSFW_CPP_OSTREAM_ENABLED == 1 -// sif::debug << "CFDPHandler::handleRequest" << std::endl; -//#else -// sif::printDebug("CFDPHandler::handleRequest\n"); -//#endif /* !FSFW_CPP_OSTREAM_ENABLED == 1 */ -//#endif -// -// // TODO read out packet from store using storeId -// -// return RETURN_OK; -//} -// -// ReturnValue_t CfdpHandler::performOperation(uint8_t opCode) { -// ReturnValue_t status = RETURN_OK; -// CommandMessage currentMessage; -// for (status = this->requestQueue->receiveMessage(¤tMessage); status == RETURN_OK; -// status = this->requestQueue->receiveMessage(¤tMessage)) { -// store_address_t storeId = CfdpMessage::getStoreId(¤tMessage); -// this->handleRequest(storeId); -// } -// return RETURN_OK; -//} -// -// uint32_t CfdpHandler::getIdentifier() const { return 0; } -// -// MessageQueueId_t CfdpHandler::getRequestQueue() const { return this->requestQueue->getId(); } diff --git a/src/fsfw/cfdp/CfdpHandler.h b/src/fsfw/cfdp/CfdpHandler.h deleted file mode 100644 index 8c2827ec..00000000 --- a/src/fsfw/cfdp/CfdpHandler.h +++ /dev/null @@ -1,63 +0,0 @@ -//#ifndef FSFW_CFDP_CFDPHANDLER_H_ -//#define FSFW_CFDP_CFDPHANDLER_H_ -// -//#include "fsfw/ipc/MessageQueueIF.h" -//#include "fsfw/objectmanager/SystemObject.h" -//#include "fsfw/returnvalues/HasReturnvaluesIF.h" -//#include "fsfw/storagemanager/storeAddress.h" -//#include "fsfw/tasks/ExecutableObjectIF.h" -//#include "fsfw/tmtcservices/AcceptsTelecommandsIF.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, CfdpHandler* distributor); -// /** -// * The destructor is empty. -// */ -// virtual ~CfdpHandler(); -// -// virtual ReturnValue_t handleRequest(store_address_t storeId); -// -// virtual ReturnValue_t initialize() override; -// virtual uint32_t getIdentifier() const override; -// MessageQueueId_t getRequestQueue() const 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; -// -// CfdpHandler* 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 = 100; -//}; -// -//#endif /* FSFW_CFDP_CFDPHANDLER_H_ */ From 11a4b276423ac287f5522cdbf913a81e1ee3d347 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Wed, 7 Sep 2022 18:20:38 +0200 Subject: [PATCH 103/169] 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); From 683cf8a047013571dc206d60c52810b8a92905a4 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Thu, 8 Sep 2022 11:08:40 +0200 Subject: [PATCH 104/169] some additional tests --- src/fsfw/cfdp/CfdpDistributor.cpp | 3 +- src/fsfw/cfdp/CfdpDistributor.h | 4 +- src/fsfw/cfdp/handler/DestHandler.cpp | 6 +- src/fsfw/cfdp/handler/DestHandler.h | 1 + src/fsfw/cfdp/pdu/FileDataReader.cpp | 8 +- src/fsfw/cfdp/pdu/FileDataReader.h | 4 +- src/fsfw/cfdp/pdu/FileDirectiveReader.cpp | 8 +- src/fsfw/cfdp/pdu/FileDirectiveReader.h | 4 +- src/fsfw/cfdp/pdu/HeaderReader.cpp | 67 +++-- .../pdu/{HeaderReader.h => PduHeaderReader.h} | 13 +- unittests/cfdp/pdu/testCfdpHeader.cpp | 253 +++++++++--------- unittests/cfdp/pdu/testKeepAlivePdu.cpp | 12 +- unittests/cfdp/pdu/testPromptPdu.cpp | 2 +- 13 files changed, 205 insertions(+), 180 deletions(-) rename src/fsfw/cfdp/pdu/{HeaderReader.h => PduHeaderReader.h} (88%) diff --git a/src/fsfw/cfdp/CfdpDistributor.cpp b/src/fsfw/cfdp/CfdpDistributor.cpp index d0237959..b233e67e 100644 --- a/src/fsfw/cfdp/CfdpDistributor.cpp +++ b/src/fsfw/cfdp/CfdpDistributor.cpp @@ -21,7 +21,8 @@ ReturnValue_t CfdpDistributor::selectDestination(MessageQueueId_t& destId) { if (accessorPair.first != returnvalue::OK) { return accessorPair.first; } - ReturnValue_t result = pduReader.setData(accessorPair.second.data(), accessorPair.second.size()); + ReturnValue_t result = + pduReader.setReadOnlyData(accessorPair.second.data(), accessorPair.second.size()); if (result != returnvalue::OK) { return result; } diff --git a/src/fsfw/cfdp/CfdpDistributor.h b/src/fsfw/cfdp/CfdpDistributor.h index 39ce0d27..13d000eb 100644 --- a/src/fsfw/cfdp/CfdpDistributor.h +++ b/src/fsfw/cfdp/CfdpDistributor.h @@ -4,7 +4,7 @@ #include #include -#include "fsfw/cfdp/pdu/HeaderReader.h" +#include "fsfw/cfdp/pdu/PduHeaderReader.h" #include "fsfw/returnvalues/returnvalue.h" #include "fsfw/tcdistribution/CfdpPacketChecker.h" #include "fsfw/tcdistribution/TcDistributorBase.h" @@ -60,7 +60,7 @@ class CfdpDistributor : public TcDistributorBase, public AcceptsTelecommandsIF { const char* name; MessageQueueId_t queueId; }; - HeaderReader pduReader; + PduHeaderReader pduReader; ReturnValue_t lastTcError = returnvalue::OK; ReturnValue_t lastTmError = returnvalue::OK; // I don't think a regular OBSW will have more than 1 or 2 of these destinations, so I think diff --git a/src/fsfw/cfdp/handler/DestHandler.cpp b/src/fsfw/cfdp/handler/DestHandler.cpp index 3660f75c..3ddf96ff 100644 --- a/src/fsfw/cfdp/handler/DestHandler.cpp +++ b/src/fsfw/cfdp/handler/DestHandler.cpp @@ -8,7 +8,7 @@ #include "fsfw/cfdp/pdu/EofPduReader.h" #include "fsfw/cfdp/pdu/FileDataReader.h" #include "fsfw/cfdp/pdu/FinishedPduCreator.h" -#include "fsfw/cfdp/pdu/HeaderReader.h" +#include "fsfw/cfdp/pdu/PduHeaderReader.h" #include "fsfw/objectmanager.h" #include "fsfw/tmtcservices/TmTcMessage.h" @@ -236,7 +236,7 @@ ReturnValue_t cfdp::DestHandler::handleMetadataParseError(ReturnValue_t result, sif::warning << "Parsing Metadata PDU failed with code " << result << std::endl; #else #endif - HeaderReader headerReader(rawData, maxSize); + PduHeaderReader headerReader(rawData, maxSize); result = headerReader.parseData(); if (result != OK) { // TODO: Now this really should not happen. Warning or error, @@ -461,3 +461,5 @@ void cfdp::DestHandler::setMsgQueue(MessageQueueIF& queue) { fp.msgQueue = &queu void cfdp::DestHandler::setEventReporter(EventReportingProxyIF& reporter) { fp.eventReporter = &reporter; } + +const cfdp::DestHandlerParams& cfdp::DestHandler::getDestHandlerParams() const { return dp; } diff --git a/src/fsfw/cfdp/handler/DestHandler.h b/src/fsfw/cfdp/handler/DestHandler.h index 5507045f..975ccaaf 100644 --- a/src/fsfw/cfdp/handler/DestHandler.h +++ b/src/fsfw/cfdp/handler/DestHandler.h @@ -126,6 +126,7 @@ class DestHandler { [[nodiscard]] CfdpStates getCfdpState() const; [[nodiscard]] TransactionStep getTransactionStep() const; [[nodiscard]] const TransactionId& getTransactionId() const; + [[nodiscard]] const DestHandlerParams& getDestHandlerParams() const; private: struct TransactionParams { diff --git a/src/fsfw/cfdp/pdu/FileDataReader.cpp b/src/fsfw/cfdp/pdu/FileDataReader.cpp index 8eac4c3f..9155ef28 100644 --- a/src/fsfw/cfdp/pdu/FileDataReader.cpp +++ b/src/fsfw/cfdp/pdu/FileDataReader.cpp @@ -1,16 +1,16 @@ #include "FileDataReader.h" FileDataReader::FileDataReader(const uint8_t* pduBuf, size_t maxSize, FileDataInfo& info) - : HeaderReader(pduBuf, maxSize), info(info) {} + : PduHeaderReader(pduBuf, maxSize), info(info) {} ReturnValue_t FileDataReader::parseData() { - ReturnValue_t result = HeaderReader::parseData(); + ReturnValue_t result = PduHeaderReader::parseData(); if (result != returnvalue::OK) { return result; } - size_t currentIdx = HeaderReader::getHeaderSize(); + size_t currentIdx = PduHeaderReader::getHeaderSize(); const uint8_t* buf = pointers.rawPtr + currentIdx; - size_t remSize = HeaderReader::getWholePduSize() - currentIdx; + size_t remSize = PduHeaderReader::getWholePduSize() - currentIdx; if (remSize < 1) { return SerializeIF::STREAM_TOO_SHORT; } diff --git a/src/fsfw/cfdp/pdu/FileDataReader.h b/src/fsfw/cfdp/pdu/FileDataReader.h index 62e0f89b..aa962e2b 100644 --- a/src/fsfw/cfdp/pdu/FileDataReader.h +++ b/src/fsfw/cfdp/pdu/FileDataReader.h @@ -3,9 +3,9 @@ #include "../definitions.h" #include "FileDataInfo.h" -#include "HeaderReader.h" +#include "PduHeaderReader.h" -class FileDataReader : public HeaderReader { +class FileDataReader : public PduHeaderReader { public: FileDataReader(const uint8_t* pduBuf, size_t maxSize, FileDataInfo& info); diff --git a/src/fsfw/cfdp/pdu/FileDirectiveReader.cpp b/src/fsfw/cfdp/pdu/FileDirectiveReader.cpp index 4099efd9..5d43ebb0 100644 --- a/src/fsfw/cfdp/pdu/FileDirectiveReader.cpp +++ b/src/fsfw/cfdp/pdu/FileDirectiveReader.cpp @@ -1,12 +1,12 @@ #include "FileDirectiveReader.h" FileDirectiveReader::FileDirectiveReader(const uint8_t *pduBuf, size_t maxSize) - : HeaderReader(pduBuf, maxSize) {} + : PduHeaderReader(pduBuf, maxSize) {} cfdp::FileDirectives FileDirectiveReader::getFileDirective() const { return fileDirective; } ReturnValue_t FileDirectiveReader::parseData() { - ReturnValue_t result = HeaderReader::parseData(); + ReturnValue_t result = PduHeaderReader::parseData(); if (result != returnvalue::OK) { return result; } @@ -16,7 +16,7 @@ ReturnValue_t FileDirectiveReader::parseData() { if (FileDirectiveReader::getWholePduSize() > maxSize) { return SerializeIF::STREAM_TOO_SHORT; } - size_t currentIdx = HeaderReader::getHeaderSize(); + size_t currentIdx = PduHeaderReader::getHeaderSize(); if (not checkFileDirective(pointers.rawPtr[currentIdx])) { return cfdp::INVALID_DIRECTIVE_FIELDS; } @@ -26,7 +26,7 @@ ReturnValue_t FileDirectiveReader::parseData() { size_t FileDirectiveReader::getHeaderSize() const { // return size of header plus the directive byte - return HeaderReader::getHeaderSize() + 1; + return PduHeaderReader::getHeaderSize() + 1; } bool FileDirectiveReader::checkFileDirective(uint8_t rawByte) { diff --git a/src/fsfw/cfdp/pdu/FileDirectiveReader.h b/src/fsfw/cfdp/pdu/FileDirectiveReader.h index 69dd44cd..83a71c71 100644 --- a/src/fsfw/cfdp/pdu/FileDirectiveReader.h +++ b/src/fsfw/cfdp/pdu/FileDirectiveReader.h @@ -2,7 +2,7 @@ #define FSFW_SRC_FSFW_CFDP_PDU_FILEDIRECTIVEDESERIALIZER_H_ #include "../definitions.h" -#include "fsfw/cfdp/pdu/HeaderReader.h" +#include "fsfw/cfdp/pdu/PduHeaderReader.h" /** * @brief This class is used to deserialize a PDU file directive header from raw memory. @@ -11,7 +11,7 @@ * This is a zero-copy implementation and #parseData needs to be called to ensure the data is * valid. */ -class FileDirectiveReader : public HeaderReader { +class FileDirectiveReader : public PduHeaderReader { public: FileDirectiveReader(const uint8_t* pduBuf, size_t maxSize); diff --git a/src/fsfw/cfdp/pdu/HeaderReader.cpp b/src/fsfw/cfdp/pdu/HeaderReader.cpp index e2f070db..3417a57c 100644 --- a/src/fsfw/cfdp/pdu/HeaderReader.cpp +++ b/src/fsfw/cfdp/pdu/HeaderReader.cpp @@ -1,12 +1,14 @@ -#include "HeaderReader.h" - #include #include -HeaderReader::HeaderReader(const uint8_t *pduBuf, size_t maxSize) { setData(pduBuf, maxSize); } +#include "PduHeaderReader.h" -ReturnValue_t HeaderReader::parseData() { +PduHeaderReader::PduHeaderReader(const uint8_t *pduBuf, size_t maxSize) { + setReadOnlyData(pduBuf, maxSize); +} + +ReturnValue_t PduHeaderReader::parseData() { if (pointers.rawPtr == nullptr) { return returnvalue::FAILED; } @@ -20,10 +22,15 @@ ReturnValue_t HeaderReader::parseData() { cfdp::WidthInBytes widthSeqNum = getLenSeqNum(); seqNumRaw = static_cast(sourceIdRaw) + static_cast(widthEntityIds); destIdRaw = static_cast(seqNumRaw) + static_cast(widthSeqNum); + if (getWholePduSize() > PduHeaderReader::getHeaderSize()) { + pointers.dataFieldStart = reinterpret_cast(destIdRaw) + widthEntityIds; + } else { + pointers.dataFieldStart = nullptr; + } return returnvalue::OK; } -ReturnValue_t HeaderReader::setData(uint8_t *dataPtr, size_t maxSize_, void *args) { +ReturnValue_t PduHeaderReader::setData(uint8_t *dataPtr, size_t maxSize_, void *args) { if (dataPtr == nullptr) { return returnvalue::FAILED; } @@ -35,68 +42,68 @@ ReturnValue_t HeaderReader::setData(uint8_t *dataPtr, size_t maxSize_, void *arg return returnvalue::OK; } -size_t HeaderReader::getHeaderSize() const { +size_t PduHeaderReader::getHeaderSize() const { if (pointers.fixedHeader != nullptr) { return getLenEntityIds() * 2 + getLenSeqNum() + 4; } return 0; } -size_t HeaderReader::getPduDataFieldLen() const { +size_t PduHeaderReader::getPduDataFieldLen() const { return (pointers.fixedHeader->pduDataFieldLenH << 8) | pointers.fixedHeader->pduDataFieldLenL; } -size_t HeaderReader::getWholePduSize() const { - return getPduDataFieldLen() + HeaderReader::getHeaderSize(); +size_t PduHeaderReader::getWholePduSize() const { + return getPduDataFieldLen() + PduHeaderReader::getHeaderSize(); } -cfdp::PduType HeaderReader::getPduType() const { +cfdp::PduType PduHeaderReader::getPduType() const { return static_cast((pointers.fixedHeader->firstByte >> 4) & 0x01); } -cfdp::Direction HeaderReader::getDirection() const { +cfdp::Direction PduHeaderReader::getDirection() const { return static_cast((pointers.fixedHeader->firstByte >> 3) & 0x01); } -cfdp::TransmissionModes HeaderReader::getTransmissionMode() const { +cfdp::TransmissionModes PduHeaderReader::getTransmissionMode() const { return static_cast((pointers.fixedHeader->firstByte >> 2) & 0x01); } -bool HeaderReader::getCrcFlag() const { return (pointers.fixedHeader->firstByte >> 1) & 0x01; } +bool PduHeaderReader::getCrcFlag() const { return (pointers.fixedHeader->firstByte >> 1) & 0x01; } -bool HeaderReader::getLargeFileFlag() const { return pointers.fixedHeader->firstByte & 0x01; } +bool PduHeaderReader::getLargeFileFlag() const { return pointers.fixedHeader->firstByte & 0x01; } -cfdp::SegmentationControl HeaderReader::getSegmentationControl() const { +cfdp::SegmentationControl PduHeaderReader::getSegmentationControl() const { return static_cast((pointers.fixedHeader->fourthByte >> 7) & 0x01); } -cfdp::WidthInBytes HeaderReader::getLenEntityIds() const { +cfdp::WidthInBytes PduHeaderReader::getLenEntityIds() const { return static_cast((pointers.fixedHeader->fourthByte >> 4) & 0x07); } -cfdp::WidthInBytes HeaderReader::getLenSeqNum() const { +cfdp::WidthInBytes PduHeaderReader::getLenSeqNum() const { return static_cast(pointers.fixedHeader->fourthByte & 0x07); } -cfdp::SegmentMetadataFlag HeaderReader::getSegmentMetadataFlag() const { +cfdp::SegmentMetadataFlag PduHeaderReader::getSegmentMetadataFlag() const { return static_cast((pointers.fixedHeader->fourthByte >> 3) & 0x01); } -void HeaderReader::getSourceId(cfdp::EntityId &sourceId) const { +void PduHeaderReader::getSourceId(cfdp::EntityId &sourceId) const { assignVarLenField(dynamic_cast(&sourceId), getLenEntityIds(), this->sourceIdRaw); } -void HeaderReader::getDestId(cfdp::EntityId &destId) const { +void PduHeaderReader::getDestId(cfdp::EntityId &destId) const { assignVarLenField(dynamic_cast(&destId), getLenEntityIds(), this->destIdRaw); } -void HeaderReader::getTransactionSeqNum(cfdp::TransactionSeqNum &seqNum) const { +void PduHeaderReader::getTransactionSeqNum(cfdp::TransactionSeqNum &seqNum) const { assignVarLenField(dynamic_cast(&seqNum), getLenSeqNum(), this->seqNumRaw); } -void HeaderReader::assignVarLenField(cfdp::VarLenField *field, cfdp::WidthInBytes width, - void *sourcePtr) const { +void PduHeaderReader::assignVarLenField(cfdp::VarLenField *field, cfdp::WidthInBytes width, + void *sourcePtr) const { switch (width) { case (cfdp::WidthInBytes::ONE_BYTE): { auto *fieldTyped = static_cast(sourcePtr); @@ -122,25 +129,25 @@ void HeaderReader::assignVarLenField(cfdp::VarLenField *field, cfdp::WidthInByte } } -size_t HeaderReader::getMaxSize() const { return maxSize; } +size_t PduHeaderReader::getMaxSize() const { return maxSize; } -bool HeaderReader::hasSegmentMetadataFlag() const { +bool PduHeaderReader::hasSegmentMetadataFlag() const { if (this->getSegmentMetadataFlag() == cfdp::SegmentMetadataFlag::PRESENT) { return true; } return false; } -ReturnValue_t HeaderReader::setData(const uint8_t *dataPtr, size_t maxSize_) { +ReturnValue_t PduHeaderReader::setReadOnlyData(const uint8_t *dataPtr, size_t maxSize_) { return setData(const_cast(dataPtr), maxSize_, nullptr); } -bool HeaderReader::isNull() const { +bool PduHeaderReader::isNull() const { return pointers.rawPtr == nullptr or pointers.fixedHeader == nullptr; } -HeaderReader::operator bool() const { return not isNull(); } +PduHeaderReader::operator bool() const { return not isNull(); } -void HeaderReader::fillConfig(PduConfig &cfg) const { +void PduHeaderReader::fillConfig(PduConfig &cfg) const { cfg.largeFile = getLargeFileFlag(); cfg.crcFlag = getCrcFlag(); cfg.mode = getTransmissionMode(); @@ -149,3 +156,5 @@ void HeaderReader::fillConfig(PduConfig &cfg) const { getSourceId(cfg.sourceId); getDestId(cfg.destId); } + +const uint8_t *PduHeaderReader::getPduDataField() const { return pointers.dataFieldStart; } diff --git a/src/fsfw/cfdp/pdu/HeaderReader.h b/src/fsfw/cfdp/pdu/PduHeaderReader.h similarity index 88% rename from src/fsfw/cfdp/pdu/HeaderReader.h rename to src/fsfw/cfdp/pdu/PduHeaderReader.h index 533320b7..7809f59c 100644 --- a/src/fsfw/cfdp/pdu/HeaderReader.h +++ b/src/fsfw/cfdp/pdu/PduHeaderReader.h @@ -23,16 +23,16 @@ struct PduHeaderFixedStruct { * This is a zero-copy implementation and #parseData needs to be called to ensure the data is * valid. */ -class HeaderReader : public RedirectableDataPointerIF, public PduHeaderIF { +class PduHeaderReader : public RedirectableDataPointerIF, public PduHeaderIF { public: - HeaderReader() = default; + PduHeaderReader() = default; /** * Initialize a PDU header from raw data. This is a zero-copy implementation and #parseData * needs to be called to ensure the data is valid * @param pduBuf * @param maxSize */ - HeaderReader(const uint8_t* pduBuf, size_t maxSize); + PduHeaderReader(const uint8_t* pduBuf, size_t maxSize); /** * This needs to be called before accessing the PDU fields to avoid segmentation faults. @@ -74,6 +74,7 @@ class HeaderReader : public RedirectableDataPointerIF, public PduHeaderIF { ReturnValue_t deserResult = returnvalue::OK; [[nodiscard]] size_t getMaxSize() const; + [[nodiscard]] const uint8_t* getPduDataField() const; /** * Can also be used to reset the pointer to a nullptr, but the getter functions will not @@ -83,11 +84,12 @@ class HeaderReader : public RedirectableDataPointerIF, public PduHeaderIF { * @param args * @return */ - ReturnValue_t setData(const uint8_t* dataPtr, size_t maxSize); + ReturnValue_t setReadOnlyData(const uint8_t* dataPtr, size_t maxSize); protected: struct Pointers { PduHeaderFixedStruct* fixedHeader = nullptr; + const uint8_t* dataFieldStart = nullptr; const uint8_t* rawPtr = nullptr; }; @@ -96,8 +98,7 @@ class HeaderReader : public RedirectableDataPointerIF, public PduHeaderIF { private: /** - * Can also be used to reset the pointer to a nullptr, but the getter functions will not - * perform nullptr checks! + * This is a reader class and setting mutable data is forbidden. Use @setReadOnlyData instead. * @param dataPtr * @param maxSize * @param args diff --git a/unittests/cfdp/pdu/testCfdpHeader.cpp b/unittests/cfdp/pdu/testCfdpHeader.cpp index 99a0c470..6d22154b 100644 --- a/unittests/cfdp/pdu/testCfdpHeader.cpp +++ b/unittests/cfdp/pdu/testCfdpHeader.cpp @@ -1,10 +1,14 @@ #include #include +#include "fsfw/cfdp/pdu/FinishedInfo.h" +#include "fsfw/cfdp/pdu/FinishedPduCreator.h" #include "fsfw/cfdp/pdu/HeaderCreator.h" -#include "fsfw/cfdp/pdu/HeaderReader.h" +#include "fsfw/cfdp/pdu/PduHeaderReader.h" #include "fsfw/returnvalues/returnvalue.h" +using namespace returnvalue; + TEST_CASE("CFDP Header", "[cfdp]") { using namespace cfdp; std::array serBuf{}; @@ -17,63 +21,62 @@ TEST_CASE("CFDP Header", "[cfdp]") { uint8_t* serTarget = serBuf.data(); const uint8_t* deserTarget = serTarget; size_t serSize = 0; - auto headerSerializer = HeaderCreator(pduConf, cfdp::PduType::FILE_DIRECTIVE, 0); + auto creator = HeaderCreator(pduConf, cfdp::PduType::FILE_DIRECTIVE, 0); SECTION("Header State") { REQUIRE(seqNum.getSerializedSize() == 1); - REQUIRE(headerSerializer.getPduDataFieldLen() == 0); - REQUIRE(headerSerializer.getSerializedSize() == 7); - REQUIRE(headerSerializer.getWholePduSize() == 7); - REQUIRE(headerSerializer.getCrcFlag() == false); - REQUIRE(headerSerializer.getDirection() == cfdp::Direction::TOWARDS_RECEIVER); - REQUIRE(headerSerializer.getLargeFileFlag() == false); - REQUIRE(headerSerializer.getLenEntityIds() == 1); - REQUIRE(headerSerializer.getLenSeqNum() == 1); - REQUIRE(headerSerializer.getPduType() == cfdp::PduType::FILE_DIRECTIVE); - REQUIRE(headerSerializer.getSegmentMetadataFlag() == cfdp::SegmentMetadataFlag::NOT_PRESENT); - REQUIRE(headerSerializer.getSegmentationControl() == false); - REQUIRE(headerSerializer.getTransmissionMode() == cfdp::TransmissionModes::ACKNOWLEDGED); + REQUIRE(creator.getPduDataFieldLen() == 0); + REQUIRE(creator.getSerializedSize() == 7); + REQUIRE(creator.getWholePduSize() == 7); + REQUIRE(creator.getCrcFlag() == false); + REQUIRE(creator.getDirection() == cfdp::Direction::TOWARDS_RECEIVER); + REQUIRE(creator.getLargeFileFlag() == false); + REQUIRE(creator.getLenEntityIds() == 1); + REQUIRE(creator.getLenSeqNum() == 1); + REQUIRE(creator.getPduType() == cfdp::PduType::FILE_DIRECTIVE); + REQUIRE(creator.getSegmentMetadataFlag() == cfdp::SegmentMetadataFlag::NOT_PRESENT); + REQUIRE(creator.getSegmentationControl() == false); + REQUIRE(creator.getTransmissionMode() == cfdp::TransmissionModes::ACKNOWLEDGED); cfdp::TransactionSeqNum seqNumLocal; - headerSerializer.getTransactionSeqNum(seqNumLocal); + creator.getTransactionSeqNum(seqNumLocal); REQUIRE(seqNumLocal.getWidth() == cfdp::WidthInBytes::ONE_BYTE); REQUIRE(seqNumLocal.getValue() == 2); cfdp::EntityId sourceDestId; - headerSerializer.getSourceId(sourceDestId); + creator.getSourceId(sourceDestId); REQUIRE(sourceDestId.getWidth() == cfdp::WidthInBytes::ONE_BYTE); REQUIRE(sourceDestId.getValue() == 0); - headerSerializer.getDestId(sourceDestId); + creator.getDestId(sourceDestId); REQUIRE(sourceDestId.getWidth() == cfdp::WidthInBytes::ONE_BYTE); REQUIRE(sourceDestId.getValue() == 1); } SECTION("Deserialization fails") { const uint8_t** dummyPtr = nullptr; - REQUIRE(headerSerializer.deSerialize(dummyPtr, &serSize, SerializeIF::Endianness::NETWORK) == + REQUIRE(creator.deSerialize(dummyPtr, &serSize, SerializeIF::Endianness::NETWORK) == returnvalue::FAILED); } SECTION("Serialization fails") { - REQUIRE(headerSerializer.serialize(nullptr, &serSize, serBuf.size(), - SerializeIF::Endianness::NETWORK) == returnvalue::FAILED); + REQUIRE(creator.serialize(nullptr, &serSize, serBuf.size(), SerializeIF::Endianness::NETWORK) == + returnvalue::FAILED); } SECTION("Buffer Too Short") { for (uint8_t idx = 0; idx < 7; idx++) { - result = headerSerializer.serialize(&serTarget, &serSize, idx, SerializeIF::Endianness::BIG); + result = creator.serialize(&serTarget, &serSize, idx, SerializeIF::Endianness::BIG); REQUIRE(result == static_cast(SerializeIF::BUFFER_TOO_SHORT)); } } SECTION("Set Data Field Len") { // Set PDU data field len - headerSerializer.setPduDataFieldLen(0x0ff0); - REQUIRE(headerSerializer.getPduDataFieldLen() == 0x0ff0); - REQUIRE(headerSerializer.getSerializedSize() == 7); - REQUIRE(headerSerializer.getWholePduSize() == 7 + 0x0ff0); + creator.setPduDataFieldLen(0x0ff0); + REQUIRE(creator.getPduDataFieldLen() == 0x0ff0); + REQUIRE(creator.getSerializedSize() == 7); + REQUIRE(creator.getWholePduSize() == 7 + 0x0ff0); serTarget = serBuf.data(); serSize = 0; - result = headerSerializer.serialize(&serTarget, &serSize, serBuf.size(), - SerializeIF::Endianness::BIG); + result = creator.serialize(&serTarget, &serSize, serBuf.size(), SerializeIF::Endianness::BIG); REQUIRE(serBuf[1] == 0x0f); REQUIRE(serBuf[2] == 0xf0); } @@ -83,28 +86,27 @@ TEST_CASE("CFDP Header", "[cfdp]") { pduConf.largeFile = true; pduConf.direction = cfdp::Direction::TOWARDS_SENDER; pduConf.mode = cfdp::TransmissionModes::UNACKNOWLEDGED; - headerSerializer.setSegmentationControl( - cfdp::SegmentationControl::RECORD_BOUNDARIES_PRESERVATION); - headerSerializer.setPduType(cfdp::PduType::FILE_DATA); - headerSerializer.setSegmentMetadataFlag(cfdp::SegmentMetadataFlag::PRESENT); + creator.setSegmentationControl(cfdp::SegmentationControl::RECORD_BOUNDARIES_PRESERVATION); + creator.setPduType(cfdp::PduType::FILE_DATA); + creator.setSegmentMetadataFlag(cfdp::SegmentMetadataFlag::PRESENT); serTarget = serBuf.data(); serSize = 0; SECTION("Regular") { // Everything except version bit flipped to one now - REQUIRE(headerSerializer.serialize(&serTarget, &serSize, serBuf.size(), - SerializeIF::Endianness::BIG) == returnvalue::OK); + REQUIRE(creator.serialize(&serTarget, &serSize, serBuf.size(), + SerializeIF::Endianness::BIG) == returnvalue::OK); CHECK(serBuf[0] == 0x3f); CHECK(serBuf[3] == 0x99); - REQUIRE(headerSerializer.getCrcFlag() == true); - REQUIRE(headerSerializer.getDirection() == cfdp::Direction::TOWARDS_SENDER); - REQUIRE(headerSerializer.getLargeFileFlag() == true); - REQUIRE(headerSerializer.getLenEntityIds() == 1); - REQUIRE(headerSerializer.getLenSeqNum() == 1); - REQUIRE(headerSerializer.getPduType() == cfdp::PduType::FILE_DATA); - REQUIRE(headerSerializer.getSegmentMetadataFlag() == cfdp::SegmentMetadataFlag::PRESENT); - REQUIRE(headerSerializer.getTransmissionMode() == cfdp::TransmissionModes::UNACKNOWLEDGED); - REQUIRE(headerSerializer.getSegmentationControl() == true); + REQUIRE(creator.getCrcFlag() == true); + REQUIRE(creator.getDirection() == cfdp::Direction::TOWARDS_SENDER); + REQUIRE(creator.getLargeFileFlag() == true); + REQUIRE(creator.getLenEntityIds() == 1); + REQUIRE(creator.getLenSeqNum() == 1); + REQUIRE(creator.getPduType() == cfdp::PduType::FILE_DATA); + REQUIRE(creator.getSegmentMetadataFlag() == cfdp::SegmentMetadataFlag::PRESENT); + REQUIRE(creator.getTransmissionMode() == cfdp::TransmissionModes::UNACKNOWLEDGED); + REQUIRE(creator.getSegmentationControl() == true); } SECTION("Other variable sized fields") { @@ -112,18 +114,18 @@ TEST_CASE("CFDP Header", "[cfdp]") { pduConf.sourceId.setValue(cfdp::WidthInBytes::FOUR_BYTES, 0xff00ff00); pduConf.destId.setValue(cfdp::WidthInBytes::FOUR_BYTES, 0x00ff00ff); REQUIRE(pduConf.sourceId.getSerializedSize() == 4); - REQUIRE(headerSerializer.getSerializedSize() == 14); - REQUIRE(headerSerializer.serialize(&serTarget, &serSize, serBuf.size(), - SerializeIF::Endianness::BIG) == returnvalue::OK); - REQUIRE(headerSerializer.getCrcFlag() == true); - REQUIRE(headerSerializer.getDirection() == cfdp::Direction::TOWARDS_SENDER); - REQUIRE(headerSerializer.getLargeFileFlag() == true); - REQUIRE(headerSerializer.getLenEntityIds() == 4); - REQUIRE(headerSerializer.getLenSeqNum() == 2); - REQUIRE(headerSerializer.getPduType() == cfdp::PduType::FILE_DATA); - REQUIRE(headerSerializer.getSegmentMetadataFlag() == cfdp::SegmentMetadataFlag::PRESENT); - REQUIRE(headerSerializer.getTransmissionMode() == cfdp::TransmissionModes::UNACKNOWLEDGED); - REQUIRE(headerSerializer.getSegmentationControl() == true); + REQUIRE(creator.getSerializedSize() == 14); + REQUIRE(creator.serialize(&serTarget, &serSize, serBuf.size(), + SerializeIF::Endianness::BIG) == returnvalue::OK); + REQUIRE(creator.getCrcFlag() == true); + REQUIRE(creator.getDirection() == cfdp::Direction::TOWARDS_SENDER); + REQUIRE(creator.getLargeFileFlag() == true); + REQUIRE(creator.getLenEntityIds() == 4); + REQUIRE(creator.getLenSeqNum() == 2); + REQUIRE(creator.getPduType() == cfdp::PduType::FILE_DATA); + REQUIRE(creator.getSegmentMetadataFlag() == cfdp::SegmentMetadataFlag::PRESENT); + REQUIRE(creator.getTransmissionMode() == cfdp::TransmissionModes::UNACKNOWLEDGED); + REQUIRE(creator.getSegmentationControl() == true); // Last three bits are 2 now (length of seq number) and bit 1 to bit 3 is 4 (len entity IDs) REQUIRE(serBuf[3] == 0b11001010); uint32_t entityId = 0; @@ -148,9 +150,8 @@ TEST_CASE("CFDP Header", "[cfdp]") { pduConf.sourceId.setValue(cfdp::WidthInBytes::FOUR_BYTES, 0xff00ff00); pduConf.destId.setValue(cfdp::WidthInBytes::FOUR_BYTES, 0x00ff00ff); for (uint8_t idx = 0; idx < 14; idx++) { - REQUIRE( - headerSerializer.serialize(&serTarget, &serSize, idx, SerializeIF::Endianness::BIG) == - SerializeIF::BUFFER_TOO_SHORT); + REQUIRE(creator.serialize(&serTarget, &serSize, idx, SerializeIF::Endianness::BIG) == + SerializeIF::BUFFER_TOO_SHORT); } } } @@ -165,8 +166,7 @@ TEST_CASE("CFDP Header", "[cfdp]") { } SECTION("Header Serialization") { - result = headerSerializer.serialize(&serTarget, &serSize, serBuf.size(), - SerializeIF::Endianness::BIG); + result = creator.serialize(&serTarget, &serSize, serBuf.size(), SerializeIF::Endianness::BIG); REQUIRE(result == returnvalue::OK); REQUIRE(serSize == 7); // Only version bits are set @@ -214,40 +214,49 @@ TEST_CASE("CFDP Header", "[cfdp]") { REQUIRE(result == static_cast(SerializeIF::BUFFER_TOO_SHORT)); } - SECTION("Header Deserialization") { - REQUIRE(headerSerializer.serialize(&serTarget, &serSize, serBuf.size(), - SerializeIF::Endianness::BIG) == returnvalue::OK); + SECTION("Header Deserialization 0") { + REQUIRE(creator.serialize(&serTarget, &serSize, serBuf.size(), SerializeIF::Endianness::BIG) == + returnvalue::OK); REQUIRE(serBuf[1] == 0); REQUIRE(serBuf[2] == 0); // Entity and Transaction Sequence number are 1 byte large REQUIRE(serBuf[3] == 0b00010001); REQUIRE(serSize == 7); // Deser call not strictly necessary - auto headerDeser = HeaderReader(serBuf.data(), serBuf.size()); + auto reader = PduHeaderReader(serBuf.data(), serBuf.size()); - ReturnValue_t serResult = headerDeser.parseData(); + ReturnValue_t serResult = reader.parseData(); REQUIRE(serResult == returnvalue::OK); - REQUIRE(headerDeser.getPduDataFieldLen() == 0); - REQUIRE(headerDeser.getHeaderSize() == 7); - REQUIRE(headerDeser.getWholePduSize() == 7); - REQUIRE(headerDeser.getCrcFlag() == false); - REQUIRE(headerDeser.getDirection() == cfdp::Direction::TOWARDS_RECEIVER); - REQUIRE(headerDeser.getLargeFileFlag() == false); - REQUIRE(headerDeser.getLenEntityIds() == 1); - REQUIRE(headerDeser.getLenSeqNum() == 1); - REQUIRE(headerDeser.getPduType() == cfdp::PduType::FILE_DIRECTIVE); - REQUIRE(headerDeser.getSegmentMetadataFlag() == cfdp::SegmentMetadataFlag::NOT_PRESENT); - REQUIRE(headerDeser.getSegmentationControl() == false); - REQUIRE(headerDeser.getTransmissionMode() == cfdp::TransmissionModes::ACKNOWLEDGED); + REQUIRE(reader.getPduDataFieldLen() == 0); + REQUIRE(reader.getHeaderSize() == 7); + REQUIRE(reader.getWholePduSize() == 7); + REQUIRE(reader.getCrcFlag() == false); + REQUIRE(reader.getDirection() == cfdp::Direction::TOWARDS_RECEIVER); + REQUIRE(reader.getLargeFileFlag() == false); + REQUIRE(reader.getLenEntityIds() == 1); + REQUIRE(reader.getLenSeqNum() == 1); + REQUIRE(reader.getPduType() == cfdp::PduType::FILE_DIRECTIVE); + REQUIRE(reader.getSegmentMetadataFlag() == cfdp::SegmentMetadataFlag::NOT_PRESENT); + REQUIRE(reader.getSegmentationControl() == false); + REQUIRE(reader.getTransmissionMode() == cfdp::TransmissionModes::ACKNOWLEDGED); + // No PDU data contained, so the PDU data field is empty + REQUIRE(reader.getPduDataField() == nullptr); + size_t deSerSize = reader.getWholePduSize(); + serTarget = serBuf.data(); + const auto** serTargetConst = const_cast(&serTarget); + result = reader.parseData(); + REQUIRE(result == returnvalue::OK); + } + + SECTION("Header Deserialization 1") { pduConf.crcFlag = true; pduConf.largeFile = true; pduConf.direction = cfdp::Direction::TOWARDS_SENDER; pduConf.mode = cfdp::TransmissionModes::UNACKNOWLEDGED; - headerSerializer.setSegmentationControl( - cfdp::SegmentationControl::RECORD_BOUNDARIES_PRESERVATION); - headerSerializer.setPduType(cfdp::PduType::FILE_DATA); - headerSerializer.setSegmentMetadataFlag(cfdp::SegmentMetadataFlag::PRESENT); + creator.setSegmentationControl(cfdp::SegmentationControl::RECORD_BOUNDARIES_PRESERVATION); + creator.setPduType(cfdp::PduType::FILE_DATA); + creator.setSegmentMetadataFlag(cfdp::SegmentMetadataFlag::PRESENT); result = pduConf.seqNum.setValue(cfdp::WidthInBytes::TWO_BYTES, 0x0fff); REQUIRE(result == returnvalue::OK); result = pduConf.sourceId.setValue(cfdp::WidthInBytes::FOUR_BYTES, 0xff00ff00); @@ -256,61 +265,63 @@ TEST_CASE("CFDP Header", "[cfdp]") { REQUIRE(result == returnvalue::OK); serTarget = serBuf.data(); serSize = 0; - result = headerSerializer.serialize(&serTarget, &serSize, serBuf.size(), - SerializeIF::Endianness::BIG); - headerDeser = HeaderReader(serBuf.data(), serBuf.size()); - - result = headerDeser.parseData(); - REQUIRE(result == returnvalue::OK); + result = creator.serialize(&serTarget, &serSize, serBuf.size(), SerializeIF::Endianness::BIG); + PduHeaderReader reader(serBuf.data(), serBuf.size()); + REQUIRE(reader.parseData() == returnvalue::OK); // Everything except version bit flipped to one now REQUIRE(serBuf[0] == 0x3f); REQUIRE(serBuf[3] == 0b11001010); - REQUIRE(headerDeser.getWholePduSize() == 14); + REQUIRE(reader.getWholePduSize() == 14); - REQUIRE(headerDeser.getCrcFlag() == true); - REQUIRE(headerDeser.getDirection() == cfdp::Direction::TOWARDS_SENDER); - REQUIRE(headerDeser.getLargeFileFlag() == true); - REQUIRE(headerDeser.getLenEntityIds() == 4); - REQUIRE(headerDeser.getLenSeqNum() == 2); - REQUIRE(headerDeser.getPduType() == cfdp::PduType::FILE_DATA); - REQUIRE(headerDeser.getSegmentMetadataFlag() == cfdp::SegmentMetadataFlag::PRESENT); - REQUIRE(headerDeser.getSegmentationControl() == true); - REQUIRE(headerDeser.getTransmissionMode() == cfdp::TransmissionModes::UNACKNOWLEDGED); + REQUIRE(reader.getCrcFlag() == true); + REQUIRE(reader.getDirection() == cfdp::Direction::TOWARDS_SENDER); + REQUIRE(reader.getLargeFileFlag() == true); + REQUIRE(reader.getLenEntityIds() == 4); + REQUIRE(reader.getLenSeqNum() == 2); + REQUIRE(reader.getPduType() == cfdp::PduType::FILE_DATA); + REQUIRE(reader.getSegmentMetadataFlag() == cfdp::SegmentMetadataFlag::PRESENT); + REQUIRE(reader.getSegmentationControl() == true); + REQUIRE(reader.getTransmissionMode() == cfdp::TransmissionModes::UNACKNOWLEDGED); + // Again, no data field set because this is a header only + REQUIRE(reader.getPduDataField() == nullptr); cfdp::TransactionSeqNum seqNumLocal; - headerDeser.getTransactionSeqNum(seqNumLocal); + reader.getTransactionSeqNum(seqNumLocal); REQUIRE(seqNumLocal.getWidth() == cfdp::WidthInBytes::TWO_BYTES); REQUIRE(seqNumLocal.getValue() == 0x0fff); cfdp::EntityId sourceDestId; - headerDeser.getSourceId(sourceDestId); + reader.getSourceId(sourceDestId); REQUIRE(sourceDestId.getWidth() == cfdp::WidthInBytes::FOUR_BYTES); REQUIRE(sourceDestId.getValue() == 0xff00ff00); - headerDeser.getDestId(sourceDestId); + reader.getDestId(sourceDestId); REQUIRE(sourceDestId.getWidth() == cfdp::WidthInBytes::FOUR_BYTES); REQUIRE(sourceDestId.getValue() == 0x00ff00ff); + CHECK(reader.setReadOnlyData(nullptr, -1) != returnvalue::OK); + REQUIRE(reader.getHeaderSize() == 14); - size_t deSerSize = headerDeser.getWholePduSize(); - serTarget = serBuf.data(); - const auto** serTargetConst = const_cast(&serTarget); - result = headerDeser.parseData(); - REQUIRE(result == returnvalue::OK); + SECTION("Manipulate Source Dest ID") { + serTarget = serBuf.data(); + serSize = 0; + pduConf.sourceId.setValue(cfdp::WidthInBytes::ONE_BYTE, 22); + pduConf.destId.setValue(cfdp::WidthInBytes::ONE_BYTE, 48); + result = creator.serialize(&serTarget, &serSize, serBuf.size(), SerializeIF::Endianness::BIG); + reader.getSourceId(sourceDestId); + REQUIRE(sourceDestId.getWidth() == cfdp::WidthInBytes::ONE_BYTE); + REQUIRE(sourceDestId.getValue() == 22); + } + } - CHECK(headerDeser.setData(nullptr, -1) != returnvalue::OK); - REQUIRE(headerDeser.getHeaderSize() == 14); - headerDeser.setData(serBuf.data(), serBuf.size()); - - serTarget = serBuf.data(); - serSize = 0; - pduConf.sourceId.setValue(cfdp::WidthInBytes::ONE_BYTE, 22); - pduConf.destId.setValue(cfdp::WidthInBytes::ONE_BYTE, 48); - result = headerSerializer.serialize(&serTarget, &serSize, serBuf.size(), - SerializeIF::Endianness::BIG); - REQUIRE(result == returnvalue::OK); - REQUIRE(headerDeser.getWholePduSize() == 8); - headerDeser.setData(serBuf.data(), serBuf.size()); - - headerDeser.getSourceId(sourceDestId); - REQUIRE(sourceDestId.getWidth() == cfdp::WidthInBytes::ONE_BYTE); - REQUIRE(sourceDestId.getValue() == 22); + SECTION("Verify data field pointer") { + FinishedInfo info(cfdp::ConditionCode::INACTIVITY_DETECTED, + cfdp::FileDeliveryCode::DATA_INCOMPLETE, + cfdp::FileDeliveryStatus::DISCARDED_DELIBERATELY); + FinishPduCreator finishCreator(pduConf, info); + REQUIRE(finishCreator.serialize(serBuf.data(), serSize, serBuf.size()) == OK); + // This PDU contains the directive code and some finishes PDU properties packed into one byte + // in addition to the header + REQUIRE(finishCreator.getSerializedSize() == 9); + PduHeaderReader reader(serBuf.data(), serBuf.size()); + REQUIRE(reader.parseData() == returnvalue::OK); + REQUIRE(reader.getPduDataField() == serBuf.data() + 7); } } diff --git a/unittests/cfdp/pdu/testKeepAlivePdu.cpp b/unittests/cfdp/pdu/testKeepAlivePdu.cpp index b82feb32..34a529e9 100644 --- a/unittests/cfdp/pdu/testKeepAlivePdu.cpp +++ b/unittests/cfdp/pdu/testKeepAlivePdu.cpp @@ -61,19 +61,19 @@ TEST_CASE("Keep Alive PDU", "[cfdp][pdu]") { // Set another file size progress.setFileSize(200, false); - KeepAlivePduDeserializer deserializer(kaBuffer.data(), kaBuffer.size(), progress); - result = deserializer.parseData(); + KeepAlivePduDeserializer reader(kaBuffer.data(), kaBuffer.size(), progress); + result = reader.parseData(); REQUIRE(result == returnvalue::OK); - auto& progRef = deserializer.getProgress(); + auto& progRef = reader.getProgress(); // Should have been overwritten REQUIRE(progRef.getSize() == 0x50); - sz = deserializer.getWholePduSize(); + sz = reader.getWholePduSize(); // invalid max size for (size_t invalidMaxSz = 0; invalidMaxSz < sz; invalidMaxSz++) { - ReturnValue_t setResult = deserializer.setData(kaBuffer.data(), invalidMaxSz); + ReturnValue_t setResult = reader.setReadOnlyData(kaBuffer.data(), invalidMaxSz); if (setResult == returnvalue::OK) { - result = deserializer.parseData(); + result = reader.parseData(); REQUIRE(result != returnvalue::OK); } } diff --git a/unittests/cfdp/pdu/testPromptPdu.cpp b/unittests/cfdp/pdu/testPromptPdu.cpp index ffabf9a4..1efd751d 100644 --- a/unittests/cfdp/pdu/testPromptPdu.cpp +++ b/unittests/cfdp/pdu/testPromptPdu.cpp @@ -59,7 +59,7 @@ TEST_CASE("Prompt PDU", "[cfdp][pdu]") { rawBuf[2] = 2; for (size_t invalidMaxSz = 0; invalidMaxSz < sz; invalidMaxSz++) { - ReturnValue_t setResult = deserializer.setData(rawBuf.data(), invalidMaxSz); + ReturnValue_t setResult = deserializer.setReadOnlyData(rawBuf.data(), invalidMaxSz); if (setResult == returnvalue::OK) { result = deserializer.parseData(); REQUIRE(result != returnvalue::OK); From c87667c03f82f2be88e2a684b98a25be4cdae26b Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Thu, 8 Sep 2022 11:26:17 +0200 Subject: [PATCH 105/169] some API improvements --- src/fsfw/cfdp/definitions.h | 2 +- src/fsfw/cfdp/handler/DestHandler.cpp | 9 ++++++--- src/fsfw/cfdp/handler/DestHandler.h | 14 ++++++++++++-- src/fsfw/cfdp/pdu/FileDataCreator.cpp | 2 +- src/fsfw/cfdp/pdu/FileDirectiveCreator.cpp | 2 +- src/fsfw/cfdp/pdu/HeaderCreator.cpp | 6 +++--- src/fsfw/cfdp/pdu/HeaderCreator.h | 8 ++++---- src/fsfw/cfdp/pdu/HeaderReader.cpp | 4 ++-- src/fsfw/cfdp/pdu/PduHeaderIF.h | 2 +- src/fsfw/cfdp/pdu/PduHeaderReader.h | 2 +- unittests/cfdp/pdu/testCfdpHeader.cpp | 16 ++++++++-------- unittests/cfdp/pdu/testFileDirective.cpp | 2 +- unittests/cfdp/testCfdp.cpp | 2 +- 13 files changed, 42 insertions(+), 29 deletions(-) diff --git a/src/fsfw/cfdp/definitions.h b/src/fsfw/cfdp/definitions.h index 635ead17..e5c11a0b 100644 --- a/src/fsfw/cfdp/definitions.h +++ b/src/fsfw/cfdp/definitions.h @@ -49,7 +49,7 @@ enum ChecksumTypes { NULL_CHECKSUM = 15 }; -enum PduType : uint8_t { FILE_DIRECTIVE = 0, FILE_DATA = 1 }; +enum PduTypes : uint8_t { FILE_DIRECTIVE = 0, FILE_DATA = 1 }; enum TransmissionModes : uint8_t { ACKNOWLEDGED = 0, UNACKNOWLEDGED = 1 }; diff --git a/src/fsfw/cfdp/handler/DestHandler.cpp b/src/fsfw/cfdp/handler/DestHandler.cpp index 3ddf96ff..a89a5eeb 100644 --- a/src/fsfw/cfdp/handler/DestHandler.cpp +++ b/src/fsfw/cfdp/handler/DestHandler.cpp @@ -29,7 +29,7 @@ const cfdp::DestHandler::FsmResult& cfdp::DestHandler::performStateMachine() { fsmRes.resetOfIteration(); if (fsmRes.step == TransactionStep::IDLE) { for (auto infoIter = dp.packetListRef.begin(); infoIter != dp.packetListRef.end();) { - if (infoIter->pduType == PduType::FILE_DIRECTIVE and + if (infoIter->pduType == PduTypes::FILE_DIRECTIVE and infoIter->directiveType == FileDirectives::METADATA) { result = handleMetadataPdu(*infoIter); checkAndHandleError(result, errorIdx); @@ -57,12 +57,12 @@ const cfdp::DestHandler::FsmResult& cfdp::DestHandler::performStateMachine() { if (fsmRes.state == CfdpStates::BUSY_CLASS_1_NACKED) { if (fsmRes.step == TransactionStep::RECEIVING_FILE_DATA_PDUS) { for (auto infoIter = dp.packetListRef.begin(); infoIter != dp.packetListRef.end();) { - if (infoIter->pduType == PduType::FILE_DATA) { + if (infoIter->pduType == PduTypes::FILE_DATA) { result = handleFileDataPdu(*infoIter); checkAndHandleError(result, errorIdx); // Store data was deleted in PDU handler because a store guard is used dp.packetListRef.erase(infoIter++); - } else if (infoIter->pduType == PduType::FILE_DIRECTIVE and + } else if (infoIter->pduType == PduTypes::FILE_DIRECTIVE and infoIter->directiveType == FileDirectives::EOF_DIRECTIVE) { // TODO: Support for check timer missing result = handleEofPdu(*infoIter); @@ -463,3 +463,6 @@ void cfdp::DestHandler::setEventReporter(EventReportingProxyIF& reporter) { } const cfdp::DestHandlerParams& cfdp::DestHandler::getDestHandlerParams() const { return dp; } + +StorageManagerIF* cfdp::DestHandler::getTmStore() const { return fp.tcStore; } +StorageManagerIF* cfdp::DestHandler::getTcStore() const { return fp.tmStore; } diff --git a/src/fsfw/cfdp/handler/DestHandler.h b/src/fsfw/cfdp/handler/DestHandler.h index 975ccaaf..8a8dd28e 100644 --- a/src/fsfw/cfdp/handler/DestHandler.h +++ b/src/fsfw/cfdp/handler/DestHandler.h @@ -21,11 +21,11 @@ namespace cfdp { struct PacketInfo { - PacketInfo(PduType type, store_address_t storeId, + PacketInfo(PduTypes type, store_address_t storeId, std::optional directive = std::nullopt) : pduType(type), directiveType(directive), storeId(storeId) {} - PduType pduType = PduType::FILE_DATA; + PduTypes pduType = PduTypes::FILE_DATA; std::optional directiveType = FileDirectives::INVALID_DIRECTIVE; store_address_t storeId = store_address_t::invalid(); PacketInfo() = default; @@ -62,6 +62,14 @@ struct DestHandlerParams { }; struct FsfwParams { + + FsfwParams(AcceptsTelemetryIF& packetDest, MessageQueueIF* msgQueue, + EventReportingProxyIF* eventReporter, StorageManagerIF& tcStore, StorageManagerIF& tmStore) + : FsfwParams(packetDest, msgQueue, eventReporter) { + this->tcStore = &tcStore; + this->tmStore = &tmStore; + } + FsfwParams(AcceptsTelemetryIF& packetDest, MessageQueueIF* msgQueue, EventReportingProxyIF* eventReporter) : packetDest(packetDest), msgQueue(msgQueue), eventReporter(eventReporter) {} @@ -127,6 +135,8 @@ class DestHandler { [[nodiscard]] TransactionStep getTransactionStep() const; [[nodiscard]] const TransactionId& getTransactionId() const; [[nodiscard]] const DestHandlerParams& getDestHandlerParams() const; + [[nodiscard]] StorageManagerIF* getTcStore() const; + [[nodiscard]] StorageManagerIF* getTmStore() const; private: struct TransactionParams { diff --git a/src/fsfw/cfdp/pdu/FileDataCreator.cpp b/src/fsfw/cfdp/pdu/FileDataCreator.cpp index 956752fb..b9a45b5a 100644 --- a/src/fsfw/cfdp/pdu/FileDataCreator.cpp +++ b/src/fsfw/cfdp/pdu/FileDataCreator.cpp @@ -3,7 +3,7 @@ #include FileDataCreator::FileDataCreator(PduConfig& conf, FileDataInfo& info) - : HeaderCreator(conf, cfdp::PduType::FILE_DATA, 0, info.getSegmentMetadataFlag()), info(info) { + : HeaderCreator(conf, cfdp::PduTypes::FILE_DATA, 0, info.getSegmentMetadataFlag()), info(info) { update(); } diff --git a/src/fsfw/cfdp/pdu/FileDirectiveCreator.cpp b/src/fsfw/cfdp/pdu/FileDirectiveCreator.cpp index 474a1cc3..1e4da14d 100644 --- a/src/fsfw/cfdp/pdu/FileDirectiveCreator.cpp +++ b/src/fsfw/cfdp/pdu/FileDirectiveCreator.cpp @@ -2,7 +2,7 @@ FileDirectiveCreator::FileDirectiveCreator(PduConfig &pduConf, cfdp::FileDirectives directiveCode, size_t directiveParamFieldLen) - : HeaderCreator(pduConf, cfdp::PduType::FILE_DIRECTIVE, directiveParamFieldLen + 1), + : HeaderCreator(pduConf, cfdp::PduTypes::FILE_DIRECTIVE, directiveParamFieldLen + 1), directiveCode(directiveCode) {} size_t FileDirectiveCreator::getSerializedSize() const { diff --git a/src/fsfw/cfdp/pdu/HeaderCreator.cpp b/src/fsfw/cfdp/pdu/HeaderCreator.cpp index e64f8481..3c50c396 100644 --- a/src/fsfw/cfdp/pdu/HeaderCreator.cpp +++ b/src/fsfw/cfdp/pdu/HeaderCreator.cpp @@ -1,6 +1,6 @@ #include "HeaderCreator.h" -HeaderCreator::HeaderCreator(PduConfig &pduConf, cfdp::PduType pduType, size_t initPduDataFieldLen, +HeaderCreator::HeaderCreator(PduConfig &pduConf, cfdp::PduTypes pduType, size_t initPduDataFieldLen, cfdp::SegmentMetadataFlag segmentMetadataFlag, cfdp::SegmentationControl segCtrl) : pduType(pduType), @@ -65,13 +65,13 @@ void HeaderCreator::setPduDataFieldLen(size_t pduDataFieldLen_) { pduDataFieldLen = pduDataFieldLen_; } -void HeaderCreator::setPduType(cfdp::PduType pduType_) { pduType = pduType_; } +void HeaderCreator::setPduType(cfdp::PduTypes pduType_) { pduType = pduType_; } void HeaderCreator::setSegmentMetadataFlag(cfdp::SegmentMetadataFlag segmentMetadataFlag_) { segmentMetadataFlag = segmentMetadataFlag_; } -cfdp::PduType HeaderCreator::getPduType() const { return pduType; } +cfdp::PduTypes HeaderCreator::getPduType() const { return pduType; } cfdp::Direction HeaderCreator::getDirection() const { return pduConf.direction; } diff --git a/src/fsfw/cfdp/pdu/HeaderCreator.h b/src/fsfw/cfdp/pdu/HeaderCreator.h index bbb4a518..a4b5c7ff 100644 --- a/src/fsfw/cfdp/pdu/HeaderCreator.h +++ b/src/fsfw/cfdp/pdu/HeaderCreator.h @@ -9,7 +9,7 @@ class HeaderCreator : public SerializeIF, public PduHeaderIF { public: HeaderCreator( - PduConfig& pduConf, cfdp::PduType pduType, size_t initPduDataFieldLen, + PduConfig& pduConf, cfdp::PduTypes pduType, size_t initPduDataFieldLen, cfdp::SegmentMetadataFlag segmentMetadataFlag = cfdp::SegmentMetadataFlag::NOT_PRESENT, cfdp::SegmentationControl segCtrl = cfdp::SegmentationControl::NO_RECORD_BOUNDARIES_PRESERVATION); @@ -29,13 +29,13 @@ class HeaderCreator : public SerializeIF, public PduHeaderIF { Endianness streamEndianness) override; void setPduDataFieldLen(size_t pduDataFieldLen); - void setPduType(cfdp::PduType pduType); + void setPduType(cfdp::PduTypes pduType); void setSegmentMetadataFlag(cfdp::SegmentMetadataFlag); [[nodiscard]] size_t getPduDataFieldLen() const override; [[nodiscard]] size_t getWholePduSize() const override; - [[nodiscard]] cfdp::PduType getPduType() const override; + [[nodiscard]] cfdp::PduTypes getPduType() const override; [[nodiscard]] cfdp::Direction getDirection() const override; [[nodiscard]] cfdp::TransmissionModes getTransmissionMode() const override; [[nodiscard]] bool getCrcFlag() const override; @@ -52,7 +52,7 @@ class HeaderCreator : public SerializeIF, public PduHeaderIF { void getTransactionSeqNum(cfdp::TransactionSeqNum& seqNum) const override; private: - cfdp::PduType pduType; + cfdp::PduTypes pduType; cfdp::SegmentMetadataFlag segmentMetadataFlag; cfdp::SegmentationControl segmentationCtrl; size_t pduDataFieldLen; diff --git a/src/fsfw/cfdp/pdu/HeaderReader.cpp b/src/fsfw/cfdp/pdu/HeaderReader.cpp index 3417a57c..f8b19ce2 100644 --- a/src/fsfw/cfdp/pdu/HeaderReader.cpp +++ b/src/fsfw/cfdp/pdu/HeaderReader.cpp @@ -57,8 +57,8 @@ size_t PduHeaderReader::getWholePduSize() const { return getPduDataFieldLen() + PduHeaderReader::getHeaderSize(); } -cfdp::PduType PduHeaderReader::getPduType() const { - return static_cast((pointers.fixedHeader->firstByte >> 4) & 0x01); +cfdp::PduTypes PduHeaderReader::getPduType() const { + return static_cast((pointers.fixedHeader->firstByte >> 4) & 0x01); } cfdp::Direction PduHeaderReader::getDirection() const { diff --git a/src/fsfw/cfdp/pdu/PduHeaderIF.h b/src/fsfw/cfdp/pdu/PduHeaderIF.h index a8d007b6..d9e4017d 100644 --- a/src/fsfw/cfdp/pdu/PduHeaderIF.h +++ b/src/fsfw/cfdp/pdu/PduHeaderIF.h @@ -17,7 +17,7 @@ class PduHeaderIF { [[nodiscard]] virtual size_t getWholePduSize() const = 0; [[nodiscard]] virtual size_t getPduDataFieldLen() const = 0; - [[nodiscard]] virtual cfdp::PduType getPduType() const = 0; + [[nodiscard]] virtual cfdp::PduTypes getPduType() const = 0; [[nodiscard]] virtual cfdp::Direction getDirection() const = 0; [[nodiscard]] virtual cfdp::TransmissionModes getTransmissionMode() const = 0; [[nodiscard]] virtual bool getCrcFlag() const = 0; diff --git a/src/fsfw/cfdp/pdu/PduHeaderReader.h b/src/fsfw/cfdp/pdu/PduHeaderReader.h index 7809f59c..a36b2145 100644 --- a/src/fsfw/cfdp/pdu/PduHeaderReader.h +++ b/src/fsfw/cfdp/pdu/PduHeaderReader.h @@ -56,7 +56,7 @@ class PduHeaderReader : public RedirectableDataPointerIF, public PduHeaderIF { [[nodiscard]] size_t getPduDataFieldLen() const override; [[nodiscard]] size_t getWholePduSize() const override; - [[nodiscard]] cfdp::PduType getPduType() const override; + [[nodiscard]] cfdp::PduTypes getPduType() const override; [[nodiscard]] cfdp::Direction getDirection() const override; [[nodiscard]] cfdp::TransmissionModes getTransmissionMode() const override; [[nodiscard]] bool getCrcFlag() const override; diff --git a/unittests/cfdp/pdu/testCfdpHeader.cpp b/unittests/cfdp/pdu/testCfdpHeader.cpp index 6d22154b..b51450ec 100644 --- a/unittests/cfdp/pdu/testCfdpHeader.cpp +++ b/unittests/cfdp/pdu/testCfdpHeader.cpp @@ -21,7 +21,7 @@ TEST_CASE("CFDP Header", "[cfdp]") { uint8_t* serTarget = serBuf.data(); const uint8_t* deserTarget = serTarget; size_t serSize = 0; - auto creator = HeaderCreator(pduConf, cfdp::PduType::FILE_DIRECTIVE, 0); + auto creator = HeaderCreator(pduConf, cfdp::PduTypes::FILE_DIRECTIVE, 0); SECTION("Header State") { REQUIRE(seqNum.getSerializedSize() == 1); @@ -33,7 +33,7 @@ TEST_CASE("CFDP Header", "[cfdp]") { REQUIRE(creator.getLargeFileFlag() == false); REQUIRE(creator.getLenEntityIds() == 1); REQUIRE(creator.getLenSeqNum() == 1); - REQUIRE(creator.getPduType() == cfdp::PduType::FILE_DIRECTIVE); + REQUIRE(creator.getPduType() == cfdp::PduTypes::FILE_DIRECTIVE); REQUIRE(creator.getSegmentMetadataFlag() == cfdp::SegmentMetadataFlag::NOT_PRESENT); REQUIRE(creator.getSegmentationControl() == false); REQUIRE(creator.getTransmissionMode() == cfdp::TransmissionModes::ACKNOWLEDGED); @@ -87,7 +87,7 @@ TEST_CASE("CFDP Header", "[cfdp]") { pduConf.direction = cfdp::Direction::TOWARDS_SENDER; pduConf.mode = cfdp::TransmissionModes::UNACKNOWLEDGED; creator.setSegmentationControl(cfdp::SegmentationControl::RECORD_BOUNDARIES_PRESERVATION); - creator.setPduType(cfdp::PduType::FILE_DATA); + creator.setPduType(cfdp::PduTypes::FILE_DATA); creator.setSegmentMetadataFlag(cfdp::SegmentMetadataFlag::PRESENT); serTarget = serBuf.data(); serSize = 0; @@ -103,7 +103,7 @@ TEST_CASE("CFDP Header", "[cfdp]") { REQUIRE(creator.getLargeFileFlag() == true); REQUIRE(creator.getLenEntityIds() == 1); REQUIRE(creator.getLenSeqNum() == 1); - REQUIRE(creator.getPduType() == cfdp::PduType::FILE_DATA); + REQUIRE(creator.getPduType() == cfdp::PduTypes::FILE_DATA); REQUIRE(creator.getSegmentMetadataFlag() == cfdp::SegmentMetadataFlag::PRESENT); REQUIRE(creator.getTransmissionMode() == cfdp::TransmissionModes::UNACKNOWLEDGED); REQUIRE(creator.getSegmentationControl() == true); @@ -122,7 +122,7 @@ TEST_CASE("CFDP Header", "[cfdp]") { REQUIRE(creator.getLargeFileFlag() == true); REQUIRE(creator.getLenEntityIds() == 4); REQUIRE(creator.getLenSeqNum() == 2); - REQUIRE(creator.getPduType() == cfdp::PduType::FILE_DATA); + REQUIRE(creator.getPduType() == cfdp::PduTypes::FILE_DATA); REQUIRE(creator.getSegmentMetadataFlag() == cfdp::SegmentMetadataFlag::PRESENT); REQUIRE(creator.getTransmissionMode() == cfdp::TransmissionModes::UNACKNOWLEDGED); REQUIRE(creator.getSegmentationControl() == true); @@ -235,7 +235,7 @@ TEST_CASE("CFDP Header", "[cfdp]") { REQUIRE(reader.getLargeFileFlag() == false); REQUIRE(reader.getLenEntityIds() == 1); REQUIRE(reader.getLenSeqNum() == 1); - REQUIRE(reader.getPduType() == cfdp::PduType::FILE_DIRECTIVE); + REQUIRE(reader.getPduType() == cfdp::PduTypes::FILE_DIRECTIVE); REQUIRE(reader.getSegmentMetadataFlag() == cfdp::SegmentMetadataFlag::NOT_PRESENT); REQUIRE(reader.getSegmentationControl() == false); REQUIRE(reader.getTransmissionMode() == cfdp::TransmissionModes::ACKNOWLEDGED); @@ -255,7 +255,7 @@ TEST_CASE("CFDP Header", "[cfdp]") { pduConf.direction = cfdp::Direction::TOWARDS_SENDER; pduConf.mode = cfdp::TransmissionModes::UNACKNOWLEDGED; creator.setSegmentationControl(cfdp::SegmentationControl::RECORD_BOUNDARIES_PRESERVATION); - creator.setPduType(cfdp::PduType::FILE_DATA); + creator.setPduType(cfdp::PduTypes::FILE_DATA); creator.setSegmentMetadataFlag(cfdp::SegmentMetadataFlag::PRESENT); result = pduConf.seqNum.setValue(cfdp::WidthInBytes::TWO_BYTES, 0x0fff); REQUIRE(result == returnvalue::OK); @@ -278,7 +278,7 @@ TEST_CASE("CFDP Header", "[cfdp]") { REQUIRE(reader.getLargeFileFlag() == true); REQUIRE(reader.getLenEntityIds() == 4); REQUIRE(reader.getLenSeqNum() == 2); - REQUIRE(reader.getPduType() == cfdp::PduType::FILE_DATA); + REQUIRE(reader.getPduType() == cfdp::PduTypes::FILE_DATA); REQUIRE(reader.getSegmentMetadataFlag() == cfdp::SegmentMetadataFlag::PRESENT); REQUIRE(reader.getSegmentationControl() == true); REQUIRE(reader.getTransmissionMode() == cfdp::TransmissionModes::UNACKNOWLEDGED); diff --git a/unittests/cfdp/pdu/testFileDirective.cpp b/unittests/cfdp/pdu/testFileDirective.cpp index 3af8b966..cb1df08d 100644 --- a/unittests/cfdp/pdu/testFileDirective.cpp +++ b/unittests/cfdp/pdu/testFileDirective.cpp @@ -76,7 +76,7 @@ TEST_CASE("CFDP File Directive", "[cfdp][pdu]") { REQUIRE(fdDeser.getFileDirective() == FileDirectives::ACK); REQUIRE(fdDeser.getPduDataFieldLen() == 5); REQUIRE(fdDeser.getHeaderSize() == 8); - REQUIRE(fdDeser.getPduType() == cfdp::PduType::FILE_DIRECTIVE); + REQUIRE(fdDeser.getPduType() == cfdp::PduTypes::FILE_DIRECTIVE); serBuf[7] = 0xff; // Invalid file directive diff --git a/unittests/cfdp/testCfdp.cpp b/unittests/cfdp/testCfdp.cpp index 3bd474f7..2e493539 100644 --- a/unittests/cfdp/testCfdp.cpp +++ b/unittests/cfdp/testCfdp.cpp @@ -68,7 +68,7 @@ TEST_CASE("CFDP Base", "[cfdp]") { REQUIRE(fdDeser.getFileDirective() == FileDirectives::ACK); REQUIRE(fdDeser.getPduDataFieldLen() == 5); REQUIRE(fdDeser.getHeaderSize() == 8); - REQUIRE(fdDeser.getPduType() == cfdp::PduType::FILE_DIRECTIVE); + REQUIRE(fdDeser.getPduType() == cfdp::PduTypes::FILE_DIRECTIVE); serBuf[7] = 0xff; // Invalid file directive From ec1e07b466980795430497323daa220738fe6932 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Thu, 8 Sep 2022 11:53:06 +0200 Subject: [PATCH 106/169] some more returncodes --- src/fsfw/cfdp/definitions.h | 6 ++++-- src/fsfw/cfdp/handler/DestHandler.h | 4 ++-- src/fsfw/cfdp/pdu/FileDirectiveReader.cpp | 4 ++-- src/fsfw/cfdp/pdu/FileDirectiveReader.h | 3 +-- unittests/cfdp/pdu/testAckPdu.cpp | 2 +- unittests/cfdp/pdu/testFileDirective.cpp | 2 +- unittests/cfdp/testCfdp.cpp | 2 +- 7 files changed, 12 insertions(+), 11 deletions(-) diff --git a/src/fsfw/cfdp/definitions.h b/src/fsfw/cfdp/definitions.h index e5c11a0b..35c4c5f8 100644 --- a/src/fsfw/cfdp/definitions.h +++ b/src/fsfw/cfdp/definitions.h @@ -20,7 +20,7 @@ static constexpr uint8_t VERSION_BITS = CFDP_VERSION_2 << 5; static constexpr uint8_t CFDP_CLASS_ID = CLASS_ID::CFDP; static constexpr ReturnValue_t INVALID_TLV_TYPE = returnvalue::makeCode(CFDP_CLASS_ID, 1); -static constexpr ReturnValue_t INVALID_DIRECTIVE_FIELDS = returnvalue::makeCode(CFDP_CLASS_ID, 2); +static constexpr ReturnValue_t INVALID_DIRECTIVE_FIELD = returnvalue::makeCode(CFDP_CLASS_ID, 2); static constexpr ReturnValue_t INVALID_PDU_DATAFIELD_LEN = returnvalue::makeCode(CFDP_CLASS_ID, 3); static constexpr ReturnValue_t INVALID_ACK_DIRECTIVE_FIELDS = returnvalue::makeCode(CFDP_CLASS_ID, 4); @@ -30,13 +30,14 @@ static constexpr ReturnValue_t METADATA_CANT_PARSE_OPTIONS = returnvalue::makeCode(CFDP_CLASS_ID, 5); static constexpr ReturnValue_t NAK_CANT_PARSE_OPTIONS = returnvalue::makeCode(CFDP_CLASS_ID, 6); static constexpr ReturnValue_t FINISHED_CANT_PARSE_FS_RESPONSES = - returnvalue::makeCode(CFDP_CLASS_ID, 6); + returnvalue::makeCode(CFDP_CLASS_ID, 7); static constexpr ReturnValue_t FILESTORE_REQUIRES_SECOND_FILE = returnvalue::makeCode(CFDP_CLASS_ID, 8); //! Can not parse filestore response because user did not pass a valid instance //! or remaining size is invalid static constexpr ReturnValue_t FILESTORE_RESPONSE_CANT_PARSE_FS_MESSAGE = returnvalue::makeCode(CFDP_CLASS_ID, 9); +static constexpr ReturnValue_t INVALID_PDU_FORMAT = returnvalue::makeCode(CFDP_CLASS_ID, 10); //! Checksum types according to the SANA Checksum Types registry //! https://sanaregistry.org/r/checksum_identifiers/ @@ -71,6 +72,7 @@ enum WidthInBytes : uint8_t { enum FileDirectives : uint8_t { INVALID_DIRECTIVE = 0x0f, + // The _DIRECTIVE suffix is mandatory here because of some nameclash! EOF_DIRECTIVE = 0x04, FINISH = 0x05, ACK = 0x06, diff --git a/src/fsfw/cfdp/handler/DestHandler.h b/src/fsfw/cfdp/handler/DestHandler.h index 8a8dd28e..000fc2c0 100644 --- a/src/fsfw/cfdp/handler/DestHandler.h +++ b/src/fsfw/cfdp/handler/DestHandler.h @@ -62,9 +62,9 @@ struct DestHandlerParams { }; struct FsfwParams { - FsfwParams(AcceptsTelemetryIF& packetDest, MessageQueueIF* msgQueue, - EventReportingProxyIF* eventReporter, StorageManagerIF& tcStore, StorageManagerIF& tmStore) + EventReportingProxyIF* eventReporter, StorageManagerIF& tcStore, + StorageManagerIF& tmStore) : FsfwParams(packetDest, msgQueue, eventReporter) { this->tcStore = &tcStore; this->tmStore = &tmStore; diff --git a/src/fsfw/cfdp/pdu/FileDirectiveReader.cpp b/src/fsfw/cfdp/pdu/FileDirectiveReader.cpp index 5d43ebb0..748ac830 100644 --- a/src/fsfw/cfdp/pdu/FileDirectiveReader.cpp +++ b/src/fsfw/cfdp/pdu/FileDirectiveReader.cpp @@ -18,7 +18,7 @@ ReturnValue_t FileDirectiveReader::parseData() { } size_t currentIdx = PduHeaderReader::getHeaderSize(); if (not checkFileDirective(pointers.rawPtr[currentIdx])) { - return cfdp::INVALID_DIRECTIVE_FIELDS; + return cfdp::INVALID_DIRECTIVE_FIELD; } setFileDirective(static_cast(pointers.rawPtr[currentIdx])); return returnvalue::OK; @@ -32,7 +32,7 @@ size_t FileDirectiveReader::getHeaderSize() const { bool FileDirectiveReader::checkFileDirective(uint8_t rawByte) { if (rawByte < cfdp::FileDirectives::EOF_DIRECTIVE or (rawByte > cfdp::FileDirectives::PROMPT and rawByte != cfdp::FileDirectives::KEEP_ALIVE)) { - // Invalid directive field. TODO: Custom returnvalue + // Invalid directive field return false; } return true; diff --git a/src/fsfw/cfdp/pdu/FileDirectiveReader.h b/src/fsfw/cfdp/pdu/FileDirectiveReader.h index 83a71c71..5bec486c 100644 --- a/src/fsfw/cfdp/pdu/FileDirectiveReader.h +++ b/src/fsfw/cfdp/pdu/FileDirectiveReader.h @@ -26,10 +26,9 @@ class FileDirectiveReader : public PduHeaderReader { void setEndianness(SerializeIF::Endianness endianness); [[nodiscard]] SerializeIF::Endianness getEndianness() const; - - protected: static bool checkFileDirective(uint8_t rawByte); + protected: private: void setFileDirective(cfdp::FileDirectives fileDirective); cfdp::FileDirectives fileDirective = cfdp::FileDirectives::INVALID_DIRECTIVE; diff --git a/unittests/cfdp/pdu/testAckPdu.cpp b/unittests/cfdp/pdu/testAckPdu.cpp index 1eb1b340..02832d9f 100644 --- a/unittests/cfdp/pdu/testAckPdu.cpp +++ b/unittests/cfdp/pdu/testAckPdu.cpp @@ -91,7 +91,7 @@ TEST_CASE("ACK PDU", "[cfdp][pdu]") { buf[sz - 2] = prevVal; buf[sz - 3] = cfdp::FileDirectives::INVALID_DIRECTIVE; result = reader2.parseData(); - REQUIRE(result == cfdp::INVALID_DIRECTIVE_FIELDS); + REQUIRE(result == cfdp::INVALID_DIRECTIVE_FIELD); buf[sz - 3] = cfdp::FileDirectives::ACK; auto maxSizeTooSmall = AckPduDeserializer(buf.data(), sz - 2, ackInfo2); result = maxSizeTooSmall.parseData(); diff --git a/unittests/cfdp/pdu/testFileDirective.cpp b/unittests/cfdp/pdu/testFileDirective.cpp index cb1df08d..31e627a6 100644 --- a/unittests/cfdp/pdu/testFileDirective.cpp +++ b/unittests/cfdp/pdu/testFileDirective.cpp @@ -80,6 +80,6 @@ TEST_CASE("CFDP File Directive", "[cfdp][pdu]") { serBuf[7] = 0xff; // Invalid file directive - REQUIRE(fdDeser.parseData() == cfdp::INVALID_DIRECTIVE_FIELDS); + REQUIRE(fdDeser.parseData() == cfdp::INVALID_DIRECTIVE_FIELD); } } \ No newline at end of file diff --git a/unittests/cfdp/testCfdp.cpp b/unittests/cfdp/testCfdp.cpp index 2e493539..38504a5b 100644 --- a/unittests/cfdp/testCfdp.cpp +++ b/unittests/cfdp/testCfdp.cpp @@ -72,7 +72,7 @@ TEST_CASE("CFDP Base", "[cfdp]") { serBuf[7] = 0xff; // Invalid file directive - REQUIRE(fdDeser.parseData() == cfdp::INVALID_DIRECTIVE_FIELDS); + REQUIRE(fdDeser.parseData() == cfdp::INVALID_DIRECTIVE_FIELD); } SECTION("File Size") { From b73754dfd62ec61410160beca8562a558c6e89cc Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Thu, 8 Sep 2022 12:07:16 +0200 Subject: [PATCH 107/169] implemented basic PDU forwarding --- ...AckPduSerializer.cpp => AckPduCreator.cpp} | 12 ++++----- .../{AckPduSerializer.h => AckPduCreator.h} | 12 ++++----- ...ckPduDeserializer.cpp => AckPduReader.cpp} | 26 ++++++++++++------- .../{AckPduDeserializer.h => AckPduReader.h} | 9 ++++--- src/fsfw/cfdp/pdu/CMakeLists.txt | 4 +-- unittests/cfdp/pdu/testAckPdu.cpp | 18 ++++++------- 6 files changed, 45 insertions(+), 36 deletions(-) rename src/fsfw/cfdp/pdu/{AckPduSerializer.cpp => AckPduCreator.cpp} (72%) rename src/fsfw/cfdp/pdu/{AckPduSerializer.h => AckPduCreator.h} (62%) rename src/fsfw/cfdp/pdu/{AckPduDeserializer.cpp => AckPduReader.cpp} (52%) rename src/fsfw/cfdp/pdu/{AckPduDeserializer.h => AckPduReader.h} (59%) diff --git a/src/fsfw/cfdp/pdu/AckPduSerializer.cpp b/src/fsfw/cfdp/pdu/AckPduCreator.cpp similarity index 72% rename from src/fsfw/cfdp/pdu/AckPduSerializer.cpp rename to src/fsfw/cfdp/pdu/AckPduCreator.cpp index 67744171..88fcedc9 100644 --- a/src/fsfw/cfdp/pdu/AckPduSerializer.cpp +++ b/src/fsfw/cfdp/pdu/AckPduCreator.cpp @@ -1,14 +1,12 @@ -#include "AckPduSerializer.h" +#include "AckPduCreator.h" -AckPduSerializer::AckPduSerializer(AckInfo &ackInfo, PduConfig &pduConf) +AckPduCreator::AckPduCreator(AckInfo &ackInfo, PduConfig &pduConf) : FileDirectiveCreator(pduConf, cfdp::FileDirectives::ACK, 2), ackInfo(ackInfo) {} -size_t AckPduSerializer::getSerializedSize() const { - return FileDirectiveCreator::getWholePduSize(); -} +size_t AckPduCreator::getSerializedSize() const { return FileDirectiveCreator::getWholePduSize(); } -ReturnValue_t AckPduSerializer::serialize(uint8_t **buffer, size_t *size, size_t maxSize, - Endianness streamEndianness) const { +ReturnValue_t AckPduCreator::serialize(uint8_t **buffer, size_t *size, size_t maxSize, + Endianness streamEndianness) const { ReturnValue_t result = FileDirectiveCreator::serialize(buffer, size, maxSize, streamEndianness); if (result != returnvalue::OK) { return result; diff --git a/src/fsfw/cfdp/pdu/AckPduSerializer.h b/src/fsfw/cfdp/pdu/AckPduCreator.h similarity index 62% rename from src/fsfw/cfdp/pdu/AckPduSerializer.h rename to src/fsfw/cfdp/pdu/AckPduCreator.h index 92014e4e..c0a89cc3 100644 --- a/src/fsfw/cfdp/pdu/AckPduSerializer.h +++ b/src/fsfw/cfdp/pdu/AckPduCreator.h @@ -1,11 +1,11 @@ -#ifndef FSFW_SRC_FSFW_CFDP_PDU_ACKPDUSERIALIZER_H_ -#define FSFW_SRC_FSFW_CFDP_PDU_ACKPDUSERIALIZER_H_ +#ifndef FSFW_CFDP_PDU_ACKPDUSERIALIZER_H_ +#define FSFW_CFDP_PDU_ACKPDUSERIALIZER_H_ #include "AckInfo.h" #include "FileDirectiveCreator.h" #include "FileDirectiveReader.h" -class AckPduSerializer : public FileDirectiveCreator { +class AckPduCreator : public FileDirectiveCreator { public: /** * @brief Serializer to pack ACK PDUs @@ -16,9 +16,9 @@ class AckPduSerializer : public FileDirectiveCreator { * @param transactionStatus * @param pduConf */ - AckPduSerializer(AckInfo& ackInfo, PduConfig& pduConf); + AckPduCreator(AckInfo& ackInfo, PduConfig& pduConf); - size_t getSerializedSize() const override; + [[nodiscard]] size_t getSerializedSize() const override; ReturnValue_t serialize(uint8_t** buffer, size_t* size, size_t maxSize, Endianness streamEndianness) const override; @@ -27,4 +27,4 @@ class AckPduSerializer : public FileDirectiveCreator { AckInfo& ackInfo; }; -#endif /* FSFW_SRC_FSFW_CFDP_PDU_ACKPDUSERIALIZER_H_ */ +#endif /* FSFW_CFDP_PDU_ACKPDUSERIALIZER_H_ */ diff --git a/src/fsfw/cfdp/pdu/AckPduDeserializer.cpp b/src/fsfw/cfdp/pdu/AckPduReader.cpp similarity index 52% rename from src/fsfw/cfdp/pdu/AckPduDeserializer.cpp rename to src/fsfw/cfdp/pdu/AckPduReader.cpp index f09db97e..4f75a2b8 100644 --- a/src/fsfw/cfdp/pdu/AckPduDeserializer.cpp +++ b/src/fsfw/cfdp/pdu/AckPduReader.cpp @@ -1,9 +1,9 @@ -#include "AckPduDeserializer.h" +#include "AckPduReader.h" -AckPduDeserializer::AckPduDeserializer(const uint8_t* pduBuf, size_t maxSize, AckInfo& info) +AckPduReader::AckPduReader(const uint8_t* pduBuf, size_t maxSize, AckInfo& info) : FileDirectiveReader(pduBuf, maxSize), info(info) {} -ReturnValue_t AckPduDeserializer::parseData() { +ReturnValue_t AckPduReader::parseData() { ReturnValue_t result = FileDirectiveReader::parseData(); if (result != returnvalue::OK) { return result; @@ -18,14 +18,12 @@ ReturnValue_t AckPduDeserializer::parseData() { return returnvalue::OK; } -bool AckPduDeserializer::checkAndSetCodes(uint8_t firstByte, uint8_t secondByte) { - uint8_t ackedDirective = static_cast(firstByte >> 4); - - if (ackedDirective != cfdp::FileDirectives::EOF_DIRECTIVE and - ackedDirective != cfdp::FileDirectives::FINISH) { +bool AckPduReader::checkAndSetCodes(uint8_t firstByte, uint8_t secondByte) { + cfdp::FileDirectives directive; + if (not checkAckedDirectiveField(firstByte, directive)) { return false; } - this->info.setAckedDirective(static_cast(ackedDirective)); + this->info.setAckedDirective(directive); uint8_t directiveSubtypeCode = firstByte & 0x0f; if (directiveSubtypeCode != 0b0000 and directiveSubtypeCode != 0b0001) { return false; @@ -35,3 +33,13 @@ bool AckPduDeserializer::checkAndSetCodes(uint8_t firstByte, uint8_t secondByte) this->info.setTransactionStatus(static_cast(secondByte & 0x0f)); return true; } +bool AckPduReader::checkAckedDirectiveField(uint8_t firstPduDataByte, + cfdp::FileDirectives& ackedDirective) { + uint8_t ackedDirectiveRaw = static_cast(firstPduDataByte >> 4); + if (ackedDirectiveRaw != cfdp::FileDirectives::EOF_DIRECTIVE and + ackedDirectiveRaw != cfdp::FileDirectives::FINISH) { + return false; + } + ackedDirective = (static_cast(ackedDirectiveRaw)); + return true; +} diff --git a/src/fsfw/cfdp/pdu/AckPduDeserializer.h b/src/fsfw/cfdp/pdu/AckPduReader.h similarity index 59% rename from src/fsfw/cfdp/pdu/AckPduDeserializer.h rename to src/fsfw/cfdp/pdu/AckPduReader.h index 4da50261..2b5dd411 100644 --- a/src/fsfw/cfdp/pdu/AckPduDeserializer.h +++ b/src/fsfw/cfdp/pdu/AckPduReader.h @@ -4,16 +4,19 @@ #include "AckInfo.h" #include "fsfw/cfdp/pdu/FileDirectiveReader.h" -class AckPduDeserializer : public FileDirectiveReader { +class AckPduReader : public FileDirectiveReader { public: - AckPduDeserializer(const uint8_t* pduBuf, size_t maxSize, AckInfo& info); + AckPduReader(const uint8_t* pduBuf, size_t maxSize, AckInfo& info); /** * * @return * - cfdp::INVALID_DIRECTIVE_FIELDS: Invalid fields */ - ReturnValue_t parseData(); + ReturnValue_t parseData() override; + + static bool checkAckedDirectiveField(uint8_t firstPduDataByte, + cfdp::FileDirectives& ackedDirective); private: bool checkAndSetCodes(uint8_t rawAckedByte, uint8_t rawAckedConditionCode); diff --git a/src/fsfw/cfdp/pdu/CMakeLists.txt b/src/fsfw/cfdp/pdu/CMakeLists.txt index a8f0b5a9..22ac76c7 100644 --- a/src/fsfw/cfdp/pdu/CMakeLists.txt +++ b/src/fsfw/cfdp/pdu/CMakeLists.txt @@ -6,8 +6,8 @@ target_sources( FileDirectiveReader.cpp FileDirectiveCreator.cpp AckInfo.cpp - AckPduSerializer.cpp - AckPduDeserializer.cpp + AckPduCreator.cpp + AckPduReader.cpp EofInfo.cpp EofPduCreator.cpp EofPduReader.cpp diff --git a/unittests/cfdp/pdu/testAckPdu.cpp b/unittests/cfdp/pdu/testAckPdu.cpp index 02832d9f..44b66bd5 100644 --- a/unittests/cfdp/pdu/testAckPdu.cpp +++ b/unittests/cfdp/pdu/testAckPdu.cpp @@ -1,8 +1,8 @@ #include #include -#include "fsfw/cfdp/pdu/AckPduDeserializer.h" -#include "fsfw/cfdp/pdu/AckPduSerializer.h" +#include "fsfw/cfdp/pdu/AckPduCreator.h" +#include "fsfw/cfdp/pdu/AckPduReader.h" #include "fsfw/globalfunctions/arrayprinter.h" TEST_CASE("ACK PDU", "[cfdp][pdu]") { @@ -18,7 +18,7 @@ TEST_CASE("ACK PDU", "[cfdp][pdu]") { auto pduConf = PduConfig(sourceId, destId, TransmissionModes::ACKNOWLEDGED, seqNum); AckInfo ackInfo(FileDirectives::EOF_DIRECTIVE, ConditionCode::NO_ERROR, AckTransactionStatus::ACTIVE); - auto ackSerializer = AckPduSerializer(ackInfo, pduConf); + auto ackSerializer = AckPduCreator(ackInfo, pduConf); result = ackSerializer.serialize(&bufptr, &sz, maxsz, SerializeIF::Endianness::NETWORK); REQUIRE(result == returnvalue::OK); @@ -30,7 +30,7 @@ TEST_CASE("ACK PDU", "[cfdp][pdu]") { ackInfo.setAckedDirective(FileDirectives::FINISH); ackInfo.setAckedConditionCode(ConditionCode::FILESTORE_REJECTION); ackInfo.setTransactionStatus(AckTransactionStatus::TERMINATED); - auto ackSerializer2 = AckPduSerializer(ackInfo, pduConf); + auto ackSerializer2 = AckPduCreator(ackInfo, pduConf); bufptr = buf.data(); sz = 0; result = ackSerializer2.serialize(&bufptr, &sz, maxsz, SerializeIF::Endianness::NETWORK); @@ -44,7 +44,7 @@ TEST_CASE("ACK PDU", "[cfdp][pdu]") { bufptr = buf.data(); sz = 0; ackInfo.setAckedDirective(FileDirectives::KEEP_ALIVE); - auto ackSerializer3 = AckPduSerializer(ackInfo, pduConf); + auto ackSerializer3 = AckPduCreator(ackInfo, pduConf); result = ackSerializer3.serialize(&bufptr, &sz, maxsz, SerializeIF::Endianness::NETWORK); // Invalid file directive REQUIRE(result != returnvalue::OK); @@ -57,7 +57,7 @@ TEST_CASE("ACK PDU", "[cfdp][pdu]") { SECTION("Deserialize") { AckInfo ackInfo2; - auto reader = AckPduDeserializer(buf.data(), sz, ackInfo2); + auto reader = AckPduReader(buf.data(), sz, ackInfo2); result = reader.parseData(); REQUIRE(result == returnvalue::OK); REQUIRE(ackInfo2.getAckedDirective() == FileDirectives::EOF_DIRECTIVE); @@ -67,13 +67,13 @@ TEST_CASE("ACK PDU", "[cfdp][pdu]") { AckInfo newInfo = AckInfo(FileDirectives::FINISH, ConditionCode::FILESTORE_REJECTION, AckTransactionStatus::TERMINATED); - auto ackSerializer2 = AckPduSerializer(newInfo, pduConf); + auto ackSerializer2 = AckPduCreator(newInfo, pduConf); bufptr = buf.data(); sz = 0; result = ackSerializer2.serialize(&bufptr, &sz, maxsz, SerializeIF::Endianness::NETWORK); REQUIRE(result == returnvalue::OK); - auto reader2 = AckPduDeserializer(buf.data(), sz, ackInfo2); + auto reader2 = AckPduReader(buf.data(), sz, ackInfo2); result = reader2.parseData(); REQUIRE(result == returnvalue::OK); REQUIRE(ackInfo2.getAckedDirective() == FileDirectives::FINISH); @@ -93,7 +93,7 @@ TEST_CASE("ACK PDU", "[cfdp][pdu]") { result = reader2.parseData(); REQUIRE(result == cfdp::INVALID_DIRECTIVE_FIELD); buf[sz - 3] = cfdp::FileDirectives::ACK; - auto maxSizeTooSmall = AckPduDeserializer(buf.data(), sz - 2, ackInfo2); + auto maxSizeTooSmall = AckPduReader(buf.data(), sz - 2, ackInfo2); result = maxSizeTooSmall.parseData(); REQUIRE(result == SerializeIF::STREAM_TOO_SHORT); } From 34dd478848cc43bf9520d366207f20bdfe2c4962 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Thu, 8 Sep 2022 16:25:19 +0200 Subject: [PATCH 108/169] helper class OneRemoteConfigProvider --- src/fsfw/cfdp/VarLenFields.cpp | 4 ++++ src/fsfw/cfdp/VarLenFields.h | 1 + src/fsfw/cfdp/handler/RemoteConfigTableIF.h | 19 +++++++++++++++++++ 3 files changed, 24 insertions(+) diff --git a/src/fsfw/cfdp/VarLenFields.cpp b/src/fsfw/cfdp/VarLenFields.cpp index 512c713c..b9e0b3a8 100644 --- a/src/fsfw/cfdp/VarLenFields.cpp +++ b/src/fsfw/cfdp/VarLenFields.cpp @@ -131,3 +131,7 @@ bool cfdp::VarLenField::operator<(const cfdp::VarLenField &other) const { bool cfdp::VarLenField::operator==(const cfdp::VarLenField &other) const { return getWidth() == other.getWidth() and getValue() == other.getValue(); } + +bool cfdp::VarLenField::operator!=(const cfdp::VarLenField &other) const { + return not(*this == other); +} diff --git a/src/fsfw/cfdp/VarLenFields.h b/src/fsfw/cfdp/VarLenFields.h index 03664995..37a9cf5c 100644 --- a/src/fsfw/cfdp/VarLenFields.h +++ b/src/fsfw/cfdp/VarLenFields.h @@ -27,6 +27,7 @@ class VarLenField : public SerializeIF { VarLenField(cfdp::WidthInBytes width, size_t value); bool operator==(const VarLenField &other) const; + bool operator!=(const VarLenField &other) const; bool operator<(const VarLenField &other) const; ReturnValue_t setValue(cfdp::WidthInBytes, size_t value); diff --git a/src/fsfw/cfdp/handler/RemoteConfigTableIF.h b/src/fsfw/cfdp/handler/RemoteConfigTableIF.h index 1cd1ec1d..d0e6121d 100644 --- a/src/fsfw/cfdp/handler/RemoteConfigTableIF.h +++ b/src/fsfw/cfdp/handler/RemoteConfigTableIF.h @@ -11,6 +11,25 @@ class RemoteConfigTableIF { virtual bool getRemoteCfg(const cfdp::EntityId& remoteId, cfdp::RemoteEntityCfg** cfg) = 0; }; +/** + * Helper class for the common case that there is exactly one remote entity + */ +class OneRemoteConfigProvider : public RemoteConfigTableIF { + public: + explicit OneRemoteConfigProvider(RemoteEntityCfg cfg) : cfg(std::move(cfg)) {} + + bool getRemoteCfg(const EntityId& remoteId, cfdp::RemoteEntityCfg** cfg_) override { + if (remoteId != cfg.remoteId) { + return false; + } + *cfg_ = &cfg; + return true; + } + + private: + RemoteEntityCfg cfg; +}; + } // namespace cfdp #endif // FSFW_CFDP_HANDLER_REMOTECONFIGTABLEIF_H From 3e9b47d3a2ea4cf0407ecae8fbac1ef9feee7d1e Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Mon, 12 Sep 2022 15:12:26 +0200 Subject: [PATCH 109/169] update docs release in conf.py --- docs/conf.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/conf.py b/docs/conf.py index a2cb73be..700b0ee9 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -22,7 +22,7 @@ copyright = "2021, Institute of Space Systems (IRS)" author = "Institute of Space Systems (IRS)" # The full version, including alpha/beta/rc tags -release = "2.0.1" +release = "5.0.0" # -- General configuration --------------------------------------------------- From 26b3e5a013726d86dfa5c64ec784499c763f143e Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Mon, 12 Sep 2022 15:14:42 +0200 Subject: [PATCH 110/169] fix misc def config --- misc/defaultcfg/fsfwconfig/objects/FsfwFactory.cpp | 5 ----- 1 file changed, 5 deletions(-) diff --git a/misc/defaultcfg/fsfwconfig/objects/FsfwFactory.cpp b/misc/defaultcfg/fsfwconfig/objects/FsfwFactory.cpp index 4d6e91f1..85a733b4 100644 --- a/misc/defaultcfg/fsfwconfig/objects/FsfwFactory.cpp +++ b/misc/defaultcfg/fsfwconfig/objects/FsfwFactory.cpp @@ -4,7 +4,6 @@ #include #include #include -#include #include #include #include @@ -41,13 +40,9 @@ void Factory::setStaticFrameworkObjectIds() { CommandingServiceBase::defaultPacketSource = objects::NO_OBJECT; CommandingServiceBase::defaultPacketDestination = objects::NO_OBJECT; - VerificationReporter::messageReceiver = objects::PUS_SERVICE_1_VERIFICATION; - DeviceHandlerBase::powerSwitcherId = objects::NO_OBJECT; DeviceHandlerBase::rawDataReceiverId = objects::PUS_SERVICE_2_DEVICE_ACCESS; DeviceHandlerFailureIsolation::powerConfirmationId = objects::NO_OBJECT; - - TmPacketBase::timeStamperId = objects::NO_OBJECT; } From a1ea671e2fb91b1e2e6b0d904e9b81701db29e28 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Tue, 13 Sep 2022 14:46:41 +0200 Subject: [PATCH 111/169] header include update --- src/fsfw/tcdistribution/TcDistributorBase.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/fsfw/tcdistribution/TcDistributorBase.cpp b/src/fsfw/tcdistribution/TcDistributorBase.cpp index f87993f8..a561b465 100644 --- a/src/fsfw/tcdistribution/TcDistributorBase.cpp +++ b/src/fsfw/tcdistribution/TcDistributorBase.cpp @@ -1,4 +1,4 @@ -#include "fsfw/tcdistribution/TcDistributorBase.h" +#include "TcDistributorBase.h" #include "definitions.h" #include "fsfw/ipc/QueueFactory.h" From 382543fc5989c6608e0aa7550ace6aa70f7d78e3 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Tue, 13 Sep 2022 15:26:14 +0200 Subject: [PATCH 112/169] important bugfix --- src/fsfw/cfdp/handler/DestHandler.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/fsfw/cfdp/handler/DestHandler.cpp b/src/fsfw/cfdp/handler/DestHandler.cpp index a89a5eeb..c4566814 100644 --- a/src/fsfw/cfdp/handler/DestHandler.cpp +++ b/src/fsfw/cfdp/handler/DestHandler.cpp @@ -464,5 +464,5 @@ void cfdp::DestHandler::setEventReporter(EventReportingProxyIF& reporter) { const cfdp::DestHandlerParams& cfdp::DestHandler::getDestHandlerParams() const { return dp; } -StorageManagerIF* cfdp::DestHandler::getTmStore() const { return fp.tcStore; } -StorageManagerIF* cfdp::DestHandler::getTcStore() const { return fp.tmStore; } +StorageManagerIF* cfdp::DestHandler::getTmStore() const { return fp.tmStore; } +StorageManagerIF* cfdp::DestHandler::getTcStore() const { return fp.tcStore; } From 44615c150b7690a3beccf459e3203561f17edf0a Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Wed, 14 Sep 2022 14:00:20 +0200 Subject: [PATCH 113/169] add printout capabilities --- src/fsfw/cfdp/VarLenFields.h | 15 ++++++++ src/fsfw/cfdp/handler/DestHandler.cpp | 38 ++++++++++++------- src/fsfw/cfdp/handler/mib.h | 1 + .../ServiceInterfaceBuffer.cpp | 1 - src/fsfw_hal/common/CMakeLists.txt | 2 +- src/fsfw_hal/common/printChar.c | 2 +- 6 files changed, 43 insertions(+), 16 deletions(-) diff --git a/src/fsfw/cfdp/VarLenFields.h b/src/fsfw/cfdp/VarLenFields.h index 37a9cf5c..37602c75 100644 --- a/src/fsfw/cfdp/VarLenFields.h +++ b/src/fsfw/cfdp/VarLenFields.h @@ -7,6 +7,7 @@ #include "fsfw/cfdp/definitions.h" #include "fsfw/serialize/SerializeIF.h" +#include "fsfw/serviceinterface.h" #include "fsfw/util/UnsignedByteField.h" namespace cfdp { @@ -43,6 +44,14 @@ class VarLenField : public SerializeIF { [[nodiscard]] cfdp::WidthInBytes getWidth() const; [[nodiscard]] size_t getValue() const; +#if FSFW_CPP_OSTREAM_ENABLED == 1 + friend std::ostream &operator<<(std::ostream &os, const VarLenField &id) { + os << "dec: " << id.getValue() << ", hex: " << std::hex << std::setw(id.getWidth()) + << std::setfill('0') << id.getValue() << std::dec << std::setfill('0'); + return os; + } +#endif + private: ReturnValue_t deSerialize(const uint8_t **buffer, size_t *size, Endianness streamEndianness) override; @@ -83,6 +92,12 @@ struct TransactionId { return entityId == other.entityId and seqNum == other.seqNum; } +#if FSFW_CPP_OSTREAM_ENABLED == 1 + friend std::ostream &operator<<(std::ostream &os, const TransactionId &id) { + os << "Source ID { " << id.entityId << " }, Sequence Number " << id.seqNum.getValue(); + return os; + } +#endif EntityId entityId; TransactionSeqNum seqNum; }; diff --git a/src/fsfw/cfdp/handler/DestHandler.cpp b/src/fsfw/cfdp/handler/DestHandler.cpp index c4566814..d43d1482 100644 --- a/src/fsfw/cfdp/handler/DestHandler.cpp +++ b/src/fsfw/cfdp/handler/DestHandler.cpp @@ -252,7 +252,8 @@ ReturnValue_t cfdp::DestHandler::handleMetadataParseError(ReturnValue_t result, headerReader.getDestId(destId); RemoteEntityCfg* remoteCfg; if (not dp.remoteCfgTable.getRemoteCfg(destId, &remoteCfg)) { -// TODO: No remote config for dest ID. I consider this a configuration error. +// TODO: No remote config for dest ID. I consider this a configuration error, which is not +// covered by the standard. // Warning or error, yield or cache appropriate returnvalue #if FSFW_CPP_OSTREAM_ENABLED == 1 sif::warning << "No remote config exists for destination ID" << std::endl; @@ -267,8 +268,9 @@ ReturnValue_t cfdp::DestHandler::handleMetadataParseError(ReturnValue_t result, ReturnValue_t cfdp::DestHandler::startTransaction(MetadataPduReader& reader, MetadataInfo& info) { if (fsmRes.state != CfdpStates::IDLE) { // According to standard, discard metadata PDU if we are busy - return returnvalue::OK; + return OK; } + ReturnValue_t result = OK; fsmRes.step = TransactionStep::TRANSACTION_START; if (reader.getTransmissionMode() == TransmissionModes::UNACKNOWLEDGED) { fsmRes.state = CfdpStates::BUSY_CLASS_1_NACKED; @@ -302,10 +304,26 @@ ReturnValue_t cfdp::DestHandler::startTransaction(MetadataPduReader& reader, Met #if FSFW_CPP_OSTREAM_ENABLED == 1 sif::warning << "cfdp::DestHandler" << __func__ << ": No remote configuration found for destination ID " - << tp.pduConf.destId.getValue() << std::endl; + << tp.pduConf.sourceId.getValue() << std::endl; #endif return FAILED; } + // If both dest name size and source name size are 0, we are dealing with a metadata only PDU, + // so there is no need to create a file or truncate an existing file + if (destNameSize > 0 and sourceNameSize > 0) { + FilesystemParams fparams(tp.destName.data()); + // TODO: Filesystem errors? + if (dp.user.vfs.fileExists(fparams)) { + dp.user.vfs.truncateFile(fparams); + } else { + result = dp.user.vfs.createFile(fparams); + if (result != OK) { + // TODO: Handle FS error. This is probably a case for the filestore rejection mechanism of + // CFDP. + // In any case, it does not really make sense to continue here + } + } + } fsmRes.step = TransactionStep::RECEIVING_FILE_DATA_PDUS; MetadataRecvdParams params(tp.transactionId, tp.pduConf.sourceId); params.fileSize = tp.fileSize.getSize(); @@ -313,15 +331,8 @@ ReturnValue_t cfdp::DestHandler::startTransaction(MetadataPduReader& reader, Met params.sourceFileName = tp.sourceName.data(); params.msgsToUserArray = dynamic_cast(userTlvVec.data()); params.msgsToUserLen = info.getOptionsLen(); - FilesystemParams fparams(tp.destName.data()); - // TODO: Filesystem errors? - if (dp.user.vfs.fileExists(fparams)) { - dp.user.vfs.truncateFile(fparams); - } else { - dp.user.vfs.createFile(fparams); - } dp.user.metadataRecvdIndication(params); - return OK; + return result; } cfdp::CfdpStates cfdp::DestHandler::getCfdpState() const { return fsmRes.state; } @@ -376,7 +387,8 @@ ReturnValue_t cfdp::DestHandler::checksumVerification() { params.size = readLen; auto result = dp.user.vfs.readFromFile(params, buf.data(), buf.size()); if (result != OK) { - // TODO: Better error handling + // TODO: I think this is a case for a filestore rejection, but it might sense to print + // a warning or trigger an event because this should generally not happen return FAILED; } crcCalc.add(buf.begin(), buf.begin() + readLen); @@ -391,7 +403,7 @@ ReturnValue_t cfdp::DestHandler::checksumVerification() { } else { // TODO: Proper error handling #if FSFW_CPP_OSTREAM_ENABLED == 1 - sif::error << "CRC check for file " << tp.sourceName.data() << " failed" << std::endl; + sif::warning << "CRC check for file " << tp.destName.data() << " failed" << std::endl; #endif tp.conditionCode = ConditionCode::FILE_CHECKSUM_FAILURE; } diff --git a/src/fsfw/cfdp/handler/mib.h b/src/fsfw/cfdp/handler/mib.h index 3b4c95e4..76284f2d 100644 --- a/src/fsfw/cfdp/handler/mib.h +++ b/src/fsfw/cfdp/handler/mib.h @@ -27,6 +27,7 @@ struct LocalEntityCfg { }; struct RemoteEntityCfg { + explicit RemoteEntityCfg(EntityId id) : remoteId(std::move(id)) {} EntityId remoteId; size_t maxFileSegmentLen = 2048; bool closureRequested = false; diff --git a/src/fsfw/serviceinterface/ServiceInterfaceBuffer.cpp b/src/fsfw/serviceinterface/ServiceInterfaceBuffer.cpp index 23892dcc..0e73be83 100644 --- a/src/fsfw/serviceinterface/ServiceInterfaceBuffer.cpp +++ b/src/fsfw/serviceinterface/ServiceInterfaceBuffer.cpp @@ -3,7 +3,6 @@ #if FSFW_CPP_OSTREAM_ENABLED == 1 #include - #include #include "fsfw/serviceinterface/serviceInterfaceDefintions.h" diff --git a/src/fsfw_hal/common/CMakeLists.txt b/src/fsfw_hal/common/CMakeLists.txt index 1cd9c678..2f4608f8 100644 --- a/src/fsfw_hal/common/CMakeLists.txt +++ b/src/fsfw_hal/common/CMakeLists.txt @@ -1,3 +1,3 @@ add_subdirectory(gpio) -target_sources(${LIB_FSFW_NAME} PRIVATE printChar.c) \ No newline at end of file +target_sources(${LIB_FSFW_NAME} PRIVATE printChar.c) diff --git a/src/fsfw_hal/common/printChar.c b/src/fsfw_hal/common/printChar.c index 6e02c1df..24fba5c8 100644 --- a/src/fsfw_hal/common/printChar.c +++ b/src/fsfw_hal/common/printChar.c @@ -1,5 +1,5 @@ -#include #include +#include void __attribute__((weak)) printChar(const char* character, bool errStream) { if (errStream) { From ac7dc55fc1061e8cba20a93e415037b7db135946 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Wed, 14 Sep 2022 19:07:17 +0200 Subject: [PATCH 114/169] fix unittest --- unittests/cfdp/handler/testDestHandler.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/unittests/cfdp/handler/testDestHandler.cpp b/unittests/cfdp/handler/testDestHandler.cpp index 20ddf678..30bb9fc5 100644 --- a/unittests/cfdp/handler/testDestHandler.cpp +++ b/unittests/cfdp/handler/testDestHandler.cpp @@ -39,8 +39,7 @@ TEST_CASE("CFDP Dest Handler", "[cfdp]") { StorageManagerMock tcStore(2, storeCfg); StorageManagerMock tmStore(3, storeCfg); FsfwParams fp(tmReceiver, &mqMock, &eventReporterMock); - RemoteEntityCfg cfg; - cfg.remoteId = remoteId; + RemoteEntityCfg cfg(remoteId); remoteCfgTableMock.addRemoteConfig(cfg); fp.tcStore = &tcStore; fp.tmStore = &tmStore; From 3a524549491f875d7356c6b996ecb4c5bbc28606 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Wed, 14 Sep 2022 19:15:52 +0200 Subject: [PATCH 115/169] removed handlers --- src/fsfw/cfdp.h | 1 - src/fsfw/cfdp/handler/CMakeLists.txt | 3 +- src/fsfw/cfdp/handler/DestHandler.cpp | 480 ------------------- src/fsfw/cfdp/handler/DestHandler.h | 202 -------- src/fsfw/cfdp/handler/SourceHandler.cpp | 1 - src/fsfw/cfdp/handler/SourceHandler.h | 6 - unittests/cfdp/handler/CMakeLists.txt | 5 +- unittests/cfdp/handler/testDestHandler.cpp | 244 ---------- unittests/cfdp/handler/testSourceHandler.cpp | 3 - unittests/cfdp/testLvs.cpp | 1 + unittests/cfdp/testTlv.cpp | 1 + 11 files changed, 5 insertions(+), 942 deletions(-) delete mode 100644 src/fsfw/cfdp/handler/DestHandler.cpp delete mode 100644 src/fsfw/cfdp/handler/DestHandler.h delete mode 100644 src/fsfw/cfdp/handler/SourceHandler.cpp delete mode 100644 src/fsfw/cfdp/handler/SourceHandler.h delete mode 100644 unittests/cfdp/handler/testDestHandler.cpp delete mode 100644 unittests/cfdp/handler/testSourceHandler.cpp diff --git a/src/fsfw/cfdp.h b/src/fsfw/cfdp.h index 28ddfec2..86086432 100644 --- a/src/fsfw/cfdp.h +++ b/src/fsfw/cfdp.h @@ -2,7 +2,6 @@ #define FSFW_CFDP_H #include "cfdp/definitions.h" -#include "cfdp/handler/DestHandler.h" #include "cfdp/handler/FaultHandlerBase.h" #include "cfdp/tlv/Lv.h" #include "cfdp/tlv/StringLv.h" diff --git a/src/fsfw/cfdp/handler/CMakeLists.txt b/src/fsfw/cfdp/handler/CMakeLists.txt index 7ad995c0..90130806 100644 --- a/src/fsfw/cfdp/handler/CMakeLists.txt +++ b/src/fsfw/cfdp/handler/CMakeLists.txt @@ -1,2 +1 @@ -target_sources(${LIB_FSFW_NAME} PRIVATE SourceHandler.cpp DestHandler.cpp - FaultHandlerBase.cpp UserBase.cpp) +target_sources(${LIB_FSFW_NAME} PRIVATE FaultHandlerBase.cpp UserBase.cpp) diff --git a/src/fsfw/cfdp/handler/DestHandler.cpp b/src/fsfw/cfdp/handler/DestHandler.cpp deleted file mode 100644 index d43d1482..00000000 --- a/src/fsfw/cfdp/handler/DestHandler.cpp +++ /dev/null @@ -1,480 +0,0 @@ -#include "DestHandler.h" - -#include - -#include - -#include "fsfw/FSFW.h" -#include "fsfw/cfdp/pdu/EofPduReader.h" -#include "fsfw/cfdp/pdu/FileDataReader.h" -#include "fsfw/cfdp/pdu/FinishedPduCreator.h" -#include "fsfw/cfdp/pdu/PduHeaderReader.h" -#include "fsfw/objectmanager.h" -#include "fsfw/tmtcservices/TmTcMessage.h" - -using namespace returnvalue; - -cfdp::DestHandler::DestHandler(DestHandlerParams params, FsfwParams fsfwParams) - : tlvVec(params.maxTlvsInOnePdu), - userTlvVec(params.maxTlvsInOnePdu), - dp(std::move(params)), - fp(fsfwParams), - tp(params.maxFilenameLen) { - tp.pduConf.direction = cfdp::Direction::TOWARDS_SENDER; -} - -const cfdp::DestHandler::FsmResult& cfdp::DestHandler::performStateMachine() { - ReturnValue_t result; - uint8_t errorIdx = 0; - fsmRes.resetOfIteration(); - if (fsmRes.step == TransactionStep::IDLE) { - for (auto infoIter = dp.packetListRef.begin(); infoIter != dp.packetListRef.end();) { - if (infoIter->pduType == PduTypes::FILE_DIRECTIVE and - infoIter->directiveType == FileDirectives::METADATA) { - result = handleMetadataPdu(*infoIter); - checkAndHandleError(result, errorIdx); - // Store data was deleted in PDU handler because a store guard is used - dp.packetListRef.erase(infoIter++); - } else { - infoIter++; - } - } - if (fsmRes.step == TransactionStep::IDLE) { - // To decrease the already high complexity of the software, all packets arriving before - // a metadata PDU are deleted. - for (auto infoIter = dp.packetListRef.begin(); infoIter != dp.packetListRef.end();) { - fp.tcStore->deleteData(infoIter->storeId); - infoIter++; - } - dp.packetListRef.clear(); - } - - if (fsmRes.step != TransactionStep::IDLE) { - fsmRes.callStatus = CallStatus::CALL_AGAIN; - } - return updateFsmRes(errorIdx); - } - if (fsmRes.state == CfdpStates::BUSY_CLASS_1_NACKED) { - if (fsmRes.step == TransactionStep::RECEIVING_FILE_DATA_PDUS) { - for (auto infoIter = dp.packetListRef.begin(); infoIter != dp.packetListRef.end();) { - if (infoIter->pduType == PduTypes::FILE_DATA) { - result = handleFileDataPdu(*infoIter); - checkAndHandleError(result, errorIdx); - // Store data was deleted in PDU handler because a store guard is used - dp.packetListRef.erase(infoIter++); - } else if (infoIter->pduType == PduTypes::FILE_DIRECTIVE and - infoIter->directiveType == FileDirectives::EOF_DIRECTIVE) { - // TODO: Support for check timer missing - result = handleEofPdu(*infoIter); - checkAndHandleError(result, errorIdx); - // Store data was deleted in PDU handler because a store guard is used - dp.packetListRef.erase(infoIter++); - } else { - infoIter++; - } - } - } - if (fsmRes.step == TransactionStep::TRANSFER_COMPLETION) { - result = handleTransferCompletion(); - checkAndHandleError(result, errorIdx); - } - if (fsmRes.step == TransactionStep::SENDING_FINISHED_PDU) { - result = sendFinishedPdu(); - checkAndHandleError(result, errorIdx); - finish(); - } - return updateFsmRes(errorIdx); - } - if (fsmRes.state == CfdpStates::BUSY_CLASS_2_ACKED) { - // TODO: Will be implemented at a later stage -#if FSFW_CPP_OSTREAM_ENABLED == 1 - sif::warning << "CFDP state machine for acknowledged mode not implemented yet" << std::endl; -#endif - } - return updateFsmRes(errorIdx); -} - -ReturnValue_t cfdp::DestHandler::passPacket(PacketInfo packet) { - if (dp.packetListRef.full()) { - return FAILED; - } - dp.packetListRef.push_back(packet); - return OK; -} - -ReturnValue_t cfdp::DestHandler::initialize() { - if (fp.tmStore == nullptr) { - fp.tmStore = ObjectManager::instance()->get(objects::TM_STORE); - if (fp.tmStore == nullptr) { - return FAILED; - } - } - - if (fp.tcStore == nullptr) { - fp.tcStore = ObjectManager::instance()->get(objects::TC_STORE); - if (fp.tcStore == nullptr) { - return FAILED; - } - } - - if (fp.msgQueue == nullptr) { - return FAILED; - } - return OK; -} - -ReturnValue_t cfdp::DestHandler::handleMetadataPdu(const PacketInfo& info) { - // Process metadata PDU - auto constAccessorPair = fp.tcStore->getData(info.storeId); - if (constAccessorPair.first != OK) { - // TODO: This is not a CFDP error. Event and/or warning? - return constAccessorPair.first; - } - cfdp::StringLv sourceFileName; - cfdp::StringLv destFileName; - MetadataInfo metadataInfo(tp.fileSize, sourceFileName, destFileName); - cfdp::Tlv* tlvArrayAsPtr = tlvVec.data(); - metadataInfo.setOptionsArray(&tlvArrayAsPtr, std::nullopt, tlvVec.size()); - MetadataPduReader reader(constAccessorPair.second.data(), constAccessorPair.second.size(), - metadataInfo); - ReturnValue_t result = reader.parseData(); - // TODO: The standard does not really specify what happens if this kind of error happens - // I think it might be a good idea to cache some sort of error code, which - // is translated into a warning and/or event by an upper layer - if (result != OK) { - return handleMetadataParseError(result, constAccessorPair.second.data(), - constAccessorPair.second.size()); - } - return startTransaction(reader, metadataInfo); -} - -ReturnValue_t cfdp::DestHandler::handleFileDataPdu(const cfdp::PacketInfo& info) { - // Process file data PDU - auto constAccessorPair = fp.tcStore->getData(info.storeId); - if (constAccessorPair.first != OK) { - // TODO: This is not a CFDP error. Event and/or warning? - return constAccessorPair.first; - } - cfdp::FileSize offset; - FileDataInfo fdInfo(offset); - FileDataReader reader(constAccessorPair.second.data(), constAccessorPair.second.size(), fdInfo); - ReturnValue_t result = reader.parseData(); - if (result != OK) { - return result; - } - size_t fileSegmentLen = 0; - const uint8_t* fileData = fdInfo.getFileData(&fileSegmentLen); - FileOpParams fileOpParams(tp.destName.data(), fileSegmentLen); - fileOpParams.offset = offset.value(); - if (dp.cfg.indicCfg.fileSegmentRecvIndicRequired) { - FileSegmentRecvdParams segParams; - segParams.offset = offset.value(); - segParams.id = tp.transactionId; - segParams.length = fileSegmentLen; - segParams.recContState = fdInfo.getRecordContinuationState(); - size_t segmentMetadatLen = 0; - auto* segMetadata = fdInfo.getSegmentMetadata(&segmentMetadatLen); - segParams.segmentMetadata = {segMetadata, segmentMetadatLen}; - dp.user.fileSegmentRecvdIndication(segParams); - } - result = dp.user.vfs.writeToFile(fileOpParams, fileData); - if (offset.value() + fileSegmentLen > tp.progress) { - tp.progress = offset.value() + fileSegmentLen; - } - if (result != returnvalue::OK) { - // TODO: Proper Error handling -#if FSFW_CPP_OSTREAM_ENABLED == 1 - sif::error << "File write error" << std::endl; -#endif - } else { - tp.deliveryStatus = FileDeliveryStatus::RETAINED_IN_FILESTORE; - } - return result; -} - -ReturnValue_t cfdp::DestHandler::handleEofPdu(const cfdp::PacketInfo& info) { - // Process EOF PDU - auto constAccessorPair = fp.tcStore->getData(info.storeId); - if (constAccessorPair.first != OK) { - // TODO: This is not a CFDP error. Event and/or warning? - return constAccessorPair.first; - } - EofInfo eofInfo(nullptr); - EofPduReader reader(constAccessorPair.second.data(), constAccessorPair.second.size(), eofInfo); - ReturnValue_t result = reader.parseData(); - if (result != OK) { - return result; - } - // TODO: Error handling - if (eofInfo.getConditionCode() == ConditionCode::NO_ERROR) { - tp.crc = eofInfo.getChecksum(); - uint64_t fileSizeFromEof = eofInfo.getFileSize().value(); - // CFDP 4.6.1.2.9: Declare file size error if progress exceeds file size - if (fileSizeFromEof > tp.progress) { - // TODO: File size error - } - tp.fileSize.setFileSize(fileSizeFromEof, std::nullopt); - } - if (dp.cfg.indicCfg.eofRecvIndicRequired) { - dp.user.eofRecvIndication(getTransactionId()); - } - if (fsmRes.step == TransactionStep::RECEIVING_FILE_DATA_PDUS) { - if (fsmRes.state == CfdpStates::BUSY_CLASS_1_NACKED) { - fsmRes.step = TransactionStep::TRANSFER_COMPLETION; - } else if (fsmRes.state == CfdpStates::BUSY_CLASS_2_ACKED) { - fsmRes.step = TransactionStep::SENDING_ACK_PDU; - } - } - return returnvalue::OK; -} - -ReturnValue_t cfdp::DestHandler::handleMetadataParseError(ReturnValue_t result, - const uint8_t* rawData, size_t maxSize) { - // TODO: try to extract destination ID for error - // TODO: Invalid metadata PDU. -#if FSFW_CPP_OSTREAM_ENABLED == 1 - sif::warning << "Parsing Metadata PDU failed with code " << result << std::endl; -#else -#endif - PduHeaderReader headerReader(rawData, maxSize); - result = headerReader.parseData(); - if (result != OK) { - // TODO: Now this really should not happen. Warning or error, - // yield or cache appropriate returnvalue -#if FSFW_CPP_OSTREAM_ENABLED == 1 - sif::warning << "Parsing Header failed" << std::endl; -#else -#endif - // TODO: Trigger appropriate event - return result; - } - cfdp::EntityId destId; - headerReader.getDestId(destId); - RemoteEntityCfg* remoteCfg; - if (not dp.remoteCfgTable.getRemoteCfg(destId, &remoteCfg)) { -// TODO: No remote config for dest ID. I consider this a configuration error, which is not -// covered by the standard. -// Warning or error, yield or cache appropriate returnvalue -#if FSFW_CPP_OSTREAM_ENABLED == 1 - sif::warning << "No remote config exists for destination ID" << std::endl; -#else -#endif - // TODO: Trigger appropriate event - } - // TODO: Appropriate returnvalue? - return returnvalue::FAILED; -} - -ReturnValue_t cfdp::DestHandler::startTransaction(MetadataPduReader& reader, MetadataInfo& info) { - if (fsmRes.state != CfdpStates::IDLE) { - // According to standard, discard metadata PDU if we are busy - return OK; - } - ReturnValue_t result = OK; - fsmRes.step = TransactionStep::TRANSACTION_START; - if (reader.getTransmissionMode() == TransmissionModes::UNACKNOWLEDGED) { - fsmRes.state = CfdpStates::BUSY_CLASS_1_NACKED; - } else if (reader.getTransmissionMode() == TransmissionModes::ACKNOWLEDGED) { - fsmRes.state = CfdpStates::BUSY_CLASS_2_ACKED; - } - tp.checksumType = info.getChecksumType(); - tp.closureRequested = info.isClosureRequested(); - size_t sourceNameSize = 0; - const uint8_t* sourceNamePtr = info.getSourceFileName().getValue(&sourceNameSize); - if (sourceNameSize > tp.sourceName.size()) { - // TODO: Warning, event etc. - return FAILED; - } - std::memcpy(tp.sourceName.data(), sourceNamePtr, sourceNameSize); - tp.sourceName[sourceNameSize] = '\0'; - size_t destNameSize = 0; - const uint8_t* destNamePtr = info.getDestFileName().getValue(&destNameSize); - if (destNameSize > tp.destName.size()) { - // TODO: Warning, event etc. - return FAILED; - } - std::memcpy(tp.destName.data(), destNamePtr, destNameSize); - tp.destName[destNameSize] = '\0'; - reader.fillConfig(tp.pduConf); - tp.pduConf.direction = Direction::TOWARDS_SENDER; - tp.transactionId.entityId = tp.pduConf.sourceId; - tp.transactionId.seqNum = tp.pduConf.seqNum; - if (not dp.remoteCfgTable.getRemoteCfg(tp.pduConf.sourceId, &tp.remoteCfg)) { - // TODO: Warning, event etc. -#if FSFW_CPP_OSTREAM_ENABLED == 1 - sif::warning << "cfdp::DestHandler" << __func__ - << ": No remote configuration found for destination ID " - << tp.pduConf.sourceId.getValue() << std::endl; -#endif - return FAILED; - } - // If both dest name size and source name size are 0, we are dealing with a metadata only PDU, - // so there is no need to create a file or truncate an existing file - if (destNameSize > 0 and sourceNameSize > 0) { - FilesystemParams fparams(tp.destName.data()); - // TODO: Filesystem errors? - if (dp.user.vfs.fileExists(fparams)) { - dp.user.vfs.truncateFile(fparams); - } else { - result = dp.user.vfs.createFile(fparams); - if (result != OK) { - // TODO: Handle FS error. This is probably a case for the filestore rejection mechanism of - // CFDP. - // In any case, it does not really make sense to continue here - } - } - } - fsmRes.step = TransactionStep::RECEIVING_FILE_DATA_PDUS; - MetadataRecvdParams params(tp.transactionId, tp.pduConf.sourceId); - params.fileSize = tp.fileSize.getSize(); - params.destFileName = tp.destName.data(); - params.sourceFileName = tp.sourceName.data(); - params.msgsToUserArray = dynamic_cast(userTlvVec.data()); - params.msgsToUserLen = info.getOptionsLen(); - dp.user.metadataRecvdIndication(params); - return result; -} - -cfdp::CfdpStates cfdp::DestHandler::getCfdpState() const { return fsmRes.state; } - -ReturnValue_t cfdp::DestHandler::handleTransferCompletion() { - ReturnValue_t result; - if (tp.checksumType != ChecksumTypes::NULL_CHECKSUM) { - result = checksumVerification(); - if (result != OK) { - // TODO: Warning / error handling? - } - } else { - tp.conditionCode = ConditionCode::NO_ERROR; - } - result = noticeOfCompletion(); - if (result != OK) { - } - if (fsmRes.state == CfdpStates::BUSY_CLASS_1_NACKED) { - if (tp.closureRequested) { - fsmRes.step = TransactionStep::SENDING_FINISHED_PDU; - } else { - finish(); - } - } else if (fsmRes.state == CfdpStates::BUSY_CLASS_2_ACKED) { - fsmRes.step = TransactionStep::SENDING_FINISHED_PDU; - } - return OK; -} - -void cfdp::DestHandler::finish() { - tp.reset(); - dp.packetListRef.clear(); - fsmRes.state = CfdpStates::IDLE; - fsmRes.step = TransactionStep::IDLE; -} - -ReturnValue_t cfdp::DestHandler::checksumVerification() { - std::array buf{}; - // TODO: Checksum verification and notice of completion - etl::crc32 crcCalc; - uint64_t currentOffset = 0; - FileOpParams params(tp.destName.data(), tp.fileSize.value()); - while (currentOffset < tp.fileSize.value()) { - uint64_t readLen; - if (currentOffset + buf.size() > tp.fileSize.value()) { - readLen = tp.fileSize.value() - currentOffset; - } else { - readLen = buf.size(); - } - if (readLen > 0) { - params.offset = currentOffset; - params.size = readLen; - auto result = dp.user.vfs.readFromFile(params, buf.data(), buf.size()); - if (result != OK) { - // TODO: I think this is a case for a filestore rejection, but it might sense to print - // a warning or trigger an event because this should generally not happen - return FAILED; - } - crcCalc.add(buf.begin(), buf.begin() + readLen); - } - currentOffset += readLen; - } - - uint32_t value = crcCalc.value(); - if (value == tp.crc) { - tp.conditionCode = ConditionCode::NO_ERROR; - tp.deliveryCode = FileDeliveryCode::DATA_COMPLETE; - } else { - // TODO: Proper error handling -#if FSFW_CPP_OSTREAM_ENABLED == 1 - sif::warning << "CRC check for file " << tp.destName.data() << " failed" << std::endl; -#endif - tp.conditionCode = ConditionCode::FILE_CHECKSUM_FAILURE; - } - return OK; -} - -ReturnValue_t cfdp::DestHandler::noticeOfCompletion() { - if (dp.cfg.indicCfg.transactionFinishedIndicRequired) { - TransactionFinishedParams params(tp.transactionId, tp.conditionCode, tp.deliveryCode, - tp.deliveryStatus); - dp.user.transactionFinishedIndication(params); - } - return OK; -} - -ReturnValue_t cfdp::DestHandler::sendFinishedPdu() { - FinishedInfo info(tp.conditionCode, tp.deliveryCode, tp.deliveryStatus); - FinishPduCreator finishedPdu(tp.pduConf, info); - store_address_t storeId; - uint8_t* dataPtr = nullptr; - ReturnValue_t result = - fp.tcStore->getFreeElement(&storeId, finishedPdu.getSerializedSize(), &dataPtr); - if (result != OK) { - // TODO: Error handling and event, this is a non CFDP specific error (most likely store is full) - return result; - } - size_t serLen = 0; - result = finishedPdu.serialize(dataPtr, serLen, finishedPdu.getSerializedSize()); - if (result != OK) { - // TODO: Error printout, this really should not happen - return result; - } - TmTcMessage msg(storeId); - 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; - } - fsmRes.packetsSent++; - return OK; -} - -cfdp::DestHandler::TransactionStep cfdp::DestHandler::getTransactionStep() const { - return fsmRes.step; -} - -const cfdp::DestHandler::FsmResult& cfdp::DestHandler::updateFsmRes(uint8_t errors) { - fsmRes.errors = errors; - fsmRes.result = OK; - if (fsmRes.errors > 0) { - fsmRes.result = FAILED; - } - return fsmRes; -} - -const cfdp::TransactionId& cfdp::DestHandler::getTransactionId() const { return tp.transactionId; } - -void cfdp::DestHandler::checkAndHandleError(ReturnValue_t result, uint8_t& errorIdx) { - if (result != OK and errorIdx < 3) { - fsmRes.errorCodes[errorIdx] = result; - errorIdx++; - } -} - -void cfdp::DestHandler::setMsgQueue(MessageQueueIF& queue) { fp.msgQueue = &queue; } - -void cfdp::DestHandler::setEventReporter(EventReportingProxyIF& reporter) { - fp.eventReporter = &reporter; -} - -const cfdp::DestHandlerParams& cfdp::DestHandler::getDestHandlerParams() const { return dp; } - -StorageManagerIF* cfdp::DestHandler::getTmStore() const { return fp.tmStore; } -StorageManagerIF* cfdp::DestHandler::getTcStore() const { return fp.tcStore; } diff --git a/src/fsfw/cfdp/handler/DestHandler.h b/src/fsfw/cfdp/handler/DestHandler.h deleted file mode 100644 index 000fc2c0..00000000 --- a/src/fsfw/cfdp/handler/DestHandler.h +++ /dev/null @@ -1,202 +0,0 @@ -#ifndef FSFW_CFDP_CFDPDESTHANDLER_H -#define FSFW_CFDP_CFDPDESTHANDLER_H - -#include -#include - -#include -#include - -#include "RemoteConfigTableIF.h" -#include "UserBase.h" -#include "defs.h" -#include "fsfw/cfdp/handler/mib.h" -#include "fsfw/cfdp/pdu/MetadataPduReader.h" -#include "fsfw/cfdp/pdu/PduConfig.h" -#include "fsfw/container/DynamicFIFO.h" -#include "fsfw/storagemanager/StorageManagerIF.h" -#include "fsfw/storagemanager/storeAddress.h" -#include "fsfw/tmtcservices/AcceptsTelemetryIF.h" - -namespace cfdp { - -struct PacketInfo { - PacketInfo(PduTypes type, store_address_t storeId, - std::optional directive = std::nullopt) - : pduType(type), directiveType(directive), storeId(storeId) {} - - PduTypes pduType = PduTypes::FILE_DATA; - std::optional directiveType = FileDirectives::INVALID_DIRECTIVE; - store_address_t storeId = store_address_t::invalid(); - PacketInfo() = default; -}; - -template -using LostSegmentsList = etl::set, SIZE>; -template -using PacketInfoList = etl::list; -using LostSegmentsListBase = etl::iset>; -using PacketInfoListBase = etl::ilist; - -struct DestHandlerParams { - DestHandlerParams(LocalEntityCfg cfg, UserBase& user, RemoteConfigTableIF& remoteCfgTable, - PacketInfoListBase& packetList, - // TODO: This container can potentially take tons of space. For a better - // memory efficient implementation, an additional abstraction could be - // be used so users can use uint32_t as the pair type - LostSegmentsListBase& lostSegmentsContainer) - : cfg(std::move(cfg)), - user(user), - remoteCfgTable(remoteCfgTable), - packetListRef(packetList), - lostSegmentsContainer(lostSegmentsContainer) {} - - LocalEntityCfg cfg; - UserBase& user; - RemoteConfigTableIF& remoteCfgTable; - - PacketInfoListBase& packetListRef; - LostSegmentsListBase& lostSegmentsContainer; - uint8_t maxTlvsInOnePdu = 10; - size_t maxFilenameLen = 255; -}; - -struct FsfwParams { - FsfwParams(AcceptsTelemetryIF& packetDest, MessageQueueIF* msgQueue, - EventReportingProxyIF* eventReporter, StorageManagerIF& tcStore, - StorageManagerIF& tmStore) - : FsfwParams(packetDest, msgQueue, eventReporter) { - this->tcStore = &tcStore; - this->tmStore = &tmStore; - } - - FsfwParams(AcceptsTelemetryIF& packetDest, MessageQueueIF* msgQueue, - EventReportingProxyIF* eventReporter) - : packetDest(packetDest), msgQueue(msgQueue), eventReporter(eventReporter) {} - AcceptsTelemetryIF& packetDest; - MessageQueueIF* msgQueue; - EventReportingProxyIF* eventReporter = nullptr; - StorageManagerIF* tcStore = nullptr; - StorageManagerIF* tmStore = nullptr; -}; - -enum class CallStatus { DONE, CALL_AFTER_DELAY, CALL_AGAIN }; - -class DestHandler { - public: - enum class TransactionStep { - IDLE = 0, - TRANSACTION_START = 1, - RECEIVING_FILE_DATA_PDUS = 2, - SENDING_ACK_PDU = 3, - TRANSFER_COMPLETION = 4, - SENDING_FINISHED_PDU = 5 - }; - - struct FsmResult { - public: - ReturnValue_t result = returnvalue::OK; - CallStatus callStatus = CallStatus::CALL_AFTER_DELAY; - TransactionStep step = TransactionStep::IDLE; - CfdpStates state = CfdpStates::IDLE; - uint32_t packetsSent = 0; - uint8_t errors = 0; - std::array errorCodes = {}; - void resetOfIteration() { - result = returnvalue::OK; - callStatus = CallStatus::CALL_AFTER_DELAY; - packetsSent = 0; - errors = 0; - errorCodes.fill(returnvalue::OK); - } - }; - /** - * Will be returned if it is advisable to call the state machine operation call again - */ - ReturnValue_t PARTIAL_SUCCESS = returnvalue::makeCode(0, 2); - ReturnValue_t FAILURE = returnvalue::makeCode(0, 3); - explicit DestHandler(DestHandlerParams handlerParams, FsfwParams fsfwParams); - - /** - * - * @return - * - @c returnvalue::OK State machine OK for this execution cycle - * - @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); - - ReturnValue_t initialize(); - - [[nodiscard]] CfdpStates getCfdpState() const; - [[nodiscard]] TransactionStep getTransactionStep() const; - [[nodiscard]] const TransactionId& getTransactionId() const; - [[nodiscard]] const DestHandlerParams& getDestHandlerParams() const; - [[nodiscard]] StorageManagerIF* getTcStore() const; - [[nodiscard]] StorageManagerIF* getTmStore() const; - - private: - struct TransactionParams { - // Initialize char vectors with length + 1 for 0 termination - explicit TransactionParams(size_t maxFileNameLen) - : sourceName(maxFileNameLen + 1), destName(maxFileNameLen + 1) {} - - void reset() { - pduConf = PduConfig(); - transactionId = TransactionId(); - std::fill(sourceName.begin(), sourceName.end(), '\0'); - std::fill(destName.begin(), destName.end(), '\0'); - fileSize.setFileSize(0, false); - conditionCode = ConditionCode::NO_ERROR; - deliveryCode = FileDeliveryCode::DATA_INCOMPLETE; - deliveryStatus = FileDeliveryStatus::DISCARDED_DELIBERATELY; - crc = 0; - progress = 0; - remoteCfg = nullptr; - closureRequested = false; - checksumType = ChecksumTypes::NULL_CHECKSUM; - } - - ChecksumTypes checksumType = ChecksumTypes::NULL_CHECKSUM; - bool closureRequested = false; - std::vector sourceName; - std::vector destName; - cfdp::FileSize fileSize; - TransactionId transactionId; - PduConfig pduConf; - ConditionCode conditionCode = ConditionCode::NO_ERROR; - FileDeliveryCode deliveryCode = FileDeliveryCode::DATA_INCOMPLETE; - FileDeliveryStatus deliveryStatus = FileDeliveryStatus::DISCARDED_DELIBERATELY; - uint32_t crc = 0; - uint64_t progress = 0; - RemoteEntityCfg* remoteCfg = nullptr; - }; - - std::vector tlvVec; - std::vector userTlvVec; - DestHandlerParams dp; - FsfwParams fp; - TransactionParams tp; - FsmResult fsmRes; - - ReturnValue_t startTransaction(MetadataPduReader& reader, MetadataInfo& info); - ReturnValue_t handleMetadataPdu(const PacketInfo& info); - ReturnValue_t handleFileDataPdu(const PacketInfo& info); - ReturnValue_t handleEofPdu(const PacketInfo& info); - ReturnValue_t handleMetadataParseError(ReturnValue_t result, const uint8_t* rawData, - size_t maxSize); - ReturnValue_t handleTransferCompletion(); - ReturnValue_t sendFinishedPdu(); - ReturnValue_t noticeOfCompletion(); - ReturnValue_t checksumVerification(); - const FsmResult& updateFsmRes(uint8_t errors); - void checkAndHandleError(ReturnValue_t result, uint8_t& errorIdx); - void finish(); -}; - -} // namespace cfdp - -#endif // FSFW_CFDP_CFDPDESTHANDLER_H diff --git a/src/fsfw/cfdp/handler/SourceHandler.cpp b/src/fsfw/cfdp/handler/SourceHandler.cpp deleted file mode 100644 index 513b25f3..00000000 --- a/src/fsfw/cfdp/handler/SourceHandler.cpp +++ /dev/null @@ -1 +0,0 @@ -#include "SourceHandler.h" diff --git a/src/fsfw/cfdp/handler/SourceHandler.h b/src/fsfw/cfdp/handler/SourceHandler.h deleted file mode 100644 index 319cf258..00000000 --- a/src/fsfw/cfdp/handler/SourceHandler.h +++ /dev/null @@ -1,6 +0,0 @@ -#ifndef FSFW_CFDP_CFDPSOURCEHANDLER_H -#define FSFW_CFDP_CFDPSOURCEHANDLER_H - -class SourceHandler {}; - -#endif // FSFW_CFDP_CFDPSOURCEHANDLER_H diff --git a/unittests/cfdp/handler/CMakeLists.txt b/unittests/cfdp/handler/CMakeLists.txt index f70e5dfb..0993a398 100644 --- a/unittests/cfdp/handler/CMakeLists.txt +++ b/unittests/cfdp/handler/CMakeLists.txt @@ -1,3 +1,2 @@ -target_sources( - ${FSFW_TEST_TGT} PRIVATE testDistributor.cpp testDestHandler.cpp - testSourceHandler.cpp testFaultHandler.cpp) +target_sources(${FSFW_TEST_TGT} PRIVATE testDistributor.cpp + testFaultHandler.cpp) diff --git a/unittests/cfdp/handler/testDestHandler.cpp b/unittests/cfdp/handler/testDestHandler.cpp deleted file mode 100644 index 30bb9fc5..00000000 --- a/unittests/cfdp/handler/testDestHandler.cpp +++ /dev/null @@ -1,244 +0,0 @@ -#include - -#include -#include -#include - -#include "fsfw/cfdp.h" -#include "fsfw/cfdp/pdu/EofPduCreator.h" -#include "fsfw/cfdp/pdu/FileDataCreator.h" -#include "fsfw/cfdp/pdu/MetadataPduCreator.h" -#include "mocks/AcceptsTmMock.h" -#include "mocks/EventReportingProxyMock.h" -#include "mocks/FilesystemMock.h" -#include "mocks/MessageQueueMock.h" -#include "mocks/StorageManagerMock.h" -#include "mocks/cfdp/FaultHandlerMock.h" -#include "mocks/cfdp/RemoteConfigTableMock.h" -#include "mocks/cfdp/UserMock.h" - -TEST_CASE("CFDP Dest Handler", "[cfdp]") { - using namespace cfdp; - using namespace returnvalue; - MessageQueueId_t destQueueId = 2; - AcceptsTmMock tmReceiver(destQueueId); - MessageQueueMock mqMock(destQueueId); - EntityId localId = EntityId(UnsignedByteField(2)); - EntityId remoteId = EntityId(UnsignedByteField(3)); - FaultHandlerMock fhMock; - LocalEntityCfg localEntityCfg(localId, IndicationCfg(), fhMock); - FilesystemMock fsMock; - UserMock userMock(fsMock); - RemoteConfigTableMock remoteCfgTableMock; - PacketInfoList<64> packetInfoList; - LostSegmentsList<128> lostSegmentsList; - DestHandlerParams dp(localEntityCfg, userMock, remoteCfgTableMock, packetInfoList, - lostSegmentsList); - EventReportingProxyMock eventReporterMock; - LocalPool::LocalPoolConfig storeCfg = {{10, 32}, {10, 64}, {10, 128}, {10, 1024}}; - StorageManagerMock tcStore(2, storeCfg); - StorageManagerMock tmStore(3, storeCfg); - FsfwParams fp(tmReceiver, &mqMock, &eventReporterMock); - RemoteEntityCfg cfg(remoteId); - remoteCfgTableMock.addRemoteConfig(cfg); - fp.tcStore = &tcStore; - fp.tmStore = &tmStore; - uint8_t* buf = nullptr; - size_t serLen = 0; - store_address_t storeId; - PduConfig conf; - auto destHandler = DestHandler(dp, fp); - CHECK(destHandler.initialize() == OK); - - auto metadataPreparation = [&](FileSize cfdpFileSize, ChecksumTypes checksumType) { - std::string srcNameString = "hello.txt"; - std::string destNameString = "hello-cpy.txt"; - StringLv srcName(srcNameString); - StringLv destName(destNameString); - MetadataInfo info(false, checksumType, cfdpFileSize, srcName, destName); - TransactionSeqNum seqNum(UnsignedByteField(1)); - conf.sourceId = remoteId; - conf.destId = localId; - conf.mode = TransmissionModes::UNACKNOWLEDGED; - conf.seqNum = seqNum; - MetadataPduCreator metadataCreator(conf, info); - REQUIRE(tcStore.getFreeElement(&storeId, metadataCreator.getSerializedSize(), &buf) == OK); - REQUIRE(metadataCreator.serialize(buf, serLen, metadataCreator.getSerializedSize()) == OK); - PacketInfo packetInfo(metadataCreator.getPduType(), storeId, - metadataCreator.getDirectiveCode()); - packetInfoList.push_back(packetInfo); - }; - - auto metadataCheck = [&](const cfdp::DestHandler::FsmResult& res, const char* sourceName, - const char* destName, size_t fileLen) { - REQUIRE(res.result == OK); - REQUIRE(res.callStatus == CallStatus::CALL_AGAIN); - REQUIRE(res.errors == 0); - // Assert that the packet was deleted after handling - REQUIRE(not tcStore.hasDataAtId(storeId)); - REQUIRE(packetInfoList.empty()); - REQUIRE(userMock.metadataRecvd.size() == 1); - auto& idMetadataPair = userMock.metadataRecvd.back(); - REQUIRE(idMetadataPair.first == destHandler.getTransactionId()); - REQUIRE(idMetadataPair.second.sourceId.getValue() == 3); - REQUIRE(idMetadataPair.second.fileSize == fileLen); - REQUIRE(strcmp(idMetadataPair.second.destFileName, destName) == 0); - REQUIRE(strcmp(idMetadataPair.second.sourceFileName, sourceName) == 0); - userMock.metadataRecvd.pop(); - REQUIRE(fsMock.fileMap.find(destName) != fsMock.fileMap.end()); - REQUIRE(res.result == OK); - REQUIRE(res.state == CfdpStates::BUSY_CLASS_1_NACKED); - REQUIRE(res.step == DestHandler::TransactionStep::RECEIVING_FILE_DATA_PDUS); - }; - - auto eofPreparation = [&](FileSize cfdpFileSize, uint32_t crc) { - EofInfo eofInfo(cfdp::ConditionCode::NO_ERROR, crc, std::move(cfdpFileSize)); - EofPduCreator eofCreator(conf, eofInfo); - REQUIRE(tcStore.getFreeElement(&storeId, eofCreator.getSerializedSize(), &buf) == OK); - REQUIRE(eofCreator.serialize(buf, serLen, eofCreator.getSerializedSize()) == OK); - PacketInfo packetInfo(eofCreator.getPduType(), storeId, eofCreator.getDirectiveCode()); - packetInfoList.push_back(packetInfo); - }; - - auto eofCheck = [&](const cfdp::DestHandler::FsmResult& res, const TransactionId& id) { - REQUIRE(res.result == OK); - REQUIRE(res.state == CfdpStates::IDLE); - REQUIRE(res.errors == 0); - REQUIRE(res.step == DestHandler::TransactionStep::IDLE); - // Assert that the packet was deleted after handling - REQUIRE(not tcStore.hasDataAtId(storeId)); - REQUIRE(packetInfoList.empty()); - REQUIRE(userMock.eofsRevd.size() == 1); - auto& eofId = userMock.eofsRevd.back(); - CHECK(eofId == id); - REQUIRE(userMock.finishedRecvd.size() == 1); - auto& idParamPair = userMock.finishedRecvd.back(); - CHECK(idParamPair.first == id); - CHECK(idParamPair.second.condCode == ConditionCode::NO_ERROR); - }; - - auto fileDataPduCheck = [&](const cfdp::DestHandler::FsmResult& res, - const std::vector& idsToCheck) { - REQUIRE(res.result == OK); - REQUIRE(res.state == CfdpStates::BUSY_CLASS_1_NACKED); - REQUIRE(res.step == DestHandler::TransactionStep::RECEIVING_FILE_DATA_PDUS); - for (const auto id : idsToCheck) { - REQUIRE(not tcStore.hasDataAtId(id)); - } - REQUIRE(packetInfoList.empty()); - }; - - SECTION("State") { - CHECK(destHandler.getCfdpState() == CfdpStates::IDLE); - CHECK(destHandler.getTransactionStep() == DestHandler::TransactionStep::IDLE); - } - - SECTION("Idle State Machine Iteration") { - auto res = destHandler.performStateMachine(); - CHECK(res.result == OK); - CHECK(res.callStatus == CallStatus::CALL_AFTER_DELAY); - CHECK(res.errors == 0); - CHECK(destHandler.getCfdpState() == CfdpStates::IDLE); - CHECK(destHandler.getTransactionStep() == DestHandler::TransactionStep::IDLE); - } - - SECTION("Empty File Transfer") { - const DestHandler::FsmResult& res = destHandler.performStateMachine(); - CHECK(res.result == OK); - FileSize cfdpFileSize(0); - metadataPreparation(cfdpFileSize, ChecksumTypes::NULL_CHECKSUM); - destHandler.performStateMachine(); - metadataCheck(res, "hello.txt", "hello-cpy.txt", 0); - destHandler.performStateMachine(); - REQUIRE(res.callStatus == CallStatus::CALL_AFTER_DELAY); - auto transactionId = destHandler.getTransactionId(); - eofPreparation(cfdpFileSize, 0); - // After EOF, operation is done because no closure was requested - destHandler.performStateMachine(); - eofCheck(res, transactionId); - } - - SECTION("Small File Transfer") { - const DestHandler::FsmResult& res = destHandler.performStateMachine(); - CHECK(res.result == OK); - std::string fileData = "hello test data"; - etl::crc32 crcCalc; - crcCalc.add(fileData.begin(), fileData.end()); - uint32_t crc32 = crcCalc.value(); - FileSize cfdpFileSize(fileData.size()); - metadataPreparation(cfdpFileSize, ChecksumTypes::CRC_32); - destHandler.performStateMachine(); - metadataCheck(res, "hello.txt", "hello-cpy.txt", fileData.size()); - destHandler.performStateMachine(); - REQUIRE(res.callStatus == CallStatus::CALL_AFTER_DELAY); - auto transactionId = destHandler.getTransactionId(); - FileSize offset(0); - FileDataInfo fdPduInfo(offset, reinterpret_cast(fileData.data()), - fileData.size()); - FileDataCreator fdPduCreator(conf, fdPduInfo); - REQUIRE(tcStore.getFreeElement(&storeId, fdPduCreator.getSerializedSize(), &buf) == OK); - REQUIRE(fdPduCreator.serialize(buf, serLen, fdPduCreator.getSerializedSize()) == OK); - PacketInfo packetInfo(fdPduCreator.getPduType(), storeId, std::nullopt); - packetInfoList.push_back(packetInfo); - destHandler.performStateMachine(); - fileDataPduCheck(res, {storeId}); - eofPreparation(cfdpFileSize, crc32); - // After EOF, operation is done because no closure was requested - destHandler.performStateMachine(); - eofCheck(res, transactionId); - } - - SECTION("Segmented File Transfer") { - const DestHandler::FsmResult& res = destHandler.performStateMachine(); - CHECK(res.result == OK); - std::random_device dev; - std::mt19937 rng(dev()); - std::uniform_int_distribution distU8(0, 255); - std::array largerFileData{}; - for (auto& val : largerFileData) { - val = distU8(rng); - } - etl::crc32 crcCalc; - crcCalc.add(largerFileData.begin(), largerFileData.end()); - uint32_t crc32 = crcCalc.value(); - FileSize cfdpFileSize(largerFileData.size()); - metadataPreparation(cfdpFileSize, ChecksumTypes::CRC_32); - destHandler.performStateMachine(); - metadataCheck(res, "hello.txt", "hello-cpy.txt", largerFileData.size()); - destHandler.performStateMachine(); - REQUIRE(res.callStatus == CallStatus::CALL_AFTER_DELAY); - auto transactionId = destHandler.getTransactionId(); - - std::vector idsToCheck; - { - FileSize offset(0); - FileDataInfo fdPduInfo(offset, reinterpret_cast(largerFileData.data()), - largerFileData.size() / 2); - FileDataCreator fdPduCreator(conf, fdPduInfo); - REQUIRE(tcStore.getFreeElement(&storeId, fdPduCreator.getSerializedSize(), &buf) == OK); - REQUIRE(fdPduCreator.serialize(buf, serLen, fdPduCreator.getSerializedSize()) == OK); - PacketInfo packetInfo(fdPduCreator.getPduType(), storeId, std::nullopt); - idsToCheck.push_back(storeId); - packetInfoList.push_back(packetInfo); - } - - { - FileSize offset(512); - FileDataInfo fdPduInfo(offset, reinterpret_cast(largerFileData.data() + 512), - largerFileData.size() / 2); - FileDataCreator fdPduCreator(conf, fdPduInfo); - REQUIRE(tcStore.getFreeElement(&storeId, fdPduCreator.getSerializedSize(), &buf) == OK); - REQUIRE(fdPduCreator.serialize(buf, serLen, fdPduCreator.getSerializedSize()) == OK); - PacketInfo packetInfo(fdPduCreator.getPduType(), storeId, std::nullopt); - idsToCheck.push_back(storeId); - packetInfoList.push_back(packetInfo); - } - - destHandler.performStateMachine(); - fileDataPduCheck(res, idsToCheck); - eofPreparation(cfdpFileSize, crc32); - // After EOF, operation is done because no closure was requested - destHandler.performStateMachine(); - eofCheck(res, transactionId); - } -} \ No newline at end of file diff --git a/unittests/cfdp/handler/testSourceHandler.cpp b/unittests/cfdp/handler/testSourceHandler.cpp deleted file mode 100644 index 570ecb08..00000000 --- a/unittests/cfdp/handler/testSourceHandler.cpp +++ /dev/null @@ -1,3 +0,0 @@ -#include - -TEST_CASE("CFDP Source Handler", "[cfdp]") {} \ No newline at end of file diff --git a/unittests/cfdp/testLvs.cpp b/unittests/cfdp/testLvs.cpp index 062281e5..22094568 100644 --- a/unittests/cfdp/testLvs.cpp +++ b/unittests/cfdp/testLvs.cpp @@ -2,6 +2,7 @@ #include #include "fsfw/cfdp.h" +#include "fsfw/cfdp/VarLenFields.h" TEST_CASE("CFDP LV", "[cfdp][lv]") { using namespace cfdp; diff --git a/unittests/cfdp/testTlv.cpp b/unittests/cfdp/testTlv.cpp index 3e7435cd..b78d8a80 100644 --- a/unittests/cfdp/testTlv.cpp +++ b/unittests/cfdp/testTlv.cpp @@ -2,6 +2,7 @@ #include #include "fsfw/cfdp.h" +#include "fsfw/cfdp/VarLenFields.h" TEST_CASE("CFDP TLV", "[cfdp][tlv]") { using namespace cfdp; From 73f1917c816cb199311e3c2ccc3ff5daa8c9ca0d Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Wed, 14 Sep 2022 19:26:07 +0200 Subject: [PATCH 116/169] update changelog --- CHANGELOG.md | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3fe567de..24bc89fc 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -25,6 +25,19 @@ and this project adheres to [Semantic Versioning](http://semver.org/). PR: https://egit.irs.uni-stuttgart.de/fsfw/fsfw/pulls/655 which also includes a migration guide +## CFDP + +- Refactoring of CFDP stack which was done during implementation of the CFDP source and destination + handlers. + - New filesystem module, changes for filesystem abstraction `HasFileSystemIF` to better + fit requirements of CFDP + - New `HostFilesystem` implementation of the `HasFileSystemIF` + - New `cfdp::UserBase` class which is the abstraction for the CFDP user in an OBSW context. + - mib module for the CFDP stack + - PDU classes renamed from `...Serializer`/`...Deserializer` to `...Creator`/`...Reader` + respetively + PR: https://egit.irs.uni-stuttgart.de/fsfw/fsfw/pulls/682/files + # [v5.0.0] 25.07.2022 ## Changes From 2e27a85c95e26b906207e433308e9ee64308cac3 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Wed, 14 Sep 2022 19:48:11 +0200 Subject: [PATCH 117/169] finished renaming operation --- src/fsfw/cfdp/pdu/CMakeLists.txt | 12 +++++----- ...Serializer.cpp => KeepAlivePduCreator.cpp} | 12 +++++----- src/fsfw/cfdp/pdu/KeepAlivePduCreator.h | 22 +++++++++++++++++++ src/fsfw/cfdp/pdu/KeepAlivePduDeserializer.h | 19 ---------------- ...eserializer.cpp => KeepAlivePduReader.cpp} | 10 ++++----- src/fsfw/cfdp/pdu/KeepAlivePduReader.h | 19 ++++++++++++++++ src/fsfw/cfdp/pdu/KeepAlivePduSerializer.h | 22 ------------------- ...NakPduSerializer.cpp => NakPduCreator.cpp} | 14 +++++------- .../{NakPduSerializer.h => NakPduCreator.h} | 12 +++++----- src/fsfw/cfdp/pdu/NakPduDeserializer.h | 21 ------------------ ...akPduDeserializer.cpp => NakPduReader.cpp} | 6 ++--- src/fsfw/cfdp/pdu/NakPduReader.h | 21 ++++++++++++++++++ ...PduSerializer.cpp => PromptPduCreator.cpp} | 11 +++++----- ...omptPduSerializer.h => PromptPduCreator.h} | 4 ++-- ...duDeserializer.cpp => PromptPduReader.cpp} | 8 +++---- ...mptPduDeserializer.h => PromptPduReader.h} | 4 ++-- unittests/cfdp/pdu/testKeepAlivePdu.cpp | 10 ++++----- unittests/cfdp/pdu/testNakPdu.cpp | 16 +++++++------- unittests/cfdp/pdu/testPromptPdu.cpp | 10 ++++----- 19 files changed, 125 insertions(+), 128 deletions(-) rename src/fsfw/cfdp/pdu/{KeepAlivePduSerializer.cpp => KeepAlivePduCreator.cpp} (54%) create mode 100644 src/fsfw/cfdp/pdu/KeepAlivePduCreator.h delete mode 100644 src/fsfw/cfdp/pdu/KeepAlivePduDeserializer.h rename src/fsfw/cfdp/pdu/{KeepAlivePduDeserializer.cpp => KeepAlivePduReader.cpp} (56%) create mode 100644 src/fsfw/cfdp/pdu/KeepAlivePduReader.h delete mode 100644 src/fsfw/cfdp/pdu/KeepAlivePduSerializer.h rename src/fsfw/cfdp/pdu/{NakPduSerializer.cpp => NakPduCreator.cpp} (74%) rename src/fsfw/cfdp/pdu/{NakPduSerializer.h => NakPduCreator.h} (70%) delete mode 100644 src/fsfw/cfdp/pdu/NakPduDeserializer.h rename src/fsfw/cfdp/pdu/{NakPduDeserializer.cpp => NakPduReader.cpp} (90%) create mode 100644 src/fsfw/cfdp/pdu/NakPduReader.h rename src/fsfw/cfdp/pdu/{PromptPduSerializer.cpp => PromptPduCreator.cpp} (54%) rename src/fsfw/cfdp/pdu/{PromptPduSerializer.h => PromptPduCreator.h} (77%) rename src/fsfw/cfdp/pdu/{PromptPduDeserializer.cpp => PromptPduReader.cpp} (65%) rename src/fsfw/cfdp/pdu/{PromptPduDeserializer.h => PromptPduReader.h} (78%) diff --git a/src/fsfw/cfdp/pdu/CMakeLists.txt b/src/fsfw/cfdp/pdu/CMakeLists.txt index 22ac76c7..c08a4b29 100644 --- a/src/fsfw/cfdp/pdu/CMakeLists.txt +++ b/src/fsfw/cfdp/pdu/CMakeLists.txt @@ -12,18 +12,18 @@ target_sources( EofPduCreator.cpp EofPduReader.cpp NakInfo.cpp - NakPduSerializer.cpp - NakPduDeserializer.cpp + NakPduCreator.cpp + NakPduReader.cpp FinishedInfo.cpp FinishedPduCreator.cpp FinishedPduReader.cpp MetadataInfo.cpp MetadataPduCreator.cpp MetadataPduReader.cpp - KeepAlivePduSerializer.cpp - KeepAlivePduDeserializer.cpp - PromptPduSerializer.cpp - PromptPduDeserializer.cpp + KeepAlivePduCreator.cpp + KeepAlivePduReader.cpp + PromptPduCreator.cpp + PromptPduReader.cpp FileDataCreator.cpp FileDataReader.cpp FileDataInfo.cpp) diff --git a/src/fsfw/cfdp/pdu/KeepAlivePduSerializer.cpp b/src/fsfw/cfdp/pdu/KeepAlivePduCreator.cpp similarity index 54% rename from src/fsfw/cfdp/pdu/KeepAlivePduSerializer.cpp rename to src/fsfw/cfdp/pdu/KeepAlivePduCreator.cpp index 882f401f..8b0ad6c8 100644 --- a/src/fsfw/cfdp/pdu/KeepAlivePduSerializer.cpp +++ b/src/fsfw/cfdp/pdu/KeepAlivePduCreator.cpp @@ -1,22 +1,22 @@ -#include "KeepAlivePduSerializer.h" +#include "KeepAlivePduCreator.h" -KeepAlivePduSerializer::KeepAlivePduSerializer(PduConfig &conf, cfdp::FileSize &progress) +KeepAlivePduCreator::KeepAlivePduCreator(PduConfig &conf, cfdp::FileSize &progress) : FileDirectiveCreator(conf, cfdp::FileDirectives::KEEP_ALIVE, 4), progress(progress) { updateDirectiveFieldLen(); } -size_t KeepAlivePduSerializer::getSerializedSize() const { +size_t KeepAlivePduCreator::getSerializedSize() const { return FileDirectiveCreator::getWholePduSize(); } -void KeepAlivePduSerializer::updateDirectiveFieldLen() { +void KeepAlivePduCreator::updateDirectiveFieldLen() { if (this->getLargeFileFlag()) { this->setDirectiveDataFieldLen(8); } } -ReturnValue_t KeepAlivePduSerializer::serialize(uint8_t **buffer, size_t *size, size_t maxSize, - Endianness streamEndianness) const { +ReturnValue_t KeepAlivePduCreator::serialize(uint8_t **buffer, size_t *size, size_t maxSize, + Endianness streamEndianness) const { ReturnValue_t result = FileDirectiveCreator::serialize(buffer, size, maxSize, streamEndianness); if (result != returnvalue::OK) { return result; diff --git a/src/fsfw/cfdp/pdu/KeepAlivePduCreator.h b/src/fsfw/cfdp/pdu/KeepAlivePduCreator.h new file mode 100644 index 00000000..aa4bf0fd --- /dev/null +++ b/src/fsfw/cfdp/pdu/KeepAlivePduCreator.h @@ -0,0 +1,22 @@ +#ifndef FSFW_CFDP_PDU_KEEPALIVEPDUSERIALIZER_H_ +#define FSFW_CFDP_PDU_KEEPALIVEPDUSERIALIZER_H_ + +#include "fsfw/cfdp/FileSize.h" +#include "fsfw/cfdp/pdu/FileDirectiveCreator.h" + +class KeepAlivePduCreator : public FileDirectiveCreator { + public: + KeepAlivePduCreator(PduConfig& conf, cfdp::FileSize& progress); + + void updateDirectiveFieldLen(); + + [[nodiscard]] size_t getSerializedSize() const override; + + ReturnValue_t serialize(uint8_t** buffer, size_t* size, size_t maxSize, + Endianness streamEndianness) const override; + + private: + cfdp::FileSize& progress; +}; + +#endif /* FSFW_CFDP_PDU_KEEPALIVEPDUSERIALIZER_H_ */ diff --git a/src/fsfw/cfdp/pdu/KeepAlivePduDeserializer.h b/src/fsfw/cfdp/pdu/KeepAlivePduDeserializer.h deleted file mode 100644 index 1a8ca14d..00000000 --- a/src/fsfw/cfdp/pdu/KeepAlivePduDeserializer.h +++ /dev/null @@ -1,19 +0,0 @@ -#ifndef FSFW_SRC_FSFW_CFDP_PDU_KEEPALIVEPDUDESERIALIZER_H_ -#define FSFW_SRC_FSFW_CFDP_PDU_KEEPALIVEPDUDESERIALIZER_H_ - -#include "fsfw/cfdp/FileSize.h" -#include "fsfw/cfdp/pdu/FileDirectiveReader.h" - -class KeepAlivePduDeserializer : public FileDirectiveReader { - public: - KeepAlivePduDeserializer(const uint8_t* pduBuf, size_t maxSize, cfdp::FileSize& progress); - - ReturnValue_t parseData() override; - - cfdp::FileSize& getProgress(); - - private: - cfdp::FileSize& progress; -}; - -#endif /* FSFW_SRC_FSFW_CFDP_PDU_KEEPALIVEPDUDESERIALIZER_H_ */ diff --git a/src/fsfw/cfdp/pdu/KeepAlivePduDeserializer.cpp b/src/fsfw/cfdp/pdu/KeepAlivePduReader.cpp similarity index 56% rename from src/fsfw/cfdp/pdu/KeepAlivePduDeserializer.cpp rename to src/fsfw/cfdp/pdu/KeepAlivePduReader.cpp index 9686cf0a..d3362cf9 100644 --- a/src/fsfw/cfdp/pdu/KeepAlivePduDeserializer.cpp +++ b/src/fsfw/cfdp/pdu/KeepAlivePduReader.cpp @@ -1,10 +1,10 @@ -#include "KeepAlivePduDeserializer.h" +#include "KeepAlivePduReader.h" -KeepAlivePduDeserializer::KeepAlivePduDeserializer(const uint8_t* pduBuf, size_t maxSize, - cfdp::FileSize& progress) +KeepAlivePduReader::KeepAlivePduReader(const uint8_t* pduBuf, size_t maxSize, + cfdp::FileSize& progress) : FileDirectiveReader(pduBuf, maxSize), progress(progress) {} -ReturnValue_t KeepAlivePduDeserializer::parseData() { +ReturnValue_t KeepAlivePduReader::parseData() { ReturnValue_t result = FileDirectiveReader::parseData(); if (result != returnvalue::OK) { return result; @@ -15,4 +15,4 @@ ReturnValue_t KeepAlivePduDeserializer::parseData() { return progress.deSerialize(&buffer, &remLen, getEndianness()); } -cfdp::FileSize& KeepAlivePduDeserializer::getProgress() { return progress; } +cfdp::FileSize& KeepAlivePduReader::getProgress() { return progress; } diff --git a/src/fsfw/cfdp/pdu/KeepAlivePduReader.h b/src/fsfw/cfdp/pdu/KeepAlivePduReader.h new file mode 100644 index 00000000..38e061f1 --- /dev/null +++ b/src/fsfw/cfdp/pdu/KeepAlivePduReader.h @@ -0,0 +1,19 @@ +#ifndef FSFW_CFDP_PDU_KEEPALIVEREADER_H_ +#define FSFW_CFDP_PDU_KEEPALIVEREADER_H_ + +#include "fsfw/cfdp/FileSize.h" +#include "fsfw/cfdp/pdu/FileDirectiveReader.h" + +class KeepAlivePduReader : public FileDirectiveReader { + public: + KeepAlivePduReader(const uint8_t* pduBuf, size_t maxSize, cfdp::FileSize& progress); + + ReturnValue_t parseData() override; + + cfdp::FileSize& getProgress(); + + private: + cfdp::FileSize& progress; +}; + +#endif /* FSFW_CFDP_PDU_KEEPALIVEPDUREADER_H_ */ diff --git a/src/fsfw/cfdp/pdu/KeepAlivePduSerializer.h b/src/fsfw/cfdp/pdu/KeepAlivePduSerializer.h deleted file mode 100644 index 0fabeb0a..00000000 --- a/src/fsfw/cfdp/pdu/KeepAlivePduSerializer.h +++ /dev/null @@ -1,22 +0,0 @@ -#ifndef FSFW_SRC_FSFW_CFDP_PDU_KEEPALIVEPDUSERIALIZER_H_ -#define FSFW_SRC_FSFW_CFDP_PDU_KEEPALIVEPDUSERIALIZER_H_ - -#include "fsfw/cfdp/FileSize.h" -#include "fsfw/cfdp/pdu/FileDirectiveCreator.h" - -class KeepAlivePduSerializer : public FileDirectiveCreator { - public: - KeepAlivePduSerializer(PduConfig& conf, cfdp::FileSize& progress); - - void updateDirectiveFieldLen(); - - size_t getSerializedSize() const override; - - ReturnValue_t serialize(uint8_t** buffer, size_t* size, size_t maxSize, - Endianness streamEndianness) const override; - - private: - cfdp::FileSize& progress; -}; - -#endif /* FSFW_SRC_FSFW_CFDP_PDU_KEEPALIVEPDUSERIALIZER_H_ */ diff --git a/src/fsfw/cfdp/pdu/NakPduSerializer.cpp b/src/fsfw/cfdp/pdu/NakPduCreator.cpp similarity index 74% rename from src/fsfw/cfdp/pdu/NakPduSerializer.cpp rename to src/fsfw/cfdp/pdu/NakPduCreator.cpp index 7f5efa08..c4493fcb 100644 --- a/src/fsfw/cfdp/pdu/NakPduSerializer.cpp +++ b/src/fsfw/cfdp/pdu/NakPduCreator.cpp @@ -1,20 +1,18 @@ -#include "NakPduSerializer.h" +#include "NakPduCreator.h" -NakPduSerializer::NakPduSerializer(PduConfig &pduConf, NakInfo &nakInfo) +NakPduCreator::NakPduCreator(PduConfig &pduConf, NakInfo &nakInfo) : FileDirectiveCreator(pduConf, cfdp::FileDirectives::NAK, 0), nakInfo(nakInfo) { updateDirectiveFieldLen(); } -void NakPduSerializer::updateDirectiveFieldLen() { +void NakPduCreator::updateDirectiveFieldLen() { this->setDirectiveDataFieldLen(nakInfo.getSerializedSize(getLargeFileFlag())); } -size_t NakPduSerializer::getSerializedSize() const { - return FileDirectiveCreator::getWholePduSize(); -} +size_t NakPduCreator::getSerializedSize() const { return FileDirectiveCreator::getWholePduSize(); } -ReturnValue_t NakPduSerializer::serialize(uint8_t **buffer, size_t *size, size_t maxSize, - Endianness streamEndianness) const { +ReturnValue_t NakPduCreator::serialize(uint8_t **buffer, size_t *size, size_t maxSize, + Endianness streamEndianness) const { ReturnValue_t result = FileDirectiveCreator::serialize(buffer, size, maxSize, streamEndianness); if (result != returnvalue::OK) { return result; diff --git a/src/fsfw/cfdp/pdu/NakPduSerializer.h b/src/fsfw/cfdp/pdu/NakPduCreator.h similarity index 70% rename from src/fsfw/cfdp/pdu/NakPduSerializer.h rename to src/fsfw/cfdp/pdu/NakPduCreator.h index 12e1bae2..bfcff78d 100644 --- a/src/fsfw/cfdp/pdu/NakPduSerializer.h +++ b/src/fsfw/cfdp/pdu/NakPduCreator.h @@ -1,5 +1,5 @@ -#ifndef FSFW_SRC_FSFW_CFDP_PDU_NAKPDUSERIALIZER_H_ -#define FSFW_SRC_FSFW_CFDP_PDU_NAKPDUSERIALIZER_H_ +#ifndef FSFW_CFDP_PDU_NAKPDUSERIALIZER_H_ +#define FSFW_CFDP_PDU_NAKPDUSERIALIZER_H_ #include @@ -8,7 +8,7 @@ #include "fsfw/cfdp/definitions.h" #include "fsfw/cfdp/pdu/FileDirectiveCreator.h" -class NakPduSerializer : public FileDirectiveCreator { +class NakPduCreator : public FileDirectiveCreator { public: /** * @@ -18,9 +18,9 @@ class NakPduSerializer : public FileDirectiveCreator { * @param [in] segmentRequests Pointer to the start of a list of segment requests * @param segmentRequestLen Length of the segment request list to be serialized */ - NakPduSerializer(PduConfig& PduConf, NakInfo& nakInfo); + NakPduCreator(PduConfig& PduConf, NakInfo& nakInfo); - size_t getSerializedSize() const override; + [[nodiscard]] size_t getSerializedSize() const override; ReturnValue_t serialize(uint8_t** buffer, size_t* size, size_t maxSize, Endianness streamEndianness) const override; @@ -35,4 +35,4 @@ class NakPduSerializer : public FileDirectiveCreator { NakInfo& nakInfo; }; -#endif /* FSFW_SRC_FSFW_CFDP_PDU_NAKPDUSERIALIZER_H_ */ +#endif /* FSFW_CFDP_PDU_NAKPDUSERIALIZER_H_ */ diff --git a/src/fsfw/cfdp/pdu/NakPduDeserializer.h b/src/fsfw/cfdp/pdu/NakPduDeserializer.h deleted file mode 100644 index c119564d..00000000 --- a/src/fsfw/cfdp/pdu/NakPduDeserializer.h +++ /dev/null @@ -1,21 +0,0 @@ -#ifndef FSFW_SRC_FSFW_CFDP_PDU_NAKPDUDESERIALIZER_H_ -#define FSFW_SRC_FSFW_CFDP_PDU_NAKPDUDESERIALIZER_H_ - -#include "fsfw/cfdp/pdu/FileDirectiveReader.h" -#include "fsfw/cfdp/pdu/NakInfo.h" - -class NakPduDeserializer : public FileDirectiveReader { - public: - NakPduDeserializer(const uint8_t* pduBuf, size_t maxSize, NakInfo& info); - - /** - * This needs to be called before accessing the PDU fields to avoid segmentation faults. - * @return - */ - virtual ReturnValue_t parseData() override; - - private: - NakInfo& nakInfo; -}; - -#endif /* FSFW_SRC_FSFW_CFDP_PDU_NAKPDUDESERIALIZER_H_ */ diff --git a/src/fsfw/cfdp/pdu/NakPduDeserializer.cpp b/src/fsfw/cfdp/pdu/NakPduReader.cpp similarity index 90% rename from src/fsfw/cfdp/pdu/NakPduDeserializer.cpp rename to src/fsfw/cfdp/pdu/NakPduReader.cpp index c27e96be..c67774c0 100644 --- a/src/fsfw/cfdp/pdu/NakPduDeserializer.cpp +++ b/src/fsfw/cfdp/pdu/NakPduReader.cpp @@ -1,9 +1,9 @@ -#include "NakPduDeserializer.h" +#include "NakPduReader.h" -NakPduDeserializer::NakPduDeserializer(const uint8_t* pduBuf, size_t maxSize, NakInfo& info) +NakPduReader::NakPduReader(const uint8_t* pduBuf, size_t maxSize, NakInfo& info) : FileDirectiveReader(pduBuf, maxSize), nakInfo(info) {} -ReturnValue_t NakPduDeserializer::parseData() { +ReturnValue_t NakPduReader::parseData() { ReturnValue_t result = FileDirectiveReader::parseData(); if (result != returnvalue::OK) { return result; diff --git a/src/fsfw/cfdp/pdu/NakPduReader.h b/src/fsfw/cfdp/pdu/NakPduReader.h new file mode 100644 index 00000000..7e08229d --- /dev/null +++ b/src/fsfw/cfdp/pdu/NakPduReader.h @@ -0,0 +1,21 @@ +#ifndef FSFW_CFDP_PDU_NAKPDUDESERIALIZER_H_ +#define FSFW_CFDP_PDU_NAKPDUDESERIALIZER_H_ + +#include "fsfw/cfdp/pdu/FileDirectiveReader.h" +#include "fsfw/cfdp/pdu/NakInfo.h" + +class NakPduReader : public FileDirectiveReader { + public: + NakPduReader(const uint8_t* pduBuf, size_t maxSize, NakInfo& info); + + /** + * This needs to be called before accessing the PDU fields to avoid segmentation faults. + * @return + */ + ReturnValue_t parseData() override; + + private: + NakInfo& nakInfo; +}; + +#endif /* FSFW_CFDP_PDU_NAKPDUDESERIALIZER_H_ */ diff --git a/src/fsfw/cfdp/pdu/PromptPduSerializer.cpp b/src/fsfw/cfdp/pdu/PromptPduCreator.cpp similarity index 54% rename from src/fsfw/cfdp/pdu/PromptPduSerializer.cpp rename to src/fsfw/cfdp/pdu/PromptPduCreator.cpp index 0823e932..43077cf6 100644 --- a/src/fsfw/cfdp/pdu/PromptPduSerializer.cpp +++ b/src/fsfw/cfdp/pdu/PromptPduCreator.cpp @@ -1,16 +1,15 @@ -#include "PromptPduSerializer.h" +#include "PromptPduCreator.h" -PromptPduSerializer::PromptPduSerializer(PduConfig &conf, - cfdp::PromptResponseRequired responseRequired) +PromptPduCreator::PromptPduCreator(PduConfig &conf, cfdp::PromptResponseRequired responseRequired) : FileDirectiveCreator(conf, cfdp::FileDirectives::PROMPT, 1), responseRequired(responseRequired) {} -size_t PromptPduSerializer::getSerializedSize() const { +size_t PromptPduCreator::getSerializedSize() const { return FileDirectiveCreator::getWholePduSize(); } -ReturnValue_t PromptPduSerializer::serialize(uint8_t **buffer, size_t *size, size_t maxSize, - Endianness streamEndianness) const { +ReturnValue_t PromptPduCreator::serialize(uint8_t **buffer, size_t *size, size_t maxSize, + Endianness streamEndianness) const { ReturnValue_t result = FileDirectiveCreator::serialize(buffer, size, maxSize, streamEndianness); if (result != returnvalue::OK) { return result; diff --git a/src/fsfw/cfdp/pdu/PromptPduSerializer.h b/src/fsfw/cfdp/pdu/PromptPduCreator.h similarity index 77% rename from src/fsfw/cfdp/pdu/PromptPduSerializer.h rename to src/fsfw/cfdp/pdu/PromptPduCreator.h index 1abe362e..ccecab6e 100644 --- a/src/fsfw/cfdp/pdu/PromptPduSerializer.h +++ b/src/fsfw/cfdp/pdu/PromptPduCreator.h @@ -3,9 +3,9 @@ #include "fsfw/cfdp/pdu/FileDirectiveCreator.h" -class PromptPduSerializer : public FileDirectiveCreator { +class PromptPduCreator : public FileDirectiveCreator { public: - PromptPduSerializer(PduConfig& conf, cfdp::PromptResponseRequired responseRequired); + PromptPduCreator(PduConfig& conf, cfdp::PromptResponseRequired responseRequired); [[nodiscard]] size_t getSerializedSize() const override; diff --git a/src/fsfw/cfdp/pdu/PromptPduDeserializer.cpp b/src/fsfw/cfdp/pdu/PromptPduReader.cpp similarity index 65% rename from src/fsfw/cfdp/pdu/PromptPduDeserializer.cpp rename to src/fsfw/cfdp/pdu/PromptPduReader.cpp index 1bccee82..f554c3c9 100644 --- a/src/fsfw/cfdp/pdu/PromptPduDeserializer.cpp +++ b/src/fsfw/cfdp/pdu/PromptPduReader.cpp @@ -1,13 +1,13 @@ -#include "PromptPduDeserializer.h" +#include "PromptPduReader.h" -PromptPduDeserializer::PromptPduDeserializer(const uint8_t *pduBuf, size_t maxSize) +PromptPduReader::PromptPduReader(const uint8_t *pduBuf, size_t maxSize) : FileDirectiveReader(pduBuf, maxSize) {} -cfdp::PromptResponseRequired PromptPduDeserializer::getPromptResponseRequired() const { +cfdp::PromptResponseRequired PromptPduReader::getPromptResponseRequired() const { return responseRequired; } -ReturnValue_t PromptPduDeserializer::parseData() { +ReturnValue_t PromptPduReader::parseData() { ReturnValue_t result = FileDirectiveReader::parseData(); if (result != returnvalue::OK) { return result; diff --git a/src/fsfw/cfdp/pdu/PromptPduDeserializer.h b/src/fsfw/cfdp/pdu/PromptPduReader.h similarity index 78% rename from src/fsfw/cfdp/pdu/PromptPduDeserializer.h rename to src/fsfw/cfdp/pdu/PromptPduReader.h index 91ed5a9a..2afcb20e 100644 --- a/src/fsfw/cfdp/pdu/PromptPduDeserializer.h +++ b/src/fsfw/cfdp/pdu/PromptPduReader.h @@ -3,9 +3,9 @@ #include "fsfw/cfdp/pdu/FileDirectiveReader.h" -class PromptPduDeserializer : public FileDirectiveReader { +class PromptPduReader : public FileDirectiveReader { public: - PromptPduDeserializer(const uint8_t *pduBuf, size_t maxSize); + PromptPduReader(const uint8_t *pduBuf, size_t maxSize); [[nodiscard]] cfdp::PromptResponseRequired getPromptResponseRequired() const; ReturnValue_t parseData() override; diff --git a/unittests/cfdp/pdu/testKeepAlivePdu.cpp b/unittests/cfdp/pdu/testKeepAlivePdu.cpp index 34a529e9..9b0e9669 100644 --- a/unittests/cfdp/pdu/testKeepAlivePdu.cpp +++ b/unittests/cfdp/pdu/testKeepAlivePdu.cpp @@ -1,8 +1,8 @@ #include #include -#include "fsfw/cfdp/pdu/KeepAlivePduDeserializer.h" -#include "fsfw/cfdp/pdu/KeepAlivePduSerializer.h" +#include "fsfw/cfdp/pdu/KeepAlivePduCreator.h" +#include "fsfw/cfdp/pdu/KeepAlivePduReader.h" #include "fsfw/globalfunctions/arrayprinter.h" TEST_CASE("Keep Alive PDU", "[cfdp][pdu]") { @@ -19,7 +19,7 @@ TEST_CASE("Keep Alive PDU", "[cfdp][pdu]") { FileSize progress(0x50); SECTION("Serialize") { - KeepAlivePduSerializer serializer(pduConf, progress); + KeepAlivePduCreator serializer(pduConf, progress); result = serializer.serialize(&buffer, &sz, kaBuffer.size(), SerializeIF::Endianness::NETWORK); REQUIRE(result == returnvalue::OK); REQUIRE(kaBuffer[10] == cfdp::FileDirectives::KEEP_ALIVE); @@ -55,13 +55,13 @@ TEST_CASE("Keep Alive PDU", "[cfdp][pdu]") { } SECTION("Deserialize") { - KeepAlivePduSerializer serializer(pduConf, progress); + KeepAlivePduCreator serializer(pduConf, progress); result = serializer.serialize(&buffer, &sz, kaBuffer.size(), SerializeIF::Endianness::NETWORK); REQUIRE(result == returnvalue::OK); // Set another file size progress.setFileSize(200, false); - KeepAlivePduDeserializer reader(kaBuffer.data(), kaBuffer.size(), progress); + KeepAlivePduReader reader(kaBuffer.data(), kaBuffer.size(), progress); result = reader.parseData(); REQUIRE(result == returnvalue::OK); auto& progRef = reader.getProgress(); diff --git a/unittests/cfdp/pdu/testNakPdu.cpp b/unittests/cfdp/pdu/testNakPdu.cpp index 954979fc..f2779788 100644 --- a/unittests/cfdp/pdu/testNakPdu.cpp +++ b/unittests/cfdp/pdu/testNakPdu.cpp @@ -1,8 +1,8 @@ #include #include -#include "fsfw/cfdp/pdu/NakPduDeserializer.h" -#include "fsfw/cfdp/pdu/NakPduSerializer.h" +#include "fsfw/cfdp/pdu/NakPduCreator.h" +#include "fsfw/cfdp/pdu/NakPduReader.h" #include "fsfw/cfdp/pdu/PduConfig.h" #include "fsfw/globalfunctions/arrayprinter.h" @@ -21,7 +21,7 @@ TEST_CASE("NAK PDU", "[cfdp][pdu]") { FileSize endOfScope(1050); NakInfo info(startOfScope, endOfScope); SECTION("Serializer") { - NakPduSerializer serializer(pduConf, info); + NakPduCreator serializer(pduConf, info); result = serializer.serialize(&buffer, &sz, nakBuffer.size(), SerializeIF::Endianness::NETWORK); REQUIRE(result == returnvalue::OK); REQUIRE(serializer.getSerializedSize() == 19); @@ -87,13 +87,13 @@ TEST_CASE("NAK PDU", "[cfdp][pdu]") { } SECTION("Deserializer") { - NakPduSerializer serializer(pduConf, info); + NakPduCreator serializer(pduConf, info); result = serializer.serialize(&buffer, &sz, nakBuffer.size(), SerializeIF::Endianness::NETWORK); REQUIRE(result == returnvalue::OK); info.getStartOfScope().setFileSize(0, false); info.getEndOfScope().setFileSize(0, false); - NakPduDeserializer deserializer(nakBuffer.data(), nakBuffer.size(), info); + NakPduReader deserializer(nakBuffer.data(), nakBuffer.size(), info); result = deserializer.parseData(); REQUIRE(result == returnvalue::OK); REQUIRE(deserializer.getWholePduSize() == 19); @@ -112,7 +112,7 @@ TEST_CASE("NAK PDU", "[cfdp][pdu]") { result = serializer.serialize(&buffer, &sz, nakBuffer.size(), SerializeIF::Endianness::NETWORK); REQUIRE(result == returnvalue::OK); - NakPduDeserializer deserializeWithSegReqs(nakBuffer.data(), nakBuffer.size(), info); + NakPduReader deserializeWithSegReqs(nakBuffer.data(), nakBuffer.size(), info); result = deserializeWithSegReqs.parseData(); REQUIRE(result == returnvalue::OK); NakInfo::SegmentRequest* segReqsPtr = nullptr; @@ -126,14 +126,14 @@ TEST_CASE("NAK PDU", "[cfdp][pdu]") { REQUIRE(deserializeWithSegReqs.getPduDataFieldLen() == 25); REQUIRE(info.getSegmentRequestsLen() == 2); for (size_t idx = 0; idx < 34; idx++) { - NakPduDeserializer faultyDeserializer(nakBuffer.data(), idx, info); + NakPduReader faultyDeserializer(nakBuffer.data(), idx, info); result = faultyDeserializer.parseData(); REQUIRE(result != returnvalue::OK); } for (size_t pduFieldLen = 0; pduFieldLen < 25; pduFieldLen++) { nakBuffer[1] = (pduFieldLen >> 8) & 0xff; nakBuffer[2] = pduFieldLen & 0xff; - NakPduDeserializer faultyDeserializer(nakBuffer.data(), nakBuffer.size(), info); + NakPduReader faultyDeserializer(nakBuffer.data(), nakBuffer.size(), info); result = faultyDeserializer.parseData(); if (pduFieldLen == 9) { REQUIRE(info.getSegmentRequestsLen() == 0); diff --git a/unittests/cfdp/pdu/testPromptPdu.cpp b/unittests/cfdp/pdu/testPromptPdu.cpp index 1efd751d..538f6459 100644 --- a/unittests/cfdp/pdu/testPromptPdu.cpp +++ b/unittests/cfdp/pdu/testPromptPdu.cpp @@ -1,8 +1,8 @@ #include #include -#include "fsfw/cfdp/pdu/PromptPduDeserializer.h" -#include "fsfw/cfdp/pdu/PromptPduSerializer.h" +#include "fsfw/cfdp/pdu/PromptPduCreator.h" +#include "fsfw/cfdp/pdu/PromptPduReader.h" #include "fsfw/globalfunctions/arrayprinter.h" TEST_CASE("Prompt PDU", "[cfdp][pdu]") { @@ -17,7 +17,7 @@ TEST_CASE("Prompt PDU", "[cfdp][pdu]") { PduConfig pduConf(sourceId, destId, TransmissionModes::ACKNOWLEDGED, seqNum); SECTION("Serialize") { - PromptPduSerializer serializer(pduConf, cfdp::PromptResponseRequired::PROMPT_KEEP_ALIVE); + PromptPduCreator serializer(pduConf, cfdp::PromptResponseRequired::PROMPT_KEEP_ALIVE); result = serializer.serialize(&buffer, &sz, rawBuf.size(), SerializeIF::Endianness::NETWORK); REQUIRE(result == returnvalue::OK); REQUIRE(serializer.getWholePduSize() == 12); @@ -41,11 +41,11 @@ TEST_CASE("Prompt PDU", "[cfdp][pdu]") { } SECTION("Deserialize") { - PromptPduSerializer serializer(pduConf, cfdp::PromptResponseRequired::PROMPT_KEEP_ALIVE); + PromptPduCreator serializer(pduConf, cfdp::PromptResponseRequired::PROMPT_KEEP_ALIVE); result = serializer.serialize(&buffer, &sz, rawBuf.size(), SerializeIF::Endianness::NETWORK); REQUIRE(result == returnvalue::OK); - PromptPduDeserializer deserializer(rawBuf.data(), rawBuf.size()); + PromptPduReader deserializer(rawBuf.data(), rawBuf.size()); result = deserializer.parseData(); REQUIRE(result == returnvalue::OK); REQUIRE(deserializer.getPromptResponseRequired() == From 723f8749d42ba24b13bc7a1606e12139f7cfda5d Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Wed, 14 Sep 2022 19:52:33 +0200 Subject: [PATCH 118/169] bump changelog --- CHANGELOG.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 24bc89fc..d85ad754 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -36,6 +36,11 @@ and this project adheres to [Semantic Versioning](http://semver.org/). - mib module for the CFDP stack - PDU classes renamed from `...Serializer`/`...Deserializer` to `...Creator`/`...Reader` respetively + - Renamed `TcDistributor` to `TcDistributorBase` to prevent confusion + - Refactored `TcDisitributorBase` to be more flexible and usable for CFDP distribution + - Renamed `CCSDSDistributor` to `CcsdsDistributor` and add feature which allows it + to remove the CCSDS header when routing a packet. This allows CCSDS agnostic receiver + implementation without an extra component PR: https://egit.irs.uni-stuttgart.de/fsfw/fsfw/pulls/682/files # [v5.0.0] 25.07.2022 From ab7c3480f58009afb2feb584f684870a158b97e6 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Thu, 15 Sep 2022 10:30:22 +0200 Subject: [PATCH 119/169] storage manager update --- .../storagemanager/ConstStorageAccessor.cpp | 8 +-- .../storagemanager/ConstStorageAccessor.h | 13 ++-- src/fsfw/storagemanager/LocalPool.cpp | 59 ++++++++----------- src/fsfw/storagemanager/LocalPool.h | 24 ++++---- src/fsfw/storagemanager/PoolManager.h | 8 +-- src/fsfw/storagemanager/StorageAccessor.cpp | 4 +- src/fsfw/storagemanager/StorageAccessor.h | 7 ++- src/fsfw/storagemanager/StorageManagerIF.h | 56 ++++++++++++++---- 8 files changed, 103 insertions(+), 76 deletions(-) diff --git a/src/fsfw/storagemanager/ConstStorageAccessor.cpp b/src/fsfw/storagemanager/ConstStorageAccessor.cpp index f64334f7..e39fa36b 100644 --- a/src/fsfw/storagemanager/ConstStorageAccessor.cpp +++ b/src/fsfw/storagemanager/ConstStorageAccessor.cpp @@ -19,7 +19,7 @@ ConstStorageAccessor::~ConstStorageAccessor() { } } -ConstStorageAccessor::ConstStorageAccessor(ConstStorageAccessor&& other) +ConstStorageAccessor::ConstStorageAccessor(ConstStorageAccessor&& other) noexcept : constDataPointer(other.constDataPointer), storeId(other.storeId), size_(other.size_), @@ -30,7 +30,7 @@ ConstStorageAccessor::ConstStorageAccessor(ConstStorageAccessor&& other) other.store = nullptr; } -ConstStorageAccessor& ConstStorageAccessor::operator=(ConstStorageAccessor&& other) { +ConstStorageAccessor& ConstStorageAccessor::operator=(ConstStorageAccessor&& other) noexcept { constDataPointer = other.constDataPointer; storeId = other.storeId; store = other.store; @@ -84,7 +84,7 @@ void ConstStorageAccessor::print() const { arrayprinter::print(constDataPointer, size_); } -void ConstStorageAccessor::assignStore(StorageManagerIF* store) { +void ConstStorageAccessor::assignStore(StorageManagerIF* store_) { internalState = AccessState::ASSIGNED; - this->store = store; + store = store_; } diff --git a/src/fsfw/storagemanager/ConstStorageAccessor.h b/src/fsfw/storagemanager/ConstStorageAccessor.h index 9cad346c..0911c6d9 100644 --- a/src/fsfw/storagemanager/ConstStorageAccessor.h +++ b/src/fsfw/storagemanager/ConstStorageAccessor.h @@ -23,6 +23,7 @@ class ConstStorageAccessor { //! StorageManager classes have exclusive access to private variables. friend class PoolManager; friend class LocalPool; + friend class StorageManagerIF; public: /** @@ -30,7 +31,7 @@ class ConstStorageAccessor { * entry to access. * @param storeId */ - ConstStorageAccessor(store_address_t storeId); + explicit ConstStorageAccessor(store_address_t storeId); ConstStorageAccessor(store_address_t storeId, StorageManagerIF* store); /** @@ -43,7 +44,7 @@ class ConstStorageAccessor { * @brief Returns a pointer to the read-only data * @return */ - const uint8_t* data() const; + [[nodiscard]] const uint8_t* data() const; /** * @brief Copies the read-only data to the supplied pointer @@ -61,13 +62,13 @@ class ConstStorageAccessor { * Get the size of the data * @return */ - size_t size() const; + [[nodiscard]] size_t size() const; /** * Get the storage ID. * @return */ - store_address_t getId() const; + [[nodiscard]] store_address_t getId() const; void print() const; @@ -79,8 +80,8 @@ class ConstStorageAccessor { * @param * @return */ - ConstStorageAccessor& operator=(ConstStorageAccessor&&); - ConstStorageAccessor(ConstStorageAccessor&&); + ConstStorageAccessor& operator=(ConstStorageAccessor&&) noexcept; + ConstStorageAccessor(ConstStorageAccessor&&) noexcept; //! The copy ctor and copy assignemnt should be deleted implicitely //! according to https://foonathan.net/2019/02/special-member-functions/ diff --git a/src/fsfw/storagemanager/LocalPool.cpp b/src/fsfw/storagemanager/LocalPool.cpp index d907a9b3..970b05f5 100644 --- a/src/fsfw/storagemanager/LocalPool.cpp +++ b/src/fsfw/storagemanager/LocalPool.cpp @@ -29,7 +29,7 @@ LocalPool::LocalPool(object_id_t setObjectId, const LocalPoolConfig& poolConfig, } } -LocalPool::~LocalPool(void) {} +LocalPool::~LocalPool() = default; ReturnValue_t LocalPool::addData(store_address_t* storageId, const uint8_t* data, size_t size, bool ignoreFault) { @@ -48,22 +48,6 @@ ReturnValue_t LocalPool::getData(store_address_t packetId, const uint8_t** packe return status; } -ReturnValue_t LocalPool::getData(store_address_t storeId, ConstStorageAccessor& storeAccessor) { - uint8_t* tempData = nullptr; - ReturnValue_t status = modifyData(storeId, &tempData, &storeAccessor.size_); - storeAccessor.assignStore(this); - storeAccessor.constDataPointer = tempData; - return status; -} - -ConstAccessorPair LocalPool::getData(store_address_t storeId) { - uint8_t* tempData = nullptr; - ConstStorageAccessor constAccessor(storeId, this); - ReturnValue_t status = modifyData(storeId, &tempData, &constAccessor.size_); - constAccessor.constDataPointer = tempData; - return ConstAccessorPair(status, std::move(constAccessor)); -} - ReturnValue_t LocalPool::getFreeElement(store_address_t* storageId, const size_t size, uint8_t** pData, bool ignoreFault) { ReturnValue_t status = reserveSpace(size, storageId, ignoreFault); @@ -75,20 +59,6 @@ ReturnValue_t LocalPool::getFreeElement(store_address_t* storageId, const size_t return status; } -AccessorPair LocalPool::modifyData(store_address_t storeId) { - StorageAccessor accessor(storeId, this); - ReturnValue_t status = modifyData(storeId, &accessor.dataPointer, &accessor.size_); - accessor.assignConstPointer(); - return AccessorPair(status, std::move(accessor)); -} - -ReturnValue_t LocalPool::modifyData(store_address_t storeId, StorageAccessor& storeAccessor) { - storeAccessor.assignStore(this); - ReturnValue_t status = modifyData(storeId, &storeAccessor.dataPointer, &storeAccessor.size_); - storeAccessor.assignConstPointer(); - return status; -} - ReturnValue_t LocalPool::modifyData(store_address_t storeId, uint8_t** packetPtr, size_t* size) { ReturnValue_t status = returnvalue::FAILED; if (storeId.poolIndex >= NUMBER_OF_SUBPOOLS) { @@ -197,8 +167,7 @@ void LocalPool::clearStore() { } } -ReturnValue_t LocalPool::reserveSpace(const size_t size, store_address_t* storeId, - bool ignoreFault) { +ReturnValue_t LocalPool::reserveSpace(size_t size, store_address_t* storeId, bool ignoreFault) { ReturnValue_t status = getSubPoolIndex(size, &storeId->poolIndex); if (status != returnvalue::OK) { #if FSFW_CPP_OSTREAM_ENABLED == 1 @@ -349,3 +318,27 @@ bool LocalPool::hasDataAtId(store_address_t storeId) const { } return false; } + +ReturnValue_t LocalPool::getFreeElement(store_address_t* storeId, size_t size, uint8_t** pData) { + return StorageManagerIF::getFreeElement(storeId, size, pData); +} + +ConstAccessorPair LocalPool::getData(store_address_t storeId) { + return StorageManagerIF::getData(storeId); +} + +ReturnValue_t LocalPool::addData(store_address_t* storeId, const uint8_t* data, size_t size) { + return StorageManagerIF::addData(storeId, data, size); +} + +ReturnValue_t LocalPool::getData(store_address_t storeId, ConstStorageAccessor& accessor) { + return StorageManagerIF::getData(storeId, accessor); +} + +ReturnValue_t LocalPool::modifyData(store_address_t storeId, StorageAccessor& accessor) { + return StorageManagerIF::modifyData(storeId, accessor); +} + +AccessorPair LocalPool::modifyData(store_address_t storeId) { + return StorageManagerIF::modifyData(storeId); +} diff --git a/src/fsfw/storagemanager/LocalPool.h b/src/fsfw/storagemanager/LocalPool.h index a82da971..54d704e6 100644 --- a/src/fsfw/storagemanager/LocalPool.h +++ b/src/fsfw/storagemanager/LocalPool.h @@ -87,21 +87,23 @@ class LocalPool : public SystemObject, public StorageManagerIF { * Documentation: See StorageManagerIF.h */ ReturnValue_t addData(store_address_t* storeId, const uint8_t* data, size_t size, - bool ignoreFault = false) override; - ReturnValue_t getFreeElement(store_address_t* storeId, const size_t size, uint8_t** pData, - bool ignoreFault = false) override; + bool ignoreFault) override; + ReturnValue_t addData(store_address_t* storeId, const uint8_t* data, size_t size) override; + + ReturnValue_t getFreeElement(store_address_t* storeId, size_t size, uint8_t** pData) override; + ReturnValue_t getFreeElement(store_address_t* storeId, size_t size, uint8_t** pData, + bool ignoreFault) override; ConstAccessorPair getData(store_address_t storeId) override; - ReturnValue_t getData(store_address_t storeId, ConstStorageAccessor& constAccessor) override; + ReturnValue_t getData(store_address_t storeId, ConstStorageAccessor& accessor) override; ReturnValue_t getData(store_address_t storeId, const uint8_t** packet_ptr, size_t* size) override; AccessorPair modifyData(store_address_t storeId) override; - ReturnValue_t modifyData(store_address_t storeId, StorageAccessor& storeAccessor) override; ReturnValue_t modifyData(store_address_t storeId, uint8_t** packet_ptr, size_t* size) override; + ReturnValue_t modifyData(store_address_t storeId, StorageAccessor& accessor) override; - virtual ReturnValue_t deleteData(store_address_t storeId) override; - virtual ReturnValue_t deleteData(uint8_t* ptr, size_t size, - store_address_t* storeId = nullptr) override; + ReturnValue_t deleteData(store_address_t storeId) override; + ReturnValue_t deleteData(uint8_t* ptr, size_t size, store_address_t* storeId) override; /** * Get the total size of allocated memory for pool data. @@ -131,8 +133,8 @@ class LocalPool : public SystemObject, public StorageManagerIF { * Get number sub pools. Each pool has pages with a specific bucket size. * @return */ - max_subpools_t getNumberOfSubPools() const override; - bool hasDataAtId(store_address_t storeId) const override; + [[nodiscard]] max_subpools_t getNumberOfSubPools() const override; + [[nodiscard]] bool hasDataAtId(store_address_t storeId) const override; protected: /** @@ -142,7 +144,7 @@ class LocalPool : public SystemObject, public StorageManagerIF { * @return - returnvalue::OK on success, * - the return codes of #getPoolIndex or #findEmpty otherwise. */ - virtual ReturnValue_t reserveSpace(const size_t size, store_address_t* address, bool ignoreFault); + virtual ReturnValue_t reserveSpace(size_t size, store_address_t* address, bool ignoreFault); private: /** diff --git a/src/fsfw/storagemanager/PoolManager.h b/src/fsfw/storagemanager/PoolManager.h index 0951a518..eaa978ef 100644 --- a/src/fsfw/storagemanager/PoolManager.h +++ b/src/fsfw/storagemanager/PoolManager.h @@ -27,7 +27,7 @@ class PoolManager : public LocalPool { * @brief In the PoolManager's destructor all allocated memory * is freed. */ - virtual ~PoolManager(); + ~PoolManager() override; /** * Set the default mutex timeout for internal calls. @@ -40,8 +40,7 @@ class PoolManager : public LocalPool { * which wraps LocalPool calls with a mutex protection. */ ReturnValue_t deleteData(store_address_t) override; - ReturnValue_t deleteData(uint8_t* buffer, size_t size, - store_address_t* storeId = nullptr) override; + ReturnValue_t deleteData(uint8_t* buffer, size_t size, store_address_t* storeId) override; /** * The developer is allowed to lock the mutex in case the lock needs @@ -58,8 +57,7 @@ class PoolManager : public LocalPool { //! Default mutex timeout value to prevent permanent blocking. uint32_t mutexTimeoutMs = 20; - ReturnValue_t reserveSpace(const size_t size, store_address_t* address, - bool ignoreFault) override; + ReturnValue_t reserveSpace(size_t size, store_address_t* address, bool ignoreFault) override; /** * @brief The mutex is created in the constructor and makes diff --git a/src/fsfw/storagemanager/StorageAccessor.cpp b/src/fsfw/storagemanager/StorageAccessor.cpp index 8a96dcec..b576a113 100644 --- a/src/fsfw/storagemanager/StorageAccessor.cpp +++ b/src/fsfw/storagemanager/StorageAccessor.cpp @@ -10,7 +10,7 @@ StorageAccessor::StorageAccessor(store_address_t storeId) : ConstStorageAccessor StorageAccessor::StorageAccessor(store_address_t storeId, StorageManagerIF* store) : ConstStorageAccessor(storeId, store) {} -StorageAccessor& StorageAccessor::operator=(StorageAccessor&& other) { +StorageAccessor& StorageAccessor::operator=(StorageAccessor&& other) noexcept { // Call the parent move assignment and also assign own member. dataPointer = other.dataPointer; ConstStorageAccessor::operator=(std::move(other)); @@ -18,7 +18,7 @@ StorageAccessor& StorageAccessor::operator=(StorageAccessor&& other) { } // Call the parent move ctor and also transfer own member. -StorageAccessor::StorageAccessor(StorageAccessor&& other) +StorageAccessor::StorageAccessor(StorageAccessor&& other) noexcept : ConstStorageAccessor(std::move(other)), dataPointer(other.dataPointer) {} ReturnValue_t StorageAccessor::getDataCopy(uint8_t* pointer, size_t maxSize) { diff --git a/src/fsfw/storagemanager/StorageAccessor.h b/src/fsfw/storagemanager/StorageAccessor.h index 5e8b25e4..b6c5dc14 100644 --- a/src/fsfw/storagemanager/StorageAccessor.h +++ b/src/fsfw/storagemanager/StorageAccessor.h @@ -12,9 +12,10 @@ class StorageAccessor : public ConstStorageAccessor { //! StorageManager classes have exclusive access to private variables. friend class PoolManager; friend class LocalPool; + friend class StorageManagerIF; public: - StorageAccessor(store_address_t storeId); + explicit StorageAccessor(store_address_t storeId); StorageAccessor(store_address_t storeId, StorageManagerIF* store); /** @@ -25,8 +26,8 @@ class StorageAccessor : public ConstStorageAccessor { * @param * @return */ - StorageAccessor& operator=(StorageAccessor&&); - StorageAccessor(StorageAccessor&&); + StorageAccessor& operator=(StorageAccessor&&) noexcept; + StorageAccessor(StorageAccessor&&) noexcept; ReturnValue_t write(uint8_t* data, size_t size, uint16_t offset = 0); uint8_t* data(); diff --git a/src/fsfw/storagemanager/StorageManagerIF.h b/src/fsfw/storagemanager/StorageManagerIF.h index 228d380b..2845e581 100644 --- a/src/fsfw/storagemanager/StorageManagerIF.h +++ b/src/fsfw/storagemanager/StorageManagerIF.h @@ -67,7 +67,12 @@ class StorageManagerIF { * @returnvalue::FAILED if data could not be added, storageId is unchanged then. */ virtual ReturnValue_t addData(store_address_t* storageId, const uint8_t* data, size_t size, - bool ignoreFault = false) = 0; + bool ignoreFault) = 0; + + virtual ReturnValue_t addData(store_address_t* storageId, const uint8_t* data, size_t size) { + return addData(storageId, data, size, false); + } + /** * @brief With deleteData, the storageManager frees the memory region * identified by packet_id. @@ -86,9 +91,10 @@ class StorageManagerIF { * @return @li returnvalue::OK on success. * @li failure code if deletion did not work */ - virtual ReturnValue_t deleteData(uint8_t* buffer, size_t size, - store_address_t* storeId = nullptr) = 0; - + virtual ReturnValue_t deleteData(uint8_t* buffer, size_t size, store_address_t* storeId) = 0; + virtual ReturnValue_t deleteData(uint8_t* buffer, size_t size) { + return deleteData(buffer, size, nullptr); + } /** * @brief Access the data by supplying a store ID. * @details @@ -97,7 +103,13 @@ class StorageManagerIF { * @param storeId * @return Pair of return value and a ConstStorageAccessor instance */ - virtual ConstAccessorPair getData(store_address_t storeId) = 0; + virtual ConstAccessorPair getData(store_address_t storeId) { + uint8_t* tempData = nullptr; + ConstStorageAccessor constAccessor(storeId, this); + ReturnValue_t status = modifyData(storeId, &tempData, &constAccessor.size_); + constAccessor.constDataPointer = tempData; + return {status, std::move(constAccessor)}; + } /** * @brief Access the data by supplying a store ID and a helper @@ -106,7 +118,13 @@ class StorageManagerIF { * @param constAccessor Wrapper function to access store data. * @return */ - virtual ReturnValue_t getData(store_address_t storeId, ConstStorageAccessor& constAccessor) = 0; + virtual ReturnValue_t getData(store_address_t storeId, ConstStorageAccessor& accessor) { + uint8_t* tempData = nullptr; + ReturnValue_t status = modifyData(storeId, &tempData, &accessor.size_); + accessor.assignStore(this); + accessor.constDataPointer = tempData; + return status; + } /** * @brief getData returns an address to data and the size of the data @@ -127,7 +145,12 @@ class StorageManagerIF { * @param storeId * @return Pair of return value and StorageAccessor helper */ - virtual AccessorPair modifyData(store_address_t storeId) = 0; + virtual AccessorPair modifyData(store_address_t storeId) { + StorageAccessor accessor(storeId, this); + ReturnValue_t status = modifyData(storeId, &accessor.dataPointer, &accessor.size_); + accessor.assignConstPointer(); + return {status, std::move(accessor)}; + } /** * Modify data by supplying a store ID and a StorageAccessor helper instance. @@ -135,7 +158,12 @@ class StorageManagerIF { * @param accessor Helper class to access the modifiable data. * @return */ - virtual ReturnValue_t modifyData(store_address_t storeId, StorageAccessor& accessor) = 0; + virtual ReturnValue_t modifyData(store_address_t storeId, StorageAccessor& accessor) { + accessor.assignStore(this); + ReturnValue_t status = modifyData(storeId, &accessor.dataPointer, &accessor.size_); + accessor.assignConstPointer(); + return status; + } /** * Get pointer and size of modifiable data by supplying the storeId @@ -154,12 +182,16 @@ class StorageManagerIF { * written to p_data! * @param storageId A pointer to the storageId to retrieve. * @param size The size of the space to be reserved. - * @param p_data A pointer to the element data is returned here. - * @return Returns @li returnvalue::OK if data was added. + * @param dataPtr A pointer to the element data is returned here. + * @return Returns @returnvalue::OK if data was added. * @returnvalue::FAILED if data could not be added, storageId is unchanged then. */ - virtual ReturnValue_t getFreeElement(store_address_t* storageId, size_t size, uint8_t** p_data, - bool ignoreFault = false) = 0; + virtual ReturnValue_t getFreeElement(store_address_t* storageId, size_t size, uint8_t** dataPtr, + bool ignoreFault) = 0; + + virtual ReturnValue_t getFreeElement(store_address_t* storageId, size_t size, uint8_t** dataPtr) { + return getFreeElement(storageId, size, dataPtr, false); + } [[nodiscard]] virtual bool hasDataAtId(store_address_t storeId) const = 0; From b3c0e2461154dcbacbd7ba958dff58fdd9289f44 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Thu, 15 Sep 2022 10:31:55 +0200 Subject: [PATCH 120/169] bump changelog --- CHANGELOG.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3fe567de..da557d70 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -24,6 +24,10 @@ and this project adheres to [Semantic Versioning](http://semver.org/). for other modules PR: https://egit.irs.uni-stuttgart.de/fsfw/fsfw/pulls/655 which also includes a migration guide +- Move some generic `StorageManagerIF` implementations from `LocalPool` to + interface itself so it can be re-used more easily. Also add new + abstract function `bool hasDataAtId(store_address_t storeId) const`. + PR: # [v5.0.0] 25.07.2022 From e063b44899a3e6a74b0a54b9ae1533af723cec83 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Thu, 15 Sep 2022 10:32:38 +0200 Subject: [PATCH 121/169] add link to PR --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index da557d70..476632df 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -27,7 +27,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/). - Move some generic `StorageManagerIF` implementations from `LocalPool` to interface itself so it can be re-used more easily. Also add new abstract function `bool hasDataAtId(store_address_t storeId) const`. - PR: + PR: https://egit.irs.uni-stuttgart.de/fsfw/fsfw/pulls/685 # [v5.0.0] 25.07.2022 From 954c749de023934f73272a2dcfe07fcfdd40dae7 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Thu, 15 Sep 2022 16:02:46 +0200 Subject: [PATCH 122/169] additional docs --- src/fsfw/filesystem/HasFileSystemIF.h | 6 +++++- src/fsfw_hal/host/HostFilesystem.cpp | 4 +++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/src/fsfw/filesystem/HasFileSystemIF.h b/src/fsfw/filesystem/HasFileSystemIF.h index ee8c5f91..c86d12b9 100644 --- a/src/fsfw/filesystem/HasFileSystemIF.h +++ b/src/fsfw/filesystem/HasFileSystemIF.h @@ -83,7 +83,11 @@ class HasFileSystemIF { virtual ReturnValue_t truncateFile(FilesystemParams params) = 0; /** - * @brief Generic function to append to file. + * @brief Generic function to write to a file. + * + * @details + * Implementations should not truncate the file. This is equivalent to opening a file with "r+" on Unix systems + * or using ios::out | ios::in with the C++ API. * @param fileOpInfo General information: File name, size to write, offset, additional arguments * @param data The data to write to the file */ diff --git a/src/fsfw_hal/host/HostFilesystem.cpp b/src/fsfw_hal/host/HostFilesystem.cpp index 6dc099b1..fe593f27 100644 --- a/src/fsfw_hal/host/HostFilesystem.cpp +++ b/src/fsfw_hal/host/HostFilesystem.cpp @@ -18,7 +18,9 @@ ReturnValue_t HostFilesystem::writeToFile(FileOpParams params, const uint8_t *da if (not exists(path)) { return HasFileSystemIF::FILE_DOES_NOT_EXIST; } - ofstream file(path, ios::binary | ios::out); + // This is equivalent to "r+" mode, which is what we need here. Only using ::out would truncate + // the file + ofstream file(path, ios::binary | ios::out | ios::in); if (file.fail()) { return HasFileSystemIF::GENERIC_FILE_ERROR; } From 2fee2fdff591c0ca44480b493d90b4c86f78a622 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Thu, 15 Sep 2022 16:20:52 +0200 Subject: [PATCH 123/169] unittest which would have caught this --- src/fsfw/filesystem/HasFileSystemIF.h | 4 ++-- unittests/hal/testHostFilesystem.cpp | 34 ++++++++++++++++++++++++--- 2 files changed, 33 insertions(+), 5 deletions(-) diff --git a/src/fsfw/filesystem/HasFileSystemIF.h b/src/fsfw/filesystem/HasFileSystemIF.h index c86d12b9..6f7112ad 100644 --- a/src/fsfw/filesystem/HasFileSystemIF.h +++ b/src/fsfw/filesystem/HasFileSystemIF.h @@ -86,8 +86,8 @@ class HasFileSystemIF { * @brief Generic function to write to a file. * * @details - * Implementations should not truncate the file. This is equivalent to opening a file with "r+" on Unix systems - * or using ios::out | ios::in with the C++ API. + * Implementations should not truncate the file. This is equivalent to opening a file with "r+" + * on Unix systems or using ios::out | ios::in with the C++ API. * @param fileOpInfo General information: File name, size to write, offset, additional arguments * @param data The data to write to the file */ diff --git a/unittests/hal/testHostFilesystem.cpp b/unittests/hal/testHostFilesystem.cpp index 3873d5e9..e33b30cc 100644 --- a/unittests/hal/testHostFilesystem.cpp +++ b/unittests/hal/testHostFilesystem.cpp @@ -1,6 +1,9 @@ +#include + #include #include #include +#include #include "fsfw/serialize/SerializeIF.h" #include "fsfw_hal/host/HostFilesystem.h" @@ -70,12 +73,37 @@ TEST_CASE("Host Filesystem", "[hal][host]") { returnvalue::OK); CHECK(fs::file_size(file0) == data.size()); ifstream ifile(file0); - char readBuf[524]{}; - ifile.read(readBuf, sizeof(readBuf)); - std::string readBackString(readBuf); + std::array readBuf{}; + ifile.read(readBuf.data(), sizeof(readBuf)); + std::string readBackString(readBuf.data()); CHECK(data == readBackString); } + SECTION("Write To File, Check Not Truncated") { + std::random_device dev; + std::mt19937 rng(dev()); + std::uniform_int_distribution distU8(1, 255); + std::array randData{}; + for (uint8_t& byte : randData) { + byte = distU8(rng); + } + FileOpParams params(file0.c_str(), randData.size() - 256); + REQUIRE(hostFs.createFile(params.fsParams) == returnvalue::OK); + CHECK(fs::is_regular_file(file0)); + REQUIRE(fs::exists(file0)); + // Write first file chunk + CHECK(hostFs.writeToFile(params, randData.cbegin()) == returnvalue::OK); + params.offset = 256; + CHECK(hostFs.writeToFile(params, randData.cbegin() + 256) == returnvalue::OK); + std::ifstream rf(file0, ios::binary); + std::array readBack{}; + REQUIRE(std::filesystem::file_size(file0) == 512); + rf.read(reinterpret_cast(readBack.data()), readBack.size()); + for (size_t i = 0; i < 512; i++) { + CHECK(randData[i] == readBack[i]); + } + } + SECTION("Read From File") { std::string data = "hello world!"; FileOpParams params(file0.c_str(), data.size()); From 54762232a412b32d8451821741501bad3c52b858 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Thu, 15 Sep 2022 16:46:09 +0200 Subject: [PATCH 124/169] refactoring and condition code to strin converter --- src/fsfw/cfdp/CMakeLists.txt | 2 +- src/fsfw/cfdp/definitions.h | 3 +- src/fsfw/cfdp/handler/FaultHandlerBase.cpp | 14 ++--- src/fsfw/cfdp/handler/FaultHandlerBase.h | 37 ++++++------- src/fsfw/cfdp/handler/UserBase.h | 10 ++-- src/fsfw/cfdp/helpers.cpp | 52 +++++++++++++++++++ src/fsfw/cfdp/helpers.h | 11 ++++ src/fsfw/cfdp/pdu/AckInfo.cpp | 6 +-- src/fsfw/cfdp/pdu/AckInfo.h | 8 +-- src/fsfw/cfdp/pdu/AckPduCreator.cpp | 2 +- src/fsfw/cfdp/pdu/AckPduReader.cpp | 2 +- src/fsfw/cfdp/pdu/EofInfo.cpp | 10 ++-- src/fsfw/cfdp/pdu/EofInfo.h | 8 +-- src/fsfw/cfdp/pdu/EofPduCreator.cpp | 2 +- src/fsfw/cfdp/pdu/EofPduReader.cpp | 4 +- src/fsfw/cfdp/pdu/FinishedInfo.cpp | 6 +-- src/fsfw/cfdp/pdu/FinishedInfo.h | 8 +-- src/fsfw/cfdp/pdu/FinishedPduReader.cpp | 8 +-- src/fsfw/cfdp/pdu/FinishedPduReader.h | 2 +- src/fsfw/cfdp/tlv/FaultHandlerOverrideTlv.cpp | 4 +- src/fsfw/cfdp/tlv/FaultHandlerOverrideTlv.h | 4 +- 21 files changed, 134 insertions(+), 69 deletions(-) create mode 100644 src/fsfw/cfdp/helpers.cpp create mode 100644 src/fsfw/cfdp/helpers.h diff --git a/src/fsfw/cfdp/CMakeLists.txt b/src/fsfw/cfdp/CMakeLists.txt index 30a7c700..f4d60201 100644 --- a/src/fsfw/cfdp/CMakeLists.txt +++ b/src/fsfw/cfdp/CMakeLists.txt @@ -1,5 +1,5 @@ target_sources(${LIB_FSFW_NAME} PRIVATE CfdpMessage.cpp CfdpDistributor.cpp - VarLenFields.cpp) + VarLenFields.cpp helpers.cpp) add_subdirectory(pdu) add_subdirectory(tlv) diff --git a/src/fsfw/cfdp/definitions.h b/src/fsfw/cfdp/definitions.h index 35c4c5f8..e6297bd7 100644 --- a/src/fsfw/cfdp/definitions.h +++ b/src/fsfw/cfdp/definitions.h @@ -82,7 +82,7 @@ enum FileDirectives : uint8_t { KEEP_ALIVE = 0x0c }; -enum ConditionCode : uint8_t { +enum ConditionCodes : uint8_t { NO_CONDITION_FIELD = 0xff, NO_ERROR = 0b0000, POSITIVE_ACK_LIMIT_REACHED = 0b0001, @@ -99,6 +99,7 @@ enum ConditionCode : uint8_t { CANCEL_REQUEST_RECEIVED = 0b1111 }; + enum FaultHandlerCodes { RESERVED = 0b0000, NOTICE_OF_CANCELLATION = 0b0001, diff --git a/src/fsfw/cfdp/handler/FaultHandlerBase.cpp b/src/fsfw/cfdp/handler/FaultHandlerBase.cpp index 1dbfce0d..0531846c 100644 --- a/src/fsfw/cfdp/handler/FaultHandlerBase.cpp +++ b/src/fsfw/cfdp/handler/FaultHandlerBase.cpp @@ -5,7 +5,7 @@ namespace cfdp { FaultHandlerBase::FaultHandlerBase() = default; FaultHandlerBase::~FaultHandlerBase() = default; -bool FaultHandlerBase::getFaultHandler(cfdp::ConditionCode code, +bool FaultHandlerBase::getFaultHandler(cfdp::ConditionCodes code, cfdp::FaultHandlerCodes& handler) const { auto iter = faultHandlerMap.find(code); if (iter == faultHandlerMap.end()) { @@ -15,7 +15,7 @@ bool FaultHandlerBase::getFaultHandler(cfdp::ConditionCode code, return true; } -bool FaultHandlerBase::setFaultHandler(cfdp::ConditionCode code, cfdp::FaultHandlerCodes handler) { +bool FaultHandlerBase::setFaultHandler(cfdp::ConditionCodes code, cfdp::FaultHandlerCodes handler) { if (not faultHandlerMap.contains(code)) { return false; } @@ -29,19 +29,19 @@ bool FaultHandlerBase::setFaultHandler(cfdp::ConditionCode code, cfdp::FaultHand return true; } -bool FaultHandlerBase::reportFault(cfdp::ConditionCode code) { +bool FaultHandlerBase::reportFault(cfdp::TransactionId& id, cfdp::ConditionCodes code) { if (not faultHandlerMap.contains(code)) { return false; } cfdp::FaultHandlerCodes fh = faultHandlerMap[code]; if (fh == cfdp::FaultHandlerCodes::IGNORE_ERROR) { - ignoreCb(code); + ignoreCb(id, code); } else if (fh == cfdp::FaultHandlerCodes::ABANDON_TRANSACTION) { - abandonCb(code); + abandonCb(id, code); } else if (fh == cfdp::FaultHandlerCodes::NOTICE_OF_CANCELLATION) { - noticeOfCancellationCb(code); + noticeOfCancellationCb(id, code); } else if (fh == cfdp::FaultHandlerCodes::NOTICE_OF_SUSPENSION) { - noticeOfSuspensionCb(code); + noticeOfSuspensionCb(id, code); } else { // Should never happen, but use defensive programming return false; diff --git a/src/fsfw/cfdp/handler/FaultHandlerBase.h b/src/fsfw/cfdp/handler/FaultHandlerBase.h index 48b9c42e..0c7f534c 100644 --- a/src/fsfw/cfdp/handler/FaultHandlerBase.h +++ b/src/fsfw/cfdp/handler/FaultHandlerBase.h @@ -3,6 +3,7 @@ #include +#include "fsfw/cfdp/VarLenFields.h" #include "fsfw/cfdp/definitions.h" namespace cfdp { @@ -42,33 +43,33 @@ class FaultHandlerBase { * - true if the condition code is valid * - false otherwise */ - bool getFaultHandler(cfdp::ConditionCode code, cfdp::FaultHandlerCodes& handler) const; + bool getFaultHandler(cfdp::ConditionCodes code, cfdp::FaultHandlerCodes& handler) const; - bool setFaultHandler(cfdp::ConditionCode code, cfdp::FaultHandlerCodes handler); + bool setFaultHandler(cfdp::ConditionCodes code, cfdp::FaultHandlerCodes handler); - bool reportFault(cfdp::ConditionCode code); + bool reportFault(cfdp::TransactionId& id, cfdp::ConditionCodes code); - virtual void noticeOfSuspensionCb(cfdp::ConditionCode code) = 0; - virtual void noticeOfCancellationCb(cfdp::ConditionCode code) = 0; - virtual void abandonCb(cfdp::ConditionCode code) = 0; - virtual void ignoreCb(cfdp::ConditionCode code) = 0; + virtual void noticeOfSuspensionCb(cfdp::TransactionId& id, cfdp::ConditionCodes code) = 0; + virtual void noticeOfCancellationCb(cfdp::TransactionId& id, cfdp::ConditionCodes code) = 0; + virtual void abandonCb(cfdp::TransactionId& id, cfdp::ConditionCodes code) = 0; + virtual void ignoreCb(cfdp::TransactionId& id, cfdp::ConditionCodes code) = 0; private: - etl::flat_map faultHandlerMap = { - etl::pair{cfdp::ConditionCode::POSITIVE_ACK_LIMIT_REACHED, + etl::flat_map faultHandlerMap = { + etl::pair{cfdp::ConditionCodes::POSITIVE_ACK_LIMIT_REACHED, cfdp::FaultHandlerCodes::IGNORE_ERROR}, - etl::pair{cfdp::ConditionCode::KEEP_ALIVE_LIMIT_REACHED, + etl::pair{cfdp::ConditionCodes::KEEP_ALIVE_LIMIT_REACHED, cfdp::FaultHandlerCodes::IGNORE_ERROR}, - etl::pair{cfdp::ConditionCode::INVALID_TRANSMISSION_MODE, + etl::pair{cfdp::ConditionCodes::INVALID_TRANSMISSION_MODE, cfdp::FaultHandlerCodes::IGNORE_ERROR}, - etl::pair{cfdp::ConditionCode::FILE_CHECKSUM_FAILURE, cfdp::FaultHandlerCodes::IGNORE_ERROR}, - etl::pair{cfdp::ConditionCode::FILE_SIZE_ERROR, cfdp::FaultHandlerCodes::IGNORE_ERROR}, - etl::pair{cfdp::ConditionCode::NAK_LIMIT_REACHED, cfdp::FaultHandlerCodes::IGNORE_ERROR}, - etl::pair{cfdp::ConditionCode::INACTIVITY_DETECTED, cfdp::FaultHandlerCodes::IGNORE_ERROR}, - etl::pair{cfdp::ConditionCode::UNSUPPORTED_CHECKSUM_TYPE, + etl::pair{cfdp::ConditionCodes::FILE_CHECKSUM_FAILURE, cfdp::FaultHandlerCodes::IGNORE_ERROR}, + etl::pair{cfdp::ConditionCodes::FILE_SIZE_ERROR, cfdp::FaultHandlerCodes::IGNORE_ERROR}, + etl::pair{cfdp::ConditionCodes::NAK_LIMIT_REACHED, cfdp::FaultHandlerCodes::IGNORE_ERROR}, + etl::pair{cfdp::ConditionCodes::INACTIVITY_DETECTED, cfdp::FaultHandlerCodes::IGNORE_ERROR}, + etl::pair{cfdp::ConditionCodes::UNSUPPORTED_CHECKSUM_TYPE, cfdp::FaultHandlerCodes::IGNORE_ERROR}, - etl::pair{cfdp::ConditionCode::FILESTORE_REJECTION, cfdp::FaultHandlerCodes::IGNORE_ERROR}, - etl::pair{cfdp::ConditionCode::CHECK_LIMIT_REACHED, cfdp::FaultHandlerCodes::IGNORE_ERROR}}; + etl::pair{cfdp::ConditionCodes::FILESTORE_REJECTION, cfdp::FaultHandlerCodes::IGNORE_ERROR}, + etl::pair{cfdp::ConditionCodes::CHECK_LIMIT_REACHED, cfdp::FaultHandlerCodes::IGNORE_ERROR}}; }; } // namespace cfdp diff --git a/src/fsfw/cfdp/handler/UserBase.h b/src/fsfw/cfdp/handler/UserBase.h index e367b4a8..4ff5eb96 100644 --- a/src/fsfw/cfdp/handler/UserBase.h +++ b/src/fsfw/cfdp/handler/UserBase.h @@ -14,12 +14,12 @@ namespace cfdp { struct TransactionFinishedParams { - TransactionFinishedParams(const TransactionId& id, ConditionCode code, FileDeliveryCode delivCode, + TransactionFinishedParams(const TransactionId& id, ConditionCodes code, FileDeliveryCode delivCode, FileDeliveryStatus status) : id(id), condCode(code), status(status), deliveryCode(delivCode) {} const TransactionId& id; - ConditionCode condCode; + ConditionCodes condCode; FileDeliveryStatus status; FileDeliveryCode deliveryCode; std::vector fsResponses; @@ -85,10 +85,10 @@ class UserBase { virtual void metadataRecvdIndication(const MetadataRecvdParams& params) = 0; virtual void fileSegmentRecvdIndication(const FileSegmentRecvdParams& params) = 0; virtual void reportIndication(const TransactionId& id, StatusReportIF& report) = 0; - virtual void suspendedIndication(const TransactionId& id, ConditionCode code) = 0; + virtual void suspendedIndication(const TransactionId& id, ConditionCodes code) = 0; virtual void resumedIndication(const TransactionId& id, size_t progress) = 0; - virtual void faultIndication(const TransactionId& id, ConditionCode code, size_t progress) = 0; - virtual void abandonedIndication(const TransactionId& id, ConditionCode code, + virtual void faultIndication(const TransactionId& id, ConditionCodes code, size_t progress) = 0; + virtual void abandonedIndication(const TransactionId& id, ConditionCodes code, size_t progress) = 0; virtual void eofRecvIndication(const TransactionId& id) = 0; diff --git a/src/fsfw/cfdp/helpers.cpp b/src/fsfw/cfdp/helpers.cpp new file mode 100644 index 00000000..49839e1f --- /dev/null +++ b/src/fsfw/cfdp/helpers.cpp @@ -0,0 +1,52 @@ +#include "helpers.h" + +const char* COND_CODE_STRINGS[14] = { + "Unknown", + "No Error", + "Positive ACK Limit Reached", + "Keep Alive Limit Reached", + "Invalid Transmission Mode", + "Filestore Rejection", + "File Checksum Failure", + "File Size Error", + "NAK limit reached", + "Inactivity Detected", + "Check Limit Reached", + "Unsupported Checksum Type", + "Suspend Request Received", + "Cancel Request Received" +}; + +const char* cfdp::getConditionCodeString(cfdp::ConditionCodes code) { + switch (code) { + case NO_CONDITION_FIELD: + return COND_CODE_STRINGS[0]; + case NO_ERROR: + return COND_CODE_STRINGS[1]; + case POSITIVE_ACK_LIMIT_REACHED: + return COND_CODE_STRINGS[2]; + case KEEP_ALIVE_LIMIT_REACHED: + return COND_CODE_STRINGS[3]; + case INVALID_TRANSMISSION_MODE: + return COND_CODE_STRINGS[4]; + case FILESTORE_REJECTION: + return COND_CODE_STRINGS[5]; + case FILE_CHECKSUM_FAILURE: + return COND_CODE_STRINGS[6]; + case FILE_SIZE_ERROR: + return COND_CODE_STRINGS[7]; + case NAK_LIMIT_REACHED: + return COND_CODE_STRINGS[8]; + case INACTIVITY_DETECTED: + return COND_CODE_STRINGS[9]; + case CHECK_LIMIT_REACHED: + return COND_CODE_STRINGS[10]; + case UNSUPPORTED_CHECKSUM_TYPE: + return COND_CODE_STRINGS[11]; + case SUSPEND_REQUEST_RECEIVED: + return COND_CODE_STRINGS[12]; + case CANCEL_REQUEST_RECEIVED: + return COND_CODE_STRINGS[13]; + } + return "Unknown"; +} diff --git a/src/fsfw/cfdp/helpers.h b/src/fsfw/cfdp/helpers.h new file mode 100644 index 00000000..df64c847 --- /dev/null +++ b/src/fsfw/cfdp/helpers.h @@ -0,0 +1,11 @@ +#ifndef FSFW_EXAMPLE_HOSTED_HELPER_H +#define FSFW_EXAMPLE_HOSTED_HELPER_H + +#include "definitions.h" + +namespace cfdp { + +const char* getConditionCodeString(cfdp::ConditionCodes code); + +} +#endif // FSFW_EXAMPLE_HOSTED_HELPER_H diff --git a/src/fsfw/cfdp/pdu/AckInfo.cpp b/src/fsfw/cfdp/pdu/AckInfo.cpp index f35cfbb1..240f1bfb 100644 --- a/src/fsfw/cfdp/pdu/AckInfo.cpp +++ b/src/fsfw/cfdp/pdu/AckInfo.cpp @@ -1,6 +1,6 @@ #include "AckInfo.h" -AckInfo::AckInfo(cfdp::FileDirectives ackedDirective, cfdp::ConditionCode ackedConditionCode, +AckInfo::AckInfo(cfdp::FileDirectives ackedDirective, cfdp::ConditionCodes ackedConditionCode, cfdp::AckTransactionStatus transactionStatus, uint8_t directiveSubtypeCode) : ackedDirective(ackedDirective), ackedConditionCode(ackedConditionCode), @@ -13,9 +13,9 @@ AckInfo::AckInfo(cfdp::FileDirectives ackedDirective, cfdp::ConditionCode ackedC } } -cfdp::ConditionCode AckInfo::getAckedConditionCode() const { return ackedConditionCode; } +cfdp::ConditionCodes AckInfo::getAckedConditionCode() const { return ackedConditionCode; } -void AckInfo::setAckedConditionCode(cfdp::ConditionCode ackedConditionCode) { +void AckInfo::setAckedConditionCode(cfdp::ConditionCodes ackedConditionCode) { this->ackedConditionCode = ackedConditionCode; if (ackedDirective == cfdp::FileDirectives::FINISH) { this->directiveSubtypeCode = 0b0001; diff --git a/src/fsfw/cfdp/pdu/AckInfo.h b/src/fsfw/cfdp/pdu/AckInfo.h index 572fc59f..2781ee73 100644 --- a/src/fsfw/cfdp/pdu/AckInfo.h +++ b/src/fsfw/cfdp/pdu/AckInfo.h @@ -6,11 +6,11 @@ class AckInfo { public: AckInfo(); - AckInfo(cfdp::FileDirectives ackedDirective, cfdp::ConditionCode ackedConditionCode, + AckInfo(cfdp::FileDirectives ackedDirective, cfdp::ConditionCodes ackedConditionCode, cfdp::AckTransactionStatus transactionStatus, uint8_t directiveSubtypeCode = 0); - cfdp::ConditionCode getAckedConditionCode() const; - void setAckedConditionCode(cfdp::ConditionCode ackedConditionCode); + cfdp::ConditionCodes getAckedConditionCode() const; + void setAckedConditionCode(cfdp::ConditionCodes ackedConditionCode); cfdp::FileDirectives getAckedDirective() const; void setAckedDirective(cfdp::FileDirectives ackedDirective); @@ -23,7 +23,7 @@ class AckInfo { private: cfdp::FileDirectives ackedDirective = cfdp::FileDirectives::INVALID_DIRECTIVE; - cfdp::ConditionCode ackedConditionCode = cfdp::ConditionCode::NO_CONDITION_FIELD; + cfdp::ConditionCodes ackedConditionCode = cfdp::ConditionCodes::NO_CONDITION_FIELD; cfdp::AckTransactionStatus transactionStatus = cfdp::AckTransactionStatus::UNDEFINED; uint8_t directiveSubtypeCode = 0; }; diff --git a/src/fsfw/cfdp/pdu/AckPduCreator.cpp b/src/fsfw/cfdp/pdu/AckPduCreator.cpp index 88fcedc9..8683c65f 100644 --- a/src/fsfw/cfdp/pdu/AckPduCreator.cpp +++ b/src/fsfw/cfdp/pdu/AckPduCreator.cpp @@ -13,7 +13,7 @@ ReturnValue_t AckPduCreator::serialize(uint8_t **buffer, size_t *size, size_t ma } cfdp::FileDirectives ackedDirective = ackInfo.getAckedDirective(); uint8_t directiveSubtypeCode = ackInfo.getDirectiveSubtypeCode(); - cfdp::ConditionCode ackedConditionCode = ackInfo.getAckedConditionCode(); + cfdp::ConditionCodes ackedConditionCode = ackInfo.getAckedConditionCode(); cfdp::AckTransactionStatus transactionStatus = ackInfo.getTransactionStatus(); if (ackedDirective != cfdp::FileDirectives::FINISH and ackedDirective != cfdp::FileDirectives::EOF_DIRECTIVE) { diff --git a/src/fsfw/cfdp/pdu/AckPduReader.cpp b/src/fsfw/cfdp/pdu/AckPduReader.cpp index 4f75a2b8..efa6f6df 100644 --- a/src/fsfw/cfdp/pdu/AckPduReader.cpp +++ b/src/fsfw/cfdp/pdu/AckPduReader.cpp @@ -29,7 +29,7 @@ bool AckPduReader::checkAndSetCodes(uint8_t firstByte, uint8_t secondByte) { return false; } this->info.setDirectiveSubtypeCode(directiveSubtypeCode); - this->info.setAckedConditionCode(static_cast(secondByte >> 4)); + this->info.setAckedConditionCode(static_cast(secondByte >> 4)); this->info.setTransactionStatus(static_cast(secondByte & 0x0f)); return true; } diff --git a/src/fsfw/cfdp/pdu/EofInfo.cpp b/src/fsfw/cfdp/pdu/EofInfo.cpp index 98e79df7..b19a709b 100644 --- a/src/fsfw/cfdp/pdu/EofInfo.cpp +++ b/src/fsfw/cfdp/pdu/EofInfo.cpp @@ -1,18 +1,18 @@ #include "EofInfo.h" -EofInfo::EofInfo(cfdp::ConditionCode conditionCode, uint32_t checksum, cfdp::FileSize fileSize, +EofInfo::EofInfo(cfdp::ConditionCodes conditionCode, uint32_t checksum, cfdp::FileSize fileSize, EntityIdTlv* faultLoc) : conditionCode(conditionCode), checksum(checksum), fileSize(fileSize), faultLoc(faultLoc) {} EofInfo::EofInfo(EntityIdTlv* faultLoc) - : conditionCode(cfdp::ConditionCode::NO_CONDITION_FIELD), + : conditionCode(cfdp::ConditionCodes::NO_CONDITION_FIELD), checksum(0), fileSize(0), faultLoc(faultLoc) {} uint32_t EofInfo::getChecksum() const { return checksum; } -cfdp::ConditionCode EofInfo::getConditionCode() const { return conditionCode; } +cfdp::ConditionCodes EofInfo::getConditionCode() const { return conditionCode; } EntityIdTlv* EofInfo::getFaultLoc() const { return faultLoc; } @@ -20,7 +20,7 @@ cfdp::FileSize& EofInfo::getFileSize() { return fileSize; } void EofInfo::setChecksum(uint32_t checksum) { this->checksum = checksum; } -void EofInfo::setConditionCode(cfdp::ConditionCode conditionCode) { +void EofInfo::setConditionCode(cfdp::ConditionCodes conditionCode) { this->conditionCode = conditionCode; } @@ -36,7 +36,7 @@ size_t EofInfo::getSerializedSize(bool fssLarge) { } // Do not account for fault location if the condition code is NO_ERROR. We assume that // a serializer will not serialize the fault location here. - if (getFaultLoc() != nullptr and getConditionCode() != cfdp::ConditionCode::NO_ERROR) { + if (getFaultLoc() != nullptr and getConditionCode() != cfdp::ConditionCodes::NO_ERROR) { size += faultLoc->getSerializedSize(); } return size; diff --git a/src/fsfw/cfdp/pdu/EofInfo.h b/src/fsfw/cfdp/pdu/EofInfo.h index 4b4fb057..bd6e6493 100644 --- a/src/fsfw/cfdp/pdu/EofInfo.h +++ b/src/fsfw/cfdp/pdu/EofInfo.h @@ -8,23 +8,23 @@ struct EofInfo { public: explicit EofInfo(EntityIdTlv* faultLoc = nullptr); - EofInfo(cfdp::ConditionCode conditionCode, uint32_t checksum, cfdp::FileSize fileSize, + EofInfo(cfdp::ConditionCodes conditionCode, uint32_t checksum, cfdp::FileSize fileSize, EntityIdTlv* faultLoc = nullptr); size_t getSerializedSize(bool fssLarge = false); [[nodiscard]] uint32_t getChecksum() const; - [[nodiscard]] cfdp::ConditionCode getConditionCode() const; + [[nodiscard]] cfdp::ConditionCodes getConditionCode() const; [[nodiscard]] EntityIdTlv* getFaultLoc() const; cfdp::FileSize& getFileSize(); void setChecksum(uint32_t checksum); - void setConditionCode(cfdp::ConditionCode conditionCode); + void setConditionCode(cfdp::ConditionCodes conditionCode); void setFaultLoc(EntityIdTlv* faultLoc); ReturnValue_t setFileSize(size_t size, bool isLarge); private: - cfdp::ConditionCode conditionCode; + cfdp::ConditionCodes conditionCode; uint32_t checksum; cfdp::FileSize fileSize; EntityIdTlv* faultLoc = nullptr; diff --git a/src/fsfw/cfdp/pdu/EofPduCreator.cpp b/src/fsfw/cfdp/pdu/EofPduCreator.cpp index 20b8c64a..3e196e02 100644 --- a/src/fsfw/cfdp/pdu/EofPduCreator.cpp +++ b/src/fsfw/cfdp/pdu/EofPduCreator.cpp @@ -33,7 +33,7 @@ ReturnValue_t EofPduCreator::serialize(uint8_t **buffer, size_t *size, size_t ma uint32_t fileSizeValue = info.getFileSize().getSize(); result = SerializeAdapter::serialize(&fileSizeValue, buffer, size, maxSize, streamEndianness); } - if (info.getFaultLoc() != nullptr and info.getConditionCode() != cfdp::ConditionCode::NO_ERROR) { + if (info.getFaultLoc() != nullptr and info.getConditionCode() != cfdp::ConditionCodes::NO_ERROR) { result = info.getFaultLoc()->serialize(buffer, size, maxSize, streamEndianness); } return result; diff --git a/src/fsfw/cfdp/pdu/EofPduReader.cpp b/src/fsfw/cfdp/pdu/EofPduReader.cpp index c80c501c..333e1224 100644 --- a/src/fsfw/cfdp/pdu/EofPduReader.cpp +++ b/src/fsfw/cfdp/pdu/EofPduReader.cpp @@ -25,7 +25,7 @@ ReturnValue_t EofPduReader::parseData() { bufPtr += currentIdx; deserLen -= currentIdx; - info.setConditionCode(static_cast(*bufPtr >> 4)); + info.setConditionCode(static_cast(*bufPtr >> 4)); bufPtr += 1; deserLen -= 1; uint32_t checksum = 0; @@ -47,7 +47,7 @@ ReturnValue_t EofPduReader::parseData() { if (result != returnvalue::OK) { return result; } - if (info.getConditionCode() != cfdp::ConditionCode::NO_ERROR) { + if (info.getConditionCode() != cfdp::ConditionCodes::NO_ERROR) { EntityIdTlv* tlvPtr = info.getFaultLoc(); if (tlvPtr == nullptr) { #if FSFW_VERBOSE_LEVEL >= 1 diff --git a/src/fsfw/cfdp/pdu/FinishedInfo.cpp b/src/fsfw/cfdp/pdu/FinishedInfo.cpp index 2f986e85..5b4ae0ca 100644 --- a/src/fsfw/cfdp/pdu/FinishedInfo.cpp +++ b/src/fsfw/cfdp/pdu/FinishedInfo.cpp @@ -2,7 +2,7 @@ FinishedInfo::FinishedInfo() {} -FinishedInfo::FinishedInfo(cfdp::ConditionCode conditionCode, cfdp::FileDeliveryCode deliveryCode, +FinishedInfo::FinishedInfo(cfdp::ConditionCodes conditionCode, cfdp::FileDeliveryCode deliveryCode, cfdp::FileDeliveryStatus fileStatus) : conditionCode(conditionCode), deliveryCode(deliveryCode), fileStatus(fileStatus) {} @@ -76,9 +76,9 @@ ReturnValue_t FinishedInfo::getFaultLocation(EntityIdTlv** faultLocation) { return returnvalue::OK; } -cfdp::ConditionCode FinishedInfo::getConditionCode() const { return conditionCode; } +cfdp::ConditionCodes FinishedInfo::getConditionCode() const { return conditionCode; } -void FinishedInfo::setConditionCode(cfdp::ConditionCode conditionCode) { +void FinishedInfo::setConditionCode(cfdp::ConditionCodes conditionCode) { this->conditionCode = conditionCode; } diff --git a/src/fsfw/cfdp/pdu/FinishedInfo.h b/src/fsfw/cfdp/pdu/FinishedInfo.h index 49d7c64d..1a2beade 100644 --- a/src/fsfw/cfdp/pdu/FinishedInfo.h +++ b/src/fsfw/cfdp/pdu/FinishedInfo.h @@ -8,7 +8,7 @@ class FinishedInfo { public: FinishedInfo(); - FinishedInfo(cfdp::ConditionCode conditionCode, cfdp::FileDeliveryCode deliveryCode, + FinishedInfo(cfdp::ConditionCodes conditionCode, cfdp::FileDeliveryCode deliveryCode, cfdp::FileDeliveryStatus fileStatus); [[nodiscard]] size_t getSerializedSize() const; @@ -25,15 +25,15 @@ class FinishedInfo { [[nodiscard]] size_t getFsResponsesLen() const; void setFilestoreResponsesArrayLen(size_t fsResponsesLen); ReturnValue_t getFaultLocation(EntityIdTlv** entityId); - [[nodiscard]] cfdp::ConditionCode getConditionCode() const; - void setConditionCode(cfdp::ConditionCode conditionCode); + [[nodiscard]] cfdp::ConditionCodes getConditionCode() const; + void setConditionCode(cfdp::ConditionCodes conditionCode); [[nodiscard]] cfdp::FileDeliveryCode getDeliveryCode() const; void setDeliveryCode(cfdp::FileDeliveryCode deliveryCode); [[nodiscard]] cfdp::FileDeliveryStatus getFileStatus() const; void setFileStatus(cfdp::FileDeliveryStatus fileStatus); private: - cfdp::ConditionCode conditionCode = cfdp::ConditionCode::NO_CONDITION_FIELD; + cfdp::ConditionCodes conditionCode = cfdp::ConditionCodes::NO_CONDITION_FIELD; cfdp::FileDeliveryCode deliveryCode = cfdp::FileDeliveryCode::DATA_COMPLETE; cfdp::FileDeliveryStatus fileStatus = cfdp::FileDeliveryStatus::DISCARDED_DELIBERATELY; FilestoreResponseTlv** fsResponses = nullptr; diff --git a/src/fsfw/cfdp/pdu/FinishedPduReader.cpp b/src/fsfw/cfdp/pdu/FinishedPduReader.cpp index 475942e0..a34abf07 100644 --- a/src/fsfw/cfdp/pdu/FinishedPduReader.cpp +++ b/src/fsfw/cfdp/pdu/FinishedPduReader.cpp @@ -15,7 +15,7 @@ ReturnValue_t FinishPduReader::parseData() { return SerializeIF::STREAM_TOO_SHORT; } uint8_t firstByte = *buf; - auto condCode = static_cast((firstByte >> 4) & 0x0f); + auto condCode = static_cast((firstByte >> 4) & 0x0f); finishedInfo.setConditionCode(condCode); finishedInfo.setDeliveryCode(static_cast(firstByte >> 2 & 0b1)); finishedInfo.setFileStatus(static_cast(firstByte & 0b11)); @@ -31,7 +31,7 @@ ReturnValue_t FinishPduReader::parseData() { FinishedInfo& FinishPduReader::getInfo() { return finishedInfo; } ReturnValue_t FinishPduReader::parseTlvs(size_t remLen, size_t currentIdx, const uint8_t* buf, - cfdp::ConditionCode conditionCode) { + cfdp::ConditionCodes conditionCode) { ReturnValue_t result = returnvalue::OK; size_t fsResponsesIdx = 0; auto endianness = getEndianness(); @@ -66,8 +66,8 @@ ReturnValue_t FinishPduReader::parseTlvs(size_t remLen, size_t currentIdx, const } else if (nextTlv == cfdp::TlvTypes::ENTITY_ID) { // This needs to be the last TLV and it should not be here if the condition code // is "No Error" or "Unsupported Checksum Type" - if (conditionCode == cfdp::ConditionCode::NO_ERROR or - conditionCode == cfdp::ConditionCode::UNSUPPORTED_CHECKSUM_TYPE) { + if (conditionCode == cfdp::ConditionCodes::NO_ERROR or + conditionCode == cfdp::ConditionCodes::UNSUPPORTED_CHECKSUM_TYPE) { return cfdp::INVALID_TLV_TYPE; } result = finishedInfo.getFaultLocation(&faultLocation); diff --git a/src/fsfw/cfdp/pdu/FinishedPduReader.h b/src/fsfw/cfdp/pdu/FinishedPduReader.h index 791a2ef4..ce489fcd 100644 --- a/src/fsfw/cfdp/pdu/FinishedPduReader.h +++ b/src/fsfw/cfdp/pdu/FinishedPduReader.h @@ -16,7 +16,7 @@ class FinishPduReader : public FileDirectiveReader { FinishedInfo& finishedInfo; ReturnValue_t parseTlvs(size_t remLen, size_t currentIdx, const uint8_t* buf, - cfdp::ConditionCode conditionCode); + cfdp::ConditionCodes conditionCode); }; #endif /* FSFW_CFDP_PDU_FINISHEDPDUDESERIALIZER_H_ */ diff --git a/src/fsfw/cfdp/tlv/FaultHandlerOverrideTlv.cpp b/src/fsfw/cfdp/tlv/FaultHandlerOverrideTlv.cpp index 89c12974..684d47c2 100644 --- a/src/fsfw/cfdp/tlv/FaultHandlerOverrideTlv.cpp +++ b/src/fsfw/cfdp/tlv/FaultHandlerOverrideTlv.cpp @@ -1,6 +1,6 @@ #include "FaultHandlerOverrideTlv.h" -FaultHandlerOverrideTlv::FaultHandlerOverrideTlv(cfdp::ConditionCode conditionCode, +FaultHandlerOverrideTlv::FaultHandlerOverrideTlv(cfdp::ConditionCodes conditionCode, cfdp::FaultHandlerCodes handlerCode) : conditionCode(conditionCode), handlerCode(handlerCode) {} @@ -44,7 +44,7 @@ ReturnValue_t FaultHandlerOverrideTlv::deSerialize(const uint8_t **buffer, size_ } *buffer += 1; *size += 1; - this->conditionCode = static_cast((**buffer >> 4) & 0x0f); + this->conditionCode = static_cast((**buffer >> 4) & 0x0f); this->handlerCode = static_cast(**buffer & 0x0f); *buffer += 1; *size += 1; diff --git a/src/fsfw/cfdp/tlv/FaultHandlerOverrideTlv.h b/src/fsfw/cfdp/tlv/FaultHandlerOverrideTlv.h index a9cee9e6..33a7fdab 100644 --- a/src/fsfw/cfdp/tlv/FaultHandlerOverrideTlv.h +++ b/src/fsfw/cfdp/tlv/FaultHandlerOverrideTlv.h @@ -6,7 +6,7 @@ class FaultHandlerOverrideTlv : public TlvIF { public: FaultHandlerOverrideTlv(); - FaultHandlerOverrideTlv(cfdp::ConditionCode conditionCode, cfdp::FaultHandlerCodes handlerCode); + FaultHandlerOverrideTlv(cfdp::ConditionCodes conditionCode, cfdp::FaultHandlerCodes handlerCode); ReturnValue_t serialize(uint8_t **buffer, size_t *size, size_t maxSize, Endianness streamEndianness) const override; @@ -19,7 +19,7 @@ class FaultHandlerOverrideTlv : public TlvIF { [[nodiscard]] cfdp::TlvTypes getType() const override; private: - cfdp::ConditionCode conditionCode = cfdp::ConditionCode::NO_CONDITION_FIELD; + cfdp::ConditionCodes conditionCode = cfdp::ConditionCodes::NO_CONDITION_FIELD; cfdp::FaultHandlerCodes handlerCode = cfdp::FaultHandlerCodes::RESERVED; }; From 6f8ccf83e71b8e08b76b27dbb3528ee9e2fa88cb Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Thu, 15 Sep 2022 18:41:15 +0200 Subject: [PATCH 125/169] use singular enum names --- src/fsfw/cfdp/definitions.h | 15 +++-- src/fsfw/cfdp/handler/FaultHandlerBase.cpp | 26 ++++----- src/fsfw/cfdp/handler/FaultHandlerBase.h | 44 +++++++------- src/fsfw/cfdp/handler/UserBase.h | 10 ++-- src/fsfw/cfdp/handler/mib.h | 4 +- src/fsfw/cfdp/helpers.cpp | 32 +++++------ src/fsfw/cfdp/helpers.h | 2 +- src/fsfw/cfdp/pdu/AckInfo.cpp | 14 ++--- src/fsfw/cfdp/pdu/AckInfo.h | 14 ++--- src/fsfw/cfdp/pdu/AckPduCreator.cpp | 10 ++-- src/fsfw/cfdp/pdu/AckPduReader.cpp | 14 ++--- src/fsfw/cfdp/pdu/AckPduReader.h | 2 +- src/fsfw/cfdp/pdu/EofInfo.cpp | 10 ++-- src/fsfw/cfdp/pdu/EofInfo.h | 8 +-- src/fsfw/cfdp/pdu/EofPduCreator.cpp | 4 +- src/fsfw/cfdp/pdu/EofPduReader.cpp | 4 +- src/fsfw/cfdp/pdu/FileDataCreator.cpp | 2 +- src/fsfw/cfdp/pdu/FileDirectiveCreator.cpp | 6 +- src/fsfw/cfdp/pdu/FileDirectiveCreator.h | 6 +- src/fsfw/cfdp/pdu/FileDirectiveReader.cpp | 10 ++-- src/fsfw/cfdp/pdu/FileDirectiveReader.h | 6 +- src/fsfw/cfdp/pdu/FinishedInfo.cpp | 6 +- src/fsfw/cfdp/pdu/FinishedInfo.h | 8 +-- src/fsfw/cfdp/pdu/FinishedPduCreator.cpp | 2 +- src/fsfw/cfdp/pdu/FinishedPduReader.cpp | 16 +++--- src/fsfw/cfdp/pdu/FinishedPduReader.h | 2 +- src/fsfw/cfdp/pdu/HeaderCreator.cpp | 8 +-- src/fsfw/cfdp/pdu/HeaderCreator.h | 10 ++-- src/fsfw/cfdp/pdu/HeaderReader.cpp | 8 +-- src/fsfw/cfdp/pdu/KeepAlivePduCreator.cpp | 2 +- src/fsfw/cfdp/pdu/MetadataInfo.cpp | 6 +- src/fsfw/cfdp/pdu/MetadataInfo.h | 8 +-- src/fsfw/cfdp/pdu/MetadataPduCreator.cpp | 2 +- src/fsfw/cfdp/pdu/MetadataPduReader.cpp | 2 +- src/fsfw/cfdp/pdu/NakPduCreator.cpp | 2 +- src/fsfw/cfdp/pdu/PduConfig.cpp | 2 +- src/fsfw/cfdp/pdu/PduConfig.h | 4 +- src/fsfw/cfdp/pdu/PduHeaderIF.h | 4 +- src/fsfw/cfdp/pdu/PduHeaderReader.h | 4 +- src/fsfw/cfdp/pdu/PromptPduCreator.cpp | 2 +- src/fsfw/cfdp/tlv/EntityIdTlv.cpp | 8 +-- src/fsfw/cfdp/tlv/EntityIdTlv.h | 2 +- src/fsfw/cfdp/tlv/FaultHandlerOverrideTlv.cpp | 14 ++--- src/fsfw/cfdp/tlv/FaultHandlerOverrideTlv.h | 8 +-- src/fsfw/cfdp/tlv/FilestoreRequestTlv.cpp | 2 +- src/fsfw/cfdp/tlv/FilestoreRequestTlv.h | 2 +- src/fsfw/cfdp/tlv/FilestoreResponseTlv.cpp | 2 +- src/fsfw/cfdp/tlv/FilestoreResponseTlv.h | 2 +- src/fsfw/cfdp/tlv/FilestoreTlvBase.h | 2 +- src/fsfw/cfdp/tlv/FlowLabelTlv.cpp | 2 +- src/fsfw/cfdp/tlv/MessageToUserTlv.cpp | 4 +- src/fsfw/cfdp/tlv/Tlv.cpp | 10 ++-- src/fsfw/cfdp/tlv/Tlv.h | 8 +-- src/fsfw/cfdp/tlv/TlvIF.h | 2 +- unittests/cfdp/handler/testDistributor.cpp | 4 +- unittests/cfdp/handler/testFaultHandler.cpp | 57 ++++++++++--------- unittests/cfdp/pdu/testAckPdu.cpp | 32 +++++------ unittests/cfdp/pdu/testCfdpHeader.cpp | 32 +++++------ unittests/cfdp/pdu/testEofPdu.cpp | 10 ++-- unittests/cfdp/pdu/testFileData.cpp | 2 +- unittests/cfdp/pdu/testFileDirective.cpp | 10 ++-- unittests/cfdp/pdu/testFinishedPdu.cpp | 6 +- unittests/cfdp/pdu/testKeepAlivePdu.cpp | 4 +- unittests/cfdp/pdu/testMetadataPdu.cpp | 18 +++--- unittests/cfdp/pdu/testNakPdu.cpp | 4 +- unittests/cfdp/pdu/testPromptPdu.cpp | 4 +- unittests/cfdp/testCfdp.cpp | 10 ++-- unittests/cfdp/testOtherTlvs.cpp | 10 ++-- unittests/cfdp/testTlv.cpp | 24 ++++---- unittests/mocks/cfdp/FaultHandlerMock.cpp | 20 +++---- unittests/mocks/cfdp/FaultHandlerMock.h | 20 +++---- 71 files changed, 337 insertions(+), 339 deletions(-) diff --git a/src/fsfw/cfdp/definitions.h b/src/fsfw/cfdp/definitions.h index e6297bd7..2d7a37fc 100644 --- a/src/fsfw/cfdp/definitions.h +++ b/src/fsfw/cfdp/definitions.h @@ -41,7 +41,7 @@ static constexpr ReturnValue_t INVALID_PDU_FORMAT = returnvalue::makeCode(CFDP_C //! Checksum types according to the SANA Checksum Types registry //! https://sanaregistry.org/r/checksum_identifiers/ -enum ChecksumTypes { +enum ChecksumType { // Modular legacy checksum MODULAR = 0, CRC_32_PROXIMITY_1 = 1, @@ -50,9 +50,9 @@ enum ChecksumTypes { NULL_CHECKSUM = 15 }; -enum PduTypes : uint8_t { FILE_DIRECTIVE = 0, FILE_DATA = 1 }; +enum PduType : uint8_t { FILE_DIRECTIVE = 0, FILE_DATA = 1 }; -enum TransmissionModes : uint8_t { ACKNOWLEDGED = 0, UNACKNOWLEDGED = 1 }; +enum TransmissionMode : uint8_t { ACKNOWLEDGED = 0, UNACKNOWLEDGED = 1 }; enum SegmentMetadataFlag : bool { NOT_PRESENT = false, PRESENT = true }; @@ -70,7 +70,7 @@ enum WidthInBytes : uint8_t { FOUR_BYTES = 4, }; -enum FileDirectives : uint8_t { +enum FileDirective : uint8_t { INVALID_DIRECTIVE = 0x0f, // The _DIRECTIVE suffix is mandatory here because of some nameclash! EOF_DIRECTIVE = 0x04, @@ -82,7 +82,7 @@ enum FileDirectives : uint8_t { KEEP_ALIVE = 0x0c }; -enum ConditionCodes : uint8_t { +enum ConditionCode : uint8_t { NO_CONDITION_FIELD = 0xff, NO_ERROR = 0b0000, POSITIVE_ACK_LIMIT_REACHED = 0b0001, @@ -99,8 +99,7 @@ enum ConditionCodes : uint8_t { CANCEL_REQUEST_RECEIVED = 0b1111 }; - -enum FaultHandlerCodes { +enum FaultHandlerCode { RESERVED = 0b0000, NOTICE_OF_CANCELLATION = 0b0001, NOTICE_OF_SUSPENSION = 0b0010, @@ -126,7 +125,7 @@ enum FileDeliveryStatus { enum PromptResponseRequired : uint8_t { PROMPT_NAK = 0, PROMPT_KEEP_ALIVE = 1 }; -enum TlvTypes : uint8_t { +enum TlvType : uint8_t { FILESTORE_REQUEST = 0x00, FILESTORE_RESPONSE = 0x01, MSG_TO_USER = 0x02, diff --git a/src/fsfw/cfdp/handler/FaultHandlerBase.cpp b/src/fsfw/cfdp/handler/FaultHandlerBase.cpp index 0531846c..4e16692e 100644 --- a/src/fsfw/cfdp/handler/FaultHandlerBase.cpp +++ b/src/fsfw/cfdp/handler/FaultHandlerBase.cpp @@ -5,8 +5,8 @@ namespace cfdp { FaultHandlerBase::FaultHandlerBase() = default; FaultHandlerBase::~FaultHandlerBase() = default; -bool FaultHandlerBase::getFaultHandler(cfdp::ConditionCodes code, - cfdp::FaultHandlerCodes& handler) const { +bool FaultHandlerBase::getFaultHandler(cfdp::ConditionCode code, + cfdp::FaultHandlerCode& handler) const { auto iter = faultHandlerMap.find(code); if (iter == faultHandlerMap.end()) { return false; @@ -15,32 +15,32 @@ bool FaultHandlerBase::getFaultHandler(cfdp::ConditionCodes code, return true; } -bool FaultHandlerBase::setFaultHandler(cfdp::ConditionCodes code, cfdp::FaultHandlerCodes handler) { +bool FaultHandlerBase::setFaultHandler(cfdp::ConditionCode code, cfdp::FaultHandlerCode handler) { if (not faultHandlerMap.contains(code)) { return false; } - if (handler != FaultHandlerCodes::NOTICE_OF_SUSPENSION and - handler != FaultHandlerCodes::ABANDON_TRANSACTION and - handler != FaultHandlerCodes::NOTICE_OF_CANCELLATION and - handler != FaultHandlerCodes::IGNORE_ERROR) { + if (handler != FaultHandlerCode::NOTICE_OF_SUSPENSION and + handler != FaultHandlerCode::ABANDON_TRANSACTION and + handler != FaultHandlerCode::NOTICE_OF_CANCELLATION and + handler != FaultHandlerCode::IGNORE_ERROR) { return false; } faultHandlerMap[code] = handler; return true; } -bool FaultHandlerBase::reportFault(cfdp::TransactionId& id, cfdp::ConditionCodes code) { +bool FaultHandlerBase::reportFault(cfdp::TransactionId& id, cfdp::ConditionCode code) { if (not faultHandlerMap.contains(code)) { return false; } - cfdp::FaultHandlerCodes fh = faultHandlerMap[code]; - if (fh == cfdp::FaultHandlerCodes::IGNORE_ERROR) { + cfdp::FaultHandlerCode fh = faultHandlerMap[code]; + if (fh == cfdp::FaultHandlerCode::IGNORE_ERROR) { ignoreCb(id, code); - } else if (fh == cfdp::FaultHandlerCodes::ABANDON_TRANSACTION) { + } else if (fh == cfdp::FaultHandlerCode::ABANDON_TRANSACTION) { abandonCb(id, code); - } else if (fh == cfdp::FaultHandlerCodes::NOTICE_OF_CANCELLATION) { + } else if (fh == cfdp::FaultHandlerCode::NOTICE_OF_CANCELLATION) { noticeOfCancellationCb(id, code); - } else if (fh == cfdp::FaultHandlerCodes::NOTICE_OF_SUSPENSION) { + } else if (fh == cfdp::FaultHandlerCode::NOTICE_OF_SUSPENSION) { noticeOfSuspensionCb(id, code); } else { // Should never happen, but use defensive programming diff --git a/src/fsfw/cfdp/handler/FaultHandlerBase.h b/src/fsfw/cfdp/handler/FaultHandlerBase.h index 0c7f534c..39b8e180 100644 --- a/src/fsfw/cfdp/handler/FaultHandlerBase.h +++ b/src/fsfw/cfdp/handler/FaultHandlerBase.h @@ -43,33 +43,33 @@ class FaultHandlerBase { * - true if the condition code is valid * - false otherwise */ - bool getFaultHandler(cfdp::ConditionCodes code, cfdp::FaultHandlerCodes& handler) const; + bool getFaultHandler(cfdp::ConditionCode code, cfdp::FaultHandlerCode& handler) const; - bool setFaultHandler(cfdp::ConditionCodes code, cfdp::FaultHandlerCodes handler); + bool setFaultHandler(cfdp::ConditionCode code, cfdp::FaultHandlerCode handler); - bool reportFault(cfdp::TransactionId& id, cfdp::ConditionCodes code); + bool reportFault(cfdp::TransactionId& id, cfdp::ConditionCode code); - virtual void noticeOfSuspensionCb(cfdp::TransactionId& id, cfdp::ConditionCodes code) = 0; - virtual void noticeOfCancellationCb(cfdp::TransactionId& id, cfdp::ConditionCodes code) = 0; - virtual void abandonCb(cfdp::TransactionId& id, cfdp::ConditionCodes code) = 0; - virtual void ignoreCb(cfdp::TransactionId& id, cfdp::ConditionCodes code) = 0; + virtual void noticeOfSuspensionCb(cfdp::TransactionId& id, cfdp::ConditionCode code) = 0; + virtual void noticeOfCancellationCb(cfdp::TransactionId& id, cfdp::ConditionCode code) = 0; + virtual void abandonCb(cfdp::TransactionId& id, cfdp::ConditionCode code) = 0; + virtual void ignoreCb(cfdp::TransactionId& id, cfdp::ConditionCode code) = 0; private: - etl::flat_map faultHandlerMap = { - etl::pair{cfdp::ConditionCodes::POSITIVE_ACK_LIMIT_REACHED, - cfdp::FaultHandlerCodes::IGNORE_ERROR}, - etl::pair{cfdp::ConditionCodes::KEEP_ALIVE_LIMIT_REACHED, - cfdp::FaultHandlerCodes::IGNORE_ERROR}, - etl::pair{cfdp::ConditionCodes::INVALID_TRANSMISSION_MODE, - cfdp::FaultHandlerCodes::IGNORE_ERROR}, - etl::pair{cfdp::ConditionCodes::FILE_CHECKSUM_FAILURE, cfdp::FaultHandlerCodes::IGNORE_ERROR}, - etl::pair{cfdp::ConditionCodes::FILE_SIZE_ERROR, cfdp::FaultHandlerCodes::IGNORE_ERROR}, - etl::pair{cfdp::ConditionCodes::NAK_LIMIT_REACHED, cfdp::FaultHandlerCodes::IGNORE_ERROR}, - etl::pair{cfdp::ConditionCodes::INACTIVITY_DETECTED, cfdp::FaultHandlerCodes::IGNORE_ERROR}, - etl::pair{cfdp::ConditionCodes::UNSUPPORTED_CHECKSUM_TYPE, - cfdp::FaultHandlerCodes::IGNORE_ERROR}, - etl::pair{cfdp::ConditionCodes::FILESTORE_REJECTION, cfdp::FaultHandlerCodes::IGNORE_ERROR}, - etl::pair{cfdp::ConditionCodes::CHECK_LIMIT_REACHED, cfdp::FaultHandlerCodes::IGNORE_ERROR}}; + etl::flat_map faultHandlerMap = { + etl::pair{cfdp::ConditionCode::POSITIVE_ACK_LIMIT_REACHED, + cfdp::FaultHandlerCode::IGNORE_ERROR}, + etl::pair{cfdp::ConditionCode::KEEP_ALIVE_LIMIT_REACHED, + cfdp::FaultHandlerCode::IGNORE_ERROR}, + etl::pair{cfdp::ConditionCode::INVALID_TRANSMISSION_MODE, + cfdp::FaultHandlerCode::IGNORE_ERROR}, + etl::pair{cfdp::ConditionCode::FILE_CHECKSUM_FAILURE, cfdp::FaultHandlerCode::IGNORE_ERROR}, + etl::pair{cfdp::ConditionCode::FILE_SIZE_ERROR, cfdp::FaultHandlerCode::IGNORE_ERROR}, + etl::pair{cfdp::ConditionCode::NAK_LIMIT_REACHED, cfdp::FaultHandlerCode::IGNORE_ERROR}, + etl::pair{cfdp::ConditionCode::INACTIVITY_DETECTED, cfdp::FaultHandlerCode::IGNORE_ERROR}, + etl::pair{cfdp::ConditionCode::UNSUPPORTED_CHECKSUM_TYPE, + cfdp::FaultHandlerCode::IGNORE_ERROR}, + etl::pair{cfdp::ConditionCode::FILESTORE_REJECTION, cfdp::FaultHandlerCode::IGNORE_ERROR}, + etl::pair{cfdp::ConditionCode::CHECK_LIMIT_REACHED, cfdp::FaultHandlerCode::IGNORE_ERROR}}; }; } // namespace cfdp diff --git a/src/fsfw/cfdp/handler/UserBase.h b/src/fsfw/cfdp/handler/UserBase.h index 4ff5eb96..e367b4a8 100644 --- a/src/fsfw/cfdp/handler/UserBase.h +++ b/src/fsfw/cfdp/handler/UserBase.h @@ -14,12 +14,12 @@ namespace cfdp { struct TransactionFinishedParams { - TransactionFinishedParams(const TransactionId& id, ConditionCodes code, FileDeliveryCode delivCode, + TransactionFinishedParams(const TransactionId& id, ConditionCode code, FileDeliveryCode delivCode, FileDeliveryStatus status) : id(id), condCode(code), status(status), deliveryCode(delivCode) {} const TransactionId& id; - ConditionCodes condCode; + ConditionCode condCode; FileDeliveryStatus status; FileDeliveryCode deliveryCode; std::vector fsResponses; @@ -85,10 +85,10 @@ class UserBase { virtual void metadataRecvdIndication(const MetadataRecvdParams& params) = 0; virtual void fileSegmentRecvdIndication(const FileSegmentRecvdParams& params) = 0; virtual void reportIndication(const TransactionId& id, StatusReportIF& report) = 0; - virtual void suspendedIndication(const TransactionId& id, ConditionCodes code) = 0; + virtual void suspendedIndication(const TransactionId& id, ConditionCode code) = 0; virtual void resumedIndication(const TransactionId& id, size_t progress) = 0; - virtual void faultIndication(const TransactionId& id, ConditionCodes code, size_t progress) = 0; - virtual void abandonedIndication(const TransactionId& id, ConditionCodes code, + virtual void faultIndication(const TransactionId& id, ConditionCode code, size_t progress) = 0; + virtual void abandonedIndication(const TransactionId& id, ConditionCode code, size_t progress) = 0; virtual void eofRecvIndication(const TransactionId& id) = 0; diff --git a/src/fsfw/cfdp/handler/mib.h b/src/fsfw/cfdp/handler/mib.h index 76284f2d..553596a6 100644 --- a/src/fsfw/cfdp/handler/mib.h +++ b/src/fsfw/cfdp/handler/mib.h @@ -32,8 +32,8 @@ struct RemoteEntityCfg { size_t maxFileSegmentLen = 2048; bool closureRequested = false; bool crcOnTransmission = false; - TransmissionModes defaultTransmissionMode = TransmissionModes::UNACKNOWLEDGED; - ChecksumTypes defaultChecksum = ChecksumTypes::NULL_CHECKSUM; + TransmissionMode defaultTransmissionMode = TransmissionMode::UNACKNOWLEDGED; + ChecksumType defaultChecksum = ChecksumType::NULL_CHECKSUM; const uint8_t version = CFDP_VERSION_2; }; diff --git a/src/fsfw/cfdp/helpers.cpp b/src/fsfw/cfdp/helpers.cpp index 49839e1f..fdb7d5ff 100644 --- a/src/fsfw/cfdp/helpers.cpp +++ b/src/fsfw/cfdp/helpers.cpp @@ -1,23 +1,21 @@ #include "helpers.h" -const char* COND_CODE_STRINGS[14] = { - "Unknown", - "No Error", - "Positive ACK Limit Reached", - "Keep Alive Limit Reached", - "Invalid Transmission Mode", - "Filestore Rejection", - "File Checksum Failure", - "File Size Error", - "NAK limit reached", - "Inactivity Detected", - "Check Limit Reached", - "Unsupported Checksum Type", - "Suspend Request Received", - "Cancel Request Received" -}; +const char* COND_CODE_STRINGS[14] = {"Unknown", + "No Error", + "Positive ACK Limit Reached", + "Keep Alive Limit Reached", + "Invalid Transmission Mode", + "Filestore Rejection", + "File Checksum Failure", + "File Size Error", + "NAK limit reached", + "Inactivity Detected", + "Check Limit Reached", + "Unsupported Checksum Type", + "Suspend Request Received", + "Cancel Request Received"}; -const char* cfdp::getConditionCodeString(cfdp::ConditionCodes code) { +const char* cfdp::getConditionCodeString(cfdp::ConditionCode code) { switch (code) { case NO_CONDITION_FIELD: return COND_CODE_STRINGS[0]; diff --git a/src/fsfw/cfdp/helpers.h b/src/fsfw/cfdp/helpers.h index df64c847..37428108 100644 --- a/src/fsfw/cfdp/helpers.h +++ b/src/fsfw/cfdp/helpers.h @@ -5,7 +5,7 @@ namespace cfdp { -const char* getConditionCodeString(cfdp::ConditionCodes code); +const char* getConditionCodeString(cfdp::ConditionCode code); } #endif // FSFW_EXAMPLE_HOSTED_HELPER_H diff --git a/src/fsfw/cfdp/pdu/AckInfo.cpp b/src/fsfw/cfdp/pdu/AckInfo.cpp index 240f1bfb..963f7cbb 100644 --- a/src/fsfw/cfdp/pdu/AckInfo.cpp +++ b/src/fsfw/cfdp/pdu/AckInfo.cpp @@ -1,32 +1,32 @@ #include "AckInfo.h" -AckInfo::AckInfo(cfdp::FileDirectives ackedDirective, cfdp::ConditionCodes ackedConditionCode, +AckInfo::AckInfo(cfdp::FileDirective ackedDirective, cfdp::ConditionCode ackedConditionCode, cfdp::AckTransactionStatus transactionStatus, uint8_t directiveSubtypeCode) : ackedDirective(ackedDirective), ackedConditionCode(ackedConditionCode), transactionStatus(transactionStatus), directiveSubtypeCode(directiveSubtypeCode) { - if (ackedDirective == cfdp::FileDirectives::FINISH) { + if (ackedDirective == cfdp::FileDirective::FINISH) { this->directiveSubtypeCode = 0b0001; } else { this->directiveSubtypeCode = 0b0000; } } -cfdp::ConditionCodes AckInfo::getAckedConditionCode() const { return ackedConditionCode; } +cfdp::ConditionCode AckInfo::getAckedConditionCode() const { return ackedConditionCode; } -void AckInfo::setAckedConditionCode(cfdp::ConditionCodes ackedConditionCode) { +void AckInfo::setAckedConditionCode(cfdp::ConditionCode ackedConditionCode) { this->ackedConditionCode = ackedConditionCode; - if (ackedDirective == cfdp::FileDirectives::FINISH) { + if (ackedDirective == cfdp::FileDirective::FINISH) { this->directiveSubtypeCode = 0b0001; } else { this->directiveSubtypeCode = 0b0000; } } -cfdp::FileDirectives AckInfo::getAckedDirective() const { return ackedDirective; } +cfdp::FileDirective AckInfo::getAckedDirective() const { return ackedDirective; } -void AckInfo::setAckedDirective(cfdp::FileDirectives ackedDirective) { +void AckInfo::setAckedDirective(cfdp::FileDirective ackedDirective) { this->ackedDirective = ackedDirective; } diff --git a/src/fsfw/cfdp/pdu/AckInfo.h b/src/fsfw/cfdp/pdu/AckInfo.h index 2781ee73..23e4d6ab 100644 --- a/src/fsfw/cfdp/pdu/AckInfo.h +++ b/src/fsfw/cfdp/pdu/AckInfo.h @@ -6,14 +6,14 @@ class AckInfo { public: AckInfo(); - AckInfo(cfdp::FileDirectives ackedDirective, cfdp::ConditionCodes ackedConditionCode, + AckInfo(cfdp::FileDirective ackedDirective, cfdp::ConditionCode ackedConditionCode, cfdp::AckTransactionStatus transactionStatus, uint8_t directiveSubtypeCode = 0); - cfdp::ConditionCodes getAckedConditionCode() const; - void setAckedConditionCode(cfdp::ConditionCodes ackedConditionCode); + cfdp::ConditionCode getAckedConditionCode() const; + void setAckedConditionCode(cfdp::ConditionCode ackedConditionCode); - cfdp::FileDirectives getAckedDirective() const; - void setAckedDirective(cfdp::FileDirectives ackedDirective); + cfdp::FileDirective getAckedDirective() const; + void setAckedDirective(cfdp::FileDirective ackedDirective); uint8_t getDirectiveSubtypeCode() const; void setDirectiveSubtypeCode(uint8_t directiveSubtypeCode); @@ -22,8 +22,8 @@ class AckInfo { void setTransactionStatus(cfdp::AckTransactionStatus transactionStatus); private: - cfdp::FileDirectives ackedDirective = cfdp::FileDirectives::INVALID_DIRECTIVE; - cfdp::ConditionCodes ackedConditionCode = cfdp::ConditionCodes::NO_CONDITION_FIELD; + cfdp::FileDirective ackedDirective = cfdp::FileDirective::INVALID_DIRECTIVE; + cfdp::ConditionCode ackedConditionCode = cfdp::ConditionCode::NO_CONDITION_FIELD; cfdp::AckTransactionStatus transactionStatus = cfdp::AckTransactionStatus::UNDEFINED; uint8_t directiveSubtypeCode = 0; }; diff --git a/src/fsfw/cfdp/pdu/AckPduCreator.cpp b/src/fsfw/cfdp/pdu/AckPduCreator.cpp index 8683c65f..f7623e57 100644 --- a/src/fsfw/cfdp/pdu/AckPduCreator.cpp +++ b/src/fsfw/cfdp/pdu/AckPduCreator.cpp @@ -1,7 +1,7 @@ #include "AckPduCreator.h" AckPduCreator::AckPduCreator(AckInfo &ackInfo, PduConfig &pduConf) - : FileDirectiveCreator(pduConf, cfdp::FileDirectives::ACK, 2), ackInfo(ackInfo) {} + : FileDirectiveCreator(pduConf, cfdp::FileDirective::ACK, 2), ackInfo(ackInfo) {} size_t AckPduCreator::getSerializedSize() const { return FileDirectiveCreator::getWholePduSize(); } @@ -11,12 +11,12 @@ ReturnValue_t AckPduCreator::serialize(uint8_t **buffer, size_t *size, size_t ma if (result != returnvalue::OK) { return result; } - cfdp::FileDirectives ackedDirective = ackInfo.getAckedDirective(); + cfdp::FileDirective ackedDirective = ackInfo.getAckedDirective(); uint8_t directiveSubtypeCode = ackInfo.getDirectiveSubtypeCode(); - cfdp::ConditionCodes ackedConditionCode = ackInfo.getAckedConditionCode(); + cfdp::ConditionCode ackedConditionCode = ackInfo.getAckedConditionCode(); cfdp::AckTransactionStatus transactionStatus = ackInfo.getTransactionStatus(); - if (ackedDirective != cfdp::FileDirectives::FINISH and - ackedDirective != cfdp::FileDirectives::EOF_DIRECTIVE) { + if (ackedDirective != cfdp::FileDirective::FINISH and + ackedDirective != cfdp::FileDirective::EOF_DIRECTIVE) { // TODO: better returncode return returnvalue::FAILED; } diff --git a/src/fsfw/cfdp/pdu/AckPduReader.cpp b/src/fsfw/cfdp/pdu/AckPduReader.cpp index efa6f6df..7204ced0 100644 --- a/src/fsfw/cfdp/pdu/AckPduReader.cpp +++ b/src/fsfw/cfdp/pdu/AckPduReader.cpp @@ -19,7 +19,7 @@ ReturnValue_t AckPduReader::parseData() { } bool AckPduReader::checkAndSetCodes(uint8_t firstByte, uint8_t secondByte) { - cfdp::FileDirectives directive; + cfdp::FileDirective directive; if (not checkAckedDirectiveField(firstByte, directive)) { return false; } @@ -29,17 +29,17 @@ bool AckPduReader::checkAndSetCodes(uint8_t firstByte, uint8_t secondByte) { return false; } this->info.setDirectiveSubtypeCode(directiveSubtypeCode); - this->info.setAckedConditionCode(static_cast(secondByte >> 4)); + this->info.setAckedConditionCode(static_cast(secondByte >> 4)); this->info.setTransactionStatus(static_cast(secondByte & 0x0f)); return true; } bool AckPduReader::checkAckedDirectiveField(uint8_t firstPduDataByte, - cfdp::FileDirectives& ackedDirective) { - uint8_t ackedDirectiveRaw = static_cast(firstPduDataByte >> 4); - if (ackedDirectiveRaw != cfdp::FileDirectives::EOF_DIRECTIVE and - ackedDirectiveRaw != cfdp::FileDirectives::FINISH) { + cfdp::FileDirective& ackedDirective) { + uint8_t ackedDirectiveRaw = static_cast(firstPduDataByte >> 4); + if (ackedDirectiveRaw != cfdp::FileDirective::EOF_DIRECTIVE and + ackedDirectiveRaw != cfdp::FileDirective::FINISH) { return false; } - ackedDirective = (static_cast(ackedDirectiveRaw)); + ackedDirective = (static_cast(ackedDirectiveRaw)); return true; } diff --git a/src/fsfw/cfdp/pdu/AckPduReader.h b/src/fsfw/cfdp/pdu/AckPduReader.h index 2b5dd411..8f8b515b 100644 --- a/src/fsfw/cfdp/pdu/AckPduReader.h +++ b/src/fsfw/cfdp/pdu/AckPduReader.h @@ -16,7 +16,7 @@ class AckPduReader : public FileDirectiveReader { ReturnValue_t parseData() override; static bool checkAckedDirectiveField(uint8_t firstPduDataByte, - cfdp::FileDirectives& ackedDirective); + cfdp::FileDirective& ackedDirective); private: bool checkAndSetCodes(uint8_t rawAckedByte, uint8_t rawAckedConditionCode); diff --git a/src/fsfw/cfdp/pdu/EofInfo.cpp b/src/fsfw/cfdp/pdu/EofInfo.cpp index b19a709b..98e79df7 100644 --- a/src/fsfw/cfdp/pdu/EofInfo.cpp +++ b/src/fsfw/cfdp/pdu/EofInfo.cpp @@ -1,18 +1,18 @@ #include "EofInfo.h" -EofInfo::EofInfo(cfdp::ConditionCodes conditionCode, uint32_t checksum, cfdp::FileSize fileSize, +EofInfo::EofInfo(cfdp::ConditionCode conditionCode, uint32_t checksum, cfdp::FileSize fileSize, EntityIdTlv* faultLoc) : conditionCode(conditionCode), checksum(checksum), fileSize(fileSize), faultLoc(faultLoc) {} EofInfo::EofInfo(EntityIdTlv* faultLoc) - : conditionCode(cfdp::ConditionCodes::NO_CONDITION_FIELD), + : conditionCode(cfdp::ConditionCode::NO_CONDITION_FIELD), checksum(0), fileSize(0), faultLoc(faultLoc) {} uint32_t EofInfo::getChecksum() const { return checksum; } -cfdp::ConditionCodes EofInfo::getConditionCode() const { return conditionCode; } +cfdp::ConditionCode EofInfo::getConditionCode() const { return conditionCode; } EntityIdTlv* EofInfo::getFaultLoc() const { return faultLoc; } @@ -20,7 +20,7 @@ cfdp::FileSize& EofInfo::getFileSize() { return fileSize; } void EofInfo::setChecksum(uint32_t checksum) { this->checksum = checksum; } -void EofInfo::setConditionCode(cfdp::ConditionCodes conditionCode) { +void EofInfo::setConditionCode(cfdp::ConditionCode conditionCode) { this->conditionCode = conditionCode; } @@ -36,7 +36,7 @@ size_t EofInfo::getSerializedSize(bool fssLarge) { } // Do not account for fault location if the condition code is NO_ERROR. We assume that // a serializer will not serialize the fault location here. - if (getFaultLoc() != nullptr and getConditionCode() != cfdp::ConditionCodes::NO_ERROR) { + if (getFaultLoc() != nullptr and getConditionCode() != cfdp::ConditionCode::NO_ERROR) { size += faultLoc->getSerializedSize(); } return size; diff --git a/src/fsfw/cfdp/pdu/EofInfo.h b/src/fsfw/cfdp/pdu/EofInfo.h index bd6e6493..4b4fb057 100644 --- a/src/fsfw/cfdp/pdu/EofInfo.h +++ b/src/fsfw/cfdp/pdu/EofInfo.h @@ -8,23 +8,23 @@ struct EofInfo { public: explicit EofInfo(EntityIdTlv* faultLoc = nullptr); - EofInfo(cfdp::ConditionCodes conditionCode, uint32_t checksum, cfdp::FileSize fileSize, + EofInfo(cfdp::ConditionCode conditionCode, uint32_t checksum, cfdp::FileSize fileSize, EntityIdTlv* faultLoc = nullptr); size_t getSerializedSize(bool fssLarge = false); [[nodiscard]] uint32_t getChecksum() const; - [[nodiscard]] cfdp::ConditionCodes getConditionCode() const; + [[nodiscard]] cfdp::ConditionCode getConditionCode() const; [[nodiscard]] EntityIdTlv* getFaultLoc() const; cfdp::FileSize& getFileSize(); void setChecksum(uint32_t checksum); - void setConditionCode(cfdp::ConditionCodes conditionCode); + void setConditionCode(cfdp::ConditionCode conditionCode); void setFaultLoc(EntityIdTlv* faultLoc); ReturnValue_t setFileSize(size_t size, bool isLarge); private: - cfdp::ConditionCodes conditionCode; + cfdp::ConditionCode conditionCode; uint32_t checksum; cfdp::FileSize fileSize; EntityIdTlv* faultLoc = nullptr; diff --git a/src/fsfw/cfdp/pdu/EofPduCreator.cpp b/src/fsfw/cfdp/pdu/EofPduCreator.cpp index 3e196e02..12a3e696 100644 --- a/src/fsfw/cfdp/pdu/EofPduCreator.cpp +++ b/src/fsfw/cfdp/pdu/EofPduCreator.cpp @@ -3,7 +3,7 @@ #include "fsfw/FSFW.h" EofPduCreator::EofPduCreator(PduConfig &conf, EofInfo &info) - : FileDirectiveCreator(conf, cfdp::FileDirectives::EOF_DIRECTIVE, 9), info(info) { + : FileDirectiveCreator(conf, cfdp::FileDirective::EOF_DIRECTIVE, 9), info(info) { setDirectiveDataFieldLen(info.getSerializedSize(HeaderCreator::getLargeFileFlag())); } @@ -33,7 +33,7 @@ ReturnValue_t EofPduCreator::serialize(uint8_t **buffer, size_t *size, size_t ma uint32_t fileSizeValue = info.getFileSize().getSize(); result = SerializeAdapter::serialize(&fileSizeValue, buffer, size, maxSize, streamEndianness); } - if (info.getFaultLoc() != nullptr and info.getConditionCode() != cfdp::ConditionCodes::NO_ERROR) { + if (info.getFaultLoc() != nullptr and info.getConditionCode() != cfdp::ConditionCode::NO_ERROR) { result = info.getFaultLoc()->serialize(buffer, size, maxSize, streamEndianness); } return result; diff --git a/src/fsfw/cfdp/pdu/EofPduReader.cpp b/src/fsfw/cfdp/pdu/EofPduReader.cpp index 333e1224..c80c501c 100644 --- a/src/fsfw/cfdp/pdu/EofPduReader.cpp +++ b/src/fsfw/cfdp/pdu/EofPduReader.cpp @@ -25,7 +25,7 @@ ReturnValue_t EofPduReader::parseData() { bufPtr += currentIdx; deserLen -= currentIdx; - info.setConditionCode(static_cast(*bufPtr >> 4)); + info.setConditionCode(static_cast(*bufPtr >> 4)); bufPtr += 1; deserLen -= 1; uint32_t checksum = 0; @@ -47,7 +47,7 @@ ReturnValue_t EofPduReader::parseData() { if (result != returnvalue::OK) { return result; } - if (info.getConditionCode() != cfdp::ConditionCodes::NO_ERROR) { + if (info.getConditionCode() != cfdp::ConditionCode::NO_ERROR) { EntityIdTlv* tlvPtr = info.getFaultLoc(); if (tlvPtr == nullptr) { #if FSFW_VERBOSE_LEVEL >= 1 diff --git a/src/fsfw/cfdp/pdu/FileDataCreator.cpp b/src/fsfw/cfdp/pdu/FileDataCreator.cpp index b9a45b5a..956752fb 100644 --- a/src/fsfw/cfdp/pdu/FileDataCreator.cpp +++ b/src/fsfw/cfdp/pdu/FileDataCreator.cpp @@ -3,7 +3,7 @@ #include FileDataCreator::FileDataCreator(PduConfig& conf, FileDataInfo& info) - : HeaderCreator(conf, cfdp::PduTypes::FILE_DATA, 0, info.getSegmentMetadataFlag()), info(info) { + : HeaderCreator(conf, cfdp::PduType::FILE_DATA, 0, info.getSegmentMetadataFlag()), info(info) { update(); } diff --git a/src/fsfw/cfdp/pdu/FileDirectiveCreator.cpp b/src/fsfw/cfdp/pdu/FileDirectiveCreator.cpp index 1e4da14d..20f93df9 100644 --- a/src/fsfw/cfdp/pdu/FileDirectiveCreator.cpp +++ b/src/fsfw/cfdp/pdu/FileDirectiveCreator.cpp @@ -1,8 +1,8 @@ #include "FileDirectiveCreator.h" -FileDirectiveCreator::FileDirectiveCreator(PduConfig &pduConf, cfdp::FileDirectives directiveCode, +FileDirectiveCreator::FileDirectiveCreator(PduConfig &pduConf, cfdp::FileDirective directiveCode, size_t directiveParamFieldLen) - : HeaderCreator(pduConf, cfdp::PduTypes::FILE_DIRECTIVE, directiveParamFieldLen + 1), + : HeaderCreator(pduConf, cfdp::PduType::FILE_DIRECTIVE, directiveParamFieldLen + 1), directiveCode(directiveCode) {} size_t FileDirectiveCreator::getSerializedSize() const { @@ -36,4 +36,4 @@ void FileDirectiveCreator::setDirectiveDataFieldLen(size_t len) { HeaderCreator::setPduDataFieldLen(len + 1); } -cfdp::FileDirectives FileDirectiveCreator::getDirectiveCode() const { return directiveCode; } +cfdp::FileDirective FileDirectiveCreator::getDirectiveCode() const { return directiveCode; } diff --git a/src/fsfw/cfdp/pdu/FileDirectiveCreator.h b/src/fsfw/cfdp/pdu/FileDirectiveCreator.h index a3b676b0..9b7f2f52 100644 --- a/src/fsfw/cfdp/pdu/FileDirectiveCreator.h +++ b/src/fsfw/cfdp/pdu/FileDirectiveCreator.h @@ -5,10 +5,10 @@ class FileDirectiveCreator : public HeaderCreator { public: - FileDirectiveCreator(PduConfig& pduConf, cfdp::FileDirectives directiveCode, + FileDirectiveCreator(PduConfig& pduConf, cfdp::FileDirective directiveCode, size_t directiveParamFieldLen); - [[nodiscard]] cfdp::FileDirectives getDirectiveCode() const; + [[nodiscard]] cfdp::FileDirective getDirectiveCode() const; /** * This only returns the size of the PDU header + 1 for the directive code octet. @@ -28,7 +28,7 @@ class FileDirectiveCreator : public HeaderCreator { void setDirectiveDataFieldLen(size_t len); private: - cfdp::FileDirectives directiveCode = cfdp::FileDirectives::INVALID_DIRECTIVE; + cfdp::FileDirective directiveCode = cfdp::FileDirective::INVALID_DIRECTIVE; }; #endif /* FSFW_SRC_FSFW_CFDP_PDU_FILEDIRECTIVESERIALIZER_H_ */ diff --git a/src/fsfw/cfdp/pdu/FileDirectiveReader.cpp b/src/fsfw/cfdp/pdu/FileDirectiveReader.cpp index 748ac830..f5fc6e58 100644 --- a/src/fsfw/cfdp/pdu/FileDirectiveReader.cpp +++ b/src/fsfw/cfdp/pdu/FileDirectiveReader.cpp @@ -3,7 +3,7 @@ FileDirectiveReader::FileDirectiveReader(const uint8_t *pduBuf, size_t maxSize) : PduHeaderReader(pduBuf, maxSize) {} -cfdp::FileDirectives FileDirectiveReader::getFileDirective() const { return fileDirective; } +cfdp::FileDirective FileDirectiveReader::getFileDirective() const { return fileDirective; } ReturnValue_t FileDirectiveReader::parseData() { ReturnValue_t result = PduHeaderReader::parseData(); @@ -20,7 +20,7 @@ ReturnValue_t FileDirectiveReader::parseData() { if (not checkFileDirective(pointers.rawPtr[currentIdx])) { return cfdp::INVALID_DIRECTIVE_FIELD; } - setFileDirective(static_cast(pointers.rawPtr[currentIdx])); + setFileDirective(static_cast(pointers.rawPtr[currentIdx])); return returnvalue::OK; } @@ -30,15 +30,15 @@ size_t FileDirectiveReader::getHeaderSize() const { } bool FileDirectiveReader::checkFileDirective(uint8_t rawByte) { - if (rawByte < cfdp::FileDirectives::EOF_DIRECTIVE or - (rawByte > cfdp::FileDirectives::PROMPT and rawByte != cfdp::FileDirectives::KEEP_ALIVE)) { + if (rawByte < cfdp::FileDirective::EOF_DIRECTIVE or + (rawByte > cfdp::FileDirective::PROMPT and rawByte != cfdp::FileDirective::KEEP_ALIVE)) { // Invalid directive field return false; } return true; } -void FileDirectiveReader::setFileDirective(cfdp::FileDirectives fileDirective_) { +void FileDirectiveReader::setFileDirective(cfdp::FileDirective fileDirective_) { fileDirective = fileDirective_; } diff --git a/src/fsfw/cfdp/pdu/FileDirectiveReader.h b/src/fsfw/cfdp/pdu/FileDirectiveReader.h index 5bec486c..9e88e006 100644 --- a/src/fsfw/cfdp/pdu/FileDirectiveReader.h +++ b/src/fsfw/cfdp/pdu/FileDirectiveReader.h @@ -22,7 +22,7 @@ class FileDirectiveReader : public PduHeaderReader { ReturnValue_t parseData() override; [[nodiscard]] size_t getHeaderSize() const override; - [[nodiscard]] cfdp::FileDirectives getFileDirective() const; + [[nodiscard]] cfdp::FileDirective getFileDirective() const; void setEndianness(SerializeIF::Endianness endianness); [[nodiscard]] SerializeIF::Endianness getEndianness() const; @@ -30,8 +30,8 @@ class FileDirectiveReader : public PduHeaderReader { protected: private: - void setFileDirective(cfdp::FileDirectives fileDirective); - cfdp::FileDirectives fileDirective = cfdp::FileDirectives::INVALID_DIRECTIVE; + void setFileDirective(cfdp::FileDirective fileDirective); + cfdp::FileDirective fileDirective = cfdp::FileDirective::INVALID_DIRECTIVE; SerializeIF::Endianness endianness = SerializeIF::Endianness::NETWORK; }; diff --git a/src/fsfw/cfdp/pdu/FinishedInfo.cpp b/src/fsfw/cfdp/pdu/FinishedInfo.cpp index 5b4ae0ca..2f986e85 100644 --- a/src/fsfw/cfdp/pdu/FinishedInfo.cpp +++ b/src/fsfw/cfdp/pdu/FinishedInfo.cpp @@ -2,7 +2,7 @@ FinishedInfo::FinishedInfo() {} -FinishedInfo::FinishedInfo(cfdp::ConditionCodes conditionCode, cfdp::FileDeliveryCode deliveryCode, +FinishedInfo::FinishedInfo(cfdp::ConditionCode conditionCode, cfdp::FileDeliveryCode deliveryCode, cfdp::FileDeliveryStatus fileStatus) : conditionCode(conditionCode), deliveryCode(deliveryCode), fileStatus(fileStatus) {} @@ -76,9 +76,9 @@ ReturnValue_t FinishedInfo::getFaultLocation(EntityIdTlv** faultLocation) { return returnvalue::OK; } -cfdp::ConditionCodes FinishedInfo::getConditionCode() const { return conditionCode; } +cfdp::ConditionCode FinishedInfo::getConditionCode() const { return conditionCode; } -void FinishedInfo::setConditionCode(cfdp::ConditionCodes conditionCode) { +void FinishedInfo::setConditionCode(cfdp::ConditionCode conditionCode) { this->conditionCode = conditionCode; } diff --git a/src/fsfw/cfdp/pdu/FinishedInfo.h b/src/fsfw/cfdp/pdu/FinishedInfo.h index 1a2beade..49d7c64d 100644 --- a/src/fsfw/cfdp/pdu/FinishedInfo.h +++ b/src/fsfw/cfdp/pdu/FinishedInfo.h @@ -8,7 +8,7 @@ class FinishedInfo { public: FinishedInfo(); - FinishedInfo(cfdp::ConditionCodes conditionCode, cfdp::FileDeliveryCode deliveryCode, + FinishedInfo(cfdp::ConditionCode conditionCode, cfdp::FileDeliveryCode deliveryCode, cfdp::FileDeliveryStatus fileStatus); [[nodiscard]] size_t getSerializedSize() const; @@ -25,15 +25,15 @@ class FinishedInfo { [[nodiscard]] size_t getFsResponsesLen() const; void setFilestoreResponsesArrayLen(size_t fsResponsesLen); ReturnValue_t getFaultLocation(EntityIdTlv** entityId); - [[nodiscard]] cfdp::ConditionCodes getConditionCode() const; - void setConditionCode(cfdp::ConditionCodes conditionCode); + [[nodiscard]] cfdp::ConditionCode getConditionCode() const; + void setConditionCode(cfdp::ConditionCode conditionCode); [[nodiscard]] cfdp::FileDeliveryCode getDeliveryCode() const; void setDeliveryCode(cfdp::FileDeliveryCode deliveryCode); [[nodiscard]] cfdp::FileDeliveryStatus getFileStatus() const; void setFileStatus(cfdp::FileDeliveryStatus fileStatus); private: - cfdp::ConditionCodes conditionCode = cfdp::ConditionCodes::NO_CONDITION_FIELD; + cfdp::ConditionCode conditionCode = cfdp::ConditionCode::NO_CONDITION_FIELD; cfdp::FileDeliveryCode deliveryCode = cfdp::FileDeliveryCode::DATA_COMPLETE; cfdp::FileDeliveryStatus fileStatus = cfdp::FileDeliveryStatus::DISCARDED_DELIBERATELY; FilestoreResponseTlv** fsResponses = nullptr; diff --git a/src/fsfw/cfdp/pdu/FinishedPduCreator.cpp b/src/fsfw/cfdp/pdu/FinishedPduCreator.cpp index 88f4491c..8ac22e0a 100644 --- a/src/fsfw/cfdp/pdu/FinishedPduCreator.cpp +++ b/src/fsfw/cfdp/pdu/FinishedPduCreator.cpp @@ -1,7 +1,7 @@ #include "FinishedPduCreator.h" FinishPduCreator::FinishPduCreator(PduConfig &conf, FinishedInfo &finishInfo) - : FileDirectiveCreator(conf, cfdp::FileDirectives::FINISH, 0), finishInfo(finishInfo) { + : FileDirectiveCreator(conf, cfdp::FileDirective::FINISH, 0), finishInfo(finishInfo) { updateDirectiveFieldLen(); } diff --git a/src/fsfw/cfdp/pdu/FinishedPduReader.cpp b/src/fsfw/cfdp/pdu/FinishedPduReader.cpp index a34abf07..08dd3a82 100644 --- a/src/fsfw/cfdp/pdu/FinishedPduReader.cpp +++ b/src/fsfw/cfdp/pdu/FinishedPduReader.cpp @@ -15,7 +15,7 @@ ReturnValue_t FinishPduReader::parseData() { return SerializeIF::STREAM_TOO_SHORT; } uint8_t firstByte = *buf; - auto condCode = static_cast((firstByte >> 4) & 0x0f); + auto condCode = static_cast((firstByte >> 4) & 0x0f); finishedInfo.setConditionCode(condCode); finishedInfo.setDeliveryCode(static_cast(firstByte >> 2 & 0b1)); finishedInfo.setFileStatus(static_cast(firstByte & 0b11)); @@ -31,14 +31,14 @@ ReturnValue_t FinishPduReader::parseData() { FinishedInfo& FinishPduReader::getInfo() { return finishedInfo; } ReturnValue_t FinishPduReader::parseTlvs(size_t remLen, size_t currentIdx, const uint8_t* buf, - cfdp::ConditionCodes conditionCode) { + cfdp::ConditionCode conditionCode) { ReturnValue_t result = returnvalue::OK; size_t fsResponsesIdx = 0; auto endianness = getEndianness(); FilestoreResponseTlv** fsResponseArray = nullptr; size_t fsResponseMaxArrayLen = 0; EntityIdTlv* faultLocation = nullptr; - cfdp::TlvTypes nextTlv = cfdp::TlvTypes::INVALID_TLV; + cfdp::TlvType nextTlv = cfdp::TlvType::INVALID_TLV; while (remLen > 0) { // Simply forward parse the TLV type. Every TLV type except the last one must be a Filestore // Response TLV, and even the last one can be a Filestore Response TLV if the fault @@ -46,8 +46,8 @@ ReturnValue_t FinishPduReader::parseTlvs(size_t remLen, size_t currentIdx, const if (currentIdx + 2 > maxSize) { return SerializeIF::STREAM_TOO_SHORT; } - nextTlv = static_cast(*buf); - if (nextTlv == cfdp::TlvTypes::FILESTORE_RESPONSE) { + nextTlv = static_cast(*buf); + if (nextTlv == cfdp::TlvType::FILESTORE_RESPONSE) { if (fsResponseArray == nullptr) { if (not finishedInfo.canHoldFsResponses()) { return cfdp::FINISHED_CANT_PARSE_FS_RESPONSES; @@ -63,11 +63,11 @@ ReturnValue_t FinishPduReader::parseTlvs(size_t remLen, size_t currentIdx, const return result; } fsResponsesIdx += 1; - } else if (nextTlv == cfdp::TlvTypes::ENTITY_ID) { + } else if (nextTlv == cfdp::TlvType::ENTITY_ID) { // This needs to be the last TLV and it should not be here if the condition code // is "No Error" or "Unsupported Checksum Type" - if (conditionCode == cfdp::ConditionCodes::NO_ERROR or - conditionCode == cfdp::ConditionCodes::UNSUPPORTED_CHECKSUM_TYPE) { + if (conditionCode == cfdp::ConditionCode::NO_ERROR or + conditionCode == cfdp::ConditionCode::UNSUPPORTED_CHECKSUM_TYPE) { return cfdp::INVALID_TLV_TYPE; } result = finishedInfo.getFaultLocation(&faultLocation); diff --git a/src/fsfw/cfdp/pdu/FinishedPduReader.h b/src/fsfw/cfdp/pdu/FinishedPduReader.h index ce489fcd..791a2ef4 100644 --- a/src/fsfw/cfdp/pdu/FinishedPduReader.h +++ b/src/fsfw/cfdp/pdu/FinishedPduReader.h @@ -16,7 +16,7 @@ class FinishPduReader : public FileDirectiveReader { FinishedInfo& finishedInfo; ReturnValue_t parseTlvs(size_t remLen, size_t currentIdx, const uint8_t* buf, - cfdp::ConditionCodes conditionCode); + cfdp::ConditionCode conditionCode); }; #endif /* FSFW_CFDP_PDU_FINISHEDPDUDESERIALIZER_H_ */ diff --git a/src/fsfw/cfdp/pdu/HeaderCreator.cpp b/src/fsfw/cfdp/pdu/HeaderCreator.cpp index 3c50c396..29688575 100644 --- a/src/fsfw/cfdp/pdu/HeaderCreator.cpp +++ b/src/fsfw/cfdp/pdu/HeaderCreator.cpp @@ -1,6 +1,6 @@ #include "HeaderCreator.h" -HeaderCreator::HeaderCreator(PduConfig &pduConf, cfdp::PduTypes pduType, size_t initPduDataFieldLen, +HeaderCreator::HeaderCreator(PduConfig &pduConf, cfdp::PduType pduType, size_t initPduDataFieldLen, cfdp::SegmentMetadataFlag segmentMetadataFlag, cfdp::SegmentationControl segCtrl) : pduType(pduType), @@ -65,17 +65,17 @@ void HeaderCreator::setPduDataFieldLen(size_t pduDataFieldLen_) { pduDataFieldLen = pduDataFieldLen_; } -void HeaderCreator::setPduType(cfdp::PduTypes pduType_) { pduType = pduType_; } +void HeaderCreator::setPduType(cfdp::PduType pduType_) { pduType = pduType_; } void HeaderCreator::setSegmentMetadataFlag(cfdp::SegmentMetadataFlag segmentMetadataFlag_) { segmentMetadataFlag = segmentMetadataFlag_; } -cfdp::PduTypes HeaderCreator::getPduType() const { return pduType; } +cfdp::PduType HeaderCreator::getPduType() const { return pduType; } cfdp::Direction HeaderCreator::getDirection() const { return pduConf.direction; } -cfdp::TransmissionModes HeaderCreator::getTransmissionMode() const { return pduConf.mode; } +cfdp::TransmissionMode HeaderCreator::getTransmissionMode() const { return pduConf.mode; } bool HeaderCreator::getCrcFlag() const { return pduConf.crcFlag; } diff --git a/src/fsfw/cfdp/pdu/HeaderCreator.h b/src/fsfw/cfdp/pdu/HeaderCreator.h index a4b5c7ff..173a6239 100644 --- a/src/fsfw/cfdp/pdu/HeaderCreator.h +++ b/src/fsfw/cfdp/pdu/HeaderCreator.h @@ -9,7 +9,7 @@ class HeaderCreator : public SerializeIF, public PduHeaderIF { public: HeaderCreator( - PduConfig& pduConf, cfdp::PduTypes pduType, size_t initPduDataFieldLen, + PduConfig& pduConf, cfdp::PduType pduType, size_t initPduDataFieldLen, cfdp::SegmentMetadataFlag segmentMetadataFlag = cfdp::SegmentMetadataFlag::NOT_PRESENT, cfdp::SegmentationControl segCtrl = cfdp::SegmentationControl::NO_RECORD_BOUNDARIES_PRESERVATION); @@ -29,15 +29,15 @@ class HeaderCreator : public SerializeIF, public PduHeaderIF { Endianness streamEndianness) override; void setPduDataFieldLen(size_t pduDataFieldLen); - void setPduType(cfdp::PduTypes pduType); + void setPduType(cfdp::PduType pduType); void setSegmentMetadataFlag(cfdp::SegmentMetadataFlag); [[nodiscard]] size_t getPduDataFieldLen() const override; [[nodiscard]] size_t getWholePduSize() const override; - [[nodiscard]] cfdp::PduTypes getPduType() const override; + [[nodiscard]] cfdp::PduType getPduType() const override; [[nodiscard]] cfdp::Direction getDirection() const override; - [[nodiscard]] cfdp::TransmissionModes getTransmissionMode() const override; + [[nodiscard]] cfdp::TransmissionMode getTransmissionMode() const override; [[nodiscard]] bool getCrcFlag() const override; [[nodiscard]] bool getLargeFileFlag() const override; [[nodiscard]] cfdp::SegmentationControl getSegmentationControl() const override; @@ -52,7 +52,7 @@ class HeaderCreator : public SerializeIF, public PduHeaderIF { void getTransactionSeqNum(cfdp::TransactionSeqNum& seqNum) const override; private: - cfdp::PduTypes pduType; + cfdp::PduType pduType; cfdp::SegmentMetadataFlag segmentMetadataFlag; cfdp::SegmentationControl segmentationCtrl; size_t pduDataFieldLen; diff --git a/src/fsfw/cfdp/pdu/HeaderReader.cpp b/src/fsfw/cfdp/pdu/HeaderReader.cpp index f8b19ce2..9edf2394 100644 --- a/src/fsfw/cfdp/pdu/HeaderReader.cpp +++ b/src/fsfw/cfdp/pdu/HeaderReader.cpp @@ -57,16 +57,16 @@ size_t PduHeaderReader::getWholePduSize() const { return getPduDataFieldLen() + PduHeaderReader::getHeaderSize(); } -cfdp::PduTypes PduHeaderReader::getPduType() const { - return static_cast((pointers.fixedHeader->firstByte >> 4) & 0x01); +cfdp::PduType PduHeaderReader::getPduType() const { + return static_cast((pointers.fixedHeader->firstByte >> 4) & 0x01); } cfdp::Direction PduHeaderReader::getDirection() const { return static_cast((pointers.fixedHeader->firstByte >> 3) & 0x01); } -cfdp::TransmissionModes PduHeaderReader::getTransmissionMode() const { - return static_cast((pointers.fixedHeader->firstByte >> 2) & 0x01); +cfdp::TransmissionMode PduHeaderReader::getTransmissionMode() const { + return static_cast((pointers.fixedHeader->firstByte >> 2) & 0x01); } bool PduHeaderReader::getCrcFlag() const { return (pointers.fixedHeader->firstByte >> 1) & 0x01; } diff --git a/src/fsfw/cfdp/pdu/KeepAlivePduCreator.cpp b/src/fsfw/cfdp/pdu/KeepAlivePduCreator.cpp index 8b0ad6c8..40747751 100644 --- a/src/fsfw/cfdp/pdu/KeepAlivePduCreator.cpp +++ b/src/fsfw/cfdp/pdu/KeepAlivePduCreator.cpp @@ -1,7 +1,7 @@ #include "KeepAlivePduCreator.h" KeepAlivePduCreator::KeepAlivePduCreator(PduConfig &conf, cfdp::FileSize &progress) - : FileDirectiveCreator(conf, cfdp::FileDirectives::KEEP_ALIVE, 4), progress(progress) { + : FileDirectiveCreator(conf, cfdp::FileDirective::KEEP_ALIVE, 4), progress(progress) { updateDirectiveFieldLen(); } diff --git a/src/fsfw/cfdp/pdu/MetadataInfo.cpp b/src/fsfw/cfdp/pdu/MetadataInfo.cpp index e1eb3ad8..d88bdd87 100644 --- a/src/fsfw/cfdp/pdu/MetadataInfo.cpp +++ b/src/fsfw/cfdp/pdu/MetadataInfo.cpp @@ -1,6 +1,6 @@ #include "MetadataInfo.h" -MetadataInfo::MetadataInfo(bool closureRequested, cfdp::ChecksumTypes checksumType, +MetadataInfo::MetadataInfo(bool closureRequested, cfdp::ChecksumType checksumType, cfdp::FileSize& fileSize, cfdp::StringLv& sourceFileName, cfdp::StringLv& destFileName) : MetadataInfo(fileSize, sourceFileName, destFileName) { @@ -23,9 +23,9 @@ void MetadataInfo::setOptionsArray(cfdp::Tlv** optionsArray_, std::optional optionsLen, std::optional maxOptionsLen); - [[nodiscard]] cfdp::ChecksumTypes getChecksumType() const; - void setChecksumType(cfdp::ChecksumTypes checksumType); + [[nodiscard]] cfdp::ChecksumType getChecksumType() const; + void setChecksumType(cfdp::ChecksumType checksumType); [[nodiscard]] bool isClosureRequested() const; void setClosureRequested(bool closureRequested = false); @@ -42,7 +42,7 @@ class MetadataInfo { private: bool closureRequested = false; - cfdp::ChecksumTypes checksumType = cfdp::ChecksumTypes::NULL_CHECKSUM; + cfdp::ChecksumType checksumType = cfdp::ChecksumType::NULL_CHECKSUM; cfdp::FileSize& fileSize; cfdp::StringLv& sourceFileName; cfdp::StringLv& destFileName; diff --git a/src/fsfw/cfdp/pdu/MetadataPduCreator.cpp b/src/fsfw/cfdp/pdu/MetadataPduCreator.cpp index fe0d04c2..536a48f4 100644 --- a/src/fsfw/cfdp/pdu/MetadataPduCreator.cpp +++ b/src/fsfw/cfdp/pdu/MetadataPduCreator.cpp @@ -1,7 +1,7 @@ #include "MetadataPduCreator.h" MetadataPduCreator::MetadataPduCreator(PduConfig &conf, MetadataInfo &info) - : FileDirectiveCreator(conf, cfdp::FileDirectives::METADATA, 5), info(info) { + : FileDirectiveCreator(conf, cfdp::FileDirective::METADATA, 5), info(info) { updateDirectiveFieldLen(); } diff --git a/src/fsfw/cfdp/pdu/MetadataPduReader.cpp b/src/fsfw/cfdp/pdu/MetadataPduReader.cpp index caf8287b..66025140 100644 --- a/src/fsfw/cfdp/pdu/MetadataPduReader.cpp +++ b/src/fsfw/cfdp/pdu/MetadataPduReader.cpp @@ -15,7 +15,7 @@ ReturnValue_t MetadataPduReader::parseData() { return SerializeIF::STREAM_TOO_SHORT; } info.setClosureRequested((*buf >> 6) & 0x01); - info.setChecksumType(static_cast(*buf & 0x0f)); + info.setChecksumType(static_cast(*buf & 0x0f)); remSize -= 1; buf += 1; auto endianness = getEndianness(); diff --git a/src/fsfw/cfdp/pdu/NakPduCreator.cpp b/src/fsfw/cfdp/pdu/NakPduCreator.cpp index c4493fcb..11f3aba9 100644 --- a/src/fsfw/cfdp/pdu/NakPduCreator.cpp +++ b/src/fsfw/cfdp/pdu/NakPduCreator.cpp @@ -1,7 +1,7 @@ #include "NakPduCreator.h" NakPduCreator::NakPduCreator(PduConfig &pduConf, NakInfo &nakInfo) - : FileDirectiveCreator(pduConf, cfdp::FileDirectives::NAK, 0), nakInfo(nakInfo) { + : FileDirectiveCreator(pduConf, cfdp::FileDirective::NAK, 0), nakInfo(nakInfo) { updateDirectiveFieldLen(); } diff --git a/src/fsfw/cfdp/pdu/PduConfig.cpp b/src/fsfw/cfdp/pdu/PduConfig.cpp index dd04e986..ccb20f51 100644 --- a/src/fsfw/cfdp/pdu/PduConfig.cpp +++ b/src/fsfw/cfdp/pdu/PduConfig.cpp @@ -2,7 +2,7 @@ #include -PduConfig::PduConfig(cfdp::EntityId sourceId, cfdp::EntityId destId, cfdp::TransmissionModes mode, +PduConfig::PduConfig(cfdp::EntityId sourceId, cfdp::EntityId destId, cfdp::TransmissionMode mode, cfdp::TransactionSeqNum seqNum, bool crcFlag, bool largeFile, cfdp::Direction direction) : mode(mode), diff --git a/src/fsfw/cfdp/pdu/PduConfig.h b/src/fsfw/cfdp/pdu/PduConfig.h index 368999cc..70f37e38 100644 --- a/src/fsfw/cfdp/pdu/PduConfig.h +++ b/src/fsfw/cfdp/pdu/PduConfig.h @@ -7,11 +7,11 @@ class PduConfig { public: PduConfig() = default; - PduConfig(cfdp::EntityId sourceId, cfdp::EntityId destId, cfdp::TransmissionModes mode, + PduConfig(cfdp::EntityId sourceId, cfdp::EntityId destId, cfdp::TransmissionMode mode, cfdp::TransactionSeqNum seqNum, bool crcFlag = false, bool largeFile = false, cfdp::Direction direction = cfdp::Direction::TOWARDS_RECEIVER); - cfdp::TransmissionModes mode = cfdp::TransmissionModes::ACKNOWLEDGED; + cfdp::TransmissionMode mode = cfdp::TransmissionMode::ACKNOWLEDGED; cfdp::TransactionSeqNum seqNum; cfdp::EntityId sourceId; cfdp::EntityId destId; diff --git a/src/fsfw/cfdp/pdu/PduHeaderIF.h b/src/fsfw/cfdp/pdu/PduHeaderIF.h index d9e4017d..341b0335 100644 --- a/src/fsfw/cfdp/pdu/PduHeaderIF.h +++ b/src/fsfw/cfdp/pdu/PduHeaderIF.h @@ -17,9 +17,9 @@ class PduHeaderIF { [[nodiscard]] virtual size_t getWholePduSize() const = 0; [[nodiscard]] virtual size_t getPduDataFieldLen() const = 0; - [[nodiscard]] virtual cfdp::PduTypes getPduType() const = 0; + [[nodiscard]] virtual cfdp::PduType getPduType() const = 0; [[nodiscard]] virtual cfdp::Direction getDirection() const = 0; - [[nodiscard]] virtual cfdp::TransmissionModes getTransmissionMode() const = 0; + [[nodiscard]] virtual cfdp::TransmissionMode getTransmissionMode() const = 0; [[nodiscard]] virtual bool getCrcFlag() const = 0; [[nodiscard]] virtual bool getLargeFileFlag() const = 0; [[nodiscard]] virtual cfdp::SegmentationControl getSegmentationControl() const = 0; diff --git a/src/fsfw/cfdp/pdu/PduHeaderReader.h b/src/fsfw/cfdp/pdu/PduHeaderReader.h index a36b2145..a2e122cd 100644 --- a/src/fsfw/cfdp/pdu/PduHeaderReader.h +++ b/src/fsfw/cfdp/pdu/PduHeaderReader.h @@ -56,9 +56,9 @@ class PduHeaderReader : public RedirectableDataPointerIF, public PduHeaderIF { [[nodiscard]] size_t getPduDataFieldLen() const override; [[nodiscard]] size_t getWholePduSize() const override; - [[nodiscard]] cfdp::PduTypes getPduType() const override; + [[nodiscard]] cfdp::PduType getPduType() const override; [[nodiscard]] cfdp::Direction getDirection() const override; - [[nodiscard]] cfdp::TransmissionModes getTransmissionMode() const override; + [[nodiscard]] cfdp::TransmissionMode getTransmissionMode() const override; [[nodiscard]] bool getCrcFlag() const override; [[nodiscard]] bool getLargeFileFlag() const override; [[nodiscard]] cfdp::SegmentationControl getSegmentationControl() const override; diff --git a/src/fsfw/cfdp/pdu/PromptPduCreator.cpp b/src/fsfw/cfdp/pdu/PromptPduCreator.cpp index 43077cf6..f4141fdb 100644 --- a/src/fsfw/cfdp/pdu/PromptPduCreator.cpp +++ b/src/fsfw/cfdp/pdu/PromptPduCreator.cpp @@ -1,7 +1,7 @@ #include "PromptPduCreator.h" PromptPduCreator::PromptPduCreator(PduConfig &conf, cfdp::PromptResponseRequired responseRequired) - : FileDirectiveCreator(conf, cfdp::FileDirectives::PROMPT, 1), + : FileDirectiveCreator(conf, cfdp::FileDirective::PROMPT, 1), responseRequired(responseRequired) {} size_t PromptPduCreator::getSerializedSize() const { diff --git a/src/fsfw/cfdp/tlv/EntityIdTlv.cpp b/src/fsfw/cfdp/tlv/EntityIdTlv.cpp index 87f55db8..d4c4d6a8 100644 --- a/src/fsfw/cfdp/tlv/EntityIdTlv.cpp +++ b/src/fsfw/cfdp/tlv/EntityIdTlv.cpp @@ -11,7 +11,7 @@ ReturnValue_t EntityIdTlv::serialize(uint8_t **buffer, size_t *size, size_t maxS if (maxSize < this->getSerializedSize()) { return BUFFER_TOO_SHORT; } - **buffer = cfdp::TlvTypes::ENTITY_ID; + **buffer = cfdp::TlvType::ENTITY_ID; *size += 1; *buffer += 1; size_t serLen = entityId.getSerializedSize(); @@ -28,8 +28,8 @@ ReturnValue_t EntityIdTlv::deSerialize(const uint8_t **buffer, size_t *size, if (*size < 3) { return STREAM_TOO_SHORT; } - cfdp::TlvTypes type = static_cast(**buffer); - if (type != cfdp::TlvTypes::ENTITY_ID) { + cfdp::TlvType type = static_cast(**buffer); + if (type != cfdp::TlvType::ENTITY_ID) { return cfdp::INVALID_TLV_TYPE; } *buffer += 1; @@ -54,6 +54,6 @@ ReturnValue_t EntityIdTlv::deSerialize(cfdp::Tlv &tlv, Endianness endianness) { uint8_t EntityIdTlv::getLengthField() const { return 1 + entityId.getSerializedSize(); } -cfdp::TlvTypes EntityIdTlv::getType() const { return cfdp::TlvTypes::ENTITY_ID; } +cfdp::TlvType EntityIdTlv::getType() const { return cfdp::TlvType::ENTITY_ID; } cfdp::EntityId &EntityIdTlv::getEntityId() { return entityId; } diff --git a/src/fsfw/cfdp/tlv/EntityIdTlv.h b/src/fsfw/cfdp/tlv/EntityIdTlv.h index 1443cc17..ac310899 100644 --- a/src/fsfw/cfdp/tlv/EntityIdTlv.h +++ b/src/fsfw/cfdp/tlv/EntityIdTlv.h @@ -27,7 +27,7 @@ class EntityIdTlv : public TlvIF { Endianness streamEndianness) override; uint8_t getLengthField() const override; - cfdp::TlvTypes getType() const override; + cfdp::TlvType getType() const override; cfdp::EntityId& getEntityId(); diff --git a/src/fsfw/cfdp/tlv/FaultHandlerOverrideTlv.cpp b/src/fsfw/cfdp/tlv/FaultHandlerOverrideTlv.cpp index 684d47c2..90b71361 100644 --- a/src/fsfw/cfdp/tlv/FaultHandlerOverrideTlv.cpp +++ b/src/fsfw/cfdp/tlv/FaultHandlerOverrideTlv.cpp @@ -1,7 +1,7 @@ #include "FaultHandlerOverrideTlv.h" -FaultHandlerOverrideTlv::FaultHandlerOverrideTlv(cfdp::ConditionCodes conditionCode, - cfdp::FaultHandlerCodes handlerCode) +FaultHandlerOverrideTlv::FaultHandlerOverrideTlv(cfdp::ConditionCode conditionCode, + cfdp::FaultHandlerCode handlerCode) : conditionCode(conditionCode), handlerCode(handlerCode) {} FaultHandlerOverrideTlv::FaultHandlerOverrideTlv() = default; @@ -32,8 +32,8 @@ ReturnValue_t FaultHandlerOverrideTlv::deSerialize(const uint8_t **buffer, size_ if (*size < 3) { return SerializeIF::STREAM_TOO_SHORT; } - auto detectedType = static_cast(**buffer); - if (detectedType != cfdp::TlvTypes::FAULT_HANDLER) { + auto detectedType = static_cast(**buffer); + if (detectedType != cfdp::TlvType::FAULT_HANDLER) { return cfdp::INVALID_TLV_TYPE; } *buffer += 1; @@ -44,11 +44,11 @@ ReturnValue_t FaultHandlerOverrideTlv::deSerialize(const uint8_t **buffer, size_ } *buffer += 1; *size += 1; - this->conditionCode = static_cast((**buffer >> 4) & 0x0f); - this->handlerCode = static_cast(**buffer & 0x0f); + this->conditionCode = static_cast((**buffer >> 4) & 0x0f); + this->handlerCode = static_cast(**buffer & 0x0f); *buffer += 1; *size += 1; return returnvalue::OK; } -cfdp::TlvTypes FaultHandlerOverrideTlv::getType() const { return cfdp::TlvTypes::FAULT_HANDLER; } +cfdp::TlvType FaultHandlerOverrideTlv::getType() const { return cfdp::TlvType::FAULT_HANDLER; } diff --git a/src/fsfw/cfdp/tlv/FaultHandlerOverrideTlv.h b/src/fsfw/cfdp/tlv/FaultHandlerOverrideTlv.h index 33a7fdab..9f5cd486 100644 --- a/src/fsfw/cfdp/tlv/FaultHandlerOverrideTlv.h +++ b/src/fsfw/cfdp/tlv/FaultHandlerOverrideTlv.h @@ -6,7 +6,7 @@ class FaultHandlerOverrideTlv : public TlvIF { public: FaultHandlerOverrideTlv(); - FaultHandlerOverrideTlv(cfdp::ConditionCodes conditionCode, cfdp::FaultHandlerCodes handlerCode); + FaultHandlerOverrideTlv(cfdp::ConditionCode conditionCode, cfdp::FaultHandlerCode handlerCode); ReturnValue_t serialize(uint8_t **buffer, size_t *size, size_t maxSize, Endianness streamEndianness) const override; @@ -16,11 +16,11 @@ class FaultHandlerOverrideTlv : public TlvIF { ReturnValue_t deSerialize(const uint8_t **buffer, size_t *size, Endianness streamEndianness) override; [[nodiscard]] uint8_t getLengthField() const override; - [[nodiscard]] cfdp::TlvTypes getType() const override; + [[nodiscard]] cfdp::TlvType getType() const override; private: - cfdp::ConditionCodes conditionCode = cfdp::ConditionCodes::NO_CONDITION_FIELD; - cfdp::FaultHandlerCodes handlerCode = cfdp::FaultHandlerCodes::RESERVED; + cfdp::ConditionCode conditionCode = cfdp::ConditionCode::NO_CONDITION_FIELD; + cfdp::FaultHandlerCode handlerCode = cfdp::FaultHandlerCode::RESERVED; }; #endif /* FSFW_SRC_FSFW_CFDP_TLV_FAULTHANDLEROVERRIDETLV_H_ */ diff --git a/src/fsfw/cfdp/tlv/FilestoreRequestTlv.cpp b/src/fsfw/cfdp/tlv/FilestoreRequestTlv.cpp index 744d79c1..1022a7d1 100644 --- a/src/fsfw/cfdp/tlv/FilestoreRequestTlv.cpp +++ b/src/fsfw/cfdp/tlv/FilestoreRequestTlv.cpp @@ -76,4 +76,4 @@ ReturnValue_t FilestoreRequestTlv::deSerializeFromValue(const uint8_t **buffer, return result; } -cfdp::TlvTypes FilestoreRequestTlv::getType() const { return cfdp::TlvTypes::FILESTORE_REQUEST; } +cfdp::TlvType FilestoreRequestTlv::getType() const { return cfdp::TlvType::FILESTORE_REQUEST; } diff --git a/src/fsfw/cfdp/tlv/FilestoreRequestTlv.h b/src/fsfw/cfdp/tlv/FilestoreRequestTlv.h index 94faaa07..02e639b8 100644 --- a/src/fsfw/cfdp/tlv/FilestoreRequestTlv.h +++ b/src/fsfw/cfdp/tlv/FilestoreRequestTlv.h @@ -30,7 +30,7 @@ class FilestoreRequestTlv : public cfdp::FilestoreTlvBase { Endianness streamEndianness) override; [[nodiscard]] uint8_t getLengthField() const override; - [[nodiscard]] cfdp::TlvTypes getType() const override; + [[nodiscard]] cfdp::TlvType getType() const override; private: cfdp::Lv *secondFileName = nullptr; diff --git a/src/fsfw/cfdp/tlv/FilestoreResponseTlv.cpp b/src/fsfw/cfdp/tlv/FilestoreResponseTlv.cpp index 51dccfb7..38b56077 100644 --- a/src/fsfw/cfdp/tlv/FilestoreResponseTlv.cpp +++ b/src/fsfw/cfdp/tlv/FilestoreResponseTlv.cpp @@ -112,4 +112,4 @@ ReturnValue_t FilestoreResponseTlv::deSerialize(const cfdp::Tlv &tlv, Endianness uint8_t FilestoreResponseTlv::getStatusCode() const { return statusCode; } -cfdp::TlvTypes FilestoreResponseTlv::getType() const { return cfdp::TlvTypes::FILESTORE_RESPONSE; } +cfdp::TlvType FilestoreResponseTlv::getType() const { return cfdp::TlvType::FILESTORE_RESPONSE; } diff --git a/src/fsfw/cfdp/tlv/FilestoreResponseTlv.h b/src/fsfw/cfdp/tlv/FilestoreResponseTlv.h index 47868693..110f1bb4 100644 --- a/src/fsfw/cfdp/tlv/FilestoreResponseTlv.h +++ b/src/fsfw/cfdp/tlv/FilestoreResponseTlv.h @@ -33,7 +33,7 @@ class FilestoreResponseTlv : public cfdp::FilestoreTlvBase { Endianness streamEndianness) override; [[nodiscard]] uint8_t getLengthField() const override; - [[nodiscard]] cfdp::TlvTypes getType() const override; + [[nodiscard]] cfdp::TlvType getType() const override; private: uint8_t statusCode; diff --git a/src/fsfw/cfdp/tlv/FilestoreTlvBase.h b/src/fsfw/cfdp/tlv/FilestoreTlvBase.h index 4aa47c7e..a5974087 100644 --- a/src/fsfw/cfdp/tlv/FilestoreTlvBase.h +++ b/src/fsfw/cfdp/tlv/FilestoreTlvBase.h @@ -102,7 +102,7 @@ class FilestoreTlvBase : public TlvIF { if (*size < 3) { return SerializeIF::STREAM_TOO_SHORT; } - auto type = static_cast(**buffer); + auto type = static_cast(**buffer); if (type != getType()) { return cfdp::INVALID_TLV_TYPE; } diff --git a/src/fsfw/cfdp/tlv/FlowLabelTlv.cpp b/src/fsfw/cfdp/tlv/FlowLabelTlv.cpp index 938af9f4..5f225669 100644 --- a/src/fsfw/cfdp/tlv/FlowLabelTlv.cpp +++ b/src/fsfw/cfdp/tlv/FlowLabelTlv.cpp @@ -1,4 +1,4 @@ #include "FlowLabelTlv.h" FlowLabelTlv::FlowLabelTlv(uint8_t* value, size_t size) - : Tlv(cfdp::TlvTypes::FLOW_LABEL, value, size) {} + : Tlv(cfdp::TlvType::FLOW_LABEL, value, size) {} diff --git a/src/fsfw/cfdp/tlv/MessageToUserTlv.cpp b/src/fsfw/cfdp/tlv/MessageToUserTlv.cpp index c6bf3633..9a3e55ff 100644 --- a/src/fsfw/cfdp/tlv/MessageToUserTlv.cpp +++ b/src/fsfw/cfdp/tlv/MessageToUserTlv.cpp @@ -1,9 +1,9 @@ #include "MessageToUserTlv.h" MessageToUserTlv::MessageToUserTlv(uint8_t* value, size_t size) - : Tlv(cfdp::TlvTypes::MSG_TO_USER, value, size) {} + : Tlv(cfdp::TlvType::MSG_TO_USER, value, size) {} MessageToUserTlv::MessageToUserTlv() : Tlv() {} MessageToUserTlv::MessageToUserTlv(const std::vector& data) - : Tlv(cfdp::TlvTypes::MSG_TO_USER, data.data(), data.size()) {} + : Tlv(cfdp::TlvType::MSG_TO_USER, data.data(), data.size()) {} diff --git a/src/fsfw/cfdp/tlv/Tlv.cpp b/src/fsfw/cfdp/tlv/Tlv.cpp index 9d5f7f15..c3fce612 100644 --- a/src/fsfw/cfdp/tlv/Tlv.cpp +++ b/src/fsfw/cfdp/tlv/Tlv.cpp @@ -1,6 +1,6 @@ #include "Tlv.h" -cfdp::Tlv::Tlv(TlvTypes type, const uint8_t *value, size_t size) +cfdp::Tlv::Tlv(TlvType type, const uint8_t *value, size_t size) : type(type), value(value, size, true) { if (size > 0) { zeroLen = false; @@ -17,7 +17,7 @@ ReturnValue_t cfdp::Tlv::serialize(uint8_t **buffer, size_t *size, size_t maxSiz if (*size + 2 > maxSize) { return BUFFER_TOO_SHORT; } - if (type == TlvTypes::INVALID_TLV) { + if (type == TlvType::INVALID_TLV) { return INVALID_TLV_TYPE; } **buffer = type; @@ -59,7 +59,7 @@ ReturnValue_t cfdp::Tlv::deSerialize(const uint8_t **buffer, size_t *size, return INVALID_TLV_TYPE; } - type = static_cast(rawType); + type = static_cast(rawType); *buffer += 1; *size -= 1; @@ -83,7 +83,7 @@ ReturnValue_t cfdp::Tlv::deSerialize(const uint8_t **buffer, size_t *size, const uint8_t *cfdp::Tlv::getValue() const { return value.getConstBuffer(); } -cfdp::TlvTypes cfdp::Tlv::getType() const { return type; } +cfdp::TlvType cfdp::Tlv::getType() const { return type; } bool cfdp::Tlv::checkType(uint8_t rawType) { if (rawType != 0x03 and rawType <= 6) { @@ -101,4 +101,4 @@ void cfdp::Tlv::setValue(uint8_t *value, size_t len) { uint8_t cfdp::Tlv::getLengthField() const { return this->value.getSerializedSize() - 1; } -void cfdp::Tlv::setType(TlvTypes type) { this->type = type; } +void cfdp::Tlv::setType(TlvType type) { this->type = type; } diff --git a/src/fsfw/cfdp/tlv/Tlv.h b/src/fsfw/cfdp/tlv/Tlv.h index ef39f88b..786a3b79 100644 --- a/src/fsfw/cfdp/tlv/Tlv.h +++ b/src/fsfw/cfdp/tlv/Tlv.h @@ -13,7 +13,7 @@ namespace cfdp { */ class Tlv : public TlvIF { public: - Tlv(TlvTypes type, const uint8_t *value, size_t size); + Tlv(TlvType type, const uint8_t *value, size_t size); Tlv(); /** @@ -47,15 +47,15 @@ class Tlv : public TlvIF { void setValue(uint8_t *value, size_t len); [[nodiscard]] const uint8_t *getValue() const; - void setType(TlvTypes type); - [[nodiscard]] TlvTypes getType() const override; + void setType(TlvType type); + [[nodiscard]] TlvType getType() const override; [[nodiscard]] uint8_t getLengthField() const override; private: bool checkType(uint8_t rawType); bool zeroLen = true; - TlvTypes type = TlvTypes::INVALID_TLV; + TlvType type = TlvType::INVALID_TLV; SerialBufferAdapter value; }; diff --git a/src/fsfw/cfdp/tlv/TlvIF.h b/src/fsfw/cfdp/tlv/TlvIF.h index 9a02b241..317d970a 100644 --- a/src/fsfw/cfdp/tlv/TlvIF.h +++ b/src/fsfw/cfdp/tlv/TlvIF.h @@ -8,7 +8,7 @@ class TlvIF : public SerializeIF { virtual ~TlvIF(){}; virtual uint8_t getLengthField() const = 0; - virtual cfdp::TlvTypes getType() const = 0; + virtual cfdp::TlvType getType() const = 0; }; #endif /* FSFW_SRC_FSFW_CFDP_TLVIF_H_ */ diff --git a/unittests/cfdp/handler/testDistributor.cpp b/unittests/cfdp/handler/testDistributor.cpp index f33e1115..8b6c46af 100644 --- a/unittests/cfdp/handler/testDistributor.cpp +++ b/unittests/cfdp/handler/testDistributor.cpp @@ -25,12 +25,12 @@ TEST_CASE("CFDP Distributor", "[cfdp][distributor]") { const cfdp::EntityId& sourceId(groundEntityId); const cfdp::EntityId& destId(obswEntityId); cfdp::TransactionSeqNum seqNum(UnsignedByteField(12)); - auto pduConf = PduConfig(sourceId, destId, cfdp::TransmissionModes::UNACKNOWLEDGED, seqNum); + auto pduConf = PduConfig(sourceId, destId, cfdp::TransmissionMode::UNACKNOWLEDGED, seqNum); std::string sourceFileString = "hello.txt"; cfdp::StringLv sourceFileName(sourceFileString); std::string destFileString = "hello2.txt"; cfdp::StringLv destFileName(destFileString); - MetadataInfo metadataInfo(false, cfdp::ChecksumTypes::CRC_32, fileSize, sourceFileName, + MetadataInfo metadataInfo(false, cfdp::ChecksumType::CRC_32, fileSize, sourceFileName, destFileName); MetadataPduCreator creator(pduConf, metadataInfo); uint8_t* dataPtr = nullptr; diff --git a/unittests/cfdp/handler/testFaultHandler.cpp b/unittests/cfdp/handler/testFaultHandler.cpp index 559744d7..5da9a70d 100644 --- a/unittests/cfdp/handler/testFaultHandler.cpp +++ b/unittests/cfdp/handler/testFaultHandler.cpp @@ -5,80 +5,81 @@ TEST_CASE("CFDP Fault Handler", "[cfdp]") { using namespace cfdp; auto fhMock = FaultHandlerMock(); - cfdp::FaultHandlerCodes fhCode; + cfdp::FaultHandlerCode fhCode; + cfdp::TransactionId id; SECTION("State") { // Verify initial condition CHECK(fhMock.getFaultHandler(ConditionCode::UNSUPPORTED_CHECKSUM_TYPE, fhCode)); - CHECK(fhCode == FaultHandlerCodes::IGNORE_ERROR); + CHECK(fhCode == FaultHandlerCode::IGNORE_ERROR); CHECK(fhMock.getFaultHandler(ConditionCode::POSITIVE_ACK_LIMIT_REACHED, fhCode)); - CHECK(fhCode == FaultHandlerCodes::IGNORE_ERROR); + CHECK(fhCode == FaultHandlerCode::IGNORE_ERROR); CHECK(fhMock.getFaultHandler(ConditionCode::KEEP_ALIVE_LIMIT_REACHED, fhCode)); - CHECK(fhCode == FaultHandlerCodes::IGNORE_ERROR); + CHECK(fhCode == FaultHandlerCode::IGNORE_ERROR); CHECK(fhMock.getFaultHandler(ConditionCode::INVALID_TRANSMISSION_MODE, fhCode)); - CHECK(fhCode == FaultHandlerCodes::IGNORE_ERROR); + CHECK(fhCode == FaultHandlerCode::IGNORE_ERROR); CHECK(fhMock.getFaultHandler(ConditionCode::FILESTORE_REJECTION, fhCode)); - CHECK(fhCode == FaultHandlerCodes::IGNORE_ERROR); + CHECK(fhCode == FaultHandlerCode::IGNORE_ERROR); CHECK(fhMock.getFaultHandler(ConditionCode::FILE_CHECKSUM_FAILURE, fhCode)); - CHECK(fhCode == FaultHandlerCodes::IGNORE_ERROR); + CHECK(fhCode == FaultHandlerCode::IGNORE_ERROR); CHECK(fhMock.getFaultHandler(ConditionCode::FILE_SIZE_ERROR, fhCode)); - CHECK(fhCode == FaultHandlerCodes::IGNORE_ERROR); + CHECK(fhCode == FaultHandlerCode::IGNORE_ERROR); CHECK(fhMock.getFaultHandler(ConditionCode::NAK_LIMIT_REACHED, fhCode)); - CHECK(fhCode == FaultHandlerCodes::IGNORE_ERROR); + CHECK(fhCode == FaultHandlerCode::IGNORE_ERROR); CHECK(fhMock.getFaultHandler(ConditionCode::INACTIVITY_DETECTED, fhCode)); - CHECK(fhCode == FaultHandlerCodes::IGNORE_ERROR); + CHECK(fhCode == FaultHandlerCode::IGNORE_ERROR); CHECK(fhMock.getFaultHandler(ConditionCode::CHECK_LIMIT_REACHED, fhCode)); - CHECK(fhCode == FaultHandlerCodes::IGNORE_ERROR); + CHECK(fhCode == FaultHandlerCode::IGNORE_ERROR); } SECTION("Call Handler, Ignore Fault") { - auto& info = fhMock.getFhInfo(FaultHandlerCodes::IGNORE_ERROR); - CHECK(fhMock.reportFault(ConditionCode::CHECK_LIMIT_REACHED)); + auto& info = fhMock.getFhInfo(FaultHandlerCode::IGNORE_ERROR); + CHECK(fhMock.reportFault(id, ConditionCode::CHECK_LIMIT_REACHED)); CHECK(info.callCount == 1); CHECK(info.condCodes.back() == ConditionCode::CHECK_LIMIT_REACHED); - fhMock.reportFault(ConditionCode::FILE_CHECKSUM_FAILURE); + fhMock.reportFault(id, ConditionCode::FILE_CHECKSUM_FAILURE); CHECK(info.callCount == 2); CHECK(info.condCodes.back() == ConditionCode::FILE_CHECKSUM_FAILURE); } - SECTION("Invalid Reported Code") { CHECK(not fhMock.reportFault(ConditionCode::NO_ERROR)); } + SECTION("Invalid Reported Code") { CHECK(not fhMock.reportFault(id, ConditionCode::NO_ERROR)); } SECTION("Invalid FH code") { CHECK(not fhMock.setFaultHandler(ConditionCode::KEEP_ALIVE_LIMIT_REACHED, - FaultHandlerCodes::RESERVED)); + FaultHandlerCode::RESERVED)); CHECK(fhMock.getFaultHandler(ConditionCode::KEEP_ALIVE_LIMIT_REACHED, fhCode)); - CHECK(fhCode == FaultHandlerCodes::IGNORE_ERROR); - CHECK(not fhMock.setFaultHandler(ConditionCode::NO_ERROR, FaultHandlerCodes::IGNORE_ERROR)); + CHECK(fhCode == FaultHandlerCode::IGNORE_ERROR); + CHECK(not fhMock.setFaultHandler(ConditionCode::NO_ERROR, FaultHandlerCode::IGNORE_ERROR)); CHECK(not fhMock.getFaultHandler(ConditionCode::NO_ERROR, fhCode)); } SECTION("Set Other Fault Handler") { CHECK(fhMock.setFaultHandler(ConditionCode::FILE_CHECKSUM_FAILURE, - FaultHandlerCodes::NOTICE_OF_CANCELLATION)); + FaultHandlerCode::NOTICE_OF_CANCELLATION)); CHECK(fhMock.setFaultHandler(ConditionCode::INACTIVITY_DETECTED, - FaultHandlerCodes::ABANDON_TRANSACTION)); + FaultHandlerCode::ABANDON_TRANSACTION)); CHECK(fhMock.setFaultHandler(ConditionCode::KEEP_ALIVE_LIMIT_REACHED, - FaultHandlerCodes::NOTICE_OF_SUSPENSION)); - auto& ignoreInfo = fhMock.getFhInfo(FaultHandlerCodes::IGNORE_ERROR); - auto& cancellationInfo = fhMock.getFhInfo(FaultHandlerCodes::NOTICE_OF_CANCELLATION); - auto& suspensionInfo = fhMock.getFhInfo(FaultHandlerCodes::NOTICE_OF_SUSPENSION); - auto& abandonInfo = fhMock.getFhInfo(FaultHandlerCodes::ABANDON_TRANSACTION); + FaultHandlerCode::NOTICE_OF_SUSPENSION)); + auto& ignoreInfo = fhMock.getFhInfo(FaultHandlerCode::IGNORE_ERROR); + auto& cancellationInfo = fhMock.getFhInfo(FaultHandlerCode::NOTICE_OF_CANCELLATION); + auto& suspensionInfo = fhMock.getFhInfo(FaultHandlerCode::NOTICE_OF_SUSPENSION); + auto& abandonInfo = fhMock.getFhInfo(FaultHandlerCode::ABANDON_TRANSACTION); - CHECK(fhMock.reportFault(ConditionCode::FILE_CHECKSUM_FAILURE)); + CHECK(fhMock.reportFault(id, ConditionCode::FILE_CHECKSUM_FAILURE)); CHECK(cancellationInfo.callCount == 1); CHECK(cancellationInfo.condCodes.back() == ConditionCode::FILE_CHECKSUM_FAILURE); CHECK(ignoreInfo.callCount == 0); CHECK(suspensionInfo.callCount == 0); CHECK(abandonInfo.callCount == 0); - CHECK(fhMock.reportFault(ConditionCode::INACTIVITY_DETECTED)); + CHECK(fhMock.reportFault(id, ConditionCode::INACTIVITY_DETECTED)); CHECK(cancellationInfo.callCount == 1); CHECK(ignoreInfo.callCount == 0); CHECK(suspensionInfo.callCount == 0); CHECK(abandonInfo.callCount == 1); CHECK(abandonInfo.condCodes.back() == ConditionCode::INACTIVITY_DETECTED); - CHECK(fhMock.reportFault(ConditionCode::KEEP_ALIVE_LIMIT_REACHED)); + CHECK(fhMock.reportFault(id, ConditionCode::KEEP_ALIVE_LIMIT_REACHED)); CHECK(cancellationInfo.callCount == 1); CHECK(ignoreInfo.callCount == 0); CHECK(suspensionInfo.callCount == 1); diff --git a/unittests/cfdp/pdu/testAckPdu.cpp b/unittests/cfdp/pdu/testAckPdu.cpp index 44b66bd5..10b264ec 100644 --- a/unittests/cfdp/pdu/testAckPdu.cpp +++ b/unittests/cfdp/pdu/testAckPdu.cpp @@ -15,19 +15,19 @@ TEST_CASE("ACK PDU", "[cfdp][pdu]") { auto seqNum = TransactionSeqNum(WidthInBytes::TWO_BYTES, 15); auto sourceId = EntityId(WidthInBytes::TWO_BYTES, 1); auto destId = EntityId(WidthInBytes::TWO_BYTES, 2); - auto pduConf = PduConfig(sourceId, destId, TransmissionModes::ACKNOWLEDGED, seqNum); - AckInfo ackInfo(FileDirectives::EOF_DIRECTIVE, ConditionCode::NO_ERROR, + auto pduConf = PduConfig(sourceId, destId, TransmissionMode::ACKNOWLEDGED, seqNum); + AckInfo ackInfo(FileDirective::EOF_DIRECTIVE, ConditionCode::NO_ERROR, AckTransactionStatus::ACTIVE); auto ackSerializer = AckPduCreator(ackInfo, pduConf); result = ackSerializer.serialize(&bufptr, &sz, maxsz, SerializeIF::Endianness::NETWORK); REQUIRE(result == returnvalue::OK); SECTION("Serialize") { - REQUIRE(buf[sz - 3] == cfdp::FileDirectives::ACK); - REQUIRE((buf[sz - 2] >> 4) == FileDirectives::EOF_DIRECTIVE); + REQUIRE(buf[sz - 3] == cfdp::FileDirective::ACK); + REQUIRE((buf[sz - 2] >> 4) == FileDirective::EOF_DIRECTIVE); REQUIRE((buf[sz - 2] & 0x0f) == 0); REQUIRE(buf[sz - 1] == AckTransactionStatus::ACTIVE); - ackInfo.setAckedDirective(FileDirectives::FINISH); + ackInfo.setAckedDirective(FileDirective::FINISH); ackInfo.setAckedConditionCode(ConditionCode::FILESTORE_REJECTION); ackInfo.setTransactionStatus(AckTransactionStatus::TERMINATED); auto ackSerializer2 = AckPduCreator(ackInfo, pduConf); @@ -35,21 +35,21 @@ TEST_CASE("ACK PDU", "[cfdp][pdu]") { sz = 0; result = ackSerializer2.serialize(&bufptr, &sz, maxsz, SerializeIF::Endianness::NETWORK); REQUIRE(result == returnvalue::OK); - REQUIRE(buf[sz - 3] == cfdp::FileDirectives::ACK); - REQUIRE((buf[sz - 2] >> 4) == FileDirectives::FINISH); + REQUIRE(buf[sz - 3] == cfdp::FileDirective::ACK); + REQUIRE((buf[sz - 2] >> 4) == FileDirective::FINISH); REQUIRE((buf[sz - 2] & 0x0f) == 0b0001); REQUIRE((buf[sz - 1] >> 4) == ConditionCode::FILESTORE_REJECTION); REQUIRE((buf[sz - 1] & 0b11) == AckTransactionStatus::TERMINATED); bufptr = buf.data(); sz = 0; - ackInfo.setAckedDirective(FileDirectives::KEEP_ALIVE); + ackInfo.setAckedDirective(FileDirective::KEEP_ALIVE); auto ackSerializer3 = AckPduCreator(ackInfo, pduConf); result = ackSerializer3.serialize(&bufptr, &sz, maxsz, SerializeIF::Endianness::NETWORK); // Invalid file directive REQUIRE(result != returnvalue::OK); - ackInfo.setAckedDirective(FileDirectives::FINISH); + ackInfo.setAckedDirective(FileDirective::FINISH); // buffer too small result = ackSerializer.serialize(&bufptr, &sz, 8, SerializeIF::Endianness::NETWORK); REQUIRE(result == SerializeIF::BUFFER_TOO_SHORT); @@ -60,12 +60,12 @@ TEST_CASE("ACK PDU", "[cfdp][pdu]") { auto reader = AckPduReader(buf.data(), sz, ackInfo2); result = reader.parseData(); REQUIRE(result == returnvalue::OK); - REQUIRE(ackInfo2.getAckedDirective() == FileDirectives::EOF_DIRECTIVE); + REQUIRE(ackInfo2.getAckedDirective() == FileDirective::EOF_DIRECTIVE); REQUIRE(ackInfo2.getAckedConditionCode() == ConditionCode::NO_ERROR); REQUIRE(ackInfo2.getDirectiveSubtypeCode() == 0); REQUIRE(ackInfo2.getTransactionStatus() == AckTransactionStatus::ACTIVE); - AckInfo newInfo = AckInfo(FileDirectives::FINISH, ConditionCode::FILESTORE_REJECTION, + AckInfo newInfo = AckInfo(FileDirective::FINISH, ConditionCode::FILESTORE_REJECTION, AckTransactionStatus::TERMINATED); auto ackSerializer2 = AckPduCreator(newInfo, pduConf); bufptr = buf.data(); @@ -76,23 +76,23 @@ TEST_CASE("ACK PDU", "[cfdp][pdu]") { auto reader2 = AckPduReader(buf.data(), sz, ackInfo2); result = reader2.parseData(); REQUIRE(result == returnvalue::OK); - REQUIRE(ackInfo2.getAckedDirective() == FileDirectives::FINISH); + REQUIRE(ackInfo2.getAckedDirective() == FileDirective::FINISH); REQUIRE(ackInfo2.getAckedConditionCode() == ConditionCode::FILESTORE_REJECTION); REQUIRE(ackInfo2.getDirectiveSubtypeCode() == 0b0001); REQUIRE(ackInfo2.getTransactionStatus() == AckTransactionStatus::TERMINATED); uint8_t prevVal = buf[sz - 2]; - buf[sz - 2] = FileDirectives::INVALID_DIRECTIVE << 4; + buf[sz - 2] = FileDirective::INVALID_DIRECTIVE << 4; result = reader2.parseData(); REQUIRE(result == cfdp::INVALID_ACK_DIRECTIVE_FIELDS); - buf[sz - 2] = FileDirectives::FINISH << 4 | 0b1111; + buf[sz - 2] = FileDirective::FINISH << 4 | 0b1111; result = reader2.parseData(); REQUIRE(result == cfdp::INVALID_ACK_DIRECTIVE_FIELDS); buf[sz - 2] = prevVal; - buf[sz - 3] = cfdp::FileDirectives::INVALID_DIRECTIVE; + buf[sz - 3] = cfdp::FileDirective::INVALID_DIRECTIVE; result = reader2.parseData(); REQUIRE(result == cfdp::INVALID_DIRECTIVE_FIELD); - buf[sz - 3] = cfdp::FileDirectives::ACK; + buf[sz - 3] = cfdp::FileDirective::ACK; auto maxSizeTooSmall = AckPduReader(buf.data(), sz - 2, ackInfo2); result = maxSizeTooSmall.parseData(); REQUIRE(result == SerializeIF::STREAM_TOO_SHORT); diff --git a/unittests/cfdp/pdu/testCfdpHeader.cpp b/unittests/cfdp/pdu/testCfdpHeader.cpp index b51450ec..5f81bec9 100644 --- a/unittests/cfdp/pdu/testCfdpHeader.cpp +++ b/unittests/cfdp/pdu/testCfdpHeader.cpp @@ -17,11 +17,11 @@ TEST_CASE("CFDP Header", "[cfdp]") { cfdp::EntityId sourceId = EntityId(cfdp::WidthInBytes::ONE_BYTE, 0); cfdp::EntityId destId = EntityId(cfdp::WidthInBytes::ONE_BYTE, 1); PduConfig pduConf = - PduConfig(sourceId, destId, cfdp::TransmissionModes::ACKNOWLEDGED, seqNum, false); + PduConfig(sourceId, destId, cfdp::TransmissionMode::ACKNOWLEDGED, seqNum, false); uint8_t* serTarget = serBuf.data(); const uint8_t* deserTarget = serTarget; size_t serSize = 0; - auto creator = HeaderCreator(pduConf, cfdp::PduTypes::FILE_DIRECTIVE, 0); + auto creator = HeaderCreator(pduConf, cfdp::PduType::FILE_DIRECTIVE, 0); SECTION("Header State") { REQUIRE(seqNum.getSerializedSize() == 1); @@ -33,10 +33,10 @@ TEST_CASE("CFDP Header", "[cfdp]") { REQUIRE(creator.getLargeFileFlag() == false); REQUIRE(creator.getLenEntityIds() == 1); REQUIRE(creator.getLenSeqNum() == 1); - REQUIRE(creator.getPduType() == cfdp::PduTypes::FILE_DIRECTIVE); + REQUIRE(creator.getPduType() == cfdp::PduType::FILE_DIRECTIVE); REQUIRE(creator.getSegmentMetadataFlag() == cfdp::SegmentMetadataFlag::NOT_PRESENT); REQUIRE(creator.getSegmentationControl() == false); - REQUIRE(creator.getTransmissionMode() == cfdp::TransmissionModes::ACKNOWLEDGED); + REQUIRE(creator.getTransmissionMode() == cfdp::TransmissionMode::ACKNOWLEDGED); cfdp::TransactionSeqNum seqNumLocal; creator.getTransactionSeqNum(seqNumLocal); REQUIRE(seqNumLocal.getWidth() == cfdp::WidthInBytes::ONE_BYTE); @@ -85,9 +85,9 @@ TEST_CASE("CFDP Header", "[cfdp]") { pduConf.crcFlag = true; pduConf.largeFile = true; pduConf.direction = cfdp::Direction::TOWARDS_SENDER; - pduConf.mode = cfdp::TransmissionModes::UNACKNOWLEDGED; + pduConf.mode = cfdp::TransmissionMode::UNACKNOWLEDGED; creator.setSegmentationControl(cfdp::SegmentationControl::RECORD_BOUNDARIES_PRESERVATION); - creator.setPduType(cfdp::PduTypes::FILE_DATA); + creator.setPduType(cfdp::PduType::FILE_DATA); creator.setSegmentMetadataFlag(cfdp::SegmentMetadataFlag::PRESENT); serTarget = serBuf.data(); serSize = 0; @@ -103,9 +103,9 @@ TEST_CASE("CFDP Header", "[cfdp]") { REQUIRE(creator.getLargeFileFlag() == true); REQUIRE(creator.getLenEntityIds() == 1); REQUIRE(creator.getLenSeqNum() == 1); - REQUIRE(creator.getPduType() == cfdp::PduTypes::FILE_DATA); + REQUIRE(creator.getPduType() == cfdp::PduType::FILE_DATA); REQUIRE(creator.getSegmentMetadataFlag() == cfdp::SegmentMetadataFlag::PRESENT); - REQUIRE(creator.getTransmissionMode() == cfdp::TransmissionModes::UNACKNOWLEDGED); + REQUIRE(creator.getTransmissionMode() == cfdp::TransmissionMode::UNACKNOWLEDGED); REQUIRE(creator.getSegmentationControl() == true); } @@ -122,9 +122,9 @@ TEST_CASE("CFDP Header", "[cfdp]") { REQUIRE(creator.getLargeFileFlag() == true); REQUIRE(creator.getLenEntityIds() == 4); REQUIRE(creator.getLenSeqNum() == 2); - REQUIRE(creator.getPduType() == cfdp::PduTypes::FILE_DATA); + REQUIRE(creator.getPduType() == cfdp::PduType::FILE_DATA); REQUIRE(creator.getSegmentMetadataFlag() == cfdp::SegmentMetadataFlag::PRESENT); - REQUIRE(creator.getTransmissionMode() == cfdp::TransmissionModes::UNACKNOWLEDGED); + REQUIRE(creator.getTransmissionMode() == cfdp::TransmissionMode::UNACKNOWLEDGED); REQUIRE(creator.getSegmentationControl() == true); // Last three bits are 2 now (length of seq number) and bit 1 to bit 3 is 4 (len entity IDs) REQUIRE(serBuf[3] == 0b11001010); @@ -235,10 +235,10 @@ TEST_CASE("CFDP Header", "[cfdp]") { REQUIRE(reader.getLargeFileFlag() == false); REQUIRE(reader.getLenEntityIds() == 1); REQUIRE(reader.getLenSeqNum() == 1); - REQUIRE(reader.getPduType() == cfdp::PduTypes::FILE_DIRECTIVE); + REQUIRE(reader.getPduType() == cfdp::PduType::FILE_DIRECTIVE); REQUIRE(reader.getSegmentMetadataFlag() == cfdp::SegmentMetadataFlag::NOT_PRESENT); REQUIRE(reader.getSegmentationControl() == false); - REQUIRE(reader.getTransmissionMode() == cfdp::TransmissionModes::ACKNOWLEDGED); + REQUIRE(reader.getTransmissionMode() == cfdp::TransmissionMode::ACKNOWLEDGED); // No PDU data contained, so the PDU data field is empty REQUIRE(reader.getPduDataField() == nullptr); @@ -253,9 +253,9 @@ TEST_CASE("CFDP Header", "[cfdp]") { pduConf.crcFlag = true; pduConf.largeFile = true; pduConf.direction = cfdp::Direction::TOWARDS_SENDER; - pduConf.mode = cfdp::TransmissionModes::UNACKNOWLEDGED; + pduConf.mode = cfdp::TransmissionMode::UNACKNOWLEDGED; creator.setSegmentationControl(cfdp::SegmentationControl::RECORD_BOUNDARIES_PRESERVATION); - creator.setPduType(cfdp::PduTypes::FILE_DATA); + creator.setPduType(cfdp::PduType::FILE_DATA); creator.setSegmentMetadataFlag(cfdp::SegmentMetadataFlag::PRESENT); result = pduConf.seqNum.setValue(cfdp::WidthInBytes::TWO_BYTES, 0x0fff); REQUIRE(result == returnvalue::OK); @@ -278,10 +278,10 @@ TEST_CASE("CFDP Header", "[cfdp]") { REQUIRE(reader.getLargeFileFlag() == true); REQUIRE(reader.getLenEntityIds() == 4); REQUIRE(reader.getLenSeqNum() == 2); - REQUIRE(reader.getPduType() == cfdp::PduTypes::FILE_DATA); + REQUIRE(reader.getPduType() == cfdp::PduType::FILE_DATA); REQUIRE(reader.getSegmentMetadataFlag() == cfdp::SegmentMetadataFlag::PRESENT); REQUIRE(reader.getSegmentationControl() == true); - REQUIRE(reader.getTransmissionMode() == cfdp::TransmissionModes::UNACKNOWLEDGED); + REQUIRE(reader.getTransmissionMode() == cfdp::TransmissionMode::UNACKNOWLEDGED); // Again, no data field set because this is a header only REQUIRE(reader.getPduDataField() == nullptr); diff --git a/unittests/cfdp/pdu/testEofPdu.cpp b/unittests/cfdp/pdu/testEofPdu.cpp index c6718e20..83e61780 100644 --- a/unittests/cfdp/pdu/testEofPdu.cpp +++ b/unittests/cfdp/pdu/testEofPdu.cpp @@ -20,7 +20,7 @@ TEST_CASE("EOF PDU", "[cfdp][pdu]") { TransactionSeqNum seqNum(WidthInBytes::TWO_BYTES, 15); EntityId sourceId(WidthInBytes::TWO_BYTES, 1); - PduConfig pduConf(sourceId, destId, TransmissionModes::ACKNOWLEDGED, seqNum); + PduConfig pduConf(sourceId, destId, TransmissionMode::ACKNOWLEDGED, seqNum); auto eofSerializer = EofPduCreator(pduConf, eofInfo); SECTION("Serialize") { @@ -37,7 +37,7 @@ TEST_CASE("EOF PDU", "[cfdp][pdu]") { SerializeIF::Endianness::NETWORK); REQUIRE(result == returnvalue::OK); REQUIRE(fileSizeVal == 12); - REQUIRE(buf[sz - 10] == cfdp::FileDirectives::EOF_DIRECTIVE); + REQUIRE(buf[sz - 10] == cfdp::FileDirective::EOF_DIRECTIVE); REQUIRE(buf[sz - 9] == 0x00); REQUIRE(sz == 20); @@ -52,13 +52,13 @@ TEST_CASE("EOF PDU", "[cfdp][pdu]") { SerializeIF::Endianness::NETWORK); REQUIRE(result == returnvalue::OK); REQUIRE(sz == 28); - REQUIRE(buf[10] == cfdp::FileDirectives::EOF_DIRECTIVE); + REQUIRE(buf[10] == cfdp::FileDirective::EOF_DIRECTIVE); REQUIRE(buf[11] >> 4 == cfdp::ConditionCode::FILESTORE_REJECTION); uint64_t fileSizeLarge = 0; result = SerializeAdapter::deSerialize(&fileSizeLarge, buf.data() + 16, nullptr, SerializeIF::Endianness::NETWORK); REQUIRE(fileSizeLarge == 0x10ffffff10); - REQUIRE(buf[sz - 4] == cfdp::TlvTypes::ENTITY_ID); + REQUIRE(buf[sz - 4] == cfdp::TlvType::ENTITY_ID); // width of entity ID is 2 REQUIRE(buf[sz - 3] == 2); uint16_t entityIdRaw = 0; @@ -105,7 +105,7 @@ TEST_CASE("EOF PDU", "[cfdp][pdu]") { REQUIRE(emptyInfo.getConditionCode() == cfdp::ConditionCode::FILESTORE_REJECTION); REQUIRE(emptyInfo.getChecksum() == 5); REQUIRE(emptyInfo.getFileSize().getSize() == 0x10ffffff10); - REQUIRE(emptyInfo.getFaultLoc()->getType() == cfdp::TlvTypes::ENTITY_ID); + REQUIRE(emptyInfo.getFaultLoc()->getType() == cfdp::TlvType::ENTITY_ID); REQUIRE(emptyInfo.getFaultLoc()->getSerializedSize() == 4); uint16_t destId = emptyInfo.getFaultLoc()->getEntityId().getValue(); REQUIRE(destId == 2); diff --git a/unittests/cfdp/pdu/testFileData.cpp b/unittests/cfdp/pdu/testFileData.cpp index 8dfd7db3..258ef9c1 100644 --- a/unittests/cfdp/pdu/testFileData.cpp +++ b/unittests/cfdp/pdu/testFileData.cpp @@ -17,7 +17,7 @@ TEST_CASE("File Data PDU", "[cfdp][pdu]") { EntityId destId(WidthInBytes::TWO_BYTES, 2); TransactionSeqNum seqNum(WidthInBytes::TWO_BYTES, 15); EntityId sourceId(WidthInBytes::TWO_BYTES, 1); - PduConfig pduConf(sourceId, destId, TransmissionModes::ACKNOWLEDGED, seqNum); + PduConfig pduConf(sourceId, destId, TransmissionMode::ACKNOWLEDGED, seqNum); for (uint8_t idx = 0; idx < 10; idx++) { fileBuffer[idx] = idx; diff --git a/unittests/cfdp/pdu/testFileDirective.cpp b/unittests/cfdp/pdu/testFileDirective.cpp index 31e627a6..e1158a1a 100644 --- a/unittests/cfdp/pdu/testFileDirective.cpp +++ b/unittests/cfdp/pdu/testFileDirective.cpp @@ -12,11 +12,11 @@ TEST_CASE("CFDP File Directive", "[cfdp][pdu]") { cfdp::EntityId sourceId = EntityId(cfdp::WidthInBytes::ONE_BYTE, 0); cfdp::EntityId destId = EntityId(cfdp::WidthInBytes::ONE_BYTE, 1); PduConfig pduConf = - PduConfig(sourceId, destId, cfdp::TransmissionModes::ACKNOWLEDGED, seqNum, false); + PduConfig(sourceId, destId, cfdp::TransmissionMode::ACKNOWLEDGED, seqNum, false); uint8_t* serTarget = serBuf.data(); const uint8_t* deserTarget = serTarget; size_t serSize = 0; - auto fdSer = FileDirectiveCreator(pduConf, FileDirectives::ACK, 4); + auto fdSer = FileDirectiveCreator(pduConf, FileDirective::ACK, 4); SECTION("Serialization") { REQUIRE(fdSer.getSerializedSize() == 8); @@ -37,7 +37,7 @@ TEST_CASE("CFDP File Directive", "[cfdp][pdu]") { REQUIRE(serBuf[5] == 2); // Dest ID REQUIRE(serBuf[6] == 1); - REQUIRE(serBuf[7] == FileDirectives::ACK); + REQUIRE(serBuf[7] == FileDirective::ACK); } SECTION("Serialization fails") { @@ -73,10 +73,10 @@ TEST_CASE("CFDP File Directive", "[cfdp][pdu]") { REQUIRE(fdDeser.parseData() == returnvalue::OK); REQUIRE(not fdDeser.isNull()); REQUIRE(fdDeser); - REQUIRE(fdDeser.getFileDirective() == FileDirectives::ACK); + REQUIRE(fdDeser.getFileDirective() == FileDirective::ACK); REQUIRE(fdDeser.getPduDataFieldLen() == 5); REQUIRE(fdDeser.getHeaderSize() == 8); - REQUIRE(fdDeser.getPduType() == cfdp::PduTypes::FILE_DIRECTIVE); + REQUIRE(fdDeser.getPduType() == cfdp::PduType::FILE_DIRECTIVE); serBuf[7] = 0xff; // Invalid file directive diff --git a/unittests/cfdp/pdu/testFinishedPdu.cpp b/unittests/cfdp/pdu/testFinishedPdu.cpp index 194e4252..b8b395cb 100644 --- a/unittests/cfdp/pdu/testFinishedPdu.cpp +++ b/unittests/cfdp/pdu/testFinishedPdu.cpp @@ -14,7 +14,7 @@ TEST_CASE("Finished PDU", "[cfdp][pdu]") { EntityId destId(WidthInBytes::TWO_BYTES, 2); TransactionSeqNum seqNum(WidthInBytes::TWO_BYTES, 15); EntityId sourceId(WidthInBytes::TWO_BYTES, 1); - PduConfig pduConf(sourceId, destId, TransmissionModes::ACKNOWLEDGED, seqNum); + PduConfig pduConf(sourceId, destId, TransmissionMode::ACKNOWLEDGED, seqNum); cfdp::Lv emptyFsMsg; FinishedInfo info(cfdp::ConditionCode::INACTIVITY_DETECTED, @@ -27,7 +27,7 @@ TEST_CASE("Finished PDU", "[cfdp][pdu]") { REQUIRE(result == returnvalue::OK); REQUIRE(serializer.getSerializedSize() == 12); REQUIRE(((fnBuffer[1] << 8) | fnBuffer[2]) == 2); - REQUIRE(fnBuffer[10] == cfdp::FileDirectives::FINISH); + REQUIRE(fnBuffer[10] == cfdp::FileDirective::FINISH); REQUIRE(((fnBuffer[sz - 1] >> 4) & 0x0f) == cfdp::ConditionCode::INACTIVITY_DETECTED); REQUIRE(((fnBuffer[sz - 1] >> 2) & 0x01) == cfdp::FileDeliveryCode::DATA_INCOMPLETE); REQUIRE((fnBuffer[sz - 1] & 0b11) == cfdp::FileDeliveryStatus::DISCARDED_DELIBERATELY); @@ -176,7 +176,7 @@ TEST_CASE("Finished PDU", "[cfdp][pdu]") { fnBuffer[11] = tmp; // Invalid TLV type, should be entity ID - fnBuffer[sz - 4] = cfdp::TlvTypes::FILESTORE_REQUEST; + fnBuffer[sz - 4] = cfdp::TlvType::FILESTORE_REQUEST; result = deserializer3.parseData(); REQUIRE(result == cfdp::INVALID_TLV_TYPE); diff --git a/unittests/cfdp/pdu/testKeepAlivePdu.cpp b/unittests/cfdp/pdu/testKeepAlivePdu.cpp index 9b0e9669..d07bccae 100644 --- a/unittests/cfdp/pdu/testKeepAlivePdu.cpp +++ b/unittests/cfdp/pdu/testKeepAlivePdu.cpp @@ -14,7 +14,7 @@ TEST_CASE("Keep Alive PDU", "[cfdp][pdu]") { EntityId destId(WidthInBytes::TWO_BYTES, 2); TransactionSeqNum seqNum(WidthInBytes::TWO_BYTES, 15); EntityId sourceId(WidthInBytes::TWO_BYTES, 1); - PduConfig pduConf(sourceId, destId, TransmissionModes::ACKNOWLEDGED, seqNum); + PduConfig pduConf(sourceId, destId, TransmissionMode::ACKNOWLEDGED, seqNum); FileSize progress(0x50); @@ -22,7 +22,7 @@ TEST_CASE("Keep Alive PDU", "[cfdp][pdu]") { KeepAlivePduCreator serializer(pduConf, progress); result = serializer.serialize(&buffer, &sz, kaBuffer.size(), SerializeIF::Endianness::NETWORK); REQUIRE(result == returnvalue::OK); - REQUIRE(kaBuffer[10] == cfdp::FileDirectives::KEEP_ALIVE); + REQUIRE(kaBuffer[10] == cfdp::FileDirective::KEEP_ALIVE); uint32_t fsRaw = 0; result = SerializeAdapter::deSerialize(&fsRaw, kaBuffer.data() + 11, nullptr, SerializeIF::Endianness::NETWORK); diff --git a/unittests/cfdp/pdu/testMetadataPdu.cpp b/unittests/cfdp/pdu/testMetadataPdu.cpp index 18b60409..a9f8bf86 100644 --- a/unittests/cfdp/pdu/testMetadataPdu.cpp +++ b/unittests/cfdp/pdu/testMetadataPdu.cpp @@ -17,13 +17,13 @@ TEST_CASE("Metadata PDU", "[cfdp][pdu]") { EntityId destId(WidthInBytes::TWO_BYTES, 2); TransactionSeqNum seqNum(WidthInBytes::TWO_BYTES, 15); EntityId sourceId(WidthInBytes::TWO_BYTES, 1); - PduConfig pduConf(sourceId, destId, TransmissionModes::ACKNOWLEDGED, seqNum); + PduConfig pduConf(sourceId, destId, TransmissionMode::ACKNOWLEDGED, seqNum); std::string firstFileName = "hello.txt"; cfdp::StringLv sourceFileName(firstFileName); cfdp::StringLv destFileName; FileSize fileSize(35); - MetadataInfo info(false, ChecksumTypes::MODULAR, fileSize, sourceFileName, destFileName); + MetadataInfo info(false, ChecksumType::MODULAR, fileSize, sourceFileName, destFileName); FilestoreResponseTlv response(FilestoreActionCode::CREATE_DIRECTORY, FSR_CREATE_NOT_ALLOWED, sourceFileName, nullptr); @@ -46,7 +46,7 @@ TEST_CASE("Metadata PDU", "[cfdp][pdu]") { REQUIRE(info.getDestFileName().getSerializedSize() == 1); REQUIRE(info.getSerializedSize() == 16); REQUIRE((mdBuffer[1] << 8 | mdBuffer[2]) == 17); - REQUIRE(mdBuffer[10] == FileDirectives::METADATA); + REQUIRE(mdBuffer[10] == FileDirective::METADATA); // no closure requested and checksum type is modular => 0x00 REQUIRE(mdBuffer[11] == 0x00); uint32_t fileSizeRaw = 0; @@ -74,7 +74,7 @@ TEST_CASE("Metadata PDU", "[cfdp][pdu]") { REQUIRE(info.getMaxOptionsLen() == 2); info.setMaxOptionsLen(3); REQUIRE(info.getMaxOptionsLen() == 3); - info.setChecksumType(cfdp::ChecksumTypes::CRC_32C); + info.setChecksumType(cfdp::ChecksumType::CRC_32C); info.setClosureRequested(true); uint8_t* buffer = mdBuffer.data(); size_t sz = 0; @@ -83,8 +83,8 @@ TEST_CASE("Metadata PDU", "[cfdp][pdu]") { result = serializer.serialize(&buffer, &sz, mdBuffer.size(), SerializeIF::Endianness::NETWORK); REQUIRE(result == returnvalue::OK); REQUIRE((mdBuffer[1] << 8 | mdBuffer[2]) == 37); - auto checksumType = static_cast(mdBuffer[11] & 0x0f); - REQUIRE(checksumType == cfdp::ChecksumTypes::CRC_32C); + auto checksumType = static_cast(mdBuffer[11] & 0x0f); + REQUIRE(checksumType == cfdp::ChecksumType::CRC_32C); bool closureRequested = mdBuffer[11] >> 6 & 0x01; REQUIRE(closureRequested == true); // The size of the two options is 19. Summing up: @@ -130,7 +130,7 @@ TEST_CASE("Metadata PDU", "[cfdp][pdu]") { size_t maxSize = 4; info.setOptionsArray(options.data(), sizeOfOptions, maxSize); REQUIRE(info.getOptionsLen() == 2); - info.setChecksumType(cfdp::ChecksumTypes::CRC_32C); + info.setChecksumType(cfdp::ChecksumType::CRC_32C); info.setClosureRequested(true); uint8_t* buffer = mdBuffer.data(); size_t sz = 0; @@ -143,9 +143,9 @@ TEST_CASE("Metadata PDU", "[cfdp][pdu]") { MetadataPduReader deserializer2(mdBuffer.data(), mdBuffer.size(), info); result = deserializer2.parseData(); REQUIRE(result == returnvalue::OK); - REQUIRE(options[0]->getType() == cfdp::TlvTypes::FILESTORE_RESPONSE); + REQUIRE(options[0]->getType() == cfdp::TlvType::FILESTORE_RESPONSE); REQUIRE(options[0]->getSerializedSize() == 14); - REQUIRE(options[1]->getType() == cfdp::TlvTypes::MSG_TO_USER); + REQUIRE(options[1]->getType() == cfdp::TlvType::MSG_TO_USER); REQUIRE(options[1]->getSerializedSize() == 5); for (size_t invalidFieldLen = 0; invalidFieldLen < 36; invalidFieldLen++) { diff --git a/unittests/cfdp/pdu/testNakPdu.cpp b/unittests/cfdp/pdu/testNakPdu.cpp index f2779788..7974dab1 100644 --- a/unittests/cfdp/pdu/testNakPdu.cpp +++ b/unittests/cfdp/pdu/testNakPdu.cpp @@ -15,7 +15,7 @@ TEST_CASE("NAK PDU", "[cfdp][pdu]") { EntityId destId(WidthInBytes::TWO_BYTES, 2); TransactionSeqNum seqNum(WidthInBytes::TWO_BYTES, 15); EntityId sourceId(WidthInBytes::TWO_BYTES, 1); - PduConfig pduConf(sourceId, destId, TransmissionModes::ACKNOWLEDGED, seqNum); + PduConfig pduConf(sourceId, destId, TransmissionMode::ACKNOWLEDGED, seqNum); FileSize startOfScope(50); FileSize endOfScope(1050); @@ -29,7 +29,7 @@ TEST_CASE("NAK PDU", "[cfdp][pdu]") { REQUIRE(sz == 19); REQUIRE(serializer.getPduDataFieldLen() == 9); REQUIRE(((nakBuffer[1] << 8) | nakBuffer[2]) == 0x09); - REQUIRE(nakBuffer[10] == cfdp::FileDirectives::NAK); + REQUIRE(nakBuffer[10] == cfdp::FileDirective::NAK); uint32_t scope = 0; result = SerializeAdapter::deSerialize(&scope, nakBuffer.data() + 11, nullptr, SerializeIF::Endianness::NETWORK); diff --git a/unittests/cfdp/pdu/testPromptPdu.cpp b/unittests/cfdp/pdu/testPromptPdu.cpp index 538f6459..6032f44e 100644 --- a/unittests/cfdp/pdu/testPromptPdu.cpp +++ b/unittests/cfdp/pdu/testPromptPdu.cpp @@ -14,7 +14,7 @@ TEST_CASE("Prompt PDU", "[cfdp][pdu]") { EntityId destId(WidthInBytes::TWO_BYTES, 2); TransactionSeqNum seqNum(WidthInBytes::TWO_BYTES, 15); EntityId sourceId(WidthInBytes::TWO_BYTES, 1); - PduConfig pduConf(sourceId, destId, TransmissionModes::ACKNOWLEDGED, seqNum); + PduConfig pduConf(sourceId, destId, TransmissionMode::ACKNOWLEDGED, seqNum); SECTION("Serialize") { PromptPduCreator serializer(pduConf, cfdp::PromptResponseRequired::PROMPT_KEEP_ALIVE); @@ -23,7 +23,7 @@ TEST_CASE("Prompt PDU", "[cfdp][pdu]") { REQUIRE(serializer.getWholePduSize() == 12); REQUIRE(sz == 12); REQUIRE(serializer.getPduDataFieldLen() == 2); - REQUIRE(rawBuf[10] == FileDirectives::PROMPT); + REQUIRE(rawBuf[10] == FileDirective::PROMPT); REQUIRE(((rawBuf[sz - 1] >> 7) & 0x01) == cfdp::PromptResponseRequired::PROMPT_KEEP_ALIVE); for (size_t invalidMaxSz = 0; invalidMaxSz < sz; invalidMaxSz++) { diff --git a/unittests/cfdp/testCfdp.cpp b/unittests/cfdp/testCfdp.cpp index 38504a5b..eacc83de 100644 --- a/unittests/cfdp/testCfdp.cpp +++ b/unittests/cfdp/testCfdp.cpp @@ -16,13 +16,13 @@ TEST_CASE("CFDP Base", "[cfdp]") { cfdp::EntityId sourceId = EntityId(cfdp::WidthInBytes::ONE_BYTE, 0); cfdp::EntityId destId = EntityId(cfdp::WidthInBytes::ONE_BYTE, 1); PduConfig pduConf = - PduConfig(sourceId, destId, cfdp::TransmissionModes::ACKNOWLEDGED, seqNum, false); + PduConfig(sourceId, destId, cfdp::TransmissionMode::ACKNOWLEDGED, seqNum, false); uint8_t* serTarget = serBuf.data(); const uint8_t* deserTarget = serTarget; size_t serSize = 0; SECTION("File Directive") { - auto fdSer = FileDirectiveCreator(pduConf, FileDirectives::ACK, 4); + auto fdSer = FileDirectiveCreator(pduConf, FileDirective::ACK, 4); REQUIRE(fdSer.getSerializedSize() == 8); serTarget = serBuf.data(); serSize = 0; @@ -41,7 +41,7 @@ TEST_CASE("CFDP Base", "[cfdp]") { REQUIRE(serBuf[5] == 2); // Dest ID REQUIRE(serBuf[6] == 1); - REQUIRE(serBuf[7] == FileDirectives::ACK); + REQUIRE(serBuf[7] == FileDirective::ACK); serTarget = serBuf.data(); size_t deserSize = 20; @@ -65,10 +65,10 @@ TEST_CASE("CFDP Base", "[cfdp]") { REQUIRE(fdDeser.getEndianness() == SerializeIF::Endianness::MACHINE); fdDeser.setEndianness(SerializeIF::Endianness::NETWORK); REQUIRE(fdDeser.parseData() == returnvalue::OK); - REQUIRE(fdDeser.getFileDirective() == FileDirectives::ACK); + REQUIRE(fdDeser.getFileDirective() == FileDirective::ACK); REQUIRE(fdDeser.getPduDataFieldLen() == 5); REQUIRE(fdDeser.getHeaderSize() == 8); - REQUIRE(fdDeser.getPduType() == cfdp::PduTypes::FILE_DIRECTIVE); + REQUIRE(fdDeser.getPduType() == cfdp::PduType::FILE_DIRECTIVE); serBuf[7] = 0xff; // Invalid file directive diff --git a/unittests/cfdp/testOtherTlvs.cpp b/unittests/cfdp/testOtherTlvs.cpp index 4eb51a7c..88413195 100644 --- a/unittests/cfdp/testOtherTlvs.cpp +++ b/unittests/cfdp/testOtherTlvs.cpp @@ -41,7 +41,7 @@ TEST_CASE("CFDP Other TLVs", "[cfdp][tlv]") { result = response.convertToTlv(rawResponse, serBuf.data(), serBuf.size(), SerializeIF::Endianness::NETWORK); REQUIRE(result == returnvalue::OK); - REQUIRE(rawResponse.getType() == cfdp::TlvTypes::FILESTORE_RESPONSE); + REQUIRE(rawResponse.getType() == cfdp::TlvType::FILESTORE_RESPONSE); cfdp::StringLv emptyMsg; cfdp::StringLv emptySecondName; FilestoreResponseTlv emptyTlv(firstName, &emptyMsg); @@ -96,12 +96,12 @@ TEST_CASE("CFDP Other TLVs", "[cfdp][tlv]") { result = request.convertToTlv(rawRequest, serBuf.data(), serBuf.size(), SerializeIF::Endianness::NETWORK); REQUIRE(result == returnvalue::OK); - REQUIRE(rawRequest.getType() == cfdp::TlvTypes::FILESTORE_REQUEST); + REQUIRE(rawRequest.getType() == cfdp::TlvType::FILESTORE_REQUEST); emptyRequest.setActionCode(cfdp::FilestoreActionCode::DELETE_FILE); result = emptyRequest.deSerialize(rawRequest, SerializeIF::Endianness::NETWORK); REQUIRE(result == returnvalue::OK); - REQUIRE(emptyRequest.getType() == cfdp::TlvTypes::FILESTORE_REQUEST); + REQUIRE(emptyRequest.getType() == cfdp::TlvType::FILESTORE_REQUEST); REQUIRE(emptyRequest.getActionCode() == cfdp::FilestoreActionCode::APPEND_FILE); } @@ -111,7 +111,7 @@ TEST_CASE("CFDP Other TLVs", "[cfdp][tlv]") { FlowLabelTlv flowLabelTlv(&flowLabel, 1); FaultHandlerOverrideTlv faultOverrideTlv(cfdp::ConditionCode::FILESTORE_REJECTION, - cfdp::FaultHandlerCodes::NOTICE_OF_CANCELLATION); + cfdp::FaultHandlerCode::NOTICE_OF_CANCELLATION); size_t sz = 0; result = faultOverrideTlv.serialize(&serPtr, &sz, rawBuf.size(), SerializeIF::Endianness::NETWORK); @@ -128,7 +128,7 @@ TEST_CASE("CFDP Other TLVs", "[cfdp][tlv]") { EntityIdTlv idTlv(emptyId); serPtr = rawBuf.data(); result = idTlv.serialize(&serPtr, &deserSize, rawBuf.size(), SerializeIF::Endianness::NETWORK); - cfdp::Tlv rawTlv(cfdp::TlvTypes::ENTITY_ID, rawBuf.data() + 2, 2); + cfdp::Tlv rawTlv(cfdp::TlvType::ENTITY_ID, rawBuf.data() + 2, 2); REQUIRE(result == returnvalue::OK); deserPtr = rawBuf.data(); result = idTlv.deSerialize(rawTlv, SerializeIF::Endianness::NETWORK); diff --git a/unittests/cfdp/testTlv.cpp b/unittests/cfdp/testTlv.cpp index b78d8a80..979bfac5 100644 --- a/unittests/cfdp/testTlv.cpp +++ b/unittests/cfdp/testTlv.cpp @@ -22,14 +22,14 @@ TEST_CASE("CFDP TLV", "[cfdp][tlv]") { SECTION("TLV Serialization") { std::array tlvBuf{}; REQUIRE(sourceId.serializeBe(tlvBuf.data(), deserSize, tlvBuf.size()) == returnvalue::OK); - auto tlv = Tlv(TlvTypes::ENTITY_ID, tlvBuf.data(), deserSize); + auto tlv = Tlv(TlvType::ENTITY_ID, tlvBuf.data(), deserSize); REQUIRE(tlv.getSerializedSize() == 4); REQUIRE(tlv.getLengthField() == 2); deserSize = 0; REQUIRE(tlv.serialize(&serPtr, &deserSize, rawBuf.size(), SerializeIF::Endianness::NETWORK) == returnvalue::OK); REQUIRE(deserSize == 4); - REQUIRE(rawBuf[0] == TlvTypes::ENTITY_ID); + REQUIRE(rawBuf[0] == TlvType::ENTITY_ID); REQUIRE(rawBuf[1] == 2); uint16_t entityId = 0; REQUIRE(SerializeAdapter::deSerialize(&entityId, rawBuf.data() + 2, &deserSize, @@ -38,7 +38,7 @@ TEST_CASE("CFDP TLV", "[cfdp][tlv]") { } SECTION("TLV Other Value") { - auto tlv = Tlv(TlvTypes::ENTITY_ID, rawBuf.data(), deserSize); + auto tlv = Tlv(TlvType::ENTITY_ID, rawBuf.data(), deserSize); // Set new value sourceId.setValue(cfdp::WidthInBytes::FOUR_BYTES, 12); REQUIRE(sourceId.serialize(&serPtr, &deserSize, rawBuf.size(), @@ -48,17 +48,17 @@ TEST_CASE("CFDP TLV", "[cfdp][tlv]") { deserSize = 0; result = tlv.serialize(&serPtr, &deserSize, rawBuf.size(), SerializeIF::Endianness::NETWORK); REQUIRE(result == returnvalue::OK); - REQUIRE(rawBuf[0] == TlvTypes::ENTITY_ID); + REQUIRE(rawBuf[0] == TlvType::ENTITY_ID); REQUIRE(rawBuf[1] == 4); REQUIRE(result == returnvalue::OK); } SECTION("TLV Invalid") { - auto tlvInvalid = Tlv(cfdp::TlvTypes::INVALID_TLV, rawBuf.data(), 0); + auto tlvInvalid = Tlv(cfdp::TlvType::INVALID_TLV, rawBuf.data(), 0); REQUIRE(tlvInvalid.serialize(&serPtr, &deserSize, rawBuf.size(), SerializeIF::Endianness::NETWORK) != returnvalue::OK); - tlvInvalid = Tlv(cfdp::TlvTypes::ENTITY_ID, nullptr, 3); + tlvInvalid = Tlv(cfdp::TlvType::ENTITY_ID, nullptr, 3); REQUIRE(tlvInvalid.serialize(&serPtr, &deserSize, rawBuf.size(), SerializeIF::Endianness::NETWORK) != returnvalue::OK); REQUIRE(tlvInvalid.serialize(&serPtr, &deserSize, 0, SerializeIF::Endianness::NETWORK) != @@ -69,13 +69,13 @@ TEST_CASE("CFDP TLV", "[cfdp][tlv]") { } SECTION("TLV Zero Length Field") { - Tlv zeroLenField(TlvTypes::FAULT_HANDLER, nullptr, 0); + Tlv zeroLenField(TlvType::FAULT_HANDLER, nullptr, 0); REQUIRE(zeroLenField.getSerializedSize() == 2); serPtr = rawBuf.data(); deserSize = 0; REQUIRE(zeroLenField.serialize(&serPtr, &deserSize, rawBuf.size(), SerializeIF::Endianness::NETWORK) == returnvalue::OK); - REQUIRE(rawBuf[0] == TlvTypes::FAULT_HANDLER); + REQUIRE(rawBuf[0] == TlvType::FAULT_HANDLER); REQUIRE(rawBuf[1] == 0); } @@ -85,7 +85,7 @@ TEST_CASE("CFDP TLV", "[cfdp][tlv]") { serPtr = tlvRawBuf.data(); result = sourceId.serialize(&serPtr, &deserSize, tlvRawBuf.size(), SerializeIF::Endianness::NETWORK); - auto tlvSerialization = Tlv(TlvTypes::ENTITY_ID, tlvRawBuf.data(), deserSize); + auto tlvSerialization = Tlv(TlvType::ENTITY_ID, tlvRawBuf.data(), deserSize); serPtr = rawBuf.data(); deserSize = 0; result = tlvSerialization.serialize(&serPtr, &deserSize, rawBuf.size(), @@ -95,7 +95,7 @@ TEST_CASE("CFDP TLV", "[cfdp][tlv]") { result = tlv.deSerialize(&deserPtr, &deserSize, SerializeIF::Endianness::NETWORK); REQUIRE(result == returnvalue::OK); REQUIRE(tlv.getSerializedSize() == 4); - REQUIRE(tlv.getType() == TlvTypes::ENTITY_ID); + REQUIRE(tlv.getType() == TlvType::ENTITY_ID); deserPtr = tlv.getValue(); uint16_t entityId = 0; deserSize = 0; @@ -109,12 +109,12 @@ TEST_CASE("CFDP TLV", "[cfdp][tlv]") { REQUIRE(tlv.deSerialize(&deserPtr, &deserSize, SerializeIF::Endianness::NETWORK) == SerializeIF::STREAM_TOO_SHORT); // Set invalid TLV - rawBuf[0] = TlvTypes::INVALID_TLV; + rawBuf[0] = TlvType::INVALID_TLV; deserSize = 4; REQUIRE(tlv.deSerialize(&deserPtr, &deserSize, SerializeIF::Endianness::NETWORK) != returnvalue::OK); - Tlv zeroLenField(TlvTypes::FAULT_HANDLER, nullptr, 0); + Tlv zeroLenField(TlvType::FAULT_HANDLER, nullptr, 0); serPtr = rawBuf.data(); deserSize = 0; REQUIRE(zeroLenField.serialize(&serPtr, &deserSize, rawBuf.size(), diff --git a/unittests/mocks/cfdp/FaultHandlerMock.cpp b/unittests/mocks/cfdp/FaultHandlerMock.cpp index 26bebda5..03736f71 100644 --- a/unittests/mocks/cfdp/FaultHandlerMock.cpp +++ b/unittests/mocks/cfdp/FaultHandlerMock.cpp @@ -2,31 +2,31 @@ namespace cfdp { -void FaultHandlerMock::noticeOfSuspensionCb(cfdp::ConditionCode code) { - auto& info = fhInfoMap.at(cfdp::FaultHandlerCodes::NOTICE_OF_SUSPENSION); +void FaultHandlerMock::noticeOfSuspensionCb(TransactionId& id, cfdp::ConditionCode code) { + auto& info = fhInfoMap.at(cfdp::FaultHandlerCode::NOTICE_OF_SUSPENSION); info.callCount++; info.condCodes.push(code); } -void FaultHandlerMock::noticeOfCancellationCb(cfdp::ConditionCode code) { - auto& info = fhInfoMap.at(cfdp::FaultHandlerCodes::NOTICE_OF_CANCELLATION); +void FaultHandlerMock::noticeOfCancellationCb(TransactionId& id, cfdp::ConditionCode code) { + auto& info = fhInfoMap.at(cfdp::FaultHandlerCode::NOTICE_OF_CANCELLATION); info.callCount++; info.condCodes.push(code); } -void FaultHandlerMock::abandonCb(cfdp::ConditionCode code) { - auto& info = fhInfoMap.at(cfdp::FaultHandlerCodes::ABANDON_TRANSACTION); +void FaultHandlerMock::abandonCb(TransactionId& id, cfdp::ConditionCode code) { + auto& info = fhInfoMap.at(cfdp::FaultHandlerCode::ABANDON_TRANSACTION); info.callCount++; info.condCodes.push(code); } -void FaultHandlerMock::ignoreCb(cfdp::ConditionCode code) { - auto& info = fhInfoMap.at(cfdp::FaultHandlerCodes::IGNORE_ERROR); +void FaultHandlerMock::ignoreCb(TransactionId& id, cfdp::ConditionCode code) { + auto& info = fhInfoMap.at(cfdp::FaultHandlerCode::IGNORE_ERROR); info.callCount++; info.condCodes.push(code); } -FaultHandlerMock::FaultInfo& FaultHandlerMock::getFhInfo(cfdp::FaultHandlerCodes fhCode) { +FaultHandlerMock::FaultInfo& FaultHandlerMock::getFhInfo(cfdp::FaultHandlerCode fhCode) { return fhInfoMap.at(fhCode); } @@ -34,7 +34,7 @@ void FaultHandlerMock::reset() { fhInfoMap.clear(); } bool FaultHandlerMock::faultCbWasCalled() const { return std::any_of(fhInfoMap.begin(), fhInfoMap.end(), - [](const std::pair& pair) { + [](const std::pair& pair) { return pair.second.callCount > 0; }); } diff --git a/unittests/mocks/cfdp/FaultHandlerMock.h b/unittests/mocks/cfdp/FaultHandlerMock.h index a35d3d2b..1c59485c 100644 --- a/unittests/mocks/cfdp/FaultHandlerMock.h +++ b/unittests/mocks/cfdp/FaultHandlerMock.h @@ -15,21 +15,21 @@ class FaultHandlerMock : public FaultHandlerBase { std::queue condCodes; }; - void noticeOfSuspensionCb(ConditionCode code) override; - void noticeOfCancellationCb(ConditionCode code) override; - void abandonCb(ConditionCode code) override; - void ignoreCb(ConditionCode code) override; + void noticeOfSuspensionCb(TransactionId& id, ConditionCode code) override; + void noticeOfCancellationCb(TransactionId& id, ConditionCode code) override; + void abandonCb(TransactionId& id,ConditionCode code) override; + void ignoreCb(TransactionId& id, ConditionCode code) override; - FaultInfo& getFhInfo(FaultHandlerCodes fhCode); + FaultInfo& getFhInfo(FaultHandlerCode fhCode); [[nodiscard]] bool faultCbWasCalled() const; void reset(); private: - std::map fhInfoMap = { - std::pair{cfdp::FaultHandlerCodes::IGNORE_ERROR, FaultInfo()}, - std::pair{cfdp::FaultHandlerCodes::NOTICE_OF_CANCELLATION, FaultInfo()}, - std::pair{cfdp::FaultHandlerCodes::NOTICE_OF_SUSPENSION, FaultInfo()}, - std::pair{cfdp::FaultHandlerCodes::ABANDON_TRANSACTION, FaultInfo()}}; + std::map fhInfoMap = { + std::pair{cfdp::FaultHandlerCode::IGNORE_ERROR, FaultInfo()}, + std::pair{cfdp::FaultHandlerCode::NOTICE_OF_CANCELLATION, FaultInfo()}, + std::pair{cfdp::FaultHandlerCode::NOTICE_OF_SUSPENSION, FaultInfo()}, + std::pair{cfdp::FaultHandlerCode::ABANDON_TRANSACTION, FaultInfo()}}; }; } // namespace cfdp From 68ce8b5b0899aa907fe62daf8b289526620f3a16 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Tue, 27 Sep 2022 21:46:11 +0200 Subject: [PATCH 126/169] tweaks to make windows build again --- src/fsfw/osal/host/Clock.cpp | 1 + src/fsfw/osal/windows/winTaskHelpers.cpp | 1 + src/fsfw/osal/windows/winTaskHelpers.h | 4 +++- src/fsfw/timemanager/ClockCommon.cpp | 8 +++++++- src/fsfw/timemanager/TimeReaderIF.h | 6 ++++++ 5 files changed, 18 insertions(+), 2 deletions(-) diff --git a/src/fsfw/osal/host/Clock.cpp b/src/fsfw/osal/host/Clock.cpp index 29c6c1a6..dbf6529c 100644 --- a/src/fsfw/osal/host/Clock.cpp +++ b/src/fsfw/osal/host/Clock.cpp @@ -8,6 +8,7 @@ #if defined(PLATFORM_WIN) #include +#define timegm _mkgmtime #elif defined(PLATFORM_UNIX) #include #endif diff --git a/src/fsfw/osal/windows/winTaskHelpers.cpp b/src/fsfw/osal/windows/winTaskHelpers.cpp index 206ee7a7..5b4feb86 100644 --- a/src/fsfw/osal/windows/winTaskHelpers.cpp +++ b/src/fsfw/osal/windows/winTaskHelpers.cpp @@ -1,6 +1,7 @@ #include "fsfw/osal/windows/winTaskHelpers.h" #include +#include TaskPriority tasks::makeWinPriority(PriorityClass prioClass, PriorityNumber prioNumber) { return (static_cast(prioClass) << 16) | static_cast(prioNumber); diff --git a/src/fsfw/osal/windows/winTaskHelpers.h b/src/fsfw/osal/windows/winTaskHelpers.h index 87cd92ce..2d6ef9b4 100644 --- a/src/fsfw/osal/windows/winTaskHelpers.h +++ b/src/fsfw/osal/windows/winTaskHelpers.h @@ -1,10 +1,12 @@ #include #include -#include "../../tasks/TaskFactory.h" +#include "fsfw/tasks/TaskFactory.h" #ifdef _WIN32 +#include + namespace tasks { enum PriorityClass : uint16_t { diff --git a/src/fsfw/timemanager/ClockCommon.cpp b/src/fsfw/timemanager/ClockCommon.cpp index 45755f35..d0ac9004 100644 --- a/src/fsfw/timemanager/ClockCommon.cpp +++ b/src/fsfw/timemanager/ClockCommon.cpp @@ -61,10 +61,16 @@ ReturnValue_t Clock::convertTimevalToTimeOfDay(const timeval* from, TimeOfDay_t* if (result != returnvalue::OK) { return result; } - MutexGuard helper(timeMutex); // gmtime writes its output in a global buffer which is not Thread Safe // Therefore we have to use a Mutex here + MutexGuard helper(timeMutex); +#ifdef PLATFORM_WIN + time_t time; + time = from->tv_sec; + timeInfo = gmtime(&time); +#else timeInfo = gmtime(&from->tv_sec); +#endif to->year = timeInfo->tm_year + 1900; to->month = timeInfo->tm_mon + 1; to->day = timeInfo->tm_mday; diff --git a/src/fsfw/timemanager/TimeReaderIF.h b/src/fsfw/timemanager/TimeReaderIF.h index 8fd7415f..6bd763c7 100644 --- a/src/fsfw/timemanager/TimeReaderIF.h +++ b/src/fsfw/timemanager/TimeReaderIF.h @@ -2,6 +2,12 @@ #define FSFW_TIMEMANAGER_TIMEREADERIF_H #include +#include "fsfw/platform.h" + +#ifdef PLATFORM_WIN +// wtf? Required for timeval! +#include +#endif #include "TimeStampIF.h" #include "fsfw/returnvalues/returnvalue.h" From b0ecf87580af6d22bd9535ab8e8782f2ffb89b4a Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Tue, 27 Sep 2022 23:57:58 +0200 Subject: [PATCH 127/169] last windows tweak --- src/fsfw_hal/common/gpio/gpioDefinitions.h | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/fsfw_hal/common/gpio/gpioDefinitions.h b/src/fsfw_hal/common/gpio/gpioDefinitions.h index eb90629e..9f5618e4 100644 --- a/src/fsfw_hal/common/gpio/gpioDefinitions.h +++ b/src/fsfw_hal/common/gpio/gpioDefinitions.h @@ -5,6 +5,13 @@ #include #include +#ifdef PLATFORM_WIN +// What is this crap? +#undef IN +#undef OUT +#undef CALLBACK +#endif + using gpioId_t = uint16_t; namespace gpio { From 876815b1c9c897bab7a9d6cc6047957c778b30ad Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Wed, 28 Sep 2022 00:03:12 +0200 Subject: [PATCH 128/169] another small windows tweak --- src/fsfw/osal/common/TcpIpBase.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/fsfw/osal/common/TcpIpBase.cpp b/src/fsfw/osal/common/TcpIpBase.cpp index 7e989c36..de0a573d 100644 --- a/src/fsfw/osal/common/TcpIpBase.cpp +++ b/src/fsfw/osal/common/TcpIpBase.cpp @@ -1,5 +1,6 @@ #include "fsfw/osal/common/TcpIpBase.h" +#include "fsfw/serviceinterface.h" #include "fsfw/platform.h" #ifdef PLATFORM_UNIX From e0c780f21c7b2bb575c40b49b1d776d1b5d423a0 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Wed, 28 Sep 2022 09:56:20 +0200 Subject: [PATCH 129/169] better comment --- src/fsfw_hal/common/gpio/gpioDefinitions.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/fsfw_hal/common/gpio/gpioDefinitions.h b/src/fsfw_hal/common/gpio/gpioDefinitions.h index 9f5618e4..9f8b5e32 100644 --- a/src/fsfw_hal/common/gpio/gpioDefinitions.h +++ b/src/fsfw_hal/common/gpio/gpioDefinitions.h @@ -6,7 +6,8 @@ #include #ifdef PLATFORM_WIN -// What is this crap? +// Defined in Windows header for whatever reason, and leads to nameclash issues with +// class enums which have entries of the same name. #undef IN #undef OUT #undef CALLBACK From dd636b186b88af02e883d0ba2a138e510bc93cfa Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Mon, 17 Oct 2022 14:01:21 +0200 Subject: [PATCH 130/169] size check bugfix --- src/fsfw/cfdp/pdu/FinishedPduCreator.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/fsfw/cfdp/pdu/FinishedPduCreator.cpp b/src/fsfw/cfdp/pdu/FinishedPduCreator.cpp index 8ac22e0a..d002e8aa 100644 --- a/src/fsfw/cfdp/pdu/FinishedPduCreator.cpp +++ b/src/fsfw/cfdp/pdu/FinishedPduCreator.cpp @@ -17,7 +17,7 @@ ReturnValue_t FinishPduCreator::serialize(uint8_t **buffer, size_t *size, size_t if (result != returnvalue::OK) { return result; } - if (*size + 1 >= maxSize) { + if (*size + 1 > maxSize) { return SerializeIF::BUFFER_TOO_SHORT; } **buffer = finishInfo.getConditionCode() << 4 | finishInfo.getDeliveryCode() << 2 | From bfe120636c098c2fea205ff8fecee6cc1d3b92d3 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Mon, 17 Oct 2022 15:08:46 +0200 Subject: [PATCH 131/169] this should have the same effect --- src/fsfw/storagemanager/LocalPool.cpp | 24 ------------------------ src/fsfw/storagemanager/LocalPool.h | 11 +++++------ 2 files changed, 5 insertions(+), 30 deletions(-) diff --git a/src/fsfw/storagemanager/LocalPool.cpp b/src/fsfw/storagemanager/LocalPool.cpp index 970b05f5..7d37507a 100644 --- a/src/fsfw/storagemanager/LocalPool.cpp +++ b/src/fsfw/storagemanager/LocalPool.cpp @@ -318,27 +318,3 @@ bool LocalPool::hasDataAtId(store_address_t storeId) const { } return false; } - -ReturnValue_t LocalPool::getFreeElement(store_address_t* storeId, size_t size, uint8_t** pData) { - return StorageManagerIF::getFreeElement(storeId, size, pData); -} - -ConstAccessorPair LocalPool::getData(store_address_t storeId) { - return StorageManagerIF::getData(storeId); -} - -ReturnValue_t LocalPool::addData(store_address_t* storeId, const uint8_t* data, size_t size) { - return StorageManagerIF::addData(storeId, data, size); -} - -ReturnValue_t LocalPool::getData(store_address_t storeId, ConstStorageAccessor& accessor) { - return StorageManagerIF::getData(storeId, accessor); -} - -ReturnValue_t LocalPool::modifyData(store_address_t storeId, StorageAccessor& accessor) { - return StorageManagerIF::modifyData(storeId, accessor); -} - -AccessorPair LocalPool::modifyData(store_address_t storeId) { - return StorageManagerIF::modifyData(storeId); -} diff --git a/src/fsfw/storagemanager/LocalPool.h b/src/fsfw/storagemanager/LocalPool.h index 54d704e6..d3494f4b 100644 --- a/src/fsfw/storagemanager/LocalPool.h +++ b/src/fsfw/storagemanager/LocalPool.h @@ -88,19 +88,13 @@ class LocalPool : public SystemObject, public StorageManagerIF { */ ReturnValue_t addData(store_address_t* storeId, const uint8_t* data, size_t size, bool ignoreFault) override; - ReturnValue_t addData(store_address_t* storeId, const uint8_t* data, size_t size) override; - ReturnValue_t getFreeElement(store_address_t* storeId, size_t size, uint8_t** pData) override; ReturnValue_t getFreeElement(store_address_t* storeId, size_t size, uint8_t** pData, bool ignoreFault) override; - ConstAccessorPair getData(store_address_t storeId) override; - ReturnValue_t getData(store_address_t storeId, ConstStorageAccessor& accessor) override; ReturnValue_t getData(store_address_t storeId, const uint8_t** packet_ptr, size_t* size) override; - AccessorPair modifyData(store_address_t storeId) override; ReturnValue_t modifyData(store_address_t storeId, uint8_t** packet_ptr, size_t* size) override; - ReturnValue_t modifyData(store_address_t storeId, StorageAccessor& accessor) override; ReturnValue_t deleteData(store_address_t storeId) override; ReturnValue_t deleteData(uint8_t* ptr, size_t size, store_address_t* storeId) override; @@ -136,6 +130,11 @@ class LocalPool : public SystemObject, public StorageManagerIF { [[nodiscard]] max_subpools_t getNumberOfSubPools() const override; [[nodiscard]] bool hasDataAtId(store_address_t storeId) const override; + using StorageManagerIF::getFreeElement; + using StorageManagerIF::getData; + using StorageManagerIF::addData; + using StorageManagerIF::modifyData; + protected: /** * With this helper method, a free element of @c size is reserved. From 652c31a683dc4a66f9929eb569e66201ef5ba446 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Mon, 17 Oct 2022 17:24:46 +0200 Subject: [PATCH 132/169] missing validity check --- src/fsfw/tmtcpacket/ccsds/SpacePacketCreator.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/fsfw/tmtcpacket/ccsds/SpacePacketCreator.cpp b/src/fsfw/tmtcpacket/ccsds/SpacePacketCreator.cpp index b8607079..745d5834 100644 --- a/src/fsfw/tmtcpacket/ccsds/SpacePacketCreator.cpp +++ b/src/fsfw/tmtcpacket/ccsds/SpacePacketCreator.cpp @@ -14,6 +14,7 @@ SpacePacketCreator::SpacePacketCreator(ccsds::PacketType packetType, bool secHea : params(SpacePacketParams(PacketId(packetType, secHeaderFlag, apid), PacketSeqCtrl(seqFlags, seqCount), dataLen)) { params.version = version; + checkFieldValidity(); } uint16_t SpacePacketCreator::getPacketIdRaw() const { return params.packetId.raw(); } From 54ad6b30168d7a83940cd97672fb71e9a9dfd657 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Mon, 24 Oct 2022 14:39:05 +0200 Subject: [PATCH 133/169] add some docs --- src/fsfw/storagemanager/LocalPool.h | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/fsfw/storagemanager/LocalPool.h b/src/fsfw/storagemanager/LocalPool.h index d3494f4b..1472ee25 100644 --- a/src/fsfw/storagemanager/LocalPool.h +++ b/src/fsfw/storagemanager/LocalPool.h @@ -130,6 +130,9 @@ class LocalPool : public SystemObject, public StorageManagerIF { [[nodiscard]] max_subpools_t getNumberOfSubPools() const override; [[nodiscard]] bool hasDataAtId(store_address_t storeId) const override; + // Using functions provided by StorageManagerIF requires either a fully qualified path + // like for example localPool.StorageManagerIF::getFreeElement(...) or re-exporting + // the fully qualified path with the using directive. using StorageManagerIF::getFreeElement; using StorageManagerIF::getData; using StorageManagerIF::addData; From 4db124c6805d0778f1857a9d6bf6b25c1c37c587 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Mon, 24 Oct 2022 15:41:29 +0200 Subject: [PATCH 134/169] ignore fault --- src/fsfw/storagemanager/LocalPool.cpp | 11 +++++------ src/fsfw/storagemanager/LocalPool.h | 11 +++++------ src/fsfw/storagemanager/StorageManagerIF.h | 14 ++------------ 3 files changed, 12 insertions(+), 24 deletions(-) diff --git a/src/fsfw/storagemanager/LocalPool.cpp b/src/fsfw/storagemanager/LocalPool.cpp index 7d37507a..b62c19b6 100644 --- a/src/fsfw/storagemanager/LocalPool.cpp +++ b/src/fsfw/storagemanager/LocalPool.cpp @@ -31,9 +31,8 @@ LocalPool::LocalPool(object_id_t setObjectId, const LocalPoolConfig& poolConfig, LocalPool::~LocalPool() = default; -ReturnValue_t LocalPool::addData(store_address_t* storageId, const uint8_t* data, size_t size, - bool ignoreFault) { - ReturnValue_t status = reserveSpace(size, storageId, ignoreFault); +ReturnValue_t LocalPool::addData(store_address_t* storageId, const uint8_t* data, size_t size) { + ReturnValue_t status = reserveSpace(size, storageId); if (status == returnvalue::OK) { write(*storageId, data, size); } @@ -49,8 +48,8 @@ ReturnValue_t LocalPool::getData(store_address_t packetId, const uint8_t** packe } ReturnValue_t LocalPool::getFreeElement(store_address_t* storageId, const size_t size, - uint8_t** pData, bool ignoreFault) { - ReturnValue_t status = reserveSpace(size, storageId, ignoreFault); + uint8_t** pData) { + ReturnValue_t status = reserveSpace(size, storageId); if (status == returnvalue::OK) { *pData = &store[storageId->poolIndex][getRawPosition(*storageId)]; } else { @@ -167,7 +166,7 @@ void LocalPool::clearStore() { } } -ReturnValue_t LocalPool::reserveSpace(size_t size, store_address_t* storeId, bool ignoreFault) { +ReturnValue_t LocalPool::reserveSpace(size_t size, store_address_t* storeId) { ReturnValue_t status = getSubPoolIndex(size, &storeId->poolIndex); if (status != returnvalue::OK) { #if FSFW_CPP_OSTREAM_ENABLED == 1 diff --git a/src/fsfw/storagemanager/LocalPool.h b/src/fsfw/storagemanager/LocalPool.h index 1472ee25..bb88842b 100644 --- a/src/fsfw/storagemanager/LocalPool.h +++ b/src/fsfw/storagemanager/LocalPool.h @@ -86,11 +86,9 @@ class LocalPool : public SystemObject, public StorageManagerIF { /** * Documentation: See StorageManagerIF.h */ - ReturnValue_t addData(store_address_t* storeId, const uint8_t* data, size_t size, - bool ignoreFault) override; + ReturnValue_t addData(store_address_t* storeId, const uint8_t* data, size_t size) override; - ReturnValue_t getFreeElement(store_address_t* storeId, size_t size, uint8_t** pData, - bool ignoreFault) override; + ReturnValue_t getFreeElement(store_address_t* storeId, size_t size, uint8_t** pData) override; ReturnValue_t getData(store_address_t storeId, const uint8_t** packet_ptr, size_t* size) override; @@ -135,7 +133,6 @@ class LocalPool : public SystemObject, public StorageManagerIF { // the fully qualified path with the using directive. using StorageManagerIF::getFreeElement; using StorageManagerIF::getData; - using StorageManagerIF::addData; using StorageManagerIF::modifyData; protected: @@ -146,7 +143,7 @@ class LocalPool : public SystemObject, public StorageManagerIF { * @return - returnvalue::OK on success, * - the return codes of #getPoolIndex or #findEmpty otherwise. */ - virtual ReturnValue_t reserveSpace(size_t size, store_address_t* address, bool ignoreFault); + virtual ReturnValue_t reserveSpace(size_t size, store_address_t* address); private: /** @@ -190,6 +187,8 @@ class LocalPool : public SystemObject, public StorageManagerIF { std::vector> sizeLists = std::vector>(NUMBER_OF_SUBPOOLS); + bool ignoreFault = false; + //! A variable to determine whether higher n pools are used if //! the store is full. bool spillsToHigherPools = false; diff --git a/src/fsfw/storagemanager/StorageManagerIF.h b/src/fsfw/storagemanager/StorageManagerIF.h index 2845e581..5d804e44 100644 --- a/src/fsfw/storagemanager/StorageManagerIF.h +++ b/src/fsfw/storagemanager/StorageManagerIF.h @@ -66,12 +66,7 @@ class StorageManagerIF { * @return Returns @returnvalue::OK if data was added. * @returnvalue::FAILED if data could not be added, storageId is unchanged then. */ - virtual ReturnValue_t addData(store_address_t* storageId, const uint8_t* data, size_t size, - bool ignoreFault) = 0; - - virtual ReturnValue_t addData(store_address_t* storageId, const uint8_t* data, size_t size) { - return addData(storageId, data, size, false); - } + virtual ReturnValue_t addData(store_address_t* storageId, const uint8_t* data, size_t size) = 0; /** * @brief With deleteData, the storageManager frees the memory region @@ -186,12 +181,7 @@ class StorageManagerIF { * @return Returns @returnvalue::OK if data was added. * @returnvalue::FAILED if data could not be added, storageId is unchanged then. */ - virtual ReturnValue_t getFreeElement(store_address_t* storageId, size_t size, uint8_t** dataPtr, - bool ignoreFault) = 0; - - virtual ReturnValue_t getFreeElement(store_address_t* storageId, size_t size, uint8_t** dataPtr) { - return getFreeElement(storageId, size, dataPtr, false); - } + virtual ReturnValue_t getFreeElement(store_address_t* storageId, size_t size, uint8_t** dataPtr) = 0; [[nodiscard]] virtual bool hasDataAtId(store_address_t storeId) const = 0; From d26f230beeec08e72856df64b81966a3f9d840a2 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Mon, 24 Oct 2022 15:43:20 +0200 Subject: [PATCH 135/169] builds --- src/fsfw/storagemanager/PoolManager.cpp | 5 ++--- src/fsfw/storagemanager/PoolManager.h | 2 +- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/src/fsfw/storagemanager/PoolManager.cpp b/src/fsfw/storagemanager/PoolManager.cpp index 41e140b2..840a7dcc 100644 --- a/src/fsfw/storagemanager/PoolManager.cpp +++ b/src/fsfw/storagemanager/PoolManager.cpp @@ -9,10 +9,9 @@ PoolManager::PoolManager(object_id_t setObjectId, const LocalPoolConfig& localPo PoolManager::~PoolManager() { MutexFactory::instance()->deleteMutex(mutex); } -ReturnValue_t PoolManager::reserveSpace(const size_t size, store_address_t* address, - bool ignoreFault) { +ReturnValue_t PoolManager::reserveSpace(const size_t size, store_address_t* address) { MutexGuard mutexHelper(mutex, MutexIF::TimeoutType::WAITING, mutexTimeoutMs); - ReturnValue_t status = LocalPool::reserveSpace(size, address, ignoreFault); + ReturnValue_t status = LocalPool::reserveSpace(size, address); return status; } diff --git a/src/fsfw/storagemanager/PoolManager.h b/src/fsfw/storagemanager/PoolManager.h index eaa978ef..aa8c93dd 100644 --- a/src/fsfw/storagemanager/PoolManager.h +++ b/src/fsfw/storagemanager/PoolManager.h @@ -57,7 +57,7 @@ class PoolManager : public LocalPool { //! Default mutex timeout value to prevent permanent blocking. uint32_t mutexTimeoutMs = 20; - ReturnValue_t reserveSpace(size_t size, store_address_t* address, bool ignoreFault) override; + ReturnValue_t reserveSpace(size_t size, store_address_t* address) override; /** * @brief The mutex is created in the constructor and makes From 81a7de28147a0c386ff29269c36d0b00db1f9ad7 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Mon, 24 Oct 2022 16:39:32 +0200 Subject: [PATCH 136/169] make dtor virtual --- src/fsfw/storagemanager/StorageManagerIF.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/fsfw/storagemanager/StorageManagerIF.h b/src/fsfw/storagemanager/StorageManagerIF.h index 5d804e44..f9fb33f5 100644 --- a/src/fsfw/storagemanager/StorageManagerIF.h +++ b/src/fsfw/storagemanager/StorageManagerIF.h @@ -55,7 +55,7 @@ class StorageManagerIF { /** * @brief This is the empty virtual destructor as required for C++ interfaces. */ - ~StorageManagerIF() = default; + virtual ~StorageManagerIF() = default; /** * @brief With addData, a free storage position is allocated and data * stored there. From 11a22577beac11a4e2d1809c3ccb0ae3444ef1e0 Mon Sep 17 00:00:00 2001 From: Ulrich Mohr Date: Tue, 25 Oct 2022 11:28:13 +0200 Subject: [PATCH 137/169] defaultconfig did not build anymore --- misc/defaultcfg/fsfwconfig/objects/FsfwFactory.cpp | 5 ----- 1 file changed, 5 deletions(-) diff --git a/misc/defaultcfg/fsfwconfig/objects/FsfwFactory.cpp b/misc/defaultcfg/fsfwconfig/objects/FsfwFactory.cpp index 4d6e91f1..85a733b4 100644 --- a/misc/defaultcfg/fsfwconfig/objects/FsfwFactory.cpp +++ b/misc/defaultcfg/fsfwconfig/objects/FsfwFactory.cpp @@ -4,7 +4,6 @@ #include #include #include -#include #include #include #include @@ -41,13 +40,9 @@ void Factory::setStaticFrameworkObjectIds() { CommandingServiceBase::defaultPacketSource = objects::NO_OBJECT; CommandingServiceBase::defaultPacketDestination = objects::NO_OBJECT; - VerificationReporter::messageReceiver = objects::PUS_SERVICE_1_VERIFICATION; - DeviceHandlerBase::powerSwitcherId = objects::NO_OBJECT; DeviceHandlerBase::rawDataReceiverId = objects::PUS_SERVICE_2_DEVICE_ACCESS; DeviceHandlerFailureIsolation::powerConfirmationId = objects::NO_OBJECT; - - TmPacketBase::timeStamperId = objects::NO_OBJECT; } From bee33526a16c565af38c04ef71fb9ae33f558ad4 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Wed, 9 Nov 2022 13:49:40 +0100 Subject: [PATCH 138/169] missing include --- src/fsfw/timemanager/TimeReaderIF.h | 1 + 1 file changed, 1 insertion(+) diff --git a/src/fsfw/timemanager/TimeReaderIF.h b/src/fsfw/timemanager/TimeReaderIF.h index 8fd7415f..be03fb2a 100644 --- a/src/fsfw/timemanager/TimeReaderIF.h +++ b/src/fsfw/timemanager/TimeReaderIF.h @@ -1,6 +1,7 @@ #ifndef FSFW_TIMEMANAGER_TIMEREADERIF_H #define FSFW_TIMEMANAGER_TIMEREADERIF_H +#include #include #include "TimeStampIF.h" From c913fe40bf0c7ebcd395ccfb04b3b426a99f2916 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Wed, 9 Nov 2022 17:54:08 +0100 Subject: [PATCH 139/169] tweaks --- CMakeLists.txt | 6 +- cmake/cmake-modules/bilke/CodeCoverage.cmake | 2 +- .../globalfunctions/timevalOperations.cpp | 9 +- src/fsfw/osal/common/TcpIpBase.cpp | 2 +- src/fsfw/osal/windows/winTaskHelpers.cpp | 3 +- .../ServiceInterfaceBuffer.cpp | 1 - src/fsfw/timemanager/TimeReaderIF.h | 1 + src/fsfw_hal/common/printChar.c | 2 +- .../globalfunctions/testTimevalOperations.cpp | 100 +++++++++--------- unittests/hal/CMakeLists.txt | 8 +- 10 files changed, 72 insertions(+), 62 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index e2572b20..df3757ea 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -340,9 +340,9 @@ if(FSFW_BUILD_TESTS) -ftest-coverage) if(WIN32) - setup_target_for_coverage_gcovr_html( - NAME ${FSFW_TEST_TGT}_coverage EXECUTABLE ${FSFW_TEST_TGT} - DEPENDENCIES ${FSFW_TEST_TGT}) + #setup_target_for_coverage_gcovr_html( + # NAME ${FSFW_TEST_TGT}_coverage EXECUTABLE ${FSFW_TEST_TGT} + # DEPENDENCIES ${FSFW_TEST_TGT}) else() setup_target_for_coverage_lcov( NAME ${FSFW_TEST_TGT}_coverage EXECUTABLE ${FSFW_TEST_TGT} diff --git a/cmake/cmake-modules/bilke/CodeCoverage.cmake b/cmake/cmake-modules/bilke/CodeCoverage.cmake index aef3d943..c8b9e4ae 100644 --- a/cmake/cmake-modules/bilke/CodeCoverage.cmake +++ b/cmake/cmake-modules/bilke/CodeCoverage.cmake @@ -140,7 +140,7 @@ find_program( GCOV_PATH gcov ) find_program( LCOV_PATH NAMES lcov lcov.bat lcov.exe lcov.perl) find_program( FASTCOV_PATH NAMES fastcov fastcov.py ) find_program( GENHTML_PATH NAMES genhtml genhtml.perl genhtml.bat ) -find_program( GCOVR_PATH gcovr PATHS ${CMAKE_SOURCE_DIR}/scripts/test) +find_program( GCOVR_PATH gcovr ) find_program( CPPFILT_PATH NAMES c++filt ) if(NOT GCOV_PATH) diff --git a/src/fsfw/globalfunctions/timevalOperations.cpp b/src/fsfw/globalfunctions/timevalOperations.cpp index e2b35512..f9f0a5c6 100644 --- a/src/fsfw/globalfunctions/timevalOperations.cpp +++ b/src/fsfw/globalfunctions/timevalOperations.cpp @@ -1,9 +1,12 @@ #include "fsfw/globalfunctions/timevalOperations.h" +#include + timeval& operator+=(timeval& lhs, const timeval& rhs) { - int64_t sum = lhs.tv_sec * 1000000. + lhs.tv_usec; - sum += rhs.tv_sec * 1000000. + rhs.tv_usec; - lhs.tv_sec = sum / 1000000; + int64_t sum = static_cast(lhs.tv_sec) * 1000000. + lhs.tv_usec; + sum += static_cast(rhs.tv_sec) * 1000000. + rhs.tv_usec; + int64_t tmp = sum / 1000000; + lhs.tv_sec = tmp; lhs.tv_usec = sum - lhs.tv_sec * 1000000; return lhs; } diff --git a/src/fsfw/osal/common/TcpIpBase.cpp b/src/fsfw/osal/common/TcpIpBase.cpp index de0a573d..486a5171 100644 --- a/src/fsfw/osal/common/TcpIpBase.cpp +++ b/src/fsfw/osal/common/TcpIpBase.cpp @@ -1,7 +1,7 @@ #include "fsfw/osal/common/TcpIpBase.h" -#include "fsfw/serviceinterface.h" #include "fsfw/platform.h" +#include "fsfw/serviceinterface.h" #ifdef PLATFORM_UNIX #include diff --git a/src/fsfw/osal/windows/winTaskHelpers.cpp b/src/fsfw/osal/windows/winTaskHelpers.cpp index 5b4feb86..235dca1e 100644 --- a/src/fsfw/osal/windows/winTaskHelpers.cpp +++ b/src/fsfw/osal/windows/winTaskHelpers.cpp @@ -1,8 +1,9 @@ #include "fsfw/osal/windows/winTaskHelpers.h" -#include #include +#include + TaskPriority tasks::makeWinPriority(PriorityClass prioClass, PriorityNumber prioNumber) { return (static_cast(prioClass) << 16) | static_cast(prioNumber); } diff --git a/src/fsfw/serviceinterface/ServiceInterfaceBuffer.cpp b/src/fsfw/serviceinterface/ServiceInterfaceBuffer.cpp index 23892dcc..0e73be83 100644 --- a/src/fsfw/serviceinterface/ServiceInterfaceBuffer.cpp +++ b/src/fsfw/serviceinterface/ServiceInterfaceBuffer.cpp @@ -3,7 +3,6 @@ #if FSFW_CPP_OSTREAM_ENABLED == 1 #include - #include #include "fsfw/serviceinterface/serviceInterfaceDefintions.h" diff --git a/src/fsfw/timemanager/TimeReaderIF.h b/src/fsfw/timemanager/TimeReaderIF.h index 6bd763c7..8dce097f 100644 --- a/src/fsfw/timemanager/TimeReaderIF.h +++ b/src/fsfw/timemanager/TimeReaderIF.h @@ -2,6 +2,7 @@ #define FSFW_TIMEMANAGER_TIMEREADERIF_H #include + #include "fsfw/platform.h" #ifdef PLATFORM_WIN diff --git a/src/fsfw_hal/common/printChar.c b/src/fsfw_hal/common/printChar.c index 6e02c1df..24fba5c8 100644 --- a/src/fsfw_hal/common/printChar.c +++ b/src/fsfw_hal/common/printChar.c @@ -1,5 +1,5 @@ -#include #include +#include void __attribute__((weak)) printChar(const char* character, bool errStream) { if (errStream) { diff --git a/unittests/globalfunctions/testTimevalOperations.cpp b/unittests/globalfunctions/testTimevalOperations.cpp index 155e6b15..0f89338b 100644 --- a/unittests/globalfunctions/testTimevalOperations.cpp +++ b/unittests/globalfunctions/testTimevalOperations.cpp @@ -56,61 +56,65 @@ TEST_CASE("TimevalTest", "[timevalOperations]") { } SECTION("Operators") { timeval t1; - t1.tv_sec = 1648227422; - t1.tv_usec = 123456; - timeval t2; - t2.tv_sec = 1648227422; - t2.tv_usec = 123456; - timeval t3 = t1 - t2; - REQUIRE(t3.tv_sec == 0); - REQUIRE(t3.tv_usec == 0); - timeval t4 = t1 - t3; - REQUIRE(t4.tv_sec == 1648227422); - REQUIRE(t4.tv_usec == 123456); - timeval t5 = t3 - t1; - REQUIRE(t5.tv_sec == -1648227422); - REQUIRE(t5.tv_usec == -123456); + if (sizeof(t1.tv_sec) == 8) { + t1.tv_sec = 1648227422; + t1.tv_usec = 123456; + timeval t2; + t2.tv_sec = 1648227422; + t2.tv_usec = 123456; + timeval t3 = t1 - t2; + REQUIRE(t3.tv_sec == 0); + REQUIRE(t3.tv_usec == 0); + timeval t4 = t1 - t3; + REQUIRE(t4.tv_sec == 1648227422); + REQUIRE(t4.tv_usec == 123456); + timeval t5 = t3 - t1; + REQUIRE(t5.tv_sec == -1648227422); + REQUIRE(t5.tv_usec == -123456); - timeval t6; - t6.tv_sec = 1648227400; - t6.tv_usec = 999999; + timeval t6; + t6.tv_sec = 1648227400; + t6.tv_usec = 999999; - timeval t7 = t6 + t1; - REQUIRE(t7.tv_sec == (1648227422ull + 1648227400ull + 1ull)); - REQUIRE(t7.tv_usec == 123455); + timeval t7 = t6 + t1; + // Overflow test + REQUIRE(t7.tv_sec == (1648227422ull + 1648227400ull + 1ull)); - timeval t8 = t1 - t6; - REQUIRE(t8.tv_sec == 1648227422 - 1648227400 - 1); - REQUIRE(t8.tv_usec == 123457); + REQUIRE(t7.tv_usec == 123455); - double scalar = 2; - timeval t9 = t1 * scalar; - REQUIRE(t9.tv_sec == 3296454844); - REQUIRE(t9.tv_usec == 246912); - timeval t10 = scalar * t1; - REQUIRE(t10.tv_sec == 3296454844); - REQUIRE(t10.tv_usec == 246912); - timeval t11 = t6 * scalar; - REQUIRE(t11.tv_sec == (3296454800 + 1)); - REQUIRE(t11.tv_usec == 999998); + timeval t8 = t1 - t6; + REQUIRE(t8.tv_sec == 1648227422 - 1648227400 - 1); + REQUIRE(t8.tv_usec == 123457); - timeval t12 = t1 / scalar; - REQUIRE(t12.tv_sec == 824113711); - REQUIRE(t12.tv_usec == 61728); + double scalar = 2; + timeval t9 = t1 * scalar; + REQUIRE(t9.tv_sec == 3296454844); + REQUIRE(t9.tv_usec == 246912); + timeval t10 = scalar * t1; + REQUIRE(t10.tv_sec == 3296454844); + REQUIRE(t10.tv_usec == 246912); + timeval t11 = t6 * scalar; + REQUIRE(t11.tv_sec == (3296454800 + 1)); + REQUIRE(t11.tv_usec == 999998); - timeval t13 = t6 / scalar; - REQUIRE(t13.tv_sec == 824113700); - // Rounding issue - REQUIRE(t13.tv_usec == 499999); + timeval t12 = t1 / scalar; + REQUIRE(t12.tv_sec == 824113711); + REQUIRE(t12.tv_usec == 61728); - double scalar2 = t9 / t1; - REQUIRE(scalar2 == Catch::Approx(2.0)); - double scalar3 = t1 / t6; - REQUIRE(scalar3 == Catch::Approx(1.000000013)); - double scalar4 = t3 / t1; - REQUIRE(scalar4 == Catch::Approx(0)); - double scalar5 = t12 / t1; - REQUIRE(scalar5 == Catch::Approx(0.5)); + timeval t13 = t6 / scalar; + REQUIRE(t13.tv_sec == 824113700); + // Rounding issue + REQUIRE(t13.tv_usec == 499999); + + double scalar2 = t9 / t1; + REQUIRE(scalar2 == Catch::Approx(2.0)); + double scalar3 = t1 / t6; + REQUIRE(scalar3 == Catch::Approx(1.000000013)); + double scalar4 = t3 / t1; + REQUIRE(scalar4 == Catch::Approx(0)); + double scalar5 = t12 / t1; + REQUIRE(scalar5 == Catch::Approx(0.5)); + } } SECTION("timevalOperations::toTimeval") { diff --git a/unittests/hal/CMakeLists.txt b/unittests/hal/CMakeLists.txt index ee14a3aa..25691a47 100644 --- a/unittests/hal/CMakeLists.txt +++ b/unittests/hal/CMakeLists.txt @@ -1,3 +1,5 @@ -target_sources(${FSFW_TEST_TGT} PRIVATE - testCommandExecutor.cpp -) +if(UNIX) + target_sources(${FSFW_TEST_TGT} PRIVATE + testCommandExecutor.cpp + ) +endif() From 83c2c4825c1c8f59c99549ee80768742833b612c Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Thu, 10 Nov 2022 15:53:18 +0100 Subject: [PATCH 140/169] fix compiler error for fixed array list copy ctor --- src/fsfw/container/FixedArrayList.h | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/fsfw/container/FixedArrayList.h b/src/fsfw/container/FixedArrayList.h index fc8be393..78184e35 100644 --- a/src/fsfw/container/FixedArrayList.h +++ b/src/fsfw/container/FixedArrayList.h @@ -20,7 +20,9 @@ class FixedArrayList : public ArrayList { FixedArrayList() : ArrayList(data, MAX_SIZE) {} FixedArrayList(const FixedArrayList& other) : ArrayList(data, MAX_SIZE) { - memcpy(this->data, other.data, sizeof(this->data)); + for (size_t idx = 0; idx < sizeof(data); idx++) { + data[idx] = other.data[idx]; + } this->entries = data; this->size = other.size; } From 5c84f124400e0b3265868c2c7b563ad0cd181ee9 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Thu, 10 Nov 2022 16:15:28 +0100 Subject: [PATCH 141/169] this not crash --- src/fsfw/container/FixedArrayList.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/fsfw/container/FixedArrayList.h b/src/fsfw/container/FixedArrayList.h index 78184e35..6ae7da41 100644 --- a/src/fsfw/container/FixedArrayList.h +++ b/src/fsfw/container/FixedArrayList.h @@ -20,11 +20,11 @@ class FixedArrayList : public ArrayList { FixedArrayList() : ArrayList(data, MAX_SIZE) {} FixedArrayList(const FixedArrayList& other) : ArrayList(data, MAX_SIZE) { - for (size_t idx = 0; idx < sizeof(data); idx++) { - data[idx] = other.data[idx]; - } this->entries = data; this->size = other.size; + for (size_t idx = 0; idx < this->size; idx++) { + data[idx] = other.data[idx]; + } } FixedArrayList& operator=(FixedArrayList other) { From 16246d6ece48e0882142fc9665b9387a1d4d3074 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Thu, 10 Nov 2022 16:18:36 +0100 Subject: [PATCH 142/169] replace other memcpy --- src/fsfw/container/FixedArrayList.h | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/fsfw/container/FixedArrayList.h b/src/fsfw/container/FixedArrayList.h index 6ae7da41..97ade7e8 100644 --- a/src/fsfw/container/FixedArrayList.h +++ b/src/fsfw/container/FixedArrayList.h @@ -28,9 +28,11 @@ class FixedArrayList : public ArrayList { } FixedArrayList& operator=(FixedArrayList other) { - memcpy(this->data, other.data, sizeof(this->data)); this->entries = data; this->size = other.size; + for (size_t idx = 0; idx < this->size; idx++) { + data[idx] = other.data[idx]; + } return *this; } From 819a298b19bd620b2373683b82dcefbe727c668e Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Thu, 10 Nov 2022 17:50:21 +0100 Subject: [PATCH 143/169] refactoring of serial drivers for linux --- CMakeLists.txt | 1 + src/fsfw_hal/linux/CMakeLists.txt | 11 +- src/fsfw_hal/linux/serial/CMakeLists.txt | 2 + .../UartComIF.cpp => serial/SerialComIF.cpp} | 226 +++--------------- .../UartComIF.h => serial/SerialComIF.h} | 34 +-- .../SerialCookie.cpp} | 7 +- .../UartCookie.h => serial/SerialCookie.h} | 46 +--- src/fsfw_hal/linux/serial/helper.cpp | 163 +++++++++++++ src/fsfw_hal/linux/serial/helper.h | 71 ++++++ src/fsfw_hal/linux/uart/CMakeLists.txt | 1 - 10 files changed, 287 insertions(+), 275 deletions(-) create mode 100644 src/fsfw_hal/linux/serial/CMakeLists.txt rename src/fsfw_hal/linux/{uart/UartComIF.cpp => serial/SerialComIF.cpp} (64%) rename src/fsfw_hal/linux/{uart/UartComIF.h => serial/SerialComIF.h} (77%) rename src/fsfw_hal/linux/{uart/UartCookie.cpp => serial/SerialCookie.cpp} (91%) rename src/fsfw_hal/linux/{uart/UartCookie.h => serial/SerialCookie.h} (81%) create mode 100644 src/fsfw_hal/linux/serial/helper.cpp create mode 100644 src/fsfw_hal/linux/serial/helper.h delete mode 100644 src/fsfw_hal/linux/uart/CMakeLists.txt diff --git a/CMakeLists.txt b/CMakeLists.txt index e2572b20..c847d47f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -122,6 +122,7 @@ if(UNIX) option(FSFW_HAL_LINUX_ADD_PERIPHERAL_DRIVERS "Add Linux peripheral drivers" OFF) option(FSFW_HAL_LINUX_ADD_LIBGPIOD "Attempt to add Linux GPIOD drivers" OFF) + option(FSFW_HAL_LINUX_ADD_SERIAL_DRIVERS "Add serial drivers" ON) endif() # Optional sources diff --git a/src/fsfw_hal/linux/CMakeLists.txt b/src/fsfw_hal/linux/CMakeLists.txt index ffa5f5ee..d22d7ff1 100644 --- a/src/fsfw_hal/linux/CMakeLists.txt +++ b/src/fsfw_hal/linux/CMakeLists.txt @@ -5,11 +5,14 @@ endif() target_sources(${LIB_FSFW_NAME} PRIVATE UnixFileGuard.cpp CommandExecutor.cpp utility.cpp) +if(FSFW_HAL_LINUX_ADD_LIBGPIOD) + add_subdirectory(gpio) +endif() +if(FSFW_HAL_LINUX_ADD_SERIAL_DRIVERS) + add_subdirectory(serial) +endif() + if(FSFW_HAL_LINUX_ADD_PERIPHERAL_DRIVERS) - if(FSFW_HAL_LINUX_ADD_LIBGPIOD) - add_subdirectory(gpio) - endif() - add_subdirectory(uart) # Adding those does not really make sense on Apple systems which are generally # host systems. It won't even compile as the headers are missing if(NOT APPLE) diff --git a/src/fsfw_hal/linux/serial/CMakeLists.txt b/src/fsfw_hal/linux/serial/CMakeLists.txt new file mode 100644 index 00000000..07d20d29 --- /dev/null +++ b/src/fsfw_hal/linux/serial/CMakeLists.txt @@ -0,0 +1,2 @@ +target_sources(${LIB_FSFW_NAME} PUBLIC SerialComIF.cpp SerialCookie.cpp + helper.cpp) diff --git a/src/fsfw_hal/linux/uart/UartComIF.cpp b/src/fsfw_hal/linux/serial/SerialComIF.cpp similarity index 64% rename from src/fsfw_hal/linux/uart/UartComIF.cpp rename to src/fsfw_hal/linux/serial/SerialComIF.cpp index 8947c562..0fd293a0 100644 --- a/src/fsfw_hal/linux/uart/UartComIF.cpp +++ b/src/fsfw_hal/linux/serial/SerialComIF.cpp @@ -1,7 +1,6 @@ -#include "UartComIF.h" - #include #include +#include #include #include @@ -11,13 +10,12 @@ #include "fsfw/serviceinterface.h" #include "fsfw_hal/linux/utility.h" -UartComIF::UartComIF(object_id_t objectId) : SystemObject(objectId) {} +SerialComIF::SerialComIF(object_id_t objectId) : SystemObject(objectId) {} -UartComIF::~UartComIF() {} +SerialComIF::~SerialComIF() {} -ReturnValue_t UartComIF::initializeInterface(CookieIF* cookie) { +ReturnValue_t SerialComIF::initializeInterface(CookieIF* cookie) { std::string deviceFile; - UartDeviceMapIter uartDeviceMapIter; if (cookie == nullptr) { return NULLPOINTER; @@ -33,7 +31,7 @@ ReturnValue_t UartComIF::initializeInterface(CookieIF* cookie) { deviceFile = uartCookie->getDeviceFile(); - uartDeviceMapIter = uartDeviceMap.find(deviceFile); + auto uartDeviceMapIter = uartDeviceMap.find(deviceFile); if (uartDeviceMapIter == uartDeviceMap.end()) { int fileDescriptor = configureUartPort(uartCookie); if (fileDescriptor < 0) { @@ -60,7 +58,7 @@ ReturnValue_t UartComIF::initializeInterface(CookieIF* cookie) { return returnvalue::OK; } -int UartComIF::configureUartPort(UartCookie* uartCookie) { +int SerialComIF::configureUartPort(UartCookie* uartCookie) { struct termios options = {}; std::string deviceFile = uartCookie->getDeviceFile(); @@ -89,11 +87,11 @@ int UartComIF::configureUartPort(UartCookie* uartCookie) { return fd; } - setParityOptions(&options, uartCookie); + uart::setParity(options, uartCookie->getParity()); setStopBitOptions(&options, uartCookie); setDatasizeOptions(&options, uartCookie); setFixedOptions(&options); - setUartMode(&options, *uartCookie); + uart::setMode(options, uartCookie->getUartMode()); if (uartCookie->getInputShouldBeFlushed()) { tcflush(fd, TCIFLUSH); } @@ -102,7 +100,7 @@ int UartComIF::configureUartPort(UartCookie* uartCookie) { options.c_cc[VTIME] = 0; options.c_cc[VMIN] = 0; - configureBaudrate(&options, uartCookie); + uart::setBaudrate(options, uartCookie->getBaudrate()); /* Save option settings */ if (tcsetattr(fd, TCSANOW, &options) != 0) { @@ -115,24 +113,7 @@ int UartComIF::configureUartPort(UartCookie* uartCookie) { return fd; } -void UartComIF::setParityOptions(struct termios* options, UartCookie* uartCookie) { - /* Clear parity bit */ - options->c_cflag &= ~PARENB; - switch (uartCookie->getParity()) { - case Parity::EVEN: - options->c_cflag |= PARENB; - options->c_cflag &= ~PARODD; - break; - case Parity::ODD: - options->c_cflag |= PARENB; - options->c_cflag |= PARODD; - break; - default: - break; - } -} - -void UartComIF::setStopBitOptions(struct termios* options, UartCookie* uartCookie) { +void SerialComIF::setStopBitOptions(struct termios* options, UartCookie* uartCookie) { /* Clear stop field. Sets stop bit to one bit */ options->c_cflag &= ~CSTOPB; switch (uartCookie->getStopBits()) { @@ -144,7 +125,7 @@ void UartComIF::setStopBitOptions(struct termios* options, UartCookie* uartCooki } } -void UartComIF::setDatasizeOptions(struct termios* options, UartCookie* uartCookie) { +void SerialComIF::setDatasizeOptions(struct termios* options, UartCookie* uartCookie) { /* Clear size bits */ options->c_cflag &= ~CSIZE; switch (uartCookie->getBitsPerWord()) { @@ -168,7 +149,7 @@ void UartComIF::setDatasizeOptions(struct termios* options, UartCookie* uartCook } } -void UartComIF::setFixedOptions(struct termios* options) { +void SerialComIF::setFixedOptions(struct termios* options) { /* Disable RTS/CTS hardware flow control */ options->c_cflag &= ~CRTSCTS; /* Turn on READ & ignore ctrl lines (CLOCAL = 1) */ @@ -191,142 +172,9 @@ void UartComIF::setFixedOptions(struct termios* options) { options->c_oflag &= ~ONLCR; } -void UartComIF::configureBaudrate(struct termios* options, UartCookie* uartCookie) { - switch (uartCookie->getBaudrate()) { - case UartBaudRate::RATE_50: - cfsetispeed(options, B50); - cfsetospeed(options, B50); - break; - case UartBaudRate::RATE_75: - cfsetispeed(options, B75); - cfsetospeed(options, B75); - break; - case UartBaudRate::RATE_110: - cfsetispeed(options, B110); - cfsetospeed(options, B110); - break; - case UartBaudRate::RATE_134: - cfsetispeed(options, B134); - cfsetospeed(options, B134); - break; - case UartBaudRate::RATE_150: - cfsetispeed(options, B150); - cfsetospeed(options, B150); - break; - case UartBaudRate::RATE_200: - cfsetispeed(options, B200); - cfsetospeed(options, B200); - break; - case UartBaudRate::RATE_300: - cfsetispeed(options, B300); - cfsetospeed(options, B300); - break; - case UartBaudRate::RATE_600: - cfsetispeed(options, B600); - cfsetospeed(options, B600); - break; - case UartBaudRate::RATE_1200: - cfsetispeed(options, B1200); - cfsetospeed(options, B1200); - break; - case UartBaudRate::RATE_1800: - cfsetispeed(options, B1800); - cfsetospeed(options, B1800); - break; - case UartBaudRate::RATE_2400: - cfsetispeed(options, B2400); - cfsetospeed(options, B2400); - break; - case UartBaudRate::RATE_4800: - cfsetispeed(options, B4800); - cfsetospeed(options, B4800); - break; - case UartBaudRate::RATE_9600: - cfsetispeed(options, B9600); - cfsetospeed(options, B9600); - break; - case UartBaudRate::RATE_19200: - cfsetispeed(options, B19200); - cfsetospeed(options, B19200); - break; - case UartBaudRate::RATE_38400: - cfsetispeed(options, B38400); - cfsetospeed(options, B38400); - break; - case UartBaudRate::RATE_57600: - cfsetispeed(options, B57600); - cfsetospeed(options, B57600); - break; - case UartBaudRate::RATE_115200: - cfsetispeed(options, B115200); - cfsetospeed(options, B115200); - break; - case UartBaudRate::RATE_230400: - cfsetispeed(options, B230400); - cfsetospeed(options, B230400); - break; -#ifndef __APPLE__ - case UartBaudRate::RATE_460800: - cfsetispeed(options, B460800); - cfsetospeed(options, B460800); - break; - case UartBaudRate::RATE_500000: - cfsetispeed(options, B500000); - cfsetospeed(options, B500000); - break; - case UartBaudRate::RATE_576000: - cfsetispeed(options, B576000); - cfsetospeed(options, B576000); - break; - case UartBaudRate::RATE_921600: - cfsetispeed(options, B921600); - cfsetospeed(options, B921600); - break; - case UartBaudRate::RATE_1000000: - cfsetispeed(options, B1000000); - cfsetospeed(options, B1000000); - break; - case UartBaudRate::RATE_1152000: - cfsetispeed(options, B1152000); - cfsetospeed(options, B1152000); - break; - case UartBaudRate::RATE_1500000: - cfsetispeed(options, B1500000); - cfsetospeed(options, B1500000); - break; - case UartBaudRate::RATE_2000000: - cfsetispeed(options, B2000000); - cfsetospeed(options, B2000000); - break; - case UartBaudRate::RATE_2500000: - cfsetispeed(options, B2500000); - cfsetospeed(options, B2500000); - break; - case UartBaudRate::RATE_3000000: - cfsetispeed(options, B3000000); - cfsetospeed(options, B3000000); - break; - case UartBaudRate::RATE_3500000: - cfsetispeed(options, B3500000); - cfsetospeed(options, B3500000); - break; - case UartBaudRate::RATE_4000000: - cfsetispeed(options, B4000000); - cfsetospeed(options, B4000000); - break; -#endif // ! __APPLE__ - default: -#if FSFW_CPP_OSTREAM_ENABLED == 1 - sif::warning << "UartComIF::configureBaudrate: Baudrate not supported" << std::endl; -#endif - break; - } -} - -ReturnValue_t UartComIF::sendMessage(CookieIF* cookie, const uint8_t* sendData, size_t sendLen) { +ReturnValue_t SerialComIF::sendMessage(CookieIF* cookie, const uint8_t* sendData, size_t sendLen) { int fd = 0; std::string deviceFile; - UartDeviceMapIter uartDeviceMapIter; if (sendLen == 0) { return returnvalue::OK; @@ -348,7 +196,7 @@ ReturnValue_t UartComIF::sendMessage(CookieIF* cookie, const uint8_t* sendData, } deviceFile = uartCookie->getDeviceFile(); - uartDeviceMapIter = uartDeviceMap.find(deviceFile); + auto uartDeviceMapIter = uartDeviceMap.find(deviceFile); if (uartDeviceMapIter == uartDeviceMap.end()) { #if FSFW_CPP_OSTREAM_ENABLED == 1 sif::debug << "UartComIF::sendMessage: Device file " << deviceFile << "not in UART map" @@ -370,11 +218,10 @@ ReturnValue_t UartComIF::sendMessage(CookieIF* cookie, const uint8_t* sendData, return returnvalue::OK; } -ReturnValue_t UartComIF::getSendSuccess(CookieIF* cookie) { return returnvalue::OK; } +ReturnValue_t SerialComIF::getSendSuccess(CookieIF* cookie) { return returnvalue::OK; } -ReturnValue_t UartComIF::requestReceiveMessage(CookieIF* cookie, size_t requestLen) { +ReturnValue_t SerialComIF::requestReceiveMessage(CookieIF* cookie, size_t requestLen) { std::string deviceFile; - UartDeviceMapIter uartDeviceMapIter; UartCookie* uartCookie = dynamic_cast(cookie); if (uartCookie == nullptr) { @@ -386,7 +233,7 @@ ReturnValue_t UartComIF::requestReceiveMessage(CookieIF* cookie, size_t requestL UartModes uartMode = uartCookie->getUartMode(); deviceFile = uartCookie->getDeviceFile(); - uartDeviceMapIter = uartDeviceMap.find(deviceFile); + auto uartDeviceMapIter = uartDeviceMap.find(deviceFile); if (uartMode == UartModes::NON_CANONICAL and requestLen == 0) { return returnvalue::OK; @@ -409,8 +256,8 @@ ReturnValue_t UartComIF::requestReceiveMessage(CookieIF* cookie, size_t requestL } } -ReturnValue_t UartComIF::handleCanonicalRead(UartCookie& uartCookie, UartDeviceMapIter& iter, - size_t requestLen) { +ReturnValue_t SerialComIF::handleCanonicalRead(UartCookie& uartCookie, + UartDeviceMap::iterator& iter, size_t requestLen) { ReturnValue_t result = returnvalue::OK; uint8_t maxReadCycles = uartCookie.getReadCycles(); uint8_t currentReadCycles = 0; @@ -467,8 +314,9 @@ ReturnValue_t UartComIF::handleCanonicalRead(UartCookie& uartCookie, UartDeviceM return result; } -ReturnValue_t UartComIF::handleNoncanonicalRead(UartCookie& uartCookie, UartDeviceMapIter& iter, - size_t requestLen) { +ReturnValue_t SerialComIF::handleNoncanonicalRead(UartCookie& uartCookie, + UartDeviceMap::iterator& iter, + size_t requestLen) { int fd = iter->second.fileDescriptor; auto bufferPtr = iter->second.replyBuffer.data(); // Size check to prevent buffer overflow @@ -501,9 +349,8 @@ ReturnValue_t UartComIF::handleNoncanonicalRead(UartCookie& uartCookie, UartDevi return returnvalue::OK; } -ReturnValue_t UartComIF::readReceivedMessage(CookieIF* cookie, uint8_t** buffer, size_t* size) { +ReturnValue_t SerialComIF::readReceivedMessage(CookieIF* cookie, uint8_t** buffer, size_t* size) { std::string deviceFile; - UartDeviceMapIter uartDeviceMapIter; UartCookie* uartCookie = dynamic_cast(cookie); if (uartCookie == nullptr) { @@ -514,7 +361,7 @@ ReturnValue_t UartComIF::readReceivedMessage(CookieIF* cookie, uint8_t** buffer, } deviceFile = uartCookie->getDeviceFile(); - uartDeviceMapIter = uartDeviceMap.find(deviceFile); + auto uartDeviceMapIter = uartDeviceMap.find(deviceFile); if (uartDeviceMapIter == uartDeviceMap.end()) { #if FSFW_CPP_OSTREAM_ENABLED == 1 sif::debug << "UartComIF::readReceivedMessage: Device file " << deviceFile << " not in uart map" @@ -532,9 +379,8 @@ ReturnValue_t UartComIF::readReceivedMessage(CookieIF* cookie, uint8_t** buffer, return returnvalue::OK; } -ReturnValue_t UartComIF::flushUartRxBuffer(CookieIF* cookie) { +ReturnValue_t SerialComIF::flushUartRxBuffer(CookieIF* cookie) { std::string deviceFile; - UartDeviceMapIter uartDeviceMapIter; UartCookie* uartCookie = dynamic_cast(cookie); if (uartCookie == nullptr) { #if FSFW_CPP_OSTREAM_ENABLED == 1 @@ -543,7 +389,7 @@ ReturnValue_t UartComIF::flushUartRxBuffer(CookieIF* cookie) { return NULLPOINTER; } deviceFile = uartCookie->getDeviceFile(); - uartDeviceMapIter = uartDeviceMap.find(deviceFile); + auto uartDeviceMapIter = uartDeviceMap.find(deviceFile); if (uartDeviceMapIter != uartDeviceMap.end()) { int fd = uartDeviceMapIter->second.fileDescriptor; tcflush(fd, TCIFLUSH); @@ -552,9 +398,8 @@ ReturnValue_t UartComIF::flushUartRxBuffer(CookieIF* cookie) { return returnvalue::FAILED; } -ReturnValue_t UartComIF::flushUartTxBuffer(CookieIF* cookie) { +ReturnValue_t SerialComIF::flushUartTxBuffer(CookieIF* cookie) { std::string deviceFile; - UartDeviceMapIter uartDeviceMapIter; UartCookie* uartCookie = dynamic_cast(cookie); if (uartCookie == nullptr) { #if FSFW_CPP_OSTREAM_ENABLED == 1 @@ -563,7 +408,7 @@ ReturnValue_t UartComIF::flushUartTxBuffer(CookieIF* cookie) { return NULLPOINTER; } deviceFile = uartCookie->getDeviceFile(); - uartDeviceMapIter = uartDeviceMap.find(deviceFile); + auto uartDeviceMapIter = uartDeviceMap.find(deviceFile); if (uartDeviceMapIter != uartDeviceMap.end()) { int fd = uartDeviceMapIter->second.fileDescriptor; tcflush(fd, TCOFLUSH); @@ -572,9 +417,8 @@ ReturnValue_t UartComIF::flushUartTxBuffer(CookieIF* cookie) { return returnvalue::FAILED; } -ReturnValue_t UartComIF::flushUartTxAndRxBuf(CookieIF* cookie) { +ReturnValue_t SerialComIF::flushUartTxAndRxBuf(CookieIF* cookie) { std::string deviceFile; - UartDeviceMapIter uartDeviceMapIter; UartCookie* uartCookie = dynamic_cast(cookie); if (uartCookie == nullptr) { #if FSFW_CPP_OSTREAM_ENABLED == 1 @@ -583,7 +427,7 @@ ReturnValue_t UartComIF::flushUartTxAndRxBuf(CookieIF* cookie) { return NULLPOINTER; } deviceFile = uartCookie->getDeviceFile(); - uartDeviceMapIter = uartDeviceMap.find(deviceFile); + auto uartDeviceMapIter = uartDeviceMap.find(deviceFile); if (uartDeviceMapIter != uartDeviceMap.end()) { int fd = uartDeviceMapIter->second.fileDescriptor; tcflush(fd, TCIOFLUSH); @@ -591,13 +435,3 @@ ReturnValue_t UartComIF::flushUartTxAndRxBuf(CookieIF* cookie) { } return returnvalue::FAILED; } - -void UartComIF::setUartMode(struct termios* options, UartCookie& uartCookie) { - UartModes uartMode = uartCookie.getUartMode(); - if (uartMode == UartModes::NON_CANONICAL) { - /* Disable canonical mode */ - options->c_lflag &= ~ICANON; - } else if (uartMode == UartModes::CANONICAL) { - options->c_lflag |= ICANON; - } -} diff --git a/src/fsfw_hal/linux/uart/UartComIF.h b/src/fsfw_hal/linux/serial/SerialComIF.h similarity index 77% rename from src/fsfw_hal/linux/uart/UartComIF.h rename to src/fsfw_hal/linux/serial/SerialComIF.h index 77318166..4953884a 100644 --- a/src/fsfw_hal/linux/uart/UartComIF.h +++ b/src/fsfw_hal/linux/serial/SerialComIF.h @@ -3,12 +3,12 @@ #include #include +#include +#include #include #include -#include "UartCookie.h" - /** * @brief This is the communication interface to access serial ports on linux based operating * systems. @@ -18,7 +18,7 @@ * * @author J. Meier */ -class UartComIF : public DeviceCommunicationIF, public SystemObject { +class SerialComIF : public DeviceCommunicationIF, public SystemObject { public: static constexpr uint8_t uartRetvalId = CLASS_ID::HAL_UART; @@ -26,9 +26,9 @@ class UartComIF : public DeviceCommunicationIF, public SystemObject { static constexpr ReturnValue_t UART_READ_SIZE_MISSMATCH = returnvalue::makeCode(uartRetvalId, 2); static constexpr ReturnValue_t UART_RX_BUFFER_TOO_SMALL = returnvalue::makeCode(uartRetvalId, 3); - UartComIF(object_id_t objectId); + SerialComIF(object_id_t objectId); - virtual ~UartComIF(); + virtual ~SerialComIF(); ReturnValue_t initializeInterface(CookieIF* cookie) override; ReturnValue_t sendMessage(CookieIF* cookie, const uint8_t* sendData, size_t sendLen) override; @@ -62,7 +62,6 @@ class UartComIF : public DeviceCommunicationIF, public SystemObject { }; using UartDeviceMap = std::unordered_map; - using UartDeviceMapIter = UartDeviceMap::iterator; /** * The uart devie map stores informations of initialized uart ports. @@ -78,17 +77,6 @@ class UartComIF : public DeviceCommunicationIF, public SystemObject { */ int configureUartPort(UartCookie* uartCookie); - /** - * @brief This function adds the parity settings to the termios options struct. - * - * @param options Pointer to termios options struct which will be modified to enable or disable - * parity checking. - * @param uartCookie Pointer to uart cookie containing the information about the desired - * parity settings. - * - */ - void setParityOptions(struct termios* options, UartCookie* uartCookie); - void setStopBitOptions(struct termios* options, UartCookie* uartCookie); /** @@ -101,17 +89,9 @@ class UartComIF : public DeviceCommunicationIF, public SystemObject { */ void setDatasizeOptions(struct termios* options, UartCookie* uartCookie); - /** - * @brief This functions adds the baudrate specified in the uartCookie to the termios options - * struct. - */ - void configureBaudrate(struct termios* options, UartCookie* uartCookie); - - void setUartMode(struct termios* options, UartCookie& uartCookie); - - ReturnValue_t handleCanonicalRead(UartCookie& uartCookie, UartDeviceMapIter& iter, + ReturnValue_t handleCanonicalRead(UartCookie& uartCookie, UartDeviceMap::iterator& iter, size_t requestLen); - ReturnValue_t handleNoncanonicalRead(UartCookie& uartCookie, UartDeviceMapIter& iter, + ReturnValue_t handleNoncanonicalRead(UartCookie& uartCookie, UartDeviceMap::iterator& iter, size_t requestLen); }; diff --git a/src/fsfw_hal/linux/uart/UartCookie.cpp b/src/fsfw_hal/linux/serial/SerialCookie.cpp similarity index 91% rename from src/fsfw_hal/linux/uart/UartCookie.cpp rename to src/fsfw_hal/linux/serial/SerialCookie.cpp index 3fedc9d4..733d84a5 100644 --- a/src/fsfw_hal/linux/uart/UartCookie.cpp +++ b/src/fsfw_hal/linux/serial/SerialCookie.cpp @@ -1,9 +1,8 @@ -#include "UartCookie.h" - #include +#include -UartCookie::UartCookie(object_id_t handlerId, std::string deviceFile, UartModes uartMode, - UartBaudRate baudrate, size_t maxReplyLen) +UartCookie::UartCookie(object_id_t handlerId, std::string deviceFile, UartBaudRate baudrate, + size_t maxReplyLen, UartModes uartMode) : handlerId(handlerId), deviceFile(deviceFile), uartMode(uartMode), diff --git a/src/fsfw_hal/linux/uart/UartCookie.h b/src/fsfw_hal/linux/serial/SerialCookie.h similarity index 81% rename from src/fsfw_hal/linux/uart/UartCookie.h rename to src/fsfw_hal/linux/serial/SerialCookie.h index 6840b352..8d0f5fb4 100644 --- a/src/fsfw_hal/linux/uart/UartCookie.h +++ b/src/fsfw_hal/linux/serial/SerialCookie.h @@ -3,50 +3,10 @@ #include #include +#include #include -enum class Parity { NONE, EVEN, ODD }; - -enum class StopBits { ONE_STOP_BIT, TWO_STOP_BITS }; - -enum class UartModes { CANONICAL, NON_CANONICAL }; - -enum class BitsPerWord { BITS_5, BITS_6, BITS_7, BITS_8 }; - -enum class UartBaudRate { - RATE_50, - RATE_75, - RATE_110, - RATE_134, - RATE_150, - RATE_200, - RATE_300, - RATE_600, - RATE_1200, - RATE_1800, - RATE_2400, - RATE_4800, - RATE_9600, - RATE_19200, - RATE_38400, - RATE_57600, - RATE_115200, - RATE_230400, - RATE_460800, - RATE_500000, - RATE_576000, - RATE_921600, - RATE_1000000, - RATE_1152000, - RATE_1500000, - RATE_2000000, - RATE_2500000, - RATE_3000000, - RATE_3500000, - RATE_4000000 -}; - /** * @brief Cookie for the UartComIF. There are many options available to configure the UART driver. * The constructor only requests for common options like the baudrate. Other options can @@ -69,8 +29,8 @@ class UartCookie : public CookieIF { * 8 databits (number of bits transfered with one uart frame) * One stop bit */ - UartCookie(object_id_t handlerId, std::string deviceFile, UartModes uartMode, - UartBaudRate baudrate, size_t maxReplyLen); + UartCookie(object_id_t handlerId, std::string deviceFile, UartBaudRate baudrate, + size_t maxReplyLen, UartModes uartMode = UartModes::NON_CANONICAL); virtual ~UartCookie(); diff --git a/src/fsfw_hal/linux/serial/helper.cpp b/src/fsfw_hal/linux/serial/helper.cpp new file mode 100644 index 00000000..ba975f2f --- /dev/null +++ b/src/fsfw_hal/linux/serial/helper.cpp @@ -0,0 +1,163 @@ +#include +#include + +#include "fsfw/serviceinterface.h" + +void uart::setMode(struct termios& options, UartModes mode) { + if (mode == UartModes::NON_CANONICAL) { + /* Disable canonical mode */ + options.c_lflag &= ~ICANON; + } else if (mode == UartModes::CANONICAL) { + options.c_lflag |= ICANON; + } +} + +void uart::setBaudrate(struct termios& options, UartBaudRate baud) { + switch (baud) { + case UartBaudRate::RATE_50: + cfsetspeed(&options, B50); + break; + case UartBaudRate::RATE_75: + cfsetspeed(&options, B75); + break; + case UartBaudRate::RATE_110: + cfsetspeed(&options, B110); + break; + case UartBaudRate::RATE_134: + cfsetspeed(&options, B134); + break; + case UartBaudRate::RATE_150: + cfsetspeed(&options, B150); + break; + case UartBaudRate::RATE_200: + cfsetspeed(&options, B200); + break; + case UartBaudRate::RATE_300: + cfsetspeed(&options, B300); + break; + case UartBaudRate::RATE_600: + cfsetspeed(&options, B600); + break; + case UartBaudRate::RATE_1200: + cfsetspeed(&options, B1200); + break; + case UartBaudRate::RATE_1800: + cfsetspeed(&options, B1800); + break; + case UartBaudRate::RATE_2400: + cfsetspeed(&options, B2400); + break; + case UartBaudRate::RATE_4800: + cfsetspeed(&options, B4800); + break; + case UartBaudRate::RATE_9600: + cfsetspeed(&options, B9600); + break; + case UartBaudRate::RATE_19200: + cfsetspeed(&options, B19200); + break; + case UartBaudRate::RATE_38400: + cfsetspeed(&options, B38400); + break; + case UartBaudRate::RATE_57600: + cfsetspeed(&options, B57600); + break; + case UartBaudRate::RATE_115200: + cfsetspeed(&options, B115200); + break; + case UartBaudRate::RATE_230400: + cfsetspeed(&options, B230400); + break; +#ifndef __APPLE__ + case UartBaudRate::RATE_460800: + cfsetspeed(&options, B460800); + break; + case UartBaudRate::RATE_500000: + cfsetspeed(&options, B500000); + break; + case UartBaudRate::RATE_576000: + cfsetspeed(&options, B576000); + break; + case UartBaudRate::RATE_921600: + cfsetspeed(&options, B921600); + break; + case UartBaudRate::RATE_1000000: + cfsetspeed(&options, B1000000); + break; + case UartBaudRate::RATE_1152000: + cfsetspeed(&options, B1152000); + break; + case UartBaudRate::RATE_1500000: + cfsetspeed(&options, B1500000); + break; + case UartBaudRate::RATE_2000000: + cfsetspeed(&options, B2000000); + break; + case UartBaudRate::RATE_2500000: + cfsetspeed(&options, B2500000); + break; + case UartBaudRate::RATE_3000000: + cfsetspeed(&options, B3000000); + break; + case UartBaudRate::RATE_3500000: + cfsetspeed(&options, B3500000); + break; + case UartBaudRate::RATE_4000000: + cfsetspeed(&options, B4000000); + break; +#endif // ! __APPLE__ + default: +#if FSFW_CPP_OSTREAM_ENABLED == 1 + sif::warning << "UartComIF::configureBaudrate: Baudrate not supported" << std::endl; +#endif + break; + } +} + +void uart::setBitsPerWord(struct termios& options, BitsPerWord bits) { + options.c_cflag &= ~CSIZE; // Clear all the size bits + if (bits == BitsPerWord::BITS_5) { + options.c_cflag |= CS5; + } else if (bits == BitsPerWord::BITS_6) { + options.c_cflag |= CS6; + } else if (bits == BitsPerWord::BITS_7) { + options.c_cflag |= CS7; + } else if (bits == BitsPerWord::BITS_8) { + options.c_cflag |= CS8; + } +} + +void uart::enableRead(struct termios& options) { options.c_cflag |= CREAD; } + +void uart::ignoreCtrlLines(struct termios& options) { options.c_cflag |= CLOCAL; } + +void uart::setParity(struct termios& options, Parity parity) { + /* Clear parity bit */ + options.c_cflag &= ~PARENB; + switch (parity) { + case Parity::EVEN: + options.c_cflag |= PARENB; + options.c_cflag &= ~PARODD; + break; + case Parity::ODD: + options.c_cflag |= PARENB; + options.c_cflag |= PARODD; + break; + default: + break; + } +} + +int uart::readCountersAndErrors(int serialPort, serial_icounter_struct& icounter) { + return ioctl(serialPort, TIOCGICOUNT, &icounter); +} + +void uart::setStopbits(struct termios& options, StopBits bits) { + if (bits == StopBits::TWO_STOP_BITS) { + // Use two stop bits + options.c_cflag |= CSTOPB; + } else { + // Clear stop field, only one stop bit used in communication + options.c_cflag &= ~CSTOPB; + } +} diff --git a/src/fsfw_hal/linux/serial/helper.h b/src/fsfw_hal/linux/serial/helper.h new file mode 100644 index 00000000..7f067d00 --- /dev/null +++ b/src/fsfw_hal/linux/serial/helper.h @@ -0,0 +1,71 @@ +#ifndef FSFW_HAL_LINUX_UART_HELPER_H_ +#define FSFW_HAL_LINUX_UART_HELPER_H_ + +#include +#include + +enum class Parity { NONE, EVEN, ODD }; + +enum class StopBits { ONE_STOP_BIT, TWO_STOP_BITS }; + +enum class UartModes { CANONICAL, NON_CANONICAL }; + +enum class BitsPerWord { BITS_5, BITS_6, BITS_7, BITS_8 }; + +enum class UartBaudRate { + RATE_50, + RATE_75, + RATE_110, + RATE_134, + RATE_150, + RATE_200, + RATE_300, + RATE_600, + RATE_1200, + RATE_1800, + RATE_2400, + RATE_4800, + RATE_9600, + RATE_19200, + RATE_38400, + RATE_57600, + RATE_115200, + RATE_230400, + RATE_460800, + RATE_500000, + RATE_576000, + RATE_921600, + RATE_1000000, + RATE_1152000, + RATE_1500000, + RATE_2000000, + RATE_2500000, + RATE_3000000, + RATE_3500000, + RATE_4000000 +}; + +namespace uart { + +void setMode(struct termios& options, UartModes mode); +/** + * @brief This functions adds the baudrate specified in the uartCookie to the termios options + * struct. + */ +void setBaudrate(struct termios& options, UartBaudRate baud); + +void setStopbits(struct termios& options, StopBits bits); + +void setBitsPerWord(struct termios& options, BitsPerWord bits); + +void enableRead(struct termios& options); + +void setParity(struct termios& options, Parity parity); + +void ignoreCtrlLines(struct termios& options); + +int readCountersAndErrors(int serialPort, serial_icounter_struct& icounter); + +} // namespace uart + +#endif /* FSFW_HAL_LINUX_UART_HELPER_H_ */ diff --git a/src/fsfw_hal/linux/uart/CMakeLists.txt b/src/fsfw_hal/linux/uart/CMakeLists.txt deleted file mode 100644 index 9cad62a4..00000000 --- a/src/fsfw_hal/linux/uart/CMakeLists.txt +++ /dev/null @@ -1 +0,0 @@ -target_sources(${LIB_FSFW_NAME} PUBLIC UartComIF.cpp UartCookie.cpp) From 5b352978c5b4fe99f6db7fae5f96c3a462032bb1 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Fri, 11 Nov 2022 11:33:35 +0100 Subject: [PATCH 144/169] rename cookie class --- src/fsfw_hal/linux/serial/SerialComIF.cpp | 24 ++++++------- src/fsfw_hal/linux/serial/SerialComIF.h | 10 +++--- src/fsfw_hal/linux/serial/SerialCookie.cpp | 42 +++++++++++----------- src/fsfw_hal/linux/serial/SerialCookie.h | 6 ++-- 4 files changed, 41 insertions(+), 41 deletions(-) diff --git a/src/fsfw_hal/linux/serial/SerialComIF.cpp b/src/fsfw_hal/linux/serial/SerialComIF.cpp index 0fd293a0..a421326b 100644 --- a/src/fsfw_hal/linux/serial/SerialComIF.cpp +++ b/src/fsfw_hal/linux/serial/SerialComIF.cpp @@ -21,7 +21,7 @@ ReturnValue_t SerialComIF::initializeInterface(CookieIF* cookie) { return NULLPOINTER; } - UartCookie* uartCookie = dynamic_cast(cookie); + SerialCookie* uartCookie = dynamic_cast(cookie); if (uartCookie == nullptr) { #if FSFW_CPP_OSTREAM_ENABLED == 1 sif::error << "UartComIF::initializeInterface: Invalid UART Cookie!" << std::endl; @@ -58,7 +58,7 @@ ReturnValue_t SerialComIF::initializeInterface(CookieIF* cookie) { return returnvalue::OK; } -int SerialComIF::configureUartPort(UartCookie* uartCookie) { +int SerialComIF::configureUartPort(SerialCookie* uartCookie) { struct termios options = {}; std::string deviceFile = uartCookie->getDeviceFile(); @@ -113,7 +113,7 @@ int SerialComIF::configureUartPort(UartCookie* uartCookie) { return fd; } -void SerialComIF::setStopBitOptions(struct termios* options, UartCookie* uartCookie) { +void SerialComIF::setStopBitOptions(struct termios* options, SerialCookie* uartCookie) { /* Clear stop field. Sets stop bit to one bit */ options->c_cflag &= ~CSTOPB; switch (uartCookie->getStopBits()) { @@ -125,7 +125,7 @@ void SerialComIF::setStopBitOptions(struct termios* options, UartCookie* uartCoo } } -void SerialComIF::setDatasizeOptions(struct termios* options, UartCookie* uartCookie) { +void SerialComIF::setDatasizeOptions(struct termios* options, SerialCookie* uartCookie) { /* Clear size bits */ options->c_cflag &= ~CSIZE; switch (uartCookie->getBitsPerWord()) { @@ -187,7 +187,7 @@ ReturnValue_t SerialComIF::sendMessage(CookieIF* cookie, const uint8_t* sendData return returnvalue::FAILED; } - UartCookie* uartCookie = dynamic_cast(cookie); + SerialCookie* uartCookie = dynamic_cast(cookie); if (uartCookie == nullptr) { #if FSFW_CPP_OSTREAM_ENABLED == 1 sif::warning << "UartComIF::sendMessasge: Invalid UART Cookie!" << std::endl; @@ -223,7 +223,7 @@ ReturnValue_t SerialComIF::getSendSuccess(CookieIF* cookie) { return returnvalue ReturnValue_t SerialComIF::requestReceiveMessage(CookieIF* cookie, size_t requestLen) { std::string deviceFile; - UartCookie* uartCookie = dynamic_cast(cookie); + SerialCookie* uartCookie = dynamic_cast(cookie); if (uartCookie == nullptr) { #if FSFW_CPP_OSTREAM_ENABLED == 1 sif::debug << "UartComIF::requestReceiveMessage: Invalid Uart Cookie!" << std::endl; @@ -256,7 +256,7 @@ ReturnValue_t SerialComIF::requestReceiveMessage(CookieIF* cookie, size_t reques } } -ReturnValue_t SerialComIF::handleCanonicalRead(UartCookie& uartCookie, +ReturnValue_t SerialComIF::handleCanonicalRead(SerialCookie& uartCookie, UartDeviceMap::iterator& iter, size_t requestLen) { ReturnValue_t result = returnvalue::OK; uint8_t maxReadCycles = uartCookie.getReadCycles(); @@ -314,7 +314,7 @@ ReturnValue_t SerialComIF::handleCanonicalRead(UartCookie& uartCookie, return result; } -ReturnValue_t SerialComIF::handleNoncanonicalRead(UartCookie& uartCookie, +ReturnValue_t SerialComIF::handleNoncanonicalRead(SerialCookie& uartCookie, UartDeviceMap::iterator& iter, size_t requestLen) { int fd = iter->second.fileDescriptor; @@ -352,7 +352,7 @@ ReturnValue_t SerialComIF::handleNoncanonicalRead(UartCookie& uartCookie, ReturnValue_t SerialComIF::readReceivedMessage(CookieIF* cookie, uint8_t** buffer, size_t* size) { std::string deviceFile; - UartCookie* uartCookie = dynamic_cast(cookie); + SerialCookie* uartCookie = dynamic_cast(cookie); if (uartCookie == nullptr) { #if FSFW_CPP_OSTREAM_ENABLED == 1 sif::debug << "UartComIF::readReceivedMessage: Invalid uart cookie!" << std::endl; @@ -381,7 +381,7 @@ ReturnValue_t SerialComIF::readReceivedMessage(CookieIF* cookie, uint8_t** buffe ReturnValue_t SerialComIF::flushUartRxBuffer(CookieIF* cookie) { std::string deviceFile; - UartCookie* uartCookie = dynamic_cast(cookie); + SerialCookie* uartCookie = dynamic_cast(cookie); if (uartCookie == nullptr) { #if FSFW_CPP_OSTREAM_ENABLED == 1 sif::warning << "UartComIF::flushUartRxBuffer: Invalid uart cookie!" << std::endl; @@ -400,7 +400,7 @@ ReturnValue_t SerialComIF::flushUartRxBuffer(CookieIF* cookie) { ReturnValue_t SerialComIF::flushUartTxBuffer(CookieIF* cookie) { std::string deviceFile; - UartCookie* uartCookie = dynamic_cast(cookie); + SerialCookie* uartCookie = dynamic_cast(cookie); if (uartCookie == nullptr) { #if FSFW_CPP_OSTREAM_ENABLED == 1 sif::warning << "UartComIF::flushUartTxBuffer: Invalid uart cookie!" << std::endl; @@ -419,7 +419,7 @@ ReturnValue_t SerialComIF::flushUartTxBuffer(CookieIF* cookie) { ReturnValue_t SerialComIF::flushUartTxAndRxBuf(CookieIF* cookie) { std::string deviceFile; - UartCookie* uartCookie = dynamic_cast(cookie); + SerialCookie* uartCookie = dynamic_cast(cookie); if (uartCookie == nullptr) { #if FSFW_CPP_OSTREAM_ENABLED == 1 sif::warning << "UartComIF::flushUartTxAndRxBuf: Invalid uart cookie!" << std::endl; diff --git a/src/fsfw_hal/linux/serial/SerialComIF.h b/src/fsfw_hal/linux/serial/SerialComIF.h index 4953884a..907da7e0 100644 --- a/src/fsfw_hal/linux/serial/SerialComIF.h +++ b/src/fsfw_hal/linux/serial/SerialComIF.h @@ -75,9 +75,9 @@ class SerialComIF : public DeviceCommunicationIF, public SystemObject { * uart device file, baudrate, parity, stopbits etc. * @return The file descriptor of the configured uart. */ - int configureUartPort(UartCookie* uartCookie); + int configureUartPort(SerialCookie* uartCookie); - void setStopBitOptions(struct termios* options, UartCookie* uartCookie); + void setStopBitOptions(struct termios* options, SerialCookie* uartCookie); /** * @brief This function sets options which are not configurable by the uartCookie. @@ -87,11 +87,11 @@ class SerialComIF : public DeviceCommunicationIF, public SystemObject { /** * @brief With this function the datasize settings are added to the termios options struct. */ - void setDatasizeOptions(struct termios* options, UartCookie* uartCookie); + void setDatasizeOptions(struct termios* options, SerialCookie* uartCookie); - ReturnValue_t handleCanonicalRead(UartCookie& uartCookie, UartDeviceMap::iterator& iter, + ReturnValue_t handleCanonicalRead(SerialCookie& uartCookie, UartDeviceMap::iterator& iter, size_t requestLen); - ReturnValue_t handleNoncanonicalRead(UartCookie& uartCookie, UartDeviceMap::iterator& iter, + ReturnValue_t handleNoncanonicalRead(SerialCookie& uartCookie, UartDeviceMap::iterator& iter, size_t requestLen); }; diff --git a/src/fsfw_hal/linux/serial/SerialCookie.cpp b/src/fsfw_hal/linux/serial/SerialCookie.cpp index 733d84a5..0e2260a5 100644 --- a/src/fsfw_hal/linux/serial/SerialCookie.cpp +++ b/src/fsfw_hal/linux/serial/SerialCookie.cpp @@ -1,7 +1,7 @@ #include #include -UartCookie::UartCookie(object_id_t handlerId, std::string deviceFile, UartBaudRate baudrate, +SerialCookie::SerialCookie(object_id_t handlerId, std::string deviceFile, UartBaudRate baudrate, size_t maxReplyLen, UartModes uartMode) : handlerId(handlerId), deviceFile(deviceFile), @@ -9,42 +9,42 @@ UartCookie::UartCookie(object_id_t handlerId, std::string deviceFile, UartBaudRa baudrate(baudrate), maxReplyLen(maxReplyLen) {} -UartCookie::~UartCookie() {} +SerialCookie::~SerialCookie() {} -UartBaudRate UartCookie::getBaudrate() const { return baudrate; } +UartBaudRate SerialCookie::getBaudrate() const { return baudrate; } -size_t UartCookie::getMaxReplyLen() const { return maxReplyLen; } +size_t SerialCookie::getMaxReplyLen() const { return maxReplyLen; } -std::string UartCookie::getDeviceFile() const { return deviceFile; } +std::string SerialCookie::getDeviceFile() const { return deviceFile; } -void UartCookie::setParityOdd() { parity = Parity::ODD; } +void SerialCookie::setParityOdd() { parity = Parity::ODD; } -void UartCookie::setParityEven() { parity = Parity::EVEN; } +void SerialCookie::setParityEven() { parity = Parity::EVEN; } -Parity UartCookie::getParity() const { return parity; } +Parity SerialCookie::getParity() const { return parity; } -void UartCookie::setBitsPerWord(BitsPerWord bitsPerWord_) { bitsPerWord = bitsPerWord_; } +void SerialCookie::setBitsPerWord(BitsPerWord bitsPerWord_) { bitsPerWord = bitsPerWord_; } -BitsPerWord UartCookie::getBitsPerWord() const { return bitsPerWord; } +BitsPerWord SerialCookie::getBitsPerWord() const { return bitsPerWord; } -StopBits UartCookie::getStopBits() const { return stopBits; } +StopBits SerialCookie::getStopBits() const { return stopBits; } -void UartCookie::setTwoStopBits() { stopBits = StopBits::TWO_STOP_BITS; } +void SerialCookie::setTwoStopBits() { stopBits = StopBits::TWO_STOP_BITS; } -void UartCookie::setOneStopBit() { stopBits = StopBits::ONE_STOP_BIT; } +void SerialCookie::setOneStopBit() { stopBits = StopBits::ONE_STOP_BIT; } -UartModes UartCookie::getUartMode() const { return uartMode; } +UartModes SerialCookie::getUartMode() const { return uartMode; } -void UartCookie::setReadCycles(uint8_t readCycles) { this->readCycles = readCycles; } +void SerialCookie::setReadCycles(uint8_t readCycles) { this->readCycles = readCycles; } -void UartCookie::setToFlushInput(bool enable) { this->flushInput = enable; } +void SerialCookie::setToFlushInput(bool enable) { this->flushInput = enable; } -uint8_t UartCookie::getReadCycles() const { return readCycles; } +uint8_t SerialCookie::getReadCycles() const { return readCycles; } -bool UartCookie::getInputShouldBeFlushed() { return this->flushInput; } +bool SerialCookie::getInputShouldBeFlushed() { return this->flushInput; } -object_id_t UartCookie::getHandlerId() const { return this->handlerId; } +object_id_t SerialCookie::getHandlerId() const { return this->handlerId; } -void UartCookie::setNoFixedSizeReply() { replySizeFixed = false; } +void SerialCookie::setNoFixedSizeReply() { replySizeFixed = false; } -bool UartCookie::isReplySizeFixed() { return replySizeFixed; } +bool SerialCookie::isReplySizeFixed() { return replySizeFixed; } diff --git a/src/fsfw_hal/linux/serial/SerialCookie.h b/src/fsfw_hal/linux/serial/SerialCookie.h index 8d0f5fb4..3916e4ca 100644 --- a/src/fsfw_hal/linux/serial/SerialCookie.h +++ b/src/fsfw_hal/linux/serial/SerialCookie.h @@ -14,7 +14,7 @@ * * @author J. Meier */ -class UartCookie : public CookieIF { +class SerialCookie : public CookieIF { public: /** * @brief Constructor for the uart cookie. @@ -29,10 +29,10 @@ class UartCookie : public CookieIF { * 8 databits (number of bits transfered with one uart frame) * One stop bit */ - UartCookie(object_id_t handlerId, std::string deviceFile, UartBaudRate baudrate, + SerialCookie(object_id_t handlerId, std::string deviceFile, UartBaudRate baudrate, size_t maxReplyLen, UartModes uartMode = UartModes::NON_CANONICAL); - virtual ~UartCookie(); + virtual ~SerialCookie(); UartBaudRate getBaudrate() const; size_t getMaxReplyLen() const; From b6a3c206cc80846fc3afec1212c1c86710f697f8 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Fri, 11 Nov 2022 11:34:58 +0100 Subject: [PATCH 145/169] smaller include tweaks --- src/fsfw_hal/linux/serial/SerialComIF.cpp | 3 ++- src/fsfw_hal/linux/serial/SerialCookie.cpp | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/fsfw_hal/linux/serial/SerialComIF.cpp b/src/fsfw_hal/linux/serial/SerialComIF.cpp index a421326b..177d74e4 100644 --- a/src/fsfw_hal/linux/serial/SerialComIF.cpp +++ b/src/fsfw_hal/linux/serial/SerialComIF.cpp @@ -1,6 +1,7 @@ +#include "SerialComIF.h" + #include #include -#include #include #include diff --git a/src/fsfw_hal/linux/serial/SerialCookie.cpp b/src/fsfw_hal/linux/serial/SerialCookie.cpp index 0e2260a5..e85d339d 100644 --- a/src/fsfw_hal/linux/serial/SerialCookie.cpp +++ b/src/fsfw_hal/linux/serial/SerialCookie.cpp @@ -1,5 +1,6 @@ +#include "SerialCookie.h" + #include -#include SerialCookie::SerialCookie(object_id_t handlerId, std::string deviceFile, UartBaudRate baudrate, size_t maxReplyLen, UartModes uartMode) From a9c6c088f25adf1b4b8fca1736276e5e5fe227ba Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Mon, 14 Nov 2022 14:08:38 +0100 Subject: [PATCH 146/169] remove leftover debugging code --- src/fsfw/globalfunctions/timevalOperations.cpp | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/src/fsfw/globalfunctions/timevalOperations.cpp b/src/fsfw/globalfunctions/timevalOperations.cpp index f9f0a5c6..79c07eaf 100644 --- a/src/fsfw/globalfunctions/timevalOperations.cpp +++ b/src/fsfw/globalfunctions/timevalOperations.cpp @@ -1,12 +1,9 @@ #include "fsfw/globalfunctions/timevalOperations.h" -#include - timeval& operator+=(timeval& lhs, const timeval& rhs) { int64_t sum = static_cast(lhs.tv_sec) * 1000000. + lhs.tv_usec; sum += static_cast(rhs.tv_sec) * 1000000. + rhs.tv_usec; - int64_t tmp = sum / 1000000; - lhs.tv_sec = tmp; + lhs.tv_sec = sum / 1000000; lhs.tv_usec = sum - lhs.tv_sec * 1000000; return lhs; } From 83a6f0b5f8b80392c54c708358245c1afc95002f Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Mon, 14 Nov 2022 14:12:26 +0100 Subject: [PATCH 147/169] reenable setup function call --- CMakeLists.txt | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index df3757ea..e2572b20 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -340,9 +340,9 @@ if(FSFW_BUILD_TESTS) -ftest-coverage) if(WIN32) - #setup_target_for_coverage_gcovr_html( - # NAME ${FSFW_TEST_TGT}_coverage EXECUTABLE ${FSFW_TEST_TGT} - # DEPENDENCIES ${FSFW_TEST_TGT}) + setup_target_for_coverage_gcovr_html( + NAME ${FSFW_TEST_TGT}_coverage EXECUTABLE ${FSFW_TEST_TGT} + DEPENDENCIES ${FSFW_TEST_TGT}) else() setup_target_for_coverage_lcov( NAME ${FSFW_TEST_TGT}_coverage EXECUTABLE ${FSFW_TEST_TGT} From 1bea2344f68d8d86746dc5416133b8a630fbc6bc Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Mon, 14 Nov 2022 14:21:00 +0100 Subject: [PATCH 148/169] remove using declaraction --- src/fsfw/storagemanager/LocalPool.h | 1 - 1 file changed, 1 deletion(-) diff --git a/src/fsfw/storagemanager/LocalPool.h b/src/fsfw/storagemanager/LocalPool.h index bb88842b..f82acd54 100644 --- a/src/fsfw/storagemanager/LocalPool.h +++ b/src/fsfw/storagemanager/LocalPool.h @@ -131,7 +131,6 @@ class LocalPool : public SystemObject, public StorageManagerIF { // Using functions provided by StorageManagerIF requires either a fully qualified path // like for example localPool.StorageManagerIF::getFreeElement(...) or re-exporting // the fully qualified path with the using directive. - using StorageManagerIF::getFreeElement; using StorageManagerIF::getData; using StorageManagerIF::modifyData; From 72d7c4344561d1cb105d663f7c1c2a4d1dbacec3 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Mon, 14 Nov 2022 14:57:37 +0100 Subject: [PATCH 149/169] updates for storage manager mock --- unittests/mocks/StorageManagerMock.cpp | 8 ++++---- unittests/mocks/StorageManagerMock.h | 6 ++---- 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/unittests/mocks/StorageManagerMock.cpp b/unittests/mocks/StorageManagerMock.cpp index 5cd3a575..8a287cd1 100644 --- a/unittests/mocks/StorageManagerMock.cpp +++ b/unittests/mocks/StorageManagerMock.cpp @@ -1,11 +1,11 @@ #include "StorageManagerMock.h" ReturnValue_t StorageManagerMock::addData(store_address_t *storageId, const uint8_t *data, - size_t size, bool ignoreFault) { + size_t size) { if (nextAddDataCallFails.first) { return nextAddDataCallFails.second; } - return LocalPool::addData(storageId, data, size, ignoreFault); + return LocalPool::addData(storageId, data, size); } ReturnValue_t StorageManagerMock::deleteData(store_address_t packet_id) { if (nextDeleteDataCallFails.first) { @@ -36,11 +36,11 @@ ReturnValue_t StorageManagerMock::modifyData(store_address_t packet_id, uint8_t } ReturnValue_t StorageManagerMock::getFreeElement(store_address_t *storageId, size_t size, - uint8_t **p_data, bool ignoreFault) { + uint8_t **p_data) { if (nextFreeElementCallFails.first) { return nextFreeElementCallFails.second; } - return LocalPool::getFreeElement(storageId, size, p_data, ignoreFault); + return LocalPool::getFreeElement(storageId, size, p_data); } bool StorageManagerMock::hasDataAtId(store_address_t storeId) const { diff --git a/unittests/mocks/StorageManagerMock.h b/unittests/mocks/StorageManagerMock.h index a52e46db..a0a59a47 100644 --- a/unittests/mocks/StorageManagerMock.h +++ b/unittests/mocks/StorageManagerMock.h @@ -8,15 +8,13 @@ class StorageManagerMock : public LocalPool { public: StorageManagerMock(object_id_t setObjectId, const LocalPoolConfig &poolConfig); - ReturnValue_t addData(store_address_t *storageId, const uint8_t *data, size_t size, - bool ignoreFault) override; + ReturnValue_t addData(store_address_t *storageId, const uint8_t *data, size_t size) override; ReturnValue_t deleteData(store_address_t packet_id) override; ReturnValue_t deleteData(uint8_t *buffer, size_t size, store_address_t *storeId) override; ReturnValue_t getData(store_address_t packet_id, const uint8_t **packet_ptr, size_t *size) override; ReturnValue_t modifyData(store_address_t packet_id, uint8_t **packet_ptr, size_t *size) override; - ReturnValue_t getFreeElement(store_address_t *storageId, size_t size, uint8_t **p_data, - bool ignoreFault) override; + ReturnValue_t getFreeElement(store_address_t *storageId, size_t size, uint8_t **p_data) override; [[nodiscard]] bool hasDataAtId(store_address_t storeId) const override; void clearStore() override; void clearSubPool(uint8_t poolIndex) override; From c013fcc1f5b257f7de6fc57668b6cfdc6fd183d7 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Tue, 15 Nov 2022 10:01:37 +0100 Subject: [PATCH 150/169] move container retvals to namespace --- src/fsfw/container/ArrayList.h | 6 ++---- src/fsfw/container/FixedMap.h | 17 ++++++----------- src/fsfw/container/definitions.h | 14 ++++++++++++++ unittests/container/TestArrayList.cpp | 2 +- unittests/container/TestFixedArrayList.cpp | 2 +- unittests/container/TestFixedMap.cpp | 20 ++++++++++---------- 6 files changed, 34 insertions(+), 27 deletions(-) create mode 100644 src/fsfw/container/definitions.h diff --git a/src/fsfw/container/ArrayList.h b/src/fsfw/container/ArrayList.h index f5f74cf1..92834558 100644 --- a/src/fsfw/container/ArrayList.h +++ b/src/fsfw/container/ArrayList.h @@ -4,6 +4,7 @@ #include "../returnvalues/returnvalue.h" #include "../serialize/SerializeAdapter.h" #include "../serialize/SerializeIF.h" +#include "definitions.h" /** * @brief A List that stores its values in an array. @@ -19,9 +20,6 @@ class ArrayList { friend class SerialArrayListAdapter; public: - static const uint8_t INTERFACE_ID = CLASS_ID::ARRAY_LIST; - static const ReturnValue_t FULL = MAKE_RETURN_CODE(0x01); - /** * This is the allocating constructor. * It allocates an array of the specified size. @@ -187,7 +185,7 @@ class ArrayList { */ ReturnValue_t insert(T entry) { if (size >= maxSize_) { - return FULL; + return containers::LIST_FULL; } entries[size] = entry; ++size; diff --git a/src/fsfw/container/FixedMap.h b/src/fsfw/container/FixedMap.h index def219d1..ce90d814 100644 --- a/src/fsfw/container/FixedMap.h +++ b/src/fsfw/container/FixedMap.h @@ -4,8 +4,8 @@ #include #include -#include "../returnvalues/returnvalue.h" #include "ArrayList.h" +#include "definitions.h" /** * @brief Map implementation for maps with a pre-defined size. @@ -24,11 +24,6 @@ class FixedMap : public SerializeIF { "derived class from SerializeIF to be serialize-able"); public: - static const uint8_t INTERFACE_ID = CLASS_ID::FIXED_MAP; - static const ReturnValue_t KEY_ALREADY_EXISTS = MAKE_RETURN_CODE(0x01); - static const ReturnValue_t MAP_FULL = MAKE_RETURN_CODE(0x02); - static const ReturnValue_t KEY_DOES_NOT_EXIST = MAKE_RETURN_CODE(0x03); - private: static const key_t EMPTY_SLOT = -1; ArrayList, uint32_t> theMap; @@ -76,10 +71,10 @@ class FixedMap : public SerializeIF { ReturnValue_t insert(key_t key, T value, Iterator* storedValue = nullptr) { if (exists(key) == returnvalue::OK) { - return KEY_ALREADY_EXISTS; + return containers::KEY_ALREADY_EXISTS; } if (_size == theMap.maxSize()) { - return MAP_FULL; + return containers::MAP_FULL; } theMap[_size].first = key; theMap[_size].second = value; @@ -93,7 +88,7 @@ class FixedMap : public SerializeIF { ReturnValue_t insert(std::pair pair) { return insert(pair.first, pair.second); } ReturnValue_t exists(key_t key) const { - ReturnValue_t result = KEY_DOES_NOT_EXIST; + ReturnValue_t result = containers::KEY_DOES_NOT_EXIST; if (findIndex(key) < _size) { result = returnvalue::OK; } @@ -103,7 +98,7 @@ class FixedMap : public SerializeIF { ReturnValue_t erase(Iterator* iter) { uint32_t i; if ((i = findIndex((*iter).value->first)) >= _size) { - return KEY_DOES_NOT_EXIST; + return containers::KEY_DOES_NOT_EXIST; } theMap[i] = theMap[_size - 1]; --_size; @@ -114,7 +109,7 @@ class FixedMap : public SerializeIF { ReturnValue_t erase(key_t key) { uint32_t i; if ((i = findIndex(key)) >= _size) { - return KEY_DOES_NOT_EXIST; + return containers::KEY_DOES_NOT_EXIST; } theMap[i] = theMap[_size - 1]; --_size; diff --git a/src/fsfw/container/definitions.h b/src/fsfw/container/definitions.h new file mode 100644 index 00000000..b50ea45d --- /dev/null +++ b/src/fsfw/container/definitions.h @@ -0,0 +1,14 @@ +#ifndef FSFW_CONTAINER_DEFINITIONS_H_ +#define FSFW_CONTAINER_DEFINITIONS_H_ + +#include "fsfw/retval.h" + +namespace containers { +static const ReturnValue_t KEY_ALREADY_EXISTS = returnvalue::makeCode(CLASS_ID::FIXED_MAP, 0x01); +static const ReturnValue_t MAP_FULL = returnvalue::makeCode(CLASS_ID::FIXED_MAP, 0x02); +static const ReturnValue_t KEY_DOES_NOT_EXIST = returnvalue::makeCode(CLASS_ID::FIXED_MAP, 0x03); + +static const ReturnValue_t LIST_FULL = returnvalue::makeCode(CLASS_ID::ARRAY_LIST, 0x01); +} // namespace containers + +#endif /* FSFW_CONTAINER_DEFINITIONS_H_ */ diff --git a/unittests/container/TestArrayList.cpp b/unittests/container/TestArrayList.cpp index 69b08faa..0c327685 100644 --- a/unittests/container/TestArrayList.cpp +++ b/unittests/container/TestArrayList.cpp @@ -43,7 +43,7 @@ TEST_CASE("Array List", "[containers]") { for (auto i = 0; i < 20; i++) { REQUIRE(list.insert(i) == static_cast(returnvalue::OK)); } - REQUIRE(list.insert(20) == static_cast(ArrayList::FULL)); + REQUIRE(list.insert(20) == static_cast(containers::LIST_FULL)); ArrayList::Iterator it = list.begin(); REQUIRE((*it) == 0); it++; diff --git a/unittests/container/TestFixedArrayList.cpp b/unittests/container/TestFixedArrayList.cpp index 876d6792..f3131c64 100644 --- a/unittests/container/TestFixedArrayList.cpp +++ b/unittests/container/TestFixedArrayList.cpp @@ -31,7 +31,7 @@ TEST_CASE("FixedArrayList Tests", "[containers]") { for (auto i = 1; i < 260; i++) { REQUIRE(list.insert(i) == static_cast(returnvalue::OK)); } - REQUIRE(list.insert(260) == static_cast(ArrayList::FULL)); + REQUIRE(list.insert(260) == static_cast(containers::LIST_FULL)); list.clear(); REQUIRE(list.size == 0); } diff --git a/unittests/container/TestFixedMap.cpp b/unittests/container/TestFixedMap.cpp index 8bfe9fed..83ff975d 100644 --- a/unittests/container/TestFixedMap.cpp +++ b/unittests/container/TestFixedMap.cpp @@ -7,6 +7,8 @@ template class FixedMap; +using namespace returnvalue; + TEST_CASE("FixedMap Tests", "[containers]") { INFO("FixedMap Tests"); @@ -24,9 +26,9 @@ TEST_CASE("FixedMap Tests", "[containers]") { REQUIRE(map.find(i)->second == i + 1); REQUIRE(not map.empty()); } - REQUIRE(map.insert(0, 0) == static_cast(FixedMap::KEY_ALREADY_EXISTS)); - REQUIRE(map.insert(31, 0) == static_cast(FixedMap::MAP_FULL)); - REQUIRE(map.exists(31) == static_cast(FixedMap::KEY_DOES_NOT_EXIST)); + REQUIRE(map.insert(0, 0) == static_cast(containers::KEY_ALREADY_EXISTS)); + REQUIRE(map.insert(31, 0) == static_cast(containers::MAP_FULL)); + REQUIRE(map.exists(31) == static_cast(containers::KEY_DOES_NOT_EXIST)); REQUIRE(map.size() == 30); REQUIRE(map.full()); { @@ -34,15 +36,14 @@ TEST_CASE("FixedMap Tests", "[containers]") { REQUIRE(map.find(5, &ptr) == static_cast(returnvalue::OK)); REQUIRE(*ptr == 6); REQUIRE(*(map.findValue(6)) == 7); - REQUIRE(map.find(31, &ptr) == - static_cast(FixedMap::KEY_DOES_NOT_EXIST)); + REQUIRE(map.find(31, &ptr) == static_cast(containers::KEY_DOES_NOT_EXIST)); } REQUIRE(map.getSerializedSize() == (sizeof(uint32_t) + 30 * (sizeof(uint32_t) + sizeof(uint16_t)))); REQUIRE(map.erase(2) == static_cast(returnvalue::OK)); - REQUIRE(map.erase(31) == static_cast(FixedMap::KEY_DOES_NOT_EXIST)); - REQUIRE(map.exists(2) == static_cast(FixedMap::KEY_DOES_NOT_EXIST)); + REQUIRE(map.erase(31) == static_cast(containers::KEY_DOES_NOT_EXIST)); + REQUIRE(map.exists(2) == static_cast(containers::KEY_DOES_NOT_EXIST)); REQUIRE(map.size() == 29); for (auto element : map) { @@ -79,8 +80,7 @@ TEST_CASE("FixedMap Tests", "[containers]") { REQUIRE(map.insert(37, 38, nullptr) == static_cast(returnvalue::OK)); REQUIRE(map.find(37)->second == 38); REQUIRE(map.size() == 2); - REQUIRE(map.insert(37, 24, nullptr) == - static_cast(FixedMap::KEY_ALREADY_EXISTS)); + REQUIRE(map.insert(37, 24, nullptr) == static_cast(containers::KEY_ALREADY_EXISTS)); REQUIRE(map.find(37)->second != 24); REQUIRE(map.size() == 2); }; @@ -137,7 +137,7 @@ TEST_CASE("FixedMap Tests", "[containers]") { FixedMap::Iterator it; std::pair pair = std::make_pair(44, 43); it = FixedMap::Iterator(&pair); - REQUIRE(map.erase(&it) == static_cast(FixedMap::KEY_DOES_NOT_EXIST)); + REQUIRE(map.erase(&it) == static_cast(containers::KEY_DOES_NOT_EXIST)); REQUIRE(map.find(45) == map.end()); size_t toLargeMap = 100; const uint8_t* ptr = reinterpret_cast(&toLargeMap); From 2a842666d5e182d1491a40fafbc77405774f1f9a Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Tue, 15 Nov 2022 10:46:46 +0100 Subject: [PATCH 151/169] SP reader getPacketData is const now --- src/fsfw/tmtcpacket/ccsds/SpacePacketReader.cpp | 2 +- src/fsfw/tmtcpacket/ccsds/SpacePacketReader.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/fsfw/tmtcpacket/ccsds/SpacePacketReader.cpp b/src/fsfw/tmtcpacket/ccsds/SpacePacketReader.cpp index 605bbd21..262653c9 100644 --- a/src/fsfw/tmtcpacket/ccsds/SpacePacketReader.cpp +++ b/src/fsfw/tmtcpacket/ccsds/SpacePacketReader.cpp @@ -21,7 +21,7 @@ SpacePacketReader::~SpacePacketReader() = default; inline uint16_t SpacePacketReader::getPacketIdRaw() const { return ccsds::getPacketId(*spHeader); } -const uint8_t* SpacePacketReader::getPacketData() { return packetDataField; } +const uint8_t* SpacePacketReader::getPacketData() const { return packetDataField; } ReturnValue_t SpacePacketReader::setData(uint8_t* data, size_t maxSize_, void* args) { return setInternalFields(data, maxSize_); diff --git a/src/fsfw/tmtcpacket/ccsds/SpacePacketReader.h b/src/fsfw/tmtcpacket/ccsds/SpacePacketReader.h index ff22510c..61939217 100644 --- a/src/fsfw/tmtcpacket/ccsds/SpacePacketReader.h +++ b/src/fsfw/tmtcpacket/ccsds/SpacePacketReader.h @@ -71,7 +71,7 @@ class SpacePacketReader : public SpacePacketIF, // Helper methods: [[nodiscard]] ReturnValue_t checkSize() const; - const uint8_t* getPacketData(); + const uint8_t* getPacketData() const; ReturnValue_t setReadOnlyData(const uint8_t* data, size_t maxSize); From fe3d6bd4320ca12e53c11feb7448aa181b5f66a6 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Tue, 15 Nov 2022 10:56:46 +0100 Subject: [PATCH 152/169] uio able to resolve symlinks now --- src/fsfw_hal/linux/uio/UioMapper.cpp | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/src/fsfw_hal/linux/uio/UioMapper.cpp b/src/fsfw_hal/linux/uio/UioMapper.cpp index 3d7e5987..e34c209a 100644 --- a/src/fsfw_hal/linux/uio/UioMapper.cpp +++ b/src/fsfw_hal/linux/uio/UioMapper.cpp @@ -1,6 +1,7 @@ #include "UioMapper.h" #include +#include #include #include @@ -13,7 +14,23 @@ const char UioMapper::UIO_PATH_PREFIX[] = "/sys/class/uio/"; const char UioMapper::MAP_SUBSTR[] = "/maps/map"; const char UioMapper::SIZE_FILE_PATH[] = "/size"; -UioMapper::UioMapper(std::string uioFile, int mapNum) : uioFile(uioFile), mapNum(mapNum) {} +UioMapper::UioMapper(std::string uioFile, int mapNum) : mapNum(mapNum) { + struct stat buf; + lstat(uioFile.c_str(), &buf); + if (S_ISLNK(buf.st_mode)) { + char* res = realpath(uioFile.c_str(), nullptr); + if (res) { + this->uioFile = res; + } else { +#if FSFW_CPP_OSTREAM_ENABLED == 1 + sif::error << "Could not resolve real path of UIO file " << uioFile << std::endl; +#endif + } + free(res); + } else { + this->uioFile = std::move(uioFile); + } +} UioMapper::~UioMapper() {} @@ -22,7 +39,7 @@ ReturnValue_t UioMapper::getMappedAdress(uint32_t** address, Permissions permiss int fd = open(uioFile.c_str(), O_RDWR); if (fd < 1) { #if FSFW_CPP_OSTREAM_ENABLED == 1 - sif::error << "PtmeAxiConfig::initialize: Invalid UIO device file" << std::endl; + sif::error << "UioMapper::getMappedAdress: Invalid UIO device file " << uioFile << std::endl; #endif return returnvalue::FAILED; } From 9483c2809d2a8c573b56dafac2e820b016021178 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Tue, 15 Nov 2022 11:26:53 +0100 Subject: [PATCH 153/169] DLE parser --- src/fsfw/globalfunctions/CMakeLists.txt | 1 + src/fsfw/globalfunctions/DleParser.cpp | 173 ++++++++++++++++++++++++ src/fsfw/globalfunctions/DleParser.h | 127 +++++++++++++++++ 3 files changed, 301 insertions(+) create mode 100644 src/fsfw/globalfunctions/DleParser.cpp create mode 100644 src/fsfw/globalfunctions/DleParser.h diff --git a/src/fsfw/globalfunctions/CMakeLists.txt b/src/fsfw/globalfunctions/CMakeLists.txt index cfa02696..cf8a25d5 100644 --- a/src/fsfw/globalfunctions/CMakeLists.txt +++ b/src/fsfw/globalfunctions/CMakeLists.txt @@ -4,6 +4,7 @@ target_sources( AsciiConverter.cpp CRC.cpp DleEncoder.cpp + DleParser.cpp PeriodicOperationDivider.cpp timevalOperations.cpp Type.cpp diff --git a/src/fsfw/globalfunctions/DleParser.cpp b/src/fsfw/globalfunctions/DleParser.cpp new file mode 100644 index 00000000..cc695bab --- /dev/null +++ b/src/fsfw/globalfunctions/DleParser.cpp @@ -0,0 +1,173 @@ +#include "DleParser.h" + +#include + +#include +#include +#include + +DleParser::DleParser(SimpleRingBuffer& decodeRingBuf, DleEncoder& decoder, BufPair encodedBuf, + BufPair decodedBuf) + : decodeRingBuf(decodeRingBuf), + decoder(decoder), + encodedBuf(encodedBuf), + decodedBuf(decodedBuf) {} + +ReturnValue_t DleParser::passData(const uint8_t* data, size_t len) { + if (data == nullptr or len == 0) { + return returnvalue::FAILED; + } + return decodeRingBuf.writeData(data, len); +} + +ReturnValue_t DleParser::parseRingBuf(size_t& readSize) { + ctx.setType(DleParser::ContextType::NONE); + size_t availableData = decodeRingBuf.getAvailableReadData(); + if (availableData == 0) { + return NO_PACKET_FOUND; + } + if (availableData > encodedBuf.second) { + ErrorInfo info; + info.len = decodeRingBuf.getAvailableReadData(); + setErrorContext(ErrorTypes::DECODING_BUF_TOO_SMALL, info); + return returnvalue::FAILED; + } + ReturnValue_t result = decodeRingBuf.readData(encodedBuf.first, availableData); + if (result != returnvalue::OK) { + ErrorInfo info; + info.res = result; + setErrorContext(ErrorTypes::RING_BUF_ERROR, info); + return result; + } + bool stxFound = false; + size_t stxIdx = 0; + for (size_t vectorIdx = 0; vectorIdx < availableData; vectorIdx++) { + // handle STX char + if (encodedBuf.first[vectorIdx] == DleEncoder::STX_CHAR) { + if (not stxFound) { + stxFound = true; + stxIdx = vectorIdx; + } else { + // might be lost packet, so we should advance the read pointer + // without skipping the STX + readSize = vectorIdx; + ErrorInfo info; + setErrorContext(ErrorTypes::CONSECUTIVE_STX_CHARS, info); + return POSSIBLE_PACKET_LOSS; + } + } + // handle ETX char + if (encodedBuf.first[vectorIdx] == DleEncoder::ETX_CHAR) { + if (stxFound) { + // This is propably a packet, so we decode it. + size_t decodedLen = 0; + size_t dummy = 0; + + ReturnValue_t result = + decoder.decode(&encodedBuf.first[stxIdx], availableData - stxIdx, &dummy, + decodedBuf.first, decodedBuf.second, &decodedLen); + if (result == returnvalue::OK) { + ctx.setType(ContextType::PACKET_FOUND); + ctx.decodedPacket.first = decodedBuf.first; + ctx.decodedPacket.second = decodedLen; + readSize = ++vectorIdx; + return returnvalue::OK; + } else { + // invalid packet, skip. + readSize = ++vectorIdx; + ErrorInfo info; + info.res = result; + setErrorContext(ErrorTypes::DECODE_ERROR, info); + return POSSIBLE_PACKET_LOSS; + } + } else { + // might be lost packet, so we should advance the read pointer + readSize = ++vectorIdx; + ErrorInfo info; + info.len = 0; + setErrorContext(ErrorTypes::CONSECUTIVE_ETX_CHARS, info); + return POSSIBLE_PACKET_LOSS; + } + } + } + return NO_PACKET_FOUND; +} + +void DleParser::defaultFoundPacketHandler(uint8_t* packet, size_t len, void* args) { +#if FSFW_VERBOSE_LEVEL >= 1 +#if FSFW_CPP_OSTREAM_ENABLED == 1 + sif::info << "DleParserBase::handleFoundPacket: Detected DLE packet with " << len << " bytes" + << std::endl; +#else + sif::printInfo("DleParserBase::handleFoundPacket: Detected DLE packet with %d bytes\n", len); +#endif +#endif +} + +void DleParser::defaultErrorHandler() { + if (ctx.getType() != DleParser::ContextType::ERROR) { + errorPrinter("No error"); + return; + } + switch (ctx.error.first) { + case (ErrorTypes::NONE): { + errorPrinter("No error"); + break; + } + case (ErrorTypes::DECODE_ERROR): { + errorPrinter("Decode Error"); + break; + } + case (ErrorTypes::RING_BUF_ERROR): { + errorPrinter("Ring Buffer Error"); + break; + } + case (ErrorTypes::ENCODED_BUF_TOO_SMALL): + case (ErrorTypes::DECODING_BUF_TOO_SMALL): { + char opt[64]; + snprintf(opt, sizeof(opt), ": Too small for packet with length %zu", + ctx.decodedPacket.second); + if (ctx.error.first == ErrorTypes::ENCODED_BUF_TOO_SMALL) { + errorPrinter("Encoded buf too small", opt); + } else { + errorPrinter("Decoding buf too small", opt); + } + break; + } + case (ErrorTypes::CONSECUTIVE_STX_CHARS): { + errorPrinter("Consecutive STX chars detected"); + break; + } + case (ErrorTypes::CONSECUTIVE_ETX_CHARS): { + errorPrinter("Consecutive ETX chars detected"); + break; + } + } +} + +void DleParser::errorPrinter(const char* str, const char* opt) { + if (opt == nullptr) { + opt = ""; + } +#if FSFW_VERBOSE_LEVEL >= 1 +#if FSFW_CPP_OSTREAM_ENABLED == 1 + sif::info << "DleParserBase::handleParseError: " << str << opt << std::endl; +#else + sif::printInfo("DleParserBase::handleParseError: %s%s\n", str, opt); +#endif +#endif +} + +void DleParser::setErrorContext(ErrorTypes err, ErrorInfo info) { + ctx.setType(ContextType::ERROR); + ctx.error.first = err; + ctx.error.second = info; +} + +ReturnValue_t DleParser::confirmBytesRead(size_t bytesRead) { + return decodeRingBuf.deleteData(bytesRead); +} + +const DleParser::Context& DleParser::getContext() { return ctx; } + +void DleParser::reset() { decodeRingBuf.clear(); } diff --git a/src/fsfw/globalfunctions/DleParser.h b/src/fsfw/globalfunctions/DleParser.h new file mode 100644 index 00000000..9802017a --- /dev/null +++ b/src/fsfw/globalfunctions/DleParser.h @@ -0,0 +1,127 @@ +#pragma once + +#include +#include +#include + +#include +#include + +/** + * @brief This base helper class can be used to extract DLE encoded packets from a data stream + * @details + * The core API of the parser takes received packets which can contains DLE packets. The parser + * can deal with DLE packets split across multiple packets. It does so by using a dedicated + * decoding ring buffer. The user can process received packets and detect errors by + * overriding two provided virtual methods. This also allows detecting multiple DLE packets + * inside one passed packet. + */ +class DleParser { + public: + static constexpr ReturnValue_t NO_PACKET_FOUND = returnvalue::makeCode(1, 1); + static constexpr ReturnValue_t POSSIBLE_PACKET_LOSS = returnvalue::makeCode(1, 2); + using BufPair = std::pair; + + enum class ContextType { NONE, PACKET_FOUND, ERROR }; + + enum class ErrorTypes { + NONE, + ENCODED_BUF_TOO_SMALL, + DECODING_BUF_TOO_SMALL, + DECODE_ERROR, + RING_BUF_ERROR, + CONSECUTIVE_STX_CHARS, + CONSECUTIVE_ETX_CHARS + }; + + union ErrorInfo { + size_t len; + ReturnValue_t res; + }; + + using ErrorPair = std::pair; + + struct Context { + public: + Context() { setType(ContextType::PACKET_FOUND); } + + void setType(ContextType type) { + this->type = type; + if (type == ContextType::PACKET_FOUND) { + error.first = ErrorTypes::NONE; + error.second.len = 0; + } else { + decodedPacket.first = nullptr; + decodedPacket.second = 0; + } + } + + ContextType getType() const { return type; } + + BufPair decodedPacket = {}; + ErrorPair error; + + private: + ContextType type; + }; + + /** + * Base class constructor + * @param decodeRingBuf Ring buffer used to store multiple packets to allow detecting DLE packets + * split across multiple packets + * @param decoder Decoder instance + * @param encodedBuf Buffer used to store encoded packets. It has to be large enough to hold + * the largest expected encoded DLE packet size + * @param decodedBuf Buffer used to store decoded packets. It has to be large enough to hold the + * largest expected decoded DLE packet size + * @param handler Function which will be called on a found packet + * @param args Arbitrary user argument + */ + DleParser(SimpleRingBuffer& decodeRingBuf, DleEncoder& decoder, BufPair encodedBuf, + BufPair decodedBuf); + + /** + * This function allows to pass new data into the parser. It then scans for DLE packets + * automatically and inserts (part of) the packet into a ring buffer if necessary. + * @param data + * @param len + * @return + */ + ReturnValue_t passData(const uint8_t* data, size_t len); + + ReturnValue_t parseRingBuf(size_t& bytesRead); + + ReturnValue_t confirmBytesRead(size_t bytesRead); + + const Context& getContext(); + /** + * Example found packet handler + * function call + * @param packet Decoded packet + * @param len Length of detected packet + */ + void defaultFoundPacketHandler(uint8_t* packet, size_t len, void* args); + /** + * Will be called if an error occured in the #passData call + * @param err + * @param ctx Context information depending on the error type + * - For buffer length errors, will be set to the detected packet length which is too large + * - For decode or ring buffer errors, will be set to the result returned from the failed call + */ + void defaultErrorHandler(); + + static void errorPrinter(const char* str, const char* opt = nullptr); + + void setErrorContext(ErrorTypes err, ErrorInfo ctx); + /** + * Resets the parser by resetting the internal states and clearing the decoding ring buffer + */ + void reset(); + + private: + SimpleRingBuffer& decodeRingBuf; + DleEncoder& decoder; + BufPair encodedBuf; + BufPair decodedBuf; + Context ctx; +}; From 8fe8d810e977e88b3ce22a2f4332527892457377 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Tue, 15 Nov 2022 11:27:31 +0100 Subject: [PATCH 154/169] only delete table if not nullptr --- src/fsfw/health/HealthHelper.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/fsfw/health/HealthHelper.cpp b/src/fsfw/health/HealthHelper.cpp index bf1a92d2..f6077ea1 100644 --- a/src/fsfw/health/HealthHelper.cpp +++ b/src/fsfw/health/HealthHelper.cpp @@ -5,7 +5,11 @@ HealthHelper::HealthHelper(HasHealthIF* owner, object_id_t objectId) : objectId(objectId), owner(owner) {} -HealthHelper::~HealthHelper() { healthTable->removeObject(objectId); } +HealthHelper::~HealthHelper() { + if (healthTable != nullptr) { + healthTable->removeObject(objectId); + } +} ReturnValue_t HealthHelper::handleHealthCommand(CommandMessage* message) { switch (message->getCommand()) { From 03620970e2e883c9dc3da8c617e73935596bafc6 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Tue, 15 Nov 2022 11:38:32 +0100 Subject: [PATCH 155/169] function to get queue is const now --- src/fsfw/tmtcservices/AcceptsTelemetryIF.h | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/fsfw/tmtcservices/AcceptsTelemetryIF.h b/src/fsfw/tmtcservices/AcceptsTelemetryIF.h index c3e3eff3..5b421cf9 100644 --- a/src/fsfw/tmtcservices/AcceptsTelemetryIF.h +++ b/src/fsfw/tmtcservices/AcceptsTelemetryIF.h @@ -21,9 +21,11 @@ class AcceptsTelemetryIF { * receiving message queue. * @return The telemetry reception message queue id. */ - virtual MessageQueueId_t getReportReceptionQueue(uint8_t virtualChannel) = 0; + [[nodiscard]] virtual MessageQueueId_t getReportReceptionQueue(uint8_t virtualChannel) const = 0; - virtual MessageQueueId_t getReportReceptionQueue() { return getReportReceptionQueue(0); } + [[nodiscard]] virtual MessageQueueId_t getReportReceptionQueue() const { + return getReportReceptionQueue(0); + } }; #endif /* FSFW_TMTCSERVICES_ACCEPTSTELEMETRYIF_H_ */ From a236a5ec507a0be1f6e8a5ef5821ec71942e8a04 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Tue, 15 Nov 2022 11:40:26 +0100 Subject: [PATCH 156/169] adaptions for AcceptsTelemetryIF --- src/fsfw/tmtcservices/TmTcBridge.cpp | 2 +- src/fsfw/tmtcservices/TmTcBridge.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/fsfw/tmtcservices/TmTcBridge.cpp b/src/fsfw/tmtcservices/TmTcBridge.cpp index 0e9f0da4..f22d70d6 100644 --- a/src/fsfw/tmtcservices/TmTcBridge.cpp +++ b/src/fsfw/tmtcservices/TmTcBridge.cpp @@ -240,7 +240,7 @@ void TmTcBridge::registerCommDisconnect() { } } -MessageQueueId_t TmTcBridge::getReportReceptionQueue(uint8_t virtualChannel) { +MessageQueueId_t TmTcBridge::getReportReceptionQueue(uint8_t virtualChannel) const { return tmTcReceptionQueue->getId(); } diff --git a/src/fsfw/tmtcservices/TmTcBridge.h b/src/fsfw/tmtcservices/TmTcBridge.h index 4b90d1d5..ed4d254e 100644 --- a/src/fsfw/tmtcservices/TmTcBridge.h +++ b/src/fsfw/tmtcservices/TmTcBridge.h @@ -65,7 +65,7 @@ class TmTcBridge : public AcceptsTelemetryIF, ReturnValue_t performOperation(uint8_t operationCode = 0) override; /** AcceptsTelemetryIF override */ - MessageQueueId_t getReportReceptionQueue(uint8_t virtualChannel = 0) override; + MessageQueueId_t getReportReceptionQueue(uint8_t virtualChannel) const override; /** AcceptsTelecommandsIF override */ uint32_t getIdentifier() const override; From d31a5306f0ddf27bd0ecf2315c03f97df0cf0865 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Tue, 15 Nov 2022 11:41:03 +0100 Subject: [PATCH 157/169] fix mock --- unittests/mocks/AcceptsTmMock.cpp | 2 +- unittests/mocks/AcceptsTmMock.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/unittests/mocks/AcceptsTmMock.cpp b/unittests/mocks/AcceptsTmMock.cpp index 7b997047..2f718e61 100644 --- a/unittests/mocks/AcceptsTmMock.cpp +++ b/unittests/mocks/AcceptsTmMock.cpp @@ -6,7 +6,7 @@ AcceptsTmMock::AcceptsTmMock(object_id_t registeredId, MessageQueueId_t queueToR AcceptsTmMock::AcceptsTmMock(MessageQueueId_t queueToReturn) : SystemObject(objects::NO_OBJECT, false), returnedQueue(queueToReturn) {} -MessageQueueId_t AcceptsTmMock::getReportReceptionQueue(uint8_t virtualChannel) { +MessageQueueId_t AcceptsTmMock::getReportReceptionQueue(uint8_t virtualChannel) const { return returnedQueue; } diff --git a/unittests/mocks/AcceptsTmMock.h b/unittests/mocks/AcceptsTmMock.h index d6cc7f85..b12e1094 100644 --- a/unittests/mocks/AcceptsTmMock.h +++ b/unittests/mocks/AcceptsTmMock.h @@ -9,7 +9,7 @@ class AcceptsTmMock : public SystemObject, public AcceptsTelemetryIF { AcceptsTmMock(object_id_t registeredId, MessageQueueId_t queueToReturn); explicit AcceptsTmMock(MessageQueueId_t queueToReturn); - MessageQueueId_t getReportReceptionQueue(uint8_t virtualChannel) override; + MessageQueueId_t getReportReceptionQueue(uint8_t virtualChannel) const override; const char* getName() const override; MessageQueueId_t returnedQueue; From cbc8dbcdd4c931b5f19f9c5a452e4b12147ce036 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Tue, 15 Nov 2022 11:44:45 +0100 Subject: [PATCH 158/169] update changelog --- CHANGELOG.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5c7ab45e..bfecc685 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -29,6 +29,8 @@ and this project adheres to [Semantic Versioning](http://semver.org/). ## Changes +- `AcceptsTelemetryIF`: `getReportReceptionQueue` is const now + PR: https://egit.irs.uni-stuttgart.de/fsfw/fsfw/pulls/712 - Remove default secondary header argument for `uint16_t getTcSpacePacketIdFromApid(uint16_t apid, bool secondaryHeaderFlag)` and `uint16_t getTmSpacePacketIdFromApid(uint16_t apid, bool secondaryHeaderFlag)` From 8199b8f3590382aa0bd40f30bf4a4287e309533b Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Tue, 15 Nov 2022 11:45:39 +0100 Subject: [PATCH 159/169] bump changelog --- CHANGELOG.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5c7ab45e..f0d6120a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -24,6 +24,8 @@ and this project adheres to [Semantic Versioning](http://semver.org/). ## Added +- `DleParser` helper class to parse DLE encoded packets from a byte stream. + PR: https://egit.irs.uni-stuttgart.de/fsfw/fsfw/pulls/711 - Add new `UnsignedByteField` class PR: https://egit.irs.uni-stuttgart.de/fsfw/fsfw/pulls/660 From f8c07ec9cf2589547f4a706f0651557a6a689943 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Tue, 15 Nov 2022 11:46:43 +0100 Subject: [PATCH 160/169] update changelog --- CHANGELOG.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5c7ab45e..9545c63e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,6 +12,9 @@ and this project adheres to [Semantic Versioning](http://semver.org/). ## Fixes +- Only delete health table entry in `HealthHelper` destructor if + health table was set. + PR: https://egit.irs.uni-stuttgart.de/fsfw/fsfw/pulls/710/files - I2C Bugfixes: Do not keep iterator as member and fix some incorrect handling with the iterator. Also properly reset the reply size for successfull transfers and erroneous transfers. PR: https://egit.irs.uni-stuttgart.de/fsfw/fsfw/pulls/700 From 3bc3da5a8d3f534b3bc74af4e840dabd277db5ad Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Tue, 15 Nov 2022 11:47:26 +0100 Subject: [PATCH 161/169] update changelog --- CHANGELOG.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5c7ab45e..0f4a9e3a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -24,6 +24,8 @@ and this project adheres to [Semantic Versioning](http://semver.org/). ## Added +- `UioMapper` is able to resolve symlinks now. + PR: https://egit.irs.uni-stuttgart.de/fsfw/fsfw/pulls/709 - Add new `UnsignedByteField` class PR: https://egit.irs.uni-stuttgart.de/fsfw/fsfw/pulls/660 From b85ca6469014c9ff4dbb2ba60c79d729d2b3fba3 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Tue, 15 Nov 2022 11:48:28 +0100 Subject: [PATCH 162/169] update changelog --- CHANGELOG.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5c7ab45e..cd5cdf47 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -29,6 +29,9 @@ and this project adheres to [Semantic Versioning](http://semver.org/). ## Changes +- Moved some container returnvalues to dedicated header and namespace + to they can be used without template specification. + PR: https://egit.irs.uni-stuttgart.de/fsfw/fsfw/pulls/707 - Remove default secondary header argument for `uint16_t getTcSpacePacketIdFromApid(uint16_t apid, bool secondaryHeaderFlag)` and `uint16_t getTmSpacePacketIdFromApid(uint16_t apid, bool secondaryHeaderFlag)` From f05295bada20f3b15b552c73b5fa16770e1cd6ec Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Thu, 17 Nov 2022 15:09:08 +0100 Subject: [PATCH 163/169] small fix to allow teardown handling --- src/fsfw/devicehandlers/DeviceHandlerBase.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/fsfw/devicehandlers/DeviceHandlerBase.cpp b/src/fsfw/devicehandlers/DeviceHandlerBase.cpp index 8ab540a0..60966501 100644 --- a/src/fsfw/devicehandlers/DeviceHandlerBase.cpp +++ b/src/fsfw/devicehandlers/DeviceHandlerBase.cpp @@ -359,6 +359,8 @@ void DeviceHandlerBase::doStateMachine() { if ((switchState == PowerSwitchIF::SWITCH_ON) || (switchState == NO_SWITCH)) { // NOTE: TransitionSourceMode and -SubMode are set by handleCommandedModeTransition childTransitionFailure = CHILD_TIMEOUT; + transitionSourceMode = _MODE_SHUT_DOWN; + transitionSourceSubMode = SUBMODE_NONE; setMode(_MODE_START_UP); callChildStatemachine(); } From 65a5abab495ad07f5aca25f27569537fea6a577a Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Mon, 21 Nov 2022 14:56:08 +0100 Subject: [PATCH 164/169] move free call --- CMakeLists.txt | 12 +++++++++--- src/fsfw/storagemanager/StorageManagerIF.h | 3 ++- src/fsfw_hal/linux/serial/SerialCookie.cpp | 2 +- src/fsfw_hal/linux/serial/SerialCookie.h | 2 +- src/fsfw_hal/linux/uio/UioMapper.cpp | 6 +++--- unittests/hal/CMakeLists.txt | 4 +--- unittests/mocks/cfdp/FaultHandlerMock.h | 2 +- 7 files changed, 18 insertions(+), 13 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index dd01510e..8308f523 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -346,9 +346,15 @@ if(FSFW_BUILD_TESTS) DEPENDENCIES ${FSFW_TEST_TGT}) else() setup_target_for_coverage_lcov( - NAME ${FSFW_TEST_TGT}_coverage EXECUTABLE ${FSFW_TEST_TGT} - DEPENDENCIES ${FSFW_TEST_TGT} - GENHTML_ARGS --html-epilog ${CMAKE_SOURCE_DIR}/unittests/lcov_epilog.html) + NAME + ${FSFW_TEST_TGT}_coverage + EXECUTABLE + ${FSFW_TEST_TGT} + DEPENDENCIES + ${FSFW_TEST_TGT} + GENHTML_ARGS + --html-epilog + ${CMAKE_SOURCE_DIR}/unittests/lcov_epilog.html) endif() endif() endif() diff --git a/src/fsfw/storagemanager/StorageManagerIF.h b/src/fsfw/storagemanager/StorageManagerIF.h index f9fb33f5..e48e19db 100644 --- a/src/fsfw/storagemanager/StorageManagerIF.h +++ b/src/fsfw/storagemanager/StorageManagerIF.h @@ -181,7 +181,8 @@ class StorageManagerIF { * @return Returns @returnvalue::OK if data was added. * @returnvalue::FAILED if data could not be added, storageId is unchanged then. */ - virtual ReturnValue_t getFreeElement(store_address_t* storageId, size_t size, uint8_t** dataPtr) = 0; + virtual ReturnValue_t getFreeElement(store_address_t* storageId, size_t size, + uint8_t** dataPtr) = 0; [[nodiscard]] virtual bool hasDataAtId(store_address_t storeId) const = 0; diff --git a/src/fsfw_hal/linux/serial/SerialCookie.cpp b/src/fsfw_hal/linux/serial/SerialCookie.cpp index e85d339d..1b7e9b51 100644 --- a/src/fsfw_hal/linux/serial/SerialCookie.cpp +++ b/src/fsfw_hal/linux/serial/SerialCookie.cpp @@ -3,7 +3,7 @@ #include SerialCookie::SerialCookie(object_id_t handlerId, std::string deviceFile, UartBaudRate baudrate, - size_t maxReplyLen, UartModes uartMode) + size_t maxReplyLen, UartModes uartMode) : handlerId(handlerId), deviceFile(deviceFile), uartMode(uartMode), diff --git a/src/fsfw_hal/linux/serial/SerialCookie.h b/src/fsfw_hal/linux/serial/SerialCookie.h index 3916e4ca..7a9c0eca 100644 --- a/src/fsfw_hal/linux/serial/SerialCookie.h +++ b/src/fsfw_hal/linux/serial/SerialCookie.h @@ -30,7 +30,7 @@ class SerialCookie : public CookieIF { * One stop bit */ SerialCookie(object_id_t handlerId, std::string deviceFile, UartBaudRate baudrate, - size_t maxReplyLen, UartModes uartMode = UartModes::NON_CANONICAL); + size_t maxReplyLen, UartModes uartMode = UartModes::NON_CANONICAL); virtual ~SerialCookie(); diff --git a/src/fsfw_hal/linux/uio/UioMapper.cpp b/src/fsfw_hal/linux/uio/UioMapper.cpp index e34c209a..9e16ce67 100644 --- a/src/fsfw_hal/linux/uio/UioMapper.cpp +++ b/src/fsfw_hal/linux/uio/UioMapper.cpp @@ -20,15 +20,15 @@ UioMapper::UioMapper(std::string uioFile, int mapNum) : mapNum(mapNum) { if (S_ISLNK(buf.st_mode)) { char* res = realpath(uioFile.c_str(), nullptr); if (res) { - this->uioFile = res; + uioFile = res; + free(res); } else { #if FSFW_CPP_OSTREAM_ENABLED == 1 sif::error << "Could not resolve real path of UIO file " << uioFile << std::endl; #endif } - free(res); } else { - this->uioFile = std::move(uioFile); + uioFile = std::move(uioFile); } } diff --git a/unittests/hal/CMakeLists.txt b/unittests/hal/CMakeLists.txt index 2a6c012b..76aabd51 100644 --- a/unittests/hal/CMakeLists.txt +++ b/unittests/hal/CMakeLists.txt @@ -1,7 +1,5 @@ target_sources(${FSFW_TEST_TGT} PRIVATE testHostFilesystem.cpp testFsMock.cpp) if(UNIX) - target_sources(${FSFW_TEST_TGT} PRIVATE - testCommandExecutor.cpp - ) + target_sources(${FSFW_TEST_TGT} PRIVATE testCommandExecutor.cpp) endif() diff --git a/unittests/mocks/cfdp/FaultHandlerMock.h b/unittests/mocks/cfdp/FaultHandlerMock.h index 1c59485c..5e094509 100644 --- a/unittests/mocks/cfdp/FaultHandlerMock.h +++ b/unittests/mocks/cfdp/FaultHandlerMock.h @@ -17,7 +17,7 @@ class FaultHandlerMock : public FaultHandlerBase { void noticeOfSuspensionCb(TransactionId& id, ConditionCode code) override; void noticeOfCancellationCb(TransactionId& id, ConditionCode code) override; - void abandonCb(TransactionId& id,ConditionCode code) override; + void abandonCb(TransactionId& id, ConditionCode code) override; void ignoreCb(TransactionId& id, ConditionCode code) override; FaultInfo& getFhInfo(FaultHandlerCode fhCode); From 23d3812fe33e255647b9af9ac9a86a1fb7eee893 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Mon, 21 Nov 2022 15:22:25 +0100 Subject: [PATCH 165/169] this is actually important --- src/fsfw_hal/linux/uio/UioMapper.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/fsfw_hal/linux/uio/UioMapper.cpp b/src/fsfw_hal/linux/uio/UioMapper.cpp index 9e16ce67..33e4fd97 100644 --- a/src/fsfw_hal/linux/uio/UioMapper.cpp +++ b/src/fsfw_hal/linux/uio/UioMapper.cpp @@ -20,7 +20,7 @@ UioMapper::UioMapper(std::string uioFile, int mapNum) : mapNum(mapNum) { if (S_ISLNK(buf.st_mode)) { char* res = realpath(uioFile.c_str(), nullptr); if (res) { - uioFile = res; + this->uioFile = res; free(res); } else { #if FSFW_CPP_OSTREAM_ENABLED == 1 @@ -28,7 +28,7 @@ UioMapper::UioMapper(std::string uioFile, int mapNum) : mapNum(mapNum) { #endif } } else { - uioFile = std::move(uioFile); + this->uioFile = std::move(uioFile); } } From ecde164f68370e3624f314a53b09691a61f53931 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Mon, 28 Nov 2022 08:30:45 +0100 Subject: [PATCH 166/169] updates for source sequence counter --- src/fsfw/tmtcservices/SourceSequenceCounter.h | 28 ++++++++++++------- 1 file changed, 18 insertions(+), 10 deletions(-) diff --git a/src/fsfw/tmtcservices/SourceSequenceCounter.h b/src/fsfw/tmtcservices/SourceSequenceCounter.h index da96dc4e..43b6945c 100644 --- a/src/fsfw/tmtcservices/SourceSequenceCounter.h +++ b/src/fsfw/tmtcservices/SourceSequenceCounter.h @@ -5,20 +5,28 @@ class SourceSequenceCounter { private: - uint16_t sequenceCount; + uint16_t sequenceCount = 0; public: - SourceSequenceCounter() : sequenceCount(0) {} - void increment() { - sequenceCount = (sequenceCount + 1) % (SpacePacketBase::LIMIT_SEQUENCE_COUNT); - } - void decrement() { - sequenceCount = (sequenceCount - 1) % (SpacePacketBase::LIMIT_SEQUENCE_COUNT); - } + SourceSequenceCounter(uint16_t initialSequenceCount = 0) : sequenceCount(initialSequenceCount) {} + void increment() { sequenceCount = (sequenceCount + 1) % (ccsds::LIMIT_SEQUENCE_COUNT); } + void decrement() { sequenceCount = (sequenceCount - 1) % (ccsds::LIMIT_SEQUENCE_COUNT); } uint16_t get() { return this->sequenceCount; } - void reset(uint16_t toValue = 0) { - sequenceCount = toValue % (SpacePacketBase::LIMIT_SEQUENCE_COUNT); + void reset(uint16_t toValue = 0) { sequenceCount = toValue % (ccsds::LIMIT_SEQUENCE_COUNT); } + SourceSequenceCounter& operator++(int) { + this->increment(); + return *this; } + SourceSequenceCounter& operator--(int) { + this->decrement(); + return *this; + } + SourceSequenceCounter& operator=(const uint16_t& newCount) { + sequenceCount = newCount; + return *this; + } + + operator uint16_t() { return this->get(); } }; #endif /* FSFW_TMTCSERVICES_SOURCESEQUENCECOUNTER_H_ */ From d0e322d7e2a54c4fb05947721793d47d2bc69d2d Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Mon, 28 Nov 2022 08:42:08 +0100 Subject: [PATCH 167/169] printout handling improvements --- src/fsfw_hal/linux/i2c/I2cComIF.cpp | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/src/fsfw_hal/linux/i2c/I2cComIF.cpp b/src/fsfw_hal/linux/i2c/I2cComIF.cpp index 4e57852b..1ad19e82 100644 --- a/src/fsfw_hal/linux/i2c/I2cComIF.cpp +++ b/src/fsfw_hal/linux/i2c/I2cComIF.cpp @@ -168,12 +168,18 @@ ReturnValue_t I2cComIF::requestReceiveMessage(CookieIF* cookie, size_t requestLe int readLen = read(fd, replyBuffer, requestLen); if (readLen != static_cast(requestLen)) { -#if FSFW_VERBOSE_LEVEL >= 1 and FSFW_CPP_OSTREAM_ENABLED == 1 - sif::error << "I2cComIF::requestReceiveMessage: Reading from I2C " - << "device failed with error code " << errno << ". Description" - << " of error: " << strerror(errno) << std::endl; - sif::error << "I2cComIF::requestReceiveMessage: Read only " << readLen << " from " << requestLen - << " bytes" << std::endl; +#if FSFW_VERBOSE_LEVEL >= 1 +#if FSFW_CPP_OSTREAM_ENABLED == 1 + if (readLen < 0) { + sif::warning << "I2cComIF::requestReceiveMessage: Reading from I2C " + << "device failed with error code " << errno << " | " << strerror(errno) + << std::endl; + } else { + sif::warning << "I2cComIF::requestReceiveMessage: Read only " << readLen << " from " + << requestLen << " bytes" << std::endl; + } +#else +#endif #endif #if FSFW_CPP_OSTREAM_ENABLED == 1 sif::debug << "I2cComIF::requestReceiveMessage: Read " << readLen << " of " << requestLen From b13453f46b8c0c1bd446d136c4a1348c8a03ab5f Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Mon, 28 Nov 2022 08:43:54 +0100 Subject: [PATCH 168/169] vec getter, reset for content --- src/fsfw_hal/linux/CommandExecutor.cpp | 4 ++++ src/fsfw_hal/linux/CommandExecutor.h | 2 ++ 2 files changed, 6 insertions(+) diff --git a/src/fsfw_hal/linux/CommandExecutor.cpp b/src/fsfw_hal/linux/CommandExecutor.cpp index 8b81d94f..27cf8aca 100644 --- a/src/fsfw_hal/linux/CommandExecutor.cpp +++ b/src/fsfw_hal/linux/CommandExecutor.cpp @@ -32,6 +32,8 @@ ReturnValue_t CommandExecutor::execute() { } else if (state == States::PENDING) { return COMMAND_PENDING; } + // Reset data in read vector + std::memset(readVec.data(), 0, readVec.size()); currentCmdFile = popen(currentCmd.c_str(), "r"); if (currentCmdFile == nullptr) { lastError = errno; @@ -205,3 +207,5 @@ ReturnValue_t CommandExecutor::executeBlocking() { } return returnvalue::OK; } + +const std::vector& CommandExecutor::getReadVector() const { return readVec; } diff --git a/src/fsfw_hal/linux/CommandExecutor.h b/src/fsfw_hal/linux/CommandExecutor.h index 81f989e7..80996bae 100644 --- a/src/fsfw_hal/linux/CommandExecutor.h +++ b/src/fsfw_hal/linux/CommandExecutor.h @@ -107,6 +107,8 @@ class CommandExecutor { */ void reset(); + const std::vector& getReadVector() const; + private: std::string currentCmd; bool blocking = true; From ca80589233a9872e23db44b1af94d26df5f7c236 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Mon, 19 Dec 2022 14:58:08 +0100 Subject: [PATCH 169/169] make get const --- src/fsfw/tmtcservices/SourceSequenceCounter.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/fsfw/tmtcservices/SourceSequenceCounter.h b/src/fsfw/tmtcservices/SourceSequenceCounter.h index 43b6945c..f530b444 100644 --- a/src/fsfw/tmtcservices/SourceSequenceCounter.h +++ b/src/fsfw/tmtcservices/SourceSequenceCounter.h @@ -11,7 +11,7 @@ class SourceSequenceCounter { SourceSequenceCounter(uint16_t initialSequenceCount = 0) : sequenceCount(initialSequenceCount) {} void increment() { sequenceCount = (sequenceCount + 1) % (ccsds::LIMIT_SEQUENCE_COUNT); } void decrement() { sequenceCount = (sequenceCount - 1) % (ccsds::LIMIT_SEQUENCE_COUNT); } - uint16_t get() { return this->sequenceCount; } + uint16_t get() const { return this->sequenceCount; } void reset(uint16_t toValue = 0) { sequenceCount = toValue % (ccsds::LIMIT_SEQUENCE_COUNT); } SourceSequenceCounter& operator++(int) { this->increment();