From 286f12cc55d635ade0b945e41ab06cd43e5f2155 Mon Sep 17 00:00:00 2001 From: Derry Hamilton Date: Thu, 16 Nov 2023 15:04:36 +0000 Subject: [PATCH 1/2] Allow device to be selected by serial, overriding the selection by index --- dump1090.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/dump1090.c b/dump1090.c index 8e84a60ac..76964b3de 100644 --- a/dump1090.c +++ b/dump1090.c @@ -139,6 +139,7 @@ struct { /* RTLSDR */ int dev_index; + char* serial; int gain; int enable_agc; rtlsdr_dev_t *dev; @@ -260,6 +261,7 @@ static long long mstime(void) { void modesInitConfig(void) { Modes.gain = MODES_MAX_GAIN; Modes.dev_index = 0; + Modes.serial = NULL; Modes.enable_agc = 0; Modes.freq = MODES_DEFAULT_FREQ; Modes.filename = NULL; @@ -344,6 +346,15 @@ void modesInitRTLSDR(void) { fprintf(stderr, "No supported RTLSDR devices found.\n"); exit(1); } + if(Modes.serial != NULL){ + for (j = 0; j < device_count; j++) { + rtlsdr_get_device_usb_strings(j, vendor, product, serial); + if(0 == strcmp(Modes.serial,serial)){ + printf("Found device with serial %s; selecting device index %d\n",Modes.serial,j); + Modes.dev_index = j; + } + } + } fprintf(stderr, "Found %d device(s):\n", device_count); for (j = 0; j < device_count; j++) { @@ -2439,6 +2450,7 @@ int getTermRows() { void showHelp(void) { printf( "--device-index Select RTL device (default: 0).\n" +"--device-serial Select RTL device by USB serial number.\n" "--gain Set gain (default: max gain. Use -100 for auto-gain).\n" "--enable-agc Enable the Automatic Gain Control (default: off).\n" "--freq Set frequency (default: 1090 Mhz).\n" @@ -2507,6 +2519,8 @@ int main(int argc, char **argv) { if (!strcmp(argv[j],"--device-index") && more) { Modes.dev_index = atoi(argv[++j]); + } else if (!strcmp(argv[j],"--device-serial") && more) { + Modes.serial = argv[++j]; } else if (!strcmp(argv[j],"--gain") && more) { Modes.gain = atof(argv[++j])*10; /* Gain is in tens of DBs */ } else if (!strcmp(argv[j],"--enable-agc")) { From ae57e25a9a51e49a2b82a7de2612dda22f11adb3 Mon Sep 17 00:00:00 2001 From: Derry Hamilton Date: Thu, 16 Nov 2023 16:29:04 +0000 Subject: [PATCH 2/2] Use the rtl_sdr unil function instead --- dump1090.c | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/dump1090.c b/dump1090.c index 76964b3de..7dc83339a 100644 --- a/dump1090.c +++ b/dump1090.c @@ -347,13 +347,8 @@ void modesInitRTLSDR(void) { exit(1); } if(Modes.serial != NULL){ - for (j = 0; j < device_count; j++) { - rtlsdr_get_device_usb_strings(j, vendor, product, serial); - if(0 == strcmp(Modes.serial,serial)){ - printf("Found device with serial %s; selecting device index %d\n",Modes.serial,j); - Modes.dev_index = j; - } - } + Modes.dev_index = rtlsdr_get_index_by_serial(Modes.serial); + printf("Found device with serial %s; selecting device index %d\n",Modes.serial,Modes.dev_index); } fprintf(stderr, "Found %d device(s):\n", device_count);