def __init__(self, sample_rate, center_freq, gain, device_addr=""): gr.top_block.__init__(self) # Make a local QtApp so we can start it from our side self.qapp = QtGui.QApplication(sys.argv) fftsize = 2048 self.src = uhd.single_usrp_source( device_addr="serial=4cfc2b4d", io_type=uhd.io_type_t.COMPLEX_FLOAT32, num_channels=1 ) self.src.set_samp_rate(sample_rate) self.src.set_center_freq(center_freq, 0) self.src.set_gain(gain, 0) self.src.set_time_now(uhd.time_spec_t(0.0)) self.snk = qtgui.sink_c( fftsize, gr.firdes.WIN_BLACKMAN_hARRIS, center_freq, self.src.get_samp_rate(), "Realtime Display" ) cmd = uhd.cmd_t(uhd.stream_cmd_t.STREAM_MODE_NUM_SAMPS_AND_DONE) self.connect(self.src, self.snk) # Tell the sink we want it displayed self.pyobj = sip.wrapinstance(self.snk.pyqwidget(), QtGui.QWidget) self.pyobj.show()
def __init__(self, queue, options, args): #grc_wxgui.top_block_gui.__init__(self, title="Top Block") gr.top_block.__init__(self) ################################################## # Variables ################################################## self.samp_rate = samp_rate = 100e6/512 ################################################## # Blocks ################################################## self.gr_complex_to_mag_squared_0 = gr.complex_to_mag_squared(1) self.gr_keep_one_in_n_0 = gr.keep_one_in_n(gr.sizeof_gr_complex*1, 10) self.keyfob_msg = keyfob.msg(queue, samp_rate/10.0, options.threshold) self.uhd_single_usrp_source_0 = uhd.single_usrp_source( device_addr="", io_type=uhd.io_type_t.COMPLEX_FLOAT32, num_channels=1, ) _clk_cfg = uhd.clock_config_t() _clk_cfg.ref_source = uhd.clock_config_t.REF_SMA _clk_cfg.pps_source = uhd.clock_config_t.PPS_SMA _clk_cfg.pps_polarity = uhd.clock_config_t.PPS_POS #self.uhd_single_usrp_source_0.set_clock_config(_clk_cfg); self.uhd_single_usrp_source_0.set_samp_rate(samp_rate) self.uhd_single_usrp_source_0.set_center_freq(options.freq, 0) self.uhd_single_usrp_source_0.set_gain(40, 0) ################################################## # Connections ################################################## self.connect((self.uhd_single_usrp_source_0, 0), (self.gr_keep_one_in_n_0, 0)) self.connect((self.gr_keep_one_in_n_0, 0), (self.gr_complex_to_mag_squared_0, 0)) self.connect((self.gr_complex_to_mag_squared_0, 0), self.keyfob_msg)
def __init__(self, uhd_address, options): gr.top_block.__init__(self) self.uhd_addr = uhd_address self.freq = options.freq self.samp_rate = options.samp_rate self.gain = options.gain self.threshold = options.threshold self.trigger = options.trigger self.uhd_src = uhd.single_usrp_source( device_addr=self.uhd_addr, io_type=uhd.io_type_t.COMPLEX_FLOAT32, num_channels=1, ) self.uhd_src.set_samp_rate(self.samp_rate) self.uhd_src.set_center_freq(self.freq, 0) self.uhd_src.set_gain(self.gain, 0) taps = firdes.low_pass_2(1, 1, 0.4, 0.1, 60) self.chanfilt = gr.fir_filter_ccc(10, taps) self.tagger = gr.burst_tagger(gr.sizeof_gr_complex) # Dummy signaler to collect a burst on known periods data = 1000*[0,] + 1000*[1,] self.signal = gr.vector_source_s(data, True) # Energy detector to get signal burst ## use squelch to detect energy self.det = gr.simple_squelch_cc(self.threshold, 0.01) ## convert to mag squared (float) self.c2m = gr.complex_to_mag_squared() ## average to debounce self.avg = gr.single_pole_iir_filter_ff(0.01) ## rescale signal for conversion to short self.scale = gr.multiply_const_ff(2**16) ## signal input uses shorts self.f2s = gr.float_to_short() # Use file sink burst tagger to capture bursts self.fsnk = gr.tagged_file_sink(gr.sizeof_gr_complex, self.samp_rate) ################################################## # Connections ################################################## self.connect((self.uhd_src, 0), (self.tagger, 0)) self.connect((self.tagger, 0), (self.fsnk, 0)) if self.trigger: # Connect a dummy signaler to the burst tagger self.connect((self.signal, 0), (self.tagger, 1)) else: # Connect an energy detector signaler to the burst tagger self.connect(self.uhd_src, self.det) self.connect(self.det, self.c2m, self.avg, self.scale, self.f2s) self.connect(self.f2s, (self.tagger, 1))
def __init__(self, uhd_address, options): gr.top_block.__init__(self) self.uhd_addr = uhd_address self.freq = options.freq self.samp_rate = options.samp_rate self.gain = options.gain self.threshold = options.threshold self.trigger = options.trigger self.uhd_src = uhd.single_usrp_source( device_addr=self.uhd_addr, stream_args=uhd.stream_args('fc32')) self.uhd_src.set_samp_rate(self.samp_rate) self.uhd_src.set_center_freq(self.freq, 0) self.uhd_src.set_gain(self.gain, 0) taps = firdes.low_pass_2(1, 1, 0.4, 0.1, 60) self.chanfilt = gr.fir_filter_ccc(10, taps) self.tagger = gr.burst_tagger(gr.sizeof_gr_complex) # Dummy signaler to collect a burst on known periods data = 1000 * [ 0, ] + 1000 * [ 1, ] self.signal = gr.vector_source_s(data, True) # Energy detector to get signal burst ## use squelch to detect energy self.det = gr.simple_squelch_cc(self.threshold, 0.01) ## convert to mag squared (float) self.c2m = gr.complex_to_mag_squared() ## average to debounce self.avg = gr.single_pole_iir_filter_ff(0.01) ## rescale signal for conversion to short self.scale = gr.multiply_const_ff(2**16) ## signal input uses shorts self.f2s = gr.float_to_short() # Use file sink burst tagger to capture bursts self.fsnk = gr.tagged_file_sink(gr.sizeof_gr_complex, self.samp_rate) ################################################## # Connections ################################################## self.connect((self.uhd_src, 0), (self.tagger, 0)) self.connect((self.tagger, 0), (self.fsnk, 0)) if self.trigger: # Connect a dummy signaler to the burst tagger self.connect((self.signal, 0), (self.tagger, 1)) else: # Connect an energy detector signaler to the burst tagger self.connect(self.uhd_src, self.det) self.connect(self.det, self.c2m, self.avg, self.scale, self.f2s) self.connect(self.f2s, (self.tagger, 1))
def __init__(self, sample_rate, center_freq, gain, device_addr=""): gr.top_block.__init__(self) # Make a local QtApp so we can start it from our side self.qapp = QtGui.QApplication(sys.argv) fftsize = 2048 self.src = uhd.single_usrp_source( device_addr="serial=4cfc2b4d", io_type=uhd.io_type_t.COMPLEX_FLOAT32, num_channels=1) self.src.set_samp_rate(sample_rate) self.src.set_center_freq(center_freq, 0) self.src.set_gain(gain, 0) self.src.set_time_now(uhd.time_spec_t(0.0)) self.snk = qtgui.sink_c(fftsize, gr.firdes.WIN_BLACKMAN_hARRIS, center_freq, self.src.get_samp_rate(), "Realtime Display") cmd = uhd.cmd_t(uhd.stream_cmd_t.STREAM_MODE_NUM_SAMPS_AND_DONE) self.connect(self.src, self.snk) # Tell the sink we want it displayed self.pyobj = sip.wrapinstance(self.snk.pyqwidget(), QtGui.QWidget) self.pyobj.show()
def __init__(self, options, args, queue): gr.top_block.__init__(self) self.options = options self.args = args rate = int(options.rate) if options.filename is None: 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(), ) else: self.u = gr.file_source(gr.sizeof_gr_complex, options.filename) 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) #the DBSRX especially tends to be spur-prone; the LPF keeps out the #spur multiple that shows up at 2MHz self.lpfiltcoeffs = gr.firdes.low_pass(1, rate, 1.8e6, 100e3) self.lpfilter = gr.fir_filter_ccf(1, self.lpfiltcoeffs) self.preamble = air.modes_preamble(rate, options.threshold) #self.framer = air.modes_framer(rate) self.slicer = air.modes_slicer(rate, queue) self.connect(self.u, self.lpfilter, 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))
def __init__(self, options, args, queue): gr.top_block.__init__(self) self.options = options self.args = args rate = int(options.rate) if options.filename is None: 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(),) else: self.u = gr.file_source(gr.sizeof_gr_complex, options.filename) 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) #the DBSRX especially tends to be spur-prone; the LPF keeps out the #spur multiple that shows up at 2MHz self.lpfiltcoeffs = gr.firdes.low_pass(1, rate, 1.8e6, 100e3) self.lpfilter = gr.fir_filter_ccf(1, self.lpfiltcoeffs) self.preamble = air.modes_preamble(rate, options.threshold) #self.framer = air.modes_framer(rate) self.slicer = air.modes_slicer(rate, queue) self.connect(self.u, self.lpfilter, 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))
def __init__(self, sample_rate, center_freq): gr.top_block.__init__(self) # Make a local QtApp so we can start it from our side self.qapp = QtGui.QApplication(sys.argv) fftsize = 2048 self.src = uhd.single_usrp_source(io_type = uhd.io_type_t.COMPLEX_FLOAT32, num_channels = 1) self.snk = qtgui.sink_c(fftsize, gr.firdes.WIN_BLACKMAN_hARRIS) self.connect(self.src, self.snk) # Tell the sink we want it displayed self.pyobj = sip.wrapinstance(self.snk.pyqwidget(), QtGui.QWidget) self.pyobj.show()
def __init__(self, fg, src_type, file_samp_type, file_to_open, file_rec_samp_rate, uhd_samp_rate, uhd_gain, center_f, uhd_subdev_spec): gr.hier_block2.__init__(self, "head", gr.io_signature(0, 0, 0), gr.io_signature(1, 1, gr.sizeof_gr_complex)) if (src_type == "File"): try: self.head_src = blocks.file_source(file_samp_type, file_to_open, True) fg.set_samp_rate(file_rec_samp_rate) fg.uhd_src_active = False if fg.cpu_watcher is not None: fg.cpu_watcher.quit() if (file_samp_type == gr.sizeof_float): self.head_bottom = gr.float_to_complex() self.connect((self.head_src, 0), (self.head_bottom, 0)) self.connect((self.head_bottom, 0), (self, 0)) else: self.connect((self.head_src, 0), (self, 0)) except RuntimeError: print "Could not initialize file-source!" self.head_src = None elif (src_type == "UHD"): try: self.head_src = uhd.single_usrp_source( device_addr='', io_type=uhd.io_type_t.COMPLEX_FLOAT32, num_channels=1) self.head_src.set_samp_rate(fg.d_uhd_samp_rate) self.head_src.set_gain(fg.d_uhd_gain, 0) self.head_src.set_center_freq(fg.center_f * 1e6, 0) self.head_src.set_subdev_spec(fg.d_uhd_subdev_spec) fg.set_samp_rate(fg.d_uhd_samp_rate) fg.uhd_src_active = True fg.cpu_watcher.start() if (fg.d_uhd_samp_type == gr.sizeof_float): self.head_bottom = gr.float_to_complex() self.connect((self.head_src, 0), (self.head_bottom, 0)) self.connect((self.head_bottom, 0), (self, 0)) else: self.connect((self.head_src, 0), (self, 0)) except RuntimeError: print "Could not initialize UHD source!" self.head_src = None else: print "Unknown type of source!"
def __init__(self, sample_rate, center_freq): gr.top_block.__init__(self) # Make a local QtApp so we can start it from our side self.qapp = QtGui.QApplication(sys.argv) fftsize = 2048 self.src = uhd.single_usrp_source( io_type=uhd.io_type_t.COMPLEX_FLOAT32, num_channels=1) self.snk = qtgui.sink_c(fftsize, gr.firdes.WIN_BLACKMAN_hARRIS) self.connect(self.src, self.snk) # Tell the sink we want it displayed self.pyobj = sip.wrapinstance(self.snk.pyqwidget(), QtGui.QWidget) self.pyobj.show()
def __init__(self, frame, panel, vbox, argv): stdgui2.std_top_block.__init__ (self, frame, panel, vbox, argv) parser = OptionParser(option_class=eng_option, conflict_handler="resolve") parser.add_option("-r", "--sample-rate", type="eng_float", default=1e6, help="set samplerate to RATE [default=%default]") parser.add_option("-f", "--freq", type="eng_float", default=1.8e9, help="set center frequency to RATE [default=%default]") parser.add_option("-d", "--soft-decimate", type="eng_float", default=1, help="decimate the given samplingrate further by a factor of [default=%default]") (options,values) = parser.parse_args() pspectrum_len = 1024 nsamples = 512 # build our flow graph input_rate = options.sample_rate soft_decimation = int(options.soft_decimate) center_freq = options.freq source = uhd.single_usrp_source(device_addr='type=usrp2',io_type=uhd.io_type_t.COMPLEX_FLOAT32, num_channels=1) source.set_samp_rate(input_rate) source.set_gain(45,0) source.set_center_freq(center_freq,0) item_size = gr.sizeof_gr_complex dec = gr.keep_one_in_n(item_size, soft_decimation) sink1 = spectrum_sink_c (panel, title="ESPRIT Spectrum", pspectrum_len=pspectrum_len, sample_rate=input_rate / soft_decimation, baseband_freq=0, ref_level=0, y_per_div=20, y_divs=10, m = 128, n = 6, nsamples = nsamples, estimator='esprit') vbox.Add (sink1.win, 1, wx.EXPAND) #sink2 = spectrum_sink_c (panel, title="MUSIC Spectrum", pspectrum_len=pspectrum_len, #sample_rate=input_rate / soft_decimation, baseband_freq=0, #ref_level=0, y_per_div=20, y_divs=10, m = 64, n = 2, nsamples = nsamples, #estimator='music') scale = gr.multiply_const_cc(30.0e3) #vbox.Add (sink2.win, 1, wx.EXPAND) self.connect(source,scale,sink1)
def __init__(self, fg, src_type, file_samp_type, file_to_open, file_rec_samp_rate, uhd_samp_rate, uhd_gain, center_f, uhd_subdev_spec): gr.hier_block2.__init__(self, "head", gr.io_signature(0, 0, 0), gr.io_signature(1, 1, gr.sizeof_gr_complex)) if(src_type == "File"): try: self.head_src = gr.file_source(file_samp_type, file_to_open, True) fg.set_samp_rate(file_rec_samp_rate) fg.uhd_src_active = False if fg.cpu_watcher is not None: fg.cpu_watcher.quit() if(file_samp_type == gr.sizeof_float): self.head_bottom = gr.float_to_complex() self.connect((self.head_src, 0), (self.head_bottom, 0)) self.connect((self.head_bottom, 0), (self, 0)) else: self.connect((self.head_src, 0), (self, 0)) except RuntimeError: print "Could not initialize file-source!" self.head_src = None elif(src_type == "UHD"): try: self.head_src = uhd.single_usrp_source(device_addr='', io_type=uhd.io_type_t.COMPLEX_FLOAT32, num_channels=1) self.head_src.set_samp_rate(fg.d_uhd_samp_rate) self.head_src.set_gain(fg.d_uhd_gain, 0) self.head_src.set_center_freq(fg.center_f*1e6 ,0) self.head_src.set_subdev_spec(fg.d_uhd_subdev_spec) fg.set_samp_rate(fg.d_uhd_samp_rate) fg.uhd_src_active = True fg.cpu_watcher.start() if(fg.d_uhd_samp_type == gr.sizeof_float): self.head_bottom = gr.float_to_complex() self.connect((self.head_src, 0), (self.head_bottom, 0)) self.connect((self.head_bottom, 0), (self, 0)) else: self.connect((self.head_src, 0), (self, 0)) except RuntimeError: print "Could not initialize UHD source!" self.head_src = None else: print "Unknown type of source!"
def __init__(self, modulator, demodulator, access_code=None, hint="addr=192.168.10.2"): gr.hier_block2.__init__(self, "Physical Layer", gr.io_signature(0, 0, 0), gr.io_signature(0, 0, 0)) if access_code is "master": self.rx_offset = 8e6 access_code = None elif access_code is "slave": self.rx_offset = -8e6 access_code = None else: self.rx_offset = 0 # create TX/RX self.u_tx = uhd.single_usrp_sink(hint, io_type=uhd.io_type_t.COMPLEX_FLOAT32, num_channels=1) self.u_rx = uhd.single_usrp_source(hint, io_type=uhd.io_type_t.COMPLEX_FLOAT32, num_channels=1) self.access_code = access_code # create packetmods self.pkt_mod = blks2.mod_pkts(modulator, pad_for_usrp=True, access_code=self.access_code) self.pkt_demod = blks2.demod_pkts(demodulator, callback=self.rx_callback, access_code=self.access_code) self.connect(self.u_rx, self.pkt_demod) self.connect(self.pkt_mod, self.u_tx)
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" # LimeSDR Mini insists we set sample rate before setting time self._u.set_samp_rate(options.rate) options.rate = int(self._u.get_samp_rate()) #retrieve actual #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) 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 = blocks.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, )
def __init__(self, freq, subdev_spec, which_USRP, gain, audio_output, debug): gr.hier_block2.__init__(self, "analog_receive_path", gr.io_signature(0, 0, 0), #input signature gr.io_signature(0, 0, 0)) #output signature self.DEBUG = debug self.freq = freq self.rx_gain = gain #Formerly From XML self.fusb_block_size = 2048 self.fusb_nblocks = 8 self.rx_usrp_pga_gain_scaling = 0.5 self.rx_base_band_bw = 5e3 self.rx_freq_deviation = 2.5e3 # acquire USRP via USB 2.0 #self.u = usrp.source_c(fusb_block_size=self.fusb_block_size, # fusb_nblocks=self.fusb_nblocks, # which=which_USRP) self.u = uhd.single_usrp_source( device_addr="", io_type=uhd.io_type_t.COMPLEX_FLOAT32, num_channels=1, ) self.u.get_device # get A/D converter sampling rate #adc_rate = self.u.adc_rate() # 64 MS/s adc_rate = 64e6 # 64 MS/s if self.DEBUG: print " Rx Path ADC rate: %d" %(adc_rate) # setting USRP and GNU Radio decimation rate self.audio_rate = 16e3 self.max_gr_decim_rate = 40 self._usrp_decim = 250 self.gr_rate1 = adc_rate / self._usrp_decim gr_interp = 1 gr_decim = 16 self.gr_rate2 = self.gr_rate1 / gr_decim if self.DEBUG: print " usrp decim: ", self._usrp_decim print " gr rate 1: ", self.gr_rate1 print " gr decim: ", gr_decim print " gr rate 2: ", self.gr_rate2 print " gr interp: ", gr_interp print " audio rate: ", self.audio_rate # ================ Set up flowgraph ================================= # set USRP decimation ratio #self.u.set_decim_rate(self._usrp_decim) self.u.set_samp_rate(self.gr_rate1) self.u.set_antenna("RX2") # set USRP daughterboard subdevice if subdev_spec is None: subdev_spec = usrp.pick_rx_subdevice(self.u) #self.u.set_mux(usrp.determine_rx_mux_value(self.u, subdev_spec)) #self.subdev = usrp.selected_subdev(self.u, subdev_spec) #if self.DEBUG: # print " RX Path use daughterboard: %s" % (self.subdev.side_and_name()) # set USRP RF frequency """ Set the center frequency in Hz. Tuning is a two step process. First we ask the front-end to tune as close to the desired frequency as it can. Then we use the result of that operation and our target_frequency to determine the value for the digital up converter. """ assert(self.freq != None) #r = self.u.tune(0, self.subdev, self.freq) r = self.u.set_center_freq(self.freq, 0) if self.DEBUG: if r: print "----Rx RF frequency set to %f Hz" %(self.freq) else: print "Failed to set Rx frequency to %f Hz" %(self.freq) raise ValueError, eng_notation.num_to_str(self.freq) # set USRP Rx PGA gain #r = self.subdev.gain_range() #_rx_usrp_gain_range = r[1] - r[0] #_rx_usrp_gain = r[0]+_rx_usrp_gain_range * self.rx_usrp_pga_gain_scaling #self.subdev.set_gain(_rx_usrp_gain) #self.u.set_gain(3.25, 0) #if self.DEBUG: # print " USRP Rx PGA Gain Range: min = %g, max = %g, step size = %g" \ # %(r[0], r[1], r[2]) # print " USRP Rx PGA gain set to: %g" %(_rx_usrp_gain) # Do NOT Enable USRP Auto Tx/Rx switching for analog flow graph! #self.subdev.set_enable(False) # Baseband Channel Filter using FM Carson's Rule chan_bw = 2*(self.rx_base_band_bw+self.rx_freq_deviation) #Carson's Rule chan_filt_coeffs_float = optfir.low_pass (1, #gain self.gr_rate1, #sampling rate chan_bw, #passband cutoff chan_bw*1.35, #stopband cutoff 0.1, #passband ripple 60) #stopband attenuation chan_filt_coeffs_fixed = ( 0.000457763671875, 0.000946044921875, 0.00067138671875, 0.001068115234375, 0.00091552734375, 0.0008544921875, 0.000518798828125, 0.0001220703125, -0.000396728515625, -0.0008544921875, -0.00128173828125, -0.00146484375, -0.001434326171875, -0.0010986328125, -0.000518798828125, 0.000274658203125, 0.001129150390625, 0.00189208984375, 0.00238037109375, 0.00250244140625, 0.002166748046875, 0.0013427734375, 0.000152587890625, -0.001220703125, -0.002532958984375, -0.0035400390625, -0.003997802734375, -0.003753662109375, -0.002777099609375, -0.0010986328125, 0.000946044921875, 0.00311279296875, 0.00494384765625, 0.00604248046875, 0.006103515625, 0.005035400390625, 0.00286865234375, -0.0001220703125, -0.00347900390625, -0.006561279296875, -0.008758544921875, -0.00958251953125, -0.008636474609375, -0.005950927734375, -0.001739501953125, 0.00335693359375, 0.00848388671875, 0.0126953125, 0.01507568359375, 0.014862060546875, 0.01171875, 0.00579833984375, -0.002227783203125, -0.01123046875, -0.0196533203125, -0.02587890625, -0.028228759765625, -0.025421142578125, -0.016754150390625, -0.002166748046875, 0.017608642578125, 0.041015625, 0.0660400390625, 0.090240478515625, 0.111083984375, 0.12640380859375, 0.134490966796875, 0.134490966796875, 0.12640380859375, 0.111083984375, 0.090240478515625, 0.0660400390625, 0.041015625, 0.017608642578125, -0.002166748046875, -0.016754150390625, -0.025421142578125, -0.028228759765625, -0.02587890625, -0.0196533203125, -0.01123046875, -0.002227783203125, 0.00579833984375, 0.01171875, 0.014862060546875, 0.01507568359375, 0.0126953125, 0.00848388671875, 0.00335693359375, -0.001739501953125, -0.005950927734375, -0.008636474609375, -0.00958251953125, -0.008758544921875, -0.006561279296875, -0.00347900390625, -0.0001220703125, 0.00286865234375, 0.005035400390625, 0.006103515625, 0.00604248046875, 0.00494384765625, 0.00311279296875, 0.000946044921875, -0.0010986328125, -0.002777099609375, -0.003753662109375, -0.003997802734375, -0.0035400390625, -0.002532958984375, -0.001220703125, 0.000152587890625, 0.0013427734375, 0.002166748046875, 0.00250244140625, 0.00238037109375, 0.00189208984375, 0.001129150390625, 0.000274658203125, -0.000518798828125, -0.0010986328125, -0.001434326171875, -0.00146484375, -0.00128173828125, -0.0008544921875, -0.000396728515625, 0.0001220703125, 0.000518798828125, 0.0008544921875, 0.00091552734375, 0.001068115234375, 0.00067138671875, 0.000946044921875, 0.000457763671875) #r = gr.enable_realtime_scheduling () self.chan_filt = dsp.fir_ccf_fm_demod_decim (chan_filt_coeffs_fixed, 14, gr_decim, 0, 0, 0, 0) print "Tap length of chan FIR: ", len(chan_filt_coeffs_fixed) # Set the software LNA gain on the output of the USRP gain= self.rx_gain self.rx_gain = max(0.0, min(gain, 1e7)) if self.DEBUG: print " Rx Path initial software signal gain: %f (max 1e7)" %(gain) print " Rx Path actual software signal gain : %f (max 1e7)" %(self.rx_gain) #FM Demodulator fm_demod_gain = self.audio_rate / (2*math.pi*self.rx_freq_deviation) self.fm_demod = gr.quadrature_demod_cf (fm_demod_gain) #Compute FIR filter taps for audio filter width_of_transition_band = self.rx_base_band_bw * 0.35 audio_coeffs = gr.firdes.low_pass (1.0, #gain self.gr_rate2, #sampling rate self.rx_base_band_bw, width_of_transition_band, gr.firdes.WIN_HAMMING) self.audio_filter = gr.fir_filter_fff(1, audio_coeffs) passband_cutoff = self.rx_base_band_bw stopband_cutoff = passband_cutoff * 1.35 self.deemph = fm_deemph(self.audio_rate) if self.DEBUG: print "Length Audio FIR ", len(audio_coeffs) # Audio sink audio_sink = audio.sink(int(self.audio_rate),"default") # "", #Audio output pcm device name. E.g., hw:0,0 or surround51 or /dev/dsp # False) # ok_to_block if self.DEBUG: print "Before Connecting Blocks" # Wiring Up #WITH CHANNEL FILTER #self.connect (self.u, self.chan_filt, self.lna, self.fm_demod, self.audio_filter, interpolator, self.deemph, self.volume_control, audio_sink) #self.connect (self.u, self.fm_demod, self.audio_filter, self.deemph, self.volume_control, howto_rx, audio_sink) self.connect (self.u, self.chan_filt, self.audio_filter, self.deemph, audio_sink)
def _setup_uhd(self): self._u = uhd.single_usrp_source(self._ip_addr, io_type=uhd.io_type_t.COMPLEX_FLOAT32, num_channels=1) self._u.set_antenna("TX/RX")
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)
def _setup_source(self, options): if options.source == "uhd": #UHD source by default from gnuradio import uhd src = uhd.single_usrp_source(options.args, uhd.io_type_t.COMPLEX_FLOAT32, 1) if(options.subdev): src.set_subdev_spec(options.subdev, 0) if not src.set_center_freq(162.0e6 * (1 + options.error/1.e6)): print "Failed to set initial frequency" else: print "Tuned to %.3fMHz" % (src.get_center_freq() / 1.e6) #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 src.get_time_source(0) != 'gpsdo': src.set_time_now(uhd.time_spec(0.0)) if options.antenna is not None: src.set_antenna(options.antenna) src.set_samp_rate(options.rate) if options.gain is None: #set to halfway g = src.get_gain_range() options.gain = (g.start()+g.stop()) / 2.0 print "Setting gain to %i" % options.gain src.set_gain(options.gain) print "Gain is %i" % src.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 src = osmosdr.source(options.args) src.set_sample_rate(options.rate) src.get_samp_rate = src.get_sample_rate #alias for UHD compatibility if not src.set_center_freq(162.0e6 * (1 + options.error/1.e6)): print "Failed to set initial frequency" else: print "Tuned to %.3fMHz" % (src.get_center_freq() / 1.e6) if options.gain is None: options.gain = 34 src.set_gain(options.gain) print "Gain is %i" % src.get_gain() else: #semantically detect whether it's ip.ip.ip.ip:port or filename self._rate = options.rate 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") src = blocks.udp_source(gr.sizeof_gr_complex, ip, int(port)) print "Using UDP source %s:%s" % (ip, port) else: src = blocks.file_source(gr.sizeof_gr_complex, options.source) print "Using file source %s" % options.source return src
def _setup_source(self, options): if options.source == "uhd": #UHD source by default from gnuradio import uhd src = uhd.single_usrp_source(options.args, uhd.io_type_t.COMPLEX_FLOAT32, 1) if(options.subdev): src.set_subdev_spec(options.subdev, 0) if not src.set_center_freq(162.0e6 * (1 + options.error/1.e6)): print("Failed to set initial frequency") else: print("Tuned to %.3fMHz" % (src.get_center_freq() / 1.e6)) #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 src.get_time_source(0) != 'gpsdo': src.set_time_now(uhd.time_spec(0.0)) if options.antenna is not None: src.set_antenna(options.antenna) src.set_samp_rate(options.rate) if options.gain is None: #set to halfway g = src.get_gain_range() options.gain = (g.start()+g.stop()) / 2.0 print("Setting gain to %i" % options.gain) src.set_gain(options.gain) print("Gain is %i" % src.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 src = osmosdr.source(options.args) src.set_sample_rate(options.rate) src.get_samp_rate = src.get_sample_rate #alias for UHD compatibility if not src.set_center_freq(162.0e6 * (1 + options.error/1.e6)): print("Failed to set initial frequency") else: print("Tuned to %.3fMHz" % (src.get_center_freq() / 1.e6)) if options.gain is None: options.gain = 34 src.set_gain(options.gain) print("Gain is %i" % src.get_gain()) else: #semantically detect whether it's ip.ip.ip.ip:port or filename self._rate = options.rate 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") src = blocks.udp_source(gr.sizeof_gr_complex, ip, int(port)) print("Using UDP source %s:%s" % (ip, port)) else: src = blocks.file_source(gr.sizeof_gr_complex, options.source) print("Using file source %s" % options.source) return src
def __init__(self, freq, subdev_spec, which_USRP, gain, audio_output, debug): gr.hier_block2.__init__( self, "analog_receive_path", gr.io_signature(0, 0, 0), #input signature gr.io_signature(0, 0, 0)) #output signature self.DEBUG = debug self.freq = freq self.rx_gain = gain #Formerly From XML self.fusb_block_size = 2048 self.fusb_nblocks = 8 self.rx_usrp_pga_gain_scaling = 0.5 self.rx_base_band_bw = 5e3 self.rx_freq_deviation = 2.5e3 # acquire USRP via USB 2.0 #self.u = usrp.source_c(fusb_block_size=self.fusb_block_size, # fusb_nblocks=self.fusb_nblocks, # which=which_USRP) self.u = uhd.single_usrp_source( device_addr="", io_type=uhd.io_type_t.COMPLEX_FLOAT32, num_channels=1, ) self.u.get_device # get A/D converter sampling rate #adc_rate = self.u.adc_rate() # 64 MS/s adc_rate = 64e6 # 64 MS/s if self.DEBUG: print " Rx Path ADC rate: %d" % (adc_rate) # setting USRP and GNU Radio decimation rate self.audio_rate = 16e3 self.max_gr_decim_rate = 40 self._usrp_decim = 250 self.gr_rate1 = adc_rate / self._usrp_decim gr_interp = 1 gr_decim = 16 self.gr_rate2 = self.gr_rate1 / gr_decim if self.DEBUG: print " usrp decim: ", self._usrp_decim print " gr rate 1: ", self.gr_rate1 print " gr decim: ", gr_decim print " gr rate 2: ", self.gr_rate2 print " gr interp: ", gr_interp print " audio rate: ", self.audio_rate # ================ Set up flowgraph ================================= # set USRP decimation ratio #self.u.set_decim_rate(self._usrp_decim) self.u.set_samp_rate(self.gr_rate1) self.u.set_antenna("RX2") # set USRP daughterboard subdevice if subdev_spec is None: subdev_spec = usrp.pick_rx_subdevice(self.u) #self.u.set_mux(usrp.determine_rx_mux_value(self.u, subdev_spec)) #self.subdev = usrp.selected_subdev(self.u, subdev_spec) #if self.DEBUG: # print " RX Path use daughterboard: %s" % (self.subdev.side_and_name()) # set USRP RF frequency """ Set the center frequency in Hz. Tuning is a two step process. First we ask the front-end to tune as close to the desired frequency as it can. Then we use the result of that operation and our target_frequency to determine the value for the digital up converter. """ assert (self.freq != None) #r = self.u.tune(0, self.subdev, self.freq) r = self.u.set_center_freq(self.freq, 0) if self.DEBUG: if r: print "----Rx RF frequency set to %f Hz" % (self.freq) else: print "Failed to set Rx frequency to %f Hz" % (self.freq) raise ValueError, eng_notation.num_to_str(self.freq) # set USRP Rx PGA gain #r = self.subdev.gain_range() #_rx_usrp_gain_range = r[1] - r[0] #_rx_usrp_gain = r[0]+_rx_usrp_gain_range * self.rx_usrp_pga_gain_scaling #self.subdev.set_gain(_rx_usrp_gain) #self.u.set_gain(3.25, 0) #if self.DEBUG: # print " USRP Rx PGA Gain Range: min = %g, max = %g, step size = %g" \ # %(r[0], r[1], r[2]) # print " USRP Rx PGA gain set to: %g" %(_rx_usrp_gain) # Do NOT Enable USRP Auto Tx/Rx switching for analog flow graph! #self.subdev.set_enable(False) # Baseband Channel Filter using FM Carson's Rule chan_bw = 2 * (self.rx_base_band_bw + self.rx_freq_deviation ) #Carson's Rule chan_filt_coeffs_float = optfir.low_pass( 1, #gain self.gr_rate1, #sampling rate chan_bw, #passband cutoff chan_bw * 1.35, #stopband cutoff 0.1, #passband ripple 60) #stopband attenuation chan_filt_coeffs_fixed = ( 0.000457763671875, 0.000946044921875, 0.00067138671875, 0.001068115234375, 0.00091552734375, 0.0008544921875, 0.000518798828125, 0.0001220703125, -0.000396728515625, -0.0008544921875, -0.00128173828125, -0.00146484375, -0.001434326171875, -0.0010986328125, -0.000518798828125, 0.000274658203125, 0.001129150390625, 0.00189208984375, 0.00238037109375, 0.00250244140625, 0.002166748046875, 0.0013427734375, 0.000152587890625, -0.001220703125, -0.002532958984375, -0.0035400390625, -0.003997802734375, -0.003753662109375, -0.002777099609375, -0.0010986328125, 0.000946044921875, 0.00311279296875, 0.00494384765625, 0.00604248046875, 0.006103515625, 0.005035400390625, 0.00286865234375, -0.0001220703125, -0.00347900390625, -0.006561279296875, -0.008758544921875, -0.00958251953125, -0.008636474609375, -0.005950927734375, -0.001739501953125, 0.00335693359375, 0.00848388671875, 0.0126953125, 0.01507568359375, 0.014862060546875, 0.01171875, 0.00579833984375, -0.002227783203125, -0.01123046875, -0.0196533203125, -0.02587890625, -0.028228759765625, -0.025421142578125, -0.016754150390625, -0.002166748046875, 0.017608642578125, 0.041015625, 0.0660400390625, 0.090240478515625, 0.111083984375, 0.12640380859375, 0.134490966796875, 0.134490966796875, 0.12640380859375, 0.111083984375, 0.090240478515625, 0.0660400390625, 0.041015625, 0.017608642578125, -0.002166748046875, -0.016754150390625, -0.025421142578125, -0.028228759765625, -0.02587890625, -0.0196533203125, -0.01123046875, -0.002227783203125, 0.00579833984375, 0.01171875, 0.014862060546875, 0.01507568359375, 0.0126953125, 0.00848388671875, 0.00335693359375, -0.001739501953125, -0.005950927734375, -0.008636474609375, -0.00958251953125, -0.008758544921875, -0.006561279296875, -0.00347900390625, -0.0001220703125, 0.00286865234375, 0.005035400390625, 0.006103515625, 0.00604248046875, 0.00494384765625, 0.00311279296875, 0.000946044921875, -0.0010986328125, -0.002777099609375, -0.003753662109375, -0.003997802734375, -0.0035400390625, -0.002532958984375, -0.001220703125, 0.000152587890625, 0.0013427734375, 0.002166748046875, 0.00250244140625, 0.00238037109375, 0.00189208984375, 0.001129150390625, 0.000274658203125, -0.000518798828125, -0.0010986328125, -0.001434326171875, -0.00146484375, -0.00128173828125, -0.0008544921875, -0.000396728515625, 0.0001220703125, 0.000518798828125, 0.0008544921875, 0.00091552734375, 0.001068115234375, 0.00067138671875, 0.000946044921875, 0.000457763671875) #r = gr.enable_realtime_scheduling () self.chan_filt = dsp.fir_ccf_fm_demod_decim(chan_filt_coeffs_fixed, 14, gr_decim, 0, 0, 0, 0) print "Tap length of chan FIR: ", len(chan_filt_coeffs_fixed) # Set the software LNA gain on the output of the USRP gain = self.rx_gain self.rx_gain = max(0.0, min(gain, 1e7)) if self.DEBUG: print " Rx Path initial software signal gain: %f (max 1e7)" % ( gain) print " Rx Path actual software signal gain : %f (max 1e7)" % ( self.rx_gain) #FM Demodulator fm_demod_gain = self.audio_rate / (2 * math.pi * self.rx_freq_deviation) self.fm_demod = gr.quadrature_demod_cf(fm_demod_gain) #Compute FIR filter taps for audio filter width_of_transition_band = self.rx_base_band_bw * 0.35 audio_coeffs = gr.firdes.low_pass( 1.0, #gain self.gr_rate2, #sampling rate self.rx_base_band_bw, width_of_transition_band, gr.firdes.WIN_HAMMING) self.audio_filter = gr.fir_filter_fff(1, audio_coeffs) passband_cutoff = self.rx_base_band_bw stopband_cutoff = passband_cutoff * 1.35 self.deemph = fm_deemph(self.audio_rate) if self.DEBUG: print "Length Audio FIR ", len(audio_coeffs) # Audio sink audio_sink = audio.sink(int(self.audio_rate), "default") # "", #Audio output pcm device name. E.g., hw:0,0 or surround51 or /dev/dsp # False) # ok_to_block if self.DEBUG: print "Before Connecting Blocks" # Wiring Up #WITH CHANNEL FILTER #self.connect (self.u, self.chan_filt, self.lna, self.fm_demod, self.audio_filter, interpolator, self.deemph, self.volume_control, audio_sink) #self.connect (self.u, self.fm_demod, self.audio_filter, self.deemph, self.volume_control, howto_rx, audio_sink) self.connect(self.u, self.chan_filt, self.audio_filter, self.deemph, audio_sink)
def __init__(self, frequency, sample_rate, uhd_address="192.168.10.2", trigger=False): gr.top_block.__init__(self) self.freq = frequency self.samp_rate = sample_rate self.uhd_addr = uhd_address self.gain = 32 self.trigger = trigger self.uhd_src = uhd.single_usrp_source( device_addr=self.uhd_addr, io_type=uhd.io_type_t.COMPLEX_FLOAT32, num_channels=1, ) self.uhd_src.set_samp_rate(self.samp_rate) self.uhd_src.set_center_freq(self.freq, 0) self.uhd_src.set_gain(self.gain, 0) taps = firdes.low_pass_2(1, 1, 0.4, 0.1, 60) self.chanfilt = gr.fir_filter_ccc(10, taps) self.ann0 = gr.annotator_alltoall(100000, gr.sizeof_gr_complex) self.tagger = gr.burst_tagger(gr.sizeof_gr_complex) # Dummy signaler to collect a burst on known periods data = 1000 * [ 0, ] + 1000 * [ 1, ] self.signal = gr.vector_source_s(data, True) # Energy detector to get signal burst self.c2m = gr.complex_to_mag_squared() self.iir = gr.single_pole_iir_filter_ff(0.0001) self.sub = gr.sub_ff() self.mult = gr.multiply_const_ff(32768) self.f2s = gr.float_to_short() self.fsnk = gr.tagged_file_sink(gr.sizeof_gr_complex, self.samp_rate) ################################################## # Connections ################################################## self.connect((self.uhd_src, 0), (self.tagger, 0)) self.connect((self.tagger, 0), (self.fsnk, 0)) if self.trigger: # Connect a dummy signaler to the burst tagger self.connect((self.signal, 0), (self.tagger, 1)) else: # Connect an energy detector signaler to the burst tagger self.connect((self.uhd_src, 0), (self.c2m, 0)) self.connect((self.c2m, 0), (self.sub, 0)) self.connect((self.c2m, 0), (self.iir, 0)) self.connect((self.iir, 0), (self.sub, 1)) self.connect((self.sub, 0), (self.mult, 0)) self.connect((self.mult, 0), (self.f2s, 0)) self.connect((self.f2s, 0), (self.tagger, 1))
def __init__(self): grc_wxgui.top_block_gui.__init__(self, title="Top Block") ################################################## # Variables ################################################## self.variable_slider_0 = variable_slider_0 = 0 self.samp_rate = samp_rate = 500e3 ################################################## # Controls ################################################## _variable_slider_0_sizer = wx.BoxSizer(wx.VERTICAL) self._variable_slider_0_text_box = forms.text_box( parent=self.GetWin(), sizer=_variable_slider_0_sizer, value=self.variable_slider_0, callback=self.set_variable_slider_0, label="Volume", converter=forms.float_converter(), proportion=0, ) self._variable_slider_0_slider = forms.slider( parent=self.GetWin(), sizer=_variable_slider_0_sizer, value=self.variable_slider_0, callback=self.set_variable_slider_0, minimum=0, maximum=100, num_steps=100, style=wx.SL_HORIZONTAL, cast=float, proportion=1, ) self.Add(_variable_slider_0_sizer) ################################################## # Blocks ################################################## self.audio_sink_0 = audio.sink(48000, "", True) self.blks2_nbfm_rx_0 = blks2.nbfm_rx( audio_rate=25000, quad_rate=100000, tau=75e-6, max_dev=15e3, ) self.blks2_rational_resampler_xxx_0 = blks2.rational_resampler_ccc( interpolation=1, decimation=5, taps=None, fractional_bw=None, ) self.blks2_rational_resampler_xxx_1 = blks2.rational_resampler_fff( interpolation=48, decimation=25, taps=None, fractional_bw=None, ) self.gr_multiply_const_vxx_0 = gr.multiply_const_vff((variable_slider_0, )) self.gr_multiply_const_vxx_1 = gr.multiply_const_vcc((100e3, )) self.low_pass_filter_0 = gr.fir_filter_ccf(1, firdes.low_pass( 10, samp_rate, 5e3, 10e3, firdes.WIN_HAMMING, 6.76)) self.uhd_single_usrp_source_0 = uhd.single_usrp_source( device_addr="addr=192.168.10.3", io_type=uhd.io_type.COMPLEX_FLOAT32, num_channels=1, ) self.uhd_single_usrp_source_0.set_samp_rate(samp_rate) self.uhd_single_usrp_source_0.set_center_freq(462.5625e6, 0) self.uhd_single_usrp_source_0.set_gain(45, 0) self.wxgui_waterfallsink2_0 = waterfallsink2.waterfall_sink_c( self.GetWin(), baseband_freq=0, dynamic_range=100, ref_level=50, ref_scale=2.0, sample_rate=samp_rate, fft_size=512, fft_rate=15, average=False, avg_alpha=None, title="Waterfall Plot", ) self.Add(self.wxgui_waterfallsink2_0.win) ################################################## # Connections ################################################## self.connect((self.blks2_nbfm_rx_0, 0), (self.blks2_rational_resampler_xxx_1, 0)) self.connect((self.blks2_rational_resampler_xxx_0, 0), (self.blks2_nbfm_rx_0, 0)) self.connect((self.low_pass_filter_0, 0), (self.blks2_rational_resampler_xxx_0, 0)) self.connect((self.blks2_rational_resampler_xxx_1, 0), (self.gr_multiply_const_vxx_0, 0)) self.connect((self.uhd_single_usrp_source_0, 0), (self.gr_multiply_const_vxx_1, 0)) self.connect((self.gr_multiply_const_vxx_1, 0), (self.low_pass_filter_0, 0)) self.connect((self.gr_multiply_const_vxx_0, 0), (self.audio_sink_0, 0)) self.connect((self.low_pass_filter_0, 0), (self.wxgui_waterfallsink2_0, 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))
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 = blocks.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) self._u = ReadByteFile(options) print "Using file source %s" % options.source print "Rate is %i" % (options.rate,)
def _setup_uhd(self): self._u = uhd.single_usrp_source(self._ip_addr, io_type=uhd.io_type_t.COMPLEX_FLOAT32, num_channels=1)