diff --git a/src/hardware/flash.rs b/src/hardware/flash.rs index 300f6d95f..6e0642973 100644 --- a/src/hardware/flash.rs +++ b/src/hardware/flash.rs @@ -1,6 +1,6 @@ -use embedded_storage::nor_flash::{ReadNorFlash, NorFlash}; -use stm32h7xx_hal::flash::{LockedFlashBank, UnlockedFlashBank}; use core::fmt::Write; +use embedded_storage::nor_flash::{NorFlash, ReadNorFlash}; +use stm32h7xx_hal::flash::{LockedFlashBank, UnlockedFlashBank}; #[derive(miniconf::Tree)] pub struct Settings { @@ -26,7 +26,10 @@ pub struct FlashSettings { } impl FlashSettings { - pub fn new(mut flash: LockedFlashBank, mac: smoltcp_nal::smoltcp::wire::EthernetAddress) -> Self { + pub fn new( + mut flash: LockedFlashBank, + mac: smoltcp_nal::smoltcp::wire::EthernetAddress, + ) -> Self { let mut settings = Settings::new(mac); let mut buffer = [0u8; 256]; let mut offset: usize = 0; @@ -34,7 +37,8 @@ impl FlashSettings { // We iteratively read the settings from flash to allow for easy expansion of the settings // without losing data in the future when new fields are added. flash.read(offset as u32, &mut buffer[..]).unwrap(); - let len = buffer.iter().skip(1).position(|x| x == &b'"').unwrap_or(0) + 2; + let len = + buffer.iter().skip(1).position(|x| x == &b'"').unwrap_or(0) + 2; settings.broker = { match serde_json_core::from_slice(&buffer[..len]) { Ok((item, size)) => { @@ -49,11 +53,11 @@ impl FlashSettings { }; flash.read(offset as u32, &mut buffer[..]).unwrap(); - let len = buffer.iter().skip(1).position(|x| x == &b'"').unwrap_or(0) + 2; + let len = + buffer.iter().skip(1).position(|x| x == &b'"').unwrap_or(0) + 2; settings.id = { match serde_json_core::from_slice(&buffer[..len]) { Ok((item, size)) => { - offset += size; item } Err(e) => { @@ -70,8 +74,14 @@ impl FlashSettings { let mut bank = self.flash.unlocked(); let mut data = [0; 512]; let mut offset: usize = 0; - offset += serde_json_core::to_slice(&self.settings.broker, &mut data[offset..]).unwrap(); - offset += serde_json_core::to_slice(&self.settings.id, &mut data[offset..]).unwrap(); + offset += serde_json_core::to_slice( + &self.settings.broker, + &mut data[offset..], + ) + .unwrap(); + offset += + serde_json_core::to_slice(&self.settings.id, &mut data[offset..]) + .unwrap(); bank.erase(0, UnlockedFlashBank::ERASE_SIZE as u32).unwrap(); bank.write(0, &data[..offset]).unwrap(); diff --git a/src/hardware/serial_terminal.rs b/src/hardware/serial_terminal.rs index c88e14598..3423cfdb3 100644 --- a/src/hardware/serial_terminal.rs +++ b/src/hardware/serial_terminal.rs @@ -119,7 +119,15 @@ fn handle_property_read( let mut buf = [0u8; 256]; for path in props { - let len = context.flash.settings.get_json(path, &mut buf).unwrap(); + let len = match context.flash.settings.get_json(path, &mut buf) { + Err(e) => { + writeln!(&mut context.output, "Failed to read {path}: {e}") + .unwrap(); + return; + } + Ok(len) => len, + }; + let stringified = core::str::from_utf8(&buf[..len]).unwrap(); writeln!(&mut context.output, "{path}: {stringified}").unwrap(); } @@ -149,7 +157,8 @@ fn handle_property_write( .unwrap(); } Err(e) => { - writeln!(&mut context.output, "Failed to update {property}: {e:?}").unwrap(); + writeln!(&mut context.output, "Failed to update {property}: {e:?}") + .unwrap(); } } } diff --git a/src/hardware/setup.rs b/src/hardware/setup.rs index 329518b8d..2e825c724 100644 --- a/src/hardware/setup.rs +++ b/src/hardware/setup.rs @@ -1072,7 +1072,8 @@ pub fn setup( let (_, flash_bank2) = device.FLASH.split(); - let settings = FlashSettings::new(flash_bank2.unwrap(), network_devices.mac_address.clone()); + let settings = + FlashSettings::new(flash_bank2.unwrap(), network_devices.mac_address); let stabilizer = StabilizerDevices { systick, diff --git a/src/net/mod.rs b/src/net/mod.rs index d0ad140f0..884bd912a 100644 --- a/src/net/mod.rs +++ b/src/net/mod.rs @@ -13,9 +13,7 @@ pub mod data_stream; pub mod network_processor; pub mod telemetry; -use crate::hardware::{ - EthernetPhy, NetworkManager, NetworkStack, SystemTimer, -}; +use crate::hardware::{EthernetPhy, NetworkManager, NetworkStack, SystemTimer}; use data_stream::{DataStream, FrameGenerator}; use network_processor::NetworkProcessor; use telemetry::TelemetryClient; @@ -224,10 +222,7 @@ where /// /// # Returns /// A client ID that may be used for MQTT client identification. -fn get_client_id( - id: &str, - mode: &str, -) -> String<64> { +fn get_client_id(id: &str, mode: &str) -> String<64> { let mut identifier = String::new(); write!(&mut identifier, "{id}-{mode}").unwrap(); identifier