From fd09e63b9eb9e989fc4beb6fa8fbadfb7b30d814 Mon Sep 17 00:00:00 2001 From: Dylan Knutson Date: Mon, 27 Jul 2026 21:27:58 +0000 Subject: [PATCH 1/3] Add second mock battery Register a distinct 2S fuel gauge as battery 1 so integration tests can verify that callers select a battery by ID. Assisted-by: GitHub Copilot:gpt-5.6-sol Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: a3539bc8-3a1f-44b3-ba4a-c171a7822595 --- platform/platform-common/src/mock/battery.rs | 25 ++++++++++++-------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/platform/platform-common/src/mock/battery.rs b/platform/platform-common/src/mock/battery.rs index 71edc3b..f6b4cb2 100644 --- a/platform/platform-common/src/mock/battery.rs +++ b/platform/platform-common/src/mock/battery.rs @@ -8,29 +8,34 @@ use static_cell::StaticCell; /// The fuel gauge, behind a mutex so the service and the driving task can share it. type FuelGauge = Mutex; -/// A single registered fuel gauge, which becomes battery `0`. -type Reg = bs::ArrayRegistration<'static, FuelGauge, 1>; +/// Two registered fuel gauges: battery `0` is a 3S pack, battery `1` a 2S pack. +type Reg = bs::ArrayRegistration<'static, FuelGauge, 2>; pub type BatteryService = bs::Service<'static, Reg>; pub async fn init(spawner: embassy_executor::Spawner) -> BatteryService { info!("Initializing battery service..."); - static FUEL_GAUGE: StaticCell = StaticCell::new(); - let fuel_gauge: &'static FuelGauge = FUEL_GAUGE.init(Mutex::new(MockFuelGauge::new())); + static FUEL_GAUGE_0: StaticCell = StaticCell::new(); + let fuel_gauge_0: &'static FuelGauge = FUEL_GAUGE_0.init(Mutex::new(MockFuelGauge::new())); + + static FUEL_GAUGE_1: StaticCell = StaticCell::new(); + let fuel_gauge_1: &'static FuelGauge = FUEL_GAUGE_1.init(Mutex::new(MockFuelGauge::new_2s())); let service = bs::Service::new(bs::ArrayRegistration { - fuel_gauges: [fuel_gauge], + fuel_gauges: [fuel_gauge_0, fuel_gauge_1], }); - bs::mock::init_state_machine(fuel_gauge) - .await - .expect("Failed to initialize battery state machine"); - spawner.spawn(update_data_task(fuel_gauge).expect("Failed to spawn battery update data task")); + for fuel_gauge in [fuel_gauge_0, fuel_gauge_1] { + bs::mock::init_state_machine(fuel_gauge) + .await + .expect("Failed to initialize battery state machine"); + spawner.spawn(update_data_task(fuel_gauge).expect("Failed to spawn battery update data task")); + } service } -#[embassy_executor::task] +#[embassy_executor::task(pool_size = 2)] pub async fn update_data_task(fuel_gauge: &'static FuelGauge) -> ! { let mut failures: u32 = 0; let mut count: usize = 0; From 24b19a21f01ddbcde3761d266789a81c1d5c80c5 Mon Sep 17 00:00:00 2001 From: Dylan Knutson Date: Wed, 29 Jul 2026 15:59:14 +0000 Subject: [PATCH 2/3] Identify mock battery logs Include each registered battery ID in update and recovery errors so failures from the two mock gauges are distinguishable. Assisted-by: GitHub Copilot:gpt-5.6-sol Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: a3539bc8-3a1f-44b3-ba4a-c171a7822595 --- platform/platform-common/src/mock/battery.rs | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/platform/platform-common/src/mock/battery.rs b/platform/platform-common/src/mock/battery.rs index f6b4cb2..e674161 100644 --- a/platform/platform-common/src/mock/battery.rs +++ b/platform/platform-common/src/mock/battery.rs @@ -25,18 +25,18 @@ pub async fn init(spawner: embassy_executor::Spawner) -> BatteryService { fuel_gauges: [fuel_gauge_0, fuel_gauge_1], }); - for fuel_gauge in [fuel_gauge_0, fuel_gauge_1] { + for (battery_id, fuel_gauge) in [fuel_gauge_0, fuel_gauge_1].into_iter().enumerate() { bs::mock::init_state_machine(fuel_gauge) .await .expect("Failed to initialize battery state machine"); - spawner.spawn(update_data_task(fuel_gauge).expect("Failed to spawn battery update data task")); + spawner.spawn(update_data_task(battery_id as u8, fuel_gauge).expect("Failed to spawn battery update data task")); } service } #[embassy_executor::task(pool_size = 2)] -pub async fn update_data_task(fuel_gauge: &'static FuelGauge) -> ! { +pub async fn update_data_task(battery_id: u8, fuel_gauge: &'static FuelGauge) -> ! { let mut failures: u32 = 0; let mut count: usize = 0; loop { @@ -44,20 +44,20 @@ pub async fn update_data_task(fuel_gauge: &'static FuelGauge) -> ! { if count.is_multiple_of(const { 60 * 60 * 60 }) { if let Err(e) = fuel_gauge.lock().await.update_static_data().await { failures += 1; - error!("FG: Static data error: {:?}", defmt::Debug2Format(&e)); + error!("FG {}: Static data error: {:?}", battery_id, defmt::Debug2Format(&e)); } } if let Err(e) = fuel_gauge.lock().await.update_dynamic_data().await { failures += 1; - error!("FG: Dynamic data error: {:?}", defmt::Debug2Format(&e)); + error!("FG {}: Dynamic data error: {:?}", battery_id, defmt::Debug2Format(&e)); } if failures > 10 { failures = 0; count = 0; - error!("FG: Too many errors, timing out and starting recovery..."); + error!("FG {}: Too many errors, timing out and starting recovery...", battery_id); if bs::mock::recover_state_machine(fuel_gauge).await.is_err() { - error!("FG: Failed to recover state machine!"); + error!("FG {}: Failed to recover state machine!", battery_id); } } From 4678609a949a27839926aaefc8bc5ab09171bfe7 Mon Sep 17 00:00:00 2001 From: Dylan Knutson Date: Wed, 29 Jul 2026 17:53:13 +0000 Subject: [PATCH 3/3] Format mock battery logging Apply the platform-common rustfmt layout required by its standalone CI formatting job. Assisted-by: GitHub Copilot:gpt-5.6-sol Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: a3539bc8-3a1f-44b3-ba4a-c171a7822595 --- platform/platform-common/src/mock/battery.rs | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/platform/platform-common/src/mock/battery.rs b/platform/platform-common/src/mock/battery.rs index e674161..ce92761 100644 --- a/platform/platform-common/src/mock/battery.rs +++ b/platform/platform-common/src/mock/battery.rs @@ -29,7 +29,8 @@ pub async fn init(spawner: embassy_executor::Spawner) -> BatteryService { bs::mock::init_state_machine(fuel_gauge) .await .expect("Failed to initialize battery state machine"); - spawner.spawn(update_data_task(battery_id as u8, fuel_gauge).expect("Failed to spawn battery update data task")); + spawner + .spawn(update_data_task(battery_id as u8, fuel_gauge).expect("Failed to spawn battery update data task")); } service @@ -55,7 +56,10 @@ pub async fn update_data_task(battery_id: u8, fuel_gauge: &'static FuelGauge) -> if failures > 10 { failures = 0; count = 0; - error!("FG {}: Too many errors, timing out and starting recovery...", battery_id); + error!( + "FG {}: Too many errors, timing out and starting recovery...", + battery_id + ); if bs::mock::recover_state_machine(fuel_gauge).await.is_err() { error!("FG {}: Failed to recover state machine!", battery_id); }