Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

automatic DC offset corrections #17

Merged
merged 3 commits into from
Dec 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 51 additions & 0 deletions src/device.rs
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,22 @@ pub trait DeviceTrait: Any + Send {
///
/// Returns `Err(Error::NotSupported)` if unsupported in underlying driver.
fn get_bandwidth_range(&self, direction: Direction, channel: usize) -> Result<Range, Error>;

//========================= AUTOMATIC DC OFFSET CORRECTIONS ===============================

/// Returns true if automatic corrections are supported
fn has_dc_offset_mode(&self, direction: Direction, channel: usize) -> Result<bool, Error>;

/// Enable or disable automatic DC offset corrections mode.
fn set_dc_offset_mode(
&self,
direction: Direction,
channel: usize,
automatic: bool,
) -> Result<(), Error>;

/// Returns true if automatic DC offset mode is enabled
fn dc_offset_mode(&self, direction: Direction, channel: usize) -> Result<bool, Error>;
}

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

fn has_dc_offset_mode(&self, direction: Direction, channel: usize) -> Result<bool, Error> {
self.dev.has_dc_offset_mode(direction, channel)
}

fn set_dc_offset_mode(
&self,
direction: Direction,
channel: usize,
automatic: bool,
) -> Result<(), Error> {
self.dev.set_dc_offset_mode(direction, channel, automatic)
}

fn dc_offset_mode(&self, direction: Direction, channel: usize) -> Result<bool, Error> {
self.dev.dc_offset_mode(direction, channel)
}
}

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

fn has_dc_offset_mode(&self, direction: Direction, channel: usize) -> Result<bool, Error> {
self.as_ref().has_dc_offset_mode(direction, channel)
}

fn set_dc_offset_mode(
&self,
direction: Direction,
channel: usize,
automatic: bool,
) -> Result<(), Error> {
self.as_ref()
.set_dc_offset_mode(direction, channel, automatic)
}

fn dc_offset_mode(&self, direction: Direction, channel: usize) -> Result<bool, Error> {
self.as_ref().dc_offset_mode(direction, channel)
}
}

impl<
Expand Down
17 changes: 17 additions & 0 deletions src/impls/aaronia_http.rs
Original file line number Diff line number Diff line change
Expand Up @@ -552,6 +552,23 @@ impl DeviceTrait for AaroniaHttp {
fn get_bandwidth_range(&self, _direction: Direction, _channel: usize) -> Result<Range, Error> {
Err(Error::NotSupported)
}

fn has_dc_offset_mode(&self, _direction: Direction, _channel: usize) -> Result<bool, Error> {
Err(Error::NotSupported)
}

fn set_dc_offset_mode(
&self,
_direction: Direction,
_channel: usize,
_automatic: bool,
) -> Result<(), Error> {
Err(Error::NotSupported)
}

fn dc_offset_mode(&self, _direction: Direction, _channel: usize) -> Result<bool, Error> {
Err(Error::NotSupported)
}
}

impl RxStreamer {
Expand Down
17 changes: 17 additions & 0 deletions src/impls/dummy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -427,6 +427,23 @@ impl DeviceTrait for Dummy {
Err(Error::ValueError)
}
}

fn has_dc_offset_mode(&self, _direction: Direction, _channel: usize) -> Result<bool, Error> {
Err(Error::NotSupported)
}

fn set_dc_offset_mode(
&self,
_direction: Direction,
_channel: usize,
_automatic: bool,
) -> Result<(), Error> {
Err(Error::NotSupported)
}

fn dc_offset_mode(&self, _direction: Direction, _channel: usize) -> Result<bool, Error> {
Err(Error::NotSupported)
}
}

impl crate::RxStreamer for RxStreamer {
Expand Down
17 changes: 17 additions & 0 deletions src/impls/rtlsdr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -414,6 +414,23 @@ impl DeviceTrait for RtlSdr {
fn get_bandwidth_range(&self, _direction: Direction, _channel: usize) -> Result<Range, Error> {
Err(Error::NotSupported)
}

fn has_dc_offset_mode(&self, _direction: Direction, _channel: usize) -> Result<bool, Error> {
Err(Error::NotSupported)
}

fn set_dc_offset_mode(
&self,
_direction: Direction,
_channel: usize,
_automatic: bool,
) -> Result<(), Error> {
Err(Error::NotSupported)
}

fn dc_offset_mode(&self, _direction: Direction, _channel: usize) -> Result<bool, Error> {
Err(Error::NotSupported)
}
}

impl crate::RxStreamer for RxStreamer {
Expand Down
19 changes: 19 additions & 0 deletions src/impls/soapy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -320,6 +320,25 @@ impl DeviceTrait for Soapy {
let range = self.dev.bandwidth_range(direction.into(), channel)?;
Ok(range.into())
}

fn has_dc_offset_mode(&self, direction: Direction, channel: usize) -> Result<bool, Error> {
Ok(self.dev.has_dc_offset_mode(direction.into(), channel)?)
}

fn set_dc_offset_mode(
&self,
direction: Direction,
channel: usize,
automatic: bool,
) -> Result<(), Error> {
Ok(self
.dev
.set_dc_offset_mode(direction.into(), channel, automatic)?)
}

fn dc_offset_mode(&self, direction: Direction, channel: usize) -> Result<bool, Error> {
Ok(self.dev.dc_offset_mode(direction.into(), channel)?)
}
}

impl crate::RxStreamer for RxStreamer {
Expand Down
Loading