From ad88bfa5b4b1085fd893d7942ff926eba94fd70f Mon Sep 17 00:00:00 2001 From: Ulrich Mohr Date: Thu, 28 Jul 2022 17:15:33 +0200 Subject: [PATCH] core controller bigWIP --- bsp_q7s/core/CoreController.cpp | 122 +++++++++-------------- bsp_q7s/core/CoreController.h | 17 +--- bsp_q7s/core/CoreDefinitions.h | 69 +++++++++++++ fsfw | 2 +- mission/controller/ThermalController.cpp | 2 +- 5 files changed, 121 insertions(+), 91 deletions(-) diff --git a/bsp_q7s/core/CoreController.cpp b/bsp_q7s/core/CoreController.cpp index e387aa71..26dcf73d 100644 --- a/bsp_q7s/core/CoreController.cpp +++ b/bsp_q7s/core/CoreController.cpp @@ -163,75 +163,53 @@ ReturnValue_t CoreController::initializeAfterTaskCreation() { return result; } -ReturnValue_t CoreController::executeAction(ActionId_t actionId, MessageQueueId_t commandedBy, - const uint8_t *data, size_t size) { - switch (actionId) { - case (LIST_DIRECTORY_INTO_FILE): { - return actionListDirectoryIntoFile(actionId, commandedBy, data, size); - } - case (SWITCH_REBOOT_FILE_HANDLING): { - if (size < 1) { - return HasActionsIF::INVALID_PARAMETERS; - } - std::string path = sdcMan->getCurrentMountPrefix() + 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_REBOOT_COUNTERS): { - if (size == 0) { - resetRebootCount(xsc::ALL_CHIP, xsc::ALL_COPY); - } else if (size == 2) { - if (data[0] > 1 or data[1] > 1) { - return HasActionsIF::INVALID_PARAMETERS; - } - resetRebootCount(static_cast(data[0]), static_cast(data[1])); - } - return HasActionsIF::EXECUTION_FINISHED; - } - case (SWITCH_IMG_LOCK): { - if (size != 3) { - return HasActionsIF::INVALID_PARAMETERS; - } - if (data[1] > 1 or data[2] > 1) { - return HasActionsIF::INVALID_PARAMETERS; - } - setRebootMechanismLock(data[0], static_cast(data[1]), - static_cast(data[2])); - return HasActionsIF::EXECUTION_FINISHED; - } - case (SET_MAX_REBOOT_CNT): { - if (size < 1) { - return HasActionsIF::INVALID_PARAMETERS; - } - std::string path = sdcMan->getCurrentMountPrefix() + REBOOT_FILE; - // Disable the reboot file mechanism - parseRebootFile(path, rebootFile); - rebootFile.maxCount = data[0]; - rewriteRebootFile(rebootFile); - return HasActionsIF::EXECUTION_FINISHED; - } - case (XSC_REBOOT_OBC): { - // Warning: This function will never return, because it reboots the system - return actionXscReboot(data, size); - } - case (REBOOT_OBC): { - // Warning: This function will never return, because it reboots the system - return actionReboot(data, size); - } - default: { - return HasActionsIF::INVALID_ACTION_ID; - } +ReturnValue_t CoreController::handleAction(SwitchRebootFileHandlingAction *action) { + std::string path = sdcMan->getCurrentMountPrefix() + REBOOT_FILE; + // Disable the reboot file mechanism + parseRebootFile(path, rebootFile); + if (action->enableRebootFile == Boolenum::NO) { + rebootFile.enabled = false; + rewriteRebootFile(rebootFile); + } else + rebootFile.enabled = true; + rewriteRebootFile(rebootFile); } + return HasActionsIF::EXECUTION_FINISHED; +} + +ReturnValue_t CoreController::handleAction(ResetRebootCountersAction *action) { + if (size == 0) { + resetRebootCount(xsc::ALL_CHIP, xsc::ALL_COPY); + } else if (size == 2) { + if (data[0] > 1 or data[1] > 1) { + return HasActionsIF::INVALID_PARAMETERS; + } + resetRebootCount(static_cast(data[0]), static_cast(data[1])); + } + return HasActionsIF::EXECUTION_FINISHED; +} + +ReturnValue_t CoreController::handleAction(SwitchImageLockAction *action) { + if (size != 3) { + return HasActionsIF::INVALID_PARAMETERS; + } + if (data[1] > 1 or data[2] > 1) { + return HasActionsIF::INVALID_PARAMETERS; + } + setRebootMechanismLock(data[0], static_cast(data[1]), static_cast(data[2])); + return HasActionsIF::EXECUTION_FINISHED; +} + +ReturnValue_t CoreController::handleAction(SetMaxRebootCntAction *action) { + if (size < 1) { + return HasActionsIF::INVALID_PARAMETERS; + } + std::string path = sdcMan->getCurrentMountPrefix() + REBOOT_FILE; + // Disable the reboot file mechanism + parseRebootFile(path, rebootFile); + rebootFile.maxCount = data[0]; + rewriteRebootFile(rebootFile); + return HasActionsIF::EXECUTION_FINISHED; } ReturnValue_t CoreController::checkModeCommand(Mode_t mode, Submode_t submode, @@ -748,9 +726,7 @@ ReturnValue_t CoreController::initVersionFile() { return HasReturnvaluesIF::RETURN_OK; } -ReturnValue_t CoreController::actionListDirectoryIntoFile(ActionId_t actionId, - MessageQueueId_t commandedBy, - const uint8_t *data, size_t size) { +ReturnValue_t CoreController::handleAction(ListDirectoryIntoFileAction *action) { // TODO: Packet definition for clean deserialization // 2 bytes for a and R flag, at least 5 bytes for minimum valid path /tmp with // null termination, at least 7 bytes for minimum target file name /tmp/a with @@ -857,7 +833,7 @@ void CoreController::initPrint() { #endif } -ReturnValue_t CoreController::actionXscReboot(const uint8_t *data, size_t size) { +ReturnValue_t CoreController::handleAction(XscRebootObcAction *action) { if (size < 1) { return HasActionsIF::INVALID_PARAMETERS; } @@ -932,7 +908,7 @@ ReturnValue_t CoreController::actionXscReboot(const uint8_t *data, size_t size) return HasReturnvaluesIF::RETURN_FAILED; } -ReturnValue_t CoreController::actionReboot(const uint8_t *data, size_t size) { +ReturnValue_t CoreController::actionReboot(RebootObcAction *action) { bool protOpPerformed = false; gracefulShutdownTasks(xsc::Chip::CHIP_0, xsc::Copy::COPY_0, protOpPerformed); std::system("reboot"); diff --git a/bsp_q7s/core/CoreController.h b/bsp_q7s/core/CoreController.h index 2ebdd4ec..274eb789 100644 --- a/bsp_q7s/core/CoreController.h +++ b/bsp_q7s/core/CoreController.h @@ -61,18 +61,6 @@ class CoreController : public ExtendedControllerBase { "/" + std::string(CONF_FOLDER) + "/" + std::string(REBOOT_FILE_NAME); const std::string TIME_FILE = "/" + std::string(CONF_FOLDER) + "/" + std::string(TIME_FILE_NAME); - static constexpr ActionId_t LIST_DIRECTORY_INTO_FILE = 0; - static constexpr ActionId_t SWITCH_REBOOT_FILE_HANDLING = 5; - static constexpr ActionId_t RESET_REBOOT_COUNTERS = 6; - static constexpr ActionId_t SWITCH_IMG_LOCK = 7; - static constexpr ActionId_t SET_MAX_REBOOT_CNT = 8; - - //! Reboot using the xsc_boot_copy command - static constexpr ActionId_t XSC_REBOOT_OBC = 32; - static constexpr ActionId_t MOUNT_OTHER_COPY = 33; - //! Reboot using the reboot command - static constexpr ActionId_t REBOOT_OBC = 34; - static constexpr uint8_t SUBSYSTEM_ID = SUBSYSTEM_ID::CORE; static constexpr Event ALLOC_FAILURE = event::makeEvent(SUBSYSTEM_ID, 0, severity::MEDIUM); @@ -94,8 +82,7 @@ class CoreController : public ExtendedControllerBase { ReturnValue_t initializeAfterTaskCreation() override; - ReturnValue_t executeAction(ActionId_t actionId, MessageQueueId_t commandedBy, - const uint8_t* data, size_t size) override; + ReturnValue_t executeAction(Action* action) override; ReturnValue_t handleCommandMessage(CommandMessage* message) override; void performControlOperation() override; @@ -224,8 +211,6 @@ class CoreController : public ExtendedControllerBase { void checkExternalSdCommandStatus(); void performRebootFileHandling(bool recreateFile); - ReturnValue_t actionListDirectoryIntoFile(ActionId_t actionId, MessageQueueId_t commandedBy, - const uint8_t* data, size_t size); ReturnValue_t actionXscReboot(const uint8_t* data, size_t size); ReturnValue_t actionReboot(const uint8_t* data, size_t size); diff --git a/bsp_q7s/core/CoreDefinitions.h b/bsp_q7s/core/CoreDefinitions.h index 91896301..fac3433f 100644 --- a/bsp_q7s/core/CoreDefinitions.h +++ b/bsp_q7s/core/CoreDefinitions.h @@ -3,8 +3,77 @@ #include +#include +#include +#include + +class CoreController; + namespace core { +FSFW_ENUM(ActionId, ActionId_t, ((LIST_DIRECTORY_INTO_FILE, 0, "List Directory into file")) +((SWITCH_REBOOT_FILE_HANDLING, 5, "Switch Reboot File Handling")) +((RESET_REBOOT_COUNTERS, 6, "Reset Boot Counters")) +((SWITCH_IMG_LOCK, 7, "Switch Image Lock")) +((SET_MAX_REBOOT_CNT, 8, "Set maximum reboot Count")) +((XSC_REBOOT_OBC, 32, "Reboot using the xsc_boot_copy command")) +((MOUNT_OTHER_COPY, 33, "Mount Other Copy")) +((REBOOT_OBC, 34, "Reboot using the reboot command"))) + +FSFW_ENUM(Boolenum, uint8_t, ((NO, 0, "NO"))((YES, 1, "Yes"))) + + +class ListDirectoryIntoFileAction : public TemplateAction { + public: + ListDirectoryIntoFileAction(CoreController *owner) + : TemplateAction(owner, ActionId::LIST_DIRECTORY_INTO_FILE){}; +}; + +class SwitchRebootFileHandlingAction : public TemplateAction { + public: + SwitchRebootFileHandlingAction(CoreController *owner) + : TemplateAction(owner, ActionId::SWITCH_REBOOT_FILE_HANDLING){}; + + Parameter enableRebootFile = Parameter::createParameter(this, "Enable Reboot File"); +}; + +class ResetRebootCountersAction : public TemplateAction { + public: + ResetRebootCountersAction(CoreController *owner) + : TemplateAction(owner, ActionId::RESET_REBOOT_COUNTERS){}; +}; + +class SwitchImageLockAction : public TemplateAction { + public: + SwitchImageLockAction(CoreController *owner) + : TemplateAction(owner, ActionId::SWITCH_IMG_LOCK){}; +}; + +class SetMaxRebootCntAction : public TemplateAction { + public: + SetMaxRebootCntAction(CoreController *owner) + : TemplateAction(owner, ActionId::SET_MAX_REBOOT_CNT){}; +}; + +class XscRebootObcAction : public TemplateAction { + public: + XscRebootObcAction(CoreController *owner) + : TemplateAction(owner, ActionId::XSC_REBOOT_OBC){}; +}; + +class MountOtherCopyAction : public TemplateAction { + public: + MountOtherCopyAction(CoreController *owner) + : TemplateAction(owner, ActionId::MOUNT_OTHER_COPY){}; +}; + +class RebootObcAction : public TemplateAction { + public: + RebootObcAction(CoreController *owner) + : TemplateAction(owner, ActionId::REBOOT_OBC){}; +}; + + static const uint8_t HK_SET_ENTRIES = 3; static const uint32_t HK_SET_ID = 5; diff --git a/fsfw b/fsfw index a1af2ceb..cfdbe0f6 160000 --- a/fsfw +++ b/fsfw @@ -1 +1 @@ -Subproject commit a1af2cebf3a53dd17e7dd948f1e698d9c4621696 +Subproject commit cfdbe0f6cb762f58f0db3f9c118c50c954f0b984 diff --git a/mission/controller/ThermalController.cpp b/mission/controller/ThermalController.cpp index 0991e803..c6674da9 100644 --- a/mission/controller/ThermalController.cpp +++ b/mission/controller/ThermalController.cpp @@ -1,6 +1,6 @@ #include "ThermalController.h" -#include +//#include #include #include #include