#!/bin/bash

READ_XSENS=\/opt\/radac\/bin\/read-xsens

function start()
{
#PID=$(ps -ax| grep $READ_XSENS |grep -v grep|tr -s ' '|cut -f 1 -d ' ');
PID=$(/sbin/pidof $READ_XSENS);
if [ "x$PID" != "x" ];
then
  echo "already on!"
  exit 1
fi
  echo "gonna start!"

#CORR=`cat /opt/radac/config/wgs.properties |grep RadarDriverProperties1|tr ',' ' '|cut -d ' ' -f 11`
#$READ_XSENS $1 $2 $3 $CORR 0 -d > /dev/null &
$READ_XSENS $1 $2 $3 $4 $5 -d > /dev/null &
}

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

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

case $1 in
start)
  start $2 $3 $4 $5 $6
  ;;
stop)
  stop
  ;;
status)
  status
  ;;
*)
  echo "Huh?"
  ;;
esac
