embedded_basic/embedded_basic.rs
1/***************************************************************************
2 *
3 * AT Command Parser
4 * Copyright (C) 2026 Antonio Salsi <passy.linux@zresa.it>
5 *
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
10 *
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
15 *
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, see <https://www.gnu.org/licenses/>.
18 *
19 ***************************************************************************/
20
21//! Basic usage example demonstrating no_std compatible code
22//!
23//! **Note**: This is a pattern demonstration example showing how the library
24//! can be used in no_std/embedded contexts. It illustrates API usage patterns
25//! and error handling approaches suitable for embedded systems.
26//!
27//! In a real embedded application, you would integrate these patterns into
28//! your firmware's main loop or RTOS tasks.
29
30#![allow(dead_code)]
31#![no_std]
32#![no_main]
33
34extern crate at_parser_rs;
35
36use at_parser_rs::{Args, AtError, AtResult, Bytes};
37
38const SIZE: usize = 64;
39
40// Example function using Args in no_std
41fn parse_args_example() -> AtResult<SIZE> {
42 let args = Args { raw: "foo,bar,baz" };
43 match args.get(1) {
44 Some(val) => Ok(Bytes::from_str(val)),
45 None => Err(AtError::InvalidArgs),
46 }
47}
48
49// Example of error handling
50fn handle_error_example() -> &'static str {
51 match parse_args_example() {
52 Ok(_) => "OK",
53 Err(AtError::InvalidArgs) => "Argomento non valido",
54 Err(_) => "Errore generico",
55 }
56}
57
58// In an embedded environment, these functions can be called from main or from a task.
59
60// Mock main for compilation (in real embedded code, this would be in your firmware)
61#[unsafe(no_mangle)]
62pub extern "C" fn main() -> ! {
63 // Example usage - in embedded this would be called from your main loop
64 let _result = handle_error_example();
65 loop {}
66}