#!/bin/sh

# param 1: start/stop
# param 2: CAN bus number (0,1,...)
# param 3: baudrate (kbps)
# param 4: cycle (ms)

if [ "$1" = "stop" ]
then
    echo "Stopping CAN live message ..."
    kill -7 `ps -ax | grep "can_live $2" | egrep -v grep | awk '{print $1}'`
    ifconfig can"$2" down
    exit 0
fi

if [ "$1" = "start" ]
then
    echo "Starting CAN live message ..."
    echo "$3" >/sys/class/net/can"$2"/can_bitrate
    ifconfig can"$2" up
    ./can_live "$2" "$4" send &
    exit 0
fi

echo "usage: 'can_config start <can_nr> <baudrate> <cycle>' or 'can_config stop <can_nr>'"
exit 1
