mirror of
https://github.com/hubaldv/bioz-host-rs.git
synced 2025-12-06 05:11:17 +00:00
Included bode plot measurements, including different number of points.
This commit is contained in:
144
Cargo.lock
generated
144
Cargo.lock
generated
@@ -442,6 +442,7 @@ dependencies = [
|
|||||||
"defmt",
|
"defmt",
|
||||||
"eframe",
|
"eframe",
|
||||||
"egui_dock",
|
"egui_dock",
|
||||||
|
"egui_extras",
|
||||||
"egui_plot",
|
"egui_plot",
|
||||||
"log",
|
"log",
|
||||||
"postcard-rpc",
|
"postcard-rpc",
|
||||||
@@ -892,9 +893,9 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "ecolor"
|
name = "ecolor"
|
||||||
version = "0.32.0"
|
version = "0.32.3"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "4a631732d995184114016fab22fc7e3faf73d6841c2d7650395fe251fbcd9285"
|
checksum = "94bdf37f8d5bd9aa7f753573fdda9cf7343afa73dd28d7bfe9593bd9798fc07e"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"bytemuck",
|
"bytemuck",
|
||||||
"emath",
|
"emath",
|
||||||
@@ -938,9 +939,9 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "egui"
|
name = "egui"
|
||||||
version = "0.32.0"
|
version = "0.32.3"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "8470210c95a42cc985d9ffebfd5067eea55bdb1c3f7611484907db9639675e28"
|
checksum = "5d5d0306cd61ca75e29682926d71f2390160247f135965242e904a636f51c0dc"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"accesskit",
|
"accesskit",
|
||||||
"ahash",
|
"ahash",
|
||||||
@@ -1005,6 +1006,20 @@ dependencies = [
|
|||||||
"paste",
|
"paste",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "egui_extras"
|
||||||
|
version = "0.32.3"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "dddbceddf39805fc6c62b1f7f9c05e23590b40844dc9ed89c6dc6dbc886e3e3b"
|
||||||
|
dependencies = [
|
||||||
|
"ahash",
|
||||||
|
"egui",
|
||||||
|
"enum-map",
|
||||||
|
"log",
|
||||||
|
"mime_guess2",
|
||||||
|
"profiling",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "egui_glow"
|
name = "egui_glow"
|
||||||
version = "0.32.0"
|
version = "0.32.0"
|
||||||
@@ -1036,9 +1051,9 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "emath"
|
name = "emath"
|
||||||
version = "0.32.0"
|
version = "0.32.3"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "45f057b141e7e46340c321400be74b793543b1b213036f0f989c35d35957c32e"
|
checksum = "45fd7bc25f769a3c198fe1cf183124bf4de3bd62ef7b4f1eaf6b08711a3af8db"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"bytemuck",
|
"bytemuck",
|
||||||
]
|
]
|
||||||
@@ -1067,6 +1082,26 @@ version = "1.1.0"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "a3d8a32ae18130a3c84dd492d4215c3d913c3b07c6b63c2eb3eb7ff1101ab7bf"
|
checksum = "a3d8a32ae18130a3c84dd492d4215c3d913c3b07c6b63c2eb3eb7ff1101ab7bf"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "enum-map"
|
||||||
|
version = "2.7.3"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "6866f3bfdf8207509a033af1a75a7b08abda06bbaaeae6669323fd5a097df2e9"
|
||||||
|
dependencies = [
|
||||||
|
"enum-map-derive",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "enum-map-derive"
|
||||||
|
version = "0.17.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "f282cfdfe92516eb26c2af8589c274c7c17681f5ecc03c18255fe741c6aa64eb"
|
||||||
|
dependencies = [
|
||||||
|
"proc-macro2",
|
||||||
|
"quote",
|
||||||
|
"syn",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "enumflags2"
|
name = "enumflags2"
|
||||||
version = "0.7.12"
|
version = "0.7.12"
|
||||||
@@ -1090,9 +1125,9 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "epaint"
|
name = "epaint"
|
||||||
version = "0.32.0"
|
version = "0.32.3"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "94cca02195f0552c17cabdc02f39aa9ab6fbd815dac60ab1cd3d5b0aa6f9551c"
|
checksum = "63adcea970b7a13094fe97a36ab9307c35a750f9e24bf00bb7ef3de573e0fddb"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"ab_glyph",
|
"ab_glyph",
|
||||||
"ahash",
|
"ahash",
|
||||||
@@ -1108,9 +1143,9 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "epaint_default_fonts"
|
name = "epaint_default_fonts"
|
||||||
version = "0.32.0"
|
version = "0.32.3"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "e8495e11ed527dff39663b8c36b6c2b2799d7e4287fb90556e455d72eca0b4d3"
|
checksum = "1537accc50c9cab5a272c39300bdd0dd5dca210f6e5e8d70be048df9596e7ca2"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "equivalent"
|
name = "equivalent"
|
||||||
@@ -1910,6 +1945,24 @@ dependencies = [
|
|||||||
"autocfg",
|
"autocfg",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "mime"
|
||||||
|
version = "0.3.17"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "6877bb514081ee2a7ff5ef9de3281f14a4dd4bceac4c09388074a6b5df8a139a"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "mime_guess2"
|
||||||
|
version = "2.3.1"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "1706dc14a2e140dec0a7a07109d9a3d5890b81e85bd6c60b906b249a77adf0ca"
|
||||||
|
dependencies = [
|
||||||
|
"mime",
|
||||||
|
"phf",
|
||||||
|
"phf_shared",
|
||||||
|
"unicase",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "miniz_oxide"
|
name = "miniz_oxide"
|
||||||
version = "0.8.9"
|
version = "0.8.9"
|
||||||
@@ -2484,6 +2537,50 @@ version = "2.3.1"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "e3148f5046208a5d56bcfc03053e3ca6334e51da8dfb19b6cdc8b306fae3283e"
|
checksum = "e3148f5046208a5d56bcfc03053e3ca6334e51da8dfb19b6cdc8b306fae3283e"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "phf"
|
||||||
|
version = "0.11.3"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "1fd6780a80ae0c52cc120a26a1a42c1ae51b247a253e4e06113d23d2c2edd078"
|
||||||
|
dependencies = [
|
||||||
|
"phf_macros",
|
||||||
|
"phf_shared",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "phf_generator"
|
||||||
|
version = "0.11.3"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "3c80231409c20246a13fddb31776fb942c38553c51e871f8cbd687a4cfb5843d"
|
||||||
|
dependencies = [
|
||||||
|
"phf_shared",
|
||||||
|
"rand",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "phf_macros"
|
||||||
|
version = "0.11.3"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "f84ac04429c13a7ff43785d75ad27569f2951ce0ffd30a3321230db2fc727216"
|
||||||
|
dependencies = [
|
||||||
|
"phf_generator",
|
||||||
|
"phf_shared",
|
||||||
|
"proc-macro2",
|
||||||
|
"quote",
|
||||||
|
"syn",
|
||||||
|
"unicase",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "phf_shared"
|
||||||
|
version = "0.11.3"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "67eabc2ef2a60eb7faa00097bd1ffdb5bd28e62bf39990626a582201b7a754e5"
|
||||||
|
dependencies = [
|
||||||
|
"siphasher",
|
||||||
|
"unicase",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "pin-project"
|
name = "pin-project"
|
||||||
version = "1.1.10"
|
version = "1.1.10"
|
||||||
@@ -2732,6 +2829,21 @@ version = "5.3.0"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "69cdb34c158ceb288df11e18b4bd39de994f6657d83847bdffdbd7f346754b0f"
|
checksum = "69cdb34c158ceb288df11e18b4bd39de994f6657d83847bdffdbd7f346754b0f"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "rand"
|
||||||
|
version = "0.8.5"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "34af8d1a0e25924bc5b7c43c079c942339d8f0a8b57c39049bef581b46327404"
|
||||||
|
dependencies = [
|
||||||
|
"rand_core",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "rand_core"
|
||||||
|
version = "0.6.4"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "ec0be4795e2f6a28069bec0b5ff3e2ac9bafc99e6a9a7dc3547996c5c816922c"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "raw-window-handle"
|
name = "raw-window-handle"
|
||||||
version = "0.6.2"
|
version = "0.6.2"
|
||||||
@@ -2996,6 +3108,12 @@ dependencies = [
|
|||||||
"windows-sys 0.48.0",
|
"windows-sys 0.48.0",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "siphasher"
|
||||||
|
version = "1.0.1"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "56199f7ddabf13fe5074ce809e7d3f42b42ae711800501b5b16ea82ad029c39d"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "slab"
|
name = "slab"
|
||||||
version = "0.4.10"
|
version = "0.4.10"
|
||||||
@@ -3470,6 +3588,12 @@ dependencies = [
|
|||||||
"thiserror 2.0.12",
|
"thiserror 2.0.12",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "unicase"
|
||||||
|
version = "2.8.1"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "75b844d17643ee918803943289730bec8aac480150456169e647ed0b576ba539"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "unicode-ident"
|
name = "unicode-ident"
|
||||||
version = "1.0.18"
|
version = "1.0.18"
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ defmt = { version = "1.0.1" }
|
|||||||
eframe = { version = "0.32.0"}
|
eframe = { version = "0.32.0"}
|
||||||
egui_plot = "0.33.0"
|
egui_plot = "0.33.0"
|
||||||
egui_dock = "0.17.0"
|
egui_dock = "0.17.0"
|
||||||
|
egui_extras = "0.32.3"
|
||||||
log = "0.4.27"
|
log = "0.4.27"
|
||||||
simple_logger = "5.0.0"
|
simple_logger = "5.0.0"
|
||||||
atomic_float = "1.1.0"
|
atomic_float = "1.1.0"
|
||||||
|
|||||||
106
src/app.rs
106
src/app.rs
@@ -9,14 +9,15 @@ use atomic_float::AtomicF32;
|
|||||||
use tokio::{sync::mpsc::{Sender}};
|
use tokio::{sync::mpsc::{Sender}};
|
||||||
|
|
||||||
use eframe::egui::{self, Button, CollapsingHeader, Color32, ComboBox, DragValue, Key, Label, Layout, Modifiers};
|
use eframe::egui::{self, Button, CollapsingHeader, Color32, ComboBox, DragValue, Key, Label, Layout, Modifiers};
|
||||||
use egui_plot::{Corner, GridInput, GridMark, Legend, Line, Plot, PlotBounds, PlotPoint, PlotPoints, Points};
|
use egui_plot::{Corner, GridInput, GridMark, Legend, Line, Plot, PlotPoint, Points};
|
||||||
use egui_dock::{DockArea, DockState, Style};
|
use egui_dock::{DockArea, DockState, Style};
|
||||||
|
use egui_extras::{TableBuilder, Column};
|
||||||
|
|
||||||
use crate::plot::{TimeSeriesPlot, BodePlot};
|
use crate::plot::{TimeSeriesPlot, BodePlot};
|
||||||
|
|
||||||
use crate::signals::StartStopSignal;
|
use crate::signals::StartStopSignal;
|
||||||
|
|
||||||
use crate::icd::{IcdDftNum, NumberOfPoints};
|
use crate::icd::{IcdDftNum, MeasurementPointSet};
|
||||||
|
|
||||||
const DFTNUM_VARIANTS: [IcdDftNum; 13] = [
|
const DFTNUM_VARIANTS: [IcdDftNum; 13] = [
|
||||||
IcdDftNum::Num4, IcdDftNum::Num8, IcdDftNum::Num16, IcdDftNum::Num32,
|
IcdDftNum::Num4, IcdDftNum::Num8, IcdDftNum::Num16, IcdDftNum::Num32,
|
||||||
@@ -25,6 +26,11 @@ const DFTNUM_VARIANTS: [IcdDftNum; 13] = [
|
|||||||
IcdDftNum::Num8192, IcdDftNum::Num16384,
|
IcdDftNum::Num8192, IcdDftNum::Num16384,
|
||||||
];
|
];
|
||||||
|
|
||||||
|
const MEASUREMENT_POINTS_VARIANTS: [MeasurementPointSet; 2] = [
|
||||||
|
MeasurementPointSet::Eight,
|
||||||
|
MeasurementPointSet::Eighteen,
|
||||||
|
];
|
||||||
|
|
||||||
#[derive(Clone, Copy,Debug, PartialEq, Eq)]
|
#[derive(Clone, Copy,Debug, PartialEq, Eq)]
|
||||||
enum TabActive {
|
enum TabActive {
|
||||||
Single,
|
Single,
|
||||||
@@ -47,7 +53,9 @@ pub struct App {
|
|||||||
pub data_frequency: Arc<AtomicF32>,
|
pub data_frequency: Arc<AtomicF32>,
|
||||||
pub single_frequency: Arc<Mutex<u32>>,
|
pub single_frequency: Arc<Mutex<u32>>,
|
||||||
pub dft_num: Arc<Mutex<IcdDftNum>>,
|
pub dft_num: Arc<Mutex<IcdDftNum>>,
|
||||||
|
pub measurement_points: Arc<Mutex<MeasurementPointSet>>,
|
||||||
pub periods_per_dft: Arc<Mutex<Option<f32>>>,
|
pub periods_per_dft: Arc<Mutex<Option<f32>>>,
|
||||||
|
pub periods_per_dft_multi: Arc<Mutex<(Vec<f32>, Option<Vec<f32>>)>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
struct TabViewer {
|
struct TabViewer {
|
||||||
@@ -59,7 +67,9 @@ struct TabViewer {
|
|||||||
on: Arc<Mutex<bool>>,
|
on: Arc<Mutex<bool>>,
|
||||||
single_frequency: Arc<Mutex<u32>>,
|
single_frequency: Arc<Mutex<u32>>,
|
||||||
dft_num: Arc<Mutex<IcdDftNum>>,
|
dft_num: Arc<Mutex<IcdDftNum>>,
|
||||||
|
measurement_points: Arc<Mutex<MeasurementPointSet>>,
|
||||||
periods_per_dft: Arc<Mutex<Option<f32>>>,
|
periods_per_dft: Arc<Mutex<Option<f32>>>,
|
||||||
|
periods_per_dft_multi: Arc<Mutex<(Vec<f32>, Option<Vec<f32>>)>>,
|
||||||
show_settings: bool,
|
show_settings: bool,
|
||||||
show_settings_toggle: Option<bool>,
|
show_settings_toggle: Option<bool>,
|
||||||
}
|
}
|
||||||
@@ -171,21 +181,76 @@ impl TabViewer {
|
|||||||
if let Ok(on) = self.on.lock() {
|
if let Ok(on) = self.on.lock() {
|
||||||
ui.add_enabled_ui(!*on, |ui| {
|
ui.add_enabled_ui(!*on, |ui| {
|
||||||
ui.horizontal(|ui| {
|
ui.horizontal(|ui| {
|
||||||
ui.label("ADC samples per DFT:");
|
ui.label("Measurement Points:");
|
||||||
let mut dft_num = self.dft_num.lock().unwrap();
|
let mut measurement_points = self.measurement_points.lock().unwrap();
|
||||||
let mut index = DFTNUM_VARIANTS.iter().position(|&x| x == *dft_num).unwrap_or(0);
|
let mut index = MEASUREMENT_POINTS_VARIANTS.iter().position(|&x| x == *measurement_points).unwrap_or(0);
|
||||||
ComboBox::from_id_salt("Dftnum")
|
ComboBox::from_id_salt("MeasurementPoints")
|
||||||
.width(75.0)
|
.width(75.0)
|
||||||
.show_index(ui, &mut index, DFTNUM_VARIANTS.len(), |i| {
|
.show_index(ui, &mut index, MEASUREMENT_POINTS_VARIANTS.len(), |i| {
|
||||||
format!("{}", 1 << (2 + i)) // 2^2 = 4, 2^3 = 8, ..., 2^14 = 16384
|
format!("{:?}", MEASUREMENT_POINTS_VARIANTS[i].len())
|
||||||
});
|
});
|
||||||
let new_value = DFTNUM_VARIANTS[index];
|
let new_value = MEASUREMENT_POINTS_VARIANTS[index];
|
||||||
if *dft_num != new_value {
|
if *measurement_points != new_value {
|
||||||
*dft_num = new_value;
|
*measurement_points = new_value;
|
||||||
info!("DFTNUM setting changed!");
|
info!("Measurement Points setting changed!");
|
||||||
};
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
ui.add_enabled_ui(*on, |ui| {
|
||||||
|
let (freq, periods_per_dft_vec) = self.periods_per_dft_multi.lock().unwrap().clone();
|
||||||
|
|
||||||
|
fn format_frequency(freq: f32) -> String {
|
||||||
|
if freq >= 1_000.0 {
|
||||||
|
// kHz
|
||||||
|
if freq % 1_000.0 == 0.0 {
|
||||||
|
format!("{}k", (freq / 1_000.0) as u64)
|
||||||
|
} else {
|
||||||
|
format!("{:.1}k", freq / 1_000.0)
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// Hz
|
||||||
|
if freq % 1.0 == 0.0 {
|
||||||
|
format!("{}", freq as u64)
|
||||||
|
} else {
|
||||||
|
format!("{:.1}", freq)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
TableBuilder::new(ui)
|
||||||
|
.column(Column::auto())
|
||||||
|
.columns(Column::remainder().at_most(30.0), freq.len())
|
||||||
|
.header(10.0, |mut header| {
|
||||||
|
header.col(|ui| {
|
||||||
|
ui.label("Frequency [Hz]:");
|
||||||
|
});
|
||||||
|
for freq in &freq {
|
||||||
|
header.col(|ui| {
|
||||||
|
ui.label(format_frequency(*freq));
|
||||||
|
});
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.body(|mut body| {
|
||||||
|
body.row(5.0, |mut row| {
|
||||||
|
row.col(|ui| {
|
||||||
|
ui.label("Periods per DFT:");
|
||||||
|
});
|
||||||
|
if let Some(periods) = periods_per_dft_vec {
|
||||||
|
for period in &periods {
|
||||||
|
row.col(|ui| {
|
||||||
|
ui.label(format!("{:.1}", period));
|
||||||
|
});
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
for _ in &freq {
|
||||||
|
row.col(|ui| {
|
||||||
|
ui.label("N/A");
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -355,7 +420,9 @@ impl App {
|
|||||||
let bode_plot = Arc::new(Mutex::new(BodePlot::new()));
|
let bode_plot = Arc::new(Mutex::new(BodePlot::new()));
|
||||||
let single_frequency = Arc::new(Mutex::new(50000));
|
let single_frequency = Arc::new(Mutex::new(50000));
|
||||||
let dft_num = Arc::new(Mutex::new(IcdDftNum::Num2048));
|
let dft_num = Arc::new(Mutex::new(IcdDftNum::Num2048));
|
||||||
|
let measurement_points = Arc::new(Mutex::new(MeasurementPointSet::Eighteen));
|
||||||
let periods_per_dft = Arc::new(Mutex::new(None));
|
let periods_per_dft = Arc::new(Mutex::new(None));
|
||||||
|
let periods_per_dft_multi = Arc::new(Mutex::new((MeasurementPointSet::Eighteen.values().to_vec(), None)));
|
||||||
let on = Arc::new(Mutex::new(true));
|
let on = Arc::new(Mutex::new(true));
|
||||||
let tab_active = TabActive::Single;
|
let tab_active = TabActive::Single;
|
||||||
|
|
||||||
@@ -368,7 +435,9 @@ impl App {
|
|||||||
bode_plot: bode_plot.clone(),
|
bode_plot: bode_plot.clone(),
|
||||||
single_frequency: single_frequency.clone(),
|
single_frequency: single_frequency.clone(),
|
||||||
dft_num: dft_num.clone(),
|
dft_num: dft_num.clone(),
|
||||||
|
measurement_points: measurement_points.clone(),
|
||||||
periods_per_dft: periods_per_dft.clone(),
|
periods_per_dft: periods_per_dft.clone(),
|
||||||
|
periods_per_dft_multi: periods_per_dft_multi.clone(),
|
||||||
on: on.clone(),
|
on: on.clone(),
|
||||||
show_settings: false,
|
show_settings: false,
|
||||||
show_settings_toggle: None,
|
show_settings_toggle: None,
|
||||||
@@ -390,13 +459,15 @@ impl App {
|
|||||||
data_frequency: Arc::new(AtomicF32::new(0.0)),
|
data_frequency: Arc::new(AtomicF32::new(0.0)),
|
||||||
single_frequency,
|
single_frequency,
|
||||||
dft_num,
|
dft_num,
|
||||||
|
measurement_points,
|
||||||
periods_per_dft,
|
periods_per_dft,
|
||||||
|
periods_per_dft_multi,
|
||||||
};
|
};
|
||||||
|
|
||||||
// For testing purposes, populate the Bode plot with a sample low-pass filter response
|
// For testing purposes, populate the Bode plot with a sample low-pass filter response
|
||||||
let fc = 1000.0; // cutoff frequency in Hz
|
let fc = 1000.0; // cutoff frequency in Hz
|
||||||
|
|
||||||
let freqs = NumberOfPoints::TwentyEight.values().to_vec();
|
let freqs = MeasurementPointSet::Eighteen.values().to_vec();
|
||||||
let magnitudes = freqs.iter()
|
let magnitudes = freqs.iter()
|
||||||
.map(|&f| {
|
.map(|&f| {
|
||||||
1.0 / (1.0 + (f / fc).powi(2)).sqrt()
|
1.0 / (1.0 + (f / fc).powi(2)).sqrt()
|
||||||
@@ -408,9 +479,8 @@ impl App {
|
|||||||
})
|
})
|
||||||
.collect::<Vec<f32>>();
|
.collect::<Vec<f32>>();
|
||||||
|
|
||||||
app.bode_plot.lock().unwrap().update_magnitudes(magnitudes);
|
app.bode_plot.lock().unwrap().update_magnitudes(MeasurementPointSet::Eighteen, magnitudes);
|
||||||
app.bode_plot.lock().unwrap().update_phases(phases);
|
app.bode_plot.lock().unwrap().update_phases(MeasurementPointSet::Eighteen, phases);
|
||||||
|
|
||||||
|
|
||||||
app.update_start_stop();
|
app.update_start_stop();
|
||||||
app
|
app
|
||||||
@@ -424,7 +494,7 @@ impl App {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
(TabActive::Multi, true) => {
|
(TabActive::Multi, true) => {
|
||||||
if let Err(e) = self.run_impedancemeter_tx.try_send(StartStopSignal::StartMulti(*self.dft_num.lock().unwrap(), NumberOfPoints::TwentyEight)) {
|
if let Err(e) = self.run_impedancemeter_tx.try_send(StartStopSignal::StartMulti(*self.measurement_points.lock().unwrap())) {
|
||||||
eprintln!("Failed to send start command: {:?}", e);
|
eprintln!("Failed to send start command: {:?}", e);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -78,7 +78,7 @@ async fn main() {
|
|||||||
.subscribe_multi::<icd::SingleImpedanceOutputTopic>(8)
|
.subscribe_multi::<icd::SingleImpedanceOutputTopic>(8)
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
client.start_impedancemeter_single(freq, bioz_icd_rs::IcdDftNum::Num2048).await.unwrap();
|
client.start_impedancemeter_single(freq, bioz_icd_rs::IcdDftNum::Num2048).await.unwrap().ok();
|
||||||
println!("Started with dft_num 2048!");
|
println!("Started with dft_num 2048!");
|
||||||
let dur = Duration::from_millis(dur.into());
|
let dur = Duration::from_millis(dur.into());
|
||||||
|
|
||||||
|
|||||||
@@ -34,6 +34,7 @@ fn main() {
|
|||||||
let data_frequency_clone = app.data_frequency.clone();
|
let data_frequency_clone = app.data_frequency.clone();
|
||||||
|
|
||||||
let periods_per_dft = app.periods_per_dft.clone();
|
let periods_per_dft = app.periods_per_dft.clone();
|
||||||
|
let periods_per_dft_multi = app.periods_per_dft_multi.clone();
|
||||||
|
|
||||||
// Execute the runtime in its own thread.
|
// Execute the runtime in its own thread.
|
||||||
std::thread::spawn(move || {
|
std::thread::spawn(move || {
|
||||||
@@ -48,6 +49,7 @@ fn main() {
|
|||||||
connected_clone,
|
connected_clone,
|
||||||
data_frequency_clone,
|
data_frequency_clone,
|
||||||
periods_per_dft,
|
periods_per_dft,
|
||||||
|
periods_per_dft_multi,
|
||||||
));
|
));
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -5,10 +5,10 @@ use postcard_rpc::{
|
|||||||
};
|
};
|
||||||
use std::convert::Infallible;
|
use std::convert::Infallible;
|
||||||
use bioz_icd_rs::{
|
use bioz_icd_rs::{
|
||||||
GetUniqueIdEndpoint, InitImpedanceResult, PingEndpoint, SetGreenLedEndpoint, StartMultiImpedance, StartMultiImpedanceEndpoint, StartSingleImpedance, StartSingleImpedanceEndpoint, StopSingleImpedanceEndpoint
|
GetUniqueIdEndpoint, ImpedanceInitResult, MultiImpedanceInitResult, MultiImpedanceStartRequest, PingEndpoint, SetGreenLedEndpoint, SingleImpedanceStartRequest, StartMultiImpedanceEndpoint, StartSingleImpedanceEndpoint, StopSingleImpedanceEndpoint
|
||||||
};
|
};
|
||||||
|
|
||||||
use crate::icd::{IcdDftNum, NumberOfPoints};
|
use crate::icd::{IcdDftNum, MeasurementPointSet};
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub struct WorkbookClient {
|
pub struct WorkbookClient {
|
||||||
@@ -66,22 +66,21 @@ impl WorkbookClient {
|
|||||||
&self,
|
&self,
|
||||||
frequency: u32,
|
frequency: u32,
|
||||||
dft_number: IcdDftNum,
|
dft_number: IcdDftNum,
|
||||||
) -> Result<InitImpedanceResult, WorkbookError<Infallible>> {
|
) -> Result<ImpedanceInitResult, WorkbookError<Infallible>> {
|
||||||
let response = self.client
|
let response = self.client
|
||||||
.send_resp::<StartSingleImpedanceEndpoint>(&StartSingleImpedance { update_frequency: 60, sinus_frequency: frequency, dft_number})
|
.send_resp::<StartSingleImpedanceEndpoint>(&SingleImpedanceStartRequest { update_frequency: 60, sinus_frequency: frequency, dft_number})
|
||||||
.await?;
|
.await?;
|
||||||
Ok(response)
|
Ok(response)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn start_impedancemeter_multi(
|
pub async fn start_impedancemeter_multi(
|
||||||
&self,
|
&self,
|
||||||
dft_number: IcdDftNum,
|
points: MeasurementPointSet,
|
||||||
number_of_points: NumberOfPoints,
|
) -> Result<MultiImpedanceInitResult, WorkbookError<Infallible>> {
|
||||||
) -> Result<(), WorkbookError<Infallible>> {
|
let response = self.client
|
||||||
self.client
|
.send_resp::<StartMultiImpedanceEndpoint>(&MultiImpedanceStartRequest { points })
|
||||||
.send_resp::<StartMultiImpedanceEndpoint>(&StartMultiImpedance { dft_number, number_of_points })
|
|
||||||
.await?;
|
.await?;
|
||||||
Ok(())
|
Ok(response)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn stop_impedancemeter(&self) -> Result<bool, WorkbookError<Infallible>> {
|
pub async fn stop_impedancemeter(&self) -> Result<bool, WorkbookError<Infallible>> {
|
||||||
|
|||||||
@@ -8,6 +8,8 @@ use atomic_float::AtomicF32;
|
|||||||
|
|
||||||
use std::sync::{Arc, Mutex};
|
use std::sync::{Arc, Mutex};
|
||||||
|
|
||||||
|
use bioz_icd_rs::MeasurementPointSet;
|
||||||
|
|
||||||
use crate::icd;
|
use crate::icd;
|
||||||
use crate::client::WorkbookClient;
|
use crate::client::WorkbookClient;
|
||||||
|
|
||||||
@@ -26,6 +28,7 @@ pub async fn communicate_with_hardware(
|
|||||||
connected: Arc<AtomicBool>,
|
connected: Arc<AtomicBool>,
|
||||||
data_frequency: Arc<AtomicF32>,
|
data_frequency: Arc<AtomicF32>,
|
||||||
periods_per_dft: Arc<Mutex<Option<f32>>>,
|
periods_per_dft: Arc<Mutex<Option<f32>>>,
|
||||||
|
periods_per_dft_multi: Arc<Mutex<(Vec<f32>, Option<Vec<f32>>)>>,
|
||||||
) {
|
) {
|
||||||
let data_counter = Arc::new(AtomicU32::new(0));
|
let data_counter = Arc::new(AtomicU32::new(0));
|
||||||
let data_counter_clone = data_counter.clone();
|
let data_counter_clone = data_counter.clone();
|
||||||
@@ -88,10 +91,10 @@ pub async fn communicate_with_hardware(
|
|||||||
info!("SingleImpedanceOutputTopic subscription ended.");
|
info!("SingleImpedanceOutputTopic subscription ended.");
|
||||||
});
|
});
|
||||||
|
|
||||||
// Subscribe to MultiImpedanceOutputTopic28
|
// Subscribe to MultiImpedanceOutputTopic8
|
||||||
let mut multi_impedance_28_sub = workbook_client
|
let mut multi_impedance_sub = workbook_client
|
||||||
.client
|
.client
|
||||||
.subscribe_multi::<icd::MultiImpedanceOutputTopic28>(8)
|
.subscribe_multi::<icd::MultiImpedanceOutputTopic>(8)
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
@@ -99,14 +102,25 @@ pub async fn communicate_with_hardware(
|
|||||||
let data_counter_clone_multi = data_counter_clone.clone();
|
let data_counter_clone_multi = data_counter_clone.clone();
|
||||||
|
|
||||||
tokio::spawn(async move {
|
tokio::spawn(async move {
|
||||||
while let Ok(val) = multi_impedance_28_sub.recv().await {
|
while let Ok(val) = multi_impedance_sub.recv().await {
|
||||||
let mut bode_plot = data.lock().unwrap();
|
let mut bode_plot = data.lock().unwrap();
|
||||||
|
|
||||||
let magnitudes = val.magnitudes.into_iter().collect::<Vec<f32>>();
|
match val.points {
|
||||||
bode_plot.update_magnitudes(magnitudes);
|
|
||||||
let phases = val.phases.into_iter().collect::<Vec<f32>>();
|
|
||||||
bode_plot.update_phases(phases);
|
|
||||||
|
|
||||||
|
MeasurementPointSet::Eight => {
|
||||||
|
let magnitudes: Vec<f32> = val.magnitudes_8.into_iter().collect();
|
||||||
|
let phases: Vec<f32> = val.phases_8.into_iter().collect();
|
||||||
|
bode_plot.update_magnitudes(MeasurementPointSet::Eight, magnitudes);
|
||||||
|
bode_plot.update_phases(MeasurementPointSet::Eight, phases);
|
||||||
|
},
|
||||||
|
MeasurementPointSet::Eighteen => {
|
||||||
|
let magnitudes: Vec<f32> = val.magnitudes_18.into_iter().collect();
|
||||||
|
let phases: Vec<f32> = val.phases_18.into_iter().collect();
|
||||||
|
bode_plot.update_magnitudes(MeasurementPointSet::Eighteen, magnitudes);
|
||||||
|
bode_plot.update_phases(MeasurementPointSet::Eighteen, phases);
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
data_counter_clone_multi.fetch_add(1, Ordering::Relaxed);
|
data_counter_clone_multi.fetch_add(1, Ordering::Relaxed);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@@ -132,12 +146,28 @@ pub async fn communicate_with_hardware(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
StartStopSignal::StartMulti(dft_num, num_points) => {
|
StartStopSignal::StartMulti(num_points) => {
|
||||||
if let Err(e) = workbook_client.start_impedancemeter_multi(dft_num, num_points).await {
|
match workbook_client.start_impedancemeter_multi(num_points).await {
|
||||||
error!("Failed to start multi-point impedancemeter: {:?}", e);
|
Ok(Ok(periods)) => {
|
||||||
} else {
|
settings.frequency = Some(StartStopSignal::StartMulti(num_points));
|
||||||
settings.frequency = Some(StartStopSignal::StartMulti(dft_num, num_points));
|
info!("Multi-point Impedancemeter started.");
|
||||||
info!("Multi-point Impedancemeter started.");
|
match num_points {
|
||||||
|
MeasurementPointSet::Eight => {
|
||||||
|
*periods_per_dft_multi.lock().unwrap() = (num_points.values().iter().copied().collect(), Some(periods.periods_per_dft_8.into_iter().collect()));
|
||||||
|
},
|
||||||
|
MeasurementPointSet::Eighteen => {
|
||||||
|
*periods_per_dft_multi.lock().unwrap() = (num_points.values().iter().copied().collect(), Some(periods.periods_per_dft_18.into_iter().collect()));
|
||||||
|
},
|
||||||
|
}
|
||||||
|
},
|
||||||
|
Ok(Err(e)) => {
|
||||||
|
error!("Failed to multi-init on hardware: {:?}", e);
|
||||||
|
*periods_per_dft_multi.lock().unwrap() = (num_points.values().iter().copied().collect(), None);
|
||||||
|
},
|
||||||
|
Err(e) => {
|
||||||
|
error!("Communication error when starting impedancemeter: {:?}", e);
|
||||||
|
*periods_per_dft_multi.lock().unwrap() = (num_points.values().iter().copied().collect(), None);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
StartStopSignal::Stop => {
|
StartStopSignal::Stop => {
|
||||||
@@ -145,6 +175,9 @@ pub async fn communicate_with_hardware(
|
|||||||
error!("Failed to stop impedancemeter: {:?}", e);
|
error!("Failed to stop impedancemeter: {:?}", e);
|
||||||
} else {
|
} else {
|
||||||
settings.frequency = Some(StartStopSignal::Stop);
|
settings.frequency = Some(StartStopSignal::Stop);
|
||||||
|
*periods_per_dft.lock().unwrap() = None;
|
||||||
|
let (freq, _) = periods_per_dft_multi.lock().unwrap().clone();
|
||||||
|
*periods_per_dft_multi.lock().unwrap() = (freq, None);
|
||||||
info!("Impedancemeter stopped.");
|
info!("Impedancemeter stopped.");
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|||||||
10
src/plot.rs
10
src/plot.rs
@@ -3,7 +3,7 @@ use std::collections::VecDeque;
|
|||||||
|
|
||||||
use egui_plot::{PlotPoint, PlotPoints};
|
use egui_plot::{PlotPoint, PlotPoints};
|
||||||
|
|
||||||
use bioz_icd_rs::NumberOfPoints;
|
use bioz_icd_rs::MeasurementPointSet;
|
||||||
|
|
||||||
pub struct TimeSeriesPlot {
|
pub struct TimeSeriesPlot {
|
||||||
pub values: VecDeque<PlotPoint>,
|
pub values: VecDeque<PlotPoint>,
|
||||||
@@ -63,14 +63,14 @@ impl BodePlot {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn update_magnitudes(&mut self, magnitudes: Vec<f32>) {
|
pub fn update_magnitudes(&mut self, points: MeasurementPointSet, magnitudes: Vec<f32>) {
|
||||||
let freqs = NumberOfPoints::TwentyEight.values().to_vec();
|
let freqs = points.values().to_vec();
|
||||||
// self.magnitudes = freqs.into_iter().zip(magnitudes.into_iter()).map(|(f, m)| PlotPoint::new(f.log10(), 20.0 * m.log10() as f32)).collect();
|
// self.magnitudes = freqs.into_iter().zip(magnitudes.into_iter()).map(|(f, m)| PlotPoint::new(f.log10(), 20.0 * m.log10() as f32)).collect();
|
||||||
self.magnitudes = freqs.into_iter().zip(magnitudes.into_iter()).map(|(f, m)| PlotPoint::new(f.log10(), m as f32)).collect();
|
self.magnitudes = freqs.into_iter().zip(magnitudes.into_iter()).map(|(f, m)| PlotPoint::new(f.log10(), m as f32)).collect();
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn update_phases(&mut self, phases: Vec<f32>) {
|
pub fn update_phases(&mut self, points: MeasurementPointSet, phases: Vec<f32>) {
|
||||||
let freqs = NumberOfPoints::TwentyEight.values().to_vec();
|
let freqs = points.values().to_vec();
|
||||||
self.phases = freqs.into_iter().zip(phases.into_iter()).map(|(f, p)| PlotPoint::new(f.log10(), p as f64)).collect();
|
self.phases = freqs.into_iter().zip(phases.into_iter()).map(|(f, p)| PlotPoint::new(f.log10(), p as f64)).collect();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
use crate::icd::{IcdDftNum, NumberOfPoints};
|
use crate::icd::{IcdDftNum, MeasurementPointSet};
|
||||||
|
|
||||||
#[derive(Copy, Clone)]
|
#[derive(Copy, Clone)]
|
||||||
pub enum StartStopSignal {
|
pub enum StartStopSignal {
|
||||||
StartSingle(u32, IcdDftNum), // frequency in Hz, DFT number
|
StartSingle(u32, IcdDftNum), // frequency in Hz, DFT number
|
||||||
StartMulti(IcdDftNum, NumberOfPoints), // DFT number, number of points per measurement
|
StartMulti(MeasurementPointSet), // DFT number, number of points per measurement
|
||||||
Stop,
|
Stop,
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user