Example #1
0
// Get a list of gains supported by the tuner.
//
// A NULL second parameter requests the gain count.
// Gain values are in tenths of dB, e.g. 115 means 11.5 dB.
//
// int rtlsdr_get_tuner_gains(rtlsdr_dev_t *dev, int *gains);
// rtlsdr_get_tuner_gains returns <= 0 on error or the number of available gain
func (c *Context) GetTunerGains() (gains []int, err int) {
	//	count := int(C.rtlsdr_get_tuner_gains((*C.rtlsdr_dev_t)(c.dev), nil))
	count := int(C.rtlsdr_get_tuner_gains((*C.rtlsdr_dev_t)(c.dev),
		(*C.int)(unsafe.Pointer(uintptr(0)))))
	if count < 0 {
		err = count
		return
	} else if count == 0 {
		return
	}
	gains = make([]int, count)
	C.rtlsdr_get_tuner_gains((*C.rtlsdr_dev_t)(c.dev),
		(*C.int)(unsafe.Pointer(&gains[0])))
	return
}
Example #2
0
// GetTunerGains returns a list of supported tuner gains.
// Values are in tenths of dB, e.g. 115 means 11.5 dB.
func (dev *Context) GetTunerGains() (gainsTenthsDb []int, err error) {
	// count := int(C.rtlsdr_get_tuner_gains((*C.rtlsdr_dev_t)(c.dev), nil))
	i := int(C.rtlsdr_get_tuner_gains((*C.rtlsdr_dev_t)(dev),
		(*C.int)(unsafe.Pointer(nil))))
	if i <= 0 {
		return gainsTenthsDb, libError(i)
	}
	buf := make([]C.int, i)
	i = int(C.rtlsdr_get_tuner_gains((*C.rtlsdr_dev_t)(dev),
		(*C.int)(unsafe.Pointer(&buf[0]))))
	if i <= 0 {
		return gainsTenthsDb, libError(i)
	}
	gainsTenthsDb = make([]int, i)
	for ii := 0; ii < i; ii++ {
		gainsTenthsDb[ii] = int(buf[ii])
	}

	return gainsTenthsDb, nil
}
Example #3
0
// GetTunerGains retrieves and stores the list of available tuner gain options
func (dev *Radio) GetTunerGains() ([]int, error) {
	dev.lock.Lock()
	defer dev.lock.Unlock()

	// The underlying rtlsdr call returns a pointer to an array of ints. The first
	// call figures out how big that array will be
	retval := C.rtlsdr_get_tuner_gains(dev.devptr, nil)
	if retval <= 0 {
		return nil, fmt.Errorf("rtlsdr_get_tuner_gains returned error value: %d", retval)
	}

	cGains := make([]C.int, 100)
	retval = C.rtlsdr_get_tuner_gains(dev.devptr, (*C.int)(unsafe.Pointer(&cGains[0])))
	if retval <= 0 {
		return nil, fmt.Errorf("rtlsdr_get_tuner_gains returned error value: %d", retval)
	}

	for i := 0; i < int(retval); i++ {
		dev.GainOptions = append(dev.GainOptions, int(cGains[i]))
	}

	return dev.GainOptions, nil
}