Tier 2: WiFi + Bluetooth ELM327 transports
- obdcore/transport.py: pluggable byte transports -- SerialTransport,
TcpTransport (WiFi ELM327, stdlib socket), BleTransport (experimental, via
optional 'bleak'; background asyncio loop buffering notifications). ble_scan().
- ElmLink refactored onto a transport with .serial()/.tcp()/.ble() factories
(close/cmd now go through self.io); no behavior change for serial.
- Controller.connect(conn={kind:serial|wifi|ble,...}); GUI connection bar gains
a transport selector (Serial/USB/BT-SPP | WiFi host:port | Bluetooth LE + Scan).
- Classic-Bluetooth needs no new code (pairs as a serial port); WiFi needs no
extra deps; BLE is opt-in (bleak not bundled, so CI binaries keep building).
- tests/test_transport.py: drives ElmLink over a fake ELM TCP server end-to-end
(connect, RPM, readiness, VIN). All suites pass.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_016yT89n4zR4qbrySoSiEyZs
This commit is contained in:
+11
-2
@@ -55,12 +55,21 @@ class Controller:
|
||||
self.reg = PidRegistry(self.profile)
|
||||
self.dtcdb = DtcDatabase(self.profile)
|
||||
|
||||
def connect(self, port=None, baud=38400, mock=False):
|
||||
def connect(self, port=None, baud=38400, mock=False, conn=None):
|
||||
"""conn: optional {'kind': 'serial'|'wifi'|'ble', ...}. Falls back to
|
||||
serial(port, baud) for backward compatibility."""
|
||||
if mock:
|
||||
self.link = MockLink(clock=time.time)
|
||||
else:
|
||||
from obdcore.link import ElmLink # imported lazily (needs pyserial)
|
||||
self.link = ElmLink(port, baud)
|
||||
c = conn or {"kind": "serial", "port": port, "baud": baud}
|
||||
kind = c.get("kind", "serial")
|
||||
if kind == "wifi":
|
||||
self.link = ElmLink.tcp(c["host"], c.get("port", 35000))
|
||||
elif kind == "ble":
|
||||
self.link = ElmLink.ble(c["address"])
|
||||
else:
|
||||
self.link = ElmLink.serial(c.get("port", port), c.get("baud", baud))
|
||||
self.link.init()
|
||||
ok = self.link.connect()
|
||||
try:
|
||||
|
||||
Reference in New Issue
Block a user