Tests
This commit is contained in:
@@ -22,25 +22,33 @@
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
use heapless::Vec;
|
||||
use crate::packet::v5::property::Property;
|
||||
use crate::packet::v5::publish_packet::QualityOfService;
|
||||
use crate::utils::types::{BinaryData, EncodedString};
|
||||
|
||||
pub struct ClientConfig<'a> {
|
||||
pub struct ClientConfig<'a, const MAX_PROPERTIES: usize> {
|
||||
pub qos: QualityOfService,
|
||||
pub keep_alive: u16,
|
||||
pub client_id: EncodedString<'a>,
|
||||
pub username_flag: bool,
|
||||
pub username: EncodedString<'a>,
|
||||
pub password_flag: bool,
|
||||
pub password: BinaryData<'a>,
|
||||
pub properties: Vec<Property<'a>, MAX_PROPERTIES>,
|
||||
}
|
||||
|
||||
impl ClientConfig<'a> {
|
||||
impl<'a, const MAX_PROPERTIES: usize> ClientConfig<'a, MAX_PROPERTIES> {
|
||||
pub fn new() -> Self {
|
||||
Self {
|
||||
qos: QualityOfService::QoS0,
|
||||
keep_alive: 60,
|
||||
client_id: EncodedString::new(),
|
||||
username_flag: false,
|
||||
username: EncodedString::new(),
|
||||
password_flag: false,
|
||||
password: BinaryData::new(),
|
||||
properties: Vec::<Property<'a>, MAX_PROPERTIES>::new()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -63,4 +71,10 @@ impl ClientConfig<'a> {
|
||||
self.password = password_s;
|
||||
self.password_flag = true;
|
||||
}
|
||||
|
||||
pub fn add_property(&mut self, prop: Property<'a>) {
|
||||
if self.properties.len() < MAX_PROPERTIES {
|
||||
self.properties.push(prop);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -25,7 +25,7 @@ pub struct MqttClientV5<'a, T, const MAX_PROPERTIES: usize> {
|
||||
recv_buffer: &'a mut [u8],
|
||||
recv_buffer_len: usize,
|
||||
rng: CountingRng,
|
||||
config: ClientConfig<'a>,
|
||||
config: ClientConfig<'a, MAX_PROPERTIES>,
|
||||
}
|
||||
|
||||
impl<'a, T, const MAX_PROPERTIES: usize> MqttClientV5<'a, T, MAX_PROPERTIES>
|
||||
@@ -38,7 +38,7 @@ where
|
||||
buffer_len: usize,
|
||||
recv_buffer: &'a mut [u8],
|
||||
recv_buffer_len: usize,
|
||||
config: ClientConfig<'a>,
|
||||
config: ClientConfig<'a, MAX_PROPERTIES>,
|
||||
) -> Self {
|
||||
Self {
|
||||
network_driver,
|
||||
@@ -54,6 +54,7 @@ where
|
||||
pub async fn connect_to_broker<'b>(&'b mut self) -> Result<(), ReasonCode> {
|
||||
let len = {
|
||||
let mut connect = ConnectPacket::<'b, 3, 0>::clean();
|
||||
connect.keep_alive = self.config.keep_alive;
|
||||
if self.config.username_flag {
|
||||
connect.add_username(&self.config.username);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user