Skip to content

Commit 3ea8a57

Browse files
author
Brendan Whitfield
committed
retain the processing of CAN's DTC_Count handling
1 parent 3c66e89 commit 3ea8a57

2 files changed

Lines changed: 9 additions & 28 deletions

File tree

obd/decoders.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -388,7 +388,7 @@ def dtc(messages):
388388
codes = []
389389
d = []
390390
for message in messages:
391-
d += message.data
391+
d += message.data[2:] # remove the mode and DTC_count bytes
392392

393393
# look at data in pairs of bytes
394394
# looping through ENDING indices to avoid odd (invalid) code lengths

obd/protocols/protocol_can.py

Lines changed: 8 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -265,39 +265,20 @@ def parse_message(self, message):
265265
# chop to the correct size (as specified in the first frame)
266266
message.data = message.data[:ff[0].data_len]
267267

268-
"""
269-
# chop off the Mode/PID bytes based on the mode number
270-
mode = message.data[0]
271-
if mode == 0x43:
272268

269+
# trim DTC requests based on DTC count
270+
# this ISN'T in the decoder because the legacy protocols
271+
# don't provide a DTC_count bytes, and instead, insert a 0x00
272+
# for consistency
273+
274+
if message.data[0] == 0x43:
273275
# []
274276
# 43 03 11 11 22 22 33 33
275277
# [DTC] [DTC] [DTC]
276278

277-
# fetch the DTC count, and use it as a length code
278-
num_dtc_bytes = message.data[1] * 2
279-
280-
# skip the PID byte and the DTC count,
281-
message.data = message.data[2:][:num_dtc_bytes]
279+
num_dtc_bytes = message.data[1] * 2 # each DTC is 2 bytes
280+
message.data = message.data[:(num_dtc_bytes + 2)] # add 2 to account for mode/DTC_count bytes
282281

283-
elif mode == 0x46:
284-
# the monitor test mode only has a mode number
285-
# the MID (mode 6's version of a PID) is needed,
286-
# and handled in the decoder
287-
message.data = message.data[1:]
288-
289-
else:
290-
# skip the Mode and PID bytes
291-
#
292-
# single line response:
293-
# [ Data ]
294-
# 00 00 07 E8 06 41 00 BE 7F B8 13
295-
#
296-
# OR, the data from a multiline response:
297-
# [ Data ]
298-
# 49 04 01 35 36 30 32 38 39 34 39 41 43 00 00 00 00 00 00
299-
message.data = message.data[2:]
300-
"""
301282
return True
302283

303284

0 commit comments

Comments
 (0)