rx data should be char rather than unsigned char
This commit is contained in:
parent
4a2e59c9d6
commit
3d17d07b1d
3 changed files with 24 additions and 6 deletions
|
@ -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)
|
||||
|
|
20
examples.py
Normal file
20
examples.py
Normal file
|
@ -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)
|
|
@ -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
|
Loading…
Reference in a new issue