def __init__(self, dut): super(MainPanel, self).__init__() self.dut = dut self.get_freq_mhz() self.get_decimation() self.decimation_points = None data, reflevel = read_data_and_reflevel(dut) self.screen = SpectrumView( compute_fft(dut, data, reflevel), self.center_freq, self.decimation_factor) self.initUI()
def __init__(self, dut): super(MainPanel, self).__init__() self.dut = dut self.center_freq = None self.decimation_factor = None self.decimation_points = None self.screen = SpectrumView() self.initDUT() self.initUI()
def __init__(self, dut): super(MainPanel, self).__init__() self.dut = dut self.mhz_bottom, self.mhz_top = (f/10**6 for f in dut.SWEEP_FREQ_RANGE) self.center_freq = None self.decimation_factor = None self.decimation_points = None self.screen = SpectrumView() self.initDUT() self.initUI()
class MainPanel(QtGui.QWidget): """ The spectrum view and controls """ def __init__(self, dut): super(MainPanel, self).__init__() self.dut = dut self.center_freq = None self.decimation_factor = None self.decimation_points = None self.screen = SpectrumView() self.initDUT() self.initUI() @inlineCallbacks def initDUT(self): self.center_freq = yield self.dut.freq() self.decimation_factor = yield self.dut.decimation() yield self.dut.request_read_perm() while True: data, reflevel = yield twisted_util.read_data_and_reflevel( self.dut, self.points) self.screen.update_data( compute_fft(self.dut, data, reflevel), self.center_freq, self.decimation_factor) def initUI(self): grid = QtGui.QGridLayout() grid.setSpacing(10) grid.addWidget(self.screen, 0, 0, 8, 1) grid.setColumnMinimumWidth(0, 400) y = 0 grid.addWidget(self._antenna_control(), y, 1, 1, 2) grid.addWidget(self._bpf_control(), y, 3, 1, 2) y += 1 grid.addWidget(self._gain_control(), y, 1, 1, 2) grid.addWidget(QtGui.QLabel('IF Gain:'), y, 3, 1, 1) grid.addWidget(self._ifgain_control(), y, 4, 1, 1) y += 1 freq, steps, freq_plus, freq_minus = self._freq_controls() grid.addWidget(QtGui.QLabel('Center Freq:'), y, 1, 1, 1) grid.addWidget(freq, y, 2, 1, 2) grid.addWidget(QtGui.QLabel('MHz'), y, 4, 1, 1) y += 1 grid.addWidget(steps, y, 2, 1, 2) grid.addWidget(freq_minus, y, 1, 1, 1) grid.addWidget(freq_plus, y, 4, 1, 1) y += 1 span, rbw = self._span_rbw_controls() grid.addWidget(span, y, 1, 1, 2) grid.addWidget(rbw, y, 3, 1, 2) self.setLayout(grid) self.show() @inlineCallbacks def _read_update_antenna_box(self): ant = yield self.dut.antenna() self._antenna_box.setCurrentIndex(ant - 1) def _antenna_control(self): antenna = QtGui.QComboBox(self) antenna.addItem("Antenna 1") antenna.addItem("Antenna 2") self._antenna_box = antenna self._read_update_antenna_box() def new_antenna(): self.dut.antenna(int(antenna.currentText().split()[-1])) antenna.currentIndexChanged.connect(new_antenna) return antenna @inlineCallbacks def _read_update_bpf_box(self): bpf = yield self.dut.preselect_filter() self._bpf_box.setCurrentIndex(0 if bpf else 1) def _bpf_control(self): bpf = QtGui.QComboBox(self) bpf.addItem("BPF On") bpf.addItem("BPF Off") self._bpf_box = bpf self._read_update_bpf_box() def new_bpf(): self.dut.preselect_filter("On" in bpf.currentText()) bpf.currentIndexChanged.connect(new_bpf) return bpf @inlineCallbacks def _read_update_gain_box(self): gain = yield self.dut.gain() self._gain_box.setCurrentIndex(self._gain_values.index(gain)) def _gain_control(self): gain = QtGui.QComboBox(self) gain_values = ['High', 'Med', 'Low', 'VLow'] for g in gain_values: gain.addItem("RF Gain: %s" % g) self._gain_values = [g.lower() for g in gain_values] self._gain_box = gain self._read_update_gain_box() def new_gain(): g = gain.currentText().split()[-1].lower().encode('ascii') self.dut.gain(g) gain.currentIndexChanged.connect(new_gain) return gain @inlineCallbacks def _read_update_ifgain_box(self): ifgain = yield self.dut.ifgain() self._ifgain_box.setValue(int(ifgain)) def _ifgain_control(self): ifgain = QtGui.QSpinBox(self) ifgain.setRange(-10, 34) ifgain.setSuffix(" dB") self._ifgain_box = ifgain self._read_update_ifgain_box() def new_ifgain(): self.dut.ifgain(ifgain.value()) ifgain.valueChanged.connect(new_ifgain) return ifgain @inlineCallbacks def _read_update_freq_edit(self): "Get current frequency from self.dut and update the edit box" self._update_freq_edit() # once immediately in case of long delay self.center_freq = yield self.dut.freq() self._update_freq_edit() def _update_freq_edit(self): "Update the frequency edit box from self.center_freq" if self.center_freq is None: self._freq_edit.setText("---") else: self._freq_edit.setText("%0.1f" % (self.center_freq / 1e6)) def _freq_controls(self): freq = QtGui.QLineEdit("") self._freq_edit = freq self._read_update_freq_edit() def write_freq(): try: f = float(freq.text()) except ValueError: return self.set_freq_mhz(f) freq.editingFinished.connect(write_freq) steps = QtGui.QComboBox(self) steps.addItem("Adjust: 1 MHz") steps.addItem("Adjust: 2.5 MHz") steps.addItem("Adjust: 10 MHz") steps.addItem("Adjust: 25 MHz") steps.addItem("Adjust: 100 MHz") steps.setCurrentIndex(2) def freq_step(factor): try: f = float(freq.text()) except ValueError: self._update_freq_edit() return delta = float(steps.currentText().split()[1]) * factor freq.setText("%0.1f" % (f + delta)) write_freq() freq_minus = QtGui.QPushButton('-') freq_minus.clicked.connect(lambda: freq_step(-1)) freq_plus = QtGui.QPushButton('+') freq_plus.clicked.connect(lambda: freq_step(1)) return freq, steps, freq_plus, freq_minus @inlineCallbacks def _read_update_span_rbw_boxes(self): self.decimation_factor = yield self.dut.decimation() self._span_box.setCurrentIndex( self._decimation_values.index(self.decimation_factor)) self._update_rbw_box() def _update_rbw_box(self): d = self.decimation_factor for i, p in enumerate(self._points_values): r = DEVICE_FULL_SPAN / d / p self._rbw_box.setItemText(i, "RBW: %s" % frequency_text(r)) if self.decimation_points and self.decimation_points == d * p: self._rbw_box.setCurrentIndex(i) self.points = self._points_values[self._rbw_box.currentIndex()] def _span_rbw_controls(self): span = QtGui.QComboBox(self) decimation_values = [1] + [2 ** x for x in range(2, 10)] for d in decimation_values: span.addItem("Span: %s" % frequency_text(DEVICE_FULL_SPAN / d)) self._decimation_values = decimation_values self._span_box = span def new_span(): self.set_decimation(decimation_values[span.currentIndex()]) self._update_rbw_box() span.currentIndexChanged.connect(new_span) rbw = QtGui.QComboBox(self) self._points_values = [2 ** x for x in range(8, 16)] self._rbw_box = rbw rbw.addItems([str(p) for p in self._points_values]) self._read_update_span_rbw_boxes() def new_rbw(): self.points = self._points_values[rbw.currentIndex()] self.decimation_points = self.decimation_factor * self.points rbw.setCurrentIndex(self._points_values.index(1024)) #new_rbw() rbw.currentIndexChanged.connect(new_rbw) return span, rbw def update_screen(self): data, reflevel = read_data_and_reflevel( self.dut, self.points) self.screen.update_data( compute_fft(self.dut, data, reflevel), self.center_freq, self.decimation_factor) def set_freq_mhz(self, f): self.center_freq = f * 1e6 self.dut.freq(self.center_freq) def set_decimation(self, d): self.decimation_factor = 1 if d == 0 else d self.dut.decimation(d)
class MainPanel(QtGui.QWidget): def __init__(self, dut): super(MainPanel, self).__init__() self.dut = dut self.get_freq_mhz() self.get_decimation() self.decimation_points = None data, reflevel = read_data_and_reflevel(dut) self.screen = SpectrumView( compute_fft(dut, data, reflevel), self.center_freq, self.decimation_factor) self.initUI() def initUI(self): grid = QtGui.QGridLayout() grid.setSpacing(10) grid.addWidget(self.screen, 0, 0, 8, 1) grid.setColumnMinimumWidth(0, 400) y = 0 grid.addWidget(self._antenna_control(), y, 1, 1, 2) grid.addWidget(self._bpf_control(), y, 3, 1, 2) y += 1 grid.addWidget(self._gain_control(), y, 1, 1, 2) grid.addWidget(QtGui.QLabel('IF Gain:'), y, 3, 1, 1) grid.addWidget(self._ifgain_control(), y, 4, 1, 1) y += 1 freq, steps, freq_plus, freq_minus = self._freq_controls() grid.addWidget(QtGui.QLabel('Center Freq:'), y, 1, 1, 1) grid.addWidget(freq, y, 2, 1, 2) grid.addWidget(QtGui.QLabel('MHz'), y, 4, 1, 1) y += 1 grid.addWidget(steps, y, 2, 1, 2) grid.addWidget(freq_minus, y, 1, 1, 1) grid.addWidget(freq_plus, y, 4, 1, 1) y += 1 span, rbw = self._span_rbw_controls() grid.addWidget(span, y, 1, 1, 2) grid.addWidget(rbw, y, 3, 1, 2) self.setLayout(grid) self.show() def _antenna_control(self): antenna = QtGui.QComboBox(self) antenna.addItem("Antenna 1") antenna.addItem("Antenna 2") antenna.setCurrentIndex(self.dut.antenna() - 1) def new_antenna(): self.dut.antenna(int(antenna.currentText().split()[-1])) antenna.currentIndexChanged.connect(new_antenna) return antenna def _bpf_control(self): bpf = QtGui.QComboBox(self) bpf.addItem("BPF On") bpf.addItem("BPF Off") bpf.setCurrentIndex(0 if self.dut.preselect_filter() else 1) def new_bpf(): self.dut.preselect_filter("On" in bpf.currentText()) bpf.currentIndexChanged.connect(new_bpf) return bpf def _gain_control(self): gain = QtGui.QComboBox(self) gain_values = ['High', 'Med', 'Low', 'VLow'] for g in gain_values: gain.addItem("RF Gain: %s" % g) gain_index = [g.lower() for g in gain_values].index(self.dut.gain()) gain.setCurrentIndex(gain_index) def new_gain(): self.dut.gain(gain.currentText().split()[-1].lower()) gain.currentIndexChanged.connect(new_gain) return gain def _ifgain_control(self): ifgain = QtGui.QSpinBox(self) ifgain.setRange(-10, 34) ifgain.setSuffix(" dB") ifgain.setValue(int(self.dut.ifgain())) def new_ifgain(): self.dut.ifgain(ifgain.value()) ifgain.valueChanged.connect(new_ifgain) return ifgain def _freq_controls(self): freq = QtGui.QLineEdit("") def read_freq(): freq.setText("%0.1f" % self.get_freq_mhz()) read_freq() def write_freq(): try: f = float(freq.text()) except ValueError: return self.set_freq_mhz(f) freq.editingFinished.connect(write_freq) steps = QtGui.QComboBox(self) steps.addItem("Adjust: 1 MHz") steps.addItem("Adjust: 2.5 MHz") steps.addItem("Adjust: 10 MHz") steps.addItem("Adjust: 25 MHz") steps.addItem("Adjust: 100 MHz") steps.setCurrentIndex(2) def freq_step(factor): try: f = float(freq.text()) except ValueError: return read_freq() delta = float(steps.currentText().split()[1]) * factor freq.setText("%0.1f" % (f + delta)) write_freq() freq_minus = QtGui.QPushButton('-') freq_minus.clicked.connect(lambda: freq_step(-1)) freq_plus = QtGui.QPushButton('+') freq_plus.clicked.connect(lambda: freq_step(1)) return freq, steps, freq_plus, freq_minus def _span_rbw_controls(self): span = QtGui.QComboBox(self) decimation_values = [1] + [2 ** x for x in range(2, 10)] for d in decimation_values: span.addItem("Span: %s" % frequency_text(DEVICE_FULL_SPAN / d)) span.setCurrentIndex(decimation_values.index(self.dut.decimation())) def new_span(): self.set_decimation(decimation_values[span.currentIndex()]) build_rbw() span.currentIndexChanged.connect(new_span) rbw = QtGui.QComboBox(self) points_values = [2 ** x for x in range(8, 16)] rbw.addItems([str(p) for p in points_values]) def build_rbw(): d = self.decimation_factor for i, p in enumerate(points_values): r = DEVICE_FULL_SPAN / d / p rbw.setItemText(i, "RBW: %s" % frequency_text(r)) if self.decimation_points and self.decimation_points == d * p: rbw.setCurrentIndex(i) self.points = points_values[rbw.currentIndex()] build_rbw() def new_rbw(): self.points = points_values[rbw.currentIndex()] self.decimation_points = self.decimation_factor * self.points rbw.setCurrentIndex(points_values.index(1024)) new_rbw() rbw.currentIndexChanged.connect(new_rbw) return span, rbw def update_screen(self): data, reflevel = read_data_and_reflevel( self.dut, self.points) self.screen.update_data( compute_fft(self.dut, data, reflevel), self.center_freq, self.decimation_factor) def get_freq_mhz(self): self.center_freq = self.dut.freq() return self.center_freq / 1e6 def set_freq_mhz(self, f): self.center_freq = f * 1e6 self.dut.freq(self.center_freq) def get_decimation(self): d = self.dut.decimation() self.decimation_factor = 1 if d == 0 else d def set_decimation(self, d): self.decimation_factor = 1 if d == 0 else d self.dut.decimation(d)