Ejemplo n.º 1
0
func main() {
	var err error
	var dev *rtl.Context

	//---------- Device Check ----------
	if c := rtl.GetDeviceCount(); c == 0 {
		log.Fatal("No devices found, exiting.\n")
	} else {
		for i := 0; i < c; i++ {
			m, p, s, err := rtl.GetDeviceUsbStrings(i)
			if err == nil {
				err = errors.New("")
			}
			log.Printf("GetDeviceUsbStrings %s - %s %s %s\n",
				err, m, p, s)
		}
	}

	log.Printf("===== Device name: %s =====\n", rtl.GetDeviceName(0))
	log.Printf("===== Running tests using device indx: 0 =====\n")

	//---------- Open Device ----------
	if dev, err = rtl.Open(0); err != nil {
		log.Fatal("\tOpen Failed, exiting\n")
	}
	defer dev.Close()

	//---------- Device Strings ----------
	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())

	//---------- Device Info ----------
	info, err := dev.GetHwInfo()
	if err != nil {
		log.Printf("\tGetHwInfo Failed - error: %s\n", err)
	} else {
		log.Printf("\tVendor ID      : 0x%X\n", info.VendorID)
		log.Printf("\tProduct ID     : 0x%X\n", info.ProductID)
		log.Println("\tManufacturer  : ", info.Manufact)
		log.Println("\tProduct       : ", info.Product)
		log.Println("\tSerial        : ", info.Serial)
		log.Println("\tHave Serial   : ", info.HaveSerial)
		log.Println("\tEnable IR     : ", info.EnableIR)
		log.Println("\tRemote Wakeup : ", info.RemoteWakeup)
	}

	ppm, err := kal.Kal((*kal.Context)(dev), kal.GSM850)
	log.Printf("PPM: %d\n", ppm)
	log.Printf("err: %s\n", err)
}
Ejemplo n.º 2
0
func main() {
	var err error
	var dev *rtl.Context

	if c := rtl.GetDeviceCount(); c == 0 {
		log.Fatal("No devices found, exiting.\n")
	}

	if dev, err = rtl.Open(0); err != nil {
		log.Fatal("\tOpen Failed, existing\n")
	}
	//defer pushes a function onto a list that will be invoked
	//after the surrounding function returns (in this case main)
	defer dev.Close()
	go sig_abort(dev)

	//Set to 1090Mhz
	dev.SetSampleRate(2000000) //from rtl_adsb.c
	dev.SetTunerGainMode(false)
	err = dev.SetCenterFreq(1090000000)
	if err != nil {
		log.Printf("\tSetCenterFreq 1090Mhz Failed, error: %s\n", err)
	}

	//dev.SetTestMode(true)
	dev.ResetBuffer()

	IQch := make(chan bool)
	var userctx rtl.UserCtx = IQch
	err = dev.ReadAsync(rtlsdr_cb, &userctx, rtl.DefaultAsyncBufNumber, 512)
	if err == nil {
		log.Printf("\tReadAsync Successful\n")
	} else {
		log.Printf("\rReadAsync FAILED - error: %s\n", err)
	}

	/*
	  var buffer []byte = make([]uint8, rtl.DefaultBufLength)
	  //var hexbuf []byte = make([]uint8, rtl.DefaultBufLength)
	  n_read, err := dev.ReadSync(buffer, rtl.DefaultBufLength)
	  if err != nil {
	    log.Printf("\tReadSynch Failed - error %s\n", err)
	  } else {
	    //hex.Decode(hexbuf, buffer)
	    log.Printf("\tReadSync %d\n", n_read)
	    //log.Printf("\t%X\n", hexbuf)
	  }
	  if err == nil && n_read < rtl.DefaultBufLength {
	    log.Printf("ReadSynch short read, %d samples lost\n", rtl.DefaultBufLength-n_read)
	  }
	*/
	log.Printf("Exiting...\n")
}
Ejemplo n.º 3
0
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")
}
Ejemplo n.º 4
0
// Read 978MHz from SDR.
func (u *UAT) sdrConfig() (err error) {
	log.Printf("===== UAT Device name: %s =====\n", rtl.GetDeviceName(u.indexID))
	if u.dev, err = rtl.Open(u.indexID); err != nil {
		log.Printf("\tUAT Open Failed...\n")
		return
	}
	log.Printf("\tGetTunerType: %s\n", u.dev.GetTunerType())

	//---------- Set Tuner Gain ----------
	err = u.dev.SetTunerGainMode(true)
	if err != nil {
		u.dev.Close()
		log.Printf("\tSetTunerGainMode Failed - error: %s\n", err)
		return
	} else {
		log.Printf("\tSetTunerGainMode Successful\n")
	}

	tgain := 480
	err = u.dev.SetTunerGain(tgain)
	if err != nil {
		u.dev.Close()
		log.Printf("\tSetTunerGain Failed - error: %s\n", err)
		return
	} else {
		log.Printf("\tSetTunerGain Successful\n")
	}

	//---------- Get/Set Sample Rate ----------
	samplerate := 2083334
	err = u.dev.SetSampleRate(samplerate)
	if err != nil {
		u.dev.Close()
		log.Printf("\tSetSampleRate Failed - error: %s\n", err)
		return
	} else {
		log.Printf("\tSetSampleRate - rate: %d\n", samplerate)
	}
	log.Printf("\tGetSampleRate: %d\n", u.dev.GetSampleRate())

	//---------- Get/Set Xtal Freq ----------
	rtlFreq, tunerFreq, err := u.dev.GetXtalFreq()
	if err != nil {
		u.dev.Close()
		log.Printf("\tGetXtalFreq Failed - error: %s\n", err)
		return
	} else {
		log.Printf("\tGetXtalFreq - Rtl: %d, Tuner: %d\n", rtlFreq, tunerFreq)
	}

	newRTLFreq := 28800000
	newTunerFreq := 28800000
	err = u.dev.SetXtalFreq(newRTLFreq, newTunerFreq)
	if err != nil {
		u.dev.Close()
		log.Printf("\tSetXtalFreq Failed - error: %s\n", err)
		return
	} else {
		log.Printf("\tSetXtalFreq - Center freq: %d, Tuner freq: %d\n",
			newRTLFreq, newTunerFreq)
	}

	//---------- Get/Set Center Freq ----------
	err = u.dev.SetCenterFreq(978000000)
	if err != nil {
		u.dev.Close()
		log.Printf("\tSetCenterFreq 978MHz Failed, error: %s\n", err)
		return
	} else {
		log.Printf("\tSetCenterFreq 978MHz Successful\n")
	}

	log.Printf("\tGetCenterFreq: %d\n", u.dev.GetCenterFreq())

	//---------- Set Bandwidth ----------
	bw := 1000000
	log.Printf("\tSetting Bandwidth: %d\n", bw)
	if err = u.dev.SetTunerBw(bw); err != nil {
		u.dev.Close()
		log.Printf("\tSetTunerBw %d Failed, error: %s\n", bw, err)
		return
	} else {
		log.Printf("\tSetTunerBw %d Successful\n", bw)
	}

	if err = u.dev.ResetBuffer(); err != nil {
		u.dev.Close()
		log.Printf("\tResetBuffer Failed - error: %s\n", err)
		return
	} else {
		log.Printf("\tResetBuffer Successful\n")
	}
	//---------- Get/Set Freq Correction ----------
	freqCorr := u.dev.GetFreqCorrection()
	log.Printf("\tGetFreqCorrection: %d\n", freqCorr)
	err = u.dev.SetFreqCorrection(globalSettings.PPM)
	if err != nil {
		u.dev.Close()
		log.Printf("\tSetFreqCorrection %d Failed, error: %s\n", globalSettings.PPM, err)
		return
	} else {
		log.Printf("\tSetFreqCorrection %d Successful\n", globalSettings.PPM)
	}
	return
}
Ejemplo n.º 5
0
Archivo: main.go Proyecto: porjo/hamsdr
func main() {
	var err error

	flag.IntVar(&dongle.devIndex, "d", 0, "dongle device index")
	flag.Var(&controller.freqs, "f", "frequency or range of frequencies, and step e.g 92.9M:100.1M:25k")
	flag.IntVar(&demod.squelchLevel, "l", 0, "squelch level")
	rateStr := flag.String("s", "24k", "sample rate")
	flag.IntVar(&dongle.ppmError, "p", 0, "ppm error")
	flag.IntVar(&dongle.gain, "g", autoGain, "gain level (defaults to autogain)")
	flag.BoolVar(&demod.agcEnable, "agc", false, "Software AGC")
	flag.BoolVar(&output.pad, "pad", false, "pad output gaps with zeros")
	demodMode := flag.String("M", "am", "demodulation mode [fm, wbfm, am]")

	flag.Parse()

	if *rateStr != "" {
		var rateIn uint32
		rateIn, err = freqHz(*rateStr)
		if err != nil {
			fmt.Fprintf(os.Stderr, "Failed to parse sample rate %s\n", err)
			return
		}
		demod.rateIn = int(rateIn)
		demod.rateOut = int(rateIn)
	}

	switch *demodMode {
	case "fm":
		demod.modeDemod = fmDemod
	case "wbfm":
		controller.wbMode = true
		demod.modeDemod = fmDemod
		demod.rateIn = 170000
		demod.rateOut = 170000
		demod.rateOut2 = 32000
		output.rate = 32000
		demod.customAtan = 1
		//demod.post_downsample = 4;
		demod.deemph = true
		demod.squelchLevel = 0
	default:
		demod.modeDemod = amDemod
	}

	if len(controller.freqs) == 0 {
		fmt.Fprintln(os.Stderr, "Please specify a frequency.")
		return
	}

	if len(controller.freqs) >= frequenciesLimit {
		fmt.Fprintf(os.Stderr, "Too many channels, maximum %d.\n", frequenciesLimit)
		return
	}

	if len(controller.freqs) > 1 && demod.squelchLevel == 0 {
		fmt.Fprintln(os.Stderr, "Please specify a squelch level.  Required for scanning multiple frequencies.")
		return
	}

	// quadruple sample_rate to limit to Δθ to ±π/2
	demod.rateIn *= demod.postDownsample

	if output.rate == 0 {
		output.rate = demod.rateOut
	}

	if flag.Arg(0) != "" {
		output.filename = flag.Arg(0)
	} else {
		output.filename = ""
	}

	dongle.dev, err = rtl.Open(dongle.devIndex)
	if err != nil {
		fmt.Fprintf(os.Stderr, "Failed to open dongle, '%s', exiting\n", err)
		return
	}
	defer dongle.dev.Close()

	if demod.deemph {
		demod.deemphA = int(
			//round(1.0/(1.0-math.Exp(-1.0/(float64(demod.rateOut)*75e-6))), 0),
			round(1.0 / (1.0 - math.Exp(-1.0/(float64(demod.rateOut)*75e-6)))),
		)
		fmt.Fprintf(os.Stderr, "Deempha %d\n", demod.deemphA)
	}
	// Set the tuner gain
	if dongle.gain == autoGain {
		fmt.Fprintf(os.Stderr, "Setting auto gain\n")
		err = dongle.dev.SetTunerGainMode(false)
		if err != nil {
			fmt.Fprintf(os.Stderr, "Error setting tuner auto-gain: %s\n", err)
			return
		}
	} else {
		dongle.gain *= 10
		dongle.gain, err = nearestGain(dongle.dev, dongle.gain)
		if err != nil {
			fmt.Fprintf(os.Stderr, "Error getting nearest gain to %d: %s\n", dongle.gain, err)
			return
		}
		err = dongle.dev.SetTunerGain(dongle.gain)
		if err != nil {
			fmt.Fprintf(os.Stderr, "Error setting tuner manual gain to %d: %s\n", dongle.gain)
			return
		}
	}

	if dongle.ppmError > 0 {
		err = dongle.dev.SetFreqCorrection(dongle.ppmError)
		if err != nil {
			fmt.Fprintf(os.Stderr, "Error setting frequency correction to %d: %s\n", dongle.ppmError, err)
			return
		}
		fmt.Fprintf(os.Stderr, "Tuner error set to %i ppm.\n", dongle.ppmError)
	}

	if output.filename == "" {
		output.file = os.Stdout
	} else {
		output.file, err = os.Create(output.filename)
		if err != nil {
			fmt.Fprintln(os.Stderr, err)
			return
		}
		defer output.file.Close()
	}

	// Reset endpoint before we start reading from it (mandatory)
	err = dongle.dev.ResetBuffer()
	if err != nil {
		fmt.Fprintln(os.Stderr, err)
		return
	}

	signalChan := make(chan os.Signal, 1)
	quit := make(exitChan)
	signal.Notify(signalChan, os.Interrupt)
	go func() {
		for _ = range signalChan {
			fmt.Fprintln(os.Stderr, "\nReceived an interrupt, stopping services...")
			close(quit)
			return
		}
	}()
	var wg sync.WaitGroup

	wg.Add(4)

	go controllerRoutine(&wg)
	go outputRoutine(&wg)
	go demodRoutine(&wg)
	go dongleRoutine(&wg)

	controller.hopChan <- true

	<-quit
	fmt.Fprintf(os.Stderr, "rtlsdr CancelAsync()\n")
	if err := dongle.dev.CancelAsync(); err != nil {
		fmt.Fprintf(os.Stderr, "Error canceling async %s\n", err)
	}

	fmt.Fprintf(os.Stderr, "Waiting for goroutines to finish...\n")
	wg.Wait()

	fmt.Fprintf(os.Stderr, "Exiting...\n")
}
Ejemplo n.º 6
0
// 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
		}
	}
}
Ejemplo n.º 7
0
func main() {
	var err error
	var dev *rtl.Context

	//---------- Device Check ----------
	if c := rtl.GetDeviceCount(); c == 0 {
		log.Fatal("No devices found, exiting.\n")
	} else {
		for i := 0; i < c; i++ {
			m, p, s, err := rtl.GetDeviceUsbStrings(i)
			if err == nil {
				err = errors.New("")
			}
			log.Printf("GetDeviceUsbStrings %s - %s %s %s\n",
				err, m, p, s)
		}
	}

	log.Printf("===== Device name: %s =====\n", rtl.GetDeviceName(0))
	log.Printf("===== Running tests using device indx: 0 =====\n")

	//---------- Open Device ----------
	if dev, err = rtl.Open(0); err != nil {
		log.Fatal("\tOpen Failed, exiting\n")
	}
	defer dev.Close()
	go sigAbort(dev)

	//---------- Device Strings ----------
	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)
	}

	/*
		//---------- Get/Set Freq Correction ----------
		freqCorr := dev.GetFreqCorrection()
		log.Printf("\tGetFreqCorrection: %d\n", freqCorr)
		err = dev.SetFreqCorrection(0) // 10ppm
		if err != nil {
			log.Printf("\tSetFreqCorrection %d Failed, error: %s\n", 0, err)
		} else {
			log.Printf("\tSetFreqCorrection %d Successful\n", 0)
		}


		//---------- Get/Set AGC Mode ----------
		if err = dev.SetAgcMode(false); err == nil {
			log.Printf("\tSetAgcMode off Successful\n")
		} else {
			log.Printf("\tSetAgcMode Failed, error: %s\n", err)
		}

		//---------- Get/Set Direct Sampling ----------
		if mode, err := dev.GetDirectSampling(); err == nil {
			log.Printf("\tGetDirectSampling Successful, mode: %s\n",
				rtl.SamplingModes[mode])
		} else {
			log.Printf("\tSetTestMode 'On' Failed - error: %s\n", err)
		}

		if err = dev.SetDirectSampling(rtl.SamplingNone); err == nil {
			log.Printf("\tSetDirectSampling 'On' Successful\n")
		} else {
			log.Printf("\tSetDirectSampling 'On' Failed - error: %s\n", err)
		}
	*/

	//---------- Get/Set Tuner IF Gain ----------
	// if err = SetTunerIfGain(stage, gain: int); err == nil {
	// 	log.Printf("\SetTunerIfGain Successful\n")
	// } else {
	// 	log.Printf("\tSetTunerIfGain Failed - error: %s\n", err)
	// }

	/*
		//---------- Get/Set test mode ----------
		if err = dev.SetTestMode(true); err == nil {
			log.Printf("\tSetTestMode 'On' Successful\n")
		} else {
			log.Printf("\tSetTestMode 'On' Failed - error: %s\n", err)
		}

		if err = dev.SetTestMode(false); err == nil {
			log.Printf("\tSetTestMode 'Off' Successful\n")
		} else {
			log.Printf("\tSetTestMode 'Off' Fail - error: %s\n", err)
		}

	*/

	//---------- Get/Set misc. streaming ----------
	godump978.Dump978Init()
	go printUAT()
	go godump978.ProcessDataFromChannel()

	if err = dev.ResetBuffer(); err == nil {
		log.Printf("\tResetBuffer Successful\n")
	} else {
		log.Printf("\tResetBuffer Failed - error: %s\n", err)
	}

	for {
		var buffer = make([]uint8, rtl.DefaultBufLength)
		nRead, err := dev.ReadSync(buffer, rtl.DefaultBufLength)
		if err != nil {
			log.Printf("\tReadSync Failed - error: %s\n", err)
		} else {
			log.Printf("\tReadSync %d\n", nRead)
			//			buf := buffer[:nRead]
			//			godump978.InChan <- buf
		}
	}
}
Ejemplo n.º 8
0
func (u *UAT) sdrConfig() (err error) {
	log.Printf("===== UAT Device Name  : %s =====\n", rtl.GetDeviceName(u.indexID))
	log.Printf("===== UAT Device Serial: %s=====\n", u.serial)

	if u.dev, err = rtl.Open(u.indexID); err != nil {
		log.Printf("\tUAT Open Failed...\n")
		return
	}
	log.Printf("\tGetTunerType: %s\n", u.dev.GetTunerType())

	//---------- Set Tuner Gain ----------
	err = u.dev.SetTunerGainMode(true)
	if err != nil {
		u.dev.Close()
		log.Printf("\tSetTunerGainMode Failed - error: %s\n", err)
		return
	}
	log.Printf("\tSetTunerGainMode Successful\n")

	err = u.dev.SetTunerGain(TunerGain)
	if err != nil {
		u.dev.Close()
		log.Printf("\tSetTunerGain Failed - error: %s\n", err)
		return
	}
	log.Printf("\tSetTunerGain Successful\n")

	tgain := u.dev.GetTunerGain()
	log.Printf("\tGetTunerGain: %d\n", tgain)

	//---------- Get/Set Sample Rate ----------
	err = u.dev.SetSampleRate(SampleRate)
	if err != nil {
		u.dev.Close()
		log.Printf("\tSetSampleRate Failed - error: %s\n", err)
		return
	}
	log.Printf("\tSetSampleRate - rate: %d\n", SampleRate)

	log.Printf("\tGetSampleRate: %d\n", u.dev.GetSampleRate())

	//---------- Get/Set Xtal Freq ----------
	rtlFreq, tunerFreq, err := u.dev.GetXtalFreq()
	if err != nil {
		u.dev.Close()
		log.Printf("\tGetXtalFreq Failed - error: %s\n", err)
		return
	}
	log.Printf("\tGetXtalFreq - Rtl: %d, Tuner: %d\n", rtlFreq, tunerFreq)

	err = u.dev.SetXtalFreq(NewRTLFreq, NewTunerFreq)
	if err != nil {
		u.dev.Close()
		log.Printf("\tSetXtalFreq Failed - error: %s\n", err)
		return
	}
	log.Printf("\tSetXtalFreq - Center freq: %d, Tuner freq: %d\n",
		NewRTLFreq, NewTunerFreq)

	//---------- Get/Set Center Freq ----------
	err = u.dev.SetCenterFreq(CenterFreq)
	if err != nil {
		u.dev.Close()
		log.Printf("\tSetCenterFreq 978MHz Failed, error: %s\n", err)
		return
	}
	log.Printf("\tSetCenterFreq 978MHz Successful\n")

	log.Printf("\tGetCenterFreq: %d\n", u.dev.GetCenterFreq())

	//---------- Set Bandwidth ----------
	log.Printf("\tSetting Bandwidth: %d\n", Bandwidth)
	if err = u.dev.SetTunerBw(Bandwidth); err != nil {
		u.dev.Close()
		log.Printf("\tSetTunerBw %d Failed, error: %s\n", Bandwidth, err)
		return
	}
	log.Printf("\tSetTunerBw %d Successful\n", Bandwidth)

	if err = u.dev.ResetBuffer(); err != nil {
		u.dev.Close()
		log.Printf("\tResetBuffer Failed - error: %s\n", err)
		return
	}
	log.Printf("\tResetBuffer Successful\n")

	//---------- Get/Set Freq Correction ----------
	freqCorr := u.dev.GetFreqCorrection()
	log.Printf("\tGetFreqCorrection: %d\n", freqCorr)

	u.ppm = getPPM(u.serial)
	err = u.dev.SetFreqCorrection(u.ppm)
	if err != nil {
		u.dev.Close()
		log.Printf("\tSetFreqCorrection %d Failed, error: %s\n", u.ppm, err)
		return
	}
	log.Printf("\tSetFreqCorrection %d Successful\n", u.ppm)

	return
}
Ejemplo n.º 9
0
// sdrConfig configures the device to 978 MHz UAT channel.
func (u *UAT) sdrConfig(indexID int) (err error) {
	if u.dev, err = rtl.Open(indexID); err != nil {
		log.Printf("\tUAT Open Failed...\n")
		return
	}
	log.Printf("\tGetTunerType: %s\n", u.dev.GetTunerType())

	//---------- Set Tuner Gain ----------
	err = u.dev.SetTunerGainMode(true)
	if err != nil {
		u.dev.Close()
		log.Printf("\tSetTunerGainMode Failed - error: %s\n", err)
		return
	}
	log.Printf("\tSetTunerGainMode Successful\n")

	tgain := 0
	gains, err := u.dev.GetTunerGains()
	if err != nil {
		log.Printf("\tGetTunerGains Failed - error: %s\n", err)
	} else if len(gains) > 0 {
		log.Printf("Gains: %v", gains)
		tgain = int(gains[0])
	}

	err = u.dev.SetTunerGain(tgain)
	if err != nil {
		u.dev.Close()
		log.Printf("\tSetTunerGain Failed - error: %s\n", err)
		return
	}
	log.Printf("\tSetTunerGain Successful. Gain: %d\n", tgain)

	//---------- Get/Set Sample Rate ----------
	samplerate := 2048000 // 2000000 // 2083334
	err = u.dev.SetSampleRate(samplerate)
	if err != nil {
		u.dev.Close()
		log.Printf("\tSetSampleRate Failed - error: %s\n", err)
		return
	}
	log.Printf("\tSetSampleRate - rate: %d\n", samplerate)
	log.Printf("\tGetSampleRate: %d\n", u.dev.GetSampleRate())

	//---------- Get/Set Xtal Freq ----------
	rtlFreq, tunerFreq, err := u.dev.GetXtalFreq()
	if err != nil {
		u.dev.Close()
		log.Printf("\tGetXtalFreq Failed - error: %s\n", err)
		return
	}
	log.Printf("\tGetXtalFreq - Rtl: %d, Tuner: %d\n", rtlFreq, tunerFreq)

	newRTLFreq := 28800000
	newTunerFreq := 28800000
	err = u.dev.SetXtalFreq(newRTLFreq, newTunerFreq)
	if err != nil {
		u.dev.Close()
		log.Printf("\tSetXtalFreq Failed - error: %s\n", err)
		return
	}
	log.Printf("\tSetXtalFreq - Center freq: %d, Tuner freq: %d\n",
		newRTLFreq, newTunerFreq)

	//---------- Get/Set Center Freq ----------
	err = u.dev.SetCenterFreq(978000000)
	if err != nil {
		u.dev.Close()
		log.Printf("\tSetCenterFreq 978MHz Failed, error: %s\n", err)
		return
	}
	log.Printf("\tSetCenterFreq 978MHz Successful\n")

	log.Printf("\tGetCenterFreq: %d\n", u.dev.GetCenterFreq())

	//---------- Set Bandwidth ----------
	bw := 1000000
	log.Printf("\tSetting Bandwidth: %d\n", bw)
	if err = u.dev.SetTunerBw(bw); err != nil {
		u.dev.Close()
		log.Printf("\tSetTunerBw %d Failed, error: %s\n", bw, err)
		return
	}
	log.Printf("\tSetTunerBw %d Successful\n", bw)

	if err = u.dev.ResetBuffer(); err != nil {
		u.dev.Close()
		log.Printf("\tResetBuffer Failed - error: %s\n", err)
		return
	}
	log.Printf("\tResetBuffer Successful\n")

	//---------- Get/Set Freq Correction ----------
	freqCorr := u.dev.GetFreqCorrection()
	log.Printf("\tGetFreqCorrection: %d\n", freqCorr)
	err = u.dev.SetFreqCorrection(freqCorr)
	if err != nil {
		u.dev.Close()
		log.Printf("\tSetFreqCorrection %d Failed, error: %s\n", freqCorr, err)
		return
	}
	log.Printf("\tSetFreqCorrection %d Successful\n", freqCorr)

	return
}