A Python-based tool for decoding and analyzing CAN bus data from automotive networks using DBC (Database CAN) files.
This project provides a complete toolchain for automotive CAN bus analysis:
- Load DBC database files - Parse message and signal definitions
- Read CAN log files - Support for Vector ASC format
- Decode CAN frames - Convert raw bytes to physical values
- Store and analyze signals - Organize time-series data
- Export to CSV - Long and wide format support
- Visualize signals - Publication-quality plots
CAN (Controller Area Network) is a robust vehicle bus standard designed for automotive applications.
- Multi-master protocol: Any ECU can transmit
- Message-based: Data organized in frames with IDs
- Real-time: Deterministic message prioritization
- Robust: Built-in error detection and fault confinement
- Efficient: Up to 1 Mbps on standard CAN
┌─────────────┬──────────┬─────┬──────────────┬─────┬───────┐
│ Arbitration │ Control │ RTR │ Data │ CRC │ ACK │
│ ID │ Field │ │ (0-8 bytes)│ │ │
└─────────────┴──────────┴─────┴──────────────┴─────┴───────┘
11 or 29 bits 6 bits 1 bit 0-64 bits 16 bits 2 bits
DBC (Database CAN) files define the structure of CAN messages in a human-readable format.
- Define message IDs and their names
- Specify signal positions within messages
- Provide scaling formulas (factor, offset)
- Document units (RPM, km/h, °C)
- Include value tables (enumerations)
SG_ RPM : 0|16@1+ (0.25,0) [0|8000] "RPM" Gateway
│ │ │ │ │ │ │ │ │ │
│ │ │ │ │ │ │ │ │ └─ Receiver
│ │ │ │ │ │ │ │ └───────── Unit
│ │ │ │ │ │ │ └─────────────── Max value
│ │ │ │ │ │ └─────────────────── Min value
│ │ │ │ │ └──────────────────────── Offset
│ │ │ │ └──────────────────────────── Factor (scale)
│ │ │ └──────────────────────────────── Value type (+ = unsigned)
│ │ └─────────────────────────────────── Byte order (1 = big-endian)
│ └────────────────────────────────────── Length (bits)
└──────────────────────────────────────────── Start bit position
- DBC Parser: Load and validate CAN database files
- ASC Log Reader: Parse Vector ASCII log format
- Frame Decoder: Convert raw CAN data to physical values
- Signal Store: Organize time-series data by signal name
- CSV Export: Long format (database) and wide format (plotting)
- Visualization: Multiple plot types with matplotlib
- Filtering: By time range, CAN IDs, or signal names
- Statistics: Min, max, mean, count for each signal
- Professional Plots: Publication-ready visualizations
- Error Handling: Graceful handling of malformed data
- Logging: Configurable verbose mode for debugging
- CLI Interface: Comprehensive command-line tool
- Python 3.10 or higher
- pip (Python package manager)
- git (optional, for cloning)
# Clone repository
git clone https://github.com/Hansajith98/can-dbc-analyzer.git
cd can-dbc-analyzer
# Create virtual environment
python3 -m venv venv
# Activate virtual environment
# On Linux/Mac:
source venv/bin/activate
# On Windows:
venv\Scripts\activatepip install -r requirements.txtDecode all signals from a CAN log:
python src/main.py --dbc dbc/example_vehicle.dbc --log logs/drive_log.ascThis will:
- Load the DBC database
- Read the CAN log file
- Decode all frames
- Export to
output/decoded_signals.csv - Generate plots in
output/plots/
# View CSV in terminal
cat output/decoded_signals.csv | head -20
# Open plots (on Linux)
xdg-open output/plots/
# Open plots (on Mac)
open output/plots/
# Open plots (on Windows)
start output/plots/- Filename:
<signal_name>.png - Content: Time-series of one signal
- Example:
rpm.pngshows RPM over time
- Filename:
combined_signals.png - Content: Multiple signals on same axes (dual y-axis if different units)
- Example: Speed and RPM together
- Filename:
subplots.png - Content: Stacked subplots, one per signal
- Example: RPM, Speed, Temperature stacked vertically
- Filename:
overview_dashboard.png - Content: Comprehensive 3-panel view
- Panels: Speed/RPM, Temp/Load, Gear
- Message-based communication
- Arbitration and priorities
- Frame structure (standard vs extended)
- Error detection (CRC, ACK)
- Message definitions
- Signal encoding (start bit, length, byte order)
- Scaling and physical units
- Value tables and enumerations
- Modular design
- Type hints and dataclasses
- Error handling
- Logging and debugging
- Command-line interfaces
- Time-series processing
- Statistical summaries
- CSV export formats
- Data visualization
Deshitha Hansajith
January 2026