#!/usr/bin/env python ################################################## # Gnuradio Python Flow Graph # Title: Top Block # Generated: Sat Apr 19 09:34:24 2014 ################################################## execfile("/home/tom/.grc_gnuradio/ChirpSource.py") from PyQt4 import Qt from gnuradio import blocks from gnuradio import eng_notation from gnuradio import filter from gnuradio import gr from gnuradio import qtgui from gnuradio.eng_option import eng_option from gnuradio.filter import firdes from optparse import OptionParser import hpsdr import numpy import sip import sys class top_block(gr.top_block, Qt.QWidget): def __init__(self): gr.top_block.__init__(self, "Top Block") Qt.QWidget.__init__(self) self.setWindowTitle("Top Block") 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", "top_block") self.restoreGeometry(self.settings.value("geometry").toByteArray()) ################################################## # Variables ################################################## self.samp_rate = samp_rate = 48000 self.TxDrive = TxDrive = 0 self.Frequency = Frequency = 3525000 ################################################## # Blocks ################################################## self._TxDrive_tool_bar = Qt.QToolBar(self) self._TxDrive_tool_bar.addWidget(Qt.QLabel("TxDrive"+": ")) self._TxDrive_line_edit = Qt.QLineEdit(str(self.TxDrive)) self._TxDrive_tool_bar.addWidget(self._TxDrive_line_edit) self._TxDrive_line_edit.returnPressed.connect( lambda: self.set_TxDrive(int(self._TxDrive_line_edit.text().toAscii()))) self.top_layout.addWidget(self._TxDrive_tool_bar) self._Frequency_tool_bar = Qt.QToolBar(self) self._Frequency_tool_bar.addWidget(Qt.QLabel("Frequency"+": ")) self._Frequency_line_edit = Qt.QLineEdit(str(self.Frequency)) self._Frequency_tool_bar.addWidget(self._Frequency_line_edit) self._Frequency_line_edit.returnPressed.connect( lambda: self.set_Frequency(int(self._Frequency_line_edit.text().toAscii()))) self.top_layout.addWidget(self._Frequency_tool_bar) self.qtgui_time_sink_x_0 = qtgui.time_sink_c( 131072, #size samp_rate, #samp_rate "QT GUI Plot", #name 1 #number of inputs ) self.qtgui_time_sink_x_0.set_update_time(0.10) self.qtgui_time_sink_x_0.set_y_axis(-1, 1) self.qtgui_time_sink_x_0.enable_tags(-1, True) self.qtgui_time_sink_x_0.set_trigger_mode(qtgui.TRIG_MODE_FREE, qtgui.TRIG_SLOPE_POS, 0.0, 0, 0, "") self.qtgui_time_sink_x_0.enable_autoscale(False) labels = ["", "", "", "", "", "", "", "", "", ""] widths = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1] colors = ["blue", "red", "green", "black", "cyan", "magenta", "yellow", "dark red", "dark green", "blue"] styles = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1] markers = [-1, -1, -1, -1, -1, -1, -1, -1, -1, -1] alphas = [1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0] for i in xrange(2*1): if len(labels[i]) == 0: if(i % 2 == 0): self.qtgui_time_sink_x_0.set_line_label(i, "Re{{Data {0}}}".format(i/2)) else: self.qtgui_time_sink_x_0.set_line_label(i, "Im{{Data {0}}}".format(i/2)) else: self.qtgui_time_sink_x_0.set_line_label(i, labels[i]) self.qtgui_time_sink_x_0.set_line_width(i, widths[i]) self.qtgui_time_sink_x_0.set_line_color(i, colors[i]) self.qtgui_time_sink_x_0.set_line_style(i, styles[i]) self.qtgui_time_sink_x_0.set_line_marker(i, markers[i]) self.qtgui_time_sink_x_0.set_line_alpha(i, alphas[i]) self._qtgui_time_sink_x_0_win = sip.wrapinstance(self.qtgui_time_sink_x_0.pyqwidget(), Qt.QWidget) self.top_layout.addWidget(self._qtgui_time_sink_x_0_win) self.hpsdr_hermesNB_0 = hpsdr.hermesNB(Frequency, 7200000, Frequency, 1, 2, 0, 0, TxDrive, samp_rate, "eth0", "0xF8", "0x00000000", 1) self.fft_filter_xxx_0 = filter.fft_filter_ccc(1, (numpy.fromfile('/home/tom/Desktop/EchoScreencaps/chirp-down-20-20-131072', numpy.complex64)), 1) self.fft_filter_xxx_0.declare_sample_delay(0) self.blocks_multiply_const_vxx_0 = blocks.multiply_const_vcc((5, )) self.ChirpSource_0 = ChirpSource(20, 48000, 0, 0.95, 20000, 0) ################################################## # Connections ################################################## self.connect((self.ChirpSource_0, 0), (self.hpsdr_hermesNB_0, 0)) self.connect((self.hpsdr_hermesNB_0, 0), (self.blocks_multiply_const_vxx_0, 0)) self.connect((self.blocks_multiply_const_vxx_0, 0), (self.fft_filter_xxx_0, 0)) self.connect((self.fft_filter_xxx_0, 0), (self.qtgui_time_sink_x_0, 0)) # QT sink close method reimplementation def closeEvent(self, event): self.settings = Qt.QSettings("GNU Radio", "top_block") self.settings.setValue("geometry", self.saveGeometry()) event.accept() def get_samp_rate(self): return self.samp_rate def set_samp_rate(self, samp_rate): self.samp_rate = samp_rate self.hpsdr_hermesNB_0.set_RxSampRate(self.samp_rate) self.qtgui_time_sink_x_0.set_samp_rate(self.samp_rate) def get_TxDrive(self): return self.TxDrive def set_TxDrive(self, TxDrive): self.TxDrive = TxDrive self.hpsdr_hermesNB_0.set_TxDrive(self.TxDrive) Qt.QMetaObject.invokeMethod(self._TxDrive_line_edit, "setText", Qt.Q_ARG("QString", str(self.TxDrive))) def get_Frequency(self): return self.Frequency def set_Frequency(self, Frequency): self.Frequency = Frequency self.hpsdr_hermesNB_0.set_Receive0Frequency(self.Frequency) self.hpsdr_hermesNB_0.set_TransmitFrequency(self.Frequency) Qt.QMetaObject.invokeMethod(self._Frequency_line_edit, "setText", Qt.Q_ARG("QString", str(self.Frequency))) 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()" parser = OptionParser(option_class=eng_option, usage="%prog: [options]") (options, args) = parser.parse_args() Qt.QApplication.setGraphicsSystem(gr.prefs().get_string('qtgui','style','raster')) qapp = Qt.QApplication(sys.argv) tb = top_block() tb.start() tb.show() def quitting(): tb.stop() tb.wait() qapp.connect(qapp, Qt.SIGNAL("aboutToQuit()"), quitting) qapp.exec_() tb = None #to clean up Qt widgets