pub struct CommandBuilder<'a, STAGE> { /* private fields */ }
Expand description

CommandBuilder

A builder struct for AT Commands

Summary

This can be used to build:

  • A test command in the form AT{name}=?
  • A query command in the form AT{name}?
  • A set command in the form AT{name}={param},{param},{param}
  • An execute command in the form AT{name}

Example

use at_commands::builder::CommandBuilder;

let mut buffer = [0; 128];

// Make a query command
let result = CommandBuilder::create_query(&mut buffer, true)
    .named("+MYQUERY")
    .finish()
    .unwrap();

// Buffer now contains "AT+MYQUERY?"
// Copy or DMA the resulting slice to the device.

// Make a set command
let result = CommandBuilder::create_set(&mut buffer, false)
    .named("+MYSET")
    .with_int_parameter(42)
    .finish()
    .unwrap();

// Buffer now contains "+MYSET=42"
// Copy or DMA the resulting slice to the device.

Implementations

Creates a builder for a test command.

The given buffer is used to build the command in and must be big enough to contain it.

Creates a builder for a query command.

The given buffer is used to build the command in and must be big enough to contain it.

Creates a builder for a set command.

The given buffer is used to build the command in and must be big enough to contain it.

Creates a builder for an test execute.

The given buffer is used to build the command in and must be big enough to contain it.

Set the name of the command.

Add an integer parameter.

Add a string parameter

Add an optional integer parameter.

Add an optional string parameter.

Add a comma, representing an unset optional parameter.

Finishes the builder.

When Ok, it returns a slice with the built command. The slice points to the same memory as the buffer, but is only as long as is required to contain the command.

The command length is thus the length of the slice.

If the buffer was not long enough, then an Err is returned with the size that was required for it to succeed.

Finishes the builder.

With the terminator variable, you can decide how to end the command. Normally this is \r\n.

use at_commands::builder::CommandBuilder;

let mut buffer = [0; 128];

// Make a query command
let result = CommandBuilder::create_query(&mut buffer, true)
    .named("+MYQUERY")
    .finish_with(b"\0")
    .unwrap();

When Ok, it returns a slice with the built command. The slice points to the same memory as the buffer, but is only as long as is required to contain the command.

The command length is thus the length of the slice.

If the buffer was not long enough, then an Err is returned with the size that was required for it to succeed.

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.