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 stringsAtContext- Trait for implementing command handlersArgs- 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, at_response};
const SIZE: usize = 64;
// 1. Define a command handler
struct EchoModule { echo: bool }
impl AtContext<SIZE> for EchoModule {
fn query(&mut self, at_response: &'static str) -> AtResult<SIZE> {
Ok(at_response!(SIZE, at_response; if self.echo { 1u8 } else { 0u8 }))
}
fn set(&mut self, at_response: &'static str, args: Args) -> AtResult<SIZE> {
let value = args.get(0).ok_or((at_response, AtError::InvalidArgs))?;
match value.as_ref() {
"0" => { self.echo = false; Ok(at_response!(SIZE, at_response; "OK")) }
"1" => { self.echo = true; Ok(at_response!(SIZE, at_response; "OK")) }
_ => Err((at_response, AtError::InvalidArgs)),
}
}
}
// 2. Create parser and register commands
// Each entry is (at_command, at_response_prefix, handler)
let mut echo = EchoModule { echo: false };
let mut parser: AtParser<EchoModule, SIZE> = AtParser::new();
let commands: &mut [(&str, &str, &mut EchoModule)] = &mut [
("AT+ECHO", "+ECHO: ", &mut echo),
];
parser.set_commands(commands);
// 3. Execute commands
parser.execute("AT+ECHO=1"); // Set echo on → Ok(("+ECHO: ", "OK"))
parser.execute("AT+ECHO?"); // Query state → Ok(("+ECHO: ", "1"))§Features
freertos(default) — Enable FreeRTOS support via osal-rsposix— Enable POSIX (Linux/macOS) threading support via osal-rsstd— Enable standard library support via osal-rsdisable_panic— Pass-through feature to osal-rs; disables the built-in panic handler
§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§
Macros§
- at_
modules - Declares a static
COMMANDStable mapping AT command strings to their handlers. - at_
quoted - Wraps a value in double-quote characters (
"). - at_
response - Macro to format an AT response with 1–6 comma-separated parameters.
Structs§
- Args
- Structure holding the arguments passed to an AT command
Enums§
- AtError
- Error types that can occur during AT command processing
Type Aliases§
- AtResult
- Result type for AT command operations.