X-Git-Url: https://git.gag.com/?a=blobdiff_plain;f=gnuradio-examples%2Fpython%2Fdigital%2Fbenchmark_loopback.py;h=e46bbdeeb8a8b9760d4b90a0fd99c87aba9fc678;hb=ee31bc0892dbd2c1d5ecae3a9ce9e54ed1bdf8c5;hp=34d25812e1b0babd8111c127decfb432b619bfc8;hpb=937b719d2e57d0497293d603da10cac2532346f6;p=debian%2Fgnuradio diff --git a/gnuradio-examples/python/digital/benchmark_loopback.py b/gnuradio-examples/python/digital/benchmark_loopback.py index 34d25812..e46bbdee 100755 --- a/gnuradio-examples/python/digital/benchmark_loopback.py +++ b/gnuradio-examples/python/digital/benchmark_loopback.py @@ -20,7 +20,7 @@ # Boston, MA 02110-1301, USA. # -from gnuradio import gr, gru, modulation_utils +from gnuradio import gr, gru, modulation_utils, blks2 from gnuradio import eng_notation from gnuradio.eng_option import eng_option from optparse import OptionParser @@ -32,35 +32,9 @@ from transmit_path_lb import transmit_path from receive_path_lb import receive_path import fusb_options -class awgn_channel(gr.hier_block): - def __init__(self, fg, sample_rate, noise_voltage, frequency_offset, seed=False): - self.input = gr.add_const_cc(0) # dummy input device - - # Create the Gaussian noise source - if not seed: - self.noise = gr.noise_source_c(gr.GR_GAUSSIAN, noise_voltage) - else: - rseed = int(time.time()) - self.noise = gr.noise_source_c(gr.GR_GAUSSIAN, noise_voltage, rseed) - - self.adder = gr.add_cc() - - # Create the frequency offset - self.offset = gr.sig_source_c(1, gr.GR_SIN_WAVE, - frequency_offset, 1.0, 0.0) - self.mixer = gr.multiply_cc() - - # Connect the components - fg.connect(self.input, (self.mixer, 0)) - fg.connect(self.offset, (self.mixer, 1)) - fg.connect(self.mixer, (self.adder, 0)) - fg.connect(self.noise, (self.adder, 1)) - - gr.hier_block.__init__(self, fg, self.input, self.adder) - -class my_graph(gr.flow_graph): +class my_top_block(gr.top_block): def __init__(self, mod_class, demod_class, rx_callback, options): - gr.flow_graph.__init__(self) + gr.top_block.__init__(self) channelon = True; @@ -71,13 +45,12 @@ class my_graph(gr.flow_graph): noise_power = power_in_signal/SNR noise_voltage = math.sqrt(noise_power) - self.txpath = transmit_path(self, mod_class, options) + self.txpath = transmit_path(mod_class, options) self.throttle = gr.throttle(gr.sizeof_gr_complex, options.sample_rate) - self.rxpath = receive_path(self, demod_class, rx_callback, options) + self.rxpath = receive_path(demod_class, rx_callback, options) if channelon: - self.channel = awgn_channel(self, options.sample_rate, noise_voltage, - frequency_offset, options.seed) + self.channel = blks2.channel_model(noise_voltage, frequency_offset, 1.01) if options.discontinuous: z = 20000*[0,] @@ -121,7 +94,7 @@ def main(): # print payload[2:len(payload)] def send_pkt(payload='', eof=False): - return fg.txpath.send_pkt(payload, eof) + return tb.txpath.send_pkt(payload, eof) mods = modulation_utils.type_1_mods() @@ -171,8 +144,8 @@ def main(): print "Warning: failed to enable realtime scheduling" # Create an instance of a hierarchical block - fg = my_graph(mods[options.modulation], demods[options.modulation], rx_callback, options) - fg.start() + tb = my_top_block(mods[options.modulation], demods[options.modulation], rx_callback, options) + tb.start() # generate and send packets nbytes = int(1e6 * options.megabytes) @@ -181,13 +154,13 @@ def main(): pkt_size = int(options.size) while n < nbytes: - send_pkt(struct.pack('!H', pktno) + (pkt_size - 2) * chr(pktno & 0xff)) + send_pkt(struct.pack('!H', pktno & 0xffff) + (pkt_size - 2) * chr(pktno & 0xff)) n += pkt_size pktno += 1 send_pkt(eof=True) - fg.wait() + tb.wait() if __name__ == '__main__': try: