rtlsource.hh
#ifndef __SDR_RTLSOURCE_HH__
#define __SDR_RTLSOURCE_HH__
#include <rtl-sdr.h>
#include <pthread.h>
#include "node.hh"
namespace sdr {
class RTLSource: public Source
{
public:
RTLSource(double frequency, double sample_rate=1e6, size_t device_idx=0);
virtual ~RTLSource();
inline double frequency() const { return _frequency; }
void setFrequency(double frequency);
inline double freqCorrection() const { return rtlsdr_get_freq_correction(_device); }
void setFreqCorrection(double ppm);
inline double sampleRate() const { return _sample_rate; }
void setSampleRate(double sample_rate);
inline bool agcEnabled() const { return _agc_enabled; }
void enableAGC(bool enable);
inline double gain() const { return rtlsdr_get_tuner_gain(_device); }
void setGain(double gain);
inline const std::vector<double> & gainFactors() const { return _gains; }
void start();
void stop();
static size_t numDevices();
static std::string deviceName(size_t idx);
protected:
static void *__rtl_sdr_parallel_main(void *ctx);
static void __rtl_sdr_callback(unsigned char *buffer, uint32_t len, void *ctx);
protected:
double _frequency;
double _sample_rate;
bool _agc_enabled;
std::vector<double> _gains;
size_t _buffer_size;
rtlsdr_dev_t *_device;
pthread_t _thread;
};
}
#endif // __SDR_RTLSOURCE_HH__
sdr::RTLSource::frequency
double frequency() const
Returns the tuner frequency.
Definition: rtlsource.hh:34
sdr::RTLSource::_gains
std::vector< double > _gains
A vector of gain factors supported by the device.
Definition: rtlsource.hh:85
sdr::RTLSource::numDevices
static size_t numDevices()
Returns the number of compatible devices found.
Definition: rtlsource.cc:123
sdr::RTLSource::_sample_rate
double _sample_rate
The current sample rate.
Definition: rtlsource.hh:81
sdr::RTLSource::gain
double gain() const
Returns the tuner gain.
Definition: rtlsource.hh:55
sdr::RTLSource::enableAGC
void enableAGC(bool enable)
Enable/Disable AGC.
Definition: rtlsource.cc:92
sdr
Definition: autocast.hh:8
sdr::RTLSource::_frequency
double _frequency
The current tuner frequency.
Definition: rtlsource.hh:79
sdr::RTLSource::start
void start()
Starts the reception.
Definition: rtlsource.cc:107
sdr::RTLSource
Implements a uint_8 I/Q source for RTL2832 based TV dongles.
Definition: rtlsource.hh:16
sdr::Source
Generic source class.
Definition: node.hh:213
sdr::RTLSource::stop
void stop()
Stops the reception.
Definition: rtlsource.cc:112
sdr::RTLSource::setFrequency
void setFrequency(double frequency)
(Re-) Sets the tuner frequency.
Definition: rtlsource.cc:66
sdr::RTLSource::setGain
void setGain(double gain)
(Re-) Sets the tuner gain.
Definition: rtlsource.cc:99
sdr::RTLSource::_thread
pthread_t _thread
The thread object.
Definition: rtlsource.hh:91
sdr::RTLSource::deviceName
static std::string deviceName(size_t idx)
Returns the name of the specified device.
Definition: rtlsource.cc:128
sdr::RTLSource::freqCorrection
double freqCorrection() const
Returns the frequency correction in parts per million (ppm).
Definition: rtlsource.hh:39
sdr::RTLSource::__rtl_sdr_parallel_main
static void * __rtl_sdr_parallel_main(void *ctx)
Parallel routine to receive some data from the device.
Definition: rtlsource.cc:134
sdr::RTLSource::__rtl_sdr_callback
static void __rtl_sdr_callback(unsigned char *buffer, uint32_t len, void *ctx)
Callback to process received data.
Definition: rtlsource.cc:142
sdr::RTLSource::setFreqCorrection
void setFreqCorrection(double ppm)
(Re-) Sets the frequency correction in ppm.
Definition: rtlsource.cc:73
sdr::RTLSource::gainFactors
const std::vector< double > & gainFactors() const
Retunrs a vector of supported gain factors.
Definition: rtlsource.hh:59
sdr::RTLSource::setSampleRate
void setSampleRate(double sample_rate)
(Re-) sets the sample rate.
Definition: rtlsource.cc:78
sdr::RTLSource::_device
rtlsdr_dev_t * _device
The RTL2832 device object.
Definition: rtlsource.hh:89
sdr::RTLSource::sampleRate
double sampleRate() const
Returns the sample rate.
Definition: rtlsource.hh:44
sdr::RTLSource::RTLSource
RTLSource(double frequency, double sample_rate=1e6, size_t device_idx=0)
Constructor.
Definition: rtlsource.cc:7
sdr::RTLSource::~RTLSource
virtual ~RTLSource()
Destructor.
Definition: rtlsource.cc:60
sdr::RTLSource::agcEnabled
bool agcEnabled() const
Returns true if AGC is enabled.
Definition: rtlsource.hh:50
sdr::RTLSource::_buffer_size
size_t _buffer_size
The buffer size.
Definition: rtlsource.hh:87
sdr::RTLSource::_agc_enabled
bool _agc_enabled
If true, the AGC is enabled.
Definition: rtlsource.hh:83