aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorMatthias P. Braendli <matthias.braendli@mpb.li>2024-01-14 17:25:57 +0100
committerMatthias P. Braendli <matthias.braendli@mpb.li>2024-01-14 17:25:57 +0100
commita1cc9912e6dc80d1152e4c1eef9d00b6c2f215a1 (patch)
tree4c9b18e867b7ffc945cdcbfd0ff14458b62ae372 /src
parent320245d45f2de4c5aa0e0f969505d8f38ebb686c (diff)
downloadcats-radio-node-a1cc9912e6dc80d1152e4c1eef9d00b6c2f215a1.tar.gz
cats-radio-node-a1cc9912e6dc80d1152e4c1eef9d00b6c2f215a1.tar.bz2
cats-radio-node-a1cc9912e6dc80d1152e4c1eef9d00b6c2f215a1.zip
Dump packet on receive error
Diffstat (limited to 'src')
-rw-r--r--src/bin/fake-radio.rs2
-rw-r--r--src/main.rs46
-rw-r--r--src/radio.rs1
-rw-r--r--src/ui.rs2
4 files changed, 23 insertions, 28 deletions
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<Vec<u8>> {
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<Mutex<f32>> {
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<T: FromStr + Sync>(value: &str) -> Result<Option<T>, T::Err> {
- if value == "" {
+ if value.is_empty() {
Ok(None)
}
else {