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;
}
if(not BLOCKING_SD_INIT) {
sdInitStateMachine();
sdStateMachine();
sdcMan->setBlocking(false);
}
@ -60,7 +60,7 @@ ReturnValue_t CoreController::handleCommandMessage(CommandMessage *message) {
void CoreController::performControlOperation() {
if(not BLOCKING_SD_INIT and not sdInfo.initFinished) {
sdInitStateMachine();
sdStateMachine();
}
performWatchdogControlOperation();
}
@ -84,7 +84,7 @@ ReturnValue_t CoreController::initialize() {
}
if(not BLOCKING_SD_INIT) {
sdInitStateMachine();
sdStateMachine();
}
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
sif::info << "No SD card initialization will be performed" << std::endl;
return HasReturnvaluesIF::RETURN_OK;
@ -146,7 +146,6 @@ ReturnValue_t CoreController::sdInitStateMachine() {
uint16_t maxCycleCount, std::string opPrintout) {
SdCardManager::OpStatus status = sdcMan->checkCurrentOp(operation);
if(status == SdCardManager::OpStatus::SUCCESS) {
sif::debug << "op success" << std::endl;
sdInfo.state = newStateOnSuccess;
sdInfo.commandExecuted = false;
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) {
sdInfo.cycleCount = 0;
sdInfo.commandExecuted = false;
@ -164,9 +172,7 @@ ReturnValue_t CoreController::sdInitStateMachine() {
}
if(sdInfo.state == SdStates::GET_INFO) {
if(not sdInfo.commandExecuted) {
sif::debug << "Getting info.." << std::endl;
// Create update status file
result = sdcMan->updateSdCardStateFile();
if(result != HasReturnvaluesIF::RETURN_OK) {
@ -182,20 +188,21 @@ ReturnValue_t CoreController::sdInitStateMachine() {
if(sdInfo.state == SdStates::SET_STATE_SELF) {
if(not sdInfo.commandExecuted) {
sif::debug << "Set self state" << std::endl;
result = sdcMan->getSdCardActiveStatus(sdInfo.currentState);
determinePreferredSdCard();
updateSdInfoOther();
if(result != HasReturnvaluesIF::RETURN_OK) {
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: " <<
static_cast<int>(sdInfo.pref) << std::endl;
#endif
if(sdInfo.prefState == sd::SdState::MOUNTED) {
sdInfo.state = SdStates::DETERMINE_OTHER;
}
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;
}
else if(sdInfo.prefState == sd::SdState::ON) {
@ -204,17 +211,20 @@ ReturnValue_t CoreController::sdInitStateMachine() {
}
else {
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(not sdInfo.commandExecuted) {
sif::debug << "Mount self" << std::endl;
result = sdCardSetup(sdInfo.pref, sd::SdState::MOUNTED, sdInfo.prefChar);
sdInfo.commandExecuted = true;
}
else {
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
#if Q7S_SD_CARD_CONFIG == Q7S_SD_COLD_REDUNDANT
if(sdInfo.otherState == sd::SdState::ON) {
sif::debug << "Determine: Setting other state off" << std::endl;
sdInfo.state = SdStates::SET_STATE_OTHER;
}
else if(sdInfo.otherState == sd::SdState::MOUNTED) {
sif::debug << "Determine: Unmounting other" << std::endl;
sdInfo.state = SdStates::MOUNT_UNMOUNT_OTHER;
}
else {
@ -255,22 +263,24 @@ ReturnValue_t CoreController::sdInitStateMachine() {
// Set state of other SD card to ON or OFF, depending on redundancy mode
#if Q7S_SD_CARD_CONFIG == Q7S_SD_COLD_REDUNDANT
if(not sdInfo.commandExecuted) {
sif::debug << "Set state other off" << std::endl;
result = sdCardSetup(sdInfo.other, sd::SdState::OFF, sdInfo.otherChar);
result = sdCardSetup(sdInfo.other, sd::SdState::OFF, sdInfo.otherChar, false);
sdInfo.commandExecuted = true;
}
else {
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
if(not sdInfo.commandExecuted) {
sif::debug << "Set state other on" << std::endl;
result = sdCardSetup(sdInfo.other, sd::SdState::ON, sdInfo.otherChar);
sdInfo.commandExecuted = true;
}
else {
nonBlockingOpChecking(SdStates::SdStates::MOUNT_UNMOUNT_OTHER, 10,
"Switching on other SD card");
sdInfo.otherState = sd::SdState::ON;
currentStateSetter(sdInfo.other, sd::SdState::ON);
}
#endif
@ -280,12 +290,13 @@ ReturnValue_t CoreController::sdInitStateMachine() {
// Mount or unmount other SD card, depending on redundancy mode
#if Q7S_SD_CARD_CONFIG == Q7S_SD_COLD_REDUNDANT
if(not sdInfo.commandExecuted) {
sif::debug << "Unmount other" << std::endl;
result = sdCardSetup(sdInfo.other, sd::SdState::ON, sdInfo.otherChar);
sdInfo.commandExecuted = true;
}
else {
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
if(not sdInfo.commandExecuted) {
@ -294,13 +305,14 @@ ReturnValue_t CoreController::sdInitStateMachine() {
}
else {
nonBlockingOpChecking(SdStates::UPDATE_INFO, 4, "Mounting other SD card");
sdInfo.otherState = sd::SdState::MOUNTED;
currentStateSetter(sdInfo.other, sd::SdState::MOUNTED);
}
#endif
}
if(sdInfo.state == SdStates::UPDATE_INFO) {
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.
// Therefore, perform this operation in blocking mode because it does not take long
// and the ready state of the SD card is available sooner
@ -316,7 +328,9 @@ ReturnValue_t CoreController::sdInitStateMachine() {
sdInfo.initFinished = true;
sdInfo.cycleCount = 0;
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,
std::string sdChar) {
std::string sdChar, bool printOutput) {
std::string mountString;
sdcMan->setPrintCommandOutput(printOutput);
if(sdCard == sd::SdCard::SLOT_0) {
mountString = SdCardManager::SD_0_MOUNT_POINT;
}
@ -418,7 +433,7 @@ ReturnValue_t CoreController::initializeAfterTaskCreation() {
}
else {
if(not sdInfo.initFinished) {
sdInitStateMachine();
sdStateMachine();
}
}
result = initVersionFile();

View File

@ -79,7 +79,7 @@ private:
SdCardManager* sdcMan = nullptr;
ReturnValue_t initSdCardBlocking();
ReturnValue_t sdInitStateMachine();
ReturnValue_t sdStateMachine();
struct SdInfo {
sd::SdCard pref = sd::SdCard::NONE;
@ -98,7 +98,8 @@ private:
SdInfo sdInfo;
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();
void determinePreferredSdCard();

View File

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

View File

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