hackrf_sweep: normalized timestamp (#1350)
* Added a new option (-n) to enable timestamp normalization within a same sweep
This commit is contained in:

committed by
GitHub

parent
05a03d41a4
commit
f6598e7b14
@ -185,6 +185,7 @@ uint32_t amp_enable;
|
|||||||
bool antenna = false;
|
bool antenna = false;
|
||||||
uint32_t antenna_enable;
|
uint32_t antenna_enable;
|
||||||
|
|
||||||
|
bool timestamp_normalized = false;
|
||||||
bool binary_output = false;
|
bool binary_output = false;
|
||||||
bool ifft_output = false;
|
bool ifft_output = false;
|
||||||
bool one_shot = false;
|
bool one_shot = false;
|
||||||
@ -203,6 +204,8 @@ uint32_t ifft_idx = 0;
|
|||||||
float* pwr;
|
float* pwr;
|
||||||
float* window;
|
float* window;
|
||||||
|
|
||||||
|
struct timeval usb_transfer_time;
|
||||||
|
|
||||||
float logPower(fftwf_complex in, float scale)
|
float logPower(fftwf_complex in, float scale)
|
||||||
{
|
{
|
||||||
float re = in[0] * scale;
|
float re = in[0] * scale;
|
||||||
@ -221,7 +224,6 @@ int rx_callback(hackrf_transfer* transfer)
|
|||||||
int i, j, ifft_bins;
|
int i, j, ifft_bins;
|
||||||
struct tm* fft_time;
|
struct tm* fft_time;
|
||||||
char time_str[50];
|
char time_str[50];
|
||||||
struct timeval usb_transfer_time;
|
|
||||||
|
|
||||||
if (NULL == outfile) {
|
if (NULL == outfile) {
|
||||||
return -1;
|
return -1;
|
||||||
@ -230,7 +232,14 @@ int rx_callback(hackrf_transfer* transfer)
|
|||||||
if (do_exit) {
|
if (do_exit) {
|
||||||
return 0;
|
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;
|
byte_count += transfer->valid_length;
|
||||||
buf = (int8_t*) transfer->buffer;
|
buf = (int8_t*) transfer->buffer;
|
||||||
ifft_bins = fftSize * step_count;
|
ifft_bins = fftSize * step_count;
|
||||||
@ -266,6 +275,12 @@ int rx_callback(hackrf_transfer* transfer)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
sweep_count++;
|
sweep_count++;
|
||||||
|
|
||||||
|
if (timestamp_normalized == true) {
|
||||||
|
// set the timestamp of the next sweep
|
||||||
|
gettimeofday(&usb_transfer_time, NULL);
|
||||||
|
}
|
||||||
|
|
||||||
if (one_shot) {
|
if (one_shot) {
|
||||||
do_exit = true;
|
do_exit = true;
|
||||||
} else if (finite_mode && sweep_count == num_sweeps) {
|
} 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[-N num_sweeps] # Number of sweeps to perform\n"
|
||||||
"\t[-B] # binary output\n"
|
"\t[-B] # binary output\n"
|
||||||
"\t[-I] # binary inverse FFT 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"
|
"\t-r filename # output file\n"
|
||||||
"\n"
|
"\n"
|
||||||
"Output fields:\n"
|
"Output fields:\n"
|
||||||
@ -461,7 +477,7 @@ int main(int argc, char** argv)
|
|||||||
const char* fftwWisdomPath = NULL;
|
const char* fftwWisdomPath = NULL;
|
||||||
int fftw_plan_type = FFTW_MEASURE;
|
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;
|
result = HACKRF_SUCCESS;
|
||||||
switch (opt) {
|
switch (opt) {
|
||||||
case 'd':
|
case 'd':
|
||||||
@ -542,6 +558,10 @@ int main(int argc, char** argv)
|
|||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case 'n':
|
||||||
|
timestamp_normalized = true;
|
||||||
|
break;
|
||||||
|
|
||||||
case '1':
|
case '1':
|
||||||
one_shot = true;
|
one_shot = true;
|
||||||
break;
|
break;
|
||||||
@ -681,6 +701,9 @@ int main(int argc, char** argv)
|
|||||||
*/
|
*/
|
||||||
fftwf_execute(fftwPlan);
|
fftwf_execute(fftwPlan);
|
||||||
|
|
||||||
|
// reset the timestamp
|
||||||
|
memset(&usb_transfer_time, 0, sizeof(usb_transfer_time));
|
||||||
|
|
||||||
#ifdef _MSC_VER
|
#ifdef _MSC_VER
|
||||||
if (binary_output) {
|
if (binary_output) {
|
||||||
_setmode(_fileno(stdout), _O_BINARY);
|
_setmode(_fileno(stdout), _O_BINARY);
|
||||||
|
Reference in New Issue
Block a user