HackRf

Struct HackRf 

Source
pub struct HackRf { /* private fields */ }
Expand description

HackRF One software defined radio.

NOTE: The Hackrf may continue transmitting the latest samples it received if never dropped. Be sure to include a

Implementations§

Source§

impl HackRf

Source

pub fn open(info: DeviceInfo) -> Result<Self>

Opens info based on the result of a nusb scan.

Source

pub fn from_fd(fd: OwnedFd) -> Result<Self>

Available on Android or Linux only.

Wraps a HackRf One exposed through an existing file descriptor.

Useful on platforms like Android where UsbManager permits access to an fd.

Source

pub fn open_first() -> Result<HackRf>

Opens the first Hackrf One found via USB.

Source

pub fn scan() -> Result<Vec<(u8, u8)>>

Scans the usb bus for hackrf devices, returning the pair of (bus_num, bus_addr) for each device.

Source

pub fn open_bus(bus_number: u8, address: u8) -> Result<HackRf>

Opens a hackrf with usb address <bus_number>:<address>

Source

pub fn reset(self) -> Result<()>

Resets the HackRf.

Source

pub fn device_version(&self) -> UsbVersion

Returns the USB version of the device.

Source

pub fn board_id(&self) -> Result<u8>

Reads the board ID of the HackRF One device.

Source

pub fn version(&self) -> Result<String>

Read the firmware version.

Source

pub fn start_tx(&self, config: &Config) -> Result<()>

Transitions the radio into transmit mode. Call this function before calling Self::write.

Previous state set via set_xxx functions will be overridden with the parameters set in config.

§Errors

This function will return an error if a tx or rx operation is already in progress or if an I/O error occurs

Source

pub fn start_rx(&self, config: &Config) -> Result<()>

Transitions the radio into receive mode. Call this function before calling Self::read.

Previous state set via set_xxx functions will be overridden with the parameters set in config.

§Errors

This function will return an error if a tx or rx operation is already in progress or if an I/O error occurs

Source

pub fn stop(&self) -> Result<()>

Transitions the radio into off mode.

Source

pub fn read(&self, samples: &mut [u8]) -> Result<usize>

Read samples from the radio.

§Panics

This function panics if samples is not a multiple of 512

Source

pub fn write(&self, samples: &[u8]) -> Result<usize>

Writes samples to the radio.

§Panics

This function panics if samples is not a multiple of 512

Source

pub fn start_rx_stream( self: &Arc<Self>, transfer_size: usize, ) -> Result<RxStream>

Setup the device to stream samples.

When the stream is dropped, the device will be reset to the Off state, meaning Self::start_rx will be required before using the device again.

Source

pub fn start_tx_stream(self: &Arc<Self>) -> Result<TxStream>

Setup the device to stream samples.

When the stream is dropped, the device will be reset to the Off state, meaning Self::start_tx will be required before using the device again.

Source§

impl HackRf

Source

pub fn set_freq(&self, hz: u64) -> Result<()>

Set the center frequency.

Source

pub fn set_amp_enable(&self, enable: bool) -> Result<()>

Enable the RX/TX RF amplifier.

In GNU radio this is used as the RF gain, where a value of 0 dB is off, and a value of 14 dB is on.

Source

pub fn set_baseband_filter_bandwidth(&self, hz: u32) -> Result<()>

Set the baseband filter bandwidth.

This is automatically set when the sample rate is changed with Self::set_sample_rate.

Source

pub fn set_sample_rate(&self, hz: u32, div: u32) -> Result<()>

Set the sample rate.

For anti-aliasing, the baseband filter bandwidth is automatically set to the widest available setting that is no more than 75% of the sample rate. This happens every time the sample rate is set. If you want to override the baseband filter selection, you must do so after setting the sample rate.

Limits are 8MHz - 20MHz. Preferred rates are 8, 10, 12.5, 16, 20MHz due to less jitter.

Source

pub fn set_lna_gain(&self, gain: u16) -> Result<()>

Set the LNA (low noise amplifier) gain.

Range 0 to 40dB in 8dB steps.

This is also known as the IF gain.

Source

pub fn set_vga_gain(&self, gain: u16) -> Result<()>

Set the VGA (variable gain amplifier) gain.

Range 0 to 62dB in 2dB steps.

This is also known as the baseband (BB) gain.

Source

pub fn set_txvga_gain(&self, gain: u16) -> Result<()>

Set the transmit VGA gain.

Range 0 to 47dB in 1db steps.

Source

pub fn set_antenna_enable(&self, value: bool) -> Result<()>

Antenna power port control. Dhruv’s guess: is this DC bias?

The source docs are a little lacking in terms of explanations here.

Trait Implementations§

Source§

impl Drop for HackRf

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more

Auto Trait Implementations§

§

impl !Freeze for HackRf

§

impl RefUnwindSafe for HackRf

§

impl Send for HackRf

§

impl Sync for HackRf

§

impl Unpin for HackRf

§

impl UnwindSafe for HackRf

Blanket Implementations§

Source§

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

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

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

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where 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 T
where 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, U> TryFrom<U> for T
where U: Into<T>,

Source§

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 T
where U: TryFrom<T>,

Source§

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.