From 91f43d00a25ce69639c89f976bcab0e10998b570 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 | 34 +++---------------- .../tmtcpacket/pus/tm/TmPacketStoredPusC.cpp | 34 +++---------------- 4 files changed, 42 insertions(+), 61 deletions(-) diff --git a/src/fsfw/tmtcpacket/pus/tm/TmPacketStoredBase.cpp b/src/fsfw/tmtcpacket/pus/tm/TmPacketStoredBase.cpp index 466e4cd2..20a8ed89 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 8e8b9c70..91ca2f93 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 3b183f09..a8a10da6 100644 --- a/src/fsfw/tmtcpacket/pus/tm/TmPacketStoredPusA.cpp +++ b/src/fsfw/tmtcpacket/pus/tm/TmPacketStoredPusA.cpp @@ -18,11 +18,12 @@ TmPacketStoredPusA::TmPacketStoredPusA(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("A", returnValue, sizeToReserve); return; } setData(pData); @@ -53,34 +54,7 @@ TmPacketStoredPusA::TmPacketStoredPusA(uint16_t apid, uint8_t service, 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 - } + handleStoreFailure("A", returnValue, sizeToReserve); return; } setData(pData); diff --git a/src/fsfw/tmtcpacket/pus/tm/TmPacketStoredPusC.cpp b/src/fsfw/tmtcpacket/pus/tm/TmPacketStoredPusC.cpp index 570d9d4e..ee574299 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); @@ -52,34 +53,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);