diff --git a/CHANGELOG.md b/CHANGELOG.md index b5881296..44c98cb5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -16,11 +16,64 @@ will consitute of a breaking change warranting a new major release: # [unreleased] -# [v6.0.0] to be released +## Changed +- TCS: Remove OBC IF board thermal module, which is exactly identical to OBC module and therefore + obsolete. +- Swapped PL and PS I2C, BPX battery and MGT are connected to PS I2C now for firmware versions + equal or above v4. However, this software version is compatible to both v3 and v4 of the firmware. +- The firmware version variables are global statics inititalized early during the program + runtime now. This makes it possible to check the firmware version earlier. +- The TCS controller will now always command heaters OFF when being blind for thermal + components (no sensors available), irrespective of current switch state. +- Make OBSW compatible to prospective FW version v5.0.0, where the Q7 I2C devices were + moved to a PL I2C block and the TMP sensor devices were moved to the PS I2C0. +- Made `Xadc` code a little bit more robust against errors. + +## Fixed + +- TMP1075: Set dataset invalid on shutdown explicitely +- Small fixes for TMP1075 FDIR: Use strange and missed reply counters. +- TCS controller: Last heater (S-band heater) was skipped for transition completion + checks. +- TCS controller: A helper member to track the elapsed heater control cycles was not reset + properly, which could lead to switch transitions being completed immediately. This can + lead to weird bugs like heaters being commanded ON twice and can potentially lead to + other bugs. +- TMP1075: Devices did not go to OFF mode when being set faulty. +- Update PL PCDU 1 in TCS mode tree on the EM. +- TMP1075: Possibly ignored health commands. +- Bugfix in FSFW where certain packet types could only be sent with source data fields with a + maximum size of 255 bytes. +- TCS CTRL: Limit number of heater handler messages sent in case there are not sensors available + anymore. + +# Added + +- Two events for heaters being commanded ON and OFF by the TCS controller +- Upper limit for burn time of TCS heaters. Currently set to 1 hour for each heater. + This mechanism will only track the burn time for heaters which were commanded by the + TCS controller. +- TCS controller is now observable by introducing a new HK dataset which exposes some internal + fields related to TCS control. + +# [v6.0.0] 2023-07-02 + +- `q7s-package` version v3.2.0 - Important bugfixes for PTME. See `q7s-package` CHANGELOG. -# [v5.2.0] 2023-06-29 +## Changed + +- Added back PTME busy bit polling. This is necessary due to changes to the AXI APB interface + to the PTME core. + +## Fixed + +- For the live channel (VC0), telemetry was still only dumped if the transmitter is active. + Please note that this fix will lead to crashes for FW versions below v3.2. + However, it might not be an issue for the oldest firmware on the satellite (v2.5.1). + +# [v5.2.0] 2023-07-02 ## Fixed @@ -32,6 +85,8 @@ will consitute of a breaking change warranting a new major release: - PTME was always reset on submode changes. The reset will now only be performed if the actual data rate changes. +- Add back ACS board code for the EM. Now that the radiation sensor was removed, the image switching + issue has disappeared and adding back the ACS board is worth it for the GPS timekeeping. # [v5.1.0] 2023-06-28 diff --git a/CMakeLists.txt b/CMakeLists.txt index 60412e93..54b43f47 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -105,7 +105,7 @@ set(OBSW_ADD_THERMAL_TEMP_INSERTER ${OBSW_Q7S_EM} CACHE STRING "Add thermal sensor temperature inserter") set(OBSW_ADD_ACS_BOARD - ${INIT_VAL} + 1 CACHE STRING "Add ACS board module") set(OBSW_ADD_GPS_CTRL ${INIT_VAL} @@ -150,7 +150,7 @@ set(OBSW_ADD_SYRLINKS 1 CACHE STRING "Add Syrlinks module") set(OBSW_ADD_TMP_DEVICES - ${INIT_VAL} + 1 CACHE STRING "Add TMP devices") set(OBSW_ADD_GOMSPACE_PCDU 1 diff --git a/README.md b/README.md index 6b06283c..ce57c33f 100644 --- a/README.md +++ b/README.md @@ -964,6 +964,12 @@ used by other software components to read the current chip and copy. This is a configuration scripts which runs after the Network Time Protocol has run. This script currently sets the static IP address `192.168.133.10` and starts the `can` interface. +## Initial boot delay + +You can create a file named `boot_delays_secs.txt` inside the home folder to delay the OBSW boot +for 6 seconds if the file is empty of for the number of seconds specified inside the file. This +can be helpful if something inside the OBSW leads to an immediate crash of the OBC. + ## PCDU Connect to serial console of P60 Dock diff --git a/bsp_hosted/ObjectFactory.cpp b/bsp_hosted/ObjectFactory.cpp index 23f1a79f..4873bc58 100644 --- a/bsp_hosted/ObjectFactory.cpp +++ b/bsp_hosted/ObjectFactory.cpp @@ -113,7 +113,7 @@ void ObjectFactory::produce(void* args) { if (heaterHandler == nullptr) { sif::error << "HeaterHandler could not be created" << std::endl; } else { - ObjectFactory::createThermalController(*heaterHandler); + ObjectFactory::createThermalController(*heaterHandler, true); } new TestTask(objects::TEST_TASK); } diff --git a/bsp_hosted/fsfwconfig/events/translateEvents.cpp b/bsp_hosted/fsfwconfig/events/translateEvents.cpp index 1500301f..b98926e5 100644 --- a/bsp_hosted/fsfwconfig/events/translateEvents.cpp +++ b/bsp_hosted/fsfwconfig/events/translateEvents.cpp @@ -1,7 +1,7 @@ /** - * @brief Auto-generated event translation file. Contains 296 translations. + * @brief Auto-generated event translation file. Contains 299 translations. * @details - * Generated on: 2023-06-21 19:01:02 + * Generated on: 2023-07-07 12:06:06 */ #include "translateEvents.h" @@ -286,6 +286,9 @@ const char *CAMERA_OVERHEATING_STRING = "CAMERA_OVERHEATING"; const char *PCDU_SYSTEM_OVERHEATING_STRING = "PCDU_SYSTEM_OVERHEATING"; const char *HEATER_NOT_OFF_FOR_OFF_MODE_STRING = "HEATER_NOT_OFF_FOR_OFF_MODE"; const char *MGT_OVERHEATING_STRING = "MGT_OVERHEATING"; +const char *TCS_SWITCHING_HEATER_ON_STRING = "TCS_SWITCHING_HEATER_ON"; +const char *TCS_SWITCHING_HEATER_OFF_STRING = "TCS_SWITCHING_HEATER_OFF"; +const char *TCS_HEATER_MAX_BURN_TIME_REACHED_STRING = "TCS_HEATER_MAX_BURN_TIME_REACHED"; const char *TX_TIMER_EXPIRED_STRING = "TX_TIMER_EXPIRED"; const char *BIT_LOCK_TX_ON_STRING = "BIT_LOCK_TX_ON"; const char *POSSIBLE_FILE_CORRUPTION_STRING = "POSSIBLE_FILE_CORRUPTION"; @@ -866,6 +869,12 @@ const char *translateEvents(Event event) { return HEATER_NOT_OFF_FOR_OFF_MODE_STRING; case (14108): return MGT_OVERHEATING_STRING; + case (14109): + return TCS_SWITCHING_HEATER_ON_STRING; + case (14110): + return TCS_SWITCHING_HEATER_OFF_STRING; + case (14111): + return TCS_HEATER_MAX_BURN_TIME_REACHED_STRING; case (14201): return TX_TIMER_EXPIRED_STRING; case (14202): diff --git a/bsp_hosted/fsfwconfig/objects/translateObjects.cpp b/bsp_hosted/fsfwconfig/objects/translateObjects.cpp index d1d0464c..458081f9 100644 --- a/bsp_hosted/fsfwconfig/objects/translateObjects.cpp +++ b/bsp_hosted/fsfwconfig/objects/translateObjects.cpp @@ -2,7 +2,7 @@ * @brief Auto-generated object translation file. * @details * Contains 171 translations. - * Generated on: 2023-06-21 19:01:02 + * Generated on: 2023-07-07 12:06:06 */ #include "translateObjects.h" diff --git a/bsp_q7s/CMakeLists.txt b/bsp_q7s/CMakeLists.txt index cf8fcacd..e3232363 100644 --- a/bsp_q7s/CMakeLists.txt +++ b/bsp_q7s/CMakeLists.txt @@ -7,7 +7,8 @@ target_link_libraries(${SIMPLE_OBSW_NAME} PUBLIC ${LIB_FSFW_NAME}) target_compile_definitions(${SIMPLE_OBSW_NAME} PRIVATE "Q7S_SIMPLE_MODE") add_subdirectory(simple) -target_sources(${OBSW_NAME} PUBLIC main.cpp obsw.cpp) +target_sources(${OBSW_NAME} PUBLIC main.cpp obsw.cpp scheduling.cpp + objectFactory.cpp) add_subdirectory(boardtest) diff --git a/bsp_q7s/boardconfig/busConf.h b/bsp_q7s/boardconfig/busConf.h index 146386c4..dc3779a7 100644 --- a/bsp_q7s/boardconfig/busConf.h +++ b/bsp_q7s/boardconfig/busConf.h @@ -12,6 +12,9 @@ static constexpr char SPI_RW_DEV[] = "/dev/spi_rw"; static constexpr char I2C_PL_EIVE[] = "/dev/i2c_pl"; //! I2C bus using the I2C peripheral of the ARM processing system (PS) static constexpr char I2C_PS_EIVE[] = "/dev/i2c_ps"; +//! I2C bus using the first I2C peripheral of the ARM processing system (PS). +//! Named like this because it is used by default for the Q7 devices. +static constexpr char I2C_Q7_EIVE[] = "/dev/i2c_q7"; static constexpr char UART_GNSS_DEV[] = "/dev/gps0"; static constexpr char UART_PLOC_MPSOC_DEV[] = "/dev/ul_plmpsoc"; diff --git a/bsp_q7s/core/CMakeLists.txt b/bsp_q7s/core/CMakeLists.txt index b726885b..33550144 100644 --- a/bsp_q7s/core/CMakeLists.txt +++ b/bsp_q7s/core/CMakeLists.txt @@ -1,4 +1 @@ -target_sources(${OBSW_NAME} PRIVATE CoreController.cpp scheduling.cpp - ObjectFactory.cpp WatchdogHandler.cpp) - -target_sources(${SIMPLE_OBSW_NAME} PRIVATE scheduling.cpp) +target_sources(${OBSW_NAME} PRIVATE CoreController.cpp WatchdogHandler.cpp) diff --git a/bsp_q7s/core/CoreController.cpp b/bsp_q7s/core/CoreController.cpp index cea6c700..00c7f248 100644 --- a/bsp_q7s/core/CoreController.cpp +++ b/bsp_q7s/core/CoreController.cpp @@ -188,17 +188,6 @@ ReturnValue_t CoreController::initialize() { } triggerEvent(core::REBOOT_SW, CURRENT_CHIP, CURRENT_COPY); announceCurrentImageInfo(); - // This has to come before the version announce because it might be required for retrieving - // the firmware version. - if (common::OBSW_VERSION_MAJOR >= 6 or common::OBSW_VERSION_MAJOR == 4) { - UioMapper sysRomMapper(q7s::UIO_SYS_ROM); - result = sysRomMapper.getMappedAdress(&mappedSysRomAddr, UioMapper::Permissions::READ_ONLY); - if (result != returnvalue::OK) { - // TODO: This might be a reason to switch to another image.. - sif::error << "Getting mapped SYS ROM UIO address failed" << std::endl; - result = ObjectManager::CHILD_INIT_FAILED; - } - } announceVersionInfo(); return result; @@ -2526,14 +2515,10 @@ void CoreController::announceVersionInfo() { } triggerEvent(VERSION_INFO, p1, p2); - - if (common::OBSW_VERSION_MAJOR >= 6 or common::OBSW_VERSION_MAJOR == 4) { - if (mappedSysRomAddr != nullptr) { - uint32_t p1Firmware = *(reinterpret_cast(mappedSysRomAddr)); - uint32_t p2Firmware = *(reinterpret_cast(mappedSysRomAddr) + 1); - triggerEvent(FIRMWARE_INFO, p1Firmware, p2Firmware); - } - } + p1 = (core::FW_VERSION_MAJOR << 24) | (core::FW_VERSION_MINOR << 16) | + (core::FW_VERSION_REVISION << 8) | (core::FW_VERSION_HAS_SHA); + std::memcpy(&p2, core::FW_VERSION_GIT_SHA, 4); + triggerEvent(FIRMWARE_INFO, p1, p2); } void CoreController::announceCurrentImageInfo() { diff --git a/bsp_q7s/core/CoreController.h b/bsp_q7s/core/CoreController.h index b68ae158..b6bc9bfb 100644 --- a/bsp_q7s/core/CoreController.h +++ b/bsp_q7s/core/CoreController.h @@ -1,6 +1,7 @@ #ifndef BSP_Q7S_CORE_CORECONTROLLER_H_ #define BSP_Q7S_CORE_CORECONTROLLER_H_ +#include #include #include #include @@ -14,7 +15,6 @@ #include #include -#include "CoreDefinitions.h" #include "OBSWConfig.h" #include "bsp_q7s/fs/SdCardManager.h" #include "events/subsystemIdRanges.h" diff --git a/bsp_q7s/core/CoreDefinitions.h b/bsp_q7s/core/defs.h similarity index 81% rename from bsp_q7s/core/CoreDefinitions.h rename to bsp_q7s/core/defs.h index 91896301..a82c1c56 100644 --- a/bsp_q7s/core/CoreDefinitions.h +++ b/bsp_q7s/core/defs.h @@ -1,10 +1,16 @@ -#ifndef BSP_Q7S_CORE_COREDEFINITIONS_H_ -#define BSP_Q7S_CORE_COREDEFINITIONS_H_ +#ifndef BSP_Q7S_CORE_DEFS_H_ +#define BSP_Q7S_CORE_DEFS_H_ #include namespace core { +extern uint8_t FW_VERSION_MAJOR; +extern uint8_t FW_VERSION_MINOR; +extern uint8_t FW_VERSION_REVISION; +extern bool FW_VERSION_HAS_SHA; +extern char FW_VERSION_GIT_SHA[4]; + static const uint8_t HK_SET_ENTRIES = 3; static const uint32_t HK_SET_ID = 5; @@ -36,4 +42,4 @@ class HkSet : public StaticLocalDataSet { } // namespace core -#endif /* BSP_Q7S_CORE_COREDEFINITIONS_H_ */ +#endif /* BSP_Q7S_CORE_DEFS_H_ */ diff --git a/bsp_q7s/em/emObjectFactory.cpp b/bsp_q7s/em/emObjectFactory.cpp index 21f8a6ad..e5d6abc2 100644 --- a/bsp_q7s/em/emObjectFactory.cpp +++ b/bsp_q7s/em/emObjectFactory.cpp @@ -1,4 +1,5 @@ #include +#include #include #include #include @@ -10,8 +11,8 @@ #include "OBSWConfig.h" #include "bsp_q7s/core/CoreController.h" -#include "bsp_q7s/core/ObjectFactory.h" #include "busConf.h" +#include "common/config/devices/addresses.h" #include "devConf.h" #include "dummies/helperFactory.h" #include "eive/objects.h" @@ -35,6 +36,7 @@ void ObjectFactory::produce(void* args) { #endif PersistentTmStores stores; + readFirmwareVersion(); ObjectFactory::produceGenericObjects(&healthTable, &pusFunnel, &cfdpFunnel, *SdCardManager::instance(), &ipcStore, &tmStore, stores, 200, enableHkSets); @@ -44,7 +46,7 @@ void ObjectFactory::produce(void* args) { SpiComIF* spiMainComIF = nullptr; I2cComIF* i2cComIF = nullptr; createCommunicationInterfaces(&gpioComIF, &uartComIF, &spiMainComIF, &i2cComIF); - /* Adding gpios for chip select decoding to the gpioComIf */ + // Adding GPIOs for chip select decoding and initializing them. q7s::gpioCallbacks::initSpiCsDecoder(gpioComIF); gpioCallbacks::disableAllDecoder(gpioComIF); createPlI2cResetGpio(gpioComIF); @@ -60,6 +62,21 @@ void ObjectFactory::produce(void* args) { #if OBSW_ADD_PLOC_SUPERVISOR == 1 || OBSW_ADD_PLOC_MPSOC == 1 dummyCfg.addPlocDummies = false; #endif +#if OBSW_ADD_TMP_DEVICES == 1 + std::vector> tmpDevsToAdd = {{ + {objects::TMP1075_HANDLER_PLPCDU_0, addresses::TMP1075_PLPCDU_0}, + {objects::TMP1075_HANDLER_PLPCDU_1, addresses::TMP1075_PLPCDU_1}, + {objects::TMP1075_HANDLER_IF_BOARD, addresses::TMP1075_IF_BOARD}, + }}; + createTmpComponents(tmpDevsToAdd); + dummy::Tmp1075Cfg tmpCfg{}; + tmpCfg.addTcsBrd0 = true; + tmpCfg.addTcsBrd1 = true; + tmpCfg.addPlPcdu0 = false; + tmpCfg.addPlPcdu1 = false; + tmpCfg.addIfBrd = false; + dummyCfg.tmp1075Cfg = tmpCfg; +#endif #if OBSW_ADD_GOMSPACE_PCDU == 1 dummyCfg.addPowerDummies = false; // The ACU broke. @@ -87,9 +104,10 @@ void ObjectFactory::produce(void* args) { new CoreController(objects::CORE_CONTROLLER, enableHkSets); -#if OBSW_ADD_ACS_BOARD == 1 - // Still initialize chip select to avoid SPI bus issues. + // Initialize chip select to avoid SPI bus issues. createRadSensorChipSelect(gpioComIF); + +#if OBSW_ADD_ACS_BOARD == 1 createAcsBoardComponents(*spiMainComIF, gpioComIF, uartComIF, *pwrSwitcher, true, adis1650x::Type::ADIS16507); #else @@ -99,8 +117,12 @@ void ObjectFactory::produce(void* args) { gpioChecker(gpioComIF->addGpios(acsBoardGpios), "ACS Board"); #endif + const char* battAndImtqI2cDev = q7s::I2C_PL_EIVE; + if (core::FW_VERSION_MAJOR >= 4) { + battAndImtqI2cDev = q7s::I2C_PS_EIVE; + } #if OBSW_ADD_MGT == 1 - createImtqComponents(pwrSwitcher, enableHkSets); + createImtqComponents(pwrSwitcher, enableHkSets, battAndImtqI2cDev); #endif #if OBSW_ADD_SYRLINKS == 1 @@ -112,7 +134,7 @@ void ObjectFactory::produce(void* args) { #endif #if OBSW_ADD_BPX_BATTERY_HANDLER == 1 - createBpxBatteryComponent(enableHkSets); + createBpxBatteryComponent(enableHkSets, battAndImtqI2cDev); #endif #if OBSW_ADD_STAR_TRACKER == 1 @@ -144,6 +166,6 @@ void ObjectFactory::produce(void* args) { createAcsController(true, enableHkSets); HeaterHandler* heaterHandler; createHeaterComponents(gpioComIF, pwrSwitcher, healthTable, heaterHandler); - createThermalController(*heaterHandler); - satsystem::init(); + createThermalController(*heaterHandler, true); + satsystem::init(true); } diff --git a/bsp_q7s/fmObjectFactory.cpp b/bsp_q7s/fmObjectFactory.cpp index d9329fc0..e43e3551 100644 --- a/bsp_q7s/fmObjectFactory.cpp +++ b/bsp_q7s/fmObjectFactory.cpp @@ -1,4 +1,5 @@ #include +#include #include #include #include @@ -7,9 +8,9 @@ #include "OBSWConfig.h" #include "bsp_q7s/core/CoreController.h" -#include "bsp_q7s/core/ObjectFactory.h" #include "busConf.h" #include "devConf.h" +#include "devices/addresses.h" #include "eive/objects.h" #include "fsfw_hal/linux/gpio/LinuxLibgpioIF.h" #include "linux/ObjectFactory.h" @@ -32,6 +33,7 @@ void ObjectFactory::produce(void* args) { #endif PersistentTmStores stores; + readFirmwareVersion(); ObjectFactory::produceGenericObjects(&healthTable, &pusFunnel, &cfdpFunnel, *SdCardManager::instance(), &ipcStore, &tmStore, stores, 200, true); @@ -67,7 +69,16 @@ void ObjectFactory::produce(void* args) { HeaterHandler* heaterHandler; createHeaterComponents(gpioComIF, pwrSwitcher, healthTable, heaterHandler); #if OBSW_ADD_TMP_DEVICES == 1 - createTmpComponents(); + std::vector> tmpDevsToAdd = {{ + {objects::TMP1075_HANDLER_TCS_0, addresses::TMP1075_TCS_0}, + {objects::TMP1075_HANDLER_TCS_1, addresses::TMP1075_TCS_1}, + {objects::TMP1075_HANDLER_PLPCDU_0, addresses::TMP1075_PLPCDU_0}, + // damaged + // {objects::TMP1075_HANDLER_PLPCDU_1, addresses::TMP1075_PLPCDU_1}, + {objects::TMP1075_HANDLER_IF_BOARD, addresses::TMP1075_IF_BOARD}, + }}; + + createTmpComponents(tmpDevsToAdd); #endif createSolarArrayDeploymentComponents(*pwrSwitcher, *gpioComIF); createPlPcduComponents(gpioComIF, spiMainComIF, pwrSwitcher, *stackHandler); @@ -77,13 +88,17 @@ void ObjectFactory::produce(void* args) { createRtdComponents(q7s::SPI_DEFAULT_DEV, gpioComIF, pwrSwitcher, spiMainComIF); createPayloadComponents(gpioComIF, *pwrSwitcher); + const char* battAndImtqI2cDev = q7s::I2C_PL_EIVE; + if (core::FW_VERSION_MAJOR >= 4) { + battAndImtqI2cDev = q7s::I2C_PS_EIVE; + } #if OBSW_ADD_MGT == 1 - createImtqComponents(pwrSwitcher, enableHkSets); + createImtqComponents(pwrSwitcher, enableHkSets, battAndImtqI2cDev); #endif createReactionWheelComponents(gpioComIF, pwrSwitcher); #if OBSW_ADD_BPX_BATTERY_HANDLER == 1 - createBpxBatteryComponent(enableHkSets); + createBpxBatteryComponent(enableHkSets, battAndImtqI2cDev); #endif #if OBSW_ADD_STAR_TRACKER == 1 @@ -113,7 +128,7 @@ void ObjectFactory::produce(void* args) { #endif /* OBSW_ADD_TEST_CODE == 1 */ createMiscComponents(); - createThermalController(*heaterHandler); + createThermalController(*heaterHandler, false); createAcsController(true, enableHkSets); - satsystem::init(); + satsystem::init(false); } diff --git a/bsp_q7s/core/ObjectFactory.cpp b/bsp_q7s/objectFactory.cpp similarity index 95% rename from bsp_q7s/core/ObjectFactory.cpp rename to bsp_q7s/objectFactory.cpp index 339b80e0..326ba8ef 100644 --- a/bsp_q7s/core/ObjectFactory.cpp +++ b/bsp_q7s/objectFactory.cpp @@ -1,8 +1,9 @@ -#include "ObjectFactory.h" +#include "objectFactory.h" #include #include #include +#include #include #include #include @@ -32,6 +33,9 @@ #include #include +#include +#include + #include "OBSWConfig.h" #include "bsp_q7s/boardtest/Q7STestTask.h" #include "bsp_q7s/callbacks/gnssCallback.h" @@ -100,6 +104,7 @@ #include +#include "bsp_q7s/core/defs.h" #include "fsfw/datapoollocal/LocalDataPoolManager.h" #include "fsfw/tmtcpacket/pus/tm.h" #include "fsfw/tmtcservices/CommandingServiceBase.h" @@ -130,6 +135,11 @@ ResetArgs RESET_ARGS_GNSS; std::atomic_bool LINK_STATE = CcsdsIpCoreHandler::LINK_DOWN; std::atomic_bool PTME_LOCKED = false; std::atomic_uint16_t I2C_FATAL_ERRORS = 0; +uint8_t core::FW_VERSION_MAJOR = 0; +uint8_t core::FW_VERSION_MINOR = 0; +uint8_t core::FW_VERSION_REVISION = 0; +bool core::FW_VERSION_HAS_SHA = false; +char core::FW_VERSION_GIT_SHA[4] = {}; void Factory::setStaticFrameworkObjectIds() { PusServiceBase::PUS_DISTRIBUTOR = objects::PUS_PACKET_DISTRIBUTOR; @@ -151,28 +161,23 @@ void Factory::setStaticFrameworkObjectIds() { void ObjectFactory::setStatics() { Factory::setStaticFrameworkObjectIds(); } -void ObjectFactory::createTmpComponents() { - std::vector> tmpDevIds = {{ - {objects::TMP1075_HANDLER_TCS_0, addresses::TMP1075_TCS_0}, - {objects::TMP1075_HANDLER_TCS_1, addresses::TMP1075_TCS_1}, - {objects::TMP1075_HANDLER_PLPCDU_0, addresses::TMP1075_PLPCDU_0}, - // damaged - // {objects::TMP1075_HANDLER_PLPCDU_1, addresses::TMP1075_PLPCDU_1}, - {objects::TMP1075_HANDLER_IF_BOARD, addresses::TMP1075_IF_BOARD}, - }}; +void ObjectFactory::createTmpComponents( + std::vector> tmpDevsToAdd) { + const char* tmpI2cDev = q7s::I2C_PS_EIVE; + if (core::FW_VERSION_MAJOR == 4) { + tmpI2cDev = q7s::I2C_PL_EIVE; + } else if (core::FW_VERSION_MAJOR >= 5) { + tmpI2cDev = q7s::I2C_Q7_EIVE; + } std::vector tmpDevCookies; - for (size_t idx = 0; idx < tmpDevIds.size(); idx++) { + for (size_t idx = 0; idx < tmpDevsToAdd.size(); idx++) { tmpDevCookies.push_back( - new I2cCookie(tmpDevIds[idx].second, TMP1075::MAX_REPLY_LENGTH, q7s::I2C_PS_EIVE)); + new I2cCookie(tmpDevsToAdd[idx].second, TMP1075::MAX_REPLY_LENGTH, tmpI2cDev)); auto* tmpDevHandler = - new Tmp1075Handler(tmpDevIds[idx].first, objects::I2C_COM_IF, tmpDevCookies[idx]); - tmpDevHandler->setCustomFdir(new TmpDevFdir(tmpDevIds[idx].first)); + new Tmp1075Handler(tmpDevsToAdd[idx].first, objects::I2C_COM_IF, tmpDevCookies[idx]); + tmpDevHandler->setCustomFdir(new TmpDevFdir(tmpDevsToAdd[idx].first)); tmpDevHandler->connectModeTreeParent(satsystem::tcs::SUBSYSTEM); - // TODO: Remove this after TCS subsystem was added - // These devices are connected to the 3V3 stack and should be powered permanently. Therefore, - // we set them to normal mode immediately here. - tmpDevHandler->setModeNormal(); } } @@ -945,12 +950,13 @@ void ObjectFactory::createStrComponents(PowerSwitchIF* pwrSwitcher) { starTracker->setCustomFdir(strFdir); } -void ObjectFactory::createImtqComponents(PowerSwitchIF* pwrSwitcher, bool enableHkSets) { +void ObjectFactory::createImtqComponents(PowerSwitchIF* pwrSwitcher, bool enableHkSets, + const char* i2cDev) { auto* imtqAssy = new ImtqAssembly(objects::IMTQ_ASSY); imtqAssy->connectModeTreeParent(satsystem::acs::ACS_SUBSYSTEM); new ImtqPollingTask(objects::IMTQ_POLLING, I2C_FATAL_ERRORS); - I2cCookie* imtqI2cCookie = new I2cCookie(addresses::IMTQ, imtq::MAX_REPLY_SIZE, q7s::I2C_PL_EIVE); + I2cCookie* imtqI2cCookie = new I2cCookie(addresses::IMTQ, imtq::MAX_REPLY_SIZE, i2cDev); auto imtqHandler = new ImtqHandler(objects::IMTQ_HANDLER, objects::IMTQ_POLLING, imtqI2cCookie, power::Switches::PDU1_CH3_MGT_5V, enableHkSets); imtqHandler->enableThermalModule(ThermalStateCfg()); @@ -966,8 +972,8 @@ void ObjectFactory::createImtqComponents(PowerSwitchIF* pwrSwitcher, bool enable #endif } -void ObjectFactory::createBpxBatteryComponent(bool enableHkSets) { - I2cCookie* bpxI2cCookie = new I2cCookie(addresses::BPX_BATTERY, 100, q7s::I2C_PL_EIVE); +void ObjectFactory::createBpxBatteryComponent(bool enableHkSets, const char* i2cDev) { + I2cCookie* bpxI2cCookie = new I2cCookie(addresses::BPX_BATTERY, 100, i2cDev); BpxBatteryHandler* bpxHandler = new BpxBatteryHandler( objects::BPX_BATT_HANDLER, objects::I2C_COM_IF, bpxI2cCookie, enableHkSets); bpxHandler->setStartUpImmediately(); @@ -1023,3 +1029,32 @@ void ObjectFactory::createPlI2cResetGpio(LinuxLibgpioIF* gpioIF) { gpioIF->pullHigh(gpioIds::PL_I2C_ARESETN); } } + +ReturnValue_t ObjectFactory::readFirmwareVersion() { + uint32_t* mappedSysRomAddr = nullptr; + // The SYS ROM FPGA block is only available in those versions. + if (not(common::OBSW_VERSION_MAJOR >= 6) or (common::OBSW_VERSION_MAJOR == 4)) { + return returnvalue::OK; + } + // This has to come before the version announce because it might be required for retrieving + // the firmware version. + UioMapper sysRomMapper(q7s::UIO_SYS_ROM); + ReturnValue_t result = + sysRomMapper.getMappedAdress(&mappedSysRomAddr, UioMapper::Permissions::READ_ONLY); + if (result != returnvalue::OK) { + sif::error << "Getting mapped SYS ROM UIO address failed" << std::endl; + return returnvalue::FAILED; + } + if (mappedSysRomAddr != nullptr) { + uint32_t firstEntry = *(reinterpret_cast(mappedSysRomAddr)); + uint32_t secondEntry = *(reinterpret_cast(mappedSysRomAddr) + 1); + core::FW_VERSION_MAJOR = (firstEntry >> 24) & 0xff; + core::FW_VERSION_MINOR = (firstEntry >> 16) & 0xff; + core::FW_VERSION_REVISION = (firstEntry >> 8) & 0xff; + bool hasGitSha = (firstEntry & 0x0b1); + if (hasGitSha) { + std::memcpy(core::FW_VERSION_GIT_SHA, &secondEntry, 4); + } + } + return returnvalue::OK; +} diff --git a/bsp_q7s/core/ObjectFactory.h b/bsp_q7s/objectFactory.h similarity index 93% rename from bsp_q7s/core/ObjectFactory.h rename to bsp_q7s/objectFactory.h index a2edec4c..491720ac 100644 --- a/bsp_q7s/core/ObjectFactory.h +++ b/bsp_q7s/objectFactory.h @@ -58,7 +58,7 @@ void createPcduComponents(LinuxLibgpioIF* gpioComIF, PowerSwitchIF** pwrSwitcher bool enableHkSets); void createPlPcduComponents(LinuxLibgpioIF* gpioComIF, SpiComIF* spiComIF, PowerSwitchIF* pwrSwitcher, Stack5VHandler& stackHandler); -void createTmpComponents(); +void createTmpComponents(std::vector> tmpDevsToAdd); void createRadSensorChipSelect(LinuxLibgpioIF* gpioIF); ReturnValue_t createRadSensorComponent(LinuxLibgpioIF* gpioComIF, Stack5VHandler& handler); void createAcsBoardGpios(GpioCookie& cookie); @@ -67,14 +67,15 @@ void createAcsBoardComponents(SpiComIF& spiComIF, LinuxLibgpioIF* gpioComIF, Ser adis1650x::Type adisType); void createHeaterComponents(GpioIF* gpioIF, PowerSwitchIF* pwrSwitcher, HealthTableIF* healthTable, HeaterHandler*& heaterHandler); -void createImtqComponents(PowerSwitchIF* pwrSwitcher, bool enableHkSets); -void createBpxBatteryComponent(bool enableHkSets); +void createImtqComponents(PowerSwitchIF* pwrSwitcher, bool enableHkSets, const char* i2cDev); +void createBpxBatteryComponent(bool enableHkSets, const char* i2cDev); void createStrComponents(PowerSwitchIF* pwrSwitcher); void createSolarArrayDeploymentComponents(PowerSwitchIF& pwrSwitcher, GpioIF& gpioIF); void createSyrlinksComponents(PowerSwitchIF* pwrSwitcher); void createPayloadComponents(LinuxLibgpioIF* gpioComIF, PowerSwitchIF& pwrSwitcher); void createReactionWheelComponents(LinuxLibgpioIF* gpioComIF, PowerSwitchIF* pwrSwitcher); ReturnValue_t createCcsdsComponents(CcsdsComponentArgs& args); +ReturnValue_t readFirmwareVersion(); void createMiscComponents(); void createTestComponents(LinuxLibgpioIF* gpioComIF); diff --git a/bsp_q7s/obsw.cpp b/bsp_q7s/obsw.cpp index dc547b03..fc49c369 100644 --- a/bsp_q7s/obsw.cpp +++ b/bsp_q7s/obsw.cpp @@ -11,13 +11,13 @@ #include "OBSWConfig.h" #include "bsp_q7s/core/WatchdogHandler.h" #include "commonConfig.h" -#include "core/scheduling.h" #include "fsfw/tasks/TaskFactory.h" #include "fsfw/version.h" #include "mission/acs/defs.h" #include "mission/com/defs.h" #include "mission/system/systemTree.h" #include "q7sConfig.h" +#include "scheduling.h" #include "watchdog/definitions.h" static constexpr int OBSW_ALREADY_RUNNING = -2; diff --git a/bsp_q7s/core/scheduling.cpp b/bsp_q7s/scheduling.cpp similarity index 98% rename from bsp_q7s/core/scheduling.cpp rename to bsp_q7s/scheduling.cpp index 60cffb98..4c853406 100644 --- a/bsp_q7s/core/scheduling.cpp +++ b/bsp_q7s/scheduling.cpp @@ -9,7 +9,6 @@ #include #include "OBSWConfig.h" -#include "bsp_q7s/core/ObjectFactory.h" #include "fsfw/objectmanager/ObjectManager.h" #include "fsfw/objectmanager/ObjectManagerIF.h" #include "fsfw/platform.h" @@ -21,6 +20,8 @@ #include "mission/pollingSeqTables.h" #include "mission/scheduling.h" #include "mission/utility/InitMission.h" +#include "objectFactory.h" +#include "q7sConfig.h" /* This is configured for linux without CR */ #ifdef PLATFORM_UNIX @@ -532,7 +533,15 @@ void scheduling::createPstTasks(TaskFactory& factory, TaskDeadlineMissedFunction FixedTimeslotTaskIF* i2cPst = factory.createFixedTimeslotTask("I2C_PS_PST", 60, PeriodicTaskIF::MINIMUM_STACK_SIZE * 4, 0.6, missedDeadlineFunc, &RR_SCHEDULING); - result = pst::pstI2cProcessingSystem(i2cPst); + pst::TmpSchedConfig tmpSchedConf; +#if OBSW_Q7S_EM == 1 + tmpSchedConf.scheduleTmpDev0 = true; + tmpSchedConf.scheduleTmpDev1 = true; + tmpSchedConf.schedulePlPcduDev0 = true; + tmpSchedConf.schedulePlPcduDev1 = true; + tmpSchedConf.scheduleIfBoardDev = true; +#endif + result = pst::pstI2c(tmpSchedConf, i2cPst); if (result != returnvalue::OK) { if (result == FixedTimeslotTaskIF::SLOT_LIST_EMPTY) { sif::warning << "scheduling::initTasks: I2C PST is empty" << std::endl; diff --git a/bsp_q7s/core/scheduling.h b/bsp_q7s/scheduling.h similarity index 100% rename from bsp_q7s/core/scheduling.h rename to bsp_q7s/scheduling.h diff --git a/bsp_q7s/xadc/Xadc.cpp b/bsp_q7s/xadc/Xadc.cpp index 34a4e159..da3fbf7f 100644 --- a/bsp_q7s/xadc/Xadc.cpp +++ b/bsp_q7s/xadc/Xadc.cpp @@ -129,7 +129,7 @@ ReturnValue_t Xadc::readValFromFile(const char* filename, T& val) { sif::warning << "Xadc::readValFromFile: Failed to open file " << filename << std::endl; return returnvalue::FAILED; } - char valstring[MAX_STR_LENGTH] = ""; + char valstring[MAX_STR_LENGTH]{}; char* returnVal = fgets(valstring, MAX_STR_LENGTH, fp); if (returnVal == nullptr) { sif::warning << "Xadc::readValFromFile: Failed to read string from file " << filename @@ -139,6 +139,11 @@ ReturnValue_t Xadc::readValFromFile(const char* filename, T& val) { } std::istringstream valSstream(valstring); valSstream >> val; + if (valSstream.bad()) { + sif::warning << "Xadc: Conversion of value to target type failed" << std::endl; + fclose(fp); + return returnvalue::FAILED; + } fclose(fp); return returnvalue::OK; } diff --git a/dummies/CoreControllerDummy.cpp b/dummies/CoreControllerDummy.cpp index 8a027dbf..df2bef03 100644 --- a/dummies/CoreControllerDummy.cpp +++ b/dummies/CoreControllerDummy.cpp @@ -1,6 +1,6 @@ #include "CoreControllerDummy.h" -#include +#include #include #include diff --git a/dummies/Max31865Dummy.cpp b/dummies/Max31865Dummy.cpp index 6ec1a716..99fc336a 100644 --- a/dummies/Max31865Dummy.cpp +++ b/dummies/Max31865Dummy.cpp @@ -7,15 +7,21 @@ using namespace returnvalue; Max31865Dummy::Max31865Dummy(object_id_t objectId, object_id_t comif, CookieIF *comCookie) : DeviceHandlerBase(objectId, comif, comCookie), set(this, EiveMax31855::EXCHANGE_SET_ID) {} void Max31865Dummy::doStartUp() { setMode(MODE_ON); } -void Max31865Dummy::doShutDown() { setMode(_MODE_POWER_DOWN); } +void Max31865Dummy::doShutDown() { + PoolReadGuard pg(&set); + set.setValidity(false, true); + setMode(MODE_OFF); +} ReturnValue_t Max31865Dummy::buildNormalDeviceCommand(DeviceCommandId_t *id) { return NOTHING_TO_SEND; } -ReturnValue_t Max31865Dummy::buildTransitionDeviceCommand(DeviceCommandId_t *id) { return OK; } +ReturnValue_t Max31865Dummy::buildTransitionDeviceCommand(DeviceCommandId_t *id) { + return NOTHING_TO_SEND; +} ReturnValue_t Max31865Dummy::buildCommandFromCommand(DeviceCommandId_t deviceCommand, const uint8_t *commandData, size_t commandDataLen) { - return 0; + return NOTHING_TO_SEND; } ReturnValue_t Max31865Dummy::scanForReply(const uint8_t *start, size_t len, DeviceCommandId_t *foundId, size_t *foundLen) { diff --git a/dummies/TemperatureSensorInserter.cpp b/dummies/TemperatureSensorInserter.cpp index 5c89d258..942231f5 100644 --- a/dummies/TemperatureSensorInserter.cpp +++ b/dummies/TemperatureSensorInserter.cpp @@ -7,9 +7,9 @@ #include #include -TemperatureSensorInserter::TemperatureSensorInserter(object_id_t objectId, - Max31865DummyMap tempSensorDummies_, - Tmp1075DummyMap tempTmpSensorDummies_) +TemperatureSensorInserter::TemperatureSensorInserter( + object_id_t objectId, Max31865DummyMap tempSensorDummies_, + std::optional tempTmpSensorDummies_) : SystemObject(objectId), max31865DummyMap(std::move(tempSensorDummies_)), tmp1075DummyMap(std::move(tempTmpSensorDummies_)) {} @@ -25,8 +25,10 @@ ReturnValue_t TemperatureSensorInserter::performOperation(uint8_t opCode) { for (auto& rtdDummy : max31865DummyMap) { rtdDummy.second->setTemperature(10, true); } - for (auto& tmpDummy : tmp1075DummyMap) { - tmpDummy.second->setTemperature(10, true); + if (tmp1075DummyMap.has_value()) { + for (auto& tmpDummy : tmp1075DummyMap.value()) { + tmpDummy.second->setTemperature(10, true); + } } tempsWereInitialized = true; } @@ -124,6 +126,21 @@ ReturnValue_t TemperatureSensorInserter::performOperation(uint8_t opCode) { sif::debug << "Setting CAM temperature back to normal" << std::endl; max31865DummyMap[objects::RTD_2_IC5_4K_CAMERA]->setTemperature(0, true); } + break; + } + case (TestCase::COLD_PLOC_STAYS_COLD): { + if (cycles == 15) { + sif::debug << "Setting cold PLOC temperature" << std::endl; + max31865DummyMap[objects::RTD_0_IC3_PLOC_HEATSPREADER]->setTemperature(-40, true); + } + break; + } + case (TestCase::COLD_CAMERA_STAYS_COLD): { + if (cycles == 15) { + sif::debug << "Setting cold PLOC temperature" << std::endl; + max31865DummyMap[objects::RTD_2_IC5_4K_CAMERA]->setTemperature(-40, true); + } + break; } } cycles++; diff --git a/dummies/TemperatureSensorInserter.h b/dummies/TemperatureSensorInserter.h index 009f5b7d..9ca3c936 100644 --- a/dummies/TemperatureSensorInserter.h +++ b/dummies/TemperatureSensorInserter.h @@ -12,7 +12,7 @@ class TemperatureSensorInserter : public ExecutableObjectIF, public SystemObject using Max31865DummyMap = std::map; using Tmp1075DummyMap = std::map; explicit TemperatureSensorInserter(object_id_t objectId, Max31865DummyMap tempSensorDummies_, - Tmp1075DummyMap tempTmpSensorDummies_); + std::optional tempTmpSensorDummies_); ReturnValue_t initialize() override; ReturnValue_t initializeAfterTaskCreation() override; @@ -22,7 +22,7 @@ class TemperatureSensorInserter : public ExecutableObjectIF, public SystemObject private: Max31865DummyMap max31865DummyMap; - Tmp1075DummyMap tmp1075DummyMap; + std::optional tmp1075DummyMap; enum TestCase { NONE = 0, @@ -33,6 +33,8 @@ class TemperatureSensorInserter : public ExecutableObjectIF, public SystemObject COLD_STR_CONSECUTIVE = 5, COLD_CAMERA = 6, COLD_PLOC_CONSECUTIVE = 7, + COLD_PLOC_STAYS_COLD = 8, + COLD_CAMERA_STAYS_COLD = 9 }; int iteration = 0; uint32_t cycles = 0; diff --git a/dummies/Tmp1075Dummy.cpp b/dummies/Tmp1075Dummy.cpp index 91a50774..7e61acef 100644 --- a/dummies/Tmp1075Dummy.cpp +++ b/dummies/Tmp1075Dummy.cpp @@ -8,35 +8,57 @@ using namespace returnvalue; Tmp1075Dummy::Tmp1075Dummy(object_id_t objectId, object_id_t comif, CookieIF *comCookie) : DeviceHandlerBase(objectId, comif, comCookie), set(this) {} -void Tmp1075Dummy::doStartUp() { setMode(MODE_NORMAL); } -void Tmp1075Dummy::doShutDown() { setMode(MODE_OFF); } +void Tmp1075Dummy::doStartUp() { setMode(MODE_ON); } +void Tmp1075Dummy::doShutDown() { + PoolReadGuard pg(&set); + set.setValidity(false, true); + setMode(MODE_OFF); +} ReturnValue_t Tmp1075Dummy::buildNormalDeviceCommand(DeviceCommandId_t *id) { return NOTHING_TO_SEND; } -ReturnValue_t Tmp1075Dummy::buildTransitionDeviceCommand(DeviceCommandId_t *id) { return OK; } + +ReturnValue_t Tmp1075Dummy::buildTransitionDeviceCommand(DeviceCommandId_t *id) { + return NOTHING_TO_SEND; +} + ReturnValue_t Tmp1075Dummy::buildCommandFromCommand(DeviceCommandId_t deviceCommand, const uint8_t *commandData, size_t commandDataLen) { - return 0; + return NOTHING_TO_SEND; } + ReturnValue_t Tmp1075Dummy::scanForReply(const uint8_t *start, size_t len, DeviceCommandId_t *foundId, size_t *foundLen) { return 0; } + ReturnValue_t Tmp1075Dummy::interpretDeviceReply(DeviceCommandId_t id, const uint8_t *packet) { return 0; } + void Tmp1075Dummy::setTemperature(float temperature, bool valid) { PoolReadGuard pg(&set); set.temperatureCelcius.value = temperature; set.setValidity(valid, true); } + void Tmp1075Dummy::fillCommandAndReplyMap() {} + uint32_t Tmp1075Dummy::getTransitionDelayMs(Mode_t modeFrom, Mode_t modeTo) { return 1000; } + ReturnValue_t Tmp1075Dummy::initializeLocalDataPool(localpool::DataPool &localDataPoolMap, LocalDataPoolManager &poolManager) { localDataPoolMap.emplace(TMP1075::TEMPERATURE_C_TMP1075, new PoolEntry({10.0}, true)); return OK; } + +ReturnValue_t Tmp1075Dummy::setHealth(HealthState health) { + if (health == FAULTY or health == PERMANENT_FAULTY) { + setMode(_MODE_SHUT_DOWN); + } + return DeviceHandlerBase::setHealth(health); +} + LocalPoolDataSetBase *Tmp1075Dummy::getDataSetHandle(sid_t sid) { return &set; } diff --git a/dummies/Tmp1075Dummy.h b/dummies/Tmp1075Dummy.h index 570fcd42..feab4f98 100644 --- a/dummies/Tmp1075Dummy.h +++ b/dummies/Tmp1075Dummy.h @@ -26,6 +26,7 @@ class Tmp1075Dummy : public DeviceHandlerBase { uint32_t getTransitionDelayMs(Mode_t modeFrom, Mode_t modeTo) override; ReturnValue_t initializeLocalDataPool(localpool::DataPool &localDataPoolMap, LocalDataPoolManager &poolManager) override; + ReturnValue_t setHealth(HealthState health) override; protected: LocalPoolDataSetBase *getDataSetHandle(sid_t sid) override; diff --git a/dummies/helperFactory.cpp b/dummies/helperFactory.cpp index 398fc4bd..e085dae0 100644 --- a/dummies/helperFactory.cpp +++ b/dummies/helperFactory.cpp @@ -194,25 +194,36 @@ void dummy::createDummies(DummyCfg cfg, PowerSwitchIF& pwrSwitcher, GpioIF* gpio objects::RTD_15_IC18_IMTQ, new Max31865Dummy(objects::RTD_15_IC18_IMTQ, objects::DUMMY_COM_IF, comCookieDummy)); - std::map tmpSensorDummies; - tmpSensorDummies.emplace( - objects::TMP1075_HANDLER_TCS_0, - new Tmp1075Dummy(objects::TMP1075_HANDLER_TCS_0, objects::DUMMY_COM_IF, comCookieDummy)); - tmpSensorDummies.emplace( - objects::TMP1075_HANDLER_TCS_1, - new Tmp1075Dummy(objects::TMP1075_HANDLER_TCS_1, objects::DUMMY_COM_IF, comCookieDummy)); - tmpSensorDummies.emplace( - objects::TMP1075_HANDLER_PLPCDU_0, - new Tmp1075Dummy(objects::TMP1075_HANDLER_PLPCDU_0, objects::DUMMY_COM_IF, comCookieDummy)); - // damaged. - // tmpSensorDummies.emplace( - // objects::TMP1075_HANDLER_PLPCDU_1, - // new Tmp1075Dummy(objects::TMP1075_HANDLER_PLPCDU_1, objects::DUMMY_COM_IF, - // comCookieDummy)); - tmpSensorDummies.emplace( - objects::TMP1075_HANDLER_IF_BOARD, - new Tmp1075Dummy(objects::TMP1075_HANDLER_IF_BOARD, objects::DUMMY_COM_IF, comCookieDummy)); - + std::optional tmpSensorDummies; + if (cfg.addTmpDummies) { + TemperatureSensorInserter::Tmp1075DummyMap tmpDummyMap; + if (cfg.tmp1075Cfg.addTcsBrd0) { + tmpDummyMap.emplace(objects::TMP1075_HANDLER_TCS_0, + new Tmp1075Dummy(objects::TMP1075_HANDLER_TCS_0, objects::DUMMY_COM_IF, + comCookieDummy)); + } + if (cfg.tmp1075Cfg.addTcsBrd1) { + tmpDummyMap.emplace(objects::TMP1075_HANDLER_TCS_1, + new Tmp1075Dummy(objects::TMP1075_HANDLER_TCS_1, objects::DUMMY_COM_IF, + comCookieDummy)); + } + if (cfg.tmp1075Cfg.addPlPcdu0) { + tmpDummyMap.emplace(objects::TMP1075_HANDLER_PLPCDU_0, + new Tmp1075Dummy(objects::TMP1075_HANDLER_PLPCDU_0, + objects::DUMMY_COM_IF, comCookieDummy)); + } + if (cfg.tmp1075Cfg.addPlPcdu1) { + tmpDummyMap.emplace(objects::TMP1075_HANDLER_PLPCDU_1, + new Tmp1075Dummy(objects::TMP1075_HANDLER_PLPCDU_1, + objects::DUMMY_COM_IF, comCookieDummy)); + } + if (cfg.tmp1075Cfg.addIfBrd) { + tmpDummyMap.emplace(objects::TMP1075_HANDLER_IF_BOARD, + new Tmp1075Dummy(objects::TMP1075_HANDLER_IF_BOARD, + objects::DUMMY_COM_IF, comCookieDummy)); + } + tmpSensorDummies = std::move(tmpDummyMap); + } new TemperatureSensorInserter(objects::THERMAL_TEMP_INSERTER, rtdSensorDummies, tmpSensorDummies); TcsBoardAssembly* tcsBoardAssy = @@ -220,8 +231,10 @@ void dummy::createDummies(DummyCfg cfg, PowerSwitchIF& pwrSwitcher, GpioIF* gpio for (auto& rtd : rtdSensorDummies) { rtd.second->connectModeTreeParent(*tcsBoardAssy); } - for (auto& tmp : tmpSensorDummies) { - tmp.second->connectModeTreeParent(satsystem::tcs::SUBSYSTEM); + if (tmpSensorDummies.has_value()) { + for (auto& tmp : tmpSensorDummies.value()) { + tmp.second->connectModeTreeParent(satsystem::tcs::SUBSYSTEM); + } } } if (cfg.addCamSwitcherDummy) { diff --git a/dummies/helperFactory.h b/dummies/helperFactory.h index 5466e809..fb272bb8 100644 --- a/dummies/helperFactory.h +++ b/dummies/helperFactory.h @@ -6,6 +6,14 @@ class GpioIF; namespace dummy { +struct Tmp1075Cfg { + bool addTcsBrd0 = true; + bool addTcsBrd1 = true; + bool addPlPcdu0 = true; + bool addPlPcdu1 = true; + bool addIfBrd = true; +}; + // Default values targeted towards EM. struct DummyCfg { bool addCoreCtrlCfg = true; @@ -20,6 +28,8 @@ struct DummyCfg { bool addRtdComIFDummy = true; bool addPlocDummies = true; bool addStrDummy = true; + bool addTmpDummies = true; + Tmp1075Cfg tmp1075Cfg; bool addCamSwitcherDummy = false; }; diff --git a/fsfw b/fsfw index 8da89eba..88e86652 160000 --- a/fsfw +++ b/fsfw @@ -1 +1 @@ -Subproject commit 8da89eba80f73cb05e5c38fc012456f1d9569af5 +Subproject commit 88e8665280a0381c41b724ab035a8c3eff1a23c1 diff --git a/generators/bsp_hosted_events.csv b/generators/bsp_hosted_events.csv index 17592d1d..3f1bbb77 100644 --- a/generators/bsp_hosted_events.csv +++ b/generators/bsp_hosted_events.csv @@ -280,6 +280,9 @@ Event ID (dec); Event ID (hex); Name; Severity; Description; File Path 14106;0x371a;PCDU_SYSTEM_OVERHEATING;HIGH;No description;mission/controller/tcsDefs.h 14107;0x371b;HEATER_NOT_OFF_FOR_OFF_MODE;MEDIUM;No description;mission/controller/tcsDefs.h 14108;0x371c;MGT_OVERHEATING;HIGH;No description;mission/controller/tcsDefs.h +14109;0x371d;TCS_SWITCHING_HEATER_ON;INFO;P1: Module index. P2: Heater index;mission/controller/tcsDefs.h +14110;0x371e;TCS_SWITCHING_HEATER_OFF;INFO;P1: Module index. P2: Heater index;mission/controller/tcsDefs.h +14111;0x371f;TCS_HEATER_MAX_BURN_TIME_REACHED;MEDIUM;P1: Heater index. P2: Maximum burn time for heater.;mission/controller/tcsDefs.h 14201;0x3779;TX_TIMER_EXPIRED;INFO;The transmit timer to protect the Syrlinks expired P1: The current timer value;mission/system/com/ComSubsystem.h 14202;0x377a;BIT_LOCK_TX_ON;INFO;Transmitter will be turned on due to detection of bitlock;mission/system/com/ComSubsystem.h 14300;0x37dc;POSSIBLE_FILE_CORRUPTION;LOW;P1: Result code of TM packet parser. P2: Timestamp of possibly corrupt file as a unix timestamp.;mission/persistentTmStoreDefs.h diff --git a/generators/bsp_q7s_events.csv b/generators/bsp_q7s_events.csv index 17592d1d..3f1bbb77 100644 --- a/generators/bsp_q7s_events.csv +++ b/generators/bsp_q7s_events.csv @@ -280,6 +280,9 @@ Event ID (dec); Event ID (hex); Name; Severity; Description; File Path 14106;0x371a;PCDU_SYSTEM_OVERHEATING;HIGH;No description;mission/controller/tcsDefs.h 14107;0x371b;HEATER_NOT_OFF_FOR_OFF_MODE;MEDIUM;No description;mission/controller/tcsDefs.h 14108;0x371c;MGT_OVERHEATING;HIGH;No description;mission/controller/tcsDefs.h +14109;0x371d;TCS_SWITCHING_HEATER_ON;INFO;P1: Module index. P2: Heater index;mission/controller/tcsDefs.h +14110;0x371e;TCS_SWITCHING_HEATER_OFF;INFO;P1: Module index. P2: Heater index;mission/controller/tcsDefs.h +14111;0x371f;TCS_HEATER_MAX_BURN_TIME_REACHED;MEDIUM;P1: Heater index. P2: Maximum burn time for heater.;mission/controller/tcsDefs.h 14201;0x3779;TX_TIMER_EXPIRED;INFO;The transmit timer to protect the Syrlinks expired P1: The current timer value;mission/system/com/ComSubsystem.h 14202;0x377a;BIT_LOCK_TX_ON;INFO;Transmitter will be turned on due to detection of bitlock;mission/system/com/ComSubsystem.h 14300;0x37dc;POSSIBLE_FILE_CORRUPTION;LOW;P1: Result code of TM packet parser. P2: Timestamp of possibly corrupt file as a unix timestamp.;mission/persistentTmStoreDefs.h diff --git a/generators/events/translateEvents.cpp b/generators/events/translateEvents.cpp index 1500301f..b98926e5 100644 --- a/generators/events/translateEvents.cpp +++ b/generators/events/translateEvents.cpp @@ -1,7 +1,7 @@ /** - * @brief Auto-generated event translation file. Contains 296 translations. + * @brief Auto-generated event translation file. Contains 299 translations. * @details - * Generated on: 2023-06-21 19:01:02 + * Generated on: 2023-07-07 12:06:06 */ #include "translateEvents.h" @@ -286,6 +286,9 @@ const char *CAMERA_OVERHEATING_STRING = "CAMERA_OVERHEATING"; const char *PCDU_SYSTEM_OVERHEATING_STRING = "PCDU_SYSTEM_OVERHEATING"; const char *HEATER_NOT_OFF_FOR_OFF_MODE_STRING = "HEATER_NOT_OFF_FOR_OFF_MODE"; const char *MGT_OVERHEATING_STRING = "MGT_OVERHEATING"; +const char *TCS_SWITCHING_HEATER_ON_STRING = "TCS_SWITCHING_HEATER_ON"; +const char *TCS_SWITCHING_HEATER_OFF_STRING = "TCS_SWITCHING_HEATER_OFF"; +const char *TCS_HEATER_MAX_BURN_TIME_REACHED_STRING = "TCS_HEATER_MAX_BURN_TIME_REACHED"; const char *TX_TIMER_EXPIRED_STRING = "TX_TIMER_EXPIRED"; const char *BIT_LOCK_TX_ON_STRING = "BIT_LOCK_TX_ON"; const char *POSSIBLE_FILE_CORRUPTION_STRING = "POSSIBLE_FILE_CORRUPTION"; @@ -866,6 +869,12 @@ const char *translateEvents(Event event) { return HEATER_NOT_OFF_FOR_OFF_MODE_STRING; case (14108): return MGT_OVERHEATING_STRING; + case (14109): + return TCS_SWITCHING_HEATER_ON_STRING; + case (14110): + return TCS_SWITCHING_HEATER_OFF_STRING; + case (14111): + return TCS_HEATER_MAX_BURN_TIME_REACHED_STRING; case (14201): return TX_TIMER_EXPIRED_STRING; case (14202): diff --git a/generators/objects/translateObjects.cpp b/generators/objects/translateObjects.cpp index 1ecd5e71..5a9af4d7 100644 --- a/generators/objects/translateObjects.cpp +++ b/generators/objects/translateObjects.cpp @@ -2,7 +2,7 @@ * @brief Auto-generated object translation file. * @details * Contains 175 translations. - * Generated on: 2023-06-21 19:01:02 + * Generated on: 2023-07-07 12:06:06 */ #include "translateObjects.h" diff --git a/linux/fsfwconfig/events/translateEvents.cpp b/linux/fsfwconfig/events/translateEvents.cpp index 1500301f..b98926e5 100644 --- a/linux/fsfwconfig/events/translateEvents.cpp +++ b/linux/fsfwconfig/events/translateEvents.cpp @@ -1,7 +1,7 @@ /** - * @brief Auto-generated event translation file. Contains 296 translations. + * @brief Auto-generated event translation file. Contains 299 translations. * @details - * Generated on: 2023-06-21 19:01:02 + * Generated on: 2023-07-07 12:06:06 */ #include "translateEvents.h" @@ -286,6 +286,9 @@ const char *CAMERA_OVERHEATING_STRING = "CAMERA_OVERHEATING"; const char *PCDU_SYSTEM_OVERHEATING_STRING = "PCDU_SYSTEM_OVERHEATING"; const char *HEATER_NOT_OFF_FOR_OFF_MODE_STRING = "HEATER_NOT_OFF_FOR_OFF_MODE"; const char *MGT_OVERHEATING_STRING = "MGT_OVERHEATING"; +const char *TCS_SWITCHING_HEATER_ON_STRING = "TCS_SWITCHING_HEATER_ON"; +const char *TCS_SWITCHING_HEATER_OFF_STRING = "TCS_SWITCHING_HEATER_OFF"; +const char *TCS_HEATER_MAX_BURN_TIME_REACHED_STRING = "TCS_HEATER_MAX_BURN_TIME_REACHED"; const char *TX_TIMER_EXPIRED_STRING = "TX_TIMER_EXPIRED"; const char *BIT_LOCK_TX_ON_STRING = "BIT_LOCK_TX_ON"; const char *POSSIBLE_FILE_CORRUPTION_STRING = "POSSIBLE_FILE_CORRUPTION"; @@ -866,6 +869,12 @@ const char *translateEvents(Event event) { return HEATER_NOT_OFF_FOR_OFF_MODE_STRING; case (14108): return MGT_OVERHEATING_STRING; + case (14109): + return TCS_SWITCHING_HEATER_ON_STRING; + case (14110): + return TCS_SWITCHING_HEATER_OFF_STRING; + case (14111): + return TCS_HEATER_MAX_BURN_TIME_REACHED_STRING; case (14201): return TX_TIMER_EXPIRED_STRING; case (14202): diff --git a/linux/fsfwconfig/objects/translateObjects.cpp b/linux/fsfwconfig/objects/translateObjects.cpp index 1ecd5e71..5a9af4d7 100644 --- a/linux/fsfwconfig/objects/translateObjects.cpp +++ b/linux/fsfwconfig/objects/translateObjects.cpp @@ -2,7 +2,7 @@ * @brief Auto-generated object translation file. * @details * Contains 175 translations. - * Generated on: 2023-06-21 19:01:02 + * Generated on: 2023-07-07 12:06:06 */ #include "translateObjects.h" diff --git a/linux/ipcore/PapbVcInterface.cpp b/linux/ipcore/PapbVcInterface.cpp index 404f3653..5dcb4519 100644 --- a/linux/ipcore/PapbVcInterface.cpp +++ b/linux/ipcore/PapbVcInterface.cpp @@ -33,10 +33,21 @@ ReturnValue_t PapbVcInterface::write(const uint8_t* data, size_t size) { } else { return DirectTmSinkIF::IS_BUSY; } + if (not pollReadyForOctet(MAX_BUSY_POLLS)) { + abortPacketTransfer(); + return returnvalue::FAILED; + } for (size_t idx = 0; idx < size; idx++) { - // if (pollInterfaceReadiness(2, false) == returnvalue::OK) { + if (not pollReadyForOctet(MAX_BUSY_POLLS)) { + abortPacketTransfer(); + return returnvalue::FAILED; + } *(vcBaseReg + DATA_REG_OFFSET) = static_cast(data[idx]); } + if (not pollReadyForOctet(MAX_BUSY_POLLS)) { + abortPacketTransfer(); + return returnvalue::FAILED; + } completePacketTransfer(); return returnvalue::OK; } @@ -51,7 +62,6 @@ bool PapbVcInterface::pollReadyForPacket() const { // Check if PAPB interface is ready to receive data. Use the configuration register for this. // Bit 5, see PTME ptme_001_01-0-7-r2 Table 31. uint32_t reg = *vcBaseReg; - // bool busy = (reg >> 5) & 0b1; return (reg >> 6) & 0b1; } @@ -77,6 +87,20 @@ bool PapbVcInterface::isBusy() const { return not pollReadyForPacket(); } void PapbVcInterface::cancelTransfer() { abortPacketTransfer(); } +inline bool PapbVcInterface::pollReadyForOctet(uint32_t maxCycles) const { + uint32_t reg; + uint32_t idx = 0; + while (idx < maxCycles) { + reg = *vcBaseReg; + // Busy bit. + if (not((reg >> 5) & 0b1)) { + return true; + } + idx++; + } + return false; +} + ReturnValue_t PapbVcInterface::sendTestFrame() { /** Size of one complete transfer frame data field amounts to 1105 bytes */ uint8_t testPacket[1105]; diff --git a/linux/ipcore/PapbVcInterface.h b/linux/ipcore/PapbVcInterface.h index ba6063b5..b5160748 100644 --- a/linux/ipcore/PapbVcInterface.h +++ b/linux/ipcore/PapbVcInterface.h @@ -80,6 +80,7 @@ class PapbVcInterface : public VirtualChannelIF { static constexpr long int FIRST_DELAY_PAPB_POLLING_NS = 10; static constexpr long int MAX_DELAY_PAPB_POLLING_NS = 40; + static constexpr uint32_t MAX_BUSY_POLLS = 1000; LinuxLibgpioIF* gpioComIF = nullptr; /** High when external buffer memory of virtual channel is empty */ @@ -118,6 +119,8 @@ class PapbVcInterface : public VirtualChannelIF { */ inline bool pollReadyForPacket() const; + inline bool pollReadyForOctet(uint32_t maxCycles) const; + /** * @brief This function can be used for debugging to check whether there are packets in * the packet buffer of the virtual channel or not. diff --git a/mission/com/LiveTmTask.cpp b/mission/com/LiveTmTask.cpp index d09c6ced..39648c15 100644 --- a/mission/com/LiveTmTask.cpp +++ b/mission/com/LiveTmTask.cpp @@ -19,13 +19,8 @@ LiveTmTask::LiveTmTask(object_id_t objectId, PusTmFunnel& pusFunnel, CfdpTmFunne ReturnValue_t LiveTmTask::performOperation(uint8_t opCode) { readCommandQueue(); while (true) { - bool performWriteOp = true; - if (mode == MODE_OFF or ptmeLocked) { - performWriteOp = false; - } - // The funnel tasks are scheduled here directly as well. - ReturnValue_t result = channel.handleNextTm(performWriteOp); + ReturnValue_t result = channel.handleNextTm(!ptmeLocked); if (result == DirectTmSinkIF::IS_BUSY) { sif::error << "Lost live TM, PAPB busy" << std::endl; } diff --git a/mission/controller/ThermalController.cpp b/mission/controller/ThermalController.cpp index 53babbd5..5f2277a9 100644 --- a/mission/controller/ThermalController.cpp +++ b/mission/controller/ThermalController.cpp @@ -1,6 +1,6 @@ #include "ThermalController.h" -#include +#include #include #include #include @@ -24,13 +24,16 @@ #define LOWER_RW_UPPER_LIMITS 0 ThermalController::ThermalController(object_id_t objectId, HeaterHandler& heater, - const std::atomic_bool& tcsBoardShortUnavailable) + const std::atomic_bool& tcsBoardShortUnavailable, + bool pollPcdu1Tmp) : ExtendedControllerBase(objectId), heaterHandler(heater), + pollPcdu1Tmp(pollPcdu1Tmp), sensorTemperatures(this), susTemperatures(this), deviceTemperatures(this), heaterInfo(this), + tcsCtrlInfo(this), imtqThermalSet(objects::IMTQ_HANDLER, ThermalStateCfg()), maxSet0PlocHspd(objects::RTD_0_IC3_PLOC_HEATSPREADER, EiveMax31855::RtdCommands::EXCHANGE_SET_ID), @@ -55,8 +58,6 @@ ThermalController::ThermalController(object_id_t objectId, HeaterHandler& heater tmp1075SetTcs0(objects::TMP1075_HANDLER_TCS_0), tmp1075SetTcs1(objects::TMP1075_HANDLER_TCS_1), tmp1075SetPlPcdu0(objects::TMP1075_HANDLER_PLPCDU_0), - // damaged - // tmp1075SetPlPcdu1(objects::TMP1075_HANDLER_PLPCDU_1), tmp1075SetIfBoard(objects::TMP1075_HANDLER_IF_BOARD), susSet0(objects::SUS_0_N_LOC_XFYFZM_PT_XF), susSet1(objects::SUS_1_N_LOC_XBYFZM_PT_XB), @@ -71,6 +72,9 @@ ThermalController::ThermalController(object_id_t objectId, HeaterHandler& heater susSet10(objects::SUS_10_N_LOC_XMYBZF_PT_ZF), susSet11(objects::SUS_11_R_LOC_XBYMZB_PT_ZB), tcsBrdShortlyUnavailable(tcsBoardShortUnavailable) { + if (pollPcdu1Tmp) { + tmp1075SetPlPcdu1 = new TMP1075::Tmp1075Dataset(objects::TMP1075_HANDLER_PLPCDU_1); + } resetSensorsArray(); } @@ -171,7 +175,7 @@ void ThermalController::performControlOperation() { } } - HeaterSwitchStates heaterSwitchStateArray{}; + tcsCtrl::HeaterSwitchStates heaterSwitchStateArray{}; heaterHandler.getAllSwitchStates(heaterSwitchStateArray); { PoolReadGuard pg(&heaterInfo); @@ -188,12 +192,11 @@ void ThermalController::performControlOperation() { if (transitionWhenHeatersOff) { bool allSwitchersOff = true; for (size_t idx = 0; idx < heaterSwitchStateArray.size(); idx++) { - if (heaterSwitchStateArray[idx] != HeaterHandler::SwitchState::OFF) { + if (heaterSwitchStateArray[idx] != heater::SwitchState::OFF) { allSwitchersOff = false; // if heater still ON after 3 cycles, switch OFF again if (transitionWhenHeatersOffCycles == 3) { - heaterHandler.switchHeater(static_cast(idx), - HeaterHandler::SwitchState::OFF); + heaterHandler.switchHeater(static_cast(idx), heater::SwitchState::OFF); triggerEvent(tcsCtrl::HEATER_NOT_OFF_FOR_OFF_MODE); } } @@ -206,8 +209,21 @@ void ThermalController::performControlOperation() { } else { transitionWhenHeatersOffCycles++; } - } else if (mode != MODE_OFF and not tcsBrdShortlyUnavailable) { - performThermalModuleCtrl(heaterSwitchStateArray); + } else if (mode != MODE_OFF) { + if (not tcsBrdShortlyUnavailable) { + performThermalModuleCtrl(heaterSwitchStateArray); + } + heaterTransitionControl(heaterSwitchStateArray); + heaterMaxDurationControl(heaterSwitchStateArray); + // This dataset makes the TCS CTRL observable. + PoolReadGuard pg(&tcsCtrlInfo); + for (uint8_t i = 0; i < thermalStates.size(); i++) { + tcsCtrlInfo.heatingOnVec[i] = thermalStates[i].heating; + tcsCtrlInfo.sensorIdxUsedForTcsCtrl[i] = thermalStates[i].sensorIndex; + tcsCtrlInfo.heaterSwitchIdx[i] = thermalStates[i].heaterSwitch; + tcsCtrlInfo.heaterStartTimes[i] = thermalStates[i].heaterStartTime; + tcsCtrlInfo.heaterEndTimes[i] = thermalStates[i].heaterEndTime; + } } } @@ -277,6 +293,11 @@ ReturnValue_t ThermalController::initializeLocalDataPool(localpool::DataPool& lo localDataPoolMap.emplace(tcsCtrl::TEMP_ADC_PAYLOAD_PCDU, new PoolEntry({0.0})); localDataPoolMap.emplace(tcsCtrl::HEATER_SWITCH_LIST, &heaterSwitchStates); localDataPoolMap.emplace(tcsCtrl::HEATER_CURRENT, &heaterCurrent); + localDataPoolMap.emplace(tcsCtrl::HEATER_ON_FOR_COMPONENT_VEC, &tcsCtrlHeaterOn); + localDataPoolMap.emplace(tcsCtrl::SENSOR_USED_FOR_TCS_CTRL, &tcsCtrlSensorIdx); + localDataPoolMap.emplace(tcsCtrl::HEATER_IDX_USED_FOR_TCS_CTRL, &tcsCtrlHeaterIdx); + localDataPoolMap.emplace(tcsCtrl::HEATER_START_TIME, &tcsCtrlStartTimes); + localDataPoolMap.emplace(tcsCtrl::HEATER_END_TIME, &tcsCtrlEndTimes); bool enableHkSets = false; #if OBSW_ENABLE_PERIODIC_HK == 1 @@ -290,6 +311,8 @@ ReturnValue_t ThermalController::initializeLocalDataPool(localpool::DataPool& lo subdp::RegularHkPeriodicParams(deviceTemperatures.getSid(), enableHkSets, 120.0)); poolManager.subscribeForDiagPeriodicPacket( subdp::DiagnosticsHkPeriodicParams(heaterInfo.getSid(), enableHkSets, 120.0)); + poolManager.subscribeForRegularPeriodicPacket( + subdp::RegularHkPeriodicParams(tcsCtrlInfo.getSid(), enableHkSets, 120.0)); return returnvalue::OK; } @@ -304,6 +327,8 @@ LocalPoolDataSetBase* ThermalController::getDataSetHandle(sid_t sid) { return &deviceTemperatures; case tcsCtrl::HEATER_SET: return &heaterInfo; + case tcsCtrl::TCS_CTRL_INFO: + return &tcsCtrlInfo; default: return nullptr; } @@ -536,19 +561,19 @@ void ThermalController::copySensors() { } } } - // damaged - /* - { - PoolReadGuard pg(&tmp1075SetPlPcdu1, MutexIF::TimeoutType::WAITING, MUTEX_TIMEOUT); - if (pg.getReadResult() == returnvalue::OK) { - sensorTemperatures.tmp1075PlPcdu1.value = tmp1075SetPlPcdu1.temperatureCelcius.value; - sensorTemperatures.tmp1075PlPcdu1.setValid(tmp1075SetPlPcdu1.temperatureCelcius.isValid()); - if (not tmp1075SetPlPcdu1.temperatureCelcius.isValid()) { - sensorTemperatures.tmp1075PlPcdu1.value = INVALID_TEMPERATURE; + // damaged on FM, and no dummies for now + if (pollPcdu1Tmp) { + { + PoolReadGuard pg(tmp1075SetPlPcdu1, MutexIF::TimeoutType::WAITING, MUTEX_TIMEOUT); + if (pg.getReadResult() == returnvalue::OK) { + sensorTemperatures.tmp1075PlPcdu1.value = tmp1075SetPlPcdu1->temperatureCelcius.value; + sensorTemperatures.tmp1075PlPcdu1.setValid(tmp1075SetPlPcdu1->temperatureCelcius.isValid()); + if (not tmp1075SetPlPcdu1->temperatureCelcius.isValid()) { + sensorTemperatures.tmp1075PlPcdu1.value = INVALID_TEMPERATURE; + } } } } - */ { PoolReadGuard pg(&tmp1075SetIfBoard, MutexIF::TimeoutType::WAITING, MUTEX_TIMEOUT); if (pg.getReadResult() == returnvalue::OK) { @@ -1005,7 +1030,7 @@ void ThermalController::ctrlAcsBoard() { heater::Switch redSwitchNr = heater::HEATER_3_OBC_BRD; // A side - thermalComponent = ACS_BOARD; + ctrlCtx.thermalComponent = tcsCtrl::ACS_BOARD; sensors[0].first = deviceTemperatures.gyro0SideA.isValid(); sensors[0].second = deviceTemperatures.gyro0SideA.value; sensors[1].first = deviceTemperatures.gyro2SideB.isValid(); @@ -1049,7 +1074,7 @@ void ThermalController::ctrlAcsBoard() { if (chooseHeater(switchNr, redSwitchNr)) { if (heaterHandler.getSwitchState(switchNr)) { if (submode != SUBMODE_NO_HEATER_CTRL) { - heaterSwitchHelper(switchNr, HeaterHandler::SwitchState::OFF, thermalComponent); + heaterSwitchHelper(switchNr, heater::SwitchState::OFF, ctrlCtx.thermalComponent); } } } @@ -1059,7 +1084,7 @@ void ThermalController::ctrlAcsBoard() { } void ThermalController::ctrlMgt() { - thermalComponent = MGT; + ctrlCtx.thermalComponent = tcsCtrl::MGT; sensors[0].first = sensorTemperatures.mgt.isValid(); sensors[0].second = sensorTemperatures.mgt.value; sensors[1].first = deviceTemperatures.mgt.isValid(); @@ -1069,11 +1094,11 @@ void ThermalController::ctrlMgt() { numSensors = 3; HeaterContext htrCtx(heater::HEATER_2_ACS_BRD, heater::HEATER_1_PCDU_PDU, mgtLimits); ctrlComponentTemperature(htrCtx); - if (componentAboveUpperLimit and not mgtTooHotFlag) { + if (ctrlCtx.componentAboveUpperLimit and not tooHotFlags.mgtTooHotFlag) { triggerEvent(tcsCtrl::MGT_OVERHEATING, tempFloatToU32()); - mgtTooHotFlag = true; - } else if (not componentAboveUpperLimit) { - mgtTooHotFlag = false; + tooHotFlags.mgtTooHotFlag = true; + } else if (not ctrlCtx.componentAboveUpperLimit) { + tooHotFlags.mgtTooHotFlag = false; } } @@ -1084,7 +1109,7 @@ void ThermalController::ctrlRw() { std::array sensorTemps{}; // RW1 - thermalComponent = RW; + ctrlCtx.thermalComponent = tcsCtrl::RW; sensors[0].first = sensorTemperatures.rw1.isValid(); sensors[0].second = sensorTemperatures.rw1.value; sensors[1].first = deviceTemperatures.rw1.isValid(); @@ -1098,14 +1123,14 @@ void ThermalController::ctrlRw() { HeaterContext htrCtx(heater::HEATER_6_DRO, heater::HEATER_6_DRO, rwLimits); ctrlComponentTemperature(htrCtx); sensorTemps[0] = tempFloatToU32(); - if (componentAboveUpperLimit) { + if (ctrlCtx.componentAboveUpperLimit) { oneIsAboveLimit = true; - eventToTrigger = overHeatEventToTrigger; + eventToTrigger = ctrlCtx.overHeatEventToTrigger; } } // RW2 - thermalComponent = RW; + ctrlCtx.thermalComponent = tcsCtrl::RW; sensors[0].first = deviceTemperatures.rw2.isValid(); sensors[0].second = deviceTemperatures.rw2.value; sensors[1].first = deviceTemperatures.rw3.isValid(); @@ -1119,15 +1144,15 @@ void ThermalController::ctrlRw() { HeaterContext htrCtx(heater::HEATER_6_DRO, heater::HEATER_6_DRO, rwLimits); ctrlComponentTemperature(htrCtx); sensorTemps[1] = tempFloatToU32(); - if (componentAboveUpperLimit) { + if (ctrlCtx.componentAboveUpperLimit) { oneIsAboveLimit = true; if (eventToTrigger != ThermalComponentIF::COMPONENT_TEMP_OOL_HIGH) { - eventToTrigger = overHeatEventToTrigger; + eventToTrigger = ctrlCtx.overHeatEventToTrigger; } } } // RW3 - thermalComponent = RW; + ctrlCtx.thermalComponent = tcsCtrl::RW; sensors[0].first = deviceTemperatures.rw3.isValid(); sensors[0].second = deviceTemperatures.rw3.value; sensors[1].first = deviceTemperatures.rw4.isValid(); @@ -1141,16 +1166,16 @@ void ThermalController::ctrlRw() { HeaterContext htrCtx(heater::HEATER_6_DRO, heater::HEATER_6_DRO, rwLimits); ctrlComponentTemperature(htrCtx); sensorTemps[2] = tempFloatToU32(); - if (componentAboveUpperLimit) { + if (ctrlCtx.componentAboveUpperLimit) { oneIsAboveLimit = true; if (eventToTrigger != ThermalComponentIF::COMPONENT_TEMP_OOL_HIGH) { - eventToTrigger = overHeatEventToTrigger; + eventToTrigger = ctrlCtx.overHeatEventToTrigger; } } } // RW4 - thermalComponent = RW; + ctrlCtx.thermalComponent = tcsCtrl::RW; sensors[0].first = deviceTemperatures.rw4.isValid(); sensors[0].second = deviceTemperatures.rw4.value; sensors[1].first = deviceTemperatures.rw1.isValid(); @@ -1164,27 +1189,27 @@ void ThermalController::ctrlRw() { HeaterContext htrCtx(heater::HEATER_6_DRO, heater::HEATER_6_DRO, rwLimits); ctrlComponentTemperature(htrCtx); sensorTemps[3] = tempFloatToU32(); - if (componentAboveUpperLimit) { + if (ctrlCtx.componentAboveUpperLimit) { oneIsAboveLimit = true; if (eventToTrigger != ThermalComponentIF::COMPONENT_TEMP_OOL_HIGH) { - eventToTrigger = overHeatEventToTrigger; + eventToTrigger = ctrlCtx.overHeatEventToTrigger; } } } - if (oneIsAboveLimit and not rwTooHotFlag) { + if (oneIsAboveLimit and not tooHotFlags.rwTooHotFlag) { EventManagerIF::triggerEvent(objects::RW1, eventToTrigger, sensorTemps[0]); EventManagerIF::triggerEvent(objects::RW2, eventToTrigger, sensorTemps[1]); EventManagerIF::triggerEvent(objects::RW3, eventToTrigger, sensorTemps[2]); EventManagerIF::triggerEvent(objects::RW4, eventToTrigger, sensorTemps[3]); - rwTooHotFlag = true; + tooHotFlags.rwTooHotFlag = true; } else if (not oneIsAboveLimit) { - rwTooHotFlag = false; + tooHotFlags.rwTooHotFlag = false; } } void ThermalController::ctrlStr() { - thermalComponent = STR; + ctrlCtx.thermalComponent = tcsCtrl::STR; sensors[0].first = sensorTemperatures.startracker.isValid(); sensors[0].second = sensorTemperatures.startracker.value; sensors[1].first = deviceTemperatures.startracker.isValid(); @@ -1194,11 +1219,11 @@ void ThermalController::ctrlStr() { numSensors = 3; HeaterContext htrCtx(heater::HEATER_5_STR, heater::HEATER_6_DRO, strLimits); ctrlComponentTemperature(htrCtx); - tooHotHandlerWhichClearsOneShotFlag(objects::STAR_TRACKER, strTooHotFlag); + tooHotHandlerWhichClearsOneShotFlag(objects::STAR_TRACKER, tooHotFlags.strTooHotFlag); } void ThermalController::ctrlIfBoard() { - thermalComponent = IF_BOARD; + ctrlCtx.thermalComponent = tcsCtrl::IF_BOARD; sensors[0].first = sensorTemperatures.tmp1075IfBrd.isValid(); sensors[0].second = sensorTemperatures.tmp1075IfBrd.value; sensors[1].first = sensorTemperatures.mgt.isValid(); @@ -1212,7 +1237,7 @@ void ThermalController::ctrlIfBoard() { } void ThermalController::ctrlTcsBoard() { - thermalComponent = TCS_BOARD; + ctrlCtx.thermalComponent = tcsCtrl::TCS_BOARD; sensors[0].first = sensorTemperatures.tcsBoard.isValid(); sensors[0].second = sensorTemperatures.tcsBoard.value; sensors[1].first = sensorTemperatures.tmp1075Tcs0.isValid(); @@ -1226,7 +1251,7 @@ void ThermalController::ctrlTcsBoard() { } void ThermalController::ctrlObc() { - thermalComponent = OBC; + ctrlCtx.thermalComponent = tcsCtrl::OBC; sensors[0].first = deviceTemperatures.q7s.isValid(); sensors[0].second = deviceTemperatures.q7s.value; sensors[1].first = sensorTemperatures.tmp1075Tcs1.isValid(); @@ -1236,35 +1261,16 @@ void ThermalController::ctrlObc() { numSensors = 3; HeaterContext htrCtx(heater::HEATER_3_OBC_BRD, heater::HEATER_2_ACS_BRD, obcLimits); ctrlComponentTemperature(htrCtx); - if (componentAboveUpperLimit and not obcTooHotFlag) { + if (ctrlCtx.componentAboveUpperLimit and not tooHotFlags.obcTooHotFlag) { triggerEvent(tcsCtrl::OBC_OVERHEATING, tempFloatToU32()); - obcTooHotFlag = true; - } else if (not componentAboveUpperLimit) { - obcTooHotFlag = false; - } -} - -void ThermalController::ctrlObcIfBoard() { - thermalComponent = OBCIF_BOARD; - sensors[0].first = deviceTemperatures.q7s.isValid(); - sensors[0].second = deviceTemperatures.q7s.value; - sensors[1].first = sensorTemperatures.tmp1075Tcs0.isValid(); - sensors[1].second = sensorTemperatures.tmp1075Tcs0.value; - sensors[2].first = sensorTemperatures.tmp1075Tcs1.isValid(); - sensors[2].second = sensorTemperatures.tmp1075Tcs1.value; - numSensors = 3; - HeaterContext htrCtx(heater::HEATER_3_OBC_BRD, heater::HEATER_2_ACS_BRD, obcIfBoardLimits); - ctrlComponentTemperature(htrCtx); - if (componentAboveUpperLimit and not obcTooHotFlag) { - triggerEvent(tcsCtrl::OBC_OVERHEATING, tempFloatToU32()); - obcTooHotFlag = true; - } else if (not componentAboveUpperLimit) { - obcTooHotFlag = false; + tooHotFlags.obcTooHotFlag = true; + } else if (not ctrlCtx.componentAboveUpperLimit) { + tooHotFlags.obcTooHotFlag = false; } } void ThermalController::ctrlSBandTransceiver() { - thermalComponent = SBAND_TRANSCEIVER; + ctrlCtx.thermalComponent = tcsCtrl::SBAND_TRANSCEIVER; sensors[0].first = deviceTemperatures.syrlinksPowerAmplifier.isValid(); sensors[0].second = deviceTemperatures.syrlinksPowerAmplifier.value; sensors[1].first = deviceTemperatures.syrlinksBasebandBoard.isValid(); @@ -1274,15 +1280,15 @@ void ThermalController::ctrlSBandTransceiver() { numSensors = 3; HeaterContext htrCtx(heater::HEATER_7_S_BAND, heater::HEATER_4_CAMERA, sBandTransceiverLimits); ctrlComponentTemperature(htrCtx); - if (componentAboveUpperLimit and not syrlinksTooHotFlag) { + if (ctrlCtx.componentAboveUpperLimit and not tooHotFlags.syrlinksTooHotFlag) { triggerEvent(tcsCtrl::SYRLINKS_OVERHEATING, tempFloatToU32()); - syrlinksTooHotFlag = true; - } else if (not componentAboveUpperLimit) { - syrlinksTooHotFlag = false; + tooHotFlags.syrlinksTooHotFlag = true; + } else if (not ctrlCtx.componentAboveUpperLimit) { + tooHotFlags.syrlinksTooHotFlag = false; } } void ThermalController::ctrlPcduP60Board() { - thermalComponent = PCDUP60_BOARD; + ctrlCtx.thermalComponent = tcsCtrl::PCDUP60_BOARD; sensors[0].first = deviceTemperatures.temp1P60dock.isValid(); sensors[0].second = deviceTemperatures.temp1P60dock.value; sensors[1].first = deviceTemperatures.temp2P60dock.isValid(); @@ -1290,16 +1296,16 @@ void ThermalController::ctrlPcduP60Board() { numSensors = 2; HeaterContext htrCtx(heater::HEATER_1_PCDU_PDU, heater::HEATER_2_ACS_BRD, pcduP60BoardLimits); ctrlComponentTemperature(htrCtx); - if (componentAboveUpperLimit and not pcduSystemTooHotFlag) { + if (ctrlCtx.componentAboveUpperLimit and not tooHotFlags.pcduSystemTooHotFlag) { triggerEvent(tcsCtrl::PCDU_SYSTEM_OVERHEATING, tempFloatToU32()); - pcduSystemTooHotFlag = true; - } else if (not componentAboveUpperLimit) { - pcduSystemTooHotFlag = false; + tooHotFlags.pcduSystemTooHotFlag = true; + } else if (not ctrlCtx.componentAboveUpperLimit) { + tooHotFlags.pcduSystemTooHotFlag = false; } // TODO: ! } void ThermalController::ctrlPcduAcu() { - thermalComponent = PCDUACU; + ctrlCtx.thermalComponent = tcsCtrl::PCDUACU; heater::Switch switchNr = heater::HEATER_1_PCDU_PDU; heater::Switch redSwitchNr = heater::HEATER_2_ACS_BRD; @@ -1307,15 +1313,15 @@ void ThermalController::ctrlPcduAcu() { bool sensorTempAvailable = true; // TODO: check if (deviceTemperatures.acu.value[0] != INVALID_TEMPERATURE) { - sensorTemp = deviceTemperatures.acu.value[0]; + ctrlCtx.sensorTemp = deviceTemperatures.acu.value[0]; } else if (deviceTemperatures.acu.value[1] != INVALID_TEMPERATURE) { - sensorTemp = deviceTemperatures.acu.value[1]; + ctrlCtx.sensorTemp = deviceTemperatures.acu.value[1]; } else if (deviceTemperatures.acu.value[2] != INVALID_TEMPERATURE) { - sensorTemp = deviceTemperatures.acu.value[2]; + ctrlCtx.sensorTemp = deviceTemperatures.acu.value[2]; } else if (sensorTemperatures.acu.isValid()) { - sensorTemp = sensorTemperatures.acu.value; + ctrlCtx.sensorTemp = sensorTemperatures.acu.value; } else { - triggerEvent(tcsCtrl::NO_VALID_SENSOR_TEMPERATURE, thermalComponent); + triggerEvent(tcsCtrl::NO_VALID_SENSOR_TEMPERATURE, ctrlCtx.thermalComponent); sensorTempAvailable = false; } if (sensorTempAvailable) { @@ -1323,16 +1329,16 @@ void ThermalController::ctrlPcduAcu() { checkLimitsAndCtrlHeater(htrCtx); } } - if (componentAboveUpperLimit and not pcduSystemTooHotFlag) { + if (ctrlCtx.componentAboveUpperLimit and not tooHotFlags.pcduSystemTooHotFlag) { triggerEvent(tcsCtrl::PCDU_SYSTEM_OVERHEATING, tempFloatToU32()); - pcduSystemTooHotFlag = true; - } else if (not componentAboveUpperLimit) { - pcduSystemTooHotFlag = false; + tooHotFlags.pcduSystemTooHotFlag = true; + } else if (not ctrlCtx.componentAboveUpperLimit) { + tooHotFlags.pcduSystemTooHotFlag = false; } } void ThermalController::ctrlPcduPdu() { - thermalComponent = PCDUPDU; + ctrlCtx.thermalComponent = tcsCtrl::PCDUPDU; sensors[0].first = deviceTemperatures.pdu1.isValid(); sensors[0].second = deviceTemperatures.pdu1.value; sensors[1].first = deviceTemperatures.pdu2.isValid(); @@ -1342,16 +1348,16 @@ void ThermalController::ctrlPcduPdu() { numSensors = 3; HeaterContext htrCtx(heater::HEATER_1_PCDU_PDU, heater::HEATER_2_ACS_BRD, pcduPduLimits); ctrlComponentTemperature(htrCtx); - if (componentAboveUpperLimit and not pcduSystemTooHotFlag) { + if (ctrlCtx.componentAboveUpperLimit and not tooHotFlags.pcduSystemTooHotFlag) { triggerEvent(tcsCtrl::PCDU_SYSTEM_OVERHEATING, tempFloatToU32()); - pcduSystemTooHotFlag = true; - } else if (not componentAboveUpperLimit) { - pcduSystemTooHotFlag = false; + tooHotFlags.pcduSystemTooHotFlag = true; + } else if (not ctrlCtx.componentAboveUpperLimit) { + tooHotFlags.pcduSystemTooHotFlag = false; } } void ThermalController::ctrlPlPcduBoard() { - thermalComponent = PLPCDU_BOARD; + ctrlCtx.thermalComponent = tcsCtrl::PLPCDU_BOARD; sensors[0].first = sensorTemperatures.tmp1075PlPcdu0.isValid(); sensors[0].second = sensorTemperatures.tmp1075PlPcdu0.value; sensors[1].first = sensorTemperatures.tmp1075PlPcdu1.isValid(); @@ -1363,11 +1369,11 @@ void ThermalController::ctrlPlPcduBoard() { numSensors = 4; HeaterContext htrCtx(heater::HEATER_1_PCDU_PDU, heater::HEATER_2_ACS_BRD, plPcduBoardLimits); ctrlComponentTemperature(htrCtx); - tooHotHandler(objects::PLPCDU_HANDLER, eBandTooHotFlag); + tooHotHandler(objects::PLPCDU_HANDLER, tooHotFlags.eBandTooHotFlag); } void ThermalController::ctrlPlocMissionBoard() { - thermalComponent = PLOCMISSION_BOARD; + ctrlCtx.thermalComponent = tcsCtrl::PLOCMISSION_BOARD; sensors[0].first = sensorTemperatures.plocHeatspreader.isValid(); sensors[0].second = sensorTemperatures.plocHeatspreader.value; sensors[1].first = sensorTemperatures.plocMissionboard.isValid(); @@ -1378,11 +1384,11 @@ void ThermalController::ctrlPlocMissionBoard() { HeaterContext htrCtx(heater::HEATER_0_PLOC_PROC_BRD, heater::HEATER_3_OBC_BRD, plocMissionBoardLimits); ctrlComponentTemperature(htrCtx); - tooHotHandler(objects::PLOC_SUPERVISOR_HANDLER, plocTooHotFlag); + tooHotHandler(objects::PLOC_SUPERVISOR_HANDLER, tooHotFlags.plocTooHotFlag); } void ThermalController::ctrlPlocProcessingBoard() { - thermalComponent = PLOCPROCESSING_BOARD; + ctrlCtx.thermalComponent = tcsCtrl::PLOCPROCESSING_BOARD; sensors[0].first = sensorTemperatures.plocMissionboard.isValid(); sensors[0].second = sensorTemperatures.plocMissionboard.value; sensors[1].first = sensorTemperatures.plocHeatspreader.isValid(); @@ -1393,11 +1399,11 @@ void ThermalController::ctrlPlocProcessingBoard() { HeaterContext htrCtx(heater::HEATER_0_PLOC_PROC_BRD, heater::HEATER_3_OBC_BRD, plocProcessingBoardLimits); ctrlComponentTemperature(htrCtx); - tooHotHandler(objects::PLOC_SUPERVISOR_HANDLER, plocTooHotFlag); + tooHotHandler(objects::PLOC_SUPERVISOR_HANDLER, tooHotFlags.plocTooHotFlag); } void ThermalController::ctrlDac() { - thermalComponent = DAC; + ctrlCtx.thermalComponent = tcsCtrl::DAC; sensors[0].first = sensorTemperatures.dacHeatspreader.isValid(); sensors[0].second = sensorTemperatures.dacHeatspreader.value; sensors[1].first = sensorTemperatures.plocMissionboard.isValid(); @@ -1407,11 +1413,11 @@ void ThermalController::ctrlDac() { numSensors = 3; HeaterContext htrCtx(heater::HEATER_0_PLOC_PROC_BRD, heater::HEATER_3_OBC_BRD, dacLimits); ctrlComponentTemperature(htrCtx); - tooHotHandler(objects::PLPCDU_HANDLER, eBandTooHotFlag); + tooHotHandler(objects::PLPCDU_HANDLER, tooHotFlags.eBandTooHotFlag); } void ThermalController::ctrlCameraBody() { - thermalComponent = CAMERA; + ctrlCtx.thermalComponent = tcsCtrl::CAMERA; sensors[0].first = sensorTemperatures.payload4kCamera.isValid(); sensors[0].second = sensorTemperatures.payload4kCamera.value; sensors[1].first = sensorTemperatures.dro.isValid(); @@ -1421,7 +1427,7 @@ void ThermalController::ctrlCameraBody() { numSensors = 3; HeaterContext htrCtx(heater::HEATER_4_CAMERA, heater::HEATER_6_DRO, cameraLimits); ctrlComponentTemperature(htrCtx); - if (componentAboveUpperLimit and not camTooHotOneShotFlag) { + if (ctrlCtx.componentAboveUpperLimit and not tooHotFlags.camTooHotOneShotFlag) { triggerEvent(tcsCtrl::CAMERA_OVERHEATING, tempFloatToU32()); CommandMessage msg; HealthMessage::setHealthMessage(&msg, HealthMessage::HEALTH_SET, HealthState::FAULTY); @@ -1430,14 +1436,14 @@ void ThermalController::ctrlCameraBody() { sif::error << "ThermalController::ctrlCameraBody(): Sending health message failed" << std::endl; } - camTooHotOneShotFlag = true; - } else if (not componentAboveUpperLimit) { - camTooHotOneShotFlag = false; + tooHotFlags.camTooHotOneShotFlag = true; + } else if (not ctrlCtx.componentAboveUpperLimit) { + tooHotFlags.camTooHotOneShotFlag = false; } } void ThermalController::ctrlDro() { - thermalComponent = DRO; + ctrlCtx.thermalComponent = tcsCtrl::DRO; sensors[0].first = sensorTemperatures.dro.isValid(); sensors[0].second = sensorTemperatures.dro.value; sensors[1].first = sensorTemperatures.payload4kCamera.isValid(); @@ -1447,11 +1453,11 @@ void ThermalController::ctrlDro() { numSensors = 3; HeaterContext htrCtx(heater::HEATER_6_DRO, heater::HEATER_4_CAMERA, droLimits); ctrlComponentTemperature(htrCtx); - tooHotHandler(objects::PLPCDU_HANDLER, eBandTooHotFlag); + tooHotHandler(objects::PLPCDU_HANDLER, tooHotFlags.eBandTooHotFlag); } void ThermalController::ctrlX8() { - thermalComponent = X8; + ctrlCtx.thermalComponent = tcsCtrl::X8; sensors[0].first = sensorTemperatures.x8.isValid(); sensors[0].second = sensorTemperatures.x8.value; sensors[1].first = sensorTemperatures.hpa.isValid(); @@ -1461,11 +1467,11 @@ void ThermalController::ctrlX8() { numSensors = 3; HeaterContext htrCtx(heater::HEATER_6_DRO, heater::HEATER_4_CAMERA, x8Limits); ctrlComponentTemperature(htrCtx); - tooHotHandler(objects::PLPCDU_HANDLER, eBandTooHotFlag); + tooHotHandler(objects::PLPCDU_HANDLER, tooHotFlags.eBandTooHotFlag); } void ThermalController::ctrlTx() { - thermalComponent = TX; + ctrlCtx.thermalComponent = tcsCtrl::TX; sensors[0].first = sensorTemperatures.eBandTx.isValid(); sensors[0].second = sensorTemperatures.eBandTx.value; sensors[1].first = sensorTemperatures.x8.isValid(); @@ -1475,11 +1481,11 @@ void ThermalController::ctrlTx() { numSensors = 3; HeaterContext htrCtx(heater::HEATER_6_DRO, heater::HEATER_4_CAMERA, txLimits); ctrlComponentTemperature(htrCtx); - tooHotHandler(objects::PLPCDU_HANDLER, eBandTooHotFlag); + tooHotHandler(objects::PLPCDU_HANDLER, tooHotFlags.eBandTooHotFlag); } void ThermalController::ctrlMpa() { - thermalComponent = MPA; + ctrlCtx.thermalComponent = tcsCtrl::MPA; sensors[0].first = sensorTemperatures.mpa.isValid(); sensors[0].second = sensorTemperatures.mpa.value; sensors[1].first = sensorTemperatures.hpa.isValid(); @@ -1489,11 +1495,11 @@ void ThermalController::ctrlMpa() { numSensors = 3; HeaterContext htrCtx(heater::HEATER_6_DRO, heater::HEATER_4_CAMERA, mpaLimits); ctrlComponentTemperature(htrCtx); - tooHotHandler(objects::PLPCDU_HANDLER, eBandTooHotFlag); + tooHotHandler(objects::PLPCDU_HANDLER, tooHotFlags.eBandTooHotFlag); } void ThermalController::ctrlHpa() { - thermalComponent = HPA; + ctrlCtx.thermalComponent = tcsCtrl::HPA; sensors[0].first = sensorTemperatures.hpa.isValid(); sensors[0].second = sensorTemperatures.hpa.value; sensors[1].first = sensorTemperatures.x8.isValid(); @@ -1503,11 +1509,11 @@ void ThermalController::ctrlHpa() { numSensors = 3; HeaterContext htrCtx(heater::HEATER_6_DRO, heater::HEATER_4_CAMERA, hpaLimits); ctrlComponentTemperature(htrCtx); - tooHotHandler(objects::PLPCDU_HANDLER, eBandTooHotFlag); + tooHotHandler(objects::PLPCDU_HANDLER, tooHotFlags.eBandTooHotFlag); } void ThermalController::ctrlScexBoard() { - thermalComponent = SCEX_BOARD; + ctrlCtx.thermalComponent = tcsCtrl::SCEX_BOARD; sensors[0].first = sensorTemperatures.scex.isValid(); sensors[0].second = sensorTemperatures.scex.value; sensors[1].first = sensorTemperatures.x8.isValid(); @@ -1517,10 +1523,11 @@ void ThermalController::ctrlScexBoard() { numSensors = 3; HeaterContext htrCtx(heater::HEATER_6_DRO, heater::HEATER_5_STR, scexBoardLimits); ctrlComponentTemperature(htrCtx); - tooHotHandlerWhichClearsOneShotFlag(objects::SCEX, scexTooHotFlag); + tooHotHandlerWhichClearsOneShotFlag(objects::SCEX, tooHotFlags.scexTooHotFlag); } -void ThermalController::performThermalModuleCtrl(const HeaterSwitchStates& heaterSwitchStates) { +void ThermalController::performThermalModuleCtrl( + const tcsCtrl::HeaterSwitchStates& heaterSwitchStates) { ctrlAcsBoard(); ctrlMgt(); ctrlRw(); @@ -1528,7 +1535,6 @@ void ThermalController::performThermalModuleCtrl(const HeaterSwitchStates& heate ctrlIfBoard(); ctrlTcsBoard(); ctrlObc(); - ctrlObcIfBoard(); ctrlSBandTransceiver(); ctrlPcduP60Board(); ctrlPcduAcu(); @@ -1537,11 +1543,11 @@ void ThermalController::performThermalModuleCtrl(const HeaterSwitchStates& heate // Payload components std::array plocInAllowedRange{}; ctrlPlocMissionBoard(); - plocInAllowedRange.at(0) = not componentAboveUpperLimit; + plocInAllowedRange.at(0) = not ctrlCtx.componentAboveUpperLimit; ctrlPlocProcessingBoard(); - plocInAllowedRange.at(1) = not componentAboveUpperLimit; + plocInAllowedRange.at(1) = not ctrlCtx.componentAboveUpperLimit; - if (plocTooHotFlag) { + if (tooHotFlags.plocTooHotFlag) { bool clearFlag = true; for (const auto& inRange : plocInAllowedRange) { if (not inRange) { @@ -1549,7 +1555,7 @@ void ThermalController::performThermalModuleCtrl(const HeaterSwitchStates& heate } } if (clearFlag) { - plocTooHotFlag = false; + tooHotFlags.plocTooHotFlag = false; } } ctrlCameraBody(); @@ -1558,21 +1564,21 @@ void ThermalController::performThermalModuleCtrl(const HeaterSwitchStates& heate // E-Band std::array eBandInAllowedRange{}; ctrlPlPcduBoard(); - eBandInAllowedRange.at(0) = not componentAboveUpperLimit; + eBandInAllowedRange.at(0) = not ctrlCtx.componentAboveUpperLimit; ctrlDac(); - eBandInAllowedRange.at(1) = not componentAboveUpperLimit; + eBandInAllowedRange.at(1) = not ctrlCtx.componentAboveUpperLimit; ctrlDro(); - eBandInAllowedRange.at(2) = not componentAboveUpperLimit; + eBandInAllowedRange.at(2) = not ctrlCtx.componentAboveUpperLimit; ctrlX8(); - eBandInAllowedRange.at(3) = not componentAboveUpperLimit; + eBandInAllowedRange.at(3) = not ctrlCtx.componentAboveUpperLimit; ctrlHpa(); - eBandInAllowedRange.at(4) = not componentAboveUpperLimit; + eBandInAllowedRange.at(4) = not ctrlCtx.componentAboveUpperLimit; ctrlTx(); - eBandInAllowedRange.at(5) = not componentAboveUpperLimit; + eBandInAllowedRange.at(5) = not ctrlCtx.componentAboveUpperLimit; ctrlMpa(); - eBandInAllowedRange.at(6) = not componentAboveUpperLimit; + eBandInAllowedRange.at(6) = not ctrlCtx.componentAboveUpperLimit; - if (eBandTooHotFlag) { + if (tooHotFlags.eBandTooHotFlag) { bool clearFlag = true; for (const auto& inRange : eBandInAllowedRange) { if (not inRange) { @@ -1580,12 +1586,11 @@ void ThermalController::performThermalModuleCtrl(const HeaterSwitchStates& heate } } if (clearFlag) { - eBandTooHotFlag = false; + tooHotFlags.eBandTooHotFlag = false; } } - - heaterTransitionControl(heaterSwitchStates); } + void ThermalController::ctrlComponentTemperature(HeaterContext& htrCtx) { if (selectAndReadSensorTemp(htrCtx)) { if (chooseHeater(htrCtx.switchNr, htrCtx.redSwitchNr)) { @@ -1596,9 +1601,11 @@ void ThermalController::ctrlComponentTemperature(HeaterContext& htrCtx) { // No sensors available, so switch the heater off. We can not perform control tasks if we // are blind.. if (chooseHeater(htrCtx.switchNr, htrCtx.redSwitchNr)) { + // Also track the counter to prevent heater handler message spam. The heater handle can only + // process 2 messages per cycle. if (heaterCtrlAllowed() and - (heaterHandler.getSwitchState(htrCtx.switchNr) == HeaterHandler::SwitchState::ON)) { - heaterSwitchHelper(htrCtx.switchNr, HeaterHandler::SwitchState::OFF, thermalComponent); + (thermalStates[ctrlCtx.thermalComponent].noSensorAvailableCounter < 3)) { + heaterSwitchHelper(htrCtx.switchNr, heater::SwitchState::OFF, ctrlCtx.thermalComponent); } } } @@ -1609,20 +1616,21 @@ bool ThermalController::selectAndReadSensorTemp(HeaterContext& htrCtx) { if (sensors[i].first and sensors[i].second != INVALID_TEMPERATURE and sensors[i].second > SANITY_LIMIT_LOWER_TEMP and sensors[i].second < SANITY_LIMIT_UPPER_TEMP) { - sensorTemp = sensors[i].second; - thermalStates[thermalComponent].errorCounter = 0; + ctrlCtx.sensorTemp = sensors[i].second; + ctrlCtx.currentSensorIndex = i; + thermalStates[ctrlCtx.thermalComponent].noSensorAvailableCounter = 0; return true; } } - thermalStates[thermalComponent].errorCounter++; - if (thermalComponent != RW and thermalComponent != ACS_BOARD) { - if (thermalStates[thermalComponent].errorCounter <= 3) { - triggerEvent(tcsCtrl::NO_VALID_SENSOR_TEMPERATURE, thermalComponent); + thermalStates[ctrlCtx.thermalComponent].noSensorAvailableCounter++; + if (ctrlCtx.thermalComponent != tcsCtrl::RW and ctrlCtx.thermalComponent != tcsCtrl::ACS_BOARD) { + if (thermalStates[ctrlCtx.thermalComponent].noSensorAvailableCounter <= 3) { + triggerEvent(tcsCtrl::NO_VALID_SENSOR_TEMPERATURE, ctrlCtx.thermalComponent); } } else { - if (thermalStates[thermalComponent].errorCounter <= 8) { - triggerEvent(tcsCtrl::NO_VALID_SENSOR_TEMPERATURE, thermalComponent); + if (thermalStates[ctrlCtx.thermalComponent].noSensorAvailableCounter <= 8) { + triggerEvent(tcsCtrl::NO_VALID_SENSOR_TEMPERATURE, ctrlCtx.thermalComponent); } } @@ -1636,7 +1644,7 @@ bool ThermalController::chooseHeater(heater::Switch& switchNr, heater::Switch re if (mainHealth != HasHealthIF::HEALTHY) { if (redHealth == HasHealthIF::HEALTHY) { switchNr = redSwitchNr; - redSwitchNrInUse = true; + ctrlCtx.redSwitchNrInUse = true; } else { heaterAvailable = false; // Special case: Ground might command/do something with the heaters, so prevent spam. @@ -1645,7 +1653,7 @@ bool ThermalController::chooseHeater(heater::Switch& switchNr, heater::Switch re } } } else { - redSwitchNrInUse = false; + ctrlCtx.redSwitchNrInUse = false; } return heaterAvailable; } @@ -1654,23 +1662,23 @@ void ThermalController::heaterCtrlTempTooHighHandler(HeaterContext& htrCtx, cons if (not heaterCtrlAllowed()) { return; } - if (htrCtx.switchState == HeaterHandler::SwitchState::ON) { - sif::info << "TCS: Component " << static_cast(thermalComponent) << " too warm, above " - << whatLimit << ", switching off heater" << std::endl; - heaterSwitchHelper(htrCtx.switchNr, HeaterHandler::SwitchState::OFF, thermalComponent); + if (htrCtx.switchState == heater::SwitchState::ON) { + sif::info << "TCS: Component " << static_cast(ctrlCtx.thermalComponent) + << " too warm, above " << whatLimit << ", switching off heater" << std::endl; + heaterSwitchHelper(htrCtx.switchNr, heater::SwitchState::OFF, ctrlCtx.thermalComponent); heaterStates[htrCtx.switchNr].switchTransition = true; - heaterStates[htrCtx.switchNr].target = HeaterHandler::SwitchState::OFF; + heaterStates[htrCtx.switchNr].target = heater::SwitchState::OFF; } - if (heaterHandler.getSwitchState(htrCtx.redSwitchNr) == HeaterHandler::SwitchState::ON) { - heaterSwitchHelper(htrCtx.redSwitchNr, HeaterHandler::SwitchState::OFF, thermalComponent); + if (heaterHandler.getSwitchState(htrCtx.redSwitchNr) == heater::SwitchState::ON) { + heaterSwitchHelper(htrCtx.redSwitchNr, heater::SwitchState::OFF, ctrlCtx.thermalComponent); heaterStates[htrCtx.redSwitchNr].switchTransition = true; - heaterStates[htrCtx.redSwitchNr].target = HeaterHandler::SwitchState::OFF; + heaterStates[htrCtx.redSwitchNr].target = heater::SwitchState::OFF; } } void ThermalController::checkLimitsAndCtrlHeater(HeaterContext& htrCtx) { - componentAboveCutOffLimit = false; - componentAboveUpperLimit = false; + ctrlCtx.componentAboveCutOffLimit = false; + ctrlCtx.componentAboveUpperLimit = false; // Stay passive during switch transitions, wait for heater switching to complete. Otherwise, // still check whether components are out of range, which might be important information for the // top level control loop. @@ -1680,39 +1688,41 @@ void ThermalController::checkLimitsAndCtrlHeater(HeaterContext& htrCtx) { return; } - htrCtx.switchState = heaterHandler.getSwitchState(htrCtx.switchNr); + htrCtx.switchState = + static_cast(heaterInfo.heaterSwitchState[htrCtx.switchNr]); // Heater off - if (htrCtx.switchState == HeaterHandler::SwitchState::OFF) { - if (sensorTemp < htrCtx.tempLimit.opLowerLimit and heaterCtrlAllowed()) { - sif::info << "TCS: Heater " << static_cast(thermalComponent) << " ON" << std::endl; - heaterSwitchHelper(htrCtx.switchNr, HeaterHandler::SwitchState::ON, thermalComponent); - heaterStates[htrCtx.switchNr].switchTransition = true; - heaterStates[htrCtx.switchNr].target = HeaterHandler::SwitchState::ON; + if (htrCtx.switchState == heater::SwitchState::OFF) { + if (ctrlCtx.sensorTemp < htrCtx.tempLimit.opLowerLimit and heaterCtrlAllowed()) { + sif::info << "TCS: Heater " << static_cast(ctrlCtx.thermalComponent) << " ON" + << std::endl; + heaterSwitchHelper(htrCtx.switchNr, heater::SwitchState::ON, ctrlCtx.thermalComponent); } else { // Even if heater control is now allowed, we can update the state. - thermalStates[thermalComponent].heating = false; + thermalStates[ctrlCtx.thermalComponent].heating = false; } heaterCtrlCheckUpperLimits(htrCtx); return; } // Heater on - if (htrCtx.switchState == HeaterHandler::SwitchState::ON) { - if (thermalStates[thermalComponent].heating) { + if (htrCtx.switchState == heater::SwitchState::ON) { + if (thermalStates[ctrlCtx.thermalComponent].heating) { // We are already in a heating cycle, so need to check whether heating task is complete. - if (sensorTemp >= htrCtx.tempLimit.opLowerLimit + TEMP_OFFSET and heaterCtrlAllowed()) { - sif::info << "TCS: Heater " << static_cast(thermalComponent) << " OFF" << std::endl; - heaterSwitchHelper(htrCtx.switchNr, HeaterHandler::SwitchState::OFF, thermalComponent); + if (ctrlCtx.sensorTemp >= htrCtx.tempLimit.opLowerLimit + TEMP_OFFSET and + heaterCtrlAllowed()) { + sif::info << "TCS: Heater " << static_cast(ctrlCtx.thermalComponent) << " OFF" + << std::endl; + heaterSwitchHelper(htrCtx.switchNr, heater::SwitchState::OFF, ctrlCtx.thermalComponent); heaterStates[htrCtx.switchNr].switchTransition = true; - heaterStates[htrCtx.switchNr].target = HeaterHandler::SwitchState::OFF; + heaterStates[htrCtx.switchNr].target = heater::SwitchState::OFF; } return; } // This can happen if heater is used as alternative heater (no regular heating cycle), so we // should still check the upper limits. bool tooHighHandlerAlreadyCalled = heaterCtrlCheckUpperLimits(htrCtx); - if (sensorTemp >= htrCtx.tempLimit.cutOffLimit) { - componentAboveCutOffLimit = true; + if (ctrlCtx.sensorTemp >= htrCtx.tempLimit.cutOffLimit) { + ctrlCtx.componentAboveCutOffLimit = true; if (not tooHighHandlerAlreadyCalled) { heaterCtrlTempTooHighHandler(htrCtx, "CutOff-Limit"); } @@ -1721,19 +1731,19 @@ void ThermalController::checkLimitsAndCtrlHeater(HeaterContext& htrCtx) { } bool ThermalController::heaterCtrlCheckUpperLimits(HeaterContext& htrCtx) { - if (sensorTemp >= htrCtx.tempLimit.nopUpperLimit) { - componentAboveUpperLimit = true; + if (ctrlCtx.sensorTemp >= htrCtx.tempLimit.nopUpperLimit) { + ctrlCtx.componentAboveUpperLimit = true; if (htrCtx.doHeaterHandling) { heaterCtrlTempTooHighHandler(htrCtx, "NOP-Limit"); } - overHeatEventToTrigger = ThermalComponentIF::COMPONENT_TEMP_OOL_HIGH; + ctrlCtx.overHeatEventToTrigger = ThermalComponentIF::COMPONENT_TEMP_OOL_HIGH; return true; - } else if (sensorTemp >= htrCtx.tempLimit.opUpperLimit) { - componentAboveUpperLimit = true; + } else if (ctrlCtx.sensorTemp >= htrCtx.tempLimit.opUpperLimit) { + ctrlCtx.componentAboveUpperLimit = true; if (htrCtx.doHeaterHandling) { heaterCtrlTempTooHighHandler(htrCtx, "OP-Limit"); } - overHeatEventToTrigger = ThermalComponentIF::COMPONENT_TEMP_HIGH; + ctrlCtx.overHeatEventToTrigger = ThermalComponentIF::COMPONENT_TEMP_HIGH; return true; } return false; @@ -1744,17 +1754,30 @@ void ThermalController::resetSensorsArray() { validValuePair.first = false; validValuePair.second = INVALID_TEMPERATURE; } - thermalComponent = NONE; + ctrlCtx.thermalComponent = tcsCtrl::NONE; } -void ThermalController::heaterTransitionControl(const HeaterSwitchStates& currentHeaterStates) { - for (unsigned i = 0; i < 7; i++) { +void ThermalController::heaterTransitionControl( + const tcsCtrl::HeaterSwitchStates& currentHeaterStates) { + for (unsigned i = 0; i < heater::Switch::NUMBER_OF_SWITCHES; i++) { if (heaterStates[i].switchTransition) { if (currentHeaterStates[i] == heaterStates[i].target) { + // Required for max heater period control + if (currentHeaterStates[i] == heater::SwitchState::ON) { + heaterStates[i].heaterOnMaxBurnTime.setTimeout(MAX_HEATER_ON_DURATIONS_MS[i]); + heaterStates[i].heaterOnMaxBurnTime.resetTimer(); + heaterStates[i].trackHeaterMaxBurnTime = true; + } else { + heaterStates[i].trackHeaterMaxBurnTime = false; + // The heater might still be one for some thermal components, so cross-check + // those components + crossCheckHeaterStateOfComponentsWhenHeaterGoesOff(static_cast(i)); + } heaterStates[i].switchTransition = false; + heaterStates[i].heaterSwitchControlCycles = 0; continue; } - if (heaterStates[i].heaterSwitchControlCycles > 3) { + if (heaterStates[i].heaterSwitchControlCycles > 5) { heaterStates[i].switchTransition = false; heaterStates[i].heaterSwitchControlCycles = 0; } @@ -1762,8 +1785,30 @@ void ThermalController::heaterTransitionControl(const HeaterSwitchStates& curren } } } + +void ThermalController::heaterMaxDurationControl( + const tcsCtrl::HeaterSwitchStates& currentHeaterStates) { + for (unsigned i = 0; i < heater::Switch::NUMBER_OF_SWITCHES; i++) { + // Right now, we only track the maximum duration for heater which were commanded by the TCS + // controller. + if (currentHeaterStates[i] == heater::SwitchState::ON and + heaterStates[i].trackHeaterMaxBurnTime and + heaterStates[i].heaterOnMaxBurnTime.hasTimedOut()) { + heaterStates[i].switchTransition = false; + heaterStates[i].heaterSwitchControlCycles = 0; + heaterStates[i].trackHeaterMaxBurnTime = false; + triggerEvent(tcsCtrl::TCS_HEATER_MAX_BURN_TIME_REACHED, static_cast(i), + MAX_HEATER_ON_DURATIONS_MS[i]); + heaterSwitchHelper(static_cast(i), heater::SwitchState::OFF, std::nullopt); + // The heater might still be one for some thermal components, so cross-check + // those components + crossCheckHeaterStateOfComponentsWhenHeaterGoesOff(static_cast(i)); + } + } +} + uint32_t ThermalController::tempFloatToU32() const { - auto sensorTempAsFloat = static_cast(sensorTemp); + auto sensorTempAsFloat = static_cast(ctrlCtx.sensorTemp); uint32_t tempRaw = 0; size_t dummyLen = 0; SerializeAdapter::serialize(&sensorTempAsFloat, reinterpret_cast(&tempRaw), &dummyLen, @@ -1782,9 +1827,9 @@ void ThermalController::setMode(Mode_t mode, Submode_t submode) { } bool ThermalController::tooHotHandler(object_id_t object, bool& oneShotFlag) { - if (componentAboveUpperLimit and not oneShotFlag) { + if (ctrlCtx.componentAboveUpperLimit and not oneShotFlag) { // Too hot -> returns true - EventManagerIF::triggerEvent(object, overHeatEventToTrigger, tempFloatToU32()); + EventManagerIF::triggerEvent(object, ctrlCtx.overHeatEventToTrigger, tempFloatToU32()); oneShotFlag = true; return true; } @@ -1796,31 +1841,48 @@ bool ThermalController::heaterCtrlAllowed() const { return submode != SUBMODE_NO void ThermalController::resetThermalStates() { for (auto& thermalState : thermalStates) { thermalState.heating = false; + thermalState.noSensorAvailableCounter = 0; + thermalState.heaterStartTime = 0; + thermalState.heaterEndTime = 0; + thermalState.sensorIndex = 0; + thermalState.heaterSwitch = heater::Switch::NUMBER_OF_SWITCHES; } } -void ThermalController::heaterSwitchHelper(heater::Switch switchNr, - HeaterHandler::SwitchState state, - unsigned componentIdx) { +void ThermalController::heaterSwitchHelper(heater::Switch switchNr, heater::SwitchState targetState, + std::optional componentIdx) { timeval currentTime; - Clock::getClockMonotonic(¤tTime); - if (state == HeaterHandler::SwitchState::ON) { - heaterHandler.switchHeater(switchNr, state); - thermalStates[componentIdx].heating = true; - thermalStates[componentIdx].heaterStartTime = currentTime.tv_sec; + Clock::getClock(¤tTime); + if (targetState == heater::SwitchState::ON) { + heaterHandler.switchHeater(switchNr, targetState); + heaterStates[switchNr].target = heater::SwitchState::ON; + heaterStates[switchNr].switchTransition = true; + if (componentIdx.has_value()) { + unsigned componentIdxVal = componentIdx.value(); + thermalStates[componentIdxVal].sensorIndex = ctrlCtx.currentSensorIndex; + thermalStates[componentIdxVal].heaterSwitch = switchNr; + thermalStates[componentIdxVal].heating = true; + thermalStates[componentIdxVal].heaterStartTime = currentTime.tv_sec; + } + triggerEvent(tcsCtrl::TCS_SWITCHING_HEATER_ON, static_cast(ctrlCtx.thermalComponent), + static_cast(switchNr)); } else { - heaterHandler.switchHeater(switchNr, state); - thermalStates[componentIdx].heating = false; - thermalStates[componentIdx].heaterEndTime = currentTime.tv_sec; + heaterHandler.switchHeater(switchNr, targetState); + if (componentIdx.has_value()) { + thermalStates[componentIdx.value()].heating = false; + thermalStates[componentIdx.value()].heaterEndTime = currentTime.tv_sec; + } + triggerEvent(tcsCtrl::TCS_SWITCHING_HEATER_OFF, static_cast(ctrlCtx.thermalComponent), + static_cast(switchNr)); } } void ThermalController::heaterSwitchHelperAllOff() { timeval currentTime; - Clock::getClockMonotonic(¤tTime); + Clock::getClock(¤tTime); size_t idx = 0; for (; idx < heater::Switch::NUMBER_OF_SWITCHES; idx++) { - heaterHandler.switchHeater(static_cast(idx), HeaterHandler::SwitchState::OFF); + heaterHandler.switchHeater(static_cast(idx), heater::SwitchState::OFF); } for (idx = 0; idx < thermalStates.size(); idx++) { thermalStates[idx].heating = false; @@ -1828,9 +1890,27 @@ void ThermalController::heaterSwitchHelperAllOff() { } } +ThermalController::~ThermalController() { + if (tmp1075SetPlPcdu1 != nullptr) { + delete tmp1075SetPlPcdu1; + } +} + +void ThermalController::crossCheckHeaterStateOfComponentsWhenHeaterGoesOff( + heater::Switch switchIdx) { + for (unsigned j = 0; j < thermalStates.size(); j++) { + if (thermalStates[j].heating and thermalStates[j].heaterSwitch == switchIdx) { + timeval currentTime; + Clock::getClock(¤tTime); + thermalStates[j].heating = false; + thermalStates[j].heaterEndTime = currentTime.tv_sec; + } + } +} + void ThermalController::tooHotHandlerWhichClearsOneShotFlag(object_id_t object, bool& oneShotFlag) { // Clear the one shot flag is the component is in acceptable temperature range. - if (not tooHotHandler(object, oneShotFlag) and not componentAboveUpperLimit) { + if (not tooHotHandler(object, oneShotFlag) and not ctrlCtx.componentAboveUpperLimit) { oneShotFlag = false; } } diff --git a/mission/controller/ThermalController.h b/mission/controller/ThermalController.h index 4eb41c67..1062fe97 100644 --- a/mission/controller/ThermalController.h +++ b/mission/controller/ThermalController.h @@ -1,7 +1,7 @@ #ifndef MISSION_CONTROLLER_THERMALCONTROLLER_H_ #define MISSION_CONTROLLER_THERMALCONTROLLER_H_ -#include +#include #include #include #include @@ -24,74 +24,7 @@ #include #include - -/** - * NOP Limit: Hard limit for device, usually from datasheet. Device damage is possible lif NOP limit - * is exceeded. - * OP Limit: Soft limit. Device should be switched off or TCS controller should take action if the - * limit is exceeded to avoid reaching NOP limit - */ -struct TempLimits { - TempLimits(float nopLowerLimit, float opLowerLimit, float cutOffLimit, float opUpperLimit, - float nopUpperLimit) - : opLowerLimit(opLowerLimit), - opUpperLimit(opUpperLimit), - cutOffLimit(cutOffLimit), - nopLowerLimit(nopLowerLimit), - nopUpperLimit(nopUpperLimit) {} - float opLowerLimit; - float opUpperLimit; - float cutOffLimit; - float nopLowerLimit; - float nopUpperLimit; -}; - -struct ThermalState { - uint8_t errorCounter; - // Is heating on for that thermal module? - bool heating = false; - heater::Switch heaterSwitch = heater::Switch::NUMBER_OF_SWITCHES; - // Heater start time and end times as UNIX seconds. Please note that these times will be updated - // when a switch command is sent, with no guarantess that the heater actually went on. - uint32_t heaterStartTime = 0; - uint32_t heaterEndTime = 0; -}; - -struct HeaterState { - bool switchTransition; - HeaterHandler::SwitchState target; - uint8_t heaterSwitchControlCycles; -}; - -using HeaterSwitchStates = std::array; - -enum ThermalComponents : uint8_t { - NONE = 0, - ACS_BOARD = 1, - MGT = 2, - RW = 3, - STR = 4, - IF_BOARD = 5, - TCS_BOARD = 6, - OBC = 7, - OBCIF_BOARD = 8, - SBAND_TRANSCEIVER = 9, - PCDUP60_BOARD = 10, - PCDUACU = 11, - PCDUPDU = 12, - PLPCDU_BOARD = 13, - PLOCMISSION_BOARD = 14, - PLOCPROCESSING_BOARD = 15, - DAC = 16, - CAMERA = 17, - DRO = 18, - X8 = 19, - HPA = 20, - TX = 21, - MPA = 22, - SCEX_BOARD = 23, - NUM_ENTRIES -}; +#include class ThermalController : public ExtendedControllerBase { public: @@ -102,8 +35,28 @@ class ThermalController : public ExtendedControllerBase { static constexpr int16_t SANITY_LIMIT_LOWER_TEMP = -80; static constexpr int16_t SANITY_LIMIT_UPPER_TEMP = 160; + // 1 hour + static constexpr uint32_t DEFAULT_MAX_HEATER_ON_DURATION_MS = 60 * 60 * 1000; + static constexpr uint32_t MAX_HEATER_ON_DURATIONS_MS[8] = {// PLOC PROC board + DEFAULT_MAX_HEATER_ON_DURATION_MS, + // PCDU PDU + DEFAULT_MAX_HEATER_ON_DURATION_MS, + // ACS Board + DEFAULT_MAX_HEATER_ON_DURATION_MS, + // OBC Board + DEFAULT_MAX_HEATER_ON_DURATION_MS, + // Camera + DEFAULT_MAX_HEATER_ON_DURATION_MS, + // STR + DEFAULT_MAX_HEATER_ON_DURATION_MS, + // DRO + DEFAULT_MAX_HEATER_ON_DURATION_MS, + // S-Band + DEFAULT_MAX_HEATER_ON_DURATION_MS}; + ThermalController(object_id_t objectId, HeaterHandler& heater, - const std::atomic_bool& tcsBoardShortUnavailable); + const std::atomic_bool& tcsBoardShortUnavailable, bool pollPcdu1Tmp); + virtual ~ThermalController(); ReturnValue_t initialize() override; @@ -111,16 +64,16 @@ class ThermalController : public ExtendedControllerBase { struct HeaterContext { public: HeaterContext(heater::Switch switchNr, heater::Switch redundantSwitchNr, - const TempLimits& tempLimit) + const tcsCtrl::TempLimits& tempLimit) : switchNr(switchNr), redSwitchNr(redundantSwitchNr), tempLimit(tempLimit) {} bool doHeaterHandling = true; heater::Switch switchNr; - HeaterHandler::SwitchState switchState = HeaterHandler::SwitchState::OFF; + heater::SwitchState switchState = heater::SwitchState::OFF; heater::Switch redSwitchNr; - const TempLimits& tempLimit; + const tcsCtrl::TempLimits& tempLimit; }; - void performThermalModuleCtrl(const HeaterSwitchStates& heaterSwitchStates); + void performThermalModuleCtrl(const tcsCtrl::HeaterSwitchStates& heaterSwitchStates); ReturnValue_t handleCommandMessage(CommandMessage* message) override; void performControlOperation() override; ReturnValue_t initializeLocalDataPool(localpool::DataPool& localDataPoolMap, @@ -142,12 +95,12 @@ class ThermalController : public ExtendedControllerBase { HeaterHandler& heaterHandler; + bool pollPcdu1Tmp; tcsCtrl::SensorTemperatures sensorTemperatures; tcsCtrl::SusTemperatures susTemperatures; tcsCtrl::DeviceTemperatures deviceTemperatures; tcsCtrl::HeaterInfo heaterInfo; - lp_vec_t currentVecPdu2 = - lp_vec_t(gp_id_t(objects::PDU2_HANDLER, PDU::pool::PDU_CURRENTS)); + tcsCtrl::TcsCtrlInfo tcsCtrlInfo; DeviceHandlerThermalSet imtqThermalSet; @@ -173,7 +126,7 @@ class ThermalController : public ExtendedControllerBase { TMP1075::Tmp1075Dataset tmp1075SetTcs1; TMP1075::Tmp1075Dataset tmp1075SetPlPcdu0; // damaged - // TMP1075::Tmp1075Dataset tmp1075SetPlPcdu1; + TMP1075::Tmp1075Dataset* tmp1075SetPlPcdu1; TMP1075::Tmp1075Dataset tmp1075SetIfBoard; // SUS @@ -227,57 +180,67 @@ class ThermalController : public ExtendedControllerBase { lp_var_t tempMgm2 = lp_var_t(objects::MGM_2_LIS3_HANDLER, mgmLis3::TEMPERATURE_CELCIUS); lp_var_t tempAdcPayloadPcdu = lp_var_t(objects::PLPCDU_HANDLER, plpcdu::TEMP); + lp_vec_t currentVecPdu2 = + lp_vec_t(gp_id_t(objects::PDU2_HANDLER, PDU::pool::PDU_CURRENTS)); // TempLimits - TempLimits acsBoardLimits = TempLimits(-40.0, -40.0, 80.0, 85.0, 85.0); - TempLimits mgtLimits = TempLimits(-40.0, -40.0, 65.0, 70.0, 70.0); - TempLimits rwLimits = TempLimits(-40.0, -40.0, 80.0, 85.0, 85.0); - TempLimits strLimits = TempLimits(-30.0, -20.0, 65.0, 70.0, 80.0); - TempLimits ifBoardLimits = TempLimits(-65.0, -40.0, 80.0, 85.0, 150.0); - TempLimits tcsBoardLimits = TempLimits(-60.0, -40.0, 80.0, 85.0, 130.0); - TempLimits obcLimits = TempLimits(-40.0, -40.0, 80.0, 85.0, 85.0); - TempLimits obcIfBoardLimits = TempLimits(-65.0, -40.0, 80.0, 85.0, 125.0); - TempLimits sBandTransceiverLimits = TempLimits(-40.0, -25.0, 35.0, 40.0, 65.0); - TempLimits pcduP60BoardLimits = TempLimits(-35.0, -35.0, 80.0, 85.0, 85.0); - TempLimits pcduAcuLimits = TempLimits(-35.0, -35.0, 80.0, 85.0, 85.0); - TempLimits pcduPduLimits = TempLimits(-35.0, -35.0, 80.0, 85.0, 85.0); - TempLimits plPcduBoardLimits = TempLimits(-55.0, -40.0, 80.0, 85.0, 125.0); - TempLimits plocMissionBoardLimits = TempLimits(-30.0, -10.0, 40.0, 45.0, 60); - TempLimits plocProcessingBoardLimits = TempLimits(-30.0, -10.0, 40.0, 45.0, 60.0); - TempLimits dacLimits = TempLimits(-65.0, -40.0, 113.0, 118.0, 150.0); - TempLimits cameraLimits = TempLimits(-40.0, -30.0, 60.0, 65.0, 85.0); - TempLimits droLimits = TempLimits(-40.0, -30.0, 75.0, 80.0, 90.0); - TempLimits x8Limits = TempLimits(-40.0, -30.0, 75.0, 80.0, 90.0); - TempLimits hpaLimits = TempLimits(-40.0, -30.0, 75.0, 80.0, 90.0); - TempLimits txLimits = TempLimits(-40.0, -30.0, 75.0, 80.0, 90.0); - TempLimits mpaLimits = TempLimits(-40.0, -30.0, 75.0, 80.0, 90.0); - TempLimits scexBoardLimits = TempLimits(-60.0, -40.0, 80.0, 85.0, 150.0); + tcsCtrl::TempLimits acsBoardLimits = tcsCtrl::TempLimits(-40.0, -40.0, 80.0, 85.0, 85.0); + tcsCtrl::TempLimits mgtLimits = tcsCtrl::TempLimits(-40.0, -40.0, 65.0, 70.0, 70.0); + tcsCtrl::TempLimits rwLimits = tcsCtrl::TempLimits(-40.0, -40.0, 80.0, 85.0, 85.0); + tcsCtrl::TempLimits strLimits = tcsCtrl::TempLimits(-30.0, -20.0, 65.0, 70.0, 80.0); + tcsCtrl::TempLimits ifBoardLimits = tcsCtrl::TempLimits(-65.0, -40.0, 80.0, 85.0, 150.0); + tcsCtrl::TempLimits tcsBoardLimits = tcsCtrl::TempLimits(-60.0, -40.0, 80.0, 85.0, 130.0); + tcsCtrl::TempLimits obcLimits = tcsCtrl::TempLimits(-40.0, -40.0, 80.0, 85.0, 85.0); + tcsCtrl::TempLimits obcIfBoardLimits = tcsCtrl::TempLimits(-65.0, -40.0, 80.0, 85.0, 125.0); + tcsCtrl::TempLimits sBandTransceiverLimits = tcsCtrl::TempLimits(-40.0, -25.0, 35.0, 40.0, 65.0); + tcsCtrl::TempLimits pcduP60BoardLimits = tcsCtrl::TempLimits(-35.0, -35.0, 80.0, 85.0, 85.0); + tcsCtrl::TempLimits pcduAcuLimits = tcsCtrl::TempLimits(-35.0, -35.0, 80.0, 85.0, 85.0); + tcsCtrl::TempLimits pcduPduLimits = tcsCtrl::TempLimits(-35.0, -35.0, 80.0, 85.0, 85.0); + tcsCtrl::TempLimits plPcduBoardLimits = tcsCtrl::TempLimits(-55.0, -40.0, 80.0, 85.0, 125.0); + tcsCtrl::TempLimits plocMissionBoardLimits = tcsCtrl::TempLimits(-30.0, -10.0, 40.0, 45.0, 60); + tcsCtrl::TempLimits plocProcessingBoardLimits = + tcsCtrl::TempLimits(-30.0, -10.0, 40.0, 45.0, 60.0); + tcsCtrl::TempLimits dacLimits = tcsCtrl::TempLimits(-65.0, -40.0, 113.0, 118.0, 150.0); + tcsCtrl::TempLimits cameraLimits = tcsCtrl::TempLimits(-40.0, -30.0, 60.0, 65.0, 85.0); + tcsCtrl::TempLimits droLimits = tcsCtrl::TempLimits(-40.0, -30.0, 75.0, 80.0, 90.0); + tcsCtrl::TempLimits x8Limits = tcsCtrl::TempLimits(-40.0, -30.0, 75.0, 80.0, 90.0); + tcsCtrl::TempLimits hpaLimits = tcsCtrl::TempLimits(-40.0, -30.0, 75.0, 80.0, 90.0); + tcsCtrl::TempLimits txLimits = tcsCtrl::TempLimits(-40.0, -30.0, 75.0, 80.0, 90.0); + tcsCtrl::TempLimits mpaLimits = tcsCtrl::TempLimits(-40.0, -30.0, 75.0, 80.0, 90.0); + tcsCtrl::TempLimits scexBoardLimits = tcsCtrl::TempLimits(-60.0, -40.0, 80.0, 85.0, 150.0); + + struct CtrlContext { + double sensorTemp = INVALID_TEMPERATURE; + uint8_t currentSensorIndex = 0; + tcsCtrl::ThermalComponents thermalComponent = tcsCtrl::NONE; + bool redSwitchNrInUse = false; + bool componentAboveCutOffLimit = false; + bool componentAboveUpperLimit = false; + Event overHeatEventToTrigger; + } ctrlCtx; - double sensorTemp = INVALID_TEMPERATURE; - ThermalComponents thermalComponent = NONE; - bool redSwitchNrInUse = false; MessageQueueId_t camId = MessageQueueIF::NO_QUEUE; - bool componentAboveCutOffLimit = false; - bool componentAboveUpperLimit = false; - Event overHeatEventToTrigger; - bool eBandTooHotFlag = false; - bool camTooHotOneShotFlag = false; - bool scexTooHotFlag = false; - bool plocTooHotFlag = false; - bool pcduSystemTooHotFlag = false; - bool syrlinksTooHotFlag = false; - bool obcTooHotFlag = false; - bool mgtTooHotFlag = false; - bool strTooHotFlag = false; - bool rwTooHotFlag = false; + + struct TooHotFlags { + bool eBandTooHotFlag = false; + bool camTooHotOneShotFlag = false; + bool scexTooHotFlag = false; + bool plocTooHotFlag = false; + bool pcduSystemTooHotFlag = false; + bool syrlinksTooHotFlag = false; + bool obcTooHotFlag = false; + bool mgtTooHotFlag = false; + bool strTooHotFlag = false; + bool rwTooHotFlag = false; + } tooHotFlags; bool transitionWhenHeatersOff = false; uint32_t transitionWhenHeatersOffCycles = 0; Mode_t targetMode = MODE_OFF; Submode_t targetSubmode = SUBMODE_NONE; uint32_t cycles = 0; - std::array thermalStates{}; - std::array heaterStates{}; + std::array thermalStates{}; + std::array heaterStates{}; // Initial delay to make sure all pool variables have been initialized their owners. // Also, wait for system initialization to complete. @@ -298,6 +261,12 @@ class ThermalController : public ExtendedControllerBase { PoolEntry heaterSwitchStates = PoolEntry(heater::NUMBER_OF_SWITCHES); PoolEntry heaterCurrent = PoolEntry(); + PoolEntry tcsCtrlHeaterOn = PoolEntry(tcsCtrl::NUM_THERMAL_COMPONENTS); + PoolEntry tcsCtrlSensorIdx = PoolEntry(tcsCtrl::NUM_THERMAL_COMPONENTS); + PoolEntry tcsCtrlHeaterIdx = PoolEntry(tcsCtrl::NUM_THERMAL_COMPONENTS); + PoolEntry tcsCtrlStartTimes = PoolEntry(tcsCtrl::NUM_THERMAL_COMPONENTS); + PoolEntry tcsCtrlEndTimes = PoolEntry(tcsCtrl::NUM_THERMAL_COMPONENTS); + static constexpr dur_millis_t MUTEX_TIMEOUT = 50; void startTransition(Mode_t mode, Submode_t submode) override; @@ -319,8 +288,8 @@ class ThermalController : public ExtendedControllerBase { bool selectAndReadSensorTemp(HeaterContext& htrCtx); void heaterSwitchHelperAllOff(); - void heaterSwitchHelper(heater::Switch switchNr, HeaterHandler::SwitchState state, - unsigned componentIdx); + void heaterSwitchHelper(heater::Switch switchNr, heater::SwitchState state, + std::optional componentIdx); void ctrlAcsBoard(); void ctrlMgt(); @@ -329,7 +298,6 @@ class ThermalController : public ExtendedControllerBase { void ctrlIfBoard(); void ctrlTcsBoard(); void ctrlObc(); - void ctrlObcIfBoard(); void ctrlSBandTransceiver(); void ctrlPcduP60Board(); void ctrlPcduAcu(); @@ -345,7 +313,22 @@ class ThermalController : public ExtendedControllerBase { void ctrlTx(); void ctrlMpa(); void ctrlScexBoard(); - void heaterTransitionControl(const HeaterSwitchStates& currentHeaterStates); + + /** + * The transition of heaters might take some time. As long as a transition is + * going on, the TCS controller works in a reduced form. This function takes care + * of tracking transition and capturing their completion. + * @param currentHeaterStates + */ + void heaterTransitionControl(const tcsCtrl::HeaterSwitchStates& currentHeaterStates); + /** + * Control tasks to prevent heaters being on for prolonged periods. Ideally, this + * should never happen, but this task prevents bugs from causing heaters to stay on + * for a long time, which draws a lot of power. + * @param currentHeaterStates + */ + void heaterMaxDurationControl(const tcsCtrl::HeaterSwitchStates& currentHeaterStates); + void crossCheckHeaterStateOfComponentsWhenHeaterGoesOff(heater::Switch switchIdx); void setMode(Mode_t mode, Submode_t submode); uint32_t tempFloatToU32() const; bool tooHotHandler(object_id_t object, bool& oneShotFlag); diff --git a/mission/controller/tcsDefs.h b/mission/controller/tcsDefs.h index e2efd98c..f5d9d180 100644 --- a/mission/controller/tcsDefs.h +++ b/mission/controller/tcsDefs.h @@ -9,6 +9,85 @@ namespace tcsCtrl { +/** + * NOP Limit: Hard limit for device, usually from datasheet. Device damage is possible lif NOP limit + * is exceeded. + * OP Limit: Soft limit. Device should be switched off or TCS controller should take action if the + * limit is exceeded to avoid reaching NOP limit + */ +struct TempLimits { + TempLimits(float nopLowerLimit, float opLowerLimit, float cutOffLimit, float opUpperLimit, + float nopUpperLimit) + : opLowerLimit(opLowerLimit), + opUpperLimit(opUpperLimit), + cutOffLimit(cutOffLimit), + nopLowerLimit(nopLowerLimit), + nopUpperLimit(nopUpperLimit) {} + float opLowerLimit; + float opUpperLimit; + float cutOffLimit; + float nopLowerLimit; + float nopUpperLimit; +}; + +/** + * Abstraction for the state of a single thermal component + */ +struct ThermalState { + uint8_t noSensorAvailableCounter; + // Which sensor is used for this component? + uint8_t sensorIndex = 0; + // Is heating on for that thermal module? + bool heating = false; + // Which switch is being used for heating the component + heater::Switch heaterSwitch = heater::Switch::HEATER_NONE; + // Heater start time and end times as UNIX seconds. Please note that these times will be updated + // when a switch command is sent, with no guarantess that the heater actually went on. + uint32_t heaterStartTime = 0; + uint32_t heaterEndTime = 0; +}; + +/** + * Abstraction for the state of a single heater. + */ +struct HeaterState { + bool switchTransition = false; + heater::SwitchState target = heater::SwitchState::OFF; + uint8_t heaterSwitchControlCycles = 0; + bool trackHeaterMaxBurnTime = false; + Countdown heaterOnMaxBurnTime; +}; + +using HeaterSwitchStates = std::array; + +enum ThermalComponents : uint8_t { + NONE = 0, + ACS_BOARD = 1, + MGT = 2, + RW = 3, + STR = 4, + IF_BOARD = 5, + TCS_BOARD = 6, + OBC = 7, + LEGACY_OBCIF_BOARD = 8, + SBAND_TRANSCEIVER = 9, + PCDUP60_BOARD = 10, + PCDUACU = 11, + PCDUPDU = 12, + PLPCDU_BOARD = 13, + PLOCMISSION_BOARD = 14, + PLOCPROCESSING_BOARD = 15, + DAC = 16, + CAMERA = 17, + DRO = 18, + X8 = 19, + HPA = 20, + TX = 21, + MPA = 22, + SCEX_BOARD = 23, + NUM_THERMAL_COMPONENTS +}; + static const uint8_t SUBSYSTEM_ID = SUBSYSTEM_ID::TCS_CONTROLLER; static constexpr Event NO_VALID_SENSOR_TEMPERATURE = MAKE_EVENT(0, severity::MEDIUM); static constexpr Event NO_HEALTHY_HEATER_AVAILABLE = MAKE_EVENT(1, severity::MEDIUM); @@ -18,6 +97,12 @@ static constexpr Event CAMERA_OVERHEATING = MAKE_EVENT(5, severity::HIGH); static constexpr Event PCDU_SYSTEM_OVERHEATING = MAKE_EVENT(6, severity::HIGH); static constexpr Event HEATER_NOT_OFF_FOR_OFF_MODE = MAKE_EVENT(7, severity::MEDIUM); static constexpr Event MGT_OVERHEATING = MAKE_EVENT(8, severity::HIGH); +//! [EXPORT] : [COMMENT] P1: Module index. P2: Heater index +static constexpr Event TCS_SWITCHING_HEATER_ON = MAKE_EVENT(9, severity::INFO); +//! [EXPORT] : [COMMENT] P1: Module index. P2: Heater index +static constexpr Event TCS_SWITCHING_HEATER_OFF = MAKE_EVENT(10, severity::INFO); +//! [EXPORT] : [COMMENT] P1: Heater index. P2: Maximum burn time for heater. +static constexpr Event TCS_HEATER_MAX_BURN_TIME_REACHED = MAKE_EVENT(11, severity::MEDIUM); enum SetId : uint32_t { SENSOR_TEMPERATURES = 0, @@ -25,6 +110,7 @@ enum SetId : uint32_t { SUS_TEMPERATURES = 2, COMPONENT_TEMPERATURES = 3, HEATER_SET = 4, + TCS_CTRL_INFO = 5 }; enum PoolIds : lp_id_t { @@ -92,7 +178,13 @@ enum PoolIds : lp_id_t { TEMP_ADC_PAYLOAD_PCDU, HEATER_SWITCH_LIST, - HEATER_CURRENT + HEATER_CURRENT, + + HEATER_ON_FOR_COMPONENT_VEC, + SENSOR_USED_FOR_TCS_CTRL, + HEATER_IDX_USED_FOR_TCS_CTRL, + HEATER_START_TIME, + HEATER_END_TIME }; static const uint8_t ENTRIES_SENSOR_TEMPERATURE_SET = 25; @@ -232,6 +324,29 @@ class HeaterInfo : public StaticLocalDataSet<3> { lp_var_t heaterCurrent = lp_var_t(sid.objectId, PoolIds::HEATER_CURRENT, this); }; +class TcsCtrlInfo : public StaticLocalDataSet<6> { + public: + explicit TcsCtrlInfo(HasLocalDataPoolIF* owner) : StaticLocalDataSet(owner, TCS_CTRL_INFO) {} + + explicit TcsCtrlInfo(object_id_t objectId) : StaticLocalDataSet(sid_t(objectId, TCS_CTRL_INFO)) {} + + lp_vec_t heatingOnVec = + lp_vec_t( + sid.objectId, PoolIds::HEATER_ON_FOR_COMPONENT_VEC, this); + lp_vec_t sensorIdxUsedForTcsCtrl = + lp_vec_t(sid.objectId, + PoolIds::SENSOR_USED_FOR_TCS_CTRL, this); + lp_vec_t heaterSwitchIdx = + lp_vec_t( + sid.objectId, PoolIds::HEATER_IDX_USED_FOR_TCS_CTRL, this); + lp_vec_t heaterStartTimes = + lp_vec_t(sid.objectId, PoolIds::HEATER_START_TIME, + this); + lp_vec_t heaterEndTimes = + lp_vec_t(sid.objectId, PoolIds::HEATER_END_TIME, + this); +}; + } // namespace tcsCtrl #endif /* MISSION_CONTROLLER_CONTROLLERDEFINITIONS_THERMALCONTROLLERDEFINITIONS_H_ */ diff --git a/mission/genericFactory.cpp b/mission/genericFactory.cpp index 0466a980..3d9d0c81 100644 --- a/mission/genericFactory.cpp +++ b/mission/genericFactory.cpp @@ -311,9 +311,9 @@ void ObjectFactory::createGenericHeaterComponents(GpioIF& gpioIF, PowerSwitchIF& heaterHandler->connectModeTreeParent(satsystem::tcs::SUBSYSTEM); } -void ObjectFactory::createThermalController(HeaterHandler& heaterHandler) { +void ObjectFactory::createThermalController(HeaterHandler& heaterHandler, bool pollPlPcduTmp1) { auto* tcsCtrl = new ThermalController(objects::THERMAL_CONTROLLER, heaterHandler, - tcs::TCS_BOARD_SHORTLY_UNAVAILABLE); + tcs::TCS_BOARD_SHORTLY_UNAVAILABLE, pollPlPcduTmp1); tcsCtrl->connectModeTreeParent(satsystem::tcs::SUBSYSTEM); } void ObjectFactory::createRwAssy(PowerSwitchIF& pwrSwitcher, power::Switch_t theSwitch, diff --git a/mission/genericFactory.h b/mission/genericFactory.h index 03bbfaa5..7845c140 100644 --- a/mission/genericFactory.h +++ b/mission/genericFactory.h @@ -50,7 +50,7 @@ void produceGenericObjects(HealthTableIF** healthTable, PusTmFunnel** pusFunnel, void createGenericHeaterComponents(GpioIF& gpioIF, PowerSwitchIF& pwrSwitcher, HeaterHandler*& heaterHandler); -void createThermalController(HeaterHandler& heaterHandler); +void createThermalController(HeaterHandler& heaterHandler, bool pollPlPcduTmp1); void createRwAssy(PowerSwitchIF& pwrSwitcher, power::Switch_t theSwitch, std::array rws, std::array rwIds); void createSusAssy(PowerSwitchIF& pwrSwitcher, std::array suses); diff --git a/mission/pollingSeqTables.cpp b/mission/pollingSeqTables.cpp index 0367ef27..e18046d5 100644 --- a/mission/pollingSeqTables.cpp +++ b/mission/pollingSeqTables.cpp @@ -39,56 +39,67 @@ ReturnValue_t pst::pstSyrlinks(FixedTimeslotTaskIF *thisSequence) { // I don't think this needs to be in a PST because linux takes care of bus serialization, but // keep it like this for now, it works -ReturnValue_t pst::pstI2cProcessingSystem(FixedTimeslotTaskIF *thisSequence) { +ReturnValue_t pst::pstI2c(TmpSchedConfig schedConf, FixedTimeslotTaskIF *thisSequence) { // Length of a communication cycle uint32_t length = thisSequence->getPeriodMs(); static_cast(length); - // These are actually part of another bus, but this works, so keep it like this for now - thisSequence->addSlot(objects::TMP1075_HANDLER_TCS_0, length * 0.2, - DeviceHandlerIF::PERFORM_OPERATION); - thisSequence->addSlot(objects::TMP1075_HANDLER_TCS_0, length * 0.2, DeviceHandlerIF::SEND_WRITE); - thisSequence->addSlot(objects::TMP1075_HANDLER_TCS_0, length * 0.2, DeviceHandlerIF::GET_WRITE); - thisSequence->addSlot(objects::TMP1075_HANDLER_TCS_0, length * 0.3, DeviceHandlerIF::SEND_READ); - thisSequence->addSlot(objects::TMP1075_HANDLER_TCS_0, length * 0.3, DeviceHandlerIF::GET_READ); + if (schedConf.scheduleTmpDev0) { + thisSequence->addSlot(objects::TMP1075_HANDLER_TCS_0, length * 0, + DeviceHandlerIF::PERFORM_OPERATION); + thisSequence->addSlot(objects::TMP1075_HANDLER_TCS_0, length * 0, DeviceHandlerIF::SEND_WRITE); + thisSequence->addSlot(objects::TMP1075_HANDLER_TCS_0, length * 0.1, DeviceHandlerIF::GET_WRITE); + thisSequence->addSlot(objects::TMP1075_HANDLER_TCS_0, length * 0.1, DeviceHandlerIF::SEND_READ); + thisSequence->addSlot(objects::TMP1075_HANDLER_TCS_0, length * 0.1, DeviceHandlerIF::GET_READ); + } - thisSequence->addSlot(objects::TMP1075_HANDLER_TCS_1, length * 0.4, - DeviceHandlerIF::PERFORM_OPERATION); - thisSequence->addSlot(objects::TMP1075_HANDLER_TCS_1, length * 0.4, DeviceHandlerIF::SEND_WRITE); - thisSequence->addSlot(objects::TMP1075_HANDLER_TCS_1, length * 0.4, DeviceHandlerIF::GET_WRITE); - thisSequence->addSlot(objects::TMP1075_HANDLER_TCS_1, length * 0.5, DeviceHandlerIF::SEND_READ); - thisSequence->addSlot(objects::TMP1075_HANDLER_TCS_1, length * 0.5, DeviceHandlerIF::GET_READ); + if (schedConf.scheduleTmpDev1) { + thisSequence->addSlot(objects::TMP1075_HANDLER_TCS_1, length * 0.2, + DeviceHandlerIF::PERFORM_OPERATION); + thisSequence->addSlot(objects::TMP1075_HANDLER_TCS_1, length * 0.2, + DeviceHandlerIF::SEND_WRITE); + thisSequence->addSlot(objects::TMP1075_HANDLER_TCS_1, length * 0.2, DeviceHandlerIF::GET_WRITE); + thisSequence->addSlot(objects::TMP1075_HANDLER_TCS_1, length * 0.3, DeviceHandlerIF::SEND_READ); + thisSequence->addSlot(objects::TMP1075_HANDLER_TCS_1, length * 0.3, DeviceHandlerIF::GET_READ); + } - thisSequence->addSlot(objects::TMP1075_HANDLER_PLPCDU_0, length * 0.6, - DeviceHandlerIF::PERFORM_OPERATION); - thisSequence->addSlot(objects::TMP1075_HANDLER_PLPCDU_0, length * 0.6, - DeviceHandlerIF::SEND_WRITE); - thisSequence->addSlot(objects::TMP1075_HANDLER_PLPCDU_0, length * 0.6, - DeviceHandlerIF::GET_WRITE); - thisSequence->addSlot(objects::TMP1075_HANDLER_PLPCDU_0, length * 0.7, - DeviceHandlerIF::SEND_READ); - thisSequence->addSlot(objects::TMP1075_HANDLER_PLPCDU_0, length * 0.7, DeviceHandlerIF::GET_READ); - // damaged - /* - thisSequence->addSlot(objects::TMP1075_HANDLER_PLPCDU_1, length * 0.4, - DeviceHandlerIF::PERFORM_OPERATION); - thisSequence->addSlot(objects::TMP1075_HANDLER_PLPCDU_1, length * 0.4, - DeviceHandlerIF::SEND_WRITE); - thisSequence->addSlot(objects::TMP1075_HANDLER_PLPCDU_1, length * 0.4, - DeviceHandlerIF::GET_WRITE); - thisSequence->addSlot(objects::TMP1075_HANDLER_PLPCDU_1, length * 0.4, - DeviceHandlerIF::SEND_READ); - thisSequence->addSlot(objects::TMP1075_HANDLER_PLPCDU_1, length * 0.4, DeviceHandlerIF::GET_READ); - */ - thisSequence->addSlot(objects::TMP1075_HANDLER_IF_BOARD, length * 0.8, - DeviceHandlerIF::PERFORM_OPERATION); - thisSequence->addSlot(objects::TMP1075_HANDLER_IF_BOARD, length * 0.8, - DeviceHandlerIF::SEND_WRITE); - thisSequence->addSlot(objects::TMP1075_HANDLER_IF_BOARD, length * 0.8, - DeviceHandlerIF::GET_WRITE); - thisSequence->addSlot(objects::TMP1075_HANDLER_IF_BOARD, length * 0.9, - DeviceHandlerIF::SEND_READ); - thisSequence->addSlot(objects::TMP1075_HANDLER_IF_BOARD, length * 0.9, DeviceHandlerIF::GET_READ); + if (schedConf.schedulePlPcduDev0) { + thisSequence->addSlot(objects::TMP1075_HANDLER_PLPCDU_0, length * 0.4, + DeviceHandlerIF::PERFORM_OPERATION); + thisSequence->addSlot(objects::TMP1075_HANDLER_PLPCDU_0, length * 0.4, + DeviceHandlerIF::SEND_WRITE); + thisSequence->addSlot(objects::TMP1075_HANDLER_PLPCDU_0, length * 0.4, + DeviceHandlerIF::GET_WRITE); + thisSequence->addSlot(objects::TMP1075_HANDLER_PLPCDU_0, length * 0.5, + DeviceHandlerIF::SEND_READ); + thisSequence->addSlot(objects::TMP1075_HANDLER_PLPCDU_0, length * 0.5, + DeviceHandlerIF::GET_READ); + } + if (schedConf.schedulePlPcduDev1) { + thisSequence->addSlot(objects::TMP1075_HANDLER_PLPCDU_1, length * 0.6, + DeviceHandlerIF::PERFORM_OPERATION); + thisSequence->addSlot(objects::TMP1075_HANDLER_PLPCDU_1, length * 0.6, + DeviceHandlerIF::SEND_WRITE); + thisSequence->addSlot(objects::TMP1075_HANDLER_PLPCDU_1, length * 0.6, + DeviceHandlerIF::GET_WRITE); + thisSequence->addSlot(objects::TMP1075_HANDLER_PLPCDU_1, length * 0.7, + DeviceHandlerIF::SEND_READ); + thisSequence->addSlot(objects::TMP1075_HANDLER_PLPCDU_1, length * 0.7, + DeviceHandlerIF::GET_READ); + } + + if (schedConf.scheduleIfBoardDev) { + thisSequence->addSlot(objects::TMP1075_HANDLER_IF_BOARD, length * 0.8, + DeviceHandlerIF::PERFORM_OPERATION); + thisSequence->addSlot(objects::TMP1075_HANDLER_IF_BOARD, length * 0.8, + DeviceHandlerIF::SEND_WRITE); + thisSequence->addSlot(objects::TMP1075_HANDLER_IF_BOARD, length * 0.8, + DeviceHandlerIF::GET_WRITE); + thisSequence->addSlot(objects::TMP1075_HANDLER_IF_BOARD, length * 0.9, + DeviceHandlerIF::SEND_READ); + thisSequence->addSlot(objects::TMP1075_HANDLER_IF_BOARD, length * 0.9, + DeviceHandlerIF::GET_READ); + } static_cast(length); return thisSequence->checkSequence(); } diff --git a/mission/pollingSeqTables.h b/mission/pollingSeqTables.h index e3bc0ad0..5df3c954 100644 --- a/mission/pollingSeqTables.h +++ b/mission/pollingSeqTables.h @@ -39,6 +39,16 @@ struct AcsPstCfg { bool scheduleStr = true; }; +// Default config is for FM. +struct TmpSchedConfig { + bool scheduleTmpDev0 = true; + bool scheduleTmpDev1 = true; + bool schedulePlPcduDev0 = true; + // damaged on FM + bool schedulePlPcduDev1 = false; + bool scheduleIfBoardDev = true; +}; + /** * @brief This function creates the PST for all gomspace devices. * @details @@ -51,7 +61,7 @@ ReturnValue_t pstSyrlinks(FixedTimeslotTaskIF* thisSequence); ReturnValue_t pstTcsAndAcs(FixedTimeslotTaskIF* thisSequence, AcsPstCfg cfg); -ReturnValue_t pstI2cProcessingSystem(FixedTimeslotTaskIF* thisSequence); +ReturnValue_t pstI2c(TmpSchedConfig schedConf, FixedTimeslotTaskIF* thisSequence); /** * Generic test PST diff --git a/mission/system/systemTree.cpp b/mission/system/systemTree.cpp index 41bf3216..10c40617 100644 --- a/mission/system/systemTree.cpp +++ b/mission/system/systemTree.cpp @@ -31,12 +31,12 @@ void buildPtgInertialSequence(Subsystem& ss, ModeListEntry& eh); static const auto OFF = HasModesIF::MODE_OFF; static const auto NML = DeviceHandlerIF::MODE_NORMAL; -void satsystem::init() { +void satsystem::init(bool commandPlPcdu1) { auto& acsSubsystem = acs::init(); acsSubsystem.connectModeTreeParent(EIVE_SYSTEM); auto& payloadSubsystem = payload::init(); payloadSubsystem.connectModeTreeParent(EIVE_SYSTEM); - auto& tcsSubsystem = tcs::init(); + auto& tcsSubsystem = tcs::init(commandPlPcdu1); tcsSubsystem.connectModeTreeParent(EIVE_SYSTEM); auto& comSubsystem = com::init(); comSubsystem.connectModeTreeParent(EIVE_SYSTEM); diff --git a/mission/system/systemTree.h b/mission/system/systemTree.h index 9d769277..0ed73a89 100644 --- a/mission/system/systemTree.h +++ b/mission/system/systemTree.h @@ -5,7 +5,7 @@ namespace satsystem { -void init(); +void init(bool commandPlPcdu1); extern EiveSystem EIVE_SYSTEM; diff --git a/mission/system/tcs/TmpDevFdir.cpp b/mission/system/tcs/TmpDevFdir.cpp index d501dd1a..8c2b1706 100644 --- a/mission/system/tcs/TmpDevFdir.cpp +++ b/mission/system/tcs/TmpDevFdir.cpp @@ -20,7 +20,7 @@ ReturnValue_t TmpDevFdir::eventReceived(EventMessage* event) { // We'll try a recovery as long as defined in MAX_REBOOT. // Might cause some AssemblyBase cycles, so keep number low. // Ignored for TMP device, no way to power cycle it without going to OFF/BOOT mode. - // handleRecovery(event->getEvent()); + setFaulty(event->getEvent()); break; case DeviceHandlerIF::DEVICE_INTERPRETING_REPLY_FAILED: case DeviceHandlerIF::DEVICE_READING_REPLY_FAILED: @@ -28,8 +28,10 @@ ReturnValue_t TmpDevFdir::eventReceived(EventMessage* event) { case DeviceHandlerIF::DEVICE_UNKNOWN_REPLY: // Some DH's generate generic reply-ids. case DeviceHandlerIF::DEVICE_BUILDING_COMMAND_FAILED: // These faults all mean that there were stupid replies from a device. - // With now way to do a recovery, set the device to faulty immediately. - setFaulty(event->getEvent()); + // With no way to do a recovery, set the device to faulty instead of trying a recovery. + if (strangeReplyCount.incrementAndCheck()) { + setFaulty(event->getEvent()); + } break; case DeviceHandlerIF::DEVICE_SENDING_COMMAND_FAILED: case DeviceHandlerIF::DEVICE_REQUESTING_REPLY_FAILED: @@ -40,7 +42,9 @@ ReturnValue_t TmpDevFdir::eventReceived(EventMessage* event) { break; } // else - setFaulty(event->getEvent()); + if (missedReplyCount.incrementAndCheck()) { + setFaulty(event->getEvent()); + } break; case StorageManagerIF::GET_DATA_FAILED: case StorageManagerIF::STORE_DATA_FAILED: diff --git a/mission/system/tcs/tcsModeTree.cpp b/mission/system/tcs/tcsModeTree.cpp index 6cc57c6f..09a4fa61 100644 --- a/mission/system/tcs/tcsModeTree.cpp +++ b/mission/system/tcs/tcsModeTree.cpp @@ -10,8 +10,8 @@ TcsSubsystem satsystem::tcs::SUBSYSTEM(objects::TCS_SUBSYSTEM, 12, 24); namespace { // Alias for checker function const auto check = subsystem::checkInsert; -void buildOffSequence(Subsystem& ss, ModeListEntry& eh); -void buildNormalSequence(Subsystem& ss, ModeListEntry& eh); +void buildOffSequence(Subsystem& ss, ModeListEntry& eh, bool commandPlPcdu1); +void buildNormalSequence(Subsystem& ss, ModeListEntry& eh, bool commandPlPcdu1); } // namespace static const auto OFF = HasModesIF::MODE_OFF; @@ -27,17 +27,17 @@ auto TCS_TABLE_NORMAL_TGT = std::make_pair((NML << 24) | 1, FixedArrayList()); auto TCS_TABLE_NORMAL_TRANS_1 = std::make_pair((NML << 24) | 3, FixedArrayList()); -Subsystem& satsystem::tcs::init() { +Subsystem& satsystem::tcs::init(bool commandPlPcdu1) { ModeListEntry entry; - buildOffSequence(SUBSYSTEM, entry); - buildNormalSequence(SUBSYSTEM, entry); + buildOffSequence(SUBSYSTEM, entry, commandPlPcdu1); + buildNormalSequence(SUBSYSTEM, entry, commandPlPcdu1); SUBSYSTEM.setInitialMode(OFF); return SUBSYSTEM; } namespace { -void buildOffSequence(Subsystem& ss, ModeListEntry& eh) { +void buildOffSequence(Subsystem& ss, ModeListEntry& eh, bool commandPlPcdu1) { std::string context = "satsystem::tcs::buildOffSequence"; auto ctxc = context.c_str(); // Insert Helper Table @@ -67,7 +67,9 @@ void buildOffSequence(Subsystem& ss, ModeListEntry& eh) { iht(objects::TMP1075_HANDLER_TCS_0, OFF, 0, TCS_TABLE_OFF_TRANS_1.second); iht(objects::TMP1075_HANDLER_TCS_1, OFF, 0, TCS_TABLE_OFF_TRANS_1.second); iht(objects::TMP1075_HANDLER_PLPCDU_0, OFF, 0, TCS_TABLE_OFF_TRANS_1.second); - // TMP PL PCDU 1 is damaged + if (commandPlPcdu1) { + iht(objects::TMP1075_HANDLER_PLPCDU_1, OFF, 0, TCS_TABLE_OFF_TRANS_1.second); + } iht(objects::TMP1075_HANDLER_IF_BOARD, OFF, 0, TCS_TABLE_OFF_TRANS_1.second); check(ss.addTable(TableEntry(TCS_TABLE_OFF_TRANS_1.first, &TCS_TABLE_OFF_TRANS_1.second)), ctxc); @@ -79,7 +81,7 @@ void buildOffSequence(Subsystem& ss, ModeListEntry& eh) { ctxc); } -void buildNormalSequence(Subsystem& ss, ModeListEntry& eh) { +void buildNormalSequence(Subsystem& ss, ModeListEntry& eh, bool commandPlPcdu1) { std::string context = "satsystem::tcs::buildNormalSequence"; auto ctxc = context.c_str(); // Insert Helper Table @@ -105,7 +107,9 @@ void buildNormalSequence(Subsystem& ss, ModeListEntry& eh) { iht(objects::TMP1075_HANDLER_TCS_0, NML, 0, TCS_TABLE_NORMAL_TRANS_0.second); iht(objects::TMP1075_HANDLER_TCS_1, NML, 0, TCS_TABLE_NORMAL_TRANS_0.second); iht(objects::TMP1075_HANDLER_PLPCDU_0, NML, 0, TCS_TABLE_NORMAL_TRANS_0.second); - // TMP PL PCDU 1 is damaged + if (commandPlPcdu1) { + iht(objects::TMP1075_HANDLER_PLPCDU_1, NML, 0, TCS_TABLE_NORMAL_TRANS_0.second); + } iht(objects::TMP1075_HANDLER_IF_BOARD, NML, 0, TCS_TABLE_NORMAL_TRANS_0.second); check(ss.addTable(TableEntry(TCS_TABLE_NORMAL_TRANS_0.first, &TCS_TABLE_NORMAL_TRANS_0.second)), ctxc); diff --git a/mission/system/tcs/tcsModeTree.h b/mission/system/tcs/tcsModeTree.h index e5973641..4370ae73 100644 --- a/mission/system/tcs/tcsModeTree.h +++ b/mission/system/tcs/tcsModeTree.h @@ -7,7 +7,7 @@ namespace satsystem { namespace tcs { extern TcsSubsystem SUBSYSTEM; -Subsystem& init(); +Subsystem& init(bool commandPlPcdu1); } // namespace tcs } // namespace satsystem diff --git a/mission/tcs/HeaterHandler.cpp b/mission/tcs/HeaterHandler.cpp index 8416a7f7..b88dfe75 100644 --- a/mission/tcs/HeaterHandler.cpp +++ b/mission/tcs/HeaterHandler.cpp @@ -97,7 +97,7 @@ ReturnValue_t HeaterHandler::initialize() { ReturnValue_t HeaterHandler::initializeHeaterMap() { for (power::Switch_t switchNr = 0; switchNr < heater::NUMBER_OF_SWITCHES; switchNr++) { - heaterVec.push_back(HeaterWrapper(helper.heaters[switchNr], SwitchState::OFF)); + heaterVec.push_back(HeaterWrapper(helper.heaters[switchNr], heater::SwitchState::OFF)); } return returnvalue::OK; } @@ -214,7 +214,7 @@ ReturnValue_t HeaterHandler::sendSwitchCommand(uint8_t switchNr, ReturnValue_t o void HeaterHandler::handleSwitchHandling() { for (uint8_t idx = 0; idx < heater::NUMBER_OF_SWITCHES; idx++) { auto health = heaterVec[idx].healthDevice->getHealth(); - if (heaterVec[idx].switchState == SwitchState::ON) { + if (heaterVec[idx].switchState == heater::SwitchState::ON) { // If a heater is still on but the device was marked faulty by the operator, the SW // will shut down the heater if (health == HasHealthIF::FAULTY or health == HasHealthIF::PERMANENT_FAULTY) { @@ -277,7 +277,7 @@ void HeaterHandler::handleSwitchOnCommand(heater::Switch heaterIdx) { triggerEvent(HEATER_WENT_ON, heaterIdx, 0); { MutexGuard mg(handlerLock, LOCK_TYPE, LOCK_TIMEOUT, LOCK_CTX); - heater.switchState = ON; + heater.switchState = heater::SwitchState::ON; } EventManagerIF::triggerEvent(helper.heaters[heaterIdx].first->getObjectId(), MODE_INFO, MODE_ON, 0); @@ -326,10 +326,10 @@ void HeaterHandler::handleSwitchOffCommand(heater::Switch heaterIdx) { } if (result == returnvalue::OK) { // Check whether switch is already off - if (getSwitchState(heaterIdx) == SwitchState::ON) { + if (getSwitchState(heaterIdx) == heater::SwitchState::ON) { { MutexGuard mg(handlerLock, LOCK_TYPE, LOCK_TIMEOUT, LOCK_CTX); - heater.switchState = OFF; + heater.switchState = heater::SwitchState::OFF; } triggerEvent(HEATER_WENT_OFF, heaterIdx, 0); } else { @@ -356,15 +356,15 @@ void HeaterHandler::handleSwitchOffCommand(heater::Switch heaterIdx) { heater.cmdActive = false; } -HeaterHandler::SwitchState HeaterHandler::getSwitchState(heater::Switch switchNr) const { +heater::SwitchState HeaterHandler::getSwitchState(heater::Switch switchNr) const { MutexGuard mg(handlerLock, LOCK_TYPE, LOCK_TIMEOUT, LOCK_CTX); return heaterVec.at(switchNr).switchState; } -ReturnValue_t HeaterHandler::switchHeater(heater::Switch heater, SwitchState switchState) { - if (switchState == SwitchState::ON) { +ReturnValue_t HeaterHandler::switchHeater(heater::Switch heater, heater::SwitchState switchState) { + if (switchState == heater::SwitchState::ON) { return sendSwitchCommand(heater, PowerSwitchIF::SWITCH_ON); - } else if (switchState == SwitchState::OFF) { + } else if (switchState == heater::SwitchState::OFF) { return sendSwitchCommand(heater, PowerSwitchIF::SWITCH_OFF); } return returnvalue::FAILED; @@ -373,10 +373,10 @@ ReturnValue_t HeaterHandler::switchHeater(heater::Switch heater, SwitchState swi void HeaterHandler::announceMode(bool recursive) { triggerEvent(MODE_INFO, mode, submode); - std::array states; + std::array states; getAllSwitchStates(states); for (unsigned idx = 0; idx < helper.heaters.size(); idx++) { - if (states[idx] == ON) { + if (states[idx] == heater::SwitchState::ON) { EventManagerIF::triggerEvent(helper.heaters[idx].first->getObjectId(), MODE_INFO, MODE_ON, 0); } else { EventManagerIF::triggerEvent(helper.heaters[idx].first->getObjectId(), MODE_INFO, MODE_OFF, @@ -405,7 +405,7 @@ ModeTreeChildIF& HeaterHandler::getModeTreeChildIF() { return *this; } object_id_t HeaterHandler::getObjectId() const { return SystemObject::getObjectId(); } -ReturnValue_t HeaterHandler::getAllSwitchStates(std::array& statesBuf) { +ReturnValue_t HeaterHandler::getAllSwitchStates(std::array& statesBuf) { { MutexGuard mg(handlerLock, LOCK_TYPE, LOCK_TIMEOUT, LOCK_CTX); if (mg.getLockResult() != returnvalue::OK) { @@ -419,13 +419,13 @@ ReturnValue_t HeaterHandler::getAllSwitchStates(std::array& stat } bool HeaterHandler::allSwitchesOff() { - bool allSwitchesOrd = false; MutexGuard mg(handlerLock, LOCK_TYPE, LOCK_TIMEOUT, LOCK_CTX); - /* Or all switches. As soon one switch is on, allSwitchesOrd will be true */ for (power::Switch_t switchNr = 0; switchNr < heater::NUMBER_OF_SWITCHES; switchNr++) { - allSwitchesOrd = allSwitchesOrd || heaterVec.at(switchNr).switchState; + if (heaterVec.at(switchNr).switchState == heater::SwitchState::ON) { + return false; + } } - return !allSwitchesOrd; + return true; } MessageQueueId_t HeaterHandler::getCommandQueue() const { return commandQueue->getId(); } @@ -440,7 +440,7 @@ ReturnValue_t HeaterHandler::getSwitchState(uint8_t switchNr) const { if (switchNr > 7) { return returnvalue::FAILED; } - if (getSwitchState(static_cast(switchNr)) == SwitchState::ON) { + if (getSwitchState(static_cast(switchNr)) == heater::SwitchState::ON) { return PowerSwitchIF::SWITCH_ON; } return PowerSwitchIF::SWITCH_OFF; diff --git a/mission/tcs/HeaterHandler.h b/mission/tcs/HeaterHandler.h index 0198ab04..4901c505 100644 --- a/mission/tcs/HeaterHandler.h +++ b/mission/tcs/HeaterHandler.h @@ -60,7 +60,6 @@ class HeaterHandler : public ExecutableObjectIF, static const ReturnValue_t COMMAND_ALREADY_WAITING = MAKE_RETURN_CODE(0xA5); enum CmdSourceParam : uint8_t { INTERNAL = 0, EXTERNAL = 1 }; - enum SwitchState : uint8_t { ON = 1, OFF = 0 }; /** Device command IDs */ static const DeviceCommandId_t SWITCH_HEATER = 0x0; @@ -69,14 +68,14 @@ class HeaterHandler : public ExecutableObjectIF, PowerSwitchIF* mainLineSwitcherObjectId, power::Switch_t mainLineSwitch); ReturnValue_t connectModeTreeParent(HasModeTreeChildrenIF& parent) override; - ReturnValue_t getAllSwitchStates(std::array& statesBuf); + ReturnValue_t getAllSwitchStates(std::array& statesBuf); virtual ~HeaterHandler(); protected: enum SwitchAction : uint8_t { SET_SWITCH_OFF, SET_SWITCH_ON, NONE }; - ReturnValue_t switchHeater(heater::Switch heater, SwitchState switchState); + ReturnValue_t switchHeater(heater::Switch heater, heater::SwitchState switchState); HasHealthIF::HealthState getHealth(heater::Switch heater); ReturnValue_t performOperation(uint8_t operationCode = 0) override; @@ -121,14 +120,14 @@ class HeaterHandler : public ExecutableObjectIF, * @param mainSwitchCountdown Sets timeout to wait for main switch being set on. */ struct HeaterWrapper { - HeaterWrapper(HeaterPair pair, SwitchState initState) + HeaterWrapper(HeaterPair pair, heater::SwitchState initState) : healthDevice(pair.first), gpioId(pair.second), switchState(initState) {} HealthDevice* healthDevice = nullptr; gpioId_t gpioId = gpio::NO_GPIO; SwitchAction action = SwitchAction::NONE; MessageQueueId_t replyQueue = MessageQueueIF::NO_QUEUE; bool cmdActive = false; - SwitchState switchState = SwitchState::OFF; + heater::SwitchState switchState = heater::SwitchState::OFF; bool waitMainSwitchOn = false; Countdown mainSwitchCountdown; }; @@ -177,7 +176,7 @@ class HeaterHandler : public ExecutableObjectIF, * @brief Returns the state of a switch (ON - true, or OFF - false). * @param switchNr The number of the switch to check. */ - SwitchState getSwitchState(heater::Switch switchNr) const; + heater::SwitchState getSwitchState(heater::Switch switchNr) const; /** * @brief This function runs commands waiting for execution. diff --git a/mission/tcs/Tmp1075Handler.cpp b/mission/tcs/Tmp1075Handler.cpp index 30331e1f..7e8569b6 100644 --- a/mission/tcs/Tmp1075Handler.cpp +++ b/mission/tcs/Tmp1075Handler.cpp @@ -1,4 +1,5 @@ #include +#include #include #include @@ -11,14 +12,12 @@ Tmp1075Handler::Tmp1075Handler(object_id_t objectId, object_id_t comIF, CookieIF Tmp1075Handler::~Tmp1075Handler() {} -void Tmp1075Handler::doStartUp() { - if (getMode() == _MODE_START_UP) { - setMode(MODE_ON); - } -} +void Tmp1075Handler::doStartUp() { setMode(MODE_ON); } void Tmp1075Handler::doShutDown() { communicationStep = CommunicationStep::START_ADC_CONVERSION; + PoolReadGuard pg(&dataset); + dataset.setValidity(false, true); setMode(_MODE_POWER_DOWN); } @@ -134,12 +133,14 @@ ReturnValue_t Tmp1075Handler::initializeLocalDataPool(localpool::DataPool &local return returnvalue::OK; } -void Tmp1075Handler::setModeNormal() { setMode(_MODE_TO_NORMAL); } - ReturnValue_t Tmp1075Handler::setHealth(HealthState health) { if (health != FAULTY and health != PERMANENT_FAULTY and health != HEALTHY and health != EXTERNAL_CONTROL) { return returnvalue::FAILED; } - return returnvalue::OK; + // Required because we do not have an assembly. + if (health == FAULTY or health == PERMANENT_FAULTY) { + setMode(_MODE_SHUT_DOWN); + } + return DeviceHandlerBase::setHealth(health); } diff --git a/mission/tcs/Tmp1075Handler.h b/mission/tcs/Tmp1075Handler.h index 02fd6823..4badca39 100644 --- a/mission/tcs/Tmp1075Handler.h +++ b/mission/tcs/Tmp1075Handler.h @@ -20,8 +20,6 @@ class Tmp1075Handler : public DeviceHandlerBase { Tmp1075Handler(object_id_t objectId, object_id_t comIF, CookieIF *comCookie); virtual ~Tmp1075Handler(); - void setModeNormal(); - protected: void doStartUp() override; void doShutDown() override; diff --git a/mission/tcs/defs.h b/mission/tcs/defs.h index 747dbc6d..e2843570 100644 --- a/mission/tcs/defs.h +++ b/mission/tcs/defs.h @@ -4,6 +4,7 @@ #include namespace heater { + enum Switch : uint8_t { HEATER_0_PLOC_PROC_BRD, HEATER_1_PCDU_PDU, @@ -13,9 +14,13 @@ enum Switch : uint8_t { HEATER_5_STR, HEATER_6_DRO, HEATER_7_S_BAND, - NUMBER_OF_SWITCHES + NUMBER_OF_SWITCHES = 8, + HEATER_NONE = 0xff }; -} + +enum SwitchState : uint8_t { ON = 1, OFF = 0 }; + +} // namespace heater namespace tcs { diff --git a/tmtc b/tmtc index 18304c31..9be81f17 160000 --- a/tmtc +++ b/tmtc @@ -1 +1 @@ -Subproject commit 18304c31fa423b1af6ff47764d4be81c7f20c8f2 +Subproject commit 9be81f1725004b55e937718fbaddc4f4e4e74081 diff --git a/unittest/controller/testThermalController.cpp b/unittest/controller/testThermalController.cpp index c2166ca0..287943ce 100644 --- a/unittest/controller/testThermalController.cpp +++ b/unittest/controller/testThermalController.cpp @@ -30,7 +30,8 @@ TEST_CASE("Thermal Controller", "[ThermalController]") { // testEnvironment::initialize(); - ThermalController controller(THERMAL_CONTROLLER_ID, *heaterHandler, tcsBrdShortlyUnavailable); + ThermalController controller(THERMAL_CONTROLLER_ID, *heaterHandler, tcsBrdShortlyUnavailable, + true); ReturnValue_t result = controller.initialize(); REQUIRE(result == returnvalue::OK);