]> code.octet-stream.net Git - m17rt/blobdiff - m17core/src/tnc.rs
Address more clippy lints
[m17rt] / m17core / src / tnc.rs
index 93a4363ae62f0939100ee51a04166fc548595edd..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) {
+        if self.ptt {
+            // Ignore self-decodes
+            return;
+        }
         match frame {
             Frame::Lsf(lsf) => {
                 // A new LSF implies a clean slate.
@@ -213,14 +217,11 @@ impl SoftTnc {
 
     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;
             }
-            _ => (),
         }
     }
 
@@ -230,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");
-        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);
         }
     }
 
@@ -407,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(
-                    &Address::Callsign(Callsign(b"M17RT-PKT".clone())),
+                    &Address::Callsign(Callsign(*b"M17RT-PKT")),
                     &Address::Broadcast,
                 ));
                 self.packet_queue[self.packet_next] = pending;
@@ -487,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),
@@ -498,6 +502,7 @@ struct OutgoingKiss {
     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,