Skip to content
Open
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
3 changes: 2 additions & 1 deletion can/io/canutils.py
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,8 @@ def on_message_received(self, msg: Message) -> None:
eol = " R\n" if msg.is_rx else " T\n"

if msg.is_remote_frame:
framestr += f"R{eol}"
remote_dlc = str(msg.dlc) if 0 < msg.dlc <= 8 else ""
framestr += f"R{remote_dlc}{eol}"
else:
if msg.is_fd:
fd_flags = 0
Expand Down
1 change: 1 addition & 0 deletions doc/changelog.d/+canutils-remote-dlc.fixed.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Preserve the requested data length when writing remote frames to candump log files.
1 change: 1 addition & 0 deletions doc/file_io.rst
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ Log (.log can-utils Logging format)
-----------------------------------

CanutilsLogWriter logs CAN data to an ASCII log file compatible with `can-utils <https://github.com/linux-can/can-utils>`_
and preserves the requested data length of classic CAN remote frames.
As specification following references can-utils can be used:
`asc2log <https://github.com/linux-can/can-utils/blob/master/asc2log.c>`_,
`log2asc <https://github.com/linux-can/can-utils/blob/master/log2asc.c>`_.
Expand Down
21 changes: 21 additions & 0 deletions test/logformats_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -998,6 +998,27 @@ def test_issue_1905(self):
class TestCanutilsFileFormat(ReaderWriterTest):
"""Tests can.CanutilsLogWriter and can.CanutilsLogReader"""

@parameterized.expand([(0, "123#R"), (5, "123#R5"), (8, "123#R8")])
def test_remote_frame_dlc(self, dlc, expected_frame):
with can.CanutilsLogWriter(self.test_file_name) as writer:
writer(
can.Message(
arbitration_id=0x123,
is_extended_id=False,
is_remote_frame=True,
dlc=dlc,
check=True,
)
)

self.assertEqual(
Path(self.test_file_name).read_text().split()[2], expected_frame
)
with can.CanutilsLogReader(self.test_file_name) as reader:
(message,) = reader
self.assertTrue(message.is_remote_frame)
self.assertEqual(message.dlc, dlc)

def _setup_instance(self):
super()._setup_instance_helper(
can.CanutilsLogWriter,
Expand Down
Loading