vco_only.py 10.3 KB
#!/usr/bin/env python2
# -*- coding: utf-8 -*-
##################################################
# GNU Radio Python Flow Graph
# Title: Vco Only
# Generated: Thu Apr 6 18:24:10 2017
##################################################
if __name__ == '__main__':
import ctypes
import sys
if sys.platform.startswith('linux'):
try:
x11 = ctypes.cdll.LoadLibrary('libX11.so')
x11.XInitThreads()
except:
print "Warning: failed to XInitThreads()"
from PyQt4 import Qt
from gnuradio import eng_notation
from gnuradio import gr
from gnuradio.eng_option import eng_option
from gnuradio.filter import firdes
from gnuradio.qtgui import Range, RangeWidget
from optparse import OptionParser
import redpitaya_gnuradio
import sys
class vco_only(gr.top_block, Qt.QWidget):
def __init__(self):
gr.top_block.__init__(self, "Vco Only")
Qt.QWidget.__init__(self)
self.setWindowTitle("Vco Only")
try:
self.setWindowIcon(Qt.QIcon.fromTheme('gnuradio-grc'))
except:
pass
self.top_scroll_layout = Qt.QVBoxLayout()
self.setLayout(self.top_scroll_layout)
self.top_scroll = Qt.QScrollArea()
self.top_scroll.setFrameStyle(Qt.QFrame.NoFrame)
self.top_scroll_layout.addWidget(self.top_scroll)
self.top_scroll.setWidgetResizable(True)
self.top_widget = Qt.QWidget()
self.top_scroll.setWidget(self.top_widget)
self.top_layout = Qt.QVBoxLayout(self.top_widget)
self.top_grid_layout = Qt.QGridLayout()
self.top_layout.addLayout(self.top_grid_layout)
self.settings = Qt.QSettings("GNU Radio", "vco_only")
self.restoreGeometry(self.settings.value("geometry").toByteArray())
##################################################
# Variables
##################################################
self.port = port = 1001
self.off_sw = off_sw = 0
self.inc_sw = inc_sw = 0
self.dds_range = dds_range = 0
self.dds_offset = dds_offset = 0
self.dds_nco = dds_nco = 0
self.dds_f0 = dds_f0 = 0
self.dds_ampl = dds_ampl = 0
self.dac1_offset = dac1_offset = 0
self.addr = addr = "192.168.0.202"
self.adc1_offset = adc1_offset = 0
##################################################
# Blocks
##################################################
_off_sw_check_box = Qt.QCheckBox('off_sw')
self._off_sw_choices = {True: 1, False: 0}
self._off_sw_choices_inv = dict((v,k) for k,v in self._off_sw_choices.iteritems())
self._off_sw_callback = lambda i: Qt.QMetaObject.invokeMethod(_off_sw_check_box, "setChecked", Qt.Q_ARG("bool", self._off_sw_choices_inv[i]))
self._off_sw_callback(self.off_sw)
_off_sw_check_box.stateChanged.connect(lambda i: self.set_off_sw(self._off_sw_choices[bool(i)]))
self.top_grid_layout.addWidget(_off_sw_check_box, 2, 2)
_inc_sw_check_box = Qt.QCheckBox('inc_sw')
self._inc_sw_choices = {True: 1, False: 0}
self._inc_sw_choices_inv = dict((v,k) for k,v in self._inc_sw_choices.iteritems())
self._inc_sw_callback = lambda i: Qt.QMetaObject.invokeMethod(_inc_sw_check_box, "setChecked", Qt.Q_ARG("bool", self._inc_sw_choices_inv[i]))
self._inc_sw_callback(self.inc_sw)
_inc_sw_check_box.stateChanged.connect(lambda i: self.set_inc_sw(self._inc_sw_choices[bool(i)]))
self.top_grid_layout.addWidget(_inc_sw_check_box, 2, 1)
self._dds_range_range = Range(0, 2**13-1, 1, 0, 200)
self._dds_range_win = RangeWidget(self._dds_range_range, self.set_dds_range, 'dds_range', "counter_slider", int)
self.top_grid_layout.addWidget(self._dds_range_win, 5, 3)
self._dds_offset_range = Range(-2**13, 2**13-1, 1, 0, 200)
self._dds_offset_win = RangeWidget(self._dds_offset_range, self.set_dds_offset, 'dds_offset', "counter_slider", int)
self.top_grid_layout.addWidget(self._dds_offset_win, 3, 3)
self._dds_nco_range = Range(0, 60000000, 1, 0, 200)
self._dds_nco_win = RangeWidget(self._dds_nco_range, self.set_dds_nco, 'dds_nco', "counter_slider", int)
self.top_grid_layout.addWidget(self._dds_nco_win, 2, 3)
self._dds_f0_range = Range(0, 60000000, 1000, 0, 200)
self._dds_f0_win = RangeWidget(self._dds_f0_range, self.set_dds_f0, 'dds_f0', "counter_slider", int)
self.top_grid_layout.addWidget(self._dds_f0_win, 4, 3)
self._dds_ampl_range = Range(0, 2**13-1, 1, 0, 200)
self._dds_ampl_win = RangeWidget(self._dds_ampl_range, self.set_dds_ampl, 'dds_ampl', "counter_slider", int)
self.top_grid_layout.addWidget(self._dds_ampl_win, 1, 3)
self._dac1_offset_range = Range(-2**13, 2**13-1, 1, 0, 200)
self._dac1_offset_win = RangeWidget(self._dac1_offset_range, self.set_dac1_offset, 'dac1_offset', "counter_slider", int)
self.top_grid_layout.addWidget(self._dac1_offset_win, 1, 2)
self._adc1_offset_range = Range(-2**13, 2**13-1, 1, 0, 200)
self._adc1_offset_win = RangeWidget(self._adc1_offset_range, self.set_adc1_offset, 'adc1_offset', "counter_slider", int)
self.top_grid_layout.addWidget(self._adc1_offset_win, 1, 1)
self.nco_counter_send_conf_0 = redpitaya_gnuradio.nco_counter_send_conf(
addr=addr,
port=port,
device='/dev/dds_nco',
freq_ref=125000000,
freq_dds=dds_nco,
acc_size=32,
offset=0,
pinc_sw=inc_sw,
poff_sw=off_sw,
)
self.add_const_set_offset_0_0_0_0_1_0 = redpitaya_gnuradio.add_const_set_offset(
addr=addr,
port=port,
device='/dev/dds_f0',
const=int(dds_f0/(125e6/2**32)),
)
self.add_const_set_offset_0_0_0_0_1 = redpitaya_gnuradio.add_const_set_offset(
addr=addr,
port=port,
device='/dev/dds_offset',
const=dds_offset,
)
self.add_const_set_offset_0_0_0_0_0_0 = redpitaya_gnuradio.add_const_set_offset(
addr=addr,
port=port,
device='/dev/dds_range',
const=dds_range,
)
self.add_const_set_offset_0_0_0_0_0 = redpitaya_gnuradio.add_const_set_offset(
addr=addr,
port=port,
device='/dev/dds_ampl',
const=dds_ampl,
)
self.add_const_set_offset_0_0_0_0 = redpitaya_gnuradio.add_const_set_offset(
addr=addr,
port=port,
device='/dev/dac1_offset',
const=dac1_offset,
)
self.add_const_set_offset_0_0_0 = redpitaya_gnuradio.add_const_set_offset(
addr=addr,
port=port,
device='/dev/adc1_offset',
const=adc1_offset,
)
def closeEvent(self, event):
self.settings = Qt.QSettings("GNU Radio", "vco_only")
self.settings.setValue("geometry", self.saveGeometry())
event.accept()
def get_port(self):
return self.port
def set_port(self, port):
self.port = port
def get_off_sw(self):
return self.off_sw
def set_off_sw(self, off_sw):
self.off_sw = off_sw
self._off_sw_callback(self.off_sw)
self.nco_counter_send_conf_0.set_nco(device='/dev/dds_nco', freq_ref=125000000, freq_dds=self.dds_nco, acc_size=32, offset=0, pinc_sw=self.inc_sw, poff_sw=self.off_sw)
def get_inc_sw(self):
return self.inc_sw
def set_inc_sw(self, inc_sw):
self.inc_sw = inc_sw
self._inc_sw_callback(self.inc_sw)
self.nco_counter_send_conf_0.set_nco(device='/dev/dds_nco', freq_ref=125000000, freq_dds=self.dds_nco, acc_size=32, offset=0, pinc_sw=self.inc_sw, poff_sw=self.off_sw)
def get_dds_range(self):
return self.dds_range
def set_dds_range(self, dds_range):
self.dds_range = dds_range
self.add_const_set_offset_0_0_0_0_0_0.set_const(device='/dev/dds_range', const=self.dds_range)
def get_dds_offset(self):
return self.dds_offset
def set_dds_offset(self, dds_offset):
self.dds_offset = dds_offset
self.add_const_set_offset_0_0_0_0_1.set_const(device='/dev/dds_offset', const=self.dds_offset)
def get_dds_nco(self):
return self.dds_nco
def set_dds_nco(self, dds_nco):
self.dds_nco = dds_nco
self.nco_counter_send_conf_0.set_nco(device='/dev/dds_nco', freq_ref=125000000, freq_dds=self.dds_nco, acc_size=32, offset=0, pinc_sw=self.inc_sw, poff_sw=self.off_sw)
def get_dds_f0(self):
return self.dds_f0
def set_dds_f0(self, dds_f0):
self.dds_f0 = dds_f0
self.add_const_set_offset_0_0_0_0_1_0.set_const(device='/dev/dds_f0', const=int(self.dds_f0/(125e6/2**32)))
def get_dds_ampl(self):
return self.dds_ampl
def set_dds_ampl(self, dds_ampl):
self.dds_ampl = dds_ampl
self.add_const_set_offset_0_0_0_0_0.set_const(device='/dev/dds_ampl', const=self.dds_ampl)
def get_dac1_offset(self):
return self.dac1_offset
def set_dac1_offset(self, dac1_offset):
self.dac1_offset = dac1_offset
self.add_const_set_offset_0_0_0_0.set_const(device='/dev/dac1_offset', const=self.dac1_offset)
def get_addr(self):
return self.addr
def set_addr(self, addr):
self.addr = addr
def get_adc1_offset(self):
return self.adc1_offset
def set_adc1_offset(self, adc1_offset):
self.adc1_offset = adc1_offset
self.add_const_set_offset_0_0_0.set_const(device='/dev/adc1_offset', const=self.adc1_offset)
def main(top_block_cls=vco_only, options=None):
from distutils.version import StrictVersion
if StrictVersion(Qt.qVersion()) >= StrictVersion("4.5.0"):
style = gr.prefs().get_string('qtgui', 'style', 'raster')
Qt.QApplication.setGraphicsSystem(style)
qapp = Qt.QApplication(sys.argv)
tb = top_block_cls()
tb.start()
tb.show()
def quitting():
tb.stop()
tb.wait()
qapp.connect(qapp, Qt.SIGNAL("aboutToQuit()"), quitting)
qapp.exec_()
if __name__ == '__main__':
main()