]>
code.octet-stream.net Git - m17rt/blob - m17app/src/adapter.rs
1 use crate::{app
::TxHandle
, link_setup
::LinkSetup
};
2 use m17core
::protocol
::PacketType
;
5 /// Can be connected to an `M17App` to receive incoming packet data.
7 /// The `packet_received` callback will be fired once for each incoming packet type. Any filtering
8 /// must be done by the receiver. There are also some lifecycle callbacks, one of which will provide
9 /// a `TxHandle` when the adapter is first added to the app. This means the adapter can transmit as
11 pub trait PacketAdapter
: Send
+ Sync
+ '
static {
12 /// This adapter was added to an `M17App`.
13 fn adapter_registered(&self, id
: usize, handle
: TxHandle
) {
18 /// This adapter was removed from an `M17App`.
19 fn adapter_removed(&self) {}
21 /// The TNC has been started and incoming packets may now arrive.
22 fn tnc_started(&self) {}
24 /// The TNC has been shut down. There will be no more tx/rx.
25 fn tnc_closed(&self) {}
27 /// A packet has been received and assembled by the radio.
28 fn packet_received(&self, link_setup
: LinkSetup
, packet_type
: PacketType
, content
: Arc
<[u8]>) {
35 /// Can be connected to an `M17App` to receive incoming streams (voice or data).
37 /// Once an incoming stream has been acquired (either by receiving a Link Setup Frame or by decoding
38 /// an ongoing LICH), all stream frames will be provided to this adapter.
40 /// There are also some lifecycle callbacks, one of which will provide a `TxHandle` when the adapter
41 /// is first added to the app. This means the adapter can transmit as well as receive.
42 pub trait StreamAdapter
: Send
+ Sync
+ '
static {
43 /// This adapter was added to an `M17App`.
44 fn adapter_registered(&self, id
: usize, handle
: TxHandle
) {
49 /// This adapter was removed from an `M17App`.
50 fn adapter_removed(&self) {}
52 /// The TNC has been started and incoming streams may now arrive.
53 fn tnc_started(&self) {}
55 /// The TNC has been shut down. There will be no more tx/rx.
56 fn tnc_closed(&self) {}
58 /// A new incoming stream has begun.
60 /// If we did not receive the end of the previous stream, this may occur even there was never a
61 /// `stream_data` where `is_final` is true.
62 fn stream_began(&self, link_setup
: LinkSetup
) {
66 /// A frame has been received for an ongoing incoming stream.
68 /// It is not guaranteed to receive every frame. Frame numbers may not start from 0, and they will
69 /// wrap around to 0 after 0x7fff. If we receive an indication that the frame is the final one then
70 /// `is_final` is set. If the transmitter never sends that frame or we fail to receive it then the
71 /// stream may trail off without that being set. Implementors should consider setting an appropriate
72 /// timeout to consider a stream "dead" and wait for the next `stream_began`.
73 fn stream_data(&self, frame_number
: u16, is_final
: bool
, data
: Arc
<[u8; 16]>) {
80 // fn stream_lost(&self);
81 // fn stream_assembled_text_block()
82 // fn stream_gnss_data()
83 // fn stream_extended_callsign_data()
85 // fn stream_tx_ended_early(&self); // underrun/overrun