From ceb542342065a76fe6651a2be2c12d6985e740b5 Mon Sep 17 00:00:00 2001 From: hodasemi Date: Thu, 21 Jul 2022 09:36:38 +0200 Subject: [PATCH] Fix out of bounds access + add debug msg --- src/service.rs | 8 ++++++-- src/service_specific/port.rs | 7 +++++++ 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/src/service.rs b/src/service.rs index 2c15214..8aa1790 100644 --- a/src/service.rs +++ b/src/service.rs @@ -8,6 +8,8 @@ use service_specific::*; use shared::config::{Config, COMMAND_COUNT, COMMAND_PAUSE}; fn main() -> Result<()> { + println!("startup macroboard service"); + // azdelivery usart device // let usb_device = UsbId { // vendor_id: 0x0403, @@ -37,6 +39,8 @@ fn main() -> Result<()> { let mut button_infos = [Duration::default(); COMMAND_COUNT]; let start_time = Instant::now(); + println!("service is now listening ..."); + // loop forever loop { // handle incoming message @@ -77,8 +81,8 @@ fn execute_button_press( } // check that this commands last execution is longer than COMMAND_PAUSE ago - if (button_infos[button_id] + COMMAND_PAUSE) < time { - button_infos[button_id] = time; + if (button_infos[button_id - 1] + COMMAND_PAUSE) < time { + button_infos[button_id - 1] = time; } else { return Ok(()); } diff --git a/src/service_specific/port.rs b/src/service_specific/port.rs index 4a43f7c..57cf981 100644 --- a/src/service_specific/port.rs +++ b/src/service_specific/port.rs @@ -32,6 +32,8 @@ impl Port { pub fn open(usb_device: UsbId, settings: SerialPortSettings) -> Result { let port_path = Self::loop_usb_devices(usb_device)?; + println!("found device at path {}", port_path); + let port = serialport::new(port_path, settings.baud_rate) .data_bits(settings.data_bits) .parity(settings.parity) @@ -72,6 +74,11 @@ impl Port { return Ok(device); } + println!( + "no device found with {}:{}", + usb_device.vendor_id, usb_device.product_id + ); + std::thread::sleep(Duration::from_secs(2)); } }