Add init_scan call to libhackrf

This commit is contained in:
Mike Walters
2016-07-24 17:48:06 +01:00
parent 1b8e1d18c5
commit 97c317e9a4
3 changed files with 54 additions and 11 deletions

View File

@ -39,27 +39,26 @@ static uint64_t scan_freq_min;
static uint64_t scan_freq_max;
static uint64_t scan_freq_step;
static inline uint64_t bytes_to_uint64(uint8_t* buf) {
uint64_t tmp = buf[0] << 24 | buf[1] << 16 | buf[2] << 8 | buf[3];
tmp <<= 32;
tmp |= buf[4] << 24 | buf[5] << 16 | buf[6] << 8 | buf[7];
return tmp;
}
struct init_scan_params {
uint64_t min_freq_hz;
uint64_t max_freq_hz;
uint64_t step_freq_hz;
};
struct init_scan_params scan_params;
usb_request_status_t usb_vendor_request_init_scan(
usb_endpoint_t* const endpoint, const usb_transfer_stage_t stage)
{
uint64_t freqs[3];
if ((stage == USB_TRANSFER_STAGE_SETUP) &&
(endpoint->setup.length == 24)) {
// DGS set scan frequencies here
//freq_min = bytes_to_uint64();
usb_transfer_schedule_block(endpoint->out, &freqs, 3*sizeof(uint64_t),
usb_transfer_schedule_block(endpoint->out, &scan_params, sizeof(struct init_scan_params),
NULL, NULL);
scan_freq_min = MAX(MIN_FREQ, freqs[0]);
scan_freq_max = MIN(MAX_FREQ, freqs[1]);
scan_freq_step = freqs[2];
scan_freq_min = MAX(MIN_FREQ, scan_params.min_freq_hz);
scan_freq_max = MIN(MAX_FREQ, scan_params.max_freq_hz);
scan_freq_step = scan_params.step_freq_hz;
scan_freq = scan_freq_min;
set_freq(scan_freq);

View File

@ -67,6 +67,8 @@ typedef enum {
HACKRF_VENDOR_REQUEST_SET_TXVGA_GAIN = 21,
HACKRF_VENDOR_REQUEST_ANTENNA_ENABLE = 23,
HACKRF_VENDOR_REQUEST_SET_FREQ_EXPLICIT = 24,
// USB_WCID_VENDOR_REQ = 25
HACKRF_VENDOR_REQUEST_INIT_SCAN = 26,
} hackrf_vendor_request;
typedef enum {
@ -1695,6 +1697,44 @@ uint32_t ADDCALL hackrf_compute_baseband_filter_bw(const uint32_t bandwidth_hz)
return p->bandwidth_hz;
}
struct init_scan_params {
uint64_t min_freq_hz;
uint64_t max_freq_hz;
uint64_t step_freq_hz;
};
int ADDCALL hackrf_init_scan(hackrf_device* device,
const uint64_t min_freq_hz, const uint64_t max_freq_hz,
const uint64_t step_freq_hz)
{
struct init_scan_params params;
uint8_t length;
int result;
params.min_freq_hz = TO_LE(min_freq_hz);
params.max_freq_hz = TO_LE(max_freq_hz);
params.step_freq_hz = TO_LE(step_freq_hz);
length = sizeof(struct init_scan_params);
result = libusb_control_transfer(
device->usb_device,
LIBUSB_ENDPOINT_OUT | LIBUSB_REQUEST_TYPE_VENDOR | LIBUSB_RECIPIENT_DEVICE,
HACKRF_VENDOR_REQUEST_INIT_SCAN,
0,
0,
(unsigned char*)&params,
length,
0
);
if (result < length)
{
return HACKRF_ERROR_LIBUSB;
} else {
return HACKRF_SUCCESS;
}
}
#ifdef __cplusplus
} // __cplusplus defined.
#endif

View File

@ -196,6 +196,10 @@ extern ADDAPI const char* ADDCALL hackrf_filter_path_name(const enum rf_path_fil
extern ADDAPI uint32_t ADDCALL hackrf_compute_baseband_filter_bw_round_down_lt(const uint32_t bandwidth_hz);
/* Compute best default value depending on sample rate (auto filter) */
extern ADDAPI uint32_t ADDCALL hackrf_compute_baseband_filter_bw(const uint32_t bandwidth_hz);
/* Start scan mode */
extern ADDAPI int ADDCALL hackrf_init_scan(hackrf_device* device,
const uint64_t min_freq_hz, const uint64_t max_freq_hz,
const uint64_t step_freq_hz);
#ifdef __cplusplus
} // __cplusplus defined.