| #!/usr/bin/env python2 |
| ################################################## |
| # GNU Radio Python Flow Graph |
| # Title: Bandpass Recorder Gui |
| # Generated: Mon Jun 22 16:32:25 2015 |
| ################################################## |
| |
| 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 import qtgui |
| from gnuradio import uhd |
| from gnuradio.eng_option import eng_option |
| from gnuradio.filter import firdes |
| from gnuradio.qtgui import Range, RangeWidget |
| from optparse import OptionParser |
| import sip |
| import sys |
| import time |
| |
| from distutils.version import StrictVersion |
| class bandpass_recorder_gui(gr.top_block, Qt.QWidget): |
| |
| def __init__(self): |
| gr.top_block.__init__(self, "Bandpass Recorder Gui") |
| Qt.QWidget.__init__(self) |
| self.setWindowTitle("Bandpass Recorder Gui") |
| 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", "bandpass_recorder_gui") |
| self.restoreGeometry(self.settings.value("geometry").toByteArray()) |
| |
| |
| ################################################## |
| # Variables |
| ################################################## |
| self.width = width = 3e6 |
| self.samp_rate = samp_rate = 30e6 |
| self.record_time = record_time = 100 |
| self.gain = gain = 50 |
| self.freq = freq = 20e3 |
| |
| ################################################## |
| # Blocks |
| ################################################## |
| self._width_range = Range(1, samp_rate, 1, 3e6, 200) |
| self._width_win = RangeWidget(self._width_range, self.set_width, "width", "counter_slider") |
| self.top_layout.addWidget(self._width_win) |
| self._gain_range = Range(0, 150, 1, 50, 200) |
| self._gain_win = RangeWidget(self._gain_range, self.set_gain, "gain", "counter_slider") |
| self.top_layout.addWidget(self._gain_win) |
| self._freq_range = Range(0, 6e9, 10000, 20e3, 200) |
| self._freq_win = RangeWidget(self._freq_range, self.set_freq, "Frequency", "counter_slider") |
| self.top_layout.addWidget(self._freq_win) |
| self.uhd_usrp_source_0 = uhd.usrp_source( |
| ",".join(("", "")), |
| uhd.stream_args( |
| cpu_format="fc32", |
| otw_format="sc16", |
| channels=range(1), |
| ), |
| ) |
| self.uhd_usrp_source_0.set_samp_rate(samp_rate) |
| self.uhd_usrp_source_0.set_center_freq(freq, 0) |
| self.uhd_usrp_source_0.set_gain(gain, 0) |
| self.uhd_usrp_source_0.set_antenna('TX/RX', 0) |
| self.uhd_usrp_source_0.set_bandwidth(width, 0) |
| self._record_time_range = Range(0, 60e3, 1, 100, 200) |
| self._record_time_win = RangeWidget(self._record_time_range, self.set_record_time, "Record Length (ms)", "counter_slider") |
| self.top_layout.addWidget(self._record_time_win) |
| self.qtgui_sink_x_0 = qtgui.sink_c( |
| 1024, #fftsize |
| firdes.WIN_BLACKMAN_hARRIS, #wintype |
| 0, #fc |
| samp_rate/2, #bw |
| "", #name |
| True, #plotfreq |
| True, #plotwaterfall |
| True, #plottime |
| True, #plotconst |
| ) |
| self.qtgui_sink_x_0.set_update_time(1.0/10) |
| self._qtgui_sink_x_0_win = sip.wrapinstance(self.qtgui_sink_x_0.pyqwidget(), Qt.QWidget) |
| self.top_layout.addWidget(self._qtgui_sink_x_0_win) |
| |
| self.qtgui_sink_x_0.enable_rf_freq(False) |
| |
| |
| |
| |
| ################################################## |
| # Connections |
| ################################################## |
| self.connect((self.uhd_usrp_source_0, 0), (self.qtgui_sink_x_0, 0)) |
| |
| def closeEvent(self, event): |
| self.settings = Qt.QSettings("GNU Radio", "bandpass_recorder_gui") |
| self.settings.setValue("geometry", self.saveGeometry()) |
| event.accept() |
| |
| def get_width(self): |
| return self.width |
| |
| def set_width(self, width): |
| self.width = width |
| self.uhd_usrp_source_0.set_bandwidth(self.width, 0) |
| |
| def get_samp_rate(self): |
| return self.samp_rate |
| |
| def set_samp_rate(self, samp_rate): |
| self.samp_rate = samp_rate |
| self.qtgui_sink_x_0.set_frequency_range(0, self.samp_rate/2) |
| self.uhd_usrp_source_0.set_samp_rate(self.samp_rate) |
| |
| def get_record_time(self): |
| return self.record_time |
| |
| def set_record_time(self, record_time): |
| self.record_time = record_time |
| |
| def get_gain(self): |
| return self.gain |
| |
| def set_gain(self, gain): |
| self.gain = gain |
| self.uhd_usrp_source_0.set_gain(self.gain, 0) |
| |
| def get_freq(self): |
| return self.freq |
| |
| def set_freq(self, freq): |
| self.freq = freq |
| self.uhd_usrp_source_0.set_center_freq(self.freq, 0) |
| |
| |
| if __name__ == '__main__': |
| parser = OptionParser(option_class=eng_option, usage="%prog: [options]") |
| (options, args) = parser.parse_args() |
| if(StrictVersion(Qt.qVersion()) >= StrictVersion("4.5.0")): |
| Qt.QApplication.setGraphicsSystem(gr.prefs().get_string('qtgui','style','raster')) |
| qapp = Qt.QApplication(sys.argv) |
| tb = bandpass_recorder_gui() |
| 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 |