can
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseCAN — 嵌入式 CAN / CAN-FD 调试工具
CAN — Embedded CAN/CAN-FD Debugging Tool
统一封装接口发现、实时监控、报文发送、日志记录、数据库文件解码和统计分析能力。
Unified encapsulation of interface discovery, real-time monitoring, message transmission, log recording, database file decoding, and statistical analysis capabilities.
配置
Configuration
环境级配置 (skill/config.json
)
skill/config.jsonEnvironment-level Configuration (skill/config.json
)
skill/config.json仅保留 slcan 相关的环境级配置:
json
{
"slcan_serial_port": "",
"slcan_serial_baudrate": 115200
}| 字段 | 说明 | 默认值 |
|---|---|---|
| slcan 场景的串口 | |
| slcan 场景的串口速率 | |
Only retain slcan-related environment-level configurations:
json
{
"slcan_serial_port": "",
"slcan_serial_baudrate": 115200
}| Field | Description | Default Value |
|---|---|---|
| Serial port for slcan scenario | |
| Serial baud rate for slcan scenario | |
工程级配置 (.embeddedskills/config.json
)
.embeddedskills/config.jsonProject-level Configuration (.embeddedskills/config.json
)
.embeddedskills/config.json工作区下的 存放工程级 CAN 配置:
.embeddedskills/config.jsonjson
{
"can": {
"interface": "",
"channel": "",
"bitrate": 500000,
"data_bitrate": 2000000,
"log_dir": ".embeddedskills/logs/can"
}
}| 字段 | 说明 | 默认值 |
|---|---|---|
| CAN 后端,如 | |
| 通道名,如 | |
| 仲裁域比特率 | |
| CAN-FD 数据域比特率 | |
| 日志输出目录 | |
The in the workspace stores project-level CAN configurations:
.embeddedskills/config.jsonjson
{
"can": {
"interface": "",
"channel": "",
"bitrate": 500000,
"data_bitrate": 2000000,
"log_dir": ".embeddedskills/logs/can"
}
}| Field | Description | Default Value |
|---|---|---|
| CAN backend, e.g., | |
| Channel name, e.g., | |
| Arbitration field bit rate | |
| CAN-FD data field bit rate | |
| Log output directory | |
参数解析优先级
Parameter Parsing Priority
- CLI 参数 (,
--interface,--channel等) - 最高优先级--bitrate - 工程级配置 (中的
.embeddedskills/config.json部分)can - 状态文件 (中的历史记录)
.embeddedskills/state.json - 默认值 - 最低优先级
- CLI Parameters (,
--interface,--channel, etc.) - Highest priority--bitrate - Project-level Configuration (the section in
can).embeddedskills/config.json - State File (historical records in )
.embeddedskills/state.json - Default Values - Lowest priority
自动扫描行为
Automatic Scanning Behavior
当未指定 和 时,脚本会自动扫描系统 CAN 接口:
interfacechannel- 若只找到一个接口,自动使用并写入工程配置
- 若找到多个接口,返回候选列表让用户选择
- 若未找到接口,提示错误
When and are not specified, the script will automatically scan system CAN interfaces:
interfacechannel- If only one interface is found, it will be used automatically and written to the project configuration
- If multiple interfaces are found, a candidate list will be returned for the user to select
- If no interface is found, an error will be prompted
子命令
Subcommands
| 子命令 | 用途 | 风险 |
|---|---|---|
| 扫描可用 CAN 接口与 USB-CAN 设备 | 低 |
| 实时监控总线报文 | 低 |
| 发送标准帧 / 扩展帧 / 远程帧 / CAN-FD 帧 | 高 |
| 记录总线报文到 ASC / BLF / CSV 文件 | 低 |
| 用 DBC 等数据库文件解码报文或日志 | 低 |
| 统计总线负载、ID 分布和帧率 | 低 |
| Subcommand | Purpose | Risk |
|---|---|---|
| Scan available CAN interfaces and USB-CAN devices | Low |
| Real-time monitoring of bus messages | Low |
| Send standard/extended/remote/CAN-FD frames | High |
| Record bus messages to ASC/BLF/CSV files | Low |
| Decode messages or logs using database files like DBC | Low |
| Statistics on bus load, ID distribution, and frame rate | Low |
执行流程
Execution Flow
- 检查 是否可用,未安装时提示
python-canpip install python-can - 按优先级解析参数:CLI > 工程级配置 > 状态文件 > 默认值
- 无子命令时默认执行
scan - 使用解析后的连接参数
monitor / send / log / stats - 先确认数据库文件和输入源存在
decode - 若未指定 /
interface,自动扫描系统 CAN 接口:channel- 唯一候选:自动使用并写入工程配置
- 多候选:返回列表让用户选择
- 成功执行后,将确认的参数写回工程配置
- 只要配置可连接就直接执行,不二次确认
send - 运行对应脚本并输出结构化结果
- 失败时优先反馈接口、驱动、比特率和过滤条件问题
- Check if is available; prompt
python-canif not installedpip install python-can - Parse parameters by priority: CLI > Project-level Configuration > State File > Default Values
- Execute by default when no subcommand is specified
scan - use the parsed connection parameters
monitor / send / log / stats - first confirms the existence of the database file and input source
decode - If /
interfaceare not specified, automatically scan system CAN interfaces:channel- Unique candidate: automatically use and write to project configuration
- Multiple candidates: return list for user selection
- After successful execution, write the confirmed parameters back to the project configuration
- executes directly as long as the configuration is connectable, no secondary confirmation required
send - Run the corresponding script and output structured results
- When failed, prioritize feedback on interface, driver, bit rate, and filter condition issues
脚本调用
Script Invocation
所有脚本位于 skill 目录的 下,通过 直接调用。
脚本会按优先级从 CLI 参数、工程级配置、状态文件中读取参数。
scripts/pythonbash
undefinedAll scripts are located in the directory under the skill directory, and can be called directly via .
Scripts read parameters from CLI parameters, project-level configuration, and state file by priority.
scripts/pythonbash
undefined扫描接口
Scan interfaces
python scripts/can_scan.py [--json]
python scripts/can_scan.py [--json]
实时监控
Real-time monitoring
python scripts/can_monitor.py [--interface <接口>] [--channel <通道>] [--bitrate <速率>] [--fd] [--filter-id <ID列表>] [--exclude-id <ID列表>] [--dbc <DBC文件>] [--timeout <秒>] [--json]
python scripts/can_monitor.py [--interface <interface>] [--channel <channel>] [--bitrate <bitrate>] [--fd] [--filter-id <ID list>] [--exclude-id <ID list>] [--dbc <DBC file>] [--timeout <seconds>] [--json]
发送报文
Send messages
python scripts/can_send.py [--interface <接口>] [--channel <通道>] [--bitrate <速率>] <id> <data> [--extended] [--remote] [--fd] [--repeat <次>] [--interval <秒>] [--periodic <毫秒>] [--listen] [--json]
python scripts/can_send.py [--interface <interface>] [--channel <channel>] [--bitrate <bitrate>] <id> <data> [--extended] [--remote] [--fd] [--repeat <times>] [--interval <seconds>] [--periodic <milliseconds>] [--listen] [--json]
日志记录
Log recording
python scripts/can_log.py [--interface <接口>] [--channel <通道>] [--bitrate <速率>] [--output <文件>] [--duration <秒>] [--max-count <数量>] [--filter-id <ID列表>] [--console] [--json]
python scripts/can_log.py [--interface <interface>] [--channel <channel>] [--bitrate <bitrate>] [--output <file>] [--duration <seconds>] [--max-count <number>] [--filter-id <ID list>] [--console] [--json]
数据库解码
Database decoding
python scripts/can_decode.py <db_file> [--db-format <auto|dbc|arxml|kcd|sym|cdd>] [--id <CAN_ID>] [--data <HEX数据>] [--log <日志文件>] [--signal <信号名>] [--list] [--json]
python scripts/can_decode.py <db_file> [--db-format <auto|dbc|arxml|kcd|sym|cdd>] [--id <CAN_ID>] [--data <HEX data>] [--log <log file>] [--signal <signal name>] [--list] [--json]
总线统计
Bus statistics
python scripts/can_stats.py [--interface <接口>] [--channel <通道>] [--bitrate <速率>] [--duration <秒>] [--top <数量>] [--watch <ID列表>] [--json]
undefinedpython scripts/can_stats.py [--interface <interface>] [--channel <channel>] [--bitrate <bitrate>] [--duration <seconds>] [--top <number>] [--watch <ID list>] [--json]
undefined输出格式
Output Format
单次命令返回标准 JSON:
json
{
"status": "ok",
"action": "scan",
"summary": "发现 2 个 CAN 接口",
"details": { ... }
}持续命令(monitor --json、send --listen --json)输出 JSON Lines,结束摘要写入 stderr。
错误输出:
json
{
"status": "error",
"action": "send",
"error": { "code": "interface_open_failed", "message": "无法打开指定 CAN 接口" }
}Single command returns standard JSON:
json
{
"status": "ok",
"action": "scan",
"summary": "Found 2 CAN interfaces",
"details": { ... }
}Continuous commands (monitor --json, send --listen --json) output JSON Lines, and the end summary is written to stderr.
Error output:
json
{
"status": "error",
"action": "send",
"error": { "code": "interface_open_failed", "message": "Failed to open the specified CAN interface" }
}核心规则
Core Rules
- 不自动猜测 interface、channel、bitrate,多接口时不自动选择
- 参数解析优先级:CLI > 工程级配置 > 状态文件 > 默认值
- 未指定 /
interface时自动扫描,唯一候选自动写入配置,多候选需用户选择channel - 成功执行后,确认的参数自动写回
.embeddedskills/config.json - 未明确说明用途时不主动发送任何报文
- 输出的持续流使用 JSON Lines,摘要写 stderr 不污染数据流
--json - DBC 解码失败不应导致监控中断
- 找不到帧定义时返回明确错误,不静默吞掉
- Do not automatically guess interface, channel, or bitrate; do not automatically select when multiple interfaces exist
- Parameter parsing priority: CLI > Project-level Configuration > State File > Default Values
- Automatically scan when /
interfaceare not specified; automatically write the unique candidate to configuration, require user selection for multiple candidateschannel - After successful execution, automatically write confirmed parameters back to
.embeddedskills/config.json - Do not actively send any messages without clear instructions on usage
- Continuous streams output via use JSON Lines, with summaries written to stderr to avoid polluting the data stream
--json - DBC decoding failure should not interrupt monitoring
- Return clear errors when frame definitions are not found, do not silently discard them
参考
References
- :常见 USB-CAN 设备信息
references/common_interfaces.json
- : Information on common USB-CAN devices
references/common_interfaces.json