From 4860131bc4c19ea1a047adfa70f22d6435229e19 Mon Sep 17 00:00:00 2001
From: Federico Lolli <federico.lolli@skywarder.eu>
Date: Thu, 11 Jul 2024 11:29:25 +0200
Subject: [PATCH] [on-host] Fixed too many useless warnings

---
 on-host/src/main.rs | 11 ++++++++---
 1 file changed, 8 insertions(+), 3 deletions(-)

diff --git a/on-host/src/main.rs b/on-host/src/main.rs
index 0e7b663..74caf98 100644
--- a/on-host/src/main.rs
+++ b/on-host/src/main.rs
@@ -12,7 +12,7 @@ use std::{
 };
 
 use clap::Parser;
-use log::{debug, error, info, warn};
+use log::{debug, error, info};
 use miette::{Context, IntoDiagnostic, Result};
 use serialport::SerialPort;
 use skyward_mavlink::{
@@ -140,6 +140,7 @@ fn get_packets(args: &Cli) -> Result<Vec<MavMessage>> {
 /// Wait for ACK signal from the device
 fn wait_for_ack(port: &mut Box<dyn SerialPort>, buffer: &mut [u8]) {
     // wait ACK
+    let start = Instant::now();
     loop {
         match port.read(buffer) {
             Ok(t) => {
@@ -148,11 +149,15 @@ fn wait_for_ack(port: &mut Box<dyn SerialPort>, buffer: &mut [u8]) {
                 if buffer[..t].contains(&ACK) {
                     break;
                 } else {
-                    warn!("didn't get the signal");
                     std::thread::sleep(Duration::from_millis(10));
                 }
             }
-            Err(ref e) if e.kind() == io::ErrorKind::TimedOut => (),
+            Err(ref e) if e.kind() == io::ErrorKind::TimedOut => {
+                if start.elapsed() > Duration::from_secs(5) {
+                    error!("FATAL: didn't get the signal");
+                    std::process::exit(1);
+                }
+            }
             Err(e) => {
                 error!("FATAL: {:?}", e);
                 std::process::exit(1);
-- 
GitLab