added JSON lib, bugfixes in FileSystemHandler
This commit is contained in:
@ -1,6 +1,7 @@
|
||||
#include "CoreController.h"
|
||||
#include "q7sConfig.h"
|
||||
|
||||
#include "../memory/scratchApi.h"
|
||||
#include "../memory/SdCardManager.h"
|
||||
|
||||
CoreController::CoreController(object_id_t objectId):
|
||||
@ -38,7 +39,9 @@ ReturnValue_t CoreController::sdCardInit() {
|
||||
return HasReturnvaluesIF::RETURN_OK;
|
||||
#else
|
||||
SdCardManager* sdcMan = SdCardManager::instance();
|
||||
|
||||
if(sdcMan == nullptr) {
|
||||
return HasReturnvaluesIF::RETURN_FAILED;
|
||||
}
|
||||
// Create update status file
|
||||
ReturnValue_t result = sdcMan->updateSdCardStateFile();
|
||||
if(result != HasReturnvaluesIF::RETURN_OK) {
|
||||
@ -46,93 +49,14 @@ ReturnValue_t CoreController::sdCardInit() {
|
||||
<< std::endl;
|
||||
}
|
||||
|
||||
auto sdStatus = std::pair<sd::SdStatus, sd::SdStatus>(sd::SdStatus::OFF, sd::SdStatus::OFF);
|
||||
result = sdcMan->getSdCardActiveStatus(sdStatus);
|
||||
auto statusPair = SdCardManager::SdStatusPair(sd::SdStatus::OFF, sd::SdStatus::OFF);
|
||||
result = sdcMan->getSdCardActiveStatus(statusPair);
|
||||
if(result != HasReturnvaluesIF::RETURN_OK) {
|
||||
sif::warning << "Getting SD card activity status failed" << std::endl;
|
||||
}
|
||||
|
||||
// Use a lambda to avoid duplicate code
|
||||
auto setUpSdCard = [&](sd::SdCard sdCard, sd::SdStatus status, std::string sdString) {
|
||||
std::string mountString;
|
||||
if(sdCard == sd::SdCard::SLOT_0) {
|
||||
mountString = SdCardManager::SD_0_MOUNT_POINT;
|
||||
}
|
||||
else {
|
||||
mountString = SdCardManager::SD_1_MOUNT_POINT;
|
||||
}
|
||||
|
||||
if(status == sd::SdStatus::OFF) {
|
||||
sif::info << "Switching on and mounting SD card " << sdString << " at " <<
|
||||
mountString << std::endl;
|
||||
return sdcMan->switchOnSdCard(sdCard, true, &sdStatus);
|
||||
}
|
||||
else if(status == sd::SdStatus::ON) {
|
||||
sif::info << "Mounting SD card " << sdString << " at " << mountString << std::endl;
|
||||
return sdcMan->mountSdCard(sdCard);
|
||||
}
|
||||
else {
|
||||
sif::info << "SD card " << sdString << " already on and mounted at " <<
|
||||
mountString << std::endl;
|
||||
return SdCardManager::ALREADY_MOUNTED;
|
||||
}
|
||||
};
|
||||
|
||||
#if Q7S_SD_CARD_CONFIG == Q7S_SD_COLD_REDUNDANT
|
||||
sd::SdCard preferredSdCard = sd::SdCard::SLOT_0;
|
||||
result = sdcMan->getPreferredSdCard(preferredSdCard);
|
||||
if(result != HasReturnvaluesIF::RETURN_OK) {
|
||||
sif::warning << "Could not get preferred SD card information from the scratch buffer"
|
||||
<< std::endl;
|
||||
}
|
||||
std::string preferredString;
|
||||
sd::SdStatus preferredStatus = sd::SdStatus::OFF;
|
||||
|
||||
sd::SdStatus otherStatus = sd::SdStatus::OFF;
|
||||
std::string otherString;
|
||||
sd::SdCard otherSdc = sd::SdCard::SLOT_0;
|
||||
|
||||
if(preferredSdCard == sd::SdCard::SLOT_0) {
|
||||
preferredStatus = sdStatus.first;
|
||||
preferredString = "0";
|
||||
otherSdc = sd::SdCard::SLOT_1;
|
||||
otherStatus = sdStatus.second;
|
||||
otherString = "1";
|
||||
}
|
||||
else {
|
||||
preferredString = "1";
|
||||
preferredStatus = sdStatus.second;
|
||||
otherStatus = sdStatus.first;
|
||||
otherSdc = sd::SdCard::SLOT_0;
|
||||
otherString = "0";
|
||||
}
|
||||
|
||||
sif::info << "Cold redundant SD card configuration, preferred SD card " <<
|
||||
preferredString << std::endl;
|
||||
|
||||
result = setUpSdCard(preferredSdCard, preferredStatus, preferredString);
|
||||
if(result != SdCardManager::ALREADY_MOUNTED and result != HasReturnvaluesIF::RETURN_OK) {
|
||||
sif::warning << "Setting up preferred card " << otherString <<
|
||||
" in cold redundant mode failed" << std::endl;
|
||||
// Try other SD card and mark set up operation as failed
|
||||
setUpSdCard(otherSdc, otherStatus, otherString);
|
||||
result = HasReturnvaluesIF::RETURN_FAILED;
|
||||
}
|
||||
|
||||
if(result != HasReturnvaluesIF::RETURN_FAILED and otherStatus != sd::SdStatus::OFF) {
|
||||
sif::info << "Switching off secondary SD card " << otherString << std::endl;
|
||||
// Switch off other SD card in cold redundant mode if setting up preferred one walked
|
||||
// without issues
|
||||
result = sdcMan->switchOffSdCard(otherSdc, otherStatus, &sdStatus);
|
||||
if(result != HasReturnvaluesIF::RETURN_OK and result != SdCardManager::ALREADY_OFF) {
|
||||
sif::warning << "Switching off secondary SD card " << otherString <<
|
||||
" in cold redundant mode failed" << std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
// Update status file
|
||||
sdcMan->updateSdCardStateFile();
|
||||
return HasReturnvaluesIF::RETURN_OK;
|
||||
return sdCardColdRedundantInit(sdcMan, statusPair);
|
||||
#elif Q7S_SD_CARD_CONFIG == Q7S_SD_HOT_REDUNDANT
|
||||
sif::info << "Hot redundant SD card configuration" << std::endl;
|
||||
|
||||
@ -146,3 +70,95 @@ ReturnValue_t CoreController::sdCardInit() {
|
||||
#endif /* Q7S_SD_CARD_CONFIG != Q7S_SD_NONE */
|
||||
|
||||
}
|
||||
|
||||
ReturnValue_t CoreController::sdCardSetup(SdCardManager& sdcMan,
|
||||
SdCardManager::SdStatusPair& statusPair,sd::SdCard sdCard, sd::SdStatus status,
|
||||
std::string sdString) {
|
||||
std::string mountString;
|
||||
if(sdCard == sd::SdCard::SLOT_0) {
|
||||
mountString = SdCardManager::SD_0_MOUNT_POINT;
|
||||
}
|
||||
else {
|
||||
mountString = SdCardManager::SD_1_MOUNT_POINT;
|
||||
}
|
||||
|
||||
if(status == sd::SdStatus::OFF) {
|
||||
sif::info << "Switching on and mounting SD card " << sdString << " at " <<
|
||||
mountString << std::endl;
|
||||
return sdcMan.switchOnSdCard(sdCard, true, &statusPair);
|
||||
}
|
||||
else if(status == sd::SdStatus::ON) {
|
||||
sif::info << "Mounting SD card " << sdString << " at " << mountString << std::endl;
|
||||
return sdcMan.mountSdCard(sdCard);
|
||||
}
|
||||
else {
|
||||
sif::info << "SD card " << sdString << " already on and mounted at " <<
|
||||
mountString << std::endl;
|
||||
return SdCardManager::ALREADY_MOUNTED;
|
||||
}
|
||||
}
|
||||
|
||||
ReturnValue_t CoreController::sdCardColdRedundantInit(SdCardManager* sdcMan,
|
||||
SdCardManager::SdStatusPair& statusPair) {
|
||||
sd::SdCard preferredSdCard = sd::SdCard::SLOT_0;
|
||||
ReturnValue_t result = sdcMan->getPreferredSdCard(preferredSdCard);
|
||||
if(result != HasReturnvaluesIF::RETURN_OK) {
|
||||
if(result == scratch::KEY_NOT_FOUND) {
|
||||
sif::warning << "CoreController::sdCardInit: "
|
||||
"Preferred SD card not set. Setting to 0" << std::endl;
|
||||
sdcMan->setPreferredSdCard(preferredSdCard);
|
||||
}
|
||||
else {
|
||||
sif::warning << "CoreController::sdCardInit: Could not get preferred SD card"
|
||||
"information from the scratch buffer" << std::endl;
|
||||
}
|
||||
}
|
||||
std::string preferredString;
|
||||
sd::SdStatus preferredStatus = sd::SdStatus::OFF;
|
||||
|
||||
sd::SdStatus otherStatus = sd::SdStatus::OFF;
|
||||
std::string otherString;
|
||||
sd::SdCard otherSdc = sd::SdCard::SLOT_0;
|
||||
|
||||
if(preferredSdCard == sd::SdCard::SLOT_0) {
|
||||
preferredStatus = statusPair.first;
|
||||
preferredString = "0";
|
||||
otherSdc = sd::SdCard::SLOT_1;
|
||||
otherStatus = statusPair.second;
|
||||
otherString = "1";
|
||||
}
|
||||
else {
|
||||
preferredString = "1";
|
||||
preferredStatus = statusPair.second;
|
||||
otherStatus = statusPair.first;
|
||||
otherSdc = sd::SdCard::SLOT_0;
|
||||
otherString = "0";
|
||||
}
|
||||
|
||||
sif::info << "Cold redundant SD card configuration, preferred SD card " <<
|
||||
preferredString << std::endl;
|
||||
|
||||
result = sdCardSetup(*sdcMan, statusPair, preferredSdCard, preferredStatus, preferredString);
|
||||
if(result != SdCardManager::ALREADY_MOUNTED and result != HasReturnvaluesIF::RETURN_OK) {
|
||||
sif::warning << "Setting up preferred card " << otherString <<
|
||||
" in cold redundant mode failed" << std::endl;
|
||||
// Try other SD card and mark set up operation as failed
|
||||
sdCardSetup(*sdcMan, statusPair, preferredSdCard, preferredStatus, preferredString);
|
||||
result = HasReturnvaluesIF::RETURN_FAILED;
|
||||
}
|
||||
|
||||
if(result != HasReturnvaluesIF::RETURN_FAILED and otherStatus != sd::SdStatus::OFF) {
|
||||
sif::info << "Switching off secondary SD card " << otherString << std::endl;
|
||||
// Switch off other SD card in cold redundant mode if setting up preferred one walked
|
||||
// without issues
|
||||
result = sdcMan->switchOffSdCard(otherSdc, otherStatus, &statusPair);
|
||||
if(result != HasReturnvaluesIF::RETURN_OK and result != SdCardManager::ALREADY_OFF) {
|
||||
sif::warning << "Switching off secondary SD card " << otherString <<
|
||||
" in cold redundant mode failed" << std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
// Update status file
|
||||
sdcMan->updateSdCardStateFile();
|
||||
return HasReturnvaluesIF::RETURN_OK;
|
||||
}
|
||||
|
Reference in New Issue
Block a user