From 60a20acc5b57fe310c3b403f7ae3dd2ed605db84 Mon Sep 17 00:00:00 2001 From: Ulrich Mohr Date: Wed, 17 Aug 2022 11:21:35 +0200 Subject: [PATCH] Core controlle rincomplete, but compiles --- bsp_q7s/core/CoreActions.h | 10 ++++++- bsp_q7s/core/CoreController.cpp | 50 +++++++++++++++++---------------- 2 files changed, 35 insertions(+), 25 deletions(-) diff --git a/bsp_q7s/core/CoreActions.h b/bsp_q7s/core/CoreActions.h index 672b9cda..9d00b451 100644 --- a/bsp_q7s/core/CoreActions.h +++ b/bsp_q7s/core/CoreActions.h @@ -52,7 +52,13 @@ class ResetRebootCountersAction class SwitchImageLockAction : public TemplateAction { public: + FSFW_ENUM(Selection, uint8_t, ((ZERO, "0"))((ONE, "1"))) + SwitchImageLockAction(CoreController *owner) : TemplateAction(owner, ActionId::SWITCH_IMG_LOCK){}; + + Parameter lock = Parameter::createParameter(this, "Lock Image"); + Parameter chip = Parameter::createParameter(this, "Chip"); + Parameter copy = Parameter::createParameter(this, "Copy"); }; class SetMaxRebootCntAction @@ -60,11 +66,13 @@ class SetMaxRebootCntAction public: SetMaxRebootCntAction(CoreController *owner) : TemplateAction(owner, ActionId::SET_MAX_REBOOT_CNT){}; + + Parameter maxCount = Parameter::createParameter(this, "Count"); }; class XscRebootObcAction : public TemplateAction { public: - FSFW_ENUM(Selection, uint8_t, ((ZERO, "0"))((ONE, "1"))((SAME, "Same"))) + 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"); diff --git a/bsp_q7s/core/CoreController.cpp b/bsp_q7s/core/CoreController.cpp index eee9be2e..e79f6208 100644 --- a/bsp_q7s/core/CoreController.cpp +++ b/bsp_q7s/core/CoreController.cpp @@ -208,24 +208,24 @@ ReturnValue_t CoreController::handleAction(core::ResetRebootCountersAction *acti } ReturnValue_t CoreController::handleAction(core::SwitchImageLockAction *action) { - if (size != 3) { - return HasActionsIF::INVALID_PARAMETERS; + bool lock = action->lock == core::Boolenum::YES; + xsc::Chip chip = xsc::CHIP_0; + if (action->chip == core::SwitchImageLockAction::Selection::ONE) { + chip = xsc::CHIP_1; } - if (data[1] > 1 or data[2] > 1) { - return HasActionsIF::INVALID_PARAMETERS; + xsc::Copy copy = xsc::COPY_0; + if (action->copy == core::SwitchImageLockAction::Selection::ONE) { + copy = xsc::COPY_0; } - setRebootMechanismLock(data[0], static_cast(data[1]), static_cast(data[2])); + setRebootMechanismLock(lock, chip, copy); return HasActionsIF::EXECUTION_FINISHED; } ReturnValue_t CoreController::handleAction(core::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]; + rebootFile.maxCount = action->maxCount; rewriteRebootFile(rebootFile); return HasActionsIF::EXECUTION_FINISHED; } @@ -749,23 +749,24 @@ ReturnValue_t CoreController::handleAction(core::ListDirectoryIntoFileAction *ac // 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 // null termination. - if (size < 14) { - return HasActionsIF::INVALID_PARAMETERS; - } + //TODO make work again + // if (size < 14) { + // return HasActionsIF::INVALID_PARAMETERS; + // } // We could also make -l optional, but I can't think of a reason why to not use -l.. // This flag specifies to run ls with -a - bool aFlag = data[0]; - data += 1; + bool aFlag = 0;//data[0]; + //data += 1; // This flag specifies to run ls with -R - bool RFlag = data[1]; - data += 1; + bool RFlag = 0;//data[1]; + //data += 1; - size_t remainingSize = size - 2; + size_t remainingSize = 0;//size - 2; // One larger for null termination, which prevents undefined behaviour if the sent // strings are not 0 terminated properly std::vector repoAndTargetFileBuffer(remainingSize + 1, 0); - std::memcpy(repoAndTargetFileBuffer.data(), data, remainingSize); + //std::memcpy(repoAndTargetFileBuffer.data(), data, remainingSize); const char *currentCharPtr = reinterpret_cast(repoAndTargetFileBuffer.data()); // Full target file name std::string repoName(currentCharPtr); @@ -792,7 +793,7 @@ ReturnValue_t CoreController::handleAction(core::ListDirectoryIntoFileAction *ac int result = std::system(oss.str().c_str()); if (result != 0) { utility::handleSystemError(result, "CoreController::actionListDirectoryIntoFile"); - actionHelper.finish(false, action->commandedBy, action->id); + actionHelper.finish(false, action->commandedBy, action->getId()); } return HasReturnvaluesIF::RETURN_OK; } @@ -876,19 +877,20 @@ ReturnValue_t CoreController::handleAction(core::XscRebootObcAction *action) { return HasActionsIF::EXECUTION_FINISHED; } #if OBSW_VERBOSE_LEVEL >= 1 - sif::info << "CoreController::actionPerformReboot: Rebooting on " << static_cast(action->chip) - << " " << static_cast(action->copy) << std::endl; + sif::info << "CoreController::actionPerformReboot: Rebooting on " + << static_cast(action->chip.value) << " " + << static_cast(action->copy.value) << 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 = xsc::CHIP_0; - if (action->chip == core::XscRebootObcAction::Selection::ONE){ - tgtChip == xsc::CHIP_1; + if (action->chip == core::XscRebootObcAction::Selection::ONE) { + tgtChip = xsc::CHIP_1; } auto tgtCopy = xsc::COPY_0; - if (action->copy == core::XscRebootObcAction::Selection::ONE){ + if (action->copy == core::XscRebootObcAction::Selection::ONE) { tgtCopy = xsc::COPY_1; }