diff options
| author | Dario Nieuwenhuis <[email protected]> | 2023-04-27 18:23:36 +0000 |
|---|---|---|
| committer | GitHub <[email protected]> | 2023-04-27 18:23:36 +0000 |
| commit | c19de2984751ba6fa2972ee66cfa2a6310d5f0c1 (patch) | |
| tree | 9ba8fa01994be9ef43af404cb4399854e8c6de22 /src/control.rs | |
| parent | f4bfda345d3d18232926a87b10333a2e624f4d04 (diff) | |
| parent | 9e96655757180d7fe32ebff1ed93a35a4c3cff28 (diff) | |
Merge pull request #63 from kbleeke/generalize-events
rework event handling to allow sending data to `Control`
Diffstat (limited to 'src/control.rs')
| -rw-r--r-- | src/control.rs | 21 |
1 files changed, 12 insertions, 9 deletions
diff --git a/src/control.rs b/src/control.rs index 30d5d0924..0c06009b9 100644 --- a/src/control.rs +++ b/src/control.rs | |||
| @@ -6,7 +6,7 @@ use embassy_time::{Duration, Timer}; | |||
| 6 | 6 | ||
| 7 | pub use crate::bus::SpiBusCyw43; | 7 | pub use crate::bus::SpiBusCyw43; |
| 8 | use crate::consts::*; | 8 | use crate::consts::*; |
| 9 | use crate::events::{Event, EventQueue}; | 9 | use crate::events::{Event, Events}; |
| 10 | use crate::fmt::Bytes; | 10 | use crate::fmt::Bytes; |
| 11 | use crate::ioctl::{IoctlState, IoctlType}; | 11 | use crate::ioctl::{IoctlState, IoctlType}; |
| 12 | use crate::structs::*; | 12 | use crate::structs::*; |
| @@ -14,15 +14,15 @@ use crate::{countries, PowerManagementMode}; | |||
| 14 | 14 | ||
| 15 | pub struct Control<'a> { | 15 | pub struct Control<'a> { |
| 16 | state_ch: ch::StateRunner<'a>, | 16 | state_ch: ch::StateRunner<'a>, |
| 17 | event_sub: &'a EventQueue, | 17 | events: &'a Events, |
| 18 | ioctl_state: &'a IoctlState, | 18 | ioctl_state: &'a IoctlState, |
| 19 | } | 19 | } |
| 20 | 20 | ||
| 21 | impl<'a> Control<'a> { | 21 | impl<'a> Control<'a> { |
| 22 | pub(crate) fn new(state_ch: ch::StateRunner<'a>, event_sub: &'a EventQueue, ioctl_state: &'a IoctlState) -> Self { | 22 | pub(crate) fn new(state_ch: ch::StateRunner<'a>, event_sub: &'a Events, ioctl_state: &'a IoctlState) -> Self { |
| 23 | Self { | 23 | Self { |
| 24 | state_ch, | 24 | state_ch, |
| 25 | event_sub, | 25 | events: event_sub, |
| 26 | ioctl_state, | 26 | ioctl_state, |
| 27 | } | 27 | } |
| 28 | } | 28 | } |
| @@ -195,24 +195,27 @@ impl<'a> Control<'a> { | |||
| 195 | } | 195 | } |
| 196 | 196 | ||
| 197 | async fn wait_for_join(&mut self, i: SsidInfo) { | 197 | async fn wait_for_join(&mut self, i: SsidInfo) { |
| 198 | let mut subscriber = self.event_sub.subscriber().unwrap(); | 198 | self.events.mask.enable(&[Event::JOIN, Event::AUTH]); |
| 199 | let mut subscriber = self.events.queue.subscriber().unwrap(); | ||
| 200 | // the actual join operation starts here | ||
| 201 | // we make sure to enable events before so we don't miss any | ||
| 199 | self.ioctl(IoctlType::Set, IOCTL_CMD_SET_SSID, 0, &mut i.to_bytes()) | 202 | self.ioctl(IoctlType::Set, IOCTL_CMD_SET_SSID, 0, &mut i.to_bytes()) |
| 200 | .await; | 203 | .await; |
| 201 | // set_ssid | 204 | // set_ssid |
| 202 | 205 | ||
| 203 | loop { | 206 | loop { |
| 204 | let msg = subscriber.next_message_pure().await; | 207 | let msg = subscriber.next_message_pure().await; |
| 205 | if msg.event_type == Event::AUTH && msg.status != 0 { | 208 | if msg.header.event_type == Event::AUTH && msg.header.status != EStatus::SUCCESS { |
| 206 | // retry | 209 | // retry |
| 207 | warn!("JOIN failed with status={}", msg.status); | 210 | warn!("JOIN failed with status={}", msg.header.status); |
| 208 | self.ioctl(IoctlType::Set, IOCTL_CMD_SET_SSID, 0, &mut i.to_bytes()) | 211 | self.ioctl(IoctlType::Set, IOCTL_CMD_SET_SSID, 0, &mut i.to_bytes()) |
| 209 | .await; | 212 | .await; |
| 210 | } else if msg.event_type == Event::JOIN && msg.status == 0 { | 213 | } else if msg.header.event_type == Event::JOIN && msg.header.status == EStatus::SUCCESS { |
| 211 | // successful join | 214 | // successful join |
| 212 | break; | 215 | break; |
| 213 | } | 216 | } |
| 214 | } | 217 | } |
| 215 | 218 | self.events.mask.disable_all(); | |
| 216 | self.state_ch.set_link_state(LinkState::Up); | 219 | self.state_ch.set_link_state(LinkState::Up); |
| 217 | info!("JOINED"); | 220 | info!("JOINED"); |
| 218 | } | 221 | } |
