diff --git a/.gitignore b/.gitignore index 4fffb2f..91b8835 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ /target /Cargo.lock +.idea/ diff --git a/src/device.rs b/src/device.rs index 8938767..565cfc9 100644 --- a/src/device.rs +++ b/src/device.rs @@ -197,6 +197,23 @@ pub trait DeviceTrait: Any + Send { /// Get the range of possible baseband sample rates. fn get_sample_rate_range(&self, direction: Direction, channel: usize) -> Result; + + //================================ BANDWIDTH ============================================ + + /// Get the hardware bandwidth filter, if available. + /// + /// Returns `Err(Error::NotSupported)` if unsupported in underlying driver. + fn bandwidth(&self, direction: Direction, channel: usize) -> Result; + + /// Set the hardware bandwidth filter, if available. + /// + /// Returns `Err(Error::NotSupported)` if unsupported in underlying driver. + fn set_bandwidth(&self, direction: Direction, channel: usize, bw: f64) -> Result<(), Error>; + + /// Get the range of possible bandwidth filter values, if available. + /// + /// Returns `Err(Error::NotSupported)` if unsupported in underlying driver. + fn get_bandwidth_range(&self, direction: Direction, channel: usize) -> Result; } /// Wrapps a driver, implementing the [DeviceTrait]. @@ -572,6 +589,18 @@ impl< fn get_sample_rate_range(&self, direction: Direction, channel: usize) -> Result { self.dev.get_sample_rate_range(direction, channel) } + + fn bandwidth(&self, direction: Direction, channel: usize) -> Result { + self.dev.bandwidth(direction, channel) + } + + fn set_bandwidth(&self, direction: Direction, channel: usize, bw: f64) -> Result<(), Error> { + self.dev.set_bandwidth(direction, channel, bw) + } + + fn get_bandwidth_range(&self, direction: Direction, channel: usize) -> Result { + self.dev.get_bandwidth_range(direction, channel) + } } #[doc(hidden)] @@ -753,6 +782,18 @@ impl DeviceTrait for GenericDevice { fn get_sample_rate_range(&self, direction: Direction, channel: usize) -> Result { self.as_ref().get_sample_rate_range(direction, channel) } + + fn bandwidth(&self, direction: Direction, channel: usize) -> Result { + self.as_ref().bandwidth(direction, channel) + } + + fn set_bandwidth(&self, direction: Direction, channel: usize, bw: f64) -> Result<(), Error> { + self.as_ref().set_bandwidth(direction, channel, bw) + } + + fn get_bandwidth_range(&self, direction: Direction, channel: usize) -> Result { + self.as_ref().get_bandwidth_range(direction, channel) + } } impl< @@ -1030,4 +1071,27 @@ impl< ) -> Result { self.dev.get_sample_rate_range(direction, channel) } + + //================================ BANDWIDTH ============================================ + + /// Get the hardware bandwidth filter, if available. + /// + /// Returns `Err(Error::NotSupported)` if unsupported in underlying driver. + fn bandwidth(&self, direction: Direction, channel: usize) -> Result { + self.dev.bandwidth(direction, channel) + } + + /// Set the hardware bandwidth filter, if available. + /// + /// Returns `Err(Error::NotSupported)` if unsupported in underlying driver. + fn set_bandwidth(&self, direction: Direction, channel: usize, bw: f64) -> Result<(), Error> { + self.dev.set_bandwidth(direction, channel, bw) + } + + /// Get the range of possible bandwidth filter values, if available. + /// + /// Returns `Err(Error::NotSupported)` if unsupported in underlying driver. + fn get_bandwidth_range(&self, direction: Direction, channel: usize) -> Result { + self.dev.get_bandwidth_range(direction, channel) + } } diff --git a/src/impls/aaronia_http.rs b/src/impls/aaronia_http.rs index 9266a44..a9026c2 100644 --- a/src/impls/aaronia_http.rs +++ b/src/impls/aaronia_http.rs @@ -540,6 +540,18 @@ impl DeviceTrait for AaroniaHttp { _ => Err(Error::ValueError), } } + + fn bandwidth(&self, _direction: Direction, _channel: usize) -> Result { + Err(Error::NotSupported) + } + + fn set_bandwidth(&self, _direction: Direction, _channel: usize, _bw: f64) -> Result<(), Error> { + Err(Error::NotSupported) + } + + fn get_bandwidth_range(&self, _direction: Direction, _channel: usize) -> Result { + Err(Error::NotSupported) + } } impl RxStreamer { diff --git a/src/impls/hackrfone.rs b/src/impls/hackrfone.rs index aeef620..11d0afc 100644 --- a/src/impls/hackrfone.rs +++ b/src/impls/hackrfone.rs @@ -524,4 +524,16 @@ impl crate::DeviceTrait for HackRfOne { Err(Error::ValueError) } } + + fn bandwidth(&self, direction: Direction, channel: usize) -> Result { + Err(Error::NotSupported) + } + + fn set_bandwidth(&self, direction: Direction, channel: usize, bw: f64) -> Result<(), Error> { + Ok(self.inner.dev.set_baseband_filter_bandwidth(bw as _)?) + } + + fn get_bandwidth_range(&self, direction: Direction, channel: usize) -> Result { + Err(Error::NotSupported) + } } diff --git a/src/impls/rtlsdr.rs b/src/impls/rtlsdr.rs index a791461..3bfed52 100644 --- a/src/impls/rtlsdr.rs +++ b/src/impls/rtlsdr.rs @@ -402,6 +402,18 @@ impl DeviceTrait for RtlSdr { Err(Error::NotSupported) } } + + fn bandwidth(&self, _direction: Direction, _channel: usize) -> Result { + Err(Error::NotSupported) + } + + fn set_bandwidth(&self, _direction: Direction, _channel: usize, bw: f64) -> Result<(), Error> { + Ok(self.dev.set_tuner_bandwidth(bw as _)?) + } + + fn get_bandwidth_range(&self, _direction: Direction, _channel: usize) -> Result { + Err(Error::NotSupported) + } } impl crate::RxStreamer for RxStreamer { diff --git a/src/impls/soapy.rs b/src/impls/soapy.rs index a100602..73dd80c 100644 --- a/src/impls/soapy.rs +++ b/src/impls/soapy.rs @@ -294,6 +294,19 @@ impl DeviceTrait for Soapy { let range = self.dev.get_sample_rate_range(direction.into(), channel)?; Ok(range.into()) } + + fn bandwidth(&self, direction: Direction, channel: usize) -> Result { + Ok(self.dev.bandwidth(direction.into(), channel)?) + } + + fn set_bandwidth(&self, direction: Direction, channel: usize, bw: f64) -> Result<(), Error> { + Ok(self.dev.set_bandwidth(direction.into(), channel, bw)?) + } + + fn get_bandwidth_range(&self, direction: Direction, channel: usize) -> Result { + let range = self.dev.bandwidth_range(direction.into(), channel)?; + Ok(range.into()) + } } impl crate::RxStreamer for RxStreamer {