2019-09-25 08:50:53 +08:00
|
|
|
#!/usr/bin/env python3
|
2017-10-01 10:20:33 +08:00
|
|
|
import time
|
|
|
|
import struct
|
|
|
|
from panda import Panda
|
|
|
|
from hexdump import hexdump
|
2019-05-23 02:49:54 +08:00
|
|
|
from panda.python.isotp import isotp_send, isotp_recv
|
2017-10-01 10:20:33 +08:00
|
|
|
|
|
|
|
# 0x7e0 = Toyota
|
|
|
|
# 0x18DB33F1 for Honda?
|
|
|
|
|
2019-10-11 03:34:52 +08:00
|
|
|
|
2017-10-01 10:20:33 +08:00
|
|
|
def get_current_data_for_pid(pid):
|
|
|
|
# 01 xx = Show current data
|
2019-10-14 09:15:04 +08:00
|
|
|
isotp_send(panda, b"\x01"+ bytes([pid]), 0x7e0)
|
2017-10-01 10:20:33 +08:00
|
|
|
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
|
2019-10-11 03:34:52 +08:00
|
|
|
isotp_send(panda, b"\x09\x02", 0x7df)
|
2017-10-01 10:20:33 +08:00
|
|
|
ret = isotp_recv(panda, 0x7e8)
|
|
|
|
hexdump(ret)
|
2019-10-11 03:34:52 +08:00
|
|
|
print("VIN: %s" % "".join(map(chr, ret[:2])))
|
2017-10-01 10:20:33 +08:00
|
|
|
|
|
|
|
# 03 = get DTCS
|
2019-10-11 03:34:52 +08:00
|
|
|
isotp_send(panda, b"\x03", 0x7e0)
|
2017-10-01 10:20:33 +08:00
|
|
|
dtcs = isotp_recv(panda, 0x7e8)
|
2019-10-11 03:34:52 +08:00
|
|
|
print("DTCs:", "".join(map(chr, dtcs[:2])))
|
2017-10-01 10:20:33 +08:00
|
|
|
|
|
|
|
supported_pids = get_supported_pids()
|
2019-09-25 09:02:15 +08:00
|
|
|
print("Supported PIDs:",supported_pids)
|
2017-10-01 10:20:33 +08:00
|
|
|
|
|
|
|
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
|
2019-09-25 09:02:15 +08:00
|
|
|
print("%d KPH, %d RPM, %.1f%% Throttle, %d deg C, %.1f%% load" % (speed, rpm, throttle, temp, load))
|
2017-10-01 10:20:33 +08:00
|
|
|
time.sleep(0.2)
|
|
|
|
|
|
|
|
|
|
|
|
|