Frequency list PoC

This commit is contained in:
Dominic Spill
2016-09-08 17:10:39 +01:00
committed by Mike Walters
parent 2d88fe4de3
commit c127cdc0a4
4 changed files with 44 additions and 61 deletions

View File

@ -33,33 +33,23 @@
#define FREQ_GRANULARITY 1000000
#define MIN_FREQ 1
#define MAX_FREQ 6000
#define MAX_FREQ_COUNT 500
volatile bool start_sweep_mode = false;
static uint64_t sweep_freq;
bool odd = true;
struct init_sweep_params {
uint16_t min_freq_mhz;
uint16_t max_freq_mhz;
uint16_t step_freq_mhz;
};
struct init_sweep_params sweep_params;
static uint16_t frequencies[MAX_FREQ_COUNT];
static uint16_t frequency_count = 0;
usb_request_status_t usb_vendor_request_init_sweep(
usb_endpoint_t* const endpoint, const usb_transfer_stage_t stage)
{
if ((stage == USB_TRANSFER_STAGE_SETUP) &&
(endpoint->setup.length == 6)) {
usb_transfer_schedule_block(endpoint->out, &sweep_params,
sizeof(struct init_sweep_params),
NULL, NULL);
if (stage == USB_TRANSFER_STAGE_SETUP) {
frequency_count = endpoint->setup.length;
usb_transfer_schedule_block(endpoint->out, &frequencies,
endpoint->setup.length, NULL, NULL);
} else if (stage == USB_TRANSFER_STAGE_DATA) {
/* Limit to min/max frequency without warning (possible FIXME) */
sweep_params.min_freq_mhz = MAX(MIN_FREQ, sweep_params.min_freq_mhz);
sweep_params.max_freq_mhz = MIN(MAX_FREQ, sweep_params.max_freq_mhz);
sweep_freq = sweep_params.min_freq_mhz;
sweep_freq = frequencies[0];
set_freq(sweep_freq*FREQ_GRANULARITY);
start_sweep_mode = true;
usb_transfer_schedule_ack(endpoint->in);
@ -70,6 +60,7 @@ usb_request_status_t usb_vendor_request_init_sweep(
void sweep_mode(void) {
unsigned int blocks_queued = 0;
unsigned int phase = 0;
unsigned int ifreq = 0;
uint8_t *buffer;
bool transfer = false;
@ -105,16 +96,9 @@ void sweep_mode(void) {
}
if (blocks_queued > 2) {
if (odd)
sweep_freq += sweep_params.step_freq_mhz / 4;
else
sweep_freq += 3 * (sweep_params.step_freq_mhz / 4);
odd = !odd;
if (sweep_freq > sweep_params.max_freq_mhz) {
odd = true;
sweep_freq = sweep_params.min_freq_mhz;
}
if(++ifreq >= frequency_count)
ifreq = 0;
sweep_freq = frequencies[ifreq];
set_freq(sweep_freq*FREQ_GRANULARITY);
blocks_queued = 0;
}

View File

@ -91,6 +91,9 @@ int gettimeofday(struct timeval *tv, void* ignored) {
#define DEFAULT_SAMPLE_RATE_HZ (20000000) /* 20MHz default sample rate */
#define DEFAULT_BASEBAND_FILTER_BANDWIDTH (15000000) /* 5MHz default */
#define FREQ_STEP (DEFAULT_SAMPLE_RATE_HZ / FREQ_ONE_MHZ)
#define MAX_FREQ_COUNT 500
#if defined _WIN32
#define sleep(a) Sleep( (a*1000) )
#endif
@ -139,7 +142,7 @@ int parse_u32_range(char* s, uint32_t* const value_min, uint32_t* const value_ma
if (result != HACKRF_SUCCESS)
return result;
result = parse_u32(sep + 1, value_max);
if (result != HACKRF_SUCCESS);
if (result != HACKRF_SUCCESS)
return result;
return HACKRF_SUCCESS;
@ -159,7 +162,6 @@ uint32_t amp_enable;
bool antenna = false;
uint32_t antenna_enable;
bool freq_range = false;
uint32_t freq_min;
uint32_t freq_max;
@ -259,17 +261,17 @@ void sigint_callback_handler(int signum) {
#endif
int main(int argc, char** argv) {
int opt;
int opt, i, result, ifreq = 0;
bool odd;
const char* path = "/dev/null";
const char* serial_number = NULL;
int result;
int exit_code = EXIT_SUCCESS;
struct timeval t_end;
float time_diff;
unsigned int lna_gain=20, vga_gain=20, txvga_gain=0;
while( (opt = getopt(argc, argv, "a:f:p:l:g:x:d:")) != EOF )
{
unsigned int lna_gain=16, vga_gain=20, txvga_gain=0;
uint16_t frequencies[MAX_FREQ_COUNT];
while( (opt = getopt(argc, argv, "a:f:p:l:g:x:d:")) != EOF ) {
result = HACKRF_SUCCESS;
switch( opt )
{
@ -283,9 +285,18 @@ int main(int argc, char** argv) {
break;
case 'f':
freq_range = true;
result = parse_u32_range(optarg, &freq_min, &freq_max);
fprintf(stderr, "Scanning %uMHz to %uMHz\n", freq_min, freq_max);
frequencies[ifreq++] = freq_min;
odd = true;
while(frequencies[ifreq-1] <= freq_max) {
if (odd)
frequencies[ifreq] = frequencies[ifreq-1] + FREQ_STEP / 4;
else
frequencies[ifreq] = frequencies[ifreq-1] + 3*(FREQ_STEP/4);
ifreq++;
odd = !odd;
}
break;
case 'p':
@ -340,7 +351,7 @@ int main(int argc, char** argv) {
}
}
if (!freq_range) {
if (ifreq == 0) {
fprintf(stderr, "argument error: must specify sweep frequency range (-f).\n");
usage();
return EXIT_FAILURE;
@ -352,7 +363,6 @@ int main(int argc, char** argv) {
fftwPlan = fftwf_plan_dft_1d(fftSize, fftwIn, fftwOut, FFTW_FORWARD, FFTW_MEASURE);
pwr = (float*)fftwf_malloc(sizeof(float) * fftSize);
window = (float*)fftwf_malloc(sizeof(float) * fftSize);
int i;
for (i = 0; i < fftSize; i++) {
window[i] = 0.5f * (1.0f - cos(2 * M_PI * i / (fftSize - 1)));
}
@ -424,9 +434,9 @@ int main(int argc, char** argv) {
}
/* DGS FIXME: allow upper and lower frequencies to be set */
result = hackrf_init_sweep(device, freq_min, freq_max, 20);
result = hackrf_init_sweep(device, frequencies, ifreq);
if( result != HACKRF_SUCCESS ) {
fprintf(stderr, "hackrf_init_scan() failed: %s (%d)\n",
fprintf(stderr, "hackrf_init_sweep() failed: %s (%d)\n",
hackrf_error_name(result), result);
usage();
return EXIT_FAILURE;

View File

@ -1697,24 +1697,14 @@ uint32_t ADDCALL hackrf_compute_baseband_filter_bw(const uint32_t bandwidth_hz)
return p->bandwidth_hz;
}
struct init_sweep_params {
uint16_t min_freq_mhz;
uint16_t max_freq_mhz;
uint16_t step_freq_mhz;
};
int ADDCALL hackrf_init_sweep(hackrf_device* device,
const uint16_t min_freq_mhz, const uint16_t max_freq_mhz,
const uint16_t step_freq_mhz)
uint16_t* frequency_list,
int length)
{
struct init_sweep_params params;
uint8_t length;
int result;
int result, i;
params.min_freq_mhz = TO_LE(min_freq_mhz);
params.max_freq_mhz = TO_LE(max_freq_mhz);
params.step_freq_mhz = TO_LE(step_freq_mhz);
length = sizeof(struct init_sweep_params);
for(i=0; i<length; i++)
frequency_list[i] = TO_LE(frequency_list[i]);
result = libusb_control_transfer(
device->usb_device,
@ -1722,13 +1712,12 @@ int ADDCALL hackrf_init_sweep(hackrf_device* device,
HACKRF_VENDOR_REQUEST_INIT_SWEEP,
0,
0,
(unsigned char*)&params,
(unsigned char*)frequency_list,
length,
0
);
if (result < length)
{
if (result < length) {
return HACKRF_ERROR_LIBUSB;
} else {
return HACKRF_SUCCESS;

View File

@ -198,8 +198,8 @@ extern ADDAPI uint32_t ADDCALL hackrf_compute_baseband_filter_bw_round_down_lt(c
extern ADDAPI uint32_t ADDCALL hackrf_compute_baseband_filter_bw(const uint32_t bandwidth_hz);
/* Start scan mode */
extern ADDAPI int ADDCALL hackrf_init_sweep(hackrf_device* device,
const uint16_t min_freq_mhz, const uint16_t max_freq_mhz,
const uint16_t step_freq_mhz);
uint16_t* frequency_list,
int length);
#ifdef __cplusplus
} // __cplusplus defined.