pub struct HackRf { /* private fields */ }Expand description
A HackRF device. This is the main struct for talking to the HackRF.
This provides all the settings to actively configure the HackRF while it is
off, as well as the ability to use debug or info fetching operations with
the HackRf::info and HackRf::debug functions. Some of these
operations are also exposed while receiving & transmitting, if it makes
sense to do so.
Implementations§
Source§impl HackRf
impl HackRf
Sourcepub async fn set_baseband_filter_bandwidth(
&self,
bandwidth_hz: u32,
) -> Result<(), Error>
pub async fn set_baseband_filter_bandwidth( &self, bandwidth_hz: u32, ) -> Result<(), Error>
Set the baseband filter bandwidth.
The possible settings are: 1.75, 2.5, 3.5, 5, 5.5, 6, 7, 8, 9, 10, 12, 14, 15, 20, 24, and 28 MHz. This function will choose the nearest, rounded down.
The default is to set this to 3/4 of the sample rate, rounded down to the nearest setting.
Setting the sample rate with set_sample_rate
will modify this setting.
Sourcepub async fn set_tx_underrun_limit(&self, val: u32) -> Result<(), Error>
pub async fn set_tx_underrun_limit(&self, val: u32) -> Result<(), Error>
Set the transmit underrun limit. This will cause the HackRF to stop operation if transmit runs out of samples to send. Set to 0 to disable.
This will also cause all outstanding transmits to stall forever, so some timeout will need to be added to the transmit completion futures.
Sourcepub async fn set_rx_overrun_limit(&self, val: u32) -> Result<(), Error>
pub async fn set_rx_overrun_limit(&self, val: u32) -> Result<(), Error>
Set the receive overrun limit. This will cause the HackRF to stop operation if more than the specified amount of samples get lost. Set to 0 to disable.
This will also cause all outstanding receives to stall forever, so some timeout will need to be added to the receive completion futures.
Sourcepub async fn set_freq(&self, freq_hz: u64) -> Result<(), Error>
pub async fn set_freq(&self, freq_hz: u64) -> Result<(), Error>
Set the operating frequency (recommended method).
This uses the internal frequency tuning code onboard the HackRF, which can differ between boards. It automatically sets the LO and IF frequencies, as well as the RF path filter.
Sourcepub async fn set_freq_explicit(
&self,
if_freq_hz: u64,
lo_freq_hz: u64,
path: RfPathFilter,
) -> Result<(), Error>
pub async fn set_freq_explicit( &self, if_freq_hz: u64, lo_freq_hz: u64, path: RfPathFilter, ) -> Result<(), Error>
Set the IF & LO tuning frequencies, and the RF path filter.
You may be looking for set_freq instead.
This sets the center frequency to f_c = f_IF + k * f_LO, where k is
-1, 0, or 1 depending on the filter selected.
IF frequency must be between 2-3 GHz, and it’s strongly recommended to be between 2170-2740 MHz.
LO frequency must be between 84.375-5400 MHz. No effect if the filter is set to bypass mode.
Sourcepub async fn set_sample_rate_manual(
&self,
freq_hz: u32,
divider: u32,
) -> Result<(), Error>
pub async fn set_sample_rate_manual( &self, freq_hz: u32, divider: u32, ) -> Result<(), Error>
Set the sample rate using a clock frequency in Hz and a divider value.
The resulting sample rate is freq_hz/divider. Divider value can be
1-31, and the rate range should be 2-20MHz. Lower & higher values are
technically possible, but not recommended.
This function will always call
set_baseband_filter_bandwidth,
so any changes to the filter should be done after this function.
You may want to just use set_sample_rate
instead.
Sourcepub async fn set_sample_rate(&self, freq: f64) -> Result<(), Error>
pub async fn set_sample_rate(&self, freq: f64) -> Result<(), Error>
Set the sample rate, which should be between 2-20 MHz.
Lower & higher rates are possible, but not recommended.
This function will always call
set_baseband_filter_bandwidth,
so any changes to the filter should be done after this function.
This function is a convenience wrapper around
set_sample_rate_manual.
Sourcepub async fn set_amp_enable(&self, enable: bool) -> Result<(), Error>
pub async fn set_amp_enable(&self, enable: bool) -> Result<(), Error>
Enable/disable the 14dB RF amplifiers.
Enable/disable the RX/TX amplifiers U13/U25 via the controlling switches U9 and U14.
Sourcepub async fn set_lna_gain(&self, value: u16) -> Result<(), Error>
pub async fn set_lna_gain(&self, value: u16) -> Result<(), Error>
Set the LNA gain.
Sets the RF RX gain of the MAX2837 transceiver IC. Must be in the range of 0-40 dB, and is forced to 8 dB steps. Intermediate values are rounded down.
Sourcepub async fn set_vga_gain(&self, value: u16) -> Result<(), Error>
pub async fn set_vga_gain(&self, value: u16) -> Result<(), Error>
Set the VGA gain.
Sets the baseband RX gain of the MAX2837 transceiver IC. Must be in the range of 0-62 dB, and is forced to 2 dB steps. Intermediate values are rounded down.
Sourcepub async fn set_txvga_gain(&self, value: u16) -> Result<(), Error>
pub async fn set_txvga_gain(&self, value: u16) -> Result<(), Error>
Set the RF TX gain.
Sets the RF TX gain of the MAX2837 transceiver IC. Must be in the range of 0-47 dB.
Sourcepub async fn set_antenna_enable(&self, enable: bool) -> Result<(), Error>
pub async fn set_antenna_enable(&self, enable: bool) -> Result<(), Error>
Temporarily enable/disable the bias-tee (antenna port power).
Enable or disable the 3.3v (max 50 mA) bias-tee. Defaults to disabled on power-up.
The firmware auto-disables this after returning to IDLE mode. Consider
using set_user_bias_t_opts instead to
configure the bias to work exactly the way you want it to.
Sourcepub async fn set_hw_sync_mode(&self, enable: bool) -> Result<(), Error>
pub async fn set_hw_sync_mode(&self, enable: bool) -> Result<(), Error>
Set hardware sync mode (hardware triggering).
See the documentation here.
When enabled, the next operating mode (RX, TX, or Sweep) will not start until the input hardware trigger occurs.
Requires API version 0x0102 or higher.
Sourcepub async fn operacake_boards(&self) -> Result<Vec<u8>, Error>
pub async fn operacake_boards(&self) -> Result<Vec<u8>, Error>
Get a list of what operacake boards are attached (up to 8).
Requires API version 0x0105 or higher.
Sourcepub async fn operacake_set_mode(
&self,
address: u8,
setting: OperacakeMode,
) -> Result<(), Error>
pub async fn operacake_set_mode( &self, address: u8, setting: OperacakeMode, ) -> Result<(), Error>
Set an Operacake board to a specific operating mode.
When set to frequency or dwell time mode, the settings are shared between all operacakes in that operating mode.
Requires API version 0x0105 or higher.
Sourcepub async fn operacake_get_mode(
&self,
address: u8,
) -> Result<OperacakeMode, Error>
pub async fn operacake_get_mode( &self, address: u8, ) -> Result<OperacakeMode, Error>
Get the operating mode of an operacake board.
Requires API version 0x0105 or higher.
Sourcepub async fn operacake_config_manual(
&self,
address: u8,
a: u8,
b: u8,
) -> Result<(), Error>
pub async fn operacake_config_manual( &self, address: u8, a: u8, b: u8, ) -> Result<(), Error>
Set an operacake’s switches manually.
Should be called after setting manual mode with
operacake_set_mode.
Requires API version 0x0102 or higher.
Sourcepub async fn operacake_config_freq(
&self,
freqs: &[OperacakeFreq],
) -> Result<(), Error>
pub async fn operacake_config_freq( &self, freqs: &[OperacakeFreq], ) -> Result<(), Error>
Match frequency bands to operacake ports.
These frequency settings are used by any operacake operating in frequency mode.
Requires API version 0x0103 or higher.
Sourcepub async fn operacake_config_time(
&self,
times: &[OperacakeDwell],
) -> Result<(), Error>
pub async fn operacake_config_time( &self, times: &[OperacakeDwell], ) -> Result<(), Error>
Match dwell times to operacake ports.
These dwell time settings are used by any operacake operating in time mode.
Requires API version 0x0105 or higher.
Sourcepub async fn reset(&self) -> Result<(), Error>
pub async fn reset(&self) -> Result<(), Error>
Reset the HackRF.
Requires API version 0x0102 or higher.
Sourcepub async fn clkout_enable(&self, enable: bool) -> Result<(), Error>
pub async fn clkout_enable(&self, enable: bool) -> Result<(), Error>
Turn on the CLKOUT port.
Requires API version 0x0103 or higher.
Sourcepub async fn clkin_status(&self) -> Result<bool, Error>
pub async fn clkin_status(&self) -> Result<bool, Error>
Check the CLKIN port status.
Set to true if the CLKIN port is used as the reference clock.
Requires API version 0x0106 or higher.
Sourcepub async fn operacake_gpio_test(&self, address: u8) -> Result<u16, Error>
pub async fn operacake_gpio_test(&self, address: u8) -> Result<u16, Error>
Perform a GPIO test of an Operacake board.
Value 0xFFFF means “GPIO mode disabled” - remove additional add-on boards and retry.
Value 0 means all tests passed.
In any other values, a 1 bit signals an error. Bits are grouped in groups of 3. Encoding:
0 - u1ctrl - u3ctrl0 - u3ctrl1 - u2ctrl0 - u2ctrl1Requires API version 0x0103 or higher.
Sourcepub async fn set_ui_enable(&self, val: u8) -> Result<(), Error>
pub async fn set_ui_enable(&self, val: u8) -> Result<(), Error>
Enable/disable the UI display on devices with one (Rad1o, PortaPack).
Requires API version 0x0104 or higher.
Sourcepub async fn set_leds(&self, state: u8) -> Result<(), Error>
pub async fn set_leds(&self, state: u8) -> Result<(), Error>
Turn the LEDs on or off, overriding the default.
There are normally 3 controllable LEDs: USB, RX, and TX. The Rad1o board has 4. After setting them individually, they may get overridden later by other functions.
| Bit | LED |
|---|---|
| 0 | USB |
| 1 | RX |
| 2 | TX |
| 3 | User |
Requires API version 0x0107 or higher.
Sourcepub async fn set_user_bias_t_opts(
&self,
opts: BiasTSetting,
) -> Result<(), Error>
pub async fn set_user_bias_t_opts( &self, opts: BiasTSetting, ) -> Result<(), Error>
Set the Bias-Tee behavior.
This function will configure what change, if any, to apply to the
bias-tee circuit on a mode change. The default is for it to always be
off, but with a custom config, it can turn on when switching to RX, TX,
or even to always be on. The settings in opts are always applied when
first changing to that mode, with BiasTMode::NoChange not changing
from whatever it is set to before the transition.
Requires API version 0x0108 or higher.
Sourcepub async fn start_rx(
self,
transfer_size: usize,
) -> Result<Receive, StateChangeError>
pub async fn start_rx( self, transfer_size: usize, ) -> Result<Receive, StateChangeError>
Switch a HackRF into receive mode, getting transfer_size samples at a
time. The transfer size is always rounded up to the nearest 256-sample
block increment; it’s recommended to be 8192 samples but can be smaller
or larger as needed. If the same size is used repeatedly with
start_rx, buffers won’t need to be reallocated.
Sourcepub async fn start_rx_sweep(
self,
params: &SweepParams,
) -> Result<Sweep, StateChangeError>
pub async fn start_rx_sweep( self, params: &SweepParams, ) -> Result<Sweep, StateChangeError>
Start a RX sweep, which will also set the sample rate and baseband filter.
Buffers are reused across sweep operations, provided that
HackRf::start_rx isn’t used, or is used with a 8192 sample buffer
size.
See Sweep for more details on the RX sweep mode.
Sourcepub async fn start_rx_sweep_custom_sample_rate(
self,
params: &SweepParams,
) -> Result<Sweep, StateChangeError>
pub async fn start_rx_sweep_custom_sample_rate( self, params: &SweepParams, ) -> Result<Sweep, StateChangeError>
Start a RX sweep, but don’t set up the sample rate and baseband filter before starting.
Buffers are reused across sweep operations, provided that
HackRf::start_rx isn’t used, or is used with a 8192 sample buffer
size.
See Sweep for more details on the RX sweep mode.