Skip to content

Commit d71daa4

Browse files
committed
Resolved bug in json parsing
1 parent a70ec26 commit d71daa4

File tree

4 files changed

+18
-19
lines changed

4 files changed

+18
-19
lines changed

.github/workflows/docker.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ on:
44
push:
55
branches:
66
- main
7-
- develop
87
pull_request:
98
paths:
109
- .docker/**

libwaterlinked/examples/send_command.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,10 +42,10 @@ auto main() -> int
4242
auto config = response.result.get<waterlinked::Configuration>();
4343

4444
std::cout << "Current configuration:\n";
45-
std::cout << " Speed of sound: " << config.speed_of_sound << " m/s\n";
45+
std::cout << " Speed of sound: " << config.speed_of_sound << "\n";
4646
std::cout << " Acoustic enabled: " << config.acoustic_enabled << "\n";
4747
std::cout << " Dark mode enabled: " << config.dark_mode_enabled << "\n";
48-
std::cout << " Mounting rotation offset: " << config.mounting_rotation_offset << " degrees\n";
48+
std::cout << " Mounting rotation offset: " << config.mounting_rotation_offset << "\n";
4949
std::cout << " Range mode: " << config.range_mode << "\n";
5050
std::cout << " Periodic cycling enabled: " << config.periodic_cycling_enabled << "\n";
5151

libwaterlinked/examples/subscribe_to_reports.cpp

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -33,25 +33,25 @@ auto main() -> int
3333
// Register a callback to receive velocity reports
3434
client.register_callback([](const waterlinked::VelocityReport & report) {
3535
std::cout << "Received velocity report:\n";
36-
std::cout << " Time: " << report.time.count() << "ms\n";
37-
std::cout << " Velocity: (" << report.vx << ", " << report.vy << ", " << report.vz << ") m/s\n";
38-
std::cout << " Figure of merit: " << report.fom << " m/s\n";
39-
std::cout << " Altitude: " << report.altitude << " m\n";
36+
std::cout << " Time: " << report.time.count() << "\n";
37+
std::cout << " Velocity: (" << report.vx << ", " << report.vy << ", " << report.vz << ")\n";
38+
std::cout << " Figure of merit: " << report.fom << "\n";
39+
std::cout << " Altitude: " << report.altitude << "\n";
4040
std::cout << " Velocity valid: " << report.velocity_valid << "\n";
4141
std::cout << " Status: " << static_cast<int>(report.status) << "\n";
42-
std::cout << " Time of validity: " << report.time_of_validity.time_since_epoch().count() << "us\n";
43-
std::cout << " Time of transmission: " << report.time_of_transmission.time_since_epoch().count() << "us\n";
42+
std::cout << " Time of validity: " << report.time_of_validity.time_since_epoch().count() << "\n";
43+
std::cout << " Time of transmission: " << report.time_of_transmission.time_since_epoch().count() << "\n";
4444
});
4545

4646
// Register a callback to receive dead reckoning reports
4747
client.register_callback([](const waterlinked::DeadReckoningReport & report) {
4848
std::cout << "Received dead reckoning report:\n";
49-
std::cout << " Timestamp: " << report.ts.time_since_epoch().count() << "us\n";
50-
std::cout << " Position: (" << report.x << ", " << report.y << ", " << report.z << ") m\n";
51-
std::cout << " Standard deviation: " << report.std << " m\n";
52-
std::cout << " Roll: " << report.roll << " degrees\n";
53-
std::cout << " Pitch: " << report.pitch << " degrees\n";
54-
std::cout << " Yaw: " << report.yaw << " degrees\n";
49+
std::cout << " Timestamp: " << report.ts.time_since_epoch().count() << "\n";
50+
std::cout << " Position: (" << report.x << ", " << report.y << ", " << report.z << ") \n";
51+
std::cout << " Standard deviation: " << report.std << "\n";
52+
std::cout << " Roll: " << report.roll << "\n";
53+
std::cout << " Pitch: " << report.pitch << "\n";
54+
std::cout << " Yaw: " << report.yaw << "\n";
5555
});
5656

5757
// Let the driver run indefinitely

libwaterlinked/src/client.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ auto parse_bytes(const std::deque<std::uint8_t> & buffer) -> std::vector<nlohman
7676
json_objects.push_back(nlohmann::json::parse(data));
7777
}
7878
catch (const std::exception & e) {
79-
std::cout << "An error occurred while attempting to parse the DVL message: " << e.what() << "\n";
79+
std::cout << "An error occurred while attempting to parse the DVL message. " << e.what() << "\n";
8080
}
8181
}
8282

@@ -299,9 +299,9 @@ auto WaterLinkedClient::process_json_object(const nlohmann::json & json_object)
299299
auto WaterLinkedClient::poll_connection() -> void
300300
{
301301
// Maintain a queue to store incoming data
302-
const std::size_t max_bytes_to_read = 1024;
303-
std::deque<std::uint8_t> buffer(max_bytes_to_read);
304-
std::size_t n_bytes_to_read = buffer.size();
302+
const std::size_t max_bytes_to_read = 2048; // Reports can be quite large, so create a large buffer
303+
std::deque<std::uint8_t> buffer;
304+
std::size_t n_bytes_to_read = max_bytes_to_read;
305305

306306
while (running_.load()) {
307307
if (read_from_socket(socket_, buffer, n_bytes_to_read) < 0) {

0 commit comments

Comments
 (0)