From 155432663b42b73cd8a23782cdb7fc39e04509b4 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Tue, 5 Oct 2021 12:47:30 +0200 Subject: [PATCH] moved store failure to separate function --- .../tmtcpacket/pus/tm/TmPacketStoredBase.cpp | 32 +++- .../tmtcpacket/pus/tm/TmPacketStoredBase.h | 3 + .../tmtcpacket/pus/tm/TmPacketStoredPusA.cpp | 140 +++++++----------- .../tmtcpacket/pus/tm/TmPacketStoredPusA.h | 74 ++++----- .../tmtcpacket/pus/tm/TmPacketStoredPusC.cpp | 34 +---- 5 files changed, 132 insertions(+), 151 deletions(-) diff --git a/src/fsfw/tmtcpacket/pus/tm/TmPacketStoredBase.cpp b/src/fsfw/tmtcpacket/pus/tm/TmPacketStoredBase.cpp index 466e4cd20..20a8ed899 100644 --- a/src/fsfw/tmtcpacket/pus/tm/TmPacketStoredBase.cpp +++ b/src/fsfw/tmtcpacket/pus/tm/TmPacketStoredBase.cpp @@ -91,4 +91,34 @@ void TmPacketStoredBase::checkAndReportLostTm() { } } - +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 index 8e8b9c70b..91ca2f934 100644 --- a/src/fsfw/tmtcpacket/pus/tm/TmPacketStoredBase.h +++ b/src/fsfw/tmtcpacket/pus/tm/TmPacketStoredBase.h @@ -82,6 +82,9 @@ protected: bool checkAndSetStore(); void checkAndReportLostTm(); + + void handleStoreFailure(const char* const packetType, ReturnValue_t result, + size_t sizeToReserve); }; diff --git a/src/fsfw/tmtcpacket/pus/tm/TmPacketStoredPusA.cpp b/src/fsfw/tmtcpacket/pus/tm/TmPacketStoredPusA.cpp index 3b183f099..067b4f8fa 100644 --- a/src/fsfw/tmtcpacket/pus/tm/TmPacketStoredPusA.cpp +++ b/src/fsfw/tmtcpacket/pus/tm/TmPacketStoredPusA.cpp @@ -5,97 +5,71 @@ #include -TmPacketStoredPusA::TmPacketStoredPusA(store_address_t setAddress) : - TmPacketStoredBase(setAddress), TmPacketPusA(nullptr){ +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) : + 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; - ReturnValue_t returnValue = store->getFreeElement(&storeAddress, - (getPacketMinimumSize() + size + headerSize), &pData); + 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) { - TmPacketStoredBase::checkAndReportLostTm(); - return; - } - setData(pData); - initializeTmPacket(apid, service, subservice, packetSubcounter); - memcpy(getSourceData(), headerData, headerSize); - memcpy(getSourceData() + headerSize, data, size); - setPacketDataLength( - size + headerSize + sizeof(PUSTmDataFieldHeaderPusA) + CRC_SIZE - 1); + if (returnValue != store->RETURN_OK) { + handleStoreFailure("A", returnValue, sizeToReserve); + return; + } + setData(pData); + 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) { - TmPacketStoredBase::checkAndReportLostTm(); -#if FSFW_VERBOSE_LEVEL >= 1 - switch(returnValue) { -#if FSFW_CPP_OSTREAM_ENABLED == 1 - case(StorageManagerIF::DATA_STORAGE_FULL): { - sif::warning << "TmPacketStoredPusA::TmPacketStoredPusC: Store full for packet with " - "size " << sizeToReserve << std::endl; - break; - } - case(StorageManagerIF::DATA_TOO_LARGE): { - sif::warning << "TmPacketStoredPusA::TmPacketStoredPusC: Data with size " << - sizeToReserve << " too large" << std::endl; - break; - } -#else - case(StorageManagerIF::DATA_STORAGE_FULL): { - sif::printWarning("TmPacketStoredPusA::TmPacketStoredPusC: Store full for packet with " - "size %d\n", sizeToReserve); - break; - } - case(StorageManagerIF::DATA_TOO_LARGE): { - sif::printWarning("TmPacketStoredPusA::TmPacketStoredPusC: Data with size " - "%d too large\n", sizeToReserve); - break; - } -#endif -#endif - } - return; - } - setData(pData); - 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 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); + 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() { diff --git a/src/fsfw/tmtcpacket/pus/tm/TmPacketStoredPusA.h b/src/fsfw/tmtcpacket/pus/tm/TmPacketStoredPusA.h index 0cfcf0b80..6a338cd55 100644 --- a/src/fsfw/tmtcpacket/pus/tm/TmPacketStoredPusA.h +++ b/src/fsfw/tmtcpacket/pus/tm/TmPacketStoredPusA.h @@ -15,46 +15,46 @@ * packets in a store with the help of a storeAddress. * @ingroup tmtcpackets */ -class TmPacketStoredPusA : +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); + /** + * 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; void setDataPointer(const uint8_t* newPointer) override; diff --git a/src/fsfw/tmtcpacket/pus/tm/TmPacketStoredPusC.cpp b/src/fsfw/tmtcpacket/pus/tm/TmPacketStoredPusC.cpp index 4a6e4d216..2fbc80431 100644 --- a/src/fsfw/tmtcpacket/pus/tm/TmPacketStoredPusC.cpp +++ b/src/fsfw/tmtcpacket/pus/tm/TmPacketStoredPusC.cpp @@ -19,11 +19,12 @@ TmPacketStoredPusC::TmPacketStoredPusC(uint16_t apid, uint8_t service, return; } uint8_t *pData = nullptr; + size_t sizeToReserve = getPacketMinimumSize() + size + headerSize; ReturnValue_t returnValue = store->getFreeElement(&storeAddress, - (getPacketMinimumSize() + size + headerSize), &pData); + sizeToReserve, &pData); if (returnValue != store->RETURN_OK) { - TmPacketStoredBase::checkAndReportLostTm(); + handleStoreFailure("C", returnValue, sizeToReserve); return; } setData(pData); @@ -53,34 +54,7 @@ TmPacketStoredPusC::TmPacketStoredPusC(uint16_t apid, uint8_t service, size_t sizeToReserve = getPacketMinimumSize() + sourceDataSize; ReturnValue_t returnValue = store->getFreeElement(&storeAddress, sizeToReserve, &pData); if (returnValue != store->RETURN_OK) { -#if FSFW_VERBOSE_LEVEL >= 1 - switch(returnValue) { -#if FSFW_CPP_OSTREAM_ENABLED == 1 - case(StorageManagerIF::DATA_STORAGE_FULL): { - sif::warning << "TmPacketStoredPusC::TmPacketStoredPusC: Store full for packet with " - "size " << sizeToReserve << std::endl; - break; - } - case(StorageManagerIF::DATA_TOO_LARGE): { - sif::warning << "TmPacketStoredPusC::TmPacketStoredPusC: Data with size " << - sizeToReserve << " too large" << std::endl; - break; - } -#else - case(StorageManagerIF::DATA_STORAGE_FULL): { - sif::printWarning("TmPacketStoredPusC::TmPacketStoredPusC: Store full for packet with " - "size %d\n", sizeToReserve); - break; - } - case(StorageManagerIF::DATA_TOO_LARGE): { - sif::printWarning("TmPacketStoredPusC::TmPacketStoredPusC: Data with size " - "%d too large\n", sizeToReserve); - break; - } -#endif -#endif - } - TmPacketStoredBase::checkAndReportLostTm(); + handleStoreFailure("C", returnValue, sizeToReserve); return; } setData(pData);