eculocate

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README

commit b85f71c43ccc1429e0cab77d642b47319c0a6552
parent 95ab2abaf4220c492895ef65499bacbd87bc6919
Author: Daniel Barlow <dan@telent.net>
Date:   Sat, 22 Nov 2025 17:55:28 +0000

add ecu.fetch_table() method

Diffstat:
Msrc/ecu.rs | 36++++++++++++++++++------------------
Msrc/main.rs | 5+++--
2 files changed, 21 insertions(+), 20 deletions(-)

diff --git a/src/ecu.rs b/src/ecu.rs @@ -90,8 +90,7 @@ impl Ecu<'_> { } } - pub async fn run_command(&mut self, _command: Command) { - let mut buf = [0u8; 80]; + async fn run_command<'a>(&mut self, command: &mut [u8], buf: &'a mut [u8]) -> &'a [u8] { let need_init = !self.is_initialized(); if need_init { @@ -125,21 +124,28 @@ impl Ecu<'_> { let handshake = Self::chat(&mut uart, &mut [0x72, 0x05, 0x00, 0xF0, 0x99], - &mut buf).await; + buf).await; info!("matches {}", handshake == b"\x02\x04\x00\xfa"); self.initialized_at = Some(Instant::now()); } - for i in [0] { - let table = Self::chat(&mut uart, - &mut [0x72, 0x07, 0x72, i, 0, 0x14, 0x0], - &mut buf).await; - if table.len() > 6 { - for b in &table[5..] { - info!("table {} {:x?}", i, b); - } + + Self::chat(&mut uart, command, buf).await + } + + pub async fn fetch_table<'a>(&mut self, n: u8, buf: &'a mut [u8]) -> &'a [u8] { + let r = self.run_command(&mut [0x72, 0x07, 0x72, n, 0, 0x14, 0x0], buf).await; + &r[5..] + } + + pub async fn do_stuff(&mut self) { + let mut buf = [0u8; 80]; + + let table = self.fetch_table(0x11, &mut buf).await; + if table.len() > 0 { + for b in table { + info!("table {} {:x?}", 0x11, b); } } - // reply for table 11 query // 2 - dest // 1a - (26) chars in message @@ -166,11 +172,5 @@ impl Ecu<'_> { // 5a - ctx-obd says 1a // 37 - ctx-obd says 51 // 92 - checksum - - - - } - - // } diff --git a/src/main.rs b/src/main.rs @@ -34,7 +34,7 @@ async fn main(_s : Spawner) { esp_println::logger::init_logger_from_env(); let config = esp_hal::Config::default().with_cpu_clock(CpuClock::max()); - let mut peripherals = esp_hal::init(config); + let peripherals = esp_hal::init(config); esp_alloc::heap_allocator!(#[esp_hal::ram(reclaimed)] size: 66320); @@ -58,7 +58,8 @@ async fn main(_s : Spawner) { let _ = join( wibble::run_ble(peripherals.BT), async { - ecu.run_command(ecu::Command::Nop).await; + info!("first"); + ecu.do_stuff().await; loop { } } ).await;