feat(multi-rig): auto-discover per-rig audio ports via GetRigs

This commit is contained in:
2026-02-25 23:31:38 +01:00
parent b1c232f388
commit 47cff3f927
9 changed files with 50 additions and 12 deletions
+17 -2
View File
@@ -15,6 +15,7 @@ use tokio::net::TcpStream;
use tokio::sync::{broadcast, mpsc, watch};
use tokio::time;
use tracing::{info, warn};
use trx_frontend::RemoteRigEntry;
use trx_core::audio::{
read_audio_msg, write_audio_msg, AudioStreamInfo, AUDIO_MSG_APRS_DECODE, AUDIO_MSG_CW_DECODE,
@@ -29,6 +30,7 @@ pub async fn run_audio_client(
default_port: u16,
rig_ports: HashMap<String, u16>,
selected_rig_id: Arc<Mutex<Option<String>>>,
known_rigs: Arc<Mutex<Vec<RemoteRigEntry>>>,
rx_tx: broadcast::Sender<Bytes>,
mut tx_rx: mpsc::Receiver<Bytes>,
stream_info_tx: watch::Sender<Option<AudioStreamInfo>>,
@@ -47,6 +49,7 @@ pub async fn run_audio_client(
&server_host,
default_port,
&rig_ports,
&known_rigs,
selected_rig_id
.lock()
.ok()
@@ -63,6 +66,7 @@ pub async fn run_audio_client(
default_port,
&rig_ports,
&selected_rig_id,
&known_rigs,
&server_addr,
&rx_tx,
&mut tx_rx,
@@ -104,6 +108,7 @@ async fn handle_audio_connection(
default_port: u16,
rig_ports: &HashMap<String, u16>,
selected_rig_id: &Arc<Mutex<Option<String>>>,
known_rigs: &Arc<Mutex<Vec<RemoteRigEntry>>>,
connected_addr: &str,
rx_tx: &broadcast::Sender<Bytes>,
tx_rx: &mut mpsc::Receiver<Bytes>,
@@ -196,6 +201,7 @@ async fn handle_audio_connection(
server_host,
default_port,
rig_ports,
known_rigs,
current_rig.as_deref(),
);
if desired_addr != connected_addr {
@@ -217,11 +223,20 @@ fn resolve_audio_addr(
host: &str,
default_port: u16,
rig_ports: &HashMap<String, u16>,
known_rigs: &Arc<Mutex<Vec<RemoteRigEntry>>>,
selected_rig_id: Option<&str>,
) -> String {
let port = selected_rig_id
.and_then(|rig_id| rig_ports.get(rig_id))
.copied()
.and_then(|rig_id| {
rig_ports.get(rig_id).copied().or_else(|| {
known_rigs.lock().ok().and_then(|entries| {
entries
.iter()
.find(|entry| entry.rig_id == rig_id)
.and_then(|entry| entry.audio_port)
})
})
})
.unwrap_or(default_port);
format!("{}:{}", host, port)
}
+1
View File
@@ -295,6 +295,7 @@ async fn async_init() -> DynResult<AppState> {
cfg.frontends.audio.server_port,
audio_rig_ports,
frontend_runtime.remote_active_rig_id.clone(),
frontend_runtime.remote_rigs.clone(),
rx_audio_tx,
tx_audio_rx,
stream_info_tx,
+2
View File
@@ -278,6 +278,7 @@ fn cache_remote_rigs(config: &RemoteClientConfig, rigs: &[RigEntry]) {
.map(|entry| RemoteRigEntry {
rig_id: entry.rig_id.clone(),
state: entry.state.clone(),
audio_port: entry.audio_port,
})
.collect();
}
@@ -561,6 +562,7 @@ mod tests {
rigs: Some(vec![RigEntry {
rig_id: "default".to_string(),
state: snapshot.clone(),
audio_port: Some(4531),
}]),
error: None,
})
+1
View File
@@ -21,6 +21,7 @@ use trx_core::{DynResult, RigRequest, RigState};
pub struct RemoteRigEntry {
pub rig_id: String,
pub state: RigSnapshot,
pub audio_port: Option<u16>,
}
/// Trait implemented by concrete frontends to expose a runner entrypoint.
@@ -244,6 +244,7 @@ fn snapshot_remote_rigs(context: &FrontendRuntimeContext) -> Vec<RigEntry> {
.map(|entry| RigEntry {
rig_id: entry.rig_id.clone(),
state: entry.state.clone(),
audio_port: entry.audio_port,
})
.collect()
})