#!/bin/sh
###############################################################################
# Start the EtherCAT Scanner Test that will allow control/monitoring
# from an EPICS Driver
###############################################################################

# =================================================================
# The following is used for Process/Threads that need to run as a       
# real-time process                                                
# =================================================================
cd $EPICS_IOCS/../iocTop/ProfileMonitorAD/current/scanner
#Generate the screenrc file
SCREENRC=/data/$1/ethScreenrc
. genScreenRc.sh
# Lock Kernel in memory                                            
ulimit -l unlimited                                                

# Run with real-time priorities
ulimit -r unlimited

# Set umask for the laci user
umask 002
# ====================================================================
# =====================================================================
# we start the ethercat scanner process under the linux screen program:
# This will allow us to attach/detach to our Ethercat scanner process
# =====================================================================
# ================================================================================================
# Start the scanner process
#echo "### Start the scanner process"

screen -h 8192 -c $SCREENRC -dm -S pmChassisScanner ./scanner -f 100 -q scanner-3-chassis.xml /tmp/sock1

# wait until kernel thread is created
/bin/sleep 1

/bin/su root -c "/usr/bin/chrt -pf 45  `ps  -Leo tid,comm | /usr/bin/awk '/EtherCAT-*/'`"

rm -f $SCREENRC
# ===============================================================================================
