随着普通电脑性能逐渐提高, DSP 能力越来越强。因此Software Define R adi o越来越受到大家的关注。本文介绍hackrf是目前最廉价的支持发射的SDR,只可惜是半双工的。hackrf是一个完全开源的项目,从软件到硬件,全部开源,因此已经国产化。可以在淘宝买到,大概1200元左右。
本文介绍了一个最简单的发射宽带FM的方法,仅供参考。
1,确认repository里的libhackrf版本并且安装正确的驱动程序
如果你使用的ubuntu或kali等版本较老的,建议使用源码的方法安装最新的libhackrf驱动。如果使用较新的操作系统如ubuntu16.xx,可以直接使用apt-get安装。
从软件仓库里安装
#apt-cahce search libhackrf-dev
#apt-get install libhackrf-dev
如果该驱动不能工作,请选下面的源码安装的方式,毕竟老的驱动支持新的硬件是比较困难的。
从源码的方式安装
编译安装hackrf要确保已经使用apt-get安装的清理干净,使用下面的命令
#apt list | grep hackrf
把搜索出来的结果,使用 apt-get remove 全部删除。
编译条件,需要安装cmake lib usb fft w 的开发包。
#apt-get install cmake libusb-1.0-0-dev libfftw3-dev
克隆代码:
#git clone https://github.com/mossmann/hackrf.git
Prerequisi te s for Linux (Debian/Ubuntu):
sudo apt-get install build-essen ti al cmake libusb-1.0-0-dev pkg-config libfftw3-dev
Build host software on Linux:
mkdir host/buildcd host/buildcmake 。.makesudo make installsudo ldconfig
2,下载发射程序
#git clone https://github.com/aricwang88/hackrf_WBFM_Trans mi t.git
准备 测试 数据源
Op TI on 1: Download or clone the test wave file f rom github.
git clone https://github.com/aricwang88/hackrf_example_res.git
Op TI on 2: Install ffmpeg or libav-tools to convert the mp3 to wave file.
Search in repository:
apt-cache search libav-toolslibav-tools - Mul TI media player, server, encoder and transcoderapt-get install libav-toolsavconv -i mm_didu.mp3 -acodec pcm_s1 6l e -ac 2 -ar 44100 -vol 200 MM_didu.wav编译
gcc -o HACKRF_WBFM_Transmit HackRF_WBFM_Transmit.c -lm -lhackrformakemake wav
编译出可执行程序 HACKRF_WBFM_Transmit.
chmod +x HACKRF_WBFM_Transmit./HACKRF_WBFM_TransmitUsage:。/HACKRF_WBFM_Transmit验证
I also upload the test wave file, please clone from other repository or convert from mp3 by ffmpeg.
。/HACKRF_WBFM_Transmit MM_didu.wavHACKRF WBFM Transmit demo 。..Begin to init hackrf 。..hackrf_init sucessfully!hackrf_open() success.Board ID Number: 2 (HackRF One)Firmware Ve rs ion: 2015.07.2HACKRF init done.Load wav file:MM_didu.wav(1-4): RIFF (5-8) Overall size: bytes:32360616, Kb:31602 (9-12) Wave marker: WAVE(13-16) Fmt marker: fmt 16 0 0 0(17-20) Length of Fmt header: 16 1 0 (21-22) Format type: 1 PCM 2 0 (23-24) Channels: 2 (25-28) Sample rate: 44100(29-32) Byte Rate: 176400 , Bit Rate:14112004 0 (33-34) Block Alignment: 4 16 0 (35-36) Bits per sample: 16 (37-40) Data Marker: data (41-44) Size of data chunk: 32360580 Number of samples:8090145 Size of each sample:4 bytesApprox.Dura TI on in seconds=183.450211Approx.Duration in h:m:s=0:3:3.450.Valid range for data values : -32768 to 32767 Alloc memory resample done.Alloc memory IQ data done.Alloc memory TX data done.Begin to process data 。..(Please w ai t about 20 seconds.)Processing: 0.00%Processing: 5.45%Processing: 10.90%Processing: 16.35%Processing: 21.80%Processing: 27.26%Processing: 32.71%Processing: 38.16%Processing: 43.61%Processing: 49.06%Processing: 54.51%Processing: 59.96%Processing: 65.41%Processing: 70.86%Processing: 76.32%Processing: 81.77%Processing: 87.22%Processing: 92.67%Processing: 98.12%IQ data transcode done.Release intermedia memory.Data process done, transmiting 。..
Ctrl+C to stop transmiting.