]> code.octet-stream.net Git - m17rt/blob - m17app/src/adapter.rs
81fdb5b0fbbbc35044f749b1312bdf083919940b
[m17rt] / m17app / src / adapter.rs
1 use crate::{app::TxHandle, link_setup::LinkSetup};
2 use m17core::protocol::PacketType;
3 use std::sync::Arc;
4
5 /// Can be connected to an `M17App` to receive incoming packet data.
6 ///
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
10 /// well as receive.
11 pub trait PacketAdapter: Send + Sync + 'static {
12 /// This adapter was added to an `M17App`.
13 fn adapter_registered(&self, id: usize, handle: TxHandle) {
14 let _ = id;
15 let _ = handle;
16 }
17
18 /// This adapter was removed from an `M17App`.
19 fn adapter_removed(&self) {}
20
21 /// The TNC has been started and incoming packets may now arrive.
22 fn tnc_started(&self) {}
23
24 /// The TNC has been shut down. There will be no more tx/rx.
25 fn tnc_closed(&self) {}
26
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]>) {
29 let _ = link_setup;
30 let _ = packet_type;
31 let _ = content;
32 }
33 }
34
35 /// Can be connected to an `M17App` to receive incoming streams (voice or data).
36 ///
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.
39 ///
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) {
45 let _ = id;
46 let _ = handle;
47 }
48
49 /// This adapter was removed from an `M17App`.
50 fn adapter_removed(&self) {}
51
52 /// The TNC has been started and incoming streams may now arrive.
53 fn tnc_started(&self) {}
54
55 /// The TNC has been shut down. There will be no more tx/rx.
56 fn tnc_closed(&self) {}
57
58 /// A new incoming stream has begun.
59 ///
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) {
63 let _ = link_setup;
64 }
65
66 /// A frame has been received for an ongoing incoming stream.
67 ///
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]>) {
74 let _ = frame_number;
75 let _ = is_final;
76 let _ = data;
77 }
78
79 // TODO
80 // fn stream_lost(&self);
81 // fn stream_assembled_text_block()
82 // fn stream_gnss_data()
83 // fn stream_extended_callsign_data()
84
85 // fn stream_tx_ended_early(&self); // underrun/overrun
86 }