Created basic sinus output via postcard rpc.

This commit is contained in:
2025-08-06 18:26:17 +02:00
parent 2d8c6d23fd
commit 0b55cdf8b8
10 changed files with 3384 additions and 29 deletions

66
src/communication.rs Normal file
View File

@@ -0,0 +1,66 @@
use tokio::select;
use tokio::sync::mpsc::Receiver;
use std::sync::{Arc, Mutex};
use crate::icd;
use crate::client::WorkbookClient;
use crate::plot::TimeSeriesPlot;
pub async fn communicate_with_hardware(
mut run_impedancemeter_rx: Receiver<u32>,
magnitude: Arc<Mutex<f32>>,
phase: Arc<Mutex<f32>>,
magnitude_series: Arc<Mutex<TimeSeriesPlot>>,
phase_series: Arc<Mutex<TimeSeriesPlot>>,
) {
let workbook_client = WorkbookClient::new();
let mut sub = workbook_client
.client
.subscribe_multi::<icd::ImpedanceTopic>(8)
.await
.unwrap();
tokio::spawn(async move {
while let Ok(val) = sub.recv().await {
let mut mag_plot = magnitude_series.lock().unwrap();
let mut phase_plot = phase_series.lock().unwrap();
*magnitude.lock().unwrap() = val.magnitude;
*phase.lock().unwrap() = val.phase;
mag_plot.add(val.magnitude as f64);
phase_plot.add(val.phase as f64);
}
});
loop {
select! {
Some(run) = run_impedancemeter_rx.recv() => {
if run > 0 {
// Start the impedancemeter
if let Err(e) = workbook_client.start_impedancemeter(run as f32).await {
eprintln!("Failed to start impedancemeter: {:?}", e);
} else {
println!("Impedancemeter started.");
}
} else {
// Stop the impedancemeter
if let Err(e) = workbook_client.stop_impedancemeter().await {
eprintln!("Failed to stop impedancemeter: {:?}", e);
} else {
println!("Impedancemeter stopped.");
}
}
}
else => {
// All channels closed
break;
}
}
}
}