mirror of
https://github.com/gnss-sdr/gnss-sdr
synced 2025-11-17 23:55:15 +00:00
Setting gains
This commit is contained in:
@@ -32,6 +32,7 @@
|
||||
*/
|
||||
#include "rtl_tcp_dongle_info.h"
|
||||
#include <string.h>
|
||||
#include <boost/foreach.hpp>
|
||||
|
||||
using boost::asio::ip::tcp;
|
||||
|
||||
@@ -85,6 +86,59 @@ const char *rtl_tcp_dongle_info::get_type_name () const {
|
||||
}
|
||||
}
|
||||
|
||||
double rtl_tcp_dongle_info::clip_gain (int gain) const {
|
||||
// the following gain values have been copied from librtlsdr
|
||||
// all gain values are expressed in tenths of a dB
|
||||
|
||||
std::vector<double> gains;
|
||||
switch (get_tuner_type()) {
|
||||
case TUNER_E4000:
|
||||
gains = { -10, 15, 40, 65, 90, 115, 140, 165, 190, 215,
|
||||
240, 290, 340, 420 };
|
||||
break;
|
||||
case TUNER_FC0012:
|
||||
gains = { -99, -40, 71, 179, 192 };
|
||||
break;
|
||||
case TUNER_FC0013:
|
||||
gains = { -99, -73, -65, -63, -60, -58, -54, 58, 61,
|
||||
63, 65, 67, 68, 70, 71, 179, 181, 182,
|
||||
184, 186, 188, 191, 197 };
|
||||
break;
|
||||
case TUNER_R820T:
|
||||
gains = { 0, 9, 14, 27, 37, 77, 87, 125, 144, 157,
|
||||
166, 197, 207, 229, 254, 280, 297, 328,
|
||||
338, 364, 372, 386, 402, 421, 434, 439,
|
||||
445, 480, 496 };
|
||||
break;
|
||||
default:
|
||||
// no gains
|
||||
break;
|
||||
}
|
||||
|
||||
// clip
|
||||
if (gains.size() == 0) {
|
||||
// no defined gains to clip to
|
||||
return gain;
|
||||
}
|
||||
else {
|
||||
double last_stop = gains.front ();
|
||||
BOOST_FOREACH (double g, gains) {
|
||||
g /= 10.0;
|
||||
|
||||
if (gain < g) {
|
||||
if (std::abs (gain - g) < std::abs (gain - last_stop)) {
|
||||
return g;
|
||||
}
|
||||
else {
|
||||
return last_stop;
|
||||
}
|
||||
}
|
||||
last_stop = g;
|
||||
}
|
||||
return last_stop;
|
||||
}
|
||||
}
|
||||
|
||||
bool rtl_tcp_dongle_info::is_valid () const {
|
||||
return ::memcmp (magic_, "RTL0", 4) == 0;
|
||||
}
|
||||
|
||||
@@ -65,6 +65,8 @@ class rtl_tcp_dongle_info {
|
||||
|
||||
const char *get_type_name () const;
|
||||
|
||||
double clip_gain (int gain) const;
|
||||
|
||||
inline uint32_t get_tuner_type () const {
|
||||
return tuner_type_;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user