From 073110c73724f027449ef7692b4663a5f0739f77 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gianguido=20Sor=C3=A0?= Date: Thu, 13 Oct 2022 17:58:52 +0200 Subject: [PATCH] net: add method to turn on wifi without scanning --- services/net/src/connection_manager.rs | 26 ++++++++++++++++++++++++++ services/net/src/lib.rs | 5 +++++ services/net/src/main.rs | 22 ++++++++++++++++++---- 3 files changed, 49 insertions(+), 4 deletions(-) diff --git a/services/net/src/connection_manager.rs b/services/net/src/connection_manager.rs index 372225767..93a85ea11 100644 --- a/services/net/src/connection_manager.rs +++ b/services/net/src/connection_manager.rs @@ -26,6 +26,7 @@ pub(crate) enum ConnectionManagerOpcode { Stop, DisconnectAndStop, WifiOnAndRun, + WifiOn, SubscribeWifiStats, UnsubWifiStats, FetchSsidList, @@ -511,6 +512,31 @@ pub(crate) fn connection_manager(sid: xous::SID, activity_interval: Arc msg_scalar_unpack!(msg, _, _, _, _, { + com.wlan_set_on().expect("couldn't turn on wifi"); + wifi_state = WifiState::Disconnected; + ssid_list.clear(); + com.set_ssid_scanning(false).unwrap(); + scan_state = SsidScanState::Idle; + intervals_without_activity = 0; + scan_count = 0; + // this will force the UI to transition from 'WiFi Off' -> 'Not connected' + wifi_stats_cache = WlanStatus { + ssid: None, + link_state: com_rs_ref::LinkState::Disconnected, + ipv4: com::Ipv4Conf::default(), + }; + log::debug!("stats update: {:?}", wifi_stats_cache); + for &sub in status_subscribers.keys() { + let buf = Buffer::into_buf(com::WlanStatusIpc::from_status(wifi_stats_cache)).or(Err(xous::Error::InternalError)).unwrap(); + buf.send(sub, WifiStateCallback::Update.to_u32().unwrap()).or(Err(xous::Error::InternalError)).unwrap(); + } + if !run.swap(true, Ordering::SeqCst) { + if !pumping.load(Ordering::SeqCst) { // avoid having multiple pump messages being sent if a user tries to rapidly toggle the run/stop switch + send_message(run_cid, Message::new_scalar(PumpOp::Pump.to_usize().unwrap(), 0, 0, 0, 0)).expect("couldn't kick off next poll"); + } + } + }), Some(ConnectionManagerOpcode::DisconnectAndStop) => { run.store(false, Ordering::SeqCst); wifi_state = WifiState::Off; diff --git a/services/net/src/lib.rs b/services/net/src/lib.rs index 1acda17c1..331c1e41c 100644 --- a/services/net/src/lib.rs +++ b/services/net/src/lib.rs @@ -180,6 +180,11 @@ impl NetManager { Message::new_scalar(Opcode::ConnMgrStartStop.to_usize().unwrap(), 3, 0,0, 0) ).map(|_| ()) } + pub fn connection_manager_wifi_on(&self) -> Result<(), xous::Error> { + send_message(self.netconn.conn(), + Message::new_scalar(Opcode::ConnMgrStartStop.to_usize().unwrap(), 4, 0,0, 0) + ).map(|_| ()) + } } impl Drop for NetManager { fn drop(&mut self) { diff --git a/services/net/src/main.rs b/services/net/src/main.rs index b772691c5..cace6d535 100644 --- a/services/net/src/main.rs +++ b/services/net/src/main.rs @@ -2103,7 +2103,7 @@ fn main() -> ! { 0, ), ) - .expect("couldn't send stop message"); + .expect("couldn't send scan stop message"); } else if code == 1 { send_message( cm_cid, @@ -2117,7 +2117,7 @@ fn main() -> ! { 0, ), ) - .expect("couldn't send stop message"); + .expect("couldn't send scan run message"); } else if code == 2 { send_message( cm_cid, @@ -2131,7 +2131,7 @@ fn main() -> ! { 0, ), ) - .expect("couldn't send disconnect and stop message"); + .expect("couldn't send wifi disconnect and stop message"); } else if code == 3 { send_message( cm_cid, @@ -2145,7 +2145,21 @@ fn main() -> ! { 0, ), ) - .expect("couldn't send disconnect and stop message"); + .expect("couldn't send wifi on and run message"); + } else if code == 4 { + send_message( + cm_cid, + Message::new_scalar( + connection_manager::ConnectionManagerOpcode::WifiOn + .to_usize() + .unwrap(), + 0, + 0, + 0, + 0, + ), + ) + .expect("couldn't send wifi on message"); } else { log::error!("Got incorrect start/stop code: {}", code); }