From d5c2726ded9c4ede0eb2aa1dafe791b9a61ef59b Mon Sep 17 00:00:00 2001 From: Giles Knap Date: Thu, 16 Jan 2025 11:59:50 +0000 Subject: [PATCH] first pass of dlsPLC conversions --- src/builder2ibek/converters/Hy8401ip.py | 5 +-- src/builder2ibek/converters/Hy8402ip.py | 5 +-- src/builder2ibek/converters/IOCInfo.py | 14 ++++++++ src/builder2ibek/converters/digitelMpc.py | 2 ++ src/builder2ibek/converters/interlock.py | 24 +++++++++++++ src/builder2ibek/converters/mks937a.py | 2 +- src/builder2ibek/converters/mks937b.py | 2 +- src/builder2ibek/converters/mrfTiming.py | 2 +- src/builder2ibek/converters/rga.py | 14 ++++++++ src/builder2ibek/converters/vacuumSpace.py | 15 ++++++++ src/builder2ibek/converters/vacuumValve.py | 42 ++++++++++++++++++++++ src/builder2ibek/utils.py | 15 ++++++++ 12 files changed, 131 insertions(+), 11 deletions(-) create mode 100644 src/builder2ibek/converters/IOCInfo.py create mode 100644 src/builder2ibek/converters/interlock.py create mode 100644 src/builder2ibek/converters/rga.py create mode 100644 src/builder2ibek/converters/vacuumSpace.py create mode 100644 src/builder2ibek/converters/vacuumValve.py diff --git a/src/builder2ibek/converters/Hy8401ip.py b/src/builder2ibek/converters/Hy8401ip.py index 8e3e92e..d0b3bf0 100644 --- a/src/builder2ibek/converters/Hy8401ip.py +++ b/src/builder2ibek/converters/Hy8401ip.py @@ -1,4 +1,3 @@ -from builder2ibek.converters.epics_base import add_interrupt_vector from builder2ibek.converters.globalHandler import globalHandler from builder2ibek.types import Entity, Generic_IOC @@ -12,6 +11,4 @@ def handler(entity: Entity, entity_type: str, ioc: Generic_IOC): """ if entity_type == "Hy8401": - vec = add_interrupt_vector() - entity.add_entity(vec) - entity.interrupt_vector = vec.name + entity.remove("name") diff --git a/src/builder2ibek/converters/Hy8402ip.py b/src/builder2ibek/converters/Hy8402ip.py index 8176876..7eea201 100644 --- a/src/builder2ibek/converters/Hy8402ip.py +++ b/src/builder2ibek/converters/Hy8402ip.py @@ -1,4 +1,3 @@ -from builder2ibek.converters.epics_base import add_interrupt_vector from builder2ibek.converters.globalHandler import globalHandler from builder2ibek.types import Entity, Generic_IOC @@ -12,6 +11,4 @@ def handler(entity: Entity, entity_type: str, ioc: Generic_IOC): """ if entity_type == "Hy8402": - vec = add_interrupt_vector() - entity.add_entity(vec) - entity.interrupt_vector = vec.name + entity.remove("name") diff --git a/src/builder2ibek/converters/IOCInfo.py b/src/builder2ibek/converters/IOCInfo.py new file mode 100644 index 0000000..47ba7f0 --- /dev/null +++ b/src/builder2ibek/converters/IOCInfo.py @@ -0,0 +1,14 @@ +from builder2ibek.converters.globalHandler import globalHandler +from builder2ibek.types import Entity, Generic_IOC + +xml_component = "IOCinfo" + + +@globalHandler +def handler(entity: Entity, entity_type: str, ioc: Generic_IOC): + """ + XML to YAML specialist convertor function for the IOCInfo support module + """ + + if entity_type == "IOCinfo": + entity.remove("name") diff --git a/src/builder2ibek/converters/digitelMpc.py b/src/builder2ibek/converters/digitelMpc.py index 6285666..033d43b 100644 --- a/src/builder2ibek/converters/digitelMpc.py +++ b/src/builder2ibek/converters/digitelMpc.py @@ -14,3 +14,5 @@ def handler(entity: Entity, entity_type: str, ioc: Generic_IOC): unit = int(entity.get("unit")) # type: ignore unit_enum = f"{unit:02d}" entity.unit = unit_enum + elif entity_type in ["digitelMpcIonp", "digitelMpcIonpGroup"]: + entity.remove("name") diff --git a/src/builder2ibek/converters/interlock.py b/src/builder2ibek/converters/interlock.py new file mode 100644 index 0000000..0808575 --- /dev/null +++ b/src/builder2ibek/converters/interlock.py @@ -0,0 +1,24 @@ +from builder2ibek.converters.globalHandler import globalHandler +from builder2ibek.types import Entity, Generic_IOC +from builder2ibek.utils import hex_to_int + +xml_component = "interlock" + +# records the port names of the read100 entities keyed by name +read100Objects = {} + + +@globalHandler +def handler(entity: Entity, entity_type: str, ioc: Generic_IOC): + """ + XML to YAML specialist convertor function for the interlock support module + + This module gets converted to dlsPLC equivalents + """ + + if entity_type == "interlock": + entity.type = "dlsPLC.interlock" + entity.addr = str(entity.addr) # TODO make int in dlsPLC.ibek.support.yaml + # entity.remove("name") + + hex_to_int(entity, "ilk") diff --git a/src/builder2ibek/converters/mks937a.py b/src/builder2ibek/converters/mks937a.py index 2c20b09..2bfb06b 100644 --- a/src/builder2ibek/converters/mks937a.py +++ b/src/builder2ibek/converters/mks937a.py @@ -10,5 +10,5 @@ def handler(entity: Entity, entity_type: str, ioc: Generic_IOC): XML to YAML specialist convertor function for the mks937a support module """ # remove GUI only parameters (except on mks937aGauge which uses it for object ref) - if entity_type != "mks937aGauge": + if entity_type not in ["mks937aGauge", "mks937a"]: entity.remove("name") diff --git a/src/builder2ibek/converters/mks937b.py b/src/builder2ibek/converters/mks937b.py index 560be5b..892ab82 100644 --- a/src/builder2ibek/converters/mks937b.py +++ b/src/builder2ibek/converters/mks937b.py @@ -11,5 +11,5 @@ def handler(entity: Entity, entity_type: str, ioc: Generic_IOC): """ # remove GUI only parameters (except those that use name for object ref) - if entity_type not in ["mks937bGauge", "mks937bImg"]: + if entity_type not in ["mks937bGauge", "mks937bImg", "mks937b", "mks937bPirg"]: entity.remove("name") diff --git a/src/builder2ibek/converters/mrfTiming.py b/src/builder2ibek/converters/mrfTiming.py index 74bc371..580c129 100644 --- a/src/builder2ibek/converters/mrfTiming.py +++ b/src/builder2ibek/converters/mrfTiming.py @@ -11,7 +11,7 @@ def handler(entity: Entity, entity_type: str, ioc: Generic_IOC): XML to YAML specialist convertor function for the pvlogging support module """ - # TODO mrfTiming not yet implemented - does it really need a irq + # TODO mrfTiming not yet implemented - does it really need a irq? if entity_type == "EventReceiverPMC": vec = add_interrupt_vector() entity.add_entity(vec) diff --git a/src/builder2ibek/converters/rga.py b/src/builder2ibek/converters/rga.py new file mode 100644 index 0000000..84c1603 --- /dev/null +++ b/src/builder2ibek/converters/rga.py @@ -0,0 +1,14 @@ +from builder2ibek.converters.globalHandler import globalHandler +from builder2ibek.types import Entity, Generic_IOC + +xml_component = "rga" + + +@globalHandler +def handler(entity: Entity, entity_type: str, ioc: Generic_IOC): + """ + XML to YAML specialist convertor function for the rga support module + """ + + if entity_type == "rga": + entity.remove("name") diff --git a/src/builder2ibek/converters/vacuumSpace.py b/src/builder2ibek/converters/vacuumSpace.py new file mode 100644 index 0000000..898da56 --- /dev/null +++ b/src/builder2ibek/converters/vacuumSpace.py @@ -0,0 +1,15 @@ +from builder2ibek.converters.globalHandler import globalHandler +from builder2ibek.types import Entity, Generic_IOC + +xml_component = "vacuumSpace" + + +@globalHandler +def handler(entity: Entity, entity_type: str, ioc: Generic_IOC): + """ + XML to YAML specialist convertor function for the vacuumSpace support module + """ + + # remove GUI only parameters (except those that use name for object ref) + if entity_type == "spaceTemplate": + entity.remove("name") diff --git a/src/builder2ibek/converters/vacuumValve.py b/src/builder2ibek/converters/vacuumValve.py new file mode 100644 index 0000000..c5bc877 --- /dev/null +++ b/src/builder2ibek/converters/vacuumValve.py @@ -0,0 +1,42 @@ +from builder2ibek.converters.globalHandler import globalHandler +from builder2ibek.types import Entity, Generic_IOC + +xml_component = "vacuumValve" + +# records the port names of the read100 entities keyed by name +read100Objects = {} + + +@globalHandler +def handler(entity: Entity, entity_type: str, ioc: Generic_IOC): + """ + XML to YAML specialist convertor function for the vacuumValve support module + + This module gets converted to dlsPLC equivalents + """ + + if entity_type == "vacuumValveRead": + # record the port name of this entity + read100Objects[entity.name] = entity.port + + entity.type = "dlsPLC.read100" + entity.century = "0" # TODO make int in dlsPLC.ibek.support.yaml + entity.remove("name") + + if entity_type == "vacuumValveRead2": + # record the port name of this entity + read100Objects[entity.name] = entity.port + + # TODO need an example to work out how to do this, we probably need + # to record in read100Objects, which centry this entity is associated + # WARNING: interlock.interlock will need to know about this (I think) + raise NotImplementedError("vacuumValveRead2 not implemented") + + elif entity_type in ["vacuumValve", "vacuumValve_callback"]: + entity.type = "dlsPLC.vacValve" + + entity.rename("crate", "vlvcc") + entity.addr = str(int(entity.valve) * 10) # TODO should be int + entity.remove("valve") + + entity.port = read100Objects[entity.vlvcc] diff --git a/src/builder2ibek/utils.py b/src/builder2ibek/utils.py index ac9686e..514f251 100644 --- a/src/builder2ibek/utils.py +++ b/src/builder2ibek/utils.py @@ -4,6 +4,8 @@ from typing import Any +from builder2ibek.types import Entity + def make_bool(value: Any): value = str(value) @@ -15,3 +17,16 @@ def make_bool(value: Any): raise (ValueError(f"Cannot convert {value} to a boolean")) return result + + +def hex_to_int(entity: Entity, prefix: str): + """ + Loop through A-F suffixes on the prefix supplied. + If the entity has a key with that prefix-suffix, rename it to the + # integer equivalent + """ + for n in range(10, 16): + hex_key = f"{prefix}{hex(n)[2:].upper()}" + print(hex_key) + if hex_key in entity: + entity.rename(hex_key, f"{prefix}{n}")