From 4649a75d40e8d1c8be364dbf079cdc85c02260d7 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Mon, 12 Sep 2022 17:23:43 +0200 Subject: [PATCH] update to new API --- bsp_linux_board/RPiSdCardManager.cpp | 8 +++++--- bsp_linux_board/RPiSdCardManager.h | 4 ++-- bsp_q7s/core/CoreController.cpp | 12 ++++++++++-- bsp_q7s/memory/FileSystemHandler.cpp | 12 ++++++++---- bsp_q7s/memory/SdCardManager.cpp | 12 +++++------- bsp_q7s/memory/SdCardManager.h | 4 ++-- fsfw | 2 +- mission/devices/PayloadPcduHandler.cpp | 4 ++-- mission/memory/SdCardMountedIF.h | 6 +++--- tmtc | 2 +- 10 files changed, 39 insertions(+), 27 deletions(-) diff --git a/bsp_linux_board/RPiSdCardManager.cpp b/bsp_linux_board/RPiSdCardManager.cpp index 73111a83..264d3cfa 100644 --- a/bsp_linux_board/RPiSdCardManager.cpp +++ b/bsp_linux_board/RPiSdCardManager.cpp @@ -12,10 +12,12 @@ bool RPiSdCardManager::isSdCardMounted(sd::SdCard sdCard) { return true; } -sd::SdCard RPiSdCardManager::getPreferredSdCard() const { - +std::optional RPiSdCardManager::getPreferredSdCard() const { + return std::nullopt; } void RPiSdCardManager::setActiveSdCard(sd::SdCard sdCard) {} -sd::SdCard RPiSdCardManager::getActiveSdCard() const {} +std::optional RPiSdCardManager::getActiveSdCard() const { + return std::nullopt; +} diff --git a/bsp_linux_board/RPiSdCardManager.h b/bsp_linux_board/RPiSdCardManager.h index 144cfe0e..b1c1d2cc 100644 --- a/bsp_linux_board/RPiSdCardManager.h +++ b/bsp_linux_board/RPiSdCardManager.h @@ -7,9 +7,9 @@ public: RPiSdCardManager(const std::string& prefix); const std::string& getCurrentMountPrefix() const override; bool isSdCardMounted(sd::SdCard sdCard) override; - sd::SdCard getPreferredSdCard() const override; + std::optional getPreferredSdCard() const override; void setActiveSdCard(sd::SdCard sdCard) override; - sd::SdCard getActiveSdCard() const override; + std::optional getActiveSdCard() const override; private: std::string prefix; }; diff --git a/bsp_q7s/core/CoreController.cpp b/bsp_q7s/core/CoreController.cpp index 02d7330d..6f774b6d 100644 --- a/bsp_q7s/core/CoreController.cpp +++ b/bsp_q7s/core/CoreController.cpp @@ -139,7 +139,11 @@ ReturnValue_t CoreController::initialize() { ReturnValue_t CoreController::initializeAfterTaskCreation() { ReturnValue_t result = returnvalue::OK; - sdInfo.pref = sdcMan->getPreferredSdCard(); + auto sdCard = sdcMan->getPreferredSdCard(); + if(not sdCard) { + return returnvalue::FAILED; + } + sdInfo.pref = sdCard.value(); sdcMan->setActiveSdCard(sdInfo.pref); currMntPrefix = sdcMan->getCurrentMountPrefix(); if (BLOCKING_SD_INIT) { @@ -337,7 +341,11 @@ ReturnValue_t CoreController::sdStateMachine() { if (sdInfo.state == SdStates::SET_STATE_SELF) { if (not sdInfo.commandExecuted) { result = sdcMan->getSdCardsStatus(sdInfo.currentState); - sdInfo.pref = sdcMan->getPreferredSdCard(); + auto sdCard = sdcMan->getPreferredSdCard(); + if(not sdCard) { + return returnvalue::FAILED; + } + sdInfo.pref = sdCard.value(); updateSdInfoOther(); if (sdInfo.pref != sd::SdCard::SLOT_0 and sdInfo.pref != sd::SdCard::SLOT_1) { sif::warning << "Preferred SD card invalid. Setting to card 0.." << std::endl; diff --git a/bsp_q7s/memory/FileSystemHandler.cpp b/bsp_q7s/memory/FileSystemHandler.cpp index cb122383..2c5fb729 100644 --- a/bsp_q7s/memory/FileSystemHandler.cpp +++ b/bsp_q7s/memory/FileSystemHandler.cpp @@ -71,8 +71,8 @@ void FileSystemHandler::fileSystemHandlerLoop() { void FileSystemHandler::fileSystemCheckup() { SdCardManager::SdStatePair statusPair; sdcMan->getSdCardsStatus(statusPair); - sd::SdCard preferredSdCard = sdcMan->getPreferredSdCard(); - if ((preferredSdCard == sd::SdCard::SLOT_0) and (statusPair.first == sd::SdState::MOUNTED)) { + auto preferredSdCard = sdcMan->getPreferredSdCard(); + if (preferredSdCard and (preferredSdCard == sd::SdCard::SLOT_0) and (statusPair.first == sd::SdState::MOUNTED)) { currentMountPrefix = SdCardManager::SD_0_MOUNT_POINT; } else if ((preferredSdCard == sd::SdCard::SLOT_1) and (statusPair.second == sd::SdState::MOUNTED)) { @@ -90,7 +90,7 @@ void FileSystemHandler::fileSystemCheckup() { sif::warning << "Preferred SD card is " << sdString << " but does not appear to be mounted. Attempting fix.." << std::endl; // This function will appear to fix the inconsistent state - ReturnValue_t result = sdcMan->sanitizeState(&statusPair, preferredSdCard); + ReturnValue_t result = sdcMan->sanitizeState(&statusPair, preferredSdCard.value()); if (result != returnvalue::OK) { // Oh no. triggerEvent(SdCardManager::SANITIZATION_FAILED, 0, 0); @@ -108,7 +108,11 @@ ReturnValue_t FileSystemHandler::initialize() { << std::endl; } sdcMan = SdCardManager::instance(); - sd::SdCard preferredSdCard = sdcMan->getPreferredSdCard(); + auto sdCard = sdcMan->getPreferredSdCard(); + if(not sdCard) { + return returnvalue::FAILED; + } + sd::SdCard preferredSdCard = sdCard.value(); if (preferredSdCard == sd::SdCard::SLOT_0) { currentMountPrefix = SdCardManager::SD_0_MOUNT_POINT; } else if (preferredSdCard == sd::SdCard::SLOT_1) { diff --git a/bsp_q7s/memory/SdCardManager.cpp b/bsp_q7s/memory/SdCardManager.cpp index ac0df040..c1b2b8de 100644 --- a/bsp_q7s/memory/SdCardManager.cpp +++ b/bsp_q7s/memory/SdCardManager.cpp @@ -300,11 +300,6 @@ ReturnValue_t SdCardManager::sanitizeState(SdStatePair* statusPair, sd::SdCard p blocking = true; resetNonBlockingState = true; } - if (prefSdCard == sd::SdCard::NONE) { - result = getPreferredSdCard(); - if (result != returnvalue::OK) { - } - } if (statusPair == nullptr) { sdStatusPtr = std::make_unique(); statusPair = sdStatusPtr.get(); @@ -379,7 +374,7 @@ void SdCardManager::processSdStatusLine(std::pair& act idx++; } -sd::SdCard SdCardManager::getPreferredSdCard() const { +std::optional SdCardManager::getPreferredSdCard() const { MutexGuard mg(mutex); auto res = mg.getLockResult(); if (res != returnvalue::OK) { @@ -558,4 +553,7 @@ void SdCardManager::setActiveSdCard(sd::SdCard sdCard) { } } -sd::SdCard SdCardManager::getActiveSdCard() const { return sdInfo.active; } +std::optional SdCardManager::getActiveSdCard() const { + MutexGuard mg(mutex); + return sdInfo.active; +} diff --git a/bsp_q7s/memory/SdCardManager.h b/bsp_q7s/memory/SdCardManager.h index 14101b0e..d8bafe25 100644 --- a/bsp_q7s/memory/SdCardManager.h +++ b/bsp_q7s/memory/SdCardManager.h @@ -92,7 +92,7 @@ class SdCardManager : public SystemObject, public SdCardMountedIF { * @param sdCard * @return */ - sd::SdCard getPreferredSdCard() const override; + std::optional getPreferredSdCard() const override; /** * Switch on the specified SD card. @@ -159,7 +159,7 @@ class SdCardManager : public SystemObject, public SdCardMountedIF { * mounted * @return */ - sd::SdCard getActiveSdCard() const override; + std::optional getActiveSdCard() const override; /** * Unmount the specified SD card. This is recommended before switching it off. The SD card diff --git a/fsfw b/fsfw index 141dcb1f..cf8fe7ea 160000 --- a/fsfw +++ b/fsfw @@ -1 +1 @@ -Subproject commit 141dcb1f149b824b5bd6e5d3339ecb712835751e +Subproject commit cf8fe7ea728bea077b9936bcf0db96845bc6419e diff --git a/mission/devices/PayloadPcduHandler.cpp b/mission/devices/PayloadPcduHandler.cpp index e643a945..c811f5d3 100644 --- a/mission/devices/PayloadPcduHandler.cpp +++ b/mission/devices/PayloadPcduHandler.cpp @@ -491,8 +491,8 @@ void PayloadPcduHandler::checkAdcValues() { void PayloadPcduHandler::checkJsonFileInit() { if (not jsonFileInitComplete) { - sd::SdCard activeSd = sdcMan->getActiveSdCard(); - if (sdcMan->isSdCardMounted(activeSd)) { + auto activeSd = sdcMan->getActiveSdCard(); + if (activeSd and sdcMan->isSdCardMounted(activeSd.value())) { params.initialize(sdcMan->getCurrentMountPrefix()); jsonFileInitComplete = true; } diff --git a/mission/memory/SdCardMountedIF.h b/mission/memory/SdCardMountedIF.h index ff0bf190..3dd529d4 100644 --- a/mission/memory/SdCardMountedIF.h +++ b/mission/memory/SdCardMountedIF.h @@ -2,7 +2,7 @@ #define MISSION_MEMORY_SDCARDMOUNTERIF_H_ #include - +#include #include "definitions.h" class SdCardMountedIF { @@ -10,9 +10,9 @@ class SdCardMountedIF { virtual ~SdCardMountedIF(){}; virtual const std::string& getCurrentMountPrefix() const = 0; virtual bool isSdCardMounted(sd::SdCard sdCard) = 0; - virtual sd::SdCard getPreferredSdCard() const = 0; + virtual std::optional getPreferredSdCard() const = 0; virtual void setActiveSdCard(sd::SdCard sdCard) = 0; - virtual sd::SdCard getActiveSdCard() const = 0; + virtual std::optional getActiveSdCard() const = 0; private: }; diff --git a/tmtc b/tmtc index b4d4a511..e1d84c5b 160000 --- a/tmtc +++ b/tmtc @@ -1 +1 @@ -Subproject commit b4d4a51164af69a22eedd645775061dbb51702b1 +Subproject commit e1d84c5b99e99ea9a9687dcd298d815dc4d8d2b6