Skip to content

Commit

Permalink
rtl,rtl_tcp: add bias=0|1 parameter to switch off|on bias voltage on
Browse files Browse the repository at this point in the history
gpio0
  • Loading branch information
Dimitri Stolnikov committed Jun 11, 2017
1 parent a3b4e5c commit 3c7d3f1
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 4 deletions.
4 changes: 2 additions & 2 deletions grc/gen_osmosdr_blocks.py
Expand Up @@ -251,8 +251,8 @@
rtl=serial_number ...
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][,direct_samp=0|1|2][,offset_tune=0|1] ...
rtl=2[,direct_samp=0|1|2][,offset_tune=0|1][,bias=0|1] ...
rtl_tcp=127.0.0.1:1234[,psize=16384][,direct_samp=0|1|2][,offset_tune=0|1][,bias=0|1] ...
osmosdr=0[,buffers=32][,buflen=N*512] ...
file='/path/to/your file',rate=1e6[,freq=100e6][,repeat=true][,throttle=true] ...
netsdr=127.0.0.1[:50000][,nchan=2]
Expand Down
8 changes: 8 additions & 0 deletions lib/rtl/rtl_source_c.cc
Expand Up @@ -92,6 +92,7 @@ rtl_source_c::rtl_source_c (const std::string &args)
{
int ret;
int index;
int bias_tee = 0;
unsigned int dev_index = 0, rtl_freq = 0, tuner_freq = 0, direct_samp = 0;
unsigned int offset_tune = 0;
char manufact[256];
Expand Down Expand Up @@ -150,6 +151,9 @@ rtl_source_c::rtl_source_c (const std::string &args)
if (dict.count("offset_tune"))
offset_tune = boost::lexical_cast< unsigned int >( dict["offset_tune"] );

if (dict.count("bias"))
bias_tee = boost::lexical_cast<bool>( dict["bias"] );

_buf_num = _buf_len = _buf_head = _buf_used = _buf_offset = 0;

if (dict.count("buffers"))
Expand Down Expand Up @@ -217,6 +221,10 @@ rtl_source_c::rtl_source_c (const std::string &args)
throw std::runtime_error("Failed to enable offset tuning.");
}

ret = rtlsdr_set_bias_tee(_dev, bias_tee);
if (ret < 0)
throw std::runtime_error("Failed to set bias tee.");

ret = rtlsdr_reset_buffer( _dev );
if (ret < 0)
throw std::runtime_error("Failed to reset usb buffers.");
Expand Down
13 changes: 11 additions & 2 deletions lib/rtl_tcp/rtl_tcp_source_c.cc
Expand Up @@ -154,6 +154,7 @@ rtl_tcp_source_c::rtl_tcp_source_c(const std::string &args) :
unsigned short port = 1234;
int payload_size = 16384;
unsigned int direct_samp = 0, offset_tune = 0;
int bias_tee = 0;

_freq = 0;
_rate = 0;
Expand Down Expand Up @@ -182,6 +183,9 @@ rtl_tcp_source_c::rtl_tcp_source_c(const std::string &args) :
if (dict.count("offset_tune"))
offset_tune = boost::lexical_cast< unsigned int >( dict["offset_tune"] );

if (dict.count("bias"))
bias_tee = boost::lexical_cast<bool>( dict["bias"] );

if (!host.length())
host = "127.0.0.1";

Expand Down Expand Up @@ -218,7 +222,6 @@ rtl_tcp_source_c::rtl_tcp_source_c(const std::string &args) :
report_error("rtl_tcp_source_f/getaddrinfo",
"can't initialize source socket" );

// FIXME leaks if report_error throws below
d_temp_buff = new unsigned char[payload_size]; // allow it to hold up to payload_size bytes
d_LUT = new float[0x100];
for (int i = 0; i < 0x100; ++i)
Expand Down Expand Up @@ -293,14 +296,20 @@ rtl_tcp_source_c::rtl_tcp_source_c(const std::string &args) :
set_gain_mode(false); /* enable manual gain mode by default */

// set direct sampling
struct command cmd = { 0x09, htonl(direct_samp) };
struct command cmd;

cmd = { 0x09, htonl(direct_samp) };
send(d_socket, (const char*)&cmd, sizeof(cmd), 0);
if (direct_samp)
_no_tuner = true;

// set offset tuning
cmd = { 0x0a, htonl(offset_tune) };
send(d_socket, (const char*)&cmd, sizeof(cmd), 0);

// set bias tee
cmd = { 0x0e, htonl(bias_tee) };
send(d_socket, (const char*)&cmd, sizeof(cmd), 0);
}

rtl_tcp_source_c::~rtl_tcp_source_c()
Expand Down

0 comments on commit 3c7d3f1

Please sign in to comment.