Skip to main content

AtContext

Trait AtContext 

Source
pub trait AtContext<const SIZE: usize> {
    // Provided methods
    fn exec(&self) -> AtResult<SIZE> { ... }
    fn query(&mut self) -> AtResult<SIZE> { ... }
    fn test(&mut self) -> AtResult<SIZE> { ... }
    fn set(&mut self, _args: Args<'_>) -> AtResult<SIZE> { ... }
}
Expand description

Trait that defines the context for AT command execution. Implementations of this trait handle the actual logic for each AT command form.

The const generic SIZE defines the size (in bytes) of the response buffer returned by command handlers.

Provided Methods§

Source

fn exec(&self) -> AtResult<SIZE>

Execute command (AT+CMD) This is called when a command is invoked without any suffix.

Examples found in repository?
examples/complete_usage.rs (line 178)
175fn execute_command(cmd: &str, name: &str, module: &mut dyn AtContext<SIZE>) {
176    let result = if let Some(rest) = cmd.strip_prefix(name) {
177        if rest.is_empty() {
178            module.exec()
179        } else if rest == "?" {
180            module.query()
181        } else if rest == "=?" {
182            module.test()
183        } else if let Some(args_str) = rest.strip_prefix('=') {
184            module.set(Args { raw: args_str })
185        } else {
186            Err(AtError::InvalidArgs)
187        }
188    } else {
189        Err(AtError::UnknownCommand)
190    };
191    let _ = result;
192}
Source

fn query(&mut self) -> AtResult<SIZE>

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 180)
175fn execute_command(cmd: &str, name: &str, module: &mut dyn AtContext<SIZE>) {
176    let result = if let Some(rest) = cmd.strip_prefix(name) {
177        if rest.is_empty() {
178            module.exec()
179        } else if rest == "?" {
180            module.query()
181        } else if rest == "=?" {
182            module.test()
183        } else if let Some(args_str) = rest.strip_prefix('=') {
184            module.set(Args { raw: args_str })
185        } else {
186            Err(AtError::InvalidArgs)
187        }
188    } else {
189        Err(AtError::UnknownCommand)
190    };
191    let _ = result;
192}
Source

fn test(&mut self) -> AtResult<SIZE>

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 182)
175fn execute_command(cmd: &str, name: &str, module: &mut dyn AtContext<SIZE>) {
176    let result = if let Some(rest) = cmd.strip_prefix(name) {
177        if rest.is_empty() {
178            module.exec()
179        } else if rest == "?" {
180            module.query()
181        } else if rest == "=?" {
182            module.test()
183        } else if let Some(args_str) = rest.strip_prefix('=') {
184            module.set(Args { raw: args_str })
185        } else {
186            Err(AtError::InvalidArgs)
187        }
188    } else {
189        Err(AtError::UnknownCommand)
190    };
191    let _ = result;
192}
Source

fn set(&mut self, _args: Args<'_>) -> AtResult<SIZE>

Set command (AT+CMD=args) This is called to set parameters for a command.

Examples found in repository?
examples/complete_usage.rs (line 184)
175fn execute_command(cmd: &str, name: &str, module: &mut dyn AtContext<SIZE>) {
176    let result = if let Some(rest) = cmd.strip_prefix(name) {
177        if rest.is_empty() {
178            module.exec()
179        } else if rest == "?" {
180            module.query()
181        } else if rest == "=?" {
182            module.test()
183        } else if let Some(args_str) = rest.strip_prefix('=') {
184            module.set(Args { raw: args_str })
185        } else {
186            Err(AtError::InvalidArgs)
187        }
188    } else {
189        Err(AtError::UnknownCommand)
190    };
191    let _ = result;
192}

Implementors§