hackrf_sweep: normalized timestamp (#1350)

* Added a new option (-n) to enable timestamp normalization within a same sweep
This commit is contained in:
Gabriele Gristina
2024-02-01 18:24:55 +01:00
committed by GitHub
parent 05a03d41a4
commit f6598e7b14

View File

@ -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,14 @@ int rx_callback(hackrf_transfer* transfer)
if (do_exit) {
return 0;
}
// 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 +275,12 @@ int rx_callback(hackrf_transfer* transfer)
}
}
sweep_count++;
if (timestamp_normalized == true) {
// set the timestamp of the next sweep
gettimeofday(&usb_transfer_time, NULL);
}
if (one_shot) {
do_exit = true;
} else if (finite_mode && sweep_count == num_sweeps) {
@ -388,6 +403,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 +477,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:w:W:P:n1BIr:h?")) != EOF) {
result = HACKRF_SUCCESS;
switch (opt) {
case 'd':
@ -542,6 +558,10 @@ int main(int argc, char** argv)
}
break;
case 'n':
timestamp_normalized = true;
break;
case '1':
one_shot = true;
break;
@ -681,6 +701,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);