mirror of
https://github.com/gnss-sdr/gnss-sdr
synced 2025-04-05 02:07:02 +00:00
Setting gains
This commit is contained in:
parent
5f3ae0c66b
commit
96fc353fe4
@ -146,6 +146,7 @@ include_directories(
|
||||
${CMAKE_SOURCE_DIR}/src/core/system_parameters
|
||||
${CMAKE_SOURCE_DIR}/src/core/interfaces
|
||||
${CMAKE_SOURCE_DIR}/src/algorithms/libs
|
||||
${CMAKE_SOURCE_DIR}/src/algorithms/signal_source/libs
|
||||
${CMAKE_SOURCE_DIR}/src/algorithms/signal_source/gnuradio_blocks
|
||||
${GLOG_INCLUDE_DIRS}
|
||||
${GFlags_INCLUDE_DIRS}
|
||||
|
@ -32,7 +32,6 @@
|
||||
|
||||
#include "rtl_tcp_signal_source_c.h"
|
||||
#include "rtl_tcp_commands.h"
|
||||
#include "rtl_tcp_dongle_info.h"
|
||||
#include <glog/logging.h>
|
||||
#include <boost/thread/thread.hpp>
|
||||
#include <map>
|
||||
@ -118,15 +117,14 @@ rtl_tcp_signal_source_c::rtl_tcp_signal_source_c(const std::string &address,
|
||||
}
|
||||
|
||||
// 5. Receive dongle info
|
||||
rtl_tcp_dongle_info info;
|
||||
ec = info.read (socket_);
|
||||
ec = info_.read (socket_);
|
||||
if (ec) {
|
||||
std::cout << "Failed to read dongle info." << std::endl;
|
||||
LOG (WARNING) << "Failed to read dongle info";
|
||||
}
|
||||
else if (info.is_valid ()) {
|
||||
std::cout << "Found " << info.get_type_name() << " tuner." << std::endl;
|
||||
LOG (INFO) << "Found " << info.get_type_name() << " tuner.";
|
||||
else if (info_.is_valid ()) {
|
||||
std::cout << "Found " << info_.get_type_name() << " tuner." << std::endl;
|
||||
LOG (INFO) << "Found " << info_.get_type_name() << " tuner.";
|
||||
}
|
||||
|
||||
// 6. Start reading
|
||||
@ -204,8 +202,9 @@ void rtl_tcp_signal_source_c::set_agc_mode (bool agc) {
|
||||
}
|
||||
|
||||
void rtl_tcp_signal_source_c::set_gain (int gain) {
|
||||
unsigned clipped = static_cast<unsigned> (info_.clip_gain (gain) * 10.0);
|
||||
boost::system::error_code ec =
|
||||
rtl_tcp_command (RTL_TCP_SET_GAIN, gain, socket_);
|
||||
rtl_tcp_command (RTL_TCP_SET_GAIN, clipped, socket_);
|
||||
if (ec) {
|
||||
std::cout << "Failed to set gain" << std::endl;
|
||||
LOG (WARNING) << "Failed to set gain";
|
||||
@ -217,6 +216,10 @@ void rtl_tcp_signal_source_c::set_if_gain (int gain) {
|
||||
struct range {
|
||||
double start, stop, step;
|
||||
};
|
||||
if (info_.get_tuner_type () != rtl_tcp_dongle_info::TUNER_E4000) {
|
||||
return;
|
||||
}
|
||||
|
||||
std::vector<range> ranges = {
|
||||
{ -3, 6, 9 },
|
||||
{ 0, 9, 3 },
|
||||
|
@ -38,6 +38,7 @@
|
||||
#ifndef GNSS_SDR_RTL_TCP_SIGNAL_SOURCE_C_H
|
||||
#define GNSS_SDR_RTL_TCP_SIGNAL_SOURCE_C_H
|
||||
|
||||
#include "rtl_tcp_dongle_info.h"
|
||||
#include <boost/asio.hpp>
|
||||
#include <gnuradio/sync_block.h>
|
||||
#include <string>
|
||||
@ -87,6 +88,8 @@ private:
|
||||
short port,
|
||||
bool flip_iq);
|
||||
|
||||
rtl_tcp_dongle_info info_;
|
||||
|
||||
// IO members
|
||||
boost::asio::io_service io_service_;
|
||||
boost::asio::ip::tcp::socket socket_;
|
||||
|
@ -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_;
|
||||
}
|
||||
|
@ -16,10 +16,10 @@
|
||||
# along with GNSS-SDR. If not, see <http://www.gnu.org/licenses/>.
|
||||
#
|
||||
|
||||
set(GNSS_RECEIVER_SOURCES
|
||||
control_thread.cc
|
||||
control_message_factory.cc
|
||||
file_configuration.cc
|
||||
set(GNSS_RECEIVER_SOURCES
|
||||
control_thread.cc
|
||||
control_message_factory.cc
|
||||
file_configuration.cc
|
||||
gnss_block_factory.cc
|
||||
gnss_flowgraph.cc
|
||||
in_memory_configuration.cc
|
||||
@ -34,6 +34,7 @@ include_directories(
|
||||
${CMAKE_SOURCE_DIR}/src/core/libs/supl/asn-rrlp
|
||||
${CMAKE_SOURCE_DIR}/src/core/libs/supl/asn-supl
|
||||
${CMAKE_SOURCE_DIR}/src/algorithms/libs
|
||||
${CMAKE_SOURCE_DIR}/src/algorithms/signal_source/libs
|
||||
${CMAKE_SOURCE_DIR}/src/algorithms/signal_source/adapters
|
||||
${CMAKE_SOURCE_DIR}/src/algorithms/signal_source/gnuradio_blocks
|
||||
${CMAKE_SOURCE_DIR}/src/algorithms/output_filter/adapters
|
||||
@ -104,27 +105,27 @@ file(GLOB GNSS_RECEIVER_INTERFACE_HEADERS "../interfaces/*.h")
|
||||
add_library(gnss_rx ${GNSS_RECEIVER_SOURCES} ${GNSS_RECEIVER_HEADERS} ${GNSS_RECEIVER_INTERFACE_HEADERS})
|
||||
source_group(Headers FILES ${GNSS_RECEIVER_HEADERS} ${GNSS_RECEIVER_INTERFACE_HEADERS})
|
||||
|
||||
target_link_libraries(gnss_rx ${Boost_LIBRARIES}
|
||||
${ARMADILLO_LIBRARIES}
|
||||
${GNURADIO_RUNTIME_LIBRARIES}
|
||||
${GNURADIO_BLOCKS_LIBRARIES}
|
||||
${GNURADIO_FFT_LIBRARIES}
|
||||
${GNURADIO_FILTER_LIBRARIES}
|
||||
gnss_system_parameters
|
||||
gnss_sp_libs
|
||||
signal_source_adapters
|
||||
datatype_adapters
|
||||
input_filter_adapters
|
||||
conditioner_adapters
|
||||
resampler_adapters
|
||||
acq_adapters
|
||||
tracking_lib
|
||||
tracking_adapters
|
||||
channel_adapters
|
||||
telemetry_decoder_adapters
|
||||
obs_adapters
|
||||
pvt_adapters
|
||||
pvt_lib
|
||||
out_adapters
|
||||
target_link_libraries(gnss_rx ${Boost_LIBRARIES}
|
||||
${ARMADILLO_LIBRARIES}
|
||||
${GNURADIO_RUNTIME_LIBRARIES}
|
||||
${GNURADIO_BLOCKS_LIBRARIES}
|
||||
${GNURADIO_FFT_LIBRARIES}
|
||||
${GNURADIO_FILTER_LIBRARIES}
|
||||
gnss_system_parameters
|
||||
gnss_sp_libs
|
||||
signal_source_adapters
|
||||
datatype_adapters
|
||||
input_filter_adapters
|
||||
conditioner_adapters
|
||||
resampler_adapters
|
||||
acq_adapters
|
||||
tracking_lib
|
||||
tracking_adapters
|
||||
channel_adapters
|
||||
telemetry_decoder_adapters
|
||||
obs_adapters
|
||||
pvt_adapters
|
||||
pvt_lib
|
||||
out_adapters
|
||||
rx_core_lib
|
||||
)
|
||||
|
Loading…
x
Reference in New Issue
Block a user