|
6 | 6 | from typing import Any |
7 | 7 |
|
8 | 8 | import yaml |
| 9 | +from epicsdbbuilder.recordbase import Record |
9 | 10 | from lxml import etree, objectify |
10 | 11 | from lxml.objectify import ObjectifiedElement |
| 12 | +from softioc.builder import records |
11 | 13 |
|
12 | 14 | from techui_builder.generate import Generator |
13 | 15 | from techui_builder.objects import Beamline, Component, Entity |
@@ -45,6 +47,7 @@ class Builder: |
45 | 47 | entities: defaultdict[str, list[Entity]] = field( |
46 | 48 | default_factory=lambda: defaultdict(list), init=False |
47 | 49 | ) |
| 50 | + devsta_pvs: dict[str, Record] = field(default_factory=dict, init=False) |
48 | 51 | _services_dir: Path = field(init=False, repr=False) |
49 | 52 | _gui_map: dict = field(init=False, repr=False) |
50 | 53 | _write_directory: Path = field(default=Path("data"), init=False, repr=False) |
@@ -79,6 +82,39 @@ def setup(self): |
79 | 82 | """Run intial setup, e.g. extracting entries from service ioc.yaml.""" |
80 | 83 | self._extract_services() |
81 | 84 |
|
| 85 | + def _create_devsta_pv(self, prefix: str, inputs: list[str]): |
| 86 | + # Extract all input PVs, provided a default "" if not provided |
| 87 | + values = [(inputs[i] if i < len(inputs) else "") for i in range(12)] |
| 88 | + inpa, inpb, inpc, inpd, inpe, inpf, inpg, inph, inpi, inpj, inpk, inpl = values |
| 89 | + |
| 90 | + devsta_pv = records.calc( # pyright: ignore[reportAttributeAccessIssue] |
| 91 | + f"{prefix}:DEVSTA", |
| 92 | + CALC="(A|B|C|D|E|F|G|H|I|J|K|L)>0?1:0", |
| 93 | + SCAN="1 second", |
| 94 | + ACKT="NO", |
| 95 | + INPA=inpa, |
| 96 | + INPB=inpb, |
| 97 | + INPC=inpc, |
| 98 | + INPD=inpd, |
| 99 | + INPE=inpe, |
| 100 | + INPF=inpf, |
| 101 | + INPG=inpg, |
| 102 | + INPH=inph, |
| 103 | + INPI=inpi, |
| 104 | + INPJ=inpj, |
| 105 | + INPK=inpk, |
| 106 | + INPL=inpl, |
| 107 | + ) |
| 108 | + |
| 109 | + self.devsta_pvs[prefix] = devsta_pv |
| 110 | + |
| 111 | + def write_devsta_pvs(self): |
| 112 | + devsta_file = self._write_directory.parent.joinpath("config/ioc.db") |
| 113 | + with open(devsta_file, "w") as f: |
| 114 | + for dpv in self.devsta_pvs.values(): |
| 115 | + dpv.Print(f) |
| 116 | + # f.write(str(dpv)) |
| 117 | + |
82 | 118 | def _extract_services(self): |
83 | 119 | """ |
84 | 120 | Finds the services folders in the services directory |
@@ -134,6 +170,10 @@ def generate_screens(self): |
134 | 170 | # any extras defined |
135 | 171 | for component in self.components: |
136 | 172 | screen_entities: list[Entity] = [] |
| 173 | + |
| 174 | + if component.devsta is not None: |
| 175 | + self._create_devsta_pv(component.prefix, component.devsta) |
| 176 | + |
137 | 177 | # ONLY IF there is a matching component and entity, generate a screen |
138 | 178 | if component.prefix in self.entities.keys(): |
139 | 179 | screen_entities.extend(self.entities[component.prefix]) |
|
0 commit comments