Merge pull request #327 from dominicgs/device_selection_options
Device selection options
This commit is contained in:
@ -38,6 +38,7 @@ static void usage() {
|
||||
printf("\t-n, --register <n>: 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 <v>: write register specified by last -n argument with value <v>\n");
|
||||
printf("\t-d, --device <s>: specify a particular device by serial number\n");
|
||||
printf("\nExamples:\n");
|
||||
printf("\t<command> -n 12 -r # reads from register 12\n");
|
||||
printf("\t<command> -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;
|
||||
|
@ -34,8 +34,7 @@ typedef int bool;
|
||||
static void usage() {
|
||||
printf("\nUsage:\n");
|
||||
printf("\t-h, --help: this help\n");
|
||||
printf("\t-s, --serial <s>: specify a particular device by serial number\n");
|
||||
printf("\t-d, --device <n>: specify a particular device by number\n");
|
||||
printf("\t-d, --device <n>: specify a particular device by serial number\n");
|
||||
printf("\t-o, --address <n>: specify a particular operacake by address [default: 0x00]\n");
|
||||
printf("\t-a <n>: set port A connection\n");
|
||||
printf("\t-b <n>: set port B 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,20 +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);
|
||||
}
|
||||
}
|
||||
|
||||
if( result ) {
|
||||
printf("hackrf_open() failed: %s (%d)\n", hackrf_error_name(result), result);
|
||||
return -1;
|
||||
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(list) {
|
||||
|
@ -39,6 +39,7 @@ static void usage() {
|
||||
printf("\t-n, --register <n>: 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 <v>: write register specified by last -n argument with value <v>\n");
|
||||
printf("\t-d, --device <s>: specify a particular device by serial number\n");
|
||||
printf("\nExamples:\n");
|
||||
printf("\t<command> -n 12 -r # reads from register 12\n");
|
||||
printf("\t<command> -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;
|
||||
|
@ -38,8 +38,8 @@ static void usage() {
|
||||
printf("\t-n, --register <n>: 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 <v>: write register specified by last -n argument with value <v>\n");
|
||||
printf("\t-s, --serial <s>: specify a particular device by serial number\n");
|
||||
printf("\t-d, --device <n>: specify a particular device by number\n");
|
||||
printf("\t-d, --device <s>: specify a particular device by serial number\n");
|
||||
printf("\t-D, --device-idx <n>: specify a particular device by number\n");
|
||||
printf("\nExamples:\n");
|
||||
printf("\t<command> -n 12 -r # reads from register 12\n");
|
||||
printf("\t<command> -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':
|
||||
|
Reference in New Issue
Block a user