]> code.octet-stream.net Git - m17rt/blobdiff - m17core/src/tnc.rs
Address more clippy lints
[m17rt] / m17core / src / tnc.rs
index 8cd0152ae81d82520b6d65a73a37ef632ac74a00..a64f367e70c1f152eafb1892c311ee663b36ec35 100644 (file)
@@ -102,6 +102,10 @@ impl SoftTnc {
 
     /// Process an individual `Frame` that has been decoded by the modem.
     pub fn handle_frame(&mut self, frame: Frame) {
 
     /// Process an individual `Frame` that has been decoded by the modem.
     pub fn handle_frame(&mut self, frame: Frame) {
+        if self.ptt {
+            // Ignore self-decodes
+            return;
+        }
         match frame {
             Frame::Lsf(lsf) => {
                 // A new LSF implies a clean slate.
         match frame {
             Frame::Lsf(lsf) => {
                 // A new LSF implies a clean slate.
@@ -117,7 +121,10 @@ impl SoftTnc {
                     Mode::Stream => {
                         let kiss = KissFrame::new_stream_setup(&lsf.0).unwrap();
                         self.kiss_to_host(kiss);
                     Mode::Stream => {
                         let kiss = KissFrame::new_stream_setup(&lsf.0).unwrap();
                         self.kiss_to_host(kiss);
-                        self.state = State::RxStream(RxStreamState { lsf, index: 0 });
+                        self.state = State::RxStream(RxStreamState {
+                            _lsf: lsf,
+                            index: 0,
+                        });
                     }
                 }
             }
                     }
                 }
             }
@@ -139,7 +146,7 @@ impl SoftTnc {
                                 let start = 25 * rx.count;
                                 let end = start + payload_len;
                                 rx.packet[start..(start + payload_len)]
                                 let start = 25 * rx.count;
                                 let end = start + payload_len;
                                 rx.packet[start..(start + payload_len)]
-                                    .copy_from_slice(&packet.payload);
+                                    .copy_from_slice(&packet.payload[0..payload_len]);
                                 // TODO: compatible packets should be sent on port 0 too
                                 let kiss =
                                     KissFrame::new_full_packet(&rx.lsf.0, &rx.packet[0..end])
                                 // TODO: compatible packets should be sent on port 0 too
                                 let kiss =
                                     KissFrame::new_full_packet(&rx.lsf.0, &rx.packet[0..end])
@@ -186,7 +193,7 @@ impl SoftTnc {
                                 // TODO: avoid discarding the first data payload here
                                 // need a queue depth of 2 for outgoing kiss
                                 self.state = State::RxStream(RxStreamState {
                                 // TODO: avoid discarding the first data payload here
                                 // need a queue depth of 2 for outgoing kiss
                                 self.state = State::RxStream(RxStreamState {
-                                    lsf,
+                                    _lsf: lsf,
                                     index: stream.frame_number + 1,
                                 });
                             }
                                     index: stream.frame_number + 1,
                                 });
                             }
@@ -210,14 +217,11 @@ impl SoftTnc {
 
     pub fn set_now(&mut self, now_samples: u64) {
         self.now = now_samples;
 
     pub fn set_now(&mut self, now_samples: u64) {
         self.now = now_samples;
-        match self.state {
-            State::TxEndingAtTime(time) => {
-                if now_samples >= time {
-                    self.ptt = false;
-                    self.state = State::Idle;
-                }
+        if let State::TxEndingAtTime(time) = self.state {
+            if now_samples >= time {
+                self.ptt = false;
+                self.state = State::Idle;
             }
             }
-            _ => (),
         }
     }
 
         }
     }
 
@@ -227,11 +231,8 @@ impl SoftTnc {
 
     pub fn set_tx_end_time(&mut self, in_samples: usize) {
         log::debug!("tnc has been told that tx will complete in {in_samples} samples");
 
     pub fn set_tx_end_time(&mut self, in_samples: usize) {
         log::debug!("tnc has been told that tx will complete in {in_samples} samples");
-        match self.state {
-            State::TxEnding => {
-                self.state = State::TxEndingAtTime(self.now + in_samples as u64);
-            }
-            _ => (),
+        if let State::TxEnding = self.state {
+            self.state = State::TxEndingAtTime(self.now + in_samples as u64);
         }
     }
 
         }
     }
 
@@ -404,7 +405,7 @@ impl SoftTnc {
                 pending.app_data[len..len + 2].copy_from_slice(&packet_crc.to_be_bytes());
                 pending.app_data_len = len + 2;
                 pending.lsf = Some(LsfFrame::new_packet(
                 pending.app_data[len..len + 2].copy_from_slice(&packet_crc.to_be_bytes());
                 pending.app_data_len = len + 2;
                 pending.lsf = Some(LsfFrame::new_packet(
-                    &Address::Callsign(Callsign(b"M17RT-PKT".clone())),
+                    &Address::Callsign(Callsign(*b"M17RT-PKT")),
                     &Address::Broadcast,
                 ));
                 self.packet_queue[self.packet_next] = pending;
                     &Address::Broadcast,
                 ));
                 self.packet_queue[self.packet_next] = pending;
@@ -431,7 +432,7 @@ impl SoftTnc {
                 }
                 pending.lsf = Some(lsf);
                 let app_data_len = len - 30;
                 }
                 pending.lsf = Some(lsf);
                 let app_data_len = len - 30;
-                pending.app_data[0..app_data_len].copy_from_slice(&payload[30..]);
+                pending.app_data[0..app_data_len].copy_from_slice(&payload[30..len]);
                 pending.app_data_len = app_data_len;
                 self.packet_queue[self.packet_next] = pending;
                 self.packet_next = (self.packet_next + 1) % 4;
                 pending.app_data_len = app_data_len;
                 self.packet_queue[self.packet_next] = pending;
                 self.packet_next = (self.packet_next + 1) % 4;
@@ -484,6 +485,12 @@ impl SoftTnc {
     }
 }
 
     }
 }
 
+impl Default for SoftTnc {
+    fn default() -> Self {
+        Self::new()
+    }
+}
+
 #[derive(Debug, PartialEq, Eq, Clone)]
 pub enum SoftTncError {
     General(&'static str),
 #[derive(Debug, PartialEq, Eq, Clone)]
 pub enum SoftTncError {
     General(&'static str),
@@ -495,6 +502,7 @@ struct OutgoingKiss {
     sent: usize,
 }
 
     sent: usize,
 }
 
+#[allow(clippy::large_enum_variant)]
 enum State {
     /// Nothing happening. We may have TX data queued but we won't act on it until CSMA opens up.
     Idle,
 enum State {
     /// Nothing happening. We may have TX data queued but we won't act on it until CSMA opens up.
     Idle,
@@ -531,7 +539,7 @@ struct RxAcquiringStreamState {
 
 struct RxStreamState {
     /// Track identifying information for this transmission so we can tell if it changes.
 
 struct RxStreamState {
     /// Track identifying information for this transmission so we can tell if it changes.
-    lsf: LsfFrame,
+    _lsf: LsfFrame,
 
     /// Expected next frame number. Allowed to skip values on RX, but not go backwards.
     index: u16,
 
     /// Expected next frame number. Allowed to skip values on RX, but not go backwards.
     index: u16,
@@ -594,7 +602,7 @@ impl PendingPacket {
             )
         };
         let mut payload = [0u8; 25];
             )
         };
         let mut payload = [0u8; 25];
-        payload.copy_from_slice(
+        payload[0..data_len].copy_from_slice(
             &self.app_data[self.app_data_transmitted..(self.app_data_transmitted + data_len)],
         );
         self.app_data_transmitted += data_len;
             &self.app_data[self.app_data_transmitted..(self.app_data_transmitted + data_len)],
         );
         self.app_data_transmitted += data_len;