macro_rules! at_response {
($size:expr, $at_resp:expr; $a1:expr) => { ... };
($size:expr, $at_resp:expr; $a1:expr, $a2:expr) => { ... };
($size:expr, $at_resp:expr; $a1:expr, $a2:expr, $a3:expr) => { ... };
($size:expr, $at_resp:expr; $a1:expr, $a2:expr, $a3:expr, $a4:expr) => { ... };
($size:expr, $at_resp:expr; $a1:expr, $a2:expr, $a3:expr, $a4:expr, $a5:expr) => { ... };
($size:expr, $at_resp:expr; $a1:expr, $a2:expr, $a3:expr, $a4:expr, $a5:expr, $a6:expr) => { ... };
}Expand description
Macro to define AT command modules
Creates a static array of command names and their associated context handlers.
§Warning
This macro uses unsafe to create mutable references to static data.
It is only suitable for single-threaded embedded contexts.
§Limitations
- Unsafe: Requires
unsafeblocks to use - Single-threaded only: Not safe for RTOS or multi-threaded environments
- Limited flexibility: Cannot mix different handler types
§Example
use at_parser_rs::at_modules;
use at_parser_rs::context::AtContext;
const SIZE: usize = 64;
static mut ECHO: EchoModule = EchoModule { echo: false };
static mut RESET: ResetModule = ResetModule;
at_modules! {
SIZE;
"AT+ECHO" => ECHO,
"AT+RST" => RESET,
}§Recommended Alternative
For most use cases, prefer the manual approach:
const SIZE: usize = 64;
let commands: &mut [(&str, &mut dyn AtContext<SIZE>)] = &mut [
("AT+ECHO", &mut echo_handler),
("AT+RST", &mut reset_handler),
];
parser.set_commands(commands);Macro to format an AT response with 1–6 comma-separated parameters.
§Syntax
ⓘ
at_response!(SIZE, AT_RESP; arg1, arg2, ..., arg6)SIZE— const usize for the response buffer capacityAT_RESP— the AT response prefix stringarg1..arg6— values to append, comma-separated