Last active
May 21, 2024 22:14
-
-
Save nemanjan00/058d42e4a878c9f3a91e78461663f8af to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
# -*- coding: utf-8 -*- | |
# | |
# SPDX-License-Identifier: GPL-3.0 | |
# | |
# GNU Radio Python Flow Graph | |
# Title: Not titled yet | |
# GNU Radio version: 3.10.10.0 | |
from PyQt5 import Qt | |
from gnuradio import qtgui | |
from gnuradio import analog | |
from gnuradio import blocks | |
from gnuradio import gr | |
from gnuradio.filter import firdes | |
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 | |
from gnuradio import soapy | |
import sip | |
import time | |
import threading | |
class calibrate1(gr.top_block, Qt.QWidget): | |
def __init__(self): | |
gr.top_block.__init__(self, "Not titled yet", catch_exceptions=True) | |
Qt.QWidget.__init__(self) | |
self.setWindowTitle("Not titled yet") | |
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", "calibrate1") | |
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.samp_rate = samp_rate = 20e6 | |
self.freq = freq = 100e6 | |
################################################## | |
# Blocks | |
################################################## | |
def _freq_probe(): | |
while True: | |
val = self.freq_pro.level() | |
try: | |
try: | |
self.doc.add_next_tick_callback(functools.partial(self.set_freq,val)) | |
except AttributeError: | |
self.set_freq(val) | |
except AttributeError: | |
pass | |
time.sleep(1.0 / (1000)) | |
_freq_thread = threading.Thread(target=_freq_probe) | |
_freq_thread.daemon = True | |
_freq_thread.start() | |
self.soapy_hackrf_sink_0 = None | |
dev = 'driver=hackrf' | |
stream_args = '' | |
tune_args = [''] | |
settings = [''] | |
self.soapy_hackrf_sink_0 = soapy.sink(dev, "fc32", 1, '', | |
stream_args, tune_args, settings) | |
self.soapy_hackrf_sink_0.set_sample_rate(0, samp_rate) | |
self.soapy_hackrf_sink_0.set_bandwidth(0, 0) | |
self.soapy_hackrf_sink_0.set_frequency(0, int(freq)) | |
self.soapy_hackrf_sink_0.set_gain(0, 'AMP', False) | |
self.soapy_hackrf_sink_0.set_gain(0, 'VGA', min(max(16, 0.0), 47.0)) | |
self.qtgui_sink_x_0 = qtgui.sink_f( | |
1024, #fftsize | |
window.WIN_BLACKMAN_hARRIS, #wintype | |
0, #fc | |
samp_rate, #bw | |
"", #name | |
True, #plotfreq | |
True, #plotwaterfall | |
True, #plottime | |
True, #plotconst | |
None # parent | |
) | |
self.qtgui_sink_x_0.set_update_time(1.0/10) | |
self._qtgui_sink_x_0_win = sip.wrapinstance(self.qtgui_sink_x_0.qwidget(), Qt.QWidget) | |
self.qtgui_sink_x_0.enable_rf_freq(False) | |
self.top_layout.addWidget(self._qtgui_sink_x_0_win) | |
self.freq_pro = blocks.probe_signal_i() | |
self.blocks_throttle2_0 = blocks.throttle( gr.sizeof_int*1, samp_rate, True, 0 if "auto" == "auto" else max( int(float(0.1) * samp_rate) if "auto" == "time" else int(0.1), 1) ) | |
self.blocks_int_to_float_0 = blocks.int_to_float(1, 1) | |
self.analog_sig_source_x_1 = analog.sig_source_i(samp_rate, analog.GR_SAW_WAVE, 0.0004, 10e6, 0, 0) | |
self.analog_sig_source_x_0 = analog.sig_source_c(samp_rate, analog.GR_COS_WAVE, 0, 1, 0, 0) | |
################################################## | |
# Connections | |
################################################## | |
self.connect((self.analog_sig_source_x_0, 0), (self.soapy_hackrf_sink_0, 0)) | |
self.connect((self.analog_sig_source_x_1, 0), (self.blocks_throttle2_0, 0)) | |
self.connect((self.blocks_int_to_float_0, 0), (self.qtgui_sink_x_0, 0)) | |
self.connect((self.blocks_throttle2_0, 0), (self.blocks_int_to_float_0, 0)) | |
self.connect((self.blocks_throttle2_0, 0), (self.freq_pro, 0)) | |
def closeEvent(self, event): | |
self.settings = Qt.QSettings("GNU Radio", "calibrate1") | |
self.settings.setValue("geometry", self.saveGeometry()) | |
self.stop() | |
self.wait() | |
event.accept() | |
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.analog_sig_source_x_1.set_sampling_freq(self.samp_rate) | |
self.blocks_throttle2_0.set_sample_rate(self.samp_rate) | |
self.qtgui_sink_x_0.set_frequency_range(0, self.samp_rate) | |
self.soapy_hackrf_sink_0.set_sample_rate(0, self.samp_rate) | |
def get_freq(self): | |
return self.freq | |
def set_freq(self, freq): | |
self.freq = freq | |
self.soapy_hackrf_sink_0.set_frequency(0, int(self.freq)) | |
def main(top_block_cls=calibrate1, 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() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment