some refactoring
This commit is contained in:
parent
5fc8b650f9
commit
5454392a91
@ -46,96 +46,96 @@ ReturnValue_t CoreController::sdCardInit() {
|
|||||||
<< std::endl;
|
<< std::endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
auto sdStatus = std::pair<sd::SdStatus, sd::SdStatus>(sd::SdStatus::OFF, sd::SdStatus::OFF);
|
auto sdStatus = std::pair<sd::SdStatus, sd::SdStatus>(sd::SdStatus::OFF, sd::SdStatus::OFF);
|
||||||
result = sdcMan->getSdCardActiveStatus(sdStatus);
|
result = sdcMan->getSdCardActiveStatus(sdStatus);
|
||||||
if(result != HasReturnvaluesIF::RETURN_OK) {
|
if(result != HasReturnvaluesIF::RETURN_OK) {
|
||||||
sif::warning << "Getting SD card activity status failed" << std::endl;
|
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
|
#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;
|
sd::SdCard preferredSdCard = sd::SdCard::SLOT_0;
|
||||||
result = sdcMan->getPreferredSdCard(preferredSdCard);
|
result = sdcMan->getPreferredSdCard(preferredSdCard);
|
||||||
if(result != HasReturnvaluesIF::RETURN_OK) {
|
if(result != HasReturnvaluesIF::RETURN_OK) {
|
||||||
sif::warning << "Could not get prefered SD card information from the scratch buffer"
|
sif::warning << "Could not get prefered SD card information from the scratch buffer"
|
||||||
<< std::endl;
|
<< std::endl;
|
||||||
}
|
}
|
||||||
sd::SdCard otherSdc = sd::SdCard::SLOT_0;
|
std::string preferredString;
|
||||||
std::string printoutString;
|
sd::SdStatus preferredStatus = sd::SdStatus::OFF;
|
||||||
|
|
||||||
|
sd::SdStatus otherStatus = sd::SdStatus::OFF;
|
||||||
std::string otherString;
|
std::string otherString;
|
||||||
|
sd::SdCard otherSdc = sd::SdCard::SLOT_0;
|
||||||
|
|
||||||
|
sif::info << "Cold redundant SD card configuration, preferred SD card " <<
|
||||||
|
preferredString << std::endl;
|
||||||
|
|
||||||
if(preferredSdCard == sd::SdCard::SLOT_0) {
|
if(preferredSdCard == sd::SdCard::SLOT_0) {
|
||||||
printoutString = "0";
|
preferredStatus = sdStatus.first;
|
||||||
|
preferredString = "0";
|
||||||
otherSdc = sd::SdCard::SLOT_1;
|
otherSdc = sd::SdCard::SLOT_1;
|
||||||
|
otherStatus = sdStatus.second;
|
||||||
otherString = "1";
|
otherString = "1";
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
printoutString = "1";
|
preferredString = "1";
|
||||||
|
preferredStatus = sdStatus.second;
|
||||||
|
otherStatus = sdStatus.first;
|
||||||
otherSdc = sd::SdCard::SLOT_0;
|
otherSdc = sd::SdCard::SLOT_0;
|
||||||
otherString = "0";
|
otherString = "0";
|
||||||
}
|
}
|
||||||
|
|
||||||
sd::SdStatus targetStatus = sd::SdStatus::OFF;
|
result = setUpSdCard(preferredSdCard, preferredStatus, preferredString);
|
||||||
if(preferredSdCard == sd::SdCard::SLOT_0) {
|
if(result != SdCardManager::ALREADY_MOUNTED and result != HasReturnvaluesIF::RETURN_OK) {
|
||||||
targetStatus = sdStatus.first;
|
sif::warning << "Setting up preferred card " << otherString <<
|
||||||
}
|
" in cold redundant mode failed" << std::endl;
|
||||||
else if(preferredSdCard == sd::SdCard::SLOT_1) {
|
// Try other SD card and mark set up operation as failed
|
||||||
targetStatus = sdStatus.second;
|
setUpSdCard(otherSdc, otherStatus, otherString);
|
||||||
|
result = HasReturnvaluesIF::RETURN_FAILED;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(targetStatus == sd::SdStatus::MOUNTED) {
|
if(result != HasReturnvaluesIF::RETURN_FAILED and otherStatus != sd::SdStatus::OFF) {
|
||||||
sif::info << "SD card " << printoutString << " is already switched on and mounted" <<
|
sif::info << "Switching off secondary SD card " << otherString << std::endl;
|
||||||
std::endl;
|
// Switch off other SD card in cold redundant mode if setting up preferred one walked
|
||||||
result = HasReturnvaluesIF::RETURN_OK;
|
// without issues
|
||||||
}
|
result = sdcMan->switchOffSdCard(otherSdc, otherStatus, &sdStatus);
|
||||||
else if(targetStatus == sd::SdStatus::ON) {
|
if(result != HasReturnvaluesIF::RETURN_OK and result != SdCardManager::ALREADY_OFF) {
|
||||||
sif::info << "Mounting SD card " << printoutString << std::endl;
|
sif::warning << "Switching off secondary SD card " << otherString <<
|
||||||
result = sdcMan->mountSdCard(preferredSdCard);
|
" in cold redundant mode failed" << std::endl;
|
||||||
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;
|
|
||||||
}
|
|
||||||
// Update status file
|
// Update status file
|
||||||
sdcMan->updateSdCardStateFile();
|
sdcMan->updateSdCardStateFile();
|
||||||
return HasReturnvaluesIF::RETURN_OK;
|
return HasReturnvaluesIF::RETURN_OK;
|
||||||
#elif Q7S_SD_CARD_CONFIG == Q7S_SD_HOT_REDUNDANT
|
#elif Q7S_SD_CARD_CONFIG == Q7S_SD_HOT_REDUNDANT
|
||||||
sif::info << "Hot redundant SD card configuration" << std::endl;
|
sif::info << "Hot redundant SD card configuration" << std::endl;
|
||||||
|
|
||||||
// Use a lambda to avoid duplicate code
|
|
||||||
auto setUpSdCard = [&](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, &sdStatus);
|
|
||||||
}
|
|
||||||
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_0, sdStatus.first, "0");
|
||||||
setUpSdCard(sd::SdCard::SLOT_1, sdStatus.second, "1");
|
setUpSdCard(sd::SdCard::SLOT_1, sdStatus.second, "1");
|
||||||
// Update status file
|
// Update status file
|
||||||
|
@ -217,7 +217,6 @@ ReturnValue_t SdCardManager::unmountSdCard(sd::SdCard sdCard) {
|
|||||||
sif::warning << "SdCardManager::unmountSdCard: Mount point is empty!" << std::endl;
|
sif::warning << "SdCardManager::unmountSdCard: Mount point is empty!" << std::endl;
|
||||||
}
|
}
|
||||||
string sdUnmountCommand = "umount " + mountPoint;
|
string sdUnmountCommand = "umount " + mountPoint;
|
||||||
sif::debug << sdUnmountCommand << std::endl;
|
|
||||||
int result = system(sdUnmountCommand.c_str());
|
int result = system(sdUnmountCommand.c_str());
|
||||||
if (result != 0) {
|
if (result != 0) {
|
||||||
utility::handleSystemError(result, "SdCardManager::unmountSdCard");
|
utility::handleSystemError(result, "SdCardManager::unmountSdCard");
|
||||||
|
Loading…
x
Reference in New Issue
Block a user