improve serial impl
This commit is contained in:
@@ -60,7 +60,8 @@ impl PacketTransportSerialCobs {
|
|||||||
pub fn receive<F: FnMut(&[u8])>(&mut self, mut f: F) -> Result<usize, super::ReceiveError> {
|
pub fn receive<F: FnMut(&[u8])>(&mut self, mut f: F) -> Result<usize, super::ReceiveError> {
|
||||||
let mut decoded_packets = 0;
|
let mut decoded_packets = 0;
|
||||||
loop {
|
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 {
|
if read_bytes == 0 {
|
||||||
break;
|
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)
|
Ok(decoded_packets)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user