From a2b93bc81171e08f886f8791543810ce64b2dfd6 Mon Sep 17 00:00:00 2001 From: SlamdaddyMcNasty <139294092+SlamdaddyMcNasty@users.noreply.github.com> Date: Tue, 11 Jul 2023 20:41:02 -0400 Subject: [PATCH] Update libhackrf.py Added ability to set HW_SYNC_MODE for external trigger --- libhackrf.py | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/libhackrf.py b/libhackrf.py index 719bea1..812ed58 100644 --- a/libhackrf.py +++ b/libhackrf.py @@ -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 @@ -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() @@ -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