From feeb7a9c95e3bdfb416305b1c70e232fdf5b2fc4 Mon Sep 17 00:00:00 2001 From: Dominic Spill Date: Fri, 3 Feb 2017 10:20:23 -0700 Subject: [PATCH] Add selection by device serial number to rffc5071 and max2837 tools --- host/hackrf-tools/src/hackrf_max2837.c | 11 +++++++++-- host/hackrf-tools/src/hackrf_operacake.c | 5 ----- host/hackrf-tools/src/hackrf_rffc5071.c | 10 ++++++++-- 3 files changed, 17 insertions(+), 9 deletions(-) diff --git a/host/hackrf-tools/src/hackrf_max2837.c b/host/hackrf-tools/src/hackrf_max2837.c index d09a7557..f52ca9e1 100644 --- a/host/hackrf-tools/src/hackrf_max2837.c +++ b/host/hackrf-tools/src/hackrf_max2837.c @@ -38,6 +38,7 @@ static void usage() { printf("\t-n, --register : set register number for read/write operations\n"); printf("\t-r, --read: read register specified by last -n argument, or all registers\n"); printf("\t-w, --write : write register specified by last -n argument with value \n"); + printf("\t-d, --device : specify a particular device by serial number\n"); printf("\nExamples:\n"); printf("\t -n 12 -r # reads from register 12\n"); printf("\t -r # reads all registers\n"); @@ -48,6 +49,7 @@ static struct option long_options[] = { { "register", required_argument, 0, 'n' }, { "write", required_argument, 0, 'w' }, { "read", no_argument, 0, 'r' }, + { "device", no_argument, 0, 'd' }, { "help", no_argument, 0, 'h' }, { 0, 0, 0, 0 }, }; @@ -133,6 +135,7 @@ int main(int argc, char** argv) { int option_index = 0; bool read = false; bool write = false; + const char* serial_number = NULL; int result = hackrf_init(); if( result ) { @@ -140,7 +143,7 @@ int main(int argc, char** argv) { return EXIT_FAILURE; } - while( (opt = getopt_long(argc, argv, "n:rw:h?", long_options, &option_index)) != EOF ) { + while( (opt = getopt_long(argc, argv, "n:rw:d:h?", long_options, &option_index)) != EOF ) { switch( opt ) { case 'n': result = parse_int(optarg, ®ister_number); @@ -155,6 +158,10 @@ int main(int argc, char** argv) { read = true; break; + case 'd': + serial_number = optarg; + break; + case 'h': case '?': usage(); @@ -184,7 +191,7 @@ int main(int argc, char** argv) { return EXIT_FAILURE; } - result = hackrf_open(&device); + result = hackrf_open_by_serial(serial_number, &device); if(result) { printf("hackrf_open() failed: %s (%d)\n", hackrf_error_name(result), result); return EXIT_FAILURE; diff --git a/host/hackrf-tools/src/hackrf_operacake.c b/host/hackrf-tools/src/hackrf_operacake.c index 5162d060..649f9902 100644 --- a/host/hackrf-tools/src/hackrf_operacake.c +++ b/host/hackrf-tools/src/hackrf_operacake.c @@ -132,11 +132,6 @@ int main(int argc, char** argv) { return EXIT_FAILURE; } - if( result ) { - printf("hackrf_open() failed: %s (%d)\n", hackrf_error_name(result), result); - return -1; - } - if(list) { result = hackrf_get_operacake_boards(device, operacakes); if (result != HACKRF_SUCCESS) { diff --git a/host/hackrf-tools/src/hackrf_rffc5071.c b/host/hackrf-tools/src/hackrf_rffc5071.c index 11285d83..867bc379 100644 --- a/host/hackrf-tools/src/hackrf_rffc5071.c +++ b/host/hackrf-tools/src/hackrf_rffc5071.c @@ -39,6 +39,7 @@ static void usage() { printf("\t-n, --register : set register number for read/write operations\n"); printf("\t-r, --read: read register specified by last -n argument, or all registers\n"); printf("\t-w, --write : write register specified by last -n argument with value \n"); + printf("\t-d, --device : specify a particular device by serial number\n"); printf("\nExamples:\n"); printf("\t -n 12 -r # reads from register 12\n"); printf("\t -r # reads all registers\n"); @@ -49,6 +50,7 @@ static struct option long_options[] = { { "register", required_argument, 0, 'n' }, { "write", required_argument, 0, 'w' }, { "read", no_argument, 0, 'r' }, + { "device", no_argument, 0, 'd' }, { "help", no_argument, 0, 'h' }, { 0, 0, 0, 0 }, }; @@ -134,6 +136,7 @@ int main(int argc, char** argv) { int option_index = 0; bool read = false; bool write = false; + const char* serial_number = NULL; int result = hackrf_init(); if( result ) { @@ -141,7 +144,7 @@ int main(int argc, char** argv) { return EXIT_FAILURE; } - while( (opt = getopt_long(argc, argv, "n:rw:h?", long_options, &option_index)) != EOF ) { + while( (opt = getopt_long(argc, argv, "n:rw:d:h?", long_options, &option_index)) != EOF ) { switch( opt ) { case 'n': result = parse_int(optarg, ®ister_number); @@ -153,6 +156,9 @@ int main(int argc, char** argv) { case 'r': read = true; break; + case 'd': + serial_number = optarg; + break; case 'h': case '?': usage(); @@ -182,7 +188,7 @@ int main(int argc, char** argv) { return EXIT_FAILURE; } - result = hackrf_open(&device); + result = hackrf_open_by_serial(serial_number, &device); if(result) { printf("hackrf_open() failed: %s (%d)\n", hackrf_error_name(result), result); return EXIT_FAILURE;