diff --git a/README b/README index 7f042032..985a026c 100644 --- a/README +++ b/README @@ -4,3 +4,25 @@ turns your Realtek RTL2832 based DVB dongle into a SDR receiver For more information see: http://sdr.osmocom.org/trac/wiki/rtl-sdr + +====================================================================== + +Features added by me (MichelinoK): + +- Ability to enable RTL AGC in rtl_sdr +- Ability to enable RTL AGC in rtl_tcp (for those apps that doesn't support enabling it) + +Now in rtl_sdr and rtl_tcp you can use the "-X" switch to enable RTL AGC + +====================================================================== + +Suggested to compile this way: + +git clone https://github.com/michelinok/rtl-sdr.git +cd rtl-sdr +mkdir build +cd build +cmake ../ -DDETACH_KERNEL_DRIVER=ON -DINSTALL_UDEV_RULES=ON +make +sudo make install +sudo ldconfig diff --git a/src/convenience/convenience.c b/src/convenience/convenience.c index cc8a8bfc..d3d6ee02 100644 --- a/src/convenience/convenience.c +++ b/src/convenience/convenience.c @@ -136,6 +136,18 @@ int nearest_gain(rtlsdr_dev_t *dev, int target_gain) return nearest; } +int verbose_set_rtlagc(rtlsdr_dev_t *dev) +{ + int r; + r = rtlsdr_set_agc_mode(dev, 1); + if (r < 0) { + fprintf(stderr, "WARNING: Failed to set RTL AGC\n"); + } else { + fprintf(stderr, "RTL AGC enabled\n"); + } + return r; +} + int verbose_set_frequency(rtlsdr_dev_t *dev, uint32_t frequency) { int r; diff --git a/src/convenience/convenience.h b/src/convenience/convenience.h index 2daac787..85e986e3 100644 --- a/src/convenience/convenience.h +++ b/src/convenience/convenience.h @@ -149,3 +149,10 @@ int verbose_reset_buffer(rtlsdr_dev_t *dev); int verbose_device_search(char *s); +/*! +* Enable RTL AGC +* Mod by MichelinoK +* email: michele@computerteam.it +*/ + +int verbose_set_rtlagc(rtlsdr_dev_t *dev); diff --git a/src/rtl_sdr.c b/src/rtl_sdr.c index 984e09aa..af518743 100644 --- a/src/rtl_sdr.c +++ b/src/rtl_sdr.c @@ -57,6 +57,7 @@ void usage(void) "\t[-S force sync output (default: async)]\n" "\t[-D direct_sampling_mode, 0 (default/off), 1 (I), 2 (Q), 3 (no-mod)]\n" "\t[-N no dithering (default: use dithering)]\n" + "\t[-X enable RTL AGC]\n" "\tfilename (a '-' dumps samples to stdout)\n\n"); exit(1); } @@ -115,6 +116,7 @@ int main(int argc, char **argv) int gain = 0; int ppm_error = 0; int sync_mode = 0; + int rtlagc = 1; int direct_sampling = 0; int dithering = 1; FILE *file; @@ -125,12 +127,15 @@ int main(int argc, char **argv) uint32_t samp_rate = DEFAULT_SAMPLE_RATE; uint32_t out_block_size = DEFAULT_BUF_LENGTH; - while ((opt = getopt(argc, argv, "d:f:g:s:b:n:p:D:SN")) != -1) { + while ((opt = getopt(argc, argv, "d:f:g:s:b:n:p:D:SNX")) != -1) { switch (opt) { case 'd': dev_index = verbose_device_search(optarg); dev_given = 1; break; + case 'X': + rtlagc = 0; + break; case 'f': frequency = (uint32_t)atofs(optarg); break; @@ -222,6 +227,12 @@ int main(int argc, char **argv) verbose_direct_sampling(dev, direct_sampling); } + /* enable RTL_AGC */ + if (!rtlagc) { + fprintf(stderr,"Enabling RTL AGC\n"); + verbose_set_rtlagc(dev); + } + /* Set the sample rate */ verbose_set_sample_rate(dev, samp_rate); diff --git a/src/rtl_tcp.c b/src/rtl_tcp.c index 35eadac0..463b7ae5 100644 --- a/src/rtl_tcp.c +++ b/src/rtl_tcp.c @@ -95,7 +95,8 @@ void usage(void) "\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[-d device index (default: 0)]\n" - "\t[-P ppm_error (default: 0)]\n"); + "\t[-P ppm_error (default: 0)]\n" + "\t[-X enable RTL AGC]\n"); exit(1); } @@ -369,6 +370,7 @@ int main(int argc, char **argv) int dev_index = 0; int dev_given = 0; int gain = 0; + int rtlagc = 0; int ppm_error = 0; int custom_ppm = 0; struct llist *curelem,*prev; @@ -388,12 +390,15 @@ 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:X")) != -1) { switch (opt) { case 'd': dev_index = verbose_device_search(optarg); dev_given = 1; break; + case 'X': + rtlagc = 1; + break; case 'f': frequency = (uint32_t)atofs(optarg); break; @@ -473,6 +478,14 @@ int main(int argc, char **argv) else fprintf(stderr, "Tuned to %i Hz.\n", frequency); + /* enable RTL_AGC */ + if (rtlagc) { + fprintf(stderr,"Enabling RTL AGC\n"); + verbose_set_rtlagc(dev); + } + + + if (0 == gain) { /* Enable automatic gain */ r = rtlsdr_set_tuner_gain_mode(dev, 0);