Struct HackRfOne

Source
pub struct HackRfOne<MODE> { /* private fields */ }
Expand description

HackRF One software defined radio.

Implementations§

Source§

impl HackRfOne<UnknownMode>

Source

pub fn new() -> Option<HackRfOne<UnknownMode>>

Open a new HackRF One.

§Example
use hackrfone::{HackRfOne, UnknownMode};

let mut radio: HackRfOne<UnknownMode> = HackRfOne::new().unwrap();
Source§

impl<MODE> HackRfOne<MODE>

Source

pub fn device_version(&self) -> Version

Get the device version from the USB descriptor.

The HackRF C API calls the equivalent of this function hackrf_usb_api_version_read.

§Example
use hackrfone::{rusb, HackRfOne, UnknownMode};

let mut radio: HackRfOne<UnknownMode> = HackRfOne::new().unwrap();
assert_eq!(radio.device_version(), rusb::Version(1, 0, 4));
Source

pub fn set_timeout(&mut self, duration: Duration)

Set the timeout for USB transfers.

§Example

Set a 100ms timeout.

use hackrfone::{HackRfOne, UnknownMode};
use std::time::Duration;

let mut radio: HackRfOne<UnknownMode> = HackRfOne::new().unwrap();
radio.set_timeout(Duration::from_millis(100))
Source

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

Read the board ID.

§Example
use hackrfone::{HackRfOne, UnknownMode};

let mut radio: HackRfOne<UnknownMode> = HackRfOne::new().unwrap();
assert_eq!(radio.board_id()?, 0x02);
Source

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

Read the firmware version.

§Example
use hackrfone::{HackRfOne, UnknownMode};

let mut radio: HackRfOne<UnknownMode> = HackRfOne::new().unwrap();
assert_eq!(radio.version()?, "2021.03.1");
Source

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

Set the center frequency.

§Example

Set the frequency to 915MHz.

use hackrfone::{HackRfOne, UnknownMode};

let mut radio: HackRfOne<UnknownMode> = HackRfOne::new().unwrap();
radio.set_freq(915_000_000)?;
Source

pub fn set_amp_enable(&mut self, en: bool) -> Result<(), Error>

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.

§Example

Disable the amplifier.

use hackrfone::{HackRfOne, UnknownMode};

let mut radio: HackRfOne<UnknownMode> = HackRfOne::new().unwrap();
radio.set_amp_enable(false)?;
Source

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

Set the baseband filter bandwidth.

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

§Example

Set the filter bandwidth to 70% of the sample rate.

use hackrfone::{HackRfOne, UnknownMode};

const SAMPLE_HZ: u32 = 20_000_000;
const SAMPLE_DIV: u32 = 2;
const FILTER_BW: u32 = (0.7 * (SAMPLE_HZ as f32) / (SAMPLE_DIV as f32)) as u32;

let mut radio: HackRfOne<UnknownMode> = HackRfOne::new().unwrap();
radio.set_sample_rate(SAMPLE_HZ, SAMPLE_DIV)?;
radio.set_baseband_filter_bandwidth(FILTER_BW)?;
Source

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

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.

§Example

Set the sample rate to 10 MHz.

use hackrfone::{HackRfOne, UnknownMode};

let mut radio: HackRfOne<UnknownMode> = HackRfOne::new().unwrap();
radio.set_sample_rate(20_000_000, 2)?;
Source

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

Set the LNA (low noise amplifier) gain.

Range 0 to 40dB in 8dB steps.

This is also known as the IF gain.

§Example

Set the LNA gain to 16 dB (generally a reasonable gain to start with).

use hackrfone::{HackRfOne, UnknownMode};

let mut radio: HackRfOne<UnknownMode> = HackRfOne::new().unwrap();
radio.set_lna_gain(16)?;
Source

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

Set the VGA (variable gain amplifier) gain.

Range 0 to 62dB in 2dB steps.

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

§Example

Set the VGA gain to 16 dB (generally a reasonable gain to start with).

use hackrfone::{HackRfOne, UnknownMode};

let mut radio: HackRfOne<UnknownMode> = HackRfOne::new().unwrap();
radio.set_vga_gain(16)?;
Source

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

Set the transmit VGA gain.

Range 0 to 47dB in 1db steps.

Source

pub fn set_antenna_enable(&mut self, value: u8) -> Result<(), Error>

Antenna power port control.

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

Source

pub fn set_clkout_enable(&mut self, en: bool) -> Result<(), Error>

CLKOUT enable.

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

Source

pub fn reset(self) -> Result<HackRfOne<UnknownMode>, Error>

Reset the HackRF radio.

§Example
use hackrfone::{HackRfOne, UnknownMode};

let mut radio: HackRfOne<UnknownMode> = HackRfOne::new().unwrap();
let mut radio: HackRfOne<UnknownMode> = radio.reset()?;
Source

pub fn into_rx_mode(self) -> Result<HackRfOne<RxMode>, Error>

Change the radio mode to RX.

§Example
use hackrfone::{HackRfOne, RxMode, UnknownMode};

let mut radio: HackRfOne<UnknownMode> = HackRfOne::new().unwrap();
let mut radio: HackRfOne<RxMode> = radio.into_rx_mode()?;
Source§

impl HackRfOne<RxMode>

Source

pub fn rx(&mut self) -> Result<Vec<u8>, Error>

Receive data from the radio.

This uses a bulk transfer to get one MTU (maximum transmission unit) of data in a single shot. The data format is pairs of signed 8-bit IQ. Use the iq_to_cplx_i8 or iq_to_cplx_f32 helpers to convert the data to a more manageable format.

Unlike libhackrf this does not spawn a sampling thread.

§Example
use hackrfone::{HackRfOne, RxMode, UnknownMode};

let mut radio: HackRfOne<UnknownMode> = HackRfOne::new().unwrap();
let mut radio: HackRfOne<RxMode> = radio.into_rx_mode()?;
let data: Vec<u8> = radio.rx()?;
radio.stop_rx()?;
Source

pub fn stop_rx(self) -> Result<HackRfOne<UnknownMode>, Error>

Stop receiving.

§Example
use hackrfone::{HackRfOne, RxMode, UnknownMode};

let mut radio: HackRfOne<UnknownMode> = HackRfOne::new().unwrap();
let mut radio: HackRfOne<RxMode> = radio.into_rx_mode()?;
let data: Vec<u8> = radio.rx()?;
radio.stop_rx()?;

Auto Trait Implementations§

§

impl<MODE> Freeze for HackRfOne<MODE>
where MODE: Freeze,

§

impl<MODE> RefUnwindSafe for HackRfOne<MODE>
where MODE: RefUnwindSafe,

§

impl<MODE> Send for HackRfOne<MODE>
where MODE: Send,

§

impl<MODE> Sync for HackRfOne<MODE>
where MODE: Sync,

§

impl<MODE> Unpin for HackRfOne<MODE>
where MODE: Unpin,

§

impl<MODE> UnwindSafe for HackRfOne<MODE>
where MODE: UnwindSafe,

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.