#==============================================================
#
#  Abs:  Common Soft IOC startup script
#
#  Name: st.cmd.soft
#
#  Side:  This script expectes the following
#         environment variables tobe defined upon entry
#           IOC_NAME   - IOC Device name,           (ie. SIOC:BSY0:MC01)
#           ENGINEER   - IOC Engineer               (ie. Mitch D'Ewart)
#           MOTION_APP - Motion application and db  (ie. motion,
#
#         Some of the above macros are defined by the script
#         envPaths, which is generated during the build and
#         saved at: iocBoot/<nodename>
#
#         Upon exit, this script will leave the ioc sitting
#         at the application TOP directory when the following
#         is defined in the Makefile:
#
#        TARGET = envPaths
#
#  Facility: SLAC Motion Controls
#
#  Auth: 02-Dec-2015, Kristi Luchini  (LUCHINI)
#  Rev:  dd-mmm-yyyy, Reviewer's Name (USERNAME)
#--------------------------------------------------------------
#  Mod:
#         14-Jul-2020, K. Luchini           (LUCHINI):
#           load envPaths
#           setup iocAdmin env var
#           load motion dbd and register record device driver.
#         09-Apr-2020, Namrata Balakrishnan (NAMRATA):
#           Moved the following to main st.cmd
#              Remove engineer env variable
#              Remove change directory to $TOP
#              Remove load database definition files
#           These items are specific to the IOC   
#         17-Oct-2019, Namrata Balakrishnan (NAMRATA):
#           add devSeqCar.db
#           add log_init.cmd.soft
#           add SUBSYS env var
#
#==============================================================
#
# Set environment variables
< envPaths

# iocAdmin environment variables
epicsEnvSet("IOC_BOOT" ,"${EPICS_IOC_APP}")
epicsEnvSet("STARTUP"  ,"${EPICS_IOCS}/${IOC}")
epicsEnvSet("ST_CMD"   ,"startup.cmd")

# iocAdmin environment variables
epicsEnvSet("SUBSYS","motion")

# required for large waveforms, used for BSA pvs
epicsEnvSet("EPICS_CA_MAX_ARRAY_BYTES", "30000")

# required for streamdevice
epicsEnvSet("STREAM_PROTOCOL_PATH", "$(TOP)/db")

# Change to the top of the app
cd ${TOP}

#==============================================================
# Load standard database
#==============================================================

# Initialize EPICS errlog message queue size.  This needs to be
# done before any dbLoad calls are made. Note the default is
# 1260 bytes - too many messages are being discarded making it 
# hard to debug.
errlogInit(5000)

# Load the database definitions file
dbLoadDatabase("dbd/${MOTION_APP}.dbd")
${MOTION_APP}_registerRecordDeviceDriver(pdbbase)

# Load iocAdmin databases to support IOC Health and monitoring
dbLoadRecords("db/iocAdminSoft.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 sequence admin
dbLoadRecords("db/devSeqCar.db","SIOC=${IOC_NAME}")

#==============================================================
# Update archive pv list in the data area
#==============================================================
system("cp archive/${IOC}.archive  ${IOC_DATA}/${IOC}/archive/")

#==============================================================
#  Load Channe Access Security if configuration file exists
#==============================================================
< ${ACF_INIT}

#==============================================================
# Start IOC Log Client
#==============================================================
< ${LOG_INIT}

# End of script

