Repository navigation
gocan, drivers: render frames, flags, and enums - #105
Conversation
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>
Codex Review SummaryThis 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. |
There was a problem hiding this comment.
💡 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".
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>
|
@codex review |
|
Codex Review: Didn't find any major issues. Can't wait for the next one! Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
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". |
Logging a frame meant formatting its fields by hand,
%vof aFramedumped the whole 64-byte data array, and printing a discovered channel produced{pcan PCAN_USBBUS1 0x51 true false false}.This adds
StringtoFrame,FrameFlags,Direction,EventKind,ControllerStateanddrivers.Channel.Frame.Stringrenders the frame field of acandump -Lline, which candump, cantraceviewer and python-can'sCanutilsLogReaderread:123#1122001ABCDE#AA123#R4, or123#Rfor DLC 0, or123#R8_9for DLC 9-15123##1AABB, flag digit carrying BRS (1) and ESI (2)123#0102030405060708_9A frame that does not
Validaterenders 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 asType(n).Channelrenders its driver, name and identifier (pcan PCAN_USBBUS1 (pcan:0x51)); its fields are all unexported, so nothing is lost.FrameEvent,Eventanddbc.Signaldeliberately have noString. In Go,%vand%+vuse aStringmethod 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:In Go,
%xalso goes throughString.Frame.Validateandisotp.Newformatted unknownFrameFlagsbits with%#x, which would now hex-encode the rendered name; both now convert touint8first, so their messages are unchanged. A few test messages switch from%xto%vfor readable flags.Verification:
string_test.gopins 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'sCanutilsLogReader. python-can rejects the classical DLC 9-15 lines because it cannot representlen8_dlc, but that is the form can-utils writes. Enum and channel labels are not pinned.🤖 Generated with Claude Code