Skip to content

Commit 3a6d7db

Browse files
committed
don't hang
1 parent bfa7d2e commit 3a6d7db

File tree

1 file changed

+18
-4
lines changed

1 file changed

+18
-4
lines changed

tests/pedal/enter_canloader.py

+18-4
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,31 @@
11
#!/usr/bin/env python
22
import sys
3+
import time
34
import struct
45
import argparse
6+
import signal
57
from panda import Panda
6-
import time
78

89
class CanHandle(object):
910
def __init__(self, p):
1011
self.p = p
1112

1213
def transact(self, dat):
13-
print "W:",dat.encode("hex")
14+
#print "W:",dat.encode("hex")
1415
self.p.isotp_send(1, dat, 0, recvaddr=2)
15-
ret = self.p.isotp_recv(2, 0, sendaddr=1)
16-
print "R:",ret.encode("hex")
16+
17+
def _handle_timeout(signum, frame):
18+
# will happen on reset
19+
raise Exception("timeout")
20+
21+
signal.signal(signal.SIGALRM, _handle_timeout)
22+
signal.alarm(1)
23+
try:
24+
ret = self.p.isotp_recv(2, 0, sendaddr=1)
25+
finally:
26+
signal.alarm(0)
27+
28+
#print "R:",ret.encode("hex")
1729
return ret
1830

1931
def controlWrite(self, request_type, request, value, index, data, timeout=0):
@@ -58,4 +70,6 @@ def bulkRead(self, endpoint, length, timeout=0):
5870
code = open(args.fn).read()
5971
Panda.flash_static(CanHandle(p), code)
6072

73+
print "can flash done"
74+
6175

0 commit comments

Comments
 (0)