diff --git a/src/device/handlers/DemandHandler.cpp b/src/device/handlers/DemandHandler.cpp index daeb96e..17babc7 100644 --- a/src/device/handlers/DemandHandler.cpp +++ b/src/device/handlers/DemandHandler.cpp @@ -14,6 +14,11 @@ bool DemandHandler::init() { if (!midas::odb::exists(this->path)) { TMFE::Instance()->Msg(MERROR, __FUNCTION__, "Key at %s doesn't exists", path.c_str()); + + midas::odb o(this->path); + std::vector v = {0.0}; + o = v; + initSuccess = false; } midas::odb o(this->path); diff --git a/src/device/handlers/FeedbackHandler.cpp b/src/device/handlers/FeedbackHandler.cpp index 3796fc8..27297f1 100644 --- a/src/device/handlers/FeedbackHandler.cpp +++ b/src/device/handlers/FeedbackHandler.cpp @@ -54,6 +54,15 @@ 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] diff --git a/src/device/handlers/FeedbackHandlerConfig.h b/src/device/handlers/FeedbackHandlerConfig.h index 0b4c522..16df396 100644 --- a/src/device/handlers/FeedbackHandlerConfig.h +++ b/src/device/handlers/FeedbackHandlerConfig.h @@ -20,7 +20,10 @@ enum class RegisterIndex { MINIMUM_PRESSURE = 8, MAXIMUM_PRESSURE = 9, CONSTANTE_1 = 10, - CONSTANTE_2 = 11 + CONSTANTE_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 }; } // namespace FeedbackHandlerConf diff --git a/src/device/handlers/SettingsHandler.cpp b/src/device/handlers/SettingsHandler.cpp index 779b241..3312478 100644 --- a/src/device/handlers/SettingsHandler.cpp +++ b/src/device/handlers/SettingsHandler.cpp @@ -90,9 +90,30 @@ bool SettingsHandler::init() { areKeysValids = false; } - if (!areKeysValids) + if (!areKeysValids) { + midas::odb o = { + {SettingsHandlerConfig::EQUIPMENT_NAME.c_str(), + {SettingsHandlerConfig::DEFAULT_EQUIPMENT_NAME.c_str()}}, + {SettingsHandlerConfig::OUTPUT_PRESSURE_SP_INDEX.c_str(), + {SettingsHandlerConfig::DEFAULT_INDEX_VALUE}}, + {SettingsHandlerConfig::INPUT_SP_INDEX.c_str(), + {SettingsHandlerConfig::DEFAULT_INDEX_VALUE}}, + {SettingsHandlerConfig::INPUT_TEMPERATURE_INDEX.c_str(), + {SettingsHandlerConfig::DEFAULT_INDEX_VALUE}}, + {SettingsHandlerConfig::INPUT_POWER_INDEX.c_str(), + {SettingsHandlerConfig::DEFAULT_INDEX_VALUE}}, + {SettingsHandlerConfig::TIME_WINDOW.c_str(), + {SettingsHandlerConfig::DEFAULT_TIME_WINDOWS_SIZE}}}; + + TMFE::Instance()->Msg( + MERROR, __FUNCTION__, + "Some keys are missing at %s. Please fill the generated template.", + path.c_str()); + + o.connect(this->path); throw std::runtime_error("SettinsHandler init failed - see MIDAS " "console and take care of all the errors\n"); + } this->pullEquipmentName(); this->pullOutputPressureSPIndex(); diff --git a/src/device/handlers/SettingsHandlerConfig.h b/src/device/handlers/SettingsHandlerConfig.h index 4fec93a..404b5b8 100644 --- a/src/device/handlers/SettingsHandlerConfig.h +++ b/src/device/handlers/SettingsHandlerConfig.h @@ -13,6 +13,11 @@ const std::string OUTPUT_PRESSURE_SP_INDEX = "MITC_OutputPressSPIndex"; const std::string INPUT_SP_INDEX = "MITC_InputVarioxSPIndex"; const std::string INPUT_TEMPERATURE_INDEX = "MITC_InputVarioxTempIndex"; const std::string INPUT_POWER_INDEX = "MITC_InputVarioxPowIndex"; +const std::string TIME_WINDOW = "Average_Power_Time_Window"; + +const std::string DEFAULT_EQUIPMENT_NAME = ""; +const int DEFAULT_INDEX_VALUE = -1; +const float DEFAULT_TIME_WINDOWS_SIZE = 30.0f; } // namespace SettingsHandlerConfig