From 2d7ba44621fa35abad07d2ddb8b253e815ce2c1f Mon Sep 17 00:00:00 2001 From: kbleeke Date: Sun, 2 Apr 2023 20:19:47 +0200 Subject: rework event handling to allow sending data --- src/control.rs | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) (limited to 'src/control.rs') diff --git a/src/control.rs b/src/control.rs index 30d5d0924..824c55125 100644 --- a/src/control.rs +++ b/src/control.rs @@ -6,7 +6,7 @@ use embassy_time::{Duration, Timer}; pub use crate::bus::SpiBusCyw43; use crate::consts::*; -use crate::events::{Event, EventQueue}; +use crate::events::{Event, Events}; use crate::fmt::Bytes; use crate::ioctl::{IoctlState, IoctlType}; use crate::structs::*; @@ -14,15 +14,15 @@ use crate::{countries, PowerManagementMode}; pub struct Control<'a> { state_ch: ch::StateRunner<'a>, - event_sub: &'a EventQueue, + events: &'a Events, ioctl_state: &'a IoctlState, } impl<'a> Control<'a> { - pub(crate) fn new(state_ch: ch::StateRunner<'a>, event_sub: &'a EventQueue, ioctl_state: &'a IoctlState) -> Self { + pub(crate) fn new(state_ch: ch::StateRunner<'a>, event_sub: &'a Events, ioctl_state: &'a IoctlState) -> Self { Self { state_ch, - event_sub, + events: event_sub, ioctl_state, } } @@ -195,24 +195,25 @@ impl<'a> Control<'a> { } async fn wait_for_join(&mut self, i: SsidInfo) { - let mut subscriber = self.event_sub.subscriber().unwrap(); + self.events.mask.enable(&[Event::JOIN, Event::AUTH]); + let mut subscriber = self.events.queue.subscriber().unwrap(); self.ioctl(IoctlType::Set, IOCTL_CMD_SET_SSID, 0, &mut i.to_bytes()) .await; // set_ssid loop { let msg = subscriber.next_message_pure().await; - if msg.event_type == Event::AUTH && msg.status != 0 { + if msg.header.event_type == Event::AUTH && msg.header.status != 0 { // retry - warn!("JOIN failed with status={}", msg.status); + warn!("JOIN failed with status={}", msg.header.status); self.ioctl(IoctlType::Set, IOCTL_CMD_SET_SSID, 0, &mut i.to_bytes()) .await; - } else if msg.event_type == Event::JOIN && msg.status == 0 { + } else if msg.header.event_type == Event::JOIN && msg.header.status == 0 { // successful join break; } } - + self.events.mask.disable_all(); self.state_ch.set_link_state(LinkState::Up); info!("JOINED"); } -- cgit From 9e96655757180d7fe32ebff1ed93a35a4c3cff28 Mon Sep 17 00:00:00 2001 From: kbleeke Date: Tue, 25 Apr 2023 19:08:47 +0200 Subject: comment some choices for current event handling --- src/control.rs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'src/control.rs') diff --git a/src/control.rs b/src/control.rs index 824c55125..0c06009b9 100644 --- a/src/control.rs +++ b/src/control.rs @@ -197,18 +197,20 @@ impl<'a> Control<'a> { async fn wait_for_join(&mut self, i: SsidInfo) { self.events.mask.enable(&[Event::JOIN, Event::AUTH]); let mut subscriber = self.events.queue.subscriber().unwrap(); + // the actual join operation starts here + // we make sure to enable events before so we don't miss any self.ioctl(IoctlType::Set, IOCTL_CMD_SET_SSID, 0, &mut i.to_bytes()) .await; // set_ssid loop { let msg = subscriber.next_message_pure().await; - if msg.header.event_type == Event::AUTH && msg.header.status != 0 { + if msg.header.event_type == Event::AUTH && msg.header.status != EStatus::SUCCESS { // retry warn!("JOIN failed with status={}", msg.header.status); self.ioctl(IoctlType::Set, IOCTL_CMD_SET_SSID, 0, &mut i.to_bytes()) .await; - } else if msg.header.event_type == Event::JOIN && msg.header.status == 0 { + } else if msg.header.event_type == Event::JOIN && msg.header.status == EStatus::SUCCESS { // successful join break; } -- cgit