more testing and bugfixes

This commit is contained in:
Robin Müller 2021-08-08 00:11:21 +02:00
parent e186bff4e4
commit 5a4d287f67
No known key found for this signature in database
GPG Key ID: 11D4952C8CCEF814
4 changed files with 52 additions and 28 deletions

View File

@ -39,7 +39,7 @@ CoreController::CoreController(object_id_t objectId):
sif::error << "CoreController::CoreController: SD card manager invalid!" << std::endl; sif::error << "CoreController::CoreController: SD card manager invalid!" << std::endl;
} }
if(not BLOCKING_SD_INIT) { if(not BLOCKING_SD_INIT) {
sdInitStateMachine(); sdStateMachine();
sdcMan->setBlocking(false); sdcMan->setBlocking(false);
} }
@ -60,7 +60,7 @@ ReturnValue_t CoreController::handleCommandMessage(CommandMessage *message) {
void CoreController::performControlOperation() { void CoreController::performControlOperation() {
if(not BLOCKING_SD_INIT and not sdInfo.initFinished) { if(not BLOCKING_SD_INIT and not sdInfo.initFinished) {
sdInitStateMachine(); sdStateMachine();
} }
performWatchdogControlOperation(); performWatchdogControlOperation();
} }
@ -84,7 +84,7 @@ ReturnValue_t CoreController::initialize() {
} }
if(not BLOCKING_SD_INIT) { if(not BLOCKING_SD_INIT) {
sdInitStateMachine(); sdStateMachine();
} }
return ExtendedControllerBase::initialize(); return ExtendedControllerBase::initialize();
@ -134,7 +134,7 @@ ReturnValue_t CoreController::initSdCardBlocking() {
} }
ReturnValue_t CoreController::sdInitStateMachine() { ReturnValue_t CoreController::sdStateMachine() {
#if Q7S_SD_CARD_CONFIG == Q7S_SD_NONE #if Q7S_SD_CARD_CONFIG == Q7S_SD_NONE
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;
@ -146,7 +146,6 @@ ReturnValue_t CoreController::sdInitStateMachine() {
uint16_t maxCycleCount, std::string opPrintout) { uint16_t maxCycleCount, std::string opPrintout) {
SdCardManager::OpStatus status = sdcMan->checkCurrentOp(operation); SdCardManager::OpStatus status = sdcMan->checkCurrentOp(operation);
if(status == SdCardManager::OpStatus::SUCCESS) { if(status == SdCardManager::OpStatus::SUCCESS) {
sif::debug << "op success" << std::endl;
sdInfo.state = newStateOnSuccess; sdInfo.state = newStateOnSuccess;
sdInfo.commandExecuted = false; sdInfo.commandExecuted = false;
sdInfo.cycleCount = 0; sdInfo.cycleCount = 0;
@ -157,6 +156,15 @@ ReturnValue_t CoreController::sdInitStateMachine() {
} }
}; };
auto currentStateSetter = [&](sd::SdCard sdCard, sd::SdState newState) {
if(sdCard == sd::SdCard::SLOT_0) {
sdInfo.currentState.first = newState;
}
else {
sdInfo.currentState.second = newState;
}
};
if(sdInfo.state == SdStates::START) { if(sdInfo.state == SdStates::START) {
sdInfo.cycleCount = 0; sdInfo.cycleCount = 0;
sdInfo.commandExecuted = false; sdInfo.commandExecuted = false;
@ -164,9 +172,7 @@ ReturnValue_t CoreController::sdInitStateMachine() {
} }
if(sdInfo.state == SdStates::GET_INFO) { if(sdInfo.state == SdStates::GET_INFO) {
if(not sdInfo.commandExecuted) { if(not sdInfo.commandExecuted) {
sif::debug << "Getting info.." << std::endl;
// Create update status file // Create update status file
result = sdcMan->updateSdCardStateFile(); result = sdcMan->updateSdCardStateFile();
if(result != HasReturnvaluesIF::RETURN_OK) { if(result != HasReturnvaluesIF::RETURN_OK) {
@ -182,20 +188,21 @@ ReturnValue_t CoreController::sdInitStateMachine() {
if(sdInfo.state == SdStates::SET_STATE_SELF) { if(sdInfo.state == SdStates::SET_STATE_SELF) {
if(not sdInfo.commandExecuted) { if(not sdInfo.commandExecuted) {
sif::debug << "Set self state" << std::endl;
result = sdcMan->getSdCardActiveStatus(sdInfo.currentState); result = sdcMan->getSdCardActiveStatus(sdInfo.currentState);
determinePreferredSdCard(); determinePreferredSdCard();
updateSdInfoOther(); updateSdInfoOther();
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;
} }
#if Q7S_SD_CARD_CONFIG == Q7S_SD_COLD_REDUNDANT
sif::info << "Cold redundant SD card configuration, preferred SD card: " << sif::info << "Cold redundant SD card configuration, preferred SD card: " <<
static_cast<int>(sdInfo.pref) << std::endl; static_cast<int>(sdInfo.pref) << std::endl;
#endif
if(sdInfo.prefState == sd::SdState::MOUNTED) { if(sdInfo.prefState == sd::SdState::MOUNTED) {
sdInfo.state = SdStates::DETERMINE_OTHER; sdInfo.state = SdStates::DETERMINE_OTHER;
} }
else if(sdInfo.prefState == sd::SdState::OFF) { else if(sdInfo.prefState == sd::SdState::OFF) {
sdCardSetup(sdInfo.pref, sd::SdState::ON, sdInfo.prefChar); sdCardSetup(sdInfo.pref, sd::SdState::ON, sdInfo.prefChar, false);
sdInfo.commandExecuted = true; sdInfo.commandExecuted = true;
} }
else if(sdInfo.prefState == sd::SdState::ON) { else if(sdInfo.prefState == sd::SdState::ON) {
@ -204,17 +211,20 @@ ReturnValue_t CoreController::sdInitStateMachine() {
} }
else { else {
nonBlockingOpChecking(SdStates::MOUNT_SELF, 10, "Setting SDC state"); nonBlockingOpChecking(SdStates::MOUNT_SELF, 10, "Setting SDC state");
sdInfo.prefState = sd::SdState::ON;
currentStateSetter(sdInfo.pref, sd::SdState::ON);
} }
} }
if(sdInfo.state == SdStates::MOUNT_SELF) { if(sdInfo.state == SdStates::MOUNT_SELF) {
if(not sdInfo.commandExecuted) { if(not sdInfo.commandExecuted) {
sif::debug << "Mount self" << std::endl;
result = sdCardSetup(sdInfo.pref, sd::SdState::MOUNTED, sdInfo.prefChar); result = sdCardSetup(sdInfo.pref, sd::SdState::MOUNTED, sdInfo.prefChar);
sdInfo.commandExecuted = true; sdInfo.commandExecuted = true;
} }
else { else {
nonBlockingOpChecking(SdStates::DETERMINE_OTHER, 5, "Mounting SD card"); nonBlockingOpChecking(SdStates::DETERMINE_OTHER, 5, "Mounting SD card");
sdInfo.prefState = sd::SdState::MOUNTED;
currentStateSetter(sdInfo.pref, sd::SdState::MOUNTED);
} }
} }
@ -224,11 +234,9 @@ ReturnValue_t CoreController::sdInitStateMachine() {
// 2. Hot redundant case: Other SD card needs to be mounted and switched on // 2. Hot redundant case: Other SD card needs to be mounted and switched on
#if Q7S_SD_CARD_CONFIG == Q7S_SD_COLD_REDUNDANT #if Q7S_SD_CARD_CONFIG == Q7S_SD_COLD_REDUNDANT
if(sdInfo.otherState == sd::SdState::ON) { if(sdInfo.otherState == sd::SdState::ON) {
sif::debug << "Determine: Setting other state off" << std::endl;
sdInfo.state = SdStates::SET_STATE_OTHER; sdInfo.state = SdStates::SET_STATE_OTHER;
} }
else if(sdInfo.otherState == sd::SdState::MOUNTED) { else if(sdInfo.otherState == sd::SdState::MOUNTED) {
sif::debug << "Determine: Unmounting other" << std::endl;
sdInfo.state = SdStates::MOUNT_UNMOUNT_OTHER; sdInfo.state = SdStates::MOUNT_UNMOUNT_OTHER;
} }
else { else {
@ -255,22 +263,24 @@ ReturnValue_t CoreController::sdInitStateMachine() {
// Set state of other SD card to ON or OFF, depending on redundancy mode // Set state of other SD card to ON or OFF, depending on redundancy mode
#if Q7S_SD_CARD_CONFIG == Q7S_SD_COLD_REDUNDANT #if Q7S_SD_CARD_CONFIG == Q7S_SD_COLD_REDUNDANT
if(not sdInfo.commandExecuted) { if(not sdInfo.commandExecuted) {
sif::debug << "Set state other off" << std::endl; result = sdCardSetup(sdInfo.other, sd::SdState::OFF, sdInfo.otherChar, false);
result = sdCardSetup(sdInfo.other, sd::SdState::OFF, sdInfo.otherChar);
sdInfo.commandExecuted = true; sdInfo.commandExecuted = true;
} }
else { else {
nonBlockingOpChecking(SdStates::UPDATE_INFO, 10, "Switching off other SD card"); nonBlockingOpChecking(SdStates::UPDATE_INFO, 10, "Switching off other SD card");
sdInfo.otherState = sd::SdState::OFF;
currentStateSetter(sdInfo.other, sd::SdState::OFF);
} }
#elif Q7S_SD_CARD_CONFIG == Q7S_SD_HOT_REDUNDANT #elif Q7S_SD_CARD_CONFIG == Q7S_SD_HOT_REDUNDANT
if(not sdInfo.commandExecuted) { if(not sdInfo.commandExecuted) {
sif::debug << "Set state other on" << std::endl;
result = sdCardSetup(sdInfo.other, sd::SdState::ON, sdInfo.otherChar); result = sdCardSetup(sdInfo.other, sd::SdState::ON, sdInfo.otherChar);
sdInfo.commandExecuted = true; sdInfo.commandExecuted = true;
} }
else { else {
nonBlockingOpChecking(SdStates::SdStates::MOUNT_UNMOUNT_OTHER, 10, nonBlockingOpChecking(SdStates::SdStates::MOUNT_UNMOUNT_OTHER, 10,
"Switching on other SD card"); "Switching on other SD card");
sdInfo.otherState = sd::SdState::ON;
currentStateSetter(sdInfo.other, sd::SdState::ON);
} }
#endif #endif
@ -280,12 +290,13 @@ ReturnValue_t CoreController::sdInitStateMachine() {
// Mount or unmount other SD card, depending on redundancy mode // Mount or unmount other SD card, depending on redundancy mode
#if Q7S_SD_CARD_CONFIG == Q7S_SD_COLD_REDUNDANT #if Q7S_SD_CARD_CONFIG == Q7S_SD_COLD_REDUNDANT
if(not sdInfo.commandExecuted) { if(not sdInfo.commandExecuted) {
sif::debug << "Unmount other" << std::endl;
result = sdCardSetup(sdInfo.other, sd::SdState::ON, sdInfo.otherChar); result = sdCardSetup(sdInfo.other, sd::SdState::ON, sdInfo.otherChar);
sdInfo.commandExecuted = true; sdInfo.commandExecuted = true;
} }
else { else {
nonBlockingOpChecking(SdStates::SET_STATE_OTHER, 10, "Unmounting other SD card"); nonBlockingOpChecking(SdStates::SET_STATE_OTHER, 10, "Unmounting other SD card");
sdInfo.otherState = sd::SdState::ON;
currentStateSetter(sdInfo.other, sd::SdState::ON);
} }
#elif Q7S_SD_CARD_CONFIG == Q7S_SD_HOT_REDUNDANT #elif Q7S_SD_CARD_CONFIG == Q7S_SD_HOT_REDUNDANT
if(not sdInfo.commandExecuted) { if(not sdInfo.commandExecuted) {
@ -294,13 +305,14 @@ ReturnValue_t CoreController::sdInitStateMachine() {
} }
else { else {
nonBlockingOpChecking(SdStates::UPDATE_INFO, 4, "Mounting other SD card"); nonBlockingOpChecking(SdStates::UPDATE_INFO, 4, "Mounting other SD card");
sdInfo.otherState = sd::SdState::MOUNTED;
currentStateSetter(sdInfo.other, sd::SdState::MOUNTED);
} }
#endif #endif
} }
if(sdInfo.state == SdStates::UPDATE_INFO) { if(sdInfo.state == SdStates::UPDATE_INFO) {
if(not sdInfo.commandExecuted) { if(not sdInfo.commandExecuted) {
sif::debug << "update info" << std::endl;
// It is assumed that all tasks are running by the point this section is reached. // It is assumed that all tasks are running by the point this section is reached.
// Therefore, perform this operation in blocking mode because it does not take long // Therefore, perform this operation in blocking mode because it does not take long
// and the ready state of the SD card is available sooner // and the ready state of the SD card is available sooner
@ -316,7 +328,9 @@ ReturnValue_t CoreController::sdInitStateMachine() {
sdInfo.initFinished = true; sdInfo.initFinished = true;
sdInfo.cycleCount = 0; sdInfo.cycleCount = 0;
sdcMan->setBlocking(false); sdcMan->setBlocking(false);
sif::debug << "Sd init done" << std::endl; sdcMan->getSdCardActiveStatus(sdInfo.currentState);
updateSdInfoOther();
sif::info << "SD card initialization finished" << std::endl;
} }
} }
@ -327,8 +341,9 @@ ReturnValue_t CoreController::sdInitStateMachine() {
ReturnValue_t CoreController::sdCardSetup(sd::SdCard sdCard, sd::SdState targetState, ReturnValue_t CoreController::sdCardSetup(sd::SdCard sdCard, sd::SdState targetState,
std::string sdChar) { std::string sdChar, bool printOutput) {
std::string mountString; std::string mountString;
sdcMan->setPrintCommandOutput(printOutput);
if(sdCard == sd::SdCard::SLOT_0) { if(sdCard == sd::SdCard::SLOT_0) {
mountString = SdCardManager::SD_0_MOUNT_POINT; mountString = SdCardManager::SD_0_MOUNT_POINT;
} }
@ -371,7 +386,7 @@ ReturnValue_t CoreController::sdCardSetup(sd::SdCard sdCard, sd::SdState targetS
return sdcMan->switchOnSdCard(sdCard, true, &sdInfo.currentState); return sdcMan->switchOnSdCard(sdCard, true, &sdInfo.currentState);
} }
else if(targetState == sd::SdState::ON) { else if(targetState == sd::SdState::ON) {
sif::info << "Switching on SD card" << sdChar << std::endl; sif::info << "Switching on SD card " << sdChar << std::endl;
return sdcMan->switchOnSdCard(sdCard, false, &sdInfo.currentState); return sdcMan->switchOnSdCard(sdCard, false, &sdInfo.currentState);
} }
} }
@ -418,7 +433,7 @@ ReturnValue_t CoreController::initializeAfterTaskCreation() {
} }
else { else {
if(not sdInfo.initFinished) { if(not sdInfo.initFinished) {
sdInitStateMachine(); sdStateMachine();
} }
} }
result = initVersionFile(); result = initVersionFile();

View File

@ -79,7 +79,7 @@ private:
SdCardManager* sdcMan = nullptr; SdCardManager* sdcMan = nullptr;
ReturnValue_t initSdCardBlocking(); ReturnValue_t initSdCardBlocking();
ReturnValue_t sdInitStateMachine(); ReturnValue_t sdStateMachine();
struct SdInfo { struct SdInfo {
sd::SdCard pref = sd::SdCard::NONE; sd::SdCard pref = sd::SdCard::NONE;
@ -98,7 +98,8 @@ private:
SdInfo sdInfo; SdInfo sdInfo;
void updateSdInfoOther(); void updateSdInfoOther();
ReturnValue_t sdCardSetup(sd::SdCard sdCard, sd::SdState targetState, std::string sdChar); ReturnValue_t sdCardSetup(sd::SdCard sdCard, sd::SdState targetState, std::string sdChar,
bool printOutput = true);
ReturnValue_t sdColdRedundantBlockingInit(); ReturnValue_t sdColdRedundantBlockingInit();
void determinePreferredSdCard(); void determinePreferredSdCard();

View File

@ -39,7 +39,8 @@ ReturnValue_t SdCardManager::switchOnSdCard(sd::SdCard sdCard, bool doMountSdCar
if(doMountSdCard) { if(doMountSdCard) {
if(not blocking) { if(not blocking) {
sif::warning << "SdCardManager::switchOnSdCard: Two-step command but manager is" sif::warning << "SdCardManager::switchOnSdCard: Two-step command but manager is"
" not configured for blocking operation. Forcing blocking mode.." << std::endl; " not configured for blocking operation. "
"Forcing blocking mode.." << std::endl;
blocking = true; blocking = true;
} }
} }
@ -161,7 +162,7 @@ ReturnValue_t SdCardManager::setSdCardState(sd::SdCard sdCard, bool on) {
} }
ostringstream command; ostringstream command;
command << "q7hw sd set " << sdstring << " " << statestring; command << "q7hw sd set " << sdstring << " " << statestring;
cmdExecutor.load(command.str(), blocking, true); cmdExecutor.load(command.str(), blocking, printCmdOutput);
ReturnValue_t result = cmdExecutor.execute(); ReturnValue_t result = cmdExecutor.execute();
if(blocking and result != HasReturnvaluesIF::RETURN_OK) { if(blocking and result != HasReturnvaluesIF::RETURN_OK) {
utility::handleSystemError(cmdExecutor.getLastError(), "SdCardManager::setSdCardState"); utility::handleSystemError(cmdExecutor.getLastError(), "SdCardManager::setSdCardState");
@ -220,7 +221,7 @@ ReturnValue_t SdCardManager::mountSdCard(sd::SdCard sdCard) {
currentOp = Operations::MOUNTING; currentOp = Operations::MOUNTING;
} }
string sdMountCommand = "mount " + mountDev + " " + mountPoint; string sdMountCommand = "mount " + mountDev + " " + mountPoint;
cmdExecutor.load(sdMountCommand, blocking, true); cmdExecutor.load(sdMountCommand, blocking, printCmdOutput);
ReturnValue_t result = cmdExecutor.execute(); ReturnValue_t result = cmdExecutor.execute();
if(blocking and result != HasReturnvaluesIF::RETURN_OK) { if(blocking and result != HasReturnvaluesIF::RETURN_OK) {
utility::handleSystemError(cmdExecutor.getLastError(), "SdCardManager::mountSdCard"); utility::handleSystemError(cmdExecutor.getLastError(), "SdCardManager::mountSdCard");
@ -259,7 +260,7 @@ ReturnValue_t SdCardManager::unmountSdCard(sd::SdCard sdCard) {
if(not blocking) { if(not blocking) {
currentOp = Operations::UNMOUNTING; currentOp = Operations::UNMOUNTING;
} }
cmdExecutor.load(sdUnmountCommand, blocking, true); cmdExecutor.load(sdUnmountCommand, blocking, printCmdOutput);
ReturnValue_t result = cmdExecutor.execute(); ReturnValue_t result = cmdExecutor.execute();
if(blocking and result != HasReturnvaluesIF::RETURN_OK) { if(blocking and result != HasReturnvaluesIF::RETURN_OK) {
utility::handleSystemError(cmdExecutor.getLastError(), "SdCardManager::unmountSdCard"); utility::handleSystemError(cmdExecutor.getLastError(), "SdCardManager::unmountSdCard");
@ -380,7 +381,7 @@ ReturnValue_t SdCardManager::updateSdCardStateFile() {
} }
// 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, true); cmdExecutor.load(updateCmd, blocking, printCmdOutput);
ReturnValue_t result = cmdExecutor.execute(); ReturnValue_t result = cmdExecutor.execute();
if(blocking and result != HasReturnvaluesIF::RETURN_OK) { if(blocking and result != HasReturnvaluesIF::RETURN_OK) {
utility::handleSystemError(cmdExecutor.getLastError(), "SdCardManager::mountSdCard"); utility::handleSystemError(cmdExecutor.getLastError(), "SdCardManager::mountSdCard");
@ -450,3 +451,8 @@ void SdCardManager::setBlocking(bool blocking) {
this->blocking = blocking; this->blocking = blocking;
} }
void SdCardManager::setPrintCommandOutput(bool print) {
this->printCmdOutput = print;
}

View File

@ -194,10 +194,12 @@ public:
void resetState(); void resetState();
void setBlocking(bool blocking); void setBlocking(bool blocking);
void setPrintCommandOutput(bool print);
private: private:
CommandExecutor cmdExecutor; CommandExecutor cmdExecutor;
Operations currentOp = Operations::IDLE; Operations currentOp = Operations::IDLE;
bool blocking = false; bool blocking = false;
bool printCmdOutput = true;
SdCardManager(); SdCardManager();