From a1cc9912e6dc80d1152e4c1eef9d00b6c2f215a1 Mon Sep 17 00:00:00 2001 From: "Matthias P. Braendli" Date: Sun, 14 Jan 2024 17:25:57 +0100 Subject: Dump packet on receive error --- src/bin/fake-radio.rs | 2 +- src/main.rs | 46 ++++++++++++++++++++-------------------------- src/radio.rs | 1 + src/ui.rs | 2 +- 4 files changed, 23 insertions(+), 28 deletions(-) (limited to 'src') diff --git a/src/bin/fake-radio.rs b/src/bin/fake-radio.rs index b7daf67..6747937 100644 --- a/src/bin/fake-radio.rs +++ b/src/bin/fake-radio.rs @@ -14,7 +14,7 @@ fn build_example_packet(comment: &str) -> anyhow::Result> { let mut buf = [0; MAX_PACKET_LEN]; let mut pkt = ham_cats::packet::Packet::new(&mut buf); pkt.add_identification( - Identification::new(&callsign, ssid, icon) + Identification::new(callsign, ssid, icon) .context("Invalid identification")?, ) .map_err(|e| anyhow!("Could not add identification to packet: {e}"))?; diff --git a/src/main.rs b/src/main.rs index 796dd7f..7423e3f 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,4 +1,3 @@ -use anyhow::Context; use log::{debug, info, warn, error}; use std::sync::{Arc, Mutex}; use tokio::net::UdpSocket; @@ -78,33 +77,28 @@ async fn main() -> std::io::Result<()> { let shared_state_receive = shared_state.clone(); tokio::task::spawn(async move { - loop { - match packet_receive - .recv() - .await - .context("Packet receive channel died") { - Ok((packet_data, rssi)) => { - debug!("RX RSSI {} len {}", rssi, packet_data.len()); - let mut buf = [0; MAX_PACKET_LEN]; - match ham_cats::packet::Packet::fully_decode(&packet_data[2..], &mut buf) { - Ok(packet) => { - if let Some(ident) = packet.identification() { - debug!(" From {}-{}", ident.callsign, ident.ssid); - } - - let mut db = shared_state_receive.lock().unwrap().db.clone(); - if let Err(e) = db.store_packet(&packet_data).await { - warn!("Failed to write to sqlite: {}", e); - } - } - Err(e) => { - warn!("Failed to decode packet: {}", e); - } - } - }, - Err(e) => warn!("Failed to decode packet: {}", e), + while let Some((packet_data, rssi)) = packet_receive.recv().await { + debug!("RX RSSI {} len {}", rssi, packet_data.len()); + let mut buf = [0; MAX_PACKET_LEN]; + match ham_cats::packet::Packet::fully_decode(&packet_data[2..], &mut buf) { + Ok(packet) => { + if let Some(ident) = packet.identification() { + debug!(" From {}-{}", ident.callsign, ident.ssid); + } + + let mut db = shared_state_receive.lock().unwrap().db.clone(); + if let Err(e) = db.store_packet(&packet_data).await { + warn!("Failed to write to sqlite: {}", e); + } } + Err(e) => { + warn!("Failed to decode packet: {}", e); + eprintln!("{:02X?}", packet_data); + } + } } + + warn!("Packet receive task stopping"); }); let port = 3000; diff --git a/src/radio.rs b/src/radio.rs index 239685f..1a917be 100644 --- a/src/radio.rs +++ b/src/radio.rs @@ -55,6 +55,7 @@ impl RadioManager { self.radio.set_channel(channel); } + #[allow(dead_code)] pub fn temperature_mutex(&self) -> Arc> { self.temperature.clone() } diff --git a/src/ui.rs b/src/ui.rs index 3ce2ab8..31d5f84 100644 --- a/src/ui.rs +++ b/src/ui.rs @@ -239,7 +239,7 @@ struct FormConfig { } fn empty_string_to_none(value: &str) -> Result, T::Err> { - if value == "" { + if value.is_empty() { Ok(None) } else { -- cgit v1.2.3