This commit is contained in:
2026-01-29 17:17:14 +03:00
parent f54778528e
commit 69acad18ca
16 changed files with 2418 additions and 0 deletions

62
scripts/setup_can.sh Normal file
View File

@@ -0,0 +1,62 @@
#!/bin/bash
# Скрипт настройки CAN интерфейсов на Raspberry Pi 5 с 2CH CAN HAT
set -e
BITRATE=${1:-500000}
echo "=== CAN Interface Setup ==="
echo "Bitrate: $BITRATE bps"
echo ""
# Проверка прав
if [ "$EUID" -ne 0 ]; then
echo "Please run as root (sudo)"
exit 1
fi
# Загрузка модулей
echo "[1/4] Loading kernel modules..."
modprobe can
modprobe can_raw
modprobe mcp251x 2>/dev/null || true # Для SPI CAN контроллеров
# Настройка can0
echo "[2/4] Configuring can0..."
if ip link show can0 &>/dev/null; then
ip link set can0 down 2>/dev/null || true
ip link set can0 type can bitrate $BITRATE
ip link set can0 up
echo " can0: UP at $BITRATE bps"
else
echo " can0: Not found (skipping)"
fi
# Настройка can1
echo "[3/4] Configuring can1..."
if ip link show can1 &>/dev/null; then
ip link set can1 down 2>/dev/null || true
ip link set can1 type can bitrate $BITRATE
ip link set can1 up
echo " can1: UP at $BITRATE bps"
else
echo " can1: Not found (skipping)"
fi
# Создание vcan0 для тестирования
echo "[4/4] Creating virtual CAN (vcan0)..."
modprobe vcan
if ! ip link show vcan0 &>/dev/null; then
ip link add dev vcan0 type vcan
fi
ip link set vcan0 up
echo " vcan0: UP (virtual)"
echo ""
echo "=== Status ==="
ip -details link show type can 2>/dev/null || echo "No physical CAN interfaces"
ip -details link show type vcan 2>/dev/null || echo "No virtual CAN interfaces"
echo ""
echo "=== Done ==="
echo "You can now run: python src/main.py -i can1 -s city"