summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Silverstone <dsilvers@digital-scurf.org>2018-04-10 23:19:15 +0100
committerDaniel Silverstone <dsilvers@digital-scurf.org>2018-04-10 23:19:15 +0100
commite57cebf54de16c2c9cb0375cde46d31baea46c66 (patch)
treedaf5199db6ac30d0e6289f4c1542faed3061abfe
parent8b0a5c31939d8328e63bf5639db7114effcb8a93 (diff)
downloadcanopied-e57cebf54de16c2c9cb0375cde46d31baea46c66.tar.bz2
Make it report the changes in data rather than the raw data
-rw-r--r--src/main.rs28
-rw-r--r--src/types.rs6
2 files changed, 31 insertions, 3 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(())
diff --git a/src/types.rs b/src/types.rs
index 6b0aacd..f815b16 100644
--- a/src/types.rs
+++ b/src/types.rs
@@ -1,4 +1,4 @@
-#[derive(Copy, Clone, Debug)]
+#[derive(Copy, Clone, Debug, PartialEq)]
pub enum Value {
Boolean(bool),
Unsigned(u32),
@@ -83,6 +83,10 @@ impl NamedValue {
}
}
+ pub fn get_name(&self) -> &str {
+ self.name.as_ref()
+ }
+
pub fn get_value(&self) -> Option<Value> {
self.value
}