Skip to content

Commit

Permalink
ttbl.device_mapper: make ttys_find_by_spec() find TTYs without USB in…
Browse files Browse the repository at this point in the history
…terface

When using ttbl.device_mapper.ttys_find_by_spec() to find TTYs
associated to a USB device, we usually had to also specify a USB
interface by appending #1.0 (the interface number), like:

>>> device_spec = "usb,#123456,##:1.0"

Which would map to /sys/devices/PATH/usbN/.../N-1.3/N-1.3:1.0 and find
ttys under ttyUSBm or tty/ttyACMm using tty* or tty/tty*.

In the case where the device has only one interface (and thus exposes
one serial port), this is overkill and adds more unneeded
verbosity. We want to be able to do just:

>>> device_spec = "usb,#123456"

So make the globs that tty_find_by_spec() be able to dig deeper into
the device structure, so it will find the subdirectories representing
the single TTY without having to specify a USB interface.

The extra globs find /sys/devices/PATH/usbN/.../N-1.3/N-1.3:1.0/ttyUSB
or /sys/devices/PATH/usbN/.../N-1.3/N-1.3:1.0/tty/ttyACM* since it
adds an extra */ to catch the interface directories hanging under the
main USB device directory.

Like this, devices which expose multiple serial ports on different USB
interfaces still can support them by specifying the interface, eg:

>>> device_spec = "usb,#123456,#:1.0"
>>> device_spec = "usb,#123456,#:2.0"
  • Loading branch information
inaky-intc committed Sep 27, 2023
1 parent da6d9d7 commit 55dba97
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions ttbd/ttbl/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#! /usr/bin/python3
#! /usr/bin/env python3
#
# Copyright (c) 2017 Intel Corporation
#
Expand Down Expand Up @@ -3049,7 +3049,15 @@ def devices_find_by_spec(self, spec: str = None, origin: str = None):
spec, origin, " ".join(devicel))
return devicel

sysfs_tty_globs = [ "tty*", "tty/tty*" ]
sysfs_tty_globs = [
# this catches when a tty device is in the top level, such as
# USB devices specified just a a serial number; if a USB
# device specifies a single serial port, this makes it work
"*/tty*", "*/tty/tty*",
# this catches a tty device that is a subdevice (eg, in a USB
# device interface)
"tty*", "tty/tty*"
]

def ttys_find_by_spec(self):
"""
Expand Down

0 comments on commit 55dba97

Please sign in to comment.