From c553e72df485fb01a89ec05e526e4200006a240e Mon Sep 17 00:00:00 2001 From: Ryan Summers Date: Mon, 1 Mar 2021 14:46:12 +0100 Subject: [PATCH 1/8] Updating miniconf dependencies --- Cargo.lock | 6 ++---- Cargo.toml | 3 +-- dsp/src/iir.rs | 4 ++-- dsp/src/iir_int.rs | 4 ++-- src/bin/dual-iir.rs | 18 +++++------------- src/hardware/afe.rs | 4 ++-- 6 files changed, 14 insertions(+), 25 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 0999288..b0cb459 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -199,9 +199,8 @@ dependencies = [ ] [[package]] -name = "derive_stringset" +name = "derive_miniconf" version = "0.1.0" -source = "git+https://github.com/quartiq/miniconf.git?branch=develop#97ace3d8268075235cb67a2a8740d200bea1fe30" dependencies = [ "proc-macro2", "quote", @@ -402,9 +401,8 @@ dependencies = [ [[package]] name = "miniconf" version = "0.1.0" -source = "git+https://github.com/quartiq/miniconf.git?branch=develop#97ace3d8268075235cb67a2a8740d200bea1fe30" dependencies = [ - "derive_stringset", + "derive_miniconf", "heapless", "minimq", "serde", diff --git a/Cargo.toml b/Cargo.toml index f384fe9..4160253 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -49,8 +49,7 @@ miniconf = "0.1" generic-array = "0.14" [patch.crates-io.miniconf] -git = "https://github.com/quartiq/miniconf.git" -branch = "develop" +path = "../miniconf/" [patch.crates-io.serde-json-core] git = "https://github.com/rust-embedded-community/serde-json-core.git" diff --git a/dsp/src/iir.rs b/dsp/src/iir.rs index d323a6c..ee9639e 100644 --- a/dsp/src/iir.rs +++ b/dsp/src/iir.rs @@ -1,4 +1,4 @@ -use miniconf::StringSet; +use miniconf::MiniconfAtomic; use serde::Deserialize; use super::{abs, copysign, macc, max, min}; @@ -39,7 +39,7 @@ pub type Vec5 = [f32; 5]; /// Therefore it can trivially implement bump-less transfer. /// * Cascading multiple IIR filters allows stable and robust /// implementation of transfer functions beyond bequadratic terms. -#[derive(Copy, Clone, Debug, Default, Deserialize, StringSet)] +#[derive(Copy, Clone, Debug, Default, Deserialize, MiniconfAtomic)] pub struct IIR { pub ba: Vec5, pub y_offset: f32, diff --git a/dsp/src/iir_int.rs b/dsp/src/iir_int.rs index ef0c1dc..5ac75f5 100644 --- a/dsp/src/iir_int.rs +++ b/dsp/src/iir_int.rs @@ -1,6 +1,6 @@ use super::tools::macc_i32; use core::f64::consts::PI; -use miniconf::StringSet; +use miniconf::MiniconfAtomic; use serde::Deserialize; /// Generic vector for integer IIR filter. @@ -46,7 +46,7 @@ impl Coeff for Vec5 { /// See `dsp::iir::IIR` for general implementation details. /// Offset and limiting disabled to suit lowpass applications. /// Coefficient scaling fixed and optimized. -#[derive(Copy, Clone, Default, Debug, StringSet, Deserialize)] +#[derive(Copy, Clone, Default, Debug, MiniconfAtomic, Deserialize)] pub struct IIR { pub ba: Vec5, // pub y_offset: i32, diff --git a/src/bin/dual-iir.rs b/src/bin/dual-iir.rs index a2279d8..9b6b24f 100644 --- a/src/bin/dual-iir.rs +++ b/src/bin/dual-iir.rs @@ -8,7 +8,7 @@ use stabilizer::hardware; use miniconf::{ embedded_nal::{IpAddr, Ipv4Addr}, - minimq, MqttInterface, StringSet, + minimq, Miniconf, MqttInterface, }; use serde::Deserialize; @@ -23,7 +23,7 @@ const SCALE: f32 = i16::MAX as _; // The number of cascaded IIR biquads per channel. Select 1 or 2! const IIR_CASCADE_LENGTH: usize = 1; -#[derive(Debug, Deserialize, StringSet)] +#[derive(Debug, Deserialize, Miniconf)] pub struct Settings { afe: [AfeGain; 2], iir_ch: [[iir::IIR; IIR_CASCADE_LENGTH]; 2], @@ -143,23 +143,15 @@ const APP: () = { let clock = c.resources.clock; loop { - let sleep = c.resources.mqtt_interface.lock(|interface| { + let _sleep = c.resources.mqtt_interface.lock(|interface| { !interface.network_stack().poll(clock.current_ms()) }); - match c - .resources + if c.resources .mqtt_interface .lock(|interface| interface.update().unwrap()) { - miniconf::Action::Continue => { - if sleep { - cortex_m::asm::wfi(); - } - } - miniconf::Action::CommitSettings => { - c.spawn.settings_update().unwrap() - } + c.spawn.settings_update().unwrap() } } } diff --git a/src/hardware/afe.rs b/src/hardware/afe.rs index 8ce1bd1..9e3674b 100644 --- a/src/hardware/afe.rs +++ b/src/hardware/afe.rs @@ -1,11 +1,11 @@ -use miniconf::StringSet; +use miniconf::Miniconf; use serde::{Deserialize, Serialize}; use core::convert::TryFrom; use enum_iterator::IntoEnumIterator; #[derive( - Copy, Clone, Debug, Serialize, Deserialize, IntoEnumIterator, StringSet, + Copy, Clone, Debug, Serialize, Deserialize, IntoEnumIterator, Miniconf, )] pub enum Gain { G1 = 0b00, From c2b00db9e96ab6a7d59edf072718d92b23ea15dd Mon Sep 17 00:00:00 2001 From: Ryan Summers Date: Tue, 2 Mar 2021 16:43:19 +0100 Subject: [PATCH 2/8] Updating minimq/miniconf dependencies --- Cargo.lock | 5 +++-- Cargo.toml | 7 ++++++- src/bin/dual-iir.rs | 8 ++------ stabilizer.py | 6 ------ 4 files changed, 11 insertions(+), 15 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index b0cb459..47be14a 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -201,6 +201,7 @@ dependencies = [ [[package]] name = "derive_miniconf" version = "0.1.0" +source = "git+https://github.com/quartiq/miniconf.git?branch=rs/crate-scope-derive#dbd3dfb0ea79b7227c9f217849817601adfa4421" dependencies = [ "proc-macro2", "quote", @@ -401,6 +402,7 @@ dependencies = [ [[package]] name = "miniconf" version = "0.1.0" +source = "git+https://github.com/quartiq/miniconf.git?branch=rs/crate-scope-derive#dbd3dfb0ea79b7227c9f217849817601adfa4421" dependencies = [ "derive_miniconf", "heapless", @@ -412,8 +414,7 @@ dependencies = [ [[package]] name = "minimq" version = "0.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9c5e626690b6f62e15710cf9815e5ca25ee54084899298c100a14b2504c80a46" +source = "git+https://github.com/quartiq/minimq.git?branch=feature/optional-client-id#18c277088d427a54b8fdb49f2755ffda2479bf3f" dependencies = [ "bit_field", "embedded-nal", diff --git a/Cargo.toml b/Cargo.toml index 4160253..340f275 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -49,7 +49,12 @@ miniconf = "0.1" generic-array = "0.14" [patch.crates-io.miniconf] -path = "../miniconf/" +git = "https://github.com/quartiq/miniconf.git" +branch = "rs/crate-scope-derive" + +[patch.crates-io.minimq] +git = "https://github.com/quartiq/minimq.git" +branch = "feature/optional-client-id" [patch.crates-io.serde-json-core] git = "https://github.com/rust-embedded-community/serde-json-core.git" diff --git a/src/bin/dual-iir.rs b/src/bin/dual-iir.rs index 9b6b24f..97ea9b3 100644 --- a/src/bin/dual-iir.rs +++ b/src/bin/dual-iir.rs @@ -63,12 +63,8 @@ const APP: () = { let mqtt_interface = { let mqtt_client = { let broker = IpAddr::V4(Ipv4Addr::new(10, 34, 16, 1)); - minimq::MqttClient::new( - broker, - "stabilizer", - stabilizer.net.stack, - ) - .unwrap() + minimq::MqttClient::new(broker, None, stabilizer.net.stack) + .unwrap() }; MqttInterface::new(mqtt_client, "stabilizer", Settings::default()) diff --git a/stabilizer.py b/stabilizer.py index 973a7d1..f302067 100644 --- a/stabilizer.py +++ b/stabilizer.py @@ -108,10 +108,6 @@ async def configure_settings(args): response = await interface.command(f'settings/{args.setting}', json.dumps(request)) logger.info(response) - if args.commit: - response = await interface.command('commit', 'commit') - logger.info(response) - def main(): """ Main program entry point. """ @@ -122,8 +118,6 @@ def main(): parser.add_argument('--broker', default='10.34.16.1', type=str, help='The MQTT broker address') parser.add_argument('values', nargs='+', type=str, help='The value of settings. key=value list or a single value is accepted.') - parser.add_argument('--commit', action='store_true', - help='Specified true to commit after updating settings.') parser.add_argument('-v', '--verbose', action='store_true', help='Enable verbose logging') args = parser.parse_args() From 40c04c67c521e70dddc1d9fc7408a7891946089d Mon Sep 17 00:00:00 2001 From: Ryan Summers Date: Tue, 2 Mar 2021 17:00:11 +0100 Subject: [PATCH 3/8] Updating dependencies --- Cargo.lock | 6 +++--- Cargo.toml | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 47be14a..c98a179 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -201,7 +201,7 @@ dependencies = [ [[package]] name = "derive_miniconf" version = "0.1.0" -source = "git+https://github.com/quartiq/miniconf.git?branch=rs/crate-scope-derive#dbd3dfb0ea79b7227c9f217849817601adfa4421" +source = "git+https://github.com/quartiq/miniconf.git?branch=develop#394d0634a9622e43a55850afc34eb4695ecababa" dependencies = [ "proc-macro2", "quote", @@ -402,7 +402,7 @@ dependencies = [ [[package]] name = "miniconf" version = "0.1.0" -source = "git+https://github.com/quartiq/miniconf.git?branch=rs/crate-scope-derive#dbd3dfb0ea79b7227c9f217849817601adfa4421" +source = "git+https://github.com/quartiq/miniconf.git?branch=develop#394d0634a9622e43a55850afc34eb4695ecababa" dependencies = [ "derive_miniconf", "heapless", @@ -414,7 +414,7 @@ dependencies = [ [[package]] name = "minimq" version = "0.2.0" -source = "git+https://github.com/quartiq/minimq.git?branch=feature/optional-client-id#18c277088d427a54b8fdb49f2755ffda2479bf3f" +source = "git+https://github.com/quartiq/minimq.git?branch=feature/optional-client-id#6777c669604fd1c8043742314159e9090ed4f115" dependencies = [ "bit_field", "embedded-nal", diff --git a/Cargo.toml b/Cargo.toml index 340f275..2e36f38 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -50,7 +50,7 @@ generic-array = "0.14" [patch.crates-io.miniconf] git = "https://github.com/quartiq/miniconf.git" -branch = "rs/crate-scope-derive" +branch = "develop" [patch.crates-io.minimq] git = "https://github.com/quartiq/minimq.git" From 4358d07dab80d658379a5dcd6b0ca48ce92a0975 Mon Sep 17 00:00:00 2001 From: Ryan Summers Date: Tue, 2 Mar 2021 17:09:10 +0100 Subject: [PATCH 4/8] Updating id semantics --- src/bin/dual-iir.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/bin/dual-iir.rs b/src/bin/dual-iir.rs index 97ea9b3..e5ff197 100644 --- a/src/bin/dual-iir.rs +++ b/src/bin/dual-iir.rs @@ -63,7 +63,7 @@ const APP: () = { let mqtt_interface = { let mqtt_client = { let broker = IpAddr::V4(Ipv4Addr::new(10, 34, 16, 1)); - minimq::MqttClient::new(broker, None, stabilizer.net.stack) + minimq::MqttClient::new(broker, "", stabilizer.net.stack) .unwrap() }; From 6f1532c2a3899ca011a091d9179bc3dce0ac737d Mon Sep 17 00:00:00 2001 From: Ryan Summers Date: Tue, 2 Mar 2021 17:11:19 +0100 Subject: [PATCH 5/8] Updating dependencies --- Cargo.lock | 2 +- Cargo.toml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index c98a179..2ee26be 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -414,7 +414,7 @@ dependencies = [ [[package]] name = "minimq" version = "0.2.0" -source = "git+https://github.com/quartiq/minimq.git?branch=feature/optional-client-id#6777c669604fd1c8043742314159e9090ed4f115" +source = "git+https://github.com/quartiq/minimq.git?branch=master#a89a6f11d0d1f63114fb15f676022eb4fe904f56" dependencies = [ "bit_field", "embedded-nal", diff --git a/Cargo.toml b/Cargo.toml index 2e36f38..3411b48 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -54,7 +54,7 @@ branch = "develop" [patch.crates-io.minimq] git = "https://github.com/quartiq/minimq.git" -branch = "feature/optional-client-id" +branch = "master" [patch.crates-io.serde-json-core] git = "https://github.com/rust-embedded-community/serde-json-core.git" From c13eaaba4c8a4145feb022557de9bb6e772f5f07 Mon Sep 17 00:00:00 2001 From: Ryan Summers Date: Tue, 2 Mar 2021 17:16:40 +0100 Subject: [PATCH 6/8] Restoring sleep semantics --- src/bin/dual-iir.rs | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/bin/dual-iir.rs b/src/bin/dual-iir.rs index e5ff197..391b127 100644 --- a/src/bin/dual-iir.rs +++ b/src/bin/dual-iir.rs @@ -139,8 +139,8 @@ const APP: () = { let clock = c.resources.clock; loop { - let _sleep = c.resources.mqtt_interface.lock(|interface| { - !interface.network_stack().poll(clock.current_ms()) + let sleep = c.resources.mqtt_interface.lock(|interface| { + interface.network_stack().poll(clock.current_ms()) }); if c.resources @@ -149,6 +149,10 @@ const APP: () = { { c.spawn.settings_update().unwrap() } + + if sleep { + cortex_m::asm::wfi(); + } } } From aca524ec8569ea4c3351e8e024775da4ba4e7a87 Mon Sep 17 00:00:00 2001 From: Ryan Summers Date: Tue, 2 Mar 2021 17:17:51 +0100 Subject: [PATCH 7/8] Fixing negation --- src/bin/dual-iir.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/bin/dual-iir.rs b/src/bin/dual-iir.rs index 391b127..00e7d12 100644 --- a/src/bin/dual-iir.rs +++ b/src/bin/dual-iir.rs @@ -140,7 +140,7 @@ const APP: () = { loop { let sleep = c.resources.mqtt_interface.lock(|interface| { - interface.network_stack().poll(clock.current_ms()) + !interface.network_stack().poll(clock.current_ms()) }); if c.resources From a9d16a1632822cf63c2af63c22e0d1de8db2f6e6 Mon Sep 17 00:00:00 2001 From: Ryan Summers Date: Tue, 2 Mar 2021 17:20:31 +0100 Subject: [PATCH 8/8] Adjusting sleep semantics --- src/bin/dual-iir.rs | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/bin/dual-iir.rs b/src/bin/dual-iir.rs index 00e7d12..25350ab 100644 --- a/src/bin/dual-iir.rs +++ b/src/bin/dual-iir.rs @@ -148,9 +148,7 @@ const APP: () = { .lock(|interface| interface.update().unwrap()) { c.spawn.settings_update().unwrap() - } - - if sleep { + } else if sleep { cortex_m::asm::wfi(); } }