From b6bb167f3c11134e41fbd4f30e15c32a5d9562c0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Robert=20J=C3=B6rdens?= Date: Tue, 1 Oct 2024 09:15:33 +0000 Subject: [PATCH] deps: update, including miniconf 0.15 --- Cargo.lock | 79 ++++++++++++++++++++++++--------- Cargo.toml | 4 +- py/pyproject.toml | 2 +- serial-settings/Cargo.toml | 2 +- serial-settings/src/lib.rs | 91 ++++++++++++++++++++++---------------- src/hardware/adc.rs | 2 +- src/hardware/dac.rs | 2 +- src/hardware/setup.rs | 4 +- src/net/mod.rs | 6 +-- src/net/telemetry.rs | 12 +---- src/settings.rs | 12 ++--- 11 files changed, 126 insertions(+), 90 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 3aa780250..b3e9b2434 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -23,9 +23,9 @@ dependencies = [ [[package]] name = "autocfg" -version = "1.3.0" +version = "1.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0c4b4d0bd25bd0b74681c0ad21497610ce1b7c91b1022cd21c80c6fbdd9476b0" +checksum = "ace50bade8e6234aa140d9a2f552bbee1db4d353f69b8217bc503490fc1a9f26" [[package]] name = "bare-metal" @@ -95,9 +95,9 @@ checksum = "37b2a672a2cb129a2e41c10b1224bb368f9f37a2b16b612598138befd7b37eb5" [[package]] name = "cc" -version = "1.1.21" +version = "1.1.23" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "07b1695e2c7e8fc85310cde85aeaab7e3097f593c91d209d3f9df76c928100f0" +checksum = "3bbb537bb4a30b90362caddba8f360c0a56bc13d3a5570028e7197204cb54a17" dependencies = [ "jobserver", "libc", @@ -176,7 +176,7 @@ dependencies = [ "proc-macro2", "quote", "strsim", - "syn 2.0.77", + "syn 2.0.79", ] [[package]] @@ -187,7 +187,7 @@ checksum = "d336a2a514f6ccccaa3e09b02d41d35330c07ddf03a62165fcec10bb561c7806" dependencies = [ "darling_core", "quote", - "syn 2.0.77", + "syn 2.0.79", ] [[package]] @@ -287,7 +287,7 @@ checksum = "a1ab991c1362ac86c61ab6f556cff143daa22e5a15e4e189df818b2fd19fe65b" dependencies = [ "proc-macro2", "quote", - "syn 2.0.77", + "syn 2.0.79", ] [[package]] @@ -412,6 +412,12 @@ dependencies = [ "stable_deref_trait", ] +[[package]] +name = "heck" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2304e00983f87ffb38b55b444b5e3b60a884b5d30c0fca7d82fe33449bbe55ea" + [[package]] name = "ident_case" version = "1.0.1" @@ -553,9 +559,9 @@ dependencies = [ [[package]] name = "miniconf" -version = "0.14.0" +version = "0.15.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8954fad4aada6a559edc5753c428cde9bc1d317f7672a5898b9943e7be414abc" +checksum = "5c6b2564a43efc42f7a739630c9752504f4eead801b5db791398538c7f1ebe27" dependencies = [ "itoa", "miniconf_derive", @@ -566,21 +572,21 @@ dependencies = [ [[package]] name = "miniconf_derive" -version = "0.14.0" +version = "0.15.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ce0cba49d607e4b2ab1b511d182112d5833397f6bb3f404b666e1be6bf94bd43" +checksum = "1767ec579af0f56cfa836adabcc69f90a0fd6d65036a3899136d355277590d13" dependencies = [ "darling", "proc-macro2", "quote", - "syn 2.0.77", + "syn 2.0.79", ] [[package]] name = "miniconf_mqtt" -version = "0.14.0" +version = "0.15.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6b62859f66f4e14fa77ec84605845a6ad9b95447630b05535e529507db35dafc" +checksum = "177c142faa49a5bc71ced59afc159fc67820d99677a206e7d8992fe7bce93970" dependencies = [ "embedded-io", "heapless 0.8.0", @@ -589,6 +595,7 @@ dependencies = [ "minimq", "serde-json-core", "smlang 0.8.0", + "strum", ] [[package]] @@ -739,7 +746,7 @@ checksum = "af1844ef2428cc3e1cb900be36181049ef3d3193c63e43026cfe202983b27a56" dependencies = [ "proc-macro2", "quote", - "syn 2.0.77", + "syn 2.0.79", ] [[package]] @@ -783,9 +790,9 @@ checksum = "953ec861398dccce10c670dfeaf3ec4911ca479e9c02154b3a215178c5f566f2" [[package]] name = "portable-atomic" -version = "1.8.0" +version = "1.9.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d30538d42559de6b034bc76fd6dd4c38961b1ee5c6c56e3808c50128fdbc22ce" +checksum = "cc9c68a3f6da06753e9335d63e27f6b9754dd1920d941135b7ea8224f141adb2" [[package]] name = "postcard" @@ -894,7 +901,7 @@ dependencies = [ "proc-macro-error", "proc-macro2", "quote", - "syn 2.0.77", + "syn 2.0.79", ] [[package]] @@ -962,6 +969,12 @@ dependencies = [ "semver 1.0.23", ] +[[package]] +name = "rustversion" +version = "1.0.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "955d28af4278de8121b7ebeb796b6a45735dc01436d898801014aced2773a3d6" + [[package]] name = "ryu" version = "1.0.18" @@ -1032,7 +1045,7 @@ checksum = "243902eda00fad750862fc144cea25caca5e20d615af0a81bee94ca738f1df1f" dependencies = [ "proc-macro2", "quote", - "syn 2.0.77", + "syn 2.0.79", ] [[package]] @@ -1055,7 +1068,7 @@ dependencies = [ "darling", "proc-macro2", "quote", - "syn 2.0.77", + "syn 2.0.79", ] [[package]] @@ -1267,6 +1280,28 @@ version = "0.11.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7da8b5736845d9f2fcb837ea5d9e2628564b3b043a70948a3f0b778838c5fb4f" +[[package]] +name = "strum" +version = "0.26.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8fec0f0aef304996cf250b31b5a10dee7980c85da9d759361292b8bca5a18f06" +dependencies = [ + "strum_macros", +] + +[[package]] +name = "strum_macros" +version = "0.26.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4c6bee85a5a24955dc440386795aa378cd9cf82acd5f764469152d2270e581be" +dependencies = [ + "heck", + "proc-macro2", + "quote", + "rustversion", + "syn 2.0.79", +] + [[package]] name = "syn" version = "1.0.109" @@ -1280,9 +1315,9 @@ dependencies = [ [[package]] name = "syn" -version = "2.0.77" +version = "2.0.79" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9f35bcdf61fd8e7be6caf75f429fdca8beb3ed76584befb503b1569faee373ed" +checksum = "89132cd0bf050864e1d38dc3bbc07a0eb8e7530af26344d3d2bbbef83499f590" dependencies = [ "proc-macro2", "quote", diff --git a/Cargo.toml b/Cargo.toml index 7909ab36f..f146c5a23 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -66,8 +66,8 @@ minimq = "0.9.0" usb-device = "0.3.2" usbd-serial = "0.2" # Keep this synced with the miniconf version in py/setup.py -miniconf = { version = "0.14", features = ["json-core", "derive", "postcard"] } -miniconf_mqtt = { version = "0.14" } +miniconf = { version = "0.15", features = ["json-core", "derive", "postcard"] } +miniconf_mqtt = { version = "0.15" } tca9539 = "0.2" smoltcp-nal = { version = "0.5", features = ["shared-stack"] } postcard = "1" diff --git a/py/pyproject.toml b/py/pyproject.toml index dcf5a6029..dd0376bdb 100644 --- a/py/pyproject.toml +++ b/py/pyproject.toml @@ -18,7 +18,7 @@ dependencies = [ "numpy", "scipy", "matplotlib", - "miniconf-mqtt@git+https://github.com/quartiq/miniconf@v0.14.0#subdirectory=py/miniconf-mqtt", + "miniconf-mqtt@git+https://github.com/quartiq/miniconf@v0.15.0#subdirectory=py/miniconf-mqtt", ] [project.urls] diff --git a/serial-settings/Cargo.toml b/serial-settings/Cargo.toml index c042b9537..93ae13b6d 100644 --- a/serial-settings/Cargo.toml +++ b/serial-settings/Cargo.toml @@ -17,7 +17,7 @@ repository = "https://github.com/quartiq/stabilizer" maintenance = { status = "actively-developed" } [dependencies] -miniconf = { version = "0.14", features = ["json-core", "postcard"] } +miniconf = { version = "0.15", features = ["json-core", "postcard"] } menu = { version = "0.6", features = ["echo"], git = "https://github.com/rust-embedded-community/menu.git" } heapless = "0.8" embedded-io = "0.6" diff --git a/serial-settings/src/lib.rs b/serial-settings/src/lib.rs index e3c38250d..6922a6cfa 100644 --- a/serial-settings/src/lib.rs +++ b/serial-settings/src/lib.rs @@ -3,7 +3,10 @@ use embedded_io::{ErrorType, Read, ReadReady, Write}; use heapless::String; -use miniconf::{JsonCoreSlash, Path, Postcard, Traversal, TreeKey}; +use miniconf::{ + json, postcard, Path, Traversal, TreeDeserializeOwned, TreeKey, + TreeSerialize, +}; mod interface; pub use interface::BestEffortInterface; @@ -11,7 +14,7 @@ pub use interface::BestEffortInterface; /// Specifies the API required for objects that are used as settings with the serial terminal /// interface. pub trait Settings: - for<'de> JsonCoreSlash<'de, Y> + for<'de> Postcard<'de, Y> + Clone + TreeSerialize + TreeDeserializeOwned + Clone { /// Reset the settings to their default values. fn reset(&mut self) {} @@ -140,32 +143,37 @@ impl<'a, P: Platform, const Y: usize> Interface<'a, P, Y> { settings, |key, interface, settings, defaults| { // Get current - let check = match settings - .get_json_by_key(&key, interface.buffer) - { - Err(miniconf::Error::Traversal(Traversal::Absent(_))) => { - return; - } - Err(e) => { - writeln!(interface, "Failed to get `{}`: {e}", *key) + let check = + match json::get_by_key(settings, &key, interface.buffer) { + Err(miniconf::Error::Traversal(Traversal::Absent( + _, + ))) => { + return; + } + Err(e) => { + writeln!( + interface, + "Failed to get `{}`: {e}", + *key + ) .unwrap(); - return; - } - Ok(len) => { - write!( - interface.platform.interface_mut(), - "{}: {}", - *key, - core::str::from_utf8(&interface.buffer[..len]) - .unwrap() - ) - .unwrap(); - yafnv::fnv1a::(&interface.buffer[..len]) - } - }; + return; + } + Ok(len) => { + write!( + interface.platform.interface_mut(), + "{}: {}", + *key, + core::str::from_utf8(&interface.buffer[..len]) + .unwrap() + ) + .unwrap(); + yafnv::fnv1a::(&interface.buffer[..len]) + } + }; // Get default and compare - match defaults.get_json_by_key(&key, interface.buffer) { + match json::get_by_key(defaults, &key, interface.buffer) { Err(miniconf::Error::Traversal(Traversal::Absent(_))) => { write!(interface, " [default: absent]") } @@ -199,15 +207,15 @@ impl<'a, P: Platform, const Y: usize> Interface<'a, P, Y> { Ok(None) => write!(interface, " [not stored]"), Ok(Some(stored)) => { - let slic = postcard::de_flavors::Slice::new(stored); + let slic = ::postcard::de_flavors::Slice::new(stored); // Use defaults as scratch space for postcard->json conversion - match defaults.set_postcard_by_key(&key, slic) { + match postcard::set_by_key(defaults, &key, slic) { Err(e) => write!( interface, " [stored deserialize error: {e}]" ), Ok(_rest) => - match defaults.get_json_by_key(&key, interface.buffer) { + match json::get_by_key(defaults, &key, interface.buffer) { Err(e) => write!( interface, " [stored serialization error: {e}]" @@ -248,8 +256,9 @@ impl<'a, P: Platform, const Y: usize> Interface<'a, P, Y> { settings, |key, interface, settings, defaults| { // Get current value checksum - let slic = postcard::ser_flavors::Slice::new(interface.buffer); - let check = match settings.get_postcard_by_key(&key, slic) { + let slic = + ::postcard::ser_flavors::Slice::new(interface.buffer); + let check = match postcard::get_by_key(settings, &key, slic) { Err(miniconf::Error::Traversal(Traversal::Absent(_))) => { return; } @@ -262,8 +271,9 @@ impl<'a, P: Platform, const Y: usize> Interface<'a, P, Y> { }; // Get default if different - let slic = postcard::ser_flavors::Slice::new(interface.buffer); - let slic = match defaults.get_postcard_by_key(&key, slic) { + let slic = + ::postcard::ser_flavors::Slice::new(interface.buffer); + let slic = match postcard::get_by_key(defaults, &key, slic) { Err(miniconf::Error::Traversal(Traversal::Absent(_))) => { log::warn!( "Can't clear. Default is absent: `{}`", @@ -291,8 +301,8 @@ impl<'a, P: Platform, const Y: usize> Interface<'a, P, Y> { // Set default if let Some(slic) = slic { - let slic = postcard::de_flavors::Slice::new(slic); - match settings.set_postcard_by_key(&key, slic) { + let slic = ::postcard::de_flavors::Slice::new(slic); + match postcard::set_by_key(settings, &key, slic) { Err(miniconf::Error::Traversal(Traversal::Absent( _, ))) => { @@ -369,8 +379,10 @@ impl<'a, P: Platform, const Y: usize> Interface<'a, P, Y> { settings, |key, interface, settings, defaults| { // Get default value checksum - let slic = postcard::ser_flavors::Slice::new(interface.buffer); - let mut check = match defaults.get_postcard_by_key(&key, slic) { + let slic = + ::postcard::ser_flavors::Slice::new(interface.buffer); + let mut check = match postcard::get_by_key(defaults, &key, slic) + { // Could also serialize directly into the hasher for all these checksum calcs Ok(slic) => yafnv::fnv1a::(slic), Err(miniconf::Error::Traversal(Traversal::Absent( @@ -417,8 +429,9 @@ impl<'a, P: Platform, const Y: usize> Interface<'a, P, Y> { } // Get value - let slic = postcard::ser_flavors::Slice::new(interface.buffer); - let value = match settings.get_postcard_by_key(&key, slic) { + let slic = + ::postcard::ser_flavors::Slice::new(interface.buffer); + let value = match postcard::get_by_key(settings, &key, slic) { Ok(value) => value, Err(miniconf::Error::Traversal(Traversal::Absent( _depth, @@ -469,7 +482,7 @@ impl<'a, P: Platform, const Y: usize> Interface<'a, P, Y> { menu::argument_finder(item, args, "value").unwrap().unwrap(); // Now, write the new value into memory. - match settings.set_json(key, value.as_bytes()) { + match json::set(settings, key, value.as_bytes()) { Ok(_) => { interface.updated = true; writeln!( diff --git a/src/hardware/adc.rs b/src/hardware/adc.rs index 7041d2ef9..63004948b 100644 --- a/src/hardware/adc.rs +++ b/src/hardware/adc.rs @@ -85,7 +85,7 @@ use hal::{ }; /// A type representing an ADC sample. -#[derive(Copy, Clone)] +#[derive(Copy, Clone, Default)] pub struct AdcCode(pub u16); impl AdcCode { diff --git a/src/hardware/dac.rs b/src/hardware/dac.rs index e01fbdd48..2fd91f386 100644 --- a/src/hardware/dac.rs +++ b/src/hardware/dac.rs @@ -78,7 +78,7 @@ static mut DAC_BUF: [[SampleBuffer; 2]; 2] = /// Custom type for referencing DAC output codes. /// The internal integer is the raw code written to the DAC output register. -#[derive(Copy, Clone)] +#[derive(Copy, Clone, Default)] pub struct DacCode(pub u16); impl DacCode { // The DAC output range in bipolar mode (including the external output op-amp) is +/- 4.096 diff --git a/src/hardware/setup.rs b/src/hardware/setup.rs index aa9d07ddd..011923efd 100644 --- a/src/hardware/setup.rs +++ b/src/hardware/setup.rs @@ -217,9 +217,7 @@ pub fn setup( sample_ticks: u32, ) -> (StabilizerDevices, Option) where - C: serial_settings::Settings - + for<'d> miniconf::JsonCoreSlash<'d, Y> - + AppSettings, + C: serial_settings::Settings + AppSettings, { // Set up RTT logging { diff --git a/src/net/mod.rs b/src/net/mod.rs index 43733fa8a..30503dee8 100644 --- a/src/net/mod.rs +++ b/src/net/mod.rs @@ -24,7 +24,7 @@ use telemetry::TelemetryClient; use core::fmt::Write; use heapless::String; -use miniconf::JsonCoreSlash; +use miniconf::{TreeDeserializeOwned, TreeSerialize}; use miniconf_mqtt::minimq; pub type NetworkReference = @@ -58,7 +58,7 @@ pub enum NetworkState { /// A structure of Stabilizer's default network users. pub struct NetworkUsers where - for<'de> S: Default + JsonCoreSlash<'de, Y> + Clone, + S: Default + TreeDeserializeOwned + TreeSerialize + Clone, { pub miniconf: miniconf_mqtt::MqttClient< 'static, @@ -76,7 +76,7 @@ where impl NetworkUsers where - for<'de> S: Default + JsonCoreSlash<'de, Y> + Clone, + S: Default + TreeDeserializeOwned + TreeSerialize + Clone, { /// Construct Stabilizer's default network users. /// diff --git a/src/net/telemetry.rs b/src/net/telemetry.rs index c8eb536b4..a2aa22039 100644 --- a/src/net/telemetry.rs +++ b/src/net/telemetry.rs @@ -40,7 +40,7 @@ pub struct TelemetryClient { /// These values can be converted to SI units immediately before reporting to save processing time. /// This allows for the DSP process to continually update the values without incurring significant /// run-time overhead during conversion to SI units. -#[derive(Copy, Clone)] +#[derive(Copy, Clone, Default)] pub struct TelemetryBuffer { /// The latest input sample on ADC0/ADC1. pub adcs: [AdcCode; 2], @@ -70,16 +70,6 @@ pub struct Telemetry { pub cpu_temp: f32, } -impl Default for TelemetryBuffer { - fn default() -> Self { - Self { - adcs: [AdcCode(0), AdcCode(0)], - dacs: [DacCode(0), DacCode(0)], - digital_inputs: [false, false], - } - } -} - impl TelemetryBuffer { /// Convert the telemetry buffer to finalized, SI-unit telemetry for reporting. /// diff --git a/src/settings.rs b/src/settings.rs index 431fec2ab..91542b536 100644 --- a/src/settings.rs +++ b/src/settings.rs @@ -27,7 +27,7 @@ use core::fmt::Write; use embassy_futures::block_on; use embedded_io::Write as EioWrite; use heapless::{String, Vec}; -use miniconf::{JsonCoreSlash, Path, Postcard, Tree}; +use miniconf::{postcard, Path, Tree, TreeDeserializeOwned, TreeSerialize}; use sequential_storage::{ cache::NoCache, map::{fetch_item, store_item, SerializationError}, @@ -85,7 +85,7 @@ impl sequential_storage::map::Key for SettingsKey { &self, buffer: &mut [u8], ) -> Result { - Ok(postcard::to_slice(self, buffer) + Ok(::postcard::to_slice(self, buffer) .map_err(|_| SerializationError::BufferTooSmall)? .len()) } @@ -94,7 +94,7 @@ impl sequential_storage::map::Key for SettingsKey { buffer: &[u8], ) -> Result<(Self, usize), SerializationError> { let original_length = buffer.len(); - let (result, remainder) = postcard::take_from_bytes(buffer) + let (result, remainder) = ::postcard::take_from_bytes(buffer) .map_err(|_| SerializationError::BufferTooSmall)?; Ok((result, original_length - remainder.len())) } @@ -115,7 +115,7 @@ pub struct SerialSettingsPlatform { impl SerialSettingsPlatform where - C: for<'d> JsonCoreSlash<'d, Y>, + C: TreeDeserializeOwned + TreeSerialize, { pub fn load(structure: &mut C, storage: &mut Flash) { // Loop over flash and read settings @@ -150,8 +150,8 @@ where log::info!("Loading initial `{}` from flash", path.as_str()); - let flavor = postcard::de_flavors::Slice::new(value); - if let Err(e) = structure.set_postcard_by_key(&path, flavor) { + let flavor = ::postcard::de_flavors::Slice::new(value); + if let Err(e) = postcard::set_by_key(structure, &path, flavor) { log::warn!( "Failed to deserialize `{}` from flash: {e:?}", path.as_str()