support multiple frequency ranges in hackrf_sweep

This commit is contained in:
Michael Ossmann
2017-02-07 15:37:26 -07:00
parent 5c196eab4d
commit 4b6de820ef
2 changed files with 45 additions and 26 deletions

View File

@ -38,4 +38,4 @@ usb_request_status_t usb_vendor_request_init_sweep(
void sweep_mode(void); void sweep_mode(void);
#endif /* __USB_API_SPCAN_H__ */ #endif /* __USB_API_SWEEP_H__ */

View File

@ -106,6 +106,9 @@ int gettimeofday(struct timeval *tv, void* ignored) {
#define sleep(a) Sleep( (a*1000) ) #define sleep(a) Sleep( (a*1000) )
#endif #endif
int num_ranges = 0;
uint16_t frequencies[MAX_SWEEP_RANGES*2];
static float TimevalDiff(const struct timeval *a, const struct timeval *b) { static float TimevalDiff(const struct timeval *a, const struct timeval *b) {
return (a->tv_sec - b->tv_sec) + 1e-6f * (a->tv_usec - b->tv_usec); return (a->tv_sec - b->tv_sec) + 1e-6f * (a->tv_usec - b->tv_usec);
} }
@ -170,9 +173,6 @@ uint32_t amp_enable;
bool antenna = false; bool antenna = false;
uint32_t antenna_enable; uint32_t antenna_enable;
uint32_t freq_min = 10;
uint32_t freq_max = 6000;
bool binary_output = false; bool binary_output = false;
int fftSize; int fftSize;
@ -314,9 +314,11 @@ int main(int argc, char** argv) {
struct timeval t_end; struct timeval t_end;
float time_diff; float time_diff;
unsigned int lna_gain=16, vga_gain=20; unsigned int lna_gain=16, vga_gain=20;
uint16_t frequencies[MAX_SWEEP_RANGES*2];
uint32_t num_samples = DEFAULT_SAMPLE_COUNT; uint32_t num_samples = DEFAULT_SAMPLE_COUNT;
int step_count; int step_count;
uint32_t freq_min = 0;
uint32_t freq_max = 6000;
while( (opt = getopt(argc, argv, "a:f:p:l:g:d:n:Bh?")) != EOF ) { while( (opt = getopt(argc, argv, "a:f:p:l:g:d:n:Bh?")) != EOF ) {
result = HACKRF_SUCCESS; result = HACKRF_SUCCESS;
@ -333,6 +335,29 @@ int main(int argc, char** argv) {
case 'f': case 'f':
result = parse_u32_range(optarg, &freq_min, &freq_max); result = parse_u32_range(optarg, &freq_min, &freq_max);
if(freq_min >= freq_max) {
fprintf(stderr,
"argument error: freq_max must be greater than freq_min.\n");
usage();
return EXIT_FAILURE;
}
if(FREQ_MAX_MHZ <freq_max) {
fprintf(stderr,
"argument error: freq_max may not be higher than %u.\n",
FREQ_MAX_MHZ);
usage();
return EXIT_FAILURE;
}
if(MAX_SWEEP_RANGES <= num_ranges) {
fprintf(stderr,
"argument error: specify a maximum of %u frequency ranges.\n",
MAX_SWEEP_RANGES);
usage();
return EXIT_FAILURE;
}
frequencies[2*num_ranges] = (uint16_t)freq_min;
frequencies[2*num_ranges+1] = (uint16_t)freq_max;
num_ranges++;
break; break;
case 'p': case 'p':
@ -406,17 +431,10 @@ int main(int argc, char** argv) {
} }
} }
if (freq_min >= freq_max) { if (0 == num_ranges) {
fprintf(stderr, "argument error: freq_max must be greater than freq_min.\n"); frequencies[0] = (uint16_t)freq_min;
usage(); frequencies[1] = (uint16_t)freq_max;
return EXIT_FAILURE; num_ranges++;
}
if (FREQ_MAX_MHZ <freq_max) {
fprintf(stderr, "argument error: freq_max may not be higher than %u.\n",
FREQ_MAX_MHZ);
usage();
return EXIT_FAILURE;
} }
fftSize = FFT_SIZE; fftSize = FFT_SIZE;
@ -496,18 +514,19 @@ int main(int argc, char** argv) {
} }
/* /*
* Plan a whole number of tuning steps of a certain bandwidth. * For each range, plan a whole number of tuning steps of a certain
* Increase freq_max if necessary to accomodate a whole number of steps, * bandwidth. Increase high end of range if necessary to accommodate a
* minimum 1. * whole number of steps, minimum 1.
*/ */
step_count = 1 + (freq_max - freq_min - 1) / TUNE_STEP; for(i = 0; i < num_ranges; i++) {
freq_max = freq_min + step_count * TUNE_STEP; step_count = 1 + (frequencies[2*i+1] - frequencies[2*i] - 1)
/ TUNE_STEP;
frequencies[2*i+1] = frequencies[2*i] + step_count * TUNE_STEP;
fprintf(stderr, "Sweeping from %u MHz to %u MHz\n",
frequencies[2*i], frequencies[2*i+1]);
}
fprintf(stderr, "Sweeping from %u MHz to %u MHz\n", freq_min, freq_max); result = hackrf_init_sweep(device, frequencies, num_ranges, num_samples,
frequencies[0] = freq_min;
frequencies[1] = freq_max;
result = hackrf_init_sweep(device, frequencies, 1, num_samples,
TUNE_STEP * FREQ_ONE_MHZ, OFFSET, INTERLEAVED); TUNE_STEP * FREQ_ONE_MHZ, OFFSET, INTERLEAVED);
if( result != HACKRF_SUCCESS ) { if( result != HACKRF_SUCCESS ) {
fprintf(stderr, "hackrf_init_sweep() failed: %s (%d)\n", fprintf(stderr, "hackrf_init_sweep() failed: %s (%d)\n",