]>
code.octet-stream.net Git - m17rt/blob - m17app/src/adapter.rs
1 use crate::{app
::TxHandle
, error
::AdapterError
, 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 /// TNC is online. New packets may now be received and it is okay to transmit.
13 fn start(&self, handle
: TxHandle
) -> Result
<(), AdapterError
> {
18 /// This adapter or the whole TNC has been shut down. There will be no more tx/rx. This is a
19 /// permanent operation.
20 fn close(&self) -> Result
<(), AdapterError
> {
24 /// A packet has been received and assembled by the radio.
25 fn packet_received(&self, link_setup
: LinkSetup
, packet_type
: PacketType
, content
: Arc
<[u8]>) {
32 /// Can be connected to an `M17App` to receive incoming streams (voice or data).
34 /// Once an incoming stream has been acquired (either by receiving a Link Setup Frame or by decoding
35 /// an ongoing LICH), all stream frames will be provided to this adapter.
37 /// There are also some lifecycle callbacks, one of which will provide a `TxHandle` when the adapter
38 /// is first added to the app. This means the adapter can transmit as well as receive.
39 pub trait StreamAdapter
: Send
+ Sync
+ '
static {
40 /// TNC is online. New streams may now be received and it is okay to transmit.
41 fn start(&self, handle
: TxHandle
) -> Result
<(), AdapterError
> {
46 /// This adapter or the whole TNC has been shut down. There will be no more tx/rx. This is a
47 /// permanent operation.
48 fn close(&self) -> Result
<(), AdapterError
> {
52 /// A new incoming stream has begun.
54 /// If we did not receive the end of the previous stream, this may occur even there was never a
55 /// `stream_data` where `is_final` is true.
56 fn stream_began(&self, link_setup
: LinkSetup
) {
60 /// A frame has been received for an ongoing incoming stream.
62 /// It is not guaranteed to receive every frame. Frame numbers may not start from 0, and they will
63 /// wrap around to 0 after 0x7fff. If we receive an indication that the frame is the final one then
64 /// `is_final` is set. If the transmitter never sends that frame or we fail to receive it then the
65 /// stream may trail off without that being set. Implementors should consider setting an appropriate
66 /// timeout to consider a stream "dead" and wait for the next `stream_began`.
67 fn stream_data(&self, frame_number
: u16, is_final
: bool
, data
: Arc
<[u8; 16]>) {
74 // fn stream_lost(&self);
75 // fn stream_assembled_text_block()
76 // fn stream_gnss_data()
77 // fn stream_extended_callsign_data()
79 // fn stream_tx_ended_early(&self); // underrun/overrun