Skip to content

Commit

Permalink
IsoTpMessage: param for single frame flow control (commaai#1079)
Browse files Browse the repository at this point in the history
* iso-tp: request a single frame at a time

* behind param

* this might be more clear

* like this better

* fit the theme

* revert this change
  • Loading branch information
sshane authored and mlocoteta committed Apr 29, 2023
1 parent 210b13d commit 1b7bb93
Showing 1 changed file with 12 additions and 3 deletions.
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

0 comments on commit 1b7bb93

Please sign in to comment.