#![allow(dead_code)]
extern crate at_parser_rs;
use at_parser_rs::{Args, AtError, AtResult};
use at_parser_rs::context::AtContext;
struct DummyUart {
baudrate: u32,
mode: u8,
}
impl DummyUart {
const fn new() -> Self {
Self { baudrate: 9600, mode: 0 }
}
fn write(&self, data: &str) {
let _ = data;
}
}
impl AtContext for DummyUart {
fn exec(&self) -> AtResult<'static> {
Err(AtError::NotSupported)
}
fn set(&mut self, args: Args) -> AtResult<'static> {
if let Some(data) = args.get(0) {
self.write(data);
Ok("SENT")
} else {
Err(AtError::InvalidArgs)
}
}
}
struct ConfigContext;
impl AtContext for ConfigContext {
fn exec(&self) -> AtResult<'static> {
Err(AtError::NotSupported)
}
fn query(&mut self) -> AtResult<'static> {
Ok("115200,1")
}
fn test(&mut self) -> AtResult<'static> {
Ok("+SETCFG: (baudrate),(mode)")
}
fn set(&mut self, args: Args) -> AtResult<'static> {
let baud = args.get(0).and_then(|s| s.parse::<u32>().ok());
let mode = args.get(1).and_then(|s| s.parse::<u8>().ok());
match (baud, mode) {
(Some(b), Some(m)) => unsafe {
UART.baudrate = b;
UART.mode = m;
Ok("CONFIGURED")
},
_ => Err(AtError::InvalidArgs),
}
}
}
static mut UART: DummyUart = DummyUart { baudrate: 9600, mode: 0 };
static mut CONFIG_CTX: ConfigContext = ConfigContext;
fn example_with_parser() -> Result<&'static str, AtError> {
Ok("OK")
}
fn example_with_commands_macro() -> Result<&'static str, AtError> {
Ok("OK")
}
fn main() {
let _result = example_with_commands_macro();
}