From e4f712e078910f5d73dc058c4ec5d72d8cabefb4 Mon Sep 17 00:00:00 2001 From: Armin Co <armin.co@hs-bochum.de> Date: Wed, 7 Oct 2020 08:22:37 +0200 Subject: [PATCH] Show more states --- src/apps/smart_grid/SmartOpcServer.cpp | 14 +++++++++++--- src/apps/smart_grid/SmartOpcServer.hpp | 7 ++++++- src/smart_grid/SmartGridModel.cpp | 2 +- 3 files changed, 18 insertions(+), 5 deletions(-) diff --git a/src/apps/smart_grid/SmartOpcServer.cpp b/src/apps/smart_grid/SmartOpcServer.cpp index 9b73863..7d7dc24 100644 --- a/src/apps/smart_grid/SmartOpcServer.cpp +++ b/src/apps/smart_grid/SmartOpcServer.cpp @@ -44,7 +44,6 @@ private: void DataChange(uint32_t handle, const Node &node, const Variant &val, AttributeId attr) override { auto v = val.As<bool>(); - std::cout << v << std::endl; m_state_machine.set_sim_mode_enabled(v); } SmgStateMachine &m_state_machine; @@ -70,10 +69,15 @@ void SmartOpcServer::setup_server() Node smart_grid_folder{m_objects_folder.AddFolder(m_idx, "smart_grid_model")}; 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_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_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() m_state_machine.run(); // 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_time.SetValue(Variant(m_state_machine.m_model.get_time())); 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())); diff --git a/src/apps/smart_grid/SmartOpcServer.hpp b/src/apps/smart_grid/SmartOpcServer.hpp index a0447a7..2d489e7 100644 --- a/src/apps/smart_grid/SmartOpcServer.hpp +++ b/src/apps/smart_grid/SmartOpcServer.hpp @@ -31,10 +31,15 @@ private: OpcUa::Node m_root_node; 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_controls; + OpcUa::Node m_time; OpcUa::Node m_producing; OpcUa::Node m_sim_mode_enabled; diff --git a/src/smart_grid/SmartGridModel.cpp b/src/smart_grid/SmartGridModel.cpp index cae77c1..b6de813 100644 --- a/src/smart_grid/SmartGridModel.cpp +++ b/src/smart_grid/SmartGridModel.cpp @@ -14,7 +14,7 @@ SmartGridModel::SmartGridModel(HardwareControl &modell) void SmartGridModel::update_wind() { 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)]; } -- GitLab