Struct hackrfone::HackRfOne[][src]

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

HackRF One software defined radio.

Implementations

Open a new HackRF One.

Example

use hackrfone::{HackRfOne, UnknownMode};

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

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));

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))

Read the board ID.

Example

use hackrfone::{HackRfOne, UnknownMode};

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

Read the firmware version.

Example

use hackrfone::{HackRfOne, UnknownMode};

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

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)?;

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)?;

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)?;

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)?;

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)?;

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)?;

Set the transmit VGA gain.

Range 0 to 47dB in 1db steps.

Antenna power port control.

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

CLKOUT enable.

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

Reset the HackRF radio.

Example

use hackrfone::{HackRfOne, UnknownMode};

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

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()?;

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()?;

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

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Performs the conversion.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.