mirror of
https://github.com/hubaldv/bioz-host-rs.git
synced 2026-07-24 00:57:44 +00:00
Add electrode config to logging file.
This commit is contained in:
@@ -49,7 +49,7 @@ pub async fn communicate_with_hardware(
|
|||||||
|
|
||||||
#[derive(Default, Clone, Copy)]
|
#[derive(Default, Clone, Copy)]
|
||||||
struct Settings {
|
struct Settings {
|
||||||
frequency: Option<StartStopSignal>,
|
mode: Option<StartStopSignal>,
|
||||||
}
|
}
|
||||||
let settings = Arc::new(Mutex::new(Settings::default()));
|
let settings = Arc::new(Mutex::new(Settings::default()));
|
||||||
|
|
||||||
@@ -57,8 +57,8 @@ pub async fn communicate_with_hardware(
|
|||||||
let workbook_client = match WorkbookClient::new() {
|
let workbook_client = match WorkbookClient::new() {
|
||||||
Ok(client) => {
|
Ok(client) => {
|
||||||
info!("Connected to hardware successfully.");
|
info!("Connected to hardware successfully.");
|
||||||
if let Some(frequency) = settings.lock().unwrap().frequency {
|
if let Some(mode) = settings.lock().unwrap().mode {
|
||||||
run_impedancemeter_tx.send(frequency).await.unwrap();
|
run_impedancemeter_tx.send(mode).await.unwrap();
|
||||||
}
|
}
|
||||||
match client.get_device_info().await.unwrap() {
|
match client.get_device_info().await.unwrap() {
|
||||||
MultiplexerCapability::Absent => {
|
MultiplexerCapability::Absent => {
|
||||||
@@ -114,7 +114,7 @@ pub async fn communicate_with_hardware(
|
|||||||
// Send logging signal
|
// Send logging signal
|
||||||
if *gui_logging_state_clone.lock().unwrap() == LoggingStates::Logging {
|
if *gui_logging_state_clone.lock().unwrap() == LoggingStates::Logging {
|
||||||
let settings = *settings_clone.lock().unwrap();
|
let settings = *settings_clone.lock().unwrap();
|
||||||
match settings.frequency {
|
match settings.mode {
|
||||||
Some(StartStopSignal::StartSingle(freq, _, _, _)) => {
|
Some(StartStopSignal::StartSingle(freq, _, _, _)) => {
|
||||||
if let Err(e) = log_tx_clone.try_send(LoggingSignal::SingleImpedance(SystemTime::now(), freq, val.magnitude, val.phase)) {
|
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);
|
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 {
|
loop {
|
||||||
select! {
|
select! {
|
||||||
Some(frequency) = run_impedancemeter_rx.recv() => {
|
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 {
|
match workbook_client.start_impedancemeter_single(freq, lead_mode, electrode_config, dft_num).await {
|
||||||
Ok(Ok(periods)) => {
|
Ok(Ok(periods)) => {
|
||||||
info!("Impedance meter started at frequency: {} with periods per DFT: {}", freq, 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);
|
*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)) => {
|
Ok(Err(e)) => {
|
||||||
error!("Failed to init on hardware: {:?}", 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) => {
|
StartStopSignal::StartSweep(lead_mode, electrode_config, num_points) => {
|
||||||
match workbook_client.start_impedancemeter_sweep(lead_mode, electrode_config, num_points).await {
|
match workbook_client.start_impedancemeter_sweep(lead_mode, electrode_config, num_points).await {
|
||||||
Ok(Ok(periods)) => {
|
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.");
|
info!("Sweep Impedancemeter started.");
|
||||||
match num_points {
|
match num_points {
|
||||||
MeasurementPointSet::Eight => {
|
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()));
|
*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)) => {
|
Ok(Err(e)) => {
|
||||||
error!("Failed to sweep-init on hardware: {:?}", 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 {
|
if let Err(e) = workbook_client.stop_impedancemeter().await {
|
||||||
error!("Failed to stop impedancemeter: {:?}", e);
|
error!("Failed to stop impedancemeter: {:?}", e);
|
||||||
} else {
|
} else {
|
||||||
settings.lock().unwrap().frequency = Some(StartStopSignal::Stop);
|
settings.lock().unwrap().mode = Some(StartStopSignal::Stop);
|
||||||
*periods_per_dft.lock().unwrap() = None;
|
*periods_per_dft.lock().unwrap() = None;
|
||||||
let (freq, _) = periods_per_dft_sweep.lock().unwrap().clone();
|
let (freq, _) = periods_per_dft_sweep.lock().unwrap().clone();
|
||||||
*periods_per_dft_sweep.lock().unwrap() = (freq, None);
|
*periods_per_dft_sweep.lock().unwrap() = (freq, None);
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
use bioz_icd_rs::ElectrodeConfiguration;
|
||||||
use log::info;
|
use log::info;
|
||||||
|
|
||||||
use std::sync::{Arc, Mutex};
|
use std::sync::{Arc, Mutex};
|
||||||
@@ -24,6 +25,7 @@ pub async fn log_data(
|
|||||||
) {
|
) {
|
||||||
let mut file: Option<File> = None;
|
let mut file: Option<File> = None;
|
||||||
let mut logging_marker = String::new();
|
let mut logging_marker = String::new();
|
||||||
|
let mut electrode_configuration = String::new();
|
||||||
|
|
||||||
loop {
|
loop {
|
||||||
match data.recv().await {
|
match data.recv().await {
|
||||||
@@ -31,30 +33,35 @@ pub async fn log_data(
|
|||||||
match signal {
|
match signal {
|
||||||
LoggingSignal::SingleImpedance(timestamp, frequency, magnitude, phase) => {
|
LoggingSignal::SingleImpedance(timestamp, frequency, magnitude, phase) => {
|
||||||
if let Some(f) = file.as_mut() {
|
if let Some(f) = file.as_mut() {
|
||||||
let _ = f.write_all(format!("{},{},{},{},{}\n",
|
let _ = f.write_all(format!("{},{},{},{},{},{}\n",
|
||||||
timestamp.duration_since(UNIX_EPOCH).unwrap().as_millis(),
|
timestamp.duration_since(UNIX_EPOCH).unwrap().as_millis(),
|
||||||
frequency,
|
frequency,
|
||||||
magnitude,
|
magnitude,
|
||||||
phase,
|
phase,
|
||||||
logging_marker)
|
logging_marker,
|
||||||
|
electrode_configuration)
|
||||||
.as_bytes())
|
.as_bytes())
|
||||||
.await;
|
.await;
|
||||||
}
|
}
|
||||||
if logging_marker.len() > 0 {
|
if logging_marker.len() > 0 {
|
||||||
logging_marker.clear();
|
logging_marker.clear();
|
||||||
}
|
}
|
||||||
|
if electrode_configuration.len() > 0 {
|
||||||
|
electrode_configuration.clear();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
LoggingSignal::SweepImpedance(timestamp, frequencies, magnitudes, phases) => {
|
LoggingSignal::SweepImpedance(timestamp, frequencies, magnitudes, phases) => {
|
||||||
if let Some(f) = file.as_mut() {
|
if let Some(f) = file.as_mut() {
|
||||||
for i in 0..frequencies.len() {
|
for i in 0..frequencies.len() {
|
||||||
let _ = f.write_all(
|
let _ = f.write_all(
|
||||||
format!("{},{},{},{},{},{}\n",
|
format!("{},{},{},{},{},{},{}\n",
|
||||||
timestamp.duration_since(UNIX_EPOCH).unwrap().as_millis(),
|
timestamp.duration_since(UNIX_EPOCH).unwrap().as_millis(),
|
||||||
frequencies[i],
|
frequencies[i],
|
||||||
magnitudes[i],
|
magnitudes[i],
|
||||||
phases[i],
|
phases[i],
|
||||||
i, // optional index
|
i, // optional index
|
||||||
logging_marker
|
logging_marker,
|
||||||
|
electrode_configuration
|
||||||
).as_bytes()
|
).as_bytes()
|
||||||
).await;
|
).await;
|
||||||
}
|
}
|
||||||
@@ -62,9 +69,9 @@ pub async fn log_data(
|
|||||||
if logging_marker.len() > 0 {
|
if logging_marker.len() > 0 {
|
||||||
logging_marker.clear();
|
logging_marker.clear();
|
||||||
}
|
}
|
||||||
|
if electrode_configuration.len() > 0 {
|
||||||
|
electrode_configuration.clear();
|
||||||
}
|
}
|
||||||
LoggingSignal::AddMarker(marker) => {
|
|
||||||
logging_marker = marker;
|
|
||||||
}
|
}
|
||||||
LoggingSignal::StartFileLogging(filename) => {
|
LoggingSignal::StartFileLogging(filename) => {
|
||||||
// Update global logging state
|
// Update global logging state
|
||||||
@@ -126,6 +133,20 @@ pub async fn log_data(
|
|||||||
// Update global logging state
|
// Update global logging state
|
||||||
*gui_logging_state.lock().unwrap() = LoggingStates::Idle;
|
*gui_logging_state.lock().unwrap() = LoggingStates::Idle;
|
||||||
}
|
}
|
||||||
|
LoggingSignal::AddMarker(marker) => {
|
||||||
|
logging_marker = marker;
|
||||||
|
}
|
||||||
|
LoggingSignal::ElectrodeCongiguration(config) => {
|
||||||
|
match config {
|
||||||
|
None => electrode_configuration = "No_multiplexer".to_string(),
|
||||||
|
Some(config) => {
|
||||||
|
electrode_configuration = match config {
|
||||||
|
ElectrodeConfiguration::WithMultiplexer2Lead(e1, e2) => format!("\"2({:?},{:?})\"", e1, e2),
|
||||||
|
ElectrodeConfiguration::WithMultiplexer4Lead(i1, i2, v1, v2) => format!("\"4({:?},{:?},{:?},{:?})\"", i1, i2, v1, v2),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
None => break, // Channel closed
|
None => break, // Channel closed
|
||||||
|
|||||||
@@ -15,4 +15,5 @@ pub enum LoggingSignal {
|
|||||||
StartFileLogging(String), // e.g. filename
|
StartFileLogging(String), // e.g. filename
|
||||||
StopFileLogging,
|
StopFileLogging,
|
||||||
AddMarker(String),
|
AddMarker(String),
|
||||||
|
ElectrodeCongiguration(Option<ElectrodeConfiguration>),
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user