summaryrefslogtreecommitdiff
path: root/src/main.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/main.rs')
-rw-r--r--src/main.rs31
1 files changed, 10 insertions, 21 deletions
diff --git a/src/main.rs b/src/main.rs
index 9c79ffc..0548678 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -1,46 +1,35 @@
extern crate futures;
extern crate mio;
extern crate socketcan;
-extern crate time;
extern crate tokio;
+#[macro_use]
+extern crate log;
+extern crate env_logger;
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() {
+ env_logger::init();
+
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))
+ .map_err(|e| error!("error = {:?}", e))
.for_each(move |frame| {
- process_frame(&frame);
+ info!("Received CAN frame: {:X}", frame);
match mytp.handle_frame(&frame) {
- None => println!("Nothing TPish"),
+ None => {}
Some((id, data)) => {
- println!("Received from {:03x} data {:?}", id, data);
+ info!("Received from {:03x} data {:?}", id, data);
}
}
while let Some(packet) = mytp.get_outgoing() {
- println!("What's more, sending {:?}", packet);
+ info!(" Sending CAN frame: {:X}", packet);
waiter.send(packet).map_err(|_| ())?;
waiter.flush().map_err(|_| ())?;
}