openpilot is an open source driver assistance system. openpilot performs the functions of Automated Lane Centering and Adaptive Cruise Control for over 200 supported car makes and models.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

60 lines
1.7 KiB

#!/usr/bin/env python
import time
import struct
from panda import Panda
from hexdump import hexdump
Squashed 'panda/' changes from 3e199cb..7f8babb 7f8babb Much more thorough limit safety tests on Honda, also switching long_controls_allowed 71099ef AddedToyota safety test around long_controls_allowed logic and fixed a bug 07fd31e added long_controls_allowed tests in GM 6ce580a added function to get/set long_controls_allowed a2f93d4 update VERSION 380b7c7 Long allowed (#202) 09714e3 Toyota gas cancellation (#200) 436b203 Honda safety: fixed bug and properly abstracted gas_interceptor_detected variable 220cc8f Honda safety: this concludes the proper re-naming a00a50c Honda safety: better naming 95b0109 Toyota: fixed regression safety tests 192fd05 Toyota safety: fixed rounding logic 0c5b220 Merge pull request #194 from commaai/refactor b35f6ff legacy build is no longer supported a06af9f always LIVE on EON dc5979f LIVE on EON 0b26645 no EON by default 1906a4b panda now draws below 100mw in power save mode e70b44a move that to main.c dfce5f6 minor fixes, and no more autobaud 7f303e8 bump version to 1.3.0 96a7e31 a soothing blue in power save mode a74f001 refactor power savings to depend on car started bit 386d5df can wake from sleep is removed, didn't work in the first place 881b1f4 not on pedal chip 0a9f8eb remove many ifdef PANDA 5069005 remove nested includes and include guards 3810452 WTF WHY WAS THIS SHIT PUT EVERYWHERE 3cf8db9 can.h always has CAN3 1f97c21 refactor pedal bootstub to use llcan 58ec63b oops, backward 6255097 new style power savings 6b282f1 tesla doesn't need a special LIN hook 1d24677 refactor #ifdef EON d9306c5 NEO are no longer supported 4af036e fixup puts 2c1e5f6 the refactor continues 7517f2c remove ifdef PANDA from main aec40ae remove fan, as it was only for NEO board 605bb27 fix bootstub build c0f1f6e move things around for simplicity f32f039 factor out clear_send 8221927 this is probably broken. refactor out llcan and clock 1114cb1 ELM327 safety mode: re use existing functions cd104e2 Vin query msg is 0x7df 223323a Examples: fixed import bug 533d239 update price 4396fb9 Update jenkinsfile (#193) 1aa00c9 Misra c2012 (#192) 047bd72 fix tests and remove rev b support git-subtree-dir: panda git-subtree-split: 7f8babb8adf6e9c10bf3aecbe8c8eac0b155d066 old-commit-hash: 9a143c5ab2b86bd5dbfa0e86ac85c2d48f1de4f3
6 years ago
from panda.python.isotp import isotp_send, isotp_recv
# 0x7e0 = Toyota
# 0x18DB33F1 for Honda?
def get_current_data_for_pid(pid):
# 01 xx = Show current data
isotp_send(panda, "\x01"+chr(pid), 0x7e0)
return isotp_recv(panda, 0x7e8)
def get_supported_pids():
ret = []
pid = 0
while 1:
supported = struct.unpack(">I", get_current_data_for_pid(pid)[2:])[0]
for i in range(1+pid, 0x21+pid):
if supported & 0x80000000:
ret.append(i)
supported <<= 1
pid += 0x20
if pid not in ret:
break
return ret
if __name__ == "__main__":
panda = Panda()
panda.set_safety_mode(Panda.SAFETY_ELM327)
panda.can_clear(0)
# 09 02 = Get VIN
Squashed 'panda/' changes from 3e199cb..7f8babb 7f8babb Much more thorough limit safety tests on Honda, also switching long_controls_allowed 71099ef AddedToyota safety test around long_controls_allowed logic and fixed a bug 07fd31e added long_controls_allowed tests in GM 6ce580a added function to get/set long_controls_allowed a2f93d4 update VERSION 380b7c7 Long allowed (#202) 09714e3 Toyota gas cancellation (#200) 436b203 Honda safety: fixed bug and properly abstracted gas_interceptor_detected variable 220cc8f Honda safety: this concludes the proper re-naming a00a50c Honda safety: better naming 95b0109 Toyota: fixed regression safety tests 192fd05 Toyota safety: fixed rounding logic 0c5b220 Merge pull request #194 from commaai/refactor b35f6ff legacy build is no longer supported a06af9f always LIVE on EON dc5979f LIVE on EON 0b26645 no EON by default 1906a4b panda now draws below 100mw in power save mode e70b44a move that to main.c dfce5f6 minor fixes, and no more autobaud 7f303e8 bump version to 1.3.0 96a7e31 a soothing blue in power save mode a74f001 refactor power savings to depend on car started bit 386d5df can wake from sleep is removed, didn't work in the first place 881b1f4 not on pedal chip 0a9f8eb remove many ifdef PANDA 5069005 remove nested includes and include guards 3810452 WTF WHY WAS THIS SHIT PUT EVERYWHERE 3cf8db9 can.h always has CAN3 1f97c21 refactor pedal bootstub to use llcan 58ec63b oops, backward 6255097 new style power savings 6b282f1 tesla doesn't need a special LIN hook 1d24677 refactor #ifdef EON d9306c5 NEO are no longer supported 4af036e fixup puts 2c1e5f6 the refactor continues 7517f2c remove ifdef PANDA from main aec40ae remove fan, as it was only for NEO board 605bb27 fix bootstub build c0f1f6e move things around for simplicity f32f039 factor out clear_send 8221927 this is probably broken. refactor out llcan and clock 1114cb1 ELM327 safety mode: re use existing functions cd104e2 Vin query msg is 0x7df 223323a Examples: fixed import bug 533d239 update price 4396fb9 Update jenkinsfile (#193) 1aa00c9 Misra c2012 (#192) 047bd72 fix tests and remove rev b support git-subtree-dir: panda git-subtree-split: 7f8babb8adf6e9c10bf3aecbe8c8eac0b155d066 old-commit-hash: 9a143c5ab2b86bd5dbfa0e86ac85c2d48f1de4f3
6 years ago
isotp_send(panda, "\x09\x02", 0x7df)
ret = isotp_recv(panda, 0x7e8)
hexdump(ret)
print "VIN: %s" % ret[2:]
# 03 = get DTCS
isotp_send(panda, "\x03", 0x7e0)
dtcs = isotp_recv(panda, 0x7e8)
print "DTCs:", dtcs[2:].encode("hex")
supported_pids = get_supported_pids()
print "Supported PIDs:",supported_pids
while 1:
speed = struct.unpack(">B", get_current_data_for_pid(13)[2:])[0] # kph
rpm = struct.unpack(">H", get_current_data_for_pid(12)[2:])[0]/4.0 # revs
throttle = struct.unpack(">B", get_current_data_for_pid(17)[2:])[0]/255.0 * 100 # percent
temp = struct.unpack(">B", get_current_data_for_pid(5)[2:])[0] - 40 # degrees C
load = struct.unpack(">B", get_current_data_for_pid(4)[2:])[0]/255.0 * 100 # percent
print "%d KPH, %d RPM, %.1f%% Throttle, %d deg C, %.1f%% load" % (speed, rpm, throttle, temp, load)
time.sleep(0.2)