Skip to content

Commit f1a012c

Browse files
jazi007Nadhmi JAZI
andauthored
[IO][ASC]: fix data length (#1246)
Co-authored-by: Nadhmi JAZI <[email protected]>
1 parent 20b3138 commit f1a012c

File tree

2 files changed

+18
-9
lines changed

2 files changed

+18
-9
lines changed

can/io/asc.py

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
import logging
1414

1515
from ..message import Message
16-
from ..util import channel2int
16+
from ..util import channel2int, len2dlc, dlc2len
1717
from .generic import FileIOMessageWriter, MessageReader
1818
from ..typechecking import StringPathLike
1919

@@ -194,11 +194,20 @@ def _process_fd_can_frame(self, line: str, msg_kwargs: Dict[str, Any]) -> Messag
194194
msg_kwargs["bitrate_switch"] = brs == "1"
195195
msg_kwargs["error_state_indicator"] = esi == "1"
196196
dlc = int(dlc_str, self._converted_base)
197-
msg_kwargs["dlc"] = dlc
198197
data_length = int(data_length_str)
199-
200-
# CAN remote Frame
201-
msg_kwargs["is_remote_frame"] = data_length == 0
198+
if data_length == 0:
199+
# CAN remote Frame
200+
msg_kwargs["is_remote_frame"] = True
201+
msg_kwargs["dlc"] = dlc
202+
else:
203+
if dlc2len(dlc) != data_length:
204+
logger.warning(
205+
"DLC vs Data Length mismatch %d[%d] != %d",
206+
dlc,
207+
dlc2len(dlc),
208+
data_length,
209+
)
210+
msg_kwargs["dlc"] = data_length
202211

203212
self._process_data_string(data, data_length, msg_kwargs)
204213

@@ -381,8 +390,8 @@ def on_message_received(self, msg: Message) -> None:
381390
symbolic_name="",
382391
brs=1 if msg.bitrate_switch else 0,
383392
esi=1 if msg.error_state_indicator else 0,
384-
dlc=msg.dlc,
385-
data_length=len(data),
393+
dlc=len2dlc(msg.dlc),
394+
data_length=len(msg.data),
386395
data=" ".join(data),
387396
message_duration=0,
388397
message_length=0,

test/logformats_test.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -520,7 +520,7 @@ def test_can_fd_message_64(self):
520520
arbitration_id=0x4EE,
521521
is_extended_id=False,
522522
channel=3,
523-
dlc=0xF,
523+
dlc=64,
524524
data=[0xA1, 2, 3, 4] + 59 * [0] + [0x64],
525525
is_fd=True,
526526
error_state_indicator=True,
@@ -529,7 +529,7 @@ def test_can_fd_message_64(self):
529529
timestamp=31.506898,
530530
arbitration_id=0x1C4D80A7,
531531
channel=3,
532-
dlc=0xF,
532+
dlc=64,
533533
data=[0xB1, 2, 3, 4] + 59 * [0] + [0x64],
534534
is_fd=True,
535535
bitrate_switch=True,

0 commit comments

Comments
 (0)