eive-obsw/mission/system/objects/Stack5VHandler.cpp
Robin Mueller 7aae4efd69
All checks were successful
EIVE/eive-obsw/pipeline/head This commit looks good
added 5v stack status read in PCDU handler
2022-12-21 17:30:21 +01:00

66 lines
1.7 KiB
C++

#include "Stack5VHandler.h"
Stack5VHandler::Stack5VHandler(PowerSwitchIF& switcher) : switcher(switcher) {
stackLock = MutexFactory::instance()->createMutex();
}
ReturnValue_t Stack5VHandler::deviceToOn(StackCommander commander) {
MutexGuard mg(stackLock);
if (switchIsOn) {
if (commander == StackCommander::PL_PCDU) {
plPcduIsOn = true;
} else {
radSensorIsOn = true;
}
return returnvalue::OK;
}
if (handlerState == HandlerState::SWITCH_PENDING) {
return BUSY;
}
return switcher.sendSwitchCommand(stackSwitch, PowerSwitchIF::SWITCH_ON);
}
ReturnValue_t Stack5VHandler::deviceToOff(StackCommander commander) {
MutexGuard mg(stackLock);
if (not switchIsOn) {
if (commander == StackCommander::PL_PCDU) {
plPcduIsOn = false;
} else {
radSensorIsOn = false;
}
return returnvalue::OK;
}
if (handlerState == HandlerState::SWITCH_PENDING) {
return BUSY;
}
if ((commander == StackCommander::PL_PCDU and radSensorIsOn) or
(commander == StackCommander::RAD_SENSOR and plPcduIsOn)) {
return returnvalue::OK;
}
return switcher.sendSwitchCommand(stackSwitch, PowerSwitchIF::SWITCH_OFF);
}
bool Stack5VHandler::isSwitchOn() {
MutexGuard mg(stackLock);
if (switcher.getSwitchState(stackSwitch) == PowerSwitchIF::SWITCH_ON) {
if (not switchIsOn) {
if (handlerState == HandlerState::SWITCH_PENDING) {
handlerState = HandlerState::IDLE;
}
switchIsOn = true;
}
return true;
} else {
if (switchIsOn) {
if (handlerState == HandlerState::SWITCH_PENDING) {
handlerState = HandlerState::IDLE;
}
switchIsOn = false;
}
radSensorIsOn = false;
plPcduIsOn = false;
}
return false;
}