You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The library depends heavily on manual bit shifts (<<, >>) and bitwise masking (&, |) applied directly inside operational code to parse the 29-bit J1939 identifier (Priority, Data Page, PDU Format, PDU Specific, Source Address) and the 64-bit ECU NAME field.
This creates a highly imperative codebase that is prone to off-by-one errors and makes onboarding or debugging incredibly tedious.
Data integrity relies entirely on runtime type handling without leveraging static type validation capabilities.
Proposed Architecture Fix
Utilize Python 3.10's modern, optimized @dataclass(slots=True) syntax to create immutable, strongly typed schemas for J1939 data primitives.
The use of slots=True minimizes memory overhead and optimizes attribute lookup performance for low-level message routing.
Integrate Python 3.10's Structural Pattern Matching (match/case) to cleanly route packets based on PDU format combinations.
Architectural Example (Python 3.10):
fromdataclassesimportdataclass@dataclass(frozen=True, slots=True)classJ1939Identifier:
priority: intpgn: intsource_address: intdestination_address: int|None=None# High-performance, declarative dispatchingdefdispatch_pdu(pdu_format: int, pdu_specific: int, frame_data: bytes):
match (pdu_format, pdu_specific):
case (236, _):
# Route to Transport Connection Management Handlerprocess_tp_cm(frame_data)
case (235, _):
# Route to Transport Data Transfer Handlerprocess_tp_dt(frame_data)
case (pdu_f, _) ifpdu_f>=240:
# Global broadcast PGN patternprocess_broadcast_pgn(pdu_format, pdu_specific, frame_data)
case _:
process_peer_to_peer(pdu_format, pdu_specific, frame_data)
Caution
This issue needs clarification since it may be a large rework and benefits is not that clear yet.
The library depends heavily on manual bit shifts (
<<,>>) and bitwise masking (&,|) applied directly inside operational code to parse the 29-bit J1939 identifier (Priority, Data Page, PDU Format, PDU Specific, Source Address) and the 64-bit ECU NAME field.Proposed Architecture Fix
Utilize Python 3.10's modern, optimized
@dataclass(slots=True)syntax to create immutable, strongly typed schemas for J1939 data primitives.slots=Trueminimizes memory overhead and optimizes attribute lookup performance for low-level message routing.match/case) to cleanly route packets based on PDU format combinations.Architectural Example (Python 3.10):
Caution
This issue needs clarification since it may be a large rework and benefits is not that clear yet.