Add electrode config to logging file.

This commit is contained in:
2026-04-20 11:56:56 +02:00
parent 27ee40e724
commit 4eac555ed4
3 changed files with 51 additions and 14 deletions

View File

@@ -49,7 +49,7 @@ pub async fn communicate_with_hardware(
#[derive(Default, Clone, Copy)]
struct Settings {
frequency: Option<StartStopSignal>,
mode: Option<StartStopSignal>,
}
let settings = Arc::new(Mutex::new(Settings::default()));
@@ -57,8 +57,8 @@ pub async fn communicate_with_hardware(
let workbook_client = match WorkbookClient::new() {
Ok(client) => {
info!("Connected to hardware successfully.");
if let Some(frequency) = settings.lock().unwrap().frequency {
run_impedancemeter_tx.send(frequency).await.unwrap();
if let Some(mode) = settings.lock().unwrap().mode {
run_impedancemeter_tx.send(mode).await.unwrap();
}
match client.get_device_info().await.unwrap() {
MultiplexerCapability::Absent => {
@@ -114,7 +114,7 @@ pub async fn communicate_with_hardware(
// Send logging signal
if *gui_logging_state_clone.lock().unwrap() == LoggingStates::Logging {
let settings = *settings_clone.lock().unwrap();
match settings.frequency {
match settings.mode {
Some(StartStopSignal::StartSingle(freq, _, _, _)) => {
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);
@@ -185,6 +185,7 @@ pub async fn communicate_with_hardware(
}
});
let log_tx_clone = log_tx.clone();
loop {
select! {
Some(frequency) = run_impedancemeter_rx.recv() => {
@@ -193,8 +194,15 @@ pub async fn communicate_with_hardware(
match workbook_client.start_impedancemeter_single(freq, lead_mode, electrode_config, dft_num).await {
Ok(Ok(periods)) => {
info!("Impedance meter started at frequency: {} with periods per DFT: {}", freq, periods);
settings.lock().unwrap().frequency = Some(StartStopSignal::StartSingle(freq, lead_mode, electrode_config, dft_num));
settings.lock().unwrap().mode = Some(StartStopSignal::StartSingle(freq, lead_mode, electrode_config, dft_num));
*periods_per_dft.lock().unwrap() = Some(periods);
// When logging add electrode configuration to logging file
if *gui_logging_state.lock().unwrap() == LoggingStates::Logging {
if let Err(e) = log_tx_clone.send(LoggingSignal::ElectrodeCongiguration(electrode_config)).await {
error!("Failed to send logging signal: {:?}", e);
}
}
},
Ok(Err(e)) => {
error!("Failed to init on hardware: {:?}", e);
@@ -209,7 +217,7 @@ pub async fn communicate_with_hardware(
StartStopSignal::StartSweep(lead_mode, electrode_config, num_points) => {
match workbook_client.start_impedancemeter_sweep(lead_mode, electrode_config, num_points).await {
Ok(Ok(periods)) => {
settings.lock().unwrap().frequency = Some(StartStopSignal::StartSweep(lead_mode, electrode_config, num_points));
settings.lock().unwrap().mode = Some(StartStopSignal::StartSweep(lead_mode, electrode_config, num_points));
info!("Sweep Impedancemeter started.");
match num_points {
MeasurementPointSet::Eight => {
@@ -219,6 +227,13 @@ pub async fn communicate_with_hardware(
*periods_per_dft_sweep.lock().unwrap() = (num_points.values().iter().copied().collect(), Some(periods.periods_per_dft_18.into_iter().collect()));
},
}
// When logging add electrode configuration to logging file
if *gui_logging_state.lock().unwrap() == LoggingStates::Logging {
if let Err(e) = log_tx_clone.send(LoggingSignal::ElectrodeCongiguration(electrode_config)).await {
error!("Failed to send logging signal: {:?}", e);
}
}
},
Ok(Err(e)) => {
error!("Failed to sweep-init on hardware: {:?}", e);
@@ -234,7 +249,7 @@ pub async fn communicate_with_hardware(
if let Err(e) = workbook_client.stop_impedancemeter().await {
error!("Failed to stop impedancemeter: {:?}", e);
} else {
settings.lock().unwrap().frequency = Some(StartStopSignal::Stop);
settings.lock().unwrap().mode = Some(StartStopSignal::Stop);
*periods_per_dft.lock().unwrap() = None;
let (freq, _) = periods_per_dft_sweep.lock().unwrap().clone();
*periods_per_dft_sweep.lock().unwrap() = (freq, None);