From f932c4c2c5880f5f64e1b63b765f62bbfe31b00c Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Thu, 24 Nov 2022 16:40:59 +0100 Subject: [PATCH] we need a dummy heater handler --- bsp_hosted/ObjectFactory.cpp | 2 +- .../fsfwconfig/objects/systemObjectList.h | 3 +- dummies/CMakeLists.txt | 2 +- dummies/TemperatureSensorInserter.cpp | 37 ++++++ dummies/TemperatureSensorInserter.h | 22 ++++ dummies/TemperatureSensorsDummy.cpp | 106 ------------------ dummies/TemperatureSensorsDummy.h | 30 ----- dummies/helpers.cpp | 5 +- mission/controller/ThermalController.cpp | 2 +- mission/controller/ThermalController.h | 40 ++++--- unittest/controller/testThermalController.cpp | 6 +- 11 files changed, 94 insertions(+), 161 deletions(-) create mode 100644 dummies/TemperatureSensorInserter.cpp create mode 100644 dummies/TemperatureSensorInserter.h delete mode 100644 dummies/TemperatureSensorsDummy.cpp delete mode 100644 dummies/TemperatureSensorsDummy.h diff --git a/bsp_hosted/ObjectFactory.cpp b/bsp_hosted/ObjectFactory.cpp index 6db37e93..07e3163b 100644 --- a/bsp_hosted/ObjectFactory.cpp +++ b/bsp_hosted/ObjectFactory.cpp @@ -45,8 +45,8 @@ #include #include #include -#include +#include "../dummies/TemperatureSensorInserter.h" #include "dummies/helpers.h" #include "mission/utility/GlobalConfigHandler.h" diff --git a/bsp_hosted/fsfwconfig/objects/systemObjectList.h b/bsp_hosted/fsfwconfig/objects/systemObjectList.h index 703cd8b8..a1f9c20b 100644 --- a/bsp_hosted/fsfwconfig/objects/systemObjectList.h +++ b/bsp_hosted/fsfwconfig/objects/systemObjectList.h @@ -24,7 +24,8 @@ enum sourceObjects : uint32_t { /* 0x49 ('I') for Communication Interfaces **/ ARDUINO_COM_IF = 0x49000001, - DUMMY_COM_IF = 0x49000002 + DUMMY_COM_IF = 0x49000002, + THERMAL_TEMP_INSERTER = 0x49000003, }; } diff --git a/dummies/CMakeLists.txt b/dummies/CMakeLists.txt index 677120fb..4f486f8a 100644 --- a/dummies/CMakeLists.txt +++ b/dummies/CMakeLists.txt @@ -1,6 +1,6 @@ target_sources( ${LIB_DUMMIES} - PUBLIC TemperatureSensorsDummy.cpp + PUBLIC TemperatureSensorInserter.cpp SusDummy.cpp BpxDummy.cpp ComIFDummy.cpp diff --git a/dummies/TemperatureSensorInserter.cpp b/dummies/TemperatureSensorInserter.cpp new file mode 100644 index 00000000..ed71968c --- /dev/null +++ b/dummies/TemperatureSensorInserter.cpp @@ -0,0 +1,37 @@ +#include "TemperatureSensorInserter.h" + +#include + +#include +#include + +TemperatureSensorInserter::TemperatureSensorInserter(object_id_t objectId) + : SystemObject(objects::THERMAL_CONTROLLER), + max31865PlocHeatspreaderSet(objects::RTD_0_IC3_PLOC_HEATSPREADER, MAX31865::MAX31865_SET_ID), + max31865PlocMissionboardSet(objects::RTD_1_IC4_PLOC_MISSIONBOARD, MAX31865::MAX31865_SET_ID) { +} + +ReturnValue_t TemperatureSensorInserter::initialize() { + max31865PlocHeatspreaderSet.temperatureCelcius = 20.0; + max31865PlocMissionboardSet.temperatureCelcius = 20.0; + return returnvalue::OK; +} + +ReturnValue_t TemperatureSensorInserter::performOperation(uint8_t opCode) { + iteration++; + value = sin(iteration / 80. * M_PI) * 10; + + ReturnValue_t result = max31865PlocHeatspreaderSet.read(); + if (result != returnvalue::OK) { + sif::warning << "Failed to read temperature from MAX31865 dataset" << std::endl; + } + max31865PlocHeatspreaderSet.rtdValue = value - 5; + max31865PlocHeatspreaderSet.temperatureCelcius = value; + if ((iteration % 100) < 20) { + max31865PlocHeatspreaderSet.setValidity(false, true); + } else { + max31865PlocHeatspreaderSet.setValidity(true, true); + } + max31865PlocHeatspreaderSet.commit(); + return returnvalue::OK; +} diff --git a/dummies/TemperatureSensorInserter.h b/dummies/TemperatureSensorInserter.h new file mode 100644 index 00000000..84b1bcdb --- /dev/null +++ b/dummies/TemperatureSensorInserter.h @@ -0,0 +1,22 @@ +#pragma once + +#include +#include + +class TemperatureSensorInserter : public ExecutableObjectIF, public SystemObject { + public: + TemperatureSensorInserter(object_id_t objectId); + + ReturnValue_t initialize() override; + + protected: + ReturnValue_t performOperation(uint8_t opCode) override; + + private: + int iteration = 0; + float value = 0; + MAX31865::Max31865Set max31865PlocHeatspreaderSet; + MAX31865::Max31865Set max31865PlocMissionboardSet; + + void noise(); +}; diff --git a/dummies/TemperatureSensorsDummy.cpp b/dummies/TemperatureSensorsDummy.cpp deleted file mode 100644 index 3f6a4d83..00000000 --- a/dummies/TemperatureSensorsDummy.cpp +++ /dev/null @@ -1,106 +0,0 @@ -#include "TemperatureSensorsDummy.h" - -#include - -#include -#include - -TemperatureSensorsDummy::TemperatureSensorsDummy() - : ExtendedControllerBase(objects::RTD_0_IC3_PLOC_HEATSPREADER), - max31865PlocHeatspreaderSet(objects::RTD_0_IC3_PLOC_HEATSPREADER, MAX31865::MAX31865_SET_ID), - max31865PlocMissionboardSet(objects::RTD_1_IC4_PLOC_MISSIONBOARD, MAX31865::MAX31865_SET_ID) { - ObjectManager::instance()->insert(objects::RTD_1_IC4_PLOC_MISSIONBOARD, this); - ObjectManager::instance()->insert(objects::RTD_2_IC5_4K_CAMERA, this); - ObjectManager::instance()->insert(objects::RTD_3_IC6_DAC_HEATSPREADER, this); - ObjectManager::instance()->insert(objects::RTD_4_IC7_STARTRACKER, this); - ObjectManager::instance()->insert(objects::RTD_5_IC8_RW1_MX_MY, this); - ObjectManager::instance()->insert(objects::RTD_6_IC9_DRO, this); - ObjectManager::instance()->insert(objects::RTD_7_IC10_SCEX, this); - ObjectManager::instance()->insert(objects::RTD_8_IC11_X8, this); - ObjectManager::instance()->insert(objects::RTD_9_IC12_HPA, this); - ObjectManager::instance()->insert(objects::RTD_10_IC13_PL_TX, this); - ObjectManager::instance()->insert(objects::RTD_11_IC14_MPA, this); - ObjectManager::instance()->insert(objects::RTD_12_IC15_ACU, this); - ObjectManager::instance()->insert(objects::RTD_13_IC16_PLPCDU_HEATSPREADER, this); - ObjectManager::instance()->insert(objects::RTD_14_IC17_TCS_BOARD, this); - ObjectManager::instance()->insert(objects::RTD_15_IC18_IMTQ, this); - ObjectManager::instance()->insert(objects::TMP1075_HANDLER_TCS_0, this); - ObjectManager::instance()->insert(objects::TMP1075_HANDLER_TCS_1, this); - - ObjectManager::instance()->insert(objects::TMP1075_HANDLER_PLPCDU_0, this); - ObjectManager::instance()->insert(objects::TMP1075_HANDLER_PLPCDU_1, this); - ObjectManager::instance()->insert(objects::TMP1075_HANDLER_IF_BOARD, this); -} - -ReturnValue_t TemperatureSensorsDummy::initialize() { - static bool done = false; - if (not done) { - done = true; - ReturnValue_t result = ExtendedControllerBase::initialize(); - if (result != returnvalue::OK) { - return result; - } - } - - max31865PlocHeatspreaderSet.temperatureCelcius = 20.0; - max31865PlocMissionboardSet.temperatureCelcius = 20.0; - return returnvalue::OK; -} - -ReturnValue_t TemperatureSensorsDummy::handleCommandMessage(CommandMessage* message) { - return returnvalue::FAILED; -} - -void TemperatureSensorsDummy::performControlOperation() { - iteration++; - value = sin(iteration / 80. * M_PI) * 10; - - ReturnValue_t result = max31865PlocHeatspreaderSet.read(); - if (result != returnvalue::OK) { - sif::warning << "Failed to read temperature from MAX31865 dataset" << std::endl; - } - max31865PlocHeatspreaderSet.rtdValue = value - 5; - max31865PlocHeatspreaderSet.temperatureCelcius = value; - if ((iteration % 100) < 20) { - max31865PlocHeatspreaderSet.setValidity(false, true); - } else { - max31865PlocHeatspreaderSet.setValidity(true, true); - } - max31865PlocHeatspreaderSet.commit(); -} - -ReturnValue_t TemperatureSensorsDummy::initializeLocalDataPool( - localpool::DataPool& localDataPoolMap, LocalDataPoolManager& poolManager) { - localDataPoolMap.emplace(static_cast(MAX31865::PoolIds::RTD_VALUE), - new PoolEntry({0})); - localDataPoolMap.emplace(static_cast(MAX31865::PoolIds::TEMPERATURE_C), - new PoolEntry({0})); - localDataPoolMap.emplace(static_cast(MAX31865::PoolIds::LAST_FAULT_BYTE), - new PoolEntry({0})); - localDataPoolMap.emplace(static_cast(MAX31865::PoolIds::FAULT_BYTE), - new PoolEntry({0})); - - return returnvalue::OK; -} - -LocalPoolDataSetBase* TemperatureSensorsDummy::getDataSetHandle(sid_t sid) { - sif::debug << "getHandle" << std::endl; - if (sid.objectId == objects::RTD_0_IC3_PLOC_HEATSPREADER) { - return &max31865PlocHeatspreaderSet; - } else if (sid.objectId == objects::RTD_1_IC4_PLOC_MISSIONBOARD) { - return &max31865PlocMissionboardSet; - } else { - return nullptr; - } -} - -ReturnValue_t TemperatureSensorsDummy::checkModeCommand(Mode_t mode, Submode_t submode, - uint32_t* msToReachTheMode) { - if (submode != SUBMODE_NONE) { - return INVALID_SUBMODE; - } - if ((mode != MODE_OFF) && (mode != MODE_ON) && (mode != MODE_NORMAL)) { - return INVALID_MODE; - } - return returnvalue::OK; -} diff --git a/dummies/TemperatureSensorsDummy.h b/dummies/TemperatureSensorsDummy.h deleted file mode 100644 index 0fcdfadb..00000000 --- a/dummies/TemperatureSensorsDummy.h +++ /dev/null @@ -1,30 +0,0 @@ -#pragma once - -#include -#include - -class TemperatureSensorsDummy : public ExtendedControllerBase { - public: - TemperatureSensorsDummy(); - - ReturnValue_t initialize() override; - - protected: - virtual ReturnValue_t handleCommandMessage(CommandMessage* message) override; - virtual void performControlOperation() override; - virtual ReturnValue_t initializeLocalDataPool(localpool::DataPool& localDataPoolMap, - LocalDataPoolManager& poolManager) override; - virtual LocalPoolDataSetBase* getDataSetHandle(sid_t sid) override; - - // Mode abstract functions - virtual ReturnValue_t checkModeCommand(Mode_t mode, Submode_t submode, - uint32_t* msToReachTheMode) override; - - private: - int iteration = 0; - float value = 0; - MAX31865::Max31865Set max31865PlocHeatspreaderSet; - MAX31865::Max31865Set max31865PlocMissionboardSet; - - void noise(); -}; diff --git a/dummies/helpers.cpp b/dummies/helpers.cpp index c489d3a0..9d449699 100644 --- a/dummies/helpers.cpp +++ b/dummies/helpers.cpp @@ -18,9 +18,10 @@ #include #include #include -#include #include +#include "TemperatureSensorInserter.h" + using namespace dummy; void dummy::createDummies(DummyCfg cfg, PowerSwitchIF& pwrSwitch) { @@ -66,7 +67,7 @@ void dummy::createDummies(DummyCfg cfg, PowerSwitchIF& pwrSwitch) { } if (cfg.addTempSensorDummies) { - new TemperatureSensorsDummy(); + new TemperatureSensorInserter(objects::THERMAL_TEMP_INSERTER); } new CamSwitcher(objects::CAM_SWITCHER, pwrSwitch, power::NO_SWITCH); new PlPcduDummy(objects::PLPCDU_HANDLER, objects::DUMMY_COM_IF, comCookieDummy); diff --git a/mission/controller/ThermalController.cpp b/mission/controller/ThermalController.cpp index 10a14b15..2026e851 100644 --- a/mission/controller/ThermalController.cpp +++ b/mission/controller/ThermalController.cpp @@ -16,7 +16,7 @@ ThermalController::ThermalController(object_id_t objectId, HeaterHandler& heater) : ExtendedControllerBase(objectId), - heater(heater), + heaterHandler(heater), sensorTemperatures(this), susTemperatures(this), deviceTemperatures(this), diff --git a/mission/controller/ThermalController.h b/mission/controller/ThermalController.h index 541737ba..44e2fb1a 100644 --- a/mission/controller/ThermalController.h +++ b/mission/controller/ThermalController.h @@ -8,20 +8,25 @@ #include #include +#include "../devices/HeaterHandler.h" + /** * 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 + * 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 opUpperLimit, float nopUpperLimit) : opLowerLimit(opLowerLimit), opUpperLimit(opUpperLimit), nopLowerLimit(nopLowerLimit), nopUpperLimit(nopUpperLimit) {} + TempLimits(float nopLowerLimit, float opLowerLimit, float opUpperLimit, float nopUpperLimit) + : opLowerLimit(opLowerLimit), + opUpperLimit(opUpperLimit), + nopLowerLimit(nopLowerLimit), + nopUpperLimit(nopUpperLimit) {} float opLowerLimit; float opUpperLimit; float nopLowerLimit; float nopUpperLimit; - //TODO define limits - + // TODO define limits }; class ThermalController : public ExtendedControllerBase { @@ -50,6 +55,8 @@ class ThermalController : public ExtendedControllerBase { InternalState internalState = InternalState::STARTUP; + HeaterHandler& heaterHandler; + thermalControllerDefinitions::SensorTemperatures sensorTemperatures; thermalControllerDefinitions::SusTemperatures susTemperatures; thermalControllerDefinitions::DeviceTemperatures deviceTemperatures; @@ -91,24 +98,23 @@ class ThermalController : public ExtendedControllerBase { SUS::SusDataset susSet10; SUS::SusDataset susSet11; - //TempLimits - //TempLimits plocHeatspreaderLimits = TempLimits(-20.0, 70.0, -30.0, 80.0); - //TempLimits plocMissionBoardLimits = TempLimits(-20.0, 70.0, -30.0, 80.0); + // TempLimits + // TempLimits plocHeatspreaderLimits = TempLimits(-20.0, 70.0, -30.0, 80.0); + // TempLimits plocMissionBoardLimits = TempLimits(-20.0, 70.0, -30.0, 80.0); TempLimits cameraLimits = TempLimits(-40.0, -30.0, 65.0, 85.0); TempLimits dacHeatspreaderLimits = TempLimits(-65.0, -40.0, 118.0, 150.0); TempLimits strLimits = TempLimits(-30.0, -20.0, 70.0, 80.0); TempLimits rw1Limits = TempLimits(-40.0, -40.0, 85.0, 85.0); - //TempLimits droLimits = TempLimits(-20.0, 70.0, -30.0, 80.0); + // TempLimits droLimits = TempLimits(-20.0, 70.0, -30.0, 80.0); TempLimits scexLimits = TempLimits(-60.0, -40.0, 85.0, 150.0); - //TempLimits x8Limits = TempLimits(-20.0, 70.0, -30.0, 80.0); - //TempLimits hpaLimits = TempLimits(-20.0, 70.0, -30.0, 80.0); - //TempLimits txModuleLimits = TempLimits(-20.0, 70.0, -30.0, 80.0); - //TempLimits mpaLimits = TempLimits(-20.0, 70.0, -30.0, 80.0); - TempLimits acuLimits = TempLimits(-55.0, -35.0, 85.0, 150.0); //TODO nopLimits - TempLimits plpcduHeatspreaderLimits = TempLimits(-65.0, -40.0, 85.0, 125.0); //TODO check + // TempLimits x8Limits = TempLimits(-20.0, 70.0, -30.0, 80.0); + // TempLimits hpaLimits = TempLimits(-20.0, 70.0, -30.0, 80.0); + // TempLimits txModuleLimits = TempLimits(-20.0, 70.0, -30.0, 80.0); + // TempLimits mpaLimits = TempLimits(-20.0, 70.0, -30.0, 80.0); + TempLimits acuLimits = TempLimits(-55.0, -35.0, 85.0, 150.0); // TODO nopLimits + TempLimits plpcduHeatspreaderLimits = TempLimits(-65.0, -40.0, 85.0, 125.0); // TODO check TempLimits tcsBoardLimits = TempLimits(-60.0, -40.0, 85.0, 130.0); - TempLimits magnettorquerLimits = TempLimits(-40.0, -30.0, 70.0, 80.0); //TODO nopLimits - + TempLimits magnettorquerLimits = TempLimits(-40.0, -30.0, 70.0, 80.0); // TODO nopLimits // Initial delay to make sure all pool variables have been initialized their owners Countdown initialCountdown = Countdown(DELAY); diff --git a/unittest/controller/testThermalController.cpp b/unittest/controller/testThermalController.cpp index 3fac0f4e..976f3c4b 100644 --- a/unittest/controller/testThermalController.cpp +++ b/unittest/controller/testThermalController.cpp @@ -1,5 +1,4 @@ #include -#include #include #include #include @@ -7,12 +6,15 @@ #include +#include "../../dummies/TemperatureSensorInserter.h" #include "../testEnvironment.h" TEST_CASE("Thermal Controller", "[ThermalController]") { const object_id_t THERMAL_CONTROLLER_ID = 0x123; - new TemperatureSensorsDummy(); + new TemperatureSensorInserter(objects::THERMAL_TEMP_INSERTER); + // TODO: Create dummy heater handler + // new HeaterHandler() new SusDummy(); // testEnvironment::initialize();