From 9e1285167f1ba05470e67b43e1a941431bb5a943 Mon Sep 17 00:00:00 2001 From: Shane Smiskol Date: Tue, 27 Sep 2022 19:31:56 -0700 Subject: [PATCH 1/6] iso-tp: request a single frame at a time --- python/uds.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/python/uds.py b/python/uds.py index b7ea96ca05..b618d5f49e 100644 --- a/python/uds.py +++ b/python/uds.py @@ -458,8 +458,8 @@ 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 (send one frame at a time) + msg = b"\x30\x01\x00".ljust(self.max_len, b"\x00") self._can_client.send([msg]) return @@ -472,6 +472,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 + else: + # notify ECU to send next frame + msg = b"\x30\x01\x00".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 From 57dc38bd88b52266e5b2979657810bc0d3b531ff Mon Sep 17 00:00:00 2001 From: Shane Smiskol Date: Wed, 28 Sep 2022 11:52:09 -0700 Subject: [PATCH 2/6] behind param --- python/uds.py | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/python/uds.py b/python/uds.py index b618d5f49e..25a3045beb 100644 --- a/python/uds.py +++ b/python/uds.py @@ -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 @@ -458,9 +459,9 @@ 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 one frame at a time) - msg = b"\x30\x01\x00".ljust(self.max_len, b"\x00") - self._can_client.send([msg]) + # send flow control message + msg = b"\x30\x01\x00" if self.single_frame_mode else b"\x30\x00\x00" + self._can_client.send([msg.ljust(self.max_len, b"\x00")]) return # consecutive rx frame @@ -472,7 +473,7 @@ 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 - else: + elif self.single_frame_mode: # notify ECU to send next frame msg = b"\x30\x01\x00".ljust(self.max_len, b"\x00") self._can_client.send([msg]) From 7685378fd25a2c5d0c9096e7f04776629567b36c Mon Sep 17 00:00:00 2001 From: Shane Smiskol Date: Wed, 28 Sep 2022 12:00:23 -0700 Subject: [PATCH 3/6] this might be more clear --- python/uds.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/python/uds.py b/python/uds.py index 25a3045beb..45fa8aa57e 100644 --- a/python/uds.py +++ b/python/uds.py @@ -460,8 +460,10 @@ def _isotp_rx_next(self, rx_data: bytes) -> None: if self.debug: print(f"ISO-TP: TX - flow control continue - {hex(self._can_client.tx_addr)}") # send flow control message - msg = b"\x30\x01\x00" if self.single_frame_mode else b"\x30\x00\x00" - self._can_client.send([msg.ljust(self.max_len, b"\x00")]) + msg = [0x30, 0x00, 0x00] + if self.single_frame_mode: + msg[1] = 0x01 + self._can_client.send([bytes(msg).ljust(self.max_len, b"\x00")]) return # consecutive rx frame From a6c49d3f257b4c1ee62497626b33ba1f1f9c6bdd Mon Sep 17 00:00:00 2001 From: Shane Smiskol Date: Wed, 5 Oct 2022 15:47:02 -0700 Subject: [PATCH 4/6] like this better --- python/uds.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/python/uds.py b/python/uds.py index 2cbd75cf3c..a3732d6334 100644 --- a/python/uds.py +++ b/python/uds.py @@ -461,10 +461,12 @@ def _isotp_rx_next(self, rx_data: bytes) -> None: if self.debug: print(f"ISO-TP: TX - flow control continue - {hex(self._can_client.tx_addr)}") # send flow control message - msg = [0x30, 0x00, 0x00] - if self.single_frame_mode: - msg[1] = 0x01 - self._can_client.send([bytes(msg).ljust(self.max_len, b"\x00")]) + msg = bytes([ + 0x30, # flow control + 0x01 if self.single_frame_mode else 0x00, # block size + 0x0a, # 10 ms STmin + ]).ljust(self.max_len, b"\x00") + self._can_client.send([msg]) return # consecutive rx frame From 6cb22069cfefbcbb4824131af5fa09c429c4490e Mon Sep 17 00:00:00 2001 From: Shane Smiskol Date: Wed, 5 Oct 2022 15:49:09 -0700 Subject: [PATCH 5/6] fit the theme --- python/uds.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/python/uds.py b/python/uds.py index a3732d6334..fd292e2192 100644 --- a/python/uds.py +++ b/python/uds.py @@ -464,7 +464,7 @@ def _isotp_rx_next(self, rx_data: bytes) -> None: msg = bytes([ 0x30, # flow control 0x01 if self.single_frame_mode else 0x00, # block size - 0x0a, # 10 ms STmin + 0x0a, # 10 ms separation time ]).ljust(self.max_len, b"\x00") self._can_client.send([msg]) return From bb0e9fe19ec6bc489a48fdba970eb10b6df45ccd Mon Sep 17 00:00:00 2001 From: Shane Smiskol Date: Wed, 5 Oct 2022 15:49:26 -0700 Subject: [PATCH 6/6] revert this change --- python/uds.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/python/uds.py b/python/uds.py index fd292e2192..7f9e8865ad 100644 --- a/python/uds.py +++ b/python/uds.py @@ -480,7 +480,7 @@ def _isotp_rx_next(self, rx_data: bytes) -> None: self.rx_done = True elif self.single_frame_mode: # notify ECU to send next frame - msg = b"\x30\x01\x00".ljust(self.max_len, b"\x00") + 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}")