Trait atat::AtatCmd

source ·
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§

source

type Response: AtatResp

The type of the response. Must implement the AtatResp trait.

Required Associated Constants§

source

const MAX_LEN: usize

The size of the buffer required to write the request.

Provided Associated Constants§

source

const CAN_ABORT: bool = false

Whether or not this command can be aborted.

source

const MAX_TIMEOUT_MS: u32 = 1_000u32

The max timeout in milliseconds.

source

const ATTEMPTS: u8 = 1u8

The max number of times to attempt a command with automatic retries if using send_retry.

source

const REATTEMPT_ON_PARSE_ERR: bool = true

Whether or not to reattempt a command on a parse error using send_retry.

source

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§

source

fn write(&self, buf: &mut [u8]) -> usize

Write the command and return the number of written bytes.

source

fn parse( &self, resp: Result<&[u8], InternalError<'_>> ) -> Result<Self::Response, Error>

Parse the response into a Self::Response or Error instance.

Object Safety§

This trait is not object safe.

Implementations on Foreign Types§

source§

impl<const L: usize> AtatCmd for String<L>

§

type Response = String<256>

source§

const MAX_LEN: usize = L

source§

fn write(&self, buf: &mut [u8]) -> usize

source§

fn parse( &self, resp: Result<&[u8], InternalError<'_>> ) -> Result<Self::Response, Error>

Implementors§