Add context for serial device exceptions

This commit is contained in:
clerie 2024-12-25 17:38:21 +01:00
parent 9b15774114
commit 1700bf5531

View File

@ -47,7 +47,7 @@ pub struct SerialInterface {
impl SerialInterface { impl SerialInterface {
pub fn new(path: &str, baud_rate: u32) -> Result<Self> { pub fn new(path: &str, baud_rate: u32) -> Result<Self> {
let interface = tokio_serial::new(path, baud_rate).open().unwrap(); let interface = tokio_serial::new(path, baud_rate).open().context("Failed to open serial device")?;
return Ok(Self { return Ok(Self {
interface: interface, interface: interface,
@ -84,7 +84,7 @@ impl SerialInterface {
debug!("Received bytes: \n{}\n{}", hex::encode(&buffer), to_ascii_debug(&buffer)); debug!("Received bytes: \n{}\n{}", hex::encode(&buffer), to_ascii_debug(&buffer));
} }
let improv_packet_offset = find_begin_of_improv_packet(&buffer).unwrap(); let improv_packet_offset = find_begin_of_improv_packet(&buffer).context("Failed to find improv header in received bytes from serial device")?;
let improv_packet_end = improv_packet_offset + 10 + <u8 as Into<usize>>::into(buffer[improv_packet_offset+8]); let improv_packet_end = improv_packet_offset + 10 + <u8 as Into<usize>>::into(buffer[improv_packet_offset+8]);