CommandBuilder

Struct CommandBuilder 

Source
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§

Source§

impl<'a> CommandBuilder<'a, Uninitialized>

Source

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

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.

Source

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

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.

Source

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

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.

Source

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

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.

Source§

impl<'a, N: Nameable> CommandBuilder<'a, Initialized<N>>

Source

pub fn named<T: AsRef<[u8]>>(self, name: T) -> CommandBuilder<'a, N>

Set the name of the command.

Source§

impl CommandBuilder<'_, Set>

Source

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

Add an integer parameter.

Source

pub fn with_string_parameter<T: AsRef<[u8]>>(self, value: T) -> Self

Add a string parameter

Source

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

Add an optional integer parameter.

Source

pub fn with_optional_string_parameter<T: AsRef<[u8]>>( self, value: Option<T>, ) -> Self

Add an optional string parameter.

Source

pub fn with_empty_parameter(self) -> Self

Add a comma, representing an unset optional parameter.

Source

pub fn with_raw_parameter<T: AsRef<[u8]>>(self, value: T) -> Self

Add an unformatted parameter

Source§

impl<'a, F: Finishable> CommandBuilder<'a, F>

Source

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

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.

Source

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

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> Freeze for CommandBuilder<'a, STAGE>

§

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

§

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,

§

impl<'a, STAGE> !UnwindSafe for CommandBuilder<'a, STAGE>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

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

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

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

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

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

The type returned in the event of a conversion error.
Source§

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

Performs the conversion.