220 lines
7.8 KiB
Python
Executable File
220 lines
7.8 KiB
Python
Executable File
#!/usr/bin/env python3
|
|
|
|
from PyQt5 import Qt
|
|
from gnuradio import qtgui
|
|
from PyQt5 import QtCore
|
|
from gnuradio import analog
|
|
from gnuradio import audio
|
|
from gnuradio import blocks
|
|
from gnuradio import filter
|
|
from gnuradio.filter import firdes
|
|
from gnuradio import gr
|
|
from gnuradio.fft import window
|
|
import sys
|
|
import signal
|
|
from PyQt5 import Qt
|
|
from argparse import ArgumentParser
|
|
from gnuradio.eng_arg import eng_float, intx
|
|
from gnuradio import eng_notation
|
|
import osmosdr
|
|
import time
|
|
import sip
|
|
|
|
|
|
|
|
class static_radio(gr.top_block, Qt.QWidget):
|
|
|
|
def __init__(self):
|
|
gr.top_block.__init__(self, "fm radio example", catch_exceptions=True)
|
|
Qt.QWidget.__init__(self)
|
|
self.setWindowTitle("fm radio example")
|
|
qtgui.util.check_set_qss()
|
|
try:
|
|
self.setWindowIcon(Qt.QIcon.fromTheme('gnuradio-grc'))
|
|
except BaseException as exc:
|
|
print(f"Qt GUI: Could not set Icon: {str(exc)}", file=sys.stderr)
|
|
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", "static radio")
|
|
|
|
try:
|
|
geometry = self.settings.value("geometry")
|
|
if geometry:
|
|
self.restoreGeometry(geometry)
|
|
except BaseException as exc:
|
|
print(f"Qt GUI: Could not restore geometry: {str(exc)}", file=sys.stderr)
|
|
|
|
##################################################
|
|
# Variables
|
|
##################################################
|
|
self.volume_adjust = volume_adjust = 1
|
|
self.samp_rate = samp_rate = 20e6
|
|
self.channel_width = channel_width = 200e3
|
|
self.channel_freq = channel_freq = 96100000.0
|
|
self.center_freq = center_freq = 97.9e6
|
|
|
|
##################################################
|
|
# Blocks
|
|
##################################################
|
|
|
|
self._volume_adjust_range = qtgui.Range(0, 5, .01, 1, 200)
|
|
self._volume_adjust_win = qtgui.RangeWidget(self._volume_adjust_range, self.set_volume_adjust, "'volume_adjust'", "counter_slider", float, QtCore.Qt.Horizontal)
|
|
self.top_layout.addWidget(self._volume_adjust_win)
|
|
self.rational_resampler_xxx_0 = filter.rational_resampler_ccc(
|
|
interpolation=12,
|
|
decimation=5,
|
|
taps=[],
|
|
fractional_bw=0)
|
|
self.qtgui_sink_x_0_0 = qtgui.sink_c(
|
|
32768, #fftsize
|
|
window.WIN_BLACKMAN_hARRIS, #wintype
|
|
channel_freq, #fc
|
|
samp_rate, #bw
|
|
"", #name
|
|
True, #plotfreq
|
|
True, #plotwaterfall
|
|
True, #plottime
|
|
True, #plotconst
|
|
None # parent
|
|
)
|
|
self.qtgui_sink_x_0_0.set_update_time(1.0/10)
|
|
self._qtgui_sink_x_0_0_win = sip.wrapinstance(self.qtgui_sink_x_0_0.qwidget(), Qt.QWidget)
|
|
|
|
self.qtgui_sink_x_0_0.enable_rf_freq(True)
|
|
|
|
self.top_layout.addWidget(self._qtgui_sink_x_0_0_win)
|
|
self.osmosdr_source_0 = osmosdr.source(
|
|
args="numchan=" + str(1) + " " + ""
|
|
)
|
|
self.osmosdr_source_0.set_time_unknown_pps(osmosdr.time_spec_t())
|
|
self.osmosdr_source_0.set_sample_rate(samp_rate)
|
|
self.osmosdr_source_0.set_center_freq(center_freq, 0)
|
|
self.osmosdr_source_0.set_freq_corr(0, 0)
|
|
self.osmosdr_source_0.set_dc_offset_mode(0, 0)
|
|
self.osmosdr_source_0.set_iq_balance_mode(0, 0)
|
|
self.osmosdr_source_0.set_gain_mode(False, 0)
|
|
self.osmosdr_source_0.set_gain(0, 0)
|
|
self.osmosdr_source_0.set_if_gain(20, 0)
|
|
self.osmosdr_source_0.set_bb_gain(20, 0)
|
|
self.osmosdr_source_0.set_antenna('', 0)
|
|
self.osmosdr_source_0.set_bandwidth(0, 0)
|
|
self.low_pass_filter_0 = filter.fir_filter_ccf(
|
|
(int(samp_rate/channel_width)),
|
|
firdes.low_pass(
|
|
1,
|
|
samp_rate,
|
|
75e3,
|
|
25e3,
|
|
window.WIN_HAMMING,
|
|
6.76))
|
|
self.blocks_multiply_xx_0 = blocks.multiply_vcc(1)
|
|
self.blocks_multiply_const_vxx_0 = blocks.multiply_const_ff(volume_adjust)
|
|
self.audio_sink_0 = audio.sink(48000, '', True)
|
|
self.analog_wfm_rcv_0 = analog.wfm_rcv(
|
|
quad_rate=48000,
|
|
audio_decimation=10,
|
|
)
|
|
self.analog_sig_source_x_0 = analog.sig_source_c(samp_rate, analog.GR_COS_WAVE, (center_freq - channel_freq), 1, 0, 0)
|
|
|
|
|
|
##################################################
|
|
# Connections
|
|
##################################################
|
|
self.connect((self.analog_sig_source_x_0, 0), (self.blocks_multiply_xx_0, 1))
|
|
self.connect((self.analog_wfm_rcv_0, 0), (self.blocks_multiply_const_vxx_0, 0))
|
|
self.connect((self.blocks_multiply_const_vxx_0, 0), (self.audio_sink_0, 0))
|
|
self.connect((self.blocks_multiply_xx_0, 0), (self.low_pass_filter_0, 0))
|
|
self.connect((self.blocks_multiply_xx_0, 0), (self.qtgui_sink_x_0_0, 0))
|
|
self.connect((self.low_pass_filter_0, 0), (self.rational_resampler_xxx_0, 0))
|
|
self.connect((self.osmosdr_source_0, 0), (self.blocks_multiply_xx_0, 0))
|
|
self.connect((self.rational_resampler_xxx_0, 0), (self.analog_wfm_rcv_0, 0))
|
|
|
|
|
|
def closeEvent(self, event):
|
|
self.settings = Qt.QSettings("GNU Radio", "static_radio")
|
|
self.settings.setValue("geometry", self.saveGeometry())
|
|
self.stop()
|
|
self.wait()
|
|
|
|
event.accept()
|
|
|
|
def get_volume_adjust(self):
|
|
return self.volume_adjust
|
|
|
|
def set_volume_adjust(self, volume_adjust):
|
|
self.volume_adjust = volume_adjust
|
|
self.blocks_multiply_const_vxx_0.set_k(self.volume_adjust)
|
|
|
|
def get_samp_rate(self):
|
|
return self.samp_rate
|
|
|
|
def set_samp_rate(self, samp_rate):
|
|
self.samp_rate = samp_rate
|
|
self.analog_sig_source_x_0.set_sampling_freq(self.samp_rate)
|
|
self.low_pass_filter_0.set_taps(firdes.low_pass(1, self.samp_rate, 75e3, 25e3, window.WIN_HAMMING, 6.76))
|
|
self.osmosdr_source_0.set_sample_rate(self.samp_rate)
|
|
self.qtgui_sink_x_0_0.set_frequency_range(self.channel_freq, self.samp_rate)
|
|
|
|
def get_channel_width(self):
|
|
return self.channel_width
|
|
|
|
def set_channel_width(self, channel_width):
|
|
self.channel_width = channel_width
|
|
|
|
def get_channel_freq(self):
|
|
return self.channel_freq
|
|
|
|
def set_channel_freq(self, channel_freq):
|
|
self.channel_freq = channel_freq
|
|
self.analog_sig_source_x_0.set_frequency((self.center_freq - self.channel_freq))
|
|
self.qtgui_sink_x_0_0.set_frequency_range(self.channel_freq, self.samp_rate)
|
|
|
|
def get_center_freq(self):
|
|
return self.center_freq
|
|
|
|
def set_center_freq(self, center_freq):
|
|
self.center_freq = center_freq
|
|
self.analog_sig_source_x_0.set_frequency((self.center_freq - self.channel_freq))
|
|
self.osmosdr_source_0.set_center_freq(self.center_freq, 0)
|
|
|
|
|
|
|
|
|
|
def main(top_block_cls=static_radio, options=None):
|
|
|
|
qapp = Qt.QApplication(sys.argv)
|
|
|
|
tb = top_block_cls()
|
|
|
|
tb.start()
|
|
|
|
tb.show()
|
|
|
|
def sig_handler(sig=None, frame=None):
|
|
tb.stop()
|
|
tb.wait()
|
|
|
|
Qt.QApplication.quit()
|
|
|
|
signal.signal(signal.SIGINT, sig_handler)
|
|
signal.signal(signal.SIGTERM, sig_handler)
|
|
|
|
timer = Qt.QTimer()
|
|
timer.start(500)
|
|
timer.timeout.connect(lambda: None)
|
|
|
|
qapp.exec_()
|
|
|
|
if __name__ == '__main__':
|
|
main()
|