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:
@@ -8,6 +8,8 @@ use atomic_float::AtomicF32;
|
||||
|
||||
use std::sync::{Arc, Mutex};
|
||||
|
||||
use bioz_icd_rs::MeasurementPointSet;
|
||||
|
||||
use crate::icd;
|
||||
use crate::client::WorkbookClient;
|
||||
|
||||
@@ -26,6 +28,7 @@ pub async fn communicate_with_hardware(
|
||||
connected: Arc<AtomicBool>,
|
||||
data_frequency: Arc<AtomicF32>,
|
||||
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_clone = data_counter.clone();
|
||||
@@ -88,10 +91,10 @@ pub async fn communicate_with_hardware(
|
||||
info!("SingleImpedanceOutputTopic subscription ended.");
|
||||
});
|
||||
|
||||
// Subscribe to MultiImpedanceOutputTopic28
|
||||
let mut multi_impedance_28_sub = workbook_client
|
||||
// Subscribe to MultiImpedanceOutputTopic8
|
||||
let mut multi_impedance_sub = workbook_client
|
||||
.client
|
||||
.subscribe_multi::<icd::MultiImpedanceOutputTopic28>(8)
|
||||
.subscribe_multi::<icd::MultiImpedanceOutputTopic>(8)
|
||||
.await
|
||||
.unwrap();
|
||||
|
||||
@@ -99,14 +102,25 @@ pub async fn communicate_with_hardware(
|
||||
let data_counter_clone_multi = data_counter_clone.clone();
|
||||
|
||||
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 magnitudes = val.magnitudes.into_iter().collect::<Vec<f32>>();
|
||||
bode_plot.update_magnitudes(magnitudes);
|
||||
let phases = val.phases.into_iter().collect::<Vec<f32>>();
|
||||
bode_plot.update_phases(phases);
|
||||
match val.points {
|
||||
|
||||
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);
|
||||
}
|
||||
});
|
||||
@@ -132,12 +146,28 @@ pub async fn communicate_with_hardware(
|
||||
}
|
||||
}
|
||||
},
|
||||
StartStopSignal::StartMulti(dft_num, num_points) => {
|
||||
if let Err(e) = workbook_client.start_impedancemeter_multi(dft_num, num_points).await {
|
||||
error!("Failed to start multi-point impedancemeter: {:?}", e);
|
||||
} else {
|
||||
settings.frequency = Some(StartStopSignal::StartMulti(dft_num, num_points));
|
||||
info!("Multi-point Impedancemeter started.");
|
||||
StartStopSignal::StartMulti(num_points) => {
|
||||
match workbook_client.start_impedancemeter_multi(num_points).await {
|
||||
Ok(Ok(periods)) => {
|
||||
settings.frequency = Some(StartStopSignal::StartMulti(num_points));
|
||||
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 => {
|
||||
@@ -145,6 +175,9 @@ pub async fn communicate_with_hardware(
|
||||
error!("Failed to stop impedancemeter: {:?}", e);
|
||||
} else {
|
||||
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.");
|
||||
}
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user