|
1
|
|
|
# Information about OBD-II PIDs |
|
2
|
|
|
# http://en.wikipedia.org/wiki/OBD-II_PIDs |
|
3
|
|
|
|
|
4
|
|
|
# PID hex codes |
|
5
|
|
|
PIDS_SUPPORTED_00_20 = "00" |
|
6
|
|
|
MONITOR_STATUS_SINCE_DTC_CLEARED = "01" |
|
7
|
|
|
FREEZE_DTC = "02" |
|
8
|
|
|
VEHICLE_IDENTIFICATION_NUMBER = "02" |
|
9
|
|
|
FUEL_SYSTEM_STATUS = "03" |
|
10
|
|
|
CALCULATED_ENGINE_LOAD = "04" |
|
11
|
|
|
ENGINE_COOLANT_TEMPERATURE = "05" |
|
12
|
|
|
SHORT_TERM_FUEL_TRIM_BANK_1 = "06" |
|
13
|
|
|
LONG_TERM_FUEL_TRIM_BANK_1 = "07" |
|
14
|
|
|
SHORT_TERM_FUEL_TRIM_BANK_2 = "08" |
|
15
|
|
|
LONG_TERM_FUEL_TRIM_BANK_2 = "09" |
|
16
|
|
|
FUEL_PRESSURE = "0A" |
|
17
|
|
|
ECU_NAME = "0A" |
|
18
|
|
|
INTAKE_MANIFOLD_PRESSURE = "0B" |
|
19
|
|
|
ENGINE_RPM = "0C" |
|
20
|
|
|
VEHICLE_SPEED = "0D" |
|
21
|
|
|
TIMING_ADVANCE = "0E" |
|
22
|
|
|
INTAKE_AIR_TEMPERATURE = "0F" |
|
23
|
|
|
MAF_AIR_FLOW = "10" |
|
24
|
|
|
THROTTLE_POSITION = "11" |
|
25
|
|
|
|
|
26
|
|
|
# TODO: Oxygen sensors |
|
27
|
|
|
|
|
28
|
|
|
AUXILIARY_INPUT_STATUS = "1E" |
|
29
|
|
|
ENGINE_RUN_TIME_SINCE_START = "1F" |
|
30
|
|
|
PIDS_SUPPORTED_21_40 = "20" |
|
31
|
|
|
DISTANCE_TRAVELED_WITH_MIL_ON = "21" |
|
32
|
|
|
|
|
33
|
|
|
FUEL_RAIL_PRESSURE = "23" |
|
34
|
|
|
|
|
35
|
|
|
COMMANDED_EGR = "2C" |
|
36
|
|
|
EGR_ERROR = "2D" |
|
37
|
|
|
COMMANDED_EVAPORATIVE_PURGE = "2E" |
|
38
|
|
|
FUEL_LEVEL_INPUT = "2F" |
|
39
|
|
|
DISTANCE_TRAVELED_SINCE_CODES_CLEARED = "31" |
|
40
|
|
|
EVAP_SYSTEM_VAPOR_PRESSURE = "32" |
|
41
|
|
|
BAROMETRIC_PRESSURE = "33" |
|
42
|
|
|
|
|
43
|
|
|
PIDS_SUPPORTED_41_60 = "40" |
|
44
|
|
|
CONTROL_MODULE_VOLTAGE = "41" |
|
45
|
|
|
ABSOLUTE_LOAD_VALUE = "42" |
|
46
|
|
|
AMBIENT_AIR_TEMPERATURE = "46" |
|
47
|
|
|
|
|
48
|
|
|
TIME_RUN_WITH_MIL_ON = "4D" |
|
49
|
|
|
TIME_SINCE_TROUBLE_CODES_CLEARED = "4E" |
|
50
|
|
|
|
|
51
|
|
|
FUEL_TYPE = "51" |
|
52
|
|
|
ETHANOL_FUEL_PERCENTAGE = "52" |
|
53
|
|
|
|
|
54
|
|
|
RELATIVE_ACCELERATOR_PEDAL_POSITION = "5A" |
|
55
|
|
|
HYBRID_BATTERY_PACK_REMAINING_LIFE = "5B" |
|
56
|
|
|
ENGINE_OIL_TEMPERATURE = "5C" |
|
57
|
|
|
FUEL_INJECTION_TIMING = "5D" |
|
58
|
|
|
ENGINE_FUEL_RATE = "5E" |
|
59
|
|
|
|
|
60
|
|
|
PIDS_SUPPORTED_61_80 = "60" |
|
61
|
|
|
ENGINE_PERCENT_TORQUE = "64" |
|
62
|
|
|
|
|
63
|
|
|
# TODO: remaining PIDs |
|
64
|
|
|
|
|
65
|
|
|
# Mode 01 PID 51 returns a value for the vehicle's fuel type |
|
66
|
|
|
|
|
67
|
|
|
FUEL_TYPE_DESCRIPTION = ( |
|
68
|
|
|
'Not Available', |
|
69
|
|
|
'Gasoline', |
|
70
|
|
|
'Methanol', |
|
71
|
|
|
'Ethanol', |
|
72
|
|
|
'Diesel', |
|
73
|
|
|
'Liquefied petroleum gas (LPG)', |
|
74
|
|
|
'Compressed natural gas (CNG)', |
|
75
|
|
|
'Propane', |
|
76
|
|
|
'Electric', |
|
77
|
|
|
'Bifuel running Gasoline', |
|
78
|
|
|
'Bifuel running Methanol', |
|
79
|
|
|
'Bifuel running Ethanol', |
|
80
|
|
|
'Bifuel running Liquefied petroleum gas (LPG)', |
|
81
|
|
|
'Bifuel running Compressed natural gas (CNG)', |
|
82
|
|
|
'Bifuel running Propane', |
|
83
|
|
|
'Bifuel running Electricity', |
|
84
|
|
|
'Bifuel running electric and combustion engine', |
|
85
|
|
|
'Hybrid gasoline', |
|
86
|
|
|
'Hybrid Ethanol', |
|
87
|
|
|
'Hybrid Diesel', |
|
88
|
|
|
'Hybrid Electric', |
|
89
|
|
|
'Hybrid running electric and combustion engine', |
|
90
|
|
|
'Hybrid Regenerative', |
|
91
|
|
|
'Bifuel running diesel' |
|
92
|
|
|
) |
|
93
|
|
|
|
|
94
|
|
|
FUEL_SYSTEM_STATUS_DESC = { |
|
95
|
|
|
0: 'No fuel system available', |
|
96
|
|
|
1: 'Open loop due to insufficient engine temperature', |
|
97
|
|
|
2: 'Closed loop, using oxygen sensor feedback to determine fuel mix', |
|
98
|
|
|
4: 'Open loop due to engine load OR fuel cut to deceleration', |
|
99
|
|
|
8: 'Open loop due to system failure', |
|
100
|
|
|
16: 'Closed loop, using at least one oxygen sensor but there is a fault in the feedback system' |
|
101
|
|
|
} |
|
102
|
|
|
|
|
103
|
|
|
# Mode 01 PID 12 returns a single byte of data which describes the |
|
104
|
|
|
# secondary air status. |
|
105
|
|
|
SECONDARY_AIR_STATUS = { |
|
106
|
|
|
1: 'Upstream', |
|
107
|
|
|
2: 'Downstream of catalytic converter', |
|
108
|
|
|
4: 'From the outside atmosphere or off', |
|
109
|
|
|
8: 'Pump commanded on for diagnostics', |
|
110
|
|
|
} |
|
111
|
|
|
|
|
112
|
|
|
# Mode 01 PID 1C returns a single byte of data which describes which OBD |
|
113
|
|
|
# standards. |
|
114
|
|
|
OBD_STANDARDS = ( |
|
115
|
|
|
None, |
|
116
|
|
|
'OBD-II as defined by the CARB', |
|
117
|
|
|
'OBD as defined by the EPA', |
|
118
|
|
|
'OBD and OBD-II', |
|
119
|
|
|
'OBD-I', |
|
120
|
|
|
'Not OBD compliant', |
|
121
|
|
|
'EOBD (Europe)', |
|
122
|
|
|
'EOBD and OBD-II', |
|
123
|
|
|
'EOBD and OBD', |
|
124
|
|
|
'EOBD, OBD and OBD II', |
|
125
|
|
|
'JOBD (Japan)', |
|
126
|
|
|
'JOBD and OBD II', |
|
127
|
|
|
'JOBD and EOBD', |
|
128
|
|
|
'JOBD, EOBD, and OBD II', |
|
129
|
|
|
'Reserved', |
|
130
|
|
|
'Reserved', |
|
131
|
|
|
'Reserved', |
|
132
|
|
|
'Engine Manufacturer Diagnostics (EMD)', |
|
133
|
|
|
'Engine Manufacturer Diagnostics Enhanced (EMD+)', |
|
134
|
|
|
'Heavy Duty On-Board Diagnostics (Child/Partial) (HD OBD-C)', |
|
135
|
|
|
'Heavy Duty On-Board Diagnostics (HD OBD)', |
|
136
|
|
|
'World Wide Harmonized OBD (WWH OBD)', |
|
137
|
|
|
'Reserved', |
|
138
|
|
|
'Heavy Duty Euro OBD Stage I without NOx control (HD EOBD-I)', |
|
139
|
|
|
'Heavy Duty Euro OBD Stage I with NOx control (HD EOBD-I N)', |
|
140
|
|
|
'Heavy Duty Euro OBD Stage II without NOx control (HD EOBD-II)', |
|
141
|
|
|
'Heavy Duty Euro OBD Stage II with NOx control (HD EOBD-II N)', |
|
142
|
|
|
'Reserved', |
|
143
|
|
|
'Brazil OBD Phase 1 (OBDBr-1)', |
|
144
|
|
|
'Brazil OBD Phase 2 (OBDBr-2)', |
|
145
|
|
|
'Korean OBD (KOBD)', |
|
146
|
|
|
'India OBD I (IOBD I)', |
|
147
|
|
|
'India OBD II (IOBD II)', |
|
148
|
|
|
'Heavy Duty Euro OBD Stage VI (HD EOBD-IV)' |
|
149
|
|
|
) |
|
150
|
|
|
|
|
151
|
|
|
DTCs_table = { |
|
152
|
|
|
'0': 'P0', |
|
153
|
|
|
'1': 'P1', |
|
154
|
|
|
'2': 'P2', |
|
155
|
|
|
'3': 'P3', |
|
156
|
|
|
'4': 'C0', |
|
157
|
|
|
'5': 'C1', |
|
158
|
|
|
'6': 'C2', |
|
159
|
|
|
'7': 'C3', |
|
160
|
|
|
'8': 'B0', |
|
161
|
|
|
'9': 'B1', |
|
162
|
|
|
'A': 'B2', |
|
163
|
|
|
'B': 'B3', |
|
164
|
|
|
'C': 'U0', |
|
165
|
|
|
'D': 'U1', |
|
166
|
|
|
'E': 'U2', |
|
167
|
|
|
'F': 'U3' |
|
168
|
|
|
|
|
169
|
|
|
} |
|
170
|
|
|
|
|
171
|
|
|
from obdlib.utils import * |
|
172
|
|
|
|
|
173
|
|
|
|
|
174
|
|
|
class Pids(object): |
|
175
|
|
|
""" |
|
176
|
|
|
Retrieves pid info from the mode file |
|
177
|
|
|
gets a necessary pid only |
|
178
|
|
|
""" |
|
179
|
|
|
|
|
180
|
|
|
def __init__(self): |
|
181
|
|
|
self.mode = 0 |
|
182
|
|
|
self.command_path = "obdlib/obd/commands/pids.{}" |
|
183
|
|
|
|
|
184
|
|
|
def set_mode(self, mode): |
|
185
|
|
|
""" |
|
186
|
|
|
Sets the current mode |
|
187
|
|
|
:param mode: integer - current mode |
|
188
|
|
|
:return self |
|
189
|
|
|
""" |
|
190
|
|
|
self.mode = mode |
|
191
|
|
|
return self |
|
192
|
|
|
|
|
193
|
|
|
def __getitem__(self, item): |
|
194
|
|
|
""" |
|
195
|
|
|
Gets one pid only |
|
196
|
|
|
:param item: integer - the pid number |
|
197
|
|
|
:return pid: tuple - params about pid |
|
198
|
|
|
""" |
|
199
|
|
|
pid = () |
|
200
|
|
|
with open(self.command_path.format(self.mode)) as pids: |
|
201
|
|
|
for index, value in enumerate(pids): |
|
202
|
|
|
if index == item: |
|
203
|
|
|
pid = eval(value) |
|
204
|
|
|
break |
|
205
|
|
|
|
|
206
|
|
|
return pid |