Watch
0
0
Fork
You've already forked esp32-c_its-companion
0

Move core ESP32 V2X to own repo

This commit is contained in:
Jannik Beyerstedt 2026-07-31 16:01:43 +02:00
commit 666499c240
11 changed files with 118 additions and 615 deletions

View file

@ -38,7 +38,7 @@ use esp_hal::clock::CpuClock;
use esp_hal::timer::timg::TimerGroup;
#[cfg(all(target_arch = "riscv32", feature = "spat"))]
use esp_println::println;
use esp_radio::wifi;
use esp32_cits_core::radio;
use geonetworking::Decode as _;
use log::{error, info, warn};
@ -49,13 +49,10 @@ mod cache;
mod geo_alg;
#[cfg(feature = "uart")]
mod io;
mod radio;
#[cfg(feature = "screen")]
mod screen;
#[cfg(feature = "gnss_ubx")]
mod ubx;
#[cfg(any(feature = "cam_tx", feature = "uart"))]
mod v2x_tx;
const WIFI_CHANNEL: radio::Channel = 180;
const WIFI_TXPOWER: i8 = 10; // dBm, 2..20
@ -244,7 +241,7 @@ async fn main(spawner: Spawner) -> ! {
let mut state = applogic::State::new();
#[cfg(feature = "cam_tx")]
let mut cam = {
let station_id = v2x_tx::make_station_id(mac);
let station_id = make_station_id(mac);
info!("V2X Station ID: {station_id}");
applogic::cam_tx::CamState::new(
@ -289,7 +286,7 @@ async fn main(spawner: Spawner) -> ! {
});
}
Some(io::msg::serial_input_msg::Payload::TxMsg(tx_request)) => {
use v2x_tx::GnItsPayload as _;
use esp32_cits_core::tx::GnItsPayload as _;
info!(
"UART: Got new TX message: Type {} with {} bytes",
@ -380,7 +377,7 @@ async fn main(spawner: Spawner) -> ! {
#[cfg(feature = "cam_tx")]
{
use v2x_tx::GnItsPayload;
use esp32_cits_core::tx::GnItsPayload as _;
let time = state.time().and_utc();
cam.update(time, fix.clone().into());
@ -513,7 +510,7 @@ async fn main(spawner: Spawner) -> ! {
reason = "adhering to callback interface"
)]
#[allow(clippy::too_many_lines)]
fn handle_frame(frame: wifi::sniffer::PromiscuousPkt<'_>) {
fn handle_frame(frame: esp_radio::wifi::sniffer::PromiscuousPkt<'_>) {
#[cfg(feature = "spat")]
const PRUNE_INTERVAL: chrono::Duration = chrono::Duration::seconds(60);
#[cfg(feature = "spat")]
@ -534,27 +531,18 @@ fn handle_frame(frame: wifi::sniffer::PromiscuousPkt<'_>) {
.naive_utc()
};
// Ignore frames with errors and non-data frames
if frame.rx_cntl.rx_state != 0 {
warn!("Received frame has RX error: {}", frame.rx_cntl.rx_state);
return;
}
if !radio::PromiscuousPktType::Data.matches(frame.frame_type) {
return;
}
// Ignore non-broadcast frames
if frame.len < (4 + 6) {
warn!(
"Received frame too small to be a valid broadcast frame: {} bytes",
frame.len
);
return;
}
let dest_mac = &frame.data[4..10];
if dest_mac != [0xff; 6] {
warn!("Received frame is not broadcast frame: Dest MAC {dest_mac:02x?}");
return;
match esp32_cits_core::rx::is_broadcast_frame(&frame) {
Err(err) => {
warn!("{err}");
return;
}
Ok(false) => {
// drop frame
return;
}
Ok(true) => {
// continue
}
}
// info!("Received frame with {} bytes", frame.len);
@ -885,3 +873,19 @@ fn send_uart0(data: &[u8]) {
}
});
}
#[cfg(all(feature = "esp", feature = "cam_tx"))]
/// Creates a station ID from the WLAN MAC address
///
/// Will use `0xC173` as static prefix and uses last 16 bit from MAC address for the remainder.
///
/// # Panics
/// Won't panic in practive b/c of pre-conditions
#[must_use]
pub fn make_station_id(mac: esp_hal::efuse::MacAddress) -> u32 {
// unwrap is fine here since we can be sure that the MacAddress is 6 byte
// and a slice of 2 bytes can be converted to [u8; 2]
let mac_last_16bit = u16::from_be_bytes(mac.as_bytes().get(4..6).unwrap().try_into().unwrap());
0xC173_0000 | u32::from(mac_last_16bit)
}