Files
obd_emulator/scripts/monitor_can.sh
2026-01-29 17:17:14 +03:00

33 lines
942 B
Bash
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#!/bin/bash
# Мониторинг CAN трафика с фильтрацией OBD2
INTERFACE=${1:-vcan0}
echo "=== CAN Monitor (OBD2) ==="
echo "Interface: $INTERFACE"
echo "Filtering: 7DF (requests) and 7E8 (responses)"
echo "Press Ctrl+C to stop"
echo ""
# Проверка candump
if ! command -v candump &> /dev/null; then
echo "Error: candump not found. Install can-utils:"
echo " sudo apt install can-utils"
exit 1
fi
# Мониторинг с фильтром
candump "$INTERFACE" | grep -E "(7DF|7E8)" | while read line; do
timestamp=$(date +"%H:%M:%S.%3N")
# Парсинг и форматирование
if echo "$line" | grep -q "7DF"; then
# Запрос
pid=$(echo "$line" | awk '{print $3}' | cut -c5-6)
echo "[$timestamp] REQUEST -> PID: 0x$pid"
elif echo "$line" | grep -q "7E8"; then
# Ответ
echo "[$timestamp] RESPONSE <- $line"
fi
done