4#ifndef WATERLINKEDSONAR_RECEIVER_HPP
5#define WATERLINKEDSONAR_RECEIVER_HPP
14#include <system_error>
61 explicit Receiver(std::unique_ptr<UdpSocket> socket,
123 std::unique_ptr<UdpSocket> socket_;
127 std::vector<std::function<void(
const RangeImageView&)>> range_callbacks_;
128 std::vector<std::function<void(
const BitmapImageView&)>> bitmap_callbacks_;
129 std::vector<std::function<void(
const ImuBatchView&)>> imu_callbacks_;
131 std::vector<std::function<void(
const std::error_code&)>>
132 socket_error_callbacks_;
135 std::atomic<bool> running_{
false};
136 bool started_{
false};
139 std::atomic<std::uint64_t> datagrams_received_{0};
140 std::atomic<std::uint64_t> range_images_{0};
141 std::atomic<std::uint64_t> bitmap_images_{0};
142 std::atomic<std::uint64_t> imu_batches_{0};
143 std::atomic<std::uint64_t> unknown_type_{0};
144 std::atomic<std::uint64_t> decode_errors_{0};
145 std::atomic<std::uint64_t> filtered_source_{0};
146 std::atomic<std::uint32_t> last_sequence_id_{0};
147 std::atomic<std::chrono::steady_clock::time_point::rep> last_datagram_ns_{0};
Owns the receive thread: reads datagrams from the injected socket, decodes them, and dispatches to th...
Definition receiver.hpp:56
void on_socket_error(std::function< void(const std::error_code &)> cb)
Registers a callback for the unrecoverable socket error that ends the receive loop.
Receiver(const Receiver &)=delete
ReceiverStats stats() const
Counter snapshot; callable from any thread.
Receiver & operator=(const Receiver &)=delete
void on_imu_batch(std::function< void(const ImuBatchView &)> cb)
Registers a callback for decoded ImuBatch messages.
~Receiver()
Stops the receive thread if it is running.
void on_range_image(std::function< void(const RangeImageView &)> cb)
Registers a callback for decoded RangeImage messages.
Receiver(std::unique_ptr< UdpSocket > socket, ReceiverOptions options={})
Takes ownership of an open socket; nothing is read until start().
void start()
Starts the receive thread.
void on_decode_error(std::function< void(rip::DecodeStatus)> cb)
Registers a callback for datagrams that fail to decode.
void on_bitmap_image(std::function< void(const BitmapImageView &)> cb)
Registers a callback for decoded BitmapImage messages.
bool running() const
False before start, after stop, and after a socket error ends the receive loop on its own.
void stop()
Stops the receive thread.
Range Image Protocol codec (https://docs.waterlinked.com/sonar-3d/sonar-3d-15-api/).
Definition rip.hpp:56
Views of the decoded RIP messages: range images, bitmap images and IMU batches.
DecodeStatus
Outcome of decoding one datagram.
Definition rip.hpp:17
Range Image Protocol decoder.
8-bit greyscale image, displayable without further processing.
Definition messages.hpp:62
Batch of approximately 100 Hz IMU samples sent while acoustics is enabled.
Definition messages.hpp:80
Per-pixel distance to the strongest reflection.
Definition messages.hpp:29
Datagram filtering applied before decoding.
Definition receiver.hpp:24
std::optional< std::string > source_ip
If set, datagrams from other senders are dropped and counted.
Definition receiver.hpp:28
Snapshot of the receive thread's counters, cumulative since start().
Definition receiver.hpp:35
std::uint64_t datagrams_received
Definition receiver.hpp:36
std::uint64_t range_images
Definition receiver.hpp:37
std::uint64_t unknown_type
Valid packets of unpublished types.
Definition receiver.hpp:40
std::chrono::steady_clock::time_point last_datagram_time
Zero before the first datagram.
Definition receiver.hpp:46
std::uint64_t bitmap_images
Definition receiver.hpp:38
std::uint64_t decode_errors
Definition receiver.hpp:41
std::uint32_t last_sequence_id
From the latest range or bitmap image.
Definition receiver.hpp:43
std::uint64_t filtered_source
Dropped by ReceiverOptions::source_ip.
Definition receiver.hpp:42
std::uint64_t imu_batches
Definition receiver.hpp:39
Receive-only UDP socket for the sonar's multicast or unicast stream.