IsoTpMessage: param for single frame flow control (#1079)

* 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
This commit is contained in:
Shane Smiskol 2022-10-05 16:12:24 -07:00 committed by GitHub
parent 9bcd9b9a24
commit 7d196264a4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 12 additions and 3 deletions

View File

@ -376,9 +376,10 @@ class CanClient():
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
@ -459,8 +460,12 @@ class IsoTpMessage():
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
@ -473,6 +478,10 @@ class IsoTpMessage():
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