[hamradio-commits] [gnss-sdr] 55/251: Setting gains

Carles Fernandez carles_fernandez-guest at moszumanska.debian.org
Wed Sep 2 00:22:35 UTC 2015


This is an automated email from the git hooks/post-receive script.

carles_fernandez-guest pushed a commit to branch master
in repository gnss-sdr.

commit 96fc353fe409a30ad8c642aae84861c953af9c60
Author: Anthony Arnold <anthony.arnold at uqconnect.edu.au>
Date:   Sun May 10 23:42:13 2015 +1000

    Setting gains
---
 .../signal_source/adapters/CMakeLists.txt          |  1 +
 .../gnuradio_blocks/rtl_tcp_signal_source_c.cc     | 17 ++++---
 .../gnuradio_blocks/rtl_tcp_signal_source_c.h      |  3 ++
 .../signal_source/libs/rtl_tcp_dongle_info.cc      | 54 ++++++++++++++++++++++
 .../signal_source/libs/rtl_tcp_dongle_info.h       |  2 +
 src/core/receiver/CMakeLists.txt                   | 53 ++++++++++-----------
 6 files changed, 97 insertions(+), 33 deletions(-)

diff --git a/src/algorithms/signal_source/adapters/CMakeLists.txt b/src/algorithms/signal_source/adapters/CMakeLists.txt
index 2cb030b..4970d2b 100644
--- a/src/algorithms/signal_source/adapters/CMakeLists.txt
+++ b/src/algorithms/signal_source/adapters/CMakeLists.txt
@@ -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}
diff --git a/src/algorithms/signal_source/gnuradio_blocks/rtl_tcp_signal_source_c.cc b/src/algorithms/signal_source/gnuradio_blocks/rtl_tcp_signal_source_c.cc
index f754ba3..a564649 100644
--- a/src/algorithms/signal_source/gnuradio_blocks/rtl_tcp_signal_source_c.cc
+++ b/src/algorithms/signal_source/gnuradio_blocks/rtl_tcp_signal_source_c.cc
@@ -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 },
diff --git a/src/algorithms/signal_source/gnuradio_blocks/rtl_tcp_signal_source_c.h b/src/algorithms/signal_source/gnuradio_blocks/rtl_tcp_signal_source_c.h
index d207a61..c60b412 100644
--- a/src/algorithms/signal_source/gnuradio_blocks/rtl_tcp_signal_source_c.h
+++ b/src/algorithms/signal_source/gnuradio_blocks/rtl_tcp_signal_source_c.h
@@ -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_;
diff --git a/src/algorithms/signal_source/libs/rtl_tcp_dongle_info.cc b/src/algorithms/signal_source/libs/rtl_tcp_dongle_info.cc
index 4312277..e7e7b15 100644
--- a/src/algorithms/signal_source/libs/rtl_tcp_dongle_info.cc
+++ b/src/algorithms/signal_source/libs/rtl_tcp_dongle_info.cc
@@ -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;
 }
diff --git a/src/algorithms/signal_source/libs/rtl_tcp_dongle_info.h b/src/algorithms/signal_source/libs/rtl_tcp_dongle_info.h
index 98e5f96..78e0ff6 100644
--- a/src/algorithms/signal_source/libs/rtl_tcp_dongle_info.h
+++ b/src/algorithms/signal_source/libs/rtl_tcp_dongle_info.h
@@ -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_;
     }
diff --git a/src/core/receiver/CMakeLists.txt b/src/core/receiver/CMakeLists.txt
index 94bff94..677efd7 100644
--- a/src/core/receiver/CMakeLists.txt
+++ b/src/core/receiver/CMakeLists.txt
@@ -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
 )

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-hamradio/gnss-sdr.git



More information about the pkg-hamradio-commits mailing list