From ac30119c28d0b752887bb345dd60d26ae11ac9f3 Mon Sep 17 00:00:00 2001 From: Gabriele Gristina Date: Thu, 7 Dec 2023 19:39:23 +0100 Subject: [PATCH 1/5] Added a new option (-n) to enable timestamp normalization within a same sweep --- host/hackrf-tools/src/hackrf_sweep.c | 30 +++++++++++++++++++++++++--- 1 file changed, 27 insertions(+), 3 deletions(-) diff --git a/host/hackrf-tools/src/hackrf_sweep.c b/host/hackrf-tools/src/hackrf_sweep.c index 9acb5f5e0..8f6bc61ce 100644 --- a/host/hackrf-tools/src/hackrf_sweep.c +++ b/host/hackrf-tools/src/hackrf_sweep.c @@ -185,6 +185,7 @@ uint32_t amp_enable; bool antenna = false; uint32_t antenna_enable; +bool timestamp_normalized = false; bool binary_output = false; bool ifft_output = false; bool one_shot = false; @@ -203,6 +204,8 @@ uint32_t ifft_idx = 0; float* pwr; float* window; +struct timeval usb_transfer_time; + float logPower(fftwf_complex in, float scale) { float re = in[0] * scale; @@ -221,7 +224,6 @@ int rx_callback(hackrf_transfer* transfer) int i, j, ifft_bins; struct tm* fft_time; char time_str[50]; - struct timeval usb_transfer_time; if (NULL == outfile) { return -1; @@ -230,7 +232,13 @@ int rx_callback(hackrf_transfer* transfer) if (do_exit) { return 0; } - gettimeofday(&usb_transfer_time, NULL); + + // happens only once with timestamp_normalized == true + if ((usb_transfer_time.tv_sec == 0 && usb_transfer_time.tv_usec == 0) || timestamp_normalized == false) { + // set the timestamp for the first sweep + gettimeofday(&usb_transfer_time, NULL); + } + byte_count += transfer->valid_length; buf = (int8_t*) transfer->buffer; ifft_bins = fftSize * step_count; @@ -266,6 +274,14 @@ int rx_callback(hackrf_transfer* transfer) } } sweep_count++; + + if (timestamp_normalized == true) + { + // set the timestamp of the next sweep + memset(&usb_transfer_time, 0, sizeof (usb_transfer_time)); + gettimeofday(&usb_transfer_time, NULL); + } + if (one_shot) { do_exit = true; } else if (finite_mode && sweep_count == num_sweeps) { @@ -388,6 +404,7 @@ static void usage() "\t[-N num_sweeps] # Number of sweeps to perform\n" "\t[-B] # binary output\n" "\t[-I] # binary inverse FFT output\n" + "\t[-n] # keep the same timestamp within a sweep\n" "\t-r filename # output file\n" "\n" "Output fields:\n" @@ -461,7 +478,7 @@ int main(int argc, char** argv) const char* fftwWisdomPath = NULL; int fftw_plan_type = FFTW_MEASURE; - while ((opt = getopt(argc, argv, "a:f:p:l:g:d:n:N:w:W:P:1BIr:h?")) != EOF) { + while ((opt = getopt(argc, argv, "a:f:p:l:g:d:n:N:w:W:P:n1BIr:h?")) != EOF) { result = HACKRF_SUCCESS; switch (opt) { case 'd': @@ -542,6 +559,10 @@ int main(int argc, char** argv) } break; + case 'n': + timestamp_normalized = true; + break; + case '1': one_shot = true; break; @@ -681,6 +702,9 @@ int main(int argc, char** argv) */ fftwf_execute(fftwPlan); + // reset the timestamp + memset(&usb_transfer_time, 0, sizeof (usb_transfer_time)); + #ifdef _MSC_VER if (binary_output) { _setmode(_fileno(stdout), _O_BINARY); From b93bda0a56b964a3e7171e1cfe24be28586fb840 Mon Sep 17 00:00:00 2001 From: Gabriele Gristina Date: Thu, 7 Dec 2023 19:52:04 +0100 Subject: [PATCH 2/5] fix getopt() optstring --- host/hackrf-tools/src/hackrf_sweep.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/host/hackrf-tools/src/hackrf_sweep.c b/host/hackrf-tools/src/hackrf_sweep.c index 8f6bc61ce..56bfc074d 100644 --- a/host/hackrf-tools/src/hackrf_sweep.c +++ b/host/hackrf-tools/src/hackrf_sweep.c @@ -478,7 +478,7 @@ int main(int argc, char** argv) const char* fftwWisdomPath = NULL; int fftw_plan_type = FFTW_MEASURE; - while ((opt = getopt(argc, argv, "a:f:p:l:g:d:n:N:w:W:P:n1BIr:h?")) != EOF) { + while ((opt = getopt(argc, argv, "a:f:p:l:g:d:N:w:W:P:n1BIr:h?")) != EOF) { result = HACKRF_SUCCESS; switch (opt) { case 'd': From a78e6f05b2847feb52bdcb16930b3e9a9885c221 Mon Sep 17 00:00:00 2001 From: Gabriele Gristina Date: Fri, 15 Dec 2023 17:35:12 +0100 Subject: [PATCH 3/5] fix clang-format errors --- host/hackrf-tools/src/hackrf_sweep.c | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/host/hackrf-tools/src/hackrf_sweep.c b/host/hackrf-tools/src/hackrf_sweep.c index 56bfc074d..cb98f5a3d 100644 --- a/host/hackrf-tools/src/hackrf_sweep.c +++ b/host/hackrf-tools/src/hackrf_sweep.c @@ -40,7 +40,7 @@ #ifndef bool typedef int bool; - #define true 1 + #define true 1 #define false 0 #endif @@ -234,7 +234,8 @@ int rx_callback(hackrf_transfer* transfer) } // happens only once with timestamp_normalized == true - if ((usb_transfer_time.tv_sec == 0 && usb_transfer_time.tv_usec == 0) || timestamp_normalized == false) { + if ((usb_transfer_time.tv_sec == 0 && usb_transfer_time.tv_usec == 0) || + timestamp_normalized == false) { // set the timestamp for the first sweep gettimeofday(&usb_transfer_time, NULL); } @@ -275,10 +276,11 @@ int rx_callback(hackrf_transfer* transfer) } sweep_count++; - if (timestamp_normalized == true) - { + if (timestamp_normalized == true) { // set the timestamp of the next sweep - memset(&usb_transfer_time, 0, sizeof (usb_transfer_time)); + memset(&usb_transfer_time, + 0, + sizeof(usb_transfer_time)); gettimeofday(&usb_transfer_time, NULL); } @@ -374,7 +376,8 @@ int rx_callback(hackrf_transfer* transfer) time_str, (long int) usb_transfer_time.tv_usec, (uint64_t) (frequency + (DEFAULT_SAMPLE_RATE_HZ / 2)), - (uint64_t) (frequency + ((DEFAULT_SAMPLE_RATE_HZ * 3) / 4)), + (uint64_t) (frequency + + ((DEFAULT_SAMPLE_RATE_HZ * 3) / 4)), fft_bin_width, fftSize); for (i = 0; (fftSize / 4) > i; i++) { @@ -703,7 +706,7 @@ int main(int argc, char** argv) fftwf_execute(fftwPlan); // reset the timestamp - memset(&usb_transfer_time, 0, sizeof (usb_transfer_time)); + memset(&usb_transfer_time, 0, sizeof(usb_transfer_time)); #ifdef _MSC_VER if (binary_output) { From 570cab1e777dd983b421469fa2df5905f734cf55 Mon Sep 17 00:00:00 2001 From: Martin Ling Date: Thu, 1 Feb 2024 17:14:25 +0000 Subject: [PATCH 4/5] Remove superfluous memset call. --- host/hackrf-tools/src/hackrf_sweep.c | 3 --- 1 file changed, 3 deletions(-) diff --git a/host/hackrf-tools/src/hackrf_sweep.c b/host/hackrf-tools/src/hackrf_sweep.c index cb98f5a3d..948b9dd47 100644 --- a/host/hackrf-tools/src/hackrf_sweep.c +++ b/host/hackrf-tools/src/hackrf_sweep.c @@ -278,9 +278,6 @@ int rx_callback(hackrf_transfer* transfer) if (timestamp_normalized == true) { // set the timestamp of the next sweep - memset(&usb_transfer_time, - 0, - sizeof(usb_transfer_time)); gettimeofday(&usb_transfer_time, NULL); } From aaa211c6a7a126f4486a03829ae82309d2e18958 Mon Sep 17 00:00:00 2001 From: Martin Ling Date: Thu, 1 Feb 2024 17:17:42 +0000 Subject: [PATCH 5/5] Fix clang-format errors. --- host/hackrf-tools/src/hackrf_sweep.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/host/hackrf-tools/src/hackrf_sweep.c b/host/hackrf-tools/src/hackrf_sweep.c index 948b9dd47..85a47a5be 100644 --- a/host/hackrf-tools/src/hackrf_sweep.c +++ b/host/hackrf-tools/src/hackrf_sweep.c @@ -40,7 +40,7 @@ #ifndef bool typedef int bool; - #define true 1 + #define true 1 #define false 0 #endif @@ -373,8 +373,7 @@ int rx_callback(hackrf_transfer* transfer) time_str, (long int) usb_transfer_time.tv_usec, (uint64_t) (frequency + (DEFAULT_SAMPLE_RATE_HZ / 2)), - (uint64_t) (frequency + - ((DEFAULT_SAMPLE_RATE_HZ * 3) / 4)), + (uint64_t) (frequency + ((DEFAULT_SAMPLE_RATE_HZ * 3) / 4)), fft_bin_width, fftSize); for (i = 0; (fftSize / 4) > i; i++) {