rtlsdr

package module
v2.10.0+incompatible Latest Latest
Warning

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

Go to latest
Published: Jun 20, 2017 License: BSD-3-Clause Imports: 5 Imported by: 13

README

gortlsdr version Build Status Godoc reference Go Report Card BSD3 License

Description

gortlsdr is a simple Go interface to devices supported by the RTL-SDR project, which turns certain USB DVB-T dongles employing the Realtek RTL2832U chipset into a low-cost, general purpose software-defined radio receiver. It wraps all the functions in the librtlsdr library (including asynchronous read support).

Supported Platforms:

  • Linux
  • OS X
  • Windows (with a little work)

Installation

Dependencies

Usage

All functions in librtlsdr are accessible from the gortlsdr package:

go get -u github.com/jpoirier/gortlsdr

Example

See the eample.go file:

go run example.go

Windows

If you don't want to build the librtlsdr and libusb dependencies from source you can use the librtlsdr pre-built package, which includes libusb, but you're restricted to building a 32-bit gortlsdr library.

Building gortlsdr on Windows:

  • Download and install git.

  • Download and install the Go tools. Create a "go-pkgs" directory-your user folder is a good location-and add a GOPATH variable to your system environment, where GOPATH is set to the go-pkgs path, e.g. GOPATH=c:\users\jpoirier\go-pkgs.

  • Download the pre-built rtl-sdr library and unzip it, e.g. to your user folder. Note the path to the header files and the *.dll files in the x32 folder.

  • Download gortlsdr, but don't install the package:

        go get -d github.com/jpoirier/gortlsdr
    
  • Set CFLAGS and LDFLAGS in rtlsdr.go. Open the rtlsdr.go file in an editor, it'll be in go-pkgs\src\github.com\jpoirier\gortlsdr, and set the following two windows specific flags shown below, but with the correct paths from your system. CFLAGS points to the header files and LDFLAGS to the *.dll files:

        cgo windows CFLAGS: -IC:/Users/jpoirier/rtlsdr
        cgo windows LDFLAGS: -lrtlsdr -LC:/Users/jpoirier/rtlsdr/x32
    
  • Build gortlsdr:

        go install github.com/jpoirier/gortlsdr
    
  • Insert the DVB-T/DAB/FM dongle into a USB port, open a shell window in go-pkgs\src\github.com\jpoirier\gortlsdr and run the example program: go run example.go. Note, the pre-built rtl-sdr package contains several test executables as well.

Credit

Todo

-joe

Documentation

Index

Constants

View Source
const (
	// EepromSize is the char size of the EEPROM
	EepromSize = 256
	// MaxStrSize = (max string length - 2 (header bytes)) \ 2,
	// where each info char is followed by a null char.
	MaxStrSize = 35
	// StrOffsetStart is the string descriptor offset start
	StrOffsetStart = 0x09
)
View Source
const (
	DefaultGAIN           = "auto"
	DefaultFc             = 80e6
	DefaultRs             = 1.024e6
	DefaultReadSize       = 1024
	CrystalFreq           = 28800000
	DefaultSampleRate     = 2048000
	DefaultAsyncBufNumber = 32
	DefaultBufLength      = (16 * 16384)
	MinimalBufLength      = 512
	MaximalBufLength      = (256 * 16384)
	LIBUSB_ERROR_OTHER    = -99
)

These constants are used to set default parameter values.

Variables

View Source
var PackageVersion = "v2.10.0"

PackageVersion is the current version

View Source
var SamplingModes = map[SamplingMode]string{
	SamplingNone:    "Disabled",
	SamplingIADC:    "I-ADC Enabled",
	SamplingQADC:    "Q-ADC Enabled",
	SamplingUnknown: "Unknown",
}

SamplingModes is a map of available sampling modes.

Functions

func GetDeviceCount

func GetDeviceCount() (count int)

GetDeviceCount returns the number of devices detected.

func GetDeviceName

func GetDeviceName(index int) (name string)

GetDeviceName returns the name of the device by index.

func GetDeviceUsbStrings

func GetDeviceUsbStrings(index int) (manufact, product, serial string, err error)

GetDeviceUsbStrings returns the information of a device by index.

func GetIndexBySerial

func GetIndexBySerial(serial string) (index int, err error)

GetIndexBySerial returns a device index by serial id.

func GetStringDescriptors

func GetStringDescriptors(data []uint8) (manufact, product, serial string, err error)

GetStringDescriptors gets the manufacturer, product, and serial strings from the hardware's eeprom.

func SetStringDescriptors

func SetStringDescriptors(info HwInfo, data []uint8) (err error)

SetStringDescriptors sets the manufacturer, product, and serial strings on the hardware's eeprom.

Types

type Context

type Context C.rtlsdr_dev_t

Context is the opened device's context.

func Open

func Open(index int) (*Context, error)

Open returns an opened device by index.

func (*Context) CancelAsync

func (dev *Context) CancelAsync() error

CancelAsync cancels all pending asynchronous operations.

func (*Context) Close

func (dev *Context) Close() (err error)

Close closes the device.

func (*Context) GetCenterFreq

func (dev *Context) GetCenterFreq() (freqHz int)

GetCenterFreq returns the tuned frequency or zero on error.

func (*Context) GetDirectSampling

func (dev *Context) GetDirectSampling() (mode SamplingMode, err error)

GetDirectSampling returns the state of direct sampling mode.

func (*Context) GetFreqCorrection

func (dev *Context) GetFreqCorrection() (ppm int)

GetFreqCorrection returns the frequency correction value.

func (*Context) GetHwInfo

func (dev *Context) GetHwInfo() (info HwInfo, err error)

GetHwInfo gets the dongle's information items.

func (*Context) GetOffsetTuning

func (dev *Context) GetOffsetTuning() (enabled bool, err error)

GetOffsetTuning returns the offset tuning mode.

func (*Context) GetSampleRate

func (dev *Context) GetSampleRate() (rateHz int)

GetSampleRate returns the sample rate.

func (*Context) GetTunerGain

func (dev *Context) GetTunerGain() (gainTenthsDb int)

GetTunerGain returns the tuner gain.

Gain values are in tenths of dB, e.g. 115 means 11.5 dB.

func (*Context) GetTunerGains

func (dev *Context) GetTunerGains() (gainsTenthsDb []int, err error)

GetTunerGains returns a list of supported tuner gains. Values are in tenths of dB, e.g. 115 means 11.5 dB.

func (*Context) GetTunerType

func (dev *Context) GetTunerType() (tunerType string)

GetTunerType returns the tuner type.

func (*Context) GetUsbStrings

func (dev *Context) GetUsbStrings() (manufact, product, serial string, err error)

GetUsbStrings returns the device information. Note, strings may be empty.

func (*Context) GetXtalFreq

func (dev *Context) GetXtalFreq() (rtlFreqHz, tunerFreqHz int, err error)

GetXtalFreq returns the crystal oscillator frequencies. Typically both ICs use the same clock.

func (*Context) ReadAsync

func (dev *Context) ReadAsync(f ReadAsyncCbT, _ *UserCtx, bufNum, bufLen int) error

ReadAsync reads samples asynchronously. Note, this function will block until canceled using CancelAsync. ReadAsyncCbT is a package global variable and therefore unsafe for use with multiple dongles.

Note, please use ReadAsync2 as this method will be deprecated in the future.

Optional bufNum buffer count, bufNum * bufLen = overall buffer size, set to 0 for default buffer count (32). Optional bufLen buffer length, must be multiple of 512, set to 0 for default buffer length (16 * 32 * 512).

func (*Context) ReadEeprom

func (dev *Context) ReadEeprom(data []uint8, offset uint8, leng uint16) (err error)

ReadEeprom returns data read from the EEPROM.

func (*Context) ReadSync

func (dev *Context) ReadSync(buf []uint8, leng int) (nRead int, err error)

ReadSync performs a synchronous read of samples and returns the number of samples read.

func (*Context) ResetBuffer

func (dev *Context) ResetBuffer() (err error)

ResetBuffer resets the streaming buffer.

func (*Context) SetAgcMode

func (dev *Context) SetAgcMode(AGCMode bool) (err error)

SetAgcMode sets the AGC mode.

func (*Context) SetBiasTee

func (dev *Context) SetBiasTee(enable bool) error

SetBiasTee enables or disables bias tee.

func (*Context) SetCenterFreq

func (dev *Context) SetCenterFreq(freqHz int) (err error)

SetCenterFreq sets the center frequency.

func (*Context) SetDirectSampling

func (dev *Context) SetDirectSampling(mode SamplingMode) (err error)

SetDirectSampling sets the direct sampling mode.

When enabled, the IF mode of the device is activated, and SetCenterFreq() will control the IF-frequency of the DDC, which can be used to tune from 0 to 28.8 MHz (xtal frequency of the device).

func (*Context) SetFreqCorrection

func (dev *Context) SetFreqCorrection(ppm int) (err error)

SetFreqCorrection sets the frequency correction.

func (*Context) SetHwInfo

func (dev *Context) SetHwInfo(info HwInfo) (err error)

SetHwInfo sets the dongle's information items.

func (*Context) SetOffsetTuning

func (dev *Context) SetOffsetTuning(enable bool) (err error)

SetOffsetTuning sets the offset tuning mode for zero-IF tuners, which avoids problems caused by the DC offset of the ADCs and 1/f noise.

func (*Context) SetSampleRate

func (dev *Context) SetSampleRate(rateHz int) (err error)

SetSampleRate sets the sample rate.

When applicable, the baseband filters are also selected based on the requested sample rate.

func (*Context) SetTestMode

func (dev *Context) SetTestMode(testMode bool) (err error)

SetTestMode sets device to test mode.

Test mode returns 8 bit counters instead of samples. Note, the counter is generated inside the device.

func (*Context) SetTunerBw

func (dev *Context) SetTunerBw(bwHz int) (err error)

SetTunerBw sets the device bandwidth.

func (*Context) SetTunerGain

func (dev *Context) SetTunerGain(gainTenthsDb int) (err error)

SetTunerGain sets the tuner gain. Note, manual gain mode must be enabled for this to work. Valid gain values may be queried using GetTunerGains.

Gain values are in tenths of dB, e.g. 115 means 11.5 dB.

func (*Context) SetTunerGainMode

func (dev *Context) SetTunerGainMode(manualMode bool) (err error)

SetTunerGainMode sets the gain mode (automatic/manual). Manual gain mode must be enabled for the gain setter function to work.

func (*Context) SetTunerIfGain

func (dev *Context) SetTunerIfGain(stage, gainTenthsDb int) (err error)

SetTunerIfGain sets the intermediate frequency gain.

Intermediate frequency gain stage number 1 to 6. Gain values are in tenths of dB, e.g. -30 means -3.0 dB.

func (*Context) SetXtalFreq

func (dev *Context) SetXtalFreq(rtlFreqHz, tunerFreqHz int) (err error)

SetXtalFreq sets the crystal oscillator frequencies.

Typically both ICs use the same clock. Changing the clock may make sense if you are applying an external clock to the tuner or to compensate the frequency (and sample rate) error caused by the original (cheap) crystal.

Note, call this function only if you fully understand the implications.

func (*Context) WriteEeprom

func (dev *Context) WriteEeprom(data []uint8, offset uint8, leng uint16) (err error)

WriteEeprom writes data to the EEPROM.

type HwInfo

type HwInfo struct {
	VendorID     uint16
	ProductID    uint16
	Manufact     string
	Product      string
	Serial       string
	HaveSerial   bool
	EnableIR     bool
	RemoteWakeup bool
}

HwInfo holds dongle specific information.

type ReadAsyncCbT

type ReadAsyncCbT func([]byte)

ReadAsyncCbT defines a user callback function type.

type SamplingMode

type SamplingMode int

SamplingMode is the sampling mode type.

const (
	SamplingNone SamplingMode = iota
	SamplingIADC
	SamplingQADC
	SamplingUnknown
)

Sampling modes.

type UserCtx

type UserCtx interface{}

UserCtx defines the second parameter of the ReadAsync method and is meant to be type asserted in the user's callback function when used. It allows the user to pass in virtually any object and is similar to C's void*.

Examples would be a channel, a device context, a buffer, etc..

A channel type assertion: c, ok := (*userctx).(chan bool)

A user context assertion: device := (*userctx).(*rtl.Context)

Jump to

Keyboard shortcuts

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