Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updating dependencies + embedded-nal #370

Merged
merged 2 commits into from
May 27, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 38 additions & 22 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -64,11 +64,11 @@ rev = "c6f2b28"

[dependencies.smoltcp-nal]
git = "https://github.com/quartiq/smoltcp-nal.git"
rev = "4a1711c"
rev = "5e56576"

[dependencies.minimq]
git = "https://github.com/quartiq/minimq.git"
rev = "d2ec3e8"
rev = "dbdbec0"

[features]
nightly = ["cortex-m/inline-asm", "dsp/nightly"]
Expand Down
9 changes: 4 additions & 5 deletions src/net/miniconf_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ where
S: miniconf::Miniconf + Default + Clone,
{
default_response_topic: String<consts::U128>,
mqtt: minimq::MqttClient<minimq::consts::U256, NetworkReference>,
mqtt: minimq::Minimq<NetworkReference, 256>,
settings: S,
subscribed: bool,
settings_prefix: String<consts::U64>,
Expand All @@ -39,8 +39,7 @@ where
/// * `prefix` - The MQTT device prefix to use for this device.
pub fn new(stack: NetworkReference, client_id: &str, prefix: &str) -> Self {
let mqtt =
minimq::MqttClient::new(MQTT_BROKER.into(), client_id, stack)
.unwrap();
minimq::Minimq::new(MQTT_BROKER.into(), client_id, stack).unwrap();

let mut response_topic: String<consts::U128> = String::from(prefix);
response_topic.push_str("/log").unwrap();
Expand All @@ -62,7 +61,7 @@ where
/// # Returns
/// An option containing an action that should be completed as a result of network servicing.
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,
Err(minimq::Error::Network(
smoltcp_nal::NetworkError::NoIpAddress,
Expand All @@ -88,7 +87,7 @@ where

// We do not currently handle or process potential subscription failures. Instead, this
// 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;
}

Expand Down
14 changes: 7 additions & 7 deletions src/net/shared.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,25 +47,25 @@ impl<'a, S> NetworkStackProxy<'a, S> {
// proxy structure.
macro_rules! forward {
($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),*))
}
}
}

// 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
S: embedded_nal::TcpStack,
S: embedded_nal::TcpClientStack,
{
type TcpSocket = S::TcpSocket;
type Error = S::Error;

forward! {open(mode: embedded_nal::Mode) -> Result<S::TcpSocket, S::Error>}
forward! {connect(socket: S::TcpSocket, remote: embedded_nal::SocketAddr) -> Result<S::TcpSocket, S::Error>}
forward! {socket() -> 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! {write(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! {send(socket: &mut S::TcpSocket, buffer: &[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>}
}

Expand Down
6 changes: 3 additions & 3 deletions src/net/telemetry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ use crate::hardware::{

/// The telemetry client for reporting telemetry data over MQTT.
pub struct TelemetryClient<T: Serialize> {
mqtt: minimq::MqttClient<minimq::consts::U256, NetworkReference>,
mqtt: minimq::Minimq<NetworkReference, 256>,
telemetry_topic: String<consts::U128>,
_telemetry: core::marker::PhantomData<T>,
}
Expand Down Expand Up @@ -97,8 +97,7 @@ impl<T: Serialize> TelemetryClient<T> {
/// A new telemetry client.
pub fn new(stack: NetworkReference, client_id: &str, prefix: &str) -> Self {
let mqtt =
minimq::MqttClient::new(MQTT_BROKER.into(), client_id, stack)
.unwrap();
minimq::Minimq::new(MQTT_BROKER.into(), client_id, stack).unwrap();

let mut telemetry_topic: String<consts::U128> = String::from(prefix);
telemetry_topic.push_str("/telemetry").unwrap();
Expand All @@ -122,6 +121,7 @@ impl<T: Serialize> TelemetryClient<T> {
let telemetry: Vec<u8, consts::U256> =
serde_json_core::to_vec(telemetry).unwrap();
self.mqtt
.client
.publish(&self.telemetry_topic, &telemetry, QoS::AtMostOnce, &[])
.ok();
}
Expand Down