|
waterlinkedsonar
C++ client library for the Water Linked Sonar 3D-15
|
Owns the receive thread: reads datagrams from the injected socket, decodes them, and dispatches to the registered callbacks on that thread. More...
#include <waterlinkedsonar/receiver.hpp>
Public Member Functions | |
| Receiver (std::unique_ptr< UdpSocket > socket, ReceiverOptions options={}) | |
| Takes ownership of an open socket; nothing is read until start(). | |
| ~Receiver () | |
| Stops the receive thread if it is running. | |
| Receiver (const Receiver &)=delete | |
| Receiver & | operator= (const Receiver &)=delete |
| void | on_range_image (std::function< void(const RangeImageView &)> cb) |
| Registers a callback for decoded RangeImage messages. | |
| void | on_bitmap_image (std::function< void(const BitmapImageView &)> cb) |
| Registers a callback for decoded BitmapImage messages. | |
| void | on_imu_batch (std::function< void(const ImuBatchView &)> cb) |
| Registers a callback for decoded ImuBatch messages. | |
| void | on_decode_error (std::function< void(rip::DecodeStatus)> cb) |
| Registers a callback for datagrams that fail to decode. | |
| 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. | |
| void | start () |
| Starts the receive thread. | |
| void | stop () |
| Stops the receive thread. | |
| bool | running () const |
| False before start, after stop, and after a socket error ends the receive loop on its own. | |
| ReceiverStats | stats () const |
| Counter snapshot; callable from any thread. | |
Owns the receive thread: reads datagrams from the injected socket, decodes them, and dispatches to the registered callbacks on that thread.
Callbacks run sequentially on the receive thread. The views they receive are valid for the duration of the callback: decode and dispatch share the one thread, so the storage behind a view is not reused until the callback returns. Copy any data kept beyond the callback.
|
explicit |
Takes ownership of an open socket; nothing is read until start().
| std::invalid_argument | when socket is null. |
| waterlinked::sonar::Receiver::~Receiver | ( | ) |
Stops the receive thread if it is running.
|
delete |
| void waterlinked::sonar::Receiver::on_bitmap_image | ( | std::function< void(const BitmapImageView &)> | cb | ) |
Registers a callback for decoded BitmapImage messages.
Same registration and execution rules as on_range_image().
| void waterlinked::sonar::Receiver::on_decode_error | ( | std::function< void(rip::DecodeStatus)> | cb | ) |
Registers a callback for datagrams that fail to decode.
Same registration and execution rules as on_range_image(). UNKNOWN_TYPE packets are counted, not reported here.
| void waterlinked::sonar::Receiver::on_imu_batch | ( | std::function< void(const ImuBatchView &)> | cb | ) |
Registers a callback for decoded ImuBatch messages.
Same registration and execution rules as on_range_image().
| void waterlinked::sonar::Receiver::on_range_image | ( | std::function< void(const RangeImageView &)> | cb | ) |
Registers a callback for decoded RangeImage messages.
Registration for any callback type is only valid before start() and throws std::logic_error afterwards; registering twice calls both. Callbacks run sequentially on the receive thread and must not block for long or throw.
| void waterlinked::sonar::Receiver::on_socket_error | ( | std::function< void(const std::error_code &)> | cb | ) |
Registers a callback for the unrecoverable socket error that ends the receive loop.
Same registration and execution rules as on_range_image(). Invoked at most once, from the receive thread, just before running() becomes false.
| bool waterlinked::sonar::Receiver::running | ( | ) | const |
False before start, after stop, and after a socket error ends the receive loop on its own.
| void waterlinked::sonar::Receiver::start | ( | ) |
| ReceiverStats waterlinked::sonar::Receiver::stats | ( | ) | const |
Counter snapshot; callable from any thread.
| void waterlinked::sonar::Receiver::stop | ( | ) |
Stops the receive thread.
Idempotent.
Joins the thread, except when called from a callback on that thread; the loop then exits once the callback returns.