From 74749bc6de8d974fb5b121eb0587522ce09b40d3 Mon Sep 17 00:00:00 2001 From: Claude Date: Thu, 26 Mar 2026 06:41:36 +0000 Subject: [PATCH] [refactor](trx-core): split RigCat into base trait + RigSdr extension Extract 13 SDR-specific methods (set_center_freq, set_bandwidth, set_sdr_gain/lna/agc/squelch/nb, set_wfm_*, filter_state, get_spectrum, get_vchan_rds) into a new RigSdr trait. RigCat retains core CAT operations and gains as_sdr()/as_sdr_ref() for optional SDR access. Non-SDR backends no longer see SDR methods in their trait impl. https://claude.ai/code/session_01XzurkeuUmamBuhQwxVy7T4 Signed-off-by: Claude --- src/trx-core/src/rig/mod.rs | 46 +++++++++++++++++++++++++++++-------- 1 file changed, 36 insertions(+), 10 deletions(-) diff --git a/src/trx-core/src/rig/mod.rs b/src/trx-core/src/rig/mod.rs index 833e1ac..c256251 100644 --- a/src/trx-core/src/rig/mod.rs +++ b/src/trx-core/src/rig/mod.rs @@ -95,6 +95,10 @@ pub trait Rig { } /// Common CAT control operations any rig backend should implement. +/// +/// This trait covers basic transceiver operations shared by all backends +/// (serial rigs, SDRs, etc.). SDR-specific controls live in the +/// [`RigSdr`] extension trait, accessible via [`as_sdr`](RigCat::as_sdr). pub trait RigCat: Rig + Send { fn get_status<'a>(&'a mut self) -> RigStatusFuture<'a>; @@ -103,16 +107,6 @@ pub trait RigCat: Rig + Send { freq: Freq, ) -> Pin> + Send + 'a>>; - fn set_center_freq<'a>( - &'a mut self, - _freq: Freq, - ) -> Pin> + Send + 'a>> { - Box::pin(std::future::ready(Err( - Box::new(response::RigError::not_supported("set_center_freq")) - as Box, - ))) - } - fn set_mode<'a>( &'a mut self, mode: RigMode, @@ -150,6 +144,38 @@ pub trait RigCat: Rig + Send { None } + /// Return a mutable reference to the SDR extension trait, if this + /// backend supports SDR-specific operations. Default: `None`. + fn as_sdr(&mut self) -> Option<&mut dyn RigSdr> { + None + } + + /// Return an immutable reference to the SDR extension trait for + /// query-only operations (filter state, spectrum, RDS). + fn as_sdr_ref(&self) -> Option<&dyn RigSdr> { + None + } +} + +/// SDR-specific extension operations. +/// +/// Backends that support SDR features (center frequency, gain, AGC, +/// squelch, noise blanker, spectrum output, etc.) implement this trait. +/// Access it from a `dyn RigCat` via [`RigCat::as_sdr`]. +/// +/// All methods have default implementations returning "not supported" +/// or `None`, so backends need only override what they actually support. +pub trait RigSdr: Send { + fn set_center_freq<'a>( + &'a mut self, + _freq: Freq, + ) -> Pin> + Send + 'a>> { + Box::pin(std::future::ready(Err( + Box::new(response::RigError::not_supported("set_center_freq")) + as Box, + ))) + } + fn set_bandwidth<'a>( &'a mut self, _bandwidth_hz: u32,