update
This commit is contained in:
@@ -30,6 +30,8 @@ add_library(
|
||||
itcPressureOptimizer
|
||||
src/device/itc_pressure_optimizer.cpp
|
||||
src/device/DemandHandler.cpp
|
||||
src/device/InputHandler.cpp
|
||||
src/device/SettingsHandler.cpp
|
||||
)
|
||||
|
||||
set_property(
|
||||
|
||||
@@ -19,6 +19,8 @@ bool DemandHandler::init() {
|
||||
|
||||
bool indexValid = true;
|
||||
|
||||
// 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)) {
|
||||
indexValid = false;
|
||||
}
|
||||
@@ -35,11 +37,11 @@ bool DemandHandler::init() {
|
||||
if (indexValid)
|
||||
return false;
|
||||
|
||||
pullMinimalPressure();
|
||||
pullMaximalPressure();
|
||||
pullConstante1();
|
||||
pullConstante2();
|
||||
pullPressureControlMode();
|
||||
this->pullMinimalPressure();
|
||||
this->pullMaximalPressure();
|
||||
this->pullConstante1();
|
||||
this->pullConstante2();
|
||||
this->pullPressureControlMode();
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -116,6 +118,7 @@ DemandHandler::DemandHandler(EventBus &eventBusReference,
|
||||
|
||||
eventBus.subscribe<itcPressureOptimizer::EquipmentInitEvent>(
|
||||
[this](const itcPressureOptimizer::EquipmentInitEvent &e) {
|
||||
printf("[EquipmentInitEvent] : init recived\n");
|
||||
this->init();
|
||||
this->setHotlink();
|
||||
});
|
||||
}
|
||||
|
||||
@@ -0,0 +1,39 @@
|
||||
#ifndef FEEDBACK_HANDLER_CONFIG_H
|
||||
#define FEEDBACK_HANDLER_CONFIG_H
|
||||
|
||||
#include <string>
|
||||
|
||||
class FeedbackHandler {
|
||||
private:
|
||||
bool isPressureControlModeEnable;
|
||||
std::string equipmentName;
|
||||
std::string odbPath;
|
||||
std::string outputKeyName = "Measured"
|
||||
|
||||
enum class RegisterIndex : uint16_t {
|
||||
SetPoint = 1,
|
||||
Temperature = 2,
|
||||
Power = 3,
|
||||
AveragePower = 4,
|
||||
Pressure = 5,
|
||||
Constante1 = 10,
|
||||
Constante2 = 11
|
||||
};
|
||||
|
||||
void setValueToOdb(int index, float value);
|
||||
|
||||
public:
|
||||
FeedbackHandler(std::string equipmentName);
|
||||
|
||||
void enablePressureControlMode(bool enable);
|
||||
|
||||
void setSP(float value);
|
||||
void setTemperature(float value);
|
||||
void setPower(float value);
|
||||
void setAveragePower(float value);
|
||||
void setPressure(float value);
|
||||
void setConstante1(float value);
|
||||
void setConstante2(float value);
|
||||
};
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,85 @@
|
||||
#include "InputHandler.h"
|
||||
#include "EventBus.h"
|
||||
#include "InputHandlerConfig.h"
|
||||
#include "SettingsHandler.h"
|
||||
|
||||
#include <string>
|
||||
#include <variant>
|
||||
|
||||
void InputHandler::updatePath(std::string name) {
|
||||
this->path = InputHandlerConfig::PATH_PREFIX + name +
|
||||
InputHandlerConfig::PATH_SUFFIX;
|
||||
}
|
||||
|
||||
void InputHandler::updateSPIndex(int index) { this->SPIndex = index; }
|
||||
|
||||
void InputHandler::updateTemperatureIndex(int index) {
|
||||
this->temperatureIndex = index;
|
||||
}
|
||||
|
||||
void InputHandler::updatePowerIndex(int index) { this->powerIndex = index; }
|
||||
|
||||
void InputHandler::pullSPValue() {
|
||||
midas::odb o(this->path);
|
||||
float SPValue = o[SPIndex];
|
||||
Event event = {EventType::SP_VALUE, SPValue};
|
||||
eventBus.publish(event);
|
||||
}
|
||||
void InputHandler::pullTemperatureValue() {
|
||||
midas::odb o(this->path);
|
||||
float temperatureValue = o[temperatureIndex];
|
||||
Event event = {EventType::TEMPERATURE_VALUE, temperatureValue};
|
||||
eventBus.publish(event);
|
||||
}
|
||||
void InputHandler::pullPowerValue() {
|
||||
midas::odb o(this->path);
|
||||
float powerValue = o[powerIndex];
|
||||
Event event = {EventType::POWER_VALUE, powerValue};
|
||||
eventBus.publish(event);
|
||||
}
|
||||
|
||||
void InputHandler::updateHotlink() {
|
||||
// TODO : Verified this code work
|
||||
// This should change the target in case of a new name given
|
||||
if (hotlink) {
|
||||
hotlink->unwatch();
|
||||
hotlink.reset();
|
||||
}
|
||||
|
||||
hotlink.emplace(path);
|
||||
|
||||
hotlink->watch([&](midas::odb &arg) {
|
||||
int hotlinkIndex = arg.get_last_index();
|
||||
if (hotlinkIndex == SPIndex) {
|
||||
pullSPValue();
|
||||
} else if (hotlinkIndex == temperatureIndex) {
|
||||
pullTemperatureValue();
|
||||
} else if (hotlinkIndex == powerIndex) {
|
||||
pullPowerValue();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
InputHandler::InputHandler(EventBus &eventBusReference)
|
||||
: eventBus(eventBusReference) {
|
||||
eventBus.subscribe<SettingsHandler::Event>(
|
||||
[this](const SettingsHandler::Event &e) {
|
||||
switch (e.type) {
|
||||
case SettingsHandler::EventType::EQUIPMENT_NAME:
|
||||
updatePath(std::get<std::string>(e.value));
|
||||
updateHotlink();
|
||||
break;
|
||||
case SettingsHandler::EventType::INPUT_SP_INDEX:
|
||||
updateSPIndex(std::get<int>(e.value));
|
||||
break;
|
||||
case SettingsHandler::EventType::INPUT_TEMPERATURE_INDEX:
|
||||
updateTemperatureIndex(std::get<int>(e.value));
|
||||
break;
|
||||
case SettingsHandler::EventType::INPUT_POWER_INDEX:
|
||||
updatePowerIndex(std::get<int>(e.value));
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@@ -1,15 +1,45 @@
|
||||
#ifndef INPUT_HANDLER_H
|
||||
#define INPUT_HANDLER_H
|
||||
|
||||
#include "EventBus.h"
|
||||
#include "odbxx.h"
|
||||
#include <optional>
|
||||
#include <string>
|
||||
|
||||
class InputHandler {
|
||||
private:
|
||||
std::string equipmentName;
|
||||
float cachedSP;
|
||||
float cachedTemperature;
|
||||
float cachedPower;
|
||||
EventBus &eventBus;
|
||||
std::string path;
|
||||
int SPIndex;
|
||||
int temperatureIndex;
|
||||
int powerIndex;
|
||||
|
||||
public:
|
||||
void updateEquipmentName(std::string name);
|
||||
std::optional<midas::odb> hotlink;
|
||||
|
||||
enum class EventType {
|
||||
SP_VALUE,
|
||||
TEMPERATURE_VALUE,
|
||||
POWER_VALUE,
|
||||
};
|
||||
|
||||
struct Event {
|
||||
EventType type;
|
||||
float value;
|
||||
};
|
||||
|
||||
void updatePath(std::string name);
|
||||
void updateSPIndex(int index);
|
||||
void updateTemperatureIndex(int index);
|
||||
void updatePowerIndex(int index);
|
||||
|
||||
void updateHotlink();
|
||||
|
||||
void pullSPValue();
|
||||
void pullTemperatureValue();
|
||||
void pullPowerValue();
|
||||
|
||||
public:
|
||||
InputHandler(EventBus &eventBusReference);
|
||||
};
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,14 @@
|
||||
#ifndef INPUT_HANDLER_CONFIG_H
|
||||
#define INPUT_HANDLER_CONFIG_H
|
||||
|
||||
#include <string>
|
||||
|
||||
namespace InputHandlerConfig {
|
||||
|
||||
const std::string PATH_PREFIX = "/Equipment/";
|
||||
const std::string PATH_SUFFIX = "/Variables";
|
||||
|
||||
const std::string INPUT_VARIABLE = "Input";
|
||||
|
||||
} // namespace InputHandlerConfig
|
||||
#endif
|
||||
@@ -2,12 +2,36 @@
|
||||
#include <string>
|
||||
|
||||
void PressureCalculator::update() {
|
||||
double c2 = average.getAverage() * cachedConstante2;
|
||||
double c1 = cachedConstante1 * (cachedTemperature - cachedSP - c2);
|
||||
double uncapedPressure = cachedMinimalPressure + c1;
|
||||
|
||||
if (c2 != 0) {
|
||||
double c2contrib = average.getAverage() * cachedConstante2;
|
||||
double c1contrib =
|
||||
cachedConstante1 * (cachedTemperature - cachedSP - c2contrib);
|
||||
double uncapedPressure = cachedMinimalPressure + c1contrib;
|
||||
|
||||
double cappedPressure = uncapedPressure;
|
||||
|
||||
if (c2contrib != 0) {
|
||||
c2contrib = -c2contrib * cachedConstante1;
|
||||
} else {
|
||||
c2contrib = 0.0f;
|
||||
}
|
||||
|
||||
if (cappedPressure < cachedMinimalPressure)
|
||||
cappedPressure = cachedMinimalPressure;
|
||||
|
||||
if (cappedPressure > cachedMaximalPressure)
|
||||
cappedPressure = cachedMaximalPressure;
|
||||
|
||||
Event event = {};
|
||||
|
||||
if (c2contrib != 0) {
|
||||
event.c1contrib = c1contrib;
|
||||
event.c2contrib = c2contrib;
|
||||
event.uncapedPressure = uncapedPressure;
|
||||
event.cappedPressure = cappedPressure;
|
||||
}
|
||||
|
||||
eventBus.publish(event);
|
||||
}
|
||||
|
||||
void PressureCalculator::updateSP(float value) {
|
||||
|
||||
@@ -3,7 +3,15 @@
|
||||
class PressureCalculator {
|
||||
private:
|
||||
Average average;
|
||||
OutputHandler outputHandler;
|
||||
EventBus &eventBus;
|
||||
|
||||
struct Event {
|
||||
float c1contrib;
|
||||
float c2contrib;
|
||||
float uncapedPressure;
|
||||
float cappedPressure;
|
||||
};
|
||||
|
||||
float cachedSP;
|
||||
float cachedTemperature;
|
||||
float cachedPower;
|
||||
@@ -13,9 +21,6 @@ class PressureCalculator {
|
||||
float cachedConstante1;
|
||||
float cachedConstante2;
|
||||
|
||||
public:
|
||||
void update();
|
||||
|
||||
void updateSP(float value);
|
||||
void updateTemperature(float value);
|
||||
void updatePower(float value);
|
||||
@@ -24,4 +29,7 @@ class PressureCalculator {
|
||||
void updateMaximalPressure(float value);
|
||||
void updateConstante1(float value);
|
||||
void updateConstante2(float value);
|
||||
|
||||
public:
|
||||
void update();
|
||||
};
|
||||
|
||||
@@ -1,35 +1,55 @@
|
||||
#include "SettingsHandler.h"
|
||||
#include "SettingsHandlerConfig.h"
|
||||
#include "itc_pressure_optimizer.h"
|
||||
#include <string>
|
||||
|
||||
using namespace SettingsHandlerConfig;
|
||||
|
||||
void SettingsHandler::pullEquipmentName() {
|
||||
midas::odb o(this->path);
|
||||
std::string equipmentName = o[ParameterIndex::EQUIPMENT_NAME];
|
||||
inputHandler.get().updateEquipmentName(equipmentName);
|
||||
std::string equipmentName = o(SettingsHandlerConfig::EQUIPMENT_NAME);
|
||||
Event event = {EventType::EQUIPMENT_NAME, equipmentName};
|
||||
eventBus.publish(event);
|
||||
}
|
||||
|
||||
void SettingsHandler::pullOutputPressureSPIndex() {
|
||||
midas::odb o(this->path);
|
||||
int outputPressureSPIndex = o[ParameterIndex::OUTPUT_PRESSURE_SP_INDEX];
|
||||
inputHandler.get().updateEquipmentName(equipmentName);
|
||||
int outputPressureSPIndex =
|
||||
o(SettingsHandlerConfig::OUTPUT_PRESSURE_SP_INDEX);
|
||||
Event event = {EventType::OUTPUT_PRESSURE_SP_INDEX, outputPressureSPIndex};
|
||||
eventBus.publish(event);
|
||||
}
|
||||
|
||||
void SettingsHandler::pullInputVarioxSPIndex() {
|
||||
void SettingsHandler::pullInputSPIndex() {
|
||||
midas::odb o(this->path);
|
||||
std::string equipmentName = o[ParameterIndex::INPUT_VARIOX_SP_INDEX];
|
||||
inputHandler.get().updateEquipmentName(equipmentName);
|
||||
int inputSPIndex = o(SettingsHandlerConfig::INPUT_SP_INDEX);
|
||||
Event event = {EventType::INPUT_SP_INDEX, inputSPIndex};
|
||||
eventBus.publish(event);
|
||||
}
|
||||
|
||||
void SettingsHandler::pullInputVarioxTemperatureIndex() {
|
||||
void SettingsHandler::pullInputTemperatureIndex() {
|
||||
midas::odb o(this->path);
|
||||
std::string equipmentName =
|
||||
o[ParameterIndex::INPUT_VARIOX_TEMPERATURE_INDEX];
|
||||
inputHandler.get().updateEquipmentName(equipmentName);
|
||||
int temperatureIndex = o(SettingsHandlerConfig::INPUT_TEMPERATURE_INDEX);
|
||||
Event event = {EventType::INPUT_TEMPERATURE_INDEX, temperatureIndex};
|
||||
eventBus.publish(event);
|
||||
}
|
||||
|
||||
void SettingsHandler::pullInputVarioxPowerIndex() {
|
||||
void SettingsHandler::pullInputPowerIndex() {
|
||||
midas::odb o(this->path);
|
||||
std::string equipmentName = o[ParameterIndex::INPUT_VARIOX_POWER_INDEX];
|
||||
inputHandler.get().updateEquipmentName(equipmentName);
|
||||
int powerIndex = o(SettingsHandlerConfig::INPUT_POWER_INDEX);
|
||||
Event event = {EventType::INPUT_POWER_INDEX, powerIndex};
|
||||
eventBus.publish(event);
|
||||
}
|
||||
|
||||
SettingsHandler::SettingsHandler(EventBus &eventBusReference,
|
||||
std::string equipmentName)
|
||||
: path(SettingsHandlerConfig::PATH_PREFIX + equipmentName +
|
||||
SettingsHandlerConfig::PATH_SUFFIX),
|
||||
eventBus(eventBusReference) {
|
||||
eventBus.subscribe<itcPressureOptimizer::EquipmentInitEvent>(
|
||||
[this](const itcPressureOptimizer::EquipmentInitEvent &e) {
|
||||
this->init();
|
||||
});
|
||||
}
|
||||
|
||||
bool SettingsHandler::init() {
|
||||
@@ -37,21 +57,26 @@ bool SettingsHandler::init() {
|
||||
|
||||
bool areKeysValids = true;
|
||||
|
||||
if (!o.exists(Configuration::EQUIPMENT_NAME)) {
|
||||
if (!o.exists(SettingsHandlerConfig::EQUIPMENT_NAME)) {
|
||||
areKeysValids = false;
|
||||
}
|
||||
if (!o.exists(Configuration::OUTPUT_PRESSURE_SP_INDEX)) {
|
||||
if (!o.exists(SettingsHandlerConfig::OUTPUT_PRESSURE_SP_INDEX)) {
|
||||
areKeysValids = false;
|
||||
}
|
||||
if (!o.exists(Configuration::EQUIPMINPUT_VARIOX_SP_INDEXENT_NAME)) {
|
||||
if (!o.exists(SettingsHandlerConfig::INPUT_SP_INDEX)) {
|
||||
areKeysValids = false;
|
||||
}
|
||||
if (!o.exists(Configuration::INPUT_VARIOX_TEMPERATURE_INDEX)) {
|
||||
if (!o.exists(SettingsHandlerConfig::INPUT_TEMPERATURE_INDEX)) {
|
||||
areKeysValids = false;
|
||||
}
|
||||
if (!o.exists(Configuration::INPUT_VARIOX_POWER_INDEX)) {
|
||||
if (!o.exists(SettingsHandlerConfig::INPUT_POWER_INDEX)) {
|
||||
areKeysValids = false;
|
||||
}
|
||||
}
|
||||
|
||||
bool SettingsHandler::setHotlink() { return false; }
|
||||
this->pullEquipmentName();
|
||||
this->pullOutputPressureSPIndex();
|
||||
this->pullInputSPIndex();
|
||||
this->pullInputTemperatureIndex();
|
||||
this->pullInputPowerIndex();
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -4,21 +4,37 @@
|
||||
#include "InputHandler.h"
|
||||
#include <functional>
|
||||
#include <string>
|
||||
#include <variant>
|
||||
|
||||
class SettingsHandler {
|
||||
|
||||
public:
|
||||
SettingsHandler(EventBus &eventBusReference, std::string equipmentName);
|
||||
bool init();
|
||||
bool setHotlink();
|
||||
|
||||
enum class EventType {
|
||||
EQUIPMENT_NAME,
|
||||
OUTPUT_PRESSURE_SP_INDEX,
|
||||
INPUT_SP_INDEX,
|
||||
INPUT_TEMPERATURE_INDEX,
|
||||
INPUT_POWER_INDEX
|
||||
};
|
||||
|
||||
struct Event {
|
||||
EventType type;
|
||||
std::variant<int, std::string> value;
|
||||
};
|
||||
|
||||
private:
|
||||
std::string path;
|
||||
std::reference_wrapper<InputHandler> inputHandler;
|
||||
EventBus &eventBus;
|
||||
|
||||
void pullEquipmentName();
|
||||
void pullOutputPressureSPIndex();
|
||||
void pullInputVarioxSPIndex();
|
||||
void pullInputVarioxTemperatureIndex();
|
||||
void pullInputVarioxPowerIndex();
|
||||
|
||||
public:
|
||||
bool init();
|
||||
bool setHotlink();
|
||||
void pullInputSPIndex();
|
||||
void pullInputTemperatureIndex();
|
||||
void pullInputPowerIndex();
|
||||
};
|
||||
|
||||
#endif
|
||||
@@ -3,17 +3,17 @@
|
||||
|
||||
#include <string>
|
||||
|
||||
namespace Configuration {
|
||||
namespace SettingsHandlerConfig {
|
||||
|
||||
const std::string PATH_PREFIX = "/Equipment/";
|
||||
const std::string PATH_SUFFIX = "/Devices/MITCPRESSC/DD/";
|
||||
|
||||
const std::string EQUIPMENT_NAME = "MITC_equipment";
|
||||
const std::string OUTPUT_PRESSURE_SP_INDEX = "MITC_OutputPressSPIndex";
|
||||
const std::string INPUT_VARIOX_SP_INDEX = "MITC_InputVarioxSPIndex";
|
||||
const std::string INPUT_VARIOX_TEMPERATURE_INDEX = "MITC_InputVarioxTempIndex";
|
||||
const std::string INPUT_VARIOX_POWER_INDEX = "MITC_InputVarioxPowIndex";
|
||||
const std::string INPUT_SP_INDEX = "MITC_InputVarioxSPIndex";
|
||||
const std::string INPUT_TEMPERATURE_INDEX = "MITC_InputVarioxTempIndex";
|
||||
const std::string INPUT_POWER_INDEX = "MITC_InputVarioxPowIndex";
|
||||
|
||||
} // namespace Configuration
|
||||
} // namespace SettingsHandlerConfig
|
||||
|
||||
#endif
|
||||
@@ -13,14 +13,15 @@
|
||||
itcPressureOptimizer::itcPressureOptimizer(std::string equipmentName,
|
||||
const char *equipmentFilename)
|
||||
: TMFeEquipment(equipmentName.c_str(), equipmentFilename), eventBus(),
|
||||
demandHandler(eventBus, equipmentName) {
|
||||
demandHandler(eventBus, equipmentName),
|
||||
settingsHandler(eventBus, equipmentName), inputHandler(eventBus) {
|
||||
fEqConfPeriodMilliSec = 1000; // refresh every seconds
|
||||
fEqConfLogHistory = 1;
|
||||
fEqConfReadOnlyWhenRunning = false;
|
||||
fEqConfWriteEventsToOdb = true;
|
||||
}
|
||||
|
||||
/*, feedbackHandler(), inputHandler(),
|
||||
/*, feedbackHandler(), ,
|
||||
outputHandler(), pressureCalculator(),
|
||||
settingsHandler()*/
|
||||
|
||||
|
||||
@@ -3,11 +3,11 @@
|
||||
|
||||
#include "DemandHandler.h"
|
||||
#include "EventBus.h"
|
||||
#include "InputHandler.h"
|
||||
#include "SettingsHandler.h"
|
||||
// #include "FeedbackHandler.h"
|
||||
// #include "InputHandler.h"
|
||||
// #include "OutputHandler.h"
|
||||
// #include "PressureCalculator.h"
|
||||
// #include "SettingsHandler.h"
|
||||
|
||||
#include "tmfe.h"
|
||||
#include <string>
|
||||
@@ -38,11 +38,11 @@ class itcPressureOptimizer : public TMFeEquipment {
|
||||
private:
|
||||
EventBus eventBus;
|
||||
DemandHandler demandHandler;
|
||||
SettingsHandler settingsHandler;
|
||||
InputHandler inputHandler;
|
||||
// FeedbackHandler feedbackHandler;
|
||||
// InputHandler inputHandler;
|
||||
// OutputHandler outputHandler;
|
||||
// PressureCalculator pressureCalculator;
|
||||
// SettingsHandler settingsHandler;
|
||||
};
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user