From 40db20bd491d99c466f60849d227e5276b3cd091 Mon Sep 17 00:00:00 2001 From: TIM ANDERSON Date: Wed, 18 Nov 2026 12:59:07 +1000 Subject: [PATCH] Preserve the requested length of remote frames in candump logs --- can/io/canutils.py | 3 ++- .../+canutils-remote-dlc.fixed.rst | 1 + doc/file_io.rst | 1 + test/logformats_test.py | 21 +++++++++++++++++++ 4 files changed, 25 insertions(+), 1 deletion(-) create mode 100644 doc/changelog.d/+canutils-remote-dlc.fixed.rst diff --git a/can/io/canutils.py b/can/io/canutils.py index 800125b73..734348e0d 100644 --- a/can/io/canutils.py +++ b/can/io/canutils.py @@ -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 diff --git a/doc/changelog.d/+canutils-remote-dlc.fixed.rst b/doc/changelog.d/+canutils-remote-dlc.fixed.rst new file mode 100644 index 000000000..081b8e6d5 --- /dev/null +++ b/doc/changelog.d/+canutils-remote-dlc.fixed.rst @@ -0,0 +1 @@ +Preserve the requested data length when writing remote frames to candump log files. diff --git a/doc/file_io.rst b/doc/file_io.rst index 329ccac53..9e39df06a 100644 --- a/doc/file_io.rst +++ b/doc/file_io.rst @@ -95,6 +95,7 @@ Log (.log can-utils Logging format) ----------------------------------- CanutilsLogWriter logs CAN data to an ASCII log file compatible with `can-utils `_ +and preserves the requested data length of classic CAN remote frames. As specification following references can-utils can be used: `asc2log `_, `log2asc `_. diff --git a/test/logformats_test.py b/test/logformats_test.py index beb5b7b9f..a4eb6ec01 100644 --- a/test/logformats_test.py +++ b/test/logformats_test.py @@ -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,