Skip to content

Commit

Permalink
WIP: Cleaned up pvi tree
Browse files Browse the repository at this point in the history
  • Loading branch information
evalott100 committed Feb 18, 2025
1 parent 530ba6a commit ae35247
Show file tree
Hide file tree
Showing 5 changed files with 158 additions and 161 deletions.
26 changes: 0 additions & 26 deletions src/fastcs/transport/epics/_options.py

This file was deleted.

9 changes: 1 addition & 8 deletions src/fastcs/transport/epics/options.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from dataclasses import dataclass, field
from dataclasses import dataclass
from enum import Enum
from pathlib import Path

Expand All @@ -24,10 +24,3 @@ class EpicsGUIOptions:
@dataclass
class EpicsIOCOptions:
pv_prefix: str = "MY-DEVICE-PREFIX"


@dataclass
class EpicsOptions:
docs: EpicsDocsOptions = field(default_factory=EpicsDocsOptions)
gui: EpicsGUIOptions = field(default_factory=EpicsGUIOptions)
ioc: EpicsIOCOptions = field(default_factory=EpicsIOCOptions)
19 changes: 13 additions & 6 deletions src/fastcs/transport/epics/p4p/ioc.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import asyncio
import re
from types import MethodType

from p4p.server import Server, StaticProvider
Expand All @@ -16,8 +17,16 @@
}


def get_pv_name(pv_prefix: str, attribute_name: str) -> str:
return f"{pv_prefix}:{attribute_name.title().replace('_', '')}"
def _snake_to_camel(name: str) -> str:
name = re.sub(
r"(?:^|_)([a-z])", lambda match: match.group(1).upper(), name
).replace("_", "")
return re.sub(r"_(\d+)$", r"\1", name)


def get_pv_name(pv_prefix: str, *attribute_names: str) -> str:
pv_formatted = ":".join([_snake_to_camel(attr) for attr in attribute_names])
return f"{pv_prefix}:{pv_formatted}" if pv_formatted else pv_prefix


async def parse_attributes(
Expand All @@ -28,19 +37,17 @@ async def parse_attributes(
pvi_tree.add_block(
prefix_root,
controller.description,
type(controller),
)

for single_mapping in controller.get_controller_mappings():
path = single_mapping.controller.path
pv_prefix = ":".join([prefix_root] + path)
pv_prefix = get_pv_name(prefix_root, *path)
provider = StaticProvider(pv_prefix)
providers.append(provider)

pvi_tree.add_block(
pv_prefix,
single_mapping.controller.description,
type(single_mapping.controller),
)

for attr_name, attribute in single_mapping.attributes.items():
Expand All @@ -57,7 +64,7 @@ async def parse_attributes(
provider.add(pv_name, command_pv)
pvi_tree.add_field(pv_name, "x")

providers.append(pvi_tree.make_provider())
providers.append(pvi_tree.make_provider(prefix_root))
return providers


Expand Down
Loading

0 comments on commit ae35247

Please sign in to comment.