py-hackrf-ctypes/README.md

48 lines
1.3 KiB
Markdown
Raw Normal View History

2014-12-24 23:04:37 -05:00
pyhackrf-ctypes
==============
pyhackrf-ctypes is a Python wrapper for libhackrf.<br>
2014-12-26 07:28:58 -05:00
I create this project because I want a simple Python interface to my hackrf board.
2014-12-25 04:27:06 -05:00
At First I use pyusb to directly get the data from HackRF, then I found pyusb can only move data at a rate of 5MiB/S, too slow for HackRF.So I choose to use ctypes .
2014-12-24 23:04:37 -05:00
# Dependencies
2014-12-24 23:08:28 -05:00
* libusb,NumPy
2014-12-24 23:04:37 -05:00
* Python 2.7.x/3.3+
2014-12-24 23:09:22 -05:00
* [libhackrf](https://github.com/mossmann/hackrf/tree/master/host)
2014-12-24 23:04:37 -05:00
2014-12-24 23:07:22 -05:00
sudo apt-get install python-dev,libusb-1.0-0
2014-12-24 23:08:28 -05:00
2014-12-24 23:04:37 -05:00
## Examples
```python
import pylibhackrf ,ctypes
hackrf = pylibhackrf.HackRf()
if hackrf.is_open == False:
hackrf.setup()
2014-12-24 23:13:49 -05:00
hackrf.set_freq(100 * 1000 * 1000)
hackrf.set_sample_rate(8 * 1000 * 1000)
2014-12-24 23:04:37 -05:00
hackrf.set_amp_enable(False)
2014-12-24 23:13:49 -05:00
hackrf.set_lna_gain(16)
hackrf.set_vga_gain(20)
hackrf.set_baseband_filter_bandwidth(1 * 1000 * 1000)
2014-12-24 23:04:37 -05:00
def callback_fun(hackrf_transfer):
array_type = (ctypes.c_byte*length)
2014-12-24 23:04:37 -05:00
values = ctypes.cast(hackrf_transfer.contents.buffer, ctypes.POINTER(array_type)).contents
#iq data here
iq = hackrf.packed_bytes_to_iq(values)
return 0
hackrf.start_rx_mode(callback_fun)
```
# Todo
There are a few remaining functions in libhackrf haven't been wrapped.
# License
2014-12-26 07:28:58 -05:00
Do What The Fuck You Want To Public License.