diff options
author | Arturs Artamonovs <dos21h@gmail.com> | 2023-03-09 22:47:36 +0000 |
---|---|---|
committer | Arturs Artamonovs <dos21h@gmail.com> | 2023-03-09 22:47:36 +0000 |
commit | 194f0c07ecbab61eb383c9d17c72fb73a4c9af80 (patch) | |
tree | a70fdd9a8e1235e1b35fbdd735ecaf9cdb7c0e41 /airspyhf | |
parent | c1ae0bcdb4eb27404d132b108f3d8da5ccdcf817 (diff) | |
parent | fba22599d2ce386517c5c7f93403e0b3a4c92877 (diff) | |
download | pyairspyhf-194f0c07ecbab61eb383c9d17c72fb73a4c9af80.tar.gz pyairspyhf-194f0c07ecbab61eb383c9d17c72fb73a4c9af80.zip |
Adding test for class. Implementeing main class. cleaning/fixing airspyhf_rx
Diffstat (limited to 'airspyhf')
-rw-r--r-- | airspyhf/airspyhf.py | 78 | ||||
-rw-r--r-- | airspyhf/libairspyhf.py | 2 |
2 files changed, 76 insertions, 4 deletions
diff --git a/airspyhf/airspyhf.py b/airspyhf/airspyhf.py index e13fada..4314c76 100644 --- a/airspyhf/airspyhf.py +++ b/airspyhf/airspyhf.py @@ -1,5 +1,77 @@ -from .libairspyhf import libairspyhf +from .libairspyhf import * +from ctypes import * class AirSpyHF: - def __init__(self): - pass
\ No newline at end of file + dev_p = airspyhf_device_t_p(None) + sample_rates = [] + def __init__(self,): + self.dev_p = None + + def open(self, device_index:int=None, serialnumber:int=None): + if serialnumber is not None: + ret = libairspyhf.airspyhf_open_sn(self.dev_p, serialnumber) + if ret != 0: + print("Cant open device by serial number") + return -1 + elif device_index is not None: + ndev = libairspyhf.airspyhf_list_devices(None, 0) + if ndev < device_index+1: + print("Device index higher then device num") + return -1 + serial = c_uint64(0) + libairspyhf.airspyhf_list_devices(byref(serial), device_index + 1) + return 0 + + def get_samplerates(self): + nsrates = c_uint32(0) + ret = libairspyhf.airspyhf_get_samplerates(self.dev_p, byref(nsrates), c_uint32(0)) + if ret != 0: + print("Cant get number of avaliable sample rates") + return [] + supported_samplerates = (c_uint32 * nsrates)(0) + ret = libairspyhf.airspyhf_get_samplerates(self.dev_p, supported_samplerates, nsrates) + if ret != 0: + print("Cant get avaliable sample rate list") + return [] + self.sample_rates = list(supported_samplerates) + return self.sample_rates + + def set_samplerate(self, samplerate:int): + if self.sample_rates == []: + self.get_samplerates() + if samplerate not in self.sample_rates: + print(f"Unknown sample rate. Avaliable samplerate {self.sample_rates}") + return -1 + + ret = libairspyhf.airspyhf_set_samplerate(self.dev_p, samplerate) + if ret != 0: + print("Cannot set samplerate") + return -1 + + return 0 + + def set_hf_agc(self,flag): + ret = libairspyhf.airspyhf_set_hf_agc(self.dev_p, flag) + return ret + + def set_hf_agc_threshold(self,flag): + ret = libairspyhf.airspyhf_set_hf_agc_threshold(self.dev_p, flag) + return ret + + def set_hf_att(self, value): + ret = libairspyhf.airspyhf_set_hf_att(dev_p, value) + return ret + + def set_hf_lna(self,flag): + ret = libairspyhf.airspyhf_set_hf_lna(dev_p, 1) + return ret + + def close(self): + ret = libairspyhf.close(self.dev_p) + if ret != 0: + print("Cant close device") + + + + + diff --git a/airspyhf/libairspyhf.py b/airspyhf/libairspyhf.py index dada9f5..a287626 100644 --- a/airspyhf/libairspyhf.py +++ b/airspyhf/libairspyhf.py @@ -23,7 +23,7 @@ def load_libairspyhf(): driver = driver() if driver is None: continue - print(driver) + #print("Search for driver named %s"%(driver)) try: dll = CDLL(driver) break |