Struct hackrfone::HackRfOne[][src]

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

HackRF One software defined radio.

Implementations

impl HackRfOne<UnknownMode>[src]

pub fn new() -> Option<HackRfOne<UnknownMode>>[src]

Open a new HackRF One.

Example

use hackrfone::{HackRfOne, UnknownMode};

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

impl<MODE> HackRfOne<MODE>[src]

pub fn device_version(&self) -> Version[src]

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

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

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

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

Read the board ID.

Example

use hackrfone::{HackRfOne, UnknownMode};

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

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

Read the firmware version.

Example

use hackrfone::{HackRfOne, UnknownMode};

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

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

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

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

Enable the RX/TX RF amplifier.

Example

Disable the amplifier.

use hackrfone::{HackRfOne, UnknownMode};

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

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

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

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

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

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

Set the LNA (low noise amplifier) gain.

Range 0 to 40dB in 8dB steps.

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

Set the VGA (variable gain amplifier) gain.

Range 0 to 62dB in 2dB steps.

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

Set the transmit VGA gain.

Range 0 to 47dB in 1db steps.

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

Antenna power port control.

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

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

CLKOUT enable.

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

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

Reset the HackRF radio.

Example

use hackrfone::{HackRfOne, UnknownMode};

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

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

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

impl HackRfOne<RxMode>[src]

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

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

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

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

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

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

The type returned in the event of a conversion error.