Repository navigation
canutils: read the candump raw DLC suffix of Classical CAN frames - #2163
Conversation
candump -8 -L writes the raw DLC (9 to 15) of a Classical CAN frame with 8 data bytes as a suffix: 123#1122334455667788_C, 123#R8_F. CanutilsLogReader raised ValueError on such a line, which ended reading of the whole file, and CanutilsLogWriter dropped the raw DLC. Read the suffix into Message.dlc the way can-utils parse_canframe does (only a digit from 9 to F after exactly 8 bytes), as the SocketCAN interface already stores len8_dlc, and write it back in the same form.
A CAN FD record such as 123##0R8_C was read as a remote frame with DLC 12; can-utils rejects it. Correct the candump option in the news fragment and test comment: the suffix comes from candump -L and -l log output, not -8.
…s does can-utils reads one length digit from 0 to 8 after R and takes the raw DLC only after the length 8, so 123#R08_C is a remote frame with DLC 0.
Codex Review Summary: ❌ FailedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
|
You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard. |
AI Review: canutils raw DLC (#2163)The reader crash on Findings
Verdictrequest changes |
Message.dlc holds the payload length of a Classical CAN frame (0 to 8), and can-utils keeps the raw DLC in the separate len8_dlc field. The reader now drops the raw DLC digit after 8 data bytes or R8, and the writer is back to main's behaviour.
|
Thanks, all six points are in 09c89a5:
Against can-utils' |
Summary of Changes
CanutilsLogReaderraisesValueError: invalid literal for int() with base 16: '_C'on candump log lines such as123#1122334455667788_C. The exception stopspython -m can.logconvert, so the output omits that record and all later records. On remote lines,123#R8_Fraises too, andR8_0toR8_9read as DLC 80 to 89 becauseint("8_0")accepts the underscore as a digit separator.ISO 11898-1 lets a Classical CAN frame with 8 data bytes carry a raw DLC value of 9 to 15. Linux SocketCAN reports this value in
len8_dlc. When the interface reports one (the driver needsCAN_CTRLMODE_CC_LEN8_DLC),candump -Landcandump -lwrite that raw DLC as a_<hex digit>suffix after 8 data bytes orR8(can-utilslib.c,CC_DLC_DELIM '_', master834ceef).can-utilskeeps the payload length (8) inlenand the raw DLC in the separatelen8_dlcfield.This change makes
CanutilsLogReaderaccept the suffix and read such a frame withdlc=8, within the 0 to 8 range thatMessage.dlcis documented to hold for Classical CAN. The raw DLC digit is dropped:_right after 8 Classical CAN data bytes ends the data; the rest is ignored._, the reader takes the length ascan-utilsdoes: one digit from0to8, else 0.123#R8_Freads as DLC 8,123#R08_Cand123#R9_Cas DLC 0._after fewer than 8 data bytes (123#1122_C) and a suffix after 8 bytes of a CAN FD record (123##01122334455667788_C) still raise, as onmainand ascan-utilsrejects them.CanutilsLogWriteris unchanged.Running
python -m can.logconvert candump.log out.logshows the behavior before and after this change:Records without the suffix read as before.
Related Issues / Pull Requests
Type of Change
Checklist
tox).Additional Notes
parse_canframefromcan-utilslib.cwas compiled into a small program and fed 186 frame strings: standard and extended IDs, 0 to 8 data bytes, suffix digits0toFin upper and lower case, remote lines (R,R0toR8,R8_0toR8_F,R08_C,R9_C,R_C), CAN FD lines with flags 0 to 3, two error frames, trailing text after the digit, a_after fewer than 8 bytes and a suffixed CAN FD record. Comparing the identifier, the remote and extended flags and the DLC (can-utils'len) of each record,CanutilsLogReadernow matchescan-utilson all 180 lines thatcan-utilsaccepts; onmainit matched 72, raised on 88 and read the wrong DLC on 20. The 6 lines thatcan-utilsrejects raise onmainand after the change.test/logformats_test.pyaddstest_read_raw_dlc(123#1122334455667788_C,123#R8_F,123#R08_C,123#R9_C), which fails onmainwithValueError, andtest_read_raw_dlc_invalid(123#1122_C,123##0R8_C,123##01122334455667788_C), which passes onmainand after the change.toxwas not run. These checks ran individually on macOS with Python 3.12.12:black --check .andruff check can examples docpass,pylint can/ioscores 10.00/10,mypy --python-version 3.12 canreports no issues, andpytest test/logformats_test.pyreports 131 passed and 21 skipped.