From fa5bda9470cad72c9533a97c9d742e4b91e720f4 Mon Sep 17 00:00:00 2001 From: Marius Meissner Date: Fri, 7 Apr 2023 12:54:32 +0200 Subject: [PATCH 1/2] Removed URC echo matching --- src/tests/urc.rs | 42 +----------------------------------------- src/urc.rs | 8 -------- src/wifi.rs | 1 - 3 files changed, 1 insertion(+), 50 deletions(-) diff --git a/src/tests/urc.rs b/src/tests/urc.rs index 42bf7f2..cc035f0 100644 --- a/src/tests/urc.rs +++ b/src/tests/urc.rs @@ -1,12 +1,5 @@ -use crate::commands::{ - AccessPointConnectCommand, ConnectCommand, ObtainLocalAddressCommand, SetMultipleConnectionsCommand, - SetSocketReceivingModeCommand, TransmissionPrepareCommand, WifiModeCommand, -}; use crate::urc::URCMessages; -use atat::heapless::String; -use atat::{AtatCmd, AtatUrc, Parser}; -use core::str::FromStr; -use embedded_nal::SocketAddrV4; +use atat::{AtatUrc, Parser}; use heapless::Vec; #[test] @@ -307,23 +300,6 @@ fn test_second_parse_longer_then_block_size() { assert!( as AtatUrc>::parse(b"+CIPRECVDATA,5:abcde").is_none()) } -#[test] -fn test_matching_cmd_echo() { - assert_cmd_echo_matching(WifiModeCommand::station_mode()); - assert_cmd_echo_matching(SetSocketReceivingModeCommand::passive_mode()); - assert_cmd_echo_matching(SetMultipleConnectionsCommand::multiple()); - assert_cmd_echo_matching(AccessPointConnectCommand::new( - String::from_str("test_network").unwrap(), - String::from_str("secret").unwrap(), - )); - assert_cmd_echo_matching(TransmissionPrepareCommand::new(0, 8)); - assert_cmd_echo_matching(ConnectCommand::tcp_v4( - 0, - SocketAddrV4::from_str("10.0.0.1:5000").unwrap(), - )); - assert_cmd_echo_matching(ObtainLocalAddressCommand::new()); -} - fn assert_result(string: &[u8], size: usize, data: &[u8]) { match as Parser>::parse(data) { Ok(result) => { @@ -335,19 +311,3 @@ fn assert_result(string: &[u8], size: usize, data: &[u8]) { } } } - -/// Asserts that command echo is matched -fn assert_cmd_echo_matching, const LEN: usize>(command: Cmd) { - let encoded = command.as_bytes(); - - // Assert that first parser ist matching - assert_result(encoded.as_slice(), encoded.len(), encoded.as_slice()); - - // Assert that echo gets converted to Unknown URC - assert_eq!( - URCMessages::Echo, - as AtatUrc>::parse(encoded.as_slice()).unwrap(), - "Echo of command {} did not return URCMessages::Echo on second parser.", - core::str::from_utf8(encoded.as_slice()).unwrap() - ); -} diff --git a/src/urc.rs b/src/urc.rs index 26a0911..49574be 100644 --- a/src/urc.rs +++ b/src/urc.rs @@ -34,8 +34,6 @@ pub enum URCMessages { DataAvailable(usize, usize), /// Received the following data requested by CIPRECVDATA command. Data(Vec), - /// Echo of a command - Echo, /// Unknown URC message Unknown, } @@ -44,11 +42,6 @@ impl AtatUrc for URCMessages { type Response = Self; fn parse(resp: &[u8]) -> Option { - // Command echo - if &resp[..3] == b"AT+" { - return Some(Self::Echo); - } - if &resp[..4] == b"+IPD" { return URCMessages::parse_data_available(resp); } @@ -220,7 +213,6 @@ impl<'a> LineBasedMatcher<'a> { /// True if a regular CRLF terminated URC message was matched fn matches_lines_based_urc(&self, line: &str) -> bool { line == "ready" - || &line[..3] == "AT+" || &line[..4] == "+IPD" || line == "SEND OK" || line == "SEND FAIL" diff --git a/src/wifi.rs b/src/wifi.rs index 12b3e06..2e8f61d 100644 --- a/src/wifi.rs +++ b/src/wifi.rs @@ -154,7 +154,6 @@ impl Session { } } URCMessages::Data(data) => self.data = Some(data), - URCMessages::Echo => {} URCMessages::Unknown => {} } } From cc1575ce35907237c81cef74abe88cbaf6c0d531 Mon Sep 17 00:00:00 2001 From: Marius Meissner Date: Fri, 7 Apr 2023 12:58:07 +0200 Subject: [PATCH 2/2] Replaced +CIFSR derive by explicit implementation for not braking thumbv6m --- src/commands.rs | 20 ++++++++++++++++++-- src/wifi.rs | 2 +- 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/src/commands.rs b/src/commands.rs index 29460a3..c8adf3b 100644 --- a/src/commands.rs +++ b/src/commands.rs @@ -107,8 +107,7 @@ impl CommandErrorHandler for AccessPointConnectCommand { } /// Command for receiving local address information including IP and MAC -#[derive(Clone, AtatCmd)] -#[at_cmd("+CIFSR", Vec, timeout_ms = 5_000)] +#[derive(Clone)] pub struct ObtainLocalAddressCommand {} impl ObtainLocalAddressCommand { @@ -117,6 +116,23 @@ impl ObtainLocalAddressCommand { } } +impl AtatCmd<10> for ObtainLocalAddressCommand { + type Response = Vec; + const MAX_TIMEOUT_MS: u32 = 5_000; + + fn as_bytes(&self) -> Vec { + Vec::from_slice("AT+CIFSR\r\n".as_bytes()).unwrap() + } + + fn parse(&self, resp: Result<&[u8], InternalError>) -> Result { + if resp.is_err() { + return Err(AtError::InvalidResponse); + } + + atat::serde_at::from_slice::>(resp.unwrap()).map_err(|_| AtError::Parse) + } +} + impl CommandErrorHandler for ObtainLocalAddressCommand { type Error = AddressErrors; const WOULD_BLOCK_ERROR: Self::Error = AddressErrors::UnexpectedWouldBlock; diff --git a/src/wifi.rs b/src/wifi.rs index 2e8f61d..f7d3d64 100644 --- a/src/wifi.rs +++ b/src/wifi.rs @@ -259,7 +259,7 @@ impl, const TIMER_HZ: u32, const TX_SIZE: usiz /// Returns local address information fn get_address(&mut self) -> Result { - let responses = self.send_command(ObtainLocalAddressCommand::new())?; + let responses = self.send_command::<_, 10>(ObtainLocalAddressCommand::new())?; LocalAddress::from_responses(responses) }