Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Debugging recipe for SDRPlay RSP2 and gnuradio-companion (scroll down for GRC recipe)
#!/usr/bin/env python2
# -*- coding: utf-8 -*-
##################################################
# GNU Radio Python Flow Graph
# Title: Sdrplay Rsp2 Fft
# Generated: Thu Jan 18 07:07:54 2018
##################################################
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 analog
from gnuradio import audio
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 gnuradio.qtgui import Range, RangeWidget
from optparse import OptionParser
import osmosdr
import sip
import sys
from gnuradio import qtgui
class sdrplay_rsp2_fft(gr.top_block, Qt.QWidget):
def __init__(self):
gr.top_block.__init__(self, "Sdrplay Rsp2 Fft")
Qt.QWidget.__init__(self)
self.setWindowTitle("Sdrplay Rsp2 Fft")
qtgui.util.check_set_qss()
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", "sdrplay_rsp2_fft")
self.restoreGeometry(self.settings.value("geometry").toByteArray())
##################################################
# Variables
##################################################
self.samp_rate = samp_rate = 250e3
self.intensity_min = intensity_min = -100
self.intensity_max = intensity_max = 0
self.gain = gain = 20
self.frequency = frequency = 162.4e6
self.bandwidth = bandwidth = 32e3
##################################################
# Blocks
##################################################
self._intensity_min_range = Range(-100, 0, 1, -100, 200)
self._intensity_min_win = RangeWidget(self._intensity_min_range, self.set_intensity_min, 'Intensity min', "counter_slider", float)
self.top_layout.addWidget(self._intensity_min_win)
self._intensity_max_range = Range(-100, 0, 1, 0, 200)
self._intensity_max_win = RangeWidget(self._intensity_max_range, self.set_intensity_max, 'Intensity max', "counter_slider", float)
self.top_layout.addWidget(self._intensity_max_win)
self._frequency_range = Range(80e6, 1090e6, 1, 162.4e6, 200)
self._frequency_win = RangeWidget(self._frequency_range, self.set_frequency, 'Center frequency', "counter_slider", float)
self.top_layout.addWidget(self._frequency_win)
self._bandwidth_range = Range(1e3, 10e6, 1, 32e3, 200)
self._bandwidth_win = RangeWidget(self._bandwidth_range, self.set_bandwidth, 'Bandwidth', "counter_slider", float)
self.top_layout.addWidget(self._bandwidth_win)
self.sdrplay_source_0 = osmosdr.source(args = '' + ",bias=" + str(0) + ",lo=" + str(0))
self.sdrplay_source_0.set_sample_rate(samp_rate)
self.sdrplay_source_0.set_center_freq(frequency, 0)
self.sdrplay_source_0.set_freq_corr(0, 0)
self.sdrplay_source_0.set_dc_offset_mode(0, 0)
self.sdrplay_source_0.set_iq_balance_mode(2, 0)
self.sdrplay_source_0.set_gain_mode(False, 0)
self.sdrplay_source_0.set_gain(0, "LNA_ATTEN_STEP", 0)
self.sdrplay_source_0.set_gain(20, "IF_ATTEN_DB", 0)
self.sdrplay_source_0.set_antenna('A', 0)
self.sdrplay_source_0.set_bandwidth(bandwidth, 0)
self.rational_resampler_xxx_0 = filter.rational_resampler_ccc(
interpolation=48000 * 4,
decimation=int(samp_rate),
taps=None,
fractional_bw=None,
)
self.qtgui_waterfall_sink_x_0 = qtgui.waterfall_sink_c(
1024, #size
firdes.WIN_BLACKMAN_hARRIS, #wintype
frequency, #fc
samp_rate, #bw
"", #name
1 #number of inputs
)
self.qtgui_waterfall_sink_x_0.set_update_time(0.10)
self.qtgui_waterfall_sink_x_0.enable_grid(False)
self.qtgui_waterfall_sink_x_0.enable_axis_labels(True)
if not True:
self.qtgui_waterfall_sink_x_0.disable_legend()
if "complex" == "float" or "complex" == "msg_float":
self.qtgui_waterfall_sink_x_0.set_plot_pos_half(not True)
labels = ['', '', '', '', '',
'', '', '', '', '']
colors = [0, 0, 0, 0, 0,
0, 0, 0, 0, 0]
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(1):
if len(labels[i]) == 0:
self.qtgui_waterfall_sink_x_0.set_line_label(i, "Data {0}".format(i))
else:
self.qtgui_waterfall_sink_x_0.set_line_label(i, labels[i])
self.qtgui_waterfall_sink_x_0.set_color_map(i, colors[i])
self.qtgui_waterfall_sink_x_0.set_line_alpha(i, alphas[i])
self.qtgui_waterfall_sink_x_0.set_intensity_range(intensity_min, intensity_max)
self._qtgui_waterfall_sink_x_0_win = sip.wrapinstance(self.qtgui_waterfall_sink_x_0.pyqwidget(), Qt.QWidget)
self.top_layout.addWidget(self._qtgui_waterfall_sink_x_0_win)
self._gain_range = Range(0, 74, 1, 20, 200)
self._gain_win = RangeWidget(self._gain_range, self.set_gain, 'Gain', "counter_slider", float)
self.top_layout.addWidget(self._gain_win)
self.audio_sink_0 = audio.sink(48000, '', False)
self.analog_wfm_rcv_0 = analog.wfm_rcv(
quad_rate=48e3,
audio_decimation=4,
)
##################################################
# Connections
##################################################
self.connect((self.analog_wfm_rcv_0, 0), (self.audio_sink_0, 0))
self.connect((self.rational_resampler_xxx_0, 0), (self.analog_wfm_rcv_0, 0))
self.connect((self.sdrplay_source_0, 0), (self.qtgui_waterfall_sink_x_0, 0))
self.connect((self.sdrplay_source_0, 0), (self.rational_resampler_xxx_0, 0))
def closeEvent(self, event):
self.settings = Qt.QSettings("GNU Radio", "sdrplay_rsp2_fft")
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.sdrplay_source_0.set_sample_rate(self.samp_rate)
self.qtgui_waterfall_sink_x_0.set_frequency_range(self.frequency, self.samp_rate)
def get_intensity_min(self):
return self.intensity_min
def set_intensity_min(self, intensity_min):
self.intensity_min = intensity_min
self.qtgui_waterfall_sink_x_0.set_intensity_range(self.intensity_min, self.intensity_max)
def get_intensity_max(self):
return self.intensity_max
def set_intensity_max(self, intensity_max):
self.intensity_max = intensity_max
self.qtgui_waterfall_sink_x_0.set_intensity_range(self.intensity_min, self.intensity_max)
def get_gain(self):
return self.gain
def set_gain(self, gain):
self.gain = gain
def get_frequency(self):
return self.frequency
def set_frequency(self, frequency):
self.frequency = frequency
self.sdrplay_source_0.set_center_freq(self.frequency, 0)
self.qtgui_waterfall_sink_x_0.set_frequency_range(self.frequency, self.samp_rate)
def get_bandwidth(self):
return self.bandwidth
def set_bandwidth(self, bandwidth):
self.bandwidth = bandwidth
self.sdrplay_source_0.set_bandwidth(self.bandwidth, 0)
def main(top_block_cls=sdrplay_rsp2_fft, 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()
<?xml version='1.0' encoding='utf-8'?>
<?grc format='1' created='3.7.12'?>
<flow_graph>
<timestamp>Mon Jan 15 22:29:58 2018</timestamp>
<block>
<key>options</key>
<param>
<key>author</key>
<value></value>
</param>
<param>
<key>window_size</key>
<value></value>
</param>
<param>
<key>category</key>
<value>[GRC Hier Blocks]</value>
</param>
<param>
<key>comment</key>
<value></value>
</param>
<param>
<key>description</key>
<value></value>
</param>
<param>
<key>_enabled</key>
<value>True</value>
</param>
<param>
<key>_coordinate</key>
<value>(8, 8)</value>
</param>
<param>
<key>_rotation</key>
<value>0</value>
</param>
<param>
<key>generate_options</key>
<value>qt_gui</value>
</param>
<param>
<key>hier_block_src_path</key>
<value>.:</value>
</param>
<param>
<key>id</key>
<value>top_block</value>
</param>
<param>
<key>max_nouts</key>
<value>0</value>
</param>
<param>
<key>qt_qss_theme</key>
<value></value>
</param>
<param>
<key>realtime_scheduling</key>
<value></value>
</param>
<param>
<key>run_command</key>
<value>{python} -u {filename}</value>
</param>
<param>
<key>run_options</key>
<value>prompt</value>
</param>
<param>
<key>run</key>
<value>True</value>
</param>
<param>
<key>sizing_mode</key>
<value>fixed</value>
</param>
<param>
<key>thread_safe_setters</key>
<value></value>
</param>
<param>
<key>title</key>
<value></value>
</param>
<param>
<key>placement</key>
<value>(0,0)</value>
</param>
</block>
<block>
<key>variable</key>
<param>
<key>comment</key>
<value></value>
</param>
<param>
<key>_enabled</key>
<value>True</value>
</param>
<param>
<key>_coordinate</key>
<value>(8, 160)</value>
</param>
<param>
<key>_rotation</key>
<value>0</value>
</param>
<param>
<key>id</key>
<value>samp_rate</value>
</param>
<param>
<key>value</key>
<value>32000</value>
</param>
</block>
<block>
<key>qtgui_waterfall_sink_x</key>
<param>
<key>axislabels</key>
<value>True</value>
</param>
<param>
<key>bw</key>
<value>samp_rate</value>
</param>
<param>
<key>alias</key>
<value></value>
</param>
<param>
<key>fc</key>
<value>162.4e6</value>
</param>
<param>
<key>comment</key>
<value></value>
</param>
<param>
<key>affinity</key>
<value></value>
</param>
<param>
<key>_enabled</key>
<value>True</value>
</param>
<param>
<key>fftsize</key>
<value>1024</value>
</param>
<param>
<key>_coordinate</key>
<value>(656, 268)</value>
</param>
<param>
<key>gui_hint</key>
<value></value>
</param>
<param>
<key>_rotation</key>
<value>0</value>
</param>
<param>
<key>grid</key>
<value>False</value>
</param>
<param>
<key>id</key>
<value>qtgui_waterfall_sink_x_0</value>
</param>
<param>
<key>int_max</key>
<value>10</value>
</param>
<param>
<key>int_min</key>
<value>-140</value>
</param>
<param>
<key>legend</key>
<value>True</value>
</param>
<param>
<key>alpha1</key>
<value>1.0</value>
</param>
<param>
<key>color1</key>
<value>0</value>
</param>
<param>
<key>label1</key>
<value></value>
</param>
<param>
<key>alpha10</key>
<value>1.0</value>
</param>
<param>
<key>color10</key>
<value>0</value>
</param>
<param>
<key>label10</key>
<value></value>
</param>
<param>
<key>alpha2</key>
<value>1.0</value>
</param>
<param>
<key>color2</key>
<value>0</value>
</param>
<param>
<key>label2</key>
<value></value>
</param>
<param>
<key>alpha3</key>
<value>1.0</value>
</param>
<param>
<key>color3</key>
<value>0</value>
</param>
<param>
<key>label3</key>
<value></value>
</param>
<param>
<key>alpha4</key>
<value>1.0</value>
</param>
<param>
<key>color4</key>
<value>0</value>
</param>
<param>
<key>label4</key>
<value></value>
</param>
<param>
<key>alpha5</key>
<value>1.0</value>
</param>
<param>
<key>color5</key>
<value>0</value>
</param>
<param>
<key>label5</key>
<value></value>
</param>
<param>
<key>alpha6</key>
<value>1.0</value>
</param>
<param>
<key>color6</key>
<value>0</value>
</param>
<param>
<key>label6</key>
<value></value>
</param>
<param>
<key>alpha7</key>
<value>1.0</value>
</param>
<param>
<key>color7</key>
<value>0</value>
</param>
<param>
<key>label7</key>
<value></value>
</param>
<param>
<key>alpha8</key>
<value>1.0</value>
</param>
<param>
<key>color8</key>
<value>0</value>
</param>
<param>
<key>label8</key>
<value></value>
</param>
<param>
<key>alpha9</key>
<value>1.0</value>
</param>
<param>
<key>color9</key>
<value>0</value>
</param>
<param>
<key>label9</key>
<value></value>
</param>
<param>
<key>maxoutbuf</key>
<value>0</value>
</param>
<param>
<key>minoutbuf</key>
<value>0</value>
</param>
<param>
<key>name</key>
<value>""</value>
</param>
<param>
<key>nconnections</key>
<value>1</value>
</param>
<param>
<key>showports</key>
<value>True</value>
</param>
<param>
<key>freqhalf</key>
<value>True</value>
</param>
<param>
<key>type</key>
<value>complex</value>
</param>
<param>
<key>update_time</key>
<value>0.10</value>
</param>
<param>
<key>wintype</key>
<value>firdes.WIN_BLACKMAN_hARRIS</value>
</param>
</block>
<block>
<key>sdrplay_source</key>
<param>
<key>loFreq</key>
<value>0</value>
</param>
<param>
<key>ant</key>
<value>A</value>
</param>
<param>
<key>bw</key>
<value>1536e3</value>
</param>
<param>
<key>bias</key>
<value>0</value>
</param>
<param>
<key>alias</key>
<value></value>
</param>
<param>
<key>comment</key>
<value></value>
</param>
<param>
<key>affinity</key>
<value></value>
</param>
<param>
<key>dc_offset_mode</key>
<value>0</value>
</param>
<param>
<key>args</key>
<value>sdrplay=0</value>
</param>
<param>
<key>_enabled</key>
<value>True</value>
</param>
<param>
<key>corr</key>
<value>0</value>
</param>
<param>
<key>freq</key>
<value>162.4e6</value>
</param>
<param>
<key>_coordinate</key>
<value>(368, 192)</value>
</param>
<param>
<key>_rotation</key>
<value>0</value>
</param>
<param>
<key>gain_mode</key>
<value>False</value>
</param>
<param>
<key>id</key>
<value>sdrplay_source_0</value>
</param>
<param>
<key>grdb</key>
<value>40</value>
</param>
<param>
<key>iq_balance_mode</key>
<value>0</value>
</param>
<param>
<key>lna</key>
<value>0</value>
</param>
<param>
<key>maxoutbuf</key>
<value>0</value>
</param>
<param>
<key>minoutbuf</key>
<value>0</value>
</param>
<param>
<key>nchan</key>
<value>1</value>
</param>
<param>
<key>type</key>
<value>fc32</value>
</param>
<param>
<key>sample_rate</key>
<value>samp_rate</value>
</param>
</block>
<connection>
<source_block_id>sdrplay_source_0</source_block_id>
<sink_block_id>qtgui_waterfall_sink_x_0</sink_block_id>
<source_key>0</source_key>
<sink_key>0</sink_key>
</connection>
</flow_graph>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.