rearrange as workspace of crates

I would rather like to be able to write tests for the complicated
bits, but using "cargo test" with the esp32 tolchain/libraries
is beyond my skill level if it's even possible.  Hence we now have
an ecu-portable crate for stuff that can be built using plain old Rust
(e.g. x86_64 with std)  and an ecu-esp32 crate for the rest of it
This commit is contained in:
2025-12-23 16:51:10 +00:00
parent 35c7d34b8d
commit ae0393cd48
12 changed files with 168 additions and 88 deletions
Generated
+6 -1
View File
@@ -290,12 +290,13 @@ dependencies = [
]
[[package]]
name = "eculogical"
name = "ecu-esp32"
version = "0.1.0"
dependencies = [
"bleps",
"bt-hci",
"dns-protocol",
"ecu_portable",
"embassy-executor",
"embassy-futures",
"embassy-net",
@@ -316,6 +317,10 @@ dependencies = [
"trouble-host",
]
[[package]]
name = "ecu_portable"
version = "0.1.0"
[[package]]
name = "embassy-embedded-hal"
version = "0.5.0"
+3 -87
View File
@@ -1,87 +1,3 @@
[package]
edition = "2024"
name = "eculogical"
rust-version = "1.88"
version = "0.1.0"
[dependencies]
esp-hal = { version = "1.0.0", features = ["esp32c3", "log-04", "unstable"] }
esp-rtos = { version = "0.2.0", features = [
"esp-alloc",
"esp-radio",
"esp32c3",
"log-04",
"embassy",
] }
esp-bootloader-esp-idf = { version = "0.4.0", features = ["esp32c3", "log-04"] }
log = "0.4.27"
bleps = { git = "https://github.com/bjoernQ/bleps", package = "bleps", rev = "a5148d8ae679e021b78f53fd33afb8bb35d0b62e", features = [
"async",
"macros",
] }
esp-alloc = "0.9.0"
bt-hci = { version = "0.6.0" }
embassy-executor = { version = "0.9.1", features = [] }
embassy-time = { version = "0.5.0", features = [] }
embedded-io = { version = "0.7.1", features = [] }
embedded-io-async = { version = "0.7.0", features = [] }
esp-backtrace = { version = "0.18.1", features = [
"esp32c3",
"panic-handler",
"println",
] }
esp-println = { version = "0.16.1", features = ["esp32c3", "log-04"] }
esp-radio = { version = "0.17.0", features = [
"ble",
"esp-alloc",
"esp32c3",
"log-04",
"unstable",
"wifi",
"smoltcp"
] }
smoltcp = { version = "0.12.0", default-features = false, features = [
"medium-ethernet",
"socket-raw",
"proto-dhcpv4",
"proto-ipv4"
] }
embassy-futures = "0.1.1"
embassy-sync = { version = "0.7" }
static_cell = "2"
trouble-host = { version = "0.5.0", features = [
"peripheral", "gatt", "default-packet-pool-mtu-255",
"derive", "scan",
] }
embassy-net = { version = "0.7.1", features = [
"medium-ethernet", "proto-ipv4", "tcp", "dhcpv4", "udp",
"dns", "mdns", "multicast"
] }
dns-protocol = { version = "0.1.2", default-features = false, features = [
# no "std" feature
] }
[profile.dev]
# Rust debug is too slow.
# For debug builds always builds with some optimization
opt-level = "s"
[profile.release]
codegen-units = 1 # LLVM can perform better optimizations using a single thread
debug = 2
debug-assertions = false
incremental = false
lto = 'fat'
opt-level = 's'
overflow-checks = false
[workspace]
resolver = "3"
members = ["ecu-esp32", "ecu-portable"]
+89
View File
@@ -0,0 +1,89 @@
[package]
edition = "2024"
name = "ecu-esp32"
rust-version = "1.88"
version = "0.1.0"
[dependencies]
ecu_portable = { path = "../ecu-portable" }
esp-hal = { version = "1.0.0", features = ["esp32c3", "log-04", "unstable"] }
esp-rtos = { version = "0.2.0", features = [
"esp-alloc",
"esp-radio",
"esp32c3",
"log-04",
"embassy",
] }
esp-bootloader-esp-idf = { version = "0.4.0", features = ["esp32c3", "log-04"] }
log = "0.4.27"
bleps = { git = "https://github.com/bjoernQ/bleps", package = "bleps", rev = "a5148d8ae679e021b78f53fd33afb8bb35d0b62e", features = [
"async",
"macros",
] }
esp-alloc = "0.9.0"
bt-hci = { version = "0.6.0" }
embassy-executor = { version = "0.9.1", features = [] }
embassy-time = { version = "0.5.0", features = [] }
embedded-io = { version = "0.7.1", features = [] }
embedded-io-async = { version = "0.7.0", features = [] }
esp-backtrace = { version = "0.18.1", features = [
"esp32c3",
"panic-handler",
"println",
] }
esp-println = { version = "0.16.1", features = ["esp32c3", "log-04"] }
esp-radio = { version = "0.17.0", features = [
"ble",
"esp-alloc",
"esp32c3",
"log-04",
"unstable",
"wifi",
"smoltcp"
] }
smoltcp = { version = "0.12.0", default-features = false, features = [
"medium-ethernet",
"socket-raw",
"proto-dhcpv4",
"proto-ipv4"
] }
embassy-futures = "0.1.1"
embassy-sync = { version = "0.7" }
static_cell = "2"
trouble-host = { version = "0.5.0", features = [
"peripheral", "gatt", "default-packet-pool-mtu-255",
"derive", "scan",
] }
embassy-net = { version = "0.7.1", features = [
"medium-ethernet", "proto-ipv4", "tcp", "dhcpv4", "udp",
"dns", "mdns", "multicast"
] }
dns-protocol = { version = "0.1.2", default-features = false, features = [
# no "std" feature
] }
[profile.dev]
# Rust debug is too slow.
# For debug builds always builds with some optimization
opt-level = "s"
[profile.release]
codegen-units = 1 # LLVM can perform better optimizations using a single thread
debug = 2
debug-assertions = false
incremental = false
lto = 'fat'
opt-level = 's'
overflow-checks = false
View File
View File
+10
View File
@@ -32,6 +32,8 @@ use esp_radio::{
},
};
use log::info;
use dns_protocol::{Message, Question,
MessageType,
@@ -73,6 +75,14 @@ async fn send_advert(sock: &UdpSocket<'_>,
None => &mut [][..]
};
let mut buf : [u8; 32] = [0; 32];
info!("ptr data bytes: {:?}",
ecu_portable::ptr_data(
&["myname", "_keihin", "_udp"],
&mut buf)
);
// FIXME for legacy unicast response max ttl is 10s
let mut answer = [
+6
View File
@@ -0,0 +1,6 @@
[package]
name = "ecu_portable"
version = "0.1.0"
edition = "2024"
[dependencies]
+41
View File
@@ -0,0 +1,41 @@
#![no_std]
use core::iter::Iterator;
pub fn ptr_data<'b>(labels : &[&str], buf : &'b mut[u8]) -> &'b mut [u8] {
let mut offset = 0;
for l in labels.iter() {
buf[offset] = l.len() as u8;
for (i, &item) in l.as_bytes().iter().enumerate() {
buf[offset + 1 + i] = item;
}
offset = offset + l.len() + 1;
}
&mut buf[..offset]
}
#[cfg(test)]
mod tests {
extern crate std;
use super::*;
#[test]
fn test_ptr_data() {
let mut buf : [u8; 32] = [0; 32];
assert_eq!(ptr_data(&["hello"], &mut buf),
[5, 104, 101, 108, 108, 111]);
assert_eq!(ptr_data(&[], &mut buf),
[]);
assert_eq!(ptr_data(&["hello", "world"], &mut buf),
[5, 104, 101, 108, 108, 111,
5, 119, 111, 114, 108, 100]);
assert_eq!(ptr_data(&["hello", "cool", "world"], &mut buf),
[5, 104, 101, 108, 108, 111,
4, 99, 111, 111, 108,
5, 119, 111, 114, 108, 100]);
}
}
+13
View File
@@ -1,3 +1,16 @@
# Building
The repo is split into two crates in a cargo workspace: code in
ecu-portable can be built and run using the native compiler, hence is
unit-testable, and code in ecu-esp32 depends on all the esp32 gubbins
so you can test it only by running it.
```
cargo test -p ecu-portable --target x86_64-unknown-linux-gnu
SSID=my-wifi PASSWORD="my-wifi-password" cargo run --release
```
# Resources
https://github.com/aeaphichart/HondaECU-1