Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added the ability to use RTL AGC in rtl_sdr #15

Open
wants to merge 14 commits into
base: master
Choose a base branch
from
22 changes: 22 additions & 0 deletions README
Original file line number Diff line number Diff line change
Expand Up @@ -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
12 changes: 12 additions & 0 deletions src/convenience/convenience.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
7 changes: 7 additions & 0 deletions src/convenience/convenience.h
Original file line number Diff line number Diff line change
Expand Up @@ -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: [email protected]
*/

int verbose_set_rtlagc(rtlsdr_dev_t *dev);
13 changes: 12 additions & 1 deletion src/rtl_sdr.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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);

Expand Down
17 changes: 15 additions & 2 deletions src/rtl_tcp.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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);
Expand Down