diff options
Diffstat (limited to 'embassy-net-nrf91/src/context.rs')
| -rw-r--r-- | embassy-net-nrf91/src/context.rs | 20 |
1 files changed, 12 insertions, 8 deletions
diff --git a/embassy-net-nrf91/src/context.rs b/embassy-net-nrf91/src/context.rs index 511468316..6b841aa16 100644 --- a/embassy-net-nrf91/src/context.rs +++ b/embassy-net-nrf91/src/context.rs | |||
| @@ -275,24 +275,28 @@ impl<'a> Control<'a> { | |||
| 275 | }) | 275 | }) |
| 276 | } | 276 | } |
| 277 | 277 | ||
| 278 | /// Run a control loop for this context, ensuring that reaattach is handled. | 278 | async fn wait_attached(&self) -> Result<Status, Error> { |
| 279 | pub async fn run<F: Fn(&Status)>(&self, config: &Config<'_>, reattach: F) -> Result<(), Error> { | ||
| 280 | self.configure(config).await?; | ||
| 281 | while !self.attached().await? { | 279 | while !self.attached().await? { |
| 282 | Timer::after(Duration::from_secs(1)).await; | 280 | Timer::after(Duration::from_secs(1)).await; |
| 283 | } | 281 | } |
| 284 | let status = self.status().await?; | 282 | let status = self.status().await?; |
| 283 | Ok(status) | ||
| 284 | } | ||
| 285 | |||
| 286 | /// Run a control loop for this context, ensuring that reaattach is handled. | ||
| 287 | pub async fn run<F: Fn(&Status)>(&self, config: &Config<'_>, reattach: F) -> Result<(), Error> { | ||
| 288 | self.configure(config).await?; | ||
| 289 | let status = self.wait_attached().await?; | ||
| 285 | let mut fd = self.control.open_raw_socket().await; | 290 | let mut fd = self.control.open_raw_socket().await; |
| 286 | reattach(&status); | 291 | reattach(&status); |
| 287 | 292 | ||
| 288 | loop { | 293 | loop { |
| 289 | if !self.attached().await? { | 294 | if !self.attached().await? { |
| 295 | trace!("detached"); | ||
| 296 | |||
| 290 | self.control.close_raw_socket(fd).await; | 297 | self.control.close_raw_socket(fd).await; |
| 291 | self.attach().await?; | 298 | let status = self.wait_attached().await?; |
| 292 | while !self.attached().await? { | 299 | trace!("attached"); |
| 293 | Timer::after(Duration::from_secs(1)).await; | ||
| 294 | } | ||
| 295 | let status = self.status().await?; | ||
| 296 | fd = self.control.open_raw_socket().await; | 300 | fd = self.control.open_raw_socket().await; |
| 297 | reattach(&status); | 301 | reattach(&status); |
| 298 | } | 302 | } |
