def test_001_t(self): # Constants tag_key = 'in1_tag' tag_value = 0 tag_offset = 0 in0_value = 1.0+1.0j in1_value = 2.717 in0_data = (in0_value,)*10 in1_data = (in1_value,)*10 sink_data = in0_data tag = gr.tag_t() tag.key = pmt.to_pmt(tag_key) tag.value = pmt.to_pmt(tag_value) tag.offset = tag_offset # Only tag Input 1 of the share block and see if it transfers # to Output 0. Also verify that Input 0 stream is propagated to # Output 0. in0 = blocks.vector_source_c(in0_data, False, 1) in1 = blocks.vector_source_f(in1_data, False, 1, (tag,)) tag_share = blocks.tag_share(gr.sizeof_gr_complex, gr.sizeof_float) sink = blocks.vector_sink_c(1) self.tb.connect(in0, (tag_share,0)) self.tb.connect(in1, (tag_share,1)) self.tb.connect(tag_share, sink) self.tb.run() self.assertEqual(len(sink.tags()), 1) self.assertEqual(pmt.to_python(sink.tags()[0].key), tag_key) self.assertEqual(pmt.to_python(sink.tags()[0].value), tag_value) self.assertEqual(sink.tags()[0].offset, tag_offset) self.assertEqual(sink.data(), sink_data)
def __init__(self, avg_len=256, nfft=2048, path="/captures/20200329", record_hz=10): gr.top_block.__init__(self, "/captures/20200329/LRO_RHCP_2020-03-29T20:34:45Z.sigmf-data") Qt.QWidget.__init__(self) self.setWindowTitle("/captures/20200329/LRO_RHCP_2020-03-29T20:34:45Z.sigmf-data") 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", "lro_playback") self.restoreGeometry(self.settings.value("geometry").toByteArray()) ################################################## # Parameters ################################################## self.avg_len = avg_len self.nfft = nfft self.path = path self.record_hz = record_hz ################################################## # Variables ################################################## self.probe_snr_func = probe_snr_func = 0 self.probe_signal_func = probe_signal_func = 0 self.probe_offset_func = probe_offset_func = 0 self.probe_noise_func = probe_noise_func = 0 self.filename = filename = "LRO_RHCP_2020-03-29T20:34:45Z.sigmf-data" self.snr_var = snr_var = "{:3.3f}".format(probe_snr_func) self.signal_var = signal_var = "{:3.3f}".format(probe_signal_func) self.samp_rate = samp_rate = 250e3 self.offset_var = offset_var = "{:3.3f}".format(probe_offset_func) self.offset_file = offset_file = "{:s}_{:s}".format(filename.split(".")[0], "offset") self.noise_var = noise_var = "{:3.3f}".format(probe_noise_func) self.variable_tag_object_0 = variable_tag_object_0 = gr.tag_utils.python_to_tag((0, pmt.intern("key"), pmt.intern("value"), pmt.intern("src"))) self.throttle_factor = throttle_factor = 10 self.snr_label = snr_label = snr_var self.signal_label = signal_label = signal_var self.rx_freq = rx_freq = 2271.2e6 self.offset_label = offset_label = offset_var self.offset_fp = offset_fp = "/".join([path,offset_file]) self.noise_label = noise_label = noise_var self.keep_n = keep_n = samp_rate/record_hz self.fp = fp = "/".join([path,filename]) self.file_l = file_l = filename.split(".")[0].split("_") self.fft_min = fft_min = -120 self.fft_max = fft_max = -80 self.decim = decim = 8 self.alpha = alpha = 1.0/(samp_rate/record_hz) ################################################## # Blocks ################################################## self.probe_offset = blocks.probe_signal_f() self._throttle_factor_tool_bar = Qt.QToolBar(self) self._throttle_factor_tool_bar.addWidget(Qt.QLabel('Throttle'+": ")) self._throttle_factor_line_edit = Qt.QLineEdit(str(self.throttle_factor)) self._throttle_factor_tool_bar.addWidget(self._throttle_factor_line_edit) self._throttle_factor_line_edit.returnPressed.connect( lambda: self.set_throttle_factor(eng_notation.str_to_num(str(self._throttle_factor_line_edit.text().toAscii())))) self.top_grid_layout.addWidget(self._throttle_factor_tool_bar, 10, 2, 1, 1) for r in range(10, 11): self.top_grid_layout.setRowStretch(r, 1) for c in range(2, 3): self.top_grid_layout.setColumnStretch(c, 1) self._samp_rate_tool_bar = Qt.QToolBar(self) self._samp_rate_tool_bar.addWidget(Qt.QLabel('SAMP_RATE'+": ")) self._samp_rate_line_edit = Qt.QLineEdit(str(self.samp_rate)) self._samp_rate_tool_bar.addWidget(self._samp_rate_line_edit) self._samp_rate_line_edit.returnPressed.connect( lambda: self.set_samp_rate(eng_notation.str_to_num(str(self._samp_rate_line_edit.text().toAscii())))) self.top_grid_layout.addWidget(self._samp_rate_tool_bar, 9, 0, 1, 1) for r in range(9, 10): self.top_grid_layout.setRowStretch(r, 1) for c in range(0, 1): self.top_grid_layout.setColumnStretch(c, 1) self.probe_snr = blocks.probe_signal_f() self.probe_signal = blocks.probe_signal_f() def _probe_offset_func_probe(): while True: val = self.probe_offset.level() try: self.set_probe_offset_func(val) except AttributeError: pass time.sleep(1.0 / (10)) _probe_offset_func_thread = threading.Thread(target=_probe_offset_func_probe) _probe_offset_func_thread.daemon = True _probe_offset_func_thread.start() self.probe_noise = blocks.probe_signal_f() self._fft_min_tool_bar = Qt.QToolBar(self) self._fft_min_tool_bar.addWidget(Qt.QLabel('fft_min'+": ")) self._fft_min_line_edit = Qt.QLineEdit(str(self.fft_min)) self._fft_min_tool_bar.addWidget(self._fft_min_line_edit) self._fft_min_line_edit.returnPressed.connect( lambda: self.set_fft_min(eng_notation.str_to_num(str(self._fft_min_line_edit.text().toAscii())))) self.top_grid_layout.addWidget(self._fft_min_tool_bar, 9, 2, 1, 1) for r in range(9, 10): self.top_grid_layout.setRowStretch(r, 1) for c in range(2, 3): self.top_grid_layout.setColumnStretch(c, 1) self._fft_max_tool_bar = Qt.QToolBar(self) self._fft_max_tool_bar.addWidget(Qt.QLabel('fft_max'+": ")) self._fft_max_line_edit = Qt.QLineEdit(str(self.fft_max)) self._fft_max_tool_bar.addWidget(self._fft_max_line_edit) self._fft_max_line_edit.returnPressed.connect( lambda: self.set_fft_max(eng_notation.str_to_num(str(self._fft_max_line_edit.text().toAscii())))) self.top_grid_layout.addWidget(self._fft_max_tool_bar, 9, 3, 1, 1) for r in range(9, 10): self.top_grid_layout.setRowStretch(r, 1) for c in range(3, 4): self.top_grid_layout.setColumnStretch(c, 1) self._snr_label_tool_bar = Qt.QToolBar(self) if None: self._snr_label_formatter = None else: self._snr_label_formatter = lambda x: str(x) self._snr_label_tool_bar.addWidget(Qt.QLabel('SNR [dB]'+": ")) self._snr_label_label = Qt.QLabel(str(self._snr_label_formatter(self.snr_label))) self._snr_label_tool_bar.addWidget(self._snr_label_label) self.top_grid_layout.addWidget(self._snr_label_tool_bar, 3, 4, 1, 1) for r in range(3, 4): self.top_grid_layout.setRowStretch(r, 1) for c in range(4, 5): self.top_grid_layout.setColumnStretch(c, 1) self._signal_label_tool_bar = Qt.QToolBar(self) if None: self._signal_label_formatter = None else: self._signal_label_formatter = lambda x: str(x) self._signal_label_tool_bar.addWidget(Qt.QLabel('Signal [dBFS]'+": ")) self._signal_label_label = Qt.QLabel(str(self._signal_label_formatter(self.signal_label))) self._signal_label_tool_bar.addWidget(self._signal_label_label) self.top_grid_layout.addWidget(self._signal_label_tool_bar, 1, 4, 1, 1) for r in range(1, 2): self.top_grid_layout.setRowStretch(r, 1) for c in range(4, 5): self.top_grid_layout.setColumnStretch(c, 1) self.sigmf_source_0 = gr_sigmf.source(fp, "cf32" + ("_le" if sys.byteorder == "little" else "_be"), False) self._rx_freq_tool_bar = Qt.QToolBar(self) self._rx_freq_tool_bar.addWidget(Qt.QLabel('FREQ'+": ")) self._rx_freq_line_edit = Qt.QLineEdit(str(self.rx_freq)) self._rx_freq_tool_bar.addWidget(self._rx_freq_line_edit) self._rx_freq_line_edit.returnPressed.connect( lambda: self.set_rx_freq(eng_notation.str_to_num(str(self._rx_freq_line_edit.text().toAscii())))) self.top_grid_layout.addWidget(self._rx_freq_tool_bar, 9, 1, 1, 1) for r in range(9, 10): self.top_grid_layout.setRowStretch(r, 1) for c in range(1, 2): self.top_grid_layout.setColumnStretch(c, 1) self.rational_resampler_xxx_0 = filter.rational_resampler_ccc( interpolation=1, decimation=decim, taps=None, fractional_bw=None, ) self.qtgui_waterfall_sink_x_0 = qtgui.waterfall_sink_c( 2048, #size firdes.WIN_BLACKMAN_hARRIS, #wintype 0, #fc samp_rate, #bw "", #name 1 #number of inputs ) self.qtgui_waterfall_sink_x_0.set_update_time(0.010) 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(fft_min, fft_max) self._qtgui_waterfall_sink_x_0_win = sip.wrapinstance(self.qtgui_waterfall_sink_x_0.pyqwidget(), Qt.QWidget) self.top_grid_layout.addWidget(self._qtgui_waterfall_sink_x_0_win, 4, 0, 4, 4) for r in range(4, 8): self.top_grid_layout.setRowStretch(r, 1) for c in range(0, 4): self.top_grid_layout.setColumnStretch(c, 1) self.qtgui_freq_sink_x_0 = qtgui.freq_sink_c( 2048, #size firdes.WIN_BLACKMAN_hARRIS, #wintype 0, #fc samp_rate, #bw "RHCP", #name 1 #number of inputs ) self.qtgui_freq_sink_x_0.set_update_time(0.010) self.qtgui_freq_sink_x_0.set_y_axis(fft_min, fft_max) self.qtgui_freq_sink_x_0.set_y_label('Relative Gain', 'dB') self.qtgui_freq_sink_x_0.set_trigger_mode(qtgui.TRIG_MODE_FREE, 0.0, 0, "") self.qtgui_freq_sink_x_0.enable_autoscale(False) self.qtgui_freq_sink_x_0.enable_grid(True) self.qtgui_freq_sink_x_0.set_fft_average(0.05) self.qtgui_freq_sink_x_0.enable_axis_labels(True) self.qtgui_freq_sink_x_0.enable_control_panel(False) if not False: self.qtgui_freq_sink_x_0.disable_legend() if "complex" == "float" or "complex" == "msg_float": self.qtgui_freq_sink_x_0.set_plot_pos_half(not True) labels = ['', '', '', '', '', '', '', '', '', ''] widths = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1] colors = ["blue", "red", "green", "black", "cyan", "magenta", "yellow", "dark red", "dark green", "dark blue"] 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_freq_sink_x_0.set_line_label(i, "Data {0}".format(i)) else: self.qtgui_freq_sink_x_0.set_line_label(i, labels[i]) self.qtgui_freq_sink_x_0.set_line_width(i, widths[i]) self.qtgui_freq_sink_x_0.set_line_color(i, colors[i]) self.qtgui_freq_sink_x_0.set_line_alpha(i, alphas[i]) self._qtgui_freq_sink_x_0_win = sip.wrapinstance(self.qtgui_freq_sink_x_0.pyqwidget(), Qt.QWidget) self.top_grid_layout.addWidget(self._qtgui_freq_sink_x_0_win, 0, 0, 4, 4) for r in range(0, 4): self.top_grid_layout.setRowStretch(r, 1) for c in range(0, 4): self.top_grid_layout.setColumnStretch(c, 1) def _probe_snr_func_probe(): while True: val = self.probe_snr.level() try: self.set_probe_snr_func(val) except AttributeError: pass time.sleep(1.0 / (10)) _probe_snr_func_thread = threading.Thread(target=_probe_snr_func_probe) _probe_snr_func_thread.daemon = True _probe_snr_func_thread.start() def _probe_signal_func_probe(): while True: val = self.probe_signal.level() try: self.set_probe_signal_func(val) except AttributeError: pass time.sleep(1.0 / (10)) _probe_signal_func_thread = threading.Thread(target=_probe_signal_func_probe) _probe_signal_func_thread.daemon = True _probe_signal_func_thread.start() def _probe_noise_func_probe(): while True: val = self.probe_noise.level() try: self.set_probe_noise_func(val) except AttributeError: pass time.sleep(1.0 / (10)) _probe_noise_func_thread = threading.Thread(target=_probe_noise_func_probe) _probe_noise_func_thread.daemon = True _probe_noise_func_thread.start() self._offset_label_tool_bar = Qt.QToolBar(self) if None: self._offset_label_formatter = None else: self._offset_label_formatter = lambda x: str(x) self._offset_label_tool_bar.addWidget(Qt.QLabel('Offset [Hz]'+": ")) self._offset_label_label = Qt.QLabel(str(self._offset_label_formatter(self.offset_label))) self._offset_label_tool_bar.addWidget(self._offset_label_label) self.top_grid_layout.addWidget(self._offset_label_tool_bar, 0, 4, 1, 1) for r in range(0, 1): self.top_grid_layout.setRowStretch(r, 1) for c in range(4, 5): self.top_grid_layout.setColumnStretch(c, 1) self._noise_label_tool_bar = Qt.QToolBar(self) if None: self._noise_label_formatter = None else: self._noise_label_formatter = lambda x: str(x) self._noise_label_tool_bar.addWidget(Qt.QLabel('Noise [dBFS]'+": ")) self._noise_label_label = Qt.QLabel(str(self._noise_label_formatter(self.noise_label))) self._noise_label_tool_bar.addWidget(self._noise_label_label) self.top_grid_layout.addWidget(self._noise_label_tool_bar, 2, 4, 1, 1) for r in range(2, 3): self.top_grid_layout.setRowStretch(r, 1) for c in range(4, 5): self.top_grid_layout.setColumnStretch(c, 1) self._keep_n_tool_bar = Qt.QToolBar(self) self._keep_n_tool_bar.addWidget(Qt.QLabel('keep_n'+": ")) self._keep_n_line_edit = Qt.QLineEdit(str(self.keep_n)) self._keep_n_tool_bar.addWidget(self._keep_n_line_edit) self._keep_n_line_edit.returnPressed.connect( lambda: self.set_keep_n(eng_notation.str_to_num(str(self._keep_n_line_edit.text().toAscii())))) self.top_grid_layout.addWidget(self._keep_n_tool_bar, 10, 1, 1, 1) for r in range(10, 11): self.top_grid_layout.setRowStretch(r, 1) for c in range(1, 2): self.top_grid_layout.setColumnStretch(c, 1) self.fft_vxx_0_0 = fft.fft_vcc(nfft/decim, True, (window.blackmanharris(nfft/decim)), True, 4) self.fft_vxx_0 = fft.fft_vcc(nfft, True, (window.blackmanharris(nfft)), True, 4) self.blocks_throttle_0 = blocks.throttle(gr.sizeof_gr_complex*1, samp_rate*throttle_factor,True) self.blocks_tag_share_0 = blocks.tag_share(gr.sizeof_float, gr.sizeof_gr_complex, 1) self.blocks_sub_xx_0 = blocks.sub_ff(1) self.blocks_stream_to_vector_0_0 = blocks.stream_to_vector(gr.sizeof_gr_complex*1, nfft/decim) self.blocks_stream_to_vector_0 = blocks.stream_to_vector(gr.sizeof_gr_complex*1, nfft) self.blocks_nlog10_ff_0_0_0 = blocks.nlog10_ff(10, nfft/decim, -10*math.log10(nfft/decim)) self.blocks_nlog10_ff_0_0 = blocks.nlog10_ff(10, nfft, -10*math.log10(nfft)) self.blocks_multiply_xx_0 = blocks.multiply_vcc(1) self.blocks_multiply_const_vxx_0_0 = blocks.multiply_const_vff((samp_rate/(2*math.pi), )) self.blocks_moving_average_xx_0_1 = blocks.moving_average_ff(int(samp_rate/record_hz), 1.0/(samp_rate/record_hz), 4000, 1) self.blocks_moving_average_xx_0_0 = blocks.moving_average_ff(int(avg_len), 1.0/(avg_len)/(nfft/decim*2), 4000, nfft/decim) self.blocks_moving_average_xx_0 = blocks.moving_average_ff(int(avg_len), 1.0/(avg_len)/nfft, 4000, nfft) self.blocks_max_xx_0_0 = blocks.max_ff(nfft/decim,1) self.blocks_max_xx_0 = blocks.max_ff(nfft,1) self.blocks_keep_one_in_n_0_0 = blocks.keep_one_in_n(gr.sizeof_float*1, int(samp_rate/record_hz)) self.blocks_complex_to_mag_squared_0_0_0 = blocks.complex_to_mag_squared(nfft/decim) self.blocks_complex_to_mag_squared_0_0 = blocks.complex_to_mag_squared(nfft) self.analog_sig_source_x_0 = analog.sig_source_c(samp_rate, analog.GR_COS_WAVE, probe_offset_func+samp_rate/4, 1, 0) self.analog_pll_freqdet_cf_0 = analog.pll_freqdet_cf(math.pi/200, math.pi/10, -math.pi/10) self._alpha_tool_bar = Qt.QToolBar(self) self._alpha_tool_bar.addWidget(Qt.QLabel('alpha'+": ")) self._alpha_line_edit = Qt.QLineEdit(str(self.alpha)) self._alpha_tool_bar.addWidget(self._alpha_line_edit) self._alpha_line_edit.returnPressed.connect( lambda: self.set_alpha(eng_notation.str_to_num(str(self._alpha_line_edit.text().toAscii())))) self.top_grid_layout.addWidget(self._alpha_tool_bar, 10, 0, 1, 1) for r in range(10, 11): self.top_grid_layout.setRowStretch(r, 1) for c in range(0, 1): self.top_grid_layout.setColumnStretch(c, 1) ################################################## # Connections ################################################## self.connect((self.analog_pll_freqdet_cf_0, 0), (self.blocks_tag_share_0, 0)) self.connect((self.analog_sig_source_x_0, 0), (self.blocks_multiply_xx_0, 1)) self.connect((self.blocks_complex_to_mag_squared_0_0, 0), (self.blocks_moving_average_xx_0, 0)) self.connect((self.blocks_complex_to_mag_squared_0_0_0, 0), (self.blocks_moving_average_xx_0_0, 0)) self.connect((self.blocks_keep_one_in_n_0_0, 0), (self.probe_offset, 0)) self.connect((self.blocks_max_xx_0, 0), (self.blocks_sub_xx_0, 0)) self.connect((self.blocks_max_xx_0, 0), (self.probe_signal, 0)) self.connect((self.blocks_max_xx_0_0, 0), (self.blocks_sub_xx_0, 1)) self.connect((self.blocks_max_xx_0_0, 0), (self.probe_noise, 0)) self.connect((self.blocks_moving_average_xx_0, 0), (self.blocks_nlog10_ff_0_0, 0)) self.connect((self.blocks_moving_average_xx_0_0, 0), (self.blocks_nlog10_ff_0_0_0, 0)) self.connect((self.blocks_moving_average_xx_0_1, 0), (self.blocks_keep_one_in_n_0_0, 0)) self.connect((self.blocks_multiply_const_vxx_0_0, 0), (self.blocks_moving_average_xx_0_1, 0)) self.connect((self.blocks_multiply_xx_0, 0), (self.rational_resampler_xxx_0, 0)) self.connect((self.blocks_nlog10_ff_0_0, 0), (self.blocks_max_xx_0, 0)) self.connect((self.blocks_nlog10_ff_0_0_0, 0), (self.blocks_max_xx_0_0, 0)) self.connect((self.blocks_stream_to_vector_0, 0), (self.fft_vxx_0, 0)) self.connect((self.blocks_stream_to_vector_0_0, 0), (self.fft_vxx_0_0, 0)) self.connect((self.blocks_sub_xx_0, 0), (self.probe_snr, 0)) self.connect((self.blocks_tag_share_0, 0), (self.blocks_multiply_const_vxx_0_0, 0)) self.connect((self.blocks_throttle_0, 0), (self.analog_pll_freqdet_cf_0, 0)) self.connect((self.blocks_throttle_0, 0), (self.blocks_multiply_xx_0, 0)) self.connect((self.blocks_throttle_0, 0), (self.blocks_stream_to_vector_0, 0)) self.connect((self.blocks_throttle_0, 0), (self.blocks_tag_share_0, 1)) self.connect((self.blocks_throttle_0, 0), (self.qtgui_freq_sink_x_0, 0)) self.connect((self.blocks_throttle_0, 0), (self.qtgui_waterfall_sink_x_0, 0)) self.connect((self.fft_vxx_0, 0), (self.blocks_complex_to_mag_squared_0_0, 0)) self.connect((self.fft_vxx_0_0, 0), (self.blocks_complex_to_mag_squared_0_0_0, 0)) self.connect((self.rational_resampler_xxx_0, 0), (self.blocks_stream_to_vector_0_0, 0)) self.connect((self.sigmf_source_0, 0), (self.blocks_throttle_0, 0))