From 24968629ec810b844b819e8f84baab2a9349ed2f Mon Sep 17 00:00:00 2001 From: Dario Nieuwenhuis Date: Sat, 20 Jan 2024 00:10:35 +0100 Subject: [PATCH] cyw43: Unify dwell time. --- cyw43/Cargo.toml | 2 +- cyw43/src/control.rs | 48 ++++++++++++++++++++------------------------ 2 files changed, 23 insertions(+), 27 deletions(-) diff --git a/cyw43/Cargo.toml b/cyw43/Cargo.toml index 64c38ea7a..f279739e4 100644 --- a/cyw43/Cargo.toml +++ b/cyw43/Cargo.toml @@ -10,7 +10,7 @@ repository = "https://github.com/embassy-rs/embassy" documentation = "https://docs.embassy.dev/cyw43" [features] -defmt = ["dep:defmt", "heapless/defmt-03"] +defmt = ["dep:defmt", "heapless/defmt-03", "embassy-time/defmt"] log = ["dep:log"] # Fetch console logs from the WiFi firmware and forward them to `log` or `defmt`. diff --git a/cyw43/src/control.rs b/cyw43/src/control.rs index 26d50d311..135b8c245 100644 --- a/cyw43/src/control.rs +++ b/cyw43/src/control.rs @@ -38,14 +38,8 @@ pub struct Control<'a> { #[derive(Copy, Clone)] #[cfg_attr(feature = "defmt", derive(defmt::Format))] pub enum ScanType { - Active { - /// Period of time to wait on each channel when active scanning. - dwell_time: Option, - }, - Passive { - /// Period of time to wait on each channel when passive scanning. - dwell_time: Option, - }, + Active, + Passive, } #[derive(Clone)] @@ -59,7 +53,10 @@ pub struct ScanOptions { pub nprobes: Option, /// Time to spend waiting on the home channel. pub home_time: Option, + /// Scan type: active or passive. pub scan_type: ScanType, + /// Period of time to wait on each channel when passive scanning. + pub dwell_time: Option, } impl Default for ScanOptions { @@ -69,7 +66,8 @@ impl Default for ScanOptions { bssid: None, nprobes: None, home_time: None, - scan_type: ScanType::Passive { dwell_time: None }, + scan_type: ScanType::Passive, + dwell_time: None, } } } @@ -514,28 +512,26 @@ impl<'a> Control<'a> { const SCANTYPE_ACTIVE: u8 = 0; const SCANTYPE_PASSIVE: u8 = 1; + let dwell_time = match scan_opts.dwell_time { + None => !0, + Some(t) => { + let mut t = t.as_millis() as u32; + if t == !0 { + t = !0 - 1; + } + t + } + }; + let mut active_time = !0; let mut passive_time = !0; - let scan_type = match scan_opts.scan_type { - ScanType::Active { dwell_time: None } => SCANTYPE_ACTIVE, - ScanType::Active { - dwell_time: Some(dwell_time), - } => { - active_time = dwell_time.as_millis() as u32; - if active_time == !0 { - active_time = !0 - 1; - } + ScanType::Active => { + active_time = dwell_time; SCANTYPE_ACTIVE } - ScanType::Passive { dwell_time: None } => SCANTYPE_PASSIVE, - ScanType::Passive { - dwell_time: Some(dwell_time), - } => { - passive_time = dwell_time.as_millis() as u32; - if passive_time == !0 { - passive_time = !0 - 1; - } + ScanType::Passive => { + passive_time = dwell_time; SCANTYPE_PASSIVE } };