diff options
author | Martin Braun <martin.braun@ettus.com> | 2017-05-31 21:58:45 -0700 |
---|---|---|
committer | Martin Braun <martin.braun@ettus.com> | 2017-12-22 15:03:58 -0800 |
commit | 3c50e39d644767ea3f668bbf2146ea4c636ce8e2 (patch) | |
tree | b0056aea97ab0a2452692603987ac83d8cf9fed0 /mpm | |
parent | cd533c8080287f8558cdb283d28ad00661c1a164 (diff) | |
download | uhd-3c50e39d644767ea3f668bbf2146ea4c636ce8e2.tar.gz uhd-3c50e39d644767ea3f668bbf2146ea4c636ce8e2.tar.bz2 uhd-3c50e39d644767ea3f668bbf2146ea4c636ce8e2.zip |
mpm: Removed gratuitous encode(), safer udev lookups
- Udev lookups now just return empty lists when they can't find anything
- Made SPI dev interface factory Py2/3 safe
Diffstat (limited to 'mpm')
-rw-r--r-- | mpm/python/usrp_mpm/dboard_manager/eiscat.py | 4 | ||||
-rw-r--r-- | mpm/python/usrp_mpm/periph_manager/udev.py | 17 | ||||
-rw-r--r-- | mpm/python/usrp_mpm/sysfs_gpio.py | 5 |
3 files changed, 15 insertions, 11 deletions
diff --git a/mpm/python/usrp_mpm/dboard_manager/eiscat.py b/mpm/python/usrp_mpm/dboard_manager/eiscat.py index 6997e2fc9..b3d70673d 100644 --- a/mpm/python/usrp_mpm/dboard_manager/eiscat.py +++ b/mpm/python/usrp_mpm/dboard_manager/eiscat.py @@ -35,7 +35,7 @@ def create_spidev_iface_sane(dev_node): Create a regs iface from a spidev node (sane values) """ return lib.spi.make_spidev_regs_iface( - dev_node, + str(dev_node), 1000000, # Speed (Hz) 3, # SPI mode 8, # Addr shift @@ -49,7 +49,7 @@ def create_spidev_iface_phasedac(dev_node): Create a regs iface from a spidev node (ADS5681) """ return lib.spi.make_spidev_regs_iface( - dev_node, + str(dev_node), 1000000, # Speed (Hz) 1, # SPI mode 20, # Addr shift diff --git a/mpm/python/usrp_mpm/periph_manager/udev.py b/mpm/python/usrp_mpm/periph_manager/udev.py index cb3b35a66..33cb3367a 100644 --- a/mpm/python/usrp_mpm/periph_manager/udev.py +++ b/mpm/python/usrp_mpm/periph_manager/udev.py @@ -21,27 +21,32 @@ from ..mpmlog import get_logger def get_eeprom_paths(address): """ - Return EEPROM device paths for a given I2C address + Return list of EEPROM device paths for a given I2C address. + If no device paths are found, an empty list is returned. """ context = pyudev.Context() parent = pyudev.Device.from_name(context, "platform", address) paths = [d.device_node if d.device_node is not None else d.sys_path for d in context.list_devices(parent=parent, subsystem="nvmem")] + if len(paths) == 0: + return [] # We need to sort this so 9-0050 comes before 10-0050 (etc.) maxlen = max((len(os.path.split(p)[1]) for p in paths)) paths = sorted( paths, key=lambda x: "{:>0{maxlen}}".format(os.path.split(x)[1], maxlen=maxlen) ) - return [os.path.join(x.encode('ascii'), 'nvmem') for x in paths] + return [os.path.join(x, 'nvmem') for x in paths] def get_spidev_nodes(spi_master): """ - Return found spidev device paths for a given SPI master + Return list of spidev device paths for a given SPI master. If no valid paths + can be found, an empty list is returned. """ context = pyudev.Context() parent = pyudev.Device.from_name(context, "platform", spi_master) - paths = [device.device_node.encode('ascii') - for device in context.list_devices(parent=parent, subsystem="spidev")] - return paths + return [ + device.device_node + for device in context.list_devices(parent=parent, subsystem="spidev") + ] diff --git a/mpm/python/usrp_mpm/sysfs_gpio.py b/mpm/python/usrp_mpm/sysfs_gpio.py index 6473d87ee..ea423dc00 100644 --- a/mpm/python/usrp_mpm/sysfs_gpio.py +++ b/mpm/python/usrp_mpm/sysfs_gpio.py @@ -19,7 +19,6 @@ Access to GPIOs mapped into the PS via sysfs """ import os -from builtins import range from builtins import object import pyudev from .mpmlog import get_logger @@ -35,11 +34,11 @@ def get_all_gpio_devs(): """ try: context = pyudev.Context() - gpios = [device.sys_name.encode('ascii') + gpios = [device.sys_name for device in context.list_devices(subsystem="gpio") if os.path.exists(os.path.join( # udev probably has better ways to do this GPIO_SYSFS_BASE_DIR, - device.sys_name.encode('ascii'), + device.sys_name, GPIO_SYSFS_LABELFILE )) ] |