Skip to content

Commit

Permalink
Merge pull request #4 from analogdevicesinc/privatize
Browse files Browse the repository at this point in the history
Cleanup class API and add more tests
  • Loading branch information
tfcollins authored Aug 29, 2019
2 parents 1c53673 + d420fef commit 7d4ed05
Show file tree
Hide file tree
Showing 11 changed files with 217 additions and 208 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
64 changes: 32 additions & 32 deletions adi/ad9361.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]

Expand All @@ -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
50 changes: 25 additions & 25 deletions adi/ad9371.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,97 +38,97 @@
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)

@property
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)
Loading

0 comments on commit 7d4ed05

Please sign in to comment.