[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:
+11
-11
@@ -223,8 +223,8 @@ pub struct DecoderHistories {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Acquire a mutex, recovering from poisoning with a warning log.
|
/// Acquire a mutex, recovering from poisoning with a warning log.
|
||||||
fn lock_or_recover<T>(mutex: &Mutex<T>, label: &str) -> std::sync::MutexGuard<'_, T> {
|
fn lock_or_recover<'a, T>(mutex: &'a Mutex<T>, label: &str) -> std::sync::MutexGuard<'a, T> {
|
||||||
mutex.unwrap_or_else(|e| {
|
mutex.lock().unwrap_or_else(|e| {
|
||||||
tracing::warn!(
|
tracing::warn!(
|
||||||
"Mutex for {} was poisoned (prior panic); recovering with potentially inconsistent data",
|
"Mutex for {} was poisoned (prior panic); recovering with potentially inconsistent data",
|
||||||
label
|
label
|
||||||
@@ -383,7 +383,7 @@ impl DecoderHistories {
|
|||||||
let before = h.len();
|
let before = h.len();
|
||||||
Self::prune_aprs(&mut h);
|
Self::prune_aprs(&mut h);
|
||||||
self.adjust_total_count(before, h.len());
|
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) {
|
pub fn clear_aprs_history(&self) {
|
||||||
@@ -426,7 +426,7 @@ impl DecoderHistories {
|
|||||||
let before = h.len();
|
let before = h.len();
|
||||||
Self::prune_hf_aprs(&mut h);
|
Self::prune_hf_aprs(&mut h);
|
||||||
self.adjust_total_count(before, h.len());
|
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) {
|
pub fn clear_hf_aprs_history(&self) {
|
||||||
@@ -463,7 +463,7 @@ impl DecoderHistories {
|
|||||||
let before = h.len();
|
let before = h.len();
|
||||||
Self::prune_cw(&mut h);
|
Self::prune_cw(&mut h);
|
||||||
self.adjust_total_count(before, h.len());
|
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) {
|
pub fn clear_cw_history(&self) {
|
||||||
@@ -500,7 +500,7 @@ impl DecoderHistories {
|
|||||||
let before = h.len();
|
let before = h.len();
|
||||||
Self::prune_ft8(&mut h);
|
Self::prune_ft8(&mut h);
|
||||||
self.adjust_total_count(before, h.len());
|
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) {
|
pub fn clear_ft8_history(&self) {
|
||||||
@@ -537,7 +537,7 @@ impl DecoderHistories {
|
|||||||
let before = h.len();
|
let before = h.len();
|
||||||
Self::prune_ft4(&mut h);
|
Self::prune_ft4(&mut h);
|
||||||
self.adjust_total_count(before, h.len());
|
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) {
|
pub fn clear_ft4_history(&self) {
|
||||||
@@ -574,7 +574,7 @@ impl DecoderHistories {
|
|||||||
let before = h.len();
|
let before = h.len();
|
||||||
Self::prune_ft2(&mut h);
|
Self::prune_ft2(&mut h);
|
||||||
self.adjust_total_count(before, h.len());
|
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) {
|
pub fn clear_ft2_history(&self) {
|
||||||
@@ -611,7 +611,7 @@ impl DecoderHistories {
|
|||||||
let before = h.len();
|
let before = h.len();
|
||||||
Self::prune_wspr(&mut h);
|
Self::prune_wspr(&mut h);
|
||||||
self.adjust_total_count(before, h.len());
|
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) {
|
pub fn clear_wspr_history(&self) {
|
||||||
@@ -651,7 +651,7 @@ impl DecoderHistories {
|
|||||||
let before = h.len();
|
let before = h.len();
|
||||||
Self::prune_lrpt(&mut h);
|
Self::prune_lrpt(&mut h);
|
||||||
self.adjust_total_count(before, h.len());
|
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) {
|
pub fn clear_lrpt_history(&self) {
|
||||||
@@ -981,7 +981,7 @@ fn run_playback(
|
|||||||
mut rx: mpsc::Receiver<Bytes>,
|
mut rx: mpsc::Receiver<Bytes>,
|
||||||
shutdown_rx: watch::Receiver<bool>,
|
shutdown_rx: watch::Receiver<bool>,
|
||||||
) -> Result<(), Box<dyn std::error::Error>> {
|
) -> 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 std::sync::mpsc::TryRecvError as StdTryRecvError;
|
||||||
use tokio::sync::mpsc::error::TryRecvError as TokioTryRecvError;
|
use tokio::sync::mpsc::error::TryRecvError as TokioTryRecvError;
|
||||||
|
|
||||||
|
|||||||
@@ -1097,9 +1097,7 @@ async fn main() -> DynResult<()> {
|
|||||||
rig_id_supervisor, e
|
rig_id_supervisor, e
|
||||||
);
|
);
|
||||||
let mut err_state = state_tx.borrow().clone();
|
let mut err_state = state_tx.borrow().clone();
|
||||||
err_state.machine_state = "Error".to_string();
|
err_state.initialized = false;
|
||||||
err_state.error_message =
|
|
||||||
Some(format!("Rig task terminated unexpectedly: {}", e));
|
|
||||||
let _ = state_tx.send(err_state);
|
let _ = state_tx.send(err_state);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -30,7 +30,7 @@ use crate::error::is_invalid_bcd_error;
|
|||||||
/// Fallback poll refresh timeout used when no config value is provided.
|
/// Fallback poll refresh timeout used when no config value is provided.
|
||||||
const DEFAULT_POLL_REFRESH_TIMEOUT: Duration = Duration::from_secs(8);
|
const DEFAULT_POLL_REFRESH_TIMEOUT: Duration = Duration::from_secs(8);
|
||||||
/// Fallback command execution timeout used when no config value is provided.
|
/// 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.
|
/// Configuration for the rig task.
|
||||||
pub struct RigTaskConfig {
|
pub struct RigTaskConfig {
|
||||||
pub registry: Arc<RegistrationContext>,
|
pub registry: Arc<RegistrationContext>,
|
||||||
@@ -91,7 +91,7 @@ impl Default for RigTaskConfig {
|
|||||||
histories: DecoderHistories::new(),
|
histories: DecoderHistories::new(),
|
||||||
vfo_prime: true,
|
vfo_prime: true,
|
||||||
prebuilt_rig: None,
|
prebuilt_rig: None,
|
||||||
command_exec_timeout: DEFAULT_COMMAND_EXEC_TIMEOUT,
|
command_exec_timeout: DEFAULT_command_exec_timeout,
|
||||||
poll_refresh_timeout: DEFAULT_POLL_REFRESH_TIMEOUT,
|
poll_refresh_timeout: DEFAULT_POLL_REFRESH_TIMEOUT,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -368,7 +368,7 @@ pub async fn run_rig_task(
|
|||||||
histories: &histories,
|
histories: &histories,
|
||||||
};
|
};
|
||||||
let result = match time::timeout(
|
let result = match time::timeout(
|
||||||
COMMAND_EXEC_TIMEOUT,
|
command_exec_timeout,
|
||||||
process_command(RigCommand::GetSpectrum, &mut cmd_ctx),
|
process_command(RigCommand::GetSpectrum, &mut cmd_ctx),
|
||||||
)
|
)
|
||||||
.await
|
.await
|
||||||
@@ -377,11 +377,11 @@ pub async fn run_rig_task(
|
|||||||
Err(_) => {
|
Err(_) => {
|
||||||
error!(
|
error!(
|
||||||
"Rig command GetSpectrum timed out after {:?}",
|
"Rig command GetSpectrum timed out after {:?}",
|
||||||
COMMAND_EXEC_TIMEOUT
|
command_exec_timeout
|
||||||
);
|
);
|
||||||
Err(RigError::communication(format!(
|
Err(RigError::communication(format!(
|
||||||
"command timed out after {:?}",
|
"command timed out after {:?}",
|
||||||
COMMAND_EXEC_TIMEOUT
|
command_exec_timeout
|
||||||
)))
|
)))
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@@ -408,18 +408,18 @@ pub async fn run_rig_task(
|
|||||||
histories: &histories,
|
histories: &histories,
|
||||||
};
|
};
|
||||||
let result =
|
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
|
.await
|
||||||
{
|
{
|
||||||
Ok(result) => result,
|
Ok(result) => result,
|
||||||
Err(_) => {
|
Err(_) => {
|
||||||
error!(
|
error!(
|
||||||
"Rig command {} timed out after {:?}",
|
"Rig command {} timed out after {:?}",
|
||||||
cmd_label, COMMAND_EXEC_TIMEOUT
|
cmd_label, command_exec_timeout
|
||||||
);
|
);
|
||||||
Err(RigError::communication(format!(
|
Err(RigError::communication(format!(
|
||||||
"command timed out after {:?}",
|
"command timed out after {:?}",
|
||||||
COMMAND_EXEC_TIMEOUT
|
command_exec_timeout
|
||||||
)))
|
)))
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user