Skip to content

Commit

Permalink
cyw43: Unify dwell time.
Browse files Browse the repository at this point in the history
  • Loading branch information
Dirbaio committed Jan 19, 2024
1 parent 6ca4303 commit 2496862
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 27 deletions.
2 changes: 1 addition & 1 deletion cyw43/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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`.
Expand Down
48 changes: 22 additions & 26 deletions cyw43/src/control.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Duration>,
},
Passive {
/// Period of time to wait on each channel when passive scanning.
dwell_time: Option<Duration>,
},
Active,
Passive,
}

#[derive(Clone)]
Expand All @@ -59,7 +53,10 @@ pub struct ScanOptions {
pub nprobes: Option<u16>,
/// Time to spend waiting on the home channel.
pub home_time: Option<Duration>,
/// Scan type: active or passive.
pub scan_type: ScanType,
/// Period of time to wait on each channel when passive scanning.
pub dwell_time: Option<Duration>,
}

impl Default for ScanOptions {
Expand All @@ -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,
}
}
}
Expand Down Expand Up @@ -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
}
};
Expand Down

0 comments on commit 2496862

Please sign in to comment.