diff --git a/bindings/c/include/cgenalyzer.h b/bindings/c/include/cgenalyzer.h index 6cfb1c6..f1c20cf 100644 --- a/bindings/c/include/cgenalyzer.h +++ b/bindings/c/include/cgenalyzer.h @@ -23,8 +23,6 @@ #ifndef CGENALYZER_H #define CGENALYZER_H #include "cgenalyzer_advanced.h" -#include -#include #include #include diff --git a/bindings/c/src/cgenalyzer.cpp b/bindings/c/src/cgenalyzer.cpp index 3022c14..e503422 100644 --- a/bindings/c/src/cgenalyzer.cpp +++ b/bindings/c/src/cgenalyzer.cpp @@ -4,16 +4,14 @@ extern "C" { int gn_config_free(gn_config *c) { - if (!((*c)->obj_key)) + if ((*c)->obj_key){ + gn_mgr_remove((*c)->obj_key); free((*c)->obj_key); - if (!((*c)->comp_key)) + } + if ((*c)->comp_key){ + gn_fa_remove_comp((*c)->obj_key, (*c)->comp_key); free((*c)->comp_key); - if (!((*c)->tone_freq)) - free((*c)->tone_freq); - if (!((*c)->tone_ampl)) - free((*c)->tone_ampl); - if (!((*c)->tone_phase)) - free((*c)->tone_phase); + } if (((*c)->_fa_results_size) > 0) { for (size_t i = 0; i < (*c)->_fa_results_size; i++) diff --git a/bindings/python/examples/do_fourier_analysis.py b/bindings/python/examples/do_fourier_analysis.py index 5112cbf..4253c6c 100644 --- a/bindings/python/examples/do_fourier_analysis.py +++ b/bindings/python/examples/do_fourier_analysis.py @@ -21,6 +21,7 @@ ) fft_out_i, fft_out_q = genalyzer.fftz(qwfi, qwfq, c) fft_out = [val for pair in zip(fft_out_i, fft_out_q) for val in pair] +genalyzer.config_set_sample_rate(data["fs"], c) genalyzer.config_fa(freq_list[0], c) all_results = genalyzer.get_fa_results(fft_out, c) pprint.pprint(all_results) diff --git a/bindings/python/examples/do_fourier_analysis_pluto_auto.py b/bindings/python/examples/do_fourier_analysis_pluto_auto.py index 7673e54..3ddfaf0 100644 --- a/bindings/python/examples/do_fourier_analysis_pluto_auto.py +++ b/bindings/python/examples/do_fourier_analysis_pluto_auto.py @@ -29,7 +29,7 @@ genalyzer.config_set_sample_rate(data["fs"], c) # Find tones -genalyzer.gn_config_fa_auto(ssb_width=120, c=c) +genalyzer.config_fa_auto(ssb_width=120, c=c) # compute FFT fft_out_i, fft_out_q = genalyzer.fftz(qwfi, qwfq, c) diff --git a/bindings/python/examples/real_analysis_advanced.py b/bindings/python/examples/real_analysis_advanced.py index 6500613..3814a0d 100644 --- a/bindings/python/examples/real_analysis_advanced.py +++ b/bindings/python/examples/real_analysis_advanced.py @@ -1,5 +1,5 @@ def main(): - import genalyzer_advanced as gn + import genalyzer.advanced as gn # print("Library path: {}".format(gn._genalyzer._libpath)) # print("Version: {}\n".format(gn.__version__)) diff --git a/bindings/python/genalyzer/__init__.py b/bindings/python/genalyzer/__init__.py index a5bdb9d..4e49e74 100644 --- a/bindings/python/genalyzer/__init__.py +++ b/bindings/python/genalyzer/__init__.py @@ -13,7 +13,7 @@ config_histz_nla, config_fftz, config_fa, - gn_config_fa_auto, + config_fa_auto, gen_ramp, gen_real_tone, gen_complex_tone, diff --git a/bindings/python/genalyzer/simplified.py b/bindings/python/genalyzer/simplified.py index e426ed7..68b9420 100644 --- a/bindings/python/genalyzer/simplified.py +++ b/bindings/python/genalyzer/simplified.py @@ -464,22 +464,23 @@ def config_free( _gn_config_free(byref(c._struct)) -def config_gen_ramp(npts: int, ramp_start: int, ramp_stop: int, *args) -> GNConfig: +def config_gen_ramp(npts: int, ramp_start: int, ramp_stop: int, c: GNConfig = None) -> GNConfig: """Configure GNConfig struct to generate tone. :param npts: number of sample points in the waveform :param ramp_start: Input start value of ramp :param ramp_stop: Input stop value of ramp :return: GNConfig object """ - if len(args) == 0: + if c is None: c = GNConfig() - elif len(args) == 1: - c = args[0] + npts = c_ulong(npts) ramp_start = c_ulong(ramp_start) ramp_stop = c_ulong(ramp_stop) - _gn_config_gen_ramp(npts, ramp_start, ramp_stop, byref(c._struct)) + ret = _gn_config_gen_ramp(npts, ramp_start, ramp_stop, byref(c._struct)) + if ret != 0: + raise Exception("config_gen_ramp failed") return c @@ -491,7 +492,7 @@ def config_gen_tone( tone_freq: float, tone_ampl: float, tone_phase: float, - *args + c: GNConfig = None ) -> GNConfig: """Configure GNConfig struct to generate tone. :param ttype: tone type @@ -503,10 +504,9 @@ def config_gen_tone( :param tone_phase: tone phase :return: GNConfig object """ - if len(args) == 0: + if c is None: c = GNConfig() - elif len(args) == 1: - c = args[0] + ttype = c_uint(ttype) npts = c_ulong(npts) sample_rate = c_double(sample_rate) @@ -516,7 +516,7 @@ def config_gen_tone( tone_ampl = (double_array)(*tone_ampl) tone_phase = (double_array)(*tone_phase) - _gn_config_gen_tone( + ret = _gn_config_gen_tone( ttype, npts, sample_rate, @@ -526,10 +526,12 @@ def config_gen_tone( tone_phase, byref(c._struct), ) + if ret != 0: + raise Exception("config_gen_tone failed") return c -def config_quantize(npts: int, fsr: float, qres: int, qnoise: float, *args) -> GNConfig: +def config_quantize(npts: int, fsr: float, qres: int, qnoise: float, c: GNConfig = None) -> GNConfig: """Configure GNConfig struct to perform quantization. :param npts: number of sample points in the waveform :param fsr: full-scale range @@ -537,21 +539,21 @@ def config_quantize(npts: int, fsr: float, qres: int, qnoise: float, *args) -> G :param qnoise: quantization noise :return: GNConfig object """ - if len(args) == 0: + if c is None: c = GNConfig() - elif len(args) == 1: - c = args[0] - + npts = c_ulong(npts) fsr = c_double(fsr) qres = c_int(qres) qnoise = c_double(qnoise) - _gn_config_quantize(npts, fsr, qres, qnoise, byref(c._struct)) + ret = _gn_config_quantize(npts, fsr, qres, qnoise, byref(c._struct)) + if ret != 0: + raise Exception("config quantize failed") return c -def config_histz_nla(npts: int, qres: int, *args) -> GNConfig: +def config_histz_nla(npts: int, qres: int, c: GNConfig = None) -> GNConfig: """Configure GNConfig struct to compute histogram or perform non-linearity analysis. :param npts: number of sample points in the waveform :param fsr: full-scale range @@ -559,20 +561,20 @@ def config_histz_nla(npts: int, qres: int, *args) -> GNConfig: :param qnoise: quantization noise :return: GNConfig object """ - if len(args) == 0: + if c is None: c = GNConfig() - elif len(args) == 1: - c = args[0] - + npts = c_ulong(npts) qres = c_int(qres) - _gn_config_histz_nla(npts, qres, byref(c._struct)) + ret = _gn_config_histz_nla(npts, qres, byref(c._struct)) + if ret != 0: + raise Exception("config_histz_nla failed") return c def config_fftz( - npts: int, qres: int, navg: int, nfft: int, win: int, *args + npts: int, qres: int, navg: int, nfft: int, win: int, c: GNConfig = None ) -> GNConfig: """Configure GNConfig struct to compute FFT. :param npts: number of sample points in the waveform @@ -581,48 +583,51 @@ def config_fftz( :param qnoise: quantization noise :return: GNConfig object """ - if len(args) == 0: + if c is None: c = GNConfig() - elif len(args) == 1: - c = args[0] - + npts = c_ulong(npts) qres = c_int(qres) navg = c_ulong(navg) nfft = c_ulong(nfft) win = c_uint(win) - _gn_config_fftz(npts, qres, navg, nfft, win, byref(c._struct)) + ret = _gn_config_fftz(npts, qres, navg, nfft, win, byref(c._struct)) + if ret != 0: + raise Exception("config_fftz failed") return c -def config_fa(fixed_tone_freq: float, *args) -> GNConfig: +def config_fa(fixed_tone_freq: float, c: GNConfig = None) -> GNConfig: """Configure GNConfig struct for Fourier analysis. :param fixed_tone_freq: fixed tone frequency :return: GNConfig object """ - if len(args) == 0: + if c is None: c = GNConfig() - elif len(args) == 1: - c = args[0] fixed_tone_freq = c_double(fixed_tone_freq) - _gn_config_fa(fixed_tone_freq, byref(c._struct)) + ret = _gn_config_fa(fixed_tone_freq, byref(c._struct)) + if ret != 0: + raise Exception("config_fa failed") return c -def gn_config_fa_auto(ssb_width: int, c: GNConfig): +def config_fa_auto(ssb_width: int, c: GNConfig = None): """Configure GNConfig struct for Fourier analysis where tones are automatically found. :param ssb_width: SSB width :param c: GNConfig object """ + if c is None: + c = GNConfig() ssb_width = c_uint8(ssb_width) ret = _gn_config_fa_auto(ssb_width, byref(c._struct)) if ret != 0: - raise Exception("gn_config_fa_auto failed") + raise Exception("config_fa_auto failed") + return c def gen_ramp(c: GNConfig) -> List[float]: