Filesystem Update #53

Merged
meierj merged 17 commits from mueller/filesystem-update into develop 2021-07-22 09:03:43 +02:00
4 changed files with 60 additions and 31 deletions
Showing only changes of commit 5fc8b650f9 - Show all commits

View File

@ -13,7 +13,7 @@
// Set to Q7S_COLD_REDUNDANT: On startup, get the prefered SD card, turn it on and mount it, and // Set to Q7S_COLD_REDUNDANT: On startup, get the prefered SD card, turn it on and mount it, and
// turn off the second SD card if it is on // turn off the second SD card if it is on
// Set to Q7S_HOT_REDUNDANT: On startup, turn on both SD cards and mount them // Set to Q7S_HOT_REDUNDANT: On startup, turn on both SD cards and mount them
#define Q7S_SD_CARD_CONFIG 1 #define Q7S_SD_CARD_CONFIG Q7S_SD_COLD_REDUNDANT
#define Q7S_ADD_RTD_DEVICES 0 #define Q7S_ADD_RTD_DEVICES 0

View File

@ -37,14 +37,16 @@ ReturnValue_t CoreController::sdCardInit() {
sif::info << "No SD card initialization will be performed" << std::endl; sif::info << "No SD card initialization will be performed" << std::endl;
return HasReturnvaluesIF::RETURN_OK; return HasReturnvaluesIF::RETURN_OK;
#else #else
// Creator or update status file SdCardManager* sdcMan = SdCardManager::instance();
ReturnValue_t result = SdCardManager::instance()->updateSdCardStateFile();
// Create update status file
ReturnValue_t result = sdcMan->updateSdCardStateFile();
if(result != HasReturnvaluesIF::RETURN_OK) { if(result != HasReturnvaluesIF::RETURN_OK) {
sif::warning << "CoreController::initialize: Updating SD card state file failed" sif::warning << "CoreController::initialize: Updating SD card state file failed"
<< std::endl; << std::endl;
} }
SdCardManager* sdcMan = SdCardManager::instance();
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) {
@ -113,15 +115,17 @@ ReturnValue_t CoreController::sdCardInit() {
if(result != HasReturnvaluesIF::RETURN_OK) { if(result != HasReturnvaluesIF::RETURN_OK) {
sif::warning << "Switching off SD card " << otherString << " failed" << std::endl; sif::warning << "Switching off SD card " << otherString << " failed" << std::endl;
} }
// Update status file
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 // Use a lambda to avoid duplicate code
auto setUpSdCard = [sdcMan](sd::SdCard sdCard, sd::SdStatus status, std::string sdString) { auto setUpSdCard = [&](sd::SdCard sdCard, sd::SdStatus status, std::string sdString) {
if(status == sd::SdStatus::OFF) { if(status == sd::SdStatus::OFF) {
sif::info << "Switching on and mounting SD card " << sdString << std::endl; sif::info << "Switching on and mounting SD card " << sdString << std::endl;
sdcMan->switchOnSdCard(sdCard, true); sdcMan->switchOnSdCard(sdCard, true, &sdStatus);
} }
else if(status == sd::SdStatus::ON) { else if(status == sd::SdStatus::ON) {
sif::info << "Mounting SD card " << sdString << std::endl; sif::info << "Mounting SD card " << sdString << std::endl;
@ -134,6 +138,8 @@ ReturnValue_t CoreController::sdCardInit() {
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
sdcMan->updateSdCardStateFile();
return HasReturnvaluesIF::RETURN_OK; return HasReturnvaluesIF::RETURN_OK;
#endif #endif

View File

@ -28,23 +28,34 @@ SdCardManager* SdCardManager::instance() {
return SdCardManager::factoryInstance; return SdCardManager::factoryInstance;
} }
ReturnValue_t SdCardManager::switchOnSdCard(sd::SdCard sdCard, bool doMountSdCard) { ReturnValue_t SdCardManager::switchOnSdCard(sd::SdCard sdCard, bool doMountSdCard,
std::pair<sd::SdStatus, sd::SdStatus> active; SdStatusPair* statusPair) {
ReturnValue_t result = getSdCardActiveStatus(active); ReturnValue_t result = HasReturnvaluesIF::RETURN_OK;
if(statusPair == nullptr) {
statusPair = std::make_unique<SdStatusPair>().get();
result = getSdCardActiveStatus(*statusPair);
if(result != HasReturnvaluesIF::RETURN_OK) {
return result;
}
}
// Not allowed, this function turns on one SD card // Not allowed, this function turns on one SD card
if(sdCard == sd::SdCard::BOTH) { if(sdCard == sd::SdCard::BOTH) {
sif::warning << "SdCardManager::switchOffSdCard: API does not allow sd::SdStatus::BOTH" sif::warning << "SdCardManager::switchOffSdCard: API does not allow sd::SdStatus::BOTH"
<< std::endl; << std::endl;
return HasReturnvaluesIF::RETURN_FAILED; return HasReturnvaluesIF::RETURN_FAILED;
} }
if(result != HasReturnvaluesIF::RETURN_OK) {
return result; sd::SdStatus targetStatus;
}
if(sdCard == sd::SdCard::SLOT_0) { if(sdCard == sd::SdCard::SLOT_0) {
if(active.first == sd::SdStatus::MOUNTED) { targetStatus = statusPair->first;
return ALREADY_MOUNTED;
} }
else if(active.first == sd::SdStatus::ON) { else if(sdCard == sd::SdCard::SLOT_1) {
targetStatus = statusPair->second;
}
auto switchCall = [&]() {
if(targetStatus == sd::SdStatus::ON) {
if(not doMountSdCard) { if(not doMountSdCard) {
return ALREADY_ON; return ALREADY_ON;
} }
@ -52,14 +63,19 @@ ReturnValue_t SdCardManager::switchOnSdCard(sd::SdCard sdCard, bool doMountSdCar
return mountSdCard(sdCard); return mountSdCard(sdCard);
} }
} }
else if(targetStatus == sd::SdStatus::MOUNTED) {
return ALREADY_MOUNTED;
}
else if(targetStatus == sd::SdStatus::OFF) {
return setSdCardState(sdCard, true);
}
else {
return HasReturnvaluesIF::RETURN_FAILED;
}
};
result = switchCall();
}
else if(sdCard == sd::SdCard::SLOT_1) {
if(active.second == sd::SdStatus::ON or active.second == sd::SdStatus::MOUNTED) {
return ALREADY_ON;
}
}
result = setSdCardState(sdCard, true);
if(result != HasReturnvaluesIF::RETURN_OK or not doMountSdCard) { if(result != HasReturnvaluesIF::RETURN_OK or not doMountSdCard) {
return result; return result;
} }
@ -67,7 +83,8 @@ ReturnValue_t SdCardManager::switchOnSdCard(sd::SdCard sdCard, bool doMountSdCar
return mountSdCard(sdCard); return mountSdCard(sdCard);
} }
ReturnValue_t SdCardManager::switchOffSdCard(sd::SdCard sdCard, bool doUnmountSdCard) { ReturnValue_t SdCardManager::switchOffSdCard(sd::SdCard sdCard, bool doUnmountSdCard,
SdStatusPair* statusPair) {
std::pair<sd::SdStatus, sd::SdStatus> active; std::pair<sd::SdStatus, sd::SdStatus> active;
ReturnValue_t result = getSdCardActiveStatus(active); ReturnValue_t result = getSdCardActiveStatus(active);
if(result != HasReturnvaluesIF::RETURN_OK) { if(result != HasReturnvaluesIF::RETURN_OK) {
@ -127,7 +144,7 @@ ReturnValue_t SdCardManager::setSdCardState(sd::SdCard sdCard, bool on) {
return SYSTEM_CALL_ERROR; return SYSTEM_CALL_ERROR;
} }
ReturnValue_t SdCardManager::getSdCardActiveStatus(std::pair<sd::SdStatus, sd::SdStatus>& active) { ReturnValue_t SdCardManager::getSdCardActiveStatus(SdStatusPair& active) {
using namespace std; using namespace std;
if(not filesystem::exists(SD_STATE_FILE)) { if(not filesystem::exists(SD_STATE_FILE)) {
return STATUS_FILE_NEXISTS; return STATUS_FILE_NEXISTS;
@ -162,7 +179,7 @@ ReturnValue_t SdCardManager::mountSdCard(sd::SdCard sdCard) {
mountPoint = SD_0_MOUNT_POINT; mountPoint = SD_0_MOUNT_POINT;
} }
else if(sdCard == sd::SdCard::SLOT_1) { else if(sdCard == sd::SdCard::SLOT_1) {
mountDev = SD_0_DEV_NAME; mountDev = SD_1_DEV_NAME;
mountPoint = SD_1_MOUNT_POINT; mountPoint = SD_1_MOUNT_POINT;
} }
if(not filesystem::exists(mountDev)) { if(not filesystem::exists(mountDev)) {

View File

@ -19,6 +19,8 @@ class MutexIF;
class SdCardManager { class SdCardManager {
friend class SdCardAccess; friend class SdCardAccess;
public: public:
using SdStatusPair = std::pair<sd::SdStatus, sd::SdStatus>;
static constexpr uint8_t INTERFACE_ID = CLASS_ID::SD_CARD_MANAGER; static constexpr uint8_t INTERFACE_ID = CLASS_ID::SD_CARD_MANAGER;
static constexpr ReturnValue_t ALREADY_ON = static constexpr ReturnValue_t ALREADY_ON =
@ -63,20 +65,24 @@ public:
* @param sdCard * @param sdCard
* @param doMountSdCard Mount the SD card after switching it on, which is necessary * @param doMountSdCard Mount the SD card after switching it on, which is necessary
* to use it * to use it
* @param statusPair If the status pair is already available, it can be passed here
* @return - RETURN_OK on success, ALREADY_ON if it is already on, * @return - RETURN_OK on success, ALREADY_ON if it is already on,
* SYSTEM_CALL_ERROR on system error * SYSTEM_CALL_ERROR on system error
*/ */
ReturnValue_t switchOnSdCard(sd::SdCard sdCard, bool doMountSdCard = true); ReturnValue_t switchOnSdCard(sd::SdCard sdCard, bool doMountSdCard = true,
SdStatusPair* statusPair = nullptr);
/** /**
* Switch off the specified SD card. * Switch off the specified SD card.
* @param sdCard * @param sdCard
* @param doUnmountSdCard Unmount the SD card before switching the card off, which makes * @param doUnmountSdCard Unmount the SD card before switching the card off, which makes
* the operation safer * the operation safer
* @param statusPair If the status pair is already available, it can be passed here
* @return - RETURN_OK on success, ALREADY_ON if it is already on, * @return - RETURN_OK on success, ALREADY_ON if it is already on,
* SYSTEM_CALL_ERROR on system error * SYSTEM_CALL_ERROR on system error
*/ */
ReturnValue_t switchOffSdCard(sd::SdCard sdCard, bool doUnmountSdCard = true); ReturnValue_t switchOffSdCard(sd::SdCard sdCard, bool doUnmountSdCard = true,
SdStatusPair* statusPair = nullptr);
/** /**
* Update the state file or creates one if it does not exist. You need to call this * Update the state file or creates one if it does not exist. You need to call this
@ -97,7 +103,7 @@ public:
* should call #updateSdCardStateFile again in that case * should call #updateSdCardStateFile again in that case
* - STATUS_FILE_NEXISTS if the status file does not exist * - STATUS_FILE_NEXISTS if the status file does not exist
*/ */
ReturnValue_t getSdCardActiveStatus(std::pair<sd::SdStatus, sd::SdStatus>& active); ReturnValue_t getSdCardActiveStatus(SdStatusPair& active);
/** /**
* Mount the specified SD card. This is necessary to use it. * Mount the specified SD card. This is necessary to use it.
@ -120,8 +126,8 @@ private:
sd::SdCard preferredSdCard = sd::SdCard::SLOT_0; sd::SdCard preferredSdCard = sd::SdCard::SLOT_0;
void processSdStatusLine(std::pair<sd::SdStatus, sd::SdStatus>& active, void processSdStatusLine(SdStatusPair& active, std::string& line, uint8_t& idx,
std::string& line, uint8_t& idx, sd::SdCard& currentSd); sd::SdCard& currentSd);
static SdCardManager* factoryInstance; static SdCardManager* factoryInstance;
}; };