v1.16.0 #323
@ -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,9 @@ ReturnValue_t CoreController::initialize() {
|
||||
|
||||
ReturnValue_t CoreController::initializeAfterTaskCreation() {
|
||||
ReturnValue_t result = HasReturnvaluesIF::RETURN_OK;
|
||||
sdInfo.pref = sdcMan->getPreferredSdCard();
|
||||
sdcMan->setActiveSdCard(sdInfo.pref);
|
||||
currMntPrefix = sdcMan->getCurrentMountPrefix();
|
||||
if (BLOCKING_SD_INIT) {
|
||||
ReturnValue_t result = initSdCardBlocking();
|
||||
if (result != HasReturnvaluesIF::RETURN_OK and result != SdCardManager::ALREADY_MOUNTED) {
|
||||
@ -165,7 +173,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 +213,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];
|
||||
@ -242,13 +250,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;
|
||||
@ -329,8 +336,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;
|
||||
@ -473,7 +480,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;
|
||||
@ -951,25 +958,6 @@ ReturnValue_t CoreController::gracefulShutdownTasks(xsc::Chip chip, xsc::Copy co
|
||||
|
||||
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";
|
||||
@ -1253,24 +1241,73 @@ void CoreController::performWatchdogControlOperation() {
|
||||
}
|
||||
|
||||
void CoreController::performMountedSdCardOperations() {
|
||||
currMntPrefix = sdcMan->getCurrentMountPrefix();
|
||||
if (doPerformMountedSdCardOps) {
|
||||
bool sdCardMounted = false;
|
||||
sdCardMounted = sdcMan->isSdCardMounted(sdInfo.pref);
|
||||
if (sdCardMounted) {
|
||||
std::string path = currMntPrefix + "/" + CONF_FOLDER;
|
||||
if (not std::filesystem::exists(path)) {
|
||||
std::filesystem::create_directory(path);
|
||||
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);
|
||||
doPerformMountedSdCardOps = 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::performSdCardCheck: Could not check "
|
||||
"read-only mount state"
|
||||
<< std::endl;
|
||||
mountedReadOnly = true;
|
||||
}
|
||||
if (mountedReadOnly) {
|
||||
int linuxErrno = 0;
|
||||
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(sdCard);
|
||||
if (result == HasReturnvaluesIF::RETURN_OK) {
|
||||
sif::warning << "CoreController::performSdCardCheck: Remounted SD Card "
|
||||
<< static_cast<uint8_t>(sdCard) << " read-write";
|
||||
} else {
|
||||
sif::error << "CoreController::performSdCardCheck: Remounting SD Card "
|
||||
<< static_cast<uint8_t>(sdCard) << " read-write failed";
|
||||
}
|
||||
}
|
||||
};
|
||||
if (active.first == sd::SdState::MOUNTED) {
|
||||
sdCardCheck(sd::SdCard::SLOT_0);
|
||||
}
|
||||
if (active.second == sd::SdState::MOUNTED) {
|
||||
sdCardCheck(sd::SdCard::SLOT_1);
|
||||
}
|
||||
|
||||
return RETURN_OK;
|
||||
}
|
||||
|
||||
void CoreController::performRebootFileHandling(bool recreateFile) {
|
||||
using namespace std;
|
||||
std::string path = currMntPrefix + REBOOT_FILE;
|
||||
@ -1696,7 +1733,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) {
|
||||
|
@ -162,11 +162,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;
|
||||
@ -182,7 +183,7 @@ class CoreController : public ExtendedControllerBase {
|
||||
} sdInfo;
|
||||
RebootFile rebootFile = {};
|
||||
std::string currMntPrefix;
|
||||
bool doPerformMountedSdCardOps = true;
|
||||
bool performOneShotSdCardOpsSwitch = true;
|
||||
|
||||
/**
|
||||
* Index 0: Chip 0 Copy 0
|
||||
@ -198,12 +199,14 @@ class CoreController : public ExtendedControllerBase {
|
||||
|
||||
ReturnValue_t initializeLocalDataPool(localpool::DataPool& localDataPoolMap,
|
||||
LocalDataPoolManager& poolManager) override;
|
||||
Countdown sdCardCheckCd = Countdown(120000);
|
||||
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();
|
||||
@ -217,7 +220,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";
|
||||
@ -466,3 +483,68 @@ bool SdCardManager::isSdCardMounted(sd::SdCard sdCard) {
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
ReturnValue_t SdCardManager::isSdCardMountedReadOnly(sd::SdCard sdcard, bool& readOnly) {
|
||||
std::ostringstream command;
|
||||
if (sdcard == sd::SdCard::SLOT_0) {
|
||||
command << "grep -q '" << SD_0_MOUNT_POINT << " vfat ro,' /proc/mounts";
|
||||
} else {
|
||||
command << "grep -q '" << SD_1_MOUNT_POINT << " vfat ro,' /proc/mounts";
|
||||
}
|
||||
ReturnValue_t result = cmdExecutor.load(command.str(), true, false);
|
||||
if (result != HasReturnvaluesIF::RETURN_OK) {
|
||||
return result;
|
||||
}
|
||||
result = cmdExecutor.execute();
|
||||
if (result != HasReturnvaluesIF::RETURN_OK) {
|
||||
int exitStatus = cmdExecutor.getLastError();
|
||||
if (exitStatus == 1) {
|
||||
readOnly = false;
|
||||
return RETURN_OK;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
auto& readVec = cmdExecutor.getReadVector();
|
||||
size_t readLen = strnlen(readVec.data(), readVec.size());
|
||||
if (readLen == 0) {
|
||||
readOnly = false;
|
||||
}
|
||||
readOnly = true;
|
||||
return HasReturnvaluesIF::RETURN_OK;
|
||||
}
|
||||
|
||||
ReturnValue_t SdCardManager::remountReadWrite(sd::SdCard sdcard) {
|
||||
std::ostringstream command;
|
||||
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;
|
||||
}
|
||||
ReturnValue_t result = cmdExecutor.load(command.str(), true, false);
|
||||
if (result != HasReturnvaluesIF::RETURN_OK) {
|
||||
return result;
|
||||
}
|
||||
return cmdExecutor.execute();
|
||||
}
|
||||
|
||||
ReturnValue_t SdCardManager::performFsck(sd::SdCard sdcard, bool printOutput, int& linuxError) {
|
||||
std::ostringstream command;
|
||||
if (sdcard == sd::SdCard::SLOT_0) {
|
||||
command << "fsck -y " << SD_0_DEV_NAME;
|
||||
} else {
|
||||
command << "fsck -y " << SD_1_DEV_NAME;
|
||||
}
|
||||
ReturnValue_t result = cmdExecutor.load(command.str(), true, printOutput);
|
||||
if (result != HasReturnvaluesIF::RETURN_OK) {
|
||||
return result;
|
||||
}
|
||||
result = cmdExecutor.execute();
|
||||
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);
|
||||
|
||||
@ -194,6 +214,12 @@ class SdCardManager : public SystemObject, public SdCardMountedIF {
|
||||
*/
|
||||
bool isSdCardMounted(sd::SdCard sdCard) override;
|
||||
|
||||
ReturnValue_t isSdCardMountedReadOnly(sd::SdCard sdcard, bool& readOnly);
|
||||
|
||||
ReturnValue_t remountReadWrite(sd::SdCard sdcard);
|
||||
|
||||
ReturnValue_t performFsck(sd::SdCard sdcard, bool printOutput, int& linuxError);
|
||||
|
||||
private:
|
||||
CommandExecutor cmdExecutor;
|
||||
Operations currentOp = Operations::IDLE;
|
||||
@ -210,7 +236,7 @@ class SdCardManager : public SystemObject, public SdCardMountedIF {
|
||||
|
||||
std::string currentPrefix;
|
||||
|
||||
static SdCardManager* factoryInstance;
|
||||
static SdCardManager* INSTANCE;
|
||||
};
|
||||
|
||||
#endif /* BSP_Q7S_MEMORY_SDCARDACCESSMANAGER_H_ */
|
||||
|
@ -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,9 +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:
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user