PressureCalculator finished

This commit is contained in:
2026-07-20 11:28:39 +02:00
parent f2cdd29e0f
commit 31e277726d
10 changed files with 116 additions and 30 deletions
+2
View File
@@ -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(
+5
View File
@@ -1,3 +1,6 @@
#ifndef AVERAGE_H
#define AVERAGE_H
#include <chrono>
#include <deque>
@@ -26,3 +29,5 @@ class Average {
void addValue(double value);
double getAverage();
};
#endif
+16
View File
@@ -33,6 +33,12 @@ bool DemandHandler::init() {
if (o.size() < static_cast<int>(ParameterIndex::CONSTANTE_2)) {
indexValid = false;
}
if (o.size() < static_cast<int>(ParameterIndex::PRESSURE_CONTROL_MODE)) {
indexValid = false;
}
if (o.size() < static_cast<int>(ParameterIndex::SET_PRESSURE)) {
indexValid = false;
}
if (indexValid)
return false;
@@ -64,6 +70,9 @@ bool DemandHandler::setHotlink() {
case static_cast<int>(ParameterIndex::PRESSURE_CONTROL_MODE):
pullPressureControlMode();
break;
case static_cast<int>(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<int>(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 +
+18 -15
View File
@@ -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<float, bool> 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<float, bool> value;
};
DemandHandler(EventBus &eventBusReference, std::string equipmentName);
};
#endif
+2
View File
@@ -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,
+10 -11
View File
@@ -16,17 +16,6 @@ class InputHandler {
std::optional<midas::odb> 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
+50
View File
@@ -1,4 +1,8 @@
#include "PressureCalculator.h"
#include "Average.h"
#include "DemandHandler.h"
#include "InputHandler.h"
#include "itc_pressure_optimizer.h"
#include <string>
void PressureCalculator::update() {
@@ -34,6 +38,51 @@ void PressureCalculator::update() {
eventBus.publish(event);
}
PressureCalculator::PressureCalculator(EventBus &eventBusReference)
: average(30), eventBus(eventBusReference) {
eventBus.subscribe<DemandHandler::Event>(
[this](const DemandHandler::Event &e) {
switch (e.type) {
case DemandHandler::EventType::MINIMAL_PRESSURE:
updateMinimalPressure(std::get<float>(e.value));
break;
case DemandHandler::EventType::MAXIMAL_PRESSURE:
updateMaximalPressure(std::get<float>(e.value));
break;
case DemandHandler::EventType::CONSTANTE_1:
updateConstante1(std::get<float>(e.value));
break;
case DemandHandler::EventType::CONSTANTE_2:
updateConstante2(std::get<float>(e.value));
break;
default:
break;
}
});
eventBus.subscribe<InputHandler::Event>(
[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<itcPressureOptimizer::EquipmentPollEvent>(
[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<double>(value));
update();
}
+9 -1
View File
@@ -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
+2 -1
View File
@@ -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;
+2 -2
View File
@@ -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 <string>
@@ -40,9 +40,9 @@ class itcPressureOptimizer : public TMFeEquipment {
DemandHandler demandHandler;
SettingsHandler settingsHandler;
InputHandler inputHandler;
PressureCalculator pressureCalculator;
// FeedbackHandler feedbackHandler;
// OutputHandler outputHandler;
// PressureCalculator pressureCalculator;
};
#endif