1# @Language: Markdown
2# @Software: VS Code/MacDown/Typora/Vim
3# @Author  : Di Wang
4# @Email   : [email protected]

See epics examples

功能

save

  • 把record的某个field值保存到某个文件中(.sav文件)
  • 对于vxWorks, 涉及nfs的处理
  • 要选择保存哪些field, 用.req文件来指定, 或者用record的info field. 例: info(autosaveFields, VAL)
  • 处理.req文件的路径以及.sav文件的路径
  • 对于.sav文件, 还要处理备份

restore

  • 在iocInit过程中, 从文件中恢复值.
  • 涉及到iocInit过程中的哪个阶段(pass 0 or pass 1)恢复. autosave使用术语position和setting来区分pass0和pass1, 但显然不如直接使用pass0和pass1方便记忆.
  • 处理不同情况的restore, 如waveform, record link.

编译

$(HOME)/epics/R7.0.8/modules目录下编译autosave之后, 在$(HOME)/epics/R7.0.8/ioc目录下创建autosave ioc, 然后创建RELEASE.local文件.

1# inside Release.local
2MODULES = $(TOP)/../../modules
3AUTOSAVE = $(MODULES)/autosave-R5-11

然后在ioc app src目录下的 Makefile中:

1xxx_LIBS += autosave
2xxx_DBD += asSupport.dbd

用法

以下为e3中的配置. 所有需要save and restore的record都在db文件中添加对应的info field, 也是比较推荐的用法, 可以避免手写req文件. 注意afterInit命令由require module提供.

 1#- Define autosave environment variables from shell environment, with suitable defaults
 2
 3#- AUTOSAVE_INCOMPLETE      - Optional: Ok to save/restore save sets with missing values?
 4#-                            Default: 1
 5#- AUTOSAVE_CA_RECONNECT    - Optional: Retry connecting to PVs whose initial connection
 6#-                                      attempt failed?,  Default: 1
 7#- AUTOSAVE_DATED_BACKUP    - Optional: Save dated backup files?
 8#-                            Default: 1
 9#- AUTOSAVE_NUM_SEQ         - Optional: Number of sequenced backup files to write
10#-                            Default: 3
11#- AUTOSAVE_SEQ_PERIOD      - Optional: Time interval in seconds between sequenced backups
12#-                            Default: 300
13#- AUTOSAVE_VALUES_FILES_PASS0    - Optional: Filename, Default: values_pass0
14#- AUTOSAVE_VALUES_FILES_PASS1    - Optional: Filename, Default: values_pass1
15#- AUTOSAVE_SETTINGS_FILES        - Optional: Filename, Default : settings
16#- AUTOSAVE_VALUES_PERIOD_PASS0   - Optional, Default 5
17#- AUTOSAVE_VALUES_PERIOD_PASS1   - Optional, Default 10
18#- AUTOSAVE_SETTINGS_PERIOD       - Optional, Default 5
19#- AUTOSAVE_DEBUG_MODE            - Optional, Default 0
20
21set_savefile_path    ("$(AS_TOP)/$(IOCDIR)", "/save")
22set_requestfile_path ("$(AS_TOP)/$(IOCDIR)", "/req")
23
24#- If there is no path, create it
25system("install -d $(AS_TOP)/$(IOCDIR)/save")
26system("install -d $(AS_TOP)/$(IOCDIR)/req")
27
28save_restoreSet_status_prefix("$(IOCNAME):as-")
29
30#- Debug-output level
31save_restoreSet_Debug($(AUTOSAVE_DEBUG_MODE=0))
32
33#- Ok to save/restore save sets with missing values (no CA connection to PV)?
34save_restoreSet_IncompleteSetsOk($(AUTOSAVE_INCOMPLETE=1))
35
36#- Tell save_restore to writed dated backup files.
37save_restoreSet_DatedBackupFiles($(AUTOSAVE_DATED_BACKUP=1))
38
39#- Tell save_restore to save sequence files.
40#- save_restore to to maintain three copies of each *.sav file
41save_restoreSet_NumSeqFiles($(AUTOSAVE_NUM_SEQ=3))
42
43#- at 5 minute intervals
44save_restoreSet_SeqPeriodInSeconds($(AUTOSAVE_SEQ_PERIOD=300))
45
46#- should periodically retry connecting to PVs whose initial connection attempt failed
47save_restoreSet_CAReconnect($(AUTOSAVE_CA_RECONNECT=1))
48
49#- Time interval in seconds between forced save-file writes.  (-1 means forever).
50#- This is intended to get save files written even if the normal trigger mechanism is broken.
51save_restoreSet_CallbackTimeout(-1)
52#- pass0 : save files are to be restored before record initialization
53set_pass0_restoreFile("$(AUTOSAVE_SETTINGS_FILES=settings).sav")
54set_pass0_restoreFile("$(AUTOSAVE_VALUES_FILES_PASS0=values_pass0).sav")
55#- pass1 : save files are to be restored after record initialization
56set_pass1_restoreFile("$(AUTOSAVE_SETTINGS_FILES=settings).sav")
57set_pass1_restoreFile("$(AUTOSAVE_VALUES_FILES_PASS1=values_pass1).sav")
58
59dbLoadRecords("save_restoreStatus.db", "P=$(IOCNAME):as-, DEAD_SECONDS=5")
60
61#- Note afterInit supplied by require
62afterInit("makeAutosaveFileFromDbInfo('$(AS_TOP)/$(IOCDIR)/req/$(AUTOSAVE_SETTINGS_FILES=settings).req','autosaveFields')")
63afterInit("makeAutosaveFileFromDbInfo('$(AS_TOP)/$(IOCDIR)/req/$(AUTOSAVE_VALUES_FILES_PASS0=values_pass0).req','autosaveFields_pass0')")
64afterInit("makeAutosaveFileFromDbInfo('$(AS_TOP)/$(IOCDIR)/req/$(AUTOSAVE_VALUES_FILES_PASS1=values_pass1).req','autosaveFields_pass1')")
65
66#- Note afterInit supplied by require
67#- We don't need PREFIX, because generated req files has the hard-code PV names from DBInfo : info tag
68afterInit("create_monitor_set('$(AUTOSAVE_SETTINGS_FILES=settings).req','$(AUTOSAVE_SETTINGS_PERIOD=5)')")
69afterInit("create_monitor_set('$(AUTOSAVE_VALUES_FILES_PASS0=values_pass0).req','$(AUTOSAVE_VALUES_PASS0_PERIOD=5)')")
70afterInit("create_monitor_set('$(AUTOSAVE_VALUES_FILES_PASS1=values_pass1).req','$(AUTOSAVE_VALUES_PASS1_PERIOD=10)')")

问题

Q: save_restoreStatus.db中的record是做什么的?

A: 用一些record来表示autosave的运行状态与报错信息. 具体是在c程序中调用ca_put()来写入这些PV. 实现上非常不优雅, 不理解为什么非要用CA. 最大的优点也许就是可以用单独一个ioc来收集所有使用autosave的ioc的状态信息. 但真的有必要吗?

 1as-SR_heartbeat
 2as-SR_i_am_alive
 3as-SR_deadIfZero
 4as-SR_disable
 5as-SR_disableMaxSecs
 6as-SR_rebootStatus
 7as-SR_status
 8as-SR_recentlyStr
 9as-SR_rebootStatusStr
10as-SR_rebootTime
11as-SR_statusStr
12as-SR_0_State * 8
13as-SR_0_Status * 8
14as-SR_0_StatusStr * 8
15as-SR_0_Name * 8
16as-SR_0_Time * 8

Q: sav文件, 默认生成5个(setting.sav, setting.sav0, setting.sav1, setting.sav2, setting.savB), 的创建逻辑与restore时的选择逻辑是什么?

A: TODO

其它

autosaveBuild

比如有savvy.db, 里面定义了若干record, 又有savvy_pass1.req文件, 这样在st.cmd中就需要用两行命令:

1dbLoadRecords("/path/to/savvy.db", "P=xxx")
2create_monitor_set("savvy_pass1.req", 30, "P=xxx")
3# 或者, 这样写
4# create_monitor_set("auto_settings.req", 30, "P=xxx")
5# 其中auto_settings.req文件中包含:
6# file savvy_pass1.req P=xxx

这就导致如果多组(db, req)文件对, 要修改的话就很容易出错.

可以使用这条命令: autosaveBuild("built_settings.req", "_pass1.req", 1) 这样dbLoadRecords($(db_name).db)命令调用后, autosave会自动搜索$(db_name)_pass1.req, 然后找到的话, 把req文件加入到built_settings.req文件中. 最后只需要处理built_settings.req文件就可以.

asVerify

 1$ bin/linux-x86_64/asVerify -h
 2usage: asVerify [-vr] <autosave_file>
 3         -v (verbose) causes all PV's to be printed out
 4             Otherwise, only PV's whose values differ are printed.
 5         -r (restore_file) causes restore files named
 6            '<autosave_file>.asVerify' and '...B'to be written.
 7         -d (debug) increment debug level by one.
 8         -rv (or -vr) does both
 9examples:
10    asVerify auto_settings.sav
11        (reports only PVs whose values differ from saved values)
12    asVerify -v auto_settings.sav
13        (reports all PVs, marking differences with '***'.)
14    asVerify -vr auto_settings.sav
15        (reports all PVs, and writes a restore file.)
16    asVerify auto_settings.sav
17    caput <myStatusPV> $?
18        (writes number of differences found to a PV.)
19
20NOTE: For the purpose of writing a restore file, you can specify a .req
21file (or any file that contains PV names, one per line) instead of a
22.sav file.  However, this program will misunderstand any 'file' commands
23that occur in a .req file.  (It will look for a PV named 'file'.)