diff --git a/Cargo.lock b/Cargo.lock index 1c415e8..d60b5a2 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -200,7 +200,7 @@ dependencies = [ [[package]] name = "derive_miniconf" version = "0.1.0" -source = "git+https://github.com/quartiq/miniconf.git?rev=c6f2b28#c6f2b28f735e27b337eaa986846536e904c6f2bd" +source = "git+https://github.com/quartiq/miniconf.git?rev=2750533#275053396f0334e9efefa1ab2aae4c19b95a9a53" dependencies = [ "proc-macro2", "quote", @@ -413,11 +413,11 @@ dependencies = [ [[package]] name = "miniconf" version = "0.1.0" -source = "git+https://github.com/quartiq/miniconf.git?rev=c6f2b28#c6f2b28f735e27b337eaa986846536e904c6f2bd" +source = "git+https://github.com/quartiq/miniconf.git?rev=2750533#275053396f0334e9efefa1ab2aae4c19b95a9a53" dependencies = [ "derive_miniconf", "serde", - "serde-json-core 0.3.0", + "serde-json-core", ] [[package]] @@ -706,17 +706,6 @@ dependencies = [ "serde_derive", ] -[[package]] -name = "serde-json-core" -version = "0.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "39af17f40c2a28d2c9a7918663ddc8a10f54cc6f109ead5c3f010869761df186" -dependencies = [ - "heapless 0.6.1", - "ryu", - "serde", -] - [[package]] name = "serde-json-core" version = "0.4.0" @@ -793,7 +782,7 @@ dependencies = [ "rtt-logger", "rtt-target", "serde", - "serde-json-core 0.4.0", + "serde-json-core", "shared-bus", "smoltcp-nal", "stm32h7xx-hal", diff --git a/Cargo.toml b/Cargo.toml index 66dc0a8..21dbd54 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -67,7 +67,7 @@ rev = "a2e3ad5" [patch.crates-io.miniconf] git = "https://github.com/quartiq/miniconf.git" -rev = "c6f2b28" +rev = "2750533" [dependencies.smoltcp-nal] git = "https://github.com/quartiq/smoltcp-nal.git" diff --git a/src/hardware/configuration.rs b/src/hardware/configuration.rs index e2eb653..02aed76 100644 --- a/src/hardware/configuration.rs +++ b/src/hardware/configuration.rs @@ -9,7 +9,7 @@ use stm32h7xx_hal::{ const NUM_SOCKETS: usize = 4; -use heapless::{consts, Vec}; +use heapless::Vec; use smoltcp_nal::smoltcp; use embedded_hal::digital::v2::{InputPin, OutputPin}; @@ -642,7 +642,7 @@ pub fn setup( let mut sockets = smoltcp::socket::SocketSet::new(&mut store.sockets[..]); - let mut handles: Vec = + let mut handles: Vec = Vec::new(); for storage in store.socket_storage.iter_mut() { let tcp_socket = { diff --git a/src/net/messages.rs b/src/net/messages.rs index 167e440..3887fef 100644 --- a/src/net/messages.rs +++ b/src/net/messages.rs @@ -1,4 +1,4 @@ -use heapless::{consts, String, Vec}; +use heapless::{String, Vec}; use serde::Serialize; use core::fmt::Write; @@ -12,15 +12,15 @@ pub enum SettingsResponseCode { /// Represents a generic MQTT message. pub struct MqttMessage<'a> { pub topic: &'a str, - pub message: Vec, - pub properties: Vec, consts::U1>, + pub message: Vec, + pub properties: Vec, 1>, } /// The payload of the MQTT response message to a settings update request. #[derive(Serialize)] pub struct SettingsResponse { code: u8, - msg: String, + msg: String<64>, } impl<'a> MqttMessage<'a> { @@ -48,8 +48,7 @@ impl<'a> MqttMessage<'a> { .unwrap_or(&default_response); // Associate any provided correlation data with the response. - let mut correlation_data: Vec, consts::U1> = - Vec::new(); + let mut correlation_data: Vec, 1> = Vec::new(); if let Some(data) = properties .iter() .find(|prop| matches!(prop, minimq::Property::CorrelationData(_))) diff --git a/src/net/miniconf_client.rs b/src/net/miniconf_client.rs index 76c64d2..cc838f6 100644 --- a/src/net/miniconf_client.rs +++ b/src/net/miniconf_client.rs @@ -10,7 +10,7 @@ ///! ///! Respones to settings updates are sent without quality-of-service guarantees, so there's no ///! guarantee that the requestee will be informed that settings have been applied. -use heapless::{consts, String}; +use heapless::String; use super::{MqttMessage, NetworkReference, SettingsResponse, UpdateState}; use crate::hardware::design_parameters::MQTT_BROKER; @@ -20,11 +20,11 @@ pub struct MiniconfClient where S: miniconf::Miniconf + Default + Clone, { - default_response_topic: String, + default_response_topic: String<128>, mqtt: minimq::Minimq, settings: S, subscribed: bool, - settings_prefix: String, + settings_prefix: String<64>, } impl MiniconfClient @@ -41,10 +41,10 @@ where let mqtt = minimq::Minimq::new(MQTT_BROKER.into(), client_id, stack).unwrap(); - let mut response_topic: String = String::from(prefix); + let mut response_topic: String<128> = String::from(prefix); response_topic.push_str("/log").unwrap(); - let mut settings_prefix: String = String::from(prefix); + let mut settings_prefix: String<64> = String::from(prefix); settings_prefix.push_str("/settings").unwrap(); Self { @@ -81,7 +81,7 @@ where if !self.subscribed && mqtt_connected { // Note(unwrap): We construct a string with two more characters than the prefix // strucutre, so we are guaranteed to have space for storage. - let mut settings_topic: String = + let mut settings_topic: String<66> = String::from(self.settings_prefix.as_str()); settings_topic.push_str("/#").unwrap(); diff --git a/src/net/mod.rs b/src/net/mod.rs index 64c9401..bdb871f 100644 --- a/src/net/mod.rs +++ b/src/net/mod.rs @@ -5,7 +5,7 @@ ///! telemetry (via MQTT), configuration of run-time settings (via MQTT + Miniconf), and live data ///! streaming over raw UDP/TCP sockets. This module encompasses the main processing routines ///! related to Stabilizer networking operations. -use heapless::{consts, String}; +use heapless::String; use miniconf::Miniconf; use serde::Serialize; @@ -134,7 +134,7 @@ fn get_client_id( app: &str, client: &str, mac: smoltcp_nal::smoltcp::wire::EthernetAddress, -) -> String { +) -> String<64> { let mut identifier = String::new(); write!(&mut identifier, "{}-{}-{}", app, mac, client).unwrap(); identifier @@ -151,10 +151,10 @@ fn get_client_id( pub fn get_device_prefix( app: &str, mac: smoltcp_nal::smoltcp::wire::EthernetAddress, -) -> String { +) -> String<128> { // Note(unwrap): The mac address + binary name must be short enough to fit into this string. If // they are defined too long, this will panic and the device will fail to boot. - let mut prefix: String = String::new(); + let mut prefix: String<128> = String::new(); write!(&mut prefix, "dt/sinara/{}/{}", app, mac).unwrap(); prefix diff --git a/src/net/telemetry.rs b/src/net/telemetry.rs index b6b9c34..d976fee 100644 --- a/src/net/telemetry.rs +++ b/src/net/telemetry.rs @@ -10,7 +10,7 @@ ///! sampling frequency. Instead, the raw codes are stored and the telemetry is generated as ///! required immediately before transmission. This ensures that any slower computation required ///! for unit conversion can be off-loaded to lower priority tasks. -use heapless::{consts, String, Vec}; +use heapless::{String, Vec}; use minimq::QoS; use serde::Serialize; @@ -22,7 +22,7 @@ use crate::hardware::{ /// The telemetry client for reporting telemetry data over MQTT. pub struct TelemetryClient { mqtt: minimq::Minimq, - telemetry_topic: String, + telemetry_topic: String<128>, _telemetry: core::marker::PhantomData, } @@ -99,7 +99,7 @@ impl TelemetryClient { let mqtt = minimq::Minimq::new(MQTT_BROKER.into(), client_id, stack).unwrap(); - let mut telemetry_topic: String = String::from(prefix); + let mut telemetry_topic: String<128> = String::from(prefix); telemetry_topic.push_str("/telemetry").unwrap(); Self { @@ -118,7 +118,7 @@ impl TelemetryClient { /// # Args /// * `telemetry` - The telemetry to report pub fn publish(&mut self, telemetry: &T) { - let telemetry: Vec = + let telemetry: Vec = serde_json_core::to_vec(telemetry).unwrap(); self.mqtt .client