hackrf

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Jun 2, 2026 License: Apache-2.0 Imports: 8 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) 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) 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) 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) 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.

Jump to

Keyboard shortcuts

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