Refactor TM handling #450

Merged
muellerr merged 47 commits from refactor_tm_handling into develop 2023-03-11 15:05:22 +01:00
3 changed files with 14 additions and 11 deletions
Showing only changes of commit 357c01343c - Show all commits

View File

@ -42,8 +42,9 @@ CoreController::CoreController(object_id_t objectId)
if (not BLOCKING_SD_INIT) { if (not BLOCKING_SD_INIT) {
sdcMan->setBlocking(false); sdcMan->setBlocking(false);
} }
Stopwatch watch; // Set up state of SD card manager and own initial state.
sdcMan->updateSdCardStateFile(true); // Stopwatch watch;
sdcMan->updateSdCardStateFile();
sdcMan->updateSdStatePair(); sdcMan->updateSdStatePair();
SdCardManager::SdStatePair sdStates; SdCardManager::SdStatePair sdStates;
sdcMan->getSdCardsStatus(sdStates); sdcMan->getSdCardsStatus(sdStates);
@ -323,7 +324,7 @@ ReturnValue_t CoreController::checkModeCommand(Mode_t mode, Submode_t submode,
ReturnValue_t CoreController::initSdCardBlocking() { ReturnValue_t CoreController::initSdCardBlocking() {
// Create update status file // Create update status file
ReturnValue_t result = sdcMan->updateSdCardStateFile(true); ReturnValue_t result = sdcMan->updateSdCardStateFile();
if (result != returnvalue::OK) { if (result != returnvalue::OK) {
sif::warning << "CoreController::initialize: Updating SD card state file failed" << std::endl; sif::warning << "CoreController::initialize: Updating SD card state file failed" << std::endl;
} }
@ -343,7 +344,7 @@ ReturnValue_t CoreController::initSdCardBlocking() {
<< static_cast<int>(sdInfo.active) << std::endl; << static_cast<int>(sdInfo.active) << std::endl;
result = sdColdRedundantBlockingInit(); result = sdColdRedundantBlockingInit();
// Update status file // Update status file
sdcMan->updateSdCardStateFile(true); sdcMan->updateSdCardStateFile();
return result; return result;
} }
if (sdInfo.cfgMode == SdCfgMode::HOT_REDUNDANT) { if (sdInfo.cfgMode == SdCfgMode::HOT_REDUNDANT) {
@ -351,7 +352,7 @@ ReturnValue_t CoreController::initSdCardBlocking() {
sdCardSetup(sd::SdCard::SLOT_0, sd::SdState::MOUNTED, "0", false); sdCardSetup(sd::SdCard::SLOT_0, sd::SdState::MOUNTED, "0", false);
sdCardSetup(sd::SdCard::SLOT_1, sd::SdState::MOUNTED, "1", false); sdCardSetup(sd::SdCard::SLOT_1, sd::SdState::MOUNTED, "1", false);
// Update status file // Update status file
sdcMan->updateSdCardStateFile(true); sdcMan->updateSdCardStateFile();
} }
return returnvalue::OK; return returnvalue::OK;
} }
@ -404,12 +405,14 @@ ReturnValue_t CoreController::sdStateMachine() {
if (sdFsmState == SdStates::GET_INFO) { if (sdFsmState == SdStates::GET_INFO) {
if (not sdInfo.commandExecuted) { if (not sdInfo.commandExecuted) {
// Create updated status file // Create updated status file
result = sdcMan->updateSdCardStateFile(false); result = sdcMan->updateSdCardStateFile();
if (result != returnvalue::OK) { if (result != returnvalue::OK) {
sif::warning << "CoreController::sdStateMachine: Updating SD card state file failed" sif::warning << "CoreController::sdStateMachine: Updating SD card state file failed"
<< std::endl; << std::endl;
} }
sdInfo.commandExecuted = true; sdFsmState = SdStates::SET_STATE_SELF;
sdInfo.commandExecuted = false;
sdInfo.cycleCount = 0;
} else { } else {
nonBlockingOpChecking(SdStates::SET_STATE_SELF, 4, "Updating SDC file"); nonBlockingOpChecking(SdStates::SET_STATE_SELF, 4, "Updating SDC file");
} }
@ -553,7 +556,7 @@ ReturnValue_t CoreController::sdStateMachine() {
sdFsmState = SdStates::UPDATE_INFO; sdFsmState = SdStates::UPDATE_INFO;
} else if (sdFsmState == SdStates::UPDATE_INFO) { } else if (sdFsmState == SdStates::UPDATE_INFO) {
// Update status file // Update status file
result = sdcMan->updateSdCardStateFile(true); result = sdcMan->updateSdCardStateFile();
if (result != returnvalue::OK) { if (result != returnvalue::OK) {
sif::warning << "CoreController::initialize: Updating SD card state file failed" << std::endl; sif::warning << "CoreController::initialize: Updating SD card state file failed" << std::endl;
} }

View File

@ -406,14 +406,14 @@ ReturnValue_t SdCardManager::setPreferredSdCard(sd::SdCard sdCard) {
return scratch::writeNumber(scratch::PREFERED_SDC_KEY, static_cast<uint8_t>(sdCard)); return scratch::writeNumber(scratch::PREFERED_SDC_KEY, static_cast<uint8_t>(sdCard));
} }
ReturnValue_t SdCardManager::updateSdCardStateFile(bool blocking) { ReturnValue_t SdCardManager::updateSdCardStateFile() {
if (cmdExecutor.getCurrentState() == CommandExecutor::States::PENDING) { if (cmdExecutor.getCurrentState() == CommandExecutor::States::PENDING) {
return CommandExecutor::COMMAND_PENDING; return CommandExecutor::COMMAND_PENDING;
} }
MutexGuard mg(sdLock, LOCK_TYPE, SD_LOCK_TIMEOUT, LOCK_CTX); MutexGuard mg(sdLock, LOCK_TYPE, SD_LOCK_TIMEOUT, LOCK_CTX);
// Use q7hw utility and pipe the command output into the state file // Use q7hw utility and pipe the command output into the state file
std::string updateCmd = "q7hw sd info all > " + std::string(SD_STATE_FILE); std::string updateCmd = "q7hw sd info all > " + std::string(SD_STATE_FILE);
cmdExecutor.load(updateCmd, blocking, printCmdOutput); cmdExecutor.load(updateCmd, true, printCmdOutput);
ReturnValue_t result = cmdExecutor.execute(); ReturnValue_t result = cmdExecutor.execute();
if (blocking and result != returnvalue::OK) { if (blocking and result != returnvalue::OK) {
utility::handleSystemError(cmdExecutor.getLastError(), "SdCardManager::mountSdCard"); utility::handleSystemError(cmdExecutor.getLastError(), "SdCardManager::mountSdCard");

View File

@ -125,7 +125,7 @@ class SdCardManager : public SystemObject, public SdCardMountedIF {
* - CommandExecutor::COMMAND_PENDING: Non-blocking command is pending * - CommandExecutor::COMMAND_PENDING: Non-blocking command is pending
* - returnvalue::FAILED: blocking command failed * - returnvalue::FAILED: blocking command failed
*/ */
ReturnValue_t updateSdCardStateFile(bool blocking); ReturnValue_t updateSdCardStateFile();
/** /**
* Get the state of the SD cards. If the state file does not exist, this function will * Get the state of the SD cards. If the state file does not exist, this function will