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"