Skip to content

Commit

Permalink
add VME vector handling
Browse files Browse the repository at this point in the history
  • Loading branch information
gilesknap committed Jan 14, 2025
1 parent 154b57a commit 897a4a1
Show file tree
Hide file tree
Showing 7 changed files with 105 additions and 1 deletion.
11 changes: 11 additions & 0 deletions src/builder2ibek/convert.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,17 @@ def do_one_element(element: Element, ioc: Generic_IOC):

entity.type = f"{info.yaml_component}.{element.name}"
new_xml = info.handler(entity, element.name, ioc)
# if the handler added some new entities add them into the IOC
extras = entity.get_extra_entities()
if extras:
for extra_entity in extras:
ioc.entities.append(extra_entity)
# move the new entity to after these extras at it is likely to depend on them
ioc.entities.remove(entity)
ioc.entities.append(entity)

# if the handler returns a new XML string, parse it and dispatch the
# new entities it defines to the correct handler
if new_xml:
new_builder = Builder()
new_builder.load_string(new_xml)
Expand Down
20 changes: 20 additions & 0 deletions src/builder2ibek/converters/DLS8515.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
from builder2ibek.converters.epics_base import add_interrupt_vector
from builder2ibek.converters.globalHandler import globalHandler
from builder2ibek.types import Entity, Generic_IOC

xml_component = "DLS8515"


@globalHandler
def handler(entity: Entity, entity_type: str, ioc: Generic_IOC):
"""
XML to YAML specialist convertor function for the pvlogging support module
"""

if entity_type == "DLS8515":
vec = add_interrupt_vector()
entity.add_entity(vec)
entity.interrupt_vector = vec.name

elif entity_type == "DLS8516":
entity.remove("name")
4 changes: 4 additions & 0 deletions src/builder2ibek/converters/autosave.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,7 @@ def handler(entity: Entity, entity_type: str, ioc: Generic_IOC):
entity.remove("name")
entity.remove("path")
entity.remove("server")
entity.remove("skip_1")
entity.remove("vx_gid")
entity.remove("vx_uid")
entity.debug = bool(entity.debug)
23 changes: 23 additions & 0 deletions src/builder2ibek/converters/epics_base.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,29 @@
from dataclasses import asdict, dataclass, field
from typing import ClassVar

from builder2ibek.converters.globalHandler import globalHandler
from builder2ibek.types import Entity, Generic_IOC

xml_component = "EPICS_BASE"
yaml_component = "epics"


@dataclass
class InterruptVector:
_interrupt_vector: ClassVar[int] = 1
type: str = "epics.InterruptVectorVME"
name: str = field(default_factory=lambda: f"Vec{InterruptVector._interrupt_vector}")

def __post_init__(self):
InterruptVector._interrupt_vector += 1


# a decorator that will be used to add an interrupt vector to the entity
def add_interrupt_vector():
vec = Entity(asdict(InterruptVector()))
return vec


@globalHandler
def handler(entity: Entity, entity_type: str, ioc: Generic_IOC):
if entity_type == "EpicsEnvSet":
Expand All @@ -24,6 +43,10 @@ def handler(entity: Entity, entity_type: str, ioc: Generic_IOC):
else:
entity.type = "epics.StartupCommand"
entity.remove("post_init")
if entity.at_end in ["true", "True"]:
# TODO get the converter to do this for us
print(f"Warning: {entity} has at_end==true MOVE IT TO THE END of ioc.yaml")
entity.remove("at_end")

elif entity_type == "dbpf":
entity.type = "epics.Dbpf"
Expand Down
17 changes: 17 additions & 0 deletions src/builder2ibek/converters/ipac.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
from builder2ibek.converters.epics_base import add_interrupt_vector
from builder2ibek.converters.globalHandler import globalHandler
from builder2ibek.types import Entity, Generic_IOC

xml_component = "ipac"


@globalHandler
def handler(entity: Entity, entity_type: str, ioc: Generic_IOC):
"""
XML to YAML specialist convertor function for the pvlogging support module
"""

if entity_type == "Hy8002":
vec = add_interrupt_vector()
entity.add_entity(vec)
entity.interrupt_vector = vec.name
17 changes: 17 additions & 0 deletions src/builder2ibek/converters/mrfTiming.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
from builder2ibek.converters.epics_base import add_interrupt_vector
from builder2ibek.converters.globalHandler import globalHandler
from builder2ibek.types import Entity, Generic_IOC

xml_component = "mrfTiming"


@globalHandler
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
if entity_type == "EventReceiverPMC":
vec = add_interrupt_vector()
entity.add_entity(vec)
14 changes: 13 additions & 1 deletion src/builder2ibek/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
Dataclasses for representing XML and YAML in memory
"""

from dataclasses import dataclass
from dataclasses import dataclass, field
from pathlib import Path
from typing import Any

Expand All @@ -19,6 +19,12 @@ class Entity(dict[str, Any]):
in the convertors package easier to type and read
"""

_extra_entities: list["Entity"]

def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
Entity._extra_entities = []

def __getattr__(self, __name: str) -> Any:
if __name in self:
return self[__name]
Expand All @@ -36,6 +42,12 @@ def rename(self, attr: str, new: str):
self[new] = self[attr]
del self[attr]

def add_entity(self, entity: "Entity"):
self._extra_entities.append(entity)

def get_extra_entities(self):
return self._extra_entities

def delete_me(self):
self.__command__ = "delete"

Expand Down

0 comments on commit 897a4a1

Please sign in to comment.