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