summaryrefslogtreecommitdiff
path: root/src/main.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/main.rs')
-rw-r--r--src/main.rs35
1 files changed, 32 insertions, 3 deletions
diff --git a/src/main.rs b/src/main.rs
index a0a4b7c..2b3b7db 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -11,6 +11,10 @@ extern crate serde;
extern crate serde_derive;
extern crate serde_yaml;
+#[macro_use]
+extern crate lazy_static;
+
+mod types;
mod canstream;
mod isotp;
mod definitions;
@@ -21,10 +25,27 @@ use futures::sync::mpsc;
use tokio::timer::Delay;
use std::time::{Duration, Instant};
+fn packet_print(id: u16, bytes: &[u8]) -> String {
+ let mut ret: String = String::new();
+
+ ret.push_str(&format!(
+ "{:03X}/{:03X} (len={:2})",
+ id - 8,
+ id,
+ bytes.len()
+ ));
+
+ for b in bytes {
+ ret.push_str(&format!(" {:02X}", b));
+ }
+
+ ret
+}
+
fn main() {
env_logger::init();
- let raw_defs = definitions::RawECUEntry::get();
+ let raw_defs = definitions::RawECUEntry::get_all();
info!("Read {} raw ecu entries", raw_defs.len());
@@ -52,7 +73,8 @@ fn main() {
);
let mut counter = 1;
- for def in &raw_defs {
+ for def in raw_defs {
+ break;
let req = def.request();
let dest = req.sendto();
let packet = req.packet().to_vec();
@@ -80,7 +102,14 @@ fn main() {
stream
.map_err(|e| error!("error = {:?}", e))
.for_each(move |frame| {
- info!("Received ISO-TP frame: {:?}", frame);
+ info!(
+ "Received ISO-TP packet: {}",
+ packet_print(frame.0, &frame.1)
+ );
+ let ecu = definitions::RawECUEntry::ecu_for(frame.0, &frame.1);
+ if let Some(ecu) = ecu {
+ info!("Decoded: {:?}", ecu.decode(&frame.1));
+ }
Ok(())
}),