From 99f703a2eb143e8e8bf688b9fbbed6fe5e9c69f5 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Fri, 14 Oct 2022 14:34:35 +0200 Subject: [PATCH] some more important bugfixes --- .../devices/SolarArrayDeploymentHandler.cpp | 86 ++++++++++--------- mission/devices/SolarArrayDeploymentHandler.h | 1 + 2 files changed, 46 insertions(+), 41 deletions(-) diff --git a/mission/devices/SolarArrayDeploymentHandler.cpp b/mission/devices/SolarArrayDeploymentHandler.cpp index df3f0805..88b3d7bf 100644 --- a/mission/devices/SolarArrayDeploymentHandler.cpp +++ b/mission/devices/SolarArrayDeploymentHandler.cpp @@ -36,22 +36,27 @@ SolarArrayDeploymentHandler::~SolarArrayDeploymentHandler() = default; ReturnValue_t SolarArrayDeploymentHandler::performOperation(uint8_t operationCode) { using namespace std::filesystem; - auto activeSdc = sdcMan.getActiveSdCard(); - if (activeSdc and activeSdc.value() == sd::SdCard::SLOT_0 and - sdcMan.isSdCardUsable(activeSdc.value())) { - if (exists(SD_0_DEPL_FILE)) { - // perform autonomous deployment handling - performAutonomousDepl(sd::SdCard::SLOT_0, dryRunStringInFile(SD_0_DEPL_FILE)); - } - } else if (activeSdc and activeSdc.value() == sd::SdCard::SLOT_1 and - sdcMan.isSdCardUsable(activeSdc.value())) { - if (exists(SD_1_DEPL_FILE)) { - // perform autonomous deployment handling - performAutonomousDepl(sd::SdCard::SLOT_1, dryRunStringInFile(SD_1_DEPL_FILE)); + if (opDivider.checkAndIncrement()) { + auto activeSdc = sdcMan.getActiveSdCard(); + if (activeSdc and activeSdc.value() == sd::SdCard::SLOT_0 and + sdcMan.isSdCardUsable(activeSdc.value())) { + if (exists(SD_0_DEPL_FILE)) { + // perform autonomous deployment handling + performAutonomousDepl(sd::SdCard::SLOT_0, dryRunStringInFile(SD_0_DEPL_FILE)); + } + } else if (activeSdc and activeSdc.value() == sd::SdCard::SLOT_1 and + sdcMan.isSdCardUsable(activeSdc.value())) { + if (exists(SD_1_DEPL_FILE)) { + // perform autonomous deployment handling + performAutonomousDepl(sd::SdCard::SLOT_1, dryRunStringInFile(SD_1_DEPL_FILE)); + } } } readCommandQueue(); handleStateMachine(); + if (firstCycle) { + firstCycle = false; + } return returnvalue::OK; } @@ -113,17 +118,21 @@ bool SolarArrayDeploymentHandler::autonomousDeplForFile(const char* filename, bo } } else if (lineNum == 1) { iss >> word; + if (iss.bad()) { + return false; + } if (word.find("secs_since_start:") == string::npos) { return false; } iss >> secsSinceBoot; - if (not initUptime) { - initUptime = secsSinceBoot; - } if (iss.bad()) { return false; } + if (not initUptime) { + initUptime = secsSinceBoot; + } + auto switchCheck = [&](AutonomousDeplState expected) { if (deplState != expected) { deplState = expected; @@ -143,39 +152,34 @@ bool SolarArrayDeploymentHandler::autonomousDeplForFile(const char* filename, bo } lineNum++; } - bool updateUptime = false; - if (opDivider.checkAndIncrement()) { - if (initUptime) { - secsSinceBoot = initUptime.value(); - } - // Uptime has increased by X seconds so we need to update the uptime count inside the file - secsSinceBoot += Clock::getUptime().tv_sec; - updateUptime = true; + if (initUptime) { + secsSinceBoot = initUptime.value(); } - if (stateSwitch) { + // Uptime has increased by X seconds so we need to update the uptime count inside the file + secsSinceBoot += Clock::getUptime().tv_sec; + if (stateSwitch or firstCycle) { if (deplState == AutonomousDeplState::FIRST_BURN or deplState == AutonomousDeplState::SECOND_BURN) { startFsmOn(config::SA_DEPL_BURN_TIME_SECS, dryRun); - } else if (deplState == AutonomousDeplState::WAIT or deplState == AutonomousDeplState::DONE) { + } else if (deplState == AutonomousDeplState::WAIT or deplState == AutonomousDeplState::DONE or + deplState == AutonomousDeplState::INIT) { startFsmOff(); } } - if (stateSwitch or updateUptime) { - std::ofstream of(filename); - of << "phase: "; - if (deplState == AutonomousDeplState::INIT) { - of << PHASE_INIT_STR << "\n"; - } else if (deplState == AutonomousDeplState::FIRST_BURN) { - of << PHASE_FIRST_BURN_STR << "\n"; - } else if (deplState == AutonomousDeplState::WAIT) { - of << PHASE_WAIT_STR << "\n"; - } else if (deplState == AutonomousDeplState::SECOND_BURN) { - of << PHASE_SECOND_BURN_STR << "\n"; - } else if (deplState == AutonomousDeplState::DONE) { - of << PHASE_DONE << "\n"; - } - of << "secs_since_start: " << std::to_string(secsSinceBoot) << "\n"; + std::ofstream of(filename); + of << "phase: "; + if (deplState == AutonomousDeplState::INIT) { + of << PHASE_INIT_STR << "\n"; + } else if (deplState == AutonomousDeplState::FIRST_BURN) { + of << PHASE_FIRST_BURN_STR << "\n"; + } else if (deplState == AutonomousDeplState::WAIT) { + of << PHASE_WAIT_STR << "\n"; + } else if (deplState == AutonomousDeplState::SECOND_BURN) { + of << PHASE_SECOND_BURN_STR << "\n"; + } else if (deplState == AutonomousDeplState::DONE) { + of << PHASE_DONE << "\n"; } + of << "secs_since_start: " << std::to_string(secsSinceBoot) << "\n"; return true; } @@ -287,7 +291,7 @@ void SolarArrayDeploymentHandler::startFsmOff() { } fsmInfo.onOff = false; retryCounter = 0; - stateMachine = StateMachine::MAIN_POWER_ON; + stateMachine = StateMachine::MAIN_POWER_OFF; } void SolarArrayDeploymentHandler::finishFsm(ReturnValue_t resultForActionHelper) { diff --git a/mission/devices/SolarArrayDeploymentHandler.h b/mission/devices/SolarArrayDeploymentHandler.h index 20a558c6..2e4c775e 100644 --- a/mission/devices/SolarArrayDeploymentHandler.h +++ b/mission/devices/SolarArrayDeploymentHandler.h @@ -151,6 +151,7 @@ class SolarArrayDeploymentHandler : public ExecutableObjectIF, FsmInfo fsmInfo; StateMachine stateMachine = IDLE; bool actionActive = false; + bool firstCycle = true; ActionId_t activeCmd = HasActionsIF::INVALID_ACTION_ID; std::optional initUptime; PeriodicOperationDivider opDivider = PeriodicOperationDivider(5);