Files
DCCONSTRUCTIONS 8b210258ca feat(usb-can): add isolated adapter runtime and confirmed CAN transactions
Package the adapter SDK boundary and runtime lifecycle. Confirm admitted CAN transactions, bound retained data and test failure paths with synthetic hardware.
2026-10-29 09:09:59 +03:00

50 lines
1.2 KiB
Python
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
"""VID/PID/product discovery; a USB descriptor is not the protocol serial."""
import hashlib
from dataclasses import dataclass
from pathlib import Path
def device_id(value):
return "usbcan_" + hashlib.sha256(value.encode()).hexdigest()[:32]
@dataclass(frozen=True)
class Attachment:
binding: str
usb: str
path: str
speed: str
@property
def id(self):
return device_id("provisional:" + self.binding)
def discover(root=Path("/sys/bus/usb/devices")):
result = []
for path in sorted(root.glob("*")):
try:
def read(name, path=path):
return (path / name).read_text().strip()
if (read("idVendor"), read("idProduct"), read("product")) != (
"04d8",
"0053",
"USB CANFD DEBUG",
):
continue
bus, dev = int(read("busnum")), int(read("devnum"))
result.append(
Attachment(
path.name + ":" + str(dev),
path.name,
f"/dev/bus/usb/{bus:03}/{dev:03}",
read("speed") + " Мбит/с",
)
)
except (OSError, ValueError):
continue
return result[:8]