Struct at_commands::builder::CommandBuilder[][src]

pub struct CommandBuilder<'a, STAGE> { /* fields omitted */ }
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

impl<'a> CommandBuilder<'a, Uninitialized>[src]

pub fn create_test(
    buffer: &'a mut [u8],
    at_prefix: bool
) -> CommandBuilder<'a, Initialized<Test>>
[src]

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.

pub fn create_query(
    buffer: &'a mut [u8],
    at_prefix: bool
) -> CommandBuilder<'a, Initialized<Query>>
[src]

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.

pub fn create_set(
    buffer: &'a mut [u8],
    at_prefix: bool
) -> CommandBuilder<'a, Initialized<Set>>
[src]

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.

pub fn create_execute(
    buffer: &'a mut [u8],
    at_prefix: bool
) -> CommandBuilder<'a, Initialized<Execute>>
[src]

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.

impl<'a, N: Nameable> CommandBuilder<'a, Initialized<N>>[src]

pub fn named(self, name: &str) -> CommandBuilder<'a, N>[src]

Set the name of the command.

impl<'a> CommandBuilder<'a, Set>[src]

pub fn with_int_parameter<INT: Into<i32>>(self, value: INT) -> Self[src]

Add an integer parameter.

pub fn with_string_parameter(self, value: &str) -> Self[src]

Add a string parameter

pub fn with_optional_int_parameter<INT: Into<i32>>(
    self,
    value: Option<INT>
) -> Self
[src]

Add an optional integer parameter.

pub fn with_optional_string_parameter(self, value: Option<&str>) -> Self[src]

Add an optional string parameter.

pub fn with_empty_parameter(self) -> Self[src]

Add a comma, representing an unset optional parameter.

impl<'a, F: Finishable> CommandBuilder<'a, F>[src]

pub fn finish(self) -> Result<&'a [u8], usize>[src]

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.

pub fn finish_with(self, terminator: &[u8]) -> Result<&'a [u8], usize>[src]

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

impl<'a, STAGE> Send for CommandBuilder<'a, STAGE> where
    STAGE: Send

impl<'a, STAGE> Sync for CommandBuilder<'a, STAGE> where
    STAGE: Sync

impl<'a, STAGE> Unpin for CommandBuilder<'a, STAGE> where
    STAGE: Unpin

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

pub fn type_id(&self) -> TypeId[src]

Gets the TypeId of self. Read more

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

pub fn borrow(&self) -> &T[src]

Immutably borrows from an owned value. Read more

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

pub fn borrow_mut(&mut self) -> &mut T[src]

Mutably borrows from an owned value. Read more

impl<T> From<T> for T[src]

pub fn from(t: T) -> T[src]

Performs the conversion.

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

pub fn into(self) -> U[src]

Performs the conversion.

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

pub fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>[src]

Performs the conversion.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.

pub fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>[src]

Performs the conversion.