Skip to content

Commit

Permalink
🎨 Committing clang-format changes
Browse files Browse the repository at this point in the history
  • Loading branch information
omarhogni committed Mar 27, 2024
1 parent c0913a6 commit b922cba
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 16 deletions.
15 changes: 8 additions & 7 deletions include/modbus/client.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -222,13 +222,14 @@ class client {
*/
template <typename completion_token>
auto read_write_multiple_registers(std::uint8_t unit,
std::uint16_t read_address,
std::uint16_t read_count,
std::uint16_t write_address,
std::vector<std::uint16_t> values,
completion_token&& token) {
return send_message<completion_token>(unit, request::read_write_multiple_registers{ read_address, read_count, write_address, values },
std::forward<decltype(token)>(token));
std::uint16_t read_address,
std::uint16_t read_count,
std::uint16_t write_address,
std::vector<std::uint16_t> values,
completion_token&& token) {
return send_message<completion_token>(
unit, request::read_write_multiple_registers{ read_address, read_count, write_address, values },
std::forward<decltype(token)>(token));
}

protected:
Expand Down
4 changes: 2 additions & 2 deletions include/modbus/default_handler.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,8 @@ struct default_handler {
}

modbus::response::read_write_multiple_registers handle(uint8_t,
const modbus::request::read_write_multiple_registers& req,
modbus::errc_t&) {
const modbus::request::read_write_multiple_registers& req,
modbus::errc_t&) {
modbus::response::read_write_multiple_registers resp{};
auto iit = req.values.begin();
auto oit = registers.begin() + req.write_address;
Expand Down
3 changes: 2 additions & 1 deletion include/modbus/server.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,8 @@ auto handle_connection(tcp::socket client, auto&& handler) -> awaitable<void> {
std::array<asio::const_buffer, 2> buffs{ asio::buffer(header_bytes), asio::buffer(resp.value()) };
co_await async_write(state->client_, buffs, use_awaitable);
} else {
std::cerr << "error client: " << state->client_.remote_endpoint() << " error " << modbus_error(resp.error()).message() << '\n';
std::cerr << "error client: " << state->client_.remote_endpoint() << " error " << modbus_error(resp.error()).message()
<< '\n';
co_await async_write(state->client_, asio::buffer(build_error_buffer(header, 0, resp.error()), count), use_awaitable);
}
}
Expand Down
9 changes: 5 additions & 4 deletions tests/deserialization.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -235,10 +235,11 @@ int main() {

"deserialize request read_write_multiple_registers"_test = []() {
// Request captured from M580 PLC
std::array<std::uint8_t, 21> data = {0x04 ,0x8c ,0x00, 0x00, 0x00, 0x0d, 0xff, 0x17, 0x00, 0x00, 0x00, 0x27, 0x00, 0x00, 0x00, 0x01, 0x02, 0x00, 0x00 };
std::array<std::uint8_t, 21> data = { 0x04, 0x8c, 0x00, 0x00, 0x00, 0x0d, 0xff, 0x17, 0x00, 0x00,
0x00, 0x27, 0x00, 0x00, 0x00, 0x01, 0x02, 0x00, 0x00 };

auto expected_request =
deserialize_request(std::span(data).subspan(modbus::tcp_mbap::size), modbus::function_e::read_write_multiple_registers);
auto expected_request = deserialize_request(std::span(data).subspan(modbus::tcp_mbap::size),
modbus::function_e::read_write_multiple_registers);
expect(expected_request.has_value());
expect(holds_alternative<modbus::request::read_write_multiple_registers>(expected_request.value()));
auto request = std::get<modbus::request::read_write_multiple_registers>(expected_request.value());
Expand Down Expand Up @@ -407,7 +408,7 @@ int main() {
};

"deserialize response read_write_multiple_registers"_test = []() {
//TODO: Having trouble creating a known good byte array for this test.
// TODO: Having trouble creating a known good byte array for this test.
};

return 0;
Expand Down
2 changes: 1 addition & 1 deletion tests/integration.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ int main() {
co_await client.connect("localhost", std::to_string(port), asio::as_tuple(asio::use_awaitable));
expect(!connect_error);
handler->registers[0] = 1337;
auto res = co_await client.read_write_multiple_registers(0, 0, 1, 1, {1338}, asio::use_awaitable);
auto res = co_await client.read_write_multiple_registers(0, 0, 1, 1, { 1338 }, asio::use_awaitable);
expect(res.has_value());
expect(res.value().values.size() == 1);
expect(res.value().values[0] == 1337) << res.value().values[0];
Expand Down
2 changes: 1 addition & 1 deletion tests/serialization.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -388,7 +388,7 @@ int main() {
"serialize request read_write_multiple_registers"_test = []() {
using req_t = modbus::response::read_write_multiple_registers;
req_t response{};
response.values = { 1337, 10, 15, 2};
response.values = { 1337, 10, 15, 2 };
auto data = response.serialize();
req_t ex_response{};
auto error = ex_response.deserialize(data);
Expand Down

0 comments on commit b922cba

Please sign in to comment.