@@ -26,6 +26,39 @@ def recv(panda, cnt, addr, nbus):
26
26
kmsgs = nmsgs [- 256 :]
27
27
return map (str , ret )
28
28
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
+
29
62
def isotp_send (panda , x , addr , bus = 0 , recvaddr = None , subaddr = None ):
30
63
if recvaddr is None :
31
64
recvaddr = addr + 8
@@ -63,38 +96,6 @@ def isotp_send(panda, x, addr, bus=0, recvaddr=None, subaddr=None):
63
96
else :
64
97
panda .can_send_many ([(addr , None , s , 0 ) for s in sends ])
65
98
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
-
98
99
def isotp_recv (panda , addr , bus = 0 , sendaddr = None , subaddr = None ):
99
100
if sendaddr is None :
100
101
sendaddr = addr - 8
0 commit comments