Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 27 additions & 3 deletions can/io/asc.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,14 @@ def __iter__(self):
temp = line.strip()
if not temp or not temp[0].isdigit():
continue
is_fd = False
try:
timestamp, channel, dummy = temp.split(
None, 2
) # , frameType, dlc, frameData
if channel == "CANFD":
timestamp, _, channel, _, dummy = temp.split(None, 4)
is_fd = True
except ValueError:
# we parsed an empty comment
continue
Expand Down Expand Up @@ -89,15 +93,32 @@ def __iter__(self):
)
yield msg
else:
brs = None
esi = None
data_length = 0
try:
# this only works if dlc > 0 and thus data is availabe
can_id_str, _, _, dlc, data = dummy.split(None, 4)
# this only works if dlc > 0 and thus data is available
if not is_fd:
can_id_str, _, _, dlc, data = dummy.split(None, 4)
else:
can_id_str, frame_name, brs, esi, dlc, data_length, data = dummy.split(
None, 6
)
if frame_name.isdigit():
# Empty frame_name
can_id_str, brs, esi, dlc, data_length, data = dummy.split(
None, 5
)
except ValueError:
# but if not, we only want to get the stuff up to the dlc
can_id_str, _, _, dlc = dummy.split(None, 3)
# and we set data to an empty sequence manually
data = ""
dlc = int(dlc)
dlc = int(dlc, 16)
if is_fd:
# For fd frames, dlc and data length might not be equal and
# data_length is the actual size of the data
dlc = int(data_length)
frame = bytearray()
data = data.split()
for byte in data[0:dlc]:
Expand All @@ -111,7 +132,10 @@ def __iter__(self):
is_remote_frame=False,
dlc=dlc,
data=frame,
is_fd=is_fd,
channel=channel,
bitrate_switch=is_fd and brs == "1",
error_state_indicator=is_fd and esi == "1",
)
self.stop()

Expand Down
2 changes: 1 addition & 1 deletion test/logformats_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -338,7 +338,7 @@ def _setup_instance(self):
super()._setup_instance_helper(
can.ASCWriter,
can.ASCReader,
check_fd=False,
check_fd=True,
check_comments=True,
preserves_channel=False,
adds_default_channel=0,
Expand Down