Frequency list PoC
This commit is contained in:

committed by
Mike Walters

parent
2d88fe4de3
commit
c127cdc0a4
@ -33,33 +33,23 @@
|
|||||||
#define FREQ_GRANULARITY 1000000
|
#define FREQ_GRANULARITY 1000000
|
||||||
#define MIN_FREQ 1
|
#define MIN_FREQ 1
|
||||||
#define MAX_FREQ 6000
|
#define MAX_FREQ 6000
|
||||||
|
#define MAX_FREQ_COUNT 500
|
||||||
|
|
||||||
volatile bool start_sweep_mode = false;
|
volatile bool start_sweep_mode = false;
|
||||||
static uint64_t sweep_freq;
|
static uint64_t sweep_freq;
|
||||||
bool odd = true;
|
bool odd = true;
|
||||||
|
static uint16_t frequencies[MAX_FREQ_COUNT];
|
||||||
struct init_sweep_params {
|
static uint16_t frequency_count = 0;
|
||||||
uint16_t min_freq_mhz;
|
|
||||||
uint16_t max_freq_mhz;
|
|
||||||
uint16_t step_freq_mhz;
|
|
||||||
};
|
|
||||||
struct init_sweep_params sweep_params;
|
|
||||||
|
|
||||||
usb_request_status_t usb_vendor_request_init_sweep(
|
usb_request_status_t usb_vendor_request_init_sweep(
|
||||||
usb_endpoint_t* const endpoint, const usb_transfer_stage_t stage)
|
usb_endpoint_t* const endpoint, const usb_transfer_stage_t stage)
|
||||||
{
|
{
|
||||||
if ((stage == USB_TRANSFER_STAGE_SETUP) &&
|
if (stage == USB_TRANSFER_STAGE_SETUP) {
|
||||||
(endpoint->setup.length == 6)) {
|
frequency_count = endpoint->setup.length;
|
||||||
|
usb_transfer_schedule_block(endpoint->out, &frequencies,
|
||||||
usb_transfer_schedule_block(endpoint->out, &sweep_params,
|
endpoint->setup.length, NULL, NULL);
|
||||||
sizeof(struct init_sweep_params),
|
|
||||||
NULL, NULL);
|
|
||||||
} else if (stage == USB_TRANSFER_STAGE_DATA) {
|
} else if (stage == USB_TRANSFER_STAGE_DATA) {
|
||||||
/* Limit to min/max frequency without warning (possible FIXME) */
|
sweep_freq = frequencies[0];
|
||||||
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;
|
|
||||||
set_freq(sweep_freq*FREQ_GRANULARITY);
|
set_freq(sweep_freq*FREQ_GRANULARITY);
|
||||||
start_sweep_mode = true;
|
start_sweep_mode = true;
|
||||||
usb_transfer_schedule_ack(endpoint->in);
|
usb_transfer_schedule_ack(endpoint->in);
|
||||||
@ -70,6 +60,7 @@ usb_request_status_t usb_vendor_request_init_sweep(
|
|||||||
void sweep_mode(void) {
|
void sweep_mode(void) {
|
||||||
unsigned int blocks_queued = 0;
|
unsigned int blocks_queued = 0;
|
||||||
unsigned int phase = 0;
|
unsigned int phase = 0;
|
||||||
|
unsigned int ifreq = 0;
|
||||||
|
|
||||||
uint8_t *buffer;
|
uint8_t *buffer;
|
||||||
bool transfer = false;
|
bool transfer = false;
|
||||||
@ -105,16 +96,9 @@ void sweep_mode(void) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (blocks_queued > 2) {
|
if (blocks_queued > 2) {
|
||||||
if (odd)
|
if(++ifreq >= frequency_count)
|
||||||
sweep_freq += sweep_params.step_freq_mhz / 4;
|
ifreq = 0;
|
||||||
else
|
sweep_freq = frequencies[ifreq];
|
||||||
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;
|
|
||||||
}
|
|
||||||
set_freq(sweep_freq*FREQ_GRANULARITY);
|
set_freq(sweep_freq*FREQ_GRANULARITY);
|
||||||
blocks_queued = 0;
|
blocks_queued = 0;
|
||||||
}
|
}
|
||||||
|
@ -91,6 +91,9 @@ int gettimeofday(struct timeval *tv, void* ignored) {
|
|||||||
#define DEFAULT_SAMPLE_RATE_HZ (20000000) /* 20MHz default sample rate */
|
#define DEFAULT_SAMPLE_RATE_HZ (20000000) /* 20MHz default sample rate */
|
||||||
#define DEFAULT_BASEBAND_FILTER_BANDWIDTH (15000000) /* 5MHz default */
|
#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
|
#if defined _WIN32
|
||||||
#define sleep(a) Sleep( (a*1000) )
|
#define sleep(a) Sleep( (a*1000) )
|
||||||
#endif
|
#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)
|
if (result != HACKRF_SUCCESS)
|
||||||
return result;
|
return result;
|
||||||
result = parse_u32(sep + 1, value_max);
|
result = parse_u32(sep + 1, value_max);
|
||||||
if (result != HACKRF_SUCCESS);
|
if (result != HACKRF_SUCCESS)
|
||||||
return result;
|
return result;
|
||||||
|
|
||||||
return HACKRF_SUCCESS;
|
return HACKRF_SUCCESS;
|
||||||
@ -159,7 +162,6 @@ uint32_t amp_enable;
|
|||||||
bool antenna = false;
|
bool antenna = false;
|
||||||
uint32_t antenna_enable;
|
uint32_t antenna_enable;
|
||||||
|
|
||||||
bool freq_range = false;
|
|
||||||
uint32_t freq_min;
|
uint32_t freq_min;
|
||||||
uint32_t freq_max;
|
uint32_t freq_max;
|
||||||
|
|
||||||
@ -259,17 +261,17 @@ void sigint_callback_handler(int signum) {
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
int main(int argc, char** argv) {
|
int main(int argc, char** argv) {
|
||||||
int opt;
|
int opt, i, result, ifreq = 0;
|
||||||
|
bool odd;
|
||||||
const char* path = "/dev/null";
|
const char* path = "/dev/null";
|
||||||
const char* serial_number = NULL;
|
const char* serial_number = NULL;
|
||||||
int result;
|
|
||||||
int exit_code = EXIT_SUCCESS;
|
int exit_code = EXIT_SUCCESS;
|
||||||
struct timeval t_end;
|
struct timeval t_end;
|
||||||
float time_diff;
|
float time_diff;
|
||||||
unsigned int lna_gain=20, vga_gain=20, txvga_gain=0;
|
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 )
|
|
||||||
{
|
while( (opt = getopt(argc, argv, "a:f:p:l:g:x:d:")) != EOF ) {
|
||||||
result = HACKRF_SUCCESS;
|
result = HACKRF_SUCCESS;
|
||||||
switch( opt )
|
switch( opt )
|
||||||
{
|
{
|
||||||
@ -283,9 +285,18 @@ int main(int argc, char** argv) {
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case 'f':
|
case 'f':
|
||||||
freq_range = true;
|
|
||||||
result = parse_u32_range(optarg, &freq_min, &freq_max);
|
result = parse_u32_range(optarg, &freq_min, &freq_max);
|
||||||
fprintf(stderr, "Scanning %uMHz to %uMHz\n", 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;
|
break;
|
||||||
|
|
||||||
case 'p':
|
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");
|
fprintf(stderr, "argument error: must specify sweep frequency range (-f).\n");
|
||||||
usage();
|
usage();
|
||||||
return EXIT_FAILURE;
|
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);
|
fftwPlan = fftwf_plan_dft_1d(fftSize, fftwIn, fftwOut, FFTW_FORWARD, FFTW_MEASURE);
|
||||||
pwr = (float*)fftwf_malloc(sizeof(float) * fftSize);
|
pwr = (float*)fftwf_malloc(sizeof(float) * fftSize);
|
||||||
window = (float*)fftwf_malloc(sizeof(float) * fftSize);
|
window = (float*)fftwf_malloc(sizeof(float) * fftSize);
|
||||||
int i;
|
|
||||||
for (i = 0; i < fftSize; i++) {
|
for (i = 0; i < fftSize; i++) {
|
||||||
window[i] = 0.5f * (1.0f - cos(2 * M_PI * i / (fftSize - 1)));
|
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 */
|
/* 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 ) {
|
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);
|
hackrf_error_name(result), result);
|
||||||
usage();
|
usage();
|
||||||
return EXIT_FAILURE;
|
return EXIT_FAILURE;
|
||||||
|
@ -1697,24 +1697,14 @@ uint32_t ADDCALL hackrf_compute_baseband_filter_bw(const uint32_t bandwidth_hz)
|
|||||||
return p->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,
|
int ADDCALL hackrf_init_sweep(hackrf_device* device,
|
||||||
const uint16_t min_freq_mhz, const uint16_t max_freq_mhz,
|
uint16_t* frequency_list,
|
||||||
const uint16_t step_freq_mhz)
|
int length)
|
||||||
{
|
{
|
||||||
struct init_sweep_params params;
|
int result, i;
|
||||||
uint8_t length;
|
|
||||||
int result;
|
|
||||||
|
|
||||||
params.min_freq_mhz = TO_LE(min_freq_mhz);
|
for(i=0; i<length; i++)
|
||||||
params.max_freq_mhz = TO_LE(max_freq_mhz);
|
frequency_list[i] = TO_LE(frequency_list[i]);
|
||||||
params.step_freq_mhz = TO_LE(step_freq_mhz);
|
|
||||||
length = sizeof(struct init_sweep_params);
|
|
||||||
|
|
||||||
result = libusb_control_transfer(
|
result = libusb_control_transfer(
|
||||||
device->usb_device,
|
device->usb_device,
|
||||||
@ -1722,13 +1712,12 @@ int ADDCALL hackrf_init_sweep(hackrf_device* device,
|
|||||||
HACKRF_VENDOR_REQUEST_INIT_SWEEP,
|
HACKRF_VENDOR_REQUEST_INIT_SWEEP,
|
||||||
0,
|
0,
|
||||||
0,
|
0,
|
||||||
(unsigned char*)¶ms,
|
(unsigned char*)frequency_list,
|
||||||
length,
|
length,
|
||||||
0
|
0
|
||||||
);
|
);
|
||||||
|
|
||||||
if (result < length)
|
if (result < length) {
|
||||||
{
|
|
||||||
return HACKRF_ERROR_LIBUSB;
|
return HACKRF_ERROR_LIBUSB;
|
||||||
} else {
|
} else {
|
||||||
return HACKRF_SUCCESS;
|
return HACKRF_SUCCESS;
|
||||||
|
@ -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);
|
extern ADDAPI uint32_t ADDCALL hackrf_compute_baseband_filter_bw(const uint32_t bandwidth_hz);
|
||||||
/* Start scan mode */
|
/* Start scan mode */
|
||||||
extern ADDAPI int ADDCALL hackrf_init_sweep(hackrf_device* device,
|
extern ADDAPI int ADDCALL hackrf_init_sweep(hackrf_device* device,
|
||||||
const uint16_t min_freq_mhz, const uint16_t max_freq_mhz,
|
uint16_t* frequency_list,
|
||||||
const uint16_t step_freq_mhz);
|
int length);
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
} // __cplusplus defined.
|
} // __cplusplus defined.
|
||||||
|
Reference in New Issue
Block a user