From 1f179bfd3a645754200b58ab89331f4b1c71da43 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Thu, 8 Jul 2021 12:07:39 +0200 Subject: [PATCH] updated core controller --- bsp_q7s/core/CoreController.cpp | 18 ++++++++++++++++++ bsp_q7s/core/CoreController.h | 2 ++ bsp_q7s/memory/SdCardManager.cpp | 28 +++++++++++++++++++--------- bsp_q7s/memory/SdCardManager.h | 12 ++++++++++++ 4 files changed, 51 insertions(+), 9 deletions(-) diff --git a/bsp_q7s/core/CoreController.cpp b/bsp_q7s/core/CoreController.cpp index 253efd91..6c2f042b 100644 --- a/bsp_q7s/core/CoreController.cpp +++ b/bsp_q7s/core/CoreController.cpp @@ -1,4 +1,5 @@ #include "CoreController.h" +#include "../memory/SdCardManager.h" CoreController::CoreController(object_id_t objectId): ExtendedControllerBase(objectId, objects::NO_OBJECT, 5) { @@ -20,6 +21,23 @@ LocalPoolDataSetBase* CoreController::getDataSetHandle(sid_t sid) { return nullptr; } +ReturnValue_t CoreController::initialize() { + // Find a way to store this non-volatile outside of SD cards (ProASIC?) + sd::SdCard preferredSdCard = sd::SdCard::SLOT_0; + // Creator or update status file + ReturnValue_t result = SdCardManager::instance()->updateSdCardStateFile(); + if(result != HasReturnvaluesIF::RETURN_OK) { + sif::warning << "CoreController::initialize: Updating SD card state file failed" + << std::endl; + } + result = SdCardManager::instance()->switchOnSdCard(preferredSdCard); + if(result != HasReturnvaluesIF::RETURN_OK) { + sif::warning << "CoreController::initialize: Turning SD card on failed" + << std::endl; + } + return HasReturnvaluesIF::RETURN_OK; +} + ReturnValue_t CoreController::checkModeCommand(Mode_t mode, Submode_t submode, uint32_t *msToReachTheMode) { return HasReturnvaluesIF::RETURN_OK; diff --git a/bsp_q7s/core/CoreController.h b/bsp_q7s/core/CoreController.h index bc8a1581..674ed073 100644 --- a/bsp_q7s/core/CoreController.h +++ b/bsp_q7s/core/CoreController.h @@ -7,6 +7,8 @@ class CoreController: public ExtendedControllerBase { public: CoreController(object_id_t objectId); + ReturnValue_t initialize() override; + ReturnValue_t handleCommandMessage(CommandMessage *message) override; void performControlOperation() override; private: diff --git a/bsp_q7s/memory/SdCardManager.cpp b/bsp_q7s/memory/SdCardManager.cpp index 1458ef1f..1341c132 100644 --- a/bsp_q7s/memory/SdCardManager.cpp +++ b/bsp_q7s/memory/SdCardManager.cpp @@ -25,17 +25,28 @@ SdCardManager* SdCardManager::instance() { } ReturnValue_t SdCardManager::switchOnSdCard(sd::SdCard sdCard) { -// if(sdCardActive(sdCard)) { -// return ALREADY_ON; -// } + std::pair active; + ReturnValue_t result = sdCardActive(active); + if(result != HasReturnvaluesIF::RETURN_OK) { + return result; + } + if((sdCard == sd::SdCard::SLOT_0 and active.first) or + (sdCard == sd::SdCard::SLOT_1 and active.second)) { + return ALREADY_ON; + } return setSdCardState(sdCard, true); - } ReturnValue_t SdCardManager::switchOffSdCard(sd::SdCard sdCard) { -// if(not sdCardActive(sdCard)) { -// return ALREADY_OFF; -// } + std::pair active; + ReturnValue_t result = sdCardActive(active); + if(result != HasReturnvaluesIF::RETURN_OK) { + return result; + } + if((sdCard == sd::SdCard::SLOT_0 and not active.first) or + (sdCard == sd::SdCard::SLOT_1 and not active.second)) { + return ALREADY_OFF; + } return setSdCardState(sdCard, false); } @@ -62,7 +73,7 @@ ReturnValue_t SdCardManager::setSdCardState(sd::SdCard sdCard, bool on) { } sif::warning << "SdCardManager::setSdCardState: system call failed with code " << result << std::endl; - return HasReturnvaluesIF::RETURN_FAILED; + return SYSTEM_CALL_ERROR; } ReturnValue_t SdCardManager::sdCardActive(std::pair& active) { @@ -78,7 +89,6 @@ ReturnValue_t SdCardManager::sdCardActive(std::pair& active) { } string line; uint8_t idx = 0; - ReturnValue_t result = HasReturnvaluesIF::RETURN_OK; bool on = false; while (std::getline(sdStatus, line)) { diff --git a/bsp_q7s/memory/SdCardManager.h b/bsp_q7s/memory/SdCardManager.h index 98ecff24..0c9c664d 100644 --- a/bsp_q7s/memory/SdCardManager.h +++ b/bsp_q7s/memory/SdCardManager.h @@ -42,8 +42,20 @@ public: sd::SdCard getPreferredSdCard() const; + /** + * Switch on the specified SD card + * @param sdCard + * @return - RETURN_OK on success, ALREADY_ON if it is already on, + * SYSTEM_CALL_ERROR on system error + */ ReturnValue_t switchOnSdCard(sd::SdCard sdCard); + /** + * Switch off the specified SD card + * @param sdCard + * @return - RETURN_OK on success, ALREADY_ON if it is already on, + * SYSTEM_CALL_ERROR on system error + */ ReturnValue_t switchOffSdCard(sd::SdCard sdCard); /**