Skip to content

Commit

Permalink
uds: better debug prints
Browse files Browse the repository at this point in the history
  • Loading branch information
gregjhogan committed Nov 13, 2019
1 parent 68c39fb commit b3e1a13
Showing 1 changed file with 5 additions and 6 deletions.
11 changes: 5 additions & 6 deletions python/uds.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
import struct
from typing import Callable, NamedTuple, Tuple, List
from enum import IntEnum
from binascii import hexlify

class SERVICE_TYPE(IntEnum):
DIAGNOSTIC_SESSION_CONTROL = 0x10
ECU_RESET = 0x11
Expand Down Expand Up @@ -287,7 +285,8 @@ def recv(self, drain=False) -> List[bytes]:
else:
for rx_addr, rx_ts, rx_data, rx_bus in msgs or []:
if rx_bus == self.bus and rx_addr in self.rx_addrs and len(rx_data) > 0:
if self.debug: print("CAN-RX: {} - {}".format(hex(rx_addr), hexlify(rx_data)))
rx_data = bytes(rx_data) # convert bytearray to bytes
if self.debug: print(f"CAN-RX: {hex(rx_addr)} - 0x{bytes.hex(rx_data)}")
msg_array.append(rx_data)
# break when non-full buffer is processed
if len(msgs) < 254:
Expand All @@ -299,7 +298,7 @@ def send(self, msgs: List[bytes], delay: float=0) -> None:
if not first and delay:
if self.debug: print(f"CAN-TX: delay - {delay}")
time.sleep(delay)
if self.debug: print("CAN-TX: {} - {}".format(hex(self.tx_addr), hexlify(msg)))
if self.debug: print(f"CAN-TX: {hex(self.tx_addr)} - 0x{bytes.hex(msg)}")
self.tx(self.tx_addr, msg, self.bus)
first = False

Expand All @@ -318,7 +317,7 @@ def send(self, dat: bytes) -> None:
self.tx_idx = 0
self.tx_done = False

if self.debug: print(f"ISO-TP: REQUEST - {hexlify(self.tx_dat)}")
if self.debug: print(f"ISO-TP: REQUEST - 0x{bytes.hex(self.tx_dat)}")
self._tx_first_frame()

def _tx_first_frame(self) -> None:
Expand Down Expand Up @@ -349,7 +348,7 @@ def recv(self) -> bytes:
if time.time() - start_time > self.timeout:
raise MessageTimeoutError("timeout waiting for response")
finally:
if self.debug: print(f"ISO-TP: RESPONSE - {hexlify(self.rx_dat)}")
if self.debug: print(f"ISO-TP: RESPONSE - 0x{bytes.hex(self.rx_dat)}")

def _isotp_rx_next(self, rx_data: bytes) -> None:
# single rx_frame
Expand Down

0 comments on commit b3e1a13

Please sign in to comment.