#!/bin/bash

XSENS_FILTER=/opt/radac/bin/xsens-filter
FILTER_DIR=/opt/radac/WGS/

function usage()
{
    echo "Usage: $(basename $0) start <sensor name> <in port> <out port> <ip address> <low-pass file> <high-pass file> <high-pass file> <high-pass file> [<angle>]"
    echo "Usage: $(basename $0) <stop|status>"
}

function start()
{
    if [ $# -ne 8 ] && [ $# -ne 9 ];
    then
        usage
        exit 1
    fi
    #PID=$(ps -ax| grep $XSENS_FILTER |grep -v grep|tr -s ' '|cut -f 1 -d ' ');
    PID=$(/sbin/pidof $XSENS_FILTER);
    if [ "x$PID" != "x" ];
    then
        exit 1
    fi

    cd /opt/radac/WGS/
    $XSENS_FILTER $1 $2 $3 $4 $5 $6 $7 $8 $9 &
}

function stop()
{
    #PID=$(ps -ax| grep $XSENS_FILTER |grep -v grep|tr -s ' '|cut -f 1 -d ' ');
    PID=$(/sbin/pidof $XSENS_FILTER);
    if [ "x$PID" == "x" ];
    then
        exit 1
    fi
    kill $PID
}

function status()
{
    #PID=$(ps -ax| grep $XSENS_FILTER |grep -v grep|tr -s ' '|cut -f 1 -d ' ');
    PID=$(/sbin/pidof $XSENS_FILTER);
    if [ "x$PID" == "x" ];
    then
        echo "$XSENS_FILTER appears not to be running"
    else
        echo "$XSENS_FILTER appears to be running with pid $PID"
    fi
}


case $1 in
    start)
    echo $2 $3 $4 $5 $6 $7 $8 $9 ${10}
    start $2 $3 $4 $5 $6 $7 $8 $9 ${10}
    ;;
    stop)
    stop
    ;;
    status)
    status
    ;;
    *)
    echo "Huh?"
    ;;
esac
