From c0bdc92b18afbb1be5dfed7830c61a661d986db1 Mon Sep 17 00:00:00 2001 From: Sebastien Bourdeauducq Date: Wed, 14 Jan 2015 11:37:08 +0800 Subject: [PATCH] master: broadcast realtime results --- artiq/management/rt_results.py | 24 ++++++++++++++++++++++++ artiq/management/worker_impl.py | 4 ++-- frontend/artiq_master.py | 17 ++++++----------- 3 files changed, 32 insertions(+), 13 deletions(-) create mode 100644 artiq/management/rt_results.py diff --git a/artiq/management/rt_results.py b/artiq/management/rt_results.py new file mode 100644 index 000000000..b554a3c94 --- /dev/null +++ b/artiq/management/rt_results.py @@ -0,0 +1,24 @@ +from artiq.management.sync_struct import Notifier, process_mod + + +class RTResults: + def __init__(self): + self.sets = Notifier(dict()) + self.current_set = "default" + + def init(self, description): + data = dict() + for rtr in description.keys(): + if isinstance(rtr, tuple): + for e in rtr: + data[e] = [] + else: + data[rtr] = [] + self.sets[self.current_set] = { + "description": description, + "data": data + } + + def update(self, mod): + target = self.sets[self.current_set]["data"] + process_mod(target, mod) diff --git a/artiq/management/worker_impl.py b/artiq/management/worker_impl.py index 17d92857f..9bf7c1d6f 100644 --- a/artiq/management/worker_impl.py +++ b/artiq/management/worker_impl.py @@ -48,8 +48,8 @@ class ParentPDB: set = make_parent_action("set_parameter", "name value") -init_rt_results = make_parent_action("init_rt_results", "data") -update_rt_results = make_parent_action("update_rt_results", "data") +init_rt_results = make_parent_action("init_rt_results", "description") +update_rt_results = make_parent_action("update_rt_results", "mod") def publish_rt_results(notifier, data): diff --git a/frontend/artiq_master.py b/frontend/artiq_master.py index e2ace48c8..9dae6e65b 100755 --- a/frontend/artiq_master.py +++ b/frontend/artiq_master.py @@ -8,6 +8,7 @@ from artiq.management.pc_rpc import Server from artiq.management.sync_struct import Publisher from artiq.management.db import FlatFileDB, SimpleHistory from artiq.management.scheduler import Scheduler +from artiq.management.rt_results import RTResults def _get_args(): @@ -24,14 +25,6 @@ def _get_args(): return parser.parse_args() -def init_rt_results(data): - print("init realtime results: " + str(data)) - - -def update_rt_results(data): - print("update realtime results: " + str(data)) - - def main(): args = _get_args() @@ -39,6 +32,7 @@ def main(): pdb = FlatFileDB("pdb.pyon") simplephist = SimpleHistory(30) pdb.hooks.append(simplephist) + rtr = RTResults() loop = asyncio.get_event_loop() atexit.register(lambda: loop.close()) @@ -47,8 +41,8 @@ def main(): "req_device": ddb.request, "req_parameter": pdb.request, "set_parameter": pdb.set, - "init_rt_results": init_rt_results, - "update_rt_results": update_rt_results + "init_rt_results": rtr.init, + "update_rt_results": rtr.update }) loop.run_until_complete(scheduler.start()) atexit.register(lambda: loop.run_until_complete(scheduler.stop())) @@ -67,7 +61,8 @@ def main(): "periodic": scheduler.periodic, "devices": ddb.data, "parameters": pdb.data, - "parameters_simplehist": simplephist.history + "parameters_simplehist": simplephist.history, + "rt_results": rtr.sets }) loop.run_until_complete(server_notify.start( args.bind, args.port_notify))