use saturating sub for timeouts, it overflowed at some point

This commit is contained in:
Vladan Popovic 2022-06-20 00:06:44 +02:00
parent f7070e02e7
commit 835bf50b80

View file

@ -62,7 +62,7 @@ impl<UART: serial::Uart> Iterator for IterableRx<UART> {
break None
}
thread::sleep(Duration::from_millis(200));
self.timeout = Some(timeout - now.elapsed());
self.timeout = Some(timeout.saturating_sub(now.elapsed()));
}
}
}
@ -140,7 +140,7 @@ impl<UART: serial::Uart> Modem<UART> {
let match_text: String = contains.unwrap_or("\n".to_string());
loop {
let rdln = self.read_line(start + timeout - Instant::now());
let rdln = self.read_line(timeout.saturating_sub(start.elapsed()));
if let Ok(line) = rdln {
println!("Read {} bytes from serial ({})", line.len(), line);
response.push_str(&line);