From 799bcf49b584eedd1e281ef07c242a24d02488f2 Mon Sep 17 00:00:00 2001 From: Hubald Verzijl Date: Wed, 8 Oct 2025 15:41:41 +0200 Subject: [PATCH] Included bode plot measurements, including different number of points. --- src/lib.rs | 65 ++++++++++++++++++++++++++++++++++++++---------------- 1 file changed, 46 insertions(+), 19 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index dba4d4a..cdb6fb0 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -8,11 +8,13 @@ use heapless::Vec; // --- #[derive(Serialize, Deserialize, Schema, Debug, PartialEq)] -pub enum InitImpedanceError { +pub enum ImpedanceInitError { DSPNotSet, } -pub type InitImpedanceResult = Result; +pub type ImpedanceInitResult = Result; + +pub type MultiImpedanceInitResult = Result; endpoints! { list = ENDPOINT_LIST; @@ -22,9 +24,9 @@ endpoints! { | PingEndpoint | u32 | u32 | "ping" | | GetUniqueIdEndpoint | () | [u8; 12] | "get_id" | | SetGreenLedEndpoint | f32 | () | "led/green" | - | StartSingleImpedanceEndpoint | StartSingleImpedance | InitImpedanceResult | "imp/start_single" | + | StartSingleImpedanceEndpoint | SingleImpedanceStartRequest | ImpedanceInitResult | "imp/start_single" | | StopSingleImpedanceEndpoint | () | bool | "imp/stop_single" | - | StartMultiImpedanceEndpoint | StartMultiImpedance | () | "imp/start_multi" | + | StartMultiImpedanceEndpoint | MultiImpedanceStartRequest | MultiImpedanceInitResult | "imp/start_multi" | | StopMultiImpedanceEndpoint | () | bool | "imp/stop_multi" | } @@ -36,12 +38,13 @@ topics! { } topics! { + list = TOPICS_OUT_LIST; direction = TopicDirection::ToClient; | TopicTy | MessageTy | Path | Cfg | | ------- | --------- | ---- | --- | | SingleImpedanceOutputTopic | SingleImpedanceOutput | "imp/single" | | - | MultiImpedanceOutputTopic28 | MultiImpedanceOutput28 | "imp/multi" | | + | MultiImpedanceOutputTopic | MultiImpedanceOutput | "imp/multi" | | } #[derive(Serialize, Deserialize, Schema, Debug, PartialEq)] @@ -51,9 +54,25 @@ pub struct SingleImpedanceOutput { } #[derive(Serialize, Deserialize, Schema, Debug, PartialEq)] -pub struct MultiImpedanceOutput28 { - pub magnitudes: Vec, - pub phases: Vec, +pub struct MultiImpedanceOutput { + pub points: MeasurementPointSet, + pub magnitudes_8: Vec, + pub phases_8: Vec, + pub magnitudes_18: Vec, + pub phases_18: Vec, +} + +#[derive(Serialize, Deserialize, Schema, Debug, PartialEq)] +pub struct MultiImpedanceOutput18 { + pub magnitudes: Vec, + pub phases: Vec, +} + +#[derive(Serialize, Deserialize, Schema, Debug, PartialEq)] +pub struct MultiImpedanceResult { + pub points: MeasurementPointSet, + pub periods_per_dft_8: Vec, + pub periods_per_dft_18: Vec, } #[derive(Clone, Copy, Serialize, Deserialize, Schema, Debug, PartialEq)] @@ -74,34 +93,42 @@ pub enum IcdDftNum { } #[derive(Serialize, Deserialize, Schema, Debug, PartialEq)] -pub struct StartSingleImpedance { +pub struct SingleImpedanceStartRequest { pub update_frequency: u32, pub sinus_frequency: u32, pub dft_number: IcdDftNum, } #[derive(Clone, Copy, Serialize, Deserialize, Schema, Debug, PartialEq)] -pub enum NumberOfPoints { - TwentyEight, +pub enum MeasurementPointSet { + Eight, + Eighteen, } -impl NumberOfPoints { +impl MeasurementPointSet { pub fn values(&self) -> &'static [f32] { match self { - NumberOfPoints::TwentyEight => { - &[1.0, 1.6, 2.5, 4.0, 6.3, - 10.0, 16.0, 25.0, 40.0, 63.0, - 100.0, 160.0, 250.0, 400.0, 630.0, + MeasurementPointSet::Eight => { + &[10000.0, 16000.0, 25000.0, 40000.0, 63000.0, + 100000.0, 160000.0, 200000.0] + } + MeasurementPointSet::Eighteen => { + &[100.0, 160.0, 250.0, 400.0, 630.0, 1000.0, 1600.0, 2500.0, 4000.0, 6300.0, 10000.0, 16000.0, 25000.0, 40000.0, 63000.0, 100000.0, 160000.0, 200000.0] } } } + pub fn len(&self) -> usize { + match self { + MeasurementPointSet::Eight => 8, + MeasurementPointSet::Eighteen => 18, + } + } } #[derive(Serialize, Deserialize, Schema, Debug, PartialEq)] -pub struct StartMultiImpedance { - pub dft_number: IcdDftNum, - pub number_of_points: NumberOfPoints, +pub struct MultiImpedanceStartRequest { + pub points: MeasurementPointSet, }