-
Notifications
You must be signed in to change notification settings - Fork 13
/
server.cpp
70 lines (56 loc) · 1.86 KB
/
server.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#include <chrono>
#include <iomanip>
#include <iostream>
#include <thread>
#include <utility>
#include <arpa/inet.h>
#include <netinet/in.h>
#include <sys/select.h>
#include <sys/socket.h>
#include <spdlog/spdlog.h>
#include <modbuscpp/modbus.hpp>
class server_logger : public modbus::logger {
public:
explicit server_logger(bool debug = false) : modbus::logger(debug) {}
virtual ~server_logger() override {}
protected:
inline virtual void error_impl(
const std::string& message) const noexcept override {
spdlog::error("{}", message);
}
inline virtual void debug_impl(
const std::string& message) const noexcept override {
if (debug_) {
spdlog::debug("{}", message);
}
}
inline virtual void info_impl(
const std::string& message) const noexcept override {
spdlog::info("{}", message);
}
};
int main([[maybe_unused]] int argc, [[maybe_unused]] const char** argv) {
spdlog::set_level(spdlog::level::debug);
modbus::logger::create<server_logger>(true);
auto&& data_table = modbus::table::create(
/*modbus::table::initializer_t{*/
// modbus::block::bits::initializer_t{modbus::address_t{0x00}, 0xFFFF,
// true}, modbus::block::bits::initializer_t{modbus::address_t{0x00},
// 0xFFFF, true},
// modbus::block::registers::initializer_t{modbus::address_t{0x00},
// 0xFFFF, 15},
/*modbus::block::registers::initializer_t{}}*/
);
auto&& server = modbus::server::create(std::move(data_table));
server->bind_connect(
[]([[maybe_unused]] auto& session_ptr, [[maybe_unused]] auto& table) {
// session_ptr->start_timer(1, std::chrono::seconds(1), [&table]() {
/*LOG_INFO("Input registers addr 0x00: {:#04x}",*/
/*table.input_registers().get(modbus::address_t{0x00}));*/
//});
});
server->run();
while (std::getchar() != '\n') {
}
return 0;
}