[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 <noreply@anthropic.com> Signed-off-by: Stanislaw Grams <stanislawgrams@gmail.com>
This commit is contained in:
@@ -21,8 +21,6 @@ use trx_core::audio::AudioStreamInfo;
|
|||||||
|
|
||||||
use trx_core::rig::request::RigRequest;
|
use trx_core::rig::request::RigRequest;
|
||||||
use trx_core::rig::state::RigState;
|
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_core::DynResult;
|
||||||
use trx_frontend::{is_frontend_registered, registered_frontends};
|
use trx_frontend::{is_frontend_registered, registered_frontends};
|
||||||
use trx_core::decode::DecodedMessage;
|
use trx_core::decode::DecodedMessage;
|
||||||
@@ -204,46 +202,7 @@ async fn async_init() -> DynResult<AppState> {
|
|||||||
|
|
||||||
let (tx, rx) = mpsc::channel::<RigRequest>(RIG_TASK_CHANNEL_BUFFER);
|
let (tx, rx) = mpsc::channel::<RigRequest>(RIG_TASK_CHANNEL_BUFFER);
|
||||||
|
|
||||||
let initial_state = RigState {
|
let initial_state = RigState::new_uninitialized();
|
||||||
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 (state_tx, state_rx) = watch::channel(initial_state);
|
let (state_tx, state_rx) = watch::channel(initial_state);
|
||||||
|
|
||||||
// Extract host for audio before moving remote_addr
|
// Extract host for audio before moving remote_addr
|
||||||
|
|||||||
@@ -13,7 +13,6 @@ use tracing::{info, warn};
|
|||||||
use trx_core::client::{ClientCommand, ClientEnvelope, ClientResponse};
|
use trx_core::client::{ClientCommand, ClientEnvelope, ClientResponse};
|
||||||
use trx_core::rig::request::RigRequest;
|
use trx_core::rig::request::RigRequest;
|
||||||
use trx_core::rig::state::RigState;
|
use trx_core::rig::state::RigState;
|
||||||
use trx_core::rig::RigControl;
|
|
||||||
use trx_core::{RigError, RigResult};
|
use trx_core::{RigError, RigResult};
|
||||||
use trx_protocol::rig_command_to_client;
|
use trx_protocol::rig_command_to_client;
|
||||||
|
|
||||||
@@ -121,7 +120,7 @@ async fn send_command(
|
|||||||
|
|
||||||
if resp.success {
|
if resp.success {
|
||||||
if let Some(snapshot) = resp.state {
|
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 Ok(snapshot);
|
||||||
}
|
}
|
||||||
return Err(RigError::communication("missing 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<String, String> {
|
pub fn parse_remote_url(url: &str) -> Result<String, String> {
|
||||||
let trimmed = url.trim();
|
let trimmed = url.trim();
|
||||||
if trimmed.is_empty() {
|
if trimmed.is_empty() {
|
||||||
|
|||||||
Reference in New Issue
Block a user