#!../../bin/linux-x86_64/QtWidgetSim

## You may have to change QtWidgetSim to something else
## everywhere it appears in this file

< envPaths

# Setup some additional environment variables
# ====================================================================
# Setup environment variables
epicsEnvSet("ENGINEER","Alisha Babbitt")
epicsEnvSet("LOCATION","Everywhere")

# ==========================================================
# Tag log messages from this softIOC with the IOC name:
# ==========================================================

epicsEnvSet("EPICS_IOC_LOG_CLIENT_INET","${IOC}")

# ========================================================
# Support Large Arrays/Waveforms; Number in Bytes
# Please calculate the size of the largest waveform
# that you support in your IOC.  Do not just copy numbers
# from other apps.  This will only lead to an exhaustion
# of resources and problems with your IOC.
# The default maximum size for a channel access array is
# 16K bytes.
# ========================================================
epicsEnvSet("EPICS_CA_MAX_ARRAY_BYTES", "65536")

# END: Additional environment variables
# ====================================================================

cd ${TOP}
# ====================================================================
# Load EPICS Database Definitions and
# Register all EPICS support components
# ====================================================================
dbLoadDatabase("dbd/QtWidgetSim.dbd")
QtWidgetSim_registerRecordDeviceDriver(pdbbase)


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

# 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}")

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


# =====================================================================
#Load Additional databases:
# =====================================================================
## Load record instances to drive our QT Widgets:
dbLoadRecords("db/QtWidget_Simulator.db","P=QT_MUON")
dbLoadRecords("db/QtWidget_Simulator.db","P=QT_MESON")
#dbLoadRecords("db/QtWidget_Simulator.db","P=QT_LEPTON")
#dbLoadRecords("db/QtWidget_Simulator.db","P=QT_QUARK")
#dbLoadRecords("db/QtWidget_Simulator.db","P=QT_PHOTON")

# 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)

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

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

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

## 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 file
# 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()

cd ${IOC_BOOT}
iocInit()

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

## Start any sequence programs
#seq sncExample,"user=ernestoHost"

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

cd("${IOC_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 )

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

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





