pub trait AtatCmd {
type Response: AtatResp;
const MAX_LEN: usize;
const CAN_ABORT: bool = false;
const MAX_TIMEOUT_MS: u32 = 1_000u32;
const ATTEMPTS: u8 = 1u8;
const REATTEMPT_ON_PARSE_ERR: bool = true;
const EXPECTS_RESPONSE_CODE: bool = true;
// Required methods
fn write(&self, buf: &mut [u8]) -> usize;
fn parse(
&self,
resp: Result<&[u8], InternalError<'_>>
) -> Result<Self::Response, Error>;
}
Expand description
This trait needs to be implemented for every command type.
It can also be derived by the atat_derive
crate.
Example:
use atat::{AtatCmd, AtatResp, Error, InternalError};
use core::fmt::Write;
use heapless::Vec;
pub struct SetGreetingText<'a> {
pub text: &'a str,
}
pub struct NoResponse;
impl AtatResp for NoResponse {};
impl<'a> AtatCmd for SetGreetingText<'a> {
type Response = NoResponse;
const MAX_LEN: usize = 64;
fn write(&self, mut buf: &mut [u8]) -> usize {
assert!(buf.len() >= Self::MAX_LEN);
let buf_len = buf.len();
use embedded_io::Write;
write!(buf, "AT+CSGT={}", self.text);
buf_len - buf.len()
}
fn parse(&self, resp: Result<&[u8], InternalError>) -> Result<Self::Response, Error> {
Ok(NoResponse)
}
}
Required Associated Types§
Required Associated Constants§
Provided Associated Constants§
sourceconst MAX_TIMEOUT_MS: u32 = 1_000u32
const MAX_TIMEOUT_MS: u32 = 1_000u32
The max timeout in milliseconds.
sourceconst ATTEMPTS: u8 = 1u8
const ATTEMPTS: u8 = 1u8
The max number of times to attempt a command with automatic retries if
using send_retry
.
sourceconst REATTEMPT_ON_PARSE_ERR: bool = true
const REATTEMPT_ON_PARSE_ERR: bool = true
Whether or not to reattempt a command on a parse error
using send_retry
.
sourceconst EXPECTS_RESPONSE_CODE: bool = true
const EXPECTS_RESPONSE_CODE: bool = true
Force client to look for a response. Empty slice is then passed to parse by client. Implemented to enhance expandability of ATAT
Required Methods§
Object Safety§
This trait is not object safe.