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>
impl<'a> CommandBuilder<'a, Uninitialized>
Sourcepub fn create_test(
buffer: &'a mut [u8],
at_prefix: bool,
) -> CommandBuilder<'a, Initialized<Test>>
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.
Sourcepub fn create_query(
buffer: &'a mut [u8],
at_prefix: bool,
) -> CommandBuilder<'a, Initialized<Query>>
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.
Sourcepub fn create_set(
buffer: &'a mut [u8],
at_prefix: bool,
) -> CommandBuilder<'a, Initialized<Set>>
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.
Sourcepub fn create_execute(
buffer: &'a mut [u8],
at_prefix: bool,
) -> CommandBuilder<'a, Initialized<Execute>>
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>>
impl<'a, N: Nameable> CommandBuilder<'a, Initialized<N>>
Sourcepub fn named<T: AsRef<[u8]>>(self, name: T) -> CommandBuilder<'a, N>
pub fn named<T: AsRef<[u8]>>(self, name: T) -> CommandBuilder<'a, N>
Set the name of the command.
Source§impl CommandBuilder<'_, Set>
impl CommandBuilder<'_, Set>
Sourcepub fn with_int_parameter<INT: Into<i32>>(self, value: INT) -> Self
pub fn with_int_parameter<INT: Into<i32>>(self, value: INT) -> Self
Add an integer parameter.
Sourcepub fn with_string_parameter<T: AsRef<[u8]>>(self, value: T) -> Self
pub fn with_string_parameter<T: AsRef<[u8]>>(self, value: T) -> Self
Add a string parameter
Sourcepub fn with_optional_int_parameter<INT: Into<i32>>(
self,
value: Option<INT>,
) -> Self
pub fn with_optional_int_parameter<INT: Into<i32>>( self, value: Option<INT>, ) -> Self
Add an optional integer parameter.
Sourcepub fn with_optional_string_parameter<T: AsRef<[u8]>>(
self,
value: Option<T>,
) -> Self
pub fn with_optional_string_parameter<T: AsRef<[u8]>>( self, value: Option<T>, ) -> Self
Add an optional string parameter.
Sourcepub fn with_empty_parameter(self) -> Self
pub fn with_empty_parameter(self) -> Self
Add a comma, representing an unset optional parameter.
Sourcepub fn with_raw_parameter<T: AsRef<[u8]>>(self, value: T) -> Self
pub fn with_raw_parameter<T: AsRef<[u8]>>(self, value: T) -> Self
Add an unformatted parameter
Source§impl<'a, F: Finishable> CommandBuilder<'a, F>
impl<'a, F: Finishable> CommandBuilder<'a, F>
Sourcepub fn finish(self) -> Result<&'a [u8], usize>
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.
Sourcepub fn finish_with(self, terminator: &[u8]) -> Result<&'a [u8], usize>
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.