diff --git a/bsp_q7s/core/ObjectFactory.cpp b/bsp_q7s/core/ObjectFactory.cpp index cdf95aa2..c0ccb036 100644 --- a/bsp_q7s/core/ObjectFactory.cpp +++ b/bsp_q7s/core/ObjectFactory.cpp @@ -83,8 +83,8 @@ #include "mission/devices/devicedefinitions/RwDefinitions.h" #include "mission/devices/devicedefinitions/SusDefinitions.h" #include "mission/devices/devicedefinitions/SyrlinksDefinitions.h" -#include "mission/system/AcsBoardAssembly.h" #include "mission/devices/devicedefinitions/payloadPcduDefinitions.h" +#include "mission/system/AcsBoardAssembly.h" #include "mission/tmtc/CCSDSHandler.h" #include "mission/tmtc/VirtualChannel.h" #include "mission/utility/TmFunnel.h" diff --git a/common/config/devices/powerSwitcherList.h b/common/config/devices/powerSwitcherList.h index a9a75ce4..f99e0930 100644 --- a/common/config/devices/powerSwitcherList.h +++ b/common/config/devices/powerSwitcherList.h @@ -3,6 +3,7 @@ #include "OBSWConfig.h" +#include #include namespace pcduSwitches { @@ -33,32 +34,36 @@ enum Switches: uint8_t { static const uint8_t ON = 1; static const uint8_t OFF = 0; -/* Output states after reboot of the PDUs */ +// Output states after reboot of the PDUs + +const std::array INIT_SWITCH_STATES = { + // PDU 1 +// Because the TE0720 is not connected to the PCDU, this switch is always on #if BOARD_TE0720 == 1 -/* Because the TE0720 is not connected to the PCDU, this switch is always on */ -static const uint8_t INIT_STATE_TCS_BOARD_8V_HEATER_IN = ON; + ON, #else -static const uint8_t INIT_STATE_TCS_BOARD_8V_HEATER_IN = OFF; + OFF, #endif -static const uint8_t INIT_STATE_SYRLINKS = OFF; -static const uint8_t INIT_STATE_STAR_TRACKER = OFF; -static const uint8_t INIT_STATE_MGT = OFF; -static const uint8_t INIT_STATE_SUS_NOMINAL = OFF; -static const uint8_t INIT_STATE_SOLAR_CELL_EXP = OFF; -static const uint8_t INIT_STATE_PLOC = OFF; -static const uint8_t INIT_STATE_ACS_BOARD_SIDE_A = OFF; - -static const uint8_t INIT_STATE_Q7S = ON; -static const uint8_t INIT_STATE_PAYLOAD_PCDU_CH1 = OFF; -static const uint8_t INIT_STATE_RW = OFF; -static const uint8_t INIT_STATE_SUS_REDUNDANT = OFF; -static const uint8_t INIT_STATE_DEPLOYMENT_MECHANISM = OFF; -static const uint8_t INIT_STATE_PAYLOAD_PCDU_CH6 = OFF; -static const uint8_t INIT_STATE_ACS_BOARD_SIDE_B = OFF; -static const uint8_t INIT_STATE_PAYLOAD_CAMERA = OFF; -static const uint8_t INIT_STATE_TCS_BOARD_3V3 = OFF; + OFF, + OFF, + OFF, + OFF, + OFF, + OFF, + OFF, + OFF, + // PDU 2 + ON, + OFF, + OFF, + OFF, + OFF, + OFF, + OFF, + OFF, + OFF +}; } - #endif /* FSFWCONFIG_DEVICES_POWERSWITCHERLIST_H_ */ diff --git a/mission/devices/PCDUHandler.cpp b/mission/devices/PCDUHandler.cpp index cd07e1d9..b9a1721e 100644 --- a/mission/devices/PCDUHandler.cpp +++ b/mission/devices/PCDUHandler.cpp @@ -77,25 +77,9 @@ ReturnValue_t PCDUHandler::initialize() { void PCDUHandler::initializeSwitchStates() { using namespace pcduSwitches; - switchStates[Switches::PDU2_CH0_Q7S] = pcduSwitches::INIT_STATE_Q7S; - switchStates[Switches::PDU2_CH6_PL_PCDU_BATT_1_14V8] = pcduSwitches::INIT_STATE_PAYLOAD_PCDU_CH1; - switchStates[Switches::PDU2_CH2_RW_5V] = pcduSwitches::INIT_STATE_RW; - switchStates[Switches::PDU2_CH3_TCS_BOARD_HEATER_IN_8V] = - pcduSwitches::INIT_STATE_TCS_BOARD_8V_HEATER_IN; - switchStates[Switches::PDU2_CH4_SUS_REDUNDANT_3V3] = pcduSwitches::INIT_STATE_SUS_REDUNDANT; - switchStates[Switches::PDU2_CH5_DEPLOYMENT_MECHANISM_8V] = - pcduSwitches::INIT_STATE_DEPLOYMENT_MECHANISM; - switchStates[Switches::PDU2_CH6_PL_PCDU_BATT_1_14V8] = pcduSwitches::INIT_STATE_PAYLOAD_PCDU_CH6; - switchStates[Switches::PDU2_CH7_ACS_BOARD_SIDE_B_3V3] = pcduSwitches::INIT_STATE_ACS_BOARD_SIDE_B; - switchStates[Switches::PDU2_CH8_PAYLOAD_CAMERA] = pcduSwitches::INIT_STATE_PAYLOAD_CAMERA; - switchStates[Switches::PDU1_CH0_TCS_BOARD_3V3] = pcduSwitches::INIT_STATE_TCS_BOARD_3V3; - switchStates[Switches::PDU1_CH1_SYRLINKS_12V] = pcduSwitches::INIT_STATE_SYRLINKS; - switchStates[Switches::PDU1_CH2_STAR_TRACKER_5V] = pcduSwitches::INIT_STATE_STAR_TRACKER; - switchStates[Switches::PDU1_CH3_MGT_5V] = pcduSwitches::INIT_STATE_MGT; - switchStates[Switches::PDU1_CH4_SUS_NOMINAL_3V3] = pcduSwitches::INIT_STATE_SUS_NOMINAL; - switchStates[Switches::PDU1_CH5_SOLAR_CELL_EXP_5V] = pcduSwitches::INIT_STATE_SOLAR_CELL_EXP; - switchStates[Switches::PDU1_CH6_PLOC_12V] = pcduSwitches::INIT_STATE_PLOC; - switchStates[Switches::PDU1_CH7_ACS_A_SIDE_3V3] = pcduSwitches::INIT_STATE_ACS_BOARD_SIDE_A; + for (uint8_t idx = 0; idx < Switches::NUMBER_OF_SWITCHES; idx++) { + switchStates[idx] = INIT_SWITCH_STATES[idx]; + } } void PCDUHandler::readCommandQueue() { @@ -178,6 +162,9 @@ void PCDUHandler::updatePdu2SwitchStates() { pdu2HkTableDataset.outEnabledAcsBoardSideB.value); checkAndUpdateSwitch(Switches::PDU2_CH8_PAYLOAD_CAMERA, pdu2HkTableDataset.outEnabledPayloadCamera.value); + if (firstSwitchInfo) { + firstSwitchInfo = false; + } } else { sif::debug << "PCDUHandler::updatePdu2SwitchStates: Failed to read PDU2 Hk Dataset" << std::endl; @@ -205,6 +192,9 @@ void PCDUHandler::updatePdu1SwitchStates() { pdu1HkTableDataset.outEnabledAcsBoardSideA.value); checkAndUpdateSwitch(Switches::PDU1_CH8_UNOCCUPIED, pdu1HkTableDataset.outEnabledChannel8.value); + if (firstSwitchInfo) { + firstSwitchInfo = false; + } } else { sif::debug << "PCDUHandler::updatePdu1SwitchStates: Failed to read dataset" << std::endl; } @@ -381,6 +371,7 @@ object_id_t PCDUHandler::getObjectId() const { return SystemObject::getObjectId( ReturnValue_t PCDUHandler::initializeLocalDataPool(localpool::DataPool& localDataPoolMap, LocalDataPoolManager& poolManager) { + using namespace pcduSwitches; localDataPoolMap.emplace(P60System::PDU2_CURRENT_OUT_Q7S, new PoolEntry({0})); localDataPoolMap.emplace(P60System::PDU2_CURRENT_OUT_PAYLOAD_PCDU_CH1, new PoolEntry({0})); @@ -419,28 +410,34 @@ ReturnValue_t PCDUHandler::initializeLocalDataPool(localpool::DataPool& localDat localDataPoolMap.emplace(P60System::PDU2_CONV_EN_3, new PoolEntry({0})); localDataPoolMap.emplace(P60System::PDU2_OUT_EN_Q7S, - new PoolEntry({pcduSwitches::INIT_STATE_Q7S})); - localDataPoolMap.emplace(P60System::PDU2_OUT_EN_PAYLOAD_PCDU_CH1, - new PoolEntry({pcduSwitches::INIT_STATE_PAYLOAD_PCDU_CH1})); + new PoolEntry({INIT_SWITCH_STATES[Switches::PDU2_CH0_Q7S]})); + localDataPoolMap.emplace( + P60System::PDU2_OUT_EN_PAYLOAD_PCDU_CH1, + new PoolEntry({INIT_SWITCH_STATES[Switches::PDU2_CH1_PL_PCDU_BATT_0_14V8]})); localDataPoolMap.emplace(P60System::PDU2_OUT_EN_RW, - new PoolEntry({pcduSwitches::INIT_STATE_RW})); + new PoolEntry({INIT_SWITCH_STATES[Switches::PDU2_CH2_RW_5V]})); #if BOARD_TE0720 == 1 localDataPoolMap.emplace(P60System::PDU2_OUT_EN_TCS_BOARD_HEATER_IN, new PoolEntry({1})); #else localDataPoolMap.emplace( P60System::PDU2_OUT_EN_TCS_BOARD_HEATER_IN, - new PoolEntry({pcduSwitches::INIT_STATE_TCS_BOARD_8V_HEATER_IN})); + new PoolEntry({INIT_SWITCH_STATES[Switches::PDU2_CH3_TCS_BOARD_HEATER_IN_8V]})); #endif - localDataPoolMap.emplace(P60System::PDU2_OUT_EN_SUS_REDUNDANT, - new PoolEntry({pcduSwitches::INIT_STATE_SUS_REDUNDANT})); - localDataPoolMap.emplace(P60System::PDU2_OUT_EN_DEPLOYMENT_MECHANISM, - new PoolEntry({pcduSwitches::INIT_STATE_DEPLOYMENT_MECHANISM})); - localDataPoolMap.emplace(P60System::PDU2_OUT_EN_PAYLOAD_PCDU_CH6, - new PoolEntry({pcduSwitches::INIT_STATE_PAYLOAD_PCDU_CH6})); - localDataPoolMap.emplace(P60System::PDU2_OUT_EN_ACS_BOARD_SIDE_B, - new PoolEntry({pcduSwitches::INIT_STATE_ACS_BOARD_SIDE_B})); - localDataPoolMap.emplace(P60System::PDU2_OUT_EN_PAYLOAD_CAMERA, - new PoolEntry({pcduSwitches::INIT_STATE_PAYLOAD_CAMERA})); + localDataPoolMap.emplace( + P60System::PDU2_OUT_EN_SUS_REDUNDANT, + new PoolEntry({INIT_SWITCH_STATES[Switches::PDU2_CH4_SUS_REDUNDANT_3V3]})); + localDataPoolMap.emplace( + P60System::PDU2_OUT_EN_DEPLOYMENT_MECHANISM, + new PoolEntry({INIT_SWITCH_STATES[Switches::PDU2_CH5_DEPLOYMENT_MECHANISM_8V]})); + localDataPoolMap.emplace( + P60System::PDU2_OUT_EN_PAYLOAD_PCDU_CH6, + new PoolEntry({INIT_SWITCH_STATES[Switches::PDU2_CH6_PL_PCDU_BATT_1_14V8]})); + localDataPoolMap.emplace( + P60System::PDU2_OUT_EN_ACS_BOARD_SIDE_B, + new PoolEntry({INIT_SWITCH_STATES[Switches::PDU2_CH7_ACS_BOARD_SIDE_B_3V3]})); + localDataPoolMap.emplace( + P60System::PDU2_OUT_EN_PAYLOAD_CAMERA, + new PoolEntry({INIT_SWITCH_STATES[Switches::PDU2_CH8_PAYLOAD_CAMERA]})); localDataPoolMap.emplace(P60System::PDU2_BOOTCAUSE, new PoolEntry({0})); localDataPoolMap.emplace(P60System::PDU2_BOOTCNT, new PoolEntry({0})); @@ -502,16 +499,32 @@ ReturnValue_t PCDUHandler::initializeLocalDataPool(localpool::DataPool& localDat new PoolEntry({0})); localDataPoolMap.emplace(P60System::PDU1_CURRENT_OUT_CHANNEL8, new PoolEntry({0})); - localDataPoolMap.emplace(P60System::PDU1_VOLTAGE_OUT_TCS_BOARD_3V3, new PoolEntry({0})); - localDataPoolMap.emplace(P60System::PDU1_VOLTAGE_OUT_SYRLINKS, new PoolEntry({0})); - localDataPoolMap.emplace(P60System::PDU1_VOLTAGE_OUT_STAR_TRACKER, new PoolEntry({0})); - localDataPoolMap.emplace(P60System::PDU1_VOLTAGE_OUT_MGT, new PoolEntry({0})); - localDataPoolMap.emplace(P60System::PDU1_VOLTAGE_OUT_SUS_NOMINAL, new PoolEntry({0})); - localDataPoolMap.emplace(P60System::PDU1_VOLTAGE_OUT_SOLAR_CELL_EXP, new PoolEntry({0})); - localDataPoolMap.emplace(P60System::PDU1_VOLTAGE_OUT_PLOC, new PoolEntry({0})); - localDataPoolMap.emplace(P60System::PDU1_VOLTAGE_OUT_ACS_BOARD_SIDE_A, - new PoolEntry({0})); - localDataPoolMap.emplace(P60System::PDU1_VOLTAGE_OUT_CHANNEL8, new PoolEntry({0})); + localDataPoolMap.emplace( + P60System::PDU1_VOLTAGE_OUT_TCS_BOARD_3V3, + new PoolEntry({INIT_SWITCH_STATES[Switches::PDU1_CH0_TCS_BOARD_3V3]})); + localDataPoolMap.emplace( + P60System::PDU1_VOLTAGE_OUT_SYRLINKS, + new PoolEntry({INIT_SWITCH_STATES[Switches::PDU1_CH1_SYRLINKS_12V]})); + localDataPoolMap.emplace( + P60System::PDU1_VOLTAGE_OUT_STAR_TRACKER, + new PoolEntry({INIT_SWITCH_STATES[Switches::PDU1_CH2_STAR_TRACKER_5V]})); + localDataPoolMap.emplace(P60System::PDU1_VOLTAGE_OUT_MGT, + new PoolEntry({INIT_SWITCH_STATES[Switches::PDU1_CH3_MGT_5V]})); + localDataPoolMap.emplace( + P60System::PDU1_VOLTAGE_OUT_SUS_NOMINAL, + new PoolEntry({INIT_SWITCH_STATES[Switches::PDU1_CH4_SUS_NOMINAL_3V3]})); + localDataPoolMap.emplace( + P60System::PDU1_VOLTAGE_OUT_SOLAR_CELL_EXP, + new PoolEntry({INIT_SWITCH_STATES[Switches::PDU1_CH5_SOLAR_CELL_EXP_5V]})); + localDataPoolMap.emplace( + P60System::PDU1_VOLTAGE_OUT_PLOC, + new PoolEntry({INIT_SWITCH_STATES[Switches::PDU1_CH6_PLOC_12V]})); + localDataPoolMap.emplace( + P60System::PDU1_VOLTAGE_OUT_ACS_BOARD_SIDE_A, + new PoolEntry({INIT_SWITCH_STATES[Switches::PDU1_CH7_ACS_A_SIDE_3V3]})); + localDataPoolMap.emplace( + P60System::PDU1_VOLTAGE_OUT_CHANNEL8, + new PoolEntry({INIT_SWITCH_STATES[Switches::PDU1_CH8_UNOCCUPIED]})); localDataPoolMap.emplace(P60System::PDU1_VCC, new PoolEntry({0})); localDataPoolMap.emplace(P60System::PDU1_VBAT, new PoolEntry({0})); @@ -603,8 +616,17 @@ LocalPoolDataSetBase* PCDUHandler::getDataSetHandle(sid_t sid) { } void PCDUHandler::checkAndUpdateSwitch(pcduSwitches::Switches switchIdx, uint8_t setValue) { + using namespace pcduSwitches; if (switchStates[switchIdx] != setValue) { - triggerEvent(power::SWITCH_HAS_CHANGED, setValue, switchIdx); + if (firstSwitchInfo) { + ReturnValue_t state = PowerSwitchIF::SWITCH_OFF; + if (INIT_SWITCH_STATES[switchIdx] == ON) { + state = PowerSwitchIF::SWITCH_ON; + } + sendSwitchCommand(switchIdx, state); + } else { + triggerEvent(power::SWITCH_HAS_CHANGED, setValue, switchIdx); + } } switchStates[switchIdx] = setValue; } diff --git a/mission/devices/PCDUHandler.h b/mission/devices/PCDUHandler.h index e9649041..cd74a593 100644 --- a/mission/devices/PCDUHandler.h +++ b/mission/devices/PCDUHandler.h @@ -84,6 +84,7 @@ class PCDUHandler : public PowerSwitchIF, MessageQueueIF* commandQueue = nullptr; size_t cmdQueueSize; + bool firstSwitchInfo = true; PeriodicTaskIF* executingTask = nullptr; diff --git a/mission/devices/devicedefinitions/powerDefinitions.h b/mission/devices/devicedefinitions/powerDefinitions.h index c5e40f12..746bda34 100644 --- a/mission/devices/devicedefinitions/powerDefinitions.h +++ b/mission/devices/devicedefinitions/powerDefinitions.h @@ -7,9 +7,11 @@ namespace power { static constexpr uint8_t SUBSYSTEM_ID = SUBSYSTEM_ID::PCDU_HANDLER; -//! [EXPORT] : [COMMENT] Indicated that a FSFW object requested setting a switch +//! [EXPORT] : [COMMENT] Indicates that a FSFW object requested setting a switch //! P1: 1 if on was requested, 0 for off | P2: Switch Index static constexpr Event SWITCH_CMD_SENT = event::makeEvent(SUBSYSTEM_ID, 0, severity::INFO); +//! [EXPORT] : [COMMENT] Indicated that a swithc state has changed +//! P1: New switch state, 1 for on, 0 for off | P2: Switch Index static constexpr Event SWITCH_HAS_CHANGED = event::makeEvent(SUBSYSTEM_ID, 1, severity::INFO); static constexpr Event SWITCHING_Q7S_DENIED = event::makeEvent(SUBSYSTEM_ID, 2, severity::MEDIUM); diff --git a/mission/system/AcsBoardAssembly.cpp b/mission/system/AcsBoardAssembly.cpp index 39162129..46add801 100644 --- a/mission/system/AcsBoardAssembly.cpp +++ b/mission/system/AcsBoardAssembly.cpp @@ -150,12 +150,13 @@ ReturnValue_t AcsBoardAssembly::handleNormalOrOnModeCmd(Mode_t mode, Submode_t s auto cmdSeq = [&](object_id_t objectId, Mode_t devMode, ModeTableIdx tableIdx) { if (mode == DeviceHandlerIF::MODE_NORMAL) { if (isUseable(objectId, devMode)) { - if (devMode == MODE_OFF or devMode == HasModesIF::UNDEFINED_MODE) { - modeTable[tableIdx].setMode(MODE_ON); - modeTable[tableIdx].setSubmode(SUBMODE_NONE); - } else { + if (devMode == MODE_ON) { modeTable[tableIdx].setMode(mode); modeTable[tableIdx].setSubmode(SUBMODE_NONE); + + } else { + modeTable[tableIdx].setMode(MODE_ON); + modeTable[tableIdx].setSubmode(SUBMODE_NONE); } } } else if (mode == MODE_ON) {