summaryrefslogtreecommitdiff
path: root/src/main.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/main.rs')
-rw-r--r--src/main.rs28
1 files changed, 26 insertions, 2 deletions
diff --git a/src/main.rs b/src/main.rs
index 915ded6..43198e1 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -24,6 +24,12 @@ use std::env::args;
use futures::sync::mpsc;
use tokio::timer::Interval;
use std::time::{Duration, Instant};
+use std::sync::Mutex;
+use std::collections::HashMap;
+use std::collections::hash_map::Entry;
+use std::vec::Vec;
+
+use types::Value;
fn packet_print(id: u16, bytes: &[u8]) -> String {
let mut ret: String = String::new();
@@ -87,17 +93,35 @@ fn main() {
}))
}));
+ let mut current: Mutex<HashMap<String, Value>> = Mutex::new(HashMap::new());
+
tokio::spawn(
stream
.map_err(|e| error!("error = {:?}", e))
.for_each(move |frame| {
- info!(
+ trace!(
"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));
+ if let Some(decoded) = ecu.decode(&frame.1) {
+ trace!("Decoded: {:?}", decoded);
+ let curmap = current.get_mut().unwrap();
+ for entry in decoded {
+ let name = entry.get_name().to_owned();
+ let value = entry.get_value().unwrap();
+ match curmap.entry(name.clone()) {
+ Entry::Occupied(o) => if value != *o.get() {
+ info!("{} changed {:?} -> {:?}", name, o.get(), value);
+ },
+ Entry::Vacant(v) => {
+ info!("{} changed None -> {:?}", name, value);
+ }
+ };
+ curmap.insert(name, value);
+ }
+ }
}
Ok(())