#==============================================================
#
#  Abs:  Generic startup script for a soft IOC
#
#  Name: st.cmd.soft
#
#  Side:  This script expectes the following
#         environment variables tobe defined upon entry
#           IOC_NAME       - IOC Device name,     (ie. SIOC:MCC0:MP00)
#           ST_GDB         - Debug flag for gdb    (optional)  
#           INIT_ACF       - file that loads caSecurity file (with path)
#           INIT_LOG       - file that loads message log prefix (with path)
#           DB_ERR_SUSPEND - file that suspends boot on db error (with path)
#
#         Some of the above macros are defined by the script
#         envPaths, which is generated during the build and
#         saved at: iocBoot/<nodename>, or by  the calling script
#
#         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 MPS Controls
#
#  Auth: 27-Aug-2021, Kristi Luchini  (LUCHINI)
#  Rev:  dd-mmm-yyyy, Reviewer's Name (USERNAME)
#--------------------------------------------------------------
#  Mod:
#        dd-mmm-yyyy, First Lastname  (USERNAME):
#         comment
#
#==============================================================
#
# Set environment variables
< envPaths

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

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

# Set path for stream devices (MCOR bulks)
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/MpsSupportSoft.dbd")
MpsSupportSoft_registerRecordDeviceDriver(pdbbase)

# 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 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}
asSetFilename("${TOP}/iocBoot/common/mps_cas.acf")

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

# End of script

