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

Allow device to be selected by serial, overriding the selection by index #177

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions dump1090.c
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@ struct {

/* RTLSDR */
int dev_index;
char* serial;
int gain;
int enable_agc;
rtlsdr_dev_t *dev;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -344,6 +346,10 @@ void modesInitRTLSDR(void) {
fprintf(stderr, "No supported RTLSDR devices found.\n");
exit(1);
}
if(Modes.serial != NULL){
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);
for (j = 0; j < device_count; j++) {
Expand Down Expand Up @@ -2439,6 +2445,7 @@ int getTermRows() {
void showHelp(void) {
printf(
"--device-index <index> Select RTL device (default: 0).\n"
"--device-serial <serial> Select RTL device by USB serial number.\n"
"--gain <db> Set gain (default: max gain. Use -100 for auto-gain).\n"
"--enable-agc Enable the Automatic Gain Control (default: off).\n"
"--freq <hz> Set frequency (default: 1090 Mhz).\n"
Expand Down Expand Up @@ -2507,6 +2514,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")) {
Expand Down