diff options
| author | Ulf Lilleengen <[email protected]> | 2024-09-04 19:31:55 +0200 |
|---|---|---|
| committer | Ulf Lilleengen <[email protected]> | 2024-09-04 19:31:55 +0200 |
| commit | ccfa6264b0ad258625f2dd667ba8e6eaca1cfdc3 (patch) | |
| tree | afd078095d2090b9641ee58ee3d47b9177f95e75 /embassy-net-nrf91/src | |
| parent | 372e45dabc0cfd3eb495e902665bb752a67aa804 (diff) | |
Add closing if raw socket to handle re-attach
Diffstat (limited to 'embassy-net-nrf91/src')
| -rw-r--r-- | embassy-net-nrf91/src/context.rs | 8 | ||||
| -rw-r--r-- | embassy-net-nrf91/src/lib.rs | 15 |
2 files changed, 18 insertions, 5 deletions
diff --git a/embassy-net-nrf91/src/context.rs b/embassy-net-nrf91/src/context.rs index f73719224..511468316 100644 --- a/embassy-net-nrf91/src/context.rs +++ b/embassy-net-nrf91/src/context.rs | |||
| @@ -4,8 +4,8 @@ use core::str::FromStr; | |||
| 4 | 4 | ||
| 5 | use at_commands::builder::CommandBuilder; | 5 | use at_commands::builder::CommandBuilder; |
| 6 | use at_commands::parser::CommandParser; | 6 | use at_commands::parser::CommandParser; |
| 7 | use embassy_time::{Duration, Timer}; | ||
| 7 | use heapless::Vec; | 8 | use heapless::Vec; |
| 8 | use embassy_time::{Timer, Duration}; | ||
| 9 | 9 | ||
| 10 | /// Provides a higher level API for controlling a given context. | 10 | /// Provides a higher level API for controlling a given context. |
| 11 | pub struct Control<'a> { | 11 | pub struct Control<'a> { |
| @@ -129,8 +129,6 @@ impl<'a> Control<'a> { | |||
| 129 | let n = self.control.at_command(op, &mut buf).await; | 129 | let n = self.control.at_command(op, &mut buf).await; |
| 130 | CommandParser::parse(&buf[..n]).expect_identifier(b"OK").finish()?; | 130 | CommandParser::parse(&buf[..n]).expect_identifier(b"OK").finish()?; |
| 131 | 131 | ||
| 132 | |||
| 133 | |||
| 134 | Ok(()) | 132 | Ok(()) |
| 135 | } | 133 | } |
| 136 | 134 | ||
| @@ -289,13 +287,13 @@ impl<'a> Control<'a> { | |||
| 289 | 287 | ||
| 290 | loop { | 288 | loop { |
| 291 | if !self.attached().await? { | 289 | if !self.attached().await? { |
| 292 | // TODO: self.control.close_raw_socket(fd).await; | 290 | self.control.close_raw_socket(fd).await; |
| 293 | self.attach().await?; | 291 | self.attach().await?; |
| 294 | while !self.attached().await? { | 292 | while !self.attached().await? { |
| 295 | Timer::after(Duration::from_secs(1)).await; | 293 | Timer::after(Duration::from_secs(1)).await; |
| 296 | } | 294 | } |
| 297 | let status = self.status().await?; | 295 | let status = self.status().await?; |
| 298 | // TODO: let mut fd = self.control.open_raw_socket().await; | 296 | fd = self.control.open_raw_socket().await; |
| 299 | reattach(&status); | 297 | reattach(&status); |
| 300 | } | 298 | } |
| 301 | Timer::after(Duration::from_secs(10)).await; | 299 | Timer::after(Duration::from_secs(10)).await; |
diff --git a/embassy-net-nrf91/src/lib.rs b/embassy-net-nrf91/src/lib.rs index ab3c6f327..d8cbe47fc 100644 --- a/embassy-net-nrf91/src/lib.rs +++ b/embassy-net-nrf91/src/lib.rs | |||
| @@ -870,6 +870,21 @@ impl<'a> Control<'a> { | |||
| 870 | trace!("got FD: {}", fd); | 870 | trace!("got FD: {}", fd); |
| 871 | fd | 871 | fd |
| 872 | } | 872 | } |
| 873 | |||
| 874 | async fn close_raw_socket(&self, fd: u32) { | ||
| 875 | let mut msg: Message = unsafe { mem::zeroed() }; | ||
| 876 | msg.channel = 2; // data | ||
| 877 | msg.id = 0x7009_0004; // close socket | ||
| 878 | msg.param_len = 8; | ||
| 879 | msg.param[4..8].copy_from_slice(&fd.to_le_bytes()); | ||
| 880 | |||
| 881 | self.request(&mut msg, &[], &mut []).await; | ||
| 882 | |||
| 883 | assert_eq!(msg.id, 0x80090004); | ||
| 884 | assert!(msg.param_len >= 12); | ||
| 885 | let status = u32::from_le_bytes(msg.param[8..12].try_into().unwrap()); | ||
| 886 | assert_eq!(status, 0); | ||
| 887 | } | ||
| 873 | } | 888 | } |
| 874 | 889 | ||
| 875 | /// Background runner for the driver. | 890 | /// Background runner for the driver. |
