Enhanced command-line utilities for CAN communication, built on the cansocket library. These tools provide modern replacements for the traditional canutils with advanced features and backward compatibility.
- cansend: Enhanced CAN frame sender with batch operations, templates, and advanced timing control
- candump: Enhanced CAN frame monitor with sophisticated filtering and multiple output formats
Tools are built automatically with the main project:
# Build all tools
cmake --build build
# Build specific tool
cmake --build build --target cansend
cmake --build build --target candump
# Disable tools build
cmake -DBUILD_TOOLS=OFF ..# Install tools to system PATH
sudo cmake --install build --component tools
# Manual installation
sudo cp build/tools/cansend/cansend /usr/local/bin/
sudo cp build/tools/candump/candump /usr/local/bin/Modern replacement for canutils' cansend with advanced features for production use.
# Send single frame (compatible with canutils)
cansend can0 123#DEADBEEF
# Send extended frame
cansend can0 12345678#1122334455667788
# Send RTR frame
cansend can0 123#R8
# Send CAN FD frame
cansend can0 123##1122334455667788# Send frame 10 times
cansend can0 123#1122 --repeat 10
# Send with 100ms interval between frames
cansend can0 123#1122 --repeat 5 --interval 100
# Send continuously (Ctrl+C to stop)
cansend can0 123#1122 --continuous --interval 50
# Per-frame timeout control
cansend can0 123#1122 --timeout 200# Send frames from file
cansend can0 --batch frames.txt
# Send frames from config file
cansend can0 --config config.conf
# Dry run (validate without sending)
cansend can0 123#1122 --dry-run# Limit to 100 frames per second
cansend can0 123#1122 --continuous --rate 100
# Verbose output with timing
cansend can0 123#1122 --repeat 10 --verbose
# Use different threading models
cansend can0 123#1122 --threading shared
cansend can0 123#1122 --threading per-thread
cansend can0 123#1122 --threading lock-free# Generate common templates
cansend --generate-templates
# List available templates
cansend --list-templates
# Save frame as template
cansend --save-template heartbeat "System heartbeat" 123#0102030405060708
# Use saved template
cansend can0 --template heartbeat
# Show template details
cansend --show-template heartbeat
# Interactive template builder
cansend --interactive
# Import/export templates
cansend --import-templates batch.txt
cansend --export-templates my_templates.txt# Comments start with #
123#DEADBEEF
456#1122334455667788
789#R8
# Empty lines are ignored
# Configuration file format
frame=123#DEADBEEF
frame=456#1122334455667788
frame=789#R8
# CAN Send Templates
# Format: name=description:frame_string
heartbeat=System heartbeat:123#0102030405060708
diagnostic=Diagnostic request:7DF#0201050000000000
| Option | Description | Example |
|---|---|---|
--repeat N |
Send frame N times | --repeat 10 |
--interval MS |
Milliseconds between frames | --interval 100 |
--timeout MS |
Timeout per frame | --timeout 200 |
--continuous |
Send until interrupted | --continuous |
--verbose |
Show detailed output | --verbose |
--dry-run |
Validate without sending | --dry-run |
--rate N |
Max frames per second | --rate 100 |
--threading MODEL |
Threading model | --threading shared |
--batch FILE |
Send from batch file | --batch frames.txt |
--config FILE |
Send from config file | --config config.conf |
--template NAME |
Use saved template | --template heartbeat |
| Model | Description | Use Case |
|---|---|---|
none |
Standard single-threaded | Default, simple usage |
shared |
Shared mutex policy | Multi-threaded readers |
per-thread |
Per-thread sockets | High-performance parallel |
lock-free |
Lock-free queues | Ultra-high frequency |
# Send heartbeat every second
cansend can0 100#01020304 --continuous --interval 1000# Send diagnostic frames with timing
cansend can0 7DF#0201050000000000 --repeat 3 --interval 50 --verbose# High-frequency testing
cansend can0 123#DEADBEEF --continuous --rate 1000 --threading lock-free# Create and use templates
cansend --save-template test_msg "Test message" 123#AABBCCDD
cansend can0 --template test_msg --repeat 5Modern replacement for canutils' candump with advanced filtering and analysis capabilities.
# Monitor all frames (compatible with canutils)
candump can0
# Monitor multiple interfaces
candump can0 can1 vcan0
# Monitor with timestamps
candump can0 --timestamp absolute
# Monitor with colors
candump can0 --color# Filter by ID range
candump can0 --id-range 0x100-0x200
# Include specific IDs
candump can0 --include-ids 0x123,0x456,0x789
# Exclude specific IDs
candump can0 --exclude-ids 0x400-0x4FF
# Traditional canutils style
candump can0,123:7FF,400:700# Filter by data pattern (wildcards with ??)
candump can0 --data-pattern "11 22 ?? 44"
# Filter by data range
candump can0 --data-range 0x00-0xFF
# Regex data matching
candump can0 --data-regex "AB.*CD"
# Only frames with changing data
candump can0 --only-changes# Only standard frames
candump can0 --only-standard
# Only extended frames
candump can0 --only-extended
# Only RTR frames
candump can0 --only-rtr
# Only error frames
candump can0 --only-error
# Only CAN FD frames
candump can0 --only-canfd# Limit to 10 frames per second per ID
candump can0 --max-rate 10
# Sample every 10th frame
candump can0 --sample-rate 10
# Time window filtering
candump can0 --time-window 9:00-17:00# Human-readable format
candump can0 --format pretty
# With ASCII data representation
candump can0 --ascii
# With interface names
candump can0 --show-interface# JSON output
candump can0 --format json
# Pretty JSON with timestamps
candump can0 --format json --timestamp absolute --pretty# CSV output for analysis
candump can0 --format csv
# Custom CSV fields
candump can0 --format csv --fields timestamp,id,data,dlc# Binary output for high-speed logging
candump can0 --format binary --log can_dump.bin# Log to file
candump can0 --log can_traffic.log
# Log with rotation (100MB files)
candump can0 --log can_traffic.log --rotate-size 100
# Compressed logging
candump can0 --log can_traffic.log.gz --compress# Show live statistics
candump can0 --stats
# Show bandwidth monitoring
candump can0 --bandwidth
# Show ID histogram
candump can0 --histogram# Pause/resume with signals
candump can0 --interactive
# Stop after N frames
candump can0 --count 1000
# Stop after timeout
candump can0 --exit-after 60s| Option | Description | Example |
|---|---|---|
--timestamp TYPE |
Timestamp format | --timestamp absolute |
--color |
Colorized output | --color |
--format FORMAT |
Output format | --format json |
--ascii |
Show ASCII data | --ascii |
--verbose |
Verbose output | --verbose |
| Option | Description | Example |
|---|---|---|
--id-range RANGE |
ID range filter | --id-range 0x100-0x200 |
--include-ids IDS |
Include ID list | --include-ids 0x123,0x456 |
--exclude-ids IDS |
Exclude ID list | --exclude-ids 0x400-0x4FF |
--data-pattern PATTERN |
Data pattern | --data-pattern "11 22 ?? 44" |
--data-regex REGEX |
Data regex | --data-regex "AB.*CD" |
--only-changes |
Changed data only | --only-changes |
--max-rate N |
Max rate per ID | --max-rate 10 |
| Option | Description | Example |
|---|---|---|
--log FILE |
Log to file | --log traffic.log |
--rotate-size MB |
Log rotation size | --rotate-size 100 |
--compress |
Compress logs | --compress |
--stats |
Show statistics | --stats |
--bandwidth |
Show bandwidth | --bandwidth |
--count N |
Stop after N frames | --count 1000 |
# Monitor with timestamps and colors
candump can0 --timestamp absolute --color --ascii# Monitor only diagnostic frames
candump can0 --id-range 0x7E0-0x7EF --only-changes --format json# Monitor high-traffic bus with rate limiting
candump can0 --max-rate 50 --stats --histogram# Monitor only error frames and changes
candump can0 --only-error --only-changes --verbose --log errors.log# Monitor with binary logging for performance
candump can0 --format binary --log perf_test.bin --stats# 24/7 monitoring with log rotation
candump can0 --log production.log --rotate-size 100 --compress --stats#!/bin/bash
# Monitor specific IDs and alert on changes
candump can0 --include-ids 0x123,0x456 --only-changes --format json | \
jq -r '.id + ": " + .data' | \
while read line; do
echo "$(date): $line" >> alerts.log
doneimport subprocess
import json
# Monitor CAN traffic in Python
proc = subprocess.Popen(
['candump', 'can0', '--format', 'json', '--include-ids', '0x123'],
stdout=subprocess.PIPE,
text=True
)
for line in proc.stdout:
frame = json.loads(line)
print(f"ID: {frame['id']}, Data: {frame['data']}")# Export to CSV for analysis
candump can0 --format csv --count 10000 --log analysis.csv
# Import into analysis tools
python -c "
import pandas as pd
df = pd.read_csv('analysis.csv')
print(df.describe())
"# Use binary format for high-speed logging
candump can0 --format binary --log high_speed.bin
# Use rate limiting to prevent overload
candump can0 --max-rate 1000 --threading lock-free# Monitor memory usage for long-running captures
candump can0 --stats --log-memory-usage# Use efficient filtering to reduce CPU load
candump can0 --include-ids 0x100-0x200 --sample-rate 10# Check interface status
ip link show can0
# Verify permissions
ls -l /dev/can*
# Test with loopback
candump can0 --loopback# Enable debug output
candump can0 --debug --verbose
# Show filter statistics
candump can0 --show-filter-stats# Old canutils syntax (still works)
cansend can0 123#DEADBEEF
# New enhanced syntax
cansend can0 123#DEADBEEF --repeat 10 --verbose# Old canutils syntax (still works)
candump can0
# New enhanced syntax
candump can0 --format json --only-changes| canutils | Enhanced Tools | Notes |
|---|---|---|
cansend can0 123#11 |
cansend can0 123#11 |
Backward compatible |
candump can0 |
candump can0 |
Backward compatible |
candump -t a can0 |
candump can0 --timestamp absolute |
New syntax |
candump -c can0 |
candump can0 --color |
New syntax |
candump -l can0 |
candump can0 --log can0.log |
Enhanced logging |
- Fork the repository
- Create a feature branch
- Add tests for new functionality
- Submit a pull request
See the main README.md for general contributing guidelines.
These tools are part of the cansocket project and are licensed under the Apache 2.0 License.