waterlinkedsonar
C++ client library for the Water Linked Sonar 3D-15
Loading...
Searching...
No Matches
Public Member Functions | List of all members
waterlinked::sonar::Receiver Class Reference

Receives datagrams on a thread of its own, decodes them and passes the messages to the registered callbacks. More...

#include <waterlinkedsonar/udp/receiver.hpp>

Public Member Functions

 Receiver (UdpSocket socket, ReceiverOptions options={})
 Takes over socket.
 
 ~Receiver ()
 Calls stop().
 
 Receiver (const Receiver &)=delete
 
Receiver & operator= (const Receiver &)=delete
 
 Receiver (Receiver &&)=delete
 
Receiver & operator= (Receiver &&)=delete
 
void on_range_image (std::function< void(const RangeImageView &)> callback)
 Sets the callback for range images, replacing any earlier one.
 
void on_bitmap_image (std::function< void(const BitmapImageView &)> callback)
 Sets the callback for bitmap images; see on_range_image().
 
void on_imu_batch (std::function< void(const ImuBatchView &)> callback)
 Sets the callback for IMU batches; see on_range_image().
 
void on_decode_error (std::function< void(rip::DecodeStatus)> callback)
 Sets the callback for datagrams that fail to decode; see on_range_image().
 
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 start ()
 Starts the receive thread.
 
void stop ()
 Stops the receive thread and joins it unless called from a callback.
 
bool running () const noexcept
 Whether the receive thread is running; false once a socket error has ended it.
 
ReceiverStats stats () const noexcept
 Current counters; callable from any thread.
 

Detailed Description

Receives datagrams on a thread of its own, decodes them and passes the messages to the registered callbacks.

Callbacks run one at a time on the receive thread and must not throw. A view passed to a callback is valid until the callback returns.

Constructor & Destructor Documentation

◆ Receiver()

waterlinked::sonar::Receiver::Receiver ( UdpSocket  socket,
ReceiverOptions  options = {} 
)
explicit

Takes over socket.

No callbacks run before start(); datagrams that arrive earlier wait in the socket's receive buffer.

◆ ~Receiver()

waterlinked::sonar::Receiver::~Receiver ( )

Calls stop().

Must not run on the receive thread, so a callback must not destroy the Receiver.

Member Function Documentation

◆ on_decode_error()

void waterlinked::sonar::Receiver::on_decode_error ( std::function< void(rip::DecodeStatus)>  callback)

Sets the callback for datagrams that fail to decode; see on_range_image().

Packets of unpublished types are only counted.

◆ on_range_image()

void waterlinked::sonar::Receiver::on_range_image ( std::function< void(const RangeImageView &)>  callback)

Sets the callback for range images, replacing any earlier one.

Exceptions
std::logic_errorafter start().

◆ start()

void waterlinked::sonar::Receiver::start ( )

Starts the receive thread.

A Receiver starts at most once.

Exceptions
std::logic_errorif it was started before.
std::system_errorif the thread cannot be created.

◆ stop()

void waterlinked::sonar::Receiver::stop ( )

Stops the receive thread and joins it unless called from a callback.

Idempotent.


The documentation for this class was generated from the following file: