From ede9c80455d64d0286c68ce9faaaa7da69aeefd1 Mon Sep 17 00:00:00 2001 From: Dimitri Stolnikov Date: Mon, 18 Feb 2013 20:43:35 +0100 Subject: [PATCH] rtl_tcp: add direct_samp and offset_tune args like used in rtl= target --- grc/gen_osmosdr_blocks.py | 2 +- lib/rtl_tcp/rtl_tcp_source_c.cc | 20 ++++++++++++++++++++ lib/rtl_tcp/rtl_tcp_source_c.h | 1 + lib/rtl_tcp/rtl_tcp_source_f.cc | 12 ++++++++++++ lib/rtl_tcp/rtl_tcp_source_f.h | 2 ++ 5 files changed, 36 insertions(+), 1 deletion(-) diff --git a/grc/gen_osmosdr_blocks.py b/grc/gen_osmosdr_blocks.py index a9d9080..c060d20 100644 --- a/grc/gen_osmosdr_blocks.py +++ b/grc/gen_osmosdr_blocks.py @@ -132,7 +132,7 @@ Lines ending with ... mean it's possible to bind devices together by specifying rtl=0[,rtl_xtal=28.8e6][,tuner_xtal=28.8e6] ... rtl=1[,buffers=32][,buflen=N*512] ... rtl=2[,direct_samp=0|1|2][,offset_tune=0|1] ... - rtl_tcp=127.0.0.1:1234[,psize=16384] ... + rtl_tcp=127.0.0.1:1234[,psize=16384][,direct_samp=0|1|2][,offset_tune=0|1] ... uhd[,serial=...][,lo_offset=0][,mcr=52e6][,nchan=2][,subdev='\\\\'B:0 A:0\\\\''] ... osmosdr=0[,mcr=64e6][,nchan=5][,buffers=32][,buflen=N*512] ... file='/path/to/your file',rate=1e6[,freq=100e6][,repeat=true][,throttle=true] ... diff --git a/lib/rtl_tcp/rtl_tcp_source_c.cc b/lib/rtl_tcp/rtl_tcp_source_c.cc index eae5a13..dcedda7 100644 --- a/lib/rtl_tcp/rtl_tcp_source_c.cc +++ b/lib/rtl_tcp/rtl_tcp_source_c.cc @@ -60,12 +60,14 @@ rtl_tcp_source_c::rtl_tcp_source_c(const std::string &args) : gr_hier_block2("rtl_tcp_source_c", gr_make_io_signature (0, 0, 0), gr_make_io_signature (1, 1, sizeof (gr_complex))), + _no_tuner(false), _auto_gain(false), _if_gain(0) { std::string host = "127.0.0.1"; unsigned short port = 1234; int payload_size = 16384; + unsigned int direct_samp = 0, offset_tune = 0; _freq = 0; _rate = 0; @@ -88,6 +90,12 @@ rtl_tcp_source_c::rtl_tcp_source_c(const std::string &args) : if (dict.count("psize")) payload_size = boost::lexical_cast< int >( dict["psize"] ); + if (dict.count("direct_samp")) + direct_samp = boost::lexical_cast< unsigned int >( dict["direct_samp"] ); + + if (dict.count("offset_tune")) + offset_tune = boost::lexical_cast< unsigned int >( dict["offset_tune"] ); + if (!host.length()) host = "127.0.0.1"; @@ -111,6 +119,13 @@ rtl_tcp_source_c::rtl_tcp_source_c(const std::string &args) : set_gain_mode(false); /* enable manual gain mode by default */ + _src->set_direct_sampling(direct_samp); + if (direct_samp) { + _no_tuner = true; + } + + _src->set_offset_tuning(offset_tune); + /* rtl tcp source provides a stream of interleaved IQ floats */ gr_deinterleave_sptr deinterleave = gr_make_deinterleave(sizeof(float)); @@ -186,6 +201,11 @@ osmosdr::freq_range_t rtl_tcp_source_c::get_freq_range( size_t chan ) { osmosdr::freq_range_t range; + if (_no_tuner) { + range += osmosdr::range_t( 0, double(28.8e6) ); // as far as we know + return range; + } + enum rtlsdr_tuner tuner = _src->get_tuner_type(); if ( tuner == RTLSDR_TUNER_E4000 ) { diff --git a/lib/rtl_tcp/rtl_tcp_source_c.h b/lib/rtl_tcp/rtl_tcp_source_c.h index c236bf1..b452e68 100644 --- a/lib/rtl_tcp/rtl_tcp_source_c.h +++ b/lib/rtl_tcp/rtl_tcp_source_c.h @@ -78,6 +78,7 @@ public: private: double _freq, _rate, _gain, _corr; + bool _no_tuner; bool _auto_gain; double _if_gain; rtl_tcp_source_f_sptr _src; diff --git a/lib/rtl_tcp/rtl_tcp_source_f.cc b/lib/rtl_tcp/rtl_tcp_source_f.cc index 0388647..304fb29 100644 --- a/lib/rtl_tcp/rtl_tcp_source_f.cc +++ b/lib/rtl_tcp/rtl_tcp_source_f.cc @@ -314,3 +314,15 @@ void rtl_tcp_source_f::set_agc_mode(int on) struct command cmd = { 0x08, htonl(on) }; send(d_socket, (const char*)&cmd, sizeof(cmd), 0); } + +void rtl_tcp_source_f::set_direct_sampling(int on) +{ + struct command cmd = { 0x09, htonl(on) }; + send(d_socket, (const char*)&cmd, sizeof(cmd), 0); +} + +void rtl_tcp_source_f::set_offset_tuning(int on) +{ + struct command cmd = { 0x0a, htonl(on) }; + send(d_socket, (const char*)&cmd, sizeof(cmd), 0); +} diff --git a/lib/rtl_tcp/rtl_tcp_source_f.h b/lib/rtl_tcp/rtl_tcp_source_f.h index e3dc3f6..ceae709 100644 --- a/lib/rtl_tcp/rtl_tcp_source_f.h +++ b/lib/rtl_tcp/rtl_tcp_source_f.h @@ -113,6 +113,8 @@ public: void set_freq_corr(int ppm); void set_if_gain(int stage, int gain); void set_agc_mode(int on); + void set_direct_sampling(int on); + void set_offset_tuning(int on); };