Skip to content

Support alarm.*_ALARM in mbb{In,Out} #34

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Aug 31, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions docs/reference/api.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
6 changes: 6 additions & 0 deletions softioc/builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,13 +62,19 @@ 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 <prefix>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):
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
# zip() silently ignores extra values in options, so explicitly check length
assert len(options) <= 16, "May not specify more than 16 enum values"
Expand Down
6 changes: 1 addition & 5 deletions tests/expected_records.db
Original file line number Diff line number Diff line change
@@ -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")
Expand Down Expand Up @@ -73,6 +68,7 @@ record(mbbi, "TS-DI-TEST-01:MBBI")
field(TWSV, "MINOR")
field(TWVL, "2")
field(ZRST, "One")
field(ZRSV, "MAJOR")
field(ZRVL, "0")
}

Expand Down
6 changes: 4 additions & 2 deletions tests/sim_records.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

from epicsdbbuilder import GetRecordNames, WriteRecords

from softioc import softioc
from softioc import softioc, alarm
from softioc.builder import *

import numpy
Expand All @@ -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(
Expand Down
2 changes: 1 addition & 1 deletion tests/test_records.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ 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()

def test_enum_length_restriction():
with pytest.raises(AssertionError):
Expand Down