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
|
2014-10-05 16:25:31 +08:00
|
|
|
|
2014-10-27 14:33:45 +08:00
|
|
|
from artiq.management.pc_rpc import Server
|
2014-12-28 18:56:26 +08:00
|
|
|
from artiq.management.sync_struct import Publisher
|
2015-01-12 18:51:23 +08:00
|
|
|
from artiq.management.db import FlatFileDB, SimpleHistory
|
2014-10-05 16:25:31 +08:00
|
|
|
from artiq.management.scheduler import Scheduler
|
|
|
|
|
|
|
|
|
2014-10-25 11:34:52 +08:00
|
|
|
def _get_args():
|
2014-12-08 19:22:02 +08:00
|
|
|
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(
|
2015-01-13 03:55:50 +08:00
|
|
|
"--port-notify", default=3250, type=int,
|
2014-12-31 20:13:10 +08:00
|
|
|
help="TCP port to listen to for notifications")
|
2014-12-28 18:56:26 +08:00
|
|
|
parser.add_argument(
|
2015-01-13 03:55:50 +08:00
|
|
|
"--port-control", default=3251, type=int,
|
2014-12-31 20:13:10 +08:00
|
|
|
help="TCP port to listen to for control")
|
2014-10-25 11:34:52 +08:00
|
|
|
return parser.parse_args()
|
|
|
|
|
|
|
|
|
2015-01-13 19:12:19 +08:00
|
|
|
def init_rt_results(data):
|
|
|
|
print("init realtime results: " + str(data))
|
|
|
|
|
|
|
|
|
|
|
|
def update_rt_results(data):
|
|
|
|
print("update realtime results: " + str(data))
|
|
|
|
|
|
|
|
|
2014-10-05 16:25:31 +08:00
|
|
|
def main():
|
2014-10-25 11:34:52 +08:00
|
|
|
args = _get_args()
|
2015-01-02 15:28:45 +08:00
|
|
|
|
2015-01-12 18:51:23 +08:00
|
|
|
ddb = FlatFileDB("ddb.pyon")
|
|
|
|
pdb = FlatFileDB("pdb.pyon")
|
|
|
|
simplephist = SimpleHistory(30)
|
|
|
|
pdb.hooks.append(simplephist)
|
2014-12-31 17:41:22 +08:00
|
|
|
|
2014-10-05 16:25:31 +08:00
|
|
|
loop = asyncio.get_event_loop()
|
2014-12-31 17:41:22 +08:00
|
|
|
atexit.register(lambda: loop.close())
|
|
|
|
|
|
|
|
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,
|
|
|
|
"init_rt_results": init_rt_results,
|
|
|
|
"update_rt_results": update_rt_results
|
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-02 14:46:58 +08:00
|
|
|
"master_schedule": scheduler,
|
2015-01-12 18:51:23 +08:00
|
|
|
"master_ddb": ddb,
|
|
|
|
"master_pdb": pdb
|
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-02 14:46:58 +08:00
|
|
|
"periodic": scheduler.periodic,
|
2015-01-12 18:51:23 +08:00
|
|
|
"devices": ddb.data,
|
|
|
|
"parameters": pdb.data,
|
2015-01-02 15:28:45 +08:00
|
|
|
"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()
|
2014-10-05 16:25:31 +08:00
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
main()
|