def detect_usrp2(): interface = 'eth0' args = ['find_usrps', '-e', interface] p = subprocess.Popen(args=args, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, shell=False, universal_newlines=True) msg = p.stdout.read() usrp2_macs = sorted(map(lambda l: l.split()[0], filter(lambda l: l.count(':') >= 5, msg.strip().splitlines()))) if(len(usrp2_macs)==0): print "\033[1;31mno USRP2's found\033[1;m" return -1 for usrp2_mac in usrp2_macs: print "\033[1;31mUSRP2 found, mac address:", usrp2_mac, "\033[1;m" u2 = usrp2.source_32fc(interface, usrp2_mac) db = u2.daughterboard_id() if(db!=-1): db_name = [k for k, v in usrp_dbid.__dict__.iteritems() if v == db][0] print "\033[1;33mRX daughterboard:", db_name, "(dbid: 0x%04X)" % (db,), "\033[1;m" print "freq range: (", u2.freq_min()/1e6, "MHz, ", u2.freq_max()/1e6, "MHz )" u2 = usrp2.sink_32fc(interface, usrp2_mac) db = u2.daughterboard_id() if(db!=-1): db_name = [k for k, v in usrp_dbid.__dict__.iteritems() if v == db][0] print "\033[1;33mTX daughterboard:", db_name, "(dbid: 0x%04X)" % (db,), "\033[1;m" print "freq range: (", u2.freq_min()/1e6, "MHz, ", u2.freq_max()/1e6, "MHz )"
def __init__(self, options): gr.top_block.__init__(self) # Create a USRP2 source and set decimation rate self._u = usrp2.source_32fc(options.interface, options.mac_addr) self._u.set_decim(512) # Set receive daughterboard gain if options.gain is None: g = self._u.gain_range() options.gain = float(g[0] + g[1]) / 2 print "Using mid-point gain of", options.gain, "(", g[0], "-", g[ 1], ")" self._u.set_gain(options.gain) # Set receive frequency if options.lo_offset is not None: self._u.set_lo_offset(options.lo_offset) tr = self._u.set_center_freq(options.freq) if tr == None: sys.stderr.write('Failed to set center frequency\n') raise SystemExit, 1 sample_rate = 100e6 / 512 symbol_rate = 18000 sps = 2 # output rate will be 36,000 ntaps = 11 * sps new_sample_rate = symbol_rate * sps channel_taps = filter.firdes.low_pass(1.0, sample_rate, options.low_pass, options.low_pass * 0.1, filter.firdes.WIN_HANN) FILTER = filter.freq_xlating_fir_filter_ccf(1, channel_taps, options.calibration, sample_rate) sys.stderr.write("sample rate: %d\n" % (sample_rate)) DEMOD = cqpsk.cqpsk_demod(samples_per_symbol=sps, excess_bw=0.35, costas_alpha=0.03, gain_mu=0.05, mu=0.05, omega_relative_limit=0.05, log=options.log, verbose=options.verbose) OUT = blocks.file_sink(gr.sizeof_float, options.output_file) r = float(sample_rate) / float(new_sample_rate) INTERPOLATOR = filter.fractional_resampler_cc(0, r) self.connect(self._u, FILTER, INTERPOLATOR, DEMOD, OUT)
def __init__(self): sense_band_start=900*10**6 sense_band_stop=940*10**6 self.fft_size = options.fft_size self.ofdm_bins = options.sense_bins # build graph s2v = gr.stream_to_vector(gr.sizeof_gr_complex, self.fft_size) mywindow = window.blackmanharris(self.fft_size) fft = gr.fft_vcc(self.fft_size, True, mywindow) power = 0 for tap in mywindow: power += tap*tap c2mag = gr.complex_to_mag_squared(self.fft_size) #log = gr.nlog10_ff(10, self.fft_size, -20*math.log10(self.fft_size)-10*math.log10(power/self.fft_size)) # modifications for USRP2 print "*******************in sensor init********************" if self.IS_USRP2: self.u = usrp2.source_32fc(options.interface, options.MAC_addr) self.u.set_decim(options.decim) samp_rate = self.u.adc_rate() / self.u.decim() else: self.u = gr.file_source(gr.sizeof_gr_complex,options.input_file, True) samp_rate = 100e6 / options.decim self.freq_step =0.75* samp_rate #self.min_center_freq = (self.min_freq + self.max_freq)/2 global BW BW = 0.75* samp_rate #self.max_freq - self.min_freq global size size=self.fft_size global ofdm_bins ofdm_bins = self.ofdm_bins global usr #global thrshold_inorder usr=samp_rate nsteps = 10 #math.ceil((self.max_freq - self.min_freq) / self.freq_step) self.max_center_freq = self.min_center_freq + (nsteps * self.freq_step) self.next_freq = self.min_center_freq tune_delay = max(0, int(round(options.tune_delay * samp_rate / self.fft_size))) # in fft_frames print tune_delay dwell_delay = max(1, int(round(options.dwell_delay * samp_rate / self.fft_size))) # in fft_frames print dwell_delay self.msgq = gr.msg_queue(16) self._tune_callback = tune(self) # hang on to this to keep it from being GC'd stats = gr.bin_statistics_f(self.fft_size, self.msgq, self._tune_callback, tune_delay, dwell_delay) self.connect(self.u, s2v, fft,c2mag,stats) if options.gain is None: # if no gain was specified, use the mid-point in dB g = self.u.gain_range() options.gain = float(g[0]+g[1])/2
def source(options): from gnuradio import usrp2 u = usrp2.source_32fc (ifc=options.ifc, mac=expand(options.mac)) u.set_decim(options.interp) ok = u.set_center_freq(options.freq) if not ok: raise ValueError("Failed to set Rx frequency to %s" % (eng_notation.num_to_str(options.freq))) if options.gain is None: options.gain = (u.gain_min() + u.gain_max())/2 # default gain is midpoint u.set_gain(options.gain) return u
def __init__(self, options): gr.top_block.__init__(self) # Create a USRP2 source and set decimation rate self._u = usrp2.source_32fc(options.interface, options.mac_addr) self._u.set_decim(512) # Set receive daughterboard gain if options.gain is None: g = self._u.gain_range() options.gain = float(g[0]+g[1])/2 print "Using mid-point gain of", options.gain, "(", g[0], "-", g[1], ")" self._u.set_gain(options.gain) # Set receive frequency if options.lo_offset is not None: self._u.set_lo_offset(options.lo_offset) tr = self._u.set_center_freq(options.freq) if tr == None: sys.stderr.write('Failed to set center frequency\n') raise SystemExit, 1 sample_rate = 100e6/512 symbol_rate = 18000 sps = 2 # output rate will be 36,000 ntaps = 11 * sps new_sample_rate = symbol_rate * sps channel_taps = gr.firdes.low_pass(1.0, sample_rate, options.low_pass, options.low_pass * 0.1, gr.firdes.WIN_HANN) FILTER = gr.freq_xlating_fir_filter_ccf(1, channel_taps, options.calibration, sample_rate) sys.stderr.write("sample rate: %d\n" %(sample_rate)) DEMOD = cqpsk.cqpsk_demod( samples_per_symbol = sps, excess_bw=0.35, costas_alpha=0.03, gain_mu=0.05, mu=0.05, omega_relative_limit=0.05, log=options.log, verbose=options.verbose) OUT = gr.file_sink(gr.sizeof_float, options.output_file) r = float(sample_rate) / float(new_sample_rate) INTERPOLATOR = gr.fractional_interpolator_cc(0, r) self.connect(self._u, FILTER, INTERPOLATOR, DEMOD, OUT)
def source(options): from gnuradio import usrp2 u = usrp2.source_32fc(ifc=options.ifc, mac=expand(options.mac)) u.set_decim(options.interp) ok = u.set_center_freq(options.freq) if not ok: raise ValueError("Failed to set Rx frequency to %s" % (eng_notation.num_to_str(options.freq))) if options.gain is None: options.gain = (u.gain_min() + u.gain_max()) / 2 # default gain is midpoint u.set_gain(options.gain) return u
def _set_source(self): options = self.options self.usrp = usrp2.source_32fc(options.interface, options.mac_addr) self.usrp.set_decim(options.decim) # determine the daughterboard subdevice input_rate = self.usrp.adc_rate() / options.decim # set initial values if options.gain is None: # if no gain was specified, use the mid-point in dB g = self.usrp.gain_range() options.gain = float(g[0]+g[1])/2 r = self.usrp.set_center_freq(options.freq) self.usrp.set_gain(options.gain) return self.usrp
def __init__(self): gr.top_block.__init__(self) gain=0.7 target_freq=930e6 decim=16 interface="" MAC_addr="" fft_size=512 self.u = usrp2.source_32fc() self.u.set_decim(128) self.u.set_center_freq(930e6) self.u.set_gain(0) self.u.config_mimo(usrp2.MC_WE_DONT_LOCK) self.s2v = gr.stream_to_vector(gr.sizeof_gr_complex*1, 512) self.f_sink = gr.file_sink(gr.sizeof_gr_complex*512, "fft_data") self.f_sink.set_unbuffered(False) self.fft = gr.fft_vcc(512, True, (window.blackmanharris(512)), True) self.connect(self.u,self.s2v,self.fft,self.f_sink)
def __init__(self, options, rx_callback): gr.top_block.__init__(self) if options.infile is None: # Initialize USRP2 block u = usrp2.source_32fc(options.interface, options.mac_addr) self.samples_per_symbol = 2 self.chan_num = options.channel self.data_rate = int(u.adc_rate() / self.samples_per_symbol / options.decim_rate) u.set_center_freq(ieee802_15_4_pkt.chan_802_15_4.chan_map[self.chan_num]) u.set_decim(options.decim_rate) u.set_gain(options.gain) print "cordic_freq = %s" % (eng_notation.num_to_str(ieee802_15_4_pkt.chan_802_15_4.chan_map[self.chan_num])) print "data_rate = ", eng_notation.num_to_str(self.data_rate) print "samples_per_symbol = ", self.samples_per_symbol print "usrp_decim = ", options.decim_rate self.src = u else: self.src = gr.file_source(gr.sizeof_gr_complex, options.infile) self.samples_per_symbol = 2 self.data_rate = 2000000 self.packet_receiver = ieee802_15_4_pkt.ieee802_15_4_demod_pkts( self, callback=rx_callback, sps=self.samples_per_symbol, symbol_rate=self.data_rate, channel=self.chan_num, threshold=options.threshold, ) # self.squelch = gr.pwr_squelch_cc(-65, gate=True) self.connect( self.src, # self.squelch, self.packet_receiver, )
def __init__(self, options, rx_callback): gr.top_block.__init__(self) if options.infile is None: # Initialize USRP2 block u = usrp2.source_32fc(options.interface, options.mac_addr) self.samples_per_symbol = 2 self.chan_num = options.channel self.data_rate = int (u.adc_rate() / self.samples_per_symbol / options.decim_rate) u.set_center_freq(ieee802_15_4_pkt.chan_802_15_4.chan_map[self.chan_num]) u.set_decim(options.decim_rate) u.set_gain(options.gain) print "cordic_freq = %s" % (eng_notation.num_to_str(ieee802_15_4_pkt.chan_802_15_4.chan_map[self.chan_num])) print "data_rate = ", eng_notation.num_to_str(self.data_rate) print "samples_per_symbol = ", self.samples_per_symbol print "usrp_decim = ", options.decim_rate self.src = u else: self.src = gr.file_source(gr.sizeof_gr_complex, options.infile); self.samples_per_symbol = 2 self.data_rate = 2000000 self.packet_receiver = ieee802_15_4_pkt.ieee802_15_4_demod_pkts(self, callback=rx_callback, sps=self.samples_per_symbol, symbol_rate=self.data_rate, channel=self.chan_num, threshold=options.threshold) #self.squelch = gr.pwr_squelch_cc(-65, gate=True) self.connect(self.src, # self.squelch, self.packet_receiver)
def main(): center_freq = 915e6 hw_dec_rate = 4 #USRP decimation rate. Lower -> more bandwidth downsample_rate = 10 #If you get 'S's, increase downsample_rate #tari = 7 # us. If you don't know, use 0. Then look at log to find actual TARI value. #pulse_width = 3.5 # us. 1/2 tari tari = 24 # us. If you don't know, use 0. Then look at log to find actual TARI value. pulse_width = 12 # us. 1/2 tari log_file = open("rm_log.log", 'w') u = usrp2.source_32fc() rm = reader_monitor(u, center_freq, hw_dec_rate, downsample_rate, pulse_width, tari, True) x = gr.enable_realtime_scheduling() if x != gr.RT_OK: print "Warning: failed to enable realtime scheduling" rm.start() t = Timer(LOG_INTERVAL, timed_log_write, [rm, log_file]) t.setDaemon(True) t.start() while 1: c = raw_input("Q to Quit") if c == "Q" or c == "q": break print "Shutting Down" rm.stop() log_file.close()
def detect_usrp2(): interface = 'eth0' args = ['find_usrps', '-e', interface] p = subprocess.Popen(args=args, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, shell=False, universal_newlines=True) msg = p.stdout.read() usrp2_macs = sorted( map(lambda l: l.split()[0], filter(lambda l: l.count(':') >= 5, msg.strip().splitlines()))) if (len(usrp2_macs) == 0): print "\033[1;31mno USRP2's found\033[1;m" return -1 for usrp2_mac in usrp2_macs: print "\033[1;31mUSRP2 found, mac address:", usrp2_mac, "\033[1;m" u2 = usrp2.source_32fc(interface, usrp2_mac) db = u2.daughterboard_id() if (db != -1): db_name = [ k for k, v in usrp_dbid.__dict__.iteritems() if v == db ][0] print "\033[1;33mRX daughterboard:", db_name, "(dbid: 0x%04X)" % ( db, ), "\033[1;m" print "freq range: (", u2.freq_min() / 1e6, "MHz, ", u2.freq_max( ) / 1e6, "MHz )" u2 = usrp2.sink_32fc(interface, usrp2_mac) db = u2.daughterboard_id() if (db != -1): db_name = [ k for k, v in usrp_dbid.__dict__.iteritems() if v == db ][0] print "\033[1;33mTX daughterboard:", db_name, "(dbid: 0x%04X)" % ( db, ), "\033[1;m" print "freq range: (", u2.freq_min() / 1e6, "MHz, ", u2.freq_max( ) / 1e6, "MHz )"
def __init__(self, interface, address, center_freq, offset_freq, decim, squelch, gain): gr.top_block.__init__(self) # setup USRP2 u = usrp2.source_32fc(interface, address) u.set_decim(decim) capture_rate = u.adc_rate() / decim u.set_center_freq(center_freq) if gain is None: g = u.gain_range() gain = float(g[0] + g[1]) / 2 u.set_gain(gain) # Setup receiver attributes channel_rate = 125000 symbol_rate = 4800 # channel filter self.channel_offset = offset_freq channel_decim = capture_rate // channel_rate channel_rate = capture_rate // channel_decim trans_width = 12.5e3 / 2 trans_centre = trans_width + (trans_width / 2) coeffs = gr.firdes.low_pass(1.0, capture_rate, trans_centre, trans_width, gr.firdes.WIN_HANN) self.channel_filter = gr.freq_xlating_fir_filter_ccf( channel_decim, coeffs, self.channel_offset, capture_rate) self.connect(u, self.channel_filter) # power squelch power_squelch = gr.pwr_squelch_cc(squelch, 1e-3, 0, True) self.connect(self.channel_filter, power_squelch) # FM demodulator self.symbol_deviation = 600.0 fm_demod_gain = channel_rate / (2.0 * pi * self.symbol_deviation) fm_demod = gr.quadrature_demod_cf(fm_demod_gain) self.connect(power_squelch, fm_demod) # symbol filter symbol_decim = 1 samples_per_symbol = channel_rate // symbol_rate symbol_coeffs = (1.0 / samples_per_symbol, ) * samples_per_symbol symbol_filter = gr.fir_filter_fff(symbol_decim, symbol_coeffs) self.connect(fm_demod, symbol_filter) # C4FM demodulator autotuneq = gr.msg_queue(2) self.demod_watcher = demod_watcher(autotuneq, self.adjust_channel_offset) demod_fsk4 = op25.fsk4_demod_ff(autotuneq, channel_rate, symbol_rate) self.connect(symbol_filter, demod_fsk4) # symbol slicer levels = [-2.0, 0.0, 2.0, 4.0] slicer = op25.fsk4_slicer_fb(levels) self.connect(demod_fsk4, slicer) # frame decoder decoder = op25.decoder_bf() self.connect(slicer, decoder) # try to connect audio output device try: audio_sink = audio.sink(8000, "plughw:0,0", True) self.connect(decoder, audio_sink) except Exception: sink = gr.null_sink(gr.sizeof_float) self.connect(decoder, null)
def __init__(self, frame, panel, vbox, argv): stdgui2.std_top_block.__init__(self, frame, panel, vbox, argv) parser = OptionParser(option_class=eng_option) parser.add_option("-e", "--interface", type="string", default="eth0", help="select Ethernet interface, default is eth0") parser.add_option( "-m", "--mac-addr", type="string", default="", help="select USRP by MAC address, default is auto-select") #parser.add_option("-A", "--antenna", default=None, # help="select Rx Antenna (only on RFX-series boards)") parser.add_option("-f", "--freq", type="eng_float", default=100.1, help="set frequency to FREQ", metavar="FREQ") parser.add_option("-g", "--gain", type="eng_float", default=None, help="set gain in dB (default is midpoint)") parser.add_option("-V", "--volume", type="eng_float", default=None, help="set volume (default is midpoint)") parser.add_option( "-O", "--audio-output", type="string", default="", help="pcm device name. E.g., hw:0,0 or surround51 or /dev/dsp") (options, args) = parser.parse_args() if len(args) != 0: parser.print_help() sys.exit(1) self.frame = frame self.panel = panel self.vol = 0 self.state = "FREQ" self.freq = 0 # build graph self.u = usrp2.source_32fc(options.interface, options.mac_addr) adc_rate = self.u.adc_rate() # 100 MS/s usrp_decim = 312 self.u.set_decim(usrp_decim) usrp_rate = adc_rate / usrp_decim # ~320 kS/s chanfilt_decim = 1 demod_rate = usrp_rate / chanfilt_decim audio_decimation = 10 audio_rate = demod_rate / audio_decimation # ~32 kHz #FIXME: need named constants and text descriptions available to (gr-)usrp2 even #when usrp(1) module is not built. A usrp_common module, perhaps? dbid = self.u.daughterboard_id() print "Using RX d'board 0x%04X" % (dbid, ) if not (dbid == 0x0001 or #usrp_dbid.BASIC_RX dbid == 0x0003 or #usrp_dbid.TV_RX dbid == 0x000c or #usrp_dbid.TV_RX_REV_2 dbid == 0x0040 or #usrp_dbid.TV_RX_REV_3 dbid == 0x0043 or #usrp_dbid.TV_RX_MIMO dbid == 0x0044 or #usrp_dbid.TV_RX_REV_2_MIMO dbid == 0x0045): #usrp_dbid.TV_RX_REV_3_MIMO print "This daughterboard does not cover the required frequency range" print "for this application. Please use a BasicRX or TVRX daughterboard." raw_input("Press ENTER to continue anyway, or Ctrl-C to exit.") chan_filt_coeffs = optfir.low_pass( 1, # gain usrp_rate, # sampling rate 80e3, # passband cutoff 115e3, # stopband cutoff 0.1, # passband ripple 60) # stopband attenuation #print len(chan_filt_coeffs) chan_filt = gr.fir_filter_ccf(chanfilt_decim, chan_filt_coeffs) self.guts = blks2.wfm_rcv(demod_rate, audio_decimation) self.volume_control = gr.multiply_const_ff(self.vol) # sound card as final sink audio_sink = audio.sink(int(audio_rate), options.audio_output, False) # ok_to_block # now wire it all together self.connect(self.u, chan_filt, self.guts, self.volume_control, audio_sink) self._build_gui(vbox, usrp_rate, demod_rate, audio_rate) if options.gain is None: # if no gain was specified, use the mid-point in dB g = self.u.gain_range() options.gain = float(g[0] + g[1]) / 2 if options.volume is None: g = self.volume_range() options.volume = float(g[0] + g[1]) / 2 if abs(options.freq) < 1e6: options.freq *= 1e6 # set initial values self.set_gain(options.gain) self.set_vol(options.volume) if not (self.set_freq(options.freq)): self._set_status_msg("Failed to set initial frequency")
def __init__(self): gr.top_block.__init__(self) parser = OptionParser(option_class=eng_option) parser.add_option("-e", "--interface", type="string", default="eth0", help="select Ethernet interface, default is eth0") parser.add_option("-m", "--mac-addr", type="string", default="", help="select USRP by MAC address, default is auto-select") parser.add_option("-W", "--bw", type="eng_float", default=1e6, help="set bandwidth of receiver [default=%default]") parser.add_option("-f", "--freq", type="eng_float", default=2412e6, help="set frequency to FREQ", metavar="FREQ") parser.add_option("-g", "--gain", type="eng_float", default=None, help="set gain in dB (default is midpoint)") parser.add_option("--fft-size", type="int", default=2048, help="Set number of FFT bins [default=%default]") (options, args) = parser.parse_args() if len(args) != 0: parser.print_help() sys.exit(1) self.options = options self.show_debug_info = True self.qapp = QtGui.QApplication(sys.argv) self.u = usrp2.source_32fc(options.interface, options.mac_addr) self._adc_rate = self.u.adc_rate() self.set_bandwidth(options.bw) if options.gain is None: # if no gain was specified, use the mid-point in dB g = self.u.gain_range() options.gain = float(g[0]+g[1])/2 self.set_gain(options.gain) if options.freq is None: # if no frequency was specified, use the mid-point of the subdev f = self.u.freq_range() options.freq = float(f[0]+f[1])/2 self.set_frequency(options.freq) self._fftsize = options.fft_size self.snk = qtgui.sink_c(options.fft_size, gr.firdes.WIN_BLACKMAN_hARRIS, self._freq, self._bandwidth, "USRP2 Display", True, True, True, False) # Set up internal amplifier self.amp = gr.multiply_const_cc(0.0) self.set_amplifier_gain(100) # Create a single-pole IIR filter to remove DC # but don't connect it yet self.dc_gain = 0.001 self.dc = gr.single_pole_iir_filter_cc(self.dc_gain) self.dc_sub = gr.sub_cc() self.connect(self.u, self.amp, self.snk) if self.show_debug_info: print "Decimation rate: ", self._decim print "Bandwidth: ", self._bandwidth print "D'board: ", self.u.daughterboard_id() # Get the reference pointer to the SpectrumDisplayForm QWidget # Wrap the pointer as a PyQt SIP object # This can now be manipulated as a PyQt4.QtGui.QWidget self.pysink = sip.wrapinstance(self.snk.pyqwidget(), QtGui.QWidget) self.main_win = main_window(self.pysink, self) self.main_win.set_frequency(self._freq) self.main_win.set_gain(self._gain) self.main_win.set_bandwidth(self._bandwidth) self.main_win.set_amplifier(self._amp_value) self.main_win.show()
def _setup_usrp2(self): self._u = usrp2.source_32fc(self._interface, self._mac_addr)
def __init__(self): gr.top_block.__init__(self) parser = OptionParser(option_class=eng_option) parser.add_option("-e", "--interface", type="string", default="eth0", help="select Ethernet interface, default is eth0") parser.add_option("-m", "--mac-addr", type="string", default="", help="select USRP by MAC address, default is auto-select") #parser.add_option("-A", "--antenna", default=None, # help="select Rx Antenna (only on RFX-series boards)") parser.add_option("-f", "--freq", type="eng_float", default=100.1, help="set frequency to FREQ", metavar="FREQ") parser.add_option("-g", "--gain", type="eng_float", default=None, help="set gain in dB (default is midpoint)") parser.add_option("-V", "--volume", type="eng_float", default=None, help="set volume (default is midpoint)") parser.add_option("-O", "--audio-output", type="string", default="", help="pcm device name. E.g., hw:0,0 or surround51 or /dev/dsp") (options, args) = parser.parse_args() if len(args) != 0: parser.print_help() sys.exit(1) self._volume = options.volume self._usrp_freq = options.freq self._usrp_gain = options.gain self._audio_rate = int(32e3) # build graph self.u = usrp2.source_32fc(options.interface, options.mac_addr) # calculate decimation values to get USRP BW at 320 kHz self.calculate_usrp_bw(320e3) self.set_decim(self._usrp_decim) #FIXME: need named constants and text descriptions available to (gr-)usrp2 even #when usrp(1) module is not built. A usrp_common module, perhaps? dbid = self.u.daughterboard_id() print "Using RX d'board 0x%04X" % (dbid,) #if not (dbid == 0x0001 or #usrp_dbid.BASIC_RX # dbid == 0x0003 or #usrp_dbid.TV_RX # dbid == 0x000c or #usrp_dbid.TV_RX_REV_2 # dbid == 0x0040 or #usrp_dbid.TV_RX_REV_3 # dbid == 0x0043 or #usrp_dbid.TV_RX_MIMO # dbid == 0x0044 or #usrp_dbid.TV_RX_REV_2_MIMO # dbid == 0x0045 ): #usrp_dbid.TV_RX_REV_3_MIMO # print "This daughterboard does not cover the required frequency range" # print "for this application. Please use a BasicRX or TVRX daughterboard." # raw_input("Press ENTER to continue anyway, or Ctrl-C to exit.") chan_filt_coeffs = optfir.low_pass (1, # gain self._usrp_rate, # sampling rate 80e3, # passband cutoff 115e3, # stopband cutoff 0.1, # passband ripple 60) # stopband attenuation #print len(chan_filt_coeffs) chan_filt = gr.fir_filter_ccf (self._chanfilt_decim, chan_filt_coeffs) self.guts = blks2.wfm_rcv (self._demod_rate, self._audio_decim) self.volume_control = gr.multiply_const_ff(1) # sound card as final sink #audio_sink = audio.sink (int (audio_rate), # options.audio_output, # False) # ok_to_block audio_sink = audio.sink (self._audio_rate, options.audio_output) if self._usrp_gain is None: # if no gain was specified, use the mid-point in dB g = self.u.gain_range() print "Gain range: ", g self._usrp_gain = float(g[0]+g[1])/2 if self._volume is None: g = self.volume_range() self._volume = float(g[0]+g[1])/2 if abs(self._usrp_freq) < 1e6: self._usrp_freq *= 1e6 # set initial values self.set_gain(self._usrp_gain) self.set_volume(self._volume) if not(self.set_freq(self._usrp_freq)): print ("Failed to set initial frequency") # Define a GUI sink to display the received signal self.qapp = QtGui.QApplication(sys.argv) fftsize = 2048 self.usrp_rx = qtgui.sink_c(fftsize, gr.firdes.WIN_BLACKMAN_hARRIS, -self._usrp_rate/2.0, self._usrp_rate/2.0, "Received Signal", True, True, False, True, False, use_openGL=False) self.usrp_rx2 = qtgui.sink_f(fftsize, gr.firdes.WIN_BLACKMAN_hARRIS, -self._usrp_rate/2.0, self._usrp_rate/2.0, "Received Signal", True, True, False, True, False) # now wire it all together self.connect (self.u, chan_filt, self.guts, self.volume_control, audio_sink) self.connect (self.u, self.usrp_rx) self.connect (self.volume_control, self.usrp_rx2) usrp_rx_widget = sip.wrapinstance(self.usrp_rx.pyqwidget(), QtGui.QWidget) usrp_rx2_widget = sip.wrapinstance(self.usrp_rx2.pyqwidget(), QtGui.QWidget) self.main_box = dialog_box(usrp_rx_widget, usrp_rx2_widget, self) self.main_box.show()
def __init__(self, frame, panel, vbox, argv): stdgui2.std_top_block.__init__(self, frame, panel, vbox, argv) self.frame = frame self.panel = panel parser = OptionParser(option_class=eng_option) parser.add_option("-e", "--interface", type="string", default="eth0", help="select Ethernet interface, default is eth0") parser.add_option("-m", "--mac-addr", type="string", default="", help="select USRP by MAC address, default is auto-select") #parser.add_option("-A", "--antenna", default=None, # help="select Rx Antenna (only on RFX-series boards)") parser.add_option("-d", "--decim", type="int", default=16, help="set fgpa decimation rate to DECIM [default=%default]") parser.add_option("-f", "--freq", type="eng_float", default=None, help="set frequency to FREQ", metavar="FREQ") parser.add_option("-g", "--gain", type="eng_float", default=None, help="set gain in dB (default is midpoint)") parser.add_option("-W", "--waterfall", action="store_true", default=False, help="Enable waterfall display") parser.add_option("-S", "--oscilloscope", action="store_true", default=False, help="Enable oscilloscope display") parser.add_option("", "--avg-alpha", type="eng_float", default=1e-1, help="Set fftsink averaging factor, default=[%default]") parser.add_option("", "--ref-scale", type="eng_float", default=1.0, help="Set dBFS=0dB input value, default=[%default]") parser.add_option("--fft-size", type="int", default=1024, help="Set number of FFT bins [default=%default]") (options, args) = parser.parse_args() if len(args) != 0: parser.print_help() sys.exit(1) self.options = options self.show_debug_info = True self.u = usrp2.source_32fc(options.interface, options.mac_addr) self.u.set_decim(options.decim) input_rate = self.u.adc_rate() / self.u.decim() if options.waterfall: self.scope = \ waterfallsink2.waterfall_sink_c (panel, fft_size=1024, sample_rate=input_rate) elif options.oscilloscope: self.scope = scopesink2.scope_sink_c(panel, sample_rate=input_rate) else: self.scope = fftsink2.fft_sink_c (panel, fft_size=options.fft_size, sample_rate=input_rate, ref_scale=options.ref_scale, ref_level=20.0, y_divs = 12, avg_alpha=options.avg_alpha) self.connect(self.u, self.scope) self._build_gui(vbox) self._setup_events() # set initial values if options.gain is None: # if no gain was specified, use the mid-point in dB g = self.u.gain_range() options.gain = float(g[0]+g[1])/2 if options.freq is None: # if no freq was specified, use the mid-point r = self.u.freq_range() options.freq = float(r[0]+r[1])/2 self.set_gain(options.gain) #if options.antenna is not None: # print "Selecting antenna %s" % (options.antenna,) # self.subdev.select_rx_antenna(options.antenna) if self.show_debug_info: self.myform['decim'].set_value(self.u.decim()) self.myform['fs@gbe'].set_value(input_rate) self.myform['dbname'].set_value("0x%04X" % (self.u.daughterboard_id(),)) # FIXME: add text name self.myform['baseband'].set_value(0) self.myform['ddc'].set_value(0) if not(self.set_freq(options.freq)): self._set_status_msg("Failed to set initial frequency")
def _setup_usrp2(self): from gnuradio import usrp2 self._u = usrp2.source_32fc(self._interface, self._mac_addr)
def __init__(self, options, rx_callback): gr.top_block.__init__(self) u = usrp2.source_32fc(options.interface, options.mac_addr) self.usrp_decim = 4 self.samples_per_symbol = 2 self.filter_decim = 5 self.resamp_interp = 4 self.resamp_decim = 5 self.data_rate = int(u.adc_rate() / self.samples_per_symbol / self.usrp_decim / self.filter_decim * self.resamp_interp / self.resamp_decim) self.sampling_rate = int(u.adc_rate() / self.usrp_decim) print "data_rate = ", eng_notation.num_to_str(self.data_rate) print "samples_per_symbol = ", self.samples_per_symbol print "usrp_decim = ", self.usrp_decim print "usrp2_gain = ", options.gain print "Squelch filter = ", options.squelch self.chan1_freq = ieee802_15_4_pkt.chan_802_15_4.chan_map[ options.channel1] self.chan1_num = options.channel1 self.chan2_num = self.chan1_num + 1 self.chan3_num = self.chan2_num + 1 self.chan4_num = self.chan3_num + 1 self.chan5_num = self.chan4_num + 1 self.chan5_freq = ieee802_15_4_pkt.chan_802_15_4.chan_map[ self.chan5_num] self.usrp_freq = (self.chan1_freq + self.chan5_freq) / 2 self.chan1_offset = self.usrp_freq - self.chan1_freq self.chan2_offset = self.chan1_offset - 5000000 self.chan3_offset = self.chan2_offset - 5000000 self.chan4_offset = self.chan3_offset - 5000000 self.chan5_offset = self.chan4_offset - 5000000 print "Centering USRP2 at = ", self.usrp_freq print "Channel ", self.chan1_num, " freq = ", self.usrp_freq - self.chan1_offset print "Channel ", self.chan2_num, " freq = ", self.usrp_freq - self.chan2_offset print "Channel ", self.chan3_num, " freq = ", self.usrp_freq - self.chan3_offset print "Channel ", self.chan4_num, " freq = ", self.usrp_freq - self.chan4_offset print "Channel ", self.chan5_num, " freq = ", self.usrp_freq - self.chan5_offset u.set_center_freq(self.usrp_freq) u.set_decim(self.usrp_decim) u.set_gain(options.gain) # Creating a filter for channel selection chan_coeffs = gr.firdes.low_pass( 1.0, # filter gain self.sampling_rate, # sampling rate 2e6, # cutoff frequency 2e6, # bandwidth gr.firdes.WIN_HANN) # filter type print "Length of chan_coeffs = ", len(chan_coeffs) # Decimating channel filters self.ddc1 = gr.freq_xlating_fir_filter_ccf( self.filter_decim, # decimation rate chan_coeffs, # taps self.chan1_offset, # frequency translation amount self.sampling_rate) # input sampling rate self.ddc2 = gr.freq_xlating_fir_filter_ccf( self.filter_decim, # decimation rate chan_coeffs, # taps self.chan2_offset, # frequency translation amount self.sampling_rate) # input sampling rate self.ddc3 = gr.fir_filter_ccf(self.filter_decim, chan_coeffs) self.ddc4 = gr.freq_xlating_fir_filter_ccf( self.filter_decim, # decimation rate chan_coeffs, # taps self.chan4_offset, # frequency translation amount self.sampling_rate) # input sampling rate self.ddc5 = gr.freq_xlating_fir_filter_ccf( self.filter_decim, # decimation rate chan_coeffs, # taps self.chan5_offset, # frequency translation amount self.sampling_rate) # input sampling rate self.packet_receiver1 = ieee802_15_4_pkt.ieee802_15_4_demod_pkts( self, callback=rx_callback, sps=self.samples_per_symbol, channel=self.chan1_num, threshold=-1) self.packet_receiver2 = ieee802_15_4_pkt.ieee802_15_4_demod_pkts( self, callback=rx_callback, sps=self.samples_per_symbol, channel=self.chan2_num, threshold=-1) self.packet_receiver3 = ieee802_15_4_pkt.ieee802_15_4_demod_pkts( self, callback=rx_callback, sps=self.samples_per_symbol, channel=self.chan3_num, threshold=-1) self.packet_receiver4 = ieee802_15_4_pkt.ieee802_15_4_demod_pkts( self, callback=rx_callback, sps=self.samples_per_symbol, channel=self.chan4_num, threshold=-1) self.packet_receiver5 = ieee802_15_4_pkt.ieee802_15_4_demod_pkts( self, callback=rx_callback, sps=self.samples_per_symbol, channel=self.chan5_num, threshold=-1) self.resampler1 = blks2.rational_resampler_ccf(self.resamp_interp, self.resamp_decim) self.resampler2 = blks2.rational_resampler_ccf(self.resamp_interp, self.resamp_decim) self.resampler3 = blks2.rational_resampler_ccf(self.resamp_interp, self.resamp_decim) self.resampler4 = blks2.rational_resampler_ccf(self.resamp_interp, self.resamp_decim) self.resampler5 = blks2.rational_resampler_ccf(self.resamp_interp, self.resamp_decim) self.u = u self.squelch = gr.pwr_squelch_cc(options.squelch, gate=True) self.connect(self.u, self.squelch) self.connect(self.squelch, self.ddc1, self.resampler1, self.packet_receiver1) self.connect(self.squelch, self.ddc2, self.resampler2, self.packet_receiver2) self.connect(self.squelch, self.ddc3, self.resampler3, self.packet_receiver3) self.connect(self.squelch, self.ddc4, self.resampler4, self.packet_receiver4) self.connect(self.squelch, self.ddc5, self.resampler5, self.packet_receiver5)
def __init__(self, options, filename): gr.top_block.__init__(self) # Create a USRP2 source if options.output_shorts: self._u = usrp2.source_16sc(options.interface, options.mac_addr) self._sink = gr.file_sink(gr.sizeof_short*2, filename) else: self._u = usrp2.source_32fc(options.interface, options.mac_addr) self._sink = gr.file_sink(gr.sizeof_gr_complex, filename) # Set receiver decimation rate self._u.set_decim(options.decim) # Set receive daughterboard gain if options.gain is None: g = self._u.gain_range() options.gain = float(g[0]+g[1])/2 print "Using mid-point gain of", options.gain, "(", g[0], "-", g[1], ")" self._u.set_gain(options.gain) # Set receive frequency if options.lo_offset is not None: self._u.set_lo_offset(options.lo_offset) tr = self._u.set_center_freq(options.freq) if tr == None: sys.stderr.write('Failed to set center frequency\n') raise SystemExit, 1 # Create head block if needed and wire it up if options.nsamples is None: self.connect(self._u, self._sink) else: if options.output_shorts: self._head = gr.head(gr.sizeof_short*2, int(options.nsamples)) else: self._head = gr.head(gr.sizeof_gr_complex, int(options.nsamples)) self.connect(self._u, self._head, self._sink) input_rate = self._u.adc_rate()/self._u.decim() if options.verbose: print "Network interface:", options.interface print "USRP2 address:", self._u.mac_addr() print "Using RX d'board id 0x%04X" % (self._u.daughterboard_id(),) print "Rx gain:", options.gain print "Rx baseband frequency:", n2s(tr.baseband_freq) print "Rx DDC frequency:", n2s(tr.dxc_freq) print "Rx residual frequency:", n2s(tr.residual_freq) print "Rx decimation rate:", options.decim print "Rx sample rate:", n2s(input_rate) if options.nsamples is None: print "Receiving samples until Ctrl-C" else: print "Receving", n2s(options.nsamples), "samples" if options.output_shorts: print "Writing 16-bit complex shorts" else: print "Writing 32-bit complex floats" print "Output filename:", filename
def __init__(self, interface, address, center_freq, offset_freq, decim, squelch, gain): gr.top_block.__init__(self) # setup USRP2 u = usrp2.source_32fc(interface, address) u.set_decim(decim) capture_rate = u.adc_rate() / decim u.set_center_freq(center_freq) if gain is None: g = u.gain_range() gain = float(g[0] + g[1]) / 2 u.set_gain(gain) # Setup receiver attributes channel_rate = 125000 symbol_rate = 4800 # channel filter self.channel_offset = offset_freq channel_decim = capture_rate // channel_rate channel_rate = capture_rate // channel_decim trans_width = 12.5e3 / 2; trans_centre = trans_width + (trans_width / 2) coeffs = gr.firdes.low_pass(1.0, capture_rate, trans_centre, trans_width, gr.firdes.WIN_HANN) self.channel_filter = gr.freq_xlating_fir_filter_ccf(channel_decim, coeffs, self.channel_offset, capture_rate) self.connect(u, self.channel_filter) # power squelch power_squelch = gr.pwr_squelch_cc(squelch, 1e-3, 0, True) self.connect(self.channel_filter, power_squelch) # FM demodulator self.symbol_deviation = 600.0 fm_demod_gain = channel_rate / (2.0 * pi * self.symbol_deviation) fm_demod = gr.quadrature_demod_cf(fm_demod_gain) self.connect(power_squelch, fm_demod) # symbol filter symbol_decim = 1 samples_per_symbol = channel_rate // symbol_rate symbol_coeffs = (1.0/samples_per_symbol,) * samples_per_symbol symbol_filter = gr.fir_filter_fff(symbol_decim, symbol_coeffs) self.connect(fm_demod, symbol_filter) # C4FM demodulator autotuneq = gr.msg_queue(2) self.demod_watcher = demod_watcher(autotuneq, self.adjust_channel_offset) demod_fsk4 = op25.fsk4_demod_ff(autotuneq, channel_rate, symbol_rate) self.connect(symbol_filter, demod_fsk4) # symbol slicer levels = [ -2.0, 0.0, 2.0, 4.0 ] slicer = op25.fsk4_slicer_fb(levels) self.connect(demod_fsk4, slicer) # frame decoder decoder = op25.decoder_bf() self.connect(slicer, decoder) # try to connect audio output device try: audio_sink = audio.sink(8000, "plughw:0,0", True) self.connect(decoder, audio_sink) except Exception: sink = gr.null_sink(gr.sizeof_float) self.connect(decoder, null);
def __init__(self,frame,panel,vbox,argv): stdgui2.std_top_block.__init__ (self,frame,panel,vbox,argv) parser = OptionParser(option_class=eng_option) parser.add_option("-e", "--interface", type="string", default="eth0", help="select Ethernet interface, default is eth0") parser.add_option("-m", "--mac-addr", type="string", default="", help="select USRP by MAC address, default is auto-select") #parser.add_option("-A", "--antenna", default=None, # help="select Rx Antenna (only on RFX-series boards)") parser.add_option("-f", "--freq", type="eng_float", default=100.1, help="set frequency to FREQ", metavar="FREQ") parser.add_option("-g", "--gain", type="eng_float", default=None, help="set gain in dB (default is midpoint)") parser.add_option("-V", "--volume", type="eng_float", default=None, help="set volume (default is midpoint)") parser.add_option("-O", "--audio-output", type="string", default="", help="pcm device name. E.g., hw:0,0 or surround51 or /dev/dsp") (options, args) = parser.parse_args() if len(args) != 0: parser.print_help() sys.exit(1) self.frame = frame self.panel = panel self.vol = 0 self.state = "FREQ" self.freq = 0 # build graph self.u = usrp2.source_32fc(options.interface, options.mac_addr) adc_rate = self.u.adc_rate() # 100 MS/s usrp_decim = 312 self.u.set_decim(usrp_decim) usrp_rate = adc_rate / usrp_decim # ~320 kS/s chanfilt_decim = 1 demod_rate = usrp_rate / chanfilt_decim audio_decimation = 10 audio_rate = demod_rate / audio_decimation # ~32 kHz #FIXME: need named constants and text descriptions available to (gr-)usrp2 even #when usrp(1) module is not built. A usrp_common module, perhaps? dbid = self.u.daughterboard_id() print "Using RX d'board 0x%04X" % (dbid,) if not (dbid == 0x0001 or #usrp_dbid.BASIC_RX dbid == 0x0003 or #usrp_dbid.TV_RX dbid == 0x000c or #usrp_dbid.TV_RX_REV_2 dbid == 0x0040 or #usrp_dbid.TV_RX_REV_3 dbid == 0x0043 or #usrp_dbid.TV_RX_MIMO dbid == 0x0044 or #usrp_dbid.TV_RX_REV_2_MIMO dbid == 0x0045 ): #usrp_dbid.TV_RX_REV_3_MIMO print "This daughterboard does not cover the required frequency range" print "for this application. Please use a BasicRX or TVRX daughterboard." raw_input("Press ENTER to continue anyway, or Ctrl-C to exit.") chan_filt_coeffs = optfir.low_pass (1, # gain usrp_rate, # sampling rate 80e3, # passband cutoff 115e3, # stopband cutoff 0.1, # passband ripple 60) # stopband attenuation #print len(chan_filt_coeffs) chan_filt = gr.fir_filter_ccf (chanfilt_decim, chan_filt_coeffs) self.guts = blks2.wfm_rcv (demod_rate, audio_decimation) self.volume_control = gr.multiply_const_ff(self.vol) # sound card as final sink audio_sink = audio.sink (int (audio_rate), options.audio_output, False) # ok_to_block # now wire it all together self.connect (self.u, chan_filt, self.guts, self.volume_control, audio_sink) self._build_gui(vbox, usrp_rate, demod_rate, audio_rate) if options.gain is None: # if no gain was specified, use the mid-point in dB g = self.u.gain_range() options.gain = float(g[0]+g[1])/2 if options.volume is None: g = self.volume_range() options.volume = float(g[0]+g[1])/2 if abs(options.freq) < 1e6: options.freq *= 1e6 # set initial values self.set_gain(options.gain) self.set_vol(options.volume) if not(self.set_freq(options.freq)): self._set_status_msg("Failed to set initial frequency")
def __init__(self): gr.top_block.__init__(self) usage = "usage: %prog [options] min_freq max_freq" parser = OptionParser(option_class=eng_option, usage=usage) parser.add_option("-R", "--rx-subdev-spec", type="subdev", default=(0,0), help="select USRP Rx side A or B (default=A)") parser.add_option("-g", "--gain", type="eng_float", default=None, help="set gain in dB (default is midpoint)") parser.add_option("", "--tune-delay", type="eng_float", default=1e-4, metavar="SECS", help="time to delay (in seconds) after changing frequency [default=%default]") parser.add_option("", "--dwell-delay", type="eng_float", default=1e-3, metavar="SECS", help="time to dwell (in seconds) at a given frequncy [default=%default]") parser.add_option("-F", "--fft-size", type="int", default=256, help="specify number of FFT bins [default=%default]") parser.add_option("-d", "--decim", type="intx", default=16, help="set decimation to DECIM [default=%default]") parser.add_option("", "--real-time", action="store_true", default=False, help="Attempt to enable real-time scheduling") parser.add_option("-f", "--freq", type="eng_float", default = 5.2e9, help="set USRP2 carrier frequency, [default=%default]", metavar="FREQ") (options, args) = parser.parse_args() #if len(args) != 2: #parser.print_help() #sys.exit(1) #self.min_freq = eng_notation.str_to_num(args[0]) #self.max_freq = eng_notation.str_to_num(args[1]) self.min_freq = options.freq self.max_freq = options.freq if self.min_freq > self.max_freq: self.min_freq, self.max_freq = self.max_freq, self.min_freq # swap them self.fft_size = options.fft_size if not options.real_time: realtime = False else: # Attempt to enable realtime scheduling r = gr.enable_realtime_scheduling() if r == gr.RT_OK: realtime = True else: realtime = False print "Note: failed to enable realtime scheduling" #build graph self.u = usrp2.source_32fc() adc_rate = self.u.adc_rate() # 64 MS/s usrp2_decim = options.decim self.u.set_decim(usrp2_decim) usrp2_rate = adc_rate / usrp2_decim #self.u.set_mux(usrp.determine_rx_mux_value(self.u, options.rx_subdev_spec)) #self.subdev = usrp.selected_subdev(self.u, options.rx_subdev_spec) #print "Using RX d'board %s" % (self.subdev.side_and_name(),) s2v = gr.stream_to_vector(gr.sizeof_gr_complex, self.fft_size) mywindow = window.blackmanharris(self.fft_size) fft = gr.fft_vcc(self.fft_size, True, mywindow) power = 0 for tap in mywindow: power += tap*tap c2mag = gr.complex_to_mag_squared(self.fft_size) # FIXME the log10 primitive is dog slow log = gr.nlog10_ff(10, self.fft_size, -20*math.log10(self.fft_size)-10*math.log10(power/self.fft_size)) # Set the freq_step to 75% of the actual data throughput. # This allows us to discard the bins on both ends of the spectrum. self.freq_step = 0.75 * usrp2_rate self.min_center_freq = self.min_freq + self.freq_step/2 nsteps = math.ceil((self.max_freq - self.min_freq) / self.freq_step) self.max_center_freq = self.min_center_freq + (nsteps * self.freq_step) self.next_freq = self.min_center_freq tune_delay = max(0, int(round(options.tune_delay * usrp2_rate / self.fft_size))) # in fft_frames dwell_delay = max(1, int(round(options.dwell_delay * usrp2_rate / self.fft_size))) # in fft_frames self.msgq = gr.msg_queue(16) self._tune_callback = tune(self) # hang on to this to keep it from being GC'd stats = gr.bin_statistics_f(self.fft_size, self.msgq, self._tune_callback, tune_delay, dwell_delay) # FIXME leave out the log10 until we speed it up #self.connect(self.u, s2v, fft, c2mag, log, stats) self.connect(self.u, s2v, fft, c2mag, stats) if options.gain is None: # if no gain was specified, use the mid-point in dB g = self.u.gain_range() #options.gain = float(g[0]+g[1])/2 options.gain = max(min(options.gain, g[1]), g[0] ) self.u.set_gain(options.gain)
def __init__(self): gr.top_block.__init__(self) parser = OptionParser(option_class=eng_option) parser.add_option("-e", "--interface", type="string", default="eth0", help="select Ethernet interface, default is eth0") parser.add_option( "-m", "--mac-addr", type="string", default="", help="select USRP by MAC address, default is auto-select") parser.add_option("-W", "--bw", type="eng_float", default=1e6, help="set bandwidth of receiver [default=%default]") parser.add_option("-f", "--freq", type="eng_float", default=2412e6, help="set frequency to FREQ", metavar="FREQ") parser.add_option("-g", "--gain", type="eng_float", default=None, help="set gain in dB (default is midpoint)") parser.add_option("--fft-size", type="int", default=2048, help="Set number of FFT bins [default=%default]") (options, args) = parser.parse_args() if len(args) != 0: parser.print_help() sys.exit(1) self.options = options self.show_debug_info = True self.qapp = QtGui.QApplication(sys.argv) self.u = usrp2.source_32fc(options.interface, options.mac_addr) self._adc_rate = self.u.adc_rate() self.set_bandwidth(options.bw) if options.gain is None: # if no gain was specified, use the mid-point in dB g = self.u.gain_range() options.gain = float(g[0] + g[1]) / 2 self.set_gain(options.gain) if options.freq is None: # if no frequency was specified, use the mid-point of the subdev f = self.u.freq_range() options.freq = float(f[0] + f[1]) / 2 self.set_frequency(options.freq) self._fftsize = options.fft_size self.snk = qtgui.sink_c(options.fft_size, gr.firdes.WIN_BLACKMAN_hARRIS, self._freq, self._bandwidth, "USRP2 Display", True, True, True, False) # Set up internal amplifier self.amp = gr.multiply_const_cc(0.0) self.set_amplifier_gain(100) # Create a single-pole IIR filter to remove DC # but don't connect it yet self.dc_gain = 0.001 self.dc = gr.single_pole_iir_filter_cc(self.dc_gain) self.dc_sub = gr.sub_cc() self.connect(self.u, self.amp, self.snk) if self.show_debug_info: print "Decimation rate: ", self._decim print "Bandwidth: ", self._bandwidth print "D'board: ", self.u.daughterboard_id() # Get the reference pointer to the SpectrumDisplayForm QWidget # Wrap the pointer as a PyQt SIP object # This can now be manipulated as a PyQt4.QtGui.QWidget self.pysink = sip.wrapinstance(self.snk.pyqwidget(), QtGui.QWidget) self.main_win = main_window(self.pysink, self) self.main_win.set_frequency(self._freq) self.main_win.set_gain(self._gain) self.main_win.set_bandwidth(self._bandwidth) self.main_win.set_amplifier(self._amp_value) self.main_win.show()
def __init__(self, options, rx_callback): gr.top_block.__init__(self) u = usrp2.source_32fc(options.interface, options.mac_addr) self.usrp_decim = 4 self.samples_per_symbol = 2 self.filter_decim = 5 self.resamp_interp = 4 self.resamp_decim = 5 self.data_rate = int (u.adc_rate() / self.samples_per_symbol / self.usrp_decim / self.filter_decim * self.resamp_interp / self.resamp_decim) self.sampling_rate = int (u.adc_rate() / self.usrp_decim) print "data_rate = ", eng_notation.num_to_str(self.data_rate) print "samples_per_symbol = ", self.samples_per_symbol print "usrp_decim = ", self.usrp_decim print "usrp2_gain = ", options.gain print "Squelch filter = ", options.squelch self.chan1_freq = ieee802_15_4_pkt.chan_802_15_4.chan_map[options.channel1] self.chan1_num = options.channel1 self.chan2_num = self.chan1_num + 1 self.chan3_num = self.chan2_num + 1 self.chan4_num = self.chan3_num + 1 self.chan5_num = self.chan4_num + 1 self.chan5_freq = ieee802_15_4_pkt.chan_802_15_4.chan_map[self.chan5_num] self.usrp_freq = (self.chan1_freq + self.chan5_freq) / 2 self.chan1_offset = self.usrp_freq - self.chan1_freq self.chan2_offset = self.chan1_offset - 5000000 self.chan3_offset = self.chan2_offset - 5000000 self.chan4_offset = self.chan3_offset - 5000000 self.chan5_offset = self.chan4_offset - 5000000 print "Centering USRP2 at = ", self.usrp_freq print "Channel ", self.chan1_num, " freq = ", self.usrp_freq - self.chan1_offset print "Channel ", self.chan2_num, " freq = ", self.usrp_freq - self.chan2_offset print "Channel ", self.chan3_num, " freq = ", self.usrp_freq - self.chan3_offset print "Channel ", self.chan4_num, " freq = ", self.usrp_freq - self.chan4_offset print "Channel ", self.chan5_num, " freq = ", self.usrp_freq - self.chan5_offset u.set_center_freq(self.usrp_freq) u.set_decim(self.usrp_decim) u.set_gain(options.gain) # Creating a filter for channel selection chan_coeffs = gr.firdes.low_pass( 1.0, # filter gain self.sampling_rate, # sampling rate 2e6, # cutoff frequency 2e6, # bandwidth gr.firdes.WIN_HANN) # filter type print "Length of chan_coeffs = ", len(chan_coeffs) # Decimating channel filters self.ddc1 = gr.freq_xlating_fir_filter_ccf( self.filter_decim, # decimation rate chan_coeffs, # taps self.chan1_offset, # frequency translation amount self.sampling_rate) # input sampling rate self.ddc2 = gr.freq_xlating_fir_filter_ccf( self.filter_decim, # decimation rate chan_coeffs, # taps self.chan2_offset, # frequency translation amount self.sampling_rate) # input sampling rate self.ddc3 = gr.fir_filter_ccf(self.filter_decim, chan_coeffs) self.ddc4 = gr.freq_xlating_fir_filter_ccf( self.filter_decim, # decimation rate chan_coeffs, # taps self.chan4_offset, # frequency translation amount self.sampling_rate) # input sampling rate self.ddc5 = gr.freq_xlating_fir_filter_ccf( self.filter_decim, # decimation rate chan_coeffs, # taps self.chan5_offset, # frequency translation amount self.sampling_rate) # input sampling rate self.packet_receiver1 = ieee802_15_4_pkt.ieee802_15_4_demod_pkts( self, callback=rx_callback, sps=self.samples_per_symbol, channel=self.chan1_num, threshold=-1) self.packet_receiver2 = ieee802_15_4_pkt.ieee802_15_4_demod_pkts( self, callback=rx_callback, sps=self.samples_per_symbol, channel=self.chan2_num, threshold=-1) self.packet_receiver3 = ieee802_15_4_pkt.ieee802_15_4_demod_pkts( self, callback=rx_callback, sps=self.samples_per_symbol, channel=self.chan3_num, threshold=-1) self.packet_receiver4 = ieee802_15_4_pkt.ieee802_15_4_demod_pkts( self, callback=rx_callback, sps=self.samples_per_symbol, channel=self.chan4_num, threshold=-1) self.packet_receiver5 = ieee802_15_4_pkt.ieee802_15_4_demod_pkts( self, callback=rx_callback, sps=self.samples_per_symbol, channel=self.chan5_num, threshold=-1) self.resampler1 = blks2.rational_resampler_ccf(self.resamp_interp,self.resamp_decim) self.resampler2 = blks2.rational_resampler_ccf(self.resamp_interp,self.resamp_decim) self.resampler3 = blks2.rational_resampler_ccf(self.resamp_interp,self.resamp_decim) self.resampler4 = blks2.rational_resampler_ccf(self.resamp_interp,self.resamp_decim) self.resampler5 = blks2.rational_resampler_ccf(self.resamp_interp,self.resamp_decim) self.u = u self.squelch = gr.pwr_squelch_cc(options.squelch, gate=True) self.connect(self.u,self.squelch) self.connect(self.squelch, self.ddc1, self.resampler1, self.packet_receiver1) self.connect(self.squelch, self.ddc2, self.resampler2, self.packet_receiver2) self.connect(self.squelch, self.ddc3, self.resampler3, self.packet_receiver3) self.connect(self.squelch, self.ddc4, self.resampler4, self.packet_receiver4) self.connect(self.squelch, self.ddc5, self.resampler5, self.packet_receiver5)