1
1
#!/usr/bin/env python
2
2
import sys
3
+ import binascii
3
4
from panda import Panda
4
5
5
6
def tesla_tester ():
@@ -17,9 +18,9 @@ def tesla_tester():
17
18
print ("WiFi connection timed out. Please make sure your Panda is connected and try again." )
18
19
sys .exit (0 )
19
20
20
- bus_speed = 125 # Tesla Body busses (B, BF) are 125kbps, rest are 500kbps
21
- bus_num = 1 # My TDC to OBD adapter has PT on bus0 BDY on bus1 and CH on bus2
22
- p .set_can_speed_kbps (bus_num , bus_speed )
21
+ body_bus_speed = 125 # Tesla Body busses (B, BF) are 125kbps, rest are 500kbps
22
+ body_bus_num = 1 # My TDC to OBD adapter has PT on bus0 BDY on bus1 and CH on bus2
23
+ p .set_can_speed_kbps (body_bus_num , body_bus_speed )
23
24
24
25
# Now set the panda from its default of SAFETY_NOOUTPUT (read only) to SAFETY_ALLOUTPUT
25
26
# Careful, as this will let us send any CAN messages we want (which could be very bad!)
@@ -38,5 +39,25 @@ def tesla_tester():
38
39
print ("Disabling output on Panda..." )
39
40
p .set_safety_mode (Panda .SAFETY_NOOUTPUT )
40
41
42
+ print ("Reading VIN from 0x568. This is painfully slow and can take up to 3 minutes (1 minute per message; 3 messages needed for full VIN)..." )
43
+
44
+ cnt = 0
45
+ vin = {}
46
+ while True :
47
+ #Read the VIN
48
+ can_recv = p .can_recv ()
49
+ for address , _ , dat , src in can_recv :
50
+ if src == body_bus_num :
51
+ if address == 1384 : #0x568 is VIN
52
+ vin_index = int (binascii .hexlify (dat )[:2 ]) #first byte is the index, 00, 01, 02
53
+ vin_string = binascii .hexlify (dat )[2 :] #rest of the string is the actual VIN data
54
+ vin [vin_index ] = vin_string .decode ("hex" )
55
+ print ("Got VIN index " + str (vin_index ) + " data " + vin [vin_index ])
56
+ cnt += 1
57
+ #if we have all 3 parts of the VIN, print it and break out of our while loop
58
+ if cnt == 3 :
59
+ print ("VIN: " + vin [0 ] + vin [1 ] + vin [2 ][:3 ])
60
+ break
61
+
41
62
if __name__ == "__main__" :
42
63
tesla_tester ()
0 commit comments