From b83f02c0f287212a8cd57ba65d12f5bd9367e005 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alexander=20H=C3=BCbener?= Date: Thu, 24 Nov 2022 21:17:31 +0100 Subject: [PATCH 01/14] cleanup stop and disconnection calls --- src/wifi.rs | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/wifi.rs b/src/wifi.rs index 858436053c1..e009a42c791 100644 --- a/src/wifi.rs +++ b/src/wifi.rs @@ -370,8 +370,6 @@ impl<'d> WifiDriver<'d> { pub fn stop(&mut self) -> Result<(), EspError> { info!("Stop requested"); - let _ = esp!(unsafe { esp_wifi_disconnect() }); - esp!(unsafe { esp_wifi_stop() })?; info!("Stopping"); @@ -701,7 +699,8 @@ impl<'d> WifiDriver<'d> { fn do_scan(&mut self) -> Result { info!("About to scan for access points"); - self.stop()?; + let _ = self.disconnect(); + let _ = self.stop(); unsafe { esp!(esp_wifi_set_mode(wifi_mode_t_WIFI_MODE_STA))?; From 3bb75bae130716b230c33040bd1d8c07a45ff260 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alexander=20H=C3=BCbener?= Date: Sun, 11 Dec 2022 16:55:32 +0100 Subject: [PATCH 02/14] refactored scan process --- src/wifi.rs | 204 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 204 insertions(+) diff --git a/src/wifi.rs b/src/wifi.rs index e009a42c791..20c8cd3da9f 100644 --- a/src/wifi.rs +++ b/src/wifi.rs @@ -31,6 +31,77 @@ use crate::private::cstr::*; use crate::private::mutex; use crate::private::waitable::*; +pub mod config { + + use esp_idf_sys::*; + + #[derive(Debug, Clone, Copy, PartialEq, Eq)] + #[repr(u32)] + pub enum ScanType { + Active = 0, + Passive = 1, + } + + impl From for u32 { + fn from(s: ScanType) -> Self { + match s { + ScanType::Active => 0, + ScanType::Passive => 1, + } + } + } + + impl Default for ScanType { + fn default() -> Self { + Self::Active + } + } + + #[derive(Debug)] + pub struct ScanTime { + pub active: (u32, u32), + pub passive: u32, + } + + impl Default for ScanTime { + fn default() -> Self { + Self { + active: (0, 0), + passive: 0, + } + } + } + + #[derive(Default, Debug)] + pub struct ScanConfig { + pub bssid: Option<[u8; 8]>, + pub ssid: Option, + pub channel: Option, + pub scan_type: ScanType, + pub scan_time: ScanTime, + pub show_hidden: bool, + } + + impl From<&ScanConfig> for wifi_scan_config_t { + fn from(s: &ScanConfig) -> Self { + Self { + bssid: s.bssid.map_or(core::ptr::null(), |v| v.as_ptr()) as *mut u8, + ssid: s.ssid.as_ref().map_or(core::ptr::null(), |v| v.as_ptr()) as *mut u8, + scan_time: wifi_scan_time_t { + active: wifi_active_scan_time_t { + min: s.scan_time.active.0, + max: s.scan_time.active.1, + }, + passive: s.scan_time.passive, + }, + channel: s.channel.unwrap_or_default(), + scan_type: s.scan_type.into(), + show_hidden: s.show_hidden, + } + } + } +} + impl From for Newtype { fn from(method: AuthMethod) -> Self { Newtype(match method { @@ -198,6 +269,13 @@ impl From for wifi_interface_t { } } +#[derive(Copy, Clone, Debug, Eq, PartialEq)] +pub enum WifiDriverMode { + Ap, + Sta, + ApSta, +} + #[allow(non_upper_case_globals)] impl From for WifiDeviceId { fn from(id: wifi_interface_t) -> Self { @@ -357,6 +435,16 @@ impl<'d> WifiDriver<'d> { Ok(caps) } + pub fn set_mode(&mut self, mode: WifiDriverMode) -> Result<(), EspError> { + let mode = match mode { + WifiDriverMode::Ap => wifi_mode_t_WIFI_MODE_AP, + WifiDriverMode::Sta => wifi_mode_t_WIFI_MODE_STA, + WifiDriverMode::ApSta => wifi_mode_t_WIFI_MODE_APSTA, + }; + + esp!(unsafe { esp_wifi_set_mode(mode) }) + } + pub fn start(&mut self) -> Result<(), EspError> { info!("Start requested"); @@ -695,6 +783,41 @@ impl<'d> WifiDriver<'d> { Ok(()) } + fn start_scan(&mut self, scan_config: &config::ScanConfig) -> Result<(), EspError> { + info!("About to scan for access points"); + + let scan_config: wifi_scan_config_t = scan_config.into(); + + esp!(unsafe { esp_wifi_scan_start(&scan_config as *const wifi_scan_config_t, false) }) + } + + fn stop_scan(&mut self) -> Result<(), EspError> { + esp!(unsafe { esp_wifi_scan_stop() }) + } + + fn get_scan_result(&mut self) -> Result, EspError> { + let mut total_count: u16 = 0; + esp!(unsafe { esp_wifi_scan_get_ap_num(&mut total_count as *mut _) })?; + + let mut ap_infos_raw: alloc::vec::Vec = + alloc::vec::Vec::with_capacity(total_count as usize); + #[allow(clippy::uninit_vec)] + // ... because we are filling it in on the next line and only reading the initialized members + unsafe { + ap_infos_raw.set_len(total_count as usize) + }; + + let real_count = self.do_get_scan_infos(&mut ap_infos_raw)?; + + let mut result = alloc::vec::Vec::with_capacity(real_count); + for ap_info_raw in ap_infos_raw.iter().take(real_count) { + let ap_info: AccessPointInfo = Newtype(ap_info_raw).into(); + + result.push(ap_info); + } + Ok(result) + } + #[allow(non_upper_case_globals)] fn do_scan(&mut self) -> Result { info!("About to scan for access points"); @@ -1225,3 +1348,84 @@ impl WifiWait { } } } + +#[derive(Debug, Clone, Copy, PartialEq, Eq)] +enum ScanState { + Init, + Stared, + Done, +} + +impl From for ScanState { + fn from(value: WifiEvent) -> Self { + match value { + WifiEvent::ScanStarted => Self::Stared, + WifiEvent::ScanDone => Self::Done, + _ => unreachable!(), + } + } +} + +/// # Example +/// ```ignore +/// # fn main() -> anyhow::Result<()> { +/// let wifi_driver = WifiDriver::new(...); +/// +/// let config = WifiScanConfig::default(); +/// let result = ScanProcess::new(&sysloop, &mut wifi_driver).scan(&config); +/// # } +/// ``` +pub struct ScanProcess<'d, 'a> { + waitable: Arc>, + wifi_driver: &'d mut WifiDriver<'a>, + _subscription: EspSubscription, +} + +impl<'d, 'a> ScanProcess<'d, 'a> { + pub fn new( + sysloop: &EspEventLoop, + wifi_driver: &'d mut WifiDriver<'a>, + ) -> Result { + let waitable: Arc> = Arc::new(Waitable::new(ScanState::Init)); + + let s_waitable = waitable.clone(); + let subscription = + sysloop.subscribe(move |event: &WifiEvent| Self::on_wifi_event(&s_waitable, event))?; + + Ok(Self { + waitable, + wifi_driver, + _subscription: subscription, + }) + } + + pub fn scan( + self, + config: &config::ScanConfig, + ) -> Result, EspError> { + self.wifi_driver.start_scan(config)?; + self.waitable + .wait_while(|state| !matches!(state, ScanState::Done)); + self.wifi_driver.get_scan_result() + } + + fn on_wifi_event(waitable: &Waitable, event: &WifiEvent) { + info!("Got wifi event: {:?}", event); + + if matches!(event, WifiEvent::ScanStarted | WifiEvent::ScanDone) { + *waitable.state.lock() = event.to_owned().into(); + waitable.cvar.notify_all(); + } + } + + fn clear_scan_result_mem(&mut self) -> Result<(), EspError> { + self.wifi_driver.get_scan_result().map(|_| ()) + } +} + +impl Drop for ScanProcess<'_, '_> { + fn drop(&mut self) { + self.wifi_driver.stop_scan().unwrap(); + self.clear_scan_result_mem().unwrap() + } +} From a057ff29e98a5ebe20cef9c84d34c85c9483b3f9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alexander=20H=C3=BCbener?= Date: Mon, 12 Dec 2022 09:36:50 +0100 Subject: [PATCH 03/14] logging --- src/wifi.rs | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/wifi.rs b/src/wifi.rs index 20c8cd3da9f..291d9d063b4 100644 --- a/src/wifi.rs +++ b/src/wifi.rs @@ -784,10 +784,7 @@ impl<'d> WifiDriver<'d> { } fn start_scan(&mut self, scan_config: &config::ScanConfig) -> Result<(), EspError> { - info!("About to scan for access points"); - let scan_config: wifi_scan_config_t = scan_config.into(); - esp!(unsafe { esp_wifi_scan_start(&scan_config as *const wifi_scan_config_t, false) }) } @@ -1403,10 +1400,16 @@ impl<'d, 'a> ScanProcess<'d, 'a> { self, config: &config::ScanConfig, ) -> Result, EspError> { + info!("About to scan for access points"); self.wifi_driver.start_scan(config)?; + self.waitable .wait_while(|state| !matches!(state, ScanState::Done)); - self.wifi_driver.get_scan_result() + + info!("About to get info for found access points"); + let scan_res = self.wifi_driver.get_scan_result()?; + info!("Got info for {} access points", scan_res.len()); + Ok(scan_res) } fn on_wifi_event(waitable: &Waitable, event: &WifiEvent) { From e2b82f2ba4fadaa92690be25bf7925b2cbf31598 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alexander=20H=C3=BCbener?= Date: Mon, 12 Dec 2022 10:55:18 +0100 Subject: [PATCH 04/14] make clippy happy --- src/wifi.rs | 15 +++------------ 1 file changed, 3 insertions(+), 12 deletions(-) diff --git a/src/wifi.rs b/src/wifi.rs index 291d9d063b4..23e343564e0 100644 --- a/src/wifi.rs +++ b/src/wifi.rs @@ -57,25 +57,16 @@ pub mod config { } } - #[derive(Debug)] + #[derive(Debug, Default)] pub struct ScanTime { pub active: (u32, u32), pub passive: u32, } - impl Default for ScanTime { - fn default() -> Self { - Self { - active: (0, 0), - passive: 0, - } - } - } - #[derive(Default, Debug)] pub struct ScanConfig { - pub bssid: Option<[u8; 8]>, - pub ssid: Option, + pub bssid: Option<[u8; 6]>, + pub ssid: Option>, pub channel: Option, pub scan_type: ScanType, pub scan_time: ScanTime, From b2d47a411d3d8c1f9bc6684007abd0050c8e1f6f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alexander=20H=C3=BCbener?= Date: Mon, 12 Dec 2022 11:52:43 +0100 Subject: [PATCH 05/14] fix build --- src/wifi.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/wifi.rs b/src/wifi.rs index 23e343564e0..f34dd693b6c 100644 --- a/src/wifi.rs +++ b/src/wifi.rs @@ -1407,7 +1407,7 @@ impl<'d, 'a> ScanProcess<'d, 'a> { info!("Got wifi event: {:?}", event); if matches!(event, WifiEvent::ScanStarted | WifiEvent::ScanDone) { - *waitable.state.lock() = event.to_owned().into(); + *waitable.state.lock() = event.clone().into(); waitable.cvar.notify_all(); } } From 2a3c4e7942edfa3d9c6047a15303f958fa9a9b25 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alexander=20H=C3=BCbener?= Date: Mon, 12 Dec 2022 12:02:05 +0100 Subject: [PATCH 06/14] make clippy happy --- src/wifi.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/wifi.rs b/src/wifi.rs index f34dd693b6c..7b09b2d6b40 100644 --- a/src/wifi.rs +++ b/src/wifi.rs @@ -1407,7 +1407,7 @@ impl<'d, 'a> ScanProcess<'d, 'a> { info!("Got wifi event: {:?}", event); if matches!(event, WifiEvent::ScanStarted | WifiEvent::ScanDone) { - *waitable.state.lock() = event.clone().into(); + *waitable.state.lock() = (*event).into(); waitable.cvar.notify_all(); } } From f199c31b7f94b567db1471d0ec210263a2371f66 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alexander=20H=C3=BCbener?= Date: Mon, 12 Dec 2022 19:13:37 +0100 Subject: [PATCH 07/14] impl new scan api --- src/wifi.rs | 378 ++++++++++++++++++++-------------------------------- 1 file changed, 146 insertions(+), 232 deletions(-) diff --git a/src/wifi.rs b/src/wifi.rs index 1198798c437..c289944f26c 100644 --- a/src/wifi.rs +++ b/src/wifi.rs @@ -1,6 +1,6 @@ use core::marker::PhantomData; use core::time::Duration; -use core::{cmp, ffi, ptr}; +use core::{cmp, ffi}; extern crate alloc; use alloc::boxed::Box; @@ -30,65 +30,22 @@ use crate::private::cstr::*; use crate::private::mutex; use crate::private::waitable::*; -pub mod config { - - use esp_idf_sys::*; - - #[derive(Debug, Clone, Copy, PartialEq, Eq)] - #[repr(u32)] - pub enum ScanType { - Active = 0, - Passive = 1, - } - - impl From for u32 { - fn from(s: ScanType) -> Self { - match s { - ScanType::Active => 0, - ScanType::Passive => 1, - } - } - } - - impl Default for ScanType { - fn default() -> Self { - Self::Active - } - } - - #[derive(Debug, Default)] - pub struct ScanTime { - pub active: (u32, u32), - pub passive: u32, - } - - #[derive(Default, Debug)] - pub struct ScanConfig { - pub bssid: Option<[u8; 6]>, - pub ssid: Option>, - pub channel: Option, - pub scan_type: ScanType, - pub scan_time: ScanTime, - pub show_hidden: bool, - } - - impl From<&ScanConfig> for wifi_scan_config_t { - fn from(s: &ScanConfig) -> Self { - Self { - bssid: s.bssid.map_or(core::ptr::null(), |v| v.as_ptr()) as *mut u8, - ssid: s.ssid.as_ref().map_or(core::ptr::null(), |v| v.as_ptr()) as *mut u8, - scan_time: wifi_scan_time_t { - active: wifi_active_scan_time_t { - min: s.scan_time.active.0, - max: s.scan_time.active.1, - }, - passive: s.scan_time.passive, +impl From<&config::ScanConfig> for Newtype { + fn from(s: &config::ScanConfig) -> Self { + Newtype(wifi_scan_config_t { + bssid: s.bssid.map_or(core::ptr::null(), |v| v.as_ptr()) as *mut u8, + ssid: s.ssid.as_ref().map_or(core::ptr::null(), |v| v.as_ptr()) as *mut u8, + scan_time: wifi_scan_time_t { + active: wifi_active_scan_time_t { + min: s.scan_time.active.0, + max: s.scan_time.active.1, }, - channel: s.channel.unwrap_or_default(), - scan_type: s.scan_type.into(), - show_hidden: s.show_hidden, - } - } + passive: s.scan_time.passive, + }, + channel: s.channel.unwrap_or_default(), + scan_type: s.scan_type.into(), + show_hidden: s.show_hidden, + }) } } @@ -259,13 +216,6 @@ impl From for wifi_interface_t { } } -#[derive(Copy, Clone, Debug, Eq, PartialEq)] -pub enum WifiDriverMode { - Ap, - Sta, - ApSta, -} - #[allow(non_upper_case_globals)] impl From for WifiDeviceId { fn from(id: wifi_interface_t) -> Self { @@ -425,16 +375,6 @@ impl<'d> WifiDriver<'d> { Ok(caps) } - pub fn set_mode(&mut self, mode: WifiDriverMode) -> Result<(), EspError> { - let mode = match mode { - WifiDriverMode::Ap => wifi_mode_t_WIFI_MODE_AP, - WifiDriverMode::Sta => wifi_mode_t_WIFI_MODE_STA, - WifiDriverMode::ApSta => wifi_mode_t_WIFI_MODE_APSTA, - }; - - esp!(unsafe { esp_wifi_set_mode(mode) }) - } - pub fn start(&mut self) -> Result<(), EspError> { info!("Start requested"); @@ -600,40 +540,60 @@ impl<'d> WifiDriver<'d> { Ok(()) } - #[allow(non_upper_case_globals)] pub fn scan_n( &mut self, + scan_config: &config::ScanConfig, ) -> Result<(heapless::Vec, usize), EspError> { - let total_count = self.do_scan()?; + self.do_scan(scan_config)?; + self.get_scan_result_n() + } + #[cfg(feature = "alloc")] + pub fn scan( + &mut self, + scan_config: &config::ScanConfig, + ) -> Result, EspError> { + self.do_scan(scan_config)?; + self.get_scan_result() + } + + pub fn start_scan(&mut self, scan_config: &config::ScanConfig) -> Result<(), EspError> { + let scan_config: Newtype = scan_config.into(); + esp!(unsafe { esp_wifi_scan_start(&scan_config.0 as *const wifi_scan_config_t, false) }) + } + + pub fn stop_scan(&mut self) -> Result<(), EspError> { + esp!(unsafe { esp_wifi_scan_stop() }) + } + + pub fn get_scan_result_n( + &mut self, + ) -> Result<(heapless::Vec, usize), EspError> { let mut ap_infos_raw: heapless::Vec = heapless::Vec::new(); - let real_count = self.do_get_scan_infos(&mut ap_infos_raw)?; + let total_count = self.do_get_scan_amount()?; unsafe { - ap_infos_raw.set_len(real_count); + ap_infos_raw.set_len(total_count.min(N)); } - let mut result = heapless::Vec::<_, N>::new(); - for ap_info_raw in ap_infos_raw.iter().take(real_count) { - let ap_info: AccessPointInfo = Newtype(ap_info_raw).into(); - info!("Found access point {:?}", ap_info); + let real_count = self.do_get_scan_infos(&mut ap_infos_raw)?; - if result.push(ap_info).is_err() { - break; - } - } + let result = ap_infos_raw[..real_count] + .iter() + .map::(|ap_info_raw| Newtype(ap_info_raw).into()) + .inspect(|ap_info| info!("Found access point {:?}", ap_info)) + .collect(); - Ok((result, total_count)) + Ok((result, real_count)) } - #[allow(non_upper_case_globals)] - pub fn scan(&mut self) -> Result, EspError> { - let total_count = self.do_scan()?; + #[cfg(feature = "alloc")] + pub fn get_scan_result(&mut self) -> Result, EspError> { + let total_count = self.do_get_scan_amount()?; let mut ap_infos_raw: alloc::vec::Vec = alloc::vec::Vec::with_capacity(total_count); - #[allow(clippy::uninit_vec)] // ... because we are filling it in on the next line and only reading the initialized members unsafe { @@ -642,13 +602,11 @@ impl<'d> WifiDriver<'d> { let real_count = self.do_get_scan_infos(&mut ap_infos_raw)?; - let mut result = alloc::vec::Vec::with_capacity(real_count); - for ap_info_raw in ap_infos_raw.iter().take(real_count) { - let ap_info: AccessPointInfo = Newtype(ap_info_raw).into(); - info!("Found access point {:?}", ap_info); - - result.push(ap_info); - } + let result = ap_infos_raw[..real_count] + .iter() + .map::(|ap_info_raw| Newtype(ap_info_raw).into()) + .inspect(|ap_info| info!("Found access point {:?}", ap_info)) + .collect(); Ok(result) } @@ -773,40 +731,7 @@ impl<'d> WifiDriver<'d> { Ok(()) } - fn start_scan(&mut self, scan_config: &config::ScanConfig) -> Result<(), EspError> { - let scan_config: wifi_scan_config_t = scan_config.into(); - esp!(unsafe { esp_wifi_scan_start(&scan_config as *const wifi_scan_config_t, false) }) - } - - fn stop_scan(&mut self) -> Result<(), EspError> { - esp!(unsafe { esp_wifi_scan_stop() }) - } - - fn get_scan_result(&mut self) -> Result, EspError> { - let mut total_count: u16 = 0; - esp!(unsafe { esp_wifi_scan_get_ap_num(&mut total_count as *mut _) })?; - - let mut ap_infos_raw: alloc::vec::Vec = - alloc::vec::Vec::with_capacity(total_count as usize); - #[allow(clippy::uninit_vec)] - // ... because we are filling it in on the next line and only reading the initialized members - unsafe { - ap_infos_raw.set_len(total_count as usize) - }; - - let real_count = self.do_get_scan_infos(&mut ap_infos_raw)?; - - let mut result = alloc::vec::Vec::with_capacity(real_count); - for ap_info_raw in ap_infos_raw.iter().take(real_count) { - let ap_info: AccessPointInfo = Newtype(ap_info_raw).into(); - - result.push(ap_info); - } - Ok(result) - } - - #[allow(non_upper_case_globals)] - fn do_scan(&mut self) -> Result { + fn do_scan(&mut self, scan_config: &config::ScanConfig) -> Result<(), EspError> { info!("About to scan for access points"); let _ = self.disconnect(); @@ -815,10 +740,18 @@ impl<'d> WifiDriver<'d> { unsafe { esp!(esp_wifi_set_mode(wifi_mode_t_WIFI_MODE_STA))?; esp!(esp_wifi_start())?; + } - esp!(esp_wifi_scan_start(ptr::null_mut(), true))?; + let scan_config: Newtype = scan_config.into(); + unsafe { + esp!(esp_wifi_scan_start( + &scan_config.0 as *const wifi_scan_config_t, + true + )) } + } + fn do_get_scan_amount(&mut self) -> Result { let mut found_ap: u16 = 0; esp!(unsafe { esp_wifi_scan_get_ap_num(&mut found_ap as *mut _) })?; @@ -827,7 +760,6 @@ impl<'d> WifiDriver<'d> { Ok(found_ap as usize) } - #[allow(non_upper_case_globals)] fn do_get_scan_infos( &mut self, ap_infos_raw: &mut [wifi_ap_record_t], @@ -938,12 +870,35 @@ impl<'d> Wifi for WifiDriver<'d> { fn scan_n( &mut self, + scan_config: &config::ScanConfig, ) -> Result<(heapless::Vec, usize), Self::Error> { - WifiDriver::scan_n(self) + WifiDriver::scan_n(self, scan_config) + } + + #[cfg(feature = "alloc")] + fn scan( + &mut self, + scan_config: &config::ScanConfig, + ) -> Result, Self::Error> { + WifiDriver::scan(self, scan_config) + } + + fn start_scan(&mut self, scan_config: &config::ScanConfig) -> Result<(), Self::Error> { + WifiDriver::start_scan(self, scan_config) } - fn scan(&mut self) -> Result, Self::Error> { - WifiDriver::scan(self) + fn stop_scan(&mut self) -> Result<(), Self::Error> { + WifiDriver::stop_scan(self) + } + + fn get_scan_result_n( + &mut self, + ) -> Result<(heapless::Vec, usize), Self::Error> { + WifiDriver::get_scan_result_n(self) + } + + fn get_scan_result(&mut self) -> Result, Self::Error> { + WifiDriver::get_scan_result(self) } } @@ -1082,12 +1037,36 @@ impl<'d> EspWifi<'d> { pub fn scan_n( &mut self, + scan_config: &config::ScanConfig, + ) -> Result<(heapless::Vec, usize), EspError> { + self.driver_mut().scan_n(scan_config) + } + + #[cfg(feature = "alloc")] + pub fn scan( + &mut self, + scan_config: &config::ScanConfig, + ) -> Result, EspError> { + self.driver_mut().scan(scan_config) + } + + pub fn start_scan(&mut self, scan_config: &config::ScanConfig) -> Result<(), EspError> { + self.driver_mut().start_scan(scan_config) + } + + pub fn stop_scan(&mut self) -> Result<(), EspError> { + self.driver_mut().stop_scan() + } + + pub fn get_scan_result_n( + &mut self, ) -> Result<(heapless::Vec, usize), EspError> { - self.driver_mut().scan_n() + self.driver_mut().get_scan_result_n() } - pub fn scan(&mut self) -> Result, EspError> { - self.driver_mut().scan() + #[cfg(feature = "alloc")] + pub fn get_scan_result(&mut self) -> Result, EspError> { + self.driver_mut().get_scan_result() } fn attach_netif(&mut self) -> Result<(), EspError> { @@ -1172,12 +1151,34 @@ impl<'d> Wifi for EspWifi<'d> { fn scan_n( &mut self, + scan_config: &config::ScanConfig, ) -> Result<(heapless::Vec, usize), Self::Error> { - EspWifi::scan_n(self) + EspWifi::scan_n(self, scan_config) } - fn scan(&mut self) -> Result, Self::Error> { - EspWifi::scan(self) + fn scan( + &mut self, + scan_config: &config::ScanConfig, + ) -> Result, Self::Error> { + EspWifi::scan(self, scan_config) + } + + fn start_scan(&mut self, scan_config: &config::ScanConfig) -> Result<(), Self::Error> { + EspWifi::start_scan(self, scan_config) + } + + fn stop_scan(&mut self) -> Result<(), Self::Error> { + EspWifi::stop_scan(self) + } + + fn get_scan_result_n( + &mut self, + ) -> Result<(heapless::Vec, usize), Self::Error> { + EspWifi::get_scan_result_n(self) + } + + fn get_scan_result(&mut self) -> Result, Self::Error> { + EspWifi::get_scan_result(self) } } @@ -1335,90 +1336,3 @@ impl WifiWait { } } } - -#[derive(Debug, Clone, Copy, PartialEq, Eq)] -enum ScanState { - Init, - Stared, - Done, -} - -impl From for ScanState { - fn from(value: WifiEvent) -> Self { - match value { - WifiEvent::ScanStarted => Self::Stared, - WifiEvent::ScanDone => Self::Done, - _ => unreachable!(), - } - } -} - -/// # Example -/// ```ignore -/// # fn main() -> anyhow::Result<()> { -/// let wifi_driver = WifiDriver::new(...); -/// -/// let config = WifiScanConfig::default(); -/// let result = ScanProcess::new(&sysloop, &mut wifi_driver).scan(&config); -/// # } -/// ``` -pub struct ScanProcess<'d, 'a> { - waitable: Arc>, - wifi_driver: &'d mut WifiDriver<'a>, - _subscription: EspSubscription, -} - -impl<'d, 'a> ScanProcess<'d, 'a> { - pub fn new( - sysloop: &EspEventLoop, - wifi_driver: &'d mut WifiDriver<'a>, - ) -> Result { - let waitable: Arc> = Arc::new(Waitable::new(ScanState::Init)); - - let s_waitable = waitable.clone(); - let subscription = - sysloop.subscribe(move |event: &WifiEvent| Self::on_wifi_event(&s_waitable, event))?; - - Ok(Self { - waitable, - wifi_driver, - _subscription: subscription, - }) - } - - pub fn scan( - self, - config: &config::ScanConfig, - ) -> Result, EspError> { - info!("About to scan for access points"); - self.wifi_driver.start_scan(config)?; - - self.waitable - .wait_while(|state| !matches!(state, ScanState::Done)); - - info!("About to get info for found access points"); - let scan_res = self.wifi_driver.get_scan_result()?; - info!("Got info for {} access points", scan_res.len()); - Ok(scan_res) - } - - fn on_wifi_event(waitable: &Waitable, event: &WifiEvent) { - info!("Got wifi event: {:?}", event); - - if matches!(event, WifiEvent::ScanStarted | WifiEvent::ScanDone) { - *waitable.state.lock() = (*event).into(); - waitable.cvar.notify_all(); - } - } - - fn clear_scan_result_mem(&mut self) -> Result<(), EspError> { - self.wifi_driver.get_scan_result().map(|_| ()) - } -} - -impl Drop for ScanProcess<'_, '_> { - fn drop(&mut self) { - self.wifi_driver.stop_scan().unwrap(); - self.clear_scan_result_mem().unwrap() - } -} From 2c02bb44e94ab0326a77464681014344d3ae9357 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alexander=20H=C3=BCbener?= Date: Tue, 13 Dec 2022 10:16:10 +0100 Subject: [PATCH 08/14] changed code execution order --- src/wifi.rs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/wifi.rs b/src/wifi.rs index c289944f26c..eb661bbf886 100644 --- a/src/wifi.rs +++ b/src/wifi.rs @@ -569,10 +569,9 @@ impl<'d> WifiDriver<'d> { pub fn get_scan_result_n( &mut self, ) -> Result<(heapless::Vec, usize), EspError> { - let mut ap_infos_raw: heapless::Vec = heapless::Vec::new(); - let total_count = self.do_get_scan_amount()?; + let mut ap_infos_raw: heapless::Vec = heapless::Vec::new(); unsafe { ap_infos_raw.set_len(total_count.min(N)); } From 7319649cd56f239a20907522ac5d86170c3c6589 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alexander=20H=C3=BCbener?= Date: Tue, 13 Dec 2022 10:31:12 +0100 Subject: [PATCH 09/14] added logging --- src/wifi.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/wifi.rs b/src/wifi.rs index eb661bbf886..2ef7969e5ac 100644 --- a/src/wifi.rs +++ b/src/wifi.rs @@ -558,6 +558,7 @@ impl<'d> WifiDriver<'d> { } pub fn start_scan(&mut self, scan_config: &config::ScanConfig) -> Result<(), EspError> { + info!("About to scan for access points"); let scan_config: Newtype = scan_config.into(); esp!(unsafe { esp_wifi_scan_start(&scan_config.0 as *const wifi_scan_config_t, false) }) } From c0996273e8f33fa5ab17d4f62c2d94388d9043e5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alexander=20H=C3=BCbener?= Date: Tue, 13 Dec 2022 10:53:14 +0100 Subject: [PATCH 10/14] remove unused returns --- src/wifi.rs | 26 +++++++++++++++++--------- 1 file changed, 17 insertions(+), 9 deletions(-) diff --git a/src/wifi.rs b/src/wifi.rs index 2ef7969e5ac..31c91925c2d 100644 --- a/src/wifi.rs +++ b/src/wifi.rs @@ -543,7 +543,7 @@ impl<'d> WifiDriver<'d> { pub fn scan_n( &mut self, scan_config: &config::ScanConfig, - ) -> Result<(heapless::Vec, usize), EspError> { + ) -> Result, EspError> { self.do_scan(scan_config)?; self.get_scan_result_n() } @@ -569,7 +569,7 @@ impl<'d> WifiDriver<'d> { pub fn get_scan_result_n( &mut self, - ) -> Result<(heapless::Vec, usize), EspError> { + ) -> Result, EspError> { let total_count = self.do_get_scan_amount()?; let mut ap_infos_raw: heapless::Vec = heapless::Vec::new(); @@ -585,7 +585,7 @@ impl<'d> WifiDriver<'d> { .inspect(|ap_info| info!("Found access point {:?}", ap_info)) .collect(); - Ok((result, real_count)) + Ok(result) } #[cfg(feature = "alloc")] @@ -872,7 +872,9 @@ impl<'d> Wifi for WifiDriver<'d> { &mut self, scan_config: &config::ScanConfig, ) -> Result<(heapless::Vec, usize), Self::Error> { - WifiDriver::scan_n(self, scan_config) + let res = WifiDriver::scan_n(self, scan_config)?; + let res_len = res.len(); + Ok((res, res_len)) } #[cfg(feature = "alloc")] @@ -894,7 +896,9 @@ impl<'d> Wifi for WifiDriver<'d> { fn get_scan_result_n( &mut self, ) -> Result<(heapless::Vec, usize), Self::Error> { - WifiDriver::get_scan_result_n(self) + let res = WifiDriver::get_scan_result_n(self)?; + let res_len = res.len(); + Ok((res, res_len)) } fn get_scan_result(&mut self) -> Result, Self::Error> { @@ -1038,7 +1042,7 @@ impl<'d> EspWifi<'d> { pub fn scan_n( &mut self, scan_config: &config::ScanConfig, - ) -> Result<(heapless::Vec, usize), EspError> { + ) -> Result, EspError> { self.driver_mut().scan_n(scan_config) } @@ -1060,7 +1064,7 @@ impl<'d> EspWifi<'d> { pub fn get_scan_result_n( &mut self, - ) -> Result<(heapless::Vec, usize), EspError> { + ) -> Result, EspError> { self.driver_mut().get_scan_result_n() } @@ -1153,7 +1157,9 @@ impl<'d> Wifi for EspWifi<'d> { &mut self, scan_config: &config::ScanConfig, ) -> Result<(heapless::Vec, usize), Self::Error> { - EspWifi::scan_n(self, scan_config) + let res = EspWifi::scan_n(self, scan_config)?; + let res_len = res.len(); + Ok((res, res_len)) } fn scan( @@ -1174,7 +1180,9 @@ impl<'d> Wifi for EspWifi<'d> { fn get_scan_result_n( &mut self, ) -> Result<(heapless::Vec, usize), Self::Error> { - EspWifi::get_scan_result_n(self) + let res = EspWifi::get_scan_result_n(self)?; + let res_len = res.len(); + Ok((res, res_len)) } fn get_scan_result(&mut self) -> Result, Self::Error> { From 7608b547b850cc0a7930f29dedc3a45b37a11809 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alexander=20H=C3=BCbener?= Date: Tue, 13 Dec 2022 12:13:41 +0100 Subject: [PATCH 11/14] renamed vars --- src/wifi.rs | 48 ++++++++++++++++++++---------------------------- 1 file changed, 20 insertions(+), 28 deletions(-) diff --git a/src/wifi.rs b/src/wifi.rs index 31c91925c2d..ccb3148b7cd 100644 --- a/src/wifi.rs +++ b/src/wifi.rs @@ -543,7 +543,7 @@ impl<'d> WifiDriver<'d> { pub fn scan_n( &mut self, scan_config: &config::ScanConfig, - ) -> Result, EspError> { + ) -> Result<(heapless::Vec, usize), EspError> { self.do_scan(scan_config)?; self.get_scan_result_n() } @@ -569,40 +569,40 @@ impl<'d> WifiDriver<'d> { pub fn get_scan_result_n( &mut self, - ) -> Result, EspError> { - let total_count = self.do_get_scan_amount()?; + ) -> Result<(heapless::Vec, usize), EspError> { + let scanned_count = self.do_get_scan_count()?; let mut ap_infos_raw: heapless::Vec = heapless::Vec::new(); unsafe { - ap_infos_raw.set_len(total_count.min(N)); + ap_infos_raw.set_len(scanned_count.min(N)); } - let real_count = self.do_get_scan_infos(&mut ap_infos_raw)?; + let fetched_count = self.do_get_scan_infos(&mut ap_infos_raw)?; - let result = ap_infos_raw[..real_count] + let result = ap_infos_raw[..fetched_count] .iter() .map::(|ap_info_raw| Newtype(ap_info_raw).into()) .inspect(|ap_info| info!("Found access point {:?}", ap_info)) .collect(); - Ok(result) + Ok((result, scanned_count)) } #[cfg(feature = "alloc")] pub fn get_scan_result(&mut self) -> Result, EspError> { - let total_count = self.do_get_scan_amount()?; + let scanned_count = self.do_get_scan_count()?; let mut ap_infos_raw: alloc::vec::Vec = - alloc::vec::Vec::with_capacity(total_count); + alloc::vec::Vec::with_capacity(scanned_count); #[allow(clippy::uninit_vec)] // ... because we are filling it in on the next line and only reading the initialized members unsafe { - ap_infos_raw.set_len(total_count) + ap_infos_raw.set_len(scanned_count) }; - let real_count = self.do_get_scan_infos(&mut ap_infos_raw)?; + let fetched_count = self.do_get_scan_infos(&mut ap_infos_raw)?; - let result = ap_infos_raw[..real_count] + let result = ap_infos_raw[..fetched_count] .iter() .map::(|ap_info_raw| Newtype(ap_info_raw).into()) .inspect(|ap_info| info!("Found access point {:?}", ap_info)) @@ -751,7 +751,7 @@ impl<'d> WifiDriver<'d> { } } - fn do_get_scan_amount(&mut self) -> Result { + fn do_get_scan_count(&mut self) -> Result { let mut found_ap: u16 = 0; esp!(unsafe { esp_wifi_scan_get_ap_num(&mut found_ap as *mut _) })?; @@ -872,9 +872,7 @@ impl<'d> Wifi for WifiDriver<'d> { &mut self, scan_config: &config::ScanConfig, ) -> Result<(heapless::Vec, usize), Self::Error> { - let res = WifiDriver::scan_n(self, scan_config)?; - let res_len = res.len(); - Ok((res, res_len)) + WifiDriver::scan_n(self, scan_config) } #[cfg(feature = "alloc")] @@ -896,9 +894,7 @@ impl<'d> Wifi for WifiDriver<'d> { fn get_scan_result_n( &mut self, ) -> Result<(heapless::Vec, usize), Self::Error> { - let res = WifiDriver::get_scan_result_n(self)?; - let res_len = res.len(); - Ok((res, res_len)) + WifiDriver::get_scan_result_n(self) } fn get_scan_result(&mut self) -> Result, Self::Error> { @@ -958,7 +954,7 @@ impl<'d> EspWifi<'d> { pub fn swap_netif( &mut self, - sta_netif: EspNetif, + sta_netif: EspNetif,let res = ap_netif: EspNetif, ) -> Result<(EspNetif, EspNetif), EspError> { self.detach_netif()?; @@ -1042,7 +1038,7 @@ impl<'d> EspWifi<'d> { pub fn scan_n( &mut self, scan_config: &config::ScanConfig, - ) -> Result, EspError> { + ) -> Result<(heapless::Vec, usize), EspError> { self.driver_mut().scan_n(scan_config) } @@ -1064,7 +1060,7 @@ impl<'d> EspWifi<'d> { pub fn get_scan_result_n( &mut self, - ) -> Result, EspError> { + ) -> Result<(heapless::Vec, usize), EspError> { self.driver_mut().get_scan_result_n() } @@ -1157,9 +1153,7 @@ impl<'d> Wifi for EspWifi<'d> { &mut self, scan_config: &config::ScanConfig, ) -> Result<(heapless::Vec, usize), Self::Error> { - let res = EspWifi::scan_n(self, scan_config)?; - let res_len = res.len(); - Ok((res, res_len)) + EspWifi::scan_n(self, scan_config) } fn scan( @@ -1180,9 +1174,7 @@ impl<'d> Wifi for EspWifi<'d> { fn get_scan_result_n( &mut self, ) -> Result<(heapless::Vec, usize), Self::Error> { - let res = EspWifi::get_scan_result_n(self)?; - let res_len = res.len(); - Ok((res, res_len)) + EspWifi::get_scan_result_n(self) } fn get_scan_result(&mut self) -> Result, Self::Error> { From bdbe4950f997d6dfdecd2ea6f48c3130a850788b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alexander=20H=C3=BCbener?= Date: Tue, 13 Dec 2022 12:21:05 +0100 Subject: [PATCH 12/14] fixed fmt --- src/wifi.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/wifi.rs b/src/wifi.rs index ccb3148b7cd..187a6ba692b 100644 --- a/src/wifi.rs +++ b/src/wifi.rs @@ -954,7 +954,7 @@ impl<'d> EspWifi<'d> { pub fn swap_netif( &mut self, - sta_netif: EspNetif,let res = + sta_netif: EspNetif, ap_netif: EspNetif, ) -> Result<(EspNetif, EspNetif), EspError> { self.detach_netif()?; From 70998aafaced56a221c9f77c092bd836346dd96d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alexander=20H=C3=BCbener?= Date: Wed, 14 Dec 2022 10:59:42 +0100 Subject: [PATCH 13/14] moved scan config back --- src/wifi.rs | 155 ++++++++++++++++++++++++++++++++-------------------- 1 file changed, 97 insertions(+), 58 deletions(-) diff --git a/src/wifi.rs b/src/wifi.rs index 187a6ba692b..c933df8c456 100644 --- a/src/wifi.rs +++ b/src/wifi.rs @@ -30,9 +30,91 @@ use crate::private::cstr::*; use crate::private::mutex; use crate::private::waitable::*; -impl From<&config::ScanConfig> for Newtype { - fn from(s: &config::ScanConfig) -> Self { - Newtype(wifi_scan_config_t { +pub mod config { + + use esp_idf_sys::*; + + #[derive(Clone, Copy, Debug, PartialEq, Eq)] + #[repr(u32)] + pub enum ScanType { + Active = 0, + Passive = 1, + } + + impl ScanType { + pub const fn new() -> Self { + Self::Active + } + } + + impl From for u32 { + fn from(s: ScanType) -> Self { + match s { + ScanType::Active => 0, + ScanType::Passive => 1, + } + } + } + + impl Default for ScanType { + fn default() -> Self { + Self::new() + } + } + + #[derive(Clone, Debug, PartialEq, Eq)] + pub struct ScanTime { + pub active: (u32, u32), + pub passive: u32, + } + + impl ScanTime { + pub const fn new() -> Self { + Self { + active: (0, 0), + passive: 0, + } + } + } + + impl Default for ScanTime { + fn default() -> Self { + Self::new() + } + } + + #[derive(Clone, Debug, PartialEq, Eq)] + pub struct ScanConfig { + pub bssid: Option<[u8; 6]>, + pub ssid: Option>, + pub channel: Option, + pub scan_type: ScanType, + pub scan_time: ScanTime, + pub show_hidden: bool, + } + + impl ScanConfig { + pub const fn new() -> Self { + Self { + bssid: None, + ssid: None, + channel: None, + scan_type: ScanType::new(), + scan_time: ScanTime::new(), + show_hidden: false, + } + } + } + + impl Default for ScanConfig { + fn default() -> Self { + Self::new() + } + } + + impl From<&ScanConfig> for wifi_scan_config_t { + fn from(s: &ScanConfig) -> Self { + Self { bssid: s.bssid.map_or(core::ptr::null(), |v| v.as_ptr()) as *mut u8, ssid: s.ssid.as_ref().map_or(core::ptr::null(), |v| v.as_ptr()) as *mut u8, scan_time: wifi_scan_time_t { @@ -45,7 +127,8 @@ impl From<&config::ScanConfig> for Newtype { channel: s.channel.unwrap_or_default(), scan_type: s.scan_type.into(), show_hidden: s.show_hidden, - }) + } + } } } @@ -559,8 +642,8 @@ impl<'d> WifiDriver<'d> { pub fn start_scan(&mut self, scan_config: &config::ScanConfig) -> Result<(), EspError> { info!("About to scan for access points"); - let scan_config: Newtype = scan_config.into(); - esp!(unsafe { esp_wifi_scan_start(&scan_config.0 as *const wifi_scan_config_t, false) }) + let scan_config: wifi_scan_config_t = scan_config.into(); + esp!(unsafe { esp_wifi_scan_start(&scan_config as *const wifi_scan_config_t, false) }) } pub fn stop_scan(&mut self) -> Result<(), EspError> { @@ -742,10 +825,10 @@ impl<'d> WifiDriver<'d> { esp!(esp_wifi_start())?; } - let scan_config: Newtype = scan_config.into(); + let scan_config: wifi_scan_config_t = scan_config.into(); unsafe { esp!(esp_wifi_scan_start( - &scan_config.0 as *const wifi_scan_config_t, + &scan_config as *const wifi_scan_config_t, true )) } @@ -870,35 +953,13 @@ impl<'d> Wifi for WifiDriver<'d> { fn scan_n( &mut self, - scan_config: &config::ScanConfig, ) -> Result<(heapless::Vec, usize), Self::Error> { - WifiDriver::scan_n(self, scan_config) + WifiDriver::scan_n(self, &config::ScanConfig::default()) } #[cfg(feature = "alloc")] - fn scan( - &mut self, - scan_config: &config::ScanConfig, - ) -> Result, Self::Error> { - WifiDriver::scan(self, scan_config) - } - - fn start_scan(&mut self, scan_config: &config::ScanConfig) -> Result<(), Self::Error> { - WifiDriver::start_scan(self, scan_config) - } - - fn stop_scan(&mut self) -> Result<(), Self::Error> { - WifiDriver::stop_scan(self) - } - - fn get_scan_result_n( - &mut self, - ) -> Result<(heapless::Vec, usize), Self::Error> { - WifiDriver::get_scan_result_n(self) - } - - fn get_scan_result(&mut self) -> Result, Self::Error> { - WifiDriver::get_scan_result(self) + fn scan(&mut self) -> Result, Self::Error> { + WifiDriver::scan(self, &config::ScanConfig::default()) } } @@ -1151,34 +1212,12 @@ impl<'d> Wifi for EspWifi<'d> { fn scan_n( &mut self, - scan_config: &config::ScanConfig, - ) -> Result<(heapless::Vec, usize), Self::Error> { - EspWifi::scan_n(self, scan_config) - } - - fn scan( - &mut self, - scan_config: &config::ScanConfig, - ) -> Result, Self::Error> { - EspWifi::scan(self, scan_config) - } - - fn start_scan(&mut self, scan_config: &config::ScanConfig) -> Result<(), Self::Error> { - EspWifi::start_scan(self, scan_config) - } - - fn stop_scan(&mut self) -> Result<(), Self::Error> { - EspWifi::stop_scan(self) - } - - fn get_scan_result_n( - &mut self, ) -> Result<(heapless::Vec, usize), Self::Error> { - EspWifi::get_scan_result_n(self) + EspWifi::scan_n(self, &config::ScanConfig::default()) } - fn get_scan_result(&mut self) -> Result, Self::Error> { - EspWifi::get_scan_result(self) + fn scan(&mut self) -> Result, Self::Error> { + EspWifi::scan(self, &config::ScanConfig::default()) } } From 39c8a756bb67351362cd34a1c39b34ad3b6acf44 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alexander=20H=C3=BCbener?= Date: Wed, 14 Dec 2022 10:59:57 +0100 Subject: [PATCH 14/14] renamed functions --- src/wifi.rs | 34 +++++++++++++++++----------------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/src/wifi.rs b/src/wifi.rs index c933df8c456..de7863c1f9f 100644 --- a/src/wifi.rs +++ b/src/wifi.rs @@ -115,18 +115,18 @@ pub mod config { impl From<&ScanConfig> for wifi_scan_config_t { fn from(s: &ScanConfig) -> Self { Self { - bssid: s.bssid.map_or(core::ptr::null(), |v| v.as_ptr()) as *mut u8, - ssid: s.ssid.as_ref().map_or(core::ptr::null(), |v| v.as_ptr()) as *mut u8, - scan_time: wifi_scan_time_t { - active: wifi_active_scan_time_t { - min: s.scan_time.active.0, - max: s.scan_time.active.1, + bssid: s.bssid.map_or(core::ptr::null(), |v| v.as_ptr()) as *mut u8, + ssid: s.ssid.as_ref().map_or(core::ptr::null(), |v| v.as_ptr()) as *mut u8, + scan_time: wifi_scan_time_t { + active: wifi_active_scan_time_t { + min: s.scan_time.active.0, + max: s.scan_time.active.1, + }, + passive: s.scan_time.passive, }, - passive: s.scan_time.passive, - }, - channel: s.channel.unwrap_or_default(), - scan_type: s.scan_type.into(), - show_hidden: s.show_hidden, + channel: s.channel.unwrap_or_default(), + scan_type: s.scan_type.into(), + show_hidden: s.show_hidden, } } } @@ -627,7 +627,7 @@ impl<'d> WifiDriver<'d> { &mut self, scan_config: &config::ScanConfig, ) -> Result<(heapless::Vec, usize), EspError> { - self.do_scan(scan_config)?; + self.do_scan_blocking(scan_config)?; self.get_scan_result_n() } @@ -636,7 +636,7 @@ impl<'d> WifiDriver<'d> { &mut self, scan_config: &config::ScanConfig, ) -> Result, EspError> { - self.do_scan(scan_config)?; + self.do_scan_blocking(scan_config)?; self.get_scan_result() } @@ -660,7 +660,7 @@ impl<'d> WifiDriver<'d> { ap_infos_raw.set_len(scanned_count.min(N)); } - let fetched_count = self.do_get_scan_infos(&mut ap_infos_raw)?; + let fetched_count = self.fetch_scan_result(&mut ap_infos_raw)?; let result = ap_infos_raw[..fetched_count] .iter() @@ -683,7 +683,7 @@ impl<'d> WifiDriver<'d> { ap_infos_raw.set_len(scanned_count) }; - let fetched_count = self.do_get_scan_infos(&mut ap_infos_raw)?; + let fetched_count = self.fetch_scan_result(&mut ap_infos_raw)?; let result = ap_infos_raw[..fetched_count] .iter() @@ -814,7 +814,7 @@ impl<'d> WifiDriver<'d> { Ok(()) } - fn do_scan(&mut self, scan_config: &config::ScanConfig) -> Result<(), EspError> { + fn do_scan_blocking(&mut self, scan_config: &config::ScanConfig) -> Result<(), EspError> { info!("About to scan for access points"); let _ = self.disconnect(); @@ -843,7 +843,7 @@ impl<'d> WifiDriver<'d> { Ok(found_ap as usize) } - fn do_get_scan_infos( + fn fetch_scan_result( &mut self, ap_infos_raw: &mut [wifi_ap_record_t], ) -> Result {