项目创建

 

 

 

 

 

 

 

 

 

 

程序编写

动态加载程序编写(runtime)

       修改项目属性:
      快捷键Alt+F7

 

 

 

 

 

 

 

 

 

新建”HackRF.h”

加入 HackRF动态库中一些相关定义

#ifndef __HACKRF_H__
#define __HACKRF_H__
#include "stdint.h"
enum hackrf_error {
HACKRF_SUCCESS = 0,
HACKRF_TRUE = 1,
HACKRF_ERROR_INVALID_PARAM = -2,
HACKRF_ERROR_NOT_FOUND = -5,
HACKRF_ERROR_BUSY = -6,
HACKRF_ERROR_NO_MEM = -11,
HACKRF_ERROR_LIBUSB = -1000,
HACKRF_ERROR_THREAD = -1001,
HACKRF_ERROR_STREAMING_THREAD_ERR = -1002,
HACKRF_ERROR_STREAMING_STOPPED = -1003,
HACKRF_ERROR_STREAMING_EXIT_CALLED = -1004,
HACKRF_ERROR_OTHER = -9999,
};
enum hackrf_board_id {
BOARD_ID_JELLYBEAN  = 0,
BOARD_ID_JAWBREAKER = 1,
BOARD_ID_HACKRF_ONE = 2,
BOARD_ID_INVALID = 0xFF,
};
enum rf_path_filter {
RF_PATH_FILTER_BYPASS = 0,
RF_PATH_FILTER_LOW_PASS = 1,
RF_PATH_FILTER_HIGH_PASS = 2,
};
typedef struct hackrf_device hackrf_device ;
typedef struct {
hackrf_device* device;
uint8_t* buffer;
int buffer_length;
int valid_length;
void* rx_ctx;
void* tx_ctx;
} hackrf_transfer;
typedef struct {
uint32_t part_id[2];
uint32_t serial_no[4];
} read_partid_serialno_t;
#endif

 

 

在main函数中动态加载 以 hackrf_init  hackrf_open为例

#include "stdafx.h"
#include "hackrf.h"
#include "windows.h"
#define NEWCALLBACK __cdecl
typedef int (NEWCALLBACK *PROHackrf_init )();//typedef  返回值类型 (CALLBACK *类型名)(参数1,参数2,...)
PROHackrf_init hackrf_init;
typedef int (NEWCALLBACK *PROHackrf_open)(hackrf_device** device)
PROHackrf_open hackrf_open;
HINSTANCE hHACKRFDLL;
void init()
{
hackrf_device* device = NULL;
hHACKRFDLL = LoadLibrary( _T( "hackrf.dll"));
hackrf_init  = ( PROHackrf_init)GetProcAddress(hHACKRFDLL,"hackrf_init" );

hackrf_open = ( PROHackrf_open )GetProcAddress(hHACKRFDLL,"hackrf_open " );
}
void Free()
{
FreeLibrary(hHACKRFDLL);
} 
int _tmain (int argc , _TCHAR * argv [])
{

init();
int result = hackrf_init();
if( result != HACKRF_SUCCESS ) 
return 1;
result = hackrf_open(&device);
if( result != HACKRF_SUCCESS )
return 1;
Free();
return 0;
}

 

将libusb-1.0.dll pthreadVSE2.dll hackrf.dll拷贝到项目目录下编译运行

隐式链接(loadtime)

 

将libgetopt_static.lib(非必须);libusb-1.0.lib;pthreadVSE2.lib;hackrf.lib填入

 

 

 

将libgetopt_static.lib(非必须);libusb-1.0.lib;pthreadVSE2.lib;hackrf.lib libusb-1.0.dll pthreadVSE2.dll hackrf.dll hackrf.h getopt.h(非必须)拷贝到项目目录下

修改main函数

 

#include "stdafx.h"
#include "hackrf.h"
#include "windows.h"
int _tmain (int argc , _TCHAR * argv [])
{   
hackrf_device* device = NULL;          
int result = hackrf_init();
if( result != HACKRF_SUCCESS )return 1;
result = hackrf_open(&device);
if( result != HACKRF_SUCCESS )return 1;
return 0;
}

附录:

 hackrf函数:
int hackrf_init();
int hackrf_exit();
int hackrf_open(hackrf_device** device);
int hackrf_close(hackrf_device* device);
int hackrf_start_rx(hackrf_device* device, hackrf_sample_block_cb_fn callback, void * rx_ctx);
int hackrf_stop_rx(hackrf_device* device);
int hackrf_start_tx(hackrf_device* device, hackrf_sample_block_cb_fn callback, void * tx_ctx);
int hackrf_stop_tx(hackrf_device* device);
/* return HACKRF_TRUE if success */
int hackrf_is_streaming(hackrf_device* device);
int  hackrf_max2837_read(hackrf_device* device, uint8_t register_number, uint16_t* value);
int  hackrf_max2837_write(hackrf_device* device, uint8_t register_number, uint16_t value);
int  hackrf_si5351c_read(hackrf_device* device, uint16_t register_number, uint16_t* value);
int  hackrf_si5351c_write(hackrf_device* device, uint16_t register_number, uint16_t value);
int  hackrf_set_baseband_filter_bandwidth(hackrf_device* device, const uint32_t bandwidth_hz);
int  hackrf_rffc5071_read(hackrf_device* device, uint8_t register_number, uint16_t* value);
int  hackrf_rffc5071_write(hackrf_device* device, uint8_t register_number, uint16_t value);
int  hackrf_spiflash_erase(hackrf_device* device);
int  hackrf_spiflash_write(hackrf_device* device, const uint32_t address, const uint16_t length, unsigned char * const data);
int  hackrf_spiflash_read(hackrf_device* device, const uint32_t address, const uint16_t length, unsigned char * data);
/* device will need to be reset after hackrf_cpld_write */
int  hackrf_cpld_write(hackrf_device* device,unsigned char* const data, const unsigned int total_length);       int  hackrf_board_id_read(hackrf_device* device, uint8_t* value);
int  hackrf_version_string_read(hackrf_device* device, char* version, uint8_t length);
int  hackrf_set_freq(hackrf_device* device, const uint64_t freq_hz);
int  hackrf_set_freq_explicit(hackrf_device* device,const uint64_t if_freq_hz, const uint64_t lo_freq_hz,const enum rf_path_filter path);
/* currently 8-20Mhz - either as a fraction, i.e. freq 20000000hz divider 2 -> 10Mhz or as plain old 10000000hz (double)preferred rates are 8, 10, 12.5, 16, 20Mhz due to less jitter */
int  hackrf_set_sample_rate_manual(hackrf_device* device, const uint32_t freq_hz, const uint32_t divider);
int  hackrf_set_sample_rate(hackrf_device* device, const double freq_hz);
/* external amp, bool on/off */
int  hackrf_set_amp_enable(hackrf_device* device, const uint8_t value);
int  hackrf_board_partid_serialno_read(hackrf_device* device, read_partid_serialno_t* read_partid_serialno);
/* range 0-40 step 8db */
int  hackrf_set_lna_gain(hackrf_device* device, uint32_t value);
/* range 0-62 step 2db */
int  hackrf_set_vga_gain(hackrf_device* device, uint32_t value);
/* range 0-47 step 1db */
int  hackrf_set_txvga_gain(hackrf_device* device, uint32_t value);
/* antenna port power control */
int  hackrf_set_antenna_enable(hackrf_device* device, const uint8_t value);
const char *  hackrf_error_name(enum hackrf_error errcode);
const char *  hackrf_board_id_name(enum hackrf_board_id board_id);
const char *  hackrf_filter_path_name(const enum rf_path_filter path);
/* Compute nearest freq for bw filter (manual filter) */
uint32_t  hackrf_compute_baseband_filter_bw_round_down_lt(const uint32_t bandwidth_hz);
/* Compute best default value depending on sample rate (auto filter) */
uint32_t  hackrf_compute_baseband_filter_bw(const uint32_t bandwidth_hz);

 

例子

链接:http://pan.baidu.com/s/1mgqPpK8 密码:uhci