From 0a7f2c6646481e1af22afa667aea9abac0497ce0 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Mon, 18 Jul 2022 10:20:26 +0200 Subject: [PATCH 001/108] refactored space packet interface --- CMakeLists.txt | 2 +- src/fsfw/osal/linux/MessageQueue.cpp | 3 +- src/fsfw/tcdistribution/CCSDSDistributor.cpp | 2 +- src/fsfw/tcdistribution/TcPacketCheckPUS.cpp | 12 +-- src/fsfw/tmtcpacket/CMakeLists.txt | 2 +- .../tmtcpacket/RedirectableDataPointerIF.h | 9 +- src/fsfw/tmtcpacket/SpacePacket.cpp | 28 ------ src/fsfw/tmtcpacket/SpacePacket.h | 89 ------------------ src/fsfw/tmtcpacket/SpacePacketBase.cpp | 86 ++++++------------ src/fsfw/tmtcpacket/SpacePacketBase.h | 85 +++-------------- src/fsfw/tmtcpacket/SpacePacketIF.h | 91 +++++++++++++++++++ src/fsfw/tmtcpacket/ccsds_header.h | 14 +-- src/fsfw/tmtcpacket/cfdp/CFDPPacketStored.cpp | 30 +++--- src/fsfw/tmtcpacket/cfdp/CFDPPacketStored.h | 7 -- .../tmtcpacket/packetmatcher/ApidMatcher.h | 19 ++-- .../packetmatcher/PacketMatchTree.cpp | 4 +- src/fsfw/tmtcpacket/pus/tc/TcPacketPus.cpp | 4 +- src/fsfw/tmtcpacket/pus/tc/TcPacketPus.h | 2 +- src/fsfw/tmtcpacket/pus/tc/TcPacketPusBase.h | 2 +- .../tmtcpacket/pus/tc/TcPacketStoredPus.cpp | 8 +- src/fsfw/tmtcpacket/pus/tm/TmPacketBase.cpp | 10 +- src/fsfw/tmtcpacket/pus/tm/TmPacketPusA.cpp | 4 +- src/fsfw/tmtcpacket/pus/tm/TmPacketPusC.cpp | 12 +-- src/fsfw/tmtcpacket/pus/tm/TmPacketPusC.h | 2 +- .../tmtcpacket/pus/tm/TmPacketStoredPusC.cpp | 6 +- .../tmtcpacket/pus/tm/TmPacketStoredPusC.h | 2 +- .../tmtcservices/CommandingServiceBase.cpp | 2 +- .../tmtcservices/VerificationReporter.cpp | 10 +- .../fsfw_tests/unit/tmtcpacket/testCcsds.cpp | 10 +- 29 files changed, 218 insertions(+), 339 deletions(-) delete mode 100644 src/fsfw/tmtcpacket/SpacePacket.cpp delete mode 100644 src/fsfw/tmtcpacket/SpacePacket.h create mode 100644 src/fsfw/tmtcpacket/SpacePacketIF.h diff --git a/CMakeLists.txt b/CMakeLists.txt index e9e3e471..440d7f9b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -133,7 +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}) +add_library(${LIB_FSFW_NAME} src/fsfw/tmtcpacket/SpacePacketIF.h) if(IPO_SUPPORTED AND FSFW_ENABLE_IPO) set_property(TARGET ${LIB_FSFW_NAME} PROPERTY INTERPROCEDURAL_OPTIMIZATION diff --git a/src/fsfw/osal/linux/MessageQueue.cpp b/src/fsfw/osal/linux/MessageQueue.cpp index 4ef7f756..ec212165 100644 --- a/src/fsfw/osal/linux/MessageQueue.cpp +++ b/src/fsfw/osal/linux/MessageQueue.cpp @@ -292,7 +292,8 @@ ReturnValue_t MessageQueue::handleOpenError(mq_attr* attributes, uint32_t messag sif::error << "MessageQueue::MessageQueue: Default MQ size " << defaultMqMaxMsg << " is too small for requested message depth " << messageDepth << std::endl; sif::error << "This error can be fixed by setting the maximum " - "allowed message depth higher" << std::endl; + "allowed message depth higher" + << std::endl; #else sif::printError( "MessageQueue::MessageQueue: Default MQ size %d is too small for" diff --git a/src/fsfw/tcdistribution/CCSDSDistributor.cpp b/src/fsfw/tcdistribution/CCSDSDistributor.cpp index 628dd8d0..0be177bf 100644 --- a/src/fsfw/tcdistribution/CCSDSDistributor.cpp +++ b/src/fsfw/tcdistribution/CCSDSDistributor.cpp @@ -46,7 +46,7 @@ TcDistributor::TcMqMapIter CCSDSDistributor::selectDestination() { sif::info << "CCSDSDistributor::selectDestination has packet with APID " << std::hex << currentPacket.getAPID() << std::dec << std::endl; #endif - auto position = this->queueMap.find(currentPacket.getAPID()); + auto position = this->queueMap.find(currentPacket.getApid()); if (position != this->queueMap.end()) { return position; } else { diff --git a/src/fsfw/tcdistribution/TcPacketCheckPUS.cpp b/src/fsfw/tcdistribution/TcPacketCheckPUS.cpp index 83844337..6d7092e5 100644 --- a/src/fsfw/tcdistribution/TcPacketCheckPUS.cpp +++ b/src/fsfw/tcdistribution/TcPacketCheckPUS.cpp @@ -11,8 +11,8 @@ TcPacketCheckPUS::TcPacketCheckPUS(uint16_t setApid) : apid(setApid) {} ReturnValue_t TcPacketCheckPUS::checkPacket(SpacePacketBase* currentPacket) { - TcPacketStoredBase* storedPacket = dynamic_cast(currentPacket); - TcPacketPusBase* tcPacketBase = dynamic_cast(currentPacket); + auto* storedPacket = dynamic_cast(currentPacket); + auto* tcPacketBase = dynamic_cast(currentPacket); if (tcPacketBase == nullptr or storedPacket == nullptr) { return RETURN_FAILED; } @@ -21,13 +21,13 @@ ReturnValue_t TcPacketCheckPUS::checkPacket(SpacePacketBase* currentPacket) { if (calculated_crc != 0) { return INCORRECT_CHECKSUM; } - bool condition = (not tcPacketBase->hasSecondaryHeader()) or - (tcPacketBase->getPacketVersionNumber() != CCSDS_VERSION_NUMBER) or - (not tcPacketBase->isTelecommand()); + 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 (tcPacketBase->getApid() != this->apid) return ILLEGAL_APID; if (not storedPacket->isSizeCorrect()) { return INCOMPLETE_PACKET; diff --git a/src/fsfw/tmtcpacket/CMakeLists.txt b/src/fsfw/tmtcpacket/CMakeLists.txt index 196ba752..dc09c9c9 100644 --- a/src/fsfw/tmtcpacket/CMakeLists.txt +++ b/src/fsfw/tmtcpacket/CMakeLists.txt @@ -1,4 +1,4 @@ -target_sources(${LIB_FSFW_NAME} PRIVATE SpacePacket.cpp SpacePacketBase.cpp) +target_sources(${LIB_FSFW_NAME} PRIVATE SpacePacketBase.cpp) add_subdirectory(cfdp) add_subdirectory(packetmatcher) diff --git a/src/fsfw/tmtcpacket/RedirectableDataPointerIF.h b/src/fsfw/tmtcpacket/RedirectableDataPointerIF.h index 364feb4e..6eb16edd 100644 --- a/src/fsfw/tmtcpacket/RedirectableDataPointerIF.h +++ b/src/fsfw/tmtcpacket/RedirectableDataPointerIF.h @@ -11,7 +11,7 @@ */ class RedirectableDataPointerIF { public: - virtual ~RedirectableDataPointerIF(){}; + virtual ~RedirectableDataPointerIF() = default; /** * Redirect the data pointer, but allow an implementation to change the data. @@ -25,9 +25,12 @@ 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 = nullptr) = 0; + 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); + } private: }; -#endif /* FSFW_SRC_FSFW_TMTCPACKET_PUS_TC_SETTABLEDATAPOINTERIF_H_ */ +#endif /* TMTCPACKET_PUS_TC_SETTABLEDATAPOINTERIF_H_ */ diff --git a/src/fsfw/tmtcpacket/SpacePacket.cpp b/src/fsfw/tmtcpacket/SpacePacket.cpp deleted file mode 100644 index 16d968fb..00000000 --- a/src/fsfw/tmtcpacket/SpacePacket.cpp +++ /dev/null @@ -1,28 +0,0 @@ -#include "fsfw/tmtcpacket/SpacePacket.h" - -#include - -#include "fsfw/tmtcpacket/ccsds_header.h" - -SpacePacket::SpacePacket(uint16_t packetDataLength, bool isTelecommand, uint16_t apid, - uint16_t sequenceCount) - : SpacePacketBase((uint8_t*)&this->localData) { - initSpacePacketHeader(isTelecommand, false, apid, sequenceCount); - this->setPacketSequenceCount(sequenceCount); - if (packetDataLength <= sizeof(this->localData.fields.buffer)) { - this->setPacketDataLength(packetDataLength); - } else { - this->setPacketDataLength(sizeof(this->localData.fields.buffer)); - } -} - -SpacePacket::~SpacePacket(void) {} - -bool SpacePacket::addWholeData(const uint8_t* p_Data, uint32_t packet_size) { - if (packet_size <= sizeof(this->localData)) { - memcpy(this->localData.byteStream, p_Data, packet_size); - return true; - } else { - return false; - } -} diff --git a/src/fsfw/tmtcpacket/SpacePacket.h b/src/fsfw/tmtcpacket/SpacePacket.h deleted file mode 100644 index 10140db1..00000000 --- a/src/fsfw/tmtcpacket/SpacePacket.h +++ /dev/null @@ -1,89 +0,0 @@ -#ifndef SPACEPACKET_H_ -#define SPACEPACKET_H_ - -#include "SpacePacketBase.h" - -/** - * The SpacePacket class is a representation of a simple CCSDS Space Packet - * without (control over) a secondary header. - * It can be instantiated with a size smaller than \c PACKET_MAX_SIZE. Its - * main use is to serve as an idle packet in case no other packets are sent. - * For the ECSS PUS part the TcPacket and TmPacket classes are used. - * A pointer to \c local_data is passed to the \c SpacePacketBase parent class, - * so the parent's methods are reachable. - * @ingroup tmtcpackets - */ -class SpacePacket : public SpacePacketBase { - public: - static const uint16_t PACKET_MAX_SIZE = 1024; - /** - * The constructor initializes the packet and sets all header information - * according to the passed parameters. - * @param packetDataLength Sets the packet data length field and therefore specifies - * the size of the packet. - * @param isTelecommand Sets the packet type field to either TC (true) or TM (false). - * @param apid Sets the packet's APID field. The default value describes an idle packet. - * @param sequenceCount ets the packet's Source Sequence Count field. - */ - SpacePacket(uint16_t packetDataLength, bool isTelecommand = false, - uint16_t apid = APID_IDLE_PACKET, uint16_t sequenceCount = 0); - /** - * The class's default destructor. - */ - virtual ~SpacePacket(); - /** - * With this call, the complete data content (including the CCSDS Primary - * Header) is overwritten with the byte stream given. - * @param p_data Pointer to data to overwrite the content with - * @param packet_size Size of the data - * @return @li \c true if packet_size is smaller than \c MAX_PACKET_SIZE. - * @li \c false else. - */ - bool addWholeData(const uint8_t* p_data, uint32_t packet_size); - - protected: - /** - * This structure defines the data structure of a Space Packet as local data. - * There's a buffer which corresponds to the Space Packet Data Field with a - * maximum size of \c PACKET_MAX_SIZE. - */ - struct PacketStructured { - CCSDSPrimaryHeader header; - uint8_t buffer[PACKET_MAX_SIZE]; - }; - /** - * This union simplifies accessing the full data content of the Space Packet. - * This is achieved by putting the \c PacketStructured struct in a union with - * a plain buffer. - */ - union SpacePacketData { - PacketStructured fields; - uint8_t byteStream[PACKET_MAX_SIZE + sizeof(CCSDSPrimaryHeader)]; - }; - /** - * This is the data representation of the class. - * It is a struct of CCSDS Primary Header and a data field, which again is - * packed in an union, so the data can be accessed as a byte stream without - * a cast. - */ - SpacePacketData localData; -}; - -namespace spacepacket { - -constexpr uint16_t getSpacePacketIdFromApid(bool isTc, uint16_t apid, - bool secondaryHeaderFlag = true) { - return ((isTc << 4) | (secondaryHeaderFlag << 3) | ((apid >> 8) & 0x07)) << 8 | (apid & 0x00ff); -} - -constexpr uint16_t getTcSpacePacketIdFromApid(uint16_t apid, bool secondaryHeaderFlag = true) { - return getSpacePacketIdFromApid(true, apid, secondaryHeaderFlag); -} - -constexpr uint16_t getTmSpacePacketIdFromApid(uint16_t apid, bool secondaryHeaderFlag = true) { - return getSpacePacketIdFromApid(false, apid, secondaryHeaderFlag); -} - -} // namespace spacepacket - -#endif /* SPACEPACKET_H_ */ diff --git a/src/fsfw/tmtcpacket/SpacePacketBase.cpp b/src/fsfw/tmtcpacket/SpacePacketBase.cpp index 756d7e50..cb18519e 100644 --- a/src/fsfw/tmtcpacket/SpacePacketBase.cpp +++ b/src/fsfw/tmtcpacket/SpacePacketBase.cpp @@ -8,12 +8,7 @@ SpacePacketBase::SpacePacketBase(const uint8_t* setAddress) { this->data = reinterpret_cast(const_cast(setAddress)); } -SpacePacketBase::~SpacePacketBase(){}; - -// CCSDS Methods: -uint8_t SpacePacketBase::getPacketVersionNumber(void) { - return (this->data->header.packet_id_h & 0b11100000) >> 5; -} +SpacePacketBase::~SpacePacketBase() = default; ReturnValue_t SpacePacketBase::initSpacePacketHeader(bool isTelecommand, bool hasSecondaryHeader, uint16_t apid, uint16_t sequenceCount) { @@ -30,82 +25,49 @@ ReturnValue_t SpacePacketBase::initSpacePacketHeader(bool isTelecommand, bool ha // reset header to zero: memset(data, 0, sizeof(this->data->header)); // Set TC/TM bit. - data->header.packet_id_h = ((isTelecommand ? 1 : 0)) << 4; + data->header.packetIdHAndVersion = ((isTelecommand ? 1 : 0)) << 4; // Set secondaryHeader bit - data->header.packet_id_h |= ((hasSecondaryHeader ? 1 : 0)) << 3; - this->setAPID(apid); + data->header.packetIdHAndVersion |= ((hasSecondaryHeader ? 1 : 0)) << 3; + this->setApid(apid); // Always initialize as standalone packets. - data->header.sequence_control_h = 0b11000000; + data->header.packetSeqCtrlH = 0b11000000; setPacketSequenceCount(sequenceCount); return HasReturnvaluesIF::RETURN_OK; } -bool SpacePacketBase::isTelecommand(void) { - return (this->data->header.packet_id_h & 0b00010000) >> 4; +inline uint16_t SpacePacketBase::getPacketId() const { + return ((this->data->header.packetIdHAndVersion) << 8) + this->data->header.packetIdL; } -bool SpacePacketBase::hasSecondaryHeader(void) { - return (this->data->header.packet_id_h & 0b00001000) >> 3; -} - -uint16_t SpacePacketBase::getPacketId() { - return ((this->data->header.packet_id_h) << 8) + this->data->header.packet_id_l; -} - -uint16_t SpacePacketBase::getAPID(void) const { - return ((this->data->header.packet_id_h & 0b00000111) << 8) + this->data->header.packet_id_l; -} - -void SpacePacketBase::setAPID(uint16_t new_apid) { +void SpacePacketBase::setApid(uint16_t setAPID) { // Use first three bits of new APID, but keep rest of packet id as it was (see specification). - this->data->header.packet_id_h = - (this->data->header.packet_id_h & 0b11111000) | ((new_apid & 0x0700) >> 8); - this->data->header.packet_id_l = (new_apid & 0x00FF); + this->data->header.packetIdHAndVersion = + (this->data->header.packetIdHAndVersion & 0b11111000) | ((setAPID & 0x0700) >> 8); + this->data->header.packetIdL = (setAPID & 0x00FF); } void SpacePacketBase::setSequenceFlags(uint8_t sequenceflags) { - this->data->header.sequence_control_h &= 0x3F; - this->data->header.sequence_control_h |= sequenceflags << 6; -} - -uint16_t SpacePacketBase::getPacketSequenceControl(void) { - return ((this->data->header.sequence_control_h) << 8) + this->data->header.sequence_control_l; -} - -uint8_t SpacePacketBase::getSequenceFlags(void) { - return (this->data->header.sequence_control_h & 0b11000000) >> 6; -} - -uint16_t SpacePacketBase::getPacketSequenceCount(void) const { - return ((this->data->header.sequence_control_h & 0b00111111) << 8) + - this->data->header.sequence_control_l; + this->data->header.packetSeqCtrlH &= 0x3F; + this->data->header.packetSeqCtrlH |= sequenceflags << 6; } void SpacePacketBase::setPacketSequenceCount(uint16_t new_count) { - this->data->header.sequence_control_h = (this->data->header.sequence_control_h & 0b11000000) | - (((new_count % LIMIT_SEQUENCE_COUNT) & 0x3F00) >> 8); - this->data->header.sequence_control_l = ((new_count % LIMIT_SEQUENCE_COUNT) & 0x00FF); -} - -uint16_t SpacePacketBase::getPacketDataLength() const { - return ((this->data->header.packet_length_h) << 8) + this->data->header.packet_length_l; + this->data->header.packetSeqCtrlH = (this->data->header.packetSeqCtrlH & 0b11000000) | + (((new_count % ccsds::LIMIT_SEQUENCE_COUNT) & 0x3F00) >> 8); + this->data->header.packetSeqCtrlL = ((new_count % ccsds::LIMIT_SEQUENCE_COUNT) & 0x00FF); } void SpacePacketBase::setPacketDataLength(uint16_t new_length) { - this->data->header.packet_length_h = ((new_length & 0xFF00) >> 8); - this->data->header.packet_length_l = (new_length & 0x00FF); + this->data->header.packetLenH = ((new_length & 0xFF00) >> 8); + this->data->header.packetLenL = (new_length & 0x00FF); } size_t SpacePacketBase::getFullSize() { // +1 is done because size in packet data length field is: size of data field -1 - return this->getPacketDataLength() + sizeof(this->data->header) + 1; + return this->getPacketDataLen() + sizeof(this->data->header) + 1; } -uint8_t* SpacePacketBase::getWholeData() { return (uint8_t*)this->data; } - -uint32_t SpacePacketBase::getApidAndSequenceCount() const { - return (getAPID() << 16) + getPacketSequenceCount(); -} +uint8_t* SpacePacketBase::getWholeData() { return reinterpret_cast(this->data); } uint8_t* SpacePacketBase::getPacketData() { return &(data->packet_data); } @@ -116,3 +78,11 @@ ReturnValue_t SpacePacketBase::setData(uint8_t* pData, size_t maxSize, void* arg this->data = reinterpret_cast(const_cast(pData)); return HasReturnvaluesIF::RETURN_OK; } +uint16_t SpacePacketBase::getPacketSeqCtrl() const { + return ((this->data->header.packetSeqCtrlH & 0b00111111) << 8) + + this->data->header.packetSeqCtrlL; +} + +uint16_t SpacePacketBase::getPacketDataLen() const { + return ((this->data->header.packetLenH) << 8) + this->data->header.packetLenL; +} diff --git a/src/fsfw/tmtcpacket/SpacePacketBase.h b/src/fsfw/tmtcpacket/SpacePacketBase.h index d9ee2b83..862e4725 100644 --- a/src/fsfw/tmtcpacket/SpacePacketBase.h +++ b/src/fsfw/tmtcpacket/SpacePacketBase.h @@ -5,6 +5,7 @@ #include +#include "SpacePacketIF.h" #include "ccsds_header.h" #include "fsfw/returnvalues/HasReturnvaluesIF.h" @@ -39,7 +40,7 @@ struct SpacePacketPointer { * the most significant bit (from left). * @ingroup tmtcpackets */ -class SpacePacketBase : virtual public RedirectableDataPointerIF { +class SpacePacketBase : public SpacePacketIF, public RedirectableDataPointerIF { protected: /** * A pointer to a structure which defines the data structure of @@ -49,11 +50,6 @@ class SpacePacketBase : virtual public RedirectableDataPointerIF { SpacePacketPointer* data; public: - static const uint16_t LIMIT_APID = 2048; // 2^1 - static const uint16_t LIMIT_SEQUENCE_COUNT = 16384; // 2^14 - static const uint16_t APID_IDLE_PACKET = 0x7FF; - static const uint8_t TELECOMMAND_PACKET = 1; - static const uint8_t TELEMETRY_PACKET = 0; /** * This definition defines the CRC size in byte. */ @@ -67,53 +63,26 @@ class SpacePacketBase : virtual public RedirectableDataPointerIF { * It sets its internal data pointer to the address passed. * @param set_address The position where the packet data lies. */ - SpacePacketBase(const uint8_t* set_address); + explicit SpacePacketBase(const uint8_t* set_address); /** * No data is allocated, so the destructor is empty. */ - virtual ~SpacePacketBase(); - - // CCSDS Methods: - /** - * Getter for the packet version number field. - * @return Returns the highest three bit of the packet in one byte. - */ - uint8_t getPacketVersionNumber(void); - /** - * This method checks the type field in the header. - * This bit specifies, if the command is interpreted as Telecommand of - * as Telemetry. For a Telecommand, the bit is set. - * @return Returns true if the bit is set and false if not. - */ - bool isTelecommand(void); + ~SpacePacketBase() override; ReturnValue_t initSpacePacketHeader(bool isTelecommand, bool hasSecondaryHeader, uint16_t apid, uint16_t sequenceCount = 0); - /** - * The CCSDS header provides a secondary header flag (the fifth-highest bit), - * which is checked with this method. - * @return Returns true if the bit is set and false if not. - */ - bool hasSecondaryHeader(void); - /** - * Returns the complete first two bytes of the packet, which together form - * the CCSDS packet id. - * @return The CCSDS packet id. - */ - uint16_t getPacketId(void); - /** - * Returns the APID of a packet, which are the lowest 11 bit of the packet - * id. - * @return The CCSDS APID. - */ - uint16_t getAPID(void) const; + + [[nodiscard]] uint16_t getPacketId() const override; + [[nodiscard]] uint16_t getPacketSeqCtrl() const override; + [[nodiscard]] uint16_t getPacketDataLen() const override; + /** * Sets the APID of a packet, which are the lowest 11 bit of the packet * id. * @param The APID to set. The highest five bits of the parameter are * ignored. */ - void setAPID(uint16_t setAPID); + void setApid(uint16_t setAPID); /** * Sets the sequence flags of a packet, which are bit 17 and 18 in the space packet header. @@ -121,24 +90,6 @@ class SpacePacketBase : virtual public RedirectableDataPointerIF { */ void setSequenceFlags(uint8_t sequenceflags); - /** - * Returns the CCSDS packet sequence control field, which are the third and - * the fourth byte of the CCSDS primary header. - * @return The CCSDS packet sequence control field. - */ - uint16_t getPacketSequenceControl(void); - /** - * Returns the SequenceFlags, which are the highest two bit of the packet - * sequence control field. - * @return The CCSDS sequence flags. - */ - uint8_t getSequenceFlags(void); - /** - * Returns the packet sequence count, which are the lowest 14 bit of the - * packet sequence control field. - * @return The CCSDS sequence count. - */ - uint16_t getPacketSequenceCount(void) const; /** * Sets the packet sequence count, which are the lowest 14 bit of the * packet sequence control field. @@ -146,15 +97,7 @@ class SpacePacketBase : virtual public RedirectableDataPointerIF { * @param setCount The value to set the count to. */ void setPacketSequenceCount(uint16_t setCount); - /** - * Returns the packet data length, which is the fifth and sixth byte of the - * CCSDS Primary Header. The packet data length is the size of every kind - * of data \b after the CCSDS Primary Header \b -1. - * @return - * The CCSDS packet data length. uint16_t is sufficient, - * because this is limit in CCSDS standard - */ - uint16_t getPacketDataLength(void) const; + /** * Sets the packet data length, which is the fifth and sixth byte of the * CCSDS Primary Header. @@ -170,7 +113,7 @@ class SpacePacketBase : virtual public RedirectableDataPointerIF { * 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(void); + virtual uint8_t* getWholeData(); uint8_t* getPacketData(); @@ -179,14 +122,12 @@ class SpacePacketBase : virtual public RedirectableDataPointerIF { * location. * @param p_Data A pointer to another raw Space Packet. */ - virtual ReturnValue_t setData(uint8_t* p_Data, size_t maxSize, void* args = nullptr) override; + ReturnValue_t setData(uint8_t* p_Data, size_t maxSize, void* args) override; /** * This method returns the full raw packet size. * @return The full size of the packet in bytes. */ size_t getFullSize(); - - uint32_t getApidAndSequenceCount() const; }; #endif /* FSFW_TMTCPACKET_SPACEPACKETBASE_H_ */ diff --git a/src/fsfw/tmtcpacket/SpacePacketIF.h b/src/fsfw/tmtcpacket/SpacePacketIF.h new file mode 100644 index 00000000..291ba8f9 --- /dev/null +++ b/src/fsfw/tmtcpacket/SpacePacketIF.h @@ -0,0 +1,91 @@ +#ifndef FSFW_TMTCPACKET_SPACEPACKETIF_H +#define FSFW_TMTCPACKET_SPACEPACKETIF_H + +#include + +namespace ccsds { + +enum PacketType : uint8_t { TM = 0, TC = 1 }; + +enum SequenceFlags : uint8_t { + CONTINUATION = 0b00, + FIRST_SEGMENT = 0b01, + LAST_SEGMENT = 0b10, + UNSEGMENTED = 0b11 +}; + +static const uint16_t LIMIT_APID = 2048; // 2^11 +static const uint16_t LIMIT_SEQUENCE_COUNT = 16384; // 2^14 +static const uint16_t APID_IDLE_PACKET = 0x7FF; + +constexpr uint16_t getSpacePacketIdFromApid(bool isTc, uint16_t apid, + bool secondaryHeaderFlag = true) { + return ((isTc << 4) | (secondaryHeaderFlag << 3) | ((apid >> 8) & 0x07)) << 8 | (apid & 0x00ff); +} + +constexpr uint16_t getTcSpacePacketIdFromApid(uint16_t apid, bool secondaryHeaderFlag = true) { + return getSpacePacketIdFromApid(true, apid, secondaryHeaderFlag); +} + +constexpr uint16_t getTmSpacePacketIdFromApid(uint16_t apid, bool secondaryHeaderFlag = true) { + return getSpacePacketIdFromApid(false, apid, secondaryHeaderFlag); +} + +} // namespace ccsds + +class SpacePacketIF { + public: + virtual ~SpacePacketIF() = default; + + /** + * Returns the complete first two bytes of the packet, which together form + * the CCSDS packet ID + * @return The CCSDS packet ID + */ + [[nodiscard]] virtual uint16_t getPacketId() const = 0; + /** + * Returns the third and the fourth byte of the CCSDS header which are the packet sequence + * control field + * @return + */ + [[nodiscard]] virtual uint16_t getPacketSeqCtrl() const = 0; + /** + * Returns the fifth and the sixth byte of the CCSDS header which is the packet length field + * @return + */ + [[nodiscard]] virtual uint16_t getPacketDataLen() const = 0; + + [[nodiscard]] virtual uint16_t getApid() const { + uint16_t packetId = getPacketId(); + // Uppermost 11 bits of packet ID + return ((packetId >> 8) & 0b111) | (packetId & 0xFF); + } + + [[nodiscard]] virtual uint8_t getVersion() const { + uint16_t packetId = getPacketId(); + return (packetId >> 13) & 0b111; + } + + [[nodiscard]] virtual ccsds::PacketType getPacketType() const { + return static_cast((getPacketId() >> 12) & 0b1); + } + + [[nodiscard]] virtual bool isTc() const { return getPacketType() == ccsds::PacketType::TC; } + + [[nodiscard]] virtual bool isTm() const { return not isTc(); } + + /** + * The CCSDS header provides a secondary header flag (the fifth-highest bit), + * which is checked with this method. + * @return Returns true if the bit is set and false if not. + */ + [[nodiscard]] virtual bool hasSecHeader() const { return (getPacketId() >> 11) & 0b1; } + + [[nodiscard]] virtual ccsds::SequenceFlags getSequenceFlags() const { + return static_cast(getPacketSeqCtrl() >> 14 & 0b11); + } + + [[nodiscard]] virtual uint16_t getSequenceCount() const { return getPacketSeqCtrl() & 0x3FFF; } +}; + +#endif // FSFW_TMTCPACKET_SPACEPACKETIF_H diff --git a/src/fsfw/tmtcpacket/ccsds_header.h b/src/fsfw/tmtcpacket/ccsds_header.h index 232790c0..c0db194e 100644 --- a/src/fsfw/tmtcpacket/ccsds_header.h +++ b/src/fsfw/tmtcpacket/ccsds_header.h @@ -1,15 +1,15 @@ #ifndef CCSDS_HEADER_H_ #define CCSDS_HEADER_H_ -#include +#include struct CCSDSPrimaryHeader { - uint8_t packet_id_h; - uint8_t packet_id_l; - uint8_t sequence_control_h; - uint8_t sequence_control_l; - uint8_t packet_length_h; - uint8_t packet_length_l; + uint8_t packetIdHAndVersion; + uint8_t packetIdL; + uint8_t packetSeqCtrlH; + uint8_t packetSeqCtrlL; + uint8_t packetLenH; + uint8_t packetLenL; }; #endif /* CCSDS_HEADER_H_ */ diff --git a/src/fsfw/tmtcpacket/cfdp/CFDPPacketStored.cpp b/src/fsfw/tmtcpacket/cfdp/CFDPPacketStored.cpp index 9a410b40..260331ac 100644 --- a/src/fsfw/tmtcpacket/cfdp/CFDPPacketStored.cpp +++ b/src/fsfw/tmtcpacket/cfdp/CFDPPacketStored.cpp @@ -2,8 +2,6 @@ #include "fsfw/objectmanager/ObjectManager.h" -StorageManagerIF* CFDPPacketStored::store = nullptr; - CFDPPacketStored::CFDPPacketStored() : CFDPPacket(nullptr) {} CFDPPacketStored::CFDPPacketStored(store_address_t setAddress) : CFDPPacket(nullptr) { @@ -15,22 +13,22 @@ CFDPPacketStored::CFDPPacketStored(const uint8_t* data, size_t size) : CFDPPacke return; } if (this->checkAndSetStore()) { - ReturnValue_t status = store->addData(&storeAddress, data, size); + ReturnValue_t status = STORE->addData(&storeAddress, data, size); if (status != HasReturnvaluesIF::RETURN_OK) { - this->setData(nullptr, -1); + this->setData(nullptr, -1, 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); + STORE->getData(storeAddress, &storePtr, &size); + this->setData(const_cast(storePtr), size, nullptr); } } ReturnValue_t CFDPPacketStored::deletePacket() { - ReturnValue_t result = this->store->deleteData(this->storeAddress); + ReturnValue_t result = STORE->deleteData(this->storeAddress); this->storeAddress.raw = StorageManagerIF::INVALID_ADDRESS; // To circumvent size checks - this->setData(nullptr, -1); + this->setData(nullptr, -1, nullptr); return result; } @@ -43,20 +41,20 @@ void CFDPPacketStored::setStoreAddress(store_address_t setAddress) { size_t tempSize; ReturnValue_t status = StorageManagerIF::RETURN_FAILED; if (this->checkAndSetStore()) { - status = this->store->getData(this->storeAddress, &tempData, &tempSize); + status = STORE->getData(this->storeAddress, &tempData, &tempSize); } if (status == StorageManagerIF::RETURN_OK) { - this->setData(const_cast(tempData), tempSize); + this->setData(const_cast(tempData), tempSize, nullptr); } else { // To circumvent size checks - this->setData(nullptr, -1); + this->setData(nullptr, -1, nullptr); this->storeAddress.raw = StorageManagerIF::INVALID_ADDRESS; } } store_address_t CFDPPacketStored::getStoreAddress() { return this->storeAddress; } -CFDPPacketStored::~CFDPPacketStored() {} +CFDPPacketStored::~CFDPPacketStored() = default; ReturnValue_t CFDPPacketStored::getData(const uint8_t** dataPtr, size_t* dataSize) { return HasReturnvaluesIF::RETURN_OK; @@ -67,9 +65,9 @@ ReturnValue_t CFDPPacketStored::getData(const uint8_t** dataPtr, size_t* dataSiz // } bool CFDPPacketStored::checkAndSetStore() { - if (this->store == nullptr) { - this->store = ObjectManager::instance()->get(objects::TC_STORE); - if (this->store == nullptr) { + if (STORE == nullptr) { + STORE = ObjectManager::instance()->get(objects::TC_STORE); + if (STORE == nullptr) { #if FSFW_CPP_OSTREAM_ENABLED == 1 sif::error << "CFDPPacketStored::CFDPPacketStored: TC Store not found!" << std::endl; #endif @@ -82,7 +80,7 @@ bool CFDPPacketStored::checkAndSetStore() { bool CFDPPacketStored::isSizeCorrect() { const uint8_t* temp_data = nullptr; size_t temp_size; - ReturnValue_t status = this->store->getData(this->storeAddress, &temp_data, &temp_size); + ReturnValue_t status = STORE->getData(this->storeAddress, &temp_data, &temp_size); if (status == StorageManagerIF::RETURN_OK) { if (this->getFullSize() == temp_size) { return true; diff --git a/src/fsfw/tmtcpacket/cfdp/CFDPPacketStored.h b/src/fsfw/tmtcpacket/cfdp/CFDPPacketStored.h index f9c73bdd..688067f9 100644 --- a/src/fsfw/tmtcpacket/cfdp/CFDPPacketStored.h +++ b/src/fsfw/tmtcpacket/cfdp/CFDPPacketStored.h @@ -39,13 +39,6 @@ class CFDPPacketStored : public CFDPPacket, public TcPacketStoredBase { bool isSizeCorrect(); protected: - /** - * This is a pointer to the store all instances of the class use. - * If the store is not yet set (i.e. @c store is NULL), every constructor - * call tries to set it and throws an error message in case of failures. - * The default store is objects::TC_STORE. - */ - static StorageManagerIF* store; /** * The address where the packet data of the object instance is stored. */ diff --git a/src/fsfw/tmtcpacket/packetmatcher/ApidMatcher.h b/src/fsfw/tmtcpacket/packetmatcher/ApidMatcher.h index cf4c88f2..3c835ef8 100644 --- a/src/fsfw/tmtcpacket/packetmatcher/ApidMatcher.h +++ b/src/fsfw/tmtcpacket/packetmatcher/ApidMatcher.h @@ -10,23 +10,26 @@ class ApidMatcher : public SerializeableMatcherIF { uint16_t apid; public: - ApidMatcher(uint16_t setApid) : apid(setApid) {} - ApidMatcher(TmPacketMinimal* test) : apid(test->getAPID()) {} - bool match(TmPacketMinimal* packet) { - if (packet->getAPID() == apid) { + explicit ApidMatcher(uint16_t setApid) : apid(setApid) {} + explicit ApidMatcher(TmPacketMinimal* test) : apid(test->getApid()) {} + bool match(TmPacketMinimal* packet) override { + if (packet->getApid() == apid) { return true; } else { return false; } } ReturnValue_t serialize(uint8_t** buffer, size_t* size, size_t maxSize, - Endianness streamEndianness) const { + Endianness streamEndianness) const override { return SerializeAdapter::serialize(&apid, buffer, size, maxSize, streamEndianness); } - size_t getSerializedSize() const { return SerializeAdapter::getSerializedSize(&apid); } - ReturnValue_t deSerialize(const uint8_t** buffer, size_t* size, Endianness streamEndianness) { + [[nodiscard]] size_t getSerializedSize() const override { + return SerializeAdapter::getSerializedSize(&apid); + } + ReturnValue_t deSerialize(const uint8_t** buffer, size_t* size, + Endianness streamEndianness) override { return SerializeAdapter::deSerialize(&apid, buffer, size, streamEndianness); } }; -#endif /* FRAMEWORK_TMTCPACKET_PACKETMATCHER_APIDMATCHER_H_ */ +#endif /* FSFW_TMTCPACKET_PACKETMATCHER_APIDMATCHER_H_ */ diff --git a/src/fsfw/tmtcpacket/packetmatcher/PacketMatchTree.cpp b/src/fsfw/tmtcpacket/packetmatcher/PacketMatchTree.cpp index 6b900030..55fd3227 100644 --- a/src/fsfw/tmtcpacket/packetmatcher/PacketMatchTree.cpp +++ b/src/fsfw/tmtcpacket/packetmatcher/PacketMatchTree.cpp @@ -34,7 +34,7 @@ ReturnValue_t PacketMatchTree::addMatch(uint16_t apid, uint8_t type, uint8_t sub data.data_field.service_type = type; data.data_field.service_subtype = subtype; TmPacketMinimal testPacket((uint8_t*)&data); - testPacket.setAPID(apid); + testPacket.setApid(apid); iterator lastTest; iterator rollback; ReturnValue_t result = @@ -126,7 +126,7 @@ ReturnValue_t PacketMatchTree::removeMatch(uint16_t apid, uint8_t type, uint8_t data.data_field.service_type = type; data.data_field.service_subtype = subtype; TmPacketMinimal testPacket((uint8_t*)&data); - testPacket.setAPID(apid); + testPacket.setApid(apid); iterator foundElement = findMatch(begin(), &testPacket); if (foundElement == this->end()) { return NO_MATCH; diff --git a/src/fsfw/tmtcpacket/pus/tc/TcPacketPus.cpp b/src/fsfw/tmtcpacket/pus/tc/TcPacketPus.cpp index f5ebe38c..c9f10b4b 100644 --- a/src/fsfw/tmtcpacket/pus/tc/TcPacketPus.cpp +++ b/src/fsfw/tmtcpacket/pus/tc/TcPacketPus.cpp @@ -37,7 +37,7 @@ uint8_t TcPacketPus::getAcknowledgeFlags() const { const uint8_t *TcPacketPus::getApplicationData() const { return &tcData->appData; } uint16_t TcPacketPus::getApplicationDataSize() const { - return getPacketDataLength() - sizeof(tcData->dataField) - CRC_SIZE + 1; + return SpacePacketBase::getPacketDataLen() - sizeof(tcData->dataField) - CRC_SIZE + 1; } uint16_t TcPacketPus::getErrorControl() const { @@ -85,7 +85,7 @@ size_t TcPacketPus::calculateFullPacketLength(size_t appDataLen) const { } ReturnValue_t TcPacketPus::setData(uint8_t *dataPtr, size_t maxSize, void *args) { - ReturnValue_t result = SpacePacketBase::setData(dataPtr, maxSize); + ReturnValue_t result = SpacePacketBase::setData(dataPtr, maxSize, args); if (result != HasReturnvaluesIF::RETURN_OK) { return result; } diff --git a/src/fsfw/tmtcpacket/pus/tc/TcPacketPus.h b/src/fsfw/tmtcpacket/pus/tc/TcPacketPus.h index 47173dad..b630cfee 100644 --- a/src/fsfw/tmtcpacket/pus/tc/TcPacketPus.h +++ b/src/fsfw/tmtcpacket/pus/tc/TcPacketPus.h @@ -63,7 +63,7 @@ class TcPacketPus : public TcPacketPusBase { size_t calculateFullPacketLength(size_t appDataLen) const override; protected: - ReturnValue_t setData(uint8_t* dataPtr, size_t maxSize, void* args = nullptr) override; + ReturnValue_t setData(uint8_t* dataPtr, size_t maxSize, void* args) override; /** * Initializes the Tc Packet header. diff --git a/src/fsfw/tmtcpacket/pus/tc/TcPacketPusBase.h b/src/fsfw/tmtcpacket/pus/tc/TcPacketPusBase.h index 9f1d07ed..c84fc67d 100644 --- a/src/fsfw/tmtcpacket/pus/tc/TcPacketPusBase.h +++ b/src/fsfw/tmtcpacket/pus/tc/TcPacketPusBase.h @@ -18,7 +18,7 @@ * check can be performed by making use of the getWholeData method. * @ingroup tmtcpackets */ -class TcPacketPusBase : public SpacePacketBase, virtual public RedirectableDataPointerIF { +class TcPacketPusBase : public SpacePacketBase { friend class TcPacketStoredBase; public: diff --git a/src/fsfw/tmtcpacket/pus/tc/TcPacketStoredPus.cpp b/src/fsfw/tmtcpacket/pus/tc/TcPacketStoredPus.cpp index 643c2ecc..95350ac2 100644 --- a/src/fsfw/tmtcpacket/pus/tc/TcPacketStoredPus.cpp +++ b/src/fsfw/tmtcpacket/pus/tc/TcPacketStoredPus.cpp @@ -21,7 +21,7 @@ TcPacketStoredPus::TcPacketStoredPus(uint16_t apid, uint8_t service, uint8_t sub #endif return; } - this->setData(pData, TC_PACKET_MIN_SIZE + size); + 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 @@ -46,12 +46,12 @@ TcPacketStoredPus::TcPacketStoredPus(const uint8_t* data, size_t size) : TcPacke if (this->checkAndSetStore()) { ReturnValue_t status = STORE->addData(&storeAddress, data, size); if (status != HasReturnvaluesIF::RETURN_OK) { - this->setData(nullptr, size); + 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); + this->setData(const_cast(storePtr), size, nullptr); } } @@ -59,7 +59,7 @@ 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); + this->setData(nullptr, -1, nullptr); return result; } diff --git a/src/fsfw/tmtcpacket/pus/tm/TmPacketBase.cpp b/src/fsfw/tmtcpacket/pus/tm/TmPacketBase.cpp index bc761d0d..e04f2b85 100644 --- a/src/fsfw/tmtcpacket/pus/tm/TmPacketBase.cpp +++ b/src/fsfw/tmtcpacket/pus/tm/TmPacketBase.cpp @@ -13,12 +13,10 @@ object_id_t TmPacketBase::timeStamperId = objects::NO_OBJECT; TmPacketBase::TmPacketBase(uint8_t* setData) : SpacePacketBase(setData) {} -TmPacketBase::~TmPacketBase() { - // Nothing to do. -} +TmPacketBase::~TmPacketBase() = default; uint16_t TmPacketBase::getSourceDataSize() { - return getPacketDataLength() - getDataFieldSize() - CRC_SIZE + 1; + return SpacePacketBase::getPacketDataLen() - getDataFieldSize() - CRC_SIZE + 1; } uint16_t TmPacketBase::getErrorControl() { @@ -41,9 +39,9 @@ ReturnValue_t TmPacketBase::getPacketTime(timeval* timestamp) const { } bool TmPacketBase::checkAndSetStamper() { - if (timeStamper == NULL) { + if (timeStamper == nullptr) { timeStamper = ObjectManager::instance()->get(timeStamperId); - if (timeStamper == NULL) { + if (timeStamper == nullptr) { #if FSFW_CPP_OSTREAM_ENABLED == 1 sif::warning << "TmPacketBase::checkAndSetStamper: Stamper not found!" << std::endl; #else diff --git a/src/fsfw/tmtcpacket/pus/tm/TmPacketPusA.cpp b/src/fsfw/tmtcpacket/pus/tm/TmPacketPusA.cpp index e8f71717..1a830004 100644 --- a/src/fsfw/tmtcpacket/pus/tm/TmPacketPusA.cpp +++ b/src/fsfw/tmtcpacket/pus/tm/TmPacketPusA.cpp @@ -25,11 +25,11 @@ uint8_t TmPacketPusA::getSubService() { return tmData->data_field.service_subtyp uint8_t* TmPacketPusA::getSourceData() { return &tmData->data; } uint16_t TmPacketPusA::getSourceDataSize() { - return getPacketDataLength() - sizeof(tmData->data_field) - CRC_SIZE + 1; + return SpacePacketBase::getPacketDataLen() - sizeof(tmData->data_field) - CRC_SIZE + 1; } ReturnValue_t TmPacketPusA::setData(uint8_t* p_Data, size_t maxSize, void* args) { - ReturnValue_t result = SpacePacketBase::setData(p_Data, maxSize); + ReturnValue_t result = SpacePacketBase::setData(p_Data, maxSize, args); if (result != HasReturnvaluesIF::RETURN_OK) { return result; } diff --git a/src/fsfw/tmtcpacket/pus/tm/TmPacketPusC.cpp b/src/fsfw/tmtcpacket/pus/tm/TmPacketPusC.cpp index ab690414..c402a577 100644 --- a/src/fsfw/tmtcpacket/pus/tm/TmPacketPusC.cpp +++ b/src/fsfw/tmtcpacket/pus/tm/TmPacketPusC.cpp @@ -14,9 +14,7 @@ TmPacketPusC::TmPacketPusC(uint8_t* setData) : TmPacketBase(setData) { tmData = reinterpret_cast(setData); } -TmPacketPusC::~TmPacketPusC() { - // Nothing to do. -} +TmPacketPusC::~TmPacketPusC() = default; uint8_t TmPacketPusC::getService() { return tmData->dataField.serviceType; } @@ -25,11 +23,11 @@ uint8_t TmPacketPusC::getSubService() { return tmData->dataField.serviceSubtype; uint8_t* TmPacketPusC::getSourceData() { return &tmData->data; } uint16_t TmPacketPusC::getSourceDataSize() { - return getPacketDataLength() - sizeof(tmData->dataField) - CRC_SIZE + 1; + return SpacePacketBase::getPacketDataLen() - sizeof(tmData->dataField) - CRC_SIZE + 1; } ReturnValue_t TmPacketPusC::setData(uint8_t* p_Data, size_t maxSize, void* args) { - ReturnValue_t result = SpacePacketBase::setData(p_Data, maxSize); + ReturnValue_t result = SpacePacketBase::setData(p_Data, maxSize, args); if (result != HasReturnvaluesIF::RETURN_OK) { return result; } @@ -64,9 +62,9 @@ ReturnValue_t TmPacketPusC::initializeTmPacket(uint16_t apid, uint8_t service, u (pus::PusVersion::PUS_C_VERSION << 4) | timeRefField; tmData->dataField.serviceType = service; tmData->dataField.serviceSubtype = subservice; - tmData->dataField.subcounterMsb = packetSubcounter << 8 & 0xff; + tmData->dataField.subcounterMsb = (packetSubcounter << 8) & 0xff; tmData->dataField.subcounterLsb = packetSubcounter & 0xff; - tmData->dataField.destinationIdMsb = destinationId << 8 & 0xff; + tmData->dataField.destinationIdMsb = (destinationId << 8) & 0xff; tmData->dataField.destinationIdLsb = destinationId & 0xff; // Timestamp packet if (TmPacketBase::checkAndSetStamper()) { diff --git a/src/fsfw/tmtcpacket/pus/tm/TmPacketPusC.h b/src/fsfw/tmtcpacket/pus/tm/TmPacketPusC.h index bbd69693..4b3ca18c 100644 --- a/src/fsfw/tmtcpacket/pus/tm/TmPacketPusC.h +++ b/src/fsfw/tmtcpacket/pus/tm/TmPacketPusC.h @@ -114,7 +114,7 @@ class TmPacketPusC : public TmPacketBase { * * @param pData A pointer to another PUS Telemetry Packet. */ - ReturnValue_t setData(uint8_t* pData, size_t maxSize, void* args = nullptr) override; + ReturnValue_t setData(uint8_t* pData, size_t maxSize, void* args) override; /** * In case data was filled manually (almost never the case). diff --git a/src/fsfw/tmtcpacket/pus/tm/TmPacketStoredPusC.cpp b/src/fsfw/tmtcpacket/pus/tm/TmPacketStoredPusC.cpp index 9c170aa3..5ade4191 100644 --- a/src/fsfw/tmtcpacket/pus/tm/TmPacketStoredPusC.cpp +++ b/src/fsfw/tmtcpacket/pus/tm/TmPacketStoredPusC.cpp @@ -26,7 +26,7 @@ TmPacketStoredPusC::TmPacketStoredPusC(uint16_t apid, uint8_t service, uint8_t s handleStoreFailure("C", returnValue, sizeToReserve); return; } - setData(pData, sizeToReserve); + setData(pData, sizeToReserve, nullptr); initializeTmPacket(apid, service, subservice, packetSubcounter, destinationId, timeRefField); memcpy(getSourceData(), headerData, headerSize); memcpy(getSourceData() + headerSize, data, size); @@ -56,7 +56,7 @@ TmPacketStoredPusC::TmPacketStoredPusC(uint16_t apid, uint8_t service, uint8_t s handleStoreFailure("C", returnValue, sizeToReserve); return; } - TmPacketPusC::setData(pData, sizeToReserve); + TmPacketPusC::setData(pData, sizeToReserve, nullptr); initializeTmPacket(apid, service, subservice, packetSubcounter, destinationId, timeRefField); uint8_t *putDataHere = getSourceData(); size_t size = 0; @@ -72,5 +72,5 @@ TmPacketStoredPusC::TmPacketStoredPusC(uint16_t apid, uint8_t service, uint8_t s uint8_t *TmPacketStoredPusC::getAllTmData() { return getWholeData(); } ReturnValue_t TmPacketStoredPusC::setData(uint8_t *newPointer, size_t maxSize, void *args) { - return TmPacketPusC::setData(newPointer, maxSize); + return TmPacketPusC::setData(newPointer, maxSize, args); } diff --git a/src/fsfw/tmtcpacket/pus/tm/TmPacketStoredPusC.h b/src/fsfw/tmtcpacket/pus/tm/TmPacketStoredPusC.h index ef84e238..fe65e2ca 100644 --- a/src/fsfw/tmtcpacket/pus/tm/TmPacketStoredPusC.h +++ b/src/fsfw/tmtcpacket/pus/tm/TmPacketStoredPusC.h @@ -66,7 +66,7 @@ class TmPacketStoredPusC : public TmPacketStoredBase, public TmPacketPusC { * @param args * @return */ - ReturnValue_t setData(uint8_t* newPointer, size_t maxSize, void* args = nullptr) override; + ReturnValue_t setData(uint8_t* newPointer, size_t maxSize, void* args) override; }; #endif /* FSFW_TMTCPACKET_PUS_TMPACKETSTOREDPUSC_H_ */ diff --git a/src/fsfw/tmtcservices/CommandingServiceBase.cpp b/src/fsfw/tmtcservices/CommandingServiceBase.cpp index bbdf8d2a..37232c49 100644 --- a/src/fsfw/tmtcservices/CommandingServiceBase.cpp +++ b/src/fsfw/tmtcservices/CommandingServiceBase.cpp @@ -350,7 +350,7 @@ void CommandingServiceBase::startExecution(TcPacketStoredPus* storedPacket, Comm iter->second.command = command.getCommand(); iter->second.tcInfo.ackFlags = storedPacket->getAcknowledgeFlags(); iter->second.tcInfo.tcPacketId = storedPacket->getPacketId(); - iter->second.tcInfo.tcSequenceControl = storedPacket->getPacketSequenceControl(); + iter->second.tcInfo.tcSequenceControl = storedPacket->getPacketSeqCtrl(); acceptPacket(tc_verification::START_SUCCESS, storedPacket); } else { command.clearCommandMessage(); diff --git a/src/fsfw/tmtcservices/VerificationReporter.cpp b/src/fsfw/tmtcservices/VerificationReporter.cpp index 9d06adc4..19277bf3 100644 --- a/src/fsfw/tmtcservices/VerificationReporter.cpp +++ b/src/fsfw/tmtcservices/VerificationReporter.cpp @@ -22,8 +22,8 @@ void VerificationReporter::sendSuccessReport(uint8_t set_report_id, TcPacketPusB return; } PusVerificationMessage message(set_report_id, currentPacket->getAcknowledgeFlags(), - currentPacket->getPacketId(), - currentPacket->getPacketSequenceControl(), 0, set_step); + currentPacket->getPacketId(), currentPacket->getPacketSeqCtrl(), 0, + set_step); ReturnValue_t status = MessageQueueSenderIF::sendMessage(acknowledgeQueue, &message); if (status != HasReturnvaluesIF::RETURN_OK) { #if FSFW_CPP_OSTREAM_ENABLED == 1 @@ -59,9 +59,9 @@ void VerificationReporter::sendFailureReport(uint8_t report_id, TcPacketPusBase* if (currentPacket == nullptr) { return; } - PusVerificationMessage message( - report_id, currentPacket->getAcknowledgeFlags(), currentPacket->getPacketId(), - currentPacket->getPacketSequenceControl(), error_code, step, parameter1, parameter2); + PusVerificationMessage message(report_id, currentPacket->getAcknowledgeFlags(), + currentPacket->getPacketId(), currentPacket->getPacketSeqCtrl(), + error_code, step, parameter1, parameter2); ReturnValue_t status = MessageQueueSenderIF::sendMessage(acknowledgeQueue, &message); if (status != HasReturnvaluesIF::RETURN_OK) { #if FSFW_CPP_OSTREAM_ENABLED == 1 diff --git a/tests/src/fsfw_tests/unit/tmtcpacket/testCcsds.cpp b/tests/src/fsfw_tests/unit/tmtcpacket/testCcsds.cpp index d395449d..76140c26 100644 --- a/tests/src/fsfw_tests/unit/tmtcpacket/testCcsds.cpp +++ b/tests/src/fsfw_tests/unit/tmtcpacket/testCcsds.cpp @@ -1,11 +1,11 @@ #include -#include "fsfw/tmtcpacket/SpacePacket.h" +#include "fsfw/tmtcpacket/SpacePacketBase.h" TEST_CASE("CCSDS Test", "[ccsds]") { - REQUIRE(spacepacket::getTcSpacePacketIdFromApid(0x22) == 0x1822); - REQUIRE(spacepacket::getTmSpacePacketIdFromApid(0x22) == 0x0822); + REQUIRE(ccsds::getTcSpacePacketIdFromApid(0x22) == 0x1822); + REQUIRE(ccsds::getTmSpacePacketIdFromApid(0x22) == 0x0822); - REQUIRE(spacepacket::getTcSpacePacketIdFromApid(0x7ff) == 0x1fff); - REQUIRE(spacepacket::getTmSpacePacketIdFromApid(0x7ff) == 0xfff); + REQUIRE(ccsds::getTcSpacePacketIdFromApid(0x7ff) == 0x1fff); + REQUIRE(ccsds::getTmSpacePacketIdFromApid(0x7ff) == 0xfff); } -- 2.43.0 From 546e173cef61917714258a14e4eb801be26c7ab5 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Mon, 18 Jul 2022 10:29:39 +0200 Subject: [PATCH 002/108] add new PUS TC IF --- CMakeLists.txt | 2 +- src/fsfw/tmtcpacket/pus/tc/PusTcIF.h | 79 +++++++++++++++++++ .../pus/tc/TcPacketDeserializer.cpp | 3 + .../tmtcpacket/pus/tc/TcPacketDeserializer.h | 14 ++++ .../tmtcpacket/pus/tc/TcPacketStoredBase.h | 2 +- 5 files changed, 98 insertions(+), 2 deletions(-) create mode 100644 src/fsfw/tmtcpacket/pus/tc/PusTcIF.h create mode 100644 src/fsfw/tmtcpacket/pus/tc/TcPacketDeserializer.cpp create mode 100644 src/fsfw/tmtcpacket/pus/tc/TcPacketDeserializer.h diff --git a/CMakeLists.txt b/CMakeLists.txt index 440d7f9b..1a8b703d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -133,7 +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) +add_library(${LIB_FSFW_NAME} src/fsfw/tmtcpacket/SpacePacketIF.h src/fsfw/tmtcpacket/pus/tc/TcPacketDeserializer.h src/fsfw/tmtcpacket/pus/tc/TcPacketDeserializer.cpp src/fsfw/tmtcpacket/pus/tc/PusTcIF.h) if(IPO_SUPPORTED AND FSFW_ENABLE_IPO) set_property(TARGET ${LIB_FSFW_NAME} PROPERTY INTERPROCEDURAL_OPTIMIZATION diff --git a/src/fsfw/tmtcpacket/pus/tc/PusTcIF.h b/src/fsfw/tmtcpacket/pus/tc/PusTcIF.h new file mode 100644 index 00000000..91f8fe1e --- /dev/null +++ b/src/fsfw/tmtcpacket/pus/tc/PusTcIF.h @@ -0,0 +1,79 @@ +#ifndef FSFW_TMTCPACKET_PUSTCIF_H +#define FSFW_TMTCPACKET_PUSTCIF_H + +#include + +class PusTcIF { + public: + virtual ~PusTcIF() = default; + + /** + * This command returns the CCSDS Secondary Header Flag. + * It shall always be zero for PUS Packets. This is the + * highest bit of the first byte of the Data Field Header. + * @return the CCSDS Secondary Header Flag + */ + [[nodiscard]] virtual uint8_t getSecondaryHeaderFlag() const = 0; + /** + * 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. + * + * It is packed in a uint8_t variable. + * @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/TcPacketDeserializer.cpp b/src/fsfw/tmtcpacket/pus/tc/TcPacketDeserializer.cpp new file mode 100644 index 00000000..a93db348 --- /dev/null +++ b/src/fsfw/tmtcpacket/pus/tc/TcPacketDeserializer.cpp @@ -0,0 +1,3 @@ +#include "TcPacketDeserializer.h" + +TcPacketDeserializer::TcPacketDeserializer(const uint8_t *data, size_t maxSize) {} diff --git a/src/fsfw/tmtcpacket/pus/tc/TcPacketDeserializer.h b/src/fsfw/tmtcpacket/pus/tc/TcPacketDeserializer.h new file mode 100644 index 00000000..b3b35084 --- /dev/null +++ b/src/fsfw/tmtcpacket/pus/tc/TcPacketDeserializer.h @@ -0,0 +1,14 @@ +#ifndef FSFW_TMTCPACKET_TCPACKETDESERIALIZER_H +#define FSFW_TMTCPACKET_TCPACKETDESERIALIZER_H + +#include "fsfw/tmtcpacket/RedirectableDataPointerIF.h" +#include "fsfw/tmtcpacket/SpacePacketIF.h" + +class TcPacketDeserializer: public SpacePacketIF, public RedirectableDataPointerIF { + public: + TcPacketDeserializer(const uint8_t* data, size_t maxSize); + private: + +}; + +#endif // FSFW_TMTCPACKET_TCPACKETDESERIALIZER_H diff --git a/src/fsfw/tmtcpacket/pus/tc/TcPacketStoredBase.h b/src/fsfw/tmtcpacket/pus/tc/TcPacketStoredBase.h index ece0e482..4d27565a 100644 --- a/src/fsfw/tmtcpacket/pus/tc/TcPacketStoredBase.h +++ b/src/fsfw/tmtcpacket/pus/tc/TcPacketStoredBase.h @@ -19,7 +19,7 @@ class TcPacketStoredBase : public TcPacketStoredIF { * Constructor to set to an existing store address. * @param setAddress */ - TcPacketStoredBase(store_address_t 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. -- 2.43.0 From d7a2eada945a3d1b77d71153d88d15ca1ce1bff3 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Mon, 18 Jul 2022 10:42:56 +0200 Subject: [PATCH 003/108] add space packet creator class --- CMakeLists.txt | 9 ++- .../datalinklayer/MapPacketExtraction.cpp | 2 +- src/fsfw/tcdistribution/CCSDSDistributor.cpp | 4 +- src/fsfw/tcdistribution/TcPacketCheckCFDP.cpp | 2 +- src/fsfw/tcdistribution/TcPacketCheckCFDP.h | 2 +- src/fsfw/tcdistribution/TcPacketCheckIF.h | 4 +- src/fsfw/tcdistribution/TcPacketCheckPUS.cpp | 2 +- src/fsfw/tcdistribution/TcPacketCheckPUS.h | 2 +- src/fsfw/tmtcpacket/CMakeLists.txt | 2 +- src/fsfw/tmtcpacket/SpacePacketCreator.cpp | 36 +++++++++++ src/fsfw/tmtcpacket/SpacePacketCreator.h | 26 ++++++++ ...cePacketBase.cpp => SpacePacketReader.cpp} | 32 +++++----- ...{SpacePacketBase.h => SpacePacketReader.h} | 8 ++- src/fsfw/tmtcpacket/cfdp/CFDPPacket.cpp | 2 +- src/fsfw/tmtcpacket/cfdp/CFDPPacket.h | 4 +- src/fsfw/tmtcpacket/pus/tc/PusTcIF.h | 60 +++++++++---------- .../tmtcpacket/pus/tc/TcPacketDeserializer.h | 4 +- src/fsfw/tmtcpacket/pus/tc/TcPacketPus.cpp | 4 +- .../tmtcpacket/pus/tc/TcPacketPusBase.cpp | 2 +- src/fsfw/tmtcpacket/pus/tc/TcPacketPusBase.h | 4 +- src/fsfw/tmtcpacket/pus/tm/TmPacketBase.cpp | 4 +- src/fsfw/tmtcpacket/pus/tm/TmPacketBase.h | 4 +- .../tmtcpacket/pus/tm/TmPacketMinimal.cpp | 2 +- src/fsfw/tmtcpacket/pus/tm/TmPacketMinimal.h | 4 +- src/fsfw/tmtcpacket/pus/tm/TmPacketPusA.cpp | 4 +- src/fsfw/tmtcpacket/pus/tm/TmPacketPusA.h | 2 +- src/fsfw/tmtcpacket/pus/tm/TmPacketPusC.cpp | 4 +- src/fsfw/tmtcpacket/pus/tm/TmPacketPusC.h | 2 +- src/fsfw/tmtcservices/SourceSequenceCounter.h | 2 +- .../fsfw_tests/unit/tmtcpacket/testCcsds.cpp | 14 +++-- 30 files changed, 164 insertions(+), 89 deletions(-) create mode 100644 src/fsfw/tmtcpacket/SpacePacketCreator.cpp create mode 100644 src/fsfw/tmtcpacket/SpacePacketCreator.h rename src/fsfw/tmtcpacket/{SpacePacketBase.cpp => SpacePacketReader.cpp} (69%) rename src/fsfw/tmtcpacket/{SpacePacketBase.h => SpacePacketReader.h} (93%) diff --git a/CMakeLists.txt b/CMakeLists.txt index 1a8b703d..066f1028 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -133,7 +133,14 @@ 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/TcPacketDeserializer.h src/fsfw/tmtcpacket/pus/tc/TcPacketDeserializer.cpp src/fsfw/tmtcpacket/pus/tc/PusTcIF.h) +add_library( + ${LIB_FSFW_NAME} + src/fsfw/tmtcpacket/SpacePacketIF.h + src/fsfw/tmtcpacket/pus/tc/TcPacketDeserializer.h + src/fsfw/tmtcpacket/pus/tc/TcPacketDeserializer.cpp + src/fsfw/tmtcpacket/pus/tc/PusTcIF.h + src/fsfw/tmtcpacket/SpacePacketCreator.h + src/fsfw/tmtcpacket/SpacePacketCreator.cpp) if(IPO_SUPPORTED AND FSFW_ENABLE_IPO) set_property(TARGET ${LIB_FSFW_NAME} PROPERTY INTERPROCEDURAL_OPTIMIZATION diff --git a/src/fsfw/datalinklayer/MapPacketExtraction.cpp b/src/fsfw/datalinklayer/MapPacketExtraction.cpp index 57aa2f08..1467f2aa 100644 --- a/src/fsfw/datalinklayer/MapPacketExtraction.cpp +++ b/src/fsfw/datalinklayer/MapPacketExtraction.cpp @@ -6,7 +6,7 @@ #include "fsfw/objectmanager/ObjectManager.h" #include "fsfw/serviceinterface/ServiceInterface.h" #include "fsfw/storagemanager/StorageManagerIF.h" -#include "fsfw/tmtcpacket/SpacePacketBase.h" +#include "fsfw/tmtcpacket/SpacePacketReader.h" #include "fsfw/tmtcservices/AcceptsTelecommandsIF.h" #include "fsfw/tmtcservices/TmTcMessage.h" diff --git a/src/fsfw/tcdistribution/CCSDSDistributor.cpp b/src/fsfw/tcdistribution/CCSDSDistributor.cpp index 0be177bf..a32cbc75 100644 --- a/src/fsfw/tcdistribution/CCSDSDistributor.cpp +++ b/src/fsfw/tcdistribution/CCSDSDistributor.cpp @@ -2,7 +2,7 @@ #include "fsfw/objectmanager/ObjectManager.h" #include "fsfw/serviceinterface/ServiceInterface.h" -#include "fsfw/tmtcpacket/SpacePacketBase.h" +#include "fsfw/tmtcpacket/SpacePacketReader.h" #define CCSDS_DISTRIBUTOR_DEBUGGING 0 @@ -40,7 +40,7 @@ TcDistributor::TcMqMapIter CCSDSDistributor::selectDestination() { #endif return queueMap.end(); } - SpacePacketBase currentPacket(packet); + SpacePacketReader currentPacket(packet); #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/TcPacketCheckCFDP.cpp b/src/fsfw/tcdistribution/TcPacketCheckCFDP.cpp index d1eb43bc..7d2bfe88 100644 --- a/src/fsfw/tcdistribution/TcPacketCheckCFDP.cpp +++ b/src/fsfw/tcdistribution/TcPacketCheckCFDP.cpp @@ -4,6 +4,6 @@ TcPacketCheckCFDP::TcPacketCheckCFDP(uint16_t setApid) : apid(setApid) {} -ReturnValue_t TcPacketCheckCFDP::checkPacket(SpacePacketBase* currentPacket) { return RETURN_OK; } +ReturnValue_t TcPacketCheckCFDP::checkPacket(SpacePacketReader* currentPacket) { return RETURN_OK; } uint16_t TcPacketCheckCFDP::getApid() const { return apid; } diff --git a/src/fsfw/tcdistribution/TcPacketCheckCFDP.h b/src/fsfw/tcdistribution/TcPacketCheckCFDP.h index 3fe281d1..5a4abd4f 100644 --- a/src/fsfw/tcdistribution/TcPacketCheckCFDP.h +++ b/src/fsfw/tcdistribution/TcPacketCheckCFDP.h @@ -25,7 +25,7 @@ class TcPacketCheckCFDP : public TcPacketCheckIF, public HasReturnvaluesIF { */ TcPacketCheckCFDP(uint16_t setApid); - ReturnValue_t checkPacket(SpacePacketBase* currentPacket) override; + ReturnValue_t checkPacket(SpacePacketReader* currentPacket) override; uint16_t getApid() const; }; diff --git a/src/fsfw/tcdistribution/TcPacketCheckIF.h b/src/fsfw/tcdistribution/TcPacketCheckIF.h index 858c3093..a9ec14a2 100644 --- a/src/fsfw/tcdistribution/TcPacketCheckIF.h +++ b/src/fsfw/tcdistribution/TcPacketCheckIF.h @@ -3,7 +3,7 @@ #include "../returnvalues/HasReturnvaluesIF.h" -class SpacePacketBase; +class SpacePacketReader; /** * This interface is used by PacketCheckers for PUS packets and CFDP packets . @@ -24,7 +24,7 @@ class TcPacketCheckIF { * - @c INCORRECT_CHECKSUM if checksum is invalid. * - @c ILLEGAL_APID if APID does not match. */ - virtual ReturnValue_t checkPacket(SpacePacketBase* currentPacket) = 0; + virtual ReturnValue_t checkPacket(SpacePacketReader* currentPacket) = 0; }; #endif /* FSFW_TCDISTRIBUTION_TCPACKETCHECKIF_H_ */ diff --git a/src/fsfw/tcdistribution/TcPacketCheckPUS.cpp b/src/fsfw/tcdistribution/TcPacketCheckPUS.cpp index 6d7092e5..304c644a 100644 --- a/src/fsfw/tcdistribution/TcPacketCheckPUS.cpp +++ b/src/fsfw/tcdistribution/TcPacketCheckPUS.cpp @@ -10,7 +10,7 @@ TcPacketCheckPUS::TcPacketCheckPUS(uint16_t setApid) : apid(setApid) {} -ReturnValue_t TcPacketCheckPUS::checkPacket(SpacePacketBase* currentPacket) { +ReturnValue_t TcPacketCheckPUS::checkPacket(SpacePacketReader* currentPacket) { auto* storedPacket = dynamic_cast(currentPacket); auto* tcPacketBase = dynamic_cast(currentPacket); if (tcPacketBase == nullptr or storedPacket == nullptr) { diff --git a/src/fsfw/tcdistribution/TcPacketCheckPUS.h b/src/fsfw/tcdistribution/TcPacketCheckPUS.h index e3eca1a4..4804a619 100644 --- a/src/fsfw/tcdistribution/TcPacketCheckPUS.h +++ b/src/fsfw/tcdistribution/TcPacketCheckPUS.h @@ -53,7 +53,7 @@ class TcPacketCheckPUS : public TcPacketCheckIF, public HasReturnvaluesIF { */ TcPacketCheckPUS(uint16_t setApid); - ReturnValue_t checkPacket(SpacePacketBase* currentPacket) override; + ReturnValue_t checkPacket(SpacePacketReader* currentPacket) override; uint16_t getApid() const; }; diff --git a/src/fsfw/tmtcpacket/CMakeLists.txt b/src/fsfw/tmtcpacket/CMakeLists.txt index dc09c9c9..85376d01 100644 --- a/src/fsfw/tmtcpacket/CMakeLists.txt +++ b/src/fsfw/tmtcpacket/CMakeLists.txt @@ -1,4 +1,4 @@ -target_sources(${LIB_FSFW_NAME} PRIVATE SpacePacketBase.cpp) +target_sources(${LIB_FSFW_NAME} PRIVATE SpacePacketReader.cpp) add_subdirectory(cfdp) add_subdirectory(packetmatcher) diff --git a/src/fsfw/tmtcpacket/SpacePacketCreator.cpp b/src/fsfw/tmtcpacket/SpacePacketCreator.cpp new file mode 100644 index 00000000..d5eb73c2 --- /dev/null +++ b/src/fsfw/tmtcpacket/SpacePacketCreator.cpp @@ -0,0 +1,36 @@ +#include "SpacePacketCreator.h" + +#include "fsfw/serialize/SerializeAdapter.h" + +SpacePacketCreator::SpacePacketCreator(uint16_t packetId_, uint16_t packetSeqCtrl_, + uint16_t packetLen_, uint8_t version_) { + packetId = packetId_; + packetSeqCtrl = packetSeqCtrl_; + packetLen = packetLen_; + version = version_; +} + +uint16_t SpacePacketCreator::getPacketId() const { return 0; } +uint16_t SpacePacketCreator::getPacketSeqCtrl() const { return 0; } +uint16_t SpacePacketCreator::getPacketDataLen() const { return 0; } + +ReturnValue_t SpacePacketCreator::serialize(uint8_t **buffer, size_t *size, size_t maxSize, + SerializeIF::Endianness streamEndianness) const { + uint16_t packetIdAndVersion = version << 13 | packetId; + ReturnValue_t result = + SerializeAdapter::serialize(&packetIdAndVersion, buffer, size, maxSize, streamEndianness); + if (result != HasReturnvaluesIF::RETURN_OK) { + return result; + } + result = SerializeAdapter::serialize(&packetSeqCtrl, buffer, size, maxSize, streamEndianness); + if (result != HasReturnvaluesIF::RETURN_OK) { + return result; + } + return SerializeAdapter::serialize(&packetLen, buffer, size, maxSize, streamEndianness); +} + +size_t SpacePacketCreator::getSerializedSize() const { return 0; } +ReturnValue_t SpacePacketCreator::deSerialize(const uint8_t **buffer, size_t *size, + SerializeIF::Endianness streamEndianness) { + return HasReturnvaluesIF::RETURN_FAILED; +} diff --git a/src/fsfw/tmtcpacket/SpacePacketCreator.h b/src/fsfw/tmtcpacket/SpacePacketCreator.h new file mode 100644 index 00000000..2e7d2537 --- /dev/null +++ b/src/fsfw/tmtcpacket/SpacePacketCreator.h @@ -0,0 +1,26 @@ +#ifndef FSFW_TMTCPACKET_SPACEPACKETCREATOR_H +#define FSFW_TMTCPACKET_SPACEPACKETCREATOR_H + +#include "SpacePacketIF.h" +#include "fsfw/serialize/SerializeIF.h" + +class SpacePacketCreator : public SerializeIF, public SpacePacketIF { + public: + SpacePacketCreator(uint16_t packetId, uint16_t packetSeqCtrl, uint16_t packetLen, + uint8_t version = 0); + [[nodiscard]] uint16_t getPacketId() const override; + [[nodiscard]] uint16_t getPacketSeqCtrl() const override; + [[nodiscard]] uint16_t getPacketDataLen() const override; + ReturnValue_t serialize(uint8_t **buffer, size_t *size, size_t maxSize, + Endianness streamEndianness) const override; + size_t getSerializedSize() const override; + ReturnValue_t deSerialize(const uint8_t **buffer, size_t *size, + Endianness streamEndianness) override; + + private: + uint16_t packetId; + uint16_t packetSeqCtrl; + uint16_t packetLen; + uint8_t version; +}; +#endif // FSFW_TMTCPACKET_SPACEPACKETCREATOR_H diff --git a/src/fsfw/tmtcpacket/SpacePacketBase.cpp b/src/fsfw/tmtcpacket/SpacePacketReader.cpp similarity index 69% rename from src/fsfw/tmtcpacket/SpacePacketBase.cpp rename to src/fsfw/tmtcpacket/SpacePacketReader.cpp index cb18519e..a1bcd465 100644 --- a/src/fsfw/tmtcpacket/SpacePacketBase.cpp +++ b/src/fsfw/tmtcpacket/SpacePacketReader.cpp @@ -1,17 +1,17 @@ -#include "fsfw/tmtcpacket/SpacePacketBase.h" +#include "fsfw/tmtcpacket/SpacePacketReader.h" #include #include "fsfw/serviceinterface/ServiceInterface.h" -SpacePacketBase::SpacePacketBase(const uint8_t* setAddress) { +SpacePacketReader::SpacePacketReader(const uint8_t* setAddress) { this->data = reinterpret_cast(const_cast(setAddress)); } -SpacePacketBase::~SpacePacketBase() = default; +SpacePacketReader::~SpacePacketReader() = default; -ReturnValue_t SpacePacketBase::initSpacePacketHeader(bool isTelecommand, bool hasSecondaryHeader, - uint16_t apid, uint16_t sequenceCount) { +ReturnValue_t SpacePacketReader::initSpacePacketHeader(bool isTelecommand, bool hasSecondaryHeader, + uint16_t apid, uint16_t sequenceCount) { if (data == nullptr) { #if FSFW_VERBOSE_LEVEL >= 1 #if FSFW_CPP_OSTREAM_ENABLED == 1 @@ -35,54 +35,54 @@ ReturnValue_t SpacePacketBase::initSpacePacketHeader(bool isTelecommand, bool ha return HasReturnvaluesIF::RETURN_OK; } -inline uint16_t SpacePacketBase::getPacketId() const { +inline uint16_t SpacePacketReader::getPacketId() const { return ((this->data->header.packetIdHAndVersion) << 8) + this->data->header.packetIdL; } -void SpacePacketBase::setApid(uint16_t setAPID) { +void SpacePacketReader::setApid(uint16_t setAPID) { // Use first three bits of new APID, but keep rest of packet id as it was (see specification). this->data->header.packetIdHAndVersion = (this->data->header.packetIdHAndVersion & 0b11111000) | ((setAPID & 0x0700) >> 8); this->data->header.packetIdL = (setAPID & 0x00FF); } -void SpacePacketBase::setSequenceFlags(uint8_t sequenceflags) { +void SpacePacketReader::setSequenceFlags(uint8_t sequenceflags) { this->data->header.packetSeqCtrlH &= 0x3F; this->data->header.packetSeqCtrlH |= sequenceflags << 6; } -void SpacePacketBase::setPacketSequenceCount(uint16_t new_count) { +void SpacePacketReader::setPacketSequenceCount(uint16_t new_count) { this->data->header.packetSeqCtrlH = (this->data->header.packetSeqCtrlH & 0b11000000) | (((new_count % ccsds::LIMIT_SEQUENCE_COUNT) & 0x3F00) >> 8); this->data->header.packetSeqCtrlL = ((new_count % ccsds::LIMIT_SEQUENCE_COUNT) & 0x00FF); } -void SpacePacketBase::setPacketDataLength(uint16_t new_length) { +void SpacePacketReader::setPacketDataLength(uint16_t new_length) { this->data->header.packetLenH = ((new_length & 0xFF00) >> 8); this->data->header.packetLenL = (new_length & 0x00FF); } -size_t SpacePacketBase::getFullSize() { +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; } -uint8_t* SpacePacketBase::getWholeData() { return reinterpret_cast(this->data); } +uint8_t* SpacePacketReader::getWholeData() { return reinterpret_cast(this->data); } -uint8_t* SpacePacketBase::getPacketData() { return &(data->packet_data); } +uint8_t* SpacePacketReader::getPacketData() { return &(data->packet_data); } -ReturnValue_t SpacePacketBase::setData(uint8_t* pData, size_t maxSize, void* args) { +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 SpacePacketBase::getPacketSeqCtrl() const { +uint16_t SpacePacketReader::getPacketSeqCtrl() const { return ((this->data->header.packetSeqCtrlH & 0b00111111) << 8) + this->data->header.packetSeqCtrlL; } -uint16_t SpacePacketBase::getPacketDataLen() const { +uint16_t SpacePacketReader::getPacketDataLen() const { return ((this->data->header.packetLenH) << 8) + this->data->header.packetLenL; } diff --git a/src/fsfw/tmtcpacket/SpacePacketBase.h b/src/fsfw/tmtcpacket/SpacePacketReader.h similarity index 93% rename from src/fsfw/tmtcpacket/SpacePacketBase.h rename to src/fsfw/tmtcpacket/SpacePacketReader.h index 862e4725..7fc88577 100644 --- a/src/fsfw/tmtcpacket/SpacePacketBase.h +++ b/src/fsfw/tmtcpacket/SpacePacketReader.h @@ -40,7 +40,7 @@ struct SpacePacketPointer { * the most significant bit (from left). * @ingroup tmtcpackets */ -class SpacePacketBase : public SpacePacketIF, public RedirectableDataPointerIF { +class SpacePacketReader : public SpacePacketIF, public RedirectableDataPointerIF { protected: /** * A pointer to a structure which defines the data structure of @@ -58,16 +58,18 @@ class SpacePacketBase : public SpacePacketIF, public RedirectableDataPointerIF { * This is the minimum size of a SpacePacket. */ static const uint16_t MINIMUM_SIZE = sizeof(CCSDSPrimaryHeader) + CRC_SIZE; + SpacePacketReader(uint16_t apid, ccsds::PacketType packetType, bool secHeader, uint16_t seqCount, + uint16_t dataLen); /** * 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 SpacePacketBase(const uint8_t* set_address); + explicit SpacePacketReader(const uint8_t* set_address); /** * No data is allocated, so the destructor is empty. */ - ~SpacePacketBase() override; + ~SpacePacketReader() override; ReturnValue_t initSpacePacketHeader(bool isTelecommand, bool hasSecondaryHeader, uint16_t apid, uint16_t sequenceCount = 0); diff --git a/src/fsfw/tmtcpacket/cfdp/CFDPPacket.cpp b/src/fsfw/tmtcpacket/cfdp/CFDPPacket.cpp index 5df50cd7..29b6c561 100644 --- a/src/fsfw/tmtcpacket/cfdp/CFDPPacket.cpp +++ b/src/fsfw/tmtcpacket/cfdp/CFDPPacket.cpp @@ -6,7 +6,7 @@ #include "fsfw/globalfunctions/arrayprinter.h" #include "fsfw/serviceinterface/ServiceInterface.h" -CFDPPacket::CFDPPacket(const uint8_t* setData) : SpacePacketBase(setData) {} +CFDPPacket::CFDPPacket(const uint8_t* setData) : SpacePacketReader(setData) {} CFDPPacket::~CFDPPacket() {} diff --git a/src/fsfw/tmtcpacket/cfdp/CFDPPacket.h b/src/fsfw/tmtcpacket/cfdp/CFDPPacket.h index 30ba98ae..a70c3938 100644 --- a/src/fsfw/tmtcpacket/cfdp/CFDPPacket.h +++ b/src/fsfw/tmtcpacket/cfdp/CFDPPacket.h @@ -1,9 +1,9 @@ #ifndef FSFW_INC_FSFW_TMTCPACKET_CFDP_CFDPPACKET_H_ #define FSFW_INC_FSFW_TMTCPACKET_CFDP_CFDPPACKET_H_ -#include "fsfw/tmtcpacket/SpacePacketBase.h" +#include "fsfw/tmtcpacket/SpacePacketReader.h" -class CFDPPacket : public SpacePacketBase { +class CFDPPacket : public SpacePacketReader { public: /** * This is the default constructor. diff --git a/src/fsfw/tmtcpacket/pus/tc/PusTcIF.h b/src/fsfw/tmtcpacket/pus/tc/PusTcIF.h index 91f8fe1e..3a2eaddc 100644 --- a/src/fsfw/tmtcpacket/pus/tc/PusTcIF.h +++ b/src/fsfw/tmtcpacket/pus/tc/PusTcIF.h @@ -4,76 +4,76 @@ #include class PusTcIF { - public: - virtual ~PusTcIF() = default; + public: + virtual ~PusTcIF() = default; - /** + /** * This command returns the CCSDS Secondary Header Flag. * It shall always be zero for PUS Packets. This is the * highest bit of the first byte of the Data Field Header. * @return the CCSDS Secondary Header Flag - */ - [[nodiscard]] virtual uint8_t getSecondaryHeaderFlag() const = 0; - /** + */ + [[nodiscard]] virtual uint8_t getSecondaryHeaderFlag() const = 0; + /** * 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; - /** + */ + [[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. * * It is packed in a uint8_t variable. * @return The packet's PUS Ack field. - */ - [[nodiscard]] virtual uint8_t getAcknowledgeFlags() const = 0; - /** + */ + [[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; - /** + */ + [[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; - /** + */ + [[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; + */ + [[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; - /** + */ + [[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; - /** + */ + [[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; - }; + */ + [[nodiscard]] virtual uint16_t getErrorControl() const = 0; +}; #endif // FSFW_TMTCPACKET_PUSTCIF_H diff --git a/src/fsfw/tmtcpacket/pus/tc/TcPacketDeserializer.h b/src/fsfw/tmtcpacket/pus/tc/TcPacketDeserializer.h index b3b35084..1e2e7bba 100644 --- a/src/fsfw/tmtcpacket/pus/tc/TcPacketDeserializer.h +++ b/src/fsfw/tmtcpacket/pus/tc/TcPacketDeserializer.h @@ -4,11 +4,11 @@ #include "fsfw/tmtcpacket/RedirectableDataPointerIF.h" #include "fsfw/tmtcpacket/SpacePacketIF.h" -class TcPacketDeserializer: public SpacePacketIF, public RedirectableDataPointerIF { +class TcPacketDeserializer : public SpacePacketIF, public RedirectableDataPointerIF { public: TcPacketDeserializer(const uint8_t* data, size_t maxSize); - private: + private: }; #endif // FSFW_TMTCPACKET_TCPACKETDESERIALIZER_H diff --git a/src/fsfw/tmtcpacket/pus/tc/TcPacketPus.cpp b/src/fsfw/tmtcpacket/pus/tc/TcPacketPus.cpp index c9f10b4b..faada828 100644 --- a/src/fsfw/tmtcpacket/pus/tc/TcPacketPus.cpp +++ b/src/fsfw/tmtcpacket/pus/tc/TcPacketPus.cpp @@ -37,7 +37,7 @@ uint8_t TcPacketPus::getAcknowledgeFlags() const { const uint8_t *TcPacketPus::getApplicationData() const { return &tcData->appData; } uint16_t TcPacketPus::getApplicationDataSize() const { - return SpacePacketBase::getPacketDataLen() - sizeof(tcData->dataField) - CRC_SIZE + 1; + return SpacePacketReader::getPacketDataLen() - sizeof(tcData->dataField) - CRC_SIZE + 1; } uint16_t TcPacketPus::getErrorControl() const { @@ -85,7 +85,7 @@ size_t TcPacketPus::calculateFullPacketLength(size_t appDataLen) const { } ReturnValue_t TcPacketPus::setData(uint8_t *dataPtr, size_t maxSize, void *args) { - ReturnValue_t result = SpacePacketBase::setData(dataPtr, maxSize, args); + ReturnValue_t result = SpacePacketReader::setData(dataPtr, maxSize, args); if (result != HasReturnvaluesIF::RETURN_OK) { return result; } diff --git a/src/fsfw/tmtcpacket/pus/tc/TcPacketPusBase.cpp b/src/fsfw/tmtcpacket/pus/tc/TcPacketPusBase.cpp index 812bae43..3d7ff888 100644 --- a/src/fsfw/tmtcpacket/pus/tc/TcPacketPusBase.cpp +++ b/src/fsfw/tmtcpacket/pus/tc/TcPacketPusBase.cpp @@ -6,7 +6,7 @@ #include "fsfw/globalfunctions/arrayprinter.h" #include "fsfw/serviceinterface/ServiceInterface.h" -TcPacketPusBase::TcPacketPusBase(const uint8_t* setData) : SpacePacketBase(setData) {} +TcPacketPusBase::TcPacketPusBase(const uint8_t* setData) : SpacePacketReader(setData) {} TcPacketPusBase::~TcPacketPusBase() {} diff --git a/src/fsfw/tmtcpacket/pus/tc/TcPacketPusBase.h b/src/fsfw/tmtcpacket/pus/tc/TcPacketPusBase.h index c84fc67d..ce30cb18 100644 --- a/src/fsfw/tmtcpacket/pus/tc/TcPacketPusBase.h +++ b/src/fsfw/tmtcpacket/pus/tc/TcPacketPusBase.h @@ -5,7 +5,7 @@ #include -#include "fsfw/tmtcpacket/SpacePacketBase.h" +#include "fsfw/tmtcpacket/SpacePacketReader.h" /** * This class is the basic data handler for any ECSS PUS Telecommand packet. @@ -18,7 +18,7 @@ * check can be performed by making use of the getWholeData method. * @ingroup tmtcpackets */ -class TcPacketPusBase : public SpacePacketBase { +class TcPacketPusBase : public SpacePacketReader { friend class TcPacketStoredBase; public: diff --git a/src/fsfw/tmtcpacket/pus/tm/TmPacketBase.cpp b/src/fsfw/tmtcpacket/pus/tm/TmPacketBase.cpp index e04f2b85..c81c2d4d 100644 --- a/src/fsfw/tmtcpacket/pus/tm/TmPacketBase.cpp +++ b/src/fsfw/tmtcpacket/pus/tm/TmPacketBase.cpp @@ -11,12 +11,12 @@ TimeStamperIF* TmPacketBase::timeStamper = nullptr; object_id_t TmPacketBase::timeStamperId = objects::NO_OBJECT; -TmPacketBase::TmPacketBase(uint8_t* setData) : SpacePacketBase(setData) {} +TmPacketBase::TmPacketBase(uint8_t* setData) : SpacePacketReader(setData) {} TmPacketBase::~TmPacketBase() = default; uint16_t TmPacketBase::getSourceDataSize() { - return SpacePacketBase::getPacketDataLen() - getDataFieldSize() - CRC_SIZE + 1; + return SpacePacketReader::getPacketDataLen() - getDataFieldSize() - CRC_SIZE + 1; } uint16_t TmPacketBase::getErrorControl() { diff --git a/src/fsfw/tmtcpacket/pus/tm/TmPacketBase.h b/src/fsfw/tmtcpacket/pus/tm/TmPacketBase.h index 72f3abd4..e1622466 100644 --- a/src/fsfw/tmtcpacket/pus/tm/TmPacketBase.h +++ b/src/fsfw/tmtcpacket/pus/tm/TmPacketBase.h @@ -4,7 +4,7 @@ #include "fsfw/objectmanager/SystemObjectIF.h" #include "fsfw/timemanager/Clock.h" #include "fsfw/timemanager/TimeStamperIF.h" -#include "fsfw/tmtcpacket/SpacePacketBase.h" +#include "fsfw/tmtcpacket/SpacePacketReader.h" namespace Factory { @@ -23,7 +23,7 @@ void setStaticFrameworkObjectIds(); * check can be performed by making use of the getWholeData method. * @ingroup tmtcpackets */ -class TmPacketBase : public SpacePacketBase { +class TmPacketBase : public SpacePacketReader { friend void(Factory::setStaticFrameworkObjectIds)(); public: diff --git a/src/fsfw/tmtcpacket/pus/tm/TmPacketMinimal.cpp b/src/fsfw/tmtcpacket/pus/tm/TmPacketMinimal.cpp index 388a4098..c1a5c4ba 100644 --- a/src/fsfw/tmtcpacket/pus/tm/TmPacketMinimal.cpp +++ b/src/fsfw/tmtcpacket/pus/tm/TmPacketMinimal.cpp @@ -5,7 +5,7 @@ #include "fsfw/tmtcpacket/pus/PacketTimestampInterpreterIF.h" -TmPacketMinimal::TmPacketMinimal(const uint8_t* set_data) : SpacePacketBase(set_data) { +TmPacketMinimal::TmPacketMinimal(const uint8_t* set_data) : SpacePacketReader(set_data) { this->tm_data = (TmPacketMinimalPointer*)set_data; } diff --git a/src/fsfw/tmtcpacket/pus/tm/TmPacketMinimal.h b/src/fsfw/tmtcpacket/pus/tm/TmPacketMinimal.h index dc9c33ae..197bf6e6 100644 --- a/src/fsfw/tmtcpacket/pus/tm/TmPacketMinimal.h +++ b/src/fsfw/tmtcpacket/pus/tm/TmPacketMinimal.h @@ -2,7 +2,7 @@ #define FRAMEWORK_TMTCPACKET_PUS_TMPACKETMINIMAL_H_ #include "../../../returnvalues/HasReturnvaluesIF.h" -#include "../../SpacePacketBase.h" +#include "../../SpacePacketReader.h" struct timeval; class PacketTimestampInterpreterIF; @@ -12,7 +12,7 @@ class PacketTimestampInterpreterIF; * This is required for handling TM packets with different APIDs with different * secondary headers. */ -class TmPacketMinimal : public SpacePacketBase { +class TmPacketMinimal : public SpacePacketReader { public: /** * This is the default constructor. diff --git a/src/fsfw/tmtcpacket/pus/tm/TmPacketPusA.cpp b/src/fsfw/tmtcpacket/pus/tm/TmPacketPusA.cpp index 1a830004..8ccb87b5 100644 --- a/src/fsfw/tmtcpacket/pus/tm/TmPacketPusA.cpp +++ b/src/fsfw/tmtcpacket/pus/tm/TmPacketPusA.cpp @@ -25,11 +25,11 @@ uint8_t TmPacketPusA::getSubService() { return tmData->data_field.service_subtyp uint8_t* TmPacketPusA::getSourceData() { return &tmData->data; } uint16_t TmPacketPusA::getSourceDataSize() { - return SpacePacketBase::getPacketDataLen() - sizeof(tmData->data_field) - CRC_SIZE + 1; + return SpacePacketReader::getPacketDataLen() - sizeof(tmData->data_field) - CRC_SIZE + 1; } ReturnValue_t TmPacketPusA::setData(uint8_t* p_Data, size_t maxSize, void* args) { - ReturnValue_t result = SpacePacketBase::setData(p_Data, maxSize, args); + ReturnValue_t result = SpacePacketReader::setData(p_Data, maxSize, args); if (result != HasReturnvaluesIF::RETURN_OK) { return result; } diff --git a/src/fsfw/tmtcpacket/pus/tm/TmPacketPusA.h b/src/fsfw/tmtcpacket/pus/tm/TmPacketPusA.h index a84547ff..6808a8d6 100644 --- a/src/fsfw/tmtcpacket/pus/tm/TmPacketPusA.h +++ b/src/fsfw/tmtcpacket/pus/tm/TmPacketPusA.h @@ -5,7 +5,7 @@ #include "fsfw/objectmanager/SystemObjectIF.h" #include "fsfw/timemanager/Clock.h" #include "fsfw/timemanager/TimeStamperIF.h" -#include "fsfw/tmtcpacket/SpacePacketBase.h" +#include "fsfw/tmtcpacket/SpacePacketReader.h" namespace Factory { void setStaticFrameworkObjectIds(); diff --git a/src/fsfw/tmtcpacket/pus/tm/TmPacketPusC.cpp b/src/fsfw/tmtcpacket/pus/tm/TmPacketPusC.cpp index c402a577..fd2248aa 100644 --- a/src/fsfw/tmtcpacket/pus/tm/TmPacketPusC.cpp +++ b/src/fsfw/tmtcpacket/pus/tm/TmPacketPusC.cpp @@ -23,11 +23,11 @@ uint8_t TmPacketPusC::getSubService() { return tmData->dataField.serviceSubtype; uint8_t* TmPacketPusC::getSourceData() { return &tmData->data; } uint16_t TmPacketPusC::getSourceDataSize() { - return SpacePacketBase::getPacketDataLen() - sizeof(tmData->dataField) - CRC_SIZE + 1; + return SpacePacketReader::getPacketDataLen() - sizeof(tmData->dataField) - CRC_SIZE + 1; } ReturnValue_t TmPacketPusC::setData(uint8_t* p_Data, size_t maxSize, void* args) { - ReturnValue_t result = SpacePacketBase::setData(p_Data, maxSize, args); + ReturnValue_t result = SpacePacketReader::setData(p_Data, maxSize, args); if (result != HasReturnvaluesIF::RETURN_OK) { return result; } diff --git a/src/fsfw/tmtcpacket/pus/tm/TmPacketPusC.h b/src/fsfw/tmtcpacket/pus/tm/TmPacketPusC.h index 4b3ca18c..bf9de122 100644 --- a/src/fsfw/tmtcpacket/pus/tm/TmPacketPusC.h +++ b/src/fsfw/tmtcpacket/pus/tm/TmPacketPusC.h @@ -5,7 +5,7 @@ #include "fsfw/objectmanager/SystemObjectIF.h" #include "fsfw/timemanager/Clock.h" #include "fsfw/timemanager/TimeStamperIF.h" -#include "fsfw/tmtcpacket/SpacePacketBase.h" +#include "fsfw/tmtcpacket/SpacePacketReader.h" namespace Factory { void setStaticFrameworkObjectIds(); diff --git a/src/fsfw/tmtcservices/SourceSequenceCounter.h b/src/fsfw/tmtcservices/SourceSequenceCounter.h index e981a945..836ac5e9 100644 --- a/src/fsfw/tmtcservices/SourceSequenceCounter.h +++ b/src/fsfw/tmtcservices/SourceSequenceCounter.h @@ -1,7 +1,7 @@ #ifndef FSFW_TMTCSERVICES_SOURCESEQUENCECOUNTER_H_ #define FSFW_TMTCSERVICES_SOURCESEQUENCECOUNTER_H_ -#include "../tmtcpacket/SpacePacketBase.h" +#include "../tmtcpacket/SpacePacketReader.h" class SourceSequenceCounter { private: diff --git a/tests/src/fsfw_tests/unit/tmtcpacket/testCcsds.cpp b/tests/src/fsfw_tests/unit/tmtcpacket/testCcsds.cpp index 76140c26..6d3b63a7 100644 --- a/tests/src/fsfw_tests/unit/tmtcpacket/testCcsds.cpp +++ b/tests/src/fsfw_tests/unit/tmtcpacket/testCcsds.cpp @@ -1,11 +1,15 @@ #include -#include "fsfw/tmtcpacket/SpacePacketBase.h" +#include "fsfw/tmtcpacket/SpacePacketReader.h" TEST_CASE("CCSDS Test", "[ccsds]") { - REQUIRE(ccsds::getTcSpacePacketIdFromApid(0x22) == 0x1822); - REQUIRE(ccsds::getTmSpacePacketIdFromApid(0x22) == 0x0822); + SECTION("Constexpr Helpers") { + REQUIRE(ccsds::getTcSpacePacketIdFromApid(0x22) == 0x1822); + REQUIRE(ccsds::getTmSpacePacketIdFromApid(0x22) == 0x0822); - REQUIRE(ccsds::getTcSpacePacketIdFromApid(0x7ff) == 0x1fff); - REQUIRE(ccsds::getTmSpacePacketIdFromApid(0x7ff) == 0xfff); + REQUIRE(ccsds::getTcSpacePacketIdFromApid(0x7ff) == 0x1fff); + REQUIRE(ccsds::getTmSpacePacketIdFromApid(0x7ff) == 0xfff); + } + + SECTION("Header Tests") { SpacePacketReader base = SpacePacketReader(); } } -- 2.43.0 From 0c5f6237807166a602d2a49e57a5027f2d80bd09 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Mon, 18 Jul 2022 10:53:55 +0200 Subject: [PATCH 004/108] additional ctor for space packet creator --- src/fsfw/serialize/SerializeAdapter.h | 4 +-- src/fsfw/tmtcpacket/SpacePacketCreator.cpp | 25 ++++++++++++++++--- src/fsfw/tmtcpacket/SpacePacketCreator.h | 10 +++++--- .../fsfw_tests/unit/tmtcpacket/testCcsds.cpp | 7 +++++- 4 files changed, 37 insertions(+), 9 deletions(-) diff --git a/src/fsfw/serialize/SerializeAdapter.h b/src/fsfw/serialize/SerializeAdapter.h index 5feda889..4580986f 100644 --- a/src/fsfw/serialize/SerializeAdapter.h +++ b/src/fsfw/serialize/SerializeAdapter.h @@ -74,7 +74,7 @@ class SerializeAdapter { return HasReturnvaluesIF::RETURN_FAILED; } InternalSerializeAdapter::value> adapter; - uint8_t **tempPtr = const_cast(&buffer); + auto **tempPtr = const_cast(&buffer); size_t tmpSize = 0; ReturnValue_t result = adapter.serialize(object, tempPtr, &tmpSize, maxSize, streamEndianness); if (serSize != nullptr) { @@ -232,7 +232,7 @@ class SerializeAdapter { } } - uint32_t getSerializedSize(const T *object) { return sizeof(T); } + uint32_t getSerializedSize(const T *) { return sizeof(T); } }; /** diff --git a/src/fsfw/tmtcpacket/SpacePacketCreator.cpp b/src/fsfw/tmtcpacket/SpacePacketCreator.cpp index d5eb73c2..0263dad3 100644 --- a/src/fsfw/tmtcpacket/SpacePacketCreator.cpp +++ b/src/fsfw/tmtcpacket/SpacePacketCreator.cpp @@ -3,11 +3,30 @@ #include "fsfw/serialize/SerializeAdapter.h" SpacePacketCreator::SpacePacketCreator(uint16_t packetId_, uint16_t packetSeqCtrl_, - uint16_t packetLen_, uint8_t version_) { + uint16_t dataLen_, uint8_t version_) { packetId = packetId_; packetSeqCtrl = packetSeqCtrl_; - packetLen = packetLen_; + dataLen = dataLen_; version = version_; + valid = true; +} + +SpacePacketCreator::SpacePacketCreator(ccsds::PacketType packetType, bool secHeaderFlag, + uint16_t apid, ccsds::SequenceFlags seqFlags, + uint16_t seqCount, uint16_t dataLen_, uint8_t version_) { + if (apid > ccsds::LIMIT_APID) { + valid = false; + return; + } + if (seqCount > ccsds::LIMIT_SEQUENCE_COUNT) { + valid = false; + return; + } + version = version_; + packetId = + (version_ << 13) | (static_cast(packetType) << 12) | (secHeaderFlag << 11) | apid; + packetSeqCtrl = static_cast(seqFlags) << 14 | seqCount; + dataLen = dataLen_; } uint16_t SpacePacketCreator::getPacketId() const { return 0; } @@ -26,7 +45,7 @@ ReturnValue_t SpacePacketCreator::serialize(uint8_t **buffer, size_t *size, size if (result != HasReturnvaluesIF::RETURN_OK) { return result; } - return SerializeAdapter::serialize(&packetLen, buffer, size, maxSize, streamEndianness); + return SerializeAdapter::serialize(&dataLen, buffer, size, maxSize, streamEndianness); } size_t SpacePacketCreator::getSerializedSize() const { return 0; } diff --git a/src/fsfw/tmtcpacket/SpacePacketCreator.h b/src/fsfw/tmtcpacket/SpacePacketCreator.h index 2e7d2537..79ea47dc 100644 --- a/src/fsfw/tmtcpacket/SpacePacketCreator.h +++ b/src/fsfw/tmtcpacket/SpacePacketCreator.h @@ -6,21 +6,25 @@ class SpacePacketCreator : public SerializeIF, public SpacePacketIF { public: - SpacePacketCreator(uint16_t packetId, uint16_t packetSeqCtrl, uint16_t packetLen, + SpacePacketCreator(ccsds::PacketType packetType, bool secHeaderFlag, uint16_t apid, + ccsds::SequenceFlags seqFlags, uint16_t seqCount, uint16_t dataLen, uint8_t version = 0); + SpacePacketCreator(uint16_t packetId, uint16_t packetSeqCtrl, uint16_t dataLen, + uint8_t version = 0); + bool valid; [[nodiscard]] uint16_t getPacketId() const override; [[nodiscard]] uint16_t getPacketSeqCtrl() const override; [[nodiscard]] uint16_t getPacketDataLen() const override; ReturnValue_t serialize(uint8_t **buffer, size_t *size, size_t maxSize, Endianness streamEndianness) const override; - size_t getSerializedSize() const override; + [[nodiscard]] size_t getSerializedSize() const override; ReturnValue_t deSerialize(const uint8_t **buffer, size_t *size, Endianness streamEndianness) override; private: uint16_t packetId; uint16_t packetSeqCtrl; - uint16_t packetLen; + uint16_t dataLen; uint8_t version; }; #endif // FSFW_TMTCPACKET_SPACEPACKETCREATOR_H diff --git a/tests/src/fsfw_tests/unit/tmtcpacket/testCcsds.cpp b/tests/src/fsfw_tests/unit/tmtcpacket/testCcsds.cpp index 6d3b63a7..0fd2a19c 100644 --- a/tests/src/fsfw_tests/unit/tmtcpacket/testCcsds.cpp +++ b/tests/src/fsfw_tests/unit/tmtcpacket/testCcsds.cpp @@ -1,5 +1,6 @@ #include +#include "fsfw/tmtcpacket/SpacePacketCreator.h" #include "fsfw/tmtcpacket/SpacePacketReader.h" TEST_CASE("CCSDS Test", "[ccsds]") { @@ -11,5 +12,9 @@ TEST_CASE("CCSDS Test", "[ccsds]") { REQUIRE(ccsds::getTmSpacePacketIdFromApid(0x7ff) == 0xfff); } - SECTION("Header Tests") { SpacePacketReader base = SpacePacketReader(); } + SECTION("Header Creator Tests") { + SpacePacketCreator base = SpacePacketCreator( + ccsds::PacketType::TM, true, 0x22, + ccsds::SequenceFlags::CONTINUATION, 12, 0x42); + } } -- 2.43.0 From 3c72a42ce145cb2b632af83df9975c2625c60556 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Mon, 18 Jul 2022 13:51:02 +0200 Subject: [PATCH 005/108] added basic sp creator test --- src/fsfw/tmtcpacket/SpacePacketCreator.cpp | 6 +++--- tests/src/fsfw_tests/unit/tmtcpacket/testCcsds.cpp | 10 ++++++++-- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/src/fsfw/tmtcpacket/SpacePacketCreator.cpp b/src/fsfw/tmtcpacket/SpacePacketCreator.cpp index 0263dad3..b02bae80 100644 --- a/src/fsfw/tmtcpacket/SpacePacketCreator.cpp +++ b/src/fsfw/tmtcpacket/SpacePacketCreator.cpp @@ -29,9 +29,9 @@ SpacePacketCreator::SpacePacketCreator(ccsds::PacketType packetType, bool secHea dataLen = dataLen_; } -uint16_t SpacePacketCreator::getPacketId() const { return 0; } -uint16_t SpacePacketCreator::getPacketSeqCtrl() const { return 0; } -uint16_t SpacePacketCreator::getPacketDataLen() const { return 0; } +uint16_t SpacePacketCreator::getPacketId() const { return packetId; } +uint16_t SpacePacketCreator::getPacketSeqCtrl() const { return packetSeqCtrl; } +uint16_t SpacePacketCreator::getPacketDataLen() const { return dataLen; } ReturnValue_t SpacePacketCreator::serialize(uint8_t **buffer, size_t *size, size_t maxSize, SerializeIF::Endianness streamEndianness) const { diff --git a/tests/src/fsfw_tests/unit/tmtcpacket/testCcsds.cpp b/tests/src/fsfw_tests/unit/tmtcpacket/testCcsds.cpp index 0fd2a19c..0925cdc7 100644 --- a/tests/src/fsfw_tests/unit/tmtcpacket/testCcsds.cpp +++ b/tests/src/fsfw_tests/unit/tmtcpacket/testCcsds.cpp @@ -14,7 +14,13 @@ TEST_CASE("CCSDS Test", "[ccsds]") { SECTION("Header Creator Tests") { SpacePacketCreator base = SpacePacketCreator( - ccsds::PacketType::TM, true, 0x22, - ccsds::SequenceFlags::CONTINUATION, 12, 0x42); + ccsds::PacketType::TC, true, 0x02, + ccsds::SequenceFlags::FIRST_SEGMENT, 0x34, 0x16); + REQUIRE(base.getApid() == 0x02); + REQUIRE(base.getSequenceFlags() == ccsds::SequenceFlags::FIRST_SEGMENT); + REQUIRE(base.getVersion() == 0b000); + REQUIRE(base.getSequenceCount() == 0x34); + REQUIRE(base.getPacketDataLen() == 0x16); + REQUIRE(base.getPacketType() == ccsds::PacketType::TC); } } -- 2.43.0 From 7e2fdc06cd53d31a946d0f6c4bf854a15a52bad8 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Mon, 18 Jul 2022 14:05:43 +0200 Subject: [PATCH 006/108] hmm this is problematic --- src/fsfw/tmtcpacket/SpacePacketCreator.cpp | 4 +-- src/fsfw/tmtcpacket/SpacePacketCreator.h | 3 ++- .../fsfw_tests/unit/tmtcpacket/testCcsds.cpp | 25 ++++++++++++++++--- 3 files changed, 25 insertions(+), 7 deletions(-) diff --git a/src/fsfw/tmtcpacket/SpacePacketCreator.cpp b/src/fsfw/tmtcpacket/SpacePacketCreator.cpp index b02bae80..06df33c0 100644 --- a/src/fsfw/tmtcpacket/SpacePacketCreator.cpp +++ b/src/fsfw/tmtcpacket/SpacePacketCreator.cpp @@ -23,8 +23,7 @@ SpacePacketCreator::SpacePacketCreator(ccsds::PacketType packetType, bool secHea return; } version = version_; - packetId = - (version_ << 13) | (static_cast(packetType) << 12) | (secHeaderFlag << 11) | apid; + packetId = (static_cast(packetType) << 12) | (static_cast(secHeaderFlag) << 11) | apid; packetSeqCtrl = static_cast(seqFlags) << 14 | seqCount; dataLen = dataLen_; } @@ -53,3 +52,4 @@ ReturnValue_t SpacePacketCreator::deSerialize(const uint8_t **buffer, size_t *si SerializeIF::Endianness streamEndianness) { return HasReturnvaluesIF::RETURN_FAILED; } +bool SpacePacketCreator::isValid() const { return valid; } diff --git a/src/fsfw/tmtcpacket/SpacePacketCreator.h b/src/fsfw/tmtcpacket/SpacePacketCreator.h index 79ea47dc..f99cb9dd 100644 --- a/src/fsfw/tmtcpacket/SpacePacketCreator.h +++ b/src/fsfw/tmtcpacket/SpacePacketCreator.h @@ -11,7 +11,7 @@ class SpacePacketCreator : public SerializeIF, public SpacePacketIF { uint8_t version = 0); SpacePacketCreator(uint16_t packetId, uint16_t packetSeqCtrl, uint16_t dataLen, uint8_t version = 0); - bool valid; + [[nodiscard]] bool isValid() const; [[nodiscard]] uint16_t getPacketId() const override; [[nodiscard]] uint16_t getPacketSeqCtrl() const override; [[nodiscard]] uint16_t getPacketDataLen() const override; @@ -22,6 +22,7 @@ class SpacePacketCreator : public SerializeIF, public SpacePacketIF { Endianness streamEndianness) override; private: + bool valid; uint16_t packetId; uint16_t packetSeqCtrl; uint16_t dataLen; diff --git a/tests/src/fsfw_tests/unit/tmtcpacket/testCcsds.cpp b/tests/src/fsfw_tests/unit/tmtcpacket/testCcsds.cpp index 0925cdc7..93cea57a 100644 --- a/tests/src/fsfw_tests/unit/tmtcpacket/testCcsds.cpp +++ b/tests/src/fsfw_tests/unit/tmtcpacket/testCcsds.cpp @@ -1,9 +1,14 @@ +#include #include #include "fsfw/tmtcpacket/SpacePacketCreator.h" #include "fsfw/tmtcpacket/SpacePacketReader.h" TEST_CASE("CCSDS Test", "[ccsds]") { + SpacePacketCreator base = SpacePacketCreator( + ccsds::PacketType::TC, true, 0x02, + ccsds::SequenceFlags::FIRST_SEGMENT, 0x34, 0x16); + SECTION("Constexpr Helpers") { REQUIRE(ccsds::getTcSpacePacketIdFromApid(0x22) == 0x1822); REQUIRE(ccsds::getTmSpacePacketIdFromApid(0x22) == 0x0822); @@ -12,15 +17,27 @@ TEST_CASE("CCSDS Test", "[ccsds]") { REQUIRE(ccsds::getTmSpacePacketIdFromApid(0x7ff) == 0xfff); } - SECTION("Header Creator Tests") { - SpacePacketCreator base = SpacePacketCreator( - ccsds::PacketType::TC, true, 0x02, - ccsds::SequenceFlags::FIRST_SEGMENT, 0x34, 0x16); + SECTION("Basic Test") { + REQUIRE(base.isValid()); REQUIRE(base.getApid() == 0x02); REQUIRE(base.getSequenceFlags() == ccsds::SequenceFlags::FIRST_SEGMENT); REQUIRE(base.getVersion() == 0b000); REQUIRE(base.getSequenceCount() == 0x34); REQUIRE(base.getPacketDataLen() == 0x16); REQUIRE(base.getPacketType() == ccsds::PacketType::TC); + REQUIRE(base.getPacketId() == 0x1802); + } + + SECTION("Raw Output") { + std::array buf {}; + uint8_t* bufPtr = buf.data(); + size_t serLen = 0; + base.serialize(&bufPtr, &serLen, buf.size(), SerializeIF::Endianness::MACHINE); + REQUIRE(buf[0] == 0x18); + REQUIRE(buf[1] == 0x02); + REQUIRE(buf[2] == 0x40); + REQUIRE(buf[3] == 0x34); + REQUIRE(buf[4] == 0x00); + REQUIRE(buf[5] == 0x16); } } -- 2.43.0 From e4d7182d93b8c5b12c3a5d70123bb49b28d94206 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Mon, 18 Jul 2022 14:58:47 +0200 Subject: [PATCH 007/108] update changelog --- CHANGELOG.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 394f1e45..3854dc79 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -40,6 +40,9 @@ and this project adheres to [Semantic Versioning](http://semver.org/). creation call. It allows passing context information and an arbitrary user argument into the message queue. Also streamlined and simplified `MessageQueue` implementation for all OSALs PR: https://egit.irs.uni-stuttgart.de/fsfw/fsfw/pulls/583 +- Internal API change: Moved the `fsfw_hal` to the `src` folder and integration and internal + tests part of `fsfw_tests` to `src`. Unittests are now in a deciated folder called `unittests` + PR: https://egit.irs.uni-stuttgart.de/fsfw/fsfw/pulls/653 ### Task Module Refactoring -- 2.43.0 From ddf38b65c34210a6add30f2b62330ef4aa5735e2 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Mon, 18 Jul 2022 16:07:26 +0200 Subject: [PATCH 008/108] apply auto-formatter --- CMakeLists.txt | 4 +- scripts/auto-formatter.sh | 3 +- src/fsfw/tmtcpacket/SpacePacketCreator.cpp | 63 +++++++++----- src/fsfw/tmtcpacket/SpacePacketCreator.h | 60 ++++++++++++-- src/fsfw_hal/CMakeLists.txt | 4 +- src/fsfw_hal/common/gpio/CMakeLists.txt | 4 +- src/fsfw_hal/devicehandlers/CMakeLists.txt | 8 +- src/fsfw_hal/linux/CMakeLists.txt | 30 +++---- src/fsfw_hal/linux/gpio/CMakeLists.txt | 18 ++-- src/fsfw_hal/linux/i2c/CMakeLists.txt | 9 +- src/fsfw_hal/linux/rpi/CMakeLists.txt | 4 +- src/fsfw_hal/linux/spi/CMakeLists.txt | 9 +- src/fsfw_hal/linux/uart/CMakeLists.txt | 5 +- src/fsfw_hal/linux/uio/CMakeLists.txt | 4 +- src/fsfw_hal/stm32h7/CMakeLists.txt | 4 +- .../stm32h7/devicetest/CMakeLists.txt | 4 +- src/fsfw_hal/stm32h7/gpio/CMakeLists.txt | 4 +- src/fsfw_hal/stm32h7/i2c/CMakeLists.txt | 3 +- src/fsfw_hal/stm32h7/spi/CMakeLists.txt | 18 ++-- src/fsfw_hal/stm32h7/uart/CMakeLists.txt | 3 +- src/fsfw_tests/CMakeLists.txt | 4 +- .../integration/assemblies/CMakeLists.txt | 4 +- .../integration/controller/CMakeLists.txt | 4 +- .../integration/devices/CMakeLists.txt | 7 +- .../integration/task/CMakeLists.txt | 4 +- src/fsfw_tests/internal/CMakeLists.txt | 8 +- .../internal/globalfunctions/CMakeLists.txt | 4 +- src/fsfw_tests/internal/osal/CMakeLists.txt | 7 +- .../internal/serialize/CMakeLists.txt | 4 +- unittests/tmtcpacket/CMakeLists.txt | 2 +- unittests/tmtcpacket/testCcsds.cpp | 43 ---------- unittests/tmtcpacket/testCcsdsReader.cpp | 82 +++++++++++++++++++ 32 files changed, 242 insertions(+), 192 deletions(-) delete mode 100644 unittests/tmtcpacket/testCcsds.cpp create mode 100644 unittests/tmtcpacket/testCcsdsReader.cpp diff --git a/CMakeLists.txt b/CMakeLists.txt index ebdf809b..98a84cb6 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -104,8 +104,8 @@ if(FSFW_GENERATE_SECTIONS) option(FSFW_REMOVE_UNUSED_CODE "Remove unused code" ON) endif() -option(FSFW_BUILD_TESTS - "Build unittest binary in addition to static library" OFF) +option(FSFW_BUILD_TESTS "Build unittest binary in addition to static library" + OFF) option(FSFW_CICD_BUILD "Build for CI/CD. This can disable problematic test" OFF) option(FSFW_BUILD_DOCS "Build documentation with Sphinx and Doxygen" OFF) if(FSFW_BUILD_TESTS) diff --git a/scripts/auto-formatter.sh b/scripts/auto-formatter.sh index 405d1268..c0ae7099 100755 --- a/scripts/auto-formatter.sh +++ b/scripts/auto-formatter.sh @@ -16,8 +16,7 @@ cpp_format="clang-format" file_selectors="-iname *.h -o -iname *.cpp -o -iname *.c -o -iname *.tpp" if command -v ${cpp_format} &> /dev/null; then find ./src ${file_selectors} | xargs ${cpp_format} --style=file -i - find ./hal ${file_selectors} | xargs ${cpp_format} --style=file -i - find ./tests ${file_selectors} | xargs ${cpp_format} --style=file -i + find ./unittests ${file_selectors} | xargs ${cpp_format} --style=file -i else echo "No ${cpp_format} tool found, not formatting C++/C files" fi diff --git a/src/fsfw/tmtcpacket/SpacePacketCreator.cpp b/src/fsfw/tmtcpacket/SpacePacketCreator.cpp index 06df33c0..acc2fea2 100644 --- a/src/fsfw/tmtcpacket/SpacePacketCreator.cpp +++ b/src/fsfw/tmtcpacket/SpacePacketCreator.cpp @@ -2,54 +2,75 @@ #include "fsfw/serialize/SerializeAdapter.h" -SpacePacketCreator::SpacePacketCreator(uint16_t packetId_, uint16_t packetSeqCtrl_, - uint16_t dataLen_, uint8_t version_) { - packetId = packetId_; - packetSeqCtrl = packetSeqCtrl_; +SpacePacketCreator::SpacePacketCreator(PacketId packetId_, PacketSeqCtrl psc_, uint16_t dataLen_, + uint8_t version_) + : packetId(packetId_), packetSeqCtrl(psc_) { dataLen = dataLen_; version = version_; - valid = true; + checkFieldValidity(); } SpacePacketCreator::SpacePacketCreator(ccsds::PacketType packetType, bool secHeaderFlag, uint16_t apid, ccsds::SequenceFlags seqFlags, - uint16_t seqCount, uint16_t dataLen_, uint8_t version_) { - if (apid > ccsds::LIMIT_APID) { - valid = false; - return; - } - if (seqCount > ccsds::LIMIT_SEQUENCE_COUNT) { - valid = false; - return; - } + uint16_t seqCount, uint16_t dataLen_, uint8_t version_) + : SpacePacketCreator(PacketId(packetType, secHeaderFlag, apid), + PacketSeqCtrl(seqFlags, seqCount), dataLen_, version_) { version = version_; - packetId = (static_cast(packetType) << 12) | (static_cast(secHeaderFlag) << 11) | apid; - packetSeqCtrl = static_cast(seqFlags) << 14 | seqCount; dataLen = dataLen_; } -uint16_t SpacePacketCreator::getPacketId() const { return packetId; } -uint16_t SpacePacketCreator::getPacketSeqCtrl() const { return packetSeqCtrl; } +uint16_t SpacePacketCreator::getPacketId() const { return packetId.raw(); } +uint16_t SpacePacketCreator::getPacketSeqCtrl() const { return packetSeqCtrl.raw(); } uint16_t SpacePacketCreator::getPacketDataLen() const { return dataLen; } ReturnValue_t SpacePacketCreator::serialize(uint8_t **buffer, size_t *size, size_t maxSize, SerializeIF::Endianness streamEndianness) const { - uint16_t packetIdAndVersion = version << 13 | packetId; + if (not isValid()) { + return HasReturnvaluesIF::RETURN_FAILED; + } + uint16_t packetIdAndVersion = (static_cast(version) << 13) | packetId.raw(); ReturnValue_t result = SerializeAdapter::serialize(&packetIdAndVersion, buffer, size, maxSize, streamEndianness); if (result != HasReturnvaluesIF::RETURN_OK) { return result; } - result = SerializeAdapter::serialize(&packetSeqCtrl, buffer, size, maxSize, streamEndianness); + uint16_t pscRaw = 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); } -size_t SpacePacketCreator::getSerializedSize() const { return 0; } +size_t SpacePacketCreator::getSerializedSize() const { return 6; } + ReturnValue_t SpacePacketCreator::deSerialize(const uint8_t **buffer, size_t *size, SerializeIF::Endianness streamEndianness) { return HasReturnvaluesIF::RETURN_FAILED; } bool SpacePacketCreator::isValid() const { return valid; } + +ReturnValue_t SpacePacketCreator::serialize(uint8_t **buffer, size_t *size, size_t maxSize) const { + return serialize(buffer, size, maxSize, SerializeIF::Endianness::NETWORK); +} +void SpacePacketCreator::setApid(uint16_t apid) { + if (apid < ccsds::LIMIT_APID) { + packetId.apid = apid; + } + checkFieldValidity(); +} + +void SpacePacketCreator::setSeqCount(uint16_t seqCount) { + if (seqCount < ccsds::LIMIT_SEQUENCE_COUNT) { + packetSeqCtrl.seqCount = seqCount; + } + checkFieldValidity(); +} +void SpacePacketCreator::setSeqFlags(ccsds::SequenceFlags flags) { packetSeqCtrl.seqFlags = flags; } +void SpacePacketCreator::setDataLen(uint16_t dataLen_) { dataLen = dataLen_; } +void SpacePacketCreator::checkFieldValidity() { + valid = true; + if (packetId.apid > ccsds::LIMIT_APID or packetSeqCtrl.seqCount > ccsds::LIMIT_SEQUENCE_COUNT) { + valid = false; + } +} diff --git a/src/fsfw/tmtcpacket/SpacePacketCreator.h b/src/fsfw/tmtcpacket/SpacePacketCreator.h index f99cb9dd..9a9a0e2d 100644 --- a/src/fsfw/tmtcpacket/SpacePacketCreator.h +++ b/src/fsfw/tmtcpacket/SpacePacketCreator.h @@ -4,27 +4,77 @@ #include "SpacePacketIF.h" #include "fsfw/serialize/SerializeIF.h" +struct PacketId { + public: + /** + * Simple wrapper for Space Packet IDs. Does not check the APID for validity + * @param packetType_ + * @param secHeaderFlag_ + * @param apid_ + */ + PacketId(ccsds::PacketType packetType_, bool secHeaderFlag_, uint16_t apid_) + : packetType(packetType_), secHeaderFlag(secHeaderFlag_), apid(apid_) {} + + /** + * NOTE: If the APID has an invalid value, the invalid bits will be cut off + * @return + */ + [[nodiscard]] uint16_t raw() const { + return (static_cast(packetType) << 12) | + (static_cast(secHeaderFlag) << 11) | (apid & 0x7ff); + } + + ccsds::PacketType packetType; + bool secHeaderFlag; + uint16_t apid; +}; + +struct PacketSeqCtrl { + public: + PacketSeqCtrl(ccsds::SequenceFlags seqFlags, uint16_t seqCount) + : seqFlags(seqFlags), seqCount(seqCount) {} + + /** + * NOTE: If the sequence control has an invalid value, the invalid bits will be cut off + * @return + */ + [[nodiscard]] uint16_t raw() const { + return (static_cast(seqFlags) << 14) | (seqCount & 0x3FFF); + } + ccsds::SequenceFlags seqFlags; + uint16_t seqCount; +}; + class SpacePacketCreator : public SerializeIF, public SpacePacketIF { public: SpacePacketCreator(ccsds::PacketType packetType, bool secHeaderFlag, uint16_t apid, ccsds::SequenceFlags seqFlags, uint16_t seqCount, uint16_t dataLen, uint8_t version = 0); - SpacePacketCreator(uint16_t packetId, uint16_t packetSeqCtrl, uint16_t dataLen, - uint8_t version = 0); + SpacePacketCreator(PacketId packetId, PacketSeqCtrl psc, uint16_t dataLen, uint8_t version = 0); [[nodiscard]] bool isValid() const; [[nodiscard]] uint16_t getPacketId() const override; [[nodiscard]] uint16_t getPacketSeqCtrl() const override; [[nodiscard]] uint16_t getPacketDataLen() const override; + + void setApid(uint16_t apid); + void setSeqCount(uint16_t seqCount); + void setSeqFlags(ccsds::SequenceFlags flags); + void setDataLen(uint16_t dataLen); + + ReturnValue_t serialize(uint8_t **buffer, size_t *size, size_t maxSize) const; 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; private: - bool valid; - uint16_t packetId; - uint16_t packetSeqCtrl; + void checkFieldValidity(); + + bool valid{}; + PacketId packetId; + PacketSeqCtrl packetSeqCtrl; uint16_t dataLen; uint8_t version; }; diff --git a/src/fsfw_hal/CMakeLists.txt b/src/fsfw_hal/CMakeLists.txt index b7559d4b..057ab3a6 100644 --- a/src/fsfw_hal/CMakeLists.txt +++ b/src/fsfw_hal/CMakeLists.txt @@ -2,9 +2,9 @@ add_subdirectory(devicehandlers) add_subdirectory(common) if(UNIX) - add_subdirectory(linux) + add_subdirectory(linux) endif() if(FSFW_HAL_ADD_STM32H7) - add_subdirectory(stm32h7) + add_subdirectory(stm32h7) endif() diff --git a/src/fsfw_hal/common/gpio/CMakeLists.txt b/src/fsfw_hal/common/gpio/CMakeLists.txt index 098c05fa..5c81d9cc 100644 --- a/src/fsfw_hal/common/gpio/CMakeLists.txt +++ b/src/fsfw_hal/common/gpio/CMakeLists.txt @@ -1,3 +1 @@ -target_sources(${LIB_FSFW_NAME} PRIVATE - GpioCookie.cpp -) \ No newline at end of file +target_sources(${LIB_FSFW_NAME} PRIVATE GpioCookie.cpp) diff --git a/src/fsfw_hal/devicehandlers/CMakeLists.txt b/src/fsfw_hal/devicehandlers/CMakeLists.txt index 94e67c72..17139416 100644 --- a/src/fsfw_hal/devicehandlers/CMakeLists.txt +++ b/src/fsfw_hal/devicehandlers/CMakeLists.txt @@ -1,5 +1,3 @@ -target_sources(${LIB_FSFW_NAME} PRIVATE - GyroL3GD20Handler.cpp - MgmRM3100Handler.cpp - MgmLIS3MDLHandler.cpp -) +target_sources( + ${LIB_FSFW_NAME} PRIVATE GyroL3GD20Handler.cpp MgmRM3100Handler.cpp + MgmLIS3MDLHandler.cpp) diff --git a/src/fsfw_hal/linux/CMakeLists.txt b/src/fsfw_hal/linux/CMakeLists.txt index f6d1a460..ffa5f5ee 100644 --- a/src/fsfw_hal/linux/CMakeLists.txt +++ b/src/fsfw_hal/linux/CMakeLists.txt @@ -1,25 +1,21 @@ if(FSFW_HAL_ADD_RASPBERRY_PI) - add_subdirectory(rpi) + add_subdirectory(rpi) endif() -target_sources(${LIB_FSFW_NAME} PRIVATE - UnixFileGuard.cpp - CommandExecutor.cpp - utility.cpp -) +target_sources(${LIB_FSFW_NAME} PRIVATE UnixFileGuard.cpp CommandExecutor.cpp + utility.cpp) if(FSFW_HAL_LINUX_ADD_PERIPHERAL_DRIVERS) -if(FSFW_HAL_LINUX_ADD_LIBGPIOD) - add_subdirectory(gpio) -endif() - add_subdirectory(uart) - # Adding those does not really make sense on Apple systems which - # are generally host systems. It won't even compile as the headers - # are missing - if(NOT APPLE) - add_subdirectory(i2c) - add_subdirectory(spi) - endif() + if(FSFW_HAL_LINUX_ADD_LIBGPIOD) + add_subdirectory(gpio) + endif() + add_subdirectory(uart) + # Adding those does not really make sense on Apple systems which are generally + # host systems. It won't even compile as the headers are missing + if(NOT APPLE) + add_subdirectory(i2c) + add_subdirectory(spi) + endif() endif() add_subdirectory(uio) diff --git a/src/fsfw_hal/linux/gpio/CMakeLists.txt b/src/fsfw_hal/linux/gpio/CMakeLists.txt index b1609850..f6e7f2b0 100644 --- a/src/fsfw_hal/linux/gpio/CMakeLists.txt +++ b/src/fsfw_hal/linux/gpio/CMakeLists.txt @@ -1,16 +1,12 @@ -# This abstraction layer requires the gpiod library. You can install this library -# with "sudo apt-get install -y libgpiod-dev". If you are cross-compiling, you need -# to install the package before syncing the sysroot to your host computer. +# This abstraction layer requires the gpiod library. You can install this +# library with "sudo apt-get install -y libgpiod-dev". If you are +# cross-compiling, you need to install the package before syncing the sysroot to +# your host computer. find_library(LIB_GPIO gpiod) if(${LIB_GPIO} MATCHES LIB_GPIO-NOTFOUND) - message(STATUS "gpiod library not found, not linking against it") + message(STATUS "gpiod library not found, not linking against it") else() - target_sources(${LIB_FSFW_NAME} PRIVATE - LinuxLibgpioIF.cpp - ) - target_link_libraries(${LIB_FSFW_NAME} PRIVATE - ${LIB_GPIO} - ) + target_sources(${LIB_FSFW_NAME} PRIVATE LinuxLibgpioIF.cpp) + target_link_libraries(${LIB_FSFW_NAME} PRIVATE ${LIB_GPIO}) endif() - diff --git a/src/fsfw_hal/linux/i2c/CMakeLists.txt b/src/fsfw_hal/linux/i2c/CMakeLists.txt index 3eb0882c..b94bdc99 100644 --- a/src/fsfw_hal/linux/i2c/CMakeLists.txt +++ b/src/fsfw_hal/linux/i2c/CMakeLists.txt @@ -1,8 +1 @@ -target_sources(${LIB_FSFW_NAME} PUBLIC - I2cComIF.cpp - I2cCookie.cpp -) - - - - +target_sources(${LIB_FSFW_NAME} PUBLIC I2cComIF.cpp I2cCookie.cpp) diff --git a/src/fsfw_hal/linux/rpi/CMakeLists.txt b/src/fsfw_hal/linux/rpi/CMakeLists.txt index 47be218c..3a865037 100644 --- a/src/fsfw_hal/linux/rpi/CMakeLists.txt +++ b/src/fsfw_hal/linux/rpi/CMakeLists.txt @@ -1,3 +1 @@ -target_sources(${LIB_FSFW_NAME} PRIVATE - GpioRPi.cpp -) \ No newline at end of file +target_sources(${LIB_FSFW_NAME} PRIVATE GpioRPi.cpp) diff --git a/src/fsfw_hal/linux/spi/CMakeLists.txt b/src/fsfw_hal/linux/spi/CMakeLists.txt index 404e1f47..f242bb3b 100644 --- a/src/fsfw_hal/linux/spi/CMakeLists.txt +++ b/src/fsfw_hal/linux/spi/CMakeLists.txt @@ -1,8 +1 @@ -target_sources(${LIB_FSFW_NAME} PUBLIC - SpiComIF.cpp - SpiCookie.cpp -) - - - - +target_sources(${LIB_FSFW_NAME} PUBLIC SpiComIF.cpp SpiCookie.cpp) diff --git a/src/fsfw_hal/linux/uart/CMakeLists.txt b/src/fsfw_hal/linux/uart/CMakeLists.txt index 21ed0278..9cad62a4 100644 --- a/src/fsfw_hal/linux/uart/CMakeLists.txt +++ b/src/fsfw_hal/linux/uart/CMakeLists.txt @@ -1,4 +1 @@ -target_sources(${LIB_FSFW_NAME} PUBLIC - UartComIF.cpp - UartCookie.cpp -) +target_sources(${LIB_FSFW_NAME} PUBLIC UartComIF.cpp UartCookie.cpp) diff --git a/src/fsfw_hal/linux/uio/CMakeLists.txt b/src/fsfw_hal/linux/uio/CMakeLists.txt index e98a0865..e3498246 100644 --- a/src/fsfw_hal/linux/uio/CMakeLists.txt +++ b/src/fsfw_hal/linux/uio/CMakeLists.txt @@ -1,3 +1 @@ -target_sources(${LIB_FSFW_NAME} PUBLIC - UioMapper.cpp -) +target_sources(${LIB_FSFW_NAME} PUBLIC UioMapper.cpp) diff --git a/src/fsfw_hal/stm32h7/CMakeLists.txt b/src/fsfw_hal/stm32h7/CMakeLists.txt index bae3b1ac..e8843ed3 100644 --- a/src/fsfw_hal/stm32h7/CMakeLists.txt +++ b/src/fsfw_hal/stm32h7/CMakeLists.txt @@ -2,6 +2,4 @@ add_subdirectory(spi) add_subdirectory(gpio) add_subdirectory(devicetest) -target_sources(${LIB_FSFW_NAME} PRIVATE - dma.cpp -) +target_sources(${LIB_FSFW_NAME} PRIVATE dma.cpp) diff --git a/src/fsfw_hal/stm32h7/devicetest/CMakeLists.txt b/src/fsfw_hal/stm32h7/devicetest/CMakeLists.txt index 7bd4c3a9..8e789ddb 100644 --- a/src/fsfw_hal/stm32h7/devicetest/CMakeLists.txt +++ b/src/fsfw_hal/stm32h7/devicetest/CMakeLists.txt @@ -1,3 +1 @@ -target_sources(${LIB_FSFW_NAME} PRIVATE - GyroL3GD20H.cpp -) \ No newline at end of file +target_sources(${LIB_FSFW_NAME} PRIVATE GyroL3GD20H.cpp) diff --git a/src/fsfw_hal/stm32h7/gpio/CMakeLists.txt b/src/fsfw_hal/stm32h7/gpio/CMakeLists.txt index 35245b25..54d76b2d 100644 --- a/src/fsfw_hal/stm32h7/gpio/CMakeLists.txt +++ b/src/fsfw_hal/stm32h7/gpio/CMakeLists.txt @@ -1,3 +1 @@ -target_sources(${LIB_FSFW_NAME} PRIVATE - gpio.cpp -) +target_sources(${LIB_FSFW_NAME} PRIVATE gpio.cpp) diff --git a/src/fsfw_hal/stm32h7/i2c/CMakeLists.txt b/src/fsfw_hal/stm32h7/i2c/CMakeLists.txt index 5ecb0990..a0d48465 100644 --- a/src/fsfw_hal/stm32h7/i2c/CMakeLists.txt +++ b/src/fsfw_hal/stm32h7/i2c/CMakeLists.txt @@ -1,2 +1 @@ -target_sources(${LIB_FSFW_NAME} PRIVATE -) +target_sources(${LIB_FSFW_NAME} PRIVATE) diff --git a/src/fsfw_hal/stm32h7/spi/CMakeLists.txt b/src/fsfw_hal/stm32h7/spi/CMakeLists.txt index aa5541bc..9a98f502 100644 --- a/src/fsfw_hal/stm32h7/spi/CMakeLists.txt +++ b/src/fsfw_hal/stm32h7/spi/CMakeLists.txt @@ -1,9 +1,9 @@ -target_sources(${LIB_FSFW_NAME} PRIVATE - spiCore.cpp - spiDefinitions.cpp - spiInterrupts.cpp - mspInit.cpp - SpiCookie.cpp - SpiComIF.cpp - stm32h743zi.cpp -) +target_sources( + ${LIB_FSFW_NAME} + PRIVATE spiCore.cpp + spiDefinitions.cpp + spiInterrupts.cpp + mspInit.cpp + SpiCookie.cpp + SpiComIF.cpp + stm32h743zi.cpp) diff --git a/src/fsfw_hal/stm32h7/uart/CMakeLists.txt b/src/fsfw_hal/stm32h7/uart/CMakeLists.txt index 5ecb0990..a0d48465 100644 --- a/src/fsfw_hal/stm32h7/uart/CMakeLists.txt +++ b/src/fsfw_hal/stm32h7/uart/CMakeLists.txt @@ -1,2 +1 @@ -target_sources(${LIB_FSFW_NAME} PRIVATE -) +target_sources(${LIB_FSFW_NAME} PRIVATE) diff --git a/src/fsfw_tests/CMakeLists.txt b/src/fsfw_tests/CMakeLists.txt index 5e16e0a7..d161699a 100644 --- a/src/fsfw_tests/CMakeLists.txt +++ b/src/fsfw_tests/CMakeLists.txt @@ -1,7 +1,7 @@ if(FSFW_ADD_INTERNAL_TESTS) - add_subdirectory(internal) + add_subdirectory(internal) endif() if(NOT FSFW_BUILD_TESTS) - add_subdirectory(integration) + add_subdirectory(integration) endif() diff --git a/src/fsfw_tests/integration/assemblies/CMakeLists.txt b/src/fsfw_tests/integration/assemblies/CMakeLists.txt index 22c06600..63a6447a 100644 --- a/src/fsfw_tests/integration/assemblies/CMakeLists.txt +++ b/src/fsfw_tests/integration/assemblies/CMakeLists.txt @@ -1,3 +1 @@ -target_sources(${LIB_FSFW_NAME} PRIVATE - TestAssembly.cpp -) \ No newline at end of file +target_sources(${LIB_FSFW_NAME} PRIVATE TestAssembly.cpp) diff --git a/src/fsfw_tests/integration/controller/CMakeLists.txt b/src/fsfw_tests/integration/controller/CMakeLists.txt index f5655b71..5eeb5c68 100644 --- a/src/fsfw_tests/integration/controller/CMakeLists.txt +++ b/src/fsfw_tests/integration/controller/CMakeLists.txt @@ -1,3 +1 @@ -target_sources(${LIB_FSFW_NAME} PRIVATE - TestController.cpp -) \ No newline at end of file +target_sources(${LIB_FSFW_NAME} PRIVATE TestController.cpp) diff --git a/src/fsfw_tests/integration/devices/CMakeLists.txt b/src/fsfw_tests/integration/devices/CMakeLists.txt index cfd238d2..d5799197 100644 --- a/src/fsfw_tests/integration/devices/CMakeLists.txt +++ b/src/fsfw_tests/integration/devices/CMakeLists.txt @@ -1,5 +1,2 @@ -target_sources(${LIB_FSFW_NAME} PRIVATE - TestCookie.cpp - TestDeviceHandler.cpp - TestEchoComIF.cpp -) +target_sources(${LIB_FSFW_NAME} PRIVATE TestCookie.cpp TestDeviceHandler.cpp + TestEchoComIF.cpp) diff --git a/src/fsfw_tests/integration/task/CMakeLists.txt b/src/fsfw_tests/integration/task/CMakeLists.txt index 4cd481bf..62d5e8ef 100644 --- a/src/fsfw_tests/integration/task/CMakeLists.txt +++ b/src/fsfw_tests/integration/task/CMakeLists.txt @@ -1,3 +1 @@ -target_sources(${LIB_FSFW_NAME} PRIVATE - TestTask.cpp -) \ No newline at end of file +target_sources(${LIB_FSFW_NAME} PRIVATE TestTask.cpp) diff --git a/src/fsfw_tests/internal/CMakeLists.txt b/src/fsfw_tests/internal/CMakeLists.txt index 2a144a9b..c1af5467 100644 --- a/src/fsfw_tests/internal/CMakeLists.txt +++ b/src/fsfw_tests/internal/CMakeLists.txt @@ -1,8 +1,6 @@ -target_sources(${LIB_FSFW_NAME} PRIVATE - InternalUnitTester.cpp - UnittDefinitions.cpp -) +target_sources(${LIB_FSFW_NAME} PRIVATE InternalUnitTester.cpp + UnittDefinitions.cpp) add_subdirectory(osal) add_subdirectory(serialize) -add_subdirectory(globalfunctions) \ No newline at end of file +add_subdirectory(globalfunctions) diff --git a/src/fsfw_tests/internal/globalfunctions/CMakeLists.txt b/src/fsfw_tests/internal/globalfunctions/CMakeLists.txt index cde97734..6e7e58ad 100644 --- a/src/fsfw_tests/internal/globalfunctions/CMakeLists.txt +++ b/src/fsfw_tests/internal/globalfunctions/CMakeLists.txt @@ -1,3 +1 @@ -target_sources(${LIB_FSFW_NAME} PRIVATE - TestArrayPrinter.cpp -) +target_sources(${LIB_FSFW_NAME} PRIVATE TestArrayPrinter.cpp) diff --git a/src/fsfw_tests/internal/osal/CMakeLists.txt b/src/fsfw_tests/internal/osal/CMakeLists.txt index 8d79d759..db1031a0 100644 --- a/src/fsfw_tests/internal/osal/CMakeLists.txt +++ b/src/fsfw_tests/internal/osal/CMakeLists.txt @@ -1,5 +1,2 @@ -target_sources(${LIB_FSFW_NAME} PRIVATE - testMq.cpp - testMutex.cpp - testSemaphore.cpp -) +target_sources(${LIB_FSFW_NAME} PRIVATE testMq.cpp testMutex.cpp + testSemaphore.cpp) diff --git a/src/fsfw_tests/internal/serialize/CMakeLists.txt b/src/fsfw_tests/internal/serialize/CMakeLists.txt index 47e8b538..ee264d9d 100644 --- a/src/fsfw_tests/internal/serialize/CMakeLists.txt +++ b/src/fsfw_tests/internal/serialize/CMakeLists.txt @@ -1,3 +1 @@ -target_sources(${LIB_FSFW_NAME} PRIVATE - IntTestSerialization.cpp -) +target_sources(${LIB_FSFW_NAME} PRIVATE IntTestSerialization.cpp) diff --git a/unittests/tmtcpacket/CMakeLists.txt b/unittests/tmtcpacket/CMakeLists.txt index 958bda40..66eb4976 100644 --- a/unittests/tmtcpacket/CMakeLists.txt +++ b/unittests/tmtcpacket/CMakeLists.txt @@ -1,3 +1,3 @@ target_sources(${FSFW_TEST_TGT} PRIVATE - testCcsds.cpp + testCcsdsReader.cpp ) diff --git a/unittests/tmtcpacket/testCcsds.cpp b/unittests/tmtcpacket/testCcsds.cpp deleted file mode 100644 index 93cea57a..00000000 --- a/unittests/tmtcpacket/testCcsds.cpp +++ /dev/null @@ -1,43 +0,0 @@ -#include -#include - -#include "fsfw/tmtcpacket/SpacePacketCreator.h" -#include "fsfw/tmtcpacket/SpacePacketReader.h" - -TEST_CASE("CCSDS Test", "[ccsds]") { - SpacePacketCreator base = SpacePacketCreator( - ccsds::PacketType::TC, true, 0x02, - ccsds::SequenceFlags::FIRST_SEGMENT, 0x34, 0x16); - - SECTION("Constexpr Helpers") { - REQUIRE(ccsds::getTcSpacePacketIdFromApid(0x22) == 0x1822); - REQUIRE(ccsds::getTmSpacePacketIdFromApid(0x22) == 0x0822); - - REQUIRE(ccsds::getTcSpacePacketIdFromApid(0x7ff) == 0x1fff); - REQUIRE(ccsds::getTmSpacePacketIdFromApid(0x7ff) == 0xfff); - } - - SECTION("Basic Test") { - REQUIRE(base.isValid()); - REQUIRE(base.getApid() == 0x02); - REQUIRE(base.getSequenceFlags() == ccsds::SequenceFlags::FIRST_SEGMENT); - REQUIRE(base.getVersion() == 0b000); - REQUIRE(base.getSequenceCount() == 0x34); - REQUIRE(base.getPacketDataLen() == 0x16); - REQUIRE(base.getPacketType() == ccsds::PacketType::TC); - REQUIRE(base.getPacketId() == 0x1802); - } - - SECTION("Raw Output") { - std::array buf {}; - uint8_t* bufPtr = buf.data(); - size_t serLen = 0; - base.serialize(&bufPtr, &serLen, buf.size(), SerializeIF::Endianness::MACHINE); - REQUIRE(buf[0] == 0x18); - REQUIRE(buf[1] == 0x02); - REQUIRE(buf[2] == 0x40); - REQUIRE(buf[3] == 0x34); - REQUIRE(buf[4] == 0x00); - REQUIRE(buf[5] == 0x16); - } -} diff --git a/unittests/tmtcpacket/testCcsdsReader.cpp b/unittests/tmtcpacket/testCcsdsReader.cpp new file mode 100644 index 00000000..700e9f1e --- /dev/null +++ b/unittests/tmtcpacket/testCcsdsReader.cpp @@ -0,0 +1,82 @@ +#include +#include +#include + +#include "fsfw/tmtcpacket/SpacePacketCreator.h" +#include "fsfw/tmtcpacket/SpacePacketReader.h" + +TEST_CASE("CCSDS Test", "[ccsds]") { + SpacePacketCreator base = SpacePacketCreator( + ccsds::PacketType::TC, true, 0x02, + ccsds::SequenceFlags::FIRST_SEGMENT, 0x34, 0x16); + std::array buf {}; + uint8_t* bufPtr = buf.data(); + size_t serLen = 0; + + SECTION("Constexpr Helpers") { + REQUIRE(ccsds::getTcSpacePacketIdFromApid(0x22) == 0x1822); + REQUIRE(ccsds::getTmSpacePacketIdFromApid(0x22) == 0x0822); + + REQUIRE(ccsds::getTcSpacePacketIdFromApid(0x7ff) == 0x1fff); + REQUIRE(ccsds::getTmSpacePacketIdFromApid(0x7ff) == 0xfff); + } + + SECTION("Basic Test") { + REQUIRE(base.isValid()); + REQUIRE(base.getApid() == 0x02); + REQUIRE(base.getSequenceFlags() == ccsds::SequenceFlags::FIRST_SEGMENT); + REQUIRE(base.getVersion() == 0b000); + REQUIRE(base.getSequenceCount() == 0x34); + REQUIRE(base.getPacketDataLen() == 0x16); + REQUIRE(base.getPacketType() == ccsds::PacketType::TC); + REQUIRE(base.getPacketId() == 0x1802); + } + + SECTION("Raw Output") { + REQUIRE(base.serialize(&bufPtr, &serLen, buf.size()) == HasReturnvaluesIF::RETURN_OK); + // TC, and secondary header flag is set -> 0b0001100 -> 0x18 + REQUIRE(buf[0] == 0x18); + // APID 0x02 + REQUIRE(buf[1] == 0x02); + // Sequence count is one byte value, so the only set bit here is the bit + // from the Sequence flag argument, which is the second bit for + // SequenceFlags.FIRST_SEGMENT + REQUIRE(buf[2] == 0x40); + // Sequence Count specified above + REQUIRE(buf[3] == 0x34); + // This byte and the next byte should be 22 big endian (packet length) + REQUIRE(buf[4] == 0x00); + REQUIRE(buf[5] == 0x16); + } + + SECTION("All Ones Output") { + base.setApid(static_cast(std::pow(2, 11)) - 1); + base.setSeqCount(static_cast(std::pow(2, 14)) - 1); + base.setSeqFlags(ccsds::SequenceFlags::UNSEGMENTED); + base.setDataLen(static_cast(std::pow(2, 16)) - 1); + REQUIRE(base.isValid()); + REQUIRE(base.serialize(&bufPtr, &serLen, buf.size()) == HasReturnvaluesIF::RETURN_OK); + REQUIRE(buf[0] == 0x1F); + REQUIRE(buf[1] == 0xFF); + REQUIRE(buf[2] == 0xFF); + REQUIRE(buf[3] == 0xFF); + REQUIRE(buf[4] == 0xFF); + REQUIRE(buf[5] == 0xFF); + } + + SECTION("Invalid APID") { + SpacePacketCreator invalid = SpacePacketCreator( + PacketId(ccsds::PacketType::TC, true, 0xFFFF), + PacketSeqCtrl(ccsds::SequenceFlags::FIRST_SEGMENT, 0x34), 0x16); + REQUIRE(not invalid.isValid()); + REQUIRE(invalid.serialize(&bufPtr, &serLen, buf.size()) == HasReturnvaluesIF::RETURN_FAILED); + } + + SECTION("Invalid Seq Count") { + SpacePacketCreator invalid = SpacePacketCreator( + PacketId(ccsds::PacketType::TC, true, 0x02), + PacketSeqCtrl(ccsds::SequenceFlags::FIRST_SEGMENT, 0xFFFF), 0x16); + REQUIRE(not invalid.isValid()); + REQUIRE(invalid.serialize(&bufPtr, &serLen, buf.size()) == HasReturnvaluesIF::RETURN_FAILED); + } +} -- 2.43.0 From 3d2af203f2e365df7f64ce28853d540c5c41ec81 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Mon, 18 Jul 2022 16:18:04 +0200 Subject: [PATCH 009/108] finished creator unittests --- unittests/cfdp/testCfdp.cpp | 2 +- unittests/datapoollocal/DataSetTest.cpp | 2 +- .../datapoollocal/LocalPoolManagerTest.cpp | 2 +- .../datapoollocal/LocalPoolVariableTest.cpp | 2 +- .../datapoollocal/LocalPoolVectorTest.cpp | 2 +- .../devicehandler/TestDeviceHandlerBase.cpp | 2 +- unittests/globalfunctions/testCRC.cpp | 2 +- unittests/globalfunctions/testDleEncoder.cpp | 2 +- .../TestInternalErrorReporter.cpp | 2 +- unittests/mocks/MessageQueueMockBase.h | 2 +- unittests/power/testPowerSwitcher.cpp | 2 +- unittests/testVersion.cpp | 5 +-- unittests/tmtcpacket/CMakeLists.txt | 2 +- ...estCcsdsReader.cpp => TestCcsdsReader.cpp} | 44 ++++++++++++++----- .../{PusTmTest.cpp => TestPusTm.cpp} | 0 15 files changed, 47 insertions(+), 26 deletions(-) rename unittests/tmtcpacket/{testCcsdsReader.cpp => TestCcsdsReader.cpp} (65%) rename unittests/tmtcpacket/{PusTmTest.cpp => TestPusTm.cpp} (100%) diff --git a/unittests/cfdp/testCfdp.cpp b/unittests/cfdp/testCfdp.cpp index 6ca95fbc..78ef618b 100644 --- a/unittests/cfdp/testCfdp.cpp +++ b/unittests/cfdp/testCfdp.cpp @@ -2,6 +2,7 @@ #include #include +#include "CatchDefinitions.h" #include "fsfw/cfdp/FileSize.h" #include "fsfw/cfdp/pdu/FileDirectiveDeserializer.h" #include "fsfw/cfdp/pdu/FileDirectiveSerializer.h" @@ -9,7 +10,6 @@ #include "fsfw/cfdp/pdu/HeaderSerializer.h" #include "fsfw/globalfunctions/arrayprinter.h" #include "fsfw/serialize/SerializeAdapter.h" -#include "CatchDefinitions.h" TEST_CASE("CFDP Base", "[CfdpBase]") { using namespace cfdp; diff --git a/unittests/datapoollocal/DataSetTest.cpp b/unittests/datapoollocal/DataSetTest.cpp index c56ed768..c9f023ef 100644 --- a/unittests/datapoollocal/DataSetTest.cpp +++ b/unittests/datapoollocal/DataSetTest.cpp @@ -8,8 +8,8 @@ #include #include -#include "LocalPoolOwnerBase.h" #include "CatchDefinitions.h" +#include "LocalPoolOwnerBase.h" #include "tests/TestsConfig.h" TEST_CASE("DataSetTest", "[DataSetTest]") { diff --git a/unittests/datapoollocal/LocalPoolManagerTest.cpp b/unittests/datapoollocal/LocalPoolManagerTest.cpp index 019c9b59..58a6065e 100644 --- a/unittests/datapoollocal/LocalPoolManagerTest.cpp +++ b/unittests/datapoollocal/LocalPoolManagerTest.cpp @@ -11,8 +11,8 @@ #include #include -#include "LocalPoolOwnerBase.h" #include "CatchDefinitions.h" +#include "LocalPoolOwnerBase.h" TEST_CASE("LocalPoolManagerTest", "[LocManTest]") { LocalPoolOwnerBase* poolOwner = diff --git a/unittests/datapoollocal/LocalPoolVariableTest.cpp b/unittests/datapoollocal/LocalPoolVariableTest.cpp index 86bd6a1e..3479cdbe 100644 --- a/unittests/datapoollocal/LocalPoolVariableTest.cpp +++ b/unittests/datapoollocal/LocalPoolVariableTest.cpp @@ -3,8 +3,8 @@ #include -#include "LocalPoolOwnerBase.h" #include "CatchDefinitions.h" +#include "LocalPoolOwnerBase.h" #include "tests/TestsConfig.h" TEST_CASE("LocalPoolVariable", "[LocPoolVarTest]") { diff --git a/unittests/datapoollocal/LocalPoolVectorTest.cpp b/unittests/datapoollocal/LocalPoolVectorTest.cpp index 3a06c826..2235ad39 100644 --- a/unittests/datapoollocal/LocalPoolVectorTest.cpp +++ b/unittests/datapoollocal/LocalPoolVectorTest.cpp @@ -3,8 +3,8 @@ #include -#include "LocalPoolOwnerBase.h" #include "CatchDefinitions.h" +#include "LocalPoolOwnerBase.h" #include "tests/TestsConfig.h" TEST_CASE("LocalPoolVector", "[LocPoolVecTest]") { diff --git a/unittests/devicehandler/TestDeviceHandlerBase.cpp b/unittests/devicehandler/TestDeviceHandlerBase.cpp index 328bc4dc..e8fdd17b 100644 --- a/unittests/devicehandler/TestDeviceHandlerBase.cpp +++ b/unittests/devicehandler/TestDeviceHandlerBase.cpp @@ -2,9 +2,9 @@ #include "ComIFMock.h" #include "DeviceFdirMock.h" -#include "devicehandler/CookieIFMock.h" #include "DeviceHandlerCommander.h" #include "DeviceHandlerMock.h" +#include "devicehandler/CookieIFMock.h" #include "objects/systemObjectList.h" TEST_CASE("Device Handler Base", "[DeviceHandlerBase]") { diff --git a/unittests/globalfunctions/testCRC.cpp b/unittests/globalfunctions/testCRC.cpp index 884bd281..2b6de4db 100644 --- a/unittests/globalfunctions/testCRC.cpp +++ b/unittests/globalfunctions/testCRC.cpp @@ -1,8 +1,8 @@ #include +#include "CatchDefinitions.h" #include "catch2/catch_test_macros.hpp" #include "fsfw/globalfunctions/CRC.h" -#include "CatchDefinitions.h" TEST_CASE("CRC", "[CRC]") { std::array testData = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}; diff --git a/unittests/globalfunctions/testDleEncoder.cpp b/unittests/globalfunctions/testDleEncoder.cpp index 1ccaddb5..0c707f4c 100644 --- a/unittests/globalfunctions/testDleEncoder.cpp +++ b/unittests/globalfunctions/testDleEncoder.cpp @@ -1,8 +1,8 @@ #include +#include "CatchDefinitions.h" #include "catch2/catch_test_macros.hpp" #include "fsfw/globalfunctions/DleEncoder.h" -#include "CatchDefinitions.h" const std::vector TEST_ARRAY_0 = {0, 0, 0, 0, 0}; const std::vector TEST_ARRAY_1 = {0, DleEncoder::DLE_CHAR, 5}; diff --git a/unittests/internalerror/TestInternalErrorReporter.cpp b/unittests/internalerror/TestInternalErrorReporter.cpp index b52c5336..2b999fae 100644 --- a/unittests/internalerror/TestInternalErrorReporter.cpp +++ b/unittests/internalerror/TestInternalErrorReporter.cpp @@ -8,11 +8,11 @@ #include #include +#include "CatchDefinitions.h" #include "fsfw/action/ActionMessage.h" #include "fsfw/ipc/CommandMessage.h" #include "fsfw/ipc/MessageQueueMessage.h" #include "fsfw/objectmanager/frameworkObjects.h" -#include "CatchDefinitions.h" #include "mocks/PeriodicTaskIFMock.h" TEST_CASE("Internal Error Reporter", "[TestInternalError]") { diff --git a/unittests/mocks/MessageQueueMockBase.h b/unittests/mocks/MessageQueueMockBase.h index 60a942d9..d3323186 100644 --- a/unittests/mocks/MessageQueueMockBase.h +++ b/unittests/mocks/MessageQueueMockBase.h @@ -4,11 +4,11 @@ #include #include +#include "CatchDefinitions.h" #include "fsfw/ipc/CommandMessage.h" #include "fsfw/ipc/MessageQueueBase.h" #include "fsfw/ipc/MessageQueueIF.h" #include "fsfw/ipc/MessageQueueMessage.h" -#include "CatchDefinitions.h" class MessageQueueMockBase : public MessageQueueBase { public: diff --git a/unittests/power/testPowerSwitcher.cpp b/unittests/power/testPowerSwitcher.cpp index cf2f2148..f6a24583 100644 --- a/unittests/power/testPowerSwitcher.cpp +++ b/unittests/power/testPowerSwitcher.cpp @@ -1,9 +1,9 @@ #include #include -#include "mocks/PowerSwitcherMock.h" #include +#include "mocks/PowerSwitcherMock.h" #include "objects/systemObjectList.h" TEST_CASE("Power Switcher", "[power-switcher]") { diff --git a/unittests/testVersion.cpp b/unittests/testVersion.cpp index e0b9897b..2f487031 100644 --- a/unittests/testVersion.cpp +++ b/unittests/testVersion.cpp @@ -1,10 +1,9 @@ -#include "fsfw/version.h" - #include -#include "fsfw/serviceinterface.h" #include "CatchDefinitions.h" +#include "fsfw/serviceinterface.h" +#include "fsfw/version.h" TEST_CASE("Version API Tests", "[TestVersionAPI]") { // Check that major version is non-zero diff --git a/unittests/tmtcpacket/CMakeLists.txt b/unittests/tmtcpacket/CMakeLists.txt index 66eb4976..ea3eec21 100644 --- a/unittests/tmtcpacket/CMakeLists.txt +++ b/unittests/tmtcpacket/CMakeLists.txt @@ -1,3 +1,3 @@ target_sources(${FSFW_TEST_TGT} PRIVATE - testCcsdsReader.cpp + TestCcsdsReader.cpp ) diff --git a/unittests/tmtcpacket/testCcsdsReader.cpp b/unittests/tmtcpacket/TestCcsdsReader.cpp similarity index 65% rename from unittests/tmtcpacket/testCcsdsReader.cpp rename to unittests/tmtcpacket/TestCcsdsReader.cpp index 700e9f1e..79d86eb1 100644 --- a/unittests/tmtcpacket/testCcsdsReader.cpp +++ b/unittests/tmtcpacket/TestCcsdsReader.cpp @@ -1,15 +1,14 @@ #include -#include #include +#include #include "fsfw/tmtcpacket/SpacePacketCreator.h" #include "fsfw/tmtcpacket/SpacePacketReader.h" TEST_CASE("CCSDS Test", "[ccsds]") { - SpacePacketCreator base = SpacePacketCreator( - ccsds::PacketType::TC, true, 0x02, - ccsds::SequenceFlags::FIRST_SEGMENT, 0x34, 0x16); - std::array buf {}; + SpacePacketCreator base = SpacePacketCreator(ccsds::PacketType::TC, true, 0x02, + ccsds::SequenceFlags::FIRST_SEGMENT, 0x34, 0x16); + std::array buf{}; uint8_t* bufPtr = buf.data(); size_t serLen = 0; @@ -30,6 +29,14 @@ TEST_CASE("CCSDS Test", "[ccsds]") { REQUIRE(base.getPacketDataLen() == 0x16); REQUIRE(base.getPacketType() == ccsds::PacketType::TC); REQUIRE(base.getPacketId() == 0x1802); + REQUIRE(base.getSerializedSize() == 6); + } + + SECTION("Deserialization Fails") { + serLen = 6; + const uint8_t* readOnlyPtr = buf.data(); + REQUIRE(base.deSerialize(&readOnlyPtr, &serLen, SerializeIF::Endianness::BIG) == + HasReturnvaluesIF::RETURN_FAILED); } SECTION("Raw Output") { @@ -65,18 +72,33 @@ TEST_CASE("CCSDS Test", "[ccsds]") { } SECTION("Invalid APID") { - SpacePacketCreator invalid = SpacePacketCreator( - PacketId(ccsds::PacketType::TC, true, 0xFFFF), - PacketSeqCtrl(ccsds::SequenceFlags::FIRST_SEGMENT, 0x34), 0x16); + SpacePacketCreator invalid = + SpacePacketCreator(PacketId(ccsds::PacketType::TC, true, 0xFFFF), + PacketSeqCtrl(ccsds::SequenceFlags::FIRST_SEGMENT, 0x34), 0x16); REQUIRE(not invalid.isValid()); REQUIRE(invalid.serialize(&bufPtr, &serLen, buf.size()) == HasReturnvaluesIF::RETURN_FAILED); } SECTION("Invalid Seq Count") { - SpacePacketCreator invalid = SpacePacketCreator( - PacketId(ccsds::PacketType::TC, true, 0x02), - PacketSeqCtrl(ccsds::SequenceFlags::FIRST_SEGMENT, 0xFFFF), 0x16); + SpacePacketCreator invalid = + SpacePacketCreator(PacketId(ccsds::PacketType::TC, true, 0x02), + PacketSeqCtrl(ccsds::SequenceFlags::FIRST_SEGMENT, 0xFFFF), 0x16); REQUIRE(not invalid.isValid()); REQUIRE(invalid.serialize(&bufPtr, &serLen, buf.size()) == HasReturnvaluesIF::RETURN_FAILED); } + + SECTION("Invalid Buf Size 1") { + serLen = 2; + REQUIRE(base.serialize(&bufPtr, &serLen, buf.size()) == SerializeIF::BUFFER_TOO_SHORT); + } + + SECTION("Invalid Buf Size 2") { + serLen = 4; + REQUIRE(base.serialize(&bufPtr, &serLen, buf.size()) == SerializeIF::BUFFER_TOO_SHORT); + } + + SECTION("Invalid Buf Size 3") { + serLen = 6; + REQUIRE(base.serialize(&bufPtr, &serLen, buf.size()) == SerializeIF::BUFFER_TOO_SHORT); + } } diff --git a/unittests/tmtcpacket/PusTmTest.cpp b/unittests/tmtcpacket/TestPusTm.cpp similarity index 100% rename from unittests/tmtcpacket/PusTmTest.cpp rename to unittests/tmtcpacket/TestPusTm.cpp -- 2.43.0 From 95b476d4bd936165c2441437c584b6c792ec70ad Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Mon, 18 Jul 2022 16:21:00 +0200 Subject: [PATCH 010/108] start ccsds reader unittests --- CMakeLists.txt | 2 +- unittests/tmtcpacket/CMakeLists.txt | 3 ++- .../{TestCcsdsReader.cpp => testCcsdsCreator.cpp} | 4 ++-- unittests/tmtcpacket/testCcsdsReader.cpp | 6 ++++++ unittests/tmtcpacket/{TestPusTm.cpp => testPusTm.cpp} | 0 5 files changed, 11 insertions(+), 4 deletions(-) rename unittests/tmtcpacket/{TestCcsdsReader.cpp => testCcsdsCreator.cpp} (97%) create mode 100644 unittests/tmtcpacket/testCcsdsReader.cpp rename unittests/tmtcpacket/{TestPusTm.cpp => testPusTm.cpp} (100%) diff --git a/CMakeLists.txt b/CMakeLists.txt index 98a84cb6..237f186a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -175,7 +175,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}) + add_executable(${FSFW_TEST_TGT} unittests/tmtcpacket/testCcsdsReader.cpp) if(IPO_SUPPORTED AND FSFW_ENABLE_IPO) set_property(TARGET ${FSFW_TEST_TGT} PROPERTY INTERPROCEDURAL_OPTIMIZATION TRUE) diff --git a/unittests/tmtcpacket/CMakeLists.txt b/unittests/tmtcpacket/CMakeLists.txt index ea3eec21..9a08868e 100644 --- a/unittests/tmtcpacket/CMakeLists.txt +++ b/unittests/tmtcpacket/CMakeLists.txt @@ -1,3 +1,4 @@ target_sources(${FSFW_TEST_TGT} PRIVATE - TestCcsdsReader.cpp + testCcsdsCreator.cpp + testCcsdsReader.cpp ) diff --git a/unittests/tmtcpacket/TestCcsdsReader.cpp b/unittests/tmtcpacket/testCcsdsCreator.cpp similarity index 97% rename from unittests/tmtcpacket/TestCcsdsReader.cpp rename to unittests/tmtcpacket/testCcsdsCreator.cpp index 79d86eb1..fbd73b10 100644 --- a/unittests/tmtcpacket/TestCcsdsReader.cpp +++ b/unittests/tmtcpacket/testCcsdsCreator.cpp @@ -3,9 +3,9 @@ #include #include "fsfw/tmtcpacket/SpacePacketCreator.h" -#include "fsfw/tmtcpacket/SpacePacketReader.h" -TEST_CASE("CCSDS Test", "[ccsds]") { + +TEST_CASE("CCSDS Creator", "[ccsds-creator]") { SpacePacketCreator base = SpacePacketCreator(ccsds::PacketType::TC, true, 0x02, ccsds::SequenceFlags::FIRST_SEGMENT, 0x34, 0x16); std::array buf{}; diff --git a/unittests/tmtcpacket/testCcsdsReader.cpp b/unittests/tmtcpacket/testCcsdsReader.cpp new file mode 100644 index 00000000..d63f4cf0 --- /dev/null +++ b/unittests/tmtcpacket/testCcsdsReader.cpp @@ -0,0 +1,6 @@ +#include +#include "fsfw/tmtcpacket/SpacePacketReader.h" + +TEST_CASE("CCSDS Reader", "[ccsds-reader]") { + +} \ No newline at end of file diff --git a/unittests/tmtcpacket/TestPusTm.cpp b/unittests/tmtcpacket/testPusTm.cpp similarity index 100% rename from unittests/tmtcpacket/TestPusTm.cpp rename to unittests/tmtcpacket/testPusTm.cpp -- 2.43.0 From 5fffbd4a905494303efba9790ca67e4cf4e5c0ef Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Mon, 18 Jul 2022 18:36:41 +0200 Subject: [PATCH 011/108] start PUS TC refactoring --- CMakeLists.txt | 4 +- src/fsfw/serialize.h | 16 +- src/fsfw/tcdistribution/TcPacketCheckPUS.cpp | 2 +- src/fsfw/tmtcpacket/SpacePacketIF.h | 11 ++ src/fsfw/tmtcpacket/SpacePacketReader.cpp | 48 ------ src/fsfw/tmtcpacket/SpacePacketReader.h | 55 ------- src/fsfw/tmtcpacket/pus/tc/CMakeLists.txt | 5 +- ...acketDeserializer.cpp => PusTcCreator.cpp} | 2 +- ...{TcPacketDeserializer.h => PusTcCreator.h} | 4 +- src/fsfw/tmtcpacket/pus/tc/PusTcIF.h | 53 ++++-- src/fsfw/tmtcpacket/pus/tc/PusTcReader.cpp | 47 ++++++ src/fsfw/tmtcpacket/pus/tc/PusTcReader.h | 82 ++++++++++ src/fsfw/tmtcpacket/pus/tc/TcPacketPus.h | 31 +--- .../tmtcpacket/pus/tc/TcPacketPusBase.cpp | 20 --- src/fsfw/tmtcpacket/pus/tc/TcPacketPusBase.h | 151 ------------------ .../tmtcpacket/pus/tc/TcPacketStoredBase.h | 1 + src/fsfw/tmtcpacket/pus/tc/TcPacketStoredIF.h | 2 +- src/fsfw/tmtcpacket/pus/tm/CMakeLists.txt | 9 +- src/fsfw/tmtcpacket/pus/tm/TmPacketPusA.cpp | 68 -------- src/fsfw/tmtcpacket/pus/tm/TmPacketPusA.h | 129 --------------- .../tmtcpacket/pus/tm/TmPacketStoredBase.h | 1 - .../tmtcpacket/pus/tm/TmPacketStoredPusA.cpp | 73 --------- .../tmtcpacket/pus/tm/TmPacketStoredPusA.h | 69 -------- src/fsfw/tmtcservices/PusVerificationReport.h | 2 +- unittests/tmtcpacket/testCcsdsCreator.cpp | 1 - unittests/tmtcpacket/testCcsdsReader.cpp | 5 +- 26 files changed, 213 insertions(+), 678 deletions(-) rename src/fsfw/tmtcpacket/pus/tc/{TcPacketDeserializer.cpp => PusTcCreator.cpp} (71%) rename src/fsfw/tmtcpacket/pus/tc/{TcPacketDeserializer.h => PusTcCreator.h} (64%) create mode 100644 src/fsfw/tmtcpacket/pus/tc/PusTcReader.cpp create mode 100644 src/fsfw/tmtcpacket/pus/tc/PusTcReader.h delete mode 100644 src/fsfw/tmtcpacket/pus/tc/TcPacketPusBase.cpp delete mode 100644 src/fsfw/tmtcpacket/pus/tc/TcPacketPusBase.h delete mode 100644 src/fsfw/tmtcpacket/pus/tm/TmPacketPusA.cpp delete mode 100644 src/fsfw/tmtcpacket/pus/tm/TmPacketPusA.h delete mode 100644 src/fsfw/tmtcpacket/pus/tm/TmPacketStoredPusA.cpp delete mode 100644 src/fsfw/tmtcpacket/pus/tm/TmPacketStoredPusA.h diff --git a/CMakeLists.txt b/CMakeLists.txt index 237f186a..5601d202 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -136,8 +136,8 @@ set(FSFW_DUMMY_TGT fsfw-dummy) add_library( ${LIB_FSFW_NAME} src/fsfw/tmtcpacket/SpacePacketIF.h - src/fsfw/tmtcpacket/pus/tc/TcPacketDeserializer.h - src/fsfw/tmtcpacket/pus/tc/TcPacketDeserializer.cpp + 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) diff --git a/src/fsfw/serialize.h b/src/fsfw/serialize.h index edd7c9c7..b74c3c32 100644 --- a/src/fsfw/serialize.h +++ b/src/fsfw/serialize.h @@ -1,10 +1,10 @@ -#ifndef FSFW_INC_FSFW_SERIALIZE_H_ -#define FSFW_INC_FSFW_SERIALIZE_H_ +#ifndef FSFW_SERIALIZE_H_ +#define FSFW_SERIALIZE_H_ -#include "src/core/serialize/EndianConverter.h" -#include "src/core/serialize/SerialArrayListAdapter.h" -#include "src/core/serialize/SerialBufferAdapter.h" -#include "src/core/serialize/SerialLinkedListAdapter.h" -#include "src/core/serialize/SerializeElement.h" +#include "serialize/EndianConverter.h" +#include "serialize/SerialArrayListAdapter.h" +#include "serialize/SerialBufferAdapter.h" +#include "serialize/SerialLinkedListAdapter.h" +#include "serialize/SerializeElement.h" -#endif /* FSFW_INC_FSFW_SERIALIZE_H_ */ +#endif /* FSFW_SERIALIZE_H_ */ diff --git a/src/fsfw/tcdistribution/TcPacketCheckPUS.cpp b/src/fsfw/tcdistribution/TcPacketCheckPUS.cpp index 304c644a..963bece7 100644 --- a/src/fsfw/tcdistribution/TcPacketCheckPUS.cpp +++ b/src/fsfw/tcdistribution/TcPacketCheckPUS.cpp @@ -3,7 +3,7 @@ #include "fsfw/globalfunctions/CRC.h" #include "fsfw/serviceinterface/ServiceInterface.h" #include "fsfw/storagemanager/StorageManagerIF.h" -#include "fsfw/tmtcpacket/pus/tc/TcPacketPusBase.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" diff --git a/src/fsfw/tmtcpacket/SpacePacketIF.h b/src/fsfw/tmtcpacket/SpacePacketIF.h index 291ba8f9..1b2bfb90 100644 --- a/src/fsfw/tmtcpacket/SpacePacketIF.h +++ b/src/fsfw/tmtcpacket/SpacePacketIF.h @@ -3,6 +3,8 @@ #include +#include "ccsds_header.h" + namespace ccsds { enum PacketType : uint8_t { TM = 0, TC = 1 }; @@ -35,6 +37,15 @@ constexpr uint16_t getTmSpacePacketIdFromApid(uint16_t apid, bool secondaryHeade class SpacePacketIF { public: + /** + * This definition defines the CRC size in byte. + */ + static const uint8_t CRC_SIZE = 2; + /** + * This is the minimum size of a SpacePacket. + */ + static const uint16_t MINIMUM_SIZE = sizeof(CCSDSPrimaryHeader) + CRC_SIZE; + virtual ~SpacePacketIF() = default; /** diff --git a/src/fsfw/tmtcpacket/SpacePacketReader.cpp b/src/fsfw/tmtcpacket/SpacePacketReader.cpp index a1bcd465..cdb00082 100644 --- a/src/fsfw/tmtcpacket/SpacePacketReader.cpp +++ b/src/fsfw/tmtcpacket/SpacePacketReader.cpp @@ -10,58 +10,10 @@ SpacePacketReader::SpacePacketReader(const uint8_t* setAddress) { SpacePacketReader::~SpacePacketReader() = default; -ReturnValue_t SpacePacketReader::initSpacePacketHeader(bool isTelecommand, bool hasSecondaryHeader, - uint16_t apid, uint16_t sequenceCount) { - if (data == nullptr) { -#if FSFW_VERBOSE_LEVEL >= 1 -#if FSFW_CPP_OSTREAM_ENABLED == 1 - sif::warning << "SpacePacketBase::initSpacePacketHeader: Data pointer is invalid" << std::endl; -#else - sif::printWarning("SpacePacketBase::initSpacePacketHeader: Data pointer is invalid!\n"); -#endif -#endif - return HasReturnvaluesIF::RETURN_FAILED; - } - // reset header to zero: - memset(data, 0, sizeof(this->data->header)); - // Set TC/TM bit. - data->header.packetIdHAndVersion = ((isTelecommand ? 1 : 0)) << 4; - // Set secondaryHeader bit - data->header.packetIdHAndVersion |= ((hasSecondaryHeader ? 1 : 0)) << 3; - this->setApid(apid); - // Always initialize as standalone packets. - data->header.packetSeqCtrlH = 0b11000000; - setPacketSequenceCount(sequenceCount); - return HasReturnvaluesIF::RETURN_OK; -} - inline uint16_t SpacePacketReader::getPacketId() const { return ((this->data->header.packetIdHAndVersion) << 8) + this->data->header.packetIdL; } -void SpacePacketReader::setApid(uint16_t setAPID) { - // Use first three bits of new APID, but keep rest of packet id as it was (see specification). - this->data->header.packetIdHAndVersion = - (this->data->header.packetIdHAndVersion & 0b11111000) | ((setAPID & 0x0700) >> 8); - this->data->header.packetIdL = (setAPID & 0x00FF); -} - -void SpacePacketReader::setSequenceFlags(uint8_t sequenceflags) { - this->data->header.packetSeqCtrlH &= 0x3F; - this->data->header.packetSeqCtrlH |= sequenceflags << 6; -} - -void SpacePacketReader::setPacketSequenceCount(uint16_t new_count) { - this->data->header.packetSeqCtrlH = (this->data->header.packetSeqCtrlH & 0b11000000) | - (((new_count % ccsds::LIMIT_SEQUENCE_COUNT) & 0x3F00) >> 8); - this->data->header.packetSeqCtrlL = ((new_count % ccsds::LIMIT_SEQUENCE_COUNT) & 0x00FF); -} - -void SpacePacketReader::setPacketDataLength(uint16_t new_length) { - this->data->header.packetLenH = ((new_length & 0xFF00) >> 8); - this->data->header.packetLenL = (new_length & 0x00FF); -} - 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; diff --git a/src/fsfw/tmtcpacket/SpacePacketReader.h b/src/fsfw/tmtcpacket/SpacePacketReader.h index 7fc88577..81151fab 100644 --- a/src/fsfw/tmtcpacket/SpacePacketReader.h +++ b/src/fsfw/tmtcpacket/SpacePacketReader.h @@ -19,16 +19,6 @@ * standards. */ -/** - * This struct defines the data structure of a Space Packet when accessed - * via a pointer. - * @ingroup tmtcpackets - */ -struct SpacePacketPointer { - CCSDSPrimaryHeader header; - uint8_t packet_data; -}; - /** * This class is the basic data handler for any CCSDS Space Packet * compatible Telecommand and Telemetry packet. @@ -50,16 +40,6 @@ class SpacePacketReader : public SpacePacketIF, public RedirectableDataPointerIF SpacePacketPointer* data; public: - /** - * This definition defines the CRC size in byte. - */ - static const uint8_t CRC_SIZE = 2; - /** - * This is the minimum size of a SpacePacket. - */ - static const uint16_t MINIMUM_SIZE = sizeof(CCSDSPrimaryHeader) + CRC_SIZE; - SpacePacketReader(uint16_t apid, ccsds::PacketType packetType, bool secHeader, uint16_t seqCount, - uint16_t dataLen); /** * This is the default constructor. * It sets its internal data pointer to the address passed. @@ -71,45 +51,10 @@ class SpacePacketReader : public SpacePacketIF, public RedirectableDataPointerIF */ ~SpacePacketReader() override; - ReturnValue_t initSpacePacketHeader(bool isTelecommand, bool hasSecondaryHeader, uint16_t apid, - uint16_t sequenceCount = 0); - [[nodiscard]] uint16_t getPacketId() const override; [[nodiscard]] uint16_t getPacketSeqCtrl() const override; [[nodiscard]] uint16_t getPacketDataLen() const override; - /** - * Sets the APID of a packet, which are the lowest 11 bit of the packet - * id. - * @param The APID to set. The highest five bits of the parameter are - * ignored. - */ - void setApid(uint16_t setAPID); - - /** - * Sets the sequence flags of a packet, which are bit 17 and 18 in the space packet header. - * @param The sequence flags to set - */ - void setSequenceFlags(uint8_t sequenceflags); - - /** - * Sets the packet sequence count, which are the lowest 14 bit of the - * packet sequence control field. - * setCount is modulo-divided by \c LIMIT_SEQUENCE_COUNT to avoid overflows. - * @param setCount The value to set the count to. - */ - void setPacketSequenceCount(uint16_t setCount); - - /** - * Sets the packet data length, which is the fifth and sixth byte of the - * CCSDS Primary Header. - * @param setLength The value of the length to set. It must fit the true - * CCSDS packet data length . The packet data length is - * the size of every kind of data \b after the CCSDS - * Primary Header \b -1. - */ - void setPacketDataLength(uint16_t setLength); - // Helper methods: /** * This method returns a raw uint8_t pointer to the packet. diff --git a/src/fsfw/tmtcpacket/pus/tc/CMakeLists.txt b/src/fsfw/tmtcpacket/pus/tc/CMakeLists.txt index 09c63bfd..c37c2c55 100644 --- a/src/fsfw/tmtcpacket/pus/tc/CMakeLists.txt +++ b/src/fsfw/tmtcpacket/pus/tc/CMakeLists.txt @@ -1,3 +1,4 @@ target_sources( - ${LIB_FSFW_NAME} PRIVATE TcPacketPusBase.cpp TcPacketPus.cpp - TcPacketStoredBase.cpp TcPacketStoredPus.cpp) + ${LIB_FSFW_NAME} + PRIVATE PusTcReader.cpp TcPacketPus.cpp PusTcReader.cpp PusTcCreator.cpp + TcPacketStoredBase.cpp TcPacketStoredPus.cpp) diff --git a/src/fsfw/tmtcpacket/pus/tc/TcPacketDeserializer.cpp b/src/fsfw/tmtcpacket/pus/tc/PusTcCreator.cpp similarity index 71% rename from src/fsfw/tmtcpacket/pus/tc/TcPacketDeserializer.cpp rename to src/fsfw/tmtcpacket/pus/tc/PusTcCreator.cpp index a93db348..c73f7a93 100644 --- a/src/fsfw/tmtcpacket/pus/tc/TcPacketDeserializer.cpp +++ b/src/fsfw/tmtcpacket/pus/tc/PusTcCreator.cpp @@ -1,3 +1,3 @@ -#include "TcPacketDeserializer.h" +#include "PusTcCreator.h" TcPacketDeserializer::TcPacketDeserializer(const uint8_t *data, size_t maxSize) {} diff --git a/src/fsfw/tmtcpacket/pus/tc/TcPacketDeserializer.h b/src/fsfw/tmtcpacket/pus/tc/PusTcCreator.h similarity index 64% rename from src/fsfw/tmtcpacket/pus/tc/TcPacketDeserializer.h rename to src/fsfw/tmtcpacket/pus/tc/PusTcCreator.h index 1e2e7bba..275cc28f 100644 --- a/src/fsfw/tmtcpacket/pus/tc/TcPacketDeserializer.h +++ b/src/fsfw/tmtcpacket/pus/tc/PusTcCreator.h @@ -4,9 +4,9 @@ #include "fsfw/tmtcpacket/RedirectableDataPointerIF.h" #include "fsfw/tmtcpacket/SpacePacketIF.h" -class TcPacketDeserializer : public SpacePacketIF, public RedirectableDataPointerIF { +class PusTcCreator : public SpacePacketIF { public: - TcPacketDeserializer(const uint8_t* data, size_t maxSize); + PusTcCreator(const uint8_t* data, size_t maxSize); private: }; diff --git a/src/fsfw/tmtcpacket/pus/tc/PusTcIF.h b/src/fsfw/tmtcpacket/pus/tc/PusTcIF.h index 3a2eaddc..54afd946 100644 --- a/src/fsfw/tmtcpacket/pus/tc/PusTcIF.h +++ b/src/fsfw/tmtcpacket/pus/tc/PusTcIF.h @@ -3,17 +3,50 @@ #include -class PusTcIF { - public: - virtual ~PusTcIF() = default; +#include "TcPacketPus.h" + +namespace ecss { + +enum AckField { + //! No acknowledgements are expected. + ACK_NONE = 0b0000, + //! Acknowledgements on acceptance are expected. + ACK_ACCEPTANCE = 0b0001, + //! Acknowledgements on start are expected. + ACK_START = 0b0010, + //! Acknowledgements on step are expected. + ACK_STEP = 0b0100, + //! Acknowledgement on completion are expected. + ACK_COMPLETION = 0b1000 +}; + +static constexpr uint8_t ACK_ALL = ACK_ACCEPTANCE | ACK_START | ACK_STEP | ACK_COMPLETION; + +/** + * This struct defines a byte-wise structured PUS C ata Field Header. + * Any optional fields in the header must be added or removed here. + * Currently, the Source Id field is present with one byte. + * No spare byte support for now. + * @ingroup tmtcpackets + */ +struct PusTcDataFieldHeader { + // Version and ACK byte, Service Byte, Subservice Byte, 2 byte Source ID + static constexpr size_t MIN_LEN = 5; + uint8_t pusVersion; + uint8_t ackFlags; + uint8_t serviceType; + uint8_t serviceSubtype; + uint16_t sourceId; +}; + +} // namespace ecss + +class PusTcIF : public SpacePacketIF { + public: + ~PusTcIF() override = default; + static const uint16_t MIN_LEN = + (sizeof(CCSDSPrimaryHeader) + ecss::PusTcDataFieldHeader::MIN_LEN + 2); - /** - * This command returns the CCSDS Secondary Header Flag. - * It shall always be zero for PUS Packets. This is the - * highest bit of the first byte of the Data Field Header. - * @return the CCSDS Secondary Header Flag - */ - [[nodiscard]] virtual uint8_t getSecondaryHeaderFlag() const = 0; /** * This command returns the TC Packet PUS Version Number. * The version number of ECSS PUS 2003 is 1. diff --git a/src/fsfw/tmtcpacket/pus/tc/PusTcReader.cpp b/src/fsfw/tmtcpacket/pus/tc/PusTcReader.cpp new file mode 100644 index 00000000..e2a66e73 --- /dev/null +++ b/src/fsfw/tmtcpacket/pus/tc/PusTcReader.cpp @@ -0,0 +1,47 @@ +#include "PusTcReader.h" + +#include + +#include "fsfw/globalfunctions/CRC.h" +#include "fsfw/globalfunctions/arrayprinter.h" +#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() = default; + +ReturnValue_t PusTcReader::parseData() { + if (maxSize < sizeof(CCSDSPrimaryHeader)) { + return SerializeIF::BUFFER_TOO_SHORT; + } + pointers.secHeaderStart = pointers.spHeaderStart + sizeof(CCSDSPrimaryHeader); + // TODO: No support for spare bytes yet + pointers.userDataStart = pointers.secHeaderStart + ecss::PusTcDataFieldHeader::MIN_LEN; +} + +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; } + +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(); } + +/* +void PusTcReader::print() { +#if FSFW_CPP_OSTREAM_ENABLED == 1 + sif::info << "TcPacketBase::print:" << std::endl; +#else + sif::printInfo("TcPacketBase::print:\n"); +#endif + arrayprinter::print(getWholeData(), getFullSize()); +} +*/ \ No newline at end of file diff --git a/src/fsfw/tmtcpacket/pus/tc/PusTcReader.h b/src/fsfw/tmtcpacket/pus/tc/PusTcReader.h new file mode 100644 index 00000000..43ab26ce --- /dev/null +++ b/src/fsfw/tmtcpacket/pus/tc/PusTcReader.h @@ -0,0 +1,82 @@ +#ifndef TMTCPACKET_PUS_TCPACKETBASE_H_ +#define TMTCPACKET_PUS_TCPACKETBASE_H_ + +#include + +#include "PusTcIF.h" +#include "fsfw/tmtcpacket/RedirectableDataPointerIF.h" +#include "fsfw/tmtcpacket/SpacePacketReader.h" + +/** + * This class is the basic data handler for any ECSS PUS Telecommand packet. + * + * In addition to #SpacePacketBase, the class provides methods to handle + * the standardized entries of the PUS TC Packet Data Field Header. + * It does not contain the packet data itself but a pointer to the + * data must be set on instantiation. An invalid pointer may cause + * damage, as no getter method checks data validity. Anyway, a NULL + * check can be performed by making use of the getWholeData method. + * @ingroup tmtcpackets + */ +class PusTcReader : public PusTcIF, public RedirectableDataPointerIF { + friend class TcPacketStoredBase; + + public: + /** + * This is the default constructor. + * It sets its internal data pointer to the address passed and also + * forwards the data pointer to the parent SpacePacketBase class. + * @param setData The position where the packet data lies. + */ + explicit PusTcReader(const uint8_t* setData, size_t size); + + ReturnValue_t parseData(); + /** + * This is the empty default destructor. + */ + ~PusTcReader() override; + + /** + * This is a debugging helper method that prints the whole packet content + * to the screen. + */ + void print(); + [[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; + [[nodiscard]] const uint8_t* getApplicationData() const override; + [[nodiscard]] uint16_t getApplicationDataSize() const override; + [[nodiscard]] uint16_t getErrorControl() const override; + + protected: + /** + * With this method, the packet data pointer can be redirected to another + * location. + * This call overwrites the parent's setData method to set both its + * @c tc_data pointer and the parent's @c data pointer. + * + * @param p_data A pointer to another PUS Telecommand Packet. + */ + ReturnValue_t setData(uint8_t* pData, size_t maxSize, void* args) override = 0; + SpacePacketReader spReader; + /** + * This struct defines the data structure of a Space Packet when accessed + * via a pointer. + * @ingroup tmtcpackets + */ + struct PusTcPointers { + const uint8_t* spHeaderStart; + const uint8_t* secHeaderStart; + const uint8_t* userDataStart; + }; + + PusTcPointers pointers{}; + size_t maxSize = 0; +}; + +#endif /* TMTCPACKET_PUS_TCPACKETBASE_H_ */ diff --git a/src/fsfw/tmtcpacket/pus/tc/TcPacketPus.h b/src/fsfw/tmtcpacket/pus/tc/TcPacketPus.h index b630cfee..d7c8d743 100644 --- a/src/fsfw/tmtcpacket/pus/tc/TcPacketPus.h +++ b/src/fsfw/tmtcpacket/pus/tc/TcPacketPus.h @@ -4,44 +4,25 @@ #include #include "../definitions.h" -#include "TcPacketPusBase.h" +#include "PusTcReader.h" #include "fsfw/FSFW.h" #include "fsfw/tmtcpacket/ccsds_header.h" -/** - * This struct defines a byte-wise structured PUS TC A Data Field Header. - * Any optional fields in the header must be added or removed here. - * Currently, the Source Id field is present with one byte. - * @ingroup tmtcpackets - */ -struct PUSTcDataFieldHeader { - uint8_t versionTypeAck; - uint8_t serviceType; - uint8_t serviceSubtype; -#if FSFW_USE_PUS_C_TELECOMMANDS == 1 - uint8_t sourceIdH; - uint8_t sourceIdL; -#else - uint8_t sourceId; -#endif -}; - /** * This struct defines the data structure of a PUS Telecommand A packet when * accessed via a pointer. * @ingroup tmtcpackets */ +/* struct TcPacketPointer { - CCSDSPrimaryHeader primary; - PUSTcDataFieldHeader dataField; - uint8_t appData; + CCSDSPrimaryHeader primary; + PusTcDataFieldHeader dataField; + uint8_t appData; }; + */ class TcPacketPus : public TcPacketPusBase { public: - static const uint16_t TC_PACKET_MIN_SIZE = - (sizeof(CCSDSPrimaryHeader) + sizeof(PUSTcDataFieldHeader) + 2); - /** * Initialize a PUS A telecommand packet which already exists. You can also * create an empty (invalid) object by passing nullptr as the data pointer diff --git a/src/fsfw/tmtcpacket/pus/tc/TcPacketPusBase.cpp b/src/fsfw/tmtcpacket/pus/tc/TcPacketPusBase.cpp deleted file mode 100644 index 3d7ff888..00000000 --- a/src/fsfw/tmtcpacket/pus/tc/TcPacketPusBase.cpp +++ /dev/null @@ -1,20 +0,0 @@ -#include "TcPacketPusBase.h" - -#include - -#include "fsfw/globalfunctions/CRC.h" -#include "fsfw/globalfunctions/arrayprinter.h" -#include "fsfw/serviceinterface/ServiceInterface.h" - -TcPacketPusBase::TcPacketPusBase(const uint8_t* setData) : SpacePacketReader(setData) {} - -TcPacketPusBase::~TcPacketPusBase() {} - -void TcPacketPusBase::print() { -#if FSFW_CPP_OSTREAM_ENABLED == 1 - sif::info << "TcPacketBase::print:" << std::endl; -#else - sif::printInfo("TcPacketBase::print:\n"); -#endif - arrayprinter::print(getWholeData(), getFullSize()); -} diff --git a/src/fsfw/tmtcpacket/pus/tc/TcPacketPusBase.h b/src/fsfw/tmtcpacket/pus/tc/TcPacketPusBase.h deleted file mode 100644 index ce30cb18..00000000 --- a/src/fsfw/tmtcpacket/pus/tc/TcPacketPusBase.h +++ /dev/null @@ -1,151 +0,0 @@ -#ifndef TMTCPACKET_PUS_TCPACKETBASE_H_ -#define TMTCPACKET_PUS_TCPACKETBASE_H_ - -#include - -#include - -#include "fsfw/tmtcpacket/SpacePacketReader.h" - -/** - * This class is the basic data handler for any ECSS PUS Telecommand packet. - * - * In addition to #SpacePacketBase, the class provides methods to handle - * the standardized entries of the PUS TC Packet Data Field Header. - * It does not contain the packet data itself but a pointer to the - * data must be set on instantiation. An invalid pointer may cause - * damage, as no getter method checks data validity. Anyway, a NULL - * check can be performed by making use of the getWholeData method. - * @ingroup tmtcpackets - */ -class TcPacketPusBase : public SpacePacketReader { - friend class TcPacketStoredBase; - - public: - enum AckField { - //! No acknowledgements are expected. - ACK_NONE = 0b0000, - //! Acknowledgements on acceptance are expected. - ACK_ACCEPTANCE = 0b0001, - //! Acknowledgements on start are expected. - ACK_START = 0b0010, - //! Acknowledgements on step are expected. - ACK_STEP = 0b0100, - //! Acknowledfgement on completion are expected. - ACK_COMPLETION = 0b1000 - }; - - static constexpr uint8_t ACK_ALL = ACK_ACCEPTANCE | ACK_START | ACK_STEP | ACK_COMPLETION; - - /** - * 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. - */ - TcPacketPusBase(const uint8_t* setData); - /** - * This is the empty default destructor. - */ - virtual ~TcPacketPusBase(); - - /** - * This command returns the CCSDS Secondary Header Flag. - * It shall always be zero for PUS Packets. This is the - * highest bit of the first byte of the Data Field Header. - * @return the CCSDS Secondary Header Flag - */ - virtual uint8_t getSecondaryHeaderFlag() const = 0; - /** - * 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 - */ - virtual uint8_t getPusVersionNumber() 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. - * - * It is packed in a uint8_t variable. - * @return The packet's PUS Ack field. - */ - 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. - */ - 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. - */ - virtual uint8_t getSubService() const = 0; - /** - * The source ID can be used to have an additional identifier, e.g. for different ground - * station. - * @return - */ - 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. - */ - 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) - */ - 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 - */ - virtual uint16_t getErrorControl() const = 0; - /** - * With this method, the Error Control Field is updated to match the - * current content of the packet. - */ - virtual void setErrorControl() = 0; - - /** - * Calculate full packet length from application data length. - * @param appDataLen - * @return - */ - virtual size_t calculateFullPacketLength(size_t appDataLen) const = 0; - - /** - * This is a debugging helper method that prints the whole packet content - * to the screen. - */ - void print(); - - protected: - /** - * With this method, the packet data pointer can be redirected to another - * location. - * This call overwrites the parent's setData method to set both its - * @c tc_data pointer and the parent's @c data pointer. - * - * @param p_data A pointer to another PUS Telecommand Packet. - */ - virtual ReturnValue_t setData(uint8_t* pData, size_t maxSize, void* args = nullptr) override = 0; -}; - -#endif /* TMTCPACKET_PUS_TCPACKETBASE_H_ */ diff --git a/src/fsfw/tmtcpacket/pus/tc/TcPacketStoredBase.h b/src/fsfw/tmtcpacket/pus/tc/TcPacketStoredBase.h index 4d27565a..d0a15cc4 100644 --- a/src/fsfw/tmtcpacket/pus/tc/TcPacketStoredBase.h +++ b/src/fsfw/tmtcpacket/pus/tc/TcPacketStoredBase.h @@ -1,6 +1,7 @@ #ifndef TMTCPACKET_PUS_TCPACKETSTORED_H_ #define TMTCPACKET_PUS_TCPACKETSTORED_H_ +#include "PusTcReader.h" #include "TcPacketStoredIF.h" #include "fsfw/storagemanager/StorageManagerIF.h" diff --git a/src/fsfw/tmtcpacket/pus/tc/TcPacketStoredIF.h b/src/fsfw/tmtcpacket/pus/tc/TcPacketStoredIF.h index 7ac8c331..1fce33d2 100644 --- a/src/fsfw/tmtcpacket/pus/tc/TcPacketStoredIF.h +++ b/src/fsfw/tmtcpacket/pus/tc/TcPacketStoredIF.h @@ -3,7 +3,7 @@ #include -#include "TcPacketPusBase.h" +#include "PusTcReader.h" #include "fsfw/returnvalues/HasReturnvaluesIF.h" #include "fsfw/storagemanager/storeAddress.h" diff --git a/src/fsfw/tmtcpacket/pus/tm/CMakeLists.txt b/src/fsfw/tmtcpacket/pus/tm/CMakeLists.txt index ded74ce2..22fbebcd 100644 --- a/src/fsfw/tmtcpacket/pus/tm/CMakeLists.txt +++ b/src/fsfw/tmtcpacket/pus/tm/CMakeLists.txt @@ -1,9 +1,4 @@ target_sources( ${LIB_FSFW_NAME} - PRIVATE TmPacketStoredPusA.cpp - TmPacketStoredPusC.cpp - TmPacketPusA.cpp - TmPacketPusC.cpp - TmPacketStoredBase.cpp - TmPacketBase.cpp - TmPacketMinimal.cpp) + PRIVATE TmPacketStoredPusC.cpp TmPacketPusC.cpp TmPacketStoredBase.cpp + TmPacketBase.cpp TmPacketMinimal.cpp) diff --git a/src/fsfw/tmtcpacket/pus/tm/TmPacketPusA.cpp b/src/fsfw/tmtcpacket/pus/tm/TmPacketPusA.cpp deleted file mode 100644 index 8ccb87b5..00000000 --- a/src/fsfw/tmtcpacket/pus/tm/TmPacketPusA.cpp +++ /dev/null @@ -1,68 +0,0 @@ -#include "TmPacketPusA.h" - -#include - -#include "../definitions.h" -#include "TmPacketBase.h" -#include "fsfw/globalfunctions/CRC.h" -#include "fsfw/globalfunctions/arrayprinter.h" -#include "fsfw/objectmanager/ObjectManagerIF.h" -#include "fsfw/serviceinterface/ServiceInterface.h" -#include "fsfw/timemanager/CCSDSTime.h" - -TmPacketPusA::TmPacketPusA(uint8_t* setData) : TmPacketBase(setData) { - tmData = reinterpret_cast(setData); -} - -TmPacketPusA::~TmPacketPusA() { - // Nothing to do. -} - -uint8_t TmPacketPusA::getService() { return tmData->data_field.service_type; } - -uint8_t TmPacketPusA::getSubService() { return tmData->data_field.service_subtype; } - -uint8_t* TmPacketPusA::getSourceData() { return &tmData->data; } - -uint16_t TmPacketPusA::getSourceDataSize() { - return SpacePacketReader::getPacketDataLen() - sizeof(tmData->data_field) - CRC_SIZE + 1; -} - -ReturnValue_t TmPacketPusA::setData(uint8_t* p_Data, size_t maxSize, void* args) { - ReturnValue_t result = SpacePacketReader::setData(p_Data, maxSize, args); - if (result != HasReturnvaluesIF::RETURN_OK) { - return result; - } - tmData = reinterpret_cast(const_cast(p_Data)); - return HasReturnvaluesIF::RETURN_OK; -} - -size_t TmPacketPusA::getPacketMinimumSize() const { return TM_PACKET_MIN_SIZE; } - -uint16_t TmPacketPusA::getDataFieldSize() { return sizeof(PUSTmDataFieldHeaderPusA); } - -uint8_t* TmPacketPusA::getPacketTimeRaw() const { return tmData->data_field.time; } - -void TmPacketPusA::initializeTmPacket(uint16_t apid, uint8_t service, uint8_t subservice, - uint8_t packetSubcounter) { - // Set primary header: - initSpacePacketHeader(false, true, apid); - // Set data Field Header: - // First, set to zero. - memset(&tmData->data_field, 0, sizeof(tmData->data_field)); - - tmData->data_field.version_type_ack = pus::PusVersion::PUS_A_VERSION << 4; - tmData->data_field.service_type = service; - tmData->data_field.service_subtype = subservice; - tmData->data_field.subcounter = packetSubcounter; - // Timestamp packet - if (TmPacketBase::checkAndSetStamper()) { - timeStamper->addTimeStamp(tmData->data_field.time, sizeof(tmData->data_field.time)); - } -} - -void TmPacketPusA::setSourceDataSize(uint16_t size) { - setPacketDataLength(size + sizeof(PUSTmDataFieldHeaderPusA) + CRC_SIZE - 1); -} - -size_t TmPacketPusA::getTimestampSize() const { return sizeof(tmData->data_field.time); } diff --git a/src/fsfw/tmtcpacket/pus/tm/TmPacketPusA.h b/src/fsfw/tmtcpacket/pus/tm/TmPacketPusA.h deleted file mode 100644 index 6808a8d6..00000000 --- a/src/fsfw/tmtcpacket/pus/tm/TmPacketPusA.h +++ /dev/null @@ -1,129 +0,0 @@ -#ifndef FSFW_TMTCPACKET_PUS_TMPACKETPUSA_H_ -#define FSFW_TMTCPACKET_PUS_TMPACKETPUSA_H_ - -#include "TmPacketBase.h" -#include "fsfw/objectmanager/SystemObjectIF.h" -#include "fsfw/timemanager/Clock.h" -#include "fsfw/timemanager/TimeStamperIF.h" -#include "fsfw/tmtcpacket/SpacePacketReader.h" - -namespace Factory { -void setStaticFrameworkObjectIds(); -} - -/** - * This struct defines a byte-wise structured PUS TM Data Field Header. - * Any optional fields in the header must be added or removed here. - * Currently, no Destination field is present, but an eigth-byte representation - * for a time tag. - * @ingroup tmtcpackets - */ -struct PUSTmDataFieldHeaderPusA { - uint8_t version_type_ack; - uint8_t service_type; - uint8_t service_subtype; - uint8_t subcounter; - // uint8_t destination; - uint8_t time[TimeStamperIF::MISSION_TIMESTAMP_SIZE]; -}; - -/** - * This struct defines the data structure of a PUS Telecommand Packet when - * accessed via a pointer. - * @ingroup tmtcpackets - */ -struct TmPacketPointerPusA { - CCSDSPrimaryHeader primary; - PUSTmDataFieldHeaderPusA data_field; - uint8_t data; -}; - -/** - * PUS A packet implementation - * @ingroup tmtcpackets - */ -class TmPacketPusA : public TmPacketBase { - friend void(Factory::setStaticFrameworkObjectIds)(); - - public: - /** - * This constant defines the minimum size of a valid PUS Telemetry Packet. - */ - static const uint32_t TM_PACKET_MIN_SIZE = - (sizeof(CCSDSPrimaryHeader) + sizeof(PUSTmDataFieldHeaderPusA) + 2); - //! Maximum size of a TM Packet in this mission. - static const uint32_t MISSION_TM_PACKET_MAX_SIZE = fsfwconfig::FSFW_MAX_TM_PACKET_SIZE; - - /** - * 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 set_address The position where the packet data lies. - */ - TmPacketPusA(uint8_t* setData); - /** - * This is the empty default destructor. - */ - virtual ~TmPacketPusA(); - - /* TmPacketBase implementations */ - uint8_t getService() override; - uint8_t getSubService() override; - uint8_t* getSourceData() override; - uint16_t getSourceDataSize() override; - uint16_t getDataFieldSize() override; - - /** - * Returns a raw pointer to the beginning of the time field. - * @return Raw pointer to time field. - */ - uint8_t* getPacketTimeRaw() const override; - size_t getTimestampSize() const override; - - size_t getPacketMinimumSize() const override; - - protected: - /** - * 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. - */ - TmPacketPointerPusA* tmData; - - /** - * Initializes the Tm Packet header. - * Does set the timestamp (to now), but not the error control field. - * @param apid APID used. - * @param service PUS Service - * @param subservice PUS Subservice - * @param packetSubcounter Additional subcounter used. - */ - void initializeTmPacket(uint16_t apid, uint8_t service, uint8_t subservice, - uint8_t packetSubcounter); - - /** - * With this method, the packet data pointer can be redirected to another - * location. - * - * This call overwrites the parent's setData method to set both its - * @c tc_data pointer and the parent's @c data pointer. - * - * @param p_data A pointer to another PUS Telemetry Packet. - */ - ReturnValue_t setData(uint8_t* pData, size_t maxSize, void* args = nullptr) override; - - /** - * In case data was filled manually (almost never the case). - * @param size Size of source data (without CRC and data filed header!). - */ - void setSourceDataSize(uint16_t size); - - /** - * Checks if a time stamper is available and tries to set it if not. - * @return Returns false if setting failed. - */ - bool checkAndSetStamper(); -}; - -#endif /* FSFW_TMTCPACKET_PUS_TMPACKETPUSA_H_ */ diff --git a/src/fsfw/tmtcpacket/pus/tm/TmPacketStoredBase.h b/src/fsfw/tmtcpacket/pus/tm/TmPacketStoredBase.h index 1732f000..85363ee9 100644 --- a/src/fsfw/tmtcpacket/pus/tm/TmPacketStoredBase.h +++ b/src/fsfw/tmtcpacket/pus/tm/TmPacketStoredBase.h @@ -2,7 +2,6 @@ #define FSFW_TMTCPACKET_PUS_TMPACKETSTOREDBASE_H_ #include "TmPacketBase.h" -#include "TmPacketPusA.h" #include "TmPacketStoredBase.h" #include "fsfw/FSFW.h" #include "fsfw/internalerror/InternalErrorReporterIF.h" diff --git a/src/fsfw/tmtcpacket/pus/tm/TmPacketStoredPusA.cpp b/src/fsfw/tmtcpacket/pus/tm/TmPacketStoredPusA.cpp deleted file mode 100644 index 37ba63f3..00000000 --- a/src/fsfw/tmtcpacket/pus/tm/TmPacketStoredPusA.cpp +++ /dev/null @@ -1,73 +0,0 @@ -#include "fsfw/tmtcpacket/pus/tm/TmPacketStoredPusA.h" - -#include - -#include "fsfw/serviceinterface/ServiceInterface.h" -#include "fsfw/tmtcservices/TmTcMessage.h" - -TmPacketStoredPusA::TmPacketStoredPusA(store_address_t setAddress) - : TmPacketStoredBase(setAddress), TmPacketPusA(nullptr) {} - -TmPacketStoredPusA::TmPacketStoredPusA(uint16_t apid, uint8_t service, uint8_t subservice, - uint8_t packetSubcounter, const uint8_t *data, uint32_t size, - const uint8_t *headerData, uint32_t headerSize) - : TmPacketPusA(nullptr) { - storeAddress.raw = StorageManagerIF::INVALID_ADDRESS; - if (not TmPacketStoredBase::checkAndSetStore()) { - return; - } - uint8_t *pData = nullptr; - size_t sizeToReserve = getPacketMinimumSize() + size + headerSize; - ReturnValue_t returnValue = store->getFreeElement(&storeAddress, sizeToReserve, &pData); - - if (returnValue != store->RETURN_OK) { - handleStoreFailure("A", returnValue, sizeToReserve); - return; - } - setData(pData, sizeToReserve); - initializeTmPacket(apid, service, subservice, packetSubcounter); - memcpy(getSourceData(), headerData, headerSize); - memcpy(getSourceData() + headerSize, data, size); - setPacketDataLength(size + headerSize + sizeof(PUSTmDataFieldHeaderPusA) + CRC_SIZE - 1); -} - -TmPacketStoredPusA::TmPacketStoredPusA(uint16_t apid, uint8_t service, uint8_t subservice, - uint8_t packetSubcounter, SerializeIF *content, - SerializeIF *header) - : TmPacketPusA(nullptr) { - storeAddress.raw = StorageManagerIF::INVALID_ADDRESS; - if (not TmPacketStoredBase::checkAndSetStore()) { - return; - } - size_t sourceDataSize = 0; - if (content != nullptr) { - sourceDataSize += content->getSerializedSize(); - } - if (header != nullptr) { - sourceDataSize += header->getSerializedSize(); - } - uint8_t *pData = nullptr; - size_t sizeToReserve = getPacketMinimumSize() + sourceDataSize; - ReturnValue_t returnValue = store->getFreeElement(&storeAddress, sizeToReserve, &pData); - if (returnValue != store->RETURN_OK) { - handleStoreFailure("A", returnValue, sizeToReserve); - return; - } - setData(pData, sizeToReserve); - initializeTmPacket(apid, service, subservice, packetSubcounter); - uint8_t *putDataHere = getSourceData(); - size_t size = 0; - if (header != nullptr) { - header->serialize(&putDataHere, &size, sourceDataSize, SerializeIF::Endianness::BIG); - } - if (content != nullptr) { - content->serialize(&putDataHere, &size, sourceDataSize, SerializeIF::Endianness::BIG); - } - setPacketDataLength(sourceDataSize + sizeof(PUSTmDataFieldHeaderPusA) + CRC_SIZE - 1); -} - -uint8_t *TmPacketStoredPusA::getAllTmData() { return getWholeData(); } - -ReturnValue_t TmPacketStoredPusA::setData(uint8_t *newPointer, size_t maxSize, void *args) { - return TmPacketPusA::setData(newPointer, maxSize); -} diff --git a/src/fsfw/tmtcpacket/pus/tm/TmPacketStoredPusA.h b/src/fsfw/tmtcpacket/pus/tm/TmPacketStoredPusA.h deleted file mode 100644 index f2db99e9..00000000 --- a/src/fsfw/tmtcpacket/pus/tm/TmPacketStoredPusA.h +++ /dev/null @@ -1,69 +0,0 @@ -#ifndef FSFW_TMTCPACKET_PUS_TMPACKETSTORED_PUSA_H_ -#define FSFW_TMTCPACKET_PUS_TMPACKETSTORED_PUSA_H_ - -#include - -#include "TmPacketPusA.h" -#include "TmPacketStoredBase.h" - -/** - * This class generates a ECSS PUS A Telemetry packet within a given - * intermediate storage. - * As most packets are passed between tasks with the help of a storage - * anyway, it seems logical to create a Packet-In-Storage access class - * which saves the user almost all storage handling operation. - * Packets can both be newly created with the class and be "linked" to - * packets in a store with the help of a storeAddress. - * @ingroup tmtcpackets - */ -class TmPacketStoredPusA : public TmPacketStoredBase, public TmPacketPusA { - public: - /** - * This is a default constructor which does not set the data pointer. - * However, it does try to set the packet store. - */ - TmPacketStoredPusA(store_address_t setAddress); - /** - * With this constructor, new space is allocated in the packet store and - * a new PUS Telemetry Packet is created there. - * Packet Application Data passed in data is copied into the packet. - * The Application data is passed in two parts, first a header, then a - * data field. This allows building a Telemetry Packet from two separate - * data sources. - * @param apid Sets the packet's APID field. - * @param service Sets the packet's Service ID field. - * This specifies the source service. - * @param subservice Sets the packet's Service Subtype field. - * This specifies the source sub-service. - * @param packet_counter Sets the Packet counter field of this packet - * @param data The payload data to be copied to the - * Application Data Field - * @param size The amount of data to be copied. - * @param headerData The header Data of the Application field, - * will be copied in front of data - * @param headerSize The size of the headerDataF - */ - TmPacketStoredPusA(uint16_t apid, uint8_t service, uint8_t subservice, uint8_t packet_counter = 0, - const uint8_t* data = nullptr, uint32_t size = 0, - const uint8_t* headerData = nullptr, uint32_t headerSize = 0); - /** - * Another ctor to directly pass structured content and header data to the - * packet to avoid additional buffers. - */ - TmPacketStoredPusA(uint16_t apid, uint8_t service, uint8_t subservice, uint8_t packet_counter, - SerializeIF* content, SerializeIF* header = nullptr); - - uint8_t* getAllTmData() override; - - private: - /** - * Implementation required by base class - * @param newPointer - * @param maxSize - * @param args - * @return - */ - ReturnValue_t setData(uint8_t* newPointer, size_t maxSize, void* args = nullptr) override; -}; - -#endif /* FSFW_TMTCPACKET_PUS_TMPACKETSTORED_PUSA_H_ */ diff --git a/src/fsfw/tmtcservices/PusVerificationReport.h b/src/fsfw/tmtcservices/PusVerificationReport.h index 60c01d55..d84f4df3 100644 --- a/src/fsfw/tmtcservices/PusVerificationReport.h +++ b/src/fsfw/tmtcservices/PusVerificationReport.h @@ -4,7 +4,7 @@ #include "VerificationCodes.h" #include "fsfw/ipc/MessageQueueMessage.h" #include "fsfw/returnvalues/HasReturnvaluesIF.h" -#include "fsfw/tmtcpacket/pus/tc/TcPacketPusBase.h" +#include "fsfw/tmtcpacket/pus/tc/PusTcReader.h" class PusVerificationMessage : public MessageQueueMessage { private: diff --git a/unittests/tmtcpacket/testCcsdsCreator.cpp b/unittests/tmtcpacket/testCcsdsCreator.cpp index fbd73b10..d56669a7 100644 --- a/unittests/tmtcpacket/testCcsdsCreator.cpp +++ b/unittests/tmtcpacket/testCcsdsCreator.cpp @@ -4,7 +4,6 @@ #include "fsfw/tmtcpacket/SpacePacketCreator.h" - TEST_CASE("CCSDS Creator", "[ccsds-creator]") { SpacePacketCreator base = SpacePacketCreator(ccsds::PacketType::TC, true, 0x02, ccsds::SequenceFlags::FIRST_SEGMENT, 0x34, 0x16); diff --git a/unittests/tmtcpacket/testCcsdsReader.cpp b/unittests/tmtcpacket/testCcsdsReader.cpp index d63f4cf0..b8a6f3dd 100644 --- a/unittests/tmtcpacket/testCcsdsReader.cpp +++ b/unittests/tmtcpacket/testCcsdsReader.cpp @@ -1,6 +1,5 @@ #include + #include "fsfw/tmtcpacket/SpacePacketReader.h" -TEST_CASE("CCSDS Reader", "[ccsds-reader]") { - -} \ No newline at end of file +TEST_CASE("CCSDS Reader", "[ccsds-reader]") {} \ No newline at end of file -- 2.43.0 From 6c636661b6592ce4f4e7f715fcb6173d545f34ce Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Tue, 19 Jul 2022 18:13:25 +0200 Subject: [PATCH 012/108] a lot of refactoring --- CMakeLists.txt | 11 +- src/fsfw/cfdp/CFDPHandler.h | 2 +- .../internalerror/InternalErrorReporterIF.h | 2 +- src/fsfw/pus/Service9TimeManagement.cpp | 2 +- src/fsfw/returnvalues/FwClassIds.h | 2 +- src/fsfw/tcdistribution/CCSDSDistributor.cpp | 2 +- src/fsfw/tcdistribution/CCSDSDistributorIF.h | 2 +- src/fsfw/tcdistribution/CFDPDistributor.cpp | 15 +- src/fsfw/tcdistribution/CFDPDistributor.h | 10 +- src/fsfw/tcdistribution/CFDPDistributorIF.h | 2 +- src/fsfw/tcdistribution/CMakeLists.txt | 9 +- ...TcPacketCheckIF.h => CcsdsPacketCheckIF.h} | 14 +- .../tcdistribution/CcsdsPacketCheckerBase.cpp | 22 +++ .../tcdistribution/CcsdsPacketCheckerBase.h | 17 ++ ...cPacketCheckCFDP.h => CfdpPacketChecker.h} | 12 +- ...{PUSDistributor.cpp => PusDistributor.cpp} | 49 +++--- .../{PUSDistributor.h => PusDistributor.h} | 17 +- src/fsfw/tcdistribution/PusPacketChecker.cpp | 44 +++++ src/fsfw/tcdistribution/PusPacketChecker.h | 38 +++++ src/fsfw/tcdistribution/TcDistributor.cpp | 2 +- src/fsfw/tcdistribution/TcPacketCheckCFDP.cpp | 13 +- src/fsfw/tcdistribution/TcPacketCheckPUS.cpp | 44 ----- src/fsfw/tcdistribution/TcPacketCheckPUS.h | 61 ------- src/fsfw/tcdistribution/definitions.h | 24 +++ src/fsfw/tmstorage/TmStorePackets.h | 2 +- src/fsfw/tmtcpacket/CMakeLists.txt | 4 +- src/fsfw/tmtcpacket/PacketStorageHelper.cpp | 25 +++ src/fsfw/tmtcpacket/PacketStorageHelper.h | 63 ++++++++ src/fsfw/tmtcpacket/ReadablePacketIF.h | 13 ++ .../tmtcpacket/RedirectableDataPointerIF.h | 6 +- src/fsfw/tmtcpacket/SpacePacketCreator.cpp | 41 ++--- src/fsfw/tmtcpacket/SpacePacketCreator.h | 18 ++- src/fsfw/tmtcpacket/SpacePacketIF.h | 13 ++ src/fsfw/tmtcpacket/SpacePacketReader.cpp | 45 +++--- src/fsfw/tmtcpacket/SpacePacketReader.h | 42 ++--- src/fsfw/tmtcpacket/cfdp/CFDPPacket.cpp | 11 +- src/fsfw/tmtcpacket/cfdp/CFDPPacketStored.cpp | 22 +-- src/fsfw/tmtcpacket/cfdp/CMakeLists.txt | 2 +- .../cfdp/{CFDPPacket.h => CfdpPacket.h} | 6 +- ...{CFDPPacketStored.h => CfdpPacketStored.h} | 18 +-- .../tmtcpacket/packetmatcher/ApidMatcher.h | 13 +- .../packetmatcher/PacketMatchTree.cpp | 52 +++--- .../packetmatcher/PacketMatchTree.h | 17 +- .../tmtcpacket/packetmatcher/ServiceMatcher.h | 19 ++- .../packetmatcher/SubserviceMatcher.h | 21 +-- .../pus/PacketTimestampInterpreterIF.h | 6 +- src/fsfw/tmtcpacket/pus/PusIF.h | 52 ++++++ src/fsfw/tmtcpacket/pus/definitions.h | 6 +- src/fsfw/tmtcpacket/pus/tc.h | 1 - src/fsfw/tmtcpacket/pus/tc/CMakeLists.txt | 8 +- src/fsfw/tmtcpacket/pus/tc/PusTcCreator.cpp | 74 ++++++++- src/fsfw/tmtcpacket/pus/tc/PusTcCreator.h | 38 ++++- src/fsfw/tmtcpacket/pus/tc/PusTcIF.h | 55 +------ src/fsfw/tmtcpacket/pus/tc/PusTcReader.cpp | 57 +++++-- src/fsfw/tmtcpacket/pus/tc/PusTcReader.h | 25 +-- src/fsfw/tmtcpacket/pus/tc/TcPacketPus.cpp | 2 +- src/fsfw/tmtcpacket/pus/tc/TcPacketPus.h | 88 +++++----- src/fsfw/tmtcpacket/pus/tc/TcPacketStored.cpp | 1 + src/fsfw/tmtcpacket/pus/tc/TcPacketStored.h | 10 ++ .../tmtcpacket/pus/tc/TcPacketStoredBase.cpp | 111 ++++++------- .../tmtcpacket/pus/tc/TcPacketStoredBase.h | 150 +++++++++--------- .../tmtcpacket/pus/tc/TcPacketStoredPus.cpp | 78 --------- .../tmtcpacket/pus/tc/TcPacketStoredPus.h | 48 ------ src/fsfw/tmtcpacket/pus/tm.h | 2 +- src/fsfw/tmtcpacket/pus/tm/CMakeLists.txt | 6 +- src/fsfw/tmtcpacket/pus/tm/PusTmCreator.cpp | 10 ++ src/fsfw/tmtcpacket/pus/tm/PusTmCreator.h | 31 ++++ src/fsfw/tmtcpacket/pus/tm/PusTmIF.h | 20 +++ src/fsfw/tmtcpacket/pus/tm/PusTmMinimal.cpp | 45 ++++++ .../tm/{TmPacketMinimal.h => PusTmMinimal.h} | 65 ++++---- src/fsfw/tmtcpacket/pus/tm/PusTmReader.cpp | 3 + src/fsfw/tmtcpacket/pus/tm/PusTmReader.h | 7 + .../tmtcpacket/pus/tm/TmPacketMinimal.cpp | 40 ----- src/fsfw/tmtcpacket/pus/tm/TmPacketPusC.cpp | 3 +- src/fsfw/tmtcservices/PusServiceBase.cpp | 23 ++- src/fsfw/tmtcservices/PusServiceBase.h | 20 ++- .../tmtcservices/VerificationReporter.cpp | 9 +- src/fsfw/tmtcservices/VerificationReporter.h | 6 +- 78 files changed, 1134 insertions(+), 835 deletions(-) rename src/fsfw/tcdistribution/{TcPacketCheckIF.h => CcsdsPacketCheckIF.h} (69%) create mode 100644 src/fsfw/tcdistribution/CcsdsPacketCheckerBase.cpp create mode 100644 src/fsfw/tcdistribution/CcsdsPacketCheckerBase.h rename src/fsfw/tcdistribution/{TcPacketCheckCFDP.h => CfdpPacketChecker.h} (63%) rename src/fsfw/tcdistribution/{PUSDistributor.cpp => PusDistributor.cpp} (75%) rename src/fsfw/tcdistribution/{PUSDistributor.h => PusDistributor.h} (84%) create mode 100644 src/fsfw/tcdistribution/PusPacketChecker.cpp create mode 100644 src/fsfw/tcdistribution/PusPacketChecker.h delete mode 100644 src/fsfw/tcdistribution/TcPacketCheckPUS.cpp delete mode 100644 src/fsfw/tcdistribution/TcPacketCheckPUS.h create mode 100644 src/fsfw/tcdistribution/definitions.h create mode 100644 src/fsfw/tmtcpacket/PacketStorageHelper.cpp create mode 100644 src/fsfw/tmtcpacket/PacketStorageHelper.h create mode 100644 src/fsfw/tmtcpacket/ReadablePacketIF.h rename src/fsfw/tmtcpacket/cfdp/{CFDPPacket.h => CfdpPacket.h} (82%) rename src/fsfw/tmtcpacket/cfdp/{CFDPPacketStored.h => CfdpPacketStored.h} (72%) create mode 100644 src/fsfw/tmtcpacket/pus/PusIF.h create mode 100644 src/fsfw/tmtcpacket/pus/tc/TcPacketStored.cpp create mode 100644 src/fsfw/tmtcpacket/pus/tc/TcPacketStored.h delete mode 100644 src/fsfw/tmtcpacket/pus/tc/TcPacketStoredPus.cpp delete mode 100644 src/fsfw/tmtcpacket/pus/tc/TcPacketStoredPus.h create mode 100644 src/fsfw/tmtcpacket/pus/tm/PusTmCreator.cpp create mode 100644 src/fsfw/tmtcpacket/pus/tm/PusTmCreator.h create mode 100644 src/fsfw/tmtcpacket/pus/tm/PusTmIF.h create mode 100644 src/fsfw/tmtcpacket/pus/tm/PusTmMinimal.cpp rename src/fsfw/tmtcpacket/pus/tm/{TmPacketMinimal.h => PusTmMinimal.h} (54%) create mode 100644 src/fsfw/tmtcpacket/pus/tm/PusTmReader.cpp create mode 100644 src/fsfw/tmtcpacket/pus/tm/PusTmReader.h delete mode 100644 src/fsfw/tmtcpacket/pus/tm/TmPacketMinimal.cpp diff --git a/CMakeLists.txt b/CMakeLists.txt index 5601d202..e59eb4c5 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 abbac6b6..3e6f0429 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 61bb52e7..aa917d21 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 86eef93a..6cd46f3a 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 f5f57276..50efd9c5 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 a32cbc75..f18e55de 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 d1c88118..da4a943f 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 d8be1543..5aa84d44 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 2a901021..e7776f1b 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 3c1836f1..3f048bbf 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 ab32c509..9cc3d170 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 a9ec14a2..55288ae4 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 00000000..8c97f646 --- /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 00000000..f5a9b317 --- /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 5a4abd4f..0838efc2 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 dad002a1..5975a7f2 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 c069c81b..fb916263 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 00000000..828303b2 --- /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 00000000..fe341378 --- /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 a650546c..600b3ca9 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 7d2bfe88..555c85b4 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 963bece7..00000000 --- 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 4804a619..00000000 --- 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 00000000..ce640308 --- /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 d54b7b52..0640fd36 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 85376d01..69b3cc48 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 00000000..89184251 --- /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 00000000..1be75b23 --- /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 00000000..c1287e81 --- /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 6eb16edd..56038036 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 acc2fea2..ff131059 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 9a9a0e2d..9c74046b 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 1b2bfb90..21ee4c32 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 cdb00082..2d7d2eda 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 81151fab..eb1d5c93 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 29b6c561..b4a8534c 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 260331ac..e597cf35 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 7d20aab8..a0d48465 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 a70c3938..e47d3b6f 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 688067f9..54f8e5be 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 3c835ef8..47e23f1c 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 55fd3227..1ab8729b 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 0cbd4494..fa3aab44 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 752c0354..6ccd9a6b 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 934e8cb8..8729bbd5 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 340f7825..d6e96438 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 00000000..61d4fcff --- /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 d4b649d0..369f869a 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 f5a467aa..33c6352f 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 c37c2c55..d2e30586 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 c73f7a93..cbd6da53 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 275cc28f..ffa2ed7c 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 54afd946..a8204a1f 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 e2a66e73..0ead9bde 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 43ab26ce..85623980 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 faada828..06f980b7 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 d7c8d743..bb2b3642 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 00000000..89ebe75a --- /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 00000000..ddd51303 --- /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 22918526..88964bfb 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 d0a15cc4..8291ac6c 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 95350ac2..00000000 --- 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 45dec293..00000000 --- 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 afbe8251..657790f4 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 22fbebcd..57c45927 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 00000000..5a1f4144 --- /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 00000000..fbdeb7d9 --- /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 00000000..b22bdf3d --- /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 00000000..4042528a --- /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 197bf6e6..a09523fb 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 00000000..d010512a --- /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 00000000..47eff293 --- /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 c1a5c4ba..00000000 --- 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 fd2248aa..7ae6de82 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 3af2b82c..f0cdb61b 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 9db1bef0..57547ace 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 19277bf3..bf33d1c4 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 c29afd60..5b4dbe0a 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, -- 2.43.0 From d80941514fe14bdffd5c113633c5b89ab85c4083 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Wed, 20 Jul 2022 11:43:16 +0200 Subject: [PATCH 013/108] start refactoring PUS TM handling --- .../datalinklayer/MapPacketExtraction.cpp | 2 +- src/fsfw/pus/Service17Test.cpp | 39 ++--- src/fsfw/pus/Service17Test.h | 13 +- src/fsfw/tcdistribution/CCSDSDistributor.cpp | 2 +- .../tcdistribution/CcsdsPacketCheckerBase.cpp | 2 +- .../tcdistribution/CcsdsPacketCheckerBase.h | 2 +- src/fsfw/tmtcpacket/CMakeLists.txt | 7 +- src/fsfw/tmtcpacket/ReadablePacketIF.h | 2 +- src/fsfw/tmtcpacket/SpacePacketCreator.h | 87 ----------- src/fsfw/tmtcpacket/ccsds/CMakeLists.txt | 2 + src/fsfw/tmtcpacket/ccsds/PacketId.h | 68 ++++++++ src/fsfw/tmtcpacket/ccsds/PacketSeqCtrl.h | 56 +++++++ .../{ => ccsds}/SpacePacketCreator.cpp | 16 +- .../tmtcpacket/ccsds/SpacePacketCreator.h | 53 +++++++ .../tmtcpacket/{ => ccsds}/SpacePacketIF.h | 59 +++---- .../{ => ccsds}/SpacePacketReader.cpp | 19 +-- .../{ => ccsds}/SpacePacketReader.h | 13 +- src/fsfw/tmtcpacket/ccsds/defs.h | 36 +++++ src/fsfw/tmtcpacket/ccsds/header.cpp | 29 ++++ src/fsfw/tmtcpacket/ccsds/header.h | 30 ++++ src/fsfw/tmtcpacket/ccsds_header.h | 15 -- src/fsfw/tmtcpacket/cfdp/CfdpPacket.h | 2 +- .../packetmatcher/PacketMatchTree.cpp | 12 +- src/fsfw/tmtcpacket/pus/PusIF.h | 2 +- src/fsfw/tmtcpacket/pus/tc/PusTcCreator.cpp | 4 +- src/fsfw/tmtcpacket/pus/tc/PusTcCreator.h | 8 +- src/fsfw/tmtcpacket/pus/tc/PusTcIF.h | 2 +- src/fsfw/tmtcpacket/pus/tc/PusTcReader.cpp | 9 +- src/fsfw/tmtcpacket/pus/tc/PusTcReader.h | 6 +- src/fsfw/tmtcpacket/pus/tc/TcPacketPus.h | 2 +- src/fsfw/tmtcpacket/pus/tm/PusTmCreator.cpp | 8 +- src/fsfw/tmtcpacket/pus/tm/PusTmCreator.h | 10 +- src/fsfw/tmtcpacket/pus/tm/PusTmMinimal.cpp | 11 +- src/fsfw/tmtcpacket/pus/tm/PusTmMinimal.h | 59 ++++--- src/fsfw/tmtcpacket/pus/tm/TmPacketBase.h | 2 +- src/fsfw/tmtcpacket/pus/tm/TmPacketPusC.h | 6 +- .../tmtcpacket/pus/tm/TmPacketStoredPusC.h | 145 +++++++++--------- src/fsfw/tmtcservices/CMakeLists.txt | 3 +- src/fsfw/tmtcservices/PusServiceBase.cpp | 14 +- src/fsfw/tmtcservices/PusServiceBase.h | 4 +- src/fsfw/tmtcservices/SourceSequenceCounter.h | 2 +- src/fsfw/tmtcservices/TmStoreHelper.cpp | 43 ++++++ src/fsfw/tmtcservices/TmStoreHelper.h | 33 ++++ .../tmtcservices/VerificationReporter.cpp | 10 +- unittests/tmtcpacket/testCcsdsCreator.cpp | 19 ++- unittests/tmtcpacket/testCcsdsReader.cpp | 2 +- 46 files changed, 615 insertions(+), 355 deletions(-) delete mode 100644 src/fsfw/tmtcpacket/SpacePacketCreator.h create mode 100644 src/fsfw/tmtcpacket/ccsds/CMakeLists.txt create mode 100644 src/fsfw/tmtcpacket/ccsds/PacketId.h create mode 100644 src/fsfw/tmtcpacket/ccsds/PacketSeqCtrl.h rename src/fsfw/tmtcpacket/{ => ccsds}/SpacePacketCreator.cpp (75%) create mode 100644 src/fsfw/tmtcpacket/ccsds/SpacePacketCreator.h rename src/fsfw/tmtcpacket/{ => ccsds}/SpacePacketIF.h (56%) rename src/fsfw/tmtcpacket/{ => ccsds}/SpacePacketReader.cpp (62%) rename src/fsfw/tmtcpacket/{ => ccsds}/SpacePacketReader.h (88%) create mode 100644 src/fsfw/tmtcpacket/ccsds/defs.h create mode 100644 src/fsfw/tmtcpacket/ccsds/header.cpp create mode 100644 src/fsfw/tmtcpacket/ccsds/header.h delete mode 100644 src/fsfw/tmtcpacket/ccsds_header.h create mode 100644 src/fsfw/tmtcservices/TmStoreHelper.cpp create mode 100644 src/fsfw/tmtcservices/TmStoreHelper.h diff --git a/src/fsfw/datalinklayer/MapPacketExtraction.cpp b/src/fsfw/datalinklayer/MapPacketExtraction.cpp index 1467f2aa..feb1cc91 100644 --- a/src/fsfw/datalinklayer/MapPacketExtraction.cpp +++ b/src/fsfw/datalinklayer/MapPacketExtraction.cpp @@ -6,7 +6,7 @@ #include "fsfw/objectmanager/ObjectManager.h" #include "fsfw/serviceinterface/ServiceInterface.h" #include "fsfw/storagemanager/StorageManagerIF.h" -#include "fsfw/tmtcpacket/SpacePacketReader.h" +#include "fsfw/tmtcpacket/ccsds/SpacePacketReader.h" #include "fsfw/tmtcservices/AcceptsTelecommandsIF.h" #include "fsfw/tmtcservices/TmTcMessage.h" diff --git a/src/fsfw/pus/Service17Test.cpp b/src/fsfw/pus/Service17Test.cpp index f784acf4..87549808 100644 --- a/src/fsfw/pus/Service17Test.cpp +++ b/src/fsfw/pus/Service17Test.cpp @@ -5,33 +5,25 @@ #include "fsfw/serviceinterface/ServiceInterface.h" #include "fsfw/tmtcpacket/pus/tm/TmPacketStored.h" -Service17Test::Service17Test(object_id_t objectId, uint16_t apid, uint8_t serviceId) - : PusServiceBase(objectId, apid, serviceId), packetSubCounter(0) {} +Service17Test::Service17Test(object_id_t objectId, uint16_t apid, uint8_t serviceId, + StorageManagerIF* tmStore, StorageManagerIF* ipcStore, + InternalErrorReporterIF* errReporter) + : PusServiceBase(objectId, apid, serviceId, ipcStore), + helper(tmStore, MessageQueueIF::NO_QUEUE, MessageQueueIF::NO_QUEUE, errReporter), + packetSubCounter(0) {} -Service17Test::~Service17Test() {} +Service17Test::~Service17Test() = default; ReturnValue_t Service17Test::handleRequest(uint8_t subservice) { switch (subservice) { case Subservice::CONNECTION_TEST: { -#if FSFW_USE_PUS_C_TELEMETRY == 0 - TmPacketStoredPusA connectionPacket(apid, serviceId, Subservice::CONNECTION_TEST_REPORT, - packetSubCounter++); -#else - TmPacketStoredPusC connectionPacket(apid, serviceId, Subservice::CONNECTION_TEST_REPORT, - packetSubCounter++); -#endif - connectionPacket.sendPacket(requestQueue->getDefaultDestination(), requestQueue->getId()); + helper.preparePacket(apid, serviceId, Subservice::CONNECTION_TEST_REPORT, packetSubCounter); + helper.sendPacket(); return HasReturnvaluesIF::RETURN_OK; } case Subservice::EVENT_TRIGGER_TEST: { -#if FSFW_USE_PUS_C_TELEMETRY == 0 - TmPacketStoredPusA connectionPacket(apid, serviceId, Subservice::CONNECTION_TEST_REPORT, - packetSubCounter++); -#else - TmPacketStoredPusC connectionPacket(apid, serviceId, Subservice::CONNECTION_TEST_REPORT, - packetSubCounter++); -#endif - connectionPacket.sendPacket(requestQueue->getDefaultDestination(), requestQueue->getId()); + helper.preparePacket(apid, serviceId, Subservice::CONNECTION_TEST_REPORT, packetSubCounter++); + helper.sendPacket(); triggerEvent(TEST, 1234, 5678); return RETURN_OK; } @@ -41,3 +33,12 @@ ReturnValue_t Service17Test::handleRequest(uint8_t subservice) { } ReturnValue_t Service17Test::performService() { return HasReturnvaluesIF::RETURN_OK; } + +ReturnValue_t Service17Test::initialize() { + ReturnValue_t result = PusServiceBase::initialize(); + if (result != HasReturnvaluesIF::RETURN_OK) { + return result; + } + helper.setMsgDestination(requestQueue->getDefaultDestination()); + helper.setMsgSource(requestQueue->getId()); + if (tm) } diff --git a/src/fsfw/pus/Service17Test.h b/src/fsfw/pus/Service17Test.h index c2248020..0f690ea4 100644 --- a/src/fsfw/pus/Service17Test.h +++ b/src/fsfw/pus/Service17Test.h @@ -3,6 +3,7 @@ #include "fsfw/objectmanager/SystemObject.h" #include "fsfw/tmtcservices/PusServiceBase.h" +#include "fsfw/tmtcservices/TmStoreHelper.h" /** * @brief Test Service @@ -32,12 +33,16 @@ class Service17Test : public PusServiceBase { EVENT_TRIGGER_TEST = 128, }; - Service17Test(object_id_t objectId, uint16_t apid, uint8_t serviceId); - virtual ~Service17Test(); - virtual ReturnValue_t handleRequest(uint8_t subservice) override; - virtual ReturnValue_t performService() override; + Service17Test(object_id_t objectId, uint16_t apid, uint8_t serviceId, + InternalErrorReporterIF* errReporter, StorageManagerIF* tmStore = nullptr, + StorageManagerIF* ipcStore = nullptr); + ~Service17Test() override; + ReturnValue_t handleRequest(uint8_t subservice) override; + ReturnValue_t performService() override; + ReturnValue_t initialize() override; protected: + TmStoreHelper helper; uint16_t packetSubCounter = 0; }; diff --git a/src/fsfw/tcdistribution/CCSDSDistributor.cpp b/src/fsfw/tcdistribution/CCSDSDistributor.cpp index f18e55de..9601825c 100644 --- a/src/fsfw/tcdistribution/CCSDSDistributor.cpp +++ b/src/fsfw/tcdistribution/CCSDSDistributor.cpp @@ -2,7 +2,7 @@ #include "fsfw/objectmanager/ObjectManager.h" #include "fsfw/serviceinterface/ServiceInterface.h" -#include "fsfw/tmtcpacket/SpacePacketReader.h" +#include "fsfw/tmtcpacket/ccsds/SpacePacketReader.h" #define CCSDS_DISTRIBUTOR_DEBUGGING 0 diff --git a/src/fsfw/tcdistribution/CcsdsPacketCheckerBase.cpp b/src/fsfw/tcdistribution/CcsdsPacketCheckerBase.cpp index 8c97f646..e1b6337f 100644 --- a/src/fsfw/tcdistribution/CcsdsPacketCheckerBase.cpp +++ b/src/fsfw/tcdistribution/CcsdsPacketCheckerBase.cpp @@ -1,7 +1,7 @@ #include "CcsdsPacketCheckerBase.h" #include "fsfw/tcdistribution/definitions.h" -#include "fsfw/tmtcpacket/SpacePacketReader.h" +#include "fsfw/tmtcpacket/ccsds/SpacePacketReader.h" CcsdsPacketCheckerBase::CcsdsPacketCheckerBase(uint16_t apid, ccsds::PacketType packetType_, uint8_t ccsdsVersion_) diff --git a/src/fsfw/tcdistribution/CcsdsPacketCheckerBase.h b/src/fsfw/tcdistribution/CcsdsPacketCheckerBase.h index f5a9b317..0f7f7e14 100644 --- a/src/fsfw/tcdistribution/CcsdsPacketCheckerBase.h +++ b/src/fsfw/tcdistribution/CcsdsPacketCheckerBase.h @@ -2,7 +2,7 @@ #define FSFW_TESTS_CCSDSPACKETCHECKERBASE_H #include "CcsdsPacketCheckIF.h" -#include "fsfw/tmtcpacket/SpacePacketIF.h" +#include "fsfw/tmtcpacket/ccsds/SpacePacketIF.h" class CcsdsPacketCheckerBase : public CcsdsPacketCheckIF, public HasReturnvaluesIF { public: diff --git a/src/fsfw/tmtcpacket/CMakeLists.txt b/src/fsfw/tmtcpacket/CMakeLists.txt index 69b3cc48..8c70d351 100644 --- a/src/fsfw/tmtcpacket/CMakeLists.txt +++ b/src/fsfw/tmtcpacket/CMakeLists.txt @@ -1,7 +1,6 @@ -target_sources( - ${LIB_FSFW_NAME} PRIVATE SpacePacketReader.cpp SpacePacketCreator.cpp - PacketStorageHelper.cpp) +target_sources(${LIB_FSFW_NAME} PRIVATE PacketStorageHelper.cpp) +add_subdirectory(ccsds) +add_subdirectory(pus) add_subdirectory(cfdp) add_subdirectory(packetmatcher) -add_subdirectory(pus) diff --git a/src/fsfw/tmtcpacket/ReadablePacketIF.h b/src/fsfw/tmtcpacket/ReadablePacketIF.h index c1287e81..01478273 100644 --- a/src/fsfw/tmtcpacket/ReadablePacketIF.h +++ b/src/fsfw/tmtcpacket/ReadablePacketIF.h @@ -1,7 +1,7 @@ #ifndef FSFW_TMTCPACKET_SPACEPACKETREADERIF_H #define FSFW_TMTCPACKET_SPACEPACKETREADERIF_H -#include "SpacePacketIF.h" +#include "fsfw/tmtcpacket/ccsds/SpacePacketIF.h" class ReadablePacketIF { public: diff --git a/src/fsfw/tmtcpacket/SpacePacketCreator.h b/src/fsfw/tmtcpacket/SpacePacketCreator.h deleted file mode 100644 index 9c74046b..00000000 --- a/src/fsfw/tmtcpacket/SpacePacketCreator.h +++ /dev/null @@ -1,87 +0,0 @@ -#ifndef FSFW_TMTCPACKET_SPACEPACKETCREATOR_H -#define FSFW_TMTCPACKET_SPACEPACKETCREATOR_H - -#include "SpacePacketIF.h" -#include "fsfw/serialize/SerializeIF.h" - -struct PacketId { - public: - /** - * Simple wrapper for Space Packet IDs. Does not check the APID for validity - * @param packetType_ - * @param secHeaderFlag_ - * @param apid_ - */ - PacketId(ccsds::PacketType packetType_, bool secHeaderFlag_, uint16_t apid_) - : packetType(packetType_), secHeaderFlag(secHeaderFlag_), apid(apid_) {} - - /** - * NOTE: If the APID has an invalid value, the invalid bits will be cut off - * @return - */ - [[nodiscard]] uint16_t raw() const { - return (static_cast(packetType) << 12) | - (static_cast(secHeaderFlag) << 11) | (apid & 0x7ff); - } - - ccsds::PacketType packetType; - bool secHeaderFlag; - uint16_t apid; -}; - -struct PacketSeqCtrl { - public: - PacketSeqCtrl(ccsds::SequenceFlags seqFlags, uint16_t seqCount) - : seqFlags(seqFlags), seqCount(seqCount) {} - - /** - * NOTE: If the sequence control has an invalid value, the invalid bits will be cut off - * @return - */ - [[nodiscard]] uint16_t raw() const { - return (static_cast(seqFlags) << 14) | (seqCount & 0x3FFF); - } - ccsds::SequenceFlags seqFlags; - uint16_t seqCount; -}; - -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); - */ - explicit SpacePacketCreator(SpacePacketParams ¶ms); - [[nodiscard]] bool isValid() const; - [[nodiscard]] uint16_t getPacketId() const override; - [[nodiscard]] uint16_t getPacketSeqCtrl() const override; - [[nodiscard]] uint16_t getPacketDataLen() const override; - - void setApid(uint16_t apid); - void setSeqCount(uint16_t seqCount); - void setSeqFlags(ccsds::SequenceFlags flags); - void setDataLen(uint16_t dataLen); - - ReturnValue_t serialize(uint8_t **buffer, size_t *size, size_t maxSize) const; - 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; - - private: - void checkFieldValidity(); - - bool valid{}; - SpacePacketParams params; -}; -#endif // FSFW_TMTCPACKET_SPACEPACKETCREATOR_H diff --git a/src/fsfw/tmtcpacket/ccsds/CMakeLists.txt b/src/fsfw/tmtcpacket/ccsds/CMakeLists.txt new file mode 100644 index 00000000..68efe09c --- /dev/null +++ b/src/fsfw/tmtcpacket/ccsds/CMakeLists.txt @@ -0,0 +1,2 @@ +target_sources(${LIB_FSFW_NAME} PRIVATE SpacePacketReader.cpp + SpacePacketCreator.cpp header.cpp) diff --git a/src/fsfw/tmtcpacket/ccsds/PacketId.h b/src/fsfw/tmtcpacket/ccsds/PacketId.h new file mode 100644 index 00000000..49587483 --- /dev/null +++ b/src/fsfw/tmtcpacket/ccsds/PacketId.h @@ -0,0 +1,68 @@ +#ifndef FSFW_TMTCPACKET_PACKETID_H +#define FSFW_TMTCPACKET_PACKETID_H + +#include + +#include "defs.h" +#include "fsfw/serialize/SerializeAdapter.h" +#include "fsfw/serialize/SerializeIF.h" + +struct PacketId : public SerializeIF { + public: + PacketId() = default; + /** + * Simple wrapper for Space Packet IDs. Does not check the APID for validity + * @param packetType_ + * @param secHeaderFlag_ + * @param apid_ + */ + PacketId(ccsds::PacketType packetType_, bool secHeaderFlag_, uint16_t apid_) + : packetType(packetType_), secHeaderFlag(secHeaderFlag_), apid(apid_) {} + + /** + * NOTE: If the APID has an invalid value, the invalid bits will be cut off + * @return + */ + [[nodiscard]] uint16_t raw() const { + return (static_cast(packetType) << 12) | + (static_cast(secHeaderFlag) << 11) | (apid & 0x7ff); + } + + static PacketId fromRaw(uint16_t raw) { + uint8_t highByte = (raw >> 8) & 0xff; + uint8_t lowByte = raw & 0xff; + return {static_cast((highByte >> 4) & 0b1), + static_cast((highByte >> 3) & 0b1), + static_cast((highByte & 0b111) << 8 | lowByte)}; + } + + ReturnValue_t serialize(uint8_t **buffer, size_t *size, size_t maxSize, + Endianness streamEndianness) const override { + uint16_t pscRaw = raw(); + return SerializeAdapter::serialize(&pscRaw, buffer, size, maxSize, streamEndianness); + } + + [[nodiscard]] size_t getSerializedSize() const override { return 2; } + + ReturnValue_t deSerialize(const uint8_t **buffer, size_t *size, + Endianness streamEndianness) override { + if (*size < 2) { + return SerializeIF::STREAM_TOO_SHORT; + } + uint8_t highByte = **buffer; + *buffer += 1; + uint8_t lowByte = **buffer; + *buffer += 1; + *size -= 2; + packetType = static_cast((highByte >> 4) & 0b1); + secHeaderFlag = (highByte >> 3) & 0b1; + apid = static_cast((highByte & 0b111) << 8 | lowByte); + return HasReturnvaluesIF::RETURN_OK; + } + + ccsds::PacketType packetType = ccsds::PacketType::TM; + bool secHeaderFlag = false; + uint16_t apid = 0; +}; + +#endif // FSFW_TMTCPACKET_PACKETID_H diff --git a/src/fsfw/tmtcpacket/ccsds/PacketSeqCtrl.h b/src/fsfw/tmtcpacket/ccsds/PacketSeqCtrl.h new file mode 100644 index 00000000..830a6fa2 --- /dev/null +++ b/src/fsfw/tmtcpacket/ccsds/PacketSeqCtrl.h @@ -0,0 +1,56 @@ +#ifndef FSFW_TMTCPACKET_PACKETSEQCTRL_H +#define FSFW_TMTCPACKET_PACKETSEQCTRL_H + +#include "defs.h" +#include "fsfw/serialize/SerializeAdapter.h" +#include "fsfw/serialize/SerializeIF.h" + +struct PacketSeqCtrl : public SerializeIF { + public: + PacketSeqCtrl() = default; + + PacketSeqCtrl(ccsds::SequenceFlags seqFlags, uint16_t seqCount) + : seqFlags(seqFlags), seqCount(seqCount) {} + + /** + * NOTE: If the sequence control has an invalid value, the invalid bits will be cut off + * @return + */ + [[nodiscard]] uint16_t raw() const { + return (static_cast(seqFlags) << 14) | (seqCount & 0x3FFF); + } + + static PacketSeqCtrl fromRaw(uint16_t raw) { + uint8_t highByte = (raw >> 8) & 0xff; + uint8_t lowByte = raw & 0xff; + return {static_cast((highByte >> 6) & 0b11), + static_cast(((highByte << 8) | lowByte) & 0x3FFF)}; + } + + ReturnValue_t serialize(uint8_t **buffer, size_t *size, size_t maxSize, + Endianness streamEndianness) const override { + uint16_t packetIdRaw = raw(); + return SerializeAdapter::serialize(&packetIdRaw, buffer, size, maxSize, streamEndianness); + } + [[nodiscard]] size_t getSerializedSize() const override { return 2; } + + ReturnValue_t deSerialize(const uint8_t **buffer, size_t *size, + Endianness streamEndianness) override { + if (*size < 2) { + return SerializeIF::STREAM_TOO_SHORT; + } + uint8_t highByte = **buffer; + *buffer += 1; + uint8_t lowByte = **buffer; + *buffer += 1; + *size -= 2; + seqFlags = static_cast((highByte >> 6) & 0b11); + seqCount = ((highByte << 8) | lowByte) & 0x3FFF; + return HasReturnvaluesIF::RETURN_OK; + } + + ccsds::SequenceFlags seqFlags = ccsds::SequenceFlags::CONTINUATION; + uint16_t seqCount = 0; +}; + +#endif // FSFW_TMTCPACKET_PACKETSEQCTRL_H diff --git a/src/fsfw/tmtcpacket/SpacePacketCreator.cpp b/src/fsfw/tmtcpacket/ccsds/SpacePacketCreator.cpp similarity index 75% rename from src/fsfw/tmtcpacket/SpacePacketCreator.cpp rename to src/fsfw/tmtcpacket/ccsds/SpacePacketCreator.cpp index ff131059..ce1852ab 100644 --- a/src/fsfw/tmtcpacket/SpacePacketCreator.cpp +++ b/src/fsfw/tmtcpacket/ccsds/SpacePacketCreator.cpp @@ -1,13 +1,23 @@ #include "SpacePacketCreator.h" +#include + #include "fsfw/serialize/SerializeAdapter.h" -SpacePacketCreator::SpacePacketCreator(SpacePacketParams ¶ms_) : params(params_) { +SpacePacketCreator::SpacePacketCreator(SpacePacketParams params_) : params(std::move(params_)) { checkFieldValidity(); } -uint16_t SpacePacketCreator::getPacketId() const { return params.packetId.raw(); } -uint16_t SpacePacketCreator::getPacketSeqCtrl() const { return params.packetSeqCtrl.raw(); } +SpacePacketCreator::SpacePacketCreator(ccsds::PacketType packetType, bool secHeaderFlag, + uint16_t apid, ccsds::SequenceFlags seqFlags, + uint16_t seqCount, uint16_t dataLen, uint8_t version) + : params(SpacePacketParams(PacketId(packetType, secHeaderFlag, apid), + PacketSeqCtrl(seqFlags, seqCount), dataLen)) { + params.version = version; +} + +uint16_t SpacePacketCreator::getPacketIdRaw() const { return params.packetId.raw(); } +uint16_t SpacePacketCreator::getPacketSeqCtrlRaw() 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, diff --git a/src/fsfw/tmtcpacket/ccsds/SpacePacketCreator.h b/src/fsfw/tmtcpacket/ccsds/SpacePacketCreator.h new file mode 100644 index 00000000..5e2888c0 --- /dev/null +++ b/src/fsfw/tmtcpacket/ccsds/SpacePacketCreator.h @@ -0,0 +1,53 @@ +#ifndef FSFW_TMTCPACKET_SPACEPACKETCREATOR_H +#define FSFW_TMTCPACKET_SPACEPACKETCREATOR_H + +#include + +#include "PacketId.h" +#include "PacketSeqCtrl.h" +#include "SpacePacketIF.h" +#include "fsfw/serialize/SerializeIF.h" + +struct SpacePacketParams { + SpacePacketParams(PacketId packetId, PacketSeqCtrl psc, uint16_t dataLen) + : packetId(std::move(packetId)), packetSeqCtrl(std::move(psc)), dataLen(dataLen) {} + + PacketId packetId{}; + PacketSeqCtrl packetSeqCtrl{}; + uint16_t dataLen = 0; + uint8_t version = 0b000; +}; + +class SpacePacketCreator : public SpacePacketIF, public SerializeIF { + public: + explicit SpacePacketCreator(SpacePacketParams params); + SpacePacketCreator(ccsds::PacketType packetType, bool secHeaderFlag, uint16_t apid, + ccsds::SequenceFlags seqFlags, uint16_t seqCount, uint16_t dataLen, + uint8_t version = 0); + + [[nodiscard]] bool isValid() const; + [[nodiscard]] uint16_t getPacketIdRaw() const override; + [[nodiscard]] uint16_t getPacketSeqCtrlRaw() const override; + [[nodiscard]] uint16_t getPacketDataLen() const override; + + void setApid(uint16_t apid); + void setSeqCount(uint16_t seqCount); + void setSeqFlags(ccsds::SequenceFlags flags); + void setDataLen(uint16_t dataLen); + + ReturnValue_t serialize(uint8_t **buffer, size_t *size, size_t maxSize) const; + 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; + + private: + void checkFieldValidity(); + + SpacePacketCreator() = default; + bool valid{}; + SpacePacketParams params; +}; +#endif // FSFW_TMTCPACKET_SPACEPACKETCREATOR_H diff --git a/src/fsfw/tmtcpacket/SpacePacketIF.h b/src/fsfw/tmtcpacket/ccsds/SpacePacketIF.h similarity index 56% rename from src/fsfw/tmtcpacket/SpacePacketIF.h rename to src/fsfw/tmtcpacket/ccsds/SpacePacketIF.h index 21ee4c32..5db7b254 100644 --- a/src/fsfw/tmtcpacket/SpacePacketIF.h +++ b/src/fsfw/tmtcpacket/ccsds/SpacePacketIF.h @@ -4,37 +4,10 @@ #include #include -#include "ccsds_header.h" - -namespace ccsds { - -enum PacketType : uint8_t { TM = 0, TC = 1 }; - -enum SequenceFlags : uint8_t { - CONTINUATION = 0b00, - FIRST_SEGMENT = 0b01, - LAST_SEGMENT = 0b10, - UNSEGMENTED = 0b11 -}; - -static const uint16_t LIMIT_APID = 2048; // 2^11 -static const uint16_t LIMIT_SEQUENCE_COUNT = 16384; // 2^14 -static const uint16_t APID_IDLE_PACKET = 0x7FF; - -constexpr uint16_t getSpacePacketIdFromApid(bool isTc, uint16_t apid, - bool secondaryHeaderFlag = true) { - return ((isTc << 4) | (secondaryHeaderFlag << 3) | ((apid >> 8) & 0x07)) << 8 | (apid & 0x00ff); -} - -constexpr uint16_t getTcSpacePacketIdFromApid(uint16_t apid, bool secondaryHeaderFlag = true) { - return getSpacePacketIdFromApid(true, apid, secondaryHeaderFlag); -} - -constexpr uint16_t getTmSpacePacketIdFromApid(uint16_t apid, bool secondaryHeaderFlag = true) { - return getSpacePacketIdFromApid(false, apid, secondaryHeaderFlag); -} - -} // namespace ccsds +#include "PacketId.h" +#include "PacketSeqCtrl.h" +#include "fsfw/tmtcpacket/ccsds/defs.h" +#include "header.h" class SpacePacketIF { public: @@ -45,7 +18,7 @@ class SpacePacketIF { /** * This is the minimum size of a SpacePacket. */ - static const uint16_t MINIMUM_SIZE = sizeof(CCSDSPrimaryHeader) + CRC_SIZE; + static const uint16_t MINIMUM_SIZE = sizeof(ccsds::PrimaryHeader) + CRC_SIZE; virtual ~SpacePacketIF() = default; @@ -54,21 +27,25 @@ class SpacePacketIF { * the CCSDS packet ID * @return The CCSDS packet ID */ - [[nodiscard]] virtual uint16_t getPacketId() const = 0; + [[nodiscard]] virtual uint16_t getPacketIdRaw() const = 0; /** * Returns the third and the fourth byte of the CCSDS header which are the packet sequence * control field * @return */ - [[nodiscard]] virtual uint16_t getPacketSeqCtrl() const = 0; + [[nodiscard]] virtual uint16_t getPacketSeqCtrlRaw() const = 0; /** * Returns the fifth and the sixth byte of the CCSDS header which is the packet length field * @return */ [[nodiscard]] virtual uint16_t getPacketDataLen() const = 0; + virtual PacketId getPacketId() { return PacketId::fromRaw(getPacketIdRaw()); } + + virtual PacketSeqCtrl getPacketSeqCtrl() { return PacketSeqCtrl::fromRaw(getPacketSeqCtrlRaw()); } + [[nodiscard]] virtual uint16_t getApid() const { - uint16_t packetId = getPacketId(); + uint16_t packetId = getPacketIdRaw(); // Uppermost 11 bits of packet ID return ((packetId >> 8) & 0b111) | (packetId & 0xFF); } @@ -78,12 +55,12 @@ class SpacePacketIF { * @return */ [[nodiscard]] virtual uint8_t getVersion() const { - uint16_t packetId = getPacketId(); + uint16_t packetId = getPacketIdRaw(); return (packetId >> 13) & 0b111; } [[nodiscard]] virtual ccsds::PacketType getPacketType() const { - return static_cast((getPacketId() >> 12) & 0b1); + return static_cast((getPacketIdRaw() >> 12) & 0b1); } [[nodiscard]] virtual bool isTc() const { return getPacketType() == ccsds::PacketType::TC; } @@ -95,20 +72,20 @@ class SpacePacketIF { * which is checked with this method. * @return Returns true if the bit is set and false if not. */ - [[nodiscard]] virtual bool hasSecHeader() const { return (getPacketId() >> 11) & 0b1; } + [[nodiscard]] virtual bool hasSecHeader() const { return (getPacketIdRaw() >> 11) & 0b1; } [[nodiscard]] virtual ccsds::SequenceFlags getSequenceFlags() const { - return static_cast(getPacketSeqCtrl() >> 14 & 0b11); + return static_cast(getPacketSeqCtrlRaw() >> 14 & 0b11); } - [[nodiscard]] virtual uint16_t getSequenceCount() const { return getPacketSeqCtrl() & 0x3FFF; } + [[nodiscard]] virtual uint16_t getSequenceCount() const { return getPacketSeqCtrlRaw() & 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; + return ccsds::HEADER_LEN + getPacketDataLen() + 1; } }; diff --git a/src/fsfw/tmtcpacket/SpacePacketReader.cpp b/src/fsfw/tmtcpacket/ccsds/SpacePacketReader.cpp similarity index 62% rename from src/fsfw/tmtcpacket/SpacePacketReader.cpp rename to src/fsfw/tmtcpacket/ccsds/SpacePacketReader.cpp index 2d7d2eda..a0ad5328 100644 --- a/src/fsfw/tmtcpacket/SpacePacketReader.cpp +++ b/src/fsfw/tmtcpacket/ccsds/SpacePacketReader.cpp @@ -1,4 +1,4 @@ -#include "fsfw/tmtcpacket/SpacePacketReader.h" +#include "SpacePacketReader.h" #include @@ -18,27 +18,24 @@ ReturnValue_t SpacePacketReader::checkLength() const { SpacePacketReader::~SpacePacketReader() = default; -inline uint16_t SpacePacketReader::getPacketId() const { - return ((spHeader->packetIdHAndVersion) << 8) + spHeader->packetIdL; -} +inline uint16_t SpacePacketReader::getPacketIdRaw() const { return ccsds::getPacketId(*spHeader); } const uint8_t* SpacePacketReader::getPacketData() { return packetDataField; } ReturnValue_t SpacePacketReader::setData(uint8_t* pData, size_t maxSize_, void* args) { setInternalFields(pData, maxSize_); + return HasReturnvaluesIF::RETURN_OK; } -uint16_t SpacePacketReader::getPacketSeqCtrl() const { - return (spHeader->packetSeqCtrlH << 8) + spHeader->packetSeqCtrlL; +uint16_t SpacePacketReader::getPacketSeqCtrlRaw() const { + return ccsds::getPacketSeqCtrl(*spHeader); } -uint16_t SpacePacketReader::getPacketDataLen() const { - return (spHeader->packetLenH << 8) | spHeader->packetIdL; -} +uint16_t SpacePacketReader::getPacketDataLen() const { return ccsds::getPacketLen(*spHeader); } void SpacePacketReader::setInternalFields(const uint8_t* data, size_t maxSize_) { maxSize = maxSize_; - spHeader = reinterpret_cast(data); - packetDataField = data + sizeof(CCSDSPrimaryHeader); + spHeader = reinterpret_cast(data); + packetDataField = data + ccsds::HEADER_LEN; } const uint8_t* SpacePacketReader::getFullData() { return reinterpret_cast(spHeader); diff --git a/src/fsfw/tmtcpacket/SpacePacketReader.h b/src/fsfw/tmtcpacket/ccsds/SpacePacketReader.h similarity index 88% rename from src/fsfw/tmtcpacket/SpacePacketReader.h rename to src/fsfw/tmtcpacket/ccsds/SpacePacketReader.h index eb1d5c93..43119146 100644 --- a/src/fsfw/tmtcpacket/SpacePacketReader.h +++ b/src/fsfw/tmtcpacket/ccsds/SpacePacketReader.h @@ -1,13 +1,12 @@ #ifndef FSFW_TMTCPACKET_SPACEPACKETBASE_H_ #define FSFW_TMTCPACKET_SPACEPACKETBASE_H_ -#include - #include -#include "ReadablePacketIF.h" -#include "ccsds_header.h" #include "fsfw/returnvalues/HasReturnvaluesIF.h" +#include "fsfw/tmtcpacket/ReadablePacketIF.h" +#include "fsfw/tmtcpacket/RedirectableDataPointerIF.h" +#include "fsfw/tmtcpacket/ccsds/defs.h" /** * @defgroup tmtcpackets Space Packets @@ -46,8 +45,8 @@ class SpacePacketReader : public SpacePacketIF, */ ~SpacePacketReader() override; - [[nodiscard]] uint16_t getPacketId() const override; - [[nodiscard]] uint16_t getPacketSeqCtrl() const override; + [[nodiscard]] uint16_t getPacketIdRaw() const override; + [[nodiscard]] uint16_t getPacketSeqCtrlRaw() const override; [[nodiscard]] uint16_t getPacketDataLen() const override; const uint8_t* getFullData() override; @@ -70,7 +69,7 @@ class SpacePacketReader : public SpacePacketIF, * the packet header. * To be hardware-safe, all elements are of byte size. */ - const CCSDSPrimaryHeader* spHeader{}; + const ccsds::PrimaryHeader* spHeader{}; const uint8_t* packetDataField{}; size_t maxSize = 0; diff --git a/src/fsfw/tmtcpacket/ccsds/defs.h b/src/fsfw/tmtcpacket/ccsds/defs.h new file mode 100644 index 00000000..1c7de540 --- /dev/null +++ b/src/fsfw/tmtcpacket/ccsds/defs.h @@ -0,0 +1,36 @@ +#ifndef CCSDS_HEADER_H_ +#define CCSDS_HEADER_H_ + +#include + +namespace ccsds { + +enum PacketType : uint8_t { TM = 0, TC = 1 }; + +enum SequenceFlags : uint8_t { + CONTINUATION = 0b00, + FIRST_SEGMENT = 0b01, + LAST_SEGMENT = 0b10, + UNSEGMENTED = 0b11 +}; + +static const uint16_t LIMIT_APID = 2048; // 2^11 +static const uint16_t LIMIT_SEQUENCE_COUNT = 16384; // 2^14 +static const uint16_t APID_IDLE_PACKET = 0x7FF; + +constexpr uint16_t getSpacePacketIdFromApid(bool isTc, uint16_t apid, + bool secondaryHeaderFlag = true) { + return ((isTc << 4) | (secondaryHeaderFlag << 3) | ((apid >> 8) & 0x07)) << 8 | (apid & 0x00ff); +} + +constexpr uint16_t getTcSpacePacketIdFromApid(uint16_t apid, bool secondaryHeaderFlag = true) { + return getSpacePacketIdFromApid(true, apid, secondaryHeaderFlag); +} + +constexpr uint16_t getTmSpacePacketIdFromApid(uint16_t apid, bool secondaryHeaderFlag = true) { + return getSpacePacketIdFromApid(false, apid, secondaryHeaderFlag); +} + +} // namespace ccsds + +#endif /* CCSDS_HEADER_H_ */ diff --git a/src/fsfw/tmtcpacket/ccsds/header.cpp b/src/fsfw/tmtcpacket/ccsds/header.cpp new file mode 100644 index 00000000..b7aa270e --- /dev/null +++ b/src/fsfw/tmtcpacket/ccsds/header.cpp @@ -0,0 +1,29 @@ +#include "header.h" + +uint16_t ccsds::getPacketId(const PrimaryHeader &header) { + return ((header.packetIdHAndVersion & 0x1F00) << 8) + header.packetIdL; +} + +uint16_t ccsds::getPacketSeqCtrl(const PrimaryHeader &header) { + return (header.packetSeqCtrlH << 8) | header.packetSeqCtrlL; +} + +uint8_t ccsds::getVersion(const PrimaryHeader &header) { + return (header.packetIdHAndVersion >> 5) & 0b111; +} + +uint16_t ccsds::getPacketLen(const PrimaryHeader &header) { + return (header.packetLenH << 8) | header.packetLenL; +} + +void ccsds::setPacketId(PrimaryHeader &header, uint16_t packetId) { + header.packetIdHAndVersion = (packetId >> 8) & 0x1F; + header.packetIdL = packetId & 0xff; +} + +void ccsds::setApid(PrimaryHeader &header, uint16_t apid) { + uint16_t packetIdRaw = getPacketId(header); + packetIdRaw &= ~0x7FF; + packetIdRaw |= apid & 0x7FF; + setPacketId(header, packetIdRaw); +} diff --git a/src/fsfw/tmtcpacket/ccsds/header.h b/src/fsfw/tmtcpacket/ccsds/header.h new file mode 100644 index 00000000..d416f697 --- /dev/null +++ b/src/fsfw/tmtcpacket/ccsds/header.h @@ -0,0 +1,30 @@ +#ifndef FSFW_TMTCPACKET_HEADER_H +#define FSFW_TMTCPACKET_HEADER_H + +#include +#include + +namespace ccsds { + +static constexpr size_t HEADER_LEN = 6; + +struct PrimaryHeader { + uint8_t packetIdHAndVersion; + uint8_t packetIdL; + uint8_t packetSeqCtrlH; + uint8_t packetSeqCtrlL; + uint8_t packetLenH; + uint8_t packetLenL; +}; + +uint16_t getPacketId(const PrimaryHeader& header); +uint16_t getPacketSeqCtrl(const PrimaryHeader& header); +uint8_t getVersion(const PrimaryHeader& header); +uint16_t getPacketLen(const PrimaryHeader& header); + +void setPacketId(PrimaryHeader& header, uint16_t packetId); +void setApid(PrimaryHeader& header, uint16_t apid); + +} // namespace ccsds + +#endif // FSFW_TMTCPACKET_HEADER_H diff --git a/src/fsfw/tmtcpacket/ccsds_header.h b/src/fsfw/tmtcpacket/ccsds_header.h deleted file mode 100644 index c0db194e..00000000 --- a/src/fsfw/tmtcpacket/ccsds_header.h +++ /dev/null @@ -1,15 +0,0 @@ -#ifndef CCSDS_HEADER_H_ -#define CCSDS_HEADER_H_ - -#include - -struct CCSDSPrimaryHeader { - uint8_t packetIdHAndVersion; - uint8_t packetIdL; - uint8_t packetSeqCtrlH; - uint8_t packetSeqCtrlL; - uint8_t packetLenH; - uint8_t packetLenL; -}; - -#endif /* CCSDS_HEADER_H_ */ diff --git a/src/fsfw/tmtcpacket/cfdp/CfdpPacket.h b/src/fsfw/tmtcpacket/cfdp/CfdpPacket.h index e47d3b6f..e391202f 100644 --- a/src/fsfw/tmtcpacket/cfdp/CfdpPacket.h +++ b/src/fsfw/tmtcpacket/cfdp/CfdpPacket.h @@ -1,7 +1,7 @@ #ifndef FSFW_INC_FSFW_TMTCPACKET_CFDP_CFDPPACKET_H_ #define FSFW_INC_FSFW_TMTCPACKET_CFDP_CFDPPACKET_H_ -#include "fsfw/tmtcpacket/SpacePacketReader.h" +#include "fsfw/tmtcpacket/ccsds/SpacePacketReader.h" class CfdpReader : public SpacePacketReader { public: diff --git a/src/fsfw/tmtcpacket/packetmatcher/PacketMatchTree.cpp b/src/fsfw/tmtcpacket/packetmatcher/PacketMatchTree.cpp index 1ab8729b..c1f6665a 100644 --- a/src/fsfw/tmtcpacket/packetmatcher/PacketMatchTree.cpp +++ b/src/fsfw/tmtcpacket/packetmatcher/PacketMatchTree.cpp @@ -32,8 +32,8 @@ PacketMatchTree::~PacketMatchTree() = default; ReturnValue_t PacketMatchTree::addMatch(uint16_t apid, uint8_t type, uint8_t subtype) { // We assume adding APID is always requested. PusTmMinimal::TmPacketMinimalPointer data{}; - data.secHeader.service_type = type; - data.secHeader.service_subtype = subtype; + data.secHeader.service = type; + data.secHeader.subservice = subtype; PusTmMinimal testPacket((uint8_t*)&data); testPacket.setApid(apid); @@ -122,13 +122,13 @@ ReturnValue_t PacketMatchTree::findOrInsertMatch(iterator startAt, VALUE_T test, } ReturnValue_t PacketMatchTree::removeMatch(uint16_t apid, uint8_t type, uint8_t subtype) { - PusTmMinimal::TmPacketMinimalPointer data; - data.secHeader.service_type = type; - data.secHeader.service_subtype = subtype; + PusTmMinimal::TmPacketMinimalPointer data{}; + data.secHeader.service = type; + data.secHeader.subservice = subtype; PusTmMinimal testPacket((uint8_t*)&data); testPacket.setApid(apid); iterator foundElement = findMatch(begin(), &testPacket); - if (foundElement == this->end()) { + if (foundElement == PacketMatchTree::end()) { return NO_MATCH; } if (type == 0) { diff --git a/src/fsfw/tmtcpacket/pus/PusIF.h b/src/fsfw/tmtcpacket/pus/PusIF.h index 61d4fcff..5eeae04d 100644 --- a/src/fsfw/tmtcpacket/pus/PusIF.h +++ b/src/fsfw/tmtcpacket/pus/PusIF.h @@ -3,7 +3,7 @@ #include -#include "fsfw/tmtcpacket/SpacePacketIF.h" +#include "fsfw/tmtcpacket/ccsds/SpacePacketIF.h" class PusIF : public SpacePacketIF { public: diff --git a/src/fsfw/tmtcpacket/pus/tc/PusTcCreator.cpp b/src/fsfw/tmtcpacket/pus/tc/PusTcCreator.cpp index cbd6da53..7de759c8 100644 --- a/src/fsfw/tmtcpacket/pus/tc/PusTcCreator.cpp +++ b/src/fsfw/tmtcpacket/pus/tc/PusTcCreator.cpp @@ -51,9 +51,9 @@ ReturnValue_t PusTcCreator::deSerialize(const uint8_t **buffer, size_t *size, return HasReturnvaluesIF::RETURN_FAILED; } -uint16_t PusTcCreator::getPacketId() const { return spCreator.getPacketId(); } +uint16_t PusTcCreator::getPacketIdRaw() const { return spCreator.getPacketIdRaw(); } -uint16_t PusTcCreator::getPacketSeqCtrl() const { return spCreator.getPacketSeqCtrl(); } +uint16_t PusTcCreator::getPacketSeqCtrlRaw() const { return spCreator.getPacketSeqCtrlRaw(); } uint16_t PusTcCreator::getPacketDataLen() const { return spCreator.getPacketDataLen(); } diff --git a/src/fsfw/tmtcpacket/pus/tc/PusTcCreator.h b/src/fsfw/tmtcpacket/pus/tc/PusTcCreator.h index ffa2ed7c..cc220fa9 100644 --- a/src/fsfw/tmtcpacket/pus/tc/PusTcCreator.h +++ b/src/fsfw/tmtcpacket/pus/tc/PusTcCreator.h @@ -2,8 +2,8 @@ #define FSFW_TMTCPACKET_TCPACKETDESERIALIZER_H #include "fsfw/tmtcpacket/RedirectableDataPointerIF.h" -#include "fsfw/tmtcpacket/SpacePacketCreator.h" -#include "fsfw/tmtcpacket/SpacePacketIF.h" +#include "fsfw/tmtcpacket/ccsds/SpacePacketCreator.h" +#include "fsfw/tmtcpacket/ccsds/SpacePacketIF.h" #include "fsfw/tmtcpacket/pus/definitions.h" #include "fsfw/tmtcpacket/pus/tc/PusTcIF.h" @@ -29,8 +29,8 @@ class PusTcCreator : public PusTcIF, public SerializeIF { [[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 getPacketIdRaw() const override; + [[nodiscard]] uint16_t getPacketSeqCtrlRaw() const override; [[nodiscard]] uint16_t getPacketDataLen() const override; [[nodiscard]] uint8_t getPusVersion() const override; [[nodiscard]] uint8_t getAcknowledgeFlags() const override; diff --git a/src/fsfw/tmtcpacket/pus/tc/PusTcIF.h b/src/fsfw/tmtcpacket/pus/tc/PusTcIF.h index a8204a1f..889260c1 100644 --- a/src/fsfw/tmtcpacket/pus/tc/PusTcIF.h +++ b/src/fsfw/tmtcpacket/pus/tc/PusTcIF.h @@ -45,7 +45,7 @@ class PusTcIF : public PusIF { public: ~PusTcIF() override = default; static const size_t MIN_LEN = - (sizeof(CCSDSPrimaryHeader) + ecss::PusTcDataFieldHeader::MIN_LEN + 2); + (sizeof(ccsds::PrimaryHeader) + ecss::PusTcDataFieldHeader::MIN_LEN + 2); /** * This is a getter for the packet's Ack field, which are the lowest four diff --git a/src/fsfw/tmtcpacket/pus/tc/PusTcReader.cpp b/src/fsfw/tmtcpacket/pus/tc/PusTcReader.cpp index 0ead9bde..43c30a46 100644 --- a/src/fsfw/tmtcpacket/pus/tc/PusTcReader.cpp +++ b/src/fsfw/tmtcpacket/pus/tc/PusTcReader.cpp @@ -21,10 +21,10 @@ ReturnValue_t PusTcReader::parseData() { } // Might become variable sized field in the future size_t secHeaderLen = ecss::PusTcDataFieldHeader::MIN_LEN; - pointers.secHeaderStart = pointers.spHeaderStart + sizeof(CCSDSPrimaryHeader); + pointers.secHeaderStart = pointers.spHeaderStart + ccsds::HEADER_LEN; // TODO: No support for spare bytes yet pointers.userDataStart = pointers.secHeaderStart + secHeaderLen; - appDataSize = size - (sizeof(CCSDSPrimaryHeader) + secHeaderLen); + appDataSize = size - (ccsds::HEADER_LEN + secHeaderLen); pointers.crcStart = pointers.userDataStart + appDataSize; return HasReturnvaluesIF::RETURN_OK; } @@ -50,8 +50,8 @@ 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::getPacketIdRaw() const { return spReader.getPacketIdRaw(); } +uint16_t PusTcReader::getPacketSeqCtrlRaw() const { return spReader.getPacketSeqCtrlRaw(); } uint16_t PusTcReader::getPacketDataLen() const { return spReader.getPacketDataLen(); } uint8_t PusTcReader::getPusVersion() const { return spReader.getVersion(); } const uint8_t* PusTcReader::getFullData() { return pointers.spHeaderStart; } @@ -64,6 +64,7 @@ ReturnValue_t PusTcReader::setData(uint8_t* pData, size_t size_, void* args) { } ReturnValue_t PusTcReader::setData(const uint8_t* data, size_t size_) { setData(const_cast(data), size_, nullptr); + return HasReturnvaluesIF::RETURN_OK; } /* diff --git a/src/fsfw/tmtcpacket/pus/tc/PusTcReader.h b/src/fsfw/tmtcpacket/pus/tc/PusTcReader.h index 85623980..b2045761 100644 --- a/src/fsfw/tmtcpacket/pus/tc/PusTcReader.h +++ b/src/fsfw/tmtcpacket/pus/tc/PusTcReader.h @@ -5,7 +5,7 @@ #include "PusTcIF.h" #include "fsfw/tmtcpacket/RedirectableDataPointerIF.h" -#include "fsfw/tmtcpacket/SpacePacketReader.h" +#include "fsfw/tmtcpacket/ccsds/SpacePacketReader.h" /** * This class is the basic data handler for any ECSS PUS Telecommand packet. @@ -40,8 +40,8 @@ class PusTcReader : public PusTcIF, public ReadablePacketIF, public Redirectable * to the screen. */ // void print(); - [[nodiscard]] uint16_t getPacketId() const override; - [[nodiscard]] uint16_t getPacketSeqCtrl() const override; + [[nodiscard]] uint16_t getPacketIdRaw() const override; + [[nodiscard]] uint16_t getPacketSeqCtrlRaw() const override; [[nodiscard]] uint16_t getPacketDataLen() const override; [[nodiscard]] uint8_t getPusVersion() const override; [[nodiscard]] uint8_t getAcknowledgeFlags() const override; diff --git a/src/fsfw/tmtcpacket/pus/tc/TcPacketPus.h b/src/fsfw/tmtcpacket/pus/tc/TcPacketPus.h index bb2b3642..fe976673 100644 --- a/src/fsfw/tmtcpacket/pus/tc/TcPacketPus.h +++ b/src/fsfw/tmtcpacket/pus/tc/TcPacketPus.h @@ -6,7 +6,7 @@ #include "../definitions.h" #include "PusTcReader.h" #include "fsfw/FSFW.h" -#include "fsfw/tmtcpacket/ccsds_header.h" +#include "fsfw/tmtcpacket/ccsds/defs.h" /** * This struct defines the data structure of a PUS Telecommand A packet when diff --git a/src/fsfw/tmtcpacket/pus/tm/PusTmCreator.cpp b/src/fsfw/tmtcpacket/pus/tm/PusTmCreator.cpp index 5a1f4144..acf0435d 100644 --- a/src/fsfw/tmtcpacket/pus/tm/PusTmCreator.cpp +++ b/src/fsfw/tmtcpacket/pus/tm/PusTmCreator.cpp @@ -1,10 +1,12 @@ #include "PusTmCreator.h" -PusTmCreator::PusTmCreator(PusTmParams params_) : params(params_){}; +PusTmCreator::PusTmCreator(PusTmParams& params_) : params(params_){}; -uint16_t PusTmCreator::getPacketId() const { return 0; } -uint16_t PusTmCreator::getPacketSeqCtrl() const { return 0; } +uint16_t PusTmCreator::getPacketIdRaw() const { return 0; } +uint16_t PusTmCreator::getPacketSeqCtrlRaw() 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; } +const uint8_t* PusTmCreator::getUserData(size_t& appDataLen) const { return nullptr; } +uint16_t PusTmCreator::getUserDataSize() const { return 0; } diff --git a/src/fsfw/tmtcpacket/pus/tm/PusTmCreator.h b/src/fsfw/tmtcpacket/pus/tm/PusTmCreator.h index fbdeb7d9..4a45e904 100644 --- a/src/fsfw/tmtcpacket/pus/tm/PusTmCreator.h +++ b/src/fsfw/tmtcpacket/pus/tm/PusTmCreator.h @@ -16,16 +16,18 @@ struct PusTmParams { class PusTmCreator : public PusIF { public: ~PusTmCreator() override = default; - explicit PusTmCreator(PusTmParams params); + explicit PusTmCreator(PusTmParams& params); - [[nodiscard]] uint16_t getPacketId() const override; - [[nodiscard]] uint16_t getPacketSeqCtrl() const override; + [[nodiscard]] uint16_t getPacketIdRaw() const override; + [[nodiscard]] uint16_t getPacketSeqCtrlRaw() 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; private: - PusTmParams params; + PusTmParams& params; }; #endif // FSFW_TMTCPACKET_TMPACKETCREATOR_H diff --git a/src/fsfw/tmtcpacket/pus/tm/PusTmMinimal.cpp b/src/fsfw/tmtcpacket/pus/tm/PusTmMinimal.cpp index 4042528a..f2cc7fcc 100644 --- a/src/fsfw/tmtcpacket/pus/tm/PusTmMinimal.cpp +++ b/src/fsfw/tmtcpacket/pus/tm/PusTmMinimal.cpp @@ -5,8 +5,9 @@ #include "fsfw/tmtcpacket/pus/PacketTimestampInterpreterIF.h" +PusTmMinimal::PusTmMinimal(mintm::MinimalPusTm* data) { tmData = data; } PusTmMinimal::PusTmMinimal(uint8_t* data) { - this->tmData = reinterpret_cast(data); + this->tmData = reinterpret_cast(data); } PusTmMinimal::~PusTmMinimal() = default; @@ -27,8 +28,8 @@ void PusTmMinimal::setInterpretTimestampObject(PacketTimestampInterpreterIF* int 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::getPacketIdRaw() const { return 0; } +uint16_t PusTmMinimal::getPacketSeqCtrlRaw() 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; } @@ -36,7 +37,9 @@ uint8_t PusTmMinimal::getSubService() const { return tmData->secHeader.subservic 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::getMessageTypeCounter() { + return (tmData->secHeader.messageTypeH << 8) | tmData->secHeader.messageTypeL; +} uint16_t PusTmMinimal::getDestId() { return 0; } const uint8_t* PusTmMinimal::getTimestamp(size_t& timeStampLen) { return nullptr; } size_t PusTmMinimal::getTimestampLen() { return 0; } diff --git a/src/fsfw/tmtcpacket/pus/tm/PusTmMinimal.h b/src/fsfw/tmtcpacket/pus/tm/PusTmMinimal.h index a09523fb..b9146def 100644 --- a/src/fsfw/tmtcpacket/pus/tm/PusTmMinimal.h +++ b/src/fsfw/tmtcpacket/pus/tm/PusTmMinimal.h @@ -3,10 +3,39 @@ #include "PusTmIF.h" #include "fsfw/returnvalues/HasReturnvaluesIF.h" -#include "fsfw/tmtcpacket/SpacePacketReader.h" +#include "fsfw/tmtcpacket/ccsds/SpacePacketReader.h" struct timeval; + class PacketTimestampInterpreterIF; + +namespace mintm { + +// NOTE: Only PUS C compatible! +struct PusTmMinimalSecHeader { + uint8_t versionAndScTimeRefStatus; + uint8_t service; + uint8_t subservice; + uint8_t messageTypeH; + uint8_t messageTypeL; +}; + +/** + * This struct defines the data structure of a PUS Telecommand Packet when + * accessed via a pointer. + * @ingroup tmtcpackets + */ +struct MinimalPusTm { + ccsds::PrimaryHeader primary; + PusTmMinimalSecHeader secHeader; + uint8_t rest; +}; + +// Must include a checksum and is therefore at least one larger than the above struct. +static const uint16_t MINIMUM_SIZE = sizeof(MinimalPusTm) + 1; + +} // namespace mintm + /** * This is a minimal version of a PUS TmPacket without any variable field, or, * in other words with Service Type, Subtype and subcounter only. @@ -15,6 +44,7 @@ class PacketTimestampInterpreterIF; */ class PusTmMinimal : public PusTmIF, public RedirectableDataPointerIF { public: + explicit PusTmMinimal(mintm::MinimalPusTm* data); /** * This is the default constructor. * It sets its internal data pointer to the address passed and also @@ -33,8 +63,8 @@ class PusTmMinimal : public PusTmIF, public RedirectableDataPointerIF { 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 getPacketIdRaw() const override; + [[nodiscard]] uint16_t getPacketSeqCtrlRaw() const override; [[nodiscard]] uint16_t getPacketDataLen() const override; [[nodiscard]] uint8_t getPusVersion() const override; [[nodiscard]] uint8_t getService() const override; @@ -47,27 +77,6 @@ class PusTmMinimal : public PusTmIF, public RedirectableDataPointerIF { 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. - * @ingroup tmtcpackets - */ - struct TmPacketMinimalPointer { - CCSDSPrimaryHeader primary; - PusTmMinimalSecHeader secHeader; - uint8_t rest; - }; - // Must include a checksum and is therefore at least one larger than the above struct. - static const uint16_t MINIMUM_SIZE = sizeof(TmPacketMinimalPointer) + 1; - protected: /** * A pointer to a structure which defines the data structure of @@ -75,7 +84,7 @@ class PusTmMinimal : public PusTmIF, public RedirectableDataPointerIF { * * To be hardware-safe, all elements are of byte size. */ - TmPacketMinimalPointer* tmData; + mintm::MinimalPusTm* tmData; static PacketTimestampInterpreterIF* timestampInterpreter; }; diff --git a/src/fsfw/tmtcpacket/pus/tm/TmPacketBase.h b/src/fsfw/tmtcpacket/pus/tm/TmPacketBase.h index e1622466..fe7619cf 100644 --- a/src/fsfw/tmtcpacket/pus/tm/TmPacketBase.h +++ b/src/fsfw/tmtcpacket/pus/tm/TmPacketBase.h @@ -4,7 +4,7 @@ #include "fsfw/objectmanager/SystemObjectIF.h" #include "fsfw/timemanager/Clock.h" #include "fsfw/timemanager/TimeStamperIF.h" -#include "fsfw/tmtcpacket/SpacePacketReader.h" +#include "fsfw/tmtcpacket/ccsds/SpacePacketReader.h" namespace Factory { diff --git a/src/fsfw/tmtcpacket/pus/tm/TmPacketPusC.h b/src/fsfw/tmtcpacket/pus/tm/TmPacketPusC.h index bf9de122..7d1eb255 100644 --- a/src/fsfw/tmtcpacket/pus/tm/TmPacketPusC.h +++ b/src/fsfw/tmtcpacket/pus/tm/TmPacketPusC.h @@ -5,7 +5,7 @@ #include "fsfw/objectmanager/SystemObjectIF.h" #include "fsfw/timemanager/Clock.h" #include "fsfw/timemanager/TimeStamperIF.h" -#include "fsfw/tmtcpacket/SpacePacketReader.h" +#include "fsfw/tmtcpacket/ccsds/SpacePacketReader.h" namespace Factory { void setStaticFrameworkObjectIds(); @@ -35,7 +35,7 @@ struct PUSTmDataFieldHeaderPusC { * @ingroup tmtcpackets */ struct TmPacketPointerPusC { - CCSDSPrimaryHeader primary; + ccsds::PrimaryHeader primary; PUSTmDataFieldHeaderPusC dataField; uint8_t data; }; @@ -52,7 +52,7 @@ class TmPacketPusC : public TmPacketBase { * This constant defines the minimum size of a valid PUS Telemetry Packet. */ static const uint32_t TM_PACKET_MIN_SIZE = - (sizeof(CCSDSPrimaryHeader) + sizeof(PUSTmDataFieldHeaderPusC) + 2); + ccsds::HEADER_LEN + sizeof(PUSTmDataFieldHeaderPusC) + 2; //! Maximum size of a TM Packet in this mission. static const uint32_t MISSION_TM_PACKET_MAX_SIZE = fsfwconfig::FSFW_MAX_TM_PACKET_SIZE; diff --git a/src/fsfw/tmtcpacket/pus/tm/TmPacketStoredPusC.h b/src/fsfw/tmtcpacket/pus/tm/TmPacketStoredPusC.h index fe65e2ca..2a1f645f 100644 --- a/src/fsfw/tmtcpacket/pus/tm/TmPacketStoredPusC.h +++ b/src/fsfw/tmtcpacket/pus/tm/TmPacketStoredPusC.h @@ -1,72 +1,73 @@ -#ifndef FSFW_TMTCPACKET_PUS_TMPACKETSTOREDPUSC_H_ -#define FSFW_TMTCPACKET_PUS_TMPACKETSTOREDPUSC_H_ - -#include "TmPacketPusC.h" -#include "TmPacketStoredBase.h" - -/** - * This class generates a ECSS PUS C Telemetry packet within a given - * intermediate storage. - * As most packets are passed between tasks with the help of a storage - * anyway, it seems logical to create a Packet-In-Storage access class - * which saves the user almost all storage handling operation. - * Packets can both be newly created with the class and be "linked" to - * packets in a store with the help of a storeAddress. - * @ingroup tmtcpackets - */ -class TmPacketStoredPusC : public TmPacketStoredBase, public TmPacketPusC { - public: - /** - * This is a default constructor which does not set the data pointer. - * However, it does try to set the packet store. - */ - TmPacketStoredPusC(store_address_t setAddress); - /** - * With this constructor, new space is allocated in the packet store and - * a new PUS Telemetry Packet is created there. - * Packet Application Data passed in data is copied into the packet. - * The Application data is passed in two parts, first a header, then a - * data field. This allows building a Telemetry Packet from two separate - * data sources. - * @param apid Sets the packet's APID field. - * @param service Sets the packet's Service ID field. - * This specifies the source service. - * @param subservice Sets the packet's Service Subtype field. - * This specifies the source sub-service. - * @param packet_counter Sets the Packet counter field of this packet - * @param data The payload data to be copied to the - * Application Data Field - * @param size The amount of data to be copied. - * @param headerData The header Data of the Application field, - * will be copied in front of data - * @param headerSize The size of the headerDataF - * @param destinationId Destination ID containing the application process ID as specified - * by PUS C - * @param timeRefField 4 bit time reference field as specified by PUS C - */ - TmPacketStoredPusC(uint16_t apid, uint8_t service, uint8_t subservice, uint16_t packetCounter = 0, - const uint8_t* data = nullptr, uint32_t size = 0, - const uint8_t* headerData = nullptr, uint32_t headerSize = 0, - uint16_t destinationId = 0, uint8_t timeRefField = 0); - /** - * Another ctor to directly pass structured content and header data to the - * packet to avoid additional buffers. - */ - TmPacketStoredPusC(uint16_t apid, uint8_t service, uint8_t subservice, uint16_t packetCounter, - SerializeIF* content, SerializeIF* header = nullptr, - uint16_t destinationId = 0, uint8_t timeRefField = 0); - - uint8_t* getAllTmData() override; - - private: - /** - * Implementation required by base class - * @param newPointer - * @param maxSize - * @param args - * @return - */ - ReturnValue_t setData(uint8_t* newPointer, size_t maxSize, void* args) override; -}; - -#endif /* FSFW_TMTCPACKET_PUS_TMPACKETSTOREDPUSC_H_ */ +//#ifndef FSFW_TMTCPACKET_PUS_TMPACKETSTOREDPUSC_H_ +//#define FSFW_TMTCPACKET_PUS_TMPACKETSTOREDPUSC_H_ +// +//#include "TmPacketPusC.h" +//#include "TmPacketStoredBase.h" +// +///** +// * This class generates a ECSS PUS C Telemetry packet within a given +// * intermediate storage. +// * As most packets are passed between tasks with the help of a storage +// * anyway, it seems logical to create a Packet-In-Storage access class +// * which saves the user almost all storage handling operation. +// * Packets can both be newly created with the class and be "linked" to +// * packets in a store with the help of a storeAddress. +// * @ingroup tmtcpackets +// */ +// class TmPacketStoredPusC : public TmPacketStoredBase, public TmPacketPusC { +// public: +// /** +// * This is a default constructor which does not set the data pointer. +// * However, it does try to set the packet store. +// */ +// TmPacketStoredPusC(store_address_t setAddress); +// /** +// * With this constructor, new space is allocated in the packet store and +// * a new PUS Telemetry Packet is created there. +// * Packet Application Data passed in data is copied into the packet. +// * The Application data is passed in two parts, first a header, then a +// * data field. This allows building a Telemetry Packet from two separate +// * data sources. +// * @param apid Sets the packet's APID field. +// * @param service Sets the packet's Service ID field. +// * This specifies the source service. +// * @param subservice Sets the packet's Service Subtype field. +// * This specifies the source sub-service. +// * @param packet_counter Sets the Packet counter field of this packet +// * @param data The payload data to be copied to the +// * Application Data Field +// * @param size The amount of data to be copied. +// * @param headerData The header Data of the Application field, +// * will be copied in front of data +// * @param headerSize The size of the headerDataF +// * @param destinationId Destination ID containing the application process ID as specified +// * by PUS C +// * @param timeRefField 4 bit time reference field as specified by PUS C +// */ +// TmPacketStoredPusC(uint16_t apid, uint8_t service, uint8_t subservice, uint16_t packetCounter = +// 0, +// const uint8_t* data = nullptr, uint32_t size = 0, +// const uint8_t* headerData = nullptr, uint32_t headerSize = 0, +// uint16_t destinationId = 0, uint8_t timeRefField = 0); +// /** +// * Another ctor to directly pass structured content and header data to the +// * packet to avoid additional buffers. +// */ +// TmPacketStoredPusC(uint16_t apid, uint8_t service, uint8_t subservice, uint16_t packetCounter, +// SerializeIF* content, SerializeIF* header = nullptr, +// uint16_t destinationId = 0, uint8_t timeRefField = 0); +// +// uint8_t* getAllTmData() override; +// +// private: +// /** +// * Implementation required by base class +// * @param newPointer +// * @param maxSize +// * @param args +// * @return +// */ +// ReturnValue_t setData(uint8_t* newPointer, size_t maxSize, void* args) override; +//}; +// +//#endif /* FSFW_TMTCPACKET_PUS_TMPACKETSTOREDPUSC_H_ */ diff --git a/src/fsfw/tmtcservices/CMakeLists.txt b/src/fsfw/tmtcservices/CMakeLists.txt index d2a3f4ed..fcbcb49d 100644 --- a/src/fsfw/tmtcservices/CMakeLists.txt +++ b/src/fsfw/tmtcservices/CMakeLists.txt @@ -6,4 +6,5 @@ target_sources( TmTcBridge.cpp TmTcMessage.cpp VerificationReporter.cpp - SpacePacketParser.cpp) + SpacePacketParser.cpp + TmStoreHelper.cpp) diff --git a/src/fsfw/tmtcservices/PusServiceBase.cpp b/src/fsfw/tmtcservices/PusServiceBase.cpp index f0cdb61b..b18a736b 100644 --- a/src/fsfw/tmtcservices/PusServiceBase.cpp +++ b/src/fsfw/tmtcservices/PusServiceBase.cpp @@ -12,8 +12,8 @@ object_id_t PusServiceBase::packetSource = 0; object_id_t PusServiceBase::packetDestination = 0; PusServiceBase::PusServiceBase(object_id_t setObjectId, uint16_t setApid, uint8_t setServiceId, - StorageManagerIF* store_) - : SystemObject(setObjectId), apid(setApid), serviceId(setServiceId), store(store_) { + StorageManagerIF* ipcStore_) + : SystemObject(setObjectId), apid(setApid), serviceId(setServiceId), ipcStore(ipcStore_) { requestQueue = QueueFactory::instance()->createMessageQueue(PUS_SERVICE_MAX_RECEPTION); } @@ -52,7 +52,7 @@ void PusServiceBase::handleRequestQueue() { if (status == RETURN_OK) { const uint8_t* dataPtr; size_t dataLen = 0; - result = store->getData(message.getStorageId(), &dataPtr, &dataLen); + result = ipcStore->getData(message.getStorageId(), &dataPtr, &dataLen); if (result != HasReturnvaluesIF::RETURN_OK) { // TODO: Warning? } @@ -73,7 +73,7 @@ void PusServiceBase::handleRequestQueue() { &this->currentPacket, result, 0, errorParameter1, errorParameter2); } - store->deleteData(message.getStorageId()); + ipcStore->deleteData(message.getStorageId()); errorParameter1 = 0; errorParameter2 = 0; } else if (status == MessageQueueIF::EMPTY) { @@ -112,6 +112,12 @@ ReturnValue_t PusServiceBase::initialize() { } this->requestQueue->setDefaultDestination(destService->getReportReceptionQueue()); distributor->registerService(this); + if (ipcStore == nullptr) { + ipcStore = ObjectManager::instance()->get(objects::IPC_STORE); + if (ipcStore == nullptr) { + return ObjectManagerIF::CHILD_INIT_FAILED; + } + } return HasReturnvaluesIF::RETURN_OK; } diff --git a/src/fsfw/tmtcservices/PusServiceBase.h b/src/fsfw/tmtcservices/PusServiceBase.h index 57547ace..d487c6c6 100644 --- a/src/fsfw/tmtcservices/PusServiceBase.h +++ b/src/fsfw/tmtcservices/PusServiceBase.h @@ -52,7 +52,7 @@ class PusServiceBase : public ExecutableObjectIF, * The Service Identifier as specified in ECSS PUS. */ PusServiceBase(object_id_t setObjectId, uint16_t setApid, uint8_t setServiceId, - StorageManagerIF* store); + StorageManagerIF* ipcStore); /** * The destructor is empty. */ @@ -144,7 +144,7 @@ class PusServiceBase : public ExecutableObjectIF, * It is deleted after handleRequest was executed. */ // TcPacketStoredPus currentPacket; - StorageManagerIF* store; + StorageManagerIF* ipcStore; PusTcReader currentPacket; static object_id_t packetSource; diff --git a/src/fsfw/tmtcservices/SourceSequenceCounter.h b/src/fsfw/tmtcservices/SourceSequenceCounter.h index 836ac5e9..da96dc4e 100644 --- a/src/fsfw/tmtcservices/SourceSequenceCounter.h +++ b/src/fsfw/tmtcservices/SourceSequenceCounter.h @@ -1,7 +1,7 @@ #ifndef FSFW_TMTCSERVICES_SOURCESEQUENCECOUNTER_H_ #define FSFW_TMTCSERVICES_SOURCESEQUENCECOUNTER_H_ -#include "../tmtcpacket/SpacePacketReader.h" +#include "fsfw/tmtcpacket/ccsds/SpacePacketReader.h" class SourceSequenceCounter { private: diff --git a/src/fsfw/tmtcservices/TmStoreHelper.cpp b/src/fsfw/tmtcservices/TmStoreHelper.cpp new file mode 100644 index 00000000..54e6ffc8 --- /dev/null +++ b/src/fsfw/tmtcservices/TmStoreHelper.cpp @@ -0,0 +1,43 @@ +#include "TmStoreHelper.h" + +#include "TmTcMessage.h" +#include "fsfw/ipc/MessageQueueSenderIF.h" + +TmStoreHelper::TmStoreHelper(StorageManagerIF *tmStore, MessageQueueId_t tmtcMsgDest, + MessageQueueId_t tmtcMsgSrc, InternalErrorReporterIF *reporter) + : creator(params), + tmtcMsgDest(tmtcMsgDest), + tmtcMsgSrc(tmtcMsgSrc), + errReporter(reporter), + tmStore(tmStore) {} + +void TmStoreHelper::preparePacket(uint16_t apid, uint8_t service, uint8_t subservice, + uint16_t counter) { + // TODO: Implement + // creator.setApid(apid); + params.service = service; + params.subservice = subservice; + params.messageTypeCounter = counter; + // TODO: Implement serialize and then serialize into the store +} + +ReturnValue_t TmStoreHelper::sendPacket() { + TmTcMessage tmMessage(currentAddr); + ReturnValue_t result = MessageQueueSenderIF::sendMessage(tmtcMsgDest, &tmMessage, tmtcMsgSrc); + if (result != HasReturnvaluesIF::RETURN_OK) { + tmStore->deleteData(currentAddr); + if (errReporter != nullptr) { + errReporter->lostTm(); + } + return result; + } + return HasReturnvaluesIF::RETURN_OK; +} + +void TmStoreHelper::setMsgDestination(MessageQueueId_t msgDest) { tmtcMsgDest = msgDest; } + +void TmStoreHelper::setMsgSource(MessageQueueId_t msgSrc) { tmtcMsgSrc = msgSrc; } + +void TmStoreHelper::setInternalErrorReporter(InternalErrorReporterIF *reporter) { + errReporter = reporter; +} diff --git a/src/fsfw/tmtcservices/TmStoreHelper.h b/src/fsfw/tmtcservices/TmStoreHelper.h new file mode 100644 index 00000000..bada3b7d --- /dev/null +++ b/src/fsfw/tmtcservices/TmStoreHelper.h @@ -0,0 +1,33 @@ +#ifndef FSFW_TMTCSERVICES_STOREHELPER_H +#define FSFW_TMTCSERVICES_STOREHELPER_H + +#include "fsfw/internalerror/InternalErrorReporterIF.h" +#include "fsfw/ipc/MessageQueueMessageIF.h" +#include "fsfw/storagemanager/StorageManagerIF.h" +#include "fsfw/tmtcpacket/pus/tm/PusTmCreator.h" + +// TODO: Serializing a packet into a store and sending the message are two different tasks +// Move them into separate classes +class TmStoreHelper { + public: + TmStoreHelper(StorageManagerIF* tmStore, MessageQueueId_t tmtcMsgDest, + MessageQueueId_t tmtcMsgSrc, InternalErrorReporterIF* reporter); + + void setInternalErrorReporter(InternalErrorReporterIF* reporter); + void setMsgDestination(MessageQueueId_t msgDest); + void setMsgSource(MessageQueueId_t msgSrc); + void preparePacket(uint16_t apid, uint8_t service, uint8_t subservice, uint16_t counter); + ReturnValue_t sendPacket(); + + private: + PusTmParams params{}; + PusTmCreator creator; + + bool doErrorReporting = true; + MessageQueueId_t tmtcMsgDest; + MessageQueueId_t tmtcMsgSrc; + InternalErrorReporterIF* errReporter; + store_address_t currentAddr{}; + StorageManagerIF* tmStore; +}; +#endif // FSFW_TMTCSERVICES_STOREHELPER_H diff --git a/src/fsfw/tmtcservices/VerificationReporter.cpp b/src/fsfw/tmtcservices/VerificationReporter.cpp index bf33d1c4..04b42934 100644 --- a/src/fsfw/tmtcservices/VerificationReporter.cpp +++ b/src/fsfw/tmtcservices/VerificationReporter.cpp @@ -22,8 +22,8 @@ void VerificationReporter::sendSuccessReport(uint8_t set_report_id, PusTcReader* return; } PusVerificationMessage message(set_report_id, currentPacket->getAcknowledgeFlags(), - currentPacket->getPacketId(), currentPacket->getPacketSeqCtrl(), 0, - set_step); + currentPacket->getPacketIdRaw(), + currentPacket->getPacketSeqCtrlRaw(), 0, set_step); ReturnValue_t status = MessageQueueSenderIF::sendMessage(acknowledgeQueue, &message); if (status != HasReturnvaluesIF::RETURN_OK) { #if FSFW_CPP_OSTREAM_ENABLED == 1 @@ -59,9 +59,9 @@ void VerificationReporter::sendFailureReport(uint8_t report_id, PusTcReader* cur if (currentPacket == nullptr) { return; } - PusVerificationMessage message(report_id, currentPacket->getAcknowledgeFlags(), - currentPacket->getPacketId(), currentPacket->getPacketSeqCtrl(), - error_code, step, parameter1, parameter2); + PusVerificationMessage message( + report_id, currentPacket->getAcknowledgeFlags(), currentPacket->getPacketIdRaw(), + currentPacket->getPacketSeqCtrlRaw(), error_code, step, parameter1, parameter2); ReturnValue_t status = MessageQueueSenderIF::sendMessage(acknowledgeQueue, &message); if (status != HasReturnvaluesIF::RETURN_OK) { #if FSFW_CPP_OSTREAM_ENABLED == 1 diff --git a/unittests/tmtcpacket/testCcsdsCreator.cpp b/unittests/tmtcpacket/testCcsdsCreator.cpp index d56669a7..2043d6a6 100644 --- a/unittests/tmtcpacket/testCcsdsCreator.cpp +++ b/unittests/tmtcpacket/testCcsdsCreator.cpp @@ -2,11 +2,12 @@ #include #include -#include "fsfw/tmtcpacket/SpacePacketCreator.h" +#include "fsfw/tmtcpacket/ccsds/SpacePacketCreator.h" TEST_CASE("CCSDS Creator", "[ccsds-creator]") { - SpacePacketCreator base = SpacePacketCreator(ccsds::PacketType::TC, true, 0x02, - ccsds::SequenceFlags::FIRST_SEGMENT, 0x34, 0x16); + auto params = SpacePacketParams(PacketId(ccsds::PacketType::TC, true, 0x02), + PacketSeqCtrl(ccsds::SequenceFlags::FIRST_SEGMENT, 0x34), 0x16); + SpacePacketCreator base = SpacePacketCreator(params); std::array buf{}; uint8_t* bufPtr = buf.data(); size_t serLen = 0; @@ -27,7 +28,7 @@ TEST_CASE("CCSDS Creator", "[ccsds-creator]") { REQUIRE(base.getSequenceCount() == 0x34); REQUIRE(base.getPacketDataLen() == 0x16); REQUIRE(base.getPacketType() == ccsds::PacketType::TC); - REQUIRE(base.getPacketId() == 0x1802); + REQUIRE(base.getPacketIdRaw() == 0x1802); REQUIRE(base.getSerializedSize() == 6); } @@ -71,17 +72,15 @@ TEST_CASE("CCSDS Creator", "[ccsds-creator]") { } SECTION("Invalid APID") { - SpacePacketCreator invalid = - SpacePacketCreator(PacketId(ccsds::PacketType::TC, true, 0xFFFF), - PacketSeqCtrl(ccsds::SequenceFlags::FIRST_SEGMENT, 0x34), 0x16); + SpacePacketCreator invalid = SpacePacketCreator( + ccsds::PacketType::TC, true, 0xFFFF, ccsds::SequenceFlags::FIRST_SEGMENT, 0x34, 0x16); REQUIRE(not invalid.isValid()); REQUIRE(invalid.serialize(&bufPtr, &serLen, buf.size()) == HasReturnvaluesIF::RETURN_FAILED); } SECTION("Invalid Seq Count") { - SpacePacketCreator invalid = - SpacePacketCreator(PacketId(ccsds::PacketType::TC, true, 0x02), - PacketSeqCtrl(ccsds::SequenceFlags::FIRST_SEGMENT, 0xFFFF), 0x16); + SpacePacketCreator invalid = SpacePacketCreator( + ccsds::PacketType::TC, true, 0x02, ccsds::SequenceFlags::FIRST_SEGMENT, 0xFFFF, 0x16); REQUIRE(not invalid.isValid()); REQUIRE(invalid.serialize(&bufPtr, &serLen, buf.size()) == HasReturnvaluesIF::RETURN_FAILED); } diff --git a/unittests/tmtcpacket/testCcsdsReader.cpp b/unittests/tmtcpacket/testCcsdsReader.cpp index b8a6f3dd..89ee5a46 100644 --- a/unittests/tmtcpacket/testCcsdsReader.cpp +++ b/unittests/tmtcpacket/testCcsdsReader.cpp @@ -1,5 +1,5 @@ #include -#include "fsfw/tmtcpacket/SpacePacketReader.h" +#include "fsfw/tmtcpacket/ccsds/SpacePacketReader.h" TEST_CASE("CCSDS Reader", "[ccsds-reader]") {} \ No newline at end of file -- 2.43.0 From 9860061fc6909f2a4b57465c2268ce6b49792949 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Wed, 20 Jul 2022 11:45:50 +0200 Subject: [PATCH 014/108] create new TmSendHelper --- src/fsfw/tmtcservices/TmStoreHelper.h | 31 ++++++++++++++++----------- 1 file changed, 19 insertions(+), 12 deletions(-) diff --git a/src/fsfw/tmtcservices/TmStoreHelper.h b/src/fsfw/tmtcservices/TmStoreHelper.h index bada3b7d..61ef93f4 100644 --- a/src/fsfw/tmtcservices/TmStoreHelper.h +++ b/src/fsfw/tmtcservices/TmStoreHelper.h @@ -6,27 +6,34 @@ #include "fsfw/storagemanager/StorageManagerIF.h" #include "fsfw/tmtcpacket/pus/tm/PusTmCreator.h" +class TmStoreAndSendWrapper { + +}; + +class TmSendHelper { + public: + TmSendHelper(MessageQueueId_t tmtcMsgDest, + MessageQueueId_t tmtcMsgSrc, InternalErrorReporterIF* reporter); + void setMsgDestination(MessageQueueId_t msgDest); + void setMsgSource(MessageQueueId_t msgSrc); + void setInternalErrorReporter(InternalErrorReporterIF* reporter); + ReturnValue_t sendPacket(); + private: + MessageQueueId_t tmtcMsgDest; + MessageQueueId_t tmtcMsgSrc; + InternalErrorReporterIF* errReporter; +}; + // TODO: Serializing a packet into a store and sending the message are two different tasks // Move them into separate classes class TmStoreHelper { public: - TmStoreHelper(StorageManagerIF* tmStore, MessageQueueId_t tmtcMsgDest, - MessageQueueId_t tmtcMsgSrc, InternalErrorReporterIF* reporter); + TmStoreHelper(StorageManagerIF* tmStore); - void setInternalErrorReporter(InternalErrorReporterIF* reporter); - void setMsgDestination(MessageQueueId_t msgDest); - void setMsgSource(MessageQueueId_t msgSrc); void preparePacket(uint16_t apid, uint8_t service, uint8_t subservice, uint16_t counter); - ReturnValue_t sendPacket(); - private: PusTmParams params{}; PusTmCreator creator; - - bool doErrorReporting = true; - MessageQueueId_t tmtcMsgDest; - MessageQueueId_t tmtcMsgSrc; - InternalErrorReporterIF* errReporter; store_address_t currentAddr{}; StorageManagerIF* tmStore; }; -- 2.43.0 From be35bd53a6b4434b5a51233d34eef95aa2e9b9fe Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Wed, 20 Jul 2022 22:21:15 +0200 Subject: [PATCH 015/108] switched to new tmtc stack API --- .../monitoring/MonitoringMessageContent.h | 6 +- src/fsfw/osal/host/MessageQueue.cpp | 2 +- src/fsfw/pus/Service17Test.cpp | 40 ++-- src/fsfw/pus/Service17Test.h | 11 +- .../pus/Service1TelecommandVerification.cpp | 36 ++-- .../pus/Service1TelecommandVerification.h | 11 +- src/fsfw/pus/Service20ParameterManagement.cpp | 4 +- src/fsfw/pus/Service2DeviceAccess.cpp | 10 +- src/fsfw/pus/Service3Housekeeping.cpp | 5 +- src/fsfw/pus/Service5EventReporting.cpp | 25 +-- src/fsfw/pus/Service5EventReporting.h | 4 +- src/fsfw/pus/Service8FunctionManagement.cpp | 6 +- src/fsfw/pus/Service9TimeManagement.cpp | 6 +- src/fsfw/pus/servicepackets/Service9Packets.h | 6 +- src/fsfw/storagemanager/StorageManagerIF.h | 8 +- src/fsfw/tcdistribution/PusDistributor.cpp | 2 +- .../{TimeStamper.h => CdsShortTimeStamper.h} | 13 +- src/fsfw/timemanager/TimeStamper.cpp | 32 +++- src/fsfw/timemanager/TimeStamperIF.h | 17 +- .../tmtcpacket/ccsds/SpacePacketCreator.cpp | 4 + .../tmtcpacket/ccsds/SpacePacketCreator.h | 9 +- src/fsfw/tmtcpacket/ccsds/SpacePacketIF.h | 2 +- .../packetmatcher/PacketMatchTree.cpp | 4 +- src/fsfw/tmtcpacket/pus/CreatorDataIF.h | 10 + src/fsfw/tmtcpacket/pus/PusIF.h | 18 -- src/fsfw/tmtcpacket/pus/RawUserDataReaderIF.h | 12 ++ src/fsfw/tmtcpacket/pus/definitions.h | 28 +++ src/fsfw/tmtcpacket/pus/tc/PusTcCreator.cpp | 36 ++-- src/fsfw/tmtcpacket/pus/tc/PusTcCreator.h | 9 +- src/fsfw/tmtcpacket/pus/tc/PusTcIF.h | 2 +- src/fsfw/tmtcpacket/pus/tc/PusTcReader.cpp | 16 +- src/fsfw/tmtcpacket/pus/tc/PusTcReader.h | 11 +- src/fsfw/tmtcpacket/pus/tm/PusTmCreator.cpp | 93 +++++++++- src/fsfw/tmtcpacket/pus/tm/PusTmCreator.h | 51 +++-- src/fsfw/tmtcpacket/pus/tm/PusTmIF.h | 14 +- src/fsfw/tmtcpacket/pus/tm/PusTmMinimal.cpp | 9 +- src/fsfw/tmtcpacket/pus/tm/PusTmMinimal.h | 14 +- src/fsfw/tmtcpacket/pus/tm/TmPacketPusC.h | 2 +- src/fsfw/tmtcservices/CMakeLists.txt | 3 +- .../tmtcservices/CommandingServiceBase.cpp | 174 +++++++++--------- src/fsfw/tmtcservices/CommandingServiceBase.h | 54 +++--- src/fsfw/tmtcservices/PusServiceBase.cpp | 43 +++-- src/fsfw/tmtcservices/PusServiceBase.h | 17 +- src/fsfw/tmtcservices/TmSendHelper.cpp | 29 +++ src/fsfw/tmtcservices/TmSendHelper.h | 26 +++ src/fsfw/tmtcservices/TmStoreHelper.cpp | 77 ++++---- src/fsfw/tmtcservices/TmStoreHelper.h | 38 ++-- .../tmtcservices/VerificationReporter.cpp | 18 +- src/fsfw/tmtcservices/VerificationReporter.h | 4 +- src/fsfw/tmtcservices/sendAndStoreHelper.h | 54 ++++++ unittests/CatchFactory.cpp | 2 - 51 files changed, 753 insertions(+), 374 deletions(-) rename src/fsfw/timemanager/{TimeStamper.h => CdsShortTimeStamper.h} (60%) create mode 100644 src/fsfw/tmtcpacket/pus/CreatorDataIF.h create mode 100644 src/fsfw/tmtcpacket/pus/RawUserDataReaderIF.h create mode 100644 src/fsfw/tmtcservices/TmSendHelper.cpp create mode 100644 src/fsfw/tmtcservices/TmSendHelper.h create mode 100644 src/fsfw/tmtcservices/sendAndStoreHelper.h diff --git a/src/fsfw/monitoring/MonitoringMessageContent.h b/src/fsfw/monitoring/MonitoringMessageContent.h index fb3ace3d..aeadacdf 100644 --- a/src/fsfw/monitoring/MonitoringMessageContent.h +++ b/src/fsfw/monitoring/MonitoringMessageContent.h @@ -34,7 +34,7 @@ class MonitoringReportContent : public SerialLinkedListAdapter { SerializeElement limitValue; SerializeElement oldState; SerializeElement newState; - uint8_t rawTimestamp[TimeStamperIF::MISSION_TIMESTAMP_SIZE] = {}; + uint8_t rawTimestamp[TimeStamperIF::MAXIMUM_TIMESTAMP_LEN] = {}; SerializeElement> timestampSerializer; TimeStamperIF* timeStamper; MonitoringReportContent() @@ -47,7 +47,7 @@ class MonitoringReportContent : public SerialLinkedListAdapter { oldState(0), newState(0), timestampSerializer(rawTimestamp, sizeof(rawTimestamp)), - timeStamper(NULL) { + timeStamper(nullptr) { setAllNext(); } MonitoringReportContent(gp_id_t globalPoolId, T value, T limitValue, ReturnValue_t oldState, @@ -61,7 +61,7 @@ class MonitoringReportContent : public SerialLinkedListAdapter { oldState(oldState), newState(newState), timestampSerializer(rawTimestamp, sizeof(rawTimestamp)), - timeStamper(NULL) { + timeStamper(nullptr) { setAllNext(); if (checkAndSetStamper()) { timeStamper->addTimeStamp(rawTimestamp, sizeof(rawTimestamp)); diff --git a/src/fsfw/osal/host/MessageQueue.cpp b/src/fsfw/osal/host/MessageQueue.cpp index d0a12850..5eb0c99a 100644 --- a/src/fsfw/osal/host/MessageQueue.cpp +++ b/src/fsfw/osal/host/MessageQueue.cpp @@ -84,7 +84,7 @@ ReturnValue_t MessageQueue::sendMessageFromMessageQueue(MessageQueueId_t sendTo, message->getMaximumMessageSize()); } else { if (not ignoreFault) { - InternalErrorReporterIF* internalErrorReporter = + auto* internalErrorReporter = ObjectManager::instance()->get(objects::INTERNAL_ERROR_REPORTER); if (internalErrorReporter != nullptr) { internalErrorReporter->queueMessageNotSent(); diff --git a/src/fsfw/pus/Service17Test.cpp b/src/fsfw/pus/Service17Test.cpp index 87549808..7d13af06 100644 --- a/src/fsfw/pus/Service17Test.cpp +++ b/src/fsfw/pus/Service17Test.cpp @@ -1,15 +1,14 @@ #include "fsfw/pus/Service17Test.h" #include "fsfw/FSFW.h" +#include "fsfw/objectmanager/ObjectManager.h" #include "fsfw/objectmanager/SystemObject.h" -#include "fsfw/serviceinterface/ServiceInterface.h" -#include "fsfw/tmtcpacket/pus/tm/TmPacketStored.h" +#include "fsfw/tmtcservices/sendAndStoreHelper.h" -Service17Test::Service17Test(object_id_t objectId, uint16_t apid, uint8_t serviceId, - StorageManagerIF* tmStore, StorageManagerIF* ipcStore, - InternalErrorReporterIF* errReporter) - : PusServiceBase(objectId, apid, serviceId, ipcStore), - helper(tmStore, MessageQueueIF::NO_QUEUE, MessageQueueIF::NO_QUEUE, errReporter), +Service17Test::Service17Test(object_id_t objectId, uint16_t apid, uint8_t serviceId) + : PusServiceBase(objectId, apid, serviceId), + storeHelper(apid, nullptr), + sendHelper(nullptr), packetSubCounter(0) {} Service17Test::~Service17Test() = default; @@ -17,15 +16,13 @@ Service17Test::~Service17Test() = default; ReturnValue_t Service17Test::handleRequest(uint8_t subservice) { switch (subservice) { case Subservice::CONNECTION_TEST: { - helper.preparePacket(apid, serviceId, Subservice::CONNECTION_TEST_REPORT, packetSubCounter); - helper.sendPacket(); - return HasReturnvaluesIF::RETURN_OK; + storeHelper.preparePacket(serviceId, Subservice::CONNECTION_TEST_REPORT, packetSubCounter); + return tm::storeAndSendTmPacket(storeHelper, sendHelper); } case Subservice::EVENT_TRIGGER_TEST: { - helper.preparePacket(apid, serviceId, Subservice::CONNECTION_TEST_REPORT, packetSubCounter++); - helper.sendPacket(); + storeHelper.preparePacket(serviceId, Subservice::CONNECTION_TEST_REPORT, packetSubCounter++); triggerEvent(TEST, 1234, 5678); - return RETURN_OK; + return tm::storeAndSendTmPacket(storeHelper, sendHelper); } default: return AcceptsTelecommandsIF::INVALID_SUBSERVICE; @@ -39,6 +36,17 @@ ReturnValue_t Service17Test::initialize() { if (result != HasReturnvaluesIF::RETURN_OK) { return result; } - helper.setMsgDestination(requestQueue->getDefaultDestination()); - helper.setMsgSource(requestQueue->getId()); - if (tm) } + initializeTmHelpers(sendHelper, storeHelper); + if (storeHelper.getTmStore() == nullptr) { + auto* tmStore = ObjectManager::instance()->get(objects::TM_STORE); + if (tmStore == nullptr) { + return ObjectManagerIF::CHILD_INIT_FAILED; + } + storeHelper.setTmStore(tmStore); + } + return result; +} + +void Service17Test::setCustomTmStore(StorageManagerIF* tmStore_) { + storeHelper.setTmStore(tmStore_); +} diff --git a/src/fsfw/pus/Service17Test.h b/src/fsfw/pus/Service17Test.h index 0f690ea4..a5bfa974 100644 --- a/src/fsfw/pus/Service17Test.h +++ b/src/fsfw/pus/Service17Test.h @@ -33,16 +33,19 @@ class Service17Test : public PusServiceBase { EVENT_TRIGGER_TEST = 128, }; - Service17Test(object_id_t objectId, uint16_t apid, uint8_t serviceId, - InternalErrorReporterIF* errReporter, StorageManagerIF* tmStore = nullptr, - StorageManagerIF* ipcStore = nullptr); + Service17Test(object_id_t objectId, uint16_t apid, uint8_t serviceId); + + void setCustomTmStore(StorageManagerIF* tmStore); + ~Service17Test() override; ReturnValue_t handleRequest(uint8_t subservice) override; ReturnValue_t performService() override; ReturnValue_t initialize() override; protected: - TmStoreHelper helper; + TmStoreHelper storeHelper; + TmSendHelper sendHelper; + uint16_t packetSubCounter = 0; }; diff --git a/src/fsfw/pus/Service1TelecommandVerification.cpp b/src/fsfw/pus/Service1TelecommandVerification.cpp index 13d6a1c4..5c49111e 100644 --- a/src/fsfw/pus/Service1TelecommandVerification.cpp +++ b/src/fsfw/pus/Service1TelecommandVerification.cpp @@ -3,10 +3,10 @@ #include "fsfw/ipc/QueueFactory.h" #include "fsfw/objectmanager/ObjectManager.h" #include "fsfw/pus/servicepackets/Service1Packets.h" -#include "fsfw/serviceinterface/ServiceInterface.h" #include "fsfw/tmtcpacket/pus/tm/TmPacketStored.h" #include "fsfw/tmtcservices/AcceptsTelemetryIF.h" #include "fsfw/tmtcservices/PusVerificationReport.h" +#include "fsfw/tmtcservices/sendAndStoreHelper.h" Service1TelecommandVerification::Service1TelecommandVerification(object_id_t objectId, uint16_t apid, uint8_t serviceId, @@ -15,7 +15,9 @@ Service1TelecommandVerification::Service1TelecommandVerification(object_id_t obj : SystemObject(objectId), apid(apid), serviceId(serviceId), - targetDestination(targetDestination) { + targetDestination(targetDestination), + sendHelper(nullptr), + storeHelper(apid, nullptr) { tmQueue = QueueFactory::instance()->createMessageQueue(messageQueueDepth); } @@ -67,32 +69,23 @@ ReturnValue_t Service1TelecommandVerification::generateFailureReport( FailureReport report(message->getReportId(), message->getTcPacketId(), message->getTcSequenceControl(), message->getStep(), message->getErrorCode(), message->getParameter1(), message->getParameter2()); -#if FSFW_USE_PUS_C_TELEMETRY == 0 - TmPacketStoredPusA tmPacket(apid, serviceId, message->getReportId(), packetSubCounter++, &report); -#else - TmPacketStoredPusC tmPacket(apid, serviceId, message->getReportId(), packetSubCounter++, &report); -#endif - ReturnValue_t result = tmPacket.sendPacket(tmQueue->getDefaultDestination(), tmQueue->getId()); - return result; + storeHelper.preparePacket(serviceId, message->getReportId(), packetSubCounter++); + storeHelper.setSourceDataSerializable(&report); + return tm::storeAndSendTmPacket(storeHelper, sendHelper); } ReturnValue_t Service1TelecommandVerification::generateSuccessReport( PusVerificationMessage* message) { SuccessReport report(message->getReportId(), message->getTcPacketId(), message->getTcSequenceControl(), message->getStep()); -#if FSFW_USE_PUS_C_TELEMETRY == 0 - TmPacketStoredPusA tmPacket(apid, serviceId, message->getReportId(), packetSubCounter++, &report); -#else - TmPacketStoredPusC tmPacket(apid, serviceId, message->getReportId(), packetSubCounter++, &report); -#endif - ReturnValue_t result = tmPacket.sendPacket(tmQueue->getDefaultDestination(), tmQueue->getId()); - return result; + storeHelper.preparePacket(serviceId, message->getReportId(), packetSubCounter++); + storeHelper.setSourceDataSerializable(&report); + return tm::storeAndSendTmPacket(storeHelper, sendHelper); } ReturnValue_t Service1TelecommandVerification::initialize() { // Get target object for TC verification messages - AcceptsTelemetryIF* funnel = - ObjectManager::instance()->get(targetDestination); + auto* funnel = ObjectManager::instance()->get(targetDestination); if (funnel == nullptr) { #if FSFW_CPP_OSTREAM_ENABLED == 1 sif::error << "Service1TelecommandVerification::initialize: Specified" @@ -103,5 +96,12 @@ ReturnValue_t Service1TelecommandVerification::initialize() { return ObjectManagerIF::CHILD_INIT_FAILED; } tmQueue->setDefaultDestination(funnel->getReportReceptionQueue()); + if (tmStore == nullptr) { + tmStore = ObjectManager::instance()->get(objects::TM_STORE); + if (tmStore == nullptr) { + return ObjectManager::CHILD_INIT_FAILED; + } + storeHelper.setTmStore(tmStore); + } return SystemObject::initialize(); } diff --git a/src/fsfw/pus/Service1TelecommandVerification.h b/src/fsfw/pus/Service1TelecommandVerification.h index 10d2da0e..a87acdfe 100644 --- a/src/fsfw/pus/Service1TelecommandVerification.h +++ b/src/fsfw/pus/Service1TelecommandVerification.h @@ -7,6 +7,8 @@ #include "fsfw/tasks/ExecutableObjectIF.h" #include "fsfw/tmtcservices/AcceptsVerifyMessageIF.h" #include "fsfw/tmtcservices/PusVerificationReport.h" +#include "fsfw/tmtcservices/TmSendHelper.h" +#include "fsfw/tmtcservices/TmStoreHelper.h" /** * @brief Verify TC acceptance, start, progress and execution. @@ -45,13 +47,13 @@ class Service1TelecommandVerification : public AcceptsVerifyMessageIF, Service1TelecommandVerification(object_id_t objectId, uint16_t apid, uint8_t serviceId, object_id_t targetDestination, uint16_t messageQueueDepth); - virtual ~Service1TelecommandVerification(); + ~Service1TelecommandVerification() override; /** * * @return ID of Verification Queue */ - virtual MessageQueueId_t getVerificationQueue() override; + MessageQueueId_t getVerificationQueue() override; /** * Performs the service periodically as specified in init_mission(). @@ -59,7 +61,7 @@ class Service1TelecommandVerification : public AcceptsVerifyMessageIF, * @param operationCode * @return */ - ReturnValue_t performOperation(uint8_t operationCode = 0) override; + ReturnValue_t performOperation(uint8_t operationCode) override; /** * Initializes the destination for TC verification messages and initializes @@ -80,6 +82,9 @@ class Service1TelecommandVerification : public AcceptsVerifyMessageIF, uint16_t packetSubCounter = 0; + TmSendHelper sendHelper; + TmStoreHelper storeHelper; + StorageManagerIF* tmStore = nullptr; MessageQueueIF* tmQueue = nullptr; enum class Subservice : uint8_t { diff --git a/src/fsfw/pus/Service20ParameterManagement.cpp b/src/fsfw/pus/Service20ParameterManagement.cpp index 61e29412..9354c80d 100644 --- a/src/fsfw/pus/Service20ParameterManagement.cpp +++ b/src/fsfw/pus/Service20ParameterManagement.cpp @@ -137,7 +137,7 @@ ReturnValue_t Service20ParameterManagement::prepareLoadCommand(CommandMessage* m if (parameterDataLen == 0) { return CommandingServiceBase::INVALID_TC; } - ReturnValue_t result = IPCStore->getFreeElement(&storeAddress, parameterDataLen, &storePointer); + ReturnValue_t result = ipcStore->getFreeElement(&storeAddress, parameterDataLen, &storePointer); if (result != HasReturnvaluesIF::RETURN_OK) { return result; } @@ -169,7 +169,7 @@ ReturnValue_t Service20ParameterManagement::handleReply(const CommandMessage* re switch (replyId) { case ParameterMessage::REPLY_PARAMETER_DUMP: { - ConstAccessorPair parameterData = IPCStore->getData(ParameterMessage::getStoreId(reply)); + ConstAccessorPair parameterData = ipcStore->getData(ParameterMessage::getStoreId(reply)); if (parameterData.first != HasReturnvaluesIF::RETURN_OK) { return HasReturnvaluesIF::RETURN_FAILED; } diff --git a/src/fsfw/pus/Service2DeviceAccess.cpp b/src/fsfw/pus/Service2DeviceAccess.cpp index 3430271e..8060b2b6 100644 --- a/src/fsfw/pus/Service2DeviceAccess.cpp +++ b/src/fsfw/pus/Service2DeviceAccess.cpp @@ -75,7 +75,7 @@ ReturnValue_t Service2DeviceAccess::prepareRawCommand(CommandMessage* messageToS // store command into the Inter Process Communication Store store_address_t storeAddress; ReturnValue_t result = - IPCStore->addData(&storeAddress, RawCommand.getCommand(), RawCommand.getCommandSize()); + ipcStore->addData(&storeAddress, RawCommand.getCommand(), RawCommand.getCommandSize()); DeviceHandlerMessage::setDeviceHandlerRawCommandMessage(messageToSet, storeAddress); return result; } @@ -135,7 +135,7 @@ void Service2DeviceAccess::sendWiretappingTm(CommandMessage* reply, uint8_t subs store_address_t storeAddress = DeviceHandlerMessage::getStoreAddress(reply); const uint8_t* data = nullptr; size_t size = 0; - ReturnValue_t result = IPCStore->getData(storeAddress, &data, &size); + ReturnValue_t result = ipcStore->getData(storeAddress, &data, &size); if (result != HasReturnvaluesIF::RETURN_OK) { #if FSFW_CPP_OSTREAM_ENABLED == 1 sif::error << "Service2DeviceAccess::sendWiretappingTm: Data Lost in " @@ -147,10 +147,8 @@ void Service2DeviceAccess::sendWiretappingTm(CommandMessage* reply, uint8_t subs // Init our dummy packet and correct endianness of object ID before // sending it back. - WiretappingPacket TmPacket(DeviceHandlerMessage::getDeviceObjectId(reply), data); - TmPacket.objectId = EndianConverter::convertBigEndian(TmPacket.objectId); - sendTmPacket(subservice, TmPacket.data, size, reinterpret_cast(&TmPacket.objectId), - sizeof(TmPacket.objectId)); + WiretappingPacket tmPacket(DeviceHandlerMessage::getDeviceObjectId(reply), data); + sendTmPacket(subservice, tmPacket.objectId, tmPacket.data, size); } MessageQueueId_t Service2DeviceAccess::getDeviceQueue() { return commandQueue->getId(); } diff --git a/src/fsfw/pus/Service3Housekeeping.cpp b/src/fsfw/pus/Service3Housekeeping.cpp index 07574783..7ef5636d 100644 --- a/src/fsfw/pus/Service3Housekeeping.cpp +++ b/src/fsfw/pus/Service3Housekeeping.cpp @@ -284,14 +284,13 @@ ReturnValue_t Service3Housekeeping::generateHkReply(const CommandMessage* hkMess store_address_t storeId; sid_t sid = HousekeepingMessage::getHkDataReply(hkMessage, &storeId); - auto resultPair = IPCStore->getData(storeId); + auto resultPair = ipcStore->getData(storeId); if (resultPair.first != HasReturnvaluesIF::RETURN_OK) { return resultPair.first; } HkPacket hkPacket(sid, resultPair.second.data(), resultPair.second.size()); - return sendTmPacket(static_cast(subserviceId), hkPacket.hkData, hkPacket.hkSize, nullptr, - 0); + return sendTmPacket(static_cast(subserviceId), hkPacket.hkData, hkPacket.hkSize); } sid_t Service3Housekeeping::buildSid(object_id_t objectId, const uint8_t** tcData, diff --git a/src/fsfw/pus/Service5EventReporting.cpp b/src/fsfw/pus/Service5EventReporting.cpp index 987217dc..4d0dcf1d 100644 --- a/src/fsfw/pus/Service5EventReporting.cpp +++ b/src/fsfw/pus/Service5EventReporting.cpp @@ -6,11 +6,14 @@ #include "fsfw/pus/servicepackets/Service5Packets.h" #include "fsfw/serviceinterface/ServiceInterface.h" #include "fsfw/tmtcpacket/pus/tm/TmPacketStored.h" +#include "fsfw/tmtcservices/sendAndStoreHelper.h" Service5EventReporting::Service5EventReporting(object_id_t objectId, uint16_t apid, uint8_t serviceId, size_t maxNumberReportsPerCycle, uint32_t messageQueueDepth) : PusServiceBase(objectId, apid, serviceId), + sendHelper(nullptr), + storeHelper(apid, nullptr), maxNumberReportsPerCycle(maxNumberReportsPerCycle) { eventQueue = QueueFactory::instance()->createMessageQueue(messageQueueDepth); } @@ -45,15 +48,9 @@ ReturnValue_t Service5EventReporting::performService() { ReturnValue_t Service5EventReporting::generateEventReport(EventMessage message) { EventReport report(message.getEventId(), message.getReporter(), message.getParameter1(), message.getParameter2()); -#if FSFW_USE_PUS_C_TELEMETRY == 0 - TmPacketStoredPusA tmPacket(PusServiceBase::apid, PusServiceBase::serviceId, - message.getSeverity(), packetSubCounter++, &report); -#else - TmPacketStoredPusC tmPacket(PusServiceBase::apid, PusServiceBase::serviceId, - message.getSeverity(), packetSubCounter++, &report); -#endif - ReturnValue_t result = - tmPacket.sendPacket(requestQueue->getDefaultDestination(), requestQueue->getId()); + storeHelper.preparePacket(serviceId, message.getSeverity(), packetSubCounter); + storeHelper.setSourceDataSerializable(&report); + ReturnValue_t result = tm::storeAndSendTmPacket(storeHelper, sendHelper); if (result != HasReturnvaluesIF::RETURN_OK) { #if FSFW_CPP_OSTREAM_ENABLED == 1 sif::warning << "Service5EventReporting::generateEventReport: " @@ -64,6 +61,8 @@ ReturnValue_t Service5EventReporting::generateEventReport(EventMessage message) "Service5EventReporting::generateEventReport: " "Could not send TM packet\n"); #endif + } else { + packetSubCounter++; } return result; } @@ -86,14 +85,18 @@ ReturnValue_t Service5EventReporting::handleRequest(uint8_t subservice) { // In addition to the default PUSServiceBase initialization, this service needs // to be registered to the event manager to listen for events. ReturnValue_t Service5EventReporting::initialize() { + ReturnValue_t result = PusServiceBase::initialize(); + if (result != HasReturnvaluesIF::RETURN_OK) { + return result; + } auto* manager = ObjectManager::instance()->get(objects::EVENT_MANAGER); if (manager == nullptr) { return RETURN_FAILED; } // register Service 5 as listener for events - ReturnValue_t result = manager->registerListener(eventQueue->getId(), true); + result = manager->registerListener(eventQueue->getId(), true); if (result != HasReturnvaluesIF::RETURN_OK) { return result; } - return PusServiceBase::initialize(); + initializeTmHelpers(sendHelper, storeHelper); } diff --git a/src/fsfw/pus/Service5EventReporting.h b/src/fsfw/pus/Service5EventReporting.h index 74264130..a357e5fc 100644 --- a/src/fsfw/pus/Service5EventReporting.h +++ b/src/fsfw/pus/Service5EventReporting.h @@ -42,7 +42,7 @@ class Service5EventReporting : public PusServiceBase { public: Service5EventReporting(object_id_t objectId, uint16_t apid, uint8_t serviceId, size_t maxNumberReportsPerCycle = 10, uint32_t messageQueueDepth = 10); - virtual ~Service5EventReporting(); + ~Service5EventReporting() override; /*** * Check for events and generate event reports if required. @@ -77,6 +77,8 @@ class Service5EventReporting : public PusServiceBase { uint16_t packetSubCounter = 0; MessageQueueIF* eventQueue = nullptr; bool enableEventReport = true; + TmSendHelper sendHelper; + TmStoreHelper storeHelper; const uint8_t maxNumberReportsPerCycle; ReturnValue_t generateEventReport(EventMessage message); diff --git a/src/fsfw/pus/Service8FunctionManagement.cpp b/src/fsfw/pus/Service8FunctionManagement.cpp index be8d9058..0b3784be 100644 --- a/src/fsfw/pus/Service8FunctionManagement.cpp +++ b/src/fsfw/pus/Service8FunctionManagement.cpp @@ -78,7 +78,7 @@ ReturnValue_t Service8FunctionManagement::prepareDirectCommand(CommandMessage* m // store additional parameters into the IPC Store store_address_t parameterAddress; ReturnValue_t result = - IPCStore->addData(¶meterAddress, command.getParameters(), command.getParametersSize()); + ipcStore->addData(¶meterAddress, command.getParameters(), command.getParametersSize()); // setCommand expects a Command Message, an Action ID and a store adress // pointing to additional parameters @@ -130,7 +130,7 @@ ReturnValue_t Service8FunctionManagement::handleDataReply(const CommandMessage* store_address_t storeId = ActionMessage::getStoreId(reply); size_t size = 0; const uint8_t* buffer = nullptr; - ReturnValue_t result = IPCStore->getData(storeId, &buffer, &size); + ReturnValue_t result = ipcStore->getData(storeId, &buffer, &size); if (result != RETURN_OK) { #if FSFW_CPP_OSTREAM_ENABLED == 1 sif::error << "Service 8: Could not retrieve data for data reply" << std::endl; @@ -140,7 +140,7 @@ ReturnValue_t Service8FunctionManagement::handleDataReply(const CommandMessage* DataReply dataReply(objectId, actionId, buffer, size); result = sendTmPacket(static_cast(Subservice::REPLY_DIRECT_COMMANDING_DATA), &dataReply); - auto deletionResult = IPCStore->deleteData(storeId); + auto deletionResult = ipcStore->deleteData(storeId); if (deletionResult != HasReturnvaluesIF::RETURN_OK) { #if FSFW_CPP_OSTREAM_ENABLED == 1 sif::warning << "Service8FunctionManagement::handleReply: Deletion" diff --git a/src/fsfw/pus/Service9TimeManagement.cpp b/src/fsfw/pus/Service9TimeManagement.cpp index 6cd46f3a..99b447c1 100644 --- a/src/fsfw/pus/Service9TimeManagement.cpp +++ b/src/fsfw/pus/Service9TimeManagement.cpp @@ -9,7 +9,7 @@ Service9TimeManagement::Service9TimeManagement(object_id_t objectId, uint16_t ap uint8_t serviceId) : PusServiceBase(objectId, apid, serviceId) {} -Service9TimeManagement::~Service9TimeManagement() {} +Service9TimeManagement::~Service9TimeManagement() = default; ReturnValue_t Service9TimeManagement::performService() { return RETURN_OK; } @@ -25,7 +25,9 @@ ReturnValue_t Service9TimeManagement::handleRequest(uint8_t subservice) { ReturnValue_t Service9TimeManagement::setTime() { Clock::TimeOfDay_t timeToSet; - TimePacket timePacket(currentPacket.getUserData(), currentPacket.getUserDataSize()); + size_t userDataLen = 0; + const uint8_t* timeData = currentPacket.getUserData(userDataLen); + TimePacket timePacket(timeData, userDataLen); ReturnValue_t result = CCSDSTime::convertFromCcsds(&timeToSet, timePacket.getTime(), timePacket.getTimeSize()); if (result != RETURN_OK) { diff --git a/src/fsfw/pus/servicepackets/Service9Packets.h b/src/fsfw/pus/servicepackets/Service9Packets.h index 076536e8..082a65fa 100644 --- a/src/fsfw/pus/servicepackets/Service9Packets.h +++ b/src/fsfw/pus/servicepackets/Service9Packets.h @@ -1,7 +1,7 @@ #ifndef FSFW_PUS_SERVICEPACKETS_SERVICE9PACKETS_H_ #define FSFW_PUS_SERVICEPACKETS_SERVICE9PACKETS_H_ -#include "../../serialize/SerialLinkedListAdapter.h" +#include "fsfw/serialize/SerialLinkedListAdapter.h" /** * @brief Subservice 128 @@ -11,16 +11,16 @@ */ class TimePacket : SerialLinkedListAdapter { //!< [EXPORT] : [SUBSERVICE] 128 public: + TimePacket(const TimePacket& command) = delete; TimePacket(const uint8_t* timeBuffer_, uint32_t timeSize_) { timeBuffer = timeBuffer_; timeSize = timeSize_; } const uint8_t* getTime() { return timeBuffer; } - uint32_t getTimeSize() const { return timeSize; } + [[nodiscard]] uint32_t getTimeSize() const { return timeSize; } private: - TimePacket(const TimePacket& command); const uint8_t* timeBuffer; uint32_t timeSize; //!< [EXPORT] : [IGNORE] }; diff --git a/src/fsfw/storagemanager/StorageManagerIF.h b/src/fsfw/storagemanager/StorageManagerIF.h index 375fc7cc..a8313344 100644 --- a/src/fsfw/storagemanager/StorageManagerIF.h +++ b/src/fsfw/storagemanager/StorageManagerIF.h @@ -55,7 +55,7 @@ class StorageManagerIF : public HasReturnvaluesIF { /** * @brief This is the empty virtual destructor as required for C++ interfaces. */ - virtual ~StorageManagerIF(){}; + ~StorageManagerIF() override = default; /** * @brief With addData, a free storage position is allocated and data * stored there. @@ -160,8 +160,8 @@ class StorageManagerIF : public HasReturnvaluesIF { * @li RETURN_FAILED if data could not be added. * storageId is unchanged then. */ - virtual ReturnValue_t getFreeElement(store_address_t* storageId, const size_t size, - uint8_t** p_data, bool ignoreFault = false) = 0; + virtual ReturnValue_t getFreeElement(store_address_t* storageId, size_t size, uint8_t** p_data, + bool ignoreFault = false) = 0; /** * Clears the whole store. @@ -192,7 +192,7 @@ class StorageManagerIF : public HasReturnvaluesIF { * Get number of pools. * @return */ - virtual max_subpools_t getNumberOfSubPools() const = 0; + [[nodiscard]] virtual max_subpools_t getNumberOfSubPools() const = 0; }; #endif /* FSFW_STORAGEMANAGER_STORAGEMANAGERIF_H_ */ diff --git a/src/fsfw/tcdistribution/PusDistributor.cpp b/src/fsfw/tcdistribution/PusDistributor.cpp index 5975a7f2..687c5f00 100644 --- a/src/fsfw/tcdistribution/PusDistributor.cpp +++ b/src/fsfw/tcdistribution/PusDistributor.cpp @@ -36,7 +36,7 @@ PusDistributor::TcMqMapIter PusDistributor::selectDestination() { HasReturnvaluesIF::RETURN_OK) { return queueMapIt; } - reader.setData(packetPtr, packetLen); + reader.setReadOnlyData(packetPtr, packetLen); // this->currentPacket->setStoreAddress(this->currentMessage.getStorageId(), currentPacket); if (reader.getFullData() != nullptr) { tcStatus = diff --git a/src/fsfw/timemanager/TimeStamper.h b/src/fsfw/timemanager/CdsShortTimeStamper.h similarity index 60% rename from src/fsfw/timemanager/TimeStamper.h rename to src/fsfw/timemanager/CdsShortTimeStamper.h index aa311ec4..1e9abfa8 100644 --- a/src/fsfw/timemanager/TimeStamper.h +++ b/src/fsfw/timemanager/CdsShortTimeStamper.h @@ -14,14 +14,15 @@ * overriding the #addTimeStamp function. * @ingroup utility */ -class TimeStamper : public TimeStamperIF, public SystemObject { +class CdsShortTimeStamper : public TimeStamperIF, public SystemObject { public: + static constexpr size_t TIMESTAMP_LEN = 7; /** * @brief Default constructor which also registers the time stamper as a * system object so it can be found with the #objectManager. * @param objectId */ - TimeStamper(object_id_t objectId); + explicit CdsShortTimeStamper(object_id_t objectId); /** * Adds a CCSDS CDC short 8 byte timestamp to the given buffer. @@ -30,7 +31,13 @@ class TimeStamper : public TimeStamperIF, public SystemObject { * @param maxSize * @return */ - virtual ReturnValue_t addTimeStamp(uint8_t* buffer, const uint8_t maxSize); + ReturnValue_t addTimeStamp(uint8_t *buffer, uint8_t maxSize) override; + ReturnValue_t serialize(uint8_t **buffer, size_t *size, size_t maxSize, + Endianness streamEndianness) const override; + size_t getSerializedSize() const override; + ReturnValue_t deSerialize(const uint8_t **buffer, size_t *size, + Endianness streamEndianness) override; + size_t getTimestampSize() const override; }; #endif /* FSFW_TIMEMANAGER_TIMESTAMPER_H_ */ diff --git a/src/fsfw/timemanager/TimeStamper.cpp b/src/fsfw/timemanager/TimeStamper.cpp index 9b4ad3d3..7096d95f 100644 --- a/src/fsfw/timemanager/TimeStamper.cpp +++ b/src/fsfw/timemanager/TimeStamper.cpp @@ -1,23 +1,35 @@ -#include "fsfw/timemanager/TimeStamper.h" - #include +#include "fsfw/timemanager/CdsShortTimeStamper.h" #include "fsfw/timemanager/Clock.h" -TimeStamper::TimeStamper(object_id_t objectId) : SystemObject(objectId) {} +CdsShortTimeStamper::CdsShortTimeStamper(object_id_t objectId) : SystemObject(objectId) {} -ReturnValue_t TimeStamper::addTimeStamp(uint8_t* buffer, const uint8_t maxSize) { - if (maxSize < TimeStamperIF::MISSION_TIMESTAMP_SIZE) { - return HasReturnvaluesIF::RETURN_FAILED; +ReturnValue_t CdsShortTimeStamper::addTimeStamp(uint8_t *buffer, const uint8_t maxSize) { + size_t serLen = 0; + return serialize(&buffer, &serLen, maxSize, SerializeIF::Endianness::NETWORK); +} + +ReturnValue_t CdsShortTimeStamper::serialize(uint8_t **buffer, size_t *size, size_t maxSize, + SerializeIF::Endianness streamEndianness) const { + if (*size + getSerializedSize() > maxSize) { + return SerializeIF::BUFFER_TOO_SHORT; } - - timeval now; + timeval now{}; Clock::getClock_timeval(&now); - CCSDSTime::CDS_short cds; + CCSDSTime::CDS_short cds{}; ReturnValue_t result = CCSDSTime::convertToCcsds(&cds, &now); if (result != HasReturnvaluesIF::RETURN_OK) { return result; } - std::memcpy(buffer, &cds, sizeof(cds)); + std::memcpy(*buffer, &cds, sizeof(cds)); + *buffer += getSerializedSize(); + *size += getSerializedSize(); return result; } +size_t CdsShortTimeStamper::getSerializedSize() const { return getTimestampSize(); } +ReturnValue_t CdsShortTimeStamper::deSerialize(const uint8_t **buffer, size_t *size, + SerializeIF::Endianness streamEndianness) { + return HasReturnvaluesIF::RETURN_FAILED; +} +size_t CdsShortTimeStamper::getTimestampSize() const { return TIMESTAMP_LEN; } diff --git a/src/fsfw/timemanager/TimeStamperIF.h b/src/fsfw/timemanager/TimeStamperIF.h index 5c3880ea..404dd10a 100644 --- a/src/fsfw/timemanager/TimeStamperIF.h +++ b/src/fsfw/timemanager/TimeStamperIF.h @@ -1,9 +1,8 @@ #ifndef FSFW_TIMEMANAGER_TIMESTAMPERIF_H_ #define FSFW_TIMEMANAGER_TIMESTAMPERIF_H_ -#include - -#include "../returnvalues/HasReturnvaluesIF.h" +#include "fsfw/returnvalues/HasReturnvaluesIF.h" +#include "fsfw/serialize/SerializeIF.h" /** * A class implementing this IF provides facilities to add a time stamp to the @@ -11,17 +10,21 @@ * Implementors need to ensure that calling the method is thread-safe, i.e. * addTimeStamp may be called in parallel from a different context. */ -class TimeStamperIF { +class TimeStamperIF : public SerializeIF { public: static const uint8_t INTERFACE_ID = CLASS_ID::TIME_STAMPER_IF; static const ReturnValue_t BAD_TIMESTAMP = MAKE_RETURN_CODE(1); + // I am going to assume there are no larger timestamps + static constexpr size_t MAXIMUM_TIMESTAMP_LEN = 16; + //! This is a mission-specific constant and determines the total //! size reserved for timestamps. - static const uint8_t MISSION_TIMESTAMP_SIZE = fsfwconfig::FSFW_MISSION_TIMESTAMP_SIZE; + // static const uint8_t MISSION_TIMESTAMP_SIZE = fsfwconfig::FSFW_MISSION_TIMESTAMP_SIZE; - virtual ReturnValue_t addTimeStamp(uint8_t* buffer, const uint8_t maxSize) = 0; - virtual ~TimeStamperIF() {} + [[nodiscard]] virtual size_t getTimestampSize() const = 0; + virtual ReturnValue_t addTimeStamp(uint8_t* buffer, uint8_t maxSize) = 0; + ~TimeStamperIF() override = default; }; #endif /* FSFW_TIMEMANAGER_TIMESTAMPERIF_H_ */ diff --git a/src/fsfw/tmtcpacket/ccsds/SpacePacketCreator.cpp b/src/fsfw/tmtcpacket/ccsds/SpacePacketCreator.cpp index ce1852ab..94cf45f4 100644 --- a/src/fsfw/tmtcpacket/ccsds/SpacePacketCreator.cpp +++ b/src/fsfw/tmtcpacket/ccsds/SpacePacketCreator.cpp @@ -75,3 +75,7 @@ void SpacePacketCreator::checkFieldValidity() { valid = false; } } + +void SpacePacketCreator::setParams(SpacePacketParams params_) { params = std::move(params_); } + +SpacePacketParams &SpacePacketCreator::getParams() { return params; } diff --git a/src/fsfw/tmtcpacket/ccsds/SpacePacketCreator.h b/src/fsfw/tmtcpacket/ccsds/SpacePacketCreator.h index 5e2888c0..dd5edbd5 100644 --- a/src/fsfw/tmtcpacket/ccsds/SpacePacketCreator.h +++ b/src/fsfw/tmtcpacket/ccsds/SpacePacketCreator.h @@ -9,6 +9,8 @@ #include "fsfw/serialize/SerializeIF.h" struct SpacePacketParams { + SpacePacketParams() = default; + SpacePacketParams(PacketId packetId, PacketSeqCtrl psc, uint16_t dataLen) : packetId(std::move(packetId)), packetSeqCtrl(std::move(psc)), dataLen(dataLen) {} @@ -20,6 +22,7 @@ struct SpacePacketParams { class SpacePacketCreator : public SpacePacketIF, public SerializeIF { public: + SpacePacketCreator() = default; explicit SpacePacketCreator(SpacePacketParams params); SpacePacketCreator(ccsds::PacketType packetType, bool secHeaderFlag, uint16_t apid, ccsds::SequenceFlags seqFlags, uint16_t seqCount, uint16_t dataLen, @@ -30,6 +33,8 @@ class SpacePacketCreator : public SpacePacketIF, public SerializeIF { [[nodiscard]] uint16_t getPacketSeqCtrlRaw() const override; [[nodiscard]] uint16_t getPacketDataLen() const override; + SpacePacketParams &getParams(); + void setParams(SpacePacketParams params); void setApid(uint16_t apid); void setSeqCount(uint16_t seqCount); void setSeqFlags(ccsds::SequenceFlags flags); @@ -45,9 +50,7 @@ class SpacePacketCreator : public SpacePacketIF, public SerializeIF { private: void checkFieldValidity(); - - SpacePacketCreator() = default; bool valid{}; - SpacePacketParams params; + SpacePacketParams params{}; }; #endif // FSFW_TMTCPACKET_SPACEPACKETCREATOR_H diff --git a/src/fsfw/tmtcpacket/ccsds/SpacePacketIF.h b/src/fsfw/tmtcpacket/ccsds/SpacePacketIF.h index 5db7b254..068e04d9 100644 --- a/src/fsfw/tmtcpacket/ccsds/SpacePacketIF.h +++ b/src/fsfw/tmtcpacket/ccsds/SpacePacketIF.h @@ -18,7 +18,7 @@ class SpacePacketIF { /** * This is the minimum size of a SpacePacket. */ - static const uint16_t MINIMUM_SIZE = sizeof(ccsds::PrimaryHeader) + CRC_SIZE; + static const uint16_t MIN_CCSDS_SIZE = sizeof(ccsds::PrimaryHeader) + CRC_SIZE; virtual ~SpacePacketIF() = default; diff --git a/src/fsfw/tmtcpacket/packetmatcher/PacketMatchTree.cpp b/src/fsfw/tmtcpacket/packetmatcher/PacketMatchTree.cpp index c1f6665a..fe0e1f69 100644 --- a/src/fsfw/tmtcpacket/packetmatcher/PacketMatchTree.cpp +++ b/src/fsfw/tmtcpacket/packetmatcher/PacketMatchTree.cpp @@ -31,7 +31,7 @@ PacketMatchTree::~PacketMatchTree() = default; ReturnValue_t PacketMatchTree::addMatch(uint16_t apid, uint8_t type, uint8_t subtype) { // We assume adding APID is always requested. - PusTmMinimal::TmPacketMinimalPointer data{}; + mintm::MinimalPusTm data{}; data.secHeader.service = type; data.secHeader.subservice = subtype; PusTmMinimal testPacket((uint8_t*)&data); @@ -122,7 +122,7 @@ ReturnValue_t PacketMatchTree::findOrInsertMatch(iterator startAt, VALUE_T test, } ReturnValue_t PacketMatchTree::removeMatch(uint16_t apid, uint8_t type, uint8_t subtype) { - PusTmMinimal::TmPacketMinimalPointer data{}; + mintm::MinimalPusTm data{}; data.secHeader.service = type; data.secHeader.subservice = subtype; PusTmMinimal testPacket((uint8_t*)&data); diff --git a/src/fsfw/tmtcpacket/pus/CreatorDataIF.h b/src/fsfw/tmtcpacket/pus/CreatorDataIF.h new file mode 100644 index 00000000..7d5d1d18 --- /dev/null +++ b/src/fsfw/tmtcpacket/pus/CreatorDataIF.h @@ -0,0 +1,10 @@ +#ifndef FSFW_TMTCPACKET_CREATORDATAIF_H +#define FSFW_TMTCPACKET_CREATORDATAIF_H + +#include "definitions.h" + +class CreatorDataIF { + public: + virtual ecss::DataWrapper& getDataWrapper() = 0; +}; +#endif // FSFW_TMTCPACKET_CREATORDATAIF_H diff --git a/src/fsfw/tmtcpacket/pus/PusIF.h b/src/fsfw/tmtcpacket/pus/PusIF.h index 5eeae04d..eb0e35f8 100644 --- a/src/fsfw/tmtcpacket/pus/PusIF.h +++ b/src/fsfw/tmtcpacket/pus/PusIF.h @@ -29,24 +29,6 @@ class PusIF : public SpacePacketIF { * @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/RawUserDataReaderIF.h b/src/fsfw/tmtcpacket/pus/RawUserDataReaderIF.h new file mode 100644 index 00000000..170ac824 --- /dev/null +++ b/src/fsfw/tmtcpacket/pus/RawUserDataReaderIF.h @@ -0,0 +1,12 @@ +#ifndef FSFW_TMTCPACKET_RAWDATAIF_H +#define FSFW_TMTCPACKET_RAWDATAIF_H + +#include +#include + +class RawUserDataReaderIF { + public: + virtual const uint8_t* getUserData(size_t& userDataLen) = 0; +}; + +#endif // FSFW_TMTCPACKET_RAWDATAIF_H diff --git a/src/fsfw/tmtcpacket/pus/definitions.h b/src/fsfw/tmtcpacket/pus/definitions.h index 369f869a..6a5c10eb 100644 --- a/src/fsfw/tmtcpacket/pus/definitions.h +++ b/src/fsfw/tmtcpacket/pus/definitions.h @@ -3,11 +3,39 @@ #include +#include "fsfw/serialize/SerializeIF.h" + namespace ecss { //! Version numbers according to ECSS-E-ST-70-41C p.439 enum PusVersion : uint8_t { PUS_A = 1, PUS_C = 2 }; +struct RawData { + const uint8_t* data; + size_t len; +}; + +enum DataTypes { RAW, SERIALIZABLE }; + +union DataUnion { + RawData raw; + SerializeIF* serializable; +}; + +struct DataWrapper { + DataTypes type; + DataUnion dataUnion; + + [[nodiscard]] size_t getLength() const { + if (type == DataTypes::RAW) { + return dataUnion.raw.len; + } else if (type == DataTypes::SERIALIZABLE and dataUnion.serializable != nullptr) { + return dataUnion.serializable->getSerializedSize(); + } + return 0; + } +}; + } // namespace ecss #endif /* FSFW_SRC_FSFW_TMTCPACKET_PUS_TM_DEFINITIONS_H_ */ diff --git a/src/fsfw/tmtcpacket/pus/tc/PusTcCreator.cpp b/src/fsfw/tmtcpacket/pus/tc/PusTcCreator.cpp index 7de759c8..8f8cc8e6 100644 --- a/src/fsfw/tmtcpacket/pus/tc/PusTcCreator.cpp +++ b/src/fsfw/tmtcpacket/pus/tc/PusTcCreator.cpp @@ -1,17 +1,20 @@ #include "PusTcCreator.h" +#include + #include "PusTcIF.h" #include "fsfw/globalfunctions/CRC.h" #include "fsfw/serialize/SerializeAdapter.h" PusTcCreator::PusTcCreator(SpacePacketParams spParams, PusTcParams pusParams) - : spCreator(spParams), pusParams(pusParams) { + : spCreator(std::move(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) { + size_t userDataLen = pusParams.dataWrapper.getLength(); + if (*size + PusTcIF::MIN_LEN + userDataLen > maxSize) { return SerializeIF::BUFFER_TOO_SHORT; } ReturnValue_t result = spCreator.serialize(buffer, size, maxSize, streamEndianness); @@ -33,15 +36,28 @@ ReturnValue_t PusTcCreator::serialize(uint8_t **buffer, size_t *size, size_t max if (result != HasReturnvaluesIF::RETURN_OK) { return result; } - std::memcpy(*buffer, pusParams.appData, pusParams.appDataLen); - *buffer += pusParams.appDataLen; - *size += pusParams.appDataLen; + if (pusParams.dataWrapper.type == ecss::DataTypes::RAW) { + const uint8_t *data = pusParams.dataWrapper.dataUnion.raw.data; + if (data != nullptr and userDataLen > 0) { + std::memcpy(*buffer, data, userDataLen); + *buffer += userDataLen; + *size += userDataLen; + } + } else if (pusParams.dataWrapper.type == ecss::DataTypes::SERIALIZABLE and + pusParams.dataWrapper.dataUnion.serializable != nullptr) { + result = pusParams.dataWrapper.dataUnion.serializable->serialize(buffer, size, maxSize, + streamEndianness); + if (result != HasReturnvaluesIF::RETURN_OK) { + return result; + } + } + 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); + spCreator.setDataLen(ecss::PusTcDataFieldHeader::MIN_LEN + pusParams.dataWrapper.getLength() + 1); } size_t PusTcCreator::getSerializedSize() const { return spCreator.getFullPacketLen(); } @@ -66,10 +82,4 @@ 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; } +ecss::DataWrapper &PusTcCreator::getDataWrapper() { return pusParams.dataWrapper; } diff --git a/src/fsfw/tmtcpacket/pus/tc/PusTcCreator.h b/src/fsfw/tmtcpacket/pus/tc/PusTcCreator.h index cc220fa9..956a2505 100644 --- a/src/fsfw/tmtcpacket/pus/tc/PusTcCreator.h +++ b/src/fsfw/tmtcpacket/pus/tc/PusTcCreator.h @@ -4,6 +4,7 @@ #include "fsfw/tmtcpacket/RedirectableDataPointerIF.h" #include "fsfw/tmtcpacket/ccsds/SpacePacketCreator.h" #include "fsfw/tmtcpacket/ccsds/SpacePacketIF.h" +#include "fsfw/tmtcpacket/pus/CreatorDataIF.h" #include "fsfw/tmtcpacket/pus/definitions.h" #include "fsfw/tmtcpacket/pus/tc/PusTcIF.h" @@ -14,12 +15,11 @@ struct PusTcParams { uint8_t subservice; uint8_t ackFlags = ecss::ACK_ALL; uint16_t sourceId = 0; - uint8_t *appData = nullptr; - size_t appDataLen = 0; + ecss::DataWrapper dataWrapper{}; uint8_t pusVersion = ecss::PusVersion::PUS_C; }; -class PusTcCreator : public PusTcIF, public SerializeIF { +class PusTcCreator : public PusTcIF, public SerializeIF, public CreatorDataIF { public: PusTcCreator(SpacePacketParams spParams, PusTcParams pusParams); @@ -37,8 +37,7 @@ class PusTcCreator : public PusTcIF, public SerializeIF { [[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; + ecss::DataWrapper &getDataWrapper() override; private: SpacePacketCreator spCreator; diff --git a/src/fsfw/tmtcpacket/pus/tc/PusTcIF.h b/src/fsfw/tmtcpacket/pus/tc/PusTcIF.h index 889260c1..61b29660 100644 --- a/src/fsfw/tmtcpacket/pus/tc/PusTcIF.h +++ b/src/fsfw/tmtcpacket/pus/tc/PusTcIF.h @@ -23,7 +23,7 @@ enum AckField { static constexpr uint8_t ACK_ALL = ACK_ACCEPTANCE | ACK_START | ACK_STEP | ACK_COMPLETION; /** - * This struct defines a byte-wise structured PUS C ata Field Header. + * This struct defines a byte-wise structured PUS C data Field Header. * Any optional fields in the header must be added or removed here. * Currently, the Source Id field is present with one byte. * No spare byte support for now. diff --git a/src/fsfw/tmtcpacket/pus/tc/PusTcReader.cpp b/src/fsfw/tmtcpacket/pus/tc/PusTcReader.cpp index 43c30a46..bf4ec181 100644 --- a/src/fsfw/tmtcpacket/pus/tc/PusTcReader.cpp +++ b/src/fsfw/tmtcpacket/pus/tc/PusTcReader.cpp @@ -7,7 +7,7 @@ #include "fsfw/serialize.h" #include "fsfw/serviceinterface/ServiceInterface.h" -PusTcReader::PusTcReader(const uint8_t* data, size_t size) { setData(data, size); } +PusTcReader::PusTcReader(const uint8_t* data, size_t size) { setReadOnlyData(data, size); } PusTcReader::~PusTcReader() = default; @@ -39,12 +39,6 @@ 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]; @@ -62,11 +56,17 @@ ReturnValue_t PusTcReader::setData(uint8_t* pData, size_t size_, void* args) { spReader.setData(pData, size_, args); return HasReturnvaluesIF::RETURN_OK; } -ReturnValue_t PusTcReader::setData(const uint8_t* data, size_t size_) { + +ReturnValue_t PusTcReader::setReadOnlyData(const uint8_t* data, size_t size_) { setData(const_cast(data), size_, nullptr); return HasReturnvaluesIF::RETURN_OK; } +const uint8_t* PusTcReader::getUserData(size_t& userDataLen) { + userDataLen = appDataSize; + return pointers.userDataStart; +} + /* void PusTcReader::print() { #if FSFW_CPP_OSTREAM_ENABLED == 1 diff --git a/src/fsfw/tmtcpacket/pus/tc/PusTcReader.h b/src/fsfw/tmtcpacket/pus/tc/PusTcReader.h index b2045761..0cf18496 100644 --- a/src/fsfw/tmtcpacket/pus/tc/PusTcReader.h +++ b/src/fsfw/tmtcpacket/pus/tc/PusTcReader.h @@ -6,6 +6,7 @@ #include "PusTcIF.h" #include "fsfw/tmtcpacket/RedirectableDataPointerIF.h" #include "fsfw/tmtcpacket/ccsds/SpacePacketReader.h" +#include "fsfw/tmtcpacket/pus/RawUserDataReaderIF.h" /** * This class is the basic data handler for any ECSS PUS Telecommand packet. @@ -18,7 +19,10 @@ * check can be performed by making use of the getWholeData method. * @ingroup tmtcpackets */ -class PusTcReader : public PusTcIF, public ReadablePacketIF, public RedirectableDataPointerIF { +class PusTcReader : public PusTcIF, + public RawUserDataReaderIF, + public ReadablePacketIF, + public RedirectableDataPointerIF { public: PusTcReader() = default; /** @@ -48,12 +52,11 @@ class PusTcReader : public PusTcIF, public ReadablePacketIF, public Redirectable [[nodiscard]] uint8_t getService() const override; [[nodiscard]] uint8_t getSubService() const override; [[nodiscard]] uint16_t getSourceId() 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); + ReturnValue_t setReadOnlyData(const uint8_t* data, size_t size); + const uint8_t* getUserData(size_t& userDataLen) override; protected: /** diff --git a/src/fsfw/tmtcpacket/pus/tm/PusTmCreator.cpp b/src/fsfw/tmtcpacket/pus/tm/PusTmCreator.cpp index acf0435d..e80eddd1 100644 --- a/src/fsfw/tmtcpacket/pus/tm/PusTmCreator.cpp +++ b/src/fsfw/tmtcpacket/pus/tm/PusTmCreator.cpp @@ -1,6 +1,19 @@ #include "PusTmCreator.h" -PusTmCreator::PusTmCreator(PusTmParams& params_) : params(params_){}; +#include + +#include "fsfw/globalfunctions/CRC.h" +#include "fsfw/timemanager/TimeStamperIF.h" + +PusTmCreator::PusTmCreator(SpacePacketParams initSpParams, PusTmParams initPusParams, + TimeStamperIF* timeStamper) + : pusParams(initPusParams), spCreator(std::move(initSpParams)){}; + +PusTmCreator::PusTmCreator(TimeStamperIF* timeStamper_) { + pusParams.secHeader.timeStamper = timeStamper_; +}; + +PusTmCreator::PusTmCreator() = default; uint16_t PusTmCreator::getPacketIdRaw() const { return 0; } uint16_t PusTmCreator::getPacketSeqCtrlRaw() const { return 0; } @@ -8,5 +21,79 @@ 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; } -const uint8_t* PusTmCreator::getUserData(size_t& appDataLen) const { return nullptr; } -uint16_t PusTmCreator::getUserDataSize() const { return 0; } +PusTmParams& PusTmCreator::getParams() { return pusParams; } +void PusTmCreator::setTimeStamper(TimeStamperIF* timeStamper_) { + pusParams.secHeader.timeStamper = timeStamper_; +} +uint8_t PusTmCreator::getScTimeRefStatus() { return 0; } +uint16_t PusTmCreator::getMessageTypeCounter() { return 0; } +uint16_t PusTmCreator::getDestId() { return 0; } + +ReturnValue_t PusTmCreator::serialize(uint8_t** buffer, size_t* size, size_t maxSize, + SerializeIF::Endianness streamEndianness) const { + if (*size + getSerializedSize() > maxSize) { + return SerializeIF::BUFFER_TOO_SHORT; + } + ReturnValue_t result = spCreator.serialize(buffer, size, maxSize); + if (result != HasReturnvaluesIF::RETURN_OK) { + return result; + } + size_t userDataLen = pusParams.dataWrapper.getLength(); + **buffer = + ((pusParams.secHeader.pusVersion << 4) & 0xF0) | (pusParams.secHeader.scTimeRefStatus & 0x0F); + *buffer += 1; + **buffer = pusParams.secHeader.service; + *buffer += 1; + **buffer = pusParams.secHeader.subservice; + *buffer += 1; + *size += 3; + result = SerializeAdapter::serialize(&pusParams.secHeader.messageTypeCounter, buffer, size, + maxSize, streamEndianness); + if (result != HasReturnvaluesIF::RETURN_OK) { + return result; + } + result = SerializeAdapter::serialize(&pusParams.secHeader.destId, buffer, size, maxSize, + streamEndianness); + if (result != HasReturnvaluesIF::RETURN_OK) { + return result; + } + result = pusParams.secHeader.timeStamper->serialize(buffer, size, maxSize, streamEndianness); + if (result != HasReturnvaluesIF::RETURN_OK) { + return result; + } + if (pusParams.dataWrapper.type == ecss::DataTypes::RAW and + pusParams.dataWrapper.dataUnion.raw.data != nullptr) { + std::memcpy(*buffer, pusParams.dataWrapper.dataUnion.raw.data, userDataLen); + *buffer += userDataLen; + *size += userDataLen; + } else if (pusParams.dataWrapper.type == ecss::DataTypes::SERIALIZABLE and + pusParams.dataWrapper.dataUnion.serializable != nullptr) { + result = pusParams.dataWrapper.dataUnion.serializable->serialize(buffer, size, maxSize, + streamEndianness); + if (result != HasReturnvaluesIF::RETURN_OK) { + return result; + } + } + uint16_t crc16 = CRC::crc16ccitt(*buffer, getFullPacketLen() - 2); + return SerializeAdapter::serialize(&crc16, buffer, size, maxSize, streamEndianness); +} + +size_t PusTmCreator::getSerializedSize() const { return getFullPacketLen(); } +ReturnValue_t PusTmCreator::deSerialize(const uint8_t** buffer, size_t* size, + SerializeIF::Endianness streamEndianness) { + return HasReturnvaluesIF::RETURN_FAILED; +} + +ecss::DataWrapper& PusTmCreator::getDataWrapper() { return pusParams.dataWrapper; } +TimeStamperIF* PusTmCreator::getTimestamper() { return pusParams.secHeader.timeStamper; } +SpacePacketParams& PusTmCreator::getSpParams() { return spCreator.getParams(); } + +void PusTmCreator::updateSpLengthField() { + size_t headerLen = PusTmIF::MIN_TM_SIZE; + if (pusParams.secHeader.timeStamper != nullptr) { + headerLen += pusParams.secHeader.timeStamper->getSerializedSize(); + } + spCreator.setDataLen(headerLen + pusParams.dataWrapper.getLength() + 1); +} + +void PusTmCreator::setApid(uint16_t apid) { spCreator.setApid(apid); }; diff --git a/src/fsfw/tmtcpacket/pus/tm/PusTmCreator.h b/src/fsfw/tmtcpacket/pus/tm/PusTmCreator.h index 4a45e904..5269bd0f 100644 --- a/src/fsfw/tmtcpacket/pus/tm/PusTmCreator.h +++ b/src/fsfw/tmtcpacket/pus/tm/PusTmCreator.h @@ -1,33 +1,62 @@ #ifndef FSFW_TMTCPACKET_TMPACKETCREATOR_H #define FSFW_TMTCPACKET_TMPACKETCREATOR_H -#include "fsfw/tmtcpacket/pus/PusIF.h" +#include "PusTmIF.h" +#include "fsfw/tmtcpacket/ccsds/SpacePacketCreator.h" +#include "fsfw/tmtcpacket/pus/CreatorDataIF.h" -struct PusTmParams { +struct PusTmSecHeader { uint8_t pusVersion; uint8_t scTimeRefStatus; uint8_t service; uint8_t subservice; uint16_t messageTypeCounter; uint16_t destId; - uint8_t* timestamp; - size_t timestampLen; + TimeStamperIF* timeStamper; }; -class PusTmCreator : public PusIF { - public: - ~PusTmCreator() override = default; - explicit PusTmCreator(PusTmParams& params); +struct PusTmParams { + PusTmSecHeader secHeader; + ecss::DataWrapper dataWrapper; +}; + +class TimeStamperIF; + +class PusTmCreator : public SerializeIF, public PusTmIF, public CreatorDataIF { + public: + PusTmCreator(); + + explicit PusTmCreator(TimeStamperIF* timeStamper); + PusTmCreator(SpacePacketParams initSpParams, PusTmParams initPusParams, + TimeStamperIF* timeStamper); + ~PusTmCreator() override = default; + + void setTimeStamper(TimeStamperIF* timeStamper); + SpacePacketParams& getSpParams(); + void setApid(uint16_t apid); + PusTmParams& getParams(); + void updateSpLengthField(); [[nodiscard]] uint16_t getPacketIdRaw() const override; [[nodiscard]] uint16_t getPacketSeqCtrlRaw() 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; + 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; + TimeStamperIF* getTimestamper() override; private: - PusTmParams& params; + ecss::DataWrapper& getDataWrapper() override; + + private: + PusTmParams pusParams{}; + SpacePacketCreator spCreator; }; #endif // FSFW_TMTCPACKET_TMPACKETCREATOR_H diff --git a/src/fsfw/tmtcpacket/pus/tm/PusTmIF.h b/src/fsfw/tmtcpacket/pus/tm/PusTmIF.h index b22bdf3d..94d41467 100644 --- a/src/fsfw/tmtcpacket/pus/tm/PusTmIF.h +++ b/src/fsfw/tmtcpacket/pus/tm/PusTmIF.h @@ -4,17 +4,27 @@ #include #include +#include "fsfw/timemanager/TimeStamperIF.h" #include "fsfw/tmtcpacket/pus/PusIF.h" +#include "fsfw/tmtcpacket/pus/definitions.h" class PusTmIF : public PusIF { public: ~PusTmIF() override = default; + /** + * Minimum length without timestamp + */ + static constexpr size_t MIN_SEC_HEADER_LEN = 7; + /** + * 2 bytes for CRC16 + */ + static constexpr size_t MIN_TM_SIZE = sizeof(ccsds::PrimaryHeader) + MIN_SEC_HEADER_LEN + 2; + 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; + virtual TimeStamperIF* getTimestamper() = 0; }; #endif // FSFW_TMTCPACKET_PUSTMIF_H diff --git a/src/fsfw/tmtcpacket/pus/tm/PusTmMinimal.cpp b/src/fsfw/tmtcpacket/pus/tm/PusTmMinimal.cpp index f2cc7fcc..f36cfc2a 100644 --- a/src/fsfw/tmtcpacket/pus/tm/PusTmMinimal.cpp +++ b/src/fsfw/tmtcpacket/pus/tm/PusTmMinimal.cpp @@ -34,15 +34,16 @@ 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.messageTypeH << 8) | tmData->secHeader.messageTypeL; } 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 */ } +const uint8_t* PusTmMinimal::getUserData(size_t& userDataLen_) { + userDataLen_ = userDataLen; + return reinterpret_cast(&tmData->rest); +} +TimeStamperIF* PusTmMinimal::getTimestamper() { return nullptr; } diff --git a/src/fsfw/tmtcpacket/pus/tm/PusTmMinimal.h b/src/fsfw/tmtcpacket/pus/tm/PusTmMinimal.h index b9146def..06ed4aff 100644 --- a/src/fsfw/tmtcpacket/pus/tm/PusTmMinimal.h +++ b/src/fsfw/tmtcpacket/pus/tm/PusTmMinimal.h @@ -4,6 +4,7 @@ #include "PusTmIF.h" #include "fsfw/returnvalues/HasReturnvaluesIF.h" #include "fsfw/tmtcpacket/ccsds/SpacePacketReader.h" +#include "fsfw/tmtcpacket/pus/RawUserDataReaderIF.h" struct timeval; @@ -12,7 +13,7 @@ class PacketTimestampInterpreterIF; namespace mintm { // NOTE: Only PUS C compatible! -struct PusTmMinimalSecHeader { +struct PusTmMinimalSecHeaderPacked { uint8_t versionAndScTimeRefStatus; uint8_t service; uint8_t subservice; @@ -27,7 +28,7 @@ struct PusTmMinimalSecHeader { */ struct MinimalPusTm { ccsds::PrimaryHeader primary; - PusTmMinimalSecHeader secHeader; + PusTmMinimalSecHeaderPacked secHeader; uint8_t rest; }; @@ -42,7 +43,7 @@ static const uint16_t MINIMUM_SIZE = sizeof(MinimalPusTm) + 1; * This is required for handling TM packets with different APIDs with different * secondary headers. */ -class PusTmMinimal : public PusTmIF, public RedirectableDataPointerIF { +class PusTmMinimal : public PusTmIF, public RawUserDataReaderIF, public RedirectableDataPointerIF { public: explicit PusTmMinimal(mintm::MinimalPusTm* data); /** @@ -69,13 +70,11 @@ class PusTmMinimal : public PusTmIF, public RedirectableDataPointerIF { [[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; + const uint8_t* getUserData(size_t& userDataLen) override; + TimeStamperIF* getTimestamper() override; protected: /** @@ -84,6 +83,7 @@ class PusTmMinimal : public PusTmIF, public RedirectableDataPointerIF { * * To be hardware-safe, all elements are of byte size. */ + size_t userDataLen = 0; mintm::MinimalPusTm* tmData; static PacketTimestampInterpreterIF* timestampInterpreter; diff --git a/src/fsfw/tmtcpacket/pus/tm/TmPacketPusC.h b/src/fsfw/tmtcpacket/pus/tm/TmPacketPusC.h index 7d1eb255..c68deadd 100644 --- a/src/fsfw/tmtcpacket/pus/tm/TmPacketPusC.h +++ b/src/fsfw/tmtcpacket/pus/tm/TmPacketPusC.h @@ -26,7 +26,7 @@ struct PUSTmDataFieldHeaderPusC { uint8_t subcounterLsb; uint8_t destinationIdMsb; uint8_t destinationIdLsb; - uint8_t time[TimeStamperIF::MISSION_TIMESTAMP_SIZE]; + // uint8_t time[TimeStamperIF::MISSION_TIMESTAMP_SIZE]; }; /** diff --git a/src/fsfw/tmtcservices/CMakeLists.txt b/src/fsfw/tmtcservices/CMakeLists.txt index fcbcb49d..a26faf7f 100644 --- a/src/fsfw/tmtcservices/CMakeLists.txt +++ b/src/fsfw/tmtcservices/CMakeLists.txt @@ -7,4 +7,5 @@ target_sources( TmTcMessage.cpp VerificationReporter.cpp SpacePacketParser.cpp - TmStoreHelper.cpp) + TmStoreHelper.cpp + TmSendHelper.cpp) diff --git a/src/fsfw/tmtcservices/CommandingServiceBase.cpp b/src/fsfw/tmtcservices/CommandingServiceBase.cpp index 37232c49..8aa5dbce 100644 --- a/src/fsfw/tmtcservices/CommandingServiceBase.cpp +++ b/src/fsfw/tmtcservices/CommandingServiceBase.cpp @@ -8,6 +8,7 @@ #include "fsfw/tmtcpacket/pus/tm.h" #include "fsfw/tmtcservices/AcceptsTelemetryIF.h" #include "fsfw/tmtcservices/TmTcMessage.h" +#include "fsfw/tmtcservices/sendAndStoreHelper.h" object_id_t CommandingServiceBase::defaultPacketSource = objects::NO_OBJECT; object_id_t CommandingServiceBase::defaultPacketDestination = objects::NO_OBJECT; @@ -19,17 +20,19 @@ CommandingServiceBase::CommandingServiceBase(object_id_t setObjectId, uint16_t a apid(apid), service(service), timeoutSeconds(commandTimeoutSeconds), + tmStoreHelper(apid, nullptr), + tmSendHelper(nullptr), commandMap(numberOfParallelCommands) { commandQueue = QueueFactory::instance()->createMessageQueue(queueDepth); requestQueue = QueueFactory::instance()->createMessageQueue(queueDepth); } -void CommandingServiceBase::setPacketSource(object_id_t packetSource) { - this->packetSource = packetSource; +void CommandingServiceBase::setPacketSource(object_id_t packetSource_) { + packetSource = packetSource_; } -void CommandingServiceBase::setPacketDestination(object_id_t packetDestination) { - this->packetDestination = packetDestination; +void CommandingServiceBase::setPacketDestination(object_id_t packetDestination_) { + packetDestination = packetDestination_; } CommandingServiceBase::~CommandingServiceBase() { @@ -58,13 +61,12 @@ ReturnValue_t CommandingServiceBase::initialize() { if (packetDestination == objects::NO_OBJECT) { packetDestination = defaultPacketDestination; } - AcceptsTelemetryIF* packetForwarding = - ObjectManager::instance()->get(packetDestination); + auto* packetForwarding = ObjectManager::instance()->get(packetDestination); if (packetSource == objects::NO_OBJECT) { packetSource = defaultPacketSource; } - PUSDistributorIF* distributor = ObjectManager::instance()->get(packetSource); + auto* distributor = ObjectManager::instance()->get(packetSource); if (packetForwarding == nullptr or distributor == nullptr) { #if FSFW_CPP_OSTREAM_ENABLED == 1 @@ -78,10 +80,10 @@ ReturnValue_t CommandingServiceBase::initialize() { distributor->registerService(this); requestQueue->setDefaultDestination(packetForwarding->getReportReceptionQueue()); - IPCStore = ObjectManager::instance()->get(objects::IPC_STORE); - TCStore = ObjectManager::instance()->get(objects::TC_STORE); + ipcStore = ObjectManager::instance()->get(objects::IPC_STORE); + tcStore = ObjectManager::instance()->get(objects::TC_STORE); - if (IPCStore == nullptr or TCStore == nullptr) { + if (ipcStore == nullptr or tcStore == nullptr) { #if FSFW_CPP_OSTREAM_ENABLED == 1 sif::error << "CommandingServiceBase::intialize: IPC store or TC store " "not initialized yet!" @@ -89,7 +91,20 @@ ReturnValue_t CommandingServiceBase::initialize() { #endif return ObjectManagerIF::CHILD_INIT_FAILED; } - + if (tmStoreHelper.getTmStore() == nullptr) { + auto* tmStore = ObjectManager::instance()->get(objects::TM_STORE); + if (tmStore == nullptr) { + return ObjectManagerIF::CHILD_INIT_FAILED; + } + tmStoreHelper.setTmStore(tmStore); + } + if (errReporter == nullptr) { + errReporter = + ObjectManager::instance()->get(objects::INTERNAL_ERROR_REPORTER); + if (errReporter != nullptr) { + tmSendHelper.setInternalErrorReporter(errReporter); + } + } return RETURN_OK; } @@ -226,23 +241,31 @@ void CommandingServiceBase::handleRequestQueue() { TmTcMessage message; ReturnValue_t result; store_address_t address; - TcPacketStoredPus packet; MessageQueueId_t queue; object_id_t objectId; for (result = requestQueue->receiveMessage(&message); result == RETURN_OK; result = requestQueue->receiveMessage(&message)) { address = message.getStorageId(); - packet.setStoreAddress(address, &packet); + const uint8_t* dataPtr; + size_t dataLen = 0; + result = tcStore->getData(message.getStorageId(), &dataPtr, &dataLen); + if (result != HasReturnvaluesIF::RETURN_OK) { + // TODO: Warning? + } + tcReader.setReadOnlyData(dataPtr, dataLen); - if ((packet.getSubService() == 0) or (isValidSubservice(packet.getSubService()) != RETURN_OK)) { - rejectPacket(tc_verification::START_FAILURE, &packet, INVALID_SUBSERVICE); + if ((tcReader.getSubService() == 0) or + (isValidSubservice(tcReader.getSubService()) != RETURN_OK)) { + rejectPacket(tc_verification::START_FAILURE, address, &tcReader, INVALID_SUBSERVICE); continue; } - result = getMessageQueueAndObject(packet.getSubService(), packet.getApplicationData(), - packet.getApplicationDataSize(), &queue, &objectId); + size_t appDataLen = 0; + const uint8_t* appData = tcReader.getUserData(appDataLen); + result = + getMessageQueueAndObject(tcReader.getSubService(), appData, appDataLen, &queue, &objectId); if (result != HasReturnvaluesIF::RETURN_OK) { - rejectPacket(tc_verification::START_FAILURE, &packet, result); + rejectPacket(tc_verification::START_FAILURE, address, &tcReader, result); continue; } @@ -253,33 +276,26 @@ void CommandingServiceBase::handleRequestQueue() { if (iter != commandMap.end()) { result = iter->second.fifo.insert(address); if (result != RETURN_OK) { - rejectPacket(tc_verification::START_FAILURE, &packet, OBJECT_BUSY); + rejectPacket(tc_verification::START_FAILURE, address, &tcReader, OBJECT_BUSY); } } else { CommandInfo newInfo; // Info will be set by startExecution if neccessary newInfo.objectId = objectId; result = commandMap.insert(queue, newInfo, &iter); if (result != RETURN_OK) { - rejectPacket(tc_verification::START_FAILURE, &packet, BUSY); + rejectPacket(tc_verification::START_FAILURE, address, &tcReader, BUSY); } else { - startExecution(&packet, iter); + startExecution(address, &tcReader, iter); } } } } -ReturnValue_t CommandingServiceBase::sendTmPacket(uint8_t subservice, const uint8_t* data, - size_t dataLen, const uint8_t* headerData, - size_t headerSize) { -#if FSFW_USE_PUS_C_TELEMETRY == 0 - TmPacketStoredPusA tmPacketStored(this->apid, this->service, subservice, this->tmPacketCounter, - data, dataLen, headerData, headerSize); -#else - TmPacketStoredPusC tmPacketStored(this->apid, this->service, subservice, this->tmPacketCounter, - data, dataLen, headerData, headerSize); -#endif - ReturnValue_t result = - tmPacketStored.sendPacket(requestQueue->getDefaultDestination(), requestQueue->getId()); +ReturnValue_t CommandingServiceBase::sendTmPacket(uint8_t subservice, const uint8_t* sourceData, + size_t sourceDataLen) { + tmStoreHelper.preparePacket(service, subservice, tmPacketCounter); + tmStoreHelper.setSourceDataRaw(sourceData, sourceDataLen); + ReturnValue_t result = tm::storeAndSendTmPacket(tmStoreHelper, tmSendHelper); if (result == HasReturnvaluesIF::RETURN_OK) { this->tmPacketCounter++; } @@ -288,54 +304,38 @@ ReturnValue_t CommandingServiceBase::sendTmPacket(uint8_t subservice, const uint ReturnValue_t CommandingServiceBase::sendTmPacket(uint8_t subservice, object_id_t objectId, const uint8_t* data, size_t dataLen) { - uint8_t buffer[sizeof(object_id_t)]; - uint8_t* pBuffer = buffer; - size_t size = 0; - SerializeAdapter::serialize(&objectId, &pBuffer, &size, sizeof(object_id_t), - SerializeIF::Endianness::BIG); -#if FSFW_USE_PUS_C_TELEMETRY == 0 - TmPacketStoredPusA tmPacketStored(this->apid, this->service, subservice, this->tmPacketCounter, - data, dataLen, buffer, size); -#else - TmPacketStoredPusC tmPacketStored(this->apid, this->service, subservice, this->tmPacketCounter, - data, dataLen, buffer, size); -#endif - ReturnValue_t result = - tmPacketStored.sendPacket(requestQueue->getDefaultDestination(), requestQueue->getId()); + tm::SourceDataWithObjectIdPrefix dataWithObjId(objectId, data, dataLen); + tmStoreHelper.preparePacket(service, subservice, tmPacketCounter); + tmStoreHelper.setSourceDataSerializable(&dataWithObjId); + ReturnValue_t result = tm::storeAndSendTmPacket(tmStoreHelper, tmSendHelper); if (result == HasReturnvaluesIF::RETURN_OK) { this->tmPacketCounter++; } return result; } -ReturnValue_t CommandingServiceBase::sendTmPacket(uint8_t subservice, SerializeIF* content, - SerializeIF* header) { -#if FSFW_USE_PUS_C_TELEMETRY == 0 - TmPacketStoredPusA tmPacketStored(this->apid, this->service, subservice, this->tmPacketCounter, - content, header); -#else - TmPacketStoredPusC tmPacketStored(this->apid, this->service, subservice, this->tmPacketCounter, - content, header); -#endif - ReturnValue_t result = - tmPacketStored.sendPacket(requestQueue->getDefaultDestination(), requestQueue->getId()); +ReturnValue_t CommandingServiceBase::sendTmPacket(uint8_t subservice, SerializeIF* sourceData) { + tmStoreHelper.preparePacket(service, subservice, tmPacketCounter); + tmStoreHelper.setSourceDataSerializable(sourceData); + ReturnValue_t result = tm::storeAndSendTmPacket(tmStoreHelper, tmSendHelper); if (result == HasReturnvaluesIF::RETURN_OK) { this->tmPacketCounter++; } return result; } -void CommandingServiceBase::startExecution(TcPacketStoredPus* storedPacket, CommandMapIter iter) { +void CommandingServiceBase::startExecution(store_address_t storeId, PusTcReader* storedPacket, + CommandMapIter iter) { ReturnValue_t result = RETURN_OK; CommandMessage command; - // TcPacketPusBase* tcPacketBase = storedPacket->getPacketBase(); if (storedPacket == nullptr) { return; } iter->second.subservice = storedPacket->getSubService(); - result = prepareCommand(&command, iter->second.subservice, storedPacket->getApplicationData(), - storedPacket->getApplicationDataSize(), &iter->second.state, - iter->second.objectId); + size_t appDataLen = 0; + const uint8_t* appData = storedPacket->getUserData(appDataLen); + result = prepareCommand(&command, iter->second.subservice, appData, appDataLen, + &iter->second.state, iter->second.objectId); ReturnValue_t sendResult = RETURN_OK; switch (result) { @@ -349,12 +349,12 @@ void CommandingServiceBase::startExecution(TcPacketStoredPus* storedPacket, Comm iter->second.subservice = storedPacket->getSubService(); iter->second.command = command.getCommand(); iter->second.tcInfo.ackFlags = storedPacket->getAcknowledgeFlags(); - iter->second.tcInfo.tcPacketId = storedPacket->getPacketId(); - iter->second.tcInfo.tcSequenceControl = storedPacket->getPacketSeqCtrl(); - acceptPacket(tc_verification::START_SUCCESS, storedPacket); + iter->second.tcInfo.tcPacketId = storedPacket->getPacketIdRaw(); + iter->second.tcInfo.tcSequenceControl = storedPacket->getPacketSeqCtrlRaw(); + acceptPacket(tc_verification::START_SUCCESS, storeId, storedPacket); } else { command.clearCommandMessage(); - rejectPacket(tc_verification::START_FAILURE, storedPacket, sendResult); + rejectPacket(tc_verification::START_FAILURE, storeId, storedPacket, sendResult); checkAndExecuteFifo(iter); } break; @@ -364,33 +364,32 @@ void CommandingServiceBase::startExecution(TcPacketStoredPus* storedPacket, Comm sendResult = commandQueue->sendMessage(iter.value->first, &command); } if (sendResult == RETURN_OK) { - verificationReporter.sendSuccessReport(tc_verification::START_SUCCESS, - storedPacket->getPacketBase()); - acceptPacket(tc_verification::COMPLETION_SUCCESS, storedPacket); + verificationReporter.sendSuccessReport(tc_verification::START_SUCCESS, storedPacket); + acceptPacket(tc_verification::COMPLETION_SUCCESS, storeId, storedPacket); checkAndExecuteFifo(iter); } else { command.clearCommandMessage(); - rejectPacket(tc_verification::START_FAILURE, storedPacket, sendResult); + rejectPacket(tc_verification::START_FAILURE, storeId, storedPacket, sendResult); checkAndExecuteFifo(iter); } break; default: - rejectPacket(tc_verification::START_FAILURE, storedPacket, result); + rejectPacket(tc_verification::START_FAILURE, storeId, storedPacket, result); checkAndExecuteFifo(iter); break; } } -void CommandingServiceBase::rejectPacket(uint8_t reportId, TcPacketStoredPus* packet, - ReturnValue_t errorCode) { - verificationReporter.sendFailureReport(reportId, dynamic_cast(packet), - errorCode); - packet->deletePacket(); +void CommandingServiceBase::rejectPacket(uint8_t reportId, store_address_t tcStoreId, + PusTcReader* correspondingTc, ReturnValue_t errorCode) { + verificationReporter.sendFailureReport(reportId, correspondingTc, errorCode); + tcStore->deleteData(tcStoreId); } -void CommandingServiceBase::acceptPacket(uint8_t reportId, TcPacketStoredPus* packet) { - verificationReporter.sendSuccessReport(reportId, dynamic_cast(packet)); - packet->deletePacket(); +void CommandingServiceBase::acceptPacket(uint8_t reportId, store_address_t tcStoreId, + PusTcReader* packet) { + verificationReporter.sendSuccessReport(reportId, packet); + tcStore->deleteData(tcStoreId); } void CommandingServiceBase::checkAndExecuteFifo(CommandMapIter& iter) { @@ -398,8 +397,15 @@ void CommandingServiceBase::checkAndExecuteFifo(CommandMapIter& iter) { if (iter->second.fifo.retrieve(&address) != RETURN_OK) { commandMap.erase(&iter); } else { - TcPacketStoredPus newPacket(address); - startExecution(&newPacket, iter); + const uint8_t* dataPtr; + size_t dataLen = 0; + ReturnValue_t result = tcStore->getData(address, &dataPtr, &dataLen); + if (result == HasReturnvaluesIF::RETURN_OK) { + tcReader.setReadOnlyData(dataPtr, dataLen); + startExecution(address, &tcReader, iter); + } else { + // TODO: Warning? + } } } @@ -426,3 +432,7 @@ void CommandingServiceBase::checkTimeout() { } void CommandingServiceBase::setTaskIF(PeriodicTaskIF* task_) { executingTask = task_; } + +void CommandingServiceBase::setCustomTmStore(StorageManagerIF* store) { + tmStoreHelper.setTmStore(store); +} diff --git a/src/fsfw/tmtcservices/CommandingServiceBase.h b/src/fsfw/tmtcservices/CommandingServiceBase.h index 4dcad024..a392fb95 100644 --- a/src/fsfw/tmtcservices/CommandingServiceBase.h +++ b/src/fsfw/tmtcservices/CommandingServiceBase.h @@ -2,6 +2,8 @@ #define FSFW_TMTCSERVICES_COMMANDINGSERVICEBASE_H_ #include "AcceptsTelecommandsIF.h" +#include "TmSendHelper.h" +#include "TmStoreHelper.h" #include "VerificationReporter.h" #include "fsfw/FSFW.h" #include "fsfw/container/FIFO.h" @@ -69,8 +71,9 @@ class CommandingServiceBase : public SystemObject, CommandingServiceBase(object_id_t setObjectId, uint16_t apid, uint8_t service, uint8_t numberOfParallelCommands, uint16_t commandTimeoutSeconds, size_t queueDepth = 20); - virtual ~CommandingServiceBase(); + ~CommandingServiceBase() override; + void setCustomTmStore(StorageManagerIF* store); /** * This setter can be used to set the packet source individually instead * of using the default static framework ID set in the factory. @@ -93,9 +96,9 @@ class CommandingServiceBase : public SystemObject, * @param opCode is unused here at the moment * @return RETURN_OK */ - virtual ReturnValue_t performOperation(uint8_t opCode) override; + ReturnValue_t performOperation(uint8_t opCode) override; - virtual uint16_t getIdentifier() override; + uint16_t getIdentifier() override; /** * Returns the requestQueue MessageQueueId_t @@ -104,7 +107,7 @@ class CommandingServiceBase : public SystemObject, * * @return requestQueue messageQueueId_t */ - virtual MessageQueueId_t getRequestQueue() override; + MessageQueueId_t getRequestQueue() override; /** * Returns the commandQueue MessageQueueId_t @@ -114,7 +117,7 @@ class CommandingServiceBase : public SystemObject, */ virtual MessageQueueId_t getCommandQueue(); - virtual ReturnValue_t initialize() override; + ReturnValue_t initialize() override; /** * Implementation of ExecutableObjectIF function @@ -122,7 +125,7 @@ class CommandingServiceBase : public SystemObject, * Used to setup the reference of the task, that executes this component * @param task Pointer to the taskIF of this task */ - virtual void setTaskIF(PeriodicTaskIF* task) override; + void setTaskIF(PeriodicTaskIF* task) override; protected: /** @@ -230,15 +233,15 @@ class CommandingServiceBase : public SystemObject, object_id_t objectId; FIFO fifo; - virtual ReturnValue_t serialize(uint8_t** buffer, size_t* size, size_t maxSize, - Endianness streamEndianness) const override { + ReturnValue_t serialize(uint8_t** buffer, size_t* size, size_t maxSize, + Endianness streamEndianness) const override { return HasReturnvaluesIF::RETURN_FAILED; }; - virtual size_t getSerializedSize() const override { return 0; }; + [[nodiscard]] size_t getSerializedSize() const override { return 0; }; - virtual ReturnValue_t deSerialize(const uint8_t** buffer, size_t* size, - Endianness streamEndianness) override { + ReturnValue_t deSerialize(const uint8_t** buffer, size_t* size, + Endianness streamEndianness) override { return HasReturnvaluesIF::RETURN_FAILED; }; }; @@ -253,9 +256,13 @@ class CommandingServiceBase : public SystemObject, uint8_t tmPacketCounter = 0; - StorageManagerIF* IPCStore = nullptr; + StorageManagerIF* ipcStore = nullptr; - StorageManagerIF* TCStore = nullptr; + PusTcReader tcReader; + TmStoreHelper tmStoreHelper; + TmSendHelper tmSendHelper; + + StorageManagerIF* tcStore = nullptr; MessageQueueIF* commandQueue = nullptr; @@ -263,6 +270,8 @@ class CommandingServiceBase : public SystemObject, VerificationReporter verificationReporter; + InternalErrorReporterIF* errReporter = nullptr; + FixedMap commandMap; /* May be set be children to return a more precise failure condition. */ @@ -284,13 +293,10 @@ class CommandingServiceBase : public SystemObject, * @brief Send TM data from pointer to data. * If a header is supplied it is added before data * @param subservice Number of subservice - * @param data Pointer to the data in the Packet - * @param dataLen Lenght of data in the Packet - * @param headerData HeaderData will be placed before data - * @param headerSize Size of HeaderData + * @param sourceData Custom source data + * @param sourceDataLen Lenght of data in the Packet */ - ReturnValue_t sendTmPacket(uint8_t subservice, const uint8_t* data, size_t dataLen, - const uint8_t* headerData = nullptr, size_t headerSize = 0); + ReturnValue_t sendTmPacket(uint8_t subservice, const uint8_t* sourceData, size_t sourceDataLen); /** * @brief To send TM packets of objects that still need to be serialized @@ -310,8 +316,7 @@ class CommandingServiceBase : public SystemObject, * @param content This is a pointer to the serialized packet * @param header Serialize IF header which will be placed before content */ - ReturnValue_t sendTmPacket(uint8_t subservice, SerializeIF* content, - SerializeIF* header = nullptr); + ReturnValue_t sendTmPacket(uint8_t subservice, SerializeIF* sourceData); void checkAndExecuteFifo(CommandMapIter& iter); @@ -345,11 +350,12 @@ class CommandingServiceBase : public SystemObject, */ void handleRequestQueue(); - void rejectPacket(uint8_t reportId, TcPacketStoredPus* packet, ReturnValue_t errorCode); + void rejectPacket(uint8_t reportId, store_address_t tcStoreId, PusTcReader* tcPacket, + ReturnValue_t errorCode); - void acceptPacket(uint8_t reportId, TcPacketStoredPus* packet); + void acceptPacket(uint8_t reportId, store_address_t tcStoreId, PusTcReader* tcPacket); - void startExecution(TcPacketStoredPus* storedPacket, CommandMapIter iter); + void startExecution(store_address_t storeId, PusTcReader* storedPacket, CommandMapIter iter); void handleCommandMessage(CommandMessage* reply); void handleReplyHandlerResult(ReturnValue_t result, CommandMapIter iter, diff --git a/src/fsfw/tmtcservices/PusServiceBase.cpp b/src/fsfw/tmtcservices/PusServiceBase.cpp index b18a736b..e924ba67 100644 --- a/src/fsfw/tmtcservices/PusServiceBase.cpp +++ b/src/fsfw/tmtcservices/PusServiceBase.cpp @@ -11,9 +11,8 @@ object_id_t PusServiceBase::packetSource = 0; object_id_t PusServiceBase::packetDestination = 0; -PusServiceBase::PusServiceBase(object_id_t setObjectId, uint16_t setApid, uint8_t setServiceId, - StorageManagerIF* ipcStore_) - : SystemObject(setObjectId), apid(setApid), serviceId(setServiceId), ipcStore(ipcStore_) { +PusServiceBase::PusServiceBase(object_id_t setObjectId, uint16_t setApid, uint8_t setServiceId) + : SystemObject(setObjectId), apid(setApid), serviceId(setServiceId) { requestQueue = QueueFactory::instance()->createMessageQueue(PUS_SERVICE_MAX_RECEPTION); } @@ -36,7 +35,7 @@ void PusServiceBase::setTaskIF(PeriodicTaskIF* taskHandle_) { this->taskHandle = void PusServiceBase::handleRequestQueue() { TmTcMessage message; - ReturnValue_t result = RETURN_FAILED; + ReturnValue_t result; for (uint8_t count = 0; count < PUS_SERVICE_MAX_RECEPTION; count++) { ReturnValue_t status = this->requestQueue->receiveMessage(&message); // if(status != MessageQueueIF::EMPTY) { @@ -57,14 +56,9 @@ void PusServiceBase::handleRequestQueue() { // TODO: Warning? } - currentPacket.setData(dataPtr, dataLen); - // info << "Service " << (uint16_t) this->serviceId << - // ": new packet!" << std::endl; + currentPacket.setReadOnlyData(dataPtr, dataLen); result = this->handleRequest(currentPacket.getSubService()); - - // debug << "Service " << (uint16_t)this->serviceId << - // ": handleRequest returned: " << (int)return_code << std::endl; if (result == RETURN_OK) { this->verifyReporter.sendSuccessReport(tc_verification::COMPLETION_SUCCESS, &this->currentPacket); @@ -78,8 +72,6 @@ void PusServiceBase::handleRequestQueue() { errorParameter2 = 0; } else if (status == MessageQueueIF::EMPTY) { status = RETURN_OK; - // debug << "PusService " << (uint16_t)this->serviceId << - // ": no new packet." << std::endl; break; } else { #if FSFW_CPP_OSTREAM_ENABLED == 1 @@ -127,3 +119,30 @@ ReturnValue_t PusServiceBase::initializeAfterTaskCreation() { // be used to get those parameters. return HasReturnvaluesIF::RETURN_OK; } + +void PusServiceBase::setCustomIpcStore(StorageManagerIF* ipcStore_) { ipcStore = ipcStore_; } + +void PusServiceBase::setCustomErrorReporter(InternalErrorReporterIF* errReporter_) { + errReporter = errReporter_; +} + +void PusServiceBase::initializeTmHelpers(TmSendHelper& tmSendHelper, TmStoreHelper& tmStoreHelper) { + initializeTmSendHelper(tmSendHelper); + initializeTmStoreHelper(tmStoreHelper); +} + +void PusServiceBase::initializeTmSendHelper(TmSendHelper& tmSendHelper) { + tmSendHelper.setMsgSource(requestQueue->getId()); + tmSendHelper.setMsgDestination(requestQueue->getDefaultDestination()); + if (errReporter == nullptr) { + errReporter = + ObjectManager::instance()->get(objects::INTERNAL_ERROR_REPORTER); + if (errReporter != nullptr) { + tmSendHelper.setInternalErrorReporter(errReporter); + } + } +} + +void PusServiceBase::initializeTmStoreHelper(TmStoreHelper& tmStoreHelper) const { + tmStoreHelper.setApid(apid); +} diff --git a/src/fsfw/tmtcservices/PusServiceBase.h b/src/fsfw/tmtcservices/PusServiceBase.h index d487c6c6..58f83540 100644 --- a/src/fsfw/tmtcservices/PusServiceBase.h +++ b/src/fsfw/tmtcservices/PusServiceBase.h @@ -2,6 +2,8 @@ #define FSFW_TMTCSERVICES_PUSSERVICEBASE_H_ #include "AcceptsTelecommandsIF.h" +#include "TmSendHelper.h" +#include "TmStoreHelper.h" #include "VerificationCodes.h" #include "VerificationReporter.h" #include "fsfw/ipc/MessageQueueIF.h" @@ -51,12 +53,18 @@ 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, - StorageManagerIF* ipcStore); + PusServiceBase(object_id_t setObjectId, uint16_t setApid, uint8_t setServiceId); /** * The destructor is empty. */ ~PusServiceBase() override; + + void setCustomIpcStore(StorageManagerIF* ipcStore); + void setCustomErrorReporter(InternalErrorReporterIF* errReporter); + + void initializeTmSendHelper(TmSendHelper& tmSendHelper); + void initializeTmStoreHelper(TmStoreHelper& tmStoreHelper) const; + void initializeTmHelpers(TmSendHelper& tmSendHelper, TmStoreHelper& tmStoreHelper); /** * @brief The handleRequest method shall handle any kind of Telecommand * Request immediately. @@ -139,13 +147,14 @@ class PusServiceBase : public ExecutableObjectIF, * sending any kind of verification message to the TC Verification Service. */ VerificationReporter verifyReporter; + /** * The current Telecommand to be processed. * It is deleted after handleRequest was executed. */ - // TcPacketStoredPus currentPacket; - StorageManagerIF* ipcStore; PusTcReader currentPacket; + StorageManagerIF* ipcStore = nullptr; + InternalErrorReporterIF* errReporter = nullptr; static object_id_t packetSource; diff --git a/src/fsfw/tmtcservices/TmSendHelper.cpp b/src/fsfw/tmtcservices/TmSendHelper.cpp new file mode 100644 index 00000000..76591ca2 --- /dev/null +++ b/src/fsfw/tmtcservices/TmSendHelper.cpp @@ -0,0 +1,29 @@ +#include "TmSendHelper.h" + +#include "fsfw/ipc/MessageQueueSenderIF.h" + +TmSendHelper::TmSendHelper(MessageQueueId_t tmtcMsgDest, MessageQueueId_t tmtcMsgSrc, + InternalErrorReporterIF *reporter) + : tmtcMsgDest(tmtcMsgDest), tmtcMsgSrc(tmtcMsgSrc), errReporter(reporter) {} + +TmSendHelper::TmSendHelper(InternalErrorReporterIF *reporter) : errReporter(reporter) {} + +ReturnValue_t TmSendHelper::sendPacket(const store_address_t &storeId) { + TmTcMessage message(storeId); + ReturnValue_t result = MessageQueueSenderIF::sendMessage(tmtcMsgDest, &message, tmtcMsgSrc); + if (result != HasReturnvaluesIF::RETURN_OK) { + if (errReporter != nullptr) { + errReporter->lostTm(); + } + return result; + } + return HasReturnvaluesIF::RETURN_OK; +} + +void TmSendHelper::setMsgDestination(MessageQueueId_t msgDest) { tmtcMsgDest = msgDest; } + +void TmSendHelper::setMsgSource(MessageQueueId_t msgSrc) { tmtcMsgSrc = msgSrc; } + +void TmSendHelper::setInternalErrorReporter(InternalErrorReporterIF *reporter) { + errReporter = reporter; +} diff --git a/src/fsfw/tmtcservices/TmSendHelper.h b/src/fsfw/tmtcservices/TmSendHelper.h new file mode 100644 index 00000000..f7acb237 --- /dev/null +++ b/src/fsfw/tmtcservices/TmSendHelper.h @@ -0,0 +1,26 @@ +#ifndef FSFW_TMTCPACKET_TMSENDHELPER_H +#define FSFW_TMTCPACKET_TMSENDHELPER_H + +#include "TmTcMessage.h" +#include "fsfw/internalerror/InternalErrorReporterIF.h" +#include "fsfw/ipc/MessageQueueIF.h" +#include "fsfw/ipc/messageQueueDefinitions.h" +#include "fsfw/returnvalues/HasReturnvaluesIF.h" + +class TmSendHelper { + public: + explicit TmSendHelper(InternalErrorReporterIF* reporter); + TmSendHelper(MessageQueueId_t tmtcMsgDest, MessageQueueId_t tmtcMsgSrc, + InternalErrorReporterIF* reporter); + void setMsgDestination(MessageQueueId_t msgDest); + void setMsgSource(MessageQueueId_t msgSrc); + void setInternalErrorReporter(InternalErrorReporterIF* reporter); + ReturnValue_t sendPacket(const store_address_t& storeId); + + private: + MessageQueueId_t tmtcMsgDest = MessageQueueIF::NO_QUEUE; + MessageQueueId_t tmtcMsgSrc = MessageQueueIF::NO_QUEUE; + InternalErrorReporterIF* errReporter; +}; + +#endif // FSFW_TMTCPACKET_TMSENDHELPER_H diff --git a/src/fsfw/tmtcservices/TmStoreHelper.cpp b/src/fsfw/tmtcservices/TmStoreHelper.cpp index 54e6ffc8..661ee3a0 100644 --- a/src/fsfw/tmtcservices/TmStoreHelper.cpp +++ b/src/fsfw/tmtcservices/TmStoreHelper.cpp @@ -1,43 +1,58 @@ #include "TmStoreHelper.h" #include "TmTcMessage.h" -#include "fsfw/ipc/MessageQueueSenderIF.h" -TmStoreHelper::TmStoreHelper(StorageManagerIF *tmStore, MessageQueueId_t tmtcMsgDest, - MessageQueueId_t tmtcMsgSrc, InternalErrorReporterIF *reporter) - : creator(params), - tmtcMsgDest(tmtcMsgDest), - tmtcMsgSrc(tmtcMsgSrc), - errReporter(reporter), - tmStore(tmStore) {} - -void TmStoreHelper::preparePacket(uint16_t apid, uint8_t service, uint8_t subservice, - uint16_t counter) { - // TODO: Implement - // creator.setApid(apid); - params.service = service; - params.subservice = subservice; - params.messageTypeCounter = counter; - // TODO: Implement serialize and then serialize into the store +TmStoreHelper::TmStoreHelper(uint16_t defaultApid, StorageManagerIF* tmStore, + TimeStamperIF* timeStamper) + : creator(timeStamper), tmStore(tmStore) { + creator.setApid(defaultApid); } -ReturnValue_t TmStoreHelper::sendPacket() { - TmTcMessage tmMessage(currentAddr); - ReturnValue_t result = MessageQueueSenderIF::sendMessage(tmtcMsgDest, &tmMessage, tmtcMsgSrc); - if (result != HasReturnvaluesIF::RETURN_OK) { - tmStore->deleteData(currentAddr); - if (errReporter != nullptr) { - errReporter->lostTm(); - } - return result; - } +TmStoreHelper::TmStoreHelper(uint16_t defaultApid, StorageManagerIF* tmStore) + : creator(nullptr), tmStore(tmStore) { + creator.setApid(defaultApid); +} + +ReturnValue_t TmStoreHelper::preparePacket(uint8_t service, uint8_t subservice, uint16_t counter) { + // TODO: Implement + // creator.setApid(apid); + PusTmParams& params = creator.getParams(); + params.secHeader.service = service; + params.secHeader.subservice = subservice; + params.secHeader.messageTypeCounter = counter; + // TODO: Implement serialize and then serialize into the store return HasReturnvaluesIF::RETURN_OK; } -void TmStoreHelper::setMsgDestination(MessageQueueId_t msgDest) { tmtcMsgDest = msgDest; } +StorageManagerIF* TmStoreHelper::getTmStore() { return tmStore; } -void TmStoreHelper::setMsgSource(MessageQueueId_t msgSrc) { tmtcMsgSrc = msgSrc; } +void TmStoreHelper::setTmStore(StorageManagerIF* store) { tmStore = store; } +const store_address_t& TmStoreHelper::getCurrentAddr() const { return currentAddr; } +ReturnValue_t TmStoreHelper::deletePacket() { return tmStore->deleteData(currentAddr); } -void TmStoreHelper::setInternalErrorReporter(InternalErrorReporterIF *reporter) { - errReporter = reporter; +void TmStoreHelper::setSourceDataRaw(const uint8_t* data, size_t len) { + PusTmParams& params = creator.getParams(); + params.dataWrapper.type = ecss::DataTypes::RAW; + params.dataWrapper.dataUnion.raw.data = data; + params.dataWrapper.dataUnion.raw.len = len; } + +void TmStoreHelper::setSourceDataSerializable(SerializeIF* serializable) { + PusTmParams& params = creator.getParams(); + params.dataWrapper.type = ecss::DataTypes::SERIALIZABLE; + params.dataWrapper.dataUnion.serializable = serializable; +} + +ReturnValue_t TmStoreHelper::addPacketToStore() { + creator.updateSpLengthField(); + uint8_t* dataPtr; + tmStore->getFreeElement(¤tAddr, creator.getSerializedSize(), &dataPtr); + size_t serLen = 0; + return creator.serialize(&dataPtr, &serLen, creator.getSerializedSize(), + SerializeIF::Endianness::NETWORK); +} + +void TmStoreHelper::setTimeStamper(TimeStamperIF* timeStamper_) { + creator.setTimeStamper(timeStamper_); +} +void TmStoreHelper::setApid(uint16_t apid) { creator.setApid(apid); } diff --git a/src/fsfw/tmtcservices/TmStoreHelper.h b/src/fsfw/tmtcservices/TmStoreHelper.h index 61ef93f4..43f7e787 100644 --- a/src/fsfw/tmtcservices/TmStoreHelper.h +++ b/src/fsfw/tmtcservices/TmStoreHelper.h @@ -4,35 +4,27 @@ #include "fsfw/internalerror/InternalErrorReporterIF.h" #include "fsfw/ipc/MessageQueueMessageIF.h" #include "fsfw/storagemanager/StorageManagerIF.h" +#include "fsfw/timemanager/TimeStamperIF.h" #include "fsfw/tmtcpacket/pus/tm/PusTmCreator.h" -class TmStoreAndSendWrapper { - -}; - -class TmSendHelper { - public: - TmSendHelper(MessageQueueId_t tmtcMsgDest, - MessageQueueId_t tmtcMsgSrc, InternalErrorReporterIF* reporter); - void setMsgDestination(MessageQueueId_t msgDest); - void setMsgSource(MessageQueueId_t msgSrc); - void setInternalErrorReporter(InternalErrorReporterIF* reporter); - ReturnValue_t sendPacket(); - private: - MessageQueueId_t tmtcMsgDest; - MessageQueueId_t tmtcMsgSrc; - InternalErrorReporterIF* errReporter; -}; - -// TODO: Serializing a packet into a store and sending the message are two different tasks -// Move them into separate classes class TmStoreHelper { public: - TmStoreHelper(StorageManagerIF* tmStore); + explicit TmStoreHelper(uint16_t defaultApid, StorageManagerIF* tmStore); + TmStoreHelper(uint16_t defaultApid, StorageManagerIF* tmStore, TimeStamperIF* timeStamper); + + ReturnValue_t preparePacket(uint8_t service, uint8_t subservice, uint16_t counter); + + void setTimeStamper(TimeStamperIF* timeStamper); + [[nodiscard]] const store_address_t& getCurrentAddr() const; + void setSourceDataRaw(const uint8_t* data, size_t len); + void setSourceDataSerializable(SerializeIF* serializable); + void setApid(uint16_t apid); + StorageManagerIF* getTmStore(); + void setTmStore(StorageManagerIF* store); + ReturnValue_t addPacketToStore(); + ReturnValue_t deletePacket(); - void preparePacket(uint16_t apid, uint8_t service, uint8_t subservice, uint16_t counter); private: - PusTmParams params{}; PusTmCreator creator; store_address_t currentAddr{}; StorageManagerIF* tmStore; diff --git a/src/fsfw/tmtcservices/VerificationReporter.cpp b/src/fsfw/tmtcservices/VerificationReporter.cpp index 04b42934..67b2af37 100644 --- a/src/fsfw/tmtcservices/VerificationReporter.cpp +++ b/src/fsfw/tmtcservices/VerificationReporter.cpp @@ -13,17 +13,17 @@ VerificationReporter::VerificationReporter() : acknowledgeQueue(MessageQueueIF:: VerificationReporter::~VerificationReporter() = default; -void VerificationReporter::sendSuccessReport(uint8_t set_report_id, PusTcReader* currentPacket, +void VerificationReporter::sendSuccessReport(uint8_t set_report_id, PusTcReader* correspondingTc, uint8_t set_step) { if (acknowledgeQueue == MessageQueueIF::NO_QUEUE) { this->initialize(); } - if (currentPacket == nullptr) { + if (correspondingTc == nullptr) { return; } - PusVerificationMessage message(set_report_id, currentPacket->getAcknowledgeFlags(), - currentPacket->getPacketIdRaw(), - currentPacket->getPacketSeqCtrlRaw(), 0, set_step); + PusVerificationMessage message(set_report_id, correspondingTc->getAcknowledgeFlags(), + correspondingTc->getPacketIdRaw(), + correspondingTc->getPacketSeqCtrlRaw(), 0, set_step); ReturnValue_t status = MessageQueueSenderIF::sendMessage(acknowledgeQueue, &message); if (status != HasReturnvaluesIF::RETURN_OK) { #if FSFW_CPP_OSTREAM_ENABLED == 1 @@ -50,18 +50,18 @@ void VerificationReporter::sendSuccessReport(uint8_t set_report_id, uint8_t ackF } } -void VerificationReporter::sendFailureReport(uint8_t report_id, PusTcReader* currentPacket, +void VerificationReporter::sendFailureReport(uint8_t report_id, PusTcReader* correspondingTc, ReturnValue_t error_code, uint8_t step, uint32_t parameter1, uint32_t parameter2) { if (acknowledgeQueue == MessageQueueIF::NO_QUEUE) { this->initialize(); } - if (currentPacket == nullptr) { + if (correspondingTc == nullptr) { return; } PusVerificationMessage message( - report_id, currentPacket->getAcknowledgeFlags(), currentPacket->getPacketIdRaw(), - currentPacket->getPacketSeqCtrlRaw(), error_code, step, parameter1, parameter2); + report_id, correspondingTc->getAcknowledgeFlags(), correspondingTc->getPacketIdRaw(), + correspondingTc->getPacketSeqCtrlRaw(), error_code, step, parameter1, parameter2); ReturnValue_t status = MessageQueueSenderIF::sendMessage(acknowledgeQueue, &message); if (status != HasReturnvaluesIF::RETURN_OK) { #if FSFW_CPP_OSTREAM_ENABLED == 1 diff --git a/src/fsfw/tmtcservices/VerificationReporter.h b/src/fsfw/tmtcservices/VerificationReporter.h index 5b4dbe0a..d668c502 100644 --- a/src/fsfw/tmtcservices/VerificationReporter.h +++ b/src/fsfw/tmtcservices/VerificationReporter.h @@ -27,11 +27,11 @@ class VerificationReporter { VerificationReporter(); virtual ~VerificationReporter(); - void sendSuccessReport(uint8_t set_report_id, PusTcReader* current_packet, uint8_t set_step = 0); + void sendSuccessReport(uint8_t set_report_id, PusTcReader* correspondingTc, 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, PusTcReader* current_packet, + void sendFailureReport(uint8_t report_id, PusTcReader* correspondingTc, 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, diff --git a/src/fsfw/tmtcservices/sendAndStoreHelper.h b/src/fsfw/tmtcservices/sendAndStoreHelper.h new file mode 100644 index 00000000..d07456f6 --- /dev/null +++ b/src/fsfw/tmtcservices/sendAndStoreHelper.h @@ -0,0 +1,54 @@ +#ifndef FSFW_TMTCSERVICES_SENDANDSTOREHELPER_H +#define FSFW_TMTCSERVICES_SENDANDSTOREHELPER_H + +#include "TmSendHelper.h" +#include "TmStoreHelper.h" + +namespace tm { + +ReturnValue_t storeAndSendTmPacket(TmStoreHelper& storeHelper, TmSendHelper& sendHelper) { + storeHelper.addPacketToStore(); + ReturnValue_t result = sendHelper.sendPacket(storeHelper.getCurrentAddr()); + if (result != HasReturnvaluesIF::RETURN_OK) { + storeHelper.deletePacket(); + } + return result; +} + +class SourceDataWithObjectIdPrefix : public SerializeIF { + public: + SourceDataWithObjectIdPrefix(object_id_t objectId, const uint8_t* srcData, size_t srcDataLen) + : objectId(objectId), srcData(srcData), srcDataLen(srcDataLen) {} + ReturnValue_t serialize(uint8_t** buffer, size_t* size, size_t maxSize, + Endianness streamEndianness) const override { + if (*size + getSerializedSize() > maxSize) { + return SerializeIF::BUFFER_TOO_SHORT; + } + ReturnValue_t result = + SerializeAdapter::serialize(&objectId, buffer, size, maxSize, streamEndianness); + if (result != HasReturnvaluesIF::RETURN_OK) { + return result; + } + std::memcpy(*buffer, srcData, srcDataLen); + *buffer += srcDataLen; + *size += srcDataLen; + return HasReturnvaluesIF::RETURN_OK; + } + + [[nodiscard]] size_t getSerializedSize() const override { return sizeof(objectId) + srcDataLen; } + + ReturnValue_t deSerialize(const uint8_t** buffer, size_t* size, + Endianness streamEndianness) override { + // TODO: Implement + return HasReturnvaluesIF::RETURN_FAILED; + } + + private: + object_id_t objectId; + const uint8_t* srcData; + size_t srcDataLen; +}; + +} // namespace tm + +#endif // FSFW_TMTCSERVICES_SENDANDSTOREHELPER_H diff --git a/unittests/CatchFactory.cpp b/unittests/CatchFactory.cpp index 860a9bed..25ced1ba 100644 --- a/unittests/CatchFactory.cpp +++ b/unittests/CatchFactory.cpp @@ -70,8 +70,6 @@ void Factory::setStaticFrameworkObjectIds() { LocalDataPoolManager::defaultHkDestination = objects::HK_RECEIVER_MOCK; DeviceHandlerFailureIsolation::powerConfirmationId = objects::NO_OBJECT; - - TmPacketBase::timeStamperId = objects::NO_OBJECT; } #endif -- 2.43.0 From d8b6cb39acfe7601338de02ee3ec37387991ef31 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Thu, 21 Jul 2022 11:34:11 +0200 Subject: [PATCH 016/108] various bugfixes and improvements --- src/fsfw/ipc/MessageQueueSenderIF.h | 9 +- src/fsfw/pus/Service5EventReporting.cpp | 1 + src/fsfw/pus/Service9TimeManagement.cpp | 4 +- src/fsfw/returnvalues/FwClassIds.h | 3 +- src/fsfw/tcdistribution/PusPacketChecker.h | 2 +- src/fsfw/timemanager/CCSDSTime.cpp | 2 +- src/fsfw/timemanager/CMakeLists.txt | 5 +- src/fsfw/timemanager/CcsdsTimeStampReader.cpp | 14 +++ src/fsfw/timemanager/CcsdsTimeStampReader.h | 19 ++++ ...imeStamper.cpp => CdsShortTimeStamper.cpp} | 6 +- src/fsfw/timemanager/CdsShortTimeStamper.h | 6 +- src/fsfw/timemanager/TimeReaderIF.h | 19 ++++ src/fsfw/timemanager/TimeStamperIF.h | 1 + .../tmtcpacket/ccsds/SpacePacketReader.cpp | 27 +++--- src/fsfw/tmtcpacket/ccsds/SpacePacketReader.h | 51 ++++++++--- src/fsfw/tmtcpacket/pus/CreatorDataIF.h | 2 +- src/fsfw/tmtcpacket/pus/PusIF.h | 5 ++ src/fsfw/tmtcpacket/pus/RawUserDataReaderIF.h | 3 +- .../tmtcpacket/pus/{definitions.h => defs.h} | 14 +++ src/fsfw/tmtcpacket/pus/tc/PusTcCreator.cpp | 10 ++- src/fsfw/tmtcpacket/pus/tc/PusTcCreator.h | 4 +- src/fsfw/tmtcpacket/pus/tc/PusTcIF.h | 6 +- src/fsfw/tmtcpacket/pus/tc/PusTcReader.cpp | 35 ++++---- src/fsfw/tmtcpacket/pus/tc/PusTcReader.h | 33 +++---- src/fsfw/tmtcpacket/pus/tc/TcPacketPus.h | 2 +- src/fsfw/tmtcpacket/pus/tm/PusTmCreator.cpp | 20 ++--- src/fsfw/tmtcpacket/pus/tm/PusTmCreator.h | 2 +- src/fsfw/tmtcpacket/pus/tm/PusTmIF.h | 5 +- src/fsfw/tmtcpacket/pus/tm/PusTmMinimal.cpp | 6 +- src/fsfw/tmtcpacket/pus/tm/PusTmMinimal.h | 4 +- src/fsfw/tmtcpacket/pus/tm/PusTmReader.cpp | 86 ++++++++++++++++++- src/fsfw/tmtcpacket/pus/tm/PusTmReader.h | 42 ++++++++- src/fsfw/tmtcpacket/pus/tm/TmPacketPusC.cpp | 2 +- .../tmtcservices/CommandingServiceBase.cpp | 36 +++++--- src/fsfw/tmtcservices/PusServiceBase.cpp | 62 +++++++------ 35 files changed, 401 insertions(+), 147 deletions(-) create mode 100644 src/fsfw/timemanager/CcsdsTimeStampReader.cpp create mode 100644 src/fsfw/timemanager/CcsdsTimeStampReader.h rename src/fsfw/timemanager/{TimeStamper.cpp => CdsShortTimeStamper.cpp} (99%) create mode 100644 src/fsfw/timemanager/TimeReaderIF.h rename src/fsfw/tmtcpacket/pus/{definitions.h => defs.h} (74%) diff --git a/src/fsfw/ipc/MessageQueueSenderIF.h b/src/fsfw/ipc/MessageQueueSenderIF.h index a98862f6..83c7223a 100644 --- a/src/fsfw/ipc/MessageQueueSenderIF.h +++ b/src/fsfw/ipc/MessageQueueSenderIF.h @@ -1,14 +1,14 @@ #ifndef FSFW_IPC_MESSAGEQUEUESENDERIF_H_ #define FSFW_IPC_MESSAGEQUEUESENDERIF_H_ -#include "../objectmanager/ObjectManagerIF.h" #include "MessageQueueIF.h" #include "MessageQueueMessageIF.h" +#include "fsfw/objectmanager/ObjectManagerIF.h" class MessageQueueSenderIF { public: - virtual ~MessageQueueSenderIF() {} - + virtual ~MessageQueueSenderIF() = default; + MessageQueueSenderIF() = delete; /** * Allows sending messages without actually "owning" a message queue. * Not sure whether this is actually a good idea. @@ -16,9 +16,6 @@ class MessageQueueSenderIF { static ReturnValue_t sendMessage(MessageQueueId_t sendTo, MessageQueueMessageIF* message, MessageQueueId_t sentFrom = MessageQueueIF::NO_QUEUE, bool ignoreFault = false); - - private: - MessageQueueSenderIF() {} }; #endif /* FSFW_IPC_MESSAGEQUEUESENDERIF_H_ */ diff --git a/src/fsfw/pus/Service5EventReporting.cpp b/src/fsfw/pus/Service5EventReporting.cpp index 4d0dcf1d..d88e58b8 100644 --- a/src/fsfw/pus/Service5EventReporting.cpp +++ b/src/fsfw/pus/Service5EventReporting.cpp @@ -99,4 +99,5 @@ ReturnValue_t Service5EventReporting::initialize() { return result; } initializeTmHelpers(sendHelper, storeHelper); + return result; } diff --git a/src/fsfw/pus/Service9TimeManagement.cpp b/src/fsfw/pus/Service9TimeManagement.cpp index 99b447c1..4abbd5d2 100644 --- a/src/fsfw/pus/Service9TimeManagement.cpp +++ b/src/fsfw/pus/Service9TimeManagement.cpp @@ -25,9 +25,7 @@ ReturnValue_t Service9TimeManagement::handleRequest(uint8_t subservice) { ReturnValue_t Service9TimeManagement::setTime() { Clock::TimeOfDay_t timeToSet; - size_t userDataLen = 0; - const uint8_t* timeData = currentPacket.getUserData(userDataLen); - TimePacket timePacket(timeData, userDataLen); + TimePacket timePacket(currentPacket.getUserData(), currentPacket.getUserDataLen()); 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 50efd9c5..1dfe1cc8 100644 --- a/src/fsfw/returnvalues/FwClassIds.h +++ b/src/fsfw/returnvalues/FwClassIds.h @@ -36,7 +36,8 @@ enum : uint8_t { TRIPLE_REDUNDACY_CHECK, // TRC PACKET_CHECK, // TCC PACKET_DISTRIBUTION, // TCD - ACCEPTS_TELECOMMANDS_IF, // PUS + ACCEPTS_TELECOMMANDS_IF, // ATC + PUS_IF, // PUS DEVICE_SERVICE_BASE, // DSB COMMAND_SERVICE_BASE, // CSB TM_STORE_BACKEND_IF, // TMB diff --git a/src/fsfw/tcdistribution/PusPacketChecker.h b/src/fsfw/tcdistribution/PusPacketChecker.h index fe341378..431ee5a8 100644 --- a/src/fsfw/tcdistribution/PusPacketChecker.h +++ b/src/fsfw/tcdistribution/PusPacketChecker.h @@ -5,7 +5,7 @@ #include "CcsdsPacketCheckerBase.h" #include "fsfw/FSFW.h" #include "fsfw/returnvalues/HasReturnvaluesIF.h" -#include "fsfw/tmtcpacket/pus/definitions.h" +#include "fsfw/tmtcpacket/pus/defs.h" #include "fsfw/tmtcservices/PusVerificationReport.h" class PacketCheckIF : public ReadablePacketIF, public PusIF {}; diff --git a/src/fsfw/timemanager/CCSDSTime.cpp b/src/fsfw/timemanager/CCSDSTime.cpp index 1f84dd03..4d5de9b3 100644 --- a/src/fsfw/timemanager/CCSDSTime.cpp +++ b/src/fsfw/timemanager/CCSDSTime.cpp @@ -504,7 +504,7 @@ ReturnValue_t CCSDSTime::convertFromCDS(timeval* to, const uint8_t* from, size_t } else if ((pField & 0b11) == 0b10) { expectedLength += 4; } - if (foundLength != NULL) { + if (foundLength != nullptr) { *foundLength = expectedLength; } if (expectedLength > maxLength) { diff --git a/src/fsfw/timemanager/CMakeLists.txt b/src/fsfw/timemanager/CMakeLists.txt index c4f77395..7e38cc6a 100644 --- a/src/fsfw/timemanager/CMakeLists.txt +++ b/src/fsfw/timemanager/CMakeLists.txt @@ -1,3 +1,4 @@ target_sources( - ${LIB_FSFW_NAME} PRIVATE CCSDSTime.cpp Countdown.cpp Stopwatch.cpp - TimeMessage.cpp TimeStamper.cpp ClockCommon.cpp) + ${LIB_FSFW_NAME} + PRIVATE CCSDSTime.cpp Countdown.cpp Stopwatch.cpp TimeMessage.cpp + CdsShortTimeStamper.cpp ClockCommon.cpp) diff --git a/src/fsfw/timemanager/CcsdsTimeStampReader.cpp b/src/fsfw/timemanager/CcsdsTimeStampReader.cpp new file mode 100644 index 00000000..d23d0387 --- /dev/null +++ b/src/fsfw/timemanager/CcsdsTimeStampReader.cpp @@ -0,0 +1,14 @@ +#include "CcsdsTimeStampReader.h" + +#include "CCSDSTime.h" + +ReturnValue_t CcsdsTimestampReader::readTimeStamp(const uint8_t* buffer, uint8_t maxSize) { + ReturnValue_t result = CCSDSTime::convertFromCcsds(&time, buffer, ×tampLen, maxSize); + if (result != HasReturnvaluesIF::RETURN_OK) { + return result; + } + return result; +} + +timeval& CcsdsTimestampReader::getTime() { return time; } +size_t CcsdsTimestampReader::getTimestampLen() { return timestampLen; } diff --git a/src/fsfw/timemanager/CcsdsTimeStampReader.h b/src/fsfw/timemanager/CcsdsTimeStampReader.h new file mode 100644 index 00000000..f323c87e --- /dev/null +++ b/src/fsfw/timemanager/CcsdsTimeStampReader.h @@ -0,0 +1,19 @@ +#ifndef FSFW_TIMEMANAGER_CCSDSTIMESTAMPREADER_H +#define FSFW_TIMEMANAGER_CCSDSTIMESTAMPREADER_H + +#include + +#include "TimeReaderIF.h" + +class CcsdsTimestampReader : public TimeReaderIF { + public: + ReturnValue_t readTimeStamp(const uint8_t* buffer, uint8_t maxSize) override; + size_t getTimestampLen() override; + timeval& getTime() override; + + private: + timeval time{}; + size_t timestampLen = 0; +}; + +#endif // FSFW_TIMEMANAGER_CCSDSTIMESTAMPREADER_H diff --git a/src/fsfw/timemanager/TimeStamper.cpp b/src/fsfw/timemanager/CdsShortTimeStamper.cpp similarity index 99% rename from src/fsfw/timemanager/TimeStamper.cpp rename to src/fsfw/timemanager/CdsShortTimeStamper.cpp index 7096d95f..af0344e3 100644 --- a/src/fsfw/timemanager/TimeStamper.cpp +++ b/src/fsfw/timemanager/CdsShortTimeStamper.cpp @@ -1,6 +1,7 @@ +#include "fsfw/timemanager/CdsShortTimeStamper.h" + #include -#include "fsfw/timemanager/CdsShortTimeStamper.h" #include "fsfw/timemanager/Clock.h" CdsShortTimeStamper::CdsShortTimeStamper(object_id_t objectId) : SystemObject(objectId) {} @@ -27,9 +28,12 @@ ReturnValue_t CdsShortTimeStamper::serialize(uint8_t **buffer, size_t *size, siz *size += getSerializedSize(); return result; } + size_t CdsShortTimeStamper::getSerializedSize() const { return getTimestampSize(); } + ReturnValue_t CdsShortTimeStamper::deSerialize(const uint8_t **buffer, size_t *size, SerializeIF::Endianness streamEndianness) { return HasReturnvaluesIF::RETURN_FAILED; } + size_t CdsShortTimeStamper::getTimestampSize() const { return TIMESTAMP_LEN; } diff --git a/src/fsfw/timemanager/CdsShortTimeStamper.h b/src/fsfw/timemanager/CdsShortTimeStamper.h index 1e9abfa8..d392c1a6 100644 --- a/src/fsfw/timemanager/CdsShortTimeStamper.h +++ b/src/fsfw/timemanager/CdsShortTimeStamper.h @@ -1,9 +1,9 @@ #ifndef FSFW_TIMEMANAGER_TIMESTAMPER_H_ #define FSFW_TIMEMANAGER_TIMESTAMPER_H_ -#include "../objectmanager/SystemObject.h" #include "CCSDSTime.h" #include "TimeStamperIF.h" +#include "fsfw/objectmanager/SystemObject.h" /** * @brief Time stamper which can be used to add any timestamp to a @@ -34,10 +34,10 @@ class CdsShortTimeStamper : public TimeStamperIF, public SystemObject { ReturnValue_t addTimeStamp(uint8_t *buffer, uint8_t maxSize) override; ReturnValue_t serialize(uint8_t **buffer, size_t *size, size_t maxSize, Endianness streamEndianness) const override; - size_t getSerializedSize() const override; + [[nodiscard]] size_t getSerializedSize() const override; ReturnValue_t deSerialize(const uint8_t **buffer, size_t *size, Endianness streamEndianness) override; - size_t getTimestampSize() const override; + [[nodiscard]] size_t getTimestampSize() const override; }; #endif /* FSFW_TIMEMANAGER_TIMESTAMPER_H_ */ diff --git a/src/fsfw/timemanager/TimeReaderIF.h b/src/fsfw/timemanager/TimeReaderIF.h new file mode 100644 index 00000000..388f7d71 --- /dev/null +++ b/src/fsfw/timemanager/TimeReaderIF.h @@ -0,0 +1,19 @@ +#ifndef FSFW_TIMEMANAGER_TIMEREADERIF_H +#define FSFW_TIMEMANAGER_TIMEREADERIF_H + +#include + +#include "fsfw/returnvalues/HasReturnvaluesIF.h" + +class TimeReaderIF { + public: + virtual ~TimeReaderIF() = default; + virtual ReturnValue_t readTimeStamp(const uint8_t* buffer, uint8_t maxSize) = 0; + // Would be nice to have this, but the clock backend needs to be redesigned + // virtual ReturnValue_t readTimestampLen(const uint8_t* buffer, uint8_t maxSize, size_t& + // timestampLen) = 0; + virtual size_t getTimestampLen() = 0; + virtual timeval& getTime() = 0; +}; + +#endif // FSFW_TIMEMANAGER_TIMEREADERIF_H diff --git a/src/fsfw/timemanager/TimeStamperIF.h b/src/fsfw/timemanager/TimeStamperIF.h index 404dd10a..2f0e8021 100644 --- a/src/fsfw/timemanager/TimeStamperIF.h +++ b/src/fsfw/timemanager/TimeStamperIF.h @@ -24,6 +24,7 @@ class TimeStamperIF : public SerializeIF { [[nodiscard]] virtual size_t getTimestampSize() const = 0; virtual ReturnValue_t addTimeStamp(uint8_t* buffer, uint8_t maxSize) = 0; + ~TimeStamperIF() override = default; }; diff --git a/src/fsfw/tmtcpacket/ccsds/SpacePacketReader.cpp b/src/fsfw/tmtcpacket/ccsds/SpacePacketReader.cpp index a0ad5328..c528d0a7 100644 --- a/src/fsfw/tmtcpacket/ccsds/SpacePacketReader.cpp +++ b/src/fsfw/tmtcpacket/ccsds/SpacePacketReader.cpp @@ -1,7 +1,5 @@ #include "SpacePacketReader.h" -#include - #include "fsfw/serialize/SerializeIF.h" #include "fsfw/serviceinterface/ServiceInterface.h" @@ -9,8 +7,8 @@ SpacePacketReader::SpacePacketReader(const uint8_t* setAddress, size_t maxSize_) setInternalFields(setAddress, maxSize_); } -ReturnValue_t SpacePacketReader::checkLength() const { - if (getFullPacketLen() > maxSize) { +ReturnValue_t SpacePacketReader::checkSize() const { + if (getFullPacketLen() > bufSize) { return SerializeIF::STREAM_TOO_SHORT; } return HasReturnvaluesIF::RETURN_OK; @@ -22,9 +20,8 @@ inline uint16_t SpacePacketReader::getPacketIdRaw() const { return ccsds::getPac const uint8_t* SpacePacketReader::getPacketData() { return packetDataField; } -ReturnValue_t SpacePacketReader::setData(uint8_t* pData, size_t maxSize_, void* args) { - setInternalFields(pData, maxSize_); - return HasReturnvaluesIF::RETURN_OK; +ReturnValue_t SpacePacketReader::setData(uint8_t* data, size_t maxSize_, void* args) { + return setInternalFields(data, maxSize_); } uint16_t SpacePacketReader::getPacketSeqCtrlRaw() const { @@ -32,11 +29,21 @@ uint16_t SpacePacketReader::getPacketSeqCtrlRaw() const { } uint16_t SpacePacketReader::getPacketDataLen() const { return ccsds::getPacketLen(*spHeader); } -void SpacePacketReader::setInternalFields(const uint8_t* data, size_t maxSize_) { - maxSize = maxSize_; + +ReturnValue_t SpacePacketReader::setInternalFields(const uint8_t* data, size_t maxSize_) { + bufSize = maxSize_; spHeader = reinterpret_cast(data); packetDataField = data + ccsds::HEADER_LEN; + return checkSize(); } + const uint8_t* SpacePacketReader::getFullData() { return reinterpret_cast(spHeader); -}; +} +size_t SpacePacketReader::getBufSize() const { return bufSize; } + +bool SpacePacketReader::isNull() const { return spHeader == nullptr; } + +ReturnValue_t SpacePacketReader::setReadOnlyData(const uint8_t* data, size_t maxSize) { + return setData(const_cast(data), maxSize, nullptr); +} diff --git a/src/fsfw/tmtcpacket/ccsds/SpacePacketReader.h b/src/fsfw/tmtcpacket/ccsds/SpacePacketReader.h index 43119146..b35b813b 100644 --- a/src/fsfw/tmtcpacket/ccsds/SpacePacketReader.h +++ b/src/fsfw/tmtcpacket/ccsds/SpacePacketReader.h @@ -22,17 +22,21 @@ * This class is the basic data handler for any CCSDS Space Packet * compatible Telecommand and Telemetry packet. * It does not contain the packet data itself but a pointer to the - * data must be set on instantiation. An invalid pointer may cause - * damage, as no getter method checks data validity. Anyway, a NULL - * check can be performed by making use of the getWholeData method. - * Remark: All bit numbers in this documentation are counted from - * the most significant bit (from left). + * data must be set on instantiation or with the @setData or @setReadOnlyData call. + * The @isNull and @checkSize methods can be used to check the validity of the data pointed to. + * + * This is a zero-copy reader class. It does not contain the packet data itself but a pointer to + * the data. Calling any accessor methods without pointing the object to valid data first will + * cause undefined behaviour. * @ingroup tmtcpackets */ class SpacePacketReader : public SpacePacketIF, public ReadablePacketIF, public RedirectableDataPointerIF { public: + /** + * Initialize an empty space packet reader which points to no data + */ SpacePacketReader() = default; /** * This is the default constructor. @@ -45,6 +49,24 @@ class SpacePacketReader : public SpacePacketIF, */ ~SpacePacketReader() override; + /** + * Check whether any data is set for the reader object + * @return + */ + [[nodiscard]] bool isNull() const; + /** + * Get size of the buffer. This is the size which is passed to the constructor or to the + * @setData call. It is not the content of the CCSDS data length field and it is not necessarily + * equal to the full packet length of the space packet. + * @return + */ + [[nodiscard]] size_t getBufSize() const; + + /** + * CCSDS header always has 6 bytes + * @return + */ + static constexpr size_t getHeaderLen() { return ccsds::HEADER_LEN; } [[nodiscard]] uint16_t getPacketIdRaw() const override; [[nodiscard]] uint16_t getPacketSeqCtrlRaw() const override; [[nodiscard]] uint16_t getPacketDataLen() const override; @@ -52,16 +74,11 @@ class SpacePacketReader : public SpacePacketIF, const uint8_t* getFullData() override; // Helper methods: - [[nodiscard]] ReturnValue_t checkLength() const; + [[nodiscard]] ReturnValue_t checkSize() const; const uint8_t* getPacketData(); - /** - * With this method, the packet data pointer can be redirected to another - * location. - * @param p_Data A pointer to another raw Space Packet. - */ - ReturnValue_t setData(uint8_t* p_Data, size_t maxSize, void* args) override; + ReturnValue_t setReadOnlyData(const uint8_t* data, size_t maxSize); protected: /** @@ -71,9 +88,15 @@ class SpacePacketReader : public SpacePacketIF, */ const ccsds::PrimaryHeader* spHeader{}; const uint8_t* packetDataField{}; - size_t maxSize = 0; + size_t bufSize = 0; + /** + * With this method, the packet data pointer can be redirected to another + * location. + * @param data A pointer to another raw Space Packet. + */ + ReturnValue_t setData(uint8_t* data, size_t maxSize, void* args) override; - void setInternalFields(const uint8_t* data, size_t maxSize); + ReturnValue_t setInternalFields(const uint8_t* data, size_t maxSize); }; #endif /* FSFW_TMTCPACKET_SPACEPACKETBASE_H_ */ diff --git a/src/fsfw/tmtcpacket/pus/CreatorDataIF.h b/src/fsfw/tmtcpacket/pus/CreatorDataIF.h index 7d5d1d18..f66ca567 100644 --- a/src/fsfw/tmtcpacket/pus/CreatorDataIF.h +++ b/src/fsfw/tmtcpacket/pus/CreatorDataIF.h @@ -1,7 +1,7 @@ #ifndef FSFW_TMTCPACKET_CREATORDATAIF_H #define FSFW_TMTCPACKET_CREATORDATAIF_H -#include "definitions.h" +#include "defs.h" class CreatorDataIF { public: diff --git a/src/fsfw/tmtcpacket/pus/PusIF.h b/src/fsfw/tmtcpacket/pus/PusIF.h index eb0e35f8..8a15f01e 100644 --- a/src/fsfw/tmtcpacket/pus/PusIF.h +++ b/src/fsfw/tmtcpacket/pus/PusIF.h @@ -3,10 +3,15 @@ #include +#include "fsfw/returnvalues/FwClassIds.h" #include "fsfw/tmtcpacket/ccsds/SpacePacketIF.h" class PusIF : public SpacePacketIF { public: + static constexpr uint8_t INTERFACE_ID = CLASS_ID::PUS_IF; + static constexpr ReturnValue_t INVALID_CRC_16 = + HasReturnvaluesIF::makeReturnCode(INTERFACE_ID, 0); + ~PusIF() override = default; /** * This command returns the TC Packet PUS Version Number. diff --git a/src/fsfw/tmtcpacket/pus/RawUserDataReaderIF.h b/src/fsfw/tmtcpacket/pus/RawUserDataReaderIF.h index 170ac824..e4e515f8 100644 --- a/src/fsfw/tmtcpacket/pus/RawUserDataReaderIF.h +++ b/src/fsfw/tmtcpacket/pus/RawUserDataReaderIF.h @@ -6,7 +6,8 @@ class RawUserDataReaderIF { public: - virtual const uint8_t* getUserData(size_t& userDataLen) = 0; + virtual const uint8_t* getUserData() const = 0; + virtual size_t getUserDataLen() const = 0; }; #endif // FSFW_TMTCPACKET_RAWDATAIF_H diff --git a/src/fsfw/tmtcpacket/pus/definitions.h b/src/fsfw/tmtcpacket/pus/defs.h similarity index 74% rename from src/fsfw/tmtcpacket/pus/definitions.h rename to src/fsfw/tmtcpacket/pus/defs.h index 6a5c10eb..027ff37c 100644 --- a/src/fsfw/tmtcpacket/pus/definitions.h +++ b/src/fsfw/tmtcpacket/pus/defs.h @@ -7,6 +7,8 @@ namespace ecss { +using PusChecksumT = uint16_t; + //! Version numbers according to ECSS-E-ST-70-41C p.439 enum PusVersion : uint8_t { PUS_A = 1, PUS_C = 2 }; @@ -36,6 +38,18 @@ struct DataWrapper { } }; +/** + * This struct defines the data structure of a Space Packet when accessed + * via a pointer. + * @ingroup tmtcpackets + */ +struct PusPointers { + const uint8_t* spHeaderStart; + const uint8_t* secHeaderStart; + const uint8_t* userDataStart; + const uint8_t* crcStart; +}; + } // namespace ecss #endif /* FSFW_SRC_FSFW_TMTCPACKET_PUS_TM_DEFINITIONS_H_ */ diff --git a/src/fsfw/tmtcpacket/pus/tc/PusTcCreator.cpp b/src/fsfw/tmtcpacket/pus/tc/PusTcCreator.cpp index 8f8cc8e6..bd824d24 100644 --- a/src/fsfw/tmtcpacket/pus/tc/PusTcCreator.cpp +++ b/src/fsfw/tmtcpacket/pus/tc/PusTcCreator.cpp @@ -14,7 +14,7 @@ PusTcCreator::PusTcCreator(SpacePacketParams spParams, PusTcParams pusParams) ReturnValue_t PusTcCreator::serialize(uint8_t **buffer, size_t *size, size_t maxSize, SerializeIF::Endianness streamEndianness) const { size_t userDataLen = pusParams.dataWrapper.getLength(); - if (*size + PusTcIF::MIN_LEN + userDataLen > maxSize) { + if (*size + PusTcIF::MIN_SIZE + userDataLen > maxSize) { return SerializeIF::BUFFER_TOO_SHORT; } ReturnValue_t result = spCreator.serialize(buffer, size, maxSize, streamEndianness); @@ -57,7 +57,8 @@ ReturnValue_t PusTcCreator::serialize(uint8_t **buffer, size_t *size, size_t max } void PusTcCreator::updateSpLengthField() { - spCreator.setDataLen(ecss::PusTcDataFieldHeader::MIN_LEN + pusParams.dataWrapper.getLength() + 1); + spCreator.setDataLen(ecss::PusTcDataFieldHeader::MIN_SIZE + pusParams.dataWrapper.getLength() + + 1); } size_t PusTcCreator::getSerializedSize() const { return spCreator.getFullPacketLen(); } @@ -82,4 +83,9 @@ uint8_t PusTcCreator::getService() const { return pusParams.service; } uint8_t PusTcCreator::getSubService() const { return pusParams.subservice; } uint16_t PusTcCreator::getSourceId() const { return pusParams.sourceId; } + ecss::DataWrapper &PusTcCreator::getDataWrapper() { return pusParams.dataWrapper; } + +PusTcParams &PusTcCreator::getPusParams() { return pusParams; } + +SpacePacketParams &PusTcCreator::getSpParams() { return spCreator.getParams(); } diff --git a/src/fsfw/tmtcpacket/pus/tc/PusTcCreator.h b/src/fsfw/tmtcpacket/pus/tc/PusTcCreator.h index 956a2505..1f6e8acb 100644 --- a/src/fsfw/tmtcpacket/pus/tc/PusTcCreator.h +++ b/src/fsfw/tmtcpacket/pus/tc/PusTcCreator.h @@ -5,7 +5,7 @@ #include "fsfw/tmtcpacket/ccsds/SpacePacketCreator.h" #include "fsfw/tmtcpacket/ccsds/SpacePacketIF.h" #include "fsfw/tmtcpacket/pus/CreatorDataIF.h" -#include "fsfw/tmtcpacket/pus/definitions.h" +#include "fsfw/tmtcpacket/pus/defs.h" #include "fsfw/tmtcpacket/pus/tc/PusTcIF.h" struct PusTcParams { @@ -24,6 +24,8 @@ class PusTcCreator : public PusTcIF, public SerializeIF, public CreatorDataIF { PusTcCreator(SpacePacketParams spParams, PusTcParams pusParams); void updateSpLengthField(); + PusTcParams &getPusParams(); + SpacePacketParams &getSpParams(); ReturnValue_t serialize(uint8_t **buffer, size_t *size, size_t maxSize, Endianness streamEndianness) const override; [[nodiscard]] size_t getSerializedSize() const override; diff --git a/src/fsfw/tmtcpacket/pus/tc/PusTcIF.h b/src/fsfw/tmtcpacket/pus/tc/PusTcIF.h index 61b29660..43e9aab0 100644 --- a/src/fsfw/tmtcpacket/pus/tc/PusTcIF.h +++ b/src/fsfw/tmtcpacket/pus/tc/PusTcIF.h @@ -31,7 +31,7 @@ static constexpr uint8_t ACK_ALL = ACK_ACCEPTANCE | ACK_START | ACK_STEP | ACK_C */ struct PusTcDataFieldHeader { // Version and ACK byte, Service Byte, Subservice Byte, 2 byte Source ID - static constexpr size_t MIN_LEN = 5; + static constexpr size_t MIN_SIZE = 5; uint8_t pusVersion; uint8_t ackFlags; uint8_t serviceType; @@ -44,8 +44,8 @@ struct PusTcDataFieldHeader { class PusTcIF : public PusIF { public: ~PusTcIF() override = default; - static const size_t MIN_LEN = - (sizeof(ccsds::PrimaryHeader) + ecss::PusTcDataFieldHeader::MIN_LEN + 2); + static const size_t MIN_SIZE = + (sizeof(ccsds::PrimaryHeader) + ecss::PusTcDataFieldHeader::MIN_SIZE + 2); /** * This is a getter for the packet's Ack field, which are the lowest four diff --git a/src/fsfw/tmtcpacket/pus/tc/PusTcReader.cpp b/src/fsfw/tmtcpacket/pus/tc/PusTcReader.cpp index bf4ec181..b9e5e00f 100644 --- a/src/fsfw/tmtcpacket/pus/tc/PusTcReader.cpp +++ b/src/fsfw/tmtcpacket/pus/tc/PusTcReader.cpp @@ -12,20 +12,30 @@ PusTcReader::PusTcReader(const uint8_t* data, size_t size) { setReadOnlyData(dat PusTcReader::~PusTcReader() = default; ReturnValue_t PusTcReader::parseData() { - ReturnValue_t result = spReader.checkLength(); + if (pointers.spHeaderStart == nullptr or spReader.isNull()) { + return HasReturnvaluesIF::RETURN_FAILED; + } + ReturnValue_t result = spReader.checkSize(); if (result != HasReturnvaluesIF::RETURN_OK) { return result; } - if (size < PusTcIF::MIN_LEN) { + if (spReader.getBufSize() < PusTcIF::MIN_SIZE) { return SerializeIF::STREAM_TOO_SHORT; } + + size_t currentOffset = SpacePacketReader::getHeaderLen(); + pointers.secHeaderStart = pointers.spHeaderStart + currentOffset; // Might become variable sized field in the future - size_t secHeaderLen = ecss::PusTcDataFieldHeader::MIN_LEN; - pointers.secHeaderStart = pointers.spHeaderStart + ccsds::HEADER_LEN; // TODO: No support for spare bytes yet - pointers.userDataStart = pointers.secHeaderStart + secHeaderLen; - appDataSize = size - (ccsds::HEADER_LEN + secHeaderLen); + currentOffset += ecss::PusTcDataFieldHeader::MIN_SIZE; + pointers.userDataStart = pointers.spHeaderStart + currentOffset; + appDataSize = spReader.getFullPacketLen() - currentOffset - sizeof(ecss::PusChecksumT); pointers.crcStart = pointers.userDataStart + appDataSize; + uint16_t crc16 = CRC::crc16ccitt(spReader.getFullData(), getFullPacketLen()); + if (crc16 != 0) { + // Checksum failure + return PusIF::INVALID_CRC_16; + } return HasReturnvaluesIF::RETURN_OK; } @@ -51,21 +61,16 @@ 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; + return spReader.setReadOnlyData(pData, size_); } ReturnValue_t PusTcReader::setReadOnlyData(const uint8_t* data, size_t size_) { - setData(const_cast(data), size_, nullptr); - return HasReturnvaluesIF::RETURN_OK; + return setData(const_cast(data), size_, nullptr); } -const uint8_t* PusTcReader::getUserData(size_t& userDataLen) { - userDataLen = appDataSize; - return pointers.userDataStart; -} +const uint8_t* PusTcReader::getUserData() const { return pointers.userDataStart; } +size_t PusTcReader::getUserDataLen() const { return appDataSize; } /* void PusTcReader::print() { diff --git a/src/fsfw/tmtcpacket/pus/tc/PusTcReader.h b/src/fsfw/tmtcpacket/pus/tc/PusTcReader.h index 0cf18496..e79f8b61 100644 --- a/src/fsfw/tmtcpacket/pus/tc/PusTcReader.h +++ b/src/fsfw/tmtcpacket/pus/tc/PusTcReader.h @@ -7,16 +7,17 @@ #include "fsfw/tmtcpacket/RedirectableDataPointerIF.h" #include "fsfw/tmtcpacket/ccsds/SpacePacketReader.h" #include "fsfw/tmtcpacket/pus/RawUserDataReaderIF.h" +#include "fsfw/tmtcpacket/pus/defs.h" /** - * This class is the basic data handler for any ECSS PUS Telecommand packet. + * This class is the basic reader class to read ECSS PUS C Telecommand packets. * - * In addition to #SpacePacketBase, the class provides methods to handle - * the standardized entries of the PUS TC Packet Data Field Header. - * It does not contain the packet data itself but a pointer to the - * data must be set on instantiation. An invalid pointer may cause - * damage, as no getter method checks data validity. Anyway, a NULL - * check can be performed by making use of the getWholeData method. + * 1. Implements the @SpacePacketIF to provide accessor methods for the contained space packet. + * 2. Implements the @PusTcIF to provide accessor methods for generic PUS C fields + * + * This is a zero-copy reader class. It does not contain the packet data itself but a pointer to + * the data. Calling any accessor methods without pointing the object to valid data first will + * cause undefined behaviour. * @ingroup tmtcpackets */ class PusTcReader : public PusTcIF, @@ -56,7 +57,8 @@ class PusTcReader : public PusTcIF, const uint8_t* getFullData() override; ReturnValue_t setReadOnlyData(const uint8_t* data, size_t size); - const uint8_t* getUserData(size_t& userDataLen) override; + [[nodiscard]] const uint8_t* getUserData() const override; + size_t getUserDataLen() const override; protected: /** @@ -70,20 +72,7 @@ class PusTcReader : public PusTcIF, 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 - * via a pointer. - * @ingroup tmtcpackets - */ - struct PusTcPointers { - const uint8_t* spHeaderStart; - const uint8_t* secHeaderStart; - const uint8_t* userDataStart; - const uint8_t* crcStart; - }; - - PusTcPointers pointers{}; - size_t size = 0; + ecss::PusPointers pointers{}; size_t appDataSize = 0; }; diff --git a/src/fsfw/tmtcpacket/pus/tc/TcPacketPus.h b/src/fsfw/tmtcpacket/pus/tc/TcPacketPus.h index fe976673..8af6125a 100644 --- a/src/fsfw/tmtcpacket/pus/tc/TcPacketPus.h +++ b/src/fsfw/tmtcpacket/pus/tc/TcPacketPus.h @@ -3,7 +3,7 @@ #include -#include "../definitions.h" +#include "../defs.h" #include "PusTcReader.h" #include "fsfw/FSFW.h" #include "fsfw/tmtcpacket/ccsds/defs.h" diff --git a/src/fsfw/tmtcpacket/pus/tm/PusTmCreator.cpp b/src/fsfw/tmtcpacket/pus/tm/PusTmCreator.cpp index e80eddd1..927ec072 100644 --- a/src/fsfw/tmtcpacket/pus/tm/PusTmCreator.cpp +++ b/src/fsfw/tmtcpacket/pus/tm/PusTmCreator.cpp @@ -7,20 +7,20 @@ PusTmCreator::PusTmCreator(SpacePacketParams initSpParams, PusTmParams initPusParams, TimeStamperIF* timeStamper) - : pusParams(initPusParams), spCreator(std::move(initSpParams)){}; + : pusParams(initPusParams), spCreator(std::move(initSpParams)) {} PusTmCreator::PusTmCreator(TimeStamperIF* timeStamper_) { pusParams.secHeader.timeStamper = timeStamper_; -}; +} PusTmCreator::PusTmCreator() = default; -uint16_t PusTmCreator::getPacketIdRaw() const { return 0; } -uint16_t PusTmCreator::getPacketSeqCtrlRaw() 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; } +uint16_t PusTmCreator::getPacketIdRaw() const { return spCreator.getPacketIdRaw(); } +uint16_t PusTmCreator::getPacketSeqCtrlRaw() const { return spCreator.getPacketSeqCtrlRaw(); } +uint16_t PusTmCreator::getPacketDataLen() const { return spCreator.getPacketDataLen(); } +uint8_t PusTmCreator::getPusVersion() const { return pusParams.secHeader.pusVersion; } +uint8_t PusTmCreator::getService() const { return pusParams.secHeader.service; } +uint8_t PusTmCreator::getSubService() const { return pusParams.secHeader.subservice; } PusTmParams& PusTmCreator::getParams() { return pusParams; } void PusTmCreator::setTimeStamper(TimeStamperIF* timeStamper_) { pusParams.secHeader.timeStamper = timeStamper_; @@ -89,11 +89,11 @@ TimeStamperIF* PusTmCreator::getTimestamper() { return pusParams.secHeader.timeS SpacePacketParams& PusTmCreator::getSpParams() { return spCreator.getParams(); } void PusTmCreator::updateSpLengthField() { - size_t headerLen = PusTmIF::MIN_TM_SIZE; + size_t headerLen = PusTmIF::MIN_SIZE; if (pusParams.secHeader.timeStamper != nullptr) { headerLen += pusParams.secHeader.timeStamper->getSerializedSize(); } spCreator.setDataLen(headerLen + pusParams.dataWrapper.getLength() + 1); } -void PusTmCreator::setApid(uint16_t apid) { spCreator.setApid(apid); }; +void PusTmCreator::setApid(uint16_t apid) { spCreator.setApid(apid); } diff --git a/src/fsfw/tmtcpacket/pus/tm/PusTmCreator.h b/src/fsfw/tmtcpacket/pus/tm/PusTmCreator.h index 5269bd0f..9ac79d16 100644 --- a/src/fsfw/tmtcpacket/pus/tm/PusTmCreator.h +++ b/src/fsfw/tmtcpacket/pus/tm/PusTmCreator.h @@ -50,7 +50,7 @@ class PusTmCreator : public SerializeIF, public PusTmIF, public CreatorDataIF { [[nodiscard]] size_t getSerializedSize() const override; ReturnValue_t deSerialize(const uint8_t** buffer, size_t* size, Endianness streamEndianness) override; - TimeStamperIF* getTimestamper() override; + TimeStamperIF* getTimestamper(); private: ecss::DataWrapper& getDataWrapper() override; diff --git a/src/fsfw/tmtcpacket/pus/tm/PusTmIF.h b/src/fsfw/tmtcpacket/pus/tm/PusTmIF.h index 94d41467..356cf20b 100644 --- a/src/fsfw/tmtcpacket/pus/tm/PusTmIF.h +++ b/src/fsfw/tmtcpacket/pus/tm/PusTmIF.h @@ -6,7 +6,7 @@ #include "fsfw/timemanager/TimeStamperIF.h" #include "fsfw/tmtcpacket/pus/PusIF.h" -#include "fsfw/tmtcpacket/pus/definitions.h" +#include "fsfw/tmtcpacket/pus/defs.h" class PusTmIF : public PusIF { public: @@ -19,12 +19,11 @@ class PusTmIF : public PusIF { /** * 2 bytes for CRC16 */ - static constexpr size_t MIN_TM_SIZE = sizeof(ccsds::PrimaryHeader) + MIN_SEC_HEADER_LEN + 2; + static constexpr size_t MIN_SIZE = sizeof(ccsds::PrimaryHeader) + MIN_SEC_HEADER_LEN + 2; virtual uint8_t getScTimeRefStatus() = 0; virtual uint16_t getMessageTypeCounter() = 0; virtual uint16_t getDestId() = 0; - virtual TimeStamperIF* getTimestamper() = 0; }; #endif // FSFW_TMTCPACKET_PUSTMIF_H diff --git a/src/fsfw/tmtcpacket/pus/tm/PusTmMinimal.cpp b/src/fsfw/tmtcpacket/pus/tm/PusTmMinimal.cpp index f36cfc2a..a389551c 100644 --- a/src/fsfw/tmtcpacket/pus/tm/PusTmMinimal.cpp +++ b/src/fsfw/tmtcpacket/pus/tm/PusTmMinimal.cpp @@ -42,8 +42,8 @@ uint16_t PusTmMinimal::getDestId() { return 0; } void PusTmMinimal::setApid(uint16_t apid) { /* TODO: Implement. Maybe provide low level function to do this */ } -const uint8_t* PusTmMinimal::getUserData(size_t& userDataLen_) { - userDataLen_ = userDataLen; +size_t PusTmMinimal::getUserDataLen() const { return userDataLen; } + +const uint8_t* PusTmMinimal::getUserData() const { return reinterpret_cast(&tmData->rest); } -TimeStamperIF* PusTmMinimal::getTimestamper() { return nullptr; } diff --git a/src/fsfw/tmtcpacket/pus/tm/PusTmMinimal.h b/src/fsfw/tmtcpacket/pus/tm/PusTmMinimal.h index 06ed4aff..7bfae4f2 100644 --- a/src/fsfw/tmtcpacket/pus/tm/PusTmMinimal.h +++ b/src/fsfw/tmtcpacket/pus/tm/PusTmMinimal.h @@ -73,8 +73,8 @@ class PusTmMinimal : public PusTmIF, public RawUserDataReaderIF, public Redirect uint8_t getScTimeRefStatus() override; uint16_t getMessageTypeCounter() override; uint16_t getDestId() override; - const uint8_t* getUserData(size_t& userDataLen) override; - TimeStamperIF* getTimestamper() override; + const uint8_t* getUserData() const override; + size_t getUserDataLen() const override; protected: /** diff --git a/src/fsfw/tmtcpacket/pus/tm/PusTmReader.cpp b/src/fsfw/tmtcpacket/pus/tm/PusTmReader.cpp index d010512a..cb30de05 100644 --- a/src/fsfw/tmtcpacket/pus/tm/PusTmReader.cpp +++ b/src/fsfw/tmtcpacket/pus/tm/PusTmReader.cpp @@ -1,3 +1,83 @@ -// -// Created by rmueller on 7/19/22. -// +#include "PusTmReader.h" + +#include "fsfw/globalfunctions/CRC.h" + +PusTmReader::PusTmReader(TimeReaderIF *timeReader) : timeReader(timeReader) {} + +PusTmReader::PusTmReader(const uint8_t *data, size_t size) { setReadOnlyData(data, size); } + +PusTmReader::PusTmReader(TimeReaderIF *timeReader, const uint8_t *data, size_t size) + : PusTmReader(timeReader) { + setReadOnlyData(data, size); +} + +ReturnValue_t PusTmReader::parseData() { + // Time reader is required to read the time stamp length at run-time + if (pointers.spHeaderStart == nullptr or spReader.isNull() or timeReader == nullptr) { + return HasReturnvaluesIF::RETURN_FAILED; + } + ReturnValue_t result = spReader.checkSize(); + if (result != HasReturnvaluesIF::RETURN_OK) { + return result; + } + if (spReader.getBufSize() < PusTmIF::MIN_SIZE) { + return SerializeIF::STREAM_TOO_SHORT; + } + + size_t currentOffset = SpacePacketReader::getHeaderLen(); + pointers.secHeaderStart = pointers.spHeaderStart + currentOffset; + currentOffset += PusTmIF::MIN_SEC_HEADER_LEN; + size_t minTimestampLen = spReader.getBufSize() - currentOffset; + result = timeReader->readTimeStamp(pointers.secHeaderStart + PusTmIF::MIN_SEC_HEADER_LEN, + minTimestampLen); + if (result != HasReturnvaluesIF::RETURN_OK) { + return result; + } + size_t timestampLen = timeReader->getTimestampLen(); + if (currentOffset + timestampLen > spReader.getBufSize()) { + return SerializeIF::STREAM_TOO_SHORT; + } + currentOffset += timestampLen; + pointers.userDataStart = pointers.spHeaderStart + currentOffset; + sourceDataLen = spReader.getFullPacketLen() - currentOffset - sizeof(ecss::PusChecksumT); + currentOffset += sourceDataLen; + pointers.crcStart = pointers.spHeaderStart + currentOffset; + uint16_t crc16 = CRC::crc16ccitt(spReader.getFullData(), getFullPacketLen()); + if (crc16 != 0) { + // Checksum failure + return PusIF::INVALID_CRC_16; + } + return HasReturnvaluesIF::RETURN_OK; +} +const uint8_t *PusTmReader::getFullData() { return spReader.getFullData(); } + +ReturnValue_t PusTmReader::setReadOnlyData(const uint8_t *data, size_t size) { + return setData(const_cast(data), size, nullptr); +} + +ReturnValue_t PusTmReader::setData(uint8_t *dataPtr, size_t size, void *args) { + pointers.spHeaderStart = dataPtr; + return spReader.setReadOnlyData(dataPtr, size); +} + +uint16_t PusTmReader::getPacketIdRaw() const { return spReader.getPacketIdRaw(); } +uint16_t PusTmReader::getPacketSeqCtrlRaw() const { return spReader.getPacketSeqCtrlRaw(); } +uint16_t PusTmReader::getPacketDataLen() const { return spReader.getPacketDataLen(); } +uint8_t PusTmReader::getPusVersion() const { return (pointers.secHeaderStart[0] >> 4) & 0b1111; } +uint8_t PusTmReader::getScTimeRefStatus() { return pointers.secHeaderStart[0] & 0b1111; } +uint8_t PusTmReader::getService() const { return pointers.secHeaderStart[1]; } +uint8_t PusTmReader::getSubService() const { return pointers.secHeaderStart[2]; } +const uint8_t *PusTmReader::getUserData() const { return pointers.userDataStart; } +size_t PusTmReader::getUserDataLen() const { return sourceDataLen; } + +uint16_t PusTmReader::getMessageTypeCounter() { + return (pointers.secHeaderStart[3] << 8) | pointers.secHeaderStart[4]; +} + +uint16_t PusTmReader::getDestId() { + return (pointers.secHeaderStart[5] << 8) | pointers.secHeaderStart[6]; +} + +void PusTmReader::setTimeReader(TimeReaderIF *timeReader_) { timeReader = timeReader_; } + +TimeReaderIF *PusTmReader::getTimeReader() { return timeReader; } diff --git a/src/fsfw/tmtcpacket/pus/tm/PusTmReader.h b/src/fsfw/tmtcpacket/pus/tm/PusTmReader.h index 47eff293..6eda4e51 100644 --- a/src/fsfw/tmtcpacket/pus/tm/PusTmReader.h +++ b/src/fsfw/tmtcpacket/pus/tm/PusTmReader.h @@ -1,7 +1,47 @@ #ifndef FSFW_TMTCPACKET_PUSTMREADER_H #define FSFW_TMTCPACKET_PUSTMREADER_H +#include "fsfw/timemanager/TimeReaderIF.h" +#include "fsfw/tmtcpacket/ReadablePacketIF.h" +#include "fsfw/tmtcpacket/RedirectableDataPointerIF.h" +#include "fsfw/tmtcpacket/ccsds/SpacePacketReader.h" +#include "fsfw/tmtcpacket/pus/RawUserDataReaderIF.h" #include "fsfw/tmtcpacket/pus/tm/PusTmIF.h" -class PusTmReader : public PusTmIF {}; +class PusTmReader : public PusTmIF, + public RawUserDataReaderIF, + public ReadablePacketIF, + public RedirectableDataPointerIF { + public: + explicit PusTmReader(TimeReaderIF* timeReader); + PusTmReader(const uint8_t* data, size_t size); + PusTmReader(TimeReaderIF* timeReader, const uint8_t* data, size_t size); + + ReturnValue_t parseData(); + const uint8_t* getFullData() override; + + void setTimeReader(TimeReaderIF* timeReader); + TimeReaderIF* getTimeReader(); + ReturnValue_t setReadOnlyData(const uint8_t* data, size_t size); + [[nodiscard]] uint16_t getPacketIdRaw() const override; + [[nodiscard]] uint16_t getPacketSeqCtrlRaw() 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() const override; + size_t getUserDataLen() const override; + uint8_t getScTimeRefStatus() override; + uint16_t getMessageTypeCounter() override; + uint16_t getDestId() override; + + private: + ReturnValue_t setData(uint8_t* dataPtr, size_t size, void* args) override; + + SpacePacketReader spReader{}; + size_t sourceDataLen = 0; + TimeReaderIF* timeReader{}; + ecss::PusPointers pointers{}; +}; + #endif // FSFW_TMTCPACKET_PUSTMREADER_H diff --git a/src/fsfw/tmtcpacket/pus/tm/TmPacketPusC.cpp b/src/fsfw/tmtcpacket/pus/tm/TmPacketPusC.cpp index 7ae6de82..5c35c540 100644 --- a/src/fsfw/tmtcpacket/pus/tm/TmPacketPusC.cpp +++ b/src/fsfw/tmtcpacket/pus/tm/TmPacketPusC.cpp @@ -2,7 +2,7 @@ #include -#include "../definitions.h" +#include "../defs.h" #include "TmPacketBase.h" #include "fsfw/globalfunctions/CRC.h" #include "fsfw/globalfunctions/arrayprinter.h" diff --git a/src/fsfw/tmtcservices/CommandingServiceBase.cpp b/src/fsfw/tmtcservices/CommandingServiceBase.cpp index 8aa5dbce..d8ac88e7 100644 --- a/src/fsfw/tmtcservices/CommandingServiceBase.cpp +++ b/src/fsfw/tmtcservices/CommandingServiceBase.cpp @@ -251,8 +251,18 @@ void CommandingServiceBase::handleRequestQueue() { result = tcStore->getData(message.getStorageId(), &dataPtr, &dataLen); if (result != HasReturnvaluesIF::RETURN_OK) { // TODO: Warning? + continue; + } + result = tcReader.setReadOnlyData(dataPtr, dataLen); + if (result != HasReturnvaluesIF::RETURN_OK) { + // TODO: Warning? + continue; + } + result = tcReader.parseData(); + if (result != HasReturnvaluesIF::RETURN_OK) { + // TODO: Warning? + continue; } - tcReader.setReadOnlyData(dataPtr, dataLen); if ((tcReader.getSubService() == 0) or (isValidSubservice(tcReader.getSubService()) != RETURN_OK)) { @@ -260,10 +270,8 @@ void CommandingServiceBase::handleRequestQueue() { continue; } - size_t appDataLen = 0; - const uint8_t* appData = tcReader.getUserData(appDataLen); - result = - getMessageQueueAndObject(tcReader.getSubService(), appData, appDataLen, &queue, &objectId); + result = getMessageQueueAndObject(tcReader.getSubService(), tcReader.getUserData(), + tcReader.getUserDataLen(), &queue, &objectId); if (result != HasReturnvaluesIF::RETURN_OK) { rejectPacket(tc_verification::START_FAILURE, address, &tcReader, result); continue; @@ -332,10 +340,9 @@ void CommandingServiceBase::startExecution(store_address_t storeId, PusTcReader* return; } iter->second.subservice = storedPacket->getSubService(); - size_t appDataLen = 0; - const uint8_t* appData = storedPacket->getUserData(appDataLen); - result = prepareCommand(&command, iter->second.subservice, appData, appDataLen, - &iter->second.state, iter->second.objectId); + result = + prepareCommand(&command, iter->second.subservice, storedPacket->getUserData(), + storedPacket->getUserDataLen(), &iter->second.state, iter->second.objectId); ReturnValue_t sendResult = RETURN_OK; switch (result) { @@ -401,7 +408,16 @@ void CommandingServiceBase::checkAndExecuteFifo(CommandMapIter& iter) { size_t dataLen = 0; ReturnValue_t result = tcStore->getData(address, &dataPtr, &dataLen); if (result == HasReturnvaluesIF::RETURN_OK) { - tcReader.setReadOnlyData(dataPtr, dataLen); + result = tcReader.setReadOnlyData(dataPtr, dataLen); + if (result != HasReturnvaluesIF::RETURN_OK) { + // TODO: Warning? + return; + } + result = tcReader.parseData(); + if (result != HasReturnvaluesIF::RETURN_OK) { + // TODO: Warning? + return; + } startExecution(address, &tcReader, iter); } else { // TODO: Warning? diff --git a/src/fsfw/tmtcservices/PusServiceBase.cpp b/src/fsfw/tmtcservices/PusServiceBase.cpp index e924ba67..5b985ad6 100644 --- a/src/fsfw/tmtcservices/PusServiceBase.cpp +++ b/src/fsfw/tmtcservices/PusServiceBase.cpp @@ -47,39 +47,51 @@ void PusServiceBase::handleRequestQueue() { // << std::endl; #endif // } - - if (status == RETURN_OK) { - const uint8_t* dataPtr; - size_t dataLen = 0; - result = ipcStore->getData(message.getStorageId(), &dataPtr, &dataLen); - if (result != HasReturnvaluesIF::RETURN_OK) { - // TODO: Warning? - } - - currentPacket.setReadOnlyData(dataPtr, dataLen); - - result = this->handleRequest(currentPacket.getSubService()); - if (result == RETURN_OK) { - this->verifyReporter.sendSuccessReport(tc_verification::COMPLETION_SUCCESS, - &this->currentPacket); - } else { - this->verifyReporter.sendFailureReport(tc_verification::COMPLETION_FAILURE, - &this->currentPacket, result, 0, errorParameter1, - errorParameter2); - } - ipcStore->deleteData(message.getStorageId()); - errorParameter1 = 0; - errorParameter2 = 0; - } else if (status == MessageQueueIF::EMPTY) { + if (status == MessageQueueIF::EMPTY) { status = RETURN_OK; break; - } else { + } else if (status != HasReturnvaluesIF::RETURN_OK) { #if FSFW_CPP_OSTREAM_ENABLED == 1 sif::error << "PusServiceBase::performOperation: Service " << this->serviceId << ": Error receiving packet. Code: " << std::hex << status << std::dec << std::endl; +#else + sif::printError( + "PusServiceBase::performOperation: Service %d. Error receiving packet. Code: %04x\n", + serviceId, status); #endif + break; } + const uint8_t* dataPtr; + size_t dataLen = 0; + result = ipcStore->getData(message.getStorageId(), &dataPtr, &dataLen); + if (result != HasReturnvaluesIF::RETURN_OK) { + // TODO: Warning? + continue; + } + + result = currentPacket.setReadOnlyData(dataPtr, dataLen); + if (result != HasReturnvaluesIF::RETURN_OK) { + // TODO: Warning? + continue; + } + result = currentPacket.parseData(); + if (result != HasReturnvaluesIF::RETURN_OK) { + // TODO: Warning? + continue; + } + result = this->handleRequest(currentPacket.getSubService()); + if (result == RETURN_OK) { + this->verifyReporter.sendSuccessReport(tc_verification::COMPLETION_SUCCESS, + &this->currentPacket); + } else { + this->verifyReporter.sendFailureReport(tc_verification::COMPLETION_FAILURE, + &this->currentPacket, result, 0, errorParameter1, + errorParameter2); + } + ipcStore->deleteData(message.getStorageId()); + errorParameter1 = 0; + errorParameter2 = 0; } } -- 2.43.0 From e5ee96259d0e605a16472c25fa9ea96d0605e2ec Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Thu, 21 Jul 2022 13:48:58 +0200 Subject: [PATCH 017/108] some fixes --- src/fsfw/pus/Service17Test.cpp | 2 +- .../pus/Service1TelecommandVerification.cpp | 2 +- src/fsfw/pus/Service5EventReporting.cpp | 2 +- src/fsfw/pus/servicepackets/Service1Packets.h | 8 +- src/fsfw/tcdistribution/PusDistributor.cpp | 4 +- src/fsfw/tmtcpacket/pus/tc.h | 3 +- src/fsfw/tmtcpacket/pus/tc/PusTcReader.cpp | 16 ++- src/fsfw/tmtcpacket/pus/tc/PusTcReader.h | 5 +- src/fsfw/tmtcpacket/pus/tm/PusTmReader.cpp | 81 ++++++------ src/fsfw/tmtcpacket/pus/tm/PusTmReader.h | 5 +- src/fsfw/tmtcservices/CMakeLists.txt | 4 +- .../tmtcservices/CommandingServiceBase.cpp | 116 +++++++----------- src/fsfw/tmtcservices/CommandingServiceBase.h | 4 +- src/fsfw/tmtcservices/PusServiceBase.cpp | 37 ++---- src/fsfw/tmtcservices/PusServiceBase.h | 4 +- src/fsfw/tmtcservices/VerificationCodes.h | 10 +- .../tmtcservices/VerificationReporter.cpp | 4 +- src/fsfw/tmtcservices/VerificationReporter.h | 6 +- src/fsfw/tmtcservices/tcHelpers.cpp | 16 +++ src/fsfw/tmtcservices/tcHelpers.h | 15 +++ src/fsfw/tmtcservices/tmHelpers.cpp | 10 ++ .../{sendAndStoreHelper.h => tmHelpers.h} | 15 +-- 22 files changed, 195 insertions(+), 174 deletions(-) create mode 100644 src/fsfw/tmtcservices/tcHelpers.cpp create mode 100644 src/fsfw/tmtcservices/tcHelpers.h create mode 100644 src/fsfw/tmtcservices/tmHelpers.cpp rename src/fsfw/tmtcservices/{sendAndStoreHelper.h => tmHelpers.h} (77%) diff --git a/src/fsfw/pus/Service17Test.cpp b/src/fsfw/pus/Service17Test.cpp index 7d13af06..52319de1 100644 --- a/src/fsfw/pus/Service17Test.cpp +++ b/src/fsfw/pus/Service17Test.cpp @@ -3,7 +3,7 @@ #include "fsfw/FSFW.h" #include "fsfw/objectmanager/ObjectManager.h" #include "fsfw/objectmanager/SystemObject.h" -#include "fsfw/tmtcservices/sendAndStoreHelper.h" +#include "fsfw/tmtcservices/tmHelpers.h" Service17Test::Service17Test(object_id_t objectId, uint16_t apid, uint8_t serviceId) : PusServiceBase(objectId, apid, serviceId), diff --git a/src/fsfw/pus/Service1TelecommandVerification.cpp b/src/fsfw/pus/Service1TelecommandVerification.cpp index 5c49111e..4b326096 100644 --- a/src/fsfw/pus/Service1TelecommandVerification.cpp +++ b/src/fsfw/pus/Service1TelecommandVerification.cpp @@ -6,7 +6,7 @@ #include "fsfw/tmtcpacket/pus/tm/TmPacketStored.h" #include "fsfw/tmtcservices/AcceptsTelemetryIF.h" #include "fsfw/tmtcservices/PusVerificationReport.h" -#include "fsfw/tmtcservices/sendAndStoreHelper.h" +#include "fsfw/tmtcservices/tmHelpers.h" Service1TelecommandVerification::Service1TelecommandVerification(object_id_t objectId, uint16_t apid, uint8_t serviceId, diff --git a/src/fsfw/pus/Service5EventReporting.cpp b/src/fsfw/pus/Service5EventReporting.cpp index d88e58b8..a0cbc316 100644 --- a/src/fsfw/pus/Service5EventReporting.cpp +++ b/src/fsfw/pus/Service5EventReporting.cpp @@ -6,7 +6,7 @@ #include "fsfw/pus/servicepackets/Service5Packets.h" #include "fsfw/serviceinterface/ServiceInterface.h" #include "fsfw/tmtcpacket/pus/tm/TmPacketStored.h" -#include "fsfw/tmtcservices/sendAndStoreHelper.h" +#include "fsfw/tmtcservices/tmHelpers.h" Service5EventReporting::Service5EventReporting(object_id_t objectId, uint16_t apid, uint8_t serviceId, size_t maxNumberReportsPerCycle, diff --git a/src/fsfw/pus/servicepackets/Service1Packets.h b/src/fsfw/pus/servicepackets/Service1Packets.h index df70f670..dce7657a 100644 --- a/src/fsfw/pus/servicepackets/Service1Packets.h +++ b/src/fsfw/pus/servicepackets/Service1Packets.h @@ -50,7 +50,7 @@ class FailureReport : public SerializeIF { //!< [EXPORT] : [SUBSERVICE] 2, 4, 6 if (result != HasReturnvaluesIF::RETURN_OK) { return result; } - if (failureSubtype == tc_verification::PROGRESS_FAILURE) { + if (failureSubtype == tcverif::PROGRESS_FAILURE) { result = SerializeAdapter::serialize(&stepNumber, buffer, size, maxSize, streamEndianness); if (result != HasReturnvaluesIF::RETURN_OK) { return result; @@ -73,7 +73,7 @@ class FailureReport : public SerializeIF { //!< [EXPORT] : [SUBSERVICE] 2, 4, 6 size_t size = 0; size += SerializeAdapter::getSerializedSize(&packetId); size += sizeof(packetSequenceControl); - if (failureSubtype == tc_verification::PROGRESS_FAILURE) { + if (failureSubtype == tcverif::PROGRESS_FAILURE) { size += SerializeAdapter::getSerializedSize(&stepNumber); } size += SerializeAdapter::getSerializedSize(&errorCode); @@ -130,7 +130,7 @@ class SuccessReport : public SerializeIF { //!< [EXPORT] : [SUBSERVICE] 1, 3, 5 if (result != HasReturnvaluesIF::RETURN_OK) { return result; } - if (subtype == tc_verification::PROGRESS_SUCCESS) { + if (subtype == tcverif::PROGRESS_SUCCESS) { result = SerializeAdapter::serialize(&stepNumber, buffer, size, maxSize, streamEndianness); if (result != HasReturnvaluesIF::RETURN_OK) { return result; @@ -143,7 +143,7 @@ class SuccessReport : public SerializeIF { //!< [EXPORT] : [SUBSERVICE] 1, 3, 5 size_t size = 0; size += SerializeAdapter::getSerializedSize(&packetId); size += sizeof(packetSequenceControl); - if (subtype == tc_verification::PROGRESS_SUCCESS) { + if (subtype == tcverif::PROGRESS_SUCCESS) { size += SerializeAdapter::getSerializedSize(&stepNumber); } return size; diff --git a/src/fsfw/tcdistribution/PusDistributor.cpp b/src/fsfw/tcdistribution/PusDistributor.cpp index 687c5f00..bac932d5 100644 --- a/src/fsfw/tcdistribution/PusDistributor.cpp +++ b/src/fsfw/tcdistribution/PusDistributor.cpp @@ -121,13 +121,13 @@ ReturnValue_t PusDistributor::callbackAfterSending(ReturnValue_t queueStatus) { tcStatus = queueStatus; } if (tcStatus != RETURN_OK) { - this->verifyChannel.sendFailureReport(tc_verification::ACCEPTANCE_FAILURE, &reader, tcStatus); + this->verifyChannel.sendFailureReport(tcverif::ACCEPTANCE_FAILURE, &reader, tcStatus); // A failed packet is deleted immediately after reporting, // otherwise it will block memory. store->deleteData(currentMessage.getStorageId()); return RETURN_FAILED; } else { - this->verifyChannel.sendSuccessReport(tc_verification::ACCEPTANCE_SUCCESS, &reader); + this->verifyChannel.sendSuccessReport(tcverif::ACCEPTANCE_SUCCESS, &reader); return RETURN_OK; } } diff --git a/src/fsfw/tmtcpacket/pus/tc.h b/src/fsfw/tmtcpacket/pus/tc.h index 33c6352f..e5e5f9f7 100644 --- a/src/fsfw/tmtcpacket/pus/tc.h +++ b/src/fsfw/tmtcpacket/pus/tc.h @@ -1,6 +1,7 @@ #ifndef FSFW_TMTCPACKET_PUS_TC_H_ #define FSFW_TMTCPACKET_PUS_TC_H_ -#include "tc/TcPacketPus.h" +#include "tc/PusTcCreator.h" +#include "tc/PusTcReader.h" #endif /* FSFW_TMTCPACKET_PUS_TC_H_ */ diff --git a/src/fsfw/tmtcpacket/pus/tc/PusTcReader.cpp b/src/fsfw/tmtcpacket/pus/tc/PusTcReader.cpp index b9e5e00f..c96bed65 100644 --- a/src/fsfw/tmtcpacket/pus/tc/PusTcReader.cpp +++ b/src/fsfw/tmtcpacket/pus/tc/PusTcReader.cpp @@ -11,7 +11,11 @@ PusTcReader::PusTcReader(const uint8_t* data, size_t size) { setReadOnlyData(dat PusTcReader::~PusTcReader() = default; -ReturnValue_t PusTcReader::parseData() { +ReturnValue_t PusTcReader::parseDataWithCrcCheck() { return parseData(true); } + +ReturnValue_t PusTcReader::parseDataWithoutCrcCheck() { return parseData(false); } + +ReturnValue_t PusTcReader::parseData(bool withCrc) { if (pointers.spHeaderStart == nullptr or spReader.isNull()) { return HasReturnvaluesIF::RETURN_FAILED; } @@ -31,10 +35,12 @@ ReturnValue_t PusTcReader::parseData() { pointers.userDataStart = pointers.spHeaderStart + currentOffset; appDataSize = spReader.getFullPacketLen() - currentOffset - sizeof(ecss::PusChecksumT); pointers.crcStart = pointers.userDataStart + appDataSize; - uint16_t crc16 = CRC::crc16ccitt(spReader.getFullData(), getFullPacketLen()); - if (crc16 != 0) { - // Checksum failure - return PusIF::INVALID_CRC_16; + if (withCrc) { + uint16_t crc16 = CRC::crc16ccitt(spReader.getFullData(), getFullPacketLen()); + if (crc16 != 0) { + // Checksum failure + return PusIF::INVALID_CRC_16; + } } return HasReturnvaluesIF::RETURN_OK; } diff --git a/src/fsfw/tmtcpacket/pus/tc/PusTcReader.h b/src/fsfw/tmtcpacket/pus/tc/PusTcReader.h index e79f8b61..528e0ca5 100644 --- a/src/fsfw/tmtcpacket/pus/tc/PusTcReader.h +++ b/src/fsfw/tmtcpacket/pus/tc/PusTcReader.h @@ -34,7 +34,9 @@ class PusTcReader : public PusTcIF, */ PusTcReader(const uint8_t* setData, size_t size); - ReturnValue_t parseData(); + ReturnValue_t parseDataWithCrcCheck(); + ReturnValue_t parseDataWithoutCrcCheck(); + /** * This is the empty default destructor. */ @@ -70,6 +72,7 @@ class PusTcReader : public PusTcIF, * @param p_data A pointer to another PUS Telecommand Packet. */ ReturnValue_t setData(uint8_t* pData, size_t size, void* args) override; + ReturnValue_t parseData(bool withCrc); SpacePacketReader spReader; ecss::PusPointers pointers{}; diff --git a/src/fsfw/tmtcpacket/pus/tm/PusTmReader.cpp b/src/fsfw/tmtcpacket/pus/tm/PusTmReader.cpp index cb30de05..024d6ac8 100644 --- a/src/fsfw/tmtcpacket/pus/tm/PusTmReader.cpp +++ b/src/fsfw/tmtcpacket/pus/tm/PusTmReader.cpp @@ -11,44 +11,10 @@ PusTmReader::PusTmReader(TimeReaderIF *timeReader, const uint8_t *data, size_t s setReadOnlyData(data, size); } -ReturnValue_t PusTmReader::parseData() { - // Time reader is required to read the time stamp length at run-time - if (pointers.spHeaderStart == nullptr or spReader.isNull() or timeReader == nullptr) { - return HasReturnvaluesIF::RETURN_FAILED; - } - ReturnValue_t result = spReader.checkSize(); - if (result != HasReturnvaluesIF::RETURN_OK) { - return result; - } - if (spReader.getBufSize() < PusTmIF::MIN_SIZE) { - return SerializeIF::STREAM_TOO_SHORT; - } +ReturnValue_t PusTmReader::parseDataWithCrcCheck() { return parseData(true); } + +ReturnValue_t PusTmReader::parseDataWithoutCrcCheck() { return parseData(false); } - size_t currentOffset = SpacePacketReader::getHeaderLen(); - pointers.secHeaderStart = pointers.spHeaderStart + currentOffset; - currentOffset += PusTmIF::MIN_SEC_HEADER_LEN; - size_t minTimestampLen = spReader.getBufSize() - currentOffset; - result = timeReader->readTimeStamp(pointers.secHeaderStart + PusTmIF::MIN_SEC_HEADER_LEN, - minTimestampLen); - if (result != HasReturnvaluesIF::RETURN_OK) { - return result; - } - size_t timestampLen = timeReader->getTimestampLen(); - if (currentOffset + timestampLen > spReader.getBufSize()) { - return SerializeIF::STREAM_TOO_SHORT; - } - currentOffset += timestampLen; - pointers.userDataStart = pointers.spHeaderStart + currentOffset; - sourceDataLen = spReader.getFullPacketLen() - currentOffset - sizeof(ecss::PusChecksumT); - currentOffset += sourceDataLen; - pointers.crcStart = pointers.spHeaderStart + currentOffset; - uint16_t crc16 = CRC::crc16ccitt(spReader.getFullData(), getFullPacketLen()); - if (crc16 != 0) { - // Checksum failure - return PusIF::INVALID_CRC_16; - } - return HasReturnvaluesIF::RETURN_OK; -} const uint8_t *PusTmReader::getFullData() { return spReader.getFullData(); } ReturnValue_t PusTmReader::setReadOnlyData(const uint8_t *data, size_t size) { @@ -81,3 +47,44 @@ uint16_t PusTmReader::getDestId() { void PusTmReader::setTimeReader(TimeReaderIF *timeReader_) { timeReader = timeReader_; } TimeReaderIF *PusTmReader::getTimeReader() { return timeReader; } + +ReturnValue_t PusTmReader::parseData(bool crcCheck) { + // Time reader is required to read the time stamp length at run-time + if (pointers.spHeaderStart == nullptr or spReader.isNull() or timeReader == nullptr) { + return HasReturnvaluesIF::RETURN_FAILED; + } + ReturnValue_t result = spReader.checkSize(); + if (result != HasReturnvaluesIF::RETURN_OK) { + return result; + } + if (spReader.getBufSize() < PusTmIF::MIN_SIZE) { + return SerializeIF::STREAM_TOO_SHORT; + } + + size_t currentOffset = SpacePacketReader::getHeaderLen(); + pointers.secHeaderStart = pointers.spHeaderStart + currentOffset; + currentOffset += PusTmIF::MIN_SEC_HEADER_LEN; + size_t minTimestampLen = spReader.getBufSize() - currentOffset; + result = timeReader->readTimeStamp(pointers.secHeaderStart + PusTmIF::MIN_SEC_HEADER_LEN, + minTimestampLen); + if (result != HasReturnvaluesIF::RETURN_OK) { + return result; + } + size_t timestampLen = timeReader->getTimestampLen(); + if (currentOffset + timestampLen > spReader.getBufSize()) { + return SerializeIF::STREAM_TOO_SHORT; + } + currentOffset += timestampLen; + pointers.userDataStart = pointers.spHeaderStart + currentOffset; + sourceDataLen = spReader.getFullPacketLen() - currentOffset - sizeof(ecss::PusChecksumT); + currentOffset += sourceDataLen; + pointers.crcStart = pointers.spHeaderStart + currentOffset; + if (crcCheck) { + uint16_t crc16 = CRC::crc16ccitt(spReader.getFullData(), getFullPacketLen()); + if (crc16 != 0) { + // Checksum failure + return PusIF::INVALID_CRC_16; + } + } + return HasReturnvaluesIF::RETURN_OK; +} diff --git a/src/fsfw/tmtcpacket/pus/tm/PusTmReader.h b/src/fsfw/tmtcpacket/pus/tm/PusTmReader.h index 6eda4e51..1d91eb95 100644 --- a/src/fsfw/tmtcpacket/pus/tm/PusTmReader.h +++ b/src/fsfw/tmtcpacket/pus/tm/PusTmReader.h @@ -17,7 +17,8 @@ class PusTmReader : public PusTmIF, PusTmReader(const uint8_t* data, size_t size); PusTmReader(TimeReaderIF* timeReader, const uint8_t* data, size_t size); - ReturnValue_t parseData(); + ReturnValue_t parseDataWithoutCrcCheck(); + ReturnValue_t parseDataWithCrcCheck(); const uint8_t* getFullData() override; void setTimeReader(TimeReaderIF* timeReader); @@ -37,7 +38,7 @@ class PusTmReader : public PusTmIF, private: ReturnValue_t setData(uint8_t* dataPtr, size_t size, void* args) override; - + ReturnValue_t parseData(bool crcCheck); SpacePacketReader spReader{}; size_t sourceDataLen = 0; TimeReaderIF* timeReader{}; diff --git a/src/fsfw/tmtcservices/CMakeLists.txt b/src/fsfw/tmtcservices/CMakeLists.txt index a26faf7f..42ac6128 100644 --- a/src/fsfw/tmtcservices/CMakeLists.txt +++ b/src/fsfw/tmtcservices/CMakeLists.txt @@ -8,4 +8,6 @@ target_sources( VerificationReporter.cpp SpacePacketParser.cpp TmStoreHelper.cpp - TmSendHelper.cpp) + TmSendHelper.cpp + tcHelpers.cpp + tmHelpers.cpp) diff --git a/src/fsfw/tmtcservices/CommandingServiceBase.cpp b/src/fsfw/tmtcservices/CommandingServiceBase.cpp index d8ac88e7..897dd962 100644 --- a/src/fsfw/tmtcservices/CommandingServiceBase.cpp +++ b/src/fsfw/tmtcservices/CommandingServiceBase.cpp @@ -8,7 +8,8 @@ #include "fsfw/tmtcpacket/pus/tm.h" #include "fsfw/tmtcservices/AcceptsTelemetryIF.h" #include "fsfw/tmtcservices/TmTcMessage.h" -#include "fsfw/tmtcservices/sendAndStoreHelper.h" +#include "fsfw/tmtcservices/tcHelpers.h" +#include "fsfw/tmtcservices/tmHelpers.h" object_id_t CommandingServiceBase::defaultPacketSource = objects::NO_OBJECT; object_id_t CommandingServiceBase::defaultPacketDestination = objects::NO_OBJECT; @@ -176,12 +177,12 @@ void CommandingServiceBase::handleCommandMessage(CommandMessage* reply) { default: if (isStep) { verificationReporter.sendFailureReport( - tc_verification::PROGRESS_FAILURE, iter->second.tcInfo.ackFlags, - iter->second.tcInfo.tcPacketId, iter->second.tcInfo.tcSequenceControl, result, - ++iter->second.step, failureParameter1, failureParameter2); + tcverif::PROGRESS_FAILURE, iter->second.tcInfo.ackFlags, iter->second.tcInfo.tcPacketId, + iter->second.tcInfo.tcSequenceControl, result, ++iter->second.step, failureParameter1, + failureParameter2); } else { verificationReporter.sendFailureReport( - tc_verification::COMPLETION_FAILURE, iter->second.tcInfo.ackFlags, + tcverif::COMPLETION_FAILURE, iter->second.tcInfo.ackFlags, iter->second.tcInfo.tcPacketId, iter->second.tcInfo.tcSequenceControl, result, 0, failureParameter1, failureParameter2); } @@ -208,28 +209,27 @@ void CommandingServiceBase::handleReplyHandlerResult(ReturnValue_t result, Comma if (sendResult == RETURN_OK) { if (isStep and result != NO_STEP_MESSAGE) { verificationReporter.sendSuccessReport( - tc_verification::PROGRESS_SUCCESS, iter->second.tcInfo.ackFlags, - iter->second.tcInfo.tcPacketId, iter->second.tcInfo.tcSequenceControl, - ++iter->second.step); + tcverif::PROGRESS_SUCCESS, iter->second.tcInfo.ackFlags, iter->second.tcInfo.tcPacketId, + iter->second.tcInfo.tcSequenceControl, ++iter->second.step); } else { verificationReporter.sendSuccessReport( - tc_verification::COMPLETION_SUCCESS, iter->second.tcInfo.ackFlags, - iter->second.tcInfo.tcPacketId, iter->second.tcInfo.tcSequenceControl, 0); + tcverif::COMPLETION_SUCCESS, iter->second.tcInfo.ackFlags, iter->second.tcInfo.tcPacketId, + iter->second.tcInfo.tcSequenceControl, 0); checkAndExecuteFifo(iter); } } else { if (isStep) { nextCommand->clearCommandMessage(); verificationReporter.sendFailureReport( - tc_verification::PROGRESS_FAILURE, iter->second.tcInfo.ackFlags, - iter->second.tcInfo.tcPacketId, iter->second.tcInfo.tcSequenceControl, sendResult, - ++iter->second.step, failureParameter1, failureParameter2); + tcverif::PROGRESS_FAILURE, iter->second.tcInfo.ackFlags, iter->second.tcInfo.tcPacketId, + iter->second.tcInfo.tcSequenceControl, sendResult, ++iter->second.step, failureParameter1, + failureParameter2); } else { nextCommand->clearCommandMessage(); verificationReporter.sendFailureReport( - tc_verification::COMPLETION_FAILURE, iter->second.tcInfo.ackFlags, - iter->second.tcInfo.tcPacketId, iter->second.tcInfo.tcSequenceControl, sendResult, 0, - failureParameter1, failureParameter2); + tcverif::COMPLETION_FAILURE, iter->second.tcInfo.ackFlags, iter->second.tcInfo.tcPacketId, + iter->second.tcInfo.tcSequenceControl, sendResult, 0, failureParameter1, + failureParameter2); } failureParameter1 = 0; failureParameter2 = 0; @@ -245,35 +245,22 @@ void CommandingServiceBase::handleRequestQueue() { object_id_t objectId; for (result = requestQueue->receiveMessage(&message); result == RETURN_OK; result = requestQueue->receiveMessage(&message)) { - address = message.getStorageId(); - const uint8_t* dataPtr; - size_t dataLen = 0; - result = tcStore->getData(message.getStorageId(), &dataPtr, &dataLen); + result = setUpTcReader(message.getStorageId()); if (result != HasReturnvaluesIF::RETURN_OK) { // TODO: Warning? + rejectPacket(tcverif::START_FAILURE, address, &tcReader, result); continue; } - result = tcReader.setReadOnlyData(dataPtr, dataLen); - if (result != HasReturnvaluesIF::RETURN_OK) { - // TODO: Warning? - continue; - } - result = tcReader.parseData(); - if (result != HasReturnvaluesIF::RETURN_OK) { - // TODO: Warning? - continue; - } - if ((tcReader.getSubService() == 0) or (isValidSubservice(tcReader.getSubService()) != RETURN_OK)) { - rejectPacket(tc_verification::START_FAILURE, address, &tcReader, INVALID_SUBSERVICE); + rejectPacket(tcverif::START_FAILURE, address, &tcReader, INVALID_SUBSERVICE); continue; } result = getMessageQueueAndObject(tcReader.getSubService(), tcReader.getUserData(), tcReader.getUserDataLen(), &queue, &objectId); if (result != HasReturnvaluesIF::RETURN_OK) { - rejectPacket(tc_verification::START_FAILURE, address, &tcReader, result); + rejectPacket(tcverif::START_FAILURE, address, &tcReader, result); continue; } @@ -284,16 +271,16 @@ void CommandingServiceBase::handleRequestQueue() { if (iter != commandMap.end()) { result = iter->second.fifo.insert(address); if (result != RETURN_OK) { - rejectPacket(tc_verification::START_FAILURE, address, &tcReader, OBJECT_BUSY); + rejectPacket(tcverif::START_FAILURE, address, &tcReader, OBJECT_BUSY); } } else { CommandInfo newInfo; // Info will be set by startExecution if neccessary newInfo.objectId = objectId; result = commandMap.insert(queue, newInfo, &iter); if (result != RETURN_OK) { - rejectPacket(tc_verification::START_FAILURE, address, &tcReader, BUSY); + rejectPacket(tcverif::START_FAILURE, address, &tcReader, BUSY); } else { - startExecution(address, &tcReader, iter); + startExecution(address, iter); } } } @@ -332,17 +319,12 @@ ReturnValue_t CommandingServiceBase::sendTmPacket(uint8_t subservice, SerializeI return result; } -void CommandingServiceBase::startExecution(store_address_t storeId, PusTcReader* storedPacket, - CommandMapIter iter) { +void CommandingServiceBase::startExecution(store_address_t storeId, CommandMapIter iter) { ReturnValue_t result = RETURN_OK; CommandMessage command; - if (storedPacket == nullptr) { - return; - } - iter->second.subservice = storedPacket->getSubService(); - result = - prepareCommand(&command, iter->second.subservice, storedPacket->getUserData(), - storedPacket->getUserDataLen(), &iter->second.state, iter->second.objectId); + iter->second.subservice = tcReader.getSubService(); + result = prepareCommand(&command, iter->second.subservice, tcReader.getUserData(), + tcReader.getUserDataLen(), &iter->second.state, iter->second.objectId); ReturnValue_t sendResult = RETURN_OK; switch (result) { @@ -353,15 +335,15 @@ void CommandingServiceBase::startExecution(store_address_t storeId, PusTcReader* if (sendResult == RETURN_OK) { Clock::getUptime(&iter->second.uptimeOfStart); iter->second.step = 0; - iter->second.subservice = storedPacket->getSubService(); + iter->second.subservice = tcReader.getSubService(); iter->second.command = command.getCommand(); - iter->second.tcInfo.ackFlags = storedPacket->getAcknowledgeFlags(); - iter->second.tcInfo.tcPacketId = storedPacket->getPacketIdRaw(); - iter->second.tcInfo.tcSequenceControl = storedPacket->getPacketSeqCtrlRaw(); - acceptPacket(tc_verification::START_SUCCESS, storeId, storedPacket); + iter->second.tcInfo.ackFlags = tcReader.getAcknowledgeFlags(); + iter->second.tcInfo.tcPacketId = tcReader.getPacketIdRaw(); + iter->second.tcInfo.tcSequenceControl = tcReader.getPacketSeqCtrlRaw(); + acceptPacket(tcverif::START_SUCCESS, storeId, &tcReader); } else { command.clearCommandMessage(); - rejectPacket(tc_verification::START_FAILURE, storeId, storedPacket, sendResult); + rejectPacket(tcverif::START_FAILURE, storeId, &tcReader, sendResult); checkAndExecuteFifo(iter); } break; @@ -371,17 +353,17 @@ void CommandingServiceBase::startExecution(store_address_t storeId, PusTcReader* sendResult = commandQueue->sendMessage(iter.value->first, &command); } if (sendResult == RETURN_OK) { - verificationReporter.sendSuccessReport(tc_verification::START_SUCCESS, storedPacket); - acceptPacket(tc_verification::COMPLETION_SUCCESS, storeId, storedPacket); + verificationReporter.sendSuccessReport(tcverif::START_SUCCESS, &tcReader); + acceptPacket(tcverif::COMPLETION_SUCCESS, storeId, &tcReader); checkAndExecuteFifo(iter); } else { command.clearCommandMessage(); - rejectPacket(tc_verification::START_FAILURE, storeId, storedPacket, sendResult); + rejectPacket(tcverif::START_FAILURE, storeId, &tcReader, sendResult); checkAndExecuteFifo(iter); } break; default: - rejectPacket(tc_verification::START_FAILURE, storeId, storedPacket, result); + rejectPacket(tcverif::START_FAILURE, storeId, &tcReader, result); checkAndExecuteFifo(iter); break; } @@ -404,23 +386,12 @@ void CommandingServiceBase::checkAndExecuteFifo(CommandMapIter& iter) { if (iter->second.fifo.retrieve(&address) != RETURN_OK) { commandMap.erase(&iter); } else { - const uint8_t* dataPtr; - size_t dataLen = 0; - ReturnValue_t result = tcStore->getData(address, &dataPtr, &dataLen); + ReturnValue_t result = setUpTcReader(address); if (result == HasReturnvaluesIF::RETURN_OK) { - result = tcReader.setReadOnlyData(dataPtr, dataLen); - if (result != HasReturnvaluesIF::RETURN_OK) { - // TODO: Warning? - return; - } - result = tcReader.parseData(); - if (result != HasReturnvaluesIF::RETURN_OK) { - // TODO: Warning? - return; - } - startExecution(address, &tcReader, iter); + startExecution(address, iter); } else { // TODO: Warning? + rejectPacket(tcverif::START_FAILURE, address, &tcReader, result); } } } @@ -440,8 +411,8 @@ void CommandingServiceBase::checkTimeout() { for (iter = commandMap.begin(); iter != commandMap.end(); ++iter) { if ((iter->second.uptimeOfStart + (timeoutSeconds * 1000)) < uptime) { verificationReporter.sendFailureReport( - tc_verification::COMPLETION_FAILURE, iter->second.tcInfo.ackFlags, - iter->second.tcInfo.tcPacketId, iter->second.tcInfo.tcSequenceControl, TIMEOUT); + tcverif::COMPLETION_FAILURE, iter->second.tcInfo.ackFlags, iter->second.tcInfo.tcPacketId, + iter->second.tcInfo.tcSequenceControl, TIMEOUT); checkAndExecuteFifo(iter); } } @@ -452,3 +423,6 @@ void CommandingServiceBase::setTaskIF(PeriodicTaskIF* task_) { executingTask = t void CommandingServiceBase::setCustomTmStore(StorageManagerIF* store) { tmStoreHelper.setTmStore(store); } +ReturnValue_t CommandingServiceBase::setUpTcReader(store_address_t storeId) { + return tc::prepareTcReader(tcStore, storeId, tcReader); +} diff --git a/src/fsfw/tmtcservices/CommandingServiceBase.h b/src/fsfw/tmtcservices/CommandingServiceBase.h index a392fb95..a58a1a93 100644 --- a/src/fsfw/tmtcservices/CommandingServiceBase.h +++ b/src/fsfw/tmtcservices/CommandingServiceBase.h @@ -350,12 +350,14 @@ class CommandingServiceBase : public SystemObject, */ void handleRequestQueue(); + ReturnValue_t setUpTcReader(store_address_t storeId); + void rejectPacket(uint8_t reportId, store_address_t tcStoreId, PusTcReader* tcPacket, ReturnValue_t errorCode); void acceptPacket(uint8_t reportId, store_address_t tcStoreId, PusTcReader* tcPacket); - void startExecution(store_address_t storeId, PusTcReader* storedPacket, CommandMapIter iter); + void startExecution(store_address_t storeId, CommandMapIter iter); void handleCommandMessage(CommandMessage* reply); void handleReplyHandlerResult(ReturnValue_t result, CommandMapIter iter, diff --git a/src/fsfw/tmtcservices/PusServiceBase.cpp b/src/fsfw/tmtcservices/PusServiceBase.cpp index 5b985ad6..e7a0e5b9 100644 --- a/src/fsfw/tmtcservices/PusServiceBase.cpp +++ b/src/fsfw/tmtcservices/PusServiceBase.cpp @@ -7,6 +7,7 @@ #include "fsfw/tmtcservices/AcceptsTelemetryIF.h" #include "fsfw/tmtcservices/PusVerificationReport.h" #include "fsfw/tmtcservices/TmTcMessage.h" +#include "fsfw/tmtcservices/tcHelpers.h" object_id_t PusServiceBase::packetSource = 0; object_id_t PusServiceBase::packetDestination = 0; @@ -62,34 +63,20 @@ void PusServiceBase::handleRequestQueue() { #endif break; } - const uint8_t* dataPtr; - size_t dataLen = 0; - result = ipcStore->getData(message.getStorageId(), &dataPtr, &dataLen); + result = tc::prepareTcReader(tcStore, message.getStorageId(), currentPacket); if (result != HasReturnvaluesIF::RETURN_OK) { - // TODO: Warning? - continue; - } - - result = currentPacket.setReadOnlyData(dataPtr, dataLen); - if (result != HasReturnvaluesIF::RETURN_OK) { - // TODO: Warning? - continue; - } - result = currentPacket.parseData(); - if (result != HasReturnvaluesIF::RETURN_OK) { - // TODO: Warning? + this->verifyReporter.sendFailureReport(tcverif::START_FAILURE, &this->currentPacket, result, + 0, errorParameter1, errorParameter2); continue; } result = this->handleRequest(currentPacket.getSubService()); if (result == RETURN_OK) { - this->verifyReporter.sendSuccessReport(tc_verification::COMPLETION_SUCCESS, - &this->currentPacket); + this->verifyReporter.sendSuccessReport(tcverif::COMPLETION_SUCCESS, &this->currentPacket); } else { - this->verifyReporter.sendFailureReport(tc_verification::COMPLETION_FAILURE, - &this->currentPacket, result, 0, errorParameter1, - errorParameter2); + this->verifyReporter.sendFailureReport(tcverif::COMPLETION_FAILURE, &this->currentPacket, + result, 0, errorParameter1, errorParameter2); } - ipcStore->deleteData(message.getStorageId()); + tcStore->deleteData(message.getStorageId()); errorParameter1 = 0; errorParameter2 = 0; } @@ -116,9 +103,9 @@ ReturnValue_t PusServiceBase::initialize() { } this->requestQueue->setDefaultDestination(destService->getReportReceptionQueue()); distributor->registerService(this); - if (ipcStore == nullptr) { - ipcStore = ObjectManager::instance()->get(objects::IPC_STORE); - if (ipcStore == nullptr) { + if (tcStore == nullptr) { + tcStore = ObjectManager::instance()->get(objects::IPC_STORE); + if (tcStore == nullptr) { return ObjectManagerIF::CHILD_INIT_FAILED; } } @@ -132,7 +119,7 @@ ReturnValue_t PusServiceBase::initializeAfterTaskCreation() { return HasReturnvaluesIF::RETURN_OK; } -void PusServiceBase::setCustomIpcStore(StorageManagerIF* ipcStore_) { ipcStore = ipcStore_; } +void PusServiceBase::setCustomTcStore(StorageManagerIF* tcStore_) { tcStore = tcStore_; } void PusServiceBase::setCustomErrorReporter(InternalErrorReporterIF* errReporter_) { errReporter = errReporter_; diff --git a/src/fsfw/tmtcservices/PusServiceBase.h b/src/fsfw/tmtcservices/PusServiceBase.h index 58f83540..7df563d0 100644 --- a/src/fsfw/tmtcservices/PusServiceBase.h +++ b/src/fsfw/tmtcservices/PusServiceBase.h @@ -59,7 +59,7 @@ class PusServiceBase : public ExecutableObjectIF, */ ~PusServiceBase() override; - void setCustomIpcStore(StorageManagerIF* ipcStore); + void setCustomTcStore(StorageManagerIF* tcStore); void setCustomErrorReporter(InternalErrorReporterIF* errReporter); void initializeTmSendHelper(TmSendHelper& tmSendHelper); @@ -153,7 +153,7 @@ class PusServiceBase : public ExecutableObjectIF, * It is deleted after handleRequest was executed. */ PusTcReader currentPacket; - StorageManagerIF* ipcStore = nullptr; + StorageManagerIF* tcStore = nullptr; InternalErrorReporterIF* errReporter = nullptr; static object_id_t packetSource; diff --git a/src/fsfw/tmtcservices/VerificationCodes.h b/src/fsfw/tmtcservices/VerificationCodes.h index 73edbc1d..91b76bde 100644 --- a/src/fsfw/tmtcservices/VerificationCodes.h +++ b/src/fsfw/tmtcservices/VerificationCodes.h @@ -1,9 +1,11 @@ #ifndef VERIFICATIONCODES_H_ #define VERIFICATIONCODES_H_ -namespace tc_verification { +#include -enum verification_flags { +namespace tcverif { + +enum VerifFlags : uint8_t { NONE = 0b0000, ACCEPTANCE = 0b0001, START = 0b0010, @@ -11,7 +13,7 @@ enum verification_flags { COMPLETION = 0b1000 }; -enum subservice_ids { +enum Subservices : uint8_t { NOTHING_TO_REPORT = 0, ACCEPTANCE_SUCCESS = 1, ACCEPTANCE_FAILURE = 2, @@ -23,6 +25,6 @@ enum subservice_ids { COMPLETION_FAILURE = 8, }; -} // namespace tc_verification +} // namespace tcverif #endif /* VERIFICATIONCODES_H_ */ diff --git a/src/fsfw/tmtcservices/VerificationReporter.cpp b/src/fsfw/tmtcservices/VerificationReporter.cpp index 67b2af37..a9b6dd47 100644 --- a/src/fsfw/tmtcservices/VerificationReporter.cpp +++ b/src/fsfw/tmtcservices/VerificationReporter.cpp @@ -51,7 +51,7 @@ void VerificationReporter::sendSuccessReport(uint8_t set_report_id, uint8_t ackF } void VerificationReporter::sendFailureReport(uint8_t report_id, PusTcReader* correspondingTc, - ReturnValue_t error_code, uint8_t step, + ReturnValue_t errorCode, uint8_t step, uint32_t parameter1, uint32_t parameter2) { if (acknowledgeQueue == MessageQueueIF::NO_QUEUE) { this->initialize(); @@ -61,7 +61,7 @@ void VerificationReporter::sendFailureReport(uint8_t report_id, PusTcReader* cor } PusVerificationMessage message( report_id, correspondingTc->getAcknowledgeFlags(), correspondingTc->getPacketIdRaw(), - correspondingTc->getPacketSeqCtrlRaw(), error_code, step, parameter1, parameter2); + correspondingTc->getPacketSeqCtrlRaw(), errorCode, step, parameter1, parameter2); ReturnValue_t status = MessageQueueSenderIF::sendMessage(acknowledgeQueue, &message); if (status != HasReturnvaluesIF::RETURN_OK) { #if FSFW_CPP_OSTREAM_ENABLED == 1 diff --git a/src/fsfw/tmtcservices/VerificationReporter.h b/src/fsfw/tmtcservices/VerificationReporter.h index d668c502..1d64fd48 100644 --- a/src/fsfw/tmtcservices/VerificationReporter.h +++ b/src/fsfw/tmtcservices/VerificationReporter.h @@ -27,15 +27,17 @@ class VerificationReporter { VerificationReporter(); virtual ~VerificationReporter(); + // TODO: The API is a little bit bloated. It might be better to group all the parameters + // into a dedicated struct void sendSuccessReport(uint8_t set_report_id, PusTcReader* correspondingTc, 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, PusTcReader* correspondingTc, - ReturnValue_t error_code = 0, uint8_t step = 0, uint32_t parameter1 = 0, + ReturnValue_t errorCode = 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, - uint16_t tcSequenceControl, ReturnValue_t error_code = 0, uint8_t step = 0, + uint16_t tcSequenceControl, ReturnValue_t errorCode = 0, uint8_t step = 0, uint32_t parameter1 = 0, uint32_t parameter2 = 0); void initialize(); diff --git a/src/fsfw/tmtcservices/tcHelpers.cpp b/src/fsfw/tmtcservices/tcHelpers.cpp new file mode 100644 index 00000000..91f6e3be --- /dev/null +++ b/src/fsfw/tmtcservices/tcHelpers.cpp @@ -0,0 +1,16 @@ +#include "tcHelpers.h" + +ReturnValue_t tc::prepareTcReader(StorageManagerIF *tcStore, store_address_t storeId, + PusTcReader &tcReader) { + const uint8_t *dataPtr; + size_t dataLen = 0; + ReturnValue_t result = tcStore->getData(storeId, &dataPtr, &dataLen); + if (result != HasReturnvaluesIF::RETURN_OK) { + return result; + } + result = tcReader.setReadOnlyData(dataPtr, dataLen); + if (result != HasReturnvaluesIF::RETURN_OK) { + return result; + } + return tcReader.parseDataWithoutCrcCheck(); +} diff --git a/src/fsfw/tmtcservices/tcHelpers.h b/src/fsfw/tmtcservices/tcHelpers.h new file mode 100644 index 00000000..fc19ae33 --- /dev/null +++ b/src/fsfw/tmtcservices/tcHelpers.h @@ -0,0 +1,15 @@ +#ifndef FSFW_TMTCSERVICES_TCHELPERS_H +#define FSFW_TMTCSERVICES_TCHELPERS_H + +#include "fsfw/returnvalues/HasReturnvaluesIF.h" +#include "fsfw/storagemanager/StorageManagerIF.h" +#include "fsfw/tmtcpacket/pus/tc.h" + +namespace tc { + +ReturnValue_t prepareTcReader(StorageManagerIF* tcStore, store_address_t storeId, + PusTcReader& tcReader); + +} // namespace tc + +#endif // FSFW_TMTCSERVICES_TCHELPERS_H diff --git a/src/fsfw/tmtcservices/tmHelpers.cpp b/src/fsfw/tmtcservices/tmHelpers.cpp new file mode 100644 index 00000000..91026d6c --- /dev/null +++ b/src/fsfw/tmtcservices/tmHelpers.cpp @@ -0,0 +1,10 @@ +#include "tmHelpers.h" + +ReturnValue_t tm::storeAndSendTmPacket(TmStoreHelper &storeHelper, TmSendHelper &sendHelper) { + storeHelper.addPacketToStore(); + ReturnValue_t result = sendHelper.sendPacket(storeHelper.getCurrentAddr()); + if (result != HasReturnvaluesIF::RETURN_OK) { + storeHelper.deletePacket(); + } + return result; +} diff --git a/src/fsfw/tmtcservices/sendAndStoreHelper.h b/src/fsfw/tmtcservices/tmHelpers.h similarity index 77% rename from src/fsfw/tmtcservices/sendAndStoreHelper.h rename to src/fsfw/tmtcservices/tmHelpers.h index d07456f6..871a7f1a 100644 --- a/src/fsfw/tmtcservices/sendAndStoreHelper.h +++ b/src/fsfw/tmtcservices/tmHelpers.h @@ -1,19 +1,12 @@ -#ifndef FSFW_TMTCSERVICES_SENDANDSTOREHELPER_H -#define FSFW_TMTCSERVICES_SENDANDSTOREHELPER_H +#ifndef FSFW_TMTCSERVICES_TMHELPERS_H_ +#define FSFW_TMTCSERVICES_TMHELPERS_H_ #include "TmSendHelper.h" #include "TmStoreHelper.h" namespace tm { -ReturnValue_t storeAndSendTmPacket(TmStoreHelper& storeHelper, TmSendHelper& sendHelper) { - storeHelper.addPacketToStore(); - ReturnValue_t result = sendHelper.sendPacket(storeHelper.getCurrentAddr()); - if (result != HasReturnvaluesIF::RETURN_OK) { - storeHelper.deletePacket(); - } - return result; -} +ReturnValue_t storeAndSendTmPacket(TmStoreHelper& storeHelper, TmSendHelper& sendHelper); class SourceDataWithObjectIdPrefix : public SerializeIF { public: @@ -51,4 +44,4 @@ class SourceDataWithObjectIdPrefix : public SerializeIF { } // namespace tm -#endif // FSFW_TMTCSERVICES_SENDANDSTOREHELPER_H +#endif // FSFW_TMTCSERVICES_TMHELPERS_H_ -- 2.43.0 From 23f264096cb9f3a191617beb562119e838c5c7b1 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Thu, 21 Jul 2022 14:05:31 +0200 Subject: [PATCH 018/108] delete a few old classes --- src/fsfw/tcdistribution/PusDistributor.cpp | 1 - src/fsfw/tmtcpacket/CMakeLists.txt | 2 - src/fsfw/tmtcpacket/PacketStorageHelper.cpp | 25 -------- src/fsfw/tmtcpacket/PacketStorageHelper.h | 63 ------------------- src/fsfw/tmtcpacket/pus/tc/TcPacketStored.cpp | 1 - src/fsfw/tmtcpacket/pus/tc/TcPacketStored.h | 10 --- 6 files changed, 102 deletions(-) delete mode 100644 src/fsfw/tmtcpacket/PacketStorageHelper.cpp delete mode 100644 src/fsfw/tmtcpacket/PacketStorageHelper.h delete mode 100644 src/fsfw/tmtcpacket/pus/tc/TcPacketStored.cpp delete mode 100644 src/fsfw/tmtcpacket/pus/tc/TcPacketStored.h diff --git a/src/fsfw/tcdistribution/PusDistributor.cpp b/src/fsfw/tcdistribution/PusDistributor.cpp index bac932d5..3a7fdf34 100644 --- a/src/fsfw/tcdistribution/PusDistributor.cpp +++ b/src/fsfw/tcdistribution/PusDistributor.cpp @@ -3,7 +3,6 @@ #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 diff --git a/src/fsfw/tmtcpacket/CMakeLists.txt b/src/fsfw/tmtcpacket/CMakeLists.txt index 8c70d351..e1b54efe 100644 --- a/src/fsfw/tmtcpacket/CMakeLists.txt +++ b/src/fsfw/tmtcpacket/CMakeLists.txt @@ -1,5 +1,3 @@ -target_sources(${LIB_FSFW_NAME} PRIVATE PacketStorageHelper.cpp) - add_subdirectory(ccsds) add_subdirectory(pus) add_subdirectory(cfdp) diff --git a/src/fsfw/tmtcpacket/PacketStorageHelper.cpp b/src/fsfw/tmtcpacket/PacketStorageHelper.cpp deleted file mode 100644 index 89184251..00000000 --- a/src/fsfw/tmtcpacket/PacketStorageHelper.cpp +++ /dev/null @@ -1,25 +0,0 @@ -#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 deleted file mode 100644 index 1be75b23..00000000 --- a/src/fsfw/tmtcpacket/PacketStorageHelper.h +++ /dev/null @@ -1,63 +0,0 @@ -#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/pus/tc/TcPacketStored.cpp b/src/fsfw/tmtcpacket/pus/tc/TcPacketStored.cpp deleted file mode 100644 index 89ebe75a..00000000 --- a/src/fsfw/tmtcpacket/pus/tc/TcPacketStored.cpp +++ /dev/null @@ -1 +0,0 @@ -#include "TcPacketStored.h" diff --git a/src/fsfw/tmtcpacket/pus/tc/TcPacketStored.h b/src/fsfw/tmtcpacket/pus/tc/TcPacketStored.h deleted file mode 100644 index ddd51303..00000000 --- a/src/fsfw/tmtcpacket/pus/tc/TcPacketStored.h +++ /dev/null @@ -1,10 +0,0 @@ -#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 -- 2.43.0 From 08e0b0f1a0eafcc0c5facb26631f8b3cff6ddeb9 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Thu, 21 Jul 2022 14:40:00 +0200 Subject: [PATCH 019/108] added sp reader unittests --- src/fsfw/tmtcpacket/ccsds/SpacePacketIF.h | 6 +++ .../tmtcpacket/ccsds/SpacePacketReader.cpp | 7 ++- src/fsfw/tmtcpacket/ccsds/SpacePacketReader.h | 5 -- src/fsfw/tmtcpacket/ccsds/header.cpp | 2 +- unittests/tmtcpacket/testCcsdsReader.cpp | 51 ++++++++++++++++++- 5 files changed, 63 insertions(+), 8 deletions(-) diff --git a/src/fsfw/tmtcpacket/ccsds/SpacePacketIF.h b/src/fsfw/tmtcpacket/ccsds/SpacePacketIF.h index 068e04d9..de01e819 100644 --- a/src/fsfw/tmtcpacket/ccsds/SpacePacketIF.h +++ b/src/fsfw/tmtcpacket/ccsds/SpacePacketIF.h @@ -22,6 +22,12 @@ class SpacePacketIF { virtual ~SpacePacketIF() = default; + /** + * CCSDS header always has 6 bytes + * @return + */ + static constexpr size_t getHeaderLen() { return ccsds::HEADER_LEN; } + /** * Returns the complete first two bytes of the packet, which together form * the CCSDS packet ID diff --git a/src/fsfw/tmtcpacket/ccsds/SpacePacketReader.cpp b/src/fsfw/tmtcpacket/ccsds/SpacePacketReader.cpp index c528d0a7..76f92107 100644 --- a/src/fsfw/tmtcpacket/ccsds/SpacePacketReader.cpp +++ b/src/fsfw/tmtcpacket/ccsds/SpacePacketReader.cpp @@ -8,6 +8,9 @@ SpacePacketReader::SpacePacketReader(const uint8_t* setAddress, size_t maxSize_) } ReturnValue_t SpacePacketReader::checkSize() const { + if (isNull()) { + return HasReturnvaluesIF::RETURN_FAILED; + } if (getFullPacketLen() > bufSize) { return SerializeIF::STREAM_TOO_SHORT; } @@ -33,7 +36,9 @@ uint16_t SpacePacketReader::getPacketDataLen() const { return ccsds::getPacketLe ReturnValue_t SpacePacketReader::setInternalFields(const uint8_t* data, size_t maxSize_) { bufSize = maxSize_; spHeader = reinterpret_cast(data); - packetDataField = data + ccsds::HEADER_LEN; + if (maxSize_ > 6) { + packetDataField = data + ccsds::HEADER_LEN; + } return checkSize(); } diff --git a/src/fsfw/tmtcpacket/ccsds/SpacePacketReader.h b/src/fsfw/tmtcpacket/ccsds/SpacePacketReader.h index b35b813b..0d075bae 100644 --- a/src/fsfw/tmtcpacket/ccsds/SpacePacketReader.h +++ b/src/fsfw/tmtcpacket/ccsds/SpacePacketReader.h @@ -62,11 +62,6 @@ class SpacePacketReader : public SpacePacketIF, */ [[nodiscard]] size_t getBufSize() const; - /** - * CCSDS header always has 6 bytes - * @return - */ - static constexpr size_t getHeaderLen() { return ccsds::HEADER_LEN; } [[nodiscard]] uint16_t getPacketIdRaw() const override; [[nodiscard]] uint16_t getPacketSeqCtrlRaw() const override; [[nodiscard]] uint16_t getPacketDataLen() const override; diff --git a/src/fsfw/tmtcpacket/ccsds/header.cpp b/src/fsfw/tmtcpacket/ccsds/header.cpp index b7aa270e..b87ab5b3 100644 --- a/src/fsfw/tmtcpacket/ccsds/header.cpp +++ b/src/fsfw/tmtcpacket/ccsds/header.cpp @@ -1,7 +1,7 @@ #include "header.h" uint16_t ccsds::getPacketId(const PrimaryHeader &header) { - return ((header.packetIdHAndVersion & 0x1F00) << 8) + header.packetIdL; + return ((header.packetIdHAndVersion & 0x1F) << 8) + header.packetIdL; } uint16_t ccsds::getPacketSeqCtrl(const PrimaryHeader &header) { diff --git a/unittests/tmtcpacket/testCcsdsReader.cpp b/unittests/tmtcpacket/testCcsdsReader.cpp index 89ee5a46..655c34e2 100644 --- a/unittests/tmtcpacket/testCcsdsReader.cpp +++ b/unittests/tmtcpacket/testCcsdsReader.cpp @@ -1,5 +1,54 @@ +#include #include +#include "fsfw/tmtcpacket/ccsds/SpacePacketCreator.h" #include "fsfw/tmtcpacket/ccsds/SpacePacketReader.h" -TEST_CASE("CCSDS Reader", "[ccsds-reader]") {} \ No newline at end of file +TEST_CASE("CCSDS Reader", "[ccsds-reader]") { + auto params = SpacePacketParams(PacketId(ccsds::PacketType::TC, true, 0x02), + PacketSeqCtrl(ccsds::SequenceFlags::FIRST_SEGMENT, 0x34), 0x16); + SpacePacketCreator base = SpacePacketCreator(params); + // This is enough to hold 0x16 (22) bytes + 6 (SP header length) + 1 as defined as the full packet + // length derived from the length field + std::array buf{}; + uint8_t* bufPtr = buf.data(); + size_t serLen = 0; + SpacePacketReader reader; + SECTION("Empty Reader") { + REQUIRE(reader.isNull()); + REQUIRE(reader.checkSize() == HasReturnvaluesIF::RETURN_FAILED); + } + + SECTION("Basic Read") { + REQUIRE(base.serialize(&bufPtr, &serLen, buf.size(), SerializeIF::Endianness::NETWORK) == + HasReturnvaluesIF::RETURN_OK); + reader.setReadOnlyData(buf.data(), SpacePacketIF::getHeaderLen()); + REQUIRE(reader.getPacketDataLen() == 0x16); + REQUIRE(reader.getFullData() == buf.data()); + REQUIRE(reader.getFullPacketLen() == 0x16 + SpacePacketReader::getHeaderLen() + 1); + REQUIRE(reader.getPacketIdRaw() == 0x1802); + REQUIRE(reader.getSequenceFlags() == ccsds::SequenceFlags::FIRST_SEGMENT); + REQUIRE(reader.getSequenceCount() == 0x34); + REQUIRE(reader.getPacketSeqCtrlRaw() == 0x4034); + REQUIRE(reader.hasSecHeader()); + REQUIRE(reader.getApid() == 0x02); + REQUIRE(not reader.isNull()); + // We only serialized the 6 bytes of the header, so the packer data should be invalid + REQUIRE(reader.getPacketData() == nullptr); + } + + SECTION("Read with additional data") { + REQUIRE(base.serialize(&bufPtr, &serLen, buf.size(), SerializeIF::Endianness::NETWORK) == + HasReturnvaluesIF::RETURN_OK); + REQUIRE(reader.setReadOnlyData(buf.data(), buf.size()) == HasReturnvaluesIF::RETURN_OK); + REQUIRE(reader.getPacketData() == buf.data() + SpacePacketIF::getHeaderLen()); + } + + SECTION("Invalid Size") { + for (size_t i = 0; i < 5; i++) { + REQUIRE(reader.setReadOnlyData(buf.data(), i) == SerializeIF::STREAM_TOO_SHORT); + REQUIRE(not reader.isNull()); + REQUIRE(reader.getPacketData() == nullptr); + } + } +} \ No newline at end of file -- 2.43.0 From 5af3138e81df3bfee27436a48206851f1d5a0b26 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Thu, 21 Jul 2022 17:48:11 +0200 Subject: [PATCH 020/108] fnished PUS TC creator unittests --- src/fsfw/tmtcpacket/ccsds/PacketId.h | 4 + .../tmtcpacket/ccsds/SpacePacketCreator.cpp | 4 + .../tmtcpacket/ccsds/SpacePacketCreator.h | 1 + src/fsfw/tmtcpacket/pus/PusIF.h | 4 +- src/fsfw/tmtcpacket/pus/defs.h | 13 ++ src/fsfw/tmtcpacket/pus/tc/PusTcCreator.cpp | 18 ++- src/fsfw/tmtcpacket/pus/tc/PusTcCreator.h | 14 +- unittests/devicehandler/CMakeLists.txt | 4 - .../devicehandler/TestDeviceHandlerBase.cpp | 8 +- unittests/mocks/CMakeLists.txt | 4 + .../{devicehandler => mocks}/ComIFMock.cpp | 0 .../{devicehandler => mocks}/ComIFMock.h | 0 .../{devicehandler => mocks}/CookieIFMock.cpp | 0 .../{devicehandler => mocks}/CookieIFMock.h | 0 .../DeviceFdirMock.cpp | 4 +- .../{devicehandler => mocks}/DeviceFdirMock.h | 0 .../DeviceHandlerMock.cpp | 0 .../DeviceHandlerMock.h | 0 unittests/mocks/SimpleSerializable.h | 35 +++++ unittests/tmtcpacket/CMakeLists.txt | 1 + unittests/tmtcpacket/testCcsdsReader.cpp | 35 +++-- unittests/tmtcpacket/testPusTcCreator.cpp | 120 ++++++++++++++++++ 22 files changed, 239 insertions(+), 30 deletions(-) rename unittests/{devicehandler => mocks}/ComIFMock.cpp (100%) rename unittests/{devicehandler => mocks}/ComIFMock.h (100%) rename unittests/{devicehandler => mocks}/CookieIFMock.cpp (100%) rename unittests/{devicehandler => mocks}/CookieIFMock.h (100%) rename unittests/{devicehandler => mocks}/DeviceFdirMock.cpp (86%) rename unittests/{devicehandler => mocks}/DeviceFdirMock.h (100%) rename unittests/{devicehandler => mocks}/DeviceHandlerMock.cpp (100%) rename unittests/{devicehandler => mocks}/DeviceHandlerMock.h (100%) create mode 100644 unittests/mocks/SimpleSerializable.h create mode 100644 unittests/tmtcpacket/testPusTcCreator.cpp diff --git a/src/fsfw/tmtcpacket/ccsds/PacketId.h b/src/fsfw/tmtcpacket/ccsds/PacketId.h index 49587483..29b82f13 100644 --- a/src/fsfw/tmtcpacket/ccsds/PacketId.h +++ b/src/fsfw/tmtcpacket/ccsds/PacketId.h @@ -19,6 +19,10 @@ struct PacketId : public SerializeIF { PacketId(ccsds::PacketType packetType_, bool secHeaderFlag_, uint16_t apid_) : packetType(packetType_), secHeaderFlag(secHeaderFlag_), apid(apid_) {} + bool operator==(const PacketId &other) const { + return packetType == other.packetType and secHeaderFlag == other.secHeaderFlag and + apid == other.apid; + } /** * NOTE: If the APID has an invalid value, the invalid bits will be cut off * @return diff --git a/src/fsfw/tmtcpacket/ccsds/SpacePacketCreator.cpp b/src/fsfw/tmtcpacket/ccsds/SpacePacketCreator.cpp index 94cf45f4..7ae8656f 100644 --- a/src/fsfw/tmtcpacket/ccsds/SpacePacketCreator.cpp +++ b/src/fsfw/tmtcpacket/ccsds/SpacePacketCreator.cpp @@ -79,3 +79,7 @@ void SpacePacketCreator::checkFieldValidity() { void SpacePacketCreator::setParams(SpacePacketParams params_) { params = std::move(params_); } SpacePacketParams &SpacePacketCreator::getParams() { return params; } + +void SpacePacketCreator::setPacketType(ccsds::PacketType type) { + params.packetId.packetType = type; +} diff --git a/src/fsfw/tmtcpacket/ccsds/SpacePacketCreator.h b/src/fsfw/tmtcpacket/ccsds/SpacePacketCreator.h index dd5edbd5..de62283f 100644 --- a/src/fsfw/tmtcpacket/ccsds/SpacePacketCreator.h +++ b/src/fsfw/tmtcpacket/ccsds/SpacePacketCreator.h @@ -35,6 +35,7 @@ class SpacePacketCreator : public SpacePacketIF, public SerializeIF { SpacePacketParams &getParams(); void setParams(SpacePacketParams params); + void setPacketType(ccsds::PacketType type); void setApid(uint16_t apid); void setSeqCount(uint16_t seqCount); void setSeqFlags(ccsds::SequenceFlags flags); diff --git a/src/fsfw/tmtcpacket/pus/PusIF.h b/src/fsfw/tmtcpacket/pus/PusIF.h index 8a15f01e..8c346b1d 100644 --- a/src/fsfw/tmtcpacket/pus/PusIF.h +++ b/src/fsfw/tmtcpacket/pus/PusIF.h @@ -9,8 +9,10 @@ class PusIF : public SpacePacketIF { public: static constexpr uint8_t INTERFACE_ID = CLASS_ID::PUS_IF; - static constexpr ReturnValue_t INVALID_CRC_16 = + static constexpr ReturnValue_t INVALID_PUS_VERSION = HasReturnvaluesIF::makeReturnCode(INTERFACE_ID, 0); + static constexpr ReturnValue_t INVALID_CRC_16 = + HasReturnvaluesIF::makeReturnCode(INTERFACE_ID, 1); ~PusIF() override = default; /** diff --git a/src/fsfw/tmtcpacket/pus/defs.h b/src/fsfw/tmtcpacket/pus/defs.h index 027ff37c..83502ed3 100644 --- a/src/fsfw/tmtcpacket/pus/defs.h +++ b/src/fsfw/tmtcpacket/pus/defs.h @@ -2,6 +2,7 @@ #define FSFW_SRC_FSFW_TMTCPACKET_PUS_TM_DEFINITIONS_H_ #include +#include #include "fsfw/serialize/SerializeIF.h" @@ -27,6 +28,7 @@ union DataUnion { struct DataWrapper { DataTypes type; DataUnion dataUnion; + using BufPairT = std::pair; [[nodiscard]] size_t getLength() const { if (type == DataTypes::RAW) { @@ -36,6 +38,17 @@ struct DataWrapper { } return 0; } + + void setRawData(BufPairT bufPair) { + type = DataTypes::RAW; + dataUnion.raw.data = bufPair.first; + dataUnion.raw.len = bufPair.second; + } + + void setSerializable(SerializeIF* serializable) { + type = DataTypes::SERIALIZABLE; + dataUnion.serializable = serializable; + } }; /** diff --git a/src/fsfw/tmtcpacket/pus/tc/PusTcCreator.cpp b/src/fsfw/tmtcpacket/pus/tc/PusTcCreator.cpp index bd824d24..2ff82d25 100644 --- a/src/fsfw/tmtcpacket/pus/tc/PusTcCreator.cpp +++ b/src/fsfw/tmtcpacket/pus/tc/PusTcCreator.cpp @@ -8,29 +8,31 @@ PusTcCreator::PusTcCreator(SpacePacketParams spParams, PusTcParams pusParams) : spCreator(std::move(spParams)), pusParams(pusParams) { + spCreator.setPacketType(ccsds::PacketType::TC); updateSpLengthField(); } ReturnValue_t PusTcCreator::serialize(uint8_t **buffer, size_t *size, size_t maxSize, SerializeIF::Endianness streamEndianness) const { + const uint8_t *start = *buffer; size_t userDataLen = pusParams.dataWrapper.getLength(); - if (*size + PusTcIF::MIN_SIZE + userDataLen > maxSize) { + if (*size + getFullPacketLen() > maxSize) { return SerializeIF::BUFFER_TOO_SHORT; } + if (pusParams.pusVersion != ecss::PusVersion::PUS_C) { + return PusIF::INVALID_PUS_VERSION; + } 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; + *size += 3; result = SerializeAdapter::serialize(&pusParams.sourceId, buffer, size, maxSize, streamEndianness); if (result != HasReturnvaluesIF::RETURN_OK) { @@ -52,7 +54,7 @@ ReturnValue_t PusTcCreator::serialize(uint8_t **buffer, size_t *size, size_t max } } - uint16_t crc16 = CRC::crc16ccitt(*buffer, getFullPacketLen() - 2); + uint16_t crc16 = CRC::crc16ccitt(start, getFullPacketLen() - 2); return SerializeAdapter::serialize(&crc16, buffer, size, maxSize, streamEndianness); } @@ -89,3 +91,7 @@ ecss::DataWrapper &PusTcCreator::getDataWrapper() { return pusParams.dataWrapper PusTcParams &PusTcCreator::getPusParams() { return pusParams; } SpacePacketParams &PusTcCreator::getSpParams() { return spCreator.getParams(); } + +ReturnValue_t PusTcCreator::serialize(uint8_t **buffer, size_t *size, size_t maxSize) { + return serialize(buffer, size, maxSize, SerializeIF::Endianness::NETWORK); +} diff --git a/src/fsfw/tmtcpacket/pus/tc/PusTcCreator.h b/src/fsfw/tmtcpacket/pus/tc/PusTcCreator.h index 1f6e8acb..c09a7238 100644 --- a/src/fsfw/tmtcpacket/pus/tc/PusTcCreator.h +++ b/src/fsfw/tmtcpacket/pus/tc/PusTcCreator.h @@ -21,13 +21,19 @@ struct PusTcParams { class PusTcCreator : public PusTcIF, public SerializeIF, public CreatorDataIF { public: - PusTcCreator(SpacePacketParams spParams, PusTcParams pusParams); + PusTcCreator(SpacePacketParams initSpParams, PusTcParams initPusParams); + /** + * If the parameter structure is changed in a way which changes the resulting serialized packet + * size, this function should be called to set the data length field in the space packet + * header. This fields is the primary source of information for length information. + * + * The only case for a telecommand where this size changes would be if user data is set. + */ void updateSpLengthField(); PusTcParams &getPusParams(); SpacePacketParams &getSpParams(); - ReturnValue_t serialize(uint8_t **buffer, size_t *size, size_t maxSize, - Endianness streamEndianness) const override; + ReturnValue_t serialize(uint8_t **buffer, size_t *size, size_t maxSize); [[nodiscard]] size_t getSerializedSize() const override; ReturnValue_t deSerialize(const uint8_t **buffer, size_t *size, Endianness streamEndianness) override; @@ -42,6 +48,8 @@ class PusTcCreator : public PusTcIF, public SerializeIF, public CreatorDataIF { ecss::DataWrapper &getDataWrapper() override; private: + ReturnValue_t serialize(uint8_t **buffer, size_t *size, size_t maxSize, + Endianness streamEndianness) const override; SpacePacketCreator spCreator; PusTcParams pusParams; }; diff --git a/unittests/devicehandler/CMakeLists.txt b/unittests/devicehandler/CMakeLists.txt index 7ad5d316..5d4d9b06 100644 --- a/unittests/devicehandler/CMakeLists.txt +++ b/unittests/devicehandler/CMakeLists.txt @@ -1,8 +1,4 @@ target_sources(${FSFW_TEST_TGT} PRIVATE - CookieIFMock.cpp - ComIFMock.cpp DeviceHandlerCommander.cpp - DeviceHandlerMock.cpp - DeviceFdirMock.cpp TestDeviceHandlerBase.cpp ) diff --git a/unittests/devicehandler/TestDeviceHandlerBase.cpp b/unittests/devicehandler/TestDeviceHandlerBase.cpp index e8fdd17b..0a1b18fa 100644 --- a/unittests/devicehandler/TestDeviceHandlerBase.cpp +++ b/unittests/devicehandler/TestDeviceHandlerBase.cpp @@ -1,10 +1,10 @@ #include -#include "ComIFMock.h" -#include "DeviceFdirMock.h" #include "DeviceHandlerCommander.h" -#include "DeviceHandlerMock.h" -#include "devicehandler/CookieIFMock.h" +#include "mocks/ComIFMock.h" +#include "mocks/CookieIFMock.h" +#include "mocks/DeviceFdirMock.h" +#include "mocks/DeviceHandlerMock.h" #include "objects/systemObjectList.h" TEST_CASE("Device Handler Base", "[DeviceHandlerBase]") { diff --git a/unittests/mocks/CMakeLists.txt b/unittests/mocks/CMakeLists.txt index 1b86547c..50a34ce8 100644 --- a/unittests/mocks/CMakeLists.txt +++ b/unittests/mocks/CMakeLists.txt @@ -1,3 +1,7 @@ target_sources(${FSFW_TEST_TGT} PRIVATE PowerSwitcherMock.cpp + DeviceHandlerMock.cpp + DeviceFdirMock.cpp + CookieIFMock.cpp + ComIFMock.cpp ) diff --git a/unittests/devicehandler/ComIFMock.cpp b/unittests/mocks/ComIFMock.cpp similarity index 100% rename from unittests/devicehandler/ComIFMock.cpp rename to unittests/mocks/ComIFMock.cpp diff --git a/unittests/devicehandler/ComIFMock.h b/unittests/mocks/ComIFMock.h similarity index 100% rename from unittests/devicehandler/ComIFMock.h rename to unittests/mocks/ComIFMock.h diff --git a/unittests/devicehandler/CookieIFMock.cpp b/unittests/mocks/CookieIFMock.cpp similarity index 100% rename from unittests/devicehandler/CookieIFMock.cpp rename to unittests/mocks/CookieIFMock.cpp diff --git a/unittests/devicehandler/CookieIFMock.h b/unittests/mocks/CookieIFMock.h similarity index 100% rename from unittests/devicehandler/CookieIFMock.h rename to unittests/mocks/CookieIFMock.h diff --git a/unittests/devicehandler/DeviceFdirMock.cpp b/unittests/mocks/DeviceFdirMock.cpp similarity index 86% rename from unittests/devicehandler/DeviceFdirMock.cpp rename to unittests/mocks/DeviceFdirMock.cpp index e3ac39ac..5dcd985d 100644 --- a/unittests/devicehandler/DeviceFdirMock.cpp +++ b/unittests/mocks/DeviceFdirMock.cpp @@ -1,11 +1,9 @@ #include "DeviceFdirMock.h" -#include "devicehandler/DeviceFdirMock.h" - DeviceFdirMock::DeviceFdirMock(object_id_t owner, object_id_t parent) : DeviceHandlerFailureIsolation(owner, parent) {} -DeviceFdirMock::~DeviceFdirMock() {} +DeviceFdirMock::~DeviceFdirMock() = default; uint32_t DeviceFdirMock::getMissedReplyCount() { ParameterWrapper parameterWrapper; diff --git a/unittests/devicehandler/DeviceFdirMock.h b/unittests/mocks/DeviceFdirMock.h similarity index 100% rename from unittests/devicehandler/DeviceFdirMock.h rename to unittests/mocks/DeviceFdirMock.h diff --git a/unittests/devicehandler/DeviceHandlerMock.cpp b/unittests/mocks/DeviceHandlerMock.cpp similarity index 100% rename from unittests/devicehandler/DeviceHandlerMock.cpp rename to unittests/mocks/DeviceHandlerMock.cpp diff --git a/unittests/devicehandler/DeviceHandlerMock.h b/unittests/mocks/DeviceHandlerMock.h similarity index 100% rename from unittests/devicehandler/DeviceHandlerMock.h rename to unittests/mocks/DeviceHandlerMock.h diff --git a/unittests/mocks/SimpleSerializable.h b/unittests/mocks/SimpleSerializable.h new file mode 100644 index 00000000..399e2826 --- /dev/null +++ b/unittests/mocks/SimpleSerializable.h @@ -0,0 +1,35 @@ +#ifndef FSFW_TESTS_SIMPLESERIALIZABLE_H +#define FSFW_TESTS_SIMPLESERIALIZABLE_H + +#include "fsfw/serialize.h" + +class SimpleSerializable : public SerializeIF { + public: + ReturnValue_t serialize(uint8_t **buffer, size_t *size, size_t maxSize, + Endianness streamEndianness) const override { + if (*size + getSerializedSize() > maxSize) { + return SerializeIF::BUFFER_TOO_SHORT; + } + **buffer = someU8; + *buffer += 1; + *size += 1; + return SerializeAdapter::serialize(&someU16, buffer, size, maxSize, streamEndianness); + } + + [[nodiscard]] size_t getSerializedSize() const override { return 3; } + ReturnValue_t deSerialize(const uint8_t **buffer, size_t *size, + Endianness streamEndianness) override { + if (*size < getSerializedSize()) { + return SerializeIF::STREAM_TOO_SHORT; + } + someU8 = **buffer; + *size -= 1; + return SerializeAdapter::deSerialize(&someU16, buffer, size, streamEndianness); + } + + private: + uint8_t someU8 = 1; + uint16_t someU16 = 0x0203; +}; + +#endif // FSFW_TESTS_SIMPLESERIALIZABLE_H diff --git a/unittests/tmtcpacket/CMakeLists.txt b/unittests/tmtcpacket/CMakeLists.txt index 9a08868e..67d8858c 100644 --- a/unittests/tmtcpacket/CMakeLists.txt +++ b/unittests/tmtcpacket/CMakeLists.txt @@ -1,4 +1,5 @@ target_sources(${FSFW_TEST_TGT} PRIVATE testCcsdsCreator.cpp testCcsdsReader.cpp + testPusTcCreator.cpp ) diff --git a/unittests/tmtcpacket/testCcsdsReader.cpp b/unittests/tmtcpacket/testCcsdsReader.cpp index 655c34e2..75b4af87 100644 --- a/unittests/tmtcpacket/testCcsdsReader.cpp +++ b/unittests/tmtcpacket/testCcsdsReader.cpp @@ -4,26 +4,22 @@ #include "fsfw/tmtcpacket/ccsds/SpacePacketCreator.h" #include "fsfw/tmtcpacket/ccsds/SpacePacketReader.h" +#define FULL_PACKET_LEN 29 + TEST_CASE("CCSDS Reader", "[ccsds-reader]") { auto params = SpacePacketParams(PacketId(ccsds::PacketType::TC, true, 0x02), PacketSeqCtrl(ccsds::SequenceFlags::FIRST_SEGMENT, 0x34), 0x16); SpacePacketCreator base = SpacePacketCreator(params); // This is enough to hold 0x16 (22) bytes + 6 (SP header length) + 1 as defined as the full packet // length derived from the length field - std::array buf{}; + std::array buf{}; uint8_t* bufPtr = buf.data(); size_t serLen = 0; SpacePacketReader reader; - SECTION("Empty Reader") { - REQUIRE(reader.isNull()); - REQUIRE(reader.checkSize() == HasReturnvaluesIF::RETURN_FAILED); - } - SECTION("Basic Read") { - REQUIRE(base.serialize(&bufPtr, &serLen, buf.size(), SerializeIF::Endianness::NETWORK) == - HasReturnvaluesIF::RETURN_OK); - reader.setReadOnlyData(buf.data(), SpacePacketIF::getHeaderLen()); + auto checkReader = [&](SpacePacketReader& reader) { REQUIRE(reader.getPacketDataLen() == 0x16); + REQUIRE(reader.getBufSize() == SpacePacketIF::getHeaderLen()); REQUIRE(reader.getFullData() == buf.data()); REQUIRE(reader.getFullPacketLen() == 0x16 + SpacePacketReader::getHeaderLen() + 1); REQUIRE(reader.getPacketIdRaw() == 0x1802); @@ -35,12 +31,33 @@ TEST_CASE("CCSDS Reader", "[ccsds-reader]") { REQUIRE(not reader.isNull()); // We only serialized the 6 bytes of the header, so the packer data should be invalid REQUIRE(reader.getPacketData() == nullptr); + }; + + SECTION("Empty Reader") { + REQUIRE(SpacePacketIF::getHeaderLen() == 6); + REQUIRE(reader.isNull()); + REQUIRE(reader.checkSize() == HasReturnvaluesIF::RETURN_FAILED); + } + + SECTION("Basic Read") { + REQUIRE(base.serialize(&bufPtr, &serLen, buf.size(), SerializeIF::Endianness::NETWORK) == + HasReturnvaluesIF::RETURN_OK); + SECTION("Setter") { + reader.setReadOnlyData(buf.data(), SpacePacketIF::getHeaderLen()); + checkReader(reader); + } + SECTION("Direct Construction") { + SpacePacketReader secondReader(buf.data(), serLen); + checkReader(secondReader); + } } SECTION("Read with additional data") { REQUIRE(base.serialize(&bufPtr, &serLen, buf.size(), SerializeIF::Endianness::NETWORK) == HasReturnvaluesIF::RETURN_OK); REQUIRE(reader.setReadOnlyData(buf.data(), buf.size()) == HasReturnvaluesIF::RETURN_OK); + REQUIRE(reader.getBufSize() == buf.size()); + REQUIRE(reader.getFullPacketLen() == FULL_PACKET_LEN); REQUIRE(reader.getPacketData() == buf.data() + SpacePacketIF::getHeaderLen()); } diff --git a/unittests/tmtcpacket/testPusTcCreator.cpp b/unittests/tmtcpacket/testPusTcCreator.cpp new file mode 100644 index 00000000..f6c15b78 --- /dev/null +++ b/unittests/tmtcpacket/testPusTcCreator.cpp @@ -0,0 +1,120 @@ +#include +#include + +#include "fsfw/globalfunctions/CRC.h" +#include "fsfw/tmtcpacket/pus/tc.h" +#include "mocks/SimpleSerializable.h" + +TEST_CASE("PUS TC Creator", "[pus-tc-creator]") { + auto packetId = PacketId(ccsds::PacketType::TC, true, 0x02); + auto spParams = + SpacePacketParams(packetId, PacketSeqCtrl(ccsds::SequenceFlags::UNSEGMENTED, 0x34), 0x00); + auto pusParams = PusTcParams(17, 1); + PusTcCreator creator(spParams, pusParams); + std::array buf{}; + uint8_t* dataPtr = buf.data(); + size_t serLen = 0; + + SECTION("State") { + REQUIRE(creator.getService() == 17); + REQUIRE(creator.getSubService() == 1); + REQUIRE(creator.getApid() == 0x02); + REQUIRE(creator.getPusVersion() == 2); + REQUIRE(creator.getAcknowledgeFlags() == 0b1111); + REQUIRE(creator.getSourceId() == 0x00); + REQUIRE(creator.getPacketSeqCtrlRaw() == 0xc034); + // bytes CCSDS header, 5 bytes secondary header, 2 bytes CRC, 3 bytes app data + REQUIRE(creator.getFullPacketLen() == 13); + // The data length field is the full packet length minus the primary header minus 1 + REQUIRE(creator.getPacketDataLen() == 6); + auto& paramsLocal = creator.getSpParams(); + REQUIRE(paramsLocal.packetId == packetId); + } + + SECTION("Serialized") { + REQUIRE(creator.serialize(&dataPtr, &serLen, buf.size()) == HasReturnvaluesIF::RETURN_OK); + REQUIRE(serLen == 13); + REQUIRE(buf[0] == 0x18); + REQUIRE(buf[1] == 0x02); + // Unsegmented, first 2 bits 11 + REQUIRE(buf[2] == 0xc0); + // Packet Sequence count only occupies lower byte of packet sequence control + REQUIRE(buf[3] == 0x34); + // Data length packed big endian + REQUIRE(buf[4] == 0x00); + REQUIRE(buf[5] == 0x06); + // PUS Version C (2) + REQUIRE(((buf[6] >> 4) & 0b1111) == 2); + // All Ack Fields is default + REQUIRE((buf[6] & 0b1111) == 0b1111); + // Service and subservice + REQUIRE(buf[7] == 17); + REQUIRE(buf[8] == 1); + // Source ID is 0 + REQUIRE(((buf[9] << 8) | buf[10]) == 0); + // CRC16 check + REQUIRE(CRC::crc16ccitt(buf.data(), serLen) == 0); + } + + SECTION("Custom Source ID") { + auto& params = creator.getPusParams(); + params.sourceId = 0x5ff; + REQUIRE(creator.getSourceId() == 0x5ff); + REQUIRE(creator.serialize(&dataPtr, &serLen, buf.size()) == HasReturnvaluesIF::RETURN_OK); + REQUIRE(((buf[9] << 8) | buf[10]) == 0x5ff); + } + + SECTION("Test with Application Data Raw") { + auto& params = creator.getPusParams(); + std::array data{1, 2, 3}; + params.dataWrapper.setRawData({data.data(), data.size()}); + // To get correct size information, the SP length field needs to be updated automatically + REQUIRE(creator.getSerializedSize() == 13); + creator.updateSpLengthField(); + REQUIRE(creator.getSerializedSize() == 16); + REQUIRE(creator.serialize(&dataPtr, &serLen, buf.size()) == HasReturnvaluesIF::RETURN_OK); + REQUIRE(serLen == 16); + REQUIRE(buf[11] == 1); + REQUIRE(buf[12] == 2); + REQUIRE(buf[13] == 3); + } + + SECTION("Test with Application Data Serializable") { + auto& params = creator.getPusParams(); + auto simpleSer = SimpleSerializable(); + params.dataWrapper.setSerializable(&simpleSer); + auto& dataWrapper = creator.getDataWrapper(); + REQUIRE(dataWrapper.type == ecss::DataTypes::SERIALIZABLE); + REQUIRE(dataWrapper.dataUnion.serializable == &simpleSer); + REQUIRE(creator.getSerializedSize() == 13); + creator.updateSpLengthField(); + REQUIRE(creator.getSerializedSize() == 16); + REQUIRE(creator.serialize(&dataPtr, &serLen, buf.size()) == HasReturnvaluesIF::RETURN_OK); + REQUIRE(serLen == 16); + REQUIRE(buf[11] == 1); + REQUIRE(buf[12] == 2); + REQUIRE(buf[13] == 3); + } + + SECTION("Deserialization Fails") { + size_t deserLen = buf.size(); + const uint8_t* roPtr = buf.data(); + REQUIRE(creator.deSerialize(&roPtr, &deserLen, SerializeIF::Endianness::NETWORK) == + HasReturnvaluesIF::RETURN_FAILED); + } + + SECTION("Serialize with invalid buffer length") { + size_t reqSize = creator.getSerializedSize(); + for (size_t maxSize = 0; maxSize < reqSize; maxSize++) { + dataPtr = buf.data(); + serLen = 0; + REQUIRE(creator.serialize(&dataPtr, &serLen, maxSize) == SerializeIF::BUFFER_TOO_SHORT); + } + } + + SECTION("Invalid PUS Version") { + auto& params = creator.getPusParams(); + params.pusVersion = 0; + REQUIRE(creator.serialize(&dataPtr, &serLen, buf.size()) == PusIF::INVALID_PUS_VERSION); + } +} \ No newline at end of file -- 2.43.0 From 61bc867bede37c2f537c338142b4855adeea1a5c Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Thu, 21 Jul 2022 17:57:31 +0200 Subject: [PATCH 021/108] delete code which is not used anymore --- .../pus/Service1TelecommandVerification.cpp | 1 - src/fsfw/pus/Service5EventReporting.cpp | 1 - src/fsfw/tmtcpacket/cfdp/CfdpPacketStored.h | 2 +- src/fsfw/tmtcpacket/pus/tc/CMakeLists.txt | 2 - src/fsfw/tmtcpacket/pus/tc/TcPacketPus.cpp | 99 ------------- src/fsfw/tmtcpacket/pus/tc/TcPacketPus.h | 69 --------- .../tmtcpacket/pus/tc/TcPacketStoredBase.cpp | 64 --------- .../tmtcpacket/pus/tc/TcPacketStoredBase.h | 84 ----------- src/fsfw/tmtcpacket/pus/tm.h | 13 +- src/fsfw/tmtcpacket/pus/tm/TmPacketBase.cpp | 63 -------- src/fsfw/tmtcpacket/pus/tm/TmPacketBase.h | 135 ------------------ src/fsfw/tmtcpacket/pus/tm/TmPacketPusC.cpp | 79 ---------- src/fsfw/tmtcpacket/pus/tm/TmPacketPusC.h | 126 ---------------- src/fsfw/tmtcpacket/pus/tm/TmPacketStored.h | 12 -- .../tmtcpacket/pus/tm/TmPacketStoredBase.cpp | 121 ---------------- .../tmtcpacket/pus/tm/TmPacketStoredBase.h | 86 ----------- .../tmtcpacket/pus/tm/TmPacketStoredPusC.cpp | 76 ---------- .../tmtcpacket/pus/tm/TmPacketStoredPusC.h | 73 ---------- unittests/CatchFactory.cpp | 1 - 19 files changed, 3 insertions(+), 1104 deletions(-) delete mode 100644 src/fsfw/tmtcpacket/pus/tc/TcPacketPus.cpp delete mode 100644 src/fsfw/tmtcpacket/pus/tc/TcPacketPus.h delete mode 100644 src/fsfw/tmtcpacket/pus/tc/TcPacketStoredBase.cpp delete mode 100644 src/fsfw/tmtcpacket/pus/tc/TcPacketStoredBase.h delete mode 100644 src/fsfw/tmtcpacket/pus/tm/TmPacketBase.cpp delete mode 100644 src/fsfw/tmtcpacket/pus/tm/TmPacketBase.h delete mode 100644 src/fsfw/tmtcpacket/pus/tm/TmPacketPusC.cpp delete mode 100644 src/fsfw/tmtcpacket/pus/tm/TmPacketPusC.h delete mode 100644 src/fsfw/tmtcpacket/pus/tm/TmPacketStored.h delete mode 100644 src/fsfw/tmtcpacket/pus/tm/TmPacketStoredBase.cpp delete mode 100644 src/fsfw/tmtcpacket/pus/tm/TmPacketStoredBase.h delete mode 100644 src/fsfw/tmtcpacket/pus/tm/TmPacketStoredPusC.cpp delete mode 100644 src/fsfw/tmtcpacket/pus/tm/TmPacketStoredPusC.h diff --git a/src/fsfw/pus/Service1TelecommandVerification.cpp b/src/fsfw/pus/Service1TelecommandVerification.cpp index 4b326096..35957ba0 100644 --- a/src/fsfw/pus/Service1TelecommandVerification.cpp +++ b/src/fsfw/pus/Service1TelecommandVerification.cpp @@ -3,7 +3,6 @@ #include "fsfw/ipc/QueueFactory.h" #include "fsfw/objectmanager/ObjectManager.h" #include "fsfw/pus/servicepackets/Service1Packets.h" -#include "fsfw/tmtcpacket/pus/tm/TmPacketStored.h" #include "fsfw/tmtcservices/AcceptsTelemetryIF.h" #include "fsfw/tmtcservices/PusVerificationReport.h" #include "fsfw/tmtcservices/tmHelpers.h" diff --git a/src/fsfw/pus/Service5EventReporting.cpp b/src/fsfw/pus/Service5EventReporting.cpp index a0cbc316..31cc72f5 100644 --- a/src/fsfw/pus/Service5EventReporting.cpp +++ b/src/fsfw/pus/Service5EventReporting.cpp @@ -5,7 +5,6 @@ #include "fsfw/objectmanager/ObjectManager.h" #include "fsfw/pus/servicepackets/Service5Packets.h" #include "fsfw/serviceinterface/ServiceInterface.h" -#include "fsfw/tmtcpacket/pus/tm/TmPacketStored.h" #include "fsfw/tmtcservices/tmHelpers.h" Service5EventReporting::Service5EventReporting(object_id_t objectId, uint16_t apid, diff --git a/src/fsfw/tmtcpacket/cfdp/CfdpPacketStored.h b/src/fsfw/tmtcpacket/cfdp/CfdpPacketStored.h index 54f8e5be..60a9524f 100644 --- a/src/fsfw/tmtcpacket/cfdp/CfdpPacketStored.h +++ b/src/fsfw/tmtcpacket/cfdp/CfdpPacketStored.h @@ -1,8 +1,8 @@ #ifndef FSFW_TMTCPACKET_CFDP_CFDPPACKETSTORED_H_ #define FSFW_TMTCPACKET_CFDP_CFDPPACKETSTORED_H_ -#include "../pus/tc/TcPacketStoredBase.h" #include "CfdpPacket.h" +#include "fsfw/storagemanager/storeAddress.h" class CfdpPacketStored : public CfdpReader { public: diff --git a/src/fsfw/tmtcpacket/pus/tc/CMakeLists.txt b/src/fsfw/tmtcpacket/pus/tc/CMakeLists.txt index d2e30586..adf7f34d 100644 --- a/src/fsfw/tmtcpacket/pus/tc/CMakeLists.txt +++ b/src/fsfw/tmtcpacket/pus/tc/CMakeLists.txt @@ -1,4 +1,2 @@ target_sources(${LIB_FSFW_NAME} PRIVATE PusTcReader.cpp PusTcReader.cpp PusTcCreator.cpp) - -# TcPacketPus.cpp diff --git a/src/fsfw/tmtcpacket/pus/tc/TcPacketPus.cpp b/src/fsfw/tmtcpacket/pus/tc/TcPacketPus.cpp deleted file mode 100644 index 06f980b7..00000000 --- a/src/fsfw/tmtcpacket/pus/tc/TcPacketPus.cpp +++ /dev/null @@ -1,99 +0,0 @@ -#include "TcPacketPus.h" - -#include - -#include "fsfw/globalfunctions/CRC.h" - -TcPacketPus::TcPacketPus(const uint8_t *setData) : TcPacketPusBase(setData) { - tcData = reinterpret_cast(const_cast(setData)); -} - -void TcPacketPus::initializeTcPacket(uint16_t apid, uint16_t sequenceCount, uint8_t ack, - uint8_t service, uint8_t subservice, - 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); - // Data Field Header. For PUS A, the first bit (CCSDS Secondary Header Flag) is zero - tcData->dataField.versionTypeAck = pusVersion << 4 | (ack & 0x0F); - tcData->dataField.serviceType = service; - tcData->dataField.serviceSubtype = subservice; -#if FSFW_USE_PUS_C_TELECOMMANDS == 1 - tcData->dataField.sourceIdH = (sourceId >> 8) | 0xff; - tcData->dataField.sourceIdL = sourceId & 0xff; -#else - tcData->dataField.sourceId = sourceId; -#endif -} - -uint8_t TcPacketPus::getService() const { return tcData->dataField.serviceType; } - -uint8_t TcPacketPus::getSubService() const { return tcData->dataField.serviceSubtype; } - -uint8_t TcPacketPus::getAcknowledgeFlags() const { - return tcData->dataField.versionTypeAck & 0b00001111; -} - -const uint8_t *TcPacketPus::getApplicationData() const { return &tcData->appData; } - -uint16_t TcPacketPus::getApplicationDataSize() const { - return SpacePacketReader::getPacketDataLen() - sizeof(tcData->dataField) - CRC_SIZE + 1; -} - -uint16_t TcPacketPus::getErrorControl() const { - uint16_t size = getApplicationDataSize() + CRC_SIZE; - uint8_t *p_to_buffer = &tcData->appData; - return (p_to_buffer[size - 2] << 8) + p_to_buffer[size - 1]; -} - -void TcPacketPus::setErrorControl() { - uint32_t full_size = getFullSize(); - uint16_t crc = CRC::crc16ccitt(getWholeData(), full_size - CRC_SIZE); - uint32_t size = getApplicationDataSize(); - (&tcData->appData)[size] = (crc & 0XFF00) >> 8; // CRCH - (&tcData->appData)[size + 1] = (crc)&0X00FF; // CRCL -} - -uint8_t TcPacketPus::getSecondaryHeaderFlag() const { -#if FSFW_USE_PUS_C_TELECOMMANDS == 1 - // Does not exist for PUS C - return 0; -#else - return (tcData->dataField.versionTypeAck & 0b10000000) >> 7; -#endif -} - -uint8_t TcPacketPus::getPusVersionNumber() const { -#if FSFW_USE_PUS_C_TELECOMMANDS == 1 - return (tcData->dataField.versionTypeAck & 0b11110000) >> 4; -#else - return (tcData->dataField.versionTypeAck & 0b01110000) >> 4; -#endif -} - -uint16_t TcPacketPus::getSourceId() const { -#if FSFW_USE_PUS_C_TELECOMMANDS == 1 - return (tcData->dataField.sourceIdH << 8) | tcData->dataField.sourceIdL; -#else - return tcData->dataField.sourceId; -#endif -} - -size_t TcPacketPus::calculateFullPacketLength(size_t appDataLen) const { - return sizeof(CCSDSPrimaryHeader) + sizeof(PUSTcDataFieldHeader) + appDataLen + - TcPacketPusBase::CRC_SIZE; -} - -ReturnValue_t TcPacketPus::setData(uint8_t *dataPtr, size_t maxSize, void *args) { - ReturnValue_t result = SpacePacketReader::setData(dataPtr, maxSize, args); - if (result != HasReturnvaluesIF::RETURN_OK) { - return result; - } - if (maxSize < sizeof(TcPacketPointer)) { - return HasReturnvaluesIF::RETURN_FAILED; - } - // This function is const-correct, but it was decided to keep the pointer non-const - // for convenience. Therefore, cast away constness here and then cast to packet type. - tcData = reinterpret_cast(const_cast(dataPtr)); - return HasReturnvaluesIF::RETURN_OK; -} diff --git a/src/fsfw/tmtcpacket/pus/tc/TcPacketPus.h b/src/fsfw/tmtcpacket/pus/tc/TcPacketPus.h deleted file mode 100644 index 8af6125a..00000000 --- a/src/fsfw/tmtcpacket/pus/tc/TcPacketPus.h +++ /dev/null @@ -1,69 +0,0 @@ -#ifndef FSFW_TMTCPACKET_PUS_TCPACKETPUSA_H_ -#define FSFW_TMTCPACKET_PUS_TCPACKETPUSA_H_ - -#include - -#include "../defs.h" -#include "PusTcReader.h" -#include "fsfw/FSFW.h" -#include "fsfw/tmtcpacket/ccsds/defs.h" - -/** - * This struct defines the data structure of a PUS Telecommand A packet when - * accessed via a pointer. - * @ingroup tmtcpackets - */ -/* -struct TcPacketPointer { - CCSDSPrimaryHeader primary; - PusTcDataFieldHeader dataField; - uint8_t appData; -}; - */ - -// 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/TcPacketStoredBase.cpp b/src/fsfw/tmtcpacket/pus/tc/TcPacketStoredBase.cpp deleted file mode 100644 index 88964bfb..00000000 --- a/src/fsfw/tmtcpacket/pus/tc/TcPacketStoredBase.cpp +++ /dev/null @@ -1,64 +0,0 @@ -#include "fsfw/tmtcpacket/pus/tc/TcPacketStoredBase.h" - -#include - -#include "fsfw/objectmanager/ObjectManager.h" -#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; } diff --git a/src/fsfw/tmtcpacket/pus/tc/TcPacketStoredBase.h b/src/fsfw/tmtcpacket/pus/tc/TcPacketStoredBase.h deleted file mode 100644 index 8291ac6c..00000000 --- a/src/fsfw/tmtcpacket/pus/tc/TcPacketStoredBase.h +++ /dev/null @@ -1,84 +0,0 @@ -#ifndef TMTCPACKET_PUS_TCPACKETSTORED_H_ -#define TMTCPACKET_PUS_TCPACKETSTORED_H_ - -#include "PusTcReader.h" -#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(); -//}; - -#endif /* TMTCPACKET_PUS_TCPACKETSTORED_H_ */ diff --git a/src/fsfw/tmtcpacket/pus/tm.h b/src/fsfw/tmtcpacket/pus/tm.h index 657790f4..619f9e01 100644 --- a/src/fsfw/tmtcpacket/pus/tm.h +++ b/src/fsfw/tmtcpacket/pus/tm.h @@ -1,16 +1,7 @@ #ifndef FSFW_TMTCPACKET_PUS_TM_H_ #define FSFW_TMTCPACKET_PUS_TM_H_ -#include "fsfw/FSFW.h" - -#if FSFW_USE_PUS_C_TELEMETRY == 1 -#include "tm/TmPacketPusC.h" -#include "tm/TmPacketStoredPusC.h" -#else -#include "tm/TmPacketPusA.h" -#include "tm/TmPacketStoredPusA.h" -#endif - -#include "tm/PusTmMinimal.h" +#include "tm/PusTmCreator.h" +#include "tm/PusTmReader.h" #endif /* FSFW_TMTCPACKET_PUS_TM_H_ */ diff --git a/src/fsfw/tmtcpacket/pus/tm/TmPacketBase.cpp b/src/fsfw/tmtcpacket/pus/tm/TmPacketBase.cpp deleted file mode 100644 index c81c2d4d..00000000 --- a/src/fsfw/tmtcpacket/pus/tm/TmPacketBase.cpp +++ /dev/null @@ -1,63 +0,0 @@ -#include "fsfw/tmtcpacket/pus/tm/TmPacketBase.h" - -#include - -#include "fsfw/globalfunctions/CRC.h" -#include "fsfw/globalfunctions/arrayprinter.h" -#include "fsfw/objectmanager/ObjectManager.h" -#include "fsfw/serviceinterface/ServiceInterface.h" -#include "fsfw/timemanager/CCSDSTime.h" - -TimeStamperIF* TmPacketBase::timeStamper = nullptr; -object_id_t TmPacketBase::timeStamperId = objects::NO_OBJECT; - -TmPacketBase::TmPacketBase(uint8_t* setData) : SpacePacketReader(setData) {} - -TmPacketBase::~TmPacketBase() = default; - -uint16_t TmPacketBase::getSourceDataSize() { - return SpacePacketReader::getPacketDataLen() - getDataFieldSize() - CRC_SIZE + 1; -} - -uint16_t TmPacketBase::getErrorControl() { - uint32_t size = getSourceDataSize() + CRC_SIZE; - uint8_t* p_to_buffer = getSourceData(); - return (p_to_buffer[size - 2] << 8) + p_to_buffer[size - 1]; -} - -void TmPacketBase::setErrorControl() { - uint32_t full_size = getFullSize(); - uint16_t crc = CRC::crc16ccitt(getWholeData(), full_size - CRC_SIZE); - uint32_t size = getSourceDataSize(); - getSourceData()[size] = (crc & 0XFF00) >> 8; // CRCH - getSourceData()[size + 1] = (crc)&0X00FF; // CRCL -} - -ReturnValue_t TmPacketBase::getPacketTime(timeval* timestamp) const { - size_t tempSize = 0; - return CCSDSTime::convertFromCcsds(timestamp, getPacketTimeRaw(), &tempSize, getTimestampSize()); -} - -bool TmPacketBase::checkAndSetStamper() { - if (timeStamper == nullptr) { - timeStamper = ObjectManager::instance()->get(timeStamperId); - if (timeStamper == nullptr) { -#if FSFW_CPP_OSTREAM_ENABLED == 1 - sif::warning << "TmPacketBase::checkAndSetStamper: Stamper not found!" << std::endl; -#else - sif::printWarning("TmPacketBase::checkAndSetStamper: Stamper not found!\n"); -#endif - return false; - } - } - return true; -} - -void TmPacketBase::print() { -#if FSFW_CPP_OSTREAM_ENABLED == 1 - sif::info << "TmPacketBase::print:" << std::endl; -#else - sif::printInfo("TmPacketBase::print:\n"); -#endif - arrayprinter::print(getWholeData(), getFullSize()); -} diff --git a/src/fsfw/tmtcpacket/pus/tm/TmPacketBase.h b/src/fsfw/tmtcpacket/pus/tm/TmPacketBase.h deleted file mode 100644 index fe7619cf..00000000 --- a/src/fsfw/tmtcpacket/pus/tm/TmPacketBase.h +++ /dev/null @@ -1,135 +0,0 @@ -#ifndef TMTCPACKET_PUS_TMPACKETBASE_H_ -#define TMTCPACKET_PUS_TMPACKETBASE_H_ - -#include "fsfw/objectmanager/SystemObjectIF.h" -#include "fsfw/timemanager/Clock.h" -#include "fsfw/timemanager/TimeStamperIF.h" -#include "fsfw/tmtcpacket/ccsds/SpacePacketReader.h" - -namespace Factory { - -void setStaticFrameworkObjectIds(); - -} - -/** - * This class is the basic data handler for any ECSS PUS Telemetry packet. - * - * In addition to #SpacePacketBase, the class provides methods to handle - * the standardized entries of the PUS TM Packet Data Field Header. - * It does not contain the packet data itself but a pointer to the - * data must be set on instantiation. An invalid pointer may cause - * damage, as no getter method checks data validity. Anyway, a NULL - * check can be performed by making use of the getWholeData method. - * @ingroup tmtcpackets - */ -class TmPacketBase : public SpacePacketReader { - friend void(Factory::setStaticFrameworkObjectIds)(); - - public: - //! Maximum size of a TM Packet in this mission. - //! TODO: Make this dependant on a config variable. - static const uint32_t MISSION_TM_PACKET_MAX_SIZE = 2048; - - /** - * 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 set_address The position where the packet data lies. - */ - TmPacketBase(uint8_t* setData); - /** - * This is the empty default destructor. - */ - virtual ~TmPacketBase(); - - /** - * 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. - */ - virtual uint8_t getService() = 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. - */ - virtual uint8_t getSubService() = 0; - /** - * This is a getter for a pointer to the packet's Source data. - * - * These are the bytes that follow after the Data Field Header. They form - * the packet's source data. - * @return A pointer to the PUS Source Data. - */ - virtual uint8_t* getSourceData() = 0; - /** - * This method calculates the size of the PUS Source 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 Source Data (without Error Control field) - */ - virtual uint16_t getSourceDataSize() = 0; - - /** - * Get size of data field which can differ based on implementation - * @return - */ - virtual uint16_t getDataFieldSize() = 0; - - virtual size_t getPacketMinimumSize() const = 0; - - /** - * Interprets the "time"-field in the secondary header and returns it in - * timeval format. - * @return Converted timestamp of packet. - */ - virtual ReturnValue_t getPacketTime(timeval* timestamp) const; - /** - * Returns a raw pointer to the beginning of the time field. - * @return Raw pointer to time field. - */ - virtual uint8_t* getPacketTimeRaw() const = 0; - - virtual size_t getTimestampSize() const = 0; - - /** - * This is a debugging helper method that prints the whole packet content - * to the screen. - */ - void print(); - /** - * With this method, the Error Control Field is updated to match the - * current content of the packet. This method is not protected because - * a recalculation by the user might be necessary when manipulating fields - * like the sequence count. - */ - void setErrorControl(); - /** - * This getter returns the Error Control Field of the packet. - * - * The field is placed after any possible Source Data. If no - * Source Data is present there's still an Error Control field. It is - * supposed to be a 16bit-CRC. - * @return The PUS Error Control - */ - uint16_t getErrorControl(); - - protected: - /** - * The timeStamper is responsible for adding a timestamp to the packet. - * It is initialized lazy. - */ - static TimeStamperIF* timeStamper; - //! The ID to use when looking for a time stamper. - static object_id_t timeStamperId; - - /** - * Checks if a time stamper is available and tries to set it if not. - * @return Returns false if setting failed. - */ - bool checkAndSetStamper(); -}; - -#endif /* TMTCPACKET_PUS_TMPACKETBASE_H_ */ diff --git a/src/fsfw/tmtcpacket/pus/tm/TmPacketPusC.cpp b/src/fsfw/tmtcpacket/pus/tm/TmPacketPusC.cpp deleted file mode 100644 index 5c35c540..00000000 --- a/src/fsfw/tmtcpacket/pus/tm/TmPacketPusC.cpp +++ /dev/null @@ -1,79 +0,0 @@ -#include "TmPacketPusC.h" - -#include - -#include "../defs.h" -#include "TmPacketBase.h" -#include "fsfw/globalfunctions/CRC.h" -#include "fsfw/globalfunctions/arrayprinter.h" -#include "fsfw/objectmanager/ObjectManagerIF.h" -#include "fsfw/serviceinterface/ServiceInterface.h" -#include "fsfw/timemanager/CCSDSTime.h" - -TmPacketPusC::TmPacketPusC(uint8_t* setData) : TmPacketBase(setData) { - tmData = reinterpret_cast(setData); -} - -TmPacketPusC::~TmPacketPusC() = default; - -uint8_t TmPacketPusC::getService() { return tmData->dataField.serviceType; } - -uint8_t TmPacketPusC::getSubService() { return tmData->dataField.serviceSubtype; } - -uint8_t* TmPacketPusC::getSourceData() { return &tmData->data; } - -uint16_t TmPacketPusC::getSourceDataSize() { - return SpacePacketReader::getPacketDataLen() - sizeof(tmData->dataField) - CRC_SIZE + 1; -} - -ReturnValue_t TmPacketPusC::setData(uint8_t* p_Data, size_t maxSize, void* args) { - ReturnValue_t result = SpacePacketReader::setData(p_Data, maxSize, args); - if (result != HasReturnvaluesIF::RETURN_OK) { - return result; - } - if (maxSize < sizeof(TmPacketPointerPusC)) { - return HasReturnvaluesIF::RETURN_OK; - } - tmData = reinterpret_cast(const_cast(p_Data)); - return HasReturnvaluesIF::RETURN_OK; -} - -size_t TmPacketPusC::getPacketMinimumSize() const { return TM_PACKET_MIN_SIZE; } - -uint16_t TmPacketPusC::getDataFieldSize() { return sizeof(PUSTmDataFieldHeaderPusC); } - -uint8_t* TmPacketPusC::getPacketTimeRaw() const { return tmData->dataField.time; } - -ReturnValue_t TmPacketPusC::initializeTmPacket(uint16_t apid, uint8_t service, uint8_t subservice, - uint16_t packetSubcounter, uint16_t destinationId, - uint8_t timeRefField) { - // Set primary header: - ReturnValue_t result = initSpacePacketHeader(false, true, apid); - if (result != HasReturnvaluesIF::RETURN_OK) { - return result; - } - // Set data Field Header: - // First, set to zero. - memset(&tmData->dataField, 0, sizeof(tmData->dataField)); - - /* Only account for last 4 bytes for time reference field */ - timeRefField &= 0b1111; - tmData->dataField.versionTimeReferenceField = (ecss::PusVersion::PUS_C << 4) | timeRefField; - tmData->dataField.serviceType = service; - tmData->dataField.serviceSubtype = subservice; - tmData->dataField.subcounterMsb = (packetSubcounter << 8) & 0xff; - tmData->dataField.subcounterLsb = packetSubcounter & 0xff; - tmData->dataField.destinationIdMsb = (destinationId << 8) & 0xff; - tmData->dataField.destinationIdLsb = destinationId & 0xff; - // Timestamp packet - if (TmPacketBase::checkAndSetStamper()) { - timeStamper->addTimeStamp(tmData->dataField.time, sizeof(tmData->dataField.time)); - } - return HasReturnvaluesIF::RETURN_OK; -} - -void TmPacketPusC::setSourceDataSize(uint16_t size) { - setPacketDataLength(size + sizeof(PUSTmDataFieldHeaderPusC) + CRC_SIZE - 1); -} - -size_t TmPacketPusC::getTimestampSize() const { return sizeof(tmData->dataField.time); } diff --git a/src/fsfw/tmtcpacket/pus/tm/TmPacketPusC.h b/src/fsfw/tmtcpacket/pus/tm/TmPacketPusC.h deleted file mode 100644 index c68deadd..00000000 --- a/src/fsfw/tmtcpacket/pus/tm/TmPacketPusC.h +++ /dev/null @@ -1,126 +0,0 @@ -#ifndef FSFW_TMTCPACKET_PUS_TMPACKETPUSC_H_ -#define FSFW_TMTCPACKET_PUS_TMPACKETPUSC_H_ - -#include "TmPacketBase.h" -#include "fsfw/objectmanager/SystemObjectIF.h" -#include "fsfw/timemanager/Clock.h" -#include "fsfw/timemanager/TimeStamperIF.h" -#include "fsfw/tmtcpacket/ccsds/SpacePacketReader.h" - -namespace Factory { -void setStaticFrameworkObjectIds(); -} - -/** - * This struct defines a byte-wise structured PUS TM Data Field Header. - * Any optional fields in the header must be added or removed here. - * Currently, no Destination field is present, but an eigth-byte representation - * for a time tag. - * @ingroup tmtcpackets - */ -struct PUSTmDataFieldHeaderPusC { - uint8_t versionTimeReferenceField; - uint8_t serviceType; - uint8_t serviceSubtype; - uint8_t subcounterMsb; - uint8_t subcounterLsb; - uint8_t destinationIdMsb; - uint8_t destinationIdLsb; - // uint8_t time[TimeStamperIF::MISSION_TIMESTAMP_SIZE]; -}; - -/** - * This struct defines the data structure of a PUS Telecommand Packet when - * accessed via a pointer. - * @ingroup tmtcpackets - */ -struct TmPacketPointerPusC { - ccsds::PrimaryHeader primary; - PUSTmDataFieldHeaderPusC dataField; - uint8_t data; -}; - -/** - * PUS A packet implementation - * @ingroup tmtcpackets - */ -class TmPacketPusC : public TmPacketBase { - friend void(Factory::setStaticFrameworkObjectIds)(); - - public: - /** - * This constant defines the minimum size of a valid PUS Telemetry Packet. - */ - static const uint32_t TM_PACKET_MIN_SIZE = - ccsds::HEADER_LEN + sizeof(PUSTmDataFieldHeaderPusC) + 2; - //! Maximum size of a TM Packet in this mission. - static const uint32_t MISSION_TM_PACKET_MAX_SIZE = fsfwconfig::FSFW_MAX_TM_PACKET_SIZE; - - /** - * 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 set_address The position where the packet data lies. - */ - TmPacketPusC(uint8_t* setData); - /** - * This is the empty default destructor. - */ - virtual ~TmPacketPusC(); - - /* TmPacketBase implementations */ - uint8_t getService() override; - uint8_t getSubService() override; - uint8_t* getSourceData() override; - uint16_t getSourceDataSize() override; - uint16_t getDataFieldSize() override; - - /** - * Returns a raw pointer to the beginning of the time field. - * @return Raw pointer to time field. - */ - uint8_t* getPacketTimeRaw() const override; - size_t getTimestampSize() const override; - - size_t getPacketMinimumSize() const override; - - protected: - /** - * 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. - */ - TmPacketPointerPusC* tmData; - - /** - * Initializes the Tm Packet header. - * Does set the timestamp (to now), but not the error control field. - * @param apid APID used. - * @param service PUS Service - * @param subservice PUS Subservice - * @param packetSubcounter Additional subcounter used. - */ - ReturnValue_t initializeTmPacket(uint16_t apid, uint8_t service, uint8_t subservice, - uint16_t packetSubcounter, uint16_t destinationId = 0, - uint8_t timeRefField = 0); - - /** - * With this method, the packet data pointer can be redirected to another - * location. - * - * This call overwrites the parent's setData method to set both its - * @c tc_data pointer and the parent's @c data pointer. - * - * @param pData A pointer to another PUS Telemetry Packet. - */ - ReturnValue_t setData(uint8_t* pData, size_t maxSize, void* args) override; - - /** - * In case data was filled manually (almost never the case). - * @param size Size of source data (without CRC and data filed header!). - */ - void setSourceDataSize(uint16_t size); -}; - -#endif /* FSFW_TMTCPACKET_PUS_TMPACKETPUSC_H_ */ diff --git a/src/fsfw/tmtcpacket/pus/tm/TmPacketStored.h b/src/fsfw/tmtcpacket/pus/tm/TmPacketStored.h deleted file mode 100644 index de10655f..00000000 --- a/src/fsfw/tmtcpacket/pus/tm/TmPacketStored.h +++ /dev/null @@ -1,12 +0,0 @@ -#ifndef FSFW_TMTCPACKET_PUS_TMPACKETSTORED_H_ -#define FSFW_TMTCPACKET_PUS_TMPACKETSTORED_H_ - -#include - -#if FSFW_USE_PUS_C_TELEMETRY == 1 -#include "TmPacketStoredPusC.h" -#else -#include "TmPacketStoredPusA.h" -#endif - -#endif /* FSFW_TMTCPACKET_PUS_TMPACKETSTORED_H_ */ diff --git a/src/fsfw/tmtcpacket/pus/tm/TmPacketStoredBase.cpp b/src/fsfw/tmtcpacket/pus/tm/TmPacketStoredBase.cpp deleted file mode 100644 index 4d37bf46..00000000 --- a/src/fsfw/tmtcpacket/pus/tm/TmPacketStoredBase.cpp +++ /dev/null @@ -1,121 +0,0 @@ -#include "fsfw/tmtcpacket/pus/tm/TmPacketStoredBase.h" - -#include - -#include "fsfw/objectmanager/ObjectManager.h" -#include "fsfw/serviceinterface/ServiceInterface.h" -#include "fsfw/tmtcservices/TmTcMessage.h" - -StorageManagerIF *TmPacketStoredBase::store = nullptr; -InternalErrorReporterIF *TmPacketStoredBase::internalErrorReporter = nullptr; - -TmPacketStoredBase::TmPacketStoredBase(store_address_t setAddress) : storeAddress(setAddress) { - setStoreAddress(storeAddress); -} - -TmPacketStoredBase::TmPacketStoredBase() {} - -TmPacketStoredBase::~TmPacketStoredBase() {} - -store_address_t TmPacketStoredBase::getStoreAddress() { return storeAddress; } - -void TmPacketStoredBase::deletePacket() { - store->deleteData(storeAddress); - storeAddress.raw = StorageManagerIF::INVALID_ADDRESS; - setData(nullptr, -1); -} - -void TmPacketStoredBase::setStoreAddress(store_address_t setAddress) { - storeAddress = setAddress; - const uint8_t *tempData = nullptr; - size_t tempSize; - if (not checkAndSetStore()) { - return; - } - ReturnValue_t status = store->getData(storeAddress, &tempData, &tempSize); - if (status == StorageManagerIF::RETURN_OK) { - setData(const_cast(tempData), tempSize); - } else { - setData(nullptr, -1); - storeAddress.raw = StorageManagerIF::INVALID_ADDRESS; - } -} - -bool TmPacketStoredBase::checkAndSetStore() { - if (store == nullptr) { - store = ObjectManager::instance()->get(objects::TM_STORE); - if (store == nullptr) { -#if FSFW_CPP_OSTREAM_ENABLED == 1 - sif::error << "TmPacketStored::TmPacketStored: TM Store not found!" << std::endl; -#endif - return false; - } - } - return true; -} - -ReturnValue_t TmPacketStoredBase::sendPacket(MessageQueueId_t destination, - MessageQueueId_t sentFrom, bool doErrorReporting) { - if (getAllTmData() == nullptr) { - // SHOULDDO: More decent code. - return HasReturnvaluesIF::RETURN_FAILED; - } - TmTcMessage tmMessage(getStoreAddress()); - ReturnValue_t result = MessageQueueSenderIF::sendMessage(destination, &tmMessage, sentFrom); - if (result != HasReturnvaluesIF::RETURN_OK) { - deletePacket(); - if (doErrorReporting) { - checkAndReportLostTm(); - } - return result; - } - // SHOULDDO: In many cases, some counter is incremented for successfully sent packets. The check - // is often not done, but just incremented. - return HasReturnvaluesIF::RETURN_OK; -} - -void TmPacketStoredBase::checkAndReportLostTm() { - if (internalErrorReporter == nullptr) { - internalErrorReporter = - ObjectManager::instance()->get(objects::INTERNAL_ERROR_REPORTER); - } - if (internalErrorReporter != nullptr) { - internalErrorReporter->lostTm(); - } -} - -void TmPacketStoredBase::handleStoreFailure(const char *const packetType, ReturnValue_t result, - size_t sizeToReserve) { - checkAndReportLostTm(); -#if FSFW_VERBOSE_LEVEL >= 1 - switch (result) { -#if FSFW_CPP_OSTREAM_ENABLED == 1 - case (StorageManagerIF::DATA_STORAGE_FULL): { - sif::warning << "TmPacketStoredPus" << packetType << ": " - << "Store full for packet with size" << sizeToReserve << std::endl; - break; - } - case (StorageManagerIF::DATA_TOO_LARGE): { - sif::warning << "TmPacketStoredPus" << packetType << ": Data with size " << sizeToReserve - << " too large" << std::endl; - break; - } -#else - case (StorageManagerIF::DATA_STORAGE_FULL): { - sif::printWarning( - "TmPacketStoredPus%s: Store full for packet with " - "size %d\n", - packetType, sizeToReserve); - break; - } - case (StorageManagerIF::DATA_TOO_LARGE): { - sif::printWarning( - "TmPacketStoredPus%s: Data with size " - "%d too large\n", - packetType, sizeToReserve); - break; - } -#endif - } -#endif -} diff --git a/src/fsfw/tmtcpacket/pus/tm/TmPacketStoredBase.h b/src/fsfw/tmtcpacket/pus/tm/TmPacketStoredBase.h deleted file mode 100644 index 85363ee9..00000000 --- a/src/fsfw/tmtcpacket/pus/tm/TmPacketStoredBase.h +++ /dev/null @@ -1,86 +0,0 @@ -#ifndef FSFW_TMTCPACKET_PUS_TMPACKETSTOREDBASE_H_ -#define FSFW_TMTCPACKET_PUS_TMPACKETSTOREDBASE_H_ - -#include "TmPacketBase.h" -#include "TmPacketStoredBase.h" -#include "fsfw/FSFW.h" -#include "fsfw/internalerror/InternalErrorReporterIF.h" -#include "fsfw/ipc/MessageQueueSenderIF.h" -#include "fsfw/serialize/SerializeIF.h" -#include "fsfw/storagemanager/StorageManagerIF.h" - -/** - * This class generates a ECSS PUS Telemetry packet within a given - * intermediate storage. - * As most packets are passed between tasks with the help of a storage - * anyway, it seems logical to create a Packet-In-Storage access class - * which saves the user almost all storage handling operation. - * Packets can both be newly created with the class and be "linked" to - * packets in a store with the help of a storeAddress. - * @ingroup tmtcpackets - */ -class TmPacketStoredBase : virtual public RedirectableDataPointerIF { - public: - /** - * This is a default constructor which does not set the data pointer. - * However, it does try to set the packet store. - */ - TmPacketStoredBase(store_address_t setAddress); - TmPacketStoredBase(); - - virtual ~TmPacketStoredBase(); - - virtual uint8_t* getAllTmData() = 0; - - /** - * This is a getter for the current store address of the packet. - * @return The current store address. The (raw) value is - * @c StorageManagerIF::INVALID_ADDRESS if - * the packet is not linked. - */ - store_address_t getStoreAddress(); - /** - * With this call, the packet is deleted. - * It removes itself from the store and sets its data pointer to NULL. - */ - void deletePacket(); - /** - * With this call, a packet can be linked to another store. This is useful - * if the packet is a class member and used for more than one packet. - * @param setAddress The new packet id to link to. - */ - void setStoreAddress(store_address_t setAddress); - - ReturnValue_t sendPacket(MessageQueueId_t destination, MessageQueueId_t sentFrom, - bool doErrorReporting = true); - - 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::TM_STORE. - */ - static StorageManagerIF* store; - - static InternalErrorReporterIF* internalErrorReporter; - - /** - * The address where the packet data of the object instance is stored. - */ - store_address_t storeAddress; - /** - * A helper method to check if a store is assigned to the class. - * If not, the method tries to retrieve the store from the global - * ObjectManager. - * @return @li @c true if the store is linked or could be created. - * @li @c false otherwise. - */ - bool checkAndSetStore(); - - void checkAndReportLostTm(); - - void handleStoreFailure(const char* const packetType, ReturnValue_t result, size_t sizeToReserve); -}; - -#endif /* FSFW_TMTCPACKET_PUS_TMPACKETSTOREDBASE_H_ */ diff --git a/src/fsfw/tmtcpacket/pus/tm/TmPacketStoredPusC.cpp b/src/fsfw/tmtcpacket/pus/tm/TmPacketStoredPusC.cpp deleted file mode 100644 index 5ade4191..00000000 --- a/src/fsfw/tmtcpacket/pus/tm/TmPacketStoredPusC.cpp +++ /dev/null @@ -1,76 +0,0 @@ -#include "fsfw/tmtcpacket/pus/tm/TmPacketStoredPusC.h" - -#include - -#include "fsfw/serviceinterface/ServiceInterface.h" -#include "fsfw/tmtcservices/TmTcMessage.h" - -TmPacketStoredPusC::TmPacketStoredPusC(store_address_t setAddress) - : TmPacketStoredBase(setAddress), TmPacketPusC(nullptr) {} - -TmPacketStoredPusC::TmPacketStoredPusC(uint16_t apid, uint8_t service, uint8_t subservice, - uint16_t packetSubcounter, const uint8_t *data, - uint32_t size, const uint8_t *headerData, - uint32_t headerSize, uint16_t destinationId, - uint8_t timeRefField) - : TmPacketPusC(nullptr) { - storeAddress.raw = StorageManagerIF::INVALID_ADDRESS; - if (not TmPacketStoredBase::checkAndSetStore()) { - return; - } - uint8_t *pData = nullptr; - size_t sizeToReserve = getPacketMinimumSize() + size + headerSize; - ReturnValue_t returnValue = store->getFreeElement(&storeAddress, sizeToReserve, &pData); - - if (returnValue != store->RETURN_OK) { - handleStoreFailure("C", returnValue, sizeToReserve); - return; - } - setData(pData, sizeToReserve, nullptr); - initializeTmPacket(apid, service, subservice, packetSubcounter, destinationId, timeRefField); - memcpy(getSourceData(), headerData, headerSize); - memcpy(getSourceData() + headerSize, data, size); - setPacketDataLength(size + headerSize + sizeof(PUSTmDataFieldHeaderPusC) + CRC_SIZE - 1); -} - -TmPacketStoredPusC::TmPacketStoredPusC(uint16_t apid, uint8_t service, uint8_t subservice, - uint16_t packetSubcounter, SerializeIF *content, - SerializeIF *header, uint16_t destinationId, - uint8_t timeRefField) - : TmPacketPusC(nullptr) { - storeAddress.raw = StorageManagerIF::INVALID_ADDRESS; - if (not TmPacketStoredBase::checkAndSetStore()) { - return; - } - size_t sourceDataSize = 0; - if (content != nullptr) { - sourceDataSize += content->getSerializedSize(); - } - if (header != nullptr) { - sourceDataSize += header->getSerializedSize(); - } - uint8_t *pData = nullptr; - size_t sizeToReserve = getPacketMinimumSize() + sourceDataSize; - ReturnValue_t returnValue = store->getFreeElement(&storeAddress, sizeToReserve, &pData); - if (returnValue != store->RETURN_OK) { - handleStoreFailure("C", returnValue, sizeToReserve); - return; - } - TmPacketPusC::setData(pData, sizeToReserve, nullptr); - initializeTmPacket(apid, service, subservice, packetSubcounter, destinationId, timeRefField); - uint8_t *putDataHere = getSourceData(); - size_t size = 0; - if (header != nullptr) { - header->serialize(&putDataHere, &size, sourceDataSize, SerializeIF::Endianness::BIG); - } - if (content != nullptr) { - content->serialize(&putDataHere, &size, sourceDataSize, SerializeIF::Endianness::BIG); - } - setPacketDataLength(sourceDataSize + sizeof(PUSTmDataFieldHeaderPusC) + CRC_SIZE - 1); -} - -uint8_t *TmPacketStoredPusC::getAllTmData() { return getWholeData(); } - -ReturnValue_t TmPacketStoredPusC::setData(uint8_t *newPointer, size_t maxSize, void *args) { - return TmPacketPusC::setData(newPointer, maxSize, args); -} diff --git a/src/fsfw/tmtcpacket/pus/tm/TmPacketStoredPusC.h b/src/fsfw/tmtcpacket/pus/tm/TmPacketStoredPusC.h deleted file mode 100644 index 2a1f645f..00000000 --- a/src/fsfw/tmtcpacket/pus/tm/TmPacketStoredPusC.h +++ /dev/null @@ -1,73 +0,0 @@ -//#ifndef FSFW_TMTCPACKET_PUS_TMPACKETSTOREDPUSC_H_ -//#define FSFW_TMTCPACKET_PUS_TMPACKETSTOREDPUSC_H_ -// -//#include "TmPacketPusC.h" -//#include "TmPacketStoredBase.h" -// -///** -// * This class generates a ECSS PUS C Telemetry packet within a given -// * intermediate storage. -// * As most packets are passed between tasks with the help of a storage -// * anyway, it seems logical to create a Packet-In-Storage access class -// * which saves the user almost all storage handling operation. -// * Packets can both be newly created with the class and be "linked" to -// * packets in a store with the help of a storeAddress. -// * @ingroup tmtcpackets -// */ -// class TmPacketStoredPusC : public TmPacketStoredBase, public TmPacketPusC { -// public: -// /** -// * This is a default constructor which does not set the data pointer. -// * However, it does try to set the packet store. -// */ -// TmPacketStoredPusC(store_address_t setAddress); -// /** -// * With this constructor, new space is allocated in the packet store and -// * a new PUS Telemetry Packet is created there. -// * Packet Application Data passed in data is copied into the packet. -// * The Application data is passed in two parts, first a header, then a -// * data field. This allows building a Telemetry Packet from two separate -// * data sources. -// * @param apid Sets the packet's APID field. -// * @param service Sets the packet's Service ID field. -// * This specifies the source service. -// * @param subservice Sets the packet's Service Subtype field. -// * This specifies the source sub-service. -// * @param packet_counter Sets the Packet counter field of this packet -// * @param data The payload data to be copied to the -// * Application Data Field -// * @param size The amount of data to be copied. -// * @param headerData The header Data of the Application field, -// * will be copied in front of data -// * @param headerSize The size of the headerDataF -// * @param destinationId Destination ID containing the application process ID as specified -// * by PUS C -// * @param timeRefField 4 bit time reference field as specified by PUS C -// */ -// TmPacketStoredPusC(uint16_t apid, uint8_t service, uint8_t subservice, uint16_t packetCounter = -// 0, -// const uint8_t* data = nullptr, uint32_t size = 0, -// const uint8_t* headerData = nullptr, uint32_t headerSize = 0, -// uint16_t destinationId = 0, uint8_t timeRefField = 0); -// /** -// * Another ctor to directly pass structured content and header data to the -// * packet to avoid additional buffers. -// */ -// TmPacketStoredPusC(uint16_t apid, uint8_t service, uint8_t subservice, uint16_t packetCounter, -// SerializeIF* content, SerializeIF* header = nullptr, -// uint16_t destinationId = 0, uint8_t timeRefField = 0); -// -// uint8_t* getAllTmData() override; -// -// private: -// /** -// * Implementation required by base class -// * @param newPointer -// * @param maxSize -// * @param args -// * @return -// */ -// ReturnValue_t setData(uint8_t* newPointer, size_t maxSize, void* args) override; -//}; -// -//#endif /* FSFW_TMTCPACKET_PUS_TMPACKETSTOREDPUSC_H_ */ diff --git a/unittests/CatchFactory.cpp b/unittests/CatchFactory.cpp index 25ced1ba..5dce8372 100644 --- a/unittests/CatchFactory.cpp +++ b/unittests/CatchFactory.cpp @@ -7,7 +7,6 @@ #include #include #include -#include #include #include -- 2.43.0 From 0981ee6f7ecabfc385424d1df3fc6d8dee1beef8 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Thu, 21 Jul 2022 18:17:37 +0200 Subject: [PATCH 022/108] minor changes, virtual dtors added --- src/fsfw/tmtcpacket/ReadablePacketIF.h | 2 ++ src/fsfw/tmtcpacket/pus/RawUserDataReaderIF.h | 5 +++-- src/fsfw/tmtcpacket/pus/tc/PusTcReader.cpp | 4 +++- src/fsfw/tmtcpacket/pus/tm/PusTmReader.cpp | 2 +- 4 files changed, 9 insertions(+), 4 deletions(-) diff --git a/src/fsfw/tmtcpacket/ReadablePacketIF.h b/src/fsfw/tmtcpacket/ReadablePacketIF.h index 01478273..bbffbe10 100644 --- a/src/fsfw/tmtcpacket/ReadablePacketIF.h +++ b/src/fsfw/tmtcpacket/ReadablePacketIF.h @@ -5,6 +5,8 @@ class ReadablePacketIF { public: + virtual ~ReadablePacketIF() = default; + /** * This method returns a raw uint8_t pointer to the readable data */ diff --git a/src/fsfw/tmtcpacket/pus/RawUserDataReaderIF.h b/src/fsfw/tmtcpacket/pus/RawUserDataReaderIF.h index e4e515f8..799b7940 100644 --- a/src/fsfw/tmtcpacket/pus/RawUserDataReaderIF.h +++ b/src/fsfw/tmtcpacket/pus/RawUserDataReaderIF.h @@ -6,8 +6,9 @@ class RawUserDataReaderIF { public: - virtual const uint8_t* getUserData() const = 0; - virtual size_t getUserDataLen() const = 0; + ~RawUserDataReaderIF() = default; + [[nodiscard]] virtual const uint8_t* getUserData() const = 0; + [[nodiscard]] virtual size_t getUserDataLen() const = 0; }; #endif // FSFW_TMTCPACKET_RAWDATAIF_H diff --git a/src/fsfw/tmtcpacket/pus/tc/PusTcReader.cpp b/src/fsfw/tmtcpacket/pus/tc/PusTcReader.cpp index c96bed65..bac6d543 100644 --- a/src/fsfw/tmtcpacket/pus/tc/PusTcReader.cpp +++ b/src/fsfw/tmtcpacket/pus/tc/PusTcReader.cpp @@ -23,7 +23,9 @@ ReturnValue_t PusTcReader::parseData(bool withCrc) { if (result != HasReturnvaluesIF::RETURN_OK) { return result; } - if (spReader.getBufSize() < PusTcIF::MIN_SIZE) { + // We already have access to the space packet fields here, so we can perform a sanity check + // on the length field + if (spReader.getFullPacketLen() < spReader.getBufSize()) { return SerializeIF::STREAM_TOO_SHORT; } diff --git a/src/fsfw/tmtcpacket/pus/tm/PusTmReader.cpp b/src/fsfw/tmtcpacket/pus/tm/PusTmReader.cpp index 024d6ac8..807dd8e0 100644 --- a/src/fsfw/tmtcpacket/pus/tm/PusTmReader.cpp +++ b/src/fsfw/tmtcpacket/pus/tm/PusTmReader.cpp @@ -57,7 +57,7 @@ ReturnValue_t PusTmReader::parseData(bool crcCheck) { if (result != HasReturnvaluesIF::RETURN_OK) { return result; } - if (spReader.getBufSize() < PusTmIF::MIN_SIZE) { + if (spReader.getFullPacketLen() < spReader.getBufSize()) { return SerializeIF::STREAM_TOO_SHORT; } -- 2.43.0 From affde6bad5b52512bd444fbc09d616f25cc684e2 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Thu, 21 Jul 2022 18:21:10 +0200 Subject: [PATCH 023/108] rename namespace --- src/fsfw/osal/host/Clock.cpp | 2 +- src/fsfw/osal/linux/Clock.cpp | 4 ++-- src/fsfw/pus/Service17Test.cpp | 4 ++-- src/fsfw/pus/Service1TelecommandVerification.cpp | 4 ++-- src/fsfw/pus/Service5EventReporting.cpp | 2 +- src/fsfw/tmtcservices/CommandingServiceBase.cpp | 9 ++++----- src/fsfw/tmtcservices/CommandingServiceBase.h | 3 --- src/fsfw/tmtcservices/tmHelpers.cpp | 3 ++- src/fsfw/tmtcservices/tmHelpers.h | 5 +++-- 9 files changed, 17 insertions(+), 19 deletions(-) diff --git a/src/fsfw/osal/host/Clock.cpp b/src/fsfw/osal/host/Clock.cpp index 19e120b3..2dc9d472 100644 --- a/src/fsfw/osal/host/Clock.cpp +++ b/src/fsfw/osal/host/Clock.cpp @@ -146,7 +146,7 @@ ReturnValue_t Clock::getDateAndTime(TimeOfDay_t* time) { } ReturnValue_t Clock::convertTimeOfDayToTimeval(const TimeOfDay_t* from, timeval* to) { - struct tm time_tm; + struct tm time_tm{}; time_tm.tm_year = from->year - 1900; time_tm.tm_mon = from->month - 1; diff --git a/src/fsfw/osal/linux/Clock.cpp b/src/fsfw/osal/linux/Clock.cpp index 534e7e22..afb4ce3a 100644 --- a/src/fsfw/osal/linux/Clock.cpp +++ b/src/fsfw/osal/linux/Clock.cpp @@ -122,7 +122,7 @@ ReturnValue_t Clock::getDateAndTime(TimeOfDay_t* time) { MutexGuard helper(timeMutex); // gmtime writes its output in a global buffer which is not Thread Safe // Therefore we have to use a Mutex here - struct tm* timeInfo; + struct telemetry* timeInfo; timeInfo = gmtime(&timeUnix.tv_sec); time->year = timeInfo->tm_year + 1900; time->month = timeInfo->tm_mon + 1; @@ -136,7 +136,7 @@ ReturnValue_t Clock::getDateAndTime(TimeOfDay_t* time) { } ReturnValue_t Clock::convertTimeOfDayToTimeval(const TimeOfDay_t* from, timeval* to) { - tm fromTm; + telemetry fromTm; // Note: Fails for years before AD fromTm.tm_year = from->year - 1900; fromTm.tm_mon = from->month - 1; diff --git a/src/fsfw/pus/Service17Test.cpp b/src/fsfw/pus/Service17Test.cpp index 52319de1..ea2c06e1 100644 --- a/src/fsfw/pus/Service17Test.cpp +++ b/src/fsfw/pus/Service17Test.cpp @@ -17,12 +17,12 @@ ReturnValue_t Service17Test::handleRequest(uint8_t subservice) { switch (subservice) { case Subservice::CONNECTION_TEST: { storeHelper.preparePacket(serviceId, Subservice::CONNECTION_TEST_REPORT, packetSubCounter); - return tm::storeAndSendTmPacket(storeHelper, sendHelper); + return telemetry::storeAndSendTmPacket(storeHelper, sendHelper); } case Subservice::EVENT_TRIGGER_TEST: { storeHelper.preparePacket(serviceId, Subservice::CONNECTION_TEST_REPORT, packetSubCounter++); triggerEvent(TEST, 1234, 5678); - return tm::storeAndSendTmPacket(storeHelper, sendHelper); + return telemetry::storeAndSendTmPacket(storeHelper, sendHelper); } default: return AcceptsTelecommandsIF::INVALID_SUBSERVICE; diff --git a/src/fsfw/pus/Service1TelecommandVerification.cpp b/src/fsfw/pus/Service1TelecommandVerification.cpp index 35957ba0..93525958 100644 --- a/src/fsfw/pus/Service1TelecommandVerification.cpp +++ b/src/fsfw/pus/Service1TelecommandVerification.cpp @@ -70,7 +70,7 @@ ReturnValue_t Service1TelecommandVerification::generateFailureReport( message->getParameter1(), message->getParameter2()); storeHelper.preparePacket(serviceId, message->getReportId(), packetSubCounter++); storeHelper.setSourceDataSerializable(&report); - return tm::storeAndSendTmPacket(storeHelper, sendHelper); + return telemetry::storeAndSendTmPacket(storeHelper, sendHelper); } ReturnValue_t Service1TelecommandVerification::generateSuccessReport( @@ -79,7 +79,7 @@ ReturnValue_t Service1TelecommandVerification::generateSuccessReport( message->getTcSequenceControl(), message->getStep()); storeHelper.preparePacket(serviceId, message->getReportId(), packetSubCounter++); storeHelper.setSourceDataSerializable(&report); - return tm::storeAndSendTmPacket(storeHelper, sendHelper); + return telemetry::storeAndSendTmPacket(storeHelper, sendHelper); } ReturnValue_t Service1TelecommandVerification::initialize() { diff --git a/src/fsfw/pus/Service5EventReporting.cpp b/src/fsfw/pus/Service5EventReporting.cpp index 31cc72f5..847f5f80 100644 --- a/src/fsfw/pus/Service5EventReporting.cpp +++ b/src/fsfw/pus/Service5EventReporting.cpp @@ -49,7 +49,7 @@ ReturnValue_t Service5EventReporting::generateEventReport(EventMessage message) message.getParameter2()); storeHelper.preparePacket(serviceId, message.getSeverity(), packetSubCounter); storeHelper.setSourceDataSerializable(&report); - ReturnValue_t result = tm::storeAndSendTmPacket(storeHelper, sendHelper); + ReturnValue_t result = telemetry::storeAndSendTmPacket(storeHelper, sendHelper); if (result != HasReturnvaluesIF::RETURN_OK) { #if FSFW_CPP_OSTREAM_ENABLED == 1 sif::warning << "Service5EventReporting::generateEventReport: " diff --git a/src/fsfw/tmtcservices/CommandingServiceBase.cpp b/src/fsfw/tmtcservices/CommandingServiceBase.cpp index 897dd962..6abe625b 100644 --- a/src/fsfw/tmtcservices/CommandingServiceBase.cpp +++ b/src/fsfw/tmtcservices/CommandingServiceBase.cpp @@ -5,7 +5,6 @@ #include "fsfw/serviceinterface/ServiceInterface.h" #include "fsfw/tcdistribution/PUSDistributorIF.h" #include "fsfw/tmtcpacket/pus/tc.h" -#include "fsfw/tmtcpacket/pus/tm.h" #include "fsfw/tmtcservices/AcceptsTelemetryIF.h" #include "fsfw/tmtcservices/TmTcMessage.h" #include "fsfw/tmtcservices/tcHelpers.h" @@ -290,7 +289,7 @@ ReturnValue_t CommandingServiceBase::sendTmPacket(uint8_t subservice, const uint size_t sourceDataLen) { tmStoreHelper.preparePacket(service, subservice, tmPacketCounter); tmStoreHelper.setSourceDataRaw(sourceData, sourceDataLen); - ReturnValue_t result = tm::storeAndSendTmPacket(tmStoreHelper, tmSendHelper); + ReturnValue_t result = telemetry::storeAndSendTmPacket(tmStoreHelper, tmSendHelper); if (result == HasReturnvaluesIF::RETURN_OK) { this->tmPacketCounter++; } @@ -299,10 +298,10 @@ ReturnValue_t CommandingServiceBase::sendTmPacket(uint8_t subservice, const uint ReturnValue_t CommandingServiceBase::sendTmPacket(uint8_t subservice, object_id_t objectId, const uint8_t* data, size_t dataLen) { - tm::SourceDataWithObjectIdPrefix dataWithObjId(objectId, data, dataLen); + telemetry::SourceDataWithObjectIdPrefix dataWithObjId(objectId, data, dataLen); tmStoreHelper.preparePacket(service, subservice, tmPacketCounter); tmStoreHelper.setSourceDataSerializable(&dataWithObjId); - ReturnValue_t result = tm::storeAndSendTmPacket(tmStoreHelper, tmSendHelper); + ReturnValue_t result = telemetry::storeAndSendTmPacket(tmStoreHelper, tmSendHelper); if (result == HasReturnvaluesIF::RETURN_OK) { this->tmPacketCounter++; } @@ -312,7 +311,7 @@ ReturnValue_t CommandingServiceBase::sendTmPacket(uint8_t subservice, object_id_ ReturnValue_t CommandingServiceBase::sendTmPacket(uint8_t subservice, SerializeIF* sourceData) { tmStoreHelper.preparePacket(service, subservice, tmPacketCounter); tmStoreHelper.setSourceDataSerializable(sourceData); - ReturnValue_t result = tm::storeAndSendTmPacket(tmStoreHelper, tmSendHelper); + ReturnValue_t result = telemetry::storeAndSendTmPacket(tmStoreHelper, tmSendHelper); if (result == HasReturnvaluesIF::RETURN_OK) { this->tmPacketCounter++; } diff --git a/src/fsfw/tmtcservices/CommandingServiceBase.h b/src/fsfw/tmtcservices/CommandingServiceBase.h index a58a1a93..9b8aa61e 100644 --- a/src/fsfw/tmtcservices/CommandingServiceBase.h +++ b/src/fsfw/tmtcservices/CommandingServiceBase.h @@ -15,9 +15,6 @@ #include "fsfw/storagemanager/StorageManagerIF.h" #include "fsfw/tasks/ExecutableObjectIF.h" -class TcPacketStoredBase; -class TcPacketStoredPus; - namespace Factory { void setStaticFrameworkObjectIds(); } diff --git a/src/fsfw/tmtcservices/tmHelpers.cpp b/src/fsfw/tmtcservices/tmHelpers.cpp index 91026d6c..d7bc66cf 100644 --- a/src/fsfw/tmtcservices/tmHelpers.cpp +++ b/src/fsfw/tmtcservices/tmHelpers.cpp @@ -1,6 +1,7 @@ #include "tmHelpers.h" -ReturnValue_t tm::storeAndSendTmPacket(TmStoreHelper &storeHelper, TmSendHelper &sendHelper) { +ReturnValue_t telemetry::storeAndSendTmPacket(TmStoreHelper &storeHelper, + TmSendHelper &sendHelper) { storeHelper.addPacketToStore(); ReturnValue_t result = sendHelper.sendPacket(storeHelper.getCurrentAddr()); if (result != HasReturnvaluesIF::RETURN_OK) { diff --git a/src/fsfw/tmtcservices/tmHelpers.h b/src/fsfw/tmtcservices/tmHelpers.h index 871a7f1a..2e783039 100644 --- a/src/fsfw/tmtcservices/tmHelpers.h +++ b/src/fsfw/tmtcservices/tmHelpers.h @@ -4,7 +4,8 @@ #include "TmSendHelper.h" #include "TmStoreHelper.h" -namespace tm { +// I'd prefer to use tm, but there have been nameclashes with the tm struct +namespace telemetry { ReturnValue_t storeAndSendTmPacket(TmStoreHelper& storeHelper, TmSendHelper& sendHelper); @@ -42,6 +43,6 @@ class SourceDataWithObjectIdPrefix : public SerializeIF { size_t srcDataLen; }; -} // namespace tm +} // namespace telemetry #endif // FSFW_TMTCSERVICES_TMHELPERS_H_ -- 2.43.0 From 0dfaba81f9a3868d64f5f88726ea91bfdb22af73 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Thu, 21 Jul 2022 19:10:15 +0200 Subject: [PATCH 024/108] finished basic TC unittests --- src/fsfw/osal/host/Clock.cpp | 2 +- src/fsfw/tmtcpacket/pus/tc/PusTcCreator.cpp | 12 ++- src/fsfw/tmtcpacket/pus/tc/PusTcCreator.h | 3 + src/fsfw/tmtcpacket/pus/tc/PusTcReader.cpp | 38 ++++------ src/fsfw/tmtcpacket/pus/tc/PusTcReader.h | 3 +- src/fsfw/tmtcpacket/pus/tm/PusTmCreator.cpp | 2 +- src/fsfw/tmtcpacket/pus/tm/PusTmReader.cpp | 4 - unittests/tmtcpacket/CMakeLists.txt | 1 + unittests/tmtcpacket/testPusTcCreator.cpp | 6 +- unittests/tmtcpacket/testPusTcReader.cpp | 81 +++++++++++++++++++++ unittests/tmtcpacket/testPusTm.cpp | 1 - 11 files changed, 118 insertions(+), 35 deletions(-) create mode 100644 unittests/tmtcpacket/testPusTcReader.cpp delete mode 100644 unittests/tmtcpacket/testPusTm.cpp diff --git a/src/fsfw/osal/host/Clock.cpp b/src/fsfw/osal/host/Clock.cpp index 2dc9d472..2f7ede89 100644 --- a/src/fsfw/osal/host/Clock.cpp +++ b/src/fsfw/osal/host/Clock.cpp @@ -146,7 +146,7 @@ ReturnValue_t Clock::getDateAndTime(TimeOfDay_t* time) { } ReturnValue_t Clock::convertTimeOfDayToTimeval(const TimeOfDay_t* from, timeval* to) { - struct tm time_tm{}; + struct tm time_tm {}; time_tm.tm_year = from->year - 1900; time_tm.tm_mon = from->month - 1; diff --git a/src/fsfw/tmtcpacket/pus/tc/PusTcCreator.cpp b/src/fsfw/tmtcpacket/pus/tc/PusTcCreator.cpp index 2ff82d25..240e7718 100644 --- a/src/fsfw/tmtcpacket/pus/tc/PusTcCreator.cpp +++ b/src/fsfw/tmtcpacket/pus/tc/PusTcCreator.cpp @@ -54,7 +54,7 @@ ReturnValue_t PusTcCreator::serialize(uint8_t **buffer, size_t *size, size_t max } } - uint16_t crc16 = CRC::crc16ccitt(start, getFullPacketLen() - 2); + uint16_t crc16 = CRC::crc16ccitt(start, getFullPacketLen() - sizeof(ecss::PusChecksumT)); return SerializeAdapter::serialize(&crc16, buffer, size, maxSize, streamEndianness); } @@ -95,3 +95,13 @@ SpacePacketParams &PusTcCreator::getSpParams() { return spCreator.getParams(); } ReturnValue_t PusTcCreator::serialize(uint8_t **buffer, size_t *size, size_t maxSize) { return serialize(buffer, size, maxSize, SerializeIF::Endianness::NETWORK); } + +void PusTcCreator::setRawAppData(ecss::DataWrapper::BufPairT bufPair) { + pusParams.dataWrapper.setRawData(bufPair); + updateSpLengthField(); +} + +void PusTcCreator::setSerializableAppData(SerializeIF *serAppData) { + pusParams.dataWrapper.setSerializable(serAppData); + updateSpLengthField(); +} diff --git a/src/fsfw/tmtcpacket/pus/tc/PusTcCreator.h b/src/fsfw/tmtcpacket/pus/tc/PusTcCreator.h index c09a7238..9e6b6e6f 100644 --- a/src/fsfw/tmtcpacket/pus/tc/PusTcCreator.h +++ b/src/fsfw/tmtcpacket/pus/tc/PusTcCreator.h @@ -33,6 +33,9 @@ class PusTcCreator : public PusTcIF, public SerializeIF, public CreatorDataIF { void updateSpLengthField(); PusTcParams &getPusParams(); SpacePacketParams &getSpParams(); + void setRawAppData(ecss::DataWrapper::BufPairT bufPair); + void setSerializableAppData(SerializeIF *serAppData); + ReturnValue_t serialize(uint8_t **buffer, size_t *size, size_t maxSize); [[nodiscard]] size_t getSerializedSize() const override; ReturnValue_t deSerialize(const uint8_t **buffer, size_t *size, diff --git a/src/fsfw/tmtcpacket/pus/tc/PusTcReader.cpp b/src/fsfw/tmtcpacket/pus/tc/PusTcReader.cpp index bac6d543..f5dd143a 100644 --- a/src/fsfw/tmtcpacket/pus/tc/PusTcReader.cpp +++ b/src/fsfw/tmtcpacket/pus/tc/PusTcReader.cpp @@ -23,20 +23,18 @@ ReturnValue_t PusTcReader::parseData(bool withCrc) { if (result != HasReturnvaluesIF::RETURN_OK) { return result; } - // We already have access to the space packet fields here, so we can perform a sanity check - // on the length field - if (spReader.getFullPacketLen() < spReader.getBufSize()) { - return SerializeIF::STREAM_TOO_SHORT; - } - size_t currentOffset = SpacePacketReader::getHeaderLen(); pointers.secHeaderStart = pointers.spHeaderStart + currentOffset; // Might become variable sized field in the future // TODO: No support for spare bytes yet currentOffset += ecss::PusTcDataFieldHeader::MIN_SIZE; - pointers.userDataStart = pointers.spHeaderStart + currentOffset; appDataSize = spReader.getFullPacketLen() - currentOffset - sizeof(ecss::PusChecksumT); - pointers.crcStart = pointers.userDataStart + appDataSize; + pointers.userDataStart = nullptr; + if (appDataSize > 0) { + pointers.userDataStart = pointers.spHeaderStart + currentOffset; + } + currentOffset += appDataSize; + pointers.crcStart = pointers.spHeaderStart + currentOffset; if (withCrc) { uint16_t crc16 = CRC::crc16ccitt(spReader.getFullData(), getFullPacketLen()); if (crc16 != 0) { @@ -47,25 +45,28 @@ ReturnValue_t PusTcReader::parseData(bool withCrc) { return HasReturnvaluesIF::RETURN_OK; } -uint8_t PusTcReader::getAcknowledgeFlags() const { - return (pointers.secHeaderStart[0] >> 4) & 0b1111; -} +uint8_t PusTcReader::getPusVersion() const { return (pointers.secHeaderStart[0] >> 4) & 0b1111; } + +uint8_t PusTcReader::getAcknowledgeFlags() const { return pointers.secHeaderStart[0] & 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]; } uint16_t PusTcReader::getErrorControl() const { - return pointers.crcStart[0] << 8 | pointers.crcStart[1]; + return (pointers.crcStart[0] << 8) | pointers.crcStart[1]; } uint16_t PusTcReader::getPacketIdRaw() const { return spReader.getPacketIdRaw(); } + uint16_t PusTcReader::getPacketSeqCtrlRaw() const { return spReader.getPacketSeqCtrlRaw(); } + 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) { @@ -80,13 +81,4 @@ ReturnValue_t PusTcReader::setReadOnlyData(const uint8_t* data, size_t size_) { const uint8_t* PusTcReader::getUserData() const { return pointers.userDataStart; } size_t PusTcReader::getUserDataLen() const { return appDataSize; } -/* -void PusTcReader::print() { -#if FSFW_CPP_OSTREAM_ENABLED == 1 - sif::info << "TcPacketBase::print:" << std::endl; -#else - sif::printInfo("TcPacketBase::print:\n"); -#endif - arrayprinter::print(getWholeData(), getFullSize()); -} -*/ \ No newline at end of file +bool PusTcReader::isNull() const { return spReader.isNull(); } diff --git a/src/fsfw/tmtcpacket/pus/tc/PusTcReader.h b/src/fsfw/tmtcpacket/pus/tc/PusTcReader.h index 528e0ca5..3be2e5e6 100644 --- a/src/fsfw/tmtcpacket/pus/tc/PusTcReader.h +++ b/src/fsfw/tmtcpacket/pus/tc/PusTcReader.h @@ -34,6 +34,7 @@ class PusTcReader : public PusTcIF, */ PusTcReader(const uint8_t* setData, size_t size); + [[nodiscard]] bool isNull() const; ReturnValue_t parseDataWithCrcCheck(); ReturnValue_t parseDataWithoutCrcCheck(); @@ -60,7 +61,7 @@ class PusTcReader : public PusTcIF, ReturnValue_t setReadOnlyData(const uint8_t* data, size_t size); [[nodiscard]] const uint8_t* getUserData() const override; - size_t getUserDataLen() const override; + [[nodiscard]] size_t getUserDataLen() const override; protected: /** diff --git a/src/fsfw/tmtcpacket/pus/tm/PusTmCreator.cpp b/src/fsfw/tmtcpacket/pus/tm/PusTmCreator.cpp index 927ec072..22c998c8 100644 --- a/src/fsfw/tmtcpacket/pus/tm/PusTmCreator.cpp +++ b/src/fsfw/tmtcpacket/pus/tm/PusTmCreator.cpp @@ -74,7 +74,7 @@ ReturnValue_t PusTmCreator::serialize(uint8_t** buffer, size_t* size, size_t max return result; } } - uint16_t crc16 = CRC::crc16ccitt(*buffer, getFullPacketLen() - 2); + uint16_t crc16 = CRC::crc16ccitt(*buffer, getFullPacketLen() - sizeof(ecss::PusChecksumT)); return SerializeAdapter::serialize(&crc16, buffer, size, maxSize, streamEndianness); } diff --git a/src/fsfw/tmtcpacket/pus/tm/PusTmReader.cpp b/src/fsfw/tmtcpacket/pus/tm/PusTmReader.cpp index 807dd8e0..e700a428 100644 --- a/src/fsfw/tmtcpacket/pus/tm/PusTmReader.cpp +++ b/src/fsfw/tmtcpacket/pus/tm/PusTmReader.cpp @@ -57,10 +57,6 @@ ReturnValue_t PusTmReader::parseData(bool crcCheck) { if (result != HasReturnvaluesIF::RETURN_OK) { return result; } - if (spReader.getFullPacketLen() < spReader.getBufSize()) { - return SerializeIF::STREAM_TOO_SHORT; - } - size_t currentOffset = SpacePacketReader::getHeaderLen(); pointers.secHeaderStart = pointers.spHeaderStart + currentOffset; currentOffset += PusTmIF::MIN_SEC_HEADER_LEN; diff --git a/unittests/tmtcpacket/CMakeLists.txt b/unittests/tmtcpacket/CMakeLists.txt index 67d8858c..673c5244 100644 --- a/unittests/tmtcpacket/CMakeLists.txt +++ b/unittests/tmtcpacket/CMakeLists.txt @@ -2,4 +2,5 @@ target_sources(${FSFW_TEST_TGT} PRIVATE testCcsdsCreator.cpp testCcsdsReader.cpp testPusTcCreator.cpp + testPusTcReader.cpp ) diff --git a/unittests/tmtcpacket/testPusTcCreator.cpp b/unittests/tmtcpacket/testPusTcCreator.cpp index f6c15b78..ca934121 100644 --- a/unittests/tmtcpacket/testPusTcCreator.cpp +++ b/unittests/tmtcpacket/testPusTcCreator.cpp @@ -54,6 +54,8 @@ TEST_CASE("PUS TC Creator", "[pus-tc-creator]") { REQUIRE(((buf[9] << 8) | buf[10]) == 0); // CRC16 check REQUIRE(CRC::crc16ccitt(buf.data(), serLen) == 0); + REQUIRE(buf[11] == 0xee); + REQUIRE(buf[12] == 0x63); } SECTION("Custom Source ID") { @@ -82,12 +84,10 @@ TEST_CASE("PUS TC Creator", "[pus-tc-creator]") { SECTION("Test with Application Data Serializable") { auto& params = creator.getPusParams(); auto simpleSer = SimpleSerializable(); - params.dataWrapper.setSerializable(&simpleSer); + creator.setSerializableAppData(&simpleSer); auto& dataWrapper = creator.getDataWrapper(); REQUIRE(dataWrapper.type == ecss::DataTypes::SERIALIZABLE); REQUIRE(dataWrapper.dataUnion.serializable == &simpleSer); - REQUIRE(creator.getSerializedSize() == 13); - creator.updateSpLengthField(); REQUIRE(creator.getSerializedSize() == 16); REQUIRE(creator.serialize(&dataPtr, &serLen, buf.size()) == HasReturnvaluesIF::RETURN_OK); REQUIRE(serLen == 16); diff --git a/unittests/tmtcpacket/testPusTcReader.cpp b/unittests/tmtcpacket/testPusTcReader.cpp new file mode 100644 index 00000000..1c870f78 --- /dev/null +++ b/unittests/tmtcpacket/testPusTcReader.cpp @@ -0,0 +1,81 @@ +#include +#include + +#include "fsfw/tmtcpacket/pus/tc/PusTcCreator.h" +#include "fsfw/tmtcpacket/pus/tc/PusTcReader.h" + +TEST_CASE("PUS TC Reader", "[pus-tc-reader]") { + auto packetId = PacketId(ccsds::PacketType::TC, true, 0x02); + auto spParams = + SpacePacketParams(packetId, PacketSeqCtrl(ccsds::SequenceFlags::UNSEGMENTED, 0x34), 0x00); + auto pusParams = PusTcParams(17, 1); + PusTcCreator creator(spParams, pusParams); + std::array buf{}; + uint8_t* dataPtr = buf.data(); + size_t serLen = 0; + PusTcReader reader; + auto checkReaderFields = [&](PusTcReader& reader) { + REQUIRE(not reader.isNull()); + REQUIRE(reader.getPacketType() == ccsds::PacketType::TC); + REQUIRE(reader.getApid() == 0x02); + REQUIRE(reader.getService() == 17); + REQUIRE(reader.getSubService() == 1); + REQUIRE(reader.getFullPacketLen() == 13); + REQUIRE(reader.getPacketDataLen() == 6); + REQUIRE(reader.getPusVersion() == 2); + REQUIRE(reader.getSequenceCount() == 0x34); + REQUIRE(reader.getUserData() == nullptr); + REQUIRE(reader.getUserDataLen() == 0); + REQUIRE(reader.getFullData() == buf.data()); + REQUIRE(reader.getSourceId() == 0x00); + REQUIRE(reader.getAcknowledgeFlags() == 0b1111); + // This value was verified to be correct + REQUIRE(reader.getErrorControl() == 0xee63); + }; + + SECTION("State") { + REQUIRE(creator.serialize(&dataPtr, &serLen, buf.size()) == HasReturnvaluesIF::RETURN_OK); + REQUIRE(reader.isNull()); + + SECTION("Setter") { + REQUIRE(reader.setReadOnlyData(buf.data(), serLen) == HasReturnvaluesIF::RETURN_OK); + REQUIRE(reader.parseDataWithCrcCheck() == HasReturnvaluesIF::RETURN_OK); + checkReaderFields(reader); + } + SECTION("Directly Constructed") { + PusTcReader secondReader(buf.data(), serLen); + REQUIRE(not secondReader.isNull()); + REQUIRE(secondReader.parseDataWithCrcCheck() == HasReturnvaluesIF::RETURN_OK); + checkReaderFields(secondReader); + } + } + + SECTION("Invalid CRC") { + REQUIRE(creator.serialize(&dataPtr, &serLen, buf.size()) == HasReturnvaluesIF::RETURN_OK); + REQUIRE(reader.setReadOnlyData(buf.data(), serLen) == HasReturnvaluesIF::RETURN_OK); + buf[11] = 0x00; + REQUIRE(reader.parseDataWithCrcCheck() == PusIF::INVALID_CRC_16); + } + + SECTION("Invalid CRC but no check") { + REQUIRE(creator.serialize(&dataPtr, &serLen, buf.size()) == HasReturnvaluesIF::RETURN_OK); + REQUIRE(reader.setReadOnlyData(buf.data(), serLen) == HasReturnvaluesIF::RETURN_OK); + buf[11] = 0x00; + REQUIRE(reader.parseDataWithoutCrcCheck() == HasReturnvaluesIF::RETURN_OK); + } + + SECTION("With application data") { + auto& params = creator.getPusParams(); + std::array data{1, 2, 3}; + creator.setRawAppData({data.data(), data.size()}); + REQUIRE(creator.serialize(&dataPtr, &serLen, buf.size()) == HasReturnvaluesIF::RETURN_OK); + REQUIRE(reader.setReadOnlyData(buf.data(), serLen) == HasReturnvaluesIF::RETURN_OK); + REQUIRE(reader.parseDataWithCrcCheck() == HasReturnvaluesIF::RETURN_OK); + const uint8_t* userDataPtr = reader.getUserData(); + REQUIRE(userDataPtr != nullptr); + REQUIRE(reader.getUserDataLen() == 3); + REQUIRE(userDataPtr[0] == 1); + REQUIRE(userDataPtr[1] == 2); + REQUIRE(userDataPtr[2] == 3); + } +} \ No newline at end of file diff --git a/unittests/tmtcpacket/testPusTm.cpp b/unittests/tmtcpacket/testPusTm.cpp deleted file mode 100644 index 8b137891..00000000 --- a/unittests/tmtcpacket/testPusTm.cpp +++ /dev/null @@ -1 +0,0 @@ - -- 2.43.0 From bfee4fd90aa7c5ca3cf7e7568220729d8680fde4 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Thu, 21 Jul 2022 19:16:44 +0200 Subject: [PATCH 025/108] add empty test files --- unittests/tmtcpacket/CMakeLists.txt | 2 ++ unittests/tmtcpacket/testPusTmCreator.cpp | 3 +++ unittests/tmtcpacket/testPusTmReader.cpp | 3 +++ 3 files changed, 8 insertions(+) create mode 100644 unittests/tmtcpacket/testPusTmCreator.cpp create mode 100644 unittests/tmtcpacket/testPusTmReader.cpp diff --git a/unittests/tmtcpacket/CMakeLists.txt b/unittests/tmtcpacket/CMakeLists.txt index 673c5244..f47c6370 100644 --- a/unittests/tmtcpacket/CMakeLists.txt +++ b/unittests/tmtcpacket/CMakeLists.txt @@ -3,4 +3,6 @@ target_sources(${FSFW_TEST_TGT} PRIVATE testCcsdsReader.cpp testPusTcCreator.cpp testPusTcReader.cpp + testPusTmCreator.cpp + testPusTmReader.cpp ) diff --git a/unittests/tmtcpacket/testPusTmCreator.cpp b/unittests/tmtcpacket/testPusTmCreator.cpp new file mode 100644 index 00000000..481b6a31 --- /dev/null +++ b/unittests/tmtcpacket/testPusTmCreator.cpp @@ -0,0 +1,3 @@ +#include + +TEST_CASE("PUS TM Creator", "[pus-tm-creator]") {} \ No newline at end of file diff --git a/unittests/tmtcpacket/testPusTmReader.cpp b/unittests/tmtcpacket/testPusTmReader.cpp new file mode 100644 index 00000000..59c01914 --- /dev/null +++ b/unittests/tmtcpacket/testPusTmReader.cpp @@ -0,0 +1,3 @@ +#include + +TEST_CASE("PUS TM Reader", "[pus-tm-reader]") {} \ No newline at end of file -- 2.43.0 From 67776241de0a6bac0d0318d688d8fe8b84f8c445 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Fri, 22 Jul 2022 16:06:31 +0200 Subject: [PATCH 026/108] verify successfull TM serialization --- src/fsfw/timemanager/TimeStamperIF.h | 4 +- src/fsfw/tmtcpacket/pus/tm/PusTmCreator.cpp | 30 ++++++---- src/fsfw/tmtcpacket/pus/tm/PusTmCreator.h | 42 +++++++++----- src/fsfw/tmtcservices/TmStoreHelper.cpp | 6 +- unittests/mocks/CdsShortTimestamperMock.h | 53 +++++++++++++++++ unittests/tmtcpacket/testPusTcCreator.cpp | 1 + unittests/tmtcpacket/testPusTmCreator.cpp | 64 ++++++++++++++++++++- 7 files changed, 170 insertions(+), 30 deletions(-) create mode 100644 unittests/mocks/CdsShortTimestamperMock.h diff --git a/src/fsfw/timemanager/TimeStamperIF.h b/src/fsfw/timemanager/TimeStamperIF.h index 2f0e8021..df680b6c 100644 --- a/src/fsfw/timemanager/TimeStamperIF.h +++ b/src/fsfw/timemanager/TimeStamperIF.h @@ -22,9 +22,9 @@ class TimeStamperIF : public SerializeIF { //! size reserved for timestamps. // static const uint8_t MISSION_TIMESTAMP_SIZE = fsfwconfig::FSFW_MISSION_TIMESTAMP_SIZE; - [[nodiscard]] virtual size_t getTimestampSize() const = 0; - virtual ReturnValue_t addTimeStamp(uint8_t* buffer, uint8_t maxSize) = 0; + [[nodiscard]] virtual size_t getTimestampSize() const { return getSerializedSize(); } + virtual ReturnValue_t addTimeStamp(uint8_t* buffer, uint8_t maxSize) = 0; ~TimeStamperIF() override = default; }; diff --git a/src/fsfw/tmtcpacket/pus/tm/PusTmCreator.cpp b/src/fsfw/tmtcpacket/pus/tm/PusTmCreator.cpp index 22c998c8..df931dfd 100644 --- a/src/fsfw/tmtcpacket/pus/tm/PusTmCreator.cpp +++ b/src/fsfw/tmtcpacket/pus/tm/PusTmCreator.cpp @@ -5,15 +5,12 @@ #include "fsfw/globalfunctions/CRC.h" #include "fsfw/timemanager/TimeStamperIF.h" -PusTmCreator::PusTmCreator(SpacePacketParams initSpParams, PusTmParams initPusParams, - TimeStamperIF* timeStamper) - : pusParams(initPusParams), spCreator(std::move(initSpParams)) {} - -PusTmCreator::PusTmCreator(TimeStamperIF* timeStamper_) { - pusParams.secHeader.timeStamper = timeStamper_; +PusTmCreator::PusTmCreator(SpacePacketParams initSpParams, PusTmParams initPusParams) + : pusParams(initPusParams), spCreator(std::move(initSpParams)) { + setup(); } -PusTmCreator::PusTmCreator() = default; +PusTmCreator::PusTmCreator() { setup(); } uint16_t PusTmCreator::getPacketIdRaw() const { return spCreator.getPacketIdRaw(); } uint16_t PusTmCreator::getPacketSeqCtrlRaw() const { return spCreator.getPacketSeqCtrlRaw(); } @@ -31,6 +28,7 @@ uint16_t PusTmCreator::getDestId() { return 0; } ReturnValue_t PusTmCreator::serialize(uint8_t** buffer, size_t* size, size_t maxSize, SerializeIF::Endianness streamEndianness) const { + const uint8_t* start = *buffer; if (*size + getSerializedSize() > maxSize) { return SerializeIF::BUFFER_TOO_SHORT; } @@ -74,7 +72,7 @@ ReturnValue_t PusTmCreator::serialize(uint8_t** buffer, size_t* size, size_t max return result; } } - uint16_t crc16 = CRC::crc16ccitt(*buffer, getFullPacketLen() - sizeof(ecss::PusChecksumT)); + uint16_t crc16 = CRC::crc16ccitt(start, getFullPacketLen() - sizeof(ecss::PusChecksumT)); return SerializeAdapter::serialize(&crc16, buffer, size, maxSize, streamEndianness); } @@ -85,15 +83,25 @@ ReturnValue_t PusTmCreator::deSerialize(const uint8_t** buffer, size_t* size, } ecss::DataWrapper& PusTmCreator::getDataWrapper() { return pusParams.dataWrapper; } -TimeStamperIF* PusTmCreator::getTimestamper() { return pusParams.secHeader.timeStamper; } +TimeStamperIF* PusTmCreator::getTimestamper() const { return pusParams.secHeader.timeStamper; } SpacePacketParams& PusTmCreator::getSpParams() { return spCreator.getParams(); } void PusTmCreator::updateSpLengthField() { - size_t headerLen = PusTmIF::MIN_SIZE; + size_t headerLen = PusTmIF::MIN_SEC_HEADER_LEN + pusParams.dataWrapper.getLength() + + sizeof(ecss::PusChecksumT) - 1; if (pusParams.secHeader.timeStamper != nullptr) { headerLen += pusParams.secHeader.timeStamper->getSerializedSize(); } - spCreator.setDataLen(headerLen + pusParams.dataWrapper.getLength() + 1); + spCreator.setDataLen(headerLen); } void PusTmCreator::setApid(uint16_t apid) { spCreator.setApid(apid); } + +ReturnValue_t PusTmCreator::serialize(uint8_t** buffer, size_t* size, size_t maxSize) const { + return serialize(buffer, size, maxSize, SerializeIF::Endianness::NETWORK); +} + +void PusTmCreator::setup() { + updateSpLengthField(); + spCreator.setPacketType(ccsds::PacketType::TM); +} diff --git a/src/fsfw/tmtcpacket/pus/tm/PusTmCreator.h b/src/fsfw/tmtcpacket/pus/tm/PusTmCreator.h index 9ac79d16..97c96391 100644 --- a/src/fsfw/tmtcpacket/pus/tm/PusTmCreator.h +++ b/src/fsfw/tmtcpacket/pus/tm/PusTmCreator.h @@ -6,18 +6,35 @@ #include "fsfw/tmtcpacket/pus/CreatorDataIF.h" struct PusTmSecHeader { - uint8_t pusVersion; - uint8_t scTimeRefStatus; - uint8_t service; - uint8_t subservice; - uint16_t messageTypeCounter; - uint16_t destId; - TimeStamperIF* timeStamper; + PusTmSecHeader() = default; + PusTmSecHeader(uint8_t service, uint8_t subservice, TimeStamperIF* timeStamper) + : service(service), subservice(subservice), timeStamper(timeStamper) {} + + uint8_t service = 0; + uint8_t subservice = 0; + TimeStamperIF* timeStamper = nullptr; + uint8_t pusVersion = ecss::PusVersion::PUS_C; + uint8_t scTimeRefStatus = 0; + uint16_t messageTypeCounter = 0; + uint16_t destId = 0; }; struct PusTmParams { + PusTmParams() = default; + explicit PusTmParams(PusTmSecHeader secHeader) : secHeader(secHeader){}; + PusTmParams(PusTmSecHeader secHeader, ecss::DataWrapper dataWrapper) + : secHeader(secHeader), dataWrapper(dataWrapper) {} + + PusTmParams(uint8_t service, uint8_t subservice, TimeStamperIF* timeStamper) + : secHeader(service, subservice, timeStamper) {} + + PusTmParams(uint8_t service, uint8_t subservice, TimeStamperIF* timeStamper, + ecss::DataWrapper dataWrapper_) + : PusTmParams(service, subservice, timeStamper) { + dataWrapper = dataWrapper_; + } PusTmSecHeader secHeader; - ecss::DataWrapper dataWrapper; + ecss::DataWrapper dataWrapper{}; }; class TimeStamperIF; @@ -25,10 +42,7 @@ class TimeStamperIF; class PusTmCreator : public SerializeIF, public PusTmIF, public CreatorDataIF { public: PusTmCreator(); - - explicit PusTmCreator(TimeStamperIF* timeStamper); - PusTmCreator(SpacePacketParams initSpParams, PusTmParams initPusParams, - TimeStamperIF* timeStamper); + PusTmCreator(SpacePacketParams initSpParams, PusTmParams initPusParams); ~PusTmCreator() override = default; void setTimeStamper(TimeStamperIF* timeStamper); @@ -45,17 +59,19 @@ class PusTmCreator : public SerializeIF, public PusTmIF, public CreatorDataIF { uint8_t getScTimeRefStatus() override; uint16_t getMessageTypeCounter() override; uint16_t getDestId() override; + ReturnValue_t serialize(uint8_t** buffer, size_t* size, size_t maxSize) const; 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; - TimeStamperIF* getTimestamper(); + [[nodiscard]] TimeStamperIF* getTimestamper() const; private: ecss::DataWrapper& getDataWrapper() override; private: + void setup(); PusTmParams pusParams{}; SpacePacketCreator spCreator; }; diff --git a/src/fsfw/tmtcservices/TmStoreHelper.cpp b/src/fsfw/tmtcservices/TmStoreHelper.cpp index 661ee3a0..44b2e6a1 100644 --- a/src/fsfw/tmtcservices/TmStoreHelper.cpp +++ b/src/fsfw/tmtcservices/TmStoreHelper.cpp @@ -4,12 +4,12 @@ TmStoreHelper::TmStoreHelper(uint16_t defaultApid, StorageManagerIF* tmStore, TimeStamperIF* timeStamper) - : creator(timeStamper), tmStore(tmStore) { + : tmStore(tmStore) { creator.setApid(defaultApid); + creator.setTimeStamper(timeStamper); } -TmStoreHelper::TmStoreHelper(uint16_t defaultApid, StorageManagerIF* tmStore) - : creator(nullptr), tmStore(tmStore) { +TmStoreHelper::TmStoreHelper(uint16_t defaultApid, StorageManagerIF* tmStore) : tmStore(tmStore) { creator.setApid(defaultApid); } diff --git a/unittests/mocks/CdsShortTimestamperMock.h b/unittests/mocks/CdsShortTimestamperMock.h new file mode 100644 index 00000000..779859d0 --- /dev/null +++ b/unittests/mocks/CdsShortTimestamperMock.h @@ -0,0 +1,53 @@ +#ifndef FSFW_TESTS_CDSSHORTTIMESTAMPERMOCK_H +#define FSFW_TESTS_CDSSHORTTIMESTAMPERMOCK_H + +#include + +#include "fsfw/timemanager/TimeStamperIF.h" + +class CdsShortTimestamperMock : public TimeStamperIF { + public: + unsigned int serializeCallCount = 0; + ReturnValue_t lastSerializeResult = HasReturnvaluesIF::RETURN_OK; + unsigned int getSizeCallCount = 0; + std::array valueToStamp{}; + + CdsShortTimestamperMock() = default; + + explicit CdsShortTimestamperMock(std::array valueToStamp) + : valueToStamp(valueToStamp) {} + + ReturnValue_t serialize(uint8_t **buffer, size_t *size, size_t maxSize, + Endianness streamEndianness) const override { + auto &thisNonConst = const_cast(*this); + thisNonConst.serializeCallCount += 1; + if (*size + getSerializedSize() > maxSize) { + thisNonConst.lastSerializeResult = SerializeIF::BUFFER_TOO_SHORT; + return lastSerializeResult; + } + std::copy(valueToStamp.begin(), valueToStamp.end(), *buffer); + thisNonConst.lastSerializeResult = HasReturnvaluesIF::RETURN_OK; + *buffer += getSerializedSize(); + *size += getSerializedSize(); + return lastSerializeResult; + } + [[nodiscard]] size_t getSerializedSize() const override { + auto &thisNonConst = const_cast(*this); + thisNonConst.getSizeCallCount += 1; + return valueToStamp.size(); + } + ReturnValue_t deSerialize(const uint8_t **buffer, size_t *size, + Endianness streamEndianness) override { + return HasReturnvaluesIF::RETURN_FAILED; + } + [[nodiscard]] size_t getTimestampSize() const override { return getSerializedSize(); } + ReturnValue_t addTimeStamp(uint8_t *buffer, uint8_t maxSize) override { return 0; } + + void reset() { + serializeCallCount = 0; + getSizeCallCount = 0; + } + + private: +}; +#endif // FSFW_TESTS_CDSSHORTTIMESTAMPERMOCK_H diff --git a/unittests/tmtcpacket/testPusTcCreator.cpp b/unittests/tmtcpacket/testPusTcCreator.cpp index ca934121..28c7e555 100644 --- a/unittests/tmtcpacket/testPusTcCreator.cpp +++ b/unittests/tmtcpacket/testPusTcCreator.cpp @@ -16,6 +16,7 @@ TEST_CASE("PUS TC Creator", "[pus-tc-creator]") { size_t serLen = 0; SECTION("State") { + REQUIRE(creator.isTc()); REQUIRE(creator.getService() == 17); REQUIRE(creator.getSubService() == 1); REQUIRE(creator.getApid() == 0x02); diff --git a/unittests/tmtcpacket/testPusTmCreator.cpp b/unittests/tmtcpacket/testPusTmCreator.cpp index 481b6a31..6b92b134 100644 --- a/unittests/tmtcpacket/testPusTmCreator.cpp +++ b/unittests/tmtcpacket/testPusTmCreator.cpp @@ -1,3 +1,65 @@ #include -TEST_CASE("PUS TM Creator", "[pus-tm-creator]") {} \ No newline at end of file +#include "fsfw/globalfunctions/arrayprinter.h" +#include "fsfw/tmtcpacket/pus/tm.h" +#include "fsfw/globalfunctions/CRC.h" +#include "mocks/CdsShortTimestamperMock.h" + +TEST_CASE("PUS TM Creator", "[pus-tm-creator]") { + auto packetId = PacketId(ccsds::PacketType::TC, true, 0xef); + auto spParams = + SpacePacketParams(packetId, PacketSeqCtrl(ccsds::SequenceFlags::UNSEGMENTED, 22), 0x00); + auto timeStamper = CdsShortTimestamperMock(); + auto pusTmParams = PusTmParams(17, 2, &timeStamper); + timeStamper.valueToStamp = {1, 2, 3, 4, 5, 6, 7}; + PusTmCreator creator(spParams, pusTmParams); + std::array buf{}; + uint8_t* dataPtr = buf.data(); + size_t serLen = 0; + + SECTION("State") { + REQUIRE(creator.isTm()); + REQUIRE(creator.getApid() == 0xef); + REQUIRE(creator.getService() == 17); + REQUIRE(creator.getSubService() == 2); + REQUIRE(creator.getTimestamper() == &timeStamper); + REQUIRE(creator.getSequenceFlags() == ccsds::SequenceFlags::UNSEGMENTED); + REQUIRE(creator.getSequenceCount() == 22); + // 6 bytes CCSDS header, 7 bytes secondary header, 7 bytes CDS short timestamp, + // 0 bytes application data, 2 bytes CRC + REQUIRE(creator.getFullPacketLen() == 22); + // As specified in standard, the data length fields is the total size of the packet without + // the primary header minus 1 + REQUIRE(creator.getPacketDataLen() == 15); + REQUIRE(timeStamper.getSizeCallCount == 1); + } + + SECTION("Serialization") { + REQUIRE(creator.serialize(&dataPtr, &serLen, buf.size()) == HasReturnvaluesIF::RETURN_OK); + REQUIRE(buf[0] == 0x08); + REQUIRE(buf[1] == 0xef); + // Unsegmented is the default + REQUIRE(buf[2] == 0xc0); + REQUIRE(buf[3] == 22); + REQUIRE(buf[4] == 0); + REQUIRE(buf[5] == 15); + REQUIRE(((buf[6] >> 4) & 0b1111) == ecss::PusVersion::PUS_C); + // SC time reference field + REQUIRE((buf[6] & 0b1111) == 0); + // Service and subservice field + REQUIRE(buf[7] == 17); + REQUIRE(buf[8] == 2); + // Message Sequence Count + REQUIRE(((buf[9] << 8) | buf[10]) == 0); + // Destination ID + REQUIRE(((buf[11] << 8) | buf[12]) == 0); + // Custom timestamp + for(size_t i = 1; i < 8; i++) { + REQUIRE(buf[12 + i] == i); + } + REQUIRE(serLen == 22); + REQUIRE(CRC::crc16ccitt(buf.data(), serLen) == 0); + REQUIRE(buf[20] == 0x03); + REQUIRE(buf[21] == 0x79); + } +} \ No newline at end of file -- 2.43.0 From 9275ccb79bae8e836ed8ea2a221252644b67d1b9 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Fri, 22 Jul 2022 16:09:18 +0200 Subject: [PATCH 027/108] added some missing implementations --- src/fsfw/tmtcpacket/pus/tm/PusTmCreator.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/fsfw/tmtcpacket/pus/tm/PusTmCreator.cpp b/src/fsfw/tmtcpacket/pus/tm/PusTmCreator.cpp index df931dfd..479358b7 100644 --- a/src/fsfw/tmtcpacket/pus/tm/PusTmCreator.cpp +++ b/src/fsfw/tmtcpacket/pus/tm/PusTmCreator.cpp @@ -22,9 +22,9 @@ PusTmParams& PusTmCreator::getParams() { return pusParams; } void PusTmCreator::setTimeStamper(TimeStamperIF* timeStamper_) { pusParams.secHeader.timeStamper = timeStamper_; } -uint8_t PusTmCreator::getScTimeRefStatus() { return 0; } -uint16_t PusTmCreator::getMessageTypeCounter() { return 0; } -uint16_t PusTmCreator::getDestId() { return 0; } +uint8_t PusTmCreator::getScTimeRefStatus() { return pusParams.secHeader.scTimeRefStatus; } +uint16_t PusTmCreator::getMessageTypeCounter() { return pusParams.secHeader.messageTypeCounter; } +uint16_t PusTmCreator::getDestId() { return pusParams.secHeader.destId; } ReturnValue_t PusTmCreator::serialize(uint8_t** buffer, size_t* size, size_t maxSize, SerializeIF::Endianness streamEndianness) const { -- 2.43.0 From f28b9ea61b52cf8b7c4675b2e5bb5dc87143a61e Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Fri, 22 Jul 2022 16:41:32 +0200 Subject: [PATCH 028/108] APID getter bugfix --- src/fsfw/tcdistribution/CCSDSDistributor.h | 2 +- src/fsfw/tmtcpacket/ccsds/SpacePacketIF.h | 3 +- src/fsfw/tmtcpacket/pus/tm/PusTmCreator.cpp | 31 ++++++++++++++++ src/fsfw/tmtcpacket/pus/tm/PusTmCreator.h | 4 ++ unittests/tmtcpacket/testPusTmCreator.cpp | 41 +++++++++++++++++++++ 5 files changed, 78 insertions(+), 3 deletions(-) diff --git a/src/fsfw/tcdistribution/CCSDSDistributor.h b/src/fsfw/tcdistribution/CCSDSDistributor.h index 2d9b1fbd..b5cfc5a4 100644 --- a/src/fsfw/tcdistribution/CCSDSDistributor.h +++ b/src/fsfw/tcdistribution/CCSDSDistributor.h @@ -31,7 +31,7 @@ class CCSDSDistributor : public TcDistributor, /** * The destructor is empty. */ - virtual ~CCSDSDistributor(); + ~CCSDSDistributor() override; MessageQueueId_t getRequestQueue() override; ReturnValue_t registerApplication(uint16_t apid, MessageQueueId_t id) override; diff --git a/src/fsfw/tmtcpacket/ccsds/SpacePacketIF.h b/src/fsfw/tmtcpacket/ccsds/SpacePacketIF.h index de01e819..41d087ad 100644 --- a/src/fsfw/tmtcpacket/ccsds/SpacePacketIF.h +++ b/src/fsfw/tmtcpacket/ccsds/SpacePacketIF.h @@ -51,9 +51,8 @@ class SpacePacketIF { virtual PacketSeqCtrl getPacketSeqCtrl() { return PacketSeqCtrl::fromRaw(getPacketSeqCtrlRaw()); } [[nodiscard]] virtual uint16_t getApid() const { - uint16_t packetId = getPacketIdRaw(); // Uppermost 11 bits of packet ID - return ((packetId >> 8) & 0b111) | (packetId & 0xFF); + return getPacketIdRaw() & 0x7ff; } /** diff --git a/src/fsfw/tmtcpacket/pus/tm/PusTmCreator.cpp b/src/fsfw/tmtcpacket/pus/tm/PusTmCreator.cpp index 479358b7..9cbdeb5c 100644 --- a/src/fsfw/tmtcpacket/pus/tm/PusTmCreator.cpp +++ b/src/fsfw/tmtcpacket/pus/tm/PusTmCreator.cpp @@ -13,17 +13,27 @@ PusTmCreator::PusTmCreator(SpacePacketParams initSpParams, PusTmParams initPusPa PusTmCreator::PusTmCreator() { setup(); } uint16_t PusTmCreator::getPacketIdRaw() const { return spCreator.getPacketIdRaw(); } + uint16_t PusTmCreator::getPacketSeqCtrlRaw() const { return spCreator.getPacketSeqCtrlRaw(); } + uint16_t PusTmCreator::getPacketDataLen() const { return spCreator.getPacketDataLen(); } + uint8_t PusTmCreator::getPusVersion() const { return pusParams.secHeader.pusVersion; } + uint8_t PusTmCreator::getService() const { return pusParams.secHeader.service; } + uint8_t PusTmCreator::getSubService() const { return pusParams.secHeader.subservice; } + PusTmParams& PusTmCreator::getParams() { return pusParams; } + void PusTmCreator::setTimeStamper(TimeStamperIF* timeStamper_) { pusParams.secHeader.timeStamper = timeStamper_; } + uint8_t PusTmCreator::getScTimeRefStatus() { return pusParams.secHeader.scTimeRefStatus; } + uint16_t PusTmCreator::getMessageTypeCounter() { return pusParams.secHeader.messageTypeCounter; } + uint16_t PusTmCreator::getDestId() { return pusParams.secHeader.destId; } ReturnValue_t PusTmCreator::serialize(uint8_t** buffer, size_t* size, size_t maxSize, @@ -83,7 +93,9 @@ ReturnValue_t PusTmCreator::deSerialize(const uint8_t** buffer, size_t* size, } ecss::DataWrapper& PusTmCreator::getDataWrapper() { return pusParams.dataWrapper; } + TimeStamperIF* PusTmCreator::getTimestamper() const { return pusParams.secHeader.timeStamper; } + SpacePacketParams& PusTmCreator::getSpParams() { return spCreator.getParams(); } void PusTmCreator::updateSpLengthField() { @@ -105,3 +117,22 @@ void PusTmCreator::setup() { updateSpLengthField(); spCreator.setPacketType(ccsds::PacketType::TM); } + +void PusTmCreator::setMessageTypeCounter(uint16_t messageTypeCounter) { + pusParams.secHeader.messageTypeCounter = messageTypeCounter; +}; + +void PusTmCreator::setDestId(uint16_t destId) { pusParams.secHeader.destId = destId; } + +void PusTmCreator::setRawSourceData(ecss::DataWrapper::BufPairT bufPair) { + pusParams.dataWrapper.type = ecss::DataTypes::RAW; + pusParams.dataWrapper.dataUnion.raw.data = bufPair.first; + pusParams.dataWrapper.dataUnion.raw.len = bufPair.second; + updateSpLengthField(); +} + +void PusTmCreator::setSerializableSourceData(SerializeIF* serializable) { + pusParams.dataWrapper.type = ecss::DataTypes::SERIALIZABLE; + pusParams.dataWrapper.dataUnion.serializable = serializable; + updateSpLengthField(); +} diff --git a/src/fsfw/tmtcpacket/pus/tm/PusTmCreator.h b/src/fsfw/tmtcpacket/pus/tm/PusTmCreator.h index 97c96391..c0406dc0 100644 --- a/src/fsfw/tmtcpacket/pus/tm/PusTmCreator.h +++ b/src/fsfw/tmtcpacket/pus/tm/PusTmCreator.h @@ -47,7 +47,11 @@ class PusTmCreator : public SerializeIF, public PusTmIF, public CreatorDataIF { void setTimeStamper(TimeStamperIF* timeStamper); SpacePacketParams& getSpParams(); + void setRawSourceData(ecss::DataWrapper::BufPairT bufPair); + void setSerializableSourceData(SerializeIF* serializable); void setApid(uint16_t apid); + void setDestId(uint16_t destId); + void setMessageTypeCounter(uint16_t messageTypeCounter); PusTmParams& getParams(); void updateSpLengthField(); [[nodiscard]] uint16_t getPacketIdRaw() const override; diff --git a/unittests/tmtcpacket/testPusTmCreator.cpp b/unittests/tmtcpacket/testPusTmCreator.cpp index 6b92b134..0cb1c093 100644 --- a/unittests/tmtcpacket/testPusTmCreator.cpp +++ b/unittests/tmtcpacket/testPusTmCreator.cpp @@ -62,4 +62,45 @@ TEST_CASE("PUS TM Creator", "[pus-tm-creator]") { REQUIRE(buf[20] == 0x03); REQUIRE(buf[21] == 0x79); } + + SECTION("Custom Fields") { + creator.setApid(0x3ff); + SECTION("Using Params") { + auto& pusParams = creator.getParams(); + pusParams.secHeader.destId = 0xfff; + pusParams.secHeader.messageTypeCounter = 0x313; + } + SECTION("Using Setters") { + auto& pusParams = creator.getParams(); + creator.setDestId(0xfff); + creator.setMessageTypeCounter(0x313); + } + REQUIRE(creator.getApid() == 0x3ff); + REQUIRE(creator.getDestId() == 0xfff); + REQUIRE(creator.getMessageTypeCounter() == 0x313); + REQUIRE(creator.serialize(&dataPtr, &serLen, buf.size()) == HasReturnvaluesIF::RETURN_OK); + // Message Sequence Count + REQUIRE(((buf[9] << 8) | buf[10]) == 0x313); + // Destination ID + REQUIRE(((buf[11] << 8) | buf[12]) == 0xfff); + } + + SECTION("Deserialization fails") { + const uint8_t* roDataPtr = nullptr; + REQUIRE(creator.deSerialize(&roDataPtr, &serLen, SerializeIF::Endianness::NETWORK) == HasReturnvaluesIF::RETURN_FAILED); + } + + SECTION("Serialize with Raw Data") { + std::array data{1, 2, 3}; + creator.setRawSourceData({data.data(), data.size()}); + REQUIRE(creator.getFullPacketLen() == 25); + REQUIRE(creator.serialize(&dataPtr, &serLen, buf.size()) == HasReturnvaluesIF::RETURN_OK); + REQUIRE(buf[20] == 1); + REQUIRE(buf[21] == 2); + REQUIRE(buf[22] == 3); + } + + SECTION("Serialize with Serializable") { + + } } \ No newline at end of file -- 2.43.0 From cecaec600753abc65d99ae09f991412b8079af74 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Fri, 22 Jul 2022 17:09:44 +0200 Subject: [PATCH 029/108] PUS TM creator tests done --- src/fsfw/tmtcpacket/pus/CreatorDataIF.h | 10 ---- src/fsfw/tmtcpacket/pus/CustomUserDataIF.h | 12 +++++ src/fsfw/tmtcpacket/pus/defs.h | 2 +- src/fsfw/tmtcpacket/pus/tc/PusTcCreator.cpp | 16 +++--- src/fsfw/tmtcpacket/pus/tc/PusTcCreator.h | 9 ++-- src/fsfw/tmtcpacket/pus/tm/PusTmCreator.cpp | 17 +++---- src/fsfw/tmtcpacket/pus/tm/PusTmCreator.h | 11 ++--- unittests/tmtcpacket/testPusTcCreator.cpp | 5 +- unittests/tmtcpacket/testPusTcReader.cpp | 55 +++++++++++---------- unittests/tmtcpacket/testPusTmCreator.cpp | 46 +++++++++++++++-- 10 files changed, 110 insertions(+), 73 deletions(-) delete mode 100644 src/fsfw/tmtcpacket/pus/CreatorDataIF.h create mode 100644 src/fsfw/tmtcpacket/pus/CustomUserDataIF.h diff --git a/src/fsfw/tmtcpacket/pus/CreatorDataIF.h b/src/fsfw/tmtcpacket/pus/CreatorDataIF.h deleted file mode 100644 index f66ca567..00000000 --- a/src/fsfw/tmtcpacket/pus/CreatorDataIF.h +++ /dev/null @@ -1,10 +0,0 @@ -#ifndef FSFW_TMTCPACKET_CREATORDATAIF_H -#define FSFW_TMTCPACKET_CREATORDATAIF_H - -#include "defs.h" - -class CreatorDataIF { - public: - virtual ecss::DataWrapper& getDataWrapper() = 0; -}; -#endif // FSFW_TMTCPACKET_CREATORDATAIF_H diff --git a/src/fsfw/tmtcpacket/pus/CustomUserDataIF.h b/src/fsfw/tmtcpacket/pus/CustomUserDataIF.h new file mode 100644 index 00000000..ddbce9f1 --- /dev/null +++ b/src/fsfw/tmtcpacket/pus/CustomUserDataIF.h @@ -0,0 +1,12 @@ +#ifndef FSFW_TMTCPACKET_CREATORDATAIF_H +#define FSFW_TMTCPACKET_CREATORDATAIF_H + +#include "defs.h" + +class CustomUserDataIF { + public: + virtual ~CustomUserDataIF() = default; + virtual ReturnValue_t setRawUserData(const uint8_t* data, size_t len) = 0; + virtual ReturnValue_t setSerializableUserData(SerializeIF* serializable) = 0; +}; +#endif // FSFW_TMTCPACKET_CREATORDATAIF_H diff --git a/src/fsfw/tmtcpacket/pus/defs.h b/src/fsfw/tmtcpacket/pus/defs.h index 83502ed3..72a154ff 100644 --- a/src/fsfw/tmtcpacket/pus/defs.h +++ b/src/fsfw/tmtcpacket/pus/defs.h @@ -28,7 +28,7 @@ union DataUnion { struct DataWrapper { DataTypes type; DataUnion dataUnion; - using BufPairT = std::pair; + using BufPairT = std::pair; [[nodiscard]] size_t getLength() const { if (type == DataTypes::RAW) { diff --git a/src/fsfw/tmtcpacket/pus/tc/PusTcCreator.cpp b/src/fsfw/tmtcpacket/pus/tc/PusTcCreator.cpp index 240e7718..9ffd6eb4 100644 --- a/src/fsfw/tmtcpacket/pus/tc/PusTcCreator.cpp +++ b/src/fsfw/tmtcpacket/pus/tc/PusTcCreator.cpp @@ -16,7 +16,7 @@ ReturnValue_t PusTcCreator::serialize(uint8_t **buffer, size_t *size, size_t max SerializeIF::Endianness streamEndianness) const { const uint8_t *start = *buffer; size_t userDataLen = pusParams.dataWrapper.getLength(); - if (*size + getFullPacketLen() > maxSize) { + if (*size + getSerializedSize() > maxSize) { return SerializeIF::BUFFER_TOO_SHORT; } if (pusParams.pusVersion != ecss::PusVersion::PUS_C) { @@ -86,8 +86,6 @@ uint8_t PusTcCreator::getSubService() const { return pusParams.subservice; } uint16_t PusTcCreator::getSourceId() const { return pusParams.sourceId; } -ecss::DataWrapper &PusTcCreator::getDataWrapper() { return pusParams.dataWrapper; } - PusTcParams &PusTcCreator::getPusParams() { return pusParams; } SpacePacketParams &PusTcCreator::getSpParams() { return spCreator.getParams(); } @@ -96,12 +94,16 @@ ReturnValue_t PusTcCreator::serialize(uint8_t **buffer, size_t *size, size_t max return serialize(buffer, size, maxSize, SerializeIF::Endianness::NETWORK); } -void PusTcCreator::setRawAppData(ecss::DataWrapper::BufPairT bufPair) { - pusParams.dataWrapper.setRawData(bufPair); +ReturnValue_t PusTcCreator::setRawUserData(const uint8_t *data, size_t len) { + // TODO: Check length field? + pusParams.dataWrapper.setRawData({data, len}); updateSpLengthField(); + return HasReturnvaluesIF::RETURN_OK; } -void PusTcCreator::setSerializableAppData(SerializeIF *serAppData) { - pusParams.dataWrapper.setSerializable(serAppData); +ReturnValue_t PusTcCreator::setSerializableUserData(SerializeIF *serializable) { + // TODO: Check length field? + pusParams.dataWrapper.setSerializable(serializable); updateSpLengthField(); + return HasReturnvaluesIF::RETURN_OK; } diff --git a/src/fsfw/tmtcpacket/pus/tc/PusTcCreator.h b/src/fsfw/tmtcpacket/pus/tc/PusTcCreator.h index 9e6b6e6f..4e5951a5 100644 --- a/src/fsfw/tmtcpacket/pus/tc/PusTcCreator.h +++ b/src/fsfw/tmtcpacket/pus/tc/PusTcCreator.h @@ -4,7 +4,7 @@ #include "fsfw/tmtcpacket/RedirectableDataPointerIF.h" #include "fsfw/tmtcpacket/ccsds/SpacePacketCreator.h" #include "fsfw/tmtcpacket/ccsds/SpacePacketIF.h" -#include "fsfw/tmtcpacket/pus/CreatorDataIF.h" +#include "fsfw/tmtcpacket/pus/CustomUserDataIF.h" #include "fsfw/tmtcpacket/pus/defs.h" #include "fsfw/tmtcpacket/pus/tc/PusTcIF.h" @@ -19,7 +19,7 @@ struct PusTcParams { uint8_t pusVersion = ecss::PusVersion::PUS_C; }; -class PusTcCreator : public PusTcIF, public SerializeIF, public CreatorDataIF { +class PusTcCreator : public PusTcIF, public SerializeIF, public CustomUserDataIF { public: PusTcCreator(SpacePacketParams initSpParams, PusTcParams initPusParams); @@ -33,8 +33,6 @@ class PusTcCreator : public PusTcIF, public SerializeIF, public CreatorDataIF { void updateSpLengthField(); PusTcParams &getPusParams(); SpacePacketParams &getSpParams(); - void setRawAppData(ecss::DataWrapper::BufPairT bufPair); - void setSerializableAppData(SerializeIF *serAppData); ReturnValue_t serialize(uint8_t **buffer, size_t *size, size_t maxSize); [[nodiscard]] size_t getSerializedSize() const override; @@ -48,7 +46,8 @@ class PusTcCreator : public PusTcIF, public SerializeIF, public CreatorDataIF { [[nodiscard]] uint8_t getService() const override; [[nodiscard]] uint8_t getSubService() const override; [[nodiscard]] uint16_t getSourceId() const override; - ecss::DataWrapper &getDataWrapper() override; + ReturnValue_t setRawUserData(const uint8_t *data, size_t len) override; + ReturnValue_t setSerializableUserData(SerializeIF *serializable) override; private: ReturnValue_t serialize(uint8_t **buffer, size_t *size, size_t maxSize, diff --git a/src/fsfw/tmtcpacket/pus/tm/PusTmCreator.cpp b/src/fsfw/tmtcpacket/pus/tm/PusTmCreator.cpp index 9cbdeb5c..b8ef0852 100644 --- a/src/fsfw/tmtcpacket/pus/tm/PusTmCreator.cpp +++ b/src/fsfw/tmtcpacket/pus/tm/PusTmCreator.cpp @@ -28,6 +28,7 @@ PusTmParams& PusTmCreator::getParams() { return pusParams; } void PusTmCreator::setTimeStamper(TimeStamperIF* timeStamper_) { pusParams.secHeader.timeStamper = timeStamper_; + updateSpLengthField(); } uint8_t PusTmCreator::getScTimeRefStatus() { return pusParams.secHeader.scTimeRefStatus; } @@ -92,8 +93,6 @@ ReturnValue_t PusTmCreator::deSerialize(const uint8_t** buffer, size_t* size, return HasReturnvaluesIF::RETURN_FAILED; } -ecss::DataWrapper& PusTmCreator::getDataWrapper() { return pusParams.dataWrapper; } - TimeStamperIF* PusTmCreator::getTimestamper() const { return pusParams.secHeader.timeStamper; } SpacePacketParams& PusTmCreator::getSpParams() { return spCreator.getParams(); } @@ -124,15 +123,13 @@ void PusTmCreator::setMessageTypeCounter(uint16_t messageTypeCounter) { void PusTmCreator::setDestId(uint16_t destId) { pusParams.secHeader.destId = destId; } -void PusTmCreator::setRawSourceData(ecss::DataWrapper::BufPairT bufPair) { - pusParams.dataWrapper.type = ecss::DataTypes::RAW; - pusParams.dataWrapper.dataUnion.raw.data = bufPair.first; - pusParams.dataWrapper.dataUnion.raw.len = bufPair.second; +ReturnValue_t PusTmCreator::setRawUserData(const uint8_t* data, size_t len) { + pusParams.dataWrapper.setRawData({data, len}); updateSpLengthField(); + return HasReturnvaluesIF::RETURN_OK; } - -void PusTmCreator::setSerializableSourceData(SerializeIF* serializable) { - pusParams.dataWrapper.type = ecss::DataTypes::SERIALIZABLE; - pusParams.dataWrapper.dataUnion.serializable = serializable; +ReturnValue_t PusTmCreator::setSerializableUserData(SerializeIF* serializable) { + pusParams.dataWrapper.setSerializable(serializable); updateSpLengthField(); + return HasReturnvaluesIF::RETURN_OK; } diff --git a/src/fsfw/tmtcpacket/pus/tm/PusTmCreator.h b/src/fsfw/tmtcpacket/pus/tm/PusTmCreator.h index c0406dc0..9981c39c 100644 --- a/src/fsfw/tmtcpacket/pus/tm/PusTmCreator.h +++ b/src/fsfw/tmtcpacket/pus/tm/PusTmCreator.h @@ -3,7 +3,7 @@ #include "PusTmIF.h" #include "fsfw/tmtcpacket/ccsds/SpacePacketCreator.h" -#include "fsfw/tmtcpacket/pus/CreatorDataIF.h" +#include "fsfw/tmtcpacket/pus/CustomUserDataIF.h" struct PusTmSecHeader { PusTmSecHeader() = default; @@ -39,7 +39,7 @@ struct PusTmParams { class TimeStamperIF; -class PusTmCreator : public SerializeIF, public PusTmIF, public CreatorDataIF { +class PusTmCreator : public SerializeIF, public PusTmIF, public CustomUserDataIF { public: PusTmCreator(); PusTmCreator(SpacePacketParams initSpParams, PusTmParams initPusParams); @@ -47,8 +47,6 @@ class PusTmCreator : public SerializeIF, public PusTmIF, public CreatorDataIF { void setTimeStamper(TimeStamperIF* timeStamper); SpacePacketParams& getSpParams(); - void setRawSourceData(ecss::DataWrapper::BufPairT bufPair); - void setSerializableSourceData(SerializeIF* serializable); void setApid(uint16_t apid); void setDestId(uint16_t destId); void setMessageTypeCounter(uint16_t messageTypeCounter); @@ -70,9 +68,8 @@ class PusTmCreator : public SerializeIF, public PusTmIF, public CreatorDataIF { ReturnValue_t deSerialize(const uint8_t** buffer, size_t* size, Endianness streamEndianness) override; [[nodiscard]] TimeStamperIF* getTimestamper() const; - - private: - ecss::DataWrapper& getDataWrapper() override; + ReturnValue_t setRawUserData(const uint8_t* data, size_t len) override; + ReturnValue_t setSerializableUserData(SerializeIF* serializable) override; private: void setup(); diff --git a/unittests/tmtcpacket/testPusTcCreator.cpp b/unittests/tmtcpacket/testPusTcCreator.cpp index 28c7e555..978833cd 100644 --- a/unittests/tmtcpacket/testPusTcCreator.cpp +++ b/unittests/tmtcpacket/testPusTcCreator.cpp @@ -85,10 +85,7 @@ TEST_CASE("PUS TC Creator", "[pus-tc-creator]") { SECTION("Test with Application Data Serializable") { auto& params = creator.getPusParams(); auto simpleSer = SimpleSerializable(); - creator.setSerializableAppData(&simpleSer); - auto& dataWrapper = creator.getDataWrapper(); - REQUIRE(dataWrapper.type == ecss::DataTypes::SERIALIZABLE); - REQUIRE(dataWrapper.dataUnion.serializable == &simpleSer); + creator.setSerializableUserData(&simpleSer); REQUIRE(creator.getSerializedSize() == 16); REQUIRE(creator.serialize(&dataPtr, &serLen, buf.size()) == HasReturnvaluesIF::RETURN_OK); REQUIRE(serLen == 16); diff --git a/unittests/tmtcpacket/testPusTcReader.cpp b/unittests/tmtcpacket/testPusTcReader.cpp index 1c870f78..82a88542 100644 --- a/unittests/tmtcpacket/testPusTcReader.cpp +++ b/unittests/tmtcpacket/testPusTcReader.cpp @@ -15,38 +15,43 @@ TEST_CASE("PUS TC Reader", "[pus-tc-reader]") { size_t serLen = 0; PusTcReader reader; auto checkReaderFields = [&](PusTcReader& reader) { - REQUIRE(not reader.isNull()); - REQUIRE(reader.getPacketType() == ccsds::PacketType::TC); - REQUIRE(reader.getApid() == 0x02); - REQUIRE(reader.getService() == 17); - REQUIRE(reader.getSubService() == 1); - REQUIRE(reader.getFullPacketLen() == 13); - REQUIRE(reader.getPacketDataLen() == 6); - REQUIRE(reader.getPusVersion() == 2); - REQUIRE(reader.getSequenceCount() == 0x34); - REQUIRE(reader.getUserData() == nullptr); - REQUIRE(reader.getUserDataLen() == 0); - REQUIRE(reader.getFullData() == buf.data()); - REQUIRE(reader.getSourceId() == 0x00); - REQUIRE(reader.getAcknowledgeFlags() == 0b1111); - // This value was verified to be correct - REQUIRE(reader.getErrorControl() == 0xee63); + }; SECTION("State") { REQUIRE(creator.serialize(&dataPtr, &serLen, buf.size()) == HasReturnvaluesIF::RETURN_OK); REQUIRE(reader.isNull()); - + PusTcReader* readerPtr = nullptr; + bool callDelete = false; SECTION("Setter") { - REQUIRE(reader.setReadOnlyData(buf.data(), serLen) == HasReturnvaluesIF::RETURN_OK); - REQUIRE(reader.parseDataWithCrcCheck() == HasReturnvaluesIF::RETURN_OK); - checkReaderFields(reader); + readerPtr = &reader; + REQUIRE(readerPtr->setReadOnlyData(buf.data(), serLen) == HasReturnvaluesIF::RETURN_OK); + REQUIRE(readerPtr->parseDataWithCrcCheck() == HasReturnvaluesIF::RETURN_OK); } SECTION("Directly Constructed") { - PusTcReader secondReader(buf.data(), serLen); - REQUIRE(not secondReader.isNull()); - REQUIRE(secondReader.parseDataWithCrcCheck() == HasReturnvaluesIF::RETURN_OK); - checkReaderFields(secondReader); + callDelete = true; + readerPtr = new PusTcReader(buf.data(), serLen); + REQUIRE(not readerPtr->isNull()); + REQUIRE(readerPtr->parseDataWithCrcCheck() == HasReturnvaluesIF::RETURN_OK); + } + REQUIRE(not readerPtr->isNull()); + REQUIRE(readerPtr->getPacketType() == ccsds::PacketType::TC); + REQUIRE(readerPtr->getApid() == 0x02); + REQUIRE(readerPtr->getService() == 17); + REQUIRE(readerPtr->getSubService() == 1); + REQUIRE(readerPtr->getFullPacketLen() == 13); + REQUIRE(readerPtr->getPacketDataLen() == 6); + REQUIRE(readerPtr->getPusVersion() == 2); + REQUIRE(readerPtr->getSequenceCount() == 0x34); + REQUIRE(readerPtr->getUserData() == nullptr); + REQUIRE(readerPtr->getUserDataLen() == 0); + REQUIRE(readerPtr->getFullData() == buf.data()); + REQUIRE(readerPtr->getSourceId() == 0x00); + REQUIRE(readerPtr->getAcknowledgeFlags() == 0b1111); + // This value was verified to be correct + REQUIRE(readerPtr->getErrorControl() == 0xee63); + if (callDelete) { + delete readerPtr; } } @@ -67,7 +72,7 @@ TEST_CASE("PUS TC Reader", "[pus-tc-reader]") { SECTION("With application data") { auto& params = creator.getPusParams(); std::array data{1, 2, 3}; - creator.setRawAppData({data.data(), data.size()}); + creator.setRawUserData(data.data(), data.size()); REQUIRE(creator.serialize(&dataPtr, &serLen, buf.size()) == HasReturnvaluesIF::RETURN_OK); REQUIRE(reader.setReadOnlyData(buf.data(), serLen) == HasReturnvaluesIF::RETURN_OK); REQUIRE(reader.parseDataWithCrcCheck() == HasReturnvaluesIF::RETURN_OK); diff --git a/unittests/tmtcpacket/testPusTmCreator.cpp b/unittests/tmtcpacket/testPusTmCreator.cpp index 0cb1c093..2b60515f 100644 --- a/unittests/tmtcpacket/testPusTmCreator.cpp +++ b/unittests/tmtcpacket/testPusTmCreator.cpp @@ -1,9 +1,10 @@ #include +#include "fsfw/globalfunctions/CRC.h" #include "fsfw/globalfunctions/arrayprinter.h" #include "fsfw/tmtcpacket/pus/tm.h" -#include "fsfw/globalfunctions/CRC.h" #include "mocks/CdsShortTimestamperMock.h" +#include "mocks/SimpleSerializable.h" TEST_CASE("PUS TM Creator", "[pus-tm-creator]") { auto packetId = PacketId(ccsds::PacketType::TC, true, 0xef); @@ -20,6 +21,8 @@ TEST_CASE("PUS TM Creator", "[pus-tm-creator]") { SECTION("State") { REQUIRE(creator.isTm()); REQUIRE(creator.getApid() == 0xef); + REQUIRE(creator.getPusVersion() == 2); + REQUIRE(creator.getScTimeRefStatus() == 0); REQUIRE(creator.getService() == 17); REQUIRE(creator.getSubService() == 2); REQUIRE(creator.getTimestamper() == &timeStamper); @@ -34,6 +37,12 @@ TEST_CASE("PUS TM Creator", "[pus-tm-creator]") { REQUIRE(timeStamper.getSizeCallCount == 1); } + SECTION("SP Params") { + auto& spParamsRef = creator.getSpParams(); + REQUIRE(spParamsRef.dataLen == 15); + REQUIRE(spParamsRef.packetId.apid == 0xef); + } + SECTION("Serialization") { REQUIRE(creator.serialize(&dataPtr, &serLen, buf.size()) == HasReturnvaluesIF::RETURN_OK); REQUIRE(buf[0] == 0x08); @@ -54,7 +63,7 @@ TEST_CASE("PUS TM Creator", "[pus-tm-creator]") { // Destination ID REQUIRE(((buf[11] << 8) | buf[12]) == 0); // Custom timestamp - for(size_t i = 1; i < 8; i++) { + for (size_t i = 1; i < 8; i++) { REQUIRE(buf[12 + i] == i); } REQUIRE(serLen == 22); @@ -87,12 +96,13 @@ TEST_CASE("PUS TM Creator", "[pus-tm-creator]") { SECTION("Deserialization fails") { const uint8_t* roDataPtr = nullptr; - REQUIRE(creator.deSerialize(&roDataPtr, &serLen, SerializeIF::Endianness::NETWORK) == HasReturnvaluesIF::RETURN_FAILED); + REQUIRE(creator.deSerialize(&roDataPtr, &serLen, SerializeIF::Endianness::NETWORK) == + HasReturnvaluesIF::RETURN_FAILED); } SECTION("Serialize with Raw Data") { std::array data{1, 2, 3}; - creator.setRawSourceData({data.data(), data.size()}); + creator.setRawUserData(data.data(), data.size()); REQUIRE(creator.getFullPacketLen() == 25); REQUIRE(creator.serialize(&dataPtr, &serLen, buf.size()) == HasReturnvaluesIF::RETURN_OK); REQUIRE(buf[20] == 1); @@ -101,6 +111,34 @@ TEST_CASE("PUS TM Creator", "[pus-tm-creator]") { } SECTION("Serialize with Serializable") { + auto simpleSer = SimpleSerializable(); + creator.setSerializableUserData(&simpleSer); + REQUIRE(creator.getFullPacketLen() == 25); + REQUIRE(creator.serialize(&dataPtr, &serLen, buf.size()) == HasReturnvaluesIF::RETURN_OK); + REQUIRE(buf[20] == 1); + REQUIRE(buf[21] == 2); + REQUIRE(buf[22] == 3); + } + SECTION("Empty Ctor") { + PusTmCreator creatorFromEmptyCtor; + // 6 bytes CCSDS header, 7 bytes secondary header, no timestamp (IF is null), + // 0 bytes application data, 2 bytes CRC + REQUIRE(creatorFromEmptyCtor.getFullPacketLen() == 15); + // As specified in standard, the data length fields is the total size of the packet without + // the primary header minus 1 + REQUIRE(creatorFromEmptyCtor.getPacketDataLen() == 8); + creatorFromEmptyCtor.setTimeStamper(&timeStamper); + REQUIRE(creatorFromEmptyCtor.getFullPacketLen() == 22); + REQUIRE(creatorFromEmptyCtor.getPacketDataLen() == 15); + } + + SECTION("Invalid Buffer Sizes") { + size_t reqSize = creator.getSerializedSize(); + for (size_t maxSize = 0; maxSize < reqSize; maxSize++) { + dataPtr = buf.data(); + serLen = 0; + REQUIRE(creator.serialize(&dataPtr, &serLen, maxSize) == SerializeIF::BUFFER_TOO_SHORT); + } } } \ No newline at end of file -- 2.43.0 From 2dfbce6174582346c87367415b8ded3732eb44ec Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Fri, 22 Jul 2022 17:11:55 +0200 Subject: [PATCH 030/108] start TM reader unittests --- unittests/tmtcpacket/testPusTmReader.cpp | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/unittests/tmtcpacket/testPusTmReader.cpp b/unittests/tmtcpacket/testPusTmReader.cpp index 59c01914..69dc7088 100644 --- a/unittests/tmtcpacket/testPusTmReader.cpp +++ b/unittests/tmtcpacket/testPusTmReader.cpp @@ -1,3 +1,18 @@ #include -TEST_CASE("PUS TM Reader", "[pus-tm-reader]") {} \ No newline at end of file +#include "fsfw/tmtcpacket/pus/tm/PusTmCreator.h" +#include "mocks/CdsShortTimestamperMock.h" + +TEST_CASE("PUS TM Reader", "[pus-tm-reader]") { + auto packetId = PacketId(ccsds::PacketType::TC, true, 0xef); + auto spParams = + SpacePacketParams(packetId, PacketSeqCtrl(ccsds::SequenceFlags::UNSEGMENTED, 22), 0x00); + auto timeStamper = CdsShortTimestamperMock(); + auto pusTmParams = PusTmParams(17, 2, &timeStamper); + timeStamper.valueToStamp = {1, 2, 3, 4, 5, 6, 7}; + PusTmCreator creator(spParams, pusTmParams); + + SECTION("State") { + + } +} \ No newline at end of file -- 2.43.0 From b350018cad26979c3dd11a4b55e924c5d53bf49a Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Fri, 22 Jul 2022 18:22:35 +0200 Subject: [PATCH 031/108] completed basic test set --- src/fsfw/timemanager/TimeReaderIF.h | 2 +- src/fsfw/tmtcpacket/pus/tc/PusTcReader.cpp | 2 + src/fsfw/tmtcpacket/pus/tc/PusTcReader.h | 7 +- src/fsfw/tmtcpacket/pus/tm/PusTmReader.cpp | 8 +- src/fsfw/tmtcpacket/pus/tm/PusTmReader.h | 6 +- unittests/mocks/CdsShortTimestamperMock.h | 19 ++++- unittests/tmtcpacket/testPusTcReader.cpp | 5 +- unittests/tmtcpacket/testPusTmCreator.cpp | 1 + unittests/tmtcpacket/testPusTmReader.cpp | 86 ++++++++++++++++++++-- 9 files changed, 117 insertions(+), 19 deletions(-) diff --git a/src/fsfw/timemanager/TimeReaderIF.h b/src/fsfw/timemanager/TimeReaderIF.h index 388f7d71..cfad90ff 100644 --- a/src/fsfw/timemanager/TimeReaderIF.h +++ b/src/fsfw/timemanager/TimeReaderIF.h @@ -8,7 +8,7 @@ class TimeReaderIF { public: virtual ~TimeReaderIF() = default; - virtual ReturnValue_t readTimeStamp(const uint8_t* buffer, uint8_t maxSize) = 0; + virtual ReturnValue_t readTimeStamp(const uint8_t* buffer, size_t maxSize) = 0; // Would be nice to have this, but the clock backend needs to be redesigned // virtual ReturnValue_t readTimestampLen(const uint8_t* buffer, uint8_t maxSize, size_t& // timestampLen) = 0; diff --git a/src/fsfw/tmtcpacket/pus/tc/PusTcReader.cpp b/src/fsfw/tmtcpacket/pus/tc/PusTcReader.cpp index f5dd143a..f50affa7 100644 --- a/src/fsfw/tmtcpacket/pus/tc/PusTcReader.cpp +++ b/src/fsfw/tmtcpacket/pus/tc/PusTcReader.cpp @@ -82,3 +82,5 @@ const uint8_t* PusTcReader::getUserData() const { return pointers.userDataStart; size_t PusTcReader::getUserDataLen() const { return appDataSize; } bool PusTcReader::isNull() const { return spReader.isNull(); } + +PusTcReader::operator bool() const { return not isNull(); } diff --git a/src/fsfw/tmtcpacket/pus/tc/PusTcReader.h b/src/fsfw/tmtcpacket/pus/tc/PusTcReader.h index 3be2e5e6..1b9eea49 100644 --- a/src/fsfw/tmtcpacket/pus/tc/PusTcReader.h +++ b/src/fsfw/tmtcpacket/pus/tc/PusTcReader.h @@ -33,16 +33,13 @@ class PusTcReader : public PusTcIF, * @param setData The position where the packet data lies. */ PusTcReader(const uint8_t* setData, size_t size); + ~PusTcReader() override; + explicit operator bool() const; [[nodiscard]] bool isNull() const; ReturnValue_t parseDataWithCrcCheck(); ReturnValue_t parseDataWithoutCrcCheck(); - /** - * This is the empty default destructor. - */ - ~PusTcReader() override; - /** * This is a debugging helper method that prints the whole packet content * to the screen. diff --git a/src/fsfw/tmtcpacket/pus/tm/PusTmReader.cpp b/src/fsfw/tmtcpacket/pus/tm/PusTmReader.cpp index e700a428..0dfab4ce 100644 --- a/src/fsfw/tmtcpacket/pus/tm/PusTmReader.cpp +++ b/src/fsfw/tmtcpacket/pus/tm/PusTmReader.cpp @@ -71,8 +71,11 @@ ReturnValue_t PusTmReader::parseData(bool crcCheck) { return SerializeIF::STREAM_TOO_SHORT; } currentOffset += timestampLen; - pointers.userDataStart = pointers.spHeaderStart + currentOffset; sourceDataLen = spReader.getFullPacketLen() - currentOffset - sizeof(ecss::PusChecksumT); + pointers.userDataStart = nullptr; + if (sourceDataLen > 0) { + pointers.userDataStart = pointers.spHeaderStart + currentOffset; + } currentOffset += sourceDataLen; pointers.crcStart = pointers.spHeaderStart + currentOffset; if (crcCheck) { @@ -84,3 +87,6 @@ ReturnValue_t PusTmReader::parseData(bool crcCheck) { } return HasReturnvaluesIF::RETURN_OK; } +bool PusTmReader::isNull() const { return spReader.isNull(); } + +PusTmReader::operator bool() const { return not isNull(); } diff --git a/src/fsfw/tmtcpacket/pus/tm/PusTmReader.h b/src/fsfw/tmtcpacket/pus/tm/PusTmReader.h index 1d91eb95..e5a61aec 100644 --- a/src/fsfw/tmtcpacket/pus/tm/PusTmReader.h +++ b/src/fsfw/tmtcpacket/pus/tm/PusTmReader.h @@ -21,6 +21,8 @@ class PusTmReader : public PusTmIF, ReturnValue_t parseDataWithCrcCheck(); const uint8_t* getFullData() override; + explicit operator bool() const; + [[nodiscard]] bool isNull() const; void setTimeReader(TimeReaderIF* timeReader); TimeReaderIF* getTimeReader(); ReturnValue_t setReadOnlyData(const uint8_t* data, size_t size); @@ -30,8 +32,8 @@ class PusTmReader : public PusTmIF, [[nodiscard]] uint8_t getPusVersion() const override; [[nodiscard]] uint8_t getService() const override; [[nodiscard]] uint8_t getSubService() const override; - const uint8_t* getUserData() const override; - size_t getUserDataLen() const override; + [[nodiscard]] const uint8_t* getUserData() const override; + [[nodiscard]] size_t getUserDataLen() const override; uint8_t getScTimeRefStatus() override; uint16_t getMessageTypeCounter() override; uint16_t getDestId() override; diff --git a/unittests/mocks/CdsShortTimestamperMock.h b/unittests/mocks/CdsShortTimestamperMock.h index 779859d0..460c98c5 100644 --- a/unittests/mocks/CdsShortTimestamperMock.h +++ b/unittests/mocks/CdsShortTimestamperMock.h @@ -5,9 +5,11 @@ #include "fsfw/timemanager/TimeStamperIF.h" -class CdsShortTimestamperMock : public TimeStamperIF { +class CdsShortTimestamperMock : public TimeStamperIF, public TimeReaderIF { public: unsigned int serializeCallCount = 0; + unsigned int deserializeCallCount = 0; + ReturnValue_t lastDeserializeResult = HasReturnvaluesIF::RETURN_OK; ReturnValue_t lastSerializeResult = HasReturnvaluesIF::RETURN_OK; unsigned int getSizeCallCount = 0; std::array valueToStamp{}; @@ -38,8 +40,15 @@ class CdsShortTimestamperMock : public TimeStamperIF { } ReturnValue_t deSerialize(const uint8_t **buffer, size_t *size, Endianness streamEndianness) override { - return HasReturnvaluesIF::RETURN_FAILED; + deserializeCallCount += 1; + if (*size < 7) { + lastDeserializeResult = SerializeIF::STREAM_TOO_SHORT; + return lastDeserializeResult; + } + std::copy(*buffer, *buffer + getSerializedSize(), valueToStamp.begin()); + return lastDeserializeResult; } + [[nodiscard]] size_t getTimestampSize() const override { return getSerializedSize(); } ReturnValue_t addTimeStamp(uint8_t *buffer, uint8_t maxSize) override { return 0; } @@ -47,7 +56,13 @@ class CdsShortTimestamperMock : public TimeStamperIF { serializeCallCount = 0; getSizeCallCount = 0; } + ReturnValue_t readTimeStamp(const uint8_t *buffer, size_t maxSize) override { + return deSerialize(&buffer, &maxSize, SerializeIF::Endianness::NETWORK); + } + size_t getTimestampLen() override { return getSerializedSize(); } + timeval &getTime() override { return dummyTime; } private: + timeval dummyTime{}; }; #endif // FSFW_TESTS_CDSSHORTTIMESTAMPERMOCK_H diff --git a/unittests/tmtcpacket/testPusTcReader.cpp b/unittests/tmtcpacket/testPusTcReader.cpp index 82a88542..3245218a 100644 --- a/unittests/tmtcpacket/testPusTcReader.cpp +++ b/unittests/tmtcpacket/testPusTcReader.cpp @@ -14,13 +14,11 @@ TEST_CASE("PUS TC Reader", "[pus-tc-reader]") { uint8_t* dataPtr = buf.data(); size_t serLen = 0; PusTcReader reader; - auto checkReaderFields = [&](PusTcReader& reader) { - - }; SECTION("State") { REQUIRE(creator.serialize(&dataPtr, &serLen, buf.size()) == HasReturnvaluesIF::RETURN_OK); REQUIRE(reader.isNull()); + REQUIRE(not reader); PusTcReader* readerPtr = nullptr; bool callDelete = false; SECTION("Setter") { @@ -35,6 +33,7 @@ TEST_CASE("PUS TC Reader", "[pus-tc-reader]") { REQUIRE(readerPtr->parseDataWithCrcCheck() == HasReturnvaluesIF::RETURN_OK); } REQUIRE(not readerPtr->isNull()); + REQUIRE(*readerPtr); REQUIRE(readerPtr->getPacketType() == ccsds::PacketType::TC); REQUIRE(readerPtr->getApid() == 0x02); REQUIRE(readerPtr->getService() == 17); diff --git a/unittests/tmtcpacket/testPusTmCreator.cpp b/unittests/tmtcpacket/testPusTmCreator.cpp index 2b60515f..035126f0 100644 --- a/unittests/tmtcpacket/testPusTmCreator.cpp +++ b/unittests/tmtcpacket/testPusTmCreator.cpp @@ -70,6 +70,7 @@ TEST_CASE("PUS TM Creator", "[pus-tm-creator]") { REQUIRE(CRC::crc16ccitt(buf.data(), serLen) == 0); REQUIRE(buf[20] == 0x03); REQUIRE(buf[21] == 0x79); + REQUIRE(timeStamper.serializeCallCount == 1); } SECTION("Custom Fields") { diff --git a/unittests/tmtcpacket/testPusTmReader.cpp b/unittests/tmtcpacket/testPusTmReader.cpp index 69dc7088..8540b97c 100644 --- a/unittests/tmtcpacket/testPusTmReader.cpp +++ b/unittests/tmtcpacket/testPusTmReader.cpp @@ -1,18 +1,94 @@ #include #include "fsfw/tmtcpacket/pus/tm/PusTmCreator.h" +#include "fsfw/tmtcpacket/pus/tm/PusTmReader.h" #include "mocks/CdsShortTimestamperMock.h" TEST_CASE("PUS TM Reader", "[pus-tm-reader]") { auto packetId = PacketId(ccsds::PacketType::TC, true, 0xef); auto spParams = SpacePacketParams(packetId, PacketSeqCtrl(ccsds::SequenceFlags::UNSEGMENTED, 22), 0x00); - auto timeStamper = CdsShortTimestamperMock(); - auto pusTmParams = PusTmParams(17, 2, &timeStamper); - timeStamper.valueToStamp = {1, 2, 3, 4, 5, 6, 7}; + auto timeStamperAndReader = CdsShortTimestamperMock(); + auto pusTmParams = PusTmParams(17, 2, &timeStamperAndReader); + timeStamperAndReader.valueToStamp = {1, 2, 3, 4, 5, 6, 7}; PusTmCreator creator(spParams, pusTmParams); + PusTmReader reader(&timeStamperAndReader); + std::array buf{}; + uint8_t* dataPtr = buf.data(); + size_t serLen = 0; - SECTION("State") { - + SECTION("Basic") { + PusTmReader* readerPtr = &reader; + bool deleteReader = false; + dataPtr = buf.data(); + serLen = 0; + REQUIRE(creator.serialize(&dataPtr, &serLen, buf.size()) == HasReturnvaluesIF::RETURN_OK); + REQUIRE(not(*readerPtr)); + REQUIRE(readerPtr->isNull()); + + SECTION("Setter") { + REQUIRE(readerPtr->setReadOnlyData(buf.data(), serLen) == HasReturnvaluesIF::RETURN_OK); + } + SECTION("Full Construction") { + readerPtr = new PusTmReader(&timeStamperAndReader, buf.data(), serLen); + deleteReader = true; + } + SECTION("Time Stamper set manually") { + readerPtr = new PusTmReader(buf.data(), serLen); + readerPtr->setTimeReader(&timeStamperAndReader); + deleteReader = true; + } + REQUIRE(readerPtr); + REQUIRE(not readerPtr->isNull()); + REQUIRE(readerPtr->parseDataWithCrcCheck() == HasReturnvaluesIF::RETURN_OK); + REQUIRE(readerPtr->getService() == 17); + REQUIRE(readerPtr->getSubService() == 2); + REQUIRE(readerPtr->getApid() == 0xef); + REQUIRE(readerPtr->getSequenceFlags() == ccsds::SequenceFlags::UNSEGMENTED); + REQUIRE(readerPtr->getScTimeRefStatus() == 0); + REQUIRE(readerPtr->getDestId() == 0); + REQUIRE(readerPtr->getMessageTypeCounter() == 0); + REQUIRE(readerPtr->getTimeReader() == &timeStamperAndReader); + REQUIRE(readerPtr->getPusVersion() == 2); + REQUIRE(readerPtr->getPacketDataLen() == 15); + REQUIRE(readerPtr->getFullPacketLen() == 22); + REQUIRE(readerPtr->getUserDataLen() == 0); + REQUIRE(readerPtr->getUserData() == nullptr); + REQUIRE(readerPtr->getFullData() == buf.data()); + if (deleteReader) { + delete readerPtr; + } + } + + SECTION("Invalid CRC") { + REQUIRE(creator.serialize(&dataPtr, &serLen, buf.size()) == HasReturnvaluesIF::RETURN_OK); + buf[20] = 0; + REQUIRE(reader.setReadOnlyData(buf.data(), serLen) == HasReturnvaluesIF::RETURN_OK); + REQUIRE(reader.parseDataWithCrcCheck() == PusIF::INVALID_CRC_16); + } + + SECTION("Set Time Reader") { + reader.setTimeReader(nullptr); + REQUIRE(reader.getTimeReader() == nullptr); + } + + SECTION("Invalid CRC ignored") { + REQUIRE(creator.serialize(&dataPtr, &serLen, buf.size()) == HasReturnvaluesIF::RETURN_OK); + buf[20] = 0; + REQUIRE(reader.setReadOnlyData(buf.data(), serLen) == HasReturnvaluesIF::RETURN_OK); + REQUIRE(reader.parseDataWithoutCrcCheck() == HasReturnvaluesIF::RETURN_OK); + } + + SECTION("Read with source data") { + std::array data{1, 2, 3}; + creator.setRawUserData(data.data(), data.size()); + REQUIRE(creator.serialize(&dataPtr, &serLen, buf.size()) == HasReturnvaluesIF::RETURN_OK); + REQUIRE(reader.setReadOnlyData(buf.data(), serLen) == HasReturnvaluesIF::RETURN_OK); + REQUIRE(reader.parseDataWithCrcCheck() == HasReturnvaluesIF::RETURN_OK); + REQUIRE(reader.getUserDataLen() == 3); + const uint8_t* roData = reader.getUserData(); + REQUIRE(roData[0] == 1); + REQUIRE(roData[1] == 2); + REQUIRE(roData[2] == 3); } } \ No newline at end of file -- 2.43.0 From cb05329dd946d1503432934e4560806ff4f83674 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Fri, 22 Jul 2022 18:31:00 +0200 Subject: [PATCH 032/108] completed baseline PUS TM unittests --- unittests/mocks/CdsShortTimestamperMock.h | 18 ++++++++++++++++++ unittests/tmtcpacket/testPusTmReader.cpp | 14 ++++++++++++++ 2 files changed, 32 insertions(+) diff --git a/unittests/mocks/CdsShortTimestamperMock.h b/unittests/mocks/CdsShortTimestamperMock.h index 460c98c5..c53c22f9 100644 --- a/unittests/mocks/CdsShortTimestamperMock.h +++ b/unittests/mocks/CdsShortTimestamperMock.h @@ -12,6 +12,10 @@ class CdsShortTimestamperMock : public TimeStamperIF, public TimeReaderIF { ReturnValue_t lastDeserializeResult = HasReturnvaluesIF::RETURN_OK; ReturnValue_t lastSerializeResult = HasReturnvaluesIF::RETURN_OK; unsigned int getSizeCallCount = 0; + bool nextSerFails = false; + ReturnValue_t serFailRetval = HasReturnvaluesIF::RETURN_FAILED; + bool nextDeserFails = false; + ReturnValue_t deserFailRetval = HasReturnvaluesIF::RETURN_FAILED; std::array valueToStamp{}; CdsShortTimestamperMock() = default; @@ -23,6 +27,9 @@ class CdsShortTimestamperMock : public TimeStamperIF, public TimeReaderIF { Endianness streamEndianness) const override { auto &thisNonConst = const_cast(*this); thisNonConst.serializeCallCount += 1; + if (nextSerFails) { + return serFailRetval; + } if (*size + getSerializedSize() > maxSize) { thisNonConst.lastSerializeResult = SerializeIF::BUFFER_TOO_SHORT; return lastSerializeResult; @@ -41,6 +48,9 @@ class CdsShortTimestamperMock : public TimeStamperIF, public TimeReaderIF { ReturnValue_t deSerialize(const uint8_t **buffer, size_t *size, Endianness streamEndianness) override { deserializeCallCount += 1; + if (nextDeserFails) { + return deserFailRetval; + } if (*size < 7) { lastDeserializeResult = SerializeIF::STREAM_TOO_SHORT; return lastDeserializeResult; @@ -55,7 +65,15 @@ class CdsShortTimestamperMock : public TimeStamperIF, public TimeReaderIF { void reset() { serializeCallCount = 0; getSizeCallCount = 0; + deserializeCallCount = 0; + nextSerFails = false; + nextDeserFails = false; + lastSerializeResult = HasReturnvaluesIF::RETURN_OK; + lastDeserializeResult = HasReturnvaluesIF::RETURN_OK; + deserFailRetval = HasReturnvaluesIF::RETURN_FAILED; + serFailRetval = HasReturnvaluesIF::RETURN_FAILED; } + ReturnValue_t readTimeStamp(const uint8_t *buffer, size_t maxSize) override { return deSerialize(&buffer, &maxSize, SerializeIF::Endianness::NETWORK); } diff --git a/unittests/tmtcpacket/testPusTmReader.cpp b/unittests/tmtcpacket/testPusTmReader.cpp index 8540b97c..7a61b731 100644 --- a/unittests/tmtcpacket/testPusTmReader.cpp +++ b/unittests/tmtcpacket/testPusTmReader.cpp @@ -91,4 +91,18 @@ TEST_CASE("PUS TM Reader", "[pus-tm-reader]") { REQUIRE(roData[1] == 2); REQUIRE(roData[2] == 3); } + + SECTION("Invalid stream lengths") { + REQUIRE(creator.serialize(&dataPtr, &serLen, buf.size()) == HasReturnvaluesIF::RETURN_OK); + for (size_t i = 0; i < serLen - 1; i++) { + REQUIRE(reader.setReadOnlyData(buf.data(), i) == SerializeIF::STREAM_TOO_SHORT); + } + } + + SECTION("Reading timestamp fails") { + timeStamperAndReader.nextDeserFails = true; + REQUIRE(creator.serialize(&dataPtr, &serLen, buf.size()) == HasReturnvaluesIF::RETURN_OK); + REQUIRE(reader.setReadOnlyData(buf.data(), serLen) == HasReturnvaluesIF::RETURN_OK); + REQUIRE(reader.parseDataWithCrcCheck() == HasReturnvaluesIF::RETURN_FAILED); + } } \ No newline at end of file -- 2.43.0 From 133894f4ba06dda17346fddaa4d448fb95a51776 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Fri, 22 Jul 2022 18:46:58 +0200 Subject: [PATCH 033/108] add basic CCSDS tests --- CMakeLists.txt | 2 +- src/fsfw/tmtcpacket/ccsds/PacketId.h | 16 +++++++-- unittests/tmtcpacket/CMakeLists.txt | 1 + unittests/tmtcpacket/testCcsds.cpp | 53 ++++++++++++++++++++++++++++ 4 files changed, 69 insertions(+), 3 deletions(-) create mode 100644 unittests/tmtcpacket/testCcsds.cpp diff --git a/CMakeLists.txt b/CMakeLists.txt index e59eb4c5..acc061fc 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -168,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}) + add_executable(${FSFW_TEST_TGT} unittests/tmtcpacket/testCcsds.cpp) if(IPO_SUPPORTED AND FSFW_ENABLE_IPO) set_property(TARGET ${FSFW_TEST_TGT} PROPERTY INTERPROCEDURAL_OPTIMIZATION TRUE) diff --git a/src/fsfw/tmtcpacket/ccsds/PacketId.h b/src/fsfw/tmtcpacket/ccsds/PacketId.h index 29b82f13..2c77652c 100644 --- a/src/fsfw/tmtcpacket/ccsds/PacketId.h +++ b/src/fsfw/tmtcpacket/ccsds/PacketId.h @@ -42,8 +42,20 @@ struct PacketId : public SerializeIF { ReturnValue_t serialize(uint8_t **buffer, size_t *size, size_t maxSize, Endianness streamEndianness) const override { - uint16_t pscRaw = raw(); - return SerializeAdapter::serialize(&pscRaw, buffer, size, maxSize, streamEndianness); + if (*size + getSerializedSize() > maxSize) { + return SerializeIF::BUFFER_TOO_SHORT; + } + uint16_t idRaw = raw(); + // Leave the first three bits untouched, they could generally contain the CCSDS version, + // or more generally, the packet ID is a 13 bit field + **buffer &= ~0x1f; + **buffer |= (idRaw >> 8) & 0x1f; + *size += 1; + *buffer += 1; + **buffer = idRaw & 0xff; + *size += 1; + *buffer += 1; + return HasReturnvaluesIF::RETURN_OK; } [[nodiscard]] size_t getSerializedSize() const override { return 2; } diff --git a/unittests/tmtcpacket/CMakeLists.txt b/unittests/tmtcpacket/CMakeLists.txt index f47c6370..dd0100a6 100644 --- a/unittests/tmtcpacket/CMakeLists.txt +++ b/unittests/tmtcpacket/CMakeLists.txt @@ -5,4 +5,5 @@ target_sources(${FSFW_TEST_TGT} PRIVATE testPusTcReader.cpp testPusTmCreator.cpp testPusTmReader.cpp + testCcsds.cpp ) diff --git a/unittests/tmtcpacket/testCcsds.cpp b/unittests/tmtcpacket/testCcsds.cpp new file mode 100644 index 00000000..28b255e5 --- /dev/null +++ b/unittests/tmtcpacket/testCcsds.cpp @@ -0,0 +1,53 @@ +#include +#include + +#include "fsfw/tmtcpacket/ccsds/PacketId.h" +#include "fsfw/tmtcpacket/ccsds/header.h" + +TEST_CASE("CCSDS Low Level", "[ccsds-ll]") { + SECTION("Lowlevel Header Packet ID test") { + ccsds::PrimaryHeader header{}; + uint16_t packetIdRaw = 0x3ff; + ccsds::setPacketId(header, packetIdRaw); + REQUIRE(header.packetIdHAndVersion == 3); + REQUIRE(header.packetIdL == 0xff); + REQUIRE(ccsds::getPacketId(header) == 0x3ff); + header.packetIdHAndVersion |= 0b00100000; + REQUIRE(ccsds::getPacketId(header) == 0x3ff); + REQUIRE(ccsds::getVersion(header) == 0b001); + } + + SECTION("Lowlevel Header APID Test") { + ccsds::PrimaryHeader header{}; + uint16_t packetIdRaw = 0x3ff; + ccsds::setPacketId(header, packetIdRaw); + ccsds::setApid(header, 0x1ff); + REQUIRE(ccsds::getPacketId(header) == 0x1ff); + } + + SECTION("Lowlevel Packet Length Test") { + ccsds::PrimaryHeader header{}; + header.packetLenH = 0x02; + header.packetLenL = 0x03; + REQUIRE(ccsds::getPacketLen(header) == 0x0203); + } +} + +TEST_CASE("CCSDS Packet ID", "[ccsds-packet-id]") { + PacketId packetId; + std::array buf{}; + size_t serLen = 0; + uint8_t* ptr = buf.data(); + SECTION("Basic") { + packetId.apid = 0x1ff; + packetId.secHeaderFlag = false; + packetId.packetType = ccsds::PacketType::TM; + REQUIRE(packetId.raw() == 0x1ff); + REQUIRE(packetId.serialize(&ptr, &serLen, buf.size(), SerializeIF::Endianness::NETWORK) == + HasReturnvaluesIF::RETURN_OK); + REQUIRE(buf[0] == 0x1); + REQUIRE(buf[1] == 0xff); + } +} + +TEST_CASE("CCSDS Packet Seq Ctrl", "[ccsds-packet-seq-ctrl]") {} -- 2.43.0 From 99aaf7068d1a53f4e849d6280d3b48aac03ceb6d Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Sat, 23 Jul 2022 10:05:57 +0200 Subject: [PATCH 034/108] some tests --- src/fsfw/serialize/SerializeIF.h | 4 ++-- unittests/tmtcpacket/testCcsds.cpp | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/fsfw/serialize/SerializeIF.h b/src/fsfw/serialize/SerializeIF.h index de5abaeb..ad8d3730 100644 --- a/src/fsfw/serialize/SerializeIF.h +++ b/src/fsfw/serialize/SerializeIF.h @@ -66,7 +66,7 @@ class SerializeIF { * Gets the size of a object if it would be serialized in a buffer * @return Size of serialized object */ - virtual size_t getSerializedSize() const = 0; + [[nodiscard]] virtual size_t getSerializedSize() const = 0; /** * @brief @@ -99,7 +99,7 @@ class SerializeIF { * @param streamEndianness * @return */ - virtual ReturnValue_t serialize(uint8_t* buffer, size_t maxSize, Endianness streamEndianness) { + virtual ReturnValue_t serialize(uint8_t* buffer, size_t maxSize, Endianness streamEndianness) const { size_t tmpSize = 0; return serialize(&buffer, &tmpSize, maxSize, streamEndianness); } diff --git a/unittests/tmtcpacket/testCcsds.cpp b/unittests/tmtcpacket/testCcsds.cpp index 28b255e5..a2679896 100644 --- a/unittests/tmtcpacket/testCcsds.cpp +++ b/unittests/tmtcpacket/testCcsds.cpp @@ -43,7 +43,7 @@ TEST_CASE("CCSDS Packet ID", "[ccsds-packet-id]") { packetId.secHeaderFlag = false; packetId.packetType = ccsds::PacketType::TM; REQUIRE(packetId.raw() == 0x1ff); - REQUIRE(packetId.serialize(&ptr, &serLen, buf.size(), SerializeIF::Endianness::NETWORK) == + REQUIRE(packetId.serialize(buf.data(), buf.size(), SerializeIF::Endianness::NETWORK) == HasReturnvaluesIF::RETURN_OK); REQUIRE(buf[0] == 0x1); REQUIRE(buf[1] == 0xff); -- 2.43.0 From 55a238d5533e1ee7c3477d570cd4ac82683afea0 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Sat, 23 Jul 2022 10:24:56 +0200 Subject: [PATCH 035/108] extended serialize if further --- src/fsfw/serialize/SerializeIF.h | 26 +++++++++++++++++++ .../tmtcpacket/ccsds/SpacePacketCreator.cpp | 4 +-- .../tmtcpacket/ccsds/SpacePacketCreator.h | 4 ++- src/fsfw/tmtcpacket/pus/tm/PusTmCreator.cpp | 2 +- unittests/tmtcpacket/testCcsds.cpp | 11 +++++--- unittests/tmtcpacket/testCcsdsCreator.cpp | 14 +++++----- 6 files changed, 46 insertions(+), 15 deletions(-) diff --git a/src/fsfw/serialize/SerializeIF.h b/src/fsfw/serialize/SerializeIF.h index 3f4fdc38..82becb26 100644 --- a/src/fsfw/serialize/SerializeIF.h +++ b/src/fsfw/serialize/SerializeIF.h @@ -62,6 +62,20 @@ class SerializeIF { virtual ReturnValue_t serialize(uint8_t **buffer, size_t *size, size_t maxSize, Endianness streamEndianness) const = 0; + /** + * Forwards to regular @serialize call with network endianness + */ + virtual ReturnValue_t serializeNe(uint8_t** buffer, size_t* size, size_t maxSize) { + return serialize(buffer, size, maxSize, SerializeIF::Endianness::NETWORK); + } + + /** + * If endianness is not explicitly specified, use machine endianness + */ + virtual ReturnValue_t serialize(uint8_t **buffer, size_t *size, size_t maxSize) { + return serialize(buffer, size, maxSize, SerializeIF::Endianness::MACHINE); + } + /** * Gets the size of a object if it would be serialized in a buffer * @return Size of serialized object @@ -90,6 +104,18 @@ class SerializeIF { */ virtual ReturnValue_t deSerialize(const uint8_t **buffer, size_t *size, Endianness streamEndianness) = 0; + /** + * Forwards to regular @deSerialize call with network endianness + */ + virtual ReturnValue_t deSerializeNe(const uint8_t** buffer, size_t* size, size_t maxSize) { + return deSerialize(buffer, size, SerializeIF::Endianness::NETWORK); + } + /** + * If endianness is not explicitly specified, use machine endianness + */ + virtual ReturnValue_t deSerialize(const uint8_t** buffer, size_t *size, size_t maxSize) { + return deSerialize(buffer, size, SerializeIF::Endianness::MACHINE); + } /** * Helper method which can be used if serialization should be performed without any additional diff --git a/src/fsfw/tmtcpacket/ccsds/SpacePacketCreator.cpp b/src/fsfw/tmtcpacket/ccsds/SpacePacketCreator.cpp index 7ae8656f..05da88b4 100644 --- a/src/fsfw/tmtcpacket/ccsds/SpacePacketCreator.cpp +++ b/src/fsfw/tmtcpacket/ccsds/SpacePacketCreator.cpp @@ -48,9 +48,6 @@ ReturnValue_t SpacePacketCreator::deSerialize(const uint8_t **buffer, size_t *si } bool SpacePacketCreator::isValid() const { return valid; } -ReturnValue_t SpacePacketCreator::serialize(uint8_t **buffer, size_t *size, size_t maxSize) const { - return serialize(buffer, size, maxSize, SerializeIF::Endianness::NETWORK); -} void SpacePacketCreator::setApid(uint16_t apid) { if (apid < ccsds::LIMIT_APID) { params.packetId.apid = apid; @@ -83,3 +80,4 @@ SpacePacketParams &SpacePacketCreator::getParams() { return params; } void SpacePacketCreator::setPacketType(ccsds::PacketType type) { params.packetId.packetType = type; } +bool SpacePacketCreator::operator==(const SpacePacketCreator &other) const { return false; } diff --git a/src/fsfw/tmtcpacket/ccsds/SpacePacketCreator.h b/src/fsfw/tmtcpacket/ccsds/SpacePacketCreator.h index de62283f..d30457ea 100644 --- a/src/fsfw/tmtcpacket/ccsds/SpacePacketCreator.h +++ b/src/fsfw/tmtcpacket/ccsds/SpacePacketCreator.h @@ -24,6 +24,9 @@ class SpacePacketCreator : public SpacePacketIF, public SerializeIF { public: SpacePacketCreator() = default; explicit SpacePacketCreator(SpacePacketParams params); + + bool operator==(const SpacePacketCreator &other) const; + SpacePacketCreator(ccsds::PacketType packetType, bool secHeaderFlag, uint16_t apid, ccsds::SequenceFlags seqFlags, uint16_t seqCount, uint16_t dataLen, uint8_t version = 0); @@ -41,7 +44,6 @@ class SpacePacketCreator : public SpacePacketIF, public SerializeIF { void setSeqFlags(ccsds::SequenceFlags flags); void setDataLen(uint16_t dataLen); - ReturnValue_t serialize(uint8_t **buffer, size_t *size, size_t maxSize) const; ReturnValue_t serialize(uint8_t **buffer, size_t *size, size_t maxSize, Endianness streamEndianness) const override; diff --git a/src/fsfw/tmtcpacket/pus/tm/PusTmCreator.cpp b/src/fsfw/tmtcpacket/pus/tm/PusTmCreator.cpp index b8ef0852..03cf2fbf 100644 --- a/src/fsfw/tmtcpacket/pus/tm/PusTmCreator.cpp +++ b/src/fsfw/tmtcpacket/pus/tm/PusTmCreator.cpp @@ -43,7 +43,7 @@ ReturnValue_t PusTmCreator::serialize(uint8_t** buffer, size_t* size, size_t max if (*size + getSerializedSize() > maxSize) { return SerializeIF::BUFFER_TOO_SHORT; } - ReturnValue_t result = spCreator.serialize(buffer, size, maxSize); + ReturnValue_t result = spCreator.serialize(buffer, size, maxSize, streamEndianness); if (result != HasReturnvaluesIF::RETURN_OK) { return result; } diff --git a/unittests/tmtcpacket/testCcsds.cpp b/unittests/tmtcpacket/testCcsds.cpp index a2679896..7f337b6d 100644 --- a/unittests/tmtcpacket/testCcsds.cpp +++ b/unittests/tmtcpacket/testCcsds.cpp @@ -36,18 +36,23 @@ TEST_CASE("CCSDS Low Level", "[ccsds-ll]") { TEST_CASE("CCSDS Packet ID", "[ccsds-packet-id]") { PacketId packetId; std::array buf{}; - size_t serLen = 0; - uint8_t* ptr = buf.data(); SECTION("Basic") { packetId.apid = 0x1ff; packetId.secHeaderFlag = false; packetId.packetType = ccsds::PacketType::TM; REQUIRE(packetId.raw() == 0x1ff); - REQUIRE(packetId.serialize(buf.data(), buf.size(), SerializeIF::Endianness::NETWORK) == + REQUIRE(packetId.SerializeIF::serialize(buf.data(), buf.size(), SerializeIF::Endianness::NETWORK) == HasReturnvaluesIF::RETURN_OK); REQUIRE(buf[0] == 0x1); REQUIRE(buf[1] == 0xff); } + + SECTION("From Raw") { + auto newId = PacketId(ccsds::PacketType::TC, true, 0x2ff); + uint16_t rawId = newId.raw(); + REQUIRE(rawId == 0x1aff); + REQUIRE(PacketId::fromRaw(rawId) == newId); + } } TEST_CASE("CCSDS Packet Seq Ctrl", "[ccsds-packet-seq-ctrl]") {} diff --git a/unittests/tmtcpacket/testCcsdsCreator.cpp b/unittests/tmtcpacket/testCcsdsCreator.cpp index 2043d6a6..91122ef9 100644 --- a/unittests/tmtcpacket/testCcsdsCreator.cpp +++ b/unittests/tmtcpacket/testCcsdsCreator.cpp @@ -40,7 +40,7 @@ TEST_CASE("CCSDS Creator", "[ccsds-creator]") { } SECTION("Raw Output") { - REQUIRE(base.serialize(&bufPtr, &serLen, buf.size()) == HasReturnvaluesIF::RETURN_OK); + REQUIRE(base.serializeNe(&bufPtr, &serLen, buf.size()) == HasReturnvaluesIF::RETURN_OK); // TC, and secondary header flag is set -> 0b0001100 -> 0x18 REQUIRE(buf[0] == 0x18); // APID 0x02 @@ -62,7 +62,7 @@ TEST_CASE("CCSDS Creator", "[ccsds-creator]") { base.setSeqFlags(ccsds::SequenceFlags::UNSEGMENTED); base.setDataLen(static_cast(std::pow(2, 16)) - 1); REQUIRE(base.isValid()); - REQUIRE(base.serialize(&bufPtr, &serLen, buf.size()) == HasReturnvaluesIF::RETURN_OK); + REQUIRE(base.serializeNe(&bufPtr, &serLen, buf.size()) == HasReturnvaluesIF::RETURN_OK); REQUIRE(buf[0] == 0x1F); REQUIRE(buf[1] == 0xFF); REQUIRE(buf[2] == 0xFF); @@ -75,28 +75,28 @@ TEST_CASE("CCSDS Creator", "[ccsds-creator]") { SpacePacketCreator invalid = SpacePacketCreator( ccsds::PacketType::TC, true, 0xFFFF, ccsds::SequenceFlags::FIRST_SEGMENT, 0x34, 0x16); REQUIRE(not invalid.isValid()); - REQUIRE(invalid.serialize(&bufPtr, &serLen, buf.size()) == HasReturnvaluesIF::RETURN_FAILED); + REQUIRE(invalid.serializeNe(&bufPtr, &serLen, buf.size()) == HasReturnvaluesIF::RETURN_FAILED); } SECTION("Invalid Seq Count") { SpacePacketCreator invalid = SpacePacketCreator( ccsds::PacketType::TC, true, 0x02, ccsds::SequenceFlags::FIRST_SEGMENT, 0xFFFF, 0x16); REQUIRE(not invalid.isValid()); - REQUIRE(invalid.serialize(&bufPtr, &serLen, buf.size()) == HasReturnvaluesIF::RETURN_FAILED); + REQUIRE(invalid.serializeNe(&bufPtr, &serLen, buf.size()) == HasReturnvaluesIF::RETURN_FAILED); } SECTION("Invalid Buf Size 1") { serLen = 2; - REQUIRE(base.serialize(&bufPtr, &serLen, buf.size()) == SerializeIF::BUFFER_TOO_SHORT); + REQUIRE(base.serializeNe(&bufPtr, &serLen, buf.size()) == SerializeIF::BUFFER_TOO_SHORT); } SECTION("Invalid Buf Size 2") { serLen = 4; - REQUIRE(base.serialize(&bufPtr, &serLen, buf.size()) == SerializeIF::BUFFER_TOO_SHORT); + REQUIRE(base.serializeNe(&bufPtr, &serLen, buf.size()) == SerializeIF::BUFFER_TOO_SHORT); } SECTION("Invalid Buf Size 3") { serLen = 6; - REQUIRE(base.serialize(&bufPtr, &serLen, buf.size()) == SerializeIF::BUFFER_TOO_SHORT); + REQUIRE(base.serializeNe(&bufPtr, &serLen, buf.size()) == SerializeIF::BUFFER_TOO_SHORT); } } -- 2.43.0 From b66fd63cb432162ea495ecb9f5717fc3daec758f Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Sat, 23 Jul 2022 10:29:19 +0200 Subject: [PATCH 036/108] remove doubly defines --- src/fsfw/serialize/SerializeIF.h | 14 -------------- unittests/tmtcpacket/testCcsds.cpp | 2 +- 2 files changed, 1 insertion(+), 15 deletions(-) diff --git a/src/fsfw/serialize/SerializeIF.h b/src/fsfw/serialize/SerializeIF.h index 0c0e4c42..9fc5b731 100644 --- a/src/fsfw/serialize/SerializeIF.h +++ b/src/fsfw/serialize/SerializeIF.h @@ -74,20 +74,6 @@ class SerializeIF { return serialize(buffer, size, maxSize, SerializeIF::Endianness::MACHINE); } - /** - * Forwards to regular @serialize call with network endianness - */ - virtual ReturnValue_t serializeNe(uint8_t** buffer, size_t* size, size_t maxSize) { - return serialize(buffer, size, maxSize, SerializeIF::Endianness::NETWORK); - } - - /** - * If endianness is not explicitly specified, use machine endianness - */ - virtual ReturnValue_t serialize(uint8_t **buffer, size_t *size, size_t maxSize) { - return serialize(buffer, size, maxSize, SerializeIF::Endianness::MACHINE); - } - /** * Gets the size of a object if it would be serialized in a buffer * @return Size of serialized object diff --git a/unittests/tmtcpacket/testCcsds.cpp b/unittests/tmtcpacket/testCcsds.cpp index 7f337b6d..1bae5912 100644 --- a/unittests/tmtcpacket/testCcsds.cpp +++ b/unittests/tmtcpacket/testCcsds.cpp @@ -41,7 +41,7 @@ TEST_CASE("CCSDS Packet ID", "[ccsds-packet-id]") { packetId.secHeaderFlag = false; packetId.packetType = ccsds::PacketType::TM; REQUIRE(packetId.raw() == 0x1ff); - REQUIRE(packetId.SerializeIF::serialize(buf.data(), buf.size(), SerializeIF::Endianness::NETWORK) == + REQUIRE(packetId.SerializeIF::serializeNe(buf.data(), buf.size()) == HasReturnvaluesIF::RETURN_OK); REQUIRE(buf[0] == 0x1); REQUIRE(buf[1] == 0xff); -- 2.43.0 From d474c4a7ee1d62d640ecca1a6cedd6f7df397b73 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Sat, 23 Jul 2022 11:43:48 +0200 Subject: [PATCH 037/108] store helper --- src/fsfw/serialize/SerializeIF.h | 6 +- src/fsfw/tmtcpacket/ccsds/PacketSeqCtrl.h | 4 ++ .../tmtcpacket/ccsds/SpacePacketCreator.cpp | 2 + .../tmtcpacket/ccsds/SpacePacketCreator.h | 1 + src/fsfw/tmtcservices/TmStoreHelper.cpp | 19 +++-- unittests/CMakeLists.txt | 1 + unittests/mocks/SimpleSerializable.h | 2 +- unittests/serialize/testSerializeIF.cpp | 44 ++++++++---- unittests/tmtcpacket/testCcsds.cpp | 69 +++++++++++++++++-- unittests/tmtcpacket/testCcsdsCreator.cpp | 57 ++++++++------- unittests/tmtcservices/CMakeLists.txt | 2 + unittests/tmtcservices/testStoreHelper.cpp | 3 + 12 files changed, 150 insertions(+), 60 deletions(-) create mode 100644 unittests/tmtcservices/CMakeLists.txt create mode 100644 unittests/tmtcservices/testStoreHelper.cpp diff --git a/src/fsfw/serialize/SerializeIF.h b/src/fsfw/serialize/SerializeIF.h index 54a1f4e3..2b466839 100644 --- a/src/fsfw/serialize/SerializeIF.h +++ b/src/fsfw/serialize/SerializeIF.h @@ -64,7 +64,7 @@ class SerializeIF { /** * Forwards to regular @serialize call with network endianness */ - virtual ReturnValue_t serializeNe(uint8_t** buffer, size_t* size, size_t maxSize) { + virtual ReturnValue_t serializeNe(uint8_t **buffer, size_t *size, size_t maxSize) { return serialize(buffer, size, maxSize, SerializeIF::Endianness::NETWORK); } /** @@ -105,13 +105,13 @@ class SerializeIF { /** * Forwards to regular @deSerialize call with network endianness */ - virtual ReturnValue_t deSerializeNe(const uint8_t** buffer, size_t* size) { + virtual ReturnValue_t deSerializeNe(const uint8_t **buffer, size_t *size) { return deSerialize(buffer, size, SerializeIF::Endianness::NETWORK); } /** * If endianness is not explicitly specified, use machine endianness */ - virtual ReturnValue_t deSerialize(const uint8_t** buffer, size_t *size) { + virtual ReturnValue_t deSerialize(const uint8_t **buffer, size_t *size) { return deSerialize(buffer, size, SerializeIF::Endianness::MACHINE); } diff --git a/src/fsfw/tmtcpacket/ccsds/PacketSeqCtrl.h b/src/fsfw/tmtcpacket/ccsds/PacketSeqCtrl.h index 830a6fa2..cd4e153e 100644 --- a/src/fsfw/tmtcpacket/ccsds/PacketSeqCtrl.h +++ b/src/fsfw/tmtcpacket/ccsds/PacketSeqCtrl.h @@ -12,6 +12,10 @@ struct PacketSeqCtrl : public SerializeIF { PacketSeqCtrl(ccsds::SequenceFlags seqFlags, uint16_t seqCount) : seqFlags(seqFlags), seqCount(seqCount) {} + bool operator==(const PacketSeqCtrl &other) const { + return seqCount == other.seqCount and seqFlags == other.seqFlags; + } + /** * NOTE: If the sequence control has an invalid value, the invalid bits will be cut off * @return diff --git a/src/fsfw/tmtcpacket/ccsds/SpacePacketCreator.cpp b/src/fsfw/tmtcpacket/ccsds/SpacePacketCreator.cpp index 05da88b4..20c9341f 100644 --- a/src/fsfw/tmtcpacket/ccsds/SpacePacketCreator.cpp +++ b/src/fsfw/tmtcpacket/ccsds/SpacePacketCreator.cpp @@ -81,3 +81,5 @@ void SpacePacketCreator::setPacketType(ccsds::PacketType type) { params.packetId.packetType = type; } bool SpacePacketCreator::operator==(const SpacePacketCreator &other) const { return false; } + +SpacePacketCreator::operator bool() const { return isValid(); } diff --git a/src/fsfw/tmtcpacket/ccsds/SpacePacketCreator.h b/src/fsfw/tmtcpacket/ccsds/SpacePacketCreator.h index d30457ea..9c13bd5a 100644 --- a/src/fsfw/tmtcpacket/ccsds/SpacePacketCreator.h +++ b/src/fsfw/tmtcpacket/ccsds/SpacePacketCreator.h @@ -26,6 +26,7 @@ class SpacePacketCreator : public SpacePacketIF, public SerializeIF { explicit SpacePacketCreator(SpacePacketParams params); bool operator==(const SpacePacketCreator &other) const; + explicit operator bool() const; SpacePacketCreator(ccsds::PacketType packetType, bool secHeaderFlag, uint16_t apid, ccsds::SequenceFlags seqFlags, uint16_t seqCount, uint16_t dataLen, diff --git a/src/fsfw/tmtcservices/TmStoreHelper.cpp b/src/fsfw/tmtcservices/TmStoreHelper.cpp index 44b2e6a1..3260d4d1 100644 --- a/src/fsfw/tmtcservices/TmStoreHelper.cpp +++ b/src/fsfw/tmtcservices/TmStoreHelper.cpp @@ -14,13 +14,10 @@ TmStoreHelper::TmStoreHelper(uint16_t defaultApid, StorageManagerIF* tmStore) : } ReturnValue_t TmStoreHelper::preparePacket(uint8_t service, uint8_t subservice, uint16_t counter) { - // TODO: Implement - // creator.setApid(apid); PusTmParams& params = creator.getParams(); params.secHeader.service = service; params.secHeader.subservice = subservice; params.secHeader.messageTypeCounter = counter; - // TODO: Implement serialize and then serialize into the store return HasReturnvaluesIF::RETURN_OK; } @@ -31,22 +28,21 @@ const store_address_t& TmStoreHelper::getCurrentAddr() const { return currentAdd ReturnValue_t TmStoreHelper::deletePacket() { return tmStore->deleteData(currentAddr); } void TmStoreHelper::setSourceDataRaw(const uint8_t* data, size_t len) { - PusTmParams& params = creator.getParams(); - params.dataWrapper.type = ecss::DataTypes::RAW; - params.dataWrapper.dataUnion.raw.data = data; - params.dataWrapper.dataUnion.raw.len = len; + creator.setRawUserData(data, len); } void TmStoreHelper::setSourceDataSerializable(SerializeIF* serializable) { - PusTmParams& params = creator.getParams(); - params.dataWrapper.type = ecss::DataTypes::SERIALIZABLE; - params.dataWrapper.dataUnion.serializable = serializable; + creator.setSerializableUserData(serializable); } ReturnValue_t TmStoreHelper::addPacketToStore() { creator.updateSpLengthField(); uint8_t* dataPtr; - tmStore->getFreeElement(¤tAddr, creator.getSerializedSize(), &dataPtr); + ReturnValue_t result = + tmStore->getFreeElement(¤tAddr, creator.getSerializedSize(), &dataPtr); + if (result != HasReturnvaluesIF::RETURN_OK) { + return result; + } size_t serLen = 0; return creator.serialize(&dataPtr, &serLen, creator.getSerializedSize(), SerializeIF::Endianness::NETWORK); @@ -55,4 +51,5 @@ ReturnValue_t TmStoreHelper::addPacketToStore() { void TmStoreHelper::setTimeStamper(TimeStamperIF* timeStamper_) { creator.setTimeStamper(timeStamper_); } + void TmStoreHelper::setApid(uint16_t apid) { creator.setApid(apid); } diff --git a/unittests/CMakeLists.txt b/unittests/CMakeLists.txt index f32c6e08..28d950d4 100644 --- a/unittests/CMakeLists.txt +++ b/unittests/CMakeLists.txt @@ -27,5 +27,6 @@ add_subdirectory(cfdp) add_subdirectory(hal) add_subdirectory(internalerror) add_subdirectory(devicehandler) +add_subdirectory(tmtcservices) target_include_directories(${FSFW_TEST_TGT} PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}) diff --git a/unittests/mocks/SimpleSerializable.h b/unittests/mocks/SimpleSerializable.h index 5c28a09a..222f1729 100644 --- a/unittests/mocks/SimpleSerializable.h +++ b/unittests/mocks/SimpleSerializable.h @@ -1,8 +1,8 @@ #ifndef FSFW_TESTS_SIMPLESERIALIZABLE_H #define FSFW_TESTS_SIMPLESERIALIZABLE_H -#include "fsfw/serialize.h" #include "fsfw/osal/Endiness.h" +#include "fsfw/serialize.h" class SimpleSerializable : public SerializeIF { public: diff --git a/unittests/serialize/testSerializeIF.cpp b/unittests/serialize/testSerializeIF.cpp index 2cbe6132..968d2b1e 100644 --- a/unittests/serialize/testSerializeIF.cpp +++ b/unittests/serialize/testSerializeIF.cpp @@ -13,7 +13,8 @@ TEST_CASE("Serialize IF Serialize", "[serialize-if-ser]") { size_t len = 0; SECTION("Little Endian Normal") { - REQUIRE(simpleSer.serialize(&ptr, &len, buf.size(), SerializeIF::Endianness::LITTLE) == HasReturnvaluesIF::RETURN_OK); + REQUIRE(simpleSer.serialize(&ptr, &len, buf.size(), SerializeIF::Endianness::LITTLE) == + HasReturnvaluesIF::RETURN_OK); CHECK(buf[0] == 1); CHECK(buf[1] == 3); CHECK(buf[2] == 2); @@ -23,7 +24,9 @@ TEST_CASE("Serialize IF Serialize", "[serialize-if-ser]") { } SECTION("Little Endian Simple") { - REQUIRE(simpleSer.SerializeIF::serialize(buf.data(), buf.size(), SerializeIF::Endianness::LITTLE) == HasReturnvaluesIF::RETURN_OK); + REQUIRE( + simpleSer.SerializeIF::serialize(buf.data(), buf.size(), SerializeIF::Endianness::LITTLE) == + HasReturnvaluesIF::RETURN_OK); CHECK(buf[0] == 1); CHECK(buf[1] == 3); CHECK(buf[2] == 2); @@ -35,7 +38,8 @@ TEST_CASE("Serialize IF Serialize", "[serialize-if-ser]") { HasReturnvaluesIF::RETURN_OK); } SECTION("Network 0") { - REQUIRE(simpleSer.serialize(&ptr, &len, buf.size(), SerializeIF::Endianness::NETWORK) == HasReturnvaluesIF::RETURN_OK); + REQUIRE(simpleSer.serialize(&ptr, &len, buf.size(), SerializeIF::Endianness::NETWORK) == + HasReturnvaluesIF::RETURN_OK); } SECTION("Network 1") { REQUIRE(simpleSer.serializeNe(&ptr, &len, buf.size()) == HasReturnvaluesIF::RETURN_OK); @@ -51,14 +55,18 @@ TEST_CASE("Serialize IF Serialize", "[serialize-if-ser]") { SECTION("Big Endian Simple") { SECTION("Explicit") { - REQUIRE(simpleSer.SerializeIF::serialize(buf.data(), buf.size(), SerializeIF::Endianness::BIG) == - HasReturnvaluesIF::RETURN_OK); + REQUIRE( + simpleSer.SerializeIF::serialize(buf.data(), buf.size(), SerializeIF::Endianness::BIG) == + HasReturnvaluesIF::RETURN_OK); } SECTION("Network 0") { - REQUIRE(simpleSer.SerializeIF::serialize(buf.data(), buf.size(), SerializeIF::Endianness::NETWORK) == HasReturnvaluesIF::RETURN_OK); + REQUIRE(simpleSer.SerializeIF::serialize(buf.data(), buf.size(), + SerializeIF::Endianness::NETWORK) == + HasReturnvaluesIF::RETURN_OK); } SECTION("Network 1") { - REQUIRE(simpleSer.SerializeIF::serializeNe(buf.data(), buf.size()) == HasReturnvaluesIF::RETURN_OK); + REQUIRE(simpleSer.SerializeIF::serializeNe(buf.data(), buf.size()) == + HasReturnvaluesIF::RETURN_OK); } CHECK(buf[0] == 1); CHECK(buf[1] == 2); @@ -102,7 +110,8 @@ TEST_CASE("SerializeIF Deserialize", "[serialize-if-de]") { size_t len = buf.size(); SECTION("Little Endian Normal") { - REQUIRE(simpleSer.deSerialize(&ptr, &len, SerializeIF::Endianness::LITTLE) == HasReturnvaluesIF::RETURN_OK); + REQUIRE(simpleSer.deSerialize(&ptr, &len, SerializeIF::Endianness::LITTLE) == + HasReturnvaluesIF::RETURN_OK); CHECK(simpleSer.getU8() == 5); CHECK(simpleSer.getU16() == 0x0100); CHECK(ptr == buf.data() + 3); @@ -110,17 +119,20 @@ TEST_CASE("SerializeIF Deserialize", "[serialize-if-de]") { } SECTION("Little Endian Simple") { - REQUIRE(simpleSer.SerializeIF::deSerialize(ptr, len, SerializeIF::Endianness::LITTLE) == HasReturnvaluesIF::RETURN_OK); + REQUIRE(simpleSer.SerializeIF::deSerialize(ptr, len, SerializeIF::Endianness::LITTLE) == + HasReturnvaluesIF::RETURN_OK); CHECK(simpleSer.getU8() == 5); CHECK(simpleSer.getU16() == 0x0100); } SECTION("Big Endian Normal") { SECTION("Explicit") { - REQUIRE(simpleSer.deSerialize(&ptr, &len, SerializeIF::Endianness::BIG) == HasReturnvaluesIF::RETURN_OK); + REQUIRE(simpleSer.deSerialize(&ptr, &len, SerializeIF::Endianness::BIG) == + HasReturnvaluesIF::RETURN_OK); } SECTION("Network 0") { - REQUIRE(simpleSer.deSerialize(&ptr, &len, SerializeIF::Endianness::NETWORK) == HasReturnvaluesIF::RETURN_OK); + REQUIRE(simpleSer.deSerialize(&ptr, &len, SerializeIF::Endianness::NETWORK) == + HasReturnvaluesIF::RETURN_OK); } SECTION("Network 1") { REQUIRE(simpleSer.SerializeIF::deSerializeNe(&ptr, &len) == HasReturnvaluesIF::RETURN_OK); @@ -133,14 +145,18 @@ TEST_CASE("SerializeIF Deserialize", "[serialize-if-de]") { SECTION("Big Endian Simple") { SECTION("Explicit") { - REQUIRE(simpleSer.SerializeIF::deSerialize(buf.data(), buf.size(), SerializeIF::Endianness::BIG) == + REQUIRE(simpleSer.SerializeIF::deSerialize(buf.data(), buf.size(), + SerializeIF::Endianness::BIG) == HasReturnvaluesIF::RETURN_OK); } SECTION("Network 0") { - REQUIRE(simpleSer.SerializeIF::deSerialize(buf.data(), buf.size(), SerializeIF::Endianness::NETWORK) == HasReturnvaluesIF::RETURN_OK); + REQUIRE(simpleSer.SerializeIF::deSerialize(buf.data(), buf.size(), + SerializeIF::Endianness::NETWORK) == + HasReturnvaluesIF::RETURN_OK); } SECTION("Network 1") { - REQUIRE(simpleSer.SerializeIF::deSerializeNe(buf.data(), buf.size()) == HasReturnvaluesIF::RETURN_OK); + REQUIRE(simpleSer.SerializeIF::deSerializeNe(buf.data(), buf.size()) == + HasReturnvaluesIF::RETURN_OK); } CHECK(simpleSer.getU8() == 5); CHECK(simpleSer.getU16() == 1); diff --git a/unittests/tmtcpacket/testCcsds.cpp b/unittests/tmtcpacket/testCcsds.cpp index 1bae5912..16883458 100644 --- a/unittests/tmtcpacket/testCcsds.cpp +++ b/unittests/tmtcpacket/testCcsds.cpp @@ -1,7 +1,9 @@ #include #include +#include #include "fsfw/tmtcpacket/ccsds/PacketId.h" +#include "fsfw/tmtcpacket/ccsds/PacketSeqCtrl.h" #include "fsfw/tmtcpacket/ccsds/header.h" TEST_CASE("CCSDS Low Level", "[ccsds-ll]") { @@ -43,16 +45,73 @@ TEST_CASE("CCSDS Packet ID", "[ccsds-packet-id]") { REQUIRE(packetId.raw() == 0x1ff); REQUIRE(packetId.SerializeIF::serializeNe(buf.data(), buf.size()) == HasReturnvaluesIF::RETURN_OK); - REQUIRE(buf[0] == 0x1); - REQUIRE(buf[1] == 0xff); + CHECK(buf[0] == 0x1); + CHECK(buf[1] == 0xff); + } + + SECTION("Invalid Ser") { + REQUIRE(packetId.SerializeIF::serializeNe(buf.data(), 0) == SerializeIF::BUFFER_TOO_SHORT); + REQUIRE(packetId.SerializeIF::serializeNe(buf.data(), 1) == SerializeIF::BUFFER_TOO_SHORT); + } + + SECTION("Invalid Deser") { + REQUIRE(packetId.SerializeIF::deSerialize(buf.data(), 1) == SerializeIF::STREAM_TOO_SHORT); + REQUIRE(packetId.SerializeIF::deSerialize(buf.data(), 0) == SerializeIF::STREAM_TOO_SHORT); } SECTION("From Raw") { auto newId = PacketId(ccsds::PacketType::TC, true, 0x2ff); uint16_t rawId = newId.raw(); - REQUIRE(rawId == 0x1aff); - REQUIRE(PacketId::fromRaw(rawId) == newId); + CHECK(rawId == 0x1aff); + CHECK(PacketId::fromRaw(rawId) == newId); + } + + SECTION("Deserialize") { + buf[0] = 0x1a; + buf[1] = 0xff; + REQUIRE(packetId.SerializeIF::deSerialize(buf.data(), buf.size()) == + HasReturnvaluesIF::RETURN_OK); + CHECK(packetId.apid == 0x2ff); + CHECK(packetId.packetType == ccsds::PacketType::TC); + CHECK(packetId.secHeaderFlag == true); } } -TEST_CASE("CCSDS Packet Seq Ctrl", "[ccsds-packet-seq-ctrl]") {} +TEST_CASE("CCSDS Packet Seq Ctrl", "[ccsds-packet-seq-ctrl]") { + PacketSeqCtrl psc; + std::array buf{}; + SECTION("Basic") { + psc.seqFlags = ccsds::SequenceFlags::FIRST_SEGMENT; + psc.seqCount = static_cast(std::round(std::pow(2, 14) - 1)); + REQUIRE(psc.raw() == 0x7fff); + REQUIRE(psc.SerializeIF::serializeNe(buf.data(), buf.size()) == HasReturnvaluesIF::RETURN_OK); + CHECK(buf[0] == 0x7f); + CHECK(buf[1] == 0xff); + } + + SECTION("From Raw") { + auto newId = PacketSeqCtrl(ccsds::SequenceFlags::LAST_SEGMENT, + static_cast(std::round(std::pow(2, 14) - 2))); + uint16_t rawId = newId.raw(); + REQUIRE(rawId == 0xbffe); + CHECK(PacketSeqCtrl::fromRaw(rawId) == newId); + } + + SECTION("Deserialize") { + buf[0] = 0xbf; + buf[1] = 0xfe; + REQUIRE(psc.SerializeIF::deSerialize(buf.data(), buf.size()) == HasReturnvaluesIF::RETURN_OK); + CHECK(psc.seqFlags == ccsds::SequenceFlags::LAST_SEGMENT); + CHECK(psc.seqCount == static_cast(std::round(std::pow(2, 14) - 2))); + } + + SECTION("Invalid Ser") { + REQUIRE(psc.SerializeIF::serializeNe(buf.data(), 0) == SerializeIF::BUFFER_TOO_SHORT); + REQUIRE(psc.SerializeIF::serializeNe(buf.data(), 1) == SerializeIF::BUFFER_TOO_SHORT); + } + + SECTION("Invalid Deser") { + REQUIRE(psc.SerializeIF::deSerialize(buf.data(), 1) == SerializeIF::STREAM_TOO_SHORT); + REQUIRE(psc.SerializeIF::deSerialize(buf.data(), 0) == SerializeIF::STREAM_TOO_SHORT); + } +} diff --git a/unittests/tmtcpacket/testCcsdsCreator.cpp b/unittests/tmtcpacket/testCcsdsCreator.cpp index 91122ef9..570e791b 100644 --- a/unittests/tmtcpacket/testCcsdsCreator.cpp +++ b/unittests/tmtcpacket/testCcsdsCreator.cpp @@ -5,8 +5,9 @@ #include "fsfw/tmtcpacket/ccsds/SpacePacketCreator.h" TEST_CASE("CCSDS Creator", "[ccsds-creator]") { - auto params = SpacePacketParams(PacketId(ccsds::PacketType::TC, true, 0x02), - PacketSeqCtrl(ccsds::SequenceFlags::FIRST_SEGMENT, 0x34), 0x16); + auto packetId = PacketId(ccsds::PacketType::TC, true, 0x02); + auto psc = PacketSeqCtrl(ccsds::SequenceFlags::FIRST_SEGMENT, 0x34); + auto params = SpacePacketParams(packetId, psc, 0x16); SpacePacketCreator base = SpacePacketCreator(params); std::array buf{}; uint8_t* bufPtr = buf.data(); @@ -21,15 +22,18 @@ TEST_CASE("CCSDS Creator", "[ccsds-creator]") { } SECTION("Basic Test") { - REQUIRE(base.isValid()); - REQUIRE(base.getApid() == 0x02); - REQUIRE(base.getSequenceFlags() == ccsds::SequenceFlags::FIRST_SEGMENT); - REQUIRE(base.getVersion() == 0b000); - REQUIRE(base.getSequenceCount() == 0x34); - REQUIRE(base.getPacketDataLen() == 0x16); - REQUIRE(base.getPacketType() == ccsds::PacketType::TC); - REQUIRE(base.getPacketIdRaw() == 0x1802); - REQUIRE(base.getSerializedSize() == 6); + CHECK(base.isValid()); + CHECK(base); + CHECK(base.getApid() == 0x02); + CHECK(base.getSequenceFlags() == ccsds::SequenceFlags::FIRST_SEGMENT); + CHECK(base.getVersion() == 0b000); + CHECK(base.getSequenceCount() == 0x34); + CHECK(base.getPacketDataLen() == 0x16); + CHECK(base.getPacketType() == ccsds::PacketType::TC); + CHECK(base.getPacketIdRaw() == 0x1802); + CHECK(base.getSerializedSize() == 6); + CHECK(base.getPacketSeqCtrl() == psc); + CHECK(base.getPacketId() == packetId); } SECTION("Deserialization Fails") { @@ -42,18 +46,18 @@ TEST_CASE("CCSDS Creator", "[ccsds-creator]") { SECTION("Raw Output") { REQUIRE(base.serializeNe(&bufPtr, &serLen, buf.size()) == HasReturnvaluesIF::RETURN_OK); // TC, and secondary header flag is set -> 0b0001100 -> 0x18 - REQUIRE(buf[0] == 0x18); + CHECK(buf[0] == 0x18); // APID 0x02 - REQUIRE(buf[1] == 0x02); + CHECK(buf[1] == 0x02); // Sequence count is one byte value, so the only set bit here is the bit // from the Sequence flag argument, which is the second bit for // SequenceFlags.FIRST_SEGMENT - REQUIRE(buf[2] == 0x40); + CHECK(buf[2] == 0x40); // Sequence Count specified above - REQUIRE(buf[3] == 0x34); + CHECK(buf[3] == 0x34); // This byte and the next byte should be 22 big endian (packet length) - REQUIRE(buf[4] == 0x00); - REQUIRE(buf[5] == 0x16); + CHECK(buf[4] == 0x00); + CHECK(buf[5] == 0x16); } SECTION("All Ones Output") { @@ -63,19 +67,20 @@ TEST_CASE("CCSDS Creator", "[ccsds-creator]") { base.setDataLen(static_cast(std::pow(2, 16)) - 1); REQUIRE(base.isValid()); REQUIRE(base.serializeNe(&bufPtr, &serLen, buf.size()) == HasReturnvaluesIF::RETURN_OK); - REQUIRE(buf[0] == 0x1F); - REQUIRE(buf[1] == 0xFF); - REQUIRE(buf[2] == 0xFF); - REQUIRE(buf[3] == 0xFF); - REQUIRE(buf[4] == 0xFF); - REQUIRE(buf[5] == 0xFF); + CHECK(buf[0] == 0x1F); + CHECK(buf[1] == 0xFF); + CHECK(buf[2] == 0xFF); + CHECK(buf[3] == 0xFF); + CHECK(buf[4] == 0xFF); + CHECK(buf[5] == 0xFF); } SECTION("Invalid APID") { - SpacePacketCreator invalid = SpacePacketCreator( + SpacePacketCreator creator = SpacePacketCreator( ccsds::PacketType::TC, true, 0xFFFF, ccsds::SequenceFlags::FIRST_SEGMENT, 0x34, 0x16); - REQUIRE(not invalid.isValid()); - REQUIRE(invalid.serializeNe(&bufPtr, &serLen, buf.size()) == HasReturnvaluesIF::RETURN_FAILED); + REQUIRE(not creator.isValid()); + REQUIRE(not creator); + REQUIRE(creator.serializeNe(&bufPtr, &serLen, buf.size()) == HasReturnvaluesIF::RETURN_FAILED); } SECTION("Invalid Seq Count") { diff --git a/unittests/tmtcservices/CMakeLists.txt b/unittests/tmtcservices/CMakeLists.txt new file mode 100644 index 00000000..5d1c1858 --- /dev/null +++ b/unittests/tmtcservices/CMakeLists.txt @@ -0,0 +1,2 @@ +target_sources(${FSFW_TEST_TGT} PRIVATE +) diff --git a/unittests/tmtcservices/testStoreHelper.cpp b/unittests/tmtcservices/testStoreHelper.cpp new file mode 100644 index 00000000..0374ece5 --- /dev/null +++ b/unittests/tmtcservices/testStoreHelper.cpp @@ -0,0 +1,3 @@ +#include + +TEST_CASE("TM Store Helper", "[tm-store-helper]") {} \ No newline at end of file -- 2.43.0 From f0c8fd26887ddaf27e8b7fae4094bc631bc74f0d Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Mon, 25 Jul 2022 10:24:43 +0200 Subject: [PATCH 038/108] some renaming --- src/fsfw/tmtcservices/CommandingServiceBase.cpp | 2 +- src/fsfw/tmtcservices/tmHelpers.h | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/fsfw/tmtcservices/CommandingServiceBase.cpp b/src/fsfw/tmtcservices/CommandingServiceBase.cpp index 6abe625b..05f649ef 100644 --- a/src/fsfw/tmtcservices/CommandingServiceBase.cpp +++ b/src/fsfw/tmtcservices/CommandingServiceBase.cpp @@ -298,7 +298,7 @@ ReturnValue_t CommandingServiceBase::sendTmPacket(uint8_t subservice, const uint ReturnValue_t CommandingServiceBase::sendTmPacket(uint8_t subservice, object_id_t objectId, const uint8_t* data, size_t dataLen) { - telemetry::SourceDataWithObjectIdPrefix dataWithObjId(objectId, data, dataLen); + telemetry::DataWithObjectIdPrefix dataWithObjId(objectId, data, dataLen); tmStoreHelper.preparePacket(service, subservice, tmPacketCounter); tmStoreHelper.setSourceDataSerializable(&dataWithObjId); ReturnValue_t result = telemetry::storeAndSendTmPacket(tmStoreHelper, tmSendHelper); diff --git a/src/fsfw/tmtcservices/tmHelpers.h b/src/fsfw/tmtcservices/tmHelpers.h index 2e783039..da55495e 100644 --- a/src/fsfw/tmtcservices/tmHelpers.h +++ b/src/fsfw/tmtcservices/tmHelpers.h @@ -9,9 +9,9 @@ namespace telemetry { ReturnValue_t storeAndSendTmPacket(TmStoreHelper& storeHelper, TmSendHelper& sendHelper); -class SourceDataWithObjectIdPrefix : public SerializeIF { +class DataWithObjectIdPrefix : public SerializeIF { public: - SourceDataWithObjectIdPrefix(object_id_t objectId, const uint8_t* srcData, size_t srcDataLen) + DataWithObjectIdPrefix(object_id_t objectId, const uint8_t* srcData, size_t srcDataLen) : objectId(objectId), srcData(srcData), srcDataLen(srcDataLen) {} ReturnValue_t serialize(uint8_t** buffer, size_t* size, size_t maxSize, Endianness streamEndianness) const override { -- 2.43.0 From 49215270224a8b13e39e16c4ec0b08572d223f07 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Mon, 25 Jul 2022 10:31:49 +0200 Subject: [PATCH 039/108] replace c include --- src/fsfw/timemanager/CCSDSTime.h | 2 +- src/fsfw/timemanager/Clock.h | 6 +++--- src/fsfw/timemanager/ReceivesTimeInfoIF.h | 6 +++--- src/fsfw/timemanager/TimeMessage.h | 2 +- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/fsfw/timemanager/CCSDSTime.h b/src/fsfw/timemanager/CCSDSTime.h index 2a2316af..f2841d0c 100644 --- a/src/fsfw/timemanager/CCSDSTime.h +++ b/src/fsfw/timemanager/CCSDSTime.h @@ -6,7 +6,7 @@ #include #include -#include "../returnvalues/HasReturnvaluesIF.h" +#include "fsfw/returnvalues/HasReturnvaluesIF.h" #include "Clock.h" #include "clockDefinitions.h" diff --git a/src/fsfw/timemanager/Clock.h b/src/fsfw/timemanager/Clock.h index 75c898e5..2dd01dd9 100644 --- a/src/fsfw/timemanager/Clock.h +++ b/src/fsfw/timemanager/Clock.h @@ -11,7 +11,7 @@ #ifdef WIN32 #include #else -#include +#include #endif class Clock { @@ -33,7 +33,7 @@ class Clock { * * @deprecated, we should not worry about ticks, but only time */ - static uint32_t getTicksPerSecond(void); + static uint32_t getTicksPerSecond(); /** * This system call sets the system time. * To set the time, it uses a TimeOfDay_t struct. @@ -148,7 +148,7 @@ class Clock { * @return * - @c RETURN_OK on success. */ - static ReturnValue_t setLeapSeconds(const uint16_t leapSeconds_); + static ReturnValue_t setLeapSeconds(uint16_t leapSeconds_); /** * Get the Leap Seconds since 1972 diff --git a/src/fsfw/timemanager/ReceivesTimeInfoIF.h b/src/fsfw/timemanager/ReceivesTimeInfoIF.h index 5fb915ae..a6067a33 100644 --- a/src/fsfw/timemanager/ReceivesTimeInfoIF.h +++ b/src/fsfw/timemanager/ReceivesTimeInfoIF.h @@ -1,7 +1,7 @@ #ifndef FSFW_TIMEMANAGER_RECEIVESTIMEINFOIF_H_ #define FSFW_TIMEMANAGER_RECEIVESTIMEINFOIF_H_ -#include "../ipc/MessageQueueSenderIF.h" +#include "fsfw/ipc/MessageQueueSenderIF.h" /** * This is a Interface for classes that receive timing information @@ -13,11 +13,11 @@ class ReceivesTimeInfoIF { * Returns the id of the queue which receives the timing information. * @return Queue id of the timing queue. */ - virtual MessageQueueId_t getTimeReceptionQueue() const = 0; + [[nodiscard]] virtual MessageQueueId_t getTimeReceptionQueue() const = 0; /** * Empty virtual destructor. */ - virtual ~ReceivesTimeInfoIF() {} + virtual ~ReceivesTimeInfoIF() = default; }; #endif /* FSFW_TIMEMANAGER_RECEIVESTIMEINFOIF_H_ */ diff --git a/src/fsfw/timemanager/TimeMessage.h b/src/fsfw/timemanager/TimeMessage.h index ae4a9caf..c5eed13f 100644 --- a/src/fsfw/timemanager/TimeMessage.h +++ b/src/fsfw/timemanager/TimeMessage.h @@ -3,7 +3,7 @@ #include -#include "../ipc/MessageQueueMessage.h" +#include "fsfw/ipc/MessageQueueMessage.h" #include "Clock.h" class TimeMessage : public MessageQueueMessage { -- 2.43.0 From 63ee88af171a72ed0377ffc4e7da4cc7ed6cc7c6 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Mon, 25 Jul 2022 10:38:44 +0200 Subject: [PATCH 040/108] added base for tm store test --- src/fsfw/storagemanager/LocalPool.h | 2 +- unittests/tmtcservices/testStoreHelper.cpp | 9 ++++++++- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/src/fsfw/storagemanager/LocalPool.h b/src/fsfw/storagemanager/LocalPool.h index 01706e9c..47f84955 100644 --- a/src/fsfw/storagemanager/LocalPool.h +++ b/src/fsfw/storagemanager/LocalPool.h @@ -81,7 +81,7 @@ class LocalPool : public SystemObject, public StorageManagerIF { /** * @brief In the LocalPool's destructor all allocated memory is freed. */ - virtual ~LocalPool(void); + ~LocalPool() override; /** * Documentation: See StorageManagerIF.h diff --git a/unittests/tmtcservices/testStoreHelper.cpp b/unittests/tmtcservices/testStoreHelper.cpp index 0374ece5..d3db0b08 100644 --- a/unittests/tmtcservices/testStoreHelper.cpp +++ b/unittests/tmtcservices/testStoreHelper.cpp @@ -1,3 +1,10 @@ #include -TEST_CASE("TM Store Helper", "[tm-store-helper]") {} \ No newline at end of file +#include "fsfw/storagemanager/LocalPool.h" +#include "fsfw/tmtcservices/TmStoreHelper.h" + +TEST_CASE("TM Store Helper", "[tm-store-helper]") { + LocalPool::LocalPoolConfig cfg = {{10, 32}, {5, 64}}; + LocalPool pool(objects::NO_OBJECT, cfg); + auto storeHelper = TmStoreHelper(2, &pool); +} \ No newline at end of file -- 2.43.0 From 832367fb306f34cb096b46efa5bb50f7e64dfc67 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Mon, 25 Jul 2022 10:50:52 +0200 Subject: [PATCH 041/108] replace some API components with references --- src/fsfw/pus/Service17Test.cpp | 2 +- .../pus/Service1TelecommandVerification.cpp | 2 +- src/fsfw/pus/Service5EventReporting.cpp | 2 +- src/fsfw/tmtcpacket/pus/tm/PusTmCreator.cpp | 4 ++-- src/fsfw/tmtcpacket/pus/tm/PusTmCreator.h | 2 +- .../tmtcservices/CommandingServiceBase.cpp | 2 +- src/fsfw/tmtcservices/TmStoreHelper.cpp | 19 ++++++++++++------- src/fsfw/tmtcservices/TmStoreHelper.h | 7 ++++--- unittests/mocks/CdsShortTimestamperMock.h | 3 ++- unittests/tmtcpacket/testPusTmCreator.cpp | 2 +- unittests/tmtcservices/CMakeLists.txt | 1 + unittests/tmtcservices/testStoreHelper.cpp | 4 +++- 12 files changed, 30 insertions(+), 20 deletions(-) diff --git a/src/fsfw/pus/Service17Test.cpp b/src/fsfw/pus/Service17Test.cpp index ea2c06e1..d9547d03 100644 --- a/src/fsfw/pus/Service17Test.cpp +++ b/src/fsfw/pus/Service17Test.cpp @@ -7,7 +7,7 @@ Service17Test::Service17Test(object_id_t objectId, uint16_t apid, uint8_t serviceId) : PusServiceBase(objectId, apid, serviceId), - storeHelper(apid, nullptr), + storeHelper(apid), sendHelper(nullptr), packetSubCounter(0) {} diff --git a/src/fsfw/pus/Service1TelecommandVerification.cpp b/src/fsfw/pus/Service1TelecommandVerification.cpp index 93525958..997b4b40 100644 --- a/src/fsfw/pus/Service1TelecommandVerification.cpp +++ b/src/fsfw/pus/Service1TelecommandVerification.cpp @@ -16,7 +16,7 @@ Service1TelecommandVerification::Service1TelecommandVerification(object_id_t obj serviceId(serviceId), targetDestination(targetDestination), sendHelper(nullptr), - storeHelper(apid, nullptr) { + storeHelper(apid) { tmQueue = QueueFactory::instance()->createMessageQueue(messageQueueDepth); } diff --git a/src/fsfw/pus/Service5EventReporting.cpp b/src/fsfw/pus/Service5EventReporting.cpp index 847f5f80..59ad7c6c 100644 --- a/src/fsfw/pus/Service5EventReporting.cpp +++ b/src/fsfw/pus/Service5EventReporting.cpp @@ -12,7 +12,7 @@ Service5EventReporting::Service5EventReporting(object_id_t objectId, uint16_t ap uint32_t messageQueueDepth) : PusServiceBase(objectId, apid, serviceId), sendHelper(nullptr), - storeHelper(apid, nullptr), + storeHelper(apid), maxNumberReportsPerCycle(maxNumberReportsPerCycle) { eventQueue = QueueFactory::instance()->createMessageQueue(messageQueueDepth); } diff --git a/src/fsfw/tmtcpacket/pus/tm/PusTmCreator.cpp b/src/fsfw/tmtcpacket/pus/tm/PusTmCreator.cpp index 03cf2fbf..6aac4660 100644 --- a/src/fsfw/tmtcpacket/pus/tm/PusTmCreator.cpp +++ b/src/fsfw/tmtcpacket/pus/tm/PusTmCreator.cpp @@ -26,8 +26,8 @@ uint8_t PusTmCreator::getSubService() const { return pusParams.secHeader.subserv PusTmParams& PusTmCreator::getParams() { return pusParams; } -void PusTmCreator::setTimeStamper(TimeStamperIF* timeStamper_) { - pusParams.secHeader.timeStamper = timeStamper_; +void PusTmCreator::setTimeStamper(TimeStamperIF& timeStamper_) { + pusParams.secHeader.timeStamper = &timeStamper_; updateSpLengthField(); } diff --git a/src/fsfw/tmtcpacket/pus/tm/PusTmCreator.h b/src/fsfw/tmtcpacket/pus/tm/PusTmCreator.h index 9981c39c..2b62fa85 100644 --- a/src/fsfw/tmtcpacket/pus/tm/PusTmCreator.h +++ b/src/fsfw/tmtcpacket/pus/tm/PusTmCreator.h @@ -45,7 +45,7 @@ class PusTmCreator : public SerializeIF, public PusTmIF, public CustomUserDataIF PusTmCreator(SpacePacketParams initSpParams, PusTmParams initPusParams); ~PusTmCreator() override = default; - void setTimeStamper(TimeStamperIF* timeStamper); + void setTimeStamper(TimeStamperIF& timeStamper); SpacePacketParams& getSpParams(); void setApid(uint16_t apid); void setDestId(uint16_t destId); diff --git a/src/fsfw/tmtcservices/CommandingServiceBase.cpp b/src/fsfw/tmtcservices/CommandingServiceBase.cpp index 05f649ef..01c25f87 100644 --- a/src/fsfw/tmtcservices/CommandingServiceBase.cpp +++ b/src/fsfw/tmtcservices/CommandingServiceBase.cpp @@ -20,7 +20,7 @@ CommandingServiceBase::CommandingServiceBase(object_id_t setObjectId, uint16_t a apid(apid), service(service), timeoutSeconds(commandTimeoutSeconds), - tmStoreHelper(apid, nullptr), + tmStoreHelper(apid), tmSendHelper(nullptr), commandMap(numberOfParallelCommands) { commandQueue = QueueFactory::instance()->createMessageQueue(queueDepth); diff --git a/src/fsfw/tmtcservices/TmStoreHelper.cpp b/src/fsfw/tmtcservices/TmStoreHelper.cpp index 3260d4d1..a1453013 100644 --- a/src/fsfw/tmtcservices/TmStoreHelper.cpp +++ b/src/fsfw/tmtcservices/TmStoreHelper.cpp @@ -2,16 +2,21 @@ #include "TmTcMessage.h" -TmStoreHelper::TmStoreHelper(uint16_t defaultApid, StorageManagerIF* tmStore, - TimeStamperIF* timeStamper) - : tmStore(tmStore) { +TmStoreHelper::TmStoreHelper(uint16_t defaultApid): tmStore(nullptr) { + creator.setApid(defaultApid); +} + +TmStoreHelper::TmStoreHelper(uint16_t defaultApid, StorageManagerIF& tmStore) : tmStore(&tmStore) { + creator.setApid(defaultApid); +} + +TmStoreHelper::TmStoreHelper(uint16_t defaultApid, StorageManagerIF& tmStore, + TimeStamperIF& timeStamper) + : tmStore(&tmStore) { creator.setApid(defaultApid); creator.setTimeStamper(timeStamper); } -TmStoreHelper::TmStoreHelper(uint16_t defaultApid, StorageManagerIF* tmStore) : tmStore(tmStore) { - creator.setApid(defaultApid); -} ReturnValue_t TmStoreHelper::preparePacket(uint8_t service, uint8_t subservice, uint16_t counter) { PusTmParams& params = creator.getParams(); @@ -48,7 +53,7 @@ ReturnValue_t TmStoreHelper::addPacketToStore() { SerializeIF::Endianness::NETWORK); } -void TmStoreHelper::setTimeStamper(TimeStamperIF* timeStamper_) { +void TmStoreHelper::setTimeStamper(TimeStamperIF& timeStamper_) { creator.setTimeStamper(timeStamper_); } diff --git a/src/fsfw/tmtcservices/TmStoreHelper.h b/src/fsfw/tmtcservices/TmStoreHelper.h index 43f7e787..1707e5bb 100644 --- a/src/fsfw/tmtcservices/TmStoreHelper.h +++ b/src/fsfw/tmtcservices/TmStoreHelper.h @@ -9,12 +9,13 @@ class TmStoreHelper { public: - explicit TmStoreHelper(uint16_t defaultApid, StorageManagerIF* tmStore); - TmStoreHelper(uint16_t defaultApid, StorageManagerIF* tmStore, TimeStamperIF* timeStamper); + explicit TmStoreHelper(uint16_t defaultApid); + TmStoreHelper(uint16_t defaultApid, StorageManagerIF& tmStore); + TmStoreHelper(uint16_t defaultApid, StorageManagerIF& tmStore, TimeStamperIF& timeStamper); ReturnValue_t preparePacket(uint8_t service, uint8_t subservice, uint16_t counter); - void setTimeStamper(TimeStamperIF* timeStamper); + void setTimeStamper(TimeStamperIF& timeStamper); [[nodiscard]] const store_address_t& getCurrentAddr() const; void setSourceDataRaw(const uint8_t* data, size_t len); void setSourceDataSerializable(SerializeIF* serializable); diff --git a/unittests/mocks/CdsShortTimestamperMock.h b/unittests/mocks/CdsShortTimestamperMock.h index c53c22f9..273cf24c 100644 --- a/unittests/mocks/CdsShortTimestamperMock.h +++ b/unittests/mocks/CdsShortTimestamperMock.h @@ -4,6 +4,7 @@ #include #include "fsfw/timemanager/TimeStamperIF.h" +#include "fsfw/timemanager/TimeReaderIF.h" class CdsShortTimestamperMock : public TimeStamperIF, public TimeReaderIF { public: @@ -74,7 +75,7 @@ class CdsShortTimestamperMock : public TimeStamperIF, public TimeReaderIF { serFailRetval = HasReturnvaluesIF::RETURN_FAILED; } - ReturnValue_t readTimeStamp(const uint8_t *buffer, size_t maxSize) override { + ReturnValue_t readTimeStamp(const uint8_t* buffer, size_t maxSize) override { return deSerialize(&buffer, &maxSize, SerializeIF::Endianness::NETWORK); } size_t getTimestampLen() override { return getSerializedSize(); } diff --git a/unittests/tmtcpacket/testPusTmCreator.cpp b/unittests/tmtcpacket/testPusTmCreator.cpp index 035126f0..cd8f0e0b 100644 --- a/unittests/tmtcpacket/testPusTmCreator.cpp +++ b/unittests/tmtcpacket/testPusTmCreator.cpp @@ -129,7 +129,7 @@ TEST_CASE("PUS TM Creator", "[pus-tm-creator]") { // As specified in standard, the data length fields is the total size of the packet without // the primary header minus 1 REQUIRE(creatorFromEmptyCtor.getPacketDataLen() == 8); - creatorFromEmptyCtor.setTimeStamper(&timeStamper); + creatorFromEmptyCtor.setTimeStamper(timeStamper); REQUIRE(creatorFromEmptyCtor.getFullPacketLen() == 22); REQUIRE(creatorFromEmptyCtor.getPacketDataLen() == 15); } diff --git a/unittests/tmtcservices/CMakeLists.txt b/unittests/tmtcservices/CMakeLists.txt index 5d1c1858..00dfab95 100644 --- a/unittests/tmtcservices/CMakeLists.txt +++ b/unittests/tmtcservices/CMakeLists.txt @@ -1,2 +1,3 @@ target_sources(${FSFW_TEST_TGT} PRIVATE + testStoreHelper.cpp ) diff --git a/unittests/tmtcservices/testStoreHelper.cpp b/unittests/tmtcservices/testStoreHelper.cpp index d3db0b08..8c92a228 100644 --- a/unittests/tmtcservices/testStoreHelper.cpp +++ b/unittests/tmtcservices/testStoreHelper.cpp @@ -2,9 +2,11 @@ #include "fsfw/storagemanager/LocalPool.h" #include "fsfw/tmtcservices/TmStoreHelper.h" +#include "mocks/CdsShortTimestamperMock.h" TEST_CASE("TM Store Helper", "[tm-store-helper]") { + auto timeStamper = CdsShortTimestamperMock(); LocalPool::LocalPoolConfig cfg = {{10, 32}, {5, 64}}; LocalPool pool(objects::NO_OBJECT, cfg); - auto storeHelper = TmStoreHelper(2, &pool); + auto storeHelper = TmStoreHelper(2, pool, timeStamper); } \ No newline at end of file -- 2.43.0 From 4989bd0f02ac4e9055c939fae4511b2c39b9cc5b Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Mon, 25 Jul 2022 10:56:19 +0200 Subject: [PATCH 042/108] fixes for Linux OSAL clock --- src/fsfw/osal/linux/Clock.cpp | 27 +++++++++++++-------------- 1 file changed, 13 insertions(+), 14 deletions(-) diff --git a/src/fsfw/osal/linux/Clock.cpp b/src/fsfw/osal/linux/Clock.cpp index afb4ce3a..00596dab 100644 --- a/src/fsfw/osal/linux/Clock.cpp +++ b/src/fsfw/osal/linux/Clock.cpp @@ -2,8 +2,7 @@ #include #include -#include -#include +#include #include #include @@ -11,14 +10,14 @@ #include "fsfw/ipc/MutexGuard.h" #include "fsfw/serviceinterface/ServiceInterface.h" -uint32_t Clock::getTicksPerSecond(void) { +uint32_t Clock::getTicksPerSecond() { uint32_t ticks = sysconf(_SC_CLK_TCK); return ticks; } ReturnValue_t Clock::setClock(const TimeOfDay_t* time) { - timespec timeUnix; - timeval timeTimeval; + timespec timeUnix{}; + timeval timeTimeval{}; convertTimeOfDayToTimeval(time, &timeTimeval); timeUnix.tv_sec = timeTimeval.tv_sec; timeUnix.tv_nsec = (__syscall_slong_t)timeTimeval.tv_usec * 1000; @@ -32,7 +31,7 @@ ReturnValue_t Clock::setClock(const TimeOfDay_t* time) { } ReturnValue_t Clock::setClock(const timeval* time) { - timespec timeUnix; + timespec timeUnix{}; timeUnix.tv_sec = time->tv_sec; timeUnix.tv_nsec = (__syscall_slong_t)time->tv_usec * 1000; int status = clock_settime(CLOCK_REALTIME, &timeUnix); @@ -44,7 +43,7 @@ ReturnValue_t Clock::setClock(const timeval* time) { } ReturnValue_t Clock::getClock_timeval(timeval* time) { - timespec timeUnix; + timespec timeUnix{}; int status = clock_gettime(CLOCK_REALTIME, &timeUnix); if (status != 0) { return HasReturnvaluesIF::RETURN_FAILED; @@ -55,18 +54,18 @@ ReturnValue_t Clock::getClock_timeval(timeval* time) { } ReturnValue_t Clock::getClock_usecs(uint64_t* time) { - timeval timeVal; + timeval timeVal{}; ReturnValue_t result = getClock_timeval(&timeVal); if (result != HasReturnvaluesIF::RETURN_OK) { return result; } - *time = (uint64_t)timeVal.tv_sec * 1e6 + timeVal.tv_usec; + *time = static_cast(timeVal.tv_sec) * 1e6 + timeVal.tv_usec; return HasReturnvaluesIF::RETURN_OK; } timeval Clock::getUptime() { - timeval uptime; + timeval uptime{}; auto result = getUptime(&uptime); if (result != HasReturnvaluesIF::RETURN_OK) { #if FSFW_CPP_OSTREAM_ENABLED == 1 @@ -99,7 +98,7 @@ ReturnValue_t Clock::getUptime(timeval* uptime) { //} ReturnValue_t Clock::getUptime(uint32_t* uptimeMs) { - timeval uptime; + timeval uptime{}; ReturnValue_t result = getUptime(&uptime); if (result != HasReturnvaluesIF::RETURN_OK) { return result; @@ -109,7 +108,7 @@ ReturnValue_t Clock::getUptime(uint32_t* uptimeMs) { } ReturnValue_t Clock::getDateAndTime(TimeOfDay_t* time) { - timespec timeUnix; + timespec timeUnix{}; int status = clock_gettime(CLOCK_REALTIME, &timeUnix); if (status != 0) { // TODO errno @@ -122,7 +121,7 @@ ReturnValue_t Clock::getDateAndTime(TimeOfDay_t* time) { MutexGuard helper(timeMutex); // gmtime writes its output in a global buffer which is not Thread Safe // Therefore we have to use a Mutex here - struct telemetry* timeInfo; + struct std::tm* timeInfo; timeInfo = gmtime(&timeUnix.tv_sec); time->year = timeInfo->tm_year + 1900; time->month = timeInfo->tm_mon + 1; @@ -136,7 +135,7 @@ ReturnValue_t Clock::getDateAndTime(TimeOfDay_t* time) { } ReturnValue_t Clock::convertTimeOfDayToTimeval(const TimeOfDay_t* from, timeval* to) { - telemetry fromTm; + std::tm fromTm{}; // Note: Fails for years before AD fromTm.tm_year = from->year - 1900; fromTm.tm_mon = from->month - 1; -- 2.43.0 From 899d021e00784951fc3caa119de540d7c6341a69 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Mon, 25 Jul 2022 11:15:45 +0200 Subject: [PATCH 043/108] using uint32_t as store_address requires explicit cast --- src/fsfw/cfdp/CFDPMessage.cpp | 2 +- src/fsfw/datapoollocal/HasLocalDataPoolIF.h | 4 ++-- src/fsfw/parameters/ParameterMessage.cpp | 2 +- src/fsfw/storagemanager/storeAddress.h | 18 ++++++++++++------ src/fsfw/tmtcservices/TmStoreHelper.cpp | 2 ++ src/fsfw/tmtcservices/TmStoreHelper.h | 1 + src/fsfw/tmtcservices/TmTcBridge.cpp | 2 +- unittests/action/TestActionHelper.cpp | 4 ++-- .../datapoollocal/LocalPoolManagerTest.cpp | 4 ++-- unittests/datapoollocal/LocalPoolOwnerBase.cpp | 4 ++-- unittests/storagemanager/TestNewAccessor.cpp | 2 +- unittests/tmtcservices/testStoreHelper.cpp | 17 +++++++++++++++++ 12 files changed, 44 insertions(+), 18 deletions(-) diff --git a/src/fsfw/cfdp/CFDPMessage.cpp b/src/fsfw/cfdp/CFDPMessage.cpp index fee55715..da6fe15b 100644 --- a/src/fsfw/cfdp/CFDPMessage.cpp +++ b/src/fsfw/cfdp/CFDPMessage.cpp @@ -10,7 +10,7 @@ void CFDPMessage::setCommand(CommandMessage *message, store_address_t cfdpPacket store_address_t CFDPMessage::getStoreId(const CommandMessage *message) { store_address_t storeAddressCFDPPacket; - storeAddressCFDPPacket = message->getParameter(); + storeAddressCFDPPacket = static_cast(message->getParameter()); return storeAddressCFDPPacket; } diff --git a/src/fsfw/datapoollocal/HasLocalDataPoolIF.h b/src/fsfw/datapoollocal/HasLocalDataPoolIF.h index a2925a46..acbe1697 100644 --- a/src/fsfw/datapoollocal/HasLocalDataPoolIF.h +++ b/src/fsfw/datapoollocal/HasLocalDataPoolIF.h @@ -80,7 +80,7 @@ class HasLocalDataPoolIF { * clearing the store automatically */ virtual void handleChangedDataset(sid_t sid, - store_address_t storeId = storeId::INVALID_STORE_ADDRESS, + store_address_t storeId = store_address_t::invalid(), bool* clearMessage = nullptr) { if (clearMessage != nullptr) { *clearMessage = true; @@ -100,7 +100,7 @@ class HasLocalDataPoolIF { * after the callback. */ virtual void handleChangedPoolVariable(gp_id_t gpid, - store_address_t storeId = storeId::INVALID_STORE_ADDRESS, + store_address_t storeId = store_address_t::invalid(), bool* clearMessage = nullptr) { if (clearMessage != nullptr) { *clearMessage = true; diff --git a/src/fsfw/parameters/ParameterMessage.cpp b/src/fsfw/parameters/ParameterMessage.cpp index 9dc58365..9a7b5288 100644 --- a/src/fsfw/parameters/ParameterMessage.cpp +++ b/src/fsfw/parameters/ParameterMessage.cpp @@ -44,7 +44,7 @@ store_address_t ParameterMessage::getParameterLoadCommand(const CommandMessage* *pfc = packedParamSettings >> 16 & 0xff; *rows = packedParamSettings >> 8 & 0xff; *columns = packedParamSettings & 0xff; - return message->getParameter2(); + return static_cast(message->getParameter2()); } void ParameterMessage::clear(CommandMessage* message) { diff --git a/src/fsfw/storagemanager/storeAddress.h b/src/fsfw/storagemanager/storeAddress.h index 41f70573..a656cfe1 100644 --- a/src/fsfw/storagemanager/storeAddress.h +++ b/src/fsfw/storagemanager/storeAddress.h @@ -3,26 +3,26 @@ #include -namespace storeId { -static constexpr uint32_t INVALID_STORE_ADDRESS = 0xffffffff; -} - /** * This union defines the type that identifies where a data packet is * stored in the store. It comprises of a raw part to read it as raw value and * a structured part to use it in pool-like stores. */ union store_address_t { + public: + static constexpr uint32_t INVALID_RAW = 0xffffffff; /** * Default Constructor, initializing to INVALID_ADDRESS */ - store_address_t() : raw(storeId::INVALID_STORE_ADDRESS) {} + store_address_t() : raw(INVALID_RAW) {} /** * Constructor to create an address object using the raw address * * @param rawAddress */ - store_address_t(uint32_t rawAddress) : raw(rawAddress) {} + explicit store_address_t(uint32_t rawAddress) : raw(rawAddress) {} + + static store_address_t invalid() { return {}; }; /** * Constructor to create an address object using pool @@ -52,6 +52,12 @@ union store_address_t { uint32_t raw; bool operator==(const store_address_t& other) const { return raw == other.raw; } + bool operator!=(const store_address_t& other) const { return raw != other.raw; } + + store_address_t& operator=(const uint32_t rawAddr) { + raw = rawAddr; + return *this; + } }; #endif /* FSFW_STORAGEMANAGER_STOREADDRESS_H_ */ diff --git a/src/fsfw/tmtcservices/TmStoreHelper.cpp b/src/fsfw/tmtcservices/TmStoreHelper.cpp index a1453013..5f766c3f 100644 --- a/src/fsfw/tmtcservices/TmStoreHelper.cpp +++ b/src/fsfw/tmtcservices/TmStoreHelper.cpp @@ -58,3 +58,5 @@ void TmStoreHelper::setTimeStamper(TimeStamperIF& timeStamper_) { } void TmStoreHelper::setApid(uint16_t apid) { creator.setApid(apid); } + +PusTmCreator& TmStoreHelper::getCreatorRef() { return creator; } diff --git a/src/fsfw/tmtcservices/TmStoreHelper.h b/src/fsfw/tmtcservices/TmStoreHelper.h index 1707e5bb..ebaff707 100644 --- a/src/fsfw/tmtcservices/TmStoreHelper.h +++ b/src/fsfw/tmtcservices/TmStoreHelper.h @@ -15,6 +15,7 @@ class TmStoreHelper { ReturnValue_t preparePacket(uint8_t service, uint8_t subservice, uint16_t counter); + PusTmCreator& getCreatorRef(); void setTimeStamper(TimeStamperIF& timeStamper); [[nodiscard]] const store_address_t& getCurrentAddr() const; void setSourceDataRaw(const uint8_t* data, size_t len); diff --git a/src/fsfw/tmtcservices/TmTcBridge.cpp b/src/fsfw/tmtcservices/TmTcBridge.cpp index 8ea67119..6af03600 100644 --- a/src/fsfw/tmtcservices/TmTcBridge.cpp +++ b/src/fsfw/tmtcservices/TmTcBridge.cpp @@ -166,7 +166,7 @@ ReturnValue_t TmTcBridge::handleTmQueue() { } ReturnValue_t TmTcBridge::storeDownlinkData(TmTcMessage* message) { - store_address_t storeId = 0; + store_address_t storeId; if (tmFifo == nullptr) { return HasReturnvaluesIF::RETURN_FAILED; } diff --git a/unittests/action/TestActionHelper.cpp b/unittests/action/TestActionHelper.cpp index 6461a195..dd252d88 100644 --- a/unittests/action/TestActionHelper.cpp +++ b/unittests/action/TestActionHelper.cpp @@ -80,7 +80,7 @@ TEST_CASE("Action Helper", "[ActionHelper]") { } SECTION("Handle failed") { - store_address_t toLongParamAddress = StorageManagerIF::INVALID_ADDRESS; + store_address_t toLongParamAddress = store_address_t::invalid(); std::array toLongData = {5, 4, 3, 2, 1}; REQUIRE(ipcStore->addData(&toLongParamAddress, toLongData.data(), 5) == retval::CATCH_OK); ActionMessage::setCommand(&actionMessage, testActionId, toLongParamAddress); @@ -98,7 +98,7 @@ TEST_CASE("Action Helper", "[ActionHelper]") { } SECTION("Missing IPC Data") { - ActionMessage::setCommand(&actionMessage, testActionId, StorageManagerIF::INVALID_ADDRESS); + ActionMessage::setCommand(&actionMessage, testActionId, store_address_t::invalid()); CHECK(not testDhMock.executeActionCalled); REQUIRE(actionHelper.handleActionMessage(&actionMessage) == retval::CATCH_OK); CommandMessage testMessage; diff --git a/unittests/datapoollocal/LocalPoolManagerTest.cpp b/unittests/datapoollocal/LocalPoolManagerTest.cpp index 58a6065e..6d9f162c 100644 --- a/unittests/datapoollocal/LocalPoolManagerTest.cpp +++ b/unittests/datapoollocal/LocalPoolManagerTest.cpp @@ -392,13 +392,13 @@ TEST_CASE("LocalPoolManagerTest", "[LocManTest]") { CHECK(gpidToCheck == lpool::uint8VarGpid); HousekeepingMessage::setUpdateSnapshotSetCommand(&hkCmd, lpool::testSid, - storeId::INVALID_STORE_ADDRESS); + store_address_t::invalid()); CHECK(poolOwner->poolManager.handleHousekeepingMessage(&hkCmd) == retval::CATCH_OK); CHECK(poolOwner->changedDataSetCallbackWasCalled(sidToCheck, storeId) == true); CHECK(sidToCheck == lpool::testSid); HousekeepingMessage::setUpdateSnapshotVariableCommand(&hkCmd, lpool::uint8VarGpid, - storeId::INVALID_STORE_ADDRESS); + store_address_t::invalid()); CHECK(poolOwner->poolManager.handleHousekeepingMessage(&hkCmd) == retval::CATCH_OK); CHECK(poolOwner->changedVariableCallbackWasCalled(gpidToCheck, storeId) == true); CHECK(gpidToCheck == lpool::uint8VarGpid); diff --git a/unittests/datapoollocal/LocalPoolOwnerBase.cpp b/unittests/datapoollocal/LocalPoolOwnerBase.cpp index 6f054893..2743e7f7 100644 --- a/unittests/datapoollocal/LocalPoolOwnerBase.cpp +++ b/unittests/datapoollocal/LocalPoolOwnerBase.cpp @@ -90,7 +90,7 @@ bool LocalPoolOwnerBase::changedDataSetCallbackWasCalled(sid_t &sid, store_addre sid = changedDatasetSid; storeId = storeIdForChangedSet; this->changedDatasetSid.raw = sid_t::INVALID_SID; - this->storeIdForChangedSet = storeId::INVALID_STORE_ADDRESS; + this->storeIdForChangedSet = store_address_t::invalid(); return condition; } @@ -108,7 +108,7 @@ bool LocalPoolOwnerBase::changedVariableCallbackWasCalled(gp_id_t &gpid, store_a gpid = changedPoolVariableGpid; storeId = storeIdForChangedVariable; this->changedPoolVariableGpid.raw = gp_id_t::INVALID_GPID; - this->storeIdForChangedVariable = storeId::INVALID_STORE_ADDRESS; + this->storeIdForChangedVariable = store_address_t::invalid(); return condition; } diff --git a/unittests/storagemanager/TestNewAccessor.cpp b/unittests/storagemanager/TestNewAccessor.cpp index 2cc2e469..996239a6 100644 --- a/unittests/storagemanager/TestNewAccessor.cpp +++ b/unittests/storagemanager/TestNewAccessor.cpp @@ -162,7 +162,7 @@ TEST_CASE("New Accessor", "[NewAccessor]") { REQUIRE(result == retval::CATCH_OK); { StorageAccessor accessor(testStoreId); - StorageAccessor accessor2(0); + StorageAccessor accessor2(store_address_t::invalid()); accessor2 = std::move(accessor); REQUIRE(accessor.data() == nullptr); std::array data; diff --git a/unittests/tmtcservices/testStoreHelper.cpp b/unittests/tmtcservices/testStoreHelper.cpp index 8c92a228..4740ef87 100644 --- a/unittests/tmtcservices/testStoreHelper.cpp +++ b/unittests/tmtcservices/testStoreHelper.cpp @@ -9,4 +9,21 @@ TEST_CASE("TM Store Helper", "[tm-store-helper]") { LocalPool::LocalPoolConfig cfg = {{10, 32}, {5, 64}}; LocalPool pool(objects::NO_OBJECT, cfg); auto storeHelper = TmStoreHelper(2, pool, timeStamper); + + SECTION("State") { + REQUIRE(storeHelper.getCurrentAddr() == store_address_t::invalid()); + REQUIRE(storeHelper.preparePacket(17, 1, 1) == HasReturnvaluesIF::RETURN_OK); + auto& creator = storeHelper.getCreatorRef(); + REQUIRE(creator.getApid() == 2); + REQUIRE(creator.getService() == 17); + REQUIRE(creator.getSubService() == 1); + REQUIRE(creator.getSequenceCount() == 0); + REQUIRE(creator.getMessageTypeCounter() == 1); + } + + SECTION("Basic") { + REQUIRE(storeHelper.preparePacket(17, 1, 1) == HasReturnvaluesIF::RETURN_OK); + REQUIRE(storeHelper.addPacketToStore() == HasReturnvaluesIF::RETURN_OK); + REQUIRE(storeHelper.getCurrentAddr() != store_address_t::invalid()); + } } \ No newline at end of file -- 2.43.0 From 973d4ee8a5fac7aa12e29acb160e88eef070beb4 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Mon, 25 Jul 2022 11:24:13 +0200 Subject: [PATCH 044/108] some more ref replacements --- src/fsfw/pus/Service17Test.cpp | 4 ++-- src/fsfw/pus/Service17Test.h | 2 +- src/fsfw/pus/Service1TelecommandVerification.cpp | 2 +- src/fsfw/tmtcservices/CommandingServiceBase.cpp | 4 ++-- src/fsfw/tmtcservices/CommandingServiceBase.h | 2 +- src/fsfw/tmtcservices/TmStoreHelper.cpp | 12 +++++++----- src/fsfw/tmtcservices/TmStoreHelper.h | 6 +++--- unittests/tmtcservices/testStoreHelper.cpp | 5 +++++ 8 files changed, 22 insertions(+), 15 deletions(-) diff --git a/src/fsfw/pus/Service17Test.cpp b/src/fsfw/pus/Service17Test.cpp index d9547d03..d7c5a71b 100644 --- a/src/fsfw/pus/Service17Test.cpp +++ b/src/fsfw/pus/Service17Test.cpp @@ -42,11 +42,11 @@ ReturnValue_t Service17Test::initialize() { if (tmStore == nullptr) { return ObjectManagerIF::CHILD_INIT_FAILED; } - storeHelper.setTmStore(tmStore); + storeHelper.setTmStore(*tmStore); } return result; } -void Service17Test::setCustomTmStore(StorageManagerIF* tmStore_) { +void Service17Test::setCustomTmStore(StorageManagerIF& tmStore_) { storeHelper.setTmStore(tmStore_); } diff --git a/src/fsfw/pus/Service17Test.h b/src/fsfw/pus/Service17Test.h index a5bfa974..54efcaa5 100644 --- a/src/fsfw/pus/Service17Test.h +++ b/src/fsfw/pus/Service17Test.h @@ -35,7 +35,7 @@ class Service17Test : public PusServiceBase { Service17Test(object_id_t objectId, uint16_t apid, uint8_t serviceId); - void setCustomTmStore(StorageManagerIF* tmStore); + void setCustomTmStore(StorageManagerIF& tmStore); ~Service17Test() override; ReturnValue_t handleRequest(uint8_t subservice) override; diff --git a/src/fsfw/pus/Service1TelecommandVerification.cpp b/src/fsfw/pus/Service1TelecommandVerification.cpp index 997b4b40..56259c1f 100644 --- a/src/fsfw/pus/Service1TelecommandVerification.cpp +++ b/src/fsfw/pus/Service1TelecommandVerification.cpp @@ -100,7 +100,7 @@ ReturnValue_t Service1TelecommandVerification::initialize() { if (tmStore == nullptr) { return ObjectManager::CHILD_INIT_FAILED; } - storeHelper.setTmStore(tmStore); + storeHelper.setTmStore(*tmStore); } return SystemObject::initialize(); } diff --git a/src/fsfw/tmtcservices/CommandingServiceBase.cpp b/src/fsfw/tmtcservices/CommandingServiceBase.cpp index 01c25f87..1a548751 100644 --- a/src/fsfw/tmtcservices/CommandingServiceBase.cpp +++ b/src/fsfw/tmtcservices/CommandingServiceBase.cpp @@ -96,7 +96,7 @@ ReturnValue_t CommandingServiceBase::initialize() { if (tmStore == nullptr) { return ObjectManagerIF::CHILD_INIT_FAILED; } - tmStoreHelper.setTmStore(tmStore); + tmStoreHelper.setTmStore(*tmStore); } if (errReporter == nullptr) { errReporter = @@ -419,7 +419,7 @@ void CommandingServiceBase::checkTimeout() { void CommandingServiceBase::setTaskIF(PeriodicTaskIF* task_) { executingTask = task_; } -void CommandingServiceBase::setCustomTmStore(StorageManagerIF* store) { +void CommandingServiceBase::setCustomTmStore(StorageManagerIF& store) { tmStoreHelper.setTmStore(store); } ReturnValue_t CommandingServiceBase::setUpTcReader(store_address_t storeId) { diff --git a/src/fsfw/tmtcservices/CommandingServiceBase.h b/src/fsfw/tmtcservices/CommandingServiceBase.h index 9b8aa61e..9d116400 100644 --- a/src/fsfw/tmtcservices/CommandingServiceBase.h +++ b/src/fsfw/tmtcservices/CommandingServiceBase.h @@ -70,7 +70,7 @@ class CommandingServiceBase : public SystemObject, size_t queueDepth = 20); ~CommandingServiceBase() override; - void setCustomTmStore(StorageManagerIF* store); + void setCustomTmStore(StorageManagerIF& store); /** * This setter can be used to set the packet source individually instead * of using the default static framework ID set in the factory. diff --git a/src/fsfw/tmtcservices/TmStoreHelper.cpp b/src/fsfw/tmtcservices/TmStoreHelper.cpp index 5f766c3f..79c617e7 100644 --- a/src/fsfw/tmtcservices/TmStoreHelper.cpp +++ b/src/fsfw/tmtcservices/TmStoreHelper.cpp @@ -28,16 +28,18 @@ ReturnValue_t TmStoreHelper::preparePacket(uint8_t service, uint8_t subservice, StorageManagerIF* TmStoreHelper::getTmStore() { return tmStore; } -void TmStoreHelper::setTmStore(StorageManagerIF* store) { tmStore = store; } +void TmStoreHelper::setTmStore(StorageManagerIF& store) { tmStore = &store; } + const store_address_t& TmStoreHelper::getCurrentAddr() const { return currentAddr; } + ReturnValue_t TmStoreHelper::deletePacket() { return tmStore->deleteData(currentAddr); } -void TmStoreHelper::setSourceDataRaw(const uint8_t* data, size_t len) { - creator.setRawUserData(data, len); +ReturnValue_t TmStoreHelper::setSourceDataRaw(const uint8_t* data, size_t len) { + return creator.setRawUserData(data, len); } -void TmStoreHelper::setSourceDataSerializable(SerializeIF* serializable) { - creator.setSerializableUserData(serializable); +ReturnValue_t TmStoreHelper::setSourceDataSerializable(SerializeIF* serializable) { + return creator.setSerializableUserData(serializable); } ReturnValue_t TmStoreHelper::addPacketToStore() { diff --git a/src/fsfw/tmtcservices/TmStoreHelper.h b/src/fsfw/tmtcservices/TmStoreHelper.h index ebaff707..cf7d3c74 100644 --- a/src/fsfw/tmtcservices/TmStoreHelper.h +++ b/src/fsfw/tmtcservices/TmStoreHelper.h @@ -18,11 +18,11 @@ class TmStoreHelper { PusTmCreator& getCreatorRef(); void setTimeStamper(TimeStamperIF& timeStamper); [[nodiscard]] const store_address_t& getCurrentAddr() const; - void setSourceDataRaw(const uint8_t* data, size_t len); - void setSourceDataSerializable(SerializeIF* serializable); + ReturnValue_t setSourceDataRaw(const uint8_t* data, size_t len); + ReturnValue_t setSourceDataSerializable(SerializeIF* serializable); void setApid(uint16_t apid); StorageManagerIF* getTmStore(); - void setTmStore(StorageManagerIF* store); + void setTmStore(StorageManagerIF& store); ReturnValue_t addPacketToStore(); ReturnValue_t deletePacket(); diff --git a/unittests/tmtcservices/testStoreHelper.cpp b/unittests/tmtcservices/testStoreHelper.cpp index 4740ef87..7e52ea14 100644 --- a/unittests/tmtcservices/testStoreHelper.cpp +++ b/unittests/tmtcservices/testStoreHelper.cpp @@ -12,6 +12,7 @@ TEST_CASE("TM Store Helper", "[tm-store-helper]") { SECTION("State") { REQUIRE(storeHelper.getCurrentAddr() == store_address_t::invalid()); + REQUIRE(storeHelper.getTmStore() == &pool); REQUIRE(storeHelper.preparePacket(17, 1, 1) == HasReturnvaluesIF::RETURN_OK); auto& creator = storeHelper.getCreatorRef(); REQUIRE(creator.getApid() == 2); @@ -25,5 +26,9 @@ TEST_CASE("TM Store Helper", "[tm-store-helper]") { REQUIRE(storeHelper.preparePacket(17, 1, 1) == HasReturnvaluesIF::RETURN_OK); REQUIRE(storeHelper.addPacketToStore() == HasReturnvaluesIF::RETURN_OK); REQUIRE(storeHelper.getCurrentAddr() != store_address_t::invalid()); + auto accessor = pool.getData(storeHelper.getCurrentAddr()); + REQUIRE(accessor.first == HasReturnvaluesIF::RETURN_OK); + // Not going to verify individual fields, the creator was unittested separately + REQUIRE(accessor.second.size() == 22); } } \ No newline at end of file -- 2.43.0 From e2ad37e3e6e1e7644d1475d3296f79005a7ca0de Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Mon, 25 Jul 2022 11:26:45 +0200 Subject: [PATCH 045/108] more ref replacements --- src/fsfw/pus/CService200ModeCommanding.cpp | 6 +++--- src/fsfw/pus/CService201HealthCommanding.cpp | 2 +- src/fsfw/pus/Service1TelecommandVerification.cpp | 4 ++-- src/fsfw/pus/Service20ParameterManagement.cpp | 2 +- src/fsfw/pus/Service5EventReporting.cpp | 2 +- src/fsfw/pus/Service8FunctionManagement.cpp | 2 +- src/fsfw/tmtcpacket/pus/CustomUserDataIF.h | 2 +- src/fsfw/tmtcpacket/pus/defs.h | 4 ++-- src/fsfw/tmtcpacket/pus/tc/PusTcCreator.cpp | 2 +- src/fsfw/tmtcpacket/pus/tc/PusTcCreator.h | 2 +- src/fsfw/tmtcpacket/pus/tm/PusTmCreator.cpp | 2 +- src/fsfw/tmtcpacket/pus/tm/PusTmCreator.h | 2 +- src/fsfw/tmtcservices/CommandingServiceBase.cpp | 4 ++-- src/fsfw/tmtcservices/CommandingServiceBase.h | 2 +- src/fsfw/tmtcservices/TmStoreHelper.cpp | 2 +- src/fsfw/tmtcservices/TmStoreHelper.h | 2 +- unittests/tmtcpacket/testPusTcCreator.cpp | 2 +- unittests/tmtcpacket/testPusTmCreator.cpp | 2 +- 18 files changed, 23 insertions(+), 23 deletions(-) diff --git a/src/fsfw/pus/CService200ModeCommanding.cpp b/src/fsfw/pus/CService200ModeCommanding.cpp index 41be3d13..9990280c 100644 --- a/src/fsfw/pus/CService200ModeCommanding.cpp +++ b/src/fsfw/pus/CService200ModeCommanding.cpp @@ -96,13 +96,13 @@ ReturnValue_t CService200ModeCommanding::handleReply(const CommandMessage *reply ReturnValue_t CService200ModeCommanding::prepareModeReply(const CommandMessage *reply, object_id_t objectId) { ModePacket modeReplyPacket(objectId, ModeMessage::getMode(reply), ModeMessage::getSubmode(reply)); - return sendTmPacket(Subservice::REPLY_MODE_REPLY, &modeReplyPacket); + return sendTmPacket(Subservice::REPLY_MODE_REPLY, modeReplyPacket); } ReturnValue_t CService200ModeCommanding::prepareWrongModeReply(const CommandMessage *reply, object_id_t objectId) { ModePacket wrongModeReply(objectId, ModeMessage::getMode(reply), ModeMessage::getSubmode(reply)); - ReturnValue_t result = sendTmPacket(Subservice::REPLY_WRONG_MODE_REPLY, &wrongModeReply); + ReturnValue_t result = sendTmPacket(Subservice::REPLY_WRONG_MODE_REPLY, wrongModeReply); if (result == RETURN_OK) { // We want to produce an error here in any case because the mode was not correct return RETURN_FAILED; @@ -113,7 +113,7 @@ ReturnValue_t CService200ModeCommanding::prepareWrongModeReply(const CommandMess ReturnValue_t CService200ModeCommanding::prepareCantReachModeReply(const CommandMessage *reply, object_id_t objectId) { CantReachModePacket cantReachModePacket(objectId, ModeMessage::getCantReachModeReason(reply)); - ReturnValue_t result = sendTmPacket(Subservice::REPLY_CANT_REACH_MODE, &cantReachModePacket); + ReturnValue_t result = sendTmPacket(Subservice::REPLY_CANT_REACH_MODE, cantReachModePacket); if (result == RETURN_OK) { // We want to produce an error here in any case because the mode was not reached return RETURN_FAILED; diff --git a/src/fsfw/pus/CService201HealthCommanding.cpp b/src/fsfw/pus/CService201HealthCommanding.cpp index 644e0d7c..c668ea52 100644 --- a/src/fsfw/pus/CService201HealthCommanding.cpp +++ b/src/fsfw/pus/CService201HealthCommanding.cpp @@ -102,5 +102,5 @@ ReturnValue_t CService201HealthCommanding::handleReply(const CommandMessage *rep auto health = static_cast(HealthMessage::getHealth(reply)); auto oldHealth = static_cast(HealthMessage::getOldHealth(reply)); HealthSetReply healthSetReply(health, oldHealth); - return sendTmPacket(Subservice::REPLY_HEALTH_SET, &healthSetReply); + return sendTmPacket(Subservice::REPLY_HEALTH_SET, healthSetReply); } diff --git a/src/fsfw/pus/Service1TelecommandVerification.cpp b/src/fsfw/pus/Service1TelecommandVerification.cpp index 56259c1f..624a73d0 100644 --- a/src/fsfw/pus/Service1TelecommandVerification.cpp +++ b/src/fsfw/pus/Service1TelecommandVerification.cpp @@ -69,7 +69,7 @@ ReturnValue_t Service1TelecommandVerification::generateFailureReport( message->getTcSequenceControl(), message->getStep(), message->getErrorCode(), message->getParameter1(), message->getParameter2()); storeHelper.preparePacket(serviceId, message->getReportId(), packetSubCounter++); - storeHelper.setSourceDataSerializable(&report); + storeHelper.setSourceDataSerializable(report); return telemetry::storeAndSendTmPacket(storeHelper, sendHelper); } @@ -78,7 +78,7 @@ ReturnValue_t Service1TelecommandVerification::generateSuccessReport( SuccessReport report(message->getReportId(), message->getTcPacketId(), message->getTcSequenceControl(), message->getStep()); storeHelper.preparePacket(serviceId, message->getReportId(), packetSubCounter++); - storeHelper.setSourceDataSerializable(&report); + storeHelper.setSourceDataSerializable(report); return telemetry::storeAndSendTmPacket(storeHelper, sendHelper); } diff --git a/src/fsfw/pus/Service20ParameterManagement.cpp b/src/fsfw/pus/Service20ParameterManagement.cpp index 9354c80d..0922793c 100644 --- a/src/fsfw/pus/Service20ParameterManagement.cpp +++ b/src/fsfw/pus/Service20ParameterManagement.cpp @@ -177,7 +177,7 @@ ReturnValue_t Service20ParameterManagement::handleReply(const CommandMessage* re ParameterId_t parameterId = ParameterMessage::getParameterId(reply); ParameterDumpReply parameterReply(objectId, parameterId, parameterData.second.data(), parameterData.second.size()); - sendTmPacket(static_cast(Subservice::PARAMETER_DUMP_REPLY), ¶meterReply); + sendTmPacket(static_cast(Subservice::PARAMETER_DUMP_REPLY), parameterReply); return HasReturnvaluesIF::RETURN_OK; } default: diff --git a/src/fsfw/pus/Service5EventReporting.cpp b/src/fsfw/pus/Service5EventReporting.cpp index 59ad7c6c..e9c9c095 100644 --- a/src/fsfw/pus/Service5EventReporting.cpp +++ b/src/fsfw/pus/Service5EventReporting.cpp @@ -48,7 +48,7 @@ ReturnValue_t Service5EventReporting::generateEventReport(EventMessage message) EventReport report(message.getEventId(), message.getReporter(), message.getParameter1(), message.getParameter2()); storeHelper.preparePacket(serviceId, message.getSeverity(), packetSubCounter); - storeHelper.setSourceDataSerializable(&report); + storeHelper.setSourceDataSerializable(report); ReturnValue_t result = telemetry::storeAndSendTmPacket(storeHelper, sendHelper); if (result != HasReturnvaluesIF::RETURN_OK) { #if FSFW_CPP_OSTREAM_ENABLED == 1 diff --git a/src/fsfw/pus/Service8FunctionManagement.cpp b/src/fsfw/pus/Service8FunctionManagement.cpp index 0b3784be..c9da6d58 100644 --- a/src/fsfw/pus/Service8FunctionManagement.cpp +++ b/src/fsfw/pus/Service8FunctionManagement.cpp @@ -138,7 +138,7 @@ ReturnValue_t Service8FunctionManagement::handleDataReply(const CommandMessage* return result; } DataReply dataReply(objectId, actionId, buffer, size); - result = sendTmPacket(static_cast(Subservice::REPLY_DIRECT_COMMANDING_DATA), &dataReply); + result = sendTmPacket(static_cast(Subservice::REPLY_DIRECT_COMMANDING_DATA), dataReply); auto deletionResult = ipcStore->deleteData(storeId); if (deletionResult != HasReturnvaluesIF::RETURN_OK) { diff --git a/src/fsfw/tmtcpacket/pus/CustomUserDataIF.h b/src/fsfw/tmtcpacket/pus/CustomUserDataIF.h index ddbce9f1..779a0414 100644 --- a/src/fsfw/tmtcpacket/pus/CustomUserDataIF.h +++ b/src/fsfw/tmtcpacket/pus/CustomUserDataIF.h @@ -7,6 +7,6 @@ class CustomUserDataIF { public: virtual ~CustomUserDataIF() = default; virtual ReturnValue_t setRawUserData(const uint8_t* data, size_t len) = 0; - virtual ReturnValue_t setSerializableUserData(SerializeIF* serializable) = 0; + virtual ReturnValue_t setSerializableUserData(SerializeIF& serializable) = 0; }; #endif // FSFW_TMTCPACKET_CREATORDATAIF_H diff --git a/src/fsfw/tmtcpacket/pus/defs.h b/src/fsfw/tmtcpacket/pus/defs.h index 72a154ff..69b3415c 100644 --- a/src/fsfw/tmtcpacket/pus/defs.h +++ b/src/fsfw/tmtcpacket/pus/defs.h @@ -45,9 +45,9 @@ struct DataWrapper { dataUnion.raw.len = bufPair.second; } - void setSerializable(SerializeIF* serializable) { + void setSerializable(SerializeIF& serializable) { type = DataTypes::SERIALIZABLE; - dataUnion.serializable = serializable; + dataUnion.serializable = &serializable; } }; diff --git a/src/fsfw/tmtcpacket/pus/tc/PusTcCreator.cpp b/src/fsfw/tmtcpacket/pus/tc/PusTcCreator.cpp index 9ffd6eb4..992ec388 100644 --- a/src/fsfw/tmtcpacket/pus/tc/PusTcCreator.cpp +++ b/src/fsfw/tmtcpacket/pus/tc/PusTcCreator.cpp @@ -101,7 +101,7 @@ ReturnValue_t PusTcCreator::setRawUserData(const uint8_t *data, size_t len) { return HasReturnvaluesIF::RETURN_OK; } -ReturnValue_t PusTcCreator::setSerializableUserData(SerializeIF *serializable) { +ReturnValue_t PusTcCreator::setSerializableUserData(SerializeIF& serializable) { // TODO: Check length field? pusParams.dataWrapper.setSerializable(serializable); updateSpLengthField(); diff --git a/src/fsfw/tmtcpacket/pus/tc/PusTcCreator.h b/src/fsfw/tmtcpacket/pus/tc/PusTcCreator.h index 4e5951a5..90b32973 100644 --- a/src/fsfw/tmtcpacket/pus/tc/PusTcCreator.h +++ b/src/fsfw/tmtcpacket/pus/tc/PusTcCreator.h @@ -47,7 +47,7 @@ class PusTcCreator : public PusTcIF, public SerializeIF, public CustomUserDataIF [[nodiscard]] uint8_t getSubService() const override; [[nodiscard]] uint16_t getSourceId() const override; ReturnValue_t setRawUserData(const uint8_t *data, size_t len) override; - ReturnValue_t setSerializableUserData(SerializeIF *serializable) override; + ReturnValue_t setSerializableUserData(SerializeIF& serializable) override; private: ReturnValue_t serialize(uint8_t **buffer, size_t *size, size_t maxSize, diff --git a/src/fsfw/tmtcpacket/pus/tm/PusTmCreator.cpp b/src/fsfw/tmtcpacket/pus/tm/PusTmCreator.cpp index 6aac4660..662e74be 100644 --- a/src/fsfw/tmtcpacket/pus/tm/PusTmCreator.cpp +++ b/src/fsfw/tmtcpacket/pus/tm/PusTmCreator.cpp @@ -128,7 +128,7 @@ ReturnValue_t PusTmCreator::setRawUserData(const uint8_t* data, size_t len) { updateSpLengthField(); return HasReturnvaluesIF::RETURN_OK; } -ReturnValue_t PusTmCreator::setSerializableUserData(SerializeIF* serializable) { +ReturnValue_t PusTmCreator::setSerializableUserData(SerializeIF& serializable) { pusParams.dataWrapper.setSerializable(serializable); updateSpLengthField(); return HasReturnvaluesIF::RETURN_OK; diff --git a/src/fsfw/tmtcpacket/pus/tm/PusTmCreator.h b/src/fsfw/tmtcpacket/pus/tm/PusTmCreator.h index 2b62fa85..7df760ce 100644 --- a/src/fsfw/tmtcpacket/pus/tm/PusTmCreator.h +++ b/src/fsfw/tmtcpacket/pus/tm/PusTmCreator.h @@ -69,7 +69,7 @@ class PusTmCreator : public SerializeIF, public PusTmIF, public CustomUserDataIF Endianness streamEndianness) override; [[nodiscard]] TimeStamperIF* getTimestamper() const; ReturnValue_t setRawUserData(const uint8_t* data, size_t len) override; - ReturnValue_t setSerializableUserData(SerializeIF* serializable) override; + ReturnValue_t setSerializableUserData(SerializeIF& serializable) override; private: void setup(); diff --git a/src/fsfw/tmtcservices/CommandingServiceBase.cpp b/src/fsfw/tmtcservices/CommandingServiceBase.cpp index 1a548751..3fac5bd2 100644 --- a/src/fsfw/tmtcservices/CommandingServiceBase.cpp +++ b/src/fsfw/tmtcservices/CommandingServiceBase.cpp @@ -300,7 +300,7 @@ ReturnValue_t CommandingServiceBase::sendTmPacket(uint8_t subservice, object_id_ const uint8_t* data, size_t dataLen) { telemetry::DataWithObjectIdPrefix dataWithObjId(objectId, data, dataLen); tmStoreHelper.preparePacket(service, subservice, tmPacketCounter); - tmStoreHelper.setSourceDataSerializable(&dataWithObjId); + tmStoreHelper.setSourceDataSerializable(dataWithObjId); ReturnValue_t result = telemetry::storeAndSendTmPacket(tmStoreHelper, tmSendHelper); if (result == HasReturnvaluesIF::RETURN_OK) { this->tmPacketCounter++; @@ -308,7 +308,7 @@ ReturnValue_t CommandingServiceBase::sendTmPacket(uint8_t subservice, object_id_ return result; } -ReturnValue_t CommandingServiceBase::sendTmPacket(uint8_t subservice, SerializeIF* sourceData) { +ReturnValue_t CommandingServiceBase::sendTmPacket(uint8_t subservice, SerializeIF& sourceData) { tmStoreHelper.preparePacket(service, subservice, tmPacketCounter); tmStoreHelper.setSourceDataSerializable(sourceData); ReturnValue_t result = telemetry::storeAndSendTmPacket(tmStoreHelper, tmSendHelper); diff --git a/src/fsfw/tmtcservices/CommandingServiceBase.h b/src/fsfw/tmtcservices/CommandingServiceBase.h index 9d116400..48575724 100644 --- a/src/fsfw/tmtcservices/CommandingServiceBase.h +++ b/src/fsfw/tmtcservices/CommandingServiceBase.h @@ -313,7 +313,7 @@ class CommandingServiceBase : public SystemObject, * @param content This is a pointer to the serialized packet * @param header Serialize IF header which will be placed before content */ - ReturnValue_t sendTmPacket(uint8_t subservice, SerializeIF* sourceData); + ReturnValue_t sendTmPacket(uint8_t subservice, SerializeIF& sourceData); void checkAndExecuteFifo(CommandMapIter& iter); diff --git a/src/fsfw/tmtcservices/TmStoreHelper.cpp b/src/fsfw/tmtcservices/TmStoreHelper.cpp index 79c617e7..e7753f44 100644 --- a/src/fsfw/tmtcservices/TmStoreHelper.cpp +++ b/src/fsfw/tmtcservices/TmStoreHelper.cpp @@ -38,7 +38,7 @@ ReturnValue_t TmStoreHelper::setSourceDataRaw(const uint8_t* data, size_t len) { return creator.setRawUserData(data, len); } -ReturnValue_t TmStoreHelper::setSourceDataSerializable(SerializeIF* serializable) { +ReturnValue_t TmStoreHelper::setSourceDataSerializable(SerializeIF& serializable) { return creator.setSerializableUserData(serializable); } diff --git a/src/fsfw/tmtcservices/TmStoreHelper.h b/src/fsfw/tmtcservices/TmStoreHelper.h index cf7d3c74..fc6de002 100644 --- a/src/fsfw/tmtcservices/TmStoreHelper.h +++ b/src/fsfw/tmtcservices/TmStoreHelper.h @@ -19,7 +19,7 @@ class TmStoreHelper { void setTimeStamper(TimeStamperIF& timeStamper); [[nodiscard]] const store_address_t& getCurrentAddr() const; ReturnValue_t setSourceDataRaw(const uint8_t* data, size_t len); - ReturnValue_t setSourceDataSerializable(SerializeIF* serializable); + ReturnValue_t setSourceDataSerializable(SerializeIF& serializable); void setApid(uint16_t apid); StorageManagerIF* getTmStore(); void setTmStore(StorageManagerIF& store); diff --git a/unittests/tmtcpacket/testPusTcCreator.cpp b/unittests/tmtcpacket/testPusTcCreator.cpp index 978833cd..c5b0743b 100644 --- a/unittests/tmtcpacket/testPusTcCreator.cpp +++ b/unittests/tmtcpacket/testPusTcCreator.cpp @@ -85,7 +85,7 @@ TEST_CASE("PUS TC Creator", "[pus-tc-creator]") { SECTION("Test with Application Data Serializable") { auto& params = creator.getPusParams(); auto simpleSer = SimpleSerializable(); - creator.setSerializableUserData(&simpleSer); + creator.setSerializableUserData(simpleSer); REQUIRE(creator.getSerializedSize() == 16); REQUIRE(creator.serialize(&dataPtr, &serLen, buf.size()) == HasReturnvaluesIF::RETURN_OK); REQUIRE(serLen == 16); diff --git a/unittests/tmtcpacket/testPusTmCreator.cpp b/unittests/tmtcpacket/testPusTmCreator.cpp index cd8f0e0b..ad8a1d4d 100644 --- a/unittests/tmtcpacket/testPusTmCreator.cpp +++ b/unittests/tmtcpacket/testPusTmCreator.cpp @@ -113,7 +113,7 @@ TEST_CASE("PUS TM Creator", "[pus-tm-creator]") { SECTION("Serialize with Serializable") { auto simpleSer = SimpleSerializable(); - creator.setSerializableUserData(&simpleSer); + creator.setSerializableUserData(simpleSer); REQUIRE(creator.getFullPacketLen() == 25); REQUIRE(creator.serialize(&dataPtr, &serLen, buf.size()) == HasReturnvaluesIF::RETURN_OK); REQUIRE(buf[20] == 1); -- 2.43.0 From 36e3956efb612ccfceb696744e8571e17c156d36 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Mon, 25 Jul 2022 13:39:07 +0200 Subject: [PATCH 046/108] finished tm store helper tests --- src/fsfw/tmtcservices/TmStoreHelper.cpp | 14 +++- src/fsfw/tmtcservices/TmStoreHelper.h | 14 +++- unittests/mocks/MessageQueueMockBase.h | 14 ++-- unittests/tmtcservices/CMakeLists.txt | 1 + unittests/tmtcservices/testSendHelper.cpp | 5 ++ unittests/tmtcservices/testStoreHelper.cpp | 77 +++++++++++++++++++++- 6 files changed, 112 insertions(+), 13 deletions(-) create mode 100644 unittests/tmtcservices/testSendHelper.cpp diff --git a/src/fsfw/tmtcservices/TmStoreHelper.cpp b/src/fsfw/tmtcservices/TmStoreHelper.cpp index e7753f44..87a530ef 100644 --- a/src/fsfw/tmtcservices/TmStoreHelper.cpp +++ b/src/fsfw/tmtcservices/TmStoreHelper.cpp @@ -26,13 +26,19 @@ ReturnValue_t TmStoreHelper::preparePacket(uint8_t service, uint8_t subservice, return HasReturnvaluesIF::RETURN_OK; } -StorageManagerIF* TmStoreHelper::getTmStore() { return tmStore; } +StorageManagerIF* TmStoreHelper::getTmStore() const { return tmStore; } void TmStoreHelper::setTmStore(StorageManagerIF& store) { tmStore = &store; } const store_address_t& TmStoreHelper::getCurrentAddr() const { return currentAddr; } -ReturnValue_t TmStoreHelper::deletePacket() { return tmStore->deleteData(currentAddr); } +ReturnValue_t TmStoreHelper::deletePacket() { + ReturnValue_t result = tmStore->deleteData(currentAddr); + if(result == HasReturnvaluesIF::RETURN_OK) { + currentAddr = store_address_t::invalid(); + } + return result; +} ReturnValue_t TmStoreHelper::setSourceDataRaw(const uint8_t* data, size_t len) { return creator.setRawUserData(data, len); @@ -62,3 +68,7 @@ void TmStoreHelper::setTimeStamper(TimeStamperIF& timeStamper_) { void TmStoreHelper::setApid(uint16_t apid) { creator.setApid(apid); } PusTmCreator& TmStoreHelper::getCreatorRef() { return creator; } + +TimeStamperIF* TmStoreHelper::getTimeStamper() const { return creator.getTimestamper(); } + +uint16_t TmStoreHelper::getApid() const { return creator.getApid(); } diff --git a/src/fsfw/tmtcservices/TmStoreHelper.h b/src/fsfw/tmtcservices/TmStoreHelper.h index fc6de002..b253361e 100644 --- a/src/fsfw/tmtcservices/TmStoreHelper.h +++ b/src/fsfw/tmtcservices/TmStoreHelper.h @@ -16,13 +16,21 @@ class TmStoreHelper { ReturnValue_t preparePacket(uint8_t service, uint8_t subservice, uint16_t counter); PusTmCreator& getCreatorRef(); + void setTimeStamper(TimeStamperIF& timeStamper); + [[nodiscard]] TimeStamperIF* getTimeStamper() const; + + [[nodiscard]] StorageManagerIF* getTmStore() const; + void setTmStore(StorageManagerIF& store); + + void setApid(uint16_t apid); + [[nodiscard]] uint16_t getApid() const; + [[nodiscard]] const store_address_t& getCurrentAddr() const; ReturnValue_t setSourceDataRaw(const uint8_t* data, size_t len); ReturnValue_t setSourceDataSerializable(SerializeIF& serializable); - void setApid(uint16_t apid); - StorageManagerIF* getTmStore(); - void setTmStore(StorageManagerIF& store); + + ReturnValue_t addPacketToStore(); ReturnValue_t deletePacket(); diff --git a/unittests/mocks/MessageQueueMockBase.h b/unittests/mocks/MessageQueueMockBase.h index d3323186..92729a7a 100644 --- a/unittests/mocks/MessageQueueMockBase.h +++ b/unittests/mocks/MessageQueueMockBase.h @@ -18,11 +18,11 @@ class MessageQueueMockBase : public MessageQueueBase { uint8_t messageSentCounter = 0; bool messageSent = false; - bool wasMessageSent(uint8_t* messageSentCounter = nullptr, bool resetCounter = true) { + bool wasMessageSent(uint8_t* messageSentCounter_ = nullptr, bool resetCounter = true) { bool tempMessageSent = messageSent; messageSent = false; - if (messageSentCounter != nullptr) { - *messageSentCounter = this->messageSentCounter; + if (messageSentCounter_ != nullptr) { + *messageSentCounter_ = this->messageSentCounter; } if (resetCounter) { this->messageSentCounter = 0; @@ -40,7 +40,7 @@ class MessageQueueMockBase : public MessageQueueBase { return receiveMessage(&message); } - virtual ReturnValue_t receiveMessage(MessageQueueMessageIF* message) override { + ReturnValue_t receiveMessage(MessageQueueMessageIF* message) override { if (messagesSentQueue.empty()) { return MessageQueueIF::EMPTY; } @@ -50,8 +50,8 @@ class MessageQueueMockBase : public MessageQueueBase { messagesSentQueue.pop(); return HasReturnvaluesIF::RETURN_OK; } - virtual ReturnValue_t flush(uint32_t* count) { return HasReturnvaluesIF::RETURN_OK; } - virtual ReturnValue_t sendMessageFrom(MessageQueueId_t sendTo, MessageQueueMessageIF* message, + ReturnValue_t flush(uint32_t* count) override { return HasReturnvaluesIF::RETURN_OK; } + ReturnValue_t sendMessageFrom(MessageQueueId_t sendTo, MessageQueueMessageIF* message, MessageQueueId_t sentFrom, bool ignoreFault = false) override { messageSent = true; @@ -61,7 +61,7 @@ class MessageQueueMockBase : public MessageQueueBase { return HasReturnvaluesIF::RETURN_OK; } - virtual ReturnValue_t reply(MessageQueueMessageIF* message) override { + ReturnValue_t reply(MessageQueueMessageIF* message) override { return sendMessageFrom(MessageQueueIF::NO_QUEUE, message, this->getId(), false); } diff --git a/unittests/tmtcservices/CMakeLists.txt b/unittests/tmtcservices/CMakeLists.txt index 00dfab95..791066ad 100644 --- a/unittests/tmtcservices/CMakeLists.txt +++ b/unittests/tmtcservices/CMakeLists.txt @@ -1,3 +1,4 @@ target_sources(${FSFW_TEST_TGT} PRIVATE testStoreHelper.cpp + testSendHelper.cpp ) diff --git a/unittests/tmtcservices/testSendHelper.cpp b/unittests/tmtcservices/testSendHelper.cpp new file mode 100644 index 00000000..66c7ab59 --- /dev/null +++ b/unittests/tmtcservices/testSendHelper.cpp @@ -0,0 +1,5 @@ +#include + +TEST_CASE("TM Send Helper", "[tm-send-helper]") { + +} \ No newline at end of file diff --git a/unittests/tmtcservices/testStoreHelper.cpp b/unittests/tmtcservices/testStoreHelper.cpp index 7e52ea14..275a6238 100644 --- a/unittests/tmtcservices/testStoreHelper.cpp +++ b/unittests/tmtcservices/testStoreHelper.cpp @@ -3,15 +3,17 @@ #include "fsfw/storagemanager/LocalPool.h" #include "fsfw/tmtcservices/TmStoreHelper.h" #include "mocks/CdsShortTimestamperMock.h" +#include "mocks/SimpleSerializable.h" TEST_CASE("TM Store Helper", "[tm-store-helper]") { auto timeStamper = CdsShortTimestamperMock(); - LocalPool::LocalPoolConfig cfg = {{10, 32}, {5, 64}}; + LocalPool::LocalPoolConfig cfg = {{5, 32}, {2, 64}}; LocalPool pool(objects::NO_OBJECT, cfg); auto storeHelper = TmStoreHelper(2, pool, timeStamper); SECTION("State") { REQUIRE(storeHelper.getCurrentAddr() == store_address_t::invalid()); + REQUIRE(storeHelper.getTimeStamper() == &timeStamper); REQUIRE(storeHelper.getTmStore() == &pool); REQUIRE(storeHelper.preparePacket(17, 1, 1) == HasReturnvaluesIF::RETURN_OK); auto& creator = storeHelper.getCreatorRef(); @@ -22,6 +24,25 @@ TEST_CASE("TM Store Helper", "[tm-store-helper]") { REQUIRE(creator.getMessageTypeCounter() == 1); } + SECTION("Timestamper Setter") { + auto timeStamper2 = CdsShortTimestamperMock(); + storeHelper.setTimeStamper(timeStamper2); + REQUIRE(storeHelper.getTimeStamper() == &timeStamper2); + } + + SECTION("Pool Setter") { + LocalPool::LocalPoolConfig cfg2 = {{10, 32}, {5, 64}}; + LocalPool pool2(objects::NO_OBJECT, cfg); + storeHelper.setTmStore(pool2); + REQUIRE(storeHelper.getTmStore() == &pool2); + } + + SECTION("APID Setter") { + storeHelper.setApid(3); + auto& creator = storeHelper.getCreatorRef(); + REQUIRE(creator.getApid() == 3); + } + SECTION("Basic") { REQUIRE(storeHelper.preparePacket(17, 1, 1) == HasReturnvaluesIF::RETURN_OK); REQUIRE(storeHelper.addPacketToStore() == HasReturnvaluesIF::RETURN_OK); @@ -31,4 +52,58 @@ TEST_CASE("TM Store Helper", "[tm-store-helper]") { // Not going to verify individual fields, the creator was unittested separately REQUIRE(accessor.second.size() == 22); } + + SECTION("Deletion") { + REQUIRE(storeHelper.preparePacket(17, 1, 1) == HasReturnvaluesIF::RETURN_OK); + REQUIRE(storeHelper.addPacketToStore() == HasReturnvaluesIF::RETURN_OK); + REQUIRE(storeHelper.getCurrentAddr() != store_address_t::invalid()); + { + auto accessor = pool.getData(storeHelper.getCurrentAddr()); + REQUIRE(accessor.first == HasReturnvaluesIF::RETURN_OK); + REQUIRE(accessor.second.size() == 22); + accessor.second.release(); + } + REQUIRE(storeHelper.deletePacket() == HasReturnvaluesIF::RETURN_OK); + REQUIRE(storeHelper.getCurrentAddr() == store_address_t::invalid()); + auto accessor = pool.getData(storeHelper.getCurrentAddr()); + REQUIRE(accessor.first != HasReturnvaluesIF::RETURN_OK); + } + + SECTION("With App Data Raw") { + REQUIRE(storeHelper.preparePacket(17, 1, 1) == HasReturnvaluesIF::RETURN_OK); + std::array data = {1, 2, 3}; + REQUIRE(storeHelper.setSourceDataRaw(data.data(), data.size()) == HasReturnvaluesIF::RETURN_OK); + REQUIRE(storeHelper.addPacketToStore() == HasReturnvaluesIF::RETURN_OK); + REQUIRE(storeHelper.getCurrentAddr() != store_address_t::invalid()); + auto accessor = pool.getData(storeHelper.getCurrentAddr()); + REQUIRE(accessor.first == HasReturnvaluesIF::RETURN_OK); + // Not going to verify individual fields, the creator was unittested separately + REQUIRE(accessor.second.size() == 25); + } + + SECTION("With App Data Serializable") { + REQUIRE(storeHelper.preparePacket(17, 1, 1) == HasReturnvaluesIF::RETURN_OK); + auto serializable = SimpleSerializable(); + REQUIRE(storeHelper.setSourceDataSerializable(serializable) == HasReturnvaluesIF::RETURN_OK); + REQUIRE(storeHelper.addPacketToStore() == HasReturnvaluesIF::RETURN_OK); + REQUIRE(storeHelper.getCurrentAddr() != store_address_t::invalid()); + auto accessor = pool.getData(storeHelper.getCurrentAddr()); + REQUIRE(accessor.first == HasReturnvaluesIF::RETURN_OK); + // Not going to verify individual fields, the creator was unittested separately + REQUIRE(accessor.second.size() == 25); + } + + SECTION("APID Only CTOR") { + auto storeHelperApidOnly = TmStoreHelper(2); + REQUIRE(storeHelperApidOnly.getApid() == 2); + REQUIRE(storeHelperApidOnly.getTmStore() == nullptr); + REQUIRE(storeHelperApidOnly.getTimeStamper() == nullptr); + } + + SECTION("APID and TM Store Only CTOR") { + auto storeHelperApidOnly = TmStoreHelper(2, pool); + REQUIRE(storeHelperApidOnly.getApid() == 2); + REQUIRE(storeHelperApidOnly.getTmStore() == &pool); + REQUIRE(storeHelperApidOnly.getTimeStamper() == nullptr); + } } \ No newline at end of file -- 2.43.0 From 1a7d7b172b0e29d2612686f3e5a9350b16881019 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Mon, 25 Jul 2022 14:04:06 +0200 Subject: [PATCH 047/108] set up new internal error reporter mock --- src/fsfw/ipc/MessageQueueBase.cpp | 2 +- src/fsfw/ipc/MessageQueueBase.h | 30 ++++----- src/fsfw/ipc/MessageQueueIF.h | 10 +-- src/fsfw/osal/host/MessageQueue.cpp | 4 +- src/fsfw/osal/host/QueueFactory.cpp | 5 +- src/fsfw/tmtcservices/PusServiceBase.cpp | 2 +- src/fsfw/tmtcservices/TmSendHelper.cpp | 15 +++-- src/fsfw/tmtcservices/TmSendHelper.h | 8 ++- .../TestInternalErrorReporter.cpp | 12 ++-- unittests/mocks/CMakeLists.txt | 1 + unittests/mocks/InternalErrorReporterMock.h | 11 +++ unittests/mocks/MessageQueueMockBase.cpp | 67 +++++++++++++++++++ unittests/mocks/MessageQueueMockBase.h | 63 +++-------------- unittests/tmtcservices/testSendHelper.cpp | 4 +- 14 files changed, 140 insertions(+), 94 deletions(-) create mode 100644 unittests/mocks/InternalErrorReporterMock.h create mode 100644 unittests/mocks/MessageQueueMockBase.cpp diff --git a/src/fsfw/ipc/MessageQueueBase.cpp b/src/fsfw/ipc/MessageQueueBase.cpp index c43670ed..56041bee 100644 --- a/src/fsfw/ipc/MessageQueueBase.cpp +++ b/src/fsfw/ipc/MessageQueueBase.cpp @@ -8,7 +8,7 @@ MessageQueueBase::MessageQueueBase(MessageQueueId_t id, MessageQueueId_t default } } -MessageQueueBase::~MessageQueueBase() {} +MessageQueueBase::~MessageQueueBase() = default; ReturnValue_t MessageQueueBase::sendToDefault(MessageQueueMessageIF* message) { return sendToDefaultFrom(message, this->getId(), false); diff --git a/src/fsfw/ipc/MessageQueueBase.h b/src/fsfw/ipc/MessageQueueBase.h index 942b6121..9c05b1a2 100644 --- a/src/fsfw/ipc/MessageQueueBase.h +++ b/src/fsfw/ipc/MessageQueueBase.h @@ -7,28 +7,28 @@ class MessageQueueBase : public MessageQueueIF { public: MessageQueueBase(MessageQueueId_t id, MessageQueueId_t defaultDest, MqArgs* mqArgs); - virtual ~MessageQueueBase(); + ~MessageQueueBase() override; // Default implementations for MessageQueueIF where possible - virtual MessageQueueId_t getLastPartner() const override; - virtual MessageQueueId_t getId() const override; - virtual MqArgs& getMqArgs() override; - virtual void setDefaultDestination(MessageQueueId_t defaultDestination) override; - virtual MessageQueueId_t getDefaultDestination() const override; - virtual bool isDefaultDestinationSet() const override; - virtual ReturnValue_t sendMessage(MessageQueueId_t sendTo, MessageQueueMessageIF* message, + [[nodiscard]] MessageQueueId_t getLastPartner() const override; + [[nodiscard]] MessageQueueId_t getId() const override; + MqArgs& getMqArgs() override; + void setDefaultDestination(MessageQueueId_t defaultDestination) override; + [[nodiscard]] MessageQueueId_t getDefaultDestination() const override; + [[nodiscard]] bool isDefaultDestinationSet() const override; + ReturnValue_t sendMessage(MessageQueueId_t sendTo, MessageQueueMessageIF* message, bool ignoreFault) override; - virtual ReturnValue_t sendToDefault(MessageQueueMessageIF* message) override; - virtual ReturnValue_t reply(MessageQueueMessageIF* message) override; - virtual ReturnValue_t receiveMessage(MessageQueueMessageIF* message, + ReturnValue_t sendToDefault(MessageQueueMessageIF* message) override; + ReturnValue_t reply(MessageQueueMessageIF* message) override; + ReturnValue_t receiveMessage(MessageQueueMessageIF* message, MessageQueueId_t* receivedFrom) override; - virtual ReturnValue_t sendToDefaultFrom(MessageQueueMessageIF* message, MessageQueueId_t sentFrom, + ReturnValue_t sendToDefaultFrom(MessageQueueMessageIF* message, MessageQueueId_t sentFrom, bool ignoreFault = false) override; // OSAL specific, forward the abstract function - virtual ReturnValue_t receiveMessage(MessageQueueMessageIF* message) = 0; - virtual ReturnValue_t sendMessageFrom(MessageQueueId_t sendTo, MessageQueueMessageIF* message, - MessageQueueId_t sentFrom, bool ignoreFault = false) = 0; + ReturnValue_t receiveMessage(MessageQueueMessageIF* message) override = 0; + ReturnValue_t sendMessageFrom(MessageQueueId_t sendTo, MessageQueueMessageIF* message, + MessageQueueId_t sentFrom, bool ignoreFault = false) override = 0; protected: MessageQueueId_t id = MessageQueueIF::NO_QUEUE; diff --git a/src/fsfw/ipc/MessageQueueIF.h b/src/fsfw/ipc/MessageQueueIF.h index 9532b2d6..4f69695a 100644 --- a/src/fsfw/ipc/MessageQueueIF.h +++ b/src/fsfw/ipc/MessageQueueIF.h @@ -30,7 +30,7 @@ class MessageQueueIF { //! [EXPORT] : [COMMENT] Returned if the target destination is invalid. static constexpr ReturnValue_t DESTINATION_INVALID = MAKE_RETURN_CODE(4); - virtual ~MessageQueueIF() {} + virtual ~MessageQueueIF() = default; /** * @brief This operation sends a message to the last communication partner. * @details @@ -82,11 +82,11 @@ class MessageQueueIF { /** * @brief This method returns the message queue ID of the last communication partner. */ - virtual MessageQueueId_t getLastPartner() const = 0; + [[nodiscard]] virtual MessageQueueId_t getLastPartner() const = 0; /** * @brief This method returns the message queue ID of this class's message queue. */ - virtual MessageQueueId_t getId() const = 0; + [[nodiscard]] virtual MessageQueueId_t getId() const = 0; /** * @brief With the sendMessage call, a queue message is sent to a receiving queue. @@ -159,9 +159,9 @@ class MessageQueueIF { /** * @brief This method is a simple getter for the default destination. */ - virtual MessageQueueId_t getDefaultDestination() const = 0; + [[nodiscard]] virtual MessageQueueId_t getDefaultDestination() const = 0; - virtual bool isDefaultDestinationSet() const = 0; + [[nodiscard]] virtual bool isDefaultDestinationSet() const = 0; virtual MqArgs& getMqArgs() = 0; }; diff --git a/src/fsfw/osal/host/MessageQueue.cpp b/src/fsfw/osal/host/MessageQueue.cpp index 5eb0c99a..dad05a5a 100644 --- a/src/fsfw/osal/host/MessageQueue.cpp +++ b/src/fsfw/osal/host/MessageQueue.cpp @@ -65,11 +65,11 @@ ReturnValue_t MessageQueue::sendMessageFromMessageQueue(MessageQueueId_t sendTo, // But I will still return a failure here. return HasReturnvaluesIF::RETURN_FAILED; } - MessageQueue* targetQueue = + auto* targetQueue = dynamic_cast(QueueMapManager::instance()->getMessageQueue(sendTo)); if (targetQueue == nullptr) { if (not ignoreFault) { - InternalErrorReporterIF* internalErrorReporter = + auto* internalErrorReporter = ObjectManager::instance()->get(objects::INTERNAL_ERROR_REPORTER); if (internalErrorReporter != nullptr) { internalErrorReporter->queueMessageNotSent(); diff --git a/src/fsfw/osal/host/QueueFactory.cpp b/src/fsfw/osal/host/QueueFactory.cpp index 732892ca..e2d83fd4 100644 --- a/src/fsfw/osal/host/QueueFactory.cpp +++ b/src/fsfw/osal/host/QueueFactory.cpp @@ -13,7 +13,6 @@ ReturnValue_t MessageQueueSenderIF::sendMessage(MessageQueueId_t sendTo, MessageQueueMessageIF* message, MessageQueueId_t sentFrom, bool ignoreFault) { return MessageQueue::sendMessageFromMessageQueue(sendTo, message, sentFrom, ignoreFault); - return HasReturnvaluesIF::RETURN_OK; } QueueFactory* QueueFactory::instance() { @@ -23,9 +22,9 @@ QueueFactory* QueueFactory::instance() { return factoryInstance; } -QueueFactory::QueueFactory() {} +QueueFactory::QueueFactory() = default; -QueueFactory::~QueueFactory() {} +QueueFactory::~QueueFactory() = default; MessageQueueIF* QueueFactory::createMessageQueue(uint32_t messageDepth, size_t maxMessageSize, MqArgs* args) { diff --git a/src/fsfw/tmtcservices/PusServiceBase.cpp b/src/fsfw/tmtcservices/PusServiceBase.cpp index e7a0e5b9..6a21b65b 100644 --- a/src/fsfw/tmtcservices/PusServiceBase.cpp +++ b/src/fsfw/tmtcservices/PusServiceBase.cpp @@ -131,7 +131,7 @@ void PusServiceBase::initializeTmHelpers(TmSendHelper& tmSendHelper, TmStoreHelp } void PusServiceBase::initializeTmSendHelper(TmSendHelper& tmSendHelper) { - tmSendHelper.setMsgSource(requestQueue->getId()); + tmSendHelper.setMsgQueue(requestQueue); tmSendHelper.setMsgDestination(requestQueue->getDefaultDestination()); if (errReporter == nullptr) { errReporter = diff --git a/src/fsfw/tmtcservices/TmSendHelper.cpp b/src/fsfw/tmtcservices/TmSendHelper.cpp index 76591ca2..f8c76b75 100644 --- a/src/fsfw/tmtcservices/TmSendHelper.cpp +++ b/src/fsfw/tmtcservices/TmSendHelper.cpp @@ -2,15 +2,21 @@ #include "fsfw/ipc/MessageQueueSenderIF.h" -TmSendHelper::TmSendHelper(MessageQueueId_t tmtcMsgDest, MessageQueueId_t tmtcMsgSrc, +TmSendHelper::TmSendHelper(MessageQueueIF* queue, MessageQueueId_t tmtcMsgDest, InternalErrorReporterIF *reporter) - : tmtcMsgDest(tmtcMsgDest), tmtcMsgSrc(tmtcMsgSrc), errReporter(reporter) {} + : tmtcMsgDest(tmtcMsgDest), queue(queue), errReporter(reporter) {} + +TmSendHelper::TmSendHelper(MessageQueueIF *queue, InternalErrorReporterIF *reporter) + : queue(queue), errReporter(reporter) {} TmSendHelper::TmSendHelper(InternalErrorReporterIF *reporter) : errReporter(reporter) {} ReturnValue_t TmSendHelper::sendPacket(const store_address_t &storeId) { + if(queue == nullptr) { + return HasReturnvaluesIF::RETURN_FAILED; + } TmTcMessage message(storeId); - ReturnValue_t result = MessageQueueSenderIF::sendMessage(tmtcMsgDest, &message, tmtcMsgSrc); + ReturnValue_t result = queue->sendMessage(tmtcMsgDest, &message, ignoreFault); if (result != HasReturnvaluesIF::RETURN_OK) { if (errReporter != nullptr) { errReporter->lostTm(); @@ -22,8 +28,7 @@ ReturnValue_t TmSendHelper::sendPacket(const store_address_t &storeId) { void TmSendHelper::setMsgDestination(MessageQueueId_t msgDest) { tmtcMsgDest = msgDest; } -void TmSendHelper::setMsgSource(MessageQueueId_t msgSrc) { tmtcMsgSrc = msgSrc; } - void TmSendHelper::setInternalErrorReporter(InternalErrorReporterIF *reporter) { errReporter = reporter; } +void TmSendHelper::setMsgQueue(MessageQueueIF *queue_) { queue = queue_; } diff --git a/src/fsfw/tmtcservices/TmSendHelper.h b/src/fsfw/tmtcservices/TmSendHelper.h index f7acb237..bca0d4a2 100644 --- a/src/fsfw/tmtcservices/TmSendHelper.h +++ b/src/fsfw/tmtcservices/TmSendHelper.h @@ -10,16 +10,18 @@ class TmSendHelper { public: explicit TmSendHelper(InternalErrorReporterIF* reporter); - TmSendHelper(MessageQueueId_t tmtcMsgDest, MessageQueueId_t tmtcMsgSrc, + TmSendHelper(MessageQueueIF* queue, InternalErrorReporterIF* reporter); + TmSendHelper(MessageQueueIF* queue, MessageQueueId_t tmtcMsgDest, InternalErrorReporterIF* reporter); + void setMsgQueue(MessageQueueIF* queue); void setMsgDestination(MessageQueueId_t msgDest); - void setMsgSource(MessageQueueId_t msgSrc); void setInternalErrorReporter(InternalErrorReporterIF* reporter); ReturnValue_t sendPacket(const store_address_t& storeId); private: MessageQueueId_t tmtcMsgDest = MessageQueueIF::NO_QUEUE; - MessageQueueId_t tmtcMsgSrc = MessageQueueIF::NO_QUEUE; + bool ignoreFault = false; + MessageQueueIF* queue = nullptr; InternalErrorReporterIF* errReporter; }; diff --git a/unittests/internalerror/TestInternalErrorReporter.cpp b/unittests/internalerror/TestInternalErrorReporter.cpp index 2b999fae..7349400e 100644 --- a/unittests/internalerror/TestInternalErrorReporter.cpp +++ b/unittests/internalerror/TestInternalErrorReporter.cpp @@ -33,7 +33,7 @@ TEST_CASE("Internal Error Reporter", "[TestInternalError]") { MessageQueueIF* hkQueue = QueueFactory::instance()->createMessageQueue(1); internalErrorReporter->getSubscriptionInterface()->subscribeForSetUpdateMessage( InternalErrorDataset::ERROR_SET_ID, objects::NO_OBJECT, hkQueue->getId(), true); - StorageManagerIF* ipcStore = ObjectManager::instance()->get(objects::IPC_STORE); + auto* ipcStore = ObjectManager::instance()->get(objects::IPC_STORE); SECTION("MessageQueueFull") { CommandMessage message; ActionMessage::setCompletionReply(&message, 10, true); @@ -57,7 +57,7 @@ TEST_CASE("Internal Error Reporter", "[TestInternalError]") { REQUIRE(gpid.objectId == objects::INTERNAL_ERROR_REPORTER); // We need the object ID of the reporter here (NO_OBJECT) InternalErrorDataset dataset(objects::INTERNAL_ERROR_REPORTER); - CCSDSTime::CDS_short time; + CCSDSTime::CDS_short time{}; ConstAccessorPair data = ipcStore->getData(storeAddress); REQUIRE(data.first == HasReturnvaluesIF::RETURN_OK); HousekeepingSnapshot hkSnapshot(&time, &dataset); @@ -87,7 +87,7 @@ TEST_CASE("Internal Error Reporter", "[TestInternalError]") { ConstAccessorPair data = ipcStore->getData(storeAddress); REQUIRE(data.first == HasReturnvaluesIF::RETURN_OK); - CCSDSTime::CDS_short time; + CCSDSTime::CDS_short time{}; // We need the object ID of the reporter here (NO_OBJECT) InternalErrorDataset dataset(objects::INTERNAL_ERROR_REPORTER); HousekeepingSnapshot hkSnapshot(&time, &dataset); @@ -107,10 +107,10 @@ TEST_CASE("Internal Error Reporter", "[TestInternalError]") { // Message Queue Id MessageQueueId_t id = internalErrorReporter->getCommandQueue(); REQUIRE(id != MessageQueueIF::NO_QUEUE); - CommandMessage message; + CommandMessage message2; sid_t sid(objects::INTERNAL_ERROR_REPORTER, InternalErrorDataset::ERROR_SET_ID); - HousekeepingMessage::setToggleReportingCommand(&message, sid, true, false); - result = hkQueue->sendMessage(id, &message); + HousekeepingMessage::setToggleReportingCommand(&message2, sid, true, false); + result = hkQueue->sendMessage(id, &message2); REQUIRE(result == HasReturnvaluesIF::RETURN_OK); internalErrorReporter->performOperation(0); } diff --git a/unittests/mocks/CMakeLists.txt b/unittests/mocks/CMakeLists.txt index 50a34ce8..90448798 100644 --- a/unittests/mocks/CMakeLists.txt +++ b/unittests/mocks/CMakeLists.txt @@ -4,4 +4,5 @@ target_sources(${FSFW_TEST_TGT} PRIVATE DeviceFdirMock.cpp CookieIFMock.cpp ComIFMock.cpp + MessageQueueMockBase.cpp ) diff --git a/unittests/mocks/InternalErrorReporterMock.h b/unittests/mocks/InternalErrorReporterMock.h new file mode 100644 index 00000000..ccc158d0 --- /dev/null +++ b/unittests/mocks/InternalErrorReporterMock.h @@ -0,0 +1,11 @@ +#ifndef FSFW_TESTS_INTERNALERRORREPORTERMOCK_H +#define FSFW_TESTS_INTERNALERRORREPORTERMOCK_H + +#include "fsfw/internalerror/InternalErrorReporterIF.h" + +class InternalErrorReporterMock: public InternalErrorReporterIF { + public: + InternalErrorReporterMock(); + private: +}; +#endif // FSFW_TESTS_INTERNALERRORREPORTERMOCK_H diff --git a/unittests/mocks/MessageQueueMockBase.cpp b/unittests/mocks/MessageQueueMockBase.cpp new file mode 100644 index 00000000..8c577851 --- /dev/null +++ b/unittests/mocks/MessageQueueMockBase.cpp @@ -0,0 +1,67 @@ +#include "MessageQueueMockBase.h" + + +MessageQueueMockBase::MessageQueueMockBase() + : MessageQueueBase(MessageQueueIF::NO_QUEUE, MessageQueueIF::NO_QUEUE, nullptr) {} + +MessageQueueMockBase::MessageQueueMockBase(MessageQueueId_t queueId) + : MessageQueueBase(queueId, MessageQueueIF::NO_QUEUE, nullptr) {} + +bool MessageQueueMockBase::wasMessageSent(uint8_t* messageSentCounter_, bool resetCounter) { + bool tempMessageSent = messageSent; + messageSent = false; + if (messageSentCounter_ != nullptr) { + *messageSentCounter_ = this->messageSentCounter; + } + if (resetCounter) { + this->messageSentCounter = 0; + } + return tempMessageSent; +} + +ReturnValue_t MessageQueueMockBase::popMessage() { + CommandMessage message; + message.clear(); + return receiveMessage(&message); +} + +ReturnValue_t MessageQueueMockBase::receiveMessage(MessageQueueMessageIF* message) { + if (messagesSentQueue.empty()) { + return MessageQueueIF::EMPTY; + } + this->last = message->getSender(); + std::memcpy(message->getBuffer(), messagesSentQueue.front().getBuffer(), + message->getMessageSize()); + messagesSentQueue.pop(); + return HasReturnvaluesIF::RETURN_OK; +} + +ReturnValue_t MessageQueueMockBase::flush(uint32_t* count) { + return HasReturnvaluesIF::RETURN_FAILED; +} + +ReturnValue_t MessageQueueMockBase::sendMessageFrom(MessageQueueId_t sendTo, + MessageQueueMessageIF* message, + MessageQueueId_t sentFrom, bool ignoreFault) { + messageSent = true; + messageSentCounter++; + MessageQueueMessage& messageRef = *(dynamic_cast(message)); + messagesSentQueue.push(messageRef); + return HasReturnvaluesIF::RETURN_OK; +} + +ReturnValue_t MessageQueueMockBase::reply(MessageQueueMessageIF* message) { + return sendMessageFrom(MessageQueueIF::NO_QUEUE, message, this->getId(), false); +} + +void MessageQueueMockBase::clearMessages(bool clearCommandMessages) { + while (not messagesSentQueue.empty()) { + if (clearCommandMessages) { + CommandMessage message; + std::memcpy(message.getBuffer(), messagesSentQueue.front().getBuffer(), + message.getMessageSize()); + message.clear(); + } + messagesSentQueue.pop(); + } +} diff --git a/unittests/mocks/MessageQueueMockBase.h b/unittests/mocks/MessageQueueMockBase.h index 92729a7a..4a4b7ce7 100644 --- a/unittests/mocks/MessageQueueMockBase.h +++ b/unittests/mocks/MessageQueueMockBase.h @@ -12,71 +12,30 @@ class MessageQueueMockBase : public MessageQueueBase { public: - MessageQueueMockBase() - : MessageQueueBase(MessageQueueIF::NO_QUEUE, MessageQueueIF::NO_QUEUE, nullptr) {} + MessageQueueMockBase(); + + explicit MessageQueueMockBase(MessageQueueId_t queueId); uint8_t messageSentCounter = 0; bool messageSent = false; - bool wasMessageSent(uint8_t* messageSentCounter_ = nullptr, bool resetCounter = true) { - bool tempMessageSent = messageSent; - messageSent = false; - if (messageSentCounter_ != nullptr) { - *messageSentCounter_ = this->messageSentCounter; - } - if (resetCounter) { - this->messageSentCounter = 0; - } - return tempMessageSent; - } + bool wasMessageSent(uint8_t* messageSentCounter_ = nullptr, bool resetCounter = true); /** * Pop a message, clearing it in the process. * @return */ - ReturnValue_t popMessage() { - CommandMessage message; - message.clear(); - return receiveMessage(&message); - } + ReturnValue_t popMessage(); - ReturnValue_t receiveMessage(MessageQueueMessageIF* message) override { - if (messagesSentQueue.empty()) { - return MessageQueueIF::EMPTY; - } - this->last = message->getSender(); - std::memcpy(message->getBuffer(), messagesSentQueue.front().getBuffer(), - message->getMessageSize()); - messagesSentQueue.pop(); - return HasReturnvaluesIF::RETURN_OK; - } - ReturnValue_t flush(uint32_t* count) override { return HasReturnvaluesIF::RETURN_OK; } + ReturnValue_t receiveMessage(MessageQueueMessageIF* message) override; + + ReturnValue_t flush(uint32_t* count) override; ReturnValue_t sendMessageFrom(MessageQueueId_t sendTo, MessageQueueMessageIF* message, MessageQueueId_t sentFrom, - bool ignoreFault = false) override { - messageSent = true; - messageSentCounter++; - MessageQueueMessage& messageRef = *(dynamic_cast(message)); - messagesSentQueue.push(messageRef); - return HasReturnvaluesIF::RETURN_OK; - } - - ReturnValue_t reply(MessageQueueMessageIF* message) override { - return sendMessageFrom(MessageQueueIF::NO_QUEUE, message, this->getId(), false); - } - - void clearMessages(bool clearCommandMessages = true) { - while (not messagesSentQueue.empty()) { - if (clearCommandMessages) { - CommandMessage message; - std::memcpy(message.getBuffer(), messagesSentQueue.front().getBuffer(), - message.getMessageSize()); - message.clear(); - } - messagesSentQueue.pop(); - } - } + bool ignoreFault = false) override; + ReturnValue_t reply(MessageQueueMessageIF* message) override; + void clearMessages(bool clearCommandMessages = true); private: std::queue messagesSentQueue; }; diff --git a/unittests/tmtcservices/testSendHelper.cpp b/unittests/tmtcservices/testSendHelper.cpp index 66c7ab59..84ef0162 100644 --- a/unittests/tmtcservices/testSendHelper.cpp +++ b/unittests/tmtcservices/testSendHelper.cpp @@ -1,5 +1,7 @@ #include -TEST_CASE("TM Send Helper", "[tm-send-helper]") { +#include "fsfw/tmtcservices/TmSendHelper.h" +TEST_CASE("TM Send Helper", "[tm-send-helper]") { + TmSendHelper sendHelper(nullptr); } \ No newline at end of file -- 2.43.0 From 9ee6da47e9218bf7aad3a475bed32a490232c84e Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Mon, 25 Jul 2022 14:31:57 +0200 Subject: [PATCH 048/108] improving mocks --- src/fsfw/tmtcservices/TmSendHelper.cpp | 8 ++++++-- src/fsfw/tmtcservices/TmSendHelper.h | 8 +++++--- unittests/mocks/CMakeLists.txt | 1 + unittests/mocks/InternalErrorReporterMock.cpp | 13 +++++++++++++ unittests/mocks/InternalErrorReporterMock.h | 7 +++++++ unittests/mocks/MessageQueueMockBase.cpp | 17 +++++++++++++---- unittests/mocks/MessageQueueMockBase.h | 13 ++++++++++--- unittests/tmtcservices/testSendHelper.cpp | 10 +++++++++- 8 files changed, 64 insertions(+), 13 deletions(-) create mode 100644 unittests/mocks/InternalErrorReporterMock.cpp diff --git a/src/fsfw/tmtcservices/TmSendHelper.cpp b/src/fsfw/tmtcservices/TmSendHelper.cpp index f8c76b75..2f57433d 100644 --- a/src/fsfw/tmtcservices/TmSendHelper.cpp +++ b/src/fsfw/tmtcservices/TmSendHelper.cpp @@ -2,8 +2,7 @@ #include "fsfw/ipc/MessageQueueSenderIF.h" -TmSendHelper::TmSendHelper(MessageQueueIF* queue, MessageQueueId_t tmtcMsgDest, - InternalErrorReporterIF *reporter) +TmSendHelper::TmSendHelper(MessageQueueIF* queue, InternalErrorReporterIF *reporter, MessageQueueId_t tmtcMsgDest) : tmtcMsgDest(tmtcMsgDest), queue(queue), errReporter(reporter) {} TmSendHelper::TmSendHelper(MessageQueueIF *queue, InternalErrorReporterIF *reporter) @@ -32,3 +31,8 @@ void TmSendHelper::setInternalErrorReporter(InternalErrorReporterIF *reporter) { errReporter = reporter; } void TmSendHelper::setMsgQueue(MessageQueueIF *queue_) { queue = queue_; } + +ReturnValue_t TmSendHelper::sendPacket(MessageQueueId_t dest, const store_address_t &storeId) { + setMsgDestination(dest); + return sendPacket(storeId); +} diff --git a/src/fsfw/tmtcservices/TmSendHelper.h b/src/fsfw/tmtcservices/TmSendHelper.h index bca0d4a2..7e11daad 100644 --- a/src/fsfw/tmtcservices/TmSendHelper.h +++ b/src/fsfw/tmtcservices/TmSendHelper.h @@ -9,13 +9,15 @@ class TmSendHelper { public: - explicit TmSendHelper(InternalErrorReporterIF* reporter); + TmSendHelper(MessageQueueIF* queue, InternalErrorReporterIF* reporter, MessageQueueId_t tmtcMsgDest); TmSendHelper(MessageQueueIF* queue, InternalErrorReporterIF* reporter); - TmSendHelper(MessageQueueIF* queue, MessageQueueId_t tmtcMsgDest, - InternalErrorReporterIF* reporter); + explicit TmSendHelper(InternalErrorReporterIF* reporter); + + void setMsgQueue(MessageQueueIF* queue); void setMsgDestination(MessageQueueId_t msgDest); void setInternalErrorReporter(InternalErrorReporterIF* reporter); + ReturnValue_t sendPacket(MessageQueueId_t dest, const store_address_t& storeId); ReturnValue_t sendPacket(const store_address_t& storeId); private: diff --git a/unittests/mocks/CMakeLists.txt b/unittests/mocks/CMakeLists.txt index 90448798..04024559 100644 --- a/unittests/mocks/CMakeLists.txt +++ b/unittests/mocks/CMakeLists.txt @@ -5,4 +5,5 @@ target_sources(${FSFW_TEST_TGT} PRIVATE CookieIFMock.cpp ComIFMock.cpp MessageQueueMockBase.cpp + InternalErrorReporterMock.cpp ) diff --git a/unittests/mocks/InternalErrorReporterMock.cpp b/unittests/mocks/InternalErrorReporterMock.cpp new file mode 100644 index 00000000..9988234b --- /dev/null +++ b/unittests/mocks/InternalErrorReporterMock.cpp @@ -0,0 +1,13 @@ +#include "InternalErrorReporterMock.h" + +InternalErrorReporterMock::InternalErrorReporterMock() = default; + +void InternalErrorReporterMock::queueMessageNotSent() { + queueMsgNotSentCallCnt++; +} +void InternalErrorReporterMock::lostTm() { + lostTmCallCnt++; +} +void InternalErrorReporterMock::storeFull() { + storeFullCallCnt++; +} diff --git a/unittests/mocks/InternalErrorReporterMock.h b/unittests/mocks/InternalErrorReporterMock.h index ccc158d0..d2921630 100644 --- a/unittests/mocks/InternalErrorReporterMock.h +++ b/unittests/mocks/InternalErrorReporterMock.h @@ -5,7 +5,14 @@ class InternalErrorReporterMock: public InternalErrorReporterIF { public: + unsigned int queueMsgNotSentCallCnt = 0; + unsigned int lostTmCallCnt = 0; + unsigned int storeFullCallCnt = 0; InternalErrorReporterMock(); + void queueMessageNotSent() override; + void lostTm() override; + void storeFull() override; + private: }; #endif // FSFW_TESTS_INTERNALERRORREPORTERMOCK_H diff --git a/unittests/mocks/MessageQueueMockBase.cpp b/unittests/mocks/MessageQueueMockBase.cpp index 8c577851..63caee26 100644 --- a/unittests/mocks/MessageQueueMockBase.cpp +++ b/unittests/mocks/MessageQueueMockBase.cpp @@ -43,10 +43,13 @@ ReturnValue_t MessageQueueMockBase::flush(uint32_t* count) { ReturnValue_t MessageQueueMockBase::sendMessageFrom(MessageQueueId_t sendTo, MessageQueueMessageIF* message, MessageQueueId_t sentFrom, bool ignoreFault) { - messageSent = true; - messageSentCounter++; - MessageQueueMessage& messageRef = *(dynamic_cast(message)); - messagesSentQueue.push(messageRef); + auto iter = sendMap.find(sendTo); + if (iter == sendMap.end()) { + sendMap.emplace(sendTo, SendInfo(message, 1)); + } else { + iter->second.callCount += 1; + iter->second.msgs.push(message); + } return HasReturnvaluesIF::RETURN_OK; } @@ -55,6 +58,12 @@ ReturnValue_t MessageQueueMockBase::reply(MessageQueueMessageIF* message) { } void MessageQueueMockBase::clearMessages(bool clearCommandMessages) { + for (const auto& destInfo: sendMap) { + if (clearCommandMessages) { + CommandMessage message; + std::memcpy(message.getBuffer(), destInfo.second.msgs.front()->getBuffer(), + message.getMessageSize()); + } while (not messagesSentQueue.empty()) { if (clearCommandMessages) { CommandMessage message; diff --git a/unittests/mocks/MessageQueueMockBase.h b/unittests/mocks/MessageQueueMockBase.h index 4a4b7ce7..e42a0a67 100644 --- a/unittests/mocks/MessageQueueMockBase.h +++ b/unittests/mocks/MessageQueueMockBase.h @@ -3,6 +3,7 @@ #include #include +#include #include "CatchDefinitions.h" #include "fsfw/ipc/CommandMessage.h" @@ -10,14 +11,21 @@ #include "fsfw/ipc/MessageQueueIF.h" #include "fsfw/ipc/MessageQueueMessage.h" +struct SendInfo { + explicit SendInfo(MessageQueueMessageIF* initMsg, unsigned int initCallCnt = 1): callCount(initCallCnt) { + msgs.push(initMsg); + } + unsigned int callCount = 0; + std::queue msgs; +}; + class MessageQueueMockBase : public MessageQueueBase { public: MessageQueueMockBase(); explicit MessageQueueMockBase(MessageQueueId_t queueId); - uint8_t messageSentCounter = 0; - bool messageSent = false; + std::map sendMap; bool wasMessageSent(uint8_t* messageSentCounter_ = nullptr, bool resetCounter = true); @@ -37,7 +45,6 @@ class MessageQueueMockBase : public MessageQueueBase { void clearMessages(bool clearCommandMessages = true); private: - std::queue messagesSentQueue; }; #endif /* FSFW_UNITTEST_TESTS_MOCKS_MESSAGEQUEUEMOCKBASE_H_ */ diff --git a/unittests/tmtcservices/testSendHelper.cpp b/unittests/tmtcservices/testSendHelper.cpp index 84ef0162..6e6fb069 100644 --- a/unittests/tmtcservices/testSendHelper.cpp +++ b/unittests/tmtcservices/testSendHelper.cpp @@ -1,7 +1,15 @@ #include #include "fsfw/tmtcservices/TmSendHelper.h" +#include "mocks/InternalErrorReporterMock.h" +#include "mocks/MessageQueueMockBase.h" TEST_CASE("TM Send Helper", "[tm-send-helper]") { - TmSendHelper sendHelper(nullptr); + auto errReporter = InternalErrorReporterMock(); + auto msgQueue = MessageQueueMockBase(); + TmSendHelper sendHelper(&msgQueue, &errReporter); + + SECTION("State") { + + } } \ No newline at end of file -- 2.43.0 From 6d0fa36f8acf75bcc93e16bf275f270b5ec5fb76 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Mon, 25 Jul 2022 19:36:56 +0200 Subject: [PATCH 049/108] cleaning up message queue mock and subscription API --- src/fsfw/datapoollocal/HasLocalDataPoolIF.h | 3 +- .../datapoollocal/LocalDataPoolManager.cpp | 77 ++-- src/fsfw/datapoollocal/LocalDataPoolManager.h | 45 +- .../ProvidesDataPoolSubscriptionIF.h | 69 ++- src/fsfw/housekeeping/AcceptsHkPacketsIF.h | 6 +- .../internalerror/InternalErrorReporter.cpp | 5 +- src/fsfw/ipc/MessageQueueBase.h | 8 +- src/fsfw/ipc/MessageQueueMessage.cpp | 36 +- src/fsfw/ipc/MessageQueueMessage.h | 113 ++--- src/fsfw/ipc/MessageQueueMessageIF.h | 32 +- src/fsfw/osal/linux/Clock.cpp | 2 +- src/fsfw/serialize/SerializeIF.h | 4 +- src/fsfw/timemanager/CCSDSTime.h | 2 +- src/fsfw/timemanager/TimeMessage.h | 2 +- src/fsfw/tmtcpacket/pus/tc/PusTcCreator.cpp | 2 +- src/fsfw/tmtcpacket/pus/tc/PusTcCreator.h | 2 +- src/fsfw/tmtcservices/TmSendHelper.cpp | 7 +- src/fsfw/tmtcservices/TmSendHelper.h | 4 +- src/fsfw/tmtcservices/TmStoreHelper.cpp | 7 +- src/fsfw/tmtcservices/TmStoreHelper.h | 1 - unittests/CatchFactory.cpp | 9 +- unittests/action/TestActionHelper.cpp | 12 +- unittests/datapoollocal/CMakeLists.txt | 8 +- .../datapoollocal/LocalPoolManagerTest.cpp | 413 ----------------- .../{DataSetTest.cpp => testDataSet.cpp} | 25 +- .../datapoollocal/testLocalPoolManager.cpp | 430 ++++++++++++++++++ ...ableTest.cpp => testLocalPoolVariable.cpp} | 0 ...VectorTest.cpp => testLocalPoolVector.cpp} | 4 +- unittests/mocks/CdsShortTimestamperMock.h | 4 +- unittests/mocks/HkReceiverMock.h | 10 +- unittests/mocks/InternalErrorReporterMock.cpp | 12 +- unittests/mocks/InternalErrorReporterMock.h | 2 +- .../LocalPoolOwnerBase.cpp | 17 +- .../LocalPoolOwnerBase.h | 64 ++- unittests/mocks/MessageQueueMockBase.cpp | 151 ++++-- unittests/mocks/MessageQueueMockBase.h | 41 +- unittests/serialize/testSerializeIF.cpp | 6 +- unittests/testcfg/objects/systemObjectList.h | 2 +- unittests/tmtcservices/testSendHelper.cpp | 4 +- 39 files changed, 916 insertions(+), 725 deletions(-) delete mode 100644 unittests/datapoollocal/LocalPoolManagerTest.cpp rename unittests/datapoollocal/{DataSetTest.cpp => testDataSet.cpp} (93%) create mode 100644 unittests/datapoollocal/testLocalPoolManager.cpp rename unittests/datapoollocal/{LocalPoolVariableTest.cpp => testLocalPoolVariable.cpp} (100%) rename unittests/datapoollocal/{LocalPoolVectorTest.cpp => testLocalPoolVector.cpp} (98%) rename unittests/{datapoollocal => mocks}/LocalPoolOwnerBase.cpp (90%) rename unittests/{datapoollocal => mocks}/LocalPoolOwnerBase.h (68%) diff --git a/src/fsfw/datapoollocal/HasLocalDataPoolIF.h b/src/fsfw/datapoollocal/HasLocalDataPoolIF.h index acbe1697..b7a6198e 100644 --- a/src/fsfw/datapoollocal/HasLocalDataPoolIF.h +++ b/src/fsfw/datapoollocal/HasLocalDataPoolIF.h @@ -79,8 +79,7 @@ class HasLocalDataPoolIF { * @param clearMessage If this is set to true, the pool manager will take care of * clearing the store automatically */ - virtual void handleChangedDataset(sid_t sid, - store_address_t storeId = store_address_t::invalid(), + virtual void handleChangedDataset(sid_t sid, store_address_t storeId = store_address_t::invalid(), bool* clearMessage = nullptr) { if (clearMessage != nullptr) { *clearMessage = true; diff --git a/src/fsfw/datapoollocal/LocalDataPoolManager.cpp b/src/fsfw/datapoollocal/LocalDataPoolManager.cpp index 9b7f800f..2ab737bf 100644 --- a/src/fsfw/datapoollocal/LocalDataPoolManager.cpp +++ b/src/fsfw/datapoollocal/LocalDataPoolManager.cpp @@ -1,6 +1,5 @@ #include "fsfw/datapoollocal/LocalDataPoolManager.h" -#include #include #include "fsfw/datapoollocal.h" @@ -15,6 +14,7 @@ #include "internal/HasLocalDpIFManagerAttorney.h" #include "internal/LocalPoolDataSetAttorney.h" +// TODO: Get rid of this. This should be a constructor argument, not something hardcoded in any way object_id_t LocalDataPoolManager::defaultHkDestination = objects::PUS_SERVICE_3_HOUSEKEEPING; LocalDataPoolManager::LocalDataPoolManager(HasLocalDataPoolIF* owner, MessageQueueIF* queueToUse, @@ -57,7 +57,7 @@ ReturnValue_t LocalDataPoolManager::initialize(MessageQueueIF* queueToUse) { } if (defaultHkDestination != objects::NO_OBJECT) { - AcceptsHkPacketsIF* hkPacketReceiver = + auto* hkPacketReceiver = ObjectManager::instance()->get(defaultHkDestination); if (hkPacketReceiver != nullptr) { hkDestinationId = hkPacketReceiver->getHkQueue(); @@ -335,29 +335,32 @@ void LocalDataPoolManager::resetHkUpdateResetHelper() { } } -ReturnValue_t LocalDataPoolManager::subscribeForPeriodicPacket(sid_t sid, bool enableReporting, - float collectionInterval, - bool isDiagnostics, - object_id_t packetDestination) { - AcceptsHkPacketsIF* hkReceiverObject = - ObjectManager::instance()->get(packetDestination); - if (hkReceiverObject == nullptr) { - printWarningOrError(sif::OutputTypes::OUT_WARNING, "subscribeForPeriodicPacket", - QUEUE_OR_DESTINATION_INVALID); - return QUEUE_OR_DESTINATION_INVALID; - } +ReturnValue_t LocalDataPoolManager::subscribeForRegularPeriodicPacket( + subdp::RegularHkPeriodicParams params) { + return subscribeForPeriodicPacket(params); +} +ReturnValue_t LocalDataPoolManager::subscribeForDiagPeriodicPacket( + subdp::DiagnosticsHkPeriodicParams params) { + return subscribeForPeriodicPacket(params); +} + +ReturnValue_t LocalDataPoolManager::subscribeForPeriodicPacket(subdp::ParamsBase& params) { struct HkReceiver hkReceiver; - hkReceiver.dataId.sid = sid; + hkReceiver.dataId.sid = params.sid; hkReceiver.reportingType = ReportingType::PERIODIC; hkReceiver.dataType = DataType::DATA_SET; - hkReceiver.destinationQueue = hkReceiverObject->getHkQueue(); + if (params.receiver == MessageQueueIF::NO_QUEUE) { + hkReceiver.destinationQueue = hkDestinationId; + } else { + hkReceiver.destinationQueue = params.receiver; + } - LocalPoolDataSetBase* dataSet = HasLocalDpIFManagerAttorney::getDataSetHandle(owner, sid); + LocalPoolDataSetBase* dataSet = HasLocalDpIFManagerAttorney::getDataSetHandle(owner, params.sid); if (dataSet != nullptr) { - LocalPoolDataSetAttorney::setReportingEnabled(*dataSet, enableReporting); - LocalPoolDataSetAttorney::setDiagnostic(*dataSet, isDiagnostics); - LocalPoolDataSetAttorney::initializePeriodicHelper(*dataSet, collectionInterval, + LocalPoolDataSetAttorney::setReportingEnabled(*dataSet, params.enableReporting); + LocalPoolDataSetAttorney::setDiagnostic(*dataSet, params.isDiagnostics()); + LocalPoolDataSetAttorney::initializePeriodicHelper(*dataSet, params.collectionInterval, owner->getPeriodicOperationFrequency()); } @@ -365,27 +368,30 @@ ReturnValue_t LocalDataPoolManager::subscribeForPeriodicPacket(sid_t sid, bool e return HasReturnvaluesIF::RETURN_OK; } -ReturnValue_t LocalDataPoolManager::subscribeForUpdatePacket(sid_t sid, bool isDiagnostics, - bool reportingEnabled, - object_id_t packetDestination) { - AcceptsHkPacketsIF* hkReceiverObject = - ObjectManager::instance()->get(packetDestination); - if (hkReceiverObject == nullptr) { - printWarningOrError(sif::OutputTypes::OUT_WARNING, "subscribeForPeriodicPacket", - QUEUE_OR_DESTINATION_INVALID); - return QUEUE_OR_DESTINATION_INVALID; - } +ReturnValue_t LocalDataPoolManager::subscribeForRegularUpdatePacket( + subdp::RegularHkUpdateParams params) { + return subscribeForUpdatePacket(params); +} +ReturnValue_t LocalDataPoolManager::subscribeForDiagUpdatePacket( + subdp::DiagnosticsHkUpdateParams params) { + return subscribeForUpdatePacket(params); +} +ReturnValue_t LocalDataPoolManager::subscribeForUpdatePacket(subdp::ParamsBase& params) { struct HkReceiver hkReceiver; - hkReceiver.dataId.sid = sid; + hkReceiver.dataId.sid = params.sid; hkReceiver.reportingType = ReportingType::UPDATE_HK; hkReceiver.dataType = DataType::DATA_SET; - hkReceiver.destinationQueue = hkReceiverObject->getHkQueue(); + if (params.receiver == MessageQueueIF::NO_QUEUE) { + hkReceiver.destinationQueue = hkDestinationId; + } else { + hkReceiver.destinationQueue = params.receiver; + } - LocalPoolDataSetBase* dataSet = HasLocalDpIFManagerAttorney::getDataSetHandle(owner, sid); + LocalPoolDataSetBase* dataSet = HasLocalDpIFManagerAttorney::getDataSetHandle(owner, params.sid); if (dataSet != nullptr) { LocalPoolDataSetAttorney::setReportingEnabled(*dataSet, true); - LocalPoolDataSetAttorney::setDiagnostic(*dataSet, isDiagnostics); + LocalPoolDataSetAttorney::setDiagnostic(*dataSet, params.isDiagnostics()); } hkReceivers.push_back(hkReceiver); @@ -639,6 +645,7 @@ ReturnValue_t LocalDataPoolManager::generateHousekeepingPacket(sid_t sid, /* Error, all destinations invalid */ printWarningOrError(sif::OutputTypes::OUT_WARNING, "generateHousekeepingPacket", QUEUE_OR_DESTINATION_INVALID); + return QUEUE_OR_DESTINATION_INVALID; } destination = hkDestinationId; } @@ -879,3 +886,7 @@ void LocalDataPoolManager::printWarningOrError(sif::OutputTypes outputType, } LocalDataPoolManager* LocalDataPoolManager::getPoolManagerHandle() { return this; } + +void LocalDataPoolManager::setHkDestinationId(MessageQueueId_t hkDestId) { + hkDestinationId = hkDestId; +} diff --git a/src/fsfw/datapoollocal/LocalDataPoolManager.h b/src/fsfw/datapoollocal/LocalDataPoolManager.h index e7ec0b6f..041a4b05 100644 --- a/src/fsfw/datapoollocal/LocalDataPoolManager.h +++ b/src/fsfw/datapoollocal/LocalDataPoolManager.h @@ -8,6 +8,7 @@ #include "ProvidesDataPoolSubscriptionIF.h" #include "fsfw/datapool/DataSetIF.h" #include "fsfw/datapool/PoolEntry.h" +#include "fsfw/housekeeping/AcceptsHkPacketsIF.h" #include "fsfw/housekeeping/HousekeepingMessage.h" #include "fsfw/housekeeping/HousekeepingPacketDownlink.h" #include "fsfw/housekeeping/PeriodicHousekeepingHelper.h" @@ -80,7 +81,9 @@ class LocalDataPoolManager : public ProvidesDataPoolSubscriptionIF, public Acces */ LocalDataPoolManager(HasLocalDataPoolIF* owner, MessageQueueIF* queueToUse, bool appendValidityBuffer = true); - virtual ~LocalDataPoolManager(); + ~LocalDataPoolManager() override; + + void setHkDestinationId(MessageQueueId_t hkDestId); /** * Assigns the queue to use. Make sure to call this in the #initialize @@ -112,31 +115,6 @@ class LocalDataPoolManager : public ProvidesDataPoolSubscriptionIF, public Acces */ virtual ReturnValue_t performHkOperation(); - /** - * @brief Subscribe for the generation of periodic packets. - * @details - * This subscription mechanism will generally be used by the data creator - * to generate housekeeping packets which are downlinked directly. - * @return - */ - ReturnValue_t subscribeForPeriodicPacket( - sid_t sid, bool enableReporting, float collectionInterval, bool isDiagnostics, - object_id_t packetDestination = defaultHkDestination) override; - - /** - * @brief Subscribe for the generation of packets if the dataset - * is marked as changed. - * @details - * This subscription mechanism will generally be used by the data creator. - * @param sid - * @param isDiagnostics - * @param packetDestination - * @return - */ - ReturnValue_t subscribeForUpdatePacket( - sid_t sid, bool reportingEnabled, bool isDiagnostics, - object_id_t packetDestination = defaultHkDestination) override; - /** * @brief Subscribe for a notification message which will be sent * if a dataset has changed. @@ -151,7 +129,7 @@ class LocalDataPoolManager : public ProvidesDataPoolSubscriptionIF, public Acces * Otherwise, only an notification message is sent. * @return */ - ReturnValue_t subscribeForSetUpdateMessage(const uint32_t setId, object_id_t destinationObject, + ReturnValue_t subscribeForSetUpdateMessage(uint32_t setId, object_id_t destinationObject, MessageQueueId_t targetQueueId, bool generateSnapshot) override; @@ -169,7 +147,7 @@ class LocalDataPoolManager : public ProvidesDataPoolSubscriptionIF, public Acces * Otherwise, only an notification message is sent. * @return */ - ReturnValue_t subscribeForVariableUpdateMessage(const lp_id_t localPoolId, + ReturnValue_t subscribeForVariableUpdateMessage(lp_id_t localPoolId, object_id_t destinationObject, MessageQueueId_t targetQueueId, bool generateSnapshot) override; @@ -252,7 +230,7 @@ class LocalDataPoolManager : public ProvidesDataPoolSubscriptionIF, public Acces */ void clearReceiversList(); - object_id_t getCreatorObjectId() const; + [[nodiscard]] object_id_t getCreatorObjectId() const; /** * Get the pointer to the mutex. Can be used to lock the data pool @@ -262,7 +240,14 @@ class LocalDataPoolManager : public ProvidesDataPoolSubscriptionIF, public Acces */ MutexIF* getMutexHandle(); - virtual LocalDataPoolManager* getPoolManagerHandle() override; + LocalDataPoolManager* getPoolManagerHandle() override; + ReturnValue_t subscribeForRegularPeriodicPacket(subdp::RegularHkPeriodicParams params) override; + ReturnValue_t subscribeForDiagPeriodicPacket(subdp::DiagnosticsHkPeriodicParams params) override; + ReturnValue_t subscribeForPeriodicPacket(subdp::ParamsBase& params); + + ReturnValue_t subscribeForRegularUpdatePacket(subdp::RegularHkUpdateParams params) override; + ReturnValue_t subscribeForDiagUpdatePacket(subdp::DiagnosticsHkUpdateParams params) override; + ReturnValue_t subscribeForUpdatePacket(subdp::ParamsBase& params); protected: /** Core data structure for the actual pool data */ diff --git a/src/fsfw/datapoollocal/ProvidesDataPoolSubscriptionIF.h b/src/fsfw/datapoollocal/ProvidesDataPoolSubscriptionIF.h index 1f13a09d..4fa86ef0 100644 --- a/src/fsfw/datapoollocal/ProvidesDataPoolSubscriptionIF.h +++ b/src/fsfw/datapoollocal/ProvidesDataPoolSubscriptionIF.h @@ -1,14 +1,56 @@ #ifndef FSFW_DATAPOOLLOCAL_PROVIDESDATAPOOLSUBSCRIPTION_H_ #define FSFW_DATAPOOLLOCAL_PROVIDESDATAPOOLSUBSCRIPTION_H_ -#include "../ipc/messageQueueDefinitions.h" -#include "../returnvalues/HasReturnvaluesIF.h" +#include "fsfw/housekeeping/AcceptsHkPacketsIF.h" +#include "fsfw/ipc/MessageQueueIF.h" +#include "fsfw/ipc/messageQueueDefinitions.h" +#include "fsfw/returnvalues/HasReturnvaluesIF.h" #include "localPoolDefinitions.h" +namespace subdp { + +struct ParamsBase { + ParamsBase(sid_t sid, bool enableReporting, float collectionInterval, bool diagnostics) + : sid(sid), + enableReporting(enableReporting), + collectionInterval(collectionInterval), + diagnostics(diagnostics) {} + + [[nodiscard]] bool isDiagnostics() const { return diagnostics; } + + sid_t sid; + bool enableReporting; + float collectionInterval; + MessageQueueId_t receiver = MessageQueueIF::NO_QUEUE; + + protected: + bool diagnostics; +}; + +struct RegularHkPeriodicParams : public ParamsBase { + RegularHkPeriodicParams(sid_t sid, bool enableReporting, float collectionInterval) + : ParamsBase(sid, enableReporting, collectionInterval, false) {} +}; + +struct DiagnosticsHkPeriodicParams : public ParamsBase { + DiagnosticsHkPeriodicParams(sid_t sid, bool enableReporting, float collectionInterval) + : ParamsBase(sid, enableReporting, collectionInterval, true) {} +}; + +struct RegularHkUpdateParams : public ParamsBase { + RegularHkUpdateParams(sid_t sid, bool enableReporting) + : ParamsBase(sid, enableReporting, 0.0, false) {} +}; + +struct DiagnosticsHkUpdateParams : public ParamsBase { + DiagnosticsHkUpdateParams(sid_t sid, bool enableReporting) + : ParamsBase(sid, enableReporting, 0.0, true) {} +}; +} // namespace subdp + class ProvidesDataPoolSubscriptionIF { public: - virtual ~ProvidesDataPoolSubscriptionIF(){}; - + virtual ~ProvidesDataPoolSubscriptionIF() = default; /** * @brief Subscribe for the generation of periodic packets. * @details @@ -16,9 +58,11 @@ class ProvidesDataPoolSubscriptionIF { * to generate housekeeping packets which are downlinked directly. * @return */ - virtual ReturnValue_t subscribeForPeriodicPacket(sid_t sid, bool enableReporting, - float collectionInterval, bool isDiagnostics, - object_id_t packetDestination) = 0; + virtual ReturnValue_t subscribeForRegularPeriodicPacket( + subdp::RegularHkPeriodicParams params) = 0; + virtual ReturnValue_t subscribeForDiagPeriodicPacket( + subdp::DiagnosticsHkPeriodicParams params) = 0; + /** * @brief Subscribe for the generation of packets if the dataset * is marked as changed. @@ -29,9 +73,9 @@ class ProvidesDataPoolSubscriptionIF { * @param packetDestination * @return */ - virtual ReturnValue_t subscribeForUpdatePacket(sid_t sid, bool reportingEnabled, - bool isDiagnostics, - object_id_t packetDestination) = 0; + virtual ReturnValue_t subscribeForRegularUpdatePacket(subdp::RegularHkUpdateParams params) = 0; + virtual ReturnValue_t subscribeForDiagUpdatePacket(subdp::DiagnosticsHkUpdateParams params) = 0; + /** * @brief Subscribe for a notification message which will be sent * if a dataset has changed. @@ -46,8 +90,7 @@ class ProvidesDataPoolSubscriptionIF { * Otherwise, only an notification message is sent. * @return */ - virtual ReturnValue_t subscribeForSetUpdateMessage(const uint32_t setId, - object_id_t destinationObject, + virtual ReturnValue_t subscribeForSetUpdateMessage(uint32_t setId, object_id_t destinationObject, MessageQueueId_t targetQueueId, bool generateSnapshot) = 0; /** @@ -64,7 +107,7 @@ class ProvidesDataPoolSubscriptionIF { * only an notification message is sent. * @return */ - virtual ReturnValue_t subscribeForVariableUpdateMessage(const lp_id_t localPoolId, + virtual ReturnValue_t subscribeForVariableUpdateMessage(lp_id_t localPoolId, object_id_t destinationObject, MessageQueueId_t targetQueueId, bool generateSnapshot) = 0; diff --git a/src/fsfw/housekeeping/AcceptsHkPacketsIF.h b/src/fsfw/housekeeping/AcceptsHkPacketsIF.h index 07882829..7648e7ed 100644 --- a/src/fsfw/housekeeping/AcceptsHkPacketsIF.h +++ b/src/fsfw/housekeeping/AcceptsHkPacketsIF.h @@ -1,12 +1,12 @@ #ifndef FRAMEWORK_HOUSEKEEPING_ACCEPTSHKPACKETSIF_H_ #define FRAMEWORK_HOUSEKEEPING_ACCEPTSHKPACKETSIF_H_ -#include "../ipc/MessageQueueMessageIF.h" +#include "fsfw/ipc/MessageQueueMessageIF.h" class AcceptsHkPacketsIF { public: - virtual ~AcceptsHkPacketsIF(){}; - virtual MessageQueueId_t getHkQueue() const = 0; + virtual ~AcceptsHkPacketsIF() = default; + [[nodiscard]] virtual MessageQueueId_t getHkQueue() const = 0; }; #endif /* FRAMEWORK_HOUSEKEEPING_ACCEPTSHKPACKETSIF_H_ */ diff --git a/src/fsfw/internalerror/InternalErrorReporter.cpp b/src/fsfw/internalerror/InternalErrorReporter.cpp index fa16ec3f..12c5aaeb 100644 --- a/src/fsfw/internalerror/InternalErrorReporter.cpp +++ b/src/fsfw/internalerror/InternalErrorReporter.cpp @@ -129,8 +129,9 @@ ReturnValue_t InternalErrorReporter::initializeLocalDataPool(localpool::DataPool localDataPoolMap.emplace(errorPoolIds::TM_HITS, new PoolEntry()); localDataPoolMap.emplace(errorPoolIds::QUEUE_HITS, new PoolEntry()); localDataPoolMap.emplace(errorPoolIds::STORE_HITS, new PoolEntry()); - poolManager.subscribeForPeriodicPacket(internalErrorSid, false, getPeriodicOperationFrequency(), - true); + poolManager.subscribeForDiagPeriodicPacket(subdp::DiagnosticsHkPeriodicParams( + internalErrorSid, false, + static_cast(getPeriodicOperationFrequency()) / static_cast(1000.0))); internalErrorDataset.setValidity(true, true); return HasReturnvaluesIF::RETURN_OK; } diff --git a/src/fsfw/ipc/MessageQueueBase.h b/src/fsfw/ipc/MessageQueueBase.h index 9c05b1a2..c4de8eeb 100644 --- a/src/fsfw/ipc/MessageQueueBase.h +++ b/src/fsfw/ipc/MessageQueueBase.h @@ -17,18 +17,18 @@ class MessageQueueBase : public MessageQueueIF { [[nodiscard]] MessageQueueId_t getDefaultDestination() const override; [[nodiscard]] bool isDefaultDestinationSet() const override; ReturnValue_t sendMessage(MessageQueueId_t sendTo, MessageQueueMessageIF* message, - bool ignoreFault) override; + bool ignoreFault) override; ReturnValue_t sendToDefault(MessageQueueMessageIF* message) override; ReturnValue_t reply(MessageQueueMessageIF* message) override; ReturnValue_t receiveMessage(MessageQueueMessageIF* message, - MessageQueueId_t* receivedFrom) override; + MessageQueueId_t* receivedFrom) override; ReturnValue_t sendToDefaultFrom(MessageQueueMessageIF* message, MessageQueueId_t sentFrom, - bool ignoreFault = false) override; + bool ignoreFault = false) override; // OSAL specific, forward the abstract function ReturnValue_t receiveMessage(MessageQueueMessageIF* message) override = 0; ReturnValue_t sendMessageFrom(MessageQueueId_t sendTo, MessageQueueMessageIF* message, - MessageQueueId_t sentFrom, bool ignoreFault = false) override = 0; + MessageQueueId_t sentFrom, bool ignoreFault = false) override = 0; protected: MessageQueueId_t id = MessageQueueIF::NO_QUEUE; diff --git a/src/fsfw/ipc/MessageQueueMessage.cpp b/src/fsfw/ipc/MessageQueueMessage.cpp index 6899915a..6e841c7f 100644 --- a/src/fsfw/ipc/MessageQueueMessage.cpp +++ b/src/fsfw/ipc/MessageQueueMessage.cpp @@ -10,10 +10,10 @@ MessageQueueMessage::MessageQueueMessage() : messageSize(getMinimumMessageSize() } MessageQueueMessage::MessageQueueMessage(uint8_t* data, size_t size) - : messageSize(this->HEADER_SIZE + size) { - if (size <= this->MAX_DATA_SIZE) { - memcpy(this->getData(), data, size); - this->messageSize = this->HEADER_SIZE + size; + : messageSize(MessageQueueMessage::HEADER_SIZE + size) { + if (size <= MessageQueueMessage::MAX_DATA_SIZE) { + std::memcpy(internalBuffer + MessageQueueMessage::HEADER_SIZE, data, size); + this->messageSize = MessageQueueMessage::HEADER_SIZE + size; } else { #if FSFW_CPP_OSTREAM_ENABLED == 1 sif::warning << "MessageQueueMessage: Passed size larger than maximum" @@ -21,21 +21,23 @@ MessageQueueMessage::MessageQueueMessage(uint8_t* data, size_t size) << std::endl; #endif memset(this->internalBuffer, 0, sizeof(this->internalBuffer)); - this->messageSize = this->HEADER_SIZE; + this->messageSize = MessageQueueMessage::HEADER_SIZE; } } -MessageQueueMessage::~MessageQueueMessage() {} +MessageQueueMessage::~MessageQueueMessage() = default; const uint8_t* MessageQueueMessage::getBuffer() const { return this->internalBuffer; } uint8_t* MessageQueueMessage::getBuffer() { return this->internalBuffer; } const uint8_t* MessageQueueMessage::getData() const { - return this->internalBuffer + this->HEADER_SIZE; + return this->internalBuffer + MessageQueueMessage::HEADER_SIZE; } -uint8_t* MessageQueueMessage::getData() { return this->internalBuffer + this->HEADER_SIZE; } +uint8_t* MessageQueueMessage::getData() { + return this->internalBuffer + MessageQueueMessage::HEADER_SIZE; +} MessageQueueId_t MessageQueueMessage::getSender() const { MessageQueueId_t temp_id; @@ -58,14 +60,22 @@ void MessageQueueMessage::print(bool printWholeMessage) { } } -void MessageQueueMessage::clear() { memset(this->getBuffer(), 0, this->MAX_MESSAGE_SIZE); } +void MessageQueueMessage::clear() { + memset(this->getBuffer(), 0, MessageQueueMessage::MAX_MESSAGE_SIZE); +} size_t MessageQueueMessage::getMessageSize() const { return this->messageSize; } -void MessageQueueMessage::setMessageSize(size_t messageSize) { this->messageSize = messageSize; } +void MessageQueueMessage::setMessageSize(size_t messageSize_) { this->messageSize = messageSize_; } -size_t MessageQueueMessage::getMinimumMessageSize() const { return this->MIN_MESSAGE_SIZE; } +size_t MessageQueueMessage::getMinimumMessageSize() const { + return MessageQueueMessage::MIN_MESSAGE_SIZE; +} -size_t MessageQueueMessage::getMaximumMessageSize() const { return this->MAX_MESSAGE_SIZE; } +size_t MessageQueueMessage::getMaximumMessageSize() const { + return MessageQueueMessage::MAX_MESSAGE_SIZE; +} -size_t MessageQueueMessage::getMaximumDataSize() const { return this->MAX_DATA_SIZE; } +size_t MessageQueueMessage::getMaximumDataSize() const { + return MessageQueueMessage::MAX_DATA_SIZE; +} diff --git a/src/fsfw/ipc/MessageQueueMessage.h b/src/fsfw/ipc/MessageQueueMessage.h index 30e50ffe..a3d596f1 100644 --- a/src/fsfw/ipc/MessageQueueMessage.h +++ b/src/fsfw/ipc/MessageQueueMessage.h @@ -25,6 +25,30 @@ */ class MessageQueueMessage : public MessageQueueMessageIF { public: + /** + * @brief This constant defines the maximum size of the data content, + * excluding the header. + * @details + * It may be changed if necessary, but in general should be kept + * as small as possible. + */ + static const size_t MAX_DATA_SIZE = 24; + /** + * @brief This constant defines the maximum total size in bytes + * of a sent message. + * @details + * It is the sum of the maximum data and the header size. Be aware that + * this constant is used to define the buffer sizes for every message + * queue in the system. So, a change here may have significant impact on + * the required resources. + */ + static constexpr size_t MAX_MESSAGE_SIZE = MAX_DATA_SIZE + HEADER_SIZE; + /** + * @brief Defines the minimum size of a message where only the + * header is included + */ + static constexpr size_t MIN_MESSAGE_SIZE = HEADER_SIZE; + /** * @brief The class is initialized empty with this constructor. * @details @@ -50,59 +74,12 @@ class MessageQueueMessage : public MessageQueueMessageIF { * @brief As no memory is allocated in this class, * the destructor is empty. */ - virtual ~MessageQueueMessage(); + ~MessageQueueMessage() override; - /** - * @brief The size information of each message is stored in - * this attribute. - * @details - * It is public to simplify usage and to allow for passing the size - * address as a pointer. Care must be taken when inheriting from this class, - * as every child class is responsible for managing the size information by - * itself. When using the class to receive a message, the size information - * is updated automatically. - * - * Please note that the minimum size is limited by the size of the header - * while the maximum size is limited by the maximum allowed message size. - */ - size_t messageSize; - /** - * @brief This constant defines the maximum size of the data content, - * excluding the header. - * @details - * It may be changed if necessary, but in general should be kept - * as small as possible. - */ - static const size_t MAX_DATA_SIZE = 24; - - /** - * @brief This constant defines the maximum total size in bytes - * of a sent message. - * @details - * It is the sum of the maximum data and the header size. Be aware that - * this constant is used to define the buffer sizes for every message - * queue in the system. So, a change here may have significant impact on - * the required resources. - */ - static constexpr size_t MAX_MESSAGE_SIZE = MAX_DATA_SIZE + HEADER_SIZE; - /** - * @brief Defines the minimum size of a message where only the - * header is included - */ - static constexpr size_t MIN_MESSAGE_SIZE = HEADER_SIZE; - - private: - /** - * @brief This is the internal buffer that contains the - * actual message data. - */ - uint8_t internalBuffer[MAX_MESSAGE_SIZE]; - - public: /** * @brief This method is used to get the complete data of the message. */ - const uint8_t* getBuffer() const override; + [[nodiscard]] const uint8_t* getBuffer() const override; /** * @brief This method is used to get the complete data of the message. */ @@ -112,7 +89,7 @@ class MessageQueueMessage : public MessageQueueMessageIF { * @details * It shall be used by child classes to add data at the right position. */ - const uint8_t* getData() const override; + [[nodiscard]] const uint8_t* getData() const override; /** * @brief This method is used to fetch the data content of the message. * @details @@ -123,7 +100,7 @@ class MessageQueueMessage : public MessageQueueMessageIF { * @brief This method is used to extract the sender's message * queue id information from a received message. */ - MessageQueueId_t getSender() const override; + [[nodiscard]] MessageQueueId_t getSender() const override; /** * @brief With this method, the whole content * and the message size is set to zero. @@ -138,16 +115,40 @@ class MessageQueueMessage : public MessageQueueMessageIF { */ void setSender(MessageQueueId_t setId) override; - virtual size_t getMessageSize() const override; - virtual void setMessageSize(size_t messageSize) override; - virtual size_t getMinimumMessageSize() const override; - virtual size_t getMaximumMessageSize() const override; - virtual size_t getMaximumDataSize() const override; + [[nodiscard]] size_t getMessageSize() const override; + void setMessageSize(size_t messageSize) override; + [[nodiscard]] size_t getMinimumMessageSize() const override; + [[nodiscard]] size_t getMaximumMessageSize() const override; + [[nodiscard]] size_t getMaximumDataSize() const override; /** * @brief This is a debug method that prints the content. */ void print(bool printWholeMessage); + + /** + * TODO: This really should not be public. If it should be possible to pass size address as a + * pointer, add a getter function returning a const reference to the size + * @brief The size information of each message is stored in + * this attribute. + * @details + * It is public to simplify usage and to allow for passing the size + * address as a pointer. Care must be taken when inheriting from this class, + * as every child class is responsible for managing the size information by + * itself. When using the class to receive a message, the size information + * is updated automatically. + * + * Please note that the minimum size is limited by the size of the header + * while the maximum size is limited by the maximum allowed message size. + */ + size_t messageSize; + + private: + /** + * @brief This is the internal buffer that contains the + * actual message data. + */ + uint8_t internalBuffer[MAX_MESSAGE_SIZE] = {}; }; #endif /* FSFW_IPC_MESSAGEQUEUEMESSAGE_H_ */ diff --git a/src/fsfw/ipc/MessageQueueMessageIF.h b/src/fsfw/ipc/MessageQueueMessageIF.h index dae28926..300a90ab 100644 --- a/src/fsfw/ipc/MessageQueueMessageIF.h +++ b/src/fsfw/ipc/MessageQueueMessageIF.h @@ -14,7 +14,7 @@ class MessageQueueMessageIF { */ static const size_t HEADER_SIZE = sizeof(MessageQueueId_t); - virtual ~MessageQueueMessageIF(){}; + virtual ~MessageQueueMessageIF() = default; /** * @brief With this method, the whole content and the message @@ -29,7 +29,7 @@ class MessageQueueMessageIF { * @brief Get read-only pointer to the complete data of the message. * @return */ - virtual const uint8_t* getBuffer() const = 0; + [[nodiscard]] virtual const uint8_t* getBuffer() const = 0; /** * @brief This method is used to get the complete data of the message. @@ -48,14 +48,14 @@ class MessageQueueMessageIF { * @brief This method is used to extract the sender's message queue id * information from a received message. */ - virtual MessageQueueId_t getSender() const = 0; + [[nodiscard]] virtual MessageQueueId_t getSender() const = 0; /** * @brief This method is used to fetch the data content of the message. * @details * It shall be used by child classes to add data at the right position. */ - virtual const uint8_t* getData() const = 0; + [[nodiscard]] virtual const uint8_t* getData() const = 0; /** * @brief This method is used to fetch the data content of the message. * @details @@ -67,12 +67,28 @@ class MessageQueueMessageIF { * Get constant message size of current message implementation. * @return */ - virtual size_t getMessageSize() const = 0; + [[nodiscard]] virtual size_t getMessageSize() const = 0; + /** + * Sets the current message size of a given message + * @param messageSize + */ virtual void setMessageSize(size_t messageSize) = 0; - virtual size_t getMinimumMessageSize() const = 0; - virtual size_t getMaximumMessageSize() const = 0; - virtual size_t getMaximumDataSize() const = 0; + /** + * Returns the smallest possible message size, including any headers + * @return + */ + [[nodiscard]] virtual size_t getMinimumMessageSize() const = 0; + /** + * Returns the largest possible message size, including any headers + * @return + */ + [[nodiscard]] virtual size_t getMaximumMessageSize() const = 0; + /** + * Returns the largest possible data size without any headers + * @return + */ + [[nodiscard]] virtual size_t getMaximumDataSize() const = 0; }; #endif /* FRAMEWORK_IPC_MESSAGEQUEUEMESSAGEIF_H_ */ diff --git a/src/fsfw/osal/linux/Clock.cpp b/src/fsfw/osal/linux/Clock.cpp index 00596dab..a173bbc5 100644 --- a/src/fsfw/osal/linux/Clock.cpp +++ b/src/fsfw/osal/linux/Clock.cpp @@ -2,9 +2,9 @@ #include #include -#include #include +#include #include #include "fsfw/ipc/MutexGuard.h" diff --git a/src/fsfw/serialize/SerializeIF.h b/src/fsfw/serialize/SerializeIF.h index 40e19530..136bd419 100644 --- a/src/fsfw/serialize/SerializeIF.h +++ b/src/fsfw/serialize/SerializeIF.h @@ -64,7 +64,7 @@ class SerializeIF { /** * Forwards to regular @serialize call with big (network) endianness */ - virtual ReturnValue_t serializeBe(uint8_t** buffer, size_t* size, size_t maxSize) { + virtual ReturnValue_t serializeBe(uint8_t **buffer, size_t *size, size_t maxSize) { return serialize(buffer, size, maxSize, SerializeIF::Endianness::NETWORK); } /** @@ -105,7 +105,7 @@ class SerializeIF { /** * Forwards to regular @deSerialize call with big (network) endianness */ - virtual ReturnValue_t deSerializeBe(const uint8_t** buffer, size_t* size) { + virtual ReturnValue_t deSerializeBe(const uint8_t **buffer, size_t *size) { return deSerialize(buffer, size, SerializeIF::Endianness::NETWORK); } /** diff --git a/src/fsfw/timemanager/CCSDSTime.h b/src/fsfw/timemanager/CCSDSTime.h index f2841d0c..3f4361f8 100644 --- a/src/fsfw/timemanager/CCSDSTime.h +++ b/src/fsfw/timemanager/CCSDSTime.h @@ -6,9 +6,9 @@ #include #include -#include "fsfw/returnvalues/HasReturnvaluesIF.h" #include "Clock.h" #include "clockDefinitions.h" +#include "fsfw/returnvalues/HasReturnvaluesIF.h" bool operator<(const timeval &lhs, const timeval &rhs); bool operator<=(const timeval &lhs, const timeval &rhs); diff --git a/src/fsfw/timemanager/TimeMessage.h b/src/fsfw/timemanager/TimeMessage.h index c5eed13f..62833036 100644 --- a/src/fsfw/timemanager/TimeMessage.h +++ b/src/fsfw/timemanager/TimeMessage.h @@ -3,8 +3,8 @@ #include -#include "fsfw/ipc/MessageQueueMessage.h" #include "Clock.h" +#include "fsfw/ipc/MessageQueueMessage.h" class TimeMessage : public MessageQueueMessage { protected: diff --git a/src/fsfw/tmtcpacket/pus/tc/PusTcCreator.cpp b/src/fsfw/tmtcpacket/pus/tc/PusTcCreator.cpp index 992ec388..d6748619 100644 --- a/src/fsfw/tmtcpacket/pus/tc/PusTcCreator.cpp +++ b/src/fsfw/tmtcpacket/pus/tc/PusTcCreator.cpp @@ -101,7 +101,7 @@ ReturnValue_t PusTcCreator::setRawUserData(const uint8_t *data, size_t len) { return HasReturnvaluesIF::RETURN_OK; } -ReturnValue_t PusTcCreator::setSerializableUserData(SerializeIF& serializable) { +ReturnValue_t PusTcCreator::setSerializableUserData(SerializeIF &serializable) { // TODO: Check length field? pusParams.dataWrapper.setSerializable(serializable); updateSpLengthField(); diff --git a/src/fsfw/tmtcpacket/pus/tc/PusTcCreator.h b/src/fsfw/tmtcpacket/pus/tc/PusTcCreator.h index 90b32973..0f903e7b 100644 --- a/src/fsfw/tmtcpacket/pus/tc/PusTcCreator.h +++ b/src/fsfw/tmtcpacket/pus/tc/PusTcCreator.h @@ -47,7 +47,7 @@ class PusTcCreator : public PusTcIF, public SerializeIF, public CustomUserDataIF [[nodiscard]] uint8_t getSubService() const override; [[nodiscard]] uint16_t getSourceId() const override; ReturnValue_t setRawUserData(const uint8_t *data, size_t len) override; - ReturnValue_t setSerializableUserData(SerializeIF& serializable) override; + ReturnValue_t setSerializableUserData(SerializeIF &serializable) override; private: ReturnValue_t serialize(uint8_t **buffer, size_t *size, size_t maxSize, diff --git a/src/fsfw/tmtcservices/TmSendHelper.cpp b/src/fsfw/tmtcservices/TmSendHelper.cpp index 2f57433d..7b464ad8 100644 --- a/src/fsfw/tmtcservices/TmSendHelper.cpp +++ b/src/fsfw/tmtcservices/TmSendHelper.cpp @@ -2,16 +2,17 @@ #include "fsfw/ipc/MessageQueueSenderIF.h" -TmSendHelper::TmSendHelper(MessageQueueIF* queue, InternalErrorReporterIF *reporter, MessageQueueId_t tmtcMsgDest) +TmSendHelper::TmSendHelper(MessageQueueIF *queue, InternalErrorReporterIF *reporter, + MessageQueueId_t tmtcMsgDest) : tmtcMsgDest(tmtcMsgDest), queue(queue), errReporter(reporter) {} TmSendHelper::TmSendHelper(MessageQueueIF *queue, InternalErrorReporterIF *reporter) - : queue(queue), errReporter(reporter) {} + : queue(queue), errReporter(reporter) {} TmSendHelper::TmSendHelper(InternalErrorReporterIF *reporter) : errReporter(reporter) {} ReturnValue_t TmSendHelper::sendPacket(const store_address_t &storeId) { - if(queue == nullptr) { + if (queue == nullptr) { return HasReturnvaluesIF::RETURN_FAILED; } TmTcMessage message(storeId); diff --git a/src/fsfw/tmtcservices/TmSendHelper.h b/src/fsfw/tmtcservices/TmSendHelper.h index 7e11daad..4cb159da 100644 --- a/src/fsfw/tmtcservices/TmSendHelper.h +++ b/src/fsfw/tmtcservices/TmSendHelper.h @@ -9,11 +9,11 @@ class TmSendHelper { public: - TmSendHelper(MessageQueueIF* queue, InternalErrorReporterIF* reporter, MessageQueueId_t tmtcMsgDest); + TmSendHelper(MessageQueueIF* queue, InternalErrorReporterIF* reporter, + MessageQueueId_t tmtcMsgDest); TmSendHelper(MessageQueueIF* queue, InternalErrorReporterIF* reporter); explicit TmSendHelper(InternalErrorReporterIF* reporter); - void setMsgQueue(MessageQueueIF* queue); void setMsgDestination(MessageQueueId_t msgDest); void setInternalErrorReporter(InternalErrorReporterIF* reporter); diff --git a/src/fsfw/tmtcservices/TmStoreHelper.cpp b/src/fsfw/tmtcservices/TmStoreHelper.cpp index 87a530ef..eb538518 100644 --- a/src/fsfw/tmtcservices/TmStoreHelper.cpp +++ b/src/fsfw/tmtcservices/TmStoreHelper.cpp @@ -2,7 +2,7 @@ #include "TmTcMessage.h" -TmStoreHelper::TmStoreHelper(uint16_t defaultApid): tmStore(nullptr) { +TmStoreHelper::TmStoreHelper(uint16_t defaultApid) : tmStore(nullptr) { creator.setApid(defaultApid); } @@ -17,7 +17,6 @@ TmStoreHelper::TmStoreHelper(uint16_t defaultApid, StorageManagerIF& tmStore, creator.setTimeStamper(timeStamper); } - ReturnValue_t TmStoreHelper::preparePacket(uint8_t service, uint8_t subservice, uint16_t counter) { PusTmParams& params = creator.getParams(); params.secHeader.service = service; @@ -33,8 +32,8 @@ void TmStoreHelper::setTmStore(StorageManagerIF& store) { tmStore = &store; } const store_address_t& TmStoreHelper::getCurrentAddr() const { return currentAddr; } ReturnValue_t TmStoreHelper::deletePacket() { - ReturnValue_t result = tmStore->deleteData(currentAddr); - if(result == HasReturnvaluesIF::RETURN_OK) { + ReturnValue_t result = tmStore->deleteData(currentAddr); + if (result == HasReturnvaluesIF::RETURN_OK) { currentAddr = store_address_t::invalid(); } return result; diff --git a/src/fsfw/tmtcservices/TmStoreHelper.h b/src/fsfw/tmtcservices/TmStoreHelper.h index b253361e..3a868d97 100644 --- a/src/fsfw/tmtcservices/TmStoreHelper.h +++ b/src/fsfw/tmtcservices/TmStoreHelper.h @@ -30,7 +30,6 @@ class TmStoreHelper { ReturnValue_t setSourceDataRaw(const uint8_t* data, size_t len); ReturnValue_t setSourceDataSerializable(SerializeIF& serializable); - ReturnValue_t addPacketToStore(); ReturnValue_t deletePacket(); diff --git a/unittests/CatchFactory.cpp b/unittests/CatchFactory.cpp index 5dce8372..fdb5fd08 100644 --- a/unittests/CatchFactory.cpp +++ b/unittests/CatchFactory.cpp @@ -10,7 +10,6 @@ #include #include -#include "datapoollocal/LocalPoolOwnerBase.h" #include "mocks/HkReceiverMock.h" #include "tests/TestsConfig.h" @@ -34,8 +33,6 @@ void Factory::produceFrameworkObjects(void* args) { new EventManager(objects::EVENT_MANAGER); new HealthTable(objects::HEALTH_TABLE); new InternalErrorReporter(objects::INTERNAL_ERROR_REPORTER); - - new LocalPoolOwnerBase(objects::TEST_LOCAL_POOL_OWNER_BASE); new HkReceiverMock(objects::HK_RECEIVER_MOCK); { @@ -54,6 +51,9 @@ void Factory::produceFrameworkObjects(void* args) { } } +// TODO: Our tests, and the code base in general should really not depend on some arbitrary function +// like this. Instead, this should be more like a general struct containing all important +// object IDs which are then explicitely passed in the object constructor void Factory::setStaticFrameworkObjectIds() { PusServiceBase::packetSource = objects::NO_OBJECT; PusServiceBase::packetDestination = objects::NO_OBJECT; @@ -66,7 +66,8 @@ void Factory::setStaticFrameworkObjectIds() { DeviceHandlerBase::powerSwitcherId = objects::NO_OBJECT; DeviceHandlerBase::rawDataReceiverId = objects::NO_OBJECT; - LocalDataPoolManager::defaultHkDestination = objects::HK_RECEIVER_MOCK; + // TODO: Incredibly ugly, get rid of it + LocalDataPoolManager::defaultHkDestination = objects::NO_OBJECT; DeviceHandlerFailureIsolation::powerConfirmationId = objects::NO_OBJECT; } diff --git a/unittests/action/TestActionHelper.cpp b/unittests/action/TestActionHelper.cpp index dd252d88..952f4572 100644 --- a/unittests/action/TestActionHelper.cpp +++ b/unittests/action/TestActionHelper.cpp @@ -57,8 +57,7 @@ TEST_CASE("Action Helper", "[ActionHelper]") { step += 1; CHECK(testMqMock.wasMessageSent()); CommandMessage testMessage; - REQUIRE(testMqMock.receiveMessage(&testMessage) == - static_cast(HasReturnvaluesIF::RETURN_OK)); + REQUIRE(testMqMock.getNextSentMessage(testMessage) == HasReturnvaluesIF::RETURN_OK); REQUIRE(testMessage.getCommand() == static_cast(ActionMessage::STEP_FAILED)); REQUIRE(testMessage.getParameter() == static_cast(testActionId)); uint32_t parameter2 = ((uint32_t)step << 16) | (uint32_t)status; @@ -72,8 +71,7 @@ TEST_CASE("Action Helper", "[ActionHelper]") { actionHelper.finish(false, testMqMock.getId(), testActionId, status); CHECK(testMqMock.wasMessageSent()); CommandMessage testMessage; - REQUIRE(testMqMock.receiveMessage(&testMessage) == - static_cast(HasReturnvaluesIF::RETURN_OK)); + REQUIRE(testMqMock.getNextSentMessage(testMessage) == HasReturnvaluesIF::RETURN_OK); REQUIRE(testMessage.getCommand() == static_cast(ActionMessage::COMPLETION_FAILED)); REQUIRE(ActionMessage::getActionId(&testMessage) == testActionId); REQUIRE(ActionMessage::getReturnCode(&testMessage) == static_cast(status)); @@ -89,8 +87,7 @@ TEST_CASE("Action Helper", "[ActionHelper]") { REQUIRE(ipcStore->getData(toLongParamAddress).first == static_cast(StorageManagerIF::DATA_DOES_NOT_EXIST)); CommandMessage testMessage; - REQUIRE(testMqMock.receiveMessage(&testMessage) == - static_cast(HasReturnvaluesIF::RETURN_OK)); + REQUIRE(testMqMock.getNextSentMessage(testMessage) == HasReturnvaluesIF::RETURN_OK); REQUIRE(testMessage.getCommand() == static_cast(ActionMessage::STEP_FAILED)); REQUIRE(ActionMessage::getReturnCode(&testMessage) == 0xAFFE); REQUIRE(ActionMessage::getStep(&testMessage) == 0); @@ -102,8 +99,7 @@ TEST_CASE("Action Helper", "[ActionHelper]") { CHECK(not testDhMock.executeActionCalled); REQUIRE(actionHelper.handleActionMessage(&actionMessage) == retval::CATCH_OK); CommandMessage testMessage; - REQUIRE(testMqMock.receiveMessage(&testMessage) == - static_cast(HasReturnvaluesIF::RETURN_OK)); + REQUIRE(testMqMock.getNextSentMessage(testMessage) == HasReturnvaluesIF::RETURN_OK); REQUIRE(testMessage.getCommand() == static_cast(ActionMessage::STEP_FAILED)); REQUIRE(ActionMessage::getReturnCode(&testMessage) == static_cast(StorageManagerIF::ILLEGAL_STORAGE_ID)); diff --git a/unittests/datapoollocal/CMakeLists.txt b/unittests/datapoollocal/CMakeLists.txt index bf465282..6b8946a2 100644 --- a/unittests/datapoollocal/CMakeLists.txt +++ b/unittests/datapoollocal/CMakeLists.txt @@ -1,7 +1,7 @@ target_sources(${FSFW_TEST_TGT} PRIVATE - LocalPoolVariableTest.cpp - LocalPoolVectorTest.cpp - DataSetTest.cpp - LocalPoolManagerTest.cpp + testLocalPoolVariable.cpp + testLocalPoolVector.cpp + testDataSet.cpp + testLocalPoolManager.cpp LocalPoolOwnerBase.cpp ) diff --git a/unittests/datapoollocal/LocalPoolManagerTest.cpp b/unittests/datapoollocal/LocalPoolManagerTest.cpp deleted file mode 100644 index 6d9f162c..00000000 --- a/unittests/datapoollocal/LocalPoolManagerTest.cpp +++ /dev/null @@ -1,413 +0,0 @@ -#include -#include -#include -#include -#include -#include -#include -#include - -#include -#include -#include - -#include "CatchDefinitions.h" -#include "LocalPoolOwnerBase.h" - -TEST_CASE("LocalPoolManagerTest", "[LocManTest]") { - LocalPoolOwnerBase* poolOwner = - ObjectManager::instance()->get(objects::TEST_LOCAL_POOL_OWNER_BASE); - REQUIRE(poolOwner != nullptr); - REQUIRE(poolOwner->initializeHkManager() == retval::CATCH_OK); - REQUIRE(poolOwner->initializeHkManagerAfterTaskCreation() == retval::CATCH_OK); - - MessageQueueMockBase* poolOwnerMock = poolOwner->getMockQueueHandle(); - REQUIRE(poolOwnerMock != nullptr); - - // MessageQueueIF* hkCommander = QueueFactory::instance()->createMessageQueue(); - CommandMessage messageSent; - uint8_t messagesSent = 0; - - SECTION("BasicTest") { - { - /* For code coverage, should not crash */ - LocalDataPoolManager manager(nullptr, nullptr); - } - auto owner = poolOwner->poolManager.getOwner(); - REQUIRE(owner != nullptr); - CHECK(owner->getObjectId() == objects::TEST_LOCAL_POOL_OWNER_BASE); - - /* Subscribe for message generation on update. */ - REQUIRE(poolOwner->subscribeWrapperSetUpdate() == retval::CATCH_OK); - /* Subscribe for an update message. */ - poolOwner->dataset.setChanged(true); - /* Now the update message should be generated. */ - REQUIRE(poolOwner->poolManager.performHkOperation() == retval::CATCH_OK); - REQUIRE(poolOwnerMock->wasMessageSent() == true); - - REQUIRE(poolOwnerMock->receiveMessage(&messageSent) == retval::CATCH_OK); - CHECK(messageSent.getCommand() == - static_cast(HousekeepingMessage::UPDATE_NOTIFICATION_SET)); - - /* Should have been reset. */ - CHECK(poolOwner->dataset.hasChanged() == false); - /* Set changed again, result should be the same. */ - poolOwner->dataset.setChanged(true); - REQUIRE(poolOwner->poolManager.performHkOperation() == retval::CATCH_OK); - - REQUIRE(poolOwnerMock->wasMessageSent(&messagesSent) == true); - CHECK(messagesSent == 1); - REQUIRE(poolOwnerMock->receiveMessage(&messageSent) == retval::CATCH_OK); - CHECK(messageSent.getCommand() == - static_cast(HousekeepingMessage::UPDATE_NOTIFICATION_SET)); - - /* Now subscribe for set update HK as well. */ - REQUIRE(poolOwner->subscribeWrapperSetUpdateHk() == retval::CATCH_OK); - poolOwner->dataset.setChanged(true); - REQUIRE(poolOwner->poolManager.performHkOperation() == retval::CATCH_OK); - REQUIRE(poolOwnerMock->wasMessageSent(&messagesSent) == true); - CHECK(messagesSent == 2); - /* first message sent should be the update notification, considering - the internal list is a vector checked in insertion order. */ - REQUIRE(poolOwnerMock->receiveMessage(&messageSent) == retval::CATCH_OK); - CHECK(messageSent.getCommand() == - static_cast(HousekeepingMessage::UPDATE_NOTIFICATION_SET)); - - REQUIRE(poolOwnerMock->receiveMessage(&messageSent) == retval::CATCH_OK); - CHECK(messageSent.getCommand() == static_cast(HousekeepingMessage::HK_REPORT)); - /* Clear message to avoid memory leak, our mock won't do it for us (yet) */ - CommandMessageCleaner::clearCommandMessage(&messageSent); - } - - SECTION("SetSnapshotUpdateTest") { - /* Set the variables in the set to certain values. These are checked later. */ - { - PoolReadGuard readHelper(&poolOwner->dataset); - REQUIRE(readHelper.getReadResult() == retval::CATCH_OK); - poolOwner->dataset.localPoolVarUint8.value = 5; - poolOwner->dataset.localPoolVarFloat.value = -12.242; - poolOwner->dataset.localPoolUint16Vec.value[0] = 2; - poolOwner->dataset.localPoolUint16Vec.value[1] = 32; - poolOwner->dataset.localPoolUint16Vec.value[2] = 42932; - } - - /* Subscribe for snapshot generation on update. */ - REQUIRE(poolOwner->subscribeWrapperSetUpdateSnapshot() == retval::CATCH_OK); - poolOwner->dataset.setChanged(true); - - /* Store current time, we are going to check the (approximate) time equality later */ - timeval now; - Clock::getClock_timeval(&now); - - /* Trigger generation of snapshot */ - REQUIRE(poolOwner->poolManager.performHkOperation() == retval::CATCH_OK); - REQUIRE(poolOwnerMock->wasMessageSent(&messagesSent) == true); - CHECK(messagesSent == 1); - REQUIRE(poolOwnerMock->receiveMessage(&messageSent) == retval::CATCH_OK); - /* Check that snapshot was generated */ - CHECK(messageSent.getCommand() == static_cast(HousekeepingMessage::UPDATE_SNAPSHOT_SET)); - /* Now we deserialize the snapshot into a new dataset instance */ - CCSDSTime::CDS_short cdsShort; - LocalPoolTestDataSet newSet; - HousekeepingSnapshot snapshot(&cdsShort, &newSet); - store_address_t storeId; - HousekeepingMessage::getUpdateSnapshotSetCommand(&messageSent, &storeId); - ConstAccessorPair accessorPair = tglob::getIpcStoreHandle()->getData(storeId); - REQUIRE(accessorPair.first == retval::CATCH_OK); - const uint8_t* readOnlyPtr = accessorPair.second.data(); - size_t sizeToDeserialize = accessorPair.second.size(); - CHECK(newSet.localPoolVarFloat.value == 0); - CHECK(newSet.localPoolVarUint8 == 0); - CHECK(newSet.localPoolUint16Vec.value[0] == 0); - CHECK(newSet.localPoolUint16Vec.value[1] == 0); - CHECK(newSet.localPoolUint16Vec.value[2] == 0); - /* Fill the dataset and timestamp */ - REQUIRE(snapshot.deSerialize(&readOnlyPtr, &sizeToDeserialize, - SerializeIF::Endianness::MACHINE) == retval::CATCH_OK); - /* Now we check that the snapshot is actually correct */ - CHECK(newSet.localPoolVarFloat.value == Catch::Approx(-12.242)); - CHECK(newSet.localPoolVarUint8 == 5); - CHECK(newSet.localPoolUint16Vec.value[0] == 2); - CHECK(newSet.localPoolUint16Vec.value[1] == 32); - CHECK(newSet.localPoolUint16Vec.value[2] == 42932); - - /* Now we check that both times are equal */ - timeval timeFromHK; - auto result = CCSDSTime::convertFromCDS(&timeFromHK, &cdsShort); - CHECK(result == HasReturnvaluesIF::RETURN_OK); - timeval difference = timeFromHK - now; - CHECK(timevalOperations::toDouble(difference) < 1.0); - } - - SECTION("VariableSnapshotTest") { - /* Acquire subscription interface */ - ProvidesDataPoolSubscriptionIF* subscriptionIF = poolOwner->getSubscriptionInterface(); - REQUIRE(subscriptionIF != nullptr); - - /* Subscribe for variable snapshot */ - REQUIRE(poolOwner->subscribeWrapperVariableSnapshot(lpool::uint8VarId) == retval::CATCH_OK); - auto poolVar = - dynamic_cast*>(poolOwner->getPoolObjectHandle(lpool::uint8VarId)); - REQUIRE(poolVar != nullptr); - - { - PoolReadGuard rg(poolVar); - CHECK(rg.getReadResult() == retval::CATCH_OK); - poolVar->value = 25; - } - - poolVar->setChanged(true); - /* Store current time, we are going to check the (approximate) time equality later */ - CCSDSTime::CDS_short timeCdsNow; - timeval now; - Clock::getClock_timeval(&now); - REQUIRE(poolOwner->poolManager.performHkOperation() == retval::CATCH_OK); - - /* Check update snapshot was sent. */ - REQUIRE(poolOwnerMock->wasMessageSent(&messagesSent) == true); - CHECK(messagesSent == 1); - - /* Should have been reset. */ - CHECK(poolVar->hasChanged() == false); - REQUIRE(poolOwnerMock->receiveMessage(&messageSent) == retval::CATCH_OK); - CHECK(messageSent.getCommand() == - static_cast(HousekeepingMessage::UPDATE_SNAPSHOT_VARIABLE)); - /* Now we deserialize the snapshot into a new dataset instance */ - CCSDSTime::CDS_short cdsShort; - lp_var_t varCopy = lp_var_t(lpool::uint8VarGpid); - HousekeepingSnapshot snapshot(&cdsShort, &varCopy); - store_address_t storeId; - HousekeepingMessage::getUpdateSnapshotVariableCommand(&messageSent, &storeId); - ConstAccessorPair accessorPair = tglob::getIpcStoreHandle()->getData(storeId); - REQUIRE(accessorPair.first == retval::CATCH_OK); - const uint8_t* readOnlyPtr = accessorPair.second.data(); - size_t sizeToDeserialize = accessorPair.second.size(); - CHECK(varCopy.value == 0); - /* Fill the dataset and timestamp */ - REQUIRE(snapshot.deSerialize(&readOnlyPtr, &sizeToDeserialize, - SerializeIF::Endianness::MACHINE) == retval::CATCH_OK); - CHECK(varCopy.value == 25); - - /* Now we check that both times are equal */ - timeval timeFromHK; - auto result = CCSDSTime::convertFromCDS(&timeFromHK, &cdsShort); - CHECK(result == HasReturnvaluesIF::RETURN_OK); - timeval difference = timeFromHK - now; - CHECK(timevalOperations::toDouble(difference) < 1.0); - } - - SECTION("VariableNotificationTest") { - /* Acquire subscription interface */ - ProvidesDataPoolSubscriptionIF* subscriptionIF = poolOwner->getSubscriptionInterface(); - REQUIRE(subscriptionIF != nullptr); - - /* Subscribe for variable update */ - REQUIRE(poolOwner->subscribeWrapperVariableUpdate(lpool::uint8VarId) == retval::CATCH_OK); - lp_var_t* poolVar = - dynamic_cast*>(poolOwner->getPoolObjectHandle(lpool::uint8VarId)); - REQUIRE(poolVar != nullptr); - poolVar->setChanged(true); - REQUIRE(poolVar->hasChanged() == true); - REQUIRE(poolOwner->poolManager.performHkOperation() == retval::CATCH_OK); - - /* Check update notification was sent. */ - REQUIRE(poolOwnerMock->wasMessageSent(&messagesSent) == true); - CHECK(messagesSent == 1); - /* Should have been reset. */ - CHECK(poolVar->hasChanged() == false); - REQUIRE(poolOwnerMock->receiveMessage(&messageSent) == retval::CATCH_OK); - CHECK(messageSent.getCommand() == - static_cast(HousekeepingMessage::UPDATE_NOTIFICATION_VARIABLE)); - /* Now subscribe for the dataset update (HK and update) again with subscription interface */ - REQUIRE(subscriptionIF->subscribeForSetUpdateMessage(lpool::testSetId, objects::NO_OBJECT, - objects::HK_RECEIVER_MOCK, - false) == retval::CATCH_OK); - REQUIRE(poolOwner->subscribeWrapperSetUpdateHk() == retval::CATCH_OK); - - poolOwner->dataset.setChanged(true); - REQUIRE(poolOwner->poolManager.performHkOperation() == retval::CATCH_OK); - /* Now two messages should be sent. */ - REQUIRE(poolOwnerMock->wasMessageSent(&messagesSent) == true); - CHECK(messagesSent == 2); - poolOwnerMock->clearMessages(true); - - poolOwner->dataset.setChanged(true); - poolVar->setChanged(true); - REQUIRE(poolOwner->poolManager.performHkOperation() == retval::CATCH_OK); - /* Now three messages should be sent. */ - REQUIRE(poolOwnerMock->wasMessageSent(&messagesSent) == true); - CHECK(messagesSent == 3); - REQUIRE(poolOwnerMock->receiveMessage(&messageSent) == retval::CATCH_OK); - CHECK(messageSent.getCommand() == - static_cast(HousekeepingMessage::UPDATE_NOTIFICATION_VARIABLE)); - REQUIRE(poolOwnerMock->receiveMessage(&messageSent) == retval::CATCH_OK); - CHECK(messageSent.getCommand() == - static_cast(HousekeepingMessage::UPDATE_NOTIFICATION_SET)); - REQUIRE(poolOwnerMock->receiveMessage(&messageSent) == retval::CATCH_OK); - CHECK(messageSent.getCommand() == static_cast(HousekeepingMessage::HK_REPORT)); - CommandMessageCleaner::clearCommandMessage(&messageSent); - REQUIRE(poolOwnerMock->receiveMessage(&messageSent) == static_cast(MessageQueueIF::EMPTY)); - } - - SECTION("PeriodicHKAndMessaging") { - /* Now we subcribe for a HK periodic generation. Even when it's difficult to simulate - the temporal behaviour correctly the HK manager should generate a HK packet - immediately and the periodic helper depends on HK op function calls anyway instead of - using the clock, so we could also just call performHkOperation multiple times */ - REQUIRE(poolOwner->subscribePeriodicHk(true) == retval::CATCH_OK); - REQUIRE(poolOwner->poolManager.performHkOperation() == retval::CATCH_OK); - /* Now HK packet should be sent as message immediately. */ - REQUIRE(poolOwnerMock->wasMessageSent(&messagesSent) == true); - CHECK(messagesSent == 1); - CHECK(poolOwnerMock->popMessage() == retval::CATCH_OK); - - LocalPoolDataSetBase* setHandle = poolOwner->getDataSetHandle(lpool::testSid); - REQUIRE(setHandle != nullptr); - CHECK(poolOwner->poolManager.generateHousekeepingPacket(lpool::testSid, setHandle, false) == - retval::CATCH_OK); - REQUIRE(poolOwnerMock->wasMessageSent(&messagesSent) == true); - CHECK(messagesSent == 1); - CHECK(poolOwnerMock->popMessage() == retval::CATCH_OK); - - CHECK(setHandle->getReportingEnabled() == true); - CommandMessage hkCmd; - HousekeepingMessage::setToggleReportingCommand(&hkCmd, lpool::testSid, false, false); - CHECK(poolOwner->poolManager.handleHousekeepingMessage(&hkCmd) == retval::CATCH_OK); - CHECK(setHandle->getReportingEnabled() == false); - REQUIRE(poolOwnerMock->wasMessageSent(&messagesSent) == true); - CHECK(messagesSent == 1); - CHECK(poolOwnerMock->popMessage() == retval::CATCH_OK); - - HousekeepingMessage::setToggleReportingCommand(&hkCmd, lpool::testSid, true, false); - CHECK(poolOwner->poolManager.handleHousekeepingMessage(&hkCmd) == retval::CATCH_OK); - CHECK(setHandle->getReportingEnabled() == true); - REQUIRE(poolOwnerMock->wasMessageSent(&messagesSent) == true); - CHECK(poolOwnerMock->popMessage() == retval::CATCH_OK); - - HousekeepingMessage::setToggleReportingCommand(&hkCmd, lpool::testSid, false, false); - CHECK(poolOwner->poolManager.handleHousekeepingMessage(&hkCmd) == retval::CATCH_OK); - CHECK(setHandle->getReportingEnabled() == false); - REQUIRE(poolOwnerMock->wasMessageSent(&messagesSent) == true); - CHECK(poolOwnerMock->popMessage() == retval::CATCH_OK); - - HousekeepingMessage::setCollectionIntervalModificationCommand(&hkCmd, lpool::testSid, 0.4, - false); - CHECK(poolOwner->poolManager.handleHousekeepingMessage(&hkCmd) == retval::CATCH_OK); - /* For non-diagnostics and a specified minimum frequency of 0.2 seconds, the - resulting collection interval should be 1.0 second */ - CHECK(poolOwner->dataset.getCollectionInterval() == 1.0); - REQUIRE(poolOwnerMock->wasMessageSent(&messagesSent) == true); - CHECK(messagesSent == 1); - CHECK(poolOwnerMock->popMessage() == retval::CATCH_OK); - - HousekeepingMessage::setStructureReportingCommand(&hkCmd, lpool::testSid, false); - REQUIRE(poolOwner->poolManager.performHkOperation() == retval::CATCH_OK); - CHECK(poolOwner->poolManager.handleHousekeepingMessage(&hkCmd) == retval::CATCH_OK); - /* Now HK packet should be sent as message. */ - REQUIRE(poolOwnerMock->wasMessageSent(&messagesSent) == true); - CHECK(messagesSent == 1); - CHECK(poolOwnerMock->popMessage() == retval::CATCH_OK); - - HousekeepingMessage::setOneShotReportCommand(&hkCmd, lpool::testSid, false); - CHECK(poolOwner->poolManager.handleHousekeepingMessage(&hkCmd) == retval::CATCH_OK); - REQUIRE(poolOwnerMock->wasMessageSent(&messagesSent) == true); - CHECK(messagesSent == 1); - CHECK(poolOwnerMock->popMessage() == retval::CATCH_OK); - - HousekeepingMessage::setUpdateNotificationSetCommand(&hkCmd, lpool::testSid); - sid_t sidToCheck; - store_address_t storeId; - CHECK(poolOwner->poolManager.handleHousekeepingMessage(&hkCmd) == retval::CATCH_OK); - CHECK(poolOwner->changedDataSetCallbackWasCalled(sidToCheck, storeId) == true); - CHECK(sidToCheck == lpool::testSid); - - /* Now we test the handling is the dataset is set to diagnostic */ - poolOwner->dataset.setDiagnostic(true); - - HousekeepingMessage::setStructureReportingCommand(&hkCmd, lpool::testSid, false); - CHECK(poolOwner->poolManager.handleHousekeepingMessage(&hkCmd) == - static_cast(LocalDataPoolManager::WRONG_HK_PACKET_TYPE)); - /* We still expect a failure message being sent */ - REQUIRE(poolOwnerMock->wasMessageSent(&messagesSent) == true); - CHECK(messagesSent == 1); - CHECK(poolOwnerMock->popMessage() == retval::CATCH_OK); - - HousekeepingMessage::setCollectionIntervalModificationCommand(&hkCmd, lpool::testSid, 0.4, - false); - CHECK(poolOwner->poolManager.handleHousekeepingMessage(&hkCmd) == - static_cast(LocalDataPoolManager::WRONG_HK_PACKET_TYPE)); - REQUIRE(poolOwnerMock->wasMessageSent(&messagesSent) == true); - CHECK(messagesSent == 1); - CHECK(poolOwnerMock->popMessage() == retval::CATCH_OK); - - HousekeepingMessage::setStructureReportingCommand(&hkCmd, lpool::testSid, false); - CHECK(poolOwner->poolManager.handleHousekeepingMessage(&hkCmd) == - static_cast(LocalDataPoolManager::WRONG_HK_PACKET_TYPE)); - REQUIRE(poolOwnerMock->wasMessageSent(&messagesSent) == true); - CHECK(messagesSent == 1); - CHECK(poolOwnerMock->popMessage() == retval::CATCH_OK); - - HousekeepingMessage::setStructureReportingCommand(&hkCmd, lpool::testSid, true); - CHECK(poolOwner->poolManager.handleHousekeepingMessage(&hkCmd) == retval::CATCH_OK); - REQUIRE(poolOwnerMock->wasMessageSent(&messagesSent) == true); - CHECK(messagesSent == 1); - CHECK(poolOwnerMock->popMessage() == retval::CATCH_OK); - - HousekeepingMessage::setCollectionIntervalModificationCommand(&hkCmd, lpool::testSid, 0.4, - true); - CHECK(poolOwner->poolManager.handleHousekeepingMessage(&hkCmd) == retval::CATCH_OK); - REQUIRE(poolOwnerMock->wasMessageSent(&messagesSent) == true); - CHECK(messagesSent == 1); - CHECK(poolOwnerMock->popMessage() == retval::CATCH_OK); - - HousekeepingMessage::setToggleReportingCommand(&hkCmd, lpool::testSid, true, true); - CHECK(poolOwner->poolManager.handleHousekeepingMessage(&hkCmd) == retval::CATCH_OK); - REQUIRE(poolOwnerMock->wasMessageSent(&messagesSent) == true); - CHECK(messagesSent == 1); - CHECK(poolOwnerMock->popMessage() == retval::CATCH_OK); - - HousekeepingMessage::setToggleReportingCommand(&hkCmd, lpool::testSid, false, true); - CHECK(poolOwner->poolManager.handleHousekeepingMessage(&hkCmd) == retval::CATCH_OK); - REQUIRE(poolOwnerMock->wasMessageSent(&messagesSent) == true); - CHECK(messagesSent == 1); - CHECK(poolOwnerMock->popMessage() == retval::CATCH_OK); - - HousekeepingMessage::setOneShotReportCommand(&hkCmd, lpool::testSid, false); - CHECK(poolOwner->poolManager.handleHousekeepingMessage(&hkCmd) == - static_cast(LocalDataPoolManager::WRONG_HK_PACKET_TYPE)); - REQUIRE(poolOwnerMock->wasMessageSent(&messagesSent) == true); - CHECK(messagesSent == 1); - CHECK(poolOwnerMock->popMessage() == retval::CATCH_OK); - - HousekeepingMessage::setOneShotReportCommand(&hkCmd, lpool::testSid, true); - CHECK(poolOwner->poolManager.handleHousekeepingMessage(&hkCmd) == retval::CATCH_OK); - REQUIRE(poolOwnerMock->wasMessageSent(&messagesSent) == true); - CHECK(messagesSent == 1); - CHECK(poolOwnerMock->popMessage() == retval::CATCH_OK); - - HousekeepingMessage::setUpdateNotificationVariableCommand(&hkCmd, lpool::uint8VarGpid); - gp_id_t gpidToCheck; - CHECK(poolOwner->poolManager.handleHousekeepingMessage(&hkCmd) == retval::CATCH_OK); - CHECK(poolOwner->changedVariableCallbackWasCalled(gpidToCheck, storeId) == true); - CHECK(gpidToCheck == lpool::uint8VarGpid); - - HousekeepingMessage::setUpdateSnapshotSetCommand(&hkCmd, lpool::testSid, - store_address_t::invalid()); - CHECK(poolOwner->poolManager.handleHousekeepingMessage(&hkCmd) == retval::CATCH_OK); - CHECK(poolOwner->changedDataSetCallbackWasCalled(sidToCheck, storeId) == true); - CHECK(sidToCheck == lpool::testSid); - - HousekeepingMessage::setUpdateSnapshotVariableCommand(&hkCmd, lpool::uint8VarGpid, - store_address_t::invalid()); - CHECK(poolOwner->poolManager.handleHousekeepingMessage(&hkCmd) == retval::CATCH_OK); - CHECK(poolOwner->changedVariableCallbackWasCalled(gpidToCheck, storeId) == true); - CHECK(gpidToCheck == lpool::uint8VarGpid); - - poolOwner->poolManager.printPoolEntry(lpool::uint8VarId); - } - - /* we need to reset the subscription list because the pool owner - is a global object. */ - CHECK(poolOwner->reset() == retval::CATCH_OK); - poolOwnerMock->clearMessages(true); -} diff --git a/unittests/datapoollocal/DataSetTest.cpp b/unittests/datapoollocal/testDataSet.cpp similarity index 93% rename from unittests/datapoollocal/DataSetTest.cpp rename to unittests/datapoollocal/testDataSet.cpp index c9f023ef..62bf59bb 100644 --- a/unittests/datapoollocal/DataSetTest.cpp +++ b/unittests/datapoollocal/testDataSet.cpp @@ -13,11 +13,10 @@ #include "tests/TestsConfig.h" TEST_CASE("DataSetTest", "[DataSetTest]") { - LocalPoolOwnerBase* poolOwner = - ObjectManager::instance()->get(objects::TEST_LOCAL_POOL_OWNER_BASE); - REQUIRE(poolOwner != nullptr); - REQUIRE(poolOwner->initializeHkManager() == retval::CATCH_OK); - REQUIRE(poolOwner->initializeHkManagerAfterTaskCreation() == retval::CATCH_OK); + auto queue = MessageQueueMockBase(); + LocalPoolOwnerBase poolOwner(queue, objects::TEST_LOCAL_POOL_OWNER_BASE); + REQUIRE(poolOwner.initializeHkManager() == retval::CATCH_OK); + REQUIRE(poolOwner.initializeHkManagerAfterTaskCreation() == retval::CATCH_OK); LocalPoolStaticTestDataSet localSet; SECTION("BasicTest") { @@ -30,9 +29,9 @@ TEST_CASE("DataSetTest", "[DataSetTest]") { size_t maxSize = localSet.getLocalPoolIdsSerializedSize(true); uint8_t localPoolIdBuff[maxSize]; /* Skip size field */ - lp_id_t* lpIds = reinterpret_cast(localPoolIdBuff + 1); + auto* lpIds = reinterpret_cast(localPoolIdBuff + 1); size_t serSize = 0; - uint8_t* localPoolIdBuffPtr = reinterpret_cast(localPoolIdBuff); + auto* localPoolIdBuffPtr = reinterpret_cast(localPoolIdBuff); /* Test local pool ID serialization */ CHECK(localSet.serializeLocalPoolIds(&localPoolIdBuffPtr, &serSize, maxSize, @@ -200,7 +199,7 @@ TEST_CASE("DataSetTest", "[DataSetTest]") { } /* Common fault test cases */ - LocalPoolObjectBase* variableHandle = poolOwner->getPoolObjectHandle(lpool::uint32VarId); + LocalPoolObjectBase* variableHandle = poolOwner.getPoolObjectHandle(lpool::uint32VarId); CHECK(variableHandle != nullptr); CHECK(localSet.registerVariable(variableHandle) == static_cast(DataSetIF::DATA_SET_FULL)); variableHandle = nullptr; @@ -209,7 +208,7 @@ TEST_CASE("DataSetTest", "[DataSetTest]") { } SECTION("MorePoolVariables") { - LocalDataSet set(poolOwner, 2, 10); + LocalDataSet set(&poolOwner, 2, 10); /* Register same variables again to get more than 8 registered variables */ for (uint8_t idx = 0; idx < 8; idx++) { @@ -234,7 +233,7 @@ TEST_CASE("DataSetTest", "[DataSetTest]") { uint8_t* buffPtr = buffer; CHECK(set.serialize(&buffPtr, &serSize, maxSize, SerializeIF::Endianness::MACHINE) == retval::CATCH_OK); - std::array validityBuffer; + std::array validityBuffer{}; std::memcpy(validityBuffer.data(), buffer + 9 + sizeof(uint16_t) * 3, 2); /* The first 9 variables should be valid */ CHECK(validityBuffer[0] == 0xff); @@ -258,7 +257,7 @@ TEST_CASE("DataSetTest", "[DataSetTest]") { SECTION("SharedDataSet") { object_id_t sharedSetId = objects::SHARED_SET_ID; - SharedLocalDataSet sharedSet(sharedSetId, poolOwner, lpool::testSetId, 5); + SharedLocalDataSet sharedSet(sharedSetId, &poolOwner, lpool::testSetId, 5); localSet.localPoolVarUint8.setReadWriteMode(pool_rwm_t::VAR_WRITE); localSet.localPoolUint16Vec.setReadWriteMode(pool_rwm_t::VAR_WRITE); CHECK(sharedSet.registerVariable(&localSet.localPoolVarUint8) == retval::CATCH_OK); @@ -279,8 +278,4 @@ TEST_CASE("DataSetTest", "[DataSetTest]") { sharedSet.setReadCommitProtectionBehaviour(true); } - - /* we need to reset the subscription list because the pool owner - is a global object. */ - CHECK(poolOwner->reset() == retval::CATCH_OK); } diff --git a/unittests/datapoollocal/testLocalPoolManager.cpp b/unittests/datapoollocal/testLocalPoolManager.cpp new file mode 100644 index 00000000..9c979df2 --- /dev/null +++ b/unittests/datapoollocal/testLocalPoolManager.cpp @@ -0,0 +1,430 @@ +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include + +#include "CatchDefinitions.h" +#include "LocalPoolOwnerBase.h" +#include "mocks/HkReceiverMock.h" + +TEST_CASE("Local Pool Manager Tests", "[LocManTest]") { + const MessageQueueId_t defaultDestId = 1; + const MessageQueueId_t hkDest = defaultDestId; + const MessageQueueId_t subscriberId = 2; + auto hkReceiver = HkReceiverMock(hkDest); + auto queue = MessageQueueMockBase(); + LocalPoolOwnerBase poolOwner(queue, objects::TEST_LOCAL_POOL_OWNER_BASE); + REQUIRE(poolOwner.initializeHkManager() == retval::CATCH_OK); + REQUIRE(poolOwner.initializeHkManagerAfterTaskCreation() == retval::CATCH_OK); + + MessageQueueMockBase& poolOwnerMock = poolOwner.getMockQueueHandle(); + + // TODO: This is ugly. This should be an arbitrary ctor argument. Fix this in the pool + // manager + poolOwnerMock.setDefaultDestination(defaultDestId); + poolOwner.setHkDestId(hkDest); + + auto* hkMan = poolOwner.getHkManagerHandle(); + + CommandMessage messageSent; + + SECTION("Basic Test") { + { + /* For code coverage, should not crash */ + LocalDataPoolManager manager(nullptr, nullptr); + } + auto owner = poolOwner.poolManager.getOwner(); + REQUIRE(owner != nullptr); + CHECK(owner->getObjectId() == objects::TEST_LOCAL_POOL_OWNER_BASE); + + /* Subscribe for message generation on update. */ + REQUIRE(poolOwner.subscribeWrapperSetUpdate(subscriberId) == retval::CATCH_OK); + /* Subscribe for an update message. */ + poolOwner.dataset.setChanged(true); + /* Now the update message should be generated. */ + REQUIRE(poolOwner.poolManager.performHkOperation() == retval::CATCH_OK); + REQUIRE(poolOwnerMock.wasMessageSent()); + + REQUIRE(poolOwnerMock.getNextSentMessage(subscriberId, messageSent) == retval::CATCH_OK); + CHECK(messageSent.getCommand() == + static_cast(HousekeepingMessage::UPDATE_NOTIFICATION_SET)); + + /* Should have been reset. */ + CHECK(poolOwner.dataset.hasChanged() == false); + poolOwnerMock.clearMessages(true); + /* Set changed again, result should be the same. */ + poolOwner.dataset.setChanged(true); + REQUIRE(poolOwner.poolManager.performHkOperation() == retval::CATCH_OK); + + REQUIRE(poolOwnerMock.wasMessageSent() == true); + CHECK(poolOwnerMock.numberOfSentMessage() == 1); + REQUIRE(poolOwnerMock.getNextSentMessage(subscriberId, messageSent) == retval::CATCH_OK); + CHECK(messageSent.getCommand() == + static_cast(HousekeepingMessage::UPDATE_NOTIFICATION_SET)); + + poolOwnerMock.clearMessages(true); + /* Now subscribe for set update HK as well. */ + REQUIRE(poolOwner.subscribeWrapperSetUpdateHk(false, &hkReceiver) == retval::CATCH_OK); + poolOwner.dataset.setChanged(true); + REQUIRE(poolOwner.poolManager.performHkOperation() == retval::CATCH_OK); + REQUIRE(poolOwnerMock.wasMessageSent() == true); + CHECK(poolOwnerMock.numberOfSentMessage() == 2); + // first message sent should be the update notification + REQUIRE(poolOwnerMock.getNextSentMessage(subscriberId, messageSent) == retval::CATCH_OK); + CHECK(messageSent.getCommand() == + static_cast(HousekeepingMessage::UPDATE_NOTIFICATION_SET)); + REQUIRE(poolOwnerMock.getNextSentMessage(messageSent) == retval::CATCH_OK); + CHECK(messageSent.getCommand() == static_cast(HousekeepingMessage::HK_REPORT)); + /* Clear message to avoid memory leak, our mock won't do it for us (yet) */ + CommandMessageCleaner::clearCommandMessage(&messageSent); + } + + SECTION("SetSnapshotUpdateTest") { + /* Set the variables in the set to certain values. These are checked later. */ + { + PoolReadGuard readHelper(&poolOwner.dataset); + REQUIRE(readHelper.getReadResult() == retval::CATCH_OK); + poolOwner.dataset.localPoolVarUint8.value = 5; + poolOwner.dataset.localPoolVarFloat.value = -12.242; + poolOwner.dataset.localPoolUint16Vec.value[0] = 2; + poolOwner.dataset.localPoolUint16Vec.value[1] = 32; + poolOwner.dataset.localPoolUint16Vec.value[2] = 42932; + } + + /* Subscribe for snapshot generation on update. */ + REQUIRE(poolOwner.subscribeWrapperSetUpdateSnapshot(subscriberId) == retval::CATCH_OK); + poolOwner.dataset.setChanged(true); + + /* Store current time, we are going to check the (approximate) time equality later */ + timeval now{}; + Clock::getClock_timeval(&now); + + /* Trigger generation of snapshot */ + REQUIRE(poolOwner.poolManager.performHkOperation() == retval::CATCH_OK); + REQUIRE(poolOwnerMock.wasMessageSent()); + CHECK(poolOwnerMock.numberOfSentMessage() == 1); + REQUIRE(poolOwnerMock.getNextSentMessage(subscriberId, messageSent) == retval::CATCH_OK); + /* Check that snapshot was generated */ + CHECK(messageSent.getCommand() == static_cast(HousekeepingMessage::UPDATE_SNAPSHOT_SET)); + /* Now we deserialize the snapshot into a new dataset instance */ + CCSDSTime::CDS_short cdsShort{}; + LocalPoolTestDataSet newSet; + HousekeepingSnapshot snapshot(&cdsShort, &newSet); + store_address_t storeId; + HousekeepingMessage::getUpdateSnapshotSetCommand(&messageSent, &storeId); + ConstAccessorPair accessorPair = tglob::getIpcStoreHandle()->getData(storeId); + REQUIRE(accessorPair.first == retval::CATCH_OK); + const uint8_t* readOnlyPtr = accessorPair.second.data(); + size_t sizeToDeserialize = accessorPair.second.size(); + CHECK(newSet.localPoolVarFloat.value == 0); + CHECK(newSet.localPoolVarUint8 == 0); + CHECK(newSet.localPoolUint16Vec.value[0] == 0); + CHECK(newSet.localPoolUint16Vec.value[1] == 0); + CHECK(newSet.localPoolUint16Vec.value[2] == 0); + /* Fill the dataset and timestamp */ + REQUIRE(snapshot.deSerialize(&readOnlyPtr, &sizeToDeserialize, + SerializeIF::Endianness::MACHINE) == retval::CATCH_OK); + /* Now we check that the snapshot is actually correct */ + CHECK(newSet.localPoolVarFloat.value == Catch::Approx(-12.242)); + CHECK(newSet.localPoolVarUint8 == 5); + CHECK(newSet.localPoolUint16Vec.value[0] == 2); + CHECK(newSet.localPoolUint16Vec.value[1] == 32); + CHECK(newSet.localPoolUint16Vec.value[2] == 42932); + + /* Now we check that both times are equal */ + timeval timeFromHK{}; + auto result = CCSDSTime::convertFromCDS(&timeFromHK, &cdsShort); + CHECK(result == HasReturnvaluesIF::RETURN_OK); + timeval difference = timeFromHK - now; + CHECK(timevalOperations::toDouble(difference) < 1.0); + } + + SECTION("VariableSnapshotTest") { + /* Acquire subscription interface */ + ProvidesDataPoolSubscriptionIF* subscriptionIF = poolOwner.getSubscriptionInterface(); + REQUIRE(subscriptionIF != nullptr); + + /* Subscribe for variable snapshot */ + REQUIRE(poolOwner.subscribeWrapperVariableSnapshot(subscriberId, lpool::uint8VarId) == + retval::CATCH_OK); + auto poolVar = + dynamic_cast*>(poolOwner.getPoolObjectHandle(lpool::uint8VarId)); + REQUIRE(poolVar != nullptr); + + { + PoolReadGuard rg(poolVar); + CHECK(rg.getReadResult() == retval::CATCH_OK); + poolVar->value = 25; + } + + poolVar->setChanged(true); + /* Store current time, we are going to check the (approximate) time equality later */ + CCSDSTime::CDS_short timeCdsNow{}; + timeval now{}; + Clock::getClock_timeval(&now); + REQUIRE(poolOwner.poolManager.performHkOperation() == retval::CATCH_OK); + + /* Check update snapshot was sent. */ + REQUIRE(poolOwnerMock.wasMessageSent()); + CHECK(poolOwnerMock.numberOfSentMessage() == 1); + + /* Should have been reset. */ + CHECK(poolVar->hasChanged() == false); + REQUIRE(poolOwnerMock.getNextSentMessage(subscriberId, messageSent) == retval::CATCH_OK); + CHECK(messageSent.getCommand() == + static_cast(HousekeepingMessage::UPDATE_SNAPSHOT_VARIABLE)); + /* Now we deserialize the snapshot into a new dataset instance */ + CCSDSTime::CDS_short cdsShort{}; + lp_var_t varCopy = lp_var_t(lpool::uint8VarGpid); + HousekeepingSnapshot snapshot(&cdsShort, &varCopy); + store_address_t storeId; + HousekeepingMessage::getUpdateSnapshotVariableCommand(&messageSent, &storeId); + ConstAccessorPair accessorPair = tglob::getIpcStoreHandle()->getData(storeId); + REQUIRE(accessorPair.first == retval::CATCH_OK); + const uint8_t* readOnlyPtr = accessorPair.second.data(); + size_t sizeToDeserialize = accessorPair.second.size(); + CHECK(varCopy.value == 0); + /* Fill the dataset and timestamp */ + REQUIRE(snapshot.deSerialize(&readOnlyPtr, &sizeToDeserialize, + SerializeIF::Endianness::MACHINE) == retval::CATCH_OK); + CHECK(varCopy.value == 25); + + /* Now we check that both times are equal */ + timeval timeFromHK{}; + auto result = CCSDSTime::convertFromCDS(&timeFromHK, &cdsShort); + CHECK(result == HasReturnvaluesIF::RETURN_OK); + timeval difference = timeFromHK - now; + CHECK(timevalOperations::toDouble(difference) < 1.0); + } + + SECTION("VariableNotificationTest") { + /* Acquire subscription interface */ + ProvidesDataPoolSubscriptionIF* subscriptionIF = poolOwner.getSubscriptionInterface(); + REQUIRE(subscriptionIF != nullptr); + + /* Subscribe for variable update */ + REQUIRE(poolOwner.subscribeWrapperVariableUpdate(subscriberId, lpool::uint8VarId) == + retval::CATCH_OK); + auto* poolVar = + dynamic_cast*>(poolOwner.getPoolObjectHandle(lpool::uint8VarId)); + REQUIRE(poolVar != nullptr); + poolVar->setChanged(true); + REQUIRE(poolVar->hasChanged() == true); + REQUIRE(poolOwner.poolManager.performHkOperation() == retval::CATCH_OK); + + /* Check update notification was sent. */ + REQUIRE(poolOwnerMock.wasMessageSent()); + CHECK(poolOwnerMock.numberOfSentMessage() == 1); + /* Should have been reset. */ + CHECK(poolVar->hasChanged() == false); + REQUIRE(poolOwnerMock.getNextSentMessage(subscriberId, messageSent) == retval::CATCH_OK); + CHECK(messageSent.getCommand() == + static_cast(HousekeepingMessage::UPDATE_NOTIFICATION_VARIABLE)); + /* Now subscribe for the dataset update (HK and update) again with subscription interface */ + REQUIRE(subscriptionIF->subscribeForSetUpdateMessage(lpool::testSetId, objects::NO_OBJECT, + subscriberId, false) == retval::CATCH_OK); + REQUIRE(poolOwner.subscribeWrapperSetUpdateHk(false, &hkReceiver) == retval::CATCH_OK); + + poolOwner.dataset.setChanged(true); + poolOwnerMock.clearMessages(); + REQUIRE(poolOwner.poolManager.performHkOperation() == retval::CATCH_OK); + /* Now two messages should be sent. */ + REQUIRE(poolOwnerMock.wasMessageSent()); + CHECK(poolOwnerMock.numberOfSentMessage() == 2); + poolOwnerMock.clearMessages(true); + + poolOwner.dataset.setChanged(true); + poolOwnerMock.clearMessages(true); + poolVar->setChanged(true); + REQUIRE(poolOwner.poolManager.performHkOperation() == retval::CATCH_OK); + /* Now three messages should be sent. */ + REQUIRE(poolOwnerMock.wasMessageSent()); + CHECK(poolOwnerMock.numberOfSentMessage() == 3); + CHECK(poolOwnerMock.numberOfSentMessage(subscriberId) == 2); + CHECK(poolOwnerMock.numberOfSentMessage(hkDest) == 1); + REQUIRE(poolOwnerMock.getNextSentMessage(subscriberId, messageSent) == retval::CATCH_OK); + CHECK(messageSent.getCommand() == + static_cast(HousekeepingMessage::UPDATE_NOTIFICATION_VARIABLE)); + REQUIRE(poolOwnerMock.clearLastSentMessage(subscriberId) == HasReturnvaluesIF::RETURN_OK); + REQUIRE(poolOwnerMock.getNextSentMessage(subscriberId, messageSent) == + HasReturnvaluesIF::RETURN_OK); + CHECK(messageSent.getCommand() == + static_cast(HousekeepingMessage::UPDATE_NOTIFICATION_SET)); + REQUIRE(poolOwnerMock.clearLastSentMessage(subscriberId) == HasReturnvaluesIF::RETURN_OK); + REQUIRE(poolOwnerMock.getNextSentMessage(messageSent) == retval::CATCH_OK); + CHECK(messageSent.getCommand() == static_cast(HousekeepingMessage::HK_REPORT)); + REQUIRE(poolOwnerMock.clearLastSentMessage() == HasReturnvaluesIF::RETURN_OK); + REQUIRE(poolOwnerMock.getNextSentMessage(subscriberId, messageSent) == MessageQueueIF::EMPTY); + REQUIRE(poolOwnerMock.getNextSentMessage(messageSent) == MessageQueueIF::EMPTY); + } + + SECTION("PeriodicHKAndMessaging") { + /* Now we subcribe for a HK periodic generation. Even when it's difficult to simulate + the temporal behaviour correctly the HK manager should generate a HK packet + immediately and the periodic helper depends on HK op function calls anyway instead of + using the clock, so we could also just call performHkOperation multiple times */ + REQUIRE(poolOwner.subscribePeriodicHk(true) == retval::CATCH_OK); + REQUIRE(poolOwner.poolManager.performHkOperation() == retval::CATCH_OK); + /* Now HK packet should be sent as message immediately. */ + REQUIRE(poolOwnerMock.wasMessageSent()); + CHECK(poolOwnerMock.numberOfSentMessage() == 1); + CHECK(poolOwnerMock.clearLastSentMessage() == retval::CATCH_OK); + + LocalPoolDataSetBase* setHandle = poolOwner.getDataSetHandle(lpool::testSid); + REQUIRE(setHandle != nullptr); + CHECK(poolOwner.poolManager.generateHousekeepingPacket(lpool::testSid, setHandle, false) == + retval::CATCH_OK); + REQUIRE(poolOwnerMock.wasMessageSent()); + CHECK(poolOwnerMock.numberOfSentMessage() == 1); + CHECK(poolOwnerMock.clearLastSentMessage() == retval::CATCH_OK); + + CHECK(setHandle->getReportingEnabled() == true); + CommandMessage hkCmd; + HousekeepingMessage::setToggleReportingCommand(&hkCmd, lpool::testSid, false, false); + CHECK(poolOwner.poolManager.handleHousekeepingMessage(&hkCmd) == retval::CATCH_OK); + CHECK(setHandle->getReportingEnabled() == false); + REQUIRE(poolOwnerMock.wasMessageSent()); + CHECK(poolOwnerMock.numberOfSentMessage() == 1); + CHECK(poolOwnerMock.clearLastSentMessage() == retval::CATCH_OK); + + HousekeepingMessage::setToggleReportingCommand(&hkCmd, lpool::testSid, true, false); + CHECK(poolOwner.poolManager.handleHousekeepingMessage(&hkCmd) == retval::CATCH_OK); + CHECK(setHandle->getReportingEnabled() == true); + REQUIRE(poolOwnerMock.wasMessageSent()); + CHECK(poolOwnerMock.clearLastSentMessage() == retval::CATCH_OK); + + HousekeepingMessage::setToggleReportingCommand(&hkCmd, lpool::testSid, false, false); + CHECK(poolOwner.poolManager.handleHousekeepingMessage(&hkCmd) == retval::CATCH_OK); + CHECK(setHandle->getReportingEnabled() == false); + REQUIRE(poolOwnerMock.wasMessageSent()); + CHECK(poolOwnerMock.clearLastSentMessage() == retval::CATCH_OK); + + HousekeepingMessage::setCollectionIntervalModificationCommand(&hkCmd, lpool::testSid, 0.4, + false); + CHECK(poolOwner.poolManager.handleHousekeepingMessage(&hkCmd) == retval::CATCH_OK); + /* For non-diagnostics and a specified minimum frequency of 0.2 seconds, the + resulting collection interval should be 1.0 second */ + CHECK(poolOwner.dataset.getCollectionInterval() == 1.0); + REQUIRE(poolOwnerMock.wasMessageSent()); + REQUIRE(poolOwnerMock.numberOfSentMessage() == 1); + CHECK(poolOwnerMock.clearLastSentMessage() == retval::CATCH_OK); + + HousekeepingMessage::setStructureReportingCommand(&hkCmd, lpool::testSid, false); + REQUIRE(poolOwner.poolManager.performHkOperation() == retval::CATCH_OK); + CHECK(poolOwner.poolManager.handleHousekeepingMessage(&hkCmd) == retval::CATCH_OK); + /* Now HK packet should be sent as message. */ + REQUIRE(poolOwnerMock.wasMessageSent()); + REQUIRE(poolOwnerMock.numberOfSentMessage() == 1); + poolOwnerMock.clearMessages(); + + HousekeepingMessage::setOneShotReportCommand(&hkCmd, lpool::testSid, false); + CHECK(poolOwner.poolManager.handleHousekeepingMessage(&hkCmd) == retval::CATCH_OK); + REQUIRE(poolOwnerMock.wasMessageSent()); + REQUIRE(poolOwnerMock.numberOfSentMessage() == 1); + poolOwnerMock.clearMessages(); + + HousekeepingMessage::setUpdateNotificationSetCommand(&hkCmd, lpool::testSid); + sid_t sidToCheck; + store_address_t storeId; + CHECK(poolOwner.poolManager.handleHousekeepingMessage(&hkCmd) == retval::CATCH_OK); + CHECK(poolOwner.changedDataSetCallbackWasCalled(sidToCheck, storeId) == true); + CHECK(sidToCheck == lpool::testSid); + + /* Now we test the handling is the dataset is set to diagnostic */ + poolOwner.dataset.setDiagnostic(true); + + HousekeepingMessage::setStructureReportingCommand(&hkCmd, lpool::testSid, false); + CHECK(poolOwner.poolManager.handleHousekeepingMessage(&hkCmd) == + static_cast(LocalDataPoolManager::WRONG_HK_PACKET_TYPE)); + /* We still expect a failure message being sent */ + REQUIRE(poolOwnerMock.wasMessageSent()); + REQUIRE(poolOwnerMock.numberOfSentMessage() == 1); + CHECK(poolOwnerMock.clearLastSentMessage() == retval::CATCH_OK); + + HousekeepingMessage::setCollectionIntervalModificationCommand(&hkCmd, lpool::testSid, 0.4, + false); + CHECK(poolOwner.poolManager.handleHousekeepingMessage(&hkCmd) == + static_cast(LocalDataPoolManager::WRONG_HK_PACKET_TYPE)); + REQUIRE(poolOwnerMock.wasMessageSent()); + REQUIRE(poolOwnerMock.numberOfSentMessage() == 1); + CHECK(poolOwnerMock.clearLastSentMessage() == retval::CATCH_OK); + + HousekeepingMessage::setStructureReportingCommand(&hkCmd, lpool::testSid, false); + CHECK(poolOwner.poolManager.handleHousekeepingMessage(&hkCmd) == + static_cast(LocalDataPoolManager::WRONG_HK_PACKET_TYPE)); + REQUIRE(poolOwnerMock.wasMessageSent()); + REQUIRE(poolOwnerMock.numberOfSentMessage() == 1); + CHECK(poolOwnerMock.clearLastSentMessage() == retval::CATCH_OK); + + HousekeepingMessage::setStructureReportingCommand(&hkCmd, lpool::testSid, true); + CHECK(poolOwner.poolManager.handleHousekeepingMessage(&hkCmd) == retval::CATCH_OK); + REQUIRE(poolOwnerMock.wasMessageSent()); + REQUIRE(poolOwnerMock.numberOfSentMessage() == 1); + poolOwnerMock.clearMessages(); + + HousekeepingMessage::setCollectionIntervalModificationCommand(&hkCmd, lpool::testSid, 0.4, + true); + CHECK(poolOwner.poolManager.handleHousekeepingMessage(&hkCmd) == retval::CATCH_OK); + REQUIRE(poolOwnerMock.wasMessageSent()); + REQUIRE(poolOwnerMock.numberOfSentMessage() == 1); + poolOwnerMock.clearMessages(); + + HousekeepingMessage::setToggleReportingCommand(&hkCmd, lpool::testSid, true, true); + CHECK(poolOwner.poolManager.handleHousekeepingMessage(&hkCmd) == retval::CATCH_OK); + REQUIRE(poolOwnerMock.wasMessageSent()); + REQUIRE(poolOwnerMock.numberOfSentMessage() == 1); + poolOwnerMock.clearMessages(); + + HousekeepingMessage::setToggleReportingCommand(&hkCmd, lpool::testSid, false, true); + CHECK(poolOwner.poolManager.handleHousekeepingMessage(&hkCmd) == retval::CATCH_OK); + REQUIRE(poolOwnerMock.wasMessageSent()); + REQUIRE(poolOwnerMock.numberOfSentMessage() == 1); + poolOwnerMock.clearMessages(); + + HousekeepingMessage::setOneShotReportCommand(&hkCmd, lpool::testSid, false); + CHECK(poolOwner.poolManager.handleHousekeepingMessage(&hkCmd) == + static_cast(LocalDataPoolManager::WRONG_HK_PACKET_TYPE)); + REQUIRE(poolOwnerMock.wasMessageSent()); + REQUIRE(poolOwnerMock.numberOfSentMessage() == 1); + poolOwnerMock.clearMessages(); + + HousekeepingMessage::setOneShotReportCommand(&hkCmd, lpool::testSid, true); + CHECK(poolOwner.poolManager.handleHousekeepingMessage(&hkCmd) == retval::CATCH_OK); + REQUIRE(poolOwnerMock.wasMessageSent()); + REQUIRE(poolOwnerMock.numberOfSentMessage() == 1); + poolOwnerMock.clearMessages(); + + HousekeepingMessage::setUpdateNotificationVariableCommand(&hkCmd, lpool::uint8VarGpid); + gp_id_t gpidToCheck; + CHECK(poolOwner.poolManager.handleHousekeepingMessage(&hkCmd) == retval::CATCH_OK); + CHECK(poolOwner.changedVariableCallbackWasCalled(gpidToCheck, storeId) == true); + CHECK(gpidToCheck == lpool::uint8VarGpid); + + HousekeepingMessage::setUpdateSnapshotSetCommand(&hkCmd, lpool::testSid, + store_address_t::invalid()); + CHECK(poolOwner.poolManager.handleHousekeepingMessage(&hkCmd) == retval::CATCH_OK); + CHECK(poolOwner.changedDataSetCallbackWasCalled(sidToCheck, storeId) == true); + CHECK(sidToCheck == lpool::testSid); + + HousekeepingMessage::setUpdateSnapshotVariableCommand(&hkCmd, lpool::uint8VarGpid, + store_address_t::invalid()); + CHECK(poolOwner.poolManager.handleHousekeepingMessage(&hkCmd) == retval::CATCH_OK); + CHECK(poolOwner.changedVariableCallbackWasCalled(gpidToCheck, storeId) == true); + CHECK(gpidToCheck == lpool::uint8VarGpid); + + poolOwner.poolManager.printPoolEntry(lpool::uint8VarId); + } + + /* we need to reset the subscription list because the pool owner + is a global object. */ + CHECK(poolOwner.reset() == retval::CATCH_OK); + poolOwnerMock.clearMessages(true); +} diff --git a/unittests/datapoollocal/LocalPoolVariableTest.cpp b/unittests/datapoollocal/testLocalPoolVariable.cpp similarity index 100% rename from unittests/datapoollocal/LocalPoolVariableTest.cpp rename to unittests/datapoollocal/testLocalPoolVariable.cpp diff --git a/unittests/datapoollocal/LocalPoolVectorTest.cpp b/unittests/datapoollocal/testLocalPoolVector.cpp similarity index 98% rename from unittests/datapoollocal/LocalPoolVectorTest.cpp rename to unittests/datapoollocal/testLocalPoolVector.cpp index 2235ad39..331d4e09 100644 --- a/unittests/datapoollocal/LocalPoolVectorTest.cpp +++ b/unittests/datapoollocal/testLocalPoolVector.cpp @@ -4,11 +4,11 @@ #include #include "CatchDefinitions.h" -#include "LocalPoolOwnerBase.h" +#include "mocks/LocalPoolOwnerBase.h" #include "tests/TestsConfig.h" TEST_CASE("LocalPoolVector", "[LocPoolVecTest]") { - LocalPoolOwnerBase* poolOwner = + auto* poolOwner = ObjectManager::instance()->get(objects::TEST_LOCAL_POOL_OWNER_BASE); REQUIRE(poolOwner != nullptr); REQUIRE(poolOwner->initializeHkManager() == retval::CATCH_OK); diff --git a/unittests/mocks/CdsShortTimestamperMock.h b/unittests/mocks/CdsShortTimestamperMock.h index 273cf24c..784ef7f4 100644 --- a/unittests/mocks/CdsShortTimestamperMock.h +++ b/unittests/mocks/CdsShortTimestamperMock.h @@ -3,8 +3,8 @@ #include -#include "fsfw/timemanager/TimeStamperIF.h" #include "fsfw/timemanager/TimeReaderIF.h" +#include "fsfw/timemanager/TimeStamperIF.h" class CdsShortTimestamperMock : public TimeStamperIF, public TimeReaderIF { public: @@ -75,7 +75,7 @@ class CdsShortTimestamperMock : public TimeStamperIF, public TimeReaderIF { serFailRetval = HasReturnvaluesIF::RETURN_FAILED; } - ReturnValue_t readTimeStamp(const uint8_t* buffer, size_t maxSize) override { + ReturnValue_t readTimeStamp(const uint8_t *buffer, size_t maxSize) override { return deSerialize(&buffer, &maxSize, SerializeIF::Endianness::NETWORK); } size_t getTimestampLen() override { return getSerializedSize(); } diff --git a/unittests/mocks/HkReceiverMock.h b/unittests/mocks/HkReceiverMock.h index 8d4b4983..33a43a81 100644 --- a/unittests/mocks/HkReceiverMock.h +++ b/unittests/mocks/HkReceiverMock.h @@ -2,13 +2,15 @@ #define FSFW_UNITTEST_TESTS_MOCKS_HKRECEIVERMOCK_H_ #include -#include -class HkReceiverMock : public SystemObject, public AcceptsHkPacketsIF { +class HkReceiverMock : public AcceptsHkPacketsIF { public: - HkReceiverMock(object_id_t objectId) : SystemObject(objectId) {} + explicit HkReceiverMock(MessageQueueId_t queueId) : queueId(queueId) {} - MessageQueueId_t getHkQueue() const { return MessageQueueIF::NO_QUEUE; } + [[nodiscard]] MessageQueueId_t getHkQueue() const override { return queueId; } + + private: + MessageQueueId_t queueId; }; #endif /* FSFW_UNITTEST_TESTS_MOCKS_HKRECEIVERMOCK_H_ */ diff --git a/unittests/mocks/InternalErrorReporterMock.cpp b/unittests/mocks/InternalErrorReporterMock.cpp index 9988234b..c7758a13 100644 --- a/unittests/mocks/InternalErrorReporterMock.cpp +++ b/unittests/mocks/InternalErrorReporterMock.cpp @@ -2,12 +2,6 @@ InternalErrorReporterMock::InternalErrorReporterMock() = default; -void InternalErrorReporterMock::queueMessageNotSent() { - queueMsgNotSentCallCnt++; -} -void InternalErrorReporterMock::lostTm() { - lostTmCallCnt++; -} -void InternalErrorReporterMock::storeFull() { - storeFullCallCnt++; -} +void InternalErrorReporterMock::queueMessageNotSent() { queueMsgNotSentCallCnt++; } +void InternalErrorReporterMock::lostTm() { lostTmCallCnt++; } +void InternalErrorReporterMock::storeFull() { storeFullCallCnt++; } diff --git a/unittests/mocks/InternalErrorReporterMock.h b/unittests/mocks/InternalErrorReporterMock.h index d2921630..f6babe09 100644 --- a/unittests/mocks/InternalErrorReporterMock.h +++ b/unittests/mocks/InternalErrorReporterMock.h @@ -3,7 +3,7 @@ #include "fsfw/internalerror/InternalErrorReporterIF.h" -class InternalErrorReporterMock: public InternalErrorReporterIF { +class InternalErrorReporterMock : public InternalErrorReporterIF { public: unsigned int queueMsgNotSentCallCnt = 0; unsigned int lostTmCallCnt = 0; diff --git a/unittests/datapoollocal/LocalPoolOwnerBase.cpp b/unittests/mocks/LocalPoolOwnerBase.cpp similarity index 90% rename from unittests/datapoollocal/LocalPoolOwnerBase.cpp rename to unittests/mocks/LocalPoolOwnerBase.cpp index 2743e7f7..f269e066 100644 --- a/unittests/datapoollocal/LocalPoolOwnerBase.cpp +++ b/unittests/mocks/LocalPoolOwnerBase.cpp @@ -1,18 +1,17 @@ #include "LocalPoolOwnerBase.h" -LocalPoolOwnerBase::LocalPoolOwnerBase(object_id_t objectId) - : SystemObject(objectId), poolManager(this, messageQueue), dataset(this, lpool::testSetId) { - messageQueue = new MessageQueueMockBase(); -} +LocalPoolOwnerBase::LocalPoolOwnerBase(MessageQueueIF &queue, object_id_t objectId) + : SystemObject(objectId), + queue(queue), + poolManager(this, &queue), + dataset(this, lpool::testSetId) {} -LocalPoolOwnerBase::~LocalPoolOwnerBase() { - QueueFactory::instance()->deleteMessageQueue(messageQueue); -} +LocalPoolOwnerBase::~LocalPoolOwnerBase() = default; ReturnValue_t LocalPoolOwnerBase::initializeHkManager() { if (not initialized) { initialized = true; - return poolManager.initialize(messageQueue); + return poolManager.initialize(&queue); } return HasReturnvaluesIF::RETURN_OK; } @@ -125,3 +124,5 @@ void LocalPoolOwnerBase::handleChangedPoolVariable(gp_id_t globPoolId, store_add this->changedPoolVariableGpid = globPoolId; this->storeIdForChangedVariable = storeId; } + +void LocalPoolOwnerBase::setHkDestId(MessageQueueId_t id) { poolManager.setHkDestinationId(id); } diff --git a/unittests/datapoollocal/LocalPoolOwnerBase.h b/unittests/mocks/LocalPoolOwnerBase.h similarity index 68% rename from unittests/datapoollocal/LocalPoolOwnerBase.h rename to unittests/mocks/LocalPoolOwnerBase.h index 0bcebc00..1dcd6cf2 100644 --- a/unittests/datapoollocal/LocalPoolOwnerBase.h +++ b/unittests/mocks/LocalPoolOwnerBase.h @@ -64,26 +64,29 @@ class LocalPoolTestDataSet : public LocalDataSet { class LocalPoolOwnerBase : public SystemObject, public HasLocalDataPoolIF { public: - LocalPoolOwnerBase(object_id_t objectId = objects::TEST_LOCAL_POOL_OWNER_BASE); + explicit LocalPoolOwnerBase(MessageQueueIF& queue, + object_id_t objectId = objects::TEST_LOCAL_POOL_OWNER_BASE); - ~LocalPoolOwnerBase(); + ~LocalPoolOwnerBase() override; - object_id_t getObjectId() const override { return SystemObject::getObjectId(); } + [[nodiscard]] object_id_t getObjectId() const override { return SystemObject::getObjectId(); } ReturnValue_t initializeHkManager(); + void setHkDestId(MessageQueueId_t id); + ReturnValue_t initializeHkManagerAfterTaskCreation(); /** Command queue for housekeeping messages. */ - MessageQueueId_t getCommandQueue() const override { return messageQueue->getId(); } + [[nodiscard]] MessageQueueId_t getCommandQueue() const override { return queue.getId(); } // This is called by initializeAfterTaskCreation of the HK manager. - virtual ReturnValue_t initializeLocalDataPool(localpool::DataPool& localDataPoolMap, - LocalDataPoolManager& poolManager) override; + ReturnValue_t initializeLocalDataPool(localpool::DataPool& localDataPoolMap, + LocalDataPoolManager& poolManager) override; LocalDataPoolManager* getHkManagerHandle() override { return &poolManager; } - dur_millis_t getPeriodicOperationFrequency() const override { return 200; } + [[nodiscard]] dur_millis_t getPeriodicOperationFrequency() const override { return 200; } /** * This function is used by the pool manager to get a valid dataset @@ -91,41 +94,54 @@ class LocalPoolOwnerBase : public SystemObject, public HasLocalDataPoolIF { * @param sid Corresponding structure ID * @return */ - virtual LocalPoolDataSetBase* getDataSetHandle(sid_t sid) override { return &dataset; } + LocalPoolDataSetBase* getDataSetHandle(sid_t sid) override { return &dataset; } - virtual LocalPoolObjectBase* getPoolObjectHandle(lp_id_t localPoolId) override; + LocalPoolObjectBase* getPoolObjectHandle(lp_id_t localPoolId) override; - MessageQueueMockBase* getMockQueueHandle() const { - return dynamic_cast(messageQueue); + [[nodiscard]] MessageQueueMockBase& getMockQueueHandle() const { + return dynamic_cast(queue); } ReturnValue_t subscribePeriodicHk(bool enableReporting) { - return poolManager.subscribeForPeriodicPacket(lpool::testSid, enableReporting, 0.2, false); + return poolManager.subscribeForRegularPeriodicPacket( + subdp::RegularHkPeriodicParams(lpool::testSid, enableReporting, 0.2)); } - ReturnValue_t subscribeWrapperSetUpdate() { + ReturnValue_t subscribeWrapperSetUpdate(MessageQueueId_t receiverId) { return poolManager.subscribeForSetUpdateMessage(lpool::testSetId, objects::NO_OBJECT, - objects::HK_RECEIVER_MOCK, false); + receiverId, false); } - ReturnValue_t subscribeWrapperSetUpdateSnapshot() { + ReturnValue_t subscribeWrapperSetUpdateSnapshot(MessageQueueId_t receiverId) { return poolManager.subscribeForSetUpdateMessage(lpool::testSetId, objects::NO_OBJECT, - objects::HK_RECEIVER_MOCK, true); + receiverId, true); } - ReturnValue_t subscribeWrapperSetUpdateHk(bool diagnostics = false) { - return poolManager.subscribeForUpdatePacket(lpool::testSid, diagnostics, false, - objects::HK_RECEIVER_MOCK); + ReturnValue_t subscribeWrapperSetUpdateHk(bool diagnostics = false, + AcceptsHkPacketsIF* receiver = nullptr) { + if (diagnostics) { + auto params = subdp::DiagnosticsHkUpdateParams(lpool::testSid, true); + if (receiver != nullptr) { + params.receiver = receiver->getHkQueue(); + } + return poolManager.subscribeForDiagUpdatePacket(params); + } else { + auto params = subdp::RegularHkUpdateParams(lpool::testSid, true); + if (receiver != nullptr) { + params.receiver = receiver->getHkQueue(); + } + return poolManager.subscribeForRegularUpdatePacket(params); + } } - ReturnValue_t subscribeWrapperVariableUpdate(lp_id_t localPoolId) { + ReturnValue_t subscribeWrapperVariableUpdate(MessageQueueId_t receiverId, lp_id_t localPoolId) { return poolManager.subscribeForVariableUpdateMessage(localPoolId, MessageQueueIF::NO_QUEUE, - objects::HK_RECEIVER_MOCK, false); + receiverId, false); } - ReturnValue_t subscribeWrapperVariableSnapshot(lp_id_t localPoolId) { + ReturnValue_t subscribeWrapperVariableSnapshot(MessageQueueId_t receiverId, lp_id_t localPoolId) { return poolManager.subscribeForVariableUpdateMessage(localPoolId, MessageQueueIF::NO_QUEUE, - objects::HK_RECEIVER_MOCK, true); + receiverId, true); } ReturnValue_t reset(); @@ -155,7 +171,7 @@ class LocalPoolOwnerBase : public SystemObject, public HasLocalDataPoolIF { lp_vec_t testUint16Vec = lp_vec_t(this, lpool::uint16Vec3Id); lp_vec_t testInt64Vec = lp_vec_t(this, lpool::int64Vec2Id); - MessageQueueIF* messageQueue = nullptr; + MessageQueueIF& queue; bool initialized = false; bool initializedAfterTaskCreation = false; diff --git a/unittests/mocks/MessageQueueMockBase.cpp b/unittests/mocks/MessageQueueMockBase.cpp index 63caee26..16388e25 100644 --- a/unittests/mocks/MessageQueueMockBase.cpp +++ b/unittests/mocks/MessageQueueMockBase.cpp @@ -1,5 +1,7 @@ #include "MessageQueueMockBase.h" +#include +#include MessageQueueMockBase::MessageQueueMockBase() : MessageQueueBase(MessageQueueIF::NO_QUEUE, MessageQueueIF::NO_QUEUE, nullptr) {} @@ -7,32 +9,47 @@ MessageQueueMockBase::MessageQueueMockBase() MessageQueueMockBase::MessageQueueMockBase(MessageQueueId_t queueId) : MessageQueueBase(queueId, MessageQueueIF::NO_QUEUE, nullptr) {} -bool MessageQueueMockBase::wasMessageSent(uint8_t* messageSentCounter_, bool resetCounter) { - bool tempMessageSent = messageSent; - messageSent = false; - if (messageSentCounter_ != nullptr) { - *messageSentCounter_ = this->messageSentCounter; - } - if (resetCounter) { - this->messageSentCounter = 0; - } - return tempMessageSent; +bool MessageQueueMockBase::wasMessageSent() const { + return std::any_of( + sendMap.begin(), sendMap.end(), + [](const std::pair& pair) { return pair.second.callCount > 0; }); } -ReturnValue_t MessageQueueMockBase::popMessage() { - CommandMessage message; - message.clear(); - return receiveMessage(&message); +size_t MessageQueueMockBase::numberOfSentMessage() const { + size_t callCount = 0; + for (auto& destInfo : sendMap) { + callCount += destInfo.second.callCount; + } + return callCount; +} + +size_t MessageQueueMockBase::numberOfSentMessage(MessageQueueId_t id) const { + auto iter = sendMap.find(id); + if (iter == sendMap.end()) { + return 0; + } + return iter->second.callCount; +} + +ReturnValue_t MessageQueueMockBase::clearLastReceivedMessage(bool clearCmdMsg) { + if (receivedMsgs.empty()) { + return MessageQueueIF::EMPTY; + } + if (clearCmdMsg) { + CommandMessage message; + std::memcpy(message.getBuffer(), receivedMsgs.front().getBuffer(), message.getMessageSize()); + message.clearCommandMessage(); + } + receivedMsgs.pop_front(); + return HasReturnvaluesIF::RETURN_OK; } ReturnValue_t MessageQueueMockBase::receiveMessage(MessageQueueMessageIF* message) { - if (messagesSentQueue.empty()) { + if (receivedMsgs.empty()) { return MessageQueueIF::EMPTY; } - this->last = message->getSender(); - std::memcpy(message->getBuffer(), messagesSentQueue.front().getBuffer(), - message->getMessageSize()); - messagesSentQueue.pop(); + std::memcpy(message->getBuffer(), receivedMsgs.front().getBuffer(), message->getMessageSize()); + receivedMsgs.pop_front(); return HasReturnvaluesIF::RETURN_OK; } @@ -43,12 +60,18 @@ ReturnValue_t MessageQueueMockBase::flush(uint32_t* count) { ReturnValue_t MessageQueueMockBase::sendMessageFrom(MessageQueueId_t sendTo, MessageQueueMessageIF* message, MessageQueueId_t sentFrom, bool ignoreFault) { + if (message == nullptr) { + return HasReturnvaluesIF::RETURN_FAILED; + } auto iter = sendMap.find(sendTo); + MessageQueueMessage messageCopy; if (iter == sendMap.end()) { - sendMap.emplace(sendTo, SendInfo(message, 1)); + createMsgCopy(messageCopy, *message); + sendMap.emplace(sendTo, SendInfo(messageCopy, 1)); } else { iter->second.callCount += 1; - iter->second.msgs.push(message); + createMsgCopy(messageCopy, *message); + iter->second.msgs.push_back(messageCopy); } return HasReturnvaluesIF::RETURN_OK; } @@ -58,19 +81,87 @@ ReturnValue_t MessageQueueMockBase::reply(MessageQueueMessageIF* message) { } void MessageQueueMockBase::clearMessages(bool clearCommandMessages) { - for (const auto& destInfo: sendMap) { - if (clearCommandMessages) { - CommandMessage message; - std::memcpy(message.getBuffer(), destInfo.second.msgs.front()->getBuffer(), - message.getMessageSize()); + if (not clearCommandMessages) { + sendMap.clear(); + return; } - while (not messagesSentQueue.empty()) { - if (clearCommandMessages) { + for (auto& destInfo : sendMap) { + for (auto& msg : destInfo.second.msgs) { CommandMessage message; - std::memcpy(message.getBuffer(), messagesSentQueue.front().getBuffer(), + std::memcpy(message.getBuffer(), destInfo.second.msgs.front().getBuffer(), message.getMessageSize()); message.clear(); + destInfo.second.msgs.pop_front(); + destInfo.second.callCount--; + } + } + sendMap.clear(); +} + +void MessageQueueMockBase::addReceivedMessage(MessageQueueMessageIF& msg) { + MessageQueueMessage messageCopy; + createMsgCopy(messageCopy, msg); + receivedMsgs.push_back(messageCopy); +} + +void MessageQueueMockBase::createMsgCopy(MessageQueueMessageIF& into, MessageQueueMessageIF& from) { + if (from.getMessageSize() > into.getMaximumDataSize()) { + throw std::invalid_argument("Passed message does not fit into message copy"); + } + std::memcpy(into.getBuffer(), from.getBuffer(), from.getMaximumDataSize()); +} + +ReturnValue_t MessageQueueMockBase::getNextSentMessage(MessageQueueId_t id, + MessageQueueMessageIF& message) { + auto iter = sendMap.find(id); + if (iter == sendMap.end() or iter->second.callCount == 0) { + return MessageQueueIF::EMPTY; + } + createMsgCopy(message, iter->second.msgs.front()); + return HasReturnvaluesIF::RETURN_OK; +} + +ReturnValue_t MessageQueueMockBase::getNextSentMessage(MessageQueueMessageIF& message) { + return getNextSentMessage(MessageQueueBase::getDefaultDestination(), message); +} + +ReturnValue_t MessageQueueMockBase::clearLastSentMessage(MessageQueueId_t destId, + bool clearCmdMsg) { + auto iter = sendMap.find(destId); + if (iter == sendMap.end()) { + return MessageQueueIF::EMPTY; + } + return clearLastSentMessage(iter, clearCmdMsg); +} + +ReturnValue_t MessageQueueMockBase::clearLastSentMessage(bool clearCmdMsg) { + auto iter = sendMap.find(getDefaultDestination()); + if (iter == sendMap.end()) { + return MessageQueueIF::EMPTY; + } + ReturnValue_t result = clearLastSentMessage(iter, clearCmdMsg); + clearEmptyEntries(); + return result; +} + +ReturnValue_t MessageQueueMockBase::clearLastSentMessage( + std::map::iterator& iter, bool clearCmdMsg) { + if (clearCmdMsg) { + CommandMessage message; + std::memcpy(message.getBuffer(), iter->second.msgs.front().getBuffer(), + message.getMessageSize()); + message.clear(); + } + iter->second.msgs.pop_front(); + iter->second.callCount--; + return HasReturnvaluesIF::RETURN_OK; +} +void MessageQueueMockBase::clearEmptyEntries() { + for (auto it = sendMap.cbegin(); it != sendMap.cend();) { + if (it->second.callCount == 0) { + sendMap.erase(it++); + } else { + ++it; } - messagesSentQueue.pop(); } } diff --git a/unittests/mocks/MessageQueueMockBase.h b/unittests/mocks/MessageQueueMockBase.h index e42a0a67..fa63b171 100644 --- a/unittests/mocks/MessageQueueMockBase.h +++ b/unittests/mocks/MessageQueueMockBase.h @@ -2,8 +2,8 @@ #define FSFW_UNITTEST_TESTS_MOCKS_MESSAGEQUEUEMOCKBASE_H_ #include -#include #include +#include #include "CatchDefinitions.h" #include "fsfw/ipc/CommandMessage.h" @@ -12,39 +12,52 @@ #include "fsfw/ipc/MessageQueueMessage.h" struct SendInfo { - explicit SendInfo(MessageQueueMessageIF* initMsg, unsigned int initCallCnt = 1): callCount(initCallCnt) { - msgs.push(initMsg); + explicit SendInfo(MessageQueueMessage& initMsg, unsigned int initCallCnt = 1) + : callCount(initCallCnt) { + msgs.push_back(initMsg); } unsigned int callCount = 0; - std::queue msgs; + std::deque msgs; }; class MessageQueueMockBase : public MessageQueueBase { public: MessageQueueMockBase(); + void addReceivedMessage(MessageQueueMessageIF& msg); explicit MessageQueueMockBase(MessageQueueId_t queueId); - std::map sendMap; - - bool wasMessageSent(uint8_t* messageSentCounter_ = nullptr, bool resetCounter = true); - + //! Get next message which was sent to the default destination + ReturnValue_t getNextSentMessage(MessageQueueMessageIF& message); + //! Get message which was sent to a specific ID + ReturnValue_t getNextSentMessage(MessageQueueId_t id, MessageQueueMessageIF& message); + [[nodiscard]] bool wasMessageSent() const; + [[nodiscard]] size_t numberOfSentMessage() const; + [[nodiscard]] size_t numberOfSentMessage(MessageQueueId_t id) const; /** * Pop a message, clearing it in the process. * @return */ - ReturnValue_t popMessage(); - - ReturnValue_t receiveMessage(MessageQueueMessageIF* message) override; + ReturnValue_t clearLastReceivedMessage(bool clearCmdMsg = true); ReturnValue_t flush(uint32_t* count) override; ReturnValue_t sendMessageFrom(MessageQueueId_t sendTo, MessageQueueMessageIF* message, - MessageQueueId_t sentFrom, - bool ignoreFault = false) override; + MessageQueueId_t sentFrom, bool ignoreFault = false) override; ReturnValue_t reply(MessageQueueMessageIF* message) override; - void clearMessages(bool clearCommandMessages = true); + ReturnValue_t clearLastSentMessage(MessageQueueId_t destId, bool clearCmdMsg = true); + ReturnValue_t clearLastSentMessage(bool clearCmdMsg = true); + void clearMessages(bool clearCmdMsg = true); + private: + using SendMap = std::map; + SendMap sendMap; + std::deque receivedMsgs; + + void clearEmptyEntries(); + ReturnValue_t receiveMessage(MessageQueueMessageIF* message) override; + static ReturnValue_t clearLastSentMessage(SendMap::iterator& iter, bool clearCmdMsg = true); + static void createMsgCopy(MessageQueueMessageIF& into, MessageQueueMessageIF& from); }; #endif /* FSFW_UNITTEST_TESTS_MOCKS_MESSAGEQUEUEMOCKBASE_H_ */ diff --git a/unittests/serialize/testSerializeIF.cpp b/unittests/serialize/testSerializeIF.cpp index b619025a..ecd61357 100644 --- a/unittests/serialize/testSerializeIF.cpp +++ b/unittests/serialize/testSerializeIF.cpp @@ -65,7 +65,8 @@ TEST_CASE("Serialize IF Serialize", "[serialize-if-ser]") { HasReturnvaluesIF::RETURN_OK); } SECTION("Network 1") { - REQUIRE(simpleSer.SerializeIF::serializeBe(buf.data(), buf.size()) == HasReturnvaluesIF::RETURN_OK); + REQUIRE(simpleSer.SerializeIF::serializeBe(buf.data(), buf.size()) == + HasReturnvaluesIF::RETURN_OK); } CHECK(buf[0] == 1); CHECK(buf[1] == 2); @@ -154,7 +155,8 @@ TEST_CASE("SerializeIF Deserialize", "[serialize-if-de]") { HasReturnvaluesIF::RETURN_OK); } SECTION("Network 1") { - REQUIRE(simpleSer.SerializeIF::deSerializeBe(buf.data(), buf.size()) == HasReturnvaluesIF::RETURN_OK); + REQUIRE(simpleSer.SerializeIF::deSerializeBe(buf.data(), buf.size()) == + HasReturnvaluesIF::RETURN_OK); } CHECK(simpleSer.getU8() == 5); CHECK(simpleSer.getU16() == 1); diff --git a/unittests/testcfg/objects/systemObjectList.h b/unittests/testcfg/objects/systemObjectList.h index 7d12e5c6..1e86d5f7 100644 --- a/unittests/testcfg/objects/systemObjectList.h +++ b/unittests/testcfg/objects/systemObjectList.h @@ -31,4 +31,4 @@ enum sourceObjects : uint32_t { }; } -#endif /* BSP_CONFIG_OBJECTS_SYSTEMOBJECTLIST_H_ */ +#endif /* HOSTED_CONFIG_OBJECTS_SYSTEMOBJECTLIST_H_ */ diff --git a/unittests/tmtcservices/testSendHelper.cpp b/unittests/tmtcservices/testSendHelper.cpp index 6e6fb069..9877d2ef 100644 --- a/unittests/tmtcservices/testSendHelper.cpp +++ b/unittests/tmtcservices/testSendHelper.cpp @@ -9,7 +9,5 @@ TEST_CASE("TM Send Helper", "[tm-send-helper]") { auto msgQueue = MessageQueueMockBase(); TmSendHelper sendHelper(&msgQueue, &errReporter); - SECTION("State") { - - } + SECTION("State") {} } \ No newline at end of file -- 2.43.0 From 935e135f1c4235772eb0748314df9192bb59d789 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Mon, 25 Jul 2022 19:42:05 +0200 Subject: [PATCH 050/108] normal queue sufficient --- unittests/action/TestActionHelper.cpp | 4 +- unittests/mocks/CMakeLists.txt | 2 +- unittests/mocks/LocalPoolOwnerBase.h | 2 +- ...QueueMockBase.cpp => MessageQueueMock.cpp} | 63 +++++++++---------- ...sageQueueMockBase.h => MessageQueueMock.h} | 12 ++-- unittests/osal/CMakeLists.txt | 2 +- .../osal/{TestMessageQueue.cpp => testMq.cpp} | 0 unittests/tmtcservices/testSendHelper.cpp | 2 +- 8 files changed, 42 insertions(+), 45 deletions(-) rename unittests/mocks/{MessageQueueMockBase.cpp => MessageQueueMock.cpp} (63%) rename unittests/mocks/{MessageQueueMockBase.h => MessageQueueMock.h} (89%) rename unittests/osal/{TestMessageQueue.cpp => testMq.cpp} (100%) diff --git a/unittests/action/TestActionHelper.cpp b/unittests/action/TestActionHelper.cpp index 952f4572..bf5589ab 100644 --- a/unittests/action/TestActionHelper.cpp +++ b/unittests/action/TestActionHelper.cpp @@ -6,11 +6,11 @@ #include #include -#include "mocks/MessageQueueMockBase.h" +#include "mocks/MessageQueueMock.h" TEST_CASE("Action Helper", "[ActionHelper]") { ActionHelperOwnerMockBase testDhMock; - MessageQueueMockBase testMqMock; + MessageQueueMock testMqMock; ActionHelper actionHelper = ActionHelper(&testDhMock, dynamic_cast(&testMqMock)); CommandMessage actionMessage; ActionId_t testActionId = 777; diff --git a/unittests/mocks/CMakeLists.txt b/unittests/mocks/CMakeLists.txt index 04024559..9ecb013a 100644 --- a/unittests/mocks/CMakeLists.txt +++ b/unittests/mocks/CMakeLists.txt @@ -4,6 +4,6 @@ target_sources(${FSFW_TEST_TGT} PRIVATE DeviceFdirMock.cpp CookieIFMock.cpp ComIFMock.cpp - MessageQueueMockBase.cpp + MessageQueueMock.cpp InternalErrorReporterMock.cpp ) diff --git a/unittests/mocks/LocalPoolOwnerBase.h b/unittests/mocks/LocalPoolOwnerBase.h index 1dcd6cf2..132885ac 100644 --- a/unittests/mocks/LocalPoolOwnerBase.h +++ b/unittests/mocks/LocalPoolOwnerBase.h @@ -10,7 +10,7 @@ #include #include -#include "../mocks/MessageQueueMockBase.h" +#include "../mocks/MessageQueueMock.h" #include "tests/TestsConfig.h" namespace lpool { diff --git a/unittests/mocks/MessageQueueMockBase.cpp b/unittests/mocks/MessageQueueMock.cpp similarity index 63% rename from unittests/mocks/MessageQueueMockBase.cpp rename to unittests/mocks/MessageQueueMock.cpp index 16388e25..cb9bf0b7 100644 --- a/unittests/mocks/MessageQueueMockBase.cpp +++ b/unittests/mocks/MessageQueueMock.cpp @@ -1,21 +1,21 @@ -#include "MessageQueueMockBase.h" +#include "MessageQueueMock.h" #include #include -MessageQueueMockBase::MessageQueueMockBase() +MessageQueueMock::MessageQueueMock() : MessageQueueBase(MessageQueueIF::NO_QUEUE, MessageQueueIF::NO_QUEUE, nullptr) {} -MessageQueueMockBase::MessageQueueMockBase(MessageQueueId_t queueId) +MessageQueueMock::MessageQueueMock(MessageQueueId_t queueId) : MessageQueueBase(queueId, MessageQueueIF::NO_QUEUE, nullptr) {} -bool MessageQueueMockBase::wasMessageSent() const { +bool MessageQueueMock::wasMessageSent() const { return std::any_of( sendMap.begin(), sendMap.end(), [](const std::pair& pair) { return pair.second.callCount > 0; }); } -size_t MessageQueueMockBase::numberOfSentMessage() const { +size_t MessageQueueMock::numberOfSentMessage() const { size_t callCount = 0; for (auto& destInfo : sendMap) { callCount += destInfo.second.callCount; @@ -23,7 +23,7 @@ size_t MessageQueueMockBase::numberOfSentMessage() const { return callCount; } -size_t MessageQueueMockBase::numberOfSentMessage(MessageQueueId_t id) const { +size_t MessageQueueMock::numberOfSentMessage(MessageQueueId_t id) const { auto iter = sendMap.find(id); if (iter == sendMap.end()) { return 0; @@ -31,7 +31,7 @@ size_t MessageQueueMockBase::numberOfSentMessage(MessageQueueId_t id) const { return iter->second.callCount; } -ReturnValue_t MessageQueueMockBase::clearLastReceivedMessage(bool clearCmdMsg) { +ReturnValue_t MessageQueueMock::clearLastReceivedMessage(bool clearCmdMsg) { if (receivedMsgs.empty()) { return MessageQueueIF::EMPTY; } @@ -40,26 +40,24 @@ ReturnValue_t MessageQueueMockBase::clearLastReceivedMessage(bool clearCmdMsg) { std::memcpy(message.getBuffer(), receivedMsgs.front().getBuffer(), message.getMessageSize()); message.clearCommandMessage(); } - receivedMsgs.pop_front(); + receivedMsgs.pop(); return HasReturnvaluesIF::RETURN_OK; } -ReturnValue_t MessageQueueMockBase::receiveMessage(MessageQueueMessageIF* message) { +ReturnValue_t MessageQueueMock::receiveMessage(MessageQueueMessageIF* message) { if (receivedMsgs.empty()) { return MessageQueueIF::EMPTY; } std::memcpy(message->getBuffer(), receivedMsgs.front().getBuffer(), message->getMessageSize()); - receivedMsgs.pop_front(); + receivedMsgs.pop(); return HasReturnvaluesIF::RETURN_OK; } -ReturnValue_t MessageQueueMockBase::flush(uint32_t* count) { - return HasReturnvaluesIF::RETURN_FAILED; -} +ReturnValue_t MessageQueueMock::flush(uint32_t* count) { return HasReturnvaluesIF::RETURN_FAILED; } -ReturnValue_t MessageQueueMockBase::sendMessageFrom(MessageQueueId_t sendTo, - MessageQueueMessageIF* message, - MessageQueueId_t sentFrom, bool ignoreFault) { +ReturnValue_t MessageQueueMock::sendMessageFrom(MessageQueueId_t sendTo, + MessageQueueMessageIF* message, + MessageQueueId_t sentFrom, bool ignoreFault) { if (message == nullptr) { return HasReturnvaluesIF::RETURN_FAILED; } @@ -71,48 +69,48 @@ ReturnValue_t MessageQueueMockBase::sendMessageFrom(MessageQueueId_t sendTo, } else { iter->second.callCount += 1; createMsgCopy(messageCopy, *message); - iter->second.msgs.push_back(messageCopy); + iter->second.msgs.push(messageCopy); } return HasReturnvaluesIF::RETURN_OK; } -ReturnValue_t MessageQueueMockBase::reply(MessageQueueMessageIF* message) { +ReturnValue_t MessageQueueMock::reply(MessageQueueMessageIF* message) { return sendMessageFrom(MessageQueueIF::NO_QUEUE, message, this->getId(), false); } -void MessageQueueMockBase::clearMessages(bool clearCommandMessages) { +void MessageQueueMock::clearMessages(bool clearCommandMessages) { if (not clearCommandMessages) { sendMap.clear(); return; } for (auto& destInfo : sendMap) { - for (auto& msg : destInfo.second.msgs) { + while (!destInfo.second.msgs.empty()) { CommandMessage message; std::memcpy(message.getBuffer(), destInfo.second.msgs.front().getBuffer(), message.getMessageSize()); message.clear(); - destInfo.second.msgs.pop_front(); + destInfo.second.msgs.pop(); destInfo.second.callCount--; } } sendMap.clear(); } -void MessageQueueMockBase::addReceivedMessage(MessageQueueMessageIF& msg) { +void MessageQueueMock::addReceivedMessage(MessageQueueMessageIF& msg) { MessageQueueMessage messageCopy; createMsgCopy(messageCopy, msg); - receivedMsgs.push_back(messageCopy); + receivedMsgs.push(messageCopy); } -void MessageQueueMockBase::createMsgCopy(MessageQueueMessageIF& into, MessageQueueMessageIF& from) { +void MessageQueueMock::createMsgCopy(MessageQueueMessageIF& into, MessageQueueMessageIF& from) { if (from.getMessageSize() > into.getMaximumDataSize()) { throw std::invalid_argument("Passed message does not fit into message copy"); } std::memcpy(into.getBuffer(), from.getBuffer(), from.getMaximumDataSize()); } -ReturnValue_t MessageQueueMockBase::getNextSentMessage(MessageQueueId_t id, - MessageQueueMessageIF& message) { +ReturnValue_t MessageQueueMock::getNextSentMessage(MessageQueueId_t id, + MessageQueueMessageIF& message) { auto iter = sendMap.find(id); if (iter == sendMap.end() or iter->second.callCount == 0) { return MessageQueueIF::EMPTY; @@ -121,12 +119,11 @@ ReturnValue_t MessageQueueMockBase::getNextSentMessage(MessageQueueId_t id, return HasReturnvaluesIF::RETURN_OK; } -ReturnValue_t MessageQueueMockBase::getNextSentMessage(MessageQueueMessageIF& message) { +ReturnValue_t MessageQueueMock::getNextSentMessage(MessageQueueMessageIF& message) { return getNextSentMessage(MessageQueueBase::getDefaultDestination(), message); } -ReturnValue_t MessageQueueMockBase::clearLastSentMessage(MessageQueueId_t destId, - bool clearCmdMsg) { +ReturnValue_t MessageQueueMock::clearLastSentMessage(MessageQueueId_t destId, bool clearCmdMsg) { auto iter = sendMap.find(destId); if (iter == sendMap.end()) { return MessageQueueIF::EMPTY; @@ -134,7 +131,7 @@ ReturnValue_t MessageQueueMockBase::clearLastSentMessage(MessageQueueId_t destId return clearLastSentMessage(iter, clearCmdMsg); } -ReturnValue_t MessageQueueMockBase::clearLastSentMessage(bool clearCmdMsg) { +ReturnValue_t MessageQueueMock::clearLastSentMessage(bool clearCmdMsg) { auto iter = sendMap.find(getDefaultDestination()); if (iter == sendMap.end()) { return MessageQueueIF::EMPTY; @@ -144,7 +141,7 @@ ReturnValue_t MessageQueueMockBase::clearLastSentMessage(bool clearCmdMsg) { return result; } -ReturnValue_t MessageQueueMockBase::clearLastSentMessage( +ReturnValue_t MessageQueueMock::clearLastSentMessage( std::map::iterator& iter, bool clearCmdMsg) { if (clearCmdMsg) { CommandMessage message; @@ -152,11 +149,11 @@ ReturnValue_t MessageQueueMockBase::clearLastSentMessage( message.getMessageSize()); message.clear(); } - iter->second.msgs.pop_front(); + iter->second.msgs.pop(); iter->second.callCount--; return HasReturnvaluesIF::RETURN_OK; } -void MessageQueueMockBase::clearEmptyEntries() { +void MessageQueueMock::clearEmptyEntries() { for (auto it = sendMap.cbegin(); it != sendMap.cend();) { if (it->second.callCount == 0) { sendMap.erase(it++); diff --git a/unittests/mocks/MessageQueueMockBase.h b/unittests/mocks/MessageQueueMock.h similarity index 89% rename from unittests/mocks/MessageQueueMockBase.h rename to unittests/mocks/MessageQueueMock.h index fa63b171..fbfa1ba9 100644 --- a/unittests/mocks/MessageQueueMockBase.h +++ b/unittests/mocks/MessageQueueMock.h @@ -14,18 +14,18 @@ struct SendInfo { explicit SendInfo(MessageQueueMessage& initMsg, unsigned int initCallCnt = 1) : callCount(initCallCnt) { - msgs.push_back(initMsg); + msgs.push(initMsg); } unsigned int callCount = 0; - std::deque msgs; + std::queue msgs; }; -class MessageQueueMockBase : public MessageQueueBase { +class MessageQueueMock : public MessageQueueBase { public: - MessageQueueMockBase(); + MessageQueueMock(); void addReceivedMessage(MessageQueueMessageIF& msg); - explicit MessageQueueMockBase(MessageQueueId_t queueId); + explicit MessageQueueMock(MessageQueueId_t queueId); //! Get next message which was sent to the default destination ReturnValue_t getNextSentMessage(MessageQueueMessageIF& message); @@ -52,7 +52,7 @@ class MessageQueueMockBase : public MessageQueueBase { private: using SendMap = std::map; SendMap sendMap; - std::deque receivedMsgs; + std::queue receivedMsgs; void clearEmptyEntries(); ReturnValue_t receiveMessage(MessageQueueMessageIF* message) override; diff --git a/unittests/osal/CMakeLists.txt b/unittests/osal/CMakeLists.txt index 030d363b..0c93eba1 100644 --- a/unittests/osal/CMakeLists.txt +++ b/unittests/osal/CMakeLists.txt @@ -1,5 +1,5 @@ target_sources(${FSFW_TEST_TGT} PRIVATE - TestMessageQueue.cpp + testMq.cpp TestSemaphore.cpp TestClock.cpp ) diff --git a/unittests/osal/TestMessageQueue.cpp b/unittests/osal/testMq.cpp similarity index 100% rename from unittests/osal/TestMessageQueue.cpp rename to unittests/osal/testMq.cpp diff --git a/unittests/tmtcservices/testSendHelper.cpp b/unittests/tmtcservices/testSendHelper.cpp index 9877d2ef..09d34a50 100644 --- a/unittests/tmtcservices/testSendHelper.cpp +++ b/unittests/tmtcservices/testSendHelper.cpp @@ -2,7 +2,7 @@ #include "fsfw/tmtcservices/TmSendHelper.h" #include "mocks/InternalErrorReporterMock.h" -#include "mocks/MessageQueueMockBase.h" +#include "mocks/MessageQueueMock.h" TEST_CASE("TM Send Helper", "[tm-send-helper]") { auto errReporter = InternalErrorReporterMock(); -- 2.43.0 From a88f767ccacdb8e1c30c61075493972e71bbc3d6 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Mon, 25 Jul 2022 19:49:19 +0200 Subject: [PATCH 051/108] all tests running again --- unittests/datapoollocal/CMakeLists.txt | 1 - unittests/datapoollocal/testDataSet.cpp | 5 +++-- unittests/datapoollocal/testLocalPoolManager.cpp | 6 +++--- unittests/datapoollocal/testLocalPoolVariable.cpp | 13 +++++-------- unittests/datapoollocal/testLocalPoolVector.cpp | 10 ++++------ unittests/mocks/CMakeLists.txt | 1 + unittests/mocks/LocalPoolOwnerBase.h | 4 ++-- unittests/tmtcservices/testSendHelper.cpp | 6 ++++-- 8 files changed, 22 insertions(+), 24 deletions(-) diff --git a/unittests/datapoollocal/CMakeLists.txt b/unittests/datapoollocal/CMakeLists.txt index 6b8946a2..016645fd 100644 --- a/unittests/datapoollocal/CMakeLists.txt +++ b/unittests/datapoollocal/CMakeLists.txt @@ -3,5 +3,4 @@ target_sources(${FSFW_TEST_TGT} PRIVATE testLocalPoolVector.cpp testDataSet.cpp testLocalPoolManager.cpp - LocalPoolOwnerBase.cpp ) diff --git a/unittests/datapoollocal/testDataSet.cpp b/unittests/datapoollocal/testDataSet.cpp index 62bf59bb..0ef5a77f 100644 --- a/unittests/datapoollocal/testDataSet.cpp +++ b/unittests/datapoollocal/testDataSet.cpp @@ -9,11 +9,12 @@ #include #include "CatchDefinitions.h" -#include "LocalPoolOwnerBase.h" +#include "mocks/LocalPoolOwnerBase.h" +#include "mocks/MessageQueueMock.h" #include "tests/TestsConfig.h" TEST_CASE("DataSetTest", "[DataSetTest]") { - auto queue = MessageQueueMockBase(); + auto queue = MessageQueueMock(); LocalPoolOwnerBase poolOwner(queue, objects::TEST_LOCAL_POOL_OWNER_BASE); REQUIRE(poolOwner.initializeHkManager() == retval::CATCH_OK); REQUIRE(poolOwner.initializeHkManagerAfterTaskCreation() == retval::CATCH_OK); diff --git a/unittests/datapoollocal/testLocalPoolManager.cpp b/unittests/datapoollocal/testLocalPoolManager.cpp index 9c979df2..228ab08c 100644 --- a/unittests/datapoollocal/testLocalPoolManager.cpp +++ b/unittests/datapoollocal/testLocalPoolManager.cpp @@ -12,7 +12,7 @@ #include #include "CatchDefinitions.h" -#include "LocalPoolOwnerBase.h" +#include "mocks/LocalPoolOwnerBase.h" #include "mocks/HkReceiverMock.h" TEST_CASE("Local Pool Manager Tests", "[LocManTest]") { @@ -20,12 +20,12 @@ TEST_CASE("Local Pool Manager Tests", "[LocManTest]") { const MessageQueueId_t hkDest = defaultDestId; const MessageQueueId_t subscriberId = 2; auto hkReceiver = HkReceiverMock(hkDest); - auto queue = MessageQueueMockBase(); + auto queue = MessageQueueMock(); LocalPoolOwnerBase poolOwner(queue, objects::TEST_LOCAL_POOL_OWNER_BASE); REQUIRE(poolOwner.initializeHkManager() == retval::CATCH_OK); REQUIRE(poolOwner.initializeHkManagerAfterTaskCreation() == retval::CATCH_OK); - MessageQueueMockBase& poolOwnerMock = poolOwner.getMockQueueHandle(); + MessageQueueMock& poolOwnerMock = poolOwner.getMockQueueHandle(); // TODO: This is ugly. This should be an arbitrary ctor argument. Fix this in the pool // manager diff --git a/unittests/datapoollocal/testLocalPoolVariable.cpp b/unittests/datapoollocal/testLocalPoolVariable.cpp index 3479cdbe..dda5aca6 100644 --- a/unittests/datapoollocal/testLocalPoolVariable.cpp +++ b/unittests/datapoollocal/testLocalPoolVariable.cpp @@ -4,15 +4,14 @@ #include #include "CatchDefinitions.h" -#include "LocalPoolOwnerBase.h" +#include "mocks/LocalPoolOwnerBase.h" #include "tests/TestsConfig.h" TEST_CASE("LocalPoolVariable", "[LocPoolVarTest]") { - auto* poolOwner = - ObjectManager::instance()->get(objects::TEST_LOCAL_POOL_OWNER_BASE); - REQUIRE(poolOwner != nullptr); - REQUIRE(poolOwner->initializeHkManager() == retval::CATCH_OK); - REQUIRE(poolOwner->initializeHkManagerAfterTaskCreation() == retval::CATCH_OK); + auto queue = MessageQueueMock(); + LocalPoolOwnerBase poolOwner(queue, objects::TEST_LOCAL_POOL_OWNER_BASE); + REQUIRE(poolOwner.initializeHkManager() == retval::CATCH_OK); + REQUIRE(poolOwner.initializeHkManagerAfterTaskCreation() == retval::CATCH_OK); SECTION("Basic Tests") { /* very basic test. */ @@ -106,6 +105,4 @@ TEST_CASE("LocalPoolVariable", "[LocPoolVarTest]") { lp_var_t invalidObjectVar2 = lp_var_t(globPoolId); lp_var_t invalidObjectVar3 = lp_var_t(nullptr, lpool::uint8VarId); } - - CHECK(poolOwner->reset() == retval::CATCH_OK); } diff --git a/unittests/datapoollocal/testLocalPoolVector.cpp b/unittests/datapoollocal/testLocalPoolVector.cpp index 331d4e09..dc91fa7e 100644 --- a/unittests/datapoollocal/testLocalPoolVector.cpp +++ b/unittests/datapoollocal/testLocalPoolVector.cpp @@ -8,11 +8,10 @@ #include "tests/TestsConfig.h" TEST_CASE("LocalPoolVector", "[LocPoolVecTest]") { - auto* poolOwner = - ObjectManager::instance()->get(objects::TEST_LOCAL_POOL_OWNER_BASE); - REQUIRE(poolOwner != nullptr); - REQUIRE(poolOwner->initializeHkManager() == retval::CATCH_OK); - REQUIRE(poolOwner->initializeHkManagerAfterTaskCreation() == retval::CATCH_OK); + auto queue = MessageQueueMock(); + LocalPoolOwnerBase poolOwner(queue, objects::TEST_LOCAL_POOL_OWNER_BASE); + REQUIRE(poolOwner.initializeHkManager() == retval::CATCH_OK); + REQUIRE(poolOwner.initializeHkManagerAfterTaskCreation() == retval::CATCH_OK); SECTION("BasicTest") { // very basic test. @@ -106,5 +105,4 @@ TEST_CASE("LocalPoolVector", "[LocPoolVecTest]") { objects::TEST_LOCAL_POOL_OWNER_BASE, lpool::uint16Vec3Id, nullptr, pool_rwm_t::VAR_READ); REQUIRE(readOnlyVec.commit() == static_cast(PoolVariableIF::INVALID_READ_WRITE_MODE)); } - poolOwner->reset(); } diff --git a/unittests/mocks/CMakeLists.txt b/unittests/mocks/CMakeLists.txt index 9ecb013a..7bc8fd30 100644 --- a/unittests/mocks/CMakeLists.txt +++ b/unittests/mocks/CMakeLists.txt @@ -6,4 +6,5 @@ target_sources(${FSFW_TEST_TGT} PRIVATE ComIFMock.cpp MessageQueueMock.cpp InternalErrorReporterMock.cpp + LocalPoolOwnerBase.cpp ) diff --git a/unittests/mocks/LocalPoolOwnerBase.h b/unittests/mocks/LocalPoolOwnerBase.h index 132885ac..329aa0b3 100644 --- a/unittests/mocks/LocalPoolOwnerBase.h +++ b/unittests/mocks/LocalPoolOwnerBase.h @@ -98,8 +98,8 @@ class LocalPoolOwnerBase : public SystemObject, public HasLocalDataPoolIF { LocalPoolObjectBase* getPoolObjectHandle(lp_id_t localPoolId) override; - [[nodiscard]] MessageQueueMockBase& getMockQueueHandle() const { - return dynamic_cast(queue); + [[nodiscard]] MessageQueueMock& getMockQueueHandle() const { + return dynamic_cast(queue); } ReturnValue_t subscribePeriodicHk(bool enableReporting) { diff --git a/unittests/tmtcservices/testSendHelper.cpp b/unittests/tmtcservices/testSendHelper.cpp index 09d34a50..fc5b86bd 100644 --- a/unittests/tmtcservices/testSendHelper.cpp +++ b/unittests/tmtcservices/testSendHelper.cpp @@ -1,4 +1,5 @@ #include +#include #include "fsfw/tmtcservices/TmSendHelper.h" #include "mocks/InternalErrorReporterMock.h" @@ -6,8 +7,9 @@ TEST_CASE("TM Send Helper", "[tm-send-helper]") { auto errReporter = InternalErrorReporterMock(); - auto msgQueue = MessageQueueMockBase(); + auto msgQueue = MessageQueueMock(); TmSendHelper sendHelper(&msgQueue, &errReporter); - SECTION("State") {} + SECTION("State") { + } } \ No newline at end of file -- 2.43.0 From 586993c081b953963d2eb9ac635cd46391212357 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Mon, 25 Jul 2022 20:31:06 +0200 Subject: [PATCH 052/108] completed send helper tests --- src/fsfw/pus/Service17Test.cpp | 5 +- .../pus/Service1TelecommandVerification.cpp | 1 - src/fsfw/pus/Service5EventReporting.cpp | 1 - src/fsfw/storagemanager/LocalPool.cpp | 15 ++- src/fsfw/storagemanager/LocalPool.h | 1 + src/fsfw/storagemanager/StorageManagerIF.h | 2 + .../tmtcservices/CommandingServiceBase.cpp | 1 - src/fsfw/tmtcservices/PusServiceBase.cpp | 4 +- src/fsfw/tmtcservices/TmSendHelper.cpp | 34 ++++--- src/fsfw/tmtcservices/TmSendHelper.h | 22 +++-- .../datapoollocal/testLocalPoolManager.cpp | 50 +++++----- unittests/mocks/InternalErrorReporterMock.cpp | 6 ++ unittests/mocks/InternalErrorReporterMock.h | 5 +- unittests/mocks/MessageQueueMock.cpp | 16 +++- unittests/mocks/MessageQueueMock.h | 7 +- unittests/storagemanager/CMakeLists.txt | 4 +- .../{TestNewAccessor.cpp => testAccessor.cpp} | 6 +- .../{TestPool.cpp => testPool.cpp} | 9 +- unittests/tmtcservices/testSendHelper.cpp | 92 ++++++++++++++++++- 19 files changed, 211 insertions(+), 70 deletions(-) rename unittests/storagemanager/{TestNewAccessor.cpp => testAccessor.cpp} (98%) rename unittests/storagemanager/{TestPool.cpp => testPool.cpp} (97%) diff --git a/src/fsfw/pus/Service17Test.cpp b/src/fsfw/pus/Service17Test.cpp index d7c5a71b..631cf939 100644 --- a/src/fsfw/pus/Service17Test.cpp +++ b/src/fsfw/pus/Service17Test.cpp @@ -6,10 +6,7 @@ #include "fsfw/tmtcservices/tmHelpers.h" Service17Test::Service17Test(object_id_t objectId, uint16_t apid, uint8_t serviceId) - : PusServiceBase(objectId, apid, serviceId), - storeHelper(apid), - sendHelper(nullptr), - packetSubCounter(0) {} + : PusServiceBase(objectId, apid, serviceId), storeHelper(apid), packetSubCounter(0) {} Service17Test::~Service17Test() = default; diff --git a/src/fsfw/pus/Service1TelecommandVerification.cpp b/src/fsfw/pus/Service1TelecommandVerification.cpp index 624a73d0..7b5e7973 100644 --- a/src/fsfw/pus/Service1TelecommandVerification.cpp +++ b/src/fsfw/pus/Service1TelecommandVerification.cpp @@ -15,7 +15,6 @@ Service1TelecommandVerification::Service1TelecommandVerification(object_id_t obj apid(apid), serviceId(serviceId), targetDestination(targetDestination), - sendHelper(nullptr), storeHelper(apid) { tmQueue = QueueFactory::instance()->createMessageQueue(messageQueueDepth); } diff --git a/src/fsfw/pus/Service5EventReporting.cpp b/src/fsfw/pus/Service5EventReporting.cpp index e9c9c095..44f7861a 100644 --- a/src/fsfw/pus/Service5EventReporting.cpp +++ b/src/fsfw/pus/Service5EventReporting.cpp @@ -11,7 +11,6 @@ Service5EventReporting::Service5EventReporting(object_id_t objectId, uint16_t ap uint8_t serviceId, size_t maxNumberReportsPerCycle, uint32_t messageQueueDepth) : PusServiceBase(objectId, apid, serviceId), - sendHelper(nullptr), storeHelper(apid), maxNumberReportsPerCycle(maxNumberReportsPerCycle) { eventQueue = QueueFactory::instance()->createMessageQueue(messageQueueDepth); diff --git a/src/fsfw/storagemanager/LocalPool.cpp b/src/fsfw/storagemanager/LocalPool.cpp index cee1d407..f8b2bdb3 100644 --- a/src/fsfw/storagemanager/LocalPool.cpp +++ b/src/fsfw/storagemanager/LocalPool.cpp @@ -194,8 +194,6 @@ void LocalPool::clearStore() { for (auto& size : sizeList) { size = STORAGE_FREE; } - // std::memset(sizeList[index], 0xff, - // numberOfElements[index] * sizeof(size_type)); } } @@ -338,3 +336,16 @@ void LocalPool::clearSubPool(max_subpools_t subpoolIndex) { } LocalPool::max_subpools_t LocalPool::getNumberOfSubPools() const { return NUMBER_OF_SUBPOOLS; } + +bool LocalPool::hasDataAtId(store_address_t storeId) const { + if (storeId.poolIndex >= NUMBER_OF_SUBPOOLS) { + return false; + } + if ((storeId.packetIndex >= numberOfElements[storeId.poolIndex])) { + return false; + } + if (sizeLists[storeId.poolIndex][storeId.packetIndex] != STORAGE_FREE) { + return true; + } + return false; +} diff --git a/src/fsfw/storagemanager/LocalPool.h b/src/fsfw/storagemanager/LocalPool.h index 47f84955..1c1d4006 100644 --- a/src/fsfw/storagemanager/LocalPool.h +++ b/src/fsfw/storagemanager/LocalPool.h @@ -132,6 +132,7 @@ class LocalPool : public SystemObject, public StorageManagerIF { * @return */ max_subpools_t getNumberOfSubPools() const override; + bool hasDataAtId(store_address_t storeId) const override; protected: /** diff --git a/src/fsfw/storagemanager/StorageManagerIF.h b/src/fsfw/storagemanager/StorageManagerIF.h index a8313344..90ea4587 100644 --- a/src/fsfw/storagemanager/StorageManagerIF.h +++ b/src/fsfw/storagemanager/StorageManagerIF.h @@ -163,6 +163,8 @@ class StorageManagerIF : public HasReturnvaluesIF { virtual ReturnValue_t getFreeElement(store_address_t* storageId, size_t size, uint8_t** p_data, bool ignoreFault = false) = 0; + [[nodiscard]] virtual bool hasDataAtId(store_address_t storeId) const = 0; + /** * Clears the whole store. * Use with care! diff --git a/src/fsfw/tmtcservices/CommandingServiceBase.cpp b/src/fsfw/tmtcservices/CommandingServiceBase.cpp index 3fac5bd2..10cc2689 100644 --- a/src/fsfw/tmtcservices/CommandingServiceBase.cpp +++ b/src/fsfw/tmtcservices/CommandingServiceBase.cpp @@ -21,7 +21,6 @@ CommandingServiceBase::CommandingServiceBase(object_id_t setObjectId, uint16_t a service(service), timeoutSeconds(commandTimeoutSeconds), tmStoreHelper(apid), - tmSendHelper(nullptr), commandMap(numberOfParallelCommands) { commandQueue = QueueFactory::instance()->createMessageQueue(queueDepth); requestQueue = QueueFactory::instance()->createMessageQueue(queueDepth); diff --git a/src/fsfw/tmtcservices/PusServiceBase.cpp b/src/fsfw/tmtcservices/PusServiceBase.cpp index 6a21b65b..26f08694 100644 --- a/src/fsfw/tmtcservices/PusServiceBase.cpp +++ b/src/fsfw/tmtcservices/PusServiceBase.cpp @@ -131,8 +131,8 @@ void PusServiceBase::initializeTmHelpers(TmSendHelper& tmSendHelper, TmStoreHelp } void PusServiceBase::initializeTmSendHelper(TmSendHelper& tmSendHelper) { - tmSendHelper.setMsgQueue(requestQueue); - tmSendHelper.setMsgDestination(requestQueue->getDefaultDestination()); + tmSendHelper.setMsgQueue(*requestQueue); + tmSendHelper.setDefaultDestination(requestQueue->getDefaultDestination()); if (errReporter == nullptr) { errReporter = ObjectManager::instance()->get(objects::INTERNAL_ERROR_REPORTER); diff --git a/src/fsfw/tmtcservices/TmSendHelper.cpp b/src/fsfw/tmtcservices/TmSendHelper.cpp index 7b464ad8..0b9d854c 100644 --- a/src/fsfw/tmtcservices/TmSendHelper.cpp +++ b/src/fsfw/tmtcservices/TmSendHelper.cpp @@ -2,38 +2,50 @@ #include "fsfw/ipc/MessageQueueSenderIF.h" -TmSendHelper::TmSendHelper(MessageQueueIF *queue, InternalErrorReporterIF *reporter, +TmSendHelper::TmSendHelper() = default; + +TmSendHelper::TmSendHelper(MessageQueueIF &queue, InternalErrorReporterIF &reporter, MessageQueueId_t tmtcMsgDest) - : tmtcMsgDest(tmtcMsgDest), queue(queue), errReporter(reporter) {} + : defaultDest(tmtcMsgDest), queue(&queue), errReporter(&reporter) {} -TmSendHelper::TmSendHelper(MessageQueueIF *queue, InternalErrorReporterIF *reporter) - : queue(queue), errReporter(reporter) {} +TmSendHelper::TmSendHelper(MessageQueueIF &queue, InternalErrorReporterIF &reporter) + : queue(&queue), errReporter(&reporter) {} -TmSendHelper::TmSendHelper(InternalErrorReporterIF *reporter) : errReporter(reporter) {} +TmSendHelper::TmSendHelper(InternalErrorReporterIF &reporter) : errReporter(&reporter) {} ReturnValue_t TmSendHelper::sendPacket(const store_address_t &storeId) { if (queue == nullptr) { return HasReturnvaluesIF::RETURN_FAILED; } TmTcMessage message(storeId); - ReturnValue_t result = queue->sendMessage(tmtcMsgDest, &message, ignoreFault); + ReturnValue_t result = queue->sendMessage(defaultDest, &message, ignoreFault); if (result != HasReturnvaluesIF::RETURN_OK) { - if (errReporter != nullptr) { + if (errReporter != nullptr and not ignoreFault) { errReporter->lostTm(); } return result; } - return HasReturnvaluesIF::RETURN_OK; + return result; } -void TmSendHelper::setMsgDestination(MessageQueueId_t msgDest) { tmtcMsgDest = msgDest; } +void TmSendHelper::setDefaultDestination(MessageQueueId_t msgDest) { defaultDest = msgDest; } void TmSendHelper::setInternalErrorReporter(InternalErrorReporterIF *reporter) { errReporter = reporter; } -void TmSendHelper::setMsgQueue(MessageQueueIF *queue_) { queue = queue_; } +void TmSendHelper::setMsgQueue(MessageQueueIF &queue_) { queue = &queue_; } ReturnValue_t TmSendHelper::sendPacket(MessageQueueId_t dest, const store_address_t &storeId) { - setMsgDestination(dest); + setDefaultDestination(dest); return sendPacket(storeId); } + +MessageQueueId_t TmSendHelper::getDefaultDestination() const { return defaultDest; } + +bool TmSendHelper::areFaultsIgnored() const { return ignoreFault; } +void TmSendHelper::ignoreFaults() { ignoreFault = true; } +void TmSendHelper::dontIgnoreFaults() { ignoreFault = false; } + +InternalErrorReporterIF *TmSendHelper::getInternalErrorReporter() const { return errReporter; } + +MessageQueueIF *TmSendHelper::getMsgQueue() const { return queue; } diff --git a/src/fsfw/tmtcservices/TmSendHelper.h b/src/fsfw/tmtcservices/TmSendHelper.h index 4cb159da..dee5a495 100644 --- a/src/fsfw/tmtcservices/TmSendHelper.h +++ b/src/fsfw/tmtcservices/TmSendHelper.h @@ -9,22 +9,30 @@ class TmSendHelper { public: - TmSendHelper(MessageQueueIF* queue, InternalErrorReporterIF* reporter, + TmSendHelper(); + TmSendHelper(MessageQueueIF& queue, InternalErrorReporterIF& reporter, MessageQueueId_t tmtcMsgDest); - TmSendHelper(MessageQueueIF* queue, InternalErrorReporterIF* reporter); - explicit TmSendHelper(InternalErrorReporterIF* reporter); + TmSendHelper(MessageQueueIF& queue, InternalErrorReporterIF& reporter); + explicit TmSendHelper(InternalErrorReporterIF& reporter); - void setMsgQueue(MessageQueueIF* queue); - void setMsgDestination(MessageQueueId_t msgDest); + void setMsgQueue(MessageQueueIF& queue); + MessageQueueIF* getMsgQueue() const; + + void setDefaultDestination(MessageQueueId_t msgDest); + [[nodiscard]] MessageQueueId_t getDefaultDestination() const; + [[nodiscard]] bool areFaultsIgnored() const; + void ignoreFaults(); + void dontIgnoreFaults(); void setInternalErrorReporter(InternalErrorReporterIF* reporter); + [[nodiscard]] InternalErrorReporterIF* getInternalErrorReporter() const; ReturnValue_t sendPacket(MessageQueueId_t dest, const store_address_t& storeId); ReturnValue_t sendPacket(const store_address_t& storeId); private: - MessageQueueId_t tmtcMsgDest = MessageQueueIF::NO_QUEUE; + MessageQueueId_t defaultDest = MessageQueueIF::NO_QUEUE; bool ignoreFault = false; MessageQueueIF* queue = nullptr; - InternalErrorReporterIF* errReporter; + InternalErrorReporterIF* errReporter = nullptr; }; #endif // FSFW_TMTCPACKET_TMSENDHELPER_H diff --git a/unittests/datapoollocal/testLocalPoolManager.cpp b/unittests/datapoollocal/testLocalPoolManager.cpp index 228ab08c..e5282c16 100644 --- a/unittests/datapoollocal/testLocalPoolManager.cpp +++ b/unittests/datapoollocal/testLocalPoolManager.cpp @@ -12,8 +12,8 @@ #include #include "CatchDefinitions.h" -#include "mocks/LocalPoolOwnerBase.h" #include "mocks/HkReceiverMock.h" +#include "mocks/LocalPoolOwnerBase.h" TEST_CASE("Local Pool Manager Tests", "[LocManTest]") { const MessageQueueId_t defaultDestId = 1; @@ -65,7 +65,7 @@ TEST_CASE("Local Pool Manager Tests", "[LocManTest]") { REQUIRE(poolOwner.poolManager.performHkOperation() == retval::CATCH_OK); REQUIRE(poolOwnerMock.wasMessageSent() == true); - CHECK(poolOwnerMock.numberOfSentMessage() == 1); + CHECK(poolOwnerMock.numberOfSentMessages() == 1); REQUIRE(poolOwnerMock.getNextSentMessage(subscriberId, messageSent) == retval::CATCH_OK); CHECK(messageSent.getCommand() == static_cast(HousekeepingMessage::UPDATE_NOTIFICATION_SET)); @@ -76,7 +76,7 @@ TEST_CASE("Local Pool Manager Tests", "[LocManTest]") { poolOwner.dataset.setChanged(true); REQUIRE(poolOwner.poolManager.performHkOperation() == retval::CATCH_OK); REQUIRE(poolOwnerMock.wasMessageSent() == true); - CHECK(poolOwnerMock.numberOfSentMessage() == 2); + CHECK(poolOwnerMock.numberOfSentMessages() == 2); // first message sent should be the update notification REQUIRE(poolOwnerMock.getNextSentMessage(subscriberId, messageSent) == retval::CATCH_OK); CHECK(messageSent.getCommand() == @@ -110,7 +110,7 @@ TEST_CASE("Local Pool Manager Tests", "[LocManTest]") { /* Trigger generation of snapshot */ REQUIRE(poolOwner.poolManager.performHkOperation() == retval::CATCH_OK); REQUIRE(poolOwnerMock.wasMessageSent()); - CHECK(poolOwnerMock.numberOfSentMessage() == 1); + CHECK(poolOwnerMock.numberOfSentMessages() == 1); REQUIRE(poolOwnerMock.getNextSentMessage(subscriberId, messageSent) == retval::CATCH_OK); /* Check that snapshot was generated */ CHECK(messageSent.getCommand() == static_cast(HousekeepingMessage::UPDATE_SNAPSHOT_SET)); @@ -174,7 +174,7 @@ TEST_CASE("Local Pool Manager Tests", "[LocManTest]") { /* Check update snapshot was sent. */ REQUIRE(poolOwnerMock.wasMessageSent()); - CHECK(poolOwnerMock.numberOfSentMessage() == 1); + CHECK(poolOwnerMock.numberOfSentMessages() == 1); /* Should have been reset. */ CHECK(poolVar->hasChanged() == false); @@ -222,7 +222,7 @@ TEST_CASE("Local Pool Manager Tests", "[LocManTest]") { /* Check update notification was sent. */ REQUIRE(poolOwnerMock.wasMessageSent()); - CHECK(poolOwnerMock.numberOfSentMessage() == 1); + CHECK(poolOwnerMock.numberOfSentMessages() == 1); /* Should have been reset. */ CHECK(poolVar->hasChanged() == false); REQUIRE(poolOwnerMock.getNextSentMessage(subscriberId, messageSent) == retval::CATCH_OK); @@ -238,7 +238,7 @@ TEST_CASE("Local Pool Manager Tests", "[LocManTest]") { REQUIRE(poolOwner.poolManager.performHkOperation() == retval::CATCH_OK); /* Now two messages should be sent. */ REQUIRE(poolOwnerMock.wasMessageSent()); - CHECK(poolOwnerMock.numberOfSentMessage() == 2); + CHECK(poolOwnerMock.numberOfSentMessages() == 2); poolOwnerMock.clearMessages(true); poolOwner.dataset.setChanged(true); @@ -247,9 +247,9 @@ TEST_CASE("Local Pool Manager Tests", "[LocManTest]") { REQUIRE(poolOwner.poolManager.performHkOperation() == retval::CATCH_OK); /* Now three messages should be sent. */ REQUIRE(poolOwnerMock.wasMessageSent()); - CHECK(poolOwnerMock.numberOfSentMessage() == 3); - CHECK(poolOwnerMock.numberOfSentMessage(subscriberId) == 2); - CHECK(poolOwnerMock.numberOfSentMessage(hkDest) == 1); + CHECK(poolOwnerMock.numberOfSentMessages() == 3); + CHECK(poolOwnerMock.numberOfSentMessagesToDest(subscriberId) == 2); + CHECK(poolOwnerMock.numberOfSentMessagesToDest(hkDest) == 1); REQUIRE(poolOwnerMock.getNextSentMessage(subscriberId, messageSent) == retval::CATCH_OK); CHECK(messageSent.getCommand() == static_cast(HousekeepingMessage::UPDATE_NOTIFICATION_VARIABLE)); @@ -275,7 +275,7 @@ TEST_CASE("Local Pool Manager Tests", "[LocManTest]") { REQUIRE(poolOwner.poolManager.performHkOperation() == retval::CATCH_OK); /* Now HK packet should be sent as message immediately. */ REQUIRE(poolOwnerMock.wasMessageSent()); - CHECK(poolOwnerMock.numberOfSentMessage() == 1); + CHECK(poolOwnerMock.numberOfSentMessages() == 1); CHECK(poolOwnerMock.clearLastSentMessage() == retval::CATCH_OK); LocalPoolDataSetBase* setHandle = poolOwner.getDataSetHandle(lpool::testSid); @@ -283,7 +283,7 @@ TEST_CASE("Local Pool Manager Tests", "[LocManTest]") { CHECK(poolOwner.poolManager.generateHousekeepingPacket(lpool::testSid, setHandle, false) == retval::CATCH_OK); REQUIRE(poolOwnerMock.wasMessageSent()); - CHECK(poolOwnerMock.numberOfSentMessage() == 1); + CHECK(poolOwnerMock.numberOfSentMessages() == 1); CHECK(poolOwnerMock.clearLastSentMessage() == retval::CATCH_OK); CHECK(setHandle->getReportingEnabled() == true); @@ -292,7 +292,7 @@ TEST_CASE("Local Pool Manager Tests", "[LocManTest]") { CHECK(poolOwner.poolManager.handleHousekeepingMessage(&hkCmd) == retval::CATCH_OK); CHECK(setHandle->getReportingEnabled() == false); REQUIRE(poolOwnerMock.wasMessageSent()); - CHECK(poolOwnerMock.numberOfSentMessage() == 1); + CHECK(poolOwnerMock.numberOfSentMessages() == 1); CHECK(poolOwnerMock.clearLastSentMessage() == retval::CATCH_OK); HousekeepingMessage::setToggleReportingCommand(&hkCmd, lpool::testSid, true, false); @@ -314,7 +314,7 @@ TEST_CASE("Local Pool Manager Tests", "[LocManTest]") { resulting collection interval should be 1.0 second */ CHECK(poolOwner.dataset.getCollectionInterval() == 1.0); REQUIRE(poolOwnerMock.wasMessageSent()); - REQUIRE(poolOwnerMock.numberOfSentMessage() == 1); + REQUIRE(poolOwnerMock.numberOfSentMessages() == 1); CHECK(poolOwnerMock.clearLastSentMessage() == retval::CATCH_OK); HousekeepingMessage::setStructureReportingCommand(&hkCmd, lpool::testSid, false); @@ -322,13 +322,13 @@ TEST_CASE("Local Pool Manager Tests", "[LocManTest]") { CHECK(poolOwner.poolManager.handleHousekeepingMessage(&hkCmd) == retval::CATCH_OK); /* Now HK packet should be sent as message. */ REQUIRE(poolOwnerMock.wasMessageSent()); - REQUIRE(poolOwnerMock.numberOfSentMessage() == 1); + REQUIRE(poolOwnerMock.numberOfSentMessages() == 1); poolOwnerMock.clearMessages(); HousekeepingMessage::setOneShotReportCommand(&hkCmd, lpool::testSid, false); CHECK(poolOwner.poolManager.handleHousekeepingMessage(&hkCmd) == retval::CATCH_OK); REQUIRE(poolOwnerMock.wasMessageSent()); - REQUIRE(poolOwnerMock.numberOfSentMessage() == 1); + REQUIRE(poolOwnerMock.numberOfSentMessages() == 1); poolOwnerMock.clearMessages(); HousekeepingMessage::setUpdateNotificationSetCommand(&hkCmd, lpool::testSid); @@ -346,7 +346,7 @@ TEST_CASE("Local Pool Manager Tests", "[LocManTest]") { static_cast(LocalDataPoolManager::WRONG_HK_PACKET_TYPE)); /* We still expect a failure message being sent */ REQUIRE(poolOwnerMock.wasMessageSent()); - REQUIRE(poolOwnerMock.numberOfSentMessage() == 1); + REQUIRE(poolOwnerMock.numberOfSentMessages() == 1); CHECK(poolOwnerMock.clearLastSentMessage() == retval::CATCH_OK); HousekeepingMessage::setCollectionIntervalModificationCommand(&hkCmd, lpool::testSid, 0.4, @@ -354,52 +354,52 @@ TEST_CASE("Local Pool Manager Tests", "[LocManTest]") { CHECK(poolOwner.poolManager.handleHousekeepingMessage(&hkCmd) == static_cast(LocalDataPoolManager::WRONG_HK_PACKET_TYPE)); REQUIRE(poolOwnerMock.wasMessageSent()); - REQUIRE(poolOwnerMock.numberOfSentMessage() == 1); + REQUIRE(poolOwnerMock.numberOfSentMessages() == 1); CHECK(poolOwnerMock.clearLastSentMessage() == retval::CATCH_OK); HousekeepingMessage::setStructureReportingCommand(&hkCmd, lpool::testSid, false); CHECK(poolOwner.poolManager.handleHousekeepingMessage(&hkCmd) == static_cast(LocalDataPoolManager::WRONG_HK_PACKET_TYPE)); REQUIRE(poolOwnerMock.wasMessageSent()); - REQUIRE(poolOwnerMock.numberOfSentMessage() == 1); + REQUIRE(poolOwnerMock.numberOfSentMessages() == 1); CHECK(poolOwnerMock.clearLastSentMessage() == retval::CATCH_OK); HousekeepingMessage::setStructureReportingCommand(&hkCmd, lpool::testSid, true); CHECK(poolOwner.poolManager.handleHousekeepingMessage(&hkCmd) == retval::CATCH_OK); REQUIRE(poolOwnerMock.wasMessageSent()); - REQUIRE(poolOwnerMock.numberOfSentMessage() == 1); + REQUIRE(poolOwnerMock.numberOfSentMessages() == 1); poolOwnerMock.clearMessages(); HousekeepingMessage::setCollectionIntervalModificationCommand(&hkCmd, lpool::testSid, 0.4, true); CHECK(poolOwner.poolManager.handleHousekeepingMessage(&hkCmd) == retval::CATCH_OK); REQUIRE(poolOwnerMock.wasMessageSent()); - REQUIRE(poolOwnerMock.numberOfSentMessage() == 1); + REQUIRE(poolOwnerMock.numberOfSentMessages() == 1); poolOwnerMock.clearMessages(); HousekeepingMessage::setToggleReportingCommand(&hkCmd, lpool::testSid, true, true); CHECK(poolOwner.poolManager.handleHousekeepingMessage(&hkCmd) == retval::CATCH_OK); REQUIRE(poolOwnerMock.wasMessageSent()); - REQUIRE(poolOwnerMock.numberOfSentMessage() == 1); + REQUIRE(poolOwnerMock.numberOfSentMessages() == 1); poolOwnerMock.clearMessages(); HousekeepingMessage::setToggleReportingCommand(&hkCmd, lpool::testSid, false, true); CHECK(poolOwner.poolManager.handleHousekeepingMessage(&hkCmd) == retval::CATCH_OK); REQUIRE(poolOwnerMock.wasMessageSent()); - REQUIRE(poolOwnerMock.numberOfSentMessage() == 1); + REQUIRE(poolOwnerMock.numberOfSentMessages() == 1); poolOwnerMock.clearMessages(); HousekeepingMessage::setOneShotReportCommand(&hkCmd, lpool::testSid, false); CHECK(poolOwner.poolManager.handleHousekeepingMessage(&hkCmd) == static_cast(LocalDataPoolManager::WRONG_HK_PACKET_TYPE)); REQUIRE(poolOwnerMock.wasMessageSent()); - REQUIRE(poolOwnerMock.numberOfSentMessage() == 1); + REQUIRE(poolOwnerMock.numberOfSentMessages() == 1); poolOwnerMock.clearMessages(); HousekeepingMessage::setOneShotReportCommand(&hkCmd, lpool::testSid, true); CHECK(poolOwner.poolManager.handleHousekeepingMessage(&hkCmd) == retval::CATCH_OK); REQUIRE(poolOwnerMock.wasMessageSent()); - REQUIRE(poolOwnerMock.numberOfSentMessage() == 1); + REQUIRE(poolOwnerMock.numberOfSentMessages() == 1); poolOwnerMock.clearMessages(); HousekeepingMessage::setUpdateNotificationVariableCommand(&hkCmd, lpool::uint8VarGpid); diff --git a/unittests/mocks/InternalErrorReporterMock.cpp b/unittests/mocks/InternalErrorReporterMock.cpp index c7758a13..f53a1ed4 100644 --- a/unittests/mocks/InternalErrorReporterMock.cpp +++ b/unittests/mocks/InternalErrorReporterMock.cpp @@ -5,3 +5,9 @@ InternalErrorReporterMock::InternalErrorReporterMock() = default; void InternalErrorReporterMock::queueMessageNotSent() { queueMsgNotSentCallCnt++; } void InternalErrorReporterMock::lostTm() { lostTmCallCnt++; } void InternalErrorReporterMock::storeFull() { storeFullCallCnt++; } + +void InternalErrorReporterMock::reset() { + queueMsgNotSentCallCnt = 0; + lostTmCallCnt = 0; + storeFullCallCnt = 0; +} diff --git a/unittests/mocks/InternalErrorReporterMock.h b/unittests/mocks/InternalErrorReporterMock.h index f6babe09..e1ad35ae 100644 --- a/unittests/mocks/InternalErrorReporterMock.h +++ b/unittests/mocks/InternalErrorReporterMock.h @@ -9,10 +9,11 @@ class InternalErrorReporterMock : public InternalErrorReporterIF { unsigned int lostTmCallCnt = 0; unsigned int storeFullCallCnt = 0; InternalErrorReporterMock(); + void reset(); + + private: void queueMessageNotSent() override; void lostTm() override; void storeFull() override; - - private: }; #endif // FSFW_TESTS_INTERNALERRORREPORTERMOCK_H diff --git a/unittests/mocks/MessageQueueMock.cpp b/unittests/mocks/MessageQueueMock.cpp index cb9bf0b7..c514cc2e 100644 --- a/unittests/mocks/MessageQueueMock.cpp +++ b/unittests/mocks/MessageQueueMock.cpp @@ -15,7 +15,7 @@ bool MessageQueueMock::wasMessageSent() const { [](const std::pair& pair) { return pair.second.callCount > 0; }); } -size_t MessageQueueMock::numberOfSentMessage() const { +size_t MessageQueueMock::numberOfSentMessages() const { size_t callCount = 0; for (auto& destInfo : sendMap) { callCount += destInfo.second.callCount; @@ -23,7 +23,7 @@ size_t MessageQueueMock::numberOfSentMessage() const { return callCount; } -size_t MessageQueueMock::numberOfSentMessage(MessageQueueId_t id) const { +size_t MessageQueueMock::numberOfSentMessagesToDest(MessageQueueId_t id) const { auto iter = sendMap.find(id); if (iter == sendMap.end()) { return 0; @@ -31,6 +31,10 @@ size_t MessageQueueMock::numberOfSentMessage(MessageQueueId_t id) const { return iter->second.callCount; } +size_t MessageQueueMock::numberOfSentMessagesToDefault() const { + return numberOfSentMessagesToDest(MessageQueueBase::getDefaultDestination()); +} + ReturnValue_t MessageQueueMock::clearLastReceivedMessage(bool clearCmdMsg) { if (receivedMsgs.empty()) { return MessageQueueIF::EMPTY; @@ -61,6 +65,10 @@ ReturnValue_t MessageQueueMock::sendMessageFrom(MessageQueueId_t sendTo, if (message == nullptr) { return HasReturnvaluesIF::RETURN_FAILED; } + if (nextSendFailsPair.first) { + nextSendFailsPair.first = false; + return nextSendFailsPair.second; + } auto iter = sendMap.find(sendTo); MessageQueueMessage messageCopy; if (iter == sendMap.end()) { @@ -162,3 +170,7 @@ void MessageQueueMock::clearEmptyEntries() { } } } +void MessageQueueMock::makeNextSendFail(ReturnValue_t retval) { + nextSendFailsPair.first = true; + nextSendFailsPair.second = retval; +} diff --git a/unittests/mocks/MessageQueueMock.h b/unittests/mocks/MessageQueueMock.h index fbfa1ba9..0be68223 100644 --- a/unittests/mocks/MessageQueueMock.h +++ b/unittests/mocks/MessageQueueMock.h @@ -32,8 +32,10 @@ class MessageQueueMock : public MessageQueueBase { //! Get message which was sent to a specific ID ReturnValue_t getNextSentMessage(MessageQueueId_t id, MessageQueueMessageIF& message); [[nodiscard]] bool wasMessageSent() const; - [[nodiscard]] size_t numberOfSentMessage() const; - [[nodiscard]] size_t numberOfSentMessage(MessageQueueId_t id) const; + void makeNextSendFail(ReturnValue_t retval); + [[nodiscard]] size_t numberOfSentMessages() const; + [[nodiscard]] size_t numberOfSentMessagesToDefault() const; + [[nodiscard]] size_t numberOfSentMessagesToDest(MessageQueueId_t id) const; /** * Pop a message, clearing it in the process. * @return @@ -53,6 +55,7 @@ class MessageQueueMock : public MessageQueueBase { using SendMap = std::map; SendMap sendMap; std::queue receivedMsgs; + std::pair nextSendFailsPair; void clearEmptyEntries(); ReturnValue_t receiveMessage(MessageQueueMessageIF* message) override; diff --git a/unittests/storagemanager/CMakeLists.txt b/unittests/storagemanager/CMakeLists.txt index 7b6280df..d2bb4dbc 100644 --- a/unittests/storagemanager/CMakeLists.txt +++ b/unittests/storagemanager/CMakeLists.txt @@ -1,4 +1,4 @@ target_sources(${FSFW_TEST_TGT} PRIVATE - TestNewAccessor.cpp - TestPool.cpp + testAccessor.cpp + testPool.cpp ) diff --git a/unittests/storagemanager/TestNewAccessor.cpp b/unittests/storagemanager/testAccessor.cpp similarity index 98% rename from unittests/storagemanager/TestNewAccessor.cpp rename to unittests/storagemanager/testAccessor.cpp index 996239a6..1404646b 100644 --- a/unittests/storagemanager/TestNewAccessor.cpp +++ b/unittests/storagemanager/testAccessor.cpp @@ -6,11 +6,11 @@ #include "CatchDefinitions.h" -TEST_CASE("New Accessor", "[NewAccessor]") { +TEST_CASE("Pool Accessor", "[pool-accessor]") { LocalPool::LocalPoolConfig poolCfg = {{1, 10}}; LocalPool SimplePool = LocalPool(0, poolCfg); - std::array testDataArray; - std::array receptionArray; + std::array testDataArray{}; + std::array receptionArray{}; store_address_t testStoreId; ReturnValue_t result = retval::CATCH_FAILED; diff --git a/unittests/storagemanager/TestPool.cpp b/unittests/storagemanager/testPool.cpp similarity index 97% rename from unittests/storagemanager/TestPool.cpp rename to unittests/storagemanager/testPool.cpp index e37c6934..03cac72a 100644 --- a/unittests/storagemanager/TestPool.cpp +++ b/unittests/storagemanager/testPool.cpp @@ -10,10 +10,10 @@ TEST_CASE("Local Pool Simple Tests [1 Pool]", "[TestPool]") { LocalPool::LocalPoolConfig config = {{1, 10}}; LocalPool simplePool(0, config); - std::array testDataArray; - std::array receptionArray; + std::array testDataArray{}; + std::array receptionArray{}; store_address_t testStoreId; - ReturnValue_t result = retval::CATCH_FAILED; + ReturnValue_t result; uint8_t* pointer = nullptr; const uint8_t* constPointer = nullptr; @@ -23,8 +23,10 @@ TEST_CASE("Local Pool Simple Tests [1 Pool]", "[TestPool]") { size_t size = 10; SECTION("Basic tests") { + REQUIRE(not simplePool.hasDataAtId(testStoreId)); result = simplePool.addData(&testStoreId, testDataArray.data(), size); REQUIRE(result == retval::CATCH_OK); + REQUIRE(simplePool.hasDataAtId(testStoreId)); result = simplePool.getData(testStoreId, &constPointer, &size); REQUIRE(result == retval::CATCH_OK); memcpy(receptionArray.data(), constPointer, size); @@ -40,6 +42,7 @@ TEST_CASE("Local Pool Simple Tests [1 Pool]", "[TestPool]") { } result = simplePool.deleteData(testStoreId); REQUIRE(result == retval::CATCH_OK); + REQUIRE(not simplePool.hasDataAtId(testStoreId)); result = simplePool.addData(&testStoreId, testDataArray.data(), 15); CHECK(result == (int)StorageManagerIF::DATA_TOO_LARGE); } diff --git a/unittests/tmtcservices/testSendHelper.cpp b/unittests/tmtcservices/testSendHelper.cpp index fc5b86bd..9daeded5 100644 --- a/unittests/tmtcservices/testSendHelper.cpp +++ b/unittests/tmtcservices/testSendHelper.cpp @@ -1,15 +1,103 @@ #include #include +#include "fsfw/storagemanager/LocalPool.h" #include "fsfw/tmtcservices/TmSendHelper.h" +#include "fsfw/tmtcservices/TmStoreHelper.h" +#include "mocks/CdsShortTimestamperMock.h" #include "mocks/InternalErrorReporterMock.h" #include "mocks/MessageQueueMock.h" TEST_CASE("TM Send Helper", "[tm-send-helper]") { + MessageQueueId_t destId = 1; auto errReporter = InternalErrorReporterMock(); auto msgQueue = MessageQueueMock(); - TmSendHelper sendHelper(&msgQueue, &errReporter); + msgQueue.setDefaultDestination(destId); + TmSendHelper sendHelper(msgQueue, errReporter, destId); + auto timeStamper = CdsShortTimestamperMock(); + LocalPool::LocalPoolConfig cfg = {{5, 32}, {2, 64}}; + LocalPool pool(objects::NO_OBJECT, cfg); + auto storeHelper = TmStoreHelper(2, pool, timeStamper); - SECTION("State") { + SECTION("State and Setters") { + REQUIRE(sendHelper.getInternalErrorReporter() == &errReporter); + REQUIRE(sendHelper.getDefaultDestination() == destId); + REQUIRE(sendHelper.getMsgQueue() == &msgQueue); + } + + SECTION("Setters") { + REQUIRE(not sendHelper.areFaultsIgnored()); + sendHelper.ignoreFaults(); + REQUIRE(sendHelper.areFaultsIgnored()); + sendHelper.dontIgnoreFaults(); + REQUIRE(not sendHelper.areFaultsIgnored()); + REQUIRE(sendHelper.getDefaultDestination() == destId); + sendHelper.setDefaultDestination(destId + 1); + REQUIRE(sendHelper.getDefaultDestination() == destId + 1); + sendHelper.setInternalErrorReporter(nullptr); + REQUIRE(sendHelper.getInternalErrorReporter() == nullptr); + } + + SECTION("Default CTOR") { + TmSendHelper emptyHelper; + REQUIRE(emptyHelper.getInternalErrorReporter() == nullptr); + REQUIRE(emptyHelper.getDefaultDestination() == MessageQueueIF::NO_QUEUE); + store_address_t dummy; + // basic robustness + REQUIRE(emptyHelper.sendPacket(dummy) == HasReturnvaluesIF::RETURN_FAILED); + } + + SECTION("One Arg CTOR") { + TmSendHelper helper(errReporter); + REQUIRE(helper.getInternalErrorReporter() == &errReporter); + REQUIRE(helper.getDefaultDestination() == MessageQueueIF::NO_QUEUE); + REQUIRE(helper.getMsgQueue() == nullptr); + } + + SECTION("Two Arg CTOR") { + TmSendHelper helper(msgQueue, errReporter); + REQUIRE(helper.getInternalErrorReporter() == &errReporter); + REQUIRE(helper.getDefaultDestination() == MessageQueueIF::NO_QUEUE); + REQUIRE(helper.getMsgQueue() == &msgQueue); + } + SECTION("Send") { + storeHelper.preparePacket(17, 2, 0); + REQUIRE(storeHelper.addPacketToStore() == HasReturnvaluesIF::RETURN_OK); + store_address_t storeId = storeHelper.getCurrentAddr(); + REQUIRE(sendHelper.sendPacket(storeId) == HasReturnvaluesIF::RETURN_OK); + REQUIRE(msgQueue.wasMessageSent()); + REQUIRE(msgQueue.numberOfSentMessagesToDefault() == 1); + TmTcMessage msg; + REQUIRE(msgQueue.getNextSentMessage(msg) == HasReturnvaluesIF::RETURN_OK); + REQUIRE(msg.getStorageId() == storeId); + REQUIRE(pool.hasDataAtId(msg.getStorageId())); + } + + SECTION("Send to Non-Default") { + storeHelper.preparePacket(17, 2, 0); + REQUIRE(storeHelper.addPacketToStore() == HasReturnvaluesIF::RETURN_OK); + store_address_t storeId = storeHelper.getCurrentAddr(); + REQUIRE(sendHelper.sendPacket(destId + 1, storeId) == HasReturnvaluesIF::RETURN_OK); + REQUIRE(msgQueue.wasMessageSent()); + REQUIRE(msgQueue.numberOfSentMessagesToDest(destId + 1) == 1); + } + + SECTION("Sending fails, errors not ignored") { + msgQueue.makeNextSendFail(HasReturnvaluesIF::RETURN_FAILED); + storeHelper.preparePacket(17, 2, 0); + REQUIRE(storeHelper.addPacketToStore() == HasReturnvaluesIF::RETURN_OK); + store_address_t storeId = storeHelper.getCurrentAddr(); + REQUIRE(sendHelper.sendPacket(destId + 1, storeId) == HasReturnvaluesIF::RETURN_FAILED); + REQUIRE(errReporter.lostTmCallCnt == 1); + } + + SECTION("Sending fails, errors ignored") { + msgQueue.makeNextSendFail(HasReturnvaluesIF::RETURN_FAILED); + storeHelper.preparePacket(17, 2, 0); + sendHelper.ignoreFaults(); + REQUIRE(storeHelper.addPacketToStore() == HasReturnvaluesIF::RETURN_OK); + store_address_t storeId = storeHelper.getCurrentAddr(); + REQUIRE(sendHelper.sendPacket(destId + 1, storeId) == HasReturnvaluesIF::RETURN_FAILED); + REQUIRE(errReporter.lostTmCallCnt == 0); } } \ No newline at end of file -- 2.43.0 From c83f75c51537618a1b31e46a0d24d192d861ae19 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Mon, 25 Jul 2022 20:41:01 +0200 Subject: [PATCH 053/108] some more tests using TM send helper --- src/fsfw/tmtcservices/tmHelpers.cpp | 15 ++++++++++----- src/fsfw/tmtcservices/tmHelpers.h | 3 ++- unittests/tmtcservices/testSendHelper.cpp | 18 +++++++++++++----- unittests/tmtcservices/testStoreHelper.cpp | 1 + 4 files changed, 26 insertions(+), 11 deletions(-) diff --git a/src/fsfw/tmtcservices/tmHelpers.cpp b/src/fsfw/tmtcservices/tmHelpers.cpp index d7bc66cf..50b40c76 100644 --- a/src/fsfw/tmtcservices/tmHelpers.cpp +++ b/src/fsfw/tmtcservices/tmHelpers.cpp @@ -1,11 +1,16 @@ #include "tmHelpers.h" -ReturnValue_t telemetry::storeAndSendTmPacket(TmStoreHelper &storeHelper, - TmSendHelper &sendHelper) { - storeHelper.addPacketToStore(); - ReturnValue_t result = sendHelper.sendPacket(storeHelper.getCurrentAddr()); +ReturnValue_t telemetry::storeAndSendTmPacket(TmStoreHelper &storeHelper, TmSendHelper &sendHelper, + bool delOnFailure) { + ReturnValue_t result = storeHelper.addPacketToStore(); if (result != HasReturnvaluesIF::RETURN_OK) { - storeHelper.deletePacket(); + return result; + } + result = sendHelper.sendPacket(storeHelper.getCurrentAddr()); + if (result != HasReturnvaluesIF::RETURN_OK) { + if (delOnFailure) { + storeHelper.deletePacket(); + } } return result; } diff --git a/src/fsfw/tmtcservices/tmHelpers.h b/src/fsfw/tmtcservices/tmHelpers.h index da55495e..e49e11ae 100644 --- a/src/fsfw/tmtcservices/tmHelpers.h +++ b/src/fsfw/tmtcservices/tmHelpers.h @@ -7,7 +7,8 @@ // I'd prefer to use tm, but there have been nameclashes with the tm struct namespace telemetry { -ReturnValue_t storeAndSendTmPacket(TmStoreHelper& storeHelper, TmSendHelper& sendHelper); +ReturnValue_t storeAndSendTmPacket(TmStoreHelper& storeHelper, TmSendHelper& sendHelper, + bool delOnFailure = true); class DataWithObjectIdPrefix : public SerializeIF { public: diff --git a/unittests/tmtcservices/testSendHelper.cpp b/unittests/tmtcservices/testSendHelper.cpp index 9daeded5..17a1d990 100644 --- a/unittests/tmtcservices/testSendHelper.cpp +++ b/unittests/tmtcservices/testSendHelper.cpp @@ -1,9 +1,9 @@ #include -#include #include "fsfw/storagemanager/LocalPool.h" #include "fsfw/tmtcservices/TmSendHelper.h" #include "fsfw/tmtcservices/TmStoreHelper.h" +#include "fsfw/tmtcservices/tmHelpers.h" #include "mocks/CdsShortTimestamperMock.h" #include "mocks/InternalErrorReporterMock.h" #include "mocks/MessageQueueMock.h" @@ -61,10 +61,18 @@ TEST_CASE("TM Send Helper", "[tm-send-helper]") { REQUIRE(helper.getMsgQueue() == &msgQueue); } SECTION("Send") { - storeHelper.preparePacket(17, 2, 0); - REQUIRE(storeHelper.addPacketToStore() == HasReturnvaluesIF::RETURN_OK); - store_address_t storeId = storeHelper.getCurrentAddr(); - REQUIRE(sendHelper.sendPacket(storeId) == HasReturnvaluesIF::RETURN_OK); + REQUIRE(storeHelper.preparePacket(17, 2, 0) == HasReturnvaluesIF::RETURN_OK); + store_address_t storeId; + SECTION("Separate Helpers") { + REQUIRE(storeHelper.addPacketToStore() == HasReturnvaluesIF::RETURN_OK); + storeId = storeHelper.getCurrentAddr(); + REQUIRE(sendHelper.sendPacket(storeId) == HasReturnvaluesIF::RETURN_OK); + } + SECTION("Helper Wrapper") { + REQUIRE(telemetry::storeAndSendTmPacket(storeHelper, sendHelper) == + HasReturnvaluesIF::RETURN_OK); + storeId = storeHelper.getCurrentAddr(); + } REQUIRE(msgQueue.wasMessageSent()); REQUIRE(msgQueue.numberOfSentMessagesToDefault() == 1); TmTcMessage msg; diff --git a/unittests/tmtcservices/testStoreHelper.cpp b/unittests/tmtcservices/testStoreHelper.cpp index 275a6238..5220957a 100644 --- a/unittests/tmtcservices/testStoreHelper.cpp +++ b/unittests/tmtcservices/testStoreHelper.cpp @@ -2,6 +2,7 @@ #include "fsfw/storagemanager/LocalPool.h" #include "fsfw/tmtcservices/TmStoreHelper.h" +#include "fsfw/tmtcservices/tmHelpers.h" #include "mocks/CdsShortTimestamperMock.h" #include "mocks/SimpleSerializable.h" -- 2.43.0 From 7d87274844f61c05dc98cdb3c170a8ec09ef259e Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Mon, 25 Jul 2022 20:53:18 +0200 Subject: [PATCH 054/108] add old api but mark it deprecated --- .../ProvidesDataPoolSubscriptionIF.h | 35 ++++++++++++++++++- 1 file changed, 34 insertions(+), 1 deletion(-) diff --git a/src/fsfw/datapoollocal/ProvidesDataPoolSubscriptionIF.h b/src/fsfw/datapoollocal/ProvidesDataPoolSubscriptionIF.h index 4fa86ef0..6170e7ac 100644 --- a/src/fsfw/datapoollocal/ProvidesDataPoolSubscriptionIF.h +++ b/src/fsfw/datapoollocal/ProvidesDataPoolSubscriptionIF.h @@ -52,7 +52,7 @@ class ProvidesDataPoolSubscriptionIF { public: virtual ~ProvidesDataPoolSubscriptionIF() = default; /** - * @brief Subscribe for the generation of periodic packets. + * @brief Subscribe for the generation of periodic packets. Used for regular HK packets * @details * This subscription mechanism will generally be used by the data creator * to generate housekeeping packets which are downlinked directly. @@ -60,9 +60,29 @@ class ProvidesDataPoolSubscriptionIF { */ virtual ReturnValue_t subscribeForRegularPeriodicPacket( subdp::RegularHkPeriodicParams params) = 0; + /** + * @brief Subscribe for the generation of periodic packets. Used for diagnostic packets + * @details + * This subscription mechanism will generally be used by the data creator + * to generate housekeeping packets which are downlinked directly. + * @return + */ virtual ReturnValue_t subscribeForDiagPeriodicPacket( subdp::DiagnosticsHkPeriodicParams params) = 0; + [[deprecated("Please use the new API which takes all arguments as one wrapper struct")]] + virtual ReturnValue_t subscribeForPeriodicPacket(sid_t sid, bool enableReporting, + float collectionInterval, bool isDiagnostics, + object_id_t packetDestination) { + if(isDiagnostics) { + subdp::DiagnosticsHkPeriodicParams params(sid, enableReporting, collectionInterval); + return subscribeForDiagPeriodicPacket(params); + } else { + subdp::RegularHkPeriodicParams params(sid, enableReporting, collectionInterval); + return subscribeForRegularPeriodicPacket(params); + } + } + /** * @brief Subscribe for the generation of packets if the dataset * is marked as changed. @@ -76,6 +96,19 @@ class ProvidesDataPoolSubscriptionIF { virtual ReturnValue_t subscribeForRegularUpdatePacket(subdp::RegularHkUpdateParams params) = 0; virtual ReturnValue_t subscribeForDiagUpdatePacket(subdp::DiagnosticsHkUpdateParams params) = 0; + [[deprecated("Please use the new API which takes all arguments as one wrapper struct")]] + virtual ReturnValue_t subscribeForUpdatePacket(sid_t sid, bool reportingEnabled, + bool isDiagnostics, + object_id_t packetDestination) { + if(isDiagnostics) { + subdp::DiagnosticsHkUpdateParams params(sid, reportingEnabled); + return subscribeForDiagUpdatePacket(params); + } else { + subdp::RegularHkUpdateParams params(sid, reportingEnabled); + return subscribeForRegularUpdatePacket(params); + } + } + /** * @brief Subscribe for a notification message which will be sent * if a dataset has changed. -- 2.43.0 From 6d00fc65c073637f1e93a10180d80a1c8564d5f0 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Mon, 25 Jul 2022 21:08:04 +0200 Subject: [PATCH 055/108] fix memory leak --- .../datapoollocal/LocalDataPoolManager.cpp | 24 ++++--------------- src/fsfw/datapoollocal/LocalDataPoolManager.h | 4 ++-- 2 files changed, 7 insertions(+), 21 deletions(-) diff --git a/src/fsfw/datapoollocal/LocalDataPoolManager.cpp b/src/fsfw/datapoollocal/LocalDataPoolManager.cpp index 2ab737bf..45ef9567 100644 --- a/src/fsfw/datapoollocal/LocalDataPoolManager.cpp +++ b/src/fsfw/datapoollocal/LocalDataPoolManager.cpp @@ -291,11 +291,7 @@ ReturnValue_t LocalDataPoolManager::addUpdateToStore(HousekeepingSnapshot& updat void LocalDataPoolManager::handleChangeResetLogic(DataType type, DataId dataId, MarkChangedIF* toReset) { - if (hkUpdateResetList == nullptr) { - /* Config error */ - return; - } - HkUpdateResetList& listRef = *hkUpdateResetList; + HkUpdateResetList& listRef = hkUpdateResetList; for (auto& changeInfo : listRef) { if (changeInfo.dataType != type) { continue; @@ -326,11 +322,7 @@ void LocalDataPoolManager::handleChangeResetLogic(DataType type, DataId dataId, } void LocalDataPoolManager::resetHkUpdateResetHelper() { - if (hkUpdateResetList == nullptr) { - return; - } - - for (auto& changeInfo : *hkUpdateResetList) { + for (auto& changeInfo : hkUpdateResetList) { changeInfo.currentUpdateCounter = changeInfo.updateCounter; } } @@ -442,11 +434,7 @@ ReturnValue_t LocalDataPoolManager::subscribeForVariableUpdateMessage( } void LocalDataPoolManager::handleHkUpdateResetListInsertion(DataType dataType, DataId dataId) { - if (hkUpdateResetList == nullptr) { - hkUpdateResetList = new std::vector(); - } - - for (auto& updateResetStruct : *hkUpdateResetList) { + for (auto& updateResetStruct : hkUpdateResetList) { if (dataType == DataType::DATA_SET) { if (updateResetStruct.dataId.sid == dataId.sid) { updateResetStruct.updateCounter++; @@ -470,7 +458,7 @@ void LocalDataPoolManager::handleHkUpdateResetListInsertion(DataType dataType, D } else { hkUpdateResetHelper.dataId.localPoolId = dataId.localPoolId; } - hkUpdateResetList->push_back(hkUpdateResetHelper); + hkUpdateResetList.push_back(hkUpdateResetHelper); } ReturnValue_t LocalDataPoolManager::handleHousekeepingMessage(CommandMessage* message) { @@ -824,9 +812,7 @@ void LocalDataPoolManager::clearReceiversList() { /* Clear the vector completely and releases allocated memory. */ HkReceivers().swap(hkReceivers); /* Also clear the reset helper if it exists */ - if (hkUpdateResetList != nullptr) { - HkUpdateResetList().swap(*hkUpdateResetList); - } + HkUpdateResetList().swap(hkUpdateResetList); } MutexIF* LocalDataPoolManager::getLocalPoolMutex() { return this->mutex; } diff --git a/src/fsfw/datapoollocal/LocalDataPoolManager.h b/src/fsfw/datapoollocal/LocalDataPoolManager.h index 041a4b05..998ca03b 100644 --- a/src/fsfw/datapoollocal/LocalDataPoolManager.h +++ b/src/fsfw/datapoollocal/LocalDataPoolManager.h @@ -297,8 +297,8 @@ class LocalDataPoolManager : public ProvidesDataPoolSubscriptionIF, public Acces using HkUpdateResetList = std::vector; /** This list is used to manage creating multiple update packets and only resetting - the update flag if all of them were created. Will only be created when needed. */ - HkUpdateResetList* hkUpdateResetList = nullptr; + the update flag if all of them were created. */ + HkUpdateResetList hkUpdateResetList = HkUpdateResetList(); /** This is the map holding the actual data. Should only be initialized * once ! */ -- 2.43.0 From c12669fe501bfd77e916e75649cb8e4022729c50 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Mon, 25 Jul 2022 22:10:20 +0200 Subject: [PATCH 056/108] this should fix the mmeory leak --- src/fsfw/datapoollocal/LocalDataPoolManager.cpp | 11 +++++------ unittests/mocks/LocalPoolOwnerBase.cpp | 10 +++++----- unittests/mocks/LocalPoolOwnerBase.h | 11 +++++++++-- 3 files changed, 19 insertions(+), 13 deletions(-) diff --git a/src/fsfw/datapoollocal/LocalDataPoolManager.cpp b/src/fsfw/datapoollocal/LocalDataPoolManager.cpp index 45ef9567..7a18b7bf 100644 --- a/src/fsfw/datapoollocal/LocalDataPoolManager.cpp +++ b/src/fsfw/datapoollocal/LocalDataPoolManager.cpp @@ -209,9 +209,9 @@ ReturnValue_t LocalDataPoolManager::handleNotificationSnapshot(HkReceiver& recei } /* Prepare and send update snapshot */ - timeval now; + timeval now{}; Clock::getClock_timeval(&now); - CCSDSTime::CDS_short cds; + CCSDSTime::CDS_short cds{}; CCSDSTime::convertToCcsds(&cds, &now); HousekeepingSnapshot updatePacket( reinterpret_cast(&cds), sizeof(cds), @@ -245,9 +245,9 @@ ReturnValue_t LocalDataPoolManager::handleNotificationSnapshot(HkReceiver& recei } /* Prepare and send update snapshot */ - timeval now; + timeval now{}; Clock::getClock_timeval(&now); - CCSDSTime::CDS_short cds; + CCSDSTime::CDS_short cds{}; CCSDSTime::convertToCcsds(&cds, &now); HousekeepingSnapshot updatePacket( reinterpret_cast(&cds), sizeof(cds), @@ -291,8 +291,7 @@ ReturnValue_t LocalDataPoolManager::addUpdateToStore(HousekeepingSnapshot& updat void LocalDataPoolManager::handleChangeResetLogic(DataType type, DataId dataId, MarkChangedIF* toReset) { - HkUpdateResetList& listRef = hkUpdateResetList; - for (auto& changeInfo : listRef) { + for (auto& changeInfo : hkUpdateResetList) { if (changeInfo.dataType != type) { continue; } diff --git a/unittests/mocks/LocalPoolOwnerBase.cpp b/unittests/mocks/LocalPoolOwnerBase.cpp index f269e066..df295b95 100644 --- a/unittests/mocks/LocalPoolOwnerBase.cpp +++ b/unittests/mocks/LocalPoolOwnerBase.cpp @@ -19,12 +19,12 @@ ReturnValue_t LocalPoolOwnerBase::initializeHkManager() { ReturnValue_t LocalPoolOwnerBase::initializeLocalDataPool(localpool::DataPool &localDataPoolMap, LocalDataPoolManager &poolManager) { // Default initialization empty for now. - localDataPoolMap.emplace(lpool::uint8VarId, new PoolEntry({0})); - localDataPoolMap.emplace(lpool::floatVarId, new PoolEntry({0})); - localDataPoolMap.emplace(lpool::uint32VarId, new PoolEntry({0})); + localDataPoolMap.emplace(lpool::uint8VarId, &u8PoolEntry); + localDataPoolMap.emplace(lpool::floatVarId, &floatPoolEntry); + localDataPoolMap.emplace(lpool::uint32VarId, &u32PoolEntry); - localDataPoolMap.emplace(lpool::uint16Vec3Id, new PoolEntry({0, 0, 0})); - localDataPoolMap.emplace(lpool::int64Vec2Id, new PoolEntry({0, 0})); + localDataPoolMap.emplace(lpool::uint16Vec3Id, &u16VecPoolEntry); + localDataPoolMap.emplace(lpool::int64Vec2Id, &i64VecPoolEntry); return HasReturnvaluesIF::RETURN_OK; } diff --git a/unittests/mocks/LocalPoolOwnerBase.h b/unittests/mocks/LocalPoolOwnerBase.h index 329aa0b3..3233d5d4 100644 --- a/unittests/mocks/LocalPoolOwnerBase.h +++ b/unittests/mocks/LocalPoolOwnerBase.h @@ -7,10 +7,12 @@ #include #include #include +#include "fsfw/datapool/PoolEntry.h" + #include #include -#include "../mocks/MessageQueueMock.h" +#include "mocks/MessageQueueMock.h" #include "tests/TestsConfig.h" namespace lpool { @@ -164,10 +166,15 @@ class LocalPoolOwnerBase : public SystemObject, public HasLocalDataPoolIF { gp_id_t changedPoolVariableGpid; store_address_t storeIdForChangedVariable; + PoolEntry u8PoolEntry = PoolEntry({0}); + PoolEntry floatPoolEntry = PoolEntry({0}); + PoolEntry u32PoolEntry = PoolEntry({0}); + PoolEntry u16VecPoolEntry = PoolEntry({0, 0, 0}); + PoolEntry i64VecPoolEntry = PoolEntry({0, 0}); + lp_var_t testUint8 = lp_var_t(this, lpool::uint8VarId); lp_var_t testFloat = lp_var_t(this, lpool::floatVarId); lp_var_t testUint32 = lp_var_t(this, lpool::uint32VarId); - lp_vec_t testUint16Vec = lp_vec_t(this, lpool::uint16Vec3Id); lp_vec_t testInt64Vec = lp_vec_t(this, lpool::int64Vec2Id); -- 2.43.0 From db33f9cc7ed5a29b05a79d55d8c66b86f683159d Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Mon, 25 Jul 2022 22:22:08 +0200 Subject: [PATCH 057/108] maybe this teardown fixes the leak --- src/fsfw/objectmanager/ObjectManager.h | 2 +- unittests/CatchFactory.cpp | 1 - unittests/CatchRunner.cpp | 2 ++ unittests/CatchSetup.cpp | 6 ++++++ 4 files changed, 9 insertions(+), 2 deletions(-) diff --git a/src/fsfw/objectmanager/ObjectManager.h b/src/fsfw/objectmanager/ObjectManager.h index 50e4af00..e0e74792 100644 --- a/src/fsfw/objectmanager/ObjectManager.h +++ b/src/fsfw/objectmanager/ObjectManager.h @@ -38,7 +38,7 @@ class ObjectManager : public ObjectManagerIF { /** * @brief In the class's destructor, all objects in the list are deleted. */ - virtual ~ObjectManager(); + ~ObjectManager() override; ReturnValue_t insert(object_id_t id, SystemObjectIF* object) override; ReturnValue_t remove(object_id_t id) override; void initialize() override; diff --git a/unittests/CatchFactory.cpp b/unittests/CatchFactory.cpp index fdb5fd08..d5d12935 100644 --- a/unittests/CatchFactory.cpp +++ b/unittests/CatchFactory.cpp @@ -33,7 +33,6 @@ void Factory::produceFrameworkObjects(void* args) { new EventManager(objects::EVENT_MANAGER); new HealthTable(objects::HEALTH_TABLE); new InternalErrorReporter(objects::INTERNAL_ERROR_REPORTER); - new HkReceiverMock(objects::HK_RECEIVER_MOCK); { PoolManager::LocalPoolConfig poolCfg = {{100, 16}, {50, 32}, {25, 64}, {15, 128}, {5, 1024}}; diff --git a/unittests/CatchRunner.cpp b/unittests/CatchRunner.cpp index 1377049c..9bdcb676 100644 --- a/unittests/CatchRunner.cpp +++ b/unittests/CatchRunner.cpp @@ -13,6 +13,7 @@ #include extern int customSetup(); +extern int customTeardown(); int main(int argc, char* argv[]) { customSetup(); @@ -21,5 +22,6 @@ int main(int argc, char* argv[]) { int result = Catch::Session().run(argc, argv); // global clean-up + customTeardown(); return result; } diff --git a/unittests/CatchSetup.cpp b/unittests/CatchSetup.cpp index 06f5190a..3b918e05 100644 --- a/unittests/CatchSetup.cpp +++ b/unittests/CatchSetup.cpp @@ -29,3 +29,9 @@ int customSetup() { objMan->initialize(); return 0; } + +int customTeardown() { + ObjectManager* objMan = ObjectManager::instance(); + delete objMan; + return 0; +} -- 2.43.0 From 747243684d61c70a1a5ba92149fb5c871ea44012 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Mon, 25 Jul 2022 22:29:18 +0200 Subject: [PATCH 058/108] more leaks --- src/fsfw/internalerror/InternalErrorReporter.cpp | 6 +++--- src/fsfw/internalerror/InternalErrorReporter.h | 3 +++ 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/src/fsfw/internalerror/InternalErrorReporter.cpp b/src/fsfw/internalerror/InternalErrorReporter.cpp index 12c5aaeb..32038406 100644 --- a/src/fsfw/internalerror/InternalErrorReporter.cpp +++ b/src/fsfw/internalerror/InternalErrorReporter.cpp @@ -126,9 +126,9 @@ MessageQueueId_t InternalErrorReporter::getCommandQueue() const { ReturnValue_t InternalErrorReporter::initializeLocalDataPool(localpool::DataPool &localDataPoolMap, LocalDataPoolManager &poolManager) { - localDataPoolMap.emplace(errorPoolIds::TM_HITS, new PoolEntry()); - localDataPoolMap.emplace(errorPoolIds::QUEUE_HITS, new PoolEntry()); - localDataPoolMap.emplace(errorPoolIds::STORE_HITS, new PoolEntry()); + localDataPoolMap.emplace(errorPoolIds::TM_HITS, &tmHitsEntry); + localDataPoolMap.emplace(errorPoolIds::QUEUE_HITS, &queueHitsEntry); + localDataPoolMap.emplace(errorPoolIds::STORE_HITS,&storeHitsEntry); poolManager.subscribeForDiagPeriodicPacket(subdp::DiagnosticsHkPeriodicParams( internalErrorSid, false, static_cast(getPeriodicOperationFrequency()) / static_cast(1000.0))); diff --git a/src/fsfw/internalerror/InternalErrorReporter.h b/src/fsfw/internalerror/InternalErrorReporter.h index 549be4bd..ca82d1a4 100644 --- a/src/fsfw/internalerror/InternalErrorReporter.h +++ b/src/fsfw/internalerror/InternalErrorReporter.h @@ -72,6 +72,9 @@ class InternalErrorReporter : public SystemObject, uint32_t queueHits = 0; uint32_t tmHits = 0; uint32_t storeHits = 0; + PoolEntry tmHitsEntry = PoolEntry(); + PoolEntry storeHitsEntry = PoolEntry(); + PoolEntry queueHitsEntry = PoolEntry(); uint32_t getAndResetQueueHits(); void incrementQueueHits(); -- 2.43.0 From e48b6f143242363b136b56b331cd9448cb3ac6c5 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Mon, 25 Jul 2022 22:36:53 +0200 Subject: [PATCH 059/108] possible double delete --- src/fsfw/health/HealthTable.h | 4 ++-- src/fsfw/objectmanager/ObjectManager.cpp | 6 +++--- unittests/CatchSetup.cpp | 2 -- 3 files changed, 5 insertions(+), 7 deletions(-) diff --git a/src/fsfw/health/HealthTable.h b/src/fsfw/health/HealthTable.h index 60e00f92..076228c1 100644 --- a/src/fsfw/health/HealthTable.h +++ b/src/fsfw/health/HealthTable.h @@ -9,8 +9,8 @@ class HealthTable : public HealthTableIF, public SystemObject { public: - HealthTable(object_id_t objectid); - virtual ~HealthTable(); + explicit HealthTable(object_id_t objectid); + ~HealthTable() override; void setMutexTimeout(MutexIF::TimeoutType timeoutType, uint32_t timeoutMs); diff --git a/src/fsfw/objectmanager/ObjectManager.cpp b/src/fsfw/objectmanager/ObjectManager.cpp index 2017938a..a0278988 100644 --- a/src/fsfw/objectmanager/ObjectManager.cpp +++ b/src/fsfw/objectmanager/ObjectManager.cpp @@ -21,7 +21,7 @@ void ObjectManager::setObjectFactoryFunction(produce_function_t objFactoryFunc, this->factoryArgs = factoryArgs; } -ObjectManager::ObjectManager() {} +ObjectManager::ObjectManager() = default; ObjectManager::~ObjectManager() { for (auto const& iter : objectList) { @@ -36,7 +36,7 @@ ReturnValue_t ObjectManager::insert(object_id_t id, SystemObjectIF* object) { // sif::debug << "ObjectManager::insert: Object " << std::hex // << (int)id << std::dec << " inserted." << std::endl; #endif - return this->RETURN_OK; + return HasReturnvaluesIF::RETURN_OK; } else { #if FSFW_CPP_OSTREAM_ENABLED == 1 sif::error << "ObjectManager::insert: Object ID " << std::hex << static_cast(id) @@ -53,7 +53,7 @@ ReturnValue_t ObjectManager::insert(object_id_t id, SystemObjectIF* object) { } ReturnValue_t ObjectManager::remove(object_id_t id) { - if (this->getSystemObject(id) != NULL) { + if (this->getSystemObject(id) != nullptr) { this->objectList.erase(id); #if FSFW_CPP_OSTREAM_ENABLED == 1 // sif::debug << "ObjectManager::removeObject: Object " << std::hex diff --git a/unittests/CatchSetup.cpp b/unittests/CatchSetup.cpp index 3b918e05..1bdc20f4 100644 --- a/unittests/CatchSetup.cpp +++ b/unittests/CatchSetup.cpp @@ -31,7 +31,5 @@ int customSetup() { } int customTeardown() { - ObjectManager* objMan = ObjectManager::instance(); - delete objMan; return 0; } -- 2.43.0 From bdf71d4e664ffa230306270e60e0a1f33e44465a Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Tue, 26 Jul 2022 10:21:16 +0200 Subject: [PATCH 060/108] add new HasReturnvaluesIF features --- .../ProvidesDataPoolSubscriptionIF.h | 22 ++++++++++--------- .../internalerror/InternalErrorReporter.cpp | 2 +- src/fsfw/returnvalues/HasReturnvaluesIF.h | 21 +++++++++++++----- src/fsfw/tmtcservices/CMakeLists.txt | 1 + .../tmtcservices/TmStoreAndSendHelper.cpp | 3 +++ src/fsfw/tmtcservices/TmStoreAndSendHelper.h | 18 +++++++++++++++ src/fsfw/tmtcservices/tmHelpers.h | 10 ++++----- unittests/CatchSetup.cpp | 4 +--- unittests/mocks/LocalPoolOwnerBase.h | 3 +-- 9 files changed, 58 insertions(+), 26 deletions(-) create mode 100644 src/fsfw/tmtcservices/TmStoreAndSendHelper.cpp create mode 100644 src/fsfw/tmtcservices/TmStoreAndSendHelper.h diff --git a/src/fsfw/datapoollocal/ProvidesDataPoolSubscriptionIF.h b/src/fsfw/datapoollocal/ProvidesDataPoolSubscriptionIF.h index 6170e7ac..e1aca321 100644 --- a/src/fsfw/datapoollocal/ProvidesDataPoolSubscriptionIF.h +++ b/src/fsfw/datapoollocal/ProvidesDataPoolSubscriptionIF.h @@ -70,11 +70,12 @@ class ProvidesDataPoolSubscriptionIF { virtual ReturnValue_t subscribeForDiagPeriodicPacket( subdp::DiagnosticsHkPeriodicParams params) = 0; - [[deprecated("Please use the new API which takes all arguments as one wrapper struct")]] - virtual ReturnValue_t subscribeForPeriodicPacket(sid_t sid, bool enableReporting, - float collectionInterval, bool isDiagnostics, - object_id_t packetDestination) { - if(isDiagnostics) { + [[deprecated( + "Please use the new API which takes all arguments as one wrapper " + "struct")]] virtual ReturnValue_t + subscribeForPeriodicPacket(sid_t sid, bool enableReporting, float collectionInterval, + bool isDiagnostics, object_id_t packetDestination) { + if (isDiagnostics) { subdp::DiagnosticsHkPeriodicParams params(sid, enableReporting, collectionInterval); return subscribeForDiagPeriodicPacket(params); } else { @@ -96,11 +97,12 @@ class ProvidesDataPoolSubscriptionIF { virtual ReturnValue_t subscribeForRegularUpdatePacket(subdp::RegularHkUpdateParams params) = 0; virtual ReturnValue_t subscribeForDiagUpdatePacket(subdp::DiagnosticsHkUpdateParams params) = 0; - [[deprecated("Please use the new API which takes all arguments as one wrapper struct")]] - virtual ReturnValue_t subscribeForUpdatePacket(sid_t sid, bool reportingEnabled, - bool isDiagnostics, - object_id_t packetDestination) { - if(isDiagnostics) { + [[deprecated( + "Please use the new API which takes all arguments as one wrapper " + "struct")]] virtual ReturnValue_t + subscribeForUpdatePacket(sid_t sid, bool reportingEnabled, bool isDiagnostics, + object_id_t packetDestination) { + if (isDiagnostics) { subdp::DiagnosticsHkUpdateParams params(sid, reportingEnabled); return subscribeForDiagUpdatePacket(params); } else { diff --git a/src/fsfw/internalerror/InternalErrorReporter.cpp b/src/fsfw/internalerror/InternalErrorReporter.cpp index 32038406..0e404d22 100644 --- a/src/fsfw/internalerror/InternalErrorReporter.cpp +++ b/src/fsfw/internalerror/InternalErrorReporter.cpp @@ -128,7 +128,7 @@ ReturnValue_t InternalErrorReporter::initializeLocalDataPool(localpool::DataPool LocalDataPoolManager &poolManager) { localDataPoolMap.emplace(errorPoolIds::TM_HITS, &tmHitsEntry); localDataPoolMap.emplace(errorPoolIds::QUEUE_HITS, &queueHitsEntry); - localDataPoolMap.emplace(errorPoolIds::STORE_HITS,&storeHitsEntry); + localDataPoolMap.emplace(errorPoolIds::STORE_HITS, &storeHitsEntry); poolManager.subscribeForDiagPeriodicPacket(subdp::DiagnosticsHkPeriodicParams( internalErrorSid, false, static_cast(getPeriodicOperationFrequency()) / static_cast(1000.0))); diff --git a/src/fsfw/returnvalues/HasReturnvaluesIF.h b/src/fsfw/returnvalues/HasReturnvaluesIF.h index eec80228..4d59c26b 100644 --- a/src/fsfw/returnvalues/HasReturnvaluesIF.h +++ b/src/fsfw/returnvalues/HasReturnvaluesIF.h @@ -10,11 +10,21 @@ #define MAKE_RETURN_CODE(number) ((INTERFACE_ID << 8) + (number)) typedef uint16_t ReturnValue_t; +namespace retval { +static constexpr ReturnValue_t OK = 0; +static constexpr ReturnValue_t FAILED = 1; + +static constexpr ReturnValue_t makeCode(uint8_t classId, uint8_t number) { + return (static_cast(classId) << 8) + number; +} +} // namespace retval + class HasReturnvaluesIF { public: - static const ReturnValue_t RETURN_OK = 0; - static const ReturnValue_t RETURN_FAILED = 1; - virtual ~HasReturnvaluesIF() {} + static const ReturnValue_t RETURN_OK = retval::OK; + static const ReturnValue_t RETURN_FAILED = retval::FAILED; + + virtual ~HasReturnvaluesIF() = default; /** * It is discouraged to use the input parameters 0,0 and 0,1 as this @@ -23,8 +33,9 @@ class HasReturnvaluesIF { * @param number * @return */ - static constexpr ReturnValue_t makeReturnCode(uint8_t classId, uint8_t number) { - return (static_cast(classId) << 8) + number; + [[deprecated("Use retval::makeCode instead")]] static constexpr ReturnValue_t makeReturnCode( + uint8_t classId, uint8_t number) { + return retval::makeCode(classId, number); } }; diff --git a/src/fsfw/tmtcservices/CMakeLists.txt b/src/fsfw/tmtcservices/CMakeLists.txt index 42ac6128..ca3c887e 100644 --- a/src/fsfw/tmtcservices/CMakeLists.txt +++ b/src/fsfw/tmtcservices/CMakeLists.txt @@ -9,5 +9,6 @@ target_sources( SpacePacketParser.cpp TmStoreHelper.cpp TmSendHelper.cpp + TmStoreAndSendHelper.cpp tcHelpers.cpp tmHelpers.cpp) diff --git a/src/fsfw/tmtcservices/TmStoreAndSendHelper.cpp b/src/fsfw/tmtcservices/TmStoreAndSendHelper.cpp new file mode 100644 index 00000000..9e858ed6 --- /dev/null +++ b/src/fsfw/tmtcservices/TmStoreAndSendHelper.cpp @@ -0,0 +1,3 @@ +#include "TmStoreAndSendHelper.h" + +StoreAndSendWrapper::StoreAndSendWrapper(TmStoreHelper& storeHelper, TmSendHelper& sendHelper) {} diff --git a/src/fsfw/tmtcservices/TmStoreAndSendHelper.h b/src/fsfw/tmtcservices/TmStoreAndSendHelper.h new file mode 100644 index 00000000..d75d6839 --- /dev/null +++ b/src/fsfw/tmtcservices/TmStoreAndSendHelper.h @@ -0,0 +1,18 @@ +#ifndef FSFW_TMTCSERVICES_TMSTOREANDSENDHELPER_H +#define FSFW_TMTCSERVICES_TMSTOREANDSENDHELPER_H + +#include "TmSendHelper.h" +#include "TmStoreHelper.h" + +class StoreAndSendWrapper { + public: + StoreAndSendWrapper(TmStoreHelper& storeHelper, TmSendHelper& sendHelper) + : storeHelper(storeHelper), sendHelper(sendHelper) {} + ReturnValue_t storeAndSendTmPacket(TmStoreHelper& storeHelper, TmSendHelper& sendHelper, + bool delOnFailure = true); + TmStoreHelper& storeHelper; + TmSendHelper& sendHelper; + bool delOnFailure = true; +}; + +#endif // FSFW_TMTCSERVICES_TMSTOREANDSENDHELPER_H diff --git a/src/fsfw/tmtcservices/tmHelpers.h b/src/fsfw/tmtcservices/tmHelpers.h index e49e11ae..6a754bdf 100644 --- a/src/fsfw/tmtcservices/tmHelpers.h +++ b/src/fsfw/tmtcservices/tmHelpers.h @@ -7,9 +7,6 @@ // I'd prefer to use tm, but there have been nameclashes with the tm struct namespace telemetry { -ReturnValue_t storeAndSendTmPacket(TmStoreHelper& storeHelper, TmSendHelper& sendHelper, - bool delOnFailure = true); - class DataWithObjectIdPrefix : public SerializeIF { public: DataWithObjectIdPrefix(object_id_t objectId, const uint8_t* srcData, size_t srcDataLen) @@ -34,8 +31,11 @@ class DataWithObjectIdPrefix : public SerializeIF { ReturnValue_t deSerialize(const uint8_t** buffer, size_t* size, Endianness streamEndianness) override { - // TODO: Implement - return HasReturnvaluesIF::RETURN_FAILED; + ReturnValue_t result = SerializeAdapter::deSerialize(&objectId, buffer, size, streamEndianness); + if (result != retval::OK) { + return result; + } + return retval::FAILED; } private: diff --git a/unittests/CatchSetup.cpp b/unittests/CatchSetup.cpp index 1bdc20f4..9206c2e1 100644 --- a/unittests/CatchSetup.cpp +++ b/unittests/CatchSetup.cpp @@ -30,6 +30,4 @@ int customSetup() { return 0; } -int customTeardown() { - return 0; -} +int customTeardown() { return 0; } diff --git a/unittests/mocks/LocalPoolOwnerBase.h b/unittests/mocks/LocalPoolOwnerBase.h index 3233d5d4..f1d1225f 100644 --- a/unittests/mocks/LocalPoolOwnerBase.h +++ b/unittests/mocks/LocalPoolOwnerBase.h @@ -7,11 +7,10 @@ #include #include #include -#include "fsfw/datapool/PoolEntry.h" - #include #include +#include "fsfw/datapool/PoolEntry.h" #include "mocks/MessageQueueMock.h" #include "tests/TestsConfig.h" -- 2.43.0 From b827bd8370ad22f6910e1979bfd2f150fc239321 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Tue, 26 Jul 2022 10:22:05 +0200 Subject: [PATCH 061/108] update HasReturnvaluesIF 1. Add new retval namespace which contains OK and FAIL returnvalue 2. Also contains makeCode constexpr function 3. Mark HasReturnvaluesIF::makeReturnCode deprecated This prevents from having to implement an interface just to use a shorter version of the general returnvalues. A namespace is better suited for this I think --- src/fsfw/returnvalues/HasReturnvaluesIF.h | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/src/fsfw/returnvalues/HasReturnvaluesIF.h b/src/fsfw/returnvalues/HasReturnvaluesIF.h index eec80228..4d59c26b 100644 --- a/src/fsfw/returnvalues/HasReturnvaluesIF.h +++ b/src/fsfw/returnvalues/HasReturnvaluesIF.h @@ -10,11 +10,21 @@ #define MAKE_RETURN_CODE(number) ((INTERFACE_ID << 8) + (number)) typedef uint16_t ReturnValue_t; +namespace retval { +static constexpr ReturnValue_t OK = 0; +static constexpr ReturnValue_t FAILED = 1; + +static constexpr ReturnValue_t makeCode(uint8_t classId, uint8_t number) { + return (static_cast(classId) << 8) + number; +} +} // namespace retval + class HasReturnvaluesIF { public: - static const ReturnValue_t RETURN_OK = 0; - static const ReturnValue_t RETURN_FAILED = 1; - virtual ~HasReturnvaluesIF() {} + static const ReturnValue_t RETURN_OK = retval::OK; + static const ReturnValue_t RETURN_FAILED = retval::FAILED; + + virtual ~HasReturnvaluesIF() = default; /** * It is discouraged to use the input parameters 0,0 and 0,1 as this @@ -23,8 +33,9 @@ class HasReturnvaluesIF { * @param number * @return */ - static constexpr ReturnValue_t makeReturnCode(uint8_t classId, uint8_t number) { - return (static_cast(classId) << 8) + number; + [[deprecated("Use retval::makeCode instead")]] static constexpr ReturnValue_t makeReturnCode( + uint8_t classId, uint8_t number) { + return retval::makeCode(classId, number); } }; -- 2.43.0 From 88ebb67c8db9c9cc14958216f2443ce989a3a0dc Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Tue, 26 Jul 2022 10:27:44 +0200 Subject: [PATCH 062/108] fix deprecation warnings --- src/fsfw/cfdp/definitions.h | 18 +++++++++--------- src/fsfw/osal/common/TcpTmTcServer.h | 2 +- src/fsfw/tasks/FixedTimeslotTaskIF.h | 2 +- src/fsfw_tests/internal/osal/testMq.cpp | 10 ++++------ .../serialize/IntTestSerialization.cpp | 15 +++++++-------- 5 files changed, 22 insertions(+), 25 deletions(-) diff --git a/src/fsfw/cfdp/definitions.h b/src/fsfw/cfdp/definitions.h index eb21f5bf..93d15bcb 100644 --- a/src/fsfw/cfdp/definitions.h +++ b/src/fsfw/cfdp/definitions.h @@ -16,27 +16,27 @@ static constexpr uint8_t VERSION_BITS = 0b00100000; static constexpr uint8_t CFDP_CLASS_ID = CLASS_ID::CFDP; static constexpr ReturnValue_t INVALID_TLV_TYPE = - HasReturnvaluesIF::makeReturnCode(CFDP_CLASS_ID, 1); + retval::makeCode(CFDP_CLASS_ID, 1); static constexpr ReturnValue_t INVALID_DIRECTIVE_FIELDS = - HasReturnvaluesIF::makeReturnCode(CFDP_CLASS_ID, 2); + retval::makeCode(CFDP_CLASS_ID, 2); static constexpr ReturnValue_t INVALID_PDU_DATAFIELD_LEN = - HasReturnvaluesIF::makeReturnCode(CFDP_CLASS_ID, 3); + retval::makeCode(CFDP_CLASS_ID, 3); static constexpr ReturnValue_t INVALID_ACK_DIRECTIVE_FIELDS = - HasReturnvaluesIF::makeReturnCode(CFDP_CLASS_ID, 4); + retval::makeCode(CFDP_CLASS_ID, 4); //! Can not parse options. This can also occur because there are options //! available but the user did not pass a valid options array static constexpr ReturnValue_t METADATA_CANT_PARSE_OPTIONS = - HasReturnvaluesIF::makeReturnCode(CFDP_CLASS_ID, 5); + retval::makeCode(CFDP_CLASS_ID, 5); static constexpr ReturnValue_t NAK_CANT_PARSE_OPTIONS = - HasReturnvaluesIF::makeReturnCode(CFDP_CLASS_ID, 6); + retval::makeCode(CFDP_CLASS_ID, 6); static constexpr ReturnValue_t FINISHED_CANT_PARSE_FS_RESPONSES = - HasReturnvaluesIF::makeReturnCode(CFDP_CLASS_ID, 6); + retval::makeCode(CFDP_CLASS_ID, 6); static constexpr ReturnValue_t FILESTORE_REQUIRES_SECOND_FILE = - HasReturnvaluesIF::makeReturnCode(CFDP_CLASS_ID, 8); + retval::makeCode(CFDP_CLASS_ID, 8); //! Can not parse filestore response because user did not pass a valid instance //! or remaining size is invalid static constexpr ReturnValue_t FILESTORE_RESPONSE_CANT_PARSE_FS_MESSAGE = - HasReturnvaluesIF::makeReturnCode(CFDP_CLASS_ID, 9); + retval::makeCode(CFDP_CLASS_ID, 9); //! Checksum types according to the SANA Checksum Types registry //! https://sanaregistry.org/r/checksum_identifiers/ diff --git a/src/fsfw/osal/common/TcpTmTcServer.h b/src/fsfw/osal/common/TcpTmTcServer.h index faf6e0a1..ae3fce39 100644 --- a/src/fsfw/osal/common/TcpTmTcServer.h +++ b/src/fsfw/osal/common/TcpTmTcServer.h @@ -108,7 +108,7 @@ class TcpTmTcServer : public SystemObject, public TcpIpBase, public ExecutableOb StorageManagerIF* tmStore = nullptr; private: - static constexpr ReturnValue_t CONN_BROKEN = HasReturnvaluesIF::makeReturnCode(1, 0); + static constexpr ReturnValue_t CONN_BROKEN = retval::makeCode(1, 0); //! TMTC bridge is cached. object_id_t tmtcBridgeId = objects::NO_OBJECT; TcpTmTcBridge* tmtcBridge = nullptr; diff --git a/src/fsfw/tasks/FixedTimeslotTaskIF.h b/src/fsfw/tasks/FixedTimeslotTaskIF.h index 3f5e30d8..6a552d81 100644 --- a/src/fsfw/tasks/FixedTimeslotTaskIF.h +++ b/src/fsfw/tasks/FixedTimeslotTaskIF.h @@ -15,7 +15,7 @@ class FixedTimeslotTaskIF : public PeriodicTaskIF { ~FixedTimeslotTaskIF() override = default; static constexpr ReturnValue_t SLOT_LIST_EMPTY = - HasReturnvaluesIF::makeReturnCode(CLASS_ID::FIXED_SLOT_TASK_IF, 0); + retval::makeCode(CLASS_ID::FIXED_SLOT_TASK_IF, 0); /** * Add an object with a slot time and the execution step to the task. diff --git a/src/fsfw_tests/internal/osal/testMq.cpp b/src/fsfw_tests/internal/osal/testMq.cpp index 0f78dbb9..30b46d63 100644 --- a/src/fsfw_tests/internal/osal/testMq.cpp +++ b/src/fsfw_tests/internal/osal/testMq.cpp @@ -7,8 +7,6 @@ #include "fsfw_tests/internal/UnittDefinitions.h" -using retval = HasReturnvaluesIF; - void testmq::testMq() { std::string id = "[testMq]"; MessageQueueIF* testSenderMq = QueueFactory::instance()->createMessageQueue(1); @@ -22,22 +20,22 @@ void testmq::testMq() { testSenderMq->setDefaultDestination(testReceiverMqId); auto result = testSenderMq->sendMessage(testReceiverMqId, &testMessage); - if (result != retval::RETURN_OK) { + if (result != retval::OK) { unitt::put_error(id); } MessageQueueMessage recvMessage; result = testReceiverMq->receiveMessage(&recvMessage); - if (result != retval::RETURN_OK or recvMessage.getData()[0] != 42) { + if (result != retval::OK or recvMessage.getData()[0] != 42) { unitt::put_error(id); } result = testSenderMq->sendMessage(testReceiverMqId, &testMessage); - if (result != retval::RETURN_OK) { + if (result != retval::OK) { unitt::put_error(id); } MessageQueueId_t senderId = 0; result = testReceiverMq->receiveMessage(&recvMessage, &senderId); - if (result != retval::RETURN_OK or recvMessage.getData()[0] != 42) { + if (result != retval::OK or recvMessage.getData()[0] != 42) { unitt::put_error(id); } if (senderId != testSenderMqId) { diff --git a/src/fsfw_tests/internal/serialize/IntTestSerialization.cpp b/src/fsfw_tests/internal/serialize/IntTestSerialization.cpp index 8e1f2bdd..1e2a385c 100644 --- a/src/fsfw_tests/internal/serialize/IntTestSerialization.cpp +++ b/src/fsfw_tests/internal/serialize/IntTestSerialization.cpp @@ -8,24 +8,23 @@ #include "fsfw_tests/internal/UnittDefinitions.h" -using retval = HasReturnvaluesIF; std::array testserialize::test_array = {0}; ReturnValue_t testserialize::test_serialization() { // Here, we test all serialization tools. First test basic cases. ReturnValue_t result = test_endianness_tools(); - if (result != retval::RETURN_OK) { + if (result != retval::OK) { return result; } result = test_autoserialization(); - if (result != retval::RETURN_OK) { + if (result != retval::OK) { return result; } result = test_serial_buffer_adapter(); - if (result != retval::RETURN_OK) { + if (result != retval::OK) { return result; } - return retval::RETURN_OK; + return retval::OK; } ReturnValue_t testserialize::test_endianness_tools() { @@ -49,7 +48,7 @@ ReturnValue_t testserialize::test_endianness_tools() { if (test_array[0] != 0 and test_array[1] != 1) { return unitt::put_error(id); } - return retval::RETURN_OK; + return retval::OK; } ReturnValue_t testserialize::test_autoserialization() { @@ -153,7 +152,7 @@ ReturnValue_t testserialize::test_autoserialization() { } // Check overflow - return retval::RETURN_OK; + return retval::OK; } // TODO: Also test for constant buffers. @@ -206,5 +205,5 @@ ReturnValue_t testserialize::test_serial_buffer_adapter() { if (testUint16 != 16) { return unitt::put_error(id); } - return retval::RETURN_OK; + return retval::OK; } -- 2.43.0 From 500a5602bd81d4530b7ae1e75f318f640d58a390 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Tue, 26 Jul 2022 11:09:57 +0200 Subject: [PATCH 063/108] added additional TM store and send helper --- src/fsfw/pus/CService200ModeCommanding.cpp | 6 +-- src/fsfw/pus/Service17Test.cpp | 10 ++-- src/fsfw/pus/Service17Test.h | 4 +- .../pus/Service1TelecommandVerification.cpp | 7 +-- .../pus/Service1TelecommandVerification.h | 2 + src/fsfw/pus/Service20ParameterManagement.cpp | 6 +-- src/fsfw/pus/Service2DeviceAccess.cpp | 2 +- src/fsfw/pus/Service5EventReporting.cpp | 7 ++- src/fsfw/pus/Service5EventReporting.h | 3 +- src/fsfw/pus/Service8FunctionManagement.cpp | 2 +- src/fsfw/pus/Service8FunctionManagement.h | 2 +- src/fsfw/tmtcpacket/pus/PusIF.h | 4 +- src/fsfw/tmtcpacket/pus/tm/PusTmCreator.cpp | 8 +++ src/fsfw/tmtcpacket/pus/tm/PusTmCreator.h | 2 + .../tmtcservices/CommandingServiceBase.cpp | 26 ++-------- src/fsfw/tmtcservices/CommandingServiceBase.h | 35 +++---------- src/fsfw/tmtcservices/TmSendHelper.h | 3 +- .../tmtcservices/TmStoreAndSendHelper.cpp | 50 ++++++++++++++++++- src/fsfw/tmtcservices/TmStoreAndSendHelper.h | 46 +++++++++++++++-- src/fsfw/tmtcservices/TmStoreHelper.cpp | 4 ++ src/fsfw/tmtcservices/TmStoreHelper.h | 2 + src/fsfw/tmtcservices/tmHelpers.cpp | 15 ------ src/fsfw_hal/linux/CommandExecutor.h | 14 +++--- unittests/tmtcservices/testSendHelper.cpp | 5 -- 24 files changed, 154 insertions(+), 111 deletions(-) diff --git a/src/fsfw/pus/CService200ModeCommanding.cpp b/src/fsfw/pus/CService200ModeCommanding.cpp index 9990280c..2e8e78a3 100644 --- a/src/fsfw/pus/CService200ModeCommanding.cpp +++ b/src/fsfw/pus/CService200ModeCommanding.cpp @@ -96,13 +96,13 @@ ReturnValue_t CService200ModeCommanding::handleReply(const CommandMessage *reply ReturnValue_t CService200ModeCommanding::prepareModeReply(const CommandMessage *reply, object_id_t objectId) { ModePacket modeReplyPacket(objectId, ModeMessage::getMode(reply), ModeMessage::getSubmode(reply)); - return sendTmPacket(Subservice::REPLY_MODE_REPLY, modeReplyPacket); + return tmHelper.sendTmPacket(Subservice::REPLY_MODE_REPLY, modeReplyPacket); } ReturnValue_t CService200ModeCommanding::prepareWrongModeReply(const CommandMessage *reply, object_id_t objectId) { ModePacket wrongModeReply(objectId, ModeMessage::getMode(reply), ModeMessage::getSubmode(reply)); - ReturnValue_t result = sendTmPacket(Subservice::REPLY_WRONG_MODE_REPLY, wrongModeReply); + ReturnValue_t result = tmHelper.sendTmPacket(Subservice::REPLY_WRONG_MODE_REPLY, wrongModeReply); if (result == RETURN_OK) { // We want to produce an error here in any case because the mode was not correct return RETURN_FAILED; @@ -113,7 +113,7 @@ ReturnValue_t CService200ModeCommanding::prepareWrongModeReply(const CommandMess ReturnValue_t CService200ModeCommanding::prepareCantReachModeReply(const CommandMessage *reply, object_id_t objectId) { CantReachModePacket cantReachModePacket(objectId, ModeMessage::getCantReachModeReason(reply)); - ReturnValue_t result = sendTmPacket(Subservice::REPLY_CANT_REACH_MODE, cantReachModePacket); + ReturnValue_t result = tmHelper.sendTmPacket(Subservice::REPLY_CANT_REACH_MODE, cantReachModePacket); if (result == RETURN_OK) { // We want to produce an error here in any case because the mode was not reached return RETURN_FAILED; diff --git a/src/fsfw/pus/Service17Test.cpp b/src/fsfw/pus/Service17Test.cpp index 631cf939..b40d2d70 100644 --- a/src/fsfw/pus/Service17Test.cpp +++ b/src/fsfw/pus/Service17Test.cpp @@ -6,20 +6,20 @@ #include "fsfw/tmtcservices/tmHelpers.h" Service17Test::Service17Test(object_id_t objectId, uint16_t apid, uint8_t serviceId) - : PusServiceBase(objectId, apid, serviceId), storeHelper(apid), packetSubCounter(0) {} + : PusServiceBase(objectId, apid, serviceId), + storeHelper(apid), + tmHelper(serviceId, storeHelper, sendHelper) {} Service17Test::~Service17Test() = default; ReturnValue_t Service17Test::handleRequest(uint8_t subservice) { switch (subservice) { case Subservice::CONNECTION_TEST: { - storeHelper.preparePacket(serviceId, Subservice::CONNECTION_TEST_REPORT, packetSubCounter); - return telemetry::storeAndSendTmPacket(storeHelper, sendHelper); + return tmHelper.sendTmPacket(Subservice::CONNECTION_TEST_REPORT); } case Subservice::EVENT_TRIGGER_TEST: { - storeHelper.preparePacket(serviceId, Subservice::CONNECTION_TEST_REPORT, packetSubCounter++); triggerEvent(TEST, 1234, 5678); - return telemetry::storeAndSendTmPacket(storeHelper, sendHelper); + return tmHelper.sendTmPacket(Subservice::EVENT_TRIGGER_TEST); } default: return AcceptsTelecommandsIF::INVALID_SUBSERVICE; diff --git a/src/fsfw/pus/Service17Test.h b/src/fsfw/pus/Service17Test.h index 54efcaa5..771fbe55 100644 --- a/src/fsfw/pus/Service17Test.h +++ b/src/fsfw/pus/Service17Test.h @@ -4,6 +4,7 @@ #include "fsfw/objectmanager/SystemObject.h" #include "fsfw/tmtcservices/PusServiceBase.h" #include "fsfw/tmtcservices/TmStoreHelper.h" +#include "fsfw/tmtcservices/TmStoreAndSendHelper.h" /** * @brief Test Service @@ -45,8 +46,7 @@ class Service17Test : public PusServiceBase { protected: TmStoreHelper storeHelper; TmSendHelper sendHelper; - - uint16_t packetSubCounter = 0; + TmStoreAndSendWrapper tmHelper; }; #endif /* FSFW_PUS_SERVICE17TEST_H_ */ diff --git a/src/fsfw/pus/Service1TelecommandVerification.cpp b/src/fsfw/pus/Service1TelecommandVerification.cpp index 7b5e7973..102ae5a0 100644 --- a/src/fsfw/pus/Service1TelecommandVerification.cpp +++ b/src/fsfw/pus/Service1TelecommandVerification.cpp @@ -15,7 +15,8 @@ Service1TelecommandVerification::Service1TelecommandVerification(object_id_t obj apid(apid), serviceId(serviceId), targetDestination(targetDestination), - storeHelper(apid) { + storeHelper(apid), + tmHelper(serviceId, storeHelper, sendHelper) { tmQueue = QueueFactory::instance()->createMessageQueue(messageQueueDepth); } @@ -69,7 +70,7 @@ ReturnValue_t Service1TelecommandVerification::generateFailureReport( message->getParameter1(), message->getParameter2()); storeHelper.preparePacket(serviceId, message->getReportId(), packetSubCounter++); storeHelper.setSourceDataSerializable(report); - return telemetry::storeAndSendTmPacket(storeHelper, sendHelper); + return tmHelper.storeAndSendTmPacket(); } ReturnValue_t Service1TelecommandVerification::generateSuccessReport( @@ -78,7 +79,7 @@ ReturnValue_t Service1TelecommandVerification::generateSuccessReport( message->getTcSequenceControl(), message->getStep()); storeHelper.preparePacket(serviceId, message->getReportId(), packetSubCounter++); storeHelper.setSourceDataSerializable(report); - return telemetry::storeAndSendTmPacket(storeHelper, sendHelper); + return tmHelper.storeAndSendTmPacket(); } ReturnValue_t Service1TelecommandVerification::initialize() { diff --git a/src/fsfw/pus/Service1TelecommandVerification.h b/src/fsfw/pus/Service1TelecommandVerification.h index a87acdfe..5709e6a9 100644 --- a/src/fsfw/pus/Service1TelecommandVerification.h +++ b/src/fsfw/pus/Service1TelecommandVerification.h @@ -9,6 +9,7 @@ #include "fsfw/tmtcservices/PusVerificationReport.h" #include "fsfw/tmtcservices/TmSendHelper.h" #include "fsfw/tmtcservices/TmStoreHelper.h" +#include "fsfw/tmtcservices/TmStoreAndSendHelper.h" /** * @brief Verify TC acceptance, start, progress and execution. @@ -84,6 +85,7 @@ class Service1TelecommandVerification : public AcceptsVerifyMessageIF, TmSendHelper sendHelper; TmStoreHelper storeHelper; + TmStoreAndSendWrapper tmHelper; StorageManagerIF* tmStore = nullptr; MessageQueueIF* tmQueue = nullptr; diff --git a/src/fsfw/pus/Service20ParameterManagement.cpp b/src/fsfw/pus/Service20ParameterManagement.cpp index 0922793c..ccb5a3b5 100644 --- a/src/fsfw/pus/Service20ParameterManagement.cpp +++ b/src/fsfw/pus/Service20ParameterManagement.cpp @@ -14,7 +14,7 @@ Service20ParameterManagement::Service20ParameterManagement(object_id_t objectId, : CommandingServiceBase(objectId, apid, serviceId, numberOfParallelCommands, commandTimeoutSeconds) {} -Service20ParameterManagement::~Service20ParameterManagement() {} +Service20ParameterManagement::~Service20ParameterManagement() = default; ReturnValue_t Service20ParameterManagement::isValidSubservice(uint8_t subservice) { switch (static_cast(subservice)) { @@ -64,7 +64,7 @@ ReturnValue_t Service20ParameterManagement::checkAndAcquireTargetID(object_id_t* ReturnValue_t Service20ParameterManagement::checkInterfaceAndAcquireMessageQueue( MessageQueueId_t* messageQueueToSet, object_id_t* objectId) { // check ReceivesParameterMessagesIF property of target - ReceivesParameterMessagesIF* possibleTarget = + auto* possibleTarget = ObjectManager::instance()->get(*objectId); if (possibleTarget == nullptr) { #if FSFW_CPP_OSTREAM_ENABLED == 1 @@ -177,7 +177,7 @@ ReturnValue_t Service20ParameterManagement::handleReply(const CommandMessage* re ParameterId_t parameterId = ParameterMessage::getParameterId(reply); ParameterDumpReply parameterReply(objectId, parameterId, parameterData.second.data(), parameterData.second.size()); - sendTmPacket(static_cast(Subservice::PARAMETER_DUMP_REPLY), parameterReply); + tmHelper.sendTmPacket(static_cast(Subservice::PARAMETER_DUMP_REPLY), parameterReply); return HasReturnvaluesIF::RETURN_OK; } default: diff --git a/src/fsfw/pus/Service2DeviceAccess.cpp b/src/fsfw/pus/Service2DeviceAccess.cpp index 8060b2b6..008d8128 100644 --- a/src/fsfw/pus/Service2DeviceAccess.cpp +++ b/src/fsfw/pus/Service2DeviceAccess.cpp @@ -148,7 +148,7 @@ void Service2DeviceAccess::sendWiretappingTm(CommandMessage* reply, uint8_t subs // Init our dummy packet and correct endianness of object ID before // sending it back. WiretappingPacket tmPacket(DeviceHandlerMessage::getDeviceObjectId(reply), data); - sendTmPacket(subservice, tmPacket.objectId, tmPacket.data, size); + tmHelper.sendTmPacket(subservice, tmPacket.objectId, tmPacket.data, size); } MessageQueueId_t Service2DeviceAccess::getDeviceQueue() { return commandQueue->getId(); } diff --git a/src/fsfw/pus/Service5EventReporting.cpp b/src/fsfw/pus/Service5EventReporting.cpp index 44f7861a..a895ad0d 100644 --- a/src/fsfw/pus/Service5EventReporting.cpp +++ b/src/fsfw/pus/Service5EventReporting.cpp @@ -12,6 +12,7 @@ Service5EventReporting::Service5EventReporting(object_id_t objectId, uint16_t ap uint32_t messageQueueDepth) : PusServiceBase(objectId, apid, serviceId), storeHelper(apid), + tmHelper(serviceId, storeHelper, sendHelper), maxNumberReportsPerCycle(maxNumberReportsPerCycle) { eventQueue = QueueFactory::instance()->createMessageQueue(messageQueueDepth); } @@ -46,9 +47,9 @@ ReturnValue_t Service5EventReporting::performService() { ReturnValue_t Service5EventReporting::generateEventReport(EventMessage message) { EventReport report(message.getEventId(), message.getReporter(), message.getParameter1(), message.getParameter2()); - storeHelper.preparePacket(serviceId, message.getSeverity(), packetSubCounter); + storeHelper.preparePacket(serviceId, message.getSeverity(), tmHelper.sendCounter); storeHelper.setSourceDataSerializable(report); - ReturnValue_t result = telemetry::storeAndSendTmPacket(storeHelper, sendHelper); + ReturnValue_t result = tmHelper.storeAndSendTmPacket(); if (result != HasReturnvaluesIF::RETURN_OK) { #if FSFW_CPP_OSTREAM_ENABLED == 1 sif::warning << "Service5EventReporting::generateEventReport: " @@ -59,8 +60,6 @@ ReturnValue_t Service5EventReporting::generateEventReport(EventMessage message) "Service5EventReporting::generateEventReport: " "Could not send TM packet\n"); #endif - } else { - packetSubCounter++; } return result; } diff --git a/src/fsfw/pus/Service5EventReporting.h b/src/fsfw/pus/Service5EventReporting.h index a357e5fc..fcbdcb6b 100644 --- a/src/fsfw/pus/Service5EventReporting.h +++ b/src/fsfw/pus/Service5EventReporting.h @@ -2,6 +2,7 @@ #define FSFW_PUS_SERVICE5EVENTREPORTING_H_ #include "fsfw/events/EventMessage.h" +#include "fsfw/tmtcservices/TmStoreAndSendHelper.h" #include "fsfw/tmtcservices/PusServiceBase.h" /** @@ -74,11 +75,11 @@ class Service5EventReporting : public PusServiceBase { }; private: - uint16_t packetSubCounter = 0; MessageQueueIF* eventQueue = nullptr; bool enableEventReport = true; TmSendHelper sendHelper; TmStoreHelper storeHelper; + TmStoreAndSendWrapper tmHelper; const uint8_t maxNumberReportsPerCycle; ReturnValue_t generateEventReport(EventMessage message); diff --git a/src/fsfw/pus/Service8FunctionManagement.cpp b/src/fsfw/pus/Service8FunctionManagement.cpp index c9da6d58..cec4e423 100644 --- a/src/fsfw/pus/Service8FunctionManagement.cpp +++ b/src/fsfw/pus/Service8FunctionManagement.cpp @@ -138,7 +138,7 @@ ReturnValue_t Service8FunctionManagement::handleDataReply(const CommandMessage* return result; } DataReply dataReply(objectId, actionId, buffer, size); - result = sendTmPacket(static_cast(Subservice::REPLY_DIRECT_COMMANDING_DATA), dataReply); + result = tmHelper.sendTmPacket(static_cast(Subservice::REPLY_DIRECT_COMMANDING_DATA), dataReply); auto deletionResult = ipcStore->deleteData(storeId); if (deletionResult != HasReturnvaluesIF::RETURN_OK) { diff --git a/src/fsfw/pus/Service8FunctionManagement.h b/src/fsfw/pus/Service8FunctionManagement.h index 649b3257..38aaf4f4 100644 --- a/src/fsfw/pus/Service8FunctionManagement.h +++ b/src/fsfw/pus/Service8FunctionManagement.h @@ -32,7 +32,7 @@ class Service8FunctionManagement : public CommandingServiceBase { public: Service8FunctionManagement(object_id_t objectId, uint16_t apid, uint8_t serviceId, uint8_t numParallelCommands = 4, uint16_t commandTimeoutSeconds = 60); - virtual ~Service8FunctionManagement(); + ~Service8FunctionManagement() override; protected: /* CSB abstract functions implementation . See CSB documentation. */ diff --git a/src/fsfw/tmtcpacket/pus/PusIF.h b/src/fsfw/tmtcpacket/pus/PusIF.h index 8c346b1d..93223ba8 100644 --- a/src/fsfw/tmtcpacket/pus/PusIF.h +++ b/src/fsfw/tmtcpacket/pus/PusIF.h @@ -10,9 +10,9 @@ class PusIF : public SpacePacketIF { public: static constexpr uint8_t INTERFACE_ID = CLASS_ID::PUS_IF; static constexpr ReturnValue_t INVALID_PUS_VERSION = - HasReturnvaluesIF::makeReturnCode(INTERFACE_ID, 0); + retval::makeCode(INTERFACE_ID, 0); static constexpr ReturnValue_t INVALID_CRC_16 = - HasReturnvaluesIF::makeReturnCode(INTERFACE_ID, 1); + retval::makeCode(INTERFACE_ID, 1); ~PusIF() override = default; /** diff --git a/src/fsfw/tmtcpacket/pus/tm/PusTmCreator.cpp b/src/fsfw/tmtcpacket/pus/tm/PusTmCreator.cpp index 662e74be..71149613 100644 --- a/src/fsfw/tmtcpacket/pus/tm/PusTmCreator.cpp +++ b/src/fsfw/tmtcpacket/pus/tm/PusTmCreator.cpp @@ -133,3 +133,11 @@ ReturnValue_t PusTmCreator::setSerializableUserData(SerializeIF& serializable) { updateSpLengthField(); return HasReturnvaluesIF::RETURN_OK; } + +void PusTmCreator::setService(uint8_t service) { + pusParams.secHeader.service = service; +} + +void PusTmCreator::setSubservice(uint8_t subservice) { + pusParams.secHeader.subservice = subservice; +} diff --git a/src/fsfw/tmtcpacket/pus/tm/PusTmCreator.h b/src/fsfw/tmtcpacket/pus/tm/PusTmCreator.h index 7df760ce..41f72c38 100644 --- a/src/fsfw/tmtcpacket/pus/tm/PusTmCreator.h +++ b/src/fsfw/tmtcpacket/pus/tm/PusTmCreator.h @@ -49,6 +49,8 @@ class PusTmCreator : public SerializeIF, public PusTmIF, public CustomUserDataIF SpacePacketParams& getSpParams(); void setApid(uint16_t apid); void setDestId(uint16_t destId); + void setService(uint8_t service); + void setSubservice(uint8_t subservice); void setMessageTypeCounter(uint16_t messageTypeCounter); PusTmParams& getParams(); void updateSpLengthField(); diff --git a/src/fsfw/tmtcservices/CommandingServiceBase.cpp b/src/fsfw/tmtcservices/CommandingServiceBase.cpp index 10cc2689..7839aa87 100644 --- a/src/fsfw/tmtcservices/CommandingServiceBase.cpp +++ b/src/fsfw/tmtcservices/CommandingServiceBase.cpp @@ -21,6 +21,7 @@ CommandingServiceBase::CommandingServiceBase(object_id_t setObjectId, uint16_t a service(service), timeoutSeconds(commandTimeoutSeconds), tmStoreHelper(apid), + tmHelper(service, tmStoreHelper, tmSendHelper), commandMap(numberOfParallelCommands) { commandQueue = QueueFactory::instance()->createMessageQueue(queueDepth); requestQueue = QueueFactory::instance()->createMessageQueue(queueDepth); @@ -286,35 +287,16 @@ void CommandingServiceBase::handleRequestQueue() { ReturnValue_t CommandingServiceBase::sendTmPacket(uint8_t subservice, const uint8_t* sourceData, size_t sourceDataLen) { - tmStoreHelper.preparePacket(service, subservice, tmPacketCounter); - tmStoreHelper.setSourceDataRaw(sourceData, sourceDataLen); - ReturnValue_t result = telemetry::storeAndSendTmPacket(tmStoreHelper, tmSendHelper); - if (result == HasReturnvaluesIF::RETURN_OK) { - this->tmPacketCounter++; - } - return result; + return tmHelper.sendTmPacket(subservice, sourceData, sourceDataLen); } ReturnValue_t CommandingServiceBase::sendTmPacket(uint8_t subservice, object_id_t objectId, const uint8_t* data, size_t dataLen) { - telemetry::DataWithObjectIdPrefix dataWithObjId(objectId, data, dataLen); - tmStoreHelper.preparePacket(service, subservice, tmPacketCounter); - tmStoreHelper.setSourceDataSerializable(dataWithObjId); - ReturnValue_t result = telemetry::storeAndSendTmPacket(tmStoreHelper, tmSendHelper); - if (result == HasReturnvaluesIF::RETURN_OK) { - this->tmPacketCounter++; - } - return result; + return tmHelper.sendTmPacket(subservice, objectId, data, dataLen); } ReturnValue_t CommandingServiceBase::sendTmPacket(uint8_t subservice, SerializeIF& sourceData) { - tmStoreHelper.preparePacket(service, subservice, tmPacketCounter); - tmStoreHelper.setSourceDataSerializable(sourceData); - ReturnValue_t result = telemetry::storeAndSendTmPacket(tmStoreHelper, tmSendHelper); - if (result == HasReturnvaluesIF::RETURN_OK) { - this->tmPacketCounter++; - } - return result; + return tmHelper.sendTmPacket(subservice, sourceData); } void CommandingServiceBase::startExecution(store_address_t storeId, CommandMapIter iter) { diff --git a/src/fsfw/tmtcservices/CommandingServiceBase.h b/src/fsfw/tmtcservices/CommandingServiceBase.h index 48575724..e96c02d7 100644 --- a/src/fsfw/tmtcservices/CommandingServiceBase.h +++ b/src/fsfw/tmtcservices/CommandingServiceBase.h @@ -6,6 +6,7 @@ #include "TmStoreHelper.h" #include "VerificationReporter.h" #include "fsfw/FSFW.h" +#include "fsfw/tmtcservices/TmStoreAndSendHelper.h" #include "fsfw/container/FIFO.h" #include "fsfw/container/FixedMap.h" #include "fsfw/ipc/CommandMessage.h" @@ -251,18 +252,15 @@ class CommandingServiceBase : public SystemObject, const uint16_t timeoutSeconds; - uint8_t tmPacketCounter = 0; - - StorageManagerIF* ipcStore = nullptr; - PusTcReader tcReader; TmStoreHelper tmStoreHelper; TmSendHelper tmSendHelper; + TmStoreAndSendWrapper tmHelper; StorageManagerIF* tcStore = nullptr; + StorageManagerIF* ipcStore = nullptr; MessageQueueIF* commandQueue = nullptr; - MessageQueueIF* requestQueue = nullptr; VerificationReporter verificationReporter; @@ -286,33 +284,12 @@ class CommandingServiceBase : public SystemObject, */ PeriodicTaskIF* executingTask = nullptr; - /** - * @brief Send TM data from pointer to data. - * If a header is supplied it is added before data - * @param subservice Number of subservice - * @param sourceData Custom source data - * @param sourceDataLen Lenght of data in the Packet - */ + [[deprecated("Use function with same name provided by tmHelper")]] ReturnValue_t sendTmPacket(uint8_t subservice, const uint8_t* sourceData, size_t sourceDataLen); - - /** - * @brief To send TM packets of objects that still need to be serialized - * and consist of an object ID with appended data. - * @param subservice Number of subservice - * @param objectId ObjectId is placed before data - * @param data Data to append to the packet - * @param dataLen Length of Data - */ + [[deprecated("Use function with same name provided by tmHelper")]] ReturnValue_t sendTmPacket(uint8_t subservice, object_id_t objectId, const uint8_t* data, size_t dataLen); - - /** - * @brief To send packets which are contained inside a class implementing - * SerializeIF. - * @param subservice Number of subservice - * @param content This is a pointer to the serialized packet - * @param header Serialize IF header which will be placed before content - */ + [[deprecated("Use function with same name provided by tmHelper")]] ReturnValue_t sendTmPacket(uint8_t subservice, SerializeIF& sourceData); void checkAndExecuteFifo(CommandMapIter& iter); diff --git a/src/fsfw/tmtcservices/TmSendHelper.h b/src/fsfw/tmtcservices/TmSendHelper.h index dee5a495..c4bec886 100644 --- a/src/fsfw/tmtcservices/TmSendHelper.h +++ b/src/fsfw/tmtcservices/TmSendHelper.h @@ -16,7 +16,7 @@ class TmSendHelper { explicit TmSendHelper(InternalErrorReporterIF& reporter); void setMsgQueue(MessageQueueIF& queue); - MessageQueueIF* getMsgQueue() const; + [[nodiscard]] MessageQueueIF* getMsgQueue() const; void setDefaultDestination(MessageQueueId_t msgDest); [[nodiscard]] MessageQueueId_t getDefaultDestination() const; @@ -28,6 +28,7 @@ class TmSendHelper { ReturnValue_t sendPacket(MessageQueueId_t dest, const store_address_t& storeId); ReturnValue_t sendPacket(const store_address_t& storeId); + private: MessageQueueId_t defaultDest = MessageQueueIF::NO_QUEUE; bool ignoreFault = false; diff --git a/src/fsfw/tmtcservices/TmStoreAndSendHelper.cpp b/src/fsfw/tmtcservices/TmStoreAndSendHelper.cpp index 9e858ed6..f10bea32 100644 --- a/src/fsfw/tmtcservices/TmStoreAndSendHelper.cpp +++ b/src/fsfw/tmtcservices/TmStoreAndSendHelper.cpp @@ -1,3 +1,51 @@ #include "TmStoreAndSendHelper.h" +#include "tmHelpers.h" -StoreAndSendWrapper::StoreAndSendWrapper(TmStoreHelper& storeHelper, TmSendHelper& sendHelper) {} +TmStoreAndSendWrapper::TmStoreAndSendWrapper( + uint8_t defaultService, TmStoreHelper& storeHelper, TmSendHelper& sendHelper) + : storeHelper(storeHelper), sendHelper(sendHelper), defaultService(defaultService){} + +ReturnValue_t TmStoreAndSendWrapper::storeAndSendTmPacket() { + ReturnValue_t result = storeHelper.addPacketToStore(); + if (result != HasReturnvaluesIF::RETURN_OK) { + return result; + } + result = sendHelper.sendPacket(storeHelper.getCurrentAddr()); + if (result != HasReturnvaluesIF::RETURN_OK) { + if (delOnFailure) { + storeHelper.deletePacket(); + } + return result; + } + if(incrementSendCounter) { + sendCounter++; + } + return result; +} + +ReturnValue_t TmStoreAndSendWrapper::sendTmPacket(uint8_t subservice, const uint8_t* sourceData, + size_t sourceDataLen) { + storeHelper.preparePacket(defaultService, subservice, sendCounter); + storeHelper.setSourceDataRaw(sourceData, sourceDataLen); + return storeAndSendTmPacket(); +} + +ReturnValue_t TmStoreAndSendWrapper::sendTmPacket(uint8_t subservice, object_id_t objectId, + const uint8_t* data, size_t dataLen) { + telemetry::DataWithObjectIdPrefix dataWithObjId(objectId, data, dataLen); + storeHelper.preparePacket(defaultService, subservice, sendCounter); + storeHelper.setSourceDataSerializable(dataWithObjId); + return storeAndSendTmPacket(); +} + +ReturnValue_t TmStoreAndSendWrapper::sendTmPacket(uint8_t subservice, SerializeIF& sourceData) { + storeHelper.preparePacket(defaultService, subservice, sendCounter); + storeHelper.setSourceDataSerializable(sourceData); + return storeAndSendTmPacket(); +} + +ReturnValue_t TmStoreAndSendWrapper::sendTmPacket(uint8_t subservice) { + storeHelper.preparePacket(defaultService, subservice, sendCounter); + storeHelper.setSourceDataRaw(nullptr, 0); + return storeAndSendTmPacket(); +} diff --git a/src/fsfw/tmtcservices/TmStoreAndSendHelper.h b/src/fsfw/tmtcservices/TmStoreAndSendHelper.h index d75d6839..44ad1799 100644 --- a/src/fsfw/tmtcservices/TmStoreAndSendHelper.h +++ b/src/fsfw/tmtcservices/TmStoreAndSendHelper.h @@ -4,15 +4,51 @@ #include "TmSendHelper.h" #include "TmStoreHelper.h" -class StoreAndSendWrapper { +/** + * Wrapper class intended to help with PUS TM handling. This wrapper class also caches the current packet count + * and the service ID + */ +class TmStoreAndSendWrapper { public: - StoreAndSendWrapper(TmStoreHelper& storeHelper, TmSendHelper& sendHelper) - : storeHelper(storeHelper), sendHelper(sendHelper) {} - ReturnValue_t storeAndSendTmPacket(TmStoreHelper& storeHelper, TmSendHelper& sendHelper, - bool delOnFailure = true); + TmStoreAndSendWrapper(uint8_t defaultService, TmStoreHelper& storeHelper, TmSendHelper& sendHelper); + ReturnValue_t storeAndSendTmPacket(); + + ReturnValue_t sendTmPacket(uint8_t subservice); + /** + * @brief Send TM data from pointer to data. + * If a header is supplied it is added before data + * @param subservice Number of subservice + * @param sourceData Custom source data + * @param sourceDataLen Lenght of data in the Packet + */ + ReturnValue_t sendTmPacket(uint8_t subservice, const uint8_t* sourceData, size_t sourceDataLen); + + /** + * @brief To send TM packets of objects that still need to be serialized + * and consist of an object ID with appended data. + * @param subservice Number of subservice + * @param objectId ObjectId is placed before data + * @param data Data to append to the packet + * @param dataLen Length of Data + */ + ReturnValue_t sendTmPacket(uint8_t subservice, object_id_t objectId, const uint8_t* data, + size_t dataLen); + + /** + * @brief To send packets which are contained inside a class implementing + * SerializeIF. + * @param subservice Number of subservice + * @param content This is a pointer to the serialized packet + * @param header Serialize IF header which will be placed before content + */ + ReturnValue_t sendTmPacket(uint8_t subservice, SerializeIF& sourceData); + + bool incrementSendCounter = true; TmStoreHelper& storeHelper; TmSendHelper& sendHelper; bool delOnFailure = true; + uint8_t defaultService = 0; + uint16_t sendCounter = 0; }; #endif // FSFW_TMTCSERVICES_TMSTOREANDSENDHELPER_H diff --git a/src/fsfw/tmtcservices/TmStoreHelper.cpp b/src/fsfw/tmtcservices/TmStoreHelper.cpp index eb538518..a8105ae0 100644 --- a/src/fsfw/tmtcservices/TmStoreHelper.cpp +++ b/src/fsfw/tmtcservices/TmStoreHelper.cpp @@ -71,3 +71,7 @@ PusTmCreator& TmStoreHelper::getCreatorRef() { return creator; } TimeStamperIF* TmStoreHelper::getTimeStamper() const { return creator.getTimestamper(); } uint16_t TmStoreHelper::getApid() const { return creator.getApid(); } + +ReturnValue_t TmStoreHelper::setService(uint8_t service) { creator.setService(service); } + +ReturnValue_t TmStoreHelper::setSubservice(uint8_t subservice) { creator.setSubservice(subservice); } diff --git a/src/fsfw/tmtcservices/TmStoreHelper.h b/src/fsfw/tmtcservices/TmStoreHelper.h index 3a868d97..6c18ac7f 100644 --- a/src/fsfw/tmtcservices/TmStoreHelper.h +++ b/src/fsfw/tmtcservices/TmStoreHelper.h @@ -27,6 +27,8 @@ class TmStoreHelper { [[nodiscard]] uint16_t getApid() const; [[nodiscard]] const store_address_t& getCurrentAddr() const; + ReturnValue_t setService(uint8_t service); + ReturnValue_t setSubservice(uint8_t subservice); ReturnValue_t setSourceDataRaw(const uint8_t* data, size_t len); ReturnValue_t setSourceDataSerializable(SerializeIF& serializable); diff --git a/src/fsfw/tmtcservices/tmHelpers.cpp b/src/fsfw/tmtcservices/tmHelpers.cpp index 50b40c76..abe2ae78 100644 --- a/src/fsfw/tmtcservices/tmHelpers.cpp +++ b/src/fsfw/tmtcservices/tmHelpers.cpp @@ -1,16 +1 @@ #include "tmHelpers.h" - -ReturnValue_t telemetry::storeAndSendTmPacket(TmStoreHelper &storeHelper, TmSendHelper &sendHelper, - bool delOnFailure) { - ReturnValue_t result = storeHelper.addPacketToStore(); - if (result != HasReturnvaluesIF::RETURN_OK) { - return result; - } - result = sendHelper.sendPacket(storeHelper.getCurrentAddr()); - if (result != HasReturnvaluesIF::RETURN_OK) { - if (delOnFailure) { - storeHelper.deletePacket(); - } - } - return result; -} diff --git a/src/fsfw_hal/linux/CommandExecutor.h b/src/fsfw_hal/linux/CommandExecutor.h index 90662c0f..f5c7a803 100644 --- a/src/fsfw_hal/linux/CommandExecutor.h +++ b/src/fsfw_hal/linux/CommandExecutor.h @@ -32,26 +32,26 @@ class CommandExecutor { //! [EXPORT] : [COMMENT] Execution of the current command has finished static constexpr ReturnValue_t EXECUTION_FINISHED = - HasReturnvaluesIF::makeReturnCode(CLASS_ID, 0); + retval::makeCode(CLASS_ID, 0); //! [EXPORT] : [COMMENT] Command is pending. This will also be returned if the user tries //! to load another command but a command is still pending - static constexpr ReturnValue_t COMMAND_PENDING = HasReturnvaluesIF::makeReturnCode(CLASS_ID, 1); + static constexpr ReturnValue_t COMMAND_PENDING = retval::makeCode(CLASS_ID, 1); //! [EXPORT] : [COMMENT] Some bytes have been read from the executing process - static constexpr ReturnValue_t BYTES_READ = HasReturnvaluesIF::makeReturnCode(CLASS_ID, 2); + static constexpr ReturnValue_t BYTES_READ = retval::makeCode(CLASS_ID, 2); //! [EXPORT] : [COMMENT] Command execution failed - static constexpr ReturnValue_t COMMAND_ERROR = HasReturnvaluesIF::makeReturnCode(CLASS_ID, 3); + static constexpr ReturnValue_t COMMAND_ERROR = retval::makeCode(CLASS_ID, 3); //! [EXPORT] : [COMMENT] static constexpr ReturnValue_t NO_COMMAND_LOADED_OR_PENDING = - HasReturnvaluesIF::makeReturnCode(CLASS_ID, 4); - static constexpr ReturnValue_t PCLOSE_CALL_ERROR = HasReturnvaluesIF::makeReturnCode(CLASS_ID, 6); + retval::makeCode(CLASS_ID, 4); + static constexpr ReturnValue_t PCLOSE_CALL_ERROR =retval::makeCode(CLASS_ID, 6); /** * Constructor. Is initialized with maximum size of internal buffer to read data from the * executed process. * @param maxSize */ - CommandExecutor(const size_t maxSize); + explicit CommandExecutor(size_t maxSize); /** * Load a new command which should be executed diff --git a/unittests/tmtcservices/testSendHelper.cpp b/unittests/tmtcservices/testSendHelper.cpp index 17a1d990..4271f192 100644 --- a/unittests/tmtcservices/testSendHelper.cpp +++ b/unittests/tmtcservices/testSendHelper.cpp @@ -68,11 +68,6 @@ TEST_CASE("TM Send Helper", "[tm-send-helper]") { storeId = storeHelper.getCurrentAddr(); REQUIRE(sendHelper.sendPacket(storeId) == HasReturnvaluesIF::RETURN_OK); } - SECTION("Helper Wrapper") { - REQUIRE(telemetry::storeAndSendTmPacket(storeHelper, sendHelper) == - HasReturnvaluesIF::RETURN_OK); - storeId = storeHelper.getCurrentAddr(); - } REQUIRE(msgQueue.wasMessageSent()); REQUIRE(msgQueue.numberOfSentMessagesToDefault() == 1); TmTcMessage msg; -- 2.43.0 From f1c37203a48cce0660951779310e12f4d36cf0a5 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Tue, 26 Jul 2022 11:14:40 +0200 Subject: [PATCH 064/108] some more API improvements and replacements --- automation/Jenkinsfile | 2 +- scripts/helper.py | 2 +- src/fsfw/cfdp/definitions.h | 21 +++++++------------ src/fsfw/pus/CService200ModeCommanding.cpp | 3 ++- src/fsfw/pus/CService201HealthCommanding.cpp | 2 +- src/fsfw/pus/Service17Test.h | 2 +- .../pus/Service1TelecommandVerification.h | 2 +- src/fsfw/pus/Service20ParameterManagement.cpp | 3 +-- src/fsfw/pus/Service3Housekeeping.cpp | 3 ++- src/fsfw/pus/Service5EventReporting.h | 2 +- src/fsfw/pus/Service8FunctionManagement.cpp | 3 ++- src/fsfw/tmtcpacket/pus/PusIF.h | 6 ++---- src/fsfw/tmtcpacket/pus/tm/PusTmCreator.cpp | 4 +--- src/fsfw/tmtcservices/CommandingServiceBase.h | 15 +++++++------ src/fsfw/tmtcservices/TmSendHelper.h | 1 - .../tmtcservices/TmStoreAndSendHelper.cpp | 9 ++++---- src/fsfw/tmtcservices/TmStoreAndSendHelper.h | 7 ++++--- src/fsfw/tmtcservices/TmStoreHelper.cpp | 11 +++++----- src/fsfw/tmtcservices/TmStoreHelper.h | 4 ++-- src/fsfw_hal/linux/CommandExecutor.h | 8 +++---- 20 files changed, 49 insertions(+), 61 deletions(-) diff --git a/automation/Jenkinsfile b/automation/Jenkinsfile index c5dcbe02..02340190 100644 --- a/automation/Jenkinsfile +++ b/automation/Jenkinsfile @@ -1,6 +1,6 @@ pipeline { environment { - BUILDDIR = 'build-tests' + BUILDDIR = 'cmake-build-tests' } agent { docker { image 'fsfw-ci:d3'} diff --git a/scripts/helper.py b/scripts/helper.py index 0ac616b6..0ced7186 100755 --- a/scripts/helper.py +++ b/scripts/helper.py @@ -13,7 +13,7 @@ from shutil import which from typing import List -UNITTEST_FOLDER_NAME = "build-tests" +UNITTEST_FOLDER_NAME = "cmake-build-tests" DOCS_FOLDER_NAME = "build-docs" diff --git a/src/fsfw/cfdp/definitions.h b/src/fsfw/cfdp/definitions.h index 93d15bcb..c532f3c1 100644 --- a/src/fsfw/cfdp/definitions.h +++ b/src/fsfw/cfdp/definitions.h @@ -15,24 +15,17 @@ static constexpr uint8_t VERSION_BITS = 0b00100000; static constexpr uint8_t CFDP_CLASS_ID = CLASS_ID::CFDP; -static constexpr ReturnValue_t INVALID_TLV_TYPE = - retval::makeCode(CFDP_CLASS_ID, 1); -static constexpr ReturnValue_t INVALID_DIRECTIVE_FIELDS = - retval::makeCode(CFDP_CLASS_ID, 2); -static constexpr ReturnValue_t INVALID_PDU_DATAFIELD_LEN = - retval::makeCode(CFDP_CLASS_ID, 3); -static constexpr ReturnValue_t INVALID_ACK_DIRECTIVE_FIELDS = - retval::makeCode(CFDP_CLASS_ID, 4); +static constexpr ReturnValue_t INVALID_TLV_TYPE = retval::makeCode(CFDP_CLASS_ID, 1); +static constexpr ReturnValue_t INVALID_DIRECTIVE_FIELDS = retval::makeCode(CFDP_CLASS_ID, 2); +static constexpr ReturnValue_t INVALID_PDU_DATAFIELD_LEN = retval::makeCode(CFDP_CLASS_ID, 3); +static constexpr ReturnValue_t INVALID_ACK_DIRECTIVE_FIELDS = retval::makeCode(CFDP_CLASS_ID, 4); //! Can not parse options. This can also occur because there are options //! available but the user did not pass a valid options array -static constexpr ReturnValue_t METADATA_CANT_PARSE_OPTIONS = - retval::makeCode(CFDP_CLASS_ID, 5); -static constexpr ReturnValue_t NAK_CANT_PARSE_OPTIONS = - retval::makeCode(CFDP_CLASS_ID, 6); +static constexpr ReturnValue_t METADATA_CANT_PARSE_OPTIONS = retval::makeCode(CFDP_CLASS_ID, 5); +static constexpr ReturnValue_t NAK_CANT_PARSE_OPTIONS = retval::makeCode(CFDP_CLASS_ID, 6); static constexpr ReturnValue_t FINISHED_CANT_PARSE_FS_RESPONSES = retval::makeCode(CFDP_CLASS_ID, 6); -static constexpr ReturnValue_t FILESTORE_REQUIRES_SECOND_FILE = - retval::makeCode(CFDP_CLASS_ID, 8); +static constexpr ReturnValue_t FILESTORE_REQUIRES_SECOND_FILE = retval::makeCode(CFDP_CLASS_ID, 8); //! Can not parse filestore response because user did not pass a valid instance //! or remaining size is invalid static constexpr ReturnValue_t FILESTORE_RESPONSE_CANT_PARSE_FS_MESSAGE = diff --git a/src/fsfw/pus/CService200ModeCommanding.cpp b/src/fsfw/pus/CService200ModeCommanding.cpp index 2e8e78a3..ea60d00b 100644 --- a/src/fsfw/pus/CService200ModeCommanding.cpp +++ b/src/fsfw/pus/CService200ModeCommanding.cpp @@ -113,7 +113,8 @@ ReturnValue_t CService200ModeCommanding::prepareWrongModeReply(const CommandMess ReturnValue_t CService200ModeCommanding::prepareCantReachModeReply(const CommandMessage *reply, object_id_t objectId) { CantReachModePacket cantReachModePacket(objectId, ModeMessage::getCantReachModeReason(reply)); - ReturnValue_t result = tmHelper.sendTmPacket(Subservice::REPLY_CANT_REACH_MODE, cantReachModePacket); + ReturnValue_t result = + tmHelper.sendTmPacket(Subservice::REPLY_CANT_REACH_MODE, cantReachModePacket); if (result == RETURN_OK) { // We want to produce an error here in any case because the mode was not reached return RETURN_FAILED; diff --git a/src/fsfw/pus/CService201HealthCommanding.cpp b/src/fsfw/pus/CService201HealthCommanding.cpp index c668ea52..4588907f 100644 --- a/src/fsfw/pus/CService201HealthCommanding.cpp +++ b/src/fsfw/pus/CService201HealthCommanding.cpp @@ -102,5 +102,5 @@ ReturnValue_t CService201HealthCommanding::handleReply(const CommandMessage *rep auto health = static_cast(HealthMessage::getHealth(reply)); auto oldHealth = static_cast(HealthMessage::getOldHealth(reply)); HealthSetReply healthSetReply(health, oldHealth); - return sendTmPacket(Subservice::REPLY_HEALTH_SET, healthSetReply); + return tmHelper.sendTmPacket(Subservice::REPLY_HEALTH_SET, healthSetReply); } diff --git a/src/fsfw/pus/Service17Test.h b/src/fsfw/pus/Service17Test.h index 771fbe55..7e2db98b 100644 --- a/src/fsfw/pus/Service17Test.h +++ b/src/fsfw/pus/Service17Test.h @@ -3,8 +3,8 @@ #include "fsfw/objectmanager/SystemObject.h" #include "fsfw/tmtcservices/PusServiceBase.h" -#include "fsfw/tmtcservices/TmStoreHelper.h" #include "fsfw/tmtcservices/TmStoreAndSendHelper.h" +#include "fsfw/tmtcservices/TmStoreHelper.h" /** * @brief Test Service diff --git a/src/fsfw/pus/Service1TelecommandVerification.h b/src/fsfw/pus/Service1TelecommandVerification.h index 5709e6a9..dcbb5017 100644 --- a/src/fsfw/pus/Service1TelecommandVerification.h +++ b/src/fsfw/pus/Service1TelecommandVerification.h @@ -8,8 +8,8 @@ #include "fsfw/tmtcservices/AcceptsVerifyMessageIF.h" #include "fsfw/tmtcservices/PusVerificationReport.h" #include "fsfw/tmtcservices/TmSendHelper.h" -#include "fsfw/tmtcservices/TmStoreHelper.h" #include "fsfw/tmtcservices/TmStoreAndSendHelper.h" +#include "fsfw/tmtcservices/TmStoreHelper.h" /** * @brief Verify TC acceptance, start, progress and execution. diff --git a/src/fsfw/pus/Service20ParameterManagement.cpp b/src/fsfw/pus/Service20ParameterManagement.cpp index ccb5a3b5..5f479530 100644 --- a/src/fsfw/pus/Service20ParameterManagement.cpp +++ b/src/fsfw/pus/Service20ParameterManagement.cpp @@ -64,8 +64,7 @@ ReturnValue_t Service20ParameterManagement::checkAndAcquireTargetID(object_id_t* ReturnValue_t Service20ParameterManagement::checkInterfaceAndAcquireMessageQueue( MessageQueueId_t* messageQueueToSet, object_id_t* objectId) { // check ReceivesParameterMessagesIF property of target - auto* possibleTarget = - ObjectManager::instance()->get(*objectId); + auto* possibleTarget = ObjectManager::instance()->get(*objectId); if (possibleTarget == nullptr) { #if FSFW_CPP_OSTREAM_ENABLED == 1 sif::error << "Service20ParameterManagement::checkInterfaceAndAcquire" diff --git a/src/fsfw/pus/Service3Housekeeping.cpp b/src/fsfw/pus/Service3Housekeeping.cpp index 7ef5636d..df7cbe0a 100644 --- a/src/fsfw/pus/Service3Housekeeping.cpp +++ b/src/fsfw/pus/Service3Housekeeping.cpp @@ -290,7 +290,8 @@ ReturnValue_t Service3Housekeeping::generateHkReply(const CommandMessage* hkMess } HkPacket hkPacket(sid, resultPair.second.data(), resultPair.second.size()); - return sendTmPacket(static_cast(subserviceId), hkPacket.hkData, hkPacket.hkSize); + return tmHelper.sendTmPacket(static_cast(subserviceId), hkPacket.hkData, + hkPacket.hkSize); } sid_t Service3Housekeeping::buildSid(object_id_t objectId, const uint8_t** tcData, diff --git a/src/fsfw/pus/Service5EventReporting.h b/src/fsfw/pus/Service5EventReporting.h index fcbdcb6b..e6f67bfd 100644 --- a/src/fsfw/pus/Service5EventReporting.h +++ b/src/fsfw/pus/Service5EventReporting.h @@ -2,8 +2,8 @@ #define FSFW_PUS_SERVICE5EVENTREPORTING_H_ #include "fsfw/events/EventMessage.h" -#include "fsfw/tmtcservices/TmStoreAndSendHelper.h" #include "fsfw/tmtcservices/PusServiceBase.h" +#include "fsfw/tmtcservices/TmStoreAndSendHelper.h" /** * @brief Report on-board events like information or errors diff --git a/src/fsfw/pus/Service8FunctionManagement.cpp b/src/fsfw/pus/Service8FunctionManagement.cpp index cec4e423..f9a6a168 100644 --- a/src/fsfw/pus/Service8FunctionManagement.cpp +++ b/src/fsfw/pus/Service8FunctionManagement.cpp @@ -138,7 +138,8 @@ ReturnValue_t Service8FunctionManagement::handleDataReply(const CommandMessage* return result; } DataReply dataReply(objectId, actionId, buffer, size); - result = tmHelper.sendTmPacket(static_cast(Subservice::REPLY_DIRECT_COMMANDING_DATA), dataReply); + result = tmHelper.sendTmPacket(static_cast(Subservice::REPLY_DIRECT_COMMANDING_DATA), + dataReply); auto deletionResult = ipcStore->deleteData(storeId); if (deletionResult != HasReturnvaluesIF::RETURN_OK) { diff --git a/src/fsfw/tmtcpacket/pus/PusIF.h b/src/fsfw/tmtcpacket/pus/PusIF.h index 93223ba8..5f27846e 100644 --- a/src/fsfw/tmtcpacket/pus/PusIF.h +++ b/src/fsfw/tmtcpacket/pus/PusIF.h @@ -9,10 +9,8 @@ class PusIF : public SpacePacketIF { public: static constexpr uint8_t INTERFACE_ID = CLASS_ID::PUS_IF; - static constexpr ReturnValue_t INVALID_PUS_VERSION = - retval::makeCode(INTERFACE_ID, 0); - static constexpr ReturnValue_t INVALID_CRC_16 = - retval::makeCode(INTERFACE_ID, 1); + static constexpr ReturnValue_t INVALID_PUS_VERSION = retval::makeCode(INTERFACE_ID, 0); + static constexpr ReturnValue_t INVALID_CRC_16 = retval::makeCode(INTERFACE_ID, 1); ~PusIF() override = default; /** diff --git a/src/fsfw/tmtcpacket/pus/tm/PusTmCreator.cpp b/src/fsfw/tmtcpacket/pus/tm/PusTmCreator.cpp index 71149613..ddcad33e 100644 --- a/src/fsfw/tmtcpacket/pus/tm/PusTmCreator.cpp +++ b/src/fsfw/tmtcpacket/pus/tm/PusTmCreator.cpp @@ -134,9 +134,7 @@ ReturnValue_t PusTmCreator::setSerializableUserData(SerializeIF& serializable) { return HasReturnvaluesIF::RETURN_OK; } -void PusTmCreator::setService(uint8_t service) { - pusParams.secHeader.service = service; -} +void PusTmCreator::setService(uint8_t service) { pusParams.secHeader.service = service; } void PusTmCreator::setSubservice(uint8_t subservice) { pusParams.secHeader.subservice = subservice; diff --git a/src/fsfw/tmtcservices/CommandingServiceBase.h b/src/fsfw/tmtcservices/CommandingServiceBase.h index e96c02d7..63067b07 100644 --- a/src/fsfw/tmtcservices/CommandingServiceBase.h +++ b/src/fsfw/tmtcservices/CommandingServiceBase.h @@ -6,7 +6,6 @@ #include "TmStoreHelper.h" #include "VerificationReporter.h" #include "fsfw/FSFW.h" -#include "fsfw/tmtcservices/TmStoreAndSendHelper.h" #include "fsfw/container/FIFO.h" #include "fsfw/container/FixedMap.h" #include "fsfw/ipc/CommandMessage.h" @@ -15,6 +14,7 @@ #include "fsfw/serialize/SerializeIF.h" #include "fsfw/storagemanager/StorageManagerIF.h" #include "fsfw/tasks/ExecutableObjectIF.h" +#include "fsfw/tmtcservices/TmStoreAndSendHelper.h" namespace Factory { void setStaticFrameworkObjectIds(); @@ -284,13 +284,12 @@ class CommandingServiceBase : public SystemObject, */ PeriodicTaskIF* executingTask = nullptr; - [[deprecated("Use function with same name provided by tmHelper")]] - ReturnValue_t sendTmPacket(uint8_t subservice, const uint8_t* sourceData, size_t sourceDataLen); - [[deprecated("Use function with same name provided by tmHelper")]] - ReturnValue_t sendTmPacket(uint8_t subservice, object_id_t objectId, const uint8_t* data, - size_t dataLen); - [[deprecated("Use function with same name provided by tmHelper")]] - ReturnValue_t sendTmPacket(uint8_t subservice, SerializeIF& sourceData); + [[deprecated("Use function with same name provided by tmHelper")]] ReturnValue_t sendTmPacket( + uint8_t subservice, const uint8_t* sourceData, size_t sourceDataLen); + [[deprecated("Use function with same name provided by tmHelper")]] ReturnValue_t sendTmPacket( + uint8_t subservice, object_id_t objectId, const uint8_t* data, size_t dataLen); + [[deprecated("Use function with same name provided by tmHelper")]] ReturnValue_t sendTmPacket( + uint8_t subservice, SerializeIF& sourceData); void checkAndExecuteFifo(CommandMapIter& iter); diff --git a/src/fsfw/tmtcservices/TmSendHelper.h b/src/fsfw/tmtcservices/TmSendHelper.h index c4bec886..244e7900 100644 --- a/src/fsfw/tmtcservices/TmSendHelper.h +++ b/src/fsfw/tmtcservices/TmSendHelper.h @@ -28,7 +28,6 @@ class TmSendHelper { ReturnValue_t sendPacket(MessageQueueId_t dest, const store_address_t& storeId); ReturnValue_t sendPacket(const store_address_t& storeId); - private: MessageQueueId_t defaultDest = MessageQueueIF::NO_QUEUE; bool ignoreFault = false; diff --git a/src/fsfw/tmtcservices/TmStoreAndSendHelper.cpp b/src/fsfw/tmtcservices/TmStoreAndSendHelper.cpp index f10bea32..61735ab5 100644 --- a/src/fsfw/tmtcservices/TmStoreAndSendHelper.cpp +++ b/src/fsfw/tmtcservices/TmStoreAndSendHelper.cpp @@ -1,9 +1,10 @@ #include "TmStoreAndSendHelper.h" + #include "tmHelpers.h" -TmStoreAndSendWrapper::TmStoreAndSendWrapper( - uint8_t defaultService, TmStoreHelper& storeHelper, TmSendHelper& sendHelper) - : storeHelper(storeHelper), sendHelper(sendHelper), defaultService(defaultService){} +TmStoreAndSendWrapper::TmStoreAndSendWrapper(uint8_t defaultService, TmStoreHelper& storeHelper, + TmSendHelper& sendHelper) + : storeHelper(storeHelper), sendHelper(sendHelper), defaultService(defaultService) {} ReturnValue_t TmStoreAndSendWrapper::storeAndSendTmPacket() { ReturnValue_t result = storeHelper.addPacketToStore(); @@ -17,7 +18,7 @@ ReturnValue_t TmStoreAndSendWrapper::storeAndSendTmPacket() { } return result; } - if(incrementSendCounter) { + if (incrementSendCounter) { sendCounter++; } return result; diff --git a/src/fsfw/tmtcservices/TmStoreAndSendHelper.h b/src/fsfw/tmtcservices/TmStoreAndSendHelper.h index 44ad1799..1a33b7d7 100644 --- a/src/fsfw/tmtcservices/TmStoreAndSendHelper.h +++ b/src/fsfw/tmtcservices/TmStoreAndSendHelper.h @@ -5,12 +5,13 @@ #include "TmStoreHelper.h" /** - * Wrapper class intended to help with PUS TM handling. This wrapper class also caches the current packet count - * and the service ID + * Wrapper class intended to help with PUS TM handling. This wrapper class also caches the current + * packet count and the service ID */ class TmStoreAndSendWrapper { public: - TmStoreAndSendWrapper(uint8_t defaultService, TmStoreHelper& storeHelper, TmSendHelper& sendHelper); + TmStoreAndSendWrapper(uint8_t defaultService, TmStoreHelper& storeHelper, + TmSendHelper& sendHelper); ReturnValue_t storeAndSendTmPacket(); ReturnValue_t sendTmPacket(uint8_t subservice); diff --git a/src/fsfw/tmtcservices/TmStoreHelper.cpp b/src/fsfw/tmtcservices/TmStoreHelper.cpp index a8105ae0..a87ca01d 100644 --- a/src/fsfw/tmtcservices/TmStoreHelper.cpp +++ b/src/fsfw/tmtcservices/TmStoreHelper.cpp @@ -18,10 +18,9 @@ TmStoreHelper::TmStoreHelper(uint16_t defaultApid, StorageManagerIF& tmStore, } ReturnValue_t TmStoreHelper::preparePacket(uint8_t service, uint8_t subservice, uint16_t counter) { - PusTmParams& params = creator.getParams(); - params.secHeader.service = service; - params.secHeader.subservice = subservice; - params.secHeader.messageTypeCounter = counter; + creator.setService(service); + creator.setSubservice(subservice); + creator.setMessageTypeCounter(counter); return HasReturnvaluesIF::RETURN_OK; } @@ -72,6 +71,6 @@ TimeStamperIF* TmStoreHelper::getTimeStamper() const { return creator.getTimesta uint16_t TmStoreHelper::getApid() const { return creator.getApid(); } -ReturnValue_t TmStoreHelper::setService(uint8_t service) { creator.setService(service); } +void TmStoreHelper::setService(uint8_t service) { creator.setService(service); } -ReturnValue_t TmStoreHelper::setSubservice(uint8_t subservice) { creator.setSubservice(subservice); } +void TmStoreHelper::setSubservice(uint8_t subservice) { creator.setSubservice(subservice); } diff --git a/src/fsfw/tmtcservices/TmStoreHelper.h b/src/fsfw/tmtcservices/TmStoreHelper.h index 6c18ac7f..e5d9eb7d 100644 --- a/src/fsfw/tmtcservices/TmStoreHelper.h +++ b/src/fsfw/tmtcservices/TmStoreHelper.h @@ -27,8 +27,8 @@ class TmStoreHelper { [[nodiscard]] uint16_t getApid() const; [[nodiscard]] const store_address_t& getCurrentAddr() const; - ReturnValue_t setService(uint8_t service); - ReturnValue_t setSubservice(uint8_t subservice); + void setService(uint8_t service); + void setSubservice(uint8_t subservice); ReturnValue_t setSourceDataRaw(const uint8_t* data, size_t len); ReturnValue_t setSourceDataSerializable(SerializeIF& serializable); diff --git a/src/fsfw_hal/linux/CommandExecutor.h b/src/fsfw_hal/linux/CommandExecutor.h index f5c7a803..27e78260 100644 --- a/src/fsfw_hal/linux/CommandExecutor.h +++ b/src/fsfw_hal/linux/CommandExecutor.h @@ -31,8 +31,7 @@ class CommandExecutor { static constexpr uint8_t CLASS_ID = CLASS_ID::LINUX_OSAL; //! [EXPORT] : [COMMENT] Execution of the current command has finished - static constexpr ReturnValue_t EXECUTION_FINISHED = - retval::makeCode(CLASS_ID, 0); + static constexpr ReturnValue_t EXECUTION_FINISHED = retval::makeCode(CLASS_ID, 0); //! [EXPORT] : [COMMENT] Command is pending. This will also be returned if the user tries //! to load another command but a command is still pending @@ -42,9 +41,8 @@ class CommandExecutor { //! [EXPORT] : [COMMENT] Command execution failed static constexpr ReturnValue_t COMMAND_ERROR = retval::makeCode(CLASS_ID, 3); //! [EXPORT] : [COMMENT] - static constexpr ReturnValue_t NO_COMMAND_LOADED_OR_PENDING = - retval::makeCode(CLASS_ID, 4); - static constexpr ReturnValue_t PCLOSE_CALL_ERROR =retval::makeCode(CLASS_ID, 6); + static constexpr ReturnValue_t NO_COMMAND_LOADED_OR_PENDING = retval::makeCode(CLASS_ID, 4); + static constexpr ReturnValue_t PCLOSE_CALL_ERROR = retval::makeCode(CLASS_ID, 6); /** * Constructor. Is initialized with maximum size of internal buffer to read data from the -- 2.43.0 From 332e9dbfd54fc02bdab1ff95e751c23a274b3532 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Tue, 26 Jul 2022 11:19:36 +0200 Subject: [PATCH 065/108] add new tests --- unittests/tmtcservices/testSendHelper.cpp | 1 - .../tmtcservices/testStoreAndSendHelper.cpp | 19 +++++++++++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) create mode 100644 unittests/tmtcservices/testStoreAndSendHelper.cpp diff --git a/unittests/tmtcservices/testSendHelper.cpp b/unittests/tmtcservices/testSendHelper.cpp index 4271f192..786fe073 100644 --- a/unittests/tmtcservices/testSendHelper.cpp +++ b/unittests/tmtcservices/testSendHelper.cpp @@ -3,7 +3,6 @@ #include "fsfw/storagemanager/LocalPool.h" #include "fsfw/tmtcservices/TmSendHelper.h" #include "fsfw/tmtcservices/TmStoreHelper.h" -#include "fsfw/tmtcservices/tmHelpers.h" #include "mocks/CdsShortTimestamperMock.h" #include "mocks/InternalErrorReporterMock.h" #include "mocks/MessageQueueMock.h" diff --git a/unittests/tmtcservices/testStoreAndSendHelper.cpp b/unittests/tmtcservices/testStoreAndSendHelper.cpp new file mode 100644 index 00000000..309556b6 --- /dev/null +++ b/unittests/tmtcservices/testStoreAndSendHelper.cpp @@ -0,0 +1,19 @@ +#include + +#include "fsfw/storagemanager/LocalPool.h" +#include "fsfw/tmtcservices/TmSendHelper.h" +#include "fsfw/tmtcservices/TmStoreHelper.h" +#include "mocks/CdsShortTimestamperMock.h" + +TEST_CASE("TM Store And Send Helper", "[tm-store-send-helper]") { + auto timeStamper = CdsShortTimestamperMock(); + LocalPool::LocalPoolConfig cfg = {{5, 32}, {2, 64}}; + LocalPool pool(objects::NO_OBJECT, cfg); + auto storeHelper = TmStoreHelper(2, pool, timeStamper); + + MessageQueueId_t destId = 1; + auto errReporter = InternalErrorReporterMock(); + auto msgQueue = MessageQueueMock(); + msgQueue.setDefaultDestination(destId); + TmSendHelper sendHelper(msgQueue, errReporter, destId); +} -- 2.43.0 From 75c824ec80cfc2e69539da1917e1913c6ef42321 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Tue, 26 Jul 2022 13:59:09 +0200 Subject: [PATCH 066/108] add new VerificationReporterIF --- src/fsfw/objectmanager/frameworkObjects.h | 1 + src/fsfw/pus/CService200ModeCommanding.cpp | 7 +- src/fsfw/pus/CService201HealthCommanding.cpp | 2 +- src/fsfw/pus/Service17Test.cpp | 12 +- src/fsfw/pus/Service20ParameterManagement.cpp | 3 +- src/fsfw/pus/Service2DeviceAccess.cpp | 6 +- src/fsfw/pus/Service3Housekeeping.cpp | 3 +- src/fsfw/pus/Service8FunctionManagement.cpp | 3 +- src/fsfw/retval.h | 6 + src/fsfw/tcdistribution/PusDistributor.cpp | 6 +- src/fsfw/tcdistribution/PusDistributor.h | 2 +- .../tmtcservices/AcceptsVerifyMessageIF.h | 4 +- .../tmtcservices/CommandingServiceBase.cpp | 142 +++++++++++------- src/fsfw/tmtcservices/CommandingServiceBase.h | 34 +++-- src/fsfw/tmtcservices/PusServiceBase.cpp | 36 ++++- src/fsfw/tmtcservices/PusServiceBase.h | 20 ++- .../tmtcservices/TmStoreAndSendHelper.cpp | 45 +++--- src/fsfw/tmtcservices/TmStoreAndSendHelper.h | 29 ++-- .../tmtcservices/VerificationReporter.cpp | 105 +++---------- src/fsfw/tmtcservices/VerificationReporter.h | 32 ++-- .../tmtcservices/VerificationReporterIF.h | 57 +++++++ src/fsfw/tmtcservices/tmHelpers.h | 56 ++++--- unittests/CatchFactory.cpp | 2 - unittests/mocks/PusServiceBaseMock.cpp | 30 ++++ unittests/mocks/PusServiceBaseMock.h | 23 +++ unittests/tmtcservices/CMakeLists.txt | 1 + unittests/tmtcservices/testPsb.cpp | 5 + .../tmtcservices/testStoreAndSendHelper.cpp | 68 +++++++++ 28 files changed, 486 insertions(+), 254 deletions(-) create mode 100644 src/fsfw/retval.h create mode 100644 src/fsfw/tmtcservices/VerificationReporterIF.h create mode 100644 unittests/mocks/PusServiceBaseMock.cpp create mode 100644 unittests/mocks/PusServiceBaseMock.h create mode 100644 unittests/tmtcservices/testPsb.cpp diff --git a/src/fsfw/objectmanager/frameworkObjects.h b/src/fsfw/objectmanager/frameworkObjects.h index cddc6ba2..be664621 100644 --- a/src/fsfw/objectmanager/frameworkObjects.h +++ b/src/fsfw/objectmanager/frameworkObjects.h @@ -33,6 +33,7 @@ enum framework_objects : object_id_t { TC_STORE = 0x534f0100, TM_STORE = 0x534f0200, TIME_STAMPER = 0x53500010, + TC_VERIFICATOR = 0x53500020, FSFW_OBJECTS_END = 0x53ffffff, NO_OBJECT = 0xFFFFFFFF diff --git a/src/fsfw/pus/CService200ModeCommanding.cpp b/src/fsfw/pus/CService200ModeCommanding.cpp index ea60d00b..9990280c 100644 --- a/src/fsfw/pus/CService200ModeCommanding.cpp +++ b/src/fsfw/pus/CService200ModeCommanding.cpp @@ -96,13 +96,13 @@ ReturnValue_t CService200ModeCommanding::handleReply(const CommandMessage *reply ReturnValue_t CService200ModeCommanding::prepareModeReply(const CommandMessage *reply, object_id_t objectId) { ModePacket modeReplyPacket(objectId, ModeMessage::getMode(reply), ModeMessage::getSubmode(reply)); - return tmHelper.sendTmPacket(Subservice::REPLY_MODE_REPLY, modeReplyPacket); + return sendTmPacket(Subservice::REPLY_MODE_REPLY, modeReplyPacket); } ReturnValue_t CService200ModeCommanding::prepareWrongModeReply(const CommandMessage *reply, object_id_t objectId) { ModePacket wrongModeReply(objectId, ModeMessage::getMode(reply), ModeMessage::getSubmode(reply)); - ReturnValue_t result = tmHelper.sendTmPacket(Subservice::REPLY_WRONG_MODE_REPLY, wrongModeReply); + ReturnValue_t result = sendTmPacket(Subservice::REPLY_WRONG_MODE_REPLY, wrongModeReply); if (result == RETURN_OK) { // We want to produce an error here in any case because the mode was not correct return RETURN_FAILED; @@ -113,8 +113,7 @@ ReturnValue_t CService200ModeCommanding::prepareWrongModeReply(const CommandMess ReturnValue_t CService200ModeCommanding::prepareCantReachModeReply(const CommandMessage *reply, object_id_t objectId) { CantReachModePacket cantReachModePacket(objectId, ModeMessage::getCantReachModeReason(reply)); - ReturnValue_t result = - tmHelper.sendTmPacket(Subservice::REPLY_CANT_REACH_MODE, cantReachModePacket); + ReturnValue_t result = sendTmPacket(Subservice::REPLY_CANT_REACH_MODE, cantReachModePacket); if (result == RETURN_OK) { // We want to produce an error here in any case because the mode was not reached return RETURN_FAILED; diff --git a/src/fsfw/pus/CService201HealthCommanding.cpp b/src/fsfw/pus/CService201HealthCommanding.cpp index 4588907f..c668ea52 100644 --- a/src/fsfw/pus/CService201HealthCommanding.cpp +++ b/src/fsfw/pus/CService201HealthCommanding.cpp @@ -102,5 +102,5 @@ ReturnValue_t CService201HealthCommanding::handleReply(const CommandMessage *rep auto health = static_cast(HealthMessage::getHealth(reply)); auto oldHealth = static_cast(HealthMessage::getOldHealth(reply)); HealthSetReply healthSetReply(health, oldHealth); - return tmHelper.sendTmPacket(Subservice::REPLY_HEALTH_SET, healthSetReply); + return sendTmPacket(Subservice::REPLY_HEALTH_SET, healthSetReply); } diff --git a/src/fsfw/pus/Service17Test.cpp b/src/fsfw/pus/Service17Test.cpp index b40d2d70..d526e055 100644 --- a/src/fsfw/pus/Service17Test.cpp +++ b/src/fsfw/pus/Service17Test.cpp @@ -15,11 +15,19 @@ Service17Test::~Service17Test() = default; ReturnValue_t Service17Test::handleRequest(uint8_t subservice) { switch (subservice) { case Subservice::CONNECTION_TEST: { - return tmHelper.sendTmPacket(Subservice::CONNECTION_TEST_REPORT); + ReturnValue_t result = tmHelper.prepareTmPacket(Subservice::CONNECTION_TEST_REPORT); + if (result != HasReturnvaluesIF::RETURN_OK) { + return result; + } + return tmHelper.storeAndSendTmPacket(); } case Subservice::EVENT_TRIGGER_TEST: { triggerEvent(TEST, 1234, 5678); - return tmHelper.sendTmPacket(Subservice::EVENT_TRIGGER_TEST); + ReturnValue_t result = tmHelper.prepareTmPacket(Subservice::EVENT_TRIGGER_TEST); + if (result != HasReturnvaluesIF::RETURN_OK) { + return result; + } + return tmHelper.storeAndSendTmPacket(); } default: return AcceptsTelecommandsIF::INVALID_SUBSERVICE; diff --git a/src/fsfw/pus/Service20ParameterManagement.cpp b/src/fsfw/pus/Service20ParameterManagement.cpp index 5f479530..6d6ca339 100644 --- a/src/fsfw/pus/Service20ParameterManagement.cpp +++ b/src/fsfw/pus/Service20ParameterManagement.cpp @@ -176,8 +176,7 @@ ReturnValue_t Service20ParameterManagement::handleReply(const CommandMessage* re ParameterId_t parameterId = ParameterMessage::getParameterId(reply); ParameterDumpReply parameterReply(objectId, parameterId, parameterData.second.data(), parameterData.second.size()); - tmHelper.sendTmPacket(static_cast(Subservice::PARAMETER_DUMP_REPLY), parameterReply); - return HasReturnvaluesIF::RETURN_OK; + return sendTmPacket(static_cast(Subservice::PARAMETER_DUMP_REPLY), parameterReply); } default: return CommandingServiceBase::INVALID_REPLY; diff --git a/src/fsfw/pus/Service2DeviceAccess.cpp b/src/fsfw/pus/Service2DeviceAccess.cpp index 008d8128..817a372e 100644 --- a/src/fsfw/pus/Service2DeviceAccess.cpp +++ b/src/fsfw/pus/Service2DeviceAccess.cpp @@ -148,7 +148,11 @@ void Service2DeviceAccess::sendWiretappingTm(CommandMessage* reply, uint8_t subs // Init our dummy packet and correct endianness of object ID before // sending it back. WiretappingPacket tmPacket(DeviceHandlerMessage::getDeviceObjectId(reply), data); - tmHelper.sendTmPacket(subservice, tmPacket.objectId, tmPacket.data, size); + result = sendTmPacket(subservice, tmPacket.objectId, tmPacket.data, size); + if (result != retval::OK) { + // TODO: Warning + return; + } } MessageQueueId_t Service2DeviceAccess::getDeviceQueue() { return commandQueue->getId(); } diff --git a/src/fsfw/pus/Service3Housekeeping.cpp b/src/fsfw/pus/Service3Housekeeping.cpp index df7cbe0a..7ef5636d 100644 --- a/src/fsfw/pus/Service3Housekeeping.cpp +++ b/src/fsfw/pus/Service3Housekeeping.cpp @@ -290,8 +290,7 @@ ReturnValue_t Service3Housekeeping::generateHkReply(const CommandMessage* hkMess } HkPacket hkPacket(sid, resultPair.second.data(), resultPair.second.size()); - return tmHelper.sendTmPacket(static_cast(subserviceId), hkPacket.hkData, - hkPacket.hkSize); + return sendTmPacket(static_cast(subserviceId), hkPacket.hkData, hkPacket.hkSize); } sid_t Service3Housekeeping::buildSid(object_id_t objectId, const uint8_t** tcData, diff --git a/src/fsfw/pus/Service8FunctionManagement.cpp b/src/fsfw/pus/Service8FunctionManagement.cpp index f9a6a168..c9da6d58 100644 --- a/src/fsfw/pus/Service8FunctionManagement.cpp +++ b/src/fsfw/pus/Service8FunctionManagement.cpp @@ -138,8 +138,7 @@ ReturnValue_t Service8FunctionManagement::handleDataReply(const CommandMessage* return result; } DataReply dataReply(objectId, actionId, buffer, size); - result = tmHelper.sendTmPacket(static_cast(Subservice::REPLY_DIRECT_COMMANDING_DATA), - dataReply); + result = sendTmPacket(static_cast(Subservice::REPLY_DIRECT_COMMANDING_DATA), dataReply); auto deletionResult = ipcStore->deleteData(storeId); if (deletionResult != HasReturnvaluesIF::RETURN_OK) { diff --git a/src/fsfw/retval.h b/src/fsfw/retval.h new file mode 100644 index 00000000..43c4e127 --- /dev/null +++ b/src/fsfw/retval.h @@ -0,0 +1,6 @@ +#ifndef FSFW_RETVAL_H +#define FSFW_RETVAL_H + +#include "fsfw/returnvalues/HasReturnvaluesIF.h" + +#endif // FSFW_RETVAL_H diff --git a/src/fsfw/tcdistribution/PusDistributor.cpp b/src/fsfw/tcdistribution/PusDistributor.cpp index 3a7fdf34..1cef2b9f 100644 --- a/src/fsfw/tcdistribution/PusDistributor.cpp +++ b/src/fsfw/tcdistribution/PusDistributor.cpp @@ -12,7 +12,6 @@ PusDistributor::PusDistributor(StorageManagerIF* store_, uint16_t setApid, objec : TcDistributor(setObjectId), store(store_), checker(setApid, ccsds::PacketType::TC), - verifyChannel(), tcStatus(RETURN_FAILED), packetSource(setPacketSource) {} @@ -120,13 +119,14 @@ ReturnValue_t PusDistributor::callbackAfterSending(ReturnValue_t queueStatus) { tcStatus = queueStatus; } if (tcStatus != RETURN_OK) { - this->verifyChannel.sendFailureReport(tcverif::ACCEPTANCE_FAILURE, &reader, tcStatus); + verifyChannel->sendFailureReport( + VerifFailureParams(tcverif::ACCEPTANCE_FAILURE, reader, tcStatus)); // A failed packet is deleted immediately after reporting, // otherwise it will block memory. store->deleteData(currentMessage.getStorageId()); return RETURN_FAILED; } else { - this->verifyChannel.sendSuccessReport(tcverif::ACCEPTANCE_SUCCESS, &reader); + verifyChannel->sendSuccessReport(VerifSuccessParams(tcverif::ACCEPTANCE_SUCCESS, reader)); return RETURN_OK; } } diff --git a/src/fsfw/tcdistribution/PusDistributor.h b/src/fsfw/tcdistribution/PusDistributor.h index fb916263..3849c793 100644 --- a/src/fsfw/tcdistribution/PusDistributor.h +++ b/src/fsfw/tcdistribution/PusDistributor.h @@ -48,7 +48,7 @@ class PusDistributor : public TcDistributor, public PUSDistributorIF, public Acc * With this class, verification messages are sent to the * TC Verification service. */ - VerificationReporter verifyChannel; + VerificationReporterIF* verifyChannel = nullptr; /** * The currently handled packet is stored here. */ diff --git a/src/fsfw/tmtcservices/AcceptsVerifyMessageIF.h b/src/fsfw/tmtcservices/AcceptsVerifyMessageIF.h index 7e58187b..daf67080 100644 --- a/src/fsfw/tmtcservices/AcceptsVerifyMessageIF.h +++ b/src/fsfw/tmtcservices/AcceptsVerifyMessageIF.h @@ -1,11 +1,11 @@ #ifndef FSFW_TMTCSERVICES_ACCEPTSVERIFICATIONMESSAGEIF_H_ #define FSFW_TMTCSERVICES_ACCEPTSVERIFICATIONMESSAGEIF_H_ -#include "../ipc/MessageQueueSenderIF.h" +#include "fsfw/ipc/MessageQueueSenderIF.h" class AcceptsVerifyMessageIF { public: - virtual ~AcceptsVerifyMessageIF() {} + virtual ~AcceptsVerifyMessageIF() = default; virtual MessageQueueId_t getVerificationQueue() = 0; }; diff --git a/src/fsfw/tmtcservices/CommandingServiceBase.cpp b/src/fsfw/tmtcservices/CommandingServiceBase.cpp index 7839aa87..c890ecfb 100644 --- a/src/fsfw/tmtcservices/CommandingServiceBase.cpp +++ b/src/fsfw/tmtcservices/CommandingServiceBase.cpp @@ -15,13 +15,15 @@ object_id_t CommandingServiceBase::defaultPacketDestination = objects::NO_OBJECT CommandingServiceBase::CommandingServiceBase(object_id_t setObjectId, uint16_t apid, uint8_t service, uint8_t numberOfParallelCommands, - uint16_t commandTimeoutSeconds, size_t queueDepth) + uint16_t commandTimeoutSeconds, size_t queueDepth, + VerificationReporterIF* verificationReporter) : SystemObject(setObjectId), apid(apid), service(service), timeoutSeconds(commandTimeoutSeconds), tmStoreHelper(apid), tmHelper(service, tmStoreHelper, tmSendHelper), + verificationReporter(verificationReporter), commandMap(numberOfParallelCommands) { commandQueue = QueueFactory::instance()->createMessageQueue(queueDepth); requestQueue = QueueFactory::instance()->createMessageQueue(queueDepth); @@ -105,12 +107,19 @@ ReturnValue_t CommandingServiceBase::initialize() { tmSendHelper.setInternalErrorReporter(errReporter); } } + if (verificationReporter == nullptr) { + verificationReporter = + ObjectManager::instance()->get(objects::TC_VERIFICATOR); + if (verificationReporter == nullptr) { + return ObjectManagerIF::CHILD_INIT_FAILED; + } + } return RETURN_OK; } void CommandingServiceBase::handleCommandQueue() { CommandMessage reply; - ReturnValue_t result = RETURN_FAILED; + ReturnValue_t result; while (true) { result = commandQueue->receiveMessage(&reply); if (result == HasReturnvaluesIF::RETURN_OK) { @@ -175,16 +184,14 @@ void CommandingServiceBase::handleCommandMessage(CommandMessage* reply) { break; default: if (isStep) { - verificationReporter.sendFailureReport( - tcverif::PROGRESS_FAILURE, iter->second.tcInfo.ackFlags, iter->second.tcInfo.tcPacketId, - iter->second.tcInfo.tcSequenceControl, result, ++iter->second.step, failureParameter1, - failureParameter2); + prepareVerificationFailureWithFullInfo(tcverif::PROGRESS_FAILURE, iter->second.tcInfo, + result, true); + failParams.step = ++iter->second.step; } else { - verificationReporter.sendFailureReport( - tcverif::COMPLETION_FAILURE, iter->second.tcInfo.ackFlags, - iter->second.tcInfo.tcPacketId, iter->second.tcInfo.tcSequenceControl, result, 0, - failureParameter1, failureParameter2); + prepareVerificationFailureWithFullInfo(tcverif::COMPLETION_FAILURE, iter->second.tcInfo, + result, true); } + verificationReporter->sendFailureReport(failParams); failureParameter1 = 0; failureParameter2 = 0; checkAndExecuteFifo(iter); @@ -207,28 +214,26 @@ void CommandingServiceBase::handleReplyHandlerResult(ReturnValue_t result, Comma if (sendResult == RETURN_OK) { if (isStep and result != NO_STEP_MESSAGE) { - verificationReporter.sendSuccessReport( - tcverif::PROGRESS_SUCCESS, iter->second.tcInfo.ackFlags, iter->second.tcInfo.tcPacketId, - iter->second.tcInfo.tcSequenceControl, ++iter->second.step); + prepareVerificationSuccessWithFullInfo(tcverif::PROGRESS_SUCCESS, iter->second.tcInfo); + successParams.step = ++iter->second.step; + verificationReporter->sendSuccessReport(successParams); } else { - verificationReporter.sendSuccessReport( - tcverif::COMPLETION_SUCCESS, iter->second.tcInfo.ackFlags, iter->second.tcInfo.tcPacketId, - iter->second.tcInfo.tcSequenceControl, 0); + prepareVerificationSuccessWithFullInfo(tcverif::COMPLETION_SUCCESS, iter->second.tcInfo); + verificationReporter->sendSuccessReport(successParams); checkAndExecuteFifo(iter); } } else { if (isStep) { + prepareVerificationFailureWithFullInfo(tcverif::PROGRESS_FAILURE, iter->second.tcInfo, result, + true); + failParams.step = ++iter->second.step; nextCommand->clearCommandMessage(); - verificationReporter.sendFailureReport( - tcverif::PROGRESS_FAILURE, iter->second.tcInfo.ackFlags, iter->second.tcInfo.tcPacketId, - iter->second.tcInfo.tcSequenceControl, sendResult, ++iter->second.step, failureParameter1, - failureParameter2); + verificationReporter->sendFailureReport(failParams); } else { + prepareVerificationFailureWithFullInfo(tcverif::COMPLETION_FAILURE, iter->second.tcInfo, + result, true); nextCommand->clearCommandMessage(); - verificationReporter.sendFailureReport( - tcverif::COMPLETION_FAILURE, iter->second.tcInfo.ackFlags, iter->second.tcInfo.tcPacketId, - iter->second.tcInfo.tcSequenceControl, sendResult, 0, failureParameter1, - failureParameter2); + verificationReporter->sendFailureReport(failParams); } failureParameter1 = 0; failureParameter2 = 0; @@ -247,19 +252,19 @@ void CommandingServiceBase::handleRequestQueue() { result = setUpTcReader(message.getStorageId()); if (result != HasReturnvaluesIF::RETURN_OK) { // TODO: Warning? - rejectPacket(tcverif::START_FAILURE, address, &tcReader, result); + rejectPacket(tcverif::START_FAILURE, address, result); continue; } if ((tcReader.getSubService() == 0) or (isValidSubservice(tcReader.getSubService()) != RETURN_OK)) { - rejectPacket(tcverif::START_FAILURE, address, &tcReader, INVALID_SUBSERVICE); + rejectPacket(tcverif::START_FAILURE, address, INVALID_SUBSERVICE); continue; } result = getMessageQueueAndObject(tcReader.getSubService(), tcReader.getUserData(), tcReader.getUserDataLen(), &queue, &objectId); if (result != HasReturnvaluesIF::RETURN_OK) { - rejectPacket(tcverif::START_FAILURE, address, &tcReader, result); + rejectPacket(tcverif::START_FAILURE, address, result); continue; } @@ -270,14 +275,14 @@ void CommandingServiceBase::handleRequestQueue() { if (iter != commandMap.end()) { result = iter->second.fifo.insert(address); if (result != RETURN_OK) { - rejectPacket(tcverif::START_FAILURE, address, &tcReader, OBJECT_BUSY); + rejectPacket(tcverif::START_FAILURE, address, OBJECT_BUSY); } } else { CommandInfo newInfo; // Info will be set by startExecution if neccessary newInfo.objectId = objectId; result = commandMap.insert(queue, newInfo, &iter); if (result != RETURN_OK) { - rejectPacket(tcverif::START_FAILURE, address, &tcReader, BUSY); + rejectPacket(tcverif::START_FAILURE, address, BUSY); } else { startExecution(address, iter); } @@ -287,24 +292,37 @@ void CommandingServiceBase::handleRequestQueue() { ReturnValue_t CommandingServiceBase::sendTmPacket(uint8_t subservice, const uint8_t* sourceData, size_t sourceDataLen) { - return tmHelper.sendTmPacket(subservice, sourceData, sourceDataLen); + ReturnValue_t result = tmHelper.prepareTmPacket(subservice, sourceData, sourceDataLen); + if (result != retval::OK) { + return result; + } + return tmHelper.storeAndSendTmPacket(); } ReturnValue_t CommandingServiceBase::sendTmPacket(uint8_t subservice, object_id_t objectId, const uint8_t* data, size_t dataLen) { - return tmHelper.sendTmPacket(subservice, objectId, data, dataLen); + telemetry::DataWithObjectIdPrefix dataWithObjId(objectId, data, dataLen); + ReturnValue_t result = tmHelper.prepareTmPacket(subservice, dataWithObjId); + if (result != retval::OK) { + return result; + } + return tmHelper.storeAndSendTmPacket(); } ReturnValue_t CommandingServiceBase::sendTmPacket(uint8_t subservice, SerializeIF& sourceData) { - return tmHelper.sendTmPacket(subservice, sourceData); + ReturnValue_t result = tmHelper.prepareTmPacket(subservice, sourceData); + if (result != retval::OK) { + return result; + } + return tmHelper.storeAndSendTmPacket(); } -void CommandingServiceBase::startExecution(store_address_t storeId, CommandMapIter iter) { - ReturnValue_t result = RETURN_OK; +void CommandingServiceBase::startExecution(store_address_t storeId, CommandMapIter& iter) { CommandMessage command; iter->second.subservice = tcReader.getSubService(); - result = prepareCommand(&command, iter->second.subservice, tcReader.getUserData(), - tcReader.getUserDataLen(), &iter->second.state, iter->second.objectId); + ReturnValue_t result = + prepareCommand(&command, iter->second.subservice, tcReader.getUserData(), + tcReader.getUserDataLen(), &iter->second.state, iter->second.objectId); ReturnValue_t sendResult = RETURN_OK; switch (result) { @@ -320,10 +338,10 @@ void CommandingServiceBase::startExecution(store_address_t storeId, CommandMapIt iter->second.tcInfo.ackFlags = tcReader.getAcknowledgeFlags(); iter->second.tcInfo.tcPacketId = tcReader.getPacketIdRaw(); iter->second.tcInfo.tcSequenceControl = tcReader.getPacketSeqCtrlRaw(); - acceptPacket(tcverif::START_SUCCESS, storeId, &tcReader); + acceptPacket(tcverif::START_SUCCESS, storeId); } else { command.clearCommandMessage(); - rejectPacket(tcverif::START_FAILURE, storeId, &tcReader, sendResult); + rejectPacket(tcverif::START_FAILURE, storeId, sendResult); checkAndExecuteFifo(iter); } break; @@ -333,31 +351,31 @@ void CommandingServiceBase::startExecution(store_address_t storeId, CommandMapIt sendResult = commandQueue->sendMessage(iter.value->first, &command); } if (sendResult == RETURN_OK) { - verificationReporter.sendSuccessReport(tcverif::START_SUCCESS, &tcReader); - acceptPacket(tcverif::COMPLETION_SUCCESS, storeId, &tcReader); + verificationReporter->sendSuccessReport( + VerifSuccessParams(tcverif::START_SUCCESS, tcReader)); + acceptPacket(tcverif::COMPLETION_SUCCESS, storeId); checkAndExecuteFifo(iter); } else { command.clearCommandMessage(); - rejectPacket(tcverif::START_FAILURE, storeId, &tcReader, sendResult); + rejectPacket(tcverif::START_FAILURE, storeId, sendResult); checkAndExecuteFifo(iter); } break; default: - rejectPacket(tcverif::START_FAILURE, storeId, &tcReader, result); + rejectPacket(tcverif::START_FAILURE, storeId, result); checkAndExecuteFifo(iter); break; } } void CommandingServiceBase::rejectPacket(uint8_t reportId, store_address_t tcStoreId, - PusTcReader* correspondingTc, ReturnValue_t errorCode) { - verificationReporter.sendFailureReport(reportId, correspondingTc, errorCode); + ReturnValue_t errorCode) { + verificationReporter->sendFailureReport(VerifFailureParams(reportId, tcReader, errorCode)); tcStore->deleteData(tcStoreId); } -void CommandingServiceBase::acceptPacket(uint8_t reportId, store_address_t tcStoreId, - PusTcReader* packet) { - verificationReporter.sendSuccessReport(reportId, packet); +void CommandingServiceBase::acceptPacket(uint8_t reportId, store_address_t tcStoreId) { + verificationReporter->sendSuccessReport(VerifSuccessParams(reportId, tcReader)); tcStore->deleteData(tcStoreId); } @@ -371,7 +389,7 @@ void CommandingServiceBase::checkAndExecuteFifo(CommandMapIter& iter) { startExecution(address, iter); } else { // TODO: Warning? - rejectPacket(tcverif::START_FAILURE, address, &tcReader, result); + rejectPacket(tcverif::START_FAILURE, address, result); } } } @@ -390,9 +408,9 @@ void CommandingServiceBase::checkTimeout() { CommandMapIter iter; for (iter = commandMap.begin(); iter != commandMap.end(); ++iter) { if ((iter->second.uptimeOfStart + (timeoutSeconds * 1000)) < uptime) { - verificationReporter.sendFailureReport( - tcverif::COMPLETION_FAILURE, iter->second.tcInfo.ackFlags, iter->second.tcInfo.tcPacketId, - iter->second.tcInfo.tcSequenceControl, TIMEOUT); + prepareVerificationFailureWithFullInfo(tcverif::COMPLETION_FAILURE, iter->second.tcInfo, + TIMEOUT, false); + verificationReporter->sendFailureReport(failParams); checkAndExecuteFifo(iter); } } @@ -406,3 +424,25 @@ void CommandingServiceBase::setCustomTmStore(StorageManagerIF& store) { ReturnValue_t CommandingServiceBase::setUpTcReader(store_address_t storeId) { return tc::prepareTcReader(tcStore, storeId, tcReader); } + +void CommandingServiceBase::prepareVerificationFailureWithFullInfo(uint8_t reportId, + CommandInfo::TcInfo& tcInfo, + ReturnValue_t errorCode, + bool setCachedFailParams) { + failParams.reportId = reportId; + failParams.tcPacketId = tcInfo.tcPacketId; + failParams.tcPsc = tcInfo.tcSequenceControl; + failParams.ackFlags = tcInfo.ackFlags; + failParams.errorCode = errorCode; + if (setCachedFailParams) { + failParams.errorParam1 = failureParameter1; + failParams.errorParam2 = failureParameter2; + } +} +void CommandingServiceBase::prepareVerificationSuccessWithFullInfo( + uint8_t reportId, CommandingServiceBase::CommandInfo::TcInfo& tcInfo) { + failParams.reportId = reportId; + failParams.tcPacketId = tcInfo.tcPacketId; + failParams.tcPsc = tcInfo.tcSequenceControl; + failParams.ackFlags = tcInfo.ackFlags; +} diff --git a/src/fsfw/tmtcservices/CommandingServiceBase.h b/src/fsfw/tmtcservices/CommandingServiceBase.h index 63067b07..202dd862 100644 --- a/src/fsfw/tmtcservices/CommandingServiceBase.h +++ b/src/fsfw/tmtcservices/CommandingServiceBase.h @@ -68,7 +68,7 @@ class CommandingServiceBase : public SystemObject, */ CommandingServiceBase(object_id_t setObjectId, uint16_t apid, uint8_t service, uint8_t numberOfParallelCommands, uint16_t commandTimeoutSeconds, - size_t queueDepth = 20); + size_t queueDepth = 20, VerificationReporterIF* reporter = nullptr); ~CommandingServiceBase() override; void setCustomTmStore(StorageManagerIF& store); @@ -218,7 +218,7 @@ class CommandingServiceBase : public SystemObject, virtual void doPeriodicOperation(); struct CommandInfo : public SerializeIF { - struct tcInfo { + struct TcInfo { uint8_t ackFlags; uint16_t tcPacketId; uint16_t tcSequenceControl; @@ -263,7 +263,7 @@ class CommandingServiceBase : public SystemObject, MessageQueueIF* commandQueue = nullptr; MessageQueueIF* requestQueue = nullptr; - VerificationReporter verificationReporter; + VerificationReporterIF* verificationReporter; InternalErrorReporterIF* errReporter = nullptr; @@ -284,19 +284,19 @@ class CommandingServiceBase : public SystemObject, */ PeriodicTaskIF* executingTask = nullptr; - [[deprecated("Use function with same name provided by tmHelper")]] ReturnValue_t sendTmPacket( - uint8_t subservice, const uint8_t* sourceData, size_t sourceDataLen); - [[deprecated("Use function with same name provided by tmHelper")]] ReturnValue_t sendTmPacket( - uint8_t subservice, object_id_t objectId, const uint8_t* data, size_t dataLen); - [[deprecated("Use function with same name provided by tmHelper")]] ReturnValue_t sendTmPacket( - uint8_t subservice, SerializeIF& sourceData); + ReturnValue_t sendTmPacket(uint8_t subservice, const uint8_t* sourceData, size_t sourceDataLen); + ReturnValue_t sendTmPacket(uint8_t subservice, object_id_t objectId, const uint8_t* data, + size_t dataLen); + ReturnValue_t sendTmPacket(uint8_t subservice, SerializeIF& sourceData); void checkAndExecuteFifo(CommandMapIter& iter); + VerifFailureParams failParams; + VerifSuccessParams successParams; private: /** * This method handles internal execution of a command, - * once it has been started by @sa{startExecution()} in the request + * once it has been started by @startExecution in the request * queue handler. * It handles replies generated by the devices and relayed by the specific * service implementation. This means that it determines further course of @@ -316,26 +316,28 @@ class CommandingServiceBase : public SystemObject, * @brief Handler function for request queue * @details * Sequence of request queue handling: - * isValidSubservice -> getMessageQueueAndObject -> startExecution + * @isValidSubservice -> @getMessageQueueAndObject -> @startExecution * Generates a Start Success Reports TM[1,3] in subfunction - * @sa{startExecution()} or a Start Failure Report TM[1,4] by using the + * @startExecution or a Start Failure Report TM[1,4] by using the * TC Verification Service. */ void handleRequestQueue(); ReturnValue_t setUpTcReader(store_address_t storeId); - void rejectPacket(uint8_t reportId, store_address_t tcStoreId, PusTcReader* tcPacket, - ReturnValue_t errorCode); + void rejectPacket(uint8_t reportId, store_address_t tcStoreId, ReturnValue_t errorCode); - void acceptPacket(uint8_t reportId, store_address_t tcStoreId, PusTcReader* tcPacket); + void acceptPacket(uint8_t reportId, store_address_t tcStoreId); - void startExecution(store_address_t storeId, CommandMapIter iter); + void startExecution(store_address_t storeId, CommandMapIter& iter); void handleCommandMessage(CommandMessage* reply); void handleReplyHandlerResult(ReturnValue_t result, CommandMapIter iter, CommandMessage* nextCommand, CommandMessage* reply, bool& isStep); + void prepareVerificationFailureWithFullInfo(uint8_t reportId, CommandInfo::TcInfo& tcInfo, + ReturnValue_t errorCode, bool setCachedFailParams); + void prepareVerificationSuccessWithFullInfo(uint8_t reportId, CommandInfo::TcInfo& tcInfo); void checkTimeout(); }; diff --git a/src/fsfw/tmtcservices/PusServiceBase.cpp b/src/fsfw/tmtcservices/PusServiceBase.cpp index 26f08694..f727e415 100644 --- a/src/fsfw/tmtcservices/PusServiceBase.cpp +++ b/src/fsfw/tmtcservices/PusServiceBase.cpp @@ -12,8 +12,12 @@ 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, + VerificationReporterIF* verifyReporter) + : SystemObject(setObjectId), + apid(setApid), + serviceId(setServiceId), + verifyReporter(verifyReporter) { requestQueue = QueueFactory::instance()->createMessageQueue(PUS_SERVICE_MAX_RECEPTION); } @@ -65,16 +69,21 @@ void PusServiceBase::handleRequestQueue() { } result = tc::prepareTcReader(tcStore, message.getStorageId(), currentPacket); if (result != HasReturnvaluesIF::RETURN_OK) { - this->verifyReporter.sendFailureReport(tcverif::START_FAILURE, &this->currentPacket, result, - 0, errorParameter1, errorParameter2); + auto params = VerifFailureParams(tcverif::START_FAILURE, currentPacket, result); + params.errorParam1 = errorParameter1; + params.errorParam2 = errorParameter2; + verifyReporter->sendFailureReport(params); continue; } - result = this->handleRequest(currentPacket.getSubService()); + result = handleRequest(currentPacket.getSubService()); if (result == RETURN_OK) { - this->verifyReporter.sendSuccessReport(tcverif::COMPLETION_SUCCESS, &this->currentPacket); + verifyReporter->sendSuccessReport( + VerifSuccessParams(tcverif::COMPLETION_SUCCESS, currentPacket)); } else { - this->verifyReporter.sendFailureReport(tcverif::COMPLETION_FAILURE, &this->currentPacket, - result, 0, errorParameter1, errorParameter2); + auto params = VerifFailureParams(tcverif::COMPLETION_FAILURE, currentPacket, result); + params.errorParam1 = errorParameter1; + params.errorParam2 = errorParameter2; + verifyReporter->sendFailureReport(params); } tcStore->deleteData(message.getStorageId()); errorParameter1 = 0; @@ -109,6 +118,13 @@ ReturnValue_t PusServiceBase::initialize() { return ObjectManagerIF::CHILD_INIT_FAILED; } } + if (verifyReporter == nullptr) { + verifyReporter = + ObjectManager::instance()->get(objects::TC_VERIFICATOR); + if (verifyReporter == nullptr) { + return ObjectManagerIF::CHILD_INIT_FAILED; + } + } return HasReturnvaluesIF::RETURN_OK; } @@ -145,3 +161,7 @@ void PusServiceBase::initializeTmSendHelper(TmSendHelper& tmSendHelper) { void PusServiceBase::initializeTmStoreHelper(TmStoreHelper& tmStoreHelper) const { tmStoreHelper.setApid(apid); } + +void PusServiceBase::setVerificationReporter(VerificationReporterIF* reporter) { + verifyReporter = reporter; +} diff --git a/src/fsfw/tmtcservices/PusServiceBase.h b/src/fsfw/tmtcservices/PusServiceBase.h index 7df563d0..4aa6fade 100644 --- a/src/fsfw/tmtcservices/PusServiceBase.h +++ b/src/fsfw/tmtcservices/PusServiceBase.h @@ -53,18 +53,33 @@ 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, + VerificationReporterIF* reporter = nullptr); /** * The destructor is empty. */ ~PusServiceBase() override; void setCustomTcStore(StorageManagerIF* tcStore); + void setVerificationReporter(VerificationReporterIF* reporter); void setCustomErrorReporter(InternalErrorReporterIF* errReporter); + /** + * Helper methods if the implementing class wants to send telemetry + * @param tmSendHelper + */ void initializeTmSendHelper(TmSendHelper& tmSendHelper); + /** + * Helper methods if the implementing class wants to store telemetry + * @param tmSendHelper + */ void initializeTmStoreHelper(TmStoreHelper& tmStoreHelper) const; + /** + * Helper methods if the implementing class wants to both send and store telemetry + * @param tmSendHelper + */ void initializeTmHelpers(TmSendHelper& tmSendHelper, TmStoreHelper& tmStoreHelper); + /** * @brief The handleRequest method shall handle any kind of Telecommand * Request immediately. @@ -146,7 +161,7 @@ class PusServiceBase : public ExecutableObjectIF, * An instance of the VerificationReporter class, that simplifies * sending any kind of verification message to the TC Verification Service. */ - VerificationReporter verifyReporter; + VerificationReporterIF* verifyReporter; /** * The current Telecommand to be processed. @@ -159,6 +174,7 @@ class PusServiceBase : public ExecutableObjectIF, static object_id_t packetSource; static object_id_t packetDestination; + VerifSuccessParams successParams; private: /** diff --git a/src/fsfw/tmtcservices/TmStoreAndSendHelper.cpp b/src/fsfw/tmtcservices/TmStoreAndSendHelper.cpp index 61735ab5..cab6db44 100644 --- a/src/fsfw/tmtcservices/TmStoreAndSendHelper.cpp +++ b/src/fsfw/tmtcservices/TmStoreAndSendHelper.cpp @@ -24,29 +24,36 @@ ReturnValue_t TmStoreAndSendWrapper::storeAndSendTmPacket() { return result; } -ReturnValue_t TmStoreAndSendWrapper::sendTmPacket(uint8_t subservice, const uint8_t* sourceData, - size_t sourceDataLen) { - storeHelper.preparePacket(defaultService, subservice, sendCounter); - storeHelper.setSourceDataRaw(sourceData, sourceDataLen); - return storeAndSendTmPacket(); +ReturnValue_t TmStoreAndSendWrapper::prepareTmPacket(uint8_t subservice, const uint8_t* sourceData, + size_t sourceDataLen) { + ReturnValue_t result = storeHelper.preparePacket(defaultService, subservice, sendCounter); + if (result != HasReturnvaluesIF::RETURN_OK) { + return result; + } + return storeHelper.setSourceDataRaw(sourceData, sourceDataLen); } -ReturnValue_t TmStoreAndSendWrapper::sendTmPacket(uint8_t subservice, object_id_t objectId, - const uint8_t* data, size_t dataLen) { - telemetry::DataWithObjectIdPrefix dataWithObjId(objectId, data, dataLen); - storeHelper.preparePacket(defaultService, subservice, sendCounter); - storeHelper.setSourceDataSerializable(dataWithObjId); - return storeAndSendTmPacket(); +ReturnValue_t TmStoreAndSendWrapper::prepareTmPacket( + uint8_t subservice, telemetry::DataWithObjectIdPrefix& dataWithObjectId) { + ReturnValue_t result = storeHelper.preparePacket(defaultService, subservice, sendCounter); + if (result != HasReturnvaluesIF::RETURN_OK) { + return result; + } + return storeHelper.setSourceDataSerializable(dataWithObjectId); } -ReturnValue_t TmStoreAndSendWrapper::sendTmPacket(uint8_t subservice, SerializeIF& sourceData) { - storeHelper.preparePacket(defaultService, subservice, sendCounter); - storeHelper.setSourceDataSerializable(sourceData); - return storeAndSendTmPacket(); +ReturnValue_t TmStoreAndSendWrapper::prepareTmPacket(uint8_t subservice, SerializeIF& sourceData) { + ReturnValue_t result = storeHelper.preparePacket(defaultService, subservice, sendCounter); + if (result != HasReturnvaluesIF::RETURN_OK) { + return result; + } + return storeHelper.setSourceDataSerializable(sourceData); } -ReturnValue_t TmStoreAndSendWrapper::sendTmPacket(uint8_t subservice) { - storeHelper.preparePacket(defaultService, subservice, sendCounter); - storeHelper.setSourceDataRaw(nullptr, 0); - return storeAndSendTmPacket(); +ReturnValue_t TmStoreAndSendWrapper::prepareTmPacket(uint8_t subservice) { + ReturnValue_t result = storeHelper.preparePacket(defaultService, subservice, sendCounter); + if (result != HasReturnvaluesIF::RETURN_OK) { + return result; + } + return storeHelper.setSourceDataRaw(nullptr, 0); } diff --git a/src/fsfw/tmtcservices/TmStoreAndSendHelper.h b/src/fsfw/tmtcservices/TmStoreAndSendHelper.h index 1a33b7d7..eef3a373 100644 --- a/src/fsfw/tmtcservices/TmStoreAndSendHelper.h +++ b/src/fsfw/tmtcservices/TmStoreAndSendHelper.h @@ -3,6 +3,7 @@ #include "TmSendHelper.h" #include "TmStoreHelper.h" +#include "tmHelpers.h" /** * Wrapper class intended to help with PUS TM handling. This wrapper class also caches the current @@ -12,37 +13,41 @@ class TmStoreAndSendWrapper { public: TmStoreAndSendWrapper(uint8_t defaultService, TmStoreHelper& storeHelper, TmSendHelper& sendHelper); - ReturnValue_t storeAndSendTmPacket(); - ReturnValue_t sendTmPacket(uint8_t subservice); /** - * @brief Send TM data from pointer to data. - * If a header is supplied it is added before data + * Prepares a TM packet with the given parameters. It will also set the default service. + * @param subservice + * @return + */ + ReturnValue_t prepareTmPacket(uint8_t subservice); + /** + * Prepares a TM packet with the given parameters. It will also set the default service. * @param subservice Number of subservice * @param sourceData Custom source data * @param sourceDataLen Lenght of data in the Packet */ - ReturnValue_t sendTmPacket(uint8_t subservice, const uint8_t* sourceData, size_t sourceDataLen); + ReturnValue_t prepareTmPacket(uint8_t subservice, const uint8_t* sourceData, + size_t sourceDataLen); /** - * @brief To send TM packets of objects that still need to be serialized - * and consist of an object ID with appended data. + * Prepares a TM packet with the given parameters. It will also set the default service. * @param subservice Number of subservice * @param objectId ObjectId is placed before data * @param data Data to append to the packet * @param dataLen Length of Data */ - ReturnValue_t sendTmPacket(uint8_t subservice, object_id_t objectId, const uint8_t* data, - size_t dataLen); + ReturnValue_t prepareTmPacket(uint8_t subservice, + telemetry::DataWithObjectIdPrefix& dataWithObjectId); /** - * @brief To send packets which are contained inside a class implementing - * SerializeIF. + * Prepares a TM packet with the given parameters. It will also set the default service. * @param subservice Number of subservice * @param content This is a pointer to the serialized packet * @param header Serialize IF header which will be placed before content */ - ReturnValue_t sendTmPacket(uint8_t subservice, SerializeIF& sourceData); + ReturnValue_t prepareTmPacket(uint8_t subservice, SerializeIF& sourceData); + + ReturnValue_t storeAndSendTmPacket(); bool incrementSendCounter = true; TmStoreHelper& storeHelper; diff --git a/src/fsfw/tmtcservices/VerificationReporter.cpp b/src/fsfw/tmtcservices/VerificationReporter.cpp index a9b6dd47..b08756d3 100644 --- a/src/fsfw/tmtcservices/VerificationReporter.cpp +++ b/src/fsfw/tmtcservices/VerificationReporter.cpp @@ -1,29 +1,25 @@ #include "fsfw/tmtcservices/VerificationReporter.h" -#include "fsfw/ipc/MessageQueueIF.h" -#include "fsfw/objectmanager/ObjectManager.h" -#include "fsfw/objectmanager/frameworkObjects.h" #include "fsfw/serviceinterface/ServiceInterface.h" -#include "fsfw/tmtcservices/AcceptsVerifyMessageIF.h" #include "fsfw/tmtcservices/PusVerificationReport.h" -object_id_t VerificationReporter::messageReceiver = objects::PUS_SERVICE_1_VERIFICATION; - -VerificationReporter::VerificationReporter() : acknowledgeQueue(MessageQueueIF::NO_QUEUE) {} +VerificationReporter::VerificationReporter(AcceptsVerifyMessageIF* receiver, object_id_t objectId) + : SystemObject(objectId) { + if (receiver != nullptr) { + acknowledgeQueue = receiver->getVerificationQueue(); + } +} VerificationReporter::~VerificationReporter() = default; -void VerificationReporter::sendSuccessReport(uint8_t set_report_id, PusTcReader* correspondingTc, - uint8_t set_step) { - if (acknowledgeQueue == MessageQueueIF::NO_QUEUE) { - this->initialize(); - } - if (correspondingTc == nullptr) { - return; - } - PusVerificationMessage message(set_report_id, correspondingTc->getAcknowledgeFlags(), - correspondingTc->getPacketIdRaw(), - correspondingTc->getPacketSeqCtrlRaw(), 0, set_step); +void VerificationReporter::setReceiver(AcceptsVerifyMessageIF& receiver) { + acknowledgeQueue = receiver.getVerificationQueue(); +} + +ReturnValue_t VerificationReporter::sendFailureReport(VerifFailureParams params) { + PusVerificationMessage message(params.reportId, params.ackFlags, params.tcPacketId, params.tcPsc, + params.errorCode, params.step, params.errorParam1, + params.errorParam2); ReturnValue_t status = MessageQueueSenderIF::sendMessage(acknowledgeQueue, &message); if (status != HasReturnvaluesIF::RETURN_OK) { #if FSFW_CPP_OSTREAM_ENABLED == 1 @@ -31,16 +27,12 @@ void VerificationReporter::sendSuccessReport(uint8_t set_report_id, PusTcReader* << "to queue. Code: " << std::hex << status << std::dec << std::endl; #endif } + return status; } -void VerificationReporter::sendSuccessReport(uint8_t set_report_id, uint8_t ackFlags, - uint16_t tcPacketId, uint16_t tcSequenceControl, - uint8_t set_step) { - if (acknowledgeQueue == MessageQueueIF::NO_QUEUE) { - this->initialize(); - } - PusVerificationMessage message(set_report_id, ackFlags, tcPacketId, tcSequenceControl, 0, - set_step); +ReturnValue_t VerificationReporter::sendSuccessReport(VerifSuccessParams params) { + PusVerificationMessage message(params.reportId, params.ackFlags, params.tcPacketId, params.tcPsc, + retval::OK, params.step); ReturnValue_t status = MessageQueueSenderIF::sendMessage(acknowledgeQueue, &message); if (status != HasReturnvaluesIF::RETURN_OK) { #if FSFW_CPP_OSTREAM_ENABLED == 1 @@ -48,64 +40,5 @@ void VerificationReporter::sendSuccessReport(uint8_t set_report_id, uint8_t ackF << "to queue. Code: " << std::hex << status << std::dec << std::endl; #endif } -} - -void VerificationReporter::sendFailureReport(uint8_t report_id, PusTcReader* correspondingTc, - ReturnValue_t errorCode, uint8_t step, - uint32_t parameter1, uint32_t parameter2) { - if (acknowledgeQueue == MessageQueueIF::NO_QUEUE) { - this->initialize(); - } - if (correspondingTc == nullptr) { - return; - } - PusVerificationMessage message( - report_id, correspondingTc->getAcknowledgeFlags(), correspondingTc->getPacketIdRaw(), - correspondingTc->getPacketSeqCtrlRaw(), errorCode, step, parameter1, parameter2); - ReturnValue_t status = MessageQueueSenderIF::sendMessage(acknowledgeQueue, &message); - if (status != HasReturnvaluesIF::RETURN_OK) { -#if FSFW_CPP_OSTREAM_ENABLED == 1 - sif::error << "VerificationReporter::sendFailureReport: Error writing " - << "to queue. Code: " << std::hex << "0x" << status << std::dec << std::endl; -#endif - } -} - -void VerificationReporter::sendFailureReport(uint8_t report_id, uint8_t ackFlags, - uint16_t tcPacketId, uint16_t tcSequenceControl, - ReturnValue_t error_code, uint8_t step, - uint32_t parameter1, uint32_t parameter2) { - if (acknowledgeQueue == MessageQueueIF::NO_QUEUE) { - this->initialize(); - } - PusVerificationMessage message(report_id, ackFlags, tcPacketId, tcSequenceControl, error_code, - step, parameter1, parameter2); - ReturnValue_t status = MessageQueueSenderIF::sendMessage(acknowledgeQueue, &message); - if (status != HasReturnvaluesIF::RETURN_OK) { -#if FSFW_CPP_OSTREAM_ENABLED == 1 - sif::error << "VerificationReporter::sendFailureReport: Error writing " - << "to queue. Code: " << std::hex << "0x" << status << std::dec << std::endl; -#endif - } -} - -void VerificationReporter::initialize() { - if (messageReceiver == objects::NO_OBJECT) { -#if FSFW_CPP_OSTREAM_ENABLED == 1 - sif::warning << "VerificationReporter::initialize: Verification message" - " receiver object ID not set yet in Factory!" - << std::endl; -#endif - return; - } - auto* temp = ObjectManager::instance()->get(messageReceiver); - if (temp == nullptr) { -#if FSFW_CPP_OSTREAM_ENABLED == 1 - sif::error << "VerificationReporter::initialize: Message " - << "receiver invalid. Make sure it is set up properly and " - << "implementsAcceptsVerifyMessageIF" << std::endl; -#endif - return; - } - this->acknowledgeQueue = temp->getVerificationQueue(); + return status; } diff --git a/src/fsfw/tmtcservices/VerificationReporter.h b/src/fsfw/tmtcservices/VerificationReporter.h index 1d64fd48..8ea45f79 100644 --- a/src/fsfw/tmtcservices/VerificationReporter.h +++ b/src/fsfw/tmtcservices/VerificationReporter.h @@ -2,12 +2,11 @@ #define FSFW_TMTCSERVICES_VERIFICATIONREPORTER_H_ #include "PusVerificationReport.h" +#include "VerificationReporterIF.h" #include "fsfw/objectmanager/ObjectManagerIF.h" +#include "fsfw/objectmanager/SystemObject.h" #include "fsfw/tmtcpacket/pus/tc/PusTcCreator.h" - -namespace Factory { -void setStaticFrameworkObjectIds(); -} +#include "fsfw/tmtcservices/AcceptsVerifyMessageIF.h" /** * @brief This helper object is used to forward verification messages @@ -20,30 +19,21 @@ void setStaticFrameworkObjectIds(); * to the PUS standard. * */ -class VerificationReporter { - friend void(Factory::setStaticFrameworkObjectIds)(); - +class VerificationReporter : public SystemObject, public VerificationReporterIF { public: - VerificationReporter(); - virtual ~VerificationReporter(); + explicit VerificationReporter(AcceptsVerifyMessageIF* receiver, + object_id_t objectId = objects::TC_VERIFICATOR); + ~VerificationReporter() override; + + void setReceiver(AcceptsVerifyMessageIF& receiver); // TODO: The API is a little bit bloated. It might be better to group all the parameters // into a dedicated struct - void sendSuccessReport(uint8_t set_report_id, PusTcReader* correspondingTc, 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); + ReturnValue_t sendSuccessReport(VerifSuccessParams params) override; - void sendFailureReport(uint8_t report_id, PusTcReader* correspondingTc, - ReturnValue_t errorCode = 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, - uint16_t tcSequenceControl, ReturnValue_t errorCode = 0, uint8_t step = 0, - uint32_t parameter1 = 0, uint32_t parameter2 = 0); - - void initialize(); + ReturnValue_t sendFailureReport(VerifFailureParams params) override; private: - static object_id_t messageReceiver; MessageQueueId_t acknowledgeQueue; }; diff --git a/src/fsfw/tmtcservices/VerificationReporterIF.h b/src/fsfw/tmtcservices/VerificationReporterIF.h new file mode 100644 index 00000000..14b6012f --- /dev/null +++ b/src/fsfw/tmtcservices/VerificationReporterIF.h @@ -0,0 +1,57 @@ +#ifndef FSFW_TMTCSERVICES_VERIFICATIONREPORTERIF_H +#define FSFW_TMTCSERVICES_VERIFICATIONREPORTERIF_H + +#include "fsfw/retval.h" +#include "fsfw/tmtcpacket/pus/tc.h" + +struct VerifParamsBase { + VerifParamsBase() : reportId(0), tcPacketId(0), tcPsc(0) {} + VerifParamsBase(uint8_t reportId, uint16_t tcPacketId, uint16_t tcPsc) + : reportId(reportId), tcPacketId(tcPacketId), tcPsc(tcPsc) {} + uint8_t reportId; + uint16_t tcPacketId; + uint16_t tcPsc; + uint8_t ackFlags = ecss::ACK_ALL; + uint8_t step = 0; +}; + +struct VerifSuccessParams : public VerifParamsBase { + VerifSuccessParams() = default; + VerifSuccessParams(uint8_t reportId, uint16_t tcPacketId, uint16_t tcPsc) + : VerifParamsBase(reportId, tcPacketId, tcPsc) {} + VerifSuccessParams(uint8_t reportId, PusTcIF& tc) + : VerifParamsBase(reportId, tc.getPacketIdRaw(), tc.getPacketSeqCtrlRaw()) {} +}; + +struct VerifFailureParams : public VerifParamsBase { + VerifFailureParams() = default; + VerifFailureParams(uint8_t reportId, uint16_t tcPacketId, uint16_t tcPsc, ReturnValue_t errorCode, + uint32_t errorParam1, uint32_t errorParams2) + : VerifParamsBase(reportId, tcPacketId, tcPsc), errorCode(errorCode) { + errorParam1 = errorParam1; + errorParams2 = errorParams2; + } + VerifFailureParams(uint8_t reportId, uint16_t tcPacketId, uint16_t tcPsc, ReturnValue_t errorCode) + : VerifParamsBase(reportId, tcPacketId, tcPsc), errorCode(errorCode) {} + VerifFailureParams(uint8_t reportId, uint16_t tcPacketId, uint16_t tcPsc) + : VerifParamsBase(reportId, tcPacketId, tcPsc) {} + VerifFailureParams(uint8_t reportId, PusTcIF& tc, ReturnValue_t errorCode) + : VerifParamsBase(reportId, tc.getPacketIdRaw(), tc.getPacketSeqCtrlRaw()), + errorCode(errorCode) {} + VerifFailureParams(uint8_t reportId, PusTcIF& tc) + : VerifParamsBase(reportId, tc.getPacketIdRaw(), tc.getPacketSeqCtrlRaw()) {} + + ReturnValue_t errorCode = retval::OK; + uint8_t step = 0; + uint32_t errorParam1 = 0; + uint32_t errorParam2 = 0; +}; +class VerificationReporterIF { + public: + virtual ~VerificationReporterIF() = default; + + virtual ReturnValue_t sendSuccessReport(VerifSuccessParams params) = 0; + virtual ReturnValue_t sendFailureReport(VerifFailureParams params) = 0; +}; + +#endif // FSFW_TMTCSERVICES_VERIFICATIONREPORTERIF_H diff --git a/src/fsfw/tmtcservices/tmHelpers.h b/src/fsfw/tmtcservices/tmHelpers.h index 6a754bdf..ad333eb2 100644 --- a/src/fsfw/tmtcservices/tmHelpers.h +++ b/src/fsfw/tmtcservices/tmHelpers.h @@ -10,38 +10,60 @@ namespace telemetry { class DataWithObjectIdPrefix : public SerializeIF { public: DataWithObjectIdPrefix(object_id_t objectId, const uint8_t* srcData, size_t srcDataLen) - : objectId(objectId), srcData(srcData), srcDataLen(srcDataLen) {} + : objectId(objectId) { + dataWrapper.type = ecss::DataTypes::RAW; + dataWrapper.dataUnion.raw.data = srcData; + dataWrapper.dataUnion.raw.len = srcDataLen; + } + + DataWithObjectIdPrefix(object_id_t objectId, SerializeIF& serializable) : objectId(objectId) { + dataWrapper.type = ecss::DataTypes::SERIALIZABLE; + dataWrapper.dataUnion.serializable = &serializable; + } + ReturnValue_t serialize(uint8_t** buffer, size_t* size, size_t maxSize, Endianness streamEndianness) const override { if (*size + getSerializedSize() > maxSize) { return SerializeIF::BUFFER_TOO_SHORT; } + if (dataWrapper.type != ecss::DataTypes::RAW) { + if ((dataWrapper.dataUnion.raw.data == nullptr) and (dataWrapper.dataUnion.raw.len > 0)) { + return retval::FAILED; + } + } else if (dataWrapper.type == ecss::DataTypes::SERIALIZABLE) { + if (dataWrapper.dataUnion.serializable == nullptr) { + return retval::FAILED; + } + } ReturnValue_t result = SerializeAdapter::serialize(&objectId, buffer, size, maxSize, streamEndianness); - if (result != HasReturnvaluesIF::RETURN_OK) { - return result; - } - std::memcpy(*buffer, srcData, srcDataLen); - *buffer += srcDataLen; - *size += srcDataLen; - return HasReturnvaluesIF::RETURN_OK; - } - - [[nodiscard]] size_t getSerializedSize() const override { return sizeof(objectId) + srcDataLen; } - - ReturnValue_t deSerialize(const uint8_t** buffer, size_t* size, - Endianness streamEndianness) override { - ReturnValue_t result = SerializeAdapter::deSerialize(&objectId, buffer, size, streamEndianness); if (result != retval::OK) { return result; } + if (dataWrapper.type != ecss::DataTypes::RAW) { + std::memcpy(*buffer, dataWrapper.dataUnion.raw.data, dataWrapper.dataUnion.raw.len); + *buffer += dataWrapper.dataUnion.raw.len; + *size += dataWrapper.dataUnion.raw.len; + } else { + return dataWrapper.dataUnion.serializable->serialize(buffer, size, maxSize, streamEndianness); + } + return retval::OK; + } + + [[nodiscard]] size_t getSerializedSize() const override { + return sizeof(objectId) + dataWrapper.getLength(); + } + + ReturnValue_t deSerialize(const uint8_t** buffer, size_t* size, + Endianness streamEndianness) override { + // As long as there is no way to know how long the expected data will be, this function + // does not make sense return retval::FAILED; } private: object_id_t objectId; - const uint8_t* srcData; - size_t srcDataLen; + ecss::DataWrapper dataWrapper{}; }; } // namespace telemetry diff --git a/unittests/CatchFactory.cpp b/unittests/CatchFactory.cpp index d5d12935..5ae5a9fb 100644 --- a/unittests/CatchFactory.cpp +++ b/unittests/CatchFactory.cpp @@ -60,8 +60,6 @@ void Factory::setStaticFrameworkObjectIds() { CommandingServiceBase::defaultPacketSource = objects::NO_OBJECT; CommandingServiceBase::defaultPacketDestination = objects::NO_OBJECT; - VerificationReporter::messageReceiver = objects::PUS_SERVICE_1_VERIFICATION; - DeviceHandlerBase::powerSwitcherId = objects::NO_OBJECT; DeviceHandlerBase::rawDataReceiverId = objects::NO_OBJECT; diff --git a/unittests/mocks/PusServiceBaseMock.cpp b/unittests/mocks/PusServiceBaseMock.cpp new file mode 100644 index 00000000..0303364f --- /dev/null +++ b/unittests/mocks/PusServiceBaseMock.cpp @@ -0,0 +1,30 @@ +#include "PusServiceBaseMock.h" + +ReturnValue_t PsbMock::handleRequest(uint8_t subservice) { + handleRequestCallCnt++; + subserviceQueue.push(subservice); + if (handleReqFailPair.first) { + handleReqFailPair.first = false; + return handleReqFailPair.second; + } + return HasReturnvaluesIF::RETURN_OK; +} + +ReturnValue_t PsbMock::performService() { + performServiceCallCnt++; + if (performServiceFailPair.first) { + performServiceFailPair.first = false; + return performServiceFailPair.second; + } + return HasReturnvaluesIF::RETURN_OK; +} + +void PsbMock::reset() { + handleRequestCallCnt = 0; + performServiceCallCnt = 0; + std::queue().swap(subserviceQueue); +} +void PsbMock::makeNextHandleReqCallFail(ReturnValue_t retval) { + handleReqFailPair.first = true; + handleReqFailPair.second = retval; +} diff --git a/unittests/mocks/PusServiceBaseMock.h b/unittests/mocks/PusServiceBaseMock.h new file mode 100644 index 00000000..f441c2a8 --- /dev/null +++ b/unittests/mocks/PusServiceBaseMock.h @@ -0,0 +1,23 @@ +#ifndef FSFW_TESTS_PUSSERVICEBASEMOCK_H +#define FSFW_TESTS_PUSSERVICEBASEMOCK_H + +#include + +#include "fsfw/tmtcservices/PusServiceBase.h" + +class PsbMock : public PusServiceBase { + public: + unsigned int handleRequestCallCnt = 0; + std::queue subserviceQueue; + unsigned int performServiceCallCnt = 0; + + std::pair handleReqFailPair; + std::pair performServiceFailPair; + ReturnValue_t handleRequest(uint8_t subservice) override; + ReturnValue_t performService() override; + + void makeNextHandleReqCallFail(ReturnValue_t retval); + void reset(); +}; + +#endif // FSFW_TESTS_PUSSERVICEBASEMOCK_H diff --git a/unittests/tmtcservices/CMakeLists.txt b/unittests/tmtcservices/CMakeLists.txt index 791066ad..4cb2dc05 100644 --- a/unittests/tmtcservices/CMakeLists.txt +++ b/unittests/tmtcservices/CMakeLists.txt @@ -1,4 +1,5 @@ target_sources(${FSFW_TEST_TGT} PRIVATE testStoreHelper.cpp testSendHelper.cpp + testStoreAndSendHelper.cpp ) diff --git a/unittests/tmtcservices/testPsb.cpp b/unittests/tmtcservices/testPsb.cpp new file mode 100644 index 00000000..43e03b48 --- /dev/null +++ b/unittests/tmtcservices/testPsb.cpp @@ -0,0 +1,5 @@ +#include + +#include "fsfw/tmtcservices/PusServiceBase.h" + +TEST_CASE("Pus Service Base", "[pus-service-base]") { auto psb = PusServiceBase() } \ No newline at end of file diff --git a/unittests/tmtcservices/testStoreAndSendHelper.cpp b/unittests/tmtcservices/testStoreAndSendHelper.cpp index 309556b6..2a522600 100644 --- a/unittests/tmtcservices/testStoreAndSendHelper.cpp +++ b/unittests/tmtcservices/testStoreAndSendHelper.cpp @@ -2,8 +2,12 @@ #include "fsfw/storagemanager/LocalPool.h" #include "fsfw/tmtcservices/TmSendHelper.h" +#include "fsfw/tmtcservices/TmStoreAndSendHelper.h" #include "fsfw/tmtcservices/TmStoreHelper.h" #include "mocks/CdsShortTimestamperMock.h" +#include "mocks/InternalErrorReporterMock.h" +#include "mocks/MessageQueueMock.h" +#include "mocks/SimpleSerializable.h" TEST_CASE("TM Store And Send Helper", "[tm-store-send-helper]") { auto timeStamper = CdsShortTimestamperMock(); @@ -16,4 +20,68 @@ TEST_CASE("TM Store And Send Helper", "[tm-store-send-helper]") { auto msgQueue = MessageQueueMock(); msgQueue.setDefaultDestination(destId); TmSendHelper sendHelper(msgQueue, errReporter, destId); + TmStoreAndSendWrapper tmHelper(17, storeHelper, sendHelper); + + SECTION("State") { + CHECK(tmHelper.sendCounter == 0); + CHECK(tmHelper.defaultService == 17); + CHECK(tmHelper.delOnFailure); + CHECK(tmHelper.incrementSendCounter); + CHECK(&tmHelper.sendHelper == &sendHelper); + CHECK(&tmHelper.storeHelper == &storeHelper); + } + + SECTION("Base Test") { + tmHelper.prepareTmPacket(2); + auto& creator = storeHelper.getCreatorRef(); + REQUIRE(creator.getSubService() == 2); + REQUIRE(creator.getService() == 17); + auto& params = creator.getParams(); + REQUIRE(params.dataWrapper.type == ecss::DataTypes::RAW); + REQUIRE(params.dataWrapper.dataUnion.raw.data == nullptr); + REQUIRE(params.dataWrapper.dataUnion.raw.len == 0); + REQUIRE(tmHelper.sendCounter == 0); + REQUIRE(tmHelper.storeAndSendTmPacket() == retval::OK); + REQUIRE(tmHelper.sendCounter == 1); + auto storeId = storeHelper.getCurrentAddr(); + REQUIRE(msgQueue.wasMessageSent()); + REQUIRE(msgQueue.numberOfSentMessagesToDefault() == 1); + TmTcMessage msg; + REQUIRE(msgQueue.getNextSentMessage(msg) == retval::OK); + REQUIRE(msg.getStorageId() == storeId); + REQUIRE(pool.hasDataAtId(msg.getStorageId())); + storeHelper.deletePacket(); + } + + SECTION("Raw Data Helper") { + std::array data = {1, 2, 3}; + REQUIRE(tmHelper.prepareTmPacket(2, data.data(), data.size()) == retval::OK); + auto& creator = storeHelper.getCreatorRef(); + auto& params = creator.getParams(); + REQUIRE(params.dataWrapper.type == ecss::DataTypes::RAW); + REQUIRE(params.dataWrapper.dataUnion.raw.data == data.data()); + REQUIRE(params.dataWrapper.dataUnion.raw.len == data.size()); + } + + SECTION("Serializable Helper") { + auto simpleSer = SimpleSerializable(); + REQUIRE(tmHelper.prepareTmPacket(2, simpleSer) == retval::OK); + auto& creator = storeHelper.getCreatorRef(); + auto& params = creator.getParams(); + REQUIRE(params.dataWrapper.type == ecss::DataTypes::SERIALIZABLE); + REQUIRE(params.dataWrapper.dataUnion.serializable == &simpleSer); + } + + SECTION("Object ID prefix Helper") { + uint32_t objectId = 0x01020304; + std::array data = {1, 2, 3}; + telemetry::DataWithObjectIdPrefix dataWithObjId(objectId, data.data(), data.size()); + REQUIRE(tmHelper.prepareTmPacket(2, dataWithObjId) == retval::OK); + auto& creator = storeHelper.getCreatorRef(); + auto& params = creator.getParams(); + REQUIRE(params.dataWrapper.type == ecss::DataTypes::SERIALIZABLE); + REQUIRE(params.dataWrapper.dataUnion.serializable == &dataWithObjId); + } + + // TODO: Error handling } -- 2.43.0 From 146a0e3828c832b329ff29106bd35a2289df72bf Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Tue, 26 Jul 2022 14:10:24 +0200 Subject: [PATCH 067/108] created PSB mock --- unittests/mocks/CMakeLists.txt | 2 ++ unittests/mocks/PusServiceBaseMock.cpp | 3 +++ unittests/mocks/PusServiceBaseMock.h | 1 + .../mocks/PusVerificationReporterMock.cpp | 23 +++++++++++++++++++ unittests/mocks/PusVerificationReporterMock.h | 23 +++++++++++++++++++ unittests/tmtcservices/CMakeLists.txt | 1 + unittests/tmtcservices/testPsb.cpp | 8 +++++-- 7 files changed, 59 insertions(+), 2 deletions(-) create mode 100644 unittests/mocks/PusVerificationReporterMock.cpp create mode 100644 unittests/mocks/PusVerificationReporterMock.h diff --git a/unittests/mocks/CMakeLists.txt b/unittests/mocks/CMakeLists.txt index 7bc8fd30..00732c80 100644 --- a/unittests/mocks/CMakeLists.txt +++ b/unittests/mocks/CMakeLists.txt @@ -7,4 +7,6 @@ target_sources(${FSFW_TEST_TGT} PRIVATE MessageQueueMock.cpp InternalErrorReporterMock.cpp LocalPoolOwnerBase.cpp + PusVerificationReporterMock.cpp + PusServiceBaseMock.cpp ) diff --git a/unittests/mocks/PusServiceBaseMock.cpp b/unittests/mocks/PusServiceBaseMock.cpp index 0303364f..4eb51fa4 100644 --- a/unittests/mocks/PusServiceBaseMock.cpp +++ b/unittests/mocks/PusServiceBaseMock.cpp @@ -1,5 +1,8 @@ #include "PusServiceBaseMock.h" +PsbMock::PsbMock(uint8_t service, uint16_t apid, VerificationReporterIF& verifyReporter) + : PusServiceBase(0, service, apid, &verifyReporter) {} + ReturnValue_t PsbMock::handleRequest(uint8_t subservice) { handleRequestCallCnt++; subserviceQueue.push(subservice); diff --git a/unittests/mocks/PusServiceBaseMock.h b/unittests/mocks/PusServiceBaseMock.h index f441c2a8..9d1bac5d 100644 --- a/unittests/mocks/PusServiceBaseMock.h +++ b/unittests/mocks/PusServiceBaseMock.h @@ -7,6 +7,7 @@ class PsbMock : public PusServiceBase { public: + PsbMock(uint8_t service, uint16_t apid, VerificationReporterIF& verifyReporter); unsigned int handleRequestCallCnt = 0; std::queue subserviceQueue; unsigned int performServiceCallCnt = 0; diff --git a/unittests/mocks/PusVerificationReporterMock.cpp b/unittests/mocks/PusVerificationReporterMock.cpp new file mode 100644 index 00000000..fdc61aca --- /dev/null +++ b/unittests/mocks/PusVerificationReporterMock.cpp @@ -0,0 +1,23 @@ +#include "PusVerificationReporterMock.h" + +size_t PusVerificationReporterMock::successCallCount() const { return successParams.size(); } +size_t PusVerificationReporterMock::failCallCount() const { return failParams.size(); } + +VerifSuccessParams& PusVerificationReporterMock::getNextSuccessCallParams() { + return successParams.front(); +} + +void PusVerificationReporterMock::popNextFailParams() { + if (not failParams.empty()) { + failParams.pop(); + } +} + +VerifFailureParams& PusVerificationReporterMock::getNextFailCallParams() { + return failParams.front(); +} +void PusVerificationReporterMock::popNextSuccessParams() { + if (not successParams.empty()) { + successParams.pop(); + } +} diff --git a/unittests/mocks/PusVerificationReporterMock.h b/unittests/mocks/PusVerificationReporterMock.h new file mode 100644 index 00000000..87595637 --- /dev/null +++ b/unittests/mocks/PusVerificationReporterMock.h @@ -0,0 +1,23 @@ +#ifndef FSFW_TESTS_PUSVERIFICATIONREPORTERMOCK_H +#define FSFW_TESTS_PUSVERIFICATIONREPORTERMOCK_H + +#include + +#include "fsfw/tmtcservices/VerificationReporterIF.h" + +class PusVerificationReporterMock : public VerificationReporterIF { + public: + std::queue successParams; + std::queue failParams; + + [[nodiscard]] size_t successCallCount() const; + VerifSuccessParams& getNextSuccessCallParams(); + void popNextSuccessParams(); + [[nodiscard]] size_t failCallCount() const; + VerifFailureParams& getNextFailCallParams(); + void popNextFailParams(); + + ReturnValue_t sendSuccessReport(VerifSuccessParams params) override { return 0; } + ReturnValue_t sendFailureReport(VerifFailureParams params) override { return 0; } +}; +#endif // FSFW_TESTS_PUSVERIFICATIONREPORTERMOCK_H diff --git a/unittests/tmtcservices/CMakeLists.txt b/unittests/tmtcservices/CMakeLists.txt index 4cb2dc05..9e60ced1 100644 --- a/unittests/tmtcservices/CMakeLists.txt +++ b/unittests/tmtcservices/CMakeLists.txt @@ -2,4 +2,5 @@ target_sources(${FSFW_TEST_TGT} PRIVATE testStoreHelper.cpp testSendHelper.cpp testStoreAndSendHelper.cpp + testPsb.cpp ) diff --git a/unittests/tmtcservices/testPsb.cpp b/unittests/tmtcservices/testPsb.cpp index 43e03b48..ea4aee61 100644 --- a/unittests/tmtcservices/testPsb.cpp +++ b/unittests/tmtcservices/testPsb.cpp @@ -1,5 +1,9 @@ #include -#include "fsfw/tmtcservices/PusServiceBase.h" +#include "mocks/PusServiceBaseMock.h" +#include "mocks/PusVerificationReporterMock.h" -TEST_CASE("Pus Service Base", "[pus-service-base]") { auto psb = PusServiceBase() } \ No newline at end of file +TEST_CASE("Pus Service Base", "[pus-service-base]") { + auto verificationReporter = PusVerificationReporterMock(); + auto psb = PsbMock(17, 0x02, verificationReporter); +} \ No newline at end of file -- 2.43.0 From f14c812aff239954a7653f5640fd6664268edb71 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Tue, 26 Jul 2022 14:14:00 +0200 Subject: [PATCH 068/108] removed some obsolete code --- src/fsfw/tmtcservices/PusServiceBase.cpp | 12 +----------- 1 file changed, 1 insertion(+), 11 deletions(-) diff --git a/src/fsfw/tmtcservices/PusServiceBase.cpp b/src/fsfw/tmtcservices/PusServiceBase.cpp index f727e415..7ee5f8c6 100644 --- a/src/fsfw/tmtcservices/PusServiceBase.cpp +++ b/src/fsfw/tmtcservices/PusServiceBase.cpp @@ -25,7 +25,7 @@ PusServiceBase::~PusServiceBase() { QueueFactory::instance()->deleteMessageQueue ReturnValue_t PusServiceBase::performOperation(uint8_t opCode) { handleRequestQueue(); - ReturnValue_t result = this->performService(); + ReturnValue_t result = performService(); if (result != RETURN_OK) { #if FSFW_CPP_OSTREAM_ENABLED == 1 sif::error << "PusService " << (uint16_t)this->serviceId << ": performService returned with " @@ -43,17 +43,7 @@ void PusServiceBase::handleRequestQueue() { ReturnValue_t result; for (uint8_t count = 0; count < PUS_SERVICE_MAX_RECEPTION; count++) { ReturnValue_t status = this->requestQueue->receiveMessage(&message); - // if(status != MessageQueueIF::EMPTY) { -#if FSFW_CPP_OSTREAM_ENABLED == 1 - // sif::debug << "PusServiceBase::performOperation: Receiving from " - // << "MQ ID: " << std::hex << "0x" << std::setw(8) - // << std::setfill('0') << this->requestQueue->getId() - // << std::dec << " returned: " << status << std::setfill(' ') - // << std::endl; -#endif - // } if (status == MessageQueueIF::EMPTY) { - status = RETURN_OK; break; } else if (status != HasReturnvaluesIF::RETURN_OK) { #if FSFW_CPP_OSTREAM_ENABLED == 1 -- 2.43.0 From d98b79cf5e639abbe66420eeca42c47593b58a85 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Tue, 26 Jul 2022 16:49:46 +0200 Subject: [PATCH 069/108] adapt PSB so it can be unittested properly --- src/fsfw/pus/Service17Test.cpp | 8 +- src/fsfw/pus/Service17Test.h | 2 +- src/fsfw/pus/Service5EventReporting.cpp | 11 +- src/fsfw/pus/Service5EventReporting.h | 4 +- src/fsfw/pus/Service9TimeManagement.cpp | 4 +- src/fsfw/pus/Service9TimeManagement.h | 8 +- src/fsfw/tmtcservices/AcceptsTelemetryIF.h | 8 +- src/fsfw/tmtcservices/PusServiceBase.cpp | 106 ++++++++++-------- src/fsfw/tmtcservices/PusServiceBase.h | 97 ++++++++++------ src/fsfw/tmtcservices/TmTcMessage.cpp | 6 +- src/fsfw/tmtcservices/TmTcMessage.h | 6 +- unittests/CatchFactory.cpp | 1 - unittests/action/TestActionHelper.cpp | 3 +- unittests/datapoollocal/testDataSet.cpp | 2 +- .../datapoollocal/testLocalPoolManager.cpp | 2 +- .../datapoollocal/testLocalPoolVariable.cpp | 2 +- .../datapoollocal/testLocalPoolVector.cpp | 2 +- unittests/mocks/AcceptsTmMock.cpp | 7 ++ unittests/mocks/AcceptsTmMock.h | 14 +++ unittests/mocks/CMakeLists.txt | 1 + unittests/mocks/MessageQueueMock.cpp | 3 - unittests/mocks/MessageQueueMock.h | 2 - unittests/mocks/PusServiceBaseMock.cpp | 4 +- unittests/mocks/PusServiceBaseMock.h | 2 +- unittests/tmtcservices/testPsb.cpp | 25 ++++- unittests/tmtcservices/testSendHelper.cpp | 4 +- .../tmtcservices/testStoreAndSendHelper.cpp | 2 +- 27 files changed, 205 insertions(+), 131 deletions(-) create mode 100644 unittests/mocks/AcceptsTmMock.cpp create mode 100644 unittests/mocks/AcceptsTmMock.h diff --git a/src/fsfw/pus/Service17Test.cpp b/src/fsfw/pus/Service17Test.cpp index d526e055..14257334 100644 --- a/src/fsfw/pus/Service17Test.cpp +++ b/src/fsfw/pus/Service17Test.cpp @@ -5,10 +5,10 @@ #include "fsfw/objectmanager/SystemObject.h" #include "fsfw/tmtcservices/tmHelpers.h" -Service17Test::Service17Test(object_id_t objectId, uint16_t apid, uint8_t serviceId) - : PusServiceBase(objectId, apid, serviceId), - storeHelper(apid), - tmHelper(serviceId, storeHelper, sendHelper) {} +Service17Test::Service17Test(PsbParams params) + : PusServiceBase(params), + storeHelper(params.apid), + tmHelper(params.serviceId, storeHelper, sendHelper) {} Service17Test::~Service17Test() = default; diff --git a/src/fsfw/pus/Service17Test.h b/src/fsfw/pus/Service17Test.h index 7e2db98b..f2ec6e4f 100644 --- a/src/fsfw/pus/Service17Test.h +++ b/src/fsfw/pus/Service17Test.h @@ -34,7 +34,7 @@ class Service17Test : public PusServiceBase { EVENT_TRIGGER_TEST = 128, }; - Service17Test(object_id_t objectId, uint16_t apid, uint8_t serviceId); + explicit Service17Test(PsbParams params); void setCustomTmStore(StorageManagerIF& tmStore); diff --git a/src/fsfw/pus/Service5EventReporting.cpp b/src/fsfw/pus/Service5EventReporting.cpp index a895ad0d..fa518d0f 100644 --- a/src/fsfw/pus/Service5EventReporting.cpp +++ b/src/fsfw/pus/Service5EventReporting.cpp @@ -7,12 +7,11 @@ #include "fsfw/serviceinterface/ServiceInterface.h" #include "fsfw/tmtcservices/tmHelpers.h" -Service5EventReporting::Service5EventReporting(object_id_t objectId, uint16_t apid, - uint8_t serviceId, size_t maxNumberReportsPerCycle, +Service5EventReporting::Service5EventReporting(PsbParams params, size_t maxNumberReportsPerCycle, uint32_t messageQueueDepth) - : PusServiceBase(objectId, apid, serviceId), - storeHelper(apid), - tmHelper(serviceId, storeHelper, sendHelper), + : PusServiceBase(params), + storeHelper(params.apid), + tmHelper(params.serviceId, storeHelper, sendHelper), maxNumberReportsPerCycle(maxNumberReportsPerCycle) { eventQueue = QueueFactory::instance()->createMessageQueue(messageQueueDepth); } @@ -47,7 +46,7 @@ ReturnValue_t Service5EventReporting::performService() { ReturnValue_t Service5EventReporting::generateEventReport(EventMessage message) { EventReport report(message.getEventId(), message.getReporter(), message.getParameter1(), message.getParameter2()); - storeHelper.preparePacket(serviceId, message.getSeverity(), tmHelper.sendCounter); + storeHelper.preparePacket(psbParams.serviceId, message.getSeverity(), tmHelper.sendCounter); storeHelper.setSourceDataSerializable(report); ReturnValue_t result = tmHelper.storeAndSendTmPacket(); if (result != HasReturnvaluesIF::RETURN_OK) { diff --git a/src/fsfw/pus/Service5EventReporting.h b/src/fsfw/pus/Service5EventReporting.h index e6f67bfd..1f4e5a3a 100644 --- a/src/fsfw/pus/Service5EventReporting.h +++ b/src/fsfw/pus/Service5EventReporting.h @@ -41,8 +41,8 @@ */ class Service5EventReporting : public PusServiceBase { public: - Service5EventReporting(object_id_t objectId, uint16_t apid, uint8_t serviceId, - size_t maxNumberReportsPerCycle = 10, uint32_t messageQueueDepth = 10); + Service5EventReporting(PsbParams params, size_t maxNumberReportsPerCycle = 10, + uint32_t messageQueueDepth = 10); ~Service5EventReporting() override; /*** diff --git a/src/fsfw/pus/Service9TimeManagement.cpp b/src/fsfw/pus/Service9TimeManagement.cpp index 4abbd5d2..4a26f993 100644 --- a/src/fsfw/pus/Service9TimeManagement.cpp +++ b/src/fsfw/pus/Service9TimeManagement.cpp @@ -5,9 +5,7 @@ #include "fsfw/serviceinterface/ServiceInterface.h" #include "fsfw/timemanager/CCSDSTime.h" -Service9TimeManagement::Service9TimeManagement(object_id_t objectId, uint16_t apid, - uint8_t serviceId) - : PusServiceBase(objectId, apid, serviceId) {} +Service9TimeManagement::Service9TimeManagement(PsbParams params) : PusServiceBase(params) {} Service9TimeManagement::~Service9TimeManagement() = default; diff --git a/src/fsfw/pus/Service9TimeManagement.h b/src/fsfw/pus/Service9TimeManagement.h index 9369e207..b4886bb0 100644 --- a/src/fsfw/pus/Service9TimeManagement.h +++ b/src/fsfw/pus/Service9TimeManagement.h @@ -16,16 +16,16 @@ class Service9TimeManagement : public PusServiceBase { /** * @brief This service provides the capability to set the on-board time. */ - Service9TimeManagement(object_id_t objectId, uint16_t apid, uint8_t serviceId); + explicit Service9TimeManagement(PsbParams params); - virtual ~Service9TimeManagement(); + ~Service9TimeManagement() override; - virtual ReturnValue_t performService() override; + ReturnValue_t performService() override; /** * @brief Sets the onboard-time by retrieving the time to set from TC[9,128]. */ - virtual ReturnValue_t handleRequest(uint8_t subservice) override; + ReturnValue_t handleRequest(uint8_t subservice) override; virtual ReturnValue_t setTime(); diff --git a/src/fsfw/tmtcservices/AcceptsTelemetryIF.h b/src/fsfw/tmtcservices/AcceptsTelemetryIF.h index 0e715130..6f8a6226 100644 --- a/src/fsfw/tmtcservices/AcceptsTelemetryIF.h +++ b/src/fsfw/tmtcservices/AcceptsTelemetryIF.h @@ -1,7 +1,7 @@ #ifndef FSFW_TMTCSERVICES_ACCEPTSTELEMETRYIF_H_ #define FSFW_TMTCSERVICES_ACCEPTSTELEMETRYIF_H_ -#include "../ipc/MessageQueueSenderIF.h" +#include "fsfw/ipc/MessageQueueSenderIF.h" /** * @brief This interface is implemented by classes that are sinks for * Telemetry. @@ -13,13 +13,15 @@ class AcceptsTelemetryIF { /** * @brief The virtual destructor as it is mandatory for C++ interfaces. */ - virtual ~AcceptsTelemetryIF() {} + virtual ~AcceptsTelemetryIF() = default; /** * @brief This method returns the message queue id of the telemetry * receiving message queue. * @return The telemetry reception message queue id. */ - virtual MessageQueueId_t getReportReceptionQueue(uint8_t virtualChannel = 0) = 0; + virtual MessageQueueId_t getReportReceptionQueue(uint8_t virtualChannel) = 0; + + virtual MessageQueueId_t getReportReceptionQueue() { return getReportReceptionQueue(0); } }; #endif /* FSFW_TMTCSERVICES_ACCEPTSTELEMETRYIF_H_ */ diff --git a/src/fsfw/tmtcservices/PusServiceBase.cpp b/src/fsfw/tmtcservices/PusServiceBase.cpp index 7ee5f8c6..8d250a0f 100644 --- a/src/fsfw/tmtcservices/PusServiceBase.cpp +++ b/src/fsfw/tmtcservices/PusServiceBase.cpp @@ -9,19 +9,16 @@ #include "fsfw/tmtcservices/TmTcMessage.h" #include "fsfw/tmtcservices/tcHelpers.h" -object_id_t PusServiceBase::packetSource = 0; object_id_t PusServiceBase::packetDestination = 0; -PusServiceBase::PusServiceBase(object_id_t setObjectId, uint16_t setApid, uint8_t setServiceId, - VerificationReporterIF* verifyReporter) - : SystemObject(setObjectId), - apid(setApid), - serviceId(setServiceId), - verifyReporter(verifyReporter) { - requestQueue = QueueFactory::instance()->createMessageQueue(PUS_SERVICE_MAX_RECEPTION); -} +PusServiceBase::PusServiceBase(PsbParams params) + : SystemObject(params.objectId), psbParams(params) {} -PusServiceBase::~PusServiceBase() { QueueFactory::instance()->deleteMessageQueue(requestQueue); } +PusServiceBase::~PusServiceBase() { + if (ownedQueue) { + QueueFactory::instance()->deleteMessageQueue(psbParams.reqQueue); + } +} ReturnValue_t PusServiceBase::performOperation(uint8_t opCode) { handleRequestQueue(); @@ -42,7 +39,7 @@ void PusServiceBase::handleRequestQueue() { TmTcMessage message; ReturnValue_t result; for (uint8_t count = 0; count < PUS_SERVICE_MAX_RECEPTION; count++) { - ReturnValue_t status = this->requestQueue->receiveMessage(&message); + ReturnValue_t status = psbParams.reqQueue->receiveMessage(&message); if (status == MessageQueueIF::EMPTY) { break; } else if (status != HasReturnvaluesIF::RETURN_OK) { @@ -53,27 +50,27 @@ void PusServiceBase::handleRequestQueue() { #else sif::printError( "PusServiceBase::performOperation: Service %d. Error receiving packet. Code: %04x\n", - serviceId, status); + psbParams.serviceId, status); #endif break; } result = tc::prepareTcReader(tcStore, message.getStorageId(), currentPacket); if (result != HasReturnvaluesIF::RETURN_OK) { - auto params = VerifFailureParams(tcverif::START_FAILURE, currentPacket, result); - params.errorParam1 = errorParameter1; - params.errorParam2 = errorParameter2; - verifyReporter->sendFailureReport(params); + auto verifParams = VerifFailureParams(tcverif::START_FAILURE, currentPacket, result); + verifParams.errorParam1 = errorParameter1; + verifParams.errorParam2 = errorParameter2; + psbParams.verifReporter->sendFailureReport(verifParams); continue; } result = handleRequest(currentPacket.getSubService()); if (result == RETURN_OK) { - verifyReporter->sendSuccessReport( + psbParams.verifReporter->sendSuccessReport( VerifSuccessParams(tcverif::COMPLETION_SUCCESS, currentPacket)); } else { - auto params = VerifFailureParams(tcverif::COMPLETION_FAILURE, currentPacket, result); - params.errorParam1 = errorParameter1; - params.errorParam2 = errorParameter2; - verifyReporter->sendFailureReport(params); + auto failParams = VerifFailureParams(tcverif::COMPLETION_FAILURE, currentPacket, result); + failParams.errorParam1 = errorParameter1; + failParams.errorParam2 = errorParameter2; + psbParams.verifReporter->sendFailureReport(failParams); } tcStore->deleteData(message.getStorageId()); errorParameter1 = 0; @@ -81,37 +78,39 @@ void PusServiceBase::handleRequestQueue() { } } -uint16_t PusServiceBase::getIdentifier() { return this->serviceId; } +uint16_t PusServiceBase::getIdentifier() { return psbParams.serviceId; } -MessageQueueId_t PusServiceBase::getRequestQueue() { return this->requestQueue->getId(); } +MessageQueueId_t PusServiceBase::getRequestQueue() { return psbParams.reqQueue->getId(); } ReturnValue_t PusServiceBase::initialize() { ReturnValue_t result = SystemObject::initialize(); if (result != RETURN_OK) { return result; } - 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 - << ": Configuration error. Make sure " - << "packetSource and packetDestination are defined correctly" << std::endl; -#endif - return ObjectManagerIF::CHILD_INIT_FAILED; + if (psbParams.reqQueue == nullptr) { + ownedQueue = true; + psbParams.reqQueue = QueueFactory::instance()->createMessageQueue(PSB_DEFAULT_QUEUE_DEPTH); + } else { + ownedQueue = false; } - this->requestQueue->setDefaultDestination(destService->getReportReceptionQueue()); - distributor->registerService(this); + if (psbParams.tmReceiver == nullptr) { + psbParams.tmReceiver = ObjectManager::instance()->get(packetDestination); + if (psbParams.tmReceiver != nullptr) { + psbParams.reqQueue->setDefaultDestination(psbParams.tmReceiver->getReportReceptionQueue()); + } + } + if (tcStore == nullptr) { - tcStore = ObjectManager::instance()->get(objects::IPC_STORE); + tcStore = ObjectManager::instance()->get(objects::TC_STORE); if (tcStore == nullptr) { return ObjectManagerIF::CHILD_INIT_FAILED; } } - if (verifyReporter == nullptr) { - verifyReporter = + + if (psbParams.verifReporter == nullptr) { + psbParams.verifReporter = ObjectManager::instance()->get(objects::TC_VERIFICATOR); - if (verifyReporter == nullptr) { + if (psbParams.verifReporter == nullptr) { return ObjectManagerIF::CHILD_INIT_FAILED; } } @@ -128,7 +127,7 @@ ReturnValue_t PusServiceBase::initializeAfterTaskCreation() { void PusServiceBase::setCustomTcStore(StorageManagerIF* tcStore_) { tcStore = tcStore_; } void PusServiceBase::setCustomErrorReporter(InternalErrorReporterIF* errReporter_) { - errReporter = errReporter_; + psbParams.errReporter = errReporter_; } void PusServiceBase::initializeTmHelpers(TmSendHelper& tmSendHelper, TmStoreHelper& tmStoreHelper) { @@ -137,21 +136,34 @@ void PusServiceBase::initializeTmHelpers(TmSendHelper& tmSendHelper, TmStoreHelp } void PusServiceBase::initializeTmSendHelper(TmSendHelper& tmSendHelper) { - tmSendHelper.setMsgQueue(*requestQueue); - tmSendHelper.setDefaultDestination(requestQueue->getDefaultDestination()); - if (errReporter == nullptr) { - errReporter = + if (psbParams.reqQueue != nullptr) { + tmSendHelper.setMsgQueue(*psbParams.reqQueue); + tmSendHelper.setDefaultDestination(psbParams.reqQueue->getDefaultDestination()); + } + + if (psbParams.errReporter == nullptr) { + psbParams.errReporter = ObjectManager::instance()->get(objects::INTERNAL_ERROR_REPORTER); - if (errReporter != nullptr) { - tmSendHelper.setInternalErrorReporter(errReporter); + if (psbParams.errReporter != nullptr) { + tmSendHelper.setInternalErrorReporter(psbParams.errReporter); } } } void PusServiceBase::initializeTmStoreHelper(TmStoreHelper& tmStoreHelper) const { - tmStoreHelper.setApid(apid); + tmStoreHelper.setApid(psbParams.apid); } void PusServiceBase::setVerificationReporter(VerificationReporterIF* reporter) { - verifyReporter = reporter; + psbParams.verifReporter = reporter; } + +ReturnValue_t PusServiceBase::registerService(PUSDistributorIF& distributor) { + return distributor.registerService(this); +} + +void PusServiceBase::setTmReceiver(AcceptsTelemetryIF* tmReceiver_) { + psbParams.tmReceiver = tmReceiver_; +} + +void PusServiceBase::setRequestQueue(MessageQueueIF* reqQueue) { psbParams.reqQueue = reqQueue; } diff --git a/src/fsfw/tmtcservices/PusServiceBase.h b/src/fsfw/tmtcservices/PusServiceBase.h index 4aa6fade..fabe6141 100644 --- a/src/fsfw/tmtcservices/PusServiceBase.h +++ b/src/fsfw/tmtcservices/PusServiceBase.h @@ -2,6 +2,7 @@ #define FSFW_TMTCSERVICES_PUSSERVICEBASE_H_ #include "AcceptsTelecommandsIF.h" +#include "AcceptsTelemetryIF.h" #include "TmSendHelper.h" #include "TmStoreHelper.h" #include "VerificationCodes.h" @@ -11,6 +12,7 @@ #include "fsfw/objectmanager/SystemObject.h" #include "fsfw/returnvalues/HasReturnvaluesIF.h" #include "fsfw/tasks/ExecutableObjectIF.h" +#include "fsfw/tcdistribution/PUSDistributorIF.h" namespace Factory { void setStaticFrameworkObjectIds(); @@ -18,6 +20,44 @@ void setStaticFrameworkObjectIds(); class StorageManagerIF; +/** + * Configuration parameters for the PUS Service Base + */ +struct PsbParams { + PsbParams() = default; + PsbParams(uint16_t apid, AcceptsTelemetryIF* tmReceiver) : apid(apid), tmReceiver(tmReceiver) {} + PsbParams(object_id_t objectId, uint16_t apid, uint8_t serviceId) + : objectId(objectId), apid(apid), serviceId(serviceId) {} + + object_id_t objectId = objects::NO_OBJECT; + uint16_t apid = 0; + uint8_t serviceId = 0; + /** + * The default destination ID for generated telemetry. If this is not set, @initialize of PSB + * will attempt to find a suitable object with the object ID @PusServiceBase::packetDestination + */ + AcceptsTelemetryIF* tmReceiver = nullptr; + /** + * An instance of the VerificationReporter class, that simplifies + * sending any kind of verification message to the TC Verification Service. If this is not set, + * @initialize of PSB will attempt to find a suitable global object with the ID + * @objects::TC_VERIFICATOR + */ + VerificationReporterIF* verifReporter = nullptr; + /** + * This is a complete instance of the telecommand reception queue + * of the class. It is initialized on construction of the class. + */ + MessageQueueIF* reqQueue = nullptr; + /** + * The internal error reporter which will be used if there are issues sending telemetry. + * If this is not set, and the TM send or store helpers are initialized with the PSB, + * the class will attempt to find a suitable global object with the ID + * @objects::INTERNAL_ERROR_REPORTER + */ + InternalErrorReporterIF* errReporter = nullptr; +}; + /** * @defgroup pus_services PUS Service Framework * These group contains all implementations of PUS Services in the OBSW. @@ -43,23 +83,33 @@ class PusServiceBase : public ExecutableObjectIF, friend void(Factory::setStaticFrameworkObjectIds)(); public: + /** + * This constant sets the maximum number of packets accepted per call. + * Remember that one packet must be completely handled in one + * #handleRequest call. + */ + static constexpr uint8_t PUS_SERVICE_MAX_RECEPTION = 10; + static constexpr uint8_t PSB_DEFAULT_QUEUE_DEPTH = 10; + /** * @brief The passed values are set, but inter-object initialization is * done in the initialize method. - * @param setObjectId - * The system object identifier of this Service instance. - * @param setApid - * The APID the Service is instantiated for. - * @param setServiceId - * The Service Identifier as specified in ECSS PUS. + * @param params All configuration parameters for the PUS Service Base */ - PusServiceBase(object_id_t setObjectId, uint16_t setApid, uint8_t setServiceId, - VerificationReporterIF* reporter = nullptr); + explicit PusServiceBase(PsbParams params); /** * The destructor is empty. */ ~PusServiceBase() override; + ReturnValue_t registerService(PUSDistributorIF& distributor); + /** + * Set the request queue which is used to receive requests. If none is set, the initialize + * function will create one + * @param reqQueue + */ + void setRequestQueue(MessageQueueIF* reqQueue); + void setTmReceiver(AcceptsTelemetryIF* tmReceiver); void setCustomTcStore(StorageManagerIF* tcStore); void setVerificationReporter(VerificationReporterIF* reporter); void setCustomErrorReporter(InternalErrorReporterIF* errReporter); @@ -136,14 +186,6 @@ class PusServiceBase : public ExecutableObjectIF, * Will be set by setTaskIF(), which is called on task creation. */ PeriodicTaskIF* taskHandle = nullptr; - /** - * The APID of this instance of the Service. - */ - uint16_t apid; - /** - * The Service Identifier. - */ - uint8_t serviceId; /** * One of two error parameters for additional error information. */ @@ -152,38 +194,19 @@ class PusServiceBase : public ExecutableObjectIF, * One of two error parameters for additional error information. */ uint32_t errorParameter2 = 0; - /** - * This is a complete instance of the telecommand reception queue - * of the class. It is initialized on construction of the class. - */ - MessageQueueIF* requestQueue = nullptr; - /** - * An instance of the VerificationReporter class, that simplifies - * sending any kind of verification message to the TC Verification Service. - */ - VerificationReporterIF* verifyReporter; - + PsbParams psbParams; /** * The current Telecommand to be processed. * It is deleted after handleRequest was executed. */ PusTcReader currentPacket; StorageManagerIF* tcStore = nullptr; - InternalErrorReporterIF* errReporter = nullptr; - - static object_id_t packetSource; + bool ownedQueue = true; static object_id_t packetDestination; VerifSuccessParams successParams; private: - /** - * This constant sets the maximum number of packets accepted per call. - * Remember that one packet must be completely handled in one - * #handleRequest call. - */ - static const uint8_t PUS_SERVICE_MAX_RECEPTION = 10; - void handleRequestQueue(); }; diff --git a/src/fsfw/tmtcservices/TmTcMessage.cpp b/src/fsfw/tmtcservices/TmTcMessage.cpp index ca76760f..bd071b5b 100644 --- a/src/fsfw/tmtcservices/TmTcMessage.cpp +++ b/src/fsfw/tmtcservices/TmTcMessage.cpp @@ -4,7 +4,7 @@ TmTcMessage::TmTcMessage() { this->messageSize += sizeof(store_address_t); } -TmTcMessage::~TmTcMessage() {} +TmTcMessage::~TmTcMessage() = default; store_address_t TmTcMessage::getStorageId() { store_address_t temp_id; @@ -18,9 +18,9 @@ TmTcMessage::TmTcMessage(store_address_t storeId) { } size_t TmTcMessage::getMinimumMessageSize() const { - return this->HEADER_SIZE + sizeof(store_address_t); + return TmTcMessage::HEADER_SIZE + sizeof(store_address_t); } void TmTcMessage::setStorageId(store_address_t storeId) { - memcpy(this->getData(), &storeId, sizeof(store_address_t)); + std::memcpy(this->getData(), &storeId, sizeof(store_address_t)); } diff --git a/src/fsfw/tmtcservices/TmTcMessage.h b/src/fsfw/tmtcservices/TmTcMessage.h index a0f67894..3fba6d7a 100644 --- a/src/fsfw/tmtcservices/TmTcMessage.h +++ b/src/fsfw/tmtcservices/TmTcMessage.h @@ -18,7 +18,7 @@ class TmTcMessage : public MessageQueueMessage { * @brief This call always returns the same fixed size of the message. * @return Returns HEADER_SIZE + @c sizeof(store_address_t). */ - size_t getMinimumMessageSize() const override; + [[nodiscard]] size_t getMinimumMessageSize() const override; public: /** @@ -30,11 +30,11 @@ class TmTcMessage : public MessageQueueMessage { * into the message. * @param packet_id The packet id to put into the message. */ - TmTcMessage(store_address_t packetId); + explicit TmTcMessage(store_address_t packetId); /** * @brief The class's destructor is empty. */ - ~TmTcMessage(); + ~TmTcMessage() override; /** * @brief This getter returns the packet id in the correct format. * @return Returns the packet id. diff --git a/unittests/CatchFactory.cpp b/unittests/CatchFactory.cpp index 5ae5a9fb..1d10c582 100644 --- a/unittests/CatchFactory.cpp +++ b/unittests/CatchFactory.cpp @@ -54,7 +54,6 @@ void Factory::produceFrameworkObjects(void* args) { // like this. Instead, this should be more like a general struct containing all important // object IDs which are then explicitely passed in the object constructor void Factory::setStaticFrameworkObjectIds() { - PusServiceBase::packetSource = objects::NO_OBJECT; PusServiceBase::packetDestination = objects::NO_OBJECT; CommandingServiceBase::defaultPacketSource = objects::NO_OBJECT; diff --git a/unittests/action/TestActionHelper.cpp b/unittests/action/TestActionHelper.cpp index bf5589ab..849e57d2 100644 --- a/unittests/action/TestActionHelper.cpp +++ b/unittests/action/TestActionHelper.cpp @@ -10,7 +10,8 @@ TEST_CASE("Action Helper", "[ActionHelper]") { ActionHelperOwnerMockBase testDhMock; - MessageQueueMock testMqMock; + // TODO: Setting another number here breaks the test. Find out why + MessageQueueMock testMqMock(MessageQueueIF::NO_QUEUE); ActionHelper actionHelper = ActionHelper(&testDhMock, dynamic_cast(&testMqMock)); CommandMessage actionMessage; ActionId_t testActionId = 777; diff --git a/unittests/datapoollocal/testDataSet.cpp b/unittests/datapoollocal/testDataSet.cpp index 0ef5a77f..532208f5 100644 --- a/unittests/datapoollocal/testDataSet.cpp +++ b/unittests/datapoollocal/testDataSet.cpp @@ -14,7 +14,7 @@ #include "tests/TestsConfig.h" TEST_CASE("DataSetTest", "[DataSetTest]") { - auto queue = MessageQueueMock(); + auto queue = MessageQueueMock(1); LocalPoolOwnerBase poolOwner(queue, objects::TEST_LOCAL_POOL_OWNER_BASE); REQUIRE(poolOwner.initializeHkManager() == retval::CATCH_OK); REQUIRE(poolOwner.initializeHkManagerAfterTaskCreation() == retval::CATCH_OK); diff --git a/unittests/datapoollocal/testLocalPoolManager.cpp b/unittests/datapoollocal/testLocalPoolManager.cpp index e5282c16..bdeec8c0 100644 --- a/unittests/datapoollocal/testLocalPoolManager.cpp +++ b/unittests/datapoollocal/testLocalPoolManager.cpp @@ -20,7 +20,7 @@ TEST_CASE("Local Pool Manager Tests", "[LocManTest]") { const MessageQueueId_t hkDest = defaultDestId; const MessageQueueId_t subscriberId = 2; auto hkReceiver = HkReceiverMock(hkDest); - auto queue = MessageQueueMock(); + auto queue = MessageQueueMock(3); LocalPoolOwnerBase poolOwner(queue, objects::TEST_LOCAL_POOL_OWNER_BASE); REQUIRE(poolOwner.initializeHkManager() == retval::CATCH_OK); REQUIRE(poolOwner.initializeHkManagerAfterTaskCreation() == retval::CATCH_OK); diff --git a/unittests/datapoollocal/testLocalPoolVariable.cpp b/unittests/datapoollocal/testLocalPoolVariable.cpp index dda5aca6..b3ae07e0 100644 --- a/unittests/datapoollocal/testLocalPoolVariable.cpp +++ b/unittests/datapoollocal/testLocalPoolVariable.cpp @@ -8,7 +8,7 @@ #include "tests/TestsConfig.h" TEST_CASE("LocalPoolVariable", "[LocPoolVarTest]") { - auto queue = MessageQueueMock(); + auto queue = MessageQueueMock(1); LocalPoolOwnerBase poolOwner(queue, objects::TEST_LOCAL_POOL_OWNER_BASE); REQUIRE(poolOwner.initializeHkManager() == retval::CATCH_OK); REQUIRE(poolOwner.initializeHkManagerAfterTaskCreation() == retval::CATCH_OK); diff --git a/unittests/datapoollocal/testLocalPoolVector.cpp b/unittests/datapoollocal/testLocalPoolVector.cpp index dc91fa7e..e04bf643 100644 --- a/unittests/datapoollocal/testLocalPoolVector.cpp +++ b/unittests/datapoollocal/testLocalPoolVector.cpp @@ -8,7 +8,7 @@ #include "tests/TestsConfig.h" TEST_CASE("LocalPoolVector", "[LocPoolVecTest]") { - auto queue = MessageQueueMock(); + auto queue = MessageQueueMock(1); LocalPoolOwnerBase poolOwner(queue, objects::TEST_LOCAL_POOL_OWNER_BASE); REQUIRE(poolOwner.initializeHkManager() == retval::CATCH_OK); REQUIRE(poolOwner.initializeHkManagerAfterTaskCreation() == retval::CATCH_OK); diff --git a/unittests/mocks/AcceptsTmMock.cpp b/unittests/mocks/AcceptsTmMock.cpp new file mode 100644 index 00000000..9142308d --- /dev/null +++ b/unittests/mocks/AcceptsTmMock.cpp @@ -0,0 +1,7 @@ +#include "AcceptsTmMock.h" + +AcceptsTmMock::AcceptsTmMock(MessageQueueId_t queueToReturn) : returnedQueue(queueToReturn) {} + +MessageQueueId_t AcceptsTmMock::getReportReceptionQueue(uint8_t virtualChannel) { + return returnedQueue; +} diff --git a/unittests/mocks/AcceptsTmMock.h b/unittests/mocks/AcceptsTmMock.h new file mode 100644 index 00000000..b0ccc9a7 --- /dev/null +++ b/unittests/mocks/AcceptsTmMock.h @@ -0,0 +1,14 @@ +#ifndef FSFW_TESTS_ACCEPTSTMMOCK_H +#define FSFW_TESTS_ACCEPTSTMMOCK_H + +#include "fsfw/tmtcservices/AcceptsTelemetryIF.h" + +class AcceptsTmMock : public AcceptsTelemetryIF { + public: + explicit AcceptsTmMock(MessageQueueId_t queueToReturn); + + MessageQueueId_t getReportReceptionQueue(uint8_t virtualChannel) override; + + MessageQueueId_t returnedQueue; +}; +#endif // FSFW_TESTS_ACCEPTSTMMOCK_H diff --git a/unittests/mocks/CMakeLists.txt b/unittests/mocks/CMakeLists.txt index 00732c80..5bb37db4 100644 --- a/unittests/mocks/CMakeLists.txt +++ b/unittests/mocks/CMakeLists.txt @@ -9,4 +9,5 @@ target_sources(${FSFW_TEST_TGT} PRIVATE LocalPoolOwnerBase.cpp PusVerificationReporterMock.cpp PusServiceBaseMock.cpp + AcceptsTmMock.cpp ) diff --git a/unittests/mocks/MessageQueueMock.cpp b/unittests/mocks/MessageQueueMock.cpp index c514cc2e..215a7830 100644 --- a/unittests/mocks/MessageQueueMock.cpp +++ b/unittests/mocks/MessageQueueMock.cpp @@ -3,9 +3,6 @@ #include #include -MessageQueueMock::MessageQueueMock() - : MessageQueueBase(MessageQueueIF::NO_QUEUE, MessageQueueIF::NO_QUEUE, nullptr) {} - MessageQueueMock::MessageQueueMock(MessageQueueId_t queueId) : MessageQueueBase(queueId, MessageQueueIF::NO_QUEUE, nullptr) {} diff --git a/unittests/mocks/MessageQueueMock.h b/unittests/mocks/MessageQueueMock.h index 0be68223..52ba5dfe 100644 --- a/unittests/mocks/MessageQueueMock.h +++ b/unittests/mocks/MessageQueueMock.h @@ -22,8 +22,6 @@ struct SendInfo { class MessageQueueMock : public MessageQueueBase { public: - MessageQueueMock(); - void addReceivedMessage(MessageQueueMessageIF& msg); explicit MessageQueueMock(MessageQueueId_t queueId); diff --git a/unittests/mocks/PusServiceBaseMock.cpp b/unittests/mocks/PusServiceBaseMock.cpp index 4eb51fa4..ef36d09e 100644 --- a/unittests/mocks/PusServiceBaseMock.cpp +++ b/unittests/mocks/PusServiceBaseMock.cpp @@ -1,7 +1,6 @@ #include "PusServiceBaseMock.h" -PsbMock::PsbMock(uint8_t service, uint16_t apid, VerificationReporterIF& verifyReporter) - : PusServiceBase(0, service, apid, &verifyReporter) {} +PsbMock::PsbMock(PsbParams params) : PusServiceBase(params) {} ReturnValue_t PsbMock::handleRequest(uint8_t subservice) { handleRequestCallCnt++; @@ -27,6 +26,7 @@ void PsbMock::reset() { performServiceCallCnt = 0; std::queue().swap(subserviceQueue); } + void PsbMock::makeNextHandleReqCallFail(ReturnValue_t retval) { handleReqFailPair.first = true; handleReqFailPair.second = retval; diff --git a/unittests/mocks/PusServiceBaseMock.h b/unittests/mocks/PusServiceBaseMock.h index 9d1bac5d..42620662 100644 --- a/unittests/mocks/PusServiceBaseMock.h +++ b/unittests/mocks/PusServiceBaseMock.h @@ -7,7 +7,7 @@ class PsbMock : public PusServiceBase { public: - PsbMock(uint8_t service, uint16_t apid, VerificationReporterIF& verifyReporter); + explicit PsbMock(PsbParams params); unsigned int handleRequestCallCnt = 0; std::queue subserviceQueue; unsigned int performServiceCallCnt = 0; diff --git a/unittests/tmtcservices/testPsb.cpp b/unittests/tmtcservices/testPsb.cpp index ea4aee61..53fe763d 100644 --- a/unittests/tmtcservices/testPsb.cpp +++ b/unittests/tmtcservices/testPsb.cpp @@ -1,9 +1,32 @@ #include +#include "fsfw/ipc/QueueFactory.h" +#include "mocks/AcceptsTmMock.h" +#include "mocks/MessageQueueMock.h" #include "mocks/PusServiceBaseMock.h" #include "mocks/PusVerificationReporterMock.h" TEST_CASE("Pus Service Base", "[pus-service-base]") { auto verificationReporter = PusVerificationReporterMock(); - auto psb = PsbMock(17, 0x02, verificationReporter); + auto msgQueue = MessageQueueMock(1); + auto tmReceiver = AcceptsTmMock(2); + auto psbParams = PsbParams(0, 0x02, 17); + psbParams.verifReporter = &verificationReporter; + psbParams.reqQueue = &msgQueue; + psbParams.tmReceiver = &tmReceiver; + auto psb = PsbMock(psbParams); + store_address_t dummyId(1); + auto reqQueue = psb.getRequestQueue(); + TmTcMessage tmtcMsg(dummyId); + REQUIRE(psb.initialize() == HasReturnvaluesIF::RETURN_OK); + + SECTION("State") { + REQUIRE(psb.getIdentifier() == 17); + REQUIRE(psb.getObjectId() == 0); + } + + SECTION("Send Request") { + msgQueue.addReceivedMessage(tmtcMsg); + REQUIRE(psb.performOperation(0) == retval::OK); + } } \ No newline at end of file diff --git a/unittests/tmtcservices/testSendHelper.cpp b/unittests/tmtcservices/testSendHelper.cpp index 786fe073..82adc04b 100644 --- a/unittests/tmtcservices/testSendHelper.cpp +++ b/unittests/tmtcservices/testSendHelper.cpp @@ -8,9 +8,9 @@ #include "mocks/MessageQueueMock.h" TEST_CASE("TM Send Helper", "[tm-send-helper]") { - MessageQueueId_t destId = 1; + MessageQueueId_t destId = 2; auto errReporter = InternalErrorReporterMock(); - auto msgQueue = MessageQueueMock(); + auto msgQueue = MessageQueueMock(1); msgQueue.setDefaultDestination(destId); TmSendHelper sendHelper(msgQueue, errReporter, destId); auto timeStamper = CdsShortTimestamperMock(); diff --git a/unittests/tmtcservices/testStoreAndSendHelper.cpp b/unittests/tmtcservices/testStoreAndSendHelper.cpp index 2a522600..73051f8e 100644 --- a/unittests/tmtcservices/testStoreAndSendHelper.cpp +++ b/unittests/tmtcservices/testStoreAndSendHelper.cpp @@ -17,7 +17,7 @@ TEST_CASE("TM Store And Send Helper", "[tm-store-send-helper]") { MessageQueueId_t destId = 1; auto errReporter = InternalErrorReporterMock(); - auto msgQueue = MessageQueueMock(); + auto msgQueue = MessageQueueMock(2); msgQueue.setDefaultDestination(destId); TmSendHelper sendHelper(msgQueue, errReporter, destId); TmStoreAndSendWrapper tmHelper(17, storeHelper, sendHelper); -- 2.43.0 From 1954ce0ea409a1b981d42198a882cdf1033edbe3 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Tue, 26 Jul 2022 17:41:10 +0200 Subject: [PATCH 070/108] default PUS receiver set automatically now --- .../tmtcservices/CommandingServiceBase.cpp | 2 +- src/fsfw/tmtcservices/PusServiceBase.cpp | 24 +++++-- src/fsfw/tmtcservices/PusServiceBase.h | 15 +++- .../tmtcservices/VerificationReporter.cpp | 26 +++++++ src/fsfw/tmtcservices/VerificationReporter.h | 3 + src/fsfw/tmtcservices/tcHelpers.cpp | 4 +- src/fsfw/tmtcservices/tcHelpers.h | 2 +- unittests/mocks/PusServiceBaseMock.cpp | 8 +++ unittests/mocks/PusServiceBaseMock.h | 1 + .../mocks/PusVerificationReporterMock.cpp | 11 +++ unittests/mocks/PusVerificationReporterMock.h | 4 +- unittests/tmtcservices/testPsb.cpp | 68 +++++++++++++++++-- 12 files changed, 149 insertions(+), 19 deletions(-) diff --git a/src/fsfw/tmtcservices/CommandingServiceBase.cpp b/src/fsfw/tmtcservices/CommandingServiceBase.cpp index c890ecfb..0815c838 100644 --- a/src/fsfw/tmtcservices/CommandingServiceBase.cpp +++ b/src/fsfw/tmtcservices/CommandingServiceBase.cpp @@ -422,7 +422,7 @@ void CommandingServiceBase::setCustomTmStore(StorageManagerIF& store) { tmStoreHelper.setTmStore(store); } ReturnValue_t CommandingServiceBase::setUpTcReader(store_address_t storeId) { - return tc::prepareTcReader(tcStore, storeId, tcReader); + return tc::prepareTcReader(*tcStore, storeId, tcReader); } void CommandingServiceBase::prepareVerificationFailureWithFullInfo(uint8_t reportId, diff --git a/src/fsfw/tmtcservices/PusServiceBase.cpp b/src/fsfw/tmtcservices/PusServiceBase.cpp index 8d250a0f..c283d655 100644 --- a/src/fsfw/tmtcservices/PusServiceBase.cpp +++ b/src/fsfw/tmtcservices/PusServiceBase.cpp @@ -10,6 +10,7 @@ #include "fsfw/tmtcservices/tcHelpers.h" object_id_t PusServiceBase::packetDestination = 0; +object_id_t PusServiceBase::pusDistributor = 0; PusServiceBase::PusServiceBase(PsbParams params) : SystemObject(params.objectId), psbParams(params) {} @@ -54,9 +55,11 @@ void PusServiceBase::handleRequestQueue() { #endif break; } - result = tc::prepareTcReader(tcStore, message.getStorageId(), currentPacket); + result = tc::prepareTcReader(*psbParams.tcPool, message.getStorageId(), currentPacket); if (result != HasReturnvaluesIF::RETURN_OK) { - auto verifParams = VerifFailureParams(tcverif::START_FAILURE, currentPacket, result); + // We were not even able to retrieve the TC, so we can not retrieve any TC properties either + // without segfaulting + auto verifParams = VerifFailureParams(tcverif::START_FAILURE, 0, 0, result); verifParams.errorParam1 = errorParameter1; verifParams.errorParam2 = errorParameter2; psbParams.verifReporter->sendFailureReport(verifParams); @@ -72,7 +75,7 @@ void PusServiceBase::handleRequestQueue() { failParams.errorParam2 = errorParameter2; psbParams.verifReporter->sendFailureReport(failParams); } - tcStore->deleteData(message.getStorageId()); + psbParams.tcPool->deleteData(message.getStorageId()); errorParameter1 = 0; errorParameter2 = 0; } @@ -100,9 +103,16 @@ ReturnValue_t PusServiceBase::initialize() { } } - if (tcStore == nullptr) { - tcStore = ObjectManager::instance()->get(objects::TC_STORE); - if (tcStore == nullptr) { + if (psbParams.pusDistributor != nullptr) { + psbParams.pusDistributor = ObjectManager::instance()->get(pusDistributor); + if (psbParams.pusDistributor != nullptr) { + registerService(*psbParams.pusDistributor); + } + } + + if (psbParams.tcPool == nullptr) { + psbParams.tcPool = ObjectManager::instance()->get(objects::TC_STORE); + if (psbParams.tcPool == nullptr) { return ObjectManagerIF::CHILD_INIT_FAILED; } } @@ -124,7 +134,7 @@ ReturnValue_t PusServiceBase::initializeAfterTaskCreation() { return HasReturnvaluesIF::RETURN_OK; } -void PusServiceBase::setCustomTcStore(StorageManagerIF* tcStore_) { tcStore = tcStore_; } +void PusServiceBase::setCustomTcStore(StorageManagerIF* tcPool) { psbParams.tcPool = tcPool; } void PusServiceBase::setCustomErrorReporter(InternalErrorReporterIF* errReporter_) { psbParams.errReporter = errReporter_; diff --git a/src/fsfw/tmtcservices/PusServiceBase.h b/src/fsfw/tmtcservices/PusServiceBase.h index fabe6141..1c1c417d 100644 --- a/src/fsfw/tmtcservices/PusServiceBase.h +++ b/src/fsfw/tmtcservices/PusServiceBase.h @@ -56,6 +56,19 @@ struct PsbParams { * @objects::INTERNAL_ERROR_REPORTER */ InternalErrorReporterIF* errReporter = nullptr; + /** + * The storage manager which will be used to retrieve any TC packet using the store ID + * received via a message. If this is not set, the class will attempt to find a suitable global + * object with the ID @objects::TC_STORE + */ + StorageManagerIF* tcPool = nullptr; + /** + * Usually, packets are sent via a dedicated PUS distributor. If this distributor is set, + * the PUS service will register itself there. Otherwise, the base class will try to find + * a suitable global distributor with the static ID @PusServiceBase::pusDistributor and + * register itself at that object. + */ + PUSDistributorIF* pusDistributor = nullptr; }; /** @@ -200,10 +213,10 @@ class PusServiceBase : public ExecutableObjectIF, * It is deleted after handleRequest was executed. */ PusTcReader currentPacket; - StorageManagerIF* tcStore = nullptr; bool ownedQueue = true; static object_id_t packetDestination; + static object_id_t pusDistributor; VerifSuccessParams successParams; private: diff --git a/src/fsfw/tmtcservices/VerificationReporter.cpp b/src/fsfw/tmtcservices/VerificationReporter.cpp index b08756d3..25d7cd4a 100644 --- a/src/fsfw/tmtcservices/VerificationReporter.cpp +++ b/src/fsfw/tmtcservices/VerificationReporter.cpp @@ -1,8 +1,11 @@ #include "fsfw/tmtcservices/VerificationReporter.h" +#include "fsfw/objectmanager.h" #include "fsfw/serviceinterface/ServiceInterface.h" #include "fsfw/tmtcservices/PusVerificationReport.h" +object_id_t VerificationReporter::DEFAULT_RECEIVER = objects::PUS_SERVICE_1_VERIFICATION; + VerificationReporter::VerificationReporter(AcceptsVerifyMessageIF* receiver, object_id_t objectId) : SystemObject(objectId) { if (receiver != nullptr) { @@ -42,3 +45,26 @@ ReturnValue_t VerificationReporter::sendSuccessReport(VerifSuccessParams params) } return status; } + +ReturnValue_t VerificationReporter::initialize() { + if (acknowledgeQueue == MessageQueueIF::NO_QUEUE) { + auto* receiver = ObjectManager::instance()->get(DEFAULT_RECEIVER); + if (receiver != nullptr) { + acknowledgeQueue = receiver->getVerificationQueue(); + } else { +#if FSFW_CPP_OSTREAM_ENABLED == 1 + sif::error + << "Could not find a suitable verification message receiver. Please ensure that it is set" + " via the constructor or creating a global one with the ID " + "VerificationReporter::DEFAULT_RECEIVER" + << std::endl; +#else + sif::printError( + "Could not find a suitable verification message receiver. Please ensure " + "that it is set via the constructor or creating a global one with the ID " + "VerificationReporter::DEFAULT_RECEIVER\n"); +#endif + } + } + return SystemObject::initialize(); +} diff --git a/src/fsfw/tmtcservices/VerificationReporter.h b/src/fsfw/tmtcservices/VerificationReporter.h index 8ea45f79..8b224808 100644 --- a/src/fsfw/tmtcservices/VerificationReporter.h +++ b/src/fsfw/tmtcservices/VerificationReporter.h @@ -33,6 +33,9 @@ class VerificationReporter : public SystemObject, public VerificationReporterIF ReturnValue_t sendFailureReport(VerifFailureParams params) override; + static object_id_t DEFAULT_RECEIVER; + ReturnValue_t initialize() override; + private: MessageQueueId_t acknowledgeQueue; }; diff --git a/src/fsfw/tmtcservices/tcHelpers.cpp b/src/fsfw/tmtcservices/tcHelpers.cpp index 91f6e3be..a51bab46 100644 --- a/src/fsfw/tmtcservices/tcHelpers.cpp +++ b/src/fsfw/tmtcservices/tcHelpers.cpp @@ -1,10 +1,10 @@ #include "tcHelpers.h" -ReturnValue_t tc::prepareTcReader(StorageManagerIF *tcStore, store_address_t storeId, +ReturnValue_t tc::prepareTcReader(StorageManagerIF &tcStore, store_address_t storeId, PusTcReader &tcReader) { const uint8_t *dataPtr; size_t dataLen = 0; - ReturnValue_t result = tcStore->getData(storeId, &dataPtr, &dataLen); + ReturnValue_t result = tcStore.getData(storeId, &dataPtr, &dataLen); if (result != HasReturnvaluesIF::RETURN_OK) { return result; } diff --git a/src/fsfw/tmtcservices/tcHelpers.h b/src/fsfw/tmtcservices/tcHelpers.h index fc19ae33..e2bbf509 100644 --- a/src/fsfw/tmtcservices/tcHelpers.h +++ b/src/fsfw/tmtcservices/tcHelpers.h @@ -7,7 +7,7 @@ namespace tc { -ReturnValue_t prepareTcReader(StorageManagerIF* tcStore, store_address_t storeId, +ReturnValue_t prepareTcReader(StorageManagerIF& tcStore, store_address_t storeId, PusTcReader& tcReader); } // namespace tc diff --git a/unittests/mocks/PusServiceBaseMock.cpp b/unittests/mocks/PusServiceBaseMock.cpp index ef36d09e..21f6a360 100644 --- a/unittests/mocks/PusServiceBaseMock.cpp +++ b/unittests/mocks/PusServiceBaseMock.cpp @@ -31,3 +31,11 @@ void PsbMock::makeNextHandleReqCallFail(ReturnValue_t retval) { handleReqFailPair.first = true; handleReqFailPair.second = retval; } +bool PsbMock::getAndPopNextSubservice(uint8_t& subservice) { + if (subserviceQueue.empty()) { + return false; + } + subservice = subserviceQueue.front(); + subserviceQueue.pop(); + return true; +} diff --git a/unittests/mocks/PusServiceBaseMock.h b/unittests/mocks/PusServiceBaseMock.h index 42620662..31ac43d3 100644 --- a/unittests/mocks/PusServiceBaseMock.h +++ b/unittests/mocks/PusServiceBaseMock.h @@ -18,6 +18,7 @@ class PsbMock : public PusServiceBase { ReturnValue_t performService() override; void makeNextHandleReqCallFail(ReturnValue_t retval); + bool getAndPopNextSubservice(uint8_t& subservice); void reset(); }; diff --git a/unittests/mocks/PusVerificationReporterMock.cpp b/unittests/mocks/PusVerificationReporterMock.cpp index fdc61aca..87b37a5a 100644 --- a/unittests/mocks/PusVerificationReporterMock.cpp +++ b/unittests/mocks/PusVerificationReporterMock.cpp @@ -16,8 +16,19 @@ void PusVerificationReporterMock::popNextFailParams() { VerifFailureParams& PusVerificationReporterMock::getNextFailCallParams() { return failParams.front(); } + void PusVerificationReporterMock::popNextSuccessParams() { if (not successParams.empty()) { successParams.pop(); } } + +ReturnValue_t PusVerificationReporterMock::sendSuccessReport(VerifSuccessParams params) { + successParams.push(params); + return HasReturnvaluesIF::RETURN_OK; +} + +ReturnValue_t PusVerificationReporterMock::sendFailureReport(VerifFailureParams params) { + failParams.push(params); + return HasReturnvaluesIF::RETURN_OK; +} diff --git a/unittests/mocks/PusVerificationReporterMock.h b/unittests/mocks/PusVerificationReporterMock.h index 87595637..5bbd36cc 100644 --- a/unittests/mocks/PusVerificationReporterMock.h +++ b/unittests/mocks/PusVerificationReporterMock.h @@ -17,7 +17,7 @@ class PusVerificationReporterMock : public VerificationReporterIF { VerifFailureParams& getNextFailCallParams(); void popNextFailParams(); - ReturnValue_t sendSuccessReport(VerifSuccessParams params) override { return 0; } - ReturnValue_t sendFailureReport(VerifFailureParams params) override { return 0; } + ReturnValue_t sendSuccessReport(VerifSuccessParams params) override; + ReturnValue_t sendFailureReport(VerifFailureParams params) override; }; #endif // FSFW_TESTS_PUSVERIFICATIONREPORTERMOCK_H diff --git a/unittests/tmtcservices/testPsb.cpp b/unittests/tmtcservices/testPsb.cpp index 53fe763d..78ae775e 100644 --- a/unittests/tmtcservices/testPsb.cpp +++ b/unittests/tmtcservices/testPsb.cpp @@ -1,7 +1,9 @@ #include #include "fsfw/ipc/QueueFactory.h" +#include "fsfw/storagemanager/LocalPool.h" #include "mocks/AcceptsTmMock.h" +#include "mocks/CdsShortTimestamperMock.h" #include "mocks/MessageQueueMock.h" #include "mocks/PusServiceBaseMock.h" #include "mocks/PusVerificationReporterMock.h" @@ -11,13 +13,26 @@ TEST_CASE("Pus Service Base", "[pus-service-base]") { auto msgQueue = MessageQueueMock(1); auto tmReceiver = AcceptsTmMock(2); auto psbParams = PsbParams(0, 0x02, 17); + + LocalPool::LocalPoolConfig cfg = {{5, 32}, {2, 64}}; + LocalPool pool(objects::NO_OBJECT, cfg); + psbParams.verifReporter = &verificationReporter; psbParams.reqQueue = &msgQueue; psbParams.tmReceiver = &tmReceiver; + psbParams.tcPool = &pool; auto psb = PsbMock(psbParams); - store_address_t dummyId(1); - auto reqQueue = psb.getRequestQueue(); - TmTcMessage tmtcMsg(dummyId); + + store_address_t storeId; + TmTcMessage tmtcMsg; + + // Components to create valid PUS packets + auto packetId = PacketId(ccsds::PacketType::TC, true, 0x02); + auto spParams = + SpacePacketParams(packetId, PacketSeqCtrl(ccsds::SequenceFlags::UNSEGMENTED, 0x34), 0x00); + auto pusParams = PusTcParams(17, 1); + PusTcCreator creator(spParams, pusParams); + REQUIRE(psb.initialize() == HasReturnvaluesIF::RETURN_OK); SECTION("State") { @@ -25,8 +40,51 @@ TEST_CASE("Pus Service Base", "[pus-service-base]") { REQUIRE(psb.getObjectId() == 0); } - SECTION("Send Request") { + SECTION("Perform Service") { + REQUIRE(psb.performServiceCallCnt == 0); + REQUIRE(psb.performOperation(0) == retval::OK); + REQUIRE(psb.performServiceCallCnt == 1); + } + + SECTION("Send Request with Successful Handling") { + REQUIRE(psb.performServiceCallCnt == 0); + uint8_t* dataPtr; + REQUIRE(pool.getFreeElement(&storeId, creator.getSerializedSize(), &dataPtr) == retval::OK); + REQUIRE(creator.serializeBe(dataPtr, creator.getSerializedSize()) == retval::OK); + tmtcMsg.setStorageId(storeId); msgQueue.addReceivedMessage(tmtcMsg); REQUIRE(psb.performOperation(0) == retval::OK); + uint8_t subservice = 0; + REQUIRE(psb.getAndPopNextSubservice(subservice)); + REQUIRE(subservice == 1); + REQUIRE(psb.performServiceCallCnt == 1); + // PSB should take care of freeing the pool slot + REQUIRE(not pool.hasDataAtId(storeId)); + REQUIRE(verificationReporter.successCallCount() == 1); + REQUIRE(verificationReporter.failCallCount() == 0); + auto verifParams = verificationReporter.getNextSuccessCallParams(); + REQUIRE(verifParams.tcPacketId == creator.getPacketIdRaw()); + REQUIRE(verifParams.tcPsc == creator.getPacketSeqCtrlRaw()); } -} \ No newline at end of file + + SECTION("Send Request with Failed Handling") { + uint8_t* dataPtr; + REQUIRE(pool.getFreeElement(&storeId, creator.getSerializedSize(), &dataPtr) == retval::OK); + REQUIRE(creator.serializeBe(dataPtr, creator.getSerializedSize()) == retval::OK); + tmtcMsg.setStorageId(storeId); + msgQueue.addReceivedMessage(tmtcMsg); + psb.makeNextHandleReqCallFail(3); + REQUIRE(psb.performOperation(0) == retval::OK); + uint8_t subservice = 0; + REQUIRE(psb.getAndPopNextSubservice(subservice)); + REQUIRE(subservice == 1); + REQUIRE(psb.performServiceCallCnt == 1); + // PSB should take care of freeing the pool slot + REQUIRE(not pool.hasDataAtId(storeId)); + REQUIRE(verificationReporter.successCallCount() == 0); + REQUIRE(verificationReporter.failCallCount() == 1); + auto verifParams = verificationReporter.getNextFailCallParams(); + REQUIRE(verifParams.tcPacketId == creator.getPacketIdRaw()); + REQUIRE(verifParams.tcPsc == creator.getPacketSeqCtrlRaw()); + } +} -- 2.43.0 From 8bf0fb98851a890c81b935b94a406263b9cf4170 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Tue, 26 Jul 2022 18:46:28 +0200 Subject: [PATCH 071/108] test auto-initializers --- .../fsfwconfig/objects/FsfwFactory.cpp | 2 +- .../tmtcservices/CommandingServiceBase.cpp | 5 +- src/fsfw/tmtcservices/CommandingServiceBase.h | 4 +- src/fsfw/tmtcservices/PusServiceBase.cpp | 45 +++---- src/fsfw/tmtcservices/PusServiceBase.h | 26 ++--- src/fsfw/tmtcservices/TmSendHelper.cpp | 4 +- src/fsfw/tmtcservices/TmSendHelper.h | 2 +- unittests/CatchFactory.cpp | 4 +- unittests/mocks/AcceptsTmMock.cpp | 6 +- unittests/mocks/AcceptsTmMock.h | 4 +- unittests/mocks/CMakeLists.txt | 1 + unittests/mocks/DeviceHandlerMock.cpp | 2 +- unittests/mocks/PusDistributorMock.cpp | 12 ++ unittests/mocks/PusDistributorMock.h | 16 +++ unittests/mocks/PusServiceBaseMock.cpp | 12 ++ unittests/mocks/PusServiceBaseMock.h | 7 ++ unittests/tmtcservices/testPsb.cpp | 110 +++++++++++++++++- unittests/tmtcservices/testSendHelper.cpp | 5 +- 18 files changed, 215 insertions(+), 52 deletions(-) create mode 100644 unittests/mocks/PusDistributorMock.cpp create mode 100644 unittests/mocks/PusDistributorMock.h diff --git a/misc/defaultcfg/fsfwconfig/objects/FsfwFactory.cpp b/misc/defaultcfg/fsfwconfig/objects/FsfwFactory.cpp index 5aef4980..4670c7e7 100644 --- a/misc/defaultcfg/fsfwconfig/objects/FsfwFactory.cpp +++ b/misc/defaultcfg/fsfwconfig/objects/FsfwFactory.cpp @@ -36,7 +36,7 @@ void Factory::produceFsfwObjects(void) { void Factory::setStaticFrameworkObjectIds() { PusServiceBase::packetSource = objects::NO_OBJECT; - PusServiceBase::packetDestination = objects::NO_OBJECT; + PusServiceBase::PACKET_DESTINATION = objects::NO_OBJECT; CommandingServiceBase::defaultPacketSource = objects::NO_OBJECT; CommandingServiceBase::defaultPacketDestination = objects::NO_OBJECT; diff --git a/src/fsfw/tmtcservices/CommandingServiceBase.cpp b/src/fsfw/tmtcservices/CommandingServiceBase.cpp index 0815c838..214adbfa 100644 --- a/src/fsfw/tmtcservices/CommandingServiceBase.cpp +++ b/src/fsfw/tmtcservices/CommandingServiceBase.cpp @@ -104,9 +104,12 @@ ReturnValue_t CommandingServiceBase::initialize() { errReporter = ObjectManager::instance()->get(objects::INTERNAL_ERROR_REPORTER); if (errReporter != nullptr) { - tmSendHelper.setInternalErrorReporter(errReporter); + tmSendHelper.setInternalErrorReporter(*errReporter); } + } else { + tmSendHelper.setInternalErrorReporter(*errReporter); } + if (verificationReporter == nullptr) { verificationReporter = ObjectManager::instance()->get(objects::TC_VERIFICATOR); diff --git a/src/fsfw/tmtcservices/CommandingServiceBase.h b/src/fsfw/tmtcservices/CommandingServiceBase.h index 202dd862..20b7d992 100644 --- a/src/fsfw/tmtcservices/CommandingServiceBase.h +++ b/src/fsfw/tmtcservices/CommandingServiceBase.h @@ -18,7 +18,7 @@ namespace Factory { void setStaticFrameworkObjectIds(); -} +}; /** * @brief This class is the basis for all PUS Services, which have to @@ -38,7 +38,7 @@ class CommandingServiceBase : public SystemObject, public AcceptsTelecommandsIF, public ExecutableObjectIF, public HasReturnvaluesIF { - friend void(Factory::setStaticFrameworkObjectIds)(); + friend void Factory::setStaticFrameworkObjectIds(); public: // We could make this configurable via preprocessor and the FSFWConfig file. diff --git a/src/fsfw/tmtcservices/PusServiceBase.cpp b/src/fsfw/tmtcservices/PusServiceBase.cpp index c283d655..9390dd19 100644 --- a/src/fsfw/tmtcservices/PusServiceBase.cpp +++ b/src/fsfw/tmtcservices/PusServiceBase.cpp @@ -9,8 +9,8 @@ #include "fsfw/tmtcservices/TmTcMessage.h" #include "fsfw/tmtcservices/tcHelpers.h" -object_id_t PusServiceBase::packetDestination = 0; -object_id_t PusServiceBase::pusDistributor = 0; +object_id_t PusServiceBase::PACKET_DESTINATION = 0; +object_id_t PusServiceBase::PUS_DISTRIBUTOR = 0; PusServiceBase::PusServiceBase(PsbParams params) : SystemObject(params.objectId), psbParams(params) {} @@ -83,7 +83,12 @@ void PusServiceBase::handleRequestQueue() { uint16_t PusServiceBase::getIdentifier() { return psbParams.serviceId; } -MessageQueueId_t PusServiceBase::getRequestQueue() { return psbParams.reqQueue->getId(); } +MessageQueueId_t PusServiceBase::getRequestQueue() { + if (psbParams.reqQueue == nullptr) { + return MessageQueueIF::NO_QUEUE; + } + return psbParams.reqQueue->getId(); +} ReturnValue_t PusServiceBase::initialize() { ReturnValue_t result = SystemObject::initialize(); @@ -96,15 +101,16 @@ ReturnValue_t PusServiceBase::initialize() { } else { ownedQueue = false; } + if (psbParams.tmReceiver == nullptr) { - psbParams.tmReceiver = ObjectManager::instance()->get(packetDestination); + psbParams.tmReceiver = ObjectManager::instance()->get(PACKET_DESTINATION); if (psbParams.tmReceiver != nullptr) { psbParams.reqQueue->setDefaultDestination(psbParams.tmReceiver->getReportReceptionQueue()); } } - if (psbParams.pusDistributor != nullptr) { - psbParams.pusDistributor = ObjectManager::instance()->get(pusDistributor); + if (psbParams.pusDistributor == nullptr) { + psbParams.pusDistributor = ObjectManager::instance()->get(PUS_DISTRIBUTOR); if (psbParams.pusDistributor != nullptr) { registerService(*psbParams.pusDistributor); } @@ -127,17 +133,10 @@ ReturnValue_t PusServiceBase::initialize() { return HasReturnvaluesIF::RETURN_OK; } -ReturnValue_t PusServiceBase::initializeAfterTaskCreation() { - // If task parameters, for example task frequency are required, this - // function should be overriden and the system object task IF can - // be used to get those parameters. - return HasReturnvaluesIF::RETURN_OK; -} +void PusServiceBase::setTcPool(StorageManagerIF& tcPool) { psbParams.tcPool = &tcPool; } -void PusServiceBase::setCustomTcStore(StorageManagerIF* tcPool) { psbParams.tcPool = tcPool; } - -void PusServiceBase::setCustomErrorReporter(InternalErrorReporterIF* errReporter_) { - psbParams.errReporter = errReporter_; +void PusServiceBase::setErrorReporter(InternalErrorReporterIF& errReporter_) { + psbParams.errReporter = &errReporter_; } void PusServiceBase::initializeTmHelpers(TmSendHelper& tmSendHelper, TmStoreHelper& tmStoreHelper) { @@ -155,8 +154,10 @@ void PusServiceBase::initializeTmSendHelper(TmSendHelper& tmSendHelper) { psbParams.errReporter = ObjectManager::instance()->get(objects::INTERNAL_ERROR_REPORTER); if (psbParams.errReporter != nullptr) { - tmSendHelper.setInternalErrorReporter(psbParams.errReporter); + tmSendHelper.setInternalErrorReporter(*psbParams.errReporter); } + } else { + tmSendHelper.setInternalErrorReporter(*psbParams.errReporter); } } @@ -164,16 +165,16 @@ void PusServiceBase::initializeTmStoreHelper(TmStoreHelper& tmStoreHelper) const tmStoreHelper.setApid(psbParams.apid); } -void PusServiceBase::setVerificationReporter(VerificationReporterIF* reporter) { - psbParams.verifReporter = reporter; +void PusServiceBase::setVerificationReporter(VerificationReporterIF& reporter) { + psbParams.verifReporter = &reporter; } ReturnValue_t PusServiceBase::registerService(PUSDistributorIF& distributor) { return distributor.registerService(this); } -void PusServiceBase::setTmReceiver(AcceptsTelemetryIF* tmReceiver_) { - psbParams.tmReceiver = tmReceiver_; +void PusServiceBase::setTmReceiver(AcceptsTelemetryIF& tmReceiver_) { + psbParams.tmReceiver = &tmReceiver_; } -void PusServiceBase::setRequestQueue(MessageQueueIF* reqQueue) { psbParams.reqQueue = reqQueue; } +void PusServiceBase::setRequestQueue(MessageQueueIF& reqQueue) { psbParams.reqQueue = &reqQueue; } diff --git a/src/fsfw/tmtcservices/PusServiceBase.h b/src/fsfw/tmtcservices/PusServiceBase.h index 1c1c417d..9c75870a 100644 --- a/src/fsfw/tmtcservices/PusServiceBase.h +++ b/src/fsfw/tmtcservices/PusServiceBase.h @@ -14,10 +14,6 @@ #include "fsfw/tasks/ExecutableObjectIF.h" #include "fsfw/tcdistribution/PUSDistributorIF.h" -namespace Factory { -void setStaticFrameworkObjectIds(); -} - class StorageManagerIF; /** @@ -71,6 +67,10 @@ struct PsbParams { PUSDistributorIF* pusDistributor = nullptr; }; +namespace Factory { +void setStaticFrameworkObjectIds(); +} + /** * @defgroup pus_services PUS Service Framework * These group contains all implementations of PUS Services in the OBSW. @@ -93,7 +93,7 @@ class PusServiceBase : public ExecutableObjectIF, public AcceptsTelecommandsIF, public SystemObject, public HasReturnvaluesIF { - friend void(Factory::setStaticFrameworkObjectIds)(); + friend void Factory::setStaticFrameworkObjectIds(); public: /** @@ -121,11 +121,11 @@ class PusServiceBase : public ExecutableObjectIF, * function will create one * @param reqQueue */ - void setRequestQueue(MessageQueueIF* reqQueue); - void setTmReceiver(AcceptsTelemetryIF* tmReceiver); - void setCustomTcStore(StorageManagerIF* tcStore); - void setVerificationReporter(VerificationReporterIF* reporter); - void setCustomErrorReporter(InternalErrorReporterIF* errReporter); + void setRequestQueue(MessageQueueIF& reqQueue); + void setTmReceiver(AcceptsTelemetryIF& tmReceiver); + void setTcPool(StorageManagerIF& tcStore); + void setVerificationReporter(VerificationReporterIF& reporter); + void setErrorReporter(InternalErrorReporterIF& errReporter); /** * Helper methods if the implementing class wants to send telemetry @@ -190,7 +190,6 @@ class PusServiceBase : public ExecutableObjectIF, ReturnValue_t initialize() override; void setTaskIF(PeriodicTaskIF* taskHandle) override; - ReturnValue_t initializeAfterTaskCreation() override; protected: /** @@ -215,9 +214,8 @@ class PusServiceBase : public ExecutableObjectIF, PusTcReader currentPacket; bool ownedQueue = true; - static object_id_t packetDestination; - static object_id_t pusDistributor; - VerifSuccessParams successParams; + static object_id_t PACKET_DESTINATION; + static object_id_t PUS_DISTRIBUTOR; private: void handleRequestQueue(); diff --git a/src/fsfw/tmtcservices/TmSendHelper.cpp b/src/fsfw/tmtcservices/TmSendHelper.cpp index 0b9d854c..ddbb86ba 100644 --- a/src/fsfw/tmtcservices/TmSendHelper.cpp +++ b/src/fsfw/tmtcservices/TmSendHelper.cpp @@ -30,8 +30,8 @@ ReturnValue_t TmSendHelper::sendPacket(const store_address_t &storeId) { void TmSendHelper::setDefaultDestination(MessageQueueId_t msgDest) { defaultDest = msgDest; } -void TmSendHelper::setInternalErrorReporter(InternalErrorReporterIF *reporter) { - errReporter = reporter; +void TmSendHelper::setInternalErrorReporter(InternalErrorReporterIF &reporter) { + errReporter = &reporter; } void TmSendHelper::setMsgQueue(MessageQueueIF &queue_) { queue = &queue_; } diff --git a/src/fsfw/tmtcservices/TmSendHelper.h b/src/fsfw/tmtcservices/TmSendHelper.h index 244e7900..a9feab75 100644 --- a/src/fsfw/tmtcservices/TmSendHelper.h +++ b/src/fsfw/tmtcservices/TmSendHelper.h @@ -23,7 +23,7 @@ class TmSendHelper { [[nodiscard]] bool areFaultsIgnored() const; void ignoreFaults(); void dontIgnoreFaults(); - void setInternalErrorReporter(InternalErrorReporterIF* reporter); + void setInternalErrorReporter(InternalErrorReporterIF& reporter); [[nodiscard]] InternalErrorReporterIF* getInternalErrorReporter() const; ReturnValue_t sendPacket(MessageQueueId_t dest, const store_address_t& storeId); ReturnValue_t sendPacket(const store_address_t& storeId); diff --git a/unittests/CatchFactory.cpp b/unittests/CatchFactory.cpp index 1d10c582..d1d3ea1c 100644 --- a/unittests/CatchFactory.cpp +++ b/unittests/CatchFactory.cpp @@ -54,7 +54,7 @@ void Factory::produceFrameworkObjects(void* args) { // like this. Instead, this should be more like a general struct containing all important // object IDs which are then explicitely passed in the object constructor void Factory::setStaticFrameworkObjectIds() { - PusServiceBase::packetDestination = objects::NO_OBJECT; + PusServiceBase::PACKET_DESTINATION = objects::NO_OBJECT; CommandingServiceBase::defaultPacketSource = objects::NO_OBJECT; CommandingServiceBase::defaultPacketDestination = objects::NO_OBJECT; @@ -62,9 +62,7 @@ void Factory::setStaticFrameworkObjectIds() { DeviceHandlerBase::powerSwitcherId = objects::NO_OBJECT; DeviceHandlerBase::rawDataReceiverId = objects::NO_OBJECT; - // TODO: Incredibly ugly, get rid of it LocalDataPoolManager::defaultHkDestination = objects::NO_OBJECT; - DeviceHandlerFailureIsolation::powerConfirmationId = objects::NO_OBJECT; } diff --git a/unittests/mocks/AcceptsTmMock.cpp b/unittests/mocks/AcceptsTmMock.cpp index 9142308d..5b1e0d05 100644 --- a/unittests/mocks/AcceptsTmMock.cpp +++ b/unittests/mocks/AcceptsTmMock.cpp @@ -1,6 +1,10 @@ #include "AcceptsTmMock.h" -AcceptsTmMock::AcceptsTmMock(MessageQueueId_t queueToReturn) : returnedQueue(queueToReturn) {} +AcceptsTmMock::AcceptsTmMock(object_id_t registeredId, MessageQueueId_t queueToReturn) + : SystemObject(registeredId), returnedQueue(queueToReturn) {} + +AcceptsTmMock::AcceptsTmMock(MessageQueueId_t queueToReturn) + : SystemObject(objects::NO_OBJECT, false), returnedQueue(queueToReturn) {} MessageQueueId_t AcceptsTmMock::getReportReceptionQueue(uint8_t virtualChannel) { return returnedQueue; diff --git a/unittests/mocks/AcceptsTmMock.h b/unittests/mocks/AcceptsTmMock.h index b0ccc9a7..a9422eb4 100644 --- a/unittests/mocks/AcceptsTmMock.h +++ b/unittests/mocks/AcceptsTmMock.h @@ -1,10 +1,12 @@ #ifndef FSFW_TESTS_ACCEPTSTMMOCK_H #define FSFW_TESTS_ACCEPTSTMMOCK_H +#include "fsfw/objectmanager/SystemObject.h" #include "fsfw/tmtcservices/AcceptsTelemetryIF.h" -class AcceptsTmMock : public AcceptsTelemetryIF { +class AcceptsTmMock : public SystemObject, public AcceptsTelemetryIF { public: + AcceptsTmMock(object_id_t registeredId, MessageQueueId_t queueToReturn); explicit AcceptsTmMock(MessageQueueId_t queueToReturn); MessageQueueId_t getReportReceptionQueue(uint8_t virtualChannel) override; diff --git a/unittests/mocks/CMakeLists.txt b/unittests/mocks/CMakeLists.txt index 5bb37db4..f3b50f62 100644 --- a/unittests/mocks/CMakeLists.txt +++ b/unittests/mocks/CMakeLists.txt @@ -10,4 +10,5 @@ target_sources(${FSFW_TEST_TGT} PRIVATE PusVerificationReporterMock.cpp PusServiceBaseMock.cpp AcceptsTmMock.cpp + PusDistributorMock.cpp ) diff --git a/unittests/mocks/DeviceHandlerMock.cpp b/unittests/mocks/DeviceHandlerMock.cpp index ea30ff6a..1398c8e9 100644 --- a/unittests/mocks/DeviceHandlerMock.cpp +++ b/unittests/mocks/DeviceHandlerMock.cpp @@ -8,7 +8,7 @@ DeviceHandlerMock::DeviceHandlerMock(object_id_t objectId, object_id_t deviceCom mode = MODE_ON; } -DeviceHandlerMock::~DeviceHandlerMock() {} +DeviceHandlerMock::~DeviceHandlerMock() = default; void DeviceHandlerMock::doStartUp() { setMode(_MODE_TO_ON); } diff --git a/unittests/mocks/PusDistributorMock.cpp b/unittests/mocks/PusDistributorMock.cpp new file mode 100644 index 00000000..cb9aed32 --- /dev/null +++ b/unittests/mocks/PusDistributorMock.cpp @@ -0,0 +1,12 @@ +#include "PusDistributorMock.h" + +PusDistributorMock::PusDistributorMock() : SystemObject(objects::NO_OBJECT, false) {} + +PusDistributorMock::PusDistributorMock(object_id_t registeredId) + : SystemObject(registeredId, true) {} + +ReturnValue_t PusDistributorMock::registerService(AcceptsTelecommandsIF *service) { + registerCallCount++; + lastServiceArg = service; + return HasReturnvaluesIF::RETURN_OK; +} diff --git a/unittests/mocks/PusDistributorMock.h b/unittests/mocks/PusDistributorMock.h new file mode 100644 index 00000000..d5c7d96f --- /dev/null +++ b/unittests/mocks/PusDistributorMock.h @@ -0,0 +1,16 @@ +#ifndef FSFW_TESTS_PUSDISTRIBUTORMOCK_H +#define FSFW_TESTS_PUSDISTRIBUTORMOCK_H + +#include "fsfw/objectmanager/SystemObject.h" +#include "fsfw/tcdistribution/PUSDistributorIF.h" + +class PusDistributorMock : public SystemObject, public PUSDistributorIF { + public: + PusDistributorMock(); + explicit PusDistributorMock(object_id_t registeredId); + unsigned int registerCallCount = 0; + AcceptsTelecommandsIF* lastServiceArg = nullptr; + ReturnValue_t registerService(AcceptsTelecommandsIF* service) override; +}; + +#endif // FSFW_TESTS_PUSDISTRIBUTORMOCK_H diff --git a/unittests/mocks/PusServiceBaseMock.cpp b/unittests/mocks/PusServiceBaseMock.cpp index 21f6a360..5c20f0a1 100644 --- a/unittests/mocks/PusServiceBaseMock.cpp +++ b/unittests/mocks/PusServiceBaseMock.cpp @@ -39,3 +39,15 @@ bool PsbMock::getAndPopNextSubservice(uint8_t& subservice) { subserviceQueue.pop(); return true; } + +PsbParams& PsbMock::getParams() { return psbParams; } + +void PsbMock::setStaticPusDistributor(object_id_t pusDistributor) { + PUS_DISTRIBUTOR = pusDistributor; +} + +object_id_t PsbMock::getStaticPusDistributor() { return PUS_DISTRIBUTOR; } + +void PsbMock::setStaticTmDest(object_id_t tmDest) { PACKET_DESTINATION = tmDest; } + +object_id_t PsbMock::getStaticTmDest() { return PACKET_DESTINATION; } diff --git a/unittests/mocks/PusServiceBaseMock.h b/unittests/mocks/PusServiceBaseMock.h index 31ac43d3..0aa6b406 100644 --- a/unittests/mocks/PusServiceBaseMock.h +++ b/unittests/mocks/PusServiceBaseMock.h @@ -12,6 +12,13 @@ class PsbMock : public PusServiceBase { std::queue subserviceQueue; unsigned int performServiceCallCnt = 0; + static void setStaticPusDistributor(object_id_t pusDistributor); + static object_id_t getStaticPusDistributor(); + static void setStaticTmDest(object_id_t tmDest); + static object_id_t getStaticTmDest(); + + PsbParams& getParams(); + std::pair handleReqFailPair; std::pair performServiceFailPair; ReturnValue_t handleRequest(uint8_t subservice) override; diff --git a/unittests/tmtcservices/testPsb.cpp b/unittests/tmtcservices/testPsb.cpp index 78ae775e..53b84b3c 100644 --- a/unittests/tmtcservices/testPsb.cpp +++ b/unittests/tmtcservices/testPsb.cpp @@ -4,15 +4,18 @@ #include "fsfw/storagemanager/LocalPool.h" #include "mocks/AcceptsTmMock.h" #include "mocks/CdsShortTimestamperMock.h" +#include "mocks/InternalErrorReporterMock.h" #include "mocks/MessageQueueMock.h" +#include "mocks/PusDistributorMock.h" #include "mocks/PusServiceBaseMock.h" #include "mocks/PusVerificationReporterMock.h" TEST_CASE("Pus Service Base", "[pus-service-base]") { + uint16_t apid = 2; auto verificationReporter = PusVerificationReporterMock(); auto msgQueue = MessageQueueMock(1); auto tmReceiver = AcceptsTmMock(2); - auto psbParams = PsbParams(0, 0x02, 17); + auto psbParams = PsbParams(0, apid, 17); LocalPool::LocalPoolConfig cfg = {{5, 32}, {2, 64}}; LocalPool pool(objects::NO_OBJECT, cfg); @@ -38,6 +41,9 @@ TEST_CASE("Pus Service Base", "[pus-service-base]") { SECTION("State") { REQUIRE(psb.getIdentifier() == 17); REQUIRE(psb.getObjectId() == 0); + REQUIRE(psb.getRequestQueue() == msgQueue.getId()); + auto psbParamsLocal = psb.getParams(); + REQUIRE(psbParamsLocal.errReporter == nullptr); } SECTION("Perform Service") { @@ -87,4 +93,106 @@ TEST_CASE("Pus Service Base", "[pus-service-base]") { REQUIRE(verifParams.tcPacketId == creator.getPacketIdRaw()); REQUIRE(verifParams.tcPsc == creator.getPacketSeqCtrlRaw()); } + + SECTION("Invalid Packet Sent") { + tmtcMsg.setStorageId(store_address_t::invalid()); + msgQueue.addReceivedMessage(tmtcMsg); + REQUIRE(psb.performOperation(0) == retval::OK); + REQUIRE(verificationReporter.failCallCount() == 1); + auto verifParams = verificationReporter.getNextFailCallParams(); + REQUIRE(verifParams.tcPacketId == 0); + REQUIRE(verifParams.tcPsc == 0); + } + + SECTION("Set Verif Reporter") { + auto verificationReporter2 = PusVerificationReporterMock(); + psb.setVerificationReporter(verificationReporter2); + auto& p = psb.getParams(); + REQUIRE(p.verifReporter == &verificationReporter2); + } + + SECTION("Set Request Queue") { + auto msgQueueMock = MessageQueueMock(2); + psb.setRequestQueue(msgQueueMock); + auto& p = psb.getParams(); + REQUIRE(p.reqQueue == &msgQueueMock); + } + + SECTION("Set TM Receiver") { + auto tmReceiver2 = AcceptsTmMock(3); + psb.setTmReceiver(tmReceiver2); + auto& p = psb.getParams(); + REQUIRE(p.tmReceiver == &tmReceiver2); + } + + SECTION("Set TC Store") { + LocalPool tcStore2(5, cfg); + psb.setTcPool(tcStore2); + auto& p = psb.getParams(); + REQUIRE(p.tcPool == &tcStore2); + } + + SECTION("Set error reporter") { + auto errReporter = InternalErrorReporterMock(); + psb.setErrorReporter(errReporter); + auto& p = psb.getParams(); + REQUIRE(p.errReporter == &errReporter); + } + SECTION("Owner Queue") { + // This will cause the initialize function to create a new owner queue + psbParams.reqQueue = nullptr; + psbParams.objectId = 1; + auto mockWithOwnerQueue = PsbMock(psbParams); + REQUIRE(mockWithOwnerQueue.getRequestQueue() == MessageQueueIF::NO_QUEUE); + REQUIRE(mockWithOwnerQueue.initialize() == retval::OK); + REQUIRE(mockWithOwnerQueue.getRequestQueue() != MessageQueueIF::NO_QUEUE); + } + + SECTION("TM Store Helper Initializer") { + TmStoreHelper storeHelper(0); + psb.initializeTmStoreHelper(storeHelper); + REQUIRE(storeHelper.getApid() == apid); + } + + SECTION("TM Send Helper Initializer") { + TmSendHelper sendHelper; + psb.initializeTmSendHelper(sendHelper); + REQUIRE(sendHelper.getMsgQueue() == &msgQueue); + REQUIRE(sendHelper.getDefaultDestination() == msgQueue.getDefaultDestination()); + } + + SECTION("TM Send Helper Initializer With Error Reporter") { + TmSendHelper sendHelper; + auto errReporter = InternalErrorReporterMock(); + psb.setErrorReporter(errReporter); + psb.initializeTmSendHelper(sendHelper); + REQUIRE(sendHelper.getMsgQueue() == &msgQueue); + REQUIRE(sendHelper.getDefaultDestination() == msgQueue.getDefaultDestination()); + REQUIRE(sendHelper.getInternalErrorReporter() == &errReporter); + } + + SECTION("Auto Initialize PUS Distributor") { + psbParams.objectId = 1; + object_id_t distributorId = 3; + auto psb2 = PsbMock(psbParams); + auto pusDistrib = PusDistributorMock(distributorId); + PsbMock::setStaticPusDistributor(distributorId); + REQUIRE(PsbMock::getStaticPusDistributor() == distributorId); + REQUIRE(psb2.initialize() == retval::OK); + REQUIRE(pusDistrib.registerCallCount == 1); + REQUIRE(pusDistrib.lastServiceArg == &psb2); + } + + SECTION("Auto Initialize Packet Destination") { + psbParams.tmReceiver = nullptr; + psbParams.objectId = 1; + object_id_t destId = 3; + auto psb2 = PsbMock(psbParams); + auto packetDest = AcceptsTmMock(destId, 2); + PsbMock::setStaticTmDest(destId); + REQUIRE(PsbMock::getStaticTmDest() == destId); + REQUIRE(psb2.initialize() == retval::OK); + auto& p = psb2.getParams(); + REQUIRE(p.tmReceiver == &packetDest); + } } diff --git a/unittests/tmtcservices/testSendHelper.cpp b/unittests/tmtcservices/testSendHelper.cpp index 82adc04b..b857776b 100644 --- a/unittests/tmtcservices/testSendHelper.cpp +++ b/unittests/tmtcservices/testSendHelper.cpp @@ -33,8 +33,9 @@ TEST_CASE("TM Send Helper", "[tm-send-helper]") { REQUIRE(sendHelper.getDefaultDestination() == destId); sendHelper.setDefaultDestination(destId + 1); REQUIRE(sendHelper.getDefaultDestination() == destId + 1); - sendHelper.setInternalErrorReporter(nullptr); - REQUIRE(sendHelper.getInternalErrorReporter() == nullptr); + auto errReporter2 = InternalErrorReporterMock(); + sendHelper.setInternalErrorReporter(errReporter2); + REQUIRE(sendHelper.getInternalErrorReporter() == &errReporter2); } SECTION("Default CTOR") { -- 2.43.0 From 152c01b2ec18c94cf072065e5313aa92eb9ee7c0 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Tue, 26 Jul 2022 18:58:36 +0200 Subject: [PATCH 072/108] psb unittests almost complete --- .../tmtcservices/VerificationReporter.cpp | 1 + src/fsfw/tmtcservices/VerificationReporter.h | 9 ++++++- .../mocks/PusVerificationReporterMock.cpp | 8 +++++++ unittests/mocks/PusVerificationReporterMock.h | 6 +++-- unittests/tmtcservices/testPsb.cpp | 24 +++++++++++++++++++ 5 files changed, 45 insertions(+), 3 deletions(-) diff --git a/src/fsfw/tmtcservices/VerificationReporter.cpp b/src/fsfw/tmtcservices/VerificationReporter.cpp index 25d7cd4a..9c38b3a7 100644 --- a/src/fsfw/tmtcservices/VerificationReporter.cpp +++ b/src/fsfw/tmtcservices/VerificationReporter.cpp @@ -5,6 +5,7 @@ #include "fsfw/tmtcservices/PusVerificationReport.h" object_id_t VerificationReporter::DEFAULT_RECEIVER = objects::PUS_SERVICE_1_VERIFICATION; +object_id_t VerificationReporter::DEFAULT_REPORTER = objects::TC_VERIFICATOR; VerificationReporter::VerificationReporter(AcceptsVerifyMessageIF* receiver, object_id_t objectId) : SystemObject(objectId) { diff --git a/src/fsfw/tmtcservices/VerificationReporter.h b/src/fsfw/tmtcservices/VerificationReporter.h index 8b224808..78c60962 100644 --- a/src/fsfw/tmtcservices/VerificationReporter.h +++ b/src/fsfw/tmtcservices/VerificationReporter.h @@ -8,6 +8,10 @@ #include "fsfw/tmtcpacket/pus/tc/PusTcCreator.h" #include "fsfw/tmtcservices/AcceptsVerifyMessageIF.h" +namespace Factory { +void setStaticFrameworkObjectIds(); +} + /** * @brief This helper object is used to forward verification messages * which are generated by the Flight Software Framework. @@ -20,9 +24,11 @@ * */ class VerificationReporter : public SystemObject, public VerificationReporterIF { + friend void Factory::setStaticFrameworkObjectIds(); + public: explicit VerificationReporter(AcceptsVerifyMessageIF* receiver, - object_id_t objectId = objects::TC_VERIFICATOR); + object_id_t objectId = DEFAULT_REPORTER); ~VerificationReporter() override; void setReceiver(AcceptsVerifyMessageIF& receiver); @@ -33,6 +39,7 @@ class VerificationReporter : public SystemObject, public VerificationReporterIF ReturnValue_t sendFailureReport(VerifFailureParams params) override; + static object_id_t DEFAULT_REPORTER; static object_id_t DEFAULT_RECEIVER; ReturnValue_t initialize() override; diff --git a/unittests/mocks/PusVerificationReporterMock.cpp b/unittests/mocks/PusVerificationReporterMock.cpp index 87b37a5a..c811d38e 100644 --- a/unittests/mocks/PusVerificationReporterMock.cpp +++ b/unittests/mocks/PusVerificationReporterMock.cpp @@ -1,5 +1,13 @@ #include "PusVerificationReporterMock.h" +#include "fsfw/objectmanager/frameworkObjects.h" + +PusVerificationReporterMock::PusVerificationReporterMock() + : SystemObject(objects::NO_OBJECT, false) {} + +PusVerificationReporterMock::PusVerificationReporterMock(object_id_t registeredId) + : SystemObject(registeredId) {} + size_t PusVerificationReporterMock::successCallCount() const { return successParams.size(); } size_t PusVerificationReporterMock::failCallCount() const { return failParams.size(); } diff --git a/unittests/mocks/PusVerificationReporterMock.h b/unittests/mocks/PusVerificationReporterMock.h index 5bbd36cc..dedfd30e 100644 --- a/unittests/mocks/PusVerificationReporterMock.h +++ b/unittests/mocks/PusVerificationReporterMock.h @@ -3,13 +3,15 @@ #include +#include "fsfw/objectmanager/SystemObject.h" #include "fsfw/tmtcservices/VerificationReporterIF.h" -class PusVerificationReporterMock : public VerificationReporterIF { +class PusVerificationReporterMock : public SystemObject, public VerificationReporterIF { public: std::queue successParams; std::queue failParams; - + PusVerificationReporterMock(); + explicit PusVerificationReporterMock(object_id_t registeredId); [[nodiscard]] size_t successCallCount() const; VerifSuccessParams& getNextSuccessCallParams(); void popNextSuccessParams(); diff --git a/unittests/tmtcservices/testPsb.cpp b/unittests/tmtcservices/testPsb.cpp index 53b84b3c..ea1991f0 100644 --- a/unittests/tmtcservices/testPsb.cpp +++ b/unittests/tmtcservices/testPsb.cpp @@ -161,6 +161,15 @@ TEST_CASE("Pus Service Base", "[pus-service-base]") { REQUIRE(sendHelper.getDefaultDestination() == msgQueue.getDefaultDestination()); } + SECTION("TM Store And Send Helper Initializer") { + TmStoreHelper storeHelper(0); + TmSendHelper sendHelper; + psb.initializeTmHelpers(sendHelper, storeHelper); + REQUIRE(sendHelper.getMsgQueue() == &msgQueue); + REQUIRE(sendHelper.getDefaultDestination() == msgQueue.getDefaultDestination()); + REQUIRE(storeHelper.getApid() == apid); + } + SECTION("TM Send Helper Initializer With Error Reporter") { TmSendHelper sendHelper; auto errReporter = InternalErrorReporterMock(); @@ -195,4 +204,19 @@ TEST_CASE("Pus Service Base", "[pus-service-base]") { auto& p = psb2.getParams(); REQUIRE(p.tmReceiver == &packetDest); } + + SECTION("Auto Initialize Verification Reporter") { + psbParams.verifReporter = nullptr; + psbParams.objectId = 1; + object_id_t reporterId = objects::TC_VERIFICATOR; + PusVerificationReporterMock otherReporter(reporterId); + auto psb2 = PsbMock(psbParams); + REQUIRE(psb2.initialize() == retval::OK); + auto& p = psb2.getParams(); + REQUIRE(p.verifReporter == &otherReporter); + } + + SECTION("Auto Initialize TC Pool") {} + + SECTION("Invalid Verification Reporter") {} } -- 2.43.0 From 681738dcc63f3d2d92eb24476b0bc7908c3bb582 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Tue, 26 Jul 2022 19:08:12 +0200 Subject: [PATCH 073/108] PSB unittests complete --- unittests/CatchFactory.cpp | 5 ----- unittests/tmtcservices/testPsb.cpp | 25 +++++++++++++++++++++++-- 2 files changed, 23 insertions(+), 7 deletions(-) diff --git a/unittests/CatchFactory.cpp b/unittests/CatchFactory.cpp index d1d3ea1c..0d855cb3 100644 --- a/unittests/CatchFactory.cpp +++ b/unittests/CatchFactory.cpp @@ -34,11 +34,6 @@ void Factory::produceFrameworkObjects(void* args) { new HealthTable(objects::HEALTH_TABLE); new InternalErrorReporter(objects::INTERNAL_ERROR_REPORTER); - { - PoolManager::LocalPoolConfig poolCfg = {{100, 16}, {50, 32}, {25, 64}, {15, 128}, {5, 1024}}; - new PoolManager(objects::TC_STORE, poolCfg); - } - { PoolManager::LocalPoolConfig poolCfg = {{100, 16}, {50, 32}, {25, 64}, {15, 128}, {5, 1024}}; new PoolManager(objects::TM_STORE, poolCfg); diff --git a/unittests/tmtcservices/testPsb.cpp b/unittests/tmtcservices/testPsb.cpp index ea1991f0..e434607f 100644 --- a/unittests/tmtcservices/testPsb.cpp +++ b/unittests/tmtcservices/testPsb.cpp @@ -2,6 +2,7 @@ #include "fsfw/ipc/QueueFactory.h" #include "fsfw/storagemanager/LocalPool.h" +#include "fsfw/storagemanager/PoolManager.h" #include "mocks/AcceptsTmMock.h" #include "mocks/CdsShortTimestamperMock.h" #include "mocks/InternalErrorReporterMock.h" @@ -216,7 +217,27 @@ TEST_CASE("Pus Service Base", "[pus-service-base]") { REQUIRE(p.verifReporter == &otherReporter); } - SECTION("Auto Initialize TC Pool") {} + SECTION("Auto Initialize TC Pool") { + PoolManager tcStoreGlobal(objects::TC_STORE, cfg); + psbParams.tcPool = nullptr; + psbParams.objectId = 1; + auto psb2 = PsbMock(psbParams); + REQUIRE(psb2.initialize() == retval::OK); + auto& p = psb2.getParams(); + REQUIRE(p.tcPool == &tcStoreGlobal); + } - SECTION("Invalid Verification Reporter") {} + SECTION("Invalid Verification Reporter") { + psbParams.verifReporter = nullptr; + psbParams.objectId = 1; + auto psb2 = PsbMock(psbParams); + REQUIRE(psb2.initialize() == ObjectManagerIF::CHILD_INIT_FAILED); + } + + SECTION("Invalid TC Store") { + psbParams.tcPool = nullptr; + psbParams.objectId = 1; + auto psb2 = PsbMock(psbParams); + REQUIRE(psb2.initialize() == ObjectManagerIF::CHILD_INIT_FAILED); + } } -- 2.43.0 From 9eb652e585c3eaf88c8e9a7778f3cfcd00562c51 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Wed, 27 Jul 2022 10:49:49 +0200 Subject: [PATCH 074/108] some printout fixes --- src/fsfw/tcdistribution/PusDistributor.cpp | 11 ++++++----- src/fsfw/tmtcservices/PusServiceBase.cpp | 6 +++--- 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/src/fsfw/tcdistribution/PusDistributor.cpp b/src/fsfw/tcdistribution/PusDistributor.cpp index 1cef2b9f..981fca1c 100644 --- a/src/fsfw/tcdistribution/PusDistributor.cpp +++ b/src/fsfw/tcdistribution/PusDistributor.cpp @@ -1,5 +1,6 @@ #include "fsfw/tcdistribution/PusDistributor.h" +#include "definitions.h" #include "fsfw/objectmanager/ObjectManager.h" #include "fsfw/serviceinterface/ServiceInterface.h" #include "fsfw/tcdistribution/CCSDSDistributorIF.h" @@ -42,15 +43,15 @@ PusDistributor::TcMqMapIter PusDistributor::selectDestination() { if (tcStatus != HasReturnvaluesIF::RETURN_OK) { #if FSFW_VERBOSE_LEVEL >= 1 const char* keyword = "unnamed error"; - if (tcStatus == TcPacketCheckPUS::INCORRECT_CHECKSUM) { + if (tcStatus == tcdistrib::INCORRECT_CHECKSUM) { keyword = "checksum"; - } else if (tcStatus == TcPacketCheckPUS::INCORRECT_PRIMARY_HEADER) { + } else if (tcStatus == tcdistrib::INCORRECT_PRIMARY_HEADER) { keyword = "incorrect primary header"; - } else if (tcStatus == TcPacketCheckPUS::ILLEGAL_APID) { + } else if (tcStatus == tcdistrib::INVALID_APID) { keyword = "illegal APID"; - } else if (tcStatus == TcPacketCheckPUS::INCORRECT_SECONDARY_HEADER) { + } else if (tcStatus == tcdistrib::INCORRECT_SECONDARY_HEADER) { keyword = "incorrect secondary header"; - } else if (tcStatus == TcPacketCheckPUS::INCOMPLETE_PACKET) { + } else if (tcStatus == tcdistrib::INCOMPLETE_PACKET) { keyword = "incomplete packet"; } #if FSFW_CPP_OSTREAM_ENABLED == 1 diff --git a/src/fsfw/tmtcservices/PusServiceBase.cpp b/src/fsfw/tmtcservices/PusServiceBase.cpp index 9390dd19..97f018e5 100644 --- a/src/fsfw/tmtcservices/PusServiceBase.cpp +++ b/src/fsfw/tmtcservices/PusServiceBase.cpp @@ -26,8 +26,8 @@ ReturnValue_t PusServiceBase::performOperation(uint8_t opCode) { ReturnValue_t result = performService(); if (result != RETURN_OK) { #if FSFW_CPP_OSTREAM_ENABLED == 1 - sif::error << "PusService " << (uint16_t)this->serviceId << ": performService returned with " - << (int16_t)result << std::endl; + sif::error << "PusService " << psbParams.serviceId << ": performService returned with " + << static_cast(result) << std::endl; #endif return RETURN_FAILED; } @@ -45,7 +45,7 @@ void PusServiceBase::handleRequestQueue() { break; } else if (status != HasReturnvaluesIF::RETURN_OK) { #if FSFW_CPP_OSTREAM_ENABLED == 1 - sif::error << "PusServiceBase::performOperation: Service " << this->serviceId + sif::error << "PusServiceBase::performOperation: Service " << psbParams.serviceId << ": Error receiving packet. Code: " << std::hex << status << std::dec << std::endl; #else -- 2.43.0 From 18ee2ab9035ac2ab90da0bc2ab8fdef5b6d381df Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Wed, 27 Jul 2022 11:26:47 +0200 Subject: [PATCH 075/108] example compiles again --- .../ProvidesDataPoolSubscriptionIF.h | 15 ++++++++++ src/fsfw/pus/Service11TelecommandScheduling.h | 5 ++-- .../pus/Service11TelecommandScheduling.tpp | 28 ++++++++----------- src/fsfw/returnvalues/HasReturnvaluesIF.h | 3 +- src/fsfw/tcdistribution/PusDistributor.cpp | 10 +++++-- src/fsfw/tcdistribution/PusDistributor.h | 4 +-- src/fsfw/tmtcpacket/ccsds/header.cpp | 7 ++++- src/fsfw/tmtcpacket/ccsds/header.h | 1 + src/fsfw/tmtcpacket/pus/tm.h | 1 + src/fsfw/tmtcpacket/pus/tm/CMakeLists.txt | 2 +- src/fsfw/tmtcpacket/pus/tm/PusTmCreator.cpp | 11 ++++---- src/fsfw/tmtcpacket/pus/tm/PusTmCreator.h | 2 +- src/fsfw/tmtcpacket/pus/tm/PusTmReader.h | 10 ++++--- src/fsfw/tmtcpacket/pus/tm/PusTmZcWriter.cpp | 18 ++++++++++++ src/fsfw/tmtcpacket/pus/tm/PusTmZcWriter.h | 14 ++++++++++ src/fsfw/tmtcservices/PusServiceBase.cpp | 2 +- .../integration/devices/TestDeviceHandler.cpp | 2 +- 17 files changed, 95 insertions(+), 40 deletions(-) create mode 100644 src/fsfw/tmtcpacket/pus/tm/PusTmZcWriter.cpp create mode 100644 src/fsfw/tmtcpacket/pus/tm/PusTmZcWriter.h diff --git a/src/fsfw/datapoollocal/ProvidesDataPoolSubscriptionIF.h b/src/fsfw/datapoollocal/ProvidesDataPoolSubscriptionIF.h index e1aca321..3001ea10 100644 --- a/src/fsfw/datapoollocal/ProvidesDataPoolSubscriptionIF.h +++ b/src/fsfw/datapoollocal/ProvidesDataPoolSubscriptionIF.h @@ -70,6 +70,15 @@ class ProvidesDataPoolSubscriptionIF { virtual ReturnValue_t subscribeForDiagPeriodicPacket( subdp::DiagnosticsHkPeriodicParams params) = 0; + [[deprecated( + "Please use the new API which takes all arguments as one wrapper " + "struct")]] virtual ReturnValue_t + subscribeForPeriodicPacket(sid_t sid, bool enableReporting, float collectionInterval, + bool isDiagnostics) { + return subscribeForPeriodicPacket(sid, enableReporting, collectionInterval, isDiagnostics, + objects::NO_OBJECT); + } + [[deprecated( "Please use the new API which takes all arguments as one wrapper " "struct")]] virtual ReturnValue_t @@ -97,6 +106,12 @@ class ProvidesDataPoolSubscriptionIF { virtual ReturnValue_t subscribeForRegularUpdatePacket(subdp::RegularHkUpdateParams params) = 0; virtual ReturnValue_t subscribeForDiagUpdatePacket(subdp::DiagnosticsHkUpdateParams params) = 0; + [[deprecated( + "Please use the new API which takes all arguments as one wrapper " + "struct")]] virtual ReturnValue_t + subscribeForUpdatePacket(sid_t sid, bool reportingEnabled, bool isDiagnostics) { + return subscribeForUpdatePacket(sid, reportingEnabled, isDiagnostics, objects::NO_OBJECT); + } [[deprecated( "Please use the new API which takes all arguments as one wrapper " "struct")]] virtual ReturnValue_t diff --git a/src/fsfw/pus/Service11TelecommandScheduling.h b/src/fsfw/pus/Service11TelecommandScheduling.h index 0fed8bca..2d855be1 100644 --- a/src/fsfw/pus/Service11TelecommandScheduling.h +++ b/src/fsfw/pus/Service11TelecommandScheduling.h @@ -74,8 +74,7 @@ class Service11TelecommandScheduling final : public PusServiceBase { TO_TIMETAG = 3 }; - Service11TelecommandScheduling(object_id_t objectId, uint16_t apid, uint8_t serviceId, - AcceptsTelecommandsIF* tcRecipient, + Service11TelecommandScheduling(PsbParams params, AcceptsTelecommandsIF* tcRecipient, uint16_t releaseTimeMarginSeconds = DEFAULT_RELEASE_TIME_MARGIN, bool debugMode = false); @@ -159,7 +158,7 @@ class Service11TelecommandScheduling final : public PusServiceBase { * @param data The Application data of the TC (get via getApplicationData()). * @return requestId */ - uint64_t getRequestIdFromDataTC(const uint8_t* data) const; + [[nodiscard]] uint64_t getRequestIdFromTc() const; /** * @brief Extracts the Request ID from the Application Data directly, assuming it is packed diff --git a/src/fsfw/pus/Service11TelecommandScheduling.tpp b/src/fsfw/pus/Service11TelecommandScheduling.tpp index 968a59ff..15440a21 100644 --- a/src/fsfw/pus/Service11TelecommandScheduling.tpp +++ b/src/fsfw/pus/Service11TelecommandScheduling.tpp @@ -11,9 +11,9 @@ static constexpr auto DEF_END = SerializeIF::Endianness::BIG; template inline Service11TelecommandScheduling::Service11TelecommandScheduling( - object_id_t objectId, uint16_t apid, uint8_t serviceId, AcceptsTelecommandsIF *tcRecipient, - uint16_t releaseTimeMarginSeconds, bool debugMode) - : PusServiceBase(objectId, apid, serviceId), + PsbParams params, AcceptsTelecommandsIF *tcRecipient, uint16_t releaseTimeMarginSeconds, + bool debugMode) + : PusServiceBase(params), RELEASE_TIME_MARGIN_SECONDS(releaseTimeMarginSeconds), debugMode(debugMode), tcRecipient(tcRecipient) {} @@ -32,8 +32,8 @@ inline ReturnValue_t Service11TelecommandScheduling::handleRequest( #endif } // Get de-serialized Timestamp - const uint8_t *data = currentPacket.getApplicationData(); - size_t size = currentPacket.getApplicationDataSize(); + const uint8_t *data = currentPacket.getUserData(); + size_t size = currentPacket.getUserDataLen(); if (data == nullptr) { return handleInvalidData("handleRequest"); } @@ -82,7 +82,7 @@ inline ReturnValue_t Service11TelecommandScheduling::performService if (schedulingEnabled) { // release tc TmTcMessage releaseMsg(it->second.storeAddr); - auto sendRet = this->requestQueue->sendMessage(recipientMsgQueueId, &releaseMsg, false); + auto sendRet = psbParams.reqQueue->sendMessage(recipientMsgQueueId, &releaseMsg, false); if (sendRet != HasReturnvaluesIF::RETURN_OK) { return sendRet; @@ -175,7 +175,7 @@ inline ReturnValue_t Service11TelecommandScheduling::doInsertActivi // store currentPacket and receive the store address store_address_t addr{}; if (tcStore->addData(&addr, data, size) != RETURN_OK || - addr.raw == storeId::INVALID_STORE_ADDRESS) { + addr.raw == store_address_t::INVALID_RAW) { #if FSFW_CPP_OSTREAM_ENABLED == 1 sif::error << "Service11TelecommandScheduling::doInsertActivity: Adding data to TC Store failed" << std::endl; @@ -190,8 +190,7 @@ inline ReturnValue_t Service11TelecommandScheduling::doInsertActivi TelecommandStruct tc; tc.seconds = timestamp; tc.storeAddr = addr; - tc.requestId = - getRequestIdFromDataTC(data); // TODO: Missing sanity check of the returned request id + tc.requestId = getRequestIdFromTc(); // TODO: Missing sanity check of the returned request id auto it = telecommandMap.insert(std::pair(timestamp, tc)); if (it == telecommandMap.end()) { @@ -455,13 +454,10 @@ inline ReturnValue_t Service11TelecommandScheduling::doFilterTimesh } template -inline uint64_t Service11TelecommandScheduling::getRequestIdFromDataTC( - const uint8_t *data) const { - TcPacketPus mask(data); - - uint32_t sourceId = mask.getSourceId(); - uint16_t apid = mask.getAPID(); - uint16_t sequenceCount = mask.getPacketSequenceCount(); +inline uint64_t Service11TelecommandScheduling::getRequestIdFromTc() const { + uint32_t sourceId = currentPacket.getSourceId(); + uint16_t apid = currentPacket.getApid(); + uint16_t sequenceCount = currentPacket.getSequenceCount(); return buildRequestId(sourceId, apid, sequenceCount); } diff --git a/src/fsfw/returnvalues/HasReturnvaluesIF.h b/src/fsfw/returnvalues/HasReturnvaluesIF.h index 4d59c26b..caef5954 100644 --- a/src/fsfw/returnvalues/HasReturnvaluesIF.h +++ b/src/fsfw/returnvalues/HasReturnvaluesIF.h @@ -33,8 +33,7 @@ class HasReturnvaluesIF { * @param number * @return */ - [[deprecated("Use retval::makeCode instead")]] static constexpr ReturnValue_t makeReturnCode( - uint8_t classId, uint8_t number) { + static constexpr ReturnValue_t makeReturnCode(uint8_t classId, uint8_t number) { return retval::makeCode(classId, number); } }; diff --git a/src/fsfw/tcdistribution/PusDistributor.cpp b/src/fsfw/tcdistribution/PusDistributor.cpp index 981fca1c..9b436dec 100644 --- a/src/fsfw/tcdistribution/PusDistributor.cpp +++ b/src/fsfw/tcdistribution/PusDistributor.cpp @@ -8,8 +8,8 @@ #define PUS_DISTRIBUTOR_DEBUGGING 0 -PusDistributor::PusDistributor(StorageManagerIF* store_, uint16_t setApid, object_id_t setObjectId, - object_id_t setPacketSource) +PusDistributor::PusDistributor(uint16_t setApid, object_id_t setObjectId, + object_id_t setPacketSource, StorageManagerIF* store_) : TcDistributor(setObjectId), store(store_), checker(setApid, ccsds::PacketType::TC), @@ -151,5 +151,11 @@ ReturnValue_t PusDistributor::initialize() { #endif return RETURN_FAILED; } + if (store == nullptr) { + store = ObjectManager::instance()->get(objects::TC_STORE); + if (store == nullptr) { + return ObjectManagerIF::CHILD_INIT_FAILED; + } + } return ccsdsDistributor->registerApplication(this); } diff --git a/src/fsfw/tcdistribution/PusDistributor.h b/src/fsfw/tcdistribution/PusDistributor.h index 3849c793..b16f1478 100644 --- a/src/fsfw/tcdistribution/PusDistributor.h +++ b/src/fsfw/tcdistribution/PusDistributor.h @@ -27,8 +27,8 @@ class PusDistributor : public TcDistributor, public PUSDistributorIF, public Acc * @param setPacketSource Object ID of the source of TC packets. * Must implement CCSDSDistributorIF. */ - PusDistributor(StorageManagerIF* store, uint16_t setApid, object_id_t setObjectId, - object_id_t setPacketSource); + PusDistributor(uint16_t setApid, object_id_t setObjectId, object_id_t setPacketSource, + StorageManagerIF* store = nullptr); /** * The destructor is empty. */ diff --git a/src/fsfw/tmtcpacket/ccsds/header.cpp b/src/fsfw/tmtcpacket/ccsds/header.cpp index b87ab5b3..6491d207 100644 --- a/src/fsfw/tmtcpacket/ccsds/header.cpp +++ b/src/fsfw/tmtcpacket/ccsds/header.cpp @@ -17,7 +17,7 @@ uint16_t ccsds::getPacketLen(const PrimaryHeader &header) { } void ccsds::setPacketId(PrimaryHeader &header, uint16_t packetId) { - header.packetIdHAndVersion = (packetId >> 8) & 0x1F; + header.packetIdHAndVersion |= (packetId >> 8) & 0x1F; header.packetIdL = packetId & 0xff; } @@ -27,3 +27,8 @@ void ccsds::setApid(PrimaryHeader &header, uint16_t apid) { packetIdRaw |= apid & 0x7FF; setPacketId(header, packetIdRaw); } + +void ccsds::setSequenceCount(PrimaryHeader &header, uint16_t seqCount) { + header.packetSeqCtrlH |= (seqCount >> 8) & 0x3F; + header.packetSeqCtrlL = seqCount & 0xFF; +} diff --git a/src/fsfw/tmtcpacket/ccsds/header.h b/src/fsfw/tmtcpacket/ccsds/header.h index d416f697..89e00601 100644 --- a/src/fsfw/tmtcpacket/ccsds/header.h +++ b/src/fsfw/tmtcpacket/ccsds/header.h @@ -24,6 +24,7 @@ uint16_t getPacketLen(const PrimaryHeader& header); void setPacketId(PrimaryHeader& header, uint16_t packetId); void setApid(PrimaryHeader& header, uint16_t apid); +void setSequenceCount(PrimaryHeader& header, uint16_t seqCount); } // namespace ccsds diff --git a/src/fsfw/tmtcpacket/pus/tm.h b/src/fsfw/tmtcpacket/pus/tm.h index 619f9e01..fc3f0b94 100644 --- a/src/fsfw/tmtcpacket/pus/tm.h +++ b/src/fsfw/tmtcpacket/pus/tm.h @@ -3,5 +3,6 @@ #include "tm/PusTmCreator.h" #include "tm/PusTmReader.h" +#include "tm/PusTmZcWriter.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 57c45927..1395d927 100644 --- a/src/fsfw/tmtcpacket/pus/tm/CMakeLists.txt +++ b/src/fsfw/tmtcpacket/pus/tm/CMakeLists.txt @@ -1,2 +1,2 @@ target_sources(${LIB_FSFW_NAME} PRIVATE PusTmCreator.cpp PusTmReader.cpp - PusTmMinimal.cpp) + PusTmMinimal.cpp PusTmZcWriter.cpp) diff --git a/src/fsfw/tmtcpacket/pus/tm/PusTmCreator.cpp b/src/fsfw/tmtcpacket/pus/tm/PusTmCreator.cpp index ddcad33e..6e6eb686 100644 --- a/src/fsfw/tmtcpacket/pus/tm/PusTmCreator.cpp +++ b/src/fsfw/tmtcpacket/pus/tm/PusTmCreator.cpp @@ -83,8 +83,11 @@ ReturnValue_t PusTmCreator::serialize(uint8_t** buffer, size_t* size, size_t max return result; } } - uint16_t crc16 = CRC::crc16ccitt(start, getFullPacketLen() - sizeof(ecss::PusChecksumT)); - return SerializeAdapter::serialize(&crc16, buffer, size, maxSize, streamEndianness); + if (calculateCrcOnSerialization) { + uint16_t crc16 = CRC::crc16ccitt(start, getFullPacketLen() - sizeof(ecss::PusChecksumT)); + return SerializeAdapter::serialize(&crc16, buffer, size, maxSize, streamEndianness); + } + return HasReturnvaluesIF::RETURN_OK; } size_t PusTmCreator::getSerializedSize() const { return getFullPacketLen(); } @@ -108,10 +111,6 @@ void PusTmCreator::updateSpLengthField() { void PusTmCreator::setApid(uint16_t apid) { spCreator.setApid(apid); } -ReturnValue_t PusTmCreator::serialize(uint8_t** buffer, size_t* size, size_t maxSize) const { - return serialize(buffer, size, maxSize, SerializeIF::Endianness::NETWORK); -} - void PusTmCreator::setup() { updateSpLengthField(); spCreator.setPacketType(ccsds::PacketType::TM); diff --git a/src/fsfw/tmtcpacket/pus/tm/PusTmCreator.h b/src/fsfw/tmtcpacket/pus/tm/PusTmCreator.h index 41f72c38..78414c37 100644 --- a/src/fsfw/tmtcpacket/pus/tm/PusTmCreator.h +++ b/src/fsfw/tmtcpacket/pus/tm/PusTmCreator.h @@ -63,7 +63,6 @@ class PusTmCreator : public SerializeIF, public PusTmIF, public CustomUserDataIF uint8_t getScTimeRefStatus() override; uint16_t getMessageTypeCounter() override; uint16_t getDestId() override; - ReturnValue_t serialize(uint8_t** buffer, size_t* size, size_t maxSize) const; ReturnValue_t serialize(uint8_t** buffer, size_t* size, size_t maxSize, Endianness streamEndianness) const override; [[nodiscard]] size_t getSerializedSize() const override; @@ -76,6 +75,7 @@ class PusTmCreator : public SerializeIF, public PusTmIF, public CustomUserDataIF private: void setup(); PusTmParams pusParams{}; + bool calculateCrcOnSerialization = true; SpacePacketCreator spCreator; }; #endif // FSFW_TMTCPACKET_TMPACKETCREATOR_H diff --git a/src/fsfw/tmtcpacket/pus/tm/PusTmReader.h b/src/fsfw/tmtcpacket/pus/tm/PusTmReader.h index e5a61aec..780b3e5f 100644 --- a/src/fsfw/tmtcpacket/pus/tm/PusTmReader.h +++ b/src/fsfw/tmtcpacket/pus/tm/PusTmReader.h @@ -38,13 +38,15 @@ class PusTmReader : public PusTmIF, uint16_t getMessageTypeCounter() override; uint16_t getDestId() override; - private: - ReturnValue_t setData(uint8_t* dataPtr, size_t size, void* args) override; - ReturnValue_t parseData(bool crcCheck); + protected: + ecss::PusPointers pointers{}; SpacePacketReader spReader{}; size_t sourceDataLen = 0; TimeReaderIF* timeReader{}; - ecss::PusPointers pointers{}; + ReturnValue_t setData(uint8_t* dataPtr, size_t size, void* args) override; + ReturnValue_t parseData(bool crcCheck); + + private: }; #endif // FSFW_TMTCPACKET_PUSTMREADER_H diff --git a/src/fsfw/tmtcpacket/pus/tm/PusTmZcWriter.cpp b/src/fsfw/tmtcpacket/pus/tm/PusTmZcWriter.cpp new file mode 100644 index 00000000..4c6c56d3 --- /dev/null +++ b/src/fsfw/tmtcpacket/pus/tm/PusTmZcWriter.cpp @@ -0,0 +1,18 @@ +#include "PusTmZcWriter.h" + +#include "fsfw/globalfunctions/CRC.h" + +PusTmZeroCopyWriter::PusTmZeroCopyWriter(uint8_t* data, size_t size) : PusTmReader(data, size) {} + +void PusTmZeroCopyWriter::setSequenceCount(uint16_t seqCount) { + auto* spHeader = + reinterpret_cast(const_cast((pointers.spHeaderStart))); + ccsds::setSequenceCount(*spHeader, seqCount); +} +void PusTmZeroCopyWriter::updateErrorControl() { + auto* crcStart = reinterpret_cast(const_cast((pointers.spHeaderStart))); + uint16_t crc16 = + CRC::crc16ccitt(PusTmReader::getFullData(), getFullPacketLen() - sizeof(ecss::PusChecksumT)); + crcStart[0] = (crc16 >> 8) & 0xff; + crcStart[1] = crc16 & 0xff; +} diff --git a/src/fsfw/tmtcpacket/pus/tm/PusTmZcWriter.h b/src/fsfw/tmtcpacket/pus/tm/PusTmZcWriter.h new file mode 100644 index 00000000..c3f5db35 --- /dev/null +++ b/src/fsfw/tmtcpacket/pus/tm/PusTmZcWriter.h @@ -0,0 +1,14 @@ +#ifndef FSFW_EXAMPLE_HOSTED_PUSTMZCWRITER_H +#define FSFW_EXAMPLE_HOSTED_PUSTMZCWRITER_H + +#include "PusTmReader.h" +class PusTmZeroCopyWriter : public PusTmReader { + public: + PusTmZeroCopyWriter(uint8_t* data, size_t size); + + void setSequenceCount(uint16_t seqCount); + void updateErrorControl(); + + private: +}; +#endif // FSFW_EXAMPLE_HOSTED_PUSTMZCWRITER_H diff --git a/src/fsfw/tmtcservices/PusServiceBase.cpp b/src/fsfw/tmtcservices/PusServiceBase.cpp index 97f018e5..094a4156 100644 --- a/src/fsfw/tmtcservices/PusServiceBase.cpp +++ b/src/fsfw/tmtcservices/PusServiceBase.cpp @@ -27,7 +27,7 @@ ReturnValue_t PusServiceBase::performOperation(uint8_t opCode) { if (result != RETURN_OK) { #if FSFW_CPP_OSTREAM_ENABLED == 1 sif::error << "PusService " << psbParams.serviceId << ": performService returned with " - << static_cast(result) << std::endl; + << static_cast(result) << std::endl; #endif return RETURN_FAILED; } diff --git a/src/fsfw_tests/integration/devices/TestDeviceHandler.cpp b/src/fsfw_tests/integration/devices/TestDeviceHandler.cpp index 36f1ea8c..551e252f 100644 --- a/src/fsfw_tests/integration/devices/TestDeviceHandler.cpp +++ b/src/fsfw_tests/integration/devices/TestDeviceHandler.cpp @@ -645,7 +645,7 @@ ReturnValue_t TestDevice::initializeLocalDataPool(localpool::DataPool& localData sid_t sid(this->getObjectId(), td::TEST_SET_ID); /* Subscribe for periodic HK packets but do not enable reporting for now. Non-diangostic with a period of one second */ - poolManager.subscribeForPeriodicPacket(sid, false, 1.0, false); + poolManager.subscribeForRegularPeriodicPacket(subdp::RegularHkPeriodicParams(sid, false, 1.0)); return HasReturnvaluesIF::RETURN_OK; } -- 2.43.0 From 064b195c752f2f6e7c0cb4660bb294cf8a8e6db1 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Wed, 27 Jul 2022 11:33:19 +0200 Subject: [PATCH 076/108] some of the deprecation warnings run amok --- src/fsfw/datapoollocal/ProvidesDataPoolSubscriptionIF.h | 9 +++------ src/fsfw/tmtcpacket/pus/tm/PusTmCreator.cpp | 9 +++++++++ src/fsfw/tmtcpacket/pus/tm/PusTmCreator.h | 9 +++++++++ 3 files changed, 21 insertions(+), 6 deletions(-) diff --git a/src/fsfw/datapoollocal/ProvidesDataPoolSubscriptionIF.h b/src/fsfw/datapoollocal/ProvidesDataPoolSubscriptionIF.h index 3001ea10..682cfa5c 100644 --- a/src/fsfw/datapoollocal/ProvidesDataPoolSubscriptionIF.h +++ b/src/fsfw/datapoollocal/ProvidesDataPoolSubscriptionIF.h @@ -70,9 +70,7 @@ class ProvidesDataPoolSubscriptionIF { virtual ReturnValue_t subscribeForDiagPeriodicPacket( subdp::DiagnosticsHkPeriodicParams params) = 0; - [[deprecated( - "Please use the new API which takes all arguments as one wrapper " - "struct")]] virtual ReturnValue_t + virtual ReturnValue_t subscribeForPeriodicPacket(sid_t sid, bool enableReporting, float collectionInterval, bool isDiagnostics) { return subscribeForPeriodicPacket(sid, enableReporting, collectionInterval, isDiagnostics, @@ -106,12 +104,11 @@ class ProvidesDataPoolSubscriptionIF { virtual ReturnValue_t subscribeForRegularUpdatePacket(subdp::RegularHkUpdateParams params) = 0; virtual ReturnValue_t subscribeForDiagUpdatePacket(subdp::DiagnosticsHkUpdateParams params) = 0; - [[deprecated( - "Please use the new API which takes all arguments as one wrapper " - "struct")]] virtual ReturnValue_t + virtual ReturnValue_t subscribeForUpdatePacket(sid_t sid, bool reportingEnabled, bool isDiagnostics) { return subscribeForUpdatePacket(sid, reportingEnabled, isDiagnostics, objects::NO_OBJECT); } + [[deprecated( "Please use the new API which takes all arguments as one wrapper " "struct")]] virtual ReturnValue_t diff --git a/src/fsfw/tmtcpacket/pus/tm/PusTmCreator.cpp b/src/fsfw/tmtcpacket/pus/tm/PusTmCreator.cpp index 6e6eb686..850eb078 100644 --- a/src/fsfw/tmtcpacket/pus/tm/PusTmCreator.cpp +++ b/src/fsfw/tmtcpacket/pus/tm/PusTmCreator.cpp @@ -12,6 +12,14 @@ PusTmCreator::PusTmCreator(SpacePacketParams initSpParams, PusTmParams initPusPa PusTmCreator::PusTmCreator() { setup(); } +void PusTmCreator::disableCrcCalculation() { + calculateCrcOnSerialization = false; +} + +void PusTmCreator::enableCrcCalculation() { + calculateCrcOnSerialization = true; +} + uint16_t PusTmCreator::getPacketIdRaw() const { return spCreator.getPacketIdRaw(); } uint16_t PusTmCreator::getPacketSeqCtrlRaw() const { return spCreator.getPacketSeqCtrlRaw(); } @@ -138,3 +146,4 @@ void PusTmCreator::setService(uint8_t service) { pusParams.secHeader.service = s void PusTmCreator::setSubservice(uint8_t subservice) { pusParams.secHeader.subservice = subservice; } +bool PusTmCreator::crcCalculationEnabled() const { return calculateCrcOnSerialization; } diff --git a/src/fsfw/tmtcpacket/pus/tm/PusTmCreator.h b/src/fsfw/tmtcpacket/pus/tm/PusTmCreator.h index 78414c37..0e7988f1 100644 --- a/src/fsfw/tmtcpacket/pus/tm/PusTmCreator.h +++ b/src/fsfw/tmtcpacket/pus/tm/PusTmCreator.h @@ -46,6 +46,15 @@ class PusTmCreator : public SerializeIF, public PusTmIF, public CustomUserDataIF ~PusTmCreator() override = default; void setTimeStamper(TimeStamperIF& timeStamper); + /** + * This function disables the CRC16 calculation on serialization. This is useful to avoid + * duplicate calculation if some lower level component needs to update fields like the sequence + * count, which would require a checksum update. + */ + void disableCrcCalculation(); + void enableCrcCalculation(); + [[nodiscard]] bool crcCalculationEnabled() const; + SpacePacketParams& getSpParams(); void setApid(uint16_t apid); void setDestId(uint16_t destId); -- 2.43.0 From 86692e202dedd682e7cbc7476b4b0908668d2fd9 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Wed, 27 Jul 2022 11:35:35 +0200 Subject: [PATCH 077/108] this gets rid of some warnings --- .../ProvidesDataPoolSubscriptionIF.h | 20 +++++++------------ 1 file changed, 7 insertions(+), 13 deletions(-) diff --git a/src/fsfw/datapoollocal/ProvidesDataPoolSubscriptionIF.h b/src/fsfw/datapoollocal/ProvidesDataPoolSubscriptionIF.h index 682cfa5c..31067268 100644 --- a/src/fsfw/datapoollocal/ProvidesDataPoolSubscriptionIF.h +++ b/src/fsfw/datapoollocal/ProvidesDataPoolSubscriptionIF.h @@ -70,18 +70,12 @@ class ProvidesDataPoolSubscriptionIF { virtual ReturnValue_t subscribeForDiagPeriodicPacket( subdp::DiagnosticsHkPeriodicParams params) = 0; - virtual ReturnValue_t - subscribeForPeriodicPacket(sid_t sid, bool enableReporting, float collectionInterval, - bool isDiagnostics) { - return subscribeForPeriodicPacket(sid, enableReporting, collectionInterval, isDiagnostics, - objects::NO_OBJECT); - } - [[deprecated( "Please use the new API which takes all arguments as one wrapper " "struct")]] virtual ReturnValue_t subscribeForPeriodicPacket(sid_t sid, bool enableReporting, float collectionInterval, - bool isDiagnostics, object_id_t packetDestination) { + bool isDiagnostics, + object_id_t packetDestination = objects::NO_OBJECT) { if (isDiagnostics) { subdp::DiagnosticsHkPeriodicParams params(sid, enableReporting, collectionInterval); return subscribeForDiagPeriodicPacket(params); @@ -104,16 +98,16 @@ class ProvidesDataPoolSubscriptionIF { virtual ReturnValue_t subscribeForRegularUpdatePacket(subdp::RegularHkUpdateParams params) = 0; virtual ReturnValue_t subscribeForDiagUpdatePacket(subdp::DiagnosticsHkUpdateParams params) = 0; - virtual ReturnValue_t - subscribeForUpdatePacket(sid_t sid, bool reportingEnabled, bool isDiagnostics) { - return subscribeForUpdatePacket(sid, reportingEnabled, isDiagnostics, objects::NO_OBJECT); - } +// virtual ReturnValue_t +// subscribeForUpdatePacket(sid_t sid, bool reportingEnabled, bool isDiagnostics) { +// return subscribeForUpdatePacket(sid, reportingEnabled, isDiagnostics, objects::NO_OBJECT); +// } [[deprecated( "Please use the new API which takes all arguments as one wrapper " "struct")]] virtual ReturnValue_t subscribeForUpdatePacket(sid_t sid, bool reportingEnabled, bool isDiagnostics, - object_id_t packetDestination) { + object_id_t packetDestination = objects::NO_OBJECT) { if (isDiagnostics) { subdp::DiagnosticsHkUpdateParams params(sid, reportingEnabled); return subscribeForDiagUpdatePacket(params); -- 2.43.0 From 059fb105583bd4ce072e1134ffbaa3aab8955d04 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Wed, 27 Jul 2022 11:41:06 +0200 Subject: [PATCH 078/108] add helper methods to disable crc calculation --- src/fsfw/tmtcservices/CommandingServiceBase.cpp | 4 ++++ src/fsfw/tmtcservices/CommandingServiceBase.h | 6 +++++- src/fsfw/tmtcservices/TmStoreHelper.cpp | 4 ++++ src/fsfw/tmtcservices/TmStoreHelper.h | 3 +++ 4 files changed, 16 insertions(+), 1 deletion(-) diff --git a/src/fsfw/tmtcservices/CommandingServiceBase.cpp b/src/fsfw/tmtcservices/CommandingServiceBase.cpp index 214adbfa..0be7c3c8 100644 --- a/src/fsfw/tmtcservices/CommandingServiceBase.cpp +++ b/src/fsfw/tmtcservices/CommandingServiceBase.cpp @@ -100,6 +100,10 @@ ReturnValue_t CommandingServiceBase::initialize() { } tmStoreHelper.setTmStore(*tmStore); } + // Generally, all TM packets will pass through a layer where the sequence count is set. + // This avoids duplicate calculation of the CRC16 + tmStoreHelper.disableCrcCalculation(); + if (errReporter == nullptr) { errReporter = ObjectManager::instance()->get(objects::INTERNAL_ERROR_REPORTER); diff --git a/src/fsfw/tmtcservices/CommandingServiceBase.h b/src/fsfw/tmtcservices/CommandingServiceBase.h index 20b7d992..8017ecc8 100644 --- a/src/fsfw/tmtcservices/CommandingServiceBase.h +++ b/src/fsfw/tmtcservices/CommandingServiceBase.h @@ -25,12 +25,16 @@ void setStaticFrameworkObjectIds(); * relay Telecommands to software bus. * * It manages Telecommand reception and the generation of Verification Reports - * similar to PusServiceBase. This class is used if a telecommand can't be + * similar to @PusServiceBase. This class is used if a telecommand can't be * handled immediately and must be relayed to the internal software bus. * - isValidSubservice * - getMessageQueueAndObject * - prepareCommand * - handleReply + * + * Please note that the TM packets generated by this class will not have a valid CRC. It is + * generally assumed that all packets will pass through a layer where the sequence count is set + * and the CRC16 needs to be re-calculated anyway. * @author gaisser * @ingroup pus_services */ diff --git a/src/fsfw/tmtcservices/TmStoreHelper.cpp b/src/fsfw/tmtcservices/TmStoreHelper.cpp index a87ca01d..8b7e5948 100644 --- a/src/fsfw/tmtcservices/TmStoreHelper.cpp +++ b/src/fsfw/tmtcservices/TmStoreHelper.cpp @@ -74,3 +74,7 @@ uint16_t TmStoreHelper::getApid() const { return creator.getApid(); } void TmStoreHelper::setService(uint8_t service) { creator.setService(service); } void TmStoreHelper::setSubservice(uint8_t subservice) { creator.setSubservice(subservice); } + +void TmStoreHelper::disableCrcCalculation() { creator.disableCrcCalculation(); } + +bool TmStoreHelper::crcCalculationEnabled() const { return creator.crcCalculationEnabled(); } diff --git a/src/fsfw/tmtcservices/TmStoreHelper.h b/src/fsfw/tmtcservices/TmStoreHelper.h index e5d9eb7d..449a2287 100644 --- a/src/fsfw/tmtcservices/TmStoreHelper.h +++ b/src/fsfw/tmtcservices/TmStoreHelper.h @@ -13,6 +13,9 @@ class TmStoreHelper { TmStoreHelper(uint16_t defaultApid, StorageManagerIF& tmStore); TmStoreHelper(uint16_t defaultApid, StorageManagerIF& tmStore, TimeStamperIF& timeStamper); + void disableCrcCalculation(); + [[nodiscard]] bool crcCalculationEnabled() const; + ReturnValue_t preparePacket(uint8_t service, uint8_t subservice, uint16_t counter); PusTmCreator& getCreatorRef(); -- 2.43.0 From 740644f2c8398227734fd4a4110b3d8ae09f3351 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Wed, 27 Jul 2022 14:40:51 +0200 Subject: [PATCH 079/108] updates for PusDistributor --- src/fsfw/tcdistribution/PusDistributor.cpp | 28 +++++++++------------- src/fsfw/tcdistribution/PusDistributor.h | 12 ++++------ 2 files changed, 15 insertions(+), 25 deletions(-) diff --git a/src/fsfw/tcdistribution/PusDistributor.cpp b/src/fsfw/tcdistribution/PusDistributor.cpp index 9b436dec..36bcd34b 100644 --- a/src/fsfw/tcdistribution/PusDistributor.cpp +++ b/src/fsfw/tcdistribution/PusDistributor.cpp @@ -9,12 +9,12 @@ #define PUS_DISTRIBUTOR_DEBUGGING 0 PusDistributor::PusDistributor(uint16_t setApid, object_id_t setObjectId, - object_id_t setPacketSource, StorageManagerIF* store_) + CCSDSDistributorIF* distributor, StorageManagerIF* store_) : TcDistributor(setObjectId), store(store_), checker(setApid, ccsds::PacketType::TC), - tcStatus(RETURN_FAILED), - packetSource(setPacketSource) {} + ccsdsDistributor(distributor), + tcStatus(RETURN_FAILED) {} PusDistributor::~PusDistributor() = default; @@ -25,7 +25,7 @@ PusDistributor::TcMqMapIter PusDistributor::selectDestination() { << storeId.packetIndex << std::endl; #endif auto queueMapIt = this->queueMap.end(); - if (this->currentPacket == nullptr) { + if (reader.isNull()) { return queueMapIt; } // TODO: Need to set the data @@ -135,13 +135,13 @@ ReturnValue_t PusDistributor::callbackAfterSending(ReturnValue_t queueStatus) { uint16_t PusDistributor::getIdentifier() { return checker.getApid(); } ReturnValue_t PusDistributor::initialize() { - if (currentPacket == nullptr) { - // Should not happen, memory allocation failed! - return ObjectManagerIF::CHILD_INIT_FAILED; + if (store == nullptr) { + store = ObjectManager::instance()->get(objects::TC_STORE); + if (store == nullptr) { + return ObjectManagerIF::CHILD_INIT_FAILED; + } } - - auto* ccsdsDistributor = ObjectManager::instance()->get(packetSource); - if (ccsdsDistributor == nullptr) { + if(ccsdsDistributor == nullptr) { #if FSFW_CPP_OSTREAM_ENABLED == 1 sif::error << "PUSDistributor::initialize: Packet source invalid" << std::endl; sif::error << " Make sure it exists and implements CCSDSDistributorIF!" << std::endl; @@ -149,13 +149,7 @@ ReturnValue_t PusDistributor::initialize() { sif::printError("PusDistributor::initialize: Packet source invalid\n"); sif::printError("Make sure it exists and implements CCSDSDistributorIF\n"); #endif - return RETURN_FAILED; - } - if (store == nullptr) { - store = ObjectManager::instance()->get(objects::TC_STORE); - if (store == nullptr) { - return ObjectManagerIF::CHILD_INIT_FAILED; - } + return ObjectManagerIF::CHILD_INIT_FAILED; } return ccsdsDistributor->registerApplication(this); } diff --git a/src/fsfw/tcdistribution/PusDistributor.h b/src/fsfw/tcdistribution/PusDistributor.h index b16f1478..bb0c7a04 100644 --- a/src/fsfw/tcdistribution/PusDistributor.h +++ b/src/fsfw/tcdistribution/PusDistributor.h @@ -9,7 +9,7 @@ #include "fsfw/tmtcservices/AcceptsTelecommandsIF.h" #include "fsfw/tmtcservices/VerificationReporter.h" -class PacketStorageHelper; +class CCSDSDistributorIF; /** * This class accepts PUS Telecommands and forwards them to Application @@ -27,7 +27,7 @@ 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(uint16_t setApid, object_id_t setObjectId, CCSDSDistributorIF* packetSource, StorageManagerIF* store = nullptr); /** * The destructor is empty. @@ -49,10 +49,8 @@ class PusDistributor : public TcDistributor, public PUSDistributorIF, public Acc * TC Verification service. */ VerificationReporterIF* verifyChannel = nullptr; - /** - * The currently handled packet is stored here. - */ - PacketStorageHelper* currentPacket = nullptr; + //! Cached for initialization + CCSDSDistributorIF* ccsdsDistributor = nullptr; PusTcReader reader; /** @@ -61,8 +59,6 @@ class PusDistributor : public TcDistributor, public PUSDistributorIF, public Acc */ ReturnValue_t tcStatus; - const object_id_t packetSource; - /** * This method reads the packet service, checks if such a service is * registered and forwards the packet to the destination. -- 2.43.0 From 083d08ae2a3e294b20c31f8970f1faa47cb1c276 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Wed, 27 Jul 2022 17:00:43 +0200 Subject: [PATCH 080/108] various bugs and improvements --- .../ProvidesDataPoolSubscriptionIF.h | 8 +- src/fsfw/osal/host/MessageQueue.h | 4 +- src/fsfw/osal/host/QueueMapManager.cpp | 2 +- .../pus/Service1TelecommandVerification.cpp | 34 ++++- .../pus/Service1TelecommandVerification.h | 1 + src/fsfw/tcdistribution/CCSDSDistributor.cpp | 22 +-- src/fsfw/tcdistribution/CCSDSDistributor.h | 18 ++- src/fsfw/tcdistribution/CFDPDistributor.cpp | 2 +- src/fsfw/tcdistribution/CMakeLists.txt | 2 +- src/fsfw/tcdistribution/CcsdsPacketCheckIF.h | 2 +- .../tcdistribution/CcsdsPacketChecker.cpp | 33 +++++ src/fsfw/tcdistribution/CcsdsPacketChecker.h | 20 +++ .../tcdistribution/CcsdsPacketCheckerBase.cpp | 22 --- .../tcdistribution/CcsdsPacketCheckerBase.h | 17 --- src/fsfw/tcdistribution/CfdpPacketChecker.h | 2 +- src/fsfw/tcdistribution/PusDistributor.cpp | 130 ++++++++++-------- src/fsfw/tcdistribution/PusDistributor.h | 2 + src/fsfw/tcdistribution/PusPacketChecker.cpp | 32 ++--- src/fsfw/tcdistribution/PusPacketChecker.h | 14 +- src/fsfw/tcdistribution/TcDistributor.cpp | 15 +- src/fsfw/tcdistribution/TcPacketCheckCFDP.cpp | 3 +- src/fsfw/timemanager/TimeStamperIF.h | 2 + src/fsfw/tmtcpacket/ReadablePacketIF.h | 2 +- .../tmtcpacket/ccsds/SpacePacketReader.cpp | 2 +- src/fsfw/tmtcpacket/ccsds/SpacePacketReader.h | 2 +- src/fsfw/tmtcpacket/pus/tc/PusTcReader.cpp | 2 +- src/fsfw/tmtcpacket/pus/tc/PusTcReader.h | 2 +- src/fsfw/tmtcpacket/pus/tm/PusTmCreator.cpp | 17 ++- src/fsfw/tmtcpacket/pus/tm/PusTmReader.cpp | 2 +- src/fsfw/tmtcpacket/pus/tm/PusTmReader.h | 2 +- .../tmtcservices/CommandingServiceBase.cpp | 6 + src/fsfw/tmtcservices/CommandingServiceBase.h | 1 + src/fsfw/tmtcservices/PusServiceBase.cpp | 7 + src/fsfw/tmtcservices/PusServiceBase.h | 5 +- src/fsfw/tmtcservices/TmSendHelper.cpp | 40 ++++-- src/fsfw/tmtcservices/TmSendHelper.h | 1 - 36 files changed, 276 insertions(+), 202 deletions(-) create mode 100644 src/fsfw/tcdistribution/CcsdsPacketChecker.cpp create mode 100644 src/fsfw/tcdistribution/CcsdsPacketChecker.h delete mode 100644 src/fsfw/tcdistribution/CcsdsPacketCheckerBase.cpp delete mode 100644 src/fsfw/tcdistribution/CcsdsPacketCheckerBase.h diff --git a/src/fsfw/datapoollocal/ProvidesDataPoolSubscriptionIF.h b/src/fsfw/datapoollocal/ProvidesDataPoolSubscriptionIF.h index 31067268..c350bb60 100644 --- a/src/fsfw/datapoollocal/ProvidesDataPoolSubscriptionIF.h +++ b/src/fsfw/datapoollocal/ProvidesDataPoolSubscriptionIF.h @@ -98,10 +98,10 @@ class ProvidesDataPoolSubscriptionIF { virtual ReturnValue_t subscribeForRegularUpdatePacket(subdp::RegularHkUpdateParams params) = 0; virtual ReturnValue_t subscribeForDiagUpdatePacket(subdp::DiagnosticsHkUpdateParams params) = 0; -// virtual ReturnValue_t -// subscribeForUpdatePacket(sid_t sid, bool reportingEnabled, bool isDiagnostics) { -// return subscribeForUpdatePacket(sid, reportingEnabled, isDiagnostics, objects::NO_OBJECT); -// } + // virtual ReturnValue_t + // subscribeForUpdatePacket(sid_t sid, bool reportingEnabled, bool isDiagnostics) { + // return subscribeForUpdatePacket(sid, reportingEnabled, isDiagnostics, objects::NO_OBJECT); + // } [[deprecated( "Please use the new API which takes all arguments as one wrapper " diff --git a/src/fsfw/osal/host/MessageQueue.h b/src/fsfw/osal/host/MessageQueue.h index 4020c6dc..7d60fb8e 100644 --- a/src/fsfw/osal/host/MessageQueue.h +++ b/src/fsfw/osal/host/MessageQueue.h @@ -68,7 +68,7 @@ class MessageQueue : public MessageQueueBase { * @details This is accomplished by using the delete call provided * by the operating system. */ - virtual ~MessageQueue(); + ~MessageQueue() override; // Implement non-generic MessageQueueIF functions not handled by MessageQueueBase virtual ReturnValue_t sendMessageFrom(MessageQueueId_t sendTo, MessageQueueMessageIF* message, @@ -111,8 +111,6 @@ class MessageQueue : public MessageQueueBase { size_t messageDepth = 0; MutexIF* queueLock; - - MessageQueueId_t defaultDestination = MessageQueueIF::NO_QUEUE; }; #endif /* FRAMEWORK_OSAL_HOST_MESSAGEQUEUE_H_ */ diff --git a/src/fsfw/osal/host/QueueMapManager.cpp b/src/fsfw/osal/host/QueueMapManager.cpp index 72c70baa..301ed131 100644 --- a/src/fsfw/osal/host/QueueMapManager.cpp +++ b/src/fsfw/osal/host/QueueMapManager.cpp @@ -54,7 +54,7 @@ MessageQueueIF* QueueMapManager::getMessageQueue(MessageQueueId_t messageQueueId } else { #if FSFW_CPP_OSTREAM_ENABLED == 1 sif::warning << "QueueMapManager::getQueueHandle: The ID " << messageQueueId - << " does not exists in the map!" << std::endl; + << " does not exist in the map" << std::endl; #else sif::printWarning("QueueMapManager::getQueueHandle: The ID %d does not exist in the map!\n", messageQueueId); diff --git a/src/fsfw/pus/Service1TelecommandVerification.cpp b/src/fsfw/pus/Service1TelecommandVerification.cpp index 102ae5a0..6c1c2310 100644 --- a/src/fsfw/pus/Service1TelecommandVerification.cpp +++ b/src/fsfw/pus/Service1TelecommandVerification.cpp @@ -68,8 +68,15 @@ ReturnValue_t Service1TelecommandVerification::generateFailureReport( FailureReport report(message->getReportId(), message->getTcPacketId(), message->getTcSequenceControl(), message->getStep(), message->getErrorCode(), message->getParameter1(), message->getParameter2()); - storeHelper.preparePacket(serviceId, message->getReportId(), packetSubCounter++); - storeHelper.setSourceDataSerializable(report); + ReturnValue_t result = + storeHelper.preparePacket(serviceId, message->getReportId(), packetSubCounter++); + if (result != HasReturnvaluesIF::RETURN_OK) { + return result; + } + result = storeHelper.setSourceDataSerializable(report); + if (result != HasReturnvaluesIF::RETURN_OK) { + return result; + } return tmHelper.storeAndSendTmPacket(); } @@ -77,8 +84,15 @@ ReturnValue_t Service1TelecommandVerification::generateSuccessReport( PusVerificationMessage* message) { SuccessReport report(message->getReportId(), message->getTcPacketId(), message->getTcSequenceControl(), message->getStep()); - storeHelper.preparePacket(serviceId, message->getReportId(), packetSubCounter++); - storeHelper.setSourceDataSerializable(report); + ReturnValue_t result = + storeHelper.preparePacket(serviceId, message->getReportId(), packetSubCounter++); + if (result != HasReturnvaluesIF::RETURN_OK) { + return result; + } + result = storeHelper.setSourceDataSerializable(report); + if (result != HasReturnvaluesIF::RETURN_OK) { + return result; + } return tmHelper.storeAndSendTmPacket(); } @@ -94,6 +108,9 @@ ReturnValue_t Service1TelecommandVerification::initialize() { #endif return ObjectManagerIF::CHILD_INIT_FAILED; } + if (tmQueue == nullptr) { + return ObjectManagerIF::CHILD_INIT_FAILED; + } tmQueue->setDefaultDestination(funnel->getReportReceptionQueue()); if (tmStore == nullptr) { tmStore = ObjectManager::instance()->get(objects::TM_STORE); @@ -102,5 +119,14 @@ ReturnValue_t Service1TelecommandVerification::initialize() { } storeHelper.setTmStore(*tmStore); } + + sendHelper.setMsgQueue(*tmQueue); + if (errReporter == nullptr) { + errReporter = + ObjectManager::instance()->get(objects::INTERNAL_ERROR_REPORTER); + if (errReporter != nullptr) { + sendHelper.setInternalErrorReporter(*errReporter); + } + } return SystemObject::initialize(); } diff --git a/src/fsfw/pus/Service1TelecommandVerification.h b/src/fsfw/pus/Service1TelecommandVerification.h index dcbb5017..2e121bbf 100644 --- a/src/fsfw/pus/Service1TelecommandVerification.h +++ b/src/fsfw/pus/Service1TelecommandVerification.h @@ -86,6 +86,7 @@ class Service1TelecommandVerification : public AcceptsVerifyMessageIF, TmSendHelper sendHelper; TmStoreHelper storeHelper; TmStoreAndSendWrapper tmHelper; + InternalErrorReporterIF* errReporter = nullptr; StorageManagerIF* tmStore = nullptr; MessageQueueIF* tmQueue = nullptr; diff --git a/src/fsfw/tcdistribution/CCSDSDistributor.cpp b/src/fsfw/tcdistribution/CCSDSDistributor.cpp index 9601825c..4dad31aa 100644 --- a/src/fsfw/tcdistribution/CCSDSDistributor.cpp +++ b/src/fsfw/tcdistribution/CCSDSDistributor.cpp @@ -4,10 +4,11 @@ #include "fsfw/serviceinterface/ServiceInterface.h" #include "fsfw/tmtcpacket/ccsds/SpacePacketReader.h" -#define CCSDS_DISTRIBUTOR_DEBUGGING 0 +#define CCSDS_DISTRIBUTOR_DEBUGGING 1 -CCSDSDistributor::CCSDSDistributor(uint16_t setDefaultApid, object_id_t setObjectId) - : TcDistributor(setObjectId), defaultApid(setDefaultApid) {} +CCSDSDistributor::CCSDSDistributor(uint16_t setDefaultApid, object_id_t setObjectId, + CcsdsPacketCheckIF* packetChecker) + : TcDistributor(setObjectId), defaultApid(setDefaultApid), packetChecker(packetChecker) {} CCSDSDistributor::~CCSDSDistributor() = default; @@ -25,7 +26,7 @@ TcDistributor::TcMqMapIter CCSDSDistributor::selectDestination() { #endif const uint8_t* packet = nullptr; size_t size = 0; - ReturnValue_t result = this->tcStore->getData(currentMessage.getStorageId(), &packet, &size); + ReturnValue_t result = tcStore->getData(currentMessage.getStorageId(), &packet, &size); if (result != HasReturnvaluesIF::RETURN_OK) { #if FSFW_VERBOSE_LEVEL >= 1 #if FSFW_CPP_OSTREAM_ENABLED == 1 @@ -41,10 +42,12 @@ TcDistributor::TcMqMapIter CCSDSDistributor::selectDestination() { return queueMap.end(); } SpacePacketReader currentPacket(packet, size); - + result = packetChecker->checkPacket(currentPacket, size); + if (result != HasReturnvaluesIF::RETURN_OK) { + } #if FSFW_CPP_OSTREAM_ENABLED == 1 && CCSDS_DISTRIBUTOR_DEBUGGING == 1 - sif::info << "CCSDSDistributor::selectDestination has packet with APID " << std::hex - << currentPacket.getAPID() << std::dec << std::endl; + sif::info << "CCSDSDistributor::selectDestination has packet with APID 0x" << std::hex + << currentPacket.getApid() << std::dec << std::endl; #endif auto position = this->queueMap.find(currentPacket.getApid()); if (position != this->queueMap.end()) { @@ -52,7 +55,7 @@ TcDistributor::TcMqMapIter CCSDSDistributor::selectDestination() { } else { // The APID was not found. Forward packet to main SW-APID anyway to // create acceptance failure report. - return this->queueMap.find(this->defaultApid); + return queueMap.find(this->defaultApid); } } @@ -80,6 +83,9 @@ ReturnValue_t CCSDSDistributor::registerApplication(uint16_t apid, MessageQueueI uint16_t CCSDSDistributor::getIdentifier() { return 0; } ReturnValue_t CCSDSDistributor::initialize() { + if (packetChecker == nullptr) { + packetChecker = new CcsdsPacketChecker(ccsds::PacketType::TC); + } ReturnValue_t status = this->TcDistributor::initialize(); this->tcStore = ObjectManager::instance()->get(objects::TC_STORE); if (this->tcStore == nullptr) { diff --git a/src/fsfw/tcdistribution/CCSDSDistributor.h b/src/fsfw/tcdistribution/CCSDSDistributor.h index b5cfc5a4..d6e4f0e7 100644 --- a/src/fsfw/tcdistribution/CCSDSDistributor.h +++ b/src/fsfw/tcdistribution/CCSDSDistributor.h @@ -1,11 +1,12 @@ #ifndef FRAMEWORK_TCDISTRIBUTION_CCSDSDISTRIBUTOR_H_ #define FRAMEWORK_TCDISTRIBUTION_CCSDSDISTRIBUTOR_H_ -#include "../objectmanager/ObjectManagerIF.h" -#include "../storagemanager/StorageManagerIF.h" -#include "../tcdistribution/CCSDSDistributorIF.h" -#include "../tcdistribution/TcDistributor.h" -#include "../tmtcservices/AcceptsTelecommandsIF.h" +#include "fsfw/objectmanager/ObjectManagerIF.h" +#include "fsfw/storagemanager/StorageManagerIF.h" +#include "fsfw/tcdistribution/CCSDSDistributorIF.h" +#include "fsfw/tcdistribution/CcsdsPacketChecker.h" +#include "fsfw/tcdistribution/TcDistributor.h" +#include "fsfw/tmtcservices/AcceptsTelecommandsIF.h" /** * @brief An instantiation of the CCSDSDistributorIF. @@ -24,10 +25,11 @@ class CCSDSDistributor : public TcDistributor, * TcDistributor ctor with a certain object id. * @details * @c tcStore is set in the @c initialize method. - * @param setDefaultApid The default APID, where packets with unknown + * @param unknownApid The default APID, where packets with unknown * destination are sent to. */ - CCSDSDistributor(uint16_t setDefaultApid, object_id_t setObjectId); + CCSDSDistributor(uint16_t unknownApid, object_id_t setObjectId, + CcsdsPacketCheckIF* packetChecker = nullptr); /** * The destructor is empty. */ @@ -63,6 +65,8 @@ class CCSDSDistributor : public TcDistributor, * pure Space Packets and there exists no SpacePacketStored class. */ StorageManagerIF* tcStore = nullptr; + + CcsdsPacketCheckIF* packetChecker = nullptr; }; #endif /* FRAMEWORK_TCDISTRIBUTION_CCSDSDISTRIBUTOR_H_ */ diff --git a/src/fsfw/tcdistribution/CFDPDistributor.cpp b/src/fsfw/tcdistribution/CFDPDistributor.cpp index 5aa84d44..0e6f968c 100644 --- a/src/fsfw/tcdistribution/CFDPDistributor.cpp +++ b/src/fsfw/tcdistribution/CFDPDistributor.cpp @@ -35,7 +35,7 @@ CFDPDistributor::TcMqMapIter CFDPDistributor::selectDestination() { } this->currentPacket->setStoreAddress(this->currentMessage.getStorageId()); if (currentPacket->getFullData() != nullptr) { - tcStatus = checker.checkPacket(currentPacket, currentPacket->getFullPacketLen()); + tcStatus = checker.checkPacket(*currentPacket, currentPacket->getFullPacketLen()); if (tcStatus != HasReturnvaluesIF::RETURN_OK) { #if FSFW_VERBOSE_LEVEL >= 1 #if FSFW_CPP_OSTREAM_ENABLED == 1 diff --git a/src/fsfw/tcdistribution/CMakeLists.txt b/src/fsfw/tcdistribution/CMakeLists.txt index 9cc3d170..532ba2ca 100644 --- a/src/fsfw/tcdistribution/CMakeLists.txt +++ b/src/fsfw/tcdistribution/CMakeLists.txt @@ -6,4 +6,4 @@ target_sources( PusPacketChecker.cpp TcPacketCheckCFDP.cpp CFDPDistributor.cpp - CcsdsPacketCheckerBase.cpp) + CcsdsPacketChecker.cpp) diff --git a/src/fsfw/tcdistribution/CcsdsPacketCheckIF.h b/src/fsfw/tcdistribution/CcsdsPacketCheckIF.h index 55288ae4..6c83532e 100644 --- a/src/fsfw/tcdistribution/CcsdsPacketCheckIF.h +++ b/src/fsfw/tcdistribution/CcsdsPacketCheckIF.h @@ -26,7 +26,7 @@ class CcsdsPacketCheckIF { * - @c INCORRECT_CHECKSUM if checksum is invalid. * - @c ILLEGAL_APID if APID does not match. */ - virtual ReturnValue_t checkPacket(SpacePacketReader* currentPacket, size_t packetLen) = 0; + virtual ReturnValue_t checkPacket(const SpacePacketReader& currentPacket, size_t packetLen) = 0; }; #endif /* FSFW_TCDISTRIBUTION_TCPACKETCHECKIF_H_ */ diff --git a/src/fsfw/tcdistribution/CcsdsPacketChecker.cpp b/src/fsfw/tcdistribution/CcsdsPacketChecker.cpp new file mode 100644 index 00000000..394f5a57 --- /dev/null +++ b/src/fsfw/tcdistribution/CcsdsPacketChecker.cpp @@ -0,0 +1,33 @@ +#include "CcsdsPacketChecker.h" + +#include "fsfw/tcdistribution/definitions.h" +#include "fsfw/tmtcpacket/ccsds/SpacePacketReader.h" + +CcsdsPacketChecker::CcsdsPacketChecker(ccsds::PacketType packetType_, uint8_t ccsdsVersion_) + : packetType(packetType_), ccsdsVersion(ccsdsVersion_) {} + +ReturnValue_t CcsdsPacketChecker::checkPacket(const SpacePacketReader& currentPacket, + size_t packetLen) { + if (checkApid) { + 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; + } + // This assumes that the getFullPacketLen version uses the space packet data length field + if (currentPacket.getFullPacketLen() != packetLen) { + return tcdistrib::INCOMPLETE_PACKET; + } + return HasReturnvaluesIF::RETURN_OK; +} + +void CcsdsPacketChecker::setApidToCheck(uint16_t apid_) { + apid = apid_; + checkApid = true; +} diff --git a/src/fsfw/tcdistribution/CcsdsPacketChecker.h b/src/fsfw/tcdistribution/CcsdsPacketChecker.h new file mode 100644 index 00000000..f910aac4 --- /dev/null +++ b/src/fsfw/tcdistribution/CcsdsPacketChecker.h @@ -0,0 +1,20 @@ +#ifndef FSFW_TESTS_CCSDSPACKETCHECKERBASE_H +#define FSFW_TESTS_CCSDSPACKETCHECKERBASE_H + +#include "CcsdsPacketCheckIF.h" +#include "fsfw/tmtcpacket/ccsds/SpacePacketIF.h" + +class CcsdsPacketChecker : public CcsdsPacketCheckIF, public HasReturnvaluesIF { + public: + CcsdsPacketChecker(ccsds::PacketType packetType, uint8_t ccsdsVersion = 0b000); + + void setApidToCheck(uint16_t apid); + ReturnValue_t checkPacket(const SpacePacketReader& currentPacket, size_t packetLen) override; + + protected: + bool checkApid = false; + uint16_t apid = 0; + ccsds::PacketType packetType; + uint8_t ccsdsVersion; +}; +#endif // FSFW_TESTS_CCSDSPACKETCHECKERBASE_H diff --git a/src/fsfw/tcdistribution/CcsdsPacketCheckerBase.cpp b/src/fsfw/tcdistribution/CcsdsPacketCheckerBase.cpp deleted file mode 100644 index e1b6337f..00000000 --- a/src/fsfw/tcdistribution/CcsdsPacketCheckerBase.cpp +++ /dev/null @@ -1,22 +0,0 @@ -#include "CcsdsPacketCheckerBase.h" - -#include "fsfw/tcdistribution/definitions.h" -#include "fsfw/tmtcpacket/ccsds/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 deleted file mode 100644 index 0f7f7e14..00000000 --- a/src/fsfw/tcdistribution/CcsdsPacketCheckerBase.h +++ /dev/null @@ -1,17 +0,0 @@ -#ifndef FSFW_TESTS_CCSDSPACKETCHECKERBASE_H -#define FSFW_TESTS_CCSDSPACKETCHECKERBASE_H - -#include "CcsdsPacketCheckIF.h" -#include "fsfw/tmtcpacket/ccsds/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/CfdpPacketChecker.h b/src/fsfw/tcdistribution/CfdpPacketChecker.h index 0838efc2..5ad802f9 100644 --- a/src/fsfw/tcdistribution/CfdpPacketChecker.h +++ b/src/fsfw/tcdistribution/CfdpPacketChecker.h @@ -25,7 +25,7 @@ class CfdpPacketChecker : public CcsdsPacketCheckIF, public HasReturnvaluesIF { */ explicit CfdpPacketChecker(uint16_t setApid); - ReturnValue_t checkPacket(SpacePacketReader* currentPacket, size_t packetLen) override; + ReturnValue_t checkPacket(const SpacePacketReader& currentPacket, size_t packetLen) override; [[nodiscard]] uint16_t getApid() const; }; diff --git a/src/fsfw/tcdistribution/PusDistributor.cpp b/src/fsfw/tcdistribution/PusDistributor.cpp index 36bcd34b..85672439 100644 --- a/src/fsfw/tcdistribution/PusDistributor.cpp +++ b/src/fsfw/tcdistribution/PusDistributor.cpp @@ -6,7 +6,7 @@ #include "fsfw/tcdistribution/CCSDSDistributorIF.h" #include "fsfw/tmtcservices/PusVerificationReport.h" -#define PUS_DISTRIBUTOR_DEBUGGING 0 +#define PUS_DISTRIBUTOR_DEBUGGING 1 PusDistributor::PusDistributor(uint16_t setApid, object_id_t setObjectId, CCSDSDistributorIF* distributor, StorageManagerIF* store_) @@ -20,71 +20,56 @@ PusDistributor::~PusDistributor() = default; 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 << ", " - << storeId.packetIndex << std::endl; + store_address_t storeId = currentMessage.getStorageId(); + sif::debug << "PUSDistributor::handlePacket received: " << storeId.poolIndex << ", " + << storeId.packetIndex << std::endl; #endif - auto queueMapIt = this->queueMap.end(); - if (reader.isNull()) { - return queueMapIt; - } - // 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.setReadOnlyData(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"; - if (tcStatus == tcdistrib::INCORRECT_CHECKSUM) { - keyword = "checksum"; - } else if (tcStatus == tcdistrib::INCORRECT_PRIMARY_HEADER) { - keyword = "incorrect primary header"; - } else if (tcStatus == tcdistrib::INVALID_APID) { - keyword = "illegal APID"; - } else if (tcStatus == tcdistrib::INCORRECT_SECONDARY_HEADER) { - keyword = "incorrect secondary header"; - } else if (tcStatus == tcdistrib::INCOMPLETE_PACKET) { - keyword = "incomplete packet"; - } -#if FSFW_CPP_OSTREAM_ENABLED == 1 - sif::warning << "PUSDistributor::handlePacket: Packet format invalid, " << keyword - << " error" << std::endl; -#else - sif::printWarning("PUSDistributor::handlePacket: Packet format invalid, %s error\n", - keyword); -#endif -#endif - } - uint32_t queue_id = reader.getService(); - queueMapIt = this->queueMap.find(queue_id); - } else { - tcStatus = PACKET_LOST; + auto queueMapIt = queueMap.end(); + // TODO: Need to set the data + const uint8_t* packetPtr = nullptr; + size_t packetLen = 0; + if (store->getData(currentMessage.getStorageId(), &packetPtr, &packetLen) != + HasReturnvaluesIF::RETURN_OK) { + return queueMapIt; + } + ReturnValue_t result = reader.setReadOnlyData(packetPtr, packetLen); + if (result != HasReturnvaluesIF::RETURN_OK) { + tcStatus = PACKET_LOST; + return queueMapIt; + } + // CRC check done by checker + result = reader.parseDataWithoutCrcCheck(); + if (result != HasReturnvaluesIF::RETURN_OK) { + tcStatus = PACKET_LOST; + return queueMapIt; + } + if (reader.getFullData() != nullptr) { + tcStatus = checker.checkPacket(reader, reader.getFullPacketLen()); + if (tcStatus != HasReturnvaluesIF::RETURN_OK) { + checkerFailurePrinter(); } + uint32_t queue_id = reader.getService(); + queueMapIt = queueMap.find(queue_id); + } else { + tcStatus = PACKET_LOST; + } - if (queueMapIt == this->queueMap.end()) { - tcStatus = DESTINATION_NOT_FOUND; + if (queueMapIt == this->queueMap.end()) { + tcStatus = DESTINATION_NOT_FOUND; #if FSFW_VERBOSE_LEVEL >= 1 #if FSFW_CPP_OSTREAM_ENABLED == 1 - sif::debug << "PUSDistributor::handlePacket: Destination not found" << std::endl; + sif::debug << "PUSDistributor::handlePacket: Destination not found" << std::endl; #else - sif::printDebug("PUSDistributor::handlePacket: Destination not found\n"); + sif::printDebug("PUSDistributor::handlePacket: Destination not found\n"); #endif /* !FSFW_CPP_OSTREAM_ENABLED == 1 */ #endif - } + } - if (tcStatus != RETURN_OK) { - return this->queueMap.end(); - } else { - return queueMapIt; - } + if (tcStatus != RETURN_OK) { + return this->queueMap.end(); + } else { + return queueMapIt; + } } ReturnValue_t PusDistributor::registerService(AcceptsTelecommandsIF* service) { @@ -141,7 +126,7 @@ ReturnValue_t PusDistributor::initialize() { return ObjectManagerIF::CHILD_INIT_FAILED; } } - if(ccsdsDistributor == nullptr) { + if (ccsdsDistributor == nullptr) { #if FSFW_CPP_OSTREAM_ENABLED == 1 sif::error << "PUSDistributor::initialize: Packet source invalid" << std::endl; sif::error << " Make sure it exists and implements CCSDSDistributorIF!" << std::endl; @@ -151,5 +136,34 @@ ReturnValue_t PusDistributor::initialize() { #endif return ObjectManagerIF::CHILD_INIT_FAILED; } + if (verifyChannel == nullptr) { + verifyChannel = ObjectManager::instance()->get(objects::TC_VERIFICATOR); + if (verifyChannel == nullptr) { + return ObjectManagerIF::CHILD_INIT_FAILED; + } + } return ccsdsDistributor->registerApplication(this); } + +void PusDistributor::checkerFailurePrinter() const { +#if FSFW_VERBOSE_LEVEL >= 1 + const char* keyword = "unnamed error"; + if (tcStatus == tcdistrib::INCORRECT_CHECKSUM) { + keyword = "checksum"; + } else if (tcStatus == tcdistrib::INCORRECT_PRIMARY_HEADER) { + keyword = "incorrect primary header"; + } else if (tcStatus == tcdistrib::INVALID_APID) { + keyword = "illegal APID"; + } else if (tcStatus == tcdistrib::INCORRECT_SECONDARY_HEADER) { + keyword = "incorrect secondary header"; + } else if (tcStatus == tcdistrib::INCOMPLETE_PACKET) { + keyword = "incomplete packet"; + } +#if FSFW_CPP_OSTREAM_ENABLED == 1 + sif::warning << "PUSDistributor::handlePacket: Packet format invalid, " << keyword << " error" + << std::endl; +#else + sif::printWarning("PUSDistributor::handlePacket: Packet format invalid, %s error\n", keyword); +#endif +#endif +} diff --git a/src/fsfw/tcdistribution/PusDistributor.h b/src/fsfw/tcdistribution/PusDistributor.h index bb0c7a04..7daf5d83 100644 --- a/src/fsfw/tcdistribution/PusDistributor.h +++ b/src/fsfw/tcdistribution/PusDistributor.h @@ -73,6 +73,8 @@ class PusDistributor : public TcDistributor, public PUSDistributorIF, public Acc * success/failure messages. */ ReturnValue_t callbackAfterSending(ReturnValue_t queueStatus) override; + + void checkerFailurePrinter() const; }; #endif /* FSFW_TCDISTRIBUTION_PUSDISTRIBUTOR_H_ */ diff --git a/src/fsfw/tcdistribution/PusPacketChecker.cpp b/src/fsfw/tcdistribution/PusPacketChecker.cpp index 828303b2..8ea8b6a8 100644 --- a/src/fsfw/tcdistribution/PusPacketChecker.cpp +++ b/src/fsfw/tcdistribution/PusPacketChecker.cpp @@ -5,40 +5,26 @@ #include "fsfw/tcdistribution/definitions.h" #include "fsfw/tmtcpacket/pus/tc/PusTcReader.h" -PusPacketChecker::PusPacketChecker(uint16_t setApid, ccsds::PacketType packetType_, +PusPacketChecker::PusPacketChecker(uint16_t apid, ccsds::PacketType packetType_, ecss::PusVersion pusVersion_) - : CcsdsPacketCheckerBase(setApid, packetType_), pusVersion(pusVersion_) {} + : pusVersion(pusVersion_), apid(apid) {} -ReturnValue_t PusPacketChecker::checkPacket(PacketCheckIF* pusPacket, size_t packetLen) { - if (pusPacket == nullptr) { - return RETURN_FAILED; - } +ReturnValue_t PusPacketChecker::checkPacket(const PusTcReader& pusPacket, size_t packetLen) { // Other primary header fields are checked by base class - if (not pusPacket->hasSecHeader()) { + if (not pusPacket.hasSecHeader()) { return tcdistrib::INVALID_SEC_HEADER_FIELD; } - uint16_t calculated_crc = - CRC::crc16ccitt(pusPacket->getFullData(), pusPacket->getFullPacketLen()); + 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.getApid() != apid) { + return tcdistrib::INVALID_APID; } - if (pusPacket->getPusVersion() != pusVersion) { + if (pusPacket.getPusVersion() != pusVersion) { return tcdistrib::INVALID_PUS_VERSION; } - return RETURN_OK; + return HasReturnvaluesIF::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 index 431ee5a8..ee56e1f8 100644 --- a/src/fsfw/tcdistribution/PusPacketChecker.h +++ b/src/fsfw/tcdistribution/PusPacketChecker.h @@ -1,38 +1,34 @@ #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/defs.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 { +class PusPacketChecker { 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); + explicit PusPacketChecker(uint16_t apid, ccsds::PacketType packetType, + ecss::PusVersion = ecss::PusVersion::PUS_C); - ReturnValue_t checkPacket(PacketCheckIF* currentPacket, size_t packetLen); + ReturnValue_t checkPacket(const PusTcReader& currentPacket, size_t packetLen); [[nodiscard]] uint16_t getApid() const; protected: ecss::PusVersion pusVersion; + uint16_t apid; 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 600b3ca9..4ec85ed9 100644 --- a/src/fsfw/tcdistribution/TcDistributor.cpp +++ b/src/fsfw/tcdistribution/TcDistributor.cpp @@ -11,25 +11,24 @@ TcDistributor::TcDistributor(object_id_t objectId) : SystemObject(objectId) { TcDistributor::~TcDistributor() { QueueFactory::instance()->deleteMessageQueue(tcQueue); } ReturnValue_t TcDistributor::performOperation(uint8_t opCode) { - ReturnValue_t status = RETURN_OK; + ReturnValue_t status; for (status = tcQueue->receiveMessage(¤tMessage); status == RETURN_OK; status = tcQueue->receiveMessage(¤tMessage)) { status = handlePacket(); } if (status == MessageQueueIF::EMPTY) { return RETURN_OK; - } else { - return status; } + return status; } ReturnValue_t TcDistributor::handlePacket() { - auto queueMapIt = this->selectDestination(); - ReturnValue_t returnValue = RETURN_FAILED; - if (queueMapIt != this->queueMap.end()) { - returnValue = this->tcQueue->sendMessage(queueMapIt->second, &this->currentMessage); + auto queueMapIt = selectDestination(); + ReturnValue_t result = HasReturnvaluesIF::RETURN_FAILED; + if (queueMapIt != queueMap.end()) { + result = tcQueue->sendMessage(queueMapIt->second, ¤tMessage); } - return this->callbackAfterSending(returnValue); + return callbackAfterSending(result); } void TcDistributor::print() { diff --git a/src/fsfw/tcdistribution/TcPacketCheckCFDP.cpp b/src/fsfw/tcdistribution/TcPacketCheckCFDP.cpp index 555c85b4..9a0b89bd 100644 --- a/src/fsfw/tcdistribution/TcPacketCheckCFDP.cpp +++ b/src/fsfw/tcdistribution/TcPacketCheckCFDP.cpp @@ -3,7 +3,8 @@ CfdpPacketChecker::CfdpPacketChecker(uint16_t setApid) : apid(setApid) {} -ReturnValue_t CfdpPacketChecker::checkPacket(SpacePacketReader* currentPacket, size_t packetLen) { +ReturnValue_t CfdpPacketChecker::checkPacket(const SpacePacketReader& currentPacket, + size_t packetLen) { return RETURN_OK; } diff --git a/src/fsfw/timemanager/TimeStamperIF.h b/src/fsfw/timemanager/TimeStamperIF.h index df680b6c..44cf0212 100644 --- a/src/fsfw/timemanager/TimeStamperIF.h +++ b/src/fsfw/timemanager/TimeStamperIF.h @@ -26,6 +26,8 @@ class TimeStamperIF : public SerializeIF { virtual ReturnValue_t addTimeStamp(uint8_t* buffer, uint8_t maxSize) = 0; ~TimeStamperIF() override = default; + + protected: }; #endif /* FSFW_TIMEMANAGER_TIMESTAMPERIF_H_ */ diff --git a/src/fsfw/tmtcpacket/ReadablePacketIF.h b/src/fsfw/tmtcpacket/ReadablePacketIF.h index bbffbe10..4f2f09e8 100644 --- a/src/fsfw/tmtcpacket/ReadablePacketIF.h +++ b/src/fsfw/tmtcpacket/ReadablePacketIF.h @@ -10,6 +10,6 @@ class ReadablePacketIF { /** * This method returns a raw uint8_t pointer to the readable data */ - virtual const uint8_t* getFullData() = 0; + [[nodiscard]] virtual const uint8_t* getFullData() const = 0; }; #endif // FSFW_TMTCPACKET_SPACEPACKETREADERIF_H diff --git a/src/fsfw/tmtcpacket/ccsds/SpacePacketReader.cpp b/src/fsfw/tmtcpacket/ccsds/SpacePacketReader.cpp index 76f92107..b6f03de9 100644 --- a/src/fsfw/tmtcpacket/ccsds/SpacePacketReader.cpp +++ b/src/fsfw/tmtcpacket/ccsds/SpacePacketReader.cpp @@ -42,7 +42,7 @@ ReturnValue_t SpacePacketReader::setInternalFields(const uint8_t* data, size_t m return checkSize(); } -const uint8_t* SpacePacketReader::getFullData() { +const uint8_t* SpacePacketReader::getFullData() const { return reinterpret_cast(spHeader); } size_t SpacePacketReader::getBufSize() const { return bufSize; } diff --git a/src/fsfw/tmtcpacket/ccsds/SpacePacketReader.h b/src/fsfw/tmtcpacket/ccsds/SpacePacketReader.h index 0d075bae..dbffa7bf 100644 --- a/src/fsfw/tmtcpacket/ccsds/SpacePacketReader.h +++ b/src/fsfw/tmtcpacket/ccsds/SpacePacketReader.h @@ -66,7 +66,7 @@ class SpacePacketReader : public SpacePacketIF, [[nodiscard]] uint16_t getPacketSeqCtrlRaw() const override; [[nodiscard]] uint16_t getPacketDataLen() const override; - const uint8_t* getFullData() override; + [[nodiscard]] const uint8_t* getFullData() const override; // Helper methods: [[nodiscard]] ReturnValue_t checkSize() const; diff --git a/src/fsfw/tmtcpacket/pus/tc/PusTcReader.cpp b/src/fsfw/tmtcpacket/pus/tc/PusTcReader.cpp index f50affa7..31bb1011 100644 --- a/src/fsfw/tmtcpacket/pus/tc/PusTcReader.cpp +++ b/src/fsfw/tmtcpacket/pus/tc/PusTcReader.cpp @@ -67,7 +67,7 @@ uint16_t PusTcReader::getPacketSeqCtrlRaw() const { return spReader.getPacketSeq uint16_t PusTcReader::getPacketDataLen() const { return spReader.getPacketDataLen(); } -const uint8_t* PusTcReader::getFullData() { return pointers.spHeaderStart; } +const uint8_t* PusTcReader::getFullData() const { return pointers.spHeaderStart; } ReturnValue_t PusTcReader::setData(uint8_t* pData, size_t size_, void* args) { pointers.spHeaderStart = pData; diff --git a/src/fsfw/tmtcpacket/pus/tc/PusTcReader.h b/src/fsfw/tmtcpacket/pus/tc/PusTcReader.h index 1b9eea49..03af43a9 100644 --- a/src/fsfw/tmtcpacket/pus/tc/PusTcReader.h +++ b/src/fsfw/tmtcpacket/pus/tc/PusTcReader.h @@ -54,7 +54,7 @@ class PusTcReader : public PusTcIF, [[nodiscard]] uint8_t getSubService() const override; [[nodiscard]] uint16_t getSourceId() const override; [[nodiscard]] uint16_t getErrorControl() const; - const uint8_t* getFullData() override; + const uint8_t* getFullData() const override; ReturnValue_t setReadOnlyData(const uint8_t* data, size_t size); [[nodiscard]] const uint8_t* getUserData() const override; diff --git a/src/fsfw/tmtcpacket/pus/tm/PusTmCreator.cpp b/src/fsfw/tmtcpacket/pus/tm/PusTmCreator.cpp index 850eb078..348308d1 100644 --- a/src/fsfw/tmtcpacket/pus/tm/PusTmCreator.cpp +++ b/src/fsfw/tmtcpacket/pus/tm/PusTmCreator.cpp @@ -12,13 +12,9 @@ PusTmCreator::PusTmCreator(SpacePacketParams initSpParams, PusTmParams initPusPa PusTmCreator::PusTmCreator() { setup(); } -void PusTmCreator::disableCrcCalculation() { - calculateCrcOnSerialization = false; -} +void PusTmCreator::disableCrcCalculation() { calculateCrcOnSerialization = false; } -void PusTmCreator::enableCrcCalculation() { - calculateCrcOnSerialization = true; -} +void PusTmCreator::enableCrcCalculation() { calculateCrcOnSerialization = true; } uint16_t PusTmCreator::getPacketIdRaw() const { return spCreator.getPacketIdRaw(); } @@ -74,10 +70,13 @@ ReturnValue_t PusTmCreator::serialize(uint8_t** buffer, size_t* size, size_t max if (result != HasReturnvaluesIF::RETURN_OK) { return result; } - result = pusParams.secHeader.timeStamper->serialize(buffer, size, maxSize, streamEndianness); - if (result != HasReturnvaluesIF::RETURN_OK) { - return result; + if (getTimestamper() != nullptr) { + result = pusParams.secHeader.timeStamper->serialize(buffer, size, maxSize, streamEndianness); + if (result != HasReturnvaluesIF::RETURN_OK) { + return result; + } } + if (pusParams.dataWrapper.type == ecss::DataTypes::RAW and pusParams.dataWrapper.dataUnion.raw.data != nullptr) { std::memcpy(*buffer, pusParams.dataWrapper.dataUnion.raw.data, userDataLen); diff --git a/src/fsfw/tmtcpacket/pus/tm/PusTmReader.cpp b/src/fsfw/tmtcpacket/pus/tm/PusTmReader.cpp index 0dfab4ce..a3dbb7b0 100644 --- a/src/fsfw/tmtcpacket/pus/tm/PusTmReader.cpp +++ b/src/fsfw/tmtcpacket/pus/tm/PusTmReader.cpp @@ -15,7 +15,7 @@ ReturnValue_t PusTmReader::parseDataWithCrcCheck() { return parseData(true); } ReturnValue_t PusTmReader::parseDataWithoutCrcCheck() { return parseData(false); } -const uint8_t *PusTmReader::getFullData() { return spReader.getFullData(); } +const uint8_t *PusTmReader::getFullData() const { return spReader.getFullData(); } ReturnValue_t PusTmReader::setReadOnlyData(const uint8_t *data, size_t size) { return setData(const_cast(data), size, nullptr); diff --git a/src/fsfw/tmtcpacket/pus/tm/PusTmReader.h b/src/fsfw/tmtcpacket/pus/tm/PusTmReader.h index 780b3e5f..fdad1b6c 100644 --- a/src/fsfw/tmtcpacket/pus/tm/PusTmReader.h +++ b/src/fsfw/tmtcpacket/pus/tm/PusTmReader.h @@ -19,7 +19,7 @@ class PusTmReader : public PusTmIF, ReturnValue_t parseDataWithoutCrcCheck(); ReturnValue_t parseDataWithCrcCheck(); - const uint8_t* getFullData() override; + const uint8_t* getFullData() const override; explicit operator bool() const; [[nodiscard]] bool isNull() const; diff --git a/src/fsfw/tmtcservices/CommandingServiceBase.cpp b/src/fsfw/tmtcservices/CommandingServiceBase.cpp index 0be7c3c8..08ba599a 100644 --- a/src/fsfw/tmtcservices/CommandingServiceBase.cpp +++ b/src/fsfw/tmtcservices/CommandingServiceBase.cpp @@ -103,6 +103,12 @@ ReturnValue_t CommandingServiceBase::initialize() { // Generally, all TM packets will pass through a layer where the sequence count is set. // This avoids duplicate calculation of the CRC16 tmStoreHelper.disableCrcCalculation(); + if (tmTimeStamper == nullptr) { + auto timerStamper = ObjectManager::instance()->get(objects::TIME_STAMPER); + if (timerStamper != nullptr) { + tmStoreHelper.setTimeStamper(*timerStamper); + } + } if (errReporter == nullptr) { errReporter = diff --git a/src/fsfw/tmtcservices/CommandingServiceBase.h b/src/fsfw/tmtcservices/CommandingServiceBase.h index 8017ecc8..f9070d17 100644 --- a/src/fsfw/tmtcservices/CommandingServiceBase.h +++ b/src/fsfw/tmtcservices/CommandingServiceBase.h @@ -267,6 +267,7 @@ class CommandingServiceBase : public SystemObject, MessageQueueIF* commandQueue = nullptr; MessageQueueIF* requestQueue = nullptr; + TimeStamperIF* tmTimeStamper = nullptr; VerificationReporterIF* verificationReporter; InternalErrorReporterIF* errReporter = nullptr; diff --git a/src/fsfw/tmtcservices/PusServiceBase.cpp b/src/fsfw/tmtcservices/PusServiceBase.cpp index 094a4156..d3d23ed7 100644 --- a/src/fsfw/tmtcservices/PusServiceBase.cpp +++ b/src/fsfw/tmtcservices/PusServiceBase.cpp @@ -4,6 +4,7 @@ #include "fsfw/objectmanager/ObjectManager.h" #include "fsfw/serviceinterface/ServiceInterface.h" #include "fsfw/tcdistribution/PUSDistributorIF.h" +#include "fsfw/timemanager/CdsShortTimeStamper.h" #include "fsfw/tmtcservices/AcceptsTelemetryIF.h" #include "fsfw/tmtcservices/PusVerificationReport.h" #include "fsfw/tmtcservices/TmTcMessage.h" @@ -163,6 +164,12 @@ void PusServiceBase::initializeTmSendHelper(TmSendHelper& tmSendHelper) { void PusServiceBase::initializeTmStoreHelper(TmStoreHelper& tmStoreHelper) const { tmStoreHelper.setApid(psbParams.apid); + if (psbParams.timeStamper == nullptr) { + auto timerStamper = ObjectManager::instance()->get(objects::TIME_STAMPER); + if (timerStamper != nullptr) { + tmStoreHelper.setTimeStamper(*timerStamper); + } + } } void PusServiceBase::setVerificationReporter(VerificationReporterIF& reporter) { diff --git a/src/fsfw/tmtcservices/PusServiceBase.h b/src/fsfw/tmtcservices/PusServiceBase.h index 9c75870a..43a2c0d4 100644 --- a/src/fsfw/tmtcservices/PusServiceBase.h +++ b/src/fsfw/tmtcservices/PusServiceBase.h @@ -65,6 +65,7 @@ struct PsbParams { * register itself at that object. */ PUSDistributorIF* pusDistributor = nullptr; + TimeStamperIF* timeStamper = nullptr; }; namespace Factory { @@ -133,7 +134,9 @@ class PusServiceBase : public ExecutableObjectIF, */ void initializeTmSendHelper(TmSendHelper& tmSendHelper); /** - * Helper methods if the implementing class wants to store telemetry + * Helper methods if the implementing class wants to store telemetry. It will set the correct APID + * and it will also attempt to set a valid time stamper. If the manually specified time stamper is + * null, it will attempt to find a suitable one using @objects::TIME_STAMPER * @param tmSendHelper */ void initializeTmStoreHelper(TmStoreHelper& tmStoreHelper) const; diff --git a/src/fsfw/tmtcservices/TmSendHelper.cpp b/src/fsfw/tmtcservices/TmSendHelper.cpp index ddbb86ba..a8e23186 100644 --- a/src/fsfw/tmtcservices/TmSendHelper.cpp +++ b/src/fsfw/tmtcservices/TmSendHelper.cpp @@ -5,8 +5,10 @@ TmSendHelper::TmSendHelper() = default; TmSendHelper::TmSendHelper(MessageQueueIF &queue, InternalErrorReporterIF &reporter, - MessageQueueId_t tmtcMsgDest) - : defaultDest(tmtcMsgDest), queue(&queue), errReporter(&reporter) {} + MessageQueueId_t defaultDest) + : queue(&queue), errReporter(&reporter) { + queue.setDefaultDestination(defaultDest); +} TmSendHelper::TmSendHelper(MessageQueueIF &queue, InternalErrorReporterIF &reporter) : queue(&queue), errReporter(&reporter) {} @@ -14,11 +16,26 @@ TmSendHelper::TmSendHelper(MessageQueueIF &queue, InternalErrorReporterIF &repor TmSendHelper::TmSendHelper(InternalErrorReporterIF &reporter) : errReporter(&reporter) {} ReturnValue_t TmSendHelper::sendPacket(const store_address_t &storeId) { + return sendPacket(getDefaultDestination(), storeId); +} + +void TmSendHelper::setDefaultDestination(MessageQueueId_t msgDest) { + if (queue != nullptr) { + queue->setDefaultDestination(msgDest); + }; +} + +void TmSendHelper::setInternalErrorReporter(InternalErrorReporterIF &reporter) { + errReporter = &reporter; +} +void TmSendHelper::setMsgQueue(MessageQueueIF &queue_) { queue = &queue_; } + +ReturnValue_t TmSendHelper::sendPacket(MessageQueueId_t dest, const store_address_t &storeId) { if (queue == nullptr) { return HasReturnvaluesIF::RETURN_FAILED; } TmTcMessage message(storeId); - ReturnValue_t result = queue->sendMessage(defaultDest, &message, ignoreFault); + ReturnValue_t result = queue->sendMessage(dest, &message, ignoreFault); if (result != HasReturnvaluesIF::RETURN_OK) { if (errReporter != nullptr and not ignoreFault) { errReporter->lostTm(); @@ -28,19 +45,12 @@ ReturnValue_t TmSendHelper::sendPacket(const store_address_t &storeId) { return result; } -void TmSendHelper::setDefaultDestination(MessageQueueId_t msgDest) { defaultDest = msgDest; } - -void TmSendHelper::setInternalErrorReporter(InternalErrorReporterIF &reporter) { - errReporter = &reporter; +MessageQueueId_t TmSendHelper::getDefaultDestination() const { + if (queue != nullptr) { + return queue->getDefaultDestination(); + }; + return MessageQueueIF::NO_QUEUE; } -void TmSendHelper::setMsgQueue(MessageQueueIF &queue_) { queue = &queue_; } - -ReturnValue_t TmSendHelper::sendPacket(MessageQueueId_t dest, const store_address_t &storeId) { - setDefaultDestination(dest); - return sendPacket(storeId); -} - -MessageQueueId_t TmSendHelper::getDefaultDestination() const { return defaultDest; } bool TmSendHelper::areFaultsIgnored() const { return ignoreFault; } void TmSendHelper::ignoreFaults() { ignoreFault = true; } diff --git a/src/fsfw/tmtcservices/TmSendHelper.h b/src/fsfw/tmtcservices/TmSendHelper.h index a9feab75..5d39d5d1 100644 --- a/src/fsfw/tmtcservices/TmSendHelper.h +++ b/src/fsfw/tmtcservices/TmSendHelper.h @@ -29,7 +29,6 @@ class TmSendHelper { ReturnValue_t sendPacket(const store_address_t& storeId); private: - MessageQueueId_t defaultDest = MessageQueueIF::NO_QUEUE; bool ignoreFault = false; MessageQueueIF* queue = nullptr; InternalErrorReporterIF* errReporter = nullptr; -- 2.43.0 From c5ad9b5fa928858930d3a33efdf87e677c574a7c Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Wed, 27 Jul 2022 17:13:42 +0200 Subject: [PATCH 081/108] switch off debugging switches --- src/fsfw/tcdistribution/CCSDSDistributor.cpp | 2 +- src/fsfw/tcdistribution/PusDistributor.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/fsfw/tcdistribution/CCSDSDistributor.cpp b/src/fsfw/tcdistribution/CCSDSDistributor.cpp index 4dad31aa..7c2974a4 100644 --- a/src/fsfw/tcdistribution/CCSDSDistributor.cpp +++ b/src/fsfw/tcdistribution/CCSDSDistributor.cpp @@ -4,7 +4,7 @@ #include "fsfw/serviceinterface/ServiceInterface.h" #include "fsfw/tmtcpacket/ccsds/SpacePacketReader.h" -#define CCSDS_DISTRIBUTOR_DEBUGGING 1 +#define CCSDS_DISTRIBUTOR_DEBUGGING 0 CCSDSDistributor::CCSDSDistributor(uint16_t setDefaultApid, object_id_t setObjectId, CcsdsPacketCheckIF* packetChecker) diff --git a/src/fsfw/tcdistribution/PusDistributor.cpp b/src/fsfw/tcdistribution/PusDistributor.cpp index 85672439..ade49201 100644 --- a/src/fsfw/tcdistribution/PusDistributor.cpp +++ b/src/fsfw/tcdistribution/PusDistributor.cpp @@ -6,7 +6,7 @@ #include "fsfw/tcdistribution/CCSDSDistributorIF.h" #include "fsfw/tmtcservices/PusVerificationReport.h" -#define PUS_DISTRIBUTOR_DEBUGGING 1 +#define PUS_DISTRIBUTOR_DEBUGGING 0 PusDistributor::PusDistributor(uint16_t setApid, object_id_t setObjectId, CCSDSDistributorIF* distributor, StorageManagerIF* store_) -- 2.43.0 From f591b9793cf777c974afaa4b73ee764b0769654a Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Wed, 27 Jul 2022 17:33:39 +0200 Subject: [PATCH 082/108] pass timeReader to Pus ZC writer --- src/fsfw/timemanager/CcsdsTimeStampReader.h | 2 -- src/fsfw/timemanager/CdsShortTimeStamper.cpp | 10 ++++++++++ src/fsfw/timemanager/CdsShortTimeStamper.h | 8 +++++++- src/fsfw/timemanager/TimeReaderIF.h | 9 +++------ src/fsfw/timemanager/TimeStampIF.h | 20 ++++++++++++++++++++ src/fsfw/timemanager/TimeStamperIF.h | 16 +++------------- src/fsfw/tmtcpacket/pus/tm/PusTmReader.cpp | 2 +- src/fsfw/tmtcpacket/pus/tm/PusTmReader.h | 2 +- src/fsfw/tmtcpacket/pus/tm/PusTmZcWriter.cpp | 3 ++- src/fsfw/tmtcpacket/pus/tm/PusTmZcWriter.h | 2 +- 10 files changed, 48 insertions(+), 26 deletions(-) create mode 100644 src/fsfw/timemanager/TimeStampIF.h diff --git a/src/fsfw/timemanager/CcsdsTimeStampReader.h b/src/fsfw/timemanager/CcsdsTimeStampReader.h index f323c87e..0bec2553 100644 --- a/src/fsfw/timemanager/CcsdsTimeStampReader.h +++ b/src/fsfw/timemanager/CcsdsTimeStampReader.h @@ -7,8 +7,6 @@ class CcsdsTimestampReader : public TimeReaderIF { public: - ReturnValue_t readTimeStamp(const uint8_t* buffer, uint8_t maxSize) override; - size_t getTimestampLen() override; timeval& getTime() override; private: diff --git a/src/fsfw/timemanager/CdsShortTimeStamper.cpp b/src/fsfw/timemanager/CdsShortTimeStamper.cpp index af0344e3..cdce62c1 100644 --- a/src/fsfw/timemanager/CdsShortTimeStamper.cpp +++ b/src/fsfw/timemanager/CdsShortTimeStamper.cpp @@ -36,4 +36,14 @@ ReturnValue_t CdsShortTimeStamper::deSerialize(const uint8_t **buffer, size_t *s return HasReturnvaluesIF::RETURN_FAILED; } +ReturnValue_t CdsShortTimeStamper::readTimeStamp(const uint8_t *buffer, size_t maxSize) { + if (maxSize < getTimestampSize()) { + return SerializeIF::STREAM_TOO_SHORT; + } + size_t foundLen = 0; + return CCSDSTime::convertFromCcsds(&readTime, buffer, &foundLen, maxSize); +} + +timeval &CdsShortTimeStamper::getTime() { return readTime; } + size_t CdsShortTimeStamper::getTimestampSize() const { return TIMESTAMP_LEN; } diff --git a/src/fsfw/timemanager/CdsShortTimeStamper.h b/src/fsfw/timemanager/CdsShortTimeStamper.h index d392c1a6..4b1f6c28 100644 --- a/src/fsfw/timemanager/CdsShortTimeStamper.h +++ b/src/fsfw/timemanager/CdsShortTimeStamper.h @@ -2,6 +2,7 @@ #define FSFW_TIMEMANAGER_TIMESTAMPER_H_ #include "CCSDSTime.h" +#include "TimeReaderIF.h" #include "TimeStamperIF.h" #include "fsfw/objectmanager/SystemObject.h" @@ -14,7 +15,7 @@ * overriding the #addTimeStamp function. * @ingroup utility */ -class CdsShortTimeStamper : public TimeStamperIF, public SystemObject { +class CdsShortTimeStamper : public TimeStamperIF, public TimeReaderIF, public SystemObject { public: static constexpr size_t TIMESTAMP_LEN = 7; /** @@ -37,7 +38,12 @@ class CdsShortTimeStamper : public TimeStamperIF, public SystemObject { [[nodiscard]] size_t getSerializedSize() const override; ReturnValue_t deSerialize(const uint8_t **buffer, size_t *size, Endianness streamEndianness) override; + ReturnValue_t readTimeStamp(const uint8_t *buffer, size_t maxSize) override; + timeval &getTime() override; [[nodiscard]] size_t getTimestampSize() const override; + + private: + timeval readTime{}; }; #endif /* FSFW_TIMEMANAGER_TIMESTAMPER_H_ */ diff --git a/src/fsfw/timemanager/TimeReaderIF.h b/src/fsfw/timemanager/TimeReaderIF.h index cfad90ff..289a0058 100644 --- a/src/fsfw/timemanager/TimeReaderIF.h +++ b/src/fsfw/timemanager/TimeReaderIF.h @@ -3,16 +3,13 @@ #include +#include "TimeStampIF.h" #include "fsfw/returnvalues/HasReturnvaluesIF.h" -class TimeReaderIF { +class TimeReaderIF : public TimeStampIF { public: - virtual ~TimeReaderIF() = default; + ~TimeReaderIF() override = default; virtual ReturnValue_t readTimeStamp(const uint8_t* buffer, size_t maxSize) = 0; - // Would be nice to have this, but the clock backend needs to be redesigned - // virtual ReturnValue_t readTimestampLen(const uint8_t* buffer, uint8_t maxSize, size_t& - // timestampLen) = 0; - virtual size_t getTimestampLen() = 0; virtual timeval& getTime() = 0; }; diff --git a/src/fsfw/timemanager/TimeStampIF.h b/src/fsfw/timemanager/TimeStampIF.h new file mode 100644 index 00000000..805cf3b1 --- /dev/null +++ b/src/fsfw/timemanager/TimeStampIF.h @@ -0,0 +1,20 @@ +#ifndef FSFW_TIMEMANAGER_TIMESTAMPIF_H +#define FSFW_TIMEMANAGER_TIMESTAMPIF_H + +#include + +#include "fsfw/retval.h" + +class TimeStampIF { + public: + static const uint8_t INTERFACE_ID = CLASS_ID::TIME_STAMPER_IF; + static const ReturnValue_t BAD_TIMESTAMP = MAKE_RETURN_CODE(1); + + // I am going to assume there are no larger timestamps + static constexpr size_t MAXIMUM_TIMESTAMP_LEN = 16; + + virtual ~TimeStampIF() = default; + [[nodiscard]] virtual size_t getTimestampSize() const = 0; +}; + +#endif // FSFW_TIMEMANAGER_TIMESTAMPIF_H diff --git a/src/fsfw/timemanager/TimeStamperIF.h b/src/fsfw/timemanager/TimeStamperIF.h index 44cf0212..9f1ed940 100644 --- a/src/fsfw/timemanager/TimeStamperIF.h +++ b/src/fsfw/timemanager/TimeStamperIF.h @@ -1,6 +1,7 @@ #ifndef FSFW_TIMEMANAGER_TIMESTAMPERIF_H_ #define FSFW_TIMEMANAGER_TIMESTAMPERIF_H_ +#include "TimeStampIF.h" #include "fsfw/returnvalues/HasReturnvaluesIF.h" #include "fsfw/serialize/SerializeIF.h" @@ -10,22 +11,11 @@ * Implementors need to ensure that calling the method is thread-safe, i.e. * addTimeStamp may be called in parallel from a different context. */ -class TimeStamperIF : public SerializeIF { +class TimeStamperIF : public SerializeIF, public TimeStampIF { public: - static const uint8_t INTERFACE_ID = CLASS_ID::TIME_STAMPER_IF; - static const ReturnValue_t BAD_TIMESTAMP = MAKE_RETURN_CODE(1); - - // I am going to assume there are no larger timestamps - static constexpr size_t MAXIMUM_TIMESTAMP_LEN = 16; - - //! This is a mission-specific constant and determines the total - //! size reserved for timestamps. - // static const uint8_t MISSION_TIMESTAMP_SIZE = fsfwconfig::FSFW_MISSION_TIMESTAMP_SIZE; - - [[nodiscard]] virtual size_t getTimestampSize() const { return getSerializedSize(); } - virtual ReturnValue_t addTimeStamp(uint8_t* buffer, uint8_t maxSize) = 0; ~TimeStamperIF() override = default; + size_t getTimestampSize() const override { return getSerializedSize(); } protected: }; diff --git a/src/fsfw/tmtcpacket/pus/tm/PusTmReader.cpp b/src/fsfw/tmtcpacket/pus/tm/PusTmReader.cpp index a3dbb7b0..2aea80fe 100644 --- a/src/fsfw/tmtcpacket/pus/tm/PusTmReader.cpp +++ b/src/fsfw/tmtcpacket/pus/tm/PusTmReader.cpp @@ -66,7 +66,7 @@ ReturnValue_t PusTmReader::parseData(bool crcCheck) { if (result != HasReturnvaluesIF::RETURN_OK) { return result; } - size_t timestampLen = timeReader->getTimestampLen(); + size_t timestampLen = timeReader->getTimestampSize(); if (currentOffset + timestampLen > spReader.getBufSize()) { return SerializeIF::STREAM_TOO_SHORT; } diff --git a/src/fsfw/tmtcpacket/pus/tm/PusTmReader.h b/src/fsfw/tmtcpacket/pus/tm/PusTmReader.h index fdad1b6c..c95fefae 100644 --- a/src/fsfw/tmtcpacket/pus/tm/PusTmReader.h +++ b/src/fsfw/tmtcpacket/pus/tm/PusTmReader.h @@ -19,7 +19,7 @@ class PusTmReader : public PusTmIF, ReturnValue_t parseDataWithoutCrcCheck(); ReturnValue_t parseDataWithCrcCheck(); - const uint8_t* getFullData() const override; + [[nodiscard]] const uint8_t* getFullData() const override; explicit operator bool() const; [[nodiscard]] bool isNull() const; diff --git a/src/fsfw/tmtcpacket/pus/tm/PusTmZcWriter.cpp b/src/fsfw/tmtcpacket/pus/tm/PusTmZcWriter.cpp index 4c6c56d3..47bb749f 100644 --- a/src/fsfw/tmtcpacket/pus/tm/PusTmZcWriter.cpp +++ b/src/fsfw/tmtcpacket/pus/tm/PusTmZcWriter.cpp @@ -2,7 +2,8 @@ #include "fsfw/globalfunctions/CRC.h" -PusTmZeroCopyWriter::PusTmZeroCopyWriter(uint8_t* data, size_t size) : PusTmReader(data, size) {} +PusTmZeroCopyWriter::PusTmZeroCopyWriter(TimeReaderIF* timeReader, uint8_t* data, size_t size) + : PusTmReader(timeReader, data, size) {} void PusTmZeroCopyWriter::setSequenceCount(uint16_t seqCount) { auto* spHeader = diff --git a/src/fsfw/tmtcpacket/pus/tm/PusTmZcWriter.h b/src/fsfw/tmtcpacket/pus/tm/PusTmZcWriter.h index c3f5db35..d3a0e5f2 100644 --- a/src/fsfw/tmtcpacket/pus/tm/PusTmZcWriter.h +++ b/src/fsfw/tmtcpacket/pus/tm/PusTmZcWriter.h @@ -4,7 +4,7 @@ #include "PusTmReader.h" class PusTmZeroCopyWriter : public PusTmReader { public: - PusTmZeroCopyWriter(uint8_t* data, size_t size); + PusTmZeroCopyWriter(TimeReaderIF* timeReader, uint8_t* data, size_t size); void setSequenceCount(uint16_t seqCount); void updateErrorControl(); -- 2.43.0 From 234ccdf7640c74d0053a994b6786010301ab36e6 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Wed, 27 Jul 2022 17:48:59 +0200 Subject: [PATCH 083/108] send time stampers properly now --- src/fsfw/pus/Service1TelecommandVerification.cpp | 11 ++++++++++- src/fsfw/pus/Service1TelecommandVerification.h | 4 +++- src/fsfw/tmtcpacket/pus/tm/PusTmReader.cpp | 5 ++--- src/fsfw/tmtcservices/CommandingServiceBase.cpp | 7 ++++--- 4 files changed, 19 insertions(+), 8 deletions(-) diff --git a/src/fsfw/pus/Service1TelecommandVerification.cpp b/src/fsfw/pus/Service1TelecommandVerification.cpp index 6c1c2310..4e314254 100644 --- a/src/fsfw/pus/Service1TelecommandVerification.cpp +++ b/src/fsfw/pus/Service1TelecommandVerification.cpp @@ -10,7 +10,8 @@ Service1TelecommandVerification::Service1TelecommandVerification(object_id_t objectId, uint16_t apid, uint8_t serviceId, object_id_t targetDestination, - uint16_t messageQueueDepth) + uint16_t messageQueueDepth, + TimeStamperIF* timeStamper) : SystemObject(objectId), apid(apid), serviceId(serviceId), @@ -119,6 +120,14 @@ ReturnValue_t Service1TelecommandVerification::initialize() { } storeHelper.setTmStore(*tmStore); } + if(timeStamper == nullptr) { + timeStamper = ObjectManager::instance()->get(objects::TIME_STAMPER); + if(timeStamper == nullptr) { + return ObjectManagerIF::CHILD_INIT_FAILED; + } + } else { + } + storeHelper.setTimeStamper(*timeStamper); sendHelper.setMsgQueue(*tmQueue); if (errReporter == nullptr) { diff --git a/src/fsfw/pus/Service1TelecommandVerification.h b/src/fsfw/pus/Service1TelecommandVerification.h index 2e121bbf..01bd9714 100644 --- a/src/fsfw/pus/Service1TelecommandVerification.h +++ b/src/fsfw/pus/Service1TelecommandVerification.h @@ -47,7 +47,8 @@ class Service1TelecommandVerification : public AcceptsVerifyMessageIF, static const uint8_t SUBSYSTEM_ID = SUBSYSTEM_ID::PUS_SERVICE_1; Service1TelecommandVerification(object_id_t objectId, uint16_t apid, uint8_t serviceId, - object_id_t targetDestination, uint16_t messageQueueDepth); + object_id_t targetDestination, uint16_t messageQueueDepth, + TimeStamperIF* timeStamper = nullptr); ~Service1TelecommandVerification() override; /** @@ -87,6 +88,7 @@ class Service1TelecommandVerification : public AcceptsVerifyMessageIF, TmStoreHelper storeHelper; TmStoreAndSendWrapper tmHelper; InternalErrorReporterIF* errReporter = nullptr; + TimeStamperIF* timeStamper = nullptr; StorageManagerIF* tmStore = nullptr; MessageQueueIF* tmQueue = nullptr; diff --git a/src/fsfw/tmtcpacket/pus/tm/PusTmReader.cpp b/src/fsfw/tmtcpacket/pus/tm/PusTmReader.cpp index 2aea80fe..ca40562b 100644 --- a/src/fsfw/tmtcpacket/pus/tm/PusTmReader.cpp +++ b/src/fsfw/tmtcpacket/pus/tm/PusTmReader.cpp @@ -60,9 +60,8 @@ ReturnValue_t PusTmReader::parseData(bool crcCheck) { size_t currentOffset = SpacePacketReader::getHeaderLen(); pointers.secHeaderStart = pointers.spHeaderStart + currentOffset; currentOffset += PusTmIF::MIN_SEC_HEADER_LEN; - size_t minTimestampLen = spReader.getBufSize() - currentOffset; - result = timeReader->readTimeStamp(pointers.secHeaderStart + PusTmIF::MIN_SEC_HEADER_LEN, - minTimestampLen); + size_t minTimestampLen = spReader.getFullPacketLen() - currentOffset; + result = timeReader->readTimeStamp(pointers.spHeaderStart + currentOffset, minTimestampLen); if (result != HasReturnvaluesIF::RETURN_OK) { return result; } diff --git a/src/fsfw/tmtcservices/CommandingServiceBase.cpp b/src/fsfw/tmtcservices/CommandingServiceBase.cpp index 08ba599a..b7edc0cb 100644 --- a/src/fsfw/tmtcservices/CommandingServiceBase.cpp +++ b/src/fsfw/tmtcservices/CommandingServiceBase.cpp @@ -104,11 +104,12 @@ ReturnValue_t CommandingServiceBase::initialize() { // This avoids duplicate calculation of the CRC16 tmStoreHelper.disableCrcCalculation(); if (tmTimeStamper == nullptr) { - auto timerStamper = ObjectManager::instance()->get(objects::TIME_STAMPER); - if (timerStamper != nullptr) { - tmStoreHelper.setTimeStamper(*timerStamper); + tmTimeStamper = ObjectManager::instance()->get(objects::TIME_STAMPER); + if (tmTimeStamper == nullptr) { + return ObjectManagerIF::CHILD_INIT_FAILED; } } + tmStoreHelper.setTimeStamper(*tmTimeStamper); if (errReporter == nullptr) { errReporter = -- 2.43.0 From 0a38d2e22d75fdfc6b2ea40449eb706055246b03 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Wed, 27 Jul 2022 17:56:16 +0200 Subject: [PATCH 084/108] small bugfix --- src/fsfw/tmtcpacket/pus/tm/PusTmZcWriter.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/fsfw/tmtcpacket/pus/tm/PusTmZcWriter.cpp b/src/fsfw/tmtcpacket/pus/tm/PusTmZcWriter.cpp index 47bb749f..bcbdba03 100644 --- a/src/fsfw/tmtcpacket/pus/tm/PusTmZcWriter.cpp +++ b/src/fsfw/tmtcpacket/pus/tm/PusTmZcWriter.cpp @@ -10,8 +10,9 @@ void PusTmZeroCopyWriter::setSequenceCount(uint16_t seqCount) { reinterpret_cast(const_cast((pointers.spHeaderStart))); ccsds::setSequenceCount(*spHeader, seqCount); } + void PusTmZeroCopyWriter::updateErrorControl() { - auto* crcStart = reinterpret_cast(const_cast((pointers.spHeaderStart))); + auto* crcStart = const_cast((pointers.crcStart)); uint16_t crc16 = CRC::crc16ccitt(PusTmReader::getFullData(), getFullPacketLen() - sizeof(ecss::PusChecksumT)); crcStart[0] = (crc16 >> 8) & 0xff; -- 2.43.0 From 356d7787437e3926fb9dd9cb067d91351c9b7ae5 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Wed, 27 Jul 2022 18:03:17 +0200 Subject: [PATCH 085/108] afmt --- src/fsfw/pus/Service1TelecommandVerification.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/fsfw/pus/Service1TelecommandVerification.cpp b/src/fsfw/pus/Service1TelecommandVerification.cpp index 4e314254..46d7237c 100644 --- a/src/fsfw/pus/Service1TelecommandVerification.cpp +++ b/src/fsfw/pus/Service1TelecommandVerification.cpp @@ -120,9 +120,9 @@ ReturnValue_t Service1TelecommandVerification::initialize() { } storeHelper.setTmStore(*tmStore); } - if(timeStamper == nullptr) { + if (timeStamper == nullptr) { timeStamper = ObjectManager::instance()->get(objects::TIME_STAMPER); - if(timeStamper == nullptr) { + if (timeStamper == nullptr) { return ObjectManagerIF::CHILD_INIT_FAILED; } } else { -- 2.43.0 From 4e571e508280555cc96932991e125fd8ebc38df7 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Wed, 27 Jul 2022 19:40:54 +0200 Subject: [PATCH 086/108] some more minor fixes --- .../tmtcservices/CommandingServiceBase.cpp | 3 ++- src/fsfw/tmtcservices/PusServiceBase.cpp | 26 +++++++++++++++---- src/fsfw/tmtcservices/PusServiceBase.h | 6 ++--- 3 files changed, 26 insertions(+), 9 deletions(-) diff --git a/src/fsfw/tmtcservices/CommandingServiceBase.cpp b/src/fsfw/tmtcservices/CommandingServiceBase.cpp index b7edc0cb..88004b0a 100644 --- a/src/fsfw/tmtcservices/CommandingServiceBase.cpp +++ b/src/fsfw/tmtcservices/CommandingServiceBase.cpp @@ -263,7 +263,8 @@ void CommandingServiceBase::handleRequestQueue() { object_id_t objectId; for (result = requestQueue->receiveMessage(&message); result == RETURN_OK; result = requestQueue->receiveMessage(&message)) { - result = setUpTcReader(message.getStorageId()); + address = message.getStorageId(); + result = setUpTcReader(address); if (result != HasReturnvaluesIF::RETURN_OK) { // TODO: Warning? rejectPacket(tcverif::START_FAILURE, address, result); diff --git a/src/fsfw/tmtcservices/PusServiceBase.cpp b/src/fsfw/tmtcservices/PusServiceBase.cpp index d3d23ed7..f8cc7cb8 100644 --- a/src/fsfw/tmtcservices/PusServiceBase.cpp +++ b/src/fsfw/tmtcservices/PusServiceBase.cpp @@ -140,12 +140,15 @@ void PusServiceBase::setErrorReporter(InternalErrorReporterIF& errReporter_) { psbParams.errReporter = &errReporter_; } -void PusServiceBase::initializeTmHelpers(TmSendHelper& tmSendHelper, TmStoreHelper& tmStoreHelper) { - initializeTmSendHelper(tmSendHelper); - initializeTmStoreHelper(tmStoreHelper); +ReturnValue_t PusServiceBase::initializeTmHelpers(TmSendHelper& tmSendHelper, TmStoreHelper& tmStoreHelper) { + ReturnValue_t result = initializeTmSendHelper(tmSendHelper); + if(result != HasReturnvaluesIF::RETURN_OK) { + return result; + } + return initializeTmStoreHelper(tmStoreHelper); } -void PusServiceBase::initializeTmSendHelper(TmSendHelper& tmSendHelper) { +ReturnValue_t PusServiceBase::initializeTmSendHelper(TmSendHelper& tmSendHelper) { if (psbParams.reqQueue != nullptr) { tmSendHelper.setMsgQueue(*psbParams.reqQueue); tmSendHelper.setDefaultDestination(psbParams.reqQueue->getDefaultDestination()); @@ -160,16 +163,29 @@ void PusServiceBase::initializeTmSendHelper(TmSendHelper& tmSendHelper) { } else { tmSendHelper.setInternalErrorReporter(*psbParams.errReporter); } + return RETURN_OK; } -void PusServiceBase::initializeTmStoreHelper(TmStoreHelper& tmStoreHelper) const { +ReturnValue_t PusServiceBase::initializeTmStoreHelper(TmStoreHelper& tmStoreHelper) const { tmStoreHelper.setApid(psbParams.apid); + if(tmStoreHelper.getTmStore() == nullptr) { + auto* tmStore = ObjectManager::instance()->get(objects::TM_STORE); + if(tmStore == nullptr) { + return ObjectManagerIF::CHILD_INIT_FAILED; + } + tmStoreHelper.setTmStore(*tmStore); + } + if (psbParams.timeStamper == nullptr) { auto timerStamper = ObjectManager::instance()->get(objects::TIME_STAMPER); if (timerStamper != nullptr) { tmStoreHelper.setTimeStamper(*timerStamper); } } + // Generally, all TM packets will pass through a layer where the sequence count is set. + // This avoids duplicate calculation of the CRC16 + tmStoreHelper.disableCrcCalculation(); + return RETURN_OK; } void PusServiceBase::setVerificationReporter(VerificationReporterIF& reporter) { diff --git a/src/fsfw/tmtcservices/PusServiceBase.h b/src/fsfw/tmtcservices/PusServiceBase.h index 43a2c0d4..86d8ea1a 100644 --- a/src/fsfw/tmtcservices/PusServiceBase.h +++ b/src/fsfw/tmtcservices/PusServiceBase.h @@ -132,19 +132,19 @@ class PusServiceBase : public ExecutableObjectIF, * Helper methods if the implementing class wants to send telemetry * @param tmSendHelper */ - void initializeTmSendHelper(TmSendHelper& tmSendHelper); + ReturnValue_t initializeTmSendHelper(TmSendHelper& tmSendHelper); /** * Helper methods if the implementing class wants to store telemetry. It will set the correct APID * and it will also attempt to set a valid time stamper. If the manually specified time stamper is * null, it will attempt to find a suitable one using @objects::TIME_STAMPER * @param tmSendHelper */ - void initializeTmStoreHelper(TmStoreHelper& tmStoreHelper) const; + ReturnValue_t initializeTmStoreHelper(TmStoreHelper& tmStoreHelper) const; /** * Helper methods if the implementing class wants to both send and store telemetry * @param tmSendHelper */ - void initializeTmHelpers(TmSendHelper& tmSendHelper, TmStoreHelper& tmStoreHelper); + ReturnValue_t initializeTmHelpers(TmSendHelper& tmSendHelper, TmStoreHelper& tmStoreHelper); /** * @brief The handleRequest method shall handle any kind of Telecommand -- 2.43.0 From d641d6353121f26695fe52647d7e0887ac6ede99 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Wed, 27 Jul 2022 19:56:11 +0200 Subject: [PATCH 087/108] set queue of tm send helper --- src/fsfw/tmtcservices/CommandingServiceBase.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/fsfw/tmtcservices/CommandingServiceBase.cpp b/src/fsfw/tmtcservices/CommandingServiceBase.cpp index 88004b0a..5278fc6c 100644 --- a/src/fsfw/tmtcservices/CommandingServiceBase.cpp +++ b/src/fsfw/tmtcservices/CommandingServiceBase.cpp @@ -120,6 +120,7 @@ ReturnValue_t CommandingServiceBase::initialize() { } else { tmSendHelper.setInternalErrorReporter(*errReporter); } + tmSendHelper.setMsgQueue(*requestQueue); if (verificationReporter == nullptr) { verificationReporter = -- 2.43.0 From f03b7cd6600fcabe6e1969630e942e4e85e80b09 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Wed, 27 Jul 2022 20:10:15 +0200 Subject: [PATCH 088/108] another bugfix in CSB --- src/fsfw/pus/Service1TelecommandVerification.cpp | 11 +++++++++++ src/fsfw/tmtcservices/CommandingServiceBase.cpp | 8 ++++---- 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/src/fsfw/pus/Service1TelecommandVerification.cpp b/src/fsfw/pus/Service1TelecommandVerification.cpp index 46d7237c..9d8ca111 100644 --- a/src/fsfw/pus/Service1TelecommandVerification.cpp +++ b/src/fsfw/pus/Service1TelecommandVerification.cpp @@ -49,6 +49,17 @@ ReturnValue_t Service1TelecommandVerification::performOperation(uint8_t operatio ReturnValue_t Service1TelecommandVerification::sendVerificationReport( PusVerificationMessage* message) { ReturnValue_t result; + uint8_t reportId = message->getReportId(); + if(reportId == 0 or reportId > 8) { +#if FSFW_CPP_OSTREAM_ENABLED == 1 + sif::error << "Service1TelecommandVerification::sendVerificationReport: Invalid report ID " << + static_cast(reportId) << " detected" << std::endl; +#else + sif::printError("Service1TelecommandVerification::sendVerificationReport: Invalid report ID " + "%d detected\n", reportId); +#endif + return HasReturnvaluesIF::RETURN_FAILED; + } if (message->getReportId() % 2 == 0) { result = generateFailureReport(message); } else { diff --git a/src/fsfw/tmtcservices/CommandingServiceBase.cpp b/src/fsfw/tmtcservices/CommandingServiceBase.cpp index 5278fc6c..c12a47b2 100644 --- a/src/fsfw/tmtcservices/CommandingServiceBase.cpp +++ b/src/fsfw/tmtcservices/CommandingServiceBase.cpp @@ -457,8 +457,8 @@ void CommandingServiceBase::prepareVerificationFailureWithFullInfo(uint8_t repor } void CommandingServiceBase::prepareVerificationSuccessWithFullInfo( uint8_t reportId, CommandingServiceBase::CommandInfo::TcInfo& tcInfo) { - failParams.reportId = reportId; - failParams.tcPacketId = tcInfo.tcPacketId; - failParams.tcPsc = tcInfo.tcSequenceControl; - failParams.ackFlags = tcInfo.ackFlags; + successParams.reportId = reportId; + successParams.tcPacketId = tcInfo.tcPacketId; + successParams.tcPsc = tcInfo.tcSequenceControl; + successParams.ackFlags = tcInfo.ackFlags; } -- 2.43.0 From 7e8afcc12f413d8199f086521e1e7a6d0db21259 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Wed, 27 Jul 2022 20:37:21 +0200 Subject: [PATCH 089/108] remove nullptr check --- src/fsfw/pus/Service11TelecommandScheduling.tpp | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/fsfw/pus/Service11TelecommandScheduling.tpp b/src/fsfw/pus/Service11TelecommandScheduling.tpp index 15440a21..83713266 100644 --- a/src/fsfw/pus/Service11TelecommandScheduling.tpp +++ b/src/fsfw/pus/Service11TelecommandScheduling.tpp @@ -34,9 +34,6 @@ inline ReturnValue_t Service11TelecommandScheduling::handleRequest( // Get de-serialized Timestamp const uint8_t *data = currentPacket.getUserData(); size_t size = currentPacket.getUserDataLen(); - if (data == nullptr) { - return handleInvalidData("handleRequest"); - } switch (subservice) { case Subservice::ENABLE_SCHEDULING: { schedulingEnabled = true; -- 2.43.0 From 93acac02f561fe61dfe05904261d15ee715f1249 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Wed, 27 Jul 2022 21:06:23 +0200 Subject: [PATCH 090/108] tests running again --- src/fsfw/pus/Service1TelecommandVerification.cpp | 12 +++++++----- src/fsfw/serialize/SerializeIF.h | 4 ++-- src/fsfw/tmtcpacket/pus/tm/PusTmCreator.cpp | 8 ++++++++ src/fsfw/tmtcpacket/pus/tm/PusTmCreator.h | 3 +++ src/fsfw/tmtcservices/PusServiceBase.cpp | 11 ++++++----- unittests/mocks/CdsShortTimestamperMock.h | 1 - unittests/tmtcpacket/testCcsds.cpp | 2 +- unittests/tmtcpacket/testPusTmCreator.cpp | 9 ++++++--- unittests/tmtcpacket/testPusTmReader.cpp | 2 +- unittests/tmtcservices/testSendHelper.cpp | 2 +- 10 files changed, 35 insertions(+), 19 deletions(-) diff --git a/src/fsfw/pus/Service1TelecommandVerification.cpp b/src/fsfw/pus/Service1TelecommandVerification.cpp index 9d8ca111..0e6e302c 100644 --- a/src/fsfw/pus/Service1TelecommandVerification.cpp +++ b/src/fsfw/pus/Service1TelecommandVerification.cpp @@ -50,13 +50,15 @@ ReturnValue_t Service1TelecommandVerification::sendVerificationReport( PusVerificationMessage* message) { ReturnValue_t result; uint8_t reportId = message->getReportId(); - if(reportId == 0 or reportId > 8) { + if (reportId == 0 or reportId > 8) { #if FSFW_CPP_OSTREAM_ENABLED == 1 - sif::error << "Service1TelecommandVerification::sendVerificationReport: Invalid report ID " << - static_cast(reportId) << " detected" << std::endl; + sif::error << "Service1TelecommandVerification::sendVerificationReport: Invalid report ID " + << static_cast(reportId) << " detected" << std::endl; #else - sif::printError("Service1TelecommandVerification::sendVerificationReport: Invalid report ID " - "%d detected\n", reportId); + sif::printError( + "Service1TelecommandVerification::sendVerificationReport: Invalid report ID " + "%d detected\n", + reportId); #endif return HasReturnvaluesIF::RETURN_FAILED; } diff --git a/src/fsfw/serialize/SerializeIF.h b/src/fsfw/serialize/SerializeIF.h index 136bd419..e33adb96 100644 --- a/src/fsfw/serialize/SerializeIF.h +++ b/src/fsfw/serialize/SerializeIF.h @@ -64,13 +64,13 @@ class SerializeIF { /** * Forwards to regular @serialize call with big (network) endianness */ - virtual ReturnValue_t serializeBe(uint8_t **buffer, size_t *size, size_t maxSize) { + virtual ReturnValue_t serializeBe(uint8_t **buffer, size_t *size, size_t maxSize) const { return serialize(buffer, size, maxSize, SerializeIF::Endianness::NETWORK); } /** * If endianness is not explicitly specified, use machine endianness */ - virtual ReturnValue_t serialize(uint8_t **buffer, size_t *size, size_t maxSize) { + virtual ReturnValue_t serialize(uint8_t **buffer, size_t *size, size_t maxSize) const { return serialize(buffer, size, maxSize, SerializeIF::Endianness::MACHINE); } diff --git a/src/fsfw/tmtcpacket/pus/tm/PusTmCreator.cpp b/src/fsfw/tmtcpacket/pus/tm/PusTmCreator.cpp index 348308d1..6253bc24 100644 --- a/src/fsfw/tmtcpacket/pus/tm/PusTmCreator.cpp +++ b/src/fsfw/tmtcpacket/pus/tm/PusTmCreator.cpp @@ -146,3 +146,11 @@ void PusTmCreator::setSubservice(uint8_t subservice) { pusParams.secHeader.subservice = subservice; } bool PusTmCreator::crcCalculationEnabled() const { return calculateCrcOnSerialization; } + +ReturnValue_t PusTmCreator::serialize(uint8_t** buffer, size_t* size, size_t maxSize) const { + return serialize(buffer, size, maxSize, SerializeIF::Endianness::NETWORK); +} + +ReturnValue_t PusTmCreator::serialize(uint8_t* buffer, size_t maxSize) const { + return SerializeIF::serialize(buffer, maxSize, SerializeIF::Endianness::NETWORK); +} \ No newline at end of file diff --git a/src/fsfw/tmtcpacket/pus/tm/PusTmCreator.h b/src/fsfw/tmtcpacket/pus/tm/PusTmCreator.h index 0e7988f1..75760968 100644 --- a/src/fsfw/tmtcpacket/pus/tm/PusTmCreator.h +++ b/src/fsfw/tmtcpacket/pus/tm/PusTmCreator.h @@ -72,6 +72,9 @@ class PusTmCreator : public SerializeIF, public PusTmIF, public CustomUserDataIF uint8_t getScTimeRefStatus() override; uint16_t getMessageTypeCounter() override; uint16_t getDestId() override; + // Override these to use default big endianness + ReturnValue_t serialize(uint8_t** buffer, size_t* size, size_t maxSize) const override; + ReturnValue_t serialize(uint8_t* buffer, size_t maxSize) const override; ReturnValue_t serialize(uint8_t** buffer, size_t* size, size_t maxSize, Endianness streamEndianness) const override; [[nodiscard]] size_t getSerializedSize() const override; diff --git a/src/fsfw/tmtcservices/PusServiceBase.cpp b/src/fsfw/tmtcservices/PusServiceBase.cpp index f8cc7cb8..b555449b 100644 --- a/src/fsfw/tmtcservices/PusServiceBase.cpp +++ b/src/fsfw/tmtcservices/PusServiceBase.cpp @@ -140,9 +140,10 @@ void PusServiceBase::setErrorReporter(InternalErrorReporterIF& errReporter_) { psbParams.errReporter = &errReporter_; } -ReturnValue_t PusServiceBase::initializeTmHelpers(TmSendHelper& tmSendHelper, TmStoreHelper& tmStoreHelper) { +ReturnValue_t PusServiceBase::initializeTmHelpers(TmSendHelper& tmSendHelper, + TmStoreHelper& tmStoreHelper) { ReturnValue_t result = initializeTmSendHelper(tmSendHelper); - if(result != HasReturnvaluesIF::RETURN_OK) { + if (result != HasReturnvaluesIF::RETURN_OK) { return result; } return initializeTmStoreHelper(tmStoreHelper); @@ -166,11 +167,11 @@ ReturnValue_t PusServiceBase::initializeTmSendHelper(TmSendHelper& tmSendHelper) return RETURN_OK; } -ReturnValue_t PusServiceBase::initializeTmStoreHelper(TmStoreHelper& tmStoreHelper) const { +ReturnValue_t PusServiceBase::initializeTmStoreHelper(TmStoreHelper& tmStoreHelper) const { tmStoreHelper.setApid(psbParams.apid); - if(tmStoreHelper.getTmStore() == nullptr) { + if (tmStoreHelper.getTmStore() == nullptr) { auto* tmStore = ObjectManager::instance()->get(objects::TM_STORE); - if(tmStore == nullptr) { + if (tmStore == nullptr) { return ObjectManagerIF::CHILD_INIT_FAILED; } tmStoreHelper.setTmStore(*tmStore); diff --git a/unittests/mocks/CdsShortTimestamperMock.h b/unittests/mocks/CdsShortTimestamperMock.h index 784ef7f4..d19385cd 100644 --- a/unittests/mocks/CdsShortTimestamperMock.h +++ b/unittests/mocks/CdsShortTimestamperMock.h @@ -78,7 +78,6 @@ class CdsShortTimestamperMock : public TimeStamperIF, public TimeReaderIF { ReturnValue_t readTimeStamp(const uint8_t *buffer, size_t maxSize) override { return deSerialize(&buffer, &maxSize, SerializeIF::Endianness::NETWORK); } - size_t getTimestampLen() override { return getSerializedSize(); } timeval &getTime() override { return dummyTime; } private: diff --git a/unittests/tmtcpacket/testCcsds.cpp b/unittests/tmtcpacket/testCcsds.cpp index e40db1c6..9be2b8af 100644 --- a/unittests/tmtcpacket/testCcsds.cpp +++ b/unittests/tmtcpacket/testCcsds.cpp @@ -24,7 +24,7 @@ TEST_CASE("CCSDS Low Level", "[ccsds-ll]") { uint16_t packetIdRaw = 0x3ff; ccsds::setPacketId(header, packetIdRaw); ccsds::setApid(header, 0x1ff); - REQUIRE(ccsds::getPacketId(header) == 0x1ff); + REQUIRE(ccsds::getPacketId(header) == 0x3ff); } SECTION("Lowlevel Packet Length Test") { diff --git a/unittests/tmtcpacket/testPusTmCreator.cpp b/unittests/tmtcpacket/testPusTmCreator.cpp index ad8a1d4d..97f3d893 100644 --- a/unittests/tmtcpacket/testPusTmCreator.cpp +++ b/unittests/tmtcpacket/testPusTmCreator.cpp @@ -44,7 +44,8 @@ TEST_CASE("PUS TM Creator", "[pus-tm-creator]") { } SECTION("Serialization") { - REQUIRE(creator.serialize(&dataPtr, &serLen, buf.size()) == HasReturnvaluesIF::RETURN_OK); + REQUIRE(creator.SerializeIF::serializeBe(&dataPtr, &serLen, buf.size()) == + HasReturnvaluesIF::RETURN_OK); REQUIRE(buf[0] == 0x08); REQUIRE(buf[1] == 0xef); // Unsegmented is the default @@ -105,7 +106,8 @@ TEST_CASE("PUS TM Creator", "[pus-tm-creator]") { std::array data{1, 2, 3}; creator.setRawUserData(data.data(), data.size()); REQUIRE(creator.getFullPacketLen() == 25); - REQUIRE(creator.serialize(&dataPtr, &serLen, buf.size()) == HasReturnvaluesIF::RETURN_OK); + REQUIRE(creator.SerializeIF::serialize(&dataPtr, &serLen, buf.size()) == + HasReturnvaluesIF::RETURN_OK); REQUIRE(buf[20] == 1); REQUIRE(buf[21] == 2); REQUIRE(buf[22] == 3); @@ -139,7 +141,8 @@ TEST_CASE("PUS TM Creator", "[pus-tm-creator]") { for (size_t maxSize = 0; maxSize < reqSize; maxSize++) { dataPtr = buf.data(); serLen = 0; - REQUIRE(creator.serialize(&dataPtr, &serLen, maxSize) == SerializeIF::BUFFER_TOO_SHORT); + REQUIRE(creator.SerializeIF::serialize(&dataPtr, &serLen, maxSize) == + SerializeIF::BUFFER_TOO_SHORT); } } } \ No newline at end of file diff --git a/unittests/tmtcpacket/testPusTmReader.cpp b/unittests/tmtcpacket/testPusTmReader.cpp index 7a61b731..3914db48 100644 --- a/unittests/tmtcpacket/testPusTmReader.cpp +++ b/unittests/tmtcpacket/testPusTmReader.cpp @@ -22,7 +22,7 @@ TEST_CASE("PUS TM Reader", "[pus-tm-reader]") { bool deleteReader = false; dataPtr = buf.data(); serLen = 0; - REQUIRE(creator.serialize(&dataPtr, &serLen, buf.size()) == HasReturnvaluesIF::RETURN_OK); + REQUIRE(creator.serializeBe(&dataPtr, &serLen, buf.size()) == HasReturnvaluesIF::RETURN_OK); REQUIRE(not(*readerPtr)); REQUIRE(readerPtr->isNull()); diff --git a/unittests/tmtcservices/testSendHelper.cpp b/unittests/tmtcservices/testSendHelper.cpp index b857776b..78ca9f0e 100644 --- a/unittests/tmtcservices/testSendHelper.cpp +++ b/unittests/tmtcservices/testSendHelper.cpp @@ -57,7 +57,7 @@ TEST_CASE("TM Send Helper", "[tm-send-helper]") { SECTION("Two Arg CTOR") { TmSendHelper helper(msgQueue, errReporter); REQUIRE(helper.getInternalErrorReporter() == &errReporter); - REQUIRE(helper.getDefaultDestination() == MessageQueueIF::NO_QUEUE); + REQUIRE(helper.getDefaultDestination() == 2); REQUIRE(helper.getMsgQueue() == &msgQueue); } SECTION("Send") { -- 2.43.0 From 85dbef20b066d707b95804e0642dee34d7cef9d1 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Wed, 27 Jul 2022 21:07:34 +0200 Subject: [PATCH 091/108] update serialize IF --- src/fsfw/serialize/SerializeIF.h | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/src/fsfw/serialize/SerializeIF.h b/src/fsfw/serialize/SerializeIF.h index e33adb96..47212ab1 100644 --- a/src/fsfw/serialize/SerializeIF.h +++ b/src/fsfw/serialize/SerializeIF.h @@ -59,18 +59,20 @@ class SerializeIF { * - @c RETURN_FAILED Generic error * - @c RETURN_OK Successful serialization */ - virtual ReturnValue_t serialize(uint8_t **buffer, size_t *size, size_t maxSize, - Endianness streamEndianness) const = 0; + [[nodiscard]] virtual ReturnValue_t serialize(uint8_t **buffer, size_t *size, size_t maxSize, + Endianness streamEndianness) const = 0; /** * Forwards to regular @serialize call with big (network) endianness */ - virtual ReturnValue_t serializeBe(uint8_t **buffer, size_t *size, size_t maxSize) const { + [[nodiscard]] virtual ReturnValue_t serializeBe(uint8_t **buffer, size_t *size, + size_t maxSize) const { return serialize(buffer, size, maxSize, SerializeIF::Endianness::NETWORK); } /** * If endianness is not explicitly specified, use machine endianness */ - virtual ReturnValue_t serialize(uint8_t **buffer, size_t *size, size_t maxSize) const { + [[nodiscard]] virtual ReturnValue_t serialize(uint8_t **buffer, size_t *size, + size_t maxSize) const { return serialize(buffer, size, maxSize, SerializeIF::Endianness::MACHINE); } @@ -123,21 +125,21 @@ class SerializeIF { * @param streamEndianness * @return */ - virtual ReturnValue_t serialize(uint8_t *buffer, size_t maxSize, - Endianness streamEndianness) const { + [[nodiscard]] virtual ReturnValue_t serialize(uint8_t *buffer, size_t maxSize, + Endianness streamEndianness) const { size_t tmpSize = 0; return serialize(&buffer, &tmpSize, maxSize, streamEndianness); } /** * Forwards to regular @serialize call with big (network) endianness */ - virtual ReturnValue_t serializeBe(uint8_t *buffer, size_t maxSize) const { + [[nodiscard]] virtual ReturnValue_t serializeBe(uint8_t *buffer, size_t maxSize) const { return serialize(buffer, maxSize, SerializeIF::Endianness::NETWORK); } /** * If endianness is not explicitly specified, use machine endianness */ - virtual ReturnValue_t serialize(uint8_t *buffer, size_t maxSize) const { + [[nodiscard]] virtual ReturnValue_t serialize(uint8_t *buffer, size_t maxSize) const { return serialize(buffer, maxSize, SerializeIF::Endianness::MACHINE); } -- 2.43.0 From 5bb7023ff30823575187da06eba50a8acec78254 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Wed, 27 Jul 2022 21:11:12 +0200 Subject: [PATCH 092/108] improvements for creator API --- src/fsfw/tmtcpacket/pus/tc/PusTcCreator.cpp | 12 ++++++++---- src/fsfw/tmtcpacket/pus/tc/PusTcCreator.h | 9 ++++++--- src/fsfw/tmtcpacket/pus/tm/PusTmCreator.h | 5 +++-- unittests/tmtcpacket/testPusTcCreator.cpp | 3 ++- unittests/tmtcpacket/testPusTmCreator.cpp | 3 ++- 5 files changed, 21 insertions(+), 11 deletions(-) diff --git a/src/fsfw/tmtcpacket/pus/tc/PusTcCreator.cpp b/src/fsfw/tmtcpacket/pus/tc/PusTcCreator.cpp index d6748619..f509717b 100644 --- a/src/fsfw/tmtcpacket/pus/tc/PusTcCreator.cpp +++ b/src/fsfw/tmtcpacket/pus/tc/PusTcCreator.cpp @@ -90,10 +90,6 @@ PusTcParams &PusTcCreator::getPusParams() { return pusParams; } SpacePacketParams &PusTcCreator::getSpParams() { return spCreator.getParams(); } -ReturnValue_t PusTcCreator::serialize(uint8_t **buffer, size_t *size, size_t maxSize) { - return serialize(buffer, size, maxSize, SerializeIF::Endianness::NETWORK); -} - ReturnValue_t PusTcCreator::setRawUserData(const uint8_t *data, size_t len) { // TODO: Check length field? pusParams.dataWrapper.setRawData({data, len}); @@ -107,3 +103,11 @@ ReturnValue_t PusTcCreator::setSerializableUserData(SerializeIF &serializable) { updateSpLengthField(); return HasReturnvaluesIF::RETURN_OK; } + +ReturnValue_t PusTcCreator::serialize(uint8_t **buffer, size_t *size, size_t maxSize) const { + return serialize(buffer, size, maxSize, SerializeIF::Endianness::NETWORK); +} + +ReturnValue_t PusTcCreator::serialize(uint8_t *buffer, size_t maxSize) const { + return SerializeIF::serialize(buffer, maxSize, SerializeIF::Endianness::NETWORK); +} diff --git a/src/fsfw/tmtcpacket/pus/tc/PusTcCreator.h b/src/fsfw/tmtcpacket/pus/tc/PusTcCreator.h index 0f903e7b..b41ad940 100644 --- a/src/fsfw/tmtcpacket/pus/tc/PusTcCreator.h +++ b/src/fsfw/tmtcpacket/pus/tc/PusTcCreator.h @@ -34,10 +34,10 @@ class PusTcCreator : public PusTcIF, public SerializeIF, public CustomUserDataIF PusTcParams &getPusParams(); SpacePacketParams &getSpParams(); - ReturnValue_t serialize(uint8_t **buffer, size_t *size, size_t maxSize); + ReturnValue_t serialize(uint8_t **buffer, size_t *size, size_t maxSize) const override; + ReturnValue_t serialize(uint8_t *buffer, size_t maxSize) const override; [[nodiscard]] size_t getSerializedSize() const override; - ReturnValue_t deSerialize(const uint8_t **buffer, size_t *size, - Endianness streamEndianness) override; + [[nodiscard]] uint16_t getPacketIdRaw() const override; [[nodiscard]] uint16_t getPacketSeqCtrlRaw() const override; [[nodiscard]] uint16_t getPacketDataLen() const override; @@ -52,6 +52,9 @@ class PusTcCreator : public PusTcIF, public SerializeIF, public CustomUserDataIF private: ReturnValue_t serialize(uint8_t **buffer, size_t *size, size_t maxSize, Endianness streamEndianness) const override; + // Forbidden to use + ReturnValue_t deSerialize(const uint8_t **buffer, size_t *size, + Endianness streamEndianness) override; SpacePacketCreator spCreator; PusTcParams pusParams; }; diff --git a/src/fsfw/tmtcpacket/pus/tm/PusTmCreator.h b/src/fsfw/tmtcpacket/pus/tm/PusTmCreator.h index 75760968..c8de3428 100644 --- a/src/fsfw/tmtcpacket/pus/tm/PusTmCreator.h +++ b/src/fsfw/tmtcpacket/pus/tm/PusTmCreator.h @@ -78,13 +78,14 @@ class PusTmCreator : public SerializeIF, public PusTmIF, public CustomUserDataIF 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]] TimeStamperIF* getTimestamper() const; ReturnValue_t setRawUserData(const uint8_t* data, size_t len) override; ReturnValue_t setSerializableUserData(SerializeIF& serializable) override; private: + // Forbidden to use + ReturnValue_t deSerialize(const uint8_t** buffer, size_t* size, + Endianness streamEndianness) override; void setup(); PusTmParams pusParams{}; bool calculateCrcOnSerialization = true; diff --git a/unittests/tmtcpacket/testPusTcCreator.cpp b/unittests/tmtcpacket/testPusTcCreator.cpp index c5b0743b..fdda717f 100644 --- a/unittests/tmtcpacket/testPusTcCreator.cpp +++ b/unittests/tmtcpacket/testPusTcCreator.cpp @@ -95,9 +95,10 @@ TEST_CASE("PUS TC Creator", "[pus-tc-creator]") { } SECTION("Deserialization Fails") { + SerializeIF& deser = creator; size_t deserLen = buf.size(); const uint8_t* roPtr = buf.data(); - REQUIRE(creator.deSerialize(&roPtr, &deserLen, SerializeIF::Endianness::NETWORK) == + REQUIRE(deser.deSerialize(&roPtr, &deserLen, SerializeIF::Endianness::NETWORK) == HasReturnvaluesIF::RETURN_FAILED); } diff --git a/unittests/tmtcpacket/testPusTmCreator.cpp b/unittests/tmtcpacket/testPusTmCreator.cpp index 97f3d893..99c16550 100644 --- a/unittests/tmtcpacket/testPusTmCreator.cpp +++ b/unittests/tmtcpacket/testPusTmCreator.cpp @@ -97,8 +97,9 @@ TEST_CASE("PUS TM Creator", "[pus-tm-creator]") { } SECTION("Deserialization fails") { + SerializeIF& deser = creator; const uint8_t* roDataPtr = nullptr; - REQUIRE(creator.deSerialize(&roDataPtr, &serLen, SerializeIF::Endianness::NETWORK) == + REQUIRE(deser.deSerialize(&roDataPtr, &serLen, SerializeIF::Endianness::NETWORK) == HasReturnvaluesIF::RETURN_FAILED); } -- 2.43.0 From b485afea5786b44bd9a7b6206c306eb3ac502457 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Wed, 27 Jul 2022 21:29:05 +0200 Subject: [PATCH 093/108] Simple SerializeIF adaptions - Returns serialized or deserialized size --- src/fsfw/serialize/SerializeIF.h | 31 +++++++++------ src/fsfw/tmtcpacket/pus/tc/PusTcCreator.cpp | 4 +- src/fsfw/tmtcpacket/pus/tc/PusTcCreator.h | 2 +- src/fsfw/tmtcpacket/pus/tm/PusTmCreator.cpp | 7 +++- src/fsfw/tmtcpacket/pus/tm/PusTmCreator.h | 2 +- unittests/serialize/testSerializeIF.cpp | 43 ++++++++++++++------- unittests/tmtcpacket/testCcsds.cpp | 41 ++++++++++++++------ unittests/tmtcpacket/testPusTcCreator.cpp | 12 ++++++ unittests/tmtcservices/testPsb.cpp | 6 ++- 9 files changed, 101 insertions(+), 47 deletions(-) diff --git a/src/fsfw/serialize/SerializeIF.h b/src/fsfw/serialize/SerializeIF.h index 47212ab1..5e7a2fb9 100644 --- a/src/fsfw/serialize/SerializeIF.h +++ b/src/fsfw/serialize/SerializeIF.h @@ -125,22 +125,26 @@ class SerializeIF { * @param streamEndianness * @return */ - [[nodiscard]] virtual ReturnValue_t serialize(uint8_t *buffer, size_t maxSize, + [[nodiscard]] virtual ReturnValue_t serialize(uint8_t *buffer, size_t &serLen, size_t maxSize, Endianness streamEndianness) const { size_t tmpSize = 0; - return serialize(&buffer, &tmpSize, maxSize, streamEndianness); + ReturnValue_t result = serialize(&buffer, &tmpSize, maxSize, streamEndianness); + serLen = tmpSize; + return result; } /** * Forwards to regular @serialize call with big (network) endianness */ - [[nodiscard]] virtual ReturnValue_t serializeBe(uint8_t *buffer, size_t maxSize) const { - return serialize(buffer, maxSize, SerializeIF::Endianness::NETWORK); + [[nodiscard]] virtual ReturnValue_t serializeBe(uint8_t *buffer, size_t &serLen, + size_t maxSize) const { + return serialize(buffer, serLen, maxSize, SerializeIF::Endianness::NETWORK); } /** * If endianness is not explicitly specified, use machine endianness */ - [[nodiscard]] virtual ReturnValue_t serialize(uint8_t *buffer, size_t maxSize) const { - return serialize(buffer, maxSize, SerializeIF::Endianness::MACHINE); + [[nodiscard]] virtual ReturnValue_t serialize(uint8_t *buffer, size_t &serLen, + size_t maxSize) const { + return serialize(buffer, serLen, maxSize, SerializeIF::Endianness::MACHINE); } /** @@ -151,21 +155,24 @@ class SerializeIF { * @param streamEndianness * @return */ - virtual ReturnValue_t deSerialize(const uint8_t *buffer, size_t maxSize, + virtual ReturnValue_t deSerialize(const uint8_t *buffer, size_t &deserSize, size_t maxSize, Endianness streamEndianness) { - return deSerialize(&buffer, &maxSize, streamEndianness); + size_t deserLen = maxSize; + ReturnValue_t result = deSerialize(&buffer, &deserLen, streamEndianness); + deserSize = maxSize - deserLen; + return result; } /** * Forwards to regular @serialize call with big (network) endianness */ - virtual ReturnValue_t deSerializeBe(const uint8_t *buffer, size_t maxSize) { - return deSerialize(buffer, maxSize, SerializeIF::Endianness::NETWORK); + virtual ReturnValue_t deSerializeBe(const uint8_t *buffer, size_t &deserSize, size_t maxSize) { + return deSerialize(buffer, deserSize, maxSize, SerializeIF::Endianness::NETWORK); } /** * If endianness is not explicitly specified, use machine endianness */ - virtual ReturnValue_t deSerialize(const uint8_t *buffer, size_t maxSize) { - return deSerialize(buffer, maxSize, SerializeIF::Endianness::MACHINE); + virtual ReturnValue_t deSerialize(const uint8_t *buffer, size_t &deserSize, size_t maxSize) { + return deSerialize(buffer, deserSize, maxSize, SerializeIF::Endianness::MACHINE); } }; diff --git a/src/fsfw/tmtcpacket/pus/tc/PusTcCreator.cpp b/src/fsfw/tmtcpacket/pus/tc/PusTcCreator.cpp index f509717b..be472051 100644 --- a/src/fsfw/tmtcpacket/pus/tc/PusTcCreator.cpp +++ b/src/fsfw/tmtcpacket/pus/tc/PusTcCreator.cpp @@ -108,6 +108,6 @@ ReturnValue_t PusTcCreator::serialize(uint8_t **buffer, size_t *size, size_t max return serialize(buffer, size, maxSize, SerializeIF::Endianness::NETWORK); } -ReturnValue_t PusTcCreator::serialize(uint8_t *buffer, size_t maxSize) const { - return SerializeIF::serialize(buffer, maxSize, SerializeIF::Endianness::NETWORK); +ReturnValue_t PusTcCreator::serialize(uint8_t *buffer, size_t &serLen, size_t maxSize) const { + return SerializeIF::serialize(buffer, serLen, maxSize, SerializeIF::Endianness::NETWORK); } diff --git a/src/fsfw/tmtcpacket/pus/tc/PusTcCreator.h b/src/fsfw/tmtcpacket/pus/tc/PusTcCreator.h index b41ad940..63a5d45f 100644 --- a/src/fsfw/tmtcpacket/pus/tc/PusTcCreator.h +++ b/src/fsfw/tmtcpacket/pus/tc/PusTcCreator.h @@ -35,7 +35,7 @@ class PusTcCreator : public PusTcIF, public SerializeIF, public CustomUserDataIF SpacePacketParams &getSpParams(); ReturnValue_t serialize(uint8_t **buffer, size_t *size, size_t maxSize) const override; - ReturnValue_t serialize(uint8_t *buffer, size_t maxSize) const override; + ReturnValue_t serialize(uint8_t *buffer, size_t &serLen, size_t maxSize) const override; [[nodiscard]] size_t getSerializedSize() const override; [[nodiscard]] uint16_t getPacketIdRaw() const override; diff --git a/src/fsfw/tmtcpacket/pus/tm/PusTmCreator.cpp b/src/fsfw/tmtcpacket/pus/tm/PusTmCreator.cpp index 6253bc24..d80182ed 100644 --- a/src/fsfw/tmtcpacket/pus/tm/PusTmCreator.cpp +++ b/src/fsfw/tmtcpacket/pus/tm/PusTmCreator.cpp @@ -94,6 +94,9 @@ ReturnValue_t PusTmCreator::serialize(uint8_t** buffer, size_t* size, size_t max uint16_t crc16 = CRC::crc16ccitt(start, getFullPacketLen() - sizeof(ecss::PusChecksumT)); return SerializeAdapter::serialize(&crc16, buffer, size, maxSize, streamEndianness); } + // Even if no CRC is calculated, account for the space taken by it + *size += 2; + *buffer += 2; return HasReturnvaluesIF::RETURN_OK; } @@ -151,6 +154,6 @@ ReturnValue_t PusTmCreator::serialize(uint8_t** buffer, size_t* size, size_t max return serialize(buffer, size, maxSize, SerializeIF::Endianness::NETWORK); } -ReturnValue_t PusTmCreator::serialize(uint8_t* buffer, size_t maxSize) const { - return SerializeIF::serialize(buffer, maxSize, SerializeIF::Endianness::NETWORK); +ReturnValue_t PusTmCreator::serialize(uint8_t* buffer, size_t& serLen, size_t maxSize) const { + return SerializeIF::serialize(buffer, serLen, maxSize, SerializeIF::Endianness::NETWORK); } \ No newline at end of file diff --git a/src/fsfw/tmtcpacket/pus/tm/PusTmCreator.h b/src/fsfw/tmtcpacket/pus/tm/PusTmCreator.h index c8de3428..a7905858 100644 --- a/src/fsfw/tmtcpacket/pus/tm/PusTmCreator.h +++ b/src/fsfw/tmtcpacket/pus/tm/PusTmCreator.h @@ -74,7 +74,7 @@ class PusTmCreator : public SerializeIF, public PusTmIF, public CustomUserDataIF uint16_t getDestId() override; // Override these to use default big endianness ReturnValue_t serialize(uint8_t** buffer, size_t* size, size_t maxSize) const override; - ReturnValue_t serialize(uint8_t* buffer, size_t maxSize) const override; + ReturnValue_t serialize(uint8_t* buffer, size_t& serLen, size_t maxSize) const override; ReturnValue_t serialize(uint8_t** buffer, size_t* size, size_t maxSize, Endianness streamEndianness) const override; [[nodiscard]] size_t getSerializedSize() const override; diff --git a/unittests/serialize/testSerializeIF.cpp b/unittests/serialize/testSerializeIF.cpp index ecd61357..5200f8b7 100644 --- a/unittests/serialize/testSerializeIF.cpp +++ b/unittests/serialize/testSerializeIF.cpp @@ -24,12 +24,14 @@ TEST_CASE("Serialize IF Serialize", "[serialize-if-ser]") { } SECTION("Little Endian Simple") { - REQUIRE( - simpleSer.SerializeIF::serialize(buf.data(), buf.size(), SerializeIF::Endianness::LITTLE) == - HasReturnvaluesIF::RETURN_OK); + size_t serLen = 0xff; + REQUIRE(simpleSer.SerializeIF::serialize(buf.data(), serLen, buf.size(), + SerializeIF::Endianness::LITTLE) == + HasReturnvaluesIF::RETURN_OK); CHECK(buf[0] == 1); CHECK(buf[1] == 3); CHECK(buf[2] == 2); + CHECK(serLen == 3); } SECTION("Big Endian Normal") { @@ -54,23 +56,25 @@ TEST_CASE("Serialize IF Serialize", "[serialize-if-ser]") { } SECTION("Big Endian Simple") { + size_t serLen = 0xff; SECTION("Explicit") { - REQUIRE( - simpleSer.SerializeIF::serialize(buf.data(), buf.size(), SerializeIF::Endianness::BIG) == - HasReturnvaluesIF::RETURN_OK); + REQUIRE(simpleSer.SerializeIF::serialize(buf.data(), serLen, buf.size(), + SerializeIF::Endianness::BIG) == + HasReturnvaluesIF::RETURN_OK); } SECTION("Network 0") { - REQUIRE(simpleSer.SerializeIF::serialize(buf.data(), buf.size(), + REQUIRE(simpleSer.SerializeIF::serialize(buf.data(), serLen, buf.size(), SerializeIF::Endianness::NETWORK) == HasReturnvaluesIF::RETURN_OK); } SECTION("Network 1") { - REQUIRE(simpleSer.SerializeIF::serializeBe(buf.data(), buf.size()) == + REQUIRE(simpleSer.SerializeIF::serializeBe(buf.data(), serLen, buf.size()) == HasReturnvaluesIF::RETURN_OK); } CHECK(buf[0] == 1); CHECK(buf[1] == 2); CHECK(buf[2] == 3); + CHECK(serLen == 3); } SECTION("Machine Endian Implicit") { @@ -90,7 +94,8 @@ TEST_CASE("Serialize IF Serialize", "[serialize-if-ser]") { } SECTION("Machine Endian Simple Implicit") { - REQUIRE(simpleSer.SerializeIF::serialize(buf.data(), buf.size()) == + size_t serLen = 0xff; + REQUIRE(simpleSer.SerializeIF::serialize(buf.data(), serLen, buf.size()) == HasReturnvaluesIF::RETURN_OK); CHECK(buf[0] == 1); #if BYTE_ORDER_SYSTEM == LITTLE_ENDIAN @@ -100,6 +105,7 @@ TEST_CASE("Serialize IF Serialize", "[serialize-if-ser]") { CHECK(buf[1] == 2); CHECK(buf[2] == 3); #endif + CHECK(serLen == 3); } } @@ -119,10 +125,13 @@ TEST_CASE("SerializeIF Deserialize", "[serialize-if-de]") { } SECTION("Little Endian Simple") { - REQUIRE(simpleSer.SerializeIF::deSerialize(ptr, len, SerializeIF::Endianness::LITTLE) == - HasReturnvaluesIF::RETURN_OK); + size_t deserLen = 0xff; + REQUIRE( + simpleSer.SerializeIF::deSerialize(ptr, deserLen, len, SerializeIF::Endianness::LITTLE) == + HasReturnvaluesIF::RETURN_OK); CHECK(simpleSer.getU8() == 5); CHECK(simpleSer.getU16() == 0x0100); + CHECK(deserLen == 3); } SECTION("Big Endian Normal") { @@ -144,22 +153,24 @@ TEST_CASE("SerializeIF Deserialize", "[serialize-if-de]") { } SECTION("Big Endian Simple") { + size_t deserLen = 0xff; SECTION("Explicit") { - REQUIRE(simpleSer.SerializeIF::deSerialize(buf.data(), buf.size(), + REQUIRE(simpleSer.SerializeIF::deSerialize(buf.data(), deserLen, buf.size(), SerializeIF::Endianness::BIG) == HasReturnvaluesIF::RETURN_OK); } SECTION("Network 0") { - REQUIRE(simpleSer.SerializeIF::deSerialize(buf.data(), buf.size(), + REQUIRE(simpleSer.SerializeIF::deSerialize(buf.data(), deserLen, buf.size(), SerializeIF::Endianness::NETWORK) == HasReturnvaluesIF::RETURN_OK); } SECTION("Network 1") { - REQUIRE(simpleSer.SerializeIF::deSerializeBe(buf.data(), buf.size()) == + REQUIRE(simpleSer.SerializeIF::deSerializeBe(buf.data(), deserLen, buf.size()) == HasReturnvaluesIF::RETURN_OK); } CHECK(simpleSer.getU8() == 5); CHECK(simpleSer.getU16() == 1); + CHECK(deserLen == 3); } SECTION("Machine Endian Implicit") { @@ -176,7 +187,8 @@ TEST_CASE("SerializeIF Deserialize", "[serialize-if-de]") { } SECTION("Machine Endian Simple Implicit") { - REQUIRE(simpleSer.SerializeIF::deSerialize(buf.data(), buf.size()) == + size_t deserLen = 0xff; + REQUIRE(simpleSer.SerializeIF::deSerialize(buf.data(), deserLen, buf.size()) == HasReturnvaluesIF::RETURN_OK); CHECK(simpleSer.getU8() == 5); #if BYTE_ORDER_SYSTEM == LITTLE_ENDIAN @@ -184,5 +196,6 @@ TEST_CASE("SerializeIF Deserialize", "[serialize-if-de]") { #else CHECK(simpleSer.getU16() == 1); #endif + CHECK(deserLen == 3); } } \ No newline at end of file diff --git a/unittests/tmtcpacket/testCcsds.cpp b/unittests/tmtcpacket/testCcsds.cpp index 9be2b8af..095020ae 100644 --- a/unittests/tmtcpacket/testCcsds.cpp +++ b/unittests/tmtcpacket/testCcsds.cpp @@ -42,21 +42,28 @@ TEST_CASE("CCSDS Packet ID", "[ccsds-packet-id]") { packetId.apid = 0x1ff; packetId.secHeaderFlag = false; packetId.packetType = ccsds::PacketType::TM; + size_t serLen = 0; REQUIRE(packetId.raw() == 0x1ff); - REQUIRE(packetId.SerializeIF::serializeBe(buf.data(), buf.size()) == + REQUIRE(packetId.SerializeIF::serializeBe(buf.data(), serLen, buf.size()) == HasReturnvaluesIF::RETURN_OK); CHECK(buf[0] == 0x1); CHECK(buf[1] == 0xff); } SECTION("Invalid Ser") { - REQUIRE(packetId.SerializeIF::serializeBe(buf.data(), 0) == SerializeIF::BUFFER_TOO_SHORT); - REQUIRE(packetId.SerializeIF::serializeBe(buf.data(), 1) == SerializeIF::BUFFER_TOO_SHORT); + size_t serLen = 0; + REQUIRE(packetId.SerializeIF::serializeBe(buf.data(), serLen, 0) == + SerializeIF::BUFFER_TOO_SHORT); + REQUIRE(packetId.SerializeIF::serializeBe(buf.data(), serLen, 1) == + SerializeIF::BUFFER_TOO_SHORT); } SECTION("Invalid Deser") { - REQUIRE(packetId.SerializeIF::deSerialize(buf.data(), 1) == SerializeIF::STREAM_TOO_SHORT); - REQUIRE(packetId.SerializeIF::deSerialize(buf.data(), 0) == SerializeIF::STREAM_TOO_SHORT); + size_t deserLen = 0; + REQUIRE(packetId.SerializeIF::deSerialize(buf.data(), deserLen, 1) == + SerializeIF::STREAM_TOO_SHORT); + REQUIRE(packetId.SerializeIF::deSerialize(buf.data(), deserLen, 0) == + SerializeIF::STREAM_TOO_SHORT); } SECTION("From Raw") { @@ -69,9 +76,11 @@ TEST_CASE("CCSDS Packet ID", "[ccsds-packet-id]") { SECTION("Deserialize") { buf[0] = 0x1a; buf[1] = 0xff; - REQUIRE(packetId.SerializeIF::deSerialize(buf.data(), buf.size()) == + size_t deserLen = 0xff; + REQUIRE(packetId.SerializeIF::deSerialize(buf.data(), deserLen, buf.size()) == HasReturnvaluesIF::RETURN_OK); CHECK(packetId.apid == 0x2ff); + CHECK(deserLen == 2); CHECK(packetId.packetType == ccsds::PacketType::TC); CHECK(packetId.secHeaderFlag == true); } @@ -81,12 +90,15 @@ TEST_CASE("CCSDS Packet Seq Ctrl", "[ccsds-packet-seq-ctrl]") { PacketSeqCtrl psc; std::array buf{}; SECTION("Basic") { + size_t serLen = 0xff; psc.seqFlags = ccsds::SequenceFlags::FIRST_SEGMENT; psc.seqCount = static_cast(std::round(std::pow(2, 14) - 1)); REQUIRE(psc.raw() == 0x7fff); - REQUIRE(psc.SerializeIF::serializeBe(buf.data(), buf.size()) == HasReturnvaluesIF::RETURN_OK); + REQUIRE(psc.SerializeIF::serializeBe(buf.data(), serLen, buf.size()) == + HasReturnvaluesIF::RETURN_OK); CHECK(buf[0] == 0x7f); CHECK(buf[1] == 0xff); + CHECK(serLen == 2); } SECTION("From Raw") { @@ -100,18 +112,23 @@ TEST_CASE("CCSDS Packet Seq Ctrl", "[ccsds-packet-seq-ctrl]") { SECTION("Deserialize") { buf[0] = 0xbf; buf[1] = 0xfe; - REQUIRE(psc.SerializeIF::deSerialize(buf.data(), buf.size()) == HasReturnvaluesIF::RETURN_OK); + size_t deserLen = 0xff; + REQUIRE(psc.SerializeIF::deSerialize(buf.data(), deserLen, buf.size()) == + HasReturnvaluesIF::RETURN_OK); CHECK(psc.seqFlags == ccsds::SequenceFlags::LAST_SEGMENT); + CHECK(deserLen == 2); CHECK(psc.seqCount == static_cast(std::round(std::pow(2, 14) - 2))); } SECTION("Invalid Ser") { - REQUIRE(psc.SerializeIF::serializeBe(buf.data(), 0) == SerializeIF::BUFFER_TOO_SHORT); - REQUIRE(psc.SerializeIF::serializeBe(buf.data(), 1) == SerializeIF::BUFFER_TOO_SHORT); + size_t deserLen = 0; + REQUIRE(psc.SerializeIF::serializeBe(buf.data(), deserLen, 0) == SerializeIF::BUFFER_TOO_SHORT); + REQUIRE(psc.SerializeIF::serializeBe(buf.data(), deserLen, 1) == SerializeIF::BUFFER_TOO_SHORT); } SECTION("Invalid Deser") { - REQUIRE(psc.SerializeIF::deSerialize(buf.data(), 1) == SerializeIF::STREAM_TOO_SHORT); - REQUIRE(psc.SerializeIF::deSerialize(buf.data(), 0) == SerializeIF::STREAM_TOO_SHORT); + size_t deserLen = 0; + REQUIRE(psc.SerializeIF::deSerialize(buf.data(), deserLen, 1) == SerializeIF::STREAM_TOO_SHORT); + REQUIRE(psc.SerializeIF::deSerialize(buf.data(), deserLen, 0) == SerializeIF::STREAM_TOO_SHORT); } } diff --git a/unittests/tmtcpacket/testPusTcCreator.cpp b/unittests/tmtcpacket/testPusTcCreator.cpp index fdda717f..ff9b6399 100644 --- a/unittests/tmtcpacket/testPusTcCreator.cpp +++ b/unittests/tmtcpacket/testPusTcCreator.cpp @@ -94,6 +94,18 @@ TEST_CASE("PUS TC Creator", "[pus-tc-creator]") { REQUIRE(buf[13] == 3); } + SECTION("Test with Application Data Serializable Simple Ser API") { + auto& params = creator.getPusParams(); + auto simpleSer = SimpleSerializable(); + creator.setSerializableUserData(simpleSer); + REQUIRE(creator.getSerializedSize() == 16); + REQUIRE(creator.serialize(dataPtr, serLen, buf.size()) == HasReturnvaluesIF::RETURN_OK); + REQUIRE(serLen == 16); + REQUIRE(buf[11] == 1); + REQUIRE(buf[12] == 2); + REQUIRE(buf[13] == 3); + } + SECTION("Deserialization Fails") { SerializeIF& deser = creator; size_t deserLen = buf.size(); diff --git a/unittests/tmtcservices/testPsb.cpp b/unittests/tmtcservices/testPsb.cpp index e434607f..9404c401 100644 --- a/unittests/tmtcservices/testPsb.cpp +++ b/unittests/tmtcservices/testPsb.cpp @@ -57,7 +57,8 @@ TEST_CASE("Pus Service Base", "[pus-service-base]") { REQUIRE(psb.performServiceCallCnt == 0); uint8_t* dataPtr; REQUIRE(pool.getFreeElement(&storeId, creator.getSerializedSize(), &dataPtr) == retval::OK); - REQUIRE(creator.serializeBe(dataPtr, creator.getSerializedSize()) == retval::OK); + size_t serLen = 0; + REQUIRE(creator.serializeBe(dataPtr, serLen, creator.getSerializedSize()) == retval::OK); tmtcMsg.setStorageId(storeId); msgQueue.addReceivedMessage(tmtcMsg); REQUIRE(psb.performOperation(0) == retval::OK); @@ -77,7 +78,8 @@ TEST_CASE("Pus Service Base", "[pus-service-base]") { SECTION("Send Request with Failed Handling") { uint8_t* dataPtr; REQUIRE(pool.getFreeElement(&storeId, creator.getSerializedSize(), &dataPtr) == retval::OK); - REQUIRE(creator.serializeBe(dataPtr, creator.getSerializedSize()) == retval::OK); + size_t serLen = 0; + REQUIRE(creator.serializeBe(dataPtr, serLen, creator.getSerializedSize()) == retval::OK); tmtcMsg.setStorageId(storeId); msgQueue.addReceivedMessage(tmtcMsg); psb.makeNextHandleReqCallFail(3); -- 2.43.0 From 5355e637114f5160439aadf64b2d455adf1d06f6 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Wed, 27 Jul 2022 21:43:32 +0200 Subject: [PATCH 094/108] use result instead of retval --- src/fsfw/cfdp/definitions.h | 18 +-- src/fsfw/osal/common/TcpTmTcServer.h | 2 +- src/fsfw/returnvalues/HasReturnvaluesIF.h | 12 +- src/fsfw/tasks/FixedTimeslotTaskIF.h | 2 +- src/fsfw_tests/internal/osal/testMq.cpp | 8 +- .../serialize/IntTestSerialization.cpp | 14 +- unittests/CatchDefinitions.h | 5 - unittests/action/TestActionHelper.cpp | 10 +- unittests/cfdp/testCfdp.cpp | 28 ++-- unittests/container/RingBufferTest.cpp | 148 +++++++++--------- unittests/datapoollocal/DataSetTest.cpp | 46 +++--- .../datapoollocal/LocalPoolManagerTest.cpp | 140 ++++++++--------- .../datapoollocal/LocalPoolVariableTest.cpp | 20 +-- .../datapoollocal/LocalPoolVectorTest.cpp | 16 +- unittests/globalfunctions/testDleEncoder.cpp | 4 +- .../TestInternalErrorReporter.cpp | 2 +- unittests/osal/TestMessageQueue.cpp | 16 +- unittests/osal/TestSemaphore.cpp | 4 +- .../serialize/TestSerialBufferAdapter.cpp | 2 +- .../serialize/TestSerialLinkedPacket.cpp | 4 +- unittests/storagemanager/TestNewAccessor.cpp | 42 ++--- unittests/storagemanager/TestPool.cpp | 58 +++---- 22 files changed, 298 insertions(+), 303 deletions(-) diff --git a/src/fsfw/cfdp/definitions.h b/src/fsfw/cfdp/definitions.h index 93d15bcb..7e023881 100644 --- a/src/fsfw/cfdp/definitions.h +++ b/src/fsfw/cfdp/definitions.h @@ -16,27 +16,27 @@ static constexpr uint8_t VERSION_BITS = 0b00100000; static constexpr uint8_t CFDP_CLASS_ID = CLASS_ID::CFDP; static constexpr ReturnValue_t INVALID_TLV_TYPE = - retval::makeCode(CFDP_CLASS_ID, 1); + result::makeCode(CFDP_CLASS_ID, 1); static constexpr ReturnValue_t INVALID_DIRECTIVE_FIELDS = - retval::makeCode(CFDP_CLASS_ID, 2); + result::makeCode(CFDP_CLASS_ID, 2); static constexpr ReturnValue_t INVALID_PDU_DATAFIELD_LEN = - retval::makeCode(CFDP_CLASS_ID, 3); + result::makeCode(CFDP_CLASS_ID, 3); static constexpr ReturnValue_t INVALID_ACK_DIRECTIVE_FIELDS = - retval::makeCode(CFDP_CLASS_ID, 4); + result::makeCode(CFDP_CLASS_ID, 4); //! Can not parse options. This can also occur because there are options //! available but the user did not pass a valid options array static constexpr ReturnValue_t METADATA_CANT_PARSE_OPTIONS = - retval::makeCode(CFDP_CLASS_ID, 5); + result::makeCode(CFDP_CLASS_ID, 5); static constexpr ReturnValue_t NAK_CANT_PARSE_OPTIONS = - retval::makeCode(CFDP_CLASS_ID, 6); + result::makeCode(CFDP_CLASS_ID, 6); static constexpr ReturnValue_t FINISHED_CANT_PARSE_FS_RESPONSES = - retval::makeCode(CFDP_CLASS_ID, 6); + result::makeCode(CFDP_CLASS_ID, 6); static constexpr ReturnValue_t FILESTORE_REQUIRES_SECOND_FILE = - retval::makeCode(CFDP_CLASS_ID, 8); + result::makeCode(CFDP_CLASS_ID, 8); //! Can not parse filestore response because user did not pass a valid instance //! or remaining size is invalid static constexpr ReturnValue_t FILESTORE_RESPONSE_CANT_PARSE_FS_MESSAGE = - retval::makeCode(CFDP_CLASS_ID, 9); + result::makeCode(CFDP_CLASS_ID, 9); //! Checksum types according to the SANA Checksum Types registry //! https://sanaregistry.org/r/checksum_identifiers/ diff --git a/src/fsfw/osal/common/TcpTmTcServer.h b/src/fsfw/osal/common/TcpTmTcServer.h index ae3fce39..1181ff10 100644 --- a/src/fsfw/osal/common/TcpTmTcServer.h +++ b/src/fsfw/osal/common/TcpTmTcServer.h @@ -108,7 +108,7 @@ class TcpTmTcServer : public SystemObject, public TcpIpBase, public ExecutableOb StorageManagerIF* tmStore = nullptr; private: - static constexpr ReturnValue_t CONN_BROKEN = retval::makeCode(1, 0); + static constexpr ReturnValue_t CONN_BROKEN = result::makeCode(1, 0); //! TMTC bridge is cached. object_id_t tmtcBridgeId = objects::NO_OBJECT; TcpTmTcBridge* tmtcBridge = nullptr; diff --git a/src/fsfw/returnvalues/HasReturnvaluesIF.h b/src/fsfw/returnvalues/HasReturnvaluesIF.h index 4d59c26b..20c10e0b 100644 --- a/src/fsfw/returnvalues/HasReturnvaluesIF.h +++ b/src/fsfw/returnvalues/HasReturnvaluesIF.h @@ -10,19 +10,19 @@ #define MAKE_RETURN_CODE(number) ((INTERFACE_ID << 8) + (number)) typedef uint16_t ReturnValue_t; -namespace retval { +namespace result { static constexpr ReturnValue_t OK = 0; static constexpr ReturnValue_t FAILED = 1; static constexpr ReturnValue_t makeCode(uint8_t classId, uint8_t number) { return (static_cast(classId) << 8) + number; } -} // namespace retval +} // namespace result class HasReturnvaluesIF { public: - static const ReturnValue_t RETURN_OK = retval::OK; - static const ReturnValue_t RETURN_FAILED = retval::FAILED; + static const ReturnValue_t RETURN_OK = result::OK; + static const ReturnValue_t RETURN_FAILED = result::FAILED; virtual ~HasReturnvaluesIF() = default; @@ -33,9 +33,9 @@ class HasReturnvaluesIF { * @param number * @return */ - [[deprecated("Use retval::makeCode instead")]] static constexpr ReturnValue_t makeReturnCode( + [[deprecated("Use result::makeCode instead")]] static constexpr ReturnValue_t makeReturnCode( uint8_t classId, uint8_t number) { - return retval::makeCode(classId, number); + return result::makeCode(classId, number); } }; diff --git a/src/fsfw/tasks/FixedTimeslotTaskIF.h b/src/fsfw/tasks/FixedTimeslotTaskIF.h index 6a552d81..c7b90ec3 100644 --- a/src/fsfw/tasks/FixedTimeslotTaskIF.h +++ b/src/fsfw/tasks/FixedTimeslotTaskIF.h @@ -15,7 +15,7 @@ class FixedTimeslotTaskIF : public PeriodicTaskIF { ~FixedTimeslotTaskIF() override = default; static constexpr ReturnValue_t SLOT_LIST_EMPTY = - retval::makeCode(CLASS_ID::FIXED_SLOT_TASK_IF, 0); + result::makeCode(CLASS_ID::FIXED_SLOT_TASK_IF, 0); /** * Add an object with a slot time and the execution step to the task. diff --git a/src/fsfw_tests/internal/osal/testMq.cpp b/src/fsfw_tests/internal/osal/testMq.cpp index 30b46d63..3d8e1034 100644 --- a/src/fsfw_tests/internal/osal/testMq.cpp +++ b/src/fsfw_tests/internal/osal/testMq.cpp @@ -20,22 +20,22 @@ void testmq::testMq() { testSenderMq->setDefaultDestination(testReceiverMqId); auto result = testSenderMq->sendMessage(testReceiverMqId, &testMessage); - if (result != retval::OK) { + if (result != result::OK) { unitt::put_error(id); } MessageQueueMessage recvMessage; result = testReceiverMq->receiveMessage(&recvMessage); - if (result != retval::OK or recvMessage.getData()[0] != 42) { + if (result != result::OK or recvMessage.getData()[0] != 42) { unitt::put_error(id); } result = testSenderMq->sendMessage(testReceiverMqId, &testMessage); - if (result != retval::OK) { + if (result != result::OK) { unitt::put_error(id); } MessageQueueId_t senderId = 0; result = testReceiverMq->receiveMessage(&recvMessage, &senderId); - if (result != retval::OK or recvMessage.getData()[0] != 42) { + if (result != result::OK or recvMessage.getData()[0] != 42) { unitt::put_error(id); } if (senderId != testSenderMqId) { diff --git a/src/fsfw_tests/internal/serialize/IntTestSerialization.cpp b/src/fsfw_tests/internal/serialize/IntTestSerialization.cpp index 1e2a385c..5865f8fc 100644 --- a/src/fsfw_tests/internal/serialize/IntTestSerialization.cpp +++ b/src/fsfw_tests/internal/serialize/IntTestSerialization.cpp @@ -13,18 +13,18 @@ std::array testserialize::test_array = {0}; ReturnValue_t testserialize::test_serialization() { // Here, we test all serialization tools. First test basic cases. ReturnValue_t result = test_endianness_tools(); - if (result != retval::OK) { + if (result != result::OK) { return result; } result = test_autoserialization(); - if (result != retval::OK) { + if (result != result::OK) { return result; } result = test_serial_buffer_adapter(); - if (result != retval::OK) { + if (result != result::OK) { return result; } - return retval::OK; + return result::OK; } ReturnValue_t testserialize::test_endianness_tools() { @@ -48,7 +48,7 @@ ReturnValue_t testserialize::test_endianness_tools() { if (test_array[0] != 0 and test_array[1] != 1) { return unitt::put_error(id); } - return retval::OK; + return result::OK; } ReturnValue_t testserialize::test_autoserialization() { @@ -152,7 +152,7 @@ ReturnValue_t testserialize::test_autoserialization() { } // Check overflow - return retval::OK; + return result::OK; } // TODO: Also test for constant buffers. @@ -205,5 +205,5 @@ ReturnValue_t testserialize::test_serial_buffer_adapter() { if (testUint16 != 16) { return unitt::put_error(id); } - return retval::OK; + return result::OK; } diff --git a/unittests/CatchDefinitions.h b/unittests/CatchDefinitions.h index f0189602..dbe3848b 100644 --- a/unittests/CatchDefinitions.h +++ b/unittests/CatchDefinitions.h @@ -5,11 +5,6 @@ #include #include -namespace retval { -static constexpr int CATCH_OK = static_cast(HasReturnvaluesIF::RETURN_OK); -static constexpr int CATCH_FAILED = static_cast(HasReturnvaluesIF::RETURN_FAILED); -} // namespace retval - namespace tconst { static constexpr MessageQueueId_t testQueueId = 42; } diff --git a/unittests/action/TestActionHelper.cpp b/unittests/action/TestActionHelper.cpp index 6461a195..0d160c6f 100644 --- a/unittests/action/TestActionHelper.cpp +++ b/unittests/action/TestActionHelper.cpp @@ -19,12 +19,12 @@ TEST_CASE("Action Helper", "[ActionHelper]") { StorageManagerIF* ipcStore = tglob::getIpcStoreHandle(); REQUIRE(ipcStore != nullptr); ipcStore->addData(¶mAddress, testParams.data(), 3); - REQUIRE(actionHelper.initialize() == retval::CATCH_OK); + REQUIRE(actionHelper.initialize() == result::OK); SECTION("Simple tests") { ActionMessage::setCommand(&actionMessage, testActionId, paramAddress); CHECK(not testDhMock.executeActionCalled); - REQUIRE(actionHelper.handleActionMessage(&actionMessage) == retval::CATCH_OK); + REQUIRE(actionHelper.handleActionMessage(&actionMessage) == result::OK); CHECK(testDhMock.executeActionCalled); // No message is sent if everything is alright. CHECK(not testMqMock.wasMessageSent()); @@ -82,10 +82,10 @@ TEST_CASE("Action Helper", "[ActionHelper]") { SECTION("Handle failed") { store_address_t toLongParamAddress = StorageManagerIF::INVALID_ADDRESS; std::array toLongData = {5, 4, 3, 2, 1}; - REQUIRE(ipcStore->addData(&toLongParamAddress, toLongData.data(), 5) == retval::CATCH_OK); + REQUIRE(ipcStore->addData(&toLongParamAddress, toLongData.data(), 5) == result::OK); ActionMessage::setCommand(&actionMessage, testActionId, toLongParamAddress); CHECK(not testDhMock.executeActionCalled); - REQUIRE(actionHelper.handleActionMessage(&actionMessage) == retval::CATCH_OK); + REQUIRE(actionHelper.handleActionMessage(&actionMessage) == result::OK); REQUIRE(ipcStore->getData(toLongParamAddress).first == static_cast(StorageManagerIF::DATA_DOES_NOT_EXIST)); CommandMessage testMessage; @@ -100,7 +100,7 @@ TEST_CASE("Action Helper", "[ActionHelper]") { SECTION("Missing IPC Data") { ActionMessage::setCommand(&actionMessage, testActionId, StorageManagerIF::INVALID_ADDRESS); CHECK(not testDhMock.executeActionCalled); - REQUIRE(actionHelper.handleActionMessage(&actionMessage) == retval::CATCH_OK); + REQUIRE(actionHelper.handleActionMessage(&actionMessage) == result::OK); CommandMessage testMessage; REQUIRE(testMqMock.receiveMessage(&testMessage) == static_cast(HasReturnvaluesIF::RETURN_OK)); diff --git a/unittests/cfdp/testCfdp.cpp b/unittests/cfdp/testCfdp.cpp index 78ef618b..e7acab01 100644 --- a/unittests/cfdp/testCfdp.cpp +++ b/unittests/cfdp/testCfdp.cpp @@ -29,10 +29,10 @@ TEST_CASE("CFDP Base", "[CfdpBase]") { const uint8_t** dummyPtr = nullptr; ReturnValue_t deserResult = headerSerializer.deSerialize(dummyPtr, &serSize, SerializeIF::Endianness::NETWORK); - REQUIRE(deserResult == retval::CATCH_FAILED); + REQUIRE(deserResult == result::FAILED); deserResult = headerSerializer.serialize(nullptr, &serSize, serBuf.size(), SerializeIF::Endianness::NETWORK); - REQUIRE(deserResult == retval::CATCH_FAILED); + REQUIRE(deserResult == result::FAILED); REQUIRE(seqNum.getSerializedSize() == 1); REQUIRE(headerSerializer.getPduDataFieldLen() == 0); @@ -62,7 +62,7 @@ TEST_CASE("CFDP Base", "[CfdpBase]") { result = headerSerializer.serialize(&serTarget, &serSize, serBuf.size(), SerializeIF::Endianness::BIG); - REQUIRE(result == retval::CATCH_OK); + REQUIRE(result == result::OK); REQUIRE(serSize == 7); // Only version bits are set REQUIRE(serBuf[0] == 0b00100000); @@ -155,11 +155,11 @@ TEST_CASE("CFDP Base", "[CfdpBase]") { REQUIRE(entityId == 0x00ff00ff); result = pduConf.sourceId.setValue(cfdp::WidthInBytes::ONE_BYTE, 0xfff); - REQUIRE(result == retval::CATCH_FAILED); + REQUIRE(result == result::FAILED); result = pduConf.sourceId.setValue(cfdp::WidthInBytes::TWO_BYTES, 0xfffff); - REQUIRE(result == retval::CATCH_FAILED); + REQUIRE(result == result::FAILED); result = pduConf.sourceId.setValue(cfdp::WidthInBytes::FOUR_BYTES, 0xfffffffff); - REQUIRE(result == retval::CATCH_FAILED); + REQUIRE(result == result::FAILED); uint8_t oneByteSourceId = 32; serTarget = &oneByteSourceId; size_t deserLen = 1; @@ -197,7 +197,7 @@ TEST_CASE("CFDP Base", "[CfdpBase]") { auto headerSerializer = HeaderSerializer(pduConf, cfdp::PduType::FILE_DIRECTIVE, 0); ReturnValue_t result = headerSerializer.serialize(&serTarget, &serSize, serBuf.size(), SerializeIF::Endianness::BIG); - REQUIRE(result == retval::CATCH_OK); + REQUIRE(result == result::OK); REQUIRE(serBuf[1] == 0); REQUIRE(serBuf[2] == 0); // Entity and Transaction Sequence number are 1 byte large @@ -207,7 +207,7 @@ TEST_CASE("CFDP Base", "[CfdpBase]") { auto headerDeser = HeaderDeserializer(serBuf.data(), serBuf.size()); ReturnValue_t serResult = headerDeser.parseData(); - REQUIRE(serResult == retval::CATCH_OK); + REQUIRE(serResult == result::OK); REQUIRE(headerDeser.getPduDataFieldLen() == 0); REQUIRE(headerDeser.getHeaderSize() == 7); REQUIRE(headerDeser.getWholePduSize() == 7); @@ -230,11 +230,11 @@ TEST_CASE("CFDP Base", "[CfdpBase]") { headerSerializer.setPduType(cfdp::PduType::FILE_DATA); headerSerializer.setSegmentMetadataFlag(cfdp::SegmentMetadataFlag::PRESENT); result = pduConf.seqNum.setValue(cfdp::WidthInBytes::TWO_BYTES, 0x0fff); - REQUIRE(result == retval::CATCH_OK); + REQUIRE(result == result::OK); result = pduConf.sourceId.setValue(cfdp::WidthInBytes::FOUR_BYTES, 0xff00ff00); - REQUIRE(result == retval::CATCH_OK); + REQUIRE(result == result::OK); result = pduConf.destId.setValue(cfdp::WidthInBytes::FOUR_BYTES, 0x00ff00ff); - REQUIRE(result == retval::CATCH_OK); + REQUIRE(result == result::OK); serTarget = serBuf.data(); serSize = 0; result = headerSerializer.serialize(&serTarget, &serSize, serBuf.size(), @@ -242,7 +242,7 @@ TEST_CASE("CFDP Base", "[CfdpBase]") { headerDeser = HeaderDeserializer(serBuf.data(), serBuf.size()); result = headerDeser.parseData(); - REQUIRE(result == retval::CATCH_OK); + REQUIRE(result == result::OK); // Everything except version bit flipped to one now REQUIRE(serBuf[0] == 0x3f); REQUIRE(serBuf[3] == 0b11001010); @@ -274,7 +274,7 @@ TEST_CASE("CFDP Base", "[CfdpBase]") { serTarget = serBuf.data(); const uint8_t** serTargetConst = const_cast(&serTarget); result = headerDeser.parseData(); - REQUIRE(result == retval::CATCH_OK); + REQUIRE(result == result::OK); headerDeser.setData(nullptr, -1); REQUIRE(headerDeser.getHeaderSize() == 0); @@ -286,7 +286,7 @@ TEST_CASE("CFDP Base", "[CfdpBase]") { pduConf.destId.setValue(cfdp::WidthInBytes::ONE_BYTE, 48); result = headerSerializer.serialize(&serTarget, &serSize, serBuf.size(), SerializeIF::Endianness::BIG); - REQUIRE(result == retval::CATCH_OK); + REQUIRE(result == result::OK); REQUIRE(headerDeser.getWholePduSize() == 8); headerDeser.setData(serBuf.data(), serBuf.size()); diff --git a/unittests/container/RingBufferTest.cpp b/unittests/container/RingBufferTest.cpp index f4f111a6..edabfd55 100644 --- a/unittests/container/RingBufferTest.cpp +++ b/unittests/container/RingBufferTest.cpp @@ -12,42 +12,42 @@ TEST_CASE("Ring Buffer Test", "[RingBufferTest]") { SECTION("Simple Test") { REQUIRE(ringBuffer.availableWriteSpace() == 9); - REQUIRE(ringBuffer.writeData(testData, 9) == retval::CATCH_OK); - REQUIRE(ringBuffer.writeData(testData, 3) == retval::CATCH_FAILED); - REQUIRE(ringBuffer.readData(readBuffer, 5, true) == retval::CATCH_OK); + REQUIRE(ringBuffer.writeData(testData, 9) == result::OK); + REQUIRE(ringBuffer.writeData(testData, 3) == result::FAILED); + REQUIRE(ringBuffer.readData(readBuffer, 5, true) == result::OK); for (uint8_t i = 0; i < 5; i++) { CHECK(readBuffer[i] == i); } REQUIRE(ringBuffer.availableWriteSpace() == 5); ringBuffer.clear(); REQUIRE(ringBuffer.availableWriteSpace() == 9); - REQUIRE(ringBuffer.writeData(testData, 4) == retval::CATCH_OK); - REQUIRE(ringBuffer.readData(readBuffer, 4, true) == retval::CATCH_OK); + REQUIRE(ringBuffer.writeData(testData, 4) == result::OK); + REQUIRE(ringBuffer.readData(readBuffer, 4, true) == result::OK); for (uint8_t i = 0; i < 4; i++) { CHECK(readBuffer[i] == i); } - REQUIRE(ringBuffer.writeData(testData, 9) == retval::CATCH_OK); - REQUIRE(ringBuffer.readData(readBuffer, 9, true) == retval::CATCH_OK); + REQUIRE(ringBuffer.writeData(testData, 9) == result::OK); + REQUIRE(ringBuffer.readData(readBuffer, 9, true) == result::OK); for (uint8_t i = 0; i < 9; i++) { CHECK(readBuffer[i] == i); } - REQUIRE(ringBuffer.writeData(testData, 1024) == retval::CATCH_FAILED); - REQUIRE(ringBuffer.writeData(nullptr, 5) == retval::CATCH_FAILED); + REQUIRE(ringBuffer.writeData(testData, 1024) == result::FAILED); + REQUIRE(ringBuffer.writeData(nullptr, 5) == result::FAILED); } SECTION("Get Free Element Test") { REQUIRE(ringBuffer.availableWriteSpace() == 9); - REQUIRE(ringBuffer.writeData(testData, 8) == retval::CATCH_OK); + REQUIRE(ringBuffer.writeData(testData, 8) == result::OK); REQUIRE(ringBuffer.availableWriteSpace() == 1); - REQUIRE(ringBuffer.readData(readBuffer, 8, true) == retval::CATCH_OK); + REQUIRE(ringBuffer.readData(readBuffer, 8, true) == result::OK); REQUIRE(ringBuffer.availableWriteSpace() == 9); uint8_t *testPtr = nullptr; - REQUIRE(ringBuffer.getFreeElement(&testPtr, 10) == retval::CATCH_FAILED); + REQUIRE(ringBuffer.getFreeElement(&testPtr, 10) == result::FAILED); REQUIRE(ringBuffer.writeTillWrap() == 2); // too many excess bytes. - REQUIRE(ringBuffer.getFreeElement(&testPtr, 8) == retval::CATCH_FAILED); - REQUIRE(ringBuffer.getFreeElement(&testPtr, 5) == retval::CATCH_OK); + REQUIRE(ringBuffer.getFreeElement(&testPtr, 8) == result::FAILED); + REQUIRE(ringBuffer.getFreeElement(&testPtr, 5) == result::OK); REQUIRE(ringBuffer.getExcessBytes() == 3); std::memcpy(testPtr, testData, 5); ringBuffer.confirmBytesWritten(5); @@ -59,19 +59,19 @@ TEST_CASE("Ring Buffer Test", "[RingBufferTest]") { } SECTION("Read Remaining Test") { - REQUIRE(ringBuffer.writeData(testData, 3) == retval::CATCH_OK); + REQUIRE(ringBuffer.writeData(testData, 3) == result::OK); REQUIRE(ringBuffer.getAvailableReadData() == 3); - REQUIRE(ringBuffer.readData(readBuffer, 5, false, false, nullptr) == retval::CATCH_FAILED); + REQUIRE(ringBuffer.readData(readBuffer, 5, false, false, nullptr) == result::FAILED); size_t trueSize = 0; - REQUIRE(ringBuffer.readData(readBuffer, 5, false, true, &trueSize) == retval::CATCH_OK); + REQUIRE(ringBuffer.readData(readBuffer, 5, false, true, &trueSize) == result::OK); REQUIRE(trueSize == 3); for (uint8_t i = 0; i < 3; i++) { CHECK(readBuffer[i] == i); } trueSize = 0; - REQUIRE(ringBuffer.deleteData(5, false, &trueSize) == retval::CATCH_FAILED); + REQUIRE(ringBuffer.deleteData(5, false, &trueSize) == result::FAILED); REQUIRE(trueSize == 0); - REQUIRE(ringBuffer.deleteData(5, true, &trueSize) == retval::CATCH_OK); + REQUIRE(ringBuffer.deleteData(5, true, &trueSize) == result::OK); REQUIRE(trueSize == 3); } } @@ -84,21 +84,21 @@ TEST_CASE("Ring Buffer Test2", "[RingBufferTest2]") { SECTION("Simple Test") { REQUIRE(ringBuffer.availableWriteSpace() == 9); - REQUIRE(ringBuffer.writeData(testData, 9) == retval::CATCH_OK); - REQUIRE(ringBuffer.readData(readBuffer, 5, true) == retval::CATCH_OK); + REQUIRE(ringBuffer.writeData(testData, 9) == result::OK); + REQUIRE(ringBuffer.readData(readBuffer, 5, true) == result::OK); for (uint8_t i = 0; i < 5; i++) { CHECK(readBuffer[i] == i); } REQUIRE(ringBuffer.availableWriteSpace() == 5); ringBuffer.clear(); REQUIRE(ringBuffer.availableWriteSpace() == 9); - REQUIRE(ringBuffer.writeData(testData, 4) == retval::CATCH_OK); - REQUIRE(ringBuffer.readData(readBuffer, 4, true) == retval::CATCH_OK); + REQUIRE(ringBuffer.writeData(testData, 4) == result::OK); + REQUIRE(ringBuffer.readData(readBuffer, 4, true) == result::OK); for (uint8_t i = 0; i < 4; i++) { CHECK(readBuffer[i] == i); } - REQUIRE(ringBuffer.writeData(testData, 9) == retval::CATCH_OK); - REQUIRE(ringBuffer.readData(readBuffer, 9, true) == retval::CATCH_OK); + REQUIRE(ringBuffer.writeData(testData, 9) == result::OK); + REQUIRE(ringBuffer.readData(readBuffer, 9, true) == result::OK); for (uint8_t i = 0; i < 9; i++) { CHECK(readBuffer[i] == i); } @@ -106,17 +106,17 @@ TEST_CASE("Ring Buffer Test2", "[RingBufferTest2]") { SECTION("Get Free Element Test") { REQUIRE(ringBuffer.availableWriteSpace() == 9); - REQUIRE(ringBuffer.writeData(testData, 8) == retval::CATCH_OK); + REQUIRE(ringBuffer.writeData(testData, 8) == result::OK); REQUIRE(ringBuffer.availableWriteSpace() == 1); - REQUIRE(ringBuffer.readData(readBuffer, 8, true) == retval::CATCH_OK); + REQUIRE(ringBuffer.readData(readBuffer, 8, true) == result::OK); REQUIRE(ringBuffer.availableWriteSpace() == 9); uint8_t *testPtr = nullptr; - REQUIRE(ringBuffer.getFreeElement(&testPtr, 10) == retval::CATCH_FAILED); + REQUIRE(ringBuffer.getFreeElement(&testPtr, 10) == result::FAILED); REQUIRE(ringBuffer.writeTillWrap() == 2); // too many excess bytes. - REQUIRE(ringBuffer.getFreeElement(&testPtr, 8) == retval::CATCH_FAILED); - REQUIRE(ringBuffer.getFreeElement(&testPtr, 5) == retval::CATCH_OK); + REQUIRE(ringBuffer.getFreeElement(&testPtr, 8) == result::FAILED); + REQUIRE(ringBuffer.getFreeElement(&testPtr, 5) == result::OK); REQUIRE(ringBuffer.getExcessBytes() == 3); std::memcpy(testPtr, testData, 5); ringBuffer.confirmBytesWritten(5); @@ -128,19 +128,19 @@ TEST_CASE("Ring Buffer Test2", "[RingBufferTest2]") { } SECTION("Read Remaining Test") { - REQUIRE(ringBuffer.writeData(testData, 3) == retval::CATCH_OK); + REQUIRE(ringBuffer.writeData(testData, 3) == result::OK); REQUIRE(ringBuffer.getAvailableReadData() == 3); - REQUIRE(ringBuffer.readData(readBuffer, 5, false, false, nullptr) == retval::CATCH_FAILED); + REQUIRE(ringBuffer.readData(readBuffer, 5, false, false, nullptr) == result::FAILED); size_t trueSize = 0; - REQUIRE(ringBuffer.readData(readBuffer, 5, false, true, &trueSize) == retval::CATCH_OK); + REQUIRE(ringBuffer.readData(readBuffer, 5, false, true, &trueSize) == result::OK); REQUIRE(trueSize == 3); for (uint8_t i = 0; i < 3; i++) { CHECK(readBuffer[i] == i); } trueSize = 0; - REQUIRE(ringBuffer.deleteData(5, false, &trueSize) == retval::CATCH_FAILED); + REQUIRE(ringBuffer.deleteData(5, false, &trueSize) == result::FAILED); REQUIRE(trueSize == 0); - REQUIRE(ringBuffer.deleteData(5, true, &trueSize) == retval::CATCH_OK); + REQUIRE(ringBuffer.deleteData(5, true, &trueSize) == result::OK); REQUIRE(trueSize == 3); } @@ -148,17 +148,17 @@ TEST_CASE("Ring Buffer Test2", "[RingBufferTest2]") { REQUIRE(ringBuffer.availableWriteSpace() == 9); // We don't allow writing of Data that is larger than the ring buffer in total REQUIRE(ringBuffer.getMaxSize() == 9); - REQUIRE(ringBuffer.writeData(testData, 13) == retval::CATCH_FAILED); + REQUIRE(ringBuffer.writeData(testData, 13) == result::FAILED); REQUIRE(ringBuffer.getAvailableReadData() == 0); ringBuffer.clear(); uint8_t *ptr = nullptr; // With excess Bytes 13 Bytes can be written to this Buffer - REQUIRE(ringBuffer.getFreeElement(&ptr, 13) == retval::CATCH_OK); + REQUIRE(ringBuffer.getFreeElement(&ptr, 13) == result::OK); REQUIRE(ptr != nullptr); memcpy(ptr, testData, 13); ringBuffer.confirmBytesWritten(13); REQUIRE(ringBuffer.getAvailableReadData() == 3); - REQUIRE(ringBuffer.readData(readBuffer, 3, true) == retval::CATCH_OK); + REQUIRE(ringBuffer.readData(readBuffer, 3, true) == result::OK); for (auto i = 0; i < 3; i++) { REQUIRE(readBuffer[i] == testData[i + 10]); } @@ -173,21 +173,21 @@ TEST_CASE("Ring Buffer Test3", "[RingBufferTest3]") { SECTION("Simple Test") { REQUIRE(ringBuffer.availableWriteSpace() == 9); - REQUIRE(ringBuffer.writeData(testData, 9) == retval::CATCH_OK); - REQUIRE(ringBuffer.readData(readBuffer, 5, true) == retval::CATCH_OK); + REQUIRE(ringBuffer.writeData(testData, 9) == result::OK); + REQUIRE(ringBuffer.readData(readBuffer, 5, true) == result::OK); for (uint8_t i = 0; i < 5; i++) { CHECK(readBuffer[i] == i); } REQUIRE(ringBuffer.availableWriteSpace() == 5); ringBuffer.clear(); REQUIRE(ringBuffer.availableWriteSpace() == 9); - REQUIRE(ringBuffer.writeData(testData, 4) == retval::CATCH_OK); - REQUIRE(ringBuffer.readData(readBuffer, 4, true) == retval::CATCH_OK); + REQUIRE(ringBuffer.writeData(testData, 4) == result::OK); + REQUIRE(ringBuffer.readData(readBuffer, 4, true) == result::OK); for (uint8_t i = 0; i < 4; i++) { CHECK(readBuffer[i] == i); } - REQUIRE(ringBuffer.writeData(testData, 9) == retval::CATCH_OK); - REQUIRE(ringBuffer.readData(readBuffer, 9, true) == retval::CATCH_OK); + REQUIRE(ringBuffer.writeData(testData, 9) == result::OK); + REQUIRE(ringBuffer.readData(readBuffer, 9, true) == result::OK); for (uint8_t i = 0; i < 9; i++) { CHECK(readBuffer[i] == i); } @@ -195,19 +195,19 @@ TEST_CASE("Ring Buffer Test3", "[RingBufferTest3]") { SECTION("Get Free Element Test") { REQUIRE(ringBuffer.availableWriteSpace() == 9); - REQUIRE(ringBuffer.writeData(testData, 8) == retval::CATCH_OK); + REQUIRE(ringBuffer.writeData(testData, 8) == result::OK); REQUIRE(ringBuffer.availableWriteSpace() == 1); - REQUIRE(ringBuffer.readData(readBuffer, 8, true) == retval::CATCH_OK); + REQUIRE(ringBuffer.readData(readBuffer, 8, true) == result::OK); REQUIRE(ringBuffer.availableWriteSpace() == 9); uint8_t *testPtr = nullptr; - REQUIRE(ringBuffer.getFreeElement(&testPtr, 10) == retval::CATCH_OK); + REQUIRE(ringBuffer.getFreeElement(&testPtr, 10) == result::OK); REQUIRE(ringBuffer.getExcessBytes() == 8); REQUIRE(ringBuffer.writeTillWrap() == 2); // too many excess bytes. - REQUIRE(ringBuffer.getFreeElement(&testPtr, 8) == retval::CATCH_FAILED); + REQUIRE(ringBuffer.getFreeElement(&testPtr, 8) == result::FAILED); // Less Execss bytes overwrites before - REQUIRE(ringBuffer.getFreeElement(&testPtr, 3) == retval::CATCH_OK); + REQUIRE(ringBuffer.getFreeElement(&testPtr, 3) == result::OK); REQUIRE(ringBuffer.getExcessBytes() == 1); std::memcpy(testPtr, testData, 3); ringBuffer.confirmBytesWritten(3); @@ -219,19 +219,19 @@ TEST_CASE("Ring Buffer Test3", "[RingBufferTest3]") { } SECTION("Read Remaining Test") { - REQUIRE(ringBuffer.writeData(testData, 3) == retval::CATCH_OK); + REQUIRE(ringBuffer.writeData(testData, 3) == result::OK); REQUIRE(ringBuffer.getAvailableReadData() == 3); - REQUIRE(ringBuffer.readData(readBuffer, 5, false, false, nullptr) == retval::CATCH_FAILED); + REQUIRE(ringBuffer.readData(readBuffer, 5, false, false, nullptr) == result::FAILED); size_t trueSize = 0; - REQUIRE(ringBuffer.readData(readBuffer, 5, false, true, &trueSize) == retval::CATCH_OK); + REQUIRE(ringBuffer.readData(readBuffer, 5, false, true, &trueSize) == result::OK); REQUIRE(trueSize == 3); for (uint8_t i = 0; i < 3; i++) { CHECK(readBuffer[i] == i); } trueSize = 0; - REQUIRE(ringBuffer.deleteData(5, false, &trueSize) == retval::CATCH_FAILED); + REQUIRE(ringBuffer.deleteData(5, false, &trueSize) == result::FAILED); REQUIRE(trueSize == 0); - REQUIRE(ringBuffer.deleteData(5, true, &trueSize) == retval::CATCH_OK); + REQUIRE(ringBuffer.deleteData(5, true, &trueSize) == result::OK); REQUIRE(trueSize == 3); } @@ -239,18 +239,18 @@ TEST_CASE("Ring Buffer Test3", "[RingBufferTest3]") { REQUIRE(ringBuffer.availableWriteSpace() == 9); // Writing more than the buffer is large. // This write will be rejected and is seen as a configuration mistake - REQUIRE(ringBuffer.writeData(testData, 13) == retval::CATCH_FAILED); + REQUIRE(ringBuffer.writeData(testData, 13) == result::FAILED); REQUIRE(ringBuffer.getAvailableReadData() == 0); ringBuffer.clear(); // Using FreeElement allows the usage of excessBytes but // should be used with caution uint8_t *ptr = nullptr; - REQUIRE(ringBuffer.getFreeElement(&ptr, 13) == retval::CATCH_OK); + REQUIRE(ringBuffer.getFreeElement(&ptr, 13) == result::OK); REQUIRE(ptr != nullptr); memcpy(ptr, testData, 13); ringBuffer.confirmBytesWritten(13); REQUIRE(ringBuffer.getAvailableReadData() == 3); - REQUIRE(ringBuffer.readData(readBuffer, 3, true) == retval::CATCH_OK); + REQUIRE(ringBuffer.readData(readBuffer, 3, true) == result::OK); for (auto i = 0; i < 3; i++) { REQUIRE(readBuffer[i] == testData[i + 10]); } @@ -264,22 +264,22 @@ TEST_CASE("Ring Buffer Test4", "[RingBufferTest4]") { SECTION("Simple Test") { REQUIRE(ringBuffer.availableWriteSpace() == 9); - REQUIRE(ringBuffer.writeData(testData, 9) == retval::CATCH_OK); - REQUIRE(ringBuffer.writeData(testData, 3) == retval::CATCH_FAILED); - REQUIRE(ringBuffer.readData(readBuffer, 5, true) == retval::CATCH_OK); + REQUIRE(ringBuffer.writeData(testData, 9) == result::OK); + REQUIRE(ringBuffer.writeData(testData, 3) == result::FAILED); + REQUIRE(ringBuffer.readData(readBuffer, 5, true) == result::OK); for (uint8_t i = 0; i < 5; i++) { CHECK(readBuffer[i] == i); } REQUIRE(ringBuffer.availableWriteSpace() == 5); ringBuffer.clear(); REQUIRE(ringBuffer.availableWriteSpace() == 9); - REQUIRE(ringBuffer.writeData(testData, 4) == retval::CATCH_OK); - REQUIRE(ringBuffer.readData(readBuffer, 4, true) == retval::CATCH_OK); + REQUIRE(ringBuffer.writeData(testData, 4) == result::OK); + REQUIRE(ringBuffer.readData(readBuffer, 4, true) == result::OK); for (uint8_t i = 0; i < 4; i++) { CHECK(readBuffer[i] == i); } - REQUIRE(ringBuffer.writeData(testData, 9) == retval::CATCH_OK); - REQUIRE(ringBuffer.readData(readBuffer, 9, true) == retval::CATCH_OK); + REQUIRE(ringBuffer.writeData(testData, 9) == result::OK); + REQUIRE(ringBuffer.readData(readBuffer, 9, true) == result::OK); for (uint8_t i = 0; i < 9; i++) { CHECK(readBuffer[i] == i); } @@ -287,16 +287,16 @@ TEST_CASE("Ring Buffer Test4", "[RingBufferTest4]") { SECTION("Get Free Element Test") { REQUIRE(ringBuffer.availableWriteSpace() == 9); - REQUIRE(ringBuffer.writeData(testData, 8) == retval::CATCH_OK); + REQUIRE(ringBuffer.writeData(testData, 8) == result::OK); REQUIRE(ringBuffer.availableWriteSpace() == 1); - REQUIRE(ringBuffer.readData(readBuffer, 8, true) == retval::CATCH_OK); + REQUIRE(ringBuffer.readData(readBuffer, 8, true) == result::OK); REQUIRE(ringBuffer.availableWriteSpace() == 9); uint8_t *testPtr = nullptr; - REQUIRE(ringBuffer.getFreeElement(&testPtr, 10) == retval::CATCH_FAILED); + REQUIRE(ringBuffer.getFreeElement(&testPtr, 10) == result::FAILED); REQUIRE(ringBuffer.writeTillWrap() == 2); - REQUIRE(ringBuffer.getFreeElement(&testPtr, 8) == retval::CATCH_OK); - REQUIRE(ringBuffer.getFreeElement(&testPtr, 5) == retval::CATCH_OK); + REQUIRE(ringBuffer.getFreeElement(&testPtr, 8) == result::OK); + REQUIRE(ringBuffer.getFreeElement(&testPtr, 5) == result::OK); REQUIRE(ringBuffer.getExcessBytes() == 3); std::memcpy(testPtr, testData, 5); ringBuffer.confirmBytesWritten(5); @@ -308,19 +308,19 @@ TEST_CASE("Ring Buffer Test4", "[RingBufferTest4]") { } SECTION("Read Remaining Test") { - REQUIRE(ringBuffer.writeData(testData, 3) == retval::CATCH_OK); + REQUIRE(ringBuffer.writeData(testData, 3) == result::OK); REQUIRE(ringBuffer.getAvailableReadData() == 3); - REQUIRE(ringBuffer.readData(readBuffer, 5, false, false, nullptr) == retval::CATCH_FAILED); + REQUIRE(ringBuffer.readData(readBuffer, 5, false, false, nullptr) == result::FAILED); size_t trueSize = 0; - REQUIRE(ringBuffer.readData(readBuffer, 5, false, true, &trueSize) == retval::CATCH_OK); + REQUIRE(ringBuffer.readData(readBuffer, 5, false, true, &trueSize) == result::OK); REQUIRE(trueSize == 3); for (uint8_t i = 0; i < 3; i++) { CHECK(readBuffer[i] == i); } trueSize = 0; - REQUIRE(ringBuffer.deleteData(5, false, &trueSize) == retval::CATCH_FAILED); + REQUIRE(ringBuffer.deleteData(5, false, &trueSize) == result::FAILED); REQUIRE(trueSize == 0); - REQUIRE(ringBuffer.deleteData(5, true, &trueSize) == retval::CATCH_OK); + REQUIRE(ringBuffer.deleteData(5, true, &trueSize) == result::OK); REQUIRE(trueSize == 3); } } diff --git a/unittests/datapoollocal/DataSetTest.cpp b/unittests/datapoollocal/DataSetTest.cpp index c9f023ef..45085eaf 100644 --- a/unittests/datapoollocal/DataSetTest.cpp +++ b/unittests/datapoollocal/DataSetTest.cpp @@ -16,8 +16,8 @@ TEST_CASE("DataSetTest", "[DataSetTest]") { LocalPoolOwnerBase* poolOwner = ObjectManager::instance()->get(objects::TEST_LOCAL_POOL_OWNER_BASE); REQUIRE(poolOwner != nullptr); - REQUIRE(poolOwner->initializeHkManager() == retval::CATCH_OK); - REQUIRE(poolOwner->initializeHkManagerAfterTaskCreation() == retval::CATCH_OK); + REQUIRE(poolOwner->initializeHkManager() == result::OK); + REQUIRE(poolOwner->initializeHkManagerAfterTaskCreation() == result::OK); LocalPoolStaticTestDataSet localSet; SECTION("BasicTest") { @@ -36,7 +36,7 @@ TEST_CASE("DataSetTest", "[DataSetTest]") { /* Test local pool ID serialization */ CHECK(localSet.serializeLocalPoolIds(&localPoolIdBuffPtr, &serSize, maxSize, - SerializeIF::Endianness::MACHINE) == retval::CATCH_OK); + SerializeIF::Endianness::MACHINE) == result::OK); CHECK(serSize == maxSize); CHECK(localPoolIdBuff[0] == 3); CHECK(lpIds[0] == localSet.localPoolVarUint8.getDataPoolId()); @@ -48,7 +48,7 @@ TEST_CASE("DataSetTest", "[DataSetTest]") { serSize = 0; CHECK(localSet.serializeLocalPoolIds(&localPoolIdBuffPtr, &serSize, maxSize, SerializeIF::Endianness::MACHINE, - false) == retval::CATCH_OK); + false) == result::OK); CHECK(serSize == maxSize - sizeof(uint8_t)); CHECK(lpIds[0] == localSet.localPoolVarUint8.getDataPoolId()); CHECK(lpIds[1] == localSet.localPoolVarFloat.getDataPoolId()); @@ -57,7 +57,7 @@ TEST_CASE("DataSetTest", "[DataSetTest]") { { /* Test read operation. Values should be all zeros */ PoolReadGuard readHelper(&localSet); - REQUIRE(readHelper.getReadResult() == retval::CATCH_OK); + REQUIRE(readHelper.getReadResult() == result::OK); CHECK(not localSet.isValid()); CHECK(localSet.localPoolVarUint8.value == 0); CHECK(not localSet.localPoolVarUint8.isValid()); @@ -90,7 +90,7 @@ TEST_CASE("DataSetTest", "[DataSetTest]") { /* Now we read again and check whether our zeroed values were overwritten with the values in the pool */ PoolReadGuard readHelper(&localSet); - REQUIRE(readHelper.getReadResult() == retval::CATCH_OK); + REQUIRE(readHelper.getReadResult() == result::OK); CHECK(localSet.isValid()); CHECK(localSet.localPoolVarUint8.value == 232); CHECK(localSet.localPoolVarUint8.isValid()); @@ -110,7 +110,7 @@ TEST_CASE("DataSetTest", "[DataSetTest]") { uint8_t buffer[maxSize + 1]; uint8_t* buffPtr = buffer; CHECK(localSet.serialize(&buffPtr, &serSize, maxSize, SerializeIF::Endianness::MACHINE) == - retval::CATCH_OK); + result::OK); uint8_t rawUint8 = buffer[0]; CHECK(rawUint8 == 232); float rawFloat = 0.0; @@ -128,7 +128,7 @@ TEST_CASE("DataSetTest", "[DataSetTest]") { std::memset(buffer, 0, sizeof(buffer)); const uint8_t* constBuffPtr = buffer; CHECK(localSet.deSerialize(&constBuffPtr, &sizeToDeserialize, - SerializeIF::Endianness::MACHINE) == retval::CATCH_OK); + SerializeIF::Endianness::MACHINE) == result::OK); /* Check whether deserialization was successfull */ CHECK(localSet.localPoolVarUint8.value == 0); CHECK(localSet.localPoolVarFloat.value == Catch::Approx(0.0)); @@ -156,7 +156,7 @@ TEST_CASE("DataSetTest", "[DataSetTest]") { serSize = 0; buffPtr = buffer; CHECK(localSet.serialize(&buffPtr, &serSize, maxSize, SerializeIF::Endianness::MACHINE) == - retval::CATCH_OK); + result::OK); CHECK(rawUint8 == 232); std::memcpy(&rawFloat, buffer + sizeof(uint8_t), sizeof(float)); CHECK(rawFloat == Catch::Approx(-2324.322)); @@ -186,7 +186,7 @@ TEST_CASE("DataSetTest", "[DataSetTest]") { sizeToDeserialize = maxSize; constBuffPtr = buffer; CHECK(localSet.deSerialize(&constBuffPtr, &sizeToDeserialize, - SerializeIF::Endianness::MACHINE) == retval::CATCH_OK); + SerializeIF::Endianness::MACHINE) == result::OK); /* Check whether deserialization was successfull */ CHECK(localSet.localPoolVarUint8.value == 0); CHECK(localSet.localPoolVarFloat.value == Catch::Approx(0.0)); @@ -213,10 +213,10 @@ TEST_CASE("DataSetTest", "[DataSetTest]") { /* Register same variables again to get more than 8 registered variables */ for (uint8_t idx = 0; idx < 8; idx++) { - REQUIRE(set.registerVariable(&localSet.localPoolVarUint8) == retval::CATCH_OK); + REQUIRE(set.registerVariable(&localSet.localPoolVarUint8) == result::OK); } - REQUIRE(set.registerVariable(&localSet.localPoolVarUint8) == retval::CATCH_OK); - REQUIRE(set.registerVariable(&localSet.localPoolUint16Vec) == retval::CATCH_OK); + REQUIRE(set.registerVariable(&localSet.localPoolVarUint8) == result::OK); + REQUIRE(set.registerVariable(&localSet.localPoolUint16Vec) == result::OK); set.setValidityBufferGeneration(true); { @@ -233,7 +233,7 @@ TEST_CASE("DataSetTest", "[DataSetTest]") { uint8_t buffer[maxSize + 1]; uint8_t* buffPtr = buffer; CHECK(set.serialize(&buffPtr, &serSize, maxSize, SerializeIF::Endianness::MACHINE) == - retval::CATCH_OK); + result::OK); std::array validityBuffer; std::memcpy(validityBuffer.data(), buffer + 9 + sizeof(uint16_t) * 3, 2); /* The first 9 variables should be valid */ @@ -251,7 +251,7 @@ TEST_CASE("DataSetTest", "[DataSetTest]") { const uint8_t* constBuffPtr = buffer; size_t sizeToDeSerialize = serSize; CHECK(set.deSerialize(&constBuffPtr, &sizeToDeSerialize, SerializeIF::Endianness::MACHINE) == - retval::CATCH_OK); + result::OK); CHECK(localSet.localPoolVarUint8.isValid() == false); CHECK(localSet.localPoolUint16Vec.isValid() == true); } @@ -261,20 +261,20 @@ TEST_CASE("DataSetTest", "[DataSetTest]") { SharedLocalDataSet sharedSet(sharedSetId, poolOwner, lpool::testSetId, 5); localSet.localPoolVarUint8.setReadWriteMode(pool_rwm_t::VAR_WRITE); localSet.localPoolUint16Vec.setReadWriteMode(pool_rwm_t::VAR_WRITE); - CHECK(sharedSet.registerVariable(&localSet.localPoolVarUint8) == retval::CATCH_OK); - CHECK(sharedSet.registerVariable(&localSet.localPoolUint16Vec) == retval::CATCH_OK); - CHECK(sharedSet.initialize() == retval::CATCH_OK); - CHECK(sharedSet.lockDataset() == retval::CATCH_OK); - CHECK(sharedSet.unlockDataset() == retval::CATCH_OK); + CHECK(sharedSet.registerVariable(&localSet.localPoolVarUint8) == result::OK); + CHECK(sharedSet.registerVariable(&localSet.localPoolUint16Vec) == result::OK); + CHECK(sharedSet.initialize() == result::OK); + CHECK(sharedSet.lockDataset() == result::OK); + CHECK(sharedSet.unlockDataset() == result::OK); { // PoolReadGuard rg(&sharedSet); - // CHECK(rg.getReadResult() == retval::CATCH_OK); + // CHECK(rg.getReadResult() == result::OK); localSet.localPoolVarUint8.value = 5; localSet.localPoolUint16Vec.value[0] = 1; localSet.localPoolUint16Vec.value[1] = 2; localSet.localPoolUint16Vec.value[2] = 3; - CHECK(sharedSet.commit() == retval::CATCH_OK); + CHECK(sharedSet.commit() == result::OK); } sharedSet.setReadCommitProtectionBehaviour(true); @@ -282,5 +282,5 @@ TEST_CASE("DataSetTest", "[DataSetTest]") { /* we need to reset the subscription list because the pool owner is a global object. */ - CHECK(poolOwner->reset() == retval::CATCH_OK); + CHECK(poolOwner->reset() == result::OK); } diff --git a/unittests/datapoollocal/LocalPoolManagerTest.cpp b/unittests/datapoollocal/LocalPoolManagerTest.cpp index 58a6065e..4fc67c97 100644 --- a/unittests/datapoollocal/LocalPoolManagerTest.cpp +++ b/unittests/datapoollocal/LocalPoolManagerTest.cpp @@ -18,8 +18,8 @@ TEST_CASE("LocalPoolManagerTest", "[LocManTest]") { LocalPoolOwnerBase* poolOwner = ObjectManager::instance()->get(objects::TEST_LOCAL_POOL_OWNER_BASE); REQUIRE(poolOwner != nullptr); - REQUIRE(poolOwner->initializeHkManager() == retval::CATCH_OK); - REQUIRE(poolOwner->initializeHkManagerAfterTaskCreation() == retval::CATCH_OK); + REQUIRE(poolOwner->initializeHkManager() == result::OK); + REQUIRE(poolOwner->initializeHkManagerAfterTaskCreation() == result::OK); MessageQueueMockBase* poolOwnerMock = poolOwner->getMockQueueHandle(); REQUIRE(poolOwnerMock != nullptr); @@ -38,14 +38,14 @@ TEST_CASE("LocalPoolManagerTest", "[LocManTest]") { CHECK(owner->getObjectId() == objects::TEST_LOCAL_POOL_OWNER_BASE); /* Subscribe for message generation on update. */ - REQUIRE(poolOwner->subscribeWrapperSetUpdate() == retval::CATCH_OK); + REQUIRE(poolOwner->subscribeWrapperSetUpdate() == result::OK); /* Subscribe for an update message. */ poolOwner->dataset.setChanged(true); /* Now the update message should be generated. */ - REQUIRE(poolOwner->poolManager.performHkOperation() == retval::CATCH_OK); + REQUIRE(poolOwner->poolManager.performHkOperation() == result::OK); REQUIRE(poolOwnerMock->wasMessageSent() == true); - REQUIRE(poolOwnerMock->receiveMessage(&messageSent) == retval::CATCH_OK); + REQUIRE(poolOwnerMock->receiveMessage(&messageSent) == result::OK); CHECK(messageSent.getCommand() == static_cast(HousekeepingMessage::UPDATE_NOTIFICATION_SET)); @@ -53,27 +53,27 @@ TEST_CASE("LocalPoolManagerTest", "[LocManTest]") { CHECK(poolOwner->dataset.hasChanged() == false); /* Set changed again, result should be the same. */ poolOwner->dataset.setChanged(true); - REQUIRE(poolOwner->poolManager.performHkOperation() == retval::CATCH_OK); + REQUIRE(poolOwner->poolManager.performHkOperation() == result::OK); REQUIRE(poolOwnerMock->wasMessageSent(&messagesSent) == true); CHECK(messagesSent == 1); - REQUIRE(poolOwnerMock->receiveMessage(&messageSent) == retval::CATCH_OK); + REQUIRE(poolOwnerMock->receiveMessage(&messageSent) == result::OK); CHECK(messageSent.getCommand() == static_cast(HousekeepingMessage::UPDATE_NOTIFICATION_SET)); /* Now subscribe for set update HK as well. */ - REQUIRE(poolOwner->subscribeWrapperSetUpdateHk() == retval::CATCH_OK); + REQUIRE(poolOwner->subscribeWrapperSetUpdateHk() == result::OK); poolOwner->dataset.setChanged(true); - REQUIRE(poolOwner->poolManager.performHkOperation() == retval::CATCH_OK); + REQUIRE(poolOwner->poolManager.performHkOperation() == result::OK); REQUIRE(poolOwnerMock->wasMessageSent(&messagesSent) == true); CHECK(messagesSent == 2); /* first message sent should be the update notification, considering the internal list is a vector checked in insertion order. */ - REQUIRE(poolOwnerMock->receiveMessage(&messageSent) == retval::CATCH_OK); + REQUIRE(poolOwnerMock->receiveMessage(&messageSent) == result::OK); CHECK(messageSent.getCommand() == static_cast(HousekeepingMessage::UPDATE_NOTIFICATION_SET)); - REQUIRE(poolOwnerMock->receiveMessage(&messageSent) == retval::CATCH_OK); + REQUIRE(poolOwnerMock->receiveMessage(&messageSent) == result::OK); CHECK(messageSent.getCommand() == static_cast(HousekeepingMessage::HK_REPORT)); /* Clear message to avoid memory leak, our mock won't do it for us (yet) */ CommandMessageCleaner::clearCommandMessage(&messageSent); @@ -83,7 +83,7 @@ TEST_CASE("LocalPoolManagerTest", "[LocManTest]") { /* Set the variables in the set to certain values. These are checked later. */ { PoolReadGuard readHelper(&poolOwner->dataset); - REQUIRE(readHelper.getReadResult() == retval::CATCH_OK); + REQUIRE(readHelper.getReadResult() == result::OK); poolOwner->dataset.localPoolVarUint8.value = 5; poolOwner->dataset.localPoolVarFloat.value = -12.242; poolOwner->dataset.localPoolUint16Vec.value[0] = 2; @@ -92,7 +92,7 @@ TEST_CASE("LocalPoolManagerTest", "[LocManTest]") { } /* Subscribe for snapshot generation on update. */ - REQUIRE(poolOwner->subscribeWrapperSetUpdateSnapshot() == retval::CATCH_OK); + REQUIRE(poolOwner->subscribeWrapperSetUpdateSnapshot() == result::OK); poolOwner->dataset.setChanged(true); /* Store current time, we are going to check the (approximate) time equality later */ @@ -100,10 +100,10 @@ TEST_CASE("LocalPoolManagerTest", "[LocManTest]") { Clock::getClock_timeval(&now); /* Trigger generation of snapshot */ - REQUIRE(poolOwner->poolManager.performHkOperation() == retval::CATCH_OK); + REQUIRE(poolOwner->poolManager.performHkOperation() == result::OK); REQUIRE(poolOwnerMock->wasMessageSent(&messagesSent) == true); CHECK(messagesSent == 1); - REQUIRE(poolOwnerMock->receiveMessage(&messageSent) == retval::CATCH_OK); + REQUIRE(poolOwnerMock->receiveMessage(&messageSent) == result::OK); /* Check that snapshot was generated */ CHECK(messageSent.getCommand() == static_cast(HousekeepingMessage::UPDATE_SNAPSHOT_SET)); /* Now we deserialize the snapshot into a new dataset instance */ @@ -113,7 +113,7 @@ TEST_CASE("LocalPoolManagerTest", "[LocManTest]") { store_address_t storeId; HousekeepingMessage::getUpdateSnapshotSetCommand(&messageSent, &storeId); ConstAccessorPair accessorPair = tglob::getIpcStoreHandle()->getData(storeId); - REQUIRE(accessorPair.first == retval::CATCH_OK); + REQUIRE(accessorPair.first == result::OK); const uint8_t* readOnlyPtr = accessorPair.second.data(); size_t sizeToDeserialize = accessorPair.second.size(); CHECK(newSet.localPoolVarFloat.value == 0); @@ -123,7 +123,7 @@ TEST_CASE("LocalPoolManagerTest", "[LocManTest]") { CHECK(newSet.localPoolUint16Vec.value[2] == 0); /* Fill the dataset and timestamp */ REQUIRE(snapshot.deSerialize(&readOnlyPtr, &sizeToDeserialize, - SerializeIF::Endianness::MACHINE) == retval::CATCH_OK); + SerializeIF::Endianness::MACHINE) == result::OK); /* Now we check that the snapshot is actually correct */ CHECK(newSet.localPoolVarFloat.value == Catch::Approx(-12.242)); CHECK(newSet.localPoolVarUint8 == 5); @@ -145,14 +145,14 @@ TEST_CASE("LocalPoolManagerTest", "[LocManTest]") { REQUIRE(subscriptionIF != nullptr); /* Subscribe for variable snapshot */ - REQUIRE(poolOwner->subscribeWrapperVariableSnapshot(lpool::uint8VarId) == retval::CATCH_OK); + REQUIRE(poolOwner->subscribeWrapperVariableSnapshot(lpool::uint8VarId) == result::OK); auto poolVar = dynamic_cast*>(poolOwner->getPoolObjectHandle(lpool::uint8VarId)); REQUIRE(poolVar != nullptr); { PoolReadGuard rg(poolVar); - CHECK(rg.getReadResult() == retval::CATCH_OK); + CHECK(rg.getReadResult() == result::OK); poolVar->value = 25; } @@ -161,7 +161,7 @@ TEST_CASE("LocalPoolManagerTest", "[LocManTest]") { CCSDSTime::CDS_short timeCdsNow; timeval now; Clock::getClock_timeval(&now); - REQUIRE(poolOwner->poolManager.performHkOperation() == retval::CATCH_OK); + REQUIRE(poolOwner->poolManager.performHkOperation() == result::OK); /* Check update snapshot was sent. */ REQUIRE(poolOwnerMock->wasMessageSent(&messagesSent) == true); @@ -169,7 +169,7 @@ TEST_CASE("LocalPoolManagerTest", "[LocManTest]") { /* Should have been reset. */ CHECK(poolVar->hasChanged() == false); - REQUIRE(poolOwnerMock->receiveMessage(&messageSent) == retval::CATCH_OK); + REQUIRE(poolOwnerMock->receiveMessage(&messageSent) == result::OK); CHECK(messageSent.getCommand() == static_cast(HousekeepingMessage::UPDATE_SNAPSHOT_VARIABLE)); /* Now we deserialize the snapshot into a new dataset instance */ @@ -179,13 +179,13 @@ TEST_CASE("LocalPoolManagerTest", "[LocManTest]") { store_address_t storeId; HousekeepingMessage::getUpdateSnapshotVariableCommand(&messageSent, &storeId); ConstAccessorPair accessorPair = tglob::getIpcStoreHandle()->getData(storeId); - REQUIRE(accessorPair.first == retval::CATCH_OK); + REQUIRE(accessorPair.first == result::OK); const uint8_t* readOnlyPtr = accessorPair.second.data(); size_t sizeToDeserialize = accessorPair.second.size(); CHECK(varCopy.value == 0); /* Fill the dataset and timestamp */ REQUIRE(snapshot.deSerialize(&readOnlyPtr, &sizeToDeserialize, - SerializeIF::Endianness::MACHINE) == retval::CATCH_OK); + SerializeIF::Endianness::MACHINE) == result::OK); CHECK(varCopy.value == 25); /* Now we check that both times are equal */ @@ -202,30 +202,30 @@ TEST_CASE("LocalPoolManagerTest", "[LocManTest]") { REQUIRE(subscriptionIF != nullptr); /* Subscribe for variable update */ - REQUIRE(poolOwner->subscribeWrapperVariableUpdate(lpool::uint8VarId) == retval::CATCH_OK); + REQUIRE(poolOwner->subscribeWrapperVariableUpdate(lpool::uint8VarId) == result::OK); lp_var_t* poolVar = dynamic_cast*>(poolOwner->getPoolObjectHandle(lpool::uint8VarId)); REQUIRE(poolVar != nullptr); poolVar->setChanged(true); REQUIRE(poolVar->hasChanged() == true); - REQUIRE(poolOwner->poolManager.performHkOperation() == retval::CATCH_OK); + REQUIRE(poolOwner->poolManager.performHkOperation() == result::OK); /* Check update notification was sent. */ REQUIRE(poolOwnerMock->wasMessageSent(&messagesSent) == true); CHECK(messagesSent == 1); /* Should have been reset. */ CHECK(poolVar->hasChanged() == false); - REQUIRE(poolOwnerMock->receiveMessage(&messageSent) == retval::CATCH_OK); + REQUIRE(poolOwnerMock->receiveMessage(&messageSent) == result::OK); CHECK(messageSent.getCommand() == static_cast(HousekeepingMessage::UPDATE_NOTIFICATION_VARIABLE)); /* Now subscribe for the dataset update (HK and update) again with subscription interface */ REQUIRE(subscriptionIF->subscribeForSetUpdateMessage(lpool::testSetId, objects::NO_OBJECT, objects::HK_RECEIVER_MOCK, - false) == retval::CATCH_OK); - REQUIRE(poolOwner->subscribeWrapperSetUpdateHk() == retval::CATCH_OK); + false) == result::OK); + REQUIRE(poolOwner->subscribeWrapperSetUpdateHk() == result::OK); poolOwner->dataset.setChanged(true); - REQUIRE(poolOwner->poolManager.performHkOperation() == retval::CATCH_OK); + REQUIRE(poolOwner->poolManager.performHkOperation() == result::OK); /* Now two messages should be sent. */ REQUIRE(poolOwnerMock->wasMessageSent(&messagesSent) == true); CHECK(messagesSent == 2); @@ -233,17 +233,17 @@ TEST_CASE("LocalPoolManagerTest", "[LocManTest]") { poolOwner->dataset.setChanged(true); poolVar->setChanged(true); - REQUIRE(poolOwner->poolManager.performHkOperation() == retval::CATCH_OK); + REQUIRE(poolOwner->poolManager.performHkOperation() == result::OK); /* Now three messages should be sent. */ REQUIRE(poolOwnerMock->wasMessageSent(&messagesSent) == true); CHECK(messagesSent == 3); - REQUIRE(poolOwnerMock->receiveMessage(&messageSent) == retval::CATCH_OK); + REQUIRE(poolOwnerMock->receiveMessage(&messageSent) == result::OK); CHECK(messageSent.getCommand() == static_cast(HousekeepingMessage::UPDATE_NOTIFICATION_VARIABLE)); - REQUIRE(poolOwnerMock->receiveMessage(&messageSent) == retval::CATCH_OK); + REQUIRE(poolOwnerMock->receiveMessage(&messageSent) == result::OK); CHECK(messageSent.getCommand() == static_cast(HousekeepingMessage::UPDATE_NOTIFICATION_SET)); - REQUIRE(poolOwnerMock->receiveMessage(&messageSent) == retval::CATCH_OK); + REQUIRE(poolOwnerMock->receiveMessage(&messageSent) == result::OK); CHECK(messageSent.getCommand() == static_cast(HousekeepingMessage::HK_REPORT)); CommandMessageCleaner::clearCommandMessage(&messageSent); REQUIRE(poolOwnerMock->receiveMessage(&messageSent) == static_cast(MessageQueueIF::EMPTY)); @@ -254,70 +254,70 @@ TEST_CASE("LocalPoolManagerTest", "[LocManTest]") { the temporal behaviour correctly the HK manager should generate a HK packet immediately and the periodic helper depends on HK op function calls anyway instead of using the clock, so we could also just call performHkOperation multiple times */ - REQUIRE(poolOwner->subscribePeriodicHk(true) == retval::CATCH_OK); - REQUIRE(poolOwner->poolManager.performHkOperation() == retval::CATCH_OK); + REQUIRE(poolOwner->subscribePeriodicHk(true) == result::OK); + REQUIRE(poolOwner->poolManager.performHkOperation() == result::OK); /* Now HK packet should be sent as message immediately. */ REQUIRE(poolOwnerMock->wasMessageSent(&messagesSent) == true); CHECK(messagesSent == 1); - CHECK(poolOwnerMock->popMessage() == retval::CATCH_OK); + CHECK(poolOwnerMock->popMessage() == result::OK); LocalPoolDataSetBase* setHandle = poolOwner->getDataSetHandle(lpool::testSid); REQUIRE(setHandle != nullptr); CHECK(poolOwner->poolManager.generateHousekeepingPacket(lpool::testSid, setHandle, false) == - retval::CATCH_OK); + result::OK); REQUIRE(poolOwnerMock->wasMessageSent(&messagesSent) == true); CHECK(messagesSent == 1); - CHECK(poolOwnerMock->popMessage() == retval::CATCH_OK); + CHECK(poolOwnerMock->popMessage() == result::OK); CHECK(setHandle->getReportingEnabled() == true); CommandMessage hkCmd; HousekeepingMessage::setToggleReportingCommand(&hkCmd, lpool::testSid, false, false); - CHECK(poolOwner->poolManager.handleHousekeepingMessage(&hkCmd) == retval::CATCH_OK); + CHECK(poolOwner->poolManager.handleHousekeepingMessage(&hkCmd) == result::OK); CHECK(setHandle->getReportingEnabled() == false); REQUIRE(poolOwnerMock->wasMessageSent(&messagesSent) == true); CHECK(messagesSent == 1); - CHECK(poolOwnerMock->popMessage() == retval::CATCH_OK); + CHECK(poolOwnerMock->popMessage() == result::OK); HousekeepingMessage::setToggleReportingCommand(&hkCmd, lpool::testSid, true, false); - CHECK(poolOwner->poolManager.handleHousekeepingMessage(&hkCmd) == retval::CATCH_OK); + CHECK(poolOwner->poolManager.handleHousekeepingMessage(&hkCmd) == result::OK); CHECK(setHandle->getReportingEnabled() == true); REQUIRE(poolOwnerMock->wasMessageSent(&messagesSent) == true); - CHECK(poolOwnerMock->popMessage() == retval::CATCH_OK); + CHECK(poolOwnerMock->popMessage() == result::OK); HousekeepingMessage::setToggleReportingCommand(&hkCmd, lpool::testSid, false, false); - CHECK(poolOwner->poolManager.handleHousekeepingMessage(&hkCmd) == retval::CATCH_OK); + CHECK(poolOwner->poolManager.handleHousekeepingMessage(&hkCmd) == result::OK); CHECK(setHandle->getReportingEnabled() == false); REQUIRE(poolOwnerMock->wasMessageSent(&messagesSent) == true); - CHECK(poolOwnerMock->popMessage() == retval::CATCH_OK); + CHECK(poolOwnerMock->popMessage() == result::OK); HousekeepingMessage::setCollectionIntervalModificationCommand(&hkCmd, lpool::testSid, 0.4, false); - CHECK(poolOwner->poolManager.handleHousekeepingMessage(&hkCmd) == retval::CATCH_OK); + CHECK(poolOwner->poolManager.handleHousekeepingMessage(&hkCmd) == result::OK); /* For non-diagnostics and a specified minimum frequency of 0.2 seconds, the resulting collection interval should be 1.0 second */ CHECK(poolOwner->dataset.getCollectionInterval() == 1.0); REQUIRE(poolOwnerMock->wasMessageSent(&messagesSent) == true); CHECK(messagesSent == 1); - CHECK(poolOwnerMock->popMessage() == retval::CATCH_OK); + CHECK(poolOwnerMock->popMessage() == result::OK); HousekeepingMessage::setStructureReportingCommand(&hkCmd, lpool::testSid, false); - REQUIRE(poolOwner->poolManager.performHkOperation() == retval::CATCH_OK); - CHECK(poolOwner->poolManager.handleHousekeepingMessage(&hkCmd) == retval::CATCH_OK); + REQUIRE(poolOwner->poolManager.performHkOperation() == result::OK); + CHECK(poolOwner->poolManager.handleHousekeepingMessage(&hkCmd) == result::OK); /* Now HK packet should be sent as message. */ REQUIRE(poolOwnerMock->wasMessageSent(&messagesSent) == true); CHECK(messagesSent == 1); - CHECK(poolOwnerMock->popMessage() == retval::CATCH_OK); + CHECK(poolOwnerMock->popMessage() == result::OK); HousekeepingMessage::setOneShotReportCommand(&hkCmd, lpool::testSid, false); - CHECK(poolOwner->poolManager.handleHousekeepingMessage(&hkCmd) == retval::CATCH_OK); + CHECK(poolOwner->poolManager.handleHousekeepingMessage(&hkCmd) == result::OK); REQUIRE(poolOwnerMock->wasMessageSent(&messagesSent) == true); CHECK(messagesSent == 1); - CHECK(poolOwnerMock->popMessage() == retval::CATCH_OK); + CHECK(poolOwnerMock->popMessage() == result::OK); HousekeepingMessage::setUpdateNotificationSetCommand(&hkCmd, lpool::testSid); sid_t sidToCheck; store_address_t storeId; - CHECK(poolOwner->poolManager.handleHousekeepingMessage(&hkCmd) == retval::CATCH_OK); + CHECK(poolOwner->poolManager.handleHousekeepingMessage(&hkCmd) == result::OK); CHECK(poolOwner->changedDataSetCallbackWasCalled(sidToCheck, storeId) == true); CHECK(sidToCheck == lpool::testSid); @@ -330,7 +330,7 @@ TEST_CASE("LocalPoolManagerTest", "[LocManTest]") { /* We still expect a failure message being sent */ REQUIRE(poolOwnerMock->wasMessageSent(&messagesSent) == true); CHECK(messagesSent == 1); - CHECK(poolOwnerMock->popMessage() == retval::CATCH_OK); + CHECK(poolOwnerMock->popMessage() == result::OK); HousekeepingMessage::setCollectionIntervalModificationCommand(&hkCmd, lpool::testSid, 0.4, false); @@ -338,68 +338,68 @@ TEST_CASE("LocalPoolManagerTest", "[LocManTest]") { static_cast(LocalDataPoolManager::WRONG_HK_PACKET_TYPE)); REQUIRE(poolOwnerMock->wasMessageSent(&messagesSent) == true); CHECK(messagesSent == 1); - CHECK(poolOwnerMock->popMessage() == retval::CATCH_OK); + CHECK(poolOwnerMock->popMessage() == result::OK); HousekeepingMessage::setStructureReportingCommand(&hkCmd, lpool::testSid, false); CHECK(poolOwner->poolManager.handleHousekeepingMessage(&hkCmd) == static_cast(LocalDataPoolManager::WRONG_HK_PACKET_TYPE)); REQUIRE(poolOwnerMock->wasMessageSent(&messagesSent) == true); CHECK(messagesSent == 1); - CHECK(poolOwnerMock->popMessage() == retval::CATCH_OK); + CHECK(poolOwnerMock->popMessage() == result::OK); HousekeepingMessage::setStructureReportingCommand(&hkCmd, lpool::testSid, true); - CHECK(poolOwner->poolManager.handleHousekeepingMessage(&hkCmd) == retval::CATCH_OK); + CHECK(poolOwner->poolManager.handleHousekeepingMessage(&hkCmd) == result::OK); REQUIRE(poolOwnerMock->wasMessageSent(&messagesSent) == true); CHECK(messagesSent == 1); - CHECK(poolOwnerMock->popMessage() == retval::CATCH_OK); + CHECK(poolOwnerMock->popMessage() == result::OK); HousekeepingMessage::setCollectionIntervalModificationCommand(&hkCmd, lpool::testSid, 0.4, true); - CHECK(poolOwner->poolManager.handleHousekeepingMessage(&hkCmd) == retval::CATCH_OK); + CHECK(poolOwner->poolManager.handleHousekeepingMessage(&hkCmd) == result::OK); REQUIRE(poolOwnerMock->wasMessageSent(&messagesSent) == true); CHECK(messagesSent == 1); - CHECK(poolOwnerMock->popMessage() == retval::CATCH_OK); + CHECK(poolOwnerMock->popMessage() == result::OK); HousekeepingMessage::setToggleReportingCommand(&hkCmd, lpool::testSid, true, true); - CHECK(poolOwner->poolManager.handleHousekeepingMessage(&hkCmd) == retval::CATCH_OK); + CHECK(poolOwner->poolManager.handleHousekeepingMessage(&hkCmd) == result::OK); REQUIRE(poolOwnerMock->wasMessageSent(&messagesSent) == true); CHECK(messagesSent == 1); - CHECK(poolOwnerMock->popMessage() == retval::CATCH_OK); + CHECK(poolOwnerMock->popMessage() == result::OK); HousekeepingMessage::setToggleReportingCommand(&hkCmd, lpool::testSid, false, true); - CHECK(poolOwner->poolManager.handleHousekeepingMessage(&hkCmd) == retval::CATCH_OK); + CHECK(poolOwner->poolManager.handleHousekeepingMessage(&hkCmd) == result::OK); REQUIRE(poolOwnerMock->wasMessageSent(&messagesSent) == true); CHECK(messagesSent == 1); - CHECK(poolOwnerMock->popMessage() == retval::CATCH_OK); + CHECK(poolOwnerMock->popMessage() == result::OK); HousekeepingMessage::setOneShotReportCommand(&hkCmd, lpool::testSid, false); CHECK(poolOwner->poolManager.handleHousekeepingMessage(&hkCmd) == static_cast(LocalDataPoolManager::WRONG_HK_PACKET_TYPE)); REQUIRE(poolOwnerMock->wasMessageSent(&messagesSent) == true); CHECK(messagesSent == 1); - CHECK(poolOwnerMock->popMessage() == retval::CATCH_OK); + CHECK(poolOwnerMock->popMessage() == result::OK); HousekeepingMessage::setOneShotReportCommand(&hkCmd, lpool::testSid, true); - CHECK(poolOwner->poolManager.handleHousekeepingMessage(&hkCmd) == retval::CATCH_OK); + CHECK(poolOwner->poolManager.handleHousekeepingMessage(&hkCmd) == result::OK); REQUIRE(poolOwnerMock->wasMessageSent(&messagesSent) == true); CHECK(messagesSent == 1); - CHECK(poolOwnerMock->popMessage() == retval::CATCH_OK); + CHECK(poolOwnerMock->popMessage() == result::OK); HousekeepingMessage::setUpdateNotificationVariableCommand(&hkCmd, lpool::uint8VarGpid); gp_id_t gpidToCheck; - CHECK(poolOwner->poolManager.handleHousekeepingMessage(&hkCmd) == retval::CATCH_OK); + CHECK(poolOwner->poolManager.handleHousekeepingMessage(&hkCmd) == result::OK); CHECK(poolOwner->changedVariableCallbackWasCalled(gpidToCheck, storeId) == true); CHECK(gpidToCheck == lpool::uint8VarGpid); HousekeepingMessage::setUpdateSnapshotSetCommand(&hkCmd, lpool::testSid, storeId::INVALID_STORE_ADDRESS); - CHECK(poolOwner->poolManager.handleHousekeepingMessage(&hkCmd) == retval::CATCH_OK); + CHECK(poolOwner->poolManager.handleHousekeepingMessage(&hkCmd) == result::OK); CHECK(poolOwner->changedDataSetCallbackWasCalled(sidToCheck, storeId) == true); CHECK(sidToCheck == lpool::testSid); HousekeepingMessage::setUpdateSnapshotVariableCommand(&hkCmd, lpool::uint8VarGpid, storeId::INVALID_STORE_ADDRESS); - CHECK(poolOwner->poolManager.handleHousekeepingMessage(&hkCmd) == retval::CATCH_OK); + CHECK(poolOwner->poolManager.handleHousekeepingMessage(&hkCmd) == result::OK); CHECK(poolOwner->changedVariableCallbackWasCalled(gpidToCheck, storeId) == true); CHECK(gpidToCheck == lpool::uint8VarGpid); @@ -408,6 +408,6 @@ TEST_CASE("LocalPoolManagerTest", "[LocManTest]") { /* we need to reset the subscription list because the pool owner is a global object. */ - CHECK(poolOwner->reset() == retval::CATCH_OK); + CHECK(poolOwner->reset() == result::OK); poolOwnerMock->clearMessages(true); } diff --git a/unittests/datapoollocal/LocalPoolVariableTest.cpp b/unittests/datapoollocal/LocalPoolVariableTest.cpp index 3479cdbe..e9bed9ed 100644 --- a/unittests/datapoollocal/LocalPoolVariableTest.cpp +++ b/unittests/datapoollocal/LocalPoolVariableTest.cpp @@ -11,23 +11,23 @@ TEST_CASE("LocalPoolVariable", "[LocPoolVarTest]") { auto* poolOwner = ObjectManager::instance()->get(objects::TEST_LOCAL_POOL_OWNER_BASE); REQUIRE(poolOwner != nullptr); - REQUIRE(poolOwner->initializeHkManager() == retval::CATCH_OK); - REQUIRE(poolOwner->initializeHkManagerAfterTaskCreation() == retval::CATCH_OK); + REQUIRE(poolOwner->initializeHkManager() == result::OK); + REQUIRE(poolOwner->initializeHkManagerAfterTaskCreation() == result::OK); SECTION("Basic Tests") { /* very basic test. */ lp_var_t testVariable = lp_var_t(objects::TEST_LOCAL_POOL_OWNER_BASE, lpool::uint8VarId); - REQUIRE(testVariable.read() == retval::CATCH_OK); + REQUIRE(testVariable.read() == result::OK); CHECK(testVariable.value == 0); testVariable.value = 5; - REQUIRE(testVariable.commit() == retval::CATCH_OK); - REQUIRE(testVariable.read() == retval::CATCH_OK); + REQUIRE(testVariable.commit() == result::OK); + REQUIRE(testVariable.read() == result::OK); REQUIRE(testVariable.value == 5); CHECK(not testVariable.isValid()); testVariable.setValid(true); CHECK(testVariable.isValid()); - CHECK(testVariable.commit(true) == retval::CATCH_OK); + CHECK(testVariable.commit(true) == result::OK); testVariable.setReadWriteMode(pool_rwm_t::VAR_READ); CHECK(testVariable.getReadWriteMode() == pool_rwm_t::VAR_READ); @@ -43,7 +43,7 @@ TEST_CASE("LocalPoolVariable", "[LocPoolVarTest]") { gp_id_t globPoolId(objects::TEST_LOCAL_POOL_OWNER_BASE, lpool::uint8VarId); lp_var_t testVariable2 = lp_var_t(globPoolId); - REQUIRE(testVariable2.read() == retval::CATCH_OK); + REQUIRE(testVariable2.read() == result::OK); CHECK(testVariable2 == 5); CHECK(testVariable == testVariable2); testVariable = 10; @@ -55,12 +55,12 @@ TEST_CASE("LocalPoolVariable", "[LocPoolVarTest]") { CHECK(maxSize == 1); size_t serSize = 0; CHECK(testVariable.serialize(&varPtr, &serSize, maxSize, SerializeIF::Endianness::MACHINE) == - retval::CATCH_OK); + result::OK); CHECK(variableRaw == 10); const uint8_t* varConstPtr = &variableRaw; testVariable = 5; CHECK(testVariable.deSerialize(&varConstPtr, &serSize, SerializeIF::Endianness::MACHINE) == - retval::CATCH_OK); + result::OK); CHECK(testVariable == 10); CHECK(testVariable != testVariable2); CHECK(testVariable2 < testVariable); @@ -107,5 +107,5 @@ TEST_CASE("LocalPoolVariable", "[LocPoolVarTest]") { lp_var_t invalidObjectVar3 = lp_var_t(nullptr, lpool::uint8VarId); } - CHECK(poolOwner->reset() == retval::CATCH_OK); + CHECK(poolOwner->reset() == result::OK); } diff --git a/unittests/datapoollocal/LocalPoolVectorTest.cpp b/unittests/datapoollocal/LocalPoolVectorTest.cpp index 2235ad39..ddf6da9b 100644 --- a/unittests/datapoollocal/LocalPoolVectorTest.cpp +++ b/unittests/datapoollocal/LocalPoolVectorTest.cpp @@ -11,26 +11,26 @@ TEST_CASE("LocalPoolVector", "[LocPoolVecTest]") { LocalPoolOwnerBase* poolOwner = ObjectManager::instance()->get(objects::TEST_LOCAL_POOL_OWNER_BASE); REQUIRE(poolOwner != nullptr); - REQUIRE(poolOwner->initializeHkManager() == retval::CATCH_OK); - REQUIRE(poolOwner->initializeHkManagerAfterTaskCreation() == retval::CATCH_OK); + REQUIRE(poolOwner->initializeHkManager() == result::OK); + REQUIRE(poolOwner->initializeHkManagerAfterTaskCreation() == result::OK); SECTION("BasicTest") { // very basic test. lp_vec_t testVector = lp_vec_t(objects::TEST_LOCAL_POOL_OWNER_BASE, lpool::uint16Vec3Id); - REQUIRE(testVector.read() == retval::CATCH_OK); + REQUIRE(testVector.read() == result::OK); testVector.value[0] = 5; testVector.value[1] = 232; testVector.value[2] = 32023; - REQUIRE(testVector.commit(true) == retval::CATCH_OK); + REQUIRE(testVector.commit(true) == result::OK); CHECK(testVector.isValid()); testVector.value[0] = 0; testVector.value[1] = 0; testVector.value[2] = 0; - CHECK(testVector.read() == retval::CATCH_OK); + CHECK(testVector.read() == result::OK); CHECK(testVector.value[0] == 5); CHECK(testVector.value[1] == 232); CHECK(testVector.value[2] == 32023); @@ -41,7 +41,7 @@ TEST_CASE("LocalPoolVector", "[LocPoolVecTest]") { (we can't throw exceptions) */ testVector[4] = 12; CHECK(testVector[2] == 12); - CHECK(testVector.commit() == retval::CATCH_OK); + CHECK(testVector.commit() == result::OK); /* Use read-only reference. */ const lp_vec_t& roTestVec = testVector; @@ -58,7 +58,7 @@ TEST_CASE("LocalPoolVector", "[LocPoolVecTest]") { uint8_t* vecPtr = reinterpret_cast(serializedVector); size_t serSize = 0; REQUIRE(testVector.serialize(&vecPtr, &serSize, maxSize, SerializeIF::Endianness::MACHINE) == - retval::CATCH_OK); + result::OK); CHECK(serSize == 6); CHECK(serializedVector[0] == 5); @@ -75,7 +75,7 @@ TEST_CASE("LocalPoolVector", "[LocPoolVecTest]") { const uint8_t* constVecPtr = reinterpret_cast(serializedVector); REQUIRE(testVector.deSerialize(&constVecPtr, &serSize, SerializeIF::Endianness::MACHINE) == - retval::CATCH_OK); + result::OK); CHECK(testVector[0] == 16); CHECK(testVector[1] == 7832); CHECK(testVector[2] == 39232); diff --git a/unittests/globalfunctions/testDleEncoder.cpp b/unittests/globalfunctions/testDleEncoder.cpp index 0c707f4c..fc4d79bf 100644 --- a/unittests/globalfunctions/testDleEncoder.cpp +++ b/unittests/globalfunctions/testDleEncoder.cpp @@ -60,7 +60,7 @@ TEST_CASE("DleEncoder", "[DleEncoder]") { const std::vector& expectedVec) { result = encoder.encode(vecToEncode.data(), vecToEncode.size(), buffer.data(), buffer.size(), &encodedLen); - REQUIRE(result == retval::CATCH_OK); + REQUIRE(result == result::OK); for (size_t idx = 0; idx < expectedVec.size(); idx++) { REQUIRE(buffer[idx] == expectedVec[idx]); } @@ -71,7 +71,7 @@ TEST_CASE("DleEncoder", "[DleEncoder]") { const std::vector& expectedVec) { result = encoder.decode(testVecEncoded.data(), testVecEncoded.size(), &readLen, buffer.data(), buffer.size(), &decodedLen); - REQUIRE(result == retval::CATCH_OK); + REQUIRE(result == result::OK); REQUIRE(readLen == testVecEncoded.size()); REQUIRE(decodedLen == expectedVec.size()); for (size_t idx = 0; idx < decodedLen; idx++) { diff --git a/unittests/internalerror/TestInternalErrorReporter.cpp b/unittests/internalerror/TestInternalErrorReporter.cpp index 2b999fae..b61a6203 100644 --- a/unittests/internalerror/TestInternalErrorReporter.cpp +++ b/unittests/internalerror/TestInternalErrorReporter.cpp @@ -38,7 +38,7 @@ TEST_CASE("Internal Error Reporter", "[TestInternalError]") { CommandMessage message; ActionMessage::setCompletionReply(&message, 10, true); auto result = hkQueue->sendMessage(testQueue->getId(), &message); - REQUIRE(result == retval::CATCH_OK); + REQUIRE(result == result::OK); uint32_t queueHits = 0; uint32_t lostTm = 0; uint32_t storeHits = 0; diff --git a/unittests/osal/TestMessageQueue.cpp b/unittests/osal/TestMessageQueue.cpp index df15b33d..b1792a9c 100644 --- a/unittests/osal/TestMessageQueue.cpp +++ b/unittests/osal/TestMessageQueue.cpp @@ -19,17 +19,17 @@ TEST_CASE("MessageQueue Basic Test", "[TestMq]") { SECTION("Simple Tests") { auto result = testSenderMq->sendMessage(testReceiverMqId, &testMessage); - REQUIRE(result == retval::CATCH_OK); + REQUIRE(result == result::OK); MessageQueueMessage recvMessage; result = testReceiverMq->receiveMessage(&recvMessage); - REQUIRE(result == retval::CATCH_OK); + REQUIRE(result == result::OK); CHECK(recvMessage.getData()[0] == 42); result = testSenderMq->sendMessage(testReceiverMqId, &testMessage); - REQUIRE(result == retval::CATCH_OK); + REQUIRE(result == result::OK); MessageQueueId_t senderId = 0; result = testReceiverMq->receiveMessage(&recvMessage, &senderId); - REQUIRE(result == retval::CATCH_OK); + REQUIRE(result == result::OK); CHECK(recvMessage.getData()[0] == 42); CHECK(senderId == testSenderMqId); senderId = testReceiverMq->getLastPartner(); @@ -37,7 +37,7 @@ TEST_CASE("MessageQueue Basic Test", "[TestMq]") { } SECTION("Test Full") { auto result = testSenderMq->sendMessage(testReceiverMqId, &testMessage); - REQUIRE(result == retval::CATCH_OK); + REQUIRE(result == result::OK); result = testSenderMq->sendMessage(testReceiverMqId, &testMessage); REQUIRE(result == MessageQueueIF::FULL); // We try another message @@ -45,12 +45,12 @@ TEST_CASE("MessageQueue Basic Test", "[TestMq]") { REQUIRE(result == MessageQueueIF::FULL); MessageQueueMessage recvMessage; result = testReceiverMq->receiveMessage(&recvMessage); - REQUIRE(result == retval::CATCH_OK); + REQUIRE(result == result::OK); CHECK(recvMessage.getData()[0] == 42); result = testSenderMq->sendMessage(testReceiverMqId, &testMessage); - REQUIRE(result == retval::CATCH_OK); + REQUIRE(result == result::OK); result = testReceiverMq->receiveMessage(&recvMessage); - REQUIRE(result == retval::CATCH_OK); + REQUIRE(result == result::OK); CHECK(recvMessage.getData()[0] == 42); } // We have to clear MQs ourself ATM diff --git a/unittests/osal/TestSemaphore.cpp b/unittests/osal/TestSemaphore.cpp index 6988af5b..376b08db 100644 --- a/unittests/osal/TestSemaphore.cpp +++ b/unittests/osal/TestSemaphore.cpp @@ -19,7 +19,7 @@ TEST_CASE("Binary Semaphore Test" , "[BinSemaphore]") { REQUIRE(binSemaph->release() == static_cast(SemaphoreIF::SEMAPHORE_NOT_OWNED)); REQUIRE(binSemaph->acquire(SemaphoreIF::POLLING) == - retval::CATCH_OK); + result::OK); { // not precise enough on linux.. should use clock instead.. //Stopwatch stopwatch(false); @@ -29,7 +29,7 @@ TEST_CASE("Binary Semaphore Test" , "[BinSemaphore]") { //CHECK(time == 5); } REQUIRE(binSemaph->getSemaphoreCounter() == 0); - REQUIRE(binSemaph->release() == retval::CATCH_OK); + REQUIRE(binSemaph->release() == result::OK); } SemaphoreFactory::instance()->deleteSemaphore(binSemaph); // perform tear-down here diff --git a/unittests/serialize/TestSerialBufferAdapter.cpp b/unittests/serialize/TestSerialBufferAdapter.cpp index 2aa76ec8..2a8fe68c 100644 --- a/unittests/serialize/TestSerialBufferAdapter.cpp +++ b/unittests/serialize/TestSerialBufferAdapter.cpp @@ -102,7 +102,7 @@ TEST_CASE("Serial Buffer Adapter", "[single-file]") { size_t size = 6; auto result = tv_serial_buffer_adapter3.deSerialize(const_cast(&arrayPtr), &size, SerializeIF::Endianness::MACHINE); - REQUIRE(result == retval::CATCH_OK); + REQUIRE(result == result::OK); CHECK(test_recv_array[0] == 1); CHECK(test_recv_array[1] == 1); CHECK(test_recv_array[2] == 1); diff --git a/unittests/serialize/TestSerialLinkedPacket.cpp b/unittests/serialize/TestSerialLinkedPacket.cpp index 2d6e476f..863c77a9 100644 --- a/unittests/serialize/TestSerialLinkedPacket.cpp +++ b/unittests/serialize/TestSerialLinkedPacket.cpp @@ -41,7 +41,7 @@ TEST_CASE("Serial Linked Packet", "[SerLinkPacket]") { // Deserialize big endian packet by setting bigEndian to true. ReturnValue_t result = testClass.deSerialize(&readOnlyPointer, &packetLen, SerializeIF::Endianness::BIG); - REQUIRE(result == retval::CATCH_OK); + REQUIRE(result == result::OK); CHECK(testClass.getHeader() == 42); // Equivalent check. // CHECK(testClass.getBuffer()[0] == 1); @@ -60,7 +60,7 @@ TEST_CASE("Serial Linked Packet", "[SerLinkPacket]") { // serialize for ground: bigEndian = true. ReturnValue_t result = testClass.serialize(&packetPointer, &serializedSize, packetMaxSize, SerializeIF::Endianness::BIG); - REQUIRE(result == retval::CATCH_OK); + REQUIRE(result == result::OK); // Result should be big endian now. CHECK(packet[3] == 42); CHECK(packet[4] == 1); diff --git a/unittests/storagemanager/TestNewAccessor.cpp b/unittests/storagemanager/TestNewAccessor.cpp index 2cc2e469..311ba44d 100644 --- a/unittests/storagemanager/TestNewAccessor.cpp +++ b/unittests/storagemanager/TestNewAccessor.cpp @@ -12,7 +12,7 @@ TEST_CASE("New Accessor", "[NewAccessor]") { std::array testDataArray; std::array receptionArray; store_address_t testStoreId; - ReturnValue_t result = retval::CATCH_FAILED; + ReturnValue_t result = result::FAILED; for (size_t i = 0; i < testDataArray.size(); i++) { testDataArray[i] = i; @@ -21,9 +21,9 @@ TEST_CASE("New Accessor", "[NewAccessor]") { SECTION("Simple tests getter functions") { result = SimplePool.addData(&testStoreId, testDataArray.data(), size); - REQUIRE(result == retval::CATCH_OK); + REQUIRE(result == result::OK); auto resultPair = SimplePool.getData(testStoreId); - REQUIRE(resultPair.first == retval::CATCH_OK); + REQUIRE(resultPair.first == result::OK); resultPair.second.getDataCopy(receptionArray.data(), 20); CHECK(resultPair.second.getId() == testStoreId); CHECK(resultPair.second.size() == 10); @@ -39,18 +39,18 @@ TEST_CASE("New Accessor", "[NewAccessor]") { { auto resultPairLoc = SimplePool.getData(testStoreId); - REQUIRE(resultPairLoc.first == retval::CATCH_OK); + REQUIRE(resultPairLoc.first == result::OK); // data should be deleted when accessor goes out of scope. } resultPair = SimplePool.getData(testStoreId); REQUIRE(resultPair.first == (int)StorageManagerIF::DATA_DOES_NOT_EXIST); result = SimplePool.addData(&testStoreId, testDataArray.data(), size); - REQUIRE(result == retval::CATCH_OK); + REQUIRE(result == result::OK); { ConstStorageAccessor constAccessor(testStoreId); result = SimplePool.getData(testStoreId, constAccessor); - REQUIRE(result == retval::CATCH_OK); + REQUIRE(result == result::OK); constAccessor.getDataCopy(receptionArray.data(), 20); for (size_t i = 0; i < size; i++) { CHECK(receptionArray[i] == i); @@ -63,12 +63,12 @@ TEST_CASE("New Accessor", "[NewAccessor]") { result = SimplePool.addData(&testStoreId, testDataArray.data(), size); { resultPair = SimplePool.getData(testStoreId); - REQUIRE(resultPair.first == retval::CATCH_OK); + REQUIRE(resultPair.first == result::OK); resultPair.second.release(); // now data should not be deleted anymore } resultPair = SimplePool.getData(testStoreId); - REQUIRE(resultPair.first == retval::CATCH_OK); + REQUIRE(resultPair.first == result::OK); resultPair.second.getDataCopy(receptionArray.data(), 20); for (size_t i = 0; i < size; i++) { CHECK(receptionArray[i] == i); @@ -77,11 +77,11 @@ TEST_CASE("New Accessor", "[NewAccessor]") { SECTION("Simple tests modify functions") { result = SimplePool.addData(&testStoreId, testDataArray.data(), size); - REQUIRE(result == retval::CATCH_OK); + REQUIRE(result == result::OK); { StorageAccessor accessor(testStoreId); result = SimplePool.modifyData(testStoreId, accessor); - REQUIRE(result == retval::CATCH_OK); + REQUIRE(result == result::OK); CHECK(accessor.getId() == testStoreId); CHECK(accessor.size() == 10); accessor.getDataCopy(receptionArray.data(), 20); @@ -98,10 +98,10 @@ TEST_CASE("New Accessor", "[NewAccessor]") { REQUIRE(resultPair.first == (int)StorageManagerIF::DATA_DOES_NOT_EXIST); result = SimplePool.addData(&testStoreId, testDataArray.data(), size); - REQUIRE(result == retval::CATCH_OK); + REQUIRE(result == result::OK); { auto resultPairLoc = SimplePool.modifyData(testStoreId); - REQUIRE(resultPairLoc.first == retval::CATCH_OK); + REQUIRE(resultPairLoc.first == result::OK); CHECK(resultPairLoc.second.getId() == testStoreId); CHECK(resultPairLoc.second.size() == 10); resultPairLoc.second.getDataCopy(receptionArray.data(), 20); @@ -117,22 +117,22 @@ TEST_CASE("New Accessor", "[NewAccessor]") { // data should not be deleted when accessor goes out of scope } resultPair = SimplePool.getData(testStoreId); - REQUIRE(resultPair.first == retval::CATCH_OK); + REQUIRE(resultPair.first == result::OK); } SECTION("Write tests") { result = SimplePool.addData(&testStoreId, testDataArray.data(), size); - REQUIRE(result == retval::CATCH_OK); + REQUIRE(result == result::OK); { auto resultPair = SimplePool.modifyData(testStoreId); - REQUIRE(resultPair.first == retval::CATCH_OK); + REQUIRE(resultPair.first == result::OK); testDataArray[9] = 42; resultPair.second.write(testDataArray.data(), 10, 0); // now data should not be deleted resultPair.second.release(); } auto resultConstPair = SimplePool.getData(testStoreId); - REQUIRE(resultConstPair.first == retval::CATCH_OK); + REQUIRE(resultConstPair.first == result::OK); resultConstPair.second.getDataCopy(receptionArray.data(), 10); for (size_t i = 0; i < size - 1; i++) { @@ -141,15 +141,15 @@ TEST_CASE("New Accessor", "[NewAccessor]") { CHECK(receptionArray[9] == 42); auto resultPair = SimplePool.modifyData(testStoreId); - REQUIRE(resultPair.first == retval::CATCH_OK); + REQUIRE(resultPair.first == result::OK); result = resultPair.second.write(testDataArray.data(), 20, 0); - REQUIRE(result == retval::CATCH_FAILED); + REQUIRE(result == result::FAILED); result = resultPair.second.write(testDataArray.data(), 10, 5); - REQUIRE(result == retval::CATCH_FAILED); + REQUIRE(result == result::FAILED); std::memset(testDataArray.data(), 42, 5); result = resultPair.second.write(testDataArray.data(), 5, 5); - REQUIRE(result == retval::CATCH_OK); + REQUIRE(result == result::OK); resultConstPair = SimplePool.getData(testStoreId); resultPair.second.getDataCopy(receptionArray.data(), 20); for (size_t i = 5; i < 10; i++) { @@ -159,7 +159,7 @@ TEST_CASE("New Accessor", "[NewAccessor]") { SECTION("Operators") { result = SimplePool.addData(&testStoreId, testDataArray.data(), size); - REQUIRE(result == retval::CATCH_OK); + REQUIRE(result == result::OK); { StorageAccessor accessor(testStoreId); StorageAccessor accessor2(0); diff --git a/unittests/storagemanager/TestPool.cpp b/unittests/storagemanager/TestPool.cpp index e37c6934..f3c4f330 100644 --- a/unittests/storagemanager/TestPool.cpp +++ b/unittests/storagemanager/TestPool.cpp @@ -13,7 +13,7 @@ TEST_CASE("Local Pool Simple Tests [1 Pool]", "[TestPool]") { std::array testDataArray; std::array receptionArray; store_address_t testStoreId; - ReturnValue_t result = retval::CATCH_FAILED; + ReturnValue_t result = result::FAILED; uint8_t* pointer = nullptr; const uint8_t* constPointer = nullptr; @@ -24,9 +24,9 @@ TEST_CASE("Local Pool Simple Tests [1 Pool]", "[TestPool]") { SECTION("Basic tests") { result = simplePool.addData(&testStoreId, testDataArray.data(), size); - REQUIRE(result == retval::CATCH_OK); + REQUIRE(result == result::OK); result = simplePool.getData(testStoreId, &constPointer, &size); - REQUIRE(result == retval::CATCH_OK); + REQUIRE(result == result::OK); memcpy(receptionArray.data(), constPointer, size); for (size_t i = 0; i < size; i++) { CHECK(receptionArray[i] == i); @@ -34,12 +34,12 @@ TEST_CASE("Local Pool Simple Tests [1 Pool]", "[TestPool]") { memset(receptionArray.data(), 0, size); result = simplePool.modifyData(testStoreId, &pointer, &size); memcpy(receptionArray.data(), pointer, size); - REQUIRE(result == retval::CATCH_OK); + REQUIRE(result == result::OK); for (size_t i = 0; i < size; i++) { CHECK(receptionArray[i] == i); } result = simplePool.deleteData(testStoreId); - REQUIRE(result == retval::CATCH_OK); + REQUIRE(result == result::OK); result = simplePool.addData(&testStoreId, testDataArray.data(), 15); CHECK(result == (int)StorageManagerIF::DATA_TOO_LARGE); } @@ -47,12 +47,12 @@ TEST_CASE("Local Pool Simple Tests [1 Pool]", "[TestPool]") { SECTION("Reservation Tests ") { pointer = nullptr; result = simplePool.getFreeElement(&testStoreId, size, &pointer); - REQUIRE(result == retval::CATCH_OK); + REQUIRE(result == result::OK); memcpy(pointer, testDataArray.data(), size); constPointer = nullptr; result = simplePool.getData(testStoreId, &constPointer, &size); - REQUIRE(result == retval::CATCH_OK); + REQUIRE(result == result::OK); memcpy(receptionArray.data(), constPointer, size); for (size_t i = 0; i < size; i++) { CHECK(receptionArray[i] == i); @@ -61,21 +61,21 @@ TEST_CASE("Local Pool Simple Tests [1 Pool]", "[TestPool]") { SECTION("Add, delete, add, add when full") { result = simplePool.addData(&testStoreId, testDataArray.data(), size); - REQUIRE(result == retval::CATCH_OK); + REQUIRE(result == result::OK); result = simplePool.getData(testStoreId, &constPointer, &size); - REQUIRE(result == retval::CATCH_OK); + REQUIRE(result == result::OK); memcpy(receptionArray.data(), constPointer, size); for (size_t i = 0; i < size; i++) { CHECK(receptionArray[i] == i); } result = simplePool.deleteData(testStoreId); - REQUIRE(result == retval::CATCH_OK); + REQUIRE(result == result::OK); result = simplePool.addData(&testStoreId, testDataArray.data(), size); - REQUIRE(result == retval::CATCH_OK); + REQUIRE(result == result::OK); result = simplePool.getData(testStoreId, &constPointer, &size); - REQUIRE(result == retval::CATCH_OK); + REQUIRE(result == result::OK); memcpy(receptionArray.data(), constPointer, size); for (size_t i = 0; i < size; i++) { CHECK(receptionArray[i] == i); @@ -102,20 +102,20 @@ TEST_CASE("Local Pool Simple Tests [1 Pool]", "[TestPool]") { SECTION("Initialize and clear store, delete with pointer") { result = simplePool.initialize(); - REQUIRE(result == retval::CATCH_OK); + REQUIRE(result == result::OK); result = simplePool.addData(&testStoreId, testDataArray.data(), size); - REQUIRE(result == retval::CATCH_OK); + REQUIRE(result == result::OK); simplePool.clearStore(); result = simplePool.addData(&testStoreId, testDataArray.data(), size); - REQUIRE(result == retval::CATCH_OK); + REQUIRE(result == result::OK); result = simplePool.modifyData(testStoreId, &pointer, &size); - REQUIRE(result == retval::CATCH_OK); + REQUIRE(result == result::OK); store_address_t newId; result = simplePool.deleteData(pointer, size, &testStoreId); - REQUIRE(result == retval::CATCH_OK); + REQUIRE(result == result::OK); REQUIRE(testStoreId.raw != (uint32_t)StorageManagerIF::INVALID_ADDRESS); result = simplePool.addData(&testStoreId, testDataArray.data(), size); - REQUIRE(result == retval::CATCH_OK); + REQUIRE(result == result::OK); } } @@ -141,7 +141,7 @@ TEST_CASE("Local Pool Extended Tests [3 Pools]", "[TestPool2]") { std::array testDataArray; std::array receptionArray; store_address_t testStoreId; - ReturnValue_t result = retval::CATCH_FAILED; + ReturnValue_t result = result::FAILED; for (size_t i = 0; i < testDataArray.size(); i++) { testDataArray[i] = i; } @@ -150,20 +150,20 @@ TEST_CASE("Local Pool Extended Tests [3 Pools]", "[TestPool2]") { SECTION("Basic tests") { size = 8; result = simplePool.addData(&testStoreId, testDataArray.data(), size); - REQUIRE(result == retval::CATCH_OK); + REQUIRE(result == result::OK); // Should be on second page of the pool now for 8 bytes CHECK(testStoreId.poolIndex == 1); CHECK(testStoreId.packetIndex == 0); size = 15; result = simplePool.addData(&testStoreId, testDataArray.data(), size); - REQUIRE(result == retval::CATCH_OK); + REQUIRE(result == result::OK); // Should be on third page of the pool now for 15 bytes CHECK(testStoreId.poolIndex == 2); CHECK(testStoreId.packetIndex == 0); result = simplePool.addData(&testStoreId, testDataArray.data(), size); - REQUIRE(result == retval::CATCH_OK); + REQUIRE(result == result::OK); // Should be on third page of the pool now for 15 bytes CHECK(testStoreId.poolIndex == 2); CHECK(testStoreId.packetIndex == 1); @@ -174,7 +174,7 @@ TEST_CASE("Local Pool Extended Tests [3 Pools]", "[TestPool2]") { size = 8; result = simplePool.addData(&testStoreId, testDataArray.data(), size); - REQUIRE(result == retval::CATCH_OK); + REQUIRE(result == result::OK); // Should still work CHECK(testStoreId.poolIndex == 1); CHECK(testStoreId.packetIndex == 1); @@ -182,7 +182,7 @@ TEST_CASE("Local Pool Extended Tests [3 Pools]", "[TestPool2]") { // fill the rest of the pool for (uint8_t idx = 2; idx < 5; idx++) { result = simplePool.addData(&testStoreId, testDataArray.data(), size); - REQUIRE(result == retval::CATCH_OK); + REQUIRE(result == result::OK); CHECK(testStoreId.poolIndex == 1); CHECK(testStoreId.packetIndex == idx); } @@ -203,21 +203,21 @@ TEST_CASE("Local Pool Extended Tests [3 Pools]", "[TestPool2]") { size = 5; for (uint8_t idx = 0; idx < 10; idx++) { result = simplePool.addData(&testStoreId, testDataArray.data(), size); - REQUIRE(result == retval::CATCH_OK); + REQUIRE(result == result::OK); CHECK(testStoreId.poolIndex == 0); CHECK(testStoreId.packetIndex == idx); } size = 10; for (uint8_t idx = 0; idx < 5; idx++) { result = simplePool.addData(&testStoreId, testDataArray.data(), size); - REQUIRE(result == retval::CATCH_OK); + REQUIRE(result == result::OK); CHECK(testStoreId.poolIndex == 1); CHECK(testStoreId.packetIndex == idx); } size = 20; for (uint8_t idx = 0; idx < 2; idx++) { result = simplePool.addData(&testStoreId, testDataArray.data(), size); - REQUIRE(result == retval::CATCH_OK); + REQUIRE(result == result::OK); CHECK(testStoreId.poolIndex == 2); CHECK(testStoreId.packetIndex == idx); } @@ -244,7 +244,7 @@ TEST_CASE("Local Pool Extended Tests [3 Pools]", "[TestPool2]") { size = 5; for (uint8_t idx = 0; idx < 10; idx++) { result = simplePool.addData(&testStoreId, testDataArray.data(), size); - REQUIRE(result == retval::CATCH_OK); + REQUIRE(result == result::OK); CHECK(testStoreId.poolIndex == 0); CHECK(testStoreId.packetIndex == idx); } @@ -261,7 +261,7 @@ TEST_CASE("Local Pool Extended Tests [3 Pools]", "[TestPool2]") { size = 10; for (uint8_t idx = 0; idx < 5; idx++) { result = simplePool.addData(&testStoreId, testDataArray.data(), size); - REQUIRE(result == retval::CATCH_OK); + REQUIRE(result == result::OK); CHECK(testStoreId.poolIndex == 1); CHECK(testStoreId.packetIndex == idx); } -- 2.43.0 From 72bc5d4d609fc5222955068e3a51195b7839dd59 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Thu, 28 Jul 2022 12:52:20 +0200 Subject: [PATCH 095/108] add tm zc test --- unittests/tmtcpacket/CMakeLists.txt | 1 + unittests/tmtcpacket/testZcTmWriter.cpp | 23 +++++++++++++++++++++++ 2 files changed, 24 insertions(+) create mode 100644 unittests/tmtcpacket/testZcTmWriter.cpp diff --git a/unittests/tmtcpacket/CMakeLists.txt b/unittests/tmtcpacket/CMakeLists.txt index dd0100a6..5b53328f 100644 --- a/unittests/tmtcpacket/CMakeLists.txt +++ b/unittests/tmtcpacket/CMakeLists.txt @@ -6,4 +6,5 @@ target_sources(${FSFW_TEST_TGT} PRIVATE testPusTmCreator.cpp testPusTmReader.cpp testCcsds.cpp + testZcTmWriter.cpp ) diff --git a/unittests/tmtcpacket/testZcTmWriter.cpp b/unittests/tmtcpacket/testZcTmWriter.cpp new file mode 100644 index 00000000..366697d1 --- /dev/null +++ b/unittests/tmtcpacket/testZcTmWriter.cpp @@ -0,0 +1,23 @@ +#include + +#include "fsfw/tmtcpacket/pus/tm.h" +#include "fsfw/tmtcpacket/pus/tm/PusTmZcWriter.h" +#include "mocks/CdsShortTimestamperMock.h" + +TEST_CASE("TM ZC Helper", "[tm-zc-helper]") { + auto packetId = PacketId(ccsds::PacketType::TC, true, 0xef); + auto spParams = + SpacePacketParams(packetId, PacketSeqCtrl(ccsds::SequenceFlags::UNSEGMENTED, 22), 0x00); + auto timeStamper = CdsShortTimestamperMock(); + auto pusTmParams = PusTmParams(17, 2, &timeStamper); + timeStamper.valueToStamp = {1, 2, 3, 4, 5, 6, 7}; + PusTmCreator creator(spParams, pusTmParams); + std::array buf{}; + uint8_t* dataPtr = buf.data(); + size_t serLen = 0; + + SECTION("Basic") { + REQUIRE(creator.serialize(dataPtr, serLen, buf.size()) == result::OK); + PusTmZeroCopyWriter() + } +} \ No newline at end of file -- 2.43.0 From 30ba9ab91627518f3e9f69ab3af03322d2e90790 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Thu, 28 Jul 2022 13:00:53 +0200 Subject: [PATCH 096/108] some more fixes --- src/fsfw/cfdp/definitions.h | 21 +-- src/fsfw/pus/Service2DeviceAccess.cpp | 4 +- src/fsfw/returnvalues/HasReturnvaluesIF.h | 3 +- src/fsfw/tmtcpacket/pus/PusIF.h | 4 +- src/fsfw/tmtcpacket/pus/tm/PusTmZcWriter.cpp | 4 +- src/fsfw/tmtcpacket/pus/tm/PusTmZcWriter.h | 2 +- .../tmtcservices/CommandingServiceBase.cpp | 6 +- .../tmtcservices/VerificationReporter.cpp | 2 +- .../tmtcservices/VerificationReporterIF.h | 2 +- src/fsfw/tmtcservices/tmHelpers.h | 10 +- src/fsfw_hal/linux/CommandExecutor.h | 12 +- unittests/datapoollocal/testDataSet.cpp | 45 ++++--- .../datapoollocal/testLocalPoolManager.cpp | 122 +++++++++--------- .../datapoollocal/testLocalPoolVariable.cpp | 18 +-- .../datapoollocal/testLocalPoolVector.cpp | 16 +-- unittests/storagemanager/testPool.cpp | 60 ++++----- unittests/tmtcpacket/testZcTmWriter.cpp | 2 +- unittests/tmtcservices/testPsb.cpp | 26 ++-- .../tmtcservices/testStoreAndSendHelper.cpp | 10 +- 19 files changed, 180 insertions(+), 189 deletions(-) diff --git a/src/fsfw/cfdp/definitions.h b/src/fsfw/cfdp/definitions.h index 7e023881..772b3ae3 100644 --- a/src/fsfw/cfdp/definitions.h +++ b/src/fsfw/cfdp/definitions.h @@ -15,24 +15,17 @@ static constexpr uint8_t VERSION_BITS = 0b00100000; static constexpr uint8_t CFDP_CLASS_ID = CLASS_ID::CFDP; -static constexpr ReturnValue_t INVALID_TLV_TYPE = - result::makeCode(CFDP_CLASS_ID, 1); -static constexpr ReturnValue_t INVALID_DIRECTIVE_FIELDS = - result::makeCode(CFDP_CLASS_ID, 2); -static constexpr ReturnValue_t INVALID_PDU_DATAFIELD_LEN = - result::makeCode(CFDP_CLASS_ID, 3); -static constexpr ReturnValue_t INVALID_ACK_DIRECTIVE_FIELDS = - result::makeCode(CFDP_CLASS_ID, 4); +static constexpr ReturnValue_t INVALID_TLV_TYPE = result::makeCode(CFDP_CLASS_ID, 1); +static constexpr ReturnValue_t INVALID_DIRECTIVE_FIELDS = result::makeCode(CFDP_CLASS_ID, 2); +static constexpr ReturnValue_t INVALID_PDU_DATAFIELD_LEN = result::makeCode(CFDP_CLASS_ID, 3); +static constexpr ReturnValue_t INVALID_ACK_DIRECTIVE_FIELDS = result::makeCode(CFDP_CLASS_ID, 4); //! Can not parse options. This can also occur because there are options //! available but the user did not pass a valid options array -static constexpr ReturnValue_t METADATA_CANT_PARSE_OPTIONS = - result::makeCode(CFDP_CLASS_ID, 5); -static constexpr ReturnValue_t NAK_CANT_PARSE_OPTIONS = - result::makeCode(CFDP_CLASS_ID, 6); +static constexpr ReturnValue_t METADATA_CANT_PARSE_OPTIONS = result::makeCode(CFDP_CLASS_ID, 5); +static constexpr ReturnValue_t NAK_CANT_PARSE_OPTIONS = result::makeCode(CFDP_CLASS_ID, 6); static constexpr ReturnValue_t FINISHED_CANT_PARSE_FS_RESPONSES = result::makeCode(CFDP_CLASS_ID, 6); -static constexpr ReturnValue_t FILESTORE_REQUIRES_SECOND_FILE = - result::makeCode(CFDP_CLASS_ID, 8); +static constexpr ReturnValue_t FILESTORE_REQUIRES_SECOND_FILE = result::makeCode(CFDP_CLASS_ID, 8); //! Can not parse filestore response because user did not pass a valid instance //! or remaining size is invalid static constexpr ReturnValue_t FILESTORE_RESPONSE_CANT_PARSE_FS_MESSAGE = diff --git a/src/fsfw/pus/Service2DeviceAccess.cpp b/src/fsfw/pus/Service2DeviceAccess.cpp index 817a372e..414f0812 100644 --- a/src/fsfw/pus/Service2DeviceAccess.cpp +++ b/src/fsfw/pus/Service2DeviceAccess.cpp @@ -136,7 +136,7 @@ void Service2DeviceAccess::sendWiretappingTm(CommandMessage* reply, uint8_t subs const uint8_t* data = nullptr; size_t size = 0; ReturnValue_t result = ipcStore->getData(storeAddress, &data, &size); - if (result != HasReturnvaluesIF::RETURN_OK) { + if (result != RETURN_OK) { #if FSFW_CPP_OSTREAM_ENABLED == 1 sif::error << "Service2DeviceAccess::sendWiretappingTm: Data Lost in " "handleUnrequestedReply with failure ID " @@ -149,7 +149,7 @@ void Service2DeviceAccess::sendWiretappingTm(CommandMessage* reply, uint8_t subs // sending it back. WiretappingPacket tmPacket(DeviceHandlerMessage::getDeviceObjectId(reply), data); result = sendTmPacket(subservice, tmPacket.objectId, tmPacket.data, size); - if (result != retval::OK) { + if (result != RETURN_OK) { // TODO: Warning return; } diff --git a/src/fsfw/returnvalues/HasReturnvaluesIF.h b/src/fsfw/returnvalues/HasReturnvaluesIF.h index 4a4cbeb6..e5e42047 100644 --- a/src/fsfw/returnvalues/HasReturnvaluesIF.h +++ b/src/fsfw/returnvalues/HasReturnvaluesIF.h @@ -33,8 +33,7 @@ class HasReturnvaluesIF { * @param number * @return */ - static constexpr ReturnValue_t makeReturnCode( - uint8_t classId, uint8_t number) { + static constexpr ReturnValue_t makeReturnCode(uint8_t classId, uint8_t number) { return result::makeCode(classId, number); } }; diff --git a/src/fsfw/tmtcpacket/pus/PusIF.h b/src/fsfw/tmtcpacket/pus/PusIF.h index 5f27846e..3c802cfa 100644 --- a/src/fsfw/tmtcpacket/pus/PusIF.h +++ b/src/fsfw/tmtcpacket/pus/PusIF.h @@ -9,8 +9,8 @@ class PusIF : public SpacePacketIF { public: static constexpr uint8_t INTERFACE_ID = CLASS_ID::PUS_IF; - static constexpr ReturnValue_t INVALID_PUS_VERSION = retval::makeCode(INTERFACE_ID, 0); - static constexpr ReturnValue_t INVALID_CRC_16 = retval::makeCode(INTERFACE_ID, 1); + static constexpr ReturnValue_t INVALID_PUS_VERSION = result::makeCode(INTERFACE_ID, 0); + static constexpr ReturnValue_t INVALID_CRC_16 = result::makeCode(INTERFACE_ID, 1); ~PusIF() override = default; /** diff --git a/src/fsfw/tmtcpacket/pus/tm/PusTmZcWriter.cpp b/src/fsfw/tmtcpacket/pus/tm/PusTmZcWriter.cpp index bcbdba03..6ca78378 100644 --- a/src/fsfw/tmtcpacket/pus/tm/PusTmZcWriter.cpp +++ b/src/fsfw/tmtcpacket/pus/tm/PusTmZcWriter.cpp @@ -2,8 +2,8 @@ #include "fsfw/globalfunctions/CRC.h" -PusTmZeroCopyWriter::PusTmZeroCopyWriter(TimeReaderIF* timeReader, uint8_t* data, size_t size) - : PusTmReader(timeReader, data, size) {} +PusTmZeroCopyWriter::PusTmZeroCopyWriter(TimeReaderIF& timeReader, uint8_t* data, size_t size) + : PusTmReader(&timeReader, data, size) {} void PusTmZeroCopyWriter::setSequenceCount(uint16_t seqCount) { auto* spHeader = diff --git a/src/fsfw/tmtcpacket/pus/tm/PusTmZcWriter.h b/src/fsfw/tmtcpacket/pus/tm/PusTmZcWriter.h index d3a0e5f2..331bda7f 100644 --- a/src/fsfw/tmtcpacket/pus/tm/PusTmZcWriter.h +++ b/src/fsfw/tmtcpacket/pus/tm/PusTmZcWriter.h @@ -4,7 +4,7 @@ #include "PusTmReader.h" class PusTmZeroCopyWriter : public PusTmReader { public: - PusTmZeroCopyWriter(TimeReaderIF* timeReader, uint8_t* data, size_t size); + PusTmZeroCopyWriter(TimeReaderIF& timeReader, uint8_t* data, size_t size); void setSequenceCount(uint16_t seqCount); void updateErrorControl(); diff --git a/src/fsfw/tmtcservices/CommandingServiceBase.cpp b/src/fsfw/tmtcservices/CommandingServiceBase.cpp index c12a47b2..ded92926 100644 --- a/src/fsfw/tmtcservices/CommandingServiceBase.cpp +++ b/src/fsfw/tmtcservices/CommandingServiceBase.cpp @@ -309,7 +309,7 @@ void CommandingServiceBase::handleRequestQueue() { ReturnValue_t CommandingServiceBase::sendTmPacket(uint8_t subservice, const uint8_t* sourceData, size_t sourceDataLen) { ReturnValue_t result = tmHelper.prepareTmPacket(subservice, sourceData, sourceDataLen); - if (result != retval::OK) { + if (result != result::OK) { return result; } return tmHelper.storeAndSendTmPacket(); @@ -319,7 +319,7 @@ ReturnValue_t CommandingServiceBase::sendTmPacket(uint8_t subservice, object_id_ const uint8_t* data, size_t dataLen) { telemetry::DataWithObjectIdPrefix dataWithObjId(objectId, data, dataLen); ReturnValue_t result = tmHelper.prepareTmPacket(subservice, dataWithObjId); - if (result != retval::OK) { + if (result != result::OK) { return result; } return tmHelper.storeAndSendTmPacket(); @@ -327,7 +327,7 @@ ReturnValue_t CommandingServiceBase::sendTmPacket(uint8_t subservice, object_id_ ReturnValue_t CommandingServiceBase::sendTmPacket(uint8_t subservice, SerializeIF& sourceData) { ReturnValue_t result = tmHelper.prepareTmPacket(subservice, sourceData); - if (result != retval::OK) { + if (result != result::OK) { return result; } return tmHelper.storeAndSendTmPacket(); diff --git a/src/fsfw/tmtcservices/VerificationReporter.cpp b/src/fsfw/tmtcservices/VerificationReporter.cpp index 9c38b3a7..2eb0c771 100644 --- a/src/fsfw/tmtcservices/VerificationReporter.cpp +++ b/src/fsfw/tmtcservices/VerificationReporter.cpp @@ -36,7 +36,7 @@ ReturnValue_t VerificationReporter::sendFailureReport(VerifFailureParams params) ReturnValue_t VerificationReporter::sendSuccessReport(VerifSuccessParams params) { PusVerificationMessage message(params.reportId, params.ackFlags, params.tcPacketId, params.tcPsc, - retval::OK, params.step); + result::OK, params.step); ReturnValue_t status = MessageQueueSenderIF::sendMessage(acknowledgeQueue, &message); if (status != HasReturnvaluesIF::RETURN_OK) { #if FSFW_CPP_OSTREAM_ENABLED == 1 diff --git a/src/fsfw/tmtcservices/VerificationReporterIF.h b/src/fsfw/tmtcservices/VerificationReporterIF.h index 14b6012f..6678c630 100644 --- a/src/fsfw/tmtcservices/VerificationReporterIF.h +++ b/src/fsfw/tmtcservices/VerificationReporterIF.h @@ -41,7 +41,7 @@ struct VerifFailureParams : public VerifParamsBase { VerifFailureParams(uint8_t reportId, PusTcIF& tc) : VerifParamsBase(reportId, tc.getPacketIdRaw(), tc.getPacketSeqCtrlRaw()) {} - ReturnValue_t errorCode = retval::OK; + ReturnValue_t errorCode = result::OK; uint8_t step = 0; uint32_t errorParam1 = 0; uint32_t errorParam2 = 0; diff --git a/src/fsfw/tmtcservices/tmHelpers.h b/src/fsfw/tmtcservices/tmHelpers.h index ad333eb2..2cb39c78 100644 --- a/src/fsfw/tmtcservices/tmHelpers.h +++ b/src/fsfw/tmtcservices/tmHelpers.h @@ -28,16 +28,16 @@ class DataWithObjectIdPrefix : public SerializeIF { } if (dataWrapper.type != ecss::DataTypes::RAW) { if ((dataWrapper.dataUnion.raw.data == nullptr) and (dataWrapper.dataUnion.raw.len > 0)) { - return retval::FAILED; + return result::FAILED; } } else if (dataWrapper.type == ecss::DataTypes::SERIALIZABLE) { if (dataWrapper.dataUnion.serializable == nullptr) { - return retval::FAILED; + return result::FAILED; } } ReturnValue_t result = SerializeAdapter::serialize(&objectId, buffer, size, maxSize, streamEndianness); - if (result != retval::OK) { + if (result != result::OK) { return result; } if (dataWrapper.type != ecss::DataTypes::RAW) { @@ -47,7 +47,7 @@ class DataWithObjectIdPrefix : public SerializeIF { } else { return dataWrapper.dataUnion.serializable->serialize(buffer, size, maxSize, streamEndianness); } - return retval::OK; + return result::OK; } [[nodiscard]] size_t getSerializedSize() const override { @@ -58,7 +58,7 @@ class DataWithObjectIdPrefix : public SerializeIF { Endianness streamEndianness) override { // As long as there is no way to know how long the expected data will be, this function // does not make sense - return retval::FAILED; + return result::FAILED; } private: diff --git a/src/fsfw_hal/linux/CommandExecutor.h b/src/fsfw_hal/linux/CommandExecutor.h index 27e78260..1696e229 100644 --- a/src/fsfw_hal/linux/CommandExecutor.h +++ b/src/fsfw_hal/linux/CommandExecutor.h @@ -31,18 +31,18 @@ class CommandExecutor { static constexpr uint8_t CLASS_ID = CLASS_ID::LINUX_OSAL; //! [EXPORT] : [COMMENT] Execution of the current command has finished - static constexpr ReturnValue_t EXECUTION_FINISHED = retval::makeCode(CLASS_ID, 0); + static constexpr ReturnValue_t EXECUTION_FINISHED = result::makeCode(CLASS_ID, 0); //! [EXPORT] : [COMMENT] Command is pending. This will also be returned if the user tries //! to load another command but a command is still pending - static constexpr ReturnValue_t COMMAND_PENDING = retval::makeCode(CLASS_ID, 1); + static constexpr ReturnValue_t COMMAND_PENDING = result::makeCode(CLASS_ID, 1); //! [EXPORT] : [COMMENT] Some bytes have been read from the executing process - static constexpr ReturnValue_t BYTES_READ = retval::makeCode(CLASS_ID, 2); + static constexpr ReturnValue_t BYTES_READ = result::makeCode(CLASS_ID, 2); //! [EXPORT] : [COMMENT] Command execution failed - static constexpr ReturnValue_t COMMAND_ERROR = retval::makeCode(CLASS_ID, 3); + static constexpr ReturnValue_t COMMAND_ERROR = result::makeCode(CLASS_ID, 3); //! [EXPORT] : [COMMENT] - static constexpr ReturnValue_t NO_COMMAND_LOADED_OR_PENDING = retval::makeCode(CLASS_ID, 4); - static constexpr ReturnValue_t PCLOSE_CALL_ERROR = retval::makeCode(CLASS_ID, 6); + static constexpr ReturnValue_t NO_COMMAND_LOADED_OR_PENDING = result::makeCode(CLASS_ID, 4); + static constexpr ReturnValue_t PCLOSE_CALL_ERROR = result::makeCode(CLASS_ID, 6); /** * Constructor. Is initialized with maximum size of internal buffer to read data from the diff --git a/unittests/datapoollocal/testDataSet.cpp b/unittests/datapoollocal/testDataSet.cpp index 532208f5..67e17d97 100644 --- a/unittests/datapoollocal/testDataSet.cpp +++ b/unittests/datapoollocal/testDataSet.cpp @@ -16,8 +16,8 @@ TEST_CASE("DataSetTest", "[DataSetTest]") { auto queue = MessageQueueMock(1); LocalPoolOwnerBase poolOwner(queue, objects::TEST_LOCAL_POOL_OWNER_BASE); - REQUIRE(poolOwner.initializeHkManager() == retval::CATCH_OK); - REQUIRE(poolOwner.initializeHkManagerAfterTaskCreation() == retval::CATCH_OK); + REQUIRE(poolOwner.initializeHkManager() == result::OK); + REQUIRE(poolOwner.initializeHkManagerAfterTaskCreation() == result::OK); LocalPoolStaticTestDataSet localSet; SECTION("BasicTest") { @@ -36,7 +36,7 @@ TEST_CASE("DataSetTest", "[DataSetTest]") { /* Test local pool ID serialization */ CHECK(localSet.serializeLocalPoolIds(&localPoolIdBuffPtr, &serSize, maxSize, - SerializeIF::Endianness::MACHINE) == retval::CATCH_OK); + SerializeIF::Endianness::MACHINE) == result::OK); CHECK(serSize == maxSize); CHECK(localPoolIdBuff[0] == 3); CHECK(lpIds[0] == localSet.localPoolVarUint8.getDataPoolId()); @@ -47,8 +47,7 @@ TEST_CASE("DataSetTest", "[DataSetTest]") { localPoolIdBuffPtr = localPoolIdBuff; serSize = 0; CHECK(localSet.serializeLocalPoolIds(&localPoolIdBuffPtr, &serSize, maxSize, - SerializeIF::Endianness::MACHINE, - false) == retval::CATCH_OK); + SerializeIF::Endianness::MACHINE, false) == result::OK); CHECK(serSize == maxSize - sizeof(uint8_t)); CHECK(lpIds[0] == localSet.localPoolVarUint8.getDataPoolId()); CHECK(lpIds[1] == localSet.localPoolVarFloat.getDataPoolId()); @@ -57,7 +56,7 @@ TEST_CASE("DataSetTest", "[DataSetTest]") { { /* Test read operation. Values should be all zeros */ PoolReadGuard readHelper(&localSet); - REQUIRE(readHelper.getReadResult() == retval::CATCH_OK); + REQUIRE(readHelper.getReadResult() == result::OK); CHECK(not localSet.isValid()); CHECK(localSet.localPoolVarUint8.value == 0); CHECK(not localSet.localPoolVarUint8.isValid()); @@ -90,7 +89,7 @@ TEST_CASE("DataSetTest", "[DataSetTest]") { /* Now we read again and check whether our zeroed values were overwritten with the values in the pool */ PoolReadGuard readHelper(&localSet); - REQUIRE(readHelper.getReadResult() == retval::CATCH_OK); + REQUIRE(readHelper.getReadResult() == result::OK); CHECK(localSet.isValid()); CHECK(localSet.localPoolVarUint8.value == 232); CHECK(localSet.localPoolVarUint8.isValid()); @@ -110,7 +109,7 @@ TEST_CASE("DataSetTest", "[DataSetTest]") { uint8_t buffer[maxSize + 1]; uint8_t* buffPtr = buffer; CHECK(localSet.serialize(&buffPtr, &serSize, maxSize, SerializeIF::Endianness::MACHINE) == - retval::CATCH_OK); + result::OK); uint8_t rawUint8 = buffer[0]; CHECK(rawUint8 == 232); float rawFloat = 0.0; @@ -128,7 +127,7 @@ TEST_CASE("DataSetTest", "[DataSetTest]") { std::memset(buffer, 0, sizeof(buffer)); const uint8_t* constBuffPtr = buffer; CHECK(localSet.deSerialize(&constBuffPtr, &sizeToDeserialize, - SerializeIF::Endianness::MACHINE) == retval::CATCH_OK); + SerializeIF::Endianness::MACHINE) == result::OK); /* Check whether deserialization was successfull */ CHECK(localSet.localPoolVarUint8.value == 0); CHECK(localSet.localPoolVarFloat.value == Catch::Approx(0.0)); @@ -156,7 +155,7 @@ TEST_CASE("DataSetTest", "[DataSetTest]") { serSize = 0; buffPtr = buffer; CHECK(localSet.serialize(&buffPtr, &serSize, maxSize, SerializeIF::Endianness::MACHINE) == - retval::CATCH_OK); + result::OK); CHECK(rawUint8 == 232); std::memcpy(&rawFloat, buffer + sizeof(uint8_t), sizeof(float)); CHECK(rawFloat == Catch::Approx(-2324.322)); @@ -186,7 +185,7 @@ TEST_CASE("DataSetTest", "[DataSetTest]") { sizeToDeserialize = maxSize; constBuffPtr = buffer; CHECK(localSet.deSerialize(&constBuffPtr, &sizeToDeserialize, - SerializeIF::Endianness::MACHINE) == retval::CATCH_OK); + SerializeIF::Endianness::MACHINE) == result::OK); /* Check whether deserialization was successfull */ CHECK(localSet.localPoolVarUint8.value == 0); CHECK(localSet.localPoolVarFloat.value == Catch::Approx(0.0)); @@ -213,10 +212,10 @@ TEST_CASE("DataSetTest", "[DataSetTest]") { /* Register same variables again to get more than 8 registered variables */ for (uint8_t idx = 0; idx < 8; idx++) { - REQUIRE(set.registerVariable(&localSet.localPoolVarUint8) == retval::CATCH_OK); + REQUIRE(set.registerVariable(&localSet.localPoolVarUint8) == result::OK); } - REQUIRE(set.registerVariable(&localSet.localPoolVarUint8) == retval::CATCH_OK); - REQUIRE(set.registerVariable(&localSet.localPoolUint16Vec) == retval::CATCH_OK); + REQUIRE(set.registerVariable(&localSet.localPoolVarUint8) == result::OK); + REQUIRE(set.registerVariable(&localSet.localPoolUint16Vec) == result::OK); set.setValidityBufferGeneration(true); { @@ -233,7 +232,7 @@ TEST_CASE("DataSetTest", "[DataSetTest]") { uint8_t buffer[maxSize + 1]; uint8_t* buffPtr = buffer; CHECK(set.serialize(&buffPtr, &serSize, maxSize, SerializeIF::Endianness::MACHINE) == - retval::CATCH_OK); + result::OK); std::array validityBuffer{}; std::memcpy(validityBuffer.data(), buffer + 9 + sizeof(uint16_t) * 3, 2); /* The first 9 variables should be valid */ @@ -251,7 +250,7 @@ TEST_CASE("DataSetTest", "[DataSetTest]") { const uint8_t* constBuffPtr = buffer; size_t sizeToDeSerialize = serSize; CHECK(set.deSerialize(&constBuffPtr, &sizeToDeSerialize, SerializeIF::Endianness::MACHINE) == - retval::CATCH_OK); + result::OK); CHECK(localSet.localPoolVarUint8.isValid() == false); CHECK(localSet.localPoolUint16Vec.isValid() == true); } @@ -261,20 +260,20 @@ TEST_CASE("DataSetTest", "[DataSetTest]") { SharedLocalDataSet sharedSet(sharedSetId, &poolOwner, lpool::testSetId, 5); localSet.localPoolVarUint8.setReadWriteMode(pool_rwm_t::VAR_WRITE); localSet.localPoolUint16Vec.setReadWriteMode(pool_rwm_t::VAR_WRITE); - CHECK(sharedSet.registerVariable(&localSet.localPoolVarUint8) == retval::CATCH_OK); - CHECK(sharedSet.registerVariable(&localSet.localPoolUint16Vec) == retval::CATCH_OK); - CHECK(sharedSet.initialize() == retval::CATCH_OK); - CHECK(sharedSet.lockDataset() == retval::CATCH_OK); - CHECK(sharedSet.unlockDataset() == retval::CATCH_OK); + CHECK(sharedSet.registerVariable(&localSet.localPoolVarUint8) == result::OK); + CHECK(sharedSet.registerVariable(&localSet.localPoolUint16Vec) == result::OK); + CHECK(sharedSet.initialize() == result::OK); + CHECK(sharedSet.lockDataset() == result::OK); + CHECK(sharedSet.unlockDataset() == result::OK); { // PoolReadGuard rg(&sharedSet); - // CHECK(rg.getReadResult() == retval::CATCH_OK); + // CHECK(rg.getReadResult() == result::OK); localSet.localPoolVarUint8.value = 5; localSet.localPoolUint16Vec.value[0] = 1; localSet.localPoolUint16Vec.value[1] = 2; localSet.localPoolUint16Vec.value[2] = 3; - CHECK(sharedSet.commit() == retval::CATCH_OK); + CHECK(sharedSet.commit() == result::OK); } sharedSet.setReadCommitProtectionBehaviour(true); diff --git a/unittests/datapoollocal/testLocalPoolManager.cpp b/unittests/datapoollocal/testLocalPoolManager.cpp index bdeec8c0..dfb72ec1 100644 --- a/unittests/datapoollocal/testLocalPoolManager.cpp +++ b/unittests/datapoollocal/testLocalPoolManager.cpp @@ -22,8 +22,8 @@ TEST_CASE("Local Pool Manager Tests", "[LocManTest]") { auto hkReceiver = HkReceiverMock(hkDest); auto queue = MessageQueueMock(3); LocalPoolOwnerBase poolOwner(queue, objects::TEST_LOCAL_POOL_OWNER_BASE); - REQUIRE(poolOwner.initializeHkManager() == retval::CATCH_OK); - REQUIRE(poolOwner.initializeHkManagerAfterTaskCreation() == retval::CATCH_OK); + REQUIRE(poolOwner.initializeHkManager() == result::OK); + REQUIRE(poolOwner.initializeHkManagerAfterTaskCreation() == result::OK); MessageQueueMock& poolOwnerMock = poolOwner.getMockQueueHandle(); @@ -46,14 +46,14 @@ TEST_CASE("Local Pool Manager Tests", "[LocManTest]") { CHECK(owner->getObjectId() == objects::TEST_LOCAL_POOL_OWNER_BASE); /* Subscribe for message generation on update. */ - REQUIRE(poolOwner.subscribeWrapperSetUpdate(subscriberId) == retval::CATCH_OK); + REQUIRE(poolOwner.subscribeWrapperSetUpdate(subscriberId) == result::OK); /* Subscribe for an update message. */ poolOwner.dataset.setChanged(true); /* Now the update message should be generated. */ - REQUIRE(poolOwner.poolManager.performHkOperation() == retval::CATCH_OK); + REQUIRE(poolOwner.poolManager.performHkOperation() == result::OK); REQUIRE(poolOwnerMock.wasMessageSent()); - REQUIRE(poolOwnerMock.getNextSentMessage(subscriberId, messageSent) == retval::CATCH_OK); + REQUIRE(poolOwnerMock.getNextSentMessage(subscriberId, messageSent) == result::OK); CHECK(messageSent.getCommand() == static_cast(HousekeepingMessage::UPDATE_NOTIFICATION_SET)); @@ -62,26 +62,26 @@ TEST_CASE("Local Pool Manager Tests", "[LocManTest]") { poolOwnerMock.clearMessages(true); /* Set changed again, result should be the same. */ poolOwner.dataset.setChanged(true); - REQUIRE(poolOwner.poolManager.performHkOperation() == retval::CATCH_OK); + REQUIRE(poolOwner.poolManager.performHkOperation() == result::OK); REQUIRE(poolOwnerMock.wasMessageSent() == true); CHECK(poolOwnerMock.numberOfSentMessages() == 1); - REQUIRE(poolOwnerMock.getNextSentMessage(subscriberId, messageSent) == retval::CATCH_OK); + REQUIRE(poolOwnerMock.getNextSentMessage(subscriberId, messageSent) == result::OK); CHECK(messageSent.getCommand() == static_cast(HousekeepingMessage::UPDATE_NOTIFICATION_SET)); poolOwnerMock.clearMessages(true); /* Now subscribe for set update HK as well. */ - REQUIRE(poolOwner.subscribeWrapperSetUpdateHk(false, &hkReceiver) == retval::CATCH_OK); + REQUIRE(poolOwner.subscribeWrapperSetUpdateHk(false, &hkReceiver) == result::OK); poolOwner.dataset.setChanged(true); - REQUIRE(poolOwner.poolManager.performHkOperation() == retval::CATCH_OK); + REQUIRE(poolOwner.poolManager.performHkOperation() == result::OK); REQUIRE(poolOwnerMock.wasMessageSent() == true); CHECK(poolOwnerMock.numberOfSentMessages() == 2); // first message sent should be the update notification - REQUIRE(poolOwnerMock.getNextSentMessage(subscriberId, messageSent) == retval::CATCH_OK); + REQUIRE(poolOwnerMock.getNextSentMessage(subscriberId, messageSent) == result::OK); CHECK(messageSent.getCommand() == static_cast(HousekeepingMessage::UPDATE_NOTIFICATION_SET)); - REQUIRE(poolOwnerMock.getNextSentMessage(messageSent) == retval::CATCH_OK); + REQUIRE(poolOwnerMock.getNextSentMessage(messageSent) == result::OK); CHECK(messageSent.getCommand() == static_cast(HousekeepingMessage::HK_REPORT)); /* Clear message to avoid memory leak, our mock won't do it for us (yet) */ CommandMessageCleaner::clearCommandMessage(&messageSent); @@ -91,7 +91,7 @@ TEST_CASE("Local Pool Manager Tests", "[LocManTest]") { /* Set the variables in the set to certain values. These are checked later. */ { PoolReadGuard readHelper(&poolOwner.dataset); - REQUIRE(readHelper.getReadResult() == retval::CATCH_OK); + REQUIRE(readHelper.getReadResult() == result::OK); poolOwner.dataset.localPoolVarUint8.value = 5; poolOwner.dataset.localPoolVarFloat.value = -12.242; poolOwner.dataset.localPoolUint16Vec.value[0] = 2; @@ -100,7 +100,7 @@ TEST_CASE("Local Pool Manager Tests", "[LocManTest]") { } /* Subscribe for snapshot generation on update. */ - REQUIRE(poolOwner.subscribeWrapperSetUpdateSnapshot(subscriberId) == retval::CATCH_OK); + REQUIRE(poolOwner.subscribeWrapperSetUpdateSnapshot(subscriberId) == result::OK); poolOwner.dataset.setChanged(true); /* Store current time, we are going to check the (approximate) time equality later */ @@ -108,10 +108,10 @@ TEST_CASE("Local Pool Manager Tests", "[LocManTest]") { Clock::getClock_timeval(&now); /* Trigger generation of snapshot */ - REQUIRE(poolOwner.poolManager.performHkOperation() == retval::CATCH_OK); + REQUIRE(poolOwner.poolManager.performHkOperation() == result::OK); REQUIRE(poolOwnerMock.wasMessageSent()); CHECK(poolOwnerMock.numberOfSentMessages() == 1); - REQUIRE(poolOwnerMock.getNextSentMessage(subscriberId, messageSent) == retval::CATCH_OK); + REQUIRE(poolOwnerMock.getNextSentMessage(subscriberId, messageSent) == result::OK); /* Check that snapshot was generated */ CHECK(messageSent.getCommand() == static_cast(HousekeepingMessage::UPDATE_SNAPSHOT_SET)); /* Now we deserialize the snapshot into a new dataset instance */ @@ -121,7 +121,7 @@ TEST_CASE("Local Pool Manager Tests", "[LocManTest]") { store_address_t storeId; HousekeepingMessage::getUpdateSnapshotSetCommand(&messageSent, &storeId); ConstAccessorPair accessorPair = tglob::getIpcStoreHandle()->getData(storeId); - REQUIRE(accessorPair.first == retval::CATCH_OK); + REQUIRE(accessorPair.first == result::OK); const uint8_t* readOnlyPtr = accessorPair.second.data(); size_t sizeToDeserialize = accessorPair.second.size(); CHECK(newSet.localPoolVarFloat.value == 0); @@ -131,7 +131,7 @@ TEST_CASE("Local Pool Manager Tests", "[LocManTest]") { CHECK(newSet.localPoolUint16Vec.value[2] == 0); /* Fill the dataset and timestamp */ REQUIRE(snapshot.deSerialize(&readOnlyPtr, &sizeToDeserialize, - SerializeIF::Endianness::MACHINE) == retval::CATCH_OK); + SerializeIF::Endianness::MACHINE) == result::OK); /* Now we check that the snapshot is actually correct */ CHECK(newSet.localPoolVarFloat.value == Catch::Approx(-12.242)); CHECK(newSet.localPoolVarUint8 == 5); @@ -154,14 +154,14 @@ TEST_CASE("Local Pool Manager Tests", "[LocManTest]") { /* Subscribe for variable snapshot */ REQUIRE(poolOwner.subscribeWrapperVariableSnapshot(subscriberId, lpool::uint8VarId) == - retval::CATCH_OK); + result::OK); auto poolVar = dynamic_cast*>(poolOwner.getPoolObjectHandle(lpool::uint8VarId)); REQUIRE(poolVar != nullptr); { PoolReadGuard rg(poolVar); - CHECK(rg.getReadResult() == retval::CATCH_OK); + CHECK(rg.getReadResult() == result::OK); poolVar->value = 25; } @@ -170,7 +170,7 @@ TEST_CASE("Local Pool Manager Tests", "[LocManTest]") { CCSDSTime::CDS_short timeCdsNow{}; timeval now{}; Clock::getClock_timeval(&now); - REQUIRE(poolOwner.poolManager.performHkOperation() == retval::CATCH_OK); + REQUIRE(poolOwner.poolManager.performHkOperation() == result::OK); /* Check update snapshot was sent. */ REQUIRE(poolOwnerMock.wasMessageSent()); @@ -178,7 +178,7 @@ TEST_CASE("Local Pool Manager Tests", "[LocManTest]") { /* Should have been reset. */ CHECK(poolVar->hasChanged() == false); - REQUIRE(poolOwnerMock.getNextSentMessage(subscriberId, messageSent) == retval::CATCH_OK); + REQUIRE(poolOwnerMock.getNextSentMessage(subscriberId, messageSent) == result::OK); CHECK(messageSent.getCommand() == static_cast(HousekeepingMessage::UPDATE_SNAPSHOT_VARIABLE)); /* Now we deserialize the snapshot into a new dataset instance */ @@ -188,13 +188,13 @@ TEST_CASE("Local Pool Manager Tests", "[LocManTest]") { store_address_t storeId; HousekeepingMessage::getUpdateSnapshotVariableCommand(&messageSent, &storeId); ConstAccessorPair accessorPair = tglob::getIpcStoreHandle()->getData(storeId); - REQUIRE(accessorPair.first == retval::CATCH_OK); + REQUIRE(accessorPair.first == result::OK); const uint8_t* readOnlyPtr = accessorPair.second.data(); size_t sizeToDeserialize = accessorPair.second.size(); CHECK(varCopy.value == 0); /* Fill the dataset and timestamp */ REQUIRE(snapshot.deSerialize(&readOnlyPtr, &sizeToDeserialize, - SerializeIF::Endianness::MACHINE) == retval::CATCH_OK); + SerializeIF::Endianness::MACHINE) == result::OK); CHECK(varCopy.value == 25); /* Now we check that both times are equal */ @@ -212,30 +212,30 @@ TEST_CASE("Local Pool Manager Tests", "[LocManTest]") { /* Subscribe for variable update */ REQUIRE(poolOwner.subscribeWrapperVariableUpdate(subscriberId, lpool::uint8VarId) == - retval::CATCH_OK); + result::OK); auto* poolVar = dynamic_cast*>(poolOwner.getPoolObjectHandle(lpool::uint8VarId)); REQUIRE(poolVar != nullptr); poolVar->setChanged(true); REQUIRE(poolVar->hasChanged() == true); - REQUIRE(poolOwner.poolManager.performHkOperation() == retval::CATCH_OK); + REQUIRE(poolOwner.poolManager.performHkOperation() == result::OK); /* Check update notification was sent. */ REQUIRE(poolOwnerMock.wasMessageSent()); CHECK(poolOwnerMock.numberOfSentMessages() == 1); /* Should have been reset. */ CHECK(poolVar->hasChanged() == false); - REQUIRE(poolOwnerMock.getNextSentMessage(subscriberId, messageSent) == retval::CATCH_OK); + REQUIRE(poolOwnerMock.getNextSentMessage(subscriberId, messageSent) == result::OK); CHECK(messageSent.getCommand() == static_cast(HousekeepingMessage::UPDATE_NOTIFICATION_VARIABLE)); /* Now subscribe for the dataset update (HK and update) again with subscription interface */ REQUIRE(subscriptionIF->subscribeForSetUpdateMessage(lpool::testSetId, objects::NO_OBJECT, - subscriberId, false) == retval::CATCH_OK); - REQUIRE(poolOwner.subscribeWrapperSetUpdateHk(false, &hkReceiver) == retval::CATCH_OK); + subscriberId, false) == result::OK); + REQUIRE(poolOwner.subscribeWrapperSetUpdateHk(false, &hkReceiver) == result::OK); poolOwner.dataset.setChanged(true); poolOwnerMock.clearMessages(); - REQUIRE(poolOwner.poolManager.performHkOperation() == retval::CATCH_OK); + REQUIRE(poolOwner.poolManager.performHkOperation() == result::OK); /* Now two messages should be sent. */ REQUIRE(poolOwnerMock.wasMessageSent()); CHECK(poolOwnerMock.numberOfSentMessages() == 2); @@ -244,13 +244,13 @@ TEST_CASE("Local Pool Manager Tests", "[LocManTest]") { poolOwner.dataset.setChanged(true); poolOwnerMock.clearMessages(true); poolVar->setChanged(true); - REQUIRE(poolOwner.poolManager.performHkOperation() == retval::CATCH_OK); + REQUIRE(poolOwner.poolManager.performHkOperation() == result::OK); /* Now three messages should be sent. */ REQUIRE(poolOwnerMock.wasMessageSent()); CHECK(poolOwnerMock.numberOfSentMessages() == 3); CHECK(poolOwnerMock.numberOfSentMessagesToDest(subscriberId) == 2); CHECK(poolOwnerMock.numberOfSentMessagesToDest(hkDest) == 1); - REQUIRE(poolOwnerMock.getNextSentMessage(subscriberId, messageSent) == retval::CATCH_OK); + REQUIRE(poolOwnerMock.getNextSentMessage(subscriberId, messageSent) == result::OK); CHECK(messageSent.getCommand() == static_cast(HousekeepingMessage::UPDATE_NOTIFICATION_VARIABLE)); REQUIRE(poolOwnerMock.clearLastSentMessage(subscriberId) == HasReturnvaluesIF::RETURN_OK); @@ -259,7 +259,7 @@ TEST_CASE("Local Pool Manager Tests", "[LocManTest]") { CHECK(messageSent.getCommand() == static_cast(HousekeepingMessage::UPDATE_NOTIFICATION_SET)); REQUIRE(poolOwnerMock.clearLastSentMessage(subscriberId) == HasReturnvaluesIF::RETURN_OK); - REQUIRE(poolOwnerMock.getNextSentMessage(messageSent) == retval::CATCH_OK); + REQUIRE(poolOwnerMock.getNextSentMessage(messageSent) == result::OK); CHECK(messageSent.getCommand() == static_cast(HousekeepingMessage::HK_REPORT)); REQUIRE(poolOwnerMock.clearLastSentMessage() == HasReturnvaluesIF::RETURN_OK); REQUIRE(poolOwnerMock.getNextSentMessage(subscriberId, messageSent) == MessageQueueIF::EMPTY); @@ -271,62 +271,62 @@ TEST_CASE("Local Pool Manager Tests", "[LocManTest]") { the temporal behaviour correctly the HK manager should generate a HK packet immediately and the periodic helper depends on HK op function calls anyway instead of using the clock, so we could also just call performHkOperation multiple times */ - REQUIRE(poolOwner.subscribePeriodicHk(true) == retval::CATCH_OK); - REQUIRE(poolOwner.poolManager.performHkOperation() == retval::CATCH_OK); + REQUIRE(poolOwner.subscribePeriodicHk(true) == result::OK); + REQUIRE(poolOwner.poolManager.performHkOperation() == result::OK); /* Now HK packet should be sent as message immediately. */ REQUIRE(poolOwnerMock.wasMessageSent()); CHECK(poolOwnerMock.numberOfSentMessages() == 1); - CHECK(poolOwnerMock.clearLastSentMessage() == retval::CATCH_OK); + CHECK(poolOwnerMock.clearLastSentMessage() == result::OK); LocalPoolDataSetBase* setHandle = poolOwner.getDataSetHandle(lpool::testSid); REQUIRE(setHandle != nullptr); CHECK(poolOwner.poolManager.generateHousekeepingPacket(lpool::testSid, setHandle, false) == - retval::CATCH_OK); + result::OK); REQUIRE(poolOwnerMock.wasMessageSent()); CHECK(poolOwnerMock.numberOfSentMessages() == 1); - CHECK(poolOwnerMock.clearLastSentMessage() == retval::CATCH_OK); + CHECK(poolOwnerMock.clearLastSentMessage() == result::OK); CHECK(setHandle->getReportingEnabled() == true); CommandMessage hkCmd; HousekeepingMessage::setToggleReportingCommand(&hkCmd, lpool::testSid, false, false); - CHECK(poolOwner.poolManager.handleHousekeepingMessage(&hkCmd) == retval::CATCH_OK); + CHECK(poolOwner.poolManager.handleHousekeepingMessage(&hkCmd) == result::OK); CHECK(setHandle->getReportingEnabled() == false); REQUIRE(poolOwnerMock.wasMessageSent()); CHECK(poolOwnerMock.numberOfSentMessages() == 1); - CHECK(poolOwnerMock.clearLastSentMessage() == retval::CATCH_OK); + CHECK(poolOwnerMock.clearLastSentMessage() == result::OK); HousekeepingMessage::setToggleReportingCommand(&hkCmd, lpool::testSid, true, false); - CHECK(poolOwner.poolManager.handleHousekeepingMessage(&hkCmd) == retval::CATCH_OK); + CHECK(poolOwner.poolManager.handleHousekeepingMessage(&hkCmd) == result::OK); CHECK(setHandle->getReportingEnabled() == true); REQUIRE(poolOwnerMock.wasMessageSent()); - CHECK(poolOwnerMock.clearLastSentMessage() == retval::CATCH_OK); + CHECK(poolOwnerMock.clearLastSentMessage() == result::OK); HousekeepingMessage::setToggleReportingCommand(&hkCmd, lpool::testSid, false, false); - CHECK(poolOwner.poolManager.handleHousekeepingMessage(&hkCmd) == retval::CATCH_OK); + CHECK(poolOwner.poolManager.handleHousekeepingMessage(&hkCmd) == result::OK); CHECK(setHandle->getReportingEnabled() == false); REQUIRE(poolOwnerMock.wasMessageSent()); - CHECK(poolOwnerMock.clearLastSentMessage() == retval::CATCH_OK); + CHECK(poolOwnerMock.clearLastSentMessage() == result::OK); HousekeepingMessage::setCollectionIntervalModificationCommand(&hkCmd, lpool::testSid, 0.4, false); - CHECK(poolOwner.poolManager.handleHousekeepingMessage(&hkCmd) == retval::CATCH_OK); + CHECK(poolOwner.poolManager.handleHousekeepingMessage(&hkCmd) == result::OK); /* For non-diagnostics and a specified minimum frequency of 0.2 seconds, the resulting collection interval should be 1.0 second */ CHECK(poolOwner.dataset.getCollectionInterval() == 1.0); REQUIRE(poolOwnerMock.wasMessageSent()); REQUIRE(poolOwnerMock.numberOfSentMessages() == 1); - CHECK(poolOwnerMock.clearLastSentMessage() == retval::CATCH_OK); + CHECK(poolOwnerMock.clearLastSentMessage() == result::OK); HousekeepingMessage::setStructureReportingCommand(&hkCmd, lpool::testSid, false); - REQUIRE(poolOwner.poolManager.performHkOperation() == retval::CATCH_OK); - CHECK(poolOwner.poolManager.handleHousekeepingMessage(&hkCmd) == retval::CATCH_OK); + REQUIRE(poolOwner.poolManager.performHkOperation() == result::OK); + CHECK(poolOwner.poolManager.handleHousekeepingMessage(&hkCmd) == result::OK); /* Now HK packet should be sent as message. */ REQUIRE(poolOwnerMock.wasMessageSent()); REQUIRE(poolOwnerMock.numberOfSentMessages() == 1); poolOwnerMock.clearMessages(); HousekeepingMessage::setOneShotReportCommand(&hkCmd, lpool::testSid, false); - CHECK(poolOwner.poolManager.handleHousekeepingMessage(&hkCmd) == retval::CATCH_OK); + CHECK(poolOwner.poolManager.handleHousekeepingMessage(&hkCmd) == result::OK); REQUIRE(poolOwnerMock.wasMessageSent()); REQUIRE(poolOwnerMock.numberOfSentMessages() == 1); poolOwnerMock.clearMessages(); @@ -334,7 +334,7 @@ TEST_CASE("Local Pool Manager Tests", "[LocManTest]") { HousekeepingMessage::setUpdateNotificationSetCommand(&hkCmd, lpool::testSid); sid_t sidToCheck; store_address_t storeId; - CHECK(poolOwner.poolManager.handleHousekeepingMessage(&hkCmd) == retval::CATCH_OK); + CHECK(poolOwner.poolManager.handleHousekeepingMessage(&hkCmd) == result::OK); CHECK(poolOwner.changedDataSetCallbackWasCalled(sidToCheck, storeId) == true); CHECK(sidToCheck == lpool::testSid); @@ -347,7 +347,7 @@ TEST_CASE("Local Pool Manager Tests", "[LocManTest]") { /* We still expect a failure message being sent */ REQUIRE(poolOwnerMock.wasMessageSent()); REQUIRE(poolOwnerMock.numberOfSentMessages() == 1); - CHECK(poolOwnerMock.clearLastSentMessage() == retval::CATCH_OK); + CHECK(poolOwnerMock.clearLastSentMessage() == result::OK); HousekeepingMessage::setCollectionIntervalModificationCommand(&hkCmd, lpool::testSid, 0.4, false); @@ -355,36 +355,36 @@ TEST_CASE("Local Pool Manager Tests", "[LocManTest]") { static_cast(LocalDataPoolManager::WRONG_HK_PACKET_TYPE)); REQUIRE(poolOwnerMock.wasMessageSent()); REQUIRE(poolOwnerMock.numberOfSentMessages() == 1); - CHECK(poolOwnerMock.clearLastSentMessage() == retval::CATCH_OK); + CHECK(poolOwnerMock.clearLastSentMessage() == result::OK); HousekeepingMessage::setStructureReportingCommand(&hkCmd, lpool::testSid, false); CHECK(poolOwner.poolManager.handleHousekeepingMessage(&hkCmd) == static_cast(LocalDataPoolManager::WRONG_HK_PACKET_TYPE)); REQUIRE(poolOwnerMock.wasMessageSent()); REQUIRE(poolOwnerMock.numberOfSentMessages() == 1); - CHECK(poolOwnerMock.clearLastSentMessage() == retval::CATCH_OK); + CHECK(poolOwnerMock.clearLastSentMessage() == result::OK); HousekeepingMessage::setStructureReportingCommand(&hkCmd, lpool::testSid, true); - CHECK(poolOwner.poolManager.handleHousekeepingMessage(&hkCmd) == retval::CATCH_OK); + CHECK(poolOwner.poolManager.handleHousekeepingMessage(&hkCmd) == result::OK); REQUIRE(poolOwnerMock.wasMessageSent()); REQUIRE(poolOwnerMock.numberOfSentMessages() == 1); poolOwnerMock.clearMessages(); HousekeepingMessage::setCollectionIntervalModificationCommand(&hkCmd, lpool::testSid, 0.4, true); - CHECK(poolOwner.poolManager.handleHousekeepingMessage(&hkCmd) == retval::CATCH_OK); + CHECK(poolOwner.poolManager.handleHousekeepingMessage(&hkCmd) == result::OK); REQUIRE(poolOwnerMock.wasMessageSent()); REQUIRE(poolOwnerMock.numberOfSentMessages() == 1); poolOwnerMock.clearMessages(); HousekeepingMessage::setToggleReportingCommand(&hkCmd, lpool::testSid, true, true); - CHECK(poolOwner.poolManager.handleHousekeepingMessage(&hkCmd) == retval::CATCH_OK); + CHECK(poolOwner.poolManager.handleHousekeepingMessage(&hkCmd) == result::OK); REQUIRE(poolOwnerMock.wasMessageSent()); REQUIRE(poolOwnerMock.numberOfSentMessages() == 1); poolOwnerMock.clearMessages(); HousekeepingMessage::setToggleReportingCommand(&hkCmd, lpool::testSid, false, true); - CHECK(poolOwner.poolManager.handleHousekeepingMessage(&hkCmd) == retval::CATCH_OK); + CHECK(poolOwner.poolManager.handleHousekeepingMessage(&hkCmd) == result::OK); REQUIRE(poolOwnerMock.wasMessageSent()); REQUIRE(poolOwnerMock.numberOfSentMessages() == 1); poolOwnerMock.clearMessages(); @@ -397,26 +397,26 @@ TEST_CASE("Local Pool Manager Tests", "[LocManTest]") { poolOwnerMock.clearMessages(); HousekeepingMessage::setOneShotReportCommand(&hkCmd, lpool::testSid, true); - CHECK(poolOwner.poolManager.handleHousekeepingMessage(&hkCmd) == retval::CATCH_OK); + CHECK(poolOwner.poolManager.handleHousekeepingMessage(&hkCmd) == result::OK); REQUIRE(poolOwnerMock.wasMessageSent()); REQUIRE(poolOwnerMock.numberOfSentMessages() == 1); poolOwnerMock.clearMessages(); HousekeepingMessage::setUpdateNotificationVariableCommand(&hkCmd, lpool::uint8VarGpid); gp_id_t gpidToCheck; - CHECK(poolOwner.poolManager.handleHousekeepingMessage(&hkCmd) == retval::CATCH_OK); + CHECK(poolOwner.poolManager.handleHousekeepingMessage(&hkCmd) == result::OK); CHECK(poolOwner.changedVariableCallbackWasCalled(gpidToCheck, storeId) == true); CHECK(gpidToCheck == lpool::uint8VarGpid); HousekeepingMessage::setUpdateSnapshotSetCommand(&hkCmd, lpool::testSid, store_address_t::invalid()); - CHECK(poolOwner.poolManager.handleHousekeepingMessage(&hkCmd) == retval::CATCH_OK); + CHECK(poolOwner.poolManager.handleHousekeepingMessage(&hkCmd) == result::OK); CHECK(poolOwner.changedDataSetCallbackWasCalled(sidToCheck, storeId) == true); CHECK(sidToCheck == lpool::testSid); HousekeepingMessage::setUpdateSnapshotVariableCommand(&hkCmd, lpool::uint8VarGpid, store_address_t::invalid()); - CHECK(poolOwner.poolManager.handleHousekeepingMessage(&hkCmd) == retval::CATCH_OK); + CHECK(poolOwner.poolManager.handleHousekeepingMessage(&hkCmd) == result::OK); CHECK(poolOwner.changedVariableCallbackWasCalled(gpidToCheck, storeId) == true); CHECK(gpidToCheck == lpool::uint8VarGpid); @@ -425,6 +425,6 @@ TEST_CASE("Local Pool Manager Tests", "[LocManTest]") { /* we need to reset the subscription list because the pool owner is a global object. */ - CHECK(poolOwner.reset() == retval::CATCH_OK); + CHECK(poolOwner.reset() == result::OK); poolOwnerMock.clearMessages(true); } diff --git a/unittests/datapoollocal/testLocalPoolVariable.cpp b/unittests/datapoollocal/testLocalPoolVariable.cpp index b3ae07e0..78b1ccde 100644 --- a/unittests/datapoollocal/testLocalPoolVariable.cpp +++ b/unittests/datapoollocal/testLocalPoolVariable.cpp @@ -10,23 +10,23 @@ TEST_CASE("LocalPoolVariable", "[LocPoolVarTest]") { auto queue = MessageQueueMock(1); LocalPoolOwnerBase poolOwner(queue, objects::TEST_LOCAL_POOL_OWNER_BASE); - REQUIRE(poolOwner.initializeHkManager() == retval::CATCH_OK); - REQUIRE(poolOwner.initializeHkManagerAfterTaskCreation() == retval::CATCH_OK); + REQUIRE(poolOwner.initializeHkManager() == result::OK); + REQUIRE(poolOwner.initializeHkManagerAfterTaskCreation() == result::OK); SECTION("Basic Tests") { /* very basic test. */ lp_var_t testVariable = lp_var_t(objects::TEST_LOCAL_POOL_OWNER_BASE, lpool::uint8VarId); - REQUIRE(testVariable.read() == retval::CATCH_OK); + REQUIRE(testVariable.read() == result::OK); CHECK(testVariable.value == 0); testVariable.value = 5; - REQUIRE(testVariable.commit() == retval::CATCH_OK); - REQUIRE(testVariable.read() == retval::CATCH_OK); + REQUIRE(testVariable.commit() == result::OK); + REQUIRE(testVariable.read() == result::OK); REQUIRE(testVariable.value == 5); CHECK(not testVariable.isValid()); testVariable.setValid(true); CHECK(testVariable.isValid()); - CHECK(testVariable.commit(true) == retval::CATCH_OK); + CHECK(testVariable.commit(true) == result::OK); testVariable.setReadWriteMode(pool_rwm_t::VAR_READ); CHECK(testVariable.getReadWriteMode() == pool_rwm_t::VAR_READ); @@ -42,7 +42,7 @@ TEST_CASE("LocalPoolVariable", "[LocPoolVarTest]") { gp_id_t globPoolId(objects::TEST_LOCAL_POOL_OWNER_BASE, lpool::uint8VarId); lp_var_t testVariable2 = lp_var_t(globPoolId); - REQUIRE(testVariable2.read() == retval::CATCH_OK); + REQUIRE(testVariable2.read() == result::OK); CHECK(testVariable2 == 5); CHECK(testVariable == testVariable2); testVariable = 10; @@ -54,12 +54,12 @@ TEST_CASE("LocalPoolVariable", "[LocPoolVarTest]") { CHECK(maxSize == 1); size_t serSize = 0; CHECK(testVariable.serialize(&varPtr, &serSize, maxSize, SerializeIF::Endianness::MACHINE) == - retval::CATCH_OK); + result::OK); CHECK(variableRaw == 10); const uint8_t* varConstPtr = &variableRaw; testVariable = 5; CHECK(testVariable.deSerialize(&varConstPtr, &serSize, SerializeIF::Endianness::MACHINE) == - retval::CATCH_OK); + result::OK); CHECK(testVariable == 10); CHECK(testVariable != testVariable2); CHECK(testVariable2 < testVariable); diff --git a/unittests/datapoollocal/testLocalPoolVector.cpp b/unittests/datapoollocal/testLocalPoolVector.cpp index e04bf643..9ebfd3a0 100644 --- a/unittests/datapoollocal/testLocalPoolVector.cpp +++ b/unittests/datapoollocal/testLocalPoolVector.cpp @@ -10,26 +10,26 @@ TEST_CASE("LocalPoolVector", "[LocPoolVecTest]") { auto queue = MessageQueueMock(1); LocalPoolOwnerBase poolOwner(queue, objects::TEST_LOCAL_POOL_OWNER_BASE); - REQUIRE(poolOwner.initializeHkManager() == retval::CATCH_OK); - REQUIRE(poolOwner.initializeHkManagerAfterTaskCreation() == retval::CATCH_OK); + REQUIRE(poolOwner.initializeHkManager() == result::OK); + REQUIRE(poolOwner.initializeHkManagerAfterTaskCreation() == result::OK); SECTION("BasicTest") { // very basic test. lp_vec_t testVector = lp_vec_t(objects::TEST_LOCAL_POOL_OWNER_BASE, lpool::uint16Vec3Id); - REQUIRE(testVector.read() == retval::CATCH_OK); + REQUIRE(testVector.read() == result::OK); testVector.value[0] = 5; testVector.value[1] = 232; testVector.value[2] = 32023; - REQUIRE(testVector.commit(true) == retval::CATCH_OK); + REQUIRE(testVector.commit(true) == result::OK); CHECK(testVector.isValid()); testVector.value[0] = 0; testVector.value[1] = 0; testVector.value[2] = 0; - CHECK(testVector.read() == retval::CATCH_OK); + CHECK(testVector.read() == result::OK); CHECK(testVector.value[0] == 5); CHECK(testVector.value[1] == 232); CHECK(testVector.value[2] == 32023); @@ -40,7 +40,7 @@ TEST_CASE("LocalPoolVector", "[LocPoolVecTest]") { (we can't throw exceptions) */ testVector[4] = 12; CHECK(testVector[2] == 12); - CHECK(testVector.commit() == retval::CATCH_OK); + CHECK(testVector.commit() == result::OK); /* Use read-only reference. */ const lp_vec_t& roTestVec = testVector; @@ -57,7 +57,7 @@ TEST_CASE("LocalPoolVector", "[LocPoolVecTest]") { uint8_t* vecPtr = reinterpret_cast(serializedVector); size_t serSize = 0; REQUIRE(testVector.serialize(&vecPtr, &serSize, maxSize, SerializeIF::Endianness::MACHINE) == - retval::CATCH_OK); + result::OK); CHECK(serSize == 6); CHECK(serializedVector[0] == 5); @@ -74,7 +74,7 @@ TEST_CASE("LocalPoolVector", "[LocPoolVecTest]") { const uint8_t* constVecPtr = reinterpret_cast(serializedVector); REQUIRE(testVector.deSerialize(&constVecPtr, &serSize, SerializeIF::Endianness::MACHINE) == - retval::CATCH_OK); + result::OK); CHECK(testVector[0] == 16); CHECK(testVector[1] == 7832); CHECK(testVector[2] == 39232); diff --git a/unittests/storagemanager/testPool.cpp b/unittests/storagemanager/testPool.cpp index 03cac72a..c3eadf1d 100644 --- a/unittests/storagemanager/testPool.cpp +++ b/unittests/storagemanager/testPool.cpp @@ -25,10 +25,10 @@ TEST_CASE("Local Pool Simple Tests [1 Pool]", "[TestPool]") { SECTION("Basic tests") { REQUIRE(not simplePool.hasDataAtId(testStoreId)); result = simplePool.addData(&testStoreId, testDataArray.data(), size); - REQUIRE(result == retval::CATCH_OK); + REQUIRE(result == result::OK); REQUIRE(simplePool.hasDataAtId(testStoreId)); result = simplePool.getData(testStoreId, &constPointer, &size); - REQUIRE(result == retval::CATCH_OK); + REQUIRE(result == result::OK); memcpy(receptionArray.data(), constPointer, size); for (size_t i = 0; i < size; i++) { CHECK(receptionArray[i] == i); @@ -36,12 +36,12 @@ TEST_CASE("Local Pool Simple Tests [1 Pool]", "[TestPool]") { memset(receptionArray.data(), 0, size); result = simplePool.modifyData(testStoreId, &pointer, &size); memcpy(receptionArray.data(), pointer, size); - REQUIRE(result == retval::CATCH_OK); + REQUIRE(result == result::OK); for (size_t i = 0; i < size; i++) { CHECK(receptionArray[i] == i); } result = simplePool.deleteData(testStoreId); - REQUIRE(result == retval::CATCH_OK); + REQUIRE(result == result::OK); REQUIRE(not simplePool.hasDataAtId(testStoreId)); result = simplePool.addData(&testStoreId, testDataArray.data(), 15); CHECK(result == (int)StorageManagerIF::DATA_TOO_LARGE); @@ -50,12 +50,12 @@ TEST_CASE("Local Pool Simple Tests [1 Pool]", "[TestPool]") { SECTION("Reservation Tests ") { pointer = nullptr; result = simplePool.getFreeElement(&testStoreId, size, &pointer); - REQUIRE(result == retval::CATCH_OK); + REQUIRE(result == result::OK); memcpy(pointer, testDataArray.data(), size); constPointer = nullptr; result = simplePool.getData(testStoreId, &constPointer, &size); - REQUIRE(result == retval::CATCH_OK); + REQUIRE(result == result::OK); memcpy(receptionArray.data(), constPointer, size); for (size_t i = 0; i < size; i++) { CHECK(receptionArray[i] == i); @@ -64,21 +64,21 @@ TEST_CASE("Local Pool Simple Tests [1 Pool]", "[TestPool]") { SECTION("Add, delete, add, add when full") { result = simplePool.addData(&testStoreId, testDataArray.data(), size); - REQUIRE(result == retval::CATCH_OK); + REQUIRE(result == result::OK); result = simplePool.getData(testStoreId, &constPointer, &size); - REQUIRE(result == retval::CATCH_OK); + REQUIRE(result == result::OK); memcpy(receptionArray.data(), constPointer, size); for (size_t i = 0; i < size; i++) { CHECK(receptionArray[i] == i); } result = simplePool.deleteData(testStoreId); - REQUIRE(result == retval::CATCH_OK); + REQUIRE(result == result::OK); result = simplePool.addData(&testStoreId, testDataArray.data(), size); - REQUIRE(result == retval::CATCH_OK); + REQUIRE(result == result::OK); result = simplePool.getData(testStoreId, &constPointer, &size); - REQUIRE(result == retval::CATCH_OK); + REQUIRE(result == result::OK); memcpy(receptionArray.data(), constPointer, size); for (size_t i = 0; i < size; i++) { CHECK(receptionArray[i] == i); @@ -105,20 +105,20 @@ TEST_CASE("Local Pool Simple Tests [1 Pool]", "[TestPool]") { SECTION("Initialize and clear store, delete with pointer") { result = simplePool.initialize(); - REQUIRE(result == retval::CATCH_OK); + REQUIRE(result == result::OK); result = simplePool.addData(&testStoreId, testDataArray.data(), size); - REQUIRE(result == retval::CATCH_OK); + REQUIRE(result == result::OK); simplePool.clearStore(); result = simplePool.addData(&testStoreId, testDataArray.data(), size); - REQUIRE(result == retval::CATCH_OK); + REQUIRE(result == result::OK); result = simplePool.modifyData(testStoreId, &pointer, &size); - REQUIRE(result == retval::CATCH_OK); + REQUIRE(result == result::OK); store_address_t newId; result = simplePool.deleteData(pointer, size, &testStoreId); - REQUIRE(result == retval::CATCH_OK); + REQUIRE(result == result::OK); REQUIRE(testStoreId.raw != (uint32_t)StorageManagerIF::INVALID_ADDRESS); result = simplePool.addData(&testStoreId, testDataArray.data(), size); - REQUIRE(result == retval::CATCH_OK); + REQUIRE(result == result::OK); } } @@ -141,10 +141,10 @@ TEST_CASE("Local Pool Extended Tests [3 Pools]", "[TestPool2]") { runIdx++; LocalPool simplePool(0, *config); - std::array testDataArray; - std::array receptionArray; + std::array testDataArray{}; + std::array receptionArray{}; store_address_t testStoreId; - ReturnValue_t result = retval::CATCH_FAILED; + ReturnValue_t result = result::FAILED; for (size_t i = 0; i < testDataArray.size(); i++) { testDataArray[i] = i; } @@ -153,20 +153,20 @@ TEST_CASE("Local Pool Extended Tests [3 Pools]", "[TestPool2]") { SECTION("Basic tests") { size = 8; result = simplePool.addData(&testStoreId, testDataArray.data(), size); - REQUIRE(result == retval::CATCH_OK); + REQUIRE(result == result::OK); // Should be on second page of the pool now for 8 bytes CHECK(testStoreId.poolIndex == 1); CHECK(testStoreId.packetIndex == 0); size = 15; result = simplePool.addData(&testStoreId, testDataArray.data(), size); - REQUIRE(result == retval::CATCH_OK); + REQUIRE(result == result::OK); // Should be on third page of the pool now for 15 bytes CHECK(testStoreId.poolIndex == 2); CHECK(testStoreId.packetIndex == 0); result = simplePool.addData(&testStoreId, testDataArray.data(), size); - REQUIRE(result == retval::CATCH_OK); + REQUIRE(result == result::OK); // Should be on third page of the pool now for 15 bytes CHECK(testStoreId.poolIndex == 2); CHECK(testStoreId.packetIndex == 1); @@ -177,7 +177,7 @@ TEST_CASE("Local Pool Extended Tests [3 Pools]", "[TestPool2]") { size = 8; result = simplePool.addData(&testStoreId, testDataArray.data(), size); - REQUIRE(result == retval::CATCH_OK); + REQUIRE(result == result::OK); // Should still work CHECK(testStoreId.poolIndex == 1); CHECK(testStoreId.packetIndex == 1); @@ -185,7 +185,7 @@ TEST_CASE("Local Pool Extended Tests [3 Pools]", "[TestPool2]") { // fill the rest of the pool for (uint8_t idx = 2; idx < 5; idx++) { result = simplePool.addData(&testStoreId, testDataArray.data(), size); - REQUIRE(result == retval::CATCH_OK); + REQUIRE(result == result::OK); CHECK(testStoreId.poolIndex == 1); CHECK(testStoreId.packetIndex == idx); } @@ -206,21 +206,21 @@ TEST_CASE("Local Pool Extended Tests [3 Pools]", "[TestPool2]") { size = 5; for (uint8_t idx = 0; idx < 10; idx++) { result = simplePool.addData(&testStoreId, testDataArray.data(), size); - REQUIRE(result == retval::CATCH_OK); + REQUIRE(result == result::OK); CHECK(testStoreId.poolIndex == 0); CHECK(testStoreId.packetIndex == idx); } size = 10; for (uint8_t idx = 0; idx < 5; idx++) { result = simplePool.addData(&testStoreId, testDataArray.data(), size); - REQUIRE(result == retval::CATCH_OK); + REQUIRE(result == result::OK); CHECK(testStoreId.poolIndex == 1); CHECK(testStoreId.packetIndex == idx); } size = 20; for (uint8_t idx = 0; idx < 2; idx++) { result = simplePool.addData(&testStoreId, testDataArray.data(), size); - REQUIRE(result == retval::CATCH_OK); + REQUIRE(result == result::OK); CHECK(testStoreId.poolIndex == 2); CHECK(testStoreId.packetIndex == idx); } @@ -247,7 +247,7 @@ TEST_CASE("Local Pool Extended Tests [3 Pools]", "[TestPool2]") { size = 5; for (uint8_t idx = 0; idx < 10; idx++) { result = simplePool.addData(&testStoreId, testDataArray.data(), size); - REQUIRE(result == retval::CATCH_OK); + REQUIRE(result == result::OK); CHECK(testStoreId.poolIndex == 0); CHECK(testStoreId.packetIndex == idx); } @@ -264,7 +264,7 @@ TEST_CASE("Local Pool Extended Tests [3 Pools]", "[TestPool2]") { size = 10; for (uint8_t idx = 0; idx < 5; idx++) { result = simplePool.addData(&testStoreId, testDataArray.data(), size); - REQUIRE(result == retval::CATCH_OK); + REQUIRE(result == result::OK); CHECK(testStoreId.poolIndex == 1); CHECK(testStoreId.packetIndex == idx); } diff --git a/unittests/tmtcpacket/testZcTmWriter.cpp b/unittests/tmtcpacket/testZcTmWriter.cpp index 366697d1..c26b0069 100644 --- a/unittests/tmtcpacket/testZcTmWriter.cpp +++ b/unittests/tmtcpacket/testZcTmWriter.cpp @@ -18,6 +18,6 @@ TEST_CASE("TM ZC Helper", "[tm-zc-helper]") { SECTION("Basic") { REQUIRE(creator.serialize(dataPtr, serLen, buf.size()) == result::OK); - PusTmZeroCopyWriter() + PusTmZeroCopyWriter(timeStamper, dataPtr, serLen); } } \ No newline at end of file diff --git a/unittests/tmtcservices/testPsb.cpp b/unittests/tmtcservices/testPsb.cpp index 9404c401..464fb3da 100644 --- a/unittests/tmtcservices/testPsb.cpp +++ b/unittests/tmtcservices/testPsb.cpp @@ -49,19 +49,19 @@ TEST_CASE("Pus Service Base", "[pus-service-base]") { SECTION("Perform Service") { REQUIRE(psb.performServiceCallCnt == 0); - REQUIRE(psb.performOperation(0) == retval::OK); + REQUIRE(psb.performOperation(0) == result::OK); REQUIRE(psb.performServiceCallCnt == 1); } SECTION("Send Request with Successful Handling") { REQUIRE(psb.performServiceCallCnt == 0); uint8_t* dataPtr; - REQUIRE(pool.getFreeElement(&storeId, creator.getSerializedSize(), &dataPtr) == retval::OK); + REQUIRE(pool.getFreeElement(&storeId, creator.getSerializedSize(), &dataPtr) == result::OK); size_t serLen = 0; - REQUIRE(creator.serializeBe(dataPtr, serLen, creator.getSerializedSize()) == retval::OK); + REQUIRE(creator.serializeBe(dataPtr, serLen, creator.getSerializedSize()) == result::OK); tmtcMsg.setStorageId(storeId); msgQueue.addReceivedMessage(tmtcMsg); - REQUIRE(psb.performOperation(0) == retval::OK); + REQUIRE(psb.performOperation(0) == result::OK); uint8_t subservice = 0; REQUIRE(psb.getAndPopNextSubservice(subservice)); REQUIRE(subservice == 1); @@ -77,13 +77,13 @@ TEST_CASE("Pus Service Base", "[pus-service-base]") { SECTION("Send Request with Failed Handling") { uint8_t* dataPtr; - REQUIRE(pool.getFreeElement(&storeId, creator.getSerializedSize(), &dataPtr) == retval::OK); + REQUIRE(pool.getFreeElement(&storeId, creator.getSerializedSize(), &dataPtr) == result::OK); size_t serLen = 0; - REQUIRE(creator.serializeBe(dataPtr, serLen, creator.getSerializedSize()) == retval::OK); + REQUIRE(creator.serializeBe(dataPtr, serLen, creator.getSerializedSize()) == result::OK); tmtcMsg.setStorageId(storeId); msgQueue.addReceivedMessage(tmtcMsg); psb.makeNextHandleReqCallFail(3); - REQUIRE(psb.performOperation(0) == retval::OK); + REQUIRE(psb.performOperation(0) == result::OK); uint8_t subservice = 0; REQUIRE(psb.getAndPopNextSubservice(subservice)); REQUIRE(subservice == 1); @@ -100,7 +100,7 @@ TEST_CASE("Pus Service Base", "[pus-service-base]") { SECTION("Invalid Packet Sent") { tmtcMsg.setStorageId(store_address_t::invalid()); msgQueue.addReceivedMessage(tmtcMsg); - REQUIRE(psb.performOperation(0) == retval::OK); + REQUIRE(psb.performOperation(0) == result::OK); REQUIRE(verificationReporter.failCallCount() == 1); auto verifParams = verificationReporter.getNextFailCallParams(); REQUIRE(verifParams.tcPacketId == 0); @@ -147,7 +147,7 @@ TEST_CASE("Pus Service Base", "[pus-service-base]") { psbParams.objectId = 1; auto mockWithOwnerQueue = PsbMock(psbParams); REQUIRE(mockWithOwnerQueue.getRequestQueue() == MessageQueueIF::NO_QUEUE); - REQUIRE(mockWithOwnerQueue.initialize() == retval::OK); + REQUIRE(mockWithOwnerQueue.initialize() == result::OK); REQUIRE(mockWithOwnerQueue.getRequestQueue() != MessageQueueIF::NO_QUEUE); } @@ -190,7 +190,7 @@ TEST_CASE("Pus Service Base", "[pus-service-base]") { auto pusDistrib = PusDistributorMock(distributorId); PsbMock::setStaticPusDistributor(distributorId); REQUIRE(PsbMock::getStaticPusDistributor() == distributorId); - REQUIRE(psb2.initialize() == retval::OK); + REQUIRE(psb2.initialize() == result::OK); REQUIRE(pusDistrib.registerCallCount == 1); REQUIRE(pusDistrib.lastServiceArg == &psb2); } @@ -203,7 +203,7 @@ TEST_CASE("Pus Service Base", "[pus-service-base]") { auto packetDest = AcceptsTmMock(destId, 2); PsbMock::setStaticTmDest(destId); REQUIRE(PsbMock::getStaticTmDest() == destId); - REQUIRE(psb2.initialize() == retval::OK); + REQUIRE(psb2.initialize() == result::OK); auto& p = psb2.getParams(); REQUIRE(p.tmReceiver == &packetDest); } @@ -214,7 +214,7 @@ TEST_CASE("Pus Service Base", "[pus-service-base]") { object_id_t reporterId = objects::TC_VERIFICATOR; PusVerificationReporterMock otherReporter(reporterId); auto psb2 = PsbMock(psbParams); - REQUIRE(psb2.initialize() == retval::OK); + REQUIRE(psb2.initialize() == result::OK); auto& p = psb2.getParams(); REQUIRE(p.verifReporter == &otherReporter); } @@ -224,7 +224,7 @@ TEST_CASE("Pus Service Base", "[pus-service-base]") { psbParams.tcPool = nullptr; psbParams.objectId = 1; auto psb2 = PsbMock(psbParams); - REQUIRE(psb2.initialize() == retval::OK); + REQUIRE(psb2.initialize() == result::OK); auto& p = psb2.getParams(); REQUIRE(p.tcPool == &tcStoreGlobal); } diff --git a/unittests/tmtcservices/testStoreAndSendHelper.cpp b/unittests/tmtcservices/testStoreAndSendHelper.cpp index 73051f8e..048ee092 100644 --- a/unittests/tmtcservices/testStoreAndSendHelper.cpp +++ b/unittests/tmtcservices/testStoreAndSendHelper.cpp @@ -41,13 +41,13 @@ TEST_CASE("TM Store And Send Helper", "[tm-store-send-helper]") { REQUIRE(params.dataWrapper.dataUnion.raw.data == nullptr); REQUIRE(params.dataWrapper.dataUnion.raw.len == 0); REQUIRE(tmHelper.sendCounter == 0); - REQUIRE(tmHelper.storeAndSendTmPacket() == retval::OK); + REQUIRE(tmHelper.storeAndSendTmPacket() == result::OK); REQUIRE(tmHelper.sendCounter == 1); auto storeId = storeHelper.getCurrentAddr(); REQUIRE(msgQueue.wasMessageSent()); REQUIRE(msgQueue.numberOfSentMessagesToDefault() == 1); TmTcMessage msg; - REQUIRE(msgQueue.getNextSentMessage(msg) == retval::OK); + REQUIRE(msgQueue.getNextSentMessage(msg) == result::OK); REQUIRE(msg.getStorageId() == storeId); REQUIRE(pool.hasDataAtId(msg.getStorageId())); storeHelper.deletePacket(); @@ -55,7 +55,7 @@ TEST_CASE("TM Store And Send Helper", "[tm-store-send-helper]") { SECTION("Raw Data Helper") { std::array data = {1, 2, 3}; - REQUIRE(tmHelper.prepareTmPacket(2, data.data(), data.size()) == retval::OK); + REQUIRE(tmHelper.prepareTmPacket(2, data.data(), data.size()) == result::OK); auto& creator = storeHelper.getCreatorRef(); auto& params = creator.getParams(); REQUIRE(params.dataWrapper.type == ecss::DataTypes::RAW); @@ -65,7 +65,7 @@ TEST_CASE("TM Store And Send Helper", "[tm-store-send-helper]") { SECTION("Serializable Helper") { auto simpleSer = SimpleSerializable(); - REQUIRE(tmHelper.prepareTmPacket(2, simpleSer) == retval::OK); + REQUIRE(tmHelper.prepareTmPacket(2, simpleSer) == result::OK); auto& creator = storeHelper.getCreatorRef(); auto& params = creator.getParams(); REQUIRE(params.dataWrapper.type == ecss::DataTypes::SERIALIZABLE); @@ -76,7 +76,7 @@ TEST_CASE("TM Store And Send Helper", "[tm-store-send-helper]") { uint32_t objectId = 0x01020304; std::array data = {1, 2, 3}; telemetry::DataWithObjectIdPrefix dataWithObjId(objectId, data.data(), data.size()); - REQUIRE(tmHelper.prepareTmPacket(2, dataWithObjId) == retval::OK); + REQUIRE(tmHelper.prepareTmPacket(2, dataWithObjId) == result::OK); auto& creator = storeHelper.getCreatorRef(); auto& params = creator.getParams(); REQUIRE(params.dataWrapper.type == ecss::DataTypes::SERIALIZABLE); -- 2.43.0 From cb118176a02ac536bd94173548732319fac11ae8 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Thu, 28 Jul 2022 13:24:50 +0200 Subject: [PATCH 097/108] completed ZcWriter unittests --- src/fsfw/tmtcpacket/pus/tc/PusTcCreator.h | 6 ++++ src/fsfw/tmtcpacket/pus/tm/PusTmCreator.h | 10 +++++++ src/fsfw/tmtcpacket/pus/tm/PusTmReader.cpp | 2 +- src/fsfw/tmtcpacket/pus/tm/PusTmReader.h | 31 ++++++++++++++++++++ src/fsfw/tmtcpacket/pus/tm/PusTmZcWriter.cpp | 6 ++++ src/fsfw/tmtcpacket/pus/tm/PusTmZcWriter.h | 7 +++++ unittests/tmtcpacket/testZcTmWriter.cpp | 21 ++++++++++++- 7 files changed, 81 insertions(+), 2 deletions(-) diff --git a/src/fsfw/tmtcpacket/pus/tc/PusTcCreator.h b/src/fsfw/tmtcpacket/pus/tc/PusTcCreator.h index 63a5d45f..3a51fb68 100644 --- a/src/fsfw/tmtcpacket/pus/tc/PusTcCreator.h +++ b/src/fsfw/tmtcpacket/pus/tc/PusTcCreator.h @@ -19,6 +19,12 @@ struct PusTcParams { uint8_t pusVersion = ecss::PusVersion::PUS_C; }; +/** + * This class provides a high-level interface to create PUS TC packets and then @serialize + * them into a raw byte format. It implements @SerializeIF for that purpose. + * A custom time stamper can be set, with the implementation of @TimeStamperIF as the only + * requirement. + */ class PusTcCreator : public PusTcIF, public SerializeIF, public CustomUserDataIF { public: PusTcCreator(SpacePacketParams initSpParams, PusTcParams initPusParams); diff --git a/src/fsfw/tmtcpacket/pus/tm/PusTmCreator.h b/src/fsfw/tmtcpacket/pus/tm/PusTmCreator.h index a7905858..9f3dcd24 100644 --- a/src/fsfw/tmtcpacket/pus/tm/PusTmCreator.h +++ b/src/fsfw/tmtcpacket/pus/tm/PusTmCreator.h @@ -39,8 +39,18 @@ struct PusTmParams { class TimeStamperIF; +/** + * This class provides a high-level interface to create PUS TM packets and then @serialize + * them into a raw byte format. It implements @SerializeIF for that purpose. + * A custom time stamper can be set, with the implementation of @TimeStamperIF as the only + * requirement. + */ class PusTmCreator : public SerializeIF, public PusTmIF, public CustomUserDataIF { public: + /** + * Empty creator with all-default parameters. Please note that serializing this will + * generate an invalid PUS packet with no timestamp. + */ PusTmCreator(); PusTmCreator(SpacePacketParams initSpParams, PusTmParams initPusParams); ~PusTmCreator() override = default; diff --git a/src/fsfw/tmtcpacket/pus/tm/PusTmReader.cpp b/src/fsfw/tmtcpacket/pus/tm/PusTmReader.cpp index ca40562b..75abdbf6 100644 --- a/src/fsfw/tmtcpacket/pus/tm/PusTmReader.cpp +++ b/src/fsfw/tmtcpacket/pus/tm/PusTmReader.cpp @@ -86,6 +86,6 @@ ReturnValue_t PusTmReader::parseData(bool crcCheck) { } return HasReturnvaluesIF::RETURN_OK; } -bool PusTmReader::isNull() const { return spReader.isNull(); } +bool PusTmReader::isNull() const { return spReader.isNull() or pointers.secHeaderStart == nullptr; } PusTmReader::operator bool() const { return not isNull(); } diff --git a/src/fsfw/tmtcpacket/pus/tm/PusTmReader.h b/src/fsfw/tmtcpacket/pus/tm/PusTmReader.h index c95fefae..c12bb4c8 100644 --- a/src/fsfw/tmtcpacket/pus/tm/PusTmReader.h +++ b/src/fsfw/tmtcpacket/pus/tm/PusTmReader.h @@ -8,6 +8,18 @@ #include "fsfw/tmtcpacket/pus/RawUserDataReaderIF.h" #include "fsfw/tmtcpacket/pus/tm/PusTmIF.h" +/** + * This object can be used to read existing PUS TM packets in raw byte format. + * It is a zero-copy object, so reading a TM packet with will not copy anything. + * + * Please note that a parser function must be called after the constructor. This will also check + * the packet for validity. + * + * There are two parser function, where one does not perform the CRC check. This is useful + * if the CRC calculation will is performed in a separate step. + * This object also requires an explicit time stamp reader to allow flexibility in the used + * timestamp. + */ class PusTmReader : public PusTmIF, public RawUserDataReaderIF, public ReadablePacketIF, @@ -17,11 +29,30 @@ class PusTmReader : public PusTmIF, PusTmReader(const uint8_t* data, size_t size); PusTmReader(TimeReaderIF* timeReader, const uint8_t* data, size_t size); + /** + * No CRC check will be performed + * @return + */ ReturnValue_t parseDataWithoutCrcCheck(); + /** + * Performs a CRC check on the data as well + * @return + * - HasReturnvaluesIF::RETURN_OK: Successfully parsed the packet + * - SerializeIF::STREAM_TOO_SHORT: Stream too short for detected packet size + * - PusIF::INVALID_CRC_16 on invalid CRC + */ ReturnValue_t parseDataWithCrcCheck(); [[nodiscard]] const uint8_t* getFullData() const override; + /** + * Returns @isNull + * @return + */ explicit operator bool() const; + /** + * No (valid) data was set yet or the parse function was not called yet. + * @return + */ [[nodiscard]] bool isNull() const; void setTimeReader(TimeReaderIF* timeReader); TimeReaderIF* getTimeReader(); diff --git a/src/fsfw/tmtcpacket/pus/tm/PusTmZcWriter.cpp b/src/fsfw/tmtcpacket/pus/tm/PusTmZcWriter.cpp index 6ca78378..6a9f6235 100644 --- a/src/fsfw/tmtcpacket/pus/tm/PusTmZcWriter.cpp +++ b/src/fsfw/tmtcpacket/pus/tm/PusTmZcWriter.cpp @@ -6,12 +6,18 @@ PusTmZeroCopyWriter::PusTmZeroCopyWriter(TimeReaderIF& timeReader, uint8_t* data : PusTmReader(&timeReader, data, size) {} void PusTmZeroCopyWriter::setSequenceCount(uint16_t seqCount) { + if (isNull()) { + return; + } auto* spHeader = reinterpret_cast(const_cast((pointers.spHeaderStart))); ccsds::setSequenceCount(*spHeader, seqCount); } void PusTmZeroCopyWriter::updateErrorControl() { + if (isNull()) { + return; + } auto* crcStart = const_cast((pointers.crcStart)); uint16_t crc16 = CRC::crc16ccitt(PusTmReader::getFullData(), getFullPacketLen() - sizeof(ecss::PusChecksumT)); diff --git a/src/fsfw/tmtcpacket/pus/tm/PusTmZcWriter.h b/src/fsfw/tmtcpacket/pus/tm/PusTmZcWriter.h index 331bda7f..36c43f51 100644 --- a/src/fsfw/tmtcpacket/pus/tm/PusTmZcWriter.h +++ b/src/fsfw/tmtcpacket/pus/tm/PusTmZcWriter.h @@ -2,6 +2,13 @@ #define FSFW_EXAMPLE_HOSTED_PUSTMZCWRITER_H #include "PusTmReader.h" + +/** + * This packet allows to update specific fields of a PUS TM packet where it is useful or necessary + * to update them in a second step. Otherwise, it offers the same interface as @PusTmReader. + * + * Right now, this class supports updating the CCSDS Sequence Count and the Error Control. + */ class PusTmZeroCopyWriter : public PusTmReader { public: PusTmZeroCopyWriter(TimeReaderIF& timeReader, uint8_t* data, size_t size); diff --git a/unittests/tmtcpacket/testZcTmWriter.cpp b/unittests/tmtcpacket/testZcTmWriter.cpp index c26b0069..fc013590 100644 --- a/unittests/tmtcpacket/testZcTmWriter.cpp +++ b/unittests/tmtcpacket/testZcTmWriter.cpp @@ -1,5 +1,6 @@ #include +#include "fsfw/globalfunctions/CRC.h" #include "fsfw/tmtcpacket/pus/tm.h" #include "fsfw/tmtcpacket/pus/tm/PusTmZcWriter.h" #include "mocks/CdsShortTimestamperMock.h" @@ -16,8 +17,26 @@ TEST_CASE("TM ZC Helper", "[tm-zc-helper]") { uint8_t* dataPtr = buf.data(); size_t serLen = 0; + SECTION("No Crash For Uninitialized Object") { + REQUIRE(creator.serialize(dataPtr, serLen, buf.size()) == result::OK); + PusTmZeroCopyWriter writer(timeStamper, dataPtr, serLen); + REQUIRE(writer.getSequenceCount() == 22); + writer.setSequenceCount(23); + // Can't set anything, parse function was not called + REQUIRE(writer.getSequenceCount() == 22); + writer.updateErrorControl(); + } + SECTION("Basic") { REQUIRE(creator.serialize(dataPtr, serLen, buf.size()) == result::OK); - PusTmZeroCopyWriter(timeStamper, dataPtr, serLen); + PusTmZeroCopyWriter writer(timeStamper, dataPtr, serLen); + REQUIRE(writer.parseDataWithoutCrcCheck() == result::OK); + REQUIRE(writer.getSequenceCount() == 22); + writer.setSequenceCount(23); + REQUIRE(writer.getSequenceCount() == 23); + // CRC is invalid now + REQUIRE(CRC::crc16ccitt(dataPtr, serLen) != 0); + writer.updateErrorControl(); + REQUIRE(CRC::crc16ccitt(dataPtr, serLen) == 0); } } \ No newline at end of file -- 2.43.0 From 1b5fa2a8fa4692f83738aa76a06b123b3874f91d Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Thu, 28 Jul 2022 13:37:07 +0200 Subject: [PATCH 098/108] test no crc generation --- unittests/tmtcpacket/testPusTmCreator.cpp | 9 +++++++++ unittests/tmtcpacket/testPusTmReader.cpp | 5 +++-- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/unittests/tmtcpacket/testPusTmCreator.cpp b/unittests/tmtcpacket/testPusTmCreator.cpp index 99c16550..4561a022 100644 --- a/unittests/tmtcpacket/testPusTmCreator.cpp +++ b/unittests/tmtcpacket/testPusTmCreator.cpp @@ -146,4 +146,13 @@ TEST_CASE("PUS TM Creator", "[pus-tm-creator]") { SerializeIF::BUFFER_TOO_SHORT); } } + + SECTION("No CRC Generation") { + creator.disableCrcCalculation(); + REQUIRE(not creator.crcCalculationEnabled()); + REQUIRE(creator.serialize(dataPtr, serLen, buf.size()) == HasReturnvaluesIF::RETURN_OK); + REQUIRE(serLen == 22); + REQUIRE(buf[20] == 0x00); + REQUIRE(buf[21] == 0x00); + } } \ No newline at end of file diff --git a/unittests/tmtcpacket/testPusTmReader.cpp b/unittests/tmtcpacket/testPusTmReader.cpp index 3914db48..7967dba6 100644 --- a/unittests/tmtcpacket/testPusTmReader.cpp +++ b/unittests/tmtcpacket/testPusTmReader.cpp @@ -38,9 +38,10 @@ TEST_CASE("PUS TM Reader", "[pus-tm-reader]") { readerPtr->setTimeReader(&timeStamperAndReader); deleteReader = true; } - REQUIRE(readerPtr); - REQUIRE(not readerPtr->isNull()); + REQUIRE(not *readerPtr); + REQUIRE(readerPtr->isNull()); REQUIRE(readerPtr->parseDataWithCrcCheck() == HasReturnvaluesIF::RETURN_OK); + REQUIRE(not readerPtr->isNull()); REQUIRE(readerPtr->getService() == 17); REQUIRE(readerPtr->getSubService() == 2); REQUIRE(readerPtr->getApid() == 0xef); -- 2.43.0 From 8f6f0e1d458236219f6570e0212d58dbc5de14da Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Thu, 28 Jul 2022 13:42:34 +0200 Subject: [PATCH 099/108] some more fail tests --- src/fsfw/tmtcservices/TmStoreAndSendHelper.cpp | 6 ++++++ unittests/tmtcservices/testStoreAndSendHelper.cpp | 7 +++++++ 2 files changed, 13 insertions(+) diff --git a/src/fsfw/tmtcservices/TmStoreAndSendHelper.cpp b/src/fsfw/tmtcservices/TmStoreAndSendHelper.cpp index cab6db44..7d4c61d6 100644 --- a/src/fsfw/tmtcservices/TmStoreAndSendHelper.cpp +++ b/src/fsfw/tmtcservices/TmStoreAndSendHelper.cpp @@ -6,6 +6,12 @@ TmStoreAndSendWrapper::TmStoreAndSendWrapper(uint8_t defaultService, TmStoreHelp TmSendHelper& sendHelper) : storeHelper(storeHelper), sendHelper(sendHelper), defaultService(defaultService) {} +/** + * Helper wrapper which stores the TM packet into the store and then sends it. + * @return + * - StorageManagerIF returnvalue if storage fails + * - MessageQueueIF returnvalue if sending fails + */ ReturnValue_t TmStoreAndSendWrapper::storeAndSendTmPacket() { ReturnValue_t result = storeHelper.addPacketToStore(); if (result != HasReturnvaluesIF::RETURN_OK) { diff --git a/unittests/tmtcservices/testStoreAndSendHelper.cpp b/unittests/tmtcservices/testStoreAndSendHelper.cpp index 048ee092..1163c33d 100644 --- a/unittests/tmtcservices/testStoreAndSendHelper.cpp +++ b/unittests/tmtcservices/testStoreAndSendHelper.cpp @@ -31,6 +31,13 @@ TEST_CASE("TM Store And Send Helper", "[tm-store-send-helper]") { CHECK(&tmHelper.storeHelper == &storeHelper); } + SECTION("Storage Fails") { + // Too large to fit in store + std::array data{}; + REQUIRE(storeHelper.setSourceDataRaw(data.data(), data.size()) == result::OK); + REQUIRE(tmHelper.storeAndSendTmPacket() == StorageManagerIF::DATA_TOO_LARGE); + } + SECTION("Base Test") { tmHelper.prepareTmPacket(2); auto& creator = storeHelper.getCreatorRef(); -- 2.43.0 From fc3412fa35eb16fb8544c3c99bd202cbee463a1e Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Thu, 28 Jul 2022 15:13:27 +0200 Subject: [PATCH 100/108] set sec header flag and add unit test for it --- src/fsfw/cfdp/CFDPMessage.cpp | 17 ------------- src/fsfw/cfdp/CMakeLists.txt | 2 +- .../cfdp/{CFDPHandler.cpp => CfdpHandler.cpp} | 24 +++++++++--------- .../cfdp/{CFDPHandler.h => CfdpHandler.h} | 6 ++--- src/fsfw/cfdp/CfdpMessage.cpp | 17 +++++++++++++ .../cfdp/{CFDPMessage.h => CfdpMessage.h} | 6 ++--- src/fsfw/storagemanager/PoolManager.cpp | 4 +-- src/fsfw/tcdistribution/CFDPDistributor.cpp | 2 +- .../tmtcpacket/ccsds/SpacePacketCreator.cpp | 2 ++ .../tmtcpacket/ccsds/SpacePacketCreator.h | 1 + src/fsfw/tmtcpacket/pus/tc/PusTcCreator.cpp | 8 ++++-- src/fsfw/tmtcpacket/pus/tc/PusTcCreator.h | 1 + src/fsfw/tmtcpacket/pus/tm/PusTmCreator.cpp | 1 + unittests/tmtcpacket/testPusTcCreator.cpp | 23 +++++++++-------- unittests/tmtcpacket/testPusTmCreator.cpp | 25 ++++++++++--------- 15 files changed, 75 insertions(+), 64 deletions(-) delete mode 100644 src/fsfw/cfdp/CFDPMessage.cpp rename src/fsfw/cfdp/{CFDPHandler.cpp => CfdpHandler.cpp} (66%) rename src/fsfw/cfdp/{CFDPHandler.h => CfdpHandler.h} (92%) create mode 100644 src/fsfw/cfdp/CfdpMessage.cpp rename src/fsfw/cfdp/{CFDPMessage.h => CfdpMessage.h} (89%) diff --git a/src/fsfw/cfdp/CFDPMessage.cpp b/src/fsfw/cfdp/CFDPMessage.cpp deleted file mode 100644 index da6fe15b..00000000 --- a/src/fsfw/cfdp/CFDPMessage.cpp +++ /dev/null @@ -1,17 +0,0 @@ -#include "CFDPMessage.h" - -CFDPMessage::CFDPMessage() {} - -CFDPMessage::~CFDPMessage() {} - -void CFDPMessage::setCommand(CommandMessage *message, store_address_t cfdpPacket) { - message->setParameter(cfdpPacket.raw); -} - -store_address_t CFDPMessage::getStoreId(const CommandMessage *message) { - store_address_t storeAddressCFDPPacket; - storeAddressCFDPPacket = static_cast(message->getParameter()); - return storeAddressCFDPPacket; -} - -void CFDPMessage::clear(CommandMessage *message) {} diff --git a/src/fsfw/cfdp/CMakeLists.txt b/src/fsfw/cfdp/CMakeLists.txt index 0b926a9a..f2affbb4 100644 --- a/src/fsfw/cfdp/CMakeLists.txt +++ b/src/fsfw/cfdp/CMakeLists.txt @@ -1,4 +1,4 @@ -target_sources(${LIB_FSFW_NAME} PRIVATE CFDPHandler.cpp CFDPMessage.cpp) +target_sources(${LIB_FSFW_NAME} PRIVATE CfdpHandler.cpp CfdpMessage.cpp) add_subdirectory(pdu) add_subdirectory(tlv) diff --git a/src/fsfw/cfdp/CFDPHandler.cpp b/src/fsfw/cfdp/CfdpHandler.cpp similarity index 66% rename from src/fsfw/cfdp/CFDPHandler.cpp rename to src/fsfw/cfdp/CfdpHandler.cpp index 96baa98c..caa64f56 100644 --- a/src/fsfw/cfdp/CFDPHandler.cpp +++ b/src/fsfw/cfdp/CfdpHandler.cpp @@ -1,24 +1,24 @@ -#include "fsfw/cfdp/CFDPHandler.h" +#include "fsfw/cfdp/CfdpHandler.h" -#include "fsfw/cfdp/CFDPMessage.h" +#include "fsfw/cfdp/CfdpMessage.h" #include "fsfw/ipc/CommandMessage.h" #include "fsfw/ipc/QueueFactory.h" #include "fsfw/objectmanager/ObjectManager.h" #include "fsfw/storagemanager/storeAddress.h" #include "fsfw/tmtcservices/AcceptsTelemetryIF.h" -object_id_t CFDPHandler::packetSource = 0; -object_id_t CFDPHandler::packetDestination = 0; +object_id_t CfdpHandler::packetSource = 0; +object_id_t CfdpHandler::packetDestination = 0; -CFDPHandler::CFDPHandler(object_id_t setObjectId, CFDPDistributor* dist) +CfdpHandler::CfdpHandler(object_id_t setObjectId, CFDPDistributor* dist) : SystemObject(setObjectId) { requestQueue = QueueFactory::instance()->createMessageQueue(CFDP_HANDLER_MAX_RECEPTION); distributor = dist; } -CFDPHandler::~CFDPHandler() {} +CfdpHandler::~CfdpHandler() = default; -ReturnValue_t CFDPHandler::initialize() { +ReturnValue_t CfdpHandler::initialize() { ReturnValue_t result = SystemObject::initialize(); if (result != RETURN_OK) { return result; @@ -27,7 +27,7 @@ ReturnValue_t CFDPHandler::initialize() { return HasReturnvaluesIF::RETURN_OK; } -ReturnValue_t CFDPHandler::handleRequest(store_address_t storeId) { +ReturnValue_t CfdpHandler::handleRequest(store_address_t storeId) { #if FSFW_VERBOSE_LEVEL >= 1 #if FSFW_CPP_OSTREAM_ENABLED == 1 sif::debug << "CFDPHandler::handleRequest" << std::endl; @@ -41,17 +41,17 @@ ReturnValue_t CFDPHandler::handleRequest(store_address_t storeId) { return RETURN_OK; } -ReturnValue_t CFDPHandler::performOperation(uint8_t opCode) { +ReturnValue_t CfdpHandler::performOperation(uint8_t opCode) { ReturnValue_t status = RETURN_OK; CommandMessage currentMessage; for (status = this->requestQueue->receiveMessage(¤tMessage); status == RETURN_OK; status = this->requestQueue->receiveMessage(¤tMessage)) { - store_address_t storeId = CFDPMessage::getStoreId(¤tMessage); + store_address_t storeId = CfdpMessage::getStoreId(¤tMessage); this->handleRequest(storeId); } return RETURN_OK; } -uint16_t CFDPHandler::getIdentifier() { return 0; } +uint16_t CfdpHandler::getIdentifier() { return 0; } -MessageQueueId_t CFDPHandler::getRequestQueue() { return this->requestQueue->getId(); } +MessageQueueId_t CfdpHandler::getRequestQueue() { return this->requestQueue->getId(); } diff --git a/src/fsfw/cfdp/CFDPHandler.h b/src/fsfw/cfdp/CfdpHandler.h similarity index 92% rename from src/fsfw/cfdp/CFDPHandler.h rename to src/fsfw/cfdp/CfdpHandler.h index 3e6f0429..01399e98 100644 --- a/src/fsfw/cfdp/CFDPHandler.h +++ b/src/fsfw/cfdp/CfdpHandler.h @@ -12,18 +12,18 @@ namespace Factory { void setStaticFrameworkObjectIds(); } -class CFDPHandler : public ExecutableObjectIF, +class CfdpHandler : public ExecutableObjectIF, public AcceptsTelecommandsIF, public SystemObject, public HasReturnvaluesIF { friend void(Factory::setStaticFrameworkObjectIds)(); public: - CFDPHandler(object_id_t setObjectId, CFDPDistributor* distributor); + CfdpHandler(object_id_t setObjectId, CFDPDistributor* distributor); /** * The destructor is empty. */ - virtual ~CFDPHandler(); + virtual ~CfdpHandler(); virtual ReturnValue_t handleRequest(store_address_t storeId); diff --git a/src/fsfw/cfdp/CfdpMessage.cpp b/src/fsfw/cfdp/CfdpMessage.cpp new file mode 100644 index 00000000..ea4e2c98 --- /dev/null +++ b/src/fsfw/cfdp/CfdpMessage.cpp @@ -0,0 +1,17 @@ +#include "CfdpMessage.h" + +CfdpMessage::CfdpMessage() = default; + +CfdpMessage::~CfdpMessage() = default; + +void CfdpMessage::setCommand(CommandMessage *message, store_address_t cfdpPacket) { + message->setParameter(cfdpPacket.raw); +} + +store_address_t CfdpMessage::getStoreId(const CommandMessage *message) { + store_address_t storeId; + storeId = static_cast(message->getParameter()); + return storeId; +} + +void CfdpMessage::clear(CommandMessage *message) {} diff --git a/src/fsfw/cfdp/CFDPMessage.h b/src/fsfw/cfdp/CfdpMessage.h similarity index 89% rename from src/fsfw/cfdp/CFDPMessage.h rename to src/fsfw/cfdp/CfdpMessage.h index 3de723eb..a3ee9421 100644 --- a/src/fsfw/cfdp/CFDPMessage.h +++ b/src/fsfw/cfdp/CfdpMessage.h @@ -5,14 +5,14 @@ #include "fsfw/objectmanager/ObjectManagerIF.h" #include "fsfw/storagemanager/StorageManagerIF.h" -class CFDPMessage { +class CfdpMessage { private: - CFDPMessage(); + CfdpMessage(); public: static const uint8_t MESSAGE_ID = messagetypes::CFDP; - virtual ~CFDPMessage(); + virtual ~CfdpMessage(); static void setCommand(CommandMessage* message, store_address_t cfdpPacket); static store_address_t getStoreId(const CommandMessage* message); diff --git a/src/fsfw/storagemanager/PoolManager.cpp b/src/fsfw/storagemanager/PoolManager.cpp index 92de1dfe..41e140b2 100644 --- a/src/fsfw/storagemanager/PoolManager.cpp +++ b/src/fsfw/storagemanager/PoolManager.cpp @@ -7,7 +7,7 @@ PoolManager::PoolManager(object_id_t setObjectId, const LocalPoolConfig& localPo mutex = MutexFactory::instance()->createMutex(); } -PoolManager::~PoolManager(void) { MutexFactory::instance()->deleteMutex(mutex); } +PoolManager::~PoolManager() { MutexFactory::instance()->deleteMutex(mutex); } ReturnValue_t PoolManager::reserveSpace(const size_t size, store_address_t* address, bool ignoreFault) { @@ -17,7 +17,7 @@ ReturnValue_t PoolManager::reserveSpace(const size_t size, store_address_t* addr } ReturnValue_t PoolManager::deleteData(store_address_t storeId) { -#if FSFW_VERBOSE_LEVEL >= 2 +#if FSFW_VERBOSE_LEVEL >= 2 && FSFW_OBJ_EVENT_TRANSLATION == 1 #if FSFW_CPP_OSTREAM_ENABLED == 1 sif::debug << "PoolManager( " << translateObject(getObjectId()) << " )::deleteData from store " << storeId.poolIndex << ". id is " << storeId.packetIndex << std::endl; diff --git a/src/fsfw/tcdistribution/CFDPDistributor.cpp b/src/fsfw/tcdistribution/CFDPDistributor.cpp index 0e6f968c..d7a02793 100644 --- a/src/fsfw/tcdistribution/CFDPDistributor.cpp +++ b/src/fsfw/tcdistribution/CFDPDistributor.cpp @@ -72,7 +72,7 @@ CFDPDistributor::TcMqMapIter CFDPDistributor::selectDestination() { ReturnValue_t CFDPDistributor::registerHandler(AcceptsTelecommandsIF* handler) { uint16_t handlerId = - handler->getIdentifier(); // should be 0, because CFDPHandler does not set a set a service-ID + handler->getIdentifier(); // should be 0, because CfdpHandler does not set a set a service-ID #if FSFW_CFDP_DISTRIBUTOR_DEBUGGING == 1 #if FSFW_CPP_OSTREAM_ENABLED == 1 sif::info << "CFDPDistributor::registerHandler: Handler ID: " << static_cast(handlerId) diff --git a/src/fsfw/tmtcpacket/ccsds/SpacePacketCreator.cpp b/src/fsfw/tmtcpacket/ccsds/SpacePacketCreator.cpp index 20c9341f..ee27cc9b 100644 --- a/src/fsfw/tmtcpacket/ccsds/SpacePacketCreator.cpp +++ b/src/fsfw/tmtcpacket/ccsds/SpacePacketCreator.cpp @@ -83,3 +83,5 @@ void SpacePacketCreator::setPacketType(ccsds::PacketType type) { bool SpacePacketCreator::operator==(const SpacePacketCreator &other) const { return false; } SpacePacketCreator::operator bool() const { return isValid(); } + +void SpacePacketCreator::setSecHeaderFlag() { params.packetId.secHeaderFlag = true; } diff --git a/src/fsfw/tmtcpacket/ccsds/SpacePacketCreator.h b/src/fsfw/tmtcpacket/ccsds/SpacePacketCreator.h index 9c13bd5a..5869560d 100644 --- a/src/fsfw/tmtcpacket/ccsds/SpacePacketCreator.h +++ b/src/fsfw/tmtcpacket/ccsds/SpacePacketCreator.h @@ -39,6 +39,7 @@ class SpacePacketCreator : public SpacePacketIF, public SerializeIF { SpacePacketParams &getParams(); void setParams(SpacePacketParams params); + void setSecHeaderFlag(); void setPacketType(ccsds::PacketType type); void setApid(uint16_t apid); void setSeqCount(uint16_t seqCount); diff --git a/src/fsfw/tmtcpacket/pus/tc/PusTcCreator.cpp b/src/fsfw/tmtcpacket/pus/tc/PusTcCreator.cpp index be472051..2e786e6e 100644 --- a/src/fsfw/tmtcpacket/pus/tc/PusTcCreator.cpp +++ b/src/fsfw/tmtcpacket/pus/tc/PusTcCreator.cpp @@ -8,8 +8,7 @@ PusTcCreator::PusTcCreator(SpacePacketParams spParams, PusTcParams pusParams) : spCreator(std::move(spParams)), pusParams(pusParams) { - spCreator.setPacketType(ccsds::PacketType::TC); - updateSpLengthField(); + setup(); } ReturnValue_t PusTcCreator::serialize(uint8_t **buffer, size_t *size, size_t maxSize, @@ -111,3 +110,8 @@ ReturnValue_t PusTcCreator::serialize(uint8_t **buffer, size_t *size, size_t max ReturnValue_t PusTcCreator::serialize(uint8_t *buffer, size_t &serLen, size_t maxSize) const { return SerializeIF::serialize(buffer, serLen, maxSize, SerializeIF::Endianness::NETWORK); } +void PusTcCreator::setup() { + spCreator.setPacketType(ccsds::PacketType::TC); + spCreator.setSecHeaderFlag(); + updateSpLengthField(); +} diff --git a/src/fsfw/tmtcpacket/pus/tc/PusTcCreator.h b/src/fsfw/tmtcpacket/pus/tc/PusTcCreator.h index 3a51fb68..ea6c1d58 100644 --- a/src/fsfw/tmtcpacket/pus/tc/PusTcCreator.h +++ b/src/fsfw/tmtcpacket/pus/tc/PusTcCreator.h @@ -61,6 +61,7 @@ class PusTcCreator : public PusTcIF, public SerializeIF, public CustomUserDataIF // Forbidden to use ReturnValue_t deSerialize(const uint8_t **buffer, size_t *size, Endianness streamEndianness) override; + void setup(); SpacePacketCreator spCreator; PusTcParams pusParams; }; diff --git a/src/fsfw/tmtcpacket/pus/tm/PusTmCreator.cpp b/src/fsfw/tmtcpacket/pus/tm/PusTmCreator.cpp index d80182ed..64dbbfeb 100644 --- a/src/fsfw/tmtcpacket/pus/tm/PusTmCreator.cpp +++ b/src/fsfw/tmtcpacket/pus/tm/PusTmCreator.cpp @@ -124,6 +124,7 @@ void PusTmCreator::setApid(uint16_t apid) { spCreator.setApid(apid); } void PusTmCreator::setup() { updateSpLengthField(); spCreator.setPacketType(ccsds::PacketType::TM); + spCreator.setSecHeaderFlag(); } void PusTmCreator::setMessageTypeCounter(uint16_t messageTypeCounter) { diff --git a/unittests/tmtcpacket/testPusTcCreator.cpp b/unittests/tmtcpacket/testPusTcCreator.cpp index ff9b6399..5bc349a6 100644 --- a/unittests/tmtcpacket/testPusTcCreator.cpp +++ b/unittests/tmtcpacket/testPusTcCreator.cpp @@ -16,20 +16,21 @@ TEST_CASE("PUS TC Creator", "[pus-tc-creator]") { size_t serLen = 0; SECTION("State") { - REQUIRE(creator.isTc()); - REQUIRE(creator.getService() == 17); - REQUIRE(creator.getSubService() == 1); - REQUIRE(creator.getApid() == 0x02); - REQUIRE(creator.getPusVersion() == 2); - REQUIRE(creator.getAcknowledgeFlags() == 0b1111); - REQUIRE(creator.getSourceId() == 0x00); - REQUIRE(creator.getPacketSeqCtrlRaw() == 0xc034); + CHECK(creator.isTc()); + CHECK(creator.hasSecHeader()); + CHECK(creator.getService() == 17); + CHECK(creator.getSubService() == 1); + CHECK(creator.getApid() == 0x02); + CHECK(creator.getPusVersion() == 2); + CHECK(creator.getAcknowledgeFlags() == 0b1111); + CHECK(creator.getSourceId() == 0x00); + CHECK(creator.getPacketSeqCtrlRaw() == 0xc034); // bytes CCSDS header, 5 bytes secondary header, 2 bytes CRC, 3 bytes app data - REQUIRE(creator.getFullPacketLen() == 13); + CHECK(creator.getFullPacketLen() == 13); // The data length field is the full packet length minus the primary header minus 1 - REQUIRE(creator.getPacketDataLen() == 6); + CHECK(creator.getPacketDataLen() == 6); auto& paramsLocal = creator.getSpParams(); - REQUIRE(paramsLocal.packetId == packetId); + CHECK(paramsLocal.packetId == packetId); } SECTION("Serialized") { diff --git a/unittests/tmtcpacket/testPusTmCreator.cpp b/unittests/tmtcpacket/testPusTmCreator.cpp index 4561a022..f32e060f 100644 --- a/unittests/tmtcpacket/testPusTmCreator.cpp +++ b/unittests/tmtcpacket/testPusTmCreator.cpp @@ -19,22 +19,23 @@ TEST_CASE("PUS TM Creator", "[pus-tm-creator]") { size_t serLen = 0; SECTION("State") { - REQUIRE(creator.isTm()); - REQUIRE(creator.getApid() == 0xef); - REQUIRE(creator.getPusVersion() == 2); - REQUIRE(creator.getScTimeRefStatus() == 0); - REQUIRE(creator.getService() == 17); - REQUIRE(creator.getSubService() == 2); - REQUIRE(creator.getTimestamper() == &timeStamper); - REQUIRE(creator.getSequenceFlags() == ccsds::SequenceFlags::UNSEGMENTED); - REQUIRE(creator.getSequenceCount() == 22); + CHECK(creator.isTm()); + CHECK(creator.hasSecHeader()); + CHECK(creator.getApid() == 0xef); + CHECK(creator.getPusVersion() == 2); + CHECK(creator.getScTimeRefStatus() == 0); + CHECK(creator.getService() == 17); + CHECK(creator.getSubService() == 2); + CHECK(creator.getTimestamper() == &timeStamper); + CHECK(creator.getSequenceFlags() == ccsds::SequenceFlags::UNSEGMENTED); + CHECK(creator.getSequenceCount() == 22); // 6 bytes CCSDS header, 7 bytes secondary header, 7 bytes CDS short timestamp, // 0 bytes application data, 2 bytes CRC - REQUIRE(creator.getFullPacketLen() == 22); + CHECK(creator.getFullPacketLen() == 22); // As specified in standard, the data length fields is the total size of the packet without // the primary header minus 1 - REQUIRE(creator.getPacketDataLen() == 15); - REQUIRE(timeStamper.getSizeCallCount == 1); + CHECK(creator.getPacketDataLen() == 15); + CHECK(timeStamper.getSizeCallCount == 1); } SECTION("SP Params") { -- 2.43.0 From da106fd96ffc9e59d95b514eb5d7eaf281f013ae Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Fri, 29 Jul 2022 10:23:59 +0200 Subject: [PATCH 101/108] do not use TC info for failed TC retrieval --- .../tmtcservices/CommandingServiceBase.cpp | 43 +++++++++++++++---- src/fsfw/tmtcservices/CommandingServiceBase.h | 20 +++++++-- .../tmtcservices/VerificationReporterIF.h | 22 +++++++--- 3 files changed, 69 insertions(+), 16 deletions(-) diff --git a/src/fsfw/tmtcservices/CommandingServiceBase.cpp b/src/fsfw/tmtcservices/CommandingServiceBase.cpp index ded92926..d7e3b514 100644 --- a/src/fsfw/tmtcservices/CommandingServiceBase.cpp +++ b/src/fsfw/tmtcservices/CommandingServiceBase.cpp @@ -267,8 +267,7 @@ void CommandingServiceBase::handleRequestQueue() { address = message.getStorageId(); result = setUpTcReader(address); if (result != HasReturnvaluesIF::RETURN_OK) { - // TODO: Warning? - rejectPacket(tcverif::START_FAILURE, address, result); + rejectPacketInvalidTc(result, address); continue; } if ((tcReader.getSubService() == 0) or @@ -384,15 +383,29 @@ void CommandingServiceBase::startExecution(store_address_t storeId, CommandMapIt } } -void CommandingServiceBase::rejectPacket(uint8_t reportId, store_address_t tcStoreId, - ReturnValue_t errorCode) { - verificationReporter->sendFailureReport(VerifFailureParams(reportId, tcReader, errorCode)); - tcStore->deleteData(tcStoreId); +ReturnValue_t CommandingServiceBase::rejectPacketInvalidTc(ReturnValue_t errorCode, + store_address_t tcStoreId) { + failureParameter1 = INVALID_TC; + prepareVerificationFailureWithNoTcInfo(tcverif::START_FAILURE, errorCode, true); + if (tcStoreId != store_address_t::invalid()) { + tcStore->deleteData(tcStoreId); + } + return verificationReporter->sendFailureReport(failParams); } -void CommandingServiceBase::acceptPacket(uint8_t reportId, store_address_t tcStoreId) { - verificationReporter->sendSuccessReport(VerifSuccessParams(reportId, tcReader)); +ReturnValue_t CommandingServiceBase::rejectPacket(uint8_t reportId, store_address_t tcStoreId, + ReturnValue_t errorCode) { + ReturnValue_t result = + verificationReporter->sendFailureReport(VerifFailureParams(reportId, tcReader, errorCode)); tcStore->deleteData(tcStoreId); + return result; +} + +ReturnValue_t CommandingServiceBase::acceptPacket(uint8_t reportId, store_address_t tcStoreId) { + ReturnValue_t result = + verificationReporter->sendSuccessReport(VerifSuccessParams(reportId, tcReader)); + tcStore->deleteData(tcStoreId); + return result; } void CommandingServiceBase::checkAndExecuteFifo(CommandMapIter& iter) { @@ -437,10 +450,23 @@ void CommandingServiceBase::setTaskIF(PeriodicTaskIF* task_) { executingTask = t void CommandingServiceBase::setCustomTmStore(StorageManagerIF& store) { tmStoreHelper.setTmStore(store); } + ReturnValue_t CommandingServiceBase::setUpTcReader(store_address_t storeId) { return tc::prepareTcReader(*tcStore, storeId, tcReader); } +void CommandingServiceBase::prepareVerificationFailureWithNoTcInfo(uint8_t reportId, + ReturnValue_t errorCode, + bool setCachedFailParams) { + failParams.resetTcFields(); + failParams.resetFailParams(); + failParams.reportId = reportId; + failParams.errorCode = errorCode; + if (setCachedFailParams) { + failParams.errorParam1 = failureParameter1; + failParams.errorParam2 = failureParameter2; + } +} void CommandingServiceBase::prepareVerificationFailureWithFullInfo(uint8_t reportId, CommandInfo::TcInfo& tcInfo, ReturnValue_t errorCode, @@ -449,6 +475,7 @@ void CommandingServiceBase::prepareVerificationFailureWithFullInfo(uint8_t repor failParams.tcPacketId = tcInfo.tcPacketId; failParams.tcPsc = tcInfo.tcSequenceControl; failParams.ackFlags = tcInfo.ackFlags; + failParams.resetFailParams(); failParams.errorCode = errorCode; if (setCachedFailParams) { failParams.errorParam1 = failureParameter1; diff --git a/src/fsfw/tmtcservices/CommandingServiceBase.h b/src/fsfw/tmtcservices/CommandingServiceBase.h index f9070d17..c16d9ded 100644 --- a/src/fsfw/tmtcservices/CommandingServiceBase.h +++ b/src/fsfw/tmtcservices/CommandingServiceBase.h @@ -52,7 +52,13 @@ class CommandingServiceBase : public SystemObject, static const ReturnValue_t EXECUTION_COMPLETE = MAKE_RETURN_CODE(1); static const ReturnValue_t NO_STEP_MESSAGE = MAKE_RETURN_CODE(2); + /** + * Target object has too many pending requests + */ static const ReturnValue_t OBJECT_BUSY = MAKE_RETURN_CODE(3); + /** + * Command map is full + */ static const ReturnValue_t BUSY = MAKE_RETURN_CODE(4); static const ReturnValue_t INVALID_TC = MAKE_RETURN_CODE(5); static const ReturnValue_t INVALID_OBJECT = MAKE_RETURN_CODE(6); @@ -330,16 +336,24 @@ class CommandingServiceBase : public SystemObject, ReturnValue_t setUpTcReader(store_address_t storeId); - void rejectPacket(uint8_t reportId, store_address_t tcStoreId, ReturnValue_t errorCode); + /** + * The TC format is invalid or there was an issue retrieving a TC packet from the store. + * @param errorCode Result of the failed operation, will be sent with the verification failure + * message + * @return + */ + ReturnValue_t rejectPacketInvalidTc(ReturnValue_t errorCode, store_address_t tcStoreId); + ReturnValue_t rejectPacket(uint8_t reportId, store_address_t tcStoreId, ReturnValue_t errorCode); - void acceptPacket(uint8_t reportId, store_address_t tcStoreId); + ReturnValue_t acceptPacket(uint8_t reportId, store_address_t tcStoreId); void startExecution(store_address_t storeId, CommandMapIter& iter); void handleCommandMessage(CommandMessage* reply); void handleReplyHandlerResult(ReturnValue_t result, CommandMapIter iter, CommandMessage* nextCommand, CommandMessage* reply, bool& isStep); - + void prepareVerificationFailureWithNoTcInfo(uint8_t reportId, ReturnValue_t errorCode, + bool setCachedFailParams); void prepareVerificationFailureWithFullInfo(uint8_t reportId, CommandInfo::TcInfo& tcInfo, ReturnValue_t errorCode, bool setCachedFailParams); void prepareVerificationSuccessWithFullInfo(uint8_t reportId, CommandInfo::TcInfo& tcInfo); diff --git a/src/fsfw/tmtcservices/VerificationReporterIF.h b/src/fsfw/tmtcservices/VerificationReporterIF.h index 6678c630..df0d5a38 100644 --- a/src/fsfw/tmtcservices/VerificationReporterIF.h +++ b/src/fsfw/tmtcservices/VerificationReporterIF.h @@ -13,6 +13,12 @@ struct VerifParamsBase { uint16_t tcPsc; uint8_t ackFlags = ecss::ACK_ALL; uint8_t step = 0; + + void resetTcFields() { + tcPacketId = 0; + tcPsc = 0; + ackFlags = 0; + } }; struct VerifSuccessParams : public VerifParamsBase { @@ -27,10 +33,10 @@ struct VerifFailureParams : public VerifParamsBase { VerifFailureParams() = default; VerifFailureParams(uint8_t reportId, uint16_t tcPacketId, uint16_t tcPsc, ReturnValue_t errorCode, uint32_t errorParam1, uint32_t errorParams2) - : VerifParamsBase(reportId, tcPacketId, tcPsc), errorCode(errorCode) { - errorParam1 = errorParam1; - errorParams2 = errorParams2; - } + : VerifParamsBase(reportId, tcPacketId, tcPsc), + errorCode(errorCode), + errorParam1(errorParam1), + errorParam2(errorParams2) {} VerifFailureParams(uint8_t reportId, uint16_t tcPacketId, uint16_t tcPsc, ReturnValue_t errorCode) : VerifParamsBase(reportId, tcPacketId, tcPsc), errorCode(errorCode) {} VerifFailureParams(uint8_t reportId, uint16_t tcPacketId, uint16_t tcPsc) @@ -41,7 +47,13 @@ struct VerifFailureParams : public VerifParamsBase { VerifFailureParams(uint8_t reportId, PusTcIF& tc) : VerifParamsBase(reportId, tc.getPacketIdRaw(), tc.getPacketSeqCtrlRaw()) {} - ReturnValue_t errorCode = result::OK; + void resetFailParams() { + errorCode = result::FAILED; + errorParam1 = 0; + errorParam2 = 0; + } + + ReturnValue_t errorCode = result::FAILED; uint8_t step = 0; uint32_t errorParam1 = 0; uint32_t errorParam2 = 0; -- 2.43.0 From 007f958a0b787a572bf1bd98b348c3a632799bf7 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Mon, 15 Aug 2022 11:38:52 +0200 Subject: [PATCH 102/108] fsfw fixes for merge --- src/fsfw/datapoollocal/LocalDataPoolManager.h | 5 +++-- src/fsfw/pus/Service5EventReporting.cpp | 2 +- src/fsfw_hal/devicehandlers/GyroL3GD20Handler.cpp | 3 ++- src/fsfw_hal/devicehandlers/MgmLIS3MDLHandler.cpp | 3 ++- src/fsfw_hal/devicehandlers/MgmRM3100Handler.cpp | 3 ++- 5 files changed, 10 insertions(+), 6 deletions(-) diff --git a/src/fsfw/datapoollocal/LocalDataPoolManager.h b/src/fsfw/datapoollocal/LocalDataPoolManager.h index 998ca03b..413e00f6 100644 --- a/src/fsfw/datapoollocal/LocalDataPoolManager.h +++ b/src/fsfw/datapoollocal/LocalDataPoolManager.h @@ -243,13 +243,14 @@ class LocalDataPoolManager : public ProvidesDataPoolSubscriptionIF, public Acces LocalDataPoolManager* getPoolManagerHandle() override; ReturnValue_t subscribeForRegularPeriodicPacket(subdp::RegularHkPeriodicParams params) override; ReturnValue_t subscribeForDiagPeriodicPacket(subdp::DiagnosticsHkPeriodicParams params) override; - ReturnValue_t subscribeForPeriodicPacket(subdp::ParamsBase& params); ReturnValue_t subscribeForRegularUpdatePacket(subdp::RegularHkUpdateParams params) override; ReturnValue_t subscribeForDiagUpdatePacket(subdp::DiagnosticsHkUpdateParams params) override; - ReturnValue_t subscribeForUpdatePacket(subdp::ParamsBase& params); protected: + ReturnValue_t subscribeForPeriodicPacket(subdp::ParamsBase& params); + ReturnValue_t subscribeForUpdatePacket(subdp::ParamsBase& params); + /** Core data structure for the actual pool data */ localpool::DataPool localPoolMap; /** Every housekeeping data manager has a mutex to protect access diff --git a/src/fsfw/pus/Service5EventReporting.cpp b/src/fsfw/pus/Service5EventReporting.cpp index 5203ff3d..13bf29c3 100644 --- a/src/fsfw/pus/Service5EventReporting.cpp +++ b/src/fsfw/pus/Service5EventReporting.cpp @@ -13,7 +13,7 @@ Service5EventReporting::Service5EventReporting(PsbParams params, size_t maxNumbe storeHelper(params.apid), tmHelper(params.serviceId, storeHelper, sendHelper), maxNumberReportsPerCycle(maxNumberReportsPerCycle) { - auto mqArgs = MqArgs(objectId, static_cast(this)); + auto mqArgs = MqArgs(getObjectId(), static_cast(this)); eventQueue = QueueFactory::instance()->createMessageQueue( messageQueueDepth, MessageQueueMessage::MAX_MESSAGE_SIZE, &mqArgs); } diff --git a/src/fsfw_hal/devicehandlers/GyroL3GD20Handler.cpp b/src/fsfw_hal/devicehandlers/GyroL3GD20Handler.cpp index 3dd19275..5ee7f978 100644 --- a/src/fsfw_hal/devicehandlers/GyroL3GD20Handler.cpp +++ b/src/fsfw_hal/devicehandlers/GyroL3GD20Handler.cpp @@ -252,7 +252,8 @@ ReturnValue_t GyroHandlerL3GD20H::initializeLocalDataPool(localpool::DataPool &l localDataPoolMap.emplace(L3GD20H::ANG_VELOC_Y, new PoolEntry({0.0})); localDataPoolMap.emplace(L3GD20H::ANG_VELOC_Z, new PoolEntry({0.0})); localDataPoolMap.emplace(L3GD20H::TEMPERATURE, new PoolEntry({0.0})); - poolManager.subscribeForPeriodicPacket(dataset.getSid(), false, 10.0, false); + poolManager.subscribeForRegularPeriodicPacket( + subdp::RegularHkPeriodicParams(dataset.getSid(), false, 10.0)); return HasReturnvaluesIF::RETURN_OK; } diff --git a/src/fsfw_hal/devicehandlers/MgmLIS3MDLHandler.cpp b/src/fsfw_hal/devicehandlers/MgmLIS3MDLHandler.cpp index e1b1294f..e366760d 100644 --- a/src/fsfw_hal/devicehandlers/MgmLIS3MDLHandler.cpp +++ b/src/fsfw_hal/devicehandlers/MgmLIS3MDLHandler.cpp @@ -469,7 +469,8 @@ ReturnValue_t MgmLIS3MDLHandler::initializeLocalDataPool(localpool::DataPool &lo LocalDataPoolManager &poolManager) { localDataPoolMap.emplace(MGMLIS3MDL::FIELD_STRENGTHS, &mgmXYZ); localDataPoolMap.emplace(MGMLIS3MDL::TEMPERATURE_CELCIUS, &temperature); - poolManager.subscribeForPeriodicPacket(dataset.getSid(), false, 10.0, false); + poolManager.subscribeForRegularPeriodicPacket( + subdp::RegularHkPeriodicParams(dataset.getSid(), false, 10.0)); return HasReturnvaluesIF::RETURN_OK; } diff --git a/src/fsfw_hal/devicehandlers/MgmRM3100Handler.cpp b/src/fsfw_hal/devicehandlers/MgmRM3100Handler.cpp index c329f5a6..b39ac852 100644 --- a/src/fsfw_hal/devicehandlers/MgmRM3100Handler.cpp +++ b/src/fsfw_hal/devicehandlers/MgmRM3100Handler.cpp @@ -310,7 +310,8 @@ void MgmRM3100Handler::modeChanged(void) { internalState = InternalState::NONE; ReturnValue_t MgmRM3100Handler::initializeLocalDataPool(localpool::DataPool &localDataPoolMap, LocalDataPoolManager &poolManager) { localDataPoolMap.emplace(RM3100::FIELD_STRENGTHS, &mgmXYZ); - poolManager.subscribeForPeriodicPacket(primaryDataset.getSid(), false, 10.0, false); + poolManager.subscribeForRegularPeriodicPacket( + subdp::RegularHkPeriodicParams(primaryDataset.getSid(), false, 10.0)); return HasReturnvaluesIF::RETURN_OK; } -- 2.43.0 From 4d82d0e4c15091aceafc8279790517702d5941f4 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Mon, 15 Aug 2022 17:24:48 +0200 Subject: [PATCH 103/108] update source sequence counter code --- src/fsfw/tmtcservices/SourceSequenceCounter.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/fsfw/tmtcservices/SourceSequenceCounter.h b/src/fsfw/tmtcservices/SourceSequenceCounter.h index 4b33fb0e..9b8e85d1 100644 --- a/src/fsfw/tmtcservices/SourceSequenceCounter.h +++ b/src/fsfw/tmtcservices/SourceSequenceCounter.h @@ -10,14 +10,14 @@ class SourceSequenceCounter { public: SourceSequenceCounter(uint16_t initialSequenceCount = 0) : sequenceCount(initialSequenceCount) {} void increment() { - sequenceCount = (sequenceCount + 1) % (SpacePacketBase::LIMIT_SEQUENCE_COUNT); + sequenceCount = (sequenceCount + 1) % (ccsds::LIMIT_SEQUENCE_COUNT); } void decrement() { - sequenceCount = (sequenceCount - 1) % (SpacePacketBase::LIMIT_SEQUENCE_COUNT); + sequenceCount = (sequenceCount - 1) % (ccsds::LIMIT_SEQUENCE_COUNT); } uint16_t get() { return this->sequenceCount; } void reset(uint16_t toValue = 0) { - sequenceCount = toValue % (SpacePacketBase::LIMIT_SEQUENCE_COUNT); + sequenceCount = toValue % (ccsds::LIMIT_SEQUENCE_COUNT); } SourceSequenceCounter& operator++(int) { this->increment(); -- 2.43.0 From 9e064fe800676f2b0919d64b51e8b9d8418b97e5 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Mon, 15 Aug 2022 19:16:31 +0200 Subject: [PATCH 104/108] fix unittests --- src/fsfw/tmtcpacket/ccsds/PacketId.h | 3 ++ src/fsfw/tmtcpacket/ccsds/PacketSeqCtrl.h | 3 ++ src/fsfw/tmtcpacket/pus/tc/PusTcCreator.cpp | 7 ---- src/fsfw/tmtcpacket/pus/tc/PusTcCreator.h | 6 ++-- src/fsfw/tmtcpacket/pus/tm/PusTmCreator.cpp | 8 ----- src/fsfw/tmtcpacket/pus/tm/PusTmCreator.h | 6 ++-- src/fsfw/util/UnsignedByteField.h | 35 ++++++++----------- .../devicehandlers/MgmLIS3MDLHandler.cpp | 3 +- .../devicehandlers/MgmRM3100Handler.cpp | 5 +-- unittests/tmtcpacket/testCcsds.cpp | 16 +++++---- unittests/tmtcpacket/testPusTcCreator.cpp | 14 ++++---- unittests/tmtcpacket/testPusTcReader.cpp | 8 ++--- unittests/tmtcpacket/testPusTmCreator.cpp | 12 +++---- unittests/tmtcpacket/testPusTmReader.cpp | 10 +++--- unittests/tmtcpacket/testZcTmWriter.cpp | 4 +-- unittests/util/testUnsignedByteField.cpp | 12 ++++--- 16 files changed, 73 insertions(+), 79 deletions(-) diff --git a/src/fsfw/tmtcpacket/ccsds/PacketId.h b/src/fsfw/tmtcpacket/ccsds/PacketId.h index 2c77652c..518b2d41 100644 --- a/src/fsfw/tmtcpacket/ccsds/PacketId.h +++ b/src/fsfw/tmtcpacket/ccsds/PacketId.h @@ -79,6 +79,9 @@ struct PacketId : public SerializeIF { ccsds::PacketType packetType = ccsds::PacketType::TM; bool secHeaderFlag = false; uint16_t apid = 0; + + using SerializeIF::deSerialize; + using SerializeIF::serialize; }; #endif // FSFW_TMTCPACKET_PACKETID_H diff --git a/src/fsfw/tmtcpacket/ccsds/PacketSeqCtrl.h b/src/fsfw/tmtcpacket/ccsds/PacketSeqCtrl.h index cd4e153e..a1e73460 100644 --- a/src/fsfw/tmtcpacket/ccsds/PacketSeqCtrl.h +++ b/src/fsfw/tmtcpacket/ccsds/PacketSeqCtrl.h @@ -55,6 +55,9 @@ struct PacketSeqCtrl : public SerializeIF { ccsds::SequenceFlags seqFlags = ccsds::SequenceFlags::CONTINUATION; uint16_t seqCount = 0; + + using SerializeIF::deSerialize; + using SerializeIF::serialize; }; #endif // FSFW_TMTCPACKET_PACKETSEQCTRL_H diff --git a/src/fsfw/tmtcpacket/pus/tc/PusTcCreator.cpp b/src/fsfw/tmtcpacket/pus/tc/PusTcCreator.cpp index 2e786e6e..e1b96945 100644 --- a/src/fsfw/tmtcpacket/pus/tc/PusTcCreator.cpp +++ b/src/fsfw/tmtcpacket/pus/tc/PusTcCreator.cpp @@ -103,13 +103,6 @@ ReturnValue_t PusTcCreator::setSerializableUserData(SerializeIF &serializable) { return HasReturnvaluesIF::RETURN_OK; } -ReturnValue_t PusTcCreator::serialize(uint8_t **buffer, size_t *size, size_t maxSize) const { - return serialize(buffer, size, maxSize, SerializeIF::Endianness::NETWORK); -} - -ReturnValue_t PusTcCreator::serialize(uint8_t *buffer, size_t &serLen, size_t maxSize) const { - return SerializeIF::serialize(buffer, serLen, maxSize, SerializeIF::Endianness::NETWORK); -} void PusTcCreator::setup() { spCreator.setPacketType(ccsds::PacketType::TC); spCreator.setSecHeaderFlag(); diff --git a/src/fsfw/tmtcpacket/pus/tc/PusTcCreator.h b/src/fsfw/tmtcpacket/pus/tc/PusTcCreator.h index ea6c1d58..72691c40 100644 --- a/src/fsfw/tmtcpacket/pus/tc/PusTcCreator.h +++ b/src/fsfw/tmtcpacket/pus/tc/PusTcCreator.h @@ -40,8 +40,6 @@ class PusTcCreator : public PusTcIF, public SerializeIF, public CustomUserDataIF PusTcParams &getPusParams(); SpacePacketParams &getSpParams(); - ReturnValue_t serialize(uint8_t **buffer, size_t *size, size_t maxSize) const override; - ReturnValue_t serialize(uint8_t *buffer, size_t &serLen, size_t maxSize) const override; [[nodiscard]] size_t getSerializedSize() const override; [[nodiscard]] uint16_t getPacketIdRaw() const override; @@ -55,7 +53,11 @@ class PusTcCreator : public PusTcIF, public SerializeIF, public CustomUserDataIF ReturnValue_t setRawUserData(const uint8_t *data, size_t len) override; ReturnValue_t setSerializableUserData(SerializeIF &serializable) override; + // Load all big endian helpers into the class namespace + using SerializeIF::serializeBe; + private: + // Forbidden to use, enforce big endian serialization ReturnValue_t serialize(uint8_t **buffer, size_t *size, size_t maxSize, Endianness streamEndianness) const override; // Forbidden to use diff --git a/src/fsfw/tmtcpacket/pus/tm/PusTmCreator.cpp b/src/fsfw/tmtcpacket/pus/tm/PusTmCreator.cpp index 64dbbfeb..44172de3 100644 --- a/src/fsfw/tmtcpacket/pus/tm/PusTmCreator.cpp +++ b/src/fsfw/tmtcpacket/pus/tm/PusTmCreator.cpp @@ -150,11 +150,3 @@ void PusTmCreator::setSubservice(uint8_t subservice) { pusParams.secHeader.subservice = subservice; } bool PusTmCreator::crcCalculationEnabled() const { return calculateCrcOnSerialization; } - -ReturnValue_t PusTmCreator::serialize(uint8_t** buffer, size_t* size, size_t maxSize) const { - return serialize(buffer, size, maxSize, SerializeIF::Endianness::NETWORK); -} - -ReturnValue_t PusTmCreator::serialize(uint8_t* buffer, size_t& serLen, size_t maxSize) const { - return SerializeIF::serialize(buffer, serLen, maxSize, SerializeIF::Endianness::NETWORK); -} \ No newline at end of file diff --git a/src/fsfw/tmtcpacket/pus/tm/PusTmCreator.h b/src/fsfw/tmtcpacket/pus/tm/PusTmCreator.h index 9f3dcd24..706a7b70 100644 --- a/src/fsfw/tmtcpacket/pus/tm/PusTmCreator.h +++ b/src/fsfw/tmtcpacket/pus/tm/PusTmCreator.h @@ -82,9 +82,6 @@ class PusTmCreator : public SerializeIF, public PusTmIF, public CustomUserDataIF uint8_t getScTimeRefStatus() override; uint16_t getMessageTypeCounter() override; uint16_t getDestId() override; - // Override these to use default big endianness - ReturnValue_t serialize(uint8_t** buffer, size_t* size, size_t maxSize) const override; - ReturnValue_t serialize(uint8_t* buffer, size_t& serLen, size_t maxSize) const override; ReturnValue_t serialize(uint8_t** buffer, size_t* size, size_t maxSize, Endianness streamEndianness) const override; [[nodiscard]] size_t getSerializedSize() const override; @@ -92,6 +89,9 @@ class PusTmCreator : public SerializeIF, public PusTmIF, public CustomUserDataIF ReturnValue_t setRawUserData(const uint8_t* data, size_t len) override; ReturnValue_t setSerializableUserData(SerializeIF& serializable) override; + // Load all big endian (network endian) helpers into scope + using SerializeIF::serializeBe; + private: // Forbidden to use ReturnValue_t deSerialize(const uint8_t** buffer, size_t* size, diff --git a/src/fsfw/util/UnsignedByteField.h b/src/fsfw/util/UnsignedByteField.h index b02e8b3a..3f4ee791 100644 --- a/src/fsfw/util/UnsignedByteField.h +++ b/src/fsfw/util/UnsignedByteField.h @@ -3,50 +3,45 @@ #include "fsfw/serialize.h" -template -class UnsignedByteField: public SerializeIF { +template +class UnsignedByteField : public SerializeIF { public: static_assert(std::is_unsigned::value); - explicit UnsignedByteField(T value): value(value) {} + explicit UnsignedByteField(T value) : value(value) {} [[nodiscard]] ReturnValue_t serialize(uint8_t **buffer, size_t *size, size_t maxSize, - Endianness streamEndianness) const override { + Endianness streamEndianness) const override { return SerializeAdapter::serialize(&value, buffer, size, maxSize, streamEndianness); } ReturnValue_t deSerialize(const uint8_t **buffer, size_t *size, - Endianness streamEndianness) override { + Endianness streamEndianness) override { return SerializeAdapter::deSerialize(&value, buffer, size, streamEndianness); } - [[nodiscard]] size_t getSerializedSize() const override { - return sizeof(T); - } + [[nodiscard]] size_t getSerializedSize() const override { return sizeof(T); } - [[nodiscard]] T getValue() const { - return value; - } + [[nodiscard]] T getValue() const { return value; } + + void setValue(T value_) { value = value_; } - void setValue(T value_) { - value = value_; - } private: T value; }; -class U32ByteField: public UnsignedByteField { +class U32ByteField : public UnsignedByteField { public: - explicit U32ByteField(uint32_t value): UnsignedByteField(value) {} + explicit U32ByteField(uint32_t value) : UnsignedByteField(value) {} }; -class U16ByteField: public UnsignedByteField { +class U16ByteField : public UnsignedByteField { public: - explicit U16ByteField(uint16_t value): UnsignedByteField(value) {} + explicit U16ByteField(uint16_t value) : UnsignedByteField(value) {} }; -class U8ByteField: public UnsignedByteField { +class U8ByteField : public UnsignedByteField { public: - explicit U8ByteField(uint8_t value): UnsignedByteField(value) {} + explicit U8ByteField(uint8_t value) : UnsignedByteField(value) {} }; #endif // FSFW_UTIL_UNSIGNEDBYTEFIELD_H diff --git a/src/fsfw_hal/devicehandlers/MgmLIS3MDLHandler.cpp b/src/fsfw_hal/devicehandlers/MgmLIS3MDLHandler.cpp index 5ddc3245..28d15e46 100644 --- a/src/fsfw_hal/devicehandlers/MgmLIS3MDLHandler.cpp +++ b/src/fsfw_hal/devicehandlers/MgmLIS3MDLHandler.cpp @@ -466,7 +466,8 @@ ReturnValue_t MgmLIS3MDLHandler::initializeLocalDataPool(localpool::DataPool &lo LocalDataPoolManager &poolManager) { localDataPoolMap.emplace(MGMLIS3MDL::FIELD_STRENGTHS, &mgmXYZ); localDataPoolMap.emplace(MGMLIS3MDL::TEMPERATURE_CELCIUS, &temperature); - poolManager.subscribeForPeriodicPacket(dataset.getSid(), false, 10.0, false); + poolManager.subscribeForRegularPeriodicPacket( + subdp::RegularHkPeriodicParams(dataset.getSid(), false, 10.0)); return HasReturnvaluesIF::RETURN_OK; } diff --git a/src/fsfw_hal/devicehandlers/MgmRM3100Handler.cpp b/src/fsfw_hal/devicehandlers/MgmRM3100Handler.cpp index c329f5a6..e8f61b9f 100644 --- a/src/fsfw_hal/devicehandlers/MgmRM3100Handler.cpp +++ b/src/fsfw_hal/devicehandlers/MgmRM3100Handler.cpp @@ -305,12 +305,13 @@ void MgmRM3100Handler::fillCommandAndReplyMap() { insertInCommandAndReplyMap(RM3100::READ_DATA, 3, &primaryDataset); } -void MgmRM3100Handler::modeChanged(void) { internalState = InternalState::NONE; } +void MgmRM3100Handler::modeChanged() { internalState = InternalState::NONE; } ReturnValue_t MgmRM3100Handler::initializeLocalDataPool(localpool::DataPool &localDataPoolMap, LocalDataPoolManager &poolManager) { localDataPoolMap.emplace(RM3100::FIELD_STRENGTHS, &mgmXYZ); - poolManager.subscribeForPeriodicPacket(primaryDataset.getSid(), false, 10.0, false); + poolManager.subscribeForRegularPeriodicPacket( + subdp::RegularHkPeriodicParams(primaryDataset.getSid(), false, 10.0)); return HasReturnvaluesIF::RETURN_OK; } diff --git a/unittests/tmtcpacket/testCcsds.cpp b/unittests/tmtcpacket/testCcsds.cpp index 095020ae..7c88c0c6 100644 --- a/unittests/tmtcpacket/testCcsds.cpp +++ b/unittests/tmtcpacket/testCcsds.cpp @@ -60,9 +60,9 @@ TEST_CASE("CCSDS Packet ID", "[ccsds-packet-id]") { SECTION("Invalid Deser") { size_t deserLen = 0; - REQUIRE(packetId.SerializeIF::deSerialize(buf.data(), deserLen, 1) == + REQUIRE(packetId.deSerialize(buf.data(), deserLen, 1, SerializeIF::Endianness::NETWORK) == SerializeIF::STREAM_TOO_SHORT); - REQUIRE(packetId.SerializeIF::deSerialize(buf.data(), deserLen, 0) == + REQUIRE(packetId.deSerialize(buf.data(), deserLen, 0, SerializeIF::Endianness::NETWORK) == SerializeIF::STREAM_TOO_SHORT); } @@ -77,8 +77,8 @@ TEST_CASE("CCSDS Packet ID", "[ccsds-packet-id]") { buf[0] = 0x1a; buf[1] = 0xff; size_t deserLen = 0xff; - REQUIRE(packetId.SerializeIF::deSerialize(buf.data(), deserLen, buf.size()) == - HasReturnvaluesIF::RETURN_OK); + REQUIRE(packetId.deSerialize(buf.data(), deserLen, buf.size(), + SerializeIF::Endianness::NETWORK) == HasReturnvaluesIF::RETURN_OK); CHECK(packetId.apid == 0x2ff); CHECK(deserLen == 2); CHECK(packetId.packetType == ccsds::PacketType::TC); @@ -113,7 +113,7 @@ TEST_CASE("CCSDS Packet Seq Ctrl", "[ccsds-packet-seq-ctrl]") { buf[0] = 0xbf; buf[1] = 0xfe; size_t deserLen = 0xff; - REQUIRE(psc.SerializeIF::deSerialize(buf.data(), deserLen, buf.size()) == + REQUIRE(psc.deSerialize(buf.data(), deserLen, buf.size(), SerializeIF::Endianness::NETWORK) == HasReturnvaluesIF::RETURN_OK); CHECK(psc.seqFlags == ccsds::SequenceFlags::LAST_SEGMENT); CHECK(deserLen == 2); @@ -128,7 +128,9 @@ TEST_CASE("CCSDS Packet Seq Ctrl", "[ccsds-packet-seq-ctrl]") { SECTION("Invalid Deser") { size_t deserLen = 0; - REQUIRE(psc.SerializeIF::deSerialize(buf.data(), deserLen, 1) == SerializeIF::STREAM_TOO_SHORT); - REQUIRE(psc.SerializeIF::deSerialize(buf.data(), deserLen, 0) == SerializeIF::STREAM_TOO_SHORT); + REQUIRE(psc.deSerialize(buf.data(), deserLen, 1, SerializeIF::Endianness::NETWORK) == + SerializeIF::STREAM_TOO_SHORT); + REQUIRE(psc.deSerialize(buf.data(), deserLen, 0, SerializeIF::Endianness::NETWORK) == + SerializeIF::STREAM_TOO_SHORT); } } diff --git a/unittests/tmtcpacket/testPusTcCreator.cpp b/unittests/tmtcpacket/testPusTcCreator.cpp index 5bc349a6..5aed24a0 100644 --- a/unittests/tmtcpacket/testPusTcCreator.cpp +++ b/unittests/tmtcpacket/testPusTcCreator.cpp @@ -34,7 +34,7 @@ TEST_CASE("PUS TC Creator", "[pus-tc-creator]") { } SECTION("Serialized") { - REQUIRE(creator.serialize(&dataPtr, &serLen, buf.size()) == HasReturnvaluesIF::RETURN_OK); + REQUIRE(creator.serializeBe(&dataPtr, &serLen, buf.size()) == HasReturnvaluesIF::RETURN_OK); REQUIRE(serLen == 13); REQUIRE(buf[0] == 0x18); REQUIRE(buf[1] == 0x02); @@ -64,7 +64,7 @@ TEST_CASE("PUS TC Creator", "[pus-tc-creator]") { auto& params = creator.getPusParams(); params.sourceId = 0x5ff; REQUIRE(creator.getSourceId() == 0x5ff); - REQUIRE(creator.serialize(&dataPtr, &serLen, buf.size()) == HasReturnvaluesIF::RETURN_OK); + REQUIRE(creator.serializeBe(&dataPtr, &serLen, buf.size()) == HasReturnvaluesIF::RETURN_OK); REQUIRE(((buf[9] << 8) | buf[10]) == 0x5ff); } @@ -76,7 +76,7 @@ TEST_CASE("PUS TC Creator", "[pus-tc-creator]") { REQUIRE(creator.getSerializedSize() == 13); creator.updateSpLengthField(); REQUIRE(creator.getSerializedSize() == 16); - REQUIRE(creator.serialize(&dataPtr, &serLen, buf.size()) == HasReturnvaluesIF::RETURN_OK); + REQUIRE(creator.serializeBe(&dataPtr, &serLen, buf.size()) == HasReturnvaluesIF::RETURN_OK); REQUIRE(serLen == 16); REQUIRE(buf[11] == 1); REQUIRE(buf[12] == 2); @@ -88,7 +88,7 @@ TEST_CASE("PUS TC Creator", "[pus-tc-creator]") { auto simpleSer = SimpleSerializable(); creator.setSerializableUserData(simpleSer); REQUIRE(creator.getSerializedSize() == 16); - REQUIRE(creator.serialize(&dataPtr, &serLen, buf.size()) == HasReturnvaluesIF::RETURN_OK); + REQUIRE(creator.serializeBe(&dataPtr, &serLen, buf.size()) == HasReturnvaluesIF::RETURN_OK); REQUIRE(serLen == 16); REQUIRE(buf[11] == 1); REQUIRE(buf[12] == 2); @@ -100,7 +100,7 @@ TEST_CASE("PUS TC Creator", "[pus-tc-creator]") { auto simpleSer = SimpleSerializable(); creator.setSerializableUserData(simpleSer); REQUIRE(creator.getSerializedSize() == 16); - REQUIRE(creator.serialize(dataPtr, serLen, buf.size()) == HasReturnvaluesIF::RETURN_OK); + REQUIRE(creator.serializeBe(dataPtr, serLen, buf.size()) == HasReturnvaluesIF::RETURN_OK); REQUIRE(serLen == 16); REQUIRE(buf[11] == 1); REQUIRE(buf[12] == 2); @@ -120,13 +120,13 @@ TEST_CASE("PUS TC Creator", "[pus-tc-creator]") { for (size_t maxSize = 0; maxSize < reqSize; maxSize++) { dataPtr = buf.data(); serLen = 0; - REQUIRE(creator.serialize(&dataPtr, &serLen, maxSize) == SerializeIF::BUFFER_TOO_SHORT); + REQUIRE(creator.serializeBe(&dataPtr, &serLen, maxSize) == SerializeIF::BUFFER_TOO_SHORT); } } SECTION("Invalid PUS Version") { auto& params = creator.getPusParams(); params.pusVersion = 0; - REQUIRE(creator.serialize(&dataPtr, &serLen, buf.size()) == PusIF::INVALID_PUS_VERSION); + REQUIRE(creator.serializeBe(&dataPtr, &serLen, buf.size()) == PusIF::INVALID_PUS_VERSION); } } \ No newline at end of file diff --git a/unittests/tmtcpacket/testPusTcReader.cpp b/unittests/tmtcpacket/testPusTcReader.cpp index 3245218a..1c3469f2 100644 --- a/unittests/tmtcpacket/testPusTcReader.cpp +++ b/unittests/tmtcpacket/testPusTcReader.cpp @@ -16,7 +16,7 @@ TEST_CASE("PUS TC Reader", "[pus-tc-reader]") { PusTcReader reader; SECTION("State") { - REQUIRE(creator.serialize(&dataPtr, &serLen, buf.size()) == HasReturnvaluesIF::RETURN_OK); + REQUIRE(creator.serializeBe(&dataPtr, &serLen, buf.size()) == HasReturnvaluesIF::RETURN_OK); REQUIRE(reader.isNull()); REQUIRE(not reader); PusTcReader* readerPtr = nullptr; @@ -55,14 +55,14 @@ TEST_CASE("PUS TC Reader", "[pus-tc-reader]") { } SECTION("Invalid CRC") { - REQUIRE(creator.serialize(&dataPtr, &serLen, buf.size()) == HasReturnvaluesIF::RETURN_OK); + REQUIRE(creator.serializeBe(&dataPtr, &serLen, buf.size()) == HasReturnvaluesIF::RETURN_OK); REQUIRE(reader.setReadOnlyData(buf.data(), serLen) == HasReturnvaluesIF::RETURN_OK); buf[11] = 0x00; REQUIRE(reader.parseDataWithCrcCheck() == PusIF::INVALID_CRC_16); } SECTION("Invalid CRC but no check") { - REQUIRE(creator.serialize(&dataPtr, &serLen, buf.size()) == HasReturnvaluesIF::RETURN_OK); + REQUIRE(creator.serializeBe(&dataPtr, &serLen, buf.size()) == HasReturnvaluesIF::RETURN_OK); REQUIRE(reader.setReadOnlyData(buf.data(), serLen) == HasReturnvaluesIF::RETURN_OK); buf[11] = 0x00; REQUIRE(reader.parseDataWithoutCrcCheck() == HasReturnvaluesIF::RETURN_OK); @@ -72,7 +72,7 @@ TEST_CASE("PUS TC Reader", "[pus-tc-reader]") { auto& params = creator.getPusParams(); std::array data{1, 2, 3}; creator.setRawUserData(data.data(), data.size()); - REQUIRE(creator.serialize(&dataPtr, &serLen, buf.size()) == HasReturnvaluesIF::RETURN_OK); + REQUIRE(creator.serializeBe(&dataPtr, &serLen, buf.size()) == HasReturnvaluesIF::RETURN_OK); REQUIRE(reader.setReadOnlyData(buf.data(), serLen) == HasReturnvaluesIF::RETURN_OK); REQUIRE(reader.parseDataWithCrcCheck() == HasReturnvaluesIF::RETURN_OK); const uint8_t* userDataPtr = reader.getUserData(); diff --git a/unittests/tmtcpacket/testPusTmCreator.cpp b/unittests/tmtcpacket/testPusTmCreator.cpp index f32e060f..4c958911 100644 --- a/unittests/tmtcpacket/testPusTmCreator.cpp +++ b/unittests/tmtcpacket/testPusTmCreator.cpp @@ -90,7 +90,7 @@ TEST_CASE("PUS TM Creator", "[pus-tm-creator]") { REQUIRE(creator.getApid() == 0x3ff); REQUIRE(creator.getDestId() == 0xfff); REQUIRE(creator.getMessageTypeCounter() == 0x313); - REQUIRE(creator.serialize(&dataPtr, &serLen, buf.size()) == HasReturnvaluesIF::RETURN_OK); + REQUIRE(creator.serializeBe(&dataPtr, &serLen, buf.size()) == HasReturnvaluesIF::RETURN_OK); // Message Sequence Count REQUIRE(((buf[9] << 8) | buf[10]) == 0x313); // Destination ID @@ -108,8 +108,7 @@ TEST_CASE("PUS TM Creator", "[pus-tm-creator]") { std::array data{1, 2, 3}; creator.setRawUserData(data.data(), data.size()); REQUIRE(creator.getFullPacketLen() == 25); - REQUIRE(creator.SerializeIF::serialize(&dataPtr, &serLen, buf.size()) == - HasReturnvaluesIF::RETURN_OK); + REQUIRE(creator.serializeBe(&dataPtr, &serLen, buf.size()) == HasReturnvaluesIF::RETURN_OK); REQUIRE(buf[20] == 1); REQUIRE(buf[21] == 2); REQUIRE(buf[22] == 3); @@ -119,7 +118,8 @@ TEST_CASE("PUS TM Creator", "[pus-tm-creator]") { auto simpleSer = SimpleSerializable(); creator.setSerializableUserData(simpleSer); REQUIRE(creator.getFullPacketLen() == 25); - REQUIRE(creator.serialize(&dataPtr, &serLen, buf.size()) == HasReturnvaluesIF::RETURN_OK); + REQUIRE(creator.serialize(&dataPtr, &serLen, buf.size(), SerializeIF::Endianness::NETWORK) == + HasReturnvaluesIF::RETURN_OK); REQUIRE(buf[20] == 1); REQUIRE(buf[21] == 2); REQUIRE(buf[22] == 3); @@ -143,7 +143,7 @@ TEST_CASE("PUS TM Creator", "[pus-tm-creator]") { for (size_t maxSize = 0; maxSize < reqSize; maxSize++) { dataPtr = buf.data(); serLen = 0; - REQUIRE(creator.SerializeIF::serialize(&dataPtr, &serLen, maxSize) == + REQUIRE(creator.serialize(&dataPtr, &serLen, maxSize, SerializeIF::Endianness::NETWORK) == SerializeIF::BUFFER_TOO_SHORT); } } @@ -151,7 +151,7 @@ TEST_CASE("PUS TM Creator", "[pus-tm-creator]") { SECTION("No CRC Generation") { creator.disableCrcCalculation(); REQUIRE(not creator.crcCalculationEnabled()); - REQUIRE(creator.serialize(dataPtr, serLen, buf.size()) == HasReturnvaluesIF::RETURN_OK); + REQUIRE(creator.serializeBe(dataPtr, serLen, buf.size()) == HasReturnvaluesIF::RETURN_OK); REQUIRE(serLen == 22); REQUIRE(buf[20] == 0x00); REQUIRE(buf[21] == 0x00); diff --git a/unittests/tmtcpacket/testPusTmReader.cpp b/unittests/tmtcpacket/testPusTmReader.cpp index 7967dba6..67659442 100644 --- a/unittests/tmtcpacket/testPusTmReader.cpp +++ b/unittests/tmtcpacket/testPusTmReader.cpp @@ -62,7 +62,7 @@ TEST_CASE("PUS TM Reader", "[pus-tm-reader]") { } SECTION("Invalid CRC") { - REQUIRE(creator.serialize(&dataPtr, &serLen, buf.size()) == HasReturnvaluesIF::RETURN_OK); + REQUIRE(creator.serializeBe(&dataPtr, &serLen, buf.size()) == HasReturnvaluesIF::RETURN_OK); buf[20] = 0; REQUIRE(reader.setReadOnlyData(buf.data(), serLen) == HasReturnvaluesIF::RETURN_OK); REQUIRE(reader.parseDataWithCrcCheck() == PusIF::INVALID_CRC_16); @@ -74,7 +74,7 @@ TEST_CASE("PUS TM Reader", "[pus-tm-reader]") { } SECTION("Invalid CRC ignored") { - REQUIRE(creator.serialize(&dataPtr, &serLen, buf.size()) == HasReturnvaluesIF::RETURN_OK); + REQUIRE(creator.serializeBe(&dataPtr, &serLen, buf.size()) == HasReturnvaluesIF::RETURN_OK); buf[20] = 0; REQUIRE(reader.setReadOnlyData(buf.data(), serLen) == HasReturnvaluesIF::RETURN_OK); REQUIRE(reader.parseDataWithoutCrcCheck() == HasReturnvaluesIF::RETURN_OK); @@ -83,7 +83,7 @@ TEST_CASE("PUS TM Reader", "[pus-tm-reader]") { SECTION("Read with source data") { std::array data{1, 2, 3}; creator.setRawUserData(data.data(), data.size()); - REQUIRE(creator.serialize(&dataPtr, &serLen, buf.size()) == HasReturnvaluesIF::RETURN_OK); + REQUIRE(creator.serializeBe(&dataPtr, &serLen, buf.size()) == HasReturnvaluesIF::RETURN_OK); REQUIRE(reader.setReadOnlyData(buf.data(), serLen) == HasReturnvaluesIF::RETURN_OK); REQUIRE(reader.parseDataWithCrcCheck() == HasReturnvaluesIF::RETURN_OK); REQUIRE(reader.getUserDataLen() == 3); @@ -94,7 +94,7 @@ TEST_CASE("PUS TM Reader", "[pus-tm-reader]") { } SECTION("Invalid stream lengths") { - REQUIRE(creator.serialize(&dataPtr, &serLen, buf.size()) == HasReturnvaluesIF::RETURN_OK); + REQUIRE(creator.serializeBe(&dataPtr, &serLen, buf.size()) == HasReturnvaluesIF::RETURN_OK); for (size_t i = 0; i < serLen - 1; i++) { REQUIRE(reader.setReadOnlyData(buf.data(), i) == SerializeIF::STREAM_TOO_SHORT); } @@ -102,7 +102,7 @@ TEST_CASE("PUS TM Reader", "[pus-tm-reader]") { SECTION("Reading timestamp fails") { timeStamperAndReader.nextDeserFails = true; - REQUIRE(creator.serialize(&dataPtr, &serLen, buf.size()) == HasReturnvaluesIF::RETURN_OK); + REQUIRE(creator.serializeBe(&dataPtr, &serLen, buf.size()) == HasReturnvaluesIF::RETURN_OK); REQUIRE(reader.setReadOnlyData(buf.data(), serLen) == HasReturnvaluesIF::RETURN_OK); REQUIRE(reader.parseDataWithCrcCheck() == HasReturnvaluesIF::RETURN_FAILED); } diff --git a/unittests/tmtcpacket/testZcTmWriter.cpp b/unittests/tmtcpacket/testZcTmWriter.cpp index fc013590..da596250 100644 --- a/unittests/tmtcpacket/testZcTmWriter.cpp +++ b/unittests/tmtcpacket/testZcTmWriter.cpp @@ -18,7 +18,7 @@ TEST_CASE("TM ZC Helper", "[tm-zc-helper]") { size_t serLen = 0; SECTION("No Crash For Uninitialized Object") { - REQUIRE(creator.serialize(dataPtr, serLen, buf.size()) == result::OK); + REQUIRE(creator.serializeBe(dataPtr, serLen, buf.size()) == result::OK); PusTmZeroCopyWriter writer(timeStamper, dataPtr, serLen); REQUIRE(writer.getSequenceCount() == 22); writer.setSequenceCount(23); @@ -28,7 +28,7 @@ TEST_CASE("TM ZC Helper", "[tm-zc-helper]") { } SECTION("Basic") { - REQUIRE(creator.serialize(dataPtr, serLen, buf.size()) == result::OK); + REQUIRE(creator.serializeBe(dataPtr, serLen, buf.size()) == result::OK); PusTmZeroCopyWriter writer(timeStamper, dataPtr, serLen); REQUIRE(writer.parseDataWithoutCrcCheck() == result::OK); REQUIRE(writer.getSequenceCount() == 22); diff --git a/unittests/util/testUnsignedByteField.cpp b/unittests/util/testUnsignedByteField.cpp index 9a67c092..83ffd3c6 100644 --- a/unittests/util/testUnsignedByteField.cpp +++ b/unittests/util/testUnsignedByteField.cpp @@ -1,10 +1,9 @@ +#include #include #include "fsfw/util/UnsignedByteField.h" -#include - TEST_CASE("Unsigned Byte Field", "[unsigned-byte-field]") { auto testByteField = UnsignedByteField(10); auto u32ByteField = U32ByteField(10); @@ -28,7 +27,8 @@ TEST_CASE("Unsigned Byte Field", "[unsigned-byte-field]") { } SECTION("Serialize U32") { - CHECK(testByteField.serializeBe(buf.data(), serLen, buf.size()) == HasReturnvaluesIF::RETURN_OK); + CHECK(testByteField.serializeBe(buf.data(), serLen, buf.size()) == + HasReturnvaluesIF::RETURN_OK); CHECK(serLen == 4); CHECK(buf[0] == 0); CHECK(buf[3] == 10); @@ -60,7 +60,8 @@ TEST_CASE("Unsigned Byte Field", "[unsigned-byte-field]") { buf[2] = 0x30; buf[3] = 0x20; size_t deserLen = 0; - CHECK(testByteField.deSerializeBe(buf.data(), deserLen, buf.size()) == HasReturnvaluesIF::RETURN_OK); + CHECK(testByteField.deSerializeBe(buf.data(), deserLen, buf.size()) == + HasReturnvaluesIF::RETURN_OK); CHECK(testByteField.getValue() == 0x50403020); } @@ -68,7 +69,8 @@ TEST_CASE("Unsigned Byte Field", "[unsigned-byte-field]") { buf[0] = 0x50; buf[1] = 0x40; size_t deserLen = 0; - CHECK(u16ByteField.deSerializeBe(buf.data(), deserLen, buf.size()) == HasReturnvaluesIF::RETURN_OK); + CHECK(u16ByteField.deSerializeBe(buf.data(), deserLen, buf.size()) == + HasReturnvaluesIF::RETURN_OK); CHECK(u16ByteField.getValue() == 0x5040); } } \ No newline at end of file -- 2.43.0 From d815f422c394bb87ccf9e9d306cb42bd01f162bc Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Tue, 16 Aug 2022 17:09:22 +0200 Subject: [PATCH 105/108] improve verif reporter API --- src/fsfw/tmtcservices/VerificationReporter.cpp | 2 +- src/fsfw/tmtcservices/VerificationReporter.h | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/fsfw/tmtcservices/VerificationReporter.cpp b/src/fsfw/tmtcservices/VerificationReporter.cpp index 2eb0c771..cce8f95d 100644 --- a/src/fsfw/tmtcservices/VerificationReporter.cpp +++ b/src/fsfw/tmtcservices/VerificationReporter.cpp @@ -7,7 +7,7 @@ object_id_t VerificationReporter::DEFAULT_RECEIVER = objects::PUS_SERVICE_1_VERIFICATION; object_id_t VerificationReporter::DEFAULT_REPORTER = objects::TC_VERIFICATOR; -VerificationReporter::VerificationReporter(AcceptsVerifyMessageIF* receiver, object_id_t objectId) +VerificationReporter::VerificationReporter(object_id_t objectId, AcceptsVerifyMessageIF* receiver) : SystemObject(objectId) { if (receiver != nullptr) { acknowledgeQueue = receiver->getVerificationQueue(); diff --git a/src/fsfw/tmtcservices/VerificationReporter.h b/src/fsfw/tmtcservices/VerificationReporter.h index 78c60962..5fb67f74 100644 --- a/src/fsfw/tmtcservices/VerificationReporter.h +++ b/src/fsfw/tmtcservices/VerificationReporter.h @@ -27,8 +27,8 @@ class VerificationReporter : public SystemObject, public VerificationReporterIF friend void Factory::setStaticFrameworkObjectIds(); public: - explicit VerificationReporter(AcceptsVerifyMessageIF* receiver, - object_id_t objectId = DEFAULT_REPORTER); + explicit VerificationReporter(object_id_t objectId = DEFAULT_REPORTER, + AcceptsVerifyMessageIF* receiver = nullptr); ~VerificationReporter() override; void setReceiver(AcceptsVerifyMessageIF& receiver); -- 2.43.0 From 8fd8a37f59a9b596c36064576b920db5e8f21992 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Tue, 16 Aug 2022 17:10:48 +0200 Subject: [PATCH 106/108] flip verif reporter ctor arguments --- src/fsfw/tmtcservices/VerificationReporter.cpp | 2 +- src/fsfw/tmtcservices/VerificationReporter.h | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/fsfw/tmtcservices/VerificationReporter.cpp b/src/fsfw/tmtcservices/VerificationReporter.cpp index 2eb0c771..cce8f95d 100644 --- a/src/fsfw/tmtcservices/VerificationReporter.cpp +++ b/src/fsfw/tmtcservices/VerificationReporter.cpp @@ -7,7 +7,7 @@ object_id_t VerificationReporter::DEFAULT_RECEIVER = objects::PUS_SERVICE_1_VERIFICATION; object_id_t VerificationReporter::DEFAULT_REPORTER = objects::TC_VERIFICATOR; -VerificationReporter::VerificationReporter(AcceptsVerifyMessageIF* receiver, object_id_t objectId) +VerificationReporter::VerificationReporter(object_id_t objectId, AcceptsVerifyMessageIF* receiver) : SystemObject(objectId) { if (receiver != nullptr) { acknowledgeQueue = receiver->getVerificationQueue(); diff --git a/src/fsfw/tmtcservices/VerificationReporter.h b/src/fsfw/tmtcservices/VerificationReporter.h index 78c60962..5fb67f74 100644 --- a/src/fsfw/tmtcservices/VerificationReporter.h +++ b/src/fsfw/tmtcservices/VerificationReporter.h @@ -27,8 +27,8 @@ class VerificationReporter : public SystemObject, public VerificationReporterIF friend void Factory::setStaticFrameworkObjectIds(); public: - explicit VerificationReporter(AcceptsVerifyMessageIF* receiver, - object_id_t objectId = DEFAULT_REPORTER); + explicit VerificationReporter(object_id_t objectId = DEFAULT_REPORTER, + AcceptsVerifyMessageIF* receiver = nullptr); ~VerificationReporter() override; void setReceiver(AcceptsVerifyMessageIF& receiver); -- 2.43.0 From 875174c4ad9524b9d1da0b9ed365e820646673ae Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Tue, 16 Aug 2022 17:17:45 +0200 Subject: [PATCH 107/108] better name for global object --- src/fsfw/objectmanager/frameworkObjects.h | 2 +- src/fsfw/tcdistribution/PusDistributor.cpp | 2 +- src/fsfw/tmtcservices/CommandingServiceBase.cpp | 2 +- src/fsfw/tmtcservices/PusServiceBase.cpp | 2 +- src/fsfw/tmtcservices/VerificationReporter.cpp | 2 +- unittests/tmtcservices/testPsb.cpp | 2 +- 6 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/fsfw/objectmanager/frameworkObjects.h b/src/fsfw/objectmanager/frameworkObjects.h index be664621..9487147d 100644 --- a/src/fsfw/objectmanager/frameworkObjects.h +++ b/src/fsfw/objectmanager/frameworkObjects.h @@ -33,7 +33,7 @@ enum framework_objects : object_id_t { TC_STORE = 0x534f0100, TM_STORE = 0x534f0200, TIME_STAMPER = 0x53500010, - TC_VERIFICATOR = 0x53500020, + VERIFICATION_REPORTER = 0x53500020, FSFW_OBJECTS_END = 0x53ffffff, NO_OBJECT = 0xFFFFFFFF diff --git a/src/fsfw/tcdistribution/PusDistributor.cpp b/src/fsfw/tcdistribution/PusDistributor.cpp index ade49201..bb8708cd 100644 --- a/src/fsfw/tcdistribution/PusDistributor.cpp +++ b/src/fsfw/tcdistribution/PusDistributor.cpp @@ -137,7 +137,7 @@ ReturnValue_t PusDistributor::initialize() { return ObjectManagerIF::CHILD_INIT_FAILED; } if (verifyChannel == nullptr) { - verifyChannel = ObjectManager::instance()->get(objects::TC_VERIFICATOR); + verifyChannel = ObjectManager::instance()->get(objects::VERIFICATION_REPORTER); if (verifyChannel == nullptr) { return ObjectManagerIF::CHILD_INIT_FAILED; } diff --git a/src/fsfw/tmtcservices/CommandingServiceBase.cpp b/src/fsfw/tmtcservices/CommandingServiceBase.cpp index d7e3b514..7856abd0 100644 --- a/src/fsfw/tmtcservices/CommandingServiceBase.cpp +++ b/src/fsfw/tmtcservices/CommandingServiceBase.cpp @@ -124,7 +124,7 @@ ReturnValue_t CommandingServiceBase::initialize() { if (verificationReporter == nullptr) { verificationReporter = - ObjectManager::instance()->get(objects::TC_VERIFICATOR); + ObjectManager::instance()->get(objects::VERIFICATION_REPORTER); if (verificationReporter == nullptr) { return ObjectManagerIF::CHILD_INIT_FAILED; } diff --git a/src/fsfw/tmtcservices/PusServiceBase.cpp b/src/fsfw/tmtcservices/PusServiceBase.cpp index b555449b..0319652d 100644 --- a/src/fsfw/tmtcservices/PusServiceBase.cpp +++ b/src/fsfw/tmtcservices/PusServiceBase.cpp @@ -126,7 +126,7 @@ ReturnValue_t PusServiceBase::initialize() { if (psbParams.verifReporter == nullptr) { psbParams.verifReporter = - ObjectManager::instance()->get(objects::TC_VERIFICATOR); + ObjectManager::instance()->get(objects::VERIFICATION_REPORTER); if (psbParams.verifReporter == nullptr) { return ObjectManagerIF::CHILD_INIT_FAILED; } diff --git a/src/fsfw/tmtcservices/VerificationReporter.cpp b/src/fsfw/tmtcservices/VerificationReporter.cpp index cce8f95d..46d3eba1 100644 --- a/src/fsfw/tmtcservices/VerificationReporter.cpp +++ b/src/fsfw/tmtcservices/VerificationReporter.cpp @@ -5,7 +5,7 @@ #include "fsfw/tmtcservices/PusVerificationReport.h" object_id_t VerificationReporter::DEFAULT_RECEIVER = objects::PUS_SERVICE_1_VERIFICATION; -object_id_t VerificationReporter::DEFAULT_REPORTER = objects::TC_VERIFICATOR; +object_id_t VerificationReporter::DEFAULT_REPORTER = objects::VERIFICATION_REPORTER; VerificationReporter::VerificationReporter(object_id_t objectId, AcceptsVerifyMessageIF* receiver) : SystemObject(objectId) { diff --git a/unittests/tmtcservices/testPsb.cpp b/unittests/tmtcservices/testPsb.cpp index 464fb3da..7f33c0dc 100644 --- a/unittests/tmtcservices/testPsb.cpp +++ b/unittests/tmtcservices/testPsb.cpp @@ -211,7 +211,7 @@ TEST_CASE("Pus Service Base", "[pus-service-base]") { SECTION("Auto Initialize Verification Reporter") { psbParams.verifReporter = nullptr; psbParams.objectId = 1; - object_id_t reporterId = objects::TC_VERIFICATOR; + object_id_t reporterId = objects::VERIFICATION_REPORTER; PusVerificationReporterMock otherReporter(reporterId); auto psb2 = PsbMock(psbParams); REQUIRE(psb2.initialize() == result::OK); -- 2.43.0 From 239d053562d87da5b68bd10538a3ebe9171cd71d Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Tue, 16 Aug 2022 17:23:10 +0200 Subject: [PATCH 108/108] update changelog --- CHANGELOG.md | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index bf50b683..bfca814b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,10 +8,19 @@ and this project adheres to [Semantic Versioning](http://semver.org/). # [unreleased] +# [v6.0.0] + ## Added - Add new `UnsignedByteField` class +## Changes + +- Overhaul of the TMTC stack, including various changes and improvements + for other modules + PR: https://egit.irs.uni-stuttgart.de/fsfw/fsfw/pulls/655 + which also includes a migration guide + # [v5.0.0] 25.07.2022 ## Changes -- 2.43.0