eculocate

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

commit 2b96e079bc872e221361b5a9513b4f7ccfd5d973
parent e7f0f62f43e11647054429d30e4e2e41164c8bd3
Author: Daniel Barlow <dan@telent.net>
Date:   Fri, 21 Nov 2025 19:53:45 +0000

chat returns slice reference to received bytes

Diffstat:
Msrc/ecu.rs | 18+++++++++++-------
1 file changed, 11 insertions(+), 7 deletions(-)

diff --git a/src/ecu.rs b/src/ecu.rs @@ -28,15 +28,19 @@ impl Ecu<'_> { } } - async fn chat(uart: &mut Uart<'_, Async>, + async fn chat<'z>(uart: &mut Uart<'_, Async>, send: &[u8], - receive: &mut [u8]) -> usize { + receive: &'z mut [u8]) -> &'z [u8] { uart.write(send).expect("write failed"); let _ = uart.flush(); let mut received = 0; let mut buf = [0u8; 80]; let discard_count = send.len(); + if send.len() > buf.len() { + panic!("send string limited to {} or fewer bytes", buf.len()); + } + while received < send.len() { let bytes = uart.read_async(&mut buf[..discard_count]).await.expect("read failed"); received += bytes; @@ -48,7 +52,7 @@ impl Ecu<'_> { received += bytes; // info!("read {bytes} {received} of {}", receive.len()); } - received + receive } pub async fn run_command(&mut self, _command: Command) { @@ -76,9 +80,9 @@ impl Ecu<'_> { let mut buf = [0u8; 80]; let _ = Self::chat(&mut uart, b"\xfe\x04\xff\xff", &mut buf[0..0]).await; Timer::after_millis(200).await; - let _ = Self::chat(&mut uart, b"\x72\x05\x00\xF0\x99", &mut buf[0..4]).await; - for b in &buf[0..4] { - info!("byte {}", b); - } + let handshake = Self::chat(&mut uart, b"\x72\x05\x00\xF0\x99", &mut buf[0..4]).await; + info!("matches {}", handshake == b"\x02\x04\x00\xfa"); } + + // }