Skip to content

Commit 02c5671

Browse files
committed
Add initial devsta generation prototype
1 parent 2b20179 commit 02c5671

File tree

6 files changed

+198
-0
lines changed

6 files changed

+198
-0
lines changed

example-synoptic/b23-services/synoptic/create_gui.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,11 +133,16 @@ components:
133133

134134
M2:
135135
prefix: FE23B-OP-MR-02
136+
devsta:
137+
- FE23B-OP-MR-02:MOTORSTA
136138

137139
M3:
138140
prefix: BL23B-OP-MR-03
139141
extras:
140142
- BL23B-MO-PMAC-01
143+
devsta:
144+
- BL23B-OP-MR-03:MOTORSTA
145+
- BL23B-MO-PMAC-01:MOTORSTA
141146

142147
# ----- MOD -----
143148

pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ dependencies = [
2626
"lxml>=5.4.0",
2727
"typer>=0.16.0",
2828
"rich>=14.1.0",
29+
"softioc>=4.6.1",
2930
]
3031
scripts = { create-gui = "techui_builder.__main__:app" }
3132

src/techui_builder/__main__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,7 @@ def main(
152152

153153
gui.setup()
154154
gui.generate_screens()
155+
gui.write_devsta_pvs()
155156

156157
LOGGER.info(f"Screens generated for {gui.beamline.dom}.")
157158

src/techui_builder/builder.py

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,10 @@
66
from typing import Any
77

88
import yaml
9+
from epicsdbbuilder.recordbase import Record
910
from lxml import etree, objectify
1011
from lxml.objectify import ObjectifiedElement
12+
from softioc.builder import records
1113

1214
from techui_builder.generate import Generator
1315
from techui_builder.objects import Beamline, Component, Entity
@@ -45,6 +47,7 @@ class Builder:
4547
entities: defaultdict[str, list[Entity]] = field(
4648
default_factory=lambda: defaultdict(list), init=False
4749
)
50+
devsta_pvs: dict[str, Record] = field(default_factory=dict, init=False)
4851
_services_dir: Path = field(init=False, repr=False)
4952
_gui_map: dict = field(init=False, repr=False)
5053
_write_directory: Path = field(default=Path("data"), init=False, repr=False)
@@ -79,6 +82,39 @@ def setup(self):
7982
"""Run intial setup, e.g. extracting entries from service ioc.yaml."""
8083
self._extract_services()
8184

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+
82118
def _extract_services(self):
83119
"""
84120
Finds the services folders in the services directory
@@ -134,6 +170,10 @@ def generate_screens(self):
134170
# any extras defined
135171
for component in self.components:
136172
screen_entities: list[Entity] = []
173+
174+
if component.devsta is not None:
175+
self._create_devsta_pv(component.prefix, component.devsta)
176+
137177
# ONLY IF there is a matching component and entity, generate a screen
138178
if component.prefix in self.entities.keys():
139179
screen_entities.extend(self.entities[component.prefix])

src/techui_builder/objects.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ class Component:
2323
prefix: str
2424
desc: str | None = field(default=None)
2525
file: str | None = field(default=None)
26+
devsta: list[str] | None = field(default=None)
2627
extras: list[str] | None = field(default=None)
2728

2829
def __post_init__(self):

0 commit comments

Comments
 (0)