diff options
| author | Ulf Lilleengen <[email protected]> | 2024-09-04 14:21:13 +0200 |
|---|---|---|
| committer | Ulf Lilleengen <[email protected]> | 2024-09-04 14:21:13 +0200 |
| commit | 49881f6fd1e3d77d63dea2313afb5201eca8ebd9 (patch) | |
| tree | f0739a1ce66c93c418e4d13baa3a7866a0a924e9 /embassy-net-nrf91 | |
| parent | b4221d75b87664485977d37df28f7319143411fc (diff) | |
rustfmt
Diffstat (limited to 'embassy-net-nrf91')
| -rw-r--r-- | embassy-net-nrf91/src/context.rs | 45 | ||||
| -rw-r--r-- | embassy-net-nrf91/src/lib.rs | 8 |
2 files changed, 34 insertions, 19 deletions
diff --git a/embassy-net-nrf91/src/context.rs b/embassy-net-nrf91/src/context.rs index 9c67cbc9f..954830417 100644 --- a/embassy-net-nrf91/src/context.rs +++ b/embassy-net-nrf91/src/context.rs | |||
| @@ -1,8 +1,10 @@ | |||
| 1 | //! Helper utility to configure a specific modem context. | 1 | //! Helper utility to configure a specific modem context. |
| 2 | use core::net::IpAddr; | 2 | use core::net::IpAddr; |
| 3 | use core::str::FromStr; | 3 | use core::str::FromStr; |
| 4 | |||
| 5 | use at_commands::builder::CommandBuilder; | ||
| 6 | use at_commands::parser::CommandParser; | ||
| 4 | use heapless::Vec; | 7 | use heapless::Vec; |
| 5 | use at_commands::{builder::CommandBuilder, parser::CommandParser}; | ||
| 6 | 8 | ||
| 7 | /// Provides a higher level API for controlling a given context. | 9 | /// Provides a higher level API for controlling a given context. |
| 8 | pub struct Control<'a> { | 10 | pub struct Control<'a> { |
| @@ -91,7 +93,8 @@ impl<'a> Control<'a> { | |||
| 91 | .with_int_parameter(self.cid) | 93 | .with_int_parameter(self.cid) |
| 92 | .with_string_parameter("IP") | 94 | .with_string_parameter("IP") |
| 93 | .with_string_parameter(config.apn) | 95 | .with_string_parameter(config.apn) |
| 94 | .finish().map_err(|_| Error::BufferTooSmall)?; | 96 | .finish() |
| 97 | .map_err(|_| Error::BufferTooSmall)?; | ||
| 95 | let n = self.control.at_command(op, &mut buf).await; | 98 | let n = self.control.at_command(op, &mut buf).await; |
| 96 | CommandParser::parse(&buf[..n]).expect_identifier(b"OK").finish()?; | 99 | CommandParser::parse(&buf[..n]).expect_identifier(b"OK").finish()?; |
| 97 | 100 | ||
| @@ -110,7 +113,8 @@ impl<'a> Control<'a> { | |||
| 110 | let op = CommandBuilder::create_set(&mut cmd, true) | 113 | let op = CommandBuilder::create_set(&mut cmd, true) |
| 111 | .named("+CFUN") | 114 | .named("+CFUN") |
| 112 | .with_int_parameter(1) | 115 | .with_int_parameter(1) |
| 113 | .finish().map_err(|_| Error::BufferTooSmall)?; | 116 | .finish() |
| 117 | .map_err(|_| Error::BufferTooSmall)?; | ||
| 114 | let n = self.control.at_command(op, &mut buf).await; | 118 | let n = self.control.at_command(op, &mut buf).await; |
| 115 | CommandParser::parse(&buf[..n]).expect_identifier(b"OK").finish()?; | 119 | CommandParser::parse(&buf[..n]).expect_identifier(b"OK").finish()?; |
| 116 | 120 | ||
| @@ -124,28 +128,37 @@ impl<'a> Control<'a> { | |||
| 124 | 128 | ||
| 125 | let op = CommandBuilder::create_query(&mut cmd, true) | 129 | let op = CommandBuilder::create_query(&mut cmd, true) |
| 126 | .named("+CGATT") | 130 | .named("+CGATT") |
| 127 | .finish().map_err(|_| Error::BufferTooSmall)?; | 131 | .finish() |
| 132 | .map_err(|_| Error::BufferTooSmall)?; | ||
| 128 | let n = self.control.at_command(op, &mut buf).await; | 133 | let n = self.control.at_command(op, &mut buf).await; |
| 129 | let (res, ) = CommandParser::parse(&buf[..n]) | 134 | let (res,) = CommandParser::parse(&buf[..n]) |
| 130 | .expect_identifier(b"+CGATT: ") | 135 | .expect_identifier(b"+CGATT: ") |
| 131 | .expect_int_parameter() | 136 | .expect_int_parameter() |
| 132 | .expect_identifier(b"\r\nOK").finish()?; | 137 | .expect_identifier(b"\r\nOK") |
| 138 | .finish()?; | ||
| 133 | let attached = res == 1; | 139 | let attached = res == 1; |
| 134 | if !attached { | 140 | if !attached { |
| 135 | return Ok(Status { attached, ip: None, gateway: None, dns: Vec::new() }) | 141 | return Ok(Status { |
| 142 | attached, | ||
| 143 | ip: None, | ||
| 144 | gateway: None, | ||
| 145 | dns: Vec::new(), | ||
| 146 | }); | ||
| 136 | } | 147 | } |
| 137 | 148 | ||
| 138 | let op = CommandBuilder::create_set(&mut cmd, true) | 149 | let op = CommandBuilder::create_set(&mut cmd, true) |
| 139 | .named("+CGPADDR") | 150 | .named("+CGPADDR") |
| 140 | .with_int_parameter(self.cid) | 151 | .with_int_parameter(self.cid) |
| 141 | .finish().map_err(|_| Error::BufferTooSmall)?; | 152 | .finish() |
| 153 | .map_err(|_| Error::BufferTooSmall)?; | ||
| 142 | let n = self.control.at_command(op, &mut buf).await; | 154 | let n = self.control.at_command(op, &mut buf).await; |
| 143 | let (_, ip1, _ip2, ) = CommandParser::parse(&buf[..n]) | 155 | let (_, ip1, _ip2) = CommandParser::parse(&buf[..n]) |
| 144 | .expect_identifier(b"+CGPADDR: ") | 156 | .expect_identifier(b"+CGPADDR: ") |
| 145 | .expect_int_parameter() | 157 | .expect_int_parameter() |
| 146 | .expect_optional_string_parameter() | 158 | .expect_optional_string_parameter() |
| 147 | .expect_optional_string_parameter() | 159 | .expect_optional_string_parameter() |
| 148 | .expect_identifier(b"\r\nOK").finish()?; | 160 | .expect_identifier(b"\r\nOK") |
| 161 | .finish()?; | ||
| 149 | 162 | ||
| 150 | let ip = if let Some(ip) = ip1 { | 163 | let ip = if let Some(ip) = ip1 { |
| 151 | let ip = IpAddr::from_str(ip).map_err(|_| Error::AddrParseError)?; | 164 | let ip = IpAddr::from_str(ip).map_err(|_| Error::AddrParseError)?; |
| @@ -158,7 +171,8 @@ impl<'a> Control<'a> { | |||
| 158 | let op = CommandBuilder::create_set(&mut cmd, true) | 171 | let op = CommandBuilder::create_set(&mut cmd, true) |
| 159 | .named("+CGCONTRDP") | 172 | .named("+CGCONTRDP") |
| 160 | .with_int_parameter(self.cid) | 173 | .with_int_parameter(self.cid) |
| 161 | .finish().map_err(|_| Error::BufferTooSmall)?; | 174 | .finish() |
| 175 | .map_err(|_| Error::BufferTooSmall)?; | ||
| 162 | let n = self.control.at_command(op, &mut buf).await; | 176 | let n = self.control.at_command(op, &mut buf).await; |
| 163 | let (_cid, _bid, _apn, _mask, gateway, dns1, dns2, _, _, _, _, _mtu) = CommandParser::parse(&buf[..n]) | 177 | let (_cid, _bid, _apn, _mask, gateway, dns1, dns2, _, _, _, _, _mtu) = CommandParser::parse(&buf[..n]) |
| 164 | .expect_identifier(b"+CGCONTRDP: ") | 178 | .expect_identifier(b"+CGCONTRDP: ") |
| @@ -174,7 +188,8 @@ impl<'a> Control<'a> { | |||
| 174 | .expect_optional_int_parameter() | 188 | .expect_optional_int_parameter() |
| 175 | .expect_optional_int_parameter() | 189 | .expect_optional_int_parameter() |
| 176 | .expect_optional_int_parameter() | 190 | .expect_optional_int_parameter() |
| 177 | .expect_identifier(b"\r\nOK").finish()?; | 191 | .expect_identifier(b"\r\nOK") |
| 192 | .finish()?; | ||
| 178 | 193 | ||
| 179 | let gateway = if let Some(ip) = gateway { | 194 | let gateway = if let Some(ip) = gateway { |
| 180 | if ip.is_empty() { | 195 | if ip.is_empty() { |
| @@ -188,11 +203,13 @@ impl<'a> Control<'a> { | |||
| 188 | 203 | ||
| 189 | let mut dns = Vec::new(); | 204 | let mut dns = Vec::new(); |
| 190 | if let Some(ip) = dns1 { | 205 | if let Some(ip) = dns1 { |
| 191 | dns.push(IpAddr::from_str(ip).map_err(|_| Error::AddrParseError)?).unwrap(); | 206 | dns.push(IpAddr::from_str(ip).map_err(|_| Error::AddrParseError)?) |
| 207 | .unwrap(); | ||
| 192 | } | 208 | } |
| 193 | 209 | ||
| 194 | if let Some(ip) = dns2 { | 210 | if let Some(ip) = dns2 { |
| 195 | dns.push(IpAddr::from_str(ip).map_err(|_| Error::AddrParseError)?).unwrap(); | 211 | dns.push(IpAddr::from_str(ip).map_err(|_| Error::AddrParseError)?) |
| 212 | .unwrap(); | ||
| 196 | } | 213 | } |
| 197 | 214 | ||
| 198 | Ok(Status { | 215 | Ok(Status { |
diff --git a/embassy-net-nrf91/src/lib.rs b/embassy-net-nrf91/src/lib.rs index 673784cb2..a60e27d97 100644 --- a/embassy-net-nrf91/src/lib.rs +++ b/embassy-net-nrf91/src/lib.rs | |||
| @@ -17,13 +17,12 @@ use core::slice; | |||
| 17 | use core::sync::atomic::{compiler_fence, fence, Ordering}; | 17 | use core::sync::atomic::{compiler_fence, fence, Ordering}; |
| 18 | use core::task::{Poll, Waker}; | 18 | use core::task::{Poll, Waker}; |
| 19 | 19 | ||
| 20 | use embassy_net_driver_channel as ch; | ||
| 21 | use embassy_sync::waitqueue::{AtomicWaker, WakerRegistration}; | ||
| 22 | use embassy_sync::blocking_mutex::raw::NoopRawMutex; | 20 | use embassy_sync::blocking_mutex::raw::NoopRawMutex; |
| 21 | use embassy_sync::pipe; | ||
| 22 | use embassy_sync::waitqueue::{AtomicWaker, WakerRegistration}; | ||
| 23 | use heapless::Vec; | 23 | use heapless::Vec; |
| 24 | use nrf9160_pac as pac; | ||
| 25 | use pac::NVIC; | 24 | use pac::NVIC; |
| 26 | use embassy_sync::pipe; | 25 | use {embassy_net_driver_channel as ch, nrf9160_pac as pac}; |
| 27 | 26 | ||
| 28 | const RX_SIZE: usize = 8 * 1024; | 27 | const RX_SIZE: usize = 8 * 1024; |
| 29 | const TRACE_SIZE: usize = 16 * 1024; | 28 | const TRACE_SIZE: usize = 16 * 1024; |
| @@ -269,7 +268,6 @@ pub struct State { | |||
| 269 | inner: MaybeUninit<RefCell<StateInner>>, | 268 | inner: MaybeUninit<RefCell<StateInner>>, |
| 270 | } | 269 | } |
| 271 | 270 | ||
| 272 | |||
| 273 | impl State { | 271 | impl State { |
| 274 | /// Create a new State. | 272 | /// Create a new State. |
| 275 | pub const fn new() -> Self { | 273 | pub const fn new() -> Self { |
