Skip to content

Commit 160c9c0

Browse files
applegurugeohot
authored andcommitted
Add tesla VIN decoder
1 parent c58fbdc commit 160c9c0

File tree

2 files changed

+26
-3
lines changed

2 files changed

+26
-3
lines changed

.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,5 @@ a.out
88
dist/
99
pandacan.egg-info/
1010
board/obj/
11+
examples/output.csv
12+
.DS_Store

examples/tesla_tester.py

+24-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#!/usr/bin/env python
22
import sys
3+
import binascii
34
from panda import Panda
45

56
def tesla_tester():
@@ -17,9 +18,9 @@ def tesla_tester():
1718
print("WiFi connection timed out. Please make sure your Panda is connected and try again.")
1819
sys.exit(0)
1920

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)
2324

2425
# Now set the panda from its default of SAFETY_NOOUTPUT (read only) to SAFETY_ALLOUTPUT
2526
# Careful, as this will let us send any CAN messages we want (which could be very bad!)
@@ -38,5 +39,25 @@ def tesla_tester():
3839
print("Disabling output on Panda...")
3940
p.set_safety_mode(Panda.SAFETY_NOOUTPUT)
4041

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+
4162
if __name__ == "__main__":
4263
tesla_tester()

0 commit comments

Comments
 (0)