From 079313313def1c0e516c78944f0f97989f029cde Mon Sep 17 00:00:00 2001 From: Stanislaw Grams Date: Thu, 12 Feb 2026 20:37:15 +0100 Subject: [PATCH] [refactor](trx-client): use RigState constructors Replace duplicated RigState initialization with new constructor methods. Changes: - Use RigState::new_uninitialized() in main.rs - Use RigState::from_snapshot() in remote_client.rs - Remove standalone state_from_snapshot() function These constructors eliminate 155 lines of duplicated struct literals and provide clear semantics for different initialization contexts. Co-Authored-By: Claude Haiku 4.5 Signed-off-by: Stanislaw Grams --- src/trx-client/src/main.rs | 43 +---------------------------- src/trx-client/src/remote_client.rs | 35 +---------------------- 2 files changed, 2 insertions(+), 76 deletions(-) diff --git a/src/trx-client/src/main.rs b/src/trx-client/src/main.rs index 3d2743e..3183b7f 100644 --- a/src/trx-client/src/main.rs +++ b/src/trx-client/src/main.rs @@ -21,8 +21,6 @@ use trx_core::audio::AudioStreamInfo; use trx_core::rig::request::RigRequest; use trx_core::rig::state::RigState; -use trx_core::rig::{RigControl, RigRxStatus, RigStatus, RigTxStatus}; -use trx_core::radio::freq::Freq; use trx_core::DynResult; use trx_frontend::{is_frontend_registered, registered_frontends}; use trx_core::decode::DecodedMessage; @@ -204,46 +202,7 @@ async fn async_init() -> DynResult { let (tx, rx) = mpsc::channel::(RIG_TASK_CHANNEL_BUFFER); - let initial_state = RigState { - rig_info: None, - status: RigStatus { - freq: Freq { hz: 144_300_000 }, - mode: trx_core::rig::state::RigMode::USB, - tx_en: false, - vfo: None, - tx: Some(RigTxStatus { - power: None, - limit: None, - swr: None, - alc: None, - }), - rx: Some(RigRxStatus { sig: None }), - lock: Some(false), - }, - initialized: false, - control: RigControl { - rpt_offset_hz: None, - ctcss_hz: None, - dcs_code: None, - lock: Some(false), - clar_hz: None, - clar_on: None, - enabled: Some(false), - }, - server_callsign: None, - server_version: None, - server_latitude: None, - server_longitude: None, - aprs_decode_enabled: false, - cw_decode_enabled: false, - cw_auto: true, - cw_wpm: 15, - cw_tone_hz: 700, - ft8_decode_enabled: false, - aprs_decode_reset_seq: 0, - cw_decode_reset_seq: 0, - ft8_decode_reset_seq: 0, - }; + let initial_state = RigState::new_uninitialized(); let (state_tx, state_rx) = watch::channel(initial_state); // Extract host for audio before moving remote_addr diff --git a/src/trx-client/src/remote_client.rs b/src/trx-client/src/remote_client.rs index 05f2da0..42a54e5 100644 --- a/src/trx-client/src/remote_client.rs +++ b/src/trx-client/src/remote_client.rs @@ -13,7 +13,6 @@ use tracing::{info, warn}; use trx_core::client::{ClientCommand, ClientEnvelope, ClientResponse}; use trx_core::rig::request::RigRequest; use trx_core::rig::state::RigState; -use trx_core::rig::RigControl; use trx_core::{RigError, RigResult}; use trx_protocol::rig_command_to_client; @@ -121,7 +120,7 @@ async fn send_command( if resp.success { if let Some(snapshot) = resp.state { - let _ = state_tx.send(state_from_snapshot(snapshot.clone())); + let _ = state_tx.send(RigState::from_snapshot(snapshot.clone())); return Ok(snapshot); } return Err(RigError::communication("missing snapshot")); @@ -132,38 +131,6 @@ async fn send_command( )) } -pub fn state_from_snapshot(snapshot: trx_core::RigSnapshot) -> RigState { - let status = snapshot.status; - let lock = status.lock; - RigState { - rig_info: Some(snapshot.info), - status, - initialized: snapshot.initialized, - control: RigControl { - rpt_offset_hz: None, - ctcss_hz: None, - dcs_code: None, - lock, - clar_hz: None, - clar_on: None, - enabled: snapshot.enabled, - }, - server_callsign: snapshot.server_callsign, - server_version: snapshot.server_version, - server_latitude: snapshot.server_latitude, - server_longitude: snapshot.server_longitude, - aprs_decode_enabled: snapshot.aprs_decode_enabled, - cw_decode_enabled: snapshot.cw_decode_enabled, - cw_auto: snapshot.cw_auto, - cw_wpm: snapshot.cw_wpm, - cw_tone_hz: snapshot.cw_tone_hz, - ft8_decode_enabled: snapshot.ft8_decode_enabled, - aprs_decode_reset_seq: 0, - cw_decode_reset_seq: 0, - ft8_decode_reset_seq: 0, - } -} - pub fn parse_remote_url(url: &str) -> Result { let trimmed = url.trim(); if trimmed.is_empty() {