Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 10 additions & 4 deletions p4pillon/config_reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,12 +116,18 @@ def process_config(pvname: str, pvdetails: dict[str, Any]) -> BasePVRecipe:
else:
pvrecipe = PVScalarRecipe(PVTypes[pvdetails["type"]], pvdetails["description"], initial)

supported_configs = [("read_only", bool), ("calc", dict)]
for config, config_type in supported_configs:
# Process variables in the configuration that are attributes of the pvrecipe class
# Set read only
temp_config = pvdetails.get("read_only")
if temp_config is not None and isinstance(temp_config, bool):
pvrecipe.read_only = temp_config

# Process configuration in the yaml specific to a supported rule
# and add this to pvrecipe.rule_configs
rule_configs = [("calc", dict), ("cps_write", dict)]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There shouldn't be references to rules which don't exist in p4pillon in the p4pillon code! This indicates that there needs to be an alternate way to handle this, which isn't a growing list of special cases.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You may wish to consider entrypoints as a potential generic solution? (https://packaging.python.org/en/latest/specifications/entry-points/) I've not used them myself, so they may not be suitable. @MatInGit has used them and has this example.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes I agree! I think this can be done in a similar way to how registered_handlers are defined in SharedNT (as a class member) so that external rules can be added to rule_configs.

for config, config_type in rule_configs:
temp_config = pvdetails.get(config)
if temp_config is not None and isinstance(temp_config, config_type):
setattr(pvrecipe, config, temp_config)
pvrecipe.rule_configs[config] = temp_config

if "control" in pvdetails:
pvrecipe.set_control_limits(**get_field_config(pvdetails, "control"))
Expand Down
7 changes: 5 additions & 2 deletions p4pillon/pvrecipe.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,9 @@ def __post_init__(self):
self.construct_settings = {}
self.config_settings = {}

# Rule specific configs to be passed to SharedNT
self.rule_configs = {}

self.construct_settings["valtype"] = self.pvtype.value
self.construct_settings["extra"] = [("descriptor", "s")]
self.config_settings["descriptor"] = self.description
Expand Down Expand Up @@ -132,8 +135,8 @@ def build_pv(
)

kwargs = {}
if hasattr(self, "calc"):
kwargs["calc"] = self.calc
for name, config in self.rule_configs.items():
kwargs[name] = config

logger.debug(debug_str)

Expand Down
9 changes: 7 additions & 2 deletions p4pillon/server/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,5 +146,10 @@ def put_pv_value(self, pv_name: str, value):
"""
Put the value to a PV using the server Context member self._ctxt
"""
logger.debug("Trying putting value %r to pv %s", value, pv_name)
self._ctxt.put(pv_name, value)
shared_pv = self[pv_name]
if shared_pv:
logger.debug("Trying SharedNT post to pv %s with value %r ", pv_name, value)
shared_pv.post(value)
else:
logger.debug("Trying Context put to pv %s with value %r ", pv_name, value)
self._ctxt.put(pv_name, value)