diff --git a/src/gate.rs b/src/gate.rs index 1731132f1f5b776c686c7549aeb383fe0fff45aa..4657576844e63f4a1d953095011ad7b7a7fe7552 100644 --- a/src/gate.rs +++ b/src/gate.rs @@ -119,7 +119,7 @@ pub async fn packet_handler( .context("Packet receive channel died")?; let mut buf = [0; MAX_PACKET_LEN]; - if let Ok(mut packet) = attempt_decode(&packet, &mut buf) { + if let Ok(mut packet) = attempt_decode(&packet, &mut buf, rssi) { let mut buf2 = [0; MAX_PACKET_LEN]; let mut internet_packet = packet.clone_backing(&mut buf2); match append_internet_to_packet_route(&callsign, ssid, rssi, &mut internet_packet) { @@ -250,7 +250,7 @@ pub async fn felinet_receive_once( .and_then(|_| Packet::semi_decode(buf).ok()) { if pkt.should_digipeat(callsign, ssid).is_ok() { - print_packet(&pkt, false); + print_packet(&pkt, None); let mut buf2 = [0; MAX_PACKET_LEN]; let mut data = Buffer::new_empty(&mut buf2); diff --git a/src/util.rs b/src/util.rs index 832b092e037cc38df4ebe4356ce36d5e6724da63..2f8fd9a399b043a5bc292fae182b6746e081f16c 100644 --- a/src/util.rs +++ b/src/util.rs @@ -6,15 +6,20 @@ use ham_cats::{ whisker::{Route, RouteIdentity, RouteNode}, }; -pub fn print_packet(pkt: &Packet<MAX_PACKET_LEN>, is_rf: bool) { - let color = if is_rf { - println!("----- RF -----"); +pub fn print_packet(pkt: &Packet<MAX_PACKET_LEN>, rssi: Option<f64>) { + println!(); - Color::Green - } else { - println!("--- FELINET ---"); + let color = match rssi { + Some(rssi) => { + println!("----- RF [{rssi} dBm] -----"); + + Color::Green + } + None => { + println!("--- FELINET ---"); - Color::Magenta + Color::Magenta + } }; if let Some(ident) = pkt.identification() { @@ -35,7 +40,11 @@ pub fn print_packet(pkt: &Packet<MAX_PACKET_LEN>, is_rf: bool) { let s = if ident.is_future() { "*" } else { "" }; let rc = ident.callsign(); let rs = ident.ssid(); - format!("{rc}-{rs}{s}") + let rssi = match ident.rssi() { + Some(x) => format!("[{x:.1} dbm]"), + None => "".to_string(), + }; + format!("{rc}-{rs}{s} {rssi}") } }) .collect::<Vec<String>>() @@ -62,17 +71,17 @@ pub fn print_packet(pkt: &Packet<MAX_PACKET_LEN>, is_rf: bool) { gps.heading() ); } - println!(); } pub fn attempt_decode<'a>( packet: &[u8], buf: &'a mut [u8; MAX_PACKET_LEN], + rssi: f64, ) -> anyhow::Result<Packet<'a, MAX_PACKET_LEN>> { let packet: Packet<MAX_PACKET_LEN> = Packet::fully_decode(packet, buf).map_err(|e| anyhow!("Could not decode packet: {e:?}"))?; - print_packet(&packet, true); + print_packet(&packet, Some(rssi)); Ok(packet) }