text: #!/usr/bin/env python
  ##################################################
  # Gnuradio Python Flow Graph
  # Title: Hackrf white space 
  # Description: Example of an OFDM Transmitter
  # Generated: Tue Apr 11 13:09:50 2017
  ##################################################
  
  from PyQt4 import Qt
  from gnuradio import blocks
  from gnuradio import digital
  from gnuradio import eng_notation
  from gnuradio import fft
  from gnuradio import gr
  from gnuradio.eng_option import eng_option
  from gnuradio.fft import window
  from gnuradio.filter import firdes
  from optparse import OptionParser
  import osmosdr
  import pmt
  import sys
  
  class tx_hackrf(gr.top_block, Qt.QWidget):
  
      def __init__(self):
          gr.top_block.__init__(self, "Hackrf white space ")
          Qt.QWidget.__init__(self)
          self.setWindowTitle("Hackrf white space ")
          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", "tx_hackrf")
          self.restoreGeometry(self.settings.value("geometry").toByteArray())
  
  
          ##################################################
          # Variables
          ##################################################
          self.occupied_carriers = occupied_carriers = (range(-26, -21) + range(-20, -7) + range(-6, 0) + range(1, 7) + range(8, 21) + range(22, 27),)
          self.length_tag_key = length_tag_key = "packet_len"
          self.sync_word2 = sync_word2 = [0, 0, 0, 0, 0, 0, -1, -1, -1, -1, 1, 1, -1, -1, -1, 1, -1, 1, 1, 1, 1, 1, -1, -1, -1, -1, -1, 1, -1, -1, 1, -1, 0, 1, -1, 1, 1, 1, -1, 1, 1, 1, -1, 1, 1, 1, 1, -1, 1, -1, -1, -1, 1, -1, 1, -1, -1, -1, -1, 0, 0, 0, 0, 0] 
          self.sync_word1 = sync_word1 = [0., 0., 0., 0., 0., 0., 0., 1.41421356, 0., -1.41421356, 0., 1.41421356, 0., -1.41421356, 0., -1.41421356, 0., -1.41421356, 0., 1.41421356, 0., -1.41421356, 0., 1.41421356, 0., -1.41421356, 0., -1.41421356, 0., -1.41421356, 0., -1.41421356, 0., 1.41421356, 0., -1.41421356, 0., 1.41421356, 0., 1.41421356, 0., 1.41421356, 0., -1.41421356, 0., 1.41421356, 0., 1.41421356, 0., 1.41421356, 0., -1.41421356, 0., 1.41421356, 0., 1.41421356, 0., 1.41421356, 0., 0., 0., 0., 0., 0.]
          self.samp_rate = samp_rate = 1E6
          self.rolloff = rolloff = 0
          self.pilot_symbols = pilot_symbols = ((1, 1, 1, -1,),)
          self.pilot_carriers = pilot_carriers = ((-21, -7, 7, 21,),)
          self.payload_mod = payload_mod = digital.constellation_qpsk()
          self.packet_len = packet_len = 96
          self.header_mod = header_mod = digital.constellation_bpsk()
          self.hdr_format = hdr_format = digital.packet_header_ofdm(occupied_carriers, 1, length_tag_key)
          self.fft_len = fft_len = 64
  
          ##################################################
          # Blocks
          ##################################################
          self.osmosdr_sink_0 = osmosdr.sink( args="numchan=" + str(1) + " " + "" )
          self.osmosdr_sink_0.set_sample_rate(samp_rate)
          self.osmosdr_sink_0.set_center_freq(109E6, 0)
          self.osmosdr_sink_0.set_freq_corr(0, 0)
          self.osmosdr_sink_0.set_gain(4, 0)
          self.osmosdr_sink_0.set_if_gain(20, 0)
          self.osmosdr_sink_0.set_bb_gain(20, 0)
          self.osmosdr_sink_0.set_antenna("", 0)
          self.osmosdr_sink_0.set_bandwidth(0, 0)
            
          self.fft_vxx_0 = fft.fft_vcc(fft_len, False, (()), True, 1)
          self.digital_packet_headergenerator_bb_default_0 = digital.packet_headergenerator_bb(96, "packet_len")
          self.digital_ofdm_cyclic_prefixer_0 = digital.ofdm_cyclic_prefixer(fft_len, fft_len+fft_len/4, rolloff, length_tag_key)
          self.digital_ofdm_carrier_allocator_cvc_0 = digital.ofdm_carrier_allocator_cvc(fft_len, occupied_carriers, pilot_carriers, pilot_symbols, (sync_word1, sync_word2), length_tag_key)
          self.digital_crc32_bb_0 = digital.crc32_bb(False, length_tag_key)
          self.digital_chunks_to_symbols_xx_0_0 = digital.chunks_to_symbols_bc((payload_mod.points()), 1)
          self.digital_chunks_to_symbols_xx_0 = digital.chunks_to_symbols_bc((header_mod.points()), 1)
          self.blocks_tagged_stream_mux_0 = blocks.tagged_stream_mux(gr.sizeof_gr_complex*1, length_tag_key, 0)
          self.blocks_tag_gate_0 = blocks.tag_gate(gr.sizeof_gr_complex * 1, False)
          self.blocks_repack_bits_bb_0 = blocks.repack_bits_bb(8, payload_mod.bits_per_symbol(), length_tag_key, False)
          self.blocks_pdu_to_tagged_stream_0 = blocks.pdu_to_tagged_stream(blocks.byte_t, "packet_len")
          self.blocks_multiply_const_vxx_0 = blocks.multiply_const_vcc((0.05, ))
          self.blocks_message_strobe_0_0 = blocks.message_strobe(pmt.intern("PDU Test"), 20)
  
          ##################################################
          # Connections
          ##################################################
          self.connect((self.digital_packet_headergenerator_bb_default_0, 0), (self.digital_chunks_to_symbols_xx_0, 0))
          self.connect((self.digital_chunks_to_symbols_xx_0, 0), (self.blocks_tagged_stream_mux_0, 0))
          self.connect((self.digital_chunks_to_symbols_xx_0_0, 0), (self.blocks_tagged_stream_mux_0, 1))
          self.connect((self.blocks_repack_bits_bb_0, 0), (self.digital_chunks_to_symbols_xx_0_0, 0))
          self.connect((self.blocks_pdu_to_tagged_stream_0, 0), (self.digital_crc32_bb_0, 0))
          self.connect((self.digital_crc32_bb_0, 0), (self.blocks_repack_bits_bb_0, 0))
          self.connect((self.digital_crc32_bb_0, 0), (self.digital_packet_headergenerator_bb_default_0, 0))
          self.connect((self.blocks_multiply_const_vxx_0, 0), (self.blocks_tag_gate_0, 0))
          self.connect((self.digital_ofdm_cyclic_prefixer_0, 0), (self.blocks_multiply_const_vxx_0, 0))
          self.connect((self.blocks_tag_gate_0, 0), (self.osmosdr_sink_0, 0))
          self.connect((self.blocks_tagged_stream_mux_0, 0), (self.digital_ofdm_carrier_allocator_cvc_0, 0))
          self.connect((self.fft_vxx_0, 0), (self.digital_ofdm_cyclic_prefixer_0, 0))
          self.connect((self.digital_ofdm_carrier_allocator_cvc_0, 0), (self.fft_vxx_0, 0))
  
          ##################################################
          # Asynch Message Connections
          ##################################################
          self.msg_connect(self.blocks_message_strobe_0_0, "strobe", self.blocks_pdu_to_tagged_stream_0, "pdus")
  
  # QT sink close method reimplementation
      def closeEvent(self, event):
          self.settings = Qt.QSettings("GNU Radio", "tx_hackrf")
          self.settings.setValue("geometry", self.saveGeometry())
          event.accept()
  
      def get_occupied_carriers(self):
          return self.occupied_carriers
  
      def set_occupied_carriers(self, occupied_carriers):
          self.occupied_carriers = occupied_carriers
          self.set_hdr_format(digital.packet_header_ofdm(self.occupied_carriers, 1, self.length_tag_key))
  
      def get_length_tag_key(self):
          return self.length_tag_key
  
      def set_length_tag_key(self, length_tag_key):
          self.length_tag_key = length_tag_key
          self.set_hdr_format(digital.packet_header_ofdm(self.occupied_carriers, 1, self.length_tag_key))
  
      def get_sync_word2(self):
          return self.sync_word2
  
      def set_sync_word2(self, sync_word2):
          self.sync_word2 = sync_word2
  
      def get_sync_word1(self):
          return self.sync_word1
  
      def set_sync_word1(self, sync_word1):
          self.sync_word1 = sync_word1
  
      def get_samp_rate(self):
          return self.samp_rate
  
      def set_samp_rate(self, samp_rate):
          self.samp_rate = samp_rate
          self.osmosdr_sink_0.set_sample_rate(self.samp_rate)
  
      def get_rolloff(self):
          return self.rolloff
  
      def set_rolloff(self, rolloff):
          self.rolloff = rolloff
  
      def get_pilot_symbols(self):
          return self.pilot_symbols
  
      def set_pilot_symbols(self, pilot_symbols):
          self.pilot_symbols = pilot_symbols
  
      def get_pilot_carriers(self):
          return self.pilot_carriers
  
      def set_pilot_carriers(self, pilot_carriers):
          self.pilot_carriers = pilot_carriers
  
      def get_payload_mod(self):
          return self.payload_mod
  
      def set_payload_mod(self, payload_mod):
          self.payload_mod = payload_mod
  
      def get_packet_len(self):
          return self.packet_len
  
      def set_packet_len(self, packet_len):
          self.packet_len = packet_len
  
      def get_header_mod(self):
          return self.header_mod
  
      def set_header_mod(self, header_mod):
          self.header_mod = header_mod
  
      def get_hdr_format(self):
          return self.hdr_format
  
      def set_hdr_format(self, hdr_format):
          self.hdr_format = hdr_format
  
      def get_fft_len(self):
          return self.fft_len
  
      def set_fft_len(self, fft_len):
          self.fft_len = fft_len
  
  if __name__ == '__main__':
      import ctypes
      import os
      if os.name == 'posix':
          try:
              x11 = ctypes.cdll.LoadLibrary('libX11.so')
              x11.XInitThreads()
          except:
              print "Warning: failed to XInitThreads()"
      parser = OptionParser(option_class=eng_option, usage="%prog: [options]")
      (options, args) = parser.parse_args()
      qapp = Qt.QApplication(sys.argv)
      tb = tx_hackrf()
      tb.start()
      tb.show()
      def quitting():
          tb.stop()
          tb.wait()
      qapp.connect(qapp, Qt.SIGNAL("aboutToQuit()"), quitting)
      qapp.exec_()
      tb = None #to clean up Qt widgets
  
  