Skip to content

Commit f038450

Browse files
authored
Interpret read DID response length dynamicaly
This is to support dynamic codec length on the case of a Read Data Identifier request that contains only one DID.
1 parent 6049a19 commit f038450

File tree

1 file changed

+12
-3
lines changed

1 file changed

+12
-3
lines changed

udsoncan/services/ReadDataByIdentifier.py

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -104,11 +104,20 @@ def interpret_response(cls, response, didlist, didconfig, tolerate_zero_padding=
104104
codec = DidCodec.from_config(didconfig[did])
105105
offset+=2
106106

107-
if len(response.data) < offset+len(codec):
107+
try:
108+
payload_size = len(codec)
109+
except NotImplementedError as nie:
110+
if len(didlist) > 1:
111+
raise nie
112+
else:
113+
# we assume the remaining response data corresponds to only one DID, thus read all of it
114+
payload_size = len(response.data) - offset
115+
116+
if len(response.data) < offset+payload_size:
108117
raise InvalidResponseException(response, "Value for data identifier 0x%04x was incomplete according to definition in configuration" % did)
109118

110-
subpayload = response.data[offset:offset+len(codec)]
111-
offset += len(codec) # Codec must define a __len__ function that matches the encoded payload length.
119+
subpayload = response.data[offset:offset+payload_size]
120+
offset += payload_size # Codec must define a __len__ function that matches the encoded payload length.
112121
val = codec.decode(subpayload)
113122
response.service_data.values[did] = val
114123

0 commit comments

Comments
 (0)