Documentation
¶
Overview ¶
Package hackrf is a pure-Go driver for the Great Scott Gadgets HackRF One software-defined radio, implementing the sdr.Driver and sdr.Device interfaces.
It speaks the libhackrf USB vendor protocol directly over the shared pure-Go USB transport at internal/sdr/rtlsdr/usb — the same transport that backs the RTL-SDR driver — so no CGO and no libhackrf are pulled into the build. Real-hardware validation against an attached HackRF One is a documented follow-up; the in-package tests exercise the wire protocol against a usb.MockTransport.
Sample format: HackRF delivers signed 8-bit interleaved IQ (I,Q,I,Q,…) on bulk endpoint 0x81 once SET_TRANSCEIVER_MODE has been flipped to receive. Each pair is converted to a complex64 sample with components in roughly [-1, 1].
Index ¶
- type Device
- func (d *Device) Close() error
- func (d *Device) FreqRange() (minHz, maxHz uint32)
- func (d *Device) Info() sdr.Info
- func (d *Device) SetBiasTee(enable bool) error
- func (d *Device) SetCenterFreq(hz uint32) error
- func (d *Device) SetFPGADCBlock(enable bool) error
- func (d *Device) SetGain(tenthDB int) error
- func (d *Device) SetNarrowbandFilter(enable bool) error
- func (d *Device) SetPPM(int) error
- func (d *Device) SetRFAmp(enable bool) error
- func (d *Device) SetSampleRate(hz uint32) error
- func (d *Device) StreamIQ(ctx context.Context) (<-chan []complex64, error)
- type Driver
- type VIDPID
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Device ¶
type Device struct {
// contains filtered or unexported fields
}
Device is one opened HackRF.
func (*Device) FreqRange ¶ added in v0.5.9
FreqRange reports the HackRF One's tuning span (sdr.FreqRanger). The device documents 1 MHz .. 6 GHz, but the sdr API carries frequency as uint32 Hz (ceiling ~4.294 GHz), so the upper bound is clamped to that ceiling — a whole-device sweep covers 1 MHz .. 4.294 GHz.
func (*Device) SetBiasTee ¶
SetBiasTee toggles the +3.3 V antenna-port bias for external LNAs.
func (*Device) SetCenterFreq ¶
SetCenterFreq programs the synthesizer to the requested frequency, in Hz. libhackrf splits the value into MHz + Hz-remainder octets.
func (*Device) SetFPGADCBlock ¶ added in v0.9.4
SetFPGADCBlock toggles the HackRF Pro's FPGA-side DC-offset blocker (sdr.FPGADCBlocker) — the gateware control register's bit 0. It removes the zero-IF DC spike in hardware, before the sample stream even leaves the device, which clears an on-channel-tuned C4FM eye that the centre spur would otherwise corrupt. A read-modify-write preserves the register's other bits. It is Pro-only: the gateware register space doesn't exist on other boards, so this errors there rather than writing to a register that isn't the one it names.
func (*Device) SetGain ¶
SetGain accepts a single tenth-dB target and distributes it across the HackRF's three gain stages (RF amp on/off, LNA 0–40 dB in 8 dB steps, VGA 0–62 dB in 2 dB steps). A negative value selects a hardware-friendly preset (amp off, LNA 16 dB, VGA 20 dB) — the HackRF has no true AGC, so "auto" maps to a sane fixed split.
func (*Device) SetNarrowbandFilter ¶ added in v0.9.4
SetNarrowbandFilter toggles the HackRF Pro's switchable narrowband anti-alias filter (sdr.NarrowbandFilterer). Engaging it tightens adjacent-channel rejection for narrowband signals — e.g. 12.5 kHz P25 voice channels — at the cost of usable RF bandwidth. It is Pro-only: on any other board the request would stall the control endpoint, so this returns an error there rather than sending it, letting the pool warn that the operator asked for a filter the hardware doesn't have.
func (*Device) SetPPM ¶
SetPPM is a no-op for HackRF — the Si5351C reference clock is internally trimmed and the protocol carries no PPM correction.
func (*Device) SetRFAmp ¶ added in v0.9.4
SetRFAmp toggles the HackRF's front-end RF amplifier and records the choice (sdr.RFAmper) so the "auto" gain preset re-asserts it on a later retune. It applies the state immediately, independent of SetGain ordering at pool setup. The amp lowers the noise figure for weak signals at the cost of ~14 dB of gain ahead of everything, so it is opt-in via the rf_amp device option and off by default.
func (*Device) SetSampleRate ¶
SetSampleRate programs the baseband sampler. libhackrf encodes the rate as a numerator/divider pair; this driver always uses a divider of 1 so the host sees exactly the requested rate.
type Driver ¶
type Driver struct {
// contains filtered or unexported fields
}
Driver implements sdr.Driver for HackRF.
func New ¶
func New(enum usb.Enumerator) *Driver
New returns a Driver that enumerates through the supplied USB backend. Pass nil to use the platform default enumerator.
type VIDPID ¶ added in v0.5.0
VIDPID is one USB identity the HackRF driver matches, exposed so `gophertrunk sdr doctor` can include HackRF in its driver-binding diagnostics. Mirrors the shape of purego.VIDPID so the doctor command can aggregate every pure-Go USB SDR into one report.
func KnownVIDPIDs ¶ added in v0.5.0
func KnownVIDPIDs() []VIDPID
KnownVIDPIDs returns the HackRF USB VID/PID variants this driver matches, in the same order Enumerate scans them. Used by `sdr doctor` to report which Windows function driver (WinUSB vs other) is bound to a connected HackRF — the in-box default is usually WinUSB via the device's WCID descriptor, but a wrong binding shows up here.