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
master
Lucas Teske 2016-03-06 01:09:59 -03:00
parent cee5d10200
commit ba43a14e92
4 changed files with 92 additions and 15 deletions

9
.gitignore vendored
View File

@ -41,4 +41,13 @@ CMakeFiles
*.cmake *.cmake
build build
**/*.o
**/*.so*
**/*.a
src/rtl_adsb
src/rtl_eeprom
src/rtl_fm
src/rtl_power
src/rtl_test
debianize/*.deb debianize/*.deb

View File

@ -26,6 +26,7 @@ extern "C" {
#include <stdint.h> #include <stdint.h>
#include <rtl-sdr_export.h> #include <rtl-sdr_export.h>
#include <rtl_tcp.h>
typedef struct rtlsdr_dev rtlsdr_dev_t; typedef struct rtlsdr_dev rtlsdr_dev_t;

51
include/rtl_tcp.h 100644
View File

@ -0,0 +1,51 @@
/*
* rtl-sdr, turns your Realtek RTL2832 based DVB dongle into a SDR receiver
* Copyright (C) 2012-2013 by Steve Markgraf <steve@steve-m.de>
* Copyright (C) 2012 by Dimitri Stolnikov <horiz0n@gmx.net>
*
* 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 <http://www.gnu.org/licenses/>.
*/
#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

View File

@ -94,6 +94,7 @@ void usage(void)
"\t[-s samplerate in Hz (default: 2048000 Hz)]\n" "\t[-s samplerate in Hz (default: 2048000 Hz)]\n"
"\t[-b number of buffers (default: 15, set by library)]\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[-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[-d device index (default: 0)]\n"
"\t[-P ppm_error (default: 0)]\n"); "\t[-P ppm_error (default: 0)]\n");
exit(1); exit(1);
@ -302,59 +303,63 @@ static void *command_worker(void *arg)
} }
} }
switch(cmd.cmd) { switch(cmd.cmd) {
case 0x01: case SET_FREQUENCY:
printf("set freq %d\n", ntohl(cmd.param)); printf("set freq %d\n", ntohl(cmd.param));
rtlsdr_set_center_freq(dev,ntohl(cmd.param)); rtlsdr_set_center_freq(dev,ntohl(cmd.param));
break; break;
case 0x02: case SET_SAMPLE_RATE:
printf("set sample rate %d\n", ntohl(cmd.param)); printf("set sample rate %d\n", ntohl(cmd.param));
rtlsdr_set_sample_rate(dev, ntohl(cmd.param)); rtlsdr_set_sample_rate(dev, ntohl(cmd.param));
break; break;
case 0x03: case SET_GAIN_MODE:
printf("set gain mode %d\n", ntohl(cmd.param)); printf("set gain mode %d\n", ntohl(cmd.param));
rtlsdr_set_tuner_gain_mode(dev, ntohl(cmd.param)); rtlsdr_set_tuner_gain_mode(dev, ntohl(cmd.param));
break; break;
case 0x04: case SET_GAIN:
printf("set gain %d\n", ntohl(cmd.param)); printf("set gain %d\n", ntohl(cmd.param));
rtlsdr_set_tuner_gain(dev, ntohl(cmd.param)); rtlsdr_set_tuner_gain(dev, ntohl(cmd.param));
break; break;
case 0x05: case SET_FREQUENCY_CORRECTION:
printf("set freq correction %d\n", ntohl(cmd.param)); printf("set freq correction %d\n", ntohl(cmd.param));
rtlsdr_set_freq_correction(dev, ntohl(cmd.param)); rtlsdr_set_freq_correction(dev, ntohl(cmd.param));
break; break;
case 0x06: case SET_IF_STAGE:
tmp = ntohl(cmd.param); tmp = ntohl(cmd.param);
printf("set if stage %d gain %d\n", tmp >> 16, (short)(tmp & 0xffff)); printf("set if stage %d gain %d\n", tmp >> 16, (short)(tmp & 0xffff));
rtlsdr_set_tuner_if_gain(dev, tmp >> 16, (short)(tmp & 0xffff)); rtlsdr_set_tuner_if_gain(dev, tmp >> 16, (short)(tmp & 0xffff));
break; break;
case 0x07: case SET_TEST_MODE:
printf("set test mode %d\n", ntohl(cmd.param)); printf("set test mode %d\n", ntohl(cmd.param));
rtlsdr_set_testmode(dev, ntohl(cmd.param)); rtlsdr_set_testmode(dev, ntohl(cmd.param));
break; break;
case 0x08: case SET_AGC_MODE:
printf("set agc mode %d\n", ntohl(cmd.param)); printf("set agc mode %d\n", ntohl(cmd.param));
rtlsdr_set_agc_mode(dev, ntohl(cmd.param)); rtlsdr_set_agc_mode(dev, ntohl(cmd.param));
break; break;
case 0x09: case SET_DIRECT_SAMPLING:
printf("set direct sampling %d\n", ntohl(cmd.param)); printf("set direct sampling %d\n", ntohl(cmd.param));
rtlsdr_set_direct_sampling(dev, ntohl(cmd.param)); rtlsdr_set_direct_sampling(dev, ntohl(cmd.param));
break; break;
case 0x0a: case SET_OFFSET_TUNING:
printf("set offset tuning %d\n", ntohl(cmd.param)); printf("set offset tuning %d\n", ntohl(cmd.param));
rtlsdr_set_offset_tuning(dev, ntohl(cmd.param)); rtlsdr_set_offset_tuning(dev, ntohl(cmd.param));
break; break;
case 0x0b: case SET_RTL_CRYSTAL:
printf("set rtl xtal %d\n", ntohl(cmd.param)); printf("set rtl xtal %d\n", ntohl(cmd.param));
rtlsdr_set_xtal_freq(dev, ntohl(cmd.param), 0); rtlsdr_set_xtal_freq(dev, ntohl(cmd.param), 0);
break; break;
case 0x0c: case SET_TUNER_CRYSTAL:
printf("set tuner xtal %d\n", ntohl(cmd.param)); printf("set tuner xtal %d\n", ntohl(cmd.param));
rtlsdr_set_xtal_freq(dev, 0, ntohl(cmd.param)); rtlsdr_set_xtal_freq(dev, 0, ntohl(cmd.param));
break; break;
case 0x0d: case SET_TUNER_GAIN_BY_INDEX:
printf("set tuner gain by index %d\n", ntohl(cmd.param)); printf("set tuner gain by index %d\n", ntohl(cmd.param));
set_gain_by_index(dev, ntohl(cmd.param)); set_gain_by_index(dev, ntohl(cmd.param));
break; 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: default:
break; break;
} }
@ -367,7 +372,7 @@ int main(int argc, char **argv)
int r, opt, i; int r, opt, i;
char* addr = "127.0.0.1"; char* addr = "127.0.0.1";
int port = 1234; int port = 1234;
uint32_t frequency = 100000000, samp_rate = 2048000; uint32_t frequency = 100000000, samp_rate = 2048000, bandwidth = 0;
struct sockaddr_in local, remote; struct sockaddr_in local, remote;
uint32_t buf_num = 0; uint32_t buf_num = 0;
int dev_index = 0; int dev_index = 0;
@ -391,7 +396,7 @@ int main(int argc, char **argv)
struct sigaction sigact, sigign; struct sigaction sigact, sigign;
#endif #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) { switch (opt) {
case 'd': case 'd':
dev_index = verbose_device_search(optarg); dev_index = verbose_device_search(optarg);
@ -420,6 +425,9 @@ int main(int argc, char **argv)
break; break;
case 'P': case 'P':
ppm_error = atoi(optarg); ppm_error = atoi(optarg);
break;
case 'w':
bandwidth = (uint32_t)atofs(optarg);
break; break;
default: default:
usage(); usage();
@ -491,6 +499,14 @@ int main(int argc, char **argv)
fprintf(stderr, "Tuner gain set to %f dB.\n", gain/10.0); 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) */ /* Reset endpoint before we start reading from it (mandatory) */
r = rtlsdr_reset_buffer(dev); r = rtlsdr_reset_buffer(dev);
if (r < 0) if (r < 0)