From 8110549fee881a0b104b9003618f030d04492b3e Mon Sep 17 00:00:00 2001 From: matthewbrandes Date: Tue, 8 Jul 2014 15:12:46 -0500 Subject: [PATCH 1/8] Update dump1090.c --- dump1090.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dump1090.c b/dump1090.c index 286fb05..281ac0c 100644 --- a/dump1090.c +++ b/dump1090.c @@ -515,7 +515,7 @@ int main(int argc, char **argv) { int more = j+1 < argc; // There are more arguments if (!strcmp(argv[j],"--device-index") && more) { - Modes.dev_index = atoi(argv[++j]); + Modes.dev_index = verbose_device_search(argv[++j]); } else if (!strcmp(argv[j],"--gain") && more) { Modes.gain = (int) atof(argv[++j])*10; // Gain is in tens of DBs } else if (!strcmp(argv[j],"--enable-agc")) { From 50b05c538e02fb9d66a5e4fc47ed676462c46c60 Mon Sep 17 00:00:00 2001 From: matthewbrandes Date: Tue, 8 Jul 2014 16:54:30 -0500 Subject: [PATCH 2/8] Create convienience.h --- convienience.h | 150 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 150 insertions(+) create mode 100644 convienience.h diff --git a/convienience.h b/convienience.h new file mode 100644 index 0000000..e1244af --- /dev/null +++ b/convienience.h @@ -0,0 +1,150 @@ +/* + * Copyright (C) 2013-2014 by Kyle Keen + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +/* a collection of user friendly tools */ + +/*! + * Convert standard suffixes (k, M, G) to double + * + * \param s a string to be parsed + * \return double + */ + +double atofs(char *s); + +/*! + * Convert time suffixes (s, m, h) to double + * + * \param s a string to be parsed + * \return seconds as double + */ + +double atoft(char *s); + +/*! + * Convert percent suffixe (%) to double + * + * \param s a string to be parsed + * \return double + */ + +double atofp(char *s); + +/*! + * Find nearest supported gain + * + * \param dev the device handle given by rtlsdr_open() + * \param target_gain in tenths of a dB + * \return 0 on success + */ + +int nearest_gain(rtlsdr_dev_t *dev, int target_gain); + +/*! + * Set device frequency and report status on stderr + * + * \param dev the device handle given by rtlsdr_open() + * \param frequency in Hz + * \return 0 on success + */ + +int verbose_set_frequency(rtlsdr_dev_t *dev, uint32_t frequency); + +/*! + * Set device sample rate and report status on stderr + * + * \param dev the device handle given by rtlsdr_open() + * \param samp_rate in samples/second + * \return 0 on success + */ + +int verbose_set_sample_rate(rtlsdr_dev_t *dev, uint32_t samp_rate); + +/*! + * Enable or disable the direct sampling mode and report status on stderr + * + * \param dev the device handle given by rtlsdr_open() + * \param on 0 means disabled, 1 I-ADC input enabled, 2 Q-ADC input enabled + * \return 0 on success + */ + +int verbose_direct_sampling(rtlsdr_dev_t *dev, int on); + +/*! + * Enable offset tuning and report status on stderr + * + * \param dev the device handle given by rtlsdr_open() + * \return 0 on success + */ + +int verbose_offset_tuning(rtlsdr_dev_t *dev); + +/*! + * Enable auto gain and report status on stderr + * + * \param dev the device handle given by rtlsdr_open() + * \return 0 on success + */ + +int verbose_auto_gain(rtlsdr_dev_t *dev); + +/*! + * Set tuner gain and report status on stderr + * + * \param dev the device handle given by rtlsdr_open() + * \param gain in tenths of a dB + * \return 0 on success + */ + +int verbose_gain_set(rtlsdr_dev_t *dev, int gain); + +/*! + * Set the frequency correction value for the device and report status on stderr. + * + * \param dev the device handle given by rtlsdr_open() + * \param ppm_error correction value in parts per million (ppm) + * \return 0 on success + */ + +int verbose_ppm_set(rtlsdr_dev_t *dev, int ppm_error); + +/*! + * Attempts to extract a correction value from eeprom and store it to an int. + * + * \param dev the device handle given by rtlsdr_open() + * \param ppm_error correction value in parts per million (ppm) + * \return 0 on success + */ +int verbose_ppm_eeprom(rtlsdr_dev_t *dev, int *ppm_error); + +/*! + * Reset buffer + * + * \param dev the device handle given by rtlsdr_open() + * \return 0 on success + */ + +int verbose_reset_buffer(rtlsdr_dev_t *dev); + +/*! + * Find the closest matching device. + * + * \param s a string to be parsed + * \return dev_index int, -1 on error + */ + +int verbose_device_search(char *s); From a190677ad41125b88cf0c548ad1278d6e7a2a33f Mon Sep 17 00:00:00 2001 From: matthewbrandes Date: Tue, 8 Jul 2014 16:55:16 -0500 Subject: [PATCH 3/8] Create convienience.c --- convienience.c | 334 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 334 insertions(+) create mode 100644 convienience.c diff --git a/convienience.c b/convienience.c new file mode 100644 index 0000000..6565e1a --- /dev/null +++ b/convienience.c @@ -0,0 +1,334 @@ +/* + * Copyright (C) 2013-2014 by Kyle Keen + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +/* a collection of user friendly tools + * todo: use strtol for more flexible int parsing + * */ + +#include +#include +#include + +#ifndef _WIN32 +#include +#else +#include +#include +#include +#define _USE_MATH_DEFINES +#endif + +#include + +#include "rtl-sdr.h" + +double atofs(char *s) +/* standard suffixes */ +{ + char last; + int len; + double suff = 1.0; + len = strlen(s); + last = s[len-1]; + s[len-1] = '\0'; + switch (last) { + case 'g': + case 'G': + suff *= 1e3; + case 'm': + case 'M': + suff *= 1e3; + case 'k': + case 'K': + suff *= 1e3; + suff *= atof(s); + s[len-1] = last; + return suff; + } + s[len-1] = last; + return atof(s); +} + +double atoft(char *s) +/* time suffixes, returns seconds */ +{ + char last; + int len; + double suff = 1.0; + len = strlen(s); + last = s[len-1]; + s[len-1] = '\0'; + switch (last) { + case 'h': + case 'H': + suff *= 60; + case 'm': + case 'M': + suff *= 60; + case 's': + case 'S': + suff *= atof(s); + s[len-1] = last; + return suff; + } + s[len-1] = last; + return atof(s); +} + +double atofp(char *s) +/* percent suffixes */ +{ + char last; + int len; + double suff = 1.0; + len = strlen(s); + last = s[len-1]; + s[len-1] = '\0'; + switch (last) { + case '%': + suff *= 0.01; + suff *= atof(s); + s[len-1] = last; + return suff; + } + s[len-1] = last; + return atof(s); +} + +int nearest_gain(rtlsdr_dev_t *dev, int target_gain) +{ + int i, r, err1, err2, count, nearest; + int* gains; + r = rtlsdr_set_tuner_gain_mode(dev, 1); + if (r < 0) { + fprintf(stderr, "WARNING: Failed to enable manual gain.\n"); + return r; + } + count = rtlsdr_get_tuner_gains(dev, NULL); + if (count <= 0) { + return 0; + } + gains = malloc(sizeof(int) * count); + count = rtlsdr_get_tuner_gains(dev, gains); + nearest = gains[0]; + for (i=0; i=0; i--) { + if (serial[i] != start_char) { + continue;} + fprintf(stderr, "PPM calibration found in eeprom.\n"); + status = 0; + *ppm_error = atoi(serial + i + 1); + break; + } + serial[len-1] = stop_char; + return status; +} + +int verbose_reset_buffer(rtlsdr_dev_t *dev) +{ + int r; + r = rtlsdr_reset_buffer(dev); + if (r < 0) { + fprintf(stderr, "WARNING: Failed to reset buffers.\n");} + return r; +} + +int verbose_device_search(char *s) +{ + int i, device_count, device, offset; + char *s2; + char vendor[256], product[256], serial[256]; + device_count = rtlsdr_get_device_count(); + if (!device_count) { + fprintf(stderr, "No supported devices found.\n"); + return -1; + } + fprintf(stderr, "Found %d device(s):\n", device_count); + for (i = 0; i < device_count; i++) { + rtlsdr_get_device_usb_strings(i, vendor, product, serial); + fprintf(stderr, " %d: %s, %s, SN: %s\n", i, vendor, product, serial); + } + fprintf(stderr, "\n"); + /* does string look like raw id number */ + device = (int)strtol(s, &s2, 0); + if (s2[0] == '\0' && device >= 0 && device < device_count) { + fprintf(stderr, "Using device %d: %s\n", + device, rtlsdr_get_device_name((uint32_t)device)); + return device; + } + /* does string exact match a serial */ + for (i = 0; i < device_count; i++) { + rtlsdr_get_device_usb_strings(i, vendor, product, serial); + if (strcmp(s, serial) != 0) { + continue;} + device = i; + fprintf(stderr, "Using device %d: %s\n", + device, rtlsdr_get_device_name((uint32_t)device)); + return device; + } + /* does string prefix match a serial */ + for (i = 0; i < device_count; i++) { + rtlsdr_get_device_usb_strings(i, vendor, product, serial); + if (strncmp(s, serial, strlen(s)) != 0) { + continue;} + device = i; + fprintf(stderr, "Using device %d: %s\n", + device, rtlsdr_get_device_name((uint32_t)device)); + return device; + } + /* does string suffix match a serial */ + for (i = 0; i < device_count; i++) { + rtlsdr_get_device_usb_strings(i, vendor, product, serial); + offset = strlen(serial) - strlen(s); + if (offset < 0) { + continue;} + if (strncmp(s, serial+offset, strlen(s)) != 0) { + continue;} + device = i; + fprintf(stderr, "Using device %d: %s\n", + device, rtlsdr_get_device_name((uint32_t)device)); + return device; + } + fprintf(stderr, "No matching devices found.\n"); + return -1; +} + +// vim: tabstop=8:softtabstop=8:shiftwidth=8:noexpandtab From d0207569b6294e182aad07a1647ad433072ab65e Mon Sep 17 00:00:00 2001 From: matthewbrandes Date: Tue, 8 Jul 2014 16:56:03 -0500 Subject: [PATCH 4/8] Update dump1090.c --- dump1090.c | 1 + 1 file changed, 1 insertion(+) diff --git a/dump1090.c b/dump1090.c index 281ac0c..dfd962c 100644 --- a/dump1090.c +++ b/dump1090.c @@ -29,6 +29,7 @@ // #include "coaa.h" #include "dump1090.h" +#include "convienience.h // // ============================= Utility functions ========================== // From 652af93b88bad90ad8828b5ffdccd4a5722cde87 Mon Sep 17 00:00:00 2001 From: matthewbrandes Date: Tue, 8 Jul 2014 16:58:23 -0500 Subject: [PATCH 5/8] Update dump1090.c --- dump1090.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dump1090.c b/dump1090.c index dfd962c..fcfaa6e 100644 --- a/dump1090.c +++ b/dump1090.c @@ -29,7 +29,7 @@ // #include "coaa.h" #include "dump1090.h" -#include "convienience.h +#include "convienience.h" // // ============================= Utility functions ========================== // From 3043e860964bed3144b3bdc2d0ce9b23920b9bb1 Mon Sep 17 00:00:00 2001 From: matthewbrandes Date: Tue, 8 Jul 2014 17:32:16 -0500 Subject: [PATCH 6/8] Delete convienience.h --- convienience.h | 150 ------------------------------------------------- 1 file changed, 150 deletions(-) delete mode 100644 convienience.h diff --git a/convienience.h b/convienience.h deleted file mode 100644 index e1244af..0000000 --- a/convienience.h +++ /dev/null @@ -1,150 +0,0 @@ -/* - * Copyright (C) 2013-2014 by Kyle Keen - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -/* a collection of user friendly tools */ - -/*! - * Convert standard suffixes (k, M, G) to double - * - * \param s a string to be parsed - * \return double - */ - -double atofs(char *s); - -/*! - * Convert time suffixes (s, m, h) to double - * - * \param s a string to be parsed - * \return seconds as double - */ - -double atoft(char *s); - -/*! - * Convert percent suffixe (%) to double - * - * \param s a string to be parsed - * \return double - */ - -double atofp(char *s); - -/*! - * Find nearest supported gain - * - * \param dev the device handle given by rtlsdr_open() - * \param target_gain in tenths of a dB - * \return 0 on success - */ - -int nearest_gain(rtlsdr_dev_t *dev, int target_gain); - -/*! - * Set device frequency and report status on stderr - * - * \param dev the device handle given by rtlsdr_open() - * \param frequency in Hz - * \return 0 on success - */ - -int verbose_set_frequency(rtlsdr_dev_t *dev, uint32_t frequency); - -/*! - * Set device sample rate and report status on stderr - * - * \param dev the device handle given by rtlsdr_open() - * \param samp_rate in samples/second - * \return 0 on success - */ - -int verbose_set_sample_rate(rtlsdr_dev_t *dev, uint32_t samp_rate); - -/*! - * Enable or disable the direct sampling mode and report status on stderr - * - * \param dev the device handle given by rtlsdr_open() - * \param on 0 means disabled, 1 I-ADC input enabled, 2 Q-ADC input enabled - * \return 0 on success - */ - -int verbose_direct_sampling(rtlsdr_dev_t *dev, int on); - -/*! - * Enable offset tuning and report status on stderr - * - * \param dev the device handle given by rtlsdr_open() - * \return 0 on success - */ - -int verbose_offset_tuning(rtlsdr_dev_t *dev); - -/*! - * Enable auto gain and report status on stderr - * - * \param dev the device handle given by rtlsdr_open() - * \return 0 on success - */ - -int verbose_auto_gain(rtlsdr_dev_t *dev); - -/*! - * Set tuner gain and report status on stderr - * - * \param dev the device handle given by rtlsdr_open() - * \param gain in tenths of a dB - * \return 0 on success - */ - -int verbose_gain_set(rtlsdr_dev_t *dev, int gain); - -/*! - * Set the frequency correction value for the device and report status on stderr. - * - * \param dev the device handle given by rtlsdr_open() - * \param ppm_error correction value in parts per million (ppm) - * \return 0 on success - */ - -int verbose_ppm_set(rtlsdr_dev_t *dev, int ppm_error); - -/*! - * Attempts to extract a correction value from eeprom and store it to an int. - * - * \param dev the device handle given by rtlsdr_open() - * \param ppm_error correction value in parts per million (ppm) - * \return 0 on success - */ -int verbose_ppm_eeprom(rtlsdr_dev_t *dev, int *ppm_error); - -/*! - * Reset buffer - * - * \param dev the device handle given by rtlsdr_open() - * \return 0 on success - */ - -int verbose_reset_buffer(rtlsdr_dev_t *dev); - -/*! - * Find the closest matching device. - * - * \param s a string to be parsed - * \return dev_index int, -1 on error - */ - -int verbose_device_search(char *s); From c80582274b86b81628e1a6a2fdcf057b87d92d14 Mon Sep 17 00:00:00 2001 From: matthewbrandes Date: Tue, 8 Jul 2014 17:32:30 -0500 Subject: [PATCH 7/8] Delete convienience.c --- convienience.c | 334 ------------------------------------------------- 1 file changed, 334 deletions(-) delete mode 100644 convienience.c diff --git a/convienience.c b/convienience.c deleted file mode 100644 index 6565e1a..0000000 --- a/convienience.c +++ /dev/null @@ -1,334 +0,0 @@ -/* - * Copyright (C) 2013-2014 by Kyle Keen - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -/* a collection of user friendly tools - * todo: use strtol for more flexible int parsing - * */ - -#include -#include -#include - -#ifndef _WIN32 -#include -#else -#include -#include -#include -#define _USE_MATH_DEFINES -#endif - -#include - -#include "rtl-sdr.h" - -double atofs(char *s) -/* standard suffixes */ -{ - char last; - int len; - double suff = 1.0; - len = strlen(s); - last = s[len-1]; - s[len-1] = '\0'; - switch (last) { - case 'g': - case 'G': - suff *= 1e3; - case 'm': - case 'M': - suff *= 1e3; - case 'k': - case 'K': - suff *= 1e3; - suff *= atof(s); - s[len-1] = last; - return suff; - } - s[len-1] = last; - return atof(s); -} - -double atoft(char *s) -/* time suffixes, returns seconds */ -{ - char last; - int len; - double suff = 1.0; - len = strlen(s); - last = s[len-1]; - s[len-1] = '\0'; - switch (last) { - case 'h': - case 'H': - suff *= 60; - case 'm': - case 'M': - suff *= 60; - case 's': - case 'S': - suff *= atof(s); - s[len-1] = last; - return suff; - } - s[len-1] = last; - return atof(s); -} - -double atofp(char *s) -/* percent suffixes */ -{ - char last; - int len; - double suff = 1.0; - len = strlen(s); - last = s[len-1]; - s[len-1] = '\0'; - switch (last) { - case '%': - suff *= 0.01; - suff *= atof(s); - s[len-1] = last; - return suff; - } - s[len-1] = last; - return atof(s); -} - -int nearest_gain(rtlsdr_dev_t *dev, int target_gain) -{ - int i, r, err1, err2, count, nearest; - int* gains; - r = rtlsdr_set_tuner_gain_mode(dev, 1); - if (r < 0) { - fprintf(stderr, "WARNING: Failed to enable manual gain.\n"); - return r; - } - count = rtlsdr_get_tuner_gains(dev, NULL); - if (count <= 0) { - return 0; - } - gains = malloc(sizeof(int) * count); - count = rtlsdr_get_tuner_gains(dev, gains); - nearest = gains[0]; - for (i=0; i=0; i--) { - if (serial[i] != start_char) { - continue;} - fprintf(stderr, "PPM calibration found in eeprom.\n"); - status = 0; - *ppm_error = atoi(serial + i + 1); - break; - } - serial[len-1] = stop_char; - return status; -} - -int verbose_reset_buffer(rtlsdr_dev_t *dev) -{ - int r; - r = rtlsdr_reset_buffer(dev); - if (r < 0) { - fprintf(stderr, "WARNING: Failed to reset buffers.\n");} - return r; -} - -int verbose_device_search(char *s) -{ - int i, device_count, device, offset; - char *s2; - char vendor[256], product[256], serial[256]; - device_count = rtlsdr_get_device_count(); - if (!device_count) { - fprintf(stderr, "No supported devices found.\n"); - return -1; - } - fprintf(stderr, "Found %d device(s):\n", device_count); - for (i = 0; i < device_count; i++) { - rtlsdr_get_device_usb_strings(i, vendor, product, serial); - fprintf(stderr, " %d: %s, %s, SN: %s\n", i, vendor, product, serial); - } - fprintf(stderr, "\n"); - /* does string look like raw id number */ - device = (int)strtol(s, &s2, 0); - if (s2[0] == '\0' && device >= 0 && device < device_count) { - fprintf(stderr, "Using device %d: %s\n", - device, rtlsdr_get_device_name((uint32_t)device)); - return device; - } - /* does string exact match a serial */ - for (i = 0; i < device_count; i++) { - rtlsdr_get_device_usb_strings(i, vendor, product, serial); - if (strcmp(s, serial) != 0) { - continue;} - device = i; - fprintf(stderr, "Using device %d: %s\n", - device, rtlsdr_get_device_name((uint32_t)device)); - return device; - } - /* does string prefix match a serial */ - for (i = 0; i < device_count; i++) { - rtlsdr_get_device_usb_strings(i, vendor, product, serial); - if (strncmp(s, serial, strlen(s)) != 0) { - continue;} - device = i; - fprintf(stderr, "Using device %d: %s\n", - device, rtlsdr_get_device_name((uint32_t)device)); - return device; - } - /* does string suffix match a serial */ - for (i = 0; i < device_count; i++) { - rtlsdr_get_device_usb_strings(i, vendor, product, serial); - offset = strlen(serial) - strlen(s); - if (offset < 0) { - continue;} - if (strncmp(s, serial+offset, strlen(s)) != 0) { - continue;} - device = i; - fprintf(stderr, "Using device %d: %s\n", - device, rtlsdr_get_device_name((uint32_t)device)); - return device; - } - fprintf(stderr, "No matching devices found.\n"); - return -1; -} - -// vim: tabstop=8:softtabstop=8:shiftwidth=8:noexpandtab From 6f14ecf7dd7b0b28b6fb6469d96be12b25ec2771 Mon Sep 17 00:00:00 2001 From: matthewbrandes Date: Tue, 8 Jul 2014 17:34:43 -0500 Subject: [PATCH 8/8] Update dump1090.c --- dump1090.c | 63 +++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 62 insertions(+), 1 deletion(-) diff --git a/dump1090.c b/dump1090.c index fcfaa6e..bbe408e 100644 --- a/dump1090.c +++ b/dump1090.c @@ -29,7 +29,6 @@ // #include "coaa.h" #include "dump1090.h" -#include "convienience.h" // // ============================= Utility functions ========================== // @@ -504,6 +503,68 @@ void backgroundTasks(void) { // //========================================================================= // +int verbose_device_search(char *s) +{ + int i, device_count, device, offset; + char *s2; + char vendor[256], product[256], serial[256]; + device_count = rtlsdr_get_device_count(); + if (!device_count) { + fprintf(stderr, "No supported devices found.\n"); + return -1; + } + fprintf(stderr, "Found %d device(s):\n", device_count); + for (i = 0; i < device_count; i++) { + rtlsdr_get_device_usb_strings(i, vendor, product, serial); + fprintf(stderr, " %d: %s, %s, SN: %s\n", i, vendor, product, serial); + } + fprintf(stderr, "\n"); + /* does string look like raw id number */ + device = (int)strtol(s, &s2, 0); + if (s2[0] == '\0' && device >= 0 && device < device_count) { + fprintf(stderr, "Using device %d: %s\n", + device, rtlsdr_get_device_name((uint32_t)device)); + return device; + } + /* does string exact match a serial */ + for (i = 0; i < device_count; i++) { + rtlsdr_get_device_usb_strings(i, vendor, product, serial); + if (strcmp(s, serial) != 0) { + continue;} + device = i; + fprintf(stderr, "Using device %d: %s\n", + device, rtlsdr_get_device_name((uint32_t)device)); + return device; + } + /* does string prefix match a serial */ + for (i = 0; i < device_count; i++) { + rtlsdr_get_device_usb_strings(i, vendor, product, serial); + if (strncmp(s, serial, strlen(s)) != 0) { + continue;} + device = i; + fprintf(stderr, "Using device %d: %s\n", + device, rtlsdr_get_device_name((uint32_t)device)); + return device; + } + /* does string suffix match a serial */ + for (i = 0; i < device_count; i++) { + rtlsdr_get_device_usb_strings(i, vendor, product, serial); + offset = strlen(serial) - strlen(s); + if (offset < 0) { + continue;} + if (strncmp(s, serial+offset, strlen(s)) != 0) { + continue;} + device = i; + fprintf(stderr, "Using device %d: %s\n", + device, rtlsdr_get_device_name((uint32_t)device)); + return device; + } + fprintf(stderr, "No matching devices found.\n"); + return -1; +} +// +//========================================================================= +// int main(int argc, char **argv) { int j;