From 55d7e7f2d27367670a7ef254434b42f0ab592b5a Mon Sep 17 00:00:00 2001 From: Dominic Spill Date: Fri, 3 Feb 2017 10:08:41 -0700 Subject: [PATCH] Standardize device selection options in hackrf-tools Fixes issue #318 --- host/hackrf-tools/src/hackrf_operacake.c | 23 ++++++----------------- host/hackrf-tools/src/hackrf_si5351c.c | 12 ++++++------ 2 files changed, 12 insertions(+), 23 deletions(-) diff --git a/host/hackrf-tools/src/hackrf_operacake.c b/host/hackrf-tools/src/hackrf_operacake.c index 91e1e0d2..5162d060 100644 --- a/host/hackrf-tools/src/hackrf_operacake.c +++ b/host/hackrf-tools/src/hackrf_operacake.c @@ -34,7 +34,6 @@ typedef int bool; static void usage() { printf("\nUsage:\n"); printf("\t-h, --help: this help\n"); - printf("\t-s, --serial : specify a particular device by serial number\n"); printf("\t-d, --device : specify a particular device by number\n"); printf("\t-o, --address : specify a particular operacake by address [default: 0x00]\n"); printf("\t-a : set port A connection\n"); @@ -44,7 +43,6 @@ static void usage() { static struct option long_options[] = { { "device", no_argument, 0, 'd' }, - { "serial", no_argument, 0, 's' }, { "address", no_argument, 0, 'o' }, { "list", no_argument, 0, 'v' }, { "help", no_argument, 0, 'h' }, @@ -65,7 +63,6 @@ int parse_int(char* const s, uint16_t* const value) { int main(int argc, char** argv) { int opt; const char* serial_number = NULL; - int device_index = 0; int operacake_address = 0; int port_a = 0; int port_b = 0; @@ -83,13 +80,9 @@ int main(int argc, char** argv) { return -1; } - while( (opt = getopt_long(argc, argv, "d:s:o:a:b:lh?", long_options, &option_index)) != EOF ) { + while( (opt = getopt_long(argc, argv, "d:o:a:b:lh?", long_options, &option_index)) != EOF ) { switch( opt ) { case 'd': - device_index = atoi(optarg); - break; - - case 's': serial_number = optarg; break; @@ -132,15 +125,11 @@ int main(int argc, char** argv) { return EXIT_FAILURE; } - if(serial_number != NULL) { - result = hackrf_open_by_serial(serial_number, &device); - } else { - hackrf_device_list_t* device_list = hackrf_device_list(); - if(device_list->devicecount <= 0) { - result = HACKRF_ERROR_NOT_FOUND; - } else { - result = hackrf_device_list_open(device_list, device_index, &device); - } + result = hackrf_open_by_serial(serial_number, &device); + if (result != HACKRF_SUCCESS) { + fprintf(stderr, "hackrf_open() failed: %s (%d)\n", + hackrf_error_name(result), result); + return EXIT_FAILURE; } if( result ) { diff --git a/host/hackrf-tools/src/hackrf_si5351c.c b/host/hackrf-tools/src/hackrf_si5351c.c index c4fc0cdb..7c8712c4 100644 --- a/host/hackrf-tools/src/hackrf_si5351c.c +++ b/host/hackrf-tools/src/hackrf_si5351c.c @@ -38,8 +38,8 @@ 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-s, --serial : specify a particular device by serial number\n"); - printf("\t-d, --device : specify a particular device by number\n"); + printf("\t-d, --device : specify a particular device by serial number\n"); + printf("\t-D, --device-idx : specify a particular device by number\n"); printf("\nExamples:\n"); printf("\t -n 12 -r # reads from register 12\n"); printf("\t -r # reads all registers\n"); @@ -52,7 +52,7 @@ static struct option long_options[] = { { "write", required_argument, 0, 'w' }, { "read", no_argument, 0, 'r' }, { "device", no_argument, 0, 'd' }, - { "serial", no_argument, 0, 's' }, + { "device-idx", no_argument, 0, 'D' }, { "help", no_argument, 0, 'h' }, { 0, 0, 0, 0 }, }; @@ -214,7 +214,7 @@ int main(int argc, char** argv) { return EXIT_FAILURE; } - while( (opt = getopt_long(argc, argv, "d:s:cn:rw:h?", long_options, &option_index)) != EOF ) { + while( (opt = getopt_long(argc, argv, "d:D:cn:rw:h?", long_options, &option_index)) != EOF ) { switch( opt ) { case 'n': result = parse_int(optarg, ®ister_number); @@ -233,11 +233,11 @@ int main(int argc, char** argv) { dump_config = true; break; - case 'd': + case 'D': device_index = atoi(optarg); break; - case 's': + case 'd': serial_number = optarg; break; case 'h':