From 31e277726da4a2ac9e192ee83d2b29db3e82f440 Mon Sep 17 00:00:00 2001 From: Hugo Jean Ponsin Date: Mon, 20 Jul 2026 11:28:39 +0200 Subject: [PATCH] PressureCalculator finished --- CMakeLists.txt | 2 ++ src/device/Average.h | 5 +++ src/device/DemandHandler.cpp | 16 +++++++++ src/device/DemandHandler.h | 33 ++++++++++-------- src/device/DemandHandlerConfig.h | 2 ++ src/device/InputHandler.h | 21 ++++++----- src/device/PressureCalculator.cpp | 50 +++++++++++++++++++++++++++ src/device/PressureCalculator.h | 10 +++++- src/device/itc_pressure_optimizer.cpp | 3 +- src/device/itc_pressure_optimizer.h | 4 +-- 10 files changed, 116 insertions(+), 30 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index fb7a546..4f93ef3 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -32,6 +32,8 @@ add_library( src/device/DemandHandler.cpp src/device/InputHandler.cpp src/device/SettingsHandler.cpp + src/device/PressureCalculator.cpp + src/device/Average.cpp ) set_property( diff --git a/src/device/Average.h b/src/device/Average.h index 3e76bbf..785b42e 100644 --- a/src/device/Average.h +++ b/src/device/Average.h @@ -1,3 +1,6 @@ +#ifndef AVERAGE_H +#define AVERAGE_H + #include #include @@ -26,3 +29,5 @@ class Average { void addValue(double value); double getAverage(); }; + +#endif \ No newline at end of file diff --git a/src/device/DemandHandler.cpp b/src/device/DemandHandler.cpp index cee662d..2c4be25 100644 --- a/src/device/DemandHandler.cpp +++ b/src/device/DemandHandler.cpp @@ -33,6 +33,12 @@ bool DemandHandler::init() { if (o.size() < static_cast(ParameterIndex::CONSTANTE_2)) { indexValid = false; } + if (o.size() < static_cast(ParameterIndex::PRESSURE_CONTROL_MODE)) { + indexValid = false; + } + if (o.size() < static_cast(ParameterIndex::SET_PRESSURE)) { + indexValid = false; + } if (indexValid) return false; @@ -64,6 +70,9 @@ bool DemandHandler::setHotlink() { case static_cast(ParameterIndex::PRESSURE_CONTROL_MODE): pullPressureControlMode(); break; + case static_cast(ParameterIndex::SET_PRESSURE): + pullSetPressure(); + break; default: // Update out of scope, discarded break; @@ -110,6 +119,13 @@ void DemandHandler::pullPressureControlMode() { eventBus.publish(event); } +void DemandHandler::pullSetPressure() { + midas::odb o(this->path); + float setPressure = o[static_cast(ParameterIndex::SET_PRESSURE)]; + Event event = {EventType::SET_PRESSURE, setPressure != 0}; + eventBus.publish(event); +} + DemandHandler::DemandHandler(EventBus &eventBusReference, std::string equipmentName) : path(DemanHandlerConfig::PATH_PREFIX + equipmentName + diff --git a/src/device/DemandHandler.h b/src/device/DemandHandler.h index f694fb7..4054e72 100644 --- a/src/device/DemandHandler.h +++ b/src/device/DemandHandler.h @@ -10,27 +10,13 @@ class DemandHandler { std::string path; EventBus &eventBus; - enum class EventType { - MINIMAL_PRESSURE, - MAXIMAL_PRESSURE, - CONSTANTE_1, - CONSTANTE_2, - PRESSURE_CONTROL_MODE - }; - - struct Event { - EventType type; - std::variant value; - }; - void pullMinimalPressure(); void pullMaximalPressure(); void pullConstante1(); void pullConstante2(); void pullPressureControlMode(); + void pullSetPressure(); - public: - DemandHandler(EventBus &eventBusReference, std::string equipmentName); /* @brief Manualy get all the value, and update owned objects */ @@ -40,6 +26,23 @@ class DemandHandler { @return true if succes, false if any error encountered */ bool setHotlink(); + + public: + enum class EventType { + MINIMAL_PRESSURE, + MAXIMAL_PRESSURE, + CONSTANTE_1, + CONSTANTE_2, + PRESSURE_CONTROL_MODE, + SET_PRESSURE + }; + + struct Event { + EventType type; + std::variant value; + }; + + DemandHandler(EventBus &eventBusReference, std::string equipmentName); }; #endif \ No newline at end of file diff --git a/src/device/DemandHandlerConfig.h b/src/device/DemandHandlerConfig.h index 855efd7..2e13b68 100644 --- a/src/device/DemandHandlerConfig.h +++ b/src/device/DemandHandlerConfig.h @@ -8,7 +8,9 @@ const std::string PATH_PREFIX = "/Equipment/"; const std::string PATH_SUFFIX = "/Demand"; enum class ParameterIndex { + PRESSURE_CONTROL_MODE = 6, + SET_PRESSURE = 7, MINIMAL_PRESSURE = 8, MAXIMAL_PRESSURE = 9, CONSTANTE_1 = 10, diff --git a/src/device/InputHandler.h b/src/device/InputHandler.h index 478c90f..7076221 100644 --- a/src/device/InputHandler.h +++ b/src/device/InputHandler.h @@ -16,17 +16,6 @@ class InputHandler { std::optional hotlink; - enum class EventType { - SP_VALUE, - TEMPERATURE_VALUE, - POWER_VALUE, - }; - - struct Event { - EventType type; - float value; - }; - void updatePath(std::string name); void updateSPIndex(int index); void updateTemperatureIndex(int index); @@ -40,6 +29,16 @@ class InputHandler { public: InputHandler(EventBus &eventBusReference); + enum class EventType { + SP_VALUE, + TEMPERATURE_VALUE, + POWER_VALUE, + }; + + struct Event { + EventType type; + float value; + }; }; #endif \ No newline at end of file diff --git a/src/device/PressureCalculator.cpp b/src/device/PressureCalculator.cpp index c2dec03..5f2e05d 100644 --- a/src/device/PressureCalculator.cpp +++ b/src/device/PressureCalculator.cpp @@ -1,4 +1,8 @@ #include "PressureCalculator.h" +#include "Average.h" +#include "DemandHandler.h" +#include "InputHandler.h" +#include "itc_pressure_optimizer.h" #include void PressureCalculator::update() { @@ -34,6 +38,51 @@ void PressureCalculator::update() { eventBus.publish(event); } +PressureCalculator::PressureCalculator(EventBus &eventBusReference) + : average(30), eventBus(eventBusReference) { + eventBus.subscribe( + [this](const DemandHandler::Event &e) { + switch (e.type) { + case DemandHandler::EventType::MINIMAL_PRESSURE: + updateMinimalPressure(std::get(e.value)); + break; + case DemandHandler::EventType::MAXIMAL_PRESSURE: + updateMaximalPressure(std::get(e.value)); + break; + case DemandHandler::EventType::CONSTANTE_1: + updateConstante1(std::get(e.value)); + break; + case DemandHandler::EventType::CONSTANTE_2: + updateConstante2(std::get(e.value)); + break; + default: + break; + } + }); + + eventBus.subscribe( + [this](const InputHandler::Event &e) { + switch (e.type) { + case InputHandler::EventType::SP_VALUE: + updateSP(e.value); + break; + case InputHandler::EventType::TEMPERATURE_VALUE: + updateTemperature(e.value); + break; + case InputHandler::EventType::POWER_VALUE: + updatePower(e.value); + break; + default: + break; + } + }); + + eventBus.subscribe( + [this](const itcPressureOptimizer::EquipmentPollEvent &e) { + update(); + }); +} + void PressureCalculator::updateSP(float value) { cachedSP = value; update(); @@ -46,6 +95,7 @@ void PressureCalculator::updateTemperature(float value) { void PressureCalculator::updatePower(float value) { cachedPower = value; + average.addValue(static_cast(value)); update(); } diff --git a/src/device/PressureCalculator.h b/src/device/PressureCalculator.h index d808acf..5387650 100644 --- a/src/device/PressureCalculator.h +++ b/src/device/PressureCalculator.h @@ -1,4 +1,8 @@ +#ifndef PRESSURE_CALCULATOR_H +#define PRESSURE_CALCULATOR_H + #include "Average.h" +#include "EventBus.h" class PressureCalculator { private: @@ -30,6 +34,10 @@ class PressureCalculator { void updateConstante1(float value); void updateConstante2(float value); - public: void update(); + + public: + PressureCalculator(EventBus &eventBusReference); }; + +#endif \ No newline at end of file diff --git a/src/device/itc_pressure_optimizer.cpp b/src/device/itc_pressure_optimizer.cpp index 40a7304..4a29043 100644 --- a/src/device/itc_pressure_optimizer.cpp +++ b/src/device/itc_pressure_optimizer.cpp @@ -14,7 +14,8 @@ itcPressureOptimizer::itcPressureOptimizer(std::string equipmentName, const char *equipmentFilename) : TMFeEquipment(equipmentName.c_str(), equipmentFilename), eventBus(), demandHandler(eventBus, equipmentName), - settingsHandler(eventBus, equipmentName), inputHandler(eventBus) { + settingsHandler(eventBus, equipmentName), inputHandler(eventBus), + pressureCalculator(eventBus) { fEqConfPeriodMilliSec = 1000; // refresh every seconds fEqConfLogHistory = 1; fEqConfReadOnlyWhenRunning = false; diff --git a/src/device/itc_pressure_optimizer.h b/src/device/itc_pressure_optimizer.h index cc86a88..5dabbe2 100644 --- a/src/device/itc_pressure_optimizer.h +++ b/src/device/itc_pressure_optimizer.h @@ -4,10 +4,10 @@ #include "DemandHandler.h" #include "EventBus.h" #include "InputHandler.h" +#include "PressureCalculator.h" #include "SettingsHandler.h" // #include "FeedbackHandler.h" // #include "OutputHandler.h" -// #include "PressureCalculator.h" #include "tmfe.h" #include @@ -40,9 +40,9 @@ class itcPressureOptimizer : public TMFeEquipment { DemandHandler demandHandler; SettingsHandler settingsHandler; InputHandler inputHandler; + PressureCalculator pressureCalculator; // FeedbackHandler feedbackHandler; // OutputHandler outputHandler; - // PressureCalculator pressureCalculator; }; #endif \ No newline at end of file