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 aa3e497..06871f3 100644 --- a/src/wifi.rs +++ b/src/wifi.rs @@ -262,7 +262,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) }