def __init__(self, callback, options): gr.top_block.__init__(self) self.source = uhd_receiver( options.args, options.bandwidth, options.rx_freq, options.rx_gain, options.spec, options.antenna, options.verbose, ) self.sink = uhd_transmitter( options.args, options.bandwidth, options.tx_freq, options.tx_gain, options.spec, options.antenna, options.verbose, ) self.txpath = transmit_path(options) self.rxpath = receive_path(callback, options) self.connect(self.txpath, self.sink) self.connect(self.source, self.rxpath)
def __init__(self, options): gr.top_block.__init__(self) if options.outfile is not None: u = gr.file_sink(gr.sizeof_gr_complex, options.outfile) elif (options.tx_freq is not None) or (options.channel is not None): if options.channel is not None: self.chan_num = options.channel options.tx_freq = ieee802_15_4_pkt.chan_802_15_4.chan_map[self.chan_num] u = uhd_transmitter(options.tx_args, options.bandwidth, options.tx_freq, options.tx_gain, options.spec, options.antenna, options.verbose, options.external) else: raise SystemExit("--tx-freq, --channel or --outfile must be specified\n") self.samples_per_symbol = 2 # transmitter self.packet_transmitter = ieee802_15_4_pkt.ieee802_15_4_mod_pkts(self, spb=self.samples_per_symbol, msgq_limit=2, log=options.log) self.amp = gr.multiply_const_cc(1) self.u = u self.connect(self.packet_transmitter, self.amp, self.u) self.connect(self.amp, gr.file_sink(gr.sizeof_gr_complex, 'cc2420-tx-diag.dat'))
def __init__(self, options, payload=''): gr.top_block.__init__(self) if(options.tx_freq is not None): self.sink = uhd_transmitter(options.args, options.bandwidth, options.tx_freq, options.tx_gain, options.spec, options.antenna, options.verbose) elif(options.to_file is not None): self.sink = gr.file_sink(gr.sizeof_gr_complex, options.to_file) else: self.sink = gr.null_sink(gr.sizeof_gr_complex) options.interp = 100e6/options.bandwidth # FTW-specific convertion # do this after for any adjustments to the options that may # occur in the sinks (specifically the UHD sink) if(options.from_file is None): self.txpath = ftw_transmit_path(options, payload) else: self.txpath = gr.file_source(gr.sizeof_gr_complex, options.from_file); # options.tx_amplitude = 1 # static value to make sure we do not exceed +-1 for the floats being sent to the sink self._tx_amplitude = options.tx_amplitude self.amp = gr.multiply_const_cc(self._tx_amplitude) # self.txpath = ftw_pnc_transmit_path(options, payload) self.connect(self.txpath, self.amp, self.sink) if options.log: self.connect(self.txpath, gr.file_sink(gr.sizeof_gr_complex, 'ftw_benchmark.dat'))
def __init__(self, modulator_class, options): gr.top_block.__init__(self) self.txpath = transmit_path(modulator_class, options) self.audio_rx = audio_rx(options.audio_input) if(options.tx_freq is not None): self.sink = uhd_transmitter(options.address, options.bitrate, options.samples_per_symbol, options.tx_freq, options.tx_gain, options.antenna, options.verbose) options.samples_per_symbol = self.sink._sps audio_rate = self.audio_rx.sample_rate usrp_rate = self.sink.get_sample_rate() rrate = usrp_rate / audio_rate elif(options.to_file is not None): self.sink = blocks.file_sink(gr.sizeof_gr_complex, options.to_file) rrate = 1 else: self.sink = blocks.null_sink(gr.sizeof_gr_complex) rrate = 1 self.resampler = filter.pfb.arb_resampler_ccf(rrate) self.connect(self.audio_rx) self.connect(self.txpath, self.resampler, self.sink)
def __init__(self, modulator, options): # Get options from call, modulator and options gr.top_block.__init__(self) if (options.tx_freq is not None): # Work-around to get the modulation's bits_per_symbol args = modulator.extract_kwargs_from_options(options) symbol_rate = options.bitrate / modulator(**args).bits_per_symbol() self.sink = uhd_transmitter(options.args, symbol_rate, options.samples_per_symbol, options.tx_freq, options.tx_gain, options.spec, options.antenna, options.verbose) options.samples_per_symbol = self.sink._sps elif (options.to_file is not None): sys.stderr.write( ("Saving samples to '%s'.\n\n" % (options.to_file))) self.sink = gr.file_sink(gr.sizeof_gr_complex, options.to_file) else: sys.stderr.write( "No sink defined, dumping samples to null sink.\n\n") self.sink = gr.null_sink(gr.sizeof_gr_complex) # do this after for any adjustments to the options that may # occur in the sinks (specifically the UHD sink) # Pass options to transmitter, setup transmitter, pass to pointer self.txpath self.txpath = transmit_path(modulator, options) # Connect and construct flowgraph self.connect( self.txpath, self.sink) #--> back to main, to enable realtime scheduling
def __init__(self, mod_class, demod_class, rx_callback, options): gr.top_block.__init__(self) # Get the modulation's bits_per_symbol args = mod_class.extract_kwargs_from_options(options) symbol_rate = options.bitrate / mod_class(**args).bits_per_symbol() self.source = uhd_receiver(options.args, symbol_rate, options.samples_per_symbol, options.rx_freq, options.rx_gain, options.spec, options.antenna, options.verbose) self.sink = uhd_transmitter(options.args, symbol_rate, options.samples_per_symbol, options.tx_freq, options.tx_gain, options.spec, options.antenna, options.verbose) options.samples_per_symbol = self.source._sps self.txpath = transmit_path(mod_class, options) self.rxpath = receive_path(demod_class, rx_callback, options) self.connect(self.txpath, self.sink) self.connect(self.source, self.rxpath)
def __init__(self, options, options_vr1, options_vr2): gr.top_block.__init__(self) if (options.file_sink is False): print("Using USRP") self.sink = uhd_transmitter(options.args, options.bandwidth, options.tx_freq, options.lo_offset, options.tx_gain, options.spec, options.antenna, options.clock_source, options.verbose) else: self.sink = blocks.null_sink(gr.sizeof_gr_complex) vr_configs = [] vr_configs.append([options_vr1.freq, options_vr1.bandwidth]) vr_configs.append([options_vr2.freq, options_vr2.bandwidth]) hydra_sink = hydra.hydra_sink(2, options.fft_length, int(options.tx_freq), int(options.bandwidth), vr_configs) self.vr1_source = zeromq.pull_source(gr.sizeof_gr_complex, 1, 'tcp://192.168.122.56:4000', 100, False, -1) self.vr2_source = zeromq.pull_source(gr.sizeof_gr_complex, 1, 'tcp://192.168.122.208:4001', 100, False, -1) self.connect(self.vr1_source, (hydra_sink, 0), self.sink) self.connect(self.vr2_source, (hydra_sink, 1)) self.hydra = hydra_sink self.xmlrpc_server = SimpleXMLRPCServer.SimpleXMLRPCServer( ("localhost", 12345), allow_none=True) self.xmlrpc_server.register_instance(self) threading.Thread(target=self.xmlrpc_server.serve_forever).start()
def _setup_sink(self, options): self.symbol_rate=2; #for bpsk will edit the code later to set this automaticly based on the selected modulation scheme self.sink = uhd_transmitter(options.args, self.symbol_rate, options.samples_per_symbol, options.tx_freq, options.tx_gain, options.spec, options.antenna, options.verbose)
def __init__(self, modulator, options): gr.top_block.__init__(self) if(options.tx_freq is not None): # Work-around to get the modulation's bits_per_symbol args = modulator.extract_kwargs_from_options(options) symbol_rate = options.bitrate / modulator(**args).bits_per_symbol() self.sink = uhd_transmitter(options.args, symbol_rate, options.samples_per_symbol, options.tx_freq, options.tx_gain, options.spec, options.antenna, options.verbose) options.samples_per_symbol = self.sink._sps elif(options.to_file is not None): sys.stderr.write(("Saving samples to '%s'.\n\n" % (options.to_file))) self.sink = gr.file_sink(gr.sizeof_gr_complex, options.to_file) else: sys.stderr.write("No sink defined, dumping samples to null sink.\n\n") self.sink = gr.null_sink(gr.sizeof_gr_complex) # do this after for any adjustments to the options that may # occur in the sinks (specifically the UHD sink) self.txpath = transmit_path(modulator, options) self.connect(self.txpath, self.sink)
def __init__(self, callback, options): gr.top_block.__init__(self) if(options.tx_freq is not None): self.sink = uhd_transmitter(options.args, options.bandwidth, options.tx_freq, options.lo_offset, options.tx_gain, options.spec, options.antenna, options.clock_source, options.verbose) # elif(options.to_file is not None): # self.sink = blocks.file_sink(gr.sizeof_gr_complex, options.to_file) else: self.sink = blocks.null_sink(gr.sizeof_gr_complex) if(options.rx_freq is not None): self.source = uhd_receiver(options.args, options.bandwidth, options.rx_freq, options.lo_offset, options.rx_gain, options.spec, options.antenna, options.clock_source, options.verbose) # elif(options.from_file is not None): # self.source = blocks.file_source(gr.sizeof_gr_complex, options.from_file) else: self.source = blocks.null_source(gr.sizeof_gr_complex) # Set up receive path # do this after for any adjustments to the options that may # occur in the sinks (specifically the UHD sink) self.rxpath = receive_path(callback, options) self.txpath = transmit_path(options) self.connect(self.source, self.rxpath) self.connect(self.txpath, self.sink)
def __init__(self, modulator, options): gr.top_block.__init__(self) if (options.tx_freq is not None): # Work-around to get the modulation's bits_per_symbol args = modulator.extract_kwargs_from_options(options) symbol_rate = options.bitrate / modulator(**args).bits_per_symbol() self.sink = uhd_transmitter(options.args, symbol_rate, options.samples_per_symbol, options.tx_freq, options.lo_offset, options.tx_gain, options.spec, options.antenna, options.clock_source, options.verbose) options.samples_per_symbol = self.sink._sps elif (options.to_file is not None): sys.stderr.write( ("Saving samples to '%s'.\n\n" % (options.to_file))) self.sink = blocks.file_sink(gr.sizeof_gr_complex, options.to_file) else: sys.stderr.write( "No sink defined, dumping samples to null sink.\n\n") self.sink = blocks.null_sink(gr.sizeof_gr_complex) # do this after for any adjustments to the options that may # occur in the sinks (specifically the UHD sink) self.txpath = transmit_path(modulator, options) self.connect(self.txpath, self.sink)
def __init__(self, mod, options): gr.top_block.__init__(self, "tx_mpsk") self._modulator_class = mod # Get mod_kwargs mod_kwargs = self._modulator_class.extract_kwargs_from_options(options) # transmitter self._modulator = self._modulator_class(**mod_kwargs) if (options.tx_freq is not None): symbol_rate = options.bitrate / self._modulator.bits_per_symbol() self._sink = uhd_transmitter(options.args, symbol_rate, options.samples_per_symbol, options.tx_freq, options.tx_gain, options.spec, options.antenna, options.verbose) options.samples_per_symbol = self._sink._sps elif (options.to_file is not None): self._sink = gr.file_sink(gr.sizeof_gr_complex, options.to_file) else: self._sink = gr.null_sink(gr.sizeof_gr_complex) self._transmitter = bert_transmit(self._modulator._constellation, options.samples_per_symbol, options.differential, options.excess_bw, gray_coded=True, verbose=options.verbose, log=options.log) self.amp = gr.multiply_const_cc(options.amplitude) self.connect(self._transmitter, self.amp, self._sink)
def __init__(self, options, payload=''): gr.top_block.__init__(self) if (options.tx_freq is not None): self.sink = uhd_transmitter(options.args, options.bandwidth, options.tx_freq, options.tx_gain, options.spec, options.antenna, options.verbose) elif (options.to_file is not None): self.sink = gr.file_sink(gr.sizeof_gr_complex, options.to_file) else: self.sink = gr.null_sink(gr.sizeof_gr_complex) options.interp = 100e6 / options.bandwidth # FTW-specific convertion # do this after for any adjustments to the options that may # occur in the sinks (specifically the UHD sink) if (options.from_file is None): self.txpath = ftw_transmit_path(options, payload) else: self.txpath = gr.file_source(gr.sizeof_gr_complex, options.from_file) # options.tx_amplitude = 1 # static value to make sure we do not exceed +-1 for the floats being sent to the sink self._tx_amplitude = options.tx_amplitude self.amp = gr.multiply_const_cc(self._tx_amplitude) # self.txpath = ftw_pnc_transmit_path(options, payload) self.connect(self.txpath, self.amp, self.sink) if options.log: self.connect( self.txpath, gr.file_sink(gr.sizeof_gr_complex, 'ftw_benchmark.dat'))
def __init__(self, callback, options): gr.top_block.__init__(self) if (options.rx_freq is not None): self.source = uhd_receiver(options.args, options.bandwidth, options.rx_freq, options.rx_gain, options.spec, options.antenna, options.verbose) elif (options.from_file is not None): self.source = gr.file_source(gr.sizeof_gr_complex, options.from_file) else: self.source = gr.null_source(gr.sizeof_gr_complex) # Set up receive path # do this after for any adjustments to the options that may # occur in the sinks (specifically the UHD sink) if (options.tx_freq is not None): self.sink = uhd_transmitter(options.args, options.bandwidth, options.tx_freq, options.tx_gain, options.spec, options.antenna, options.verbose) elif (options.to_file is not None): self.sink = gr.file_sink(gr.sizeof_gr_complex, options.to_file) else: self.sink = gr.null_sink(gr.sizeof_gr_complex) self.source.set_sample_rate(1500000) #rx sample rate self.sink.set_sample_rate(640000) self.rxpath = receive_path(callback, options) self.txpath = transmit_path(options) self.connect(self.source, self.rxpath) self.connect(self.txpath, self.sink) self.source.set_antenna("RX2") global freq freq = options.tx_freq # - 12e6
def __init__(self, options): gr.top_block.__init__(self) if options.outfile is not None: u = gr.file_sink(gr.sizeof_gr_complex, options.outfile) elif (options.tx_freq is not None) or (options.channel is not None): if options.channel is not None: self.chan_num = options.channel options.tx_freq = ieee802_15_4_pkt.chan_802_15_4.chan_map[ self.chan_num] u = uhd_transmitter(options.tx_args, options.bandwidth, options.tx_freq, options.tx_gain, options.spec, options.antenna, options.verbose, options.external) else: raise SystemExit( "--tx-freq, --channel or --outfile must be specified\n") self.samples_per_symbol = 2 # transmitter self.packet_transmitter = ieee802_15_4_pkt.ieee802_15_4_mod_pkts( self, spb=self.samples_per_symbol, msgq_limit=2, log=options.log) self.amp = gr.multiply_const_cc(1) self.u = u self.connect(self.packet_transmitter, self.amp, self.u) self.connect(self.amp, gr.file_sink(gr.sizeof_gr_complex, 'cc2420-tx-diag.dat'))
def __init__(self, modulator, demodulator, rx_callback, options): gr.top_block.__init__(self) #parameters to sense channe #options.symbol_rate=2500000 #options.samples_per_symbol=2 #options.rx_freq=2500000000 #options.rx_gain=20 #options.chbw_factor=1 sense_symbol_rate=2500000 sense_samples_per_symbol=2 sense_rx_freq=2500000000 sense_rx_gain=20 options.chbw_factor=1 #options.samples_per_symbol, #args = demodulator.extract_kwargs_from_options(options) self.sensesource=uhd_receiver(options.args, sense_symbol_rate, sense_samples_per_symbol, sense_rx_freq, sense_rx_gain, options.spec, options.antenna, options.verbose) if(options.tx_freq is not None): # Work-around to get the modulation's bits_per_symbol args = modulator.extract_kwargs_from_options(options) symbol_rate = options.bitrate / modulator(**args).bits_per_symbol() self.sink = uhd_transmitter(options.args, symbol_rate, options.samples_per_symbol, options.tx_freq, options.tx_gain, options.spec, options.antenna, options.verbose) options.samples_per_symbol = self.sink._sps elif(options.to_file is not None): sys.stderr.write(("Saving samples to '%s'.\n\n" % (options.to_file))) self.sink = gr.file_sink(gr.sizeof_gr_complex, options.to_file) else: sys.stderr.write("No sink defined, dumping samples to null sink.\n\n") self.sink = gr.null_sink(gr.sizeof_gr_complex) self.txgate = gr.copy(gr.sizeof_gr_complex) self.sensegate = gr.copy(gr.sizeof_gr_complex) #self.msgq = gr.msg_queue() # do this after for any adjustments to the options that may # occur in the sinks (specifically the UHD sink) self.txpath = transmit_path(modulator, options) self.connect(self.txpath, self.txgate, self.sink) # do sense self.sensepath = sensing_path(options) self.tx_enabled = True self.sense_flag=False self.connect(self.sensesource, self.sensepath)
def __init__(self, callback, options): gr.top_block.__init__(self) ### Rx Side ### if(options.rx_freq is not None): self.source = uhd_receiver(options.args_rx, options.bandwidth, options.rx_freq, options.rx_gain, options.spec, options.antenna, options.verbose) elif(options.from_file is not None): self.source = gr.file_source(gr.sizeof_gr_complex, options.from_file) else: self.source = gr.null_source(gr.sizeof_gr_complex) # Set up receive path # do this after for any adjustments to the options that may # occur in the sinks (specifically the UHD sink) self.rxpath = receive_path(callback, options) ## Tx Side ### if(options.tx_freq is not None): self.sink = uhd_transmitter(options.args_tx, options.bandwidth, options.tx_freq, options.tx_gain, options.spec, options.antenna, options.verbose) elif(options.to_file is not None): self.sink = gr.file_sink(gr.sizeof_gr_complex, options.to_file) else: self.sink = gr.null_sink(gr.sizeof_gr_complex) # do this after for any adjustments to the options that may # occur in the sinks (specifically the UHD sink) self.txpath = transmit_path(options) self.connect(self.txpath, self.sink) # self.txpath = gr.message_source(gr.sizeof_gr_complex, 3) # nco_sensitivity = 2.0/options.fft_length # correct for fine frequency # self.nco = ftw.pnc_frequency_modulator_fc(nco_sensitivity) # self.connect(self.txpath, self.sink) # self.nco, # if you use two USRPs and want to synchonized # need to change uhd_interface.py # self.source.config_mimo() # time.sleep(1) # to make sync stable if options.debug: self.connect(self.source, gr.file_sink(gr.sizeof_gr_complex, 'rx.dat')) # Save reception signal else: self.connect(self.source, self.rxpath) #self.connect(self.source, gr.file_sink(gr.sizeof_gr_complex, 'rx.dat')) if(options.verbose): self._print_verbage()
def __init__(self, callback, options): gr.top_block.__init__(self) ### Rx Side ### if (options.rx_freq is not None): self.source = uhd_receiver(options.args_rx, options.bandwidth, options.rx_freq, options.rx_gain, options.spec, options.antenna, options.verbose) elif (options.from_file is not None): self.source = gr.file_source(gr.sizeof_gr_complex, options.from_file) else: self.source = gr.null_source(gr.sizeof_gr_complex) # Set up receive path # do this after for any adjustments to the options that may # occur in the sinks (specifically the UHD sink) self.rxpath = receive_path(callback, options) ## Tx Side ### if (options.tx_freq is not None): self.sink = uhd_transmitter(options.args_tx, options.bandwidth, options.tx_freq, options.tx_gain, options.spec, options.antenna, options.verbose) elif (options.to_file is not None): self.sink = gr.file_sink(gr.sizeof_gr_complex, options.to_file) else: self.sink = gr.null_sink(gr.sizeof_gr_complex) # do this after for any adjustments to the options that may # occur in the sinks (specifically the UHD sink) self.txpath = transmit_path(options) self.connect(self.txpath, self.sink) # self.txpath = gr.message_source(gr.sizeof_gr_complex, 3) # nco_sensitivity = 2.0/options.fft_length # correct for fine frequency # self.nco = ftw.pnc_frequency_modulator_fc(nco_sensitivity) # self.connect(self.txpath, self.sink) # self.nco, # if you use two USRPs and want to synchonized # need to change uhd_interface.py # self.source.config_mimo() # time.sleep(1) # to make sync stable if options.debug: self.connect(self.source, gr.file_sink(gr.sizeof_gr_complex, 'rx.dat')) # Save reception signal else: self.connect(self.source, self.rxpath) #self.connect(self.source, gr.file_sink(gr.sizeof_gr_complex, 'rx.dat')) if (options.verbose): self._print_verbage()
def __init__(self, options): gr.top_block.__init__(self) self.sink = uhd_transmitter(options.args, options.bandwidth, options.tx_freq, options.lo_offset, options.tx_gain, options.spec, options.antenna, options.clock_source, options.verbose) self.txpath = transmit_path(options) self.connect(self.txpath, self.sink)
def __init__(self, rx_callback, options): gr.top_block.__init__(self) # Setting up 'Transmit Path' self.txpath = transmit_path(options, self) # Setting up 'Receive Path' packet = cnPacket() self.rxpath = receive_path(rx_callback, packet, options) # Channel samples_per_packet = options.samples_per_symbol * 8 * 36 if options.mode == 'default': print 'Operating mode : Default' mods = digital.modulation_utils.type_1_mods() modulator = mods[options.modulation] args = modulator.extract_kwargs_from_options(options) symbol_rate = options.bitrate / modulator(**args).bits_per_symbol() self.usrp_sink = uhd_transmitter(options.args, symbol_rate, options.samples_per_symbol, options.tx_freq, options.tx_gain, options.spec, options.antenna, options.verbose) self.usrp_source = uhd_receiver(options.args, symbol_rate, options.samples_per_symbol, options.rx_freq, options.rx_gain, options.spec, options.antenna, options.verbose) options.samples_per_symbol = self.usrp_sink._sps #self.usrp_sink = usrp_sink(options) #self.usrp_source = usrp_source(options) self.connect(self.txpath, self.usrp_sink) self.connect(self.usrp_source, self.rxpath) elif options.mode == 'loopback': print 'Operating mode : Loopback' self.channel = channel_emulator(options,samples_per_packet) self.connect(self.txpath, self.channel, self.rxpath)
def __init__(self, options): gr.top_block.__init__(self) self.sink = uhd_transmitter(options.args, options.bandwidth, options.tx_freq, options.tx_gain, options.spec, options.antenna, options.verbose) # do this after for any adjustments to the options that may # occur in the sinks (specifically the UHD sink) self.txpath = transmit_path(options) self.connect(self.txpath, self.sink)
def __init__(self, options): gr.top_block.__init__(self) if options.tx_freq is not None: u = uhd_transmitter(options.args, options.bandwidth, options.tx_freq, options.tx_gain, options.spec, options.antenna, options.external, options.verbose) elif options.outfile is not None: u = gr.file_sink(gr.sizeof_gr_complex, options.outfile) else: raise SystemExit("--freq or --outfile must be specified\n") if options.infile is not None: tx = gr.file_source(gr.sizeof_gr_complex, options.infile, repeat=options.repeat) else: tx = ofdm_rxtx.TX(options) data_tones = tx.params.data_tones if options.char > 0: # read char from file data = gr.stream_to_vector(gr.sizeof_float, data_tones * 2) # NOTE: we use repeat, assuming the file is long enough or properly aligned self.connect( gr.file_source(gr.sizeof_char, options.txdata, repeat=True), gr.char_to_float(), gr.multiply_const_ff(options.char * (2**-0.5) / 128.0), data) else: data = ofdm_rxtx.make_data(data_tones, options.size, options.txdata) if options.log: self.connect( data, gr.file_sink(data_tones * gr.sizeof_gr_complex, 'tx-data.dat')) self.connect(data, tx) self.sender = ofdm_rxtx.sender_thread(tx, options) if options.amp != 1: amp = gr.multiply_const_cc(options.amp) self.connect(tx, amp, u) else: self.connect(tx, u)
def _setup_usrp_source2(self, options): """ Creates a USRP sink, determines the settings for best bitrate, and attaches to the transmitter's subdevice. """ print "setup_usrp_source2", self._tx_freq if (self._tx_freq is not None): self.u_sink = uhd_transmitter(options.args, options.bandwidth, self._tx_freq, options.tx_gain, options.spec, options.antenna, options.verbose) print "setup usrp sink ", self.u_sink # do this after for any adjustments to the options that may # occur in the sinks (specifically the UHD sink) self.txpath = transmit_path(options) self.connect(self.txpath, self.u_sink)
def __init__(self, modulator, options): gr.top_block.__init__(self) if(options.tx_freq is not None): # Work-around to get the modulation's bits_per_symbol args = modulator.extract_kwargs_from_options(options) symbol_rate = options.bitrate / modulator(**args).bits_per_symbol() self.sink = uhd_transmitter(options.args, symbol_rate, options.samples_per_symbol, options.tx_freq, options.lo_offset, options.tx_gain, options.spec, options.antenna, options.clock_source, options.verbose) options.samples_per_symbol = self.sink._sps elif(options.to_file is not None): sys.stderr.write(("Saving samples to '%s'.\n\n" % (options.to_file))) self.sink = blocks.file_sink(gr.sizeof_gr_complex, options.to_file) else: sys.stderr.write("No sink defined, dumping samples to null sink.\n\n") self.sink = blocks.null_sink(gr.sizeof_gr_complex) # do this after for any adjustments to the options that may # occur in the sinks (specifically the UHD sink) self.txpath = transmit_path(modulator, options) alpha = 0.001 thresh = 20 self.probe = analog.probe_avg_mag_sqrd_c(thresh,alpha) self.source = uhd.usrp_source( ",".join(("", "")), uhd.stream_args( cpu_format="fc32", channels=range(1), ), ) self.source.set_samp_rate(self.sink._rate) self.source.set_center_freq(uhd.tune_request(options.tx_freq,0)) self.source.set_gain(options.tx_gain) self.connect(self.source, self.probe) self.connect(self.txpath, self.sink) print >> sys.stderr, options
def __init__(self, options): gr.top_block.__init__(self) if (options.tx_freq is not None): self.sink = uhd_transmitter(options.args, options.bandwidth, options.tx_freq, options.tx_gain, options.spec, options.antenna, options.verbose) elif (options.to_file is not None): self.sink = gr.file_sink(gr.sizeof_gr_complex, options.to_file) else: self.sink = gr.null_sink(gr.sizeof_gr_complex) # do this after for any adjustments to the options that may # occur in the sinks (specifically the UHD sink) self.txpath = gr.file_source(gr.sizeof_gr_complex, options.data_file) self.amp = gr.multiply_const_cc(options.amp) self.connect(self.txpath, self.amp, self.sink)
def _setup_usrp_source2(self,options): """ Creates a USRP sink, determines the settings for best bitrate, and attaches to the transmitter's subdevice. """ print "setup_usrp_source2",self._tx_freq if(self._tx_freq is not None): self.u_sink = uhd_transmitter(options.args, options.bandwidth, self._tx_freq, options.tx_gain, options.spec, options.antenna, options.verbose) print "setup usrp sink " , self.u_sink # do this after for any adjustments to the options that may # occur in the sinks (specifically the UHD sink) self.txpath = transmit_path(options) self.connect(self.txpath, self.u_sink)
def __init__(self, callback, fwd_callback, options): gr.top_block.__init__(self) self.source = uhd_receiver(options.args, options.bandwidth, options.rx_freq, options.rx_gain, options.spec, options.antenna, options.verbose) self.sink = uhd_transmitter(options.args, options.bandwidth, options.tx_freq, options.tx_gain, options.spec, options.antenna, options.verbose) self.rxpath = receive_path(callback, fwd_callback, options) self.connect(self.source, self.rxpath) self.txpath = transmit_path(options) self.connect(self.txpath, self.sink)
def __init__(self, options): gr.top_block.__init__(self) if(options.tx_freq is not None): self.sink = uhd_transmitter(options.args, options.bandwidth, options.tx_freq, options.tx_gain, options.spec, options.antenna, options.verbose) elif(options.to_file is not None): self.sink = gr.file_sink(gr.sizeof_gr_complex, options.to_file) else: self.sink = gr.null_sink(gr.sizeof_gr_complex) # do this after for any adjustments to the options that may # occur in the sinks (specifically the UHD sink) self.txpath = gr.message_source(gr.sizeof_gr_complex, 3) self.amp = gr.multiply_const_cc(options.amp) self.connect(self.txpath, self.amp, self.sink)
def __init__(self, options): gr.top_block.__init__(self) data_capsule = ( (+0+0j), (+0+0j), (+0+0j), (+0+0j), (+0+0j), (+1+1j), (+1+1j), (+1+1j), (+1+1j), (+1+1j) ) symbol_rate = 500000 self.source = uhd_receiver(options.args, symbol_rate, 2, options.rx_freq, 30, options.spec, "RX2", options.verbose) self.tx = uhd_transmitter(options.args, symbol_rate, 2, options.tx_freq, 30, options.spec, "TX/RX", options.verbose) options.samples_per_symbol = self.source._sps # Set up receive path # do this after for any adjustments to the options that may # occur in the sinks (specifically the UHD sink) self.serve = gr.vector_source_c(data_capsule) #self.correlator = correlator_cc.correlator_cc() #self.sink = gr.vector_sink_c() #self.file_sink = gr.file_sink(gr.sizeof_gr_complex, "out") self.server = correlator_cc.go_start_cc() self.inserter = correlator_cc.preamble_insert_cc() self.correlator = correlator_cc.correlator_cc() self.connect(self.source, self.correlator) self.connect(self.serve, (self.server,0)) self.connect(self.correlator, (self.server,1)) self.connect(self.server, self.inserter) self.connect(self.inserter, self.tx)
def __init__(self, options): gr.top_block.__init__(self) if(options.tx_freq is not None): self.sink = uhd_transmitter(options.args, options.bandwidth, options.tx_freq, options.lo_offset, options.tx_gain, options.spec, options.antenna, options.clock_source, options.verbose) elif(options.to_file is not None): self.sink = blocks.file_sink(gr.sizeof_gr_complex, options.to_file) else: self.sink = blocks.null_sink(gr.sizeof_gr_complex) # do this after for any adjustments to the options that may # occur in the sinks (specifically the UHD sink) self.txpath = transmit_path(options) self.connect(self.txpath, self.sink)
def __init__(self, options): gr.top_block.__init__(self) if options.freq is not None: u = uhd_transmitter(options.tx_args, options.bandwidth, options.tx_freq, options.tx_gain, options.spec, options.antenna, options.verbose, options.external) elif options.outfile is not None: u = blocks.file_sink(gr.sizeof_gr_complex, options.outfile) else: raise SystemExit("--freq or --outfile must be specified\n") tx = transmit_path.ofdm_transmit_path(options) amp = blocks.multiply_const_cc(options.tx_amplitude) self.connect(tx, amp, u) self.tx = tx self.u = u self.outfile = options.outfile
def __init__(self, callback, fwd_callback, options): #def __init__(self, options): gr.top_block.__init__(self) if(options.tx_freq is not None): self.sink = uhd_transmitter(options.args, options.bandwidth, options.tx_freq, options.tx_gain, options.spec, options.antenna, options.verbose) if(options.rx_freq is not None): self.source = uhd_receiver(options.args, options.bandwidth, options.rx_freq, options.rx_gain, options.spec, options.antenna, options.verbose) elif(options.to_file is not None): self.sink = gr.file_sink(gr.sizeof_gr_complex, options.to_file) else: self.sink = gr.null_sink(gr.sizeof_gr_complex) # do this after for any adjustments to the options that may # occur in the sinks (specifically the UHD sink) print "flow:: ", options.flow # only for bidirectional flows: source in the reverse direction needs to # start the ofdm_sink first to allow the socket connections working fine.. if (options.flow == 1): self.rxpath = receive_path(callback, fwd_callback, options) self.connect(self.source, self.rxpath) self.txpath = transmit_path(options) self.connect(self.txpath, self.sink) else: self.txpath = transmit_path(options) self.connect(self.txpath, self.sink) self.rxpath = receive_path(callback, fwd_callback, options) self.connect(self.source, self.rxpath)
def __init__(self, modulator_class, options): ''' See below for what options should hold ''' gr.hier_block2.__init__(self, "usrp_transmit_path", gr.io_signature(0, 0, 0), # Input signature gr.io_signature(0, 0, 0)) # Output signature tx_path = transmit_path.transmit_path(modulator_class, options) for attr in dir(tx_path): #forward the methods if not attr.startswith('_') and not hasattr(self, attr): setattr(self, attr, getattr(tx_path, attr)) #setup usrp args = modulator_class.extract_kwargs_from_options(options) symbol_rate = options.bitrate / modulator_class(**args).bits_per_symbol() self.sink = uhd_transmitter(options.args, symbol_rate, options.samples_per_symbol, options.tx_freq, options.tx_gain, options.spec, options.antenna, options.verbose) #connect self.connect(tx_path, self.sink)
def __init__(self, options): gr.top_block.__init__(self) if options.tx_freq is not None: u = uhd_transmitter(options.args, options.bandwidth, options.tx_freq, options.tx_gain, options.spec, options.antenna, options.external, options.verbose) elif options.outfile is not None: u = gr.file_sink(gr.sizeof_gr_complex, options.outfile) else: raise SystemExit("--freq or --outfile must be specified\n") if options.infile is not None: tx = gr.file_source(gr.sizeof_gr_complex, options.infile, repeat = options.repeat) else: tx = ofdm_rxtx.TX(options) data_tones = tx.params.data_tones if options.char > 0: # read char from file data = gr.stream_to_vector(gr.sizeof_float, data_tones * 2) # NOTE: we use repeat, assuming the file is long enough or properly aligned self.connect(gr.file_source(gr.sizeof_char, options.txdata, repeat=True), gr.char_to_float(), gr.multiply_const_ff(options.char * (2**-0.5) / 128.0), data) else: data = ofdm_rxtx.make_data(data_tones, options.size, options.txdata) if options.log: self.connect(data, gr.file_sink(data_tones * gr.sizeof_gr_complex, 'tx-data.dat')) self.connect(data, tx) self.sender = ofdm_rxtx.sender_thread(tx, options) if options.amp != 1: amp = gr.multiply_const_cc(options.amp) self.connect(tx, amp, u) else: self.connect(tx, u)
def __init__(self, mod, options): gr.top_block.__init__(self, "tx_mpsk") self._modulator_class = mod # Get mod_kwargs mod_kwargs = self._modulator_class.extract_kwargs_from_options(options) # transmitter self._modulator = self._modulator_class(**mod_kwargs) if options.tx_freq is not None: self._sink = uhd_transmitter( options.args, options.bitrate, options.samples_per_symbol, options.tx_freq, options.tx_gain, options.antenna, options.verbose, ) options.samples_per_symbol = self._sink._sps elif options.to_file is not None: self._sink = gr.file_sink(gr.sizeof_gr_complex, options.to_file) else: self._sink = gr.null_sink(gr.sizeof_gr_complex) self._transmitter = bert_transmit( self._modulator._constellation, options.samples_per_symbol, options.differential, options.excess_bw, gray_coded=True, verbose=options.verbose, log=options.log, ) self.connect(self._transmitter, self._sink)
def __init__(self, options): gr.top_block.__init__(self) # some arbitrary data data_capsule = ( (+1+1j), (+1+1j), (-1-1j), (-1-1j), (+1+1j), (-1+1j), (-1+1j), (+1-1j), (+1-1j), (-1-1j) ) # Work-around to get the modulation's bits_per_symbol symbol_rate = 500000 self.sink = uhd_transmitter(options.args, symbol_rate, 2, options.tx_freq, 30, options.spec, "TX/RX", options.verbose) self.rx = uhd_receiver(options.args, symbol_rate, 2, options.rx_freq, 30, options.spec, "RX2", options.verbose) options.samples_per_symbol = self.sink._sps self.serve = gr.vector_source_c(data_capsule) #self.inserter = correlator_cc.preamble_insert_cc() #self.connect(self.source, self.inserter) #self.connect(self.inserter, self.sink) self.server = correlator_cc.go_start_cc() self.inserter = correlator_cc.preamble_insert_cc() self.correlator = correlator_cc.correlator_cc() self.connect(self.rx, self.correlator) self.connect(self.serve, (self.server,0)) self.connect(self.correlator, (self.server,1)) self.connect(self.server, self.inserter) self.connect(self.inserter, self.sink)
def __init__(self, options): gr.top_block.__init__(self) if (options.tx_freq is not None): options.bandwidth = 10000000 / 2 #options.bandwidth = 100000000/16 print options.bandwidth self.sink = uhd_transmitter(options.args, options.bandwidth, options.tx_freq, options.lo_offset, options.tx_gain, options.spec, options.antenna, options.clock_source, options.verbose) elif (options.to_file is not None): self.sink = blocks.file_sink(gr.sizeof_gr_complex, options.to_file) else: self.sink = blocks.null_sink(gr.sizeof_gr_complex) # do this after for any adjustments to the options that may # occur in the sinks (specifically the UHD sink) self.txpath = transmit_path(options) self.connect(self.txpath, self.sink)
def __init__(self, options): gr.top_block.__init__(self) if(options.to_file is not None): self.file = blocks.file_sink(gr.sizeof_gr_complex, options.to_file) self.sink = blocks.throttle(gr.sizeof_gr_complex,1e6) self.connect( self.sink, self.file ) elif(options.tx_freq is not None): self.sink = uhd_transmitter(options.args, options.bandwidth, options.tx_freq, options.lo_offset, options.tx_gain, options.spec, options.antenna, options.clock_source, options.verbose) else: self.sink = blocks.null_sink(gr.sizeof_gr_complex) self._setup_tx_path(options) self._setup_rpc_manager() if options.freqoff is not None: freq_off = self.freq_off = channel.freq_offset(options.freqoff ) self.connect(self.txpath, freq_off) self.txpath = freq_off self.rpc_mgr_tx.add_interface("set_freq_offset",self.freq_off.set_freqoff) if options.multipath: if options.itu_channel: self.fad_chan = channel.itpp_channel(options.bandwidth) self.rpc_mgr_tx.add_interface("set_channel_profile",self.fad_chan.set_channel_profile) else: self.fad_chan = filter.fir_filter_ccc(1,[1.0,0.0,2e-1+0.1j,1e-4-0.04j]) self.connect(self.txpath, self.fad_chan) self.txpath = self.fad_chan self.connect(self.txpath, self.sink)
def __init__(self, options): gr.top_block.__init__(self) if (options.to_file is not None): self.file = blocks.file_sink(gr.sizeof_gr_complex, options.to_file) self.sink = blocks.throttle(gr.sizeof_gr_complex, 1e6) self.connect(self.sink, self.file) elif (options.tx_freq is not None): self.sink = uhd_transmitter(options.args, options.bandwidth, options.tx_freq, options.lo_offset, options.tx_gain, options.spec, options.antenna, options.clock_source, options.verbose) else: self.sink = blocks.null_sink(gr.sizeof_gr_complex) self._setup_tx_path(options) self._setup_rpc_manager() if options.freqoff is not None: freq_off = self.freq_off = channel.freq_offset(options.freqoff) self.connect(self.txpath, freq_off) self.txpath = freq_off self.rpc_mgr_tx.add_interface("set_freq_offset", self.freq_off.set_freqoff) if options.multipath: if options.itu_channel: self.fad_chan = channel.itpp_channel(options.bandwidth) self.rpc_mgr_tx.add_interface( "set_channel_profile", self.fad_chan.set_channel_profile) else: self.fad_chan = filter.fir_filter_ccc( 1, [1.0, 0.0, 2e-1 + 0.1j, 1e-4 - 0.04j]) self.connect(self.txpath, self.fad_chan) self.txpath = self.fad_chan self.connect(self.txpath, self.sink)
def __init__(self, byte_size, bit_rate=100000): gr.top_block.__init__(self) self.mod_type = "bpsk" # bpsk or qpsk if (self.mod_type == "bpsk"): self.bits = 1 else: self.bits = 2 self.samples_per_symbol = 4 self.bit_rate = bit_rate self.symbol_rate = self.bit_rate / self.bits self.freq = 1000000000.0 self.trans = transmit_path(byte_size, self.mod_type, self.samples_per_symbol) self.sink = uhd_transmitter(sym_rate=self.symbol_rate, sps=self.samples_per_symbol, freq=self.freq, verbose=True, gain=19.5) self.connect(self.trans, self.sink)
def __init__(self, callback, fwd_callback, options): #def __init__(self, options): gr.top_block.__init__(self) if (options.tx_freq is not None): self.sink = uhd_transmitter(options.args, options.bandwidth, options.tx_freq, options.tx_gain, options.spec, options.antenna, options.verbose) if (options.rx_freq is not None): self.source = uhd_receiver(options.args, options.bandwidth, options.rx_freq, options.rx_gain, options.spec, options.antenna, options.verbose) elif (options.to_file is not None): self.sink = gr.file_sink(gr.sizeof_gr_complex, options.to_file) else: self.sink = gr.null_sink(gr.sizeof_gr_complex) # do this after for any adjustments to the options that may # occur in the sinks (specifically the UHD sink) print "flow:: ", options.flow # only for bidirectional flows: source in the reverse direction needs to # start the ofdm_sink first to allow the socket connections working fine.. if (options.flow == 1): self.rxpath = receive_path(callback, fwd_callback, options) self.connect(self.source, self.rxpath) self.txpath = transmit_path(options) self.connect(self.txpath, self.sink) else: self.txpath = transmit_path(options) self.connect(self.txpath, self.sink) self.rxpath = receive_path(callback, fwd_callback, options) self.connect(self.source, self.rxpath)
def __init__(self, callback, options): gr.top_block.__init__(self) #rec if(options.rx_freq is not None): self.source = uhd_receiver(options.args, options.bandwidth, options.rx_freq, options.rx_gain, options.spec, options.antenna, options.verbose) elif(options.from_file is not None): self.source = gr.file_source(gr.sizeof_gr_complex, options.from_file) else: self.source = gr.null_source(gr.sizeof_gr_complex) # Set up receive path # do this after for any adjustments to the options that may # occur in the sinks (specifically the UHD sink) self.rxpath = receive_path(callback, options) self.connect(self.source, self.rxpath) #trans if(options.tx_freq is not None): self.sink = uhd_transmitter(options.args, options.bandwidth, options.tx_freq, options.tx_gain, options.spec, options.antenna, options.verbose) elif(options.to_file is not None): self.sink = gr.file_sink(gr.sizeof_gr_complex, options.to_file) else: self.sink = gr.null_sink(gr.sizeof_gr_complex) # do this after for any adjustments to the options that may # occur in the sinks (specifically the UHD sink) self.txpath = transmit_path(options) self.connect(self.txpath, self.sink)
def __init__(self, options): gr.top_block.__init__(self) use_sink = None if(options.tx_freq is not None): self.sink = uhd_transmitter(options.args, options.bandwidth, options.tx_freq, options.tx_gain, options.spec, options.antenna, options.verbose) use_sink = self.sink elif(options.to_file is not None): self.sink = gr.file_sink(gr.sizeof_gr_complex, options.to_file) self.throttle = gr.throttle(gr.sizeof_gr_complex*1, options.file_samp_rate) self.connect(self.throttle, self.sink) use_sink = self.throttle else: self.sink = gr.null_sink(gr.sizeof_gr_complex) # do this after for any adjustments to the options that may # occur in the sinks (specifically the UHD sink) self.txpath = [ ] self.txpath.append(transmit_path(options)) self.txpath.append(transmit_path(options)) samp_rate = 0 if(options.tx_freq is not None): samp_rate = self.sink.get_sample_rate() else: samp_rate = options.file_samp_rate print "SAMP RATE " + str(samp_rate) volume = options.split_amplitude band_transition = options.band_trans_width low_transition = options.low_trans_width guard_width = options.guard_width self.low_pass_filter_qv0 = gr.interp_fir_filter_ccf(2, firdes.low_pass( 1, samp_rate, samp_rate/4-guard_width/2, low_transition, firdes.WIN_HAMMING, 6.76)) self.freq_translate_qv0 = filter.freq_xlating_fir_filter_ccc(1, (options.num_taps, ), samp_rate/4, samp_rate) self.band_pass_filter_qv0 = gr.fir_filter_ccc(1, firdes.complex_band_pass( 1, samp_rate, -samp_rate/2+guard_width, 0-guard_width, band_transition, firdes.WIN_HAMMING, 6.76)) self.low_pass_filter_qv1 = gr.interp_fir_filter_ccf(2, firdes.low_pass( 1, samp_rate, samp_rate/4-guard_width/2, low_transition, firdes.WIN_HAMMING, 6.76)) self.freq_translate_qv1 = filter.freq_xlating_fir_filter_ccc(1, (options.num_taps, ), -samp_rate/4, samp_rate) self.band_pass_filter_qv1 = gr.fir_filter_ccc(1, firdes.complex_band_pass( 1, samp_rate, 0+guard_width, samp_rate/2-guard_width, band_transition, firdes.WIN_HAMMING, 6.76)) self.combiner = gr.add_vcc(1) self.volume_multiply = blocks.multiply_const_vcc((volume, )) self.connect((self.txpath[0], 0), (self.low_pass_filter_qv0, 0)) self.connect((self.txpath[1], 0), (self.low_pass_filter_qv1, 0)) self.connect((self.low_pass_filter_qv0, 0), (self.freq_translate_qv0, 0)) self.connect((self.freq_translate_qv0, 0), (self.band_pass_filter_qv0, 0)) self.connect((self.low_pass_filter_qv1, 0), (self.freq_translate_qv1, 0)) self.connect((self.freq_translate_qv1, 0), (self.band_pass_filter_qv1, 0)) self.connect((self.band_pass_filter_qv0, 0), (self.combiner, 0)) self.connect((self.band_pass_filter_qv1, 0), (self.combiner, 1)) self.connect((self.combiner, 0), (self.volume_multiply, 0)) self.connect(self.volume_multiply, use_sink)
def __init__(self, options): gr.top_block.__init__(self) # Input Data File TX_input_file = "TX_Input_Data" _TX_input_file = "TX_Input_Data" # TX_input_file = "Ding_Dong2.wma" # _TX_input_file = 'Ding_Dong2.wma' TX_source_data = gr.file_source(gr.sizeof_char, TX_input_file) TX_Input_filesize = os.stat(_TX_input_file).st_size # RX_output_file = "RX_output_test_file" # _RX_output_file = 'RX_output_test_file' # RX_file_sink = gr.file_sink(gr.sizeof_char, RX_output_file) # RX_output_filesize = os.stat(_RX_output_file).st_size # Source block # frame = ((+1+0j),(+1+0j),(+1+0j),(+1+0j),(+1+0j),(+1+0j),(+1+0j),(+1+0j),(+1+0j),(+1+0j)) zeros10 = (0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0) zeros20 = zeros10 + zeros10 zeros40 = zeros20 + zeros20 frame_pad223 = zeros40 + zeros40 + zeros40 + zeros40 + zeros40 + zeros20 + (0x0, 0x0, 0x0) frame_pad219 = ( zeros40 + zeros40 + zeros40 + zeros40 + zeros40 + zeros10 + (0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0) ) frame_pad215 = zeros40 + zeros40 + zeros40 + zeros40 + zeros40 + zeros10 + (0x0, 0x0, 0x0, 0x0, 0x0) frame_pad183 = zeros40 + zeros40 + zeros40 + zeros40 + zeros20 + (0x0, 0x0, 0x0) frame_pad179 = zeros40 + zeros40 + zeros40 + zeros40 + zeros10 + (0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0) data12 = (0xD, 0xE, 0xA, 0xD, 0xB, 0xE, 0xE, 0xF, 0xD, 0x0, 0x0, 0xD) data40 = data12 + data12 + data12 + (0xD, 0xE, 0xA, 0xD) data10 = (0x0, 0x1, 0x2, 0x3, 0x4, 0x5, 0x6, 0x7, 0x8, 0x9) data223 = data40 + data40 + data40 + data40 + data40 + data10 + data10 + (0xA, 0xB, 0xC) data219 = data40 + data40 + data40 + data40 + data40 + data10 + (0x0, 0x1, 0x2, 0x3, 0x4, 0x5, 0x6, 0x7, 0x8) data183 = data40 + data40 + data40 + data40 + data10 + data10 + (0x0, 0x1, 0x2) # src = frame_pad + data + data + data + data + frame_pad # src = frame_pad + frame_pad + data + data + data + data + data + data + data + data + data + data+ data + frame_pad + frame_pad # src = frame_pad215+data219+frame_pad219 # 10 frames # src = frame_pad215+frame_pad219+data219+data219+data219+data219+data219+data219+frame_pad219+frame_pad219 # 20 frames # src = frame_pad215+frame_pad219+data219+data219+data219+data219+data219+data219 # src = src+data219+data219 # src = src+data219+data219 # src = src+data219+data219 # src = src+data219+data219 # src = src+data219+data219 # src = src+frame_pad219+frame_pad219 # 8 frames # src = frame_pad215+frame_pad219+data219+data219+data219+data219+data219+data219 # src = src+data219+data219 # src = src+data219+data219 # src = src+data219+data219 # src = src+data219+data219 # src = src+data219+data219 # src = src+data219+data219 # src = src+data219+data219 # src = src+data219+data219 # src = src+data219+data219 # src = src+data219+data219 # src = src+data219+data219 # src = src+data219+data219 # src = src+data219+data219 # src = src+data219+data219 # src = src+data219+data219 # src = src+data219+data219 # src = src+data219+data219 # src = src+data219+data219 # src = src+data219+data219 # src = src+data219+data219 # src = src+frame_pad219+frame_pad219 # 50 frames # 8 frames src = frame_pad179 + frame_pad183 + data183 + data183 + data183 + data183 + data183 + data183 # src = src+data183+data183 # src = src+data183+data183 # src = src+data183+data183 # src = src+data183+data183 # src = src+data183+data183 # src = src+data183+data183 # src = src+data183+data183 # src = src+data183+data183 # src = src+data183+data183 # src = src+data183+data183 # src = src+data183+data183 # src = src+data183+data183 # src = src+data183+data183 # src = src+data183+data183 # src = src+data183+data183 # src = src+data183+data183 # src = src+data183+data183 # src = src+data183+data183 # src = src+data183+data183 # src = src+data183+data183 src = src + frame_pad183 + frame_pad183 # 50 frames # src = src + src # src = src + src # src = src + src # src = src + src # src = src + src # src = src + src # src = src + src # src = src + src # src = src + src # print len(src) # print len(data) # data = data + data + data + data # data = data + data + data + data + data + data + data + data + data + data + data + data + data + data # data = (0xd, 0xe, 0xa, 0xd, 0xb, 0xe, 0xe, 0xf, 0xd, 0x0) # self.source = gr.vector_source_b(src) # self.source = gr.vector_source_b(frame_pad) # CRC TX block # self.crctx = crc.crctx() # src = src + src # src = src + src # src = src + src # src = src + src # src = src + src # src = src + src # src = src + src # src = src + src # src = src + src # print len(src) # print len(data) # data = data + data + data + data # data = data + data + data + data + data + data + data + data + data + data + data + data + data + data # data = (0xd, 0xe, 0xa, 0xd, 0xb, 0xe, 0xe, 0xf, 0xd, 0x0) # self.source = gr.vector_source_b(src) # self.source = gr.vector_source_b(frame_pad) # CRC TX block # self.crctx = crc.crctx() # src = src + src # src = src + src # src = src + src # src = src + src # src = src + src # src = src + src # src = src + src # src = src + src # src = src + src # print len(src) # print len(data) # data = data + data + data + data # data = data + data + data + data + data + data + data + data + data + data + data + data + data + data # data = (0xd, 0xe, 0xa, 0xd, 0xb, 0xe, 0xe, 0xf, 0xd, 0x0) # self.source = gr.vector_source_b(src) # self.source = gr.vector_source_b(frame_pad) # CRC TX block self.crctx = crc.crctx(TX_Input_filesize) # RS encoding self.encoder = rscoding_bb.encode_bb() # Spreader self.spreader = spreader.spreader_bc() # Preamble insert block self.inserter = correlator_cc.preamble_insert_cc() # Printer block self.printer = print_bb.print_bb() # Sink block symbol_rate = 500000 # Work-around to get the modulation's bits_per_symbol self.sink = uhd_transmitter(options.args, symbol_rate, 2, options.tx_freq, 30, options.spec, "TX/RX", 1) # options.verbose) options.samples_per_symbol = self.sink._sps ntaps = 11 * int(options.samples_per_symbol) self.rrc_taps = gr.firdes.root_raised_cosine(1.0, 1000000, symbol_rate, 1.0, ntaps) self.rrc_filter = gr.interp_fir_filter_ccf(1, self.rrc_taps) # Connect the blocks # self.connect(self.source, self.inserter) # self.connect(self.inserter, self.sink) # self.connect(self.source, self.spreader) self.connect(TX_source_data, self.crctx) # self.connect(self.crctx, self.printer) # self.connect(self.printer, self.encoder) self.connect(self.crctx, self.encoder) self.connect(self.encoder, self.spreader) # self.connect(self.source, self.spreader) self.connect(self.spreader, self.inserter) # self.connect(self.inserter, self.rrc_filter) # self.connect(self.rrc_filter, self.sink) self.connect(self.inserter, self.sink)
def main(): #Searches for static 1Mhz windows def find_hole(power_list): bin_start=0 bin_stop=0 bins=0 results = [] for i in range(0,len(power_list)): if power_list[i]< 40.0 : bins=bins+1 if bins == 34: bin_stop=i break else: bins=0 bin_start=i+1 if bin_stop == 0: return 0 results.append(bin_start) results.append(bin_stop) return results #Attemp to find where opponent transmits def fuzz_target(power_list): bin_start=0 bin_stop=0 for i in range(0,len(power_list)): if power_list[i] > 60.0 : bin_start = i if (i+34) <= len(power_list): bin_stop = i+34 else: bin_stop = len(power_list) break if bin_start == 0: return 0 middle_bin = ((bin_stop-bin_start)/2) + bin_start result = (middle_bin*27902) + 2357500000.0 return result def send_pkt(payload='', eof=False): return tb.txpath.send_pkt(payload, eof) mods = digital.modulation_utils.type_1_mods() parser = OptionParser(option_class=eng_option, conflict_handler="resolve") expert_grp = parser.add_option_group("Expert") parser.add_option("-m", "--modulation", type="choice", choices=mods.keys(), default='qpsk', help="Select modulation from: %s [default=%%default]" % (', '.join(mods.keys()),)) parser.add_option("-s", "--size", type="eng_float", default=1500, help="set packet size [default=%default]") parser.add_option("-M", "--megabytes", type="eng_float", default=1.0, help="set megabytes to transmit [default=%default]") parser.add_option("","--discontinuous", action="store_true", default=False, help="enable discontinous transmission (bursts of 5 packets)") parser.add_option("","--from-file", default=None, help="use intput file for packet contents") parser.add_option("","--to-file", default=None, help="Output file for modulated samples") parser.add_option("","--server", action="store_true", default=False, help="To take data from the server") transmit_path.add_options(parser, expert_grp) uhd_transmitter.add_options(parser) for mod in mods.values(): mod.add_options(expert_grp) (options, args) = parser.parse_args () if len(args) != 0: parser.print_help() sys.exit(1) if options.from_file is not None: source_file = open(options.from_file, 'r') # build the graph # tb = my_top_block(mods[options.modulation], options) r = gr.enable_realtime_scheduling() if r != gr.RT_OK: print "Warning: failed to enable realtime scheduling" sb = senseblock() freq_list = [] packet_list = [] #Initialise tb = my_top_block(mods[options.modulation], options) tb.start() # start flow graph #Fake tranmission phase, to provoke opponent attacks payload_fake = struct.pack('!H', 666 & 0xffff) + "Qamazing team, if we lose handshake freq we are done for!" for i in range(0, 4000): send_pkt(payload_fake) sys.stderr.write('.') #Sense and fuzz phase tb.lock() time.sleep(2) sb.start() freq_list = sense_loop(sb) for i in range(0,1000): fuzz_result = fuzz_target(freq_list) print "Sensing complete, stoping senseblock, prepare to fuzz" sb.stop() sb.wait() tb.unlock() if fuzz_result != 0: options.tx_freq= fuzz_result sink = uhd_transmitter(options.args, symbol_rate2, options.samples_per_symbol, options.tx_freq, options.lo_offset, options.tx_gain, options.spec, options.antenna, options.clock_source, options.verbose) txpath = transmit_path(modulator2, options) for i in range(0, 4000): send_pkt(payload_fake) sys.stderr.write('.') else: time.sleep(1) print "Did not find fuzz targets" time.sleep(2) print "Fuzzing phase complete" #Initial sense and then send the result at handshake freq tb.lock() sb.start() freq_list = sense_loop(sb) while True : bin_results = find_hole(freq_list) if bin_results != 0 : break; middle_bin = int(((bin_results[1]-bin_results[0])/2) + bin_results[0]) print "Sensing complete, stoping senseblock preparation" sb.stop() sb.wait() tb.unlock() #Jump to handshake freq options.tx_freq=2362000000 sink = uhd_transmitter(options.args, symbol_rate2, options.samples_per_symbol, options.tx_freq, options.lo_offset, options.tx_gain, options.spec, options.antenna, options.clock_source, options.verbose) txpath = transmit_path(modulator2, options) #Special pktno to distinguish sensing packets number = 3333 #Set new transmit freq to midpoint of discovered window new_freq = str((middle_bin*27902) + 2357500000.0) payload_sense = struct.pack('!H', number & 0xffff) + new_freq #Send a large number of sensing packets (may change if ACK is developed), and then jump #to new freq for i in range(0, 2000): send_pkt(payload_sense) time.sleep(1) options.tx_freq=(middle_bin*27902) + 2357500000.0 sink = uhd_transmitter(options.args, symbol_rate2, options.samples_per_symbol, options.tx_freq, options.lo_offset, options.tx_gain, options.spec, options.antenna, options.clock_source, options.verbose) txpath = transmit_path(modulator2, options) #Main transmit phase # generate and send packets nbytes = int(1e6 * options.megabytes) n = 0 pktno = 0 pkt_size = int(options.size) # connect to server if options.server: sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) server_address = ('10.0.0.200', 50000) print >>sys.stderr, 'connecting to %s port %s' % server_address sock.connect(server_address) while pktno <= 1000 and options.server: #print "nbytes :%s , pkt_size : %s , n : %s " %(nbytes, pkt_size, n) if options.server: data = ""; while len(data) < pkt_size: data += sock.recv(pkt_size - len(data)) if data == '': # No more data received from server sock.close() break; elif options.from_file is None: data = (pkt_size - 2) * chr(pktno & 0xff) else: data = source_file.read(pkt_size - 2) pktno+=1 packet_list.append(data) #Send packets in bursts of 100 or 165 and then sense again #Repeat process, until end of expirement loop_check = True while(1): for i in range(0, len(packet_list)): data=packet_list[i] payload = struct.pack('!H', i & 0xffff) + data send_pkt(payload) sys.stderr.write('.') #Alternate 2 loops, so that the system jumps at different packet numbers #This is to ensure, we dont lose packets due to transmitter jumping slightly faster if i % 100 == 0 and i > 0 and loop_check: tb.lock() sb.start() freq_list = sense_loop(sb) while True : bin_results = find_hole(freq_list) if bin_results != 0 : break; middle_bin = int(((bin_results[1]-bin_results[0])/2) + bin_results[0]) print "Sensing complete, stoping senseblock main" sb.stop() sb.wait() tb.unlock() number = 3333 new_freq = str((middle_bin*27902) + 2357500000.0) payload_sense = struct.pack('!H', number & 0xffff) + new_freq for i in range(0, 2000): send_pkt(payload_sense) time.sleep(1) options.tx_freq=(middle_bin*27902) + 2357500000.0 sink = uhd_transmitter(options.args, symbol_rate2, options.samples_per_symbol, options.tx_freq, options.lo_offset, options.tx_gain, options.spec, options.antenna, options.clock_source, options.verbose) txpath = transmit_path(modulator2, options) elif i % 165 == 0 and i > 0 and not loop_check: tb.lock() sb.start() freq_list = sense_loop(sb) while True : bin_results = find_hole(freq_list) if bin_results != 0 : break; middle_bin = int(((bin_results[1]-bin_results[0])/2) + bin_results[0]) print "Sensing complete, stoping senseblock main" sb.stop() sb.wait() tb.unlock() number = 3333 new_freq = str((middle_bin*27902) + 2357500000.0) payload_sense = struct.pack('!H', number & 0xffff) + new_freq for i in range(0, 2000): send_pkt(payload_sense) time.sleep(1) options.tx_freq=(middle_bin*27902) + 2357500000.0 sink = uhd_transmitter(options.args, symbol_rate2, options.samples_per_symbol, options.tx_freq, options.lo_offset, options.tx_gain, options.spec, options.antenna, options.clock_source, options.verbose) txpath = transmit_path(modulator2, options) loop_check = not(loop_check) send_pkt(eof=True) tb.wait() # wait for it to finish
def __init__(self, mod, options): gr.top_block.__init__(self, "tx_mpsk") Qt.QWidget.__init__(self) self.setWindowTitle("MPSK Tx") try: self.setWindowIcon(Qt.QIcon.fromTheme('gnuradio-grc')) except: pass self.top_scroll_layout = Qt.QVBoxLayout() self.setLayout(self.top_scroll_layout) self.top_scroll = Qt.QScrollArea() self.top_scroll.setFrameStyle(Qt.QFrame.NoFrame) self.top_scroll_layout.addWidget(self.top_scroll) self.top_scroll.setWidgetResizable(True) self.top_widget = Qt.QWidget() self.top_scroll.setWidget(self.top_widget) self.top_layout = Qt.QVBoxLayout(self.top_widget) self.top_grid_layout = Qt.QGridLayout() self.top_layout.addLayout(self.top_grid_layout) self._modulator_class = mod # Get mod_kwargs mod_kwargs = self._modulator_class.extract_kwargs_from_options(options) # transmitter self._modulator = self._modulator_class(**mod_kwargs) if (options.tx_freq is not None): symbol_rate = options.bitrate / self._modulator.bits_per_symbol() self._sink = uhd_transmitter(options.args, symbol_rate, options.samples_per_symbol, options.tx_freq, options.tx_gain, options.spec, options.antenna, options.verbose) options.samples_per_symbol = self._sink._sps elif (options.to_file is not None): self._sink = blocks.file_sink(gr.sizeof_gr_complex, options.to_file) else: self._sink = blocks.null_sink(gr.sizeof_gr_complex) #Create GUI to see symbols constellation self.qtgui_const_sink = qtgui.const_sink_c( 400, #size "", #name 1 #number of inputs ) self.qtgui_const_sink.set_update_time(0.1) self.qtgui_const_sink.set_y_axis(-2, 2) self.qtgui_const_sink.set_x_axis(-2, 2) self.qtgui_const_sink.set_trigger_mode(qtgui.TRIG_MODE_FREE, qtgui.TRIG_SLOPE_POS, 0.0, 0, "") self.qtgui_const_sink.enable_autoscale(False) self.qtgui_const_sink.enable_grid(False) self.qtgui_const_sink.enable_axis_labels(True) if not True: self.qtgui_const_sink.disable_legend() labels = ["", "", "", "", "", "", "", "", "", ""] widths = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1] colors = [ "blue", "red", "red", "red", "red", "red", "red", "red", "red", "red" ] styles = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0] markers = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0] alphas = [1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0] for i in xrange(1): if len(labels[i]) == 0: self.qtgui_const_sink.set_line_label(i, "Data {0}".format(i)) else: self.qtgui_const_sink.set_line_label(i, labels[i]) self.qtgui_const_sink.set_line_width(i, widths[i]) self.qtgui_const_sink.set_line_color(i, colors[i]) self.qtgui_const_sink.set_line_style(i, styles[i]) self.qtgui_const_sink.set_line_marker(i, markers[i]) self.qtgui_const_sink.set_line_alpha(i, alphas[i]) self._qtgui_const_sink_win = sip.wrapinstance( self.qtgui_const_sink.pyqwidget(), Qt.QWidget) self.top_layout.addWidget(self._qtgui_const_sink_win) self._transmitter = bert_transmit(self._modulator._constellation, options.samples_per_symbol, options.differential, options.excess_bw, gray_coded=True, verbose=options.verbose, log=options.log) self.amp = blocks.multiply_const_cc(options.amplitude) self.connect(self._transmitter, self.amp, self._sink) self.connect(self.amp, self.qtgui_const_sink)
def __init__(self, modulator, demodulator, rx_callback, options): gr.top_block.__init__(self) sense_symbol_rate=2500000 sense_samples_per_symbol=2 sense_rx_freq=2500000000 sense_rx_gain=20 options.chbw_factor=1 global bandchoose #args = demodulator.extract_kwargs_from_options(options) self.sensesource=uhd_receiver(options.args, sense_symbol_rate, sense_samples_per_symbol, sense_rx_freq, sense_rx_gain, options.spec, options.antenna, options.verbose) if(options.tx_freq is not None): # Work-around to get the modulation's bits_per_symbol args = modulator.extract_kwargs_from_options(options) symbol_rate = options.bitrate / modulator(**args).bits_per_symbol() fa = samp_rate/4 #1000000 self.sink = uhd_transmitter(options.args, symbol_rate, options.samples_per_symbol, options.tx_freq, options.tx_gain, options.spec, options.antenna, options.verbose) options.samples_per_symbol = self.sink._sps elif(options.to_file is not None): sys.stderr.write(("Saving samples to '%s'.\n\n" % (options.to_file))) self.sink = gr.file_sink(gr.sizeof_gr_complex, options.to_file) else: sys.stderr.write("No sink defined, dumping samples to null sink.\n\n") self.sink = gr.null_sink(gr.sizeof_gr_complex) self.txgate = gr.copy(gr.sizeof_gr_complex) self.sensegate = gr.copy(gr.sizeof_gr_complex) #self.msgq = gr.msg_queue() # do this after for any adjustments to the options that may # occur in the sinks (specifically the UHD sink) # do sense self.sensepath = sensing_path(options) self.tx_enabled = True self.sense_flag=False self.connect(self.sensesource, self.sensepath) # do this after for any adjustments to the options that may # occur in the sinks (specifically the UHD sink) self.txpath1 = transmit_path(modulator, options) self.txpath2 = transmit_path(modulator, options) #self.connect(self.txpath, self.sink) # Define the math operator blocks # Generate exp(jw1t) and exp(-jw1t) self.gr_multiply_xx_0 = gr.multiply_vff(1) self.gr_float_to_complex_0_0 = gr.float_to_complex(1) self.gr_float_to_complex_0 = gr.float_to_complex(1) self.const_source_x_0 = gr.sig_source_f(0, gr.GR_CONST_WAVE, 0, 0, -1) self.analog_sig_source_x_0_0 = gr.sig_source_f(samp_rate, gr.GR_SIN_WAVE, fa, 1, 0) self.analog_sig_source_x_0 = gr.sig_source_f(samp_rate, gr.GR_COS_WAVE, fa, 1, 0) # Combine signal from two subbands self.gr_multiply_xx_1 = gr.multiply_vcc(1) self.gr_multiply_xx_2 = gr.multiply_vcc(1) self.gr_c2f_1 = gr.complex_to_float(1) self.gr_c2f_2 = gr.complex_to_float(1) self.gr_add_xx_re = gr.add_vff(1) self.gr_add_xx_im = gr.add_vff(1) self.gr_f2c = gr.float_to_complex(1) self.gr_null_source_0 = gr.null_source(gr.sizeof_gr_complex*1) # output from gr_float_to_complex_0_0 is exp(-jw1t) # output from gr_float_to_complex_0 is exp(jw1t) self.connect((self.gr_multiply_xx_0, 0), (self.gr_float_to_complex_0_0, 1)) self.connect((self.analog_sig_source_x_0, 0), (self.gr_float_to_complex_0_0, 0)) self.connect((self.analog_sig_source_x_0_0, 0), (self.gr_float_to_complex_0, 1)) self.connect((self.analog_sig_source_x_0, 0), (self.gr_float_to_complex_0, 0)) self.connect((self.analog_sig_source_x_0_0, 0), (self.gr_multiply_xx_0, 0)) self.connect((self.const_source_x_0, 0), (self.gr_multiply_xx_0, 1)) # txpath1 * exp(-jw1t) #self.connect(self.txpath1, (self.gr_multiply_xx_1, 0)) self.connect((self.gr_float_to_complex_0_0, 0), (self.gr_multiply_xx_1, 1)) # txpath2 * exp(jw1t) #self.connect(self.txpath2, (self.gr_multiply_xx_2, 0)) self.connect((self.gr_float_to_complex_0, 0), (self.gr_multiply_xx_2, 1)) if bandchoose == 0: self.connect(self.txpath1, (self.gr_multiply_xx_1, 0)) self.connect(self.gr_null_source_0 , (self.gr_multiply_xx_2, 0)) elif bandchoose == 1: self.connect(self.gr_null_source_0 , (self.gr_multiply_xx_1, 0)) self.connect(self.txpath2, (self.gr_multiply_xx_2, 0)) else: self.connect(self.txpath1, (self.gr_multiply_xx_1, 0)) self.connect(self.txpath2, (self.gr_multiply_xx_2, 0)) self.connect((self.gr_multiply_xx_1, 0), self.gr_c2f_1) self.connect((self.gr_multiply_xx_2, 0), self.gr_c2f_2) self.connect((self.gr_c2f_1,0), (self.gr_add_xx_re,0)) self.connect((self.gr_c2f_2,0), (self.gr_add_xx_re,1)) self.connect((self.gr_c2f_1,1), (self.gr_add_xx_im,0)) self.connect((self.gr_c2f_2,1), (self.gr_add_xx_im,1)) self.connect(self.gr_add_xx_re, (self.gr_f2c,0)) self.connect(self.gr_add_xx_im, (self.gr_f2c,1)) self.connect(self.gr_f2c, self.sink)
def __init__(self, modulator, options): gr.top_block.__init__(self) self.txpath = [] use_sink = None if options.tx_freq is not None: # Work-around to get the modulation's bits_per_symbol args = modulator.extract_kwargs_from_options(options) symbol_rate = options.bitrate / modulator(**args).bits_per_symbol() self.sink = uhd_transmitter( options.args, symbol_rate, options.samples_per_symbol, options.tx_freq, options.tx_gain, options.spec, options.antenna, options.verbose, ) sample_rate = self.sink.get_sample_rate() options.samples_per_symbol = self.sink._sps use_sink = self.sink elif options.to_file is not None: sys.stderr.write(("Saving samples to '%s'.\n\n" % (options.to_file))) self.sink = gr.file_sink(gr.sizeof_gr_complex, options.to_file) self.throttle = gr.throttle(gr.sizeof_gr_complex * 1, options.file_samp_rate) self.connect(self.throttle, self.sink) use_sink = self.throttle else: sys.stderr.write("No sink defined, dumping samples to null sink.\n\n") self.sink = gr.null_sink(gr.sizeof_gr_complex) # do this after for any adjustments to the options that may # occur in the sinks (specifically the UHD sink) self.txpath.append(transmit_path(modulator, options)) self.txpath.append(transmit_path(modulator, options)) samp_rate = 0 if options.tx_freq is not None: samp_rate = self.sink.get_sample_rate() else: samp_rate = options.file_samp_rate volume = options.split_amplitude band_transition = options.band_trans_width low_transition = options.low_trans_width guard_width = options.guard_width self.low_pass_filter_qv0 = gr.interp_fir_filter_ccf( 2, firdes.low_pass(1, samp_rate, samp_rate / 4 - guard_width / 2, low_transition, firdes.WIN_HAMMING, 6.76) ) self.freq_translate_qv0 = filter.freq_xlating_fir_filter_ccc(1, (options.num_taps,), samp_rate / 4, samp_rate) self.band_pass_filter_qv0 = gr.fir_filter_ccc( 1, firdes.complex_band_pass( 1, samp_rate, -samp_rate / 2 + guard_width, 0 - guard_width, band_transition, firdes.WIN_HAMMING, 6.76 ), ) self.low_pass_filter_qv1 = gr.interp_fir_filter_ccf( 2, firdes.low_pass(1, samp_rate, samp_rate / 4 - guard_width / 2, low_transition, firdes.WIN_HAMMING, 6.76) ) self.freq_translate_qv1 = filter.freq_xlating_fir_filter_ccc(1, (options.num_taps,), -samp_rate / 4, samp_rate) self.band_pass_filter_qv1 = gr.fir_filter_ccc( 1, firdes.complex_band_pass( 1, samp_rate, 0 + guard_width, samp_rate / 2 - guard_width, band_transition, firdes.WIN_HAMMING, 6.76 ), ) self.combiner = gr.add_vcc(1) self.volume_multiply = blocks.multiply_const_vcc((volume,)) self.connect((self.txpath[0], 0), (self.low_pass_filter_qv0, 0)) self.connect((self.txpath[1], 0), (self.low_pass_filter_qv1, 0)) self.connect((self.low_pass_filter_qv0, 0), (self.freq_translate_qv0, 0)) self.connect((self.freq_translate_qv0, 0), (self.band_pass_filter_qv0, 0)) self.connect((self.low_pass_filter_qv1, 0), (self.freq_translate_qv1, 0)) self.connect((self.freq_translate_qv1, 0), (self.band_pass_filter_qv1, 0)) self.connect((self.band_pass_filter_qv0, 0), (self.combiner, 0)) self.connect((self.band_pass_filter_qv1, 0), (self.combiner, 1)) self.connect((self.combiner, 0), (self.volume_multiply, 0)) self.connect(self.volume_multiply, use_sink)
def __init__(self, options): gr.top_block.__init__(self) if(options.tx_freq is not None): symbol_rate = 500000 self.sink = uhd_transmitter(options.args, symbol_rate, 2, options.tx_freq, 30, options.spec, "TX/RX", 1) options.samples_per_symbol = self.sink._sps elif(options.to_file is not None): sys.stderr.write(("Saving samples to '%s'.\n\n" % (options.to_file))) self.sink = gr.file_sink(gr.sizeof_gr_complex, options.to_file) else: sys.stderr.write("No sink defined, dumping samples to null sink.\n\n") self.sink = gr.null_sink(gr.sizeof_gr_complex) # Packetizer self.packettx = packetizer.packet_source() # CRC TX block self.crctx = crc.crctx(0) # RS encoding self.encoder = rscoding_bb.encode_bb() # Spreader self.spreader = spreader.spreader_bc() # Preamble insert block self.inserter = correlator_cc.preamble_insert_cc() # Printer block self.printer = print_bb.print_bb() ntaps = 11 * int(options.samples_per_symbol) self.rrc_taps = gr.firdes.root_raised_cosine( 1.0, 1000000, symbol_rate, 1.0, ntaps) self.rrc_filter = gr.interp_fir_filter_ccf(1, self.rrc_taps) # Connect the blocks #self.connect(self.source, self.inserter) #self.connect(self.inserter, self.sink) #self.connect(self.source, self.spreader) #self.connect(TX_source_data, self.crctx) self.connect(self.packettx, self.crctx) #self.connect(self.crctx, self.printer) #self.connect(self.printer, self.encoder) self.connect(self.crctx, self.encoder) self.connect(self.encoder, self.spreader) #self.connect(self.source, self.spreader) self.connect(self.spreader, self.inserter) #self.connect(self.inserter, self.rrc_filter) #self.connect(self.rrc_filter, self.sink) self.connect(self.inserter, self.sink)
def __init__(self, options_tx, options_rx, callback): gr.top_block.__init__(self) self.init_pctime = 0 self.init_hwtime = 0 self.tx_outfile = options_tx.tx_outfile self._tx_amplitude = options_tx.tx_amplitude ####################################################################### # USRP Config # ####################################################################### tx_slave=False rx_slave=False if options_tx.tx_args != options_rx.rx_args: print "===Transceiver: enable MIMO mode, RX as slave, TX as master===" rx_slave=True if options_rx.mode == "PNC": rx_slave=False # lzyou: it seems that you MUST put rx before tx # otherwise something strange will happen (eg, not synced even the program tells you synced) d_rx_enable = True if options_rx.rx_freq is not None: source = uhd_receiver(options_rx.rx_args, options_rx.bandwidth, options_rx.rx_freq, options_rx.rx_gain, options_rx.spec, options_rx.antenna, options_rx.verbose, options_rx.external, rx_slave) #source.u.set_min_output_buffer(163840) elif options_rx.rx_infile is not None: source = blocks.file_source(gr.sizeof_gr_complex, options_rx.rx_infile) else: source = None d_rx_enable = False self.d_rx_enable = d_rx_enable self.source = source d_tx_enable = True if options_tx.tx_freq is not None: sink = uhd_transmitter(options_tx.tx_args, options_tx.bandwidth, options_tx.tx_freq, options_tx.tx_gain, options_tx.spec, options_tx.antenna, options_tx.verbose, options_tx.external, tx_slave) elif options_tx.tx_outfile is not None: sink = blocks.file_sink(gr.sizeof_gr_complex, options_tx.tx_outfile) else: sink = None d_tx_enable = False self.d_tx_enable = d_tx_enable self.sink = sink ####################################################################### # FIXME: support diff (tx/rx) framebytes self.framebytes = None ####################################################################### # Tx Path # ####################################################################### if d_tx_enable: self.tx = transmit_path.ofdm_transmit_path(options_tx) self.amp = blocks.multiply_const_cc(self._tx_amplitude) #self.amp.set_min_output_buffer(163840) self.connect(self.tx, self.amp, self.sink) self.framebytes = self.tx.framebytes ####################################################################### ####################################################################### # Rx Path # ####################################################################### # log usrp raw samples #if options_rx.mode == 'PNC': # self.connect(source, blocks.file_sink(gr.sizeof_gr_complex, '/tmp/PNCRXdiag.dat')) if options_rx.logfile: if options_rx.mode == 'PNC': self.connect(source, blocks.file_sink(gr.sizeof_gr_complex, '/tmp/PNCRXdiag.dat')) else: assert(options_rx.node != None) if options_rx.node == 'A': self.connect(source, blocks.file_sink(gr.sizeof_gr_complex, '/tmp/NodeARXdiag.dat')) elif options_rx.node == 'B': self.connect(source, blocks.file_sink(gr.sizeof_gr_complex, '/tmp/NodeBRXdiag.dat')) # setup receive_path if d_rx_enable: if options_rx.rx_outfile is not None: self.rx = blocks.file_sink(gr.sizeof_gr_complex, options_rx.rx_outfile) self.connect(self.source, self.rx) return self.rx = receive_path.ofdm_receive_path(options_rx, callback) #if self.framebytes is not None: # assert(self.framebytes == self.rx.framebytes) self.framebytes = self.rx.framebytes self.connect(self.source, self.rx) else: self.rx = None ####################################################################### if options_rx.profile: from gnuradio.ctrlport import monitor self.ctrlport_monitor = monitor() self.ctrlport_monitor_performance = monitor("gr-perf-monitorx")