From bbf5eb79e84a1a0b2567b3883df6d131ff853de2 Mon Sep 17 00:00:00 2001
From: Stephen D <webmaster@scd31.com>
Date: Fri, 1 Dec 2023 16:22:43 -0400
Subject: [PATCH] print rssi

---
 src/gate.rs |  4 ++--
 src/util.rs | 29 +++++++++++++++++++----------
 2 files changed, 21 insertions(+), 12 deletions(-)

diff --git a/src/gate.rs b/src/gate.rs
index 1731132..4657576 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 832b092..2f8fd9a 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)
 }
-- 
GitLab