stop robot on disconnect
This commit is contained in:
parent
09c1fe5982
commit
38ca539af8
1 changed files with 9 additions and 1 deletions
|
@ -1,4 +1,4 @@
|
|||
use std::{f32::NAN, io::{BufRead, BufReader, BufWriter, Read, Write}, net::TcpListener, sync::{Arc, Mutex}, thread::sleep, time::Duration};
|
||||
use std::{io::{BufRead, BufReader, BufWriter, Read, Write}, net::TcpListener, sync::{Arc, Mutex}, thread::sleep, time::Duration};
|
||||
|
||||
use common::{Command, Telemetry};
|
||||
use postcard::to_vec_cobs;
|
||||
|
@ -73,6 +73,14 @@ fn handle_connection(command: Arc<Mutex<Command>>, telemetry: Arc<Mutex<Telemetr
|
|||
let mut data_buf = std::vec::Vec::new();
|
||||
let len = reader.read_until(b'\n', &mut data_buf)?;
|
||||
|
||||
// eof
|
||||
if len == 0 {
|
||||
*command.lock().unwrap() = Command::default(); // stop motors
|
||||
println!("disconnected from LabVIEW");
|
||||
return anyhow::Ok(());
|
||||
}
|
||||
|
||||
|
||||
let Ok(new_command) = serde_json::from_slice::<Command>(&data_buf[0..len]) else {continue;};
|
||||
|
||||
*command.lock().unwrap() = new_command.clone();
|
||||
|
|
Loading…
Reference in a new issue