From f3e498a62a1eeabd1665eea98f3cc6dd79949ab8 Mon Sep 17 00:00:00 2001 From: Oliver Jowett Date: Mon, 19 Jul 2021 17:32:51 +0800 Subject: [PATCH] Treat the magic agc setting as just another gain step. The legacy -10 value is still supported for compatbility with old configs, but new configs should just select an appropriate gain e.g. 60dB. rtlsdr default gain continues to be the highest regular gain step (~ 49.6dB) --- debian/upgrade-config | 3 +++ dump1090.c | 4 ++-- dump1090.h | 4 ++-- sdr_rtlsdr.c | 8 ++++---- 4 files changed, 11 insertions(+), 8 deletions(-) diff --git a/debian/upgrade-config b/debian/upgrade-config index 6c42ec7..7622867 100755 --- a/debian/upgrade-config +++ b/debian/upgrade-config @@ -102,6 +102,9 @@ if [ "${EXTRAS_NET_RO_INTERVAL:-1300}" != "0.2" ]; then EXTRA_OPTIONS="$EXTRA_OP # special case for device index 0 (the default) if [ "${RECEIVER_SERIAL}" = "0" ]; then RECEIVER_SERIAL=""; fi +# special case for gain -10 -> gain 60 +if [ "${RECEIVER_GAIN}" = "-10" ]; then RECEIVER_GAIN="60"; fi + # special case for ports set to zero (new config uses a blank entry for that) if [ "${NET_RAW_INPUT_PORTS}" = "0" ]; then NET_RAW_INPUT_PORTS=""; fi if [ "${NET_RAW_OUTPUT_PORTS}" = "0" ]; then NET_RAW_OUTPUT_PORTS=""; fi diff --git a/dump1090.c b/dump1090.c index ce9e242..1af16c4 100644 --- a/dump1090.c +++ b/dump1090.c @@ -110,7 +110,7 @@ static void modesInitConfig(void) { memset(&Modes, 0, sizeof(Modes)); // Now initialise things that should not be 0/NULL to their defaults - Modes.gain = MODES_MAX_GAIN; + Modes.gain = MODES_DEFAULT_GAIN; Modes.freq = MODES_DEFAULT_FREQ; Modes.check_crc = 1; Modes.fix_df = 1; @@ -340,7 +340,7 @@ static void showHelp(void) " Decoder settings\n" "\n" // ------ 80 char limit ----------------------------------------------------------| -"--gain Set gain (default: max gain. Use -10 for auto-gain)\n" +"--gain Set gain in dB (default: varies by SDR type)\n" "--freq Set frequency (default: 1090 Mhz)\n" "--fix Enable single-bit error correction using CRC\n" "--fix-2bit Enable two-bit error correction using CRC\n" diff --git a/dump1090.h b/dump1090.h index 8bf6918..2beeea7 100644 --- a/dump1090.h +++ b/dump1090.h @@ -92,8 +92,8 @@ #define MODES_RTL_BUF_SIZE (16*16384) // 256k #define MODES_MAG_BUF_SAMPLES (MODES_RTL_BUF_SIZE / 2) // Each sample is 2 bytes #define MODES_MAG_BUFFERS 12 // Number of magnitude buffers (should be smaller than RTL_BUFFERS for flowcontrol to work) -#define MODES_AUTO_GAIN -10 // Use automatic gain -#define MODES_MAX_GAIN 999999 // Use max available gain +#define MODES_LEGACY_AUTO_GAIN -10 // old gain value for "use automatic gain" +#define MODES_DEFAULT_GAIN 999999 // Use default SDR gain #define MODES_MSG_SQUELCH_DB 4.0 // Minimum SNR, in dB #define MODES_MSG_ENCODER_ERRS 3 // Maximum number of encoding errors diff --git a/sdr_rtlsdr.c b/sdr_rtlsdr.c index e7a8c5f..33f4297 100644 --- a/sdr_rtlsdr.c +++ b/sdr_rtlsdr.c @@ -255,17 +255,17 @@ bool rtlsdrOpen(void) RTLSDR.gains = gains; int selected = -1; - if (Modes.gain == MODES_AUTO_GAIN) { + if (Modes.gain == MODES_LEGACY_AUTO_GAIN) { selected = numgains; - } else if (Modes.gain == MODES_MAX_GAIN) { + } else if (Modes.gain == MODES_DEFAULT_GAIN) { selected = numgains - 1; } else { - for (int i = 0; i < numgains; ++i) { + for (int i = 0; i <= numgains; ++i) { if (selected == -1 || fabs(gains[i]/10.0 - Modes.gain) < fabs(gains[selected]/10.0 - Modes.gain)) selected = i; } } - + rtlsdrSetGain(selected); }