-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathlocal_serial.rs
42 lines (40 loc) · 1.34 KB
/
local_serial.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
use std::time::Duration;
use std::{env, io};
fn main() {
let path = env::args().nth(1).expect("no serial port supplied");
let mut port = serialport::new(path, 115_200)
.timeout(Duration::from_millis(20))
.open()
.expect("failed to open serial port");
let mut buf = [0; 1024];
let mut parser = crsf::Parser::new(crsf::ParserConfig::default());
loop {
match port.read(buf.as_mut_slice()) {
Ok(n @ 1..) => {
for result in parser.iter_packets(&buf[..n]) {
match result {
Ok(crsf::Packet::LinkStatistics(link_stats)) => {
println!("{:?}", link_stats);
}
Ok(crsf::Packet::RcChannelsPacked(rc_channels)) => {
println!("{:?}", rc_channels);
}
Err(err) => {
println!("err: {:?}", err);
}
_ => {}
}
}
}
Ok(0) => {
eprintln!("EOF");
break;
}
Err(ref e) if e.kind() == io::ErrorKind::TimedOut => (),
Err(e) => {
eprintln!("{}", e);
break;
}
}
}
}