diff --git a/.travis.yml b/.travis.yml index 94f96dfaf..be761773b 100644 --- a/.travis.yml +++ b/.travis.yml @@ -16,7 +16,7 @@ install: - sudo pip install -r requirements_doc.txt script: - export PYTHONPATH=$PYTHONPATH:'/usr/lib/python3.6/site-packages' -- python -m unittest +- python -m unittest -v after_success: - export PYTHONPATH=$PYTHONPATH:'/usr/lib/python3.6/site-packages' - cd doc && make html diff --git a/adi/ad9361.py b/adi/ad9361.py index 6060be38c..04c633cad 100644 --- a/adi/ad9361.py +++ b/adi/ad9361.py @@ -38,118 +38,118 @@ class ad9361(rx_tx, context_manager): """ AD9361 Transceiver """ - complex_data = True - rx_channel_names = ["voltage0", "voltage1", "voltage2", "voltage3"] - tx_channel_names = ["voltage0", "voltage1", "voltage2", "voltage3"] - device_name = "" + _complex_data = True + _rx_channel_names = ["voltage0", "voltage1", "voltage2", "voltage3"] + _tx_channel_names = ["voltage0", "voltage1", "voltage2", "voltage3"] + _device_name = "" rx_enabled_channels = [0, 1] tx_enabled_channels = [0, 1] def __init__(self, uri=""): - context_manager.__init__(self, uri, self.device_name) + context_manager.__init__(self, uri, self._device_name) - self.ctrl = self.ctx.find_device("ad9361-phy") - self.rxadc = self.ctx.find_device("cf-ad9361-lpc") - self.txdac = self.ctx.find_device("cf-ad9361-dds-core-lpc") + self._ctrl = self._ctx.find_device("ad9361-phy") + self._rxadc = self._ctx.find_device("cf-ad9361-lpc") + self._txdac = self._ctx.find_device("cf-ad9361-dds-core-lpc") rx_tx.__init__(self, self.rx_enabled_channels, self.tx_enabled_channels) @property def filter(self): """Load FIR filter file. Provide path to filter file to attribute""" - return self.get_iio_dev_attr("filter_fir_config") + return self._get_iio_dev_attr("filter_fir_config") @filter.setter def filter(self, value): with open(value, "r") as file: data = file.read() self.sample_rate = 3000000 - self.set_iio_attr_str("out", "voltage_filter_fir_en", False, 0) - self.set_iio_dev_attr_str("filter_fir_config", data) - self.set_iio_attr_str("out", "voltage_filter_fir_en", False, 1) + self._set_iio_attr_str("out", "voltage_filter_fir_en", False, 0) + self._set_iio_dev_attr_str("filter_fir_config", data) + self._set_iio_attr_str("out", "voltage_filter_fir_en", False, 1) @property def gain_control_mode(self): """gain_control_mode: Mode of receive path AGC. Options are: slow_attack, fast_attack, manual""" - return self.get_iio_attr("voltage0", "gain_control_mode", False) + return self._get_iio_attr("voltage0", "gain_control_mode", False) @gain_control_mode.setter def gain_control_mode(self, value): - self.set_iio_attr_str("voltage0", "gain_control_mode", False, value) + self._set_iio_attr_str("voltage0", "gain_control_mode", False, value) @property def rx_hardwaregain(self): """rx_hardwaregain: Gain applied to RX path. Only applicable when gain_control_mode is set to 'manual'""" - return self.get_iio_attr("voltage0", "hardwaregain", False) + return self._get_iio_attr("voltage0", "hardwaregain", False) @rx_hardwaregain.setter def rx_hardwaregain(self, value): if self.gain_control_mode == "manual": - self.set_iio_attr("voltage0", "hardwaregain", False, value) + self._set_iio_attr("voltage0", "hardwaregain", False, value) @property def tx_hardwaregain(self): """tx_hardwaregain: Attenuation applied to TX path""" - return self.get_iio_attr("voltage0", "hardwaregain", True) + return self._get_iio_attr("voltage0", "hardwaregain", True) @tx_hardwaregain.setter def tx_hardwaregain(self, value): - self.set_iio_attr("voltage0", "hardwaregain", True, value) + self._set_iio_attr("voltage0", "hardwaregain", True, value) @property def rx_rf_bandwidth(self): """rx_rf_bandwidth: Bandwidth of front-end analog filter of RX path""" - return self.get_iio_attr("voltage0", "rf_bandwidth", False) + return self._get_iio_attr("voltage0", "rf_bandwidth", False) @rx_rf_bandwidth.setter def rx_rf_bandwidth(self, value): - self.set_iio_attr("voltage0", "rf_bandwidth", False, value) + self._set_iio_attr("voltage0", "rf_bandwidth", False, value) @property def tx_rf_bandwidth(self): """tx_rf_bandwidth: Bandwidth of front-end analog filter of TX path""" - return self.get_iio_attr("voltage0", "rf_bandwidth", True) + return self._get_iio_attr("voltage0", "rf_bandwidth", True) @tx_rf_bandwidth.setter def tx_rf_bandwidth(self, value): - self.set_iio_attr("voltage0", "rf_bandwidth", True, value) + self._set_iio_attr("voltage0", "rf_bandwidth", True, value) @property def sample_rate(self): """sample_rate: Sample rate RX and TX paths in samples per second""" - return self.get_iio_attr("voltage0", "sampling_frequency", False) + return self._get_iio_attr("voltage0", "sampling_frequency", False) @sample_rate.setter def sample_rate(self, value): - self.set_iio_attr("voltage0", "sampling_frequency", False, value) + self._set_iio_attr("voltage0", "sampling_frequency", False, value) @property def rx_lo(self): """rx_lo: Carrier frequency of RX path""" - return self.get_iio_attr("altvoltage0", "frequency", True) + return self._get_iio_attr("altvoltage0", "frequency", True) @rx_lo.setter def rx_lo(self, value): - self.set_iio_attr("altvoltage0", "frequency", True, value) + self._set_iio_attr("altvoltage0", "frequency", True, value) @property def tx_lo(self): """tx_lo: Carrier frequency of TX path""" - return self.get_iio_attr("altvoltage1", "frequency", True) + return self._get_iio_attr("altvoltage1", "frequency", True) @tx_lo.setter def tx_lo(self, value): - self.set_iio_attr("altvoltage1", "frequency", True, value) + self._set_iio_attr("altvoltage1", "frequency", True, value) class ad9364(ad9361): """ AD9364 Transceiver """ - rx_channel_names = ["voltage0", "voltage1"] - tx_channel_names = ["voltage0", "voltage1"] + _rx_channel_names = ["voltage0", "voltage1"] + _tx_channel_names = ["voltage0", "voltage1"] rx_enabled_channels = [0] tx_enabled_channels = [0] @@ -163,6 +163,6 @@ class ad9363(ad9361): class Pluto(ad9364): """ PlutoSDR Evaluation Platform """ - device_name = "PlutoSDR" - uri_auto = "ip:pluto.local" + _device_name = "PlutoSDR" + _uri_auto = "ip:pluto.local" pass diff --git a/adi/ad9371.py b/adi/ad9371.py index 561088cd6..fb097517d 100644 --- a/adi/ad9371.py +++ b/adi/ad9371.py @@ -38,21 +38,21 @@ class ad9371(rx_tx, context_manager): """ AD9371 Transceiver """ - complex_data = True - rx_channel_names = ["voltage0_i", "voltage0_q", "voltage1_i", "voltage1_q"] - tx_channel_names = ["voltage0", "voltage1", "voltage2", "voltage3"] - device_name = "" + _complex_data = True + _rx_channel_names = ["voltage0_i", "voltage0_q", "voltage1_i", "voltage1_q"] + _tx_channel_names = ["voltage0", "voltage1", "voltage2", "voltage3"] + _device_name = "" rx_enabled_channels = [0, 1] tx_enabled_channels = [0, 1] def __init__(self, uri=""): - context_manager.__init__(self, uri, self.device_name) + context_manager.__init__(self, uri, self._device_name) - self.ctrl = self.ctx.find_device("ad9371-phy") - self.rxadc = self.ctx.find_device("axi-ad9371-rx-hpc") - self.rxobs = self.ctx.find_device("axi-ad9371-rx-obs-hpc") - self.txdac = self.ctx.find_device("axi-ad9371-tx-hpc") + self._ctrl = self._ctx.find_device("ad9371-phy") + self._rxadc = self._ctx.find_device("axi-ad9371-rx-hpc") + self._rxobs = self._ctx.find_device("axi-ad9371-rx-obs-hpc") + self._txdac = self._ctx.find_device("axi-ad9371-tx-hpc") rx_tx.__init__(self, self.rx_enabled_channels, self.tx_enabled_channels) @@ -60,75 +60,75 @@ def __init__(self, uri=""): def gain_control_mode(self): """gain_control_mode: Mode of receive path AGC. Options are: automatic, hybrid, manual""" - return self.get_iio_attr("voltage0", "gain_control_mode", False) + return self._get_iio_attr("voltage0", "gain_control_mode", False) @gain_control_mode.setter def gain_control_mode(self, value): - self.set_iio_attr_str("voltage0", "gain_control_mode", False, value) + self._set_iio_attr_str("voltage0", "gain_control_mode", False, value) @property def rx_hardwaregain(self): """rx_hardwaregain: Gain applied to RX path. Only applicable when gain_control_mode is set to 'manual'""" - return self.get_iio_attr("voltage0", "hardwaregain", False) + return self._get_iio_attr("voltage0", "hardwaregain", False) @rx_hardwaregain.setter def rx_hardwaregain(self, value): if self.gain_control_mode == "manual": - self.set_iio_attr("voltage0", "hardwaregain", False, value) + self._set_iio_attr("voltage0", "hardwaregain", False, value) @property def tx_hardwaregain(self): """tx_hardwaregain: Attenuation applied to TX path""" - return self.get_iio_attr("voltage0", "hardwaregain", True) + return self._get_iio_attr("voltage0", "hardwaregain", True) @tx_hardwaregain.setter def tx_hardwaregain(self, value): - self.set_iio_attr("voltage0", "hardwaregain", True, value) + self._set_iio_attr("voltage0", "hardwaregain", True, value) @property def rx_rf_bandwidth(self): """rx_rf_bandwidth: Bandwidth of front-end analog filter of RX path""" - return self.get_iio_attr("voltage0", "rf_bandwidth", False) + return self._get_iio_attr("voltage0", "rf_bandwidth", False) @property def tx_rf_bandwidth(self): """tx_rf_bandwidth: Bandwidth of front-end analog filter of TX path""" - return self.get_iio_attr("voltage0", "rf_bandwidth", True) + return self._get_iio_attr("voltage0", "rf_bandwidth", True) @property def rx_sample_rate(self): """rx_sample_rate: Sample rate RX path in samples per second""" - return self.get_iio_attr("voltage0", "sampling_frequency", False) + return self._get_iio_attr("voltage0", "sampling_frequency", False) @property def tx_sample_rate(self): """tx_sample_rate: Sample rate TX path in samples per second""" - return self.get_iio_attr("voltage0", "sampling_frequency", True) + return self._get_iio_attr("voltage0", "sampling_frequency", True) @property def rx_lo(self): """rx_lo: Carrier frequency of RX path""" - return self.get_iio_attr("altvoltage0", "RX_LO_frequency", True) + return self._get_iio_attr("altvoltage0", "RX_LO_frequency", True) @rx_lo.setter def rx_lo(self, value): - self.set_iio_attr("altvoltage0", "RX_LO_frequency", True, value) + self._set_iio_attr("altvoltage0", "RX_LO_frequency", True, value) @property def tx_lo(self): """tx_lo: Carrier frequency of TX path""" - return self.get_iio_attr("altvoltage1", "TX_LO_frequency", True) + return self._get_iio_attr("altvoltage1", "TX_LO_frequency", True) @tx_lo.setter def tx_lo(self, value): - self.set_iio_attr("altvoltage1", "TX_LO_frequency", True, value) + self._set_iio_attr("altvoltage1", "TX_LO_frequency", True, value) @property def sn_lo(self): """sn_lo: Carrier frequency of Sniffer/ORx path""" - return self.get_iio_attr("altvoltage2", "RX_SN_LO_frequency", True) + return self._get_iio_attr("altvoltage2", "RX_SN_LO_frequency", True) @sn_lo.setter def sn_lo(self, value): - self.set_iio_attr("altvoltage2", "RX_SN_LO_frequency", True, value) + self._set_iio_attr("altvoltage2", "RX_SN_LO_frequency", True, value) diff --git a/adi/adrv9009.py b/adi/adrv9009.py index 2e17f63ee..157e977c2 100644 --- a/adi/adrv9009.py +++ b/adi/adrv9009.py @@ -38,110 +38,110 @@ class adrv9009(rx_tx, context_manager): """ ADRV9009 Transceiver """ - complex_data = True - rx_channel_names = ["voltage0_i", "voltage0_q", "voltage1_i", "voltage1_q"] - tx_channel_names = ["voltage0", "voltage1", "voltage2", "voltage3"] - device_name = "" + _complex_data = True + _rx_channel_names = ["voltage0_i", "voltage0_q", "voltage1_i", "voltage1_q"] + _tx_channel_names = ["voltage0", "voltage1", "voltage2", "voltage3"] + _device_name = "" rx_enabled_channels = [0, 1] tx_enabled_channels = [0, 1] def __init__(self, uri=""): - context_manager.__init__(self, uri, self.device_name) + context_manager.__init__(self, uri, self._device_name) - self.ctrl = self.ctx.find_device("adrv9009-phy") - self.rxadc = self.ctx.find_device("axi-adrv9009-rx-hpc") - self.rxobs = self.ctx.find_device("axi-adrv9009-rx-obs-hpc") - self.txdac = self.ctx.find_device("axi-adrv9009-tx-hpc") + self._ctrl = self._ctx.find_device("adrv9009-phy") + self._rxadc = self._ctx.find_device("axi-adrv9009-rx-hpc") + self._rxobs = self._ctx.find_device("axi-adrv9009-rx-obs-hpc") + self._txdac = self._ctx.find_device("axi-adrv9009-tx-hpc") rx_tx.__init__(self, self.rx_enabled_channels, self.tx_enabled_channels) # @property # def profile(self): # """Load profile file. Provide path to profile file to attribute""" - # return self.get_iio_dev_attr("profile_config") + # return self._get_iio_dev_attr("profile_config") # # @profile.setter # def profile(self, value): # with open(value, "r") as file: # data = file.read() - # self.set_iio_dev_attr_str("profile_config", data) + # self._set_iio_dev_attr_str("profile_config", data) @property def gain_control_mode(self): """gain_control_mode: Mode of receive path AGC. Options are: slow_attack, manual""" - return self.get_iio_attr("voltage0", "gain_control_mode", False) + return self._get_iio_attr("voltage0", "gain_control_mode", False) @gain_control_mode.setter def gain_control_mode(self, value): - self.set_iio_attr_str("voltage0", "gain_control_mode", False, value) + self._set_iio_attr_str("voltage0", "gain_control_mode", False, value) @property def rx_hardwaregain_chan0(self): """rx_hardwaregain: Gain applied to RX path channel 0. Only applicable when gain_control_mode is set to 'manual'""" - return self.get_iio_attr("voltage0", "hardwaregain", False) + return self._get_iio_attr("voltage0", "hardwaregain", False) @rx_hardwaregain_chan0.setter def rx_hardwaregain_chan0(self, value): if self.gain_control_mode == "manual": - self.set_iio_attr("voltage0", "hardwaregain", False, value) + self._set_iio_attr("voltage0", "hardwaregain", False, value) @property def rx_hardwaregain_chan1(self): """rx_hardwaregain: Gain applied to RX path channel 1. Only applicable when gain_control_mode is set to 'manual'""" - return self.get_iio_attr("voltage1", "hardwaregain", False) + return self._get_iio_attr("voltage1", "hardwaregain", False) @rx_hardwaregain_chan1.setter def rx_hardwaregain_chan1(self, value): if self.gain_control_mode == "manual": - self.set_iio_attr("voltage1", "hardwaregain", False, value) + self._set_iio_attr("voltage1", "hardwaregain", False, value) @property def tx_hardwaregain_chan0(self): """tx_hardwaregain: Attenuation applied to TX path channel 0""" - return self.get_iio_attr("voltage0", "hardwaregain", True) + return self._get_iio_attr("voltage0", "hardwaregain", True) @tx_hardwaregain_chan0.setter def tx_hardwaregain_chan0(self, value): - self.set_iio_attr("voltage0", "hardwaregain", True, value) + self._set_iio_attr("voltage0", "hardwaregain", True, value) @property def tx_hardwaregain_chan1(self): """tx_hardwaregain: Attenuation applied to TX path channel 1""" - return self.get_iio_attr("voltage1", "hardwaregain", True) + return self._get_iio_attr("voltage1", "hardwaregain", True) @tx_hardwaregain_chan1.setter def tx_hardwaregain_chan1(self, value): - self.set_iio_attr("voltage1", "hardwaregain", True, value) + self._set_iio_attr("voltage1", "hardwaregain", True, value) @property def rx_rf_bandwidth(self): """rx_rf_bandwidth: Bandwidth of front-end analog filter of RX path""" - return self.get_iio_attr("voltage0", "rf_bandwidth", False) + return self._get_iio_attr("voltage0", "rf_bandwidth", False) @property def tx_rf_bandwidth(self): """tx_rf_bandwidth: Bandwidth of front-end analog filter of TX path""" - return self.get_iio_attr("voltage0", "rf_bandwidth", True) + return self._get_iio_attr("voltage0", "rf_bandwidth", True) @property def rx_sample_rate(self): """rx_sample_rate: Sample rate RX path in samples per second""" - return self.get_iio_attr("voltage0", "sampling_frequency", False) + return self._get_iio_attr("voltage0", "sampling_frequency", False) @property def tx_sample_rate(self): """tx_sample_rate: Sample rate TX path in samples per second""" - return self.get_iio_attr("voltage0", "sampling_frequency", True) + return self._get_iio_attr("voltage0", "sampling_frequency", True) @property def trx_lo(self): """trx_lo: Carrier frequency of TX and RX path""" - return self.get_iio_attr("altvoltage0", "frequency", True) + return self._get_iio_attr("altvoltage0", "frequency", True) @trx_lo.setter def trx_lo(self, value): - self.set_iio_attr("altvoltage0", "frequency", True, value) + self._set_iio_attr("altvoltage0", "frequency", True, value) diff --git a/adi/adrv9009_zu11eg.py b/adi/adrv9009_zu11eg.py index 885af8f56..685bc285e 100644 --- a/adi/adrv9009_zu11eg.py +++ b/adi/adrv9009_zu11eg.py @@ -37,7 +37,7 @@ class adrv9009_zu11eg(adrv9009): """ ADRV9009-ZU11EG System-On-Module """ - rx_channel_names = [ + _rx_channel_names = [ "voltage0_i", "voltage0_q", "voltage1_i", @@ -47,7 +47,7 @@ class adrv9009_zu11eg(adrv9009): "voltage3_i", "voltage3_q", ] - tx_channel_names = [ + _tx_channel_names = [ "voltage0", "voltage1", "voltage2", @@ -57,91 +57,91 @@ class adrv9009_zu11eg(adrv9009): "voltage6", "voltage7", ] - device_name = "" + _device_name = "" rx_enabled_channels = [0, 1] tx_enabled_channels = [0, 1] def __init__(self, uri=""): adrv9009.__init__(self, uri=uri) - self.ctrl_b = self.ctx.find_device("adrv9009-phy-b") + self._ctrl_b = self._ctx.find_device("adrv9009-phy-b") @property def gain_control_mode_chip_b(self): """gain_control_mode_chip_b: Mode of receive path AGC. Options are: slow_attack, manual""" - return self.get_iio_attr("voltage0", "gain_control_mode", False, self.ctrl_b) + return self._get_iio_attr("voltage0", "gain_control_mode", False, self._ctrl_b) @gain_control_mode_chip_b.setter def gain_control_mode_chip_b(self, value): - self.set_iio_attr_str( - "voltage0", "gain_control_mode", False, value, self.ctrl_b + self._set_iio_attr_str( + "voltage0", "gain_control_mode", False, value, self._ctrl_b ) @property def rx_hardwaregain_chan0_chip_b(self): """rx_hardwaregain: Gain applied to RX path channel 0. Only applicable when gain_control_mode is set to 'manual'""" - return self.get_iio_attr("voltage0", "hardwaregain", False, self.ctrl_b) + return self._get_iio_attr("voltage0", "hardwaregain", False, self._ctrl_b) @rx_hardwaregain_chan0_chip_b.setter def rx_hardwaregain_chan0_chip_b(self, value): if self.gain_control_mode_chip_b == "manual": - self.set_iio_attr("voltage0", "hardwaregain", False, value, self.ctrl_b) + self._set_iio_attr("voltage0", "hardwaregain", False, value, self._ctrl_b) @property def rx_hardwaregain_chan1_chip_b(self): """rx_hardwaregain: Gain applied to RX path channel 1. Only applicable when gain_control_mode is set to 'manual'""" - return self.get_iio_attr("voltage1", "hardwaregain", False, self.ctrl_b) + return self._get_iio_attr("voltage1", "hardwaregain", False, self._ctrl_b) @rx_hardwaregain_chan1_chip_b.setter def rx_hardwaregain_chan1_chip_b(self, value): if self.gain_control_mode_chip_b == "manual": - self.set_iio_attr("voltage1", "hardwaregain", False, value, self.ctrl_b) + self._set_iio_attr("voltage1", "hardwaregain", False, value, self._ctrl_b) @property def tx_hardwaregain_chan0_chip_b(self): """tx_hardwaregain: Attenuation applied to TX path channel 0""" - return self.get_iio_attr("voltage0", "hardwaregain", True, self.ctrl_b) + return self._get_iio_attr("voltage0", "hardwaregain", True, self._ctrl_b) @tx_hardwaregain_chan0_chip_b.setter def tx_hardwaregain_chan0_chip_b(self, value): - self.set_iio_attr("voltage0", "hardwaregain", True, value, self.ctrl_b) + self._set_iio_attr("voltage0", "hardwaregain", True, value, self._ctrl_b) @property def tx_hardwaregain_chan1_chip_b(self): """tx_hardwaregain: Attenuation applied to TX path channel 1""" - return self.get_iio_attr("voltage1", "hardwaregain", True, self.ctrl_b) + return self._get_iio_attr("voltage1", "hardwaregain", True, self._ctrl_b) @tx_hardwaregain_chan1_chip_b.setter def tx_hardwaregain_chan1_chip_b(self, value): - self.set_iio_attr("voltage1", "hardwaregain", True, value, self.ctrl_b) + self._set_iio_attr("voltage1", "hardwaregain", True, value, self._ctrl_b) @property def rx_rf_bandwidth_chip_b(self): """rx_rf_bandwidth: Bandwidth of front-end analog filter of RX path""" - return self.get_iio_attr("voltage0", "rf_bandwidth", False, self.ctrl_b) + return self._get_iio_attr("voltage0", "rf_bandwidth", False, self._ctrl_b) @property def tx_rf_bandwidth_chip_b(self): """tx_rf_bandwidth: Bandwidth of front-end analog filter of TX path""" - return self.get_iio_attr("voltage0", "rf_bandwidth", True, self.ctrl_b) + return self._get_iio_attr("voltage0", "rf_bandwidth", True, self._ctrl_b) @property def rx_sample_rate_chip_b(self): """rx_sample_rate: Sample rate RX path in samples per second""" - return self.get_iio_attr("voltage0", "sampling_frequency", False, self.ctrl_b) + return self._get_iio_attr("voltage0", "sampling_frequency", False, self._ctrl_b) @property def tx_sample_rate_chip_b(self): """tx_sample_rate: Sample rate TX path in samples per second""" - return self.get_iio_attr("voltage0", "sampling_frequency", True, self.ctrl_b) + return self._get_iio_attr("voltage0", "sampling_frequency", True, self._ctrl_b) @property def trx_lo_chip_b(self): """trx_lo: Carrier frequency of TX and RX path""" - return self.get_iio_attr("altvoltage0", "frequency", True, self.ctrl_b) + return self._get_iio_attr("altvoltage0", "frequency", True, self._ctrl_b) @trx_lo_chip_b.setter def trx_lo_chip_b(self, value): - self.set_iio_attr("altvoltage0", "frequency", True, value, self.ctrl_b) + self._set_iio_attr("altvoltage0", "frequency", True, value, self._ctrl_b) diff --git a/adi/attribute.py b/adi/attribute.py index fa67a7e99..fd7556678 100644 --- a/adi/attribute.py +++ b/adi/attribute.py @@ -33,44 +33,44 @@ class attribute: - def set_iio_attr_str(self, channel_name, attr_name, output, value, ctrl=None): - if ctrl: - channel = ctrl.find_channel(channel_name, output) + def _set_iio_attr_str(self, channel_name, attr_name, output, value, _ctrl=None): + if _ctrl: + channel = _ctrl.find_channel(channel_name, output) else: - channel = self.ctrl.find_channel(channel_name, output) + channel = self._ctrl.find_channel(channel_name, output) try: channel.attrs[attr_name].value = str(value) except Exception as ex: raise ex - def set_iio_attr(self, channel_name, attr_name, output, value, ctrl=None): - if ctrl: - channel = ctrl.find_channel(channel_name, output) + def _set_iio_attr(self, channel_name, attr_name, output, value, _ctrl=None): + if _ctrl: + channel = _ctrl.find_channel(channel_name, output) else: - channel = self.ctrl.find_channel(channel_name, output) + channel = self._ctrl.find_channel(channel_name, output) try: channel.attrs[attr_name].value = str(int(value)) except Exception as ex: raise ex - def get_iio_attr(self, channel_name, attr_name, output, ctrl=None): - if ctrl: - channel = ctrl.find_channel(channel_name, output) + def _get_iio_attr(self, channel_name, attr_name, output, _ctrl=None): + if _ctrl: + channel = _ctrl.find_channel(channel_name, output) else: - channel = self.ctrl.find_channel(channel_name, output) + channel = self._ctrl.find_channel(channel_name, output) return channel.attrs[attr_name].value - def set_iio_dev_attr_str(self, attr_name, value, ctrl=None): + def _set_iio_dev_attr_str(self, attr_name, value, _ctrl=None): try: - if ctrl: - ctrl.attrs[attr_name].value = str(value) + if _ctrl: + _ctrl.attrs[attr_name].value = str(value) else: - self.ctrl.attrs[attr_name].value = str(value) + self._ctrl.attrs[attr_name].value = str(value) except Exception as ex: raise ex - def get_iio_dev_attr(self, attr_name, ctrl=None): - if ctrl: - return ctrl.attrs[attr_name].value + def _get_iio_dev_attr(self, attr_name, _ctrl=None): + if _ctrl: + return _ctrl.attrs[attr_name].value else: - return self.ctrl.attrs[attr_name].value + return self._ctrl.attrs[attr_name].value diff --git a/adi/context_manager.py b/adi/context_manager.py index 4304df11b..c8f9a7c35 100644 --- a/adi/context_manager.py +++ b/adi/context_manager.py @@ -35,26 +35,26 @@ class context_manager(object): - uri_auto = "ip:analog" - ctx = None + _uri_auto = "ip:analog" + _ctx = None - def __init__(self, uri="", device_name=""): + def __init__(self, uri="", _device_name=""): self.uri = uri try: if self.uri == "": # Try USB contexts first - if device_name != "": + if _device_name != "": contexts = iio.scan_contexts() for c in contexts: - if device_name in contexts[c]: - self.ctx = iio.Context(c) + if _device_name in contexts[c]: + self._ctx = iio.Context(c) break # Try auto discover - if not self.ctx and self.uri_auto != "": - self.ctx = iio.Context(self.uri_auto) - if not self.ctx: + if not self._ctx and self._uri_auto != "": + self._ctx = iio.Context(self._uri_auto) + if not self._ctx: raise else: - self.ctx = iio.Context(self.uri) + self._ctx = iio.Context(self.uri) except BaseException: raise Exception("No device found") diff --git a/adi/dds.py b/adi/dds.py index 68d0e11cc..e901114e2 100644 --- a/adi/dds.py +++ b/adi/dds.py @@ -51,9 +51,9 @@ def __init__(self): self.dds_phases = np.zeros(self.num_tx_channels * 2) self.dds_enabled = np.zeros(self.num_tx_channels * 2, dtype=bool) - def update_dds(self, attr, value): + def __update_dds(self, attr, value): indx = 0 - for chan in self.txdac.channels: + for chan in self._txdac.channels: if not chan.name: continue if attr == "raw": @@ -62,10 +62,10 @@ def update_dds(self, attr, value): chan.attrs[attr].value = str(value[indx]) indx = indx + 1 - def read_dds(self, attr): + def _read_dds(self, attr): values = [] indx = 0 - for chan in self.txdac.channels: + for chan in self._txdac.channels: if not chan.name: continue values.append(chan.attrs[attr].value) @@ -78,39 +78,39 @@ def disable_dds(self): @property def dds_frequencies(self): """ Frequencies of DDSs in Hz""" - return self.read_dds("frequency") + return self._read_dds("frequency") @dds_frequencies.setter def dds_frequencies(self, value): - self.update_dds("frequency", value) + self.__update_dds("frequency", value) @property def dds_scales(self): """ Scale of DDS signal generators Ranges [0,1] """ - return self.read_dds("scale") + return self._read_dds("scale") @dds_scales.setter def dds_scales(self, value): - self.update_dds("scale", value) + self.__update_dds("scale", value) @property def dds_phases(self): """ Phases of DDS signal generators. Range in millidegrees [0,360000] """ - return self.read_dds("phase") + return self._read_dds("phase") @dds_scales.setter def dds_phases(self, value): - self.update_dds("phase", value) + self.__update_dds("phase", value) @property def dds_enabled(self): """ DDS generator enable state """ - return self.read_dds("raw") + return self._read_dds("raw") @dds_enabled.setter def dds_enabled(self, value): - self.update_dds("raw", value) + self.__update_dds("raw", value) diff --git a/adi/rx_tx.py b/adi/rx_tx.py index c2eef2980..d99d7bb21 100644 --- a/adi/rx_tx.py +++ b/adi/rx_tx.py @@ -38,18 +38,18 @@ class phy(attribute): - ctrl = [] + _ctrl = [] def __del__(self): - self.ctrl = [] + self._ctrl = [] class rx(attribute): """ Buffer handling for receive devices """ - rxadc = [] - rx_channel_names = [] - rxbuf = None + _rx_channel_names = [] + __rxbuf = None + _rxadc = [] def __init__(self, rx_enabled_channels, rx_buffer_size=1024): self.rx_enabled_channels = rx_enabled_channels @@ -71,7 +71,7 @@ def rx_enabled_channels(self): @rx_enabled_channels.setter def rx_enabled_channels(self, value): - if self.complex_data: + if self._complex_data: if max(value) > ((self.num_rx_channels) / 2 - 1): raise Exception("RX mapping exceeds available channels") else: @@ -84,27 +84,27 @@ def num_rx_channels_enabled(self): return len(self.__rx_enabled_channels) def __del__(self): - self.rxbuf = [] - self.rxadc = [] + self.__rxbuf = [] + self._rxadc = [] - def init_channels(self): - if self.complex_data: + def _init_channels(self): + if self._complex_data: for map in self.rx_enabled_channels: - v = self.rxadc.find_channel(self.rx_channel_names[map * 2]) + v = self._rxadc.find_channel(self._rx_channel_names[map * 2]) v.enabled = True - v = self.rxadc.find_channel(self.rx_channel_names[map * 2 + 1]) + v = self._rxadc.find_channel(self._rx_channel_names[map * 2 + 1]) v.enabled = True else: for map in self.rx_enabled_channels: - v = self.rxadc.find_channel(self.rx_channel_names[map]) + v = self._rxadc.find_channel(self._rx_channel_names[map]) v.enabled = True - self.rxbuf = iio.Buffer(self.rxadc, self.__rx_buffer_size, False) + self.__rxbuf = iio.Buffer(self._rxadc, self.__rx_buffer_size, False) - def rx_complex(self): - if not self.rxbuf: - self.init_channels(False) - self.rxbuf.refill() - data = self.rxbuf.read() + def __rx_complex(self): + if not self.__rxbuf: + self._init_channels(False) + self.__rxbuf.refill() + data = self.__rxbuf.read() x = np.frombuffer(data, dtype=np.int16) indx = 0 sig = [] @@ -117,11 +117,11 @@ def rx_complex(self): return sig[0] return sig - def rx_non_complex(self): - if not self.rxbuf: - self.init_channels(False) - self.rxbuf.refill() - data = self.rxbuf.read() + def __rx_non_complex(self): + if not self.__rxbuf: + self._init_channels(False) + self.__rxbuf.refill() + data = self.__rxbuf.read() x = np.frombuffer(data, dtype=np.int16) indx = 0 sig = [] @@ -134,19 +134,19 @@ def rx_non_complex(self): return sig def rx(self): - if self.complex_data: - return self.rx_complex() + if self._complex_data: + return self.__rx_complex() else: - return self.rx_non_complex() + return self.__rx_non_complex() class tx(dds, attribute): """ Buffer handling for receive devices """ - txdac = [] - tx_channel_names = [] + _txdac = [] + _tx_channel_names = [] tx_buffer_size = 1024 - txbuf = None + __txbuf = None def __init__(self, tx_enabled_channels, tx_cyclic_buffer=False): self.tx_enabled_channels = tx_enabled_channels @@ -154,7 +154,7 @@ def __init__(self, tx_enabled_channels, tx_cyclic_buffer=False): dds.__init__(self) def __del__(self): - self.txdac = [] + self._txdac = [] @property def tx_cyclic_buffer(self): @@ -176,7 +176,7 @@ def tx_enabled_channels(self): @tx_enabled_channels.setter def tx_enabled_channels(self, value): - if self.complex_data: + if self._complex_data: if max(value) > ((self.num_tx_channels) / 2 - 1): raise Exception("TX mapping exceeds available channels") else: @@ -184,23 +184,23 @@ def tx_enabled_channels(self, value): raise Exception("TX mapping exceeds available channels") self.__tx_enabled_channels = value - def init_channels(self): - if self.complex_data: + def _init_channels(self): + if self._complex_data: for map in self.tx_enabled_channels: - v = self.txdac.find_channel(self.tx_channel_names[map * 2], True) + v = self._txdac.find_channel(self._tx_channel_names[map * 2], True) v.enabled = True - v = self.txdac.find_channel(self.tx_channel_names[map * 2 + 1], True) + v = self._txdac.find_channel(self._tx_channel_names[map * 2 + 1], True) v.enabled = True else: for map in self.tx_enabled_channels: - v = self.txdac.find_channel(self.tx_channel_names[map]) + v = self._txdac.find_channel(self._tx_channel_names[map]) v.enabled = True - self.txbuf = iio.Buffer( - self.txdac, self.tx_buffer_size, self.__tx_cyclic_buffer + self.__txbuf = iio.Buffer( + self._txdac, self.tx_buffer_size, self.__tx_cyclic_buffer ) def tx(self, data_np): - if self.complex_data: + if self._complex_data: if self.num_tx_channels_enabled == 1: data_np = [data_np] @@ -226,26 +226,26 @@ def tx(self, data_np): data[indx::l] = chan.astype(int) indx = indx + 1 - if not self.txbuf: + if not self.__txbuf: self.disable_dds() self.tx_buff_length = len(data) - self.init_channels(True) + self._init_channels(True) if len(data) != self.tx_buff_length: raise # Send data to buffer - self.txbuf.write(bytearray(data)) - self.txbuf.push() + self.__txbuf.write(bytearray(data)) + self.__txbuf.push() class rx_tx(rx, tx, phy): - complex_data = False + _complex_data = False def __init__(self, rx_enabled_channels, tx_enabled_channels): - self.num_rx_channels = len(self.rx_channel_names) - self.num_tx_channels = len(self.tx_channel_names) + self.num_rx_channels = len(self._rx_channel_names) + self.num_tx_channels = len(self._tx_channel_names) rx.__init__(self, rx_enabled_channels) tx.__init__(self, tx_enabled_channels) @@ -254,8 +254,8 @@ def __del__(self): tx.__del__(self) phy.__del__(self) - def init_channels(self, istx=False): + def _init_channels(self, istx=False): if istx: - tx.init_channels(self) + tx._init_channels(self) else: - rx.init_channels(self) + rx._init_channels(self) diff --git a/examples/ad9371.py b/examples/ad9371.py index 82f74f6bf..d48c7d0e4 100644 --- a/examples/ad9371.py +++ b/examples/ad9371.py @@ -50,7 +50,7 @@ sdr.gain_control_mode = "automatic" # Enable digital loopback -# sdr.ctrl.debug_attrs['loopback_tx_rx'].value = '1' +# sdr._ctrl.debug_attrs['loopback_tx_rx'].value = '1' # Read properties print("RX LO %s" % (sdr.rx_lo)) diff --git a/test/pluto.py b/test/test_pluto.py similarity index 89% rename from test/pluto.py rename to test/test_pluto.py index 5aded626b..980301cab 100644 --- a/test/pluto.py +++ b/test/test_pluto.py @@ -41,6 +41,21 @@ import iio +def check_pluto(): + # Try USB contexts first + contexts = iio.scan_contexts() + for c in contexts: + if "PlutoSDR" in contexts[c]: + return True + # Try auto discover + try: + iio.Context("ip:pluto.local") + return True + except Exception as e: + print(e) + return False + + class TestPluto(unittest.TestCase): do_plots = False @@ -61,11 +76,12 @@ def freq_est(self, y, fs): return xf[indx] def setUp(self): - self.longMessage = True + pass def tearDown(self): pass + @unittest.skipUnless(check_pluto(), "PlutoSDR not attached") def testPlutoADC(self): # See if we can get non-zero data from Pluto sdr = Pluto() @@ -73,6 +89,7 @@ def testPlutoADC(self): s = np.sum(np.abs(data)) self.assertGreater(s, 0, "check non-zero data") + @unittest.skipUnless(check_pluto(), "PlutoSDR not attached") def testPlutoDAC(self): # See if we can tone from Pluto using DMAs sdr = Pluto() @@ -114,12 +131,4 @@ def testPlutoDAC(self): if __name__ == "__main__": - from os import path - import sys - - try: - iio.Context("ip:192.168.2.1") - except: - print("No Pluto found") - sys.exit(1) unittest.main()