Skip to content

Commit 46deaa7

Browse files
committed
Improve consistency of PVA and CA PV generation
1 parent 1fd8830 commit 46deaa7

File tree

4 files changed

+30
-33
lines changed

4 files changed

+30
-33
lines changed

docs/conf.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@
9494
("py:class", "fastcs.logging._graylog.GraylogStaticFields"),
9595
("py:class", "fastcs.logging._graylog.GraylogEnvFields"),
9696
("py:obj", "fastcs.launch.build_controller_api"),
97+
("py:obj", "fastcs.transport.epics.util.controller_pv_prefix"),
9798
("docutils", "fastcs.demo.controllers.TemperatureControllerSettings"),
9899
# TypeVar without docstrings still give warnings
99100
("py:class", "fastcs.datatypes.T_Numerical"),

src/fastcs/transport/epics/ca/ioc.py

Lines changed: 10 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
record_metadata_from_datatype,
2121
)
2222
from fastcs.transport.epics.options import EpicsIOCOptions
23+
from fastcs.transport.epics.util import controller_pv_prefix
2324
from fastcs.util import snake_to_pascal
2425

2526
EPICS_MAX_NAME_LENGTH = 60
@@ -111,27 +112,26 @@ def _add_sub_controller_pvi_info(pv_prefix: str, parent: ControllerAPI):
111112
parent: Controller to add PVI refs for
112113
113114
"""
114-
parent_pvi = ":".join([pv_prefix] + parent.path + ["PVI"])
115+
parent_pvi = f"{controller_pv_prefix(pv_prefix, parent)}:PVI"
115116

116117
for child in parent.sub_apis.values():
117-
child_pvi = ":".join([pv_prefix] + _controller_pv_prefix(child.path) + ["PVI"])
118+
child_pvi = f"{controller_pv_prefix(pv_prefix, child)}:PVI"
118119
child_name = child.path[-1].lower()
119120

120121
_add_pvi_info(child_pvi, parent_pvi, child_name)
121-
122122
_add_sub_controller_pvi_info(pv_prefix, child)
123123

124124

125125
def _create_and_link_attribute_pvs(
126126
root_pv_prefix: str, root_controller_api: ControllerAPI
127127
) -> None:
128128
for controller_api in root_controller_api.walk_api():
129-
path = controller_api.path
129+
pv_prefix = controller_pv_prefix(root_pv_prefix, controller_api)
130+
130131
for attr_name, attribute in controller_api.attributes.items():
131132
pv_name = snake_to_pascal(attr_name)
132-
pv_prefix = ":".join([root_pv_prefix] + _controller_pv_prefix(path))
133-
full_pv_name_length = len(f"{pv_prefix}:{pv_name}")
134133

134+
full_pv_name_length = len(f"{pv_prefix}:{pv_name}")
135135
if full_pv_name_length > EPICS_MAX_NAME_LENGTH:
136136
attribute.enabled = False
137137
print(
@@ -224,9 +224,7 @@ async def async_write_display(value: T):
224224

225225
record.set(cast_to_epics_type(attribute.datatype, value), process=False)
226226

227-
record = _make_record(
228-
f"{pv_prefix}:{pv_name}", attribute, on_update=on_update, out_record=True
229-
)
227+
record = _make_record(pv, attribute, on_update=on_update, out_record=True)
230228

231229
_add_attr_pvi_info(record, pv_prefix, attr_name, "w")
232230

@@ -237,10 +235,11 @@ def _create_and_link_command_pvs(
237235
root_pv_prefix: str, root_controller_api: ControllerAPI
238236
) -> None:
239237
for controller_api in root_controller_api.walk_api():
240-
path = controller_api.path
238+
pv_prefix = controller_pv_prefix(root_pv_prefix, controller_api)
239+
241240
for attr_name, method in controller_api.command_methods.items():
242241
pv_name = snake_to_pascal(attr_name)
243-
pv_prefix = ":".join([root_pv_prefix] + _controller_pv_prefix(path))
242+
244243
if len(f"{pv_prefix}:{pv_name}") > EPICS_MAX_NAME_LENGTH:
245244
print(
246245
f"Not creating PV for {attr_name} as full name would exceed"
@@ -302,7 +301,3 @@ def _add_attr_pvi_info(
302301
}
303302
},
304303
)
305-
306-
307-
def _controller_pv_prefix(controller_path: list[str]) -> list[str]:
308-
return [snake_to_pascal(node) for node in controller_path]

src/fastcs/transport/epics/pva/ioc.py

Lines changed: 13 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
from fastcs.attributes import Attribute, AttrR, AttrRW, AttrW
66
from fastcs.controller_api import ControllerAPI
7+
from fastcs.transport.epics.util import controller_pv_prefix
78
from fastcs.util import snake_to_pascal
89

910
from ._pv_handlers import (
@@ -26,12 +27,6 @@ def _attribute_to_access(attribute: Attribute) -> AccessModeType:
2627
raise ValueError(f"Unknown attribute type {type(attribute)}")
2728

2829

29-
def get_pv_name(pv_prefix: str, *attribute_names: str) -> str:
30-
"""Converts from an attribute name to a pv name."""
31-
pv_formatted = ":".join([snake_to_pascal(attr) for attr in attribute_names])
32-
return f"{pv_prefix}:{pv_formatted}" if pv_formatted else pv_prefix
33-
34-
3530
async def parse_attributes(
3631
root_pv_prefix: str, root_controller_api: ControllerAPI
3732
) -> list[StaticProvider]:
@@ -40,33 +35,33 @@ async def parse_attributes(
4035
provider = StaticProvider(root_pv_prefix)
4136

4237
for controller_api in root_controller_api.walk_api():
43-
pv_prefix = get_pv_name(root_pv_prefix, *controller_api.path)
38+
pv_prefix = controller_pv_prefix(root_pv_prefix, controller_api)
4439

4540
pvi_tree.add_sub_device(pv_prefix, controller_api.description)
4641

4742
for attr_name, attribute in controller_api.attributes.items():
48-
pv_name = get_pv_name(pv_prefix, attr_name)
43+
full_pv_name = f"{pv_prefix}:{snake_to_pascal(attr_name)}"
4944
match attribute:
5045
case AttrRW():
5146
attribute_pv = make_shared_write_pv(attribute)
5247
attribute_pv_rbv = make_shared_read_pv(attribute)
53-
provider.add(pv_name, attribute_pv)
54-
provider.add(f"{pv_name}_RBV", attribute_pv_rbv)
55-
pvi_tree.add_signal(pv_name, "rw")
48+
provider.add(f"{full_pv_name}", attribute_pv)
49+
provider.add(f"{full_pv_name}_RBV", attribute_pv_rbv)
50+
pvi_tree.add_signal(f"{full_pv_name}", "rw")
5651
case AttrR():
5752
attribute_pv = make_shared_read_pv(attribute)
58-
provider.add(pv_name, attribute_pv)
59-
pvi_tree.add_signal(pv_name, "r")
53+
provider.add(f"{full_pv_name}", attribute_pv)
54+
pvi_tree.add_signal(f"{full_pv_name}", "r")
6055
case AttrW():
6156
attribute_pv = make_shared_write_pv(attribute)
62-
provider.add(pv_name, attribute_pv)
63-
pvi_tree.add_signal(pv_name, "w")
57+
provider.add(f"{full_pv_name}", attribute_pv)
58+
pvi_tree.add_signal(f"{full_pv_name}", "w")
6459

6560
for attr_name, method in controller_api.command_methods.items():
66-
pv_name = get_pv_name(pv_prefix, attr_name)
61+
full_pv_name = f"{pv_prefix}:{snake_to_pascal(attr_name)}"
6762
command_pv = make_command_pv(method.fn)
68-
provider.add(pv_name, command_pv)
69-
pvi_tree.add_signal(pv_name, "x")
63+
provider.add(f"{full_pv_name}", command_pv)
64+
pvi_tree.add_signal(f"{full_pv_name}", "x")
7065

7166
return [provider, pvi_tree.make_provider()]
7267

src/fastcs/transport/epics/util.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
from fastcs.controller_api import ControllerAPI
2+
from fastcs.util import snake_to_pascal
3+
4+
5+
def controller_pv_prefix(prefix: str, controller_api: ControllerAPI) -> str:
6+
return ":".join([prefix] + [snake_to_pascal(node) for node in controller_api.path])

0 commit comments

Comments
 (0)