diff --git a/Cargo.lock b/Cargo.lock index ab58dc3..359840b 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -763,6 +763,16 @@ version = "1.0.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "877a4ace8713b0bcf2a4e7eec82529c029f1d0619886d18145fea96c3ffe5c0f" +[[package]] +name = "errno" +version = "0.3.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "39cab71617ae0d63f51a36d69f866391735b51691dbda63cf6f96d042b63efeb" +dependencies = [ + "libc", + "windows-sys", +] + [[package]] name = "esp-alloc" version = "0.10.0" @@ -1160,6 +1170,8 @@ dependencies = [ "mipidsi", "num-traits", "profont", + "prost", + "prost-build", ] [[package]] @@ -1234,12 +1246,24 @@ dependencies = [ "arrayvec", ] +[[package]] +name = "fastrand" +version = "2.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "da7c62ceae207dd37ea5b845da6a0696c799f85e97da1ab5b7910be3c1c80223" + [[package]] name = "find-msvc-tools" version = "0.1.9" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5baebc0774151f905a1a2cc41989300b1e6fbb29aff0ceffa1064fdd3088d582" +[[package]] +name = "fixedbitset" +version = "0.5.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1d674e81391d1e1ab681a28d99df07927c6d4aa5b027d7da16ba32d1d21ecd99" + [[package]] name = "float-cmp" version = "0.9.0" @@ -1549,6 +1573,12 @@ version = "0.10.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2b23ac50abb8261cb38c6e2a7192d3302e0836dac1628f6a93b82b4fad185897" +[[package]] +name = "linux-raw-sys" +version = "0.12.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "32a66949e030da00e8c7d4434b251670a91556f4144941d37452769c25d58a53" + [[package]] name = "litrs" version = "1.0.0" @@ -1612,6 +1642,12 @@ dependencies = [ "heapless 0.8.0", ] +[[package]] +name = "multimap" +version = "0.10.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1d87ecb2933e8aeadb3e3a02b828fed80a7528047e68b4f424523a0981a3a084" + [[package]] name = "nb" version = "0.1.3" @@ -1770,6 +1806,17 @@ version = "1.0.15" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "57c0d7b74b563b49d38dae00a0c37d4d6de9b432382b2892f0574ddcae73fd0a" +[[package]] +name = "petgraph" +version = "0.8.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8701b58ea97060d5e5b155d383a69952a60943f0e6dfe30b04c287beb0b27455" +dependencies = [ + "fixedbitset", + "hashbrown 0.15.5", + "indexmap", +] + [[package]] name = "pin-project-lite" version = "0.2.17" @@ -1849,6 +1896,57 @@ dependencies = [ "embedded-graphics", ] +[[package]] +name = "prost" +version = "0.14.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "528ac67416ff8646872a3c02cad9cc4ee5dc9f9540c9b10771855c95cb2e5ae1" +dependencies = [ + "bytes", + "prost-derive", +] + +[[package]] +name = "prost-build" +version = "0.14.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "03da047801ff44bb6a4d407d4860c05fd70bb81714e6b2f3812603d5b145b042" +dependencies = [ + "heck", + "itertools", + "log", + "multimap", + "petgraph", + "prettyplease", + "prost", + "prost-types", + "regex", + "syn 2.0.117", + "tempfile", +] + +[[package]] +name = "prost-derive" +version = "0.14.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b570b25f7617e43d59005d0990ccb79e950a423952cea19671b7a876da390adf" +dependencies = [ + "anyhow", + "itertools", + "proc-macro2", + "quote", + "syn 2.0.117", +] + +[[package]] +name = "prost-types" +version = "0.14.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f94967dc7688f3054c7fac87473ffae4cc4c3904800e2d9f5b857246d8963b0a" +dependencies = [ + "prost", +] + [[package]] name = "quote" version = "1.0.45" @@ -2037,6 +2135,19 @@ dependencies = [ "svgbobdoc", ] +[[package]] +name = "rustix" +version = "1.1.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b6fe4565b9518b83ef4f91bb47ce29620ca828bd32cb7e408f0062e9930ba190" +dependencies = [ + "bitflags", + "errno", + "libc", + "linux-raw-sys", + "windows-sys", +] + [[package]] name = "rustversion" version = "1.0.22" @@ -2248,6 +2359,18 @@ version = "1.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "55937e1799185b12863d447f42597ed69d9928686b8d88a1df17376a097d8369" +[[package]] +name = "tempfile" +version = "3.27.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "32497e9a4c7b38532efcdebeef879707aa9f794296a4f0244f6f69e9bc8574bd" +dependencies = [ + "fastrand", + "once_cell", + "rustix", + "windows-sys", +] + [[package]] name = "termcolor" version = "1.4.1" diff --git a/Cargo.toml b/Cargo.toml index 546cb89..ac69615 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -97,11 +97,15 @@ geo-types = { version = "0.7.19", default-features = false } mipidsi = { version = "0.10.0", optional = true } num-traits = { version = "0.2.19", default-features = false, features = ["libm"] } profont = { version = "0.7.0", optional = true } +prost = { version = "0.14", default-features = false, features = ["derive"] } [dev-dependencies] assert_float_eq = "1.2.0" env_logger = "0.11.10" +[build-dependencies] +prost-build = "0.14" + # For fine tuning these settings, please refer to https://doc.rust-lang.org/cargo/reference/profiles.html [profile.dev] diff --git a/build.rs b/build.rs index 7ad15d3..f376e0e 100644 --- a/build.rs +++ b/build.rs @@ -1,6 +1,6 @@ use std::env; -fn main() { +fn main() -> std::io::Result<()> { let target_arch = env::var("CARGO_CFG_TARGET_ARCH").unwrap(); if target_arch == "riscv32" { @@ -8,6 +8,16 @@ fn main() { // make sure linkall.x is the last linker script (otherwise might cause problems with flip-link) println!("cargo:rustc-link-arg=-Tlinkall.x"); } + + let descriptor_path = + std::path::PathBuf::from(env::var("OUT_DIR").unwrap()).join("proto_descriptor.bin"); + + prost_build::Config::new() + .file_descriptor_set_path(&descriptor_path) + .compile_well_known_types() + .compile_protos(&["docs/c_its-messages.proto"], &["docs/"])?; + + Ok(()) } fn linker_be_nice() { diff --git a/docs/c_its-messages.proto b/docs/c_its-messages.proto index a45083c..c2ca54e 100644 --- a/docs/c_its-messages.proto +++ b/docs/c_its-messages.proto @@ -78,8 +78,8 @@ message RawMsgTx { message PositionState { required Position position = 1; - optional uint32 heading_deg = 2; - optional uint32 speed = 3; // speed in 1/100 m/s + optional uint32 heading = 3; // heading in 1/10 deg + optional uint32 speed = 4; // speed in 1/100 m/s } message DenmEvent { diff --git a/src/io.rs b/src/io.rs new file mode 100644 index 0000000..cb23055 --- /dev/null +++ b/src/io.rs @@ -0,0 +1,51 @@ +//! UART/ BLE I/O Protocol + +pub mod msg { + #![allow(clippy::all, clippy::pedantic, clippy::nursery, dead_code)] + include!(concat!(env!("OUT_DIR"), "/c_its_io.rs")); +} + +impl From for msg::SerialOutputMsg { + fn from(value: msg::RawMsgRx) -> Self { + use msg::serial_output_msg::Payload; + + Self { + payload: Some(Payload::RxMsg(value)), + } + } +} + +impl From for msg::SerialOutputMsg { + fn from(value: msg::DenmEvent) -> Self { + use msg::serial_output_msg::Payload; + + Self { + payload: Some(Payload::Denm(value)), + } + } +} + +impl From for crate::applogic::PositionState { + fn from(value: msg::PositionState) -> Self { + let position = geo_types::Point::new( + value.position.longitude_deg.into(), + value.position.latitude_deg.into(), + ); + let heading_deg = value.heading.map(|v| { + #[allow(clippy::cast_precision_loss)] + let val = (v as f32) / 10.; + val + }); + let speed_mps = value.speed.map(|v| { + #[allow(clippy::cast_precision_loss)] + let val = (v as f32) / 100.; + val + }); + + Self { + position, + heading_deg, + speed_mps, + } + } +} diff --git a/src/main.rs b/src/main.rs index 79cf7d9..c0d9e3a 100644 --- a/src/main.rs +++ b/src/main.rs @@ -26,7 +26,7 @@ use esp_hal::timer::timg::TimerGroup; use esp_println::println; use esp_radio::wifi; use geonetworking::Decode as _; -use log::{debug, error, info, warn}; +use log::{error, info, warn}; extern crate alloc; @@ -34,6 +34,7 @@ mod applogic; #[cfg(feature = "spat")] mod cache; mod geo_alg; +mod io; mod radio; #[cfg(feature = "screen")] mod screen;