Skip to content

Commit 162f485

Browse files
authoredOct 14, 2019
fix chr to bytes conversions (#298)
1 parent 4972376 commit 162f485

File tree

2 files changed

+9
-9
lines changed

2 files changed

+9
-9
lines changed
 

‎examples/query_vin_and_stats.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212

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

1818
def get_supported_pids():

‎python/isotp.py

+8-8
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ def msg(x):
66
if DEBUG:
77
print("S:", binascii.hexlify(x))
88
if len(x) <= 7:
9-
ret = chr(len(x)).encode("utf8") + x
9+
ret = bytes([len(x)]) + x
1010
else:
1111
assert False
1212
return ret.ljust(8, b"\x00")
@@ -40,7 +40,7 @@ def isotp_recv_subaddr(panda, addr, bus, sendaddr, subaddr):
4040
dat = msg[3:]
4141

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

4646
idx = 1
@@ -68,22 +68,22 @@ def isotp_send(panda, x, addr, bus=0, recvaddr=None, subaddr=None):
6868
if len(x) <= 7 and subaddr is None:
6969
panda.can_send(addr, msg(x), bus)
7070
elif len(x) <= 6 and subaddr is not None:
71-
panda.can_send(addr, chr(subaddr).encode("utf8") + msg(x)[0:7], bus)
71+
panda.can_send(addr, bytes([subaddr]) + msg(x)[0:7], bus)
7272
else:
7373
if subaddr:
74-
ss = (chr(subaddr) + chr(0x10 + (len(x)>>8)) + chr(len(x)&0xFF)).encode("utf8") + x[0:5]
74+
ss = bytes([subaddr]) + bytes([0x10 + (len(x) >> 8)]) + bytes([len(x) & 0xFF]) + x[0:5]
7575
x = x[5:]
7676
else:
77-
ss = (chr(0x10 + (len(x)>>8)) + chr(len(x)&0xFF)).encode("utf8") + x[0:6]
77+
ss = bytes([0x10 + (len(x) >> 8)]) + bytes([len(x) & 0xFF]) + x[0:6]
7878
x = x[6:]
7979
idx = 1
8080
sends = []
8181
while len(x) > 0:
8282
if subaddr:
83-
sends.append((((chr(subaddr) + chr(0x20 + (idx&0xF))).encode('utf8') + x[0:6]).ljust(8, b"\x00")))
83+
sends.append(((bytes([subaddr]) + bytes([0x20 + (idx & 0xF)]) + x[0:6]).ljust(8, b"\x00")))
8484
x = x[6:]
8585
else:
86-
sends.append(((chr(0x20 + (idx&0xF)).encode("utf8") + x[0:7]).ljust(8, b"\x00")))
86+
sends.append(((bytes([0x20 + (idx & 0xF)]) + x[0:7]).ljust(8, b"\x00")))
8787
x = x[7:]
8888
idx += 1
8989

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

110-
if msg[0]&0xf0 == 0x10:
110+
if msg[0] & 0xf0 == 0x10:
111111
# first
112112
tlen = ((msg[0] & 0xf) << 8) | msg[1]
113113
dat = msg[2:]

0 commit comments

Comments
 (0)