diff --git a/src/fsfw/devicehandlers/DeviceHandlerBase.cpp b/src/fsfw/devicehandlers/DeviceHandlerBase.cpp index 5eb45685c..f3cfcee48 100644 --- a/src/fsfw/devicehandlers/DeviceHandlerBase.cpp +++ b/src/fsfw/devicehandlers/DeviceHandlerBase.cpp @@ -446,9 +446,6 @@ ReturnValue_t DeviceHandlerBase::insertInReplyMap(DeviceCommandId_t replyId, info.dataSet = dataSet; info.command = deviceCommandMap.end(); info.countdown = countdown; - if (info.periodic) { - info.active = true; - } auto resultPair = deviceReplyMap.emplace(replyId, info); if (resultPair.second) { return RETURN_OK; @@ -522,8 +519,10 @@ ReturnValue_t DeviceHandlerBase::updatePeriodicReply(bool enable, DeviceCommandI } if (enable) { info->delayCycles = info->maxDelayCycles; + info->active = true; } else { info->delayCycles = 0; + info->active = false; } } return HasReturnvaluesIF::RETURN_OK; @@ -999,6 +998,8 @@ ReturnValue_t DeviceHandlerBase::enableReplyInReplyMap(DeviceCommandMap::iterato } if (iter != deviceReplyMap.end()) { DeviceReplyInfo* info = &(iter->second); + // If a countdown has been set, the delay cycles will be ignored and the reply times out + // as soon as the countdown has expired info->delayCycles = info->maxDelayCycles; info->command = command; command->second.expectedReplies = expectedReplies; diff --git a/tests/src/fsfw_tests/unit/devicehandler/DeviceHandlerMock.cpp b/tests/src/fsfw_tests/unit/devicehandler/DeviceHandlerMock.cpp index 7350d5798..a17da98b1 100644 --- a/tests/src/fsfw_tests/unit/devicehandler/DeviceHandlerMock.cpp +++ b/tests/src/fsfw_tests/unit/devicehandler/DeviceHandlerMock.cpp @@ -93,3 +93,11 @@ void DeviceHandlerMock::changeSimpleCommandReplyCountdown(uint32_t timeout) { void DeviceHandlerMock::resetPeriodicReplyState() { periodicReplyReceived = false; } bool DeviceHandlerMock::getPeriodicReplyReceived() { return periodicReplyReceived; } + +ReturnValue_t DeviceHandlerMock::enablePeriodicReply(DeviceCommandId_t replyId) { + return updatePeriodicReply(true, replyId); +} + +ReturnValue_t DeviceHandlerMock::disablePeriodicReply(DeviceCommandId_t replyId) { + return updatePeriodicReply(false, replyId); +} diff --git a/tests/src/fsfw_tests/unit/devicehandler/DeviceHandlerMock.h b/tests/src/fsfw_tests/unit/devicehandler/DeviceHandlerMock.h index 1ab1d90b0..f5fcb4aad 100644 --- a/tests/src/fsfw_tests/unit/devicehandler/DeviceHandlerMock.h +++ b/tests/src/fsfw_tests/unit/devicehandler/DeviceHandlerMock.h @@ -18,6 +18,8 @@ class DeviceHandlerMock : public DeviceHandlerBase { void changeSimpleCommandReplyCountdown(uint32_t timeout); void resetPeriodicReplyState(); bool getPeriodicReplyReceived(); + ReturnValue_t enablePeriodicReply(DeviceCommandId_t replyId); + ReturnValue_t disablePeriodicReply(DeviceCommandId_t replyId); protected: void doStartUp() override; diff --git a/tests/src/fsfw_tests/unit/devicehandler/TestDeviceHandlerBase.cpp b/tests/src/fsfw_tests/unit/devicehandler/TestDeviceHandlerBase.cpp index dd9e9ca55..99d3816f5 100644 --- a/tests/src/fsfw_tests/unit/devicehandler/TestDeviceHandlerBase.cpp +++ b/tests/src/fsfw_tests/unit/devicehandler/TestDeviceHandlerBase.cpp @@ -60,6 +60,7 @@ TEST_CASE("Device Handler Base", "[DeviceHandlerBase]") { SECTION("Periodic reply nominal") { comIF.setTestCase(ComIFMock::TestCase::PERIODIC_REPLY_NOMINAL); + deviceHandlerMock.enablePeriodicReply(DeviceHandlerMock::PERIODIC_REPLY); deviceHandlerMock.performOperation(DeviceHandlerIF::PERFORM_OPERATION); deviceHandlerMock.performOperation(DeviceHandlerIF::SEND_WRITE); deviceHandlerMock.performOperation(DeviceHandlerIF::GET_WRITE); @@ -72,6 +73,7 @@ TEST_CASE("Device Handler Base", "[DeviceHandlerBase]") { comIF.setTestCase(ComIFMock::TestCase::MISSED_REPLY); // Set the timeout to 0 to immediately timeout the reply deviceHandlerMock.changePeriodicReplyCountdown(0); + deviceHandlerMock.enablePeriodicReply(DeviceHandlerMock::PERIODIC_REPLY); deviceHandlerMock.performOperation(DeviceHandlerIF::PERFORM_OPERATION); deviceHandlerMock.performOperation(DeviceHandlerIF::SEND_WRITE); deviceHandlerMock.performOperation(DeviceHandlerIF::GET_WRITE); @@ -79,5 +81,15 @@ TEST_CASE("Device Handler Base", "[DeviceHandlerBase]") { deviceHandlerMock.performOperation(DeviceHandlerIF::GET_READ); uint32_t missedReplies = deviceFdirMock.getMissedReplyCount(); REQUIRE(missedReplies == 1); + // Test if disabling of periodic reply + deviceHandlerMock.disablePeriodicReply(DeviceHandlerMock::PERIODIC_REPLY); + deviceHandlerMock.performOperation(DeviceHandlerIF::PERFORM_OPERATION); + deviceHandlerMock.performOperation(DeviceHandlerIF::SEND_WRITE); + deviceHandlerMock.performOperation(DeviceHandlerIF::GET_WRITE); + deviceHandlerMock.performOperation(DeviceHandlerIF::SEND_READ); + deviceHandlerMock.performOperation(DeviceHandlerIF::GET_READ); + missedReplies = deviceFdirMock.getMissedReplyCount(); + // Should still be 1 because periodic reply is now disabled + REQUIRE(missedReplies == 1); } }