eive-obsw/mission/controller/ThermalController.cpp
Ulrich Mohr c024756540
Some checks failed
EIVE/eive-obsw/pipeline/head There was a failure building this commit
WIP extending thermal controller
2022-05-23 00:37:49 +02:00

237 lines
10 KiB
C++

#include "ThermalController.h"
#include <fsfw/datapool/PoolReadGuard.h>
#include <objects/systemObjectList.h>
ThermalController::ThermalController(object_id_t objectId, object_id_t parentId)
: ExtendedControllerBase(objectId, parentId),
sensorTemperatures(this),
deviceTemperatures(this),
componentTemperatures(this),
max31865Set0(objects::RTD_0_IC3_PLOC_HEATSPREADER),
max31865Set1(objects::RTD_1_IC4_PLOC_MISSIONBOARD),
max31865Set2(objects::RTD_2_IC5_4K_CAMERA),
max31865Set3(objects::RTD_3_IC6_DAC_HEATSPREADER),
max31865Set4(objects::RTD_4_IC7_STARTRACKER),
max31865Set5(objects::RTD_5_IC8_RW1_MX_MY),
max31865Set6(objects::RTD_6_IC9_DRO),
max31865Set7(objects::RTD_7_IC10_SCEX),
max31865Set8(objects::RTD_8_IC11_X8),
max31865Set9(objects::RTD_9_IC12_HPA),
max31865Set10(objects::RTD_10_IC13_PL_TX),
max31865Set11(objects::RTD_11_IC14_MPA),
max31865Set12(objects::RTD_12_IC15_ACU),
max31865Set13(objects::RTD_13_IC16_PLPCDU_HEATSPREADER),
max31865Set14(objects::RTD_14_IC17_TCS_BOARD),
max31865Set15(objects::RTD_15_IC18_IMTQ),
tmp1075Set1(objects::TMP1075_HANDLER_1),
tmp1075Set2(objects::TMP1075_HANDLER_2) {}
ReturnValue_t ThermalController::initialize() {
auto result = ExtendedControllerBase::initialize();
return result;
}
ReturnValue_t ThermalController::handleCommandMessage(CommandMessage* message) {
return RETURN_FAILED;
}
void ThermalController::performControlOperation() {
ReturnValue_t result = sensorTemperatures.read();
if (result == RETURN_OK) {
copySensors();
sensorTemperatures.commit();
}
result = deviceTemperatures.read();
if (result == RETURN_OK) {
copyDevices();
deviceTemperatures.commit();
}
result = componentTemperatures.read();
if (result != RETURN_OK) {
return;
}
componentTemperatures.commit();
}
ReturnValue_t ThermalController::initializeLocalDataPool(localpool::DataPool& localDataPoolMap,
LocalDataPoolManager& poolManager) {
localDataPoolMap.emplace(thermalControllerDefinitions::SENSOR_PLOC_HEATSPREADER,
new PoolEntry<float>({0.0}));
localDataPoolMap.emplace(thermalControllerDefinitions::SENSOR_PLOC_MISSIONBOARD,
new PoolEntry<float>({1.0}));
localDataPoolMap.emplace(thermalControllerDefinitions::SENSOR_4K_CAMERA,
new PoolEntry<float>({2.0}));
localDataPoolMap.emplace(thermalControllerDefinitions::SENSOR_DAC_HEATSPREADER,
new PoolEntry<float>({3.0}));
localDataPoolMap.emplace(thermalControllerDefinitions::SENSOR_STARTRACKER,
new PoolEntry<float>({4.0}));
localDataPoolMap.emplace(thermalControllerDefinitions::SENSOR_RW1, new PoolEntry<float>({5.0}));
localDataPoolMap.emplace(thermalControllerDefinitions::SENSOR_DRO, new PoolEntry<float>({6.0}));
localDataPoolMap.emplace(thermalControllerDefinitions::SENSOR_SCEX, new PoolEntry<float>({7.0}));
localDataPoolMap.emplace(thermalControllerDefinitions::SENSOR_X8, new PoolEntry<float>({8.0}));
localDataPoolMap.emplace(thermalControllerDefinitions::SENSOR_HPA, new PoolEntry<float>({9.0}));
localDataPoolMap.emplace(thermalControllerDefinitions::SENSOR_TX_MODUL,
new PoolEntry<float>({10.0}));
localDataPoolMap.emplace(thermalControllerDefinitions::SENSOR_MPA, new PoolEntry<float>({11.0}));
localDataPoolMap.emplace(thermalControllerDefinitions::SENSOR_ACU, new PoolEntry<float>({12.0}));
localDataPoolMap.emplace(thermalControllerDefinitions::SENSOR_PLPCDU_HEATSPREADER,
new PoolEntry<float>({13.0}));
localDataPoolMap.emplace(thermalControllerDefinitions::SENSOR_TCS_BOARD,
new PoolEntry<float>({14.0}));
localDataPoolMap.emplace(thermalControllerDefinitions::SENSOR_MAGNETTORQUER,
new PoolEntry<float>({15.0}));
localDataPoolMap.emplace(thermalControllerDefinitions::SENSOR_TMP1075_1,
new PoolEntry<float>({15.0}));
localDataPoolMap.emplace(thermalControllerDefinitions::SENSOR_TMP1075_2,
new PoolEntry<float>({15.0}));
localDataPoolMap.emplace(thermalControllerDefinitions::COMPONENT_RW, new PoolEntry<float>({0.0}));
poolManager.subscribeForPeriodicPacket(sensorTemperatures.getSid(), true, 1.0, false);
return RETURN_OK;
}
LocalPoolDataSetBase* ThermalController::getDataSetHandle(sid_t sid) {
switch (sid.ownerSetId) {
case thermalControllerDefinitions::SENSOR_TEMPERATURES:
return &sensorTemperatures;
case thermalControllerDefinitions::COMPONENT_TEMPERATURES:
return &componentTemperatures;
default:
return nullptr;
}
}
ReturnValue_t ThermalController::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 RETURN_OK;
}
void ThermalController::copySensors() {
PoolReadGuard pg0(&max31865Set0);
if (pg0.getReadResult() == HasReturnvaluesIF::RETURN_OK) {
sensorTemperatures.sensor_ploc_heatspreader.value = max31865Set0.temperatureCelcius.value;
sensorTemperatures.sensor_ploc_heatspreader.setValid(max31865Set0.temperatureCelcius.isValid());
}
PoolReadGuard pg1(&max31865Set1);
if (pg1.getReadResult() == HasReturnvaluesIF::RETURN_OK) {
sensorTemperatures.sensor_ploc_missionboard.value = max31865Set1.temperatureCelcius.value;
sensorTemperatures.sensor_ploc_missionboard.setValid(max31865Set1.temperatureCelcius.isValid());
}
PoolReadGuard pg2(&max31865Set2);
if (pg2.getReadResult() == HasReturnvaluesIF::RETURN_OK) {
sensorTemperatures.sensor_4k_camera.value = max31865Set2.temperatureCelcius.value;
sensorTemperatures.sensor_4k_camera.setValid(max31865Set2.temperatureCelcius.isValid());
}
PoolReadGuard pg3(&max31865Set3);
if (pg3.getReadResult() == HasReturnvaluesIF::RETURN_OK) {
sensorTemperatures.sensor_dac_heatspreader.value = max31865Set3.temperatureCelcius.value;
sensorTemperatures.sensor_dac_heatspreader.setValid(max31865Set3.temperatureCelcius.isValid());
}
PoolReadGuard pg4(&max31865Set4);
if (pg4.getReadResult() == HasReturnvaluesIF::RETURN_OK) {
sensorTemperatures.sensor_startracker.value = max31865Set4.temperatureCelcius.value;
sensorTemperatures.sensor_startracker.setValid(max31865Set4.temperatureCelcius.isValid());
}
PoolReadGuard pg5(&max31865Set5);
if (pg5.getReadResult() == HasReturnvaluesIF::RETURN_OK) {
sensorTemperatures.sensor_rw1.value = max31865Set5.temperatureCelcius.value;
sensorTemperatures.sensor_rw1.setValid(max31865Set5.temperatureCelcius.isValid());
}
PoolReadGuard pg6(&max31865Set6);
if (pg6.getReadResult() == HasReturnvaluesIF::RETURN_OK) {
sensorTemperatures.sensor_dro.value = max31865Set6.temperatureCelcius.value;
sensorTemperatures.sensor_dro.setValid(max31865Set6.temperatureCelcius.isValid());
}
PoolReadGuard pg7(&max31865Set7);
if (pg7.getReadResult() == HasReturnvaluesIF::RETURN_OK) {
sensorTemperatures.sensor_scex.value = max31865Set7.temperatureCelcius.value;
sensorTemperatures.sensor_scex.setValid(max31865Set7.temperatureCelcius.isValid());
}
PoolReadGuard pg8(&max31865Set8);
if (pg8.getReadResult() == HasReturnvaluesIF::RETURN_OK) {
sensorTemperatures.sensor_x8.value = max31865Set8.temperatureCelcius.value;
sensorTemperatures.sensor_x8.setValid(max31865Set8.temperatureCelcius.isValid());
}
PoolReadGuard pg9(&max31865Set9);
if (pg9.getReadResult() == HasReturnvaluesIF::RETURN_OK) {
sensorTemperatures.sensor_hpa.value = max31865Set9.temperatureCelcius.value;
sensorTemperatures.sensor_hpa.setValid(max31865Set9.temperatureCelcius.isValid());
}
PoolReadGuard pg10(&max31865Set10);
if (pg10.getReadResult() == HasReturnvaluesIF::RETURN_OK) {
sensorTemperatures.sensor_tx_modul.value = max31865Set10.temperatureCelcius.value;
sensorTemperatures.sensor_tx_modul.setValid(max31865Set10.temperatureCelcius.isValid());
}
PoolReadGuard pg11(&max31865Set11);
if (pg11.getReadResult() == HasReturnvaluesIF::RETURN_OK) {
sensorTemperatures.sensor_mpa.value = max31865Set11.temperatureCelcius.value;
sensorTemperatures.sensor_mpa.setValid(max31865Set11.temperatureCelcius.isValid());
}
PoolReadGuard pg12(&max31865Set12);
if (pg12.getReadResult() == HasReturnvaluesIF::RETURN_OK) {
sensorTemperatures.sensor_acu.value = max31865Set12.temperatureCelcius.value;
sensorTemperatures.sensor_acu.setValid(max31865Set12.temperatureCelcius.isValid());
}
PoolReadGuard pg13(&max31865Set13);
if (pg13.getReadResult() == HasReturnvaluesIF::RETURN_OK) {
sensorTemperatures.sensor_plpcdu_heatspreader.value = max31865Set13.temperatureCelcius.value;
sensorTemperatures.sensor_plpcdu_heatspreader.setValid(
max31865Set13.temperatureCelcius.isValid());
}
PoolReadGuard pg14(&max31865Set14);
if (pg14.getReadResult() == HasReturnvaluesIF::RETURN_OK) {
sensorTemperatures.sensor_tcs_board.value = max31865Set14.temperatureCelcius.value;
sensorTemperatures.sensor_tcs_board.setValid(max31865Set14.temperatureCelcius.isValid());
}
PoolReadGuard pg15(&max31865Set15);
if (pg15.getReadResult() == HasReturnvaluesIF::RETURN_OK) {
sensorTemperatures.sensor_magnettorquer.value = max31865Set15.temperatureCelcius.value;
sensorTemperatures.sensor_magnettorquer.setValid(max31865Set15.temperatureCelcius.isValid());
}
PoolReadGuard pg111(&tmp1075Set1);
if (pg1.getReadResult() == HasReturnvaluesIF::RETURN_OK) {
sensorTemperatures.sensor_tmp1075_1.value = tmp1075Set1.temperatureCelcius.value;
sensorTemperatures.sensor_tmp1075_1.setValid(tmp1075Set1.temperatureCelcius.isValid());
if (not tmp1075Set1.temperatureCelcius.isValid()) {
sensorTemperatures.sensor_tmp1075_1.value = INVALID_TEMPERATURE;
}
}
PoolReadGuard pg112(&tmp1075Set2);
if (pg2.getReadResult() == HasReturnvaluesIF::RETURN_OK) {
sensorTemperatures.sensor_tmp1075_2.value = tmp1075Set2.temperatureCelcius.value;
sensorTemperatures.sensor_tmp1075_2.setValid(tmp1075Set2.temperatureCelcius.isValid());
if (not tmp1075Set2.temperatureCelcius.isValid()) {
sensorTemperatures.sensor_tmp1075_2.value = INVALID_TEMPERATURE;
}
}
}
void ThermalController::copyDevices() {}