From 0bbcfb34e8c6d591ff1eb2ef099a41b69f44b0ca Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Wed, 2 Aug 2023 11:14:35 +0200 Subject: [PATCH 01/11] tweaks for pin handling --- CHANGELOG.md | 1 + mission/payload/PayloadPcduHandler.cpp | 30 ++++++++++++-------------- mission/payload/PayloadPcduHandler.h | 1 + tmtc | 2 +- 4 files changed, 17 insertions(+), 17 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index fe6a2cb3..ae107d14 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -29,6 +29,7 @@ will consitute of a breaking change warranting a new major release: ## Changed - The `EiveSystem` now only sends reboot commands targetting the same image. +- Added 200 ms delay between switching HPA/MPA/TX/X8 and DRO GPIP pin OFF. # [v6.2.0] 2023-07-26 diff --git a/mission/payload/PayloadPcduHandler.cpp b/mission/payload/PayloadPcduHandler.cpp index 9223f454..4f22be87 100644 --- a/mission/payload/PayloadPcduHandler.cpp +++ b/mission/payload/PayloadPcduHandler.cpp @@ -1,4 +1,5 @@ #include +#include #include #include "OBSWConfig.h" @@ -73,14 +74,7 @@ void PayloadPcduHandler::doTransition(Mode_t modeFrom, Submode_t subModeFrom) { stateMachineToNormal(modeFrom, subModeFrom); return; } else if (getMode() == _MODE_TO_ON and modeFrom == MODE_NORMAL) { - gpioIF->pullLow(gpioIds::PLPCDU_ENB_HPA); - gpioIF->pullLow(gpioIds::PLPCDU_ENB_MPA); - gpioIF->pullLow(gpioIds::PLPCDU_ENB_TX); - gpioIF->pullLow(gpioIds::PLPCDU_ENB_X8); - gpioIF->pullLow(gpioIds::PLPCDU_ENB_DRO); - gpioIF->pullLow(gpioIds::PLPCDU_ENB_TX); - gpioIF->pullLow(gpioIds::PLPCDU_ENB_VBAT0); - gpioIF->pullLow(gpioIds::PLPCDU_ENB_VBAT1); + pullAllGpiosLow(200); state = States::STACK_5V_CORRECT; } DeviceHandlerBase::doTransition(modeFrom, subModeFrom); @@ -367,14 +361,7 @@ void PayloadPcduHandler::enablePeriodicPrintout(bool enable, uint8_t divider) { void PayloadPcduHandler::quickTransitionBackToOff(bool startTransitionToOff, bool notifyFdir) { States currentState = state; - gpioIF->pullLow(gpioIds::PLPCDU_ENB_HPA); - gpioIF->pullLow(gpioIds::PLPCDU_ENB_MPA); - gpioIF->pullLow(gpioIds::PLPCDU_ENB_TX); - gpioIF->pullLow(gpioIds::PLPCDU_ENB_X8); - gpioIF->pullLow(gpioIds::PLPCDU_ENB_DRO); - gpioIF->pullLow(gpioIds::PLPCDU_ENB_TX); - gpioIF->pullLow(gpioIds::PLPCDU_ENB_VBAT0); - gpioIF->pullLow(gpioIds::PLPCDU_ENB_VBAT1); + pullAllGpiosLow(200); state = States::STACK_5V_SWITCHING; adcState = AdcStates::OFF; if (startTransitionToOff) { @@ -677,6 +664,17 @@ void PayloadPcduHandler::handleFailureInjection(std::string output, Event event) droToX8InjectionRequested = false; } +void PayloadPcduHandler::pullAllGpiosLow(uint32_t delayBeforeSwitchingOffDro) { + gpioIF->pullLow(gpioIds::PLPCDU_ENB_HPA); + gpioIF->pullLow(gpioIds::PLPCDU_ENB_MPA); + gpioIF->pullLow(gpioIds::PLPCDU_ENB_TX); + gpioIF->pullLow(gpioIds::PLPCDU_ENB_X8); + TaskFactory::delayTask(delayBeforeSwitchingOffDro); + gpioIF->pullLow(gpioIds::PLPCDU_ENB_DRO); + gpioIF->pullLow(gpioIds::PLPCDU_ENB_VBAT0); + gpioIF->pullLow(gpioIds::PLPCDU_ENB_VBAT1); +} + ReturnValue_t PayloadPcduHandler::handleDoubleParamUpdate(std::string key, ParameterWrapper* parameterWrapper, const ParameterWrapper* newValues) { diff --git a/mission/payload/PayloadPcduHandler.h b/mission/payload/PayloadPcduHandler.h index b73de353..78646104 100644 --- a/mission/payload/PayloadPcduHandler.h +++ b/mission/payload/PayloadPcduHandler.h @@ -168,6 +168,7 @@ class PayloadPcduHandler : public DeviceHandlerBase { void handleExtConvRead(const uint8_t* bufStart); void handlePrintout(); + void pullAllGpiosLow(uint32_t delayBeforeSwitchingOffDro); void checkAdcValues(); void handleOutOfBoundsPrintout(); void checkJsonFileInit(); diff --git a/tmtc b/tmtc index ab770a00..4b054b76 160000 --- a/tmtc +++ b/tmtc @@ -1 +1 @@ -Subproject commit ab770a0057258cc399072477a42eb0253d919aba +Subproject commit 4b054b7628e43975e2401c7db10c358824f7a2d3 -- 2.43.0 From a88725070b020d43ec834e5e5fd3463d123c688d Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Wed, 2 Aug 2023 13:40:37 +0200 Subject: [PATCH 02/11] more robust code --- CMakeLists.txt | 2 +- mission/payload/PayloadPcduHandler.cpp | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 6ffaf32f..17a6d5a6 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -144,7 +144,7 @@ set(OBSW_ADD_RAD_SENSORS ${INIT_VAL} CACHE STRING "Add Rad Sensor module") set(OBSW_ADD_PL_PCDU - ${INIT_VAL} + 1 CACHE STRING "Add Payload PCDU modukle") set(OBSW_ADD_SYRLINKS 1 diff --git a/mission/payload/PayloadPcduHandler.cpp b/mission/payload/PayloadPcduHandler.cpp index 4f22be87..7984b2ca 100644 --- a/mission/payload/PayloadPcduHandler.cpp +++ b/mission/payload/PayloadPcduHandler.cpp @@ -65,6 +65,7 @@ void PayloadPcduHandler::doShutDown() { return; } state = States::PL_PCDU_OFF; + quickTransitionAlreadyCalled = false; // No need to set mode _MODE_POWER_DOWN, power switching was already handled setMode(MODE_OFF); } -- 2.43.0 From eae63a8dc9ee750822824575724df67c9260c286 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Wed, 2 Aug 2023 14:08:10 +0200 Subject: [PATCH 03/11] add PL PCDU for EM --- CHANGELOG.md | 6 ++++++ bsp_q7s/em/emObjectFactory.cpp | 8 ++++++++ bsp_q7s/fmObjectFactory.cpp | 2 ++ bsp_q7s/objectFactory.cpp | 2 -- dummies/helperFactory.cpp | 8 +++++--- dummies/helperFactory.h | 1 + mission/payload/PayloadPcduHandler.cpp | 22 ++++++++++++++-------- mission/payload/PayloadPcduHandler.h | 1 + 8 files changed, 37 insertions(+), 13 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ae107d14..8a6ddc9d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -30,6 +30,12 @@ will consitute of a breaking change warranting a new major release: - The `EiveSystem` now only sends reboot commands targetting the same image. - Added 200 ms delay between switching HPA/MPA/TX/X8 and DRO GPIP pin OFF. +- PL PCDU ADC set is now automatically enabled for `NORMAL` mode transitions. It is automatically + disabled for `OFF` mode transitions. + +## Added + +- PL PCDU for EM build. # [v6.2.0] 2023-07-26 diff --git a/bsp_q7s/em/emObjectFactory.cpp b/bsp_q7s/em/emObjectFactory.cpp index 14cafdb2..3c3ba290 100644 --- a/bsp_q7s/em/emObjectFactory.cpp +++ b/bsp_q7s/em/emObjectFactory.cpp @@ -94,6 +94,9 @@ void ObjectFactory::produce(void* args) { #if OBSW_ADD_ACS_BOARD == 1 dummyCfg.addAcsBoardDummies = false; #endif +#if OBSW_ADD_PL_PCDU == 0 + dummyCfg.addPlPcduDummy = true; +#endif PowerSwitchIF* pwrSwitcher = nullptr; #if OBSW_ADD_GOMSPACE_PCDU == 0 @@ -107,6 +110,8 @@ void ObjectFactory::produce(void* args) { new CoreController(objects::CORE_CONTROLLER, enableHkSets); + auto* stackHandler = new Stack5VHandler(*pwrSwitcher); + // Initialize chip select to avoid SPI bus issues. createRadSensorChipSelect(gpioComIF); @@ -146,6 +151,9 @@ void ObjectFactory::produce(void* args) { createStrComponents(pwrSwitcher); #endif /* OBSW_ADD_STAR_TRACKER == 1 */ +#if OBSW_ADD_PL_PCDU == 1 + createPlPcduComponents(gpioComIF, spiMainComIF, pwrSwitcher, *stackHandler); +#endif createPayloadComponents(gpioComIF, *pwrSwitcher); #if OBSW_ADD_CCSDS_IP_CORES == 1 diff --git a/bsp_q7s/fmObjectFactory.cpp b/bsp_q7s/fmObjectFactory.cpp index e43e3551..a3ab6bba 100644 --- a/bsp_q7s/fmObjectFactory.cpp +++ b/bsp_q7s/fmObjectFactory.cpp @@ -81,7 +81,9 @@ void ObjectFactory::produce(void* args) { createTmpComponents(tmpDevsToAdd); #endif createSolarArrayDeploymentComponents(*pwrSwitcher, *gpioComIF); +#if OBSW_ADD_PL_PCDU == 1 createPlPcduComponents(gpioComIF, spiMainComIF, pwrSwitcher, *stackHandler); +#endif #if OBSW_ADD_SYRLINKS == 1 createSyrlinksComponents(pwrSwitcher); #endif /* OBSW_ADD_SYRLINKS == 1 */ diff --git a/bsp_q7s/objectFactory.cpp b/bsp_q7s/objectFactory.cpp index 04da40a9..39271628 100644 --- a/bsp_q7s/objectFactory.cpp +++ b/bsp_q7s/objectFactory.cpp @@ -902,8 +902,6 @@ void ObjectFactory::createPlPcduComponents(LinuxLibgpioIF* gpioComIF, SpiComIF* new PayloadPcduHandler(objects::PLPCDU_HANDLER, objects::SPI_MAIN_COM_IF, spiCookie, gpioComIF, SdCardManager::instance(), stackHandler, false); spiCookie->setCallbackMode(PayloadPcduHandler::extConvAsTwoCallback, plPcduHandler); -// plPcduHandler->enablePeriodicPrintout(true, 5); -// static_cast(plPcduHandler); #if OBSW_TEST_PL_PCDU == 1 plPcduHandler->setStartUpImmediately(); #endif diff --git a/dummies/helperFactory.cpp b/dummies/helperFactory.cpp index 8f58cbaf..b23720b4 100644 --- a/dummies/helperFactory.cpp +++ b/dummies/helperFactory.cpp @@ -248,9 +248,11 @@ void dummy::createDummies(DummyCfg cfg, PowerSwitchIF& pwrSwitcher, GpioIF* gpio auto* scexDummy = new ScexDummy(objects::SCEX, objects::DUMMY_COM_IF, comCookieDummy); scexDummy->connectModeTreeParent(satsystem::payload::SUBSYSTEM); } - auto* plPcduDummy = - new PlPcduDummy(objects::PLPCDU_HANDLER, objects::DUMMY_COM_IF, comCookieDummy); - plPcduDummy->connectModeTreeParent(satsystem::payload::SUBSYSTEM); + if (cfg.addPlPcduDummy) { + auto* plPcduDummy = + new PlPcduDummy(objects::PLPCDU_HANDLER, objects::DUMMY_COM_IF, comCookieDummy); + plPcduDummy->connectModeTreeParent(satsystem::payload::SUBSYSTEM); + } if (cfg.addPlocDummies) { auto* plocMpsocDummy = new PlocMpsocDummy(objects::PLOC_MPSOC_HANDLER, objects::DUMMY_COM_IF, comCookieDummy); diff --git a/dummies/helperFactory.h b/dummies/helperFactory.h index 32da11cd..34d167f0 100644 --- a/dummies/helperFactory.h +++ b/dummies/helperFactory.h @@ -30,6 +30,7 @@ struct DummyCfg { bool addStrDummy = true; bool addTmpDummies = true; bool addRadSensorDummy = true; + bool addPlPcduDummy = false; Tmp1075Cfg tmp1075Cfg; bool addCamSwitcherDummy = false; bool addScexDummy = false; diff --git a/mission/payload/PayloadPcduHandler.cpp b/mission/payload/PayloadPcduHandler.cpp index 7984b2ca..f6ac891c 100644 --- a/mission/payload/PayloadPcduHandler.cpp +++ b/mission/payload/PayloadPcduHandler.cpp @@ -66,6 +66,7 @@ void PayloadPcduHandler::doShutDown() { } state = States::PL_PCDU_OFF; quickTransitionAlreadyCalled = false; + adcSet.setReportingEnabled(false); // No need to set mode _MODE_POWER_DOWN, power switching was already handled setMode(MODE_OFF); } @@ -84,6 +85,10 @@ void PayloadPcduHandler::doTransition(Mode_t modeFrom, Submode_t subModeFrom) { ReturnValue_t PayloadPcduHandler::stateMachineToNormal(Mode_t modeFrom, Submode_t subModeFrom) { using namespace plpcdu; bool doFinish = true; + if (toNormalOneShot) { + adcSet.setReportingEnabled(true); + toNormalOneShot = false; + } if (((getSubmode() >> SOLID_STATE_RELAYS_ADC_ON) & 0b1) == 1) { if (state == States::PL_PCDU_OFF) { sif::error << "PayloadPcduHandler::stateMachineToNormal: Unexpected state PL_PCDU_OFF" @@ -162,6 +167,7 @@ ReturnValue_t PayloadPcduHandler::stateMachineToNormal(Mode_t modeFrom, Submode_ switchHandler(MPA_ON, gpioIds::PLPCDU_ENB_MPA, "MPA"); switchHandler(HPA_ON, gpioIds::PLPCDU_ENB_HPA, "HPA"); if (doFinish) { + toNormalOneShot = true; setMode(MODE_NORMAL); } return returnvalue::OK; @@ -666,14 +672,14 @@ void PayloadPcduHandler::handleFailureInjection(std::string output, Event event) } void PayloadPcduHandler::pullAllGpiosLow(uint32_t delayBeforeSwitchingOffDro) { - gpioIF->pullLow(gpioIds::PLPCDU_ENB_HPA); - gpioIF->pullLow(gpioIds::PLPCDU_ENB_MPA); - gpioIF->pullLow(gpioIds::PLPCDU_ENB_TX); - gpioIF->pullLow(gpioIds::PLPCDU_ENB_X8); - TaskFactory::delayTask(delayBeforeSwitchingOffDro); - gpioIF->pullLow(gpioIds::PLPCDU_ENB_DRO); - gpioIF->pullLow(gpioIds::PLPCDU_ENB_VBAT0); - gpioIF->pullLow(gpioIds::PLPCDU_ENB_VBAT1); + gpioIF->pullLow(gpioIds::PLPCDU_ENB_HPA); + gpioIF->pullLow(gpioIds::PLPCDU_ENB_MPA); + gpioIF->pullLow(gpioIds::PLPCDU_ENB_TX); + gpioIF->pullLow(gpioIds::PLPCDU_ENB_X8); + TaskFactory::delayTask(delayBeforeSwitchingOffDro); + gpioIF->pullLow(gpioIds::PLPCDU_ENB_DRO); + gpioIF->pullLow(gpioIds::PLPCDU_ENB_VBAT0); + gpioIF->pullLow(gpioIds::PLPCDU_ENB_VBAT1); } ReturnValue_t PayloadPcduHandler::handleDoubleParamUpdate(std::string key, diff --git a/mission/payload/PayloadPcduHandler.h b/mission/payload/PayloadPcduHandler.h index 78646104..ab21a445 100644 --- a/mission/payload/PayloadPcduHandler.h +++ b/mission/payload/PayloadPcduHandler.h @@ -128,6 +128,7 @@ class PayloadPcduHandler : public DeviceHandlerBase { bool mpaToHpaInjectionRequested = false; bool allOnInjectRequested = false; bool clearSetOnOffFlag = true; + bool toNormalOneShot = true; PeriodicOperationDivider opDivider = PeriodicOperationDivider(5); uint8_t tempReadDivisor = 1; -- 2.43.0 From b23ae2e152cb0ae687058da2242b5e7a8b37aef9 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Wed, 2 Aug 2023 14:17:32 +0200 Subject: [PATCH 04/11] logiically it works.. --- mission/payload/PayloadPcduHandler.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/mission/payload/PayloadPcduHandler.cpp b/mission/payload/PayloadPcduHandler.cpp index f6ac891c..a5c1043d 100644 --- a/mission/payload/PayloadPcduHandler.cpp +++ b/mission/payload/PayloadPcduHandler.cpp @@ -672,6 +672,7 @@ void PayloadPcduHandler::handleFailureInjection(std::string output, Event event) } void PayloadPcduHandler::pullAllGpiosLow(uint32_t delayBeforeSwitchingOffDro) { + sif::info << "Pulling all PL PCDU GPIOs to low" << std::endl; gpioIF->pullLow(gpioIds::PLPCDU_ENB_HPA); gpioIF->pullLow(gpioIds::PLPCDU_ENB_MPA); gpioIF->pullLow(gpioIds::PLPCDU_ENB_TX); -- 2.43.0 From d2c0c1709e372f93d24fe27c1d07462badfb8b2d Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Wed, 2 Aug 2023 15:29:13 +0200 Subject: [PATCH 05/11] that should do the job --- mission/payload/PayloadPcduHandler.cpp | 249 +++++++++++++------------ mission/payload/PayloadPcduHandler.h | 20 +- 2 files changed, 130 insertions(+), 139 deletions(-) diff --git a/mission/payload/PayloadPcduHandler.cpp b/mission/payload/PayloadPcduHandler.cpp index a5c1043d..5b964699 100644 --- a/mission/payload/PayloadPcduHandler.cpp +++ b/mission/payload/PayloadPcduHandler.cpp @@ -66,7 +66,11 @@ void PayloadPcduHandler::doShutDown() { } state = States::PL_PCDU_OFF; quickTransitionAlreadyCalled = false; - adcSet.setReportingEnabled(false); + { + PoolReadGuard pg(&adcSet); + adcSet.setReportingEnabled(false); + adcSet.setValidity(false, true); + } // No need to set mode _MODE_POWER_DOWN, power switching was already handled setMode(MODE_OFF); } @@ -86,6 +90,7 @@ ReturnValue_t PayloadPcduHandler::stateMachineToNormal(Mode_t modeFrom, Submode_ using namespace plpcdu; bool doFinish = true; if (toNormalOneShot) { + PoolReadGuard pg(&adcSet); adcSet.setReportingEnabled(true); toNormalOneShot = false; } @@ -114,23 +119,23 @@ ReturnValue_t PayloadPcduHandler::stateMachineToNormal(Mode_t modeFrom, Submode_ state = States::ON_TRANS_ADC_CLOSE_ZERO; adcCountdown.setTimeout(50); adcCountdown.resetTimer(); - adcState = AdcStates::BOOT_DELAY; + adcState = AdcState::BOOT_DELAY; doFinish = false; // If the values are not close to zero, we should not allow transition monMode = MonitoringMode::CLOSE_TO_ZERO; } } if (state == States::ON_TRANS_ADC_CLOSE_ZERO) { - if (adcState == AdcStates::BOOT_DELAY) { + if (adcState == AdcState::BOOT_DELAY) { doFinish = false; if (adcCountdown.hasTimedOut()) { - adcState = AdcStates::SEND_SETUP; + adcState = AdcState::SEND_SETUP; adcCmdExecuted = false; } } - if (adcState == AdcStates::SEND_SETUP) { + if (adcState == AdcState::SEND_SETUP) { if (adcCmdExecuted) { - adcState = AdcStates::NORMAL; + adcState = AdcState::NORMAL; doFinish = true; adcCountdown.setTimeout(100); adcCountdown.resetTimer(); @@ -175,11 +180,11 @@ ReturnValue_t PayloadPcduHandler::stateMachineToNormal(Mode_t modeFrom, Submode_ ReturnValue_t PayloadPcduHandler::buildNormalDeviceCommand(DeviceCommandId_t* id) { switch (adcState) { - case (AdcStates::SEND_SETUP): { + case (AdcState::SEND_SETUP): { *id = plpcdu::SETUP_CMD; return buildCommandFromCommand(*id, nullptr, 0); } - case (AdcStates::NORMAL): { + case (AdcState::NORMAL): { *id = plpcdu::READ_WITH_TEMP_EXT; return buildCommandFromCommand(*id, nullptr, 0); } @@ -191,7 +196,7 @@ ReturnValue_t PayloadPcduHandler::buildNormalDeviceCommand(DeviceCommandId_t* id } ReturnValue_t PayloadPcduHandler::buildTransitionDeviceCommand(DeviceCommandId_t* id) { - if (adcState == AdcStates::SEND_SETUP) { + if (adcState == AdcState::SEND_SETUP) { *id = plpcdu::SETUP_CMD; return buildCommandFromCommand(*id, nullptr, 0); } @@ -212,9 +217,9 @@ void PayloadPcduHandler::updateSwitchGpio(gpioId_t id, gpio::Levels level) { } void PayloadPcduHandler::fillCommandAndReplyMap() { - insertInCommandAndReplyMap(plpcdu::READ_CMD, 2, &adcSet); - insertInCommandAndReplyMap(plpcdu::READ_TEMP_EXT, 1, &adcSet); - insertInCommandAndReplyMap(plpcdu::READ_WITH_TEMP_EXT, 1, &adcSet); + insertInCommandAndReplyMap(plpcdu::READ_CMD, 2); + insertInCommandAndReplyMap(plpcdu::READ_TEMP_EXT, 1); + insertInCommandAndReplyMap(plpcdu::READ_WITH_TEMP_EXT, 1); insertInCommandAndReplyMap(plpcdu::SETUP_CMD, 1); } @@ -278,27 +283,31 @@ ReturnValue_t PayloadPcduHandler::interpretDeviceReply(DeviceCommandId_t id, break; } case (READ_CMD): { - PoolReadGuard pg(&adcSet); - if (pg.getReadResult() != returnvalue::OK) { - return pg.getReadResult(); + { + PoolReadGuard pg(&adcSet); + if (pg.getReadResult() != returnvalue::OK) { + return pg.getReadResult(); + } + handleExtConvRead(packet); + checkAdcValues(); + adcSet.setValidity(true, true); } - handleExtConvRead(packet); - checkAdcValues(); - adcSet.setValidity(true, true); handlePrintout(); break; } case (READ_WITH_TEMP_EXT): { - PoolReadGuard pg(&adcSet); - if (pg.getReadResult() != returnvalue::OK) { - return pg.getReadResult(); + { + PoolReadGuard pg(&adcSet); + if (pg.getReadResult() != returnvalue::OK) { + return pg.getReadResult(); + } + handleExtConvRead(packet); + uint8_t tempStartIdx = ADC_REPLY_SIZE + TEMP_REPLY_SIZE - 2; + adcSet.tempC.value = + max1227::getTemperature(packet[tempStartIdx] << 8 | packet[tempStartIdx + 1]); + checkAdcValues(); + adcSet.setValidity(true, true); } - handleExtConvRead(packet); - uint8_t tempStartIdx = ADC_REPLY_SIZE + TEMP_REPLY_SIZE - 2; - adcSet.tempC.value = - max1227::getTemperature(packet[tempStartIdx] << 8 | packet[tempStartIdx + 1]); - checkAdcValues(); - adcSet.setValidity(true, true); handlePrintout(); break; } @@ -370,9 +379,11 @@ void PayloadPcduHandler::quickTransitionBackToOff(bool startTransitionToOff, boo States currentState = state; pullAllGpiosLow(200); state = States::STACK_5V_SWITCHING; - adcState = AdcStates::OFF; + adcState = AdcState::OFF; if (startTransitionToOff) { + sif::debug << "transition back to off" << std::endl; startTransition(MODE_OFF, 0); + sif::debug << "blubwapfwa" << std::endl; } if (notifyFdir) { triggerEvent(TRANSITION_BACK_TO_OFF, static_cast(currentState)); @@ -400,108 +411,94 @@ void PayloadPcduHandler::checkAdcValues() { float lowerBound = 0.0; float upperBound = 0.0; bool adcTransition = false; - adcTransition = state == States::ON_TRANS_DRO and adcCountdown.isBusy(); - // Now check against voltage and current limits, depending on state - if (state >= States::ON_TRANS_DRO and not adcTransition) { - if (ssrToDroInjectionRequested) { - handleFailureInjection("SSR to DRO", NEG_V_OUT_OF_BOUNDS); - ssrToDroInjectionRequested = false; - return; - } - params.getValue(PARAM_KEY_MAP[NEG_V_LOWER_BOUND], lowerBound); - params.getValue(PARAM_KEY_MAP[NEG_V_UPPER_BOUND], upperBound); - if (not checkVoltage(adcSet.processed[U_NEG_V_FB], lowerBound, upperBound, - NEG_V_OUT_OF_BOUNDS)) { - return; - } - params.getValue(PARAM_KEY_MAP[DRO_U_LOWER_BOUND], lowerBound); - params.getValue(PARAM_KEY_MAP[DRO_U_UPPER_BOUND], upperBound); - if (not checkVoltage(adcSet.processed[U_DRO_DIV_6], lowerBound, upperBound, - U_DRO_OUT_OF_BOUNDS)) { - return; - } - params.getValue(PARAM_KEY_MAP[DRO_I_UPPER_BOUND], upperBound); - if (not checkCurrent(adcSet.processed[I_DRO], upperBound, I_DRO_OUT_OF_BOUNDS)) { + adcTransition = adcState == AdcState::NORMAL and adcCountdown.isBusy(); + if (NO_ADC_CHECKS) { + return; + } + // Now check against voltage and current limits. + if (ssrToDroInjectionRequested) { + handleFailureInjection("SSR to DRO", NEG_V_OUT_OF_BOUNDS); + ssrToDroInjectionRequested = false; + return; + } + if (droToX8InjectionRequested) { + handleFailureInjection("X8 to TX", U_X8_OUT_OF_BOUNDS); + droToX8InjectionRequested = false; + return; + } + if (txToMpaInjectionRequested) { + handleFailureInjection("TX to MPA", U_TX_OUT_OF_BOUNDS); + txToMpaInjectionRequested = false; + return; + } + if (mpaToHpaInjectionRequested) { + handleFailureInjection("MPA to HPA", U_HPA_OUT_OF_BOUNDS); + mpaToHpaInjectionRequested = false; + return; + } + if (allOnInjectRequested) { + handleFailureInjection("All On", U_HPA_OUT_OF_BOUNDS); + allOnInjectRequested = false; + return; + } + params.getValue(PARAM_KEY_MAP[NEG_V_LOWER_BOUND], lowerBound); + params.getValue(PARAM_KEY_MAP[NEG_V_UPPER_BOUND], upperBound); + if (not checkVoltage(adcSet.processed[U_NEG_V_FB], lowerBound, upperBound, NEG_V_OUT_OF_BOUNDS)) { + return; + } + params.getValue(PARAM_KEY_MAP[DRO_U_LOWER_BOUND], lowerBound); + params.getValue(PARAM_KEY_MAP[DRO_U_UPPER_BOUND], upperBound); + if (not checkVoltage(adcSet.processed[U_DRO_DIV_6], lowerBound, upperBound, + U_DRO_OUT_OF_BOUNDS)) { + return; + } + params.getValue(PARAM_KEY_MAP[DRO_I_UPPER_BOUND], upperBound); + if (not checkCurrent(adcSet.processed[I_DRO], upperBound, I_DRO_OUT_OF_BOUNDS)) { #if OBSW_VERBOSE_LEVEL >= 1 - sif::warning << "Detected out of bounds current for DRO: " << adcSet.processed[I_DRO] - << ", Raw: " << adcSet.channels[I_DRO] << std::endl; + sif::warning << "Detected out of bounds current for DRO: " << adcSet.processed[I_DRO] + << ", Raw: " << adcSet.channels[I_DRO] << std::endl; #endif - return; - } + return; } - adcTransition = state == States::ON_TRANS_X8 and adcCountdown.isBusy(); - if (state >= States::ON_TRANS_X8 and not adcTransition) { - if (droToX8InjectionRequested) { - handleFailureInjection("X8 to TX", U_X8_OUT_OF_BOUNDS); - droToX8InjectionRequested = false; - return; - } - params.getValue(PARAM_KEY_MAP[X8_U_LOWER_BOUND], lowerBound); - params.getValue(PARAM_KEY_MAP[X8_U_UPPER_BOUND], upperBound); - if (not checkVoltage(adcSet.processed[U_X8_DIV_6], lowerBound, upperBound, - U_X8_OUT_OF_BOUNDS)) { - return; - } - params.getValue(PARAM_KEY_MAP[X8_I_UPPER_BOUND], upperBound); - if (not checkCurrent(adcSet.processed[I_X8], upperBound, I_X8_OUT_OF_BOUNDS)) { - return; - } + params.getValue(PARAM_KEY_MAP[X8_U_LOWER_BOUND], lowerBound); + params.getValue(PARAM_KEY_MAP[X8_U_UPPER_BOUND], upperBound); + if (not checkVoltage(adcSet.processed[U_X8_DIV_6], lowerBound, upperBound, U_X8_OUT_OF_BOUNDS)) { + return; } - adcTransition = state == States::ON_TRANS_TX and adcCountdown.isBusy(); - if (state >= States::ON_TRANS_TX and not adcTransition) { - if (txToMpaInjectionRequested) { - handleFailureInjection("TX to MPA", U_TX_OUT_OF_BOUNDS); - txToMpaInjectionRequested = false; - return; - } - params.getValue(PARAM_KEY_MAP[TX_U_LOWER_BOUND], lowerBound); - params.getValue(PARAM_KEY_MAP[TX_U_UPPER_BOUND], upperBound); - if (not checkVoltage(adcSet.processed[U_TX_DIV_6], lowerBound, upperBound, - U_TX_OUT_OF_BOUNDS)) { - return; - } - params.getValue(PARAM_KEY_MAP[TX_I_UPPER_BOUND], upperBound); - if (not checkCurrent(adcSet.processed[I_TX], upperBound, I_TX_OUT_OF_BOUNDS)) { - return; - } + params.getValue(PARAM_KEY_MAP[X8_I_UPPER_BOUND], upperBound); + if (not checkCurrent(adcSet.processed[I_X8], upperBound, I_X8_OUT_OF_BOUNDS)) { + return; } - adcTransition = state == States::ON_TRANS_MPA and adcCountdown.isBusy(); - if (state >= States::ON_TRANS_MPA and not adcTransition) { - if (mpaToHpaInjectionRequested) { - handleFailureInjection("MPA to HPA", U_HPA_OUT_OF_BOUNDS); - mpaToHpaInjectionRequested = false; - return; - } - params.getValue(PARAM_KEY_MAP[MPA_U_LOWER_BOUND], lowerBound); - params.getValue(PARAM_KEY_MAP[MPA_U_UPPER_BOUND], upperBound); - if (not checkVoltage(adcSet.processed[U_MPA_DIV_6], lowerBound, upperBound, - U_MPA_OUT_OF_BOUNDS)) { - return; - } - params.getValue(PARAM_KEY_MAP[MPA_I_UPPER_BOUND], upperBound); - if (not checkCurrent(adcSet.processed[I_MPA], upperBound, I_MPA_OUT_OF_BOUNDS)) { - return; - } + params.getValue(PARAM_KEY_MAP[TX_U_LOWER_BOUND], lowerBound); + params.getValue(PARAM_KEY_MAP[TX_U_UPPER_BOUND], upperBound); + if (not checkVoltage(adcSet.processed[U_TX_DIV_6], lowerBound, upperBound, U_TX_OUT_OF_BOUNDS)) { + return; } - adcTransition = state == States::ON_TRANS_HPA and adcCountdown.isBusy(); - if (state >= States::ON_TRANS_HPA and not adcTransition) { - if (allOnInjectRequested) { - handleFailureInjection("All On", U_HPA_OUT_OF_BOUNDS); - allOnInjectRequested = false; - return; - } - params.getValue(PARAM_KEY_MAP[HPA_U_LOWER_BOUND], lowerBound); - params.getValue(PARAM_KEY_MAP[HPA_U_UPPER_BOUND], upperBound); - if (not checkVoltage(adcSet.processed[U_HPA_DIV_6], lowerBound, upperBound, - U_HPA_OUT_OF_BOUNDS)) { - return; - } - params.getValue(PARAM_KEY_MAP[HPA_I_UPPER_BOUND], upperBound); - if (not checkCurrent(adcSet.processed[I_HPA], upperBound, I_HPA_OUT_OF_BOUNDS)) { - sif::warning << "PayloadPcduHandler::checkCurrent: I HPA exceeded limit: Measured " - << adcSet.processed[I_HPA] << " mA" << std::endl; - return; - } + params.getValue(PARAM_KEY_MAP[TX_I_UPPER_BOUND], upperBound); + if (not checkCurrent(adcSet.processed[I_TX], upperBound, I_TX_OUT_OF_BOUNDS)) { + return; + } + params.getValue(PARAM_KEY_MAP[MPA_U_LOWER_BOUND], lowerBound); + params.getValue(PARAM_KEY_MAP[MPA_U_UPPER_BOUND], upperBound); + if (not checkVoltage(adcSet.processed[U_MPA_DIV_6], lowerBound, upperBound, + U_MPA_OUT_OF_BOUNDS)) { + return; + } + params.getValue(PARAM_KEY_MAP[MPA_I_UPPER_BOUND], upperBound); + if (not checkCurrent(adcSet.processed[I_MPA], upperBound, I_MPA_OUT_OF_BOUNDS)) { + return; + } + params.getValue(PARAM_KEY_MAP[HPA_U_LOWER_BOUND], lowerBound); + params.getValue(PARAM_KEY_MAP[HPA_U_UPPER_BOUND], upperBound); + if (not checkVoltage(adcSet.processed[U_HPA_DIV_6], lowerBound, upperBound, + U_HPA_OUT_OF_BOUNDS)) { + return; + } + params.getValue(PARAM_KEY_MAP[HPA_I_UPPER_BOUND], upperBound); + if (not checkCurrent(adcSet.processed[I_HPA], upperBound, I_HPA_OUT_OF_BOUNDS)) { + sif::warning << "PayloadPcduHandler::checkCurrent: I HPA exceeded limit: Measured " + << adcSet.processed[I_HPA] << " mA" << std::endl; + return; } transitionOk = true; } @@ -521,6 +518,8 @@ void PayloadPcduHandler::checkJsonFileInit() { bool PayloadPcduHandler::checkVoltage(float val, float lowerBound, float upperBound, Event event) { bool tooLarge = false; + sif::debug << "CHecking voltage. Value: " << val << ", lower bound: " << lowerBound + << ", upper bound: " << upperBound << std::endl; if (val < lowerBound or val > upperBound) { if (val > upperBound) { tooLarge = true; @@ -698,6 +697,8 @@ ReturnValue_t PayloadPcduHandler::handleDoubleParamUpdate(std::string key, return params.writeJsonFile(); } +LocalPoolDataSetBase* PayloadPcduHandler::getDataSetHandle(sid_t sid) { return &adcSet; } + #ifdef XIPHOS_Q7S ReturnValue_t PayloadPcduHandler::extConvAsTwoCallback(SpiComIF* comIf, SpiCookie* cookie, const uint8_t* sendData, size_t sendLen, diff --git a/mission/payload/PayloadPcduHandler.h b/mission/payload/PayloadPcduHandler.h index ab21a445..d9370dcf 100644 --- a/mission/payload/PayloadPcduHandler.h +++ b/mission/payload/PayloadPcduHandler.h @@ -76,6 +76,8 @@ class PayloadPcduHandler : public DeviceHandlerBase { #endif private: + static constexpr bool NO_ADC_CHECKS = false; + enum class States : uint8_t { PL_PCDU_OFF, STACK_5V_SWITCHING, @@ -84,20 +86,7 @@ class PayloadPcduHandler : public DeviceHandlerBase { // Solid State Relay, enable battery voltages VBAT0 and VBAT1. This will also switch on // the ADC ON_TRANS_SSR, - ON_TRANS_ADC_CLOSE_ZERO, - // Enable Dielectric Resonant Oscillator and start monitoring voltages as - // soon as DRO voltage reaches 6V - ON_TRANS_DRO, - // Switch on X8 compoennt and monitor voltages for 5 seconds - ON_TRANS_X8, - // Switch on TX component and monitor voltages for 5 seconds - ON_TRANS_TX, - // Switch on MPA component and monitor voltages for 5 seconds - ON_TRANS_MPA, - // Switch on HPA component and monitor voltages for 5 seconds - ON_TRANS_HPA, - // All components of the experiment are on - PL_PCDU_ON, + ON_TRANS_ADC_CLOSE_ZERO } state = States::PL_PCDU_OFF; duallane::Submodes pwrSubmode = duallane::Submodes::A_SIDE; @@ -106,7 +95,7 @@ class PayloadPcduHandler : public DeviceHandlerBase { enum class MonitoringMode { NONE, CLOSE_TO_ZERO, NEGATIVE } monMode = MonitoringMode::NONE; - enum class AdcStates { OFF, BOOT_DELAY, SEND_SETUP, NORMAL } adcState = AdcStates::OFF; + enum class AdcState { OFF, BOOT_DELAY, SEND_SETUP, NORMAL } adcState = AdcState::OFF; bool goToNormalMode = false; plpcdu::PlPcduAdcSet adcSet; @@ -180,6 +169,7 @@ class PayloadPcduHandler : public DeviceHandlerBase { ReturnValue_t serializeFloat(uint32_t& param, float val); ReturnValue_t handleDoubleParamUpdate(std::string key, ParameterWrapper* parameterWrapper, const ParameterWrapper* newValues); + LocalPoolDataSetBase* getDataSetHandle(sid_t sid) override; }; #endif /* LINUX_DEVICES_PLPCDUHANDLER_H_ */ -- 2.43.0 From 093f7f3a31dcf5685c0818f33eafb4d14508bf59 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Thu, 3 Aug 2023 09:59:08 +0200 Subject: [PATCH 06/11] re-introduce proper bounds checking --- mission/payload/PayloadPcduHandler.cpp | 125 ++++++++++++++----------- 1 file changed, 68 insertions(+), 57 deletions(-) diff --git a/mission/payload/PayloadPcduHandler.cpp b/mission/payload/PayloadPcduHandler.cpp index 5b964699..85af7cb1 100644 --- a/mission/payload/PayloadPcduHandler.cpp +++ b/mission/payload/PayloadPcduHandler.cpp @@ -410,9 +410,8 @@ void PayloadPcduHandler::checkAdcValues() { adcSet.processed[U_DRO_DIV_6] = static_cast(adcSet.channels[11]) * SCALE_VOLTAGE; float lowerBound = 0.0; float upperBound = 0.0; - bool adcTransition = false; - adcTransition = adcState == AdcState::NORMAL and adcCountdown.isBusy(); - if (NO_ADC_CHECKS) { + bool adcTransition = adcState == AdcState::NORMAL and adcCountdown.isBusy(); + if (NO_ADC_CHECKS or adcTransition) { return; } // Now check against voltage and current limits. @@ -441,64 +440,78 @@ void PayloadPcduHandler::checkAdcValues() { allOnInjectRequested = false; return; } - params.getValue(PARAM_KEY_MAP[NEG_V_LOWER_BOUND], lowerBound); - params.getValue(PARAM_KEY_MAP[NEG_V_UPPER_BOUND], upperBound); - if (not checkVoltage(adcSet.processed[U_NEG_V_FB], lowerBound, upperBound, NEG_V_OUT_OF_BOUNDS)) { - return; - } - params.getValue(PARAM_KEY_MAP[DRO_U_LOWER_BOUND], lowerBound); - params.getValue(PARAM_KEY_MAP[DRO_U_UPPER_BOUND], upperBound); - if (not checkVoltage(adcSet.processed[U_DRO_DIV_6], lowerBound, upperBound, - U_DRO_OUT_OF_BOUNDS)) { - return; - } - params.getValue(PARAM_KEY_MAP[DRO_I_UPPER_BOUND], upperBound); - if (not checkCurrent(adcSet.processed[I_DRO], upperBound, I_DRO_OUT_OF_BOUNDS)) { + uint8_t submode = getSubmode(); + if (((submode >> NormalSubmodeBits::DRO_ON) & 0b1) == 0b1) { + params.getValue(PARAM_KEY_MAP[NEG_V_LOWER_BOUND], lowerBound); + params.getValue(PARAM_KEY_MAP[NEG_V_UPPER_BOUND], upperBound); + if (not checkVoltage(adcSet.processed[U_NEG_V_FB], lowerBound, upperBound, + NEG_V_OUT_OF_BOUNDS)) { + return; + } + params.getValue(PARAM_KEY_MAP[DRO_U_LOWER_BOUND], lowerBound); + params.getValue(PARAM_KEY_MAP[DRO_U_UPPER_BOUND], upperBound); + if (not checkVoltage(adcSet.processed[U_DRO_DIV_6], lowerBound, upperBound, + U_DRO_OUT_OF_BOUNDS)) { + return; + } + params.getValue(PARAM_KEY_MAP[DRO_I_UPPER_BOUND], upperBound); + if (not checkCurrent(adcSet.processed[I_DRO], upperBound, I_DRO_OUT_OF_BOUNDS)) { #if OBSW_VERBOSE_LEVEL >= 1 - sif::warning << "Detected out of bounds current for DRO: " << adcSet.processed[I_DRO] - << ", Raw: " << adcSet.channels[I_DRO] << std::endl; + sif::warning << "Detected out of bounds current for DRO: " << adcSet.processed[I_DRO] + << ", Raw: " << adcSet.channels[I_DRO] << std::endl; #endif - return; + return; + } } - params.getValue(PARAM_KEY_MAP[X8_U_LOWER_BOUND], lowerBound); - params.getValue(PARAM_KEY_MAP[X8_U_UPPER_BOUND], upperBound); - if (not checkVoltage(adcSet.processed[U_X8_DIV_6], lowerBound, upperBound, U_X8_OUT_OF_BOUNDS)) { - return; + if (((submode >> NormalSubmodeBits::X8_ON) & 0b1) == 0b1) { + params.getValue(PARAM_KEY_MAP[X8_U_LOWER_BOUND], lowerBound); + params.getValue(PARAM_KEY_MAP[X8_U_UPPER_BOUND], upperBound); + if (not checkVoltage(adcSet.processed[U_X8_DIV_6], lowerBound, upperBound, + U_X8_OUT_OF_BOUNDS)) { + return; + } + params.getValue(PARAM_KEY_MAP[X8_I_UPPER_BOUND], upperBound); + if (not checkCurrent(adcSet.processed[I_X8], upperBound, I_X8_OUT_OF_BOUNDS)) { + return; + } } - params.getValue(PARAM_KEY_MAP[X8_I_UPPER_BOUND], upperBound); - if (not checkCurrent(adcSet.processed[I_X8], upperBound, I_X8_OUT_OF_BOUNDS)) { - return; + if (((submode >> NormalSubmodeBits::TX_ON) & 0b1) == 0b1) { + params.getValue(PARAM_KEY_MAP[TX_U_LOWER_BOUND], lowerBound); + params.getValue(PARAM_KEY_MAP[TX_U_UPPER_BOUND], upperBound); + if (not checkVoltage(adcSet.processed[U_TX_DIV_6], lowerBound, upperBound, + U_TX_OUT_OF_BOUNDS)) { + return; + } + params.getValue(PARAM_KEY_MAP[TX_I_UPPER_BOUND], upperBound); + if (not checkCurrent(adcSet.processed[I_TX], upperBound, I_TX_OUT_OF_BOUNDS)) { + return; + } } - params.getValue(PARAM_KEY_MAP[TX_U_LOWER_BOUND], lowerBound); - params.getValue(PARAM_KEY_MAP[TX_U_UPPER_BOUND], upperBound); - if (not checkVoltage(adcSet.processed[U_TX_DIV_6], lowerBound, upperBound, U_TX_OUT_OF_BOUNDS)) { - return; + if (((submode >> NormalSubmodeBits::MPA_ON) & 0b1) == 0b1) { + params.getValue(PARAM_KEY_MAP[MPA_U_LOWER_BOUND], lowerBound); + params.getValue(PARAM_KEY_MAP[MPA_U_UPPER_BOUND], upperBound); + if (not checkVoltage(adcSet.processed[U_MPA_DIV_6], lowerBound, upperBound, + U_MPA_OUT_OF_BOUNDS)) { + return; + } + params.getValue(PARAM_KEY_MAP[MPA_I_UPPER_BOUND], upperBound); + if (not checkCurrent(adcSet.processed[I_MPA], upperBound, I_MPA_OUT_OF_BOUNDS)) { + return; + } } - params.getValue(PARAM_KEY_MAP[TX_I_UPPER_BOUND], upperBound); - if (not checkCurrent(adcSet.processed[I_TX], upperBound, I_TX_OUT_OF_BOUNDS)) { - return; - } - params.getValue(PARAM_KEY_MAP[MPA_U_LOWER_BOUND], lowerBound); - params.getValue(PARAM_KEY_MAP[MPA_U_UPPER_BOUND], upperBound); - if (not checkVoltage(adcSet.processed[U_MPA_DIV_6], lowerBound, upperBound, - U_MPA_OUT_OF_BOUNDS)) { - return; - } - params.getValue(PARAM_KEY_MAP[MPA_I_UPPER_BOUND], upperBound); - if (not checkCurrent(adcSet.processed[I_MPA], upperBound, I_MPA_OUT_OF_BOUNDS)) { - return; - } - params.getValue(PARAM_KEY_MAP[HPA_U_LOWER_BOUND], lowerBound); - params.getValue(PARAM_KEY_MAP[HPA_U_UPPER_BOUND], upperBound); - if (not checkVoltage(adcSet.processed[U_HPA_DIV_6], lowerBound, upperBound, - U_HPA_OUT_OF_BOUNDS)) { - return; - } - params.getValue(PARAM_KEY_MAP[HPA_I_UPPER_BOUND], upperBound); - if (not checkCurrent(adcSet.processed[I_HPA], upperBound, I_HPA_OUT_OF_BOUNDS)) { - sif::warning << "PayloadPcduHandler::checkCurrent: I HPA exceeded limit: Measured " - << adcSet.processed[I_HPA] << " mA" << std::endl; - return; + if (((submode >> NormalSubmodeBits::HPA_ON) & 0b1) == 0b1) { + params.getValue(PARAM_KEY_MAP[HPA_U_LOWER_BOUND], lowerBound); + params.getValue(PARAM_KEY_MAP[HPA_U_UPPER_BOUND], upperBound); + if (not checkVoltage(adcSet.processed[U_HPA_DIV_6], lowerBound, upperBound, + U_HPA_OUT_OF_BOUNDS)) { + return; + } + params.getValue(PARAM_KEY_MAP[HPA_I_UPPER_BOUND], upperBound); + if (not checkCurrent(adcSet.processed[I_HPA], upperBound, I_HPA_OUT_OF_BOUNDS)) { + sif::warning << "PayloadPcduHandler::checkCurrent: I HPA exceeded limit: Measured " + << adcSet.processed[I_HPA] << " mA" << std::endl; + return; + } } transitionOk = true; } @@ -518,8 +531,6 @@ void PayloadPcduHandler::checkJsonFileInit() { bool PayloadPcduHandler::checkVoltage(float val, float lowerBound, float upperBound, Event event) { bool tooLarge = false; - sif::debug << "CHecking voltage. Value: " << val << ", lower bound: " << lowerBound - << ", upper bound: " << upperBound << std::endl; if (val < lowerBound or val > upperBound) { if (val > upperBound) { tooLarge = true; -- 2.43.0 From 1f02c0ef57ece0e9cf41175685eea5952749daf3 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Thu, 3 Aug 2023 10:05:10 +0200 Subject: [PATCH 07/11] set set to 0 for OFF cmd --- mission/payload/PayloadPcduHandler.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/mission/payload/PayloadPcduHandler.cpp b/mission/payload/PayloadPcduHandler.cpp index 85af7cb1..2ec12fc0 100644 --- a/mission/payload/PayloadPcduHandler.cpp +++ b/mission/payload/PayloadPcduHandler.cpp @@ -69,6 +69,10 @@ void PayloadPcduHandler::doShutDown() { { PoolReadGuard pg(&adcSet); adcSet.setReportingEnabled(false); + adcSet.tempC = 0; + + std::memset(adcSet.channels.value, 0, sizeof(adcSet.channels.value)); + std::memset(adcSet.processed.value, 0, sizeof(adcSet.processed.value)); adcSet.setValidity(false, true); } // No need to set mode _MODE_POWER_DOWN, power switching was already handled -- 2.43.0 From 6f8ad08e9bfaaed770fcfb6b6d562a3e5ecc970f Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Thu, 3 Aug 2023 10:06:10 +0200 Subject: [PATCH 08/11] changelog --- CHANGELOG.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3be10611..698d79f0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -26,6 +26,8 @@ will consitute of a breaking change warranting a new major release: - Detumbling is now exited when its exit value is undercut and not its entry value. - `EiveSystem`: Add a small delay between triggering an event for FDIR reboots and sending the command to the core controller. +- PL PDU: Fixed bounds checking logic. Bound checks will only be performed for modules which are + enabled. ## Changed -- 2.43.0 From 7c3329abb21c14e1bb8bcab8e88e0e590acd6251 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Thu, 3 Aug 2023 10:16:11 +0200 Subject: [PATCH 09/11] this is more correct --- mission/payload/PayloadPcduHandler.cpp | 50 +++++++++++++------------- 1 file changed, 25 insertions(+), 25 deletions(-) diff --git a/mission/payload/PayloadPcduHandler.cpp b/mission/payload/PayloadPcduHandler.cpp index 2ec12fc0..b3f35897 100644 --- a/mission/payload/PayloadPcduHandler.cpp +++ b/mission/payload/PayloadPcduHandler.cpp @@ -419,33 +419,13 @@ void PayloadPcduHandler::checkAdcValues() { return; } // Now check against voltage and current limits. - if (ssrToDroInjectionRequested) { - handleFailureInjection("SSR to DRO", NEG_V_OUT_OF_BOUNDS); - ssrToDroInjectionRequested = false; - return; - } - if (droToX8InjectionRequested) { - handleFailureInjection("X8 to TX", U_X8_OUT_OF_BOUNDS); - droToX8InjectionRequested = false; - return; - } - if (txToMpaInjectionRequested) { - handleFailureInjection("TX to MPA", U_TX_OUT_OF_BOUNDS); - txToMpaInjectionRequested = false; - return; - } - if (mpaToHpaInjectionRequested) { - handleFailureInjection("MPA to HPA", U_HPA_OUT_OF_BOUNDS); - mpaToHpaInjectionRequested = false; - return; - } - if (allOnInjectRequested) { - handleFailureInjection("All On", U_HPA_OUT_OF_BOUNDS); - allOnInjectRequested = false; - return; - } uint8_t submode = getSubmode(); if (((submode >> NormalSubmodeBits::DRO_ON) & 0b1) == 0b1) { + if (ssrToDroInjectionRequested) { + handleFailureInjection("SSR to DRO", NEG_V_OUT_OF_BOUNDS); + ssrToDroInjectionRequested = false; + return; + } params.getValue(PARAM_KEY_MAP[NEG_V_LOWER_BOUND], lowerBound); params.getValue(PARAM_KEY_MAP[NEG_V_UPPER_BOUND], upperBound); if (not checkVoltage(adcSet.processed[U_NEG_V_FB], lowerBound, upperBound, @@ -468,6 +448,11 @@ void PayloadPcduHandler::checkAdcValues() { } } if (((submode >> NormalSubmodeBits::X8_ON) & 0b1) == 0b1) { + if (droToX8InjectionRequested) { + handleFailureInjection("X8 to TX", U_X8_OUT_OF_BOUNDS); + droToX8InjectionRequested = false; + return; + } params.getValue(PARAM_KEY_MAP[X8_U_LOWER_BOUND], lowerBound); params.getValue(PARAM_KEY_MAP[X8_U_UPPER_BOUND], upperBound); if (not checkVoltage(adcSet.processed[U_X8_DIV_6], lowerBound, upperBound, @@ -480,6 +465,11 @@ void PayloadPcduHandler::checkAdcValues() { } } if (((submode >> NormalSubmodeBits::TX_ON) & 0b1) == 0b1) { + if (txToMpaInjectionRequested) { + handleFailureInjection("TX to MPA", U_TX_OUT_OF_BOUNDS); + txToMpaInjectionRequested = false; + return; + } params.getValue(PARAM_KEY_MAP[TX_U_LOWER_BOUND], lowerBound); params.getValue(PARAM_KEY_MAP[TX_U_UPPER_BOUND], upperBound); if (not checkVoltage(adcSet.processed[U_TX_DIV_6], lowerBound, upperBound, @@ -492,6 +482,11 @@ void PayloadPcduHandler::checkAdcValues() { } } if (((submode >> NormalSubmodeBits::MPA_ON) & 0b1) == 0b1) { + if (mpaToHpaInjectionRequested) { + handleFailureInjection("MPA to HPA", U_HPA_OUT_OF_BOUNDS); + mpaToHpaInjectionRequested = false; + return; + } params.getValue(PARAM_KEY_MAP[MPA_U_LOWER_BOUND], lowerBound); params.getValue(PARAM_KEY_MAP[MPA_U_UPPER_BOUND], upperBound); if (not checkVoltage(adcSet.processed[U_MPA_DIV_6], lowerBound, upperBound, @@ -504,6 +499,11 @@ void PayloadPcduHandler::checkAdcValues() { } } if (((submode >> NormalSubmodeBits::HPA_ON) & 0b1) == 0b1) { + if (allOnInjectRequested) { + handleFailureInjection("All On", U_HPA_OUT_OF_BOUNDS); + allOnInjectRequested = false; + return; + } params.getValue(PARAM_KEY_MAP[HPA_U_LOWER_BOUND], lowerBound); params.getValue(PARAM_KEY_MAP[HPA_U_UPPER_BOUND], upperBound); if (not checkVoltage(adcSet.processed[U_HPA_DIV_6], lowerBound, upperBound, -- 2.43.0 From 97f40232d7b923e2297508c6b48af9ef9a2d446d Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Thu, 3 Aug 2023 10:16:51 +0200 Subject: [PATCH 10/11] changelog typo --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 698d79f0..247eddd4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -33,7 +33,7 @@ will consitute of a breaking change warranting a new major release: - SCEX: Only perform filesystem checks when not in OFF mode. - The `EiveSystem` now only sends reboot commands targetting the same image. -- Added 200 ms delay between switching HPA/MPA/TX/X8 and DRO GPIP pin OFF. +- Added 200 ms delay between switching HPA/MPA/TX/X8 and DRO GPIO pin OFF. - PL PCDU ADC set is now automatically enabled for `NORMAL` mode transitions. It is automatically disabled for `OFF` mode transitions. -- 2.43.0 From e746c151d335a986006fd3010eefe1fb4bcb2d81 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Thu, 3 Aug 2023 13:03:10 +0200 Subject: [PATCH 11/11] tweaks --- mission/payload/PayloadPcduHandler.cpp | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/mission/payload/PayloadPcduHandler.cpp b/mission/payload/PayloadPcduHandler.cpp index b3f35897..0f2ef2d6 100644 --- a/mission/payload/PayloadPcduHandler.cpp +++ b/mission/payload/PayloadPcduHandler.cpp @@ -1,4 +1,5 @@ -#include +#include +#include "fsfw/thermal/tcsDefinitions.h" #include #include @@ -69,7 +70,7 @@ void PayloadPcduHandler::doShutDown() { { PoolReadGuard pg(&adcSet); adcSet.setReportingEnabled(false); - adcSet.tempC = 0; + adcSet.tempC = thermal::INVALID_TEMPERATURE; std::memset(adcSet.channels.value, 0, sizeof(adcSet.channels.value)); std::memset(adcSet.processed.value, 0, sizeof(adcSet.processed.value)); @@ -385,9 +386,7 @@ void PayloadPcduHandler::quickTransitionBackToOff(bool startTransitionToOff, boo state = States::STACK_5V_SWITCHING; adcState = AdcState::OFF; if (startTransitionToOff) { - sif::debug << "transition back to off" << std::endl; startTransition(MODE_OFF, 0); - sif::debug << "blubwapfwa" << std::endl; } if (notifyFdir) { triggerEvent(TRANSITION_BACK_TO_OFF, static_cast(currentState)); -- 2.43.0