Skip to content

Commit

Permalink
Replaced +CIFSR derive by explicit implementation for not braking thu…
Browse files Browse the repository at this point in the history
…mbv6m
  • Loading branch information
marius-meissner committed Apr 7, 2023
1 parent b91a27c commit 4957992
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 3 deletions.
20 changes: 18 additions & 2 deletions src/commands.rs
Expand Up @@ -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<LocalAddressResponse, 4>, timeout_ms = 5_000)]
#[derive(Clone)]
pub struct ObtainLocalAddressCommand {}

impl ObtainLocalAddressCommand {
Expand All @@ -117,6 +116,23 @@ impl ObtainLocalAddressCommand {
}
}

impl AtatCmd<10> for ObtainLocalAddressCommand {
type Response = Vec<LocalAddressResponse, 4>;
const MAX_TIMEOUT_MS: u32 = 5_000;

fn as_bytes(&self) -> Vec<u8, 10> {
Vec::from_slice("AT+CIFSR\r\n".as_bytes()).unwrap()
}

fn parse(&self, resp: Result<&[u8], InternalError>) -> Result<Self::Response, AtError> {
if resp.is_err() {
return Err(AtError::InvalidResponse);
}

atat::serde_at::from_slice::<Vec<LocalAddressResponse, 4>>(resp.unwrap()).map_err(|_| AtError::Parse)
}
}

impl CommandErrorHandler for ObtainLocalAddressCommand {
type Error = AddressErrors;
const WOULD_BLOCK_ERROR: Self::Error = AddressErrors::UnexpectedWouldBlock;
Expand Down
2 changes: 1 addition & 1 deletion src/wifi.rs
Expand Up @@ -262,7 +262,7 @@ impl<A: AtatClient, T: Timer<TIMER_HZ>, const TIMER_HZ: u32, const TX_SIZE: usiz

/// Returns local address information
fn get_address(&mut self) -> Result<LocalAddress, AddressErrors> {
let responses = self.send_command(ObtainLocalAddressCommand::new())?;
let responses = self.send_command::<_, 10>(ObtainLocalAddressCommand::new())?;
LocalAddress::from_responses(responses)
}

Expand Down

0 comments on commit 4957992

Please sign in to comment.