rtltcp: github.com/bemasher/rtltcp Index | Examples | Files | Directories

package rtltcp

import "github.com/bemasher/rtltcp"

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

Code:

var sdr SDR

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

// Connect to address and defer close.
sdr.Connect(addr)
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...

Index

Examples

Package Files

rtltcp.go

type DongleInfo Uses

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 Uses

func (d DongleInfo) String() string

func (DongleInfo) Valid Uses

func (d DongleInfo) Valid() bool

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

type Flags Uses

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 Uses

type SDR struct {
    *net.TCPConn
    Flags Flags
    Info  DongleInfo
}

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

func (*SDR) Connect Uses

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

Give an address of the form "127.0.0.1:1234" 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 "127.0.0.1:1234" or command line flag value.

func (SDR) HandleFlags Uses

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 Uses

func (sdr *SDR) RegisterFlags()

Registers command line flags for rtltcp commands.

func (SDR) SetAGCMode Uses

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

Set RTL AGC mode, true for enabled.

func (SDR) SetCenterFreq Uses

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

Set the center frequency in Hz.

func (SDR) SetDirectSampling Uses

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

Set direct sampling mode.

func (SDR) SetFreqCorrection Uses

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

Set frequency correction in ppm.

func (SDR) SetGain Uses

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

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

func (SDR) SetGainByIndex Uses

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

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

func (SDR) SetGainMode Uses

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

Set the Tuner AGC, true to enable.

func (SDR) SetOffsetTuning Uses

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

Set offset tuning, true for enabled.

func (SDR) SetRTLXtalFreq Uses

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

Set RTL xtal frequency.

func (SDR) SetSampleRate Uses

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

Set the sample rate in Hz.

func (SDR) SetTestMode Uses

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

Set test mode, true for enabled.

func (SDR) SetTunerIfGain Uses

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

Set tuner intermediate frequency stage and gain.

func (SDR) SetTunerXtalFreq Uses

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

Set tuner xtal frequency.

type Tuner Uses

type Tuner uint32

Provides mapping of tuner value to tuner string.

func (Tuner) String Uses

func (t Tuner) String() string

Directories

PathSynopsis
si

Package rtltcp imports 6 packages (graph) and is imported by 1 packages. Updated 2018-01-09. Refresh now. Tools for package owners.