diff --git a/src/trx-server/src/audio.rs b/src/trx-server/src/audio.rs index 6f8fdb4..a2cc99e 100644 --- a/src/trx-server/src/audio.rs +++ b/src/trx-server/src/audio.rs @@ -223,8 +223,8 @@ pub struct DecoderHistories { } /// Acquire a mutex, recovering from poisoning with a warning log. -fn lock_or_recover(mutex: &Mutex, label: &str) -> std::sync::MutexGuard<'_, T> { - mutex.unwrap_or_else(|e| { +fn lock_or_recover<'a, T>(mutex: &'a Mutex, label: &str) -> std::sync::MutexGuard<'a, T> { + mutex.lock().unwrap_or_else(|e| { tracing::warn!( "Mutex for {} was poisoned (prior panic); recovering with potentially inconsistent data", label @@ -383,7 +383,7 @@ impl DecoderHistories { let before = h.len(); Self::prune_aprs(&mut h); self.adjust_total_count(before, h.len()); - h.iter().map(|(_, pkt)| pkt.clone()).collect() + h.iter().map(|(_, pkt): &(Instant, AprsPacket)| pkt.clone()).collect() } pub fn clear_aprs_history(&self) { @@ -426,7 +426,7 @@ impl DecoderHistories { let before = h.len(); Self::prune_hf_aprs(&mut h); self.adjust_total_count(before, h.len()); - h.iter().map(|(_, pkt)| pkt.clone()).collect() + h.iter().map(|(_, pkt): &(Instant, AprsPacket)| pkt.clone()).collect() } pub fn clear_hf_aprs_history(&self) { @@ -463,7 +463,7 @@ impl DecoderHistories { let before = h.len(); Self::prune_cw(&mut h); self.adjust_total_count(before, h.len()); - h.iter().map(|(_, evt)| evt.clone()).collect() + h.iter().map(|(_, evt): &(Instant, CwEvent)| evt.clone()).collect() } pub fn clear_cw_history(&self) { @@ -500,7 +500,7 @@ impl DecoderHistories { let before = h.len(); Self::prune_ft8(&mut h); self.adjust_total_count(before, h.len()); - h.iter().map(|(_, msg)| msg.clone()).collect() + h.iter().map(|(_, msg): &(Instant, Ft8Message)| msg.clone()).collect() } pub fn clear_ft8_history(&self) { @@ -537,7 +537,7 @@ impl DecoderHistories { let before = h.len(); Self::prune_ft4(&mut h); self.adjust_total_count(before, h.len()); - h.iter().map(|(_, msg)| msg.clone()).collect() + h.iter().map(|(_, msg): &(Instant, Ft8Message)| msg.clone()).collect() } pub fn clear_ft4_history(&self) { @@ -574,7 +574,7 @@ impl DecoderHistories { let before = h.len(); Self::prune_ft2(&mut h); self.adjust_total_count(before, h.len()); - h.iter().map(|(_, msg)| msg.clone()).collect() + h.iter().map(|(_, msg): &(Instant, Ft8Message)| msg.clone()).collect() } pub fn clear_ft2_history(&self) { @@ -611,7 +611,7 @@ impl DecoderHistories { let before = h.len(); Self::prune_wspr(&mut h); self.adjust_total_count(before, h.len()); - h.iter().map(|(_, msg)| msg.clone()).collect() + h.iter().map(|(_, msg): &(Instant, WsprMessage)| msg.clone()).collect() } pub fn clear_wspr_history(&self) { @@ -651,7 +651,7 @@ impl DecoderHistories { let before = h.len(); Self::prune_lrpt(&mut h); self.adjust_total_count(before, h.len()); - h.iter().map(|(_, img)| img.clone()).collect() + h.iter().map(|(_, img): &(Instant, LrptImage)| img.clone()).collect() } pub fn clear_lrpt_history(&self) { @@ -981,7 +981,7 @@ fn run_playback( mut rx: mpsc::Receiver, shutdown_rx: watch::Receiver, ) -> Result<(), Box> { - use cpal::traits::{DeviceTrait, HostTrait, StreamTrait}; + use cpal::traits::{DeviceTrait, StreamTrait}; use std::sync::mpsc::TryRecvError as StdTryRecvError; use tokio::sync::mpsc::error::TryRecvError as TokioTryRecvError; diff --git a/src/trx-server/src/main.rs b/src/trx-server/src/main.rs index 0fa1924..052f347 100644 --- a/src/trx-server/src/main.rs +++ b/src/trx-server/src/main.rs @@ -1097,9 +1097,7 @@ async fn main() -> DynResult<()> { rig_id_supervisor, e ); let mut err_state = state_tx.borrow().clone(); - err_state.machine_state = "Error".to_string(); - err_state.error_message = - Some(format!("Rig task terminated unexpectedly: {}", e)); + err_state.initialized = false; let _ = state_tx.send(err_state); } } diff --git a/src/trx-server/src/rig_task.rs b/src/trx-server/src/rig_task.rs index cc75943..edd1e76 100644 --- a/src/trx-server/src/rig_task.rs +++ b/src/trx-server/src/rig_task.rs @@ -30,7 +30,7 @@ use crate::error::is_invalid_bcd_error; /// Fallback poll refresh timeout used when no config value is provided. const DEFAULT_POLL_REFRESH_TIMEOUT: Duration = Duration::from_secs(8); /// Fallback command execution timeout used when no config value is provided. -const DEFAULT_COMMAND_EXEC_TIMEOUT: Duration = Duration::from_secs(10); +const DEFAULT_command_exec_timeout: Duration = Duration::from_secs(10); /// Configuration for the rig task. pub struct RigTaskConfig { pub registry: Arc, @@ -91,7 +91,7 @@ impl Default for RigTaskConfig { histories: DecoderHistories::new(), vfo_prime: true, prebuilt_rig: None, - command_exec_timeout: DEFAULT_COMMAND_EXEC_TIMEOUT, + command_exec_timeout: DEFAULT_command_exec_timeout, poll_refresh_timeout: DEFAULT_POLL_REFRESH_TIMEOUT, } } @@ -368,7 +368,7 @@ pub async fn run_rig_task( histories: &histories, }; let result = match time::timeout( - COMMAND_EXEC_TIMEOUT, + command_exec_timeout, process_command(RigCommand::GetSpectrum, &mut cmd_ctx), ) .await @@ -377,11 +377,11 @@ pub async fn run_rig_task( Err(_) => { error!( "Rig command GetSpectrum timed out after {:?}", - COMMAND_EXEC_TIMEOUT + command_exec_timeout ); Err(RigError::communication(format!( "command timed out after {:?}", - COMMAND_EXEC_TIMEOUT + command_exec_timeout ))) } }; @@ -408,18 +408,18 @@ pub async fn run_rig_task( histories: &histories, }; let result = - match time::timeout(COMMAND_EXEC_TIMEOUT, process_command(cmd, &mut cmd_ctx)) + match time::timeout(command_exec_timeout, process_command(cmd, &mut cmd_ctx)) .await { Ok(result) => result, Err(_) => { error!( "Rig command {} timed out after {:?}", - cmd_label, COMMAND_EXEC_TIMEOUT + cmd_label, command_exec_timeout ); Err(RigError::communication(format!( "command timed out after {:?}", - COMMAND_EXEC_TIMEOUT + command_exec_timeout ))) } };