forked from M-Labs/artiq
big changes but reasonable
This commit is contained in:
parent
c6194eb430
commit
12db9b106d
@ -363,61 +363,72 @@ class _DACWidget(_SimpleDisplayWidget):
|
|||||||
return (self.spi_channel, self.channel)
|
return (self.spi_channel, self.channel)
|
||||||
|
|
||||||
|
|
||||||
_WidgetDesc = namedtuple("_WidgetDesc", "uid comment cls arguments")
|
_ChannelDesc = namedtuple("_ChannelDesc", "name widget_type clss kwargs")
|
||||||
|
|
||||||
|
|
||||||
def setup_from_ddb(ddb):
|
def _setup_ttl(k, v, description):
|
||||||
mi_addr = None
|
|
||||||
mi_port = None
|
|
||||||
dds_sysclk = None
|
|
||||||
description = set()
|
|
||||||
|
|
||||||
for k, v in ddb.items():
|
|
||||||
try:
|
|
||||||
if isinstance(v, dict):
|
|
||||||
comment = v.get("comment")
|
|
||||||
if v["type"] == "local":
|
|
||||||
if v["module"] == "artiq.coredevice.ttl":
|
|
||||||
if "ttl_urukul" in k:
|
if "ttl_urukul" in k:
|
||||||
continue
|
return
|
||||||
channel = v["arguments"]["channel"]
|
channel = v["arguments"]["channel"]
|
||||||
force_out = v["class"] == "TTLOut"
|
channel_desc = _ChannelDesc(k, _TTLWidget, v["class"], {})
|
||||||
widget = _WidgetDesc(k, comment, _TTLWidget, (channel, force_out, k))
|
description[(channel, None)] = channel_desc
|
||||||
description.add(widget)
|
|
||||||
elif (v["module"] == "artiq.coredevice.ad9914" and v["class"] == "AD9914"):
|
|
||||||
|
def _setup_ad9914(k, v, description):
|
||||||
bus_channel = v["arguments"]["bus_channel"]
|
bus_channel = v["arguments"]["bus_channel"]
|
||||||
channel = v["arguments"]["channel"]
|
channel = v["arguments"]["channel"]
|
||||||
dds_sysclk = v["arguments"]["sysclk"]
|
dds_sysclk = v["arguments"]["sysclk"]
|
||||||
model = _DDSModel(v["class"], dds_sysclk)
|
channel_desc = _ChannelDesc(k, _DDSWidget, v["class"],
|
||||||
widget = _WidgetDesc(k, comment, _DDSWidget,
|
{"dds_sysclk": dds_sysclk})
|
||||||
(k, bus_channel, channel, model))
|
description[(bus_channel, channel)] = channel_desc
|
||||||
description.add(widget)
|
|
||||||
elif (v["module"] == "artiq.coredevice.ad9910" and v["class"] == "AD9910") or \
|
|
||||||
(v["module"] == "artiq.coredevice.ad9912" and v["class"] == "AD9912"):
|
def _setup_urukul(k, v, description, ddb):
|
||||||
channel = v["arguments"]["chip_select"] - 4
|
channel = v["arguments"]["chip_select"] - 4
|
||||||
if channel < 0:
|
if channel < 0:
|
||||||
continue
|
return
|
||||||
dds_cpld = v["arguments"]["cpld_device"]
|
dds_cpld = v["arguments"]["cpld_device"]
|
||||||
spi_dev = ddb[dds_cpld]["arguments"]["spi_device"]
|
spi_dev = ddb[dds_cpld]["arguments"]["spi_device"]
|
||||||
bus_channel = ddb[spi_dev]["arguments"]["channel"]
|
bus_channel = ddb[spi_dev]["arguments"]["channel"]
|
||||||
pll = v["arguments"]["pll_n"]
|
pll = v["arguments"]["pll_n"]
|
||||||
refclk = ddb[dds_cpld]["arguments"]["refclk"]
|
refclk = ddb[dds_cpld]["arguments"]["refclk"]
|
||||||
clk_div = v["arguments"].get("clk_div", 0)
|
clk_div = v["arguments"].get("clk_div", 0)
|
||||||
model = _DDSModel(v["class"], refclk, dds_cpld, pll, clk_div)
|
channel_desc = _ChannelDesc(k, _DDSWidget, v["class"],
|
||||||
widget = _WidgetDesc(k, comment, _DDSWidget,
|
{"refclk": refclk, "dds_cpld": dds_cpld,
|
||||||
(k, bus_channel, channel, model))
|
"pll": pll, "clk_div": clk_div})
|
||||||
description.add(widget)
|
description[(bus_channel, channel)] = channel_desc
|
||||||
elif (v["module"] == "artiq.coredevice.ad53xx" and v["class"] == "AD53xx") or \
|
|
||||||
(v["module"] == "artiq.coredevice.zotino" and v["class"] == "Zotino"):
|
|
||||||
|
def _setup_dac(k, v, description, ddb):
|
||||||
spi_device = v["arguments"]["spi_device"]
|
spi_device = v["arguments"]["spi_device"]
|
||||||
spi_device = ddb[spi_device]
|
spi_device = ddb[spi_device]
|
||||||
while isinstance(spi_device, str):
|
while isinstance(spi_device, str):
|
||||||
spi_device = ddb[spi_device]
|
spi_device = ddb[spi_device]
|
||||||
spi_channel = spi_device["arguments"]["channel"]
|
spi_channel = spi_device["arguments"]["channel"]
|
||||||
for channel in range(32):
|
for channel in range(32):
|
||||||
widget = _WidgetDesc((k, channel), comment, _DACWidget,
|
channel_desc = _ChannelDesc(k, _DACWidget, v["class"], {})
|
||||||
(spi_channel, channel, k))
|
description[(spi_channel, channel)] = channel_desc
|
||||||
description.add(widget)
|
|
||||||
|
|
||||||
|
def setup_from_ddb(ddb):
|
||||||
|
mi_addr = None
|
||||||
|
mi_port = None
|
||||||
|
description = dict() # (uid, channel) -> _ChannelDesc
|
||||||
|
|
||||||
|
for k, v in ddb.items():
|
||||||
|
try:
|
||||||
|
if isinstance(v, dict):
|
||||||
|
if v["type"] == "local":
|
||||||
|
if v["module"] == "artiq.coredevice.ttl":
|
||||||
|
_setup_ttl(k, v, description)
|
||||||
|
elif (v["module"] == "artiq.coredevice.ad9914" and v["class"] == "AD9914"):
|
||||||
|
_setup_ad9914(k, v, description)
|
||||||
|
elif (v["module"] == "artiq.coredevice.ad9910" and v["class"] == "AD9910") or \
|
||||||
|
(v["module"] == "artiq.coredevice.ad9912" and v["class"] == "AD9912"):
|
||||||
|
_setup_urukul(k, v, description, ddb)
|
||||||
|
elif (v["module"] == "artiq.coredevice.ad53xx" and v["class"] == "AD53xx") or \
|
||||||
|
(v["module"] == "artiq.coredevice.zotino" and v["class"] == "Zotino"):
|
||||||
|
_setup_dac(k, v, description, ddb)
|
||||||
elif v["type"] == "controller" and k == "core_moninj":
|
elif v["type"] == "controller" and k == "core_moninj":
|
||||||
mi_addr = v["host"]
|
mi_addr = v["host"]
|
||||||
mi_port = v.get("port_proxy", 1383)
|
mi_port = v.get("port_proxy", 1383)
|
||||||
@ -437,16 +448,14 @@ class _DeviceManager:
|
|||||||
self.schedule_ctl = schedule_ctl
|
self.schedule_ctl = schedule_ctl
|
||||||
|
|
||||||
self.ddb = dict()
|
self.ddb = dict()
|
||||||
self.description = set()
|
|
||||||
self.widgets_by_uid = dict()
|
# only modified by notify_ddb
|
||||||
|
self.description = dict()
|
||||||
|
|
||||||
|
self.displayed_channels = dict()
|
||||||
|
|
||||||
self.dds_sysclk = 0
|
self.dds_sysclk = 0
|
||||||
self.ttl_cb = lambda: None
|
self.refresh_display_cb = lambda: None
|
||||||
self.ttl_widgets = dict()
|
|
||||||
self.dds_cb = lambda: None
|
|
||||||
self.dds_widgets = dict()
|
|
||||||
self.dac_cb = lambda: None
|
|
||||||
self.dac_widgets = dict()
|
|
||||||
|
|
||||||
def init_ddb(self, ddb):
|
def init_ddb(self, ddb):
|
||||||
self.ddb = ddb
|
self.ddb = ddb
|
||||||
@ -454,55 +463,12 @@ class _DeviceManager:
|
|||||||
def notify_ddb(self, mod):
|
def notify_ddb(self, mod):
|
||||||
mi_addr, mi_port, description = setup_from_ddb(self.ddb)
|
mi_addr, mi_port, description = setup_from_ddb(self.ddb)
|
||||||
|
|
||||||
if (mi_addr, mi_port) != (self.mi_addr, self.mi_port):
|
if (mi_addr, mi_port, description) != (self.mi_addr, self.mi_port, self.description):
|
||||||
self.mi_addr = mi_addr
|
self.mi_addr = mi_addr
|
||||||
self.mi_port = mi_port
|
self.mi_port = mi_port
|
||||||
self.reconnect_mi.set()
|
|
||||||
|
|
||||||
for to_remove in self.description - description:
|
|
||||||
widget = self.widgets_by_uid[to_remove.uid]
|
|
||||||
del self.widgets_by_uid[to_remove.uid]
|
|
||||||
|
|
||||||
if isinstance(widget, _TTLWidget):
|
|
||||||
self.setup_ttl_monitoring(False, widget.channel)
|
|
||||||
widget.deleteLater()
|
|
||||||
del self.ttl_widgets[widget.channel]
|
|
||||||
self.ttl_cb()
|
|
||||||
elif isinstance(widget, _DDSWidget):
|
|
||||||
self.setup_dds_monitoring(False, widget.bus_channel, widget.channel)
|
|
||||||
widget.deleteLater()
|
|
||||||
del self.dds_widgets[(widget.bus_channel, widget.channel)]
|
|
||||||
self.dds_cb()
|
|
||||||
elif isinstance(widget, _DACWidget):
|
|
||||||
self.setup_dac_monitoring(False, widget.spi_channel, widget.channel)
|
|
||||||
widget.deleteLater()
|
|
||||||
del self.dac_widgets[(widget.spi_channel, widget.channel)]
|
|
||||||
self.dac_cb()
|
|
||||||
else:
|
|
||||||
raise ValueError
|
|
||||||
|
|
||||||
for to_add in description - self.description:
|
|
||||||
widget = to_add.cls(self, *to_add.arguments)
|
|
||||||
if to_add.comment is not None:
|
|
||||||
widget.setToolTip(to_add.comment)
|
|
||||||
self.widgets_by_uid[to_add.uid] = widget
|
|
||||||
|
|
||||||
if isinstance(widget, _TTLWidget):
|
|
||||||
self.ttl_widgets[widget.channel] = widget
|
|
||||||
self.ttl_cb()
|
|
||||||
self.setup_ttl_monitoring(True, widget.channel)
|
|
||||||
elif isinstance(widget, _DDSWidget):
|
|
||||||
self.dds_widgets[(widget.bus_channel, widget.channel)] = widget
|
|
||||||
self.dds_cb()
|
|
||||||
self.setup_dds_monitoring(True, widget.bus_channel, widget.channel)
|
|
||||||
elif isinstance(widget, _DACWidget):
|
|
||||||
self.dac_widgets[(widget.spi_channel, widget.channel)] = widget
|
|
||||||
self.dac_cb()
|
|
||||||
self.setup_dac_monitoring(True, widget.spi_channel, widget.channel)
|
|
||||||
else:
|
|
||||||
raise ValueError
|
|
||||||
|
|
||||||
self.description = description
|
self.description = description
|
||||||
|
self.refresh_display_cb()
|
||||||
|
self.reconnect_mi.set()
|
||||||
|
|
||||||
def ttl_set_mode(self, channel, mode):
|
def ttl_set_mode(self, channel, mode):
|
||||||
if self.mi_connection is not None:
|
if self.mi_connection is not None:
|
||||||
@ -655,6 +621,15 @@ class _DeviceManager:
|
|||||||
"ToggleDDS",
|
"ToggleDDS",
|
||||||
"Toggle DDS {} {}".format(dds_channel, "on" if sw else "off"))
|
"Toggle DDS {} {}".format(dds_channel, "on" if sw else "off"))
|
||||||
|
|
||||||
|
def setup_monitoring(self, uid, enable):
|
||||||
|
widget_type = self.description[uid].widget_type
|
||||||
|
if widget_type == "TTL":
|
||||||
|
self.setup_ttl_monitoring(enable, uid[0])
|
||||||
|
elif widget_type == "DDS":
|
||||||
|
self.setup_dds_monitoring(enable, *uid)
|
||||||
|
elif widget_type == "DAC":
|
||||||
|
self.setup_dac_monitoring(enable, *uid)
|
||||||
|
|
||||||
def setup_ttl_monitoring(self, enable, channel):
|
def setup_ttl_monitoring(self, enable, channel):
|
||||||
if self.mi_connection is not None:
|
if self.mi_connection is not None:
|
||||||
self.mi_connection.monitor_probe(enable, channel, TTLProbe.level.value)
|
self.mi_connection.monitor_probe(enable, channel, TTLProbe.level.value)
|
||||||
@ -673,30 +648,15 @@ class _DeviceManager:
|
|||||||
self.mi_connection.monitor_probe(enable, spi_channel, channel)
|
self.mi_connection.monitor_probe(enable, spi_channel, channel)
|
||||||
|
|
||||||
def monitor_cb(self, channel, probe, value):
|
def monitor_cb(self, channel, probe, value):
|
||||||
if channel in self.ttl_widgets:
|
if (channel, None) in self.displayed_channels:
|
||||||
widget = self.ttl_widgets[channel]
|
self.displayed_channels[(channel, None)].monitor_cb(probe, value)
|
||||||
if probe == TTLProbe.level.value:
|
elif (channel, probe) in self.displayed_channels:
|
||||||
widget.cur_level = bool(value)
|
self.displayed_channels[(channel, probe)].monitor_cb(probe, value)
|
||||||
elif probe == TTLProbe.oe.value:
|
|
||||||
widget.cur_oe = bool(value)
|
|
||||||
widget.refresh_display()
|
|
||||||
elif (channel, probe) in self.dds_widgets:
|
|
||||||
widget = self.dds_widgets[(channel, probe)]
|
|
||||||
widget.dds_model.monitor_update(probe, value)
|
|
||||||
widget.refresh_display()
|
|
||||||
elif (channel, probe) in self.dac_widgets:
|
|
||||||
widget = self.dac_widgets[(channel, probe)]
|
|
||||||
widget.cur_value = value
|
|
||||||
widget.refresh_display()
|
|
||||||
|
|
||||||
def injection_status_cb(self, channel, override, value):
|
def injection_status_cb(self, channel, override, value):
|
||||||
if channel in self.ttl_widgets:
|
if (channel, None) in self.displayed_channels and \
|
||||||
widget = self.ttl_widgets[channel]
|
self.description[(channel, None)].widget_type == "TTL":
|
||||||
if override == TTLOverride.en.value:
|
self.displayed_channels[(channel, None)].injection_status_cb(override, value)
|
||||||
widget.cur_override = bool(value)
|
|
||||||
if override == TTLOverride.level.value:
|
|
||||||
widget.cur_override_level = bool(value)
|
|
||||||
widget.refresh_display()
|
|
||||||
|
|
||||||
def disconnect_cb(self):
|
def disconnect_cb(self):
|
||||||
logger.error("lost connection to moninj")
|
logger.error("lost connection to moninj")
|
||||||
@ -722,12 +682,8 @@ class _DeviceManager:
|
|||||||
logger.info("ARTIQ dashboard connected to moninj (%s)",
|
logger.info("ARTIQ dashboard connected to moninj (%s)",
|
||||||
self.mi_addr)
|
self.mi_addr)
|
||||||
self.mi_connection = new_mi_connection
|
self.mi_connection = new_mi_connection
|
||||||
for ttl_channel in self.ttl_widgets.keys():
|
for key in self.displayed_channels:
|
||||||
self.setup_ttl_monitoring(True, ttl_channel)
|
self.setup_monitoring(key, True)
|
||||||
for bus_channel, channel in self.dds_widgets.keys():
|
|
||||||
self.setup_dds_monitoring(True, bus_channel, channel)
|
|
||||||
for spi_channel, channel in self.dac_widgets.keys():
|
|
||||||
self.setup_dac_monitoring(True, spi_channel, channel)
|
|
||||||
|
|
||||||
async def close(self):
|
async def close(self):
|
||||||
self.mi_connector_task.cancel()
|
self.mi_connector_task.cancel()
|
||||||
@ -756,9 +712,7 @@ class MonInjDock(QtWidgets.QDockWidget):
|
|||||||
scroll_area.setWidget(grid_widget)
|
scroll_area.setWidget(grid_widget)
|
||||||
|
|
||||||
self.dm = _DeviceManager(schedule_ctl)
|
self.dm = _DeviceManager(schedule_ctl)
|
||||||
self.dm.ttl_cb = lambda: self.layout_widgets(self.dm.ttl_widgets.values())
|
self.dm.refresh_display_cb = self.refresh_display_cb
|
||||||
self.dm.dds_cb = lambda: self.layout_widgets(self.dm.dds_widgets.values())
|
|
||||||
self.dm.dac_cb = lambda: self.layout_widgets(self.dm.dac_widgets.values())
|
|
||||||
|
|
||||||
def layout_widgets(self, widgets):
|
def layout_widgets(self, widgets):
|
||||||
for widget in sorted(widgets, key=lambda w: w.sort_key()):
|
for widget in sorted(widgets, key=lambda w: w.sort_key()):
|
||||||
|
Loading…
Reference in New Issue
Block a user