Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions libhackrf.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,10 @@ def enum(*sequential, **named):
HACKRF_TRANSCEIVER_MODE_RECEIVE=1,
HACKRF_TRANSCEIVER_MODE_TRANSMIT=2)

HackRfHwSyncMode = enum(
HACKRF_HW_SYNC_MODE_OFF=0,
HACKRF_HW_SYNC_MODE_ON=1)

# Data structures
_libusb_device_handle = c_void_p
_pthread_t = c_ulong
Expand Down Expand Up @@ -169,6 +173,12 @@ class hackrf_device_list_t(Structure):
f.restype = POINTER(hackrf_device_list_t)
f.argtypes = []

# HARDWARE SYNCHRONIZATION SETTINGS
# extern ADDAPI int ADDCALL hackrf_hw_sync_mode(hackrf_device* device,
# const uint8_t value);
libhackrf.hackrf_set_hw_sync_mode.restype = c_int
libhackrf.hackrf_set_hw_sync_mode.argtypes = [p_hackrf_device, c_uint8]


def hackrf_device_list():
return libhackrf.hackrf_device_list()
Expand Down Expand Up @@ -463,6 +473,20 @@ def disable_amp(self):
raise IOError("error disabling amp")
return 0

def enable_hw_sync(self):
result = libhackrf.hackrf_set_hw_sync_mode(self.dev_p, 1)
if result != 0:
# TODO: make this error message better
raise IOError("error enabling hw sync")
return 0

def disable_hw_sync(self):
result = libhackrf.hackrf_set_hw_sync_mode(self.dev_p, 0)
if result != 0:
# TODO: make this error message better
raise IOError("error disabling hw sync")
return 0

# rounds down to multiple of 8 (15 -> 8, 39 -> 32), etc.
# internally, hackrf_set_lna_gain does the same thing
# But we take care of it so we can keep track of the correct gain
Expand Down