adding defautl template for feedback

This commit is contained in:
2026-07-27 16:26:32 +02:00
parent fc733bd37f
commit 4a42f980d0
4 changed files with 57 additions and 29 deletions
+35 -17
View File
@@ -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<float> v = {0.0};
o = v;
std::vector<float> v;
v.resize(static_cast<int>(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<int>(ParameterIndex::MINIMAL_PRESSURE)) {
if (o[DemanHandlerConfig::DEMAND].size() <
static_cast<int>(ParameterIndex::MINIMAL_PRESSURE)) {
TMFE::Instance()->Msg(
MERROR, __FUNCTION__,
"Minimal pressure index is %i, where array size is %i.",
static_cast<int>(ParameterIndex::MINIMAL_PRESSURE), o.size());
initSuccess = false;
}
if (o.size() < static_cast<int>(ParameterIndex::MAXIMAL_PRESSURE)) {
if (o[DemanHandlerConfig::DEMAND].size() <
static_cast<int>(ParameterIndex::MAXIMAL_PRESSURE)) {
TMFE::Instance()->Msg(
MERROR, __FUNCTION__,
"maximal pressure index is %i, where array size is %i.",
static_cast<int>(ParameterIndex::MAXIMAL_PRESSURE), o.size());
initSuccess = false;
}
if (o.size() < static_cast<int>(ParameterIndex::CONSTANTE_1)) {
if (o[DemanHandlerConfig::DEMAND].size() <
static_cast<int>(ParameterIndex::CONSTANTE_1)) {
TMFE::Instance()->Msg(
MERROR, __FUNCTION__,
"Constante 1 index is %i, where array size is %i.",
static_cast<int>(ParameterIndex::CONSTANTE_1), o.size());
initSuccess = false;
}
if (o.size() < static_cast<int>(ParameterIndex::CONSTANTE_2)) {
if (o[DemanHandlerConfig::DEMAND].size() <
static_cast<int>(ParameterIndex::CONSTANTE_2)) {
TMFE::Instance()->Msg(
MERROR, __FUNCTION__,
"Constante 2 index is %i, where array size is %i.",
static_cast<int>(ParameterIndex::CONSTANTE_2), o.size());
initSuccess = false;
}
if (o.size() < static_cast<int>(ParameterIndex::PRESSURE_CONTROL_MODE)) {
if (o[DemanHandlerConfig::DEMAND].size() <
static_cast<int>(ParameterIndex::PRESSURE_CONTROL_MODE)) {
TMFE::Instance()->Msg(
MERROR, __FUNCTION__,
"Pressure control mode index is %i, where array size is %i.",
static_cast<int>(ParameterIndex::PRESSURE_CONTROL_MODE), o.size());
initSuccess = false;
}
if (o.size() < static_cast<int>(ParameterIndex::SET_PRESSURE)) {
if (o[DemanHandlerConfig::DEMAND].size() <
static_cast<int>(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<int>(ParameterIndex::MINIMAL_PRESSURE)];
o[DemanHandlerConfig::DEMAND]
[static_cast<int>(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<int>(ParameterIndex::MAXIMAL_PRESSURE)];
o[DemanHandlerConfig::DEMAND]
[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[static_cast<int>(ParameterIndex::CONSTANTE_1)];
float constante1 = o[DemanHandlerConfig::DEMAND]
[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[static_cast<int>(ParameterIndex::CONSTANTE_2)];
float constance2 = o[DemanHandlerConfig::DEMAND]
[static_cast<int>(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<int>(ParameterIndex::PRESSURE_CONTROL_MODE)];
o[DemanHandlerConfig::DEMAND]
[static_cast<int>(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<int>(ParameterIndex::SET_PRESSURE)];
float setPressure = o[DemanHandlerConfig::DEMAND]
[static_cast<int>(ParameterIndex::SET_PRESSURE)];
Event event = {EventType::SET_PRESSURE, setPressure != 0};
eventBus.publish(event);
}
+4 -2
View File
@@ -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
+16 -10
View File
@@ -15,8 +15,9 @@ FeedbackHandler::FeedbackHandler(EventBus &eventBusReference,
eventBusReference.subscribe<PressureCalculator::Event>(
[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<DemandHandler::Event>(
[this](const DemandHandler::Event &e) {
generateOdbKeyIfNeeded();
switch (e.type) {
case DemandHandler::EventType::PRESSURE_CONTROL_MODE:
enablePressureControlMode(std::get<bool>(e.value));
@@ -37,6 +39,7 @@ FeedbackHandler::FeedbackHandler(EventBus &eventBusReference,
});
eventBusReference.subscribe<InputHandler::Event>(
[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<float> v;
v.resize(static_cast<int>(
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<float> v;
v.resize(static_cast<int>(
FeedbackHandlerConf::RegisterIndex::MAXIMUM_REGISTRY_INDEX));
midas::odb o(path);
o[FeedbackHandlerConf::OUTPUT_VARNAME] = v;
}
}
void FeedbackHandler::enablePressureControlMode(bool enable) {
isPressureControlModeEnable = enable;
updatePressure();
+2
View File
@@ -12,6 +12,8 @@ class FeedbackHandler {
std::string path;
void generateOdbKeyIfNeeded();
/*
Internal value setters
*/