package module
v0.0.0-...-989d5f8 Latest Latest

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

Go to latest
Published: Apr 30, 2023 License: AGPL-3.0 Imports: 6 Imported by: 10



Go wrapper for the TCP protocol implemented by the rtl_tcp tool for Realtek DVB-T based SDR's by OsmoSDR. More documentation to come.





This package provides a wrapper for the TCP protocol implemented by the rtl_tcp tool used with Realtek DVB-T based SDR's.

Example (SDR)
var sdr SDR

// Resolve address, this may be ip:port or hostname:port.
addr, err := net.ResolveTCPAddr("tcp4", "")
if err != nil {
	log.Fatal("Error resolving address:", err)

// Connect to address and defer close.
defer sdr.Close()

// Print dongle info.
fmt.Printf("%+v\n", sdr.Info)
// Example: {Magic:"RTL0" Tuner:R820T GainCount:29}

// Create an array of bytes for samples.
buf := make([]byte, 16384)

// Read the entire array. This is usually done in a loop.
_, err = io.ReadFull(sdr, buf)
if err != nil {
	log.Fatal("Error reading samples:", err)

// Do something with data in buf...




This section is empty.


This section is empty.


This section is empty.


type DongleInfo

type DongleInfo struct {
	Magic     [4]byte
	Tuner     Tuner
	GainCount uint32 // Useful for setting gain by index

Contains the Magic number, tuner information and the number of valid gain values.

func (DongleInfo) String

func (d DongleInfo) String() string

func (DongleInfo) Valid

func (d DongleInfo) Valid() bool

Checks that the magic number received matches the expected byte string 'RTL0'.

type Flags

type Flags struct {
	ServerAddr     string
	CenterFreq     si.ScientificNotation
	SampleRate     si.ScientificNotation
	TunerGainMode  bool
	TunerGain      float64
	FreqCorrection int
	TestMode       bool
	AgcMode        bool
	DirectSampling bool
	OffsetTuning   bool
	RtlXtalFreq    uint
	TunerXtalFreq  uint
	GainByIndex    uint

type SDR

type SDR struct {
	Flags Flags
	Info  DongleInfo

Contains dongle information and an embedded tcp connection to the spectrum server

func (*SDR) Connect

func (sdr *SDR) Connect(addr *net.TCPAddr) (err error)

Give an address of the form "" connects to the spectrum server at the given address or returns an error. The user is responsible for closing this connection. If addr is nil, use "" or command line flag value.

func (SDR) HandleFlags

func (sdr SDR) HandleFlags() (err error)

Parses flags and executes commands associated with each flag. Should only be called once connected to rtl_tcp.

func (*SDR) RegisterFlags

func (sdr *SDR) RegisterFlags()

Registers command line flags for rtltcp commands.

func (SDR) SetAGCMode

func (sdr SDR) SetAGCMode(state bool) (err error)

Set RTL AGC mode, true for enabled.

func (SDR) SetCenterFreq

func (sdr SDR) SetCenterFreq(freq uint32) (err error)

Set the center frequency in Hz.

func (SDR) SetDirectSampling

func (sdr SDR) SetDirectSampling(state bool) (err error)

Set direct sampling mode.

func (SDR) SetFreqCorrection

func (sdr SDR) SetFreqCorrection(ppm uint32) (err error)

Set frequency correction in ppm.

func (SDR) SetGain

func (sdr SDR) SetGain(gain uint32) (err error)

Set gain in tenths of dB. (197 => 19.7dB)

func (SDR) SetGainByIndex

func (sdr SDR) SetGainByIndex(idx uint32) (err error)

Set gain by index, must be <= DongleInfo.GainCount

func (SDR) SetGainMode

func (sdr SDR) SetGainMode(state bool) (err error)

Set the Tuner AGC, true to enable.

func (SDR) SetOffsetTuning

func (sdr SDR) SetOffsetTuning(state bool) (err error)

Set offset tuning, true for enabled.

func (SDR) SetRTLXtalFreq

func (sdr SDR) SetRTLXtalFreq(freq uint32) (err error)

Set RTL xtal frequency.

func (SDR) SetSampleRate

func (sdr SDR) SetSampleRate(rate uint32) (err error)

Set the sample rate in Hz.

func (SDR) SetTestMode

func (sdr SDR) SetTestMode(state bool) (err error)

Set test mode, true for enabled.

func (SDR) SetTunerIfGain

func (sdr SDR) SetTunerIfGain(stage, gain uint16) (err error)

Set tuner intermediate frequency stage and gain.

func (SDR) SetTunerXtalFreq

func (sdr SDR) SetTunerXtalFreq(freq uint32) (err error)

Set tuner xtal frequency.

type Tuner

type Tuner uint32

Provides mapping of tuner value to tuner string.

func (Tuner) String

func (t Tuner) String() string


Path Synopsis

Jump to

Keyboard shortcuts

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