Skip to content

Commit be82899

Browse files
committed
despite it being bad code, move isotp
1 parent 000715b commit be82899

File tree

2 files changed

+34
-32
lines changed

2 files changed

+34
-32
lines changed

python/__init__.py

+1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
from flash_release import flash_release
1414
from update import ensure_st_up_to_date
1515
from serial import PandaSerial
16+
from isotp import isotp_send, isotp_recv
1617

1718
__version__ = '0.0.6'
1819

examples/isotp.py python/isotp.py

+33-32
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,39 @@ def recv(panda, cnt, addr, nbus):
2626
kmsgs = nmsgs[-256:]
2727
return map(str, ret)
2828

29+
def isotp_recv_subaddr(panda, addr, bus, sendaddr, subaddr):
30+
msg = recv(panda, 1, addr, bus)[0]
31+
32+
# TODO: handle other subaddr also communicating
33+
assert ord(msg[0]) == subaddr
34+
35+
if ord(msg[1])&0xf0 == 0x10:
36+
# first
37+
tlen = ((ord(msg[1]) & 0xf) << 8) | ord(msg[2])
38+
dat = msg[3:]
39+
40+
# 0 block size?
41+
CONTINUE = chr(subaddr) + "\x30" + "\x00"*6
42+
panda.can_send(sendaddr, CONTINUE, bus)
43+
44+
idx = 1
45+
for mm in recv(panda, (tlen-len(dat) + 5)/6, addr, bus):
46+
assert ord(mm[0]) == subaddr
47+
assert ord(mm[1]) == (0x20 | idx)
48+
dat += mm[2:]
49+
idx += 1
50+
elif ord(msg[1])&0xf0 == 0x00:
51+
# single
52+
tlen = ord(msg[1]) & 0xf
53+
dat = msg[2:]
54+
else:
55+
print msg.encode("hex")
56+
assert False
57+
58+
return dat[0:tlen]
59+
60+
# **** import below this line ****
61+
2962
def isotp_send(panda, x, addr, bus=0, recvaddr=None, subaddr=None):
3063
if recvaddr is None:
3164
recvaddr = addr+8
@@ -63,38 +96,6 @@ def isotp_send(panda, x, addr, bus=0, recvaddr=None, subaddr=None):
6396
else:
6497
panda.can_send_many([(addr, None, s, 0) for s in sends])
6598

66-
def isotp_recv_subaddr(panda, addr, bus, sendaddr, subaddr):
67-
msg = recv(panda, 1, addr, bus)[0]
68-
69-
# TODO: handle other subaddr also communicating
70-
assert ord(msg[0]) == subaddr
71-
72-
if ord(msg[1])&0xf0 == 0x10:
73-
# first
74-
tlen = ((ord(msg[1]) & 0xf) << 8) | ord(msg[2])
75-
dat = msg[3:]
76-
77-
# 0 block size?
78-
CONTINUE = chr(subaddr) + "\x30" + "\x00"*6
79-
panda.can_send(sendaddr, CONTINUE, bus)
80-
81-
idx = 1
82-
for mm in recv(panda, (tlen-len(dat) + 5)/6, addr, bus):
83-
assert ord(mm[0]) == subaddr
84-
assert ord(mm[1]) == (0x20 | idx)
85-
dat += mm[2:]
86-
idx += 1
87-
elif ord(msg[1])&0xf0 == 0x00:
88-
# single
89-
tlen = ord(msg[1]) & 0xf
90-
dat = msg[2:]
91-
else:
92-
print msg.encode("hex")
93-
assert False
94-
95-
return dat[0:tlen]
96-
97-
9899
def isotp_recv(panda, addr, bus=0, sendaddr=None, subaddr=None):
99100
if sendaddr is None:
100101
sendaddr = addr-8

0 commit comments

Comments
 (0)