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

Update

parent 6e2f3d58
Branches
No related tags found
No related merge requests found
...@@ -6,9 +6,10 @@ set(CMAKE_CXX_STANDARD 17) ...@@ -6,9 +6,10 @@ set(CMAKE_CXX_STANDARD 17)
# Add spdlog for nice and easy logging # Add spdlog for nice and easy logging
add_subdirectory(libs/spdlog) add_subdirectory(libs/spdlog)
include_directories(src) include_directories(src)
include_directories(libs/spdlog/include)
include_directories(src/observ) include_directories(src/observ)
include_directories(libs/spdlog/include)
include_directories(src/com) include_directories(src/com)
add_library(soc_com add_library(soc_com
...@@ -17,15 +18,15 @@ add_library(soc_com ...@@ -17,15 +18,15 @@ add_library(soc_com
src/com/Socket.cpp) src/com/Socket.cpp)
# Test application to manually send commands to the Arduino # Test application to manually send commands to the Arduino
add_executable(manual_control src/manual_control/ComTest.cpp) # add_executable(manual_control src/manual_control/ComTest.cpp)
target_link_libraries(manual_control spdlog) # target_link_libraries(manual_control PRIVATE spdlog)
add_executable(sample_client # add_executable(sample_client
src/manual_control/sample_client.cpp # src/manual_control/sample_client.cpp
src/com/Socket.cpp # src/com/Socket.cpp
src/com/Protocol.cpp # src/com/Protocol.cpp
) # )
target_link_libraries(sample_client spdlog) # target_link_libraries(sample_client spdlog)
# Smart Grid Simulation # Smart Grid Simulation
include_directories(src/i2c) include_directories(src/i2c)
...@@ -33,24 +34,24 @@ include_directories(src/smart_grid) ...@@ -33,24 +34,24 @@ include_directories(src/smart_grid)
# Add OPC UA # Add OPC UA
if(BUILD_OPC_UA_FOR_INSTALL) # if(BUILD_OPC_UA_FOR_INSTALL)
macro(SET_OPTION option value) # macro(SET_OPTION option value)
set(${option} ${value} CACHE "" INTERNAL FORCE) # set(${option} ${value} CACHE "" INTERNAL FORCE)
endmacro() # endmacro()
option(BUILD_CLIENT "Build Client" OFF) # option(BUILD_CLIENT "Build Client" OFF)
option(BUILD_SERVER "Build Server" ON) # option(BUILD_SERVER "Build Server" ON)
#
option(SSL_SUPPORT_MBEDTLS "Support rsa-oaep password encryption using mbedtls library " OFF) # option(SSL_SUPPORT_MBEDTLS "Support rsa-oaep password encryption using mbedtls library " OFF)
#
option(BUILD_PYTHON "Build Python bindings" OFF) # option(BUILD_PYTHON "Build Python bindings" OFF)
option(BUILD_TESTING "Build and run tests" OFF) # option(BUILD_TESTING "Build and run tests" OFF)
option(BUILD_SHARED_LIBS "Build shared libraries." ON) # option(BUILD_SHARED_LIBS "Build shared libraries." ON)
add_subdirectory(libs/freeopcua) add_subdirectory(libs/freeopcua)
endif(BUILD_OPC_UA_FOR_INSTALL) # endif(BUILD_OPC_UA_FOR_INSTALL)
add_executable(opc_server.exe src/apps/SmgOPC_server/opc_server.cpp) # add_executable(opc_server.exe src/apps/SmgOPC_server/opc_server.cpp)
target_include_directories(opc_server.exe PUBLIC libs/freeopcua/include) # target_include_directories(opc_server.exe PUBLIC libs/freeopcua/include)
target_link_libraries(opc_server.exe opcuacore opcuaserver) # target_link_libraries(opc_server.exe PUBLIC opcuacore opcserver)
add_executable(smart_grid.exe add_executable(smart_grid.exe
...@@ -65,6 +66,6 @@ add_executable(smart_grid.exe ...@@ -65,6 +66,6 @@ add_executable(smart_grid.exe
) )
# target_link_libraries(smart_grid.exe PRIVATE spdlog) # target_link_libraries(smart_grid.exe PRIVATE spdlog)
target_compile_options(smart_grid.exe PRIVATE -Wall -Wextra -pedantic) # target_compile_options(smart_grid.exe PRIVATE -Wall -Wextra -pedantic)
target_include_directories(smart_grid.exe PUBLIC libs/freeopcua/include) target_include_directories(smart_grid.exe PUBLIC libs/freeopcua/include)
target_link_libraries(smart_grid.exe PUBLIC opcuacore opcuaserver) target_link_libraries(smart_grid.exe PUBLIC opcuacore PUBLIC opcuaserver PRIVATE spdlog)
...@@ -17,7 +17,6 @@ std::vector<OpcUa::Variant> my_method(NodeId context, std::vector<OpcUa::Variant ...@@ -17,7 +17,6 @@ std::vector<OpcUa::Variant> my_method(NodeId context, std::vector<OpcUa::Variant
auto vv = renewable.GetValue().As<double>(); auto vv = renewable.GetValue().As<double>();
vv += 1; vv += 1;
//renewable.SetValue(Variant(vv));
std::vector<OpcUa::Variant> result; std::vector<OpcUa::Variant> result;
result.push_back(Variant(static_cast<uint8_t>(0))); result.push_back(Variant(static_cast<uint8_t>(0)));
...@@ -29,7 +28,6 @@ class SubClient : public SubscriptionHandler ...@@ -29,7 +28,6 @@ class SubClient : public SubscriptionHandler
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
{ {
std::cout << "Received DataChange event for Node " << node << std::endl; std::cout << "Received DataChange event for Node " << node << std::endl;
} }
}; };
......
...@@ -53,7 +53,8 @@ private: ...@@ -53,7 +53,8 @@ private:
SmartOpcServer::SmartOpcServer(SmgStateMachine &state_machine) SmartOpcServer::SmartOpcServer(SmgStateMachine &state_machine)
: m_state_machine{state_machine} : m_state_machine{state_machine}
{ {
// m_logger = spdlog::stderr_color_mt("server"); m_logger = spdlog::stderr_color_mt("server");
m_logger->info("OPC Server is starting..");
m_server = UaServer(); m_server = UaServer();
m_server.SetEndpoint(k_opc_server_url); m_server.SetEndpoint(k_opc_server_url);
m_server.SetServerURI("Smart Grid OPC UA server"); m_server.SetServerURI("Smart Grid OPC UA server");
...@@ -69,12 +70,13 @@ void SmartOpcServer::setup_server() ...@@ -69,12 +70,13 @@ 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_sun = m_state.AddVariable(m_idx, "sun-Power", Variant(m_state_machine.m_model.get_sun())); 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_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().sum())); m_power_production = m_state.AddVariable(m_idx, "power_production", Variant(m_state_machine.m_model.get_power_production().sum()));
m_usage = m_state.AddVariable(m_idx, "used_power", Variant(m_state_machine.m_model.get_power_usage().sum())); m_usage = m_state.AddVariable(m_idx, "used_power", Variant(m_state_machine.m_model.get_power_usage().sum()));
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_renewable_power = m_state.AddVariable(m_idx, "renewable_power", Variant(m_state_machine.m_model.get_power_production().clean())); m_renewable_power = m_state.AddVariable(m_idx, "renewable_power", Variant(m_state_machine.m_model.get_power_production().clean()));
m_conventional_power = m_state.AddVariable(m_idx, "conventional_power", Variant(m_state_machine.m_model.get_power_production().conventional));
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_time = m_controls.AddVariable(m_idx, "time", Variant(m_state_machine.m_model.get_time()));
...@@ -113,6 +115,8 @@ void SmartOpcServer::run_server() ...@@ -113,6 +115,8 @@ void SmartOpcServer::run_server()
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()));
m_renewable_power.SetValue(m_state_machine.m_model.get_power_production().clean()); m_renewable_power.SetValue(m_state_machine.m_model.get_power_production().clean());
m_conventional_power.SetValue(m_state_machine.m_model.get_power_production().conventional);
std::this_thread::sleep_for(std::chrono::seconds(1)); std::this_thread::sleep_for(std::chrono::seconds(1));
m_logger->flush();
} }
} }
\ No newline at end of file
...@@ -37,6 +37,7 @@ private: ...@@ -37,6 +37,7 @@ private:
OpcUa::Node m_usage; OpcUa::Node m_usage;
OpcUa::Node m_excess_power; OpcUa::Node m_excess_power;
OpcUa::Node m_renewable_power; OpcUa::Node m_renewable_power;
OpcUa::Node m_conventional_power;
OpcUa::Node m_controls; OpcUa::Node m_controls;
OpcUa::Node m_time; OpcUa::Node m_time;
...@@ -44,7 +45,6 @@ private: ...@@ -44,7 +45,6 @@ private:
OpcUa::Node m_sim_mode_enabled; OpcUa::Node m_sim_mode_enabled;
std::shared_ptr<spdlog::logger> m_logger; std::shared_ptr<spdlog::logger> m_logger;
}; };
......
...@@ -13,30 +13,23 @@ ...@@ -13,30 +13,23 @@
#include "SmgStateMachine.hpp" #include "SmgStateMachine.hpp"
#include "SmartOpcServer.hpp" #include "SmartOpcServer.hpp"
/// @brief Log user inputs
///
void log_args(int argc, char **argv)
{
// spdlog::debug("User arguments:");
// for (int i = 0; i < argc; ++i)
// {
// spdlog::debug("[{}] {}", i, argv[i]);
// }
}
int main(int argc, char **argv) int main(int argc, char **argv)
{ {
// spdlog::set_level(spdlog::level::info); auto log_main = spdlog::stdout_color_st("main");
// spdlog::info("Starting - Smart Grid Modell"); log_main->info("Starting - Smart Grid Model");
// log_args(argc, argv);
uint8_t slave_address{0x14}; uint8_t slave_address{0x14};
i2c::Node i2c_channel{slave_address}; i2c::Node i2c_channel{slave_address};
if (false == i2c_channel.open_device("/dev/i2c-1")) if (false == i2c_channel.open_device("/dev/i2c-1"))
{ {
log_main->error("Failed to open i2c device!");
exit(1); exit(1);
} }
std::cout << "At least hardware works!" << std::endl; else
{
log_main->info("Connecting to model via I2C was successfull!");
}
HardwareControl hardware{i2c_channel}; HardwareControl hardware{i2c_channel};
SmartGridModel model{hardware}; SmartGridModel model{hardware};
...@@ -46,6 +39,6 @@ int main(int argc, char **argv) ...@@ -46,6 +39,6 @@ int main(int argc, char **argv)
SmartOpcServer server{stateMachine}; SmartOpcServer server{stateMachine};
server.run_server(); server.run_server();
// spdlog::info("End"); log_main->info("Done!");
return 0; return 0;
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment