#include "CoreController.h" #include "q7sConfig.h" #include "../memory/SdCardManager.h" CoreController::CoreController(object_id_t objectId): ExtendedControllerBase(objectId, objects::NO_OBJECT, 5) { } ReturnValue_t CoreController::handleCommandMessage(CommandMessage *message) { return HasReturnvaluesIF::RETURN_OK; } void CoreController::performControlOperation() { } ReturnValue_t CoreController::initializeLocalDataPool(localpool::DataPool &localDataPoolMap, LocalDataPoolManager &poolManager) { return HasReturnvaluesIF::RETURN_OK; } LocalPoolDataSetBase* CoreController::getDataSetHandle(sid_t sid) { return nullptr; } ReturnValue_t CoreController::initialize() { return sdCardInit(); } ReturnValue_t CoreController::checkModeCommand(Mode_t mode, Submode_t submode, uint32_t *msToReachTheMode) { return HasReturnvaluesIF::RETURN_OK; } ReturnValue_t CoreController::sdCardInit() { #if Q7S_SD_CARD_CONFIG == Q7S_SD_NONE sif::info << "No SD card initialization will be performed" << std::endl; return HasReturnvaluesIF::RETURN_OK; #else // 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; } SdCardManager* sdcMan = SdCardManager::instance(); auto sdStatus = std::pair(sd::SdStatus::OFF, sd::SdStatus::OFF); result = sdcMan->getSdCardActiveStatus(sdStatus); if(result != HasReturnvaluesIF::RETURN_OK) { sif::warning << "Getting SD card activity status failed" << std::endl; } #if Q7S_SD_CARD_CONFIG == Q7S_SD_COLD_REDUNDANT sif::info << "Cold redundant SD card configuration" << std::endl; sd::SdCard preferredSdCard = sd::SdCard::SLOT_0; result = sdcMan->getPreferredSdCard(preferredSdCard); if(result != HasReturnvaluesIF::RETURN_OK) { sif::warning << "Could not get prefered SD card information from the scratch buffer" << std::endl; } sd::SdCard otherSdc = sd::SdCard::SLOT_0; std::string printoutString; std::string otherString; if(preferredSdCard == sd::SdCard::SLOT_0) { printoutString = "0"; otherSdc = sd::SdCard::SLOT_1; otherString = "1"; } else { printoutString = "1"; otherSdc = sd::SdCard::SLOT_0; otherString = "0"; } sd::SdStatus targetStatus = sd::SdStatus::OFF; if(preferredSdCard == sd::SdCard::SLOT_0) { targetStatus = sdStatus.first; } else if(preferredSdCard == sd::SdCard::SLOT_1) { targetStatus = sdStatus.second; } if(targetStatus == sd::SdStatus::MOUNTED) { sif::info << "SD card " << printoutString << " is already switched on and mounted" << std::endl; result = HasReturnvaluesIF::RETURN_OK; } else if(targetStatus == sd::SdStatus::ON) { sif::info << "Mounting SD card " << printoutString << std::endl; result = sdcMan->mountSdCard(preferredSdCard); if(result != HasReturnvaluesIF::RETURN_OK) { sif::warning << "Mounting SD card failed" << std::endl; } } else if(targetStatus == sd::SdStatus::OFF) { sif::info << "Switching on and mounting SD card " << printoutString << std::endl; result = sdcMan->switchOnSdCard(preferredSdCard, true); if(result != HasReturnvaluesIF::RETURN_OK) { sif::warning << "Switching on and mounting SD card failed" << std::endl; } } if(result != HasReturnvaluesIF::RETURN_OK) { // This should not happen.. Switch on other SD card for now sdcMan->switchOnSdCard(otherSdc, true); return HasReturnvaluesIF::RETURN_FAILED; } sif::info << "Switching off SD card " << otherString << std::endl; // Switch off other SD card in cold-redundant mode result = sdcMan->switchOffSdCard(otherSdc, true); if(result != HasReturnvaluesIF::RETURN_OK) { sif::warning << "Switching off SD card " << otherString << " failed" << std::endl; } return HasReturnvaluesIF::RETURN_OK; #elif Q7S_SD_CARD_CONFIG == Q7S_SD_HOT_REDUNDANT sif::info << "Hot redundant SD card configuration" << std::endl; // Use a lambda to avoid duplicate code auto setUpSdCard = [sdcMan](sd::SdCard sdCard, sd::SdStatus status, std::string sdString) { if(status == sd::SdStatus::OFF) { sif::info << "Switching on and mounting SD card " << sdString << std::endl; sdcMan->switchOnSdCard(sdCard, true); } else if(status == sd::SdStatus::ON) { sif::info << "Mounting SD card " << sdString << std::endl; sdcMan->mountSdCard(sdCard); } else { sif::info << "SD card " << sdString << " already on and mounted" << std::endl; } }; setUpSdCard(sd::SdCard::SLOT_0, sdStatus.first, "0"); setUpSdCard(sd::SdCard::SLOT_1, sdStatus.second, "1"); return HasReturnvaluesIF::RETURN_OK; #endif #endif /* Q7S_SD_CARD_CONFIG != Q7S_SD_NONE */ }