From 4ecbd5d2c93dcb9c1deb9f7077d7bba89cc6ec20 Mon Sep 17 00:00:00 2001 From: Mike Walters Date: Thu, 9 Sep 2021 21:59:03 +0100 Subject: [PATCH] hackrf_operacake: add option for default dwell time This allows for usage like this: $ hackrf_operacake -m time -w 1e6 -t A1 -t A2 -t A3 $ hackrf_transfer -r /dev/null -s 1e6 ref #930 --- host/hackrf-tools/src/hackrf_operacake.c | 32 ++++++++++++++++++++++-- 1 file changed, 30 insertions(+), 2 deletions(-) diff --git a/host/hackrf-tools/src/hackrf_operacake.c b/host/hackrf-tools/src/hackrf_operacake.c index 6c5775e4..f7ae8b99 100644 --- a/host/hackrf-tools/src/hackrf_operacake.c +++ b/host/hackrf-tools/src/hackrf_operacake.c @@ -50,7 +50,8 @@ static void usage() { printf("\t-a : set port A connection\n"); printf("\t-b : set port B connection\n"); printf("\t-f : automatically assign for range in MHz\n"); - printf("\t-t : in time-switching mode, dwell on for samples. This argument can be repeated to specify a list of ports.\n"); + printf("\t-t : in time-switching mode, dwell on for samples. Specify only to use the default dwell time (with -w). This argument can be repeated to specify a list of ports.\n"); + printf("\t-w : set default dwell time for time-switching mode"); printf("\t-l, --list: list available operacake boards\n"); printf("\t-g, --gpio_test: test GPIO functionality of an opera cake\n"); } @@ -151,8 +152,20 @@ int parse_dwell(char* s, hackrf_operacake_dwell_time* dwell_time) { if (result != HACKRF_SUCCESS) return result; + if (dwell == 0) { + fprintf(stderr, "dwell time cannot be 0\n"); + return HACKRF_ERROR_INVALID_PARAM; + } dwell_time->dwell = (uint32_t)dwell; return HACKRF_SUCCESS; + } else if (sscanf(s, "%15[^:]", port) == 1) { + result = parse_port(port, &dwell_time->port); + if (result != HACKRF_SUCCESS) + return result; + + // This will be replaced with the default dwell time later. + dwell_time->dwell = 0; + return HACKRF_SUCCESS; } return HACKRF_ERROR_INVALID_PARAM; } @@ -177,6 +190,7 @@ int main(int argc, char** argv) { hackrf_operacake_dwell_time dwell_times[HACKRF_OPERACAKE_MAX_DWELL_TIMES]; uint8_t range_idx = 0; uint8_t dwell_idx = 0; + uint32_t default_dwell = 0; int result = hackrf_init(); if( result ) { @@ -184,7 +198,7 @@ int main(int argc, char** argv) { return -1; } - while( (opt = getopt_long(argc, argv, "d:o:a:m:b:lf:t:hg?", long_options, &option_index)) != EOF ) { + while( (opt = getopt_long(argc, argv, "d:o:a:m:b:lf:t:w:hg?", long_options, &option_index)) != EOF ) { switch( opt ) { case 'd': serial_number = optarg; @@ -257,6 +271,10 @@ int main(int argc, char** argv) { dwell_idx++; break; + case 'w': + default_dwell = atof(optarg); + break; + case 'a': result = parse_port(optarg, &port_a); if (result != HACKRF_SUCCESS) { @@ -434,6 +452,16 @@ int main(int argc, char** argv) { } if(dwell_idx) { + for (i = 0; i < dwell_idx; i++) { + if (dwell_times[i].dwell == 0) { + if (default_dwell == 0) { + fprintf(stderr, "port '%u' set to use default dwell time, but default dwell time is not set. Use -w argument to set default dwell time.\n", + dwell_times[i].port); + return EXIT_FAILURE; + } + dwell_times[i].dwell = default_dwell; + } + } result = hackrf_set_operacake_dwell_times(device, dwell_times, dwell_idx); if( result ) { printf("hackrf_set_operacake_dwell_times() failed: %s (%d)\n", hackrf_error_name(result), result);