pub struct HackRfOne<MODE> { /* private fields */ }
Expand description
HackRF One software defined radio.
Implementations§
Source§impl HackRfOne<UnknownMode>
impl HackRfOne<UnknownMode>
Source§impl<MODE> HackRfOne<MODE>
impl<MODE> HackRfOne<MODE>
Sourcepub fn device_version(&self) -> Version
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));
Sourcepub fn set_timeout(&mut self, duration: Duration)
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))
Sourcepub fn board_id(&self) -> Result<u8, Error>
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);
Sourcepub fn version(&self) -> Result<String, Error>
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");
Sourcepub fn set_freq(&mut self, hz: u64) -> Result<(), Error>
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)?;
Sourcepub fn set_amp_enable(&mut self, en: bool) -> Result<(), Error>
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)?;
Sourcepub fn set_baseband_filter_bandwidth(&mut self, hz: u32) -> Result<(), Error>
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)?;
Sourcepub fn set_sample_rate(&mut self, hz: u32, div: u32) -> Result<(), Error>
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)?;
Sourcepub fn set_lna_gain(&mut self, gain: u16) -> Result<(), Error>
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)?;
Sourcepub fn set_vga_gain(&mut self, gain: u16) -> Result<(), Error>
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)?;
Sourcepub fn set_txvga_gain(&mut self, gain: u16) -> Result<(), Error>
pub fn set_txvga_gain(&mut self, gain: u16) -> Result<(), Error>
Set the transmit VGA gain.
Range 0 to 47dB in 1db steps.
Sourcepub fn set_antenna_enable(&mut self, value: u8) -> Result<(), Error>
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.
Sourcepub fn set_clkout_enable(&mut self, en: bool) -> Result<(), Error>
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§impl HackRfOne<RxMode>
impl HackRfOne<RxMode>
Sourcepub fn rx(&mut self) -> Result<Vec<u8>, Error>
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()?;
Sourcepub fn stop_rx(self) -> Result<HackRfOne<UnknownMode>, Error>
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()?;