Skip to content

Commit c58fbdc

Browse files
applegurugeohot
authored andcommitted
Adding a an example for outputting CAN data to a tesla from Panda
1 parent 1a7b95e commit c58fbdc

File tree

1 file changed

+42
-0
lines changed

1 file changed

+42
-0
lines changed

examples/tesla_tester.py

+42
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
#!/usr/bin/env python
2+
import sys
3+
from panda import Panda
4+
5+
def tesla_tester():
6+
7+
try:
8+
print("Trying to connect to Panda over USB...")
9+
p = Panda()
10+
11+
except AssertionError:
12+
print("USB connection failed. Trying WiFi...")
13+
14+
try:
15+
p = Panda("WIFI")
16+
except:
17+
print("WiFi connection timed out. Please make sure your Panda is connected and try again.")
18+
sys.exit(0)
19+
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)
23+
24+
# Now set the panda from its default of SAFETY_NOOUTPUT (read only) to SAFETY_ALLOUTPUT
25+
# Careful, as this will let us send any CAN messages we want (which could be very bad!)
26+
print("Setting Panda to output mode...")
27+
p.set_safety_mode(Panda.SAFETY_ALLOUTPUT)
28+
29+
# BDY 0x248 is the MCU_commands message, which includes folding mirrors, opening the trunk, frunk, setting the cars lock state and more. For our test, we will edit the 3rd byte, which is MCU_lockRequest. 0x01 will lock, 0x02 will unlock:
30+
print("Unlocking Tesla...")
31+
p.can_send(0x248, "\x00\x00\x02\x00\x00\x00\x00\x00", bus_num)
32+
33+
#Or, we can set the first byte, MCU_frontHoodCommand + MCU_liftgateSwitch, to 0x01 to pop the frunk, or 0x04 to open/close the trunk (0x05 should open both)
34+
print("Opening Frunk...")
35+
p.can_send(0x248, "\x01\x00\x00\x00\x00\x00\x00\x00", bus_num)
36+
37+
#Back to safety...
38+
print("Disabling output on Panda...")
39+
p.set_safety_mode(Panda.SAFETY_NOOUTPUT)
40+
41+
if __name__ == "__main__":
42+
tesla_tester()

0 commit comments

Comments
 (0)