Skip to content

Commit

Permalink
Various fixes from the PR
Browse files Browse the repository at this point in the history
  • Loading branch information
evalott100 committed Sep 1, 2023
1 parent c13d7aa commit 20bac0b
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 21 deletions.
16 changes: 8 additions & 8 deletions src/pandablocks_ioc/_tables.py
Original file line number Diff line number Diff line change
Expand Up @@ -308,9 +308,9 @@ def __init__(
value,
)

putorder_index = 1

for field_name, field_record_container in self.table_fields_records.items():
for i, (field_name, field_record_container) in enumerate(
self.table_fields_records.items()
):
field_details = field_record_container.field

full_name = table_name + ":" + field_name
Expand All @@ -333,14 +333,14 @@ def __init__(
field_pva_info = {
"+type": "plain",
"+channel": "VAL",
"+putorder": putorder_index,
"+putorder": i + 1,
"+trigger": "",
}

pva_info = {f"value.{field_name.lower()}": field_pva_info}

# For the last column in the table
if putorder_index == len(self.table_fields_records):
if i == len(self.table_fields_records) - 1:
# Trigger a monitor update
field_pva_info["+trigger"] = "*"
# Add metadata
Expand All @@ -351,8 +351,6 @@ def __init__(
{pva_table_name: pva_info},
)

putorder_index += 1

field_record_container.record_info = RecordInfo(lambda x: x, None, False)

field_record_container.record_info.add_record(field_record)
Expand Down Expand Up @@ -456,7 +454,9 @@ def __init__(
OUT=PP(mode_record),
)
# Edit mode done first, Submit mode done last
putorder = 0 if action == TableModeEnum.EDIT else putorder_index
putorder = (
0 if action == TableModeEnum.EDIT else len(self.table_fields_records)
)
action_record.add_info(
"Q:group",
{
Expand Down
3 changes: 2 additions & 1 deletion src/pandablocks_ioc/_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@ def device_and_record_to_panda_name(field_name: EpicsName) -> PandAName:
convention."""

if field_name.endswith(":LABEL"):
# Device is a metadata_label field
# Field is the label for the block, which is stored in the special
# *METADATA area

block_name = field_name.split(":")[-2]
if not block_name[-1].isdigit():
Expand Down
27 changes: 15 additions & 12 deletions src/pandablocks_ioc/ioc.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ async def _create_softioc(
except OSError:
logging.exception("Unable to connect to PandA")
raise
(all_records, all_values_dict, panda_dict) = await create_records(
(all_records, all_values_dict, block_info_dict) = await create_records(
client, dispatcher, record_prefix
)

Expand All @@ -104,7 +104,7 @@ async def _create_softioc(
raise RuntimeError("Unexpected state - softioc task already exists")

create_softioc_task = asyncio.create_task(
update(client, all_records, 0.1, all_values_dict, panda_dict)
update(client, all_records, 0.1, all_values_dict, block_info_dict)
)

create_softioc_task.add_done_callback(_when_finished)
Expand Down Expand Up @@ -188,13 +188,13 @@ async def introspect_panda(


def _create_dicts_from_changes(
changes: Changes, block_info: Dict[str, BlockInfo]
changes: Changes, block_info_dict: Dict[str, BlockInfo]
) -> Tuple[Dict[str, Dict[EpicsName, RecordValue]], Dict[EpicsName, RecordValue]]:
"""Take the `Changes` object and convert it into two dictionaries.
Args:
changes: The `Changes` object as returned by `GetChanges`
block_info: Information from the initial `GetBlockInfo` request,
block_info_dict: Information from the initial `GetBlockInfo` request,
used to check the `number` of blocks for parsing metadata
Returns:
Expand Down Expand Up @@ -222,10 +222,10 @@ def _store_values(
"LABEL_"
):
_, block_name_number = field_name.split("_", maxsplit=1)
if block_name_number in block_info:
number_of_blocks = block_info[block_name_number].number
if block_name_number in block_info_dict:
number_of_blocks = block_info_dict[block_name_number].number
else:
number_of_blocks = block_info[block_name_number[:-1]].number
number_of_blocks = block_info_dict[block_name_number[:-1]].number

# The block is fixed with metadata
# "*METADATA.LABEL_SEQ2": "NewSeqMetadataLabel",
Expand Down Expand Up @@ -1694,7 +1694,7 @@ def create_block_records(

# The record uses the default _RecordUpdater.update to update the value
# on the panda
record_dict[key] = self._create_record_info(
record_dict[EpicsName(key)] = self._create_record_info(
key,
None,
builder.longStringOut,
Expand Down Expand Up @@ -1741,7 +1741,7 @@ async def create_records(
EpicsName,
RecordValue,
],
Dict[str, _BlockAndFieldInfo],
Dict[str, BlockInfo],
]:
"""Query the PandA and create the relevant records based on the information
returned"""
Expand Down Expand Up @@ -1816,15 +1816,16 @@ async def create_records(

record_factory.initialise(dispatcher)

return (all_records, all_values_dict, panda_dict)
block_info_dict = {key: value.block_info for key, value in panda_dict.items()}
return (all_records, all_values_dict, block_info_dict)


async def update(
client: AsyncioClient,
all_records: Dict[EpicsName, RecordInfo],
poll_period: float,
all_values_dict: Dict[EpicsName, RecordValue],
block_info: Dict[str, BlockInfo],
block_info_dict: Dict[str, BlockInfo],
):
"""Query the PandA at regular intervals for any changed fields, and update
the records accordingly
Expand Down Expand Up @@ -1867,7 +1868,9 @@ async def update(
# Clear any alarm state as we've received a new update from PandA
set_all_records_severity(all_records, alarm.NO_ALARM, alarm.UDF_ALARM)

_, new_all_values_dict = _create_dicts_from_changes(changes, block_info)
_, new_all_values_dict = _create_dicts_from_changes(
changes, block_info_dict
)

# Apply the new values to the existing dict, so various updater classes
# will have access to the latest values.
Expand Down

0 comments on commit 20bac0b

Please sign in to comment.