Skip to content

Commit

Permalink
rtlsdr: fix bandwith option; rtl_adsb: added bandwidth option '-w'
Browse files Browse the repository at this point in the history
* allow units with rtl_sdr option '-n'
* fix application order for rtlsdr_set_opt_string()

Signed-off-by: hayati ayguen <[email protected]>
  • Loading branch information
hayguen committed Mar 22, 2024
1 parent d430e2e commit 1031aee
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 21 deletions.
19 changes: 13 additions & 6 deletions src/rtl_adsb.c
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@
#endif

#define ADSB_RATE 2000000
#define ADSB_BW 3000000
#define ADSB_FREQ 1090000000
#define DEFAULT_ASYNC_BUF_NUMBER 12
#define DEFAULT_BUF_LENGTH (16 * 16384)
Expand Down Expand Up @@ -383,6 +384,7 @@ int main(int argc, char **argv)
const char * rtlOpts = NULL;
int r, opt;
int gain = AUTO_GAIN; /* tenths of a dB */
uint32_t bandwidth = 0;
int dev_index = 0;
int dev_given = 0;
int ppm_error = 0;
Expand All @@ -391,7 +393,7 @@ int main(int argc, char **argv)
pthread_mutex_init(&ready_m, NULL);
squares_precompute();

while ((opt = getopt(argc, argv, "d:g:p:e:O:Q:VSTv")) != -1)
while ((opt = getopt(argc, argv, "d:g:w:p:e:O:Q:VSTv")) != -1)
{
switch (opt) {
case 'd':
Expand All @@ -404,6 +406,9 @@ int main(int argc, char **argv)
case 'g':
gain = (int)(atof(optarg) * 10);
break;
case 'w':
bandwidth = (uint32_t)atofs(optarg);
break;
case 'p':
ppm_error = atoi(optarg);
break;
Expand Down Expand Up @@ -491,17 +496,19 @@ int main(int argc, char **argv)
if (enable_biastee)
fprintf(stderr, "activated bias-T on GPIO PIN 0\n");

/* set - especially sideband - before testing tuning range */
if (rtlOpts) {
rtlsdr_set_opt_string(dev, rtlOpts, verbosity);
}

/* Set the tuner frequency */
verbose_set_frequency(dev, ADSB_FREQ);

/* Set the sample rate */
verbose_set_sample_rate(dev, ADSB_RATE);

/* Set the tuner bandwidth */
verbose_set_bandwidth(dev, bandwidth);

if (rtlOpts) {
rtlsdr_set_opt_string(dev, rtlOpts, verbosity);
}

/* Reset endpoint before we start reading from it (mandatory) */
verbose_reset_buffer(dev);

Expand Down
26 changes: 19 additions & 7 deletions src/rtl_sdr.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>

#ifndef _WIN32
#include <unistd.h>
Expand Down Expand Up @@ -191,8 +192,16 @@ int main(int argc, char **argv)
out_block_size = (uint32_t)atof(optarg);
break;
case 'n':
iq_frames_to_read = (uint32_t)atof(optarg);
{
double tmp_arg = atofs(optarg);
if (tmp_arg > UINT32_MAX) {
iq_frames_to_read = UINT32_MAX;
fprintf(stderr, "limited number of samples to record\n");
}
else
iq_frames_to_read = (uint32_t)tmp_arg;
break;
}
case 'S':
sync_mode = 1;
break;
Expand Down Expand Up @@ -268,11 +277,14 @@ int main(int argc, char **argv)
/* Set the sample rate */
verbose_set_sample_rate(dev, samp_rate);

/* Set the frequency */
verbose_set_frequency(dev, frequency);

/* Set the tuner bandwidth */
verbose_set_bandwidth(dev, bandwidth);

/* Set the frequency */
verbose_set_frequency(dev, frequency);
if (verbosity && bandwidth)
verbose_list_bandwidths(dev);

if (0 == gain) {
/* Enable automatic gain */
Expand All @@ -283,10 +295,6 @@ int main(int argc, char **argv)
verbose_gain_set(dev, gain);
}

if (rtlOpts) {
rtlsdr_set_opt_string(dev, rtlOpts, verbosity);
}

verbose_ppm_set(dev, ppm_error);

if(strcmp(filename, "-") == 0) { /* Write samples to stdout */
Expand All @@ -312,6 +320,10 @@ int main(int argc, char **argv)
}
}

if (rtlOpts) {
rtlsdr_set_opt_string(dev, rtlOpts, verbosity);
}

/* Reset endpoint before we start reading from it (mandatory) */
verbose_reset_buffer(dev);

Expand Down
8 changes: 4 additions & 4 deletions src/rtl_tcp.c
Original file line number Diff line number Diff line change
Expand Up @@ -897,10 +897,6 @@ int main(int argc, char **argv)
if (r < 0)
fprintf(stderr, "WARNING: Failed to set sample rate.\n");

if (rtlOpts) {
rtlsdr_set_opt_string(dev, rtlOpts, verbosity);
}

/* Set direct sampling with threshold */
rtlsdr_set_ds_mode(dev, ds_mode, ds_threshold);

Expand Down Expand Up @@ -935,6 +931,10 @@ int main(int argc, char **argv)
if (enable_biastee)
fprintf(stderr, "activated bias-T on GPIO PIN 0\n");

if (rtlOpts) {
rtlsdr_set_opt_string(dev, rtlOpts, verbosity);
}

/* Reset endpoint before we start reading from it (mandatory) */
r = rtlsdr_reset_buffer(dev);
if (r < 0)
Expand Down
8 changes: 4 additions & 4 deletions src/rtl_udp.c
Original file line number Diff line number Diff line change
Expand Up @@ -880,10 +880,6 @@ int main(int argc, char **argv)
if (r < 0)
fprintf(stderr, "WARNING: Failed to set sample rate.\n");

if (rtlOpts) {
rtlsdr_set_opt_string(dev, rtlOpts, verbosity);
}

/* Set direct sampling with threshold */
rtlsdr_set_ds_mode(dev, ds_mode, ds_threshold);

Expand Down Expand Up @@ -918,6 +914,10 @@ int main(int argc, char **argv)
if (enable_biastee)
fprintf(stderr, "activated bias-T on GPIO PIN 0\n");

if (rtlOpts) {
rtlsdr_set_opt_string(dev, rtlOpts, verbosity);
}

/* Reset endpoint before we start reading from it (mandatory) */
r = rtlsdr_reset_buffer(dev);
if (r < 0)
Expand Down

0 comments on commit 1031aee

Please sign in to comment.