[feat](trx-server): add latitude/longitude config and propagation
Add latitude and longitude Option<f64> fields to [general] config section and propagate through ResolvedConfig, RigTaskConfig, and build_initial_state into the RigState/RigSnapshot pipeline. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> Signed-off-by: Stanislaw Grams <stanislawgrams@gmail.com>
This commit is contained in:
@@ -41,6 +41,10 @@ pub struct GeneralConfig {
|
||||
pub callsign: Option<String>,
|
||||
/// Log level (trace, debug, info, warn, error)
|
||||
pub log_level: Option<String>,
|
||||
/// Receiver latitude (decimal degrees, WGS84)
|
||||
pub latitude: Option<f64>,
|
||||
/// Receiver longitude (decimal degrees, WGS84)
|
||||
pub longitude: Option<f64>,
|
||||
}
|
||||
|
||||
impl Default for GeneralConfig {
|
||||
@@ -48,6 +52,8 @@ impl Default for GeneralConfig {
|
||||
Self {
|
||||
callsign: Some("N0CALL".to_string()),
|
||||
log_level: None,
|
||||
latitude: None,
|
||||
longitude: None,
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -244,6 +250,8 @@ impl ServerConfig {
|
||||
general: GeneralConfig {
|
||||
callsign: Some("N0CALL".to_string()),
|
||||
log_level: Some("info".to_string()),
|
||||
latitude: None,
|
||||
longitude: None,
|
||||
},
|
||||
rig: RigConfig {
|
||||
model: Some("ft817".to_string()),
|
||||
|
||||
@@ -108,6 +108,8 @@ struct ResolvedConfig {
|
||||
rig: String,
|
||||
access: RigAccess,
|
||||
callsign: Option<String>,
|
||||
latitude: Option<f64>,
|
||||
longitude: Option<f64>,
|
||||
}
|
||||
|
||||
fn resolve_config(cli: &Cli, cfg: &ServerConfig) -> DynResult<ResolvedConfig> {
|
||||
@@ -173,14 +175,20 @@ fn resolve_config(cli: &Cli, cfg: &ServerConfig) -> DynResult<ResolvedConfig> {
|
||||
.clone()
|
||||
.or_else(|| cfg.general.callsign.clone());
|
||||
|
||||
let latitude = cfg.general.latitude;
|
||||
let longitude = cfg.general.longitude;
|
||||
|
||||
Ok(ResolvedConfig {
|
||||
rig,
|
||||
access,
|
||||
callsign,
|
||||
latitude,
|
||||
longitude,
|
||||
})
|
||||
}
|
||||
|
||||
fn build_initial_state(cfg: &ServerConfig, callsign: &Option<String>) -> RigState {
|
||||
fn build_initial_state(cfg: &ServerConfig, resolved: &ResolvedConfig) -> RigState {
|
||||
let callsign = &resolved.callsign;
|
||||
RigState {
|
||||
rig_info: None,
|
||||
status: RigStatus {
|
||||
@@ -211,6 +219,8 @@ fn build_initial_state(cfg: &ServerConfig, callsign: &Option<String>) -> RigStat
|
||||
},
|
||||
server_callsign: callsign.clone(),
|
||||
server_version: Some(env!("CARGO_PKG_VERSION").to_string()),
|
||||
server_latitude: resolved.latitude,
|
||||
server_longitude: resolved.longitude,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -234,6 +244,8 @@ fn build_rig_task_config(
|
||||
initial_mode: cfg.rig.initial_mode.clone(),
|
||||
server_callsign: resolved.callsign.clone(),
|
||||
server_version: Some(env!("CARGO_PKG_VERSION").to_string()),
|
||||
server_latitude: resolved.latitude,
|
||||
server_longitude: resolved.longitude,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -284,7 +296,7 @@ async fn main() -> DynResult<()> {
|
||||
}
|
||||
|
||||
let (tx, rx) = mpsc::channel::<RigRequest>(RIG_TASK_CHANNEL_BUFFER);
|
||||
let initial_state = build_initial_state(&cfg, &resolved.callsign);
|
||||
let initial_state = build_initial_state(&cfg, &resolved);
|
||||
let (state_tx, state_rx) = watch::channel(initial_state);
|
||||
// Keep receivers alive so channels don't close prematurely
|
||||
let _state_rx = state_rx;
|
||||
|
||||
@@ -35,6 +35,8 @@ pub struct RigTaskConfig {
|
||||
pub initial_mode: RigMode,
|
||||
pub server_callsign: Option<String>,
|
||||
pub server_version: Option<String>,
|
||||
pub server_latitude: Option<f64>,
|
||||
pub server_longitude: Option<f64>,
|
||||
}
|
||||
|
||||
impl Default for RigTaskConfig {
|
||||
@@ -51,6 +53,8 @@ impl Default for RigTaskConfig {
|
||||
initial_mode: RigMode::USB,
|
||||
server_callsign: None,
|
||||
server_version: None,
|
||||
server_latitude: None,
|
||||
server_longitude: None,
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -86,6 +90,8 @@ pub async fn run_rig_task(
|
||||
let emitter = RigEventEmitter::new();
|
||||
let server_callsign = config.server_callsign.clone();
|
||||
let server_version = config.server_version.clone();
|
||||
let server_latitude = config.server_latitude;
|
||||
let server_longitude = config.server_longitude;
|
||||
let mut state = RigState {
|
||||
rig_info: None,
|
||||
status: RigStatus {
|
||||
@@ -114,6 +120,8 @@ pub async fn run_rig_task(
|
||||
},
|
||||
server_callsign,
|
||||
server_version,
|
||||
server_latitude,
|
||||
server_longitude,
|
||||
};
|
||||
|
||||
// Polling configuration
|
||||
|
||||
Reference in New Issue
Block a user