From 5361b3a7f43cce012dbd3525aec6ddfdb6c756ad Mon Sep 17 00:00:00 2001 From: Mike Walters Date: Thu, 18 Mar 2021 19:48:53 +0000 Subject: [PATCH] hackrf_sweep: switch main loop timing back to 1Hz fixes #850 fixes #851 --- host/hackrf-tools/src/hackrf_sweep.c | 26 +++++++++++++++----------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/host/hackrf-tools/src/hackrf_sweep.c b/host/hackrf-tools/src/hackrf_sweep.c index 1eb9af45f..ad598a499 100644 --- a/host/hackrf-tools/src/hackrf_sweep.c +++ b/host/hackrf-tools/src/hackrf_sweep.c @@ -393,6 +393,7 @@ int main(int argc, char** argv) { const char* serial_number = NULL; int exit_code = EXIT_SUCCESS; struct timeval time_now; + struct timeval time_prev; float time_diff; float sweep_rate; unsigned int lna_gain=16, vga_gain=20; @@ -702,6 +703,7 @@ int main(int argc, char** argv) { } gettimeofday(&t_start, NULL); + time_prev = t_start; fprintf(stderr, "Stop with Ctrl-C\n"); while((hackrf_is_streaming(device) == HACKRF_TRUE) && (do_exit == false)) { @@ -709,18 +711,20 @@ int main(int argc, char** argv) { m_sleep(50); gettimeofday(&time_now, NULL); - - time_difference = TimevalDiff(&time_now, &t_start); - sweep_rate = (float)sweep_count / time_difference; - fprintf(stderr, "%" PRIu64 " total sweeps completed, %.2f sweeps/second\n", - sweep_count, sweep_rate); - - if (byte_count == 0) { - exit_code = EXIT_FAILURE; - fprintf(stderr, "\nCouldn't transfer any data for one second.\n"); - break; + if (TimevalDiff(&time_now, &time_prev) >= 1.0f) { + time_difference = TimevalDiff(&time_now, &t_start); + sweep_rate = (float)sweep_count / time_difference; + fprintf(stderr, "%" PRIu64 " total sweeps completed, %.2f sweeps/second\n", + sweep_count, sweep_rate); + + if (byte_count == 0) { + exit_code = EXIT_FAILURE; + fprintf(stderr, "\nCouldn't transfer any data for one second.\n"); + break; + } + byte_count = 0; + time_prev = time_now; } - byte_count = 0; } result = hackrf_is_streaming(device);