diff --git a/CMakeLists.txt b/CMakeLists.txt index e46d6c9dfde8352b127950323d6cda0660b990bf..1a6a4761829c184915ffb4986cee2f2e54d91c22 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -31,6 +31,28 @@ target_link_libraries(sample_client spdlog) include_directories(src/i2c) include_directories(src/smart_grid) + +# Add OPC UA +if(BUILD_OPC_UA_FOR_INSTALL) + macro(SET_OPTION option value) + set(${option} ${value} CACHE "" INTERNAL FORCE) + endmacro() + option(BUILD_CLIENT "Build Client" OFF) + option(BUILD_SERVER "Build Server" ON) + + option(SSL_SUPPORT_MBEDTLS "Support rsa-oaep password encryption using mbedtls library " OFF) + + option(BUILD_PYTHON "Build Python bindings" OFF) + option(BUILD_TESTING "Build and run tests" OFF) + option(BUILD_SHARED_LIBS "Build shared libraries." ON) + add_subdirectory(libs/freeopcua) +endif(BUILD_OPC_UA_FOR_INSTALL) + +add_executable(opc_server.exe src/apps/SmgOPC_server/opc_server.cpp) +target_include_directories(opc_server.exe PUBLIC libs/freeopcua/include) +target_link_libraries(opc_server.exe opcuacore opcuaserver) + + add_executable(smart_grid.exe src/apps/smart_grid/smg_server.cpp src/apps/smart_grid/SmgStateMachine.cpp @@ -42,29 +64,7 @@ add_executable(smart_grid.exe src/smart_grid/HardwareControl.cpp ) -target_link_libraries(smart_grid.exe spdlog) +# target_link_libraries(smart_grid.exe PRIVATE spdlog) target_compile_options(smart_grid.exe PRIVATE -Wall -Wextra -pedantic) target_include_directories(smart_grid.exe PUBLIC libs/freeopcua/include) -target_link_libraries(smart_grid.exe opcuacore opcuaserver) - -# Add OPC UA -if(BUILD_OPC_UA_FOR_INSTALL) - - -macro(SET_OPTION option value) -set(${option} ${value} CACHE "" INTERNAL FORCE) -endmacro() -option(BUILD_CLIENT "Build Client" OFF) -option(BUILD_SERVER "Build Server" ON) - -option(SSL_SUPPORT_MBEDTLS "Support rsa-oaep password encryption using mbedtls library " OFF) - -option(BUILD_PYTHON "Build Python bindings" OFF) -option(BUILD_TESTING "Build and run tests" OFF) -option(BUILD_SHARED_LIBS "Build shared libraries." ON) -add_subdirectory(libs/freeopcua) -endif(BUILD_OPC_UA_FOR_INSTALL) - -add_executable(opc_server.exe src/apps/SmgOPC_server/opc_server.cpp) -target_include_directories(opc_server.exe PUBLIC libs/freeopcua/include) -target_link_libraries(opc_server.exe opcuacore opcuaserver) \ No newline at end of file +target_link_libraries(smart_grid.exe PUBLIC opcuacore opcuaserver) diff --git a/src/apps/smart_grid/SmartOpcServer.cpp b/src/apps/smart_grid/SmartOpcServer.cpp index 9283130a6705f2befee97bfed211e01ca8a4eca2..199e9b2be406d98f861ac8c25899c0668d3707ca 100644 --- a/src/apps/smart_grid/SmartOpcServer.cpp +++ b/src/apps/smart_grid/SmartOpcServer.cpp @@ -4,6 +4,7 @@ using namespace OpcUa; +const char* k_opc_server_url = "opc.tcp://localhost:4840/opcua/smart-grid-model"; class SubClientTime : public SubscriptionHandler { diff --git a/src/apps/smart_grid/SmartOpcServer.hpp b/src/apps/smart_grid/SmartOpcServer.hpp index 2ad423112d011bf4beb85253f7aed28f611d5ac9..a0447a7009010a49bf94b225accbb78aa07de926 100644 --- a/src/apps/smart_grid/SmartOpcServer.hpp +++ b/src/apps/smart_grid/SmartOpcServer.hpp @@ -12,7 +12,6 @@ #include "SmgStateMachine.hpp" -const char* k_opc_server_url = "opc.tcp://localhost:4840/opcua/smart-grid-model"; class SmartOpcServer { diff --git a/src/apps/smart_grid/smg_server.cpp b/src/apps/smart_grid/smg_server.cpp index 34f0daf75edf4b96ca3dc96c5b234a6787d8e39b..8b8471ac39bd4cde0ce5d4004133404392d0fe3b 100644 --- a/src/apps/smart_grid/smg_server.cpp +++ b/src/apps/smart_grid/smg_server.cpp @@ -1,7 +1,6 @@ /// @file main.cpp /// #include <thread> -#include "spdlog/spdlog.h" #include "i2c/Node.hpp" #include "HardwareControl.hpp" @@ -11,23 +10,24 @@ #include "SmartGridModel.hpp" #include "SmgStateMachine.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]); - } + // spdlog::debug("User arguments:"); + // for (int i = 0; i < argc; ++i) + // { + // spdlog::debug("[{}] {}", i, argv[i]); + // } } int main(int argc, char **argv) { - spdlog::set_level(spdlog::level::info); - spdlog::info("Starting - Smart Grid Modell"); - log_args(argc, argv); + // spdlog::set_level(spdlog::level::info); + // spdlog::info("Starting - Smart Grid Modell"); + // log_args(argc, argv); uint8_t slave_address{0x14}; i2c::Node i2c_channel{slave_address}; @@ -37,15 +37,12 @@ int main(int argc, char **argv) } HardwareControl hardware{i2c_channel}; - SmartGridModel model{hardware}; - SmgStateMachine stateMachine{model}; - - // auto log = std::make_shared<StateLogger>(); - // model.attach(log); + // SmartGridModel model{hardware}; + // SmgStateMachine stateMachine{model}; - // run state machine - stateMachine.run(); + // SmartOpcServer server{stateMachine}; + // server.run_server(); - spdlog::info("End"); + // spdlog::info("End"); return 0; } diff --git a/src/i2c/Node.cpp b/src/i2c/Node.cpp index 3ee42ead9463192a95deedfb8d0376213771fc57..c50c60f8d785a4aeb0a6981e725c83275b1ccd47 100644 --- a/src/i2c/Node.cpp +++ b/src/i2c/Node.cpp @@ -5,7 +5,7 @@ #include <linux/i2c-dev.h> #include <unistd.h> -#include <spdlog/spdlog.h> +// #include <spdlog/spdlog.h> using namespace i2c; @@ -24,13 +24,13 @@ bool Node::open_device(const char *i2c_device_name) auto fd = open(i2c_device_name, O_RDWR); if (fd < 0) { - spdlog::error("Failed to open device {}", i2c_device_name); + // spdlog::error("Failed to open device {}", i2c_device_name); return false; } auto success_selecting_device = ioctl(fd, I2C_SLAVE, m_address); if (success_selecting_device < 0) { - spdlog::error("Failed to select i2c node {}", m_address); + // spdlog::error("Failed to select i2c node {}", m_address); return false; } m_device = fd; @@ -42,7 +42,7 @@ bool Node::send(uint8_t *data, ssize_t size) ssize_t bytes_written = write(m_device, data, size); if (bytes_written != size) { - spdlog::error("Error while writing bytes. Written {} bytes instead of {}!", bytes_written, size); + // spdlog::error("Error while writing bytes. Written {} bytes instead of {}!", bytes_written, size); return false; } return true; @@ -90,7 +90,7 @@ int Node::read16(uint8_t reg_addr) if (success != 0) { // error - spdlog::error("Error while reading data."); + // spdlog::error("Error while reading data."); return -1; } else @@ -98,7 +98,7 @@ int Node::read16(uint8_t reg_addr) int answer{0}; answer |= static_cast<int>(data.block[0] << 8); // MSB answer |= static_cast<int>(data.block[1] << 0); // LSB - spdlog::debug("Received data: {} {} converted to {}.", data.block[0], data.block[1], answer); + // spdlog::debug("Received data: {} {} converted to {}.", data.block[0], data.block[1], answer); return answer; } } \ No newline at end of file diff --git a/src/smart_grid/SmartGridModel.cpp b/src/smart_grid/SmartGridModel.cpp index 18f1295b7632bcd2930f3a4d6a88a1f9eb906891..cae77c1202b58c97e990c7705c137d1f2e813154 100644 --- a/src/smart_grid/SmartGridModel.cpp +++ b/src/smart_grid/SmartGridModel.cpp @@ -2,7 +2,7 @@ /// #include "SmartGridModel.hpp" -#include "spdlog/spdlog.h" +// #include "spdlog/spdlog.h" SmartGridModel::SmartGridModel(HardwareControl &modell) : m_modell(modell) @@ -101,10 +101,10 @@ void SmartGridModel::update_sun() void SmartGridModel::print_states() { - spdlog::debug("Time <{}> Sun <{}> Wind<{}>", m_time, m_sun, m_wind); - spdlog::debug("Power Conv <{}> Solar <{}> Wind<{}>", m_production.conventional, m_production.renewable.solar, m_production.renewable.wind); - spdlog::debug("Usage Village<{}> Industry<{}>", m_usage.village, m_usage.industry); - spdlog::debug("excess_power<{}>", calc_excess_power()); + // spdlog::debug("Time <{}> Sun <{}> Wind<{}>", m_time, m_sun, m_wind); + // spdlog::debug("Power Conv <{}> Solar <{}> Wind<{}>", m_production.conventional, m_production.renewable.solar, m_production.renewable.wind); + // spdlog::debug("Usage Village<{}> Industry<{}>", m_usage.village, m_usage.industry); + // spdlog::debug("excess_power<{}>", calc_excess_power()); } diff --git a/src/smart_grid/SmartGridModel.hpp b/src/smart_grid/SmartGridModel.hpp index ab3c57ae0f5d550a26ca10bd5a071e956a35f33c..cfa3179778480dfc6e6c90ece57a370bc02a6186 100644 --- a/src/smart_grid/SmartGridModel.hpp +++ b/src/smart_grid/SmartGridModel.hpp @@ -8,7 +8,6 @@ #include <ctime> #include "HardwareControl.hpp" - #include "ObserverPattern.hpp" struct MaxPower {