Silence noisy debug message on reading nothing

This commit is contained in:
2025-08-01 19:41:27 +02:00
parent c8ff31d9c5
commit d0c20153e4

View File

@@ -69,6 +69,7 @@ pub fn find_packet(buffer: &[u8]) -> Result<PacketBounds> {
pub struct SerialInterface {
interface: Box<dyn tokio_serial::SerialPort>,
buffer: Vec<u8>,
mute_available_bytes_debug_message: bool,
}
impl SerialInterface {
@@ -79,6 +80,7 @@ impl SerialInterface {
return Ok(Self {
interface: interface,
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")?
.try_into()?;
debug!("Available bytes to read: {}", available_bytes);
let mut buffer: Vec<u8> = vec![0; available_bytes];
if buffer.len() <= 0 {
debug!("No bytes available to read");
if available_bytes <= 0 && self.mute_available_bytes_debug_message {
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)
.context("Failed to read bytes from serial device")?;