2
0
mirror of https://github.com/m-labs/artiq.git synced 2024-12-24 10:54:02 +08:00
artiq/frontend/artiq_master.py

68 lines
2.0 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
from artiq.management.pc_rpc import Server
2014-12-28 18:56:26 +08:00
from artiq.management.sync_struct import Publisher
from artiq.management.dpdb import DeviceParamDB, SimpleParameterHistory
from artiq.management.scheduler import Scheduler
2014-10-25 11:34:52 +08:00
def _get_args():
parser = argparse.ArgumentParser(description="ARTIQ master")
2014-10-25 11:34:52 +08:00
parser.add_argument(
"--bind", default="::1",
help="hostname or IP address to bind to")
parser.add_argument(
2014-12-31 20:13:10 +08:00
"--port-notify", default=8887, type=int,
help="TCP port to listen to for notifications")
2014-12-28 18:56:26 +08:00
parser.add_argument(
2014-12-31 20:13:10 +08:00
"--port-control", default=8888, type=int,
help="TCP port to listen to for control")
2014-10-25 11:34:52 +08:00
return parser.parse_args()
def main():
2014-10-25 11:34:52 +08:00
args = _get_args()
2014-12-31 17:41:22 +08:00
dpdb = DeviceParamDB("ddb.pyon", "pdb.pyon")
simplephist = SimpleParameterHistory(30)
dpdb.parameter_hooks.append(simplephist)
2014-12-31 17:41:22 +08:00
loop = asyncio.get_event_loop()
2014-12-31 17:41:22 +08:00
atexit.register(lambda: loop.close())
scheduler = Scheduler({
"req_device": dpdb.req_device,
2015-01-07 17:50:05 +08:00
"req_parameter": dpdb.req_parameter,
"set_parameter": dpdb.set_parameter
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_schedule": scheduler,
"master_dpdb": dpdb
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,
"periodic": scheduler.periodic,
"devices": dpdb.ddb,
"parameters": dpdb.pdb,
"parameters_simplehist": simplephist.history
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()