4#ifndef WATERLINKEDSONAR_UDP_RECEIVER_HPP
5#define WATERLINKEDSONAR_UDP_RECEIVER_HPP
13#include <system_error>
19namespace waterlinked::sonar {
97 [[nodiscard]]
bool running() const noexcept;
103 void require_not_started() const;
105 void dispatch(const rip::Decoded& decoded);
109 rip::Decoder decoder_;
114 std::function<
void(rip::DecodeStatus)> on_decode_error_;
115 std::function<
void(const std::error_code&)> on_socket_error_;
118 std::atomic<std::thread::
id> loop_thread_;
119 std::atomic<
bool> running_{
false};
120 bool started_{
false};
122 std::atomic<std::uint64_t> datagrams_received_{0};
123 std::atomic<std::uint64_t> range_images_{0};
124 std::atomic<std::uint64_t> bitmap_images_{0};
125 std::atomic<std::uint64_t> imu_batches_{0};
126 std::atomic<std::uint64_t> unknown_type_{0};
127 std::atomic<std::uint64_t> decode_errors_{0};
128 std::atomic<std::uint64_t> filtered_source_{0};
129 std::atomic<std::uint32_t> last_sequence_id_{0};
130 std::atomic<std::chrono::steady_clock::rep> last_datagram_ticks_{0};
Receives datagrams on a thread of its own, decodes them and passes the messages to the registered cal...
Definition receiver.hpp:51
void on_range_image(std::function< void(const RangeImageView &)> callback)
Sets the callback for range images, replacing any earlier one.
ReceiverStats stats() const noexcept
Current counters; callable from any thread.
void on_socket_error(std::function< void(const std::error_code &)> callback)
Sets the callback for the socket error that ends the receive thread; see on_range_image().
void on_bitmap_image(std::function< void(const BitmapImageView &)> callback)
Sets the callback for bitmap images; see on_range_image().
void start()
Starts the receive thread.
void on_imu_batch(std::function< void(const ImuBatchView &)> callback)
Sets the callback for IMU batches; see on_range_image().
bool running() const noexcept
Whether the receive thread is running; false once a socket error has ended it.
void on_decode_error(std::function< void(rip::DecodeStatus)> callback)
Sets the callback for datagrams that fail to decode; see on_range_image().
Receiver(UdpSocket socket, ReceiverOptions options={})
Takes over socket.
void stop()
Stops the receive thread and joins it unless called from a callback.
IPv4 UDP socket bound for the sonar's multicast or unicast stream.
Definition socket.hpp:42
Decoder for Range Image Protocol packets.
DecodeStatus
Outcome of decoding one packet.
Definition decoder.hpp:21
Views of the messages carried by the Range Image Protocol.
Receive-only UDP socket for the sonar's data stream.
8-bit greyscale image that can be displayed as is.
Definition messages.hpp:52
IMU samples taken at about 100 Hz while acoustics is enabled.
Definition messages.hpp:69
Distance to the strongest reflection for each pixel.
Definition messages.hpp:26
Filtering applied to datagrams before decoding.
Definition receiver.hpp:22
std::optional< std::string > source_ip
Sender to accept; datagrams from other senders are dropped.
Definition receiver.hpp:25
Counters accumulated since Receiver::start().
Definition receiver.hpp:31
std::uint64_t datagrams_received
Datagrams that passed the filter.
Definition receiver.hpp:32
std::uint64_t range_images
Decoded range images.
Definition receiver.hpp:33
std::uint64_t unknown_type
Valid packets of unpublished types.
Definition receiver.hpp:36
std::chrono::steady_clock::time_point last_datagram_time
Arrival of the latest datagram that passed the filter; the epoch before the first one.
Definition receiver.hpp:43
std::uint64_t bitmap_images
Decoded bitmap images.
Definition receiver.hpp:34
std::uint64_t decode_errors
Datagrams that failed to decode.
Definition receiver.hpp:37
std::uint32_t last_sequence_id
Sequence ID of the latest range or bitmap image.
Definition receiver.hpp:40
std::uint64_t filtered_source
Dropped by ReceiverOptions::source_ip.
Definition receiver.hpp:38
std::uint64_t imu_batches
Decoded IMU batches.
Definition receiver.hpp:35