Skip to content

Fix ASCReader CANoe 7 CAN FD layouts - #2154

Merged
zariiii9003 merged 5 commits into
hardbyte:mainfrom
zhaojiale2021:canoe7-asc-fd
Nov 28, 2026
Merged

zariiii9003 merged 5 commits into
hardbyte:mainfrom
zhaojiale2021:canoe7-asc-fd

Conversation

@zhaojiale2021

Copy link
Copy Markdown
Contributor

Summary of Changes

  • Add native ASCReader support for CANoe 7.x CAN FD records whose field order is <channel> <id> <Rx|Tx>.
  • Resolve CANoe decimal DLC codes against the authoritative data-length field while preserving python-can hexadecimal DLC spellings.
  • Add a CANoe 7.0.0 regression fixture and a 32-byte CAN FD DLC regression; add a towncrier changelog fragment.

Related Issues / Pull Requests

  • Related to the existing CANoe ASC compatibility work.

Type of Change

  • Bug fix
  • New feature
  • Documentation update
  • Refactoring
  • Other (please describe)

Checklist

  • I have followed the contribution guide.
  • I have added or updated tests as appropriate.
  • I have added or updated documentation as appropriate.
  • I have added a news fragment for towncrier.
  • The targeted ASC test class passes: 37 passed, 1 skipped.

Additional Notes

This fix also removes the need for an application-level CANoe 7.x fallback in CanVouch.

zhaojiale2021 and others added 3 commits November 25, 2026 05:51
Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
@zariiii9003

Copy link
Copy Markdown
Collaborator

AI Review: ASCReader support for CANoe 7.x CAN FD layout (#2154)

Context

  • Vector "CAN, Log & Trigger ASC Logging Format" specifies CAN FD records "since v8.1" as <Channel> <Dir> <ID> … (§3.3). The older <Channel> <ID> <Dir> <BRS> <ESI> d|r <DLC> <DataLength> … order ("CANoe 7 layout") appears only in the §3.1.4 example log.
  • On main, every CANoe 7 layout line raises ValueError and stops reading. This PR fixes data frames, which is an improvement.

Findings

  • CANoe 7 layout remote frames crash the reader (can/io/asc.py, new fields[1] not in ("Rx", "Tx") block): the §3.1.4 line CANFD 1 100 Tx 1 0 r 8 Length = … raises ValueError and every later message is lost. Fix: on r, set is_remote_frame=True and dlc=dlc2len(<DLC>), and skip <DataLength>.
  • The result of _parse_fd_dlc is never used (can/io/asc.py): msg_kwargs["dlc"] = data_length overrides it. Fix: delete the method and its call, and drop the decimal-DLC claim from the changelog fragment.
  • Short CANoe 7 layout lines produce fake messages (if len(rest) < 4, if index + 1 >= len(rest)): CANFD 1 1e3 Rx 1 0 d comes out as an empty frame. Fix: raise ValueError, like the existing path.
  • The CANoe 7 layout error-frame check is untested (rest[0].lower() == "errorframe"): the specification doesn't document this form. Fix: remove it, or add a test with a real log line.
  • The changelog fragment name produces a broken link (doc/changelog.d/canoe7.fixed.rst): towncrier renders it as :issue:`canoe7` . Fix: rename it to 2154.fixed.rst, as doc/development.rst requires.

Tests

  • test_read_canoe_7_decimal_fd_dlc goes through the same path as test_read_canoe_7_can_fd_layout and passes without the DLC code. Fix: merge them into one test that reads a data frame and a remote frame.

Verdict

request changes

Handle remote and error frames, reject malformed short records, merge the CANoe regressions, and use the PR-number changelog filename.

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
@zariiii9003

Copy link
Copy Markdown
Collaborator

AI Review: ASCReader support for CAN FD records with the identifier before the direction (#2154)

Context

  • On main, any CANFD line in the order <Channel> <ID> <Dir> … raises ValueError and ends iteration. With this PR, the two data frames in the example log of Vector "CAN, Log & Trigger ASC Logging Format" (v1.4.16, §3.1.4) parse correctly, and the remote frame no longer ends reading. That is an improvement.
  • Earlier review: the unused _parse_fd_dlc, the short-line handling, the remote-frame crash, the merged test and the fragment name are fixed. The error-frame check is still not tested (see below).
  • Correction to the earlier review: its suggestion dlc=dlc2len(<DLC>) for remote frames was wrong, because dlc2len uses the CAN FD length table. The DLC handling requested below replaces it.

Findings

  • Regression: TxRq records stop the reader (can/io/asc.py, fields[1] not in ("Rx", "Tx")). §3.14 of the same specification lists <Dir> as Rx, Tx or TxRq. On main, CANFD 1 TxRq 1 0 0 1 1 01 parses. On this PR it enters the new branch and raises ValueError: invalid literal for int() with base 16: 'TxRq'.
  • Remote frames come out as CAN FD frames (marker == "r" branch). Every remote frame in this layout is returned with is_fd=True together with is_remote_frame=True, and with bitrate_switch=True when BRS is 1, as in the §3.1.4 example. ISO 11898-1:2015 §8.4.3 states "There shall be no LLC RF in FBFF or FEFF", and Message(check=True) rejects both combinations.
  • Remote-frame DLC codes 9–F are misread. A remote frame's DLC code may be 9–F (ISO 11898-1:2015 §8.4.2.4, §8.4.3; ASC §3.14 "Hex: 0…F"), which in classic CAN means 8 bytes. The PR parses the code as decimal and maps it through the CAN FD table, so r 9 gives dlc=12, and r a–r f raise ValueError, which ends reading of the file.
  • test_read_canoe_7_fd_error_frame does not test this change. Its line CANFD 5 Tx ErrorFrame … has Tx at position 1, so it takes the existing path. The test passes on main and still passes with the new errorframe check deleted. No specification version I checked documents an error frame in the identifier-first order, so remove both the check and the test.
  • The PR description is out of date. The bullet "Resolve CANoe decimal DLC codes against the authoritative data-length field…" describes code that was removed in 2660e0c. Please delete it.

Recommended changes

On top of 2660e0c. With these changes test/logformats_test.py passes, and reverting any single behavioural change turns test_read_canoe_7_can_fd_layout red.

--- a/can/io/asc.py
+++ b/can/io/asc.py
@@ def _process_fd_can_frame(self, line: str, msg_kwargs: dict[str, Any]) -> Message:
         fields = line.split()
-        if len(fields) >= 4 and fields[1] not in ("Rx", "Tx"):
+        if len(fields) >= 4 and fields[1] not in ("Rx", "Tx", "TxRq"):
@@
             rest = fields[3:]
-            if rest and rest[0].lower() == "errorframe":
-                msg_kwargs["is_error_frame"] = True
-                return Message(**msg_kwargs)
             if len(rest) < 3:
                 raise ValueError(f"Malformed CAN FD message: {line}")
@@
             if marker not in ("d", "r"):
                 raise ValueError(f"Malformed CAN FD message: {line}")
-            msg_kwargs["is_fd"] = True
-            msg_kwargs["bitrate_switch"] = brs == "1"
-            msg_kwargs["error_state_indicator"] = esi == "1"
-
             if marker == "r":
                 if len(rest) < 4:
                     raise ValueError(f"Malformed CAN FD remote frame: {line}")
-                dlc_code = int(rest[3], 10)
+                msg_kwargs["is_fd"] = False
                 msg_kwargs["is_remote_frame"] = True
-                msg_kwargs["dlc"] = dlc2len(dlc_code)
-                msg_kwargs["data"] = bytearray()
+                msg_kwargs["dlc"] = min(8, int(rest[3], self._converted_base))
                 return Message(**msg_kwargs)

+            msg_kwargs["bitrate_switch"] = brs == "1"
+            msg_kwargs["error_state_indicator"] = esi == "1"
+
             if len(rest) < 5:
--- a/test/logformats_test.py
+++ b/test/logformats_test.py
@@ def test_read_canoe_7_can_fd_layout(self):
             "0.001000 CANFD 1 1e3 Rx 1 0 d 13 32 " + " ".join(["00"] * 32) + "\n"
-            "0.002000 CANFD 1 100 Tx 1 0 r 8 Length = 1704000\n"
+            "0.002000 CANFD 1 100 Tx 1 0 r f Length = 1704000\n"
+            "0.003000 CANFD 1 TxRq 1 0 0 1 1 01\n"
         )
         with can.ASCReader(stream) as reader:
-            data, large, remote = reader
+            data, large, remote, txrq = reader
@@
-        self.assertTrue(remote.is_fd)
+        self.assertFalse(remote.is_fd)
+        self.assertFalse(remote.bitrate_switch)
         self.assertTrue(remote.is_remote_frame)
         self.assertEqual(remote.arbitration_id, 0x100)
         self.assertFalse(remote.is_rx)
         self.assertEqual(remote.dlc, 8)
         self.assertEqual(remote.data, b"")

+        self.assertEqual(txrq.arbitration_id, 0x1)
+        self.assertFalse(txrq.is_rx)
+
@@
-    def test_read_canoe_7_fd_error_frame(self):
-        stream = StringIO(
-            "base hex timestamps absolute\n"
-            "0.000000 CANFD 5 Tx ErrorFrame "
-            "Not Acknowledge error, dominant error flag\n"
-        )
-        with can.ASCReader(stream) as reader:
-            (actual,) = reader
-
-        self.assertTrue(actual.is_error_frame)
-        self.assertEqual(actual.channel, 4)
-

Verdict

request changes

Keep TxRq on the standard CAN FD layout path, parse CANoe 7 remote frames as classic remote frames, and constrain DLC 9-F to classic DLC 8.

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>

@zariiii9003 zariiii9003 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you

@zariiii9003
zariiii9003 merged commit d81b980 into hardbyte:main Nov 28, 2026
28 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants