Skip to content
Snippets Groups Projects
Commit 20076359 authored by Federico Lolli's avatar Federico Lolli
Browse files

moved to a EOT ASCII byte as signal

parent e91d5068
No related merge requests found
......@@ -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());
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment