Struct rtlsdr::Device

source ·
pub struct Device { /* private fields */ }
Expand description

Device struct

Implementations§

source§

impl Device

source

pub fn open(&mut self) -> Result<(), RtlsdrError>

Open device This may fail due to a libusb error or some other unspecified error

source

pub fn close(&mut self) -> Result<(), String>

source

pub fn get_xtal_freq(&self) -> Result<(u32, u32), String>

Get crystal oscillator frequencies used for the RTL2832 and the tuner IC Usually both ICs use the same clock.

source

pub fn set_xtal_freq( &mut self, rtl_freq: u32, tuner_freq: u32 ) -> Result<(), String>

Set crystal oscillator frequencies used for the RTL2832 and the tuner IC. Usually both ICs use the same clock. Changing the clock may make sense if you are applying an external clock to the tuner or to compensate the frequency (and samplerate) error caused by the original (cheap) crystal. NOTE: Call this function only if you fully understand the implications.

source

pub fn get_usb_device_strings(&self) -> Result<(String, String, String), String>

Get USB device strings. @return (manufacturer, product, serial) strings

source

pub fn read_eeprom(&self, offset: u8, len: u16) -> Result<Vec<u8>, String>

Read the device EEPROM

source

pub fn write_eeprom(&mut self, offset: u8, buf: &mut [u8]) -> Result<(), String>

Write the device EEPROM

source

pub fn get_center_freq(&self) -> Result<u64, String>

Get actual frequency the device is tuned to in Hz

source

pub fn set_center_freq(&mut self, freq: u64) -> Result<(), String>

Set the frequency the device is tuned to in Hz

source

pub fn set_harmonic_rx(&mut self, harmonic: i32) -> Result<(), String>

Set harmonic reception - for R820T/2 tuner @param harmonic - receive n’th harmonic. 0 = default for disabling this

source

pub fn is_tuner_pll_locked(&self) -> Result<bool, String>

Check, if tuner PLL (frequency) is still locked. Tuner/PLL might loose lock (at high frequencies), e.g. for temperature reasons

source

pub fn get_freq_correction(&self) -> i32

Get actual frequency correction value of the device. @return correction value in parts per million (ppm)

source

pub fn set_freq_correction(&mut self, ppm: i32) -> Result<(), String>

Set frequency correction value for the device. @param ppm correction value in parts per million (ppm)

source

pub fn get_tuner_type(&self) -> TunerType

Get the tuner type

source

pub fn get_tuner_gains(&self) -> Vec<i32>

Get a list of gains supported by the tuner. Gain values in tenths of a dB, 115 means 11.5 dB

source

pub fn get_tuner_gain(&self) -> i32

Get actual (RF / HF) gain the device is configured to - excluding the IF gain. Gain in tenths of a dB, 115 means 11.5 dB. unfortunately it’s impossible to distinguish error against 0 dB

source

pub fn set_tuner_gain(&mut self, gain: i32) -> Result<(), String>

Set the gain for the device. Manual gain mode must be enabled for this to work. Valid gain values may be queried with rtlsdr_get_tuner_gains function. Gain in tenths of a dB, 115 means 11.5 dB

source

pub fn get_bandwidth(&self) -> Result<u32, String>

Get the bandwidth for the device. Zero means automatic BW selection.

source

pub fn set_tuner_bandwidth(&mut self, bw: u32) -> Result<(), String>

Set the bandwidth for the device. @param bw bandwidth in Hz. Zero means automatic BW selection.

source

pub fn set_tuner_band_center(&mut self, center: i32) -> Result<(), String>

Sets the center of the filtered tuner band(width) @param center in Hz. Zero means, that band center shall be at zero (=default). set if_band_center_freq = +samplerate/4 to have the filtered band centered at output’s right half.

source

pub fn set_tuner_sideband(&mut self, sideband: Sideband) -> Result<(), String>

Set the mixer sideband for the device.

source

pub fn set_tuner_gain_ext( &self, lna_gain: i32, mixer_gain: i32, vga_gain: i32 ) -> Result<(), String>

Set LNA / Mixer / VGA Device Gain for R820T/2 device is configured to. @param lna_gain index in 0 .. 15: 0 == min; see tuner_r82xx.c table r82xx_lna_gain_steps[] @param mixer_gain index in 0 .. 15: 0 == min; see tuner_r82xx.c table r82xx_mixer_gain_steps[] @param vga_gain index in 0 .. 15: 0 == -12 dB; 15 == 40.5 dB; => 3.5 dB/step; vga_gain index 16 activates AGC for VGA controlled from RTL2832 see tuner_r82xx.c table r82xx_vga_gain_steps[]

source

pub fn set_tuner_if_gain(&mut self, stage: i32, gain: i32) -> Result<(), String>

Set the intermediate frequency gain for the device. @param stage intermediate frequency gain stage number (1 to 6 for E4000) @param gain in tenths of a dB, -30 means -3.0 dB.

source

pub fn set_tuner_gain_mode(&mut self, manual: bool) -> Result<(), String>

Set the gain mode (automatic/manual) for the device. Manual gain mode must be enabled for the gain setter function to work.

source

pub fn set_tuner_if_mode(&mut self, agc_mode: i32) -> Result<(), String>

Set the agc_variant for automatic gain mode for the device (only R820T/2). Automatic gain mode must be enabled for the gain setter function to work. @param if_mode 0: set automatic VGA, which is controlled from RTL2832 -2500 .. +2500: set fixed IF gain in tenths of a dB, 115 means 11.5 dB. use -1 or +1 in case you neither want attenuation nor gain. this equals the VGA gain for R820T/2 tuner. exact values (R820T/2) are in range -47 .. 408 in tenth of a dB, giving -4.7 .. +40.8 dB. these exact values may slightly change with better measurements. 10000 .. 10015: IF gain == VGA index from parameter if_mode set if_mode by index: index := VGA_idx +10000 10016 .. 10031: same as 10000 .. 10015, but additionally set automatic VGA 10011: for fixed VGA (=default) of -12 dB + 11 * 3.5 dB = 26.5 dB

source

pub fn get_sample_rate(&self) -> Result<u32, String>

Get actual sample rate the device is configured to. @return sample rate in Hz

source

pub fn set_sample_rate(&mut self, rate: u32) -> Result<(), String>

Set the sample rate for the device. @param rate sample rate in Hz

source

pub fn set_test_mode(&mut self, test_mode: bool) -> Result<(), String>

Enable test mode that returns an 8 bit counter instead of the samples. The counter is generated inside the RTL2832.

source

pub fn set_agc_mode(&mut self, enabled: bool) -> Result<(), String>

Enable or disable the internal digital AGC of the RTL2832.

source

pub fn get_direct_sampling(&self) -> Result<DirectSampling, String>

Get state of the direct sampling mode

source

pub fn set_direct_sampling( &mut self, mode: DirectSampling ) -> Result<(), String>

Enable or disable the direct sampling mode. When enabled, the IF mode of the RTL2832 is activated, and set_center_freq() will control the IF-frequency of the DDC, which can be used to tune from 0 to 28.8 MHz (xtal frequency of the RTL2832).

source

pub fn set_ds_mode( &mut self, mode: DirectSamplingThreshold, freq_threshold: u32 ) -> Result<(), String>

Set direct sampling mode with threshold @param mode static modes 0 .. 2 as in rtlsdr_set_direct_sampling(). other modes do automatic switching @param freq_threshold direct sampling is used below this frequency, else quadrature mode through tuner set 0 for using default setting per tuner - not fully implemented yet!

source

pub fn get_offset_tuning(&self) -> Result<bool, String>

Get state of the offset tuning mode

source

pub fn set_offset_tuning(&mut self, enabled: bool) -> Result<(), String>

Enable or disable offset tuning for zero-IF tuners, which allows to avoid problems caused by the DC offset of the ADCs and 1/f noise.

source

pub fn set_dithering(&mut self, enabled: bool) -> Result<(), String>

Enable or disable frequency dithering for r820t tuners. Must be performed before freq_set(). Fails for other tuners.

source

pub fn reset_buffer(&mut self) -> Result<(), String>

Reset buffer in RTL2832

source

pub fn read_sync(&self, buf: &mut [u8]) -> Result<i32, RtlsdrError>

Read data synchronously

source

pub fn wait_async<F, U>(&self, cb: F, ctx: &mut U) -> Result<(), String>where F: FnMut(*mut u8, u32, &mut U),

👎Deprecated

Read samples from the device asynchronously. This function will block until it is being canceled using rtlsdr_cancel_async() NOTE: This function is deprecated and is subject for removal. @param cb callback function to return received samples @param ctx user specific context to pass via the callback function

source

pub fn read_async<F, U>( &self, cb: F, ctx: &mut U, buf_num: u32, buf_len: u32 ) -> Result<(), String>where F: FnMut(*mut u8, u32, &mut U),

Read samples from the device asynchronously. This function will block until it is being canceled using rtlsdr_cancel_async() @param cb callback function to return received samples @param ctx user specific context to pass via the callback function @param buf_num optional buffer count, buf_num * buf_len = overall buffer size set to 0 for default buffer count (15) @param buf_len optional buffer length, must be multiple of 512, should be a multiple of 16384 (URB size), set to 0 for default buffer length (16 * 32 * 512)

source

pub fn cancel_async(&self) -> Result<(), String>

Cancel all pending asynchronous operations on the device. Due to incomplete concurrency implementation, this should only be called from within the callback function, so it is in the correct thread.

source

pub fn ir_query(&self, buf: &mut [u8]) -> Result<i32, String>

Read from the remote control (RC) infrared (IR) sensor @param buf buffer to write IR signal (MSB=pulse/space, 7LSB=duration*20usec), recommended 128-bytes @param buf_len size of buf @return 0 if no signal, >0 number of bytes written into buf

source

pub fn set_bias_tee(&mut self, on: bool) -> Result<(), String>

Enable or disable (the bias tee on) GPIO PIN 0 - if not reconfigured. See rtlsdr_set_opt_string() option ‘T’. This works for rtl-sdr.com v3 dongles, see http://www.rtl-sdr.com/rtl-sdr-blog-v-3-dongles-user-guide/ Note: rtlsdr_close() does not clear GPIO lines, so it leaves the (bias tee) line enabled if a client program doesn’t explictly disable it.

source

pub fn set_bias_tee_gpio(&mut self, gpio: i32, on: bool) -> Result<(), String>

Enable or disable (the bias tee on) the given GPIO pin. Note: rtlsdr_close() does not clear GPIO lines, so it leaves the (bias tee) lines enabled if a client program doesn’t explictly disable it. @param gpio the gpio pin – assuming this line is connected to Bias T. gpio needs to be in 0 .. 7. BUT pin 4 is connected to Tuner RESET. and for FC0012 is already connected/reserved pin 6 for switching V/U-HF. @param on: 1 for Bias T on. 0 for Bias T off.

source

pub fn set_gpio_output(&mut self, gpio: u8) -> Result<(), String>

Setup a GPIO pin as output.

source

pub fn set_gpio_input(&mut self, gpio: u8) -> Result<(), String>

Setup a GPIO pin as input.

source

pub fn get_gpio_bit(&self, gpio: u8) -> Result<i32, String>

Read a bit from a GPIO pin.

source

pub fn set_gpio_bit(&mut self, gpio: u8, bit: i32) -> Result<(), String>

Write a bit to a GPIO pin.

source

pub fn get_gpio_byte(&self) -> Result<i32, String>

Read GPIO byte.

source

pub fn set_gpio_byte(&mut self, byte: i32) -> Result<(), String>

Write GPIO byte.

source

pub fn set_gpio_status(&mut self, status: i32) -> Result<(), String>

Set GPIO status

source

pub fn set_opt_string( &mut self, opts: String, verbose: bool ) -> Result<(), String>

Sets multiple options from a string encoded like “bw=300:agc=0:gain=27.3:dagc=0:T=1”. this is a helper function, that programs don’t need to implement every single option at the command line interface. Options are seperated by colon ‘:’. There mustn’t be extra spaces between option name and ‘=’. option ‘f’ set center frequency as in rtlsdr_set_center_freq() option ‘bw’ sets tuner bandwidth as in rtlsdr_set_tuner_bandwidth() - but value is in kHz. option ‘agc’ sets tuner gain mode as with rtlsdr_set_tuner_gain_mode(): ‘1’ means manual gain mode shall be enabled. option ‘gain’ sets tuner gain as with rtlsdr_set_tuner_gain(): values in tenth dB. option ‘dagc’ or ‘dgc’ de/activates digital agc as with rtlsdr_set_agc_mode(). 1 to enable. 0 to disable. option ‘ds’ set direct sampling as with rtlsdr_set_direct_sampling(): ‘0’ to deactivate, ‘1’ or ‘i’ for I-ADC input, ‘2’ or ‘q’ for Q-ADC input option ‘t’ or ‘T’ for enabling bias tee on GPIO PIN 0 as with rtlsdr_set_bias_tee(): ‘1’ for Bias T on. ‘0’ for Bias T off. @param opts described option string @param verbose print parsed options to stderr

source

pub fn get_opt_help(long_info: bool) -> String

Get opt help

source

pub fn get_tuner_i2c_register(&self, data: &mut [u8]) -> Result<(), String>

Get tuner i2c register

source

pub fn set_tuner_i2c_register( &mut self, i2c_register: u32, mask: u8, data: u8 ) -> Result<(), String>

Exposes/permits hacking of Tuner-specific I2C registers: set register once @param i2c_register register address @param mask 8-bit bitmask, indicating which bits shall be set @param data 8-bit data, which shall be set

source

pub fn set_tuner_i2c_override( &mut self, i2c_register: u32, mask: u8, data: u8 ) -> Result<(), String>

Exposes/permits hacking of Tuner-specific I2C registers: set and keep register for future @param i2c_register register address @param mask 8-bit bitmask, indicating which bits shall be set @param data 8-bit data, which shall be set; data in 0 .. 255 sets override; data > 255 clears override

source

pub fn get_version_id() -> &'static str

Request version id string to identify source and date of library

source

pub fn get_version() -> (u16, u16)

Request version numbers of library @return (major, minor)

Trait Implementations§

source§

impl Clone for Device

source§

fn clone(&self) -> Device

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl Debug for Device

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl Drop for Device

source§

fn drop(&mut self)

Executes the destructor for this type. Read more
source§

impl PartialEq<Device> for Device

source§

fn eq(&self, other: &Device) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl Eq for Device

source§

impl StructuralEq for Device

source§

impl StructuralPartialEq for Device

Auto Trait Implementations§

§

impl RefUnwindSafe for Device

§

impl !Send for Device

§

impl !Sync for Device

§

impl Unpin for Device

§

impl UnwindSafe for Device

Blanket Implementations§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for Twhere U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> ToOwned for Twhere T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T, U> TryFrom<U> for Twhere U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for Twhere U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.