8000 gocan, drivers: render frames, flags, and enums by tomrford · Pull Request #105 · tomrford/gocan · GitHub
[go: up one dir, main page]

Skip to content

gocan, drivers: render frames, flags, and enums - #105

Merged
tomrford merged 4 commits into
mainfrom
core-string-methods
Oct 19, 2026
Merged

tomrford merged 4 commits into
mainfrom
core-string-methods

Conversation

@tomrford
@tomrford tomrford commented Oct 19, 2026 •
Copy link
Copy Markdown
Owner

Logging a frame meant formatting its fields by hand, %v of a Frame dumped the whole 64-byte data array, and printing a discovered channel produced {pcan PCAN_USBBUS1 0x51 true false false}.

This adds String to Frame, FrameFlags, Direction, EventKind, ControllerState and drivers.Channel.

Frame.String renders the frame field of a candump -L line, which candump, cantraceviewer and python-can's CanutilsLogReader read:

Frame Rendering
standard data 123#1122
extended data 001ABCDE#AA
remote 123#R4, or 123#R for DLC 0, or 123#R8_9 for DLC 9-15
CAN FD 123##1AABB, flag digit carrying BRS (1) and ESI (2)
classical DLC 9-15 123#0102030405060708_9

A frame that does not Validate renders as a diagnostic struct ending in (invalid), so it is never mistaken for a trace record. Each enum renders its name, and an undefined value renders as Type(n). Channel renders its driver, name and identifier (pcan PCAN_USBBUS1 (pcan:0x51)); its fields are all unexported, so nothing is lost.

FrameEvent, Event and dbc.Signal deliberately have no String. In Go, %v and %+v use a String method when one exists, so one on these structs would hide their fields. With the Stringers above, their default printing already reads well and keeps every field:

{Bus:1 Timestamp:… Direction:receive Frame:123##11122}
{Bus:1 Timestamp:… Kind:controller state ControllerState:bus off TXErrorCount:12 RXErrorCount:3 ErrorCountsKnown:true}

In Go, %x also goes through String. Frame.Validate and isotp.New formatted unknown FrameFlags bits with %#x, which would now hex-encode the rendered name; both now convert to uint8 first, so their messages are unchanged. A few test messages switch from %x to %v for readable flags.

Verification: string_test.go pins all sixteen frame renderings (the format contract) and the diagnostic form for five invalid frames. The thirteen representable data and remote lines were round-tripped through python-can 4.6.1's CanutilsLogReader. python-can rejects the classical DLC 9-15 lines because it cannot represent len8_dlc, but that is the form can-utils writes. Enum and channel labels are not pinned.

🤖 Generated with Claude Code

tomrford and others added 2 commits October 19, 2026 16:48
Frames, events, and channel capabilities had no String method, so logging a
frame meant formatting its fields by hand and printing a channel produced a
struct dump.

Frame.String renders the can-utils log form that candump -L writes and
candump, cantraceviewer, and python-can's CanutilsLogWriter read: three
hexadecimal digits for a standard identifier and eight for an extended one,
uppercase payload, R with the requested data length code for a remote frame, a
flag digit for CAN FD bit-rate switching and the error state indicator, and the
underscore-suffixed data length code for a classical frame above DLC 8. A frame
that does not Validate renders as a diagnostic struct instead, so an invalid
frame is never mistaken for a trace record. FrameEvent and Event add their bus
and direction, and the event kind and controller state or error counts.

Direction, FrameFlags, EventKind, and ControllerState render their own names,
matching the wording the asc writer already uses for controller states, and
drivers.Channel adds its driver, native name, and identifier.

Amp-Thread-ID: https://ampcode.com/threads/T-01a15485-21ac-76eb-a8a3-dbbf21de0692
Co-authored-by: Amp <amp@ampcode.com>
Struct printing already reads well once Frame and the enums have Stringers,
and a String on FrameEvent or Event would hide their fields from %+v.
Formatting FrameFlags with %x now goes through String, so the two error
messages that did so convert to the raw bits first.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@tomrford tomrford changed the title gocan, drivers: render the log vocabulary gocan, drivers: render frames, flags, and enums Oct 19, 2026
@tomrford
tomrford marked this pull request as ready for review October 19, 2026 15:29
@chatgpt-codex-connector
chatgpt-codex-connector Bot commented Oct 19, 2026 •
Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-19T19:29:15.937486Z 78eac76 Manual request
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 33a9455172

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread frame.go Resolved
can-utils reads the digit after R only up to 8 and takes a raw DLC above 8
from an "_<dlc>" suffix after R8, so 123#R9 loses the DLC.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@tomrford
Copy link
Copy Markdown
Owner Author

@codex review

@chatgpt-codex-connector
Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Can't wait for the next one!

Reviewed commit: 78eac76b5b

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@tomrford
tomrford merged commit f13d717 into main Oct 19, 2026
1 check passed
@tomrford
tomrford deleted the core-string-methods branch October 19, 2026 19:55
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.

1 participant

0