Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
Richard Cunningham committed Sep 25, 2024
2 parents 58d44a2 + 6eadee5 commit e70ca6a
Show file tree
Hide file tree
Showing 5 changed files with 2 additions and 102 deletions.
38 changes: 1 addition & 37 deletions src/pandablocks_ioc/ioc.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
GetBlockInfo,
GetChanges,
GetFieldInfo,
GetLine,
Put,
)
from pandablocks.responses import (
Expand Down Expand Up @@ -62,7 +61,6 @@
ScalarRecordValue,
check_num_labels,
device_and_record_to_panda_name,
epics_to_panda_name,
panda_to_epics_name,
trim_description,
trim_string_value,
Expand Down Expand Up @@ -422,10 +420,7 @@ async def update(self, new_val):

@dataclass
class _TimeRecordUpdater(_RecordUpdater):
"""Set the EGU and DRVL values on a record when the UNITS sub-record is updated.
DRVL will only be updated if the `is_type_time` flag is True - fields with a subtype
of `time` do not have a `MIN` attribute."""
"""Set the EGU values on a record when the UNITS sub-record is updated."""

base_record: RecordWrapper
is_type_time: bool
Expand All @@ -440,9 +435,6 @@ async def update(self, new_val: Any):
async def update_parent_record(self, new_val):
self.update_egu(new_val)

if self.is_type_time:
await self.update_drvl()

def update_egu(self, new_val) -> None:
assert self.labels

Expand All @@ -463,31 +455,6 @@ def update_egu(self, new_val) -> None:
1,
)

async def update_drvl(self) -> None:
# The MIN attribute of a TIME type is automatically updated when the
# UNITS record is updated. Retrieve the new value and set it into DRVL.

# Remove the EPICS name prefix
record_name = self.record_info.record.name.replace(
self.record_prefix + ":", "", 1
)

# Trim off the last component to find the base record
base_record_name = record_name.rsplit(":", maxsplit=1)[0]

panda_field_name = epics_to_panda_name(base_record_name)

new_min = await self.client.send(GetLine(f"{panda_field_name}.MIN"))

new_min_float = np.require(new_min, dtype=np.float64)

db_put_field(
f"{self.base_record.name}.DRVL",
fields.DBF_DOUBLE,
new_min_float.ctypes.data,
1,
)


@dataclass
class StringRecordLabelValidator:
Expand Down Expand Up @@ -776,9 +743,6 @@ def _make_type_time(
initial_value=values[record_name],
)

# MIN attribute is the DRVL field in EPICS
record_dict[record_name].record.DRVL = field_info.min_val

return record_dict

def _make_subtype_time_param(
Expand Down
9 changes: 0 additions & 9 deletions tests/fixtures/mocked_panda.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
GetBlockInfo,
GetChanges,
GetFieldInfo,
GetLine,
Put,
)
from pandablocks.connections import DataConnection
Expand Down Expand Up @@ -510,7 +509,6 @@ def multiple_seq_responses(table_field_info, table_data_1, table_data_2):
],
)
): repeat(None),
# DRVL changing from 8e-06 ms to minutes
command_to_key(GetFieldInfo(block="SEQ", extended_metadata=True)): repeat(
{"TABLE": table_field_info}
),
Expand Down Expand Up @@ -588,7 +586,6 @@ def no_numbered_suffix_to_metadata_responses(table_field_info, table_data_1):
],
)
): repeat(None),
# DRVL changing from 8e-06 ms to minutes
command_to_key(GetFieldInfo(block="SEQ", extended_metadata=True)): repeat(
{"TABLE": table_field_info}
),
Expand Down Expand Up @@ -812,14 +809,9 @@ def standard_responses(table_field_info, table_data_1, table_data_2):
units_labels=["min", "s", "ms", "ns"],
subtype=None,
description="EGU Desc",
min_val=8e-06,
)
},
),
# DRVL changing from 8e-06 ms to minutes
command_to_key(GetLine(field="PULSE.DELAY.MIN")): chain(
["8e-09"], repeat("1.333333333e-10")
),
command_to_key(GetFieldInfo(block="SEQ", extended_metadata=True)): repeat(
{"TABLE": table_field_info}
),
Expand All @@ -843,7 +835,6 @@ def standard_responses(table_field_info, table_data_1, table_data_2):
"*METADATA.LABEL_PCAP1": "PcapMetadataLabel",
"PULSE.DELAY": "100",
"PULSE.DELAY.UNITS": "ms",
"PULSE.DELAY.MIN": "8e-06",
},
multiline_values={"SEQ.TABLE": table_data_1},
),
Expand Down
7 changes: 0 additions & 7 deletions tests/test_connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
GetBlockInfo,
GetChanges,
GetFieldInfo,
GetLine,
Put,
TimeFieldInfo,
)
Expand Down Expand Up @@ -79,14 +78,9 @@ def panda_disconnect_responses(table_field_info, table_data_1, table_data_2):
units_labels=["min", "s", "ms", "ns"],
subtype=None,
description="EGU Desc",
min_val=8e-06,
)
},
),
# DRVL changing from 8e-06 ms to minutes
command_to_key(GetLine(field="PULSE.DELAY.MIN")): chain(
["8e-09"], repeat("1.333333333e-10")
),
command_to_key(GetFieldInfo(block="SEQ", extended_metadata=True)): repeat(
{"TABLE": table_field_info}
),
Expand All @@ -110,7 +104,6 @@ def panda_disconnect_responses(table_field_info, table_data_1, table_data_2):
"*METADATA.LABEL_PCAP1": "PcapMetadataLabel",
"PULSE.DELAY": "100",
"PULSE.DELAY.UNITS": "ms",
"PULSE.DELAY.MIN": "8e-06",
},
multiline_values={"SEQ.TABLE": table_data_1},
),
Expand Down
26 changes: 1 addition & 25 deletions tests/test_ioc.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import pytest
from mock.mock import MagicMock, call
from pandablocks.asyncio import AsyncioClient
from pandablocks.commands import GetLine, Put
from pandablocks.commands import Put
from pandablocks.responses import (
BitMuxFieldInfo,
BitOutFieldInfo,
Expand Down Expand Up @@ -135,7 +135,6 @@ def idfn(val):
None,
None,
units_labels=["s", "ms", "min"],
min_val=8e-09,
),
{
f"{TEST_RECORD}": "0.1",
Expand Down Expand Up @@ -659,29 +658,6 @@ async def test_time_record_updater_update_egu(
assert isinstance(put_field_args[2], int)


@patch("pandablocks_ioc.ioc.db_put_field")
async def test_time_record_updater_update_drvl(
db_put_field: MagicMock, mocked_time_record_updater: Tuple[_TimeRecordUpdater, str]
):
"""Test that _TimeRecordUpdater.update_drvl works correctly"""

time_record_updater, test_prefix = mocked_time_record_updater
await time_record_updater.update_drvl()

time_record_updater.client.send.assert_called_once_with(GetLine("TEST.MIN"))

db_put_field.assert_called_once()

# Check the expected arguments are passed to db_put_field.
# Note we don't check the value of `array.ctypes.data` parameter as it's a pointer
# to a memory address so will always vary
put_field_args = db_put_field.call_args.args
expected_args = [test_prefix + ":BASE:RECORD.DRVL", fields.DBF_DOUBLE, 1]
for arg in expected_args:
assert arg in put_field_args
assert isinstance(put_field_args[2], int)


def test_uint_sets_record_attributes(ioc_record_factory: IocRecordFactory):
"""Test that creating a uint record correctly sets all the attributes"""

Expand Down
24 changes: 0 additions & 24 deletions tests/test_ioc_system.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,6 @@ async def test_introspect_panda(
"PCAP:LABEL": "PcapMetadataLabel",
"PULSE:DELAY": "100",
"PCAP:ARM": "0",
"PULSE:DELAY:MIN": "8e-06",
"PULSE:DELAY:UNITS": "ms",
"SEQ:TABLE": table_data_1,
}
Expand Down Expand Up @@ -225,23 +224,11 @@ async def test_create_softioc_time_panda_changes(mocked_panda_standard_responses
test_prefix + ":PULSE:DELAY:UNITS", units_queue.put, datatype=str
)
assert await asyncio.wait_for(units_queue.get(), TIMEOUT) == "ms"

drvl_queue = asyncio.Queue()
m3 = camonitor(
test_prefix + ":PULSE:DELAY.DRVL",
drvl_queue.put,
)
# The units value changes from ms to s in the test Client, which causes
# the DRVL value to change from 8e-06 to 8e-09, consistent to ms to s.

assert await asyncio.wait_for(drvl_queue.get(), TIMEOUT) == 8e-06
assert await asyncio.wait_for(egu_queue.get(), TIMEOUT) == "s"
assert await asyncio.wait_for(units_queue.get(), TIMEOUT) == "s"
assert await asyncio.wait_for(drvl_queue.get(), TIMEOUT) == 8e-09
finally:
m1.close()
m2.close()
m3.close()


async def test_create_softioc_time_epics_changes(
Expand Down Expand Up @@ -271,17 +258,8 @@ async def test_create_softioc_time_epics_changes(
test_prefix + ":PULSE:DELAY:UNITS", units_queue.put, datatype=str
)
assert await asyncio.wait_for(units_queue.get(), TIMEOUT) == "ms"

drvl_queue = asyncio.Queue()
m3 = camonitor(
test_prefix + ":PULSE:DELAY.DRVL",
drvl_queue.put,
)
assert await asyncio.wait_for(drvl_queue.get(), TIMEOUT) == 8e-06

assert await asyncio.wait_for(egu_queue.get(), TIMEOUT) == "s"
assert await asyncio.wait_for(units_queue.get(), TIMEOUT) == "s"
assert await asyncio.wait_for(drvl_queue.get(), TIMEOUT) == 8e-09

# Change the UNITS to "min"
assert await caput(
Expand All @@ -290,12 +268,10 @@ async def test_create_softioc_time_epics_changes(

assert await asyncio.wait_for(egu_queue.get(), TIMEOUT) == "min"
assert await asyncio.wait_for(units_queue.get(), TIMEOUT) == "min"
assert await asyncio.wait_for(drvl_queue.get(), TIMEOUT) == 1.333333333e-10

finally:
m1.close()
m2.close()
m3.close()


async def test_softioc_records_block(mocked_panda_standard_responses):
Expand Down

0 comments on commit e70ca6a

Please sign in to comment.