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

Fixing libs

parent 96ea0f2d
Branches
No related tags found
No related merge requests found
......@@ -31,26 +31,9 @@ target_link_libraries(sample_client spdlog)
include_directories(src/i2c)
include_directories(src/smart_grid)
add_executable(smart_grid.exe
src/apps/smart_grid/smg_server.cpp
src/apps/smart_grid/SmgStateMachine.cpp
src/apps/smart_grid/SmartOpcServer.cpp
src/smart_grid/SmartGridModel.cpp
src/i2c/Node.cpp
src/com/Socket.cpp
src/com/Protocol.cpp
src/smart_grid/HardwareControl.cpp
)
target_link_libraries(smart_grid.exe 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()
......@@ -68,3 +51,20 @@ 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
src/apps/smart_grid/SmartOpcServer.cpp
src/smart_grid/SmartGridModel.cpp
src/i2c/Node.cpp
src/com/Socket.cpp
src/com/Protocol.cpp
src/smart_grid/HardwareControl.cpp
)
# 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 PUBLIC opcuacore opcuaserver)
......@@ -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
{
......
......@@ -12,7 +12,6 @@
#include "SmgStateMachine.hpp"
const char* k_opc_server_url = "opc.tcp://localhost:4840/opcua/smart-grid-model";
class SmartOpcServer
{
......
/// @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;
}
......@@ -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
......@@ -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());
}
......
......@@ -8,7 +8,6 @@
#include <ctime>
#include "HardwareControl.hpp"
#include "ObserverPattern.hpp"
struct MaxPower
{
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment