pub struct Args<'a> {
pub raw: &'a str,
}Expand description
Structure holding the arguments passed to an AT command
Fields§
§raw: &'a strRaw argument string (comma-separated values)
Implementations§
Source§impl<'a> Args<'a>
impl<'a> Args<'a>
Sourcepub fn get(&self, index: usize) -> Option<&'a str>
pub fn get(&self, index: usize) -> Option<&'a str>
Get an argument by index (0-based) Arguments are separated by commas
Examples found in repository?
More examples
examples/embedded_uart_config.rs (line 53)
52 fn set(&mut self, args: Args) -> AtResult<'static> {
53 if let Some(data) = args.get(0) {
54 self.write(data);
55 Ok("SENT")
56 } else {
57 Err(AtError::InvalidArgs)
58 }
59 }
60}
61
62// Device configuration context
63struct ConfigContext;
64
65impl AtContext for ConfigContext {
66 fn exec(&self) -> AtResult<'static> {
67 // Not supported for SETCFG
68 Err(AtError::NotSupported)
69 }
70
71 fn query(&mut self) -> AtResult<'static> {
72 // Return current configuration as a static string
73 // In real implementation, format the values dynamically
74 Ok("115200,1")
75 }
76
77 fn test(&mut self) -> AtResult<'static> {
78 // Return supported configuration options
79 Ok("+SETCFG: (baudrate),(mode)")
80 }
81
82 fn set(&mut self, args: Args) -> AtResult<'static> {
83 let baud = args.get(0).and_then(|s| s.parse::<u32>().ok());
84 let mode = args.get(1).and_then(|s| s.parse::<u8>().ok());
85 match (baud, mode) {
86 (Some(b), Some(m)) => unsafe {
87 // Configure UART
88 UART.baudrate = b;
89 UART.mode = m;
90 Ok("CONFIGURED")
91 },
92 _ => Err(AtError::InvalidArgs),
93 }
94 }examples/complete_usage.rs (line 56)
55 fn set(&mut self, args: Args) -> AtResult<'static> {
56 let value = args.get(0).ok_or(AtError::InvalidArgs)?;
57 match value {
58 "0" => {
59 self.echo = false;
60 Ok("ECHO OFF")
61 }
62 "1" => {
63 self.echo = true;
64 Ok("ECHO ON")
65 }
66 _ => Err(AtError::InvalidArgs),
67 }
68 }
69}
70
71/// Reset command module - simulates system reset
72pub struct ResetModule;
73
74impl AtContext for ResetModule {
75 /// Execute: perform reset
76 fn exec(&self) -> AtResult<'static> {
77 println!(" [System reset triggered]");
78 Ok("OK - System reset")
79 }
80
81 /// Test: show command description
82 fn test(&mut self) -> AtResult<'static> {
83 Ok("Reset the system")
84 }
85}
86
87/// Info command module - provides system information
88pub struct InfoModule {
89 pub version: &'static str,
90}
91
92impl AtContext for InfoModule {
93 /// Execute: return system info
94 fn exec(&self) -> AtResult<'static> {
95 Ok(self.version)
96 }
97
98 /// Query: return detailed info
99 fn query(&mut self) -> AtResult<'static> {
100 Ok("AT-Parser-RS v1.0.0 - AT Command Parser Library")
101 }
102}
103
104/// LED command module - controls an LED with multiple parameters
105pub struct LedModule {
106 pub state: bool,
107 pub brightness: u8,
108}
109
110impl AtContext for LedModule {
111 /// Execute: return current LED state
112 fn exec(&self) -> AtResult<'static> {
113 if self.state {
114 Ok("LED: ON")
115 } else {
116 Ok("LED: OFF")
117 }
118 }
119
120 /// Query: return state and brightness
121 fn query(&mut self) -> AtResult<'static> {
122 if self.state {
123 Ok("1,100")
124 } else {
125 Ok("0,0")
126 }
127 }
128
129 /// Test: show usage
130 fn test(&mut self) -> AtResult<'static> {
131 Ok("AT+LED=<state>,<brightness> where state: 0|1, brightness: 0-100")
132 }
133
134 /// Set: change LED state and brightness
135 fn set(&mut self, args: Args) -> AtResult<'static> {
136 let state_str = args.get(0).ok_or(AtError::InvalidArgs)?;
137
138 self.state = match state_str {
139 "0" => false,
140 "1" => true,
141 _ => return Err(AtError::InvalidArgs),
142 };
143
144 // Optional brightness parameter
145 if let Some(brightness_str) = args.get(1) {
146 self.brightness = brightness_str
147 .parse::<u8>()
148 .map_err(|_| AtError::InvalidArgs)?;
149
150 if self.brightness > 100 {
151 return Err(AtError::InvalidArgs);
152 }
153 }
154
155 if self.state {
156 Ok("LED ON")
157 } else {
158 Ok("LED OFF")
159 }
160 }Auto Trait Implementations§
impl<'a> Freeze for Args<'a>
impl<'a> RefUnwindSafe for Args<'a>
impl<'a> Send for Args<'a>
impl<'a> Sync for Args<'a>
impl<'a> Unpin for Args<'a>
impl<'a> UnwindSafe for Args<'a>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more