From b33603cc9375dbc61ac94f22b3099007fa3687b5 Mon Sep 17 00:00:00 2001
From: Stephen D <webmaster@scd31.com>
Date: Thu, 19 Oct 2023 13:34:58 -0300
Subject: [PATCH] bug fixes and channel support

---
 src/config.rs |  3 ++-
 src/lib.rs    | 14 ++++++++++----
 2 files changed, 12 insertions(+), 5 deletions(-)

diff --git a/src/config.rs b/src/config.rs
index ee071a1..1ef9b9a 100644
--- a/src/config.rs
+++ b/src/config.rs
@@ -250,7 +250,8 @@ pub const RADIO_CONFIG_500_4: [u8; 643] = [
     0xC, 0x11, 0x40, 0x8, 0x0, 0x3A, 0xC, 0xB1, 0x7E, 0x44, 0x44, 0x20, 0xFE,
 ];
 
-// 430.5 MHz
+// 430.000 MHz @ channel 0
+// 430.500 MHZ @ channel 20 (default CATS frequency)
 // 9600 baud 2-FSK
 // Variable packet length up to 8191 bytes
 pub const RADIO_CONFIG_CATS: [u8; 644] = [
diff --git a/src/lib.rs b/src/lib.rs
index 9943a6f..b957b31 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -26,6 +26,7 @@ pub struct Rf4463<const MAX_PACKET_LEN: usize, Spi, SdnPin, CsPin, Delay> {
     radio: InternalRadio<Spi, SdnPin, CsPin, Delay>,
     state: InternalState<MAX_PACKET_LEN>,
     rx_forever: bool,
+    channel: u8,
 }
 
 impl<
@@ -56,6 +57,7 @@ where
             radio: InternalRadio::new(spi, sdn, cs, delay, config)?,
             state: InternalState::Idle,
             rx_forever: false,
+            channel: 0,
         })
     }
 
@@ -71,6 +73,10 @@ where
         self.radio.get_rssi()
     }
 
+    pub fn set_channel(&mut self, channel: u8) {
+        self.channel = channel;
+    }
+
     pub fn is_idle(&mut self) -> bool {
         matches!(self.state, InternalState::Idle)
     }
@@ -88,7 +94,7 @@ where
 
         self.radio.send_command::<0>(&mut [
             START_RX,
-            0,
+            self.channel,
             0,
             (MAX_PACKET_LEN >> 8).try_into().unwrap(),
             (MAX_PACKET_LEN & 0xff).try_into().unwrap(),
@@ -167,10 +173,10 @@ where
         self.radio
             .send_command::<0>(&mut [
                 START_TX,
-                0,
+                self.channel,
                 u8::from(State::Sleep) << 4,
-                (MAX_PACKET_LEN >> 8).try_into().unwrap(),
-                (MAX_PACKET_LEN & 0xff).try_into().unwrap(),
+                (len >> 8).try_into().unwrap(),
+                (len & 0xff).try_into().unwrap(),
                 0,
                 0,
             ])
-- 
GitLab