Last active
January 9, 2026 15:46
-
-
Save hovsep/68ef34c7811b2ed9d7eb8a57fd5b67c0 to your computer and use it in GitHub Desktop.
CAN frame structure
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // Frame represents a simplified CAN frame | |
| type Frame struct { | |
| // CAN identifier (11-bit standard ID) | |
| // Determines priority during arbitration: lower ID = higher priority | |
| Id uint32 | |
| // Data Length Code (DLC) | |
| // Indicates how many bytes of data are in the payload (0–8 for classic CAN, up to 64 for CAN FD) | |
| DLC uint8 | |
| // Payload data | |
| // Holds the actual message sent between nodes | |
| // ProtocolMaxDataBytes defines the max supported bytes (e.g., 8 for classic CAN) | |
| Data [ProtocolMaxDataBytes]byte | |
| // Fields below exist in this demo but are not stored within the frame struct: | |
| // SOF (Start of Frame) – marks the beginning of a frame | |
| // IFS – inter-frame spacing, ensures minimum gap between frames | |
| // EOF – end-of-frame marker | |
| // Fields exist in real CAN but are omitted in this demo: | |
| // RTR (Remote Transmission Request) – distinguishes data frames from remote frames | |
| // IDE (Identifier Extension) – indicates standard (11-bit) or extended (29-bit) ID | |
| // r0, r1 – reserved bits for future use / protocol compliance | |
| // CRC – cyclic redundancy check for error detection | |
| // ACK – acknowledgment bit, set by receivers if frame is valid | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment