diff --git a/Cargo.toml b/Cargo.toml index 1c3de80..8602951 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -4,7 +4,8 @@ version = "0.1.0" edition = "2024" [dependencies] -postcard-rpc = { version = "0.11.12" } +postcard-rpc = { version = "0.11.15" } +heapless = { version = "0.9.0", features = ["serde"] } [dependencies.serde] version = "1.0.219" @@ -12,8 +13,8 @@ features = ["derive"] default-features = false [dependencies.postcard-schema] -version = "0.2.4" -features = ["derive"] +version = "0.2.5" +features = ["derive", "heapless-v0_9"] [features] use-std = [] diff --git a/src/lib.rs b/src/lib.rs index 6875422..dba4d4a 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -3,19 +3,29 @@ use postcard_rpc::{endpoints, topics, TopicDirection}; use postcard_schema::Schema; use serde::{Deserialize, Serialize}; +use heapless::Vec; // --- +#[derive(Serialize, Deserialize, Schema, Debug, PartialEq)] +pub enum InitImpedanceError { + DSPNotSet, +} + +pub type InitImpedanceResult = Result; + endpoints! { list = ENDPOINT_LIST; omit_std = true; - | EndpointTy | RequestTy | ResponseTy | Path | - | ---------- | --------- | ---------- | ---- | - | PingEndpoint | u32 | u32 | "ping" | - | GetUniqueIdEndpoint | () | [u8; 12] | "get_id" | - | SetGreenLedEndpoint | f32 | () | "led/green" | - | StartImpedanceEndpoint | StartImpedance | () | "imp/start" | - | StopImpedanceEndpoint | () | bool | "imp/stop" | + | EndpointTy | RequestTy | ResponseTy | Path | + | ---------- | --------- | ---------- | ---- | + | PingEndpoint | u32 | u32 | "ping" | + | GetUniqueIdEndpoint | () | [u8; 12] | "get_id" | + | SetGreenLedEndpoint | f32 | () | "led/green" | + | StartSingleImpedanceEndpoint | StartSingleImpedance | InitImpedanceResult | "imp/start_single" | + | StopSingleImpedanceEndpoint | () | bool | "imp/stop_single" | + | StartMultiImpedanceEndpoint | StartMultiImpedance | () | "imp/start_multi" | + | StopMultiImpedanceEndpoint | () | bool | "imp/stop_multi" | } topics! { @@ -28,17 +38,24 @@ topics! { topics! { list = TOPICS_OUT_LIST; direction = TopicDirection::ToClient; - | TopicTy | MessageTy | Path | Cfg | - | ------- | --------- | ---- | --- | - | ImpedanceOutputTopic | ImpedanceOutput | "imp/data" | | + | TopicTy | MessageTy | Path | Cfg | + | ------- | --------- | ---- | --- | + | SingleImpedanceOutputTopic | SingleImpedanceOutput | "imp/single" | | + | MultiImpedanceOutputTopic28 | MultiImpedanceOutput28 | "imp/multi" | | } #[derive(Serialize, Deserialize, Schema, Debug, PartialEq)] -pub struct ImpedanceOutput { +pub struct SingleImpedanceOutput { pub magnitude: f32, pub phase: f32, } +#[derive(Serialize, Deserialize, Schema, Debug, PartialEq)] +pub struct MultiImpedanceOutput28 { + pub magnitudes: Vec, + pub phases: Vec, +} + #[derive(Clone, Copy, Serialize, Deserialize, Schema, Debug, PartialEq)] pub enum IcdDftNum { Num4, @@ -57,8 +74,34 @@ pub enum IcdDftNum { } #[derive(Serialize, Deserialize, Schema, Debug, PartialEq)] -pub struct StartImpedance { +pub struct StartSingleImpedance { pub update_frequency: u32, pub sinus_frequency: u32, pub dft_number: IcdDftNum, } + +#[derive(Clone, Copy, Serialize, Deserialize, Schema, Debug, PartialEq)] +pub enum NumberOfPoints { + TwentyEight, +} + +impl NumberOfPoints { + 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, + 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] + } + } + } +} + +#[derive(Serialize, Deserialize, Schema, Debug, PartialEq)] +pub struct StartMultiImpedance { + pub dft_number: IcdDftNum, + pub number_of_points: NumberOfPoints, +}