From 2ef7995763f45b8922bacf5e7fb5fd8ba8962e5a Mon Sep 17 00:00:00 2001 From: Yan Date: Fri, 19 Mar 2021 16:23:36 +0100 Subject: [PATCH 1/3] hackrf_sweep: flush output earlier Gives listener access to complete data faster. Otherwise the data might be delayed until the whole closing procedure is done. --- host/hackrf-tools/src/hackrf_sweep.c | 1 + 1 file changed, 1 insertion(+) diff --git a/host/hackrf-tools/src/hackrf_sweep.c b/host/hackrf-tools/src/hackrf_sweep.c index ad598a49..38a4c297 100644 --- a/host/hackrf-tools/src/hackrf_sweep.c +++ b/host/hackrf-tools/src/hackrf_sweep.c @@ -727,6 +727,7 @@ int main(int argc, char** argv) { } } + fflush(outfile); result = hackrf_is_streaming(device); if (do_exit) { fprintf(stderr, "\nExiting...\n"); From 4c46fc74b39e437ad48612e15b8a2974f0c7520b Mon Sep 17 00:00:00 2001 From: Yan Date: Fri, 19 Mar 2021 16:31:37 +0100 Subject: [PATCH 2/3] hackrf_sweep: speed up ending by removing unnecessary code hackrf_stop_rx() is handled in hackrf_close(), so there seems to be no need to call it separately. Furthermore, if hackrf_stop() is called separately, it causes hackrf_close() to take more than half a second longer. --- host/hackrf-tools/src/hackrf_sweep.c | 8 -------- 1 file changed, 8 deletions(-) diff --git a/host/hackrf-tools/src/hackrf_sweep.c b/host/hackrf-tools/src/hackrf_sweep.c index 38a4c297..e81c809d 100644 --- a/host/hackrf-tools/src/hackrf_sweep.c +++ b/host/hackrf-tools/src/hackrf_sweep.c @@ -742,14 +742,6 @@ int main(int argc, char** argv) { sweep_count, time_diff, sweep_rate); if(device != NULL) { - result = hackrf_stop_rx(device); - if(result != HACKRF_SUCCESS) { - fprintf(stderr, "hackrf_stop_rx() failed: %s (%d)\n", - hackrf_error_name(result), result); - } else { - fprintf(stderr, "hackrf_stop_rx() done\n"); - } - result = hackrf_close(device); if(result != HACKRF_SUCCESS) { fprintf(stderr, "hackrf_close() failed: %s (%d)\n", From ab4498f8ac63cafcca457d6c1cf1ad06e14c892d Mon Sep 17 00:00:00 2001 From: Yan Date: Sat, 20 Mar 2021 10:07:51 +0100 Subject: [PATCH 3/3] hackrf_sweep: exit early from rx_callback if do_exit set Sometimes, if a small frequency interval is scanned, the callback is triggered even though we already have the number of sweeps we want, and sweep_count gets increased, showing the wrong "Total sweeps". --- host/hackrf-tools/src/hackrf_sweep.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/host/hackrf-tools/src/hackrf_sweep.c b/host/hackrf-tools/src/hackrf_sweep.c index e81c809d..1355a633 100644 --- a/host/hackrf-tools/src/hackrf_sweep.c +++ b/host/hackrf-tools/src/hackrf_sweep.c @@ -220,6 +220,9 @@ int rx_callback(hackrf_transfer* transfer) { return -1; } + if(do_exit) { + return 0; + } gettimeofday(&usb_transfer_time, NULL); byte_count += transfer->valid_length; buf = (int8_t*) transfer->buffer;