#!/bin/sh

Dytest=.
CmV=/virgoApp/Cm/v8r3
FdV=/virgoApp/Fd/v5r1p6
#UNAME=`uname`

DYDIR=`dirname ${0}`
DyServer=$DYDIR/../$UNAME/dataDisplay.exe
echo "Using $DyServer"


if [ ${#} -eq 0 ] ; then
  echo " "
  echo "Provide please a test number:"
  echo "    0 = do all tests"
  echo "    1 = data from one raw data file             (ddfileraw.car)"
  echo "    2 = data from one 50Hz data file            (ddfile50Hz.car)"
  echo "    3 = data from one trend data file           (ddfiletrend.car)"
  echo "    4 = data from raw data dir                  (ddfiledir.car)"
  echo "    5 = data from ffl file                      (ddfileffl.car)"
  echo "    6 = all types of plot                       (ddplotall.car)"
  echo "    7 = superposed plots                        (ddplotsuperpose.car)"
  echo "    8 = plots with special features             (ddplotspecial.car)"
  echo "    9 = missing and corrupted data              (ddfilebaddata.car)"
  echo "   10 = data processed by user fct              (dduserfct.car)"
  echo "   11 = all vdyplots                            (ddvdyplot.car)"
  echo "   12 = all vdyplots 2D                         (ddvdyplot2.car)"
  echo " "
  echo "   20 = connect to dataSender                   (ddsender.car)"
  echo "   21 = connect online                          (ddcm.car)"
  echo "   22 = use Cm name displaytest                 (ddcmstatic.car)"
  echo "   23 = cm at speed limit                       (ddcmlimit.car)"
  echo "   24 = cm at speed limit with superposed plots (ddcmlimit_same.car)"
  echo " "
  echo "   30 = connect to a shared memory              (ddshm.car)"
  echo " "
  exit 0 
fi

cd $Dytest


# Reading files tests
#####################

if [ ${1} -eq "1" ]  || [ ${1} -eq "0" ];  then $DyServer $DYDIR/ddfileraw.car ; fi
if [ ${1} -eq "2" ]  || [ ${1} -eq "0" ];  then $DyServer $DYDIR/ddfile50Hz.car ; fi
if [ ${1} -eq "3" ]  || [ ${1} -eq "0" ];  then $DyServer $DYDIR/ddfiletrend.car ; fi
if [ ${1} -eq "4" ]  || [ ${1} -eq "0" ];  then $DyServer $DYDIR/ddfiledir.car ; fi
if [ ${1} -eq "5" ]  || [ ${1} -eq "0" ];  then $DyServer $DYDIR/ddfileffl.car ; fi
if [ ${1} -eq "6" ]  || [ ${1} -eq "0" ];  then $DyServer $DYDIR/ddplotall.car ; fi
if [ ${1} -eq "7" ]  || [ ${1} -eq "0" ];  then $DyServer $DYDIR/ddplotsuperpose.car ; fi
if [ ${1} -eq "8" ]  || [ ${1} -eq "0" ];  then $DyServer $DYDIR/ddplotspecial.car ; fi
if [ ${1} -eq "9" ]  || [ ${1} -eq "0" ];  then $DyServer $DYDIR/ddfilebaddata.car ; fi
if [ ${1} -eq "10" ] || [ ${1} -eq "0" ];  then $DyServer $DYDIR/dduserfct.car ; fi
if [ ${1} -eq "11" ] || [ ${1} -eq "0" ];  then $DyServer $DYDIR/ddvdyplot.car ; fi
if [ ${1} -eq "12" ] || [ ${1} -eq "0" ];  then $DyServer $DYDIR/ddvdyplot2.car ; fi


# Cm Online connections tests
#############################

if [ ${1} -eq "20" ] || [ ${1} -eq "0" ]; then
  export CMDOMAIN=Cascina
  sleep 2
  $DyServer $DYDIR/ddsender.car ; echo "running ddsender.car";
fi

if [ ${1} -eq "21" ] || [ ${1} -eq "0" ]; then
  xterm -sb -sl 1024 -geometry 168x10+10+0 -T "fbsimtest - `date +\"%d %b %Y-%T\"`" -e $FdV/$UNAME/FdSim.exe displaytest 0 1 -adc 20000 4 -proc 20000 1 -cmname fbsimtest &
  sleep 2
  $DyServer $DYDIR/ddcm.car ; echo "running ddcm.car";
  $CmV/$UNAME/cm.exe send -to fbsimtest -type CfgKill
  echo "Removing fbsimtest"
  sleep 2
fi

if [ ${1} -eq "22" ] || [ ${1} -eq "0" ]; then
  xterm -sb -sl 1024 -geometry 168x10+10+0 -T "fbsimtest - `date +\"%d %b %Y-%T\"`" -e $FdV/$UNAME/FdSim.exe displaytest 0 1 -adc 20000 4 -proc 20000 1 -cmname fbsimtest &
  sleep 2
  $DyServer $DYDIR/ddcmstatic.car ; echo "running ddcmstatic.car";
  $CmV/$UNAME/cm.exe send -to fbsimtest -type CfgKill
  echo "Removing fbsimtest"
  sleep 2
fi

if [ ${1} -eq "23" ] || [ ${1} -eq "0" ]; then
  xterm -sb -sl 1024 -geometry 168x10+10+0 -T "fbsimtest - `date +\"%d %b %Y-%T\"`" -e $FdV/$UNAME/FdSim.exe displaytest 0 1 -adc 20000 4 -proc 20000 1 -cmname fbsimtest &
  sleep 2
  $DyServer $DYDIR/ddcmlimit.car ; echo "running ddcmlimit.car";
  $CmV/$UNAME/cm.exe send -to fbsimtest -type CfgKill
  echo "Removing fbsimtest"
  sleep 2
fi

if [ ${1} -eq "24" ] || [ ${1} -eq "0" ]; then
  xterm -sb -sl 1024 -geometry 168x10+10+0 -T "fbsimtest - `date +\"%d %b %Y-%T\"`" -e $FdV/$UNAME/FdSim.exe displaytest 0 1 -adc 20000 4 -proc 20000 1 -cmname fbsimtest &
  sleep 2
  $DyServer $DYDIR/ddcmlimit_same.car ; echo "running ddcmlimit_same.car";
  $CmV/$UNAME/cm.exe send -to fbsimtest -type CfgKill
  echo "Removing fbsimtest"
fi

# Shared memory connection tests
################################

if [ ${1} -eq "30" ] || [ ${1} -eq "0" ]; then
  xterm -sb -sl 1024 -geometry 168x10+10+0 -T "producertest - `date +\"%d %b %Y-%T\"`" -e $FdV/$UNAME/producer.exe producer &
  pid=$!
  sleep 2
  $DyServer $DYDIR/ddshm.car ; echo "running ddshm.car";
  kill $pid
  echo "Removing producertest"
fi


if [ ${1} -eq "0" ]; then
  echo "All tests done"
else
  echo "Test ${1} done."
fi
echo " "


