some more testing and bugfixes
All checks were successful
EIVE/eive-obsw/pipeline/pr-develop This commit looks good

This commit is contained in:
2022-10-14 14:55:37 +02:00
parent 99f703a2eb
commit 3cff1c48e9
9 changed files with 100 additions and 87 deletions

View File

@ -60,6 +60,62 @@ ReturnValue_t SolarArrayDeploymentHandler::performOperation(uint8_t operationCod
return returnvalue::OK;
}
void SolarArrayDeploymentHandler::handleStateMachine() {
if (stateMachine == MAIN_POWER_ON) {
mainLineSwitcher.sendSwitchCommand(mainLineSwitch, PowerSwitchIF::SWITCH_ON);
mainSwitchCountdown.setTimeout(mainLineSwitcher.getSwitchDelayMs());
stateMachine = WAIT_MAIN_POWER_ON;
sif::info << "S/A Deployment: Deployment power line on" << std::endl;
}
if (stateMachine == MAIN_POWER_OFF) {
// These should never fail
allOff();
stateMachine = WAIT_MAIN_POWER_OFF;
sif::info << "S/A Deployment: Deployment power line off" << std::endl;
}
if (stateMachine == WAIT_MAIN_POWER_ON) {
if (checkMainPowerOn()) {
if (DEBUG_MODE) {
sif::debug << "SA DEPL FSM: WAIT_MAIN_POWER_ON done -> SWITCH_DEPL_GPIOS" << std::endl;
}
stateMachine = SWITCH_DEPL_GPIOS;
}
}
if (stateMachine == WAIT_MAIN_POWER_OFF) {
if (checkMainPowerOff()) {
if (DEBUG_MODE) {
sif::debug << "SA DEPL FSM: WAIT_MAIN_POWER_OFF done -> FSM DONE" << std::endl;
}
sif::info << "S/A Deployment: FSM done" << std::endl;
finishFsm(returnvalue::OK);
}
}
if (stateMachine == SWITCH_DEPL_GPIOS) {
burnCountdown.setTimeout(fsmInfo.burnCountdownMs);
// This should never fail
channelAlternationCd.resetTimer();
if (not fsmInfo.dryRun) {
sa2Off();
sa1On();
fsmInfo.alternationDummy = true;
}
sif::info << "S/A Deployment: Burning" << std::endl;
triggerEvent(BURN_PHASE_START, fsmInfo.burnCountdownMs, fsmInfo.dryRun);
stateMachine = BURNING;
}
if (stateMachine == BURNING) {
saGpioAlternation();
if (burnCountdown.hasTimedOut()) {
if (DEBUG_MODE) {
sif::debug << "SA DEPL FSM: BURNING done -> WAIT_MAIN_POWER_OFF" << std::endl;
}
allOff();
triggerEvent(BURN_PHASE_DONE, fsmInfo.burnCountdownMs, fsmInfo.dryRun);
stateMachine = WAIT_MAIN_POWER_OFF;
}
}
}
ReturnValue_t SolarArrayDeploymentHandler::performAutonomousDepl(sd::SdCard sdCard, bool dryRun) {
using namespace std::filesystem;
using namespace std;
@ -72,21 +128,22 @@ ReturnValue_t SolarArrayDeploymentHandler::performAutonomousDepl(sd::SdCard sdCa
if (not exists(SD_0_DEPLY_INFO)) {
initFile(SD_0_DEPLY_INFO);
}
if (not autonomousDeplForFile(SD_0_DEPLY_INFO, dryRun)) {
if (not autonomousDeplForFile(sd::SdCard::SLOT_0, SD_0_DEPLY_INFO, dryRun)) {
initFile(SD_0_DEPLY_INFO);
}
} else if (sdCard == sd::SdCard::SLOT_1) {
if (not exists(SD_1_DEPLY_INFO)) {
initFile(SD_1_DEPLY_INFO);
}
if (not autonomousDeplForFile(SD_1_DEPLY_INFO, dryRun)) {
if (not autonomousDeplForFile(sd::SdCard::SLOT_1, SD_1_DEPLY_INFO, dryRun)) {
initFile(SD_1_DEPLY_INFO);
}
}
return returnvalue::OK;
}
bool SolarArrayDeploymentHandler::autonomousDeplForFile(const char* filename, bool dryRun) {
bool SolarArrayDeploymentHandler::autonomousDeplForFile(sd::SdCard sdCard, const char* filename,
bool dryRun) {
using namespace std;
ifstream file(filename);
string line;
@ -166,79 +223,31 @@ bool SolarArrayDeploymentHandler::autonomousDeplForFile(const char* filename, bo
startFsmOff();
}
}
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";
if (deplState == AutonomousDeplState::DONE) {
remove(filename);
if (sdCard == sd::SdCard::SLOT_0) {
remove(SD_0_DEPL_FILE);
} else {
remove(SD_1_DEPL_FILE);
}
triggerEvent(AUTONOMOUS_DEPLOYMENT_COMPLETED);
} else {
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";
}
of << "secs_since_start: " << std::to_string(secsSinceBoot) << "\n";
}
of << "secs_since_start: " << std::to_string(secsSinceBoot) << "\n";
return true;
}
void SolarArrayDeploymentHandler::handleStateMachine() {
if (stateMachine == MAIN_POWER_ON) {
mainLineSwitcher.sendSwitchCommand(mainLineSwitch, PowerSwitchIF::SWITCH_ON);
mainSwitchCountdown.setTimeout(mainLineSwitcher.getSwitchDelayMs());
stateMachine = WAIT_MAIN_POWER_ON;
sif::info << "S/A Deployment: Deployment power line on" << std::endl;
}
if (stateMachine == MAIN_POWER_OFF) {
// These should never fail
allOff();
stateMachine = WAIT_MAIN_POWER_OFF;
sif::info << "S/A Deployment: Deployment power line off" << std::endl;
}
if (stateMachine == WAIT_MAIN_POWER_ON) {
if (checkMainPowerOn()) {
if (DEBUG_MODE) {
sif::debug << "SA DEPL FSM: WAIT_MAIN_POWER_ON done -> SWITCH_DEPL_GPIOS" << std::endl;
}
stateMachine = SWITCH_DEPL_GPIOS;
}
}
if (stateMachine == WAIT_MAIN_POWER_OFF) {
if (checkMainPowerOff()) {
if (DEBUG_MODE) {
sif::debug << "SA DEPL FSM: WAIT_MAIN_POWER_OFF done -> FSM DONE" << std::endl;
}
sif::info << "S/A Deployment: FSM done" << std::endl;
finishFsm(returnvalue::OK);
}
}
if (stateMachine == SWITCH_DEPL_GPIOS) {
burnCountdown.setTimeout(fsmInfo.burnCountdownMs);
// This should never fail
channelAlternationCd.resetTimer();
if (not fsmInfo.dryRun) {
sa2Off();
sa1On();
fsmInfo.alternationDummy = true;
}
sif::info << "S/A Deployment: Burning" << std::endl;
triggerEvent(BURN_PHASE_START, fsmInfo.burnCountdownMs, fsmInfo.dryRun);
stateMachine = BURNING;
}
if (stateMachine == BURNING) {
saGpioAlternation();
if (burnCountdown.hasTimedOut()) {
if (DEBUG_MODE) {
sif::debug << "SA DEPL FSM: BURNING done -> WAIT_MAIN_POWER_OFF" << std::endl;
}
allOff();
triggerEvent(BURN_PHASE_DONE, fsmInfo.burnCountdownMs, fsmInfo.dryRun);
stateMachine = WAIT_MAIN_POWER_OFF;
}
}
}
bool SolarArrayDeploymentHandler::checkMainPowerOn() { return checkMainPower(true); }
bool SolarArrayDeploymentHandler::checkMainPowerOff() { return checkMainPower(false); }
@ -276,7 +285,6 @@ bool SolarArrayDeploymentHandler::startFsmOn(uint32_t burnCountdownSecs, bool dr
if (burnCountdownSecs > config::SA_DEPL_MAX_BURN_TIME) {
burnCountdownSecs = config::SA_DEPL_MAX_BURN_TIME;
}
fsmInfo.onOff = true;
fsmInfo.dryRun = dryRun;
fsmInfo.burnCountdownMs = burnCountdownSecs * 1000;
stateMachine = StateMachine::MAIN_POWER_ON;
@ -289,7 +297,6 @@ void SolarArrayDeploymentHandler::startFsmOff() {
// off commands override the state machine. Cancel any active action commands.
finishFsm(returnvalue::FAILED);
}
fsmInfo.onOff = false;
retryCounter = 0;
stateMachine = StateMachine::MAIN_POWER_OFF;
}
@ -298,7 +305,6 @@ void SolarArrayDeploymentHandler::finishFsm(ReturnValue_t resultForActionHelper)
retryCounter = 0;
stateMachine = StateMachine::IDLE;
fsmInfo.dryRun = false;
fsmInfo.onOff = false;
fsmInfo.alternationDummy = false;
if (actionActive) {
bool success = false;

View File

@ -117,8 +117,6 @@ class SolarArrayDeploymentHandler : public ExecutableObjectIF,
struct FsmInfo {
// Not required anymore
// DeploymentChannels channel;
// false if OFF, true is ON
bool onOff;
bool dryRun;
bool alternationDummy = false;
uint32_t burnCountdownMs = config::SA_DEPL_MAX_BURN_TIME;
@ -147,6 +145,8 @@ class SolarArrayDeploymentHandler : public ExecutableObjectIF,
event::makeEvent(SUBSYSTEM_ID, 6, severity::HIGH);
static constexpr Event DEPL_SA2_GPIO_SWTICH_OFF_FAILED =
event::makeEvent(SUBSYSTEM_ID, 7, severity::HIGH);
static constexpr Event AUTONOMOUS_DEPLOYMENT_COMPLETED =
event::makeEvent(SUBSYSTEM_ID, 8, severity::INFO);
FsmInfo fsmInfo;
StateMachine stateMachine = IDLE;
@ -164,7 +164,7 @@ class SolarArrayDeploymentHandler : public ExecutableObjectIF,
ReturnValue_t performAutonomousDepl(sd::SdCard sdCard, bool dryRun);
bool dryRunStringInFile(const char* filename);
bool autonomousDeplForFile(const char* filename, bool dryRun);
bool autonomousDeplForFile(sd::SdCard sdCard, const char* filename, bool dryRun);
/**
* This countdown is used to check if the PCDU sets the 8V line on in the intended time.
*/