text: #!/usr/bin/env python3
  # -*- coding: utf-8 -*-
  
  #
  # SPDX-License-Identifier: GPL-3.0
  #
  # GNU Radio Python Flow Graph
  # Title: Sigmf Adsb Playback
  # GNU Radio version: 3.8.2.0
  
  from distutils.version import StrictVersion
  
  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 PyQt5 import Qt
  from gnuradio import eng_notation
  from gnuradio import qtgui
  from gnuradio.filter import firdes
  import sip
  from gnuradio import fosphor
  from gnuradio.fft import window
  from gnuradio import analog
  from gnuradio import blocks
  from gnuradio import filter
  from gnuradio import gr
  import sys
  import signal
  from argparse import ArgumentParser
  from gnuradio.eng_arg import eng_float, intx
  from gnuradio.qtgui import Range, RangeWidget
  import adsb
  import gr_sigmf
  
  from gnuradio import qtgui
  
  class sigmf_adsb_playback(gr.top_block, Qt.QWidget):
  
      def __init__(self):
          gr.top_block.__init__(self, "Sigmf Adsb Playback")
          Qt.QWidget.__init__(self)
          self.setWindowTitle("Sigmf Adsb Playback")
          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", "sigmf_adsb_playback")
  
          try:
              if StrictVersion(Qt.qVersion()) < StrictVersion("5.0.0"):
                  self.restoreGeometry(self.settings.value("geometry").toByteArray())
              else:
                  self.restoreGeometry(self.settings.value("geometry"))
          except:
              pass
  
          ##################################################
          # Variables
          ##################################################
          self.threshold = threshold = 10
          self.samp_rate = samp_rate = 10e6
          self.rx_gain = rx_gain = 50
          self.lpf_cutoff = lpf_cutoff = 1.5e6
          self.freq = freq = 1090e6
  
          ##################################################
          # Blocks
          ##################################################
          self._threshold_tool_bar = Qt.QToolBar(self)
          self._threshold_tool_bar.addWidget(Qt.QLabel('Detection Threshold' + ": "))
          self._threshold_line_edit = Qt.QLineEdit(str(self.threshold))
          self._threshold_tool_bar.addWidget(self._threshold_line_edit)
          self._threshold_line_edit.returnPressed.connect(
              lambda: self.set_threshold(eng_notation.str_to_num(str(self._threshold_line_edit.text()))))
          self.top_grid_layout.addWidget(self._threshold_tool_bar, 0, 6, 1, 2)
          for r in range(0, 1):
              self.top_grid_layout.setRowStretch(r, 1)
          for c in range(6, 8):
              self.top_grid_layout.setColumnStretch(c, 1)
          self._lpf_cutoff_tool_bar = Qt.QToolBar(self)
          self._lpf_cutoff_tool_bar.addWidget(Qt.QLabel('lpf_cutoff' + ": "))
          self._lpf_cutoff_line_edit = Qt.QLineEdit(str(self.lpf_cutoff))
          self._lpf_cutoff_tool_bar.addWidget(self._lpf_cutoff_line_edit)
          self._lpf_cutoff_line_edit.returnPressed.connect(
              lambda: self.set_lpf_cutoff(eng_notation.str_to_num(str(self._lpf_cutoff_line_edit.text()))))
          self.top_grid_layout.addWidget(self._lpf_cutoff_tool_bar, 1, 6, 1, 2)
          for r in range(1, 2):
              self.top_grid_layout.setRowStretch(r, 1)
          for c in range(6, 8):
              self.top_grid_layout.setColumnStretch(c, 1)
          self.sigmf_source_0 = gr_sigmf.source('/captures/20191211/ADSB_2019-12-11T22:34:43Z.sigmf-data', "cf32" + ("_le" if sys.byteorder == "little" else "_be"), False)
          self._rx_gain_range = Range(1, 76, 1, 50, 200)
          self._rx_gain_win = RangeWidget(self._rx_gain_range, self.set_rx_gain, 'rx_gain', "counter_slider", float)
          self.top_grid_layout.addWidget(self._rx_gain_win, 0, 4, 1, 2)
          for r in range(0, 1):
              self.top_grid_layout.setRowStretch(r, 1)
          for c in range(4, 6):
              self.top_grid_layout.setColumnStretch(c, 1)
          self.rational_resampler_xxx_0 = filter.rational_resampler_ccc(
                  interpolation=4,
                  decimation=10,
                  taps=None,
                  fractional_bw=None)
          self.qtgui_time_sink_x_0 = qtgui.time_sink_f(
              int(samp_rate*1*150e-6), #size
              int(samp_rate*1), #samp_rate
              "", #name
              2 #number of inputs
          )
          self.qtgui_time_sink_x_0.set_update_time(1.0/100.0)
          self.qtgui_time_sink_x_0.set_y_axis(0, 100)
  
          self.qtgui_time_sink_x_0.set_y_label('Amplitude', "")
  
          self.qtgui_time_sink_x_0.enable_tags(True)
          self.qtgui_time_sink_x_0.set_trigger_mode(qtgui.TRIG_MODE_TAG, qtgui.TRIG_SLOPE_POS, 0, 1.25e-6, 0, "burst")
          self.qtgui_time_sink_x_0.enable_autoscale(False)
          self.qtgui_time_sink_x_0.enable_grid(True)
          self.qtgui_time_sink_x_0.enable_axis_labels(True)
          self.qtgui_time_sink_x_0.enable_control_panel(False)
          self.qtgui_time_sink_x_0.enable_stem_plot(False)
  
          self.qtgui_time_sink_x_0.disable_legend()
  
          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]
          styles = [1, 1, 1, 1, 1,
              1, 1, 1, 1, 1]
          markers = [0, -1, -1, -1, -1,
              -1, -1, -1, -1, -1]
  
  
          for i in range(2):
              if len(labels[i]) == 0:
                  self.qtgui_time_sink_x_0.set_line_label(i, "Data {0}".format(i))
              else:
                  self.qtgui_time_sink_x_0.set_line_label(i, labels[i])
              self.qtgui_time_sink_x_0.set_line_width(i, widths[i])
              self.qtgui_time_sink_x_0.set_line_color(i, colors[i])
              self.qtgui_time_sink_x_0.set_line_style(i, styles[i])
              self.qtgui_time_sink_x_0.set_line_marker(i, markers[i])
              self.qtgui_time_sink_x_0.set_line_alpha(i, alphas[i])
  
          self._qtgui_time_sink_x_0_win = sip.wrapinstance(self.qtgui_time_sink_x_0.pyqwidget(), Qt.QWidget)
          self.top_grid_layout.addWidget(self._qtgui_time_sink_x_0_win, 2, 4, 1, 4)
          for r in range(2, 3):
              self.top_grid_layout.setRowStretch(r, 1)
          for c in range(4, 8):
              self.top_grid_layout.setColumnStretch(c, 1)
          self.low_pass_filter_0 = filter.fir_filter_ccf(
              1,
              firdes.low_pass(
                  1,
                  samp_rate/10*4,
                  lpf_cutoff,
                  10e3,
                  firdes.WIN_HAMMING,
                  6.76))
          self.fosphor_qt_sink_c_1 = fosphor.qt_sink_c()
          self.fosphor_qt_sink_c_1.set_fft_window(window.WIN_BLACKMAN_hARRIS)
          self.fosphor_qt_sink_c_1.set_frequency_range(0, samp_rate/10*4)
          self._fosphor_qt_sink_c_1_win = sip.wrapinstance(self.fosphor_qt_sink_c_1.pyqwidget(), Qt.QWidget)
          self.top_grid_layout.addWidget(self._fosphor_qt_sink_c_1_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)
          self.blocks_unpacked_to_packed_xx_0 = blocks.unpacked_to_packed_bb(1, gr.GR_MSB_FIRST)
          self.blocks_throttle_0 = blocks.throttle(gr.sizeof_gr_complex*1, samp_rate ,True)
          self.blocks_tagged_stream_to_pdu_0 = blocks.tagged_stream_to_pdu(blocks.byte_t, 'packet_len')
          self.blocks_tagged_stream_multiply_length_0 = blocks.tagged_stream_multiply_length(gr.sizeof_char*1, 'packet_len', 1.0/8)
          self.blocks_socket_pdu_0 = blocks.socket_pdu('TCP_SERVER', '127.0.0.1', '52001', 10000, False)
          self.blocks_pdu_to_tagged_stream_0 = blocks.pdu_to_tagged_stream(blocks.byte_t, 'packet_len')
          self.blocks_message_debug_0 = blocks.message_debug()
          self.blocks_complex_to_mag_squared_0 = blocks.complex_to_mag_squared(1)
          self.analog_const_source_x_0 = analog.sig_source_f(0, analog.GR_CONST_WAVE, 0, 0, threshold)
          self.analog_agc2_xx_0 = analog.agc2_cc(1e-6, 1e-3, 1.0, 1.0)
          self.analog_agc2_xx_0.set_max_gain(65536)
          self.adsb_framer_1 = adsb.framer(samp_rate, threshold)
          self.adsb_demod_0 = adsb.demod(samp_rate)
          self.adsb_decoder_0 = adsb.decoder("All Messages", "None", "None")
  
  
  
          ##################################################
          # Connections
          ##################################################
          self.msg_connect((self.adsb_decoder_0, 'decoded'), (self.blocks_pdu_to_tagged_stream_0, 'pdus'))
          self.msg_connect((self.adsb_demod_0, 'demodulated'), (self.adsb_decoder_0, 'demodulated'))
          self.msg_connect((self.blocks_tagged_stream_to_pdu_0, 'pdus'), (self.blocks_message_debug_0, 'print'))
          self.msg_connect((self.blocks_tagged_stream_to_pdu_0, 'pdus'), (self.blocks_socket_pdu_0, 'pdus'))
          self.connect((self.adsb_demod_0, 0), (self.qtgui_time_sink_x_0, 0))
          self.connect((self.adsb_framer_1, 0), (self.adsb_demod_0, 0))
          self.connect((self.analog_agc2_xx_0, 0), (self.low_pass_filter_0, 0))
          self.connect((self.analog_const_source_x_0, 0), (self.qtgui_time_sink_x_0, 1))
          self.connect((self.blocks_complex_to_mag_squared_0, 0), (self.adsb_framer_1, 0))
          self.connect((self.blocks_pdu_to_tagged_stream_0, 0), (self.blocks_unpacked_to_packed_xx_0, 0))
          self.connect((self.blocks_tagged_stream_multiply_length_0, 0), (self.blocks_tagged_stream_to_pdu_0, 0))
          self.connect((self.blocks_throttle_0, 0), (self.rational_resampler_xxx_0, 0))
          self.connect((self.blocks_unpacked_to_packed_xx_0, 0), (self.blocks_tagged_stream_multiply_length_0, 0))
          self.connect((self.low_pass_filter_0, 0), (self.blocks_complex_to_mag_squared_0, 0))
          self.connect((self.low_pass_filter_0, 0), (self.fosphor_qt_sink_c_1, 0))
          self.connect((self.rational_resampler_xxx_0, 0), (self.analog_agc2_xx_0, 0))
          self.connect((self.sigmf_source_0, 0), (self.blocks_throttle_0, 0))
  
  
      def closeEvent(self, event):
          self.settings = Qt.QSettings("GNU Radio", "sigmf_adsb_playback")
          self.settings.setValue("geometry", self.saveGeometry())
          event.accept()
  
      def get_threshold(self):
          return self.threshold
  
      def set_threshold(self, threshold):
          self.threshold = threshold
          Qt.QMetaObject.invokeMethod(self._threshold_line_edit, "setText", Qt.Q_ARG("QString", eng_notation.num_to_str(self.threshold)))
          self.adsb_framer_1.set_threshold(self.threshold)
          self.analog_const_source_x_0.set_offset(self.threshold)
  
      def get_samp_rate(self):
          return self.samp_rate
  
      def set_samp_rate(self, samp_rate):
          self.samp_rate = samp_rate
          self.blocks_throttle_0.set_sample_rate(self.samp_rate )
          self.fosphor_qt_sink_c_1.set_frequency_range(0, self.samp_rate/10*4)
          self.low_pass_filter_0.set_taps(firdes.low_pass(1, self.samp_rate/10*4, self.lpf_cutoff, 10e3, firdes.WIN_HAMMING, 6.76))
          self.qtgui_time_sink_x_0.set_samp_rate(int(self.samp_rate*1))
  
      def get_rx_gain(self):
          return self.rx_gain
  
      def set_rx_gain(self, rx_gain):
          self.rx_gain = rx_gain
  
      def get_lpf_cutoff(self):
          return self.lpf_cutoff
  
      def set_lpf_cutoff(self, lpf_cutoff):
          self.lpf_cutoff = lpf_cutoff
          Qt.QMetaObject.invokeMethod(self._lpf_cutoff_line_edit, "setText", Qt.Q_ARG("QString", eng_notation.num_to_str(self.lpf_cutoff)))
          self.low_pass_filter_0.set_taps(firdes.low_pass(1, self.samp_rate/10*4, self.lpf_cutoff, 10e3, firdes.WIN_HAMMING, 6.76))
  
      def get_freq(self):
          return self.freq
  
      def set_freq(self, freq):
          self.freq = freq
  
  
  
  
  
  def main(top_block_cls=sigmf_adsb_playback, options=None):
  
      if StrictVersion("4.5.0") <= StrictVersion(Qt.qVersion()) < StrictVersion("5.0.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 sig_handler(sig=None, frame=None):
          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)
  
      def quitting():
          tb.stop()
          tb.wait()
  
      qapp.aboutToQuit.connect(quitting)
      qapp.exec_()
  
  if __name__ == '__main__':
      main()
  