demandHandler working

This commit is contained in:
2026-07-16 13:11:01 +02:00
parent 87b90d51a9
commit bb596ca100
10 changed files with 159 additions and 60 deletions
+48 -34
View File
@@ -1,28 +1,34 @@
#include "DemandHandler.h"
#include "DemandHandlerConfig.h"
#include "itc_pressure_optimizer.h"
#include <functional>
#include <string>
bool DemandHandler::init() {
midas::odb o(this->path);
#include "odbxx.h"
#include "tmfe.h"
if (!o.exists()) {
// TODO : ERROR MESSAGE
using namespace DemanHandlerConfig;
bool DemandHandler::init() {
if (!midas::odb::exists(this->path)) {
printf("[DEMANDE HANDLER] : Path doesn't exist\n");
return false;
}
midas::odb o(this->path);
bool indexValid = true;
if (o.size() < ParameterIndex::MINIMAL_PRESSURE) {
if (o.size() < static_cast<int>(ParameterIndex::MINIMAL_PRESSURE)) {
indexValid = false;
}
if (o.size() < ParameterIndex::MAXIMAL_PRESSURE) {
if (o.size() < static_cast<int>(ParameterIndex::MAXIMAL_PRESSURE)) {
indexValid = false;
}
if (o.size() < ParameterIndex::CONSTANTE_1) {
if (o.size() < static_cast<int>(ParameterIndex::CONSTANTE_1)) {
indexValid = false;
}
if (o.size() < ParameterIndex::CONSTANTE_2) {
if (o.size() < static_cast<int>(ParameterIndex::CONSTANTE_2)) {
indexValid = false;
}
@@ -39,21 +45,21 @@ bool DemandHandler::init() {
bool DemandHandler::setHotlink() {
midas::odb to_watch(this->path);
to_watch([&](midas::odb &arg) {
to_watch.watch([&](midas::odb &arg) {
switch (arg.get_last_index()) {
case ParameterIndex::MINIMAL_PRESSURE:
case static_cast<int>(ParameterIndex::MINIMAL_PRESSURE):
pullMinimalPressure();
break;
case ParameterIndex::MAXIMAL_PRESSURE:
case static_cast<int>(ParameterIndex::MAXIMAL_PRESSURE):
pullMaximalPressure();
break;
case ParameterIndex::MINIMAL_PRESSURE:
case static_cast<int>(ParameterIndex::CONSTANTE_1):
pullConstante1();
break;
case ParameterIndex::MINIMAL_PRESSURE:
case static_cast<int>(ParameterIndex::CONSTANTE_2):
pullConstante2();
break;
case ParameterIndex::PRESSURE_CONTROL_MODE:
case static_cast<int>(ParameterIndex::PRESSURE_CONTROL_MODE):
pullPressureControlMode();
break;
default:
@@ -61,47 +67,55 @@ bool DemandHandler::setHotlink() {
break;
}
});
return true;
}
void DemandHandler::pullMinimalPressure() {
midas::odb o(this->path);
float minimalPressure = o[ParameterIndex::MINIMAL_PRESSURE];
pressureCalculator.get().updateMinimalPressure(minimalPressure);
float minimalPressure =
o[static_cast<int>(ParameterIndex::MINIMAL_PRESSURE)];
Event event = {EventType::MINIMAL_PRESSURE, minimalPressure};
eventBus.publish(event);
}
void DemandHandler::pullMaximalPressure() {
midas::odb o(this->path);
float maximalPressure = o[ParameterIndex::MAXIMAL_PRESSURE];
pressureCalculator.get().updateMinimalPressure(maximalPressure);
float maximalPressure =
o[static_cast<int>(ParameterIndex::MAXIMAL_PRESSURE)];
Event event = {EventType::MAXIMAL_PRESSURE, maximalPressure};
eventBus.publish(event);
}
void DemandHandler::pullConstante1() {
midas::odb o(this->path);
float constante1 = o[ParameterIndex::CONSTANTE_1];
pressureCalculator.get().updateMinimalPressure(constante1);
feedbackHandler.get().setConstante1(constante1);
float constante1 = o[static_cast<int>(ParameterIndex::CONSTANTE_1)];
Event event = {EventType::CONSTANTE_1, constante1};
eventBus.publish(event);
}
void DemandHandler::pullConstante2() {
midas::odb o(this->path);
float constance2 = o[ParameterIndex::CONSTANTE_2];
pressureCalculator.get().updateMinimalPressure(constance2);
feedbackHandler.get().setConstante2(constante2);
float constance2 = o[static_cast<int>(ParameterIndex::CONSTANTE_2)];
Event event = {EventType::CONSTANTE_2, constance2};
eventBus.publish(event);
}
void DemandHandler::pullPressureControlMode() {
midas::odb o(this->path);
float pressureControlMode = o[ParameterIndex::PRESSURE_CONTROL_MODE];
feedbackHandler.get().enablePressureControlMode(pressureControlMode);
float pressureControlMode =
o[static_cast<int>(ParameterIndex::PRESSURE_CONTROL_MODE)];
Event event = {EventType::PRESSURE_CONTROL_MODE, pressureControlMode != 0};
eventBus.publish(event);
}
DemandHandler::DemandHandler(
std::string equipmentName,
std::reference_wrapper<FeedbackHandler> feedbackHandler,
std::reference_wrapper<PressureCalculator> pressureCalculator) {
DemandHandler::DemandHandler(EventBus &eventBusReference,
std::string equipmentName)
: path(DemanHandlerConfig::PATH_PREFIX + equipmentName +
DemanHandlerConfig::PATH_SUFFIX),
eventBus(eventBusReference) {
this->path = DemanHandlerConfig::PATH_PREFIX + equipmentName +
DemanHandlerConfig::PATH_SUFFIX;
this->feedbackHandler = feedbackHandler;
this->pressureCalculator = pressureCalculator;
eventBus.subscribe<itcPressureOptimizer::EquipmentInitEvent>(
[this](const itcPressureOptimizer::EquipmentInitEvent &e) {
printf("[EquipmentInitEvent] : init recived\n");
});
}
+17 -9
View File
@@ -1,16 +1,27 @@
#ifndef DEMAND_HANDLER_H
#define DEMAND_HANDLER_H
#include "FeedbackHandler.h"
#include "PressureCalculator.h"
#include <functional>
#include "EventBus.h"
#include <string>
#include <variant>
class DemandHandler {
private:
std::string path;
std::reference_wrapper<FeedbackHandler> feedbackHandler;
std::reference_wrapper<PressureCalculator> pressureCalculator;
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();
@@ -19,10 +30,7 @@ class DemandHandler {
void pullPressureControlMode();
public:
DemandHandler(
std::string equipmentName,
std::reference_wrapper<FeedbackHandler> feedbackHandler,
std::reference_wrapper<PressureCalculator> pressureCalculator);
DemandHandler(EventBus &eventBusReference, std::string equipmentName);
/*
@brief Manualy get all the value, and update owned objects
*/
+3 -3
View File
@@ -7,14 +7,14 @@ namespace DemanHandlerConfig {
const std::string PATH_PREFIX = "/Equipment/";
const std::string PATH_SUFFIX = "/Demand";
class enum ParameterIndex {
enum class ParameterIndex {
PRESSURE_CONTROL_MODE = 6,
MINIMAL_PRESSURE = 8,
MAXIMAL_PRESSURE = 9,
CONSTANTE_1 = 10,
CONSTANTE_2 = 11
}
};
} // namespace DemanHandlerConfig
}; // namespace DemanHandlerConfig
#endif
@@ -1,3 +1,6 @@
#ifndef EVENT_BUS_H
#define EVENT_BUS_H
#include <functional>
#include <iostream>
#include <memory>
@@ -55,4 +58,6 @@ class EventBus {
}
}
}
};
};
#endif
+1 -1
View File
@@ -17,7 +17,7 @@ class FeedbackHandler {
Constante2 = 11
};
setValueToOdb(int index, float value);
void setValueToOdb(int index, float value);
public:
FeedbackHandler(std::string equipmentName);
+33
View File
@@ -0,0 +1,33 @@
#include "itc_pressure_optimizer.h"
#include "DemandHandler.h"
#include "EventBus.h"
// #include "FeedbackHandler.h"
// #include "InputHandler.h"
// #include "OutputHandler.h"
// #include "PressureCalculator.h"
// #include "SettingsHandler.h"
#include <string>
itcPressureOptimizer::itcPressureOptimizer(std::string equipmentName,
const char *equipmentFilename)
: TMFeEquipment(equipmentName.c_str(), equipmentFilename), eventBus(),
demandHandler(eventBus, equipmentName) {
fEqConfPeriodMilliSec = 1000; // refresh every seconds
fEqConfLogHistory = 1;
fEqConfReadOnlyWhenRunning = false;
fEqConfWriteEventsToOdb = true;
}
/*, feedbackHandler(), inputHandler(),
outputHandler(), pressureCalculator(),
settingsHandler()*/
void itcPressureOptimizer::HandlePeriodic() {}
TMFeResult
itcPressureOptimizer::HandleInit(const std::vector<std::string> &args) {
eventBus.publish(EquipmentInitEvent{});
return TMFeResult();
}
+48
View File
@@ -0,0 +1,48 @@
#ifndef ITC_PRESSURE_OPTIMIZER_H
#define ITC_PRESSURE_OPTIMIZER_H
#include "DemandHandler.h"
#include "EventBus.h"
// #include "FeedbackHandler.h"
// #include "InputHandler.h"
// #include "OutputHandler.h"
// #include "PressureCalculator.h"
// #include "SettingsHandler.h"
#include "tmfe.h"
#include <string>
class itcPressureOptimizer : public TMFeEquipment {
public:
struct EquipmentInitEvent {};
struct EquipmentPollEvent {};
/**
* @brief Constructor
* @param equipmentName for debug purpose, cpp file of the equipment
*/
itcPressureOptimizer(std::string equipmentName,
const char *equipmentFilename);
/**
* @brief Method overridden called periodically by Midas
*/
void HandlePeriodic();
/**
* @brief Method overridden called by Midas at initialization
*/
TMFeResult HandleInit(const std::vector<std::string> &args);
private:
EventBus eventBus;
DemandHandler demandHandler;
// FeedbackHandler feedbackHandler;
// InputHandler inputHandler;
// OutputHandler outputHandler;
// PressureCalculator pressureCalculator;
// SettingsHandler settingsHandler;
};
#endif