From 13cc31dca9e15f9c87eef982a601c737a7db0f6f Mon Sep 17 00:00:00 2001 From: Ulrich Mohr Date: Tue, 16 Aug 2022 18:31:58 +0200 Subject: [PATCH] working on core controller --- bsp_q7s/core/CoreActions.h | 84 +++++++++++++++++ bsp_q7s/core/CoreController.cpp | 110 ++++++++++++++--------- bsp_q7s/core/CoreController.h | 10 +++ bsp_q7s/core/CoreDefinitions.h | 69 -------------- mission/controller/ThermalController.cpp | 2 +- 5 files changed, 161 insertions(+), 114 deletions(-) create mode 100644 bsp_q7s/core/CoreActions.h diff --git a/bsp_q7s/core/CoreActions.h b/bsp_q7s/core/CoreActions.h new file mode 100644 index 00000000..672b9cda --- /dev/null +++ b/bsp_q7s/core/CoreActions.h @@ -0,0 +1,84 @@ +#pragma once + +#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: + FSFW_ENUM(Selection, uint8_t, ((ZERO, "0"))((ONE, "1"))((ALL, "All"))) + + ResetRebootCountersAction(CoreController *owner) + : TemplateAction(owner, ActionId::RESET_REBOOT_COUNTERS){}; + + Parameter chip = Parameter::createParameter(this, "Chip"); + Parameter copy = Parameter::createParameter(this, "Copy"); +}; + +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: + FSFW_ENUM(Selection, uint8_t, ((ZERO, "0"))((ONE, "1"))((SAME, "Same"))) + XscRebootObcAction(CoreController *owner) : TemplateAction(owner, ActionId::XSC_REBOOT_OBC){}; + + Parameter chip = Parameter::createParameter(this, "Chip"); + Parameter copy = Parameter::createParameter(this, "Copy"); +}; + +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){}; +}; + +} // namespace core diff --git a/bsp_q7s/core/CoreController.cpp b/bsp_q7s/core/CoreController.cpp index 26dcf73d..eee9be2e 100644 --- a/bsp_q7s/core/CoreController.cpp +++ b/bsp_q7s/core/CoreController.cpp @@ -163,33 +163,51 @@ ReturnValue_t CoreController::initializeAfterTaskCreation() { return result; } -ReturnValue_t CoreController::handleAction(SwitchRebootFileHandlingAction *action) { +ReturnValue_t CoreController::handleAction(core::SwitchRebootFileHandlingAction *action) { std::string path = sdcMan->getCurrentMountPrefix() + REBOOT_FILE; // Disable the reboot file mechanism parseRebootFile(path, rebootFile); - if (action->enableRebootFile == Boolenum::NO) { + if (action->enableRebootFile == core::Boolenum::NO) { rebootFile.enabled = false; rewriteRebootFile(rebootFile); - } else + } 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])); +ReturnValue_t CoreController::handleAction(core::ResetRebootCountersAction *action) { + xsc::Chip chip = xsc::NO_CHIP; + switch (action->chip) { + case core::ResetRebootCountersAction::Selection::ALL: + chip = xsc::ALL_CHIP; + break; + case core::ResetRebootCountersAction::Selection::ZERO: + chip = xsc::CHIP_0; + break; + case core::ResetRebootCountersAction::Selection::ONE: + chip = xsc::CHIP_1; + break; } + xsc::Copy copy = xsc::NO_COPY; + switch (action->copy) { + case core::ResetRebootCountersAction::Selection::ALL: + copy = xsc::ALL_COPY; + break; + case core::ResetRebootCountersAction::Selection::ZERO: + copy = xsc::COPY_0; + break; + case core::ResetRebootCountersAction::Selection::ONE: + copy = xsc::COPY_1; + break; + } + resetRebootCount(chip, copy); + return HasActionsIF::EXECUTION_FINISHED; } -ReturnValue_t CoreController::handleAction(SwitchImageLockAction *action) { +ReturnValue_t CoreController::handleAction(core::SwitchImageLockAction *action) { if (size != 3) { return HasActionsIF::INVALID_PARAMETERS; } @@ -200,7 +218,7 @@ ReturnValue_t CoreController::handleAction(SwitchImageLockAction *action) { return HasActionsIF::EXECUTION_FINISHED; } -ReturnValue_t CoreController::handleAction(SetMaxRebootCntAction *action) { +ReturnValue_t CoreController::handleAction(core::SetMaxRebootCntAction *action) { if (size < 1) { return HasActionsIF::INVALID_PARAMETERS; } @@ -726,7 +744,7 @@ ReturnValue_t CoreController::initVersionFile() { return HasReturnvaluesIF::RETURN_OK; } -ReturnValue_t CoreController::handleAction(ListDirectoryIntoFileAction *action) { +ReturnValue_t CoreController::handleAction(core::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 @@ -774,7 +792,7 @@ ReturnValue_t CoreController::handleAction(ListDirectoryIntoFileAction *action) int result = std::system(oss.str().c_str()); if (result != 0) { utility::handleSystemError(result, "CoreController::actionListDirectoryIntoFile"); - actionHelper.finish(false, commandedBy, actionId); + actionHelper.finish(false, action->commandedBy, action->id); } return HasReturnvaluesIF::RETURN_OK; } @@ -833,11 +851,16 @@ void CoreController::initPrint() { #endif } -ReturnValue_t CoreController::handleAction(XscRebootObcAction *action) { - if (size < 1) { +ReturnValue_t CoreController::handleAction(core::XscRebootObcAction *action) { + if (action->chip == core::XscRebootObcAction::Selection::SAME and + not(action->copy == core::XscRebootObcAction::Selection::SAME)) { return HasActionsIF::INVALID_PARAMETERS; } - bool rebootSameBootCopy = data[0]; + bool rebootSameBootCopy = false; + if (action->chip == core::XscRebootObcAction::Selection::SAME and + action->copy == core::XscRebootObcAction::Selection::SAME) { + rebootSameBootCopy = true; + } bool protOpPerformed = false; SdCardManager::instance()->setBlocking(true); if (rebootSameBootCopy) { @@ -852,19 +875,22 @@ ReturnValue_t CoreController::handleAction(XscRebootObcAction *action) { } return HasActionsIF::EXECUTION_FINISHED; } - if (size < 3 or (data[1] > 1 or data[2] > 1)) { - return HasActionsIF::INVALID_PARAMETERS; - } #if OBSW_VERBOSE_LEVEL >= 1 - sif::info << "CoreController::actionPerformReboot: Rebooting on " << static_cast(data[1]) - << " " << static_cast(data[2]) << std::endl; + sif::info << "CoreController::actionPerformReboot: Rebooting on " << static_cast(action->chip) + << " " << static_cast(action->copy) << std::endl; #endif // Check that the target chip and copy is writeprotected first generateChipStateFile(); // If any boot copies are unprotected, protect them here - auto tgtChip = static_cast(data[1]); - auto tgtCopy = static_cast(data[2]); + auto tgtChip = xsc::CHIP_0; + if (action->chip == core::XscRebootObcAction::Selection::ONE){ + tgtChip == xsc::CHIP_1; + } + auto tgtCopy = xsc::COPY_0; + if (action->copy == core::XscRebootObcAction::Selection::ONE){ + tgtCopy = xsc::COPY_1; + } // This function can not really fail gracefulShutdownTasks(tgtChip, tgtCopy, protOpPerformed); @@ -908,7 +934,7 @@ ReturnValue_t CoreController::handleAction(XscRebootObcAction *action) { return HasReturnvaluesIF::RETURN_FAILED; } -ReturnValue_t CoreController::actionReboot(RebootObcAction *action) { +ReturnValue_t CoreController::handleAction(core::RebootObcAction *action) { bool protOpPerformed = false; gracefulShutdownTasks(xsc::Chip::CHIP_0, xsc::Copy::COPY_0, protOpPerformed); std::system("reboot"); @@ -1668,24 +1694,20 @@ void CoreController::resetRebootCount(xsc::Chip tgtChip, xsc::Copy tgtCopy) { std::string path = currMntPrefix + REBOOT_FILE; // Disable the reboot file mechanism parseRebootFile(path, rebootFile); - if (tgtChip == xsc::ALL_CHIP and tgtCopy == xsc::ALL_COPY) { - rebootFile.img00Cnt = 0; - rebootFile.img01Cnt = 0; - rebootFile.img10Cnt = 0; - rebootFile.img11Cnt = 0; - } else { - if (tgtChip == xsc::CHIP_0) { - if (tgtCopy == xsc::COPY_0) { - rebootFile.img00Cnt = 0; - } else { - rebootFile.img01Cnt = 0; - } - } else { - if (tgtCopy == xsc::COPY_0) { - rebootFile.img10Cnt = 0; - } else { - rebootFile.img11Cnt = 0; - } + if (tgtChip == xsc::ALL_CHIP or tgtChip == xsc::CHIP_0) { + if (tgtCopy == xsc::ALL_COPY or tgtCopy == xsc::COPY_0) { + rebootFile.img00Cnt = 0; + } + if (tgtCopy == xsc::ALL_COPY or tgtCopy == xsc::COPY_1) { + rebootFile.img01Cnt = 0; + } + } + if (tgtChip == xsc::ALL_CHIP or tgtChip == xsc::CHIP_1) { + if (tgtCopy == xsc::ALL_COPY or tgtCopy == xsc::COPY_0) { + rebootFile.img10Cnt = 0; + } + if (tgtCopy == xsc::ALL_COPY or tgtCopy == xsc::COPY_1) { + rebootFile.img11Cnt = 0; } } rewriteRebootFile(rebootFile); diff --git a/bsp_q7s/core/CoreController.h b/bsp_q7s/core/CoreController.h index 274eb789..92a639c6 100644 --- a/bsp_q7s/core/CoreController.h +++ b/bsp_q7s/core/CoreController.h @@ -6,6 +6,7 @@ #include +#include "CoreActions.h" #include "CoreDefinitions.h" #include "bsp_q7s/memory/SdCardManager.h" #include "events/subsystemIdRanges.h" @@ -84,6 +85,15 @@ class CoreController : public ExtendedControllerBase { ReturnValue_t executeAction(Action* action) override; + ReturnValue_t handleAction(core::ListDirectoryIntoFileAction* action); + ReturnValue_t handleAction(core::SwitchRebootFileHandlingAction* action); + ReturnValue_t handleAction(core::ResetRebootCountersAction* action); + ReturnValue_t handleAction(core::SwitchImageLockAction* action); + ReturnValue_t handleAction(core::SetMaxRebootCntAction* action); + ReturnValue_t handleAction(core::XscRebootObcAction* action); + ReturnValue_t handleAction(core::MountOtherCopyAction* action); + ReturnValue_t handleAction(core::RebootObcAction* action); + ReturnValue_t handleCommandMessage(CommandMessage* message) override; void performControlOperation() override; diff --git a/bsp_q7s/core/CoreDefinitions.h b/bsp_q7s/core/CoreDefinitions.h index fac3433f..91896301 100644 --- a/bsp_q7s/core/CoreDefinitions.h +++ b/bsp_q7s/core/CoreDefinitions.h @@ -3,77 +3,8 @@ #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/mission/controller/ThermalController.cpp b/mission/controller/ThermalController.cpp index c6674da9..0991e803 100644 --- a/mission/controller/ThermalController.cpp +++ b/mission/controller/ThermalController.cpp @@ -1,6 +1,6 @@ #include "ThermalController.h" -//#include +#include #include #include #include