1
Fork 0

handle robot disconnection

This commit is contained in:
Andy Killorin 2025-07-20 20:58:45 -05:00
parent 38ca539af8
commit a8bfb8cd8a
Signed by: ank
GPG key ID: 23F9463ECB67FE8C

View file

@ -32,7 +32,10 @@ fn main() {
loop {
let command = command.lock().unwrap().clone();
let encoded: Vec<u8, 20> = to_vec_cobs(&command).unwrap();
port.write(&encoded).expect("port write fail");
if port.write(&encoded).is_err() {
println!("disconnected from robot");
return;
};
sleep(Duration::from_millis(200));
}
@ -94,7 +97,7 @@ fn handle_connection(command: Arc<Mutex<Command>>, telemetry: Arc<Mutex<Telemetr
println!("sent d{}", telem.distance);
serde_json::to_writer(&mut writer, &telem).unwrap();
writer.write(&[b'\r',b'\n'])?;
writer.write_all(b"\r\n")?;
writer.flush()?;
}
}