| #!/usr/bin/python |
| # Copyright 2015 Google Inc. All Rights Reserved. |
| # |
| # Licensed under the Apache License, Version 2.0 (the "License"); |
| # you may not use this file except in compliance with the License. |
| # You may obtain a copy of the License at |
| # |
| # http://www.apache.org/licenses/LICENSE-2.0 |
| # |
| # Unless required by applicable law or agreed to in writing, software |
| # distributed under the License is distributed on an "AS IS" BASIS, |
| # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| # See the License for the specific language governing permissions and |
| # limitations under the License. |
| # |
| |
| 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 blocks |
| from gnuradio import eng_notation |
| from gnuradio import gr |
| from gnuradio import uhd |
| from gnuradio.eng_option import eng_option |
| from gnuradio.filter import firdes |
| from optparse import OptionParser |
| import sys |
| import time |
| |
| from distutils.version import StrictVersion |
| class bandpass_recorder_file(gr.top_block, Qt.QWidget): |
| |
| def __init__(self): |
| gr.top_block.__init__(self, "Bandpass Recorder File") |
| Qt.QWidget.__init__(self) |
| self.setWindowTitle("Bandpass Recorder File") |
| 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_file") |
| self.restoreGeometry(self.settings.value("geometry").toByteArray()) |
| |
| |
| ################################################## |
| # Variables |
| ################################################## |
| self.width = width = 1 |
| self.samp_rate = samp_rate = 30e6 |
| self.gain = gain = 1 |
| self.freq = freq = 1 |
| |
| ################################################## |
| # Blocks |
| ################################################## |
| self.uhd_usrp_source_0 = uhd.usrp_source( |
| ",".join(("", "")), |
| uhd.stream_args( |
| cpu_format="fc32", |
| otw_format="sc8", |
| 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.blocks_file_sink_0 = blocks.file_sink(gr.sizeof_gr_complex*1, "recorder.out", False) |
| self.blocks_file_sink_0.set_unbuffered(False) |
| |
| ################################################## |
| # Connections |
| ################################################## |
| self.connect((self.uhd_usrp_source_0, 0), (self.blocks_file_sink_0, 0)) |
| |
| def closeEvent(self, event): |
| self.settings = Qt.QSettings("GNU Radio", "bandpass_recorder_file") |
| 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.uhd_usrp_source_0.set_samp_rate(self.samp_rate) |
| |
| 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_file() |
| 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 |