2022-03-05 03:02:09 +01:00
|
|
|
#include "DualLanePowerStateMachine.h"
|
|
|
|
|
|
|
|
#include <fsfw/devicehandlers/AssemblyBase.h>
|
|
|
|
#include <fsfw/power/PowerSwitchIF.h>
|
|
|
|
|
2022-03-25 16:01:44 +01:00
|
|
|
DualLanePowerStateMachine::DualLanePowerStateMachine(power::Switch_t switchA,
|
|
|
|
power::Switch_t switchB,
|
2022-03-05 03:02:09 +01:00
|
|
|
PowerSwitchIF* pwrSwitcher,
|
2022-03-07 16:47:15 +01:00
|
|
|
dur_millis_t checkTimeout)
|
2022-03-22 15:49:22 +01:00
|
|
|
: PowerStateMachineBase(pwrSwitcher, checkTimeout), SWITCH_A(switchA), SWITCH_B(switchB) {}
|
2022-03-07 16:47:15 +01:00
|
|
|
|
2022-03-22 15:49:22 +01:00
|
|
|
power::OpCodes DualLanePowerStateMachine::fsm() {
|
2022-03-05 03:02:09 +01:00
|
|
|
using namespace duallane;
|
2022-08-24 17:27:47 +02:00
|
|
|
ReturnValue_t switchStateA = returnvalue::OK;
|
|
|
|
ReturnValue_t switchStateB = returnvalue::OK;
|
2022-03-22 15:49:22 +01:00
|
|
|
if (state == power::States::IDLE or state == power::States::MODE_COMMANDING) {
|
2022-03-17 19:23:39 +01:00
|
|
|
return opResult;
|
2022-03-07 18:39:33 +01:00
|
|
|
}
|
2022-03-22 15:49:22 +01:00
|
|
|
if (state == power::States::SWITCHING_POWER or state == power::States::CHECKING_POWER) {
|
2022-03-05 03:02:09 +01:00
|
|
|
switchStateA = pwrSwitcher->getSwitchState(SWITCH_A);
|
|
|
|
switchStateB = pwrSwitcher->getSwitchState(SWITCH_B);
|
|
|
|
} else {
|
2022-03-17 19:23:39 +01:00
|
|
|
return opResult;
|
2022-03-05 03:02:09 +01:00
|
|
|
}
|
2022-03-07 18:39:33 +01:00
|
|
|
if (targetMode == HasModesIF::MODE_OFF) {
|
2022-03-05 03:02:09 +01:00
|
|
|
if (switchStateA == PowerSwitchIF::SWITCH_OFF and switchStateB == PowerSwitchIF::SWITCH_OFF) {
|
2022-03-22 15:49:22 +01:00
|
|
|
state = power::States::IDLE;
|
|
|
|
opResult = power::OpCodes::TO_OFF_DONE;
|
2022-03-17 19:23:39 +01:00
|
|
|
return opResult;
|
2022-03-05 03:02:09 +01:00
|
|
|
}
|
|
|
|
} else {
|
2022-03-07 18:39:33 +01:00
|
|
|
switch (targetSubmode) {
|
2022-03-05 03:02:09 +01:00
|
|
|
case (A_SIDE): {
|
|
|
|
if (switchStateA == PowerSwitchIF::SWITCH_ON and
|
|
|
|
switchStateB == PowerSwitchIF::SWITCH_OFF) {
|
2022-03-22 15:49:22 +01:00
|
|
|
state = power::States::MODE_COMMANDING;
|
|
|
|
opResult = power::OpCodes::TO_NOT_OFF_DONE;
|
2022-03-17 19:23:39 +01:00
|
|
|
return opResult;
|
2022-03-05 03:02:09 +01:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case (B_SIDE): {
|
|
|
|
if (switchStateA == PowerSwitchIF::SWITCH_OFF and
|
|
|
|
switchStateB == PowerSwitchIF::SWITCH_ON) {
|
2022-03-22 15:49:22 +01:00
|
|
|
state = power::States::MODE_COMMANDING;
|
|
|
|
opResult = power::OpCodes::TO_NOT_OFF_DONE;
|
2022-03-17 19:23:39 +01:00
|
|
|
return opResult;
|
2022-03-05 03:02:09 +01:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case (DUAL_MODE): {
|
|
|
|
if (switchStateA == PowerSwitchIF::SWITCH_ON and switchStateB == PowerSwitchIF::SWITCH_ON) {
|
2022-03-22 15:49:22 +01:00
|
|
|
state = power::States::MODE_COMMANDING;
|
|
|
|
opResult = power::OpCodes::TO_NOT_OFF_DONE;
|
2022-03-17 19:23:39 +01:00
|
|
|
return opResult;
|
2022-03-05 03:02:09 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2022-03-22 15:49:22 +01:00
|
|
|
if (state == power::States::SWITCHING_POWER) {
|
2022-03-07 18:39:33 +01:00
|
|
|
if (targetMode == HasModesIF::MODE_OFF) {
|
2022-03-05 03:02:09 +01:00
|
|
|
if (switchStateA != PowerSwitchIF::SWITCH_OFF) {
|
2022-03-07 18:39:33 +01:00
|
|
|
pwrSwitcher->sendSwitchCommand(SWITCH_A, PowerSwitchIF::SWITCH_OFF);
|
2022-03-05 03:02:09 +01:00
|
|
|
}
|
|
|
|
if (switchStateB != PowerSwitchIF::SWITCH_OFF) {
|
|
|
|
pwrSwitcher->sendSwitchCommand(SWITCH_B, PowerSwitchIF::SWITCH_OFF);
|
|
|
|
}
|
2022-03-07 16:47:15 +01:00
|
|
|
checkTimeout.resetTimer();
|
2022-03-05 03:02:09 +01:00
|
|
|
} else {
|
2022-03-07 18:39:33 +01:00
|
|
|
switch (targetSubmode) {
|
2022-03-05 03:02:09 +01:00
|
|
|
case (A_SIDE): {
|
|
|
|
if (switchStateA != PowerSwitchIF::SWITCH_ON) {
|
|
|
|
pwrSwitcher->sendSwitchCommand(SWITCH_A, PowerSwitchIF::SWITCH_ON);
|
|
|
|
}
|
|
|
|
if (switchStateB != PowerSwitchIF::SWITCH_OFF) {
|
|
|
|
pwrSwitcher->sendSwitchCommand(SWITCH_B, PowerSwitchIF::SWITCH_OFF);
|
|
|
|
}
|
2022-03-07 16:47:15 +01:00
|
|
|
checkTimeout.resetTimer();
|
2022-03-05 03:02:09 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case (B_SIDE): {
|
|
|
|
if (switchStateA != PowerSwitchIF::SWITCH_OFF) {
|
|
|
|
pwrSwitcher->sendSwitchCommand(SWITCH_A, PowerSwitchIF::SWITCH_OFF);
|
|
|
|
}
|
|
|
|
if (switchStateB != PowerSwitchIF::SWITCH_ON) {
|
2022-03-17 10:48:35 +01:00
|
|
|
pwrSwitcher->sendSwitchCommand(SWITCH_B, PowerSwitchIF::SWITCH_ON);
|
2022-03-05 03:02:09 +01:00
|
|
|
}
|
2022-03-07 16:47:15 +01:00
|
|
|
checkTimeout.resetTimer();
|
2022-03-05 03:02:09 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case (DUAL_MODE): {
|
|
|
|
if (switchStateA != PowerSwitchIF::SWITCH_ON) {
|
|
|
|
pwrSwitcher->sendSwitchCommand(SWITCH_A, PowerSwitchIF::SWITCH_ON);
|
|
|
|
}
|
|
|
|
if (switchStateB != PowerSwitchIF::SWITCH_ON) {
|
|
|
|
pwrSwitcher->sendSwitchCommand(SWITCH_B, PowerSwitchIF::SWITCH_ON);
|
|
|
|
}
|
2022-03-07 16:47:15 +01:00
|
|
|
checkTimeout.resetTimer();
|
2022-03-05 03:02:09 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2022-03-22 15:49:22 +01:00
|
|
|
state = power::States::CHECKING_POWER;
|
2022-03-05 03:02:09 +01:00
|
|
|
}
|
2022-03-22 15:49:22 +01:00
|
|
|
if (state == power::States::CHECKING_POWER) {
|
2022-03-07 16:47:15 +01:00
|
|
|
if (checkTimeout.hasTimedOut()) {
|
2022-03-22 15:49:22 +01:00
|
|
|
return power::OpCodes::TIMEOUT_OCCURED;
|
2022-03-07 16:47:15 +01:00
|
|
|
}
|
2022-03-05 03:02:09 +01:00
|
|
|
}
|
2022-03-17 19:23:39 +01:00
|
|
|
return opResult;
|
2022-03-05 03:02:09 +01:00
|
|
|
}
|