Skip to content

Commit

Permalink
Merge pull request #164 from quartiq/runtime-sensor
Browse files Browse the repository at this point in the history
bump dependencies, miniconf 0.15
  • Loading branch information
jordens authored Oct 1, 2024
2 parents 3dd2e64 + e08f62d commit 66d24a3
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 49 deletions.
71 changes: 36 additions & 35 deletions Cargo.lock

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

4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,8 @@ bytemuck = { version = "1.18.0", features = [
"derive",
], default-features = false }
# Note: Keep in-sync with `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" }
strum = { version = "0.26.1", default-features = false, features = ["derive"] }
serial-settings = "0.1"
postcard = "1"
Expand Down
4 changes: 1 addition & 3 deletions src/hardware/setup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -126,9 +126,7 @@ pub fn setup<C, const Y: usize>(
clock: crate::SystemTimer,
) -> ThermostatDevices<C, Y>
where
C: serial_settings::Settings<Y>
+ for<'d> miniconf::JsonCoreSlash<'d, Y>
+ crate::settings::AppSettings,
C: serial_settings::Settings<Y> + crate::settings::AppSettings,
{
// Set up RTT logging
{
Expand Down
6 changes: 3 additions & 3 deletions src/net/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ use telemetry::TelemetryClient;

use core::fmt::Write;
use heapless::String;
use miniconf::{JsonCoreSlash, Tree};
use miniconf::{Tree, TreeDeserializeOwned, TreeSerialize};

pub type NetworkReference = smoltcp_nal::shared::NetworkStackProxy<'static, NetworkStack>;

Expand Down Expand Up @@ -57,7 +57,7 @@ pub enum NetworkState {
/// A structure of Stabilizer's default network users.
pub struct NetworkUsers<S, const Y: usize>
where
for<'de> S: Default + JsonCoreSlash<'de, Y> + Clone,
S: Default + TreeDeserializeOwned<Y> + TreeSerialize<Y> + Clone,
{
pub miniconf: miniconf_mqtt::MqttClient<
'static,
Expand All @@ -75,7 +75,7 @@ where

impl<S, const Y: usize> NetworkUsers<S, Y>
where
for<'de> S: Default + JsonCoreSlash<'de, Y> + Clone,
S: Default + TreeDeserializeOwned<Y> + TreeSerialize<Y> + Clone,
{
/// Construct Stabilizer's default network users.
///
Expand Down
12 changes: 6 additions & 6 deletions src/settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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},
Expand Down Expand Up @@ -80,15 +80,15 @@ pub struct SettingsKey(Vec<u8, 128>);

impl sequential_storage::map::Key for SettingsKey {
fn serialize_into(&self, buffer: &mut [u8]) -> Result<usize, SerializationError> {
Ok(postcard::to_slice(self, buffer)
Ok(::postcard::to_slice(self, buffer)
.map_err(|_| SerializationError::BufferTooSmall)?
.len())
}

fn deserialize_from(buffer: &[u8]) -> Result<(Self, usize), SerializationError> {
let original_length = buffer.len();
let (result, remainder) =
postcard::take_from_bytes(buffer).map_err(|_| SerializationError::BufferTooSmall)?;
::postcard::take_from_bytes(buffer).map_err(|_| SerializationError::BufferTooSmall)?;
Ok((result, original_length - remainder.len()))
}
}
Expand All @@ -108,7 +108,7 @@ pub struct SerialSettingsPlatform<C, const Y: usize> {

impl<C, const Y: usize> SerialSettingsPlatform<C, Y>
where
C: for<'d> JsonCoreSlash<'d, Y>,
C: TreeDeserializeOwned<Y> + TreeSerialize<Y>,
{
pub fn load(structure: &mut C, storage: &mut Flash) {
// Loop over flash and read settings
Expand Down Expand Up @@ -140,8 +140,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()
Expand Down

0 comments on commit 66d24a3

Please sign in to comment.