aboutsummaryrefslogtreecommitdiffstats
path: root/src/main.rs
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/main.rs
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/main.rs')
-rw-r--r--src/main.rs46
1 files changed, 20 insertions, 26 deletions
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;