can

Original🇨🇳 Chinese
Translated
7 scriptsChecked / no sensitive code detected

Embedded CAN/CAN-FD debugging tool for interface scanning, message monitoring, test frame transmission, log recording, database file decoding, and bus statistics. Automatically triggered when users mention CAN, CAN-FD, DBC decoding, bus packet capture, USB-CAN joint debugging, message transmission, bus statistics, PCAN, Vector, slcan, CAN interface scanning, CAN ID filtering, ASC logs, BLF files. Also compatible with explicit invocation via /can. Even if users only say "check CAN messages", "send a test frame" or "decode DBC", this skill should be triggered as long as the context involves CAN bus communication.

2installs
Added on

NPX Install

npx skill4agent add zhinkgit/embeddedskills can

Tags

Translated version includes tags in frontmatter

SKILL.md Content (Chinese)

View Translation Comparison →

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

Environment-level Configuration (
skill/config.json
)

Only retain slcan-related environment-level configurations:
json
{
  "slcan_serial_port": "",
  "slcan_serial_baudrate": 115200
}
FieldDescriptionDefault Value
slcan_serial_port
Serial port for slcan scenario
""
slcan_serial_baudrate
Serial baud rate for slcan scenario
115200

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

The
.embeddedskills/config.json
in the workspace stores project-level CAN configurations:
json
{
  "can": {
    "interface": "",
    "channel": "",
    "bitrate": 500000,
    "data_bitrate": 2000000,
    "log_dir": ".embeddedskills/logs/can"
  }
}
FieldDescriptionDefault Value
interface
CAN backend, e.g.,
pcan
/
vector
/
slcan
""
channel
Channel name, e.g.,
PCAN_USBBUS1
""
bitrate
Arbitration field bit rate
500000
data_bitrate
CAN-FD data field bit rate
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 (the
    can
    section in
    .embeddedskills/config.json
    )
  3. State File (historical records in
    .embeddedskills/state.json
    )
  4. Default Values - Lowest priority

Automatic Scanning Behavior

When
interface
and
channel
are not specified, the script will automatically scan system CAN interfaces:
  • 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

SubcommandPurposeRisk
scan
Scan available CAN interfaces and USB-CAN devicesLow
monitor
Real-time monitoring of bus messagesLow
send
Send standard/extended/remote/CAN-FD framesHigh
log
Record bus messages to ASC/BLF/CSV filesLow
decode
Decode messages or logs using database files like DBCLow
stats
Statistics on bus load, ID distribution, and frame rateLow

Execution Flow

  1. Check if
    python-can
    is available; prompt
    pip install python-can
    if not installed
  2. Parse parameters by priority: CLI > Project-level Configuration > State File > Default Values
  3. Execute
    scan
    by default when no subcommand is specified
  4. monitor / send / log / stats
    use the parsed connection parameters
  5. decode
    first confirms the existence of the database file and input source
  6. If
    interface
    /
    channel
    are not specified, automatically scan system CAN interfaces:
    • Unique candidate: automatically use and write to project configuration
    • Multiple candidates: return list for user selection
  7. After successful execution, write the confirmed parameters back to the project configuration
  8. send
    executes directly as long as the configuration is connectable, no secondary confirmation required
  9. Run the corresponding script and output structured results
  10. When failed, prioritize feedback on interface, driver, bit rate, and filter condition issues

Script Invocation

All scripts are located in the
scripts/
directory under the skill directory, and can be called directly via
python
. Scripts read parameters from CLI parameters, project-level configuration, and state file by priority.
bash
# Scan interfaces
python scripts/can_scan.py [--json]

# Real-time monitoring
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 <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 <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 data>] [--log <log file>] [--signal <signal name>] [--list] [--json]

# Bus statistics
python scripts/can_stats.py [--interface <interface>] [--channel <channel>] [--bitrate <bitrate>] [--duration <seconds>] [--top <number>] [--watch <ID list>] [--json]

Output Format

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

  • 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
    interface
    /
    channel
    are not specified; automatically write the unique candidate to configuration, require user selection for multiple candidates
  • 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
    --json
    use JSON Lines, with summaries written to stderr to avoid polluting the data stream
  • DBC decoding failure should not interrupt monitoring
  • Return clear errors when frame definitions are not found, do not silently discard them

References

  • references/common_interfaces.json
    : Information on common USB-CAN devices