extern crate futures; extern crate mio; extern crate socketcan; extern crate time; extern crate tokio; mod canstream; mod isotp; use tokio::prelude::*; fn process_frame(frame: &socketcan::CANFrame) { let ts = time::now_utc().to_timespec(); print!( "({}.{:06}) {} {:03x}#", ts.sec, ts.nsec / 1000, "vcan0", frame.id() ); for byte in frame.data().iter() { print!("{:02x}", byte); } println!(""); } fn main() { let (sink, stream) = canstream::CANStream::from_name("vcan0").unwrap().split(); let mut waiter = sink.wait(); let mut mytp = isotp::ISOTP::new(); tokio::run( stream .map_err(|e| println!("error = {:?}", e)) .for_each(move |frame| { process_frame(&frame); match mytp.handle_frame(&frame) { None => println!("Nothing TPish"), Some((id, data)) => { println!("Received from {:03x} data {:?}", id, data); } } while let Some(packet) = mytp.get_outgoing() { println!("What's more, sending {:?}", packet); waiter.send(packet).map_err(|_| ())?; waiter.flush().map_err(|_| ())?; } Ok(()) }), ); }