2
0
mirror of https://github.com/m-labs/artiq.git synced 2024-12-22 18:04:03 +08:00
artiq/frontend/artiq_master.py

75 lines
2.1 KiB
Python
Executable File

#!/usr/bin/env python3
import asyncio
import argparse
import atexit
from artiq.management.pc_rpc import Server
from artiq.management.sync_struct import Publisher
from artiq.management.db import FlatFileDB, SimpleHistory
from artiq.master.scheduler import Scheduler
from artiq.master.rt_results import RTResults
def _get_args():
parser = argparse.ArgumentParser(description="ARTIQ master")
parser.add_argument(
"--bind", default="::1",
help="hostname or IP address to bind to")
parser.add_argument(
"--port-notify", default=3250, type=int,
help="TCP port to listen to for notifications")
parser.add_argument(
"--port-control", default=3251, type=int,
help="TCP port to listen to for control")
return parser.parse_args()
def main():
args = _get_args()
ddb = FlatFileDB("ddb.pyon")
pdb = FlatFileDB("pdb.pyon")
simplephist = SimpleHistory(30)
pdb.hooks.append(simplephist)
rtr = RTResults()
loop = asyncio.get_event_loop()
atexit.register(lambda: loop.close())
scheduler = Scheduler({
"req_device": ddb.request,
"req_parameter": pdb.request,
"set_parameter": pdb.set,
"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()))
server_control = Server({
"master_schedule": scheduler,
"master_ddb": ddb,
"master_pdb": pdb
})
loop.run_until_complete(server_control.start(
args.bind, args.port_control))
atexit.register(lambda: loop.run_until_complete(server_control.stop()))
server_notify = Publisher({
"queue": scheduler.queue,
"periodic": scheduler.periodic,
"devices": ddb.data,
"parameters": pdb.data,
"parameters_simplehist": simplephist.history,
"rt_results": rtr.groups
})
loop.run_until_complete(server_notify.start(
args.bind, args.port_notify))
atexit.register(lambda: loop.run_until_complete(server_notify.stop()))
loop.run_forever()
if __name__ == "__main__":
main()