From 083d0f53ae3deeed600bb26ad0eb0b79a501406a Mon Sep 17 00:00:00 2001 From: Tom Cobb Date: Tue, 31 Aug 2021 09:17:44 +0100 Subject: [PATCH 1/2] Support alarm.*_ALARM in mbb{In,Out} --- docs/reference/api.rst | 8 ++++++-- softioc/builder.py | 6 ++++++ tests/expected_records.db | 5 +++-- tests/sim_records.py | 6 ++++-- 4 files changed, 19 insertions(+), 6 deletions(-) diff --git a/docs/reference/api.rst b/docs/reference/api.rst index e40ef2cc..7efab9e0 100644 --- a/docs/reference/api.rst +++ b/docs/reference/api.rst @@ -273,8 +273,12 @@ All functions return a wrapped `ProcessDeviceSupportIn` or status = mbbIn('STATUS', 'OK', - ('FAILING', "MINOR"), - ('FAILED', "MAJOR")) + ('FAILING', 'MINOR'), + ('FAILED', 'MAJOR'), + ('NOT CONNECTED', 'INVALID')) + + Severities can also be assigned using the `softioc.alarm` numerical + severities if preferred. Numerical values are assigned to options sequentially from 0 to 15 and cannot be overridden. diff --git a/softioc/builder.py b/softioc/builder.py index 964d651e..d2c3058b 100644 --- a/softioc/builder.py +++ b/softioc/builder.py @@ -62,6 +62,9 @@ def longOut(name, DRVL=None, DRVH=None, EGU=None, **fields): 'ZR', 'ON', 'TW', 'TH', 'FR', 'FV', 'SX', 'SV', # 0-7 'EI', 'NI', 'TE', 'EL', 'TV', 'TT', 'FT', 'FF'] # 8-15 +# All the severity strings supported by SV +_severityStrings = ["NO_ALARM", "MINOR", "MAJOR", "INVALID"] + # Converts a list of (option [,severity]) values or tuples into field settings # suitable for mbbi and mbbo records. def _process_mbb_values(options, fields): @@ -69,6 +72,9 @@ def process_value(prefix, value, option, severity=None): fields[prefix + 'ST'] = option fields[prefix + 'VL'] = value if severity: + if isinstance(severity, int): + # Map alarm.MINOR_ALARM -> "MINOR" + severity = _severityStrings[severity] fields[prefix + 'SV'] = severity for prefix, (value, option) in zip(_mbbPrefixes, enumerate(options)): if isinstance(option, tuple): diff --git a/tests/expected_records.db b/tests/expected_records.db index 290c5c82..360d672b 100644 --- a/tests/expected_records.db +++ b/tests/expected_records.db @@ -1,7 +1,7 @@ # This file was automatically generated on Fri 13 Aug 2021 16:49:03 BST. -# +# # *** Please do not edit this file: edit the source file instead. *** -# +# record(ai, "TS-DI-TEST-01:AI") { @@ -73,6 +73,7 @@ record(mbbi, "TS-DI-TEST-01:MBBI") field(TWSV, "MINOR") field(TWVL, "2") field(ZRST, "One") + field(ZRSV, "MAJOR") field(ZRVL, "0") } diff --git a/tests/sim_records.py b/tests/sim_records.py index 7bcd9861..3009e356 100644 --- a/tests/sim_records.py +++ b/tests/sim_records.py @@ -4,7 +4,7 @@ from epicsdbbuilder import GetRecordNames, WriteRecords -from softioc import softioc +from softioc import softioc, alarm from softioc.builder import * import numpy @@ -26,7 +26,9 @@ def on_update_name(value, name): t_boolin = boolIn('BOOLIN', 'True', 'False', initial_value=False) t_longin = longIn('LONGIN', initial_value=33) t_stringin = stringIn('STRINGIN', initial_value="Testing string") -t_mbbi = mbbIn('MBBI', 'One', 'Two', ('Three', "MINOR"), initial_value=2) +t_mbbi = mbbIn( + 'MBBI', ('One', alarm.MAJOR_ALARM), 'Two', ('Three', "MINOR"), + initial_value=2) t_ao = aOut('AO', initial_value=12.45, on_update_name=on_update_name) t_boolout = boolOut( From 28b5d1b1b55e63fa00bac2829ede630b18e63ebc Mon Sep 17 00:00:00 2001 From: Tom Cobb Date: Tue, 31 Aug 2021 09:27:40 +0100 Subject: [PATCH 2/2] Remove autogenerated header from test file --- tests/expected_records.db | 5 ----- tests/test_records.py | 2 +- 2 files changed, 1 insertion(+), 6 deletions(-) diff --git a/tests/expected_records.db b/tests/expected_records.db index 360d672b..61d383db 100644 --- a/tests/expected_records.db +++ b/tests/expected_records.db @@ -1,8 +1,3 @@ -# This file was automatically generated on Fri 13 Aug 2021 16:49:03 BST. -# -# *** Please do not edit this file: edit the source file instead. *** -# - record(ai, "TS-DI-TEST-01:AI") { field(DTYP, "Python") diff --git a/tests/test_records.py b/tests/test_records.py index a3778a5b..9fc1ac10 100644 --- a/tests/test_records.py +++ b/tests/test_records.py @@ -9,4 +9,4 @@ def test_records(tmp_path): path = str(tmp_path / "records.db") builder.WriteRecords(path) expected = os.path.join(os.path.dirname(__file__), "expected_records.db") - assert open(path).readlines()[4:] == open(expected).readlines()[4:] + assert open(path).readlines()[5:] == open(expected).readlines()