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