From 304cc4bc73e66c017b7661d4145b64f7566b106d Mon Sep 17 00:00:00 2001 From: Armin Co <armin.co@hs-bochum.de> Date: Tue, 6 Oct 2020 08:58:52 +0200 Subject: [PATCH] Fixing libs --- CMakeLists.txt | 48 +++++++++++++------------- src/apps/smart_grid/SmartOpcServer.cpp | 1 + src/apps/smart_grid/SmartOpcServer.hpp | 1 - src/apps/smart_grid/smg_server.cpp | 31 ++++++++--------- src/i2c/Node.cpp | 12 +++---- src/smart_grid/SmartGridModel.cpp | 10 +++--- src/smart_grid/SmartGridModel.hpp | 1 - 7 files changed, 50 insertions(+), 54 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index e46d6c9..1a6a476 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 9283130..199e9b2 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 2ad4231..a0447a7 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 34f0daf..8b8471a 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 3ee42ea..c50c60f 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 18f1295..cae77c1 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 ab3c57a..cfa3179 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 { -- GitLab