2014-10-05 16:25:31 +08:00
|
|
|
#!/usr/bin/env python3
|
|
|
|
|
|
|
|
import asyncio
|
2014-10-25 11:34:52 +08:00
|
|
|
import argparse
|
2014-12-31 17:41:22 +08:00
|
|
|
import atexit
|
2015-02-03 22:06:45 +08:00
|
|
|
import os
|
2014-10-05 16:25:31 +08:00
|
|
|
|
2015-01-17 19:38:20 +08:00
|
|
|
from artiq.protocols.pc_rpc import Server
|
|
|
|
from artiq.protocols.sync_struct import Publisher
|
|
|
|
from artiq.protocols.file_db import FlatFileDB, SimpleHistory
|
2015-01-14 12:16:49 +08:00
|
|
|
from artiq.master.scheduler import Scheduler
|
|
|
|
from artiq.master.rt_results import RTResults
|
2015-01-26 23:37:33 +08:00
|
|
|
from artiq.master.repository import Repository
|
2015-01-28 21:44:15 +08:00
|
|
|
from artiq.tools import verbosity_args, init_logger
|
2014-10-05 16:25:31 +08:00
|
|
|
|
|
|
|
|
2015-01-23 00:52:13 +08:00
|
|
|
def get_argparser():
|
2014-12-08 19:22:02 +08:00
|
|
|
parser = argparse.ArgumentParser(description="ARTIQ master")
|
2015-02-16 05:55:43 +08:00
|
|
|
group = parser.add_argument_group("network")
|
|
|
|
group.add_argument(
|
2014-10-25 11:34:52 +08:00
|
|
|
"--bind", default="::1",
|
|
|
|
help="hostname or IP address to bind to")
|
2015-02-16 05:55:43 +08:00
|
|
|
group.add_argument(
|
2015-01-13 03:55:50 +08:00
|
|
|
"--port-notify", default=3250, type=int,
|
2015-02-16 05:58:57 +08:00
|
|
|
help="TCP port to listen to for notifications (default: 3250)")
|
2015-02-16 05:55:43 +08:00
|
|
|
group.add_argument(
|
2015-01-13 03:55:50 +08:00
|
|
|
"--port-control", default=3251, type=int,
|
2015-02-16 05:58:57 +08:00
|
|
|
help="TCP port to listen to for control (default: 3251)")
|
2015-01-28 21:44:15 +08:00
|
|
|
verbosity_args(parser)
|
2015-01-23 00:52:13 +08:00
|
|
|
return parser
|
2014-10-25 11:34:52 +08:00
|
|
|
|
|
|
|
|
2014-10-05 16:25:31 +08:00
|
|
|
def main():
|
2015-01-23 00:52:13 +08:00
|
|
|
args = get_argparser().parse_args()
|
2015-01-02 15:28:45 +08:00
|
|
|
|
2015-01-28 21:44:15 +08:00
|
|
|
init_logger(args)
|
2015-01-12 18:51:23 +08:00
|
|
|
ddb = FlatFileDB("ddb.pyon")
|
|
|
|
pdb = FlatFileDB("pdb.pyon")
|
|
|
|
simplephist = SimpleHistory(30)
|
|
|
|
pdb.hooks.append(simplephist)
|
2015-01-14 11:37:08 +08:00
|
|
|
rtr = RTResults()
|
2015-01-26 23:37:33 +08:00
|
|
|
repository = Repository()
|
2015-01-29 19:59:16 +08:00
|
|
|
explist = FlatFileDB("explist.pyon")
|
2014-12-31 17:41:22 +08:00
|
|
|
|
2015-02-04 14:44:39 +08:00
|
|
|
if os.name == "nt":
|
2015-02-03 22:06:45 +08:00
|
|
|
loop = asyncio.ProactorEventLoop()
|
|
|
|
asyncio.set_event_loop(loop)
|
|
|
|
else:
|
|
|
|
loop = asyncio.get_event_loop()
|
2014-12-31 17:41:22 +08:00
|
|
|
atexit.register(lambda: loop.close())
|
|
|
|
|
2015-01-30 20:36:54 +08:00
|
|
|
def run_cb(rid, run_params):
|
|
|
|
rtr.current_group = run_params["rtr_group"]
|
2014-12-31 17:41:22 +08:00
|
|
|
scheduler = Scheduler({
|
2015-01-12 18:51:23 +08:00
|
|
|
"req_device": ddb.request,
|
|
|
|
"req_parameter": pdb.request,
|
2015-01-13 19:12:19 +08:00
|
|
|
"set_parameter": pdb.set,
|
2015-01-14 11:37:08 +08:00
|
|
|
"init_rt_results": rtr.init,
|
|
|
|
"update_rt_results": rtr.update
|
2015-01-30 20:36:54 +08:00
|
|
|
}, run_cb)
|
2014-12-31 17:41:22 +08:00
|
|
|
loop.run_until_complete(scheduler.start())
|
|
|
|
atexit.register(lambda: loop.run_until_complete(scheduler.stop()))
|
|
|
|
|
2014-12-31 20:13:10 +08:00
|
|
|
server_control = Server({
|
2015-01-12 18:51:23 +08:00
|
|
|
"master_ddb": ddb,
|
2015-01-26 23:37:33 +08:00
|
|
|
"master_pdb": pdb,
|
|
|
|
"master_schedule": scheduler,
|
2015-01-29 19:59:16 +08:00
|
|
|
"master_repository": repository,
|
|
|
|
"master_explist": explist
|
2014-12-31 20:13:10 +08:00
|
|
|
})
|
|
|
|
loop.run_until_complete(server_control.start(
|
|
|
|
args.bind, args.port_control))
|
|
|
|
atexit.register(lambda: loop.run_until_complete(server_control.stop()))
|
2014-12-31 17:41:22 +08:00
|
|
|
|
2014-12-31 20:13:10 +08:00
|
|
|
server_notify = Publisher({
|
2014-12-31 17:41:22 +08:00
|
|
|
"queue": scheduler.queue,
|
2015-01-23 00:23:00 +08:00
|
|
|
"timed": scheduler.timed,
|
2015-01-12 18:51:23 +08:00
|
|
|
"devices": ddb.data,
|
|
|
|
"parameters": pdb.data,
|
2015-01-14 11:37:08 +08:00
|
|
|
"parameters_simplehist": simplephist.history,
|
2015-01-29 19:59:16 +08:00
|
|
|
"rt_results": rtr.groups,
|
|
|
|
"explist": explist.data
|
2014-12-31 17:41:22 +08:00
|
|
|
})
|
2014-12-31 20:13:10 +08:00
|
|
|
loop.run_until_complete(server_notify.start(
|
|
|
|
args.bind, args.port_notify))
|
|
|
|
atexit.register(lambda: loop.run_until_complete(server_notify.stop()))
|
2014-12-31 17:41:22 +08:00
|
|
|
|
|
|
|
loop.run_forever()
|
2014-10-05 16:25:31 +08:00
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
main()
|