waveform, comm_analyzer add cursor label unit

pull/2342/head
Simon Renblad 2024-02-20 11:07:10 +08:00 committed by Sébastien Bourdeauducq
parent edd23977f8
commit 779b7704ed
2 changed files with 34 additions and 34 deletions

View File

@ -248,7 +248,7 @@ class VCDManager:
def set_timescale_ps(self, timescale):
self.out.write("$timescale {}ps $end\n".format(round(timescale)))
def get_channel(self, name, width, ty, ndecimals=0):
def get_channel(self, name, width, ty, precision=0, unit=""):
code = next(self.codes)
self.out.write("$var wire {width} {code} {name} $end\n"
.format(name=name, code=code, width=width))
@ -285,9 +285,9 @@ class WaveformManager:
def set_timescale_ps(self, timescale):
self.trace["timescale"] = int(timescale)
def get_channel(self, name, width, ty, ndecimals=0):
def get_channel(self, name, width, ty, precision=0, unit=""):
if ty == WaveformType.LOG:
self.trace["logs"][self.current_scope + name] = (width, ty, ndecimals)
self.trace["logs"][self.current_scope + name] = (ty, width, precision, unit)
data = self.trace["data"][self.current_scope + name] = list()
channel = WaveformChannel(data, self.current_time)
self.channels.append(channel)
@ -338,8 +338,8 @@ class ChannelSignatureManager:
self.current_scope = ""
self.channels = dict()
def get_channel(self, name, width, ty, ndecimals=0):
self.channels[self.current_scope + name] = (width, ty, ndecimals)
def get_channel(self, name, width, ty, precision=0, unit=""):
self.channels[self.current_scope + name] = (ty, width, precision, unit)
return None
@contextmanager
@ -381,9 +381,9 @@ class TTLClockGenHandler:
def __init__(self, manager, name, ref_period):
self.name = name
self.ref_period = ref_period
ndecimals = max(0, math.ceil(math.log10(2**24 * ref_period)))
precision = max(0, math.ceil(math.log10(2**24 * ref_period) + 6))
self.channel_frequency = manager.get_channel(
"ttl_clkgen/" + name, 64, ty=WaveformType.ANALOG, ndecimals=ndecimals)
"ttl_clkgen/" + name, 64, ty=WaveformType.ANALOG, precision=precision, unit="MHz")
def process_message(self, message):
if isinstance(message, OutputMessage):
@ -404,17 +404,18 @@ class DDSHandler:
def add_dds_channel(self, name, dds_channel_nr):
dds_channel = dict()
frequency_decimals = max(0, math.ceil(math.log10(2**32 / self.sysclk)))
phase_decimals = max(0, math.ceil(math.log10(2**16)))
frequency_precision = max(0, math.ceil(math.log10(2**32 / self.sysclk) + 6))
phase_precision = max(0, math.ceil(math.log10(2**16)))
with self.manager.scope("dds", name):
dds_channel["vcd_frequency"] = \
self.manager.get_channel(name + "/frequency", 64,
ty=WaveformType.ANALOG,
ndecimals=frequency_decimals)
precision=frequency_precision,
unit="MHz")
dds_channel["vcd_phase"] = \
self.manager.get_channel(name + "/phase", 64,
ty=WaveformType.ANALOG,
ndecimals=phase_decimals)
precision=phase_precision)
dds_channel["ftw"] = [None, None]
dds_channel["pow"] = None
self.dds_channels[dds_channel_nr] = dds_channel
@ -691,8 +692,8 @@ def get_channel_list(devices):
ref_period = get_ref_period(devices)
if ref_period is None:
ref_period = DEFAULT_REF_PERIOD
ndecimals = max(0, math.ceil(math.log10(1 / ref_period)))
manager.get_channel("rtio_slack", 64, ty=WaveformType.ANALOG, ndecimals=ndecimals)
precision = max(0, math.ceil(math.log10(1 / ref_period) - 6))
manager.get_channel("rtio_slack", 64, ty=WaveformType.ANALOG, precision=precision, unit="us")
return manager.channels

View File

@ -15,7 +15,7 @@ from sipyco.sync_struct import Subscriber
from sipyco.pc_rpc import AsyncioClient
from sipyco import pyon
from artiq.tools import exc_to_warning
from artiq.tools import exc_to_warning, short_format
from artiq.coredevice import comm_analyzer
from artiq.coredevice.comm_analyzer import WaveformType
from artiq.gui.tools import LayoutWidget, get_open_file_name, get_save_file_name
@ -133,7 +133,7 @@ class _BackgroundItem(pg.GraphicsWidgetAnchor, pg.GraphicsWidget):
class _BaseWaveform(pg.PlotWidget):
cursorMove = QtCore.pyqtSignal(float)
def __init__(self, name, width, ndecimals,
def __init__(self, name, width, precision, unit,
parent=None, pen="r", stepMode="right", connect="finite"):
pg.PlotWidget.__init__(self,
parent=parent,
@ -150,7 +150,8 @@ class _BaseWaveform(pg.PlotWidget):
self.name = name
self.width = width
self.ndecimals = ndecimals
self.precision = precision
self.unit = unit
self.x_data = []
self.y_data = []
@ -240,8 +241,8 @@ class _BaseWaveform(pg.PlotWidget):
class BitWaveform(_BaseWaveform):
def __init__(self, name, width, ndecimals, parent=None):
_BaseWaveform.__init__(self, name, width, ndecimals, parent)
def __init__(self, name, width, precision, unit, parent=None):
_BaseWaveform.__init__(self, name, width, precision, unit, parent)
self.plot_item.showGrid(x=True, y=False)
self._arrows = []
@ -287,9 +288,8 @@ class BitWaveform(_BaseWaveform):
class AnalogWaveform(_BaseWaveform):
def __init__(self, name, width, ndecimals, parent=None):
_BaseWaveform.__init__(self, name, width, ndecimals, parent)
self._format_string = "{:." + str(ndecimals) + "f}"
def __init__(self, name, width, precision, unit, parent=None):
_BaseWaveform.__init__(self, name, width, precision, unit, parent)
def onDataChange(self, data):
try:
@ -306,15 +306,15 @@ class AnalogWaveform(_BaseWaveform):
def onCursorMove(self, x):
_BaseWaveform.onCursorMove(self, x)
if self.cursor_y is not None:
t = self._format_string.format(self.cursor_y)
t = short_format(self.cursor_y, {"precision": self.precision, "unit": self.unit})
else:
t = ""
self.cursor_label.setText(t)
class BitVectorWaveform(_BaseWaveform):
def __init__(self, name, width, ndecimals, parent=None):
_BaseWaveform.__init__(self, name, width, ndecimals, parent)
def __init__(self, name, width, precision, unit, parent=None):
_BaseWaveform.__init__(self, name, width, precision, parent)
self._labels = []
self._format_string = "{:0=" + str(math.ceil(width / 4)) + "X}"
self.view_box.sigTransformChanged.connect(self._update_labels)
@ -372,8 +372,8 @@ class BitVectorWaveform(_BaseWaveform):
class LogWaveform(_BaseWaveform):
def __init__(self, name, width, ndecimals, parent=None):
_BaseWaveform.__init__(self, name, width, ndecimals, parent)
def __init__(self, name, width, precision, unit, parent=None):
_BaseWaveform.__init__(self, name, width, precision, parent)
self.plot_data_item.opts['pen'] = None
self.plot_data_item.opts['symbol'] = 'x'
self._labels = []
@ -521,15 +521,15 @@ class _WaveformView(QtWidgets.QWidget):
self._splitter.widget(i).onCursorMove(x)
def _create_waveform(self, row):
name, ty, width, ndecimals = (
self._model.data(self._model.index(row, i)) for i in range(4))
name, ty, width, precision, unit = (
self._model.data(self._model.index(row, i)) for i in range(5))
waveform_cls = {
WaveformType.BIT: BitWaveform,
WaveformType.VECTOR: BitVectorWaveform,
WaveformType.ANALOG: AnalogWaveform,
WaveformType.LOG: LogWaveform
}[ty]
w = waveform_cls(name, width, ndecimals, parent=self._splitter)
w = waveform_cls(name, width, precision, unit, parent=self._splitter)
w.setXLink(self._ref_vb)
w.setStoppedX(self._stopped_x)
w.setTimescale(self._timescale)
@ -555,7 +555,7 @@ class _WaveformView(QtWidgets.QWidget):
class _WaveformModel(QtCore.QAbstractTableModel):
def __init__(self):
self.backing_struct = []
self.headers = ["name", "type", "width", "ndecimals", "data"]
self.headers = ["name", "type", "width", "precision", "unit", "data"]
QtCore.QAbstractTableModel.__init__(self)
def rowCount(self, parent=QtCore.QModelIndex()):
@ -596,11 +596,11 @@ class _WaveformModel(QtCore.QAbstractTableModel):
self.endRemoveRows()
def export_list(self):
return [[row[0], row[1].value, row[2], row[3]] for row in self.backing_struct]
return [[row[0], row[1].value, *row[2:5]] for row in self.backing_struct]
def import_list(self, channel_list):
self.clear()
data = [[row[0], WaveformType(row[1]), row[2], row[3], []] for row in channel_list]
data = [[row[0], WaveformType(row[1]), *row[2:5], []] for row in channel_list]
self.extend(data)
def update_data(self, waveform_data, top, bottom):
@ -708,8 +708,7 @@ class _AddChannelDialog(QtWidgets.QDialog):
for select in selection:
key = self._model.index_to_key(select)
if key is not None:
width, ty, ndecimals = self._model[key].ref
channels.append([key, ty, width, ndecimals, []])
channels.append([key, *self._model[key].ref, []])
self.accepted.emit(channels)
self.close()