func main() { runtime.GOMAXPROCS(3) var status int var dev *rtl.Context if c := rtl.GetDeviceCount(); c == 0 { log.Fatal("No devices found, exiting.\n") } else { for i := 0; i < c; i++ { m, p, s, status := rtl.GetDeviceUsbStrings(i) log.Printf("GetDeviceUsbStrings %s - %s %s %s\n", rtl.Status[status], m, p, s) } } log.Printf("===== Device name: %s =====\n", rtl.GetDeviceName(0)) log.Printf("===== Running tests using device indx: %d =====\n", 0) if dev, status = rtl.Open(0); status != rtl.Success { log.Fatal("\tOpen Failed, exiting\n") } defer dev.Close() go sig_abort(dev) m, p, s, status := dev.GetUsbStrings() log.Printf("\tGetUsbStrings %s - %s %s %s\n", rtl.Status[status], m, p, s) g, status := dev.GetTunerGains() log.Printf("\tGetTunerGains %s\n", rtl.Status[status]) if status == rtl.Success { fmt.Printf("\tGains: ") for _, j := range g { fmt.Printf("%d ", j) } fmt.Printf("\n") } log.Printf("\tSetSampleRate %s - rate: %d\n", rtl.Status[dev.SetSampleRate(rtl.DefaultSampleRate)], rtl.DefaultSampleRate) log.Printf("\tGetSampleRate: %d\n", dev.GetSampleRate()) // status = dev.SetXtalFreq(rtl_freq, tuner_freq) // log.Printf("\tSetXtalFreq %s - Center freq: %d, Tuner freq: %d\n", // rtl.Status[status], rtl_freq, tuner_freq) rtl_freq, tuner_freq, status := dev.GetXtalFreq() log.Printf("\tGetXtalFreq %s - Rtl: %d, Tuner: %d\n", rtl.Status[status], rtl_freq, tuner_freq) status = dev.SetCenterFreq(850000000) if status < 0 { log.Println("\tSetCenterFreq 850MHz Failed, error code: %d\n", status) } else { log.Println("\tSetCenterFreq 850MHz Successful") } log.Printf("\tGetCenterFreq: %d\n", dev.GetCenterFreq()) log.Printf("\tGetFreqCorrection: %d\n", dev.GetFreqCorrection()) log.Printf("\tGetTunerType: %s\n", rtl.TunerType[dev.GetTunerType()]) log.Printf("\tSetTunerGainMode: %s\n", rtl.TunerType[dev.SetTunerGainMode(rtl.GainAuto)]) log.Printf("\tGetTunerGain: %d\n", dev.GetTunerGain()) /* func (c *Context) SetFreqCorrection(ppm int) (err int) func (c *Context) SetTunerGain(gain int) (err int) func (c *Context) SetTunerIfGain(stage, gain int) (err int) func (c *Context) SetAgcMode(on int) (err int) func (c *Context) SetDirectSampling(on int) (err int) */ if status = dev.SetTestMode(1); status < 1 { log.Printf("\tSetTestMode 'On' Failed - error code: %d\n", status) } else { log.Printf("\tSetTestMode 'On' Successful\n") } log.Printf("\tResetBuffer %s\n", rtl.Status[dev.ResetBuffer()]) var buffer []byte = make([]uint8, rtl.DefaultBufLength) n_read, status := dev.ReadSync(buffer, rtl.DefaultBufLength) log.Printf("\tReadSync %s\n", rtl.Status[status]) if status == rtl.Success && n_read < rtl.DefaultBufLength { log.Println("ReadSync short read, %d samples lost\n", rtl.DefaultBufLength-n_read) } if status = dev.SetTestMode(1); status < 1 { log.Printf("\tSetTestMode 'Off' Fail - error code: %d\n", status) } else { log.Printf("\tSetTestMode 'Off' Success\n") } // Note, ReadAsync blocks until CancelAsync is called, so spawn // a goroutine running in its own system thread that'll wait // for the async-read callback to signal when it's done. IQch := make(chan bool) go async_stop(dev, IQch) var userctx rtl.UserCtx = IQch status = dev.ReadAsync(rtlsdr_cb, &userctx, rtl.DefaultAsyncBufNumber, rtl.DefaultBufLength) log.Printf("\tReadAsync %s\n", rtl.Status[status]) log.Printf("Exiting...\n") }
// Read 978MHz from SDR. func sdrReader() { var err error var dev *rtl.Context log.Printf("===== UAT Device name: %s =====\n", rtl.GetDeviceName(uatSDR)) if dev, err = rtl.Open(uatSDR); err != nil { log.Printf("\tOpen Failed, exiting\n") uatSDR = -1 return } defer dev.Close() m, p, s, err := dev.GetUsbStrings() if err != nil { log.Printf("\tGetUsbStrings Failed - error: %s\n", err) } else { log.Printf("\tGetUsbStrings - %s %s %s\n", m, p, s) } log.Printf("\tGetTunerType: %s\n", dev.GetTunerType()) //---------- Set Tuner Gain ---------- tgain := 480 err = dev.SetTunerGainMode(true) if err != nil { log.Printf("\tSetTunerGainMode Failed - error: %s\n", err) } else { log.Printf("\tSetTunerGainMode Successful\n") } err = dev.SetTunerGain(tgain) if err != nil { log.Printf("\tSetTunerGain Failed - error: %s\n", err) } else { log.Printf("\tSetTunerGain Successful\n") } //---------- Get/Set Sample Rate ---------- samplerate := 2083334 err = dev.SetSampleRate(samplerate) if err != nil { log.Printf("\tSetSampleRate Failed - error: %s\n", err) } else { log.Printf("\tSetSampleRate - rate: %d\n", samplerate) } log.Printf("\tGetSampleRate: %d\n", dev.GetSampleRate()) //---------- Get/Set Xtal Freq ---------- rtlFreq, tunerFreq, err := dev.GetXtalFreq() if err != nil { log.Printf("\tGetXtalFreq Failed - error: %s\n", err) } else { log.Printf("\tGetXtalFreq - Rtl: %d, Tuner: %d\n", rtlFreq, tunerFreq) } newRTLFreq := 28800000 newTunerFreq := 28800000 err = dev.SetXtalFreq(newRTLFreq, newTunerFreq) if err != nil { log.Printf("\tSetXtalFreq Failed - error: %s\n", err) } else { log.Printf("\tSetXtalFreq - Center freq: %d, Tuner freq: %d\n", newRTLFreq, newTunerFreq) } //---------- Get/Set Center Freq ---------- err = dev.SetCenterFreq(978000000) if err != nil { log.Printf("\tSetCenterFreq 978MHz Failed, error: %s\n", err) } else { log.Printf("\tSetCenterFreq 978MHz Successful\n") } log.Printf("\tGetCenterFreq: %d\n", dev.GetCenterFreq()) //---------- Set Bandwidth ---------- bw := 1000000 log.Printf("\tSetting Bandwidth: %d\n", bw) if err = dev.SetTunerBw(bw); err != nil { log.Printf("\tSetTunerBw %d Failed, error: %s\n", bw, err) } else { log.Printf("\tSetTunerBw %d Successful\n", bw) } if err = dev.ResetBuffer(); err == nil { log.Printf("\tResetBuffer Successful\n") } else { log.Printf("\tResetBuffer Failed - error: %s\n", err) } //---------- Get/Set Freq Correction ---------- freqCorr := dev.GetFreqCorrection() log.Printf("\tGetFreqCorrection: %d\n", freqCorr) err = dev.SetFreqCorrection(globalSettings.PPM) if err != nil { log.Printf("\tSetFreqCorrection %d Failed, error: %s\n", globalSettings.PPM, err) } else { log.Printf("\tSetFreqCorrection %d Successful\n", globalSettings.PPM) } for uatSDR != -1 { var buffer = make([]uint8, rtl.DefaultBufLength) nRead, err := dev.ReadSync(buffer, rtl.DefaultBufLength) if err != nil { log.Printf("\tReadSync Failed - error: %s\n", err) uatSDR = -1 break } else { // log.Printf("\tReadSync %d\n", nRead) buf := buffer[:nRead] godump978.InChan <- buf } } }