commit 5a0435f5eb977f62960eea662c9f0e3c3748b879
parent cf1f5dcde34b7e85505a2bdd0e9bd0b77d0e68a2
Author: Daniel Barlow <dan@telent.net>
Date: Fri, 21 Nov 2025 23:55:56 +0000
use length byte in header of received message
Diffstat:
| M | src/ecu.rs | | | 70 | +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++------- |
1 file changed, 63 insertions(+), 7 deletions(-)
diff --git a/src/ecu.rs b/src/ecu.rs
@@ -7,6 +7,9 @@ use esp_hal::{
use embassy_time::Timer;
use log::{info};
+// implement iterator
+// https://doc.rust-lang.org/std/iter/index.html#implementing-iterator
+
pub enum Command { Nop }
pub struct Ecu<'a> {
@@ -60,13 +63,21 @@ impl Ecu<'_> {
received += bytes;
// info!("discard {bytes} {received} of {discard_count}");
}
- received = 0;
- while received < receive.len() {
- let bytes = uart.read_async(&mut receive[received..]).await.expect("read failed");
- received += bytes;
- // info!("read {bytes} {received} of {}", receive.len());
+
+ if receive.len() > 0 {
+ let _ = uart.read_async(&mut receive[0..2]).await.expect("read failed");
+ let expected = receive[1].into();
+
+ received = 2;
+ while received < expected {
+ let bytes = uart.read_async(&mut receive[received..]).await.expect("read failed");
+ received += bytes;
+ info!("read {bytes} {received} of {}", receive.len());
+ }
+ &receive[0..expected]
+ } else {
+ &[]
}
- receive
}
pub async fn run_command(&mut self, _command: Command) {
@@ -101,8 +112,53 @@ impl Ecu<'_> {
// checksum is also correct on this packet
let handshake = Self::chat(&mut uart,
&mut [0x72, 0x05, 0x00, 0xF0, 0x99],
- &mut buf[0..4]).await;
+ &mut buf).await;
info!("matches {}", handshake == b"\x02\x04\x00\xfa");
+
+ let table_11 = Self::chat(&mut uart,
+ &mut [0x72, 0x07, 0x72, 0x11, 0, 0x14, 0xF0],
+ &mut buf).await;
+ for b in table_11 {
+ info!("table {:x?}", b);
+ }
+
+ // next steps:
+ // - use reply length byte to get whole packet
+ // - implement checksum algo
+ // - try some other tables
+
+ // checksum is (0x100 - (sum of bytes in message, mod 0x100))
+
+
+ // 2 - dest
+ // 1a - (26) chars in message
+ // 72 - query type
+ // 11 - table mumber
+ // 0 - offset
+ // ** table starts here
+ // 0 0 - rpm
+ // 6 - tps volt * 5/256
+ // 0 - tps %
+ // ff - ect volt * 5/256
+ // a - ect deg c
+ // ff - iat volt * 5/256
+ // a - iat deg c
+ // f1 - map volt
+ // a8 - map kPa
+ // ff
+ // ff
+ // 7c - battery voltage (0.1v) = 12.4
+ // 0 - speed
+ // 0 0 - fuel inj (?)
+ // 80 - ctx-obd says (?) and = 80
+ // 93 - ctx-obd says 63
+ // 5a - ctx-obd says 1a
+ // 37 - ctx-obd says 51
+ // 92 - checksum
+
+
+
+
}
//