@@ -26,15 +26,17 @@ std::vector<uint8_t> Connection::sendRequest(const MB::ModbusRequest &req) {
26
26
std::vector<uint8_t > rawReq;
27
27
rawReq.reserve (6 );
28
28
29
- rawReq.push_back (static_cast <const uint8_t &&>(reinterpret_cast <const uint8_t *>(&_messageID)[1 ]));
29
+ rawReq.push_back (
30
+ static_cast <const uint8_t &&>(reinterpret_cast <const uint8_t *>(&_messageID)[1 ]));
30
31
rawReq.push_back (static_cast <uint8_t >(_messageID));
31
32
rawReq.push_back (0x00 );
32
33
rawReq.push_back (0x00 );
33
34
34
35
std::vector<uint8_t > dat = req.toRaw ();
35
36
36
37
uint32_t size = dat.size ();
37
- rawReq.push_back (static_cast <const uint16_t &&>(reinterpret_cast <const uint16_t *>(&size)[1 ]));
38
+ rawReq.push_back (
39
+ static_cast <const uint16_t &&>(reinterpret_cast <const uint16_t *>(&size)[1 ]));
38
40
rawReq.push_back (static_cast <uint16_t >(size));
39
41
40
42
rawReq.insert (rawReq.end (), dat.begin (), dat.end ());
@@ -48,15 +50,17 @@ std::vector<uint8_t> Connection::sendResponse(const MB::ModbusResponse &res) {
48
50
std::vector<uint8_t > rawReq;
49
51
rawReq.reserve (6 );
50
52
51
- rawReq.push_back (static_cast <const uint8_t &&>(reinterpret_cast <const uint8_t *>(&_messageID)[1 ]));
53
+ rawReq.push_back (
54
+ static_cast <const uint8_t &&>(reinterpret_cast <const uint8_t *>(&_messageID)[1 ]));
52
55
rawReq.push_back (static_cast <uint8_t >(_messageID));
53
56
rawReq.push_back (0x00 );
54
57
rawReq.push_back (0x00 );
55
58
56
59
std::vector<uint8_t > dat = res.toRaw ();
57
60
58
61
uint32_t size = dat.size ();
59
- rawReq.push_back (static_cast <const uint16_t &&>(reinterpret_cast <const uint16_t *>(&size)[1 ]));
62
+ rawReq.push_back (
63
+ static_cast <const uint16_t &&>(reinterpret_cast <const uint16_t *>(&size)[1 ]));
60
64
rawReq.push_back (static_cast <uint16_t >(size));
61
65
62
66
rawReq.insert (rawReq.end (), dat.begin (), dat.end ());
@@ -70,15 +74,17 @@ std::vector<uint8_t> Connection::sendException(const MB::ModbusException &ex) {
70
74
std::vector<uint8_t > rawReq;
71
75
rawReq.reserve (6 );
72
76
73
- rawReq.push_back (static_cast <const uint8_t &&>(reinterpret_cast <const uint8_t *>(&_messageID)[1 ]));
77
+ rawReq.push_back (
78
+ static_cast <const uint8_t &&>(reinterpret_cast <const uint8_t *>(&_messageID)[1 ]));
74
79
rawReq.push_back (static_cast <uint8_t >(_messageID));
75
80
rawReq.push_back (0x00 );
76
81
rawReq.push_back (0x00 );
77
82
78
83
std::vector<uint8_t > dat = ex.toRaw ();
79
84
80
85
uint32_t size = dat.size ();
81
- rawReq.push_back (static_cast <const uint16_t &&>(reinterpret_cast <const uint16_t *>(&size)[1 ]));
86
+ rawReq.push_back (
87
+ static_cast <const uint16_t &&>(reinterpret_cast <const uint16_t *>(&size)[1 ]));
82
88
rawReq.push_back (static_cast <uint16_t >(size));
83
89
84
90
rawReq.insert (rawReq.end (), dat.begin (), dat.end ());
@@ -90,8 +96,8 @@ std::vector<uint8_t> Connection::sendException(const MB::ModbusException &ex) {
90
96
91
97
std::vector<uint8_t > Connection::awaitRawMessage () {
92
98
pollfd pfd;
93
- pfd.fd = this ->_sockfd ;
94
- pfd.events = POLLIN;
99
+ pfd.fd = this ->_sockfd ;
100
+ pfd.events = POLLIN;
95
101
pfd.revents = POLLIN;
96
102
if (::poll (&pfd, 1 , 60 * 1000 /* 1 minute means the connection has died */ ) <= 0 ) {
97
103
throw MB::ModbusException (MB::utils::ConnectionClosed);
@@ -115,8 +121,8 @@ std::vector<uint8_t> Connection::awaitRawMessage() {
115
121
116
122
MB::ModbusRequest Connection::awaitRequest () {
117
123
pollfd pfd;
118
- pfd.fd = this ->_sockfd ;
119
- pfd.events = POLLIN;
124
+ pfd.fd = this ->_sockfd ;
125
+ pfd.events = POLLIN;
120
126
pfd.revents = POLLIN;
121
127
if (::poll (&pfd, 1 , 60 * 1000 /* 1 minute means the connection has died */ ) <= 0 ) {
122
128
throw MB::ModbusException (MB::utils::Timeout);
@@ -146,8 +152,8 @@ MB::ModbusRequest Connection::awaitRequest() {
146
152
147
153
MB::ModbusResponse Connection::awaitResponse () {
148
154
pollfd pfd;
149
- pfd.fd = this ->_sockfd ;
150
- pfd.events = POLLIN;
155
+ pfd.fd = this ->_sockfd ;
156
+ pfd.events = POLLIN;
151
157
pfd.revents = POLLIN;
152
158
153
159
if (::poll (&pfd, 1 , this ->_timeout ) <= 0 ) {
@@ -195,8 +201,8 @@ Connection Connection::with(std::string addr, int port) {
195
201
196
202
sockaddr_in server;
197
203
server.sin_family = AF_INET;
198
- server.sin_port = ::htons (port);
199
- server.sin_addr = { inet_addr (addr.c_str ()) };
204
+ server.sin_port = ::htons (port);
205
+ server.sin_addr = {inet_addr (addr.c_str ())};
200
206
201
207
if (::connect (sock, reinterpret_cast <struct sockaddr *>(&server), sizeof (server)) < 0 )
202
208
throw std::runtime_error (" Cannot connect, errno = " + std::to_string (errno));
0 commit comments