diff --git a/CMakeLists.txt b/CMakeLists.txt index 5601d2021..e59eb4c5f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -133,14 +133,7 @@ option(FSFW_ADD_SGP4_PROPAGATOR "Add SGP4 propagator code" OFF) set(FSFW_TEST_TGT fsfw-tests) set(FSFW_DUMMY_TGT fsfw-dummy) -add_library( - ${LIB_FSFW_NAME} - src/fsfw/tmtcpacket/SpacePacketIF.h - src/fsfw/tmtcpacket/pus/tc/PusTcCreator.h - src/fsfw/tmtcpacket/pus/tc/PusTcCreator.cpp - src/fsfw/tmtcpacket/pus/tc/PusTcIF.h - src/fsfw/tmtcpacket/SpacePacketCreator.h - src/fsfw/tmtcpacket/SpacePacketCreator.cpp) +add_library(${LIB_FSFW_NAME}) if(IPO_SUPPORTED AND FSFW_ENABLE_IPO) set_property(TARGET ${LIB_FSFW_NAME} PROPERTY INTERPROCEDURAL_OPTIMIZATION @@ -175,7 +168,7 @@ if(FSFW_BUILD_TESTS) configure_file(unittests/testcfg/TestsConfig.h.in tests/TestsConfig.h) project(${FSFW_TEST_TGT} CXX C) - add_executable(${FSFW_TEST_TGT} unittests/tmtcpacket/testCcsdsReader.cpp) + add_executable(${FSFW_TEST_TGT}) if(IPO_SUPPORTED AND FSFW_ENABLE_IPO) set_property(TARGET ${FSFW_TEST_TGT} PROPERTY INTERPROCEDURAL_OPTIMIZATION TRUE) diff --git a/src/fsfw/cfdp/CFDPHandler.h b/src/fsfw/cfdp/CFDPHandler.h index abbac6b65..3e6f04293 100644 --- a/src/fsfw/cfdp/CFDPHandler.h +++ b/src/fsfw/cfdp/CFDPHandler.h @@ -45,7 +45,7 @@ class CFDPHandler : public ExecutableObjectIF, * The current CFDP packet to be processed. * It is deleted after handleRequest was executed. */ - CFDPPacketStored currentPacket; + CfdpPacketStored currentPacket; static object_id_t packetSource; diff --git a/src/fsfw/internalerror/InternalErrorReporterIF.h b/src/fsfw/internalerror/InternalErrorReporterIF.h index 61bb52e7b..aa917d214 100644 --- a/src/fsfw/internalerror/InternalErrorReporterIF.h +++ b/src/fsfw/internalerror/InternalErrorReporterIF.h @@ -12,7 +12,7 @@ */ class InternalErrorReporterIF { public: - virtual ~InternalErrorReporterIF() {} + virtual ~InternalErrorReporterIF() = default; /** * @brief Function to be called if a message queue could not be sent. * @details OSAL Implementations should call this function to indicate that diff --git a/src/fsfw/pus/Service9TimeManagement.cpp b/src/fsfw/pus/Service9TimeManagement.cpp index 86eef93a0..6cd46f3a0 100644 --- a/src/fsfw/pus/Service9TimeManagement.cpp +++ b/src/fsfw/pus/Service9TimeManagement.cpp @@ -25,7 +25,7 @@ ReturnValue_t Service9TimeManagement::handleRequest(uint8_t subservice) { ReturnValue_t Service9TimeManagement::setTime() { Clock::TimeOfDay_t timeToSet; - TimePacket timePacket(currentPacket.getApplicationData(), currentPacket.getApplicationDataSize()); + TimePacket timePacket(currentPacket.getUserData(), currentPacket.getUserDataSize()); ReturnValue_t result = CCSDSTime::convertFromCcsds(&timeToSet, timePacket.getTime(), timePacket.getTimeSize()); if (result != RETURN_OK) { diff --git a/src/fsfw/returnvalues/FwClassIds.h b/src/fsfw/returnvalues/FwClassIds.h index f5f57276e..50efd9c58 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 - TC_PACKET_CHECK, // TCC + PACKET_CHECK, // TCC PACKET_DISTRIBUTION, // TCD ACCEPTS_TELECOMMANDS_IF, // PUS DEVICE_SERVICE_BASE, // DSB diff --git a/src/fsfw/tcdistribution/CCSDSDistributor.cpp b/src/fsfw/tcdistribution/CCSDSDistributor.cpp index a32cbc754..f18e55def 100644 --- a/src/fsfw/tcdistribution/CCSDSDistributor.cpp +++ b/src/fsfw/tcdistribution/CCSDSDistributor.cpp @@ -40,7 +40,7 @@ TcDistributor::TcMqMapIter CCSDSDistributor::selectDestination() { #endif return queueMap.end(); } - SpacePacketReader currentPacket(packet); + SpacePacketReader currentPacket(packet, size); #if FSFW_CPP_OSTREAM_ENABLED == 1 && CCSDS_DISTRIBUTOR_DEBUGGING == 1 sif::info << "CCSDSDistributor::selectDestination has packet with APID " << std::hex diff --git a/src/fsfw/tcdistribution/CCSDSDistributorIF.h b/src/fsfw/tcdistribution/CCSDSDistributorIF.h index d1c88118d..da4a943fe 100644 --- a/src/fsfw/tcdistribution/CCSDSDistributorIF.h +++ b/src/fsfw/tcdistribution/CCSDSDistributorIF.h @@ -34,7 +34,7 @@ class CCSDSDistributorIF { /** * The empty virtual destructor. */ - virtual ~CCSDSDistributorIF() {} + virtual ~CCSDSDistributorIF() = default; }; #endif /* FSFW_TCDISTRIBUTION_CCSDSDISTRIBUTORIF_H_ */ diff --git a/src/fsfw/tcdistribution/CFDPDistributor.cpp b/src/fsfw/tcdistribution/CFDPDistributor.cpp index d8be1543e..5aa84d44a 100644 --- a/src/fsfw/tcdistribution/CFDPDistributor.cpp +++ b/src/fsfw/tcdistribution/CFDPDistributor.cpp @@ -2,7 +2,7 @@ #include "fsfw/objectmanager/ObjectManager.h" #include "fsfw/tcdistribution/CCSDSDistributorIF.h" -#include "fsfw/tmtcpacket/cfdp/CFDPPacketStored.h" +#include "fsfw/tmtcpacket/cfdp/CfdpPacketStored.h" #ifndef FSFW_CFDP_DISTRIBUTOR_DEBUGGING #define FSFW_CFDP_DISTRIBUTOR_DEBUGGING 1 @@ -16,7 +16,7 @@ CFDPDistributor::CFDPDistributor(uint16_t setApid, object_id_t setObjectId, tcStatus(RETURN_FAILED), packetSource(setPacketSource) {} -CFDPDistributor::~CFDPDistributor() {} +CFDPDistributor::~CFDPDistributor() = default; CFDPDistributor::TcMqMapIter CFDPDistributor::selectDestination() { #if FSFW_CFDP_DISTRIBUTOR_DEBUGGING == 1 @@ -29,13 +29,13 @@ CFDPDistributor::TcMqMapIter CFDPDistributor::selectDestination() { storeId.packetIndex); #endif #endif - TcMqMapIter queueMapIt = this->queueMap.end(); + auto queueMapIt = this->queueMap.end(); if (this->currentPacket == nullptr) { return queueMapIt; } this->currentPacket->setStoreAddress(this->currentMessage.getStorageId()); - if (currentPacket->getWholeData() != nullptr) { - tcStatus = checker.checkPacket(currentPacket); + 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 @@ -121,14 +121,13 @@ MessageQueueId_t CFDPDistributor::getRequestQueue() { return tcQueue->getId(); } uint16_t CFDPDistributor::getIdentifier() { return this->apid; } ReturnValue_t CFDPDistributor::initialize() { - currentPacket = new CFDPPacketStored(); + currentPacket = new CfdpPacketStored(); if (currentPacket == nullptr) { // Should not happen, memory allocation failed! return ObjectManagerIF::CHILD_INIT_FAILED; } - CCSDSDistributorIF* 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; diff --git a/src/fsfw/tcdistribution/CFDPDistributor.h b/src/fsfw/tcdistribution/CFDPDistributor.h index 2a901021b..e7776f1b8 100644 --- a/src/fsfw/tcdistribution/CFDPDistributor.h +++ b/src/fsfw/tcdistribution/CFDPDistributor.h @@ -1,10 +1,10 @@ #ifndef FSFW_TCDISTRIBUTION_CFDPDISTRIBUTOR_H_ #define FSFW_TCDISTRIBUTION_CFDPDISTRIBUTOR_H_ -#include +#include #include "../returnvalues/HasReturnvaluesIF.h" -#include "../tmtcpacket/cfdp/CFDPPacketStored.h" +#include "../tmtcpacket/cfdp/CfdpPacketStored.h" #include "../tmtcservices/AcceptsTelecommandsIF.h" #include "../tmtcservices/VerificationReporter.h" #include "CFDPDistributorIF.h" @@ -31,7 +31,7 @@ class CFDPDistributor : public TcDistributor, /** * The destructor is empty. */ - virtual ~CFDPDistributor(); + ~CFDPDistributor() override; ReturnValue_t registerHandler(AcceptsTelecommandsIF* handler) override; MessageQueueId_t getRequestQueue() override; ReturnValue_t initialize() override; @@ -42,8 +42,8 @@ class CFDPDistributor : public TcDistributor, /** * The currently handled packet is stored here. */ - CFDPPacketStored* currentPacket = nullptr; - TcPacketCheckCFDP checker; + CfdpPacketStored* currentPacket = nullptr; + CfdpPacketChecker checker; /** * With this variable, the current check status is stored to generate * acceptance messages later. diff --git a/src/fsfw/tcdistribution/CFDPDistributorIF.h b/src/fsfw/tcdistribution/CFDPDistributorIF.h index 3c1836f1b..3f048bbfd 100644 --- a/src/fsfw/tcdistribution/CFDPDistributorIF.h +++ b/src/fsfw/tcdistribution/CFDPDistributorIF.h @@ -13,7 +13,7 @@ class CFDPDistributorIF { /** * The empty virtual destructor. */ - virtual ~CFDPDistributorIF() {} + 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/CMakeLists.txt b/src/fsfw/tcdistribution/CMakeLists.txt index ab32c509d..9cc3d1703 100644 --- a/src/fsfw/tcdistribution/CMakeLists.txt +++ b/src/fsfw/tcdistribution/CMakeLists.txt @@ -1,4 +1,9 @@ target_sources( ${LIB_FSFW_NAME} - PRIVATE CCSDSDistributor.cpp PUSDistributor.cpp TcDistributor.cpp - TcPacketCheckPUS.cpp TcPacketCheckCFDP.cpp CFDPDistributor.cpp) + PRIVATE CCSDSDistributor.cpp + PusDistributor.cpp + TcDistributor.cpp + PusPacketChecker.cpp + TcPacketCheckCFDP.cpp + CFDPDistributor.cpp + CcsdsPacketCheckerBase.cpp) diff --git a/src/fsfw/tcdistribution/TcPacketCheckIF.h b/src/fsfw/tcdistribution/CcsdsPacketCheckIF.h similarity index 69% rename from src/fsfw/tcdistribution/TcPacketCheckIF.h rename to src/fsfw/tcdistribution/CcsdsPacketCheckIF.h index a9ec14a28..55288ae4c 100644 --- a/src/fsfw/tcdistribution/TcPacketCheckIF.h +++ b/src/fsfw/tcdistribution/CcsdsPacketCheckIF.h @@ -1,7 +1,9 @@ #ifndef FSFW_TCDISTRIBUTION_TCPACKETCHECKIF_H_ #define FSFW_TCDISTRIBUTION_TCPACKETCHECKIF_H_ -#include "../returnvalues/HasReturnvaluesIF.h" +#include + +#include "fsfw/returnvalues/HasReturnvaluesIF.h" class SpacePacketReader; @@ -9,22 +11,22 @@ class SpacePacketReader; * This interface is used by PacketCheckers for PUS packets and CFDP packets . * @ingroup tc_distribution */ -class TcPacketCheckIF { +class CcsdsPacketCheckIF { public: /** * The empty virtual destructor. */ - virtual ~TcPacketCheckIF() {} + virtual ~CcsdsPacketCheckIF() = default; /** * This is the actual method to formally check a certain Packet. * The packet's Application Data can not be checked here. * @param current_packet The packet to check * @return - @c RETURN_OK on success. - * - @c INCORRECT_CHECKSUM if checksum is invalid. - * - @c ILLEGAL_APID if APID does not match. + * - @c INCORRECT_CHECKSUM if checksum is invalid. + * - @c ILLEGAL_APID if APID does not match. */ - virtual ReturnValue_t checkPacket(SpacePacketReader* currentPacket) = 0; + virtual ReturnValue_t checkPacket(SpacePacketReader* currentPacket, size_t packetLen) = 0; }; #endif /* FSFW_TCDISTRIBUTION_TCPACKETCHECKIF_H_ */ diff --git a/src/fsfw/tcdistribution/CcsdsPacketCheckerBase.cpp b/src/fsfw/tcdistribution/CcsdsPacketCheckerBase.cpp new file mode 100644 index 000000000..8c97f646b --- /dev/null +++ b/src/fsfw/tcdistribution/CcsdsPacketCheckerBase.cpp @@ -0,0 +1,22 @@ +#include "CcsdsPacketCheckerBase.h" + +#include "fsfw/tcdistribution/definitions.h" +#include "fsfw/tmtcpacket/SpacePacketReader.h" + +CcsdsPacketCheckerBase::CcsdsPacketCheckerBase(uint16_t apid, ccsds::PacketType packetType_, + uint8_t ccsdsVersion_) + : apid(apid), packetType(packetType_), ccsdsVersion(ccsdsVersion_) {} + +ReturnValue_t CcsdsPacketCheckerBase::checkPacket(SpacePacketReader* currentPacket, + size_t packetLen) { + if (currentPacket->getApid() != apid) { + return tcdistrib::INVALID_APID; + } + if (currentPacket->getVersion() != ccsdsVersion) { + return tcdistrib::INVALID_CCSDS_VERSION; + } + if (currentPacket->getPacketType() != packetType) { + return tcdistrib::INVALID_PACKET_TYPE; + } + return HasReturnvaluesIF::RETURN_OK; +} \ No newline at end of file diff --git a/src/fsfw/tcdistribution/CcsdsPacketCheckerBase.h b/src/fsfw/tcdistribution/CcsdsPacketCheckerBase.h new file mode 100644 index 000000000..f5a9b3174 --- /dev/null +++ b/src/fsfw/tcdistribution/CcsdsPacketCheckerBase.h @@ -0,0 +1,17 @@ +#ifndef FSFW_TESTS_CCSDSPACKETCHECKERBASE_H +#define FSFW_TESTS_CCSDSPACKETCHECKERBASE_H + +#include "CcsdsPacketCheckIF.h" +#include "fsfw/tmtcpacket/SpacePacketIF.h" + +class CcsdsPacketCheckerBase : public CcsdsPacketCheckIF, public HasReturnvaluesIF { + public: + CcsdsPacketCheckerBase(uint16_t apid, ccsds::PacketType packetType, uint8_t ccsdsVersion = 0b000); + ReturnValue_t checkPacket(SpacePacketReader* currentPacket, size_t packetLen) override; + + protected: + uint16_t apid; + ccsds::PacketType packetType; + uint8_t ccsdsVersion; +}; +#endif // FSFW_TESTS_CCSDSPACKETCHECKERBASE_H diff --git a/src/fsfw/tcdistribution/TcPacketCheckCFDP.h b/src/fsfw/tcdistribution/CfdpPacketChecker.h similarity index 63% rename from src/fsfw/tcdistribution/TcPacketCheckCFDP.h rename to src/fsfw/tcdistribution/CfdpPacketChecker.h index 5a4abd4f0..0838efc26 100644 --- a/src/fsfw/tcdistribution/TcPacketCheckCFDP.h +++ b/src/fsfw/tcdistribution/CfdpPacketChecker.h @@ -1,16 +1,16 @@ #ifndef FSFW_TCDISTRIBUTION_TCPACKETCHECKCFDP_H_ #define FSFW_TCDISTRIBUTION_TCPACKETCHECKCFDP_H_ -#include "TcPacketCheckIF.h" +#include "CcsdsPacketCheckIF.h" #include "fsfw/FSFW.h" -class CFDPPacketStored; +class CfdpPacketStored; /** * This class performs a formal packet check for incoming CFDP Packets. * @ingroup tc_distribution */ -class TcPacketCheckCFDP : public TcPacketCheckIF, public HasReturnvaluesIF { +class CfdpPacketChecker : public CcsdsPacketCheckIF, public HasReturnvaluesIF { protected: /** * The packet id each correct packet should have. @@ -23,11 +23,11 @@ class TcPacketCheckCFDP : public TcPacketCheckIF, public HasReturnvaluesIF { * The constructor only sets the APID attribute. * @param set_apid The APID to set. */ - TcPacketCheckCFDP(uint16_t setApid); + explicit CfdpPacketChecker(uint16_t setApid); - ReturnValue_t checkPacket(SpacePacketReader* currentPacket) override; + ReturnValue_t checkPacket(SpacePacketReader* currentPacket, size_t packetLen) override; - uint16_t getApid() const; + [[nodiscard]] uint16_t getApid() const; }; #endif /* FSFW_TCDISTRIBUTION_TCPACKETCHECKCFDP_H_ */ diff --git a/src/fsfw/tcdistribution/PUSDistributor.cpp b/src/fsfw/tcdistribution/PusDistributor.cpp similarity index 75% rename from src/fsfw/tcdistribution/PUSDistributor.cpp rename to src/fsfw/tcdistribution/PusDistributor.cpp index dad002a1a..5975a7f24 100644 --- a/src/fsfw/tcdistribution/PUSDistributor.cpp +++ b/src/fsfw/tcdistribution/PusDistributor.cpp @@ -1,23 +1,25 @@ -#include "fsfw/tcdistribution/PUSDistributor.h" +#include "fsfw/tcdistribution/PusDistributor.h" #include "fsfw/objectmanager/ObjectManager.h" #include "fsfw/serviceinterface/ServiceInterface.h" #include "fsfw/tcdistribution/CCSDSDistributorIF.h" +#include "fsfw/tmtcpacket/PacketStorageHelper.h" #include "fsfw/tmtcservices/PusVerificationReport.h" #define PUS_DISTRIBUTOR_DEBUGGING 0 -PUSDistributor::PUSDistributor(uint16_t setApid, object_id_t setObjectId, +PusDistributor::PusDistributor(StorageManagerIF* store_, uint16_t setApid, object_id_t setObjectId, object_id_t setPacketSource) : TcDistributor(setObjectId), - checker(setApid), + store(store_), + checker(setApid, ccsds::PacketType::TC), verifyChannel(), tcStatus(RETURN_FAILED), packetSource(setPacketSource) {} -PUSDistributor::~PUSDistributor() = default; +PusDistributor::~PusDistributor() = default; -PUSDistributor::TcMqMapIter PUSDistributor::selectDestination() { +PusDistributor::TcMqMapIter PusDistributor::selectDestination() { #if FSFW_CPP_OSTREAM_ENABLED == 1 && PUS_DISTRIBUTOR_DEBUGGING == 1 store_address_t storeId = this->currentMessage.getStorageId()); sif::debug << "PUSDistributor::handlePacket received: " << storeId.poolIndex << ", " @@ -27,9 +29,18 @@ PUSDistributor::TcMqMapIter PUSDistributor::selectDestination() { if (this->currentPacket == nullptr) { return queueMapIt; } - this->currentPacket->setStoreAddress(this->currentMessage.getStorageId(), currentPacket); - if (currentPacket->getWholeData() != nullptr) { - tcStatus = checker.checkPacket(currentPacket); + // 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; + } + reader.setData(packetPtr, packetLen); + // this->currentPacket->setStoreAddress(this->currentMessage.getStorageId(), currentPacket); + if (reader.getFullData() != nullptr) { + tcStatus = + checker.checkPacket(dynamic_cast(&reader), reader.getFullPacketLen()); if (tcStatus != HasReturnvaluesIF::RETURN_OK) { #if FSFW_VERBOSE_LEVEL >= 1 const char* keyword = "unnamed error"; @@ -53,7 +64,7 @@ PUSDistributor::TcMqMapIter PUSDistributor::selectDestination() { #endif #endif } - uint32_t queue_id = currentPacket->getService(); + uint32_t queue_id = reader.getService(); queueMapIt = this->queueMap.find(queue_id); } else { tcStatus = PACKET_LOST; @@ -77,7 +88,7 @@ PUSDistributor::TcMqMapIter PUSDistributor::selectDestination() { } } -ReturnValue_t PUSDistributor::registerService(AcceptsTelecommandsIF* service) { +ReturnValue_t PusDistributor::registerService(AcceptsTelecommandsIF* service) { uint16_t serviceId = service->getIdentifier(); #if PUS_DISTRIBUTOR_DEBUGGING == 1 #if FSFW_CPP_OSTREAM_ENABLED == 1 @@ -103,29 +114,27 @@ ReturnValue_t PUSDistributor::registerService(AcceptsTelecommandsIF* service) { return HasReturnvaluesIF::RETURN_OK; } -MessageQueueId_t PUSDistributor::getRequestQueue() { return tcQueue->getId(); } +MessageQueueId_t PusDistributor::getRequestQueue() { return tcQueue->getId(); } -ReturnValue_t PUSDistributor::callbackAfterSending(ReturnValue_t queueStatus) { +ReturnValue_t PusDistributor::callbackAfterSending(ReturnValue_t queueStatus) { if (queueStatus != RETURN_OK) { tcStatus = queueStatus; } if (tcStatus != RETURN_OK) { - this->verifyChannel.sendFailureReport(tc_verification::ACCEPTANCE_FAILURE, currentPacket, - tcStatus); + this->verifyChannel.sendFailureReport(tc_verification::ACCEPTANCE_FAILURE, &reader, tcStatus); // A failed packet is deleted immediately after reporting, // otherwise it will block memory. - currentPacket->deletePacket(); + store->deleteData(currentMessage.getStorageId()); return RETURN_FAILED; } else { - this->verifyChannel.sendSuccessReport(tc_verification::ACCEPTANCE_SUCCESS, currentPacket); + this->verifyChannel.sendSuccessReport(tc_verification::ACCEPTANCE_SUCCESS, &reader); return RETURN_OK; } } -uint16_t PUSDistributor::getIdentifier() { return checker.getApid(); } +uint16_t PusDistributor::getIdentifier() { return checker.getApid(); } -ReturnValue_t PUSDistributor::initialize() { - currentPacket = new TcPacketStoredPus(); +ReturnValue_t PusDistributor::initialize() { if (currentPacket == nullptr) { // Should not happen, memory allocation failed! return ObjectManagerIF::CHILD_INIT_FAILED; @@ -137,7 +146,7 @@ ReturnValue_t PUSDistributor::initialize() { sif::error << "PUSDistributor::initialize: Packet source invalid" << std::endl; sif::error << " Make sure it exists and implements CCSDSDistributorIF!" << std::endl; #else - sif::printError("PUSDistributor::initialize: Packet source invalid\n"); + sif::printError("PusDistributor::initialize: Packet source invalid\n"); sif::printError("Make sure it exists and implements CCSDSDistributorIF\n"); #endif return RETURN_FAILED; diff --git a/src/fsfw/tcdistribution/PUSDistributor.h b/src/fsfw/tcdistribution/PusDistributor.h similarity index 84% rename from src/fsfw/tcdistribution/PUSDistributor.h rename to src/fsfw/tcdistribution/PusDistributor.h index c069c81b8..fb916263c 100644 --- a/src/fsfw/tcdistribution/PUSDistributor.h +++ b/src/fsfw/tcdistribution/PusDistributor.h @@ -2,20 +2,22 @@ #define FSFW_TCDISTRIBUTION_PUSDISTRIBUTOR_H_ #include "PUSDistributorIF.h" +#include "PusPacketChecker.h" #include "TcDistributor.h" -#include "TcPacketCheckPUS.h" #include "fsfw/returnvalues/HasReturnvaluesIF.h" #include "fsfw/tmtcpacket/pus/tc.h" #include "fsfw/tmtcservices/AcceptsTelecommandsIF.h" #include "fsfw/tmtcservices/VerificationReporter.h" +class PacketStorageHelper; + /** * This class accepts PUS Telecommands and forwards them to Application * services. In addition, the class performs a formal packet check and * 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,21 +27,23 @@ class PUSDistributor : public TcDistributor, public PUSDistributorIF, public Acc * @param setPacketSource Object ID of the source of TC packets. * Must implement CCSDSDistributorIF. */ - PUSDistributor(uint16_t setApid, object_id_t setObjectId, object_id_t setPacketSource); + PusDistributor(StorageManagerIF* store, uint16_t setApid, object_id_t setObjectId, + object_id_t setPacketSource); /** * The destructor is empty. */ - virtual ~PUSDistributor(); + ~PusDistributor() override; ReturnValue_t registerService(AcceptsTelecommandsIF* service) override; MessageQueueId_t getRequestQueue() override; ReturnValue_t initialize() override; uint16_t getIdentifier() override; protected: + StorageManagerIF* store; /** * This attribute contains the class, that performs a formal packet check. */ - TcPacketCheckPUS checker; + PusPacketChecker checker; /** * With this class, verification messages are sent to the * TC Verification service. @@ -48,7 +52,8 @@ class PUSDistributor : public TcDistributor, public PUSDistributorIF, public Acc /** * The currently handled packet is stored here. */ - TcPacketStoredPus* currentPacket = nullptr; + PacketStorageHelper* currentPacket = nullptr; + PusTcReader reader; /** * With this variable, the current check status is stored to generate diff --git a/src/fsfw/tcdistribution/PusPacketChecker.cpp b/src/fsfw/tcdistribution/PusPacketChecker.cpp new file mode 100644 index 000000000..828303b20 --- /dev/null +++ b/src/fsfw/tcdistribution/PusPacketChecker.cpp @@ -0,0 +1,44 @@ +#include "fsfw/tcdistribution/PusPacketChecker.h" + +#include "fsfw/globalfunctions/CRC.h" +#include "fsfw/serviceinterface/ServiceInterface.h" +#include "fsfw/tcdistribution/definitions.h" +#include "fsfw/tmtcpacket/pus/tc/PusTcReader.h" + +PusPacketChecker::PusPacketChecker(uint16_t setApid, ccsds::PacketType packetType_, + ecss::PusVersion pusVersion_) + : CcsdsPacketCheckerBase(setApid, packetType_), pusVersion(pusVersion_) {} + +ReturnValue_t PusPacketChecker::checkPacket(PacketCheckIF* pusPacket, size_t packetLen) { + if (pusPacket == nullptr) { + return RETURN_FAILED; + } + // Other primary header fields are checked by base class + if (not pusPacket->hasSecHeader()) { + return tcdistrib::INVALID_SEC_HEADER_FIELD; + } + uint16_t calculated_crc = + CRC::crc16ccitt(pusPacket->getFullData(), pusPacket->getFullPacketLen()); + if (calculated_crc != 0) { + return tcdistrib::INCORRECT_CHECKSUM; + } + + // This assumes that the getFullPacketLen version uses the space packet data length field + if (pusPacket->getFullPacketLen() != packetLen) { + return tcdistrib::INCOMPLETE_PACKET; + } + if (pusPacket->getPusVersion() != pusVersion) { + return tcdistrib::INVALID_PUS_VERSION; + } + return RETURN_OK; +} + +uint16_t PusPacketChecker::getApid() const { return apid; } + +ReturnValue_t PusPacketChecker::checkPacket(SpacePacketReader* currentPacket, size_t packetLen) { + ReturnValue_t result = CcsdsPacketCheckerBase::checkPacket(currentPacket, packetLen); + if (result != HasReturnvaluesIF::RETURN_OK) { + return result; + } + return checkPacket(dynamic_cast(currentPacket), packetLen); +} diff --git a/src/fsfw/tcdistribution/PusPacketChecker.h b/src/fsfw/tcdistribution/PusPacketChecker.h new file mode 100644 index 000000000..fe3413785 --- /dev/null +++ b/src/fsfw/tcdistribution/PusPacketChecker.h @@ -0,0 +1,38 @@ +#ifndef FSFW_TCDISTRIBUTION_TCPACKETCHECKPUS_H_ +#define FSFW_TCDISTRIBUTION_TCPACKETCHECKPUS_H_ + +#include "CcsdsPacketCheckIF.h" +#include "CcsdsPacketCheckerBase.h" +#include "fsfw/FSFW.h" +#include "fsfw/returnvalues/HasReturnvaluesIF.h" +#include "fsfw/tmtcpacket/pus/definitions.h" +#include "fsfw/tmtcservices/PusVerificationReport.h" + +class PacketCheckIF : public ReadablePacketIF, public PusIF {}; + +/** + * This class performs a formal packet check for incoming PUS Telecommand Packets. + * Currently, it only checks if the APID and CRC are correct. + * @ingroup tc_distribution + */ +class PusPacketChecker : public CcsdsPacketCheckerBase { + public: + /** + * The constructor only sets the APID attribute. + * @param set_apid The APID to set. + */ + PusPacketChecker(uint16_t setApid, ccsds::PacketType packetType, + ecss::PusVersion = ecss::PusVersion::PUS_C); + + ReturnValue_t checkPacket(PacketCheckIF* currentPacket, size_t packetLen); + + [[nodiscard]] uint16_t getApid() const; + + protected: + ecss::PusVersion pusVersion; + + private: + ReturnValue_t checkPacket(SpacePacketReader* currentPacket, size_t packetLen) override; +}; + +#endif /* FSFW_TCDISTRIBUTION_TCPACKETCHECKPUS_H_ */ diff --git a/src/fsfw/tcdistribution/TcDistributor.cpp b/src/fsfw/tcdistribution/TcDistributor.cpp index a650546c1..600b3ca99 100644 --- a/src/fsfw/tcdistribution/TcDistributor.cpp +++ b/src/fsfw/tcdistribution/TcDistributor.cpp @@ -24,7 +24,7 @@ ReturnValue_t TcDistributor::performOperation(uint8_t opCode) { } ReturnValue_t TcDistributor::handlePacket() { - TcMqMapIter queueMapIt = this->selectDestination(); + auto queueMapIt = this->selectDestination(); ReturnValue_t returnValue = RETURN_FAILED; if (queueMapIt != this->queueMap.end()) { returnValue = this->tcQueue->sendMessage(queueMapIt->second, &this->currentMessage); diff --git a/src/fsfw/tcdistribution/TcPacketCheckCFDP.cpp b/src/fsfw/tcdistribution/TcPacketCheckCFDP.cpp index 7d2bfe88f..555c85b45 100644 --- a/src/fsfw/tcdistribution/TcPacketCheckCFDP.cpp +++ b/src/fsfw/tcdistribution/TcPacketCheckCFDP.cpp @@ -1,9 +1,10 @@ -#include "fsfw/tcdistribution/TcPacketCheckCFDP.h" +#include "fsfw/tcdistribution/CfdpPacketChecker.h" +#include "fsfw/tmtcpacket/cfdp/CfdpPacketStored.h" -#include "fsfw/tmtcpacket/cfdp/CFDPPacketStored.h" +CfdpPacketChecker::CfdpPacketChecker(uint16_t setApid) : apid(setApid) {} -TcPacketCheckCFDP::TcPacketCheckCFDP(uint16_t setApid) : apid(setApid) {} +ReturnValue_t CfdpPacketChecker::checkPacket(SpacePacketReader* currentPacket, size_t packetLen) { + return RETURN_OK; +} -ReturnValue_t TcPacketCheckCFDP::checkPacket(SpacePacketReader* currentPacket) { return RETURN_OK; } - -uint16_t TcPacketCheckCFDP::getApid() const { return apid; } +uint16_t CfdpPacketChecker::getApid() const { return apid; } diff --git a/src/fsfw/tcdistribution/TcPacketCheckPUS.cpp b/src/fsfw/tcdistribution/TcPacketCheckPUS.cpp deleted file mode 100644 index 963bece77..000000000 --- a/src/fsfw/tcdistribution/TcPacketCheckPUS.cpp +++ /dev/null @@ -1,44 +0,0 @@ -#include "fsfw/tcdistribution/TcPacketCheckPUS.h" - -#include "fsfw/globalfunctions/CRC.h" -#include "fsfw/serviceinterface/ServiceInterface.h" -#include "fsfw/storagemanager/StorageManagerIF.h" -#include "fsfw/tmtcpacket/pus/tc/PusTcReader.h" -#include "fsfw/tmtcpacket/pus/tc/TcPacketStoredBase.h" -#include "fsfw/tmtcpacket/pus/tc/TcPacketStoredPus.h" -#include "fsfw/tmtcservices/VerificationCodes.h" - -TcPacketCheckPUS::TcPacketCheckPUS(uint16_t setApid) : apid(setApid) {} - -ReturnValue_t TcPacketCheckPUS::checkPacket(SpacePacketReader* currentPacket) { - auto* storedPacket = dynamic_cast(currentPacket); - auto* tcPacketBase = dynamic_cast(currentPacket); - if (tcPacketBase == nullptr or storedPacket == nullptr) { - return RETURN_FAILED; - } - uint16_t calculated_crc = - CRC::crc16ccitt(tcPacketBase->getWholeData(), tcPacketBase->getFullSize()); - if (calculated_crc != 0) { - return INCORRECT_CHECKSUM; - } - bool condition = (not tcPacketBase->hasSecHeader()) or - (tcPacketBase->getVersion() != CCSDS_VERSION_NUMBER) or - (not tcPacketBase->isTc()); - if (condition) { - return INCORRECT_PRIMARY_HEADER; - } - if (tcPacketBase->getApid() != this->apid) return ILLEGAL_APID; - - if (not storedPacket->isSizeCorrect()) { - return INCOMPLETE_PACKET; - } - - condition = (tcPacketBase->getSecondaryHeaderFlag() != CCSDS_SECONDARY_HEADER_FLAG) || - (tcPacketBase->getPusVersionNumber() != PUS_VERSION_NUMBER); - if (condition) { - return INCORRECT_SECONDARY_HEADER; - } - return RETURN_OK; -} - -uint16_t TcPacketCheckPUS::getApid() const { return apid; } diff --git a/src/fsfw/tcdistribution/TcPacketCheckPUS.h b/src/fsfw/tcdistribution/TcPacketCheckPUS.h deleted file mode 100644 index 4804a619d..000000000 --- a/src/fsfw/tcdistribution/TcPacketCheckPUS.h +++ /dev/null @@ -1,61 +0,0 @@ -#ifndef FSFW_TCDISTRIBUTION_TCPACKETCHECKPUS_H_ -#define FSFW_TCDISTRIBUTION_TCPACKETCHECKPUS_H_ - -#include "TcPacketCheckIF.h" -#include "fsfw/FSFW.h" -#include "fsfw/returnvalues/HasReturnvaluesIF.h" -#include "fsfw/tmtcservices/PusVerificationReport.h" - -class TcPacketStoredBase; - -/** - * This class performs a formal packet check for incoming PUS Telecommand Packets. - * Currently, it only checks if the APID and CRC are correct. - * @ingroup tc_distribution - */ -class TcPacketCheckPUS : public TcPacketCheckIF, public HasReturnvaluesIF { - protected: - /** - * Describes the version number a packet must have to pass. - */ - static constexpr uint8_t CCSDS_VERSION_NUMBER = 0; - /** - * Describes the secondary header a packet must have to pass. - */ - static constexpr uint8_t CCSDS_SECONDARY_HEADER_FLAG = 0; - /** - * Describes the TC Packet PUS Version Number a packet must have to pass. - */ -#if FSFW_USE_PUS_C_TELECOMMANDS == 1 - static constexpr uint8_t PUS_VERSION_NUMBER = 2; -#else - static constexpr uint8_t PUS_VERSION_NUMBER = 1; -#endif - - /** - * The packet id each correct packet should have. - * It is composed of the APID and some static fields. - */ - uint16_t apid; - - public: - static const uint8_t INTERFACE_ID = CLASS_ID::TC_PACKET_CHECK; - static const ReturnValue_t ILLEGAL_APID = MAKE_RETURN_CODE(0); - static const ReturnValue_t INCOMPLETE_PACKET = MAKE_RETURN_CODE(1); - static const ReturnValue_t INCORRECT_CHECKSUM = MAKE_RETURN_CODE(2); - static const ReturnValue_t ILLEGAL_PACKET_TYPE = MAKE_RETURN_CODE(3); - static const ReturnValue_t ILLEGAL_PACKET_SUBTYPE = MAKE_RETURN_CODE(4); - static const ReturnValue_t INCORRECT_PRIMARY_HEADER = MAKE_RETURN_CODE(5); - static const ReturnValue_t INCORRECT_SECONDARY_HEADER = MAKE_RETURN_CODE(6); - /** - * The constructor only sets the APID attribute. - * @param set_apid The APID to set. - */ - TcPacketCheckPUS(uint16_t setApid); - - ReturnValue_t checkPacket(SpacePacketReader* currentPacket) override; - - uint16_t getApid() const; -}; - -#endif /* FSFW_TCDISTRIBUTION_TCPACKETCHECKPUS_H_ */ diff --git a/src/fsfw/tcdistribution/definitions.h b/src/fsfw/tcdistribution/definitions.h new file mode 100644 index 000000000..ce6403085 --- /dev/null +++ b/src/fsfw/tcdistribution/definitions.h @@ -0,0 +1,24 @@ +#ifndef FSFW_TMTCPACKET_DEFINITIONS_H +#define FSFW_TMTCPACKET_DEFINITIONS_H + +#include + +#include "fsfw/returnvalues/FwClassIds.h" +#include "fsfw/returnvalues/HasReturnvaluesIF.h" + +namespace tcdistrib { +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 constexpr ReturnValue_t INCOMPLETE_PACKET = MAKE_RETURN_CODE(5); +static constexpr ReturnValue_t INVALID_PUS_VERSION = MAKE_RETURN_CODE(6); +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 +#endif // FSFW_TMTCPACKET_DEFINITIONS_H diff --git a/src/fsfw/tmstorage/TmStorePackets.h b/src/fsfw/tmstorage/TmStorePackets.h index d54b7b52a..0640fd361 100644 --- a/src/fsfw/tmstorage/TmStorePackets.h +++ b/src/fsfw/tmstorage/TmStorePackets.h @@ -8,7 +8,7 @@ #include "fsfw/serialize/SerializeElement.h" #include "fsfw/timemanager/CCSDSTime.h" #include "fsfw/timemanager/TimeStamperIF.h" -#include "fsfw/tmtcpacket/pus/tm/TmPacketMinimal.h" +#include "fsfw/tmtcpacket/pus/tm/PusTmMinimal.h" #include "tmStorageConf.h" class ServiceSubservice : public SerialLinkedListAdapter { diff --git a/src/fsfw/tmtcpacket/CMakeLists.txt b/src/fsfw/tmtcpacket/CMakeLists.txt index 85376d01b..69b3cc483 100644 --- a/src/fsfw/tmtcpacket/CMakeLists.txt +++ b/src/fsfw/tmtcpacket/CMakeLists.txt @@ -1,4 +1,6 @@ -target_sources(${LIB_FSFW_NAME} PRIVATE SpacePacketReader.cpp) +target_sources( + ${LIB_FSFW_NAME} PRIVATE SpacePacketReader.cpp SpacePacketCreator.cpp + PacketStorageHelper.cpp) add_subdirectory(cfdp) add_subdirectory(packetmatcher) diff --git a/src/fsfw/tmtcpacket/PacketStorageHelper.cpp b/src/fsfw/tmtcpacket/PacketStorageHelper.cpp new file mode 100644 index 000000000..891842514 --- /dev/null +++ b/src/fsfw/tmtcpacket/PacketStorageHelper.cpp @@ -0,0 +1,25 @@ +#include "PacketStorageHelper.h" + +#include + +#include "fsfw/serialize.h" +#include "fsfw/serviceinterface/ServiceInterface.h" +#include "fsfw/storagemanager/StorageManagerIF.h" + +PacketStorageHelper::PacketStorageHelper(StorageManagerIF* store_, + SerializeIF::Endianness endianness_) + : store(store_), endianness(endianness_) {} + +ReturnValue_t PacketStorageHelper::addPacket(SerializeIF* packet, store_address_t& storeId) { + uint8_t* ptr = nullptr; + size_t serLen = 0; + ReturnValue_t result = store->getFreeElement(&storeId, packet->getSerializedSize(), &ptr); + if (result != HasReturnvaluesIF::RETURN_OK) { + return result; + } + return packet->serialize(&ptr, &serLen, packet->getSerializedSize(), endianness); +} + +ReturnValue_t PacketStorageHelper::deletePacket(store_address_t storeId) { + return store->deleteData(storeId); +} diff --git a/src/fsfw/tmtcpacket/PacketStorageHelper.h b/src/fsfw/tmtcpacket/PacketStorageHelper.h new file mode 100644 index 000000000..1be75b23f --- /dev/null +++ b/src/fsfw/tmtcpacket/PacketStorageHelper.h @@ -0,0 +1,63 @@ +#ifndef FSFW_TMTCPACKET_PUS_TCPACKETSTOREDPUSA_H_ +#define FSFW_TMTCPACKET_PUS_TCPACKETSTOREDPUSA_H_ + +#include "fsfw/returnvalues/HasReturnvaluesIF.h" +#include "fsfw/serialize.h" +#include "fsfw/storagemanager/storeAddress.h" + +class StorageManagerIF; + +class PacketStorageHelper { + public: + explicit PacketStorageHelper(StorageManagerIF* store, SerializeIF::Endianness endianness); + + ReturnValue_t addPacket(SerializeIF* packet, store_address_t& storeId); + ReturnValue_t deletePacket(store_address_t storeId); + + private: + StorageManagerIF* store; + SerializeIF::Endianness endianness; +}; +// class TcPacketStoredPus : public TcPacketStoredBase, public TcPacketPus { +// public: +// /** +// * With this constructor, new space is allocated in the packet store and +// * a new PUS Telecommand Packet is created there. +// * Packet Application Data passed in data is copied into the packet. +// * @param apid Sets the packet's APID field. +// * @param service Sets the packet's Service ID field. +// * This specifies the destination service. +// * @param subservice Sets the packet's Service Subtype field. +// * This specifies the destination sub-service. +// * @param sequence_count Sets the packet's Source Sequence Count field. +// * @param data The data to be copied to the Application Data Field. +// * @param size The amount of data to be copied. +// * @param ack Set's the packet's Ack field, which specifies +// * number of verification packets returned +// * for this command. +// */ +// TcPacketStoredPus(uint16_t apid, uint8_t service, uint8_t subservice, uint8_t sequence_count = +// 0, +// const uint8_t* data = nullptr, size_t size = 0, +// uint8_t ack = TcPacketPusBase::ACK_ALL); +// /** +// * Create stored packet with existing data. +// * @param data +// * @param size +// */ +// TcPacketStoredPus(const uint8_t* data, size_t size); +// /** +// * Create stored packet from existing packet in store +// * @param setAddress +// */ +// TcPacketStoredPus(store_address_t setAddress); +// TcPacketStoredPus(); +// +// ReturnValue_t deletePacket() override; +// TcPacketPusBase* getPacketBase(); +// +// private: +// bool isSizeCorrect() override; +// }; + +#endif /* FSFW_TMTCPACKET_PUS_TCPACKETSTOREDPUSA_H_ */ diff --git a/src/fsfw/tmtcpacket/ReadablePacketIF.h b/src/fsfw/tmtcpacket/ReadablePacketIF.h new file mode 100644 index 000000000..c1287e816 --- /dev/null +++ b/src/fsfw/tmtcpacket/ReadablePacketIF.h @@ -0,0 +1,13 @@ +#ifndef FSFW_TMTCPACKET_SPACEPACKETREADERIF_H +#define FSFW_TMTCPACKET_SPACEPACKETREADERIF_H + +#include "SpacePacketIF.h" + +class ReadablePacketIF { + public: + /** + * This method returns a raw uint8_t pointer to the readable data + */ + virtual const uint8_t* getFullData() = 0; +}; +#endif // FSFW_TMTCPACKET_SPACEPACKETREADERIF_H diff --git a/src/fsfw/tmtcpacket/RedirectableDataPointerIF.h b/src/fsfw/tmtcpacket/RedirectableDataPointerIF.h index 6eb16eddf..560380369 100644 --- a/src/fsfw/tmtcpacket/RedirectableDataPointerIF.h +++ b/src/fsfw/tmtcpacket/RedirectableDataPointerIF.h @@ -25,9 +25,9 @@ class RedirectableDataPointerIF { * - RETURN_OK if the pointer was set successfully * - RETURN_FAILED on general error of if the maximum size is too small */ - virtual ReturnValue_t setData(uint8_t* dataPtr, size_t maxSize, void* args) = 0; - virtual ReturnValue_t setData(uint8_t* dataPtr, size_t maxSize) { - return setData(dataPtr, maxSize, nullptr); + virtual ReturnValue_t setData(uint8_t* dataPtr, size_t size, void* args) = 0; + virtual ReturnValue_t setData(uint8_t* dataPtr, size_t size) { + return setData(dataPtr, size, nullptr); } private: diff --git a/src/fsfw/tmtcpacket/SpacePacketCreator.cpp b/src/fsfw/tmtcpacket/SpacePacketCreator.cpp index acc2fea2a..ff131059a 100644 --- a/src/fsfw/tmtcpacket/SpacePacketCreator.cpp +++ b/src/fsfw/tmtcpacket/SpacePacketCreator.cpp @@ -2,44 +2,32 @@ #include "fsfw/serialize/SerializeAdapter.h" -SpacePacketCreator::SpacePacketCreator(PacketId packetId_, PacketSeqCtrl psc_, uint16_t dataLen_, - uint8_t version_) - : packetId(packetId_), packetSeqCtrl(psc_) { - dataLen = dataLen_; - version = version_; +SpacePacketCreator::SpacePacketCreator(SpacePacketParams ¶ms_) : params(params_) { checkFieldValidity(); } -SpacePacketCreator::SpacePacketCreator(ccsds::PacketType packetType, bool secHeaderFlag, - uint16_t apid, ccsds::SequenceFlags seqFlags, - uint16_t seqCount, uint16_t dataLen_, uint8_t version_) - : SpacePacketCreator(PacketId(packetType, secHeaderFlag, apid), - PacketSeqCtrl(seqFlags, seqCount), dataLen_, version_) { - version = version_; - dataLen = dataLen_; -} - -uint16_t SpacePacketCreator::getPacketId() const { return packetId.raw(); } -uint16_t SpacePacketCreator::getPacketSeqCtrl() const { return packetSeqCtrl.raw(); } -uint16_t SpacePacketCreator::getPacketDataLen() const { return dataLen; } +uint16_t SpacePacketCreator::getPacketId() const { return params.packetId.raw(); } +uint16_t SpacePacketCreator::getPacketSeqCtrl() const { return params.packetSeqCtrl.raw(); } +uint16_t SpacePacketCreator::getPacketDataLen() const { return params.dataLen; } ReturnValue_t SpacePacketCreator::serialize(uint8_t **buffer, size_t *size, size_t maxSize, SerializeIF::Endianness streamEndianness) const { if (not isValid()) { return HasReturnvaluesIF::RETURN_FAILED; } - uint16_t packetIdAndVersion = (static_cast(version) << 13) | packetId.raw(); + uint16_t packetIdAndVersion = + (static_cast(params.version) << 13) | params.packetId.raw(); ReturnValue_t result = SerializeAdapter::serialize(&packetIdAndVersion, buffer, size, maxSize, streamEndianness); if (result != HasReturnvaluesIF::RETURN_OK) { return result; } - uint16_t pscRaw = packetSeqCtrl.raw(); + uint16_t pscRaw = params.packetSeqCtrl.raw(); result = SerializeAdapter::serialize(&pscRaw, buffer, size, maxSize, streamEndianness); if (result != HasReturnvaluesIF::RETURN_OK) { return result; } - return SerializeAdapter::serialize(&dataLen, buffer, size, maxSize, streamEndianness); + return SerializeAdapter::serialize(¶ms.dataLen, buffer, size, maxSize, streamEndianness); } size_t SpacePacketCreator::getSerializedSize() const { return 6; } @@ -55,22 +43,25 @@ ReturnValue_t SpacePacketCreator::serialize(uint8_t **buffer, size_t *size, size } void SpacePacketCreator::setApid(uint16_t apid) { if (apid < ccsds::LIMIT_APID) { - packetId.apid = apid; + params.packetId.apid = apid; } checkFieldValidity(); } void SpacePacketCreator::setSeqCount(uint16_t seqCount) { if (seqCount < ccsds::LIMIT_SEQUENCE_COUNT) { - packetSeqCtrl.seqCount = seqCount; + params.packetSeqCtrl.seqCount = seqCount; } checkFieldValidity(); } -void SpacePacketCreator::setSeqFlags(ccsds::SequenceFlags flags) { packetSeqCtrl.seqFlags = flags; } -void SpacePacketCreator::setDataLen(uint16_t dataLen_) { dataLen = dataLen_; } +void SpacePacketCreator::setSeqFlags(ccsds::SequenceFlags flags) { + params.packetSeqCtrl.seqFlags = flags; +} +void SpacePacketCreator::setDataLen(uint16_t dataLen_) { params.dataLen = dataLen_; } void SpacePacketCreator::checkFieldValidity() { valid = true; - if (packetId.apid > ccsds::LIMIT_APID or packetSeqCtrl.seqCount > ccsds::LIMIT_SEQUENCE_COUNT) { + if (params.packetId.apid > ccsds::LIMIT_APID or + params.packetSeqCtrl.seqCount > ccsds::LIMIT_SEQUENCE_COUNT) { valid = false; } } diff --git a/src/fsfw/tmtcpacket/SpacePacketCreator.h b/src/fsfw/tmtcpacket/SpacePacketCreator.h index 9a9a0e2df..9c74046bb 100644 --- a/src/fsfw/tmtcpacket/SpacePacketCreator.h +++ b/src/fsfw/tmtcpacket/SpacePacketCreator.h @@ -45,12 +45,21 @@ struct PacketSeqCtrl { uint16_t seqCount; }; -class SpacePacketCreator : public SerializeIF, public SpacePacketIF { +struct SpacePacketParams { + PacketId packetId; + PacketSeqCtrl packetSeqCtrl; + uint16_t dataLen; + uint8_t version = 0b000; +}; + +class SpacePacketCreator : public SpacePacketIF, public SerializeIF { public: + /* SpacePacketCreator(ccsds::PacketType packetType, bool secHeaderFlag, uint16_t apid, ccsds::SequenceFlags seqFlags, uint16_t seqCount, uint16_t dataLen, uint8_t version = 0); - SpacePacketCreator(PacketId packetId, PacketSeqCtrl psc, uint16_t dataLen, uint8_t version = 0); + */ + explicit SpacePacketCreator(SpacePacketParams ¶ms); [[nodiscard]] bool isValid() const; [[nodiscard]] uint16_t getPacketId() const override; [[nodiscard]] uint16_t getPacketSeqCtrl() const override; @@ -73,9 +82,6 @@ class SpacePacketCreator : public SerializeIF, public SpacePacketIF { void checkFieldValidity(); bool valid{}; - PacketId packetId; - PacketSeqCtrl packetSeqCtrl; - uint16_t dataLen; - uint8_t version; + SpacePacketParams params; }; #endif // FSFW_TMTCPACKET_SPACEPACKETCREATOR_H diff --git a/src/fsfw/tmtcpacket/SpacePacketIF.h b/src/fsfw/tmtcpacket/SpacePacketIF.h index 1b2bfb903..21ee4c322 100644 --- a/src/fsfw/tmtcpacket/SpacePacketIF.h +++ b/src/fsfw/tmtcpacket/SpacePacketIF.h @@ -1,6 +1,7 @@ #ifndef FSFW_TMTCPACKET_SPACEPACKETIF_H #define FSFW_TMTCPACKET_SPACEPACKETIF_H +#include #include #include "ccsds_header.h" @@ -72,6 +73,10 @@ class SpacePacketIF { return ((packetId >> 8) & 0b111) | (packetId & 0xFF); } + /** + * Returns the CCSDS version number + * @return + */ [[nodiscard]] virtual uint8_t getVersion() const { uint16_t packetId = getPacketId(); return (packetId >> 13) & 0b111; @@ -97,6 +102,14 @@ class SpacePacketIF { } [[nodiscard]] virtual uint16_t getSequenceCount() const { return getPacketSeqCtrl() & 0x3FFF; } + + /** + * Returns the full packet length based of the packet data length field + * @return + */ + [[nodiscard]] virtual size_t getFullPacketLen() const { + return sizeof(CCSDSPrimaryHeader) + getPacketDataLen() + 1; + } }; #endif // FSFW_TMTCPACKET_SPACEPACKETIF_H diff --git a/src/fsfw/tmtcpacket/SpacePacketReader.cpp b/src/fsfw/tmtcpacket/SpacePacketReader.cpp index cdb000825..2d7d2edac 100644 --- a/src/fsfw/tmtcpacket/SpacePacketReader.cpp +++ b/src/fsfw/tmtcpacket/SpacePacketReader.cpp @@ -2,39 +2,44 @@ #include +#include "fsfw/serialize/SerializeIF.h" #include "fsfw/serviceinterface/ServiceInterface.h" -SpacePacketReader::SpacePacketReader(const uint8_t* setAddress) { - this->data = reinterpret_cast(const_cast(setAddress)); +SpacePacketReader::SpacePacketReader(const uint8_t* setAddress, size_t maxSize_) { + setInternalFields(setAddress, maxSize_); +} + +ReturnValue_t SpacePacketReader::checkLength() const { + if (getFullPacketLen() > maxSize) { + return SerializeIF::STREAM_TOO_SHORT; + } + return HasReturnvaluesIF::RETURN_OK; } SpacePacketReader::~SpacePacketReader() = default; inline uint16_t SpacePacketReader::getPacketId() const { - return ((this->data->header.packetIdHAndVersion) << 8) + this->data->header.packetIdL; + return ((spHeader->packetIdHAndVersion) << 8) + spHeader->packetIdL; } -size_t SpacePacketReader::getFullSize() { - // +1 is done because size in packet data length field is: size of data field -1 - return this->getPacketDataLen() + sizeof(this->data->header) + 1; +const uint8_t* SpacePacketReader::getPacketData() { return packetDataField; } + +ReturnValue_t SpacePacketReader::setData(uint8_t* pData, size_t maxSize_, void* args) { + setInternalFields(pData, maxSize_); } -uint8_t* SpacePacketReader::getWholeData() { return reinterpret_cast(this->data); } - -uint8_t* SpacePacketReader::getPacketData() { return &(data->packet_data); } - -ReturnValue_t SpacePacketReader::setData(uint8_t* pData, size_t maxSize, void* args) { - if (maxSize < 6) { - return HasReturnvaluesIF::RETURN_FAILED; - } - this->data = reinterpret_cast(const_cast(pData)); - return HasReturnvaluesIF::RETURN_OK; -} uint16_t SpacePacketReader::getPacketSeqCtrl() const { - return ((this->data->header.packetSeqCtrlH & 0b00111111) << 8) + - this->data->header.packetSeqCtrlL; + return (spHeader->packetSeqCtrlH << 8) + spHeader->packetSeqCtrlL; } uint16_t SpacePacketReader::getPacketDataLen() const { - return ((this->data->header.packetLenH) << 8) + this->data->header.packetLenL; + return (spHeader->packetLenH << 8) | spHeader->packetIdL; } +void SpacePacketReader::setInternalFields(const uint8_t* data, size_t maxSize_) { + maxSize = maxSize_; + spHeader = reinterpret_cast(data); + packetDataField = data + sizeof(CCSDSPrimaryHeader); +} +const uint8_t* SpacePacketReader::getFullData() { + return reinterpret_cast(spHeader); +}; diff --git a/src/fsfw/tmtcpacket/SpacePacketReader.h b/src/fsfw/tmtcpacket/SpacePacketReader.h index 81151fab3..eb1d5c937 100644 --- a/src/fsfw/tmtcpacket/SpacePacketReader.h +++ b/src/fsfw/tmtcpacket/SpacePacketReader.h @@ -5,7 +5,7 @@ #include -#include "SpacePacketIF.h" +#include "ReadablePacketIF.h" #include "ccsds_header.h" #include "fsfw/returnvalues/HasReturnvaluesIF.h" @@ -30,22 +30,17 @@ * the most significant bit (from left). * @ingroup tmtcpackets */ -class SpacePacketReader : public SpacePacketIF, public RedirectableDataPointerIF { - protected: - /** - * A pointer to a structure which defines the data structure of - * the packet header. - * To be hardware-safe, all elements are of byte size. - */ - SpacePacketPointer* data; - +class SpacePacketReader : public SpacePacketIF, + public ReadablePacketIF, + public RedirectableDataPointerIF { public: + SpacePacketReader() = default; /** * This is the default constructor. * It sets its internal data pointer to the address passed. * @param set_address The position where the packet data lies. */ - explicit SpacePacketReader(const uint8_t* set_address); + explicit SpacePacketReader(const uint8_t* setAddress, size_t maxSize); /** * No data is allocated, so the destructor is empty. */ @@ -55,14 +50,12 @@ class SpacePacketReader : public SpacePacketIF, public RedirectableDataPointerIF [[nodiscard]] uint16_t getPacketSeqCtrl() const override; [[nodiscard]] uint16_t getPacketDataLen() const override; - // Helper methods: - /** - * This method returns a raw uint8_t pointer to the packet. - * @return A \c uint8_t pointer to the first byte of the CCSDS primary header. - */ - virtual uint8_t* getWholeData(); + const uint8_t* getFullData() override; - uint8_t* getPacketData(); + // Helper methods: + [[nodiscard]] ReturnValue_t checkLength() const; + + const uint8_t* getPacketData(); /** * With this method, the packet data pointer can be redirected to another @@ -70,11 +63,18 @@ class SpacePacketReader : public SpacePacketIF, public RedirectableDataPointerIF * @param p_Data A pointer to another raw Space Packet. */ ReturnValue_t setData(uint8_t* p_Data, size_t maxSize, void* args) override; + + protected: /** - * This method returns the full raw packet size. - * @return The full size of the packet in bytes. + * A pointer to a structure which defines the data structure of + * the packet header. + * To be hardware-safe, all elements are of byte size. */ - size_t getFullSize(); + const CCSDSPrimaryHeader* spHeader{}; + const uint8_t* packetDataField{}; + size_t maxSize = 0; + + void setInternalFields(const uint8_t* data, size_t maxSize); }; #endif /* FSFW_TMTCPACKET_SPACEPACKETBASE_H_ */ diff --git a/src/fsfw/tmtcpacket/cfdp/CFDPPacket.cpp b/src/fsfw/tmtcpacket/cfdp/CFDPPacket.cpp index 29b6c5612..b4a8534c6 100644 --- a/src/fsfw/tmtcpacket/cfdp/CFDPPacket.cpp +++ b/src/fsfw/tmtcpacket/cfdp/CFDPPacket.cpp @@ -1,4 +1,4 @@ -#include "fsfw/tmtcpacket/cfdp/CFDPPacket.h" +#include "fsfw/tmtcpacket/cfdp/CfdpPacket.h" #include @@ -6,15 +6,16 @@ #include "fsfw/globalfunctions/arrayprinter.h" #include "fsfw/serviceinterface/ServiceInterface.h" -CFDPPacket::CFDPPacket(const uint8_t* setData) : SpacePacketReader(setData) {} +CfdpReader::CfdpReader(const uint8_t* setData, size_t maxSize) + : SpacePacketReader(setData, maxSize) {} -CFDPPacket::~CFDPPacket() {} +CfdpReader::~CfdpReader() = default; -void CFDPPacket::print() { +void CfdpReader::print() { #if FSFW_CPP_OSTREAM_ENABLED == 1 sif::info << "CFDPPacket::print:" << std::endl; #else sif::printInfo("CFDPPacket::print:\n"); #endif - arrayprinter::print(getWholeData(), getFullSize()); + // arrayprinter::print(getWholeData(), getFullSize()); } diff --git a/src/fsfw/tmtcpacket/cfdp/CFDPPacketStored.cpp b/src/fsfw/tmtcpacket/cfdp/CFDPPacketStored.cpp index 260331ac3..e597cf359 100644 --- a/src/fsfw/tmtcpacket/cfdp/CFDPPacketStored.cpp +++ b/src/fsfw/tmtcpacket/cfdp/CFDPPacketStored.cpp @@ -1,14 +1,14 @@ -#include "fsfw/tmtcpacket/cfdp/CFDPPacketStored.h" +#include "fsfw/tmtcpacket/cfdp/CfdpPacketStored.h" #include "fsfw/objectmanager/ObjectManager.h" -CFDPPacketStored::CFDPPacketStored() : CFDPPacket(nullptr) {} +CfdpPacketStored::CfdpPacketStored() : CfdpReader(nullptr) {} -CFDPPacketStored::CFDPPacketStored(store_address_t setAddress) : CFDPPacket(nullptr) { +CfdpPacketStored::CfdpPacketStored(store_address_t setAddress) : CfdpReader(nullptr) { this->setStoreAddress(setAddress); } -CFDPPacketStored::CFDPPacketStored(const uint8_t* data, size_t size) : CFDPPacket(data) { +CfdpPacketStored::CfdpPacketStored(const uint8_t* data, size_t size) : CfdpReader(data) { if (this->getFullSize() != size) { return; } @@ -24,7 +24,7 @@ CFDPPacketStored::CFDPPacketStored(const uint8_t* data, size_t size) : CFDPPacke } } -ReturnValue_t CFDPPacketStored::deletePacket() { +ReturnValue_t CfdpPacketStored::deletePacket() { ReturnValue_t result = STORE->deleteData(this->storeAddress); this->storeAddress.raw = StorageManagerIF::INVALID_ADDRESS; // To circumvent size checks @@ -35,7 +35,7 @@ ReturnValue_t CFDPPacketStored::deletePacket() { // CFDPPacket* CFDPPacketStored::getPacketBase() { // return this; // } -void CFDPPacketStored::setStoreAddress(store_address_t setAddress) { +void CfdpPacketStored::setStoreAddress(store_address_t setAddress) { this->storeAddress = setAddress; const uint8_t* tempData = nullptr; size_t tempSize; @@ -52,11 +52,11 @@ void CFDPPacketStored::setStoreAddress(store_address_t setAddress) { } } -store_address_t CFDPPacketStored::getStoreAddress() { return this->storeAddress; } +store_address_t CfdpPacketStored::getStoreAddress() { return this->storeAddress; } -CFDPPacketStored::~CFDPPacketStored() = default; +CfdpPacketStored::~CfdpPacketStored() = default; -ReturnValue_t CFDPPacketStored::getData(const uint8_t** dataPtr, size_t* dataSize) { +ReturnValue_t CfdpPacketStored::getData(const uint8_t** dataPtr, size_t* dataSize) { return HasReturnvaluesIF::RETURN_OK; } @@ -64,7 +64,7 @@ ReturnValue_t CFDPPacketStored::getData(const uint8_t** dataPtr, size_t* dataSiz // return HasReturnvaluesIF::RETURN_OK; // } -bool CFDPPacketStored::checkAndSetStore() { +bool CfdpPacketStored::checkAndSetStore() { if (STORE == nullptr) { STORE = ObjectManager::instance()->get(objects::TC_STORE); if (STORE == nullptr) { @@ -77,7 +77,7 @@ bool CFDPPacketStored::checkAndSetStore() { return true; } -bool CFDPPacketStored::isSizeCorrect() { +bool CfdpPacketStored::isSizeCorrect() { const uint8_t* temp_data = nullptr; size_t temp_size; ReturnValue_t status = STORE->getData(this->storeAddress, &temp_data, &temp_size); diff --git a/src/fsfw/tmtcpacket/cfdp/CMakeLists.txt b/src/fsfw/tmtcpacket/cfdp/CMakeLists.txt index 7d20aab88..a0d48465e 100644 --- a/src/fsfw/tmtcpacket/cfdp/CMakeLists.txt +++ b/src/fsfw/tmtcpacket/cfdp/CMakeLists.txt @@ -1 +1 @@ -target_sources(${LIB_FSFW_NAME} PRIVATE CFDPPacket.cpp CFDPPacketStored.cpp) +target_sources(${LIB_FSFW_NAME} PRIVATE) diff --git a/src/fsfw/tmtcpacket/cfdp/CFDPPacket.h b/src/fsfw/tmtcpacket/cfdp/CfdpPacket.h similarity index 82% rename from src/fsfw/tmtcpacket/cfdp/CFDPPacket.h rename to src/fsfw/tmtcpacket/cfdp/CfdpPacket.h index a70c39381..e47d3b6f5 100644 --- a/src/fsfw/tmtcpacket/cfdp/CFDPPacket.h +++ b/src/fsfw/tmtcpacket/cfdp/CfdpPacket.h @@ -3,7 +3,7 @@ #include "fsfw/tmtcpacket/SpacePacketReader.h" -class CFDPPacket : public SpacePacketReader { +class CfdpReader : public SpacePacketReader { public: /** * This is the default constructor. @@ -11,11 +11,11 @@ class CFDPPacket : public SpacePacketReader { * forwards the data pointer to the parent SpacePacketBase class. * @param setData The position where the packet data lies. */ - CFDPPacket(const uint8_t* setData); + explicit CfdpReader(const uint8_t* setData, size_t maxSize); /** * This is the empty default destructor. */ - virtual ~CFDPPacket(); + ~CfdpReader() override; /** * This is a debugging helper method that prints the whole packet content diff --git a/src/fsfw/tmtcpacket/cfdp/CFDPPacketStored.h b/src/fsfw/tmtcpacket/cfdp/CfdpPacketStored.h similarity index 72% rename from src/fsfw/tmtcpacket/cfdp/CFDPPacketStored.h rename to src/fsfw/tmtcpacket/cfdp/CfdpPacketStored.h index 688067f90..54f8e5be8 100644 --- a/src/fsfw/tmtcpacket/cfdp/CFDPPacketStored.h +++ b/src/fsfw/tmtcpacket/cfdp/CfdpPacketStored.h @@ -1,25 +1,25 @@ -#ifndef FSFW_INC_FSFW_TMTCPACKET_CFDP_CFDPPACKETSTORED_H_ -#define FSFW_INC_FSFW_TMTCPACKET_CFDP_CFDPPACKETSTORED_H_ +#ifndef FSFW_TMTCPACKET_CFDP_CFDPPACKETSTORED_H_ +#define FSFW_TMTCPACKET_CFDP_CFDPPACKETSTORED_H_ #include "../pus/tc/TcPacketStoredBase.h" -#include "CFDPPacket.h" +#include "CfdpPacket.h" -class CFDPPacketStored : public CFDPPacket, public TcPacketStoredBase { +class CfdpPacketStored : public CfdpReader { public: /** * Create stored packet with existing data. * @param data * @param size */ - CFDPPacketStored(const uint8_t* data, size_t size); + CfdpPacketStored(const uint8_t* data, size_t size); /** * Create stored packet from existing packet in store * @param setAddress */ - CFDPPacketStored(store_address_t setAddress); - CFDPPacketStored(); + explicit CfdpPacketStored(store_address_t setAddress); + CfdpPacketStored(); - virtual ~CFDPPacketStored(); + ~CfdpPacketStored() override; /** * Getter function for the raw data. @@ -53,4 +53,4 @@ class CFDPPacketStored : public CFDPPacket, public TcPacketStoredBase { bool checkAndSetStore(); }; -#endif /* FSFW_INC_FSFW_TMTCPACKET_CFDP_CFDPPACKETSTORED_H_ */ +#endif /* FSFW_TMTCPACKET_CFDP_CFDPPACKETSTORED_H_ */ diff --git a/src/fsfw/tmtcpacket/packetmatcher/ApidMatcher.h b/src/fsfw/tmtcpacket/packetmatcher/ApidMatcher.h index 3c835ef81..47e23f1c9 100644 --- a/src/fsfw/tmtcpacket/packetmatcher/ApidMatcher.h +++ b/src/fsfw/tmtcpacket/packetmatcher/ApidMatcher.h @@ -1,18 +1,19 @@ #ifndef FSFW_TMTCPACKET_PACKETMATCHER_APIDMATCHER_H_ #define FSFW_TMTCPACKET_PACKETMATCHER_APIDMATCHER_H_ -#include "../../globalfunctions/matching/SerializeableMatcherIF.h" -#include "../../serialize/SerializeAdapter.h" -#include "../../tmtcpacket/pus/tm/TmPacketMinimal.h" +#include "fsfw/globalfunctions/matching/SerializeableMatcherIF.h" +#include "fsfw/serialize/SerializeAdapter.h" +#include "fsfw/tmtcpacket/pus/tm/PusTmIF.h" +#include "fsfw/tmtcpacket/pus/tm/PusTmMinimal.h" -class ApidMatcher : public SerializeableMatcherIF { +class ApidMatcher : public SerializeableMatcherIF { private: uint16_t apid; public: explicit ApidMatcher(uint16_t setApid) : apid(setApid) {} - explicit ApidMatcher(TmPacketMinimal* test) : apid(test->getApid()) {} - bool match(TmPacketMinimal* packet) override { + explicit ApidMatcher(PusTmIF* test) : apid(test->getApid()) {} + bool match(PusTmIF* packet) override { if (packet->getApid() == apid) { return true; } else { diff --git a/src/fsfw/tmtcpacket/packetmatcher/PacketMatchTree.cpp b/src/fsfw/tmtcpacket/packetmatcher/PacketMatchTree.cpp index 55fd3227a..1ab8729bf 100644 --- a/src/fsfw/tmtcpacket/packetmatcher/PacketMatchTree.cpp +++ b/src/fsfw/tmtcpacket/packetmatcher/PacketMatchTree.cpp @@ -1,5 +1,6 @@ #include "fsfw/tmtcpacket/packetmatcher/PacketMatchTree.h" +#include "fsfw/storagemanager/LocalPool.h" #include "fsfw/tmtcpacket/packetmatcher/ApidMatcher.h" #include "fsfw/tmtcpacket/packetmatcher/ServiceMatcher.h" #include "fsfw/tmtcpacket/packetmatcher/SubserviceMatcher.h" @@ -12,33 +13,34 @@ const LocalPool::LocalPoolConfig PacketMatchTree::poolConfig = { {40, sizeof(PacketMatchTree::Node)}}; PacketMatchTree::PacketMatchTree(Node* root) - : MatchTree(root, 2), + : MatchTree(root, 2), factoryBackend(0, poolConfig, false, true), factory(&factoryBackend) {} PacketMatchTree::PacketMatchTree(iterator root) - : MatchTree(root.element, 2), + : MatchTree(root.element, 2), factoryBackend(0, poolConfig, false, true), factory(&factoryBackend) {} PacketMatchTree::PacketMatchTree() - : MatchTree((Node*)NULL, 2), + : MatchTree(nullptr, 2), factoryBackend(0, poolConfig, false, true), factory(&factoryBackend) {} -PacketMatchTree::~PacketMatchTree() {} +PacketMatchTree::~PacketMatchTree() = default; ReturnValue_t PacketMatchTree::addMatch(uint16_t apid, uint8_t type, uint8_t subtype) { // We assume adding APID is always requested. - TmPacketMinimal::TmPacketMinimalPointer data; - data.data_field.service_type = type; - data.data_field.service_subtype = subtype; - TmPacketMinimal testPacket((uint8_t*)&data); + PusTmMinimal::TmPacketMinimalPointer data{}; + data.secHeader.service_type = type; + data.secHeader.service_subtype = subtype; + PusTmMinimal testPacket((uint8_t*)&data); testPacket.setApid(apid); + iterator lastTest; iterator rollback; ReturnValue_t result = - findOrInsertMatch(this->begin(), &testPacket, &lastTest); + findOrInsertMatch(this->begin(), &testPacket, &lastTest); if (result == NEW_NODE_CREATED) { rollback = lastTest; } else if (result != RETURN_OK) { @@ -47,38 +49,36 @@ ReturnValue_t PacketMatchTree::addMatch(uint16_t apid, uint8_t type, uint8_t sub if (type == 0) { // Check if lastTest has no children, otherwise, delete them, // as a more general check is requested. - if (lastTest.left() != this->end()) { + if (lastTest.left() != PacketMatchTree::end()) { removeElementAndAllChildren(lastTest.left()); } return RETURN_OK; } // Type insertion required. - result = - findOrInsertMatch(lastTest.left(), &testPacket, &lastTest); + result = findOrInsertMatch(lastTest.left(), &testPacket, &lastTest); if (result == NEW_NODE_CREATED) { - if (rollback == this->end()) { + if (rollback == PacketMatchTree::end()) { rollback = lastTest; } } else if (result != RETURN_OK) { - if (rollback != this->end()) { + if (rollback != PacketMatchTree::end()) { removeElementAndAllChildren(rollback); } return result; } if (subtype == 0) { - if (lastTest.left() != this->end()) { + if (lastTest.left() != PacketMatchTree::end()) { // See above removeElementAndAllChildren(lastTest.left()); } return RETURN_OK; } // Subtype insertion required. - result = findOrInsertMatch(lastTest.left(), &testPacket, - &lastTest); + result = findOrInsertMatch(lastTest.left(), &testPacket, &lastTest); if (result == NEW_NODE_CREATED) { return RETURN_OK; } else if (result != RETURN_OK) { - if (rollback != this->end()) { + if (rollback != PacketMatchTree::end()) { removeElementAndAllChildren(rollback); } return result; @@ -91,7 +91,7 @@ ReturnValue_t PacketMatchTree::findOrInsertMatch(iterator startAt, VALUE_T test, iterator* lastTest) { bool attachToBranch = AND; iterator iter = startAt; - while (iter != this->end()) { + while (iter != PacketMatchTree::end()) { bool isMatch = iter->match(test); attachToBranch = OR; *lastTest = iter; @@ -104,11 +104,11 @@ ReturnValue_t PacketMatchTree::findOrInsertMatch(iterator startAt, VALUE_T test, } // Only reached if nothing was found. SerializeableMatcherIF* newContent = factory.generate(test); - if (newContent == NULL) { + if (newContent == nullptr) { return FULL; } Node* newNode = factory.generate(newContent); - if (newNode == NULL) { + if (newNode == nullptr) { // Need to make sure partially generated content is deleted, otherwise, that's a leak. factory.destroy(static_cast(newContent)); return FULL; @@ -122,10 +122,10 @@ ReturnValue_t PacketMatchTree::findOrInsertMatch(iterator startAt, VALUE_T test, } ReturnValue_t PacketMatchTree::removeMatch(uint16_t apid, uint8_t type, uint8_t subtype) { - TmPacketMinimal::TmPacketMinimalPointer data; - data.data_field.service_type = type; - data.data_field.service_subtype = subtype; - TmPacketMinimal testPacket((uint8_t*)&data); + PusTmMinimal::TmPacketMinimalPointer data; + data.secHeader.service_type = type; + data.secHeader.service_subtype = subtype; + PusTmMinimal testPacket((uint8_t*)&data); testPacket.setApid(apid); iterator foundElement = findMatch(begin(), &testPacket); if (foundElement == this->end()) { @@ -158,7 +158,7 @@ ReturnValue_t PacketMatchTree::removeMatch(uint16_t apid, uint8_t type, uint8_t return removeElementAndReconnectChildren(foundElement); } -PacketMatchTree::iterator PacketMatchTree::findMatch(iterator startAt, TmPacketMinimal* test) { +PacketMatchTree::iterator PacketMatchTree::findMatch(iterator startAt, PusTmIF* test) { iterator iter = startAt; while (iter != end()) { bool isMatch = iter->match(test); diff --git a/src/fsfw/tmtcpacket/packetmatcher/PacketMatchTree.h b/src/fsfw/tmtcpacket/packetmatcher/PacketMatchTree.h index 0cbd44949..fa3aab449 100644 --- a/src/fsfw/tmtcpacket/packetmatcher/PacketMatchTree.h +++ b/src/fsfw/tmtcpacket/packetmatcher/PacketMatchTree.h @@ -4,21 +4,22 @@ #include "fsfw/container/PlacementFactory.h" #include "fsfw/globalfunctions/matching/MatchTree.h" #include "fsfw/storagemanager/LocalPool.h" -#include "fsfw/tmtcpacket/pus/tm/TmPacketMinimal.h" +#include "fsfw/tmtcpacket/pus/tm/PusTmIF.h" +#include "fsfw/tmtcpacket/pus/tm/PusTmMinimal.h" -class PacketMatchTree : public MatchTree, public HasReturnvaluesIF { +class PacketMatchTree : public MatchTree, public HasReturnvaluesIF { public: - PacketMatchTree(Node* root); - PacketMatchTree(iterator root); + explicit PacketMatchTree(Node* root); + explicit PacketMatchTree(iterator root); PacketMatchTree(); - virtual ~PacketMatchTree(); + ~PacketMatchTree() override; ReturnValue_t changeMatch(bool addToMatch, uint16_t apid, uint8_t type = 0, uint8_t subtype = 0); ReturnValue_t addMatch(uint16_t apid, uint8_t type = 0, uint8_t subtype = 0); ReturnValue_t removeMatch(uint16_t apid, uint8_t type = 0, uint8_t subtype = 0); ReturnValue_t initialize(); protected: - ReturnValue_t cleanUpElement(iterator position); + ReturnValue_t cleanUpElement(iterator position) override; private: static const uint8_t N_POOLS = 4; @@ -29,7 +30,7 @@ class PacketMatchTree : public MatchTree, public HasReturnvalu static const uint16_t N_ELEMENTS[N_POOLS]; template ReturnValue_t findOrInsertMatch(iterator startAt, VALUE_T test, iterator* lastTest); - iterator findMatch(iterator startAt, TmPacketMinimal* test); + iterator findMatch(iterator startAt, PusTmIF* test); }; -#endif /* FRAMEWORK_TMTCPACKET_PACKETMATCHER_PACKETMATCHTREE_H_ */ +#endif /* FSFW_TMTCPACKET_PACKETMATCHER_PACKETMATCHTREE_H_ */ diff --git a/src/fsfw/tmtcpacket/packetmatcher/ServiceMatcher.h b/src/fsfw/tmtcpacket/packetmatcher/ServiceMatcher.h index 752c03547..6ccd9a6b1 100644 --- a/src/fsfw/tmtcpacket/packetmatcher/ServiceMatcher.h +++ b/src/fsfw/tmtcpacket/packetmatcher/ServiceMatcher.h @@ -3,16 +3,16 @@ #include "../../globalfunctions/matching/SerializeableMatcherIF.h" #include "../../serialize/SerializeAdapter.h" -#include "../pus/tm/TmPacketMinimal.h" +#include "../pus/tm/PusTmMinimal.h" -class ServiceMatcher : public SerializeableMatcherIF { +class ServiceMatcher : public SerializeableMatcherIF { private: uint8_t service; public: - ServiceMatcher(uint8_t setService) : service(setService) {} - ServiceMatcher(TmPacketMinimal* test) : service(test->getService()) {} - bool match(TmPacketMinimal* packet) { + explicit ServiceMatcher(uint8_t setService) : service(setService) {} + explicit ServiceMatcher(PusTmIF* test) : service(test->getService()) {} + bool match(PusTmIF* packet) override { if (packet->getService() == service) { return true; } else { @@ -20,11 +20,14 @@ class ServiceMatcher : public SerializeableMatcherIF { } } ReturnValue_t serialize(uint8_t** buffer, size_t* size, size_t maxSize, - Endianness streamEndianness) const { + Endianness streamEndianness) const override { return SerializeAdapter::serialize(&service, buffer, size, maxSize, streamEndianness); } - size_t getSerializedSize() const { return SerializeAdapter::getSerializedSize(&service); } - ReturnValue_t deSerialize(const uint8_t** buffer, size_t* size, Endianness streamEndianness) { + [[nodiscard]] size_t getSerializedSize() const override { + return SerializeAdapter::getSerializedSize(&service); + } + ReturnValue_t deSerialize(const uint8_t** buffer, size_t* size, + Endianness streamEndianness) override { return SerializeAdapter::deSerialize(&service, buffer, size, streamEndianness); } }; diff --git a/src/fsfw/tmtcpacket/packetmatcher/SubserviceMatcher.h b/src/fsfw/tmtcpacket/packetmatcher/SubserviceMatcher.h index 934e8cb83..8729bbd5e 100644 --- a/src/fsfw/tmtcpacket/packetmatcher/SubserviceMatcher.h +++ b/src/fsfw/tmtcpacket/packetmatcher/SubserviceMatcher.h @@ -3,13 +3,13 @@ #include "../../globalfunctions/matching/SerializeableMatcherIF.h" #include "../../serialize/SerializeAdapter.h" -#include "../pus/tm/TmPacketMinimal.h" +#include "../pus/tm/PusTmMinimal.h" -class SubServiceMatcher : public SerializeableMatcherIF { +class SubServiceMatcher : public SerializeableMatcherIF { public: - SubServiceMatcher(uint8_t subService) : subService(subService) {} - SubServiceMatcher(TmPacketMinimal* test) : subService(test->getSubService()) {} - bool match(TmPacketMinimal* packet) { + explicit SubServiceMatcher(uint8_t subService) : subService(subService) {} + explicit SubServiceMatcher(PusTmIF* test) : subService(test->getSubService()) {} + bool match(PusTmIF* packet) override { if (packet->getSubService() == subService) { return true; } else { @@ -17,16 +17,19 @@ class SubServiceMatcher : public SerializeableMatcherIF { } } ReturnValue_t serialize(uint8_t** buffer, size_t* size, size_t maxSize, - Endianness streamEndianness) const { + Endianness streamEndianness) const override { return SerializeAdapter::serialize(&subService, buffer, size, maxSize, streamEndianness); } - size_t getSerializedSize() const { return SerializeAdapter::getSerializedSize(&subService); } - ReturnValue_t deSerialize(const uint8_t** buffer, size_t* size, Endianness streamEndianness) { + [[nodiscard]] size_t getSerializedSize() const override { + return SerializeAdapter::getSerializedSize(&subService); + } + ReturnValue_t deSerialize(const uint8_t** buffer, size_t* size, + Endianness streamEndianness) override { return SerializeAdapter::deSerialize(&subService, buffer, size, streamEndianness); } private: - uint8_t subService; + uint8_t subService{}; }; #endif /* FRAMEWORK_TMTCPACKET_PACKETMATCHER_SUBSERVICEMATCHER_H_ */ diff --git a/src/fsfw/tmtcpacket/pus/PacketTimestampInterpreterIF.h b/src/fsfw/tmtcpacket/pus/PacketTimestampInterpreterIF.h index 340f78255..d6e964383 100644 --- a/src/fsfw/tmtcpacket/pus/PacketTimestampInterpreterIF.h +++ b/src/fsfw/tmtcpacket/pus/PacketTimestampInterpreterIF.h @@ -3,13 +3,13 @@ #include "fsfw/returnvalues/HasReturnvaluesIF.h" -class TmPacketMinimal; +class PusTmMinimal; class PacketTimestampInterpreterIF { public: virtual ~PacketTimestampInterpreterIF() {} - virtual ReturnValue_t getPacketTime(TmPacketMinimal* packet, timeval* timestamp) const = 0; - virtual ReturnValue_t getPacketTimeRaw(TmPacketMinimal* packet, const uint8_t** timePtr, + virtual ReturnValue_t getPacketTime(PusTmMinimal* packet, timeval* timestamp) const = 0; + virtual ReturnValue_t getPacketTimeRaw(PusTmMinimal* packet, const uint8_t** timePtr, uint32_t* size) const = 0; }; diff --git a/src/fsfw/tmtcpacket/pus/PusIF.h b/src/fsfw/tmtcpacket/pus/PusIF.h new file mode 100644 index 000000000..61d4fcffd --- /dev/null +++ b/src/fsfw/tmtcpacket/pus/PusIF.h @@ -0,0 +1,52 @@ +#ifndef FSFW_TMTCPACKET_PUSIF_H +#define FSFW_TMTCPACKET_PUSIF_H + +#include + +#include "fsfw/tmtcpacket/SpacePacketIF.h" + +class PusIF : public SpacePacketIF { + public: + ~PusIF() override = default; + /** + * This command returns the TC Packet PUS Version Number. + * The version number of ECSS PUS 2003 is 1. + * It consists of the second to fourth highest bits of the + * first byte. + * @return + */ + [[nodiscard]] virtual uint8_t getPusVersion() const = 0; + + /** + * This is a getter for the packet's PUS Service ID, which is the second + * byte of the Data Field Header. + * @return The packet's PUS Service ID. + */ + [[nodiscard]] virtual uint8_t getService() const = 0; + /** + * This is a getter for the packet's PUS Service Subtype, which is the + * third byte of the Data Field Header. + * @return The packet's PUS Service Subtype. + */ + [[nodiscard]] virtual uint8_t getSubService() const = 0; + + /** + * This is a getter for a pointer to the packet's Application data. + * + * These are the bytes that follow after the Data Field Header. They form + * the packet's application data. + * @return A pointer to the PUS Application Data. + */ + [[nodiscard]] virtual const uint8_t* getUserData(size_t& appDataLen) const = 0; + /** + * This method calculates the size of the PUS Application data field. + * + * It takes the information stored in the CCSDS Packet Data Length field + * and subtracts the Data Field Header size and the CRC size. + * @return The size of the PUS Application Data (without Error Control + * field) + */ + [[nodiscard]] virtual uint16_t getUserDataSize() const = 0; +}; + +#endif // FSFW_TMTCPACKET_PUSIF_H diff --git a/src/fsfw/tmtcpacket/pus/definitions.h b/src/fsfw/tmtcpacket/pus/definitions.h index d4b649d03..369f869a9 100644 --- a/src/fsfw/tmtcpacket/pus/definitions.h +++ b/src/fsfw/tmtcpacket/pus/definitions.h @@ -3,11 +3,11 @@ #include -namespace pus { +namespace ecss { //! Version numbers according to ECSS-E-ST-70-41C p.439 -enum PusVersion : uint8_t { PUS_A_VERSION = 1, PUS_C_VERSION = 2 }; +enum PusVersion : uint8_t { PUS_A = 1, PUS_C = 2 }; -} // namespace pus +} // namespace ecss #endif /* FSFW_SRC_FSFW_TMTCPACKET_PUS_TM_DEFINITIONS_H_ */ diff --git a/src/fsfw/tmtcpacket/pus/tc.h b/src/fsfw/tmtcpacket/pus/tc.h index f5a467aa1..33c6352f3 100644 --- a/src/fsfw/tmtcpacket/pus/tc.h +++ b/src/fsfw/tmtcpacket/pus/tc.h @@ -2,6 +2,5 @@ #define FSFW_TMTCPACKET_PUS_TC_H_ #include "tc/TcPacketPus.h" -#include "tc/TcPacketStoredPus.h" #endif /* FSFW_TMTCPACKET_PUS_TC_H_ */ diff --git a/src/fsfw/tmtcpacket/pus/tc/CMakeLists.txt b/src/fsfw/tmtcpacket/pus/tc/CMakeLists.txt index c37c2c550..d2e30586d 100644 --- a/src/fsfw/tmtcpacket/pus/tc/CMakeLists.txt +++ b/src/fsfw/tmtcpacket/pus/tc/CMakeLists.txt @@ -1,4 +1,4 @@ -target_sources( - ${LIB_FSFW_NAME} - PRIVATE PusTcReader.cpp TcPacketPus.cpp PusTcReader.cpp PusTcCreator.cpp - TcPacketStoredBase.cpp TcPacketStoredPus.cpp) +target_sources(${LIB_FSFW_NAME} PRIVATE PusTcReader.cpp PusTcReader.cpp + PusTcCreator.cpp) + +# TcPacketPus.cpp diff --git a/src/fsfw/tmtcpacket/pus/tc/PusTcCreator.cpp b/src/fsfw/tmtcpacket/pus/tc/PusTcCreator.cpp index c73f7a93b..cbd6da534 100644 --- a/src/fsfw/tmtcpacket/pus/tc/PusTcCreator.cpp +++ b/src/fsfw/tmtcpacket/pus/tc/PusTcCreator.cpp @@ -1,3 +1,75 @@ #include "PusTcCreator.h" -TcPacketDeserializer::TcPacketDeserializer(const uint8_t *data, size_t maxSize) {} +#include "PusTcIF.h" +#include "fsfw/globalfunctions/CRC.h" +#include "fsfw/serialize/SerializeAdapter.h" + +PusTcCreator::PusTcCreator(SpacePacketParams spParams, PusTcParams pusParams) + : spCreator(spParams), pusParams(pusParams) { + updateSpLengthField(); +} + +ReturnValue_t PusTcCreator::serialize(uint8_t **buffer, size_t *size, size_t maxSize, + SerializeIF::Endianness streamEndianness) const { + if (*size + PusTcIF::MIN_LEN + pusParams.appDataLen > maxSize) { + return SerializeIF::BUFFER_TOO_SHORT; + } + ReturnValue_t result = spCreator.serialize(buffer, size, maxSize, streamEndianness); + if (result != HasReturnvaluesIF::RETURN_OK) { + return result; + } + if (pusParams.pusVersion != ecss::PusVersion::PUS_C) { + // TODO: Dedicated returnvalue + return HasReturnvaluesIF::RETURN_FAILED; + } + **buffer = pusParams.pusVersion << 4 | pusParams.ackFlags; + *buffer += 1; + **buffer = pusParams.service; + *buffer += 1; + **buffer = pusParams.subservice; + *buffer += 1; + result = + SerializeAdapter::serialize(&pusParams.sourceId, buffer, size, maxSize, streamEndianness); + if (result != HasReturnvaluesIF::RETURN_OK) { + return result; + } + std::memcpy(*buffer, pusParams.appData, pusParams.appDataLen); + *buffer += pusParams.appDataLen; + *size += pusParams.appDataLen; + uint16_t crc16 = CRC::crc16ccitt(*buffer, getFullPacketLen() - 2); + return SerializeAdapter::serialize(&crc16, buffer, size, maxSize, streamEndianness); +} + +void PusTcCreator::updateSpLengthField() { + spCreator.setDataLen(ecss::PusTcDataFieldHeader::MIN_LEN + pusParams.appDataLen + 1); +} + +size_t PusTcCreator::getSerializedSize() const { return spCreator.getFullPacketLen(); } + +ReturnValue_t PusTcCreator::deSerialize(const uint8_t **buffer, size_t *size, + SerializeIF::Endianness streamEndianness) { + return HasReturnvaluesIF::RETURN_FAILED; +} + +uint16_t PusTcCreator::getPacketId() const { return spCreator.getPacketId(); } + +uint16_t PusTcCreator::getPacketSeqCtrl() const { return spCreator.getPacketSeqCtrl(); } + +uint16_t PusTcCreator::getPacketDataLen() const { return spCreator.getPacketDataLen(); } + +uint8_t PusTcCreator::getPusVersion() const { return pusParams.pusVersion; } + +uint8_t PusTcCreator::getAcknowledgeFlags() const { return pusParams.ackFlags; } + +uint8_t PusTcCreator::getService() const { return pusParams.service; } + +uint8_t PusTcCreator::getSubService() const { return pusParams.subservice; } + +uint16_t PusTcCreator::getSourceId() const { return pusParams.sourceId; } + +const uint8_t *PusTcCreator::getUserData(size_t &appDataLen) const { + appDataLen = getUserDataSize(); + return pusParams.appData; +} + +uint16_t PusTcCreator::getUserDataSize() const { return pusParams.appDataLen; } diff --git a/src/fsfw/tmtcpacket/pus/tc/PusTcCreator.h b/src/fsfw/tmtcpacket/pus/tc/PusTcCreator.h index 275cc28f9..ffa2ed7c6 100644 --- a/src/fsfw/tmtcpacket/pus/tc/PusTcCreator.h +++ b/src/fsfw/tmtcpacket/pus/tc/PusTcCreator.h @@ -2,13 +2,47 @@ #define FSFW_TMTCPACKET_TCPACKETDESERIALIZER_H #include "fsfw/tmtcpacket/RedirectableDataPointerIF.h" +#include "fsfw/tmtcpacket/SpacePacketCreator.h" #include "fsfw/tmtcpacket/SpacePacketIF.h" +#include "fsfw/tmtcpacket/pus/definitions.h" +#include "fsfw/tmtcpacket/pus/tc/PusTcIF.h" -class PusTcCreator : public SpacePacketIF { +struct PusTcParams { + PusTcParams(uint8_t service_, uint8_t subservice_) : service(service_), subservice(subservice_) {} + + uint8_t service; + uint8_t subservice; + uint8_t ackFlags = ecss::ACK_ALL; + uint16_t sourceId = 0; + uint8_t *appData = nullptr; + size_t appDataLen = 0; + uint8_t pusVersion = ecss::PusVersion::PUS_C; +}; + +class PusTcCreator : public PusTcIF, public SerializeIF { public: - PusTcCreator(const uint8_t* data, size_t maxSize); + PusTcCreator(SpacePacketParams spParams, PusTcParams pusParams); + + void updateSpLengthField(); + ReturnValue_t serialize(uint8_t **buffer, size_t *size, size_t maxSize, + Endianness streamEndianness) const override; + [[nodiscard]] size_t getSerializedSize() const override; + ReturnValue_t deSerialize(const uint8_t **buffer, size_t *size, + Endianness streamEndianness) override; + [[nodiscard]] uint16_t getPacketId() const override; + [[nodiscard]] uint16_t getPacketSeqCtrl() const override; + [[nodiscard]] uint16_t getPacketDataLen() const override; + [[nodiscard]] uint8_t getPusVersion() const override; + [[nodiscard]] uint8_t getAcknowledgeFlags() const override; + [[nodiscard]] uint8_t getService() const override; + [[nodiscard]] uint8_t getSubService() const override; + [[nodiscard]] uint16_t getSourceId() const override; + const uint8_t *getUserData(size_t &appDataLen) const override; + [[nodiscard]] uint16_t getUserDataSize() const override; private: + SpacePacketCreator spCreator; + PusTcParams pusParams; }; #endif // FSFW_TMTCPACKET_TCPACKETDESERIALIZER_H diff --git a/src/fsfw/tmtcpacket/pus/tc/PusTcIF.h b/src/fsfw/tmtcpacket/pus/tc/PusTcIF.h index 54afd946b..a8204a1fa 100644 --- a/src/fsfw/tmtcpacket/pus/tc/PusTcIF.h +++ b/src/fsfw/tmtcpacket/pus/tc/PusTcIF.h @@ -3,7 +3,7 @@ #include -#include "TcPacketPus.h" +#include "fsfw/tmtcpacket/pus/PusIF.h" namespace ecss { @@ -41,20 +41,12 @@ struct PusTcDataFieldHeader { } // namespace ecss -class PusTcIF : public SpacePacketIF { +class PusTcIF : public PusIF { public: ~PusTcIF() override = default; - static const uint16_t MIN_LEN = + static const size_t MIN_LEN = (sizeof(CCSDSPrimaryHeader) + ecss::PusTcDataFieldHeader::MIN_LEN + 2); - /** - * This command returns the TC Packet PUS Version Number. - * The version number of ECSS PUS 2003 is 1. - * It consists of the second to fourth highest bits of the - * first byte. - * @return - */ - [[nodiscard]] virtual uint8_t getPusVersion() const = 0; /** * This is a getter for the packet's Ack field, which are the lowest four * bits of the first byte of the Data Field Header. @@ -63,50 +55,13 @@ class PusTcIF : public SpacePacketIF { * @return The packet's PUS Ack field. */ [[nodiscard]] virtual uint8_t getAcknowledgeFlags() const = 0; - /** - * This is a getter for the packet's PUS Service ID, which is the second - * byte of the Data Field Header. - * @return The packet's PUS Service ID. - */ - [[nodiscard]] virtual uint8_t getService() const = 0; - /** - * This is a getter for the packet's PUS Service Subtype, which is the - * third byte of the Data Field Header. - * @return The packet's PUS Service Subtype. - */ - [[nodiscard]] virtual uint8_t getSubService() const = 0; + /** * The source ID can be used to have an additional identifier, e.g. for different ground * station. * @return */ [[nodiscard]] virtual uint16_t getSourceId() const = 0; - - /** - * This is a getter for a pointer to the packet's Application data. - * - * These are the bytes that follow after the Data Field Header. They form - * the packet's application data. - * @return A pointer to the PUS Application Data. - */ - [[nodiscard]] virtual const uint8_t* getApplicationData() const = 0; - /** - * This method calculates the size of the PUS Application data field. - * - * It takes the information stored in the CCSDS Packet Data Length field - * and subtracts the Data Field Header size and the CRC size. - * @return The size of the PUS Application Data (without Error Control - * field) - */ - [[nodiscard]] virtual uint16_t getApplicationDataSize() const = 0; - /** - * This getter returns the Error Control Field of the packet. - * - * The field is placed after any possible Application Data. If no - * Application Data is present there's still an Error Control field. It is - * supposed to be a 16bit-CRC. - * @return The PUS Error Control - */ - [[nodiscard]] virtual uint16_t getErrorControl() const = 0; }; + #endif // FSFW_TMTCPACKET_PUSTCIF_H diff --git a/src/fsfw/tmtcpacket/pus/tc/PusTcReader.cpp b/src/fsfw/tmtcpacket/pus/tc/PusTcReader.cpp index e2a66e73d..0ead9bde3 100644 --- a/src/fsfw/tmtcpacket/pus/tc/PusTcReader.cpp +++ b/src/fsfw/tmtcpacket/pus/tc/PusTcReader.cpp @@ -7,33 +7,64 @@ #include "fsfw/serialize.h" #include "fsfw/serviceinterface/ServiceInterface.h" -PusTcReader::PusTcReader(const uint8_t* setData, size_t size) : spReader(setData), maxSize(size) { - pointers.spHeaderStart = setData; -} +PusTcReader::PusTcReader(const uint8_t* data, size_t size) { setData(data, size); } PusTcReader::~PusTcReader() = default; ReturnValue_t PusTcReader::parseData() { - if (maxSize < sizeof(CCSDSPrimaryHeader)) { - return SerializeIF::BUFFER_TOO_SHORT; + ReturnValue_t result = spReader.checkLength(); + if (result != HasReturnvaluesIF::RETURN_OK) { + return result; } + if (size < PusTcIF::MIN_LEN) { + return SerializeIF::STREAM_TOO_SHORT; + } + // Might become variable sized field in the future + size_t secHeaderLen = ecss::PusTcDataFieldHeader::MIN_LEN; pointers.secHeaderStart = pointers.spHeaderStart + sizeof(CCSDSPrimaryHeader); // TODO: No support for spare bytes yet - pointers.userDataStart = pointers.secHeaderStart + ecss::PusTcDataFieldHeader::MIN_LEN; + pointers.userDataStart = pointers.secHeaderStart + secHeaderLen; + appDataSize = size - (sizeof(CCSDSPrimaryHeader) + secHeaderLen); + pointers.crcStart = pointers.userDataStart + appDataSize; + return HasReturnvaluesIF::RETURN_OK; } -uint8_t PusTcReader::getAcknowledgeFlags() const { return 0; } -uint8_t PusTcReader::getService() const { return 0; } -uint8_t PusTcReader::getSubService() const { return 0; } -uint16_t PusTcReader::getSourceId() const { return 0; } -const uint8_t* PusTcReader::getApplicationData() const { return nullptr; } -uint16_t PusTcReader::getApplicationDataSize() const { return 0; } -uint16_t PusTcReader::getErrorControl() const { return 0; } +uint8_t PusTcReader::getAcknowledgeFlags() const { + return (pointers.secHeaderStart[0] >> 4) & 0b1111; +} + +uint8_t PusTcReader::getService() const { return pointers.secHeaderStart[1]; } + +uint8_t PusTcReader::getSubService() const { return pointers.secHeaderStart[2]; } +uint16_t PusTcReader::getSourceId() const { + return (pointers.secHeaderStart[3] << 8) | pointers.secHeaderStart[4]; +} +const uint8_t* PusTcReader::getUserData(size_t& appDataLen) const { + appDataLen = appDataSize; + return pointers.userDataStart; +} + +uint16_t PusTcReader::getUserDataSize() const { return appDataSize; } + +uint16_t PusTcReader::getErrorControl() const { + return pointers.crcStart[0] << 8 | pointers.crcStart[1]; +} uint16_t PusTcReader::getPacketId() const { return spReader.getPacketId(); } uint16_t PusTcReader::getPacketSeqCtrl() const { return spReader.getPacketSeqCtrl(); } uint16_t PusTcReader::getPacketDataLen() const { return spReader.getPacketDataLen(); } uint8_t PusTcReader::getPusVersion() const { return spReader.getVersion(); } +const uint8_t* PusTcReader::getFullData() { return pointers.spHeaderStart; } + +ReturnValue_t PusTcReader::setData(uint8_t* pData, size_t size_, void* args) { + size = size_; + pointers.spHeaderStart = pData; + spReader.setData(pData, size_, args); + return HasReturnvaluesIF::RETURN_OK; +} +ReturnValue_t PusTcReader::setData(const uint8_t* data, size_t size_) { + setData(const_cast(data), size_, nullptr); +} /* void PusTcReader::print() { diff --git a/src/fsfw/tmtcpacket/pus/tc/PusTcReader.h b/src/fsfw/tmtcpacket/pus/tc/PusTcReader.h index 43ab26ce5..85623980a 100644 --- a/src/fsfw/tmtcpacket/pus/tc/PusTcReader.h +++ b/src/fsfw/tmtcpacket/pus/tc/PusTcReader.h @@ -18,17 +18,16 @@ * check can be performed by making use of the getWholeData method. * @ingroup tmtcpackets */ -class PusTcReader : public PusTcIF, public RedirectableDataPointerIF { - friend class TcPacketStoredBase; - +class PusTcReader : public PusTcIF, public ReadablePacketIF, public RedirectableDataPointerIF { public: + PusTcReader() = default; /** * This is the default constructor. * It sets its internal data pointer to the address passed and also * forwards the data pointer to the parent SpacePacketBase class. * @param setData The position where the packet data lies. */ - explicit PusTcReader(const uint8_t* setData, size_t size); + PusTcReader(const uint8_t* setData, size_t size); ReturnValue_t parseData(); /** @@ -40,7 +39,7 @@ class PusTcReader : public PusTcIF, public RedirectableDataPointerIF { * This is a debugging helper method that prints the whole packet content * to the screen. */ - void print(); + // void print(); [[nodiscard]] uint16_t getPacketId() const override; [[nodiscard]] uint16_t getPacketSeqCtrl() const override; [[nodiscard]] uint16_t getPacketDataLen() const override; @@ -49,9 +48,12 @@ class PusTcReader : public PusTcIF, public RedirectableDataPointerIF { [[nodiscard]] uint8_t getService() const override; [[nodiscard]] uint8_t getSubService() const override; [[nodiscard]] uint16_t getSourceId() const override; - [[nodiscard]] const uint8_t* getApplicationData() const override; - [[nodiscard]] uint16_t getApplicationDataSize() const override; - [[nodiscard]] uint16_t getErrorControl() const override; + [[nodiscard]] const uint8_t* getUserData(size_t& appDataLen) const override; + [[nodiscard]] uint16_t getUserDataSize() const override; + [[nodiscard]] uint16_t getErrorControl() const; + const uint8_t* getFullData() override; + + ReturnValue_t setData(const uint8_t* data, size_t size); protected: /** @@ -62,7 +64,8 @@ class PusTcReader : public PusTcIF, public RedirectableDataPointerIF { * * @param p_data A pointer to another PUS Telecommand Packet. */ - ReturnValue_t setData(uint8_t* pData, size_t maxSize, void* args) override = 0; + ReturnValue_t setData(uint8_t* pData, size_t size, void* args) override; + SpacePacketReader spReader; /** * This struct defines the data structure of a Space Packet when accessed @@ -73,10 +76,12 @@ class PusTcReader : public PusTcIF, public RedirectableDataPointerIF { const uint8_t* spHeaderStart; const uint8_t* secHeaderStart; const uint8_t* userDataStart; + const uint8_t* crcStart; }; PusTcPointers pointers{}; - size_t maxSize = 0; + size_t size = 0; + size_t appDataSize = 0; }; #endif /* TMTCPACKET_PUS_TCPACKETBASE_H_ */ diff --git a/src/fsfw/tmtcpacket/pus/tc/TcPacketPus.cpp b/src/fsfw/tmtcpacket/pus/tc/TcPacketPus.cpp index faada828b..06f980b7b 100644 --- a/src/fsfw/tmtcpacket/pus/tc/TcPacketPus.cpp +++ b/src/fsfw/tmtcpacket/pus/tc/TcPacketPus.cpp @@ -10,7 +10,7 @@ TcPacketPus::TcPacketPus(const uint8_t *setData) : TcPacketPusBase(setData) { void TcPacketPus::initializeTcPacket(uint16_t apid, uint16_t sequenceCount, uint8_t ack, uint8_t service, uint8_t subservice, - pus::PusVersion pusVersion, uint16_t sourceId) { + ecss::PusVersion pusVersion, uint16_t sourceId) { initSpacePacketHeader(true, true, apid, sequenceCount); std::memset(&tcData->dataField, 0, sizeof(tcData->dataField)); setPacketDataLength(sizeof(PUSTcDataFieldHeader) + CRC_SIZE - 1); diff --git a/src/fsfw/tmtcpacket/pus/tc/TcPacketPus.h b/src/fsfw/tmtcpacket/pus/tc/TcPacketPus.h index d7c8d7436..bb2b3642e 100644 --- a/src/fsfw/tmtcpacket/pus/tc/TcPacketPus.h +++ b/src/fsfw/tmtcpacket/pus/tc/TcPacketPus.h @@ -21,49 +21,49 @@ struct TcPacketPointer { }; */ -class TcPacketPus : public TcPacketPusBase { - public: - /** - * Initialize a PUS A telecommand packet which already exists. You can also - * create an empty (invalid) object by passing nullptr as the data pointer - * @param setData - */ - TcPacketPus(const uint8_t* setData); - - // Base class overrides - uint8_t getSecondaryHeaderFlag() const override; - uint8_t getPusVersionNumber() const override; - uint8_t getAcknowledgeFlags() const override; - uint8_t getService() const override; - uint8_t getSubService() const override; - uint16_t getSourceId() const override; - const uint8_t* getApplicationData() const override; - uint16_t getApplicationDataSize() const override; - uint16_t getErrorControl() const override; - void setErrorControl() override; - size_t calculateFullPacketLength(size_t appDataLen) const override; - - protected: - ReturnValue_t setData(uint8_t* dataPtr, size_t maxSize, void* args) override; - - /** - * Initializes the Tc Packet header. - * @param apid APID used. - * @param sequenceCount Sequence Count in the primary header. - * @param ack Which acknowledeges are expected from the receiver. - * @param service PUS Service - * @param subservice PUS Subservice - */ - void initializeTcPacket(uint16_t apid, uint16_t sequenceCount, uint8_t ack, uint8_t service, - uint8_t subservice, pus::PusVersion pusVersion, uint16_t sourceId = 0); - - /** - * A pointer to a structure which defines the data structure of - * the packet's data. - * - * To be hardware-safe, all elements are of byte size. - */ - TcPacketPointer* tcData = nullptr; -}; +// class TcPacketPus : public TcPacketPusBase { +// public: +// /** +// * Initialize a PUS A telecommand packet which already exists. You can also +// * create an empty (invalid) object by passing nullptr as the data pointer +// * @param setData +// */ +// TcPacketPus(const uint8_t* setData); +// +// // Base class overrides +// uint8_t getSecondaryHeaderFlag() const override; +// uint8_t getPusVersionNumber() const override; +// uint8_t getAcknowledgeFlags() const override; +// uint8_t getService() const override; +// uint8_t getSubService() const override; +// uint16_t getSourceId() const override; +// const uint8_t* getApplicationData() const override; +// uint16_t getApplicationDataSize() const override; +// uint16_t getErrorControl() const override; +// void setErrorControl() override; +// size_t calculateFullPacketLength(size_t appDataLen) const override; +// +// protected: +// ReturnValue_t setData(uint8_t* dataPtr, size_t maxSize, void* args) override; +// +// /** +// * Initializes the Tc Packet header. +// * @param apid APID used. +// * @param sequenceCount Sequence Count in the primary header. +// * @param ack Which acknowledeges are expected from the receiver. +// * @param service PUS Service +// * @param subservice PUS Subservice +// */ +// void initializeTcPacket(uint16_t apid, uint16_t sequenceCount, uint8_t ack, uint8_t service, +// uint8_t subservice, pus::PusVersion pusVersion, uint16_t sourceId = 0); +// +// /** +// * A pointer to a structure which defines the data structure of +// * the packet's data. +// * +// * To be hardware-safe, all elements are of byte size. +// */ +// TcPacketPointer* tcData = nullptr; +// }; #endif /* FSFW_TMTCPACKET_PUS_TCPACKETPUSA_H_ */ diff --git a/src/fsfw/tmtcpacket/pus/tc/TcPacketStored.cpp b/src/fsfw/tmtcpacket/pus/tc/TcPacketStored.cpp new file mode 100644 index 000000000..89ebe75aa --- /dev/null +++ b/src/fsfw/tmtcpacket/pus/tc/TcPacketStored.cpp @@ -0,0 +1 @@ +#include "TcPacketStored.h" diff --git a/src/fsfw/tmtcpacket/pus/tc/TcPacketStored.h b/src/fsfw/tmtcpacket/pus/tc/TcPacketStored.h new file mode 100644 index 000000000..ddd513031 --- /dev/null +++ b/src/fsfw/tmtcpacket/pus/tc/TcPacketStored.h @@ -0,0 +1,10 @@ +#ifndef FSFW_TMTCPACKET_TCPACKETSTORED_H +#define FSFW_TMTCPACKET_TCPACKETSTORED_H + +#include "fsfw/tmtcpacket/PacketStorageHelper.h" + +class TcPacketStored : public PacketStorageHelper { + TcPacketStored(StorageManagerIF* store); +}; + +#endif // FSFW_TMTCPACKET_TCPACKETSTORED_H diff --git a/src/fsfw/tmtcpacket/pus/tc/TcPacketStoredBase.cpp b/src/fsfw/tmtcpacket/pus/tc/TcPacketStoredBase.cpp index 229185262..88964bfb9 100644 --- a/src/fsfw/tmtcpacket/pus/tc/TcPacketStoredBase.cpp +++ b/src/fsfw/tmtcpacket/pus/tc/TcPacketStoredBase.cpp @@ -6,58 +6,59 @@ #include "fsfw/objectmanager/frameworkObjects.h" #include "fsfw/serviceinterface/ServiceInterface.h" -StorageManagerIF* TcPacketStoredBase::STORE = nullptr; - -TcPacketStoredBase::TcPacketStoredBase() { - this->storeAddress.raw = StorageManagerIF::INVALID_ADDRESS; - TcPacketStoredBase::checkAndSetStore(); -} - -TcPacketStoredBase::~TcPacketStoredBase() = default; - -ReturnValue_t TcPacketStoredBase::getData(const uint8_t** dataPtr, size_t* dataSize) { - auto result = TcPacketStoredBase::STORE->getData(storeAddress, dataPtr, dataSize); - if (result != HasReturnvaluesIF::RETURN_OK) { -#if FSFW_CPP_OSTREAM_ENABLED == 1 - sif::warning << "TcPacketStoredBase: Could not get data" << std::endl; -#else - sif::printWarning("TcPacketStoredBase: Could not get data!\n"); -#endif - } - return result; -} - -bool TcPacketStoredBase::checkAndSetStore() { - if (TcPacketStoredBase::STORE == nullptr) { - TcPacketStoredBase::STORE = ObjectManager::instance()->get(objects::TC_STORE); - if (TcPacketStoredBase::STORE == nullptr) { -#if FSFW_CPP_OSTREAM_ENABLED == 1 - sif::error << "TcPacketStoredBase::TcPacketStoredBase: TC Store not found" << std::endl; -#else - sif::printError("TcPacketStoredBase::TcPacketStoredBase: TC Store not found\n"); -#endif - return false; - } - } - return true; -} - -void TcPacketStoredBase::setStoreAddress(store_address_t setAddress, - RedirectableDataPointerIF* packet) { - this->storeAddress = setAddress; - const uint8_t* tempData = nullptr; - size_t tempSize; - ReturnValue_t status = StorageManagerIF::RETURN_FAILED; - if (this->checkAndSetStore()) { - status = TcPacketStoredBase::STORE->getData(this->storeAddress, &tempData, &tempSize); - } - - if (status == StorageManagerIF::RETURN_OK) { - packet->setData(const_cast(tempData), tempSize); - } else { - packet->setData(nullptr, -1); - this->storeAddress.raw = StorageManagerIF::INVALID_ADDRESS; - } -} - -store_address_t TcPacketStoredBase::getStoreAddress() { return this->storeAddress; } +// StorageManagerIF* TcPacketStoredBase::STORE = nullptr; +// +// TcPacketStoredBase::TcPacketStoredBase() { +// this->storeAddress.raw = StorageManagerIF::INVALID_ADDRESS; +// TcPacketStoredBase::checkAndSetStore(); +// } +// +// TcPacketStoredBase::~TcPacketStoredBase() = default; +// +// ReturnValue_t TcPacketStoredBase::getData(const uint8_t** dataPtr, size_t* dataSize) { +// auto result = TcPacketStoredBase::STORE->getData(storeAddress, dataPtr, dataSize); +// if (result != HasReturnvaluesIF::RETURN_OK) { +//#if FSFW_CPP_OSTREAM_ENABLED == 1 +// sif::warning << "TcPacketStoredBase: Could not get data" << std::endl; +//#else +// sif::printWarning("TcPacketStoredBase: Could not get data!\n"); +//#endif +// } +// return result; +// } +// +// bool TcPacketStoredBase::checkAndSetStore() { +// if (TcPacketStoredBase::STORE == nullptr) { +// TcPacketStoredBase::STORE = +// ObjectManager::instance()->get(objects::TC_STORE); if +// (TcPacketStoredBase::STORE == nullptr) { +//#if FSFW_CPP_OSTREAM_ENABLED == 1 +// sif::error << "TcPacketStoredBase::TcPacketStoredBase: TC Store not found" << std::endl; +//#else +// sif::printError("TcPacketStoredBase::TcPacketStoredBase: TC Store not found\n"); +//#endif +// return false; +// } +// } +// return true; +// } +// +// void TcPacketStoredBase::setStoreAddress(store_address_t setAddress, +// RedirectableDataPointerIF* packet) { +// this->storeAddress = setAddress; +// const uint8_t* tempData = nullptr; +// size_t tempSize; +// ReturnValue_t status = StorageManagerIF::RETURN_FAILED; +// if (this->checkAndSetStore()) { +// status = TcPacketStoredBase::STORE->getData(this->storeAddress, &tempData, &tempSize); +// } +// +// if (status == StorageManagerIF::RETURN_OK) { +// packet->setData(const_cast(tempData), tempSize); +// } else { +// packet->setData(nullptr, -1); +// this->storeAddress.raw = StorageManagerIF::INVALID_ADDRESS; +// } +// } +// +// store_address_t TcPacketStoredBase::getStoreAddress() { return this->storeAddress; } diff --git a/src/fsfw/tmtcpacket/pus/tc/TcPacketStoredBase.h b/src/fsfw/tmtcpacket/pus/tc/TcPacketStoredBase.h index d0a15cc4f..8291ac6c0 100644 --- a/src/fsfw/tmtcpacket/pus/tc/TcPacketStoredBase.h +++ b/src/fsfw/tmtcpacket/pus/tc/TcPacketStoredBase.h @@ -5,80 +5,80 @@ #include "TcPacketStoredIF.h" #include "fsfw/storagemanager/StorageManagerIF.h" -/** - * Base class for telecommand packets like CFDP or PUS packets. - * @ingroup tmtcpackets - */ -class TcPacketStoredBase : public TcPacketStoredIF { - public: - /** - * This is a default constructor which does not set the data pointer to initialize - * with an empty cached store address - */ - TcPacketStoredBase(); - /** - * Constructor to set to an existing store address. - * @param setAddress - */ - explicit TcPacketStoredBase(store_address_t setAddress); - /** - * Another constructor to create a TcPacket from a raw packet stream. - * Takes the data and adds it unchecked to the TcStore. - * @param data Pointer to the complete TC Space Packet. - * @param Size size of the packet. - */ - TcPacketStoredBase(const uint8_t* data, uint32_t size); - - virtual ~TcPacketStoredBase(); - - /** - * Getter function for the raw data. - * @param dataPtr [out] Pointer to the data pointer to set - * @param dataSize [out] Address of size to set. - * @return -@c RETURN_OK if data was retrieved successfully. - */ - ReturnValue_t getData(const uint8_t** dataPtr, size_t* dataSize) override; - - void setStoreAddress(store_address_t setAddress, RedirectableDataPointerIF* packet) override; - store_address_t getStoreAddress() override; - - /** - * With this call, the packet is deleted. - * It removes itself from the store and sets its data pointer to NULL. - * @return returncode from deleting the data. - */ - virtual ReturnValue_t deletePacket() = 0; - - /** - * This method performs a size check. - * It reads the stored size and compares it with the size entered in the - * packet header. This class is the optimal place for such a check as it - * has access to both the header data and the store. - * @return true if size is correct, false if packet is not registered in - * store or size is incorrect. - */ - virtual bool isSizeCorrect() = 0; - - protected: - /** - * This is a pointer to the store all instances of the class use. - * If the store is not yet set (i.e. @c store is NULL), every constructor - * call tries to set it and throws an error message in case of failures. - * The default store is objects::TC_STORE. - */ - static StorageManagerIF* STORE; - /** - * The address where the packet data of the object instance is stored. - */ - store_address_t storeAddress; - /** - * A helper method to check if a store is assigned to the class. - * If not, the method tries to retrieve the store from the global - * ObjectManager. - * @return @li @c true if the store is linked or could be created. - * @li @c false otherwise. - */ - static bool checkAndSetStore(); -}; +///** +// * Base class for telecommand packets like CFDP or PUS packets. +// * @ingroup tmtcpackets +// */ +// class TcPacketStoredBase : public TcPacketStoredIF { +// public: +// /** +// * This is a default constructor which does not set the data pointer to initialize +// * with an empty cached store address +// */ +// TcPacketStoredBase(); +// /** +// * Constructor to set to an existing store address. +// * @param setAddress +// */ +// explicit TcPacketStoredBase(store_address_t setAddress); +// /** +// * Another constructor to create a TcPacket from a raw packet stream. +// * Takes the data and adds it unchecked to the TcStore. +// * @param data Pointer to the complete TC Space Packet. +// * @param Size size of the packet. +// */ +// TcPacketStoredBase(const uint8_t* data, uint32_t size); +// +// virtual ~TcPacketStoredBase(); +// +// /** +// * Getter function for the raw data. +// * @param dataPtr [out] Pointer to the data pointer to set +// * @param dataSize [out] Address of size to set. +// * @return -@c RETURN_OK if data was retrieved successfully. +// */ +// ReturnValue_t getData(const uint8_t** dataPtr, size_t* dataSize) override; +// +// void setStoreAddress(store_address_t setAddress, RedirectableDataPointerIF* packet) override; +// store_address_t getStoreAddress() override; +// +// /** +// * With this call, the packet is deleted. +// * It removes itself from the store and sets its data pointer to NULL. +// * @return returncode from deleting the data. +// */ +// virtual ReturnValue_t deletePacket() = 0; +// +// /** +// * This method performs a size check. +// * It reads the stored size and compares it with the size entered in the +// * packet header. This class is the optimal place for such a check as it +// * has access to both the header data and the store. +// * @return true if size is correct, false if packet is not registered in +// * store or size is incorrect. +// */ +// virtual bool isSizeCorrect() = 0; +// +// protected: +// /** +// * This is a pointer to the store all instances of the class use. +// * If the store is not yet set (i.e. @c store is NULL), every constructor +// * call tries to set it and throws an error message in case of failures. +// * The default store is objects::TC_STORE. +// */ +// static StorageManagerIF* STORE; +// /** +// * The address where the packet data of the object instance is stored. +// */ +// store_address_t storeAddress; +// /** +// * A helper method to check if a store is assigned to the class. +// * If not, the method tries to retrieve the store from the global +// * ObjectManager. +// * @return @li @c true if the store is linked or could be created. +// * @li @c false otherwise. +// */ +// static bool checkAndSetStore(); +//}; #endif /* TMTCPACKET_PUS_TCPACKETSTORED_H_ */ diff --git a/src/fsfw/tmtcpacket/pus/tc/TcPacketStoredPus.cpp b/src/fsfw/tmtcpacket/pus/tc/TcPacketStoredPus.cpp deleted file mode 100644 index 95350ac28..000000000 --- a/src/fsfw/tmtcpacket/pus/tc/TcPacketStoredPus.cpp +++ /dev/null @@ -1,78 +0,0 @@ -#include "fsfw/tmtcpacket/pus/tc/TcPacketStoredPus.h" - -#include - -#include "fsfw/serviceinterface/ServiceInterface.h" - -TcPacketStoredPus::TcPacketStoredPus(uint16_t apid, uint8_t service, uint8_t subservice, - uint8_t sequenceCount, const uint8_t* data, size_t size, - uint8_t ack) - : TcPacketPus(nullptr) { - this->storeAddress.raw = StorageManagerIF::INVALID_ADDRESS; - if (not this->checkAndSetStore()) { - return; - } - uint8_t* pData = nullptr; - ReturnValue_t returnValue = - this->STORE->getFreeElement(&this->storeAddress, (TC_PACKET_MIN_SIZE + size), &pData); - if (returnValue != this->STORE->RETURN_OK) { -#if FSFW_CPP_OSTREAM_ENABLED == 1 - sif::warning << "TcPacketStoredBase: Could not get free element from store!" << std::endl; -#endif - return; - } - this->setData(pData, TC_PACKET_MIN_SIZE + size, nullptr); -#if FSFW_USE_PUS_C_TELECOMMANDS == 1 - pus::PusVersion pusVersion = pus::PusVersion::PUS_C_VERSION; -#else - pus::PusVersion pusVersion = pus::PusVersion::PUS_A_VERSION; -#endif - initializeTcPacket(apid, sequenceCount, ack, service, subservice, pusVersion); - std::memcpy(&tcData->appData, data, size); - this->setPacketDataLength(size + sizeof(PUSTcDataFieldHeader) + CRC_SIZE - 1); - this->setErrorControl(); -} - -TcPacketStoredPus::TcPacketStoredPus() : TcPacketStoredBase(), TcPacketPus(nullptr) {} - -TcPacketStoredPus::TcPacketStoredPus(store_address_t setAddress) : TcPacketPus(nullptr) { - TcPacketStoredBase::setStoreAddress(setAddress, this); -} - -TcPacketStoredPus::TcPacketStoredPus(const uint8_t* data, size_t size) : TcPacketPus(data) { - if (this->getFullSize() != size) { - return; - } - if (this->checkAndSetStore()) { - ReturnValue_t status = STORE->addData(&storeAddress, data, size); - if (status != HasReturnvaluesIF::RETURN_OK) { - this->setData(nullptr, size, nullptr); - } - const uint8_t* storePtr = nullptr; - // Repoint base data pointer to the data in the store. - STORE->getData(storeAddress, &storePtr, &size); - this->setData(const_cast(storePtr), size, nullptr); - } -} - -ReturnValue_t TcPacketStoredPus::deletePacket() { - ReturnValue_t result = this->STORE->deleteData(this->storeAddress); - this->storeAddress.raw = StorageManagerIF::INVALID_ADDRESS; - // To circumvent size checks - this->setData(nullptr, -1, nullptr); - return result; -} - -TcPacketPusBase* TcPacketStoredPus::getPacketBase() { return this; } - -bool TcPacketStoredPus::isSizeCorrect() { - const uint8_t* temp_data = nullptr; - size_t temp_size; - ReturnValue_t status = this->STORE->getData(this->storeAddress, &temp_data, &temp_size); - if (status == StorageManagerIF::RETURN_OK) { - if (this->getFullSize() == temp_size) { - return true; - } - } - return false; -} diff --git a/src/fsfw/tmtcpacket/pus/tc/TcPacketStoredPus.h b/src/fsfw/tmtcpacket/pus/tc/TcPacketStoredPus.h deleted file mode 100644 index 45dec293b..000000000 --- a/src/fsfw/tmtcpacket/pus/tc/TcPacketStoredPus.h +++ /dev/null @@ -1,48 +0,0 @@ -#ifndef FSFW_TMTCPACKET_PUS_TCPACKETSTOREDPUSA_H_ -#define FSFW_TMTCPACKET_PUS_TCPACKETSTOREDPUSA_H_ - -#include "TcPacketPus.h" -#include "TcPacketStoredBase.h" - -class TcPacketStoredPus : public TcPacketStoredBase, public TcPacketPus { - public: - /** - * With this constructor, new space is allocated in the packet store and - * a new PUS Telecommand Packet is created there. - * Packet Application Data passed in data is copied into the packet. - * @param apid Sets the packet's APID field. - * @param service Sets the packet's Service ID field. - * This specifies the destination service. - * @param subservice Sets the packet's Service Subtype field. - * This specifies the destination sub-service. - * @param sequence_count Sets the packet's Source Sequence Count field. - * @param data The data to be copied to the Application Data Field. - * @param size The amount of data to be copied. - * @param ack Set's the packet's Ack field, which specifies - * number of verification packets returned - * for this command. - */ - TcPacketStoredPus(uint16_t apid, uint8_t service, uint8_t subservice, uint8_t sequence_count = 0, - const uint8_t* data = nullptr, size_t size = 0, - uint8_t ack = TcPacketPusBase::ACK_ALL); - /** - * Create stored packet with existing data. - * @param data - * @param size - */ - TcPacketStoredPus(const uint8_t* data, size_t size); - /** - * Create stored packet from existing packet in store - * @param setAddress - */ - TcPacketStoredPus(store_address_t setAddress); - TcPacketStoredPus(); - - ReturnValue_t deletePacket() override; - TcPacketPusBase* getPacketBase(); - - private: - bool isSizeCorrect() override; -}; - -#endif /* FSFW_TMTCPACKET_PUS_TCPACKETSTOREDPUSA_H_ */ diff --git a/src/fsfw/tmtcpacket/pus/tm.h b/src/fsfw/tmtcpacket/pus/tm.h index afbe8251b..657790f43 100644 --- a/src/fsfw/tmtcpacket/pus/tm.h +++ b/src/fsfw/tmtcpacket/pus/tm.h @@ -11,6 +11,6 @@ #include "tm/TmPacketStoredPusA.h" #endif -#include "tm/TmPacketMinimal.h" +#include "tm/PusTmMinimal.h" #endif /* FSFW_TMTCPACKET_PUS_TM_H_ */ diff --git a/src/fsfw/tmtcpacket/pus/tm/CMakeLists.txt b/src/fsfw/tmtcpacket/pus/tm/CMakeLists.txt index 22fbebcd4..57c45927a 100644 --- a/src/fsfw/tmtcpacket/pus/tm/CMakeLists.txt +++ b/src/fsfw/tmtcpacket/pus/tm/CMakeLists.txt @@ -1,4 +1,2 @@ -target_sources( - ${LIB_FSFW_NAME} - PRIVATE TmPacketStoredPusC.cpp TmPacketPusC.cpp TmPacketStoredBase.cpp - TmPacketBase.cpp TmPacketMinimal.cpp) +target_sources(${LIB_FSFW_NAME} PRIVATE PusTmCreator.cpp PusTmReader.cpp + PusTmMinimal.cpp) diff --git a/src/fsfw/tmtcpacket/pus/tm/PusTmCreator.cpp b/src/fsfw/tmtcpacket/pus/tm/PusTmCreator.cpp new file mode 100644 index 000000000..5a1f4144b --- /dev/null +++ b/src/fsfw/tmtcpacket/pus/tm/PusTmCreator.cpp @@ -0,0 +1,10 @@ +#include "PusTmCreator.h" + +PusTmCreator::PusTmCreator(PusTmParams params_) : params(params_){}; + +uint16_t PusTmCreator::getPacketId() const { return 0; } +uint16_t PusTmCreator::getPacketSeqCtrl() const { return 0; } +uint16_t PusTmCreator::getPacketDataLen() const { return 0; } +uint8_t PusTmCreator::getPusVersion() const { return 0; } +uint8_t PusTmCreator::getService() const { return 0; } +uint8_t PusTmCreator::getSubService() const { return 0; } diff --git a/src/fsfw/tmtcpacket/pus/tm/PusTmCreator.h b/src/fsfw/tmtcpacket/pus/tm/PusTmCreator.h new file mode 100644 index 000000000..fbdeb7d9f --- /dev/null +++ b/src/fsfw/tmtcpacket/pus/tm/PusTmCreator.h @@ -0,0 +1,31 @@ +#ifndef FSFW_TMTCPACKET_TMPACKETCREATOR_H +#define FSFW_TMTCPACKET_TMPACKETCREATOR_H + +#include "fsfw/tmtcpacket/pus/PusIF.h" + +struct PusTmParams { + uint8_t pusVersion; + uint8_t scTimeRefStatus; + uint8_t service; + uint8_t subservice; + uint16_t messageTypeCounter; + uint16_t destId; + uint8_t* timestamp; + size_t timestampLen; +}; +class PusTmCreator : public PusIF { + public: + ~PusTmCreator() override = default; + explicit PusTmCreator(PusTmParams params); + + [[nodiscard]] uint16_t getPacketId() const override; + [[nodiscard]] uint16_t getPacketSeqCtrl() const override; + [[nodiscard]] uint16_t getPacketDataLen() const override; + [[nodiscard]] uint8_t getPusVersion() const override; + [[nodiscard]] uint8_t getService() const override; + [[nodiscard]] uint8_t getSubService() const override; + + private: + PusTmParams params; +}; +#endif // FSFW_TMTCPACKET_TMPACKETCREATOR_H diff --git a/src/fsfw/tmtcpacket/pus/tm/PusTmIF.h b/src/fsfw/tmtcpacket/pus/tm/PusTmIF.h new file mode 100644 index 000000000..b22bdf3da --- /dev/null +++ b/src/fsfw/tmtcpacket/pus/tm/PusTmIF.h @@ -0,0 +1,20 @@ +#ifndef FSFW_TMTCPACKET_PUSTMIF_H +#define FSFW_TMTCPACKET_PUSTMIF_H + +#include +#include + +#include "fsfw/tmtcpacket/pus/PusIF.h" + +class PusTmIF : public PusIF { + public: + ~PusTmIF() override = default; + + virtual uint8_t getScTimeRefStatus() = 0; + virtual uint16_t getMessageTypeCounter() = 0; + virtual uint16_t getDestId() = 0; + virtual const uint8_t* getTimestamp(size_t& timeStampLen) = 0; + virtual size_t getTimestampLen() = 0; +}; + +#endif // FSFW_TMTCPACKET_PUSTMIF_H diff --git a/src/fsfw/tmtcpacket/pus/tm/PusTmMinimal.cpp b/src/fsfw/tmtcpacket/pus/tm/PusTmMinimal.cpp new file mode 100644 index 000000000..4042528ab --- /dev/null +++ b/src/fsfw/tmtcpacket/pus/tm/PusTmMinimal.cpp @@ -0,0 +1,45 @@ +#include "fsfw/tmtcpacket/pus/tm/PusTmMinimal.h" + +#include +#include + +#include "fsfw/tmtcpacket/pus/PacketTimestampInterpreterIF.h" + +PusTmMinimal::PusTmMinimal(uint8_t* data) { + this->tmData = reinterpret_cast(data); +} + +PusTmMinimal::~PusTmMinimal() = default; + +ReturnValue_t PusTmMinimal::getPacketTime(timeval* timestamp) { + if (timestampInterpreter == nullptr) { + return HasReturnvaluesIF::RETURN_FAILED; + } + return timestampInterpreter->getPacketTime(this, timestamp); +} + +void PusTmMinimal::setInterpretTimestampObject(PacketTimestampInterpreterIF* interpreter) { + if (PusTmMinimal::timestampInterpreter == nullptr) { + PusTmMinimal::timestampInterpreter = interpreter; + } +} + +PacketTimestampInterpreterIF* PusTmMinimal::timestampInterpreter = nullptr; +// TODO: Implement all of this +ReturnValue_t PusTmMinimal::setData(uint8_t* dataPtr, size_t size, void* args) { return 0; } +uint16_t PusTmMinimal::getPacketId() const { return 0; } +uint16_t PusTmMinimal::getPacketSeqCtrl() const { return 0; } +uint16_t PusTmMinimal::getPacketDataLen() const { return 0; } +uint8_t PusTmMinimal::getPusVersion() const { return 0; } +uint8_t PusTmMinimal::getService() const { return tmData->secHeader.service; } +uint8_t PusTmMinimal::getSubService() const { return tmData->secHeader.subservice; } +const uint8_t* PusTmMinimal::getUserData(size_t& appDataLen) const { return nullptr; } +uint16_t PusTmMinimal::getUserDataSize() const { return 0; } +uint8_t PusTmMinimal::getScTimeRefStatus() { return 0; } +uint16_t PusTmMinimal::getMessageTypeCounter() { return tmData->secHeader.messageTypeCounter; } +uint16_t PusTmMinimal::getDestId() { return 0; } +const uint8_t* PusTmMinimal::getTimestamp(size_t& timeStampLen) { return nullptr; } +size_t PusTmMinimal::getTimestampLen() { return 0; } +void PusTmMinimal::setApid(uint16_t apid) { + /* TODO: Implement. Maybe provide low level function to do this */ +} diff --git a/src/fsfw/tmtcpacket/pus/tm/TmPacketMinimal.h b/src/fsfw/tmtcpacket/pus/tm/PusTmMinimal.h similarity index 54% rename from src/fsfw/tmtcpacket/pus/tm/TmPacketMinimal.h rename to src/fsfw/tmtcpacket/pus/tm/PusTmMinimal.h index 197bf6e6b..a09523fbd 100644 --- a/src/fsfw/tmtcpacket/pus/tm/TmPacketMinimal.h +++ b/src/fsfw/tmtcpacket/pus/tm/PusTmMinimal.h @@ -1,8 +1,9 @@ #ifndef FRAMEWORK_TMTCPACKET_PUS_TMPACKETMINIMAL_H_ #define FRAMEWORK_TMTCPACKET_PUS_TMPACKETMINIMAL_H_ -#include "../../../returnvalues/HasReturnvaluesIF.h" -#include "../../SpacePacketReader.h" +#include "PusTmIF.h" +#include "fsfw/returnvalues/HasReturnvaluesIF.h" +#include "fsfw/tmtcpacket/SpacePacketReader.h" struct timeval; class PacketTimestampInterpreterIF; @@ -12,7 +13,7 @@ class PacketTimestampInterpreterIF; * This is required for handling TM packets with different APIDs with different * secondary headers. */ -class TmPacketMinimal : public SpacePacketReader { +class PusTmMinimal : public PusTmIF, public RedirectableDataPointerIF { public: /** * This is the default constructor. @@ -20,40 +21,40 @@ class TmPacketMinimal : public SpacePacketReader { * forwards the data pointer to the parent SpacePacketBase class. * @param set_address The position where the packet data lies. */ - TmPacketMinimal(const uint8_t* set_data); + explicit PusTmMinimal(uint8_t* data); /** * This is the empty default destructor. */ - virtual ~TmPacketMinimal(); - /** - * This is a getter for the packet's PUS Service ID, which is the second - * byte of the Data Field Header. - * @return The packet's PUS Service ID. - */ - uint8_t getService(); - /** - * This is a getter for the packet's PUS Service Subtype, which is the - * third byte of the Data Field Header. - * @return The packet's PUS Service Subtype. - */ - uint8_t getSubService(); - /** - * Returns the subcounter. - * @return the subcounter of the Data Field Header. - */ - uint8_t getPacketSubcounter(); - struct PUSTmMinimalHeader { - uint8_t version_type_ack; - uint8_t service_type; - uint8_t service_subtype; - uint8_t subcounter; - }; + ~PusTmMinimal() override; + + void setApid(uint16_t apid); ReturnValue_t getPacketTime(timeval* timestamp); - ReturnValue_t getPacketTimeRaw(const uint8_t** timePtr, uint32_t* size); - static void setInterpretTimestampObject(PacketTimestampInterpreterIF* interpreter); + ReturnValue_t setData(uint8_t* dataPtr, size_t size, void* args) override; + [[nodiscard]] uint16_t getPacketId() const override; + [[nodiscard]] uint16_t getPacketSeqCtrl() const override; + [[nodiscard]] uint16_t getPacketDataLen() const override; + [[nodiscard]] uint8_t getPusVersion() const override; + [[nodiscard]] uint8_t getService() const override; + [[nodiscard]] uint8_t getSubService() const override; + const uint8_t* getUserData(size_t& appDataLen) const override; + [[nodiscard]] uint16_t getUserDataSize() const override; + uint8_t getScTimeRefStatus() override; + uint16_t getMessageTypeCounter() override; + uint16_t getDestId() override; + const uint8_t* getTimestamp(size_t& timeStampLen) override; + size_t getTimestampLen() override; + + // NOTE: Only PUS C compatible! + struct PusTmMinimalSecHeader { + uint8_t versionAndScTimeRefStatus; + uint8_t service; + uint8_t subservice; + uint16_t messageTypeCounter; + }; + /** * This struct defines the data structure of a PUS Telecommand Packet when * accessed via a pointer. @@ -61,7 +62,7 @@ class TmPacketMinimal : public SpacePacketReader { */ struct TmPacketMinimalPointer { CCSDSPrimaryHeader primary; - PUSTmMinimalHeader data_field; + PusTmMinimalSecHeader secHeader; uint8_t rest; }; // Must include a checksum and is therefore at least one larger than the above struct. @@ -74,7 +75,7 @@ class TmPacketMinimal : public SpacePacketReader { * * To be hardware-safe, all elements are of byte size. */ - TmPacketMinimalPointer* tm_data; + TmPacketMinimalPointer* tmData; static PacketTimestampInterpreterIF* timestampInterpreter; }; diff --git a/src/fsfw/tmtcpacket/pus/tm/PusTmReader.cpp b/src/fsfw/tmtcpacket/pus/tm/PusTmReader.cpp new file mode 100644 index 000000000..d010512ad --- /dev/null +++ b/src/fsfw/tmtcpacket/pus/tm/PusTmReader.cpp @@ -0,0 +1,3 @@ +// +// Created by rmueller on 7/19/22. +// diff --git a/src/fsfw/tmtcpacket/pus/tm/PusTmReader.h b/src/fsfw/tmtcpacket/pus/tm/PusTmReader.h new file mode 100644 index 000000000..47eff2936 --- /dev/null +++ b/src/fsfw/tmtcpacket/pus/tm/PusTmReader.h @@ -0,0 +1,7 @@ +#ifndef FSFW_TMTCPACKET_PUSTMREADER_H +#define FSFW_TMTCPACKET_PUSTMREADER_H + +#include "fsfw/tmtcpacket/pus/tm/PusTmIF.h" + +class PusTmReader : public PusTmIF {}; +#endif // FSFW_TMTCPACKET_PUSTMREADER_H diff --git a/src/fsfw/tmtcpacket/pus/tm/TmPacketMinimal.cpp b/src/fsfw/tmtcpacket/pus/tm/TmPacketMinimal.cpp deleted file mode 100644 index c1a5c4ba7..000000000 --- a/src/fsfw/tmtcpacket/pus/tm/TmPacketMinimal.cpp +++ /dev/null @@ -1,40 +0,0 @@ -#include "fsfw/tmtcpacket/pus/tm/TmPacketMinimal.h" - -#include -#include - -#include "fsfw/tmtcpacket/pus/PacketTimestampInterpreterIF.h" - -TmPacketMinimal::TmPacketMinimal(const uint8_t* set_data) : SpacePacketReader(set_data) { - this->tm_data = (TmPacketMinimalPointer*)set_data; -} - -TmPacketMinimal::~TmPacketMinimal() {} - -uint8_t TmPacketMinimal::getService() { return tm_data->data_field.service_type; } - -uint8_t TmPacketMinimal::getSubService() { return tm_data->data_field.service_subtype; } - -uint8_t TmPacketMinimal::getPacketSubcounter() { return tm_data->data_field.subcounter; } - -ReturnValue_t TmPacketMinimal::getPacketTime(timeval* timestamp) { - if (timestampInterpreter == NULL) { - return HasReturnvaluesIF::RETURN_FAILED; - } - return timestampInterpreter->getPacketTime(this, timestamp); -} - -ReturnValue_t TmPacketMinimal::getPacketTimeRaw(const uint8_t** timePtr, uint32_t* size) { - if (timestampInterpreter == NULL) { - return HasReturnvaluesIF::RETURN_FAILED; - } - return timestampInterpreter->getPacketTimeRaw(this, timePtr, size); -} - -void TmPacketMinimal::setInterpretTimestampObject(PacketTimestampInterpreterIF* interpreter) { - if (TmPacketMinimal::timestampInterpreter == NULL) { - TmPacketMinimal::timestampInterpreter = interpreter; - } -} - -PacketTimestampInterpreterIF* TmPacketMinimal::timestampInterpreter = NULL; diff --git a/src/fsfw/tmtcpacket/pus/tm/TmPacketPusC.cpp b/src/fsfw/tmtcpacket/pus/tm/TmPacketPusC.cpp index fd2248aa7..7ae6de82d 100644 --- a/src/fsfw/tmtcpacket/pus/tm/TmPacketPusC.cpp +++ b/src/fsfw/tmtcpacket/pus/tm/TmPacketPusC.cpp @@ -58,8 +58,7 @@ ReturnValue_t TmPacketPusC::initializeTmPacket(uint16_t apid, uint8_t service, u /* Only account for last 4 bytes for time reference field */ timeRefField &= 0b1111; - tmData->dataField.versionTimeReferenceField = - (pus::PusVersion::PUS_C_VERSION << 4) | timeRefField; + tmData->dataField.versionTimeReferenceField = (ecss::PusVersion::PUS_C << 4) | timeRefField; tmData->dataField.serviceType = service; tmData->dataField.serviceSubtype = subservice; tmData->dataField.subcounterMsb = (packetSubcounter << 8) & 0xff; diff --git a/src/fsfw/tmtcservices/PusServiceBase.cpp b/src/fsfw/tmtcservices/PusServiceBase.cpp index 3af2b82ce..f0cdb61b9 100644 --- a/src/fsfw/tmtcservices/PusServiceBase.cpp +++ b/src/fsfw/tmtcservices/PusServiceBase.cpp @@ -11,8 +11,9 @@ object_id_t PusServiceBase::packetSource = 0; object_id_t PusServiceBase::packetDestination = 0; -PusServiceBase::PusServiceBase(object_id_t setObjectId, uint16_t setApid, uint8_t setServiceId) - : SystemObject(setObjectId), apid(setApid), serviceId(setServiceId) { +PusServiceBase::PusServiceBase(object_id_t setObjectId, uint16_t setApid, uint8_t setServiceId, + StorageManagerIF* store_) + : SystemObject(setObjectId), apid(setApid), serviceId(setServiceId), store(store_) { requestQueue = QueueFactory::instance()->createMessageQueue(PUS_SERVICE_MAX_RECEPTION); } @@ -31,7 +32,7 @@ ReturnValue_t PusServiceBase::performOperation(uint8_t opCode) { return RETURN_OK; } -void PusServiceBase::setTaskIF(PeriodicTaskIF* taskHandle) { this->taskHandle = taskHandle; } +void PusServiceBase::setTaskIF(PeriodicTaskIF* taskHandle_) { this->taskHandle = taskHandle_; } void PusServiceBase::handleRequestQueue() { TmTcMessage message; @@ -49,7 +50,14 @@ void PusServiceBase::handleRequestQueue() { // } if (status == RETURN_OK) { - this->currentPacket.setStoreAddress(message.getStorageId(), ¤tPacket); + const uint8_t* dataPtr; + size_t dataLen = 0; + result = store->getData(message.getStorageId(), &dataPtr, &dataLen); + if (result != HasReturnvaluesIF::RETURN_OK) { + // TODO: Warning? + } + + currentPacket.setData(dataPtr, dataLen); // info << "Service " << (uint16_t) this->serviceId << // ": new packet!" << std::endl; @@ -65,7 +73,7 @@ void PusServiceBase::handleRequestQueue() { &this->currentPacket, result, 0, errorParameter1, errorParameter2); } - this->currentPacket.deletePacket(); + store->deleteData(message.getStorageId()); errorParameter1 = 0; errorParameter2 = 0; } else if (status == MessageQueueIF::EMPTY) { @@ -92,9 +100,8 @@ ReturnValue_t PusServiceBase::initialize() { if (result != RETURN_OK) { return result; } - AcceptsTelemetryIF* destService = - ObjectManager::instance()->get(packetDestination); - PUSDistributorIF* distributor = ObjectManager::instance()->get(packetSource); + auto* destService = ObjectManager::instance()->get(packetDestination); + auto* distributor = ObjectManager::instance()->get(packetSource); if (destService == nullptr or distributor == nullptr) { #if FSFW_CPP_OSTREAM_ENABLED == 1 sif::error << "PusServiceBase::PusServiceBase: Service " << this->serviceId diff --git a/src/fsfw/tmtcservices/PusServiceBase.h b/src/fsfw/tmtcservices/PusServiceBase.h index 9db1bef0b..57547ace1 100644 --- a/src/fsfw/tmtcservices/PusServiceBase.h +++ b/src/fsfw/tmtcservices/PusServiceBase.h @@ -9,12 +9,13 @@ #include "fsfw/objectmanager/SystemObject.h" #include "fsfw/returnvalues/HasReturnvaluesIF.h" #include "fsfw/tasks/ExecutableObjectIF.h" -#include "fsfw/tmtcpacket/pus/tc.h" namespace Factory { void setStaticFrameworkObjectIds(); } +class StorageManagerIF; + /** * @defgroup pus_services PUS Service Framework * These group contains all implementations of PUS Services in the OBSW. @@ -50,11 +51,12 @@ class PusServiceBase : public ExecutableObjectIF, * @param setServiceId * The Service Identifier as specified in ECSS PUS. */ - PusServiceBase(object_id_t setObjectId, uint16_t setApid, uint8_t setServiceId); + PusServiceBase(object_id_t setObjectId, uint16_t setApid, uint8_t setServiceId, + StorageManagerIF* store); /** * The destructor is empty. */ - virtual ~PusServiceBase(); + ~PusServiceBase() override; /** * @brief The handleRequest method shall handle any kind of Telecommand * Request immediately. @@ -97,12 +99,12 @@ class PusServiceBase : public ExecutableObjectIF, * @c RETURN_FAILED else. */ ReturnValue_t performOperation(uint8_t opCode) override; - virtual uint16_t getIdentifier() override; + uint16_t getIdentifier() override; MessageQueueId_t getRequestQueue() override; - virtual ReturnValue_t initialize() override; + ReturnValue_t initialize() override; - virtual void setTaskIF(PeriodicTaskIF* taskHandle) override; - virtual ReturnValue_t initializeAfterTaskCreation() override; + void setTaskIF(PeriodicTaskIF* taskHandle) override; + ReturnValue_t initializeAfterTaskCreation() override; protected: /** @@ -141,7 +143,9 @@ class PusServiceBase : public ExecutableObjectIF, * The current Telecommand to be processed. * It is deleted after handleRequest was executed. */ - TcPacketStoredPus currentPacket; + // TcPacketStoredPus currentPacket; + StorageManagerIF* store; + PusTcReader currentPacket; static object_id_t packetSource; diff --git a/src/fsfw/tmtcservices/VerificationReporter.cpp b/src/fsfw/tmtcservices/VerificationReporter.cpp index 19277bf3c..bf33d1c42 100644 --- a/src/fsfw/tmtcservices/VerificationReporter.cpp +++ b/src/fsfw/tmtcservices/VerificationReporter.cpp @@ -11,9 +11,9 @@ object_id_t VerificationReporter::messageReceiver = objects::PUS_SERVICE_1_VERIF VerificationReporter::VerificationReporter() : acknowledgeQueue(MessageQueueIF::NO_QUEUE) {} -VerificationReporter::~VerificationReporter() {} +VerificationReporter::~VerificationReporter() = default; -void VerificationReporter::sendSuccessReport(uint8_t set_report_id, TcPacketPusBase* currentPacket, +void VerificationReporter::sendSuccessReport(uint8_t set_report_id, PusTcReader* currentPacket, uint8_t set_step) { if (acknowledgeQueue == MessageQueueIF::NO_QUEUE) { this->initialize(); @@ -50,7 +50,7 @@ void VerificationReporter::sendSuccessReport(uint8_t set_report_id, uint8_t ackF } } -void VerificationReporter::sendFailureReport(uint8_t report_id, TcPacketPusBase* currentPacket, +void VerificationReporter::sendFailureReport(uint8_t report_id, PusTcReader* currentPacket, ReturnValue_t error_code, uint8_t step, uint32_t parameter1, uint32_t parameter2) { if (acknowledgeQueue == MessageQueueIF::NO_QUEUE) { @@ -98,8 +98,7 @@ void VerificationReporter::initialize() { #endif return; } - AcceptsVerifyMessageIF* temp = - ObjectManager::instance()->get(messageReceiver); + auto* temp = ObjectManager::instance()->get(messageReceiver); if (temp == nullptr) { #if FSFW_CPP_OSTREAM_ENABLED == 1 sif::error << "VerificationReporter::initialize: Message " diff --git a/src/fsfw/tmtcservices/VerificationReporter.h b/src/fsfw/tmtcservices/VerificationReporter.h index c29afd603..5b4dbe0aa 100644 --- a/src/fsfw/tmtcservices/VerificationReporter.h +++ b/src/fsfw/tmtcservices/VerificationReporter.h @@ -3,6 +3,7 @@ #include "PusVerificationReport.h" #include "fsfw/objectmanager/ObjectManagerIF.h" +#include "fsfw/tmtcpacket/pus/tc/PusTcCreator.h" namespace Factory { void setStaticFrameworkObjectIds(); @@ -26,12 +27,11 @@ class VerificationReporter { VerificationReporter(); virtual ~VerificationReporter(); - void sendSuccessReport(uint8_t set_report_id, TcPacketPusBase* current_packet, - uint8_t set_step = 0); + void sendSuccessReport(uint8_t set_report_id, PusTcReader* current_packet, uint8_t set_step = 0); void sendSuccessReport(uint8_t set_report_id, uint8_t ackFlags, uint16_t tcPacketId, uint16_t tcSequenceControl, uint8_t set_step = 0); - void sendFailureReport(uint8_t report_id, TcPacketPusBase* current_packet, + void sendFailureReport(uint8_t report_id, PusTcReader* current_packet, ReturnValue_t error_code = 0, uint8_t step = 0, uint32_t parameter1 = 0, uint32_t parameter2 = 0); void sendFailureReport(uint8_t report_id, uint8_t ackFlags, uint16_t tcPacketId,