From 84eea817ac6f36712b32f1201c5baa1b8b65053c Mon Sep 17 00:00:00 2001 From: Ryan Summers Date: Mon, 4 Jan 2021 15:15:15 +0100 Subject: [PATCH 1/5] Updating documentation, refactoring reflected power interlock threshold --- .github/workflows/ci.yml | 31 +++++++++-- README.md | 27 ++++++++-- booster.py | 19 +++---- src/mqtt_control.rs | 17 +++--- src/platform.rs | 4 ++ src/rf_channel.rs | 88 ++++++++++++-------------------- src/settings/channel_settings.rs | 2 - 7 files changed, 104 insertions(+), 84 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 1a25d991..833042fa 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -52,27 +52,52 @@ jobs: - beta steps: - uses: actions/checkout@v2 + - name: Install Rust ${{ matrix.toolchain }} uses: actions-rs/toolchain@v1 with: toolchain: ${{ matrix.toolchain }} target: thumbv7em-none-eabihf override: true - - name: cargo check + components: llvm-tools-preview + + - name: Install Binutils + uses: actions-rs/cargo@v1 + with: + command: install + args: cargo-binutils + + - name: Style Check uses: actions-rs/cargo@v1 with: command: check args: --verbose - - name: cargo build + + - name: Build [Debug] uses: actions-rs/cargo@v1 with: command: build - - name: cargo build release + + - name: Build [Release] uses: actions-rs/cargo@v1 with: command: build args: --release + - name: Generate Release + uses: actions-rs/cargo@v1 + with: + command: objcopy + args: --release --verbose -- -O binary booster-release.bin + + - name: Upload Release + if: ${{ matrix.toolchain == 'stable' }} + with: + name: Firmware Images + path: | + target/*/release/booster + booster-release.bin + compile-unstable: runs-on: ubuntu-latest steps: diff --git a/README.md b/README.md index b6b19458..0738f398 100644 --- a/README.md +++ b/README.md @@ -105,7 +105,12 @@ Additionally, the USB port allows the user to: * Reset booster * Enter DFU mode for upgrading firmware -## Ethernet +## Booster Units + +Booster uses SI units for all telemetry messages and properties, with the exception of power +measurements. All power measurements are instead specified in dBm. + +## Ethernet Telemetry and Control Booster uses MQTT for telemetry and control of RF channels. All booster MQTT topics are prefixed with the booster ID, which defaults to a combination of `booster` and the MAC address of the device. @@ -127,6 +132,18 @@ property is provided, Booster will respond by default to `/log`. For a reference implementation of the API to control booster over MQTT, refer to `booster.py` +**Note**: When using mosquitto, the channel telemetry can be read using: +``` +mosquitto_sub -h mqtt -t '/ch' +``` +Note in the above that is an integer between 0 and 7 (inclusive). is as specified above. + +### Booster Properties + +Throughout the code, any reference to a "Property" refers to a value that is configurable by the +user. Telemetry outputs, such as temperature or power measurements, are not considered to be +properties of Booster. + ### Special Note on Booster properties When reading or writing Booster properties of `/channel/read` or `/channel/write`, the @@ -214,7 +231,11 @@ the channel when Booster boots. Note that saving channel settings overwrites any **Prerequisites** * Ensure `dfu-util` is installed. On Ubuntu, install it from `apt` using `sudo apt-get install dfu-util` -* If building your own firmware, install `cargo-binutils`: `cargo install cargo-binutils` +* If building your own firmware, [`cargo-binutils`](https://github.com/rust-embedded/cargo-binutils#installation)) must be installed: +``` +cargo install cargo-binutils +rustup component add llvm-tools-preview +``` The following instructions describe the process of uploading a new firmware image over the DFU Bootloader USB interface. @@ -224,7 +245,7 @@ Bootloader USB interface. - Note: You may also use the latest [pre-built](https://github.com/quartiq/booster/releases) assets instead of building firmware. 1. Generate the binary file for your firmware build: `cargo objcopy -- -O binary booster.bin` - - Note: If you built with `--release`, replace `debug` with `release` in the above command. + - Note: If you built with `--release`, use the commmand: `cargo objcopy --release -- -O binary booster.bin` 1. Reset Booster into DFU mode: - Insert a pin into the DFU Bootloader hole to press the DFU button diff --git a/booster.py b/booster.py index 3ede0e6b..e8d5e30f 100644 --- a/booster.py +++ b/booster.py @@ -25,7 +25,7 @@ class PropertyId(enum.Enum): """ Represents a property ID for Booster RF channels. """ - InterlockThresholds = 'InterlockThresholds' + OutputInterlockThreshold = 'OutputInterlockThreshold' OutputPowerTransform = 'OutputPowerTransform' InputPowerTransform = 'InputPowerTransform' ReflectedPowerTransform = 'ReflectedPowerTransform' @@ -273,14 +273,11 @@ async def channel_configuration(args): await interface.enable_channel(args.channel) print(f'Channel {args.channel} enabled') - if args.thresholds: - thresholds = { - 'output': args.thresholds[0], - 'reflected': args.thresholds[1], - } - await interface.write_property(args.channel, PropertyId.InterlockThresholds, thresholds) - print(f'Channel {args.channel}: Output power threshold = {args.thresholds[0]} dBm, ' - f'Reflected power interlock threshold = {args.thresholds[1]} dBm') + if args.threshold: + await interface.write_property(args.channel, + PropertyId.OutputInterlockThreshold, + args.threshold) + print(f'Channel {args.channel}: Output power threshold = {args.threshold} dBm') if args.bias: vgs, ids = await interface.set_bias(args.channel, args.bias) @@ -317,9 +314,7 @@ def main(): help='Tune the RF channel bias current to the provided value') parser.add_argument('--enable', action='store_true', help='Enable the RF channel') parser.add_argument('--disable', action='store_true', help='Disable the RF channel') - parser.add_argument('--thresholds', type=float, nargs=2, - help='The interlock thresholds in the following order: ' - ' ') + parser.add_argument('--threshold', type=float, help='The output interlock threshold') parser.add_argument('--save', action='store_true', help='Save the RF channel configuration') loop = asyncio.get_event_loop() diff --git a/src/mqtt_control.rs b/src/mqtt_control.rs index 58e1ff9c..eef620a5 100644 --- a/src/mqtt_control.rs +++ b/src/mqtt_control.rs @@ -10,9 +10,7 @@ use embedded_hal::blocking::delay::DelayUs; use heapless::{consts, String}; use minimq::{Property, QoS}; -use crate::rf_channel::{ - InterlockThresholds, Property as ChannelProperty, PropertyId as ChannelPropertyId, -}; +use crate::rf_channel::{Property as ChannelProperty, PropertyId as ChannelPropertyId}; use crate::linear_transformation::LinearTransformation; @@ -37,8 +35,8 @@ impl PropertyReadResponse { pub fn okay(prop: ChannelProperty) -> String { // Serialize the property. let data: String = match prop { - ChannelProperty::InterlockThresholds(thresholds) => { - serde_json_core::to_string(&thresholds).unwrap() + ChannelProperty::OutputInterlockThreshold(threshold) => { + serde_json_core::to_string(&threshold).unwrap() } ChannelProperty::InputPowerTransform(transform) => { serde_json_core::to_string(&transform).unwrap() @@ -95,10 +93,11 @@ impl PropertyWriteRequest { // Convert the property let prop = match self.prop { - ChannelPropertyId::InterlockThresholds => ChannelProperty::InterlockThresholds( - serde_json_core::from_str::(&data) - .map_err(|_| Error::Invalid)?, - ), + ChannelPropertyId::OutputInterlockThreshold => { + ChannelProperty::OutputInterlockThreshold( + serde_json_core::from_str::(&data).map_err(|_| Error::Invalid)?, + ) + } ChannelPropertyId::OutputPowerTransform => ChannelProperty::OutputPowerTransform( serde_json_core::from_str::(&data) .map_err(|_| Error::Invalid)?, diff --git a/src/platform.rs b/src/platform.rs index ec73d37b..8afa6a18 100644 --- a/src/platform.rs +++ b/src/platform.rs @@ -8,6 +8,10 @@ use super::hal; use embedded_hal::{blocking::delay::DelayUs, digital::v2::OutputPin}; +// Booster hardware channels are capable of withstanding up to 1W of reflected RF power. This +// corresponds with a value of 30 dBm. +pub const MAXIMUM_REFLECTED_POWER_DBM: f32 = 30.0; + #[panic_handler] fn panic(_info: &core::panic::PanicInfo) -> ! { cortex_m::interrupt::disable(); diff --git a/src/rf_channel.rs b/src/rf_channel.rs index e2510db5..2badc29a 100644 --- a/src/rf_channel.rs +++ b/src/rf_channel.rs @@ -25,17 +25,10 @@ use stm32f4xx_hal::{ use rtic::cyccnt::{Duration, Instant}; -#[derive(serde::Deserialize, serde::Serialize)] -/// Represents the interlock threshold levels. -pub struct InterlockThresholds { - pub output: f32, - pub reflected: f32, -} - #[derive(serde::Deserialize, serde::Serialize)] /// Used to identify a specific channel property. pub enum PropertyId { - InterlockThresholds, + OutputInterlockThreshold, OutputPowerTransform, InputPowerTransform, ReflectedPowerTransform, @@ -43,7 +36,7 @@ pub enum PropertyId { /// Represents an operation property of an RF channel. pub enum Property { - InterlockThresholds(InterlockThresholds), + OutputInterlockThreshold(f32), OutputPowerTransform(LinearTransformation), InputPowerTransform(LinearTransformation), ReflectedPowerTransform(LinearTransformation), @@ -514,12 +507,17 @@ impl RfChannel { }; channel - .set_interlock_thresholds( + .set_output_interlock_threshold( channel.settings.data.output_interlock_threshold, - channel.settings.data.reflected_interlock_threshold, ) .unwrap(); + // The reflected power interlock threshold is always configured to 30 dBm (1W + // reflected power) to protect Booster hardware. + channel + .set_reflected_interlock_threshold(platform::MAXIMUM_REFLECTED_POWER_DBM) + .unwrap(); + // If the channel configuration specifies the channel as enabled, power up the // channel now. if channel.settings.data.enabled && platform::watchdog_detected() == false { @@ -543,44 +541,35 @@ impl RfChannel { /// Set the interlock thresholds for the channel. /// /// # Args - /// * `output_power` - The dBm interlock threshold to configure for the output power. - /// * `reflected_power` - The dBm interlock threshold to configure for reflected power. - pub fn set_interlock_thresholds( - &mut self, - output_power: f32, - reflected_power: f32, - ) -> Result<(), Error> { + /// * `power` - The dBm interlock threshold to configure for reflected power. + fn set_reflected_interlock_threshold(&mut self, power: f32) -> Result<(), Error> { match self.i2c_devices.interlock_thresholds_dac.set_voltage( - self.settings - .data - .reflected_power_transform - .invert(reflected_power), + self.settings.data.reflected_power_transform.invert(power), ad5627::Dac::A, ) { - Err(ad5627::Error::Range) => return Err(Error::Bounds), - Err(ad5627::Error::I2c(_)) => return Err(Error::Interface), - Ok(voltage) => { - self.settings.data.reflected_interlock_threshold = - self.settings.data.reflected_power_transform.map(voltage); - } + Err(ad5627::Error::Range) => Err(Error::Bounds), + Err(ad5627::Error::I2c(_)) => Err(Error::Interface), + Ok(_) => Ok(()), } + } + /// Set the output interlock threshold for the channel. + /// + /// # Args + /// * `power` - The dBm interlock threshold to configure for the output power. + pub fn set_output_interlock_threshold(&mut self, power: f32) -> Result<(), Error> { match self.i2c_devices.interlock_thresholds_dac.set_voltage( - self.settings - .data - .output_power_transform - .invert(output_power), + self.settings.data.output_power_transform.invert(power), ad5627::Dac::B, ) { - Err(ad5627::Error::Range) => return Err(Error::Bounds), - Err(ad5627::Error::I2c(_)) => return Err(Error::Interface), + Err(ad5627::Error::Range) => Err(Error::Bounds), + Err(ad5627::Error::I2c(_)) => Err(Error::Interface), Ok(voltage) => { self.settings.data.output_interlock_threshold = self.settings.data.output_power_transform.map(voltage); + Ok(()) } } - - Ok(()) } fn check_faults(&mut self) -> Option { @@ -745,10 +734,8 @@ impl RfChannel { // As a workaround, we need to ensure that the interlock level is above the output power // detector level. When RF is disabled, the power detectors output a near-zero value, so // 100mV should be a sufficient level. - if (self.settings.data.reflected_interlock_threshold - < self.settings.data.reflected_power_transform.map(0.100)) - || (self.settings.data.output_interlock_threshold - < self.settings.data.output_power_transform.map(0.100)) + if self.settings.data.output_interlock_threshold + < self.settings.data.output_power_transform.map(0.100) { self.start_disable(); return Err(Error::Invalid); @@ -947,14 +934,6 @@ impl RfChannel { self.settings.data.output_interlock_threshold } - /// Get the current reflected power interlock threshold. - /// - /// # Returns - /// The current reflected interlock threshold in dBm. - pub fn get_reflected_interlock_threshold(&self) -> f32 { - self.settings.data.reflected_interlock_threshold - } - /// Get the current bias voltage programmed to the RF amplification transistor. pub fn get_bias_voltage(&self) -> f32 { self.settings.data.bias_voltage @@ -975,7 +954,7 @@ impl RfChannel { input_power: self.get_input_power(), output_power: self.get_output_power(adc), reflected_power: self.get_reflected_power(adc), - reflected_overdrive_threshold: self.get_reflected_interlock_threshold(), + reflected_overdrive_threshold: platform::MAXIMUM_REFLECTED_POWER_DBM, output_overdrive_threshold: self.get_output_interlock_threshold(), bias_voltage: self.get_bias_voltage(), state: self.get_state(), @@ -995,8 +974,8 @@ impl RfChannel { /// * `property` - The property to configure on the channel. pub fn set_property(&mut self, property: Property) -> Result<(), Error> { match property { - Property::InterlockThresholds(InterlockThresholds { output, reflected }) => { - self.set_interlock_thresholds(output, reflected)?; + Property::OutputInterlockThreshold(output) => { + self.set_output_interlock_threshold(output)?; } Property::OutputPowerTransform(transform) => { self.settings.data.output_power_transform = transform; @@ -1021,10 +1000,9 @@ impl RfChannel { /// The current channel property. pub fn get_property(&self, property: PropertyId) -> Property { match property { - PropertyId::InterlockThresholds => Property::InterlockThresholds(InterlockThresholds { - output: self.settings.data.output_interlock_threshold, - reflected: self.settings.data.reflected_interlock_threshold, - }), + PropertyId::OutputInterlockThreshold => { + Property::OutputInterlockThreshold(self.settings.data.output_interlock_threshold) + } PropertyId::OutputPowerTransform => { Property::OutputPowerTransform(self.settings.data.output_power_transform.clone()) } diff --git a/src/settings/channel_settings.rs b/src/settings/channel_settings.rs index e87e2144..727de66e 100644 --- a/src/settings/channel_settings.rs +++ b/src/settings/channel_settings.rs @@ -12,7 +12,6 @@ use microchip_24aa02e48::Microchip24AA02E48; /// Represents booster channel-specific configuration values. #[derive(serde::Serialize, serde::Deserialize)] pub struct BoosterChannelData { - pub reflected_interlock_threshold: f32, pub output_interlock_threshold: f32, pub bias_voltage: f32, pub enabled: bool, @@ -25,7 +24,6 @@ impl BoosterChannelData { /// Generate default booster channel data. pub fn default() -> Self { Self { - reflected_interlock_threshold: 0.0, output_interlock_threshold: 0.0, bias_voltage: -3.2, enabled: false, From 7f97d486446cf94491cca7f06d768fc8cb95690a Mon Sep 17 00:00:00 2001 From: Ryan Summers Date: Mon, 4 Jan 2021 15:21:18 +0100 Subject: [PATCH 2/5] Updating archive for develop and master only --- .github/workflows/ci.yml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 833042fa..f2282fd4 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -91,7 +91,9 @@ jobs: args: --release --verbose -- -O binary booster-release.bin - name: Upload Release - if: ${{ matrix.toolchain == 'stable' }} + if: ${{ matrix.toolchain == 'stable' }} && + (${{ github.ref == 'refs/heads/master' }} || + ${{ github.ref == 'refs/heads/develop' }}) with: name: Firmware Images path: | From 3e6aa25e24660b968c891a41768b60fdf809636f Mon Sep 17 00:00:00 2001 From: Ryan Summers Date: Mon, 4 Jan 2021 15:24:42 +0100 Subject: [PATCH 3/5] Addign upload-artifact use --- .github/workflows/ci.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index f2282fd4..b5c04a68 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -91,6 +91,7 @@ jobs: args: --release --verbose -- -O binary booster-release.bin - name: Upload Release + uses: actions/upload-artifact@v2 if: ${{ matrix.toolchain == 'stable' }} && (${{ github.ref == 'refs/heads/master' }} || ${{ github.ref == 'refs/heads/develop' }}) From 8f6be952a9185df41b6c9d4398e622692fcd55d3 Mon Sep 17 00:00:00 2001 From: Ryan Summers Date: Mon, 4 Jan 2021 15:52:53 +0100 Subject: [PATCH 4/5] Apply suggestions from code review MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Robert Jördens --- README.md | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 0738f398..1aace696 100644 --- a/README.md +++ b/README.md @@ -107,8 +107,7 @@ Additionally, the USB port allows the user to: ## Booster Units -Booster uses SI units for all telemetry messages and properties, with the exception of power -measurements. All power measurements are instead specified in dBm. +Booster uses SI units (Volt, Ampere, Celsius) for telemetry messages and properties. Power measurements are specified in dBm. ## Ethernet Telemetry and Control @@ -134,7 +133,7 @@ For a reference implementation of the API to control booster over MQTT, refer to **Note**: When using mosquitto, the channel telemetry can be read using: ``` -mosquitto_sub -h mqtt -t '/ch' +mosquitto_sub -h mqtt -v -t /ch ``` Note in the above that is an integer between 0 and 7 (inclusive). is as specified above. From daf359fc70afdf61704ac3a7591caa7f3f277917 Mon Sep 17 00:00:00 2001 From: Ryan Summers Date: Tue, 5 Jan 2021 19:48:24 +0100 Subject: [PATCH 5/5] Updating after testing --- Cargo.lock | 4 +-- Cargo.toml | 2 +- booster.py | 10 +++--- src/mqtt_control.rs | 58 +++++++++++++------------------- src/settings/channel_settings.rs | 2 +- 5 files changed, 33 insertions(+), 43 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 01ad1e43..9b0c28ae 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -581,9 +581,9 @@ dependencies = [ [[package]] name = "serde-json-core" -version = "0.1.0" +version = "0.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cbf406405ada9ef326ca78677324ac66994ff348fc48a16030be08caeed29825" +checksum = "89fd6016a00149b485f66da701f76d909210d319040c97b6eff300f6e2ba2153" dependencies = [ "heapless", "serde", diff --git a/Cargo.toml b/Cargo.toml index c85b1b1f..66ecc22e 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -17,7 +17,7 @@ heapless = { version = "0.5.5", features = ["serde"] } bit_field = "0.10.0" debounced-pin = "0.3.0" serde = {version = "1.0", features = ["derive"], default-features = false } -serde-json-core = "0.1" +serde-json-core = "0.2" logos = { version = "0.11.4", default-features = false, features = ["export_derive"] } bbqueue = "0.4.10" usbd-serial = "0.1.0" diff --git a/booster.py b/booster.py index e8d5e30f..44847376 100644 --- a/booster.py +++ b/booster.py @@ -166,7 +166,7 @@ async def read_property(self, channel, prop): request = generate_request(prop=prop.value, channel=CHANNEL[channel]) response = await self.command("channel/read", request) - return json.loads(response['data'].replace("'", '"')) + return json.loads(response['data']) async def write_property(self, channel, prop_id, value): @@ -178,7 +178,7 @@ async def write_property(self, channel, prop_id, value): value: The value to write to the property. """ request = generate_request(prop=prop_id.value, channel=CHANNEL[channel], - data=json.dumps(value).replace('"', "'")) + data=json.dumps(value)) await self.command("channel/write", request) @@ -273,17 +273,17 @@ async def channel_configuration(args): await interface.enable_channel(args.channel) print(f'Channel {args.channel} enabled') - if args.threshold: + if args.threshold is not None: await interface.write_property(args.channel, PropertyId.OutputInterlockThreshold, args.threshold) print(f'Channel {args.channel}: Output power threshold = {args.threshold} dBm') - if args.bias: + if args.bias is not None: vgs, ids = await interface.set_bias(args.channel, args.bias) print(f'Channel {args.channel}: Vgs = {vgs:.3f} V, Ids = {ids * 1000:.2f} mA') - if args.tune: + if args.tune is not None: vgs, ids = await interface.tune_bias(args.channel, args.tune) print(f'Channel {args.channel}: Vgs = {vgs:.3f} V, Ids = {ids * 1000:.2f} mA') diff --git a/src/mqtt_control.rs b/src/mqtt_control.rs index eef620a5..83ffcdfb 100644 --- a/src/mqtt_control.rs +++ b/src/mqtt_control.rs @@ -49,21 +49,11 @@ impl PropertyReadResponse { } }; - let mut response = Self { + let response = Self { code: 200, - data: String::new(), + data: String::from(data.as_str()), }; - // Convert double quotes to single in the encoded property. This gets around string escape - // sequences. - for byte in data.as_str().chars() { - if byte == '"' { - response.data.push('\'').unwrap(); - } else { - response.data.push(byte).unwrap(); - } - } - serde_json_core::to_string(&response).unwrap() } } @@ -81,34 +71,34 @@ impl PropertyWriteRequest { /// # Returns /// The property if it could be deserialized. Otherwise, an error is returned. pub fn property(&self) -> Result { - // Convert single quotes to double in the property data. - let mut data: String = String::new(); - for byte in self.data.as_str().chars() { - if byte == '\'' { - data.push('"').unwrap(); - } else { - data.push(byte).unwrap(); - } - } - // Convert the property let prop = match self.prop { ChannelPropertyId::OutputInterlockThreshold => { + // Due to a bug in serde-json-core, trailing data must be present for a float to be + // properly parsed. For more information, refer to: + // https://github.com/rust-embedded-community/serde-json-core/issues/47 + let mut data: String = String::from(self.data.as_str()); + data.push(' ').unwrap(); ChannelProperty::OutputInterlockThreshold( - serde_json_core::from_str::(&data).map_err(|_| Error::Invalid)?, + serde_json_core::from_str::(&data) + .map_err(|_| Error::Invalid)? + .0, ) } ChannelPropertyId::OutputPowerTransform => ChannelProperty::OutputPowerTransform( - serde_json_core::from_str::(&data) - .map_err(|_| Error::Invalid)?, + serde_json_core::from_str::(&self.data) + .map_err(|_| Error::Invalid)? + .0, ), ChannelPropertyId::InputPowerTransform => ChannelProperty::InputPowerTransform( - serde_json_core::from_str::(&data) - .map_err(|_| Error::Invalid)?, + serde_json_core::from_str::(&self.data) + .map_err(|_| Error::Invalid)? + .0, ), ChannelPropertyId::ReflectedPowerTransform => ChannelProperty::ReflectedPowerTransform( - serde_json_core::from_str::(&data) - .map_err(|_| Error::Invalid)?, + serde_json_core::from_str::(&self.data) + .map_err(|_| Error::Invalid)? + .0, ), }; @@ -330,7 +320,7 @@ impl ControlState { /// A String response indicating the result of the request. fn handle_channel_update(message: &[u8], channels: &mut BoosterChannels) -> String { let request = match serde_json_core::from_slice::(message) { - Ok(data) => data, + Ok((data, _)) => data, Err(_) => return Response::error_msg("Failed to decode data"), }; channels @@ -368,7 +358,7 @@ fn handle_channel_property_read( channels: &mut BoosterChannels, ) -> String { let request = match serde_json_core::from_slice::(message) { - Ok(data) => data, + Ok((data, _)) => data, Err(_) => return Response::error_msg("Failed to decode read request"), }; @@ -391,8 +381,8 @@ fn handle_channel_property_write( channels: &mut BoosterChannels, ) -> String { let request = match serde_json_core::from_slice::(message) { - Ok(data) => data, - Err(_) => return Response::error_msg("Failed to decode read request"), + Ok((data, _)) => data, + Err(_) => return Response::error_msg("Failed to decode write request"), }; let property = match request.property() { @@ -421,7 +411,7 @@ fn handle_channel_bias( delay: &mut impl DelayUs, ) -> String { let request = match serde_json_core::from_slice::(message) { - Ok(data) => data, + Ok((data, _)) => data, Err(_) => return Response::error_msg("Failed to decode data"), }; diff --git a/src/settings/channel_settings.rs b/src/settings/channel_settings.rs index 727de66e..a5a15f45 100644 --- a/src/settings/channel_settings.rs +++ b/src/settings/channel_settings.rs @@ -56,7 +56,7 @@ impl BoosterChannelData { /// # Returns /// The configuration if deserialization was successful. Otherwise, returns an error. pub fn deserialize(data: &[u8; 64]) -> Result { - let config: BoosterChannelData = postcard::from_bytes(data).unwrap(); + let config: BoosterChannelData = postcard::from_bytes(data).or(Err(Error::Invalid))?; // Validate configuration parameters. if config.bias_voltage < -3.3 || config.bias_voltage > 0.0 {