Skip to content
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

Remove SOFBMode from PS IOC #309

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
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
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
3.49.0
3.50.0
68 changes: 7 additions & 61 deletions as-ps/as_ps/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@
import numpy as _np
from pcaspy import Alarm as _Alarm, Severity as _Severity
from siriuspy.namesys import SiriusPVName as _SiriusPVName
from siriuspy.pwrsupply.bsmp.constants import UDC_MAX_NR_DEV as _UDC_MAX_NR_DEV
from siriuspy.pwrsupply.csdev import PSSOFB_MAX_NR_UDC as _PSSOFB_MAX_NR_UDC
from siriuspy.thread import LoopQueueThread as _LoopQueueThread
from siriuspy.util import get_last_commit_hash as _get_last_commit_hash, \
print_ioc_banner as _print_ioc_banner
Expand All @@ -21,37 +19,24 @@ class App:

_sleep_scan = 0.050 # [s]
_regexp_setpoint = _re.compile('^.*-(SP|Sel)$')
_sofb_value_length = _PSSOFB_MAX_NR_UDC * _UDC_MAX_NR_DEV

def __init__(self, driver, bbblist, dbset, prefix):
"""Init application."""
# --- init begin

self._driver = driver

# flag to indicate sofb processing is taking place
self._sofb_processing = False

# flag to indicate idff processing is taking place
self._idff_processing = False

# write operation queue
self._queue = _LoopQueueThread()
self._queue.start()

# counter of SOFBUpdate-Cmd write events
self._counter_sofbupdate_cmd = 0

# mapping device to bbb
self._bbblist = bbblist
# NOTE: change IOC to accept only one BBB !!!

sofbmode_pvname = self.bbblist[0].psnames[0] + ':SOFBMode-Sts'
if sofbmode_pvname in dbset[prefix]:
self._sofbmode_sts_pvname = sofbmode_pvname
else:
self._sofbmode_sts_pvname = None

idffmode_pvname = self.bbblist[0].psnames[0] + ':IDFFMode-Sts'
if idffmode_pvname in dbset[prefix]:
self._has_idffmode = True
Expand Down Expand Up @@ -118,10 +103,6 @@ def write(self, reason, value):
# 'IOC.write (beg)', 1e3*(_time.time() % 1)))
pvname = _SiriusPVName(reason)

if self._sofbmode_sts_pvname:
sofb_state = self.driver.getParam(self._sofbmode_sts_pvname)
else:
sofb_state = False
if self._has_idffmode:
pvname_idffmode_sts = pvname.substitute(propty='IDFFMode-Sts')
idff_state = self.driver.getParam(pvname_idffmode_sts)
Expand All @@ -137,24 +118,13 @@ def write(self, reason, value):
_log.info(strf.format(wstr, reason, str(value), ignorestr))
return

idff_or_sofb_state = sofb_state or idff_state
idff_nor_sofb_reason = 'SOFB' not in reason and 'IDFF' not in reason
if idff_or_sofb_state and idff_nor_sofb_reason:
ignorestr, wstr = (' (SOFB/IDFF Mode On)', 'W!')
if idff_state and 'IDFF' not in reason:
ignorestr, wstr = (' (IDFF Mode On)', 'W!')
else:
ignorestr, wstr = ('', 'W ')

strf = "[{:.2s}] - {:.32s} = {:.50s}{}"
if 'SOFBUpdate-Cmd' in reason:
self._counter_sofbupdate_cmd += 1
if self._counter_sofbupdate_cmd == 1000:
# prints SOFBUpdate-Cmd after 1000 events
ignorestr = ' (1000 events)'
_log.info(strf.format(wstr, reason, str(value), ignorestr))
self._counter_sofbupdate_cmd = 0
else:
# print all other write events
_log.info(strf.format(wstr, reason, str(value), ignorestr))
# print write events
_log.info(strf.format(wstr, reason, str(value), ignorestr))

# NOTE: This modified behaviour is to allow loading
# global_config to complete without artificial warning
Expand All @@ -172,8 +142,7 @@ def scan_bbb(self, bbb):
"""Scan BBB devices and update ioc epics DB."""
for devname in bbb.psnames:
# forcing scan everytime!
if not self._sofb_processing:
self.scan_device(bbb, devname, force_update=True)
self.scan_device(bbb, devname, force_update=True)

def scan_device(self, bbb, devname, force_update=False):
"""Scan BBB device and update ioc epics DB."""
Expand All @@ -200,16 +169,6 @@ def _create_bbb_dev_dict(self):
return dev2bbb, dev2conn, interval

def _write_operation(self, bbb, pvname, value):
# NOTE: check if using SiriusPVName subs alters efficiency
if pvname.endswith('SOFBCurrent-SP'):
# signal SOFB processing
status = self._check_write_sofb(pvname, value)
if not status:
strf = "[{:.2s}] - {:.32s} = {:.50s}"
_log.info(strf.format('W!', pvname, 'Invalid length!'))
return
self._sofb_processing = True

# process priority changed PVs
priority_pvs = bbb.write(pvname.device_name, pvname.propty, value)
for reason, val in priority_pvs.items():
Expand All @@ -220,25 +179,16 @@ def _write_operation(self, bbb, pvname, value):
reason, _Alarm.TIMEOUT_ALARM, _Severity.INVALID_ALARM)
self.driver.updatePV(reason)

# signal end of eventual SOFB processing
self._sofb_processing = False

# print('{:<30s} : {:>9.3f} ms'.format(
# 'IOC.write (end)', 1e3*(_time.time() % 1)))

def _check_write_immediately(self, reason, value):
"""Check if reason is immediately writeable."""
_ = value
# Accept *-SP and *-Sel right away (not *-Cmd !)
if not App._regexp_setpoint.match(reason):
return False
return self._check_write_sofb(reason, value)

def _check_write_sofb(self, reason, value):
if not reason.endswith('SOFBCurrent-SP'): # Use SiriusPVName ?
return True
value_len = 1 if not \
isinstance(value, (tuple, list, _np.ndarray)) else len(value)
return value_len == App._sofb_value_length
return True

def _update_ioc_database(
self, bbb, devname, dev_connected=True, force_update=False):
Expand All @@ -263,10 +213,6 @@ def _update_ioc_database(

for reason, new_value in data.items():

# if sofb processing abort update
if self._sofb_processing:
return

# set strength limits
for strename in strength_names:
if strename is not None and strename in reason:
Expand Down