CodeRef
CodeRef
  • Software
    • VSCode
  • Midjourney_AI
    • Midjourney Cheat Sheet
  • aws
    • S3 Reference
    • Services
  • bash
    • .bashrc File Contents
    • CAN
    • _System Config File Locations
    • argument-length-limits
    • Conditionals
    • Data Structures
    • File Permissions
    • File Syncing
    • File System
    • Functions
    • General
    • Loops
    • My Functions
    • Networking
    • Number Operations
    • OpenVPN
    • Operators
    • Resource Management
    • Serial RS232
    • Spinning Wheel Animation
    • SSH
    • Text Operations
    • Environment Variables
  • cpp
    • ChatGPT | Pointers vs. References
    • arrays
    • Classes
    • Data Types / Structures
    • Enumerated Classes
    • Exception Handling
    • Function Objects
    • Functions
    • I/O
    • Loops
    • Macros
    • Namespaces
    • New Features
    • Pointers
    • Scope
    • Smart Pointers
    • Raw String Literals
    • Style Guide
    • Switch Case
    • Templating
    • How to Use tinyxml2
    • Useful Libraries
    • google-test
    • Conditionals
    • Rule of Three/Five
    • Optional Parameters
    • Keywords
    • Filesystem
    • Random
    • Casting
    • tools
  • git
    • Code Review Dependency Strategy
    • Git Bisect Guide
    • Git Reference
    • removing-cherry-picks
    • Useful Tools
    • Graphite Reference
  • js
    • functions
    • Javascript Reference
  • linux
    • Display
    • Dual Boot with Windows
    • File System
    • NVIDIA
    • Sending/Receiving TCP/UDP Messages in Ubuntu
    • dynamically_linked_binaries
  • markdown
    • Images
    • obsidian-reference
  • python
    • Classes
    • Exceptions
    • Functions
    • Operations
    • Python Reference
    • unittest_command-line-args
    • unittest_magicmock_GPT
    • unittest_mock
    • unittest_printing
    • unittest_subtest
    • useful-stuff
    • jupyter
    • poetry
  • ros
    • _ROS Cheat Sheet
    • Create New Workspace
    • Install ROS
    • Node Sample - Listener
    • Node Sample - Talker
    • Node Template
    • Setup
    • urdf
  • excel
    • excel-reference
  • windows
    • File System
    • WSL - Windows Subsystem for Linux
    • WSL
  • software_engineering
    • uncle_bob_lectures
      • Overview
      • Lesson 01 - Notes
  • web
    • Front End
    • Hugo
    • new_frontend_tools
  • sql
    • cheatsheet
Powered by GitBook
On this page
  1. bash

CAN

CAN message structure:

# CAN Frame:
XXXXXXX  AABBBBCC  [D]  EE FF GG HH II JJ KK LL

# Meaning:
XXXXXXX = Name of connected can bus
ID (hex) = Identifier

    AA = Priority
    BBBB = PGN (message family)
    CC = Source address

[D] (dec?) = Size of payload  
CAN 2.0 = 8 bytes  
CAN FD = variable number of bytes

PAYLOAD (hex) = Data transmitted
    EE = Data byte 1 = command byte / message identifier
    FF = Data byte 2
    GG = Data byte 3
    HH = Data byte 4
    II = Data byte 5
    JJ = Data byte 6
    KK = Data byte 7
    LL = Data byte 8

Reading left to right:
    Little Endian = bytes go from least significant to most significant (LSB to MSB)
    Big Endian = bytes go from most significant to least significant (MSB to LSB)

Whether to use little or big endian is the choice of the person defining the CAN message.

candump:

# CAN Dump
candump canport1
# CAN dump and search for string "[8] C1",
# Only report results containing it.
candump canport1 | grep "\[8\] C1"
# Candump with absolute timestamps in date format.
candump -tA canport1 | grep -i "FFFEB1"
# Candump pulling 1 data frame only.
candump -n 1 canport1
# Save candump output for 2 CAN buses to a log file.
candump canport1 canport2 > ./log.txt

candump filtering:

  • https://manpages.ubuntu.com/manpages/bionic/man1/candump.1.html

  • https://stackoverflow.com/questions/32870891/heavily-confused-by-candump-socketcan-id-filtering-feature

# Candump filtering:
candump -r 1 -n 1 brtcan2,18FFF4B1:0FFFFFF0
	# 18FFF4B1 is the ID, 0FFFFFF0 is the mask.
	# Both are hexadecimal.
	# They are ANDed together, so this returns all frames with ID matching _8FFF4B_.
	# -r 1 = sets buffer to 1 (not sure the effect of this, still testing).
candump -r 1 -n 1 brtcan2,18FFF4B1~0FFFFFF0
	# The "~" will return all frames NOT matching that ID+mask.

Last updated 1 year ago