"""Bounded, read-only firmware diagnostics and exact-attachment USB descriptors.""" from pathlib import Path from .serial import check_attachment def read_diagnostics(device): attachment = device.attachment check_attachment(attachment) path = Path('/sys/bus/usb/devices') / attachment.usb usb = {"port": attachment.usb, "tty": attachment.tty, "speed": attachment.speed} for field in ('idVendor', 'idProduct', 'bcdDevice', 'manufacturer', 'product', 'serial'): try: usb[field] = (path / field).read_text()[:256].strip() except OSError: usb[field] = None reports = {name: device.link.diagnostic(name) for name in ('hw_status', 'faults')} check_attachment(attachment) return {"usb": usb, "reports": reports}