From ba43a14e9238ccd59adc85c894e5aea7e0d694b4 Mon Sep 17 00:00:00 2001 From: Lucas Teske Date: Sun, 6 Mar 2016 01:09:59 -0300 Subject: [PATCH] Updates on rtl_tcp * Added Bandwidth Parameter (-w) to rtl_tcp to set the device bandwidth through cmd args * Added Bandwidth Network Parameter (0x0E) to rtl_tcp to set the device bandwidth through network * Added RTL_TCP_COMMANDS enum to better organize the network commands * Added binary files to gitignore --- .gitignore | 9 +++++++++ include/rtl-sdr.h | 1 + include/rtl_tcp.h | 51 +++++++++++++++++++++++++++++++++++++++++++++++ src/rtl_tcp.c | 46 ++++++++++++++++++++++++++++-------------- 4 files changed, 92 insertions(+), 15 deletions(-) create mode 100644 include/rtl_tcp.h diff --git a/.gitignore b/.gitignore index d22084c..84e02eb 100644 --- a/.gitignore +++ b/.gitignore @@ -41,4 +41,13 @@ CMakeFiles *.cmake build +**/*.o +**/*.so* +**/*.a +src/rtl_adsb +src/rtl_eeprom +src/rtl_fm +src/rtl_power +src/rtl_test + debianize/*.deb diff --git a/include/rtl-sdr.h b/include/rtl-sdr.h index 38ae207..0f90caf 100644 --- a/include/rtl-sdr.h +++ b/include/rtl-sdr.h @@ -26,6 +26,7 @@ extern "C" { #include #include +#include typedef struct rtlsdr_dev rtlsdr_dev_t; diff --git a/include/rtl_tcp.h b/include/rtl_tcp.h new file mode 100644 index 0000000..fb8d613 --- /dev/null +++ b/include/rtl_tcp.h @@ -0,0 +1,51 @@ +/* + * rtl-sdr, turns your Realtek RTL2832 based DVB dongle into a SDR receiver + * Copyright (C) 2012-2013 by Steve Markgraf + * Copyright (C) 2012 by Dimitri Stolnikov + * + * This program 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 2 of the License, or + * (at your option) any later version. + * + * This program 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 this program. If not, see . + */ + +#ifndef __RTL_TCP_H +#define __RTL_TCP_H + +#ifdef __cplusplus +extern "C" { +#endif + +/*! + * This enum defines the possible commands in rtl_tcp + */ +enum RTL_TCP_COMMANDS { + SET_FREQUENCY = 0x01, + SET_SAMPLE_RATE = 0x02, + SET_GAIN_MODE = 0x03, + SET_GAIN = 0x04, + SET_FREQUENCY_CORRECTION = 0x05, + SET_IF_STAGE = 0x06, + SET_TEST_MODE = 0x07, + SET_AGC_MODE = 0x08, + SET_DIRECT_SAMPLING = 0x09, + SET_OFFSET_TUNING = 0x0A, + SET_RTL_CRYSTAL = 0x0B, + SET_TUNER_CRYSTAL = 0x0C, + SET_TUNER_GAIN_BY_INDEX = 0x0D, + SET_TUNER_BANDWIDTH = 0x0E +}; + +#ifdef __cplusplus +} +#endif + +#endif \ No newline at end of file diff --git a/src/rtl_tcp.c b/src/rtl_tcp.c index 317e0f3..9f17bd8 100644 --- a/src/rtl_tcp.c +++ b/src/rtl_tcp.c @@ -94,6 +94,7 @@ void usage(void) "\t[-s samplerate in Hz (default: 2048000 Hz)]\n" "\t[-b number of buffers (default: 15, set by library)]\n" "\t[-n max number of linked list buffers to keep (default: 500)]\n" + "\t[-w rtlsdr device bandwidth (for R820T device)\n" "\t[-d device index (default: 0)]\n" "\t[-P ppm_error (default: 0)]\n"); exit(1); @@ -302,59 +303,63 @@ static void *command_worker(void *arg) } } switch(cmd.cmd) { - case 0x01: + case SET_FREQUENCY: printf("set freq %d\n", ntohl(cmd.param)); rtlsdr_set_center_freq(dev,ntohl(cmd.param)); break; - case 0x02: + case SET_SAMPLE_RATE: printf("set sample rate %d\n", ntohl(cmd.param)); rtlsdr_set_sample_rate(dev, ntohl(cmd.param)); break; - case 0x03: + case SET_GAIN_MODE: printf("set gain mode %d\n", ntohl(cmd.param)); rtlsdr_set_tuner_gain_mode(dev, ntohl(cmd.param)); break; - case 0x04: + case SET_GAIN: printf("set gain %d\n", ntohl(cmd.param)); rtlsdr_set_tuner_gain(dev, ntohl(cmd.param)); break; - case 0x05: + case SET_FREQUENCY_CORRECTION: printf("set freq correction %d\n", ntohl(cmd.param)); rtlsdr_set_freq_correction(dev, ntohl(cmd.param)); break; - case 0x06: + case SET_IF_STAGE: tmp = ntohl(cmd.param); printf("set if stage %d gain %d\n", tmp >> 16, (short)(tmp & 0xffff)); rtlsdr_set_tuner_if_gain(dev, tmp >> 16, (short)(tmp & 0xffff)); break; - case 0x07: + case SET_TEST_MODE: printf("set test mode %d\n", ntohl(cmd.param)); rtlsdr_set_testmode(dev, ntohl(cmd.param)); break; - case 0x08: + case SET_AGC_MODE: printf("set agc mode %d\n", ntohl(cmd.param)); rtlsdr_set_agc_mode(dev, ntohl(cmd.param)); break; - case 0x09: + case SET_DIRECT_SAMPLING: printf("set direct sampling %d\n", ntohl(cmd.param)); rtlsdr_set_direct_sampling(dev, ntohl(cmd.param)); break; - case 0x0a: + case SET_OFFSET_TUNING: printf("set offset tuning %d\n", ntohl(cmd.param)); rtlsdr_set_offset_tuning(dev, ntohl(cmd.param)); break; - case 0x0b: + case SET_RTL_CRYSTAL: printf("set rtl xtal %d\n", ntohl(cmd.param)); rtlsdr_set_xtal_freq(dev, ntohl(cmd.param), 0); break; - case 0x0c: + case SET_TUNER_CRYSTAL: printf("set tuner xtal %d\n", ntohl(cmd.param)); rtlsdr_set_xtal_freq(dev, 0, ntohl(cmd.param)); break; - case 0x0d: + case SET_TUNER_GAIN_BY_INDEX: printf("set tuner gain by index %d\n", ntohl(cmd.param)); set_gain_by_index(dev, ntohl(cmd.param)); break; + case SET_TUNER_BANDWIDTH: + printf("set tuner bandwidth to %i\n", ntohl(cmd.param)); + rtlsdr_set_tuner_bandwidth(dev, ntohl(cmd.param)); + break; default: break; } @@ -367,7 +372,7 @@ int main(int argc, char **argv) int r, opt, i; char* addr = "127.0.0.1"; int port = 1234; - uint32_t frequency = 100000000, samp_rate = 2048000; + uint32_t frequency = 100000000, samp_rate = 2048000, bandwidth = 0; struct sockaddr_in local, remote; uint32_t buf_num = 0; int dev_index = 0; @@ -391,7 +396,7 @@ int main(int argc, char **argv) struct sigaction sigact, sigign; #endif - while ((opt = getopt(argc, argv, "a:p:f:g:s:b:n:d:P:")) != -1) { + while ((opt = getopt(argc, argv, "a:p:f:g:s:b:n:d:P:w:")) != -1) { switch (opt) { case 'd': dev_index = verbose_device_search(optarg); @@ -420,6 +425,9 @@ int main(int argc, char **argv) break; case 'P': ppm_error = atoi(optarg); + break; + case 'w': + bandwidth = (uint32_t)atofs(optarg); break; default: usage(); @@ -491,6 +499,14 @@ int main(int argc, char **argv) fprintf(stderr, "Tuner gain set to %f dB.\n", gain/10.0); } + r = rtlsdr_set_tuner_bandwidth(dev, bandwidth); + if (r < 0) + fprintf(stderr, "WARNING: Failed to set tuner bandwidth.\n"); + else if (bandwidth != 0) + fprintf(stderr, "Tuner bandwidth set to %i.\n", bandwidth); + else + fprintf(stderr, "Tuner bandwidth set to automatic.\n"); + /* Reset endpoint before we start reading from it (mandatory) */ r = rtlsdr_reset_buffer(dev); if (r < 0)