<p dir="ltr">unsubscribe</p>
<div class="gmail_extra"><br><div class="gmail_quote">Em 24/08/2016 22:55,  <<a href="mailto:osmocom-sdr-request@lists.osmocom.org">osmocom-sdr-request@lists.osmocom.org</a>> escreveu:<br type="attribution"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Send osmocom-sdr mailing list submissions to<br>
        <a href="mailto:osmocom-sdr@lists.osmocom.org">osmocom-sdr@lists.osmocom.org</a><br>
<br>
To subscribe or unsubscribe via the World Wide Web, visit<br>
        <a href="https://lists.osmocom.org/mailman/listinfo/osmocom-sdr" rel="noreferrer" target="_blank">https://lists.osmocom.org/<wbr>mailman/listinfo/osmocom-sdr</a><br>
or, via email, send a message with subject or body 'help' to<br>
        <a href="mailto:osmocom-sdr-request@lists.osmocom.org">osmocom-sdr-request@lists.<wbr>osmocom.org</a><br>
<br>
You can reach the person managing the list at<br>
        <a href="mailto:osmocom-sdr-owner@lists.osmocom.org">osmocom-sdr-owner@lists.<wbr>osmocom.org</a><br>
<br>
When replying, please edit your Subject line so it is more specific<br>
than "Re: Contents of osmocom-sdr digest..."<br>
<br>
<br>
Today's Topics:<br>
<br>
   1. PATCH: Fixed arbitrary resampling in rtl_fm<br>
      (<a href="mailto:f.meyer-hermann@gsg-elektronik.de">f.meyer-hermann@gsg-<wbr>elektronik.de</a>)<br>
   2. Uccess! My first librtlsdr application (Neoklis Kyriazis)<br>
   3. Re: Uccess! My first librtlsdr application (Lucas Teske)<br>
   4. Fwd: Development of rtl-sdr driver (Piotr Krysik)<br>
   5. RTL-SDR and RTL-TCP drivers (Krzysztof Halasa)<br>
   6. [PATCH] RTL-SDR: convert _lut to float[] to reduce size by a<br>
      factor of 256 (Krzysztof Halasa)<br>
   7. [PATCH] RTL-TCP: Convert to single class model (Krzysztof Halasa)<br>
<br>
<br>
------------------------------<wbr>------------------------------<wbr>----------<br>
<br>
Message: 1<br>
Date: Mon, 25 Jul 2016 13:13:13 +0200<br>
From: <a href="mailto:f.meyer-hermann@gsg-elektronik.de">f.meyer-hermann@gsg-<wbr>elektronik.de</a><br>
To: <a href="mailto:osmocom-sdr@lists.osmocom.org">osmocom-sdr@lists.osmocom.org</a><br>
Subject: PATCH: Fixed arbitrary resampling in rtl_fm<br>
Message-ID: <<a href="mailto:20160725111313.GA15278@gsg-elektronik.de">20160725111313.GA15278@gsg-<wbr>elektronik.de</a>><br>
Content-Type: text/plain; charset=us-ascii<br>
<br>
As already on github, I fixed rtl_fm's arbitrary resampling by fixing the<br>
output buffer length and allowing upsampling by copying the audio data since<br>
the algorithm cannot work in-place.<br>
I have attached a patch, if you are interested to integrate it into the<br>
official branch.<br>
Regards,<br>
<br>
Ferdinand Meyer-Hermann<br>
<br>
<br>
------------------------------<br>
<br>
Message: 2<br>
Date: Fri, 5 Aug 2016 05:09:49 +0000 (UTC)<br>
From: Neoklis Kyriazis <<a href="mailto:nkcyham@yahoo.com">nkcyham@yahoo.com</a>><br>
To: "<a href="mailto:osmocom-sdr@lists.osmocom.org">osmocom-sdr@lists.osmocom.org</a><wbr>" <<a href="mailto:osmocom-sdr@lists.osmocom.org">osmocom-sdr@lists.osmocom.org</a><wbr>><br>
Subject: Uccess! My first librtlsdr application<br>
Message-ID:<br>
        <<a href="mailto:1565657774.9528793.1470373789409.JavaMail.yahoo@mail.yahoo.com">1565657774.9528793.<wbr>1470373789409.JavaMail.yahoo@<wbr>mail.yahoo.com</a>><br>
Content-Type: text/plain; charset=UTF-8<br>
<br>
Hi<br>
<br>
<br>
First, my thanks to everyone involved with the development and<br>
release of librtlsdr. Well done. :-)<br>
<br>
I always wanted to try my hand building an SDR application and<br>
so I installed the latest librtlsdr and started writing code<br>
<br>
to test the various functions in the librtlsdr library. Having<br>
gotten familiar with this, I started work on modifying my old<br>
Wx satellite APT image decoder app, xwxapt, to support an rtlsdr<br>
receiver beside the linear VHF receiver it was written for.<br>
<br>
Its always difficult to extensively modify an existing app, but<br>
in the end it all worked out well and xwxapt can now receive the<br>
old APT format images from Wx sats with the rtl-sdr receiver. In<br>
the process, I modified xwxapt to include controls for the rtl-sdr<br>
unit, display an FFT-derived spectrum of the 2.4kHz sub-carrier<br>
and a spectrum of the baseband O/P of the RTL2832 device. Images<br>
are decoded in real time and displayed incrementally in xwxapt's<br>
window. xwxapt is available under the GPL at:<br>
<br>
<br>
<a href="http://www.5b4az.org/" rel="noreferrer" target="_blank">http://www.5b4az.org/</a> in Weather Imaging->Image Decoders menu.<br>
<br>
--<br>
Best Regards<br>
Neoklis - Ham Radio Call:5B4AZ<br>
<a href="http://www.5b4az.org/" rel="noreferrer" target="_blank">http://www.5b4az.org/</a><br>
<br>
<br>
------------------------------<br>
<br>
Message: 3<br>
Date: Fri, 5 Aug 2016 13:29:29 -0300<br>
From: Lucas Teske <<a href="mailto:lucas@teske.net.br">lucas@teske.net.br</a>><br>
To: <a href="mailto:osmocom-sdr@lists.osmocom.org">osmocom-sdr@lists.osmocom.org</a><br>
Subject: Re: Uccess! My first librtlsdr application<br>
Message-ID: <<a href="mailto:fb16ab1f-4ff9-3ba5-04a0-5b1231fa72ef@teske.net.br">fb16ab1f-4ff9-3ba5-04a0-<wbr>5b1231fa72ef@teske.net.br</a>><br>
Content-Type: text/plain; charset="utf-8"<br>
<br>
Nice Neoklis!<br>
<br>
<br>
It looks good, I will give a try on the weekend :D<br>
<br>
<br>
Btw, you should post the source-code at github, in this way it is easier<br>
to submit patches and stuff.<br>
<br>
<br>
Lucas<br>
<br>
Em 05/08/2016 02:09, Neoklis Kyriazis escreveu:<br>
> Hi<br>
><br>
><br>
> First, my thanks to everyone involved with the development and<br>
> release of librtlsdr. Well done. :-)<br>
><br>
> I always wanted to try my hand building an SDR application and<br>
> so I installed the latest librtlsdr and started writing code<br>
><br>
> to test the various functions in the librtlsdr library. Having<br>
> gotten familiar with this, I started work on modifying my old<br>
> Wx satellite APT image decoder app, xwxapt, to support an rtlsdr<br>
> receiver beside the linear VHF receiver it was written for.<br>
><br>
> Its always difficult to extensively modify an existing app, but<br>
> in the end it all worked out well and xwxapt can now receive the<br>
> old APT format images from Wx sats with the rtl-sdr receiver. In<br>
> the process, I modified xwxapt to include controls for the rtl-sdr<br>
> unit, display an FFT-derived spectrum of the 2.4kHz sub-carrier<br>
> and a spectrum of the baseband O/P of the RTL2832 device. Images<br>
> are decoded in real time and displayed incrementally in xwxapt's<br>
> window. xwxapt is available under the GPL at:<br>
><br>
><br>
> <a href="http://www.5b4az.org/" rel="noreferrer" target="_blank">http://www.5b4az.org/</a> in Weather Imaging->Image Decoders menu.<br>
><br>
> --<br>
> Best Regards<br>
> Neoklis - Ham Radio Call:5B4AZ<br>
> <a href="http://www.5b4az.org/" rel="noreferrer" target="_blank">http://www.5b4az.org/</a><br>
<br>
<br>
-------------- next part --------------<br>
A non-text attachment was scrubbed...<br>
Name: smime.p7s<br>
Type: application/pkcs7-signature<br>
Size: 3823 bytes<br>
Desc: Assinatura criptogr??fica S/MIME<br>
URL: <<a href="http://lists.osmocom.org/pipermail/osmocom-sdr/attachments/20160805/d6b47cd6/attachment-0001.bin" rel="noreferrer" target="_blank">http://lists.osmocom.org/<wbr>pipermail/osmocom-sdr/<wbr>attachments/20160805/d6b47cd6/<wbr>attachment-0001.bin</a>><br>
<br>
------------------------------<br>
<br>
Message: 4<br>
Date: Mon, 8 Aug 2016 13:14:30 +0200<br>
From: Piotr Krysik <<a href="mailto:ptrkrysik@gmail.com">ptrkrysik@gmail.com</a>><br>
To: <a href="mailto:osmocom-sdr@lists.osmocom.org">osmocom-sdr@lists.osmocom.org</a><br>
Subject: Fwd: Development of rtl-sdr driver<br>
Message-ID: <<a href="mailto:fd1e2ce6-eeff-1901-eca7-4eecd09a9a74@gmail.com">fd1e2ce6-eeff-1901-eca7-<wbr>4eecd09a9a74@gmail.com</a>><br>
Content-Type: text/plain; charset=utf-8<br>
<br>
<br>
Hi everyone,<br>
<br>
I've send the e-mail to the OpenBSC list before, but as I was informed<br>
by Harald this is the right place for such discussions. So I'm resending<br>
it here.<br>
<br>
The osmocom's version of rtl-sdr driver seems to be the main one.<br>
Osmocom's repository is used by distributions to build rtl-sdr packages<br>
and it is source of the code for compilation with use of GNU Radio's<br>
Pybombs.<br>
<br>
Is there someone in the Osmocom who is maintaining it? There were some<br>
important developments regarding this driver and it would be great to<br>
add these patches in the Osmocom's repo.<br>
<br>
For example one that interests me is turning off dithering so multiple<br>
dongles sharing the same clock generate the same LO frequency. Currently<br>
there is always little frequency offset that makes coherent of the<br>
receivers operation much harder.<br>
<br>
Such changes of course have to be done carefully so nothing gets broken<br>
in the process. In case of turning off dithering it results with worse<br>
tuning granularity, so for example turning it off could be made optional.<br>
<br>
--<br>
Best Regards,<br>
Piotr Krysik<br>
<br>
<br>
------------------------------<br>
<br>
Message: 5<br>
Date: Wed, 24 Aug 2016 23:43:03 +0200<br>
From: Krzysztof Halasa <<a href="mailto:khc@pm.waw.pl">khc@pm.waw.pl</a>><br>
To: <a href="mailto:osmocom-sdr@lists.osmocom.org">osmocom-sdr@lists.osmocom.org</a><br>
Subject: RTL-SDR and RTL-TCP drivers<br>
Message-ID: <<a href="mailto:m3pooxu9lk.fsf@pm.waw.pl">m3pooxu9lk.fsf@pm.waw.pl</a>><br>
Content-Type: text/plain<br>
<br>
Hello,<br>
<br>
it's my first mail on this list, so please forgive me if I do something<br>
wrong.<br>
<br>
I'm about to post a couple of patches for RTL drivers:<br>
<br>
1. RTL-SDR: convert _lut to float[] to reduce size by a factor of 256.<br>
<br>
The _lut is being indexed by I + Q (16 bits = 65536 entries), however<br>
both samples can be processed independently, resulting in 8-bit LUT.<br>
Saves a bit of RAM and CPU cache.<br>
<br>
lib/rtl/rtl_source_c.cc | 19 ++++++-------------<br>
lib/rtl/rtl_source_c.h  |  4 ++--<br>
2 files changed, 8 insertions(+), 15 deletions(-)<br>
<br>
<br>
2. RTL-TCP: Convert to single class model<br>
<br>
The existing RTL TCP driver is quite different from its brother RTL_SDR.<br>
It's much more complicated, uses gr::blocks::deinterleave and<br>
gr::blocks::float_to_complex, and generally doesn't work correctly<br>
(e.g. <a href="https://github.com/csete/gqrx/issues/99" rel="noreferrer" target="_blank">https://github.com/csete/gqrx/<wbr>issues/99</a><br>
 Spectrum is mirrored when filter or demodulator changes (rtl_tcp) #99)<br>
<br>
I've converted the RTL TCP driver to the model used by RTL_SDR,<br>
simplifying it in the process, and fixing the GQRX issue.<br>
<br>
lib/rtl_tcp/CMakeLists.txt      |   1 -<br>
lib/rtl_tcp/rtl_tcp_source_c.<wbr>cc | 352 ++++++++++++++++++++++++++++++<wbr>++--------<br>
lib/rtl_tcp/rtl_tcp_source_c.h  |  32 +++-<br>
lib/rtl_tcp/rtl_tcp_source_f.<wbr>cc | 327 ------------------------------<wbr>-------<br>
lib/rtl_tcp/rtl_tcp_source_f.h  | 125 --------------<br>
5 files changed, 309 insertions(+), 528 deletions(-)<br>
<br>
<br>
I'm also thinking about merging the code common to RTL-SDR and RTL-TCP,<br>
but this it's done yet.<br>
<br>
Comments?<br>
--<br>
Krzysztof Halasa<br>
<br>
<br>
------------------------------<br>
<br>
Message: 6<br>
Date: Wed, 24 Aug 2016 23:53:39 +0200<br>
From: Krzysztof Halasa <<a href="mailto:khc@pm.waw.pl">khc@pm.waw.pl</a>><br>
To: <a href="mailto:osmocom-sdr@lists.osmocom.org">osmocom-sdr@lists.osmocom.org</a><br>
Subject: [PATCH] RTL-SDR: convert _lut to float[] to reduce size by a<br>
        factor of 256<br>
Message-ID: <<a href="mailto:m3lgzlu93w.fsf@pm.waw.pl">m3lgzlu93w.fsf@pm.waw.pl</a>><br>
Content-Type: text/plain<br>
<br>
The _lut is being indexed by I + Q (16 bits = 65536 entries), however<br>
both samples can be processed independently, resulting in 8-bit LUT.<br>
Saves a bit of RAM and CPU cache.<br>
<br>
diff --git a/lib/rtl/rtl_source_c.cc b/lib/rtl/rtl_source_c.cc<br>
index 93328b8..999ff9e 100644<br>
--- a/lib/rtl/rtl_source_c.cc<br>
+++ b/lib/rtl/rtl_source_c.cc<br>
@@ -172,15 +172,8 @@ rtl_source_c::rtl_source_c (const std::string &args)<br>
   _samp_avail = _buf_len / BYTES_PER_SAMPLE;<br>
<br>
   // create a lookup table for gr_complex values<br>
-  for (unsigned int i = 0; i <= 0xffff; i++) {<br>
-#ifdef BOOST_LITTLE_ENDIAN<br>
-    _lut.push_back( gr_complex( (float(i & 0xff) - 127.4f) * (1.0f/128.0f),<br>
-                                (float(i >> 8) - 127.4f) * (1.0f/128.0f) ) );<br>
-#else // BOOST_BIG_ENDIAN<br>
-    _lut.push_back( gr_complex( (float(i >> 8) - 127.4f) * (1.0f/128.0f),<br>
-                                (float(i & 0xff) - 127.4f) * (1.0f/128.0f) ) );<br>
-#endif<br>
-  }<br>
+  for (unsigned int i = 0; i < 0x100; i++)<br>
+    _lut.push_back((i - 127.4f) / 128.0f);<br>
<br>
   _dev = NULL;<br>
   ret = rtlsdr_open( &_dev, dev_index );<br>
@@ -230,11 +223,11 @@ rtl_source_c::rtl_source_c (const std::string &args)<br>
<br>
   set_if_gain( 24 ); /* preset to a reasonable default (non-GRC use case) */<br>
<br>
-  _buf = (unsigned short **) malloc(_buf_num * sizeof(unsigned short *));<br>
+  _buf = (unsigned char **)malloc(_buf_num * sizeof(unsigned char *));<br>
<br>
   if (_buf) {<br>
     for(unsigned int i = 0; i < _buf_num; ++i)<br>
-      _buf[i] = (unsigned short *) malloc(_buf_len);<br>
+      _buf[i] = (unsigned char *)malloc(_buf_len);<br>
   }<br>
 }<br>
<br>
@@ -348,10 +341,10 @@ int rtl_source_c::work( int noutput_items,<br>
<br>
   while (noutput_items && _buf_used) {<br>
     const int nout = std::min(noutput_items, _samp_avail);<br>
-    const unsigned short *buf = _buf[_buf_head] + _buf_offset;<br>
+    const unsigned char *buf = _buf[_buf_head] + _buf_offset * 2;<br>
<br>
     for (int i = 0; i < nout; ++i)<br>
-      *out++ = _lut[ *(buf + i) ];<br>
+      *out++ = gr_complex(_lut[buf[i * 2]], _lut[buf[i * 2 + 1]]);<br>
<br>
     noutput_items -= nout;<br>
     _samp_avail -= nout;<br>
diff --git a/lib/rtl/rtl_source_c.h b/lib/rtl/rtl_source_c.h<br>
index 76de400..902b386 100644<br>
--- a/lib/rtl/rtl_source_c.h<br>
+++ b/lib/rtl/rtl_source_c.h<br>
@@ -122,11 +122,11 @@ private:<br>
   static void _rtlsdr_wait(rtl_source_c *obj);<br>
   void rtlsdr_wait();<br>
<br>
-  std::vector<gr_complex> _lut;<br>
+  std::vector<float> _lut;<br>
<br>
   rtlsdr_dev_t *_dev;<br>
   gr::thread::thread _thread;<br>
-  unsigned short **_buf;<br>
+  unsigned char **_buf;<br>
   unsigned int _buf_num;<br>
   unsigned int _buf_len;<br>
   unsigned int _buf_head;<br>
<br>
<br>
------------------------------<br>
<br>
Message: 7<br>
Date: Wed, 24 Aug 2016 23:55:40 +0200<br>
From: Krzysztof Halasa <<a href="mailto:khc@pm.waw.pl">khc@pm.waw.pl</a>><br>
To: <a href="mailto:osmocom-sdr@lists.osmocom.org">osmocom-sdr@lists.osmocom.org</a><br>
Subject: [PATCH] RTL-TCP: Convert to single class model<br>
Message-ID: <<a href="mailto:m3h9a9u90j.fsf@pm.waw.pl">m3h9a9u90j.fsf@pm.waw.pl</a>><br>
Content-Type: text/plain<br>
<br>
The existing RTL TCP driver is quite different from its brother RTL_SDR.<br>
It's much more complicated, uses gr::blocks::deinterleave and<br>
gr::blocks::float_to_complex, and generally doesn't work correctly<br>
(e.g. <a href="https://github.com/csete/gqrx/issues/99" rel="noreferrer" target="_blank">https://github.com/csete/gqrx/<wbr>issues/99</a><br>
 Spectrum is mirrored when filter or demodulator changes (rtl_tcp) #99)<br>
<br>
I've converted the RTL TCP driver to the model used by RTL_SDR,<br>
simplifying it in the process, and fixing the GQRX issue.<br>
<br>
diff --git a/lib/rtl_tcp/CMakeLists.txt b/lib/rtl_tcp/CMakeLists.txt<br>
index 18400fd..9f7c201 100644<br>
--- a/lib/rtl_tcp/CMakeLists.txt<br>
+++ b/lib/rtl_tcp/CMakeLists.txt<br>
@@ -26,7 +26,6 @@ include_directories(<br>
 )<br>
<br>
 set(rtl_tcp_srcs<br>
-    ${CMAKE_CURRENT_SOURCE_DIR}/<wbr>rtl_tcp_source_f.cc<br>
     ${CMAKE_CURRENT_SOURCE_DIR}/<wbr>rtl_tcp_source_c.cc<br>
 )<br>
<br>
diff --git a/lib/rtl_tcp/rtl_tcp_source_<wbr>c.cc b/lib/rtl_tcp/rtl_tcp_source_<wbr>c.cc<br>
index a365688..64a3f77 100644<br>
--- a/lib/rtl_tcp/rtl_tcp_source_<wbr>c.cc<br>
+++ b/lib/rtl_tcp/rtl_tcp_source_<wbr>c.cc<br>
@@ -1,4 +1,4 @@<br>
-/* -*- c++ -*- */<br>
+/* -*- mode: c++; c-basic-offset: 2 -*- */<br>
 /*<br>
  * Copyright 2012 Dimitri Stolnikov <<a href="mailto:horiz0n@gmx.net">horiz0n@gmx.net</a>><br>
  *<br>
@@ -26,31 +26,114 @@<br>
 #include <boost/algorithm/string.hpp><br>
<br>
 #include <gnuradio/io_signature.h><br>
-#include <gnuradio/blocks/deinterleave.<wbr>h><br>
-#include <gnuradio/blocks/float_to_<wbr>complex.h><br>
<br>
 #include "rtl_tcp_source_c.h"<br>
-<br>
 #include "arg_helpers.h"<br>
<br>
+#if defined(_WIN32)<br>
+// if not posix, assume winsock<br>
+#pragma comment(lib, "ws2_32.lib")<br>
+#define USING_WINSOCK<br>
+#include <winsock2.h><br>
+#include <ws2tcpip.h><br>
+#define SHUT_RDWR 2<br>
+typedef char* optval_t;<br>
+#else<br>
+#include <netdb.h><br>
+#include <sys/types.h><br>
+#include <sys/socket.h><br>
+#include <netinet/in.h><br>
+#include <netinet/tcp.h><br>
+#include <arpa/inet.h><br>
+typedef void* optval_t;<br>
+#endif<br>
+<br>
+#ifdef _MSC_VER<br>
+#include <cstddef><br>
+typedef ptrdiff_t ssize_t;<br>
+#endif //_MSC_VER<br>
+<br>
+#ifndef _WIN32<br>
+#include <netinet/in.h><br>
+#else<br>
+#include <WinSock2.h><br>
+#endif<br>
+<br>
+#define BYTES_PER_SAMPLE  2 // rtl_tcp device delivers 8 bit unsigned IQ data<br>
+<br>
+/* copied from rtl sdr code */<br>
+typedef struct { /* structure size must be multiple of 2 bytes */<br>
+  char magic[4];<br>
+  uint32_t tuner_type;<br>
+  uint32_t tuner_gain_count;<br>
+} dongle_info_t;<br>
+<br>
+#ifdef _WIN32<br>
+#define __attribute__(x)<br>
+#pragma pack(push, 1)<br>
+#endif<br>
+struct command {<br>
+  unsigned char cmd;<br>
+  unsigned int param;<br>
+} __attribute__((packed));<br>
+#ifdef _WIN32<br>
+#pragma pack(pop)<br>
+#endif<br>
+<br>
+#define USE_SELECT    1  // non-blocking receive on all platforms<br>
+#define USE_RCV_TIMEO 0  // non-blocking receive on all but Cygwin<br>
+#define SRC_VERBOSE 0<br>
+#define SNK_VERBOSE 0<br>
+<br>
+static int is_error( int perr )<br>
+{<br>
+  // Compare error to posix error code; return nonzero if match.<br>
+#if defined(USING_WINSOCK)<br>
+#define ENOPROTOOPT 109<br>
+  // All codes to be checked for must be defined below<br>
+  int werr = WSAGetLastError();<br>
+  switch( werr ) {<br>
+  case WSAETIMEDOUT:<br>
+    return( perr == EAGAIN );<br>
+  case WSAENOPROTOOPT:<br>
+    return( perr == ENOPROTOOPT );<br>
+  default:<br>
+    fprintf(stderr,"rtl_tcp_<wbr>source_f: unknown error %d WS err %d \n", perr, werr );<br>
+    throw std::runtime_error("internal error");<br>
+  }<br>
+  return 0;<br>
+#else<br>
+  return( perr == errno );<br>
+#endif<br>
+}<br>
+<br>
+static void report_error( const char *msg1, const char *msg2 )<br>
+{<br>
+  // Deal with errors, both posix and winsock<br>
+#if defined(USING_WINSOCK)<br>
+  int werr = WSAGetLastError();<br>
+  fprintf(stderr, "%s: winsock error %d\n", msg1, werr );<br>
+#else<br>
+  perror(msg1);<br>
+#endif<br>
+  if( msg2 != NULL )<br>
+    throw std::runtime_error(msg2);<br>
+  return;<br>
+}<br>
+<br>
 using namespace boost::assign;<br>
<br>
-static std::string get_tuner_name( enum rtlsdr_tuner tuner_type )<br>
+const char * rtl_tcp_source_c::get_tuner_<wbr>name(void)<br>
 {<br>
-  if ( RTLSDR_TUNER_E4000 == tuner_type )<br>
-    return "E4000";<br>
-  else if ( RTLSDR_TUNER_FC0012 == tuner_type )<br>
-    return "FC0012";<br>
-  else if ( RTLSDR_TUNER_FC0013 == tuner_type )<br>
-    return "FC0013";<br>
-  else if ( RTLSDR_TUNER_FC2580 == tuner_type )<br>
-    return "FC2580";<br>
-  else if ( RTLSDR_TUNER_R820T == tuner_type )<br>
-    return "R820T";<br>
-  else if ( RTLSDR_TUNER_R828D == tuner_type )<br>
-    return "R828D";<br>
-  else<br>
-    return "Unknown";<br>
+  switch (d_tuner_type) {<br>
+  case RTLSDR_TUNER_E4000: return "E4000";<br>
+  case RTLSDR_TUNER_FC0012: return "FC0012";<br>
+  case RTLSDR_TUNER_FC0013: return "FC0013";<br>
+  case RTLSDR_TUNER_FC2580: return "FC2580";<br>
+  case RTLSDR_TUNER_R820T: return "R820T";<br>
+  case RTLSDR_TUNER_R828D: return "R828D";<br>
+  default: return "Unknown";<br>
+  }<br>
 }<br>
<br>
 rtl_tcp_source_c_sptr make_rtl_tcp_source_c(const std::string &args)<br>
@@ -59,9 +142,10 @@ rtl_tcp_source_c_sptr make_rtl_tcp_source_c(const std::string &args)<br>
 }<br>
<br>
 rtl_tcp_source_c::rtl_tcp_<wbr>source_c(const std::string &args) :<br>
-  gr::hier_block2("rtl_tcp_<wbr>source_c",<br>
+  gr::sync_block("rtl_tcp_<wbr>source_c",<br>
                  gr::io_signature::make(0, 0, 0),<br>
                  gr::io_signature::make(1, 1, sizeof (gr_complex))),<br>
+  d_socket(-1),<br>
   _no_tuner(false),<br>
   _auto_gain(false),<br>
   _if_gain(0)<br>
@@ -107,43 +191,162 @@ rtl_tcp_source_c::rtl_tcp_<wbr>source_c(const std::string &args) :<br>
   if (payload_size <= 0)<br>
     payload_size = 16384;<br>
<br>
-  _src = make_rtl_tcp_source_f(sizeof(<wbr>float), host.c_str(), port, payload_size);<br>
+#if defined(USING_WINSOCK) // for Windows (with MinGW)<br>
+  // initialize winsock DLL<br>
+  WSADATA wsaData;<br>
+  int iResult = WSAStartup( MAKEWORD(2,2), &wsaData );<br>
+  if( iResult != NO_ERROR ) {<br>
+    report_error( "rtl_tcp_source_f WSAStartup", "can't open socket" );<br>
+  }<br>
+#endif<br>
<br>
-  if ( _src->get_tuner_type() != RTLSDR_TUNER_UNKNOWN )<br>
-  {<br>
+  // Set up the address stucture for the source address and port numbers<br>
+  // Get the source IP address from the host name<br>
+  struct addrinfo *ip_src;      // store the source IP address to use<br>
+  struct addrinfo hints;<br>
+  memset( (void*)&hints, 0, sizeof(hints) );<br>
+  hints.ai_family = AF_UNSPEC;<br>
+  hints.ai_socktype = SOCK_STREAM;<br>
+  hints.ai_protocol = IPPROTO_TCP;<br>
+  hints.ai_flags = AI_PASSIVE;<br>
+  char port_str[12];<br>
+  sprintf( port_str, "%d", port );<br>
+<br>
+  // FIXME leaks if report_error throws below<br>
+  int ret = getaddrinfo(host.c_str(), port_str, &hints, &ip_src);<br>
+  if (ret != 0)<br>
+    report_error("rtl_tcp_source_<wbr>f/getaddrinfo",<br>
+                 "can't initialize source socket" );<br>
+<br>
+  // FIXME leaks if report_error throws below<br>
+  d_temp_buff = new unsigned char[payload_size];   // allow it to hold up to payload_size bytes<br>
+  d_LUT = new float[0x100];<br>
+  for (int i = 0; i < 0x100; ++i)<br>
+    d_LUT[i] = (((float)(i & 0xff)) - 127.4f) * (1.0f / 128.0f);<br>
+<br>
+  // create socket<br>
+  d_socket = socket(ip_src->ai_family, ip_src->ai_socktype,<br>
+                    ip_src->ai_protocol);<br>
+  if (d_socket == -1)<br>
+    report_error("socket open","can't open socket");<br>
+<br>
+  // Turn on reuse address<br>
+  int opt_val = 1;<br>
+  if (setsockopt(d_socket, SOL_SOCKET, SO_REUSEADDR, (optval_t)&opt_val, sizeof(int)) == -1)<br>
+    report_error("SO_REUSEADDR","<wbr>can't set socket option SO_REUSEADDR");<br>
+<br>
+  // Don't wait when shutting down<br>
+  linger lngr;<br>
+  lngr.l_onoff  = 1;<br>
+  lngr.l_linger = 0;<br>
+  if (setsockopt(d_socket, SOL_SOCKET, SO_LINGER, (optval_t)&lngr, sizeof(linger)) == -1)<br>
+    if (!is_error(ENOPROTOOPT)) // no SO_LINGER for SOCK_DGRAM on Windows<br>
+      report_error("SO_LINGER","can'<wbr>t set socket option SO_LINGER");<br>
+<br>
+#if USE_RCV_TIMEO<br>
+  // Set a timeout on the receive function to not block indefinitely<br>
+  // This value can (and probably should) be changed<br>
+  // Ignored on Cygwin<br>
+#if defined(USING_WINSOCK)<br>
+  DWORD timeout = 1000;  // milliseconds<br>
+#else<br>
+  timeval timeout;<br>
+  timeout.tv_sec = 1;<br>
+  timeout.tv_usec = 0;<br>
+#endif<br>
+  if (setsockopt(d_socket, SOL_SOCKET, SO_RCVTIMEO, (optval_t)&timeout, sizeof(timeout)) == -1)<br>
+    report_error("SO_RCVTIMEO","<wbr>can't set socket option SO_RCVTIMEO");<br>
+#endif // USE_RCV_TIMEO<br>
+<br>
+  while (::connect(d_socket, ip_src->ai_addr, ip_src->ai_addrlen) != 0)<br>
+    ; // FIXME handle errors?<br>
+  freeaddrinfo(ip_src);<br>
+<br>
+  int flag = 1;<br>
+  setsockopt(d_socket, IPPROTO_TCP, TCP_NODELAY, (char *)&flag,sizeof(flag));<br>
+<br>
+  dongle_info_t dongle_info;<br>
+  ret = recv(d_socket, (char*)&dongle_info, sizeof(dongle_info), 0);<br>
+  if (sizeof(dongle_info) != ret)<br>
+    fprintf(stderr,"failed to read dongle info\n");<br>
+<br>
+  d_tuner_type = RTLSDR_TUNER_UNKNOWN;<br>
+  d_tuner_gain_count = 0;<br>
+  d_tuner_if_gain_count = 0;<br>
+<br>
+  if (memcmp(dongle_info.magic, "RTL0", 4) == 0) {<br>
+    d_tuner_type = rtlsdr_tuner(ntohl(dongle_<wbr>info.tuner_type));<br>
+    d_tuner_gain_count = ntohl(dongle_info.tuner_gain_<wbr>count);<br>
+    if (RTLSDR_TUNER_E4000 == d_tuner_type)<br>
+      d_tuner_if_gain_count = 53;<br>
+  }<br>
+<br>
+  if (d_tuner_type != RTLSDR_TUNER_UNKNOWN) {<br>
     std::cerr << "The RTL TCP server reports a "<br>
-              << get_tuner_name( _src->get_tuner_type() )<br>
+              << get_tuner_name()<br>
               << " tuner with "<br>
-              << _src->get_tuner_gain_count() << " RF and "<br>
-              << _src->get_tuner_if_gain_count(<wbr>) << " IF gains."<br>
+              << d_tuner_gain_count << " RF and "<br>
+              << d_tuner_if_gain_count << " IF gains."<br>
               << std::endl;<br>
   }<br>
<br>
   set_gain_mode(false); /* enable manual gain mode by default */<br>
<br>
-  _src->set_direct_sampling(<wbr>direct_samp);<br>
-  if (direct_samp) {<br>
+  // set direct sampling<br>
+  struct command cmd = { 0x09, htonl(direct_samp) };<br>
+  send(d_socket, (const char*)&cmd, sizeof(cmd), 0);<br>
+  if (direct_samp)<br>
     _no_tuner = true;<br>
-  }<br>
<br>
-  _src->set_offset_tuning(<wbr>offset_tune);<br>
-<br>
-  /* rtl tcp source provides a stream of interleaved IQ floats */<br>
-  gr::blocks::deinterleave::sptr deinterleave = \<br>
-      gr::blocks::deinterleave::<wbr>make( sizeof(float) );<br>
+  // set offset tuning<br>
+  cmd = { 0x0a, htonl(offset_tune) };<br>
+  send(d_socket, (const char*)&cmd, sizeof(cmd), 0);<br>
+}<br>
<br>
-  /* block to convert deinterleaved floats to a complex stream */<br>
-  gr::blocks::float_to_complex::<wbr>sptr f2c = \<br>
-      gr::blocks::float_to_complex::<wbr>make( 1 );<br>
+rtl_tcp_source_c::~rtl_tcp_<wbr>source_c()<br>
+{<br>
+  delete [] d_temp_buff;<br>
+<br>
+  if (d_socket != -1) {<br>
+    shutdown(d_socket, SHUT_RDWR);<br>
+#if defined(USING_WINSOCK)<br>
+    closesocket(d_socket);<br>
+#else<br>
+    ::close(d_socket);<br>
+#endif<br>
+    d_socket = -1;<br>
+  }<br>
<br>
-  connect(_src, 0, deinterleave, 0);<br>
-  connect(deinterleave, 0, f2c, 0); /* I */<br>
-  connect(deinterleave, 1, f2c, 1); /* Q */<br>
-  connect(f2c, 0, self(), 0);<br>
+#if defined(USING_WINSOCK) // for Windows (with MinGW)<br>
+  // free winsock resources<br>
+  WSACleanup();<br>
+#endif<br>
 }<br>
<br>
-rtl_tcp_source_c::~rtl_tcp_<wbr>source_c()<br>
+<br>
+int rtl_tcp_source_c::work(int noutput_items,<br>
+                          gr_vector_const_void_star &input_items,<br>
+                          gr_vector_void_star &output_items)<br>
 {<br>
+  gr_complex *out = (gr_complex *)output_items[0];<br>
+  int bytesleft = noutput_items * BYTES_PER_SAMPLE;<br>
+  int index = 0;<br>
+  int receivedbytes = 0;<br>
+  while (bytesleft > 0) {<br>
+    receivedbytes = recv(d_socket, (char*)&d_temp_buff[index], bytesleft, 0);<br>
+<br>
+    if (receivedbytes == -1 && !is_error(EAGAIN)) {<br>
+      fprintf(stderr, "socket error\n");<br>
+      return -1;<br>
+    }<br>
+    bytesleft -= receivedbytes;<br>
+    index += receivedbytes;<br>
+  }<br>
+<br>
+  for (int i = 0; i < noutput_items; i++)<br>
+    out[i] = gr_complex(d_LUT[d_temp_buff[i * 2]], d_LUT[d_temp_buff[i * 2 + 1]]);<br>
+<br>
+  return noutput_items;<br>
 }<br>
<br>
 std::string rtl_tcp_source_c::name()<br>
@@ -193,7 +396,8 @@ osmosdr::meta_range_t rtl_tcp_source_c::get_sample_<wbr>rates( void )<br>
<br>
 double rtl_tcp_source_c::set_sample_<wbr>rate( double rate )<br>
 {<br>
-  _src->set_sample_rate( int(rate) );<br>
+  struct command cmd = { 0x02, htonl(rate) };<br>
+  send(d_socket, (const char*)&cmd, sizeof(cmd), 0);<br>
<br>
   _rate = rate;<br>
<br>
@@ -214,24 +418,26 @@ osmosdr::freq_range_t rtl_tcp_source_c::get_freq_<wbr>range( size_t chan )<br>
     return range;<br>
   }<br>
<br>
-  enum rtlsdr_tuner tuner = _src->get_tuner_type();<br>
-<br>
-  if ( tuner == RTLSDR_TUNER_E4000 ) {<br>
-    /* there is a (temperature dependent) gap between 1100 to 1250 MHz */<br>
-    range += osmosdr::range_t( 52e6, 2.2e9 );<br>
-  } else if ( tuner == RTLSDR_TUNER_FC0012 ) {<br>
+  switch (d_tuner_type) {<br>
+  case RTLSDR_TUNER_FC0012:<br>
     range += osmosdr::range_t( 22e6, 948e6 );<br>
-  } else if ( tuner == RTLSDR_TUNER_FC0013 ) {<br>
+    break;<br>
+  case RTLSDR_TUNER_FC0013:<br>
     range += osmosdr::range_t( 22e6, 1.1e9 );<br>
-  } else if ( tuner == RTLSDR_TUNER_FC2580 ) {<br>
+    break;<br>
+  case RTLSDR_TUNER_FC2580:<br>
     range += osmosdr::range_t( 146e6, 308e6 );<br>
     range += osmosdr::range_t( 438e6, 924e6 );<br>
-  } else if ( tuner == RTLSDR_TUNER_R820T ) {<br>
+    break;<br>
+  case RTLSDR_TUNER_R820T:<br>
     range += osmosdr::range_t( 24e6, 1766e6 );<br>
-  } else if ( tuner == RTLSDR_TUNER_R828D ) {<br>
+    break;<br>
+  case RTLSDR_TUNER_R828D:<br>
     range += osmosdr::range_t( 24e6, 1766e6 );<br>
-  } else {<br>
-    range += osmosdr::range_t( 52e6, 2.2e9 ); // assume E4000 tuner<br>
+    break;<br>
+  default:                     // assume E4000 tuner<br>
+    /* there is a (temperature dependent) gap between 1100 to 1250 MHz */<br>
+    range += osmosdr::range_t( 52e6, 2.2e9 );<br>
   }<br>
<br>
   return range;<br>
@@ -239,7 +445,8 @@ osmosdr::freq_range_t rtl_tcp_source_c::get_freq_<wbr>range( size_t chan )<br>
<br>
 double rtl_tcp_source_c::set_center_<wbr>freq( double freq, size_t chan )<br>
 {<br>
-  _src->set_freq( int(freq) );<br>
+  struct command cmd = { 0x01, htonl(freq) };<br>
+  send(d_socket, (const char*)&cmd, sizeof(cmd), 0);<br>
<br>
   _freq = freq;<br>
<br>
@@ -253,7 +460,8 @@ double rtl_tcp_source_c::get_center_<wbr>freq( size_t chan )<br>
<br>
 double rtl_tcp_source_c::set_freq_<wbr>corr( double ppm, size_t chan )<br>
 {<br>
-  _src->set_freq_corr( int(ppm) );<br>
+  struct command cmd = { 0x05, htonl(ppm) };<br>
+  send(d_socket, (const char*)&cmd, sizeof(cmd), 0);<br>
<br>
   _corr = ppm;<br>
<br>
@@ -271,9 +479,8 @@ std::vector<std::string> rtl_tcp_source_c::get_gain_<wbr>names( size_t chan )<br>
<br>
   names += "LNA";<br>
<br>
-  if ( _src->get_tuner_type() == RTLSDR_TUNER_E4000 ) {<br>
+  if (d_tuner_type == RTLSDR_TUNER_E4000)<br>
     names += "IF";<br>
-  }<br>
<br>
   return names;<br>
 }<br>
@@ -301,8 +508,7 @@ osmosdr::gain_range_t rtl_tcp_source_c::get_gain_<wbr>range( size_t chan )<br>
   const int *ptr = NULL;<br>
   int len = 0;<br>
<br>
-  switch (_src->get_tuner_type())<br>
-  {<br>
+  switch (d_tuner_type) {<br>
   case RTLSDR_TUNER_E4000:<br>
     ptr = e4k_gains; len = sizeof(e4k_gains);<br>
     break;<br>
@@ -335,11 +541,10 @@ osmosdr::gain_range_t rtl_tcp_source_c::get_gain_<wbr>range( size_t chan )<br>
 osmosdr::gain_range_t rtl_tcp_source_c::get_gain_<wbr>range( const std::string & name, size_t chan )<br>
 {<br>
   if ( "IF" == name ) {<br>
-    if ( _src->get_tuner_type() == RTLSDR_TUNER_E4000 ) {<br>
+    if (d_tuner_type == RTLSDR_TUNER_E4000)<br>
       return osmosdr::gain_range_t(3, 56, 1);<br>
-    } else {<br>
+    else<br>
       return osmosdr::gain_range_t();<br>
-    }<br>
   }<br>
<br>
   return get_gain_range( chan );<br>
@@ -347,8 +552,13 @@ osmosdr::gain_range_t rtl_tcp_source_c::get_gain_<wbr>range( const std::string & name<br>
<br>
 bool rtl_tcp_source_c::set_gain_<wbr>mode( bool automatic, size_t chan )<br>
 {<br>
-  _src->set_gain_mode(int(!<wbr>automatic));<br>
-  _src->set_agc_mode(automatic);<br>
+  // gain mode<br>
+  struct command cmd = { 0x03, htonl(!automatic) };<br>
+  send(d_socket, (const char*)&cmd, sizeof(cmd), 0);<br>
+<br>
+  // AGC mode<br>
+  cmd = { 0x08, htonl(automatic) };<br>
+  send(d_socket, (const char*)&cmd, sizeof(cmd), 0);<br>
<br>
   _auto_gain = automatic;<br>
<br>
@@ -364,7 +574,8 @@ double rtl_tcp_source_c::set_gain( double gain, size_t chan )<br>
 {<br>
   osmosdr::gain_range_t gains = rtl_tcp_source_c::get_gain_<wbr>range( chan );<br>
<br>
-  _src->set_gain( int(gains.clip(gain) * 10.0) );<br>
+  struct command cmd = { 0x04, htonl(int(gains.clip(gain) * 10.0)) };<br>
+  send(d_socket, (const char*)&cmd, sizeof(cmd), 0);<br>
<br>
   _gain = gain;<br>
<br>
@@ -396,7 +607,7 @@ double rtl_tcp_source_c::get_gain( const std::string & name, size_t chan )<br>
<br>
 double rtl_tcp_source_c::set_if_gain(<wbr>double gain, size_t chan)<br>
 {<br>
-  if ( _src->get_tuner_type() != RTLSDR_TUNER_E4000 ) {<br>
+  if (d_tuner_type != RTLSDR_TUNER_E4000) {<br>
     _if_gain = 0;<br>
     return _if_gain;<br>
   }<br>
@@ -448,7 +659,10 @@ double rtl_tcp_source_c::set_if_gain(<wbr>double gain, size_t chan)<br>
   std::cerr << " = " << sum << std::endl;<br>
 #endif<br>
   for (unsigned int stage = 1; stage <= gains.size(); stage++) {<br>
-    _src->set_if_gain(stage, int(gains[ stage ] * 10.0));<br>
+    int gain_i = int(gains[stage] * 10.0);<br>
+    uint32_t params = stage << 16 | (gain_i & 0xffff);<br>
+    struct command cmd = { 0x06, htonl(params) };<br>
+    send(d_socket, (const char*)&cmd, sizeof(cmd), 0);<br>
   }<br>
<br>
   _if_gain = gain;<br>
diff --git a/lib/rtl_tcp/rtl_tcp_source_<wbr>c.h b/lib/rtl_tcp/rtl_tcp_source_<wbr>c.h<br>
index 454d1a2..b07e5dd 100644<br>
--- a/lib/rtl_tcp/rtl_tcp_source_<wbr>c.h<br>
+++ b/lib/rtl_tcp/rtl_tcp_source_<wbr>c.h<br>
@@ -1,4 +1,4 @@<br>
-/* -*- c++ -*- */<br>
+/* -*- mode: c++; c-basic-offset: 2 -*- */<br>
 /*<br>
  * Copyright 2012 Dimitri Stolnikov <<a href="mailto:horiz0n@gmx.net">horiz0n@gmx.net</a>><br>
  *<br>
@@ -20,12 +20,10 @@<br>
 #ifndef RTL_TCP_SOURCE_C_H<br>
 #define RTL_TCP_SOURCE_C_H<br>
<br>
-#include <gnuradio/hier_block2.h><br>
+#include <gnuradio/sync_block.h><br>
<br>
 #include "source_iface.h"<br>
<br>
-#include "rtl_tcp_source_f.h"<br>
-<br>
 class rtl_tcp_source_c;<br>
<br>
 typedef boost::shared_ptr< rtl_tcp_source_c > rtl_tcp_source_c_sptr;<br>
@@ -33,17 +31,33 @@ typedef boost::shared_ptr< rtl_tcp_source_c > rtl_tcp_source_c_sptr;<br>
 rtl_tcp_source_c_sptr make_rtl_tcp_source_c( const std::string & args = "" );<br>
<br>
 class rtl_tcp_source_c :<br>
-    public gr::hier_block2,<br>
+    public gr::sync_block,<br>
     public source_iface<br>
 {<br>
 private:<br>
+  /* copied from rtl sdr */<br>
+  enum rtlsdr_tuner {<br>
+    RTLSDR_TUNER_UNKNOWN = 0,<br>
+    RTLSDR_TUNER_E4000,<br>
+    RTLSDR_TUNER_FC0012,<br>
+    RTLSDR_TUNER_FC0013,<br>
+    RTLSDR_TUNER_FC2580,<br>
+    RTLSDR_TUNER_R820T,<br>
+    RTLSDR_TUNER_R828D<br>
+  };<br>
+<br>
   friend rtl_tcp_source_c_sptr make_rtl_tcp_source_c(const std::string &args);<br>
<br>
   rtl_tcp_source_c(const std::string &args);<br>
+  const char * get_tuner_name(void);<br>
<br>
 public:<br>
   ~rtl_tcp_source_c();<br>
<br>
+  int work(int noutput_items,<br>
+          gr_vector_const_void_star &input_items,<br>
+          gr_vector_void_star &output_items);<br>
+<br>
   std::string name();<br>
<br>
   static std::vector< std::string > get_devices( bool fake = false );<br>
@@ -77,11 +91,17 @@ public:<br>
   std::string get_antenna( size_t chan = 0 );<br>
<br>
 private:<br>
+  int d_socket;                  // handle to socket<br>
   double _freq, _rate, _gain, _corr;<br>
   bool _no_tuner;<br>
   bool _auto_gain;<br>
   double _if_gain;<br>
-  rtl_tcp_source_f_sptr _src;<br>
+<br>
+  enum rtlsdr_tuner d_tuner_type;<br>
+  unsigned int d_tuner_gain_count;<br>
+  unsigned int d_tuner_if_gain_count;<br>
+  unsigned char *d_temp_buff; // hold buffer between calls<br>
+  float *d_LUT;<br>
 };<br>
<br>
 #endif // RTL_TCP_SOURCE_C_H<br>
diff --git a/lib/rtl_tcp/rtl_tcp_source_<wbr>f.cc b/lib/rtl_tcp/rtl_tcp_source_<wbr>f.cc<br>
deleted file mode 100644<br>
index a17594c..0000000<br>
--- a/lib/rtl_tcp/rtl_tcp_source_<wbr>f.cc<br>
+++ /dev/null<br>
@@ -1,327 +0,0 @@<br>
-/* -*- c++ -*- */<br>
-/*<br>
- * Copyright 2012 Hoernchen <<a href="mailto:la@tfc-server.de">la@tfc-server.de</a>><br>
- * Copyright 2012 Dimitri Stolnikov <<a href="mailto:horiz0n@gmx.net">horiz0n@gmx.net</a>><br>
- *<br>
- * GNU Radio is free software; you can redistribute it and/or modify<br>
- * it under the terms of the GNU General Public License as published by<br>
- * the Free Software Foundation; either version 3, or (at your option)<br>
- * any later version.<br>
- *<br>
- * GNU Radio is distributed in the hope that it will be useful,<br>
- * but WITHOUT ANY WARRANTY; without even the implied warranty of<br>
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the<br>
- * GNU General Public License for more details.<br>
- *<br>
- * You should have received a copy of the GNU General Public License<br>
- * along with GNU Radio; see the file COPYING.  If not, write to<br>
- * the Free Software Foundation, Inc., 51 Franklin Street,<br>
- * Boston, MA 02110-1301, USA.<br>
- */<br>
-//#define HAVE_WINDOWS_H<br>
-<br>
-<br>
-#include <rtl_tcp_source_f.h><br>
-#include <gnuradio/io_signature.h><br>
-#include <stdexcept><br>
-#include <errno.h><br>
-#include <stdio.h><br>
-#include <string.h><br>
-<br>
-#ifndef _WIN32<br>
-#include <netinet/in.h><br>
-#else<br>
-#include <WinSock2.h><br>
-#endif<br>
-<br>
-/* copied from rtl sdr code */<br>
-typedef struct { /* structure size must be multiple of 2 bytes */<br>
-  char magic[4];<br>
-  uint32_t tuner_type;<br>
-  uint32_t tuner_gain_count;<br>
-} dongle_info_t;<br>
-<br>
-#define USE_SELECT    1  // non-blocking receive on all platforms<br>
-#define USE_RCV_TIMEO 0  // non-blocking receive on all but Cygwin<br>
-#define SRC_VERBOSE 0<br>
-#define SNK_VERBOSE 0<br>
-<br>
-static int is_error( int perr )<br>
-{<br>
-  // Compare error to posix error code; return nonzero if match.<br>
-#if defined(USING_WINSOCK)<br>
-#define ENOPROTOOPT 109<br>
-  // All codes to be checked for must be defined below<br>
-  int werr = WSAGetLastError();<br>
-  switch( werr ) {<br>
-  case WSAETIMEDOUT:<br>
-    return( perr == EAGAIN );<br>
-  case WSAENOPROTOOPT:<br>
-    return( perr == ENOPROTOOPT );<br>
-  default:<br>
-    fprintf(stderr,"rtl_tcp_<wbr>source_f: unknown error %d WS err %d \n", perr, werr );<br>
-    throw std::runtime_error("internal error");<br>
-  }<br>
-  return 0;<br>
-#else<br>
-  return( perr == errno );<br>
-#endif<br>
-}<br>
-<br>
-static void report_error( const char *msg1, const char *msg2 )<br>
-{<br>
-  // Deal with errors, both posix and winsock<br>
-#if defined(USING_WINSOCK)<br>
-  int werr = WSAGetLastError();<br>
-  fprintf(stderr, "%s: winsock error %d\n", msg1, werr );<br>
-#else<br>
-  perror(msg1);<br>
-#endif<br>
-  if( msg2 != NULL )<br>
-    throw std::runtime_error(msg2);<br>
-  return;<br>
-}<br>
-<br>
-rtl_tcp_source_f::rtl_tcp_<wbr>source_f(size_t itemsize,<br>
-                                   const char *host,<br>
-                                   unsigned short port,<br>
-                                   int payload_size,<br>
-                                   bool eof,<br>
-                                   bool wait)<br>
-  : gr::sync_block ("rtl_tcp_source_f",<br>
-                   gr::io_signature::make(0, 0, 0),<br>
-                   gr::io_signature::make(1, 1, sizeof(float))),<br>
-    d_itemsize(itemsize),<br>
-    d_payload_size(payload_size),<br>
-    d_eof(eof),<br>
-    d_wait(wait),<br>
-    d_socket(-1),<br>
-    d_temp_offset(0)<br>
-{<br>
-  int ret = 0;<br>
-#if defined(USING_WINSOCK) // for Windows (with MinGW)<br>
-  // initialize winsock DLL<br>
-  WSADATA wsaData;<br>
-  int iResult = WSAStartup( MAKEWORD(2,2), &wsaData );<br>
-  if( iResult != NO_ERROR ) {<br>
-    report_error( "rtl_tcp_source_f WSAStartup", "can't open socket" );<br>
-  }<br>
-#endif<br>
-<br>
-  // Set up the address stucture for the source address and port numbers<br>
-  // Get the source IP address from the host name<br>
-  struct addrinfo *ip_src;      // store the source IP address to use<br>
-  struct addrinfo hints;<br>
-  memset( (void*)&hints, 0, sizeof(hints) );<br>
-  hints.ai_family = AF_UNSPEC;<br>
-  hints.ai_socktype = SOCK_STREAM;<br>
-  hints.ai_protocol = IPPROTO_TCP;<br>
-  hints.ai_flags = AI_PASSIVE;<br>
-  char port_str[12];<br>
-  sprintf( port_str, "%d", port );<br>
-<br>
-  // FIXME leaks if report_error throws below<br>
-  ret = getaddrinfo( host, port_str, &hints, &ip_src );<br>
-  if( ret != 0 )<br>
-    report_error("rtl_tcp_source_<wbr>f/getaddrinfo",<br>
-                 "can't initialize source socket" );<br>
-<br>
-  // FIXME leaks if report_error throws below<br>
-  d_temp_buff = new unsigned char[d_payload_size];   // allow it to hold up to payload_size bytes<br>
-  d_LUT= new float[0xff+1];<br>
-  for(int i=0; i <=(0xff);++i){<br>
-    d_LUT[i] = (((float)(i&0xff))-127.4f)*(1.<wbr>0f/128.0f);<br>
-  }<br>
-  // create socket<br>
-  d_socket = socket(ip_src->ai_family, ip_src->ai_socktype,<br>
-                    ip_src->ai_protocol);<br>
-  if(d_socket == -1) {<br>
-    report_error("socket open","can't open socket");<br>
-  }<br>
-<br>
-  // Turn on reuse address<br>
-  int opt_val = 1;<br>
-  if(setsockopt(d_socket, SOL_SOCKET, SO_REUSEADDR, (optval_t)&opt_val, sizeof(int)) == -1) {<br>
-    report_error("SO_REUSEADDR","<wbr>can't set socket option SO_REUSEADDR");<br>
-  }<br>
-<br>
-  // Don't wait when shutting down<br>
-  linger lngr;<br>
-  lngr.l_onoff  = 1;<br>
-  lngr.l_linger = 0;<br>
-  if(setsockopt(d_socket, SOL_SOCKET, SO_LINGER, (optval_t)&lngr, sizeof(linger)) == -1) {<br>
-    if( !is_error(ENOPROTOOPT) ) {  // no SO_LINGER for SOCK_DGRAM on Windows<br>
-      report_error("SO_LINGER","can'<wbr>t set socket option SO_LINGER");<br>
-    }<br>
-  }<br>
-<br>
-#if USE_RCV_TIMEO<br>
-  // Set a timeout on the receive function to not block indefinitely<br>
-  // This value can (and probably should) be changed<br>
-  // Ignored on Cygwin<br>
-#if defined(USING_WINSOCK)<br>
-  DWORD timeout = 1000;  // milliseconds<br>
-#else<br>
-  timeval timeout;<br>
-  timeout.tv_sec = 1;<br>
-  timeout.tv_usec = 0;<br>
-#endif<br>
-  if(setsockopt(d_socket, SOL_SOCKET, SO_RCVTIMEO, (optval_t)&timeout, sizeof(timeout)) == -1) {<br>
-    report_error("SO_RCVTIMEO","<wbr>can't set socket option SO_RCVTIMEO");<br>
-  }<br>
-#endif // USE_RCV_TIMEO<br>
-<br>
-  while(connect(d_socket, ip_src->ai_addr, ip_src->ai_addrlen) != 0);<br>
-  freeaddrinfo(ip_src);<br>
-<br>
-  int flag = 1;<br>
-  setsockopt(d_socket, IPPROTO_TCP, TCP_NODELAY, (char *)&flag,sizeof(flag));<br>
-<br>
-  dongle_info_t dongle_info;<br>
-  ret = recv(d_socket, (char*)&dongle_info, sizeof(dongle_info), 0);<br>
-  if (sizeof(dongle_info) != ret)<br>
-    fprintf(stderr,"failed to read dongle info\n");<br>
-<br>
-  d_tuner_type = RTLSDR_TUNER_UNKNOWN;<br>
-  d_tuner_gain_count = 0;<br>
-  d_tuner_if_gain_count = 0;<br>
-<br>
-  if (memcmp(dongle_info.magic, "RTL0", 4) == 0)<br>
-  {<br>
-    d_tuner_type = ntohl(dongle_info.tuner_type);<br>
-    d_tuner_gain_count = ntohl(dongle_info.tuner_gain_<wbr>count);<br>
-    if ( RTLSDR_TUNER_E4000 == d_tuner_type )<br>
-      d_tuner_if_gain_count = 53;<br>
-  }<br>
-}<br>
-<br>
-rtl_tcp_source_f_sptr make_rtl_tcp_source_f (size_t itemsize,<br>
-                                             const char *ipaddr,<br>
-                                             unsigned short port,<br>
-                                             int payload_size,<br>
-                                             bool eof,<br>
-                                             bool wait)<br>
-{<br>
-  return gnuradio::get_initial_sptr(new rtl_tcp_source_f (<br>
-                                      itemsize,<br>
-                                      ipaddr,<br>
-                                      port,<br>
-                                      payload_size,<br>
-                                      eof,<br>
-                                      wait));<br>
-}<br>
-<br>
-rtl_tcp_source_f::~rtl_tcp_<wbr>source_f ()<br>
-{<br>
-  delete [] d_temp_buff;<br>
-<br>
-  if (d_socket != -1){<br>
-    shutdown(d_socket, SHUT_RDWR);<br>
-#if defined(USING_WINSOCK)<br>
-    closesocket(d_socket);<br>
-#else<br>
-    ::close(d_socket);<br>
-#endif<br>
-    d_socket = -1;<br>
-  }<br>
-<br>
-#if defined(USING_WINSOCK) // for Windows (with MinGW)<br>
-  // free winsock resources<br>
-  WSACleanup();<br>
-#endif<br>
-}<br>
-<br>
-int rtl_tcp_source_f::work (int noutput_items,<br>
-                            gr_vector_const_void_star &input_items,<br>
-                            gr_vector_void_star &output_items)<br>
-{<br>
-  float *out = (float *) output_items[0];<br>
-  ssize_t r = 0;<br>
-<br>
-  int bytesleft = noutput_items;<br>
-  int index = 0;<br>
-  int receivedbytes = 0;<br>
-  while(bytesleft > 0) {<br>
-    receivedbytes = recv(d_socket, (char*)&d_temp_buff[index], bytesleft, 0);<br>
-<br>
-    if(receivedbytes == -1 && !is_error(EAGAIN)){<br>
-      fprintf(stderr, "socket error\n");<br>
-      return -1;<br>
-    }<br>
-    bytesleft -= receivedbytes;<br>
-    index += receivedbytes;<br>
-  }<br>
-  r = noutput_items;<br>
-<br>
-  for(int i=0; i<r; ++i)<br>
-    out[i]=d_LUT[*(d_temp_buff+d_<wbr>temp_offset+i)];<br>
-<br>
-  return r;<br>
-}<br>
-<br>
-#ifdef _WIN32<br>
-#define __attribute__(x)<br>
-#pragma pack(push, 1)<br>
-#endif<br>
-struct command{<br>
-  unsigned char cmd;<br>
-  unsigned int param;<br>
-}__attribute__((packed));<br>
-#ifdef _WIN32<br>
-#pragma pack(pop)<br>
-#endif<br>
-<br>
-void rtl_tcp_source_f::set_freq(int freq)<br>
-{<br>
-  struct command cmd = { 0x01, htonl(freq) };<br>
-  send(d_socket, (const char*)&cmd, sizeof(cmd), 0);<br>
-}<br>
-<br>
-void rtl_tcp_source_f::set_sample_<wbr>rate(int sample_rate)<br>
-{<br>
-  struct command cmd = { 0x02, htonl(sample_rate) };<br>
-  send(d_socket, (const char*)&cmd, sizeof(cmd), 0);<br>
-}<br>
-<br>
-void rtl_tcp_source_f::set_gain_<wbr>mode(int manual)<br>
-{<br>
-  struct command cmd = { 0x03, htonl(manual) };<br>
-  send(d_socket, (const char*)&cmd, sizeof(cmd), 0);<br>
-}<br>
-<br>
-void rtl_tcp_source_f::set_gain(int gain)<br>
-{<br>
-  struct command cmd = { 0x04, htonl(gain) };<br>
-  send(d_socket, (const char*)&cmd, sizeof(cmd), 0);<br>
-}<br>
-<br>
-void rtl_tcp_source_f::set_freq_<wbr>corr(int ppm)<br>
-{<br>
-  struct command cmd = { 0x05, htonl(ppm) };<br>
-  send(d_socket, (const char*)&cmd, sizeof(cmd), 0);<br>
-}<br>
-<br>
-void rtl_tcp_source_f::set_if_gain(<wbr>int stage, int gain)<br>
-{<br>
-  uint32_t params = stage << 16 | (gain & 0xffff);<br>
-  struct command cmd = { 0x06, htonl(params) };<br>
-  send(d_socket, (const char*)&cmd, sizeof(cmd), 0);<br>
-}<br>
-<br>
-void rtl_tcp_source_f::set_agc_<wbr>mode(int on)<br>
-{<br>
-  struct command cmd = { 0x08, htonl(on) };<br>
-  send(d_socket, (const char*)&cmd, sizeof(cmd), 0);<br>
-}<br>
-<br>
-void rtl_tcp_source_f::set_direct_<wbr>sampling(int on)<br>
-{<br>
-  struct command cmd = { 0x09, htonl(on) };<br>
-  send(d_socket, (const char*)&cmd, sizeof(cmd), 0);<br>
-}<br>
-<br>
-void rtl_tcp_source_f::set_offset_<wbr>tuning(int on)<br>
-{<br>
-  struct command cmd = { 0x0a, htonl(on) };<br>
-  send(d_socket, (const char*)&cmd, sizeof(cmd), 0);<br>
-}<br>
diff --git a/lib/rtl_tcp/rtl_tcp_source_<wbr>f.h b/lib/rtl_tcp/rtl_tcp_source_<wbr>f.h<br>
deleted file mode 100644<br>
index 84ac57a..0000000<br>
--- a/lib/rtl_tcp/rtl_tcp_source_<wbr>f.h<br>
+++ /dev/null<br>
@@ -1,125 +0,0 @@<br>
-/* -*- c++ -*- */<br>
-/*<br>
- * Copyright 2012 Hoernchen <<a href="mailto:la@tfc-server.de">la@tfc-server.de</a>><br>
- *<br>
- * GNU Radio is free software; you can redistribute it and/or modify<br>
- * it under the terms of the GNU General Public License as published by<br>
- * the Free Software Foundation; either version 3, or (at your option)<br>
- * any later version.<br>
- *<br>
- * GNU Radio is distributed in the hope that it will be useful,<br>
- * but WITHOUT ANY WARRANTY; without even the implied warranty of<br>
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the<br>
- * GNU General Public License for more details.<br>
- *<br>
- * You should have received a copy of the GNU General Public License<br>
- * along with GNU Radio; see the file COPYING.  If not, write to<br>
- * the Free Software Foundation, Inc., 51 Franklin Street,<br>
- * Boston, MA 02110-1301, USA.<br>
- */<br>
-<br>
-#ifndef RTL_TCP_SOURCE_F_H<br>
-#define RTL_TCP_SOURCE_F_H<br>
-<br>
-#include <gnuradio/sync_block.h><br>
-#include <gnuradio/thread/thread.h><br>
-<br>
-#if defined(_WIN32)<br>
-// if not posix, assume winsock<br>
-#pragma comment(lib, "ws2_32.lib")<br>
-#define USING_WINSOCK<br>
-#include <winsock2.h><br>
-#include <ws2tcpip.h><br>
-#define SHUT_RDWR 2<br>
-typedef char* optval_t;<br>
-#else<br>
-#include <netdb.h><br>
-#include <sys/types.h><br>
-#include <sys/socket.h><br>
-#include <netinet/in.h><br>
-#include <netinet/tcp.h><br>
-#include <arpa/inet.h><br>
-typedef void* optval_t;<br>
-#endif<br>
-<br>
-#ifdef _MSC_VER<br>
-#include <cstddef><br>
-typedef ptrdiff_t ssize_t;<br>
-#endif //_MSC_VER<br>
-<br>
-/* copied from rtl sdr */<br>
-enum rtlsdr_tuner {<br>
-  RTLSDR_TUNER_UNKNOWN = 0,<br>
-  RTLSDR_TUNER_E4000,<br>
-  RTLSDR_TUNER_FC0012,<br>
-  RTLSDR_TUNER_FC0013,<br>
-  RTLSDR_TUNER_FC2580,<br>
-  RTLSDR_TUNER_R820T,<br>
-  RTLSDR_TUNER_R828D<br>
-};<br>
-<br>
-class rtl_tcp_source_f;<br>
-typedef boost::shared_ptr<rtl_tcp_<wbr>source_f> rtl_tcp_source_f_sptr;<br>
-<br>
-rtl_tcp_source_f_sptr make_rtl_tcp_source_f (<br>
-    size_t itemsize,<br>
-    const char *host,<br>
-    unsigned short port,<br>
-    int payload_size,<br>
-    bool eof = false,<br>
-    bool wait = false);<br>
-<br>
-class rtl_tcp_source_f : public gr::sync_block<br>
-{<br>
-private:<br>
-  size_t        d_itemsize;<br>
-  int           d_payload_size;  // maximum transmission unit (packet length)<br>
-  bool          d_eof;           // zero-length packet is EOF<br>
-  bool          d_wait;          // wait if data if not immediately available<br>
-  int           d_socket;        // handle to socket<br>
-  unsigned char *d_temp_buff;    // hold buffer between calls<br>
-  size_t        d_temp_offset;   // point to temp buffer location offset<br>
-  float         *d_LUT;<br>
-<br>
-  unsigned int d_tuner_type;<br>
-  unsigned int d_tuner_gain_count;<br>
-  unsigned int d_tuner_if_gain_count;<br>
-<br>
-private:<br>
-  rtl_tcp_source_f(size_t itemsize, const char *host,<br>
-                   unsigned short port, int payload_size, bool eof, bool wait);<br>
-<br>
-  // The friend declaration allows make_source_c to<br>
-  // access the private constructor.<br>
-  friend rtl_tcp_source_f_sptr make_rtl_tcp_source_f (<br>
-      size_t itemsize,<br>
-      const char *host,<br>
-      unsigned short port,<br>
-      int payload_size,<br>
-      bool eof,<br>
-      bool wait);<br>
-<br>
-public:<br>
-  ~rtl_tcp_source_f();<br>
-<br>
-  enum rtlsdr_tuner get_tuner_type() { return (enum rtlsdr_tuner) d_tuner_type; }<br>
-  unsigned int get_tuner_gain_count() { return d_tuner_gain_count; }<br>
-  unsigned int get_tuner_if_gain_count() { return d_tuner_if_gain_count; }<br>
-<br>
-  int work(int noutput_items,<br>
-           gr_vector_const_void_star &input_items,<br>
-           gr_vector_void_star &output_items);<br>
-<br>
-  void set_freq(int freq);<br>
-  void set_sample_rate(int sample_rate);<br>
-  void set_gain_mode(int manual);<br>
-  void set_gain(int gain);<br>
-  void set_freq_corr(int ppm);<br>
-  void set_if_gain(int stage, int gain);<br>
-  void set_agc_mode(int on);<br>
-  void set_direct_sampling(int on);<br>
-  void set_offset_tuning(int on);<br>
-};<br>
-<br>
-<br>
-#endif /* RTL_TCP_SOURCE_F_H */<br>
<br>
<br>
------------------------------<br>
<br>
Subject: Digest Footer<br>
<br>
______________________________<wbr>_________________<br>
osmocom-sdr mailing list<br>
<a href="mailto:osmocom-sdr@lists.osmocom.org">osmocom-sdr@lists.osmocom.org</a><br>
<a href="https://lists.osmocom.org/mailman/listinfo/osmocom-sdr" rel="noreferrer" target="_blank">https://lists.osmocom.org/<wbr>mailman/listinfo/osmocom-sdr</a><br>
<br>
<br>
------------------------------<br>
<br>
End of osmocom-sdr Digest, Vol 21, Issue 2<br>
******************************<wbr>************<br>
</blockquote></div></div>