From bbb2e671aba89a7f72ef2966e12b8b2af1cf3a9e Mon Sep 17 00:00:00 2001 From: Stephen D <webmaster@scd31.com> Date: Thu, 19 Oct 2023 19:36:17 -0300 Subject: [PATCH] variable length rx --- src/lib.rs | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index b957b31..6fcc0fa 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -81,10 +81,13 @@ where matches!(self.state, InternalState::Idle) } - pub fn start_rx(&mut self, rx_forever: bool) -> Result<(), Spi::Error> { + // Len is none when using a variable-length packet + pub fn start_rx(&mut self, len: Option<usize>, rx_forever: bool) -> Result<(), Spi::Error> { self.radio.clear_fifo()?; self.radio.clear_ph_and_modem_interrupts()?; + let len = len.unwrap_or(0); + self.state = InternalState::Rx { data: [0; MAX_PACKET_LEN], i: 0, @@ -96,8 +99,8 @@ where START_RX, self.channel, 0, - (MAX_PACKET_LEN >> 8).try_into().unwrap(), - (MAX_PACKET_LEN & 0xff).try_into().unwrap(), + (len >> 8).try_into().unwrap(), + (len & 0xff).try_into().unwrap(), State::Rx.into(), if rx_forever { State::Rx.into() -- GitLab