Skip to content

Commit

Permalink
Rebase on master
Browse files Browse the repository at this point in the history
  • Loading branch information
MathiasKoch committed Jul 18, 2024
2 parents 67807ba + 2d83219 commit e9e0dff
Show file tree
Hide file tree
Showing 4 changed files with 98 additions and 30 deletions.
16 changes: 8 additions & 8 deletions src/command/edm/urc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ use heapless::Vec;
use no_std_net::{Ipv4Addr, Ipv6Addr};
use ublox_sockets::ChannelId;

#[allow(clippy::large_enum_variant)]
#[derive(Debug, Clone, PartialEq)]
pub enum EdmEvent {
BluetoothConnectEvent(BluetoothConnectEvent),
Expand Down Expand Up @@ -48,10 +49,10 @@ impl AtatUrc for EdmEvent {
|| resp.len() == AUTOCONNECTMESSAGE.len() + 1
{
let mut urc = resp;
match urc.iter().position(|x| !x.is_ascii_whitespace()) {
Some(i) => urc = &urc[i..],
None => (),
if let Some(i) = urc.iter().position(|x| !x.is_ascii_whitespace()) {
urc = &urc[i..];
};

let cmd = Urc::parse(urc)?;
return EdmEvent::ATEvent(cmd).into();
}
Expand Down Expand Up @@ -80,9 +81,8 @@ impl AtatUrc for EdmEvent {
match resp[4].into() {
PayloadType::ATEvent => {
let mut urc = &resp[AT_COMMAND_POSITION..PAYLOAD_POSITION + payload_len];
match urc.iter().position(|x| !x.is_ascii_whitespace()) {
Some(i) => urc = &urc[i..],
None => (),
if let Some(i) = urc.iter().position(|x| !x.is_ascii_whitespace()) {
urc = &urc[i..];
};
let cmd = Urc::parse(urc)?;
EdmEvent::ATEvent(cmd).into()
Expand Down Expand Up @@ -193,9 +193,9 @@ mod test {
handle: PeerHandle(2),
connection_type: crate::command::data_mode::types::ConnectionType::IPv4,
protocol: crate::command::data_mode::types::IPProtocol::UDP,
local_address: Bytes::from_slice(&"0.0.0.0".as_bytes()).unwrap(),
local_address: Bytes::from_slice("0.0.0.0".as_bytes()).unwrap(),
local_port: 0,
remote_address: Bytes::from_slice(&"162.159.200.1".as_bytes()).unwrap(),
remote_address: Bytes::from_slice("162.159.200.1".as_bytes()).unwrap(),
remote_port: 123,
}));
let parsed_urc = EdmEvent::parse(resp);
Expand Down
79 changes: 73 additions & 6 deletions src/command/wifi/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,81 @@ use super::{NoResponse, OnOff};
/// This command is used to configure up to 10 different Wi-Fi networks. After configuring a network, it must be
/// activated (Wi-Fi Station Configuration Action +UWSCA) before use.
/// If more than one configuration has active on start up parameter enabled, the behaviour is undefined.
#[derive(Clone, AtatCmd)]
#[at_cmd("+UWSC", NoResponse, timeout_ms = 1000)]
pub struct SetWifiStationConfig {
#[derive(Clone)]
// #[at_cmd("+UWSC", NoResponse, timeout_ms = 1000)]
pub struct SetWifiStationConfig<'a> {
/// Wi-Fi configuration id. 0-9
#[at_arg(position = 0)]
// #[at_arg(position = 0)]
pub config_id: u8,
#[at_arg(position = 1)]
pub config_param: WifiStationConfig,
// #[at_arg(position = 1)]
pub config_param: WifiStationConfig<'a>,
}

// FIXME:
#[automatically_derived]
impl<'a> atat::AtatLen for SetWifiStationConfig<'a> {
const LEN: usize =
<WifiStationConfig<'a> as atat::AtatLen>::LEN + <u8 as atat::AtatLen>::LEN + 1usize;
}
const ATAT_SETWIFISTATIONCONFIG_LEN: usize =
<WifiStationConfig<'_> as atat::AtatLen>::LEN + <u8 as atat::AtatLen>::LEN + 1usize;
#[automatically_derived]
impl<'a> atat::AtatCmd<{ ATAT_SETWIFISTATIONCONFIG_LEN + 12usize }> for SetWifiStationConfig<'a> {

Check failure on line 37 in src/command/wifi/mod.rs

View workflow job for this annotation

GitHub Actions / Test

trait takes 0 generic arguments but 1 generic argument was supplied

Check failure on line 37 in src/command/wifi/mod.rs

View workflow job for this annotation

GitHub Actions / Test

not all trait items implemented, missing: `MAX_LEN`, `write`

Check failure on line 37 in src/command/wifi/mod.rs

View workflow job for this annotation

GitHub Actions / clippy

not all trait items implemented, missing: `MAX_LEN`, `write`

error[E0046]: not all trait items implemented, missing: `MAX_LEN`, `write` --> src/command/wifi/mod.rs:37:1 | 37 | impl<'a> atat::AtatCmd<{ ATAT_SETWIFISTATIONCONFIG_LEN + 12usize }> for SetWifiStationConfig<'a> { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ missing `MAX_LEN`, `write` in implementation | = help: implement the missing item: `const MAX_LEN: usize = 42;` = help: implement the missing item: `fn write(&self, _: &mut [u8]) -> usize { todo!() }`

Check failure on line 37 in src/command/wifi/mod.rs

View workflow job for this annotation

GitHub Actions / clippy

trait takes 0 generic arguments but 1 generic argument was supplied

error[E0107]: trait takes 0 generic arguments but 1 generic argument was supplied --> src/command/wifi/mod.rs:37:16 | 37 | impl<'a> atat::AtatCmd<{ ATAT_SETWIFISTATIONCONFIG_LEN + 12usize }> for SetWifiStationConfig<'a> { | ^^^^^^^ expected 0 generic arguments | note: trait defined here, with 0 generic parameters --> /home/runner/.cargo/git/checkouts/atat-1e6ba3d4ab83bd35/a466836/atat/src/traits.rs:63:11 | 63 | pub trait AtatCmd { | ^^^^^^^
type Response = NoResponse;
const MAX_TIMEOUT_MS: u32 = 1000u32;
#[inline]
fn as_bytes(&self) -> atat::heapless::Vec<u8, { ATAT_SETWIFISTATIONCONFIG_LEN + 12usize }> {

Check failure on line 41 in src/command/wifi/mod.rs

View workflow job for this annotation

GitHub Actions / Test

method `as_bytes` is not a member of trait `atat::AtatCmd`
match atat::serde_at::to_vec(

Check failure on line 42 in src/command/wifi/mod.rs

View workflow job for this annotation

GitHub Actions / Test

cannot find function `to_vec` in crate `atat::serde_at`

Check failure on line 42 in src/command/wifi/mod.rs

View workflow job for this annotation

GitHub Actions / clippy

cannot find function `to_vec` in crate `atat::serde_at`

error[E0425]: cannot find function `to_vec` in crate `atat::serde_at` --> src/command/wifi/mod.rs:42:31 | 42 | match atat::serde_at::to_vec( | ^^^^^^ not found in `atat::serde_at` | note: found an item that was configured out --> /home/runner/.cargo/git/checkouts/atat-1e6ba3d4ab83bd35/a466836/serde_at/src/lib.rs:27:32 | 27 | pub use self::ser::{to_string, to_vec}; | ^^^^^^ = note: the item is gated behind the `heapless` feature
self,
"+UWSC",
atat::serde_at::SerializeOptions {
value_sep: true,
cmd_prefix: "AT",
termination: "\r\n",
quote_escape_strings: true,
},
) {
Ok(s) => s,
Err(_) => panic!("Failed to serialize command"),
}
}

Check failure on line 55 in src/command/wifi/mod.rs

View workflow job for this annotation

GitHub Actions / clippy

method `as_bytes` is not a member of trait `atat::AtatCmd`

error[E0407]: method `as_bytes` is not a member of trait `atat::AtatCmd` --> src/command/wifi/mod.rs:41:5 | 41 | / fn as_bytes(&self) -> atat::heapless::Vec<u8, { ATAT_SETWIFISTATIONCONFIG_LEN + 12usize }> { 42 | | match atat::serde_at::to_vec( 43 | | self, 44 | | "+UWSC", ... | 54 | | } 55 | | } | |_____^ not a member of trait `atat::AtatCmd`
#[inline]
fn parse(
&self,
res: Result<&[u8], atat::InternalError>,
) -> core::result::Result<Self::Response, atat::Error> {
match res {
Ok(resp) => {
atat::serde_at::from_slice::<NoResponse>(resp).map_err(|e| atat::Error::Parse)

Check warning on line 63 in src/command/wifi/mod.rs

View workflow job for this annotation

GitHub Actions / Test

unused variable: `e`

Check warning on line 63 in src/command/wifi/mod.rs

View workflow job for this annotation

GitHub Actions / clippy

unused variable: `e`

warning: unused variable: `e` --> src/command/wifi/mod.rs:63:73 | 63 | atat::serde_at::from_slice::<NoResponse>(resp).map_err(|e| atat::Error::Parse) | ^ help: if this is intentional, prefix it with an underscore: `_e`
}
Err(e) => Err(e.into()),
}
}
}
#[automatically_derived]
impl<'a> atat::serde_at::serde::Serialize for SetWifiStationConfig<'a> {
#[inline]
fn serialize<S>(&self, serializer: S) -> core::result::Result<S::Ok, S::Error>
where
S: atat::serde_at::serde::Serializer,
{
let mut serde_state = atat::serde_at::serde::Serializer::serialize_struct(
serializer,
"SetWifiStationConfig",
2usize,
)?;
atat::serde_at::serde::ser::SerializeStruct::serialize_field(
&mut serde_state,
"config_id",
&self.config_id,
)?;
atat::serde_at::serde::ser::SerializeStruct::serialize_field(
&mut serde_state,
"config_param",
&self.config_param,
)?;
atat::serde_at::serde::ser::SerializeStruct::end(serde_state)
}
}

/// 7.1 Wi-Fi station configuration +UWSC
Expand Down
30 changes: 15 additions & 15 deletions src/command/wifi/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ pub enum WifiStationConfigParameter {
}

#[derive(Clone, PartialEq, AtatEnum)]
pub enum WifiStationConfig {
pub enum WifiStationConfig<'a> {
/// <param_val1> decides if the station is active on start up.
/// - Off (default): Inactive
/// - On: active
Expand All @@ -127,7 +127,7 @@ pub enum WifiStationConfig {
/// SSID - <param_val1> is the Service Set Identifier. The factory default
/// value is an empty string ("").
#[at_arg(value = 2)]
SSID(String<64>),
SSID(#[at_arg(len = 64)] &'a str),
/// Authentication - <param_val> is the authentication type.
/// - 1 (default): Open
/// - 2: WPA/WPA2 PSK
Expand All @@ -146,11 +146,11 @@ pub enum WifiStationConfig {
/// Authentication " is supported.
#[at_arg(value = 6)]
WEPKeys(
String<13>,
Option<String<13>>,
Option<String<13>>,
Option<String<13>>,
Option<String<13>>,
#[at_arg(len = 13)] &'a str,
#[at_arg(len = 13)] Option<&'a str>,
#[at_arg(len = 13)] Option<&'a str>,
#[at_arg(len = 13)] Option<&'a str>,
#[at_arg(len = 13)] Option<&'a str>,
),
/// Active Key - <param_val1> is the WEP active TX key (factory default 0
/// means that Open authentication with WEP encryption is disabled). Range
Expand All @@ -160,38 +160,38 @@ pub enum WifiStationConfig {
/// PSK/Passphrase - <param_val1> is the PSK (32 HEX values) or Passphrase
/// (8-63 ASCII characters as a string) for WPA/WPA2 PSK.
#[at_arg(value = 8)]
WpaPskOrPassphrase(String<64>),
WpaPskOrPassphrase(#[at_arg(len = 64)] &'a str),
/// Password - <param_val1> is the password for LEAP and PEAP; string with a
/// maximum length of 31.
#[at_arg(value = 9)]
EAPPassword(String<31>),
EAPPassword(#[at_arg(len = 31)] &'a str),
/// User name - <param_val1> is the public user name for LEAP and PEAP;
/// string with a maximum length of 31.
#[at_arg(value = 10)]
UserName(String<31>),
UserName(#[at_arg(len = 31)] &'a str),
/// Domain name - <param_val1> is the public domain name for LEAP and PEAP;
/// string with a maximum length of 63. The domain name is an optional
/// parameter.
#[at_arg(value = 11)]
DomainName(String<63>),
DomainName(#[at_arg(len = 63)] &'a str),
/// Client certificate name - <param_val1> is the internal client
/// certificate name for EAP-TLS as defined in the SSL/TLS certificates and
/// private keys manager +USECMNG command; string with a maximum length of
/// 32. Supported software versions 4.0.0 onwards
#[at_arg(value = 12)]
ClientCertificateName(String<32>),
ClientCertificateName(#[at_arg(len = 32)] &'a str),
/// Client private key - <param_val1> is the internal client private key
/// name for EAP- TLS as defined in the SSL/TLS certificates and private
/// keys manager +USECMNG command; string with a maximum length of 32.
/// Supported software versions 4.0.0 onwards
#[at_arg(value = 13)]
ClientPrivateKey(String<32>),
ClientPrivateKey(#[at_arg(len = 32)] &'a str),
/// CA certificate name - <param_val1> is the internal CA certificate name
/// for EAP- TLS as defined in the SSL/TLS certificates and private keys
/// manager +USECMNG command; string with a maximum length of 32. Supported
/// software versions 5.0.0 onwards
#[at_arg(value = 14)]
CACertificateName(String<32>),
CACertificateName(#[at_arg(len = 32)] &'a str),
/// Validate CA certificate. The default value is On; Setting this value to
/// Off means no CA Certificate validation has been done. For example
/// at+uwsc=0,15,0 would mean that the server CA Certificate is not
Expand Down Expand Up @@ -426,7 +426,7 @@ pub enum WifiStationAction {
Deactivate = 4,
}

#[derive(Debug, Clone, PartialEq, AtatEnum)]
#[derive(Debug, Clone, PartialEq, AtatEnum, defmt::Format)]

Check failure on line 429 in src/command/wifi/types.rs

View workflow job for this annotation

GitHub Actions / Test

failed to resolve: use of undeclared crate or module `defmt`

Check failure on line 429 in src/command/wifi/types.rs

View workflow job for this annotation

GitHub Actions / clippy

failed to resolve: use of undeclared crate or module `defmt`

error[E0433]: failed to resolve: use of undeclared crate or module `defmt` --> src/command/wifi/types.rs:429:45 | 429 | #[derive(Debug, Clone, PartialEq, AtatEnum, defmt::Format)] | ^^^^^ use of undeclared crate or module `defmt`
#[repr(u8)]
pub enum OperationMode {
Infrastructure = 1,
Expand Down
3 changes: 2 additions & 1 deletion src/network.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,9 @@ pub enum WifiMode {
AccessPoint,
}

#[derive(Debug)]
#[derive(Debug, defmt::Format)]

Check failure on line 17 in src/network.rs

View workflow job for this annotation

GitHub Actions / Test

failed to resolve: use of undeclared crate or module `defmt`

Check failure on line 17 in src/network.rs

View workflow job for this annotation

GitHub Actions / clippy

failed to resolve: use of undeclared crate or module `defmt`

error[E0433]: failed to resolve: use of undeclared crate or module `defmt` --> src/network.rs:17:17 | 17 | #[derive(Debug, defmt::Format)] | ^^^^^ use of undeclared crate or module `defmt`
pub struct WifiNetwork {
#[defmt(Debug2Format)]

Check failure on line 19 in src/network.rs

View workflow job for this annotation

GitHub Actions / Test

cannot find attribute `defmt` in this scope
pub bssid: Bytes<20>,
pub op_mode: OperationMode,
pub ssid: String<64>,
Expand Down

0 comments on commit e9e0dff

Please sign in to comment.