This repository has been archived by the owner on Sep 30, 2024. It is now read-only.
forked from peterh/pyobd
-
Notifications
You must be signed in to change notification settings - Fork 0
/
pynog.py
102 lines (88 loc) · 2.19 KB
/
pynog.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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
import obd_io
import os
import threading
import sys
import serial
import platform
import time
# import ConfigParser
from subprocess import call
from obd2_codes import pcodes
from obd2_codes import ptest
from obd_utils import scanSerial
ID_ABOUT = 101
ID_EXIT = 110
ID_CONFIG = 500
ID_CLEAR = 501
ID_GETC = 502
ID_RESET = 503
ID_LOOK = 504
ALL_ON = 505
ALL_OFF = 506
ID_DISCONNECT = 507
ID_HELP_ABOUT = 508
ID_HELP_VISIT = 509
ID_HELP_ORDER = 510
# call("sudo rfcomm connect /dev/rfcomm0 00:1D:A5:02:12:18 1",shell=True)
# time.sleep(4) # Sleeping More Than Necessary, better to wait for shell response
port = obd_io.OBDPort("/dev/rfcomm0",None,5,0)
print("Consider Using A Window")
def initCommunication():
#call("sudo rfcomm connect 0 00:1D:A5:00:0F:A1 &>/dev/null",shell=True)
if port.State == 0:
return None
active = []
supp = port.sensor(0)[1]
print("Comm initialized")
print(active)
print(supp)
for i in range(1, len(supp)):
if supp[i-1] == "1": #put X in coloum if PID is supported
active.append(1)
else:
active.append(0)
#while(1):
#for i in range(len(supp)):
# for i in range(50):
# if supp[i]=="1":
# try:
# print `((port.sensor(12)[1]-1346500000)-689000)/10.55-700`+"RPM"
# except:
# print "ERROR ERROR"
initCommunication()
def getRPM():
rpms = port.sensor(12)[1]
try:
# return ((port.sensor(12)[1]-1346500000)-689000)/10.5-700
rpms = port.sensor(12)[1]
return int(rpms)
except:
return "err"
def getSpeed():
try:
speeds = port.sensor(13)[1]
speeds = int(speeds)
speeds /= 1.609
return int(speeds)
except:
return "Drugs are bad mmmkay?"
def getCoolantTemp():
try:
return port.sensor(5)[1]
except:
return "err"
def getIntakeTemp():
try:
return port.sensor(15)[1]
except:
return "err"
def getThrottle():
try:
return int(( port.sensor(17)[1] )*100.0/255.0)
except:
return "err"
def getLoad():
try:
return int(( port.sensor(4)[1] )*100.0/255.0)
except:
return "err"