Merge pull request #545 from GravesJake/sweep_n

Add limited sweep mode
This commit is contained in:
Dominic Spill
2018-11-07 11:48:51 -07:00
committed by GitHub

View File

@ -102,10 +102,13 @@ int gettimeofday(struct timeval *tv, void* ignored) {
#define THROWAWAY_BLOCKS 2
#if defined _WIN32
#define sleep(a) Sleep( (a*1000) )
#define m_sleep(a) Sleep( (a) )
#else
#define m_sleep(a) usleep((a*1000))
#endif
uint32_t num_samples = SAMPLES_PER_BLOCK;
uint32_t num_sweeps = 0;
int num_ranges = 0;
uint16_t frequencies[MAX_SWEEP_RANGES*2];
int step_count;
@ -179,6 +182,7 @@ uint32_t antenna_enable;
bool binary_output = false;
bool ifft_output = false;
bool one_shot = false;
bool finite_mode = false;
volatile bool sweep_started = false;
int fftSize = 20;
@ -245,6 +249,9 @@ int rx_callback(hackrf_transfer* transfer) {
if(one_shot) {
do_exit = true;
}
else if(finite_mode && sweep_count == num_sweeps) {
do_exit = true;
}
}
sweep_started = true;
time_stamp = usb_transfer_time;
@ -352,6 +359,7 @@ static void usage() {
fprintf(stderr, "\t[-n num_samples] # Number of samples per frequency, 8192-4294967296\n");
fprintf(stderr, "\t[-w bin_width] # FFT bin width (frequency resolution) in Hz\n");
fprintf(stderr, "\t[-1] # one shot mode\n");
fprintf(stderr, "\t[-N num_sweeps] # Number of sweeps to perform\n");
fprintf(stderr, "\t[-B] # binary output\n");
fprintf(stderr, "\t[-I] # binary inverse FFT output\n");
fprintf(stderr, "\t-r filename # output file\n");
@ -393,7 +401,7 @@ int main(int argc, char** argv) {
uint32_t requested_fft_bin_width;
while( (opt = getopt(argc, argv, "a:f:p:l:g:d:n:w:1BIr:h?")) != EOF ) {
while( (opt = getopt(argc, argv, "a:f:p:l:g:d:n:N:w:1BIr:h?")) != EOF ) {
result = HACKRF_SUCCESS;
switch( opt )
{
@ -450,6 +458,11 @@ int main(int argc, char** argv) {
result = parse_u32(optarg, &num_samples);
break;
case 'N':
finite_mode = true;
result = parse_u32(optarg, &num_sweeps);
break;
case 'w':
result = parse_u32(optarg, &requested_fft_bin_width);
fftSize = DEFAULT_SAMPLE_RATE_HZ / requested_fft_bin_width;
@ -693,8 +706,8 @@ int main(int argc, char** argv) {
fprintf(stderr, "Stop with Ctrl-C\n");
while((hackrf_is_streaming(device) == HACKRF_TRUE) && (do_exit == false)) {
float time_difference;
sleep(1);
m_sleep(50);
gettimeofday(&time_now, NULL);
time_difference = TimevalDiff(&time_now, &t_start);