diff --git a/mission/devices/PCDUHandler.cpp b/mission/devices/PCDUHandler.cpp index b9a1721e..11c84118 100644 --- a/mission/devices/PCDUHandler.cpp +++ b/mission/devices/PCDUHandler.cpp @@ -141,29 +141,30 @@ void PCDUHandler::updateHkTableDataset(store_address_t storeId, LocalPoolDataSet void PCDUHandler::updatePdu2SwitchStates() { using namespace pcduSwitches; + GOMSPACE::Pdu pdu = GOMSPACE::Pdu::PDU2; PoolReadGuard rg(&pdu2HkTableDataset); if (rg.getReadResult() == RETURN_OK) { MutexGuard mg(pwrMutex); - checkAndUpdateSwitch(Switches::PDU2_CH0_Q7S, pdu2HkTableDataset.outEnabledQ7S.value); + checkAndUpdateSwitch(pdu, Switches::PDU2_CH0_Q7S, pdu2HkTableDataset.outEnabledQ7S.value); - checkAndUpdateSwitch(Switches::PDU2_CH1_PL_PCDU_BATT_0_14V8, + checkAndUpdateSwitch(pdu, Switches::PDU2_CH1_PL_PCDU_BATT_0_14V8, pdu2HkTableDataset.outEnabledPlPCDUCh1.value); - checkAndUpdateSwitch(Switches::PDU2_CH2_RW_5V, + checkAndUpdateSwitch(pdu, Switches::PDU2_CH2_RW_5V, pdu2HkTableDataset.outEnabledReactionWheels.value); - checkAndUpdateSwitch(Switches::PDU2_CH3_TCS_BOARD_HEATER_IN_8V, + checkAndUpdateSwitch(pdu, Switches::PDU2_CH3_TCS_BOARD_HEATER_IN_8V, pdu2HkTableDataset.outEnabledTCSBoardHeaterIn.value); - checkAndUpdateSwitch(Switches::PDU2_CH4_SUS_REDUNDANT_3V3, + checkAndUpdateSwitch(pdu, Switches::PDU2_CH4_SUS_REDUNDANT_3V3, pdu2HkTableDataset.outEnabledSUSRedundant.value); - checkAndUpdateSwitch(Switches::PDU2_CH5_DEPLOYMENT_MECHANISM_8V, + checkAndUpdateSwitch(pdu, Switches::PDU2_CH5_DEPLOYMENT_MECHANISM_8V, pdu2HkTableDataset.outEnabledDeplMechanism.value); - checkAndUpdateSwitch(Switches::PDU2_CH6_PL_PCDU_BATT_1_14V8, + checkAndUpdateSwitch(pdu, Switches::PDU2_CH6_PL_PCDU_BATT_1_14V8, pdu2HkTableDataset.outEnabledPlPCDUCh6.value); - checkAndUpdateSwitch(Switches::PDU2_CH7_ACS_BOARD_SIDE_B_3V3, + checkAndUpdateSwitch(pdu, Switches::PDU2_CH7_ACS_BOARD_SIDE_B_3V3, pdu2HkTableDataset.outEnabledAcsBoardSideB.value); - checkAndUpdateSwitch(Switches::PDU2_CH8_PAYLOAD_CAMERA, + checkAndUpdateSwitch(pdu, Switches::PDU2_CH8_PAYLOAD_CAMERA, pdu2HkTableDataset.outEnabledPayloadCamera.value); - if (firstSwitchInfo) { - firstSwitchInfo = false; + if (firstSwitchInfoPdu2) { + firstSwitchInfoPdu2 = false; } } else { sif::debug << "PCDUHandler::updatePdu2SwitchStates: Failed to read PDU2 Hk Dataset" @@ -174,26 +175,27 @@ void PCDUHandler::updatePdu2SwitchStates() { void PCDUHandler::updatePdu1SwitchStates() { using namespace pcduSwitches; PoolReadGuard rg(&pdu1HkTableDataset); + GOMSPACE::Pdu pdu = GOMSPACE::Pdu::PDU1; if (rg.getReadResult() == RETURN_OK) { MutexGuard mg(pwrMutex); - checkAndUpdateSwitch(Switches::PDU1_CH0_TCS_BOARD_3V3, + checkAndUpdateSwitch(pdu, Switches::PDU1_CH0_TCS_BOARD_3V3, pdu1HkTableDataset.outEnabledTCSBoard3V3.value); - checkAndUpdateSwitch(Switches::PDU1_CH1_SYRLINKS_12V, + checkAndUpdateSwitch(pdu, Switches::PDU1_CH1_SYRLINKS_12V, pdu1HkTableDataset.outEnabledSyrlinks.value); - checkAndUpdateSwitch(Switches::PDU1_CH2_STAR_TRACKER_5V, + checkAndUpdateSwitch(pdu, Switches::PDU1_CH2_STAR_TRACKER_5V, pdu1HkTableDataset.outEnabledStarTracker.value); - checkAndUpdateSwitch(Switches::PDU1_CH3_MGT_5V, pdu1HkTableDataset.outEnabledMGT.value); - checkAndUpdateSwitch(Switches::PDU1_CH4_SUS_NOMINAL_3V3, + checkAndUpdateSwitch(pdu, Switches::PDU1_CH3_MGT_5V, pdu1HkTableDataset.outEnabledMGT.value); + checkAndUpdateSwitch(pdu, Switches::PDU1_CH4_SUS_NOMINAL_3V3, pdu1HkTableDataset.outEnabledSUSNominal.value); - checkAndUpdateSwitch(Switches::PDU1_CH5_SOLAR_CELL_EXP_5V, + checkAndUpdateSwitch(pdu, Switches::PDU1_CH5_SOLAR_CELL_EXP_5V, pdu1HkTableDataset.outEnabledSolarCellExp.value); - checkAndUpdateSwitch(Switches::PDU1_CH6_PLOC_12V, pdu1HkTableDataset.outEnabledPLOC.value); - checkAndUpdateSwitch(Switches::PDU1_CH7_ACS_A_SIDE_3V3, + checkAndUpdateSwitch(pdu, Switches::PDU1_CH6_PLOC_12V, pdu1HkTableDataset.outEnabledPLOC.value); + checkAndUpdateSwitch(pdu, Switches::PDU1_CH7_ACS_A_SIDE_3V3, pdu1HkTableDataset.outEnabledAcsBoardSideA.value); - checkAndUpdateSwitch(Switches::PDU1_CH8_UNOCCUPIED, + checkAndUpdateSwitch(pdu, Switches::PDU1_CH8_UNOCCUPIED, pdu1HkTableDataset.outEnabledChannel8.value); - if (firstSwitchInfo) { - firstSwitchInfo = false; + if (firstSwitchInfoPdu1) { + firstSwitchInfoPdu1 = false; } } else { sif::debug << "PCDUHandler::updatePdu1SwitchStates: Failed to read dataset" << std::endl; @@ -615,10 +617,14 @@ LocalPoolDataSetBase* PCDUHandler::getDataSetHandle(sid_t sid) { } } -void PCDUHandler::checkAndUpdateSwitch(pcduSwitches::Switches switchIdx, uint8_t setValue) { +void PCDUHandler::checkAndUpdateSwitch(GOMSPACE::Pdu pdu, pcduSwitches::Switches switchIdx, + uint8_t setValue) { using namespace pcduSwitches; if (switchStates[switchIdx] != setValue) { - if (firstSwitchInfo) { + // This code initializes the switches to the default init switch states on every reboot. + // This is not done by the PCDU unless it is power-cycled. + if (((pdu == GOMSPACE::Pdu::PDU1) and firstSwitchInfoPdu1) or + ((pdu == GOMSPACE::Pdu::PDU2) and firstSwitchInfoPdu2)) { ReturnValue_t state = PowerSwitchIF::SWITCH_OFF; if (INIT_SWITCH_STATES[switchIdx] == ON) { state = PowerSwitchIF::SWITCH_ON; diff --git a/mission/devices/PCDUHandler.h b/mission/devices/PCDUHandler.h index cd74a593..3d014205 100644 --- a/mission/devices/PCDUHandler.h +++ b/mission/devices/PCDUHandler.h @@ -84,7 +84,8 @@ class PCDUHandler : public PowerSwitchIF, MessageQueueIF* commandQueue = nullptr; size_t cmdQueueSize; - bool firstSwitchInfo = true; + bool firstSwitchInfoPdu1 = true; + bool firstSwitchInfoPdu2 = true; PeriodicTaskIF* executingTask = nullptr; @@ -118,7 +119,7 @@ class PCDUHandler : public PowerSwitchIF, */ void updateHkTableDataset(store_address_t storeId, LocalPoolDataSetBase* dataset, CCSDSTime::CDS_short* datasetTimeStamp); - void checkAndUpdateSwitch(pcduSwitches::Switches switchIdx, uint8_t setValue); + void checkAndUpdateSwitch(GOMSPACE::Pdu pdu, pcduSwitches::Switches switchIdx, uint8_t setValue); }; #endif /* MISSION_DEVICES_PCDUHANDLER_H_ */