Skip to content

Commit 665c571

Browse files
committed
fix format, remove constexpr, and add coverage
1 parent 2a0d752 commit 665c571

36 files changed

+359
-387
lines changed

CMakeLists.txt

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -115,16 +115,12 @@ target_compile_options(modbuscpp PUBLIC "$<$<BOOL:${MSVC}>:/permissive->")
115115
target_link_libraries(modbuscpp PRIVATE Threads::Threads ${Boost_LIBRARIES} fmt struc asio2)
116116

117117
target_include_directories(
118-
modbuscpp
119-
PUBLIC $<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/include>
120-
$<INSTALL_INTERFACE:include/${PROJECT_NAME}-${PROJECT_VERSION}>
118+
modbuscpp PUBLIC $<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/include>
119+
$<INSTALL_INTERFACE:include/${PROJECT_NAME}-${PROJECT_VERSION}>
121120
)
122121

123-
if (Boost_FOUND)
124-
target_include_directories(
125-
modbuscpp
126-
PUBLIC $<BUILD_INTERFACE:${Boost_INCLUDE_DIR}>
127-
)
122+
if(Boost_FOUND)
123+
target_include_directories(modbuscpp PUBLIC $<BUILD_INTERFACE:${Boost_INCLUDE_DIR}>)
128124
endif()
129125

130126
# ---- Create an installable target ----

cmake/Asio2.cmake

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,13 @@ CPMAddPackage(
1010
NAME asio2
1111
GITHUB_REPOSITORY zhllxt/asio2
1212
VERSION 1
13-
GIT_TAG ce6ac7f6ba2a931a19b9abb7627d12cfaeed8ab1)
13+
GIT_TAG ce6ac7f6ba2a931a19b9abb7627d12cfaeed8ab1
14+
)
1415

1516
if(asio2_ADDED)
1617
add_library(asio2 INTERFACE)
1718

18-
target_include_directories(asio2
19-
INTERFACE
20-
$<BUILD_INTERFACE:${Boost_INCLUDE_DIR}>
21-
$<BUILD_INTERFACE:${asio2_SOURCE_DIR}>)
19+
target_include_directories(
20+
asio2 INTERFACE $<BUILD_INTERFACE:${Boost_INCLUDE_DIR}> $<BUILD_INTERFACE:${asio2_SOURCE_DIR}>
21+
)
2222
endif()

cmake/Boost.cmake

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,9 @@ endif()
55

66
option(BOOST_STATIC "Boost static library" OFF)
77

8-
set(Boost_USE_STATIC_LIBS ${BOOST_STATIC}) # only find static libs
9-
set(Boost_USE_DEBUG_LIBS OFF) # ignore debug libs and
10-
set(Boost_USE_RELEASE_LIBS ON) # only find release libs
11-
set(Boost_USE_MULTITHREADED ON)
12-
set(Boost_USE_STATIC_RUNTIME OFF)
13-
find_package(Boost 1.70.0 REQUIRED COMPONENTS
14-
system)
8+
set(Boost_USE_STATIC_LIBS ${BOOST_STATIC}) # only find static libs
9+
set(Boost_USE_DEBUG_LIBS OFF) # ignore debug libs and
10+
set(Boost_USE_RELEASE_LIBS ON) # only find release libs
11+
set(Boost_USE_MULTITHREADED ON)
12+
set(Boost_USE_STATIC_RUNTIME OFF)
13+
find_package(Boost 1.70.0 REQUIRED COMPONENTS system)

codecov.yaml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
ignore:
22
- "test"
3+
- "**/_deps/**"
4+
- "**/usr/**"
5+
- "*.yaml"
36

47
comment:
5-
require_changes: true
8+
require_changes: true

include/modbuscpp/details/adu.hpp

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ namespace internal {
3737
* --- Rest of data... (N byte)
3838
*/
3939
class adu {
40-
public:
40+
public:
4141
/**
4242
* Initializer
4343
*/
@@ -114,7 +114,7 @@ class adu {
114114
explicit adu(constants::function_code function,
115115
const header_t& m_header) noexcept;
116116

117-
public:
117+
public:
118118
/**
119119
* Encode packet
120120
*
@@ -136,7 +136,7 @@ class adu {
136136
*/
137137
virtual void decode(const packet_t& packet) = 0;
138138

139-
public:
139+
public:
140140
/** Getter */
141141
/**
142142
* Get function code
@@ -279,7 +279,7 @@ class adu {
279279
return obj.dump(os);
280280
}
281281

282-
protected:
282+
protected:
283283
/**
284284
* Decode packet header
285285
*
@@ -309,13 +309,13 @@ class adu {
309309
return header_length + 1 + data_length;
310310
}
311311

312-
public:
312+
public:
313313
/**
314314
* Header length
315315
*/
316316
static constexpr typename packet_t::size_type header_length = 7;
317317

318-
protected:
318+
protected:
319319
/**
320320
* Protocol ID
321321
*/
@@ -328,19 +328,19 @@ class adu {
328328
/**
329329
* Max length
330330
*/
331-
static constexpr typename packet_t::size_type max_length =
332-
constants::max_adu_length;
331+
static constexpr typename packet_t::size_type max_length
332+
= constants::max_adu_length;
333333
/**
334334
* Max PDU length
335335
*/
336-
static constexpr typename packet_t::size_type max_pdu_size =
337-
max_length - header_length;
336+
static constexpr typename packet_t::size_type max_pdu_size
337+
= max_length - header_length;
338338
/**
339339
* Header struct with function format
340340
*/
341341
static constexpr std::string_view header_func_format = "HHHBB";
342342

343-
protected:
343+
protected:
344344
/**
345345
* Function
346346
*/

include/modbuscpp/details/asio2.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,4 @@
77
#include <asio2/base/timer.hpp>
88
#include <asio2/tcp/tcp_server.hpp>
99

10-
#endif // LIB_MODBUS_ASIO2_HPP_
10+
#endif // LIB_MODBUS_ASIO2_HPP_

include/modbuscpp/details/bit-read.hpp

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -35,18 +35,18 @@ namespace request {
3535
* [ Starting Address (2 bytes) ]
3636
* [ Quantity of bits (2 bytes) ]
3737
*/
38-
template <constants::function_code function_code>
39-
class base_read_bits : public internal::request {
40-
public:
38+
template <constants::function_code function_code> class base_read_bits
39+
: public internal::request {
40+
public:
4141
/**
4242
* request::base_read_bits constructor
4343
*
4444
* @param address address requested
4545
* @param count count requested
4646
*/
47-
explicit base_read_bits(
48-
const address_t& address = address_t{},
49-
const read_num_bits_t& count = read_num_bits_t{}) noexcept;
47+
explicit base_read_bits(const address_t& address = address_t{},
48+
const read_num_bits_t& count
49+
= read_num_bits_t{}) noexcept;
5050

5151
/**
5252
* Encode read bits packet from given data
@@ -109,7 +109,7 @@ class base_read_bits : public internal::request {
109109
*/
110110
virtual std::ostream& dump(std::ostream& os) const override;
111111

112-
private:
112+
private:
113113
/**
114114
* Data length (4 bytes)
115115
*/
@@ -129,8 +129,8 @@ class base_read_bits : public internal::request {
129129
};
130130

131131
using read_coils = base_read_bits<constants::function_code::read_coils>;
132-
using read_discrete_inputs =
133-
base_read_bits<constants::function_code::read_discrete_inputs>;
132+
using read_discrete_inputs
133+
= base_read_bits<constants::function_code::read_discrete_inputs>;
134134
} // namespace request
135135

136136
namespace response {
@@ -148,9 +148,9 @@ namespace response {
148148
* [ Byte count = N (1 byte) ]
149149
* [ Bits (n = N or N + 1 bytes) ]
150150
*/
151-
template <constants::function_code function_code>
152-
class base_read_bits : public internal::response {
153-
public:
151+
template <constants::function_code function_code> class base_read_bits
152+
: public internal::response {
153+
public:
154154
/**
155155
* Create std::unique_ptr of response::read_bits
156156
*
@@ -202,7 +202,7 @@ class base_read_bits : public internal::response {
202202
*/
203203
inline const block::bits::container_type& bits() const { return bits_; }
204204

205-
private:
205+
private:
206206
/**
207207
* Request pointer
208208
*/
@@ -222,9 +222,9 @@ class base_read_bits : public internal::response {
222222
};
223223

224224
using read_coils = base_read_bits<constants::function_code::read_coils>;
225-
using read_discrete_inputs =
226-
base_read_bits<constants::function_code::read_discrete_inputs>;
225+
using read_discrete_inputs
226+
= base_read_bits<constants::function_code::read_discrete_inputs>;
227227
} // namespace response
228-
}
228+
} // namespace modbus
229229

230230
#endif // LIB_MODBUS_MODBUS_BIT_READ_HPP_

include/modbuscpp/details/bit-read.inline.hpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -83,15 +83,15 @@ void base_read_bits<function_code>::decode_passed(const packet_t& packet) {
8383
throw ex::bad_data();
8484
}
8585

86-
packet_t::size_type byte_idx = header_length + 1;
86+
packet_t::size_type byte_idx = header_length + 1;
8787
count_ = static_cast<std::uint16_t>(packet[byte_idx]);
8888

8989
if (count_ != request_->count().get()) {
9090
throw ex::bad_data();
9191
}
9292

93-
block::bits::container_type buffer =
94-
op::unpack_bits(packet.begin() + byte_idx + 1, packet.end());
93+
block::bits::container_type buffer
94+
= op::unpack_bits(packet.begin() + byte_idx + 1, packet.end());
9595

9696
if (buffer.size() != request_->count().get()) {
9797
throw ex::bad_data();

include/modbuscpp/details/bit-write.hpp

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ namespace request {
4747
* [ Output Value (2 bytes) ]
4848
*/
4949
class write_single_coil : public internal::request {
50-
public:
50+
public:
5151
/**
5252
* request::write_single_coil constructor
5353
*
@@ -98,7 +98,7 @@ class write_single_coil : public internal::request {
9898
*/
9999
virtual std::ostream& dump(std::ostream& os) const override;
100100

101-
public:
101+
public:
102102
/**
103103
* Get address
104104
*
@@ -113,7 +113,7 @@ class write_single_coil : public internal::request {
113113
*/
114114
inline value::bits value() const { return value_; }
115115

116-
private:
116+
private:
117117
/**
118118
* Data length (4 bytes)
119119
*/
@@ -149,7 +149,7 @@ class write_single_coil : public internal::request {
149149
* [ Output value (N x 1 bytes) ]
150150
*/
151151
class write_multiple_coils : public internal::request {
152-
public:
152+
public:
153153
/**
154154
* request::write_multiple_coils constructor
155155
*
@@ -210,7 +210,7 @@ class write_multiple_coils : public internal::request {
210210
*/
211211
virtual std::ostream& dump(std::ostream& os) const override;
212212

213-
public:
213+
public:
214214
/**
215215
* Get address
216216
*
@@ -232,7 +232,7 @@ class write_multiple_coils : public internal::request {
232232
*/
233233
inline const block::bits::container_type& values() const { return values_; }
234234

235-
private:
235+
private:
236236
/**
237237
* Get data length
238238
*
@@ -242,7 +242,7 @@ class write_multiple_coils : public internal::request {
242242
*/
243243
inline std::uint16_t data_length() const { return 4 + 1 + byte_count_; }
244244

245-
private:
245+
private:
246246
/**
247247
* Address
248248
*/
@@ -280,7 +280,7 @@ namespace response {
280280
* [ Output Value (2 bytes) ]
281281
*/
282282
class write_single_coil : public internal::response {
283-
public:
283+
public:
284284
/**
285285
* Create std::unique_ptr of response::write_single_coil
286286
*
@@ -320,7 +320,7 @@ class write_single_coil : public internal::response {
320320
*/
321321
virtual std::ostream& dump(std::ostream& os) const override;
322322

323-
private:
323+
private:
324324
/**
325325
* Request pointer
326326
*/
@@ -352,7 +352,7 @@ class write_single_coil : public internal::response {
352352
* [ Quantity of Outputs (2 bytes) ]
353353
*/
354354
class write_multiple_coils : public internal::response {
355-
public:
355+
public:
356356
/**
357357
* Create std::unique_ptr of response::write_multiple_coils
358358
*
@@ -406,7 +406,7 @@ class write_multiple_coils : public internal::response {
406406
*/
407407
inline const write_num_bits_t& count() const { return count_; }
408408

409-
private:
409+
private:
410410
/**
411411
* Request pointer
412412
*/
@@ -428,8 +428,7 @@ class write_multiple_coils : public internal::response {
428428
*/
429429
static constexpr std::string_view format = "HH";
430430
};
431-
}
432-
} // namespace request
433-
434-
#endif // LIB_MODBUS_MODBUS_BIT_WRITE_HPP_
431+
} // namespace response
432+
} // namespace modbus
435433

434+
#endif // LIB_MODBUS_MODBUS_BIT_WRITE_HPP_

0 commit comments

Comments
 (0)