Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

IsoTpMessage: param for single frame flow control #1079

Merged
merged 7 commits into from
Oct 5, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 12 additions & 3 deletions python/uds.py
Original file line number Diff line number Diff line change
Expand Up @@ -376,9 +376,10 @@ def send(self, msgs: List[bytes], delay: float = 0) -> None:
self._recv_buffer()

class IsoTpMessage():
def __init__(self, can_client: CanClient, timeout: float = 1, debug: bool = False, max_len: int = 8):
def __init__(self, can_client: CanClient, timeout: float = 1, single_frame_mode: bool = False, debug: bool = False, max_len: int = 8):
self._can_client = can_client
self.timeout = timeout
self.single_frame_mode = single_frame_mode
self.debug = debug
self.max_len = max_len

Expand Down Expand Up @@ -459,8 +460,12 @@ def _isotp_rx_next(self, rx_data: bytes) -> None:
print(f"ISO-TP: RX - first frame - {hex(self._can_client.rx_addr)} idx={self.rx_idx} done={self.rx_done}")
if self.debug:
print(f"ISO-TP: TX - flow control continue - {hex(self._can_client.tx_addr)}")
# send flow control message (send all bytes) with a separation time of 10 ms
msg = b"\x30\x00\x0a".ljust(self.max_len, b"\x00")
# send flow control message
msg = bytes([
0x30, # flow control
0x01 if self.single_frame_mode else 0x00, # block size
0x0a, # 10 ms separation time
]).ljust(self.max_len, b"\x00")
self._can_client.send([msg])
return

Expand All @@ -473,6 +478,10 @@ def _isotp_rx_next(self, rx_data: bytes) -> None:
self.rx_dat += rx_data[1:1 + rx_size]
if self.rx_len == len(self.rx_dat):
self.rx_done = True
elif self.single_frame_mode:
# notify ECU to send next frame
msg = b"\x30\x01\x0a".ljust(self.max_len, b"\x00")
self._can_client.send([msg])
if self.debug:
print(f"ISO-TP: RX - consecutive frame - {hex(self._can_client.rx_addr)} idx={self.rx_idx} done={self.rx_done}")
return
Expand Down