IsoTpMessage: return if message updated (#1078)

* extend timeout for each message/frame (not multi-frame full response)

* linter
This commit is contained in:
Shane Smiskol
2022-09-27 18:08:09 -07:00
committed by GitHub
parent 10c0991666
commit 51f023bc66

View File

@@ -414,21 +414,23 @@ class IsoTpMessage():
msg = (struct.pack("!H", 0x1000 | self.tx_len) + self.tx_dat[:self.max_len - 2]).ljust(self.max_len - 2, b"\x00")
self._can_client.send([msg])
def recv(self, timeout=None) -> Optional[bytes]:
def recv(self, timeout=None) -> Tuple[Optional[bytes], bool]:
if timeout is None:
timeout = self.timeout
start_time = time.monotonic()
updated = False
try:
while True:
for msg in self._can_client.recv():
self._isotp_rx_next(msg)
start_time = time.monotonic()
updated = True
if self.tx_done and self.rx_done:
return self.rx_dat
return self.rx_dat, updated
# no timeout indicates non-blocking
if timeout == 0:
return None
return None, updated
if time.monotonic() - start_time > timeout:
raise MessageTimeoutError("timeout waiting for response")
finally:
@@ -553,7 +555,7 @@ class UdsClient():
response_pending = False
while True:
timeout = self.response_pending_timeout if response_pending else self.timeout
resp = isotp_msg.recv(timeout)
resp, _ = isotp_msg.recv(timeout)
if resp is None:
continue