diff --git a/README.md b/README.md index 0792ce4..b247d44 100644 --- a/README.md +++ b/README.md @@ -31,7 +31,7 @@ if hackrf.is_open == False: hackrf.set_baseband_filter_bandwidth(1 * 1000 * 1000) def callback_fun(hackrf_transfer): - array_type = (ctypes.c_ubyte*length) + array_type = (ctypes.c_byte*length) values = ctypes.cast(hackrf_transfer.contents.buffer, ctypes.POINTER(array_type)).contents #iq data here iq = hackrf.packed_bytes_to_iq(values) diff --git a/examples.py b/examples.py new file mode 100644 index 0000000..f5c71ca --- /dev/null +++ b/examples.py @@ -0,0 +1,20 @@ +import pylibhackrf ,ctypes + +hackrf = pylibhackrf.HackRf() + +if hackrf.is_open == False: + hackrf.setup() + hackrf.set_freq(100 * 1000 * 1000) + hackrf.set_sample_rate(8 * 1000 * 1000) + hackrf.set_amp_enable(False) + hackrf.set_lna_gain(16) + hackrf.set_vga_gain(20) + +def callback_fun(hackrf_transfer): + array_type = (ctypes.c_byte*length) + 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) \ No newline at end of file diff --git a/pylibhackrf.py b/pylibhackrf.py index d66a8bc..63d76f8 100644 --- a/pylibhackrf.py +++ b/pylibhackrf.py @@ -80,7 +80,7 @@ class hackrf_device(Structure): class hackrf_transfer(Structure): _fields_ = [("hackrf_device", POINTER(hackrf_device)), - ("buffer", POINTER(c_uint8)), + ("buffer", POINTER(c_byte)), ("buffer_length", c_int), ("valid_length", c_int), ("rx_ctx", c_void_p), @@ -523,8 +523,7 @@ class HackRf(object): # use NumPy array iq = np.empty(len(bytes)//2, 'complex') iq.real, iq.imag = bytes[::2], bytes[1::2] - iq /= (255/2) - iq -= (1 + 1j) + iq /= 128.0 return iq def packed_bytes_to_iq_withsize(self, bytes, size): @@ -535,6 +534,5 @@ class HackRf(object): iq = np.empty(size , 'complex') bytes2 = bytes[0:size * 2] iq.real, iq.imag = bytes2[::2], bytes2[1::2] - iq /= (255/2) - iq -= (1 + 1j) + iq /= 128.0 return iq \ No newline at end of file