improve serial impl

This commit is contained in:
Robin Mueller
2025-11-04 15:24:13 +01:00
parent f6aedfcab4
commit 00dc99d697

View File

@@ -60,7 +60,8 @@ impl PacketTransportSerialCobs {
pub fn receive<F: FnMut(&[u8])>(&mut self, mut f: F) -> Result<usize, super::ReceiveError> {
let mut decoded_packets = 0;
loop {
let read_bytes = self.serial.read(&mut self.reception_buffer)?;
match self.serial.read(&mut self.reception_buffer) {
Ok(read_bytes) => {
if read_bytes == 0 {
break;
}
@@ -75,6 +76,16 @@ impl PacketTransportSerialCobs {
}
}
}
Err(e) => {
if e.kind() == std::io::ErrorKind::TimedOut
|| e.kind() == std::io::ErrorKind::WouldBlock
{
break;
}
return Err(super::ReceiveError::Io(e));
}
}
}
Ok(decoded_packets)
}