eive-obsw/linux/devices/PayloadPcduHandler.cpp

162 lines
5.4 KiB
C++
Raw Normal View History

2022-02-10 14:24:34 +01:00
#include "PayloadPcduHandler.h"
2022-02-10 16:55:06 +01:00
#include "devices/gpioIds.h"
PayloadPcduHandler::PayloadPcduHandler(object_id_t objectId, object_id_t comIF, CookieIF* cookie,
2022-02-10 16:55:18 +01:00
GpioIF* gpioIF)
: DeviceHandlerBase(objectId, comIF, cookie), gpioIF(gpioIF) {}
2022-02-10 14:24:34 +01:00
2022-02-10 16:05:36 +01:00
void PayloadPcduHandler::doStartUp() {
2022-02-10 18:05:14 +01:00
if ((state != States::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
2022-02-10 18:05:14 +01:00
if (transitionOk) {
transitionOk = false;
// We are now in ON mode
setMode(MODE_ON);
// The ADC can now be read. If the values are not close to zero, we should not allow
// transition
monMode = MonitoringMode::CLOSE_TO_ZERO;
2022-02-10 16:55:18 +01:00
}
2022-02-10 16:05:36 +01:00
}
2022-02-10 16:55:06 +01:00
}
void PayloadPcduHandler::doTransition(Mode_t modeFrom, Submode_t subModeFrom) {
2022-02-10 16:55:18 +01:00
if (mode == _MODE_TO_NORMAL) {
if (state == States::ON_TRANS_ADC_CLOSE_ZERO) {
2022-02-10 18:05:14 +01:00
if (not commandExecuted) {
countdown.resetTimer();
commandExecuted = true;
}
// ADC values are ok, 5 seconds have elapsed
2022-02-10 18:05:14 +01:00
if (transitionOk and countdown.hasTimedOut()) {
state = States::ON_TRANS_DRO;
// Now start monitoring for negative voltages instead
monMode = MonitoringMode::NEGATIVE;
countdown.resetTimer();
commandExecuted = false;
transitionOk = false;
}
}
if (state == States::ON_TRANS_DRO) {
2022-02-10 18:05:14 +01:00
if (not commandExecuted) {
// Switch on DRO and start monitoring for negative voltagea
2022-02-10 16:55:06 +01:00
gpioIF->pullHigh(gpioIds::PLPCDU_ENB_DRO);
2022-02-10 18:05:14 +01:00
commandExecuted = true;
}
// ADC values are ok, 5 seconds have elapsed
2022-02-10 18:05:14 +01:00
if (transitionOk and countdown.hasTimedOut()) {
state = States::ON_TRANS_X8;
countdown.resetTimer();
commandExecuted = false;
transitionOk = false;
}
}
if (state == States::ON_TRANS_X8) {
2022-02-10 18:05:14 +01:00
if (not commandExecuted) {
// Switch on X8
2022-02-10 16:55:06 +01:00
gpioIF->pullHigh(gpioIds::PLPCDU_ENB_X8);
2022-02-10 18:05:14 +01:00
commandExecuted = true;
}
// ADC values are ok, 5 seconds have elapsed
2022-02-10 18:05:14 +01:00
if (transitionOk and countdown.hasTimedOut()) {
state = States::ON_TRANS_TX;
countdown.resetTimer();
commandExecuted = false;
transitionOk = false;
}
}
2022-02-10 18:05:14 +01:00
if (state == States::ON_TRANS_TX) {
if (not commandExecuted) {
// Switch on TX
gpioIF->pullHigh(gpioIds::PLPCDU_ENB_TX);
2022-02-10 18:05:14 +01:00
commandExecuted = true;
}
// ADC values are ok, 5 seconds have elapsed
2022-02-10 18:05:14 +01:00
if (transitionOk and countdown.hasTimedOut()) {
state = States::ON_TRANS_MPA;
countdown.resetTimer();
commandExecuted = false;
transitionOk = false;
}
}
2022-02-10 18:05:14 +01:00
if (state == States::ON_TRANS_MPA) {
if (not commandExecuted) {
// Switch on MPA
gpioIF->pullHigh(gpioIds::PLPCDU_ENB_MPA);
2022-02-10 18:05:14 +01:00
commandExecuted = true;
}
// ADC values are ok, 5 seconds have elapsed
2022-02-10 18:05:14 +01:00
if (transitionOk and countdown.hasTimedOut()) {
state = States::ON_TRANS_HPA;
countdown.resetTimer();
commandExecuted = false;
transitionOk = false;
}
}
2022-02-10 18:05:14 +01:00
if (state == States::ON_TRANS_HPA) {
if (not commandExecuted) {
// Switch on HPA
2022-02-10 16:55:06 +01:00
gpioIF->pullHigh(gpioIds::PLPCDU_ENB_HPA);
2022-02-10 18:05:14 +01:00
commandExecuted = true;
2022-02-10 16:55:06 +01:00
}
// ADC values are ok, 5 seconds have elapsed
2022-02-10 18:05:14 +01:00
if (transitionOk and countdown.hasTimedOut()) {
state = States::PCDU_ON;
2022-02-10 16:55:06 +01:00
setMode(MODE_NORMAL);
countdown.resetTimer();
commandExecuted = false;
transitionOk = false;
2022-02-10 16:55:06 +01:00
}
2022-02-10 16:55:18 +01:00
}
2022-02-10 16:05:36 +01:00
}
}
2022-02-10 14:24:34 +01:00
void PayloadPcduHandler::doShutDown() {}
ReturnValue_t PayloadPcduHandler::buildNormalDeviceCommand(DeviceCommandId_t* id) {
return HasReturnvaluesIF::RETURN_OK;
}
ReturnValue_t PayloadPcduHandler::buildTransitionDeviceCommand(DeviceCommandId_t* id) {
return HasReturnvaluesIF::RETURN_OK;
}
void PayloadPcduHandler::fillCommandAndReplyMap() {}
ReturnValue_t PayloadPcduHandler::buildCommandFromCommand(DeviceCommandId_t deviceCommand,
const uint8_t* commandData,
size_t commandDataLen) {
return HasReturnvaluesIF::RETURN_OK;
}
ReturnValue_t PayloadPcduHandler::scanForReply(const uint8_t* start, size_t remainingSize,
DeviceCommandId_t* foundId, size_t* foundLen) {
return HasReturnvaluesIF::RETURN_OK;
}
ReturnValue_t PayloadPcduHandler::interpretDeviceReply(DeviceCommandId_t id,
const uint8_t* packet) {
return HasReturnvaluesIF::RETURN_OK;
}
2022-02-10 18:04:53 +01:00
uint32_t PayloadPcduHandler::getTransitionDelayMs(Mode_t modeFrom, Mode_t modeTo) {
// 20 minutes transition delay is allowed
return 20 * 60 * 60;
}
2022-02-10 14:24:34 +01:00
ReturnValue_t PayloadPcduHandler::initializeLocalDataPool(localpool::DataPool& localDataPoolMap,
LocalDataPoolManager& poolManager) {
return HasReturnvaluesIF::RETURN_OK;
}