Commit a576ff0b282c6881933be2d63c26809e2ffebc0b

Authored by Peter M. Groen
1 parent f0c30279

Add TCP connection

src/modbustcp.cpp
... ... @@ -9,6 +9,7 @@
9 9 using namespace osdev::components::modbus;
10 10  
11 11 ModbusTcp::ModbusTcp(const ConnectionConfig &con_config)
  12 +
12 13 {
13 14  
14 15 }
... ...
src/modbustcp.h
... ... @@ -8,10 +8,19 @@
8 8  
9 9 #include "imodbusport.h"
10 10  
  11 +#include <unistd.h>
  12 +#include <sys/socket.h>
  13 +#include <netinet/in.h>
  14 +#include <arpa/inet.h>
  15 +
11 16 namespace osdev {
12 17 namespace components {
13 18 namespace modbus {
14 19  
  20 +using X_SOCKET = int;
  21 +using SOCKADDR = struct sockaddr;
  22 +using SOCKADDR_IN = struct sockaddr_in;
  23 +
15 24 class ModbusTcp : public IModbusPort
16 25 {
17 26 public:
... ... @@ -24,6 +33,13 @@ public:
24 33 virtual bool Close() const override;
25 34 virtual int Read(uint8_t *buffer) const override;
26 35 virtual int Write(uint8_t *buffer, size_t length) const override;
  36 +
  37 +private:
  38 + uint16_t m_port {502};
  39 + std::string m_host {};
  40 + X_SOCKET m_socket {-1};
  41 + SOCKADDR_IN m_server {};
  42 +
27 43 };
28 44  
29 45 } /* End namespace modbus */
... ...