Commit a576ff0b282c6881933be2d63c26809e2ffebc0b
1 parent
f0c30279
Add TCP connection
Showing
2 changed files
with
17 additions
and
0 deletions
src/modbustcp.cpp
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 */ | ... | ... |