[hamradio-commits] [gnss-sdr] 44/251: rtl_tcp specific signal source block

Carles Fernandez carles_fernandez-guest at moszumanska.debian.org
Wed Sep 2 00:22:34 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 128a7452d500e32e9165d798beaaf5b979af6005
Author: Anthony Arnold <anthony.arnold at uqconnect.ed.au>
Date:   Fri May 8 16:59:38 2015 +1000

    rtl_tcp specific signal source block
---
 conf/gnss-sdr_GPS_L1_rtl_tcp_realtime.conf         |  16 +-
 .../signal_source/adapters/CMakeLists.txt          |  67 +++----
 .../adapters/rtl_tcp_signal_source.cc              | 188 +++++++++++++++++++
 .../signal_source/adapters/rtl_tcp_signal_source.h | 114 ++++++++++++
 .../signal_source/gnuradio_blocks/CMakeLists.txt   |   6 +-
 .../gnuradio_blocks/rtl_tcp_signal_source_cc.cc    | 207 +++++++++++++++++++++
 .../gnuradio_blocks/rtl_tcp_signal_source_cc.h     | 100 ++++++++++
 src/core/receiver/gnss_block_factory.cc            |  16 ++
 8 files changed, 672 insertions(+), 42 deletions(-)

diff --git a/conf/gnss-sdr_GPS_L1_rtl_tcp_realtime.conf b/conf/gnss-sdr_GPS_L1_rtl_tcp_realtime.conf
index 930b554..5db4b11 100644
--- a/conf/gnss-sdr_GPS_L1_rtl_tcp_realtime.conf
+++ b/conf/gnss-sdr_GPS_L1_rtl_tcp_realtime.conf
@@ -9,7 +9,7 @@
 ;internal_fs_hz: Internal signal sampling frequency after the signal conditioning stage [Hz].
 ;FOR USE GNSS-SDR WITH RTLSDR DONGLES USER MUST SET THE CALIBRATED SAMPLE RATE HERE
 ; i.e. using front-end-cal as reported here:http://www.cttc.es/publication/turning-a-television-into-a-gnss-receiver/
-GNSS-SDR.internal_fs_hz=1999898
+GNSS-SDR.internal_fs_hz=1200000
 
 ;######### CONTROL_THREAD CONFIG ############
 ControlThread.wait_for_flowgraph=false
@@ -28,7 +28,7 @@ GNSS-SDR.SUPL_CI=0x31b0
 
 ;######### SIGNAL_SOURCE CONFIG ############
 ;#implementation: Use [File_Signal_Source] or [UHD_Signal_Source] or [GN3S_Signal_Source] [Osmosdr_Signal_Source]
-SignalSource.implementation=Osmosdr_Signal_Source
+SignalSource.implementation=RtlTcp_Signal_Source
 
 ;#filename: path to file with the captured GNSS signal samples to be processed
 SignalSource.filename=/media/DATALOGGER_/signals/RTL-SDR/geo/pmt4.dat
@@ -39,7 +39,7 @@ SignalSource.item_type=gr_complex
 ;#sampling_frequency: Original Signal sampling frequency in [Hz]
 ;FOR USE GNSS-SDR WITH RTLSDR DONGLES USER MUST SET THE CALIBRATED SAMPLE RATE HERE
 ; i.e. using front-end-cal as reported here:http://www.cttc.es/publication/turning-a-television-into-a-gnss-receiver/
-SignalSource.sampling_frequency=2000000
+SignalSource.sampling_frequency=1200000
 
 ;#freq: RF front-end center frequency in [Hz]
 SignalSource.freq=1575420000
@@ -72,9 +72,11 @@ SignalSource.dump_filename=../data/signal_source.dat
 ; it helps to not overload the CPU, but the processing time will be longer.
 SignalSource.enable_throttle_control=false
 
-;#Send optional arguments to the OsmoSdr Gnuradio block
-;#Arguments are comma-delimited. See http://sdr.osmocom.org/trac/wiki/GrOsmoSDR for documentation.
-SignalSource.osmosdr_args=rtl_tcp,offset_tune=1
+;#Address of the rtl_tcp server
+SignalSource.address=127.0.0.1
+
+;#Port of the rtl_tcp server
+SignalSource.port=1234
 
 ;######### SIGNAL_CONDITIONER CONFIG ############
 ;## It holds blocks to change data type, filter and resample input data.
@@ -157,7 +159,7 @@ InputFilter.grid_density=16
 ;#InputFilter.IF is the intermediate frequency (in Hz) shifted down to zero Hz
 ;FOR USE GNSS-SDR WITH RTLSDR DONGLES USER MUST SET THE CALIBRATED SAMPLE RATE HERE
 ; i.e. using front-end-cal as reported here:http://www.cttc.es/publication/turning-a-television-into-a-gnss-receiver/
-InputFilter.sampling_frequency=1999898
+InputFilter.sampling_frequency=1200000
 ;# IF deviation due to front-end LO inaccuracies [HZ]
 InputFilter.IF=80558
 
diff --git a/src/algorithms/signal_source/adapters/CMakeLists.txt b/src/algorithms/signal_source/adapters/CMakeLists.txt
index c8c753b..2cb030b 100644
--- a/src/algorithms/signal_source/adapters/CMakeLists.txt
+++ b/src/algorithms/signal_source/adapters/CMakeLists.txt
@@ -25,7 +25,7 @@ if(ENABLE_GN3S)
 
      # find_package(GrGN3S)
      # if not found, build it with ExternalPackage_Add
-     include(ExternalProject)     
+     include(ExternalProject)
      ExternalProject_Add(
           gr-gn3s
           SOURCE_DIR ${CMAKE_SOURCE_DIR}/drivers/gr-gn3s
@@ -34,21 +34,21 @@ if(ENABLE_GN3S)
           PATCH_COMMAND ""
           INSTALL_COMMAND ""
      )
-     
+
      # Set up variables
      set(GRGN3S_INCLUDE_DIRS ${GRGN3S_DIR}/include ${GRGN3S_DIR} ${GRGN3S_DIR}/src)
-     set(GRGN3S_LIBRARIES 
+     set(GRGN3S_LIBRARIES
          "${CMAKE_CURRENT_BINARY_DIR}/../../../../gr-gn3s/lib/${CMAKE_FIND_LIBRARY_PREFIXES}gr-gn3s${CMAKE_SHARED_LIBRARY_SUFFIX}"
-     ) 
+     )
      set(OPT_LIBRARIES ${OPT_LIBRARIES} ${GRGN3S_LIBRARIES})
      set(OPT_DRIVER_INCLUDE_DIRS ${OPT_DRIVER_INCLUDE_DIRS} ${GRGN3S_INCLUDE_DIRS})
      set(OPT_DRIVER_SOURCES ${OPT_DRIVER_SOURCES} gn3s_signal_source.cc)
-     
+
      #  Copy GN3S firmware binary file to install folder
-     message(STATUS "Copying the GN3S firmware binary file to install folder")    
-     file(COPY ${CMAKE_SOURCE_DIR}/firmware/GN3S_v2/bin/gn3s_firmware.ihx 
+     message(STATUS "Copying the GN3S firmware binary file to install folder")
+     file(COPY ${CMAKE_SOURCE_DIR}/firmware/GN3S_v2/bin/gn3s_firmware.ihx
           DESTINATION ${CMAKE_SOURCE_DIR}/install/
-     )     
+     )
 endif(ENABLE_GN3S)
 
 if(ENABLE_FLEXIBAND)
@@ -61,15 +61,15 @@ if(ENABLE_FLEXIBAND)
     find_package(teleorbit REQUIRED)
     if(NOT TELEORBIT_FOUND)
         message(FATAL_ERROR "Teleorbit Flexiband GNURadio driver required to build gnss-sdr with the optional FLEXIBAND adapter")
-    endif(NOT TELEORBIT_FOUND) 
-     
+    endif(NOT TELEORBIT_FOUND)
+
      # Set up variables
-    set(FLEXIBAND_DRIVER_INCLUDE_DIRS 
-        ${OPT_DRIVER_INCLUDE_DIRS} 
+    set(FLEXIBAND_DRIVER_INCLUDE_DIRS
+        ${OPT_DRIVER_INCLUDE_DIRS}
         ${TELEORBIT_INCLUDE_DIR}/teleorbit
     )
     set(OPT_LIBRARIES ${OPT_LIBRARIES} ${TELEORBIT_LIBRARIES})
-    set(OPT_DRIVER_INCLUDE_DIRS ${OPT_DRIVER_INCLUDE_DIRS} ${FLEXIBAND_DRIVER_INCLUDE_DIRS}) 
+    set(OPT_DRIVER_INCLUDE_DIRS ${OPT_DRIVER_INCLUDE_DIRS} ${FLEXIBAND_DRIVER_INCLUDE_DIRS})
     set(OPT_DRIVER_SOURCES ${OPT_DRIVER_SOURCES} flexiband_signal_source.cc)
 endif(ENABLE_FLEXIBAND)
 
@@ -83,7 +83,7 @@ if(ENABLE_ARRAY)
      endif(OS_IS_MACOSX)
      # find_package(GrDbfcttc)
      # if not found, build it with ExternalPackage_Add
-     include(ExternalProject)     
+     include(ExternalProject)
      ExternalProject_Add(
           gr-dbfcttc
           SOURCE_DIR ${CMAKE_SOURCE_DIR}/drivers/gr-dbfcttc
@@ -93,12 +93,12 @@ if(ENABLE_ARRAY)
           CMAKE_ARGS ${MACOSX_ARGS}
           INSTALL_COMMAND ""
      )
-     
+
      # Set up variables
      set(GRDBFCTTC_INCLUDE_DIRS ${GRDBFCTTC_DIR}/include ${GRDBFCTTC_DIR} ${GRDBFCTTC_DIR}/src)
-     set(GRDBFCTTC_LIBRARIES 
+     set(GRDBFCTTC_LIBRARIES
          "${CMAKE_CURRENT_BINARY_DIR}/../../../../gr-dbfcttc/lib/${CMAKE_FIND_LIBRARY_PREFIXES}gnuradio-dbfcttc${CMAKE_SHARED_LIBRARY_SUFFIX}"
-     ) 
+     )
      set(OPT_LIBRARIES ${OPT_LIBRARIES} ${GRDBFCTTC_LIBRARIES})
      set(OPT_DRIVER_INCLUDE_DIRS ${OPT_DRIVER_INCLUDE_DIRS} ${GRDBFCTTC_INCLUDE_DIRS})
      set(OPT_DRIVER_SOURCES ${OPT_DRIVER_SOURCES} raw_array_signal_source.cc)
@@ -108,33 +108,34 @@ endif(ENABLE_ARRAY)
 if(ENABLE_OSMOSDR)
     ################################################################################
     # OsmoSDR - http://sdr.osmocom.org/trac/
-    ################################################################################  
+    ################################################################################
     find_package(GrOsmoSDR REQUIRED)
     if(NOT GROSMOSDR_FOUND)
         message(FATAL_ERROR "gr-osmosdr required to build gnss-sdr with the optional OSMOSDR driver")
-    endif(NOT GROSMOSDR_FOUND)  
-    
+    endif(NOT GROSMOSDR_FOUND)
+
     # set OSMO include dirs
-    set(OSMO_DRIVER_INCLUDE_DIRS 
-        ${OPT_DRIVER_INCLUDE_DIRS} 
+    set(OSMO_DRIVER_INCLUDE_DIRS
+        ${OPT_DRIVER_INCLUDE_DIRS}
         ${GROSMOSDR_INCLUDE_DIR}/osmosdr
     )
     set(OPT_DRIVER_SOURCES ${OPT_DRIVER_SOURCES} osmosdr_signal_source.cc)
     set(OPT_LIBRARIES ${OPT_LIBRARIES} ${GROSMOSDR_LIBRARIES})
-    set(OPT_DRIVER_INCLUDE_DIRS ${OPT_DRIVER_INCLUDE_DIRS} ${OSMO_DRIVER_INCLUDE_DIRS}) 
+    set(OPT_DRIVER_INCLUDE_DIRS ${OPT_DRIVER_INCLUDE_DIRS} ${OSMO_DRIVER_INCLUDE_DIRS})
 endif(ENABLE_OSMOSDR)
 
 if(ENABLE_UHD)
     set(OPT_DRIVER_SOURCES ${OPT_DRIVER_SOURCES} uhd_signal_source.cc)
     set(OPT_LIBRARIES ${OPT_LIBRARIES} ${UHD_LIBRARIES} ${GNURADIO_UHD_LIBRARIES})
-    set(OPT_DRIVER_INCLUDE_DIRS ${OPT_DRIVER_INCLUDE_DIRS} ${UHD_INCLUDE_DIRS}) 
+    set(OPT_DRIVER_INCLUDE_DIRS ${OPT_DRIVER_INCLUDE_DIRS} ${UHD_INCLUDE_DIRS})
 endif(ENABLE_UHD)
 
 
-set(SIGNAL_SOURCE_ADAPTER_SOURCES file_signal_source.cc 
-                                  gen_signal_source.cc                           
-                                  nsr_file_signal_source.cc 
+set(SIGNAL_SOURCE_ADAPTER_SOURCES file_signal_source.cc
+                                  gen_signal_source.cc
+                                  nsr_file_signal_source.cc
                                   spir_file_signal_source.cc
+				  rtl_tcp_signal_source.cc
                                   ${OPT_DRIVER_SOURCES}
 )
 
@@ -147,7 +148,7 @@ include_directories(
      ${CMAKE_SOURCE_DIR}/src/algorithms/libs
      ${CMAKE_SOURCE_DIR}/src/algorithms/signal_source/gnuradio_blocks
      ${GLOG_INCLUDE_DIRS}
-     ${GFlags_INCLUDE_DIRS}     
+     ${GFlags_INCLUDE_DIRS}
      ${Boost_INCLUDE_DIRS}
      ${GNURADIO_RUNTIME_INCLUDE_DIRS}
      ${VOLK_INCLUDE_DIRS}
@@ -162,10 +163,10 @@ add_definitions(-DGNSSSDR_INSTALL_DIR="${CMAKE_INSTALL_PREFIX}")
 file(GLOB SIGNAL_SOURCE_ADAPTER_HEADERS "*.h")
 add_library(signal_source_adapters ${SIGNAL_SOURCE_ADAPTER_SOURCES} ${SIGNAL_SOURCE_ADAPTER_HEADERS})
 source_group(Headers FILES ${SIGNAL_SOURCE_ADAPTER_HEADERS})
-target_link_libraries(signal_source_adapters signal_source_gr_blocks 
-                                             ${Boost_LIBRARIES} 
-                                             ${GNURADIO_PMT_LIBRARIES} 
-                                             ${GNURADIO_BLOCKS_LIBRARIES}                                         
-                                             ${OPT_LIBRARIES} 
+target_link_libraries(signal_source_adapters signal_source_gr_blocks
+                                             ${Boost_LIBRARIES}
+                                             ${GNURADIO_PMT_LIBRARIES}
+                                             ${GNURADIO_BLOCKS_LIBRARIES}
+                                             ${OPT_LIBRARIES}
                                              gnss_sp_libs
 )
diff --git a/src/algorithms/signal_source/adapters/rtl_tcp_signal_source.cc b/src/algorithms/signal_source/adapters/rtl_tcp_signal_source.cc
new file mode 100644
index 0000000..4eb19ea
--- /dev/null
+++ b/src/algorithms/signal_source/adapters/rtl_tcp_signal_source.cc
@@ -0,0 +1,188 @@
+/*!
+ * \file rtl_tcp_signal_source.cc
+ * \brief Signal source for the Realtek RTL2832U USB dongle DVB-T receiver
+ *        over TCP.
+ * (see http://sdr.osmocom.org/trac/wiki/rtl-sdr for more information)
+ * \author Anthony Arnold, 2015. anthony.arnold(at)uqconnect.edu.au
+ *
+ * -------------------------------------------------------------------------
+ *
+ * Copyright (C) 2010-2015  (see AUTHORS file for a list of contributors)
+ *
+ * GNSS-SDR is a software defined Global Navigation
+ *          Satellite Systems receiver
+ *
+ * This file is part of GNSS-SDR.
+ *
+ * GNSS-SDR is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * GNSS-SDR is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with GNSS-SDR. If not, see <http://www.gnu.org/licenses/>.
+ *
+ * -------------------------------------------------------------------------
+ */
+
+#include "rtl_tcp_signal_source.h"
+#include <glog/logging.h>
+#include <iostream>
+#include <boost/format.hpp>
+#include "configuration_interface.h"
+#include "gnss_sdr_valve.h"
+#include "GPS_L1_CA.h"
+
+using google::LogMessage;
+
+
+RtlTcpSignalSource::RtlTcpSignalSource(ConfigurationInterface* configuration,
+        std::string role, unsigned int in_stream, unsigned int out_stream,
+        boost::shared_ptr<gr::msg_queue> queue) :
+                role_(role), in_stream_(in_stream), out_stream_(out_stream),
+                queue_(queue)
+{
+    // DUMP PARAMETERS
+    std::string empty = "";
+    std::string default_dump_file = "./data/signal_source.dat";
+    std::string default_item_type = "gr_complex";
+    samples_ = configuration->property(role + ".samples", 0);
+    dump_ = configuration->property(role + ".dump", false);
+    dump_filename_ = configuration->property(role + ".dump_filename",
+            default_dump_file);
+
+    // rtl_tcp PARAMTERS
+    std::string default_address = "127.0.0.1";
+    short default_port = 1234;
+    AGC_enabled_ = configuration->property(role + ".AGC_enabled", true);
+    freq_ = configuration->property(role + ".freq", GPS_L1_FREQ_HZ);
+    gain_ = configuration->property(role + ".gain", (double)40.0);
+    rf_gain_ = configuration->property(role + ".rf_gain", (double)40.0);
+    if_gain_ = configuration->property(role + ".if_gain", (double)40.0);
+    sample_rate_ = configuration->property(role + ".sampling_frequency", (double)2.0e6);
+    item_type_ = configuration->property(role + ".item_type", default_item_type);
+    address_ = configuration->property(role + ".address", default_address);
+    port_ = configuration->property(role + ".port", default_port);
+
+    if (item_type_.compare("short") == 0)
+        {
+            item_size_ = sizeof(short);
+        }
+    else if (item_type_.compare("gr_complex") == 0)
+        {
+            item_size_ = sizeof(gr_complex);
+            // 1. Make the gr block
+            try
+            {
+	       std::cout << "Connecting to " << address_ << ":" << port_ << std::endl;
+	       LOG (INFO) << "Connecting to " << address_ << ":" << port_;
+	       signal_source_ = rtl_tcp_make_signal_source_cc (address_, port_);
+            }
+            catch( boost::exception & e )
+            {
+	       DLOG(FATAL) << "Boost exception: " << boost::diagnostic_information(e);
+            }
+
+            // 2 set sampling rate
+            signal_source_->set_sample_rate(sample_rate_);
+
+            // 3. set rx frequency
+            signal_source_->set_frequency(freq_);
+
+	    // 4. set rx gain
+            /*if (this->AGC_enabled_ == true)
+	    {
+                    osmosdr_source_->set_gain_mode(true);
+                    std::cout << "AGC enabled" << std::endl;
+                    LOG(INFO) << "AGC enabled";
+	    }
+            else
+	    {
+                    osmosdr_source_->set_gain_mode(false);
+                    osmosdr_source_->set_gain(gain_, 0);
+                    osmosdr_source_->set_if_gain(if_gain_, 0);
+                    osmosdr_source_->set_bb_gain(rf_gain_, 0);
+	    }*/
+        }
+    else
+        {
+            LOG(WARNING) << item_type_ << " unrecognized item type. Using short.";
+            item_size_ = sizeof(short);
+        }
+
+    if (samples_ != 0)
+        {
+            DLOG(INFO) << "Send STOP signal after " << samples_ << " samples";
+            valve_ = gnss_sdr_make_valve(item_size_, samples_, queue_);
+            DLOG(INFO) << "valve(" << valve_->unique_id() << ")";
+        }
+
+    if (dump_)
+        {
+            DLOG(INFO) << "Dumping output into file " << dump_filename_;
+            file_sink_ = gr::blocks::file_sink::make(item_size_, dump_filename_.c_str());
+            DLOG(INFO) << "file_sink(" << file_sink_->unique_id() << ")";
+        }
+
+    deinterleave_ = gr::blocks::deinterleave::make (sizeof (float));
+    ftoc_ = gr::blocks::float_to_complex::make ( 1 );
+}
+
+
+RtlTcpSignalSource::~RtlTcpSignalSource()
+{}
+
+
+void RtlTcpSignalSource::connect(gr::top_block_sptr top_block) {
+   // deinterleave and convert to complex
+   top_block->connect (signal_source_, 0, deinterleave_, 0);
+   top_block->connect (deinterleave_, 0, ftoc_, 0);
+   top_block->connect (deinterleave_, 1, ftoc_, 1);
+
+   if ( samples_ ) {
+      top_block->connect (ftoc_, 0, valve_, 0);
+      DLOG(INFO) << "connected rtl tcp source to valve";
+      if ( dump_ ) {
+	 top_block->connect(valve_, 0, file_sink_, 0);
+	 DLOG(INFO) << "connected valve to file sink";
+      }
+   }
+   else if ( dump_ ) {
+	 top_block->connect(ftoc_, 0, file_sink_, 0);
+	 DLOG(INFO) << "connected rtl tcp source to file sink";
+   }
+}
+
+void RtlTcpSignalSource::disconnect(gr::top_block_sptr top_block) {
+   top_block->disconnect (signal_source_, 0, deinterleave_, 0);
+   top_block->disconnect (deinterleave_, 0, ftoc_, 0);
+   top_block->disconnect (deinterleave_, 1, ftoc_, 1);
+   if ( samples_ ) {
+      top_block->disconnect (ftoc_, 0, valve_, 0);
+      if ( dump_ ) {
+	 top_block->disconnect(valve_, 0, file_sink_, 0);
+      }
+   }
+   else if ( dump_ ) {
+	 top_block->disconnect(ftoc_, 0, file_sink_, 0);
+   }
+}
+
+gr::basic_block_sptr RtlTcpSignalSource::get_left_block() {
+    LOG(WARNING) << "Trying to get signal source left block.";
+    return gr::basic_block_sptr();
+}
+
+gr::basic_block_sptr RtlTcpSignalSource::get_right_block() {
+   if (samples_ != 0) {
+      return valve_;
+   }
+   else {
+      return ftoc_;
+   }
+}
diff --git a/src/algorithms/signal_source/adapters/rtl_tcp_signal_source.h b/src/algorithms/signal_source/adapters/rtl_tcp_signal_source.h
new file mode 100644
index 0000000..deaa631
--- /dev/null
+++ b/src/algorithms/signal_source/adapters/rtl_tcp_signal_source.h
@@ -0,0 +1,114 @@
+/*!
+ * \file rtl_tcp_signal_source.h
+ * \brief Signal source which reads from rtl_tcp.
+ * (see http://sdr.osmocom.org/trac/wiki/rtl-sdr for more information)
+ * \author Anthony Arnold, 2015. anthony.arnold(at)uqconnect.edu.au
+ *
+ * -------------------------------------------------------------------------
+ *
+ * Copyright (C) 2010-2015  (see AUTHORS file for a list of contributors)
+ *
+ * GNSS-SDR is a software defined Global Navigation
+ *          Satellite Systems receiver
+ *
+ * This file is part of GNSS-SDR.
+ *
+ * GNSS-SDR is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * GNSS-SDR is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with GNSS-SDR. If not, see <http://www.gnu.org/licenses/>.
+ *
+ * -------------------------------------------------------------------------
+ */
+
+#ifndef GNSS_SDR_RTL_TCP_SIGNAL_SOURCE_H
+#define GNSS_SDR_RTL_TCP_SIGNAL_SOURCE_H
+
+#include <string>
+#include <boost/shared_ptr.hpp>
+#include <gnuradio/msg_queue.h>
+#include <gnuradio/blocks/file_sink.h>
+#include <gnuradio/blocks/deinterleave.h>
+#include <gnuradio/blocks/float_to_complex.h>
+#include "rtl_tcp_signal_source_cc.h"
+#include "gnss_block_interface.h"
+
+class ConfigurationInterface;
+
+/*!
+ * \brief This class reads from rtl_tcp, which streams interleaved
+ * I/Q samples over TCP.
+ * (see http://sdr.osmocom.org/trac/wiki/rtl-sdr)
+ */
+class RtlTcpSignalSource: public GNSSBlockInterface
+{
+public:
+	RtlTcpSignalSource(ConfigurationInterface* configuration,
+            std::string role, unsigned int in_stream,
+            unsigned int out_stream, boost::shared_ptr<gr::msg_queue> queue);
+
+    virtual ~RtlTcpSignalSource();
+
+    std::string role()
+    {
+        return role_;
+    }
+
+    /*!
+     * \brief Returns "RtlTcp_Signal_Source"
+     */
+    std::string implementation()
+    {
+        return "RtlTcp_Signal_Source";
+    }
+    size_t item_size()
+    {
+        return item_size_;
+    }
+
+    void connect(gr::top_block_sptr top_block);
+    void disconnect(gr::top_block_sptr top_block);
+    gr::basic_block_sptr get_left_block();
+    gr::basic_block_sptr get_right_block();
+
+private:
+    std::string role_;
+
+    // rtl_tcp settings
+    std::string address_;
+    short port_;
+    bool AGC_enabled_;
+    double sample_rate_;
+
+    unsigned int in_stream_;
+    unsigned int out_stream_;
+
+    double freq_;
+    double gain_;
+    double if_gain_;
+    double rf_gain_;
+
+    std::string item_type_;
+    size_t item_size_;
+    long samples_;
+    bool dump_;
+    std::string dump_filename_;
+
+    rtl_tcp_signal_source_cc_sptr signal_source_;
+    gr::blocks::deinterleave::sptr deinterleave_;
+    gr::blocks::float_to_complex::sptr ftoc_;
+
+    boost::shared_ptr<gr::block> valve_;
+    gr::blocks::file_sink::sptr file_sink_;
+    boost::shared_ptr<gr::msg_queue> queue_;
+};
+
+#endif /*GNSS_SDR_RTL_TCP_SIGNAL_SOURCE_H */
diff --git a/src/algorithms/signal_source/gnuradio_blocks/CMakeLists.txt b/src/algorithms/signal_source/gnuradio_blocks/CMakeLists.txt
index a63d6a6..917d80e 100644
--- a/src/algorithms/signal_source/gnuradio_blocks/CMakeLists.txt
+++ b/src/algorithms/signal_source/gnuradio_blocks/CMakeLists.txt
@@ -17,9 +17,10 @@
 #
 
 
-set(SIGNAL_SOURCE_GR_BLOCKS_SOURCES 
+set(SIGNAL_SOURCE_GR_BLOCKS_SOURCES
      unpack_byte_2bit_samples.cc
      unpack_intspir_1bit_samples.cc
+     rtl_tcp_signal_source_cc.cc
 )
 
 include_directories(
@@ -27,9 +28,10 @@ include_directories(
      ${GLOG_INCLUDE_DIRS}
      ${GFlags_INCLUDE_DIRS}
      ${GNURADIO_RUNTIME_INCLUDE_DIRS}
+     ${Boost_INCLUDE_DIRS}
 )
 
 file(GLOB SIGNAL_SOURCE_GR_BLOCKS_HEADERS "*.h")
 add_library(signal_source_gr_blocks ${SIGNAL_SOURCE_GR_BLOCKS_SOURCES} ${SIGNAL_SOURCE_GR_BLOCKS_HEADERS})
 source_group(Headers FILES ${SIGNAL_SOURCE_GR_BLOCKS_HEADERS})
-target_link_libraries(signal_source_gr_blocks ${GNURADIO_RUNTIME_LIBRARIES})
\ No newline at end of file
+target_link_libraries(signal_source_gr_blocks ${GNURADIO_RUNTIME_LIBRARIES} ${Boost_LIBRARIES})
\ No newline at end of file
diff --git a/src/algorithms/signal_source/gnuradio_blocks/rtl_tcp_signal_source_cc.cc b/src/algorithms/signal_source/gnuradio_blocks/rtl_tcp_signal_source_cc.cc
new file mode 100644
index 0000000..bd657dc
--- /dev/null
+++ b/src/algorithms/signal_source/gnuradio_blocks/rtl_tcp_signal_source_cc.cc
@@ -0,0 +1,207 @@
+/*!
+ * \file rtl_tcp_signal_source_cc.cc
+ * \brief An rtl_tcp signal source reader.
+ * \author Anthony Arnold, 2015. anthony.arnold(at)uqconnect.edu.au
+ *
+ * -------------------------------------------------------------------------
+ *
+ * Copyright (C) 2010-2015  (see AUTHORS file for a list of contributors)
+ *
+ * GNSS-SDR is a software defined Global Navigation
+ *          Satellite Systems receiver
+ *
+ * This file is part of GNSS-SDR.
+ *
+ * GNSS-SDR is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * GNSS-SDR is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with GNSS-SDR. If not, see <http://www.gnu.org/licenses/>.
+ *
+ * -------------------------------------------------------------------------
+ */
+
+#include "rtl_tcp_signal_source_cc.h"
+#include <glog/logging.h>
+#include <boost/thread.hpp>
+
+using google::LogMessage;
+
+namespace ip = boost::asio::ip;
+using boost::asio::ip::tcp;
+
+// command ids
+enum {
+   CMD_ID_SET_FREQUENCY = 1,
+   CMD_ID_SET_SAMPLE_RATE = 2
+};
+
+// rtl_tcp command
+struct command {
+   enum {
+      data_size = 1 + sizeof (unsigned int)
+   };
+   boost::array<unsigned char, data_size> data_;
+
+   command (unsigned char cmd, unsigned int param)
+   {
+      data_[0] = cmd;
+      unsigned int nparam =
+	 boost::asio::detail::socket_ops::host_to_network_long (param);
+      memcpy (&data_[1], &nparam, sizeof (nparam));
+   }
+
+   boost::system::error_code send (tcp::socket &socket_) {
+      boost::system::error_code ec;
+      socket_.send (boost::asio::buffer (data_), 0, ec);
+      return ec;
+   }
+};
+
+// set frequency command
+struct set_frequency_command : command {
+   set_frequency_command (unsigned int freq)
+      : command (CMD_ID_SET_FREQUENCY, freq)
+   {
+   }
+};
+
+// set sample rate  command
+struct set_sample_rate_command : command {
+   set_sample_rate_command (unsigned int sample_rate)
+      : command (CMD_ID_SET_SAMPLE_RATE, sample_rate)
+   {
+   }
+};
+
+rtl_tcp_signal_source_cc_sptr
+rtl_tcp_make_signal_source_cc(const std::string &address,
+			      short port)
+{
+   return gnuradio::get_initial_sptr (new rtl_tcp_signal_source_cc (address, port));
+}
+
+
+rtl_tcp_signal_source_cc::rtl_tcp_signal_source_cc(const std::string &address,
+						   short port)
+   : gr::sync_block ("rtl_tcp_signal_source_cc",
+                   gr::io_signature::make(0, 0, 0),
+                   gr::io_signature::make(1, 1, sizeof(float))),
+     socket_ (io_service_),
+     buffer_ (1048576),
+     unread_ (0)
+{
+   boost::system::error_code ec;
+
+   for (int i = 0; i < 256; i++) {
+      lookup_[i] = (((float)(i & 0xff)) - 127.4f) * (1.0f / 128.0f);
+   }
+
+   ip::address addr = ip::address::from_string (address, ec);
+   if (ec) {
+      std::cout << address << " is not an IP address" << std::endl;
+      LOG (WARNING) << address << " is not an IP address";
+      return;
+   }
+
+   socket_.connect(tcp::endpoint (addr, port), ec);
+   if (ec) {
+      std::cout << "Failed to connect to " << addr << ":" << port
+		<< "(" << ec << ")" << std::endl;
+      LOG (WARNING)  << "Failed to connect to " << addr << ":" << port
+		   << "(" << ec << ")";
+      return;
+   }
+   std::cout << "Connected to " << addr << ":" << port << std::endl;
+   LOG (WARNING)  << "Connected to " << addr << ":" << port;
+
+   boost::asio::async_read (socket_, boost::asio::buffer (data_),
+			    boost::bind (&rtl_tcp_signal_source_cc::handle_read,
+					 this, _1, _2));
+   boost::thread (boost::bind (&boost::asio::io_service::run, &io_service_));
+   //io_service_.poll ();
+}
+
+rtl_tcp_signal_source_cc::~rtl_tcp_signal_source_cc()
+{
+   io_service_.stop ();
+}
+
+int rtl_tcp_signal_source_cc::work (int noutput_items,
+				    gr_vector_const_void_star &input_items,
+				    gr_vector_void_star &output_items)
+{
+   float *out = reinterpret_cast <float *>( output_items[0] );
+   int i = 0;
+
+   {
+      boost::mutex::scoped_lock lock (mutex_);
+      not_empty_.wait (lock, boost::bind (&rtl_tcp_signal_source_cc::not_empty,
+					  this));
+
+      for ( ; i < noutput_items && unread_ > 0; i++ ) {
+	 out[i] = buffer_[--unread_];
+      }
+   }
+   not_full_.notify_one ();
+   return i == 0 ? -1 : i;
+}
+
+
+void rtl_tcp_signal_source_cc::set_frequency (int frequency) {
+   boost::system::error_code ec =
+      set_frequency_command (frequency).send(socket_);
+   if (ec) {
+      std::cout << "Failed to set frequency" << std::endl;
+      LOG (WARNING) << "Failed to set frequency";
+   }
+}
+
+void rtl_tcp_signal_source_cc::set_sample_rate (int sample_rate) {
+   boost::system::error_code ec =
+      set_sample_rate_command (sample_rate).send(socket_);
+   if (ec) {
+      std::cout << "Failed to set sample rate" << std::endl;
+      LOG (WARNING) << "Failed to set sample rate";
+   }
+}
+
+void rtl_tcp_signal_source_cc::handle_read  (const boost::system::error_code &ec,
+					     size_t bytes_transferred)
+{
+   if (ec) {
+      std::cout << "Error during read: " << ec << std::endl;
+      LOG (WARNING) << "Error during read: " << ec;
+      not_empty_.notify_one ();
+   }
+   else {
+      {
+	 boost::mutex::scoped_lock lock (mutex_);
+	 not_full_.wait (lock, boost::bind (&rtl_tcp_signal_source_cc::not_full,
+					    this));
+
+	 for (size_t i = 0; i < bytes_transferred; i++) {
+	    while (!not_full( )) {
+	       not_empty_.notify_one ();
+	       not_full_.wait (lock, boost::bind (&rtl_tcp_signal_source_cc::not_full,
+						  this));
+	    }
+
+	    buffer_.push_front (lookup_ [data_[i]]);
+	    unread_++;
+	 }
+      }
+      not_empty_.notify_one ();
+
+      boost::asio::async_read (socket_, boost::asio::buffer (data_),
+			       boost::bind (&rtl_tcp_signal_source_cc::handle_read,
+					    this, _1, _2));
+   }
+}
diff --git a/src/algorithms/signal_source/gnuradio_blocks/rtl_tcp_signal_source_cc.h b/src/algorithms/signal_source/gnuradio_blocks/rtl_tcp_signal_source_cc.h
new file mode 100644
index 0000000..2c5aad0
--- /dev/null
+++ b/src/algorithms/signal_source/gnuradio_blocks/rtl_tcp_signal_source_cc.h
@@ -0,0 +1,100 @@
+/*!
+ * \file rtl_tcp_signal_source_cc.h
+ * \brief Interface of an rtl_tcp signal source reader.
+ * \author Anthony Arnold, 2015. anthony.arnold(at)uqconnect.edu.au
+ *
+ * -------------------------------------------------------------------------
+ *
+ * Copyright (C) 2010-2015  (see AUTHORS file for a list of contributors)
+ *
+ * GNSS-SDR is a software defined Global Navigation
+ *          Satellite Systems receiver
+ *
+ * This file is part of GNSS-SDR.
+ *
+ * GNSS-SDR is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * GNSS-SDR is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with GNSS-SDR. If not, see <http://www.gnu.org/licenses/>.
+ *
+ * -------------------------------------------------------------------------
+ */
+
+#ifndef GNSS_SDR_RTL_TCP_SIGNAL_SOURCE_CC_H
+#define	GNSS_SDR_RTL_TCP_SIGNAL_SOURCE_CC_H
+
+#include <boost/asio.hpp>
+#include <gnuradio/sync_block.h>
+#include <string>
+#include <boost/thread/mutex.hpp>
+#include <boost/thread/condition.hpp>
+#include <boost/array.hpp>
+#include <boost/circular_buffer.hpp>
+
+class rtl_tcp_signal_source_cc;
+
+typedef boost::shared_ptr<rtl_tcp_signal_source_cc>
+        rtl_tcp_signal_source_cc_sptr;
+
+rtl_tcp_signal_source_cc_sptr
+rtl_tcp_make_signal_source_cc(const std::string &address,
+			      short port);
+
+/*!
+ * \brief This class reads interleaved I/Q samples
+ * from an rtl_tcp server.
+ */
+class rtl_tcp_signal_source_cc : public gr::sync_block
+{
+public:
+    ~rtl_tcp_signal_source_cc();
+
+    int work (int noutput_items,
+	      gr_vector_const_void_star &input_items,
+	      gr_vector_void_star &output_items);
+
+    void set_frequency (int frequency);
+    void set_sample_rate (int sample_rate);
+
+private:
+    friend rtl_tcp_signal_source_cc_sptr
+       rtl_tcp_make_signal_source_cc(const std::string &address,
+				     short port);
+
+    rtl_tcp_signal_source_cc(const std::string &address,
+			     short port);
+
+    boost::asio::io_service io_service_;
+    boost::asio::ip::tcp::socket socket_;
+
+    boost::mutex mutex_;
+    boost::condition not_full_;
+    boost::condition not_empty_;
+    boost::circular_buffer<float> buffer_;
+    size_t unread_;
+
+    boost::array<float, 256> lookup_;
+    boost::array<unsigned char, 256> data_;
+
+    void handle_read (const boost::system::error_code &ec,
+		      size_t bytes_transferred);
+
+    inline bool not_full ( ) const {
+       return unread_ < buffer_.capacity( );
+    }
+
+    inline bool not_empty ( ) const {
+       return unread_ > 0;
+    }
+
+};
+
+#endif //GNSS_SDR_RTL_TCP_SIGNAL_SOURCE_CC_H
diff --git a/src/core/receiver/gnss_block_factory.cc b/src/core/receiver/gnss_block_factory.cc
index 4579585..40c9df7 100644
--- a/src/core/receiver/gnss_block_factory.cc
+++ b/src/core/receiver/gnss_block_factory.cc
@@ -46,6 +46,7 @@
 #include "file_signal_source.h"
 #include "nsr_file_signal_source.h"
 #include "spir_file_signal_source.h"
+#include "rtl_tcp_signal_source.h"
 #include "null_sink_output_filter.h"
 #include "file_output_filter.h"
 #include "channel.h"
@@ -434,6 +435,21 @@ std::unique_ptr<GNSSBlockInterface> GNSSBlockFactory::GetBlock(
                     exit(1);
             }
         }
+    else if (implementation.compare("RtlTcp_Signal_Source") == 0)
+        {
+            try
+            {
+                    std::unique_ptr<GNSSBlockInterface> block_(new RtlTcpSignalSource(configuration.get(), role, in_streams,
+                            out_streams, queue));
+                    block = std::move(block_);
+
+            }
+            catch (const std::exception &e)
+            {
+                    std::cout << "GNSS-SDR program ended." << std::endl;
+                    exit(1);
+            }
+        }
 #if UHD_DRIVER
     else if (implementation.compare("UHD_Signal_Source") == 0)
         {

-- 
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