[fix](trx-server): fix compilation errors in audio, rig_task, and main

- Add lifetime parameter to lock_or_recover and fix missing .lock() call
- Replace undefined COMMAND_EXEC_TIMEOUT constant with local command_exec_timeout variable
- Add explicit type annotations to closure parameters in history snapshot methods
- Remove unused HostTrait import
- Fix non-existent machine_state/error_message fields on RigState in crash recovery

https://claude.ai/code/session_01HAkST2gLsYDXPom3282ABY
Signed-off-by: Claude <noreply@anthropic.com>
This commit is contained in:
Claude
2026-03-29 07:26:33 +00:00
committed by Stan Grams
parent 6c08ff4776
commit 01d0b9efdd
3 changed files with 20 additions and 22 deletions
+11 -11
View File
@@ -223,8 +223,8 @@ pub struct DecoderHistories {
}
/// Acquire a mutex, recovering from poisoning with a warning log.
fn lock_or_recover<T>(mutex: &Mutex<T>, label: &str) -> std::sync::MutexGuard<'_, T> {
mutex.unwrap_or_else(|e| {
fn lock_or_recover<'a, T>(mutex: &'a Mutex<T>, 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<Bytes>,
shutdown_rx: watch::Receiver<bool>,
) -> Result<(), Box<dyn std::error::Error>> {
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;
+1 -3
View File
@@ -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);
}
}
+8 -8
View File
@@ -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<RegistrationContext>,
@@ -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
)))
}
};