summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Silverstone <dsilvers@digital-scurf.org>2018-04-12 21:17:23 +0100
committerDaniel Silverstone <dsilvers@digital-scurf.org>2018-04-12 21:17:23 +0100
commitc07e7db28949d2e72d64bd88add30ea14da46e99 (patch)
tree679485845c47d7e5a978675e0891577e060a48a5
parent3954dd3ff48a3d82913506757917cb263616e3cc (diff)
downloadcanopied-c07e7db28949d2e72d64bd88add30ea14da46e99.tar.bz2
Support cadence on Raw ECUs
-rw-r--r--src/definitions.rs36
1 files changed, 35 insertions, 1 deletions
diff --git a/src/definitions.rs b/src/definitions.rs
index f4eb74e..3cecccb 100644
--- a/src/definitions.rs
+++ b/src/definitions.rs
@@ -51,6 +51,7 @@ pub struct RawECUResponse {
pub struct RawECUEntry {
name: String,
description: String,
+ cadence: usize,
request: RawECURequest,
response: RawECUResponse,
}
@@ -98,6 +99,10 @@ impl RawECUEntry {
&self.request
}
+ pub fn cadence(&self) -> usize {
+ self.cadence
+ }
+
pub fn decode(&self, payload: &[u8]) -> Option<Vec<NamedValue>> {
trace!("Decoding for {} ({})", self.name(), self.description());
let mut ret = Vec::new();
@@ -176,10 +181,39 @@ impl RawECUEntry {
n.push_str(&format!(".unused_{}", i));
n
};
- ret.push(NamedValue::new(&name, Some(Value::from(payload[i]))));
+ ret.push(NamedValue::new(&name, Some(Value::from_raw(payload[i]))));
}
}
Some(ret)
}
}
+
+pub struct CadencedECUs {
+ count: usize,
+ ecu: usize,
+}
+
+impl CadencedECUs {
+ pub fn new() -> CadencedECUs {
+ CadencedECUs { count: 0, ecu: 0 }
+ }
+}
+
+impl Iterator for CadencedECUs {
+ type Item = &'static RawECUEntry;
+ fn next(&mut self) -> Option<Self::Item> {
+ let ecus = RawECUEntry::get_all();
+ loop {
+ if self.ecu == ecus.len() {
+ self.ecu = 0;
+ self.count += 1
+ }
+ let ecu = &ecus[self.ecu];
+ self.ecu += 1;
+ if (self.count % ecu.cadence()) == 0 {
+ return Some(ecu);
+ }
+ }
+ }
+}