gr-baz Package

rtl2832.h
Go to the documentation of this file.
1#ifndef INCLUDED_RTL2832
2#define INCLUDED_RTL2832
3
4#include <stdio.h>
5#include <stdarg.h>
6
7#ifdef LIBUSB_FOUND
8#include <libusb-1.0/libusb.h>
9#else
10#include <libusb/libusb.h> // libusbx on Windows
11#endif // LIBUSB_FOUND
12
13#ifdef _WIN32
14
15#ifdef RTL2832_EXPORTS
16#define RTL2832_API __declspec(dllexport)
17#else
18#define RTL2832_API __declspec(dllimport)
19#endif
20
21// 'libusb.h' offers uint8_t & uint16_t
22 typedef __int8 int8_t;
23 typedef unsigned int uint32_t;
24 typedef unsigned __int64 uint64_t;
25
26#else
27
28#define RTL2832_API
29#define RTL2832_TEMPLATE
30
31#endif // _WIN32
32
33#include <vector>
34#include <map>
35#include <string>
36
37 RTL2832_API extern int get_map_index(int value, const int* map, int pair_count);
38 RTL2832_API extern const char* libusb_result_to_string(int res);
39
40#ifdef _WIN32
41#define CURRENT_FUNCTION __FUNCTION__
42#else
43#define CURRENT_FUNCTION __PRETTY_FUNCTION__
44#endif // _WIN32
45
46// Swap following comments to disable I2C reporting
47//#define DEBUG_TUNER_I2C(t,r) // This is empty on purpose
48#define DEBUG_TUNER_I2C(t,r) \
49 if (t->params().message_output && function && (line_number >= 0) && (line)) \
50 t->params().message_output->on_log_message_ex(RTL2832_NAMESPACE::log_sink::LOG_LEVEL_ERROR, "%s: %s [%i] @ %s:%i \"%s\"\n", __FUNCTION__, libusb_result_to_string(r), r, function, line_number, line);
51
52#define RTL2832_NAMESPACE rtl2832
53
54 namespace RTL2832_NAMESPACE
55{
56
57 class demod;
58
59 enum result_code
60{
61 // < 0: libusb result code
62 FAILURE = 0,
63 SUCCESS = 1 // > 0 also # bytes transferred
64};
65
66#define TUNERS_NAMESPACE tuners
67
68#define TUNER_FACTORY_FN_NAME Factory
69#define TUNER_PROBE_FN_NAME Probe
70#define DECLARE_TUNER_FACTORY() \
71 public: \
72 static tuner* TUNER_FACTORY_FN_NAME(demod* p); \
73 static int TUNER_PROBE_FN_NAME(demod* d);
74#define IMPLEMENT_TUNER_FACTORY(class_name) \
75 tuner* class_name::TUNER_FACTORY_FN_NAME(demod* p) \
76 { return new class_name(p); }
77#define IMPLEMENT_INLINE_TUNER_FACTORY(class_name) \
78 public: \
79 static tuner* TUNER_FACTORY_FN_NAME(demod* p) \
80 { return new class_name(p); } \
81 static int TUNER_PROBE_FN_NAME(demod* d);
82
83// _WIN32: DLL WARNING! These will cause C4251, but only 'vector' can be exported as a DLL interface. You must have exactly the same STL headers in your importing files, otherwise your app will crash. Solution is to recompile this library with your own STL headers.
84 typedef std::pair<double,double> range_t;
85 typedef std::vector<double> values_t;
86 typedef std::map<int,std::string> num_name_map_t;
87
88 inline bool values_to_range(const values_t& v, range_t& r)
89{ if (v.empty()) return false; r = std::make_pair(v[0], v[v.size() - 1]); return true; }
90
91 inline bool is_valid_range(const range_t& r)
92{ return !(r.first == r.second); }
93
94 inline bool in_range(const range_t& r, double d)
95{ return !((d < r.first) || (d > r.second)); }
96
97 inline bool in_valid_range(const range_t& r, double d) // If invalid range, return 'true'
98{ return ((is_valid_range(r) == false) || (in_range(r, d))); }
99
100 inline double calc_range(const range_t& r)
101{ return (r.second - r.first); }
102
103 class log_sink
104{
105 public:
106 enum level
107 {
108 LOG_LEVEL_ERROR = -1, // Negative: more serious
109 LOG_LEVEL_DEFAULT = 0,
110 LOG_LEVEL_VERBOSE = 1, // Positive: more verbose
111 };
112 public:
113 virtual void on_log_message_va(int level, const char* msg, va_list args)=0;
114 public:
115 inline virtual void on_log_message(const char* msg, ...)
116 { va_list args; va_start(args, msg); on_log_message_va(LOG_LEVEL_DEFAULT, msg, args); }
117 inline virtual void on_log_message_ex(int level, const char* msg, ...)
118 { va_list args; va_start(args, msg); on_log_message_va(level, msg, args); }
119};
120
121 class i2c_interface
122{
123 public:
124 virtual int set_i2c_repeater(bool on = true, const char* function_name = NULL, int line_number = -1, const char* line = NULL)=0;
125 virtual int i2c_read(uint8_t i2c_addr, uint8_t *buffer, int len)=0;
126 virtual int i2c_write(uint8_t i2c_addr, uint8_t *buffer, int len)=0;
127 virtual int i2c_write_reg(uint8_t i2c_addr, uint8_t reg, uint8_t val)=0;
128 virtual int i2c_read_reg(uint8_t i2c_addr, uint8_t reg, uint8_t& data)=0;
129};
130
131 class named_interface
132{
133 public:
134 virtual const char* name() const=0;
135};
136
137 class RTL2832_API tuner : public i2c_interface, public named_interface
138{
139 public:
140 virtual ~tuner();
141 public:
142 typedef tuner* (*CreateTunerFn)(demod* p);
143 typedef int (*ProbeTunerFn)(demod* p);
144 typedef struct params
145 {
146 log_sink* message_output;
147 bool verbose;
148 } PARAMS, *PPARAMS;
149 enum gain_mode {
150 NOT_SUPPORTED = -1,
151 DEFAULT = 0,
152 // Specific values > 0 & internal to tuner implementations
153 };
154 public:
155 virtual int initialise(PPARAMS params = NULL)=0;
156 //virtual const char* name()=0;
157 virtual int set_frequency(double freq)=0;
158 virtual int set_bandwidth(double bw)=0;
159 virtual int set_gain(double gain)=0;
160 virtual int set_gain_mode(int mode)=0;
161 virtual int set_auto_gain_mode(bool on = true)=0;
162 public:
163 virtual int set_i2c_repeater(bool on = true, const char* function_name = NULL, int line_number = -1, const char* line = NULL)=0;
164 virtual int i2c_read(uint8_t i2c_addr, uint8_t *buffer, int len)=0;
165 virtual int i2c_write(uint8_t i2c_addr, uint8_t *buffer, int len)=0;
166 public:
167 virtual double frequency() const=0;
168 virtual double bandwidth() const=0;
169 virtual double gain() const=0;
170 virtual int gain_mode() const=0;
171 public:
172 virtual range_t gain_range() const=0;
173 virtual values_t gain_values() const=0;
174 virtual range_t frequency_range() const=0;
175 virtual range_t bandwidth_range() const=0;
176 virtual values_t bandwidth_values() const=0;
177 public:
178 virtual num_name_map_t gain_modes() const=0;
179 virtual bool calc_appropriate_gain_mode(int& mode)/* const*/=0;
180 virtual bool auto_gain_mode() const=0;
181 public:
182 virtual const PARAMS& params() const=0;
183 virtual demod* parent() const=0;
184};
185
186 class RTL2832_API tuner_skeleton : public tuner
187{
188 public:
189 tuner_skeleton(demod* p);
190 virtual ~tuner_skeleton();
191 protected:
192 demod* m_demod;
193 tuner::PARAMS m_params;
194 bool m_auto_gain_mode;
195 int m_gain_mode;
196 double m_freq;
197 double m_gain;
198 double m_bandwidth;
199 range_t m_gain_range;
200 values_t m_gain_values;
201 range_t m_frequency_range;
202 range_t m_bandwidth_range;
203 values_t m_bandwidth_values;
204 num_name_map_t m_gain_modes;
205 public:
206 virtual int initialise(tuner::PPARAMS params = NULL);
207 virtual const char* name() const
208 { return "(dummy)"; }
209 virtual int set_frequency(double freq)
210 { return SUCCESS; }
211 virtual int set_bandwidth(double bw)
212 { return SUCCESS; }
213 virtual int set_gain(double gain)
214 { return SUCCESS; }
215 virtual int set_gain_mode(int mode)
216 { return SUCCESS; }
217 public:
218 virtual int set_i2c_repeater(bool on = true, const char* function_name = NULL, int line_number = -1, const char* line = NULL);
219 virtual int i2c_read(uint8_t i2c_addr, uint8_t *buffer, int len);
220 virtual int i2c_write(uint8_t i2c_addr, uint8_t *buffer, int len);
221 virtual int i2c_write_reg(uint8_t i2c_addr, uint8_t reg, uint8_t val);
222 virtual int i2c_read_reg(uint8_t i2c_addr, uint8_t reg, uint8_t& data);
223 public:
224 virtual double frequency() const
225 { return m_freq; }
226 virtual double bandwidth() const
227 { return m_bandwidth; }
228 virtual double gain() const
229 { return m_gain; }
230 virtual int gain_mode() const
231 { return m_gain_mode; }
232 virtual int set_auto_gain_mode(bool on = true)
233 { m_auto_gain_mode = on; return SUCCESS; }
234 public:
235 virtual range_t gain_range() const
236 { return m_gain_range; }
237 virtual values_t gain_values() const
238 { return m_gain_values; }
239 virtual range_t frequency_range() const
240 { return m_frequency_range; }
241 virtual range_t bandwidth_range() const
242 { return m_bandwidth_range; }
243 virtual values_t bandwidth_values() const
244 { return m_bandwidth_values; }
245 public:
246 virtual num_name_map_t gain_modes() const
247 { return m_gain_modes; }
248 virtual bool calc_appropriate_gain_mode(int& mode)/* const*/
249 { mode = m_gain_mode; return true; }
250 virtual bool auto_gain_mode() const
251 { return m_auto_gain_mode; }
252 public:
253 const tuner::PARAMS& params() const
254 { return m_params; }
255 demod* parent() const
256 { return m_demod; }
257};
258
259 class i2c_repeater_scope
260{
261 private:
262 i2c_interface* m_p;
263 const char* m_function_name;
264 int m_line_number;
265 const char* m_line;
266 public:
267 i2c_repeater_scope(i2c_interface* p, const char* function_name = NULL, int line_number = -1, const char* line = NULL)
268 : m_p(p)
269 , m_function_name(function_name)
270 , m_line_number(line_number)
271 , m_line(line)
272 { p->set_i2c_repeater(true, function_name, line_number, line); }
273 ~i2c_repeater_scope()
274 { m_p->set_i2c_repeater(false, m_function_name, m_line_number, m_line); }
275};
276
277#define I2C_REPEATER_SCOPE(p) i2c_repeater_scope _i2c_repeater_scope(p, CURRENT_FUNCTION, __LINE__, p->name())
278#define THIS_I2C_REPEATER_SCOPE() I2C_REPEATER_SCOPE(this)
279
280 typedef struct device_info
281{
282 const char* name;
283 uint16_t vid, pid;
284 tuner::CreateTunerFn factory;
285 uint32_t max_rate, min_rate, crystal_frequency, flags;
286} DEVICE_INFO, *PDEVICE_INFO;
287
288//#define CHECK_LIBUSB_RESULT(r) (r)
289//#define CHECK_LIBUSB_NEG_RESULT(r) (r)
290//#define CHECK_LIBUSB_RESULT_EX(r,f,l,s) (r)
291#define CHECK_LIBUSB_RESULT(r) check_libusb_result(r, false, CURRENT_FUNCTION, __LINE__, #r)
292#define CHECK_LIBUSB_NEG_RESULT(r) check_libusb_result(r, true, CURRENT_FUNCTION, __LINE__, #r)
293#define CHECK_LIBUSB_RESULT_EX(r,f,l,s) check_libusb_result(r, false, f, l, s)
294
295#define CHECK_LIBUSB_RESULT_RETURN_EX(d,r) \
296 { int res = d->CHECK_LIBUSB_RESULT(r); \
297 if (res <= 0) return res; }
298
299#define CHECK_LIBUSB_NEG_RESULT_RETURN_EX(d,r) \
300 { int res = d->CHECK_LIBUSB_NEG_RESULT(r); \
301 if (res < 0) return res; }
302
303#define CHECK_LIBUSB_RESULT_RETURN(r) CHECK_LIBUSB_RESULT_RETURN_EX(this,r)
304#define CHECK_LIBUSB_NEG_RESULT_RETURN(d,r) CHECK_LIBUSB_NEG_RESULT_RETURN_EX(this,r)
305
306#define RTL2832_FIR_COEFF_COUNT 20
307#define RTL2832_TUNER_NAME_LEN (32+1)
308
309 class RTL2832_API demod : public i2c_interface, public named_interface
310{
311 public:
312 demod();
313 virtual ~demod();
314 public:
315 //static const int FIR_COEFF_COUNT = 20;
316 //static const int TUNER_NAME_LEN = 32+1;
317 typedef struct params
318 {
319 uint16_t vid;
320 uint16_t pid;
321 bool verbose;
322 int default_timeout; // 0: use default, -1: poll only
323 log_sink* message_output;
324 bool use_custom_fir_coefficients;
325 uint8_t fir_coeff[RTL2832_FIR_COEFF_COUNT];
326 //bool use_tuner_params; // Use if valid tuner::PPARAMS pointer
327 tuner::PPARAMS tuner_params;
328 uint32_t crystal_frequency;
329 char tuner_name[RTL2832_TUNER_NAME_LEN];
330 } PARAMS, *PPARAMS;
331 protected:
332 struct libusb_device_handle *m_devh;
333 PDEVICE_INFO m_current_info;
334 tuner *m_tuner, *m_dummy_tuner;
335 bool m_libusb_init_done;
336 PARAMS m_params;
337 range_t m_sample_rate_range;
338 double m_sample_rate;
339 uint32_t m_crystal_frequency;
340 bool m_tuner_was_active; // True if the kernel driver was detached
341 public:
342 int initialise(PPARAMS params = NULL);
343 const char* name() const;
344 void destroy();
345 int reset();
346 int set_sample_rate(uint32_t samp_rate, double* real_rate = NULL);
347 int set_if(double frequency);
348 int read_samples(unsigned char* buffer, uint32_t buffer_size, int* bytes_read, int timeout = -1);
349 protected:
350 int find_device();
351 int init_demod();
352 int demod_write_reg(uint8_t page, uint16_t addr, uint16_t val, uint8_t len);
353 int demod_read_reg(uint8_t page, uint8_t addr, uint8_t len, uint16_t& reg);
354 int write_reg(uint8_t block, uint16_t addr, uint16_t val, uint8_t len);
355 int read_reg(uint8_t block, uint16_t addr, uint8_t len, uint16_t& reg);
356 int write_array(uint8_t block, uint16_t addr, uint8_t *array, uint8_t len);
357 int read_array(uint8_t block, uint16_t addr, uint8_t *array, uint8_t len);
358 public:
359 int check_libusb_result(int res, bool zero_okay, const char* function_name = NULL, int line_number = -1, const char* line = NULL);
360 void log(const char* message, ...);
361 public:
362 int set_i2c_repeater(bool on = true, const char* function_name = NULL, int line_number = -1, const char* line = NULL);
363 int i2c_read(uint8_t i2c_addr, uint8_t *buffer, int len);
364 int i2c_write(uint8_t i2c_addr, uint8_t *buffer, int len);
365 int i2c_write_reg(uint8_t i2c_addr, uint8_t reg, uint8_t val);
366 int i2c_read_reg(uint8_t i2c_addr, uint8_t reg, uint8_t& data);
367 public:
368 int set_gpio_output(uint8_t gpio);
369 int set_gpio_bit(uint8_t gpio, int val);
370 public:
371 inline tuner* active_tuner() const
372 { return m_tuner; }
373 inline double sample_rate() const
374 { return m_sample_rate; }
375 inline uint32_t crystal_frequency() const
376 { return m_crystal_frequency; }
377 range_t sample_rate_range() const
378 { return m_sample_rate_range; }
379 protected:
380 enum usb_reg {
381 USB_SYSCTL = 0x2000,
382 USB_CTRL = 0x2010,
383 USB_STAT = 0x2014,
384 USB_EPA_CFG = 0x2144,
385 USB_EPA_CTL = 0x2148,
386 USB_EPA_MAXPKT = 0x2158,
387 USB_EPA_MAXPKT_2 = 0x215a,
388 USB_EPA_FIFO_CFG = 0x2160,
389 };
390 enum sys_reg {
391 DEMOD_CTL = 0x3000,
392 GPO = 0x3001,
393 GPI = 0x3002,
394 GPOE = 0x3003,
395 GPD = 0x3004,
396 SYSINTE = 0x3005,
397 SYSINTS = 0x3006,
398 GP_CFG0 = 0x3007,
399 GP_CFG1 = 0x3008,
400 SYSINTE_1 = 0x3009,
401 SYSINTS_1 = 0x300a,
402 DEMOD_CTL_1 = 0x300b,
403 IR_SUSPEND = 0x300c,
404 };
405 enum blocks {
406 DEMODB = 0,
407 USBB = 1,
408 SYSB = 2,
409 TUNB = 3,
410 ROMB = 4,
411 IRB = 5,
412 IICB = 6,
413 };
414};
415
416}
417
418#endif // INCLUDED_RTL2832
RTL2832_NAMESPACE::demod
Definition rtl2832.h:310
RTL2832_NAMESPACE::demod::sample_rate
double sample_rate() const
Definition rtl2832.h:373
RTL2832_NAMESPACE::demod::crystal_frequency
uint32_t crystal_frequency() const
Definition rtl2832.h:375
RTL2832_NAMESPACE::demod::i2c_read
int i2c_read(uint8_t i2c_addr, uint8_t *buffer, int len)
RTL2832_NAMESPACE::demod::active_tuner
tuner * active_tuner() const
Definition rtl2832.h:371
RTL2832_NAMESPACE::demod::m_dummy_tuner
tuner * m_dummy_tuner
Definition rtl2832.h:334
RTL2832_NAMESPACE::demod::i2c_write
int i2c_write(uint8_t i2c_addr, uint8_t *buffer, int len)
RTL2832_NAMESPACE::demod::m_libusb_init_done
bool m_libusb_init_done
Definition rtl2832.h:335
RTL2832_NAMESPACE::demod::check_libusb_result
int check_libusb_result(int res, bool zero_okay, const char *function_name=NULL, int line_number=-1, const char *line=NULL)
RTL2832_NAMESPACE::demod::sample_rate_range
range_t sample_rate_range() const
Definition rtl2832.h:377
RTL2832_NAMESPACE::demod::write_reg
int write_reg(uint8_t block, uint16_t addr, uint16_t val, uint8_t len)
RTL2832_NAMESPACE::demod::read_array
int read_array(uint8_t block, uint16_t addr, uint8_t *array, uint8_t len)
RTL2832_NAMESPACE::demod::demod_write_reg
int demod_write_reg(uint8_t page, uint16_t addr, uint16_t val, uint8_t len)
RTL2832_NAMESPACE::demod::sys_reg
sys_reg
Definition rtl2832.h:390
RTL2832_NAMESPACE::demod::SYSINTE_1
@ SYSINTE_1
Definition rtl2832.h:400
RTL2832_NAMESPACE::demod::IR_SUSPEND
@ IR_SUSPEND
Definition rtl2832.h:403
RTL2832_NAMESPACE::demod::SYSINTS_1
@ SYSINTS_1
Definition rtl2832.h:401
RTL2832_NAMESPACE::demod::GPO
@ GPO
Definition rtl2832.h:392
RTL2832_NAMESPACE::demod::SYSINTE
@ SYSINTE
Definition rtl2832.h:396
RTL2832_NAMESPACE::demod::DEMOD_CTL
@ DEMOD_CTL
Definition rtl2832.h:391
RTL2832_NAMESPACE::demod::GP_CFG1
@ GP_CFG1
Definition rtl2832.h:399
RTL2832_NAMESPACE::demod::GPOE
@ GPOE
Definition rtl2832.h:394
RTL2832_NAMESPACE::demod::GPI
@ GPI
Definition rtl2832.h:393
RTL2832_NAMESPACE::demod::GP_CFG0
@ GP_CFG0
Definition rtl2832.h:398
RTL2832_NAMESPACE::demod::SYSINTS
@ SYSINTS
Definition rtl2832.h:397
RTL2832_NAMESPACE::demod::GPD
@ GPD
Definition rtl2832.h:395
RTL2832_NAMESPACE::demod::DEMOD_CTL_1
@ DEMOD_CTL_1
Definition rtl2832.h:402
RTL2832_NAMESPACE::demod::set_if
int set_if(double frequency)
RTL2832_NAMESPACE::demod::demod
demod()
RTL2832_NAMESPACE::demod::m_sample_rate_range
range_t m_sample_rate_range
Definition rtl2832.h:337
RTL2832_NAMESPACE::demod::blocks
blocks
Definition rtl2832.h:405
RTL2832_NAMESPACE::demod::IICB
@ IICB
Definition rtl2832.h:412
RTL2832_NAMESPACE::demod::ROMB
@ ROMB
Definition rtl2832.h:410
RTL2832_NAMESPACE::demod::SYSB
@ SYSB
Definition rtl2832.h:408
RTL2832_NAMESPACE::demod::TUNB
@ TUNB
Definition rtl2832.h:409
RTL2832_NAMESPACE::demod::USBB
@ USBB
Definition rtl2832.h:407
RTL2832_NAMESPACE::demod::DEMODB
@ DEMODB
Definition rtl2832.h:406
RTL2832_NAMESPACE::demod::IRB
@ IRB
Definition rtl2832.h:411
RTL2832_NAMESPACE::demod::m_devh
struct libusb_device_handle * m_devh
Definition rtl2832.h:332
RTL2832_NAMESPACE::demod::read_reg
int read_reg(uint8_t block, uint16_t addr, uint8_t len, uint16_t &reg)
RTL2832_NAMESPACE::demod::usb_reg
usb_reg
Definition rtl2832.h:380
RTL2832_NAMESPACE::demod::USB_STAT
@ USB_STAT
Definition rtl2832.h:383
RTL2832_NAMESPACE::demod::USB_EPA_CTL
@ USB_EPA_CTL
Definition rtl2832.h:385
RTL2832_NAMESPACE::demod::USB_CTRL
@ USB_CTRL
Definition rtl2832.h:382
RTL2832_NAMESPACE::demod::USB_EPA_FIFO_CFG
@ USB_EPA_FIFO_CFG
Definition rtl2832.h:388
RTL2832_NAMESPACE::demod::USB_EPA_MAXPKT
@ USB_EPA_MAXPKT
Definition rtl2832.h:386
RTL2832_NAMESPACE::demod::USB_EPA_CFG
@ USB_EPA_CFG
Definition rtl2832.h:384
RTL2832_NAMESPACE::demod::USB_EPA_MAXPKT_2
@ USB_EPA_MAXPKT_2
Definition rtl2832.h:387
RTL2832_NAMESPACE::demod::USB_SYSCTL
@ USB_SYSCTL
Definition rtl2832.h:381
RTL2832_NAMESPACE::demod::PARAMS
struct RTL2832_NAMESPACE::demod::params PARAMS
RTL2832_NAMESPACE::demod::PPARAMS
struct RTL2832_NAMESPACE::demod::params * PPARAMS
RTL2832_NAMESPACE::demod::reset
int reset()
RTL2832_NAMESPACE::demod::destroy
void destroy()
RTL2832_NAMESPACE::demod::m_sample_rate
double m_sample_rate
Definition rtl2832.h:338
RTL2832_NAMESPACE::demod::m_tuner_was_active
bool m_tuner_was_active
Definition rtl2832.h:340
RTL2832_NAMESPACE::demod::initialise
int initialise(PPARAMS params=NULL)
RTL2832_NAMESPACE::demod::set_gpio_bit
int set_gpio_bit(uint8_t gpio, int val)
RTL2832_NAMESPACE::demod::set_i2c_repeater
int set_i2c_repeater(bool on=true, const char *function_name=NULL, int line_number=-1, const char *line=NULL)
RTL2832_NAMESPACE::demod::m_current_info
PDEVICE_INFO m_current_info
Definition rtl2832.h:333
RTL2832_NAMESPACE::demod::i2c_read_reg
int i2c_read_reg(uint8_t i2c_addr, uint8_t reg, uint8_t &data)
RTL2832_NAMESPACE::demod::i2c_write_reg
int i2c_write_reg(uint8_t i2c_addr, uint8_t reg, uint8_t val)
RTL2832_NAMESPACE::demod::demod_read_reg
int demod_read_reg(uint8_t page, uint8_t addr, uint8_t len, uint16_t &reg)
RTL2832_NAMESPACE::demod::find_device
int find_device()
RTL2832_NAMESPACE::demod::set_sample_rate
int set_sample_rate(uint32_t samp_rate, double *real_rate=NULL)
RTL2832_NAMESPACE::demod::set_gpio_output
int set_gpio_output(uint8_t gpio)
RTL2832_NAMESPACE::demod::m_params
PARAMS m_params
Definition rtl2832.h:336
RTL2832_NAMESPACE::demod::name
const char * name() const
RTL2832_NAMESPACE::demod::~demod
virtual ~demod()
RTL2832_NAMESPACE::demod::log
void log(const char *message,...)
RTL2832_NAMESPACE::demod::init_demod
int init_demod()
RTL2832_NAMESPACE::demod::m_crystal_frequency
uint32_t m_crystal_frequency
Definition rtl2832.h:339
RTL2832_NAMESPACE::demod::read_samples
int read_samples(unsigned char *buffer, uint32_t buffer_size, int *bytes_read, int timeout=-1)
RTL2832_NAMESPACE::demod::write_array
int write_array(uint8_t block, uint16_t addr, uint8_t *array, uint8_t len)
RTL2832_NAMESPACE::demod::m_tuner
tuner * m_tuner
Definition rtl2832.h:334
RTL2832_NAMESPACE::i2c_interface
Definition rtl2832.h:122
RTL2832_NAMESPACE::i2c_interface::i2c_read
virtual int i2c_read(uint8_t i2c_addr, uint8_t *buffer, int len)=0
RTL2832_NAMESPACE::i2c_interface::set_i2c_repeater
virtual int set_i2c_repeater(bool on=true, const char *function_name=NULL, int line_number=-1, const char *line=NULL)=0
RTL2832_NAMESPACE::i2c_interface::i2c_write_reg
virtual int i2c_write_reg(uint8_t i2c_addr, uint8_t reg, uint8_t val)=0
RTL2832_NAMESPACE::i2c_interface::i2c_read_reg
virtual int i2c_read_reg(uint8_t i2c_addr, uint8_t reg, uint8_t &data)=0
RTL2832_NAMESPACE::i2c_interface::i2c_write
virtual int i2c_write(uint8_t i2c_addr, uint8_t *buffer, int len)=0
RTL2832_NAMESPACE::i2c_repeater_scope::i2c_repeater_scope
i2c_repeater_scope(i2c_interface *p, const char *function_name=NULL, int line_number=-1, const char *line=NULL)
Definition rtl2832.h:267
RTL2832_NAMESPACE::i2c_repeater_scope::~i2c_repeater_scope
~i2c_repeater_scope()
Definition rtl2832.h:273
RTL2832_NAMESPACE::log_sink
Definition rtl2832.h:104
RTL2832_NAMESPACE::log_sink::level
level
Definition rtl2832.h:107
RTL2832_NAMESPACE::log_sink::LOG_LEVEL_ERROR
@ LOG_LEVEL_ERROR
Definition rtl2832.h:108
RTL2832_NAMESPACE::log_sink::LOG_LEVEL_DEFAULT
@ LOG_LEVEL_DEFAULT
Definition rtl2832.h:109
RTL2832_NAMESPACE::log_sink::LOG_LEVEL_VERBOSE
@ LOG_LEVEL_VERBOSE
Definition rtl2832.h:110
RTL2832_NAMESPACE::log_sink::on_log_message_va
virtual void on_log_message_va(int level, const char *msg, va_list args)=0
RTL2832_NAMESPACE::log_sink::on_log_message
virtual void on_log_message(const char *msg,...)
Definition rtl2832.h:115
RTL2832_NAMESPACE::log_sink::on_log_message_ex
virtual void on_log_message_ex(int level, const char *msg,...)
Definition rtl2832.h:117
RTL2832_NAMESPACE::named_interface
Definition rtl2832.h:132
RTL2832_NAMESPACE::named_interface::name
virtual const char * name() const =0
RTL2832_NAMESPACE::tuner_skeleton::bandwidth_range
virtual range_t bandwidth_range() const
Definition rtl2832.h:241
RTL2832_NAMESPACE::tuner_skeleton::m_gain_values
values_t m_gain_values
Definition rtl2832.h:200
RTL2832_NAMESPACE::tuner_skeleton::m_bandwidth
double m_bandwidth
Definition rtl2832.h:198
RTL2832_NAMESPACE::tuner_skeleton::initialise
virtual int initialise(tuner::PPARAMS params=NULL)
RTL2832_NAMESPACE::tuner_skeleton::gain_mode
virtual int gain_mode() const
Definition rtl2832.h:230
RTL2832_NAMESPACE::tuner_skeleton::m_auto_gain_mode
bool m_auto_gain_mode
Definition rtl2832.h:194
RTL2832_NAMESPACE::tuner_skeleton::tuner_skeleton
tuner_skeleton(demod *p)
RTL2832_NAMESPACE::tuner_skeleton::m_gain_range
range_t m_gain_range
Definition rtl2832.h:199
RTL2832_NAMESPACE::tuner_skeleton::i2c_write
virtual int i2c_write(uint8_t i2c_addr, uint8_t *buffer, int len)
RTL2832_NAMESPACE::tuner_skeleton::params
const tuner::PARAMS & params() const
Definition rtl2832.h:253
RTL2832_NAMESPACE::tuner_skeleton::set_frequency
virtual int set_frequency(double freq)
Definition rtl2832.h:209
RTL2832_NAMESPACE::tuner_skeleton::name
virtual const char * name() const
Definition rtl2832.h:207
RTL2832_NAMESPACE::tuner_skeleton::bandwidth
virtual double bandwidth() const
Definition rtl2832.h:226
RTL2832_NAMESPACE::tuner_skeleton::m_bandwidth_values
values_t m_bandwidth_values
Definition rtl2832.h:203
RTL2832_NAMESPACE::tuner_skeleton::bandwidth_values
virtual values_t bandwidth_values() const
Definition rtl2832.h:243
RTL2832_NAMESPACE::tuner_skeleton::m_params
tuner::PARAMS m_params
Definition rtl2832.h:193
RTL2832_NAMESPACE::tuner_skeleton::calc_appropriate_gain_mode
virtual bool calc_appropriate_gain_mode(int &mode)
Definition rtl2832.h:248
RTL2832_NAMESPACE::tuner_skeleton::m_bandwidth_range
range_t m_bandwidth_range
Definition rtl2832.h:202
RTL2832_NAMESPACE::tuner_skeleton::m_freq
double m_freq
Definition rtl2832.h:196
RTL2832_NAMESPACE::tuner_skeleton::m_gain_mode
int m_gain_mode
Definition rtl2832.h:195
RTL2832_NAMESPACE::tuner_skeleton::frequency
virtual double frequency() const
Definition rtl2832.h:224
RTL2832_NAMESPACE::tuner_skeleton::~tuner_skeleton
virtual ~tuner_skeleton()
RTL2832_NAMESPACE::tuner_skeleton::i2c_read_reg
virtual int i2c_read_reg(uint8_t i2c_addr, uint8_t reg, uint8_t &data)
RTL2832_NAMESPACE::tuner_skeleton::gain_range
virtual range_t gain_range() const
Definition rtl2832.h:235
RTL2832_NAMESPACE::tuner_skeleton::m_gain
double m_gain
Definition rtl2832.h:197
RTL2832_NAMESPACE::tuner_skeleton::set_bandwidth
virtual int set_bandwidth(double bw)
Definition rtl2832.h:211
RTL2832_NAMESPACE::tuner_skeleton::i2c_write_reg
virtual int i2c_write_reg(uint8_t i2c_addr, uint8_t reg, uint8_t val)
RTL2832_NAMESPACE::tuner_skeleton::m_demod
demod * m_demod
Definition rtl2832.h:192
RTL2832_NAMESPACE::tuner_skeleton::auto_gain_mode
virtual bool auto_gain_mode() const
Definition rtl2832.h:250
RTL2832_NAMESPACE::tuner_skeleton::set_auto_gain_mode
virtual int set_auto_gain_mode(bool on=true)
Definition rtl2832.h:232
RTL2832_NAMESPACE::tuner_skeleton::set_gain_mode
virtual int set_gain_mode(int mode)
Definition rtl2832.h:215
RTL2832_NAMESPACE::tuner_skeleton::gain_values
virtual values_t gain_values() const
Definition rtl2832.h:237
RTL2832_NAMESPACE::tuner_skeleton::gain
virtual double gain() const
Definition rtl2832.h:228
RTL2832_NAMESPACE::tuner_skeleton::parent
demod * parent() const
Definition rtl2832.h:255
RTL2832_NAMESPACE::tuner_skeleton::gain_modes
virtual num_name_map_t gain_modes() const
Definition rtl2832.h:246
RTL2832_NAMESPACE::tuner_skeleton::frequency_range
virtual range_t frequency_range() const
Definition rtl2832.h:239
RTL2832_NAMESPACE::tuner_skeleton::m_gain_modes
num_name_map_t m_gain_modes
Definition rtl2832.h:204
RTL2832_NAMESPACE::tuner_skeleton::set_gain
virtual int set_gain(double gain)
Definition rtl2832.h:213
RTL2832_NAMESPACE::tuner_skeleton::i2c_read
virtual int i2c_read(uint8_t i2c_addr, uint8_t *buffer, int len)
RTL2832_NAMESPACE::tuner_skeleton::m_frequency_range
range_t m_frequency_range
Definition rtl2832.h:201
RTL2832_NAMESPACE::tuner_skeleton::set_i2c_repeater
virtual int set_i2c_repeater(bool on=true, const char *function_name=NULL, int line_number=-1, const char *line=NULL)
RTL2832_NAMESPACE::tuner
Definition rtl2832.h:138
RTL2832_NAMESPACE::tuner::parent
virtual demod * parent() const =0
RTL2832_NAMESPACE::tuner::initialise
virtual int initialise(PPARAMS params=NULL)=0
RTL2832_NAMESPACE::tuner::PPARAMS
struct RTL2832_NAMESPACE::tuner::params * PPARAMS
RTL2832_NAMESPACE::tuner::set_auto_gain_mode
virtual int set_auto_gain_mode(bool on=true)=0
RTL2832_NAMESPACE::tuner::ProbeTunerFn
int(* ProbeTunerFn)(demod *p)
Definition rtl2832.h:143
RTL2832_NAMESPACE::tuner::gain_range
virtual range_t gain_range() const =0
RTL2832_NAMESPACE::tuner::calc_appropriate_gain_mode
virtual bool calc_appropriate_gain_mode(int &mode)=0
RTL2832_NAMESPACE::tuner::bandwidth_values
virtual values_t bandwidth_values() const =0
RTL2832_NAMESPACE::tuner::CreateTunerFn
tuner *(* CreateTunerFn)(demod *p)
Definition rtl2832.h:142
RTL2832_NAMESPACE::tuner::gain
virtual double gain() const =0
RTL2832_NAMESPACE::tuner::auto_gain_mode
virtual bool auto_gain_mode() const =0
RTL2832_NAMESPACE::tuner::frequency_range
virtual range_t frequency_range() const =0
RTL2832_NAMESPACE::tuner::gain_mode
virtual int gain_mode() const =0
RTL2832_NAMESPACE::tuner::i2c_write
virtual int i2c_write(uint8_t i2c_addr, uint8_t *buffer, int len)=0
RTL2832_NAMESPACE::tuner::params
virtual const PARAMS & params() const =0
RTL2832_NAMESPACE::tuner::set_i2c_repeater
virtual int set_i2c_repeater(bool on=true, const char *function_name=NULL, int line_number=-1, const char *line=NULL)=0
RTL2832_NAMESPACE::tuner::~tuner
virtual ~tuner()
RTL2832_NAMESPACE::tuner::set_gain
virtual int set_gain(double gain)=0
RTL2832_NAMESPACE::tuner::bandwidth_range
virtual range_t bandwidth_range() const =0
RTL2832_NAMESPACE::tuner::set_frequency
virtual int set_frequency(double freq)=0
RTL2832_NAMESPACE::tuner::set_bandwidth
virtual int set_bandwidth(double bw)=0
RTL2832_NAMESPACE::tuner::gain_modes
virtual num_name_map_t gain_modes() const =0
RTL2832_NAMESPACE::tuner::set_gain_mode
virtual int set_gain_mode(int mode)=0
RTL2832_NAMESPACE::tuner::gain_mode
gain_mode
Definition rtl2832.h:149
RTL2832_NAMESPACE::tuner::DEFAULT
@ DEFAULT
Definition rtl2832.h:151
RTL2832_NAMESPACE::tuner::NOT_SUPPORTED
@ NOT_SUPPORTED
Definition rtl2832.h:150
RTL2832_NAMESPACE::tuner::gain_values
virtual values_t gain_values() const =0
RTL2832_NAMESPACE::tuner::frequency
virtual double frequency() const =0
RTL2832_NAMESPACE::tuner::PARAMS
struct RTL2832_NAMESPACE::tuner::params PARAMS
RTL2832_NAMESPACE::tuner::i2c_read
virtual int i2c_read(uint8_t i2c_addr, uint8_t *buffer, int len)=0
RTL2832_NAMESPACE::tuner::bandwidth
virtual double bandwidth() const =0
RTL2832_NAMESPACE
Definition rtl2832-tuner_e4000.h:6
RTL2832_NAMESPACE::in_range
bool in_range(const range_t &r, double d)
Definition rtl2832.h:94
RTL2832_NAMESPACE::in_valid_range
bool in_valid_range(const range_t &r, double d)
Definition rtl2832.h:97
RTL2832_NAMESPACE::range_t
std::pair< double, double > range_t
Definition rtl2832.h:84
RTL2832_NAMESPACE::is_valid_range
bool is_valid_range(const range_t &r)
Definition rtl2832.h:91
RTL2832_NAMESPACE::PDEVICE_INFO
struct RTL2832_NAMESPACE::device_info * PDEVICE_INFO
RTL2832_NAMESPACE::result_code
result_code
Definition rtl2832.h:60
RTL2832_NAMESPACE::FAILURE
@ FAILURE
Definition rtl2832.h:62
RTL2832_NAMESPACE::SUCCESS
@ SUCCESS
Definition rtl2832.h:63
RTL2832_NAMESPACE::num_name_map_t
std::map< int, std::string > num_name_map_t
Definition rtl2832.h:86
RTL2832_NAMESPACE::values_to_range
bool values_to_range(const values_t &v, range_t &r)
Definition rtl2832.h:88
RTL2832_NAMESPACE::values_t
std::vector< double > values_t
Definition rtl2832.h:85
RTL2832_NAMESPACE::calc_range
double calc_range(const range_t &r)
Definition rtl2832.h:100
get_map_index
RTL2832_API int get_map_index(int value, const int *map, int pair_count)
RTL2832_API
#define RTL2832_API
Definition rtl2832.h:28
RTL2832_TUNER_NAME_LEN
#define RTL2832_TUNER_NAME_LEN
Definition rtl2832.h:307
RTL2832_FIR_COEFF_COUNT
#define RTL2832_FIR_COEFF_COUNT
Definition rtl2832.h:306
libusb_result_to_string
RTL2832_API const char * libusb_result_to_string(int res)
RTL2832_NAMESPACE::demod::params
Definition rtl2832.h:318
RTL2832_NAMESPACE::demod::params::vid
uint16_t vid
Definition rtl2832.h:319
RTL2832_NAMESPACE::demod::params::fir_coeff
uint8_t fir_coeff[RTL2832_FIR_COEFF_COUNT]
Definition rtl2832.h:325
RTL2832_NAMESPACE::demod::params::crystal_frequency
uint32_t crystal_frequency
Definition rtl2832.h:328
RTL2832_NAMESPACE::demod::params::tuner_name
char tuner_name[RTL2832_TUNER_NAME_LEN]
Definition rtl2832.h:329
RTL2832_NAMESPACE::demod::params::use_custom_fir_coefficients
bool use_custom_fir_coefficients
Definition rtl2832.h:324
RTL2832_NAMESPACE::demod::params::verbose
bool verbose
Definition rtl2832.h:321
RTL2832_NAMESPACE::demod::params::pid
uint16_t pid
Definition rtl2832.h:320
RTL2832_NAMESPACE::demod::params::default_timeout
int default_timeout
Definition rtl2832.h:322
RTL2832_NAMESPACE::demod::params::message_output
log_sink * message_output
Definition rtl2832.h:323
RTL2832_NAMESPACE::demod::params::tuner_params
tuner::PPARAMS tuner_params
Definition rtl2832.h:327
RTL2832_NAMESPACE::device_info
Definition rtl2832.h:281
RTL2832_NAMESPACE::device_info::max_rate
uint32_t max_rate
Definition rtl2832.h:285
RTL2832_NAMESPACE::device_info::vid
uint16_t vid
Definition rtl2832.h:283
RTL2832_NAMESPACE::device_info::crystal_frequency
uint32_t crystal_frequency
Definition rtl2832.h:285
RTL2832_NAMESPACE::device_info::flags
uint32_t flags
Definition rtl2832.h:285
RTL2832_NAMESPACE::device_info::factory
tuner::CreateTunerFn factory
Definition rtl2832.h:284
RTL2832_NAMESPACE::device_info::name
const char * name
Definition rtl2832.h:282
RTL2832_NAMESPACE::device_info::pid
uint16_t pid
Definition rtl2832.h:283
RTL2832_NAMESPACE::device_info::min_rate
uint32_t min_rate
Definition rtl2832.h:285
RTL2832_NAMESPACE::tuner::params
Definition rtl2832.h:145
RTL2832_NAMESPACE::tuner::params::verbose
bool verbose
Definition rtl2832.h:147
RTL2832_NAMESPACE::tuner::params::message_output
log_sink * message_output
Definition rtl2832.h:146