+pub struct TxHandle {
+ event_tx: mpsc::SyncSender<TncControlEvent>,
+}
+
+impl TxHandle {
+ pub fn transmit_packet(&self, link_setup: &LinkSetup, packet_type: PacketType, payload: &[u8]) {
+ let (pack_type, pack_type_len) = packet_type.as_proto();
+ if pack_type_len + payload.len() > 823 {
+ // TODO: error for invalid transmission type
+ return;
+ }
+ let mut full_payload = vec![];
+ full_payload.extend_from_slice(&pack_type[0..pack_type_len]);
+ full_payload.extend_from_slice(&payload);
+ let crc = m17core::crc::m17_crc(&full_payload);
+ full_payload.extend_from_slice(&crc.to_be_bytes());
+ let kiss_frame = KissFrame::new_full_packet(&link_setup.raw.0, &full_payload).unwrap();
+ let _ = self.event_tx.send(TncControlEvent::Kiss(kiss_frame));
+ }
+
+ pub fn transmit_stream_start(&self, link_setup: &LinkSetup) {
+ let kiss_frame = KissFrame::new_stream_setup(&link_setup.raw.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, stream: &StreamFrame) {
+ let kiss_frame = KissFrame::new_stream_data(&stream).unwrap();
+ let _ = self.event_tx.send(TncControlEvent::Kiss(kiss_frame));
+ }
+}
+