Fixed bug that prevented hackrf_max2837 and hackrf_rffc5071 from displaying help when HackRF is not found.
This commit is contained in:
@ -26,6 +26,12 @@
|
||||
#include <stdlib.h>
|
||||
#include <getopt.h>
|
||||
|
||||
#ifndef bool
|
||||
typedef int bool;
|
||||
#define true 1
|
||||
#define false 0
|
||||
#endif
|
||||
|
||||
static void usage() {
|
||||
printf("\nUsage:\n");
|
||||
printf("\t-h, --help: this help\n");
|
||||
@ -125,6 +131,8 @@ int main(int argc, char** argv) {
|
||||
uint16_t register_value;
|
||||
hackrf_device* device = NULL;
|
||||
int option_index = 0;
|
||||
bool read = false;
|
||||
bool write = false;
|
||||
|
||||
int result = hackrf_init();
|
||||
if( result ) {
|
||||
@ -132,12 +140,6 @@ int main(int argc, char** argv) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
result = hackrf_open(&device);
|
||||
if( result ) {
|
||||
printf("hackrf_open() failed: %s (%d)\n", hackrf_error_name(result), result);
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
while( (opt = getopt_long(argc, argv, "n:rw:h?", long_options, &option_index)) != EOF ) {
|
||||
switch( opt ) {
|
||||
case 'n':
|
||||
@ -145,18 +147,12 @@ int main(int argc, char** argv) {
|
||||
break;
|
||||
|
||||
case 'w':
|
||||
write = true;
|
||||
result = parse_int(optarg, ®ister_value);
|
||||
if( result == HACKRF_SUCCESS ) {
|
||||
result = write_register(device, register_number, register_value);
|
||||
}
|
||||
break;
|
||||
|
||||
case 'r':
|
||||
if( register_number == REGISTER_INVALID ) {
|
||||
result = dump_registers(device);
|
||||
} else {
|
||||
result = dump_register(device, register_number);
|
||||
}
|
||||
read = true;
|
||||
break;
|
||||
|
||||
case 'h':
|
||||
@ -171,7 +167,38 @@ int main(int argc, char** argv) {
|
||||
|
||||
if( result != HACKRF_SUCCESS ) {
|
||||
printf("argument error: %s (%d)\n", hackrf_error_name(result), result);
|
||||
break;
|
||||
usage();
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
}
|
||||
|
||||
if(write && read) {
|
||||
fprintf(stderr, "Read and write options are mutually exclusive.\n");
|
||||
usage();
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
if(!(write || read)) {
|
||||
fprintf(stderr, "Specify either read or write option.\n");
|
||||
usage();
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
result = hackrf_open(&device);
|
||||
if(result) {
|
||||
printf("hackrf_open() failed: %s (%d)\n", hackrf_error_name(result), result);
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
if(write) {
|
||||
result = write_register(device, register_number, register_value);
|
||||
}
|
||||
|
||||
if(read) {
|
||||
if(register_number == REGISTER_INVALID) {
|
||||
result = dump_registers(device);
|
||||
} else {
|
||||
result = dump_register(device, register_number);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -27,6 +27,12 @@
|
||||
#include <stdlib.h>
|
||||
#include <getopt.h>
|
||||
|
||||
#ifndef bool
|
||||
typedef int bool;
|
||||
#define true 1
|
||||
#define false 0
|
||||
#endif
|
||||
|
||||
static void usage() {
|
||||
printf("\nUsage:\n");
|
||||
printf("\t-h, --help: this help\n");
|
||||
@ -126,6 +132,8 @@ int main(int argc, char** argv) {
|
||||
uint16_t register_value;
|
||||
hackrf_device* device = NULL;
|
||||
int option_index = 0;
|
||||
bool read = false;
|
||||
bool write = false;
|
||||
|
||||
int result = hackrf_init();
|
||||
if( result ) {
|
||||
@ -133,37 +141,22 @@ int main(int argc, char** argv) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
result = hackrf_open(&device);
|
||||
if( result ) {
|
||||
printf("hackrf_open() failed: %s (%d)\n", hackrf_error_name(result), result);
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
while( (opt = getopt_long(argc, argv, "n:rw:h?", long_options, &option_index)) != EOF ) {
|
||||
switch( opt ) {
|
||||
case 'n':
|
||||
result = parse_int(optarg, ®ister_number);
|
||||
break;
|
||||
|
||||
case 'w':
|
||||
write = true;
|
||||
result = parse_int(optarg, ®ister_value);
|
||||
if( result == HACKRF_SUCCESS ) {
|
||||
result = write_register(device, register_number, register_value);
|
||||
}
|
||||
break;
|
||||
|
||||
case 'r':
|
||||
if( register_number == REGISTER_INVALID ) {
|
||||
result = dump_registers(device);
|
||||
} else {
|
||||
result = dump_register(device, register_number);
|
||||
}
|
||||
read = true;
|
||||
break;
|
||||
case 'h':
|
||||
case '?':
|
||||
usage();
|
||||
return EXIT_SUCCESS;
|
||||
|
||||
default:
|
||||
fprintf(stderr, "unknown argument '-%c %s'\n", opt, optarg);
|
||||
usage();
|
||||
@ -173,7 +166,37 @@ int main(int argc, char** argv) {
|
||||
if( result != HACKRF_SUCCESS ) {
|
||||
printf("argument error: %s (%d)\n", hackrf_error_name(result), result);
|
||||
usage();
|
||||
break;
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
}
|
||||
|
||||
if(write && read) {
|
||||
fprintf(stderr, "Read and write options are mutually exclusive.\n");
|
||||
usage();
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
if(!(write || read)) {
|
||||
fprintf(stderr, "Specify either read or write option.\n");
|
||||
usage();
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
result = hackrf_open(&device);
|
||||
if(result) {
|
||||
printf("hackrf_open() failed: %s (%d)\n", hackrf_error_name(result), result);
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
if(write) {
|
||||
result = write_register(device, register_number, register_value);
|
||||
}
|
||||
|
||||
if(read) {
|
||||
if(register_number == REGISTER_INVALID) {
|
||||
result = dump_registers(device);
|
||||
} else {
|
||||
result = dump_register(device, register_number);
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user