plpcdu refactoring
All checks were successful
EIVE/eive-obsw/pipeline/head This commit looks good

This commit is contained in:
Robin Müller 2022-03-24 12:48:23 +01:00
parent 8f63e6321e
commit 2fb8ca4aaa
No known key found for this signature in database
GPG Key ID: 71B58F8A3CDFA9AC
2 changed files with 57 additions and 44 deletions

View File

@ -22,54 +22,66 @@ PayloadPcduHandler::PayloadPcduHandler(object_id_t objectId, object_id_t comIF,
sdcMan(sdcMan) {}
void PayloadPcduHandler::doStartUp() {
if ((state != States::PCDU_OFF) and (state != States::ON_TRANS_SSR)) {
if ((state != States::PL_PCDU_OFF) and (state != States::ON_TRANS_SSR)) {
// Config error
sif::error << "PayloadPcduHandler::doStartUp: Invalid state" << std::endl;
}
if (state == States::PCDU_OFF) {
// Switch on relays here
gpioIF->pullHigh(gpioIds::PLPCDU_ENB_VBAT0);
gpioIF->pullHigh(gpioIds::PLPCDU_ENB_VBAT1);
state = States::ON_TRANS_SSR;
transitionOk = true;
}
if (state == States::ON_TRANS_SSR) {
// If necessary, check whether a certain amount of time has elapsed
if (transitionOk) {
transitionOk = false;
state = States::ON_TRANS_ADC_CLOSE_ZERO;
// We are now in ON mode
startTransition(MODE_NORMAL, 0);
adcCountdown.setTimeout(50);
adcCountdown.resetTimer();
adcState = AdcStates::BOOT_DELAY;
// The ADC can now be read. If the values are not close to zero, we should not allow
// transition
monMode = MonitoringMode::CLOSE_TO_ZERO;
}
}
// TODO: Handle switching power on here
// TODO: Go to on mode here instead, indicating that the power is on
// We are now in ON mode
setMode(MODE_ON);
}
void PayloadPcduHandler::stateMachineToNormal() {
void PayloadPcduHandler::stateMachineToNormal(Mode_t modeFrom, Submode_t subModeFrom) {
using namespace plpcdu;
if (adcState == AdcStates::BOOT_DELAY) {
if (adcCountdown.hasTimedOut()) {
adcState = AdcStates::SEND_SETUP;
adcCmdExecuted = false;
if(submode == plpcdu::NORMAL_ALL_ON or submode == plpcdu::NORMAL_ADC_ONLY) {
if(state == States::PL_PCDU_OFF) {
// TODO: Config error, emit error printout
setMode(MODE_OFF);
}
}
if (adcState == AdcStates::SEND_SETUP) {
if (adcCmdExecuted) {
adcState = AdcStates::NORMAL;
setMode(MODE_NORMAL, NORMAL_ADC_ONLY);
adcCountdown.setTimeout(100);
adcCountdown.resetTimer();
adcCmdExecuted = false;
if (state == States::POWER_CHANNELS_ON) {
// Switch on relays here
gpioIF->pullHigh(gpioIds::PLPCDU_ENB_VBAT0);
gpioIF->pullHigh(gpioIds::PLPCDU_ENB_VBAT1);
state = States::ON_TRANS_SSR;
transitionOk = true;
}
if (state == States::ON_TRANS_SSR) {
// If necessary, check whether a certain amount of time has elapsed
if (transitionOk) {
transitionOk = false;
state = States::ON_TRANS_ADC_CLOSE_ZERO;
adcCountdown.setTimeout(50);
adcCountdown.resetTimer();
adcState = AdcStates::BOOT_DELAY;
// If the values are not close to zero, we should not allow transition
monMode = MonitoringMode::CLOSE_TO_ZERO;
}
}
if(state == States::ON_TRANS_ADC_CLOSE_ZERO) {
if (adcState == AdcStates::BOOT_DELAY) {
if (adcCountdown.hasTimedOut()) {
adcState = AdcStates::SEND_SETUP;
adcCmdExecuted = false;
}
}
if (adcState == AdcStates::SEND_SETUP) {
if (adcCmdExecuted) {
adcState = AdcStates::NORMAL;
if(submode == plpcdu::NORMAL_ADC_ONLY) {
setMode(MODE_NORMAL, NORMAL_ADC_ONLY);
}
adcCountdown.setTimeout(100);
adcCountdown.resetTimer();
adcCmdExecuted = false;
}
}
}
}
if (submode == plpcdu::NORMAL_ALL_ON) {
if (state == States::ON_TRANS_ADC_CLOSE_ZERO) {
if (not commandExecuted) {
if (not commandExecuted and adcState == AdcStates::NORMAL) {
float waitTime = DFT_SSR_TO_DRO_WAIT_TIME;
params.getValue(PARAM_KEY_MAP[SSR_TO_DRO_WAIT_TIME], waitTime);
countdown.setTimeout(std::round(waitTime * 1000));
@ -188,7 +200,7 @@ void PayloadPcduHandler::stateMachineToNormal() {
}
// ADC values are ok, 5 seconds have elapsed
if (transitionOk and countdown.hasTimedOut()) {
state = States::PCDU_ON;
state = States::PL_PCDU_ON;
setMode(MODE_NORMAL, plpcdu::NORMAL_ALL_ON);
countdown.resetTimer();
commandExecuted = false;
@ -200,7 +212,7 @@ void PayloadPcduHandler::stateMachineToNormal() {
void PayloadPcduHandler::doTransition(Mode_t modeFrom, Submode_t subModeFrom) {
if (mode == _MODE_TO_NORMAL) {
stateMachineToNormal();
stateMachineToNormal(modeFrom, subModeFrom);
}
}
@ -398,7 +410,7 @@ void PayloadPcduHandler::transitionBackToOff(bool notifyFdir) {
gpioIF->pullLow(gpioIds::PLPCDU_ENB_TX);
gpioIF->pullLow(gpioIds::PLPCDU_ENB_VBAT0);
gpioIF->pullLow(gpioIds::PLPCDU_ENB_VBAT1);
state = States::PCDU_OFF;
state = States::PL_PCDU_OFF;
adcState = AdcStates::OFF;
setMode(MODE_OFF);
if (notifyFdir) {

View File

@ -75,7 +75,8 @@ class PayloadPcduHandler : public DeviceHandlerBase {
private:
enum class States : uint8_t {
PCDU_OFF,
PL_PCDU_OFF,
POWER_CHANNELS_ON,
// Solid State Relay, enable battery voltages VBAT0 and VBAT1. This will also switch on
// the ADC
ON_TRANS_SSR,
@ -92,8 +93,8 @@ class PayloadPcduHandler : public DeviceHandlerBase {
// Switch on HPA component and monitor voltages for 5 seconds
ON_TRANS_HPA,
// All components of the experiment are on
PCDU_ON,
} state = States::PCDU_OFF;
PL_PCDU_ON,
} state = States::PL_PCDU_OFF;
enum class AdcMode { EXT_CONV, INT_CONV } adcMode = AdcMode::INT_CONV;
@ -158,7 +159,7 @@ class PayloadPcduHandler : public DeviceHandlerBase {
void checkAdcValues();
void handleOutOfBoundsPrintout();
void checkJsonFileInit();
void stateMachineToNormal();
void stateMachineToNormal(Mode_t modeFrom, Submode_t subModeFrom);
bool checkVoltage(float val, float lowerBound, float upperBound, Event event);
bool checkCurrent(float val, float upperBound, Event event);
void handleFailureInjection(std::string output, Event event);