[feat](trx-server): add configurable display name for rigs
Add optional `name` field to RigInstanceConfig to allow long-form rig names (e.g., "HF Transceiver"). The name defaults to rig id if not configured. Add display_name() method to get display name with fallback to id. Propagate display_name through RigHandle to listener for GetRigs response. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -32,6 +32,9 @@ use trx_core::rig::state::RigMode;
|
|||||||
pub struct RigInstanceConfig {
|
pub struct RigInstanceConfig {
|
||||||
/// Stable rig identifier used in protocol routing.
|
/// Stable rig identifier used in protocol routing.
|
||||||
pub id: String,
|
pub id: String,
|
||||||
|
/// Display name for the rig (e.g., "HF Transceiver", "VHF/UHF SDR").
|
||||||
|
/// If not specified, defaults to the rig id.
|
||||||
|
pub name: Option<String>,
|
||||||
/// Rig backend configuration.
|
/// Rig backend configuration.
|
||||||
pub rig: RigConfig,
|
pub rig: RigConfig,
|
||||||
/// Polling and retry behavior.
|
/// Polling and retry behavior.
|
||||||
@@ -52,6 +55,7 @@ impl Default for RigInstanceConfig {
|
|||||||
fn default() -> Self {
|
fn default() -> Self {
|
||||||
Self {
|
Self {
|
||||||
id: "default".to_string(),
|
id: "default".to_string(),
|
||||||
|
name: None,
|
||||||
rig: RigConfig::default(),
|
rig: RigConfig::default(),
|
||||||
behavior: BehaviorConfig::default(),
|
behavior: BehaviorConfig::default(),
|
||||||
audio: AudioConfig::default(),
|
audio: AudioConfig::default(),
|
||||||
@@ -63,6 +67,14 @@ impl Default for RigInstanceConfig {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl RigInstanceConfig {
|
||||||
|
/// Get the display name for this rig.
|
||||||
|
/// Returns the configured name if set, otherwise the id.
|
||||||
|
pub fn display_name(&self) -> &str {
|
||||||
|
self.name.as_deref().unwrap_or(&self.id)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// Top-level server configuration structure.
|
/// Top-level server configuration structure.
|
||||||
#[derive(Debug, Clone, Default, Serialize, Deserialize)]
|
#[derive(Debug, Clone, Default, Serialize, Deserialize)]
|
||||||
#[serde(default)]
|
#[serde(default)]
|
||||||
@@ -618,6 +630,7 @@ impl ServerConfig {
|
|||||||
}
|
}
|
||||||
vec![RigInstanceConfig {
|
vec![RigInstanceConfig {
|
||||||
id: "default".to_string(),
|
id: "default".to_string(),
|
||||||
|
name: None,
|
||||||
rig: self.rig.clone(),
|
rig: self.rig.clone(),
|
||||||
behavior: self.behavior.clone(),
|
behavior: self.behavior.clone(),
|
||||||
audio: self.audio.clone(),
|
audio: self.audio.clone(),
|
||||||
|
|||||||
@@ -243,6 +243,7 @@ async fn handle_client(
|
|||||||
if let Some(snapshot) = state.snapshot() {
|
if let Some(snapshot) = state.snapshot() {
|
||||||
entries.push(RigEntry {
|
entries.push(RigEntry {
|
||||||
rig_id: handle.rig_id.clone(),
|
rig_id: handle.rig_id.clone(),
|
||||||
|
display_name: Some(handle.display_name.clone()),
|
||||||
state: snapshot,
|
state: snapshot,
|
||||||
audio_port: Some(handle.audio_port),
|
audio_port: Some(handle.audio_port),
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -798,6 +798,7 @@ async fn main() -> DynResult<()> {
|
|||||||
rig_cfg.id.clone(),
|
rig_cfg.id.clone(),
|
||||||
RigHandle {
|
RigHandle {
|
||||||
rig_id: rig_cfg.id.clone(),
|
rig_id: rig_cfg.id.clone(),
|
||||||
|
display_name: rig_cfg.display_name().to_string(),
|
||||||
rig_tx,
|
rig_tx,
|
||||||
state_rx,
|
state_rx,
|
||||||
audio_port: rig_cfg.audio.port,
|
audio_port: rig_cfg.audio.port,
|
||||||
|
|||||||
@@ -16,6 +16,8 @@ use trx_core::rig::state::RigState;
|
|||||||
pub struct RigHandle {
|
pub struct RigHandle {
|
||||||
/// Stable rig identifier, matches the key in the HashMap.
|
/// Stable rig identifier, matches the key in the HashMap.
|
||||||
pub rig_id: String,
|
pub rig_id: String,
|
||||||
|
/// Display name for the rig (from config, or rig_id if not set).
|
||||||
|
pub display_name: String,
|
||||||
/// Send commands to the rig task.
|
/// Send commands to the rig task.
|
||||||
pub rig_tx: mpsc::Sender<RigRequest>,
|
pub rig_tx: mpsc::Sender<RigRequest>,
|
||||||
/// Watch the latest rig state for fast GetState/GetRigs responses.
|
/// Watch the latest rig state for fast GetState/GetRigs responses.
|
||||||
|
|||||||
Reference in New Issue
Block a user