From 4a42f980d08b51b6f81b2fbc48838c03d78dac76 Mon Sep 17 00:00:00 2001 From: Hugo Jean Ponsin Date: Mon, 27 Jul 2026 16:26:32 +0200 Subject: [PATCH] adding defautl template for feedback --- src/device/handlers/DemandHandler.cpp | 52 +++++++++++++++-------- src/device/handlers/DemandHandlerConfig.h | 6 ++- src/device/handlers/FeedbackHandler.cpp | 26 +++++++----- src/device/handlers/FeedbackHandler.h | 2 + 4 files changed, 57 insertions(+), 29 deletions(-) diff --git a/src/device/handlers/DemandHandler.cpp b/src/device/handlers/DemandHandler.cpp index 17babc7..576e23b 100644 --- a/src/device/handlers/DemandHandler.cpp +++ b/src/device/handlers/DemandHandler.cpp @@ -11,13 +11,19 @@ using namespace DemanHandlerConfig; bool DemandHandler::init() { bool initSuccess = true; - if (!midas::odb::exists(this->path)) { - TMFE::Instance()->Msg(MERROR, __FUNCTION__, "Key at %s doesn't exists", - path.c_str()); + if (!midas::odb::exists(this->path + "/" + DemanHandlerConfig::DEMAND)) { + TMFE::Instance()->Msg(MERROR, __FUNCTION__, + "Key at %s/%s doesn't exists", path.c_str(), + DemanHandlerConfig::DEMAND.c_str()); midas::odb o(this->path); - std::vector v = {0.0}; - o = v; + std::vector v; + v.resize(static_cast(ParameterIndex::MAXIMUM_PARAMETER_INDEX)); + o[DemanHandlerConfig::DEMAND] = v; + + TMFE::Instance()->Msg(MERROR, __FUNCTION__, + "Template generated at %s. Please fill it.", + path.c_str()); initSuccess = false; } @@ -25,42 +31,48 @@ bool DemandHandler::init() { // This is checked every start, in case of someone change the index in the // config header - if (o.size() < static_cast(ParameterIndex::MINIMAL_PRESSURE)) { + if (o[DemanHandlerConfig::DEMAND].size() < + static_cast(ParameterIndex::MINIMAL_PRESSURE)) { TMFE::Instance()->Msg( MERROR, __FUNCTION__, "Minimal pressure index is %i, where array size is %i.", static_cast(ParameterIndex::MINIMAL_PRESSURE), o.size()); initSuccess = false; } - if (o.size() < static_cast(ParameterIndex::MAXIMAL_PRESSURE)) { + if (o[DemanHandlerConfig::DEMAND].size() < + static_cast(ParameterIndex::MAXIMAL_PRESSURE)) { TMFE::Instance()->Msg( MERROR, __FUNCTION__, "maximal pressure index is %i, where array size is %i.", static_cast(ParameterIndex::MAXIMAL_PRESSURE), o.size()); initSuccess = false; } - if (o.size() < static_cast(ParameterIndex::CONSTANTE_1)) { + if (o[DemanHandlerConfig::DEMAND].size() < + static_cast(ParameterIndex::CONSTANTE_1)) { TMFE::Instance()->Msg( MERROR, __FUNCTION__, "Constante 1 index is %i, where array size is %i.", static_cast(ParameterIndex::CONSTANTE_1), o.size()); initSuccess = false; } - if (o.size() < static_cast(ParameterIndex::CONSTANTE_2)) { + if (o[DemanHandlerConfig::DEMAND].size() < + static_cast(ParameterIndex::CONSTANTE_2)) { TMFE::Instance()->Msg( MERROR, __FUNCTION__, "Constante 2 index is %i, where array size is %i.", static_cast(ParameterIndex::CONSTANTE_2), o.size()); initSuccess = false; } - if (o.size() < static_cast(ParameterIndex::PRESSURE_CONTROL_MODE)) { + if (o[DemanHandlerConfig::DEMAND].size() < + static_cast(ParameterIndex::PRESSURE_CONTROL_MODE)) { TMFE::Instance()->Msg( MERROR, __FUNCTION__, "Pressure control mode index is %i, where array size is %i.", static_cast(ParameterIndex::PRESSURE_CONTROL_MODE), o.size()); initSuccess = false; } - if (o.size() < static_cast(ParameterIndex::SET_PRESSURE)) { + if (o[DemanHandlerConfig::DEMAND].size() < + static_cast(ParameterIndex::SET_PRESSURE)) { TMFE::Instance()->Msg( MERROR, __FUNCTION__, "Set pressure index is %i, where array size is %i.", @@ -113,7 +125,8 @@ bool DemandHandler::setHotlink() { void DemandHandler::pullMinimalPressure() { midas::odb o(this->path); float minimalPressure = - o[static_cast(ParameterIndex::MINIMAL_PRESSURE)]; + o[DemanHandlerConfig::DEMAND] + [static_cast(ParameterIndex::MINIMAL_PRESSURE)]; Event event = {EventType::MINIMAL_PRESSURE, minimalPressure}; eventBus.publish(event); } @@ -121,21 +134,24 @@ void DemandHandler::pullMinimalPressure() { void DemandHandler::pullMaximalPressure() { midas::odb o(this->path); float maximalPressure = - o[static_cast(ParameterIndex::MAXIMAL_PRESSURE)]; + o[DemanHandlerConfig::DEMAND] + [static_cast(ParameterIndex::MAXIMAL_PRESSURE)]; Event event = {EventType::MAXIMAL_PRESSURE, maximalPressure}; eventBus.publish(event); } void DemandHandler::pullConstante1() { midas::odb o(this->path); - float constante1 = o[static_cast(ParameterIndex::CONSTANTE_1)]; + float constante1 = o[DemanHandlerConfig::DEMAND] + [static_cast(ParameterIndex::CONSTANTE_1)]; Event event = {EventType::CONSTANTE_1, constante1}; eventBus.publish(event); } void DemandHandler::pullConstante2() { midas::odb o(this->path); - float constance2 = o[static_cast(ParameterIndex::CONSTANTE_2)]; + float constance2 = o[DemanHandlerConfig::DEMAND] + [static_cast(ParameterIndex::CONSTANTE_2)]; Event event = {EventType::CONSTANTE_2, constance2}; eventBus.publish(event); } @@ -143,14 +159,16 @@ void DemandHandler::pullConstante2() { void DemandHandler::pullPressureControlMode() { midas::odb o(this->path); float pressureControlMode = - o[static_cast(ParameterIndex::PRESSURE_CONTROL_MODE)]; + o[DemanHandlerConfig::DEMAND] + [static_cast(ParameterIndex::PRESSURE_CONTROL_MODE)]; Event event = {EventType::PRESSURE_CONTROL_MODE, pressureControlMode != 0}; eventBus.publish(event); } void DemandHandler::pullSetPressure() { midas::odb o(this->path); - float setPressure = o[static_cast(ParameterIndex::SET_PRESSURE)]; + float setPressure = o[DemanHandlerConfig::DEMAND] + [static_cast(ParameterIndex::SET_PRESSURE)]; Event event = {EventType::SET_PRESSURE, setPressure != 0}; eventBus.publish(event); } diff --git a/src/device/handlers/DemandHandlerConfig.h b/src/device/handlers/DemandHandlerConfig.h index 8223d23..a6ea7f9 100644 --- a/src/device/handlers/DemandHandlerConfig.h +++ b/src/device/handlers/DemandHandlerConfig.h @@ -5,7 +5,8 @@ namespace DemanHandlerConfig { const std::string PATH_PREFIX = "/Equipment/"; -const std::string PATH_SUFFIX = "/Variables/Demand"; +const std::string PATH_SUFFIX = "/Variables"; +const std::string DEMAND = "Demand"; enum class ParameterIndex { @@ -14,7 +15,8 @@ enum class ParameterIndex { MINIMAL_PRESSURE = 8, MAXIMAL_PRESSURE = 9, CONSTANTE_1 = 10, - CONSTANTE_2 = 11 + CONSTANTE_2 = 11, + MAXIMUM_PARAMETER_INDEX = 11 }; }; // namespace DemanHandlerConfig diff --git a/src/device/handlers/FeedbackHandler.cpp b/src/device/handlers/FeedbackHandler.cpp index 27297f1..b890f8f 100644 --- a/src/device/handlers/FeedbackHandler.cpp +++ b/src/device/handlers/FeedbackHandler.cpp @@ -15,8 +15,9 @@ FeedbackHandler::FeedbackHandler(EventBus &eventBusReference, eventBusReference.subscribe( [this](const PressureCalculator::Event &e) { - setConstante2(e.c2contrib); + generateOdbKeyIfNeeded(); setConstante1(e.c1contrib); + setConstante2(e.c2contrib); setPressureMinimum(e.uncapedPressure); setPressureMaximum(e.uncapedPressure); setPressure(e.cappedPressure); @@ -24,6 +25,7 @@ FeedbackHandler::FeedbackHandler(EventBus &eventBusReference, }); eventBusReference.subscribe( [this](const DemandHandler::Event &e) { + generateOdbKeyIfNeeded(); switch (e.type) { case DemandHandler::EventType::PRESSURE_CONTROL_MODE: enablePressureControlMode(std::get(e.value)); @@ -37,6 +39,7 @@ FeedbackHandler::FeedbackHandler(EventBus &eventBusReference, }); eventBusReference.subscribe( [this](const InputHandler::Event &e) { + generateOdbKeyIfNeeded(); switch (e.type) { case InputHandler::EventType::SP_VALUE: setSP(e.value); @@ -54,15 +57,6 @@ FeedbackHandler::FeedbackHandler(EventBus &eventBusReference, } void FeedbackHandler::updatePressure() { - // If the key doesn't exist, we create the template. - if (!midas::odb::exists(path + FeedbackHandlerConf::OUTPUT_VARNAME)) { - std::vector v; - v.resize(static_cast( - FeedbackHandlerConf::RegisterIndex::MAXIMUM_REGISTRY_INDEX)); - midas::odb o(path); - o[FeedbackHandlerConf::OUTPUT_VARNAME] = v; - } - { midas::odb o(path); o[FeedbackHandlerConf::OUTPUT_VARNAME] @@ -87,6 +81,18 @@ void FeedbackHandler::updatePressure() { } } +void FeedbackHandler::generateOdbKeyIfNeeded() { + // If the key doesn't exist, we create the template. + + if (!midas::odb::exists(path + FeedbackHandlerConf::OUTPUT_VARNAME)) { + std::vector v; + v.resize(static_cast( + FeedbackHandlerConf::RegisterIndex::MAXIMUM_REGISTRY_INDEX)); + midas::odb o(path); + o[FeedbackHandlerConf::OUTPUT_VARNAME] = v; + } +} + void FeedbackHandler::enablePressureControlMode(bool enable) { isPressureControlModeEnable = enable; updatePressure(); diff --git a/src/device/handlers/FeedbackHandler.h b/src/device/handlers/FeedbackHandler.h index b1086f1..d1b5728 100644 --- a/src/device/handlers/FeedbackHandler.h +++ b/src/device/handlers/FeedbackHandler.h @@ -12,6 +12,8 @@ class FeedbackHandler { std::string path; + void generateOdbKeyIfNeeded(); + /* Internal value setters */