Skip to content

Commit

Permalink
hackrf_sweep: normalized timestamp (#1350)
Browse files Browse the repository at this point in the history
* Added a new option (-n) to enable timestamp normalization within a same sweep
  • Loading branch information
matrix authored Feb 1, 2024
1 parent 05a03d4 commit f6598e7
Showing 1 changed file with 26 additions and 3 deletions.
29 changes: 26 additions & 3 deletions host/hackrf-tools/src/hackrf_sweep.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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;
Expand All @@ -230,7 +232,14 @@ 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;
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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':
Expand Down Expand Up @@ -542,6 +558,10 @@ int main(int argc, char** argv)
}
break;

case 'n':
timestamp_normalized = true;
break;

case '1':
one_shot = true;
break;
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit f6598e7

Please sign in to comment.