Merge branch 'mueller_5v_stack_cmd_for_devices' of https://egit.irs.uni-stuttgart.de/eive/eive-obsw into mueller_5v_stack_cmd_for_devices
All checks were successful
EIVE/eive-obsw/pipeline/pr-develop This commit looks good

This commit is contained in:
Robin Müller 2022-12-22 14:33:04 +01:00
commit 95113179d8
12 changed files with 121 additions and 62 deletions

View File

@ -228,10 +228,6 @@ ReturnValue_t ObjectFactory::createRadSensorComponent(LinuxLibgpioIF* gpioComIF,
auto radSensor = new RadiationSensorHandler(objects::RAD_SENSOR, objects::SPI_MAIN_COM_IF, auto radSensor = new RadiationSensorHandler(objects::RAD_SENSOR, objects::SPI_MAIN_COM_IF,
spiCookieRadSensor, gpioComIF, stackHandler); spiCookieRadSensor, gpioComIF, stackHandler);
static_cast<void>(radSensor); static_cast<void>(radSensor);
// The radiation sensor ADC is powered by the 5V stack connector which should always be on
radSensor->setStartUpImmediately();
// It's a simple sensor, so just to to normal mode immediately
radSensor->setToGoToNormalModeImmediately();
#if OBSW_DEBUG_RAD_SENSOR == 1 #if OBSW_DEBUG_RAD_SENSOR == 1
radSensor->enablePeriodicDataPrint(true); radSensor->enablePeriodicDataPrint(true);
#endif #endif
@ -834,7 +830,8 @@ ReturnValue_t ObjectFactory::createCcsdsComponents(LinuxLibgpioIF* gpioComIF,
} }
void ObjectFactory::createPlPcduComponents(LinuxLibgpioIF* gpioComIF, SpiComIF* spiComIF, void ObjectFactory::createPlPcduComponents(LinuxLibgpioIF* gpioComIF, SpiComIF* spiComIF,
PowerSwitchIF* pwrSwitcher) { PowerSwitchIF* pwrSwitcher,
Stack5VHandler& stackHandler) {
using namespace gpio; using namespace gpio;
// Create all GPIO components first // Create all GPIO components first
GpioCookie* plPcduGpios = new GpioCookie; GpioCookie* plPcduGpios = new GpioCookie;
@ -880,10 +877,9 @@ void ObjectFactory::createPlPcduComponents(LinuxLibgpioIF* gpioComIF, SpiComIF*
new SpiCookie(addresses::PLPCDU_ADC, gpioIds::PLPCDU_ADC_CS, plpcdu::MAX_ADC_REPLY_SIZE, new SpiCookie(addresses::PLPCDU_ADC, gpioIds::PLPCDU_ADC_CS, plpcdu::MAX_ADC_REPLY_SIZE,
spi::DEFAULT_MAX_1227_MODE, spi::PL_PCDU_MAX_1227_SPEED); spi::DEFAULT_MAX_1227_MODE, spi::PL_PCDU_MAX_1227_SPEED);
// Create device handler components // Create device handler components
auto plPcduHandler = new PayloadPcduHandler( auto plPcduHandler =
objects::PLPCDU_HANDLER, objects::SPI_MAIN_COM_IF, spiCookie, gpioComIF, new PayloadPcduHandler(objects::PLPCDU_HANDLER, objects::SPI_MAIN_COM_IF, spiCookie,
SdCardManager::instance(), pwrSwitcher, pcdu::Switches::PDU2_CH1_PL_PCDU_BATT_0_14V8, gpioComIF, SdCardManager::instance(), stackHandler, false);
pcdu::Switches::PDU2_CH6_PL_PCDU_BATT_1_14V8, false);
spiCookie->setCallbackMode(PayloadPcduHandler::extConvAsTwoCallback, plPcduHandler); spiCookie->setCallbackMode(PayloadPcduHandler::extConvAsTwoCallback, plPcduHandler);
// plPcduHandler->enablePeriodicPrintout(true, 5); // plPcduHandler->enablePeriodicPrintout(true, 5);
// static_cast<void>(plPcduHandler); // static_cast<void>(plPcduHandler);

View File

@ -28,7 +28,7 @@ void createCommunicationInterfaces(LinuxLibgpioIF** gpioComIF, SerialComIF** uar
SpiComIF** spiRwComIF); SpiComIF** spiRwComIF);
void createPcduComponents(LinuxLibgpioIF* gpioComIF, PowerSwitchIF** pwrSwitcher); void createPcduComponents(LinuxLibgpioIF* gpioComIF, PowerSwitchIF** pwrSwitcher);
void createPlPcduComponents(LinuxLibgpioIF* gpioComIF, SpiComIF* spiComIF, void createPlPcduComponents(LinuxLibgpioIF* gpioComIF, SpiComIF* spiComIF,
PowerSwitchIF* pwrSwitcher); PowerSwitchIF* pwrSwitcher, Stack5VHandler& stackHandler);
void createTmpComponents(); void createTmpComponents();
ReturnValue_t createRadSensorComponent(LinuxLibgpioIF* gpioComIF, Stack5VHandler& handler); ReturnValue_t createRadSensorComponent(LinuxLibgpioIF* gpioComIF, Stack5VHandler& handler);
void createAcsBoardComponents(LinuxLibgpioIF* gpioComIF, SerialComIF* uartComIF, void createAcsBoardComponents(LinuxLibgpioIF* gpioComIF, SerialComIF* uartComIF,

View File

@ -50,7 +50,7 @@ void ObjectFactory::produce(void* args) {
createTmpComponents(); createTmpComponents();
#endif #endif
createSolarArrayDeploymentComponents(*pwrSwitcher, *gpioComIF); createSolarArrayDeploymentComponents(*pwrSwitcher, *gpioComIF);
createPlPcduComponents(gpioComIF, spiMainComIF, pwrSwitcher); createPlPcduComponents(gpioComIF, spiMainComIF, pwrSwitcher, *stackHandler);
#if OBSW_ADD_SYRLINKS == 1 #if OBSW_ADD_SYRLINKS == 1
createSyrlinksComponents(pwrSwitcher); createSyrlinksComponents(pwrSwitcher);
#endif /* OBSW_ADD_SYRLINKS == 1 */ #endif /* OBSW_ADD_SYRLINKS == 1 */

View File

@ -11,6 +11,7 @@
PCDUHandler::PCDUHandler(object_id_t setObjectId, size_t cmdQueueSize) PCDUHandler::PCDUHandler(object_id_t setObjectId, size_t cmdQueueSize)
: SystemObject(setObjectId), : SystemObject(setObjectId),
poolManager(this, nullptr), poolManager(this, nullptr),
p60CoreHk(objects::P60DOCK_HANDLER),
pdu1CoreHk(this), pdu1CoreHk(this),
pdu2CoreHk(this), pdu2CoreHk(this),
switcherSet(this), switcherSet(this),
@ -28,6 +29,22 @@ ReturnValue_t PCDUHandler::performOperation(uint8_t counter) {
readCommandQueue(); readCommandQueue();
return returnvalue::OK; return returnvalue::OK;
} }
uint8_t switchState = 0;
{
PoolReadGuard pg(&p60CoreHk.outputEnables);
if (pg.getReadResult() == returnvalue::OK) {
switchState = p60CoreHk.outputEnables.value[10];
}
}
{
PoolReadGuard pg(&switcherSet.p60Dock5VStack);
if (pg.getReadResult() == returnvalue::OK) {
if (switcherSet.p60Dock5VStack.value != switchState) {
triggerEvent(power::SWITCH_HAS_CHANGED, switchState, pcdu::Switches::P60_DOCK_5V_STACK);
}
switcherSet.p60Dock5VStack.value = switchState;
}
}
return returnvalue::OK; return returnvalue::OK;
} }
@ -398,6 +415,7 @@ ReturnValue_t PCDUHandler::initializeLocalDataPool(localpool::DataPool& localDat
using namespace pcdu; using namespace pcdu;
localDataPoolMap.emplace(PoolIds::PDU1_SWITCHES, &pdu1Switches); localDataPoolMap.emplace(PoolIds::PDU1_SWITCHES, &pdu1Switches);
localDataPoolMap.emplace(PoolIds::PDU2_SWITCHES, &pdu2Switches); localDataPoolMap.emplace(PoolIds::PDU2_SWITCHES, &pdu2Switches);
localDataPoolMap.emplace(PoolIds::P60DOCK_SWITCHES, &p60Dock5VSwitch);
poolManager.subscribeForRegularPeriodicPacket( poolManager.subscribeForRegularPeriodicPacket(
subdp::RegularHkPeriodicParams(switcherSet.getSid(), false, 5.0)); subdp::RegularHkPeriodicParams(switcherSet.getSid(), false, 5.0));
return returnvalue::OK; return returnvalue::OK;

View File

@ -56,6 +56,8 @@ class PCDUHandler : public PowerSwitchIF,
/** Housekeeping manager. Handles updates of local pool variables. */ /** Housekeeping manager. Handles updates of local pool variables. */
LocalDataPoolManager poolManager; LocalDataPoolManager poolManager;
P60Dock::CoreHkSet p60CoreHk;
/** Hk table dataset of PDU1 */ /** Hk table dataset of PDU1 */
PDU1::Pdu1CoreHk pdu1CoreHk; PDU1::Pdu1CoreHk pdu1CoreHk;
/** /**
@ -71,6 +73,7 @@ class PCDUHandler : public PowerSwitchIF,
PoolEntry<uint8_t>(pcdu::INIT_SWITCHES_PDU1.data(), pcdu::INIT_SWITCHES_PDU1.size()); PoolEntry<uint8_t>(pcdu::INIT_SWITCHES_PDU1.data(), pcdu::INIT_SWITCHES_PDU1.size());
PoolEntry<uint8_t> pdu2Switches = PoolEntry<uint8_t> pdu2Switches =
PoolEntry<uint8_t>(pcdu::INIT_SWITCHES_PDU2.data(), pcdu::INIT_SWITCHES_PDU2.size()); PoolEntry<uint8_t>(pcdu::INIT_SWITCHES_PDU2.data(), pcdu::INIT_SWITCHES_PDU2.size());
PoolEntry<uint8_t> p60Dock5VSwitch = PoolEntry<uint8_t>();
/** The timeStamp of the current pdu2HkTableDataset */ /** The timeStamp of the current pdu2HkTableDataset */
CCSDSTime::CDS_short timeStampPdu2HkDataset; CCSDSTime::CDS_short timeStampPdu2HkDataset;

View File

@ -16,29 +16,37 @@
PayloadPcduHandler::PayloadPcduHandler(object_id_t objectId, object_id_t comIF, CookieIF* cookie, PayloadPcduHandler::PayloadPcduHandler(object_id_t objectId, object_id_t comIF, CookieIF* cookie,
GpioIF* gpioIF, SdCardMountedIF* sdcMan, GpioIF* gpioIF, SdCardMountedIF* sdcMan,
PowerSwitchIF* pwrSwitcher, power::Switch_t switchA, Stack5VHandler& stackHandler, bool periodicPrintout)
power::Switch_t switchB, bool periodicPrintout)
: DeviceHandlerBase(objectId, comIF, cookie), : DeviceHandlerBase(objectId, comIF, cookie),
adcSet(this), adcSet(this),
stackHandler(stackHandler),
periodicPrintout(periodicPrintout), periodicPrintout(periodicPrintout),
gpioIF(gpioIF), gpioIF(gpioIF),
sdcMan(sdcMan), sdcMan(sdcMan) {}
pwrStateMachine(switchA, switchB, pwrSwitcher) {}
void PayloadPcduHandler::doStartUp() { void PayloadPcduHandler::doStartUp() {
if ((state != States::PL_PCDU_OFF) and (state != States::ON_TRANS_SSR)) { if ((state != States::PL_PCDU_OFF) and (state != States::ON_TRANS_SSR)) {
// Config error // Config error
sif::error << "PayloadPcduHandler::doStartUp: Invalid state" << std::endl; sif::error << "PayloadPcduHandler::doStartUp: Invalid state" << std::endl;
} }
if (pwrStateMachine.getState() == power::States::IDLE) {
pwrStateMachine.start(MODE_ON, pwrSubmode);
}
clearSetOnOffFlag = true; clearSetOnOffFlag = true;
auto opCode = pwrStateMachine.fsm(); if (state == States::PL_PCDU_OFF) {
if (opCode == power::OpCodes::TO_NOT_OFF_DONE or opCode == power::OpCodes::TIMEOUT_OCCURED) { state = States::STACK_5V_SWITCHING;
pwrStateMachine.reset(); }
if (state == States::STACK_5V_SWITCHING) {
ReturnValue_t retval = stackHandler.deviceToOn(StackCommander::PL_PCDU);
if (retval == BUSY) {
return;
}
state == States::STACK_5V_PENDING;
}
if (state == States::STACK_5V_PENDING) {
if (stackHandler.isSwitchOn()) {
state = States::STACK_5V_CORRECT;
}
}
if (state == States::STACK_5V_CORRECT) {
quickTransitionAlreadyCalled = false; quickTransitionAlreadyCalled = false;
state = States::POWER_CHANNELS_ON;
setMode(_MODE_TO_ON); setMode(_MODE_TO_ON);
} }
} }
@ -48,17 +56,24 @@ void PayloadPcduHandler::doShutDown() {
quickTransitionBackToOff(false, false); quickTransitionBackToOff(false, false);
quickTransitionAlreadyCalled = true; quickTransitionAlreadyCalled = true;
} }
if (pwrStateMachine.getState() == power::States::IDLE) {
pwrStateMachine.start(MODE_OFF, 0);
}
if (clearSetOnOffFlag) { if (clearSetOnOffFlag) {
std::memset(adcSet.processed.value, 0, adcSet.processed.getSerializedSize()); std::memset(adcSet.processed.value, 0, adcSet.processed.getSerializedSize());
clearSetOnOffFlag = false; clearSetOnOffFlag = false;
} }
auto opCode = pwrStateMachine.fsm(); if (state == States::STACK_5V_SWITCHING) {
if (opCode == power::OpCodes::TO_OFF_DONE or opCode == power::OpCodes::TIMEOUT_OCCURED) { ReturnValue_t retval = stackHandler.deviceToOff(StackCommander::PL_PCDU);
pwrStateMachine.reset(); if (retval == BUSY) {
return;
}
state == States::STACK_5V_PENDING;
}
if (state == States::STACK_5V_PENDING) {
if (not stackHandler.isSwitchOn()) {
state == States::STACK_5V_CORRECT;
}
}
if (state == States::STACK_5V_CORRECT) {
state = States::PL_PCDU_OFF; state = States::PL_PCDU_OFF;
// No need to set mode _MODE_POWER_DOWN, power switching was already handled // No need to set mode _MODE_POWER_DOWN, power switching was already handled
setMode(MODE_OFF); setMode(MODE_OFF);
@ -83,7 +98,7 @@ ReturnValue_t PayloadPcduHandler::stateMachineToNormal(Mode_t modeFrom, Submode_
setMode(MODE_OFF); setMode(MODE_OFF);
return returnvalue::FAILED; return returnvalue::FAILED;
} }
if (state == States::POWER_CHANNELS_ON) { if (state == States::STACK_5V_CORRECT) {
#if OBSW_VERBOSE_LEVEL >= 1 #if OBSW_VERBOSE_LEVEL >= 1
sif::info << "Switching on SSR VBAT0 & VBAT1 GPIOs" << std::endl; sif::info << "Switching on SSR VBAT0 & VBAT1 GPIOs" << std::endl;
#endif #endif
@ -358,7 +373,7 @@ void PayloadPcduHandler::quickTransitionBackToOff(bool startTransitionToOff, boo
gpioIF->pullLow(gpioIds::PLPCDU_ENB_TX); gpioIF->pullLow(gpioIds::PLPCDU_ENB_TX);
gpioIF->pullLow(gpioIds::PLPCDU_ENB_VBAT0); gpioIF->pullLow(gpioIds::PLPCDU_ENB_VBAT0);
gpioIF->pullLow(gpioIds::PLPCDU_ENB_VBAT1); gpioIF->pullLow(gpioIds::PLPCDU_ENB_VBAT1);
state = States::PL_PCDU_OFF; state = States::STACK_5V_SWITCHING;
adcState = AdcStates::OFF; adcState = AdcStates::OFF;
if (startTransitionToOff) { if (startTransitionToOff) {
startTransition(MODE_OFF, 0); startTransition(MODE_OFF, 0);

View File

@ -4,6 +4,7 @@
#include <fsfw/devicehandlers/DeviceHandlerBase.h> #include <fsfw/devicehandlers/DeviceHandlerBase.h>
#include <fsfw/globalfunctions/PeriodicOperationDivider.h> #include <fsfw/globalfunctions/PeriodicOperationDivider.h>
#include <fsfw/timemanager/Countdown.h> #include <fsfw/timemanager/Countdown.h>
#include <mission/system/objects/Stack5VHandler.h>
#include "events/subsystemIdRanges.h" #include "events/subsystemIdRanges.h"
#include "fsfw/FSFW.h" #include "fsfw/FSFW.h"
@ -62,8 +63,7 @@ class PayloadPcduHandler : public DeviceHandlerBase {
static constexpr Event I_HPA_OUT_OF_BOUNDS = event::makeEvent(SUBSYSTEM_ID, 11, severity::MEDIUM); static constexpr Event I_HPA_OUT_OF_BOUNDS = event::makeEvent(SUBSYSTEM_ID, 11, severity::MEDIUM);
PayloadPcduHandler(object_id_t objectId, object_id_t comIF, CookieIF* cookie, GpioIF* gpioIF, PayloadPcduHandler(object_id_t objectId, object_id_t comIF, CookieIF* cookie, GpioIF* gpioIF,
SdCardMountedIF* sdcMan, PowerSwitchIF* pwrSwitcher, power::Switch_t switchCh0, SdCardMountedIF* sdcMan, Stack5VHandler& stackHandler, bool periodicPrintout);
power::Switch_t switchCh1, bool periodicPrintout);
void setToGoToNormalModeImmediately(bool enable); void setToGoToNormalModeImmediately(bool enable);
void enablePeriodicPrintout(bool enable, uint8_t divider); void enablePeriodicPrintout(bool enable, uint8_t divider);
@ -78,7 +78,9 @@ class PayloadPcduHandler : public DeviceHandlerBase {
private: private:
enum class States : uint8_t { enum class States : uint8_t {
PL_PCDU_OFF, PL_PCDU_OFF,
POWER_CHANNELS_ON, STACK_5V_SWITCHING,
STACK_5V_PENDING,
STACK_5V_CORRECT,
// Solid State Relay, enable battery voltages VBAT0 and VBAT1. This will also switch on // Solid State Relay, enable battery voltages VBAT0 and VBAT1. This will also switch on
// the ADC // the ADC
ON_TRANS_SSR, ON_TRANS_SSR,
@ -108,6 +110,7 @@ class PayloadPcduHandler : public DeviceHandlerBase {
bool goToNormalMode = false; bool goToNormalMode = false;
plpcdu::PlPcduAdcSet adcSet; plpcdu::PlPcduAdcSet adcSet;
Stack5VHandler& stackHandler;
std::array<uint8_t, plpcdu::MAX_ADC_REPLY_SIZE> cmdBuf = {}; std::array<uint8_t, plpcdu::MAX_ADC_REPLY_SIZE> cmdBuf = {};
// This variable is tied to DRO +6 V voltage. Voltages, currents are monitored and the experiment // This variable is tied to DRO +6 V voltage. Voltages, currents are monitored and the experiment
// is shut down immediately if there is a negative voltage. // is shut down immediately if there is a negative voltage.
@ -140,7 +143,6 @@ class PayloadPcduHandler : public DeviceHandlerBase {
PoolEntry<float> processedValues = PoolEntry<float> processedValues =
PoolEntry<float>({0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0}); PoolEntry<float>({0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0});
PoolEntry<float> tempC = PoolEntry<float>({0.0}); PoolEntry<float> tempC = PoolEntry<float>({0.0});
DualLanePowerStateMachine pwrStateMachine;
void updateSwitchGpio(gpioId_t id, gpio::Levels level); void updateSwitchGpio(gpioId_t id, gpio::Levels level);

View File

@ -7,8 +7,11 @@
RadiationSensorHandler::RadiationSensorHandler(object_id_t objectId, object_id_t comIF, RadiationSensorHandler::RadiationSensorHandler(object_id_t objectId, object_id_t comIF,
CookieIF *comCookie, GpioIF *gpioIF, CookieIF *comCookie, GpioIF *gpioIF,
Stack5VHandler &handler) Stack5VHandler &stackHandler)
: DeviceHandlerBase(objectId, comIF, comCookie), dataset(this), gpioIF(gpioIF) { : DeviceHandlerBase(objectId, comIF, comCookie),
dataset(this),
gpioIF(gpioIF),
stackHandler(stackHandler) {
if (comCookie == nullptr) { if (comCookie == nullptr) {
sif::error << "RadiationSensorHandler: Invalid com cookie" << std::endl; sif::error << "RadiationSensorHandler: Invalid com cookie" << std::endl;
} }
@ -17,18 +20,35 @@ RadiationSensorHandler::RadiationSensorHandler(object_id_t objectId, object_id_t
RadiationSensorHandler::~RadiationSensorHandler() {} RadiationSensorHandler::~RadiationSensorHandler() {}
void RadiationSensorHandler::doStartUp() { void RadiationSensorHandler::doStartUp() {
if (internalState == InternalState::OFF) {
ReturnValue_t retval = stackHandler.deviceToOn(StackCommander::RAD_SENSOR);
if (retval == BUSY) {
return;
}
internalState = InternalState::POWER_SWITCHING;
}
if (internalState == InternalState::POWER_SWITCHING) {
if (stackHandler.isSwitchOn()) {
internalState == InternalState::SETUP;
}
}
if (internalState == InternalState::CONFIGURED) { if (internalState == InternalState::CONFIGURED) {
if (goToNormalMode) { if (goToNormalMode) {
setMode(MODE_NORMAL); setMode(MODE_NORMAL);
} } else {
else {
setMode(_MODE_TO_ON); setMode(_MODE_TO_ON);
} }
} }
} }
void RadiationSensorHandler::doShutDown() { setMode(_MODE_POWER_DOWN); } void RadiationSensorHandler::doShutDown() {
ReturnValue_t retval = stackHandler.deviceToOff(StackCommander::RAD_SENSOR);
if (retval == BUSY) {
return;
}
internalState = InternalState::OFF;
setMode(_MODE_POWER_DOWN);
}
ReturnValue_t RadiationSensorHandler::buildNormalDeviceCommand(DeviceCommandId_t *id) { ReturnValue_t RadiationSensorHandler::buildNormalDeviceCommand(DeviceCommandId_t *id) {
switch (communicationStep) { switch (communicationStep) {

View File

@ -40,16 +40,17 @@ class RadiationSensorHandler : public DeviceHandlerBase {
private: private:
enum class CommunicationStep { START_CONVERSION, READ_CONVERSIONS }; enum class CommunicationStep { START_CONVERSION, READ_CONVERSIONS };
enum class InternalState { SETUP, CONFIGURED }; enum class InternalState { OFF, POWER_SWITCHING, SETUP, CONFIGURED };
bool printPeriodicData = false; bool printPeriodicData = false;
RAD_SENSOR::RadSensorDataset dataset; RAD_SENSOR::RadSensorDataset dataset;
static const uint8_t MAX_CMD_LEN = RAD_SENSOR::READ_SIZE; static const uint8_t MAX_CMD_LEN = RAD_SENSOR::READ_SIZE;
GpioIF *gpioIF = nullptr; GpioIF *gpioIF = nullptr;
Stack5VHandler &stackHandler;
bool goToNormalMode = false; bool goToNormalMode = false;
uint8_t cmdBuffer[MAX_CMD_LEN]; uint8_t cmdBuffer[MAX_CMD_LEN];
InternalState internalState = InternalState::SETUP; InternalState internalState = InternalState::OFF;
CommunicationStep communicationStep = CommunicationStep::START_CONVERSION; CommunicationStep communicationStep = CommunicationStep::START_CONVERSION;
}; };

View File

@ -713,7 +713,7 @@ class AuxHk : public StaticLocalDataSet<12> {
namespace pcdu { namespace pcdu {
enum PoolIds : uint32_t { PDU1_SWITCHES, PDU2_SWITCHES }; enum PoolIds : uint32_t { PDU1_SWITCHES, PDU2_SWITCHES, P60DOCK_SWITCHES };
/* Switches are uint8_t datatype and go from 0 to 255 */ /* Switches are uint8_t datatype and go from 0 to 255 */
enum Switches : power::Switch_t { enum Switches : power::Switch_t {
@ -771,6 +771,7 @@ class SwitcherStates : public StaticLocalDataSet<NUMBER_OF_SWITCHES> {
lp_vec_t<uint8_t, PDU::CHANNELS_LEN>(sid.objectId, PDU1_SWITCHES, this); lp_vec_t<uint8_t, PDU::CHANNELS_LEN>(sid.objectId, PDU1_SWITCHES, this);
lp_vec_t<uint8_t, PDU::CHANNELS_LEN> pdu2Switches = lp_vec_t<uint8_t, PDU::CHANNELS_LEN> pdu2Switches =
lp_vec_t<uint8_t, PDU::CHANNELS_LEN>(sid.objectId, PDU2_SWITCHES, this); lp_vec_t<uint8_t, PDU::CHANNELS_LEN>(sid.objectId, PDU2_SWITCHES, this);
lp_var_t<uint8_t> p60Dock5VStack = lp_var_t<uint8_t>(sid.objectId, P60DOCK_SWITCHES, this);
}; };
} // namespace pcdu } // namespace pcdu

View File

@ -6,27 +6,39 @@ Stack5VHandler::Stack5VHandler(PowerSwitchIF& switcher) : switcher(switcher) {
ReturnValue_t Stack5VHandler::deviceToOn(StackCommander commander) { ReturnValue_t Stack5VHandler::deviceToOn(StackCommander commander) {
MutexGuard mg(stackLock); MutexGuard mg(stackLock);
if (switchIsOn or handlerState == HandlerState::SWITCH_PENDING) { if (switchIsOn) {
if (commander == StackCommander::PL_PCDU) {
plPcduIsOn = true;
} else {
radSensorIsOn = true;
}
return returnvalue::OK; return returnvalue::OK;
} }
if (commander == StackCommander::PL_PCDU) { if (handlerState == HandlerState::SWITCH_PENDING) {
plPcduCommandedOn = true; return BUSY;
} else if (commander == StackCommander::RAD_SENSOR) {
radSensorCommandedOn = true;
} }
handlerState == HandlerState::SWITCH_PENDING;
return switcher.sendSwitchCommand(stackSwitch, PowerSwitchIF::SWITCH_ON); return switcher.sendSwitchCommand(stackSwitch, PowerSwitchIF::SWITCH_ON);
} }
ReturnValue_t Stack5VHandler::deviceToOff(StackCommander commander) { ReturnValue_t Stack5VHandler::deviceToOff(StackCommander commander) {
MutexGuard mg(stackLock); MutexGuard mg(stackLock);
if (not switchIsOn) { if (not switchIsOn) {
if (commander == StackCommander::PL_PCDU) {
plPcduIsOn = false;
} else {
radSensorIsOn = false;
}
return returnvalue::OK; return returnvalue::OK;
} }
if (commander == StackCommander::PL_PCDU) { if (handlerState == HandlerState::SWITCH_PENDING) {
plPcduCommandedOn = true; return BUSY;
} else if (commander == StackCommander::RAD_SENSOR) {
radSensorCommandedOn = true;
} }
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); return switcher.sendSwitchCommand(stackSwitch, PowerSwitchIF::SWITCH_OFF);
} }
@ -39,12 +51,6 @@ bool Stack5VHandler::isSwitchOn() {
} }
switchIsOn = true; switchIsOn = true;
} }
if (plPcduCommandedOn) {
plPcduIsOn = true;
}
if (radSensorCommandedOn) {
radSensorIsOn = true;
}
return true; return true;
} else { } else {
if (switchIsOn) { if (switchIsOn) {
@ -55,8 +61,6 @@ bool Stack5VHandler::isSwitchOn() {
} }
radSensorIsOn = false; radSensorIsOn = false;
plPcduIsOn = false; plPcduIsOn = false;
radSensorCommandedOn = false;
plPcduCommandedOn = false;
} }
return false; return false;
} }

View File

@ -10,6 +10,7 @@ enum class HandlerState { SWITCH_PENDING, IDLE };
class Stack5VHandler { class Stack5VHandler {
public: public:
static constexpr ReturnValue_t BUSY = returnvalue::makeCode(1, 0);
Stack5VHandler(PowerSwitchIF& switcher); Stack5VHandler(PowerSwitchIF& switcher);
ReturnValue_t deviceToOn(StackCommander commander); ReturnValue_t deviceToOn(StackCommander commander);
@ -22,8 +23,6 @@ class Stack5VHandler {
PowerSwitchIF& switcher; PowerSwitchIF& switcher;
bool switchIsOn = false; bool switchIsOn = false;
HandlerState handlerState = HandlerState::IDLE; HandlerState handlerState = HandlerState::IDLE;
bool plPcduCommandedOn = false;
bool radSensorCommandedOn = false;
bool radSensorIsOn = false; bool radSensorIsOn = false;
bool plPcduIsOn = false; bool plPcduIsOn = false;
pcdu::Switches stackSwitch = pcdu::Switches::P60_DOCK_5V_STACK; pcdu::Switches stackSwitch = pcdu::Switches::P60_DOCK_5V_STACK;