#==============================================================
#
#  Abs:  Common BCS startup script for soft IOCs
#
#  Name: st.cmd.soft
#
#  Rem:  Upon entry we expect to be at location TOP
#        and the following macros must be defined.
#        Note that all other environment variables
#        used within this file are defined in envPaths.
#
#           IOC_NAME      - IOC Device name    (ie. SIOC:SYS1:BC01)
#           LOCATION      - Rack location
#           EPICS_IOC_APP - defined in $EPICS_IOCS/<ioc>/startup.cmd
#
#        Upon exiting this script the directory
#        will be set to the TOP of the IOC Application.
#
#  Facility: EED BCS Controls
#
#  Auth: 15-May-2018, Kristi Luchini  (LUCHINI)
#  Rev:  dd-mmm-yyyy, Reviewer's Name (USERNAME)
#--------------------------------------------------------------
#  Mod:
#        17-Sep-2019, K. Luchini     (LUCHINI):
#         chg ENGINEER from K. Luchini to M. Dunning
#         add env var STREAM_PROTOCOL_PATH
#        16-Aug-2019, K. Luchini     (LUCHINI):
#         load ca security file
#         load init_log.cmd.soft
#         add env var SUBSYS
#
#==============================================================
#
# Set environment variables
< envPaths

# Setup environment variables
# Get current iocBoot directory path so we can return easily
epicsEnvSet("IOC_BOOT" ,"${EPICS_IOC_APP}")

# iocAdmin environment variables
# the environment variable LOCATION must
# be defined upon entry.
epicsEnvSet("ENGINEER"  , "")
epicsEnvSet("STARTUP"   , "${EPICS_IOCS}/${IOC}")
epicsEnvSet("ST_CMD"    , "startup.cmd")

# Setup environment variable for iocLogPrefix
epicsEnvSet("SUBSYS", "BCS")

# Set path for stream devices (MCOR bulks)
epicsEnvSet("STREAM_PROTOCOL_PATH","${TOP}/db")

# NFS directory with read-write access
epicsEnvSet("IOC_RESTORE"     , "${IOC_DATA}/${IOC}/autosave")

#==============================================================
# Load the database definitions file and standard databases
#==============================================================
# Load standard EPICS Database
cd ${TOP}
dbLoadDatabase("dbd/bcsSoft.dbd")
bcsSoft_registerRecordDeviceDriver(pdbbase)

# Load IOC Administration Databse
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}")

#==============================================================
# Update archive pv list in the data area
#==============================================================
system("cp ${TOP}/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






