forked from JonnoFTW/rpi-can-logger
-
Notifications
You must be signed in to change notification settings - Fork 0
/
query_single_pid.py
executable file
·35 lines (32 loc) · 973 Bytes
/
query_single_pid.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
#!/usr/bin/env python3
import can
import atexit
import time
from rpi_can_logger.logger import obd_pids
from util import get_args
interface, channel = get_args()
bus = can.interface.Bus(channel=channel, bustype=interface)
atexit.register(bus.shutdown)
print("Querying PID on CAN:", bus)
while 1:
try:
pid = 0
while pid <= 0xC4:
time.sleep(0.1)
if 0x100+pid in obd_pids:
disp = obd_pids[0x100+pid]['name']
else:
disp = hex(pid)
print("Requesting",disp)
msg = can.Message(extended_id=0, data=[2, 1, pid, 0, 0, 0, 0, 0], arbitration_id=0x07DF)
# print(msg)
bus.send(msg)
for i in range(100):
msg = bus.recv()
if msg.arbitration_id in [0x7df, 0x7e8]:
print("R>", msg)
pid += 1
break
except KeyboardInterrupt:
print("Terminating")
break