Skip to main content

Crate at_parser_rs

Crate at_parser_rs 

Source
Expand description

AT Command Parser Library

This library provides a flexible parser for AT commands, commonly used in embedded systems and communication devices. It supports no_std environments.

§Architecture

The library is built around three core components:

  • AtParser - The main parser that processes AT command strings
  • AtContext - Trait for implementing command handlers
  • Args - Structure for accessing command arguments

§Command Forms

Supports all standard AT command forms:

  • AT+CMD - Execute (action without parameters)
  • AT+CMD? - Query (get current value/state)
  • AT+CMD=? - Test (get supported values/ranges)
  • AT+CMD=<args> - Set (configure with parameters)

§Quick Start

use at_parser_rs::context::AtContext;
use at_parser_rs::parser::AtParser;
use at_parser_rs::{Args, AtResult, AtError, Bytes};

const SIZE: usize = 64;

// 1. Define a command handler
struct EchoModule { echo: bool }

impl AtContext<SIZE> for EchoModule {
    fn query(&mut self) -> AtResult<SIZE> {
        if self.echo { Ok(Bytes::from_str("1")) } else { Ok(Bytes::from_str("0")) }
    }
     
    fn set(&mut self, args: Args) -> AtResult<SIZE> {
        match args.get(0) {
            Some("0") => { self.echo = false; Ok(Bytes::from_str("OK")) }
            Some("1") => { self.echo = true; Ok(Bytes::from_str("OK")) }
            _ => Err(AtError::InvalidArgs),
        }
    }
}

// 2. Create parser and register commands
let mut echo = EchoModule { echo: false };
let mut parser: AtParser<EchoModule, SIZE> = AtParser::new();

let commands: &mut [(&str, &mut dyn AtContext<SIZE>)] = &mut [
    ("AT+ECHO", &mut echo),
];
parser.set_commands(commands);

// 3. Execute commands
parser.execute("AT+ECHO=1");  // Set echo on
parser.execute("AT+ECHO?");   // Query current state

§Features

  • freertos (default) - Enable FreeRTOS support via osal-rs
  • posix - Enable POSIX support via osal-rs
  • std - Enable standard library support via osal-rs
  • disable_panic - Pass-through feature to osal-rs for panic handling

§Thread Safety

The library can be used in single-threaded (bare-metal) or multi-threaded (RTOS) environments. For RTOS, use appropriate synchronization primitives around command handlers (e.g., Mutex<RefCell<Handler>>).

Modules§

context
parser

Macros§

at_modules
Macro to define AT command modules

Structs§

Args
Structure holding the arguments passed to an AT command
Bytes
Fixed-size byte array wrapper with string conversion utilities.

Enums§

AtError
Error types that can occur during AT command processing

Type Aliases§

AtResult
Result type for AT command operations Returns either a Bytes<SIZE> response buffer or an AtError