Skip to content

Commit

Permalink
Updated zebra2 implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
coretl committed Dec 4, 2015
1 parent 0d1438d commit 651a153
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 34 deletions.
7 changes: 5 additions & 2 deletions malcolm/devices/zebra2/zebra2.py
Expand Up @@ -29,8 +29,11 @@ def __init__(self, name, hostname, port):
# Now create N block objects based on this info
for block, num in self.num_blocks.items():
field_data = self.comms.get_field_data(block)
for i in range(num):
self.make_block(block, i + 1, field_data)
if num == 1:
self.make_block(block, "", field_data)
else:
for i in range(num):
self.make_block(block, i + 1, field_data)
# Publish these blocks
self.blocks = [b.name for b in self._blocks.values()]
# Now poll them at 10Hz
Expand Down
3 changes: 3 additions & 0 deletions malcolm/devices/zebra2/zebra2comms.py
Expand Up @@ -99,6 +99,9 @@ def get_changes(self):
if line.endswith("(error)"):
field = line.split(" ", 1)[0]
val = Exception
elif "<" in line:
# table
pass
else:
field, val = line.split("=", 1)
changes[field] = val
Expand Down
14 changes: 7 additions & 7 deletions malcolm/personalities/simdetectorpersonality_new.py
Expand Up @@ -163,7 +163,7 @@ def _configure_hdf5Writer(self):
params.update(arrayPort=self.positionPlugin.portName, block=False)
self.hdf5Writer.configure(**params)

def do_configure(self, **config_params):
def do_configure(self, config_params, task):
"""Start doing a configuration using config_params.
Return DState.Configuring, message when started
"""
Expand All @@ -176,22 +176,22 @@ def do_configure(self, **config_params):
setattr(self, name, value)
self.stepsPerRun = 1
self.currentStep = 0
self.report("Configuring simDetector")
task.report("Configuring simDetector")
self._configure_simDetector()
self.report("Configuring positionPlugin")
task.report("Configuring positionPlugin")
self._configure_positionPlugin()
# Setup config matcher
self._sconfig = ConfigMatcher(
SeqTransitionItem(
self.child_statemachines,
DState.Ready, DState.rest()))
name, changes = self.report_wait("Wait for plugins to configure")
name, changes = task.report_wait("Wait for plugins to configure")
while not self._sconfig.check_done(name, changes):
name, changes = self.report_wait()
self.report("Configuring hdf5Writer")
name, changes = task.report_wait()
task.report("Configuring hdf5Writer")
self._configure_hdf5Writer(self.positionPlugin.dimensions)
# Finished
self.report("Configuring done", DState.Ready)
task.report("Configuring done", DState.Ready)

def do_ready(self, value, changes):
"""Work out if the changes mean we are still ready for run.
Expand Down
33 changes: 8 additions & 25 deletions tests/dls_tests/system_zebra2sim.py
Expand Up @@ -34,32 +34,15 @@ def setUp(self):
self.z.loop_run()

def test_blocks(self):
expected = [
'Z:TTLIN1', 'Z:TTLIN2', 'Z:TTLIN3', 'Z:TTLIN4', 'Z:TTLIN5',
'Z:TTLIN6', 'Z:OUTENC1', 'Z:OUTENC2', 'Z:OUTENC3', 'Z:OUTENC4',
'Z:CALC1', 'Z:CALC2', 'Z:SRGATE1', 'Z:SRGATE2', 'Z:SRGATE3',
'Z:SRGATE4', 'Z:PCOMP1', 'Z:PCOMP2', 'Z:PCOMP3', 'Z:PCOMP4',
'Z:LUT1', 'Z:LUT2', 'Z:LUT3', 'Z:LUT4', 'Z:LUT5', 'Z:LUT6',
'Z:LUT7', 'Z:LUT8', 'Z:TTLOUT1', 'Z:TTLOUT2', 'Z:TTLOUT3',
'Z:TTLOUT4', 'Z:TTLOUT5', 'Z:TTLOUT6', 'Z:TTLOUT7', 'Z:TTLOUT8',
'Z:TTLOUT9', 'Z:TTLOUT10', 'Z:LVDSOUT1', 'Z:LVDSOUT2', 'Z:ADC1',
'Z:ADC2', 'Z:ADC3', 'Z:ADC4', 'Z:ADC5', 'Z:ADC6', 'Z:ADC7',
'Z:ADC8', 'Z:DIV1', 'Z:DIV2', 'Z:DIV3', 'Z:DIV4', 'Z:INENC1',
'Z:INENC2', 'Z:INENC3', 'Z:INENC4', 'Z:COUNTER1', 'Z:COUNTER2',
'Z:COUNTER3', 'Z:COUNTER4', 'Z:COUNTER5', 'Z:COUNTER6',
'Z:COUNTER7', 'Z:COUNTER8', 'Z:ADDER1', 'Z:PCAP1', 'Z:POSENC1',
'Z:POSENC2', 'Z:POSENC3', 'Z:POSENC4', 'Z:LVD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 'Z:COUNTER2', 'Z:COUNTER3', 'Z:COUNTER4', 'Z:COUNTER5', 'Z:COUNTER6', 'Z:COUNTER7', 'Z:COUNTER8', 'Z:ADDER', 'Z:CLOCKS', 'Z:BITS', 'Z:QDEC1', 'Z:QDEC2', 'Z:QDEC3', 'Z:QDEC4']
self.assertEqual(self.z.blocks, expected)
adder = self.z._blocks["ADDER1"]
adder = self.z._blocks["ADDER"]
expected = ['uptime',
'RESULT',
'RESULT_UNITS',
'RESULT_SCALE',
'RESULT_OFFSET',
'RESULT_CAPTURE',
'RESULT:UNITS',
'RESULT:SCALE',
'RESULT:OFFSET',
'RESULT:CAPTURE',
'MASK',
'OUTSCALE']
self.assertEqual(adder.attributes.keys(), expected)
Expand All @@ -68,9 +51,9 @@ def test_poll(self):
pulse1 = self.z._blocks["PULSE1"]
self.assertEqual(pulse1.WIDTH, None)
m = MagicMock()
pulse1.add_listener(m, "attributes.WIDTH_UNITS")
pulse1.add_listener(m, "attributes.WIDTH:UNITS")
cothread.Sleep(0.2)
self.assertEqual(m.call_args[0][0], pulse1.attributes["WIDTH_UNITS"])
self.assertEqual(m.call_args[0][0], pulse1.attributes["WIDTH:UNITS"])
self.assertEqual(m.call_args[0][1]["value"], "s")

if __name__ == '__main__':
Expand Down

0 comments on commit 651a153

Please sign in to comment.