#!/usr/bin/env bash # Bring up the CANable at IDS-CAN speed and log timestamped raw frames. # # Usage: # ./log-can.sh # bring up can0 @ 250k, live candump # ./log-can.sh rec NAME # also tee a timestamped log to NAME-.log # ./log-can.sh watch # cansniffer color-diff view (operate a load, watch bytes) # ./log-can.sh down # take the interface down # # Requires: can-utils (paru -S can-utils on Arch). This CANable shipped with # slcan firmware (a /dev/ttyACM* serial device) — bridge it to can0 first with # sudo slcand -o -s5 /dev/ttyACMx can0 # A candleLight/gs_usb reflash would instead give a native socketcan can0 and let # the up() path below set the bitrate directly. set -euo pipefail IFACE="${IFACE:-can0}" BITRATE=250000 # IDS-CAN is 250k CMD="${1:-up}" up() { if ! ip link show "$IFACE" &>/dev/null; then echo "No $IFACE — is the CANable plugged in? (dmesg | grep -i gs_usb)" >&2 exit 1 fi sudo ip link set "$IFACE" down 2>/dev/null || true sudo ip link set "$IFACE" up type can bitrate "$BITRATE" echo "$IFACE up @ ${BITRATE} bps" } case "$CMD" in up) up; exec candump -ta -x "$IFACE" ;; rec) up name="${2:-onecontrol}"; out="$(dirname "$0")/${name}-$(date +%F_%H%M%S).log" echo "logging -> $out (Ctrl-C to stop)" exec candump -ta -x "$IFACE" | tee "$out" ;; watch) up; exec cansniffer -c "$IFACE" ;; down) sudo ip link set "$IFACE" down; echo "$IFACE down" ;; *) echo "usage: $0 {up|rec NAME|watch|down}" >&2; exit 2 ;; esac