From 66483334eb744413dd70eedc3ce41c4547ee6ca0 Mon Sep 17 00:00:00 2001 From: Arturs Artamonovs Date: Tue, 17 Oct 2023 09:43:49 +0100 Subject: Add version support --- LICENSE | 29 +++++++++++++++++++++++ airspyhf/libairspyhf.py | 62 +++++++++++++++++++++++++++++++++++-------------- 2 files changed, 73 insertions(+), 18 deletions(-) create mode 100644 LICENSE diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..56e8074 --- /dev/null +++ b/LICENSE @@ -0,0 +1,29 @@ +BSD 3-Clause License + +Copyright (c) 2023, Arturs Artamonovs +All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are met: + +* Redistributions of source code must retain the above copyright notice, this + list of conditions and the following disclaimer. + +* Redistributions in binary form must reproduce the above copyright notice, + this list of conditions and the following disclaimer in the documentation + and/or other materials provided with the distribution. + +* Neither the name of the copyright holder nor the names of its + contributors may be used to endorse or promote products derived from + this software without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE +FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, +OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. \ No newline at end of file diff --git a/airspyhf/libairspyhf.py b/airspyhf/libairspyhf.py index a287626..c279b34 100644 --- a/airspyhf/libairspyhf.py +++ b/airspyhf/libairspyhf.py @@ -1,8 +1,16 @@ import sys import os from ctypes import * +import ctypes from ctypes.util import find_library +#main supproted version is 1.7.1 define versions of deriviatives of it +#added support for 1.6.8 version most common version out there + +VERSION_171 = 1 +VERSION_168 = 0 +CURRENT_VERSION = VERSION_171 + def load_libairspyhf(): if sys.platform == "linux" and 'LD_LIBRARY_PATH' in os.environ.keys(): @@ -12,8 +20,9 @@ def load_libairspyhf(): driver_files = [local_path + '/libairspyhf.so' for local_path in ld_library_paths] else: driver_files = [] - driver_files += ['libairspyhf.so'] - driver_files += ['airspyhf.dll', 'libairspyhf.so', 'libairspyhf.dylib'] + + #driver_files += ['libairspyhf.0.dylib'] + driver_files += ['airspyhf.dll', 'libairspyhf.so', 'libairspyhf.0.dylib'] driver_files += ['..//airspyhf.dll', '..//libairspyhf.so'] driver_files += [lambda : find_library('airspyhf'), lambda : find_library('libairspyhf')] dll = None @@ -25,9 +34,10 @@ def load_libairspyhf(): continue #print("Search for driver named %s"%(driver)) try: - dll = CDLL(driver) + dll = CDLL(driver,use_errno=True) break except: + print("Cant load dll %s %d"%(driver, ctypes.get_errno())) pass else: raise ImportError('Error loading libairspyhf. Make sure libairspyhf '\ @@ -72,6 +82,16 @@ airspyhf_sample_block_cb_fn = PYFUNCTYPE(c_int, POINTER(airspyhf_transfer_t)) f = libairspyhf.airspyhf_lib_version f.restype, f.argtypes = None, [POINTER(airspyhf_lib_version_t)] +p = airspyhf_lib_version_t() +libairspyhf.airspyhf_lib_version(byref(p)) +if (p.major_version==1) and (p.minor_version==6) and (p.revision==8): + CURRENT_VERSION = VERSION_168 + print("Set libairspyhf version 1.6.8") +else: + CURRENT_VERSION = VERSION_171 + print("Set libairspyhf version 1.7.1 (Actual version (%d,%d,%d)"%(p.major_version,p.minor_version,p.revision)) + + #int ADDCALL airspyhf_list_devices(uint64_t *serials, int count); f = libairspyhf.airspyhf_list_devices f.restype, f.argtypes = c_int, [POINTER(c_uint64), c_int] @@ -84,10 +104,11 @@ f.restype, f.argtypes = c_int, [POINTER(airspyhf_device_t_p)] f = libairspyhf.airspyhf_open_sn f.restype, f.argtypes = c_int, [POINTER(airspyhf_device_t_p), c_uint64] - -#int ADDCALL airspyhf_open_fd(airspyhf_device_t** device, int fd); -f = libairspyhf.airspyhf_open_fd -f.restype, f.argtypes = c_int, [POINTER(airspyhf_device_t_p), c_int] +# start from 1.7.1 +if CURRENT_VERSION >= VERSION_171: + #int ADDCALL airspyhf_open_fd(airspyhf_device_t** device, int fd); + f = libairspyhf.airspyhf_open_fd + f.restype, f.argtypes = c_int, [POINTER(airspyhf_device_t_p), c_int] #int ADDCALL airspyhf_close(airspyhf_device_t* device); f = libairspyhf.airspyhf_close @@ -97,7 +118,6 @@ f.restype, f.argtypes = c_int, [airspyhf_device_t_p] f = libairspyhf.airspyhf_get_output_size f.restype, f.argtypes = c_int, [airspyhf_device_t_p] - #int ADDCALL airspyhf_start(airspyhf_device_t* device, airspyhf_sample_block_cb_fn callback, void* ctx); f = libairspyhf.airspyhf_start f.restype, f.argtypes = c_int, [airspyhf_device_t_p,airspyhf_sample_block_cb_fn,py_object] @@ -118,9 +138,11 @@ f.restype, f.argtypes = c_int, [airspyhf_device_t_p] f = libairspyhf.airspyhf_set_freq f.restype, f.argtypes = c_int, [airspyhf_device_t_p, c_uint32] -#int ADDCALL airspyhf_set_freq_double(airspyhf_device_t* device, const double freq_hz); -f = libairspyhf.airspyhf_set_freq_double -f.restype, f.argtypes = c_int, [airspyhf_device_t_p, c_double] +# start from 1.7.1 +if CURRENT_VERSION >= VERSION_171: + #int ADDCALL airspyhf_set_freq_double(airspyhf_device_t* device, const double freq_hz); + f = libairspyhf.airspyhf_set_freq_double + f.restype, f.argtypes = c_int, [airspyhf_device_t_p, c_double] #int ADDCALL airspyhf_set_lib_dsp(airspyhf_device_t* device, const uint8_t flag); /* Enables/Disables the IQ Correction, IF shift and Fine Tuning. */ f = libairspyhf.airspyhf_set_lib_dsp @@ -142,13 +164,17 @@ f.restype, f.argtypes = c_int, [airspyhf_device_t_p, POINTER(c_int32)] f = libairspyhf.airspyhf_set_calibration f.restype, f.argtypes = c_int, [airspyhf_device_t_p, c_int32] -#int ADDCALL airspyhf_get_vctcxo_calibration(airspyhf_device_t* device, uint16_t* vc); -f = libairspyhf.airspyhf_get_vctcxo_calibration -f.restype, f.argtypes = c_int, [airspyhf_device_t_p, POINTER(c_uint16)] - -#int ADDCALL airspyhf_set_vctcxo_calibration(airspyhf_device_t* device, uint16_t vc); -f = libairspyhf.airspyhf_set_vctcxo_calibration -f.restype, f.argtypes = c_int, [airspyhf_device_t_p, c_uint16] +# start from 1.7.1 +if CURRENT_VERSION >= VERSION_171: + #int ADDCALL airspyhf_get_vctcxo_calibration(airspyhf_device_t* device, uint16_t* vc); + f = libairspyhf.airspyhf_get_vctcxo_calibration + f.restype, f.argtypes = c_int, [airspyhf_device_t_p, POINTER(c_uint16)] + +# start from 1.7.1 +if CURRENT_VERSION >= VERSION_171: + #int ADDCALL airspyhf_set_vctcxo_calibration(airspyhf_device_t* device, uint16_t vc); + f = libairspyhf.airspyhf_set_vctcxo_calibration + f.restype, f.argtypes = c_int, [airspyhf_device_t_p, c_uint16] #int ADDCALL airspyhf_set_optimal_iq_correction_point(airspyhf_device_t* device, float w); f = libairspyhf.airspyhf_set_optimal_iq_correction_point -- cgit v1.2.3