Skip to content

Commit 5bbf2a2

Browse files
author
Brendan Whitfield
committed
started tweaking get_DTC functions
1 parent bfe779d commit 5bbf2a2

3 files changed

Lines changed: 9 additions & 14 deletions

File tree

obd/commands.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,7 @@ def __eq__(self, other):
252252

253253
__mode3__ = [
254254
# sensor name description mode cmd bytes decoder
255-
OBDCommand("GET_DTC" , "Get DTCs" , "03", "" , 0, noop ),
255+
OBDCommand("GET_DTC" , "Get DTCs" , "03", "" , 6, noop ),
256256
]
257257

258258
__mode4__ = [

obd/decoders.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -355,13 +355,11 @@ def dtc(_hex):
355355

356356
# converts a frame of 2-byte DTCs into a list of DTCs
357357
def dtc_frame(_hex):
358-
code_length = 4 # number of hex chars consumed by one code
359-
size = len(_hex) / code_length # number of codes defined in THIS FRAME (not total)
360358
codes = []
361-
for n in range(size):
359+
for n in range(3):
362360

363-
start = code_length * n
364-
end = start + code_length
361+
start = 4 * n
362+
end = start + 4
365363

366364
codes.append(dtc(_hex[start:end]))
367365

obd/obd.py

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -167,20 +167,17 @@ def query(self, c, force=False):
167167
return self.send(c)
168168

169169

170-
'''
171170
def query_DTC(self):
172171
""" read all DTCs """
173172

174173
n = self.query(commands.STATUS).value['DTC Count'];
174+
n = n if (n < 128) else 0 # if this number is over 128, it's invalid
175175

176176
codes = [];
177177

178-
# poll until the number of commands received equals that returned from STATUS
179-
# or until this has looped 128 times (the max number of DTCs that STATUS reports)
180-
i = 0
181-
while (len(codes) < n) and (i < 128):
182-
codes += self.query(commands.GET_DTC).value
183-
i += 1
178+
while n > 0:
179+
current_codes = self.query(commands.GET_DTC).value
180+
codes += current_codes
181+
n -= len(current_codes)
184182

185183
return codes
186-
'''

0 commit comments

Comments
 (0)