diff --git a/host/hackrf-tools/src/hackrf_cpldjtag.c b/host/hackrf-tools/src/hackrf_cpldjtag.c index b76c9349..3c9a89e1 100644 --- a/host/hackrf-tools/src/hackrf_cpldjtag.c +++ b/host/hackrf-tools/src/hackrf_cpldjtag.c @@ -45,6 +45,7 @@ uint8_t data[MAX_XSVF_LENGTH]; static struct option long_options[] = { { "xsvf", required_argument, 0, 'x' }, + { "help", no_argument, 0, 'h' }, { 0, 0, 0, 0 }, }; @@ -79,7 +80,8 @@ int parse_int(char* s, uint32_t* const value) static void usage() { printf("Usage:\n"); - printf("\t-x : XSVF file to be written to CPLD.\n"); + printf("\t-h, --help: this help\n"); + printf("\t-x, --xsvf : XSVF file to be written to CPLD.\n"); printf("\t-d : Serial number of device, if multiple devices\n"); } @@ -97,7 +99,7 @@ int main(int argc, char** argv) ssize_t bytes_read; uint8_t* pdata = &data[0]; - while ((opt = getopt_long(argc, argv, "x:d:", long_options, + while ((opt = getopt_long(argc, argv, "x:d:h?", long_options, &option_index)) != EOF) { switch (opt) { case 'x': @@ -107,8 +109,13 @@ int main(int argc, char** argv) case 'd': serial_number = optarg; break; + case 'h': + case '?': + usage(); + return EXIT_SUCCESS; default: + fprintf(stderr, "unknown argument '-%c %s'\n", opt, optarg); usage(); return EXIT_FAILURE; } diff --git a/host/hackrf-tools/src/hackrf_max2837.c b/host/hackrf-tools/src/hackrf_max2837.c index d8fb75f5..38ac01be 100644 --- a/host/hackrf-tools/src/hackrf_max2837.c +++ b/host/hackrf-tools/src/hackrf_max2837.c @@ -28,6 +28,7 @@ static void usage() { printf("\nUsage:\n"); + printf("\t-h, --help: this help\n"); printf("\t-n, --register : set register number for subsequent 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"); @@ -41,6 +42,7 @@ static struct option long_options[] = { { "register", required_argument, 0, 'n' }, { "write", required_argument, 0, 'w' }, { "read", no_argument, 0, 'r' }, + { "help", no_argument, 0, 'h' }, { 0, 0, 0, 0 }, }; @@ -127,16 +129,16 @@ int main(int argc, char** argv) { int result = hackrf_init(); if( result ) { printf("hackrf_init() failed: %s (%d)\n", hackrf_error_name(result), result); - return -1; + return EXIT_FAILURE; } result = hackrf_open(&device); if( result ) { printf("hackrf_open() failed: %s (%d)\n", hackrf_error_name(result), result); - return -1; + return EXIT_FAILURE; } - while( (opt = getopt_long(argc, argv, "n:rw:", long_options, &option_index)) != EOF ) { + while( (opt = getopt_long(argc, argv, "n:rw:h?", long_options, &option_index)) != EOF ) { switch( opt ) { case 'n': result = parse_int(optarg, ®ister_number); @@ -157,8 +159,14 @@ int main(int argc, char** argv) { } break; - default: + case 'h': + case '?': usage(); + return EXIT_SUCCESS; + default: + fprintf(stderr, "unknown argument '-%c %s'\n", opt, optarg); + usage(); + return EXIT_FAILURE; } if( result != HACKRF_SUCCESS ) { @@ -170,10 +178,10 @@ int main(int argc, char** argv) { result = hackrf_close(device); if( result ) { printf("hackrf_close() failed: %s (%d)\n", hackrf_error_name(result), result); - return -1; + return EXIT_FAILURE; } hackrf_exit(); - return 0; + return EXIT_SUCCESS; } diff --git a/host/hackrf-tools/src/hackrf_operacake.c b/host/hackrf-tools/src/hackrf_operacake.c index 086af5cb..6f8e2e1b 100644 --- a/host/hackrf-tools/src/hackrf_operacake.c +++ b/host/hackrf-tools/src/hackrf_operacake.c @@ -33,6 +33,7 @@ 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"); @@ -45,6 +46,7 @@ static struct option long_options[] = { { "device", no_argument, 0, 'd' }, { "serial", no_argument, 0, 's' }, { "address", no_argument, 0, 'o' }, + { "help", no_argument, 0, 'h' }, { 0, 0, 0, 0 }, }; @@ -78,7 +80,7 @@ int main(int argc, char** argv) { return -1; } - while( (opt = getopt_long(argc, argv, "d:s:o:a:b:v", long_options, &option_index)) != EOF ) { + while( (opt = getopt_long(argc, argv, "d:s:o:a:b:vh?", long_options, &option_index)) != EOF ) { switch( opt ) { case 'd': device_index = atoi(optarg); @@ -103,9 +105,15 @@ int main(int argc, char** argv) { case 'v': verbose = 1; break; + case 'h': + case '?': + usage(); + return EXIT_SUCCESS; default: + fprintf(stderr, "unknown argument '-%c %s'\n", opt, optarg); usage(); + return EXIT_FAILURE; } if( result != HACKRF_SUCCESS ) { diff --git a/host/hackrf-tools/src/hackrf_rffc5071.c b/host/hackrf-tools/src/hackrf_rffc5071.c index c9630dd4..7282184a 100644 --- a/host/hackrf-tools/src/hackrf_rffc5071.c +++ b/host/hackrf-tools/src/hackrf_rffc5071.c @@ -29,6 +29,7 @@ static void usage() { printf("\nUsage:\n"); + printf("\t-h, --help: this help\n"); printf("\t-n, --register : set register number for subsequent 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"); @@ -42,6 +43,7 @@ static struct option long_options[] = { { "register", required_argument, 0, 'n' }, { "write", required_argument, 0, 'w' }, { "read", no_argument, 0, 'r' }, + { "help", no_argument, 0, 'h' }, { 0, 0, 0, 0 }, }; @@ -128,16 +130,16 @@ int main(int argc, char** argv) { int result = hackrf_init(); if( result ) { printf("hackrf_init() failed: %s (%d)\n", hackrf_error_name(result), result); - return -1; + return EXIT_FAILURE; } result = hackrf_open(&device); if( result ) { printf("hackrf_open() failed: %s (%d)\n", hackrf_error_name(result), result); - return -1; + return EXIT_FAILURE; } - while( (opt = getopt_long(argc, argv, "n:rw:", long_options, &option_index)) != EOF ) { + while( (opt = getopt_long(argc, argv, "n:rw:h?", long_options, &option_index)) != EOF ) { switch( opt ) { case 'n': result = parse_int(optarg, ®ister_number); @@ -157,9 +159,15 @@ int main(int argc, char** argv) { result = dump_register(device, register_number); } break; + case 'h': + case '?': + usage(); + return EXIT_SUCCESS; default: + fprintf(stderr, "unknown argument '-%c %s'\n", opt, optarg); usage(); + return EXIT_FAILURE; } if( result != HACKRF_SUCCESS ) { @@ -172,10 +180,10 @@ int main(int argc, char** argv) { result = hackrf_close(device); if( result ) { printf("hackrf_close() failed: %s (%d)\n", hackrf_error_name(result), result); - return -1; + return EXIT_FAILURE; } hackrf_exit(); - return 0; + return EXIT_SUCCESS; } diff --git a/host/hackrf-tools/src/hackrf_si5351c.c b/host/hackrf-tools/src/hackrf_si5351c.c index fae59409..69dedc86 100644 --- a/host/hackrf-tools/src/hackrf_si5351c.c +++ b/host/hackrf-tools/src/hackrf_si5351c.c @@ -33,6 +33,7 @@ typedef int bool; static void usage() { printf("\nUsage:\n"); + printf("\t-h, --help: this help\n"); printf("\t-c, --config: print textual configuration information\n"); printf("\t-n, --register : set register number for subsequent read/write operations\n"); printf("\t-r, --read: read register specified by last -n argument, or all registers\n"); @@ -52,6 +53,7 @@ static struct option long_options[] = { { "read", no_argument, 0, 'r' }, { "device", no_argument, 0, 'd' }, { "serial", no_argument, 0, 's' }, + { "help", no_argument, 0, 'h' }, { 0, 0, 0, 0 }, }; @@ -209,10 +211,10 @@ int main(int argc, char** argv) { int result = hackrf_init(); if( result ) { printf("hackrf_init() failed: %s (%d)\n", hackrf_error_name(result), result); - return -1; + return EXIT_FAILURE; } - while( (opt = getopt_long(argc, argv, "d:s:cn:rw:", long_options, &option_index)) != EOF ) { + while( (opt = getopt_long(argc, argv, "d:s:cn:rw:h?", long_options, &option_index)) != EOF ) { switch( opt ) { case 'n': result = parse_int(optarg, ®ister_number); @@ -237,9 +239,15 @@ int main(int argc, char** argv) { case 's': serial_number = optarg; break; + case 'h': + case '?': + usage(); + return EXIT_SUCCESS; default: + fprintf(stderr, "unknown argument '-%c %s'\n", opt, optarg); usage(); + return EXIT_FAILURE; } if( result != HACKRF_SUCCESS ) { @@ -261,7 +269,7 @@ int main(int argc, char** argv) { if( result ) { printf("hackrf_open() failed: %s (%d)\n", hackrf_error_name(result), result); - return -1; + return EXIT_FAILURE; } if(write) { @@ -282,10 +290,10 @@ int main(int argc, char** argv) { result = hackrf_close(device); if( result ) { printf("hackrf_close() failed: %s (%d)\n", hackrf_error_name(result), result); - return -1; + return EXIT_FAILURE; } hackrf_exit(); - return 0; + return EXIT_SUCCESS; } diff --git a/host/hackrf-tools/src/hackrf_spiflash.c b/host/hackrf-tools/src/hackrf_spiflash.c index 49cc2bf9..5acb6646 100644 --- a/host/hackrf-tools/src/hackrf_spiflash.c +++ b/host/hackrf-tools/src/hackrf_spiflash.c @@ -52,6 +52,7 @@ static struct option long_options[] = { { "read", required_argument, 0, 'r' }, { "write", required_argument, 0, 'w' }, { "verbose", no_argument, 0, 'v' }, + { "help", no_argument, 0, 'h' }, { 0, 0, 0, 0 }, }; @@ -86,6 +87,7 @@ int parse_u32(char* s, uint32_t* const value) static void usage() { printf("Usage:\n"); + printf("\t-h, --help: this help\n"); printf("\t-a, --address : starting address (default: 0)\n"); printf("\t-l, --length : number of bytes to read (default: %d)\n", MAX_LENGTH); printf("\t-r : Read data into file.\n"); @@ -115,7 +117,7 @@ int main(int argc, char** argv) bool verbose = false; bool reset = false; - while ((opt = getopt_long(argc, argv, "a:l:r:w:d:vR", long_options, + while ((opt = getopt_long(argc, argv, "a:l:r:w:d:vRh?", long_options, &option_index)) != EOF) { switch (opt) { case 'a': @@ -148,9 +150,10 @@ int main(int argc, char** argv) reset = true; break; + case 'h': case '?': usage(); - return EXIT_FAILURE; + return EXIT_SUCCESS; default: fprintf(stderr, "unknown argument '-%c %s'\n", opt, optarg); diff --git a/host/hackrf-tools/src/hackrf_sweep.c b/host/hackrf-tools/src/hackrf_sweep.c index da700fa2..c907a390 100644 --- a/host/hackrf-tools/src/hackrf_sweep.c +++ b/host/hackrf-tools/src/hackrf_sweep.c @@ -235,6 +235,7 @@ int rx_callback(hackrf_transfer* transfer) { static void usage() { fprintf(stderr, "Usage:\n"); + fprintf(stderr, "\t[-h] # this help\n"); fprintf(stderr, "\t[-d serial_number] # Serial number of desired HackRF.\n"); fprintf(stderr, "\t[-a amp_enable] # RX/TX RF amplifier 1=Enable, 0=Disable.\n"); fprintf(stderr, "\t[-f freq_min:freq_max # Specify minimum & maximum sweep frequencies (MHz).\n"); @@ -276,7 +277,7 @@ int main(int argc, char** argv) { uint16_t frequencies[MAX_FREQ_COUNT]; uint32_t num_samples = DEFAULT_SAMPLE_COUNT; - while( (opt = getopt(argc, argv, "a:f:p:l:g:x:d:n:")) != EOF ) { + while( (opt = getopt(argc, argv, "a:f:p:l:g:x:d:n:h?")) != EOF ) { result = HACKRF_SUCCESS; switch( opt ) { @@ -325,6 +326,11 @@ int main(int argc, char** argv) { result = parse_u32(optarg, &num_samples); break; + case 'h': + case '?': + usage(); + return EXIT_SUCCESS; + default: fprintf(stderr, "unknown argument '-%c %s'\n", opt, optarg); usage(); diff --git a/host/hackrf-tools/src/hackrf_transfer.c b/host/hackrf-tools/src/hackrf_transfer.c index a36166c6..b4a3b18b 100644 --- a/host/hackrf-tools/src/hackrf_transfer.c +++ b/host/hackrf-tools/src/hackrf_transfer.c @@ -469,6 +469,7 @@ int tx_callback(hackrf_transfer* transfer) { static void usage() { printf("Usage:\n"); + printf("\t-h # this help\n"); printf("\t[-d serial_number] # Serial number of desired HackRF.\n"); printf("\t-r # Receive data into file (use '-' for stdout).\n"); printf("\t-t # Transmit data from file (use '-' for stdin).\n"); @@ -544,7 +545,7 @@ int main(int argc, char** argv) { float time_diff; unsigned int lna_gain=8, vga_gain=20, txvga_gain=0; - while( (opt = getopt(argc, argv, "Hwr:t:f:i:o:m:a:p:s:n:b:l:g:x:c:d:C:RS:")) != EOF ) + while( (opt = getopt(argc, argv, "Hwr:t:f:i:o:m:a:p:s:n:b:l:g:x:c:d:C:RS:h?")) != EOF ) { result = HACKRF_SUCCESS; switch( opt ) @@ -673,9 +674,10 @@ int main(int argc, char** argv) { result = parse_u32(optarg, &crystal_correct_ppm); break; + case 'h': case '?': usage(); - return EXIT_FAILURE; + return EXIT_SUCCESS; default: fprintf(stderr, "unknown argument '-%c %s'\n", opt, optarg);