pub trait AtContext {
// Provided methods
fn exec(&self) -> AtResult<'static> { ... }
fn query(&mut self) -> AtResult<'static> { ... }
fn test(&mut self) -> AtResult<'static> { ... }
fn set(&mut self, _args: Args<'_>) -> AtResult<'static> { ... }
}Expand description
Trait that defines the context for AT command execution. Implementations of this trait handle the actual logic for each AT command form.
Provided Methods§
Sourcefn exec(&self) -> AtResult<'static>
fn exec(&self) -> AtResult<'static>
Execute command (AT+CMD) This is called when a command is invoked without any suffix.
Examples found in repository?
examples/complete_usage.rs (line 170)
164fn execute_command(cmd: &str, name: &str, module: &mut dyn AtContext) {
165 println!("\n> {}", cmd);
166
167 let result = if let Some(rest) = cmd.strip_prefix(name) {
168 if rest.is_empty() {
169 // Execute form: AT+CMD
170 module.exec()
171 } else if rest == "?" {
172 // Query form: AT+CMD?
173 module.query()
174 } else if rest == "=?" {
175 // Test form: AT+CMD=?
176 module.test()
177 } else if let Some(args_str) = rest.strip_prefix('=') {
178 // Set form: AT+CMD=args
179 module.set(Args { raw: args_str })
180 } else {
181 Err(AtError::InvalidArgs)
182 }
183 } else {
184 Err(AtError::UnknownCommand)
185 };
186
187 match result {
188 Ok(response) => println!(" Response: {}", response),
189 Err(AtError::UnknownCommand) => println!(" Error: Unknown command"),
190 Err(AtError::NotSupported) => println!(" Error: Operation not supported"),
191 Err(AtError::InvalidArgs) => println!(" Error: Invalid arguments"),
192 }
193}Sourcefn query(&mut self) -> AtResult<'static>
fn query(&mut self) -> AtResult<'static>
Query command (AT+CMD?) This is called to retrieve the current value/state of a command.
Examples found in repository?
examples/complete_usage.rs (line 173)
164fn execute_command(cmd: &str, name: &str, module: &mut dyn AtContext) {
165 println!("\n> {}", cmd);
166
167 let result = if let Some(rest) = cmd.strip_prefix(name) {
168 if rest.is_empty() {
169 // Execute form: AT+CMD
170 module.exec()
171 } else if rest == "?" {
172 // Query form: AT+CMD?
173 module.query()
174 } else if rest == "=?" {
175 // Test form: AT+CMD=?
176 module.test()
177 } else if let Some(args_str) = rest.strip_prefix('=') {
178 // Set form: AT+CMD=args
179 module.set(Args { raw: args_str })
180 } else {
181 Err(AtError::InvalidArgs)
182 }
183 } else {
184 Err(AtError::UnknownCommand)
185 };
186
187 match result {
188 Ok(response) => println!(" Response: {}", response),
189 Err(AtError::UnknownCommand) => println!(" Error: Unknown command"),
190 Err(AtError::NotSupported) => println!(" Error: Operation not supported"),
191 Err(AtError::InvalidArgs) => println!(" Error: Invalid arguments"),
192 }
193}Sourcefn test(&mut self) -> AtResult<'static>
fn test(&mut self) -> AtResult<'static>
Test command (AT+CMD=?) This is called to check if a command is supported or to get valid parameter ranges.
Examples found in repository?
examples/complete_usage.rs (line 176)
164fn execute_command(cmd: &str, name: &str, module: &mut dyn AtContext) {
165 println!("\n> {}", cmd);
166
167 let result = if let Some(rest) = cmd.strip_prefix(name) {
168 if rest.is_empty() {
169 // Execute form: AT+CMD
170 module.exec()
171 } else if rest == "?" {
172 // Query form: AT+CMD?
173 module.query()
174 } else if rest == "=?" {
175 // Test form: AT+CMD=?
176 module.test()
177 } else if let Some(args_str) = rest.strip_prefix('=') {
178 // Set form: AT+CMD=args
179 module.set(Args { raw: args_str })
180 } else {
181 Err(AtError::InvalidArgs)
182 }
183 } else {
184 Err(AtError::UnknownCommand)
185 };
186
187 match result {
188 Ok(response) => println!(" Response: {}", response),
189 Err(AtError::UnknownCommand) => println!(" Error: Unknown command"),
190 Err(AtError::NotSupported) => println!(" Error: Operation not supported"),
191 Err(AtError::InvalidArgs) => println!(" Error: Invalid arguments"),
192 }
193}Sourcefn set(&mut self, _args: Args<'_>) -> AtResult<'static>
fn set(&mut self, _args: Args<'_>) -> AtResult<'static>
Set command (AT+CMD=args) This is called to set parameters for a command.
Examples found in repository?
examples/complete_usage.rs (line 179)
164fn execute_command(cmd: &str, name: &str, module: &mut dyn AtContext) {
165 println!("\n> {}", cmd);
166
167 let result = if let Some(rest) = cmd.strip_prefix(name) {
168 if rest.is_empty() {
169 // Execute form: AT+CMD
170 module.exec()
171 } else if rest == "?" {
172 // Query form: AT+CMD?
173 module.query()
174 } else if rest == "=?" {
175 // Test form: AT+CMD=?
176 module.test()
177 } else if let Some(args_str) = rest.strip_prefix('=') {
178 // Set form: AT+CMD=args
179 module.set(Args { raw: args_str })
180 } else {
181 Err(AtError::InvalidArgs)
182 }
183 } else {
184 Err(AtError::UnknownCommand)
185 };
186
187 match result {
188 Ok(response) => println!(" Response: {}", response),
189 Err(AtError::UnknownCommand) => println!(" Error: Unknown command"),
190 Err(AtError::NotSupported) => println!(" Error: Operation not supported"),
191 Err(AtError::InvalidArgs) => println!(" Error: Invalid arguments"),
192 }
193}