Updating the embedded-nal

This commit is contained in:
Ryan Summers 2021-05-27 13:42:52 +02:00
parent 9c92100c6d
commit f10bce709f
5 changed files with 55 additions and 40 deletions

62
Cargo.lock generated
View File

@ -42,6 +42,15 @@ dependencies = [
"embedded-hal", "embedded-hal",
] ]
[[package]]
name = "atomic-polyfill"
version = "0.1.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "30302dda7a66f8c55932ebf208f7def840743ff64d495e9ceffcd97c18f11d39"
dependencies = [
"cortex-m 0.7.2",
]
[[package]] [[package]]
name = "autocfg" name = "autocfg"
version = "1.0.1" version = "1.0.1"
@ -240,11 +249,11 @@ dependencies = [
[[package]] [[package]]
name = "embedded-nal" name = "embedded-nal"
version = "0.1.0" version = "0.6.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ae46eb1b02de5a76d9d0ea21d657ff5b0ad2cc47f3a7723608227b1dd1b3eb18" checksum = "db9efecb57ab54fa918730f2874d7d37647169c50fa1357fecb81abee840b113"
dependencies = [ dependencies = [
"heapless 0.5.6", "heapless 0.7.1",
"nb 1.0.0", "nb 1.0.0",
"no-std-net", "no-std-net",
] ]
@ -317,24 +326,21 @@ dependencies = [
"byteorder", "byteorder",
] ]
[[package]]
name = "hash32"
version = "0.2.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b0c35f58762feb77d74ebe43bdbc3210f09be9fe6742234d573bacc26ed92b67"
dependencies = [
"byteorder",
]
[[package]] [[package]]
name = "hashbrown" name = "hashbrown"
version = "0.9.1" version = "0.9.1"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d7afe4a420e3fe79967a00898cc1f4db7c8a49a9333a29f8a4bd76a253d5cd04" checksum = "d7afe4a420e3fe79967a00898cc1f4db7c8a49a9333a29f8a4bd76a253d5cd04"
[[package]]
name = "heapless"
version = "0.5.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "74911a68a1658cfcfb61bc0ccfbd536e3b6e906f8c2f7883ee50157e3e2184f1"
dependencies = [
"as-slice",
"generic-array 0.13.3",
"hash32",
"stable_deref_trait",
]
[[package]] [[package]]
name = "heapless" name = "heapless"
version = "0.6.1" version = "0.6.1"
@ -343,11 +349,22 @@ checksum = "634bd4d29cbf24424d0a4bfcbf80c6960129dc24424752a7d1d1390607023422"
dependencies = [ dependencies = [
"as-slice", "as-slice",
"generic-array 0.14.4", "generic-array 0.14.4",
"hash32", "hash32 0.1.1",
"serde", "serde",
"stable_deref_trait", "stable_deref_trait",
] ]
[[package]]
name = "heapless"
version = "0.7.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c7ee8a997d259962217f40279f34201fdf06e669bafa69d7c1f4c7ff1893b5f6"
dependencies = [
"atomic-polyfill",
"hash32 0.2.1",
"stable_deref_trait",
]
[[package]] [[package]]
name = "indexmap" name = "indexmap"
version = "1.6.2" version = "1.6.2"
@ -409,13 +426,12 @@ dependencies = [
[[package]] [[package]]
name = "minimq" name = "minimq"
version = "0.2.0" version = "0.2.0"
source = "git+https://github.com/quartiq/minimq.git?rev=d2ec3e8#d2ec3e8351fa403ea96defd98c0b4410cbaa18a4" source = "git+https://github.com/quartiq/minimq.git?branch=feature/nal-update#98c1dffc4b0eeeaadf696320e1ce4234d5b52de0"
dependencies = [ dependencies = [
"bit_field", "bit_field",
"embedded-nal", "embedded-nal",
"enum-iterator", "enum-iterator",
"generic-array 0.14.4", "heapless 0.7.1",
"heapless 0.6.1",
] ]
[[package]] [[package]]
@ -454,9 +470,9 @@ dependencies = [
[[package]] [[package]]
name = "no-std-net" name = "no-std-net"
version = "0.4.0" version = "0.5.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2178127478ae4ee9be7180bc9c3bffb6354dd7238400db567102f98c413a9f35" checksum = "1bcece43b12349917e096cddfa66107277f123e6c96a5aea78711dc601a47152"
[[package]] [[package]]
name = "num" name = "num"
@ -745,10 +761,10 @@ dependencies = [
[[package]] [[package]]
name = "smoltcp-nal" name = "smoltcp-nal"
version = "0.1.0" version = "0.1.0"
source = "git+https://github.com/quartiq/smoltcp-nal.git?rev=4a1711c#4a1711c54cdf79f5ee8c1c99a1e8984f5944270c" source = "git+https://github.com/quartiq/smoltcp-nal.git?branch=feature/nal-update#65d94c4ab9e06d2e5c48547a0c9cd6836591e355"
dependencies = [ dependencies = [
"embedded-nal", "embedded-nal",
"heapless 0.6.1", "heapless 0.7.1",
"nanorand", "nanorand",
"smoltcp", "smoltcp",
] ]

View File

@ -64,11 +64,11 @@ rev = "c6f2b28"
[dependencies.smoltcp-nal] [dependencies.smoltcp-nal]
git = "https://github.com/quartiq/smoltcp-nal.git" git = "https://github.com/quartiq/smoltcp-nal.git"
rev = "4a1711c" branch = "feature/nal-update"
[dependencies.minimq] [dependencies.minimq]
git = "https://github.com/quartiq/minimq.git" git = "https://github.com/quartiq/minimq.git"
rev = "d2ec3e8" branch = "feature/nal-update"
[features] [features]
nightly = ["cortex-m/inline-asm", "dsp/nightly"] nightly = ["cortex-m/inline-asm", "dsp/nightly"]

View File

@ -21,7 +21,7 @@ where
S: miniconf::Miniconf + Default + Clone, S: miniconf::Miniconf + Default + Clone,
{ {
default_response_topic: String<consts::U128>, default_response_topic: String<consts::U128>,
mqtt: minimq::MqttClient<minimq::consts::U256, NetworkReference>, mqtt: minimq::Minimq<NetworkReference, 256>,
settings: S, settings: S,
subscribed: bool, subscribed: bool,
settings_prefix: String<consts::U64>, settings_prefix: String<consts::U64>,
@ -39,8 +39,7 @@ where
/// * `prefix` - The MQTT device prefix to use for this device. /// * `prefix` - The MQTT device prefix to use for this device.
pub fn new(stack: NetworkReference, client_id: &str, prefix: &str) -> Self { pub fn new(stack: NetworkReference, client_id: &str, prefix: &str) -> Self {
let mqtt = let mqtt =
minimq::MqttClient::new(MQTT_BROKER.into(), client_id, stack) minimq::Minimq::new(MQTT_BROKER.into(), client_id, stack).unwrap();
.unwrap();
let mut response_topic: String<consts::U128> = String::from(prefix); let mut response_topic: String<consts::U128> = String::from(prefix);
response_topic.push_str("/log").unwrap(); response_topic.push_str("/log").unwrap();
@ -62,7 +61,7 @@ where
/// # Returns /// # Returns
/// An option containing an action that should be completed as a result of network servicing. /// An option containing an action that should be completed as a result of network servicing.
pub fn update(&mut self) -> UpdateState { pub fn update(&mut self) -> UpdateState {
let mqtt_connected = match self.mqtt.is_connected() { let mqtt_connected = match self.mqtt.client.is_connected() {
Ok(connected) => connected, Ok(connected) => connected,
Err(minimq::Error::Network( Err(minimq::Error::Network(
smoltcp_nal::NetworkError::NoIpAddress, smoltcp_nal::NetworkError::NoIpAddress,
@ -88,7 +87,7 @@ where
// We do not currently handle or process potential subscription failures. Instead, this // We do not currently handle or process potential subscription failures. Instead, this
// failure will be logged through the stabilizer logging interface. // failure will be logged through the stabilizer logging interface.
self.mqtt.subscribe(&settings_topic, &[]).unwrap(); self.mqtt.client.subscribe(&settings_topic, &[]).unwrap();
self.subscribed = true; self.subscribed = true;
} }

View File

@ -47,25 +47,25 @@ impl<'a, S> NetworkStackProxy<'a, S> {
// proxy structure. // proxy structure.
macro_rules! forward { macro_rules! forward {
($func:ident($($v:ident: $IT:ty),*) -> $T:ty) => { ($func:ident($($v:ident: $IT:ty),*) -> $T:ty) => {
fn $func(&self, $($v: $IT),*) -> $T { fn $func(&mut self, $($v: $IT),*) -> $T {
self.mutex.lock(|stack| stack.$func($($v),*)) self.mutex.lock(|stack| stack.$func($($v),*))
} }
} }
} }
// Implement a TCP stack for the proxy if the underlying network stack implements it. // Implement a TCP stack for the proxy if the underlying network stack implements it.
impl<'a, S> embedded_nal::TcpStack for NetworkStackProxy<'a, S> impl<'a, S> embedded_nal::TcpClientStack for NetworkStackProxy<'a, S>
where where
S: embedded_nal::TcpStack, S: embedded_nal::TcpClientStack,
{ {
type TcpSocket = S::TcpSocket; type TcpSocket = S::TcpSocket;
type Error = S::Error; type Error = S::Error;
forward! {open(mode: embedded_nal::Mode) -> Result<S::TcpSocket, S::Error>} forward! {socket() -> Result<S::TcpSocket, S::Error>}
forward! {connect(socket: S::TcpSocket, remote: embedded_nal::SocketAddr) -> Result<S::TcpSocket, S::Error>} forward! {connect(socket: &mut S::TcpSocket, remote: embedded_nal::SocketAddr) -> embedded_nal::nb::Result<(), S::Error>}
forward! {is_connected(socket: &S::TcpSocket) -> Result<bool, S::Error>} forward! {is_connected(socket: &S::TcpSocket) -> Result<bool, S::Error>}
forward! {write(socket: &mut S::TcpSocket, buffer: &[u8]) -> embedded_nal::nb::Result<usize, S::Error>} forward! {send(socket: &mut S::TcpSocket, buffer: &[u8]) -> embedded_nal::nb::Result<usize, S::Error>}
forward! {read(socket: &mut S::TcpSocket, buffer: &mut [u8]) -> embedded_nal::nb::Result<usize, S::Error>} forward! {receive(socket: &mut S::TcpSocket, buffer: &mut [u8]) -> embedded_nal::nb::Result<usize, S::Error>}
forward! {close(socket: S::TcpSocket) -> Result<(), S::Error>} forward! {close(socket: S::TcpSocket) -> Result<(), S::Error>}
} }

View File

@ -21,7 +21,7 @@ use crate::hardware::{
/// The telemetry client for reporting telemetry data over MQTT. /// The telemetry client for reporting telemetry data over MQTT.
pub struct TelemetryClient<T: Serialize> { pub struct TelemetryClient<T: Serialize> {
mqtt: minimq::MqttClient<minimq::consts::U256, NetworkReference>, mqtt: minimq::Minimq<NetworkReference, 256>,
telemetry_topic: String<consts::U128>, telemetry_topic: String<consts::U128>,
_telemetry: core::marker::PhantomData<T>, _telemetry: core::marker::PhantomData<T>,
} }
@ -97,8 +97,7 @@ impl<T: Serialize> TelemetryClient<T> {
/// A new telemetry client. /// A new telemetry client.
pub fn new(stack: NetworkReference, client_id: &str, prefix: &str) -> Self { pub fn new(stack: NetworkReference, client_id: &str, prefix: &str) -> Self {
let mqtt = let mqtt =
minimq::MqttClient::new(MQTT_BROKER.into(), client_id, stack) minimq::Minimq::new(MQTT_BROKER.into(), client_id, stack).unwrap();
.unwrap();
let mut telemetry_topic: String<consts::U128> = String::from(prefix); let mut telemetry_topic: String<consts::U128> = String::from(prefix);
telemetry_topic.push_str("/telemetry").unwrap(); telemetry_topic.push_str("/telemetry").unwrap();
@ -122,6 +121,7 @@ impl<T: Serialize> TelemetryClient<T> {
let telemetry: Vec<u8, consts::U256> = let telemetry: Vec<u8, consts::U256> =
serde_json_core::to_vec(telemetry).unwrap(); serde_json_core::to_vec(telemetry).unwrap();
self.mqtt self.mqtt
.client
.publish(&self.telemetry_topic, &telemetry, QoS::AtMostOnce, &[]) .publish(&self.telemetry_topic, &telemetry, QoS::AtMostOnce, &[])
.ok(); .ok();
} }