diff options
| author | kbleeke <[email protected]> | 2023-04-02 20:19:47 +0200 |
|---|---|---|
| committer | kbleeke <[email protected]> | 2023-04-25 19:14:00 +0200 |
| commit | 2d7ba44621fa35abad07d2ddb8b253e815ce2c1f (patch) | |
| tree | 999561ce27e3662a22ee2590c79eaa0791099953 /src/control.rs | |
| parent | 6a1a3e6877053b1b72adb3c1446f4f077ad3b03e (diff) | |
rework event handling to allow sending data
Diffstat (limited to 'src/control.rs')
| -rw-r--r-- | src/control.rs | 19 |
1 files changed, 10 insertions, 9 deletions
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}; | |||
| 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,25 @@ 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(); | ||
| 199 | self.ioctl(IoctlType::Set, IOCTL_CMD_SET_SSID, 0, &mut i.to_bytes()) | 200 | self.ioctl(IoctlType::Set, IOCTL_CMD_SET_SSID, 0, &mut i.to_bytes()) |
| 200 | .await; | 201 | .await; |
| 201 | // set_ssid | 202 | // set_ssid |
| 202 | 203 | ||
| 203 | loop { | 204 | loop { |
| 204 | let msg = subscriber.next_message_pure().await; | 205 | let msg = subscriber.next_message_pure().await; |
| 205 | if msg.event_type == Event::AUTH && msg.status != 0 { | 206 | if msg.header.event_type == Event::AUTH && msg.header.status != 0 { |
| 206 | // retry | 207 | // retry |
| 207 | warn!("JOIN failed with status={}", msg.status); | 208 | warn!("JOIN failed with status={}", msg.header.status); |
| 208 | self.ioctl(IoctlType::Set, IOCTL_CMD_SET_SSID, 0, &mut i.to_bytes()) | 209 | self.ioctl(IoctlType::Set, IOCTL_CMD_SET_SSID, 0, &mut i.to_bytes()) |
| 209 | .await; | 210 | .await; |
| 210 | } else if msg.event_type == Event::JOIN && msg.status == 0 { | 211 | } else if msg.header.event_type == Event::JOIN && msg.header.status == 0 { |
| 211 | // successful join | 212 | // successful join |
| 212 | break; | 213 | break; |
| 213 | } | 214 | } |
| 214 | } | 215 | } |
| 215 | 216 | self.events.mask.disable_all(); | |
| 216 | self.state_ch.set_link_state(LinkState::Up); | 217 | self.state_ch.set_link_state(LinkState::Up); |
| 217 | info!("JOINED"); | 218 | info!("JOINED"); |
| 218 | } | 219 | } |
