From fd09e63b9eb9e989fc4beb6fa8fbadfb7b30d814 Mon Sep 17 00:00:00 2001 From: Dylan Knutson Date: Mon, 27 Jul 2026 21:27:58 +0000 Subject: [PATCH] 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;