diff --git a/CMakeLists.txt b/CMakeLists.txt index 52be0fe..3da4b68 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -60,6 +60,7 @@ target_include_directories( ################################################################################ ## Frontend ################################################################################ +if(${BUILD_FRONTEND}) add_executable(itcPressureOptimizerScfe src/frontend/itc_pressure_optimizer_scfe.cpp @@ -90,4 +91,7 @@ target_link_libraries( install( TARGETS itcPressureOptimizerScfe RUNTIME DESTINATION bin -) \ No newline at end of file +) + +endif() + diff --git a/src/device/handlers/DemandHandler.cpp b/src/device/handlers/DemandHandler.cpp index 8c3765d..715296e 100644 --- a/src/device/handlers/DemandHandler.cpp +++ b/src/device/handlers/DemandHandler.cpp @@ -43,24 +43,24 @@ bool DemandHandler::init() { static_cast(ParameterIndex::MAXIMAL_PRESSURE)) { TMFE::Instance()->Msg( MERROR, __FUNCTION__, - "maximal pressure index is %i, where array size is %i.", + "Maximal pressure index is %i, where array size is %i.", static_cast(ParameterIndex::MAXIMAL_PRESSURE), o.size()); initSuccess = false; } if (o[DemandHandlerConfig::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()); + static_cast(ParameterIndex::CONSTANT_1)) { + TMFE::Instance()->Msg(MERROR, __FUNCTION__, + "Constant 1 index is %i, where array size is %i.", + static_cast(ParameterIndex::CONSTANT_1), + o.size()); initSuccess = false; } if (o[DemandHandlerConfig::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()); + static_cast(ParameterIndex::CONSTANT_2)) { + TMFE::Instance()->Msg(MERROR, __FUNCTION__, + "Constant 2 index is %i, where array size is %i.", + static_cast(ParameterIndex::CONSTANT_2), + o.size()); initSuccess = false; } if (o[DemandHandlerConfig::DEMAND].size() < @@ -86,8 +86,8 @@ bool DemandHandler::init() { this->pullMinimalPressure(); this->pullMaximalPressure(); - this->pullConstante1(); - this->pullConstante2(); + this->pullConstant1(); + this->pullConstant2(); this->pullPressureControlMode(); return true; } @@ -102,11 +102,11 @@ bool DemandHandler::setHotlink() { case static_cast(ParameterIndex::MAXIMAL_PRESSURE): pullMaximalPressure(); break; - case static_cast(ParameterIndex::CONSTANTE_1): - pullConstante1(); + case static_cast(ParameterIndex::CONSTANT_1): + pullConstant1(); break; - case static_cast(ParameterIndex::CONSTANTE_2): - pullConstante2(); + case static_cast(ParameterIndex::CONSTANT_2): + pullConstant2(); break; case static_cast(ParameterIndex::PRESSURE_CONTROL_MODE): pullPressureControlMode(); @@ -140,19 +140,19 @@ void DemandHandler::pullMaximalPressure() { eventBus.publish(event); } -void DemandHandler::pullConstante1() { +void DemandHandler::pullConstant1() { midas::odb o(this->path); float constante1 = o[DemandHandlerConfig::DEMAND] - [static_cast(ParameterIndex::CONSTANTE_1)]; - Event event = {EventType::CONSTANTE_1, constante1}; + [static_cast(ParameterIndex::CONSTANT_1)]; + Event event = {EventType::CONSTANT_1, constante1}; eventBus.publish(event); } -void DemandHandler::pullConstante2() { +void DemandHandler::pullConstant2() { midas::odb o(this->path); float constance2 = o[DemandHandlerConfig::DEMAND] - [static_cast(ParameterIndex::CONSTANTE_2)]; - Event event = {EventType::CONSTANTE_2, constance2}; + [static_cast(ParameterIndex::CONSTANT_2)]; + Event event = {EventType::CONSTANT_2, constance2}; eventBus.publish(event); } @@ -161,7 +161,8 @@ void DemandHandler::pullPressureControlMode() { float pressureControlMode = o[DemandHandlerConfig::DEMAND] [static_cast(ParameterIndex::PRESSURE_CONTROL_MODE)]; - Event event = {EventType::PRESSURE_CONTROL_MODE, pressureControlMode != 0}; + Event event = {EventType::ENABLE_PRESSURE_CONTROL_MODE, + pressureControlMode != 0}; eventBus.publish(event); } @@ -169,7 +170,7 @@ void DemandHandler::pullSetPressure() { midas::odb o(this->path); float setPressure = o[DemandHandlerConfig::DEMAND] [static_cast(ParameterIndex::SET_PRESSURE)]; - Event event = {EventType::SET_PRESSURE, setPressure != 0}; + Event event = {EventType::ENABLE_SET_PRESSURE, setPressure != 0}; eventBus.publish(event); } diff --git a/src/device/handlers/DemandHandler.h b/src/device/handlers/DemandHandler.h index d9f4f00..0ee62c8 100644 --- a/src/device/handlers/DemandHandler.h +++ b/src/device/handlers/DemandHandler.h @@ -10,10 +10,10 @@ class DemandHandler { enum class EventType { MINIMAL_PRESSURE, MAXIMAL_PRESSURE, - CONSTANTE_1, - CONSTANTE_2, - PRESSURE_CONTROL_MODE, - SET_PRESSURE + CONSTANT_1, + CONSTANT_2, + ENABLE_PRESSURE_CONTROL_MODE, + ENABLE_SET_PRESSURE }; struct Event { @@ -32,8 +32,8 @@ class DemandHandler { */ void pullMinimalPressure(); void pullMaximalPressure(); - void pullConstante1(); - void pullConstante2(); + void pullConstant1(); + void pullConstant2(); void pullPressureControlMode(); void pullSetPressure(); diff --git a/src/device/handlers/DemandHandlerConfig.h b/src/device/handlers/DemandHandlerConfig.h index d08975c..39f24ad 100644 --- a/src/device/handlers/DemandHandlerConfig.h +++ b/src/device/handlers/DemandHandlerConfig.h @@ -14,8 +14,8 @@ enum class ParameterIndex { SET_PRESSURE = 7, MINIMAL_PRESSURE = 8, MAXIMAL_PRESSURE = 9, - CONSTANTE_1 = 10, - CONSTANTE_2 = 11, + CONSTANT_1 = 10, + CONSTANT_2 = 11, MAXIMUM_PARAMETER_INDEX = 11 }; diff --git a/src/device/handlers/FeedbackHandler.cpp b/src/device/handlers/FeedbackHandler.cpp index 1e34df6..9d1db2c 100644 --- a/src/device/handlers/FeedbackHandler.cpp +++ b/src/device/handlers/FeedbackHandler.cpp @@ -17,10 +17,10 @@ FeedbackHandler::FeedbackHandler(EventBus &eventBusReference, [this](const DemandHandler::Event &e) { generateOdbKeyIfNeeded(); switch (e.type) { - case DemandHandler::EventType::PRESSURE_CONTROL_MODE: + case DemandHandler::EventType::ENABLE_PRESSURE_CONTROL_MODE: enablePressureControlMode(std::get(e.value)); break; - case DemandHandler::EventType::SET_PRESSURE: + case DemandHandler::EventType::ENABLE_SET_PRESSURE: enableSetPressure(std::get(e.value)); break; default: @@ -48,10 +48,10 @@ FeedbackHandler::FeedbackHandler(EventBus &eventBusReference, eventBusReference.subscribe( [this](const PressureCalculator::Event &e) { generateOdbKeyIfNeeded(); - setConstante1(e.c1contrib); - setConstante2(e.c2contrib); - setPressureMinimum(e.uncapedPressure); - setPressureMaximum(e.uncapedPressure); + setConstant1(e.c1contrib); + setConstant2(e.c2contrib); + setPressureMinimum(e.uncappedPressure); + setPressureMaximum(e.uncappedPressure); setPressure(e.cappedPressure); setAveragePower(e.averagePower); }); @@ -109,11 +109,10 @@ void FeedbackHandler::setPressure(float value) { updatePressure(); } -void FeedbackHandler::setConstante1(float value) { +void FeedbackHandler::setConstant1(float value) { midas::odb o(path); o[FeedbackHandlerConf::OUTPUT_VARNAME] - [static_cast(FeedbackHandlerConf::RegisterIndex::CONSTANTE_1)] = - value; + [static_cast(FeedbackHandlerConf::RegisterIndex::CONSTANT_1)] = value; } void FeedbackHandler::setAveragePower(float value) { midas::odb o(path); @@ -122,11 +121,10 @@ void FeedbackHandler::setAveragePower(float value) { value; } -void FeedbackHandler::setConstante2(float value) { +void FeedbackHandler::setConstant2(float value) { midas::odb o(path); o[FeedbackHandlerConf::OUTPUT_VARNAME] - [static_cast(FeedbackHandlerConf::RegisterIndex::CONSTANTE_2)] = - value; + [static_cast(FeedbackHandlerConf::RegisterIndex::CONSTANT_2)] = value; } void FeedbackHandler::setPressureMinimum(float value) { diff --git a/src/device/handlers/FeedbackHandler.h b/src/device/handlers/FeedbackHandler.h index c3ef9e8..0e2ff68 100644 --- a/src/device/handlers/FeedbackHandler.h +++ b/src/device/handlers/FeedbackHandler.h @@ -30,8 +30,8 @@ class FeedbackHandler { void setPower(float value); void setAveragePower(float value); void setPressure(float value); - void setConstante1(float value); - void setConstante2(float value); + void setConstant1(float value); + void setConstant2(float value); /* Update pressure value diff --git a/src/device/handlers/FeedbackHandlerConfig.h b/src/device/handlers/FeedbackHandlerConfig.h index 16df396..2ef01b8 100644 --- a/src/device/handlers/FeedbackHandlerConfig.h +++ b/src/device/handlers/FeedbackHandlerConfig.h @@ -19,8 +19,8 @@ enum class RegisterIndex { PRESSURE = 5, MINIMUM_PRESSURE = 8, MAXIMUM_PRESSURE = 9, - CONSTANTE_1 = 10, - CONSTANTE_2 = 11, + CONSTANT_1 = 10, + CONSTANT_2 = 11, MAXIMUM_REGISTRY_INDEX = 11 // Used as a safety guard for undersize array. Put this enum member // always as the same value as the highest member diff --git a/src/device/handlers/OutputHandler.cpp b/src/device/handlers/OutputHandler.cpp index 4ec7d83..b686361 100644 --- a/src/device/handlers/OutputHandler.cpp +++ b/src/device/handlers/OutputHandler.cpp @@ -58,9 +58,6 @@ void OutputHandler::update() { isIndexValid = true; } - //// SHOULD I CRASH IF KEY NOT VALID ? - //// FOR NOW, FAILED SILENTLY - if (isSetPressureEnable && isKeyValid) o(OutputHandlerConfig::OUTPUT_VARIABLE)[outputPressureSPIndex] = pressure; @@ -71,7 +68,7 @@ OutputHandler::OutputHandler(EventBus &eventBusReference) { eventBusReference.subscribe( [this](const DemandHandler::Event &e) { switch (e.type) { - case DemandHandler::EventType::SET_PRESSURE: + case DemandHandler::EventType::ENABLE_SET_PRESSURE: enableSetPressure(std::get(e.value)); break; default: diff --git a/src/device/handlers/PressureCalculator.cpp b/src/device/handlers/PressureCalculator.cpp index 1dba962..58e3d93 100644 --- a/src/device/handlers/PressureCalculator.cpp +++ b/src/device/handlers/PressureCalculator.cpp @@ -3,34 +3,32 @@ #include "Average.h" #include "DemandHandler.h" #include "InputHandler.h" +#include #include void PressureCalculator::update() { - double averagePower = average.getAverage(); - double c2contrib = averagePower * cachedConstante2; - double c1contrib = - cachedConstante1 * (cachedTemperature - cachedSP - c2contrib); - double uncapedPressure = cachedMinimalPressure + c1contrib; + float averagePower = average.getAverage(); + float c2contrib = averagePower * cachedConstant2; + float c1contrib = + cachedConstant1 * (cachedTemperature - cachedSP - c2contrib); + float uncappedPressure = cachedMinimalPressure + c1contrib; - double cappedPressure = uncapedPressure; + float cappedPressure = uncappedPressure; if (c2contrib != 0) { - c2contrib = -c2contrib * cachedConstante1; + c2contrib = -c2contrib * cachedConstant1; } else { c2contrib = 0.0f; } - if (cappedPressure < cachedMinimalPressure) - cappedPressure = cachedMinimalPressure; - - if (cappedPressure > cachedMaximalPressure) - cappedPressure = cachedMaximalPressure; + cappedPressure = std::clamp(uncappedPressure, cachedMinimalPressure, + cachedMaximalPressure); Event event = {}; event.c1contrib = c1contrib; event.c2contrib = c2contrib; - event.uncapedPressure = uncapedPressure; + event.uncappedPressure = uncappedPressure; event.cappedPressure = cappedPressure; event.averagePower = averagePower; @@ -48,11 +46,11 @@ PressureCalculator::PressureCalculator(EventBus &eventBusReference) case DemandHandler::EventType::MAXIMAL_PRESSURE: updateMaximalPressure(std::get(e.value)); break; - case DemandHandler::EventType::CONSTANTE_1: - updateConstante1(std::get(e.value)); + case DemandHandler::EventType::CONSTANT_1: + updateConstant1(std::get(e.value)); break; - case DemandHandler::EventType::CONSTANTE_2: - updateConstante2(std::get(e.value)); + case DemandHandler::EventType::CONSTANT_2: + updateConstant2(std::get(e.value)); break; default: break; @@ -108,12 +106,12 @@ void PressureCalculator::updateMaximalPressure(float value) { update(); } -void PressureCalculator::updateConstante1(float value) { - cachedConstante1 = value; +void PressureCalculator::updateConstant1(float value) { + cachedConstant1 = value; update(); } -void PressureCalculator::updateConstante2(float value) { - cachedConstante2 = value; +void PressureCalculator::updateConstant2(float value) { + cachedConstant2 = value; update(); } diff --git a/src/device/handlers/PressureCalculator.h b/src/device/handlers/PressureCalculator.h index e5a1f15..3a4e835 100644 --- a/src/device/handlers/PressureCalculator.h +++ b/src/device/handlers/PressureCalculator.h @@ -11,7 +11,7 @@ class PressureCalculator { struct Event { float c1contrib; float c2contrib; - float uncapedPressure; + float uncappedPressure; float cappedPressure; float averagePower; }; @@ -26,8 +26,8 @@ class PressureCalculator { float cachedMinimalPressure; float cachedMaximalPressure; - float cachedConstante1; - float cachedConstante2; + float cachedConstant1; + float cachedConstant2; /* Internal value setters (from InputHandler) @@ -40,8 +40,8 @@ class PressureCalculator { */ void updateMinimalPressure(float value); void updateMaximalPressure(float value); - void updateConstante1(float value); - void updateConstante2(float value); + void updateConstant1(float value); + void updateConstant2(float value); /* Update pressure value