Skip to content

Commit

Permalink
added initial values
Browse files Browse the repository at this point in the history
  • Loading branch information
evalott100 committed Nov 11, 2024
1 parent 030a2e1 commit 2a4f5c2
Show file tree
Hide file tree
Showing 3 changed files with 75 additions and 51 deletions.
6 changes: 5 additions & 1 deletion src/fastcs_pandablocks/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,10 +81,14 @@ def main():
level = getattr(logging, parsed_args.log_level.upper(), None)
logging.basicConfig(format="%(levelname)s:%(message)s", level=level)

screens_directory = (
Path(parsed_args.screens_dir) if parsed_args.screens_dir else None
)

ioc(
parsed_args.prefix,
parsed_args.hostname,
screens_directory=Path(parsed_args.screens_dir),
screens_directory=screens_directory,
clear_bobfiles=parsed_args.clear_bobfiles,
poll_period=parsed_args.poll_period,
naming_convention=PvNamingConvention(parsed_args.pv_naming_convention),
Expand Down
85 changes: 56 additions & 29 deletions src/fastcs_pandablocks/panda/fields.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,7 @@


def _strip_description(description: str | None) -> str | None:
if description is None:
return description
return description[:MAXIMUM_DESCRIPTION_LENGTH]
return None if description is None else description[:MAXIMUM_DESCRIPTION_LENGTH]


class FieldController(SubController):
Expand Down Expand Up @@ -126,6 +124,7 @@ def __init__(
handler=DefaultFieldHandler(panda_name),
description=_strip_description(field_info.description),
group=WidgetGroup.PARAMETERS.value,
initial_value=float(initial_values[panda_name]),
)
self._additional_attributes["units"] = AttrW(
String(),
Expand All @@ -140,6 +139,7 @@ def __init__(
self,
panda_name: PandaName,
field_info: SubtypeTimeFieldInfo,
initial_values: RawInitialValuesType,
):
super().__init__(panda_name)
self.top_level_attribute = AttrR(
Expand All @@ -149,6 +149,7 @@ def __init__(
),
description=_strip_description(field_info.description),
group=WidgetGroup.OUTPUTS.value,
initial_value=float(initial_values[panda_name]),
)
self._additional_attributes["units"] = AttrW(
String(),
Expand All @@ -163,6 +164,7 @@ def __init__(
self,
panda_name: PandaName,
field_info: SubtypeTimeFieldInfo,
initial_value: RawInitialValuesType,
):
super().__init__(panda_name)
self.top_level_attribute = AttrW(
Expand Down Expand Up @@ -191,6 +193,7 @@ def __init__(
Bool(znam="0", onam="1"),
description=_strip_description(field_info.description),
group=WidgetGroup.OUTPUTS.value,
initial_value=bool(int(initial_values[panda_name])),
)


Expand All @@ -206,6 +209,7 @@ def __init__(
Float(),
description=_strip_description(field_info.description),
group=WidgetGroup.OUTPUTS.value,
initial_value=bool(int(initial_values[panda_name])),
)

scaled = AttrR(
Expand Down Expand Up @@ -320,15 +324,17 @@ def __init__(
initial_values: RawInitialValuesType,
):
super().__init__(panda_name)

self.top_level_attribute = AttrRW(
String(),
description=_strip_description(bit_mux_field_info.description),
handler=DefaultFieldHandler(panda_name),
group=WidgetGroup.INPUTS.value,
initial_value=initial_values[panda_name],
)

self._additional_attributes["delay"] = AttrRW(
Float(),
Int(),
description="Clock delay on input.",
handler=DefaultFieldHandler(panda_name),
group=WidgetGroup.INPUTS.value,
Expand All @@ -347,7 +353,10 @@ def __init__(
super().__init__(panda_name)
self.top_level_attribute = AttrRW(
String(),
description=_strip_description(pos_mux_field_info.description),
group=WidgetGroup.INPUTS.value,
allowed_values=pos_mux_field_info.labels,
initial_value=initial_values[panda_name],
)


Expand All @@ -361,9 +370,13 @@ def __init__(
super().__init__(panda_name)
self.top_level_attribute = AttrR(
Float(prec=0),
description=_strip_description(uint_param_field_info.description),
group=WidgetGroup.PARAMETERS.value,
initial_value=float(initial_values[panda_name]),
)

# TODO: set DRVL, DRVH, HOPR (new fastcs feature)


class UintReadFieldController(FieldController):
def __init__(
Expand All @@ -375,9 +388,9 @@ def __init__(
super().__init__(panda_name)
self.top_level_attribute = AttrR(
Float(prec=0),
description=_strip_description(uint_read_field_info.description),
group=WidgetGroup.READBACKS.value,
# To be added once we have a pvxs backend
# description=uint_read_field_info.description,
initial_value=float(initial_values[panda_name]),
)


Expand All @@ -391,6 +404,7 @@ def __init__(
super().__init__(panda_name)
self.top_level_attribute = AttrW(
Float(prec=0),
description=_strip_description(uint_write_field_info.description),
group=WidgetGroup.OUTPUTS.value,
)

Expand All @@ -404,8 +418,10 @@ def __init__(
):
super().__init__(panda_name)
self.top_level_attribute = AttrRW(
Float(prec=0),
Int(),
description=_strip_description(int_param_field_info.description),
group=WidgetGroup.PARAMETERS.value,
initial_value=int(initial_values[panda_name]),
)


Expand All @@ -419,7 +435,9 @@ def __init__(
super().__init__(panda_name)
self.top_level_attribute = AttrR(
Int(),
description=_strip_description(int_read_field_info.description),
group=WidgetGroup.READBACKS.value,
initial_value=int(initial_values[panda_name]),
)


Expand All @@ -433,6 +451,7 @@ def __init__(
super().__init__(panda_name)
self.top_level_attribute = AttrW(
Int(),
description=_strip_description(int_write_field_info.description),
group=WidgetGroup.PARAMETERS.value,
)

Expand All @@ -446,8 +465,10 @@ def __init__(
):
super().__init__(panda_name)
self.top_level_attribute = AttrRW(
Float(),
Float(units=scalar_param_field_info.units),
description=_strip_description(scalar_param_field_info.description),
group=WidgetGroup.PARAMETERS.value,
initial_value=float(initial_values[panda_name]),
)


Expand All @@ -461,7 +482,9 @@ def __init__(
super().__init__(panda_name)
self.top_level_attribute = AttrR(
Float(),
description=_strip_description(scalar_read_field_info.description),
group=WidgetGroup.READBACKS.value,
initial_value=float(initial_values[panda_name]),
)


Expand All @@ -475,6 +498,7 @@ def __init__(
super().__init__(panda_name)
self.top_level_attribute = AttrR(
Float(),
description=_strip_description(scalar_write_field_info.description),
group=WidgetGroup.PARAMETERS.value,
)

Expand All @@ -489,7 +513,11 @@ def __init__(
super().__init__(panda_name)
self.top_level_attribute = AttrRW(
Bool(znam="0", onam="1"),
description=_strip_description(bit_param_field_info.description),
group=WidgetGroup.PARAMETERS.value,
# Initial value is string "0"/"1".
# TODO: Equip each read/readwrite field with a converter
initial_value=bool(int(initial_values[panda_name])),
)


Expand All @@ -503,7 +531,9 @@ def __init__(
super().__init__(panda_name)
self.top_level_attribute = AttrR(
Bool(znam="0", onam="1"),
description=_strip_description(bit_read_field_info.description),
group=WidgetGroup.READBACKS.value,
initial_value=bool(int(initial_values[panda_name])),
)


Expand All @@ -517,24 +547,11 @@ def __init__(
super().__init__(panda_name)
self.top_level_attribute = AttrW(
Bool(znam="0", onam="1"),
description=_strip_description(bit_write_field_info.description),
group=WidgetGroup.OUTPUTS.value,
)


class ActionReadFieldController(FieldController):
def __init__(
self,
panda_name: PandaName,
action_read_field_info: FieldInfo,
initial_values: RawInitialValuesType,
):
super().__init__(panda_name)
self.top_level_attribute = AttrR(
Bool(znam="0", onam="1"),
group=WidgetGroup.READBACKS.value,
)


class ActionWriteFieldController(FieldController):
def __init__(
self,
Expand All @@ -545,6 +562,7 @@ def __init__(
super().__init__(panda_name)
self.top_level_attribute = AttrW(
Bool(znam="0", onam="1"),
description=_strip_description(action_write_field_info.description),
group=WidgetGroup.OUTPUTS.value,
)

Expand All @@ -559,7 +577,9 @@ def __init__(
super().__init__(panda_name)
self.top_level_attribute = AttrRW(
String(),
description=_strip_description(lut_param_field_info.description),
group=WidgetGroup.PARAMETERS.value,
initial_value=initial_values[panda_name],
)


Expand All @@ -573,7 +593,9 @@ def __init__(
super().__init__(panda_name)
self.top_level_attribute = AttrR(
String(),
description=_strip_description(lut_read_field_info.description),
group=WidgetGroup.READBACKS.value,
initial_value=initial_values[panda_name],
)


Expand All @@ -587,6 +609,7 @@ def __init__(
super().__init__(panda_name)
self.top_level_attribute = AttrR(
String(),
description=_strip_description(lut_read_field_info.description),
group=WidgetGroup.OUTPUTS.value,
)

Expand All @@ -599,10 +622,12 @@ def __init__(
initial_values: RawInitialValuesType,
):
super().__init__(panda_name)
self.allowed_values = enum_param_field_info.labels
self.top_level_attribute = AttrRW(
String(),
description=_strip_description(enum_param_field_info.description),
allowed_values=enum_param_field_info.labels,
group=WidgetGroup.PARAMETERS.value,
initial_value=initial_values[panda_name],
)


Expand All @@ -614,9 +639,15 @@ def __init__(
initial_values: RawInitialValuesType,
):
super().__init__(panda_name)

# We use a raw string for this since many labels won't fit into
# mbbIn fields because of EPICS limitations.
# Since this is read only it doesn't matter.
self.top_level_attribute = AttrR(
String(),
description=_strip_description(enum_read_field_info.description),
group=WidgetGroup.READBACKS.value,
initial_value=initial_values[panda_name],
)


Expand All @@ -630,6 +661,8 @@ def __init__(
super().__init__(panda_name)
self.top_level_attribute = AttrW(
String(),
description=_strip_description(enum_write_field_info.description),
allowed_values=enum_write_field_info.labels,
group=WidgetGroup.OUTPUTS.value,
)

Expand All @@ -654,7 +687,6 @@ def __init__(
| BitParamFieldController
| BitReadFieldController
| BitWriteFieldController
| ActionReadFieldController
| ActionWriteFieldController
| LutParamFieldController
| LutReadFieldController
Expand Down Expand Up @@ -735,11 +767,6 @@ def get_field_controller_from_field_info(
return IntWriteFieldController(panda_name, field_info, initial_values)

# Action types
case FieldInfo(
type="read",
subtype="action",
):
return ActionReadFieldController(panda_name, field_info, initial_values)
case FieldInfo(
type="write",
subtype="action",
Expand Down
Loading

0 comments on commit 2a4f5c2

Please sign in to comment.