mirror of
https://github.com/infiniteCable2/panda.git
synced 2026-02-18 17:23:52 +08:00
query VIN and stats example from periscope
This commit is contained in:
@@ -1,6 +1,8 @@
|
||||
#!/usr/bin/env python
|
||||
DEBUG = False
|
||||
|
||||
def msg(x):
|
||||
print "S:",x.encode("hex")
|
||||
if DEBUG:
|
||||
print "S:",x.encode("hex")
|
||||
if len(x) <= 7:
|
||||
ret = chr(len(x)) + x
|
||||
else:
|
||||
@@ -68,16 +70,8 @@ def isotp_recv(panda, addr, bus=0):
|
||||
|
||||
dat = dat[0:tlen]
|
||||
|
||||
print "R:",dat.encode("hex")
|
||||
if DEBUG:
|
||||
print "R:",dat.encode("hex")
|
||||
|
||||
return dat
|
||||
|
||||
if __name__ == "__main__":
|
||||
from panda import Panda
|
||||
print "getting VIN"
|
||||
panda = Panda()
|
||||
panda.set_safety_mode(Panda.SAFETY_ALLOUTPUT)
|
||||
panda.can_clear(0)
|
||||
ret = isotp_send(panda, "\x09\x02", 0x7df)
|
||||
print "VIN: %s" % isotp_recv(panda, 0x7e8)
|
||||
|
||||
59
examples/query_vin_and_stats.py
Executable file
59
examples/query_vin_and_stats.py
Executable file
@@ -0,0 +1,59 @@
|
||||
#!/usr/bin/env python
|
||||
import time
|
||||
import struct
|
||||
from panda import Panda
|
||||
from hexdump import hexdump
|
||||
from 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
|
||||
isotp_send(panda, "\x09\x02", 0x7e0)
|
||||
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)
|
||||
|
||||
|
||||
|
||||
@@ -97,7 +97,10 @@ class WifiHandle(object):
|
||||
class Panda(object):
|
||||
SAFETY_NOOUTPUT = 0
|
||||
SAFETY_HONDA = 1
|
||||
SAFETY_TOYOTA = 2
|
||||
SAFETY_TOYOTA_NOLIMITS = 0x1336
|
||||
SAFETY_ALLOUTPUT = 0x1337
|
||||
SAFETY_ELM327 = 0xE327
|
||||
|
||||
SERIAL_DEBUG = 0
|
||||
SERIAL_ESP = 1
|
||||
|
||||
Reference in New Issue
Block a user