Skip to content

Commit c95035a

Browse files
authored
Support alarm.*_ALARM in mbb{In,Out} (#34)
Support alarm.*_ALARM in mbb{In,Out}
1 parent 26b4bfb commit c95035a

File tree

5 files changed

+18
-10
lines changed

5 files changed

+18
-10
lines changed

docs/reference/api.rst

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -273,8 +273,12 @@ All functions return a wrapped `ProcessDeviceSupportIn` or
273273

274274
status = mbbIn('STATUS',
275275
'OK',
276-
('FAILING', "MINOR"),
277-
('FAILED', "MAJOR"))
276+
('FAILING', 'MINOR'),
277+
('FAILED', 'MAJOR'),
278+
('NOT CONNECTED', 'INVALID'))
279+
280+
Severities can also be assigned using the `softioc.alarm` numerical
281+
severities if preferred.
278282

279283
Numerical values are assigned to options sequentially from 0 to 15 and
280284
cannot be overridden.

softioc/builder.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,13 +62,19 @@ def longOut(name, DRVL=None, DRVH=None, EGU=None, **fields):
6262
'ZR', 'ON', 'TW', 'TH', 'FR', 'FV', 'SX', 'SV', # 0-7
6363
'EI', 'NI', 'TE', 'EL', 'TV', 'TT', 'FT', 'FF'] # 8-15
6464

65+
# All the severity strings supported by <prefix>SV
66+
_severityStrings = ["NO_ALARM", "MINOR", "MAJOR", "INVALID"]
67+
6568
# Converts a list of (option [,severity]) values or tuples into field settings
6669
# suitable for mbbi and mbbo records.
6770
def _process_mbb_values(options, fields):
6871
def process_value(prefix, value, option, severity=None):
6972
fields[prefix + 'ST'] = option
7073
fields[prefix + 'VL'] = value
7174
if severity:
75+
if isinstance(severity, int):
76+
# Map alarm.MINOR_ALARM -> "MINOR"
77+
severity = _severityStrings[severity]
7278
fields[prefix + 'SV'] = severity
7379
# zip() silently ignores extra values in options, so explicitly check length
7480
assert len(options) <= 16, "May not specify more than 16 enum values"

tests/expected_records.db

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,3 @@
1-
# This file was automatically generated on Fri 13 Aug 2021 16:49:03 BST.
2-
#
3-
# *** Please do not edit this file: edit the source file instead. ***
4-
#
5-
61
record(ai, "TS-DI-TEST-01:AI")
72
{
83
field(DTYP, "Python")
@@ -73,6 +68,7 @@ record(mbbi, "TS-DI-TEST-01:MBBI")
7368
field(TWSV, "MINOR")
7469
field(TWVL, "2")
7570
field(ZRST, "One")
71+
field(ZRSV, "MAJOR")
7672
field(ZRVL, "0")
7773
}
7874

tests/sim_records.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
from epicsdbbuilder import GetRecordNames, WriteRecords
66

7-
from softioc import softioc
7+
from softioc import softioc, alarm
88
from softioc.builder import *
99

1010
import numpy
@@ -26,7 +26,9 @@ def on_update_name(value, name):
2626
t_boolin = boolIn('BOOLIN', 'True', 'False', initial_value=False)
2727
t_longin = longIn('LONGIN', initial_value=33)
2828
t_stringin = stringIn('STRINGIN', initial_value="Testing string")
29-
t_mbbi = mbbIn('MBBI', 'One', 'Two', ('Three', "MINOR"), initial_value=2)
29+
t_mbbi = mbbIn(
30+
'MBBI', ('One', alarm.MAJOR_ALARM), 'Two', ('Three', "MINOR"),
31+
initial_value=2)
3032

3133
t_ao = aOut('AO', initial_value=12.45, on_update_name=on_update_name)
3234
t_boolout = boolOut(

tests/test_records.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ def test_records(tmp_path):
1010
path = str(tmp_path / "records.db")
1111
builder.WriteRecords(path)
1212
expected = os.path.join(os.path.dirname(__file__), "expected_records.db")
13-
assert open(path).readlines()[4:] == open(expected).readlines()[4:]
13+
assert open(path).readlines()[5:] == open(expected).readlines()
1414

1515
def test_enum_length_restriction():
1616
with pytest.raises(AssertionError):

0 commit comments

Comments
 (0)