コード例 #1
0
ファイル: benchmark_rx2.py プロジェクト: pgoeser/gnuradio
def main():
    global n_rcvd, n_right

    n_rcvd = 0
    n_right = 0
    
    def rx_callback(ok, payload):
        global n_rcvd, n_right
        (pktno,) = struct.unpack('!H', payload[0:2])
        n_rcvd += 1
        if ok:
            n_right += 1

        print "ok = %5s  pktno = %4d  n_rcvd = %4d  n_right = %4d" % (
            ok, pktno, n_rcvd, n_right)


    demods = modulation_utils2.type_1_demods()

    # Create Options Parser:
    parser = OptionParser (option_class=eng_option, conflict_handler="resolve")
    expert_grp = parser.add_option_group("Expert")

    parser.add_option("-m", "--modulation", type="choice", choices=demods.keys(), 
                      default='dbpsk2',
                      help="Select modulation from: %s [default=%%default]"
                            % (', '.join(demods.keys()),))

    usrp_receive_path2.add_options(parser, expert_grp)

    for mod in demods.values():
        mod.add_options(expert_grp)

    (options, args) = parser.parse_args ()

    if len(args) != 0:
        parser.print_help(sys.stderr)
        sys.exit(1)

    if options.rx_freq is None:
        sys.stderr.write("You must specify -f FREQ or --freq FREQ\n")
        parser.print_help(sys.stderr)
        sys.exit(1)


    # build the graph
    tb = my_top_block(demods[options.modulation], rx_callback, options)

    r = gr.enable_realtime_scheduling()
    if r != gr.RT_OK:
        print "Warning: Failed to enable realtime scheduling."

    tb.start()        # start flow graph
    tb.wait()         # wait for it to finish
コード例 #2
0
def main():

    global n_rcvd, n_right, pktno

    n_rcvd = 0
    n_right = 0
    pktno = 0
    
    def rx_callback(ok, payload):
        global n_rcvd, n_right, pktno
        (pktno,) = struct.unpack('!H', payload[0:2])
        n_rcvd += 1
        if ok:
            n_right += 1

        if not options.gui:
            print "ok = %5s  pktno = %4d  n_rcvd = %4d  n_right = %4d" % (
                ok, pktno, n_rcvd, n_right)
        

    def send_pkt(payload='', eof=False):
        return tb.txpath.send_pkt(payload, eof)

    mods = modulation_utils2.type_1_mods()
    demods = modulation_utils2.type_1_demods()

    parser = OptionParser(option_class=eng_option, conflict_handler="resolve")
    expert_grp = parser.add_option_group("Expert")
    channel_grp = parser.add_option_group("Channel")

    parser.add_option("-m", "--modulation", type="choice", choices=mods.keys(),
                      default='dbpsk2',
                      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("-G", "--gui", action="store_true", default=False,
                      help="Turn on the GUI [default=%default]")

    channel_grp.add_option("", "--sample-rate", type="eng_float", default=1e5,
                           help="set speed of channel/simulation rate to RATE [default=%default]") 
    channel_grp.add_option("", "--snr", type="eng_float", default=30,
                           help="set the SNR of the channel in dB [default=%default]")
    channel_grp.add_option("", "--frequency-offset", type="eng_float", default=0,
                           help="set frequency offset introduced by channel [default=%default]")
    channel_grp.add_option("", "--timing-offset", type="eng_float", default=1.0,
                           help="set timing offset introduced by channel [default=%default]")
    channel_grp.add_option("", "--seed", action="store_true", default=False,
                           help="use a random seed for AWGN noise [default=%default]")

    transmit_path.add_options(parser, expert_grp)
    receive_path.add_options(parser, expert_grp)

    for mod in mods.values():
        mod.add_options(expert_grp)
    for demod in demods.values():
        demod.add_options(expert_grp)

    (options, args) = parser.parse_args ()

    if len(args) != 0:
        parser.print_help()
        sys.exit(1)
        
    r = gr.enable_realtime_scheduling()
    if r != gr.RT_OK:
        print "Warning: failed to enable realtime scheduling"
        
    # Create an instance of a hierarchical block
    tb = my_top_block(mods[options.modulation],
                      demods[options.modulation],
                      rx_callback, options)
    tb.start()

    packet_sender = th_send(send_pkt, options.megabytes, options.size)
    packet_sender.start()

    if(options.gui):
        tb.qapp.exec_()
        packet_sender.stop()
    else:
        # Process until done; hack in to the join to stop on an interrupt
        while(packet_sender.isAlive()):
            try:
                packet_sender.join(1)
            except KeyboardInterrupt:
                packet_sender.stop()
コード例 #3
0
def main():

    global n_rcvd, n_right, pktno

    n_rcvd = 0
    n_right = 0
    pktno = 0

    def rx_callback(ok, payload):
        global n_rcvd, n_right, pktno
        (pktno, ) = struct.unpack('!H', payload[0:2])
        n_rcvd += 1
        if ok:
            n_right += 1

        if not options.gui:
            print "ok = %5s  pktno = %4d  n_rcvd = %4d  n_right = %4d" % (
                ok, pktno, n_rcvd, n_right)

    def send_pkt(payload='', eof=False):
        return tb.txpath.send_pkt(payload, eof)

    mods = modulation_utils2.type_1_mods()
    demods = modulation_utils2.type_1_demods()

    parser = OptionParser(option_class=eng_option, conflict_handler="resolve")
    expert_grp = parser.add_option_group("Expert")
    channel_grp = parser.add_option_group("Channel")

    parser.add_option("-m",
                      "--modulation",
                      type="choice",
                      choices=mods.keys(),
                      default='dbpsk2',
                      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("-G",
                      "--gui",
                      action="store_true",
                      default=False,
                      help="Turn on the GUI [default=%default]")

    channel_grp.add_option(
        "",
        "--sample-rate",
        type="eng_float",
        default=1e5,
        help="set speed of channel/simulation rate to RATE [default=%default]")
    channel_grp.add_option(
        "",
        "--snr",
        type="eng_float",
        default=30,
        help="set the SNR of the channel in dB [default=%default]")
    channel_grp.add_option(
        "",
        "--frequency-offset",
        type="eng_float",
        default=0,
        help="set frequency offset introduced by channel [default=%default]")
    channel_grp.add_option(
        "",
        "--timing-offset",
        type="eng_float",
        default=1.0,
        help="set timing offset introduced by channel [default=%default]")
    channel_grp.add_option(
        "",
        "--seed",
        action="store_true",
        default=False,
        help="use a random seed for AWGN noise [default=%default]")

    transmit_path.add_options(parser, expert_grp)
    receive_path.add_options(parser, expert_grp)

    for mod in mods.values():
        mod.add_options(expert_grp)
    for demod in demods.values():
        demod.add_options(expert_grp)

    (options, args) = parser.parse_args()

    if len(args) != 0:
        parser.print_help()
        sys.exit(1)

    r = gr.enable_realtime_scheduling()
    if r != gr.RT_OK:
        print "Warning: failed to enable realtime scheduling"

    # Create an instance of a hierarchical block
    tb = my_top_block(mods[options.modulation], demods[options.modulation],
                      rx_callback, options)
    tb.start()

    packet_sender = th_send(send_pkt, options.megabytes, options.size)
    packet_sender.start()

    if (options.gui):
        tb.qapp.exec_()
        packet_sender.stop()
    else:
        # Process until done; hack in to the join to stop on an interrupt
        while (packet_sender.isAlive()):
            try:
                packet_sender.join(1)
            except KeyboardInterrupt:
                packet_sender.stop()