Skip to content

Commit

Permalink
Added hardware bandwidth accessors, as available in underlying drivers.
Browse files Browse the repository at this point in the history
  • Loading branch information
metasim authored and bastibl committed Oct 27, 2024
1 parent 002a3c3 commit 3ada71a
Show file tree
Hide file tree
Showing 6 changed files with 114 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
/target
/Cargo.lock
.idea/
64 changes: 64 additions & 0 deletions src/device.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Range, Error>;

//================================ 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<f64, Error>;

/// 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<Range, Error>;
}

/// Wrapps a driver, implementing the [DeviceTrait].
Expand Down Expand Up @@ -572,6 +589,18 @@ impl<
fn get_sample_rate_range(&self, direction: Direction, channel: usize) -> Result<Range, Error> {
self.dev.get_sample_rate_range(direction, channel)
}

fn bandwidth(&self, direction: Direction, channel: usize) -> Result<f64, Error> {
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<Range, Error> {
self.dev.get_bandwidth_range(direction, channel)
}
}

#[doc(hidden)]
Expand Down Expand Up @@ -753,6 +782,18 @@ impl DeviceTrait for GenericDevice {
fn get_sample_rate_range(&self, direction: Direction, channel: usize) -> Result<Range, Error> {
self.as_ref().get_sample_rate_range(direction, channel)
}

fn bandwidth(&self, direction: Direction, channel: usize) -> Result<f64, Error> {
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<Range, Error> {
self.as_ref().get_bandwidth_range(direction, channel)
}
}

impl<
Expand Down Expand Up @@ -1030,4 +1071,27 @@ impl<
) -> Result<Range, Error> {
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<f64, Error> {
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<Range, Error> {
self.dev.get_bandwidth_range(direction, channel)
}
}
12 changes: 12 additions & 0 deletions src/impls/aaronia_http.rs
Original file line number Diff line number Diff line change
Expand Up @@ -540,6 +540,18 @@ impl DeviceTrait for AaroniaHttp {
_ => Err(Error::ValueError),
}
}

fn bandwidth(&self, _direction: Direction, _channel: usize) -> Result<f64, Error> {
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<Range, Error> {
Err(Error::NotSupported)
}
}

impl RxStreamer {
Expand Down
12 changes: 12 additions & 0 deletions src/impls/hackrfone.rs
Original file line number Diff line number Diff line change
Expand Up @@ -524,4 +524,16 @@ impl crate::DeviceTrait for HackRfOne {
Err(Error::ValueError)
}
}

fn bandwidth(&self, direction: Direction, channel: usize) -> Result<f64, Error> {
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<Range, Error> {
Err(Error::NotSupported)
}
}
12 changes: 12 additions & 0 deletions src/impls/rtlsdr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -402,6 +402,18 @@ impl DeviceTrait for RtlSdr {
Err(Error::NotSupported)
}
}

fn bandwidth(&self, _direction: Direction, _channel: usize) -> Result<f64, Error> {
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<Range, Error> {
Err(Error::NotSupported)
}
}

impl crate::RxStreamer for RxStreamer {
Expand Down
13 changes: 13 additions & 0 deletions src/impls/soapy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<f64, Error> {
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<Range, Error> {
let range = self.dev.bandwidth_range(direction.into(), channel)?;
Ok(range.into())
}
}

impl crate::RxStreamer for RxStreamer {
Expand Down

0 comments on commit 3ada71a

Please sign in to comment.