#==============================================================
#
#  Abs:  Start autosave PVs (RTEMS)
#
#  Name: restore.cmd
#
#  Rem:  This script is loaded after iocInit
#
#       "In the lore that has built up around autosave,
#        PV's that should be restored only before record
#        initialization have been termed "positions".
#        All other PV's have been termed "settings".
#
#        Thus, you might run across a file called
#        'auto_positions.req', and now you'll know that
#        the parameters in this file are intended to be
#        restored only during autosave's pass-0."
#           - from autosave documentation
#
#        This script expects the following
#        macros tobe defined upon entry:
#          a) TOP        - Enviroment varilable for path to top of IOC Application
#          b) /data      - NFS Mount for IOC data directory
#          c) the status prefix has been set for autosave
#          d) the request and save files locations have been set
#          e) the save_restoreStatus.db has been loaded
#
#       The autosave restore PV list is generated from the database
#       info field and the PV list is written to the standard filenames:
#         info_settings.req
#         info_positions.req
#       These files can be found in in the directory defined
#       in init_restore.cmd
#
#       Upon existing this script the directory will be set to
#       the IOC Application TOP.
#
#  Facility:  SLAC Magnet Controls
#
#  Auth: 23-Jul-2014, Kristi Luchini  (LUCHINI)
#  Rev:  dd-mmm-yyyy, Reviewer's Name (USERNAME)
#--------------------------------------------------------------
#  Mod:
#        19-Jun-2023, K. Luchini      (LUCHINI):
#          modify for autosave
#
#==============================================================
#
# Wait before building autosave files
epicsThreadSleep(1)

# Generate the autosave PV list
# Note we need change directory to
# where we are saving the restore
# request file.
chdir(getenv("/data/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
# Also the static restore file is not monitored.
create_monitor_set("info_positions.req", 5 )
create_monitor_set("info_settings.req" , 5 )

# Turn off debug messages
save_restoreSet_Debug(0)

# change directory to TOP of application
# Change directory to the TOP of the Application
chdir(getenv("TOP"))

# End of script






