Skip to content
Snippets Groups Projects
Commit aacfe1ad authored by Stephen D's avatar Stephen D
Browse files

add timeout when txing

parent eed7712c
No related branches found
No related tags found
No related merge requests found
......@@ -5,7 +5,10 @@ use rppal::{
hal::Delay,
spi::{Bus, Mode, SlaveSelect, Spi},
};
use std::{thread, time::Duration};
use std::{
thread,
time::{Duration, Instant},
};
use tokio::sync::mpsc::{error::TryRecvError, Receiver, Sender};
pub const MAX_PACKET_LEN: usize = 8191;
......@@ -89,10 +92,18 @@ impl RadioManager {
fn send_packet(&mut self, data: &[u8]) -> anyhow::Result<()> {
self.radio.start_tx(data).map_err(|e| anyhow!("{e:?}"))?;
const TIMEOUT: Duration = Duration::from_secs(10);
let start_time = Instant::now();
while !self.radio.is_idle() {
self.radio
.interrupt(None, Some(data))
.map_err(|e| anyhow!("{e:?}"))?;
if start_time + TIMEOUT < Instant::now() {
bail!("Timeout while transmitting");
}
thread::sleep(Duration::from_millis(25));
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment