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.
This commit is contained in:
DCCONSTRUCTIONS
2026-10-29 09:09:59 +03:00
parent f32c7b400b
commit 8b210258ca
30 changed files with 3336 additions and 0 deletions
+49
View File
@@ -0,0 +1,49 @@
"""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]