#![allow(dead_code)]
#![no_std]
#![no_main]
extern crate at_parser_rs;
use at_parser_rs::{Args, AtError, AtResult, Bytes};
use at_parser_rs::context::AtContext;
const SIZE: usize = 64;
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<SIZE> for DummyUart {
fn exec(&self) -> AtResult<'_, SIZE> {
Err(AtError::NotSupported)
}
fn set(&mut self, args: Args) -> AtResult<'_, SIZE> {
if let Some(data) = args.get(0) {
self.write(data);
Ok(Bytes::from_str("SENT"))
} else {
Err(AtError::InvalidArgs)
}
}
}
struct ConfigContext;
impl AtContext<SIZE> for ConfigContext {
fn exec(&self) -> AtResult<'_, SIZE> {
Err(AtError::NotSupported)
}
fn query(&mut self) -> AtResult<'_, SIZE> {
Ok(Bytes::from_str("115200,1"))
}
fn test(&mut self) -> AtResult<'_, SIZE> {
Ok(Bytes::from_str("+SETCFG: (baudrate),(mode)"))
}
fn set(&mut self, args: Args) -> AtResult<'_, SIZE> {
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(Bytes::from_str("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<'static>> {
Ok("OK")
}
fn example_with_commands_macro() -> Result<&'static str, AtError<'static>> {
Ok("OK")
}
#[unsafe(no_mangle)]
pub extern "C" fn main() -> ! {
let _result = example_with_commands_macro();
loop {}
}