#!/usr/bin/env bash # Bring up the CANable at RV-C 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 sniff # cansniffer color-diff view (toggle a load, watch bytes) # ./log-can.sh down # take the interface down # # Requires: can-utils (pacman -S can-utils). CANable 2.0 with candleLight/gs_usb # firmware enumerates as a native socketcan device (default can0). set -euo pipefail IFACE="${IFACE:-can0}" BITRATE=250000 # RV-C is always 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" ;; sniff) up; exec cansniffer -c "$IFACE" ;; down) sudo ip link set "$IFACE" down; echo "$IFACE down" ;; *) echo "usage: $0 {up|rec NAME|sniff|down}" >&2; exit 2 ;; esac