#!../../bin/rhel6-x86_64/Motion

< envPaths

## Register all support components
dbLoadDatabase("../../dbd/Motion.dbd")
Motion_registerRecordDeviceDriver(pdbbase)

# ====================================================================
# Setup some additional environment variables
# ====================================================================
# Setup environment variables

# tag log messages with IOC name
# How to escape the "sioc-ltu0-mc02" as the PERL program
# will try to repl.ace it.
# So, uncomment the following and remove the backslash
epicsEnvSet("EPICS_IOC_LOG_CLIENT_INET","${IOC}")


epicsEnvSet("EPICS_CA_MAX_ARRAY_BYTES","8000000")

# ============================================
# Set MACROS for EVRs
# ============================================
# FAC = SYS0 ==> LCLS1
# FAC = SYS1 ==> FACET

# System Location:
epicsEnvSet("LOCA","LTU0")
epicsEnvSet("IOC_NAME","SIOC:LTU0:MC02")
epicsEnvSet("SUBSYSTEM","MC02")
epicsEnvSet("FAC","SYS0")
epicsEnvSet("AEROTECH_NODE","moc-b34-mc08:8000")
epicsEnvSet("STREAM_PROTOCOL_PATH", "$(TOP)/MotionApp/src/protocols/" )

cd ${TOP}

###########################################################
# Initialize all hardware first                           #
###########################################################

# ======================================================= 
# Aerotech Ensemble CP controller configuration          
# =======================================================

< iocBoot/common/aerotech.init

########################################################################
# BEGIN: Load the record databases
#######################################################################

# =====================================================================
# Load iocAdmin databases to support IOC Health and monitoring
# =====================================================================
dbLoadRecords("db/iocAdminSoft.db","IOC=${IOC_NAME}")
dbLoadRecords("db/iocAdminScanMon.db","IOC=${IOC_NAME}")

# The following database is a result of a python parser
# which looks at RELEASE_SITE and RELEASE to discover
# versions of software your IOC is referencing
# The python parser is part of iocAdmin
dbLoadRecords("db/iocRelease.db","IOC=${IOC_NAME}")

# =====================================================================
# Load database for autosave status
# =====================================================================
dbLoadRecords("db/save_restoreStatus.db", "P=${IOC_NAME}:")

# =====================================================================
# Load database for fast wire scanner
# =====================================================================
< iocBoot/${IOC}/loadDBs

# END: Loading the record databases
#####################################################################################################

# =====================================================================
## Begin: Setup autosave/restore
# ====================================================================                                
# ============================================================
# If all PVs don't connect continue anyway
# ============================================================
#save_restoreSet_IncompleteSetsOk(1)

# ============================================================
# created save/restore backup files with date string
# useful for recovery.
# ============================================================
#save_restoreSet_DatedBackupFiles(1)
#save_restoreSet_DatedBackupFiles(0)

# ============================================================
# Where to find the list of PVs to save
# ============================================================
#set_requestfile_path("/data/${IOC}/autosave-req")

# ============================================================
# Where to write the save files that will be used to restore
# ============================================================
#set_savefile_path("/data/${IOC}/autosave")

# ============================================================
# Prefix that is use to update save/restore status database
# records
# ============================================================
#save_restoreSet_UseStatusPVs(1)
#save_restoreSet_status_prefix("${IOC_NAME}:")

## Restore datasets
#set_pass0_restoreFile("info_settings.sav")
#set_pass1_restoreFile("info_settings.sav")

# =====================================================================
# End: Setup autosave/restore
# =====================================================================

# =====================================================================
# Channel Access Security:
# This is required if you use caPutLog.
# Set access security filea
# Load common LCLS Access Configuration File
< ${ACF_INIT}

# =============================================================
# Start EPICS IOC Process (i.e. all threads will start running)
# =============================================================

## Run this to trace the stages of iocInit
#traceIocInit()

iocInit()

# =====================================================
# Turn on caPutLogging:
# Log values only on change to the iocLogServer:
caPutLogInit("${EPICS_CA_PUT_LOG_ADDR}")
caPutLogShow(2)
# =====================================================

## Start any sequence programs
#seq sncExample,"user=gwbrownHost"
seq( &timeout, "motor=WIRE:LTU0:122, name=WSVM2-aerotech")
seq( &initializeAerotech, "motor=WIRE:LTU0:122, name=WSVM2-aerotech")

## ===========================================================
## Start autosave routines to save our data
## ===========================================================
# optional, needed if the IOC takes a very long time to boot.
#epicsThreadSleep( 1.0)

#cd("/data/${IOC}/autosave-req")
#iocshCmd("makeAutosaveFiles")

# Start the save_restore task
# save changes on change, but no faster
# than every 5 seconds.
# Note: the last arg cannot be set to 0
#create_monitor_set("info_positions.req", 5 )
#create_monitor_set("info_settings.req" , 30 )

# =====================================================================
# Setup Real-time priorities after iocInit for kernel driver threads
# =====================================================================
#cd ${TOP}/iocBoot/${IOC}
#system("/bin/su root -c `pwd`/rtPrioritySetup.cmd")
# =====================================================================

# An example of using the CEXP Shell:
#cexpsh("-c",'printf("hello\n")')

