|
|
|
@ -51,6 +51,7 @@ void PayloadPcduHandler::doShutDown() {
|
|
|
|
|
auto opCode = pwrStateMachine.fsm();
|
|
|
|
|
if (opCode == power::OpCodes::TO_OFF_DONE or opCode == power::OpCodes::TIMEOUT_OCCURED) {
|
|
|
|
|
pwrStateMachine.reset();
|
|
|
|
|
state = States::PL_PCDU_OFF;
|
|
|
|
|
// No need to set mode _MODE_POWER_DOWN, power switching was already handled
|
|
|
|
|
setMode(MODE_OFF);
|
|
|
|
|
}
|
|
|
|
@ -66,7 +67,8 @@ void PayloadPcduHandler::doTransition(Mode_t modeFrom, Submode_t subModeFrom) {
|
|
|
|
|
|
|
|
|
|
ReturnValue_t PayloadPcduHandler::stateMachineToNormal(Mode_t modeFrom, Submode_t subModeFrom) {
|
|
|
|
|
using namespace plpcdu;
|
|
|
|
|
if (submode == NormalSubmodes::SOLID_STATE_RELAYS_ADC_ON) {
|
|
|
|
|
bool doFinish = true;
|
|
|
|
|
if (((submode >> SOLID_STATE_RELAYS_ADC_ON) & 0b1) == 1) {
|
|
|
|
|
if (state == States::PL_PCDU_OFF) {
|
|
|
|
|
sif::error << "PayloadPcduHandler::stateMachineToNormal: Unexpected state PL_PCDU_OFF"
|
|
|
|
|
<< "detected" << std::endl;
|
|
|
|
@ -82,22 +84,24 @@ ReturnValue_t PayloadPcduHandler::stateMachineToNormal(Mode_t modeFrom, Submode_
|
|
|
|
|
gpioIF->pullHigh(gpioIds::PLPCDU_ENB_VBAT1);
|
|
|
|
|
state = States::ON_TRANS_SSR;
|
|
|
|
|
transitionOk = true;
|
|
|
|
|
doFinish = false;
|
|
|
|
|
}
|
|
|
|
|
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;
|
|
|
|
|
doFinish = false;
|
|
|
|
|
// 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) {
|
|
|
|
|
doFinish = false;
|
|
|
|
|
if (adcCountdown.hasTimedOut()) {
|
|
|
|
|
adcState = AdcStates::SEND_SETUP;
|
|
|
|
|
adcCmdExecuted = false;
|
|
|
|
@ -106,68 +110,38 @@ ReturnValue_t PayloadPcduHandler::stateMachineToNormal(Mode_t modeFrom, Submode_
|
|
|
|
|
if (adcState == AdcStates::SEND_SETUP) {
|
|
|
|
|
if (adcCmdExecuted) {
|
|
|
|
|
adcState = AdcStates::NORMAL;
|
|
|
|
|
doFinish = true;
|
|
|
|
|
adcCountdown.setTimeout(100);
|
|
|
|
|
adcCountdown.resetTimer();
|
|
|
|
|
adcCmdExecuted = false;
|
|
|
|
|
setMode(MODE_NORMAL, submode);
|
|
|
|
|
return HasReturnvaluesIF::RETURN_OK;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (submode == NormalSubmodes::DRO_ON) {
|
|
|
|
|
auto switchHandler = [&](NormalSubmodeBits bit, gpioId_t id, std::string info) {
|
|
|
|
|
if (((diffMask >> bit) & 1) == 1) {
|
|
|
|
|
if (((submode >> bit) & 1) == 1) {
|
|
|
|
|
#if OBSW_VERBOSE_LEVEL >= 1
|
|
|
|
|
sif::info << "Enabling PL PCDU DRO module" << std::endl;
|
|
|
|
|
sif::info << "Enabling PL PCDU " << info << " module" << std::endl;
|
|
|
|
|
#endif
|
|
|
|
|
// Switch on DRO and start monitoring for negative voltages
|
|
|
|
|
gpioIF->pullHigh(gpioIds::PLPCDU_ENB_DRO);
|
|
|
|
|
adcCountdown.setTimeout(100);
|
|
|
|
|
adcCountdown.resetTimer();
|
|
|
|
|
setMode(MODE_NORMAL, submode);
|
|
|
|
|
updateSwitchGpio(id, gpio::Levels::HIGH);
|
|
|
|
|
} else {
|
|
|
|
|
#if OBSW_VERBOSE_LEVEL >= 1
|
|
|
|
|
sif::info << "Disabling PL PCDU " << info << " module" << std::endl;
|
|
|
|
|
#endif
|
|
|
|
|
updateSwitchGpio(id, gpio::Levels::LOW);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (submode == NormalSubmodes::X8_ON) {
|
|
|
|
|
#if OBSW_VERBOSE_LEVEL >= 1
|
|
|
|
|
sif::info << "Enabling PL PCDU X8 module" << std::endl;
|
|
|
|
|
#endif
|
|
|
|
|
// Switch on DRO and start monitoring for negative voltages
|
|
|
|
|
gpioIF->pullHigh(gpioIds::PLPCDU_ENB_X8);
|
|
|
|
|
adcCountdown.setTimeout(100);
|
|
|
|
|
adcCountdown.resetTimer();
|
|
|
|
|
setMode(MODE_NORMAL, submode);
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
if (submode == NormalSubmodes::TX_ON) {
|
|
|
|
|
#if OBSW_VERBOSE_LEVEL >= 1
|
|
|
|
|
sif::info << "Enabling PL PCDU TX module" << std::endl;
|
|
|
|
|
#endif
|
|
|
|
|
// Switch on DRO and start monitoring for negative voltages
|
|
|
|
|
gpioIF->pullHigh(gpioIds::PLPCDU_ENB_TX);
|
|
|
|
|
adcCountdown.setTimeout(100);
|
|
|
|
|
adcCountdown.resetTimer();
|
|
|
|
|
setMode(MODE_NORMAL, submode);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (submode == NormalSubmodes::MPA_ON) {
|
|
|
|
|
#if OBSW_VERBOSE_LEVEL >= 1
|
|
|
|
|
sif::info << "Enabling PL PCDU MPA module" << std::endl;
|
|
|
|
|
#endif
|
|
|
|
|
// Switch on DRO and start monitoring for negative voltages
|
|
|
|
|
gpioIF->pullHigh(gpioIds::PLPCDU_ENB_MPA);
|
|
|
|
|
adcCountdown.setTimeout(100);
|
|
|
|
|
adcCountdown.resetTimer();
|
|
|
|
|
setMode(MODE_NORMAL, submode);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (submode == NormalSubmodes::HPA_ON) {
|
|
|
|
|
#if OBSW_VERBOSE_LEVEL >= 1
|
|
|
|
|
sif::info << "Enabling PL PCDU HPA module" << std::endl;
|
|
|
|
|
#endif
|
|
|
|
|
// Switch on DRO and start monitoring for negative voltages
|
|
|
|
|
gpioIF->pullHigh(gpioIds::PLPCDU_ENB_HPA);
|
|
|
|
|
adcCountdown.setTimeout(100);
|
|
|
|
|
adcCountdown.resetTimer();
|
|
|
|
|
switchHandler(DRO_ON, gpioIds::PLPCDU_ENB_DRO, "DRO");
|
|
|
|
|
switchHandler(X8_ON, gpioIds::PLPCDU_ENB_X8, "X8");
|
|
|
|
|
switchHandler(TX_ON, gpioIds::PLPCDU_ENB_TX, "TX");
|
|
|
|
|
switchHandler(MPA_ON, gpioIds::PLPCDU_ENB_MPA, "MPA");
|
|
|
|
|
switchHandler(HPA_ON, gpioIds::PLPCDU_ENB_HPA, "HPA");
|
|
|
|
|
if (doFinish) {
|
|
|
|
|
setMode(MODE_NORMAL, submode);
|
|
|
|
|
}
|
|
|
|
|
return RETURN_OK;
|
|
|
|
@ -201,6 +175,16 @@ ReturnValue_t PayloadPcduHandler::buildTransitionDeviceCommand(DeviceCommandId_t
|
|
|
|
|
return NOTHING_TO_SEND;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void PayloadPcduHandler::updateSwitchGpio(gpioId_t id, gpio::Levels level) {
|
|
|
|
|
if (level == gpio::Levels::HIGH) {
|
|
|
|
|
gpioIF->pullHigh(id);
|
|
|
|
|
} else {
|
|
|
|
|
gpioIF->pullLow(id);
|
|
|
|
|
}
|
|
|
|
|
adcCountdown.setTimeout(100);
|
|
|
|
|
adcCountdown.resetTimer();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void PayloadPcduHandler::fillCommandAndReplyMap() {
|
|
|
|
|
insertInCommandAndReplyMap(plpcdu::READ_CMD, 2, &adcSet);
|
|
|
|
|
insertInCommandAndReplyMap(plpcdu::READ_TEMP_EXT, 1, &adcSet);
|
|
|
|
@ -548,25 +532,33 @@ bool PayloadPcduHandler::checkCurrent(float val, float upperBound, Event event)
|
|
|
|
|
ReturnValue_t PayloadPcduHandler::isModeCombinationValid(Mode_t mode, Submode_t submode) {
|
|
|
|
|
using namespace plpcdu;
|
|
|
|
|
if (mode == MODE_NORMAL) {
|
|
|
|
|
diffMask = submode ^ this->submode;
|
|
|
|
|
// Also deals with the case where the mode is MODE_ON, submode should be 0 here
|
|
|
|
|
if (submode == NormalSubmodes::SOLID_STATE_RELAYS_ADC_ON and
|
|
|
|
|
(this->mode == MODE_NORMAL and this->submode != NormalSubmodes::ALL_OFF)) {
|
|
|
|
|
if ((((submode >> SOLID_STATE_RELAYS_ADC_ON) & 0b1) == SOLID_STATE_RELAYS_ADC_ON) and
|
|
|
|
|
(this->mode == MODE_NORMAL and this->submode != ALL_OFF_SUBMODE)) {
|
|
|
|
|
return TRANS_NOT_ALLOWED;
|
|
|
|
|
}
|
|
|
|
|
if ((submode == NormalSubmodes::DRO_ON and
|
|
|
|
|
this->submode != NormalSubmodes::SOLID_STATE_RELAYS_ADC_ON)) {
|
|
|
|
|
if (((((submode >> DRO_ON) & 1) == 1) and
|
|
|
|
|
((this->submode & 0b1) != (1 << SOLID_STATE_RELAYS_ADC_ON)))) {
|
|
|
|
|
return TRANS_NOT_ALLOWED;
|
|
|
|
|
}
|
|
|
|
|
if ((submode == NormalSubmodes::X8_ON and this->submode != NormalSubmodes::DRO_ON)) {
|
|
|
|
|
if ((((submode >> X8_ON) & 1) == 1) and
|
|
|
|
|
((this->submode & 0b11) != ((1 << SOLID_STATE_RELAYS_ADC_ON) | (1 << DRO_ON)))) {
|
|
|
|
|
return TRANS_NOT_ALLOWED;
|
|
|
|
|
}
|
|
|
|
|
if ((submode == NormalSubmodes::TX_ON and this->submode != NormalSubmodes::X8_ON)) {
|
|
|
|
|
if (((((submode >> TX_ON) & 1) == 1) and
|
|
|
|
|
((this->submode & 0b111) !=
|
|
|
|
|
((1 << X8_ON) | (1 << DRO_ON) | (1 << SOLID_STATE_RELAYS_ADC_ON))))) {
|
|
|
|
|
return TRANS_NOT_ALLOWED;
|
|
|
|
|
}
|
|
|
|
|
if ((submode == NormalSubmodes::MPA_ON and this->submode != NormalSubmodes::TX_ON)) {
|
|
|
|
|
if ((((submode >> MPA_ON) & 1) == 1 and
|
|
|
|
|
((this->submode & 0b1111) !=
|
|
|
|
|
((1 << TX_ON) | (1 << X8_ON) | (1 << DRO_ON) | (1 << SOLID_STATE_RELAYS_ADC_ON))))) {
|
|
|
|
|
return TRANS_NOT_ALLOWED;
|
|
|
|
|
}
|
|
|
|
|
if ((submode == NormalSubmodes::HPA_ON and this->submode != NormalSubmodes::MPA_ON)) {
|
|
|
|
|
if ((((submode >> HPA_ON) & 1) == 1 and
|
|
|
|
|
((this->submode & 0b11111) != ((1 << MPA_ON) | (1 << TX_ON) | (1 << X8_ON) |
|
|
|
|
|
(1 << DRO_ON) | (1 << SOLID_STATE_RELAYS_ADC_ON))))) {
|
|
|
|
|
return TRANS_NOT_ALLOWED;
|
|
|
|
|
}
|
|
|
|
|
return HasReturnvaluesIF::RETURN_OK;
|
|
|
|
|