Core Controller Remount SD Handling #253
@ -56,6 +56,7 @@ CoreController::CoreController(object_id_t objectId)
|
||||
} catch (const std::filesystem::filesystem_error &e) {
|
||||
sif::error << "CoreController::CoreController: Failed with exception " << e.what() << std::endl;
|
||||
}
|
||||
sdCardCheckCd.timeOut();
|
||||
eventQueue = QueueFactory::instance()->createMessageQueue(5, EventMessage::MAX_MESSAGE_SIZE);
|
||||
}
|
||||
|
||||
@ -77,6 +78,10 @@ void CoreController::performControlOperation() {
|
||||
performWatchdogControlOperation();
|
||||
sdStateMachine();
|
||||
performMountedSdCardOperations();
|
||||
if (sdCardCheckCd.hasTimedOut()) {
|
||||
performSdCardCheck();
|
||||
sdCardCheckCd.resetTimer();
|
||||
}
|
||||
readHkData();
|
||||
opDivider5.checkAndIncrement();
|
||||
opDivider10.checkAndIncrement();
|
||||
@ -134,6 +139,8 @@ ReturnValue_t CoreController::initialize() {
|
||||
|
||||
ReturnValue_t CoreController::initializeAfterTaskCreation() {
|
||||
ReturnValue_t result = HasReturnvaluesIF::RETURN_OK;
|
||||
sdInfo.pref = sdcMan->getPreferredSdCard();
|
||||
sdcMan->setActiveSdCard(sdInfo.pref);
|
||||
if (BLOCKING_SD_INIT) {
|
||||
ReturnValue_t result = initSdCardBlocking();
|
||||
if (result != HasReturnvaluesIF::RETURN_OK and result != SdCardManager::ALREADY_MOUNTED) {
|
||||
@ -165,7 +172,7 @@ ReturnValue_t CoreController::executeAction(ActionId_t actionId, MessageQueueId_
|
||||
if (size < 1) {
|
||||
return HasActionsIF::INVALID_PARAMETERS;
|
||||
}
|
||||
std::string path = sdcMan->getCurrentMountPrefix(sdInfo.pref) + REBOOT_FILE;
|
||||
std::string path = sdcMan->getCurrentMountPrefix() + REBOOT_FILE;
|
||||
// Disable the reboot file mechanism
|
||||
parseRebootFile(path, rebootFile);
|
||||
if (data[0] == 0) {
|
||||
@ -205,7 +212,7 @@ ReturnValue_t CoreController::executeAction(ActionId_t actionId, MessageQueueId_
|
||||
if (size < 1) {
|
||||
return HasActionsIF::INVALID_PARAMETERS;
|
||||
}
|
||||
std::string path = sdcMan->getCurrentMountPrefix(sdInfo.pref) + REBOOT_FILE;
|
||||
std::string path = sdcMan->getCurrentMountPrefix() + REBOOT_FILE;
|
||||
// Disable the reboot file mechanism
|
||||
parseRebootFile(path, rebootFile);
|
||||
rebootFile.maxCount = data[0];
|
||||
@ -237,13 +244,12 @@ ReturnValue_t CoreController::initSdCardBlocking() {
|
||||
return HasReturnvaluesIF::RETURN_OK;
|
||||
#else
|
||||
|
||||
result = sdcMan->getSdCardActiveStatus(sdInfo.currentState);
|
||||
result = sdcMan->getSdCardsStatus(sdInfo.currentState);
|
||||
if (result != HasReturnvaluesIF::RETURN_OK) {
|
||||
sif::warning << "Getting SD card activity status failed" << std::endl;
|
||||
}
|
||||
|
||||
#if Q7S_SD_CARD_CONFIG == Q7S_SD_COLD_REDUNDANT
|
||||
determinePreferredSdCard();
|
||||
updateSdInfoOther();
|
||||
sif::info << "Cold redundant SD card configuration, preferred SD card: "
|
||||
<< static_cast<int>(sdInfo.pref) << std::endl;
|
||||
@ -324,8 +330,8 @@ ReturnValue_t CoreController::sdStateMachine() {
|
||||
|
||||
if (sdInfo.state == SdStates::SET_STATE_SELF) {
|
||||
if (not sdInfo.commandExecuted) {
|
||||
result = sdcMan->getSdCardActiveStatus(sdInfo.currentState);
|
||||
determinePreferredSdCard();
|
||||
result = sdcMan->getSdCardsStatus(sdInfo.currentState);
|
||||
sdInfo.pref = sdcMan->getPreferredSdCard();
|
||||
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;
|
||||
@ -468,7 +474,7 @@ ReturnValue_t CoreController::sdStateMachine() {
|
||||
sdInfo.state = SdStates::IDLE;
|
||||
sdInfo.cycleCount = 0;
|
||||
sdcMan->setBlocking(false);
|
||||
sdcMan->getSdCardActiveStatus(sdInfo.currentState);
|
||||
sdcMan->getSdCardsStatus(sdInfo.currentState);
|
||||
if (not sdInfo.initFinished) {
|
||||
updateSdInfoOther();
|
||||
sdInfo.initFinished = true;
|
||||
@ -933,25 +939,6 @@ ReturnValue_t CoreController::actionPerformReboot(const uint8_t *data, size_t si
|
||||
|
||||
CoreController::~CoreController() {}
|
||||
|
||||
void CoreController::determinePreferredSdCard() {
|
||||
if (sdInfo.pref == sd::SdCard::NONE) {
|
||||
ReturnValue_t result = sdcMan->getPreferredSdCard(sdInfo.pref);
|
||||
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(sd::SdCard::SLOT_0);
|
||||
sdInfo.pref = sd::SdCard::SLOT_0;
|
||||
} else {
|
||||
sif::warning << "CoreController::sdCardInit: Could not get preferred SD card"
|
||||
"information from the scratch buffer"
|
||||
<< std::endl;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void CoreController::updateSdInfoOther() {
|
||||
if (sdInfo.pref == sd::SdCard::SLOT_0) {
|
||||
sdInfo.prefChar = "0";
|
||||
@ -1235,46 +1222,71 @@ void CoreController::performWatchdogControlOperation() {
|
||||
}
|
||||
|
||||
void CoreController::performMountedSdCardOperations() {
|
||||
currMntPrefix = sdcMan->getCurrentMountPrefix();
|
||||
if (performMountedSdCardOpsSwitch) {
|
||||
bool sdCardMounted = false;
|
||||
bool mountedReadOnly = false;
|
||||
ReturnValue_t result = sdcMan->isSdCardMountedReadOnly(sdInfo.pref, mountedReadOnly);
|
||||
auto mountedSdCardOp = [&](bool& mntSwitch, sd::SdCard sdCard, std::string mntPoint) {
|
||||
if (mntSwitch) {
|
||||
bool sdCardMounted = sdcMan->isSdCardMounted(sdCard);
|
||||
if (sdCardMounted and not performOneShotSdCardOpsSwitch) {
|
||||
std::ostringstream path;
|
||||
path << mntPoint << "/" << CONF_FOLDER;
|
||||
if (not std::filesystem::exists(path.str())) {
|
||||
std::filesystem::create_directory(path.str());
|
||||
}
|
||||
initVersionFile();
|
||||
initClockFromTimeFile();
|
||||
performRebootFileHandling(false);
|
||||
performOneShotSdCardOpsSwitch = true;
|
||||
}
|
||||
mntSwitch = false;
|
||||
}
|
||||
};
|
||||
if(sdInfo.pref == sd::SdCard::SLOT_1) {
|
||||
mountedSdCardOp(sdInfo.mountSwitch.second, sd::SdCard::SLOT_1, SdCardManager::SD_1_MOUNT_POINT);
|
||||
mountedSdCardOp(sdInfo.mountSwitch.first, sd::SdCard::SLOT_0, SdCardManager::SD_0_MOUNT_POINT);
|
||||
} else {
|
||||
mountedSdCardOp(sdInfo.mountSwitch.first, sd::SdCard::SLOT_0, SdCardManager::SD_0_MOUNT_POINT);
|
||||
mountedSdCardOp(sdInfo.mountSwitch.second, sd::SdCard::SLOT_1, SdCardManager::SD_1_MOUNT_POINT);
|
||||
}
|
||||
timeFileHandler();
|
||||
}
|
||||
|
||||
ReturnValue_t CoreController::performSdCardCheck() {
|
||||
bool mountedReadOnly = false;
|
||||
SdCardManager::SdStatePair active;
|
||||
sdcMan->getSdCardsStatus(active);
|
||||
auto sdCardCheck = [&](sd::SdCard sdCard) {
|
||||
ReturnValue_t result = sdcMan->isSdCardMountedReadOnly(sdCard, mountedReadOnly);
|
||||
if (result != HasReturnvaluesIF::RETURN_OK) {
|
||||
sif::error << "CoreController::performMountedSdCardOperations: Could not check "
|
||||
"read-only mount state" << std::endl;
|
||||
sif::error << "CoreController::performSdCardCheck: Could not check "
|
||||
"read-only mount state"
|
||||
<< std::endl;
|
||||
mountedReadOnly = true;
|
||||
}
|
||||
if (mountedReadOnly) {
|
||||
int linuxErrno = 0;
|
||||
result = sdcMan->performFsck(sdInfo.pref, true, linuxErrno);
|
||||
if(result != HasReturnvaluesIF::RETURN_OK) {
|
||||
sif::error << "CoreController::performMountedSdCardOperations: fsck command on SD Card "
|
||||
<< sdInfo.prefChar << " failed with code " << linuxErrno << " | " << strerror(linuxErrno);
|
||||
result = sdcMan->performFsck(sdCard, true, linuxErrno);
|
||||
if (result != HasReturnvaluesIF::RETURN_OK) {
|
||||
sif::error << "CoreController::performSdCardCheck: fsck command on SD Card "
|
||||
<< static_cast<uint8_t>(sdCard) << " failed with code " << linuxErrno << " | "
|
||||
<< strerror(linuxErrno);
|
||||
}
|
||||
result = sdcMan->remountReadWrite(sdInfo.pref);
|
||||
if(result == HasReturnvaluesIF::RETURN_OK) {
|
||||
sif::warning << "CoreController::performMountedSdCardOperations: Remounted SD Card " <<
|
||||
sdInfo.prefChar << " read-write";
|
||||
result = sdcMan->remountReadWrite(sdCard);
|
||||
if (result == HasReturnvaluesIF::RETURN_OK) {
|
||||
sif::warning << "CoreController::performSdCardCheck: Remounted SD Card "
|
||||
<< static_cast<uint8_t>(sdCard) << " read-write";
|
||||
} else {
|
||||
sif::error << "CoreController::performMountedSdCardOperations: Remounting SD Card " <<
|
||||
sdInfo.prefChar << " read-write failed";
|
||||
sif::error << "CoreController::performSdCardCheck: Remounting SD Card "
|
||||
<< static_cast<uint8_t>(sdCard) << " read-write failed";
|
||||
}
|
||||
}
|
||||
sdCardMounted = sdcMan->isSdCardMounted(sdInfo.pref);
|
||||
if (sdCardMounted and not performOneShotSdCardOpsSwitch) {
|
||||
std::ostringstream path;
|
||||
path << currMntPrefix << "/" << CONF_FOLDER;
|
||||
if (not std::filesystem::exists(path.str())) {
|
||||
std::filesystem::create_directory(path.str());
|
||||
}
|
||||
initVersionFile();
|
||||
initClockFromTimeFile();
|
||||
performRebootFileHandling(false);
|
||||
performOneShotSdCardOpsSwitch = true;
|
||||
}
|
||||
};
|
||||
if (active.first == sd::SdState::MOUNTED) {
|
||||
sdCardCheck(sd::SdCard::SLOT_0);
|
||||
}
|
||||
timeFileHandler();
|
||||
if (active.second == sd::SdState::MOUNTED) {
|
||||
sdCardCheck(sd::SdCard::SLOT_1);
|
||||
}
|
||||
|
||||
return RETURN_OK;
|
||||
}
|
||||
|
||||
void CoreController::performRebootFileHandling(bool recreateFile) {
|
||||
@ -1702,7 +1714,7 @@ void CoreController::rewriteRebootFile(RebootFile file) {
|
||||
}
|
||||
|
||||
void CoreController::setRebootMechanismLock(bool lock, xsc::Chip tgtChip, xsc::Copy tgtCopy) {
|
||||
std::string path = sdcMan->getCurrentMountPrefix(sdInfo.pref) + REBOOT_FILE;
|
||||
std::string path = currMntPrefix + REBOOT_FILE;
|
||||
// Disable the reboot file mechanism
|
||||
parseRebootFile(path, rebootFile);
|
||||
if (tgtChip == xsc::CHIP_0) {
|
||||
|
@ -159,11 +159,12 @@ class CoreController : public ExtendedControllerBase {
|
||||
|
||||
struct SdInfo {
|
||||
sd::SdCard pref = sd::SdCard::NONE;
|
||||
sd::SdState prefState = sd::SdState::OFF;
|
||||
sd::SdCard other = sd::SdCard::NONE;
|
||||
sd::SdState prefState = sd::SdState::OFF;
|
||||
sd::SdState otherState = sd::SdState::OFF;
|
||||
std::string prefChar = "0";
|
||||
std::string otherChar = "1";
|
||||
std::pair<bool, bool> mountSwitch = {true, true};
|
||||
SdStates state = SdStates::START;
|
||||
// Used to track whether a command was executed
|
||||
bool commandExecuted = true;
|
||||
@ -180,7 +181,6 @@ class CoreController : public ExtendedControllerBase {
|
||||
RebootFile rebootFile = {};
|
||||
std::string currMntPrefix;
|
||||
bool performOneShotSdCardOpsSwitch = true;
|
||||
bool performMountedSdCardOpsSwitch = true;
|
||||
|
||||
/**
|
||||
* Index 0: Chip 0 Copy 0
|
||||
@ -196,12 +196,14 @@ class CoreController : public ExtendedControllerBase {
|
||||
|
||||
ReturnValue_t initializeLocalDataPool(localpool::DataPool& localDataPoolMap,
|
||||
LocalDataPoolManager& poolManager) override;
|
||||
Countdown sdCardCheckCd = Countdown(10000);
|
||||
LocalPoolDataSetBase* getDataSetHandle(sid_t sid) override;
|
||||
ReturnValue_t checkModeCommand(Mode_t mode, Submode_t submode, uint32_t* msToReachTheMode);
|
||||
void performMountedSdCardOperations();
|
||||
ReturnValue_t initVersionFile();
|
||||
|
||||
ReturnValue_t initClockFromTimeFile();
|
||||
ReturnValue_t performSdCardCheck();
|
||||
ReturnValue_t timeFileHandler();
|
||||
ReturnValue_t initBootCopy();
|
||||
ReturnValue_t initWatchdogFifo();
|
||||
@ -215,7 +217,6 @@ class CoreController : public ExtendedControllerBase {
|
||||
ReturnValue_t sdColdRedundantBlockingInit();
|
||||
|
||||
void currentStateSetter(sd::SdCard sdCard, sd::SdState newState);
|
||||
void determinePreferredSdCard();
|
||||
void executeNextExternalSdCommand();
|
||||
void checkExternalSdCommandStatus();
|
||||
void performRebootFileHandling(bool recreateFile);
|
||||
|
@ -70,9 +70,8 @@ void FileSystemHandler::fileSystemHandlerLoop() {
|
||||
|
||||
void FileSystemHandler::fileSystemCheckup() {
|
||||
SdCardManager::SdStatePair statusPair;
|
||||
sdcMan->getSdCardActiveStatus(statusPair);
|
||||
sd::SdCard preferredSdCard;
|
||||
sdcMan->getPreferredSdCard(preferredSdCard);
|
||||
sdcMan->getSdCardsStatus(statusPair);
|
||||
sd::SdCard preferredSdCard = sdcMan->getPreferredSdCard();
|
||||
if ((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
|
||||
@ -109,11 +108,7 @@ ReturnValue_t FileSystemHandler::initialize() {
|
||||
<< std::endl;
|
||||
}
|
||||
sdcMan = SdCardManager::instance();
|
||||
sd::SdCard preferredSdCard;
|
||||
ReturnValue_t result = sdcMan->getPreferredSdCard(preferredSdCard);
|
||||
if (result != HasReturnvaluesIF::RETURN_OK) {
|
||||
return result;
|
||||
}
|
||||
sd::SdCard preferredSdCard = sdcMan->getPreferredSdCard();
|
||||
if (preferredSdCard == sd::SdCard::SLOT_0) {
|
||||
currentMountPrefix = SdCardManager::SD_0_MOUNT_POINT;
|
||||
} else if (preferredSdCard == sd::SdCard::SLOT_1) {
|
||||
|
@ -16,23 +16,44 @@
|
||||
#include "linux/utility/utility.h"
|
||||
#include "scratchApi.h"
|
||||
|
||||
SdCardManager* SdCardManager::factoryInstance = nullptr;
|
||||
SdCardManager* SdCardManager::INSTANCE = nullptr;
|
||||
|
||||
SdCardManager::SdCardManager() : SystemObject(objects::SDC_MANAGER), cmdExecutor(256) {
|
||||
mutex = MutexFactory::instance()->createMutex();
|
||||
MutexGuard mg(mutex);
|
||||
uint8_t prefSdRaw = 0;
|
||||
ReturnValue_t result = scratch::readNumber(scratch::PREFERED_SDC_KEY, prefSdRaw);
|
||||
|
||||
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;
|
||||
setPreferredSdCard(sd::SdCard::SLOT_0);
|
||||
sdInfo.pref = sd::SdCard::SLOT_0;
|
||||
} else {
|
||||
// Should not happen.
|
||||
// TODO: Maybe trigger event?
|
||||
sif::error << "SdCardManager::SdCardManager: Reading preferred SD card from scratch"
|
||||
"buffer failed"
|
||||
<< std::endl;
|
||||
sdInfo.pref = sd::SdCard::SLOT_0;
|
||||
}
|
||||
}
|
||||
sdInfo.pref = static_cast<sd::SdCard>(prefSdRaw);
|
||||
}
|
||||
|
||||
SdCardManager::~SdCardManager() {}
|
||||
|
||||
void SdCardManager::create() {
|
||||
if (factoryInstance == nullptr) {
|
||||
factoryInstance = new SdCardManager();
|
||||
if (INSTANCE == nullptr) {
|
||||
INSTANCE = new SdCardManager();
|
||||
}
|
||||
}
|
||||
|
||||
SdCardManager* SdCardManager::instance() {
|
||||
SdCardManager::create();
|
||||
return SdCardManager::factoryInstance;
|
||||
return SdCardManager::INSTANCE;
|
||||
}
|
||||
|
||||
ReturnValue_t SdCardManager::switchOnSdCard(sd::SdCard sdCard, bool doMountSdCard,
|
||||
@ -51,7 +72,7 @@ ReturnValue_t SdCardManager::switchOnSdCard(sd::SdCard sdCard, bool doMountSdCar
|
||||
if (statusPair == nullptr) {
|
||||
sdStatusPtr = std::make_unique<SdStatePair>();
|
||||
statusPair = sdStatusPtr.get();
|
||||
result = getSdCardActiveStatus(*statusPair);
|
||||
result = getSdCardsStatus(*statusPair);
|
||||
if (result != HasReturnvaluesIF::RETURN_OK) {
|
||||
return result;
|
||||
}
|
||||
@ -98,7 +119,7 @@ ReturnValue_t SdCardManager::switchOnSdCard(sd::SdCard sdCard, bool doMountSdCar
|
||||
ReturnValue_t SdCardManager::switchOffSdCard(sd::SdCard sdCard, bool doUnmountSdCard,
|
||||
SdStatePair* statusPair) {
|
||||
std::pair<sd::SdState, sd::SdState> active;
|
||||
ReturnValue_t result = getSdCardActiveStatus(active);
|
||||
ReturnValue_t result = getSdCardsStatus(active);
|
||||
if (result != HasReturnvaluesIF::RETURN_OK) {
|
||||
return result;
|
||||
}
|
||||
@ -165,7 +186,7 @@ ReturnValue_t SdCardManager::setSdCardState(sd::SdCard sdCard, bool on) {
|
||||
return result;
|
||||
}
|
||||
|
||||
ReturnValue_t SdCardManager::getSdCardActiveStatus(SdStatePair& active) {
|
||||
ReturnValue_t SdCardManager::getSdCardsStatus(SdStatePair& active) {
|
||||
using namespace std;
|
||||
MutexGuard mg(mutex);
|
||||
if (not filesystem::exists(SD_STATE_FILE)) {
|
||||
@ -273,14 +294,14 @@ ReturnValue_t SdCardManager::sanitizeState(SdStatePair* statusPair, sd::SdCard p
|
||||
resetNonBlockingState = true;
|
||||
}
|
||||
if (prefSdCard == sd::SdCard::NONE) {
|
||||
result = getPreferredSdCard(prefSdCard);
|
||||
result = getPreferredSdCard();
|
||||
if (result != HasReturnvaluesIF::RETURN_OK) {
|
||||
}
|
||||
}
|
||||
if (statusPair == nullptr) {
|
||||
sdStatusPtr = std::make_unique<SdStatePair>();
|
||||
statusPair = sdStatusPtr.get();
|
||||
getSdCardActiveStatus(*statusPair);
|
||||
getSdCardsStatus(*statusPair);
|
||||
}
|
||||
|
||||
if (statusPair->first == sd::SdState::ON) {
|
||||
@ -351,20 +372,21 @@ void SdCardManager::processSdStatusLine(std::pair<sd::SdState, sd::SdState>& act
|
||||
idx++;
|
||||
}
|
||||
|
||||
ReturnValue_t SdCardManager::getPreferredSdCard(sd::SdCard& sdCard) const {
|
||||
uint8_t prefSdCard = 0;
|
||||
ReturnValue_t result = scratch::readNumber(scratch::PREFERED_SDC_KEY, prefSdCard);
|
||||
if (result != HasReturnvaluesIF::RETURN_OK) {
|
||||
return result;
|
||||
sd::SdCard SdCardManager::getPreferredSdCard() const {
|
||||
MutexGuard mg(mutex);
|
||||
auto res = mg.getLockResult();
|
||||
if (res != RETURN_OK) {
|
||||
sif::error << "SdCardManager::getPreferredSdCard: Lock error" << std::endl;
|
||||
}
|
||||
sdCard = static_cast<sd::SdCard>(prefSdCard);
|
||||
return HasReturnvaluesIF::RETURN_OK;
|
||||
return sdInfo.pref;
|
||||
}
|
||||
|
||||
ReturnValue_t SdCardManager::setPreferredSdCard(sd::SdCard sdCard) {
|
||||
MutexGuard mg(mutex);
|
||||
if (sdCard == sd::SdCard::BOTH) {
|
||||
return HasReturnvaluesIF::RETURN_FAILED;
|
||||
}
|
||||
sdInfo.pref = sdCard;
|
||||
return scratch::writeNumber(scratch::PREFERED_SDC_KEY, static_cast<uint8_t>(sdCard));
|
||||
}
|
||||
|
||||
@ -383,14 +405,9 @@ ReturnValue_t SdCardManager::updateSdCardStateFile() {
|
||||
return result;
|
||||
}
|
||||
|
||||
std::string SdCardManager::getCurrentMountPrefix(sd::SdCard prefSdCard) {
|
||||
if (prefSdCard == sd::SdCard::NONE) {
|
||||
ReturnValue_t result = getPreferredSdCard(prefSdCard);
|
||||
if (result != HasReturnvaluesIF::RETURN_OK) {
|
||||
return SD_0_MOUNT_POINT;
|
||||
}
|
||||
}
|
||||
if (prefSdCard == sd::SdCard::SLOT_0) {
|
||||
std::string SdCardManager::getCurrentMountPrefix() const {
|
||||
MutexGuard mg(mutex);
|
||||
if (sdInfo.active == sd::SdCard::SLOT_0) {
|
||||
return SD_0_MOUNT_POINT;
|
||||
} else {
|
||||
return SD_1_MOUNT_POINT;
|
||||
@ -443,7 +460,7 @@ void SdCardManager::setPrintCommandOutput(bool print) { this->printCmdOutput = p
|
||||
|
||||
bool SdCardManager::isSdCardMounted(sd::SdCard sdCard) {
|
||||
SdCardManager::SdStatePair active;
|
||||
ReturnValue_t result = this->getSdCardActiveStatus(active);
|
||||
ReturnValue_t result = this->getSdCardsStatus(active);
|
||||
|
||||
if (result != HasReturnvaluesIF::RETURN_OK) {
|
||||
sif::debug << "SdCardManager::isSdCardMounted: Failed to get SD card active state";
|
||||
@ -469,10 +486,10 @@ bool SdCardManager::isSdCardMounted(sd::SdCard sdCard) {
|
||||
|
||||
ReturnValue_t SdCardManager::isSdCardMountedReadOnly(sd::SdCard sdcard, bool& readOnly) {
|
||||
std::ostringstream command;
|
||||
if(sdcard == sd::SdCard::SLOT_0) {
|
||||
command << "grep -q \"" << SD_0_DEV_NAME << " vfat ro, \" /proc/mounts";
|
||||
if (sdcard == sd::SdCard::SLOT_0) {
|
||||
command << "grep -q \"" << SD_0_DEV_NAME << " vfat ro, \" /proc/mounts";
|
||||
} else {
|
||||
command << "grep -q \"" << SD_1_DEV_NAME << " vfat ro, \" /proc/mounts";
|
||||
command << "grep -q \"" << SD_1_DEV_NAME << " vfat ro, \" /proc/mounts";
|
||||
}
|
||||
ReturnValue_t result = cmdExecutor.load(command.str(), true, false);
|
||||
if (result != HasReturnvaluesIF::RETURN_OK) {
|
||||
@ -484,7 +501,7 @@ ReturnValue_t SdCardManager::isSdCardMountedReadOnly(sd::SdCard sdcard, bool& re
|
||||
}
|
||||
auto& readVec = cmdExecutor.getReadVector();
|
||||
size_t readLen = strnlen(readVec.data(), readVec.size());
|
||||
if(readLen == 0) {
|
||||
if (readLen == 0) {
|
||||
readOnly = false;
|
||||
}
|
||||
readOnly = true;
|
||||
@ -493,7 +510,7 @@ ReturnValue_t SdCardManager::isSdCardMountedReadOnly(sd::SdCard sdcard, bool& re
|
||||
|
||||
ReturnValue_t SdCardManager::remountReadWrite(sd::SdCard sdcard) {
|
||||
std::ostringstream command;
|
||||
if(sdcard == sd::SdCard::SLOT_0) {
|
||||
if (sdcard == sd::SdCard::SLOT_0) {
|
||||
command << "mount -o remount,rw " << SD_0_DEV_NAME << " " << SD_0_MOUNT_POINT;
|
||||
} else {
|
||||
command << "mount -o remount,rw " << SD_1_DEV_NAME << " " << SD_1_MOUNT_POINT;
|
||||
@ -507,7 +524,7 @@ ReturnValue_t SdCardManager::remountReadWrite(sd::SdCard sdcard) {
|
||||
|
||||
ReturnValue_t SdCardManager::performFsck(sd::SdCard sdcard, bool printOutput, int& linuxError) {
|
||||
std::ostringstream command;
|
||||
if(sdcard == sd::SdCard::SLOT_0) {
|
||||
if (sdcard == sd::SdCard::SLOT_0) {
|
||||
command << "fsck -y " << SD_0_DEV_NAME;
|
||||
} else {
|
||||
command << "fsck -y " << SD_1_DEV_NAME;
|
||||
@ -517,8 +534,16 @@ ReturnValue_t SdCardManager::performFsck(sd::SdCard sdcard, bool printOutput, in
|
||||
return result;
|
||||
}
|
||||
result = cmdExecutor.execute();
|
||||
if(result != HasReturnvaluesIF::RETURN_OK) {
|
||||
if (result != HasReturnvaluesIF::RETURN_OK) {
|
||||
linuxError = cmdExecutor.getLastError();
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
void SdCardManager::setActiveSdCard(sd::SdCard sdCard) {
|
||||
sdInfo.active = sdCard;
|
||||
}
|
||||
|
||||
sd::SdCard SdCardManager::getActiveSdCard() const {
|
||||
return sdInfo.active;
|
||||
}
|
||||
|
@ -24,7 +24,7 @@ class MutexIF;
|
||||
* @brief Manages handling of SD cards like switching them on or off or getting the current
|
||||
* state
|
||||
*/
|
||||
class SdCardManager : public SystemObject, public SdCardMountedIF {
|
||||
class SdCardManager : public SystemObject, public HasReturnvaluesIF, public SdCardMountedIF {
|
||||
friend class SdCardAccess;
|
||||
|
||||
public:
|
||||
@ -36,6 +36,12 @@ class SdCardManager : public SystemObject, public SdCardMountedIF {
|
||||
|
||||
using SdStatePair = std::pair<sd::SdState, sd::SdState>;
|
||||
|
||||
struct SdInfo {
|
||||
sd::SdCard pref = sd::SdCard::NONE;
|
||||
sd::SdCard other = sd::SdCard::NONE;
|
||||
sd::SdCard active = sd::SdCard::NONE;
|
||||
} sdInfo;
|
||||
|
||||
static constexpr uint8_t INTERFACE_ID = CLASS_ID::SD_CARD_MANAGER;
|
||||
|
||||
static constexpr ReturnValue_t OP_ONGOING = HasReturnvaluesIF::makeReturnCode(INTERFACE_ID, 0);
|
||||
@ -91,7 +97,7 @@ class SdCardManager : public SystemObject, public SdCardMountedIF {
|
||||
* @param sdCard
|
||||
* @return
|
||||
*/
|
||||
ReturnValue_t getPreferredSdCard(sd::SdCard& sdCard) const override;
|
||||
sd::SdCard getPreferredSdCard() const override;
|
||||
|
||||
/**
|
||||
* Switch on the specified SD card.
|
||||
@ -138,7 +144,7 @@ class SdCardManager : public SystemObject, public SdCardMountedIF {
|
||||
* should call #updateSdCardStateFile again in that case
|
||||
* - STATUS_FILE_NEXISTS if the status file does not exist
|
||||
*/
|
||||
ReturnValue_t getSdCardActiveStatus(SdStatePair& active);
|
||||
ReturnValue_t getSdCardsStatus(SdStatePair& active);
|
||||
|
||||
/**
|
||||
* Mount the specified SD card. This is necessary to use it.
|
||||
@ -146,6 +152,20 @@ class SdCardManager : public SystemObject, public SdCardMountedIF {
|
||||
* @return
|
||||
*/
|
||||
ReturnValue_t mountSdCard(sd::SdCard sdCard);
|
||||
|
||||
/**
|
||||
* Set the currently active SD card. This does not necessarily mean that the SD card is on or
|
||||
* mounted
|
||||
* @param sdCard
|
||||
*/
|
||||
void setActiveSdCard(sd::SdCard sdCard) override;
|
||||
/**
|
||||
* Get the currently active SD card. This does not necessarily mean that the SD card is on or
|
||||
* mounted
|
||||
* @return
|
||||
*/
|
||||
sd::SdCard getActiveSdCard() const override;
|
||||
|
||||
/**
|
||||
* Unmount the specified SD card. This is recommended before switching it off. The SD card
|
||||
* can't be used after it has been unmounted.
|
||||
@ -173,7 +193,7 @@ class SdCardManager : public SystemObject, public SdCardMountedIF {
|
||||
* @param prefSdCardPtr
|
||||
* @return
|
||||
*/
|
||||
std::string getCurrentMountPrefix(sd::SdCard prefSdCardPtr = sd::SdCard::NONE) override;
|
||||
std::string getCurrentMountPrefix() const override;
|
||||
|
||||
OpStatus checkCurrentOp(Operations& currentOp);
|
||||
|
||||
@ -216,7 +236,7 @@ class SdCardManager : public SystemObject, public SdCardMountedIF {
|
||||
|
||||
std::string currentPrefix;
|
||||
|
||||
static SdCardManager* factoryInstance;
|
||||
static SdCardManager* INSTANCE;
|
||||
};
|
||||
|
||||
#endif /* BSP_Q7S_MEMORY_SDCARDACCESSMANAGER_H_ */
|
||||
|
@ -114,7 +114,7 @@ bool Max31865RtdReader::periodicInitHandling() {
|
||||
#if OBSW_RTD_AUTO_MODE == 0
|
||||
result = writeBiasSel(Bias::ON, rtd->spiCookie, BASE_CFG);
|
||||
#endif
|
||||
someRtdUsable = true;
|
||||
someRtdUsable = true;
|
||||
}
|
||||
}
|
||||
return someRtdUsable;
|
||||
|
@ -123,7 +123,7 @@ void Max31865EiveHandler::fillCommandAndReplyMap() {
|
||||
|
||||
ReturnValue_t Max31865EiveHandler::scanForReply(const uint8_t* start, size_t remainingSize,
|
||||
DeviceCommandId_t* foundId, size_t* foundLen) {
|
||||
if(mode == _MODE_POWER_ON or mode == _MODE_WAIT_ON) {
|
||||
if (mode == _MODE_POWER_ON or mode == _MODE_WAIT_ON) {
|
||||
return IGNORE_FULL_PACKET;
|
||||
}
|
||||
if (remainingSize != structLen) {
|
||||
|
@ -490,10 +490,9 @@ void PayloadPcduHandler::checkAdcValues() {
|
||||
|
||||
void PayloadPcduHandler::checkJsonFileInit() {
|
||||
if (not jsonFileInitComplete) {
|
||||
sd::SdCard prefSd;
|
||||
sdcMan->getPreferredSdCard(prefSd);
|
||||
if (sdcMan->isSdCardMounted(prefSd)) {
|
||||
params.initialize(sdcMan->getCurrentMountPrefix(prefSd));
|
||||
sd::SdCard activeSd = sdcMan->getActiveSdCard();
|
||||
if (sdcMan->isSdCardMounted(activeSd)) {
|
||||
params.initialize(sdcMan->getCurrentMountPrefix());
|
||||
jsonFileInitComplete = true;
|
||||
}
|
||||
}
|
||||
|
@ -8,10 +8,11 @@
|
||||
class SdCardMountedIF {
|
||||
public:
|
||||
virtual ~SdCardMountedIF(){};
|
||||
virtual std::string getCurrentMountPrefix(sd::SdCard prefSdCardPtr = sd::SdCard::NONE) = 0;
|
||||
virtual std::string getCurrentMountPrefix() const = 0;
|
||||
virtual bool isSdCardMounted(sd::SdCard sdCard) = 0;
|
||||
virtual ReturnValue_t getPreferredSdCard(sd::SdCard& sdCard) const = 0;
|
||||
|
||||
virtual sd::SdCard getPreferredSdCard() const = 0;
|
||||
virtual void setActiveSdCard(sd::SdCard sdCard) = 0;
|
||||
virtual sd::SdCard getActiveSdCard() const = 0;
|
||||
private:
|
||||
};
|
||||
|
||||
|
2
tmtc
2
tmtc
@ -1 +1 @@
|
||||
Subproject commit 9332fb8690de200070e712a70b1fa339d5b6b8d8
|
||||
Subproject commit 51bbeaa693a11bfc4d2cb342354041972dd93c1e
|
Loading…
Reference in New Issue
Block a user