From 7bf7a310c8712b15f41f78c6d6864dd5713440d9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Robert=20J=C3=B6rdens?= Date: Thu, 10 Aug 2023 18:03:42 +0200 Subject: [PATCH 01/17] new miniconf (trait split) --- Cargo.lock | 6 ++---- Cargo.toml | 2 +- src/bin/dual-iir.rs | 10 +++++----- src/bin/lockin.rs | 8 ++++---- src/hardware/signal_generator.rs | 4 ++-- src/net/mod.rs | 6 +++--- 6 files changed, 17 insertions(+), 19 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index ba9f831b1..89973b38e 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -416,8 +416,7 @@ dependencies = [ [[package]] name = "miniconf" version = "0.8.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9e34fb3249ad071debda2ceb8d29e271d0fd283039f7bf04d9d7921dec4e6b4e" +source = "git+https://github.com/quartiq/miniconf.git?branch=trait-split#61d4d09c88c7fab852b527960889ceb4d8975960" dependencies = [ "heapless", "itoa", @@ -432,8 +431,7 @@ dependencies = [ [[package]] name = "miniconf_derive" version = "0.8.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c2327f540b14c86184b066abe25daca988c15c60f0d9a215d2a37f3032805d47" +source = "git+https://github.com/quartiq/miniconf.git?branch=trait-split#61d4d09c88c7fab852b527960889ceb4d8975960" dependencies = [ "proc-macro2", "quote", diff --git a/Cargo.toml b/Cargo.toml index ae2a343a7..c6e34dca8 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -60,7 +60,7 @@ enum-iterator = "1.4.1" rand_xorshift = "0.3.0" rand_core = "0.6.4" minimq = "0.7" -miniconf = "0.8" +miniconf = { git = "https://github.com/quartiq/miniconf.git", branch = "trait-split"} # "0.8" smoltcp-nal = { version = "0.4", features = ["shared-stack"]} [dependencies.stm32h7xx-hal] diff --git a/src/bin/dual-iir.rs b/src/bin/dual-iir.rs index 2de314530..0b3fd1a5e 100644 --- a/src/bin/dual-iir.rs +++ b/src/bin/dual-iir.rs @@ -50,7 +50,7 @@ use stabilizer::{ }, net::{ data_stream::{FrameGenerator, StreamFormat, StreamTarget}, - miniconf::Miniconf, + miniconf::Tree, telemetry::{Telemetry, TelemetryBuffer}, NetworkState, NetworkUsers, }, @@ -71,7 +71,7 @@ const SAMPLE_TICKS: u32 = 1 << SAMPLE_TICKS_LOG2; const SAMPLE_PERIOD: f32 = SAMPLE_TICKS as f32 * hardware::design_parameters::TIMER_PERIOD; -#[derive(Clone, Copy, Debug, Miniconf)] +#[derive(Clone, Copy, Debug, Tree)] pub struct Settings { /// Configure the Analog Front End (AFE) gain. /// @@ -82,7 +82,7 @@ pub struct Settings { /// /// # Value /// Any of the variants of [Gain] enclosed in double quotes. - #[miniconf(defer)] + #[tree()] afe: [Gain; 2], /// Configure the IIR filter parameters. @@ -95,7 +95,7 @@ pub struct Settings { /// /// # Value /// See [iir::IIR#miniconf] - #[miniconf(defer(2))] + #[tree(depth(2))] iir_ch: [[iir::IIR; IIR_CASCADE_LENGTH]; 2], /// Specified true if DI1 should be used as a "hold" input. @@ -143,7 +143,7 @@ pub struct Settings { /// /// # Value /// See [signal_generator::BasicConfig#miniconf] - #[miniconf(defer(2))] + #[tree(depth(2))] signal_generator: [signal_generator::BasicConfig; 2], } diff --git a/src/bin/lockin.rs b/src/bin/lockin.rs index 342765907..86da4d4e6 100644 --- a/src/bin/lockin.rs +++ b/src/bin/lockin.rs @@ -53,7 +53,7 @@ use stabilizer::{ }, net::{ data_stream::{FrameGenerator, StreamFormat, StreamTarget}, - miniconf::Miniconf, + miniconf::Tree, serde::{Deserialize, Serialize}, telemetry::{Telemetry, TelemetryBuffer}, NetworkState, NetworkUsers, @@ -97,7 +97,7 @@ enum LockinMode { External, } -#[derive(Copy, Clone, Debug, Miniconf)] +#[derive(Copy, Clone, Debug, Tree)] pub struct Settings { /// Configure the Analog Front End (AFE) gain. /// @@ -108,7 +108,7 @@ pub struct Settings { /// /// # Value /// Any of the variants of [Gain] enclosed in double quotes. - #[miniconf(defer)] + #[tree()] afe: [Gain; 2], /// Specifies the operational mode of the lockin. @@ -168,7 +168,7 @@ pub struct Settings { /// /// # Value /// One of the variants of [Conf] enclosed in double quotes. - #[miniconf(defer)] + #[tree()] output_conf: [Conf; 2], /// Specifies the telemetry output period in seconds. diff --git a/src/hardware/signal_generator.rs b/src/hardware/signal_generator.rs index d4d55efb0..71b642823 100644 --- a/src/hardware/signal_generator.rs +++ b/src/hardware/signal_generator.rs @@ -1,4 +1,4 @@ -use miniconf::Miniconf; +use miniconf::Tree; use rand_core::{RngCore, SeedableRng}; use rand_xorshift::XorShiftRng; use serde::{Deserialize, Serialize}; @@ -20,7 +20,7 @@ pub enum Signal { /// Where `` may be any of [Signal] variants, `frequency` specifies the signal frequency /// in Hertz, `symmetry` specifies the normalized signal symmetry which ranges from 0 - 1.0, and /// `amplitude` specifies the signal amplitude in Volts. -#[derive(Copy, Clone, Debug, Miniconf)] +#[derive(Copy, Clone, Debug, Tree)] pub struct BasicConfig { /// The signal type that should be generated. See [Signal] variants. pub signal: Signal, diff --git a/src/net/mod.rs b/src/net/mod.rs index 8ce4d27aa..c06f0f3c6 100644 --- a/src/net/mod.rs +++ b/src/net/mod.rs @@ -21,7 +21,7 @@ use telemetry::TelemetryClient; use core::fmt::Write; use heapless::String; -use miniconf::Miniconf; +use miniconf::{TreeDeserialize, TreeSerialize}; use serde::Serialize; use smoltcp_nal::embedded_nal::SocketAddr; @@ -44,7 +44,7 @@ pub enum NetworkState { /// A structure of Stabilizer's default network users. pub struct NetworkUsers< - S: Default + Miniconf + Clone, + S: Default + TreeSerialize + TreeDeserialize + Clone, T: Serialize, const Y: usize, > { @@ -58,7 +58,7 @@ pub struct NetworkUsers< impl NetworkUsers where - S: Default + Miniconf + Clone, + S: Default + TreeSerialize + TreeDeserialize + Clone, T: Serialize, { /// Construct Stabilizer's default network users. From 0897752e2e814efb9b306ee3e07ed7e9ecff1a6a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Robert=20J=C3=B6rdens?= Date: Mon, 14 Aug 2023 16:39:15 +0200 Subject: [PATCH 02/17] use tree attr without parentheses --- Cargo.lock | 4 ++-- src/bin/dual-iir.rs | 2 +- src/bin/lockin.rs | 4 ++-- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 89973b38e..3173a7e6d 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -416,7 +416,7 @@ dependencies = [ [[package]] name = "miniconf" version = "0.8.0" -source = "git+https://github.com/quartiq/miniconf.git?branch=trait-split#61d4d09c88c7fab852b527960889ceb4d8975960" +source = "git+https://github.com/quartiq/miniconf.git?branch=trait-split#28b8c4cf7380d2172dc538f14b439076408b6a2a" dependencies = [ "heapless", "itoa", @@ -431,7 +431,7 @@ dependencies = [ [[package]] name = "miniconf_derive" version = "0.8.0" -source = "git+https://github.com/quartiq/miniconf.git?branch=trait-split#61d4d09c88c7fab852b527960889ceb4d8975960" +source = "git+https://github.com/quartiq/miniconf.git?branch=trait-split#28b8c4cf7380d2172dc538f14b439076408b6a2a" dependencies = [ "proc-macro2", "quote", diff --git a/src/bin/dual-iir.rs b/src/bin/dual-iir.rs index 0b3fd1a5e..a2585e82e 100644 --- a/src/bin/dual-iir.rs +++ b/src/bin/dual-iir.rs @@ -82,7 +82,7 @@ pub struct Settings { /// /// # Value /// Any of the variants of [Gain] enclosed in double quotes. - #[tree()] + #[tree] afe: [Gain; 2], /// Configure the IIR filter parameters. diff --git a/src/bin/lockin.rs b/src/bin/lockin.rs index 86da4d4e6..3cd662b98 100644 --- a/src/bin/lockin.rs +++ b/src/bin/lockin.rs @@ -108,7 +108,7 @@ pub struct Settings { /// /// # Value /// Any of the variants of [Gain] enclosed in double quotes. - #[tree()] + #[tree] afe: [Gain; 2], /// Specifies the operational mode of the lockin. @@ -168,7 +168,7 @@ pub struct Settings { /// /// # Value /// One of the variants of [Conf] enclosed in double quotes. - #[tree()] + #[tree] output_conf: [Conf; 2], /// Specifies the telemetry output period in seconds. From 464ac4ea1d96d30a89c732ce43f16b9b98680e71 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Robert=20J=C3=B6rdens?= Date: Mon, 14 Aug 2023 17:53:04 +0200 Subject: [PATCH 03/17] use jsoncoreslash trait --- src/net/mod.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/net/mod.rs b/src/net/mod.rs index c06f0f3c6..77106ef86 100644 --- a/src/net/mod.rs +++ b/src/net/mod.rs @@ -21,7 +21,7 @@ use telemetry::TelemetryClient; use core::fmt::Write; use heapless::String; -use miniconf::{TreeDeserialize, TreeSerialize}; +use miniconf::JsonCoreSlash; use serde::Serialize; use smoltcp_nal::embedded_nal::SocketAddr; @@ -44,7 +44,7 @@ pub enum NetworkState { /// A structure of Stabilizer's default network users. pub struct NetworkUsers< - S: Default + TreeSerialize + TreeDeserialize + Clone, + S: Default + JsonCoreSlash + Clone, T: Serialize, const Y: usize, > { @@ -58,7 +58,7 @@ pub struct NetworkUsers< impl NetworkUsers where - S: Default + TreeSerialize + TreeDeserialize + Clone, + S: Default + JsonCoreSlash + Clone, T: Serialize, { /// Construct Stabilizer's default network users. From 5f37315fcbca2939dce99334457f2e4b8128db06 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Robert=20J=C3=B6rdens?= Date: Wed, 16 Aug 2023 16:07:42 +0200 Subject: [PATCH 04/17] update miniconf --- Cargo.lock | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 3173a7e6d..2e1cf755f 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -416,7 +416,7 @@ dependencies = [ [[package]] name = "miniconf" version = "0.8.0" -source = "git+https://github.com/quartiq/miniconf.git?branch=trait-split#28b8c4cf7380d2172dc538f14b439076408b6a2a" +source = "git+https://github.com/quartiq/miniconf.git?branch=trait-split#6b6854e6c8cb29d0a2a7ab4333543a4e46afcfd9" dependencies = [ "heapless", "itoa", @@ -431,7 +431,7 @@ dependencies = [ [[package]] name = "miniconf_derive" version = "0.8.0" -source = "git+https://github.com/quartiq/miniconf.git?branch=trait-split#28b8c4cf7380d2172dc538f14b439076408b6a2a" +source = "git+https://github.com/quartiq/miniconf.git?branch=trait-split#6b6854e6c8cb29d0a2a7ab4333543a4e46afcfd9" dependencies = [ "proc-macro2", "quote", From a6766d0bc99dbf8dcdb5f9db7b650e7b85264b48 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Robert=20J=C3=B6rdens?= Date: Mon, 21 Aug 2023 11:18:59 +0200 Subject: [PATCH 05/17] add list test to hitl --- hitl/run.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/hitl/run.sh b/hitl/run.sh index da8e7208f..87f686080 100755 --- a/hitl/run.sh +++ b/hitl/run.sh @@ -32,6 +32,7 @@ sleep 30 ping -c 5 -w 20 stabilizer-hitl # Test the MQTT interface. This uses the default broker "mqtt" +python3 -m miniconf $PREFIX --list python3 -m miniconf $PREFIX afe/0='"G2"' python3 -m stabilizer.iir_coefficients -p $PREFIX -c 0 -v pid --Ki 10 --Kp 1 From 964834c83f9063b8b9a9e3cf115d6997615e1258 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Robert=20J=C3=B6rdens?= Date: Mon, 21 Aug 2023 11:26:27 +0200 Subject: [PATCH 06/17] py: bump miniconf, fix path start, use current api names --- Cargo.toml | 3 ++- hitl/loopback.py | 20 ++++++++++---------- hitl/run.sh | 2 +- hitl/streaming.py | 8 ++++---- py/setup.py | 3 ++- py/stabilizer/iir_coefficients.py | 2 +- 6 files changed, 20 insertions(+), 18 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index c6e34dca8..755d1ac76 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -60,7 +60,8 @@ enum-iterator = "1.4.1" rand_xorshift = "0.3.0" rand_core = "0.6.4" minimq = "0.7" -miniconf = { git = "https://github.com/quartiq/miniconf.git", branch = "trait-split"} # "0.8" +# Keep this synced with the miniconf version in py/setup.py +miniconf = { git = "https://github.com/quartiq/miniconf.git" } # "0.9" smoltcp-nal = { version = "0.4", features = ["shared-stack"]} [dependencies.stm32h7xx-hal] diff --git a/hitl/loopback.py b/hitl/loopback.py index f2c6f08de..cb573982f 100644 --- a/hitl/loopback.py +++ b/hitl/loopback.py @@ -53,11 +53,11 @@ async def test_loopback(miniconf, telemetry_queue, set_point, gain=1, channel=0) print(f'Testing loopback for Vout = {set_point:.2f}, Gain = x{gain}') print('---------------------------------') # Configure the AFE and IIRs to output at the set point - await miniconf.command(f'afe/{channel}', f'G{gain}', retain=False) - await miniconf.command(f'iir_ch/{channel}/0', static_iir_output(set_point), retain=False) + await miniconf.set(f'/afe/{channel}', f'G{gain}', retain=False) + await miniconf.set(f'/iir_ch/{channel}/0', static_iir_output(set_point), retain=False) # Configure signal generators to not affect the test. - await miniconf.command('signal_generator/0/amplitude', 0, retain=False) + await miniconf.set('/signal_generator/0/amplitude', 0, retain=False) # Wait for telemetry to update. await asyncio.sleep(5.0) @@ -86,21 +86,21 @@ async def test(): """ The actual testing being completed. """ tele = await Telemetry.create(args.prefix, args.broker) - interface = await Miniconf.create(args.prefix, args.broker) + miniconf = await Miniconf.create(args.prefix, args.broker) # Disable IIR holds and configure the telemetry rate. - await interface.command('allow_hold', False, retain=False) - await interface.command('force_hold', False, retain=False) - await interface.command('telemetry_period', 1, retain=False) + await miniconf.set('allow_hold', False, retain=False) + await miniconf.set('force_hold', False, retain=False) + await miniconf.set('telemetry_period', 1, retain=False) # Test loopback with a static 1V output of the DACs. - await test_loopback(interface, tele.queue, 1.0) + await test_loopback(miniconf, tele.queue, 1.0) # Repeat test with AFE = 2x - await test_loopback(interface, tele.queue, 1.0, gain=2) + await test_loopback(miniconf, tele.queue, 1.0, gain=2) # Test with 0V output - await test_loopback(interface, tele.queue, 0.0) + await test_loopback(miniconf, tele.queue, 0.0) sys.exit(asyncio.run(test())) diff --git a/hitl/run.sh b/hitl/run.sh index 87f686080..1f17896c0 100755 --- a/hitl/run.sh +++ b/hitl/run.sh @@ -33,7 +33,7 @@ ping -c 5 -w 20 stabilizer-hitl # Test the MQTT interface. This uses the default broker "mqtt" python3 -m miniconf $PREFIX --list -python3 -m miniconf $PREFIX afe/0='"G2"' +python3 -m miniconf $PREFIX /afe/0='"G2"' python3 -m stabilizer.iir_coefficients -p $PREFIX -c 0 -v pid --Ki 10 --Kp 1 # Test the ADC/DACs connected via loopback. diff --git a/hitl/streaming.py b/hitl/streaming.py index 604f9a5b3..ea63fb2d2 100644 --- a/hitl/streaming.py +++ b/hitl/streaming.py @@ -33,8 +33,8 @@ async def _main(): local_ip = get_local_ip(args.broker) logger.info("Starting stream") - await conf.command( - "stream_target", {"ip": local_ip, "port": args.port}, retain=False) + await conf.set( + "/stream_target", {"ip": local_ip, "port": args.port}, retain=False) try: logger.info("Testing stream reception") @@ -44,8 +44,8 @@ async def _main(): raise RuntimeError("High frame loss", loss) finally: logger.info("Stopping stream") - await conf.command( - "stream_target", {"ip": [0, 0, 0, 0], "port": 0}, retain=False) + await conf.set( + "/stream_target", {"ip": [0, 0, 0, 0], "port": 0}, retain=False) logger.info("Draining queue") await asyncio.sleep(.1) diff --git a/py/setup.py b/py/setup.py index 64bbdad61..308f7b39f 100644 --- a/py/setup.py +++ b/py/setup.py @@ -14,6 +14,7 @@ "scipy", "matplotlib", "gmqtt", - "miniconf-mqtt@git+https://github.com/quartiq/miniconf@v0.7.0#subdirectory=py/miniconf-mqtt", + # Keep this synced with the miniconf version in Cargo.toml + "miniconf-mqtt@git+https://github.com/quartiq/miniconf@master#subdirectory=py/miniconf-mqtt", ], ) diff --git a/py/stabilizer/iir_coefficients.py b/py/stabilizer/iir_coefficients.py index a665cf35f..7f1c8bc8a 100644 --- a/py/stabilizer/iir_coefficients.py +++ b/py/stabilizer/iir_coefficients.py @@ -298,7 +298,7 @@ async def configure(): # Set the filter coefficients. # Note: In the future, we will need to Handle higher-order cascades. - await interface.command(f"iir_ch/{args.channel}/0", { + await interface.set(f"/iir_ch/{args.channel}/0", { "ba": coefficients, "y_min": stabilizer.voltage_to_machine_units(args.y_min), "y_max": stabilizer.voltage_to_machine_units(args.y_max), From ece95655b4a14d4d60fd5621815e68bb8961d201 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Robert=20J=C3=B6rdens?= Date: Tue, 22 Aug 2023 12:00:12 +0200 Subject: [PATCH 07/17] bump miniconf --- Cargo.lock | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 2e1cf755f..ff2c03005 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -416,7 +416,7 @@ dependencies = [ [[package]] name = "miniconf" version = "0.8.0" -source = "git+https://github.com/quartiq/miniconf.git?branch=trait-split#6b6854e6c8cb29d0a2a7ab4333543a4e46afcfd9" +source = "git+https://github.com/quartiq/miniconf.git#16ddbbc5f469ba226428c1e1440270762f24f424" dependencies = [ "heapless", "itoa", @@ -431,7 +431,7 @@ dependencies = [ [[package]] name = "miniconf_derive" version = "0.8.0" -source = "git+https://github.com/quartiq/miniconf.git?branch=trait-split#6b6854e6c8cb29d0a2a7ab4333543a4e46afcfd9" +source = "git+https://github.com/quartiq/miniconf.git#16ddbbc5f469ba226428c1e1440270762f24f424" dependencies = [ "proc-macro2", "quote", From bc6d9d3c5f15da793d02269ed35dab1730f1b5ec Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Robert=20J=C3=B6rdens?= Date: Tue, 22 Aug 2023 12:04:15 +0200 Subject: [PATCH 08/17] lifetime bounds --- src/net/mod.rs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/net/mod.rs b/src/net/mod.rs index 77106ef86..9ef95e57c 100644 --- a/src/net/mod.rs +++ b/src/net/mod.rs @@ -43,11 +43,11 @@ pub enum NetworkState { } /// A structure of Stabilizer's default network users. -pub struct NetworkUsers< - S: Default + JsonCoreSlash + Clone, +pub struct NetworkUsers +where + for<'de> S: Default + JsonCoreSlash<'de, Y> + Clone, T: Serialize, - const Y: usize, -> { +{ pub miniconf: miniconf::MqttClient, pub processor: NetworkProcessor, @@ -58,7 +58,7 @@ pub struct NetworkUsers< impl NetworkUsers where - S: Default + JsonCoreSlash + Clone, + for<'de> S: Default + JsonCoreSlash<'de, Y> + Clone, T: Serialize, { /// Construct Stabilizer's default network users. From b76e0ecff0a6b07b7adb198d284d6404cab7e03f Mon Sep 17 00:00:00 2001 From: Ryan Summers Date: Tue, 22 Aug 2023 14:30:58 +0200 Subject: [PATCH 09/17] Updating to use DNS in smoltcp --- Cargo.lock | 6 ++---- Cargo.toml | 8 ++++++++ src/hardware/setup.rs | 11 ++++++++--- 3 files changed, 18 insertions(+), 7 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index ba9f831b1..b8b6825a0 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -443,8 +443,7 @@ dependencies = [ [[package]] name = "minimq" version = "0.7.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0106439fe4eb2e88c5b6b8fcb505b2f679bd8e105c947aa1f1a77f6b57a38653" +source = "git+https://github.com/quartiq/minimq?branch=feature/dns-brokers#93aa7cc2f29ca7d1239ffa7716055a333fad7c75" dependencies = [ "bit_field", "embedded-nal", @@ -861,8 +860,7 @@ dependencies = [ [[package]] name = "smoltcp-nal" version = "0.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "75077a28569d93c2eed77164fd36dd224a9efcf6ecf0e574f293ed638783b000" +source = "git+https://github.com/quartiq/smoltcp-nal?branch=feature/dns-support#ef39367621826ed4a32257b174ced5bdcb4a12e6" dependencies = [ "embedded-nal", "embedded-time", diff --git a/Cargo.toml b/Cargo.toml index ae2a343a7..8333ff1be 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -67,6 +67,14 @@ smoltcp-nal = { version = "0.4", features = ["shared-stack"]} git = "https://github.com/stm32-rs/stm32h7xx-hal" features = ["stm32h743v", "rt", "ethernet", "xspi"] +[patch.crates-io.smoltcp-nal] +git = "https://github.com/quartiq/smoltcp-nal" +branch = "feature/dns-support" + +[patch.crates-io.minimq] +git = "https://github.com/quartiq/minimq" +branch = "feature/dns-brokers" + [features] nightly = [ ] pounder_v1_0 = [ ] diff --git a/src/hardware/setup.rs b/src/hardware/setup.rs index cd26f7424..8880917a2 100644 --- a/src/hardware/setup.rs +++ b/src/hardware/setup.rs @@ -28,10 +28,12 @@ const NUM_SOCKETS: usize = NUM_UDP_SOCKETS + NUM_TCP_SOCKETS; pub struct NetStorage { pub ip_addrs: [smoltcp::wire::IpCidr; 1], - // Note: There is an additional socket set item required for the DHCP socket. - pub sockets: [smoltcp::iface::SocketStorage<'static>; NUM_SOCKETS + 1], + // Note: There is an additional socket set item required for the DHCP and DNS sockets + // respectively. + pub sockets: [smoltcp::iface::SocketStorage<'static>; NUM_SOCKETS + 2], pub tcp_socket_storage: [TcpSocketStorage; NUM_TCP_SOCKETS], pub udp_socket_storage: [UdpSocketStorage; NUM_UDP_SOCKETS], + pub dns_storage: [Option; 1], } #[derive(Copy, Clone)] @@ -79,9 +81,10 @@ impl Default for NetStorage { ip_addrs: [smoltcp::wire::IpCidr::Ipv6( smoltcp::wire::Ipv6Cidr::SOLICITED_NODE_PREFIX, )], - sockets: [smoltcp::iface::SocketStorage::EMPTY; NUM_SOCKETS + 1], + sockets: [smoltcp::iface::SocketStorage::EMPTY; NUM_SOCKETS + 2], tcp_socket_storage: [TcpSocketStorage::new(); NUM_TCP_SOCKETS], udp_socket_storage: [UdpSocketStorage::new(); NUM_UDP_SOCKETS], + dns_storage: [None; 1], } } } @@ -696,6 +699,8 @@ pub fn setup( sockets.add(smoltcp::socket::dhcpv4::Socket::new()); } + sockets.add(smoltcp::socket::dns::Socket::new(&[], &mut store.dns_storage)); + for storage in store.udp_socket_storage[..].iter_mut() { let udp_socket = { let rx_buffer = smoltcp::socket::udp::PacketBuffer::new( From 4faa9c2d1fb7468f6aedc2e39aa3fe7e8e245387 Mon Sep 17 00:00:00 2001 From: Ryan Summers Date: Tue, 22 Aug 2023 14:32:28 +0200 Subject: [PATCH 10/17] Updating minimq to use buffers --- Cargo.lock | 19 +++++++++++++++++-- Cargo.toml | 2 +- src/net/mod.rs | 35 ++++++++++++++++++++++++++++++----- src/net/telemetry.rs | 15 +++------------ 4 files changed, 51 insertions(+), 20 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 49ce99a71..666f8751f 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -414,7 +414,7 @@ dependencies = [ "itoa", "log", "miniconf_derive", - "minimq", + "minimq 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)", "serde", "serde-json-core", "smlang", @@ -447,6 +447,21 @@ dependencies = [ "varint-rs", ] +[[package]] +name = "minimq" +version = "0.7.0" +source = "git+https://github.com/quartiq/minimq#8e7e2b8c6faf72b87a630b0c2a0571a8d117f187" +dependencies = [ + "bit_field", + "embedded-nal", + "embedded-time", + "heapless", + "num_enum 0.5.11", + "serde", + "smlang", + "varint-rs", +] + [[package]] name = "mono-clock" version = "0.1.1" @@ -877,7 +892,7 @@ dependencies = [ "log", "mcp230xx", "miniconf", - "minimq", + "minimq 0.7.0 (git+https://github.com/quartiq/minimq)", "mono-clock", "mutex-trait", "num_enum 0.6.1", diff --git a/Cargo.toml b/Cargo.toml index a0e02db23..e4b30558e 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -59,7 +59,7 @@ lm75 = "0.2" enum-iterator = "1.4.1" rand_xorshift = "0.3.0" rand_core = "0.6.4" -minimq = "0.7" +minimq = {git = "https://github.com/quartiq/minimq"} miniconf = "0.8" smoltcp-nal = { version = "0.4", features = ["shared-stack"]} diff --git a/src/net/mod.rs b/src/net/mod.rs index 14d139613..f122bdfee 100644 --- a/src/net/mod.rs +++ b/src/net/mod.rs @@ -31,6 +31,22 @@ pub type NetworkReference = /// The default MQTT broker IP address if unspecified. pub const DEFAULT_MQTT_BROKER: [u8; 4] = [10, 34, 16, 10]; +pub struct MqttStorage { + rx_storage: [u8; 1024], + tx_storage: [u8; 1024], + session_state: [u8; 1024], +} + +impl Default for MqttStorage { + fn default() -> Self { + Self { + rx_storage: [0u8; 1024], + tx_storage: [0u8; 1024], + session_state: [0u8; 1024], + } + } +} + pub enum UpdateState { NoChange, Updated, @@ -100,13 +116,22 @@ where ) .unwrap(); - let telemetry = TelemetryClient::new( + let store = + cortex_m::singleton!(: MqttStorage = MqttStorage::default()) + .unwrap(); + + let mqtt = minimq::Minimq::new( + broker, + &get_client_id(app, "tlm", mac), stack_manager.acquire_stack(), clock, - &get_client_id(app, "tlm", mac), - &prefix, - broker, - ); + &mut store.rx_storage, + &mut store.tx_storage, + &mut store.session_state, + ) + .unwrap(); + + let telemetry = TelemetryClient::new(mqtt, &prefix); let (generator, stream) = data_stream::setup_streaming(stack_manager.acquire_stack()); diff --git a/src/net/telemetry.rs b/src/net/telemetry.rs index 13293c8f1..4bd9eb59c 100644 --- a/src/net/telemetry.rs +++ b/src/net/telemetry.rs @@ -19,7 +19,7 @@ use minimq::embedded_nal::IpAddr; /// The telemetry client for reporting telemetry data over MQTT. pub struct TelemetryClient { - mqtt: minimq::Minimq, + mqtt: minimq::Minimq<'static, NetworkReference, SystemTimer>, telemetry_topic: String<128>, _telemetry: core::marker::PhantomData, } @@ -97,24 +97,15 @@ impl TelemetryClient { /// Construct a new telemetry client. /// /// # Args - /// * `stack` - A reference to the (shared) underlying network stack. - /// * `clock` - A `SystemTimer` implementing `Clock`. - /// * `client_id` - The MQTT client ID of the telemetry client. + /// * `mqtt` - The MQTT client /// * `prefix` - The device prefix to use for MQTT telemetry reporting. - /// * `broker` - The IP address of the MQTT broker to use. /// /// # Returns /// A new telemetry client. pub fn new( - stack: NetworkReference, - clock: SystemTimer, - client_id: &str, + mqtt: minimq::Minimq<'static, NetworkReference, SystemTimer>, prefix: &str, - broker: IpAddr, ) -> Self { - let mqtt = - minimq::Minimq::new(broker, client_id, stack, clock).unwrap(); - let mut telemetry_topic: String<128> = String::from(prefix); telemetry_topic.push_str("/telemetry").unwrap(); From cd3a9157ebbb091726af39d330305df14bcdf9bf Mon Sep 17 00:00:00 2001 From: Ryan Summers Date: Tue, 22 Aug 2023 14:45:05 +0200 Subject: [PATCH 11/17] Adding WIP updates --- Cargo.lock | 9 +++++---- Cargo.toml | 6 +----- src/hardware/setup.rs | 2 +- src/net/mod.rs | 4 ++-- src/net/telemetry.rs | 5 ++--- 5 files changed, 11 insertions(+), 15 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 71b3c393d..7513fd404 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -443,7 +443,8 @@ dependencies = [ [[package]] name = "minimq" version = "0.7.0" -source = "git+https://github.com/quartiq/minimq?branch=feature/dns-brokers#93aa7cc2f29ca7d1239ffa7716055a333fad7c75" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0106439fe4eb2e88c5b6b8fcb505b2f679bd8e105c947aa1f1a77f6b57a38653" dependencies = [ "bit_field", "embedded-nal", @@ -458,7 +459,7 @@ dependencies = [ [[package]] name = "minimq" version = "0.7.0" -source = "git+https://github.com/quartiq/minimq#8e7e2b8c6faf72b87a630b0c2a0571a8d117f187" +source = "git+https://github.com/quartiq/minimq?branch=feature/dns-brokers#93aa7cc2f29ca7d1239ffa7716055a333fad7c75" dependencies = [ "bit_field", "embedded-nal", @@ -875,7 +876,7 @@ dependencies = [ [[package]] name = "smoltcp-nal" version = "0.4.0" -source = "git+https://github.com/quartiq/smoltcp-nal?branch=feature/dns-support#ef39367621826ed4a32257b174ced5bdcb4a12e6" +source = "git+https://github.com/quartiq/smoltcp-nal?branch=feature/dns-support#8092b7b7757474bf66e9dcb0fd6168a06ab8d1a7" dependencies = [ "embedded-nal", "embedded-time", @@ -911,7 +912,7 @@ dependencies = [ "log", "mcp230xx", "miniconf", - "minimq 0.7.0 (git+https://github.com/quartiq/minimq)", + "minimq 0.7.0 (git+https://github.com/quartiq/minimq?branch=feature/dns-brokers)", "mono-clock", "mutex-trait", "num_enum 0.7.0", diff --git a/Cargo.toml b/Cargo.toml index 9c60d2ff5..fa7e12068 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -59,7 +59,7 @@ lm75 = "0.2" enum-iterator = "1.4.1" rand_xorshift = "0.3.0" rand_core = "0.6.4" -minimq = {git = "https://github.com/quartiq/minimq"} +minimq = {git = "https://github.com/quartiq/minimq", branch = "feature/dns-brokers"} miniconf = "0.8" smoltcp-nal = { version = "0.4", features = ["shared-stack"]} @@ -71,10 +71,6 @@ features = ["stm32h743v", "rt", "ethernet", "xspi"] git = "https://github.com/quartiq/smoltcp-nal" branch = "feature/dns-support" -[patch.crates-io.minimq] -git = "https://github.com/quartiq/minimq" -branch = "feature/dns-brokers" - [features] nightly = [ ] pounder_v1_0 = [ ] diff --git a/src/hardware/setup.rs b/src/hardware/setup.rs index 8880917a2..7719df337 100644 --- a/src/hardware/setup.rs +++ b/src/hardware/setup.rs @@ -699,7 +699,7 @@ pub fn setup( sockets.add(smoltcp::socket::dhcpv4::Socket::new()); } - sockets.add(smoltcp::socket::dns::Socket::new(&[], &mut store.dns_storage)); + sockets.add(smoltcp::socket::dns::Socket::new(&[], &mut store.dns_storage[..])); for storage in store.udp_socket_storage[..].iter_mut() { let udp_socket = { diff --git a/src/net/mod.rs b/src/net/mod.rs index ba08f601d..69551d273 100644 --- a/src/net/mod.rs +++ b/src/net/mod.rs @@ -110,7 +110,7 @@ where stack_manager.acquire_stack(), &get_client_id(app, "settings", mac), &prefix, - broker, + "10.35.20.1".parse().unwrap(), clock, S::default(), ) @@ -121,7 +121,7 @@ where .unwrap(); let mqtt = minimq::Minimq::new( - broker, + minimq::broker::NamedBroker::new("mqtt", stack_manager.acquire_stack()), &get_client_id(app, "tlm", mac), stack_manager.acquire_stack(), clock, diff --git a/src/net/telemetry.rs b/src/net/telemetry.rs index 4bd9eb59c..11a5cad6c 100644 --- a/src/net/telemetry.rs +++ b/src/net/telemetry.rs @@ -15,11 +15,10 @@ use serde::Serialize; use super::NetworkReference; use crate::hardware::{adc::AdcCode, afe::Gain, dac::DacCode, SystemTimer}; -use minimq::embedded_nal::IpAddr; /// The telemetry client for reporting telemetry data over MQTT. pub struct TelemetryClient { - mqtt: minimq::Minimq<'static, NetworkReference, SystemTimer>, + mqtt: minimq::Minimq<'static, NetworkReference, SystemTimer, minimq::broker::NamedBroker>, telemetry_topic: String<128>, _telemetry: core::marker::PhantomData, } @@ -103,7 +102,7 @@ impl TelemetryClient { /// # Returns /// A new telemetry client. pub fn new( - mqtt: minimq::Minimq<'static, NetworkReference, SystemTimer>, + mqtt: minimq::Minimq<'static, NetworkReference, SystemTimer, minimq::broker::NamedBroker>, prefix: &str, ) -> Self { let mut telemetry_topic: String<128> = String::from(prefix); From 7372c2a0481f72f6e81658412df0bd0240523fd2 Mon Sep 17 00:00:00 2001 From: Ryan Summers Date: Thu, 31 Aug 2023 15:21:54 +0200 Subject: [PATCH 12/17] Updating miniconf and mqtt telemetry to use deferred publication --- Cargo.lock | 20 +++++++------- Cargo.toml | 10 +++---- src/bin/dual-iir.rs | 16 +++++------- src/bin/lockin.rs | 12 +++------ src/hardware/signal_generator.rs | 5 ++-- src/net/mod.rs | 45 ++++++++++++++------------------ src/net/telemetry.rs | 2 +- 7 files changed, 44 insertions(+), 66 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 7513fd404..89269f62d 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -416,14 +416,13 @@ dependencies = [ [[package]] name = "miniconf" version = "0.8.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9e34fb3249ad071debda2ceb8d29e271d0fd283039f7bf04d9d7921dec4e6b4e" +source = "git+https://github.com/quartiq/miniconf?branch=feature/minimq-update#e0d4d4b4c38fdd1c79cbfc2044e3800dd16c53ce" dependencies = [ "heapless", "itoa", "log", "miniconf_derive", - "minimq 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)", + "minimq 0.7.0 (git+https://github.com/quartiq/minimq)", "serde", "serde-json-core", "smlang", @@ -432,8 +431,7 @@ dependencies = [ [[package]] name = "miniconf_derive" version = "0.8.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c2327f540b14c86184b066abe25daca988c15c60f0d9a215d2a37f3032805d47" +source = "git+https://github.com/quartiq/miniconf?branch=feature/minimq-update#e0d4d4b4c38fdd1c79cbfc2044e3800dd16c53ce" dependencies = [ "proc-macro2", "quote", @@ -443,8 +441,7 @@ dependencies = [ [[package]] name = "minimq" version = "0.7.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0106439fe4eb2e88c5b6b8fcb505b2f679bd8e105c947aa1f1a77f6b57a38653" +source = "git+https://github.com/quartiq/minimq?branch=master#2b466aa1bd7377d59ba58f76172bdd3422d5570c" dependencies = [ "bit_field", "embedded-nal", @@ -459,7 +456,7 @@ dependencies = [ [[package]] name = "minimq" version = "0.7.0" -source = "git+https://github.com/quartiq/minimq?branch=feature/dns-brokers#93aa7cc2f29ca7d1239ffa7716055a333fad7c75" +source = "git+https://github.com/quartiq/minimq#2b466aa1bd7377d59ba58f76172bdd3422d5570c" dependencies = [ "bit_field", "embedded-nal", @@ -875,8 +872,9 @@ dependencies = [ [[package]] name = "smoltcp-nal" -version = "0.4.0" -source = "git+https://github.com/quartiq/smoltcp-nal?branch=feature/dns-support#8092b7b7757474bf66e9dcb0fd6168a06ab8d1a7" +version = "0.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6dd2ed2f8e7643a170506863ed0f52ad1dc5762abdcff27de825dde14fc8025f" dependencies = [ "embedded-nal", "embedded-time", @@ -912,7 +910,7 @@ dependencies = [ "log", "mcp230xx", "miniconf", - "minimq 0.7.0 (git+https://github.com/quartiq/minimq?branch=feature/dns-brokers)", + "minimq 0.7.0 (git+https://github.com/quartiq/minimq?branch=master)", "mono-clock", "mutex-trait", "num_enum 0.7.0", diff --git a/Cargo.toml b/Cargo.toml index fa7e12068..dbf0164b6 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -59,18 +59,14 @@ lm75 = "0.2" enum-iterator = "1.4.1" rand_xorshift = "0.3.0" rand_core = "0.6.4" -minimq = {git = "https://github.com/quartiq/minimq", branch = "feature/dns-brokers"} -miniconf = "0.8" -smoltcp-nal = { version = "0.4", features = ["shared-stack"]} +minimq = {git = "https://github.com/quartiq/minimq", branch = "master"} +miniconf = {git="https://github.com/quartiq/miniconf", branch = "feature/minimq-update"} +smoltcp-nal = { version = "0.4.1", features = ["shared-stack"]} [dependencies.stm32h7xx-hal] git = "https://github.com/stm32-rs/stm32h7xx-hal" features = ["stm32h743v", "rt", "ethernet", "xspi"] -[patch.crates-io.smoltcp-nal] -git = "https://github.com/quartiq/smoltcp-nal" -branch = "feature/dns-support" - [features] nightly = [ ] pounder_v1_0 = [ ] diff --git a/src/bin/dual-iir.rs b/src/bin/dual-iir.rs index 2de314530..9287edc2c 100644 --- a/src/bin/dual-iir.rs +++ b/src/bin/dual-iir.rs @@ -50,7 +50,7 @@ use stabilizer::{ }, net::{ data_stream::{FrameGenerator, StreamFormat, StreamTarget}, - miniconf::Miniconf, + miniconf::Tree, telemetry::{Telemetry, TelemetryBuffer}, NetworkState, NetworkUsers, }, @@ -71,7 +71,7 @@ const SAMPLE_TICKS: u32 = 1 << SAMPLE_TICKS_LOG2; const SAMPLE_PERIOD: f32 = SAMPLE_TICKS as f32 * hardware::design_parameters::TIMER_PERIOD; -#[derive(Clone, Copy, Debug, Miniconf)] +#[derive(Clone, Copy, Debug, Tree)] pub struct Settings { /// Configure the Analog Front End (AFE) gain. /// @@ -82,7 +82,7 @@ pub struct Settings { /// /// # Value /// Any of the variants of [Gain] enclosed in double quotes. - #[miniconf(defer)] + #[tree] afe: [Gain; 2], /// Configure the IIR filter parameters. @@ -95,7 +95,7 @@ pub struct Settings { /// /// # Value /// See [iir::IIR#miniconf] - #[miniconf(defer(2))] + #[tree] iir_ch: [[iir::IIR; IIR_CASCADE_LENGTH]; 2], /// Specified true if DI1 should be used as a "hold" input. @@ -143,7 +143,7 @@ pub struct Settings { /// /// # Value /// See [signal_generator::BasicConfig#miniconf] - #[miniconf(defer(2))] + #[tree] signal_generator: [signal_generator::BasicConfig; 2], } @@ -182,7 +182,7 @@ mod app { #[shared] struct Shared { - network: NetworkUsers, + network: NetworkUsers, settings: Settings, telemetry: TelemetryBuffer, @@ -220,10 +220,6 @@ mod app { clock, env!("CARGO_BIN_NAME"), stabilizer.net.mac_address, - option_env!("BROKER") - .unwrap_or("10.34.16.1") - .parse() - .unwrap(), ); let generator = network.configure_streaming(StreamFormat::AdcDacData); diff --git a/src/bin/lockin.rs b/src/bin/lockin.rs index 342765907..9329a886a 100644 --- a/src/bin/lockin.rs +++ b/src/bin/lockin.rs @@ -53,7 +53,7 @@ use stabilizer::{ }, net::{ data_stream::{FrameGenerator, StreamFormat, StreamTarget}, - miniconf::Miniconf, + miniconf::Tree, serde::{Deserialize, Serialize}, telemetry::{Telemetry, TelemetryBuffer}, NetworkState, NetworkUsers, @@ -97,7 +97,7 @@ enum LockinMode { External, } -#[derive(Copy, Clone, Debug, Miniconf)] +#[derive(Copy, Clone, Debug, Tree)] pub struct Settings { /// Configure the Analog Front End (AFE) gain. /// @@ -108,7 +108,7 @@ pub struct Settings { /// /// # Value /// Any of the variants of [Gain] enclosed in double quotes. - #[miniconf(defer)] + #[tree] afe: [Gain; 2], /// Specifies the operational mode of the lockin. @@ -168,7 +168,7 @@ pub struct Settings { /// /// # Value /// One of the variants of [Conf] enclosed in double quotes. - #[miniconf(defer)] + #[tree] output_conf: [Conf; 2], /// Specifies the telemetry output period in seconds. @@ -260,10 +260,6 @@ mod app { clock, env!("CARGO_BIN_NAME"), stabilizer.net.mac_address, - option_env!("BROKER") - .unwrap_or("10.34.16.1") - .parse() - .unwrap(), ); let generator = network.configure_streaming(StreamFormat::AdcDacData); diff --git a/src/hardware/signal_generator.rs b/src/hardware/signal_generator.rs index d4d55efb0..f14f7aa78 100644 --- a/src/hardware/signal_generator.rs +++ b/src/hardware/signal_generator.rs @@ -1,4 +1,3 @@ -use miniconf::Miniconf; use rand_core::{RngCore, SeedableRng}; use rand_xorshift::XorShiftRng; use serde::{Deserialize, Serialize}; @@ -14,13 +13,13 @@ pub enum Signal { /// Basic configuration for a generated signal. /// -/// # Miniconf +/// # Miniconf Tree /// `{"signal": , "frequency", 1000.0, "symmetry": 0.5, "amplitude": 1.0}` /// /// Where `` may be any of [Signal] variants, `frequency` specifies the signal frequency /// in Hertz, `symmetry` specifies the normalized signal symmetry which ranges from 0 - 1.0, and /// `amplitude` specifies the signal amplitude in Volts. -#[derive(Copy, Clone, Debug, Miniconf)] +#[derive(Copy, Clone, Debug, Deserialize, Serialize)] pub struct BasicConfig { /// The signal type that should be generated. See [Signal] variants. pub signal: Signal, diff --git a/src/net/mod.rs b/src/net/mod.rs index 69551d273..b6ae2bc18 100644 --- a/src/net/mod.rs +++ b/src/net/mod.rs @@ -15,13 +15,12 @@ pub mod telemetry; use crate::hardware::{EthernetPhy, NetworkManager, NetworkStack, SystemTimer}; use data_stream::{DataStream, FrameGenerator}; -use minimq::embedded_nal::IpAddr; use network_processor::NetworkProcessor; use telemetry::TelemetryClient; use core::fmt::Write; use heapless::String; -use miniconf::Miniconf; +use miniconf::TreeKey; use serde::Serialize; use smoltcp_nal::embedded_nal::SocketAddr; @@ -32,17 +31,15 @@ pub type NetworkReference = pub const DEFAULT_MQTT_BROKER: [u8; 4] = [10, 34, 16, 10]; pub struct MqttStorage { - rx_storage: [u8; 1024], - tx_storage: [u8; 1024], - session_state: [u8; 1024], + telemetry: [u8; 1024], + settings: [u8; 1024], } impl Default for MqttStorage { fn default() -> Self { Self { - rx_storage: [0u8; 1024], - tx_storage: [0u8; 1024], - session_state: [0u8; 1024], + telemetry: [0u8; 1024], + settings: [0u8; 1024], } } } @@ -60,12 +57,12 @@ pub enum NetworkState { /// A structure of Stabilizer's default network users. pub struct NetworkUsers< - S: Default + Miniconf + Clone, + S: Default + TreeKey + Clone, T: Serialize, const Y: usize, > { pub miniconf: - miniconf::MqttClient, + miniconf::MqttClient<'static, S, NetworkReference, SystemTimer, miniconf::minimq::broker::NamedBroker, Y>, pub processor: NetworkProcessor, stream: DataStream, generator: Option, @@ -74,7 +71,7 @@ pub struct NetworkUsers< impl NetworkUsers where - S: Default + Miniconf + Clone, + for<'de> S: Default + miniconf::JsonCoreSlash<'de, Y> + Clone, T: Serialize, { /// Construct Stabilizer's default network users. @@ -85,7 +82,6 @@ where /// * `clock` - A `SystemTimer` implementing `Clock`. /// * `app` - The name of the application. /// * `mac` - The MAC address of the network. - /// * `broker` - The IP address of the MQTT broker to use. /// /// # Returns /// A new struct of network users. @@ -95,7 +91,6 @@ where clock: SystemTimer, app: &str, mac: smoltcp_nal::smoltcp::wire::EthernetAddress, - broker: IpAddr, ) -> Self { let stack_manager = cortex_m::singleton!(: NetworkManager = NetworkManager::new(stack)) @@ -106,30 +101,28 @@ where let prefix = get_device_prefix(app, mac); + let store = + cortex_m::singleton!(: MqttStorage = MqttStorage::default()) + .unwrap(); + + let broker_domain_name = option_env!("BROKER").unwrap_or("fake"); + let broker = miniconf::minimq::broker::NamedBroker::new(broker_domain_name, stack_manager.acquire_stack()).unwrap(); let settings = miniconf::MqttClient::new( stack_manager.acquire_stack(), - &get_client_id(app, "settings", mac), &prefix, - "10.35.20.1".parse().unwrap(), clock, S::default(), + miniconf::minimq::ConfigBuilder::new(broker, &mut store.settings) + .client_id(&get_client_id(app, "settings", mac)).unwrap() ) .unwrap(); - let store = - cortex_m::singleton!(: MqttStorage = MqttStorage::default()) - .unwrap(); - + let broker = minimq::broker::NamedBroker::new(broker_domain_name, stack_manager.acquire_stack()).unwrap(); let mqtt = minimq::Minimq::new( - minimq::broker::NamedBroker::new("mqtt", stack_manager.acquire_stack()), - &get_client_id(app, "tlm", mac), stack_manager.acquire_stack(), clock, - &mut store.rx_storage, - &mut store.tx_storage, - &mut store.session_state, - ) - .unwrap(); + minimq::ConfigBuilder::new(broker, &mut store.telemetry).client_id(&get_client_id(app, "tlm", mac)).unwrap() + ); let telemetry = TelemetryClient::new(mqtt, &prefix); diff --git a/src/net/telemetry.rs b/src/net/telemetry.rs index 11a5cad6c..b6316403e 100644 --- a/src/net/telemetry.rs +++ b/src/net/telemetry.rs @@ -129,7 +129,7 @@ impl TelemetryClient { self.mqtt .client() .publish( - minimq::Publication::new(&telemetry) + minimq::Publication::<&[u8]>::new(&telemetry) .topic(&self.telemetry_topic) .finish() .unwrap(), From 8edfb37597f2a3b2cacb71ebd025a7e24f78bcfc Mon Sep 17 00:00:00 2001 From: Ryan Summers Date: Tue, 5 Sep 2023 12:21:16 +0200 Subject: [PATCH 13/17] Refactoring after updates --- Cargo.lock | 25 ++++---------------- Cargo.toml | 4 ++-- src/bin/dual-iir.rs | 7 +++--- src/bin/lockin.rs | 1 + src/hardware/setup.rs | 5 +++- src/hardware/signal_generator.rs | 3 ++- src/net/mod.rs | 40 +++++++++++++++++++++++--------- src/net/telemetry.rs | 14 +++++++++-- 8 files changed, 59 insertions(+), 40 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 89269f62d..1f7cbf78d 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -416,13 +416,13 @@ dependencies = [ [[package]] name = "miniconf" version = "0.8.0" -source = "git+https://github.com/quartiq/miniconf?branch=feature/minimq-update#e0d4d4b4c38fdd1c79cbfc2044e3800dd16c53ce" +source = "git+https://github.com/quartiq/miniconf#61946c1a739abb79870fedcb096c5cd697eee361" dependencies = [ "heapless", "itoa", "log", "miniconf_derive", - "minimq 0.7.0 (git+https://github.com/quartiq/minimq)", + "minimq", "serde", "serde-json-core", "smlang", @@ -431,7 +431,7 @@ dependencies = [ [[package]] name = "miniconf_derive" version = "0.8.0" -source = "git+https://github.com/quartiq/miniconf?branch=feature/minimq-update#e0d4d4b4c38fdd1c79cbfc2044e3800dd16c53ce" +source = "git+https://github.com/quartiq/miniconf#61946c1a739abb79870fedcb096c5cd697eee361" dependencies = [ "proc-macro2", "quote", @@ -441,22 +441,7 @@ dependencies = [ [[package]] name = "minimq" version = "0.7.0" -source = "git+https://github.com/quartiq/minimq?branch=master#2b466aa1bd7377d59ba58f76172bdd3422d5570c" -dependencies = [ - "bit_field", - "embedded-nal", - "embedded-time", - "heapless", - "num_enum 0.5.11", - "serde", - "smlang", - "varint-rs", -] - -[[package]] -name = "minimq" -version = "0.7.0" -source = "git+https://github.com/quartiq/minimq#2b466aa1bd7377d59ba58f76172bdd3422d5570c" +source = "git+https://github.com/quartiq/minimq#f4cb420186fb6f294ffdaa612bb8401c3261fd63" dependencies = [ "bit_field", "embedded-nal", @@ -910,7 +895,7 @@ dependencies = [ "log", "mcp230xx", "miniconf", - "minimq 0.7.0 (git+https://github.com/quartiq/minimq?branch=master)", + "minimq", "mono-clock", "mutex-trait", "num_enum 0.7.0", diff --git a/Cargo.toml b/Cargo.toml index dbf0164b6..07cbf8e54 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -59,8 +59,8 @@ lm75 = "0.2" enum-iterator = "1.4.1" rand_xorshift = "0.3.0" rand_core = "0.6.4" -minimq = {git = "https://github.com/quartiq/minimq", branch = "master"} -miniconf = {git="https://github.com/quartiq/miniconf", branch = "feature/minimq-update"} +minimq = {git = "https://github.com/quartiq/minimq"} +miniconf = {git="https://github.com/quartiq/miniconf"} smoltcp-nal = { version = "0.4.1", features = ["shared-stack"]} [dependencies.stm32h7xx-hal] diff --git a/src/bin/dual-iir.rs b/src/bin/dual-iir.rs index 9287edc2c..1db097100 100644 --- a/src/bin/dual-iir.rs +++ b/src/bin/dual-iir.rs @@ -95,7 +95,7 @@ pub struct Settings { /// /// # Value /// See [iir::IIR#miniconf] - #[tree] + #[tree(depth(2))] iir_ch: [[iir::IIR; IIR_CASCADE_LENGTH]; 2], /// Specified true if DI1 should be used as a "hold" input. @@ -143,7 +143,7 @@ pub struct Settings { /// /// # Value /// See [signal_generator::BasicConfig#miniconf] - #[tree] + #[tree(depth(2))] signal_generator: [signal_generator::BasicConfig; 2], } @@ -182,7 +182,7 @@ mod app { #[shared] struct Shared { - network: NetworkUsers, + network: NetworkUsers, settings: Settings, telemetry: TelemetryBuffer, @@ -220,6 +220,7 @@ mod app { clock, env!("CARGO_BIN_NAME"), stabilizer.net.mac_address, + option_env!("BROKER").unwrap_or("10.34.16.10"), ); let generator = network.configure_streaming(StreamFormat::AdcDacData); diff --git a/src/bin/lockin.rs b/src/bin/lockin.rs index 9329a886a..c30fea38c 100644 --- a/src/bin/lockin.rs +++ b/src/bin/lockin.rs @@ -260,6 +260,7 @@ mod app { clock, env!("CARGO_BIN_NAME"), stabilizer.net.mac_address, + option_env!("BROKER").unwrap_or("10.34.16.10"), ); let generator = network.configure_streaming(StreamFormat::AdcDacData); diff --git a/src/hardware/setup.rs b/src/hardware/setup.rs index 7719df337..a8b52e7ad 100644 --- a/src/hardware/setup.rs +++ b/src/hardware/setup.rs @@ -699,7 +699,10 @@ pub fn setup( sockets.add(smoltcp::socket::dhcpv4::Socket::new()); } - sockets.add(smoltcp::socket::dns::Socket::new(&[], &mut store.dns_storage[..])); + sockets.add(smoltcp::socket::dns::Socket::new( + &[], + &mut store.dns_storage[..], + )); for storage in store.udp_socket_storage[..].iter_mut() { let udp_socket = { diff --git a/src/hardware/signal_generator.rs b/src/hardware/signal_generator.rs index f14f7aa78..3a8b4d259 100644 --- a/src/hardware/signal_generator.rs +++ b/src/hardware/signal_generator.rs @@ -1,3 +1,4 @@ +use miniconf::Tree; use rand_core::{RngCore, SeedableRng}; use rand_xorshift::XorShiftRng; use serde::{Deserialize, Serialize}; @@ -19,7 +20,7 @@ pub enum Signal { /// Where `` may be any of [Signal] variants, `frequency` specifies the signal frequency /// in Hertz, `symmetry` specifies the normalized signal symmetry which ranges from 0 - 1.0, and /// `amplitude` specifies the signal amplitude in Volts. -#[derive(Copy, Clone, Debug, Deserialize, Serialize)] +#[derive(Copy, Clone, Debug, Tree)] pub struct BasicConfig { /// The signal type that should be generated. See [Signal] variants. pub signal: Signal, diff --git a/src/net/mod.rs b/src/net/mod.rs index b6ae2bc18..16ab057cf 100644 --- a/src/net/mod.rs +++ b/src/net/mod.rs @@ -27,9 +27,6 @@ use smoltcp_nal::embedded_nal::SocketAddr; pub type NetworkReference = smoltcp_nal::shared::NetworkStackProxy<'static, NetworkStack>; -/// The default MQTT broker IP address if unspecified. -pub const DEFAULT_MQTT_BROKER: [u8; 4] = [10, 34, 16, 10]; - pub struct MqttStorage { telemetry: [u8; 1024], settings: [u8; 1024], @@ -61,8 +58,14 @@ pub struct NetworkUsers< T: Serialize, const Y: usize, > { - pub miniconf: - miniconf::MqttClient<'static, S, NetworkReference, SystemTimer, miniconf::minimq::broker::NamedBroker, Y>, + pub miniconf: miniconf::MqttClient< + 'static, + S, + NetworkReference, + SystemTimer, + miniconf::minimq::broker::NamedBroker, + Y, + >, pub processor: NetworkProcessor, stream: DataStream, generator: Option, @@ -82,6 +85,7 @@ where /// * `clock` - A `SystemTimer` implementing `Clock`. /// * `app` - The name of the application. /// * `mac` - The MAC address of the network. + /// * `broker` - The domain name of the MQTT broker to use. /// /// # Returns /// A new struct of network users. @@ -91,6 +95,7 @@ where clock: SystemTimer, app: &str, mac: smoltcp_nal::smoltcp::wire::EthernetAddress, + broker: &str, ) -> Self { let stack_manager = cortex_m::singleton!(: NetworkManager = NetworkManager::new(stack)) @@ -105,23 +110,36 @@ where cortex_m::singleton!(: MqttStorage = MqttStorage::default()) .unwrap(); - let broker_domain_name = option_env!("BROKER").unwrap_or("fake"); - let broker = miniconf::minimq::broker::NamedBroker::new(broker_domain_name, stack_manager.acquire_stack()).unwrap(); + let named_broker = miniconf::minimq::broker::NamedBroker::new( + broker, + stack_manager.acquire_stack(), + ) + .unwrap(); let settings = miniconf::MqttClient::new( stack_manager.acquire_stack(), &prefix, clock, S::default(), - miniconf::minimq::ConfigBuilder::new(broker, &mut store.settings) - .client_id(&get_client_id(app, "settings", mac)).unwrap() + miniconf::minimq::ConfigBuilder::new( + named_broker, + &mut store.settings, + ) + .client_id(&get_client_id(app, "settings", mac)) + .unwrap(), ) .unwrap(); - let broker = minimq::broker::NamedBroker::new(broker_domain_name, stack_manager.acquire_stack()).unwrap(); + let named_broker = minimq::broker::NamedBroker::new( + broker, + stack_manager.acquire_stack(), + ) + .unwrap(); let mqtt = minimq::Minimq::new( stack_manager.acquire_stack(), clock, - minimq::ConfigBuilder::new(broker, &mut store.telemetry).client_id(&get_client_id(app, "tlm", mac)).unwrap() + minimq::ConfigBuilder::new(named_broker, &mut store.telemetry) + .client_id(&get_client_id(app, "tlm", mac)) + .unwrap(), ); let telemetry = TelemetryClient::new(mqtt, &prefix); diff --git a/src/net/telemetry.rs b/src/net/telemetry.rs index b6316403e..e5efd28ef 100644 --- a/src/net/telemetry.rs +++ b/src/net/telemetry.rs @@ -18,7 +18,12 @@ use crate::hardware::{adc::AdcCode, afe::Gain, dac::DacCode, SystemTimer}; /// The telemetry client for reporting telemetry data over MQTT. pub struct TelemetryClient { - mqtt: minimq::Minimq<'static, NetworkReference, SystemTimer, minimq::broker::NamedBroker>, + mqtt: minimq::Minimq< + 'static, + NetworkReference, + SystemTimer, + minimq::broker::NamedBroker, + >, telemetry_topic: String<128>, _telemetry: core::marker::PhantomData, } @@ -102,7 +107,12 @@ impl TelemetryClient { /// # Returns /// A new telemetry client. pub fn new( - mqtt: minimq::Minimq<'static, NetworkReference, SystemTimer, minimq::broker::NamedBroker>, + mqtt: minimq::Minimq< + 'static, + NetworkReference, + SystemTimer, + minimq::broker::NamedBroker, + >, prefix: &str, ) -> Self { let mut telemetry_topic: String<128> = String::from(prefix); From 6c01d30360381b1deeea3858634b48c3e77aeaed Mon Sep 17 00:00:00 2001 From: Ryan Summers Date: Tue, 5 Sep 2023 13:33:18 +0200 Subject: [PATCH 14/17] Updating broker default DNS name --- src/bin/dual-iir.rs | 2 +- src/bin/lockin.rs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/bin/dual-iir.rs b/src/bin/dual-iir.rs index 1db097100..8a6918acc 100644 --- a/src/bin/dual-iir.rs +++ b/src/bin/dual-iir.rs @@ -220,7 +220,7 @@ mod app { clock, env!("CARGO_BIN_NAME"), stabilizer.net.mac_address, - option_env!("BROKER").unwrap_or("10.34.16.10"), + option_env!("BROKER").unwrap_or("mqtt"), ); let generator = network.configure_streaming(StreamFormat::AdcDacData); diff --git a/src/bin/lockin.rs b/src/bin/lockin.rs index c30fea38c..f44872228 100644 --- a/src/bin/lockin.rs +++ b/src/bin/lockin.rs @@ -260,7 +260,7 @@ mod app { clock, env!("CARGO_BIN_NAME"), stabilizer.net.mac_address, - option_env!("BROKER").unwrap_or("10.34.16.10"), + option_env!("BROKER").unwrap_or("mqtt"), ); let generator = network.configure_streaming(StreamFormat::AdcDacData); From d6898130aeab8056fa3612ed286912dcc08660de Mon Sep 17 00:00:00 2001 From: Ryan Summers Date: Tue, 5 Sep 2023 15:55:13 +0200 Subject: [PATCH 15/17] Updating lockfile --- Cargo.lock | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Cargo.lock b/Cargo.lock index 1f7cbf78d..1a0a04db6 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -441,7 +441,7 @@ dependencies = [ [[package]] name = "minimq" version = "0.7.0" -source = "git+https://github.com/quartiq/minimq#f4cb420186fb6f294ffdaa612bb8401c3261fd63" +source = "git+https://github.com/quartiq/minimq#008fe6305b263046cabe296a64518cd99e597e35" dependencies = [ "bit_field", "embedded-nal", From 72aba1a88b90b554f501b4de78527b561d4b261c Mon Sep 17 00:00:00 2001 From: Ryan Summers Date: Tue, 5 Sep 2023 15:58:41 +0200 Subject: [PATCH 16/17] Fixing miniconf path --- py/setup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/py/setup.py b/py/setup.py index 308f7b39f..0148af75d 100644 --- a/py/setup.py +++ b/py/setup.py @@ -15,6 +15,6 @@ "matplotlib", "gmqtt", # Keep this synced with the miniconf version in Cargo.toml - "miniconf-mqtt@git+https://github.com/quartiq/miniconf@master#subdirectory=py/miniconf-mqtt", + "miniconf-mqtt@git+https://github.com/quartiq/miniconf@main#subdirectory=py/miniconf-mqtt", ], ) From 64b237c4b37b94b1254b6f2c10410584e4ea082a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Robert=20J=C3=B6rdens?= Date: Tue, 5 Sep 2023 16:16:27 +0200 Subject: [PATCH 17/17] Update hitl/loopback.py Co-authored-by: Ryan Summers --- hitl/loopback.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/hitl/loopback.py b/hitl/loopback.py index cb573982f..dd32c6b41 100644 --- a/hitl/loopback.py +++ b/hitl/loopback.py @@ -89,9 +89,9 @@ async def test(): miniconf = await Miniconf.create(args.prefix, args.broker) # Disable IIR holds and configure the telemetry rate. - await miniconf.set('allow_hold', False, retain=False) - await miniconf.set('force_hold', False, retain=False) - await miniconf.set('telemetry_period', 1, retain=False) + await miniconf.set('/allow_hold', False, retain=False) + await miniconf.set('/force_hold', False, retain=False) + await miniconf.set('/telemetry_period', 1, retain=False) # Test loopback with a static 1V output of the DACs. await test_loopback(miniconf, tele.queue, 1.0)