Skip to content

Commit

Permalink
Package reorganized. (#447)
Browse files Browse the repository at this point in the history
  • Loading branch information
ATATC committed Nov 19, 2024
1 parent 4c6bfdd commit 5903709
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 17 deletions.
1 change: 0 additions & 1 deletion leads/dt/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,3 @@
from leads.dt.odometer import *
from leads.dt.predefined_tags import *
from leads.dt.registry import *
from leads.dt.sobd import *
1 change: 1 addition & 0 deletions leads_comm_serial/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@

from leads_comm_serial.connection import *
from leads_comm_serial.identity import *
from leads_comm_serial.sobd import *
1 change: 1 addition & 0 deletions leads_comm_serial/sobd/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from leads_comm_serial.sobd import *
31 changes: 15 additions & 16 deletions leads/dt/sobd.py → leads_comm_serial/sobd/sobd.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,20 @@

from serial import Serial as _Serial

from leads import require_config
from leads.comm import Entity, Callback, Service
from leads.dt.device import Device
from leads.logger import L
from leads_comm_serial import SerialConnection as _SerialConnection, AutoIdentity as _AutoIdentity
from leads import require_config as _require_config, Device as _Device, L as _L
from leads.comm import Entity as _Entity, Callback as _Callback, Service as _Service
from leads_comm_serial.connection import SerialConnection
from leads_comm_serial.identity import AutoIdentity


class SOBD(Device, Entity, _AutoIdentity):
class SOBD(_Device, _Entity, AutoIdentity):
def __init__(self, port: str | _Literal["auto"], baud_rate: int = 9600, password: str = "") -> None:
Device.__init__(self)
Entity.__init__(self, -1, _SOBDCallback(self))
_AutoIdentity.__init__(self, port == "auto")
_Device.__init__(self)
_Entity.__init__(self, -1, _SOBDCallback(self))
AutoIdentity.__init__(self, port == "auto")
self._serial: _Serial = _Serial()
self._serial.baudrate = baud_rate
self._connection: _SerialConnection | None = None
self._connection: SerialConnection | None = None
self._serial.port = self.suggest_next_port() if port == "auto" else port
self._password: str = password
self._locked: bool = password != ""
Expand All @@ -40,12 +39,12 @@ def update(self, data: str) -> None:
if self._locked:
return
if data.startswith("dbl="):
require_config().w_debug_level = data[4:].upper()
_require_config().w_debug_level = data[4:].upper()
else:
self.write("\n".join(L.history_messages()).encode())
self.write("\n".join(_L.history_messages()).encode())

@_override
def check_identity(self, connection: _SerialConnection) -> bool:
def check_identity(self, connection: SerialConnection) -> bool:
connection.send(b"ic")
return (msg := connection.receive()) and msg.startswith(self.tag().encode())

Expand All @@ -68,15 +67,15 @@ def close(self) -> None:
self._connection.close()


class _SOBDCallback(Callback):
class _SOBDCallback(_Callback):
def __init__(self, sobd: SOBD) -> None:
super().__init__()
self._sobd: SOBD = sobd

@_override
def on_receive(self, service: Service, msg: bytes) -> None:
def on_receive(self, service: _Service, msg: bytes) -> None:
self.super(service=service, msg=msg)
try:
self._sobd.update(msg.decode())
except UnicodeDecodeError:
L.debug(f"Discarding this message: {msg}")
_L.debug(f"Discarding this message: {msg}")

0 comments on commit 5903709

Please sign in to comment.