hackrf

package
v1.0.8 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 4, 2026 License: Apache-2.0 Imports: 7 Imported by: 0

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

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

func (d *Device) Close() error

Close stops any active stream and releases the USB handle.

func (*Device) FreqRange added in v0.5.9

func (d *Device) FreqRange() (minHz, maxHz uint32)

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

func (d *Device) Info() sdr.Info

Info implements sdr.Device.

func (*Device) SetBiasTee

func (d *Device) SetBiasTee(enable bool) error

SetBiasTee toggles the +3.3 V antenna-port bias for external LNAs.

func (*Device) SetCenterFreq

func (d *Device) SetCenterFreq(hz uint32) error

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

func (d *Device) SetFPGADCBlock(enable bool) error

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

func (d *Device) SetGain(tenthDB int) error

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

func (d *Device) SetNarrowbandFilter(enable bool) error

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

func (d *Device) SetPPM(int) error

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

func (d *Device) SetRFAmp(enable bool) error

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

func (d *Device) SetSampleRate(hz uint32) error

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.

func (*Device) StreamIQ

func (d *Device) StreamIQ(ctx context.Context) (<-chan []complex64, error)

StreamIQ flips the HackRF into receive mode and reaps bulk-IN URBs, converting each int8 IQ pair into a complex64 sample on the returned channel. Close (or ctx cancellation) stops the stream and returns the device to off-mode.

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.

func (*Driver) Enumerate

func (d *Driver) Enumerate() ([]sdr.Info, error)

Enumerate scans every HackRF PID variant and returns an sdr.Info per detected device. The descriptor list is cached so a subsequent Open reuses the same ordering.

func (*Driver) Name

func (d *Driver) Name() string

Name implements sdr.Driver.

func (*Driver) Open

func (d *Driver) Open(idx int) (sdr.Device, error)

Open claims the device at idx and returns an sdr.Device. The caller is responsible for calling Close.

type VIDPID added in v0.5.0

type VIDPID struct {
	VID  uint16
	PID  uint16
	Name string
}

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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL