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]
impl<'a> CommandBuilder<'a, Uninitialized>[src]pub fn create_test(
buffer: &'a mut [u8],
at_prefix: bool
) -> CommandBuilder<'a, Initialized<Test>>[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]
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]
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]
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]
impl<'a, N: Nameable> CommandBuilder<'a, Initialized<N>>[src]pub fn named(self, name: &str) -> CommandBuilder<'a, N>[src]
pub fn named(self, name: &str) -> CommandBuilder<'a, N>[src]Set the name of the command.
impl<'a> CommandBuilder<'a, Set>[src]
impl<'a> CommandBuilder<'a, Set>[src]pub fn with_int_parameter<INT: Into<i32>>(self, value: INT) -> Self[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]
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]
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]
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]
pub fn with_empty_parameter(self) -> Self[src]Add a comma, representing an unset optional parameter.
impl<'a, F: Finishable> CommandBuilder<'a, F>[src]
impl<'a, F: Finishable> CommandBuilder<'a, F>[src]pub fn finish(self) -> Result<&'a [u8], usize>[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]
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,
STAGE: Send,
impl<'a, STAGE> Sync for CommandBuilder<'a, STAGE> where
STAGE: Sync,
STAGE: Sync,
impl<'a, STAGE> Unpin for CommandBuilder<'a, STAGE> where
STAGE: Unpin,
STAGE: Unpin,