Skip to content
Snippets Groups Projects
Commit e4f712e0 authored by Armin Co's avatar Armin Co
Browse files

Show more states

parent 9b08b69d
No related branches found
No related tags found
No related merge requests found
...@@ -44,7 +44,6 @@ private: ...@@ -44,7 +44,6 @@ private:
void DataChange(uint32_t handle, const Node &node, const Variant &val, AttributeId attr) override void DataChange(uint32_t handle, const Node &node, const Variant &val, AttributeId attr) override
{ {
auto v = val.As<bool>(); auto v = val.As<bool>();
std::cout << v << std::endl;
m_state_machine.set_sim_mode_enabled(v); m_state_machine.set_sim_mode_enabled(v);
} }
SmgStateMachine &m_state_machine; SmgStateMachine &m_state_machine;
...@@ -70,10 +69,15 @@ void SmartOpcServer::setup_server() ...@@ -70,10 +69,15 @@ void SmartOpcServer::setup_server()
Node smart_grid_folder{m_objects_folder.AddFolder(m_idx, "smart_grid_model")}; Node smart_grid_folder{m_objects_folder.AddFolder(m_idx, "smart_grid_model")};
m_state = smart_grid_folder.AddObject(m_idx, "state"); m_state = smart_grid_folder.AddObject(m_idx, "state");
m_time = m_state.AddVariable(m_idx, "time", Variant(m_state_machine.m_model.get_time())); m_sun = m_state.AddVariable(m_idx, "sun-Power", Variant(m_state_machine.m_model.get_sun()));
m_wind = m_state.AddVariable(m_idx, "wind_power", Variant(m_state_machine.m_model.get_wind()));
m_power_production = m_state.AddVariable(m_idx, "power_production", Variant(m_state_machine.m_model.get_power_production()));
m_usage = m_state.AddVariable(m_idx, "used_power", Variant(m_state_machine.m_model.get_power_usage()));
m_excess_power = m_state.AddVariable(m_idx, "excess_power", Variant(m_state_machine.m_model.get_excess_power())); m_excess_power = m_state.AddVariable(m_idx, "excess_power", Variant(m_state_machine.m_model.get_excess_power()));
m_controls = smart_grid_folder.AddObject(m_idx, "controls"); m_controls = smart_grid_folder.AddObject(m_idx, "controls");
m_time = m_controls.AddVariable(m_idx, "time", Variant(m_state_machine.m_model.get_time()));
m_producing = m_controls.AddVariable(m_idx, "producing", Variant(m_state_machine.m_model.get_producing_state())); m_producing = m_controls.AddVariable(m_idx, "producing", Variant(m_state_machine.m_model.get_producing_state()));
m_sim_mode_enabled = m_controls.AddVariable(m_idx, "sim_mode_enabled", Variant(m_state_machine.is_sim_mode_enabled())); m_sim_mode_enabled = m_controls.AddVariable(m_idx, "sim_mode_enabled", Variant(m_state_machine.is_sim_mode_enabled()));
} }
...@@ -100,8 +104,12 @@ void SmartOpcServer::run_server() ...@@ -100,8 +104,12 @@ void SmartOpcServer::run_server()
m_state_machine.run(); m_state_machine.run();
// update opc objects // update opc objects
m_time.SetValue(Variant(m_state_machine.m_model.get_time())); m_sun.SetValue(Variant(m_state_machine.m_model.get_sun()));
m_wind.SetValue(Variant(m_state_machine.m_model.get_wind()));
m_power_production.SetValue(Variant(m_state_machine.m_model.get_power_production()));
m_usage.SetValue(Variant(m_state_machine.m_model.get_power_usage()));
m_excess_power.SetValue(Variant(m_state_machine.m_model.get_excess_power())); m_excess_power.SetValue(Variant(m_state_machine.m_model.get_excess_power()));
m_time.SetValue(Variant(m_state_machine.m_model.get_time()));
m_producing.SetValue(Variant(m_state_machine.m_model.get_producing_state())); m_producing.SetValue(Variant(m_state_machine.m_model.get_producing_state()));
m_sim_mode_enabled.SetValue(Variant(m_state_machine.is_sim_mode_enabled())); m_sim_mode_enabled.SetValue(Variant(m_state_machine.is_sim_mode_enabled()));
......
...@@ -31,10 +31,15 @@ private: ...@@ -31,10 +31,15 @@ private:
OpcUa::Node m_root_node; OpcUa::Node m_root_node;
OpcUa::Node m_state; OpcUa::Node m_state;
OpcUa::Node m_time; OpcUa::Node m_sun;
OpcUa::Node m_wind;
OpcUa::Node m_power_production;
OpcUa::Node m_usage;
OpcUa::Node m_excess_power; OpcUa::Node m_excess_power;
OpcUa::Node m_controls; OpcUa::Node m_controls;
OpcUa::Node m_time;
OpcUa::Node m_producing; OpcUa::Node m_producing;
OpcUa::Node m_sim_mode_enabled; OpcUa::Node m_sim_mode_enabled;
......
...@@ -14,7 +14,7 @@ SmartGridModel::SmartGridModel(HardwareControl &modell) ...@@ -14,7 +14,7 @@ SmartGridModel::SmartGridModel(HardwareControl &modell)
void SmartGridModel::update_wind() void SmartGridModel::update_wind()
{ {
auto wind_by_sun = m_sun * 9.0 / 100.0; // wind by sun should be 5 max. auto wind_by_sun = m_sun * 9.0 / 100.0; // wind by sun should be 5 max.
auto random_wind = ((std::rand() * 1.0) / RAND_MAX) * 3.0; auto random_wind = ((std::rand() * 1.0) / RAND_MAX) * 1.0;
m_wind = power_wind[static_cast<int>(wind_by_sun + random_wind)]; m_wind = power_wind[static_cast<int>(wind_by_sun + random_wind)];
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment