artiq/artiq/frontend/artiq_master.py

92 lines
2.8 KiB
Python
Raw Normal View History

#!/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
import os
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
2015-01-23 00:52:13 +08:00
def get_argparser():
parser = argparse.ArgumentParser(description="ARTIQ master")
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")
group.add_argument(
"--port-notify", default=3250, type=int,
2015-02-16 05:58:57 +08:00
help="TCP port to listen to for notifications (default: 3250)")
group.add_argument(
"--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
def main():
2015-01-23 00:52:13 +08:00
args = get_argparser().parse_args()
2015-01-28 21:44:15 +08:00
init_logger(args)
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":
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())
def run_cb(rid, run_params):
rtr.current_group = run_params["rtr_group"]
2014-12-31 17:41:22 +08:00
scheduler = Scheduler({
"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
}, 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({
"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,
"timed": scheduler.timed,
"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()
if __name__ == "__main__":
main()