Cython-accelerated BLF file reading/writing and signal query library.
Project description
cfastblf
Cython-accelerated BLF file reading/writing and signal query library.
Project Introduction
cfastblf is a high-performance BLF (Binary Logging Format) file reading/writing library written in Cython, specifically designed for processing automotive bus data. By compiling critical performance paths into native code using Cython, it provides faster file parsing and processing speed compared to python-can.
This library supports reading, filtering, signal decoding, and exporting of CAN/CAN FD messages, offering both low-level direct access and high-level query usage patterns, suitable for automotive data analysis and test validation scenarios.
Features
- High-performance parsing: Core logic compiled with Cython, significantly improving BLF file parsing speed
- NumPy integration: Uses NumPy structured arrays as memory data structures for high-speed data analysis and processing
- Memory efficient: Optimized index-data block storage structure effectively reduces memory usage, supports loading hundreds of millions of frame data at once
- Complete protocol support: Supports multiple message types including CAN, CAN FD, error frames, etc.
- Flexible signal decoding: Supports high-speed signal extraction and conversion based on DBC files
- Advanced query functionality: Provides expression-based message filtering and signal mapping
- Platform compatibility: Free version supports Windows, contact author for other system versions
Installation
pip install cfastblf
Usage
from cfastblf import read, write, signal_decoder, Query
with open(r'myblf.blf', 'rb') as blf: # Note: use binary read mode
# Read all CAN/CANFD frames from BLF file, returns a tuple
# The tuple contains: index array (numpy structured array) and compact data block (numpy byte array)
# The dtype structure of index structured array: np.dtype([('timestamp', 'i8'), ('can_id', 'u4'), ('is64', 'u1'), ('channel', 'u1'), ('len', 'u1'), ('flags', 'u1'), ('loc', 'u8')])
# Where:
# * timestamp: timestamp in nanoseconds
# * len: message payload length (bytes)
# * flags: flag bits, from high to low: reserved, is_extended_id, is_remote_frame, is_error_frame, is_fd, is_rx, bitrate_switch, error_state_indicator
# * loc: offset in data block (bytes)
frames = read(blf)
# Low-level usage: directly read message frames
index, chunk = frames # Destructure tuple, chunk can be reused by frame subsets
msg = index[5] # The 5th CAN message (frame)
can_id = msg['can_id'] # Read CAN ID
payload = chunk[msg['loc']:msg['loc'] + msg['len']] # Get message payload
# Low-level usage: filter frames with specific CAN_ID
sub = frames[0][frames[0]['can_id'] == 0x150] # Pure numpy computation
# High-level usage: using query
from cantools import database as db
dbc = db.load_file(r'mybus.dbc', encoding='gbk') # Load DBC file
qry = Query() # Create query
qry.addDatabase(dbc) # Add signal database
# Filter frames with CAN ID 0x150, note: must use 'frames' in query string to represent actual frame array
sub = qry.filter(frames, "frames['can_id'] == 0x150") # Note: sub is still a tuple
# Decode ECU_150_CheckSum signal from all frames in subset sub
sig = qry.map(sub, 'signals.ECU_150_CheckSum(frames)') # Returns float array
# Save frame subset as BLF file
with open('output.blf', 'wb') as f: # Must use binary write mode
write(f, sub)
Free Version Limitations
This module is freeware, not open source software. Free version has the following limitations:
- Only provides binary installation packages for Windows systems.
- Only supports processing up to 2M CAN/CANFD frames, data exceeding this limit will be truncated.
Contact Author
Email: rockswang@foxmail.com GitHub: https://github.com/rockswang/cfastblf
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distributions
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file cfastblf-0.1.2-cp38-cp38-win_amd64.whl.
File metadata
- Download URL: cfastblf-0.1.2-cp38-cp38-win_amd64.whl
- Upload date:
- Size: 208.7 kB
- Tags: CPython 3.8, Windows x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.8.10
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
6864f802e5d72557f953b389798372700d03d1a4a07ca7fbe5ba0d02f710e432
|
|
| MD5 |
984b3e410df5757ff219775a216244b8
|
|
| BLAKE2b-256 |
177a5f37843036e32f38d891ab649952d5976247e62a7cb7a808890bdbe2aa80
|