feat: MAC-based USB serial number and protocol unit tests
Replace hardcoded USB serial "001" with the board's MAC address so multiple dongles are uniquely identifiable on one host. Thread MAC through usb_task as a parameter, removing the Board import. Add 31 unit tests for protocol serialization: RadioConfig roundtrips, all Command tags, all Response variants, validation boundaries, and edge cases. Gate firmware modules with #[cfg(not(test))] and add DONGLORA_HOST_TEST env var so `just test` runs on the host.
This commit is contained in:
3 files changed
+396
-16
No files matched your search
+26
-3
@@ -12,21 +12,30 @@
|
||||
//!
|
||||
//! The host drives everything. The radio idles until commanded.
|
||||
|
||||
#![no_std]
|
||||
#![no_main]
|
||||
#![cfg_attr(not(test), no_std)]
|
||||
#![cfg_attr(not(test), no_main)]
|
||||
|
||||
#[cfg(not(test))]
|
||||
mod board;
|
||||
#[cfg(not(test))]
|
||||
mod channel;
|
||||
#[cfg(not(test))]
|
||||
mod display;
|
||||
mod protocol;
|
||||
#[cfg(not(test))]
|
||||
mod radio;
|
||||
#[cfg(not(test))]
|
||||
mod usb;
|
||||
|
||||
#[cfg(not(test))]
|
||||
use embassy_executor::Spawner;
|
||||
|
||||
#[cfg(not(test))]
|
||||
use crate::board::LoRaBoard;
|
||||
#[cfg(not(test))]
|
||||
use crate::channel::{CommandChannel, DisplayCommandChannel, ResponseChannel, StatusWatch};
|
||||
|
||||
#[cfg(not(test))]
|
||||
cfg_if::cfg_if! {
|
||||
if #[cfg(feature = "rak_wisblock_4631")] {
|
||||
use panic_probe as _;
|
||||
@@ -36,11 +45,16 @@ cfg_if::cfg_if! {
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(not(test))]
|
||||
static COMMANDS: CommandChannel = CommandChannel::new();
|
||||
#[cfg(not(test))]
|
||||
static RESPONSES: ResponseChannel = ResponseChannel::new();
|
||||
#[cfg(not(test))]
|
||||
static STATUS: StatusWatch = StatusWatch::new();
|
||||
#[cfg(not(test))]
|
||||
static DISPLAY_COMMANDS: DisplayCommandChannel = DisplayCommandChannel::new();
|
||||
|
||||
#[cfg(not(test))]
|
||||
cfg_if::cfg_if! {
|
||||
if #[cfg(feature = "rak_wisblock_4631")] {
|
||||
#[embassy_executor::main]
|
||||
@@ -55,8 +69,10 @@ cfg_if::cfg_if! {
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(not(test))]
|
||||
async fn run(spawner: Spawner) {
|
||||
let board = <board::Board as LoRaBoard>::init();
|
||||
let mac = board::Board::mac_address();
|
||||
let (radio, usb, display) = board.into_parts();
|
||||
|
||||
let has_display = display.is_some();
|
||||
@@ -65,7 +81,14 @@ async fn run(spawner: Spawner) {
|
||||
.spawn(radio::radio_task(radio, &COMMANDS, &RESPONSES, &STATUS))
|
||||
.expect("spawn radio_task");
|
||||
spawner
|
||||
.spawn(usb::usb_task(usb, &COMMANDS, &RESPONSES, &DISPLAY_COMMANDS, has_display))
|
||||
.spawn(usb::usb_task(
|
||||
usb,
|
||||
&COMMANDS,
|
||||
&RESPONSES,
|
||||
&DISPLAY_COMMANDS,
|
||||
has_display,
|
||||
mac,
|
||||
))
|
||||
.expect("spawn usb_task");
|
||||
|
||||
if let Some(dp) = display {
|
||||
|
||||
Reference in new issue
Block a user