Updated logging to be able to select output folder.

This commit is contained in:
2025-12-04 16:50:42 +01:00
parent ef3fc12cb8
commit 1ca1c2c7b4
6 changed files with 275 additions and 80 deletions

View File

@@ -15,6 +15,7 @@ use bioz_icd_rs::MeasurementPointSet;
use crate::icd;
use crate::client::WorkbookClient;
use crate::logging::LoggingStates;
use crate::plot::{TimeSeriesPlot, BodePlot};
use crate::signals::{LoggingSignal, StartStopSignal};
@@ -31,7 +32,7 @@ pub async fn communicate_with_hardware(
data_frequency: Arc<AtomicF32>,
periods_per_dft: Arc<Mutex<Option<f32>>>,
periods_per_dft_sweep: Arc<Mutex<(Vec<u32>, Option<Vec<f32>>)>>,
gui_logging_enabled: Arc<AtomicBool>,
gui_logging_state: Arc<Mutex<LoggingStates>>,
log_tx: Sender<LoggingSignal>,
) {
let data_counter = Arc::new(AtomicU32::new(0));
@@ -78,7 +79,7 @@ pub async fn communicate_with_hardware(
let data_counter_clone_single = data_counter_clone.clone();
// Clone log_tx for the task
let gui_logging_enabled_clone = gui_logging_enabled.clone();
let gui_logging_state_clone = gui_logging_state.clone();
let log_tx_clone = log_tx.clone();
let settings_clone = settings.clone();
@@ -91,7 +92,7 @@ pub async fn communicate_with_hardware(
let mut mag_val = data.2.lock().unwrap();
let mut phase_val = data.3.lock().unwrap();
*mag_val = val.magnitude;
*mag_val = val.magnitude;
*phase_val = val.phase;
mag_plot.add(val.magnitude as f64);
@@ -100,11 +101,11 @@ pub async fn communicate_with_hardware(
data_counter_clone_single.fetch_add(1, Ordering::Relaxed);
}
// Send logging signal
if gui_logging_enabled_clone.load(Ordering::Relaxed) {
if *gui_logging_state_clone.lock().unwrap() == LoggingStates::Logging {
let settings = *settings_clone.lock().unwrap();
match settings.frequency {
Some(StartStopSignal::StartSingle(freq, _, _)) => {
if let Err(e) = log_tx_clone.send(LoggingSignal::SingleImpedance(SystemTime::now(), freq, val.magnitude, val.phase)).await {
if let Err(e) = log_tx_clone.try_send(LoggingSignal::SingleImpedance(SystemTime::now(), freq, val.magnitude, val.phase)) {
error!("Failed to send logging signal: {:?}", e);
}
},
@@ -131,7 +132,7 @@ pub async fn communicate_with_hardware(
let data_counter_clone_sweep = data_counter_clone.clone();
// Clone log_tx for the task
let gui_logging_enabled_clone = gui_logging_enabled.clone();
let gui_logging_state_clone = gui_logging_state.clone();
let log_tx_clone = log_tx.clone();
tokio::spawn(async move {
@@ -147,7 +148,7 @@ pub async fn communicate_with_hardware(
bode_plot.update_magnitudes(MeasurementPointSet::Eight, magnitudes.clone());
bode_plot.update_phases(MeasurementPointSet::Eight, phases.clone());
}
if gui_logging_enabled_clone.load(Ordering::Relaxed) {
if *gui_logging_state_clone.lock().unwrap() == LoggingStates::Logging {
if let Err(e) = log_tx_clone.send(LoggingSignal::SweepImpedance(SystemTime::now(), MeasurementPointSet::Eight.values().to_vec(), magnitudes.clone(), phases.clone())).await {
error!("Failed to send logging signal: {:?}", e);
}
@@ -161,7 +162,7 @@ pub async fn communicate_with_hardware(
bode_plot.update_magnitudes(MeasurementPointSet::Eighteen, magnitudes.clone());
bode_plot.update_phases(MeasurementPointSet::Eighteen, phases.clone());
}
if gui_logging_enabled_clone.load(Ordering::Relaxed) {
if *gui_logging_state_clone.lock().unwrap() == LoggingStates::Logging {
if let Err(e) = log_tx_clone.send(LoggingSignal::SweepImpedance(SystemTime::now(), MeasurementPointSet::Eighteen.values().to_vec(), magnitudes.clone(), phases.clone())).await {
error!("Failed to send logging signal: {:?}", e);
}