Beispiel #1
0
    def test_001(self):
        port = 65500

        n_data = 16
        src_data = [float(x) for x in range(n_data)]
        expected_result = tuple(src_data)
        src = gr.vector_source_f(src_data)
        udp_snd = gr.udp_sink( gr.sizeof_float, 'localhost', port )
        self.tb_snd.connect( src, udp_snd )

        udp_rcv = gr.udp_source( gr.sizeof_float, 'localhost', port )
        dst = gr.vector_sink_f()
        self.tb_rcv.connect( udp_rcv, dst )

        self.tb_rcv.start()
        self.tb_snd.run()
        udp_snd.disconnect()
        self.timeout = False
        q = Timer(3.0,self.stop_rcv)
        q.start()
        self.tb_rcv.wait()
        q.cancel()

        result_data = dst.data()
        self.assertEqual(expected_result, result_data)
        self.assert_(not self.timeout)
Beispiel #2
0
    def __init__(self, serverip, serverport, clientname, packetsize,
                 simulation, samp_rate, center_freq, net_id,
                 device_addr, stream_args):
        gr.hier_block2.__init__(self, "sim_source_c",
                                gr.io_signature(0, 0, 0),
                                gr.io_signature(1, 1, gr.sizeof_gr_complex))
        uhd_gate.__init__(self)
        self.simulation = simulation
        self.serverip = serverip
        self.samp_rate = samp_rate
        self.typ = 'rx'
        if not self.simulation:
            self.usrp = uhd.usrp_source(device_addr, stream_args)
                # TODO: Parameters
            self.connect(self.usrp, self)
        else:
            self.simsrc = sim_source_cc(self, serverip, serverport, clientname,
                                        packetsize, samp_rate, center_freq,
                                        net_id)
            # TODO: dirty hack!!!
#            self.tcp_source = grc_blks2.tcp_source(itemsize=gr.sizeof_gr_complex,
#                                                   addr=self.serverip,
#                                                   port=self.simsrc.get_dataport(),
#                                                   server=False)
            self.tcp_source = gr.udp_source(itemsize=gr.sizeof_gr_complex,
                                            host=self.serverip,
                                            port=self.simsrc.get_dataport(),
                                            payload_size=1472,
                                            eof=False,
                                            wait=True)
            self.gain_blk = blocks.multiply_const_vcc((1, ))
            self.connect(self.tcp_source, self.gain_blk, self.simsrc, self)
    def __init__(self, host, port, pkt_size, eof, wait):
        gr.top_block.__init__(self, "vector_sink")

        udp = gr.udp_source(gr.sizeof_float, host, port, pkt_size,
                            eof=eof, wait=wait)
        sink = gr.file_sink(gr.sizeof_float, "received.dat")
        self.connect(udp, sink)
Beispiel #4
0
    def test_002(self):
        udp_rcv = gr.udp_source( gr.sizeof_float, '0.0.0.0', 0, eof=False )
        rcv_port = udp_rcv.get_port()

        udp_snd = gr.udp_sink( gr.sizeof_float, '127.0.0.1', 65500 )
        udp_snd.connect( 'localhost', rcv_port )

        n_data = 16
        src_data = [float(x) for x in range(n_data)]
        expected_result = tuple(src_data)
        src = gr.vector_source_f(src_data)
        dst = gr.vector_sink_f()

        self.tb_snd.connect( src, udp_snd )
        self.tb_rcv.connect( udp_rcv, dst )

        self.tb_rcv.start()
        self.tb_snd.run()
        udp_snd.disconnect()
        self.timeout = False
        q = Timer(3.0,self.stop_rcv)
        q.start()
        self.tb_rcv.wait()
        q.cancel()

        result_data = dst.data()
        self.assertEqual(expected_result, result_data)
        self.assert_(self.timeout)  # source ignores EOF?
Beispiel #5
0
	def __init__(self):
		grc_wxgui.top_block_gui.__init__(self, title="Top Block")

		##################################################
		# Variables
		##################################################
		self.samp_rate = samp_rate = 32000

		##################################################
		# Blocks
		##################################################
		self.wxgui_scopesink2_0 = scopesink2.scope_sink_f(
			self.GetWin(),
			title="Scope Plot",
			sample_rate=125,
			v_scale=0,
			v_offset=0,
			t_scale=1000,
			ac_couple=False,
			xy_mode=False,
			num_inputs=1,
			trig_mode=gr.gr_TRIG_MODE_AUTO,
			y_axis_label="Counts",
		)
		self.Add(self.wxgui_scopesink2_0.win)
		self.gr_udp_source_1 = gr.udp_source(gr.sizeof_short*1, "127.0.0.1", 1235, 2, True, True)
		self.gr_short_to_float_0_0 = gr.short_to_float()

		##################################################
		# Connections
		##################################################
		self.connect((self.gr_udp_source_1, 0), (self.gr_short_to_float_0_0, 0))
		self.connect((self.gr_short_to_float_0_0, 0), (self.wxgui_scopesink2_0, 0))
	def __init__(self):
		grc_wxgui.top_block_gui.__init__(self, title="Top Block")

		##################################################
		# Variables
		##################################################
		self.samp_rate = samp_rate = 32000
		self.remove_head = remove_head = 0

		##################################################
		# Blocks
		##################################################
		self._remove_head_chooser = forms.radio_buttons(
			parent=self.GetWin(),
			value=self.remove_head,
			callback=self.set_remove_head,
			label="Remove Head",
			choices=[0,1],
			labels=[],
			style=wx.RA_HORIZONTAL,
		)
		self.Add(self._remove_head_chooser)
		self.wxgui_scopesink2_0 = scopesink2.scope_sink_f(
			self.GetWin(),
			title="Scope Plot",
			sample_rate=samp_rate,
			v_scale=0,
			v_offset=0,
			t_scale=0,
			ac_couple=False,
			xy_mode=False,
			num_inputs=2,
			trig_mode=gr.gr_TRIG_MODE_AUTO,
			y_axis_label="Counts",
		)
		self.Add(self.wxgui_scopesink2_0.win)
		self.gr_udp_source_0 = gr.udp_source(gr.sizeof_short*1, "192.168.2.200", 9997, 590, False, True)
		self.gr_short_to_float_0_0 = gr.short_to_float(1, 1)
		self.gr_short_to_float_0 = gr.short_to_float(1, 1)
		self.gr_file_sink_0_1_0 = gr.file_sink(gr.sizeof_short*1, "/home/cgardner/sandbox/gr-csg/gr-fp/grc_testfp/test_fp_odd.bin")
		self.gr_file_sink_0_1_0.set_unbuffered(True)
		self.gr_file_sink_0_1 = gr.file_sink(gr.sizeof_short*1, "/home/cgardner/sandbox/gr-csg/gr-fp/grc_testfp/test_raw_even.bin")
		self.gr_file_sink_0_1.set_unbuffered(True)
		self.gr_deinterleave_0 = gr.deinterleave(gr.sizeof_short*1)
		self.fpgnu_fpdata_sink_0 = fpgnu_swig.fpdata_sink(remove_head)

		##################################################
		# Connections
		##################################################
		self.connect((self.gr_udp_source_0, 0), (self.fpgnu_fpdata_sink_0, 0))
		self.connect((self.gr_short_to_float_0, 0), (self.wxgui_scopesink2_0, 0))
		self.connect((self.gr_deinterleave_0, 1), (self.gr_file_sink_0_1_0, 0))
		self.connect((self.fpgnu_fpdata_sink_0, 0), (self.gr_deinterleave_0, 0))
		self.connect((self.gr_deinterleave_0, 0), (self.gr_file_sink_0_1, 0))
		self.connect((self.gr_short_to_float_0_0, 0), (self.wxgui_scopesink2_0, 1))
		self.connect((self.gr_deinterleave_0, 1), (self.gr_short_to_float_0_0, 0))
		self.connect((self.gr_deinterleave_0, 0), (self.gr_short_to_float_0, 0))
Beispiel #7
0
 def __init__(self, host, port, pkt_size, sample_rate, eof, wait):
     gr.top_block.__init__(self, "dial_tone_sink")
     udp = gr.udp_source(gr.sizeof_float,
                         host,
                         port,
                         pkt_size,
                         eof=eof,
                         wait=wait)
     sink = audio.sink(sample_rate)
     self.connect(udp, sink)
Beispiel #8
0
 def __init__(self, host, port, pkt_size, sample_rate, eof, wait):
     gr.top_block.__init__(self, "audio_sink")
     src = gr.udp_source(gr.sizeof_float,
                         host,
                         port,
                         pkt_size,
                         eof=eof,
                         wait=wait)
     dst = audio.sink(sample_rate)
     self.connect(src, dst)
Beispiel #9
0
 def xUdpSource(self, address):
 #   ------------------------------------------------------------------------
     try:
         host, port = address.split(":")
     except:
         print "UdpSourceAdapter.xUdpSource: Bad address \"%s\"" % address
         return None
     try:
         return gr.udp_source(
             gr.sizeof_float, host, int(port), 1472, False, True)
     except:
         print "UdpSourceAdapter.xUdpSource: Blown creation \"%s\"" % address
         return None
    def __init__(self):
        gr.top_block.__init__(self, "Burst View")
        Qt.QWidget.__init__(self)
        self.setWindowTitle("Burst View")
        self.setWindowIcon(Qt.QIcon.fromTheme('gnuradio-grc'))
        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)



        ##################################################
        # Variables
        ##################################################
        self.samp_rate = samp_rate = 1e6

        ##################################################
        # Blocks
        ##################################################
        self.qtgui_sink_x_0 = qtgui.sink_c(
        	1024, #fftsize
        	firdes.WIN_BLACKMAN_hARRIS, #wintype
        	0, #fc
        	samp_rate, #bw
        	"QT GUI Plot", #name
        	True, #plotfreq
        	True, #plotwaterfall
        	True, #plottime
        	True, #plotconst
        )
        self.qtgui_sink_x_0.set_update_time(1.0/10)
        self._qtgui_sink_x_0_win = sip.wrapinstance(self.qtgui_sink_x_0.pyqwidget(), Qt.QWidget)
        self.top_layout.addWidget(self._qtgui_sink_x_0_win)
        
        
        self.gr_udp_source_0 = gr.udp_source(gr.sizeof_gr_complex*1, "127.0.0.1", 12345, 1472, True, True)

        ##################################################
        # Connections
        ##################################################

        self.connect((self.gr_udp_source_0, 0), (self.qtgui_sink_x_0, 0))
Beispiel #11
0
    def __init__(self, twisted_con, tcp_addr, tcp_port, app_center_freq,
                 app_samp_rate, sim_bw, sim_center_freq):
        gr.hier_block2.__init__(self, "tw2gr_c",
                                gr.io_signature(0, 0, 0),
                                gr.io_signature(1, 1, gr.sizeof_gr_complex))
        self.tw2gr = tw2gr_cc(twisted_con)
#        self.tcp_source = tcp_source(itemsize=gr.sizeof_gr_complex,
#                                     addr=tcp_addr,
#                                     port=tcp_port,
#                                     server=True)
        self.tcp_source = gr.udp_source(itemsize=gr.sizeof_gr_complex,
                                        host=str(tcp_addr),
                                        port=tcp_port,
                                        payload_size=1472,
                                        eof=False,
                                        wait=True)

        print "Connecting tw2gr..."
        self.connect(self.tcp_source, self.tw2gr, self)
	def __init__(self):
		grc_wxgui.top_block_gui.__init__(self, title="Top Block")

		##################################################
		# Variables
		##################################################
		self.samp_rate = samp_rate = 32000

		##################################################
		# Blocks
		##################################################
		self.gr_udp_source_0 = gr.udp_source(gr.sizeof_float*1, "192.168.2.200", 9997, 18*50, False, True)
		self.gr_file_sink_0_1 = gr.file_sink(gr.sizeof_float*1, "testme.bin")
		self.gr_file_sink_0_1.set_unbuffered(True)
		self.fpgnu_fpdata_sink_0 = fpgnu_swig.fpdata_sink()

		##################################################
		# Connections
		##################################################
		self.connect((self.fpgnu_fpdata_sink_0, 0), (self.gr_file_sink_0_1, 0))
		self.connect((self.gr_udp_source_0, 0), (self.fpgnu_fpdata_sink_0, 0))
    def __init__(self, src, port, pkt_size):
        gr.top_block.__init__(self, "vector_sink")

        udp = gr.udp_source(gr.sizeof_float, src, port, pkt_size)
        sink = gr.file_sink(gr.sizeof_float, "received.dat")
        self.connect(udp, sink)
Beispiel #14
0
 def _set_source(self):
     options = self.options
     self.usrp = gr.udp_source(gr.sizeof_gr_complex, "localhost", 63223)
     return self.usrp
Beispiel #15
0
    def __init__(self, frame, panel, vbox, argv):
        MAX_CHANNELS = 7
        stdgui2.std_top_block.__init__(self, frame, panel, vbox, argv)

        parser = OptionParser(option_class=eng_option)
        parser.add_option("-T",
                          "--tx-subdev-spec",
                          type="subdev",
                          default=None,
                          help="select USRP Tx side A or B")
        parser.add_option("-e",
                          "--enable-fft",
                          action="store_true",
                          default=False,
                          help="enable spectrum plot (and use more CPU)")
        parser.add_option("-f",
                          "--freq",
                          type="eng_float",
                          default=None,
                          help="set Tx frequency to FREQ [required]",
                          metavar="FREQ")
        parser.add_option("-i",
                          "--file-input",
                          action="store_true",
                          default=False,
                          help="input from baseband-0.dat, baseband-1.dat ...")
        parser.add_option("-g",
                          "--audio-gain",
                          type="eng_float",
                          default=1.0,
                          help="input audio gain multiplier")
        parser.add_option("-n",
                          "--nchannels",
                          type="int",
                          default=2,
                          help="number of Tx channels [1,4]")
        parser.add_option("-a",
                          "--udp-addr",
                          type="string",
                          default="127.0.0.1",
                          help="UDP host IP address")
        parser.add_option("-p",
                          "--udp-port",
                          type="int",
                          default=0,
                          help="UDP port number")
        parser.add_option("-r",
                          "--repeat",
                          action="store_true",
                          default=False,
                          help="continuously replay input file")
        parser.add_option("-S",
                          "--stretch",
                          type="int",
                          default=0,
                          help="elastic buffer trigger value")
        parser.add_option("-v",
                          "--verbose",
                          action="store_true",
                          default=False,
                          help="print out stats")
        parser.add_option(
            "-I",
            "--audio-input",
            type="string",
            default="",
            help="pcm input device name.  E.g., hw:0,0 or /dev/dsp")
        (options, args) = parser.parse_args()

        if len(args) != 0:
            parser.print_help()
            sys.exit(1)

        if options.nchannels < 1 or options.nchannels > MAX_CHANNELS:
            sys.stderr.write(
                "op25_tx: nchannels out of range.  Must be in [1,%d]\n" %
                MAX_CHANNELS)
            sys.exit(1)

        if options.freq is None:
            sys.stderr.write("op25_tx: must specify frequency with -f FREQ\n")
            parser.print_help()
            sys.exit(1)

        # ----------------------------------------------------------------
        # Set up constants and parameters

        self.u = usrp.sink_c()  # the USRP sink (consumes samples)

        self.dac_rate = self.u.dac_rate()  # 128 MS/s
        self.usrp_interp = 400
        self.u.set_interp_rate(self.usrp_interp)
        self.usrp_rate = self.dac_rate / self.usrp_interp  # 320 kS/s
        self.sw_interp = 10
        self.audio_rate = self.usrp_rate / self.sw_interp  # 32 kS/s

        # determine the daughterboard subdevice we're using
        if options.tx_subdev_spec is None:
            options.tx_subdev_spec = usrp.pick_tx_subdevice(self.u)

        m = usrp.determine_tx_mux_value(self.u, options.tx_subdev_spec)
        #print "mux = %#04x" % (m,)
        self.u.set_mux(m)
        self.subdev = usrp.selected_subdev(self.u, options.tx_subdev_spec)
        print "Using TX d'board %s" % (self.subdev.side_and_name(), )

        self.subdev.set_gain(self.subdev.gain_range()[0])  # set min Tx gain
        if not self.set_freq(options.freq):
            freq_range = self.subdev.freq_range()
            print "Failed to set frequency to %s.  Daughterboard supports %s to %s" % (
                eng_notation.num_to_str(
                    options.freq), eng_notation.num_to_str(
                        freq_range[0]), eng_notation.num_to_str(freq_range[1]))
            raise SystemExit
        self.subdev.set_enable(True)  # enable transmitter

        # instantiate vocoders
        self.vocoders = []
        if options.file_input:
            for i in range(options.nchannels):
                t = gr.file_source(gr.sizeof_char, "baseband-%d.dat" % i,
                                   options.repeat)
                self.vocoders.append(t)

        elif options.udp_port > 0:
            self.udp_sources = []
            for i in range(options.nchannels):
                t = gr.udp_source(1, options.udp_addr, options.udp_port + i,
                                  216)
                self.udp_sources.append(t)
                arity = 2
                t = gr.packed_to_unpacked_bb(arity, gr.GR_MSB_FIRST)
                self.vocoders.append(t)
                self.connect(self.udp_sources[i], self.vocoders[i])

        else:
            self.audio_amps = []
            self.converters = []
            input_audio_rate = 8000
            self.audio_input = audio.source(input_audio_rate,
                                            options.audio_input)
            for i in range(options.nchannels):
                t = gr.multiply_const_ff(32767 * options.audio_gain)
                self.audio_amps.append(t)
                t = gr.float_to_short()
                self.converters.append(t)
                t = repeater.vocoder(
                    True,  # 0=Decode,True=Encode
                    options.verbose,  # Verbose flag
                    options.stretch,  # flex amount
                    "",  # udp ip address
                    0,  # udp port
                    False)  # dump raw u vectors
                self.vocoders.append(t)
                self.connect((self.audio_input, i), self.audio_amps[i],
                             self.converters[i], self.vocoders[i])

        sum = gr.add_cc()

        # Instantiate N NBFM channels
        step = 25e3
        offset = (0 * step, 1 * step, -1 * step, 2 * step, -2 * step, 3 * step,
                  -3 * step)
        for i in range(options.nchannels):
            t = pipeline(self.vocoders[i], offset[i], self.audio_rate,
                         self.usrp_rate)
            self.connect(t, (sum, i))

        gain = gr.multiply_const_cc(4000.0 / options.nchannels)

        # connect it all
        self.connect(sum, gain)
        self.connect(gain, self.u)

        # plot an FFT to verify we are sending what we want
        if options.enable_fft:
            post_mod = fftsink2.fft_sink_c(panel,
                                           title="Post Modulation",
                                           fft_size=512,
                                           sample_rate=self.usrp_rate,
                                           y_per_div=20,
                                           ref_level=40)
            self.connect(sum, post_mod)
            vbox.Add(post_mod.win, 1, wx.EXPAND)
Beispiel #16
0
    def __init__(self, options, args, queue):
        gr.top_block.__init__(self)

        self.options = options
        self.args = args
        self.rate = int(options.rate)
        
        if options.filename is None and options.udp is None and not options.rtlsdr:
          #UHD source by default
          from gnuradio import uhd
          self.u = uhd.single_usrp_source(options.args, uhd.io_type_t.COMPLEX_FLOAT32, 1)
          time_spec = uhd.time_spec(0.0)
          self.u.set_time_now(time_spec)
        
          #if(options.rx_subdev_spec is None):
          #  options.rx_subdev_spec = ""
          #self.u.set_subdev_spec(options.rx_subdev_spec)
          if not options.antenna is None:
            self.u.set_antenna(options.antenna)
        
          self.u.set_samp_rate(rate)
          self.rate = int(self.u.get_samp_rate()) #retrieve actual
        
          if options.gain is None: #set to halfway
            g = self.u.get_gain_range()
            options.gain = (g.start()+g.stop()) / 2.0
        
          if not(self.tune(options.freq)):
            print "Failed to set initial frequency"
        
          print "Setting gain to %i" % options.gain
          self.u.set_gain(options.gain)
          print "Gain is %i" % self.u.get_gain()
          
        elif options.rtlsdr: #RTLSDR dongle
            import osmosdr
            self.u = osmosdr.source_c(options.args)
            self.u.set_sample_rate(2.4e6) #fixed for RTL dongles
            if not self.u.set_center_freq(options.centerfreq - options.error):
                print "Failed to set initial frequency"
        
            self.u.set_gain_mode(0) #manual gain mode
            if options.gain is None:
                options.gain = 25#34
                
            self.u.set_gain(options.gain)
            print "Gain is %i" % self.u.get_gain()
        
            use_resampler = True
            self.rate=2.4e6
                    
        else:
          if options.filename is not None:
            self.u = gr.file_source(gr.sizeof_gr_complex, options.filename)
          elif options.udp is not None:
            self.u = gr.udp_source(gr.sizeof_gr_complex, "localhost", options.udp)
          else:
            raise Exception("No valid source selected")
        
        
        print "Samples per second is %i" % self.rate
        
        self._syms_per_sec = 3600;
        
        options.audiorate = 11025
        options.rate = self.rate
        
        options.samples_per_second = self.rate #yeah i know it's on the list
        options.syms_per_sec = self._syms_per_sec
        options.gain_mu = 0.01
        options.mu=0.5
        options.omega_relative_limit = 0.3
        options.syms_per_sec = self._syms_per_sec
        options.offset = options.centerfreq - options.freq
        print "Control channel offset: %f" % options.offset
        
        self.demod = fsk_demod(options)
        self.start_correlator = gr.correlate_access_code_tag_bb("10101100",0,"smartnet_preamble") #should mark start of packet #digital.
        #self.start_correlator = digital.correlate_access_code_bb("10101100",0) #should mark start of packet #digital.
#        self.smartnet_sync = smartnet.sync()
        self.smartnet_deinterleave = smartnet.deinterleave()
#        self.smartnet_parity = smartnet.parity()
        self.smartnet_crc = smartnet.crc(queue)
#        self.smartnet_packetize = smartnet.packetize()
#        self.parse = smartnet.parse(queue) #packet-based. this simply posts lightly-formatted messages to the queue.
        
        self.connect(self.u, self.demod)
                                                        #self.smartnet_sync,        self.smartnet_parity,
        self.connect(self.demod, self.start_correlator,  self.smartnet_deinterleave,  self.smartnet_crc)#, self.smartnet_packetize, self.parse)
Beispiel #17
0
 def _set_source(self):
     options = self.options
     self.usrp = gr.udp_source(gr.sizeof_gr_complex, "localhost", 63223)
     return self.usrp
Beispiel #18
0
 def __init__(self, host, port, pkt_size, sample_rate, eof, wait):
     gr.top_block.__init__(self, "dial_tone_sink")
     udp = gr.udp_source(gr.sizeof_float, host, port, pkt_size,
                         eof=eof, wait=wait)
     sink = audio.sink(sample_rate)
     self.connect(udp, sink)
Beispiel #19
0
    def __init__(self, frame, panel, vbox, argv):
        MAX_CHANNELS = 7
        stdgui2.std_top_block.__init__ (self, frame, panel, vbox, argv)

        parser = OptionParser (option_class=eng_option)
        parser.add_option("-T", "--tx-subdev-spec", type="subdev", default=None,
                          help="select USRP Tx side A or B")
        parser.add_option("-e","--enable-fft", action="store_true", default=False,
                          help="enable spectrum plot (and use more CPU)")
        parser.add_option("-f", "--freq", type="eng_float", default=None,
                           help="set Tx frequency to FREQ [required]", metavar="FREQ")
        parser.add_option("-i","--file-input", action="store_true", default=False,
                          help="input from baseband-0.dat, baseband-1.dat ...")
        parser.add_option("-g", "--audio-gain", type="eng_float", default=1.0,
                           help="input audio gain multiplier")
        parser.add_option("-n", "--nchannels", type="int", default=1,
                           help="number of Tx channels [1,4]")
        parser.add_option("-a", "--udp-addr", type="string", default="127.0.0.1",
                           help="UDP host IP address")
        parser.add_option("--args", type="string", default="",
                           help="device args")
        parser.add_option("--gains", type="string", default="",
                           help="gains")
        parser.add_option("-p", "--udp-port", type="int", default=0,
                           help="UDP port number")
        parser.add_option("-r","--repeat", action="store_true", default=False,
                          help="continuously replay input file")
        parser.add_option("-S", "--stretch", type="int", default=0,
                           help="elastic buffer trigger value")
        parser.add_option("-v","--verbose", action="store_true", default=False,
                          help="print out stats")
        parser.add_option("-I", "--audio-input", type="string", default="", help="pcm input device name.  E.g., hw:0,0 or /dev/dsp")
        (options, args) = parser.parse_args ()

        if len(args) != 0:
            parser.print_help()
            sys.exit(1)

        if options.nchannels < 1 or options.nchannels > MAX_CHANNELS:
            sys.stderr.write ("op25_tx: nchannels out of range.  Must be in [1,%d]\n" % MAX_CHANNELS)
            sys.exit(1)
        
        if options.freq is None:
            sys.stderr.write("op25_tx: must specify frequency with -f FREQ\n")
            parser.print_help()
            sys.exit(1)

        # ----------------------------------------------------------------
        # Set up constants and parameters

        self.u = osmosdr.sink (options.args)       # the USRP sink (consumes samples)
        gain_names = self.u.get_gain_names()
        for name in gain_names:
            gain_range = self.u.get_gain_range(name)
            print "gain: name: %s range: start %d stop %d step %d" % (name, gain_range[0].start(), gain_range[0].stop(), gain_range[0].step())
        if options.gains:
            for tuple in options.gains.split(","):
                name, gain = tuple.split(":")
                gain = int(gain)
                print "setting gain %s to %d" % (name, gain)
                self.u.set_gain(gain, name)

        self.usrp_rate = 320000
        print 'setting sample rate'
        self.u.set_sample_rate(self.usrp_rate)
        self.u.set_center_freq(int(options.freq))
        #self.u.set_bandwidth(self.usrp_rate)

        #self.u = blocks.file_sink(gr.sizeof_gr_complex, 'usrp-samp.dat')

        #self.dac_rate = self.u.dac_rate()                    # 128 MS/s
        #self.usrp_interp = 400
        #self.u.set_interp_rate(self.usrp_interp)
        #self.usrp_rate = self.dac_rate / self.usrp_interp    # 320 kS/s
        #self.sw_interp = 10
        #self.audio_rate = self.usrp_rate / self.sw_interp    # 32 kS/s
        self.audio_rate = 32000

#       if not self.set_freq(options.freq):
#           freq_range = self.subdev.freq_range()
#           print "Failed to set frequency to %s.  Daughterboard supports %s to %s" % (
#               eng_notation.num_to_str(options.freq),
#               eng_notation.num_to_str(freq_range[0]),
#               eng_notation.num_to_str(freq_range[1]))
#           raise SystemExit
#       self.subdev.set_enable(True)                         # enable transmitter

        # instantiate vocoders
        self.vocoders   = []
        if options.file_input:
            i = 0
            t = blocks.file_source(gr.sizeof_char, "baseband-%d.dat" % i, options.repeat)
            self.vocoders.append(t)

        elif options.udp_port > 0:
          self.udp_sources   = []
          for i in range (options.nchannels):
            t = gr.udp_source(1, options.udp_addr, options.udp_port + i, 216)
            self.udp_sources.append(t)
            arity = 2
            t = gr.packed_to_unpacked_bb(arity, gr.GR_MSB_FIRST)
            self.vocoders.append(t)
            self.connect(self.udp_sources[i], self.vocoders[i])

        if 1: # else:
          input_audio_rate = 8000
          #self.audio_input = audio.source(input_audio_rate, options.audio_input)
          af = 1333
          audio_input = analog.sig_source_s( input_audio_rate, analog.GR_SIN_WAVE, af, 15000)
          t = op25_repeater.vocoder(True,		# 0=Decode,True=Encode
                                  options.verbose,	# Verbose flag
                                  options.stretch,	# flex amount
                                  "",			# udp ip address
                                  0,			# udp port
                                  False) 		# dump raw u vectors
          self.connect(audio_input, t)
          self.vocoders.append(t)

        sum = blocks.add_cc ()

        # Instantiate N NBFM channels
        step = 100e3
        offset = (0 * step, -1 * step, +1 * step, 2 * step, -2 * step, 3 * step, -3 * step)
        for i in range (options.nchannels):
            t = pipeline(self.vocoders[i], offset[i],
                         self.audio_rate, self.usrp_rate)
            self.connect(t, (sum, i))

        t = file_pipeline(offset[2], self.usrp_rate, '2013-320k-filt.dat')
        self.connect(t, (sum, options.nchannels))

        gain = blocks.multiply_const_cc (0.75 / (options.nchannels+1))

        # connect it all
        self.connect (sum, gain)
        self.connect (gain, self.u)

        # plot an FFT to verify we are sending what we want
        if options.enable_fft:
            post_mod = fftsink2.fft_sink_c(panel, title="Post Modulation",
                                           fft_size=512, sample_rate=self.usrp_rate,
                                           y_per_div=20, ref_level=40)
            self.connect (sum, post_mod)
            vbox.Add (post_mod.win, 1, wx.EXPAND)
Beispiel #20
0
			self._created = True
			#print "Created remote device: %s" % (self._name)
			
			#self._send("HEADER", "OFF")	# Enhanced udp_source
			
			if sample_rate is not None:
				self._send_and_wait_for_ok("RATE", sample_rate)
			else:
				#sample_rate = self.adc_freq() / decim_rate
				if self.set_decim_rate(decim_rate) == False:
					raise Exception, "Invalid decimation: %s (sample rate: %s)" % (decim_rate, sample_rate)
		
		if self.udp_source is None:
			assert self.vec2stream is None and self.ishort2complex is None
			udp_interface = "0.0.0.0"	# MAGIC
			self.udp_source = gr.udp_source(gr.sizeof_short * 2, udp_interface, udp_port, self._packet_size, True, True, True)
			#print "--> UDP Source listening on port:", udp_port, "interface:", udp_interface, "MTU:", self._packet_size
			self.vec2stream = gr.vector_to_stream(gr.sizeof_short * 1, 2)
			self.ishort2complex = gr.interleaved_short_to_complex()
		
			self.connect(self.udp_source, self.vec2stream, self.ishort2complex, self)
		else:
			assert self.vec2stream is not None and self.ishort2complex is not None
		
		if self._listen_only == False:
			if self._last_antenna is not None:
				self.select_rx_antenna(self._last_antenna)
			if self._last_freq is not None:
				self.set_freq(self._last_freq)
			if self._last_gain is not None:
				self.set_gain(self._last_gain)
Beispiel #21
0
    def __init__(self, frame, panel, vbox, argv):
        MAX_CHANNELS = 7
        stdgui2.std_top_block.__init__ (self, frame, panel, vbox, argv)

        parser = OptionParser (option_class=eng_option)
        parser.add_option("-T", "--tx-subdev-spec", type="subdev", default=None,
                          help="select USRP Tx side A or B")
        parser.add_option("-e","--enable-fft", action="store_true", default=False,
                          help="enable spectrum plot (and use more CPU)")
        parser.add_option("-f", "--freq", type="eng_float", default=None,
                           help="set Tx frequency to FREQ [required]", metavar="FREQ")
        parser.add_option("-i","--file-input", action="store_true", default=False,
                          help="input from baseband-0.dat, baseband-1.dat ...")
        parser.add_option("-g", "--audio-gain", type="eng_float", default=1.0,
                           help="input audio gain multiplier")
        parser.add_option("-n", "--nchannels", type="int", default=2,
                           help="number of Tx channels [1,4]")
        parser.add_option("-a", "--udp-addr", type="string", default="127.0.0.1",
                           help="UDP host IP address")
        parser.add_option("-p", "--udp-port", type="int", default=0,
                           help="UDP port number")
        parser.add_option("-r","--repeat", action="store_true", default=False,
                          help="continuously replay input file")
        parser.add_option("-S", "--stretch", type="int", default=0,
                           help="elastic buffer trigger value")
        parser.add_option("-v","--verbose", action="store_true", default=False,
                          help="print out stats")
        parser.add_option("-I", "--audio-input", type="string", default="", help="pcm input device name.  E.g., hw:0,0 or /dev/dsp")
        (options, args) = parser.parse_args ()

        if len(args) != 0:
            parser.print_help()
            sys.exit(1)

        if options.nchannels < 1 or options.nchannels > MAX_CHANNELS:
            sys.stderr.write ("op25_tx: nchannels out of range.  Must be in [1,%d]\n" % MAX_CHANNELS)
            sys.exit(1)
        
        if options.freq is None:
            sys.stderr.write("op25_tx: must specify frequency with -f FREQ\n")
            parser.print_help()
            sys.exit(1)

        # ----------------------------------------------------------------
        # Set up constants and parameters

        self.u = usrp.sink_c ()       # the USRP sink (consumes samples)

        self.dac_rate = self.u.dac_rate()                    # 128 MS/s
        self.usrp_interp = 400
        self.u.set_interp_rate(self.usrp_interp)
        self.usrp_rate = self.dac_rate / self.usrp_interp    # 320 kS/s
        self.sw_interp = 10
        self.audio_rate = self.usrp_rate / self.sw_interp    # 32 kS/s

        # determine the daughterboard subdevice we're using
        if options.tx_subdev_spec is None:
            options.tx_subdev_spec = usrp.pick_tx_subdevice(self.u)

        m = usrp.determine_tx_mux_value(self.u, options.tx_subdev_spec)
        #print "mux = %#04x" % (m,)
        self.u.set_mux(m)
        self.subdev = usrp.selected_subdev(self.u, options.tx_subdev_spec)
        print "Using TX d'board %s" % (self.subdev.side_and_name(),)

        self.subdev.set_gain(self.subdev.gain_range()[0])    # set min Tx gain
        if not self.set_freq(options.freq):
            freq_range = self.subdev.freq_range()
            print "Failed to set frequency to %s.  Daughterboard supports %s to %s" % (
                eng_notation.num_to_str(options.freq),
                eng_notation.num_to_str(freq_range[0]),
                eng_notation.num_to_str(freq_range[1]))
            raise SystemExit
        self.subdev.set_enable(True)                         # enable transmitter

        # instantiate vocoders
        self.vocoders   = []
        if options.file_input:
          for i in range (options.nchannels):
            t = gr.file_source(gr.sizeof_char, "baseband-%d.dat" % i, options.repeat)
            self.vocoders.append(t)

        elif options.udp_port > 0:
          self.udp_sources   = []
          for i in range (options.nchannels):
            t = gr.udp_source(1, options.udp_addr, options.udp_port + i, 216)
            self.udp_sources.append(t)
            arity = 2
            t = gr.packed_to_unpacked_bb(arity, gr.GR_MSB_FIRST)
            self.vocoders.append(t)
            self.connect(self.udp_sources[i], self.vocoders[i])

        else:
          self.audio_amps = []
          self.converters = []
          input_audio_rate = 8000
          self.audio_input = audio.source(input_audio_rate, options.audio_input)
          for i in range (options.nchannels):
            t = gr.multiply_const_ff(32767 * options.audio_gain)
            self.audio_amps.append(t)
            t = gr.float_to_short()
            self.converters.append(t)
            t = repeater.vocoder(True,			# 0=Decode,True=Encode
                                  options.verbose,	# Verbose flag
                                  options.stretch,	# flex amount
                                  "",			# udp ip address
                                  0,			# udp port
                                  False) 		# dump raw u vectors
            self.vocoders.append(t)
            self.connect((self.audio_input, i), self.audio_amps[i], self.converters[i], self.vocoders[i])

        sum = gr.add_cc ()

        # Instantiate N NBFM channels
        step = 25e3
        offset = (0 * step, 1 * step, -1 * step, 2 * step, -2 * step, 3 * step, -3 * step)
        for i in range (options.nchannels):
            t = pipeline(self.vocoders[i], offset[i],
                         self.audio_rate, self.usrp_rate)
            self.connect(t, (sum, i))

        gain = gr.multiply_const_cc (4000.0 / options.nchannels)

        # connect it all
        self.connect (sum, gain)
        self.connect (gain, self.u)

        # plot an FFT to verify we are sending what we want
        if options.enable_fft:
            post_mod = fftsink2.fft_sink_c(panel, title="Post Modulation",
                                           fft_size=512, sample_rate=self.usrp_rate,
                                           y_per_div=20, ref_level=40)
            self.connect (sum, post_mod)
            vbox.Add (post_mod.win, 1, wx.EXPAND)
Beispiel #22
0
  def __init__(self, options, args, queue):
    gr.top_block.__init__(self)

    self.options = options
    self.args = args
    rate = int(options.rate)
    use_resampler = False

    if options.filename is None and options.udp is None and not options.rtlsdr:
      #UHD source by default
      from gnuradio import uhd
      self.u = uhd.single_usrp_source("", uhd.io_type_t.COMPLEX_FLOAT32, 1)
      time_spec = uhd.time_spec(0.0)
      self.u.set_time_now(time_spec)

      #if(options.rx_subdev_spec is None):
      #  options.rx_subdev_spec = ""
      #self.u.set_subdev_spec(options.rx_subdev_spec)
      if not options.antenna is None:
        self.u.set_antenna(options.antenna)

      self.u.set_samp_rate(rate)
      rate = int(self.u.get_samp_rate()) #retrieve actual

      if options.gain is None: #set to halfway
        g = self.u.get_gain_range()
        options.gain = (g.start()+g.stop()) / 2.0

      if not(self.tune(options.freq)):
        print "Failed to set initial frequency"

      print "Setting gain to %i" % options.gain
      self.u.set_gain(options.gain)
      print "Gain is %i" % self.u.get_gain()
      
    elif options.rtlsdr: #RTLSDR dongle
        import osmosdr
        self.u = osmosdr.source_c()
        self.u.set_sample_rate(2.4e6) #fixed for RTL dongles
        if not self.u.set_center_freq(options.freq):
            print "Failed to set initial frequency"

        self.u.set_gain_mode(0) #manual gain mode
        if options.gain is None:
            options.gain = 49
            
        self.u.set_gain(options.gain)
        print "Gain is %i" % self.u.get_gain()

        use_resampler = True
                
    else:
      if options.filename is not None:
        self.u = gr.file_source(gr.sizeof_gr_complex, options.filename)
      elif options.udp is not None:
        self.u = gr.udp_source(gr.sizeof_gr_complex, "localhost", options.udp)
      else:
        raise Exception("No valid source selected")
        

    print "Rate is %i" % (rate,)

    pass_all = 0
    if options.output_all :
      pass_all = 1

    self.demod = gr.complex_to_mag()
    self.avg = gr.moving_average_ff(100, 1.0/100, 400)
    
    self.preamble = air_modes.modes_preamble(rate, options.threshold)
    #self.framer = air_modes.modes_framer(rate)
    self.slicer = air_modes.modes_slicer(rate, queue)

    if use_resampler:
        self.lpfiltcoeffs = gr.firdes.low_pass(1, 5*2.4e6, 1.2e6, 300e3)
        self.resample = blks2.rational_resampler_ccf(interpolation=5, decimation=3, taps=self.lpfiltcoeffs)
        self.connect(self.u, self.resample, self.demod)
    else:
        self.connect(self.u, self.demod)

    self.connect(self.demod, self.avg)
    self.connect(self.demod, (self.preamble, 0))
    self.connect(self.avg, (self.preamble, 1))
    self.connect((self.preamble, 0), (self.slicer, 0))
Beispiel #23
0
    def _setup_source(self, options):
        if options.source == "uhd":
            #UHD source by default
            from gnuradio import uhd
            self._u = uhd.single_usrp_source(options.args,
                                             uhd.io_type_t.COMPLEX_FLOAT32, 1)

            if (options.subdev):
                self._u.set_subdev_spec(options.subdev, 0)

            if not self._u.set_center_freq(options.freq):
                print "Failed to set initial frequency"

            #check for GPSDO
            #if you have a GPSDO, UHD will automatically set the timestamp to UTC time
            #as well as automatically set the clock to lock to GPSDO.
            if self._u.get_time_source(0) != 'gpsdo':
                self._u.set_time_now(uhd.time_spec(0.0))

            if options.antenna is not None:
                self._u.set_antenna(options.antenna)

            self._u.set_samp_rate(options.rate)
            options.rate = int(self._u.get_samp_rate())  #retrieve actual

            if options.gain is None:  #set to halfway
                g = self._u.get_gain_range()
                options.gain = (g.start() + g.stop()) / 2.0

            print "Setting gain to %i" % options.gain
            self._u.set_gain(options.gain)
            print "Gain is %i" % self._u.get_gain()

        #TODO: detect if you're using an RTLSDR or Jawbreaker
        #and set up accordingly.
        elif options.source == "osmocom":  #RTLSDR dongle or HackRF Jawbreaker
            import osmosdr
            self._u = osmosdr.source(options.args)
            #        self._u.set_sample_rate(3.2e6) #fixed for RTL dongles
            self._u.set_sample_rate(options.rate)
            if not self._u.set_center_freq(options.freq):
                print "Failed to set initial frequency"

#        self._u.set_gain_mode(0) #manual gain mode
            if options.gain is None:
                options.gain = 34
            self._u.set_gain(options.gain)
            print "Gain is %i" % self._u.get_gain()

            #Note: this should only come into play if using an RTLSDR.


#        lpfiltcoeffs = gr.firdes.low_pass(1, 5*3.2e6, 1.6e6, 300e3)
#        self._resample = filter.rational_resampler_ccf(interpolation=5, decimation=4, taps=lpfiltcoeffs)

        else:
            #semantically detect whether it's ip.ip.ip.ip:port or filename
            if ':' in options.source:
                try:
                    ip, port = re.search("(.*)\:(\d{1,5})",
                                         options.source).groups()
                except:
                    raise Exception(
                        "Please input UDP source e.g. 192.168.10.1:12345")
                self._u = gr.udp_source(gr.sizeof_gr_complex, ip, int(port))
                print "Using UDP source %s:%s" % (ip, port)
            else:
                self._u = blocks.file_source(gr.sizeof_gr_complex,
                                             options.source)
                print "Using file source %s" % options.source

        print "Rate is %i" % (options.rate, )
Beispiel #24
0
    def __init__(self, frame, panel, vbox, argv):
        MAX_CHANNELS = 7
        stdgui2.std_top_block.__init__ (self, frame, panel, vbox, argv)

        parser = OptionParser (option_class=eng_option)
        parser.add_option("-T", "--tx-subdev-spec", type="subdev", default=None,
                          help="select USRP Tx side A or B")
        parser.add_option("-e","--enable-fft", action="store_true", default=False,
                          help="enable spectrum plot (and use more CPU)")
        parser.add_option("-f", "--freq", type="eng_float", default=None,
                           help="set Tx frequency to FREQ [required]", metavar="FREQ")
        parser.add_option("-i","--file-input", action="store_true", default=False,
                          help="input from baseband-0.dat, baseband-1.dat ...")
        parser.add_option("-g", "--audio-gain", type="eng_float", default=1.0,
                           help="input audio gain multiplier")
        parser.add_option("-n", "--nchannels", type="int", default=1,
                           help="number of Tx channels [1,4]")
        parser.add_option("-a", "--udp-addr", type="string", default="127.0.0.1",
                           help="UDP host IP address")
        parser.add_option("--args", type="string", default="",
                           help="device args")
        parser.add_option("--gains", type="string", default="",
                           help="gains")
        parser.add_option("-p", "--udp-port", type="int", default=0,
                           help="UDP port number")
        parser.add_option("-r","--repeat", action="store_true", default=False,
                          help="continuously replay input file")
        parser.add_option("-S", "--stretch", type="int", default=0,
                           help="elastic buffer trigger value")
        parser.add_option("-v","--verbose", action="store_true", default=False,
                          help="print out stats")
        parser.add_option("-I", "--audio-input", type="string", default="", help="pcm input device name.  E.g., hw:0,0 or /dev/dsp")
        (options, args) = parser.parse_args ()

        if len(args) != 0:
            parser.print_help()
            sys.exit(1)

        if options.nchannels < 1 or options.nchannels > MAX_CHANNELS:
            sys.stderr.write ("op25_tx: nchannels out of range.  Must be in [1,%d]\n" % MAX_CHANNELS)
            sys.exit(1)
        
        if options.freq is None:
            sys.stderr.write("op25_tx: must specify frequency with -f FREQ\n")
            parser.print_help()
            sys.exit(1)

        # ----------------------------------------------------------------
        # Set up constants and parameters

        self.u = osmosdr.sink (options.args)       # the USRP sink (consumes samples)
        gain_names = self.u.get_gain_names()
        for name in gain_names:
            gain_range = self.u.get_gain_range(name)
            print("gain: name: %s range: start %d stop %d step %d" % (name, gain_range[0].start(), gain_range[0].stop(), gain_range[0].step()))
        if options.gains:
            for tuple in options.gains.split(","):
                name, gain = tuple.split(":")
                gain = int(gain)
                print("setting gain %s to %d" % (name, gain))
                self.u.set_gain(gain, name)

        self.usrp_rate = 320000
        print('setting sample rate')
        self.u.set_sample_rate(self.usrp_rate)
        self.u.set_center_freq(int(options.freq))
        #self.u.set_bandwidth(self.usrp_rate)

        #self.u = blocks.file_sink(gr.sizeof_gr_complex, 'usrp-samp.dat')

        #self.dac_rate = self.u.dac_rate()                    # 128 MS/s
        #self.usrp_interp = 400
        #self.u.set_interp_rate(self.usrp_interp)
        #self.usrp_rate = self.dac_rate / self.usrp_interp    # 320 kS/s
        #self.sw_interp = 10
        #self.audio_rate = self.usrp_rate / self.sw_interp    # 32 kS/s
        self.audio_rate = 32000

#       if not self.set_freq(options.freq):
#           freq_range = self.subdev.freq_range()
#           print "Failed to set frequency to %s.  Daughterboard supports %s to %s" % (
#               eng_notation.num_to_str(options.freq),
#               eng_notation.num_to_str(freq_range[0]),
#               eng_notation.num_to_str(freq_range[1]))
#           raise SystemExit
#       self.subdev.set_enable(True)                         # enable transmitter

        # instantiate vocoders
        self.vocoders   = []
        if options.file_input:
            i = 0
            t = blocks.file_source(gr.sizeof_char, "baseband-%d.dat" % i, options.repeat)
            self.vocoders.append(t)

        elif options.udp_port > 0:
          self.udp_sources   = []
          for i in range (options.nchannels):
            t = gr.udp_source(1, options.udp_addr, options.udp_port + i, 216)
            self.udp_sources.append(t)
            arity = 2
            t = gr.packed_to_unpacked_bb(arity, gr.GR_MSB_FIRST)
            self.vocoders.append(t)
            self.connect(self.udp_sources[i], self.vocoders[i])

        if 1: # else:
          input_audio_rate = 8000
          #self.audio_input = audio.source(input_audio_rate, options.audio_input)
          af = 1333
          audio_input = analog.sig_source_s( input_audio_rate, analog.GR_SIN_WAVE, af, 15000)
          t = op25_repeater.vocoder(True,          # 0=Decode,True=Encode
                                  options.verbose, # Verbose flag
                                  options.stretch, # flex amount
                                  "",              # udp ip address
                                  0,               # udp port
                                  False)           # dump raw u vectors
          self.connect(audio_input, t)
          self.vocoders.append(t)

        sum = blocks.add_cc ()

        # Instantiate N NBFM channels
        step = 100e3
        offset = (0 * step, -1 * step, +1 * step, 2 * step, -2 * step, 3 * step, -3 * step)
        for i in range (options.nchannels):
            t = pipeline(self.vocoders[i], offset[i],
                         self.audio_rate, self.usrp_rate)
            self.connect(t, (sum, i))

        t = file_pipeline(offset[2], self.usrp_rate, '2013-320k-filt.dat')
        self.connect(t, (sum, options.nchannels))

        gain = blocks.multiply_const_cc (0.75 / (options.nchannels+1))

        # connect it all
        self.connect (sum, gain)
        self.connect (gain, self.u)

        # plot an FFT to verify we are sending what we want
        if options.enable_fft:
            post_mod = fftsink2.fft_sink_c(panel, title="Post Modulation",
                                           fft_size=512, sample_rate=self.usrp_rate,
                                           y_per_div=20, ref_level=40)
            self.connect (sum, post_mod)
            vbox.Add (post_mod.win, 1, wx.EXPAND)
Beispiel #25
0
 def __init__(self, host, port, pkt_size, sample_rate, eof, wait):
     gr.top_block.__init__(self, "audio_sink")
     src = gr.udp_source(gr.sizeof_float, host, port, pkt_size,
                         eof=eof, wait=wait)
     dst = audio.sink(sample_rate)
     self.connect(src, dst)
Beispiel #26
0
  def _setup_source(self, options):
    if options.source == "uhd":
      #UHD source by default
      from gnuradio import uhd
      self._u = uhd.single_usrp_source(options.args, uhd.io_type_t.COMPLEX_FLOAT32, 1)

      if(options.subdev):
        self._u.set_subdev_spec(options.subdev, 0)

      if not self._u.set_center_freq(options.freq):
        print "Failed to set initial frequency"

      #check for GPSDO
      #if you have a GPSDO, UHD will automatically set the timestamp to UTC time
      #as well as automatically set the clock to lock to GPSDO.
      if self._u.get_time_source(0) != 'gpsdo':
        self._u.set_time_now(uhd.time_spec(0.0))

      if options.antenna is not None:
        self._u.set_antenna(options.antenna)

      self._u.set_samp_rate(options.rate)
      options.rate = int(self._u.get_samp_rate()) #retrieve actual

      if options.gain is None: #set to halfway
        g = self._u.get_gain_range()
        options.gain = (g.start()+g.stop()) / 2.0

      print "Setting gain to %i" % options.gain
      self._u.set_gain(options.gain)
      print "Gain is %i" % self._u.get_gain()

    #TODO: detect if you're using an RTLSDR or Jawbreaker
    #and set up accordingly.
    elif options.source == "osmocom": #RTLSDR dongle or HackRF Jawbreaker
        import osmosdr
        self._u = osmosdr.source(options.args)
#        self._u.set_sample_rate(3.2e6) #fixed for RTL dongles
        self._u.set_sample_rate(options.rate)
        if not self._u.set_center_freq(options.freq):
            print "Failed to set initial frequency"

#        self._u.set_gain_mode(0) #manual gain mode
        if options.gain is None:
            options.gain = 34
        self._u.set_gain(options.gain)
        print "Gain is %i" % self._u.get_gain()

        #Note: this should only come into play if using an RTLSDR.
#        lpfiltcoeffs = gr.firdes.low_pass(1, 5*3.2e6, 1.6e6, 300e3)
#        self._resample = filter.rational_resampler_ccf(interpolation=5, decimation=4, taps=lpfiltcoeffs)

    else:
      #semantically detect whether it's ip.ip.ip.ip:port or filename
      if ':' in options.source:
        try:
          ip, port = re.search("(.*)\:(\d{1,5})", options.source).groups()
        except:
          raise Exception("Please input UDP source e.g. 192.168.10.1:12345")
        self._u = gr.udp_source(gr.sizeof_gr_complex, ip, int(port))
        print "Using UDP source %s:%s" % (ip, port)
      else:
        self._u = blocks.file_source(gr.sizeof_gr_complex, options.source)
        print "Using file source %s" % options.source

    print "Rate is %i" % (options.rate,)
Beispiel #27
0
	def __init__(self):
		grc_wxgui.top_block_gui.__init__(self, title="RTL-SDR to Pure Data")
		_icon_path = "/usr/share/icons/hicolor/32x32/apps/gnuradio-grc.png"
		self.SetIcon(wx.Icon(_icon_path, wx.BITMAP_TYPE_ANY))

		##################################################
		# Variables
		##################################################
		self.samp_rate = samp_rate = 1920000
		self.cur_freq_fine = cur_freq_fine = 0
		self.cur_freq = cur_freq = 0
		self.channels_coeffs_0 = channels_coeffs_0 = gr.firdes.low_pass(1.0,samp_rate,20000,25000,gr.firdes.WIN_HAMMING)
		self.channels_coeffs = channels_coeffs = gr.firdes.low_pass(1.0,samp_rate,20000,45000,gr.firdes.WIN_HAMMING)

		##################################################
		# Blocks
		##################################################
		self.signal_cur = gr.probe_signal_f()
		self.fine_cur = gr.probe_signal_f()
		self.rtlsdr_source_c_0 = osmosdr.source_c( args="nchan=" + str(1) + " " + "" )
		self.rtlsdr_source_c_0.set_sample_rate(samp_rate)
		self.rtlsdr_source_c_0.set_center_freq(78000000, 0)
		self.rtlsdr_source_c_0.set_freq_corr(0, 0)
		self.rtlsdr_source_c_0.set_gain_mode(0, 0)
		self.rtlsdr_source_c_0.set_gain(10, 0)
		self.rtlsdr_source_c_0.set_if_gain(24, 0)
			
		self.gr_udp_source_0_0 = gr.udp_source(gr.sizeof_float*1, "127.0.0.1", 2001, 4, True, True)
		self.gr_udp_source_0 = gr.udp_source(gr.sizeof_float*1, "127.0.0.1", 2000, 4, True, True)
		self.gr_udp_sink_0_0 = gr.udp_sink(gr.sizeof_float*2048, "127.0.0.1", 2002, 11776, True)
		self.fft_vxx_0 = fft.fft_vcc(2048, True, (window.blackmanharris(1024)), True, 1)
		def _cur_freq_fine_probe():
			while True:
				val = self.fine_cur.level()
				try: self.set_cur_freq_fine(val)
				except AttributeError, e: pass
				time.sleep(1.0/(10))
		_cur_freq_fine_thread = threading.Thread(target=_cur_freq_fine_probe)
		_cur_freq_fine_thread.daemon = True
		_cur_freq_fine_thread.start()
		def _cur_freq_probe():
			while True:
				val = self.signal_cur.level()
				try: self.set_cur_freq(val)
				except AttributeError, e: pass
				time.sleep(1.0/(10))
		_cur_freq_thread = threading.Thread(target=_cur_freq_probe)
		_cur_freq_thread.daemon = True
		_cur_freq_thread.start()
		self.blocks_nlog10_ff_0 = blocks.nlog10_ff(1, 2048, 0)
		self.blocks_complex_to_mag_squared_0 = blocks.complex_to_mag_squared(2048)
		self.blks2_stream_to_vector_decimator_0 = blks2.stream_to_vector_decimator(
			item_size=gr.sizeof_gr_complex,
			sample_rate=samp_rate,
			vec_rate=25,
			vec_len=2048,
		)

		##################################################
		# Connections
		##################################################
		self.connect((self.fft_vxx_0, 0), (self.blocks_complex_to_mag_squared_0, 0))
		self.connect((self.blks2_stream_to_vector_decimator_0, 0), (self.fft_vxx_0, 0))
		self.connect((self.blocks_complex_to_mag_squared_0, 0), (self.blocks_nlog10_ff_0, 0))
		self.connect((self.rtlsdr_source_c_0, 0), (self.blks2_stream_to_vector_decimator_0, 0))
		self.connect((self.gr_udp_source_0_0, 0), (self.fine_cur, 0))
		self.connect((self.gr_udp_source_0, 0), (self.signal_cur, 0))
		self.connect((self.blocks_nlog10_ff_0, 0), (self.gr_udp_sink_0_0, 0))