67 lines
1.8 KiB
C++
67 lines
1.8 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;
|
|
}
|
|
handlerState == HandlerState::SWITCH_PENDING;
|
|
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;
|
|
}
|
|
handlerState == HandlerState::SWITCH_PENDING;
|
|
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;
|
|
}
|