Silence noisy debug message on reading nothing
This commit is contained in:
@@ -69,6 +69,7 @@ pub fn find_packet(buffer: &[u8]) -> Result<PacketBounds> {
|
|||||||
pub struct SerialInterface {
|
pub struct SerialInterface {
|
||||||
interface: Box<dyn tokio_serial::SerialPort>,
|
interface: Box<dyn tokio_serial::SerialPort>,
|
||||||
buffer: Vec<u8>,
|
buffer: Vec<u8>,
|
||||||
|
mute_available_bytes_debug_message: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl SerialInterface {
|
impl SerialInterface {
|
||||||
@@ -79,6 +80,7 @@ impl SerialInterface {
|
|||||||
return Ok(Self {
|
return Ok(Self {
|
||||||
interface: interface,
|
interface: interface,
|
||||||
buffer: Vec::new(),
|
buffer: Vec::new(),
|
||||||
|
mute_available_bytes_debug_message: false,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -108,13 +110,23 @@ impl SerialInterface {
|
|||||||
.context("Failed to figure out how many bytes are available to read")?
|
.context("Failed to figure out how many bytes are available to read")?
|
||||||
.try_into()?;
|
.try_into()?;
|
||||||
|
|
||||||
debug!("Available bytes to read: {}", available_bytes);
|
|
||||||
let mut buffer: Vec<u8> = vec![0; available_bytes];
|
|
||||||
|
|
||||||
if buffer.len() <= 0 {
|
if available_bytes <= 0 && self.mute_available_bytes_debug_message {
|
||||||
debug!("No bytes available to read");
|
|
||||||
return Ok(());
|
return Ok(());
|
||||||
}
|
}
|
||||||
|
else {
|
||||||
|
self.mute_available_bytes_debug_message = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
debug!("Available bytes to read: {}", available_bytes);
|
||||||
|
|
||||||
|
if available_bytes <= 0 {
|
||||||
|
debug!("Trying to read more bytes...");
|
||||||
|
self.mute_available_bytes_debug_message = true;
|
||||||
|
return Ok(());
|
||||||
|
}
|
||||||
|
|
||||||
|
let mut buffer: Vec<u8> = vec![0; available_bytes];
|
||||||
|
|
||||||
self.interface.read(&mut buffer)
|
self.interface.read(&mut buffer)
|
||||||
.context("Failed to read bytes from serial device")?;
|
.context("Failed to read bytes from serial device")?;
|
||||||
|
Reference in New Issue
Block a user