Add start return result to show periods per DFT in GUI.

This commit is contained in:
2025-10-07 13:01:16 +02:00
parent 42c5dd4cc2
commit 4325bbadeb
2 changed files with 59 additions and 15 deletions

View File

@@ -4,7 +4,8 @@ version = "0.1.0"
edition = "2024" edition = "2024"
[dependencies] [dependencies]
postcard-rpc = { version = "0.11.12" } postcard-rpc = { version = "0.11.15" }
heapless = { version = "0.9.0", features = ["serde"] }
[dependencies.serde] [dependencies.serde]
version = "1.0.219" version = "1.0.219"
@@ -12,8 +13,8 @@ features = ["derive"]
default-features = false default-features = false
[dependencies.postcard-schema] [dependencies.postcard-schema]
version = "0.2.4" version = "0.2.5"
features = ["derive"] features = ["derive", "heapless-v0_9"]
[features] [features]
use-std = [] use-std = []

View File

@@ -3,19 +3,29 @@
use postcard_rpc::{endpoints, topics, TopicDirection}; use postcard_rpc::{endpoints, topics, TopicDirection};
use postcard_schema::Schema; use postcard_schema::Schema;
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use heapless::Vec;
// --- // ---
#[derive(Serialize, Deserialize, Schema, Debug, PartialEq)]
pub enum InitImpedanceError {
DSPNotSet,
}
pub type InitImpedanceResult = Result<f32, InitImpedanceError>;
endpoints! { endpoints! {
list = ENDPOINT_LIST; list = ENDPOINT_LIST;
omit_std = true; omit_std = true;
| EndpointTy | RequestTy | ResponseTy | Path | | EndpointTy | RequestTy | ResponseTy | Path |
| ---------- | --------- | ---------- | ---- | | ---------- | --------- | ---------- | ---- |
| PingEndpoint | u32 | u32 | "ping" | | PingEndpoint | u32 | u32 | "ping" |
| GetUniqueIdEndpoint | () | [u8; 12] | "get_id" | | GetUniqueIdEndpoint | () | [u8; 12] | "get_id" |
| SetGreenLedEndpoint | f32 | () | "led/green" | | SetGreenLedEndpoint | f32 | () | "led/green" |
| StartImpedanceEndpoint | StartImpedance | () | "imp/start" | | StartSingleImpedanceEndpoint | StartSingleImpedance | InitImpedanceResult | "imp/start_single" |
| StopImpedanceEndpoint | () | bool | "imp/stop" | | StopSingleImpedanceEndpoint | () | bool | "imp/stop_single" |
| StartMultiImpedanceEndpoint | StartMultiImpedance | () | "imp/start_multi" |
| StopMultiImpedanceEndpoint | () | bool | "imp/stop_multi" |
} }
topics! { topics! {
@@ -28,17 +38,24 @@ topics! {
topics! { topics! {
list = TOPICS_OUT_LIST; list = TOPICS_OUT_LIST;
direction = TopicDirection::ToClient; direction = TopicDirection::ToClient;
| TopicTy | MessageTy | Path | Cfg | | TopicTy | MessageTy | Path | Cfg |
| ------- | --------- | ---- | --- | | ------- | --------- | ---- | --- |
| ImpedanceOutputTopic | ImpedanceOutput | "imp/data" | | | SingleImpedanceOutputTopic | SingleImpedanceOutput | "imp/single" | |
| MultiImpedanceOutputTopic28 | MultiImpedanceOutput28 | "imp/multi" | |
} }
#[derive(Serialize, Deserialize, Schema, Debug, PartialEq)] #[derive(Serialize, Deserialize, Schema, Debug, PartialEq)]
pub struct ImpedanceOutput { pub struct SingleImpedanceOutput {
pub magnitude: f32, pub magnitude: f32,
pub phase: f32, pub phase: f32,
} }
#[derive(Serialize, Deserialize, Schema, Debug, PartialEq)]
pub struct MultiImpedanceOutput28 {
pub magnitudes: Vec<f32, 28>,
pub phases: Vec<f32, 28>,
}
#[derive(Clone, Copy, Serialize, Deserialize, Schema, Debug, PartialEq)] #[derive(Clone, Copy, Serialize, Deserialize, Schema, Debug, PartialEq)]
pub enum IcdDftNum { pub enum IcdDftNum {
Num4, Num4,
@@ -57,8 +74,34 @@ pub enum IcdDftNum {
} }
#[derive(Serialize, Deserialize, Schema, Debug, PartialEq)] #[derive(Serialize, Deserialize, Schema, Debug, PartialEq)]
pub struct StartImpedance { pub struct StartSingleImpedance {
pub update_frequency: u32, pub update_frequency: u32,
pub sinus_frequency: u32, pub sinus_frequency: u32,
pub dft_number: IcdDftNum, 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,
}