Skip to content

Commit

Permalink
Fixed some errors
Browse files Browse the repository at this point in the history
  • Loading branch information
evalott100 committed Jun 29, 2023
1 parent 6094360 commit 593f747
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 34 deletions.
40 changes: 13 additions & 27 deletions src/pandablocks_ioc/_tables.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,16 +155,12 @@ def __init__(
full_name = EpicsName(full_name)
description = trim_description(field_details.description, full_name)

waveform_val = self._construct_waveform_val(
field_data, field_name, field_details
)

field_record: RecordWrapper = builder.WaveformOut(
full_name,
DESC=description,
validate=self.validate_waveform,
on_update_name=self.update_waveform,
initial_value=waveform_val,
initial_value=field_data[field_name],
length=field_info.max_length,
)

Expand Down Expand Up @@ -305,23 +301,6 @@ def __init__(
SignalRW(index_record_name, index_record_name, TextWrite()),
)

def _construct_waveform_val(
self,
field_data: Dict[str, UnpackedArray],
field_name: str,
field_details: TableFieldDetails,
):
"""Convert the values into the right form. For enums this means converting
the numeric values PandA sends us into the string representation. For all other
types the numeric representation is used."""

if field_details.labels and not all(
[isinstance(x, str) for x in field_data[field_name]]
):
return [field_details.labels[x] for x in field_data[field_name]]

return field_data[field_name]

def validate_waveform(self, record: RecordWrapper, new_val) -> bool:
"""Controls whether updates to the waveform records are processed, based on the
value of the MODE record.
Expand Down Expand Up @@ -387,7 +366,14 @@ async def update_mode(self, new_val: int):
try:
# Send all EPICS data to PandA
logging.info(f"Sending table data for {self.table_name} to PandA")
packed_data = table_to_words(self.all_values_dict, self.field_info)

table = {}
for x in self.table_fields_records:
record_info = self.table_fields_records[x].record_info
if record_info:
table[x] = record_info.record.get()

packed_data = table_to_words(table, self.field_info)

panda_field_name = epics_to_panda_name(self.table_name)
await self.client.send(Put(panda_field_name, packed_data))
Expand Down Expand Up @@ -460,11 +446,11 @@ def update_table(self, new_values: List[str]) -> None:

for field_name, field_record in self.table_fields_records.items():
assert field_record.record_info
waveform_val = self._construct_waveform_val(
field_data, field_name, field_record.field
)

# Must skip processing as the validate method would reject the update
field_record.record_info.record.set(waveform_val, process=False)
field_record.record_info.record.set(
field_data[field_name], process=False
)
self._update_scalar(field_record.record_info.record.name)

# All items in field_data have the same length, so just use 0th.
Expand Down
8 changes: 1 addition & 7 deletions tests/test_tables.py
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,7 @@ async def test_create_softioc_table_update_send_to_panda(
await caput(TEST_PREFIX + ":SEQ1:TABLE:MODE", "SUBMIT", wait=True, timeout=TIMEOUT)

# Confirm the server received the expected string
print(dummy_server_system.expected_message_responses)
assert "" not in dummy_server_system.expected_message_responses

# Check the three numbers that should have updated from the REPEATS column change
Expand Down Expand Up @@ -422,9 +423,6 @@ async def test_table_updater_update_mode_submit_exception(
called_args = record_info.record.set.call_args

expected = called_args[0][0]
labels = table_updater.table_fields_records[field_name].field.labels
if labels:
expected = [labels[x] for x in expected]

numpy.testing.assert_array_equal(data, expected)

Expand Down Expand Up @@ -485,10 +483,6 @@ async def test_table_updater_update_mode_discard(

expected = called_args[0][0]

labels = table_updater.table_fields_records[field_name].field.labels
if labels:
expected = [labels[x] for x in expected]

numpy.testing.assert_array_equal(data, expected)

table_updater.mode_record_info.record.set.assert_called_once_with(
Expand Down

0 comments on commit 593f747

Please sign in to comment.