# !/bin/bash
# This script is meant to be run on the tester carts. Ctrl+C to quit.
# CAN log will be converted into asc files for each individually specified bus and stored in /tmp folder.
# Call script: ./can_logging.sh <BUS1> <BUS2> <BUS3> <...>

can_busses=("$@")
testtime=$(date +'%m_%d_%Y_%T')

# Ctrl-C Handler
function ctrl_c() {
    echo "Trapped CTRL-C: END CAN LOGGING"
    for i in "${can_busses[@]}"
    do
        log2asc -I /tmp/can_log_$testtime.log "$i" -O /tmp/"$i"_can_log_$testtime.asc
    done
}

# Log all can busses
trap ctrl_c INT
candump -L any > /tmp/can_log_$testtime.log