SuperAPI AI Directory

can

Coding & development

View repository

Updated 10-15 15:28

About this skill

CAN — Embedded CAN / CAN-FD debugging tool

Unified encapsulation of interface discovery, real-time monitoring, message sending, logging, database file decoding, and statistical analysis capabilities.

Configuration

Environment-level configuration (skill/config.json)

Only retain slcan-related environment-level configuration:

{
  "slcan_serial_port": "",
  "slcan_serial_baudrate": 115200
}
Field Description Default value
slcan_serial_port Serial port for slcan scenarios ""
slcan_serial_baudrate Serial port baud rate for slcan scenarios 115200

Project-level configuration (.embeddedskills/config.json)

Under the workspace, .embeddedskills/config.json stores project-level CAN configuration:

{
  "can": {
    "interface": "",
    "channel": "",
    "bitrate": 500000,
    "data_bitrate": 2000000,
    "log_dir": ".embeddedskills/logs/can"
  }
}
Field Description Default value
interface CAN backend, such as pcan / vector / slcan ""
channel Channel name, such as PCAN_USBBUS1 ""
bitrate Arbitration domain bitrate 500000
data_bitrate CAN-FD data domain bitrate 2000000
log_dir Log output directory .embeddedskills/logs/can

Parameter parsing priority

  1. CLI parameters (--interface, --channel, --bitrate , etc.) - highest priority
  2. Project-level configuration (.embeddedskills/config.json in can section)
  3. State file (.embeddedskills/state.json history records)
  4. Default value - lowest priority

Automatic scanning behavior

When interface and channel are not specified, the script automatically scans system CAN interfaces and processes as follows:

  1. Scan all available CAN interfaces in the system
  2. If only one interface is found → automatically use it and write to project configuration
  3. If multiple interfaces are found → return a candidate list and wait for user selection
  4. If no interface is found → prompt an error and stop execution

Subcommands

Subcommand Purpose Risk
scan Scan available CAN interfaces and USB-CAN devices Low
monitor Real-time monitoring of bus messages Low
send Send standard frames / extended frames / remote frames / CAN-FD frames High
log Record bus messages to ASC / BLF / CSV files Low
decode Decode messages or logs using database files such as DBC Low
stats Count bus load, ID distribution, and frame rate Low

Execution flow

  1. Check whether python-can is available; if not installed, prompt pip install python-can
  2. Parse parameters by priority: CLI > project-level configuration > state file > default value
  3. When there is no subcommand, execute scan
  4. monitor / send / log / stats Use the parsed connection parameters
  5. decode First confirm that the database file and input source exist
  6. If interface/channelis not specified, automatically scan system CAN interfaces:
    • Unique candidate: automatically use it and write to project configuration
    • Multiple candidates: return a list for the user to choose
  7. After successful execution, write the confirmed parameters back to the project configuration
  8. send As long as the configuration can connect, execute directly without secondary confirmation
  9. Run the corresponding script and output structured results
  10. When it fails, prioritize reporting issues with the interface, driver, bitrate, and filter conditions

Script invocation

All scripts are located in the skill directory under scripts/ and are invoked directly via python . Scripts read parameters by priority from CLI arguments, project-level configuration, and state files.

# 扫描接口
python scripts/can_scan.py [--json]

# 实时监控
python scripts/can_monitor.py [--interface <接口>] [--channel <通道>] [--bitrate <速率>] [--fd] [--filter-id <ID列表>] [--exclude-id <ID列表>] [--dbc <DBC文件>] [--timeout <秒>] [--json]

# 发送报文
python scripts/can_send.py [--interface <接口>] [--channel <通道>] [--bitrate <速率>] <id> <data> [--extended] [--remote] [--fd] [--repeat <次>] [--interval <秒>] [--periodic <毫秒>] [--listen] [--json]

# 日志记录
python scripts/can_log.py [--interface <接口>] [--channel <通道>] [--bitrate <速率>] [--output <文件>] [--duration <秒>] [--max-count <数量>] [--filter-id <ID列表>] [--console] [--json]

# 数据库解码
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_stats.py [--interface <接口>] [--channel <通道>] [--bitrate <速率>] [--duration <秒>] [--top <数量>] [--watch <ID列表>] [--json]

Output format

A single command returns standard JSON:

{
  "status": "ok",
  "action": "scan",
  "summary": "发现 2 个 CAN 接口",
  "details": { ... }
}

Continuous commands (monitor --json, send --listen --json) output JSON Lines, and the end summary is written to stderr.

Error output:

{
  "status": "error",
  "action": "send",
  "error": { "code": "interface_open_failed", "message": "无法打开指定 CAN 接口" }
}

Core rules

  • Do not automatically guess interface, channel, or bitrate; do not automatically select when there are multiple interfaces
  • Parameter resolution priority: CLI > project-level configuration > state file > default values; automatic scan results take effect only when no CLI parameters are provided
  • When not specified, interface/channel automatically scans; a unique candidate is automatically written to the configuration, while multiple candidates require user selection
  • After successful execution, the confirmed parameters are automatically written back to .embeddedskills/config.json
  • Do not proactively send any messages unless the purpose is explicitly stated
  • --json The continuous stream output uses JSON Lines, and the summary is written to stderr without polluting the data stream
  • DBC decoding failure should not interrupt monitoring
  • When no frame definition is found, return a clear error and do not silently swallow it

Reference

  • references/common_interfaces.json: common USB-CAN device information