def __init__(self, options, rx_callback): phy_base.__init__(self, options, rx_callback) # Receive chain demod_class = phy_psk.DEMODS[options.psk_modulation] demod_kwargs = demod_class.extract_kwargs_from_options(options) self._rx_demod = blks2.demod_pkts( demod_class(**demod_kwargs), callback=self._rx_callback) sw_decim = 1 self._rx_chan_filt = gr.fft_filter_ccc( sw_decim, gr.firdes.low_pass ( 1.0, # gain sw_decim * self._rx_demod._demodulator.samples_per_symbol(), # sampling rate 1.0, # midpoint of trans. band 0.5, # width of trans. band gr.firdes.WIN_HANN)) # filter type self.connect(self, self._rx_chan_filt, self._rx_demod) # Trasmit chain mod_class = phy_psk.MODS[options.psk_modulation] mod_kwargs = mod_class.extract_kwargs_from_options(options) self._tx_mod = blks2.mod_pkts( mod_class(**mod_kwargs), pad_for_usrp=True) self.connect(self._tx_mod, gr.kludge_copy(gr.sizeof_gr_complex), self)
def __init__(self, demod_class, rx_callback, options): gr.hier_block2.__init__( self, "receive_path", gr.io_signature(1, 1, gr.sizeof_gr_complex), # Input signature gr.io_signature(0, 0, 0)) # Output signature options = copy.copy( options) # make a copy so we can destructively modify self._verbose = options.verbose self._bitrate = options.bitrate # desired bit rate self._samples_per_symbol = options.samples_per_symbol # desired samples/symbol self._rx_callback = rx_callback # this callback is fired when there's a packet available self._demod_class = demod_class # the demodulator_class we're using # Get demod_kwargs demod_kwargs = self._demod_class.extract_kwargs_from_options(options) # Design filter to get actual channel we want sw_decim = 1 chan_coeffs = gr.firdes.low_pass( 1.0, # gain sw_decim * self._samples_per_symbol, # sampling rate 1.0, # midpoint of trans. band 0.5, # width of trans. band gr.firdes.WIN_HANN) # filter type self.channel_filter = gr.fft_filter_ccc(sw_decim, chan_coeffs) # receiver self.packet_receiver = \ blks2.demod_pkts(self._demod_class(**demod_kwargs), access_code=None, callback=self._rx_callback, threshold=-1) # Carrier Sensing Blocks alpha = 0.001 thresh = 30 # in dB, will have to adjust self.probe = gr.probe_avg_mag_sqrd_c(thresh, alpha) # Display some information about the setup if self._verbose: self._print_verbage() # connect block input to channel filter self.connect(self, self.channel_filter) # connect the channel input filter to the carrier power detector self.connect(self.channel_filter, self.probe) # connect channel filter to the packet receiver self.connect(self.channel_filter, self.packet_receiver)
def __init__(self, demod_class, rx_callback, options): gr.hier_block2.__init__(self, "receive_path", gr.io_signature(1, 1, gr.sizeof_gr_complex), # Input signature gr.io_signature(0, 0, 0)) # Output signature options = copy.copy(options) # make a copy so we can destructively modify self._verbose = options.verbose self._bitrate = options.bitrate # desired bit rate self._samples_per_symbol = options.samples_per_symbol # desired samples/symbol self._rx_callback = rx_callback # this callback is fired when there's a packet available self._demod_class = demod_class # the demodulator_class we're using # Get demod_kwargs demod_kwargs = self._demod_class.extract_kwargs_from_options(options) # Design filter to get actual channel we want sw_decim = 1 chan_coeffs = gr.firdes.low_pass (1.0, # gain sw_decim * self._samples_per_symbol, # sampling rate 1.0, # midpoint of trans. band 0.5, # width of trans. band gr.firdes.WIN_HANN) # filter type self.channel_filter = gr.fft_filter_ccc(sw_decim, chan_coeffs) # receiver self.packet_receiver = \ blks2.demod_pkts(self._demod_class(**demod_kwargs), access_code=None, callback=self._rx_callback, threshold=-1) # Carrier Sensing Blocks alpha = 0.001 thresh = 30 # in dB, will have to adjust self.probe = gr.probe_avg_mag_sqrd_c(thresh,alpha) # Display some information about the setup if self._verbose: self._print_verbage() # connect block input to channel filter self.connect(self, self.channel_filter) # connect the channel input filter to the carrier power detector self.connect(self.channel_filter, self.probe) # connect channel filter to the packet receiver self.connect(self.channel_filter, self.packet_receiver)
def __init__(self, inputfile, callback, options): gr.top_block.__init__(self) # settings for the demodulator: /usr/local/lib/python2.5/site-packages/gnuradio/blks2impl/gmsk.py # settings for the demodulator: /usr/local/lib/python2.5/site-packages/gnuradio/blks2impl/pkt.py if options.dsp: self.src = audio.source(options.dsp_sample_rate, "", True) else: self.src = gr.wavfile_source( inputfile, False ) self.iq_to_c = gr.float_to_complex() if options.dsp and options.wait: samples = options.dsp_sample_rate * options.wait self._head0 = gr.head(gr.sizeof_float, samples) self._head1 = gr.head(gr.sizeof_float, samples) self.connect( (self.src, 0), self._head0, (self.iq_to_c, 0) ) self.connect( (self.src, 1), self._head1, (self.iq_to_c, 1) ) if verbose: print "installed %d second head filter on dsp (%d samples at %d sps)" % (options.wait, samples, options.dsp_sample_rate) else: self.connect( (self.src, 0), (self.iq_to_c, 0) ) self.connect( (self.src, 1), (self.iq_to_c, 1) ) self.demodulator = blks2.gmsk_demod(samples_per_symbol=options.samples_per_symbol) self.pkt_queue = blks2.demod_pkts( demodulator=self.demodulator, callback=callback, threshold=options.threshold ) if options.carrier_frequency == 0: self.mixer = self.iq_to_c else: self.carrier = gr.sig_source_c( options.carrier_sample_rate, gr.GR_SIN_WAVE, - options.carrier_frequency, 1.0 ) self.mixer = gr.multiply_vcc(1) self.connect(self.iq_to_c, (self.mixer, 0) ) self.connect(self.carrier, (self.mixer, 1) ) self.amp = gr.multiply_const_cc(1); self.amp.set_k(options.amp_amplitude) self.connect(self.mixer, self.amp, self.pkt_queue) if options.debug_wavs: from myblks import debugwav self._dpass = debugwav("rx_passband", options) self._dbase = debugwav("rx_baseband", options) self.connect(self.iq_to_c, self._dpass) self.connect(self.mixer, self._dbase) if options.debug_files: self._dpassf = gr.file_sink(gr.sizeof_gr_complex*1, "debug_rx_passband.d_c") self._dbasef = gr.file_sink(gr.sizeof_gr_complex*1, "debug_rx_baseband.d_c") self.connect(self.iq_to_c, self._dpassf) self.connect(self.mixer, self._dbasef)
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 __init__(self, demod_class, rx_callback, options): gr.hier_block2.__init__(self, "receive_path", gr.io_signature(0, 0, 0), # Input signature gr.io_signature(0, 0, 0)) # Output signature options = copy.copy(options) # make a copy so we can destructively modify self._verbose = options.verbose self._rx_freq = options.rx_freq # receiver's center frequency self._rx_gain = options.rx_gain # receiver's gain self._rx_subdev_spec = options.rx_subdev_spec # daughterboard to use self._bitrate = options.bitrate # desired bit rate self._decim = options.decim # Decimating rate for the USRP (prelim) self._samples_per_symbol = options.samples_per_symbol # desired samples/symbol self._fusb_block_size = options.fusb_block_size # usb info for USRP self._fusb_nblocks = options.fusb_nblocks # usb info for USRP self._rx_callback = rx_callback # this callback is fired when there's a packet available self._demod_class = demod_class # the demodulator_class we're using if self._rx_freq is None: sys.stderr.write("-f FREQ or --freq FREQ or --rx-freq FREQ must be specified\n") raise SystemExit # Set up USRP source; also adjusts decim, samples_per_symbol, and bitrate self._setup_usrp_source() g = self.subdev.gain_range() if options.show_rx_gain_range: print "Rx Gain Range: minimum = %g, maximum = %g, step size = %g" \ % (g[0], g[1], g[2]) self.set_gain(options.rx_gain) self.set_auto_tr(True) # enable Auto Transmit/Receive switching # Set RF frequency ok = self.set_freq(self._rx_freq) if not ok: print "Failed to set Rx frequency to %s" % (eng_notation.num_to_str(self._rx_freq)) raise ValueError, eng_notation.num_to_str(self._rx_freq) # copy the final answers back into options for use by demodulator options.samples_per_symbol = self._samples_per_symbol options.bitrate = self._bitrate options.decim = self._decim # Get demod_kwargs demod_kwargs = self._demod_class.extract_kwargs_from_options(options) # Design filter to get actual channel we want sw_decim = 1 chan_coeffs = gr.firdes.low_pass (1.0, # gain sw_decim * self._samples_per_symbol, # sampling rate 1.0, # midpoint of trans. band 0.5, # width of trans. band gr.firdes.WIN_HANN) # filter type # Decimating channel filter # complex in and out, float taps self.chan_filt = gr.fft_filter_ccc(sw_decim, chan_coeffs) #self.chan_filt = gr.fir_filter_ccf(sw_decim, chan_coeffs) # receiver self.packet_receiver = \ blks2.demod_pkts(self._demod_class(**demod_kwargs), access_code=None, callback=self._rx_callback, threshold=-1) # Carrier Sensing Blocks alpha = 0.001 thresh = 30 # in dB, will have to adjust self.sequelcher = gr.simple_squelch_cc(45) if options.log_rx_power == True: self.probe = gr.probe_avg_mag_sqrd_cf(thresh,alpha) self.power_sink = gr.file_sink(gr.sizeof_float, "rxpower.dat") self.connect(self.chan_filt, self.probe, self.power_sink) else: self.probe = gr.probe_avg_mag_sqrd_c(thresh,alpha) #self.connect(self.chan_filt, self.sequelcher, self.probe) # Display some information about the setup if self._verbose: self._print_verbage() #filter the noise and pass only the transmitted data #file_source = gr.file_source(gr.sizeof_gr_complex,"modulated_data.dat") #self.connect(self.chan_filt,file_sink) self.connect(self.u, self.chan_filt,self.sequelcher, self.packet_receiver)
def __init__(self, demod_class, rx_callback, options): gr.hier_block2.__init__( self, "receive_path", gr.io_signature(0, 0, 0), # Input signature gr.io_signature(0, 0, 0)) # Output signature options = copy.copy( options) # make a copy so we can destructively modify self._which = options.which # the USRP board attached self._verbose = options.verbose self._rx_freq = options.rx_freq # receiver's center frequency self._rx_gain = options.rx_gain # receiver's gain self._rx_subdev_spec = options.rx_subdev_spec # daughterboard to use self._bitrate = options.bitrate # desired bit rate self._decim = options.decim # Decimating rate for the USRP (prelim) self._samples_per_symbol = options.samples_per_symbol # desired samples/symbol self._fusb_block_size = options.fusb_block_size # usb info for USRP self._fusb_nblocks = options.fusb_nblocks # usb info for USRP self._rx_callback = rx_callback # this callback is fired when there's a packet available self._demod_class = demod_class # the demodulator_class we're using if self._rx_freq is None: sys.stderr.write( "-f FREQ or --freq FREQ or --rx-freq FREQ must be specified\n") raise SystemExit # Set up USRP source; also adjusts decim, samples_per_symbol, and bitrate self._setup_usrp_source() g = self.subdev.gain_range() if options.show_rx_gain_range: print "Rx Gain Range: minimum = %g, maximum = %g, step size = %g" \ % (g[0], g[1], g[2]) self.set_gain(options.rx_gain) self.set_auto_tr(True) # enable Auto Transmit/Receive switching # Set RF frequency ok = self.set_freq(self._rx_freq) if not ok: print "Failed to set Rx frequency to %s" % ( eng_notation.num_to_str(self._rx_freq)) raise ValueError, eng_notation.num_to_str(self._rx_freq) # copy the final answers back into options for use by demodulator options.samples_per_symbol = self._samples_per_symbol options.bitrate = self._bitrate options.decim = self._decim # Get demod_kwargs demod_kwargs = self._demod_class.extract_kwargs_from_options(options) # Design filter to get actual channel we want sw_decim = 1 chan_coeffs = gr.firdes.low_pass( 1.0, # gain sw_decim * self._samples_per_symbol, # sampling rate 1.0, # midpoint of trans. band 0.5, # width of trans. band gr.firdes.WIN_HANN) # filter type # Decimating channel filter # complex in and out, float taps self.chan_filt = gr.fft_filter_ccc(sw_decim, chan_coeffs) #self.chan_filt = gr.fir_filter_ccf(sw_decim, chan_coeffs) # receiver self.packet_receiver = \ blks2.demod_pkts(self._demod_class(**demod_kwargs), access_code=None, callback=self._rx_callback, threshold=-1) # Carrier Sensing Blocks alpha = 0.001 thresh = 30 # in dB, will have to adjust if options.log_rx_power == True: self.probe = gr.probe_avg_mag_sqrd_cf(thresh, alpha) self.power_sink = gr.file_sink(gr.sizeof_float, "rxpower.dat") self.connect(self.chan_filt, self.probe, self.power_sink) else: self.probe = gr.probe_avg_mag_sqrd_c(thresh, alpha) self.connect(self.chan_filt, self.probe) # Display some information about the setup if self._verbose: self._print_verbage() self.connect(self.u, self.chan_filt, self.packet_receiver)