X-Git-Url: https://code.octet-stream.net/m17rt/blobdiff_plain/b8702d115ebc071a9ae97e9aa9c4bc00196b5e26..c3a031d9fa12f5fc9888838a4793e47512ad7326:/m17app/src/app.rs?ds=inline diff --git a/m17app/src/app.rs b/m17app/src/app.rs index 8130455..b142663 100644 --- a/m17app/src/app.rs +++ b/m17app/src/app.rs @@ -1,7 +1,7 @@ use crate::adapter::{PacketAdapter, StreamAdapter}; use crate::tnc::Tnc; use m17core::kiss::{KissBuffer, KissCommand, KissFrame}; -use m17core::protocol::{EncryptionType, LsfFrame, PacketType}; +use m17core::protocol::{EncryptionType, LsfFrame, PacketType, StreamFrame}; use log::debug; use std::collections::HashMap; @@ -60,14 +60,6 @@ impl M17App { } } - pub fn transmit_packet(&self, packet_type: PacketType, payload: &[u8]) { - // hang on where do we get the LSF details from? We need a destination obviously - // our source address needs to be configured here too - // also there is possible CAN, encryption, meta payload - - // we will immediately convert this into a KISS payload before sending into channel so we only need borrow on data - } - /// Create a handle that can be used to transmit data on the TNC pub fn tx(&self) -> TxHandle { TxHandle { @@ -80,6 +72,8 @@ impl M17App { } pub fn close(&self) { + // TODO: blocking function to indicate TNC has finished closing + // then we could call this in a signal handler to ensure PTT is dropped before quit let _ = self.event_tx.send(TncControlEvent::Close); } } @@ -89,13 +83,29 @@ pub struct TxHandle { } impl TxHandle { + pub fn transmit_packet(&self, packet_type: PacketType, payload: &[u8]) { + // hang on where do we get the LSF details from? We need a destination obviously + // our source address needs to be configured here too + // also there is possible CAN, encryption, meta payload + + // we will immediately convert this into a KISS payload before sending into channel so we only need borrow on data + } + // add more methods here for stream outgoing - pub fn transmit_stream_start(&self /* lsf?, payload? what needs to be configured ?! */) {} + pub fn transmit_stream_start(&self, lsf: LsfFrame) { + // TODO: is asking for an LsfFrame a good idea or unfriendly API? + // What I should do here is create a LinkSetup struct which wraps an LsfFrame and can be loaded with a raw one + let kiss_frame = KissFrame::new_stream_setup(&lsf.0).unwrap(); + let _ = self.event_tx.send(TncControlEvent::Kiss(kiss_frame)); + } // as long as there is only one TNC it is implied there is only ever one stream transmission in flight - pub fn transmit_stream_next(&self, /* next payload, */ end_of_stream: bool) {} + pub fn transmit_stream_next(&self, stream: StreamFrame) { + let kiss_frame = KissFrame::new_stream_data(&stream).unwrap(); + let _ = self.event_tx.send(TncControlEvent::Kiss(kiss_frame)); + } } /// Synchronised structure for listeners subscribing to packets and streams. @@ -125,7 +135,7 @@ enum TncControlEvent { Close, } -fn spawn_reader<T: Tnc + Send + 'static>(mut tnc: T, adapters: Arc<RwLock<Adapters>>) { +fn spawn_reader<T: Tnc>(mut tnc: T, adapters: Arc<RwLock<Adapters>>) { std::thread::spawn(move || { let mut kiss_buffer = KissBuffer::new(); let mut stream_running = false; @@ -156,7 +166,7 @@ fn spawn_reader<T: Tnc + Send + 'static>(mut tnc: T, adapters: Arc<RwLock<Adapte continue; } let lsf = LsfFrame(payload[0..30].try_into().unwrap()); - if lsf.crc() != 0 { + if lsf.check_crc() != 0 { debug!("LSF in full packet frame did not pass CRC"); continue; } @@ -199,7 +209,7 @@ fn spawn_reader<T: Tnc + Send + 'static>(mut tnc: T, adapters: Arc<RwLock<Adapte }; if n == 30 { let lsf = LsfFrame(payload[0..30].try_into().unwrap()); - if lsf.crc() != 0 { + if lsf.check_crc() != 0 { debug!("initial LSF in stream did not pass CRC"); continue; } @@ -241,7 +251,7 @@ fn spawn_reader<T: Tnc + Send + 'static>(mut tnc: T, adapters: Arc<RwLock<Adapte }); } -fn spawn_writer<T: Tnc + Send + 'static>(mut tnc: T, event_rx: mpsc::Receiver<TncControlEvent>) { +fn spawn_writer<T: Tnc>(mut tnc: T, event_rx: mpsc::Receiver<TncControlEvent>) { std::thread::spawn(move || { while let Ok(ev) = event_rx.recv() { match ev {