From c059d9172fdfa18ef5b2c49aa6433ad22db858fc Mon Sep 17 00:00:00 2001
From: Stephen D <webmaster@scd31.com>
Date: Sat, 3 Jun 2023 11:12:51 -0300
Subject: [PATCH] tx garbage at the start of a packet burst to give the AGC
 time to calibrate

---
 src/main.rs | 17 ++++++++++++++++-
 1 file changed, 16 insertions(+), 1 deletion(-)

diff --git a/src/main.rs b/src/main.rs
index 475c065..3409546 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -23,6 +23,7 @@ mod app {
     use ringbuffer::{ConstGenericRingBuffer, RingBuffer, RingBufferRead, RingBufferWrite};
 
     use crate::packet::Packet;
+    use crate::packet::PACKET_LEN;
 
     // in # packets
     const BUFFER_LEN: usize = 50;
@@ -139,14 +140,28 @@ mod app {
     #[idle(local=[radio], shared=[tx_buf, radio_temp])]
     fn idle(mut ctx: idle::Context) -> ! {
         let mut i = 0;
+        let mut iterations_since_last_packet = 0;
         loop {
             if let Some(mut pkt) = ctx.shared.tx_buf.lock(|buf| buf.dequeue()) {
+                if iterations_since_last_packet >= 1000 {
+                    // if we haven't transmitted in a while, the receiver's AGC is going to be messed up
+                    // send 5 packets just so it can calibrate before we actually send it
+                    for _ in 0..5 {
+                        const GARBAGE: [u8; PACKET_LEN] = [0x00; PACKET_LEN];
+                        ctx.local.radio.tx(&mut GARBAGE.clone()).unwrap();
+                    }
+                }
+
                 ctx.local.radio.tx(&mut pkt.data).unwrap();
+
+                iterations_since_last_packet = 0;
+            } else {
+                iterations_since_last_packet += 1;
             }
 
             i += 1;
 
-            // get temp every 500 packets, or whenever when idle TODO
+            // get temp every 500 packets, or whenever when idle
             if i >= 500 {
                 i = 0;
 
-- 
GitLab