handle robot disconnection
This commit is contained in:
parent
38ca539af8
commit
a8bfb8cd8a
1 changed files with 5 additions and 2 deletions
|
@ -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()?;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue