コード例 #1
0
ファイル: ofdm_tx.py プロジェクト: suiody/graduate_demo
    def __init__(self, midFreq, fft_len, occupied_len, cp_len, inter):
        if midFreq == None or fft_len == None or \
            occupied_len == None or cp_len == None:
            print 'param is not ok!'
            return
        args = ['--tx-amplitude', '5000', '-i', str(inter), '-T', 'B', '-v']
        args.append('-f')
        args.append(str(midFreq))
        args.append('--fft-length')
        args.append(str(fft_len))
        args.append('--occupied-tones')
        args.append(str(occupied_len))
        args.append('--cp-length')
        args.append(str(cp_len))

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

        my_top_block.add_options(parser, expert_grp)
        transmit_path.add_options(parser, expert_grp)
        blks2.ofdm_mod.add_options(parser, expert_grp)
        blks2.ofdm_demod.add_options(parser, expert_grp)
        fusb_options.add_options(expert_grp)

        (options, args) = parser.parse_args(args)

        self.tb = my_top_block(options)

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

        self.tb.start()
        print 'tx init ok!'
コード例 #2
0
    def add_options(normal, expert):
        """
        Adds usrp-specific options to the Options Parser
        """
        add_freq_option(normal)
        normal.add_option("-T", "--tx-subdev-spec", type="subdev", default=None,
                          help="select USRP Tx side A or B")
        normal.add_option("-v", "--verbose", action="store_true", default=False)

        expert.add_option("", "--tx-freq", type="eng_float", default=None,
                          help="set transmit frequency to FREQ [default=%default]", metavar="FREQ")
        expert.add_option("-i", "--interp", type="intx", default=256,
                          help="set fpga interpolation rate to INTERP [default=%default]")
       
        normal.add_option("-R", "--rx-subdev-spec", type="subdev", default=None,
                          help="select USRP Rx side A or B")
        normal.add_option("", "--rx-gain", type="eng_float", default=None, metavar="GAIN",
                          help="set receiver gain in dB [default=midpoint].  See also --show-rx-gain-range")
        normal.add_option("", "--show-rx-gain-range", action="store_true", default=False, 
                          help="print min and max Rx gain available on selected daughterboard")
        normal.add_option("-v", "--verbose", action="store_true", default=False)

        expert.add_option("", "--rx-freq", type="eng_float", default=None,
                          help="set Rx frequency to FREQ [default=%default]", metavar="FREQ")
        expert.add_option("-d", "--decim", type="intx", default=128,
                          help="set fpga decimation rate to DECIM [default=%default]")
        expert.add_option("", "--snr", type="eng_float", default=30,
                          help="set the SNR of the channel in dB [default=%default]")

        #other necessary options
        transmit_path.add_options(normal, expert)
        receive_path.add_options(normal, expert)
        blks2.ofdm_mod.add_options(normal, expert)
        blks2.ofdm_demod.add_options(normal, expert)
        fusb_options.add_options(expert)
コード例 #3
0
def main():
    global n_rcvd, n_right

    n_rcvd = 0
    n_right = 0
    
    def rx_callback(ok, payload):
        global n_rcvd, n_right
        n_rcvd += 1
        if ok:
            n_right += 1

        fg.audio_tx.msgq().insert_tail(gr.message_from_string(payload))
        
        print "ok = %r  n_rcvd = %4d  n_right = %4d" % (
            ok, n_rcvd, n_right)

    demods = modulation_utils.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='gmsk',
                      help="Select modulation from: %s [default=%%default]"
                            % (', '.join(demods.keys()),))
    parser.add_option("-O", "--audio-output", type="string", default="",
                      help="pcm output device name.  E.g., hw:0,0 or /dev/dsp")

    receive_path.add_options(parser, expert_grp)

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

    fusb_options.add_options(expert_grp)

    parser.set_defaults(bitrate=50e3)  # override default bitrate default
    (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.run()
コード例 #4
0
def main():
    parser = OptionParser(conflict_handler="resolve")
    expert_grp = parser.add_option_group("Expert")

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

    parser.add_option("-c",
                      "--cfg",
                      action="store",
                      type="string",
                      default=None,
                      help="Specifiy configuration file, default: none",
                      config="false")

    (options, args) = parser.parse_args()

    if options.cfg is not None:
        (options, args) = parser.parse_args(files=[options.cfg])
        print "Using configuration file %s" % (options.cfg)

    benchmark = ofdm_mrrc_benchmark(options)
    runtime = benchmark

    r = gr.enable_realtime_scheduling()
    if r != gr.RT_OK:
        print "Couldn't enable realtime scheduling"
    else:
        print "Enabled realtime scheduling"

    try:
        if options.dot_graph:
            string_benchmark = runtime.dot_graph()
            filetx = os.path.expanduser('benchmark_mrrc_ofdm.dot')
            dot_file = open(filetx, 'w')
            dot_file.write(string_benchmark)
            dot_file.close()

        runtime.run()
        #runtime.start()
        try:
            tx.txpath._control._id_source.ready()
        except:
            pass

    except KeyboardInterrupt:
        runtime.stop()

        runtime.wait()

    if options.measure:
        print "min", tx.m.get_min()
        print "max", tx.m.get_max()
        print "avg", tx.m.get_avg()
コード例 #5
0
def main():
  parser = OptionParser(conflict_handler="resolve")
  expert_grp = parser.add_option_group("Expert")

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

  parser.add_option( 
    "-c", "--cfg",
    action="store", type="string", default=None,
    help="Specifiy configuration file, default: none",
    config="false" )
  
  (options, args) = parser.parse_args()
  
  if options.cfg is not None:
    (options,args) = parser.parse_args(files=[options.cfg])
    print "Using configuration file %s" % ( options.cfg )

  benchmark = ofdm_mrrc_benchmark(options)
  runtime = benchmark

  r = gr.enable_realtime_scheduling()
  if r != gr.RT_OK:
    print "Couldn't enable realtime scheduling"
  else:
    print "Enabled realtime scheduling"

  try:
    if options.dot_graph:
      string_benchmark = runtime.dot_graph()
      filetx = os.path.expanduser('benchmark_mrrc_ofdm.dot')
      dot_file = open(filetx,'w')
      dot_file.write(string_benchmark)
      dot_file.close()
    
    runtime.run()
    #runtime.start()
    try:
      tx.txpath._control._id_source.ready()
    except:
      pass
  
  except KeyboardInterrupt:
    runtime.stop()

    runtime.wait()
    

  if options.measure:
    print "min",tx.m.get_min()
    print "max",tx.m.get_max()
    print "avg",tx.m.get_avg()
コード例 #6
0
def main():
    def send_pkt(payload='', eof=False):
        return tb.txpath.send_pkt(payload, eof)

    parser = OptionParser(option_class=eng_option, conflict_handler="resolve")
    expert_grp = parser.add_option_group("Expert")
    parser.add_option("-s",
                      "--size",
                      type="eng_float",
                      default=400,
                      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 discontinuous mode")

    my_top_block.add_options(parser, expert_grp)
    transmit_path.add_options(parser, expert_grp)
    blks2.ofdm_mod.add_options(parser, expert_grp)
    blks2.ofdm_demod.add_options(parser, expert_grp)
    fusb_options.add_options(expert_grp)

    (options, args) = parser.parse_args()

    # build the graph
    tb = my_top_block(options)

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

    tb.start()  # start flow graph

    # generate and send packets
    nbytes = int(1e6 * options.megabytes)
    n = 0
    pktno = 0
    pkt_size = int(options.size)

    while n < nbytes:
        send_pkt(struct.pack('!H', pktno) + (pkt_size - 2) * chr(pktno & 0xff))
        n += pkt_size
        sys.stderr.write('.')
        if options.discontinuous and pktno % 5 == 1:
            time.sleep(1)
        pktno += 1

    send_pkt(eof=True)
    tb.wait()  # wait for it to finish
コード例 #7
0
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_utils.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='gmsk',
                      help="Select modulation from: %s [default=%%default]"
                            % (', '.join(demods.keys()),))

    receive_path.add_options(parser, expert_grp)

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

    fusb_options.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
コード例 #8
0
ファイル: benchmark_ofdm_rx.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
        n_rcvd += 1
        (pktno, ) = struct.unpack('!H', payload[0:2])
        if ok:
            n_right += 1
        print "ok: %r \t pktno: %d \t n_rcvd: %d \t n_right: %d" % (
            ok, pktno, n_rcvd, n_right)

        if 0:
            printlst = list()
            for x in payload[2:]:
                t = hex(ord(x)).replace('0x', '')
                if (len(t) == 1):
                    t = '0' + t
                printlst.append(t)
            printable = ''.join(printlst)

            print printable
            print "\n"

    parser = OptionParser(option_class=eng_option, conflict_handler="resolve")
    expert_grp = parser.add_option_group("Expert")
    parser.add_option("",
                      "--discontinuous",
                      action="store_true",
                      default=False,
                      help="enable discontinuous")

    my_top_block.add_options(parser, expert_grp)
    receive_path.add_options(parser, expert_grp)
    blks2.ofdm_mod.add_options(parser, expert_grp)
    blks2.ofdm_demod.add_options(parser, expert_grp)
    fusb_options.add_options(expert_grp)

    (options, args) = parser.parse_args()

    # build the graph
    tb = my_top_block(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
コード例 #9
0
def main():
    parser = OptionParser(conflict_handler="resolve")
    expert_grp = parser.add_option_group("Expert")

    ofdm_tx.add_options(parser, expert_grp)
    transmit_path.add_options(parser, expert_grp)
    fusb_options.add_options(expert_grp)

    parser.add_option("-c",
                      "--cfg",
                      action="store",
                      type="string",
                      default=None,
                      help="Specifiy configuration file, default: none",
                      config="false")

    (options, args) = parser.parse_args()

    if options.cfg is not None:
        (options, args) = parser.parse_args(files=[options.cfg])
        print "Using configuration file %s" % (options.cfg)

    tx = ofdm_tx(options)
    runtime = tx

    r = gr.enable_realtime_scheduling()
    if r != gr.RT_OK:
        print "Couldn't enable realtime scheduling"
    else:
        print "Enabled realtime scheduling"

    try:
        orb = CORBA.ORB_init(sys.argv, CORBA.ORB_ID)
        string_tx = runtime.dot_graph()

        dot_file = open("text_tx.dot", 'w')
        dot_file.write(string_tx)
        dot_file.close()

        runtime.start()
        try:
            tx.txpath._control._id_source.ready()
        except:
            pass
        orb.run()
    except KeyboardInterrupt:
        runtime.stop()
        runtime.wait()

    if options.measure:
        print "min", tx.m.get_min()
        print "max", tx.m.get_max()
        print "avg", tx.m.get_avg()
コード例 #10
0
ファイル: tx_n.py プロジェクト: WindyCitySDR/gr-ofdm
def main():
  parser = OptionParser(conflict_handler="resolve")
  expert_grp = parser.add_option_group("Expert")

  ofdm_tx.add_options(parser, expert_grp)
  transmit_path.add_options(parser, expert_grp)
  fusb_options.add_options(expert_grp)

  parser.add_option( 
    "-c", "--cfg",
    action="store", type="string", default=None,
    help="Specifiy configuration file, default: none",
    config="false" )
  
  (options, args) = parser.parse_args()
  
  if options.cfg is not None:
    (options,args) = parser.parse_args(files=[options.cfg])
    print "Using configuration file %s" % ( options.cfg )

  tx = ofdm_tx(options)
  runtime = tx

  r = gr.enable_realtime_scheduling()
  if r != gr.RT_OK:
    print "Couldn't enable realtime scheduling"
  else:
    print "Enabled realtime scheduling"

  try:
    orb = CORBA.ORB_init(sys.argv,CORBA.ORB_ID)
    string_tx = runtime.dot_graph()
    
    dot_file = open("text_tx.dot",'w')
    dot_file.write(string_tx)
    dot_file.close()
    
    runtime.start()
    try:
      tx.txpath._control._id_source.ready()
    except:
      pass
    orb.run()
  except KeyboardInterrupt:
    runtime.stop()
    runtime.wait()

  if options.measure:
    print "min",tx.m.get_min()
    print "max",tx.m.get_max()
    print "avg",tx.m.get_avg()
コード例 #11
0
ファイル: benchmark_ofdm_rx.py プロジェクト: GREO/GNU-Radio
def main():

    global n_rcvd, n_right
        
    n_rcvd = 0
    n_right = 0

    def rx_callback(ok, payload):
        global n_rcvd, n_right
        n_rcvd += 1
        (pktno,) = struct.unpack('!H', payload[0:2])
        if ok:
            n_right += 1
        print "ok: %r \t pktno: %d \t n_rcvd: %d \t n_right: %d" % (ok, pktno, n_rcvd, n_right)

        if 0:
            printlst = list()
            for x in payload[2:]:
                t = hex(ord(x)).replace('0x', '')
                if(len(t) == 1):
                    t = '0' + t
                printlst.append(t)
            printable = ''.join(printlst)

            print printable
            print "\n"

    parser = OptionParser(option_class=eng_option, conflict_handler="resolve")
    expert_grp = parser.add_option_group("Expert")
    parser.add_option("","--discontinuous", action="store_true", default=False,
                      help="enable discontinuous")

    my_top_block.add_options(parser, expert_grp)
    receive_path.add_options(parser, expert_grp)
    blks2.ofdm_mod.add_options(parser, expert_grp)
    blks2.ofdm_demod.add_options(parser, expert_grp)
    fusb_options.add_options(expert_grp)

    (options, args) = parser.parse_args ()

    # build the graph
    tb = my_top_block(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
コード例 #12
0
def main():

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

    parser = OptionParser(option_class=eng_option, conflict_handler="resolve")
    expert_grp = parser.add_option_group("Expert")
    parser.add_option("-s", "--size", type="eng_float", default=400,
                      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 discontinuous mode")

    my_top_block.add_options(parser, expert_grp)
    transmit_path.add_options(parser, expert_grp)
    gr_papyrus.ofdm.ofdm_mod.add_options(parser, expert_grp)
    gr_papyrus.ofdm.ofdm_demod.add_options(parser, expert_grp)
    fusb_options.add_options(expert_grp)

    (options, args) = parser.parse_args ()

    # build the graph
    tb = my_top_block(options)
    
    r = gr.enable_realtime_scheduling()
    if r != gr.RT_OK:
        print "Warning: failed to enable realtime scheduling"

    tb.start()                       # start flow graph
    
    # generate and send packets
    nbytes = int(1e6 * options.megabytes)
    n = 0
    pktno = 0
    pkt_size = int(options.size)

    while n < nbytes:
        send_pkt(struct.pack('!H', pktno) + (pkt_size - 2) * chr(pktno & 0xff))
        n += pkt_size
        sys.stderr.write('.')
        if options.discontinuous and pktno % 5 == 1:
            time.sleep(1)
        pktno += 1
        
    send_pkt(eof=True)
    tb.wait()                       # wait for it to finish
コード例 #13
0
    def __init__(self,
                 midFreq,
                 fft_len,
                 occupied_len,
                 cp_len,
                 dinter,
                 callback=None):
        if midFreq == None or fft_len == None or \
            occupied_len == None or cp_len == None:
            print 'param is not ok!'
            return

        if callback == None:
            callback = self.rx_callback
        args = ['-d', str(dinter), '-R', 'B', '-v']
        args.append('-f')
        args.append(str(midFreq))
        args.append('--fft-length')
        args.append(str(fft_len))
        args.append('--occupied-tones')
        args.append(str(occupied_len))
        args.append('--cp-length')
        args.append(str(cp_len))

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

        my_top_block.add_options(parser, expert_grp)
        receive_path.add_options(parser, expert_grp)
        blks2.ofdm_mod.add_options(parser, expert_grp)
        blks2.ofdm_demod.add_options(parser, expert_grp)
        fusb_options.add_options(expert_grp)

        (options, args) = parser.parse_args(args)

        self.tb = my_top_block(callback, options)

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

        self.n_rcvd = 0
        self.n_right = 0

        print 'rx init ok!'
コード例 #14
0
ファイル: ofdm_rx.py プロジェクト: jfwang213/graduate_demo
    def __init__(self, midFreq, fft_len, occupied_len, cp_len, dinter, callback = None):
        if midFreq == None or fft_len == None or \
            occupied_len == None or cp_len == None:
            print 'param is not ok!'
            return

        if callback == None:
            callback = self.rx_callback
        args = ['-d', str(dinter), '-R', 'B', '-v']        
        args.append('-f')
        args.append(str(midFreq))
        args.append('--fft-length')
        args.append(str(fft_len))
        args.append('--occupied-tones')
        args.append(str(occupied_len))
        args.append('--cp-length')
        args.append(str(cp_len))
        
        parser = OptionParser(option_class=eng_option, conflict_handler="resolve")
        expert_grp = parser.add_option_group("Expert")

        my_top_block.add_options(parser, expert_grp)
        receive_path.add_options(parser, expert_grp)
        blks2.ofdm_mod.add_options(parser, expert_grp)
        blks2.ofdm_demod.add_options(parser, expert_grp)
        fusb_options.add_options(expert_grp)

        (options, args) = parser.parse_args (args)
        
        self.tb = my_top_block(callback, options)

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

        self.n_rcvd = 0
        self.n_right = 0
        
        print 'rx init ok!'
コード例 #15
0
ファイル: ssma.py プロジェクト: tyc85/nwsdr-3.6.3-dsc
def main():

    global n_right
    n_right = 0 

    start_time = time.time()

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

    parser.add_option("-m", "--modulation", type="choice", choices=['bpsk', 'qpsk'],
                      default='bpsk',
                      help="Select modulation from: bpsk, qpsk [default=%%default]")
    expert_grp.add_option("-c", "--carrier-threshold", type="eng_float", default=40,
                      help="set carrier detect threshold (dB) [default=%default]")

    parser.add_option("-v","--verbose", action="store_true", default=False)

    # linklab, add option to indicate sender or receiver
    parser.add_option("-s","--sender", action="store_true", default=False)
    parser.add_option("-r","--receiver", action="store_true", default=False)


    usrp_graph.add_options(parser, expert_grp)
    transmit_path.add_options(parser, expert_grp)
    receive_path.add_options(parser, expert_grp)
    blks2.ofdm_mod.add_options(parser, expert_grp)
    blks2.ofdm_demod.add_options(parser, expert_grp)

    fusb_options.add_options(expert_grp)

    (options, args) = parser.parse_args ()
    options.carrier_map = SYNC_MAP
    
    if len(args) != 0:
        parser.print_help(sys.stderr)
        sys.exit(1)

    if options.rx_freq is None or options.tx_freq is None:
        sys.stderr.write("You must specify -f FREQ or --freq FREQ\n")
        parser.print_help(sys.stderr)
        sys.exit(1)
    
	# linklab, check if the current node is either a sender or a receiver
    if options.sender and options.receiver:
        sys.stderr.write("You cannot specify both sender and receiver\n")
        sys.exit(1)
    if (not options.sender) and (not options.receiver):
        sys.stderr.write("You must specify either sender or receiver\n")
        sys.exit(1)
    #

    # Attempt to enable realtime scheduling
    r = gr.enable_realtime_scheduling()
    if r == gr.RT_OK:
        realtime = True
    else:
        realtime = False
        print "Note: failed to enable realtime scheduling"


    # If the user hasn't set the fusb_* parameters on the command line,
    # pick some values that will reduce latency.

    if options.fusb_block_size == 0 and options.fusb_nblocks == 0:
        if realtime:                        # be more aggressive
            options.fusb_block_size = gr.prefs().get_long('fusb', 'rt_block_size', 1024)
            options.fusb_nblocks    = gr.prefs().get_long('fusb', 'rt_nblocks', 16)
        else:
            options.fusb_block_size = gr.prefs().get_long('fusb', 'block_size', 4096)
            options.fusb_nblocks    = gr.prefs().get_long('fusb', 'nblocks', 16)
    
    #print "fusb_block_size =", options.fusb_block_size
    #print "fusb_nblocks    =", options.fusb_nblocks

    # instantiate the MAC
    # linklab, use ssma instead of csma
	mac = ss_mac(options.sender, start_time, verbose=True)

    # update freq_offset
    options.rx_freq += get_freq_offset()
    options.tx_freq += get_freq_offset()
    print "RX frequency", options.rx_freq
    print "TX frequency", options.tx_freq

    # build the graph (PHY)
    tb = usrp_graph(mac.ReceivePacket, options)

    mac.set_flow_graph(tb)    # give the MAC a handle for the PHY

    #if fg.txpath.bitrate() != fg.rxpath.bitrate():
    #    print "WARNING: Transmit bitrate = %sb/sec, Receive bitrate = %sb/sec" % (
    #        eng_notation.num_to_str(fg.txpath.bitrate()),
    #        eng_notation.num_to_str(fg.rxpath.bitrate()))
             
    print "modulation:     %s"   % (options.modulation,)
    print "freq:           %s"      % (eng_notation.num_to_str(options.tx_freq))
    # print "bitrate:        %sb/sec" % (eng_notation.num_to_str(tb.txpath.bitrate()),)
    # print "samples/symbol: %3d" % (tb.txpath.samples_per_symbol(),)
    # print "interp:         %3d" % (tb.txpath.interp(),)
    # print "decim:          %3d" % (tb.rxpath.decim(),)


    tb.start()    # Start executing the flow graph (runs in separate threads)

    mac.main_loop()    # don't expect this to return...
    while 1:
        pass
コード例 #16
0
def main():
    mac_addr = '00:00:00:00:00:01'
    
    mac = senderMAC(mac_addr)
    
    def send_pkt(payload):
        tb.send_pkt(payload)

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

    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='gmsk',
                      help="Select modulation from: %s [default=%%default]"
                            % (', '.join(mods.keys()),))

    parser.add_option("-v","--verbose", action="store_true", default=False)
    expert_grp.add_option("-c", "--carrier-threshold", type="eng_float", default=30,
                          help="set carrier detect threshold (dB) [default=%default]")
    expert_grp.add_option("","--tun-device-filename", default="/dev/net/tun",
                          help="path to tun device file [default=%default]")
    parser.add_option("","--filename", default=None,
                      help="use file for packet contents")

    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)

    fusb_options.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 or options.tx_freq is None:
        sys.stderr.write("You must specify -f FREQ or --freq FREQ\n")
        parser.print_help(sys.stderr)
        sys.exit(1)

    if options.filename is None:
        print 'no file specified'
        


    # Attempt to enable realtime scheduling
    r = gr.enable_realtime_scheduling()
    if r == gr.RT_OK:
        realtime = True
    else:
        realtime = False
        print "Note: failed to enable realtime scheduling"


    # If the user hasn't set the fusb_* parameters on the command line,
    # pick some values that will reduce latency.

    if options.fusb_block_size == 0 and options.fusb_nblocks == 0:
        if realtime:                        # be more aggressive
            options.fusb_block_size = gr.prefs().get_long('fusb', 'rt_block_size', 1024)
            options.fusb_nblocks    = gr.prefs().get_long('fusb', 'rt_nblocks', 16)
        else:
            options.fusb_block_size = gr.prefs().get_long('fusb', 'block_size', 4096)
            options.fusb_nblocks    = gr.prefs().get_long('fusb', 'nblocks', 16)
    

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

    #mac.set_top_block(tb)    # give the MAC a handle for the PHY

    if tb.txpath.bitrate() != tb.rxpath.bitrate():
        print "WARNING: Transmit bitrate = %sb/sec, Receive bitrate = %sb/sec" % (
            eng_notation.num_to_str(tb.txpath.bitrate()),
            eng_notation.num_to_str(tb.rxpath.bitrate()))
             
    print "modulation:     %s"   % (options.modulation,)
    print "freq:           %s"      % (eng_notation.num_to_str(options.tx_freq))
    print "bitrate:        %sb/sec" % (eng_notation.num_to_str(tb.txpath.bitrate()),)
    print "samples/symbol: %3d" % (tb.txpath.samples_per_symbol(),)


    tb.rxpath.set_carrier_threshold(options.carrier_threshold)
    print "Carrier sense threshold:", options.carrier_threshold, "dB"
    
    tb.start()    # Start executing the flow graph (runs in separate threads)
    f = open(options.filename,"rb")
    bytesread = f.read(1318)
    print "read bytes of size %u" % len(bytesread)
    while len(bytesread)>0:
        print "read bytes of size %u" % len(bytesread)
        mac.Send(bytesread)
        bytesread = f.read(1318)
    tb.wait()     # wait for it to finish
コード例 #17
0
ファイル: usrp_tos.py プロジェクト: nesl/uant
def main():

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

    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='gmsk',
                      help="Select modulation from: %s [default=%%default]"
                            % (', '.join(mods.keys()),))

    parser.add_option("-v","--verbose", action="store_true", default=False)
    parser.add_option("-n", "--nodeid", type="int", default=None,
                              help="specify node ID")
    expert_grp.add_option("-c", "--carrier-threshold", type="eng_float", default=30,
                          help="set carrier detect threshold (dB) [default=%default]")
    expert_grp.add_option("","--tun-device-filename", default="/dev/net/tun",
                          help="path to tun device file [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)

    fusb_options.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 or options.tx_freq is None:
        sys.stderr.write("You must specify -f FREQ or --freq FREQ\n")
        parser.print_help(sys.stderr)
        sys.exit(1)

    # open the TUN/TAP interface
    #(tun_fd, tun_ifname) = open_tun_interface(options.tun_device_filename)

    # Attempt to enable realtime scheduling
    r = gr.enable_realtime_scheduling()
    if r == gr.RT_OK:
        realtime = True
    else:
        realtime = False
        print "Note: failed to enable realtime scheduling"


    # If the user hasn't set the fusb_* parameters on the command line,
    # pick some values that will reduce latency.

    if options.fusb_block_size == 0 and options.fusb_nblocks == 0:
        if realtime:                        # be more aggressive
            options.fusb_block_size = gr.prefs().get_long('fusb', 'rt_block_size', 1024)
            options.fusb_nblocks    = gr.prefs().get_long('fusb', 'rt_nblocks', 16)
        else:
            options.fusb_block_size = gr.prefs().get_long('fusb', 'block_size', 4096)
            options.fusb_nblocks    = gr.prefs().get_long('fusb', 'nblocks', 16)
    
    #print "fusb_block_size =", options.fusb_block_size
    #print "fusb_nblocks    =", options.fusb_nblocks

    # instantiate the MAC
    mac = cs_mac(verbose=False)

    # build the graph (PHY)
    tb = my_top_block(mods[options.modulation],
                      demods[options.modulation],
                      mac.phy_rx_callback,
                      options)

    mac.set_top_block(tb)    # give the MAC a handle for the PHY

    if tb.txpath.bitrate() != tb.rxpath.bitrate():
        print "WARNING: Transmit bitrate = %sb/sec, Receive bitrate = %sb/sec" % (
            eng_notation.num_to_str(tb.txpath.bitrate()),
            eng_notation.num_to_str(tb.rxpath.bitrate()))
             
    print "modulation:     %s"   % (options.modulation,)
    print "freq:           %s"      % (eng_notation.num_to_str(options.tx_freq))
    print "bitrate:        %sb/sec" % (eng_notation.num_to_str(tb.txpath.bitrate()),)
    print "samples/symbol: %3d" % (tb.txpath.samples_per_symbol(),)
    #print "interp:         %3d" % (tb.txpath.interp(),)
    #print "decim:          %3d" % (tb.rxpath.decim(),)

    tb.rxpath.set_carrier_threshold(options.carrier_threshold)


    tb.start()    # Start executing the flow graph (runs in separate threads)
コード例 #18
0
ファイル: simple_mac.py プロジェクト: phoorichet/bbn_80211
def main():

    tun_device_default = "/dev/net/tun"
    if (platform.system() == 'FreeBSD' or platform.system() == 'NetBSD'):
       tun_device_default = "/dev/tap"

    parser = OptionParser (option_class=eng_option, 
	                   usage="usage: %prog [options] [ipaddr=macaddr] ...")
    parser.add_option("-f", "--freq", type="eng_float", default=423.1e6,
                       help="set Tx and Rx frequency to FREQ [default=%default]", metavar="FREQ")
    parser.add_option("-r", "--bitrate", type="eng_float", default=None,
                      help="specify bitrate.  spb and interp will be derived.")
    parser.add_option("-g", "--rx-gain", type="eng_float", default=27,
                      help="set rx gain")
    parser.add_option("-p", "--tx-gain", type="eng_float", default=100,
                      help="set tx gain")
    parser.add_option("-T", "--tx-subdev-spec", type="subdev", default=None,
                      help="select USRP Tx side A or B")
    parser.add_option("-R", "--rx-subdev-spec", type="subdev", default=None,
                      help="select USRP Rx side A or B")
    parser.add_option("-S", "--spb", type="int", default=None, help="set samples/baud [default=%default]")
    parser.add_option("-d", "--decim", type="intx", default=None,
                      help="set fpga decim rate to DECIM [default=%default]")
    parser.add_option("-i", "--interp", type="intx", default=None,
                      help="set fpga interpolation rate to INTERP [default=%default]")
    parser.add_option("-c", "--carrier-threshold", type="eng_float", default=30,
                      help="set carrier detect threshold (dB) [default=%default]")
    parser.add_option("", "--bt", type="float", default=0.3, help="set bandwidth-time product [default=%default]")
    parser.add_option("","--tun-device-filename", default=tun_device_default,
                      help="path to tun device file [default=%default]")
    parser.add_option("-b","--bssid", default="00:00:00:00:00:00", 
		    help="set bssid for network in the form xx:xx:xx:xx:xx:xx")
    parser.add_option("","--tun", action="store_true", default=False, 
		    help="use tun device instead of tap to pass packets.")
    parser.add_option("","--macfile", default="simple-config", 
                    help="filename containing a set of ipaddr=macaddr mappings, only needed with --tun.")
    parser.add_option("-v","--verbose", action="store_true", default=False)
    fusb_options.add_options(parser)
    (options, args) = parser.parse_args ()

    bssid = validate_mac_addr(options.bssid)
    if bssid == 0:
	print "Invalid BSSID ", options.bssid
        parser.print_help()
        sys.exit(1)

    if options.freq < 1e6:
        options.freq *= 1e6

    mod_kwargs = {
        'bt' : options.bt,
        }

    pkttype = 'eth'
    tuntype = 'tap'
    mcache = None
    if options.tun:
        pkttype = 'ip'
        tuntype = 'tun'
   
        # If a file of IP address to MAC address mappings has been provided,
        # open it and read it in.  Since the format is the same as the command
        # line mappings, add it to the end of the args list so they can both
        # be processed at the same time
        if options.macfile != None:
            try: 
      	        config = file(options.macfile, 'r')
                for line in config:
                    line = line.strip()
                    # skip blank lines
                    if line == '':
                       continue
                    # skip comment lines
                    if line[0] == '#':
                       continue
                    args.append(line)
                config.close()
            except IOError:
                print "Cannot open configuration file: ", options.macfile

        # remove the mac addr.  
        # The remaining arguments should be ip->mac mappings
	del args[0]
        mcache = mac_cache()
        for map in args:
            addrs = map.split('=', 1)
            if len(addrs) != 2:
               print "Invalid ipaddr=macaddr mapping ", map
               parser.print_help()
               sys.exit(1)
            try: 
               ipaddr = socket.inet_aton(addrs[0])
            except socket.error:
      	       print "Invalid IP addr ", addrs[0]
               parser.print_help()
               sys.exit(1)
            macaddr = validate_mac_addr(addrs[1])
            if macaddr == 0:
	       print "Invalid MAC addr ", addrs[1]
               parser.print_help()
               sys.exit(1)
            mcache.add(ipaddr, macaddr)
        if options.verbose:
            print "Configured MAC addresses:"
            mcache.print_map()
    # end if options.tun
        

    # open the TUN/TAP interface
    (tun_fd, tun_ifname) = open_tun_interface(tuntype, options.tun_device_filename)
    tun_mac = get_mac_for_interface(tun_ifname)
    mac_addr = validate_mac_addr(tun_mac)
    if mac_addr == 0:
        print "Invalid MAC address ", tun_mac, " for interface ", tun_ifname
	print "exiting."
        sys.exit(1)
    if options.verbose:
        print "Using MAC address ", tun_mac, " for interface ", tun_ifname


    # Attempt to enable realtime scheduling
    r = gr.enable_realtime_scheduling()
    if r == gr.RT_OK:
        realtime = True
    else:
        realtime = False
        print "Note: failed to enable realtime scheduling"


    # If the user hasn't set the fusb_* parameters on the command line,
    # pick some values that will reduce latency.

    if options.fusb_block_size == 0 and options.fusb_nblocks == 0:
        if realtime:                        # be more aggressive
            options.fusb_block_size = gr.prefs().get_long('fusb', 'rt_block_size', 1024)
            options.fusb_nblocks    = gr.prefs().get_long('fusb', 'rt_nblocks', 16)
        else:
            options.fusb_block_size = gr.prefs().get_long('fusb', 'block_size', 4096)
            options.fusb_nblocks    = gr.prefs().get_long('fusb', 'nblocks', 16)
    
    print "fusb_block_size =", options.fusb_block_size
    print "fusb_nblocks    =", options.fusb_nblocks

    # instantiate the MAC
    mac = cs_mac(tun_fd, mac_addr, pkttype, bssid, mcache, verbose=True)


    # build the graph (PHY)
    fg = my_graph(blks.gmsk2_mod, blks.gmsk2_demod,
                  options.tx_subdev_spec, options.rx_subdev_spec,
                  mac.phy_rx_callback, 
                  options, mod_kwargs)

    mac.set_flow_graph(fg)    # give the MAC a handle for the PHY

    if fg.txpath.bitrate() != fg.rxpath.bitrate():
        print "WARNING: Transmit bitrate = %sb/sec, Receive bitrate = %sb/sec" % (
            eng_notation.num_to_str(fg.txpath.bitrate()),
            eng_notation.num_to_str(fg.rxpath.bitrate()))
             
    print "bitrate: %sb/sec" % (eng_notation.num_to_str(fg.txpath.bitrate()),)
    print "spb:     %3d" % (fg.txpath.spb(),)
    print "interp:  %3d" % (fg.txpath.interp(),)

    ok = fg.txpath.set_freq(options.freq)
    if not ok:
        print "Failed to set Tx frequency to %s" % (eng_notation.num_to_str(options.freq),)
        raise SystemExit

    ok = fg.rxpath.set_freq(options.freq)
    if not ok:
        print "Failed to set Rx frequency to %s" % (eng_notation.num_to_str(options.freq),)
        raise SystemExit

    fg.rxpath.set_gain(options.rx_gain)
    print "Rx gain_range: ", fg.rxpath.subdev.gain_range(), " using", fg.rxpath.gain

    fg.rxpath.set_carrier_threshold(options.carrier_threshold)
    print "Carrier sense threshold:", options.carrier_threshold, "dB"
    
    print
    print "Allocated virtual ethernet interface: %s" % (tun_ifname,)
    print "You must now use ifconfig to set its IP address. E.g.,"
    print
    print "  $ sudo ifconfig %s 10.10.10.1" % (tun_ifname,)
    print
    print "Be sure to use a different address in the same subnet for each machine."
    print


    fg.start()    # Start executing the flow graph (runs in separate threads)

    mac.main_loop()    # don't expect this to return...

    fg.stop()     # but if it does, tell flow graph to stop.
    fg.wait()     # wait for it to finish
コード例 #19
0
def main():

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

    def rx_callback(ok, payload):
        print "ok = %r, payload = '%s'" % (ok, payload)

    mods = 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='gmsk',
                      help="Select modulation from: %s [default=%%default]"
                            % (', '.join(mods.keys()),))
    parser.add_option("-M", "--megabytes", type="eng_float", default=0,
                      help="set megabytes to transmit [default=inf]")
    parser.add_option("-I", "--audio-input", type="string", default="",
                      help="pcm input device name.  E.g., hw:0,0 or /dev/dsp")

    transmit_path.add_options(parser, expert_grp)

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

    fusb_options.add_options(expert_grp)

    parser.set_defaults(bitrate=50e3)  # override default bitrate default
    (options, args) = parser.parse_args ()

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

    if options.tx_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(mods[options.modulation], options)

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


    tb.start()                       # start flow graph

    # generate and send packets
    nbytes = int(1e6 * options.megabytes)
    n = 0
    pktno = 0

    while nbytes == 0 or n < nbytes:
        packet = tb.audio_rx.get_encoded_voice_packet()
        s = packet.to_string()
        send_pkt(s)
        n += len(s)
        sys.stderr.write('.')
        pktno += 1
        
    send_pkt(eof=True)
    tb.wait()                       # wait for it to finish
    tb.txpath.set_auto_tr(False)
コード例 #20
0
def main():

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

    parser.add_option(
        "-m",
        "--modulation",
        type="choice",
        choices=['bpsk', 'qpsk'],
        default='bpsk',
        help="Select modulation from: bpsk, qpsk [default=%%default]")

    parser.add_option("-v", "--verbose", action="store_true", default=False)
    expert_grp.add_option(
        "-c",
        "--carrier-threshold",
        type="eng_float",
        default=30,
        help="set carrier detect threshold (dB) [default=%default]")
    expert_grp.add_option("",
                          "--tun-device-filename",
                          default="/dev/net/tun",
                          help="path to tun device file [default=%default]")

    usrp_graph.add_options(parser, expert_grp)
    transmit_path.add_options(parser, expert_grp)
    receive_path.add_options(parser, expert_grp)
    blks2.ofdm_mod.add_options(parser, expert_grp)
    blks2.ofdm_demod.add_options(parser, expert_grp)

    fusb_options.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 or options.tx_freq is None:
        sys.stderr.write("You must specify -f FREQ or --freq FREQ\n")
        parser.print_help(sys.stderr)
        sys.exit(1)

    # open the TUN/TAP interface
    (tun_fd, tun_ifname) = open_tun_interface(options.tun_device_filename)

    # Attempt to enable realtime scheduling
    r = gr.enable_realtime_scheduling()
    if r == gr.RT_OK:
        realtime = True
    else:
        realtime = False
        print "Note: failed to enable realtime scheduling"

    # If the user hasn't set the fusb_* parameters on the command line,
    # pick some values that will reduce latency.

    if options.fusb_block_size == 0 and options.fusb_nblocks == 0:
        if realtime:  # be more aggressive
            options.fusb_block_size = gr.prefs().get_long(
                'fusb', 'rt_block_size', 1024)
            options.fusb_nblocks = gr.prefs().get_long('fusb', 'rt_nblocks',
                                                       16)
        else:
            options.fusb_block_size = gr.prefs().get_long(
                'fusb', 'block_size', 4096)
            options.fusb_nblocks = gr.prefs().get_long('fusb', 'nblocks', 16)

    #print "fusb_block_size =", options.fusb_block_size
    #print "fusb_nblocks    =", options.fusb_nblocks

    # instantiate the MAC
    mac = cs_mac(tun_fd, verbose=True)

    # build the graph (PHY)
    tb = usrp_graph(mac.phy_rx_callback, options)

    mac.set_flow_graph(tb)  # give the MAC a handle for the PHY

    #if fg.txpath.bitrate() != fg.rxpath.bitrate():
    #    print "WARNING: Transmit bitrate = %sb/sec, Receive bitrate = %sb/sec" % (
    #        eng_notation.num_to_str(fg.txpath.bitrate()),
    #        eng_notation.num_to_str(fg.rxpath.bitrate()))

    print "modulation:     %s" % (options.modulation, )
    print "freq:           %s" % (eng_notation.num_to_str(options.tx_freq))
    #print "bitrate:        %sb/sec" % (eng_notation.num_to_str(fg.txpath.bitrate()),)
    #print "samples/symbol: %3d" % (fg.txpath.samples_per_symbol(),)
    #print "interp:         %3d" % (fg.txpath.interp(),)
    #print "decim:          %3d" % (fg.rxpath.decim(),)

    tb.rxpath.set_carrier_threshold(options.carrier_threshold)
    print "Carrier sense threshold:", options.carrier_threshold, "dB"

    print
    print "Allocated virtual ethernet interface: %s" % (tun_ifname, )
    print "You must now use ifconfig to set its IP address. E.g.,"
    print
    print "  $ sudo ifconfig %s 192.168.200.1" % (tun_ifname, )
    print
    print "Be sure to use a different address in the same subnet for each machine."
    print

    tb.start()  # Start executing the flow graph (runs in separate threads)

    mac.main_loop()  # don't expect this to return...

    tb.stop()  # but if it does, tell flow graph to stop.
    tb.wait()  # wait for it to finish
コード例 #21
0
def main():

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

    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='gmsk',
                      help="Select modulation from: %s [default=%%default]" %
                      (', '.join(mods.keys()), ))

    parser.add_option("-v", "--verbose", action="store_true", default=False)
    parser.add_option("-n",
                      "--nodeid",
                      type="int",
                      default=None,
                      help="specify node ID")
    expert_grp.add_option(
        "-c",
        "--carrier-threshold",
        type="eng_float",
        default=30,
        help="set carrier detect threshold (dB) [default=%default]")
    expert_grp.add_option("",
                          "--tun-device-filename",
                          default="/dev/net/tun",
                          help="path to tun device file [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)

    fusb_options.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 or options.tx_freq is None:
        sys.stderr.write("You must specify -f FREQ or --freq FREQ\n")
        parser.print_help(sys.stderr)
        sys.exit(1)

    # open the TUN/TAP interface
    #(tun_fd, tun_ifname) = open_tun_interface(options.tun_device_filename)

    # Attempt to enable realtime scheduling
    r = gr.enable_realtime_scheduling()
    if r == gr.RT_OK:
        realtime = True
    else:
        realtime = False
        print "Note: failed to enable realtime scheduling"

    # If the user hasn't set the fusb_* parameters on the command line,
    # pick some values that will reduce latency.

    if options.fusb_block_size == 0 and options.fusb_nblocks == 0:
        if realtime:  # be more aggressive
            options.fusb_block_size = gr.prefs().get_long(
                'fusb', 'rt_block_size', 1024)
            options.fusb_nblocks = gr.prefs().get_long('fusb', 'rt_nblocks',
                                                       16)
        else:
            options.fusb_block_size = gr.prefs().get_long(
                'fusb', 'block_size', 4096)
            options.fusb_nblocks = gr.prefs().get_long('fusb', 'nblocks', 16)

    #print "fusb_block_size =", options.fusb_block_size
    #print "fusb_nblocks    =", options.fusb_nblocks

    # instantiate the MAC
    mac = cs_mac(verbose=False)

    # build the graph (PHY)
    tb = my_top_block(mods[options.modulation], demods[options.modulation],
                      mac.phy_rx_callback, options)

    mac.set_top_block(tb)  # give the MAC a handle for the PHY

    if tb.txpath.bitrate() != tb.rxpath.bitrate():
        print "WARNING: Transmit bitrate = %sb/sec, Receive bitrate = %sb/sec" % (
            eng_notation.num_to_str(tb.txpath.bitrate()),
            eng_notation.num_to_str(tb.rxpath.bitrate()))

    print "modulation:     %s" % (options.modulation, )
    print "freq:           %s" % (eng_notation.num_to_str(options.tx_freq))
    print "bitrate:        %sb/sec" % (eng_notation.num_to_str(
        tb.txpath.bitrate()), )
    print "samples/symbol: %3d" % (tb.txpath.samples_per_symbol(), )
    #print "interp:         %3d" % (tb.txpath.interp(),)
    #print "decim:          %3d" % (tb.rxpath.decim(),)

    tb.rxpath.set_carrier_threshold(options.carrier_threshold)

    tb.start()  # Start executing the flow graph (runs in separate threads)
コード例 #22
0
    def add_options(normal, expert):
        """
        Adds usrp-specific options to the Options Parser
        """
        add_freq_option(normal)
        normal.add_option("-T",
                          "--tx-subdev-spec",
                          type="subdev",
                          default=None,
                          help="select USRP Tx side A or B")
        normal.add_option("-v",
                          "--verbose",
                          action="store_true",
                          default=False)

        expert.add_option(
            "",
            "--tx-freq",
            type="eng_float",
            default=None,
            help="set transmit frequency to FREQ [default=%default]",
            metavar="FREQ")
        expert.add_option(
            "-i",
            "--interp",
            type="intx",
            default=256,
            help="set fpga interpolation rate to INTERP [default=%default]")

        normal.add_option("-R",
                          "--rx-subdev-spec",
                          type="subdev",
                          default=None,
                          help="select USRP Rx side A or B")
        normal.add_option(
            "",
            "--rx-gain",
            type="eng_float",
            default=None,
            metavar="GAIN",
            help=
            "set receiver gain in dB [default=midpoint].  See also --show-rx-gain-range"
        )
        normal.add_option(
            "",
            "--show-rx-gain-range",
            action="store_true",
            default=False,
            help="print min and max Rx gain available on selected daughterboard"
        )
        normal.add_option("-v",
                          "--verbose",
                          action="store_true",
                          default=False)

        expert.add_option("",
                          "--rx-freq",
                          type="eng_float",
                          default=None,
                          help="set Rx frequency to FREQ [default=%default]",
                          metavar="FREQ")
        expert.add_option(
            "-d",
            "--decim",
            type="intx",
            default=128,
            help="set fpga decimation rate to DECIM [default=%default]")
        expert.add_option(
            "",
            "--snr",
            type="eng_float",
            default=30,
            help="set the SNR of the channel in dB [default=%default]")

        #other necessary options
        transmit_path.add_options(normal, expert)
        receive_path.add_options(normal, expert)
        blks2.ofdm_mod.add_options(normal, expert)
        blks2.ofdm_demod.add_options(normal, expert)
        fusb_options.add_options(expert)
コード例 #23
0
def main():

    global n_rcvd, n_right

    n_rcvd = 0
    n_right = 0

    # linklab, add parameters for interger freq offset (int_fo), fractional freq offset (frac_fo)
    # SINR estimation in time domain (time_sinr), SINR estimation in freq domain
    def rx_callback(ok, payload, int_fo, frac_fo, time_sinr, freq_sinr):
        global n_rcvd, n_right
        n_rcvd += 1
        try:
            (pktno, ) = struct.unpack('!H', payload[0:2])
        except:
            pktno = 1
        if ok:
            n_right += 1
            freq_offset = int_fo + frac_fo / math.pi
            print "freq offset: %+.2f(subcarriers) \t SINR: %.2f(time domain), %.2f(freq domain)" % (
                freq_offset, time_sinr, freq_sinr)
        # linklab, calculate packet loss rate and error rate
        try:
            pkt_loss = (1 - n_rcvd / float(pktno)) * 100
            pkt_err = (1 - n_right / float(pktno)) * 100
        except:
            pkt_loss = 100
            pkt_err = 100

        # linklab, print packet info
        print "ok: %r \t pktno: %d \t n_rcvd: %d \t n_right: %d \t pkt_loss: %.2f%% \t pkt_err: %.2f%%" % (
            ok, pktno, n_rcvd, n_right, pkt_loss, pkt_err)

        if 0:
            printlst = list()
            for x in payload[2:]:
                t = hex(ord(x)).replace('0x', '')
                if (len(t) == 1):
                    t = '0' + t
                printlst.append(t)
            printable = ''.join(printlst)

            print printable
            print "\n"

    parser = OptionParser(option_class=eng_option, conflict_handler="resolve")
    expert_grp = parser.add_option_group("Expert")
    parser.add_option("",
                      "--discontinuous",
                      action="store_true",
                      default=False,
                      help="enable discontinuous")

    my_top_block.add_options(parser, expert_grp)
    receive_path.add_options(parser, expert_grp)
    gr_papyrus.ofdm.ofdm_mod.add_options(parser, expert_grp)
    gr_papyrus.ofdm.ofdm_demod.add_options(parser, expert_grp)
    fusb_options.add_options(expert_grp)

    (options, args) = parser.parse_args()

    # build the graph
    tb = my_top_block(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
コード例 #24
0
ファイル: tunnel.py プロジェクト: GREO/GNU-Radio
def main():

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

    parser.add_option("-m", "--modulation", type="choice", choices=['bpsk', 'qpsk'],
                      default='bpsk',
                      help="Select modulation from: bpsk, qpsk [default=%%default]")
    
    parser.add_option("-v","--verbose", action="store_true", default=False)
    expert_grp.add_option("-c", "--carrier-threshold", type="eng_float", default=30,
                          help="set carrier detect threshold (dB) [default=%default]")
    expert_grp.add_option("","--tun-device-filename", default="/dev/net/tun",
                          help="path to tun device file [default=%default]")

    usrp_graph.add_options(parser, expert_grp)
    transmit_path.add_options(parser, expert_grp)
    receive_path.add_options(parser, expert_grp)
    blks2.ofdm_mod.add_options(parser, expert_grp)
    blks2.ofdm_demod.add_options(parser, expert_grp)

    fusb_options.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 or options.tx_freq is None:
        sys.stderr.write("You must specify -f FREQ or --freq FREQ\n")
        parser.print_help(sys.stderr)
        sys.exit(1)

    # open the TUN/TAP interface
    (tun_fd, tun_ifname) = open_tun_interface(options.tun_device_filename)

    # Attempt to enable realtime scheduling
    r = gr.enable_realtime_scheduling()
    if r == gr.RT_OK:
        realtime = True
    else:
        realtime = False
        print "Note: failed to enable realtime scheduling"


    # If the user hasn't set the fusb_* parameters on the command line,
    # pick some values that will reduce latency.

    if options.fusb_block_size == 0 and options.fusb_nblocks == 0:
        if realtime:                        # be more aggressive
            options.fusb_block_size = gr.prefs().get_long('fusb', 'rt_block_size', 1024)
            options.fusb_nblocks    = gr.prefs().get_long('fusb', 'rt_nblocks', 16)
        else:
            options.fusb_block_size = gr.prefs().get_long('fusb', 'block_size', 4096)
            options.fusb_nblocks    = gr.prefs().get_long('fusb', 'nblocks', 16)
    
    #print "fusb_block_size =", options.fusb_block_size
    #print "fusb_nblocks    =", options.fusb_nblocks

    # instantiate the MAC
    mac = cs_mac(tun_fd, verbose=True)


    # build the graph (PHY)
    tb = usrp_graph(mac.phy_rx_callback, options)

    mac.set_flow_graph(tb)    # give the MAC a handle for the PHY

    #if fg.txpath.bitrate() != fg.rxpath.bitrate():
    #    print "WARNING: Transmit bitrate = %sb/sec, Receive bitrate = %sb/sec" % (
    #        eng_notation.num_to_str(fg.txpath.bitrate()),
    #        eng_notation.num_to_str(fg.rxpath.bitrate()))
             
    print "modulation:     %s"   % (options.modulation,)
    print "freq:           %s"      % (eng_notation.num_to_str(options.tx_freq))
    #print "bitrate:        %sb/sec" % (eng_notation.num_to_str(fg.txpath.bitrate()),)
    #print "samples/symbol: %3d" % (fg.txpath.samples_per_symbol(),)
    #print "interp:         %3d" % (fg.txpath.interp(),)
    #print "decim:          %3d" % (fg.rxpath.decim(),)

    tb.rxpath.set_carrier_threshold(options.carrier_threshold)
    print "Carrier sense threshold:", options.carrier_threshold, "dB"
    
    print
    print "Allocated virtual ethernet interface: %s" % (tun_ifname,)
    print "You must now use ifconfig to set its IP address. E.g.,"
    print
    print "  $ sudo ifconfig %s 192.168.200.1" % (tun_ifname,)
    print
    print "Be sure to use a different address in the same subnet for each machine."
    print


    tb.start()    # Start executing the flow graph (runs in separate threads)

    mac.main_loop()    # don't expect this to return...

    tb.stop()     # but if it does, tell flow graph to stop.
    tb.wait()     # wait for it to finish
コード例 #25
0
def main():

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

    def rx_callback(ok, payload):
        print "ok = %r, payload = '%s'" % (ok, payload)

    mods = 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='gmsk',
                      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 file for packet contents")

    transmit_path.add_options(parser, expert_grp)

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

    fusb_options.add_options(expert_grp)
    (options, args) = parser.parse_args ()

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

    if options.tx_freq is None:
        sys.stderr.write("You must specify -f FREQ or --freq FREQ\n")
        parser.print_help(sys.stderr)
        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"

    tb.start()                       # start flow graph
        
    # generate and send packets
    nbytes = int(1e6 * options.megabytes)
    n = 0
    pktno = 0
    pkt_size = int(options.size)

    while n < nbytes:
        if options.from_file is None:
            data = (pkt_size - 2) * chr(pktno & 0xff) 
        else:
            data = source_file.read(pkt_size - 2)
            if data == '':
                break;

        payload = struct.pack('!H', pktno & 0xffff) + data
        send_pkt(payload)
        n += len(payload)
        sys.stderr.write('.')
        if options.discontinuous and pktno % 5 == 4:
            time.sleep(1)
        pktno += 1
        
    send_pkt(eof=True)

    tb.wait()                       # wait for it to finish
コード例 #26
0
def main():

    global n_rcvd, n_right

    n_rcvd = 0
    n_right = 0

    # linklab, add parameters for interger freq offset (int_fo), fractional freq offset (frac_fo)
    # SINR estimation in time domain (time_sinr), SINR estimation in freq domain
    def rx_callback(ok, payload, int_fo, frac_fo, time_sinr, freq_sinr):
        global n_rcvd, n_right
        n_rcvd += 1
        try:
            (pktno,) = struct.unpack("!H", payload[0:2])
        except:
            pktno = 1
        if ok:
            n_right += 1
            freq_offset = int_fo + frac_fo / math.pi
            print "freq offset: %+.2f(subcarriers) \t SINR: %.2f(time domain), %.2f(freq domain)" % (
                freq_offset,
                time_sinr,
                freq_sinr,
            )
        # linklab, calculate packet loss rate and error rate
        try:
            pkt_loss = (1 - n_rcvd / float(pktno)) * 100
            pkt_err = (1 - n_right / float(pktno)) * 100
        except:
            pkt_loss = 100
            pkt_err = 100

        # linklab, print packet info
        print "ok: %r \t pktno: %d \t n_rcvd: %d \t n_right: %d \t pkt_loss: %.2f%% \t pkt_err: %.2f%%" % (
            ok,
            pktno,
            n_rcvd,
            n_right,
            pkt_loss,
            pkt_err,
        )

        if 0:
            printlst = list()
            for x in payload[2:]:
                t = hex(ord(x)).replace("0x", "")
                if len(t) == 1:
                    t = "0" + t
                printlst.append(t)
            printable = "".join(printlst)

            print printable
            print "\n"

    parser = OptionParser(option_class=eng_option, conflict_handler="resolve")
    expert_grp = parser.add_option_group("Expert")
    parser.add_option("", "--discontinuous", action="store_true", default=False, help="enable discontinuous")

    my_top_block.add_options(parser, expert_grp)
    receive_path.add_options(parser, expert_grp)
    gr_papyrus.ofdm.ofdm_mod.add_options(parser, expert_grp)
    gr_papyrus.ofdm.ofdm_demod.add_options(parser, expert_grp)
    fusb_options.add_options(expert_grp)

    (options, args) = parser.parse_args()

    # build the graph
    tb = my_top_block(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