Skip to content
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
9 changes: 9 additions & 0 deletions src/server_common/schema/blocks.xsd
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,11 @@
<xs:element ref="blk:log_deadband" minOccurs="0"/>
<xs:element ref="blk:set_block" minOccurs="0"/>
<xs:element ref="blk:set_block_val" minOccurs="0"/>
<xs:element ref="blk:alarm_enabled" minOccurs="0"/>
<xs:element ref="blk:alarm_latched" minOccurs="0"/>
<xs:element ref="blk:alarm_delay" minOccurs="0"/>
<xs:element ref="blk:alarm_guidance" minOccurs="0"/>

</xs:sequence>
</xs:complexType>
</xs:element>
Expand All @@ -42,4 +47,8 @@
<xs:element name="log_deadband" type="xs:double"/>
<xs:element name="set_block" type="xs:string"/>
<xs:element name="set_block_val" type="xs:string"/>
<xs:element name="alarm_enabled" type="xs:string"/>
<xs:element name="alarm_latched" type="xs:string"/>
<xs:element name="alarm_delay" type="xs:double"/>
<xs:element name="alarm_guidance" type="xs:string"/>
</xs:schema>
33 changes: 24 additions & 9 deletions src/server_common/utilities.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
from server_common.common_exceptions import MaxAttemptsExceededException
from server_common.loggers.logger import Logger

# ruff: noqa: ANN001, ANN201, ANN002, ANN003, ANN202, E721
# Default to base class - does not actually log anything
LOGGER = Logger()
_LOGGER_LOCK = threading.RLock() # To prevent message interleaving between different threads.
Expand Down Expand Up @@ -72,8 +73,8 @@ def print_and_log(message, severity=SEVERITY.INFO, src="BLOCKSVR"):

Args:
message (string|exception): The message to log
severity (string, optional): Gives the severity of the message. Expected serverities are MAJOR, MINOR and INFO.
Default severity is INFO.
severity (string, optional): Gives the severity of the message. Expected serverities are
MAJOR, MINOR and INFO. Default severity is INFO.
src (string, optional): Gives the source of the message. Default source is BLOCKSVR.
"""
with _LOGGER_LOCK:
Expand Down Expand Up @@ -115,7 +116,8 @@ def dehex_and_decompress(value):


def dehex_and_decompress_waveform(value):
"""Decompresses the inputted waveform, assuming it is a array of integers representing characters (null terminated).
"""Decompresses the inputted waveform, assuming it is a array of integers
representing characters (null terminated).

Args:
value (list[int]): The string to be decompressed
Expand Down Expand Up @@ -181,11 +183,11 @@ def value_list_to_xml(value_list, grp, group_tag, item_tag):
"""Converts a list of values to corresponding xml.

Args:
value_list (dist[str, dict[object, object]]): The dictionary of names and their values, values are in turn a
dictonary of names and value {name: {parameter : value, parameter : value}}
value_list (dist[str, dict[object, object]]): The dictionary of names and their values,
values are in turn a dictonary of names and value {name:{parameter:value,parameter:value}}
grp (ElementTree.SubElement): The SubElement object to append the list on to
group_tag (string): The tag that corresponds to the group for the items given in the list e.g. macros
item_tag (string): The tag that corresponds to each item in the list e.g. macro
group_tag (string): The tag that corresponds to the group for the items given in the list
e.g. macros item_tag (string): The tag that corresponds to each item in the list e.g. macro
"""
xml_list = ElementTree.SubElement(grp, group_tag)
if len(value_list) > 0:
Expand Down Expand Up @@ -218,7 +220,7 @@ def create_pv_name(name, current_pvs, default_pv, limit=6, allow_colon=False):
current_pvs (list): List of already allocated pvs
default_pv (string): Basis for the PV if name is unreasonable, must be a valid PV name
limit (integer): Character limit for the PV
allow_colon (bool): If True, pv name is allowed to contain colons; if False, remove the colons
allow_colon (bool): If True,pv name is allowed to contain colons;if False,remove the colons

Returns:
string : A valid PV
Expand Down Expand Up @@ -344,7 +346,8 @@ def remove_from_end(string, text_to_remove):

def lowercase_and_make_unique(in_list):
"""
Takes a collection of strings, and returns it with all strings lowercased and with duplicates removed.
Takes a collection of strings, and returns it with all strings lowercased and with duplicates
removed.

Args:
in_list (List[str]): the collection of strings to operate on
Expand All @@ -371,3 +374,15 @@ def parse_date_time_arg_exit_on_fail(date_arg, error_code=1):
except (ValueError, TypeError) as ex:
print(f"Can not interpret date '{date_arg}' error: {ex}")
exit(error_code)


def dehex_and_decompress_waveform_value(value):
"""Decompresses the inputted waveform, assuming it is available as string.

Args:
value (str): The string to be decompressed

Returns:
str : A decompressed and unhexed version of the input string
"""
return zlib.decompress(binascii.unhexlify(value))
Loading