From 20076359b865a6931e009bfd8b42f695491799a3 Mon Sep 17 00:00:00 2001
From: Federico Lolli <federico.lolli@skywarder.eu>
Date: Mon, 22 Jan 2024 10:24:10 +0100
Subject: [PATCH] moved to a EOT ASCII byte as signal

---
 src/main.rs | 19 +++++++++++++------
 1 file changed, 13 insertions(+), 6 deletions(-)

diff --git a/src/main.rs b/src/main.rs
index 077f1b5..9f2359c 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -7,6 +7,8 @@ use std::time::Instant;
 use ffi::MavlinkPayloadFlightTM;
 use serialport::SerialPort;
 
+const EOT: u8 = 0x04;
+
 trait MavLinkPort {
     fn write_packet(&mut self, packet: MavlinkPayloadFlightTM);
 }
@@ -52,19 +54,24 @@ fn main() {
 
     // read from buffer and print to stdout
     let mut buffer = [0u8; 1000];
-    let mut buffered_string = String::new();
     let mut start: Option<Instant> = None;
     let mut times = Vec::new();
     let mut i = 0;
     loop {
         match port.read(&mut buffer) {
             Ok(t) => {
-                // encode the buffer into a string
-                let input = String::from_utf8_lossy(&buffer[..t]);
+                // check if we got the signal to start sending data
+                let eot_f = buffer[..t].contains(&EOT);
+
+                // encode the buffer into a string (remove the EOT character)
+                let input = if eot_f {
+                    String::from_utf8_lossy(&buffer[..t - 1])
+                } else {
+                    String::from_utf8_lossy(&buffer[..t])
+                };
+
                 // if we got the signal to start sending data, send it
-                buffered_string.push_str(&input);
-                if buffered_string.contains("[WAITING]") {
-                    buffered_string.clear();
+                if eot_f {
                     if let Some(packet) = iter.next() {
                         if let Some(t) = start {
                             times.push(t.elapsed().as_millis());
-- 
GitLab