Repository navigation
canutils: read candump error frames of every class as error frames - #2146
Conversation
candump writes an error frame as CAN_ERR_FLAG plus the error class bits, followed by the error data bytes. The reader only recognised the bus error class, so a controller problem (20000004#...) or bus off frame was read as an extended data frame, and a bus error frame lost its channel, direction and data bytes. Test CAN_ERR_FLAG alone and keep the class bits in arbitration_id, as the SocketCAN interface does, together with the data bytes, channel and direction. The writer now writes the message's error class instead of always writing the bus error class, so an error frame round-trips.
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:On Regression in the writerProblem: an error frame whose Fix: if no error-class bits are set, write error_class = msg.arbitration_id & 0x1FFFFFFF
if not error_class:
# no SocketCAN error-class bits: write CAN_ERR_BUSERROR (0x080),
# so older readers still recognise the line as an error frame
error_class = CAN_ERR_BUSERROR
framestr += f" {CAN_ERR_FLAG | error_class:08X}#"Also
|
Older python-can readers recognise a candump error frame only by CAN_ERR_BUSERROR, so an error frame without class bits (as read from ASC or BLF) keeps the bus error class on write. The shared error frame round trip no longer holds for such frames; dedicated tests cover it. Rename the news fragment to the PR number.
|
I applied your writer fix in The previous head ( I added With the fix, the shared round-trip fixtures' On |
zariiii9003
left a comment
There was a problem hiding this comment.
Thank you. Although this highlights a problem: some parts of python-can use arbitration_id to communicate error types while it was never a documented part of the API. So these changes might cause issues with non-linux interfaces.
Summary of Changes
CanutilsLogReadertreats acandump -Lline as an error frame only when bothCAN_ERR_FLAG(0x20000000) andCAN_ERR_BUSERROR(0x80) are set. An error frame whose class bits lackCAN_ERR_BUSERROR, such as a controller problem (0x04) or bus off (0x40), is read as an extended data frame.can.logconvertwrites a controller-problem frame (0x04) as an ASC data frame instead ofErrorFrame.can.playerwithout--error-framestransmits that frame onto the bus as a data frame. For bus error frames,CanutilsLogReaderdropschannel, direction,dlc, and the 8 data bytes.CanutilsLogWriteralso ignoresarbitration_idon error frames and always writes the bus error class.In
can/io/canutils.py,CanutilsLogReadernow setsis_error_frame=bool(can_id & CAN_ERR_FLAG), which is howcan/interfaces/socketcan/socketcan.pyand can-utils'log2ascrecognise an error frame. The reader builds oneMessagefor every frame line. Error frames keep the low 29 bits of the candump ID inarbitration_id(for the defined error classes this matches the SocketCAN interface), along with the data bytes,dlc,channeland direction.CanutilsLogWriterencodes error frames that have SocketCAN error class bits asCAN_ERR_FLAG | (msg.arbitration_id & 0x1FFFFFFF). Whenarbitration_id & 0x1FFFFFFFis0, as forcan.Message(is_error_frame=True), ASCErrorFramelines and BLF error frames without an ID, it writesCAN_ERR_BUSERROR, so the line is20000080#as onmain. Writing20000080#avoids20000000#, which releasedpython-canversions (2.0.0 to 4.6.1) read as a data frame with ID0.Input (
err.log):Before (
main):After:
TestCanutilsFileFormatintest/logformats_test.pynow includestest_read_error_frames,test_write_error_frame_class, andtest_write_error_frame_without_class.test_read_error_framesverifies thatCanutilsLogReaderpreserves class, data, and channel on candump error lines.test_write_error_frame_classverifies that an error frame with class0x204writes as20000204#0004000000000102and reads back equal.test_write_error_frame_without_classverifies thatMessage(timestamp=1.0, is_error_frame=True, channel="can0")writes(1.000000) can0 20000080#and reads back as an error frame witharbitration_id0x080. The first two tests fail onmainand pass after the change.test_write_error_frame_without_classfails on the previous PR head4c172a7, which writes20000000#, and passes on0a360c5.TestCanutilsFileFormatnow passescheck_error_frames=Falseto the shared reader/writer round-trip helper, asTestTrcFileFormatBasealready does. The shared fixtures includeMessage(is_error_frame=True)witharbitration_id0, which now reads back witharbitration_idequal toCAN_ERR_BUSERROR, so the generic round trip cannot hold for it. Dedicated canutils tests cover error frames instead.Additional checks:
CAN_ERR_FLAG, empty-data bus errors, andR/Tsuffixes) fail onmainand pass after the change.0x00000080) read identically onmainand after the change..logto.logwithcan.logconvert, comes back line for line apart from the writer'sRdirection suffix. Onmainits two bus error frames come back asvcan0 20000080#, without channel or data bytes. Its ASC conversion is the same onmainand after the change, apart from the generated date header.test/data/logfile.asc,logfile_errorframes.asc, andtest_CanErrorFrames.asc, 11 error frames in total, all witharbitration_id0) to candump format and reading the output withmain's reader recognises 11 of 11 as error frames on0a360c5(0 of 11 on4c172a7).Related Issues / Pull Requests
main)Type of Change
Checklist
tox).Additional Notes
Compatibility:
20000080#, as onmain, and reads back witharbitration_id0x080(onmainit reads back witharbitration_id0). An error frame whose class bits lackCAN_ERR_BUSERROR(for example20000204#) is still read as a data frame by releasedpython-canversions, asmainalready does for candump's own error frames of those classes.arbitration_id, andCanutilsLogWriterwrites its low 29 bits afterCAN_ERR_FLAGas the error class when non-zero (andCAN_ERR_BUSERRORwhen0).python-canreleases now reads back witharbitration_idequal toCAN_ERR_BUSERROR.Local checks (
0a360c5, macOS):pytest test/logformats_test.py(Python 3.12 venv, withoutasammdf): 86 passed, 18 skipped.tox -e type: passed.tox -e lint:blackandruffpassed;pylintreports only the fiveselectno-member messages (epoll,EPOLLIN,EPOLLOUT) incan/interfaces/socketcan/socketcan.py, identical onmainon macOS.tox -e py: 536 passed, 117 skipped, 6 failed; the 6 are theBasicTestUdpMulticastBusIPv4tests intest/back2back_test.py, which also fail onmainon macOS.