From d4dcd8c03fa77587c03bada4d5ed85f565fadf5f Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Mon, 28 Feb 2022 16:55:49 +0100 Subject: [PATCH] added missing command --- bsp_q7s/core/CoreController.cpp | 11 +++++ unittest/rebootLogic/CoreController.cpp | 59 +++++++++++++++++++++++++ unittest/rebootLogic/CoreController.h | 12 +++++ unittest/rebootLogic/HasActionsIF.h | 9 ++++ unittest/rebootLogic/definitions.h | 5 +++ 5 files changed, 96 insertions(+) create mode 100644 unittest/rebootLogic/HasActionsIF.h create mode 100644 unittest/rebootLogic/definitions.h diff --git a/bsp_q7s/core/CoreController.cpp b/bsp_q7s/core/CoreController.cpp index 7acbd9ff..189fed8e 100644 --- a/bsp_q7s/core/CoreController.cpp +++ b/bsp_q7s/core/CoreController.cpp @@ -151,6 +151,17 @@ ReturnValue_t CoreController::executeAction(ActionId_t actionId, MessageQueueId_ resetRebootCount(xsc::CHIP_1, xsc::COPY_1); return HasActionsIF::EXECUTION_FINISHED; } + case(SET_MAX_REBOOT_CNT): { + if(size < 1) { + return HasActionsIF::INVALID_PARAMETERS; + } + std::string path = sdcMan->getCurrentMountPrefix(sdInfo.pref) + REBOOT_FILE; + // Disable the reboot file mechanism + parseRebootFile(path, rebootFile); + rebootFile.maxCount = data[0]; + rewriteRebootFile(rebootFile); + return HasActionsIF::EXECUTION_FINISHED; + } case (REBOOT_OBC): { return actionPerformReboot(data, size); } diff --git a/unittest/rebootLogic/CoreController.cpp b/unittest/rebootLogic/CoreController.cpp index 34133ccf..a4949601 100644 --- a/unittest/rebootLogic/CoreController.cpp +++ b/unittest/rebootLogic/CoreController.cpp @@ -1,4 +1,5 @@ #include "conf.h" +#include "HasActionsIF.h" #include "CoreController.h" #include "SdCardManager.h" #include "event.h" @@ -366,3 +367,61 @@ void CoreController::rewriteRebootFile(RebootFile file) { << static_cast(file.lastCopy) << "\n"; } } + +ReturnValue_t CoreController::executeAction(ActionId_t actionId, MessageQueueId_t commandedBy, + const uint8_t *data, size_t size) { +switch (actionId) { + case (SWITCH_REBOOT_FILE_HANDLING): { + if (size < 1) { + return HasActionsIF::INVALID_PARAMETERS; + } + std::string path = sdcMan->getCurrentMountPrefix(sdInfo.pref) + REBOOT_FILE; + // Disable the reboot file mechanism + parseRebootFile(path, rebootFile); + if (data[0] == 0) { + rebootFile.enabled = false; + rewriteRebootFile(rebootFile); + } else if (data[0] == 1) { + rebootFile.enabled = true; + rewriteRebootFile(rebootFile); + } else { + return HasActionsIF::INVALID_PARAMETERS; + } + return HasActionsIF::EXECUTION_FINISHED; + } + case (RESET_ALL_REBOOT_COUNTERS): { + resetRebootCount(xsc::ALL_CHIP, xsc::ALL_COPY); + return HasActionsIF::EXECUTION_FINISHED; + } + case (RESET_REBOOT_COUNTER_00): { + resetRebootCount(xsc::CHIP_0, xsc::COPY_0); + return HasActionsIF::EXECUTION_FINISHED; + } + case (RESET_REBOOT_COUNTER_01): { + resetRebootCount(xsc::CHIP_0, xsc::COPY_1); + return HasActionsIF::EXECUTION_FINISHED; + } + case (RESET_REBOOT_COUNTER_10): { + resetRebootCount(xsc::CHIP_1, xsc::COPY_0); + return HasActionsIF::EXECUTION_FINISHED; + } + case (RESET_REBOOT_COUNTER_11): { + resetRebootCount(xsc::CHIP_1, xsc::COPY_1); + return HasActionsIF::EXECUTION_FINISHED; + } + case(SET_MAX_REBOOT_CNT): { + if(size < 1) { + return HasActionsIF::INVALID_PARAMETERS; + } + std::string path = sdcMan->getCurrentMountPrefix(sdInfo.pref) + REBOOT_FILE; + // Disable the reboot file mechanism + parseRebootFile(path, rebootFile); + rebootFile.maxCount = data[0]; + rewriteRebootFile(rebootFile); + return HasActionsIF::EXECUTION_FINISHED; + } + default: { + return HasActionsIF::INVALID_ACTION_ID; + } + } +} \ No newline at end of file diff --git a/unittest/rebootLogic/CoreController.h b/unittest/rebootLogic/CoreController.h index 209db0da..0fa4e0c7 100644 --- a/unittest/rebootLogic/CoreController.h +++ b/unittest/rebootLogic/CoreController.h @@ -1,5 +1,6 @@ #pragma once +#include "definitions.h" #include "SdCardManager.h" #include @@ -38,7 +39,18 @@ public: static xsc::Chip CURRENT_CHIP; static xsc::Copy CURRENT_COPY; + static constexpr ActionId_t SWITCH_REBOOT_FILE_HANDLING = 5; + static constexpr ActionId_t RESET_ALL_REBOOT_COUNTERS = 6; + static constexpr ActionId_t RESET_REBOOT_COUNTER_00 = 7; + static constexpr ActionId_t RESET_REBOOT_COUNTER_01 = 8; + static constexpr ActionId_t RESET_REBOOT_COUNTER_10 = 9; + static constexpr ActionId_t RESET_REBOOT_COUNTER_11 = 10; + static constexpr ActionId_t SET_MAX_REBOOT_CNT = 11; + CoreController(); + + ReturnValue_t executeAction(ActionId_t actionId, MessageQueueId_t commandedBy, + const uint8_t* data, size_t size); void performRebootFileHandling(bool recreateFile); void determineAndExecuteReboot(RebootFile& rf, bool& needsReboot, xsc::Chip& tgtChip, xsc::Copy& tgtCopy); diff --git a/unittest/rebootLogic/HasActionsIF.h b/unittest/rebootLogic/HasActionsIF.h new file mode 100644 index 00000000..773ad54f --- /dev/null +++ b/unittest/rebootLogic/HasActionsIF.h @@ -0,0 +1,9 @@ +#include "definitions.h" + +class HasActionsIF { +public: + static const ReturnValue_t IS_BUSY = 1; + static const ReturnValue_t INVALID_PARAMETERS = 2; + static const ReturnValue_t EXECUTION_FINISHED = 3; + static const ReturnValue_t INVALID_ACTION_ID = 4; +}; diff --git a/unittest/rebootLogic/definitions.h b/unittest/rebootLogic/definitions.h new file mode 100644 index 00000000..377d2e23 --- /dev/null +++ b/unittest/rebootLogic/definitions.h @@ -0,0 +1,5 @@ +#include + +using ActionId_t = uint32_t; +using MessageQueueId_t = uint32_t; +using ReturnValue_t = uint16_t;