Skip to content

Commit

Permalink
fix chr to bytes conversions (#298)
Browse files Browse the repository at this point in the history
  • Loading branch information
rbiasini authored Oct 14, 2019
1 parent 4972376 commit 162f485
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 9 deletions.
2 changes: 1 addition & 1 deletion examples/query_vin_and_stats.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

def get_current_data_for_pid(pid):
# 01 xx = Show current data
isotp_send(panda, b"\x01"+ (chr(pid)).encode("utf8"), 0x7e0)
isotp_send(panda, b"\x01"+ bytes([pid]), 0x7e0)
return isotp_recv(panda, 0x7e8)

def get_supported_pids():
Expand Down
16 changes: 8 additions & 8 deletions python/isotp.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ def msg(x):
if DEBUG:
print("S:", binascii.hexlify(x))
if len(x) <= 7:
ret = chr(len(x)).encode("utf8") + x
ret = bytes([len(x)]) + x
else:
assert False
return ret.ljust(8, b"\x00")
Expand Down Expand Up @@ -40,7 +40,7 @@ def isotp_recv_subaddr(panda, addr, bus, sendaddr, subaddr):
dat = msg[3:]

# 0 block size?
CONTINUE = chr(subaddr).encode("utf8") + b"\x30" + b"\x00"*6
CONTINUE = bytes([subaddr]) + b"\x30" + b"\x00"*6
panda.can_send(sendaddr, CONTINUE, bus)

idx = 1
Expand Down Expand Up @@ -68,22 +68,22 @@ def isotp_send(panda, x, addr, bus=0, recvaddr=None, subaddr=None):
if len(x) <= 7 and subaddr is None:
panda.can_send(addr, msg(x), bus)
elif len(x) <= 6 and subaddr is not None:
panda.can_send(addr, chr(subaddr).encode("utf8") + msg(x)[0:7], bus)
panda.can_send(addr, bytes([subaddr]) + msg(x)[0:7], bus)
else:
if subaddr:
ss = (chr(subaddr) + chr(0x10 + (len(x)>>8)) + chr(len(x)&0xFF)).encode("utf8") + x[0:5]
ss = bytes([subaddr]) + bytes([0x10 + (len(x) >> 8)]) + bytes([len(x) & 0xFF]) + x[0:5]
x = x[5:]
else:
ss = (chr(0x10 + (len(x)>>8)) + chr(len(x)&0xFF)).encode("utf8") + x[0:6]
ss = bytes([0x10 + (len(x) >> 8)]) + bytes([len(x) & 0xFF]) + x[0:6]
x = x[6:]
idx = 1
sends = []
while len(x) > 0:
if subaddr:
sends.append((((chr(subaddr) + chr(0x20 + (idx&0xF))).encode('utf8') + x[0:6]).ljust(8, b"\x00")))
sends.append(((bytes([subaddr]) + bytes([0x20 + (idx & 0xF)]) + x[0:6]).ljust(8, b"\x00")))
x = x[6:]
else:
sends.append(((chr(0x20 + (idx&0xF)).encode("utf8") + x[0:7]).ljust(8, b"\x00")))
sends.append(((bytes([0x20 + (idx & 0xF)]) + x[0:7]).ljust(8, b"\x00")))
x = x[7:]
idx += 1

Expand All @@ -107,7 +107,7 @@ def isotp_recv(panda, addr, bus=0, sendaddr=None, subaddr=None):
else:
msg = recv(panda, 1, addr, bus)[0]

if msg[0]&0xf0 == 0x10:
if msg[0] & 0xf0 == 0x10:
# first
tlen = ((msg[0] & 0xf) << 8) | msg[1]
dat = msg[2:]
Expand Down

0 comments on commit 162f485

Please sign in to comment.