Exemple #1
0
 def add_parser_options (parser):
     if not parser.has_option("-v"):
         parser.add_option ("-v", "--verbose", type="int", \
                 default=default_phy_setup.d_options['verbose'], \
                 help="set verbose level of output [default=%default]")
     if not parser.has_option("--debug"):
         parser.add_option ("", "--debug", type="int", \
                 default=default_phy_setup.d_options['debug'], \
                 help="set debug level of system [default=%default]")
     if not parser.has_option("-n"):
         parser.add_option ("-n", "--nchannels", type="int", \
                 default=default_phy_setup.d_options['nchannels'], \
                 help="set number of channels (or antennas) on USRP board [default=%default]")
     if not parser.has_option("-G"):
         parser.add_option ("-G", "--rx-gain", type="eng_float", \
                 default=default_phy_setup.d_options['rx_gain'], \
                 help="set usrp receive gain in dB [default=%default]")
     if not parser.has_option("-g"):
         parser.add_option ("-g", "--tx-gain", type="eng_float", \
                 default=default_phy_setup.d_options['tx_gain'], \
                 help="set software transmit gain in dB [default=%default]")
     if not parser.has_option("-u"):
         parser.add_option ("-u", "--upsample", type="int",
                 default=default_phy_setup.d_options['upsample'], \
                 help="set the upsampling factor [default=%default]")
     if not parser.has_option("--inband"):
         parser.add_option("", "--inband", action="store_true", \
                 default=default_phy_setup.d_options['inband'],
                 help="enable inband signalling in RF [default=%default]")
     RadioRx.add_parser_options(parser)
     RadioTx.add_parser_options(parser)
Exemple #2
0
def TestTx():
    """ Parser Options """
    parser = OptionParser (option_class=eng_option)
    RadioTx.add_parser_options (parser)
    (options, args) = parser.parse_args ()
    if len(args)!=0:
        parser.print_help()
        sys.exit(1)

    print "TestTx\n=========="

    tb = gr.top_block()
    tx = RadioTx(options)
    tb.connect(tx)

    #T, w, C = 10.0, 100.0e3, 100
    T, w, C = 10.0, 40.0e3, 100
    A = 4000
    if SEND_MIMO_TRAINING:
        T = 10.0
        s = "hi"*4
        txvector = mimo.txvector()
        txvector.set_length(len(s) )
        phy = mimo.tx(options.nchannels)
        phy.configure(txvector)
        phy.set_gain(10000)
        phy.set_upsampling_factor(2)
        phy.transmit(s)
        m = phy.outputQ().delete_head()
        print "created message ... %d samples"%(m.length()/gr.sizeof_gr_complex/options.nchannels)
    else:
        P = min(T, C/w)
        k = max(1, int(T/P) )
        s = Signal()
        s.setData(make_exponential(A, P, w, options.sample_rate) )
        m = gr.message_from_string(s.string(k), 0, 1, len(s.vector())*k )
        print "created message ... %d samples"%(int(k*P*options.sample_rate) )

    interval = 0.2
    g = FuncThread(send_msg, "send msg", m, tx.pad.inputQ(), interval)
    g.setDaemon(1)
    g.start()
    
    stoptime = T+5.0
    f = FuncThread(send_stoprf, "stop rf", tx, stoptime)
    f.setDaemon(1)
    f.start()
    
    print "running ..."
    tb.run()
    print "stoppping ..."
Exemple #3
0
    def __init__(self, options):
        gr.top_block.__init__(self)
        # check for default options before calling constructor
        default_phy_setup.check_options(options)
        self.verbose = options.verbose
        self.debug = options.debug

        # instantiate blocks
        self.tx = self.make_tx(options)
        self.rx = self.make_rx(options)
        # create runtime environment for mblocks
        self.rt = None
        if options.inband:
            self.rt = rf.runtime(True, True)
        self.txpath, self.rxpath = None, None
        self.txpath = RadioTx(options)
        if self.rx: self.rxpath = RadioRx(options)

        if (self.tx==None): self.warning("tx is not defined.")
        if (self.rx==None): self.warning("rx is not defined.")

        # connect hier_block2's to RadioRx and RadioTx
        if self.rx: self.connect(self.rxpath, self.rx)
        if self.tx: self.connect(self.txpath)

        # set options
        if hasattr(self.tx, 'set_debug'): self.tx.set_debug(options.debug)
        if hasattr(self.rx, 'set_debug'): self.rx.set_debug(options.debug)
        self.set_nchannels(options.nchannels)
        self.sample_rate = options.sample_rate
        self.set_upsample(options.upsample)
        self.set_tx_gain(options.tx_gain)
        self.set_rx_gain(options.rx_gain)

        # connect other relevant parameters
        if self.tx: self.tx.set_outputQ(self.txpath.pad.inputQ() )
Exemple #4
0
class transceiver (gr.top_block):
    
    def __init__(self, options):
        gr.top_block.__init__(self)
        # check for default options before calling constructor
        default_phy_setup.check_options(options)
        self.verbose = options.verbose
        self.debug = options.debug

        # instantiate blocks
        self.tx = self.make_tx(options)
        self.rx = self.make_rx(options)
        # create runtime environment for mblocks
        self.rt = None
        if options.inband:
            self.rt = rf.runtime(True, True)
        self.txpath, self.rxpath = None, None
        self.txpath = RadioTx(options)
        if self.rx: self.rxpath = RadioRx(options)

        if (self.tx==None): self.warning("tx is not defined.")
        if (self.rx==None): self.warning("rx is not defined.")

        # connect hier_block2's to RadioRx and RadioTx
        if self.rx: self.connect(self.rxpath, self.rx)
        if self.tx: self.connect(self.txpath)

        # set options
        if hasattr(self.tx, 'set_debug'): self.tx.set_debug(options.debug)
        if hasattr(self.rx, 'set_debug'): self.rx.set_debug(options.debug)
        self.set_nchannels(options.nchannels)
        self.sample_rate = options.sample_rate
        self.set_upsample(options.upsample)
        self.set_tx_gain(options.tx_gain)
        self.set_rx_gain(options.rx_gain)

        # connect other relevant parameters
        if self.tx: self.tx.set_outputQ(self.txpath.pad.inputQ() )

    def make_tx(self, options):
        return phy.tx()

    def make_rx(self, options):
        return phy.rx()

    def stop(self):
        if self.txpath: self.txpath.shutdown()
        else: return
        if self.rxpath: self.rxpath.shutdown()
        else: return
        if not self.txpath.fake_rf: gr.top_block.stop(self)
        self.txpath = None
        self.rxpath = None

    def shutdown(self):
        print "phy.shutdown called ..."
        self.stop()

    def set_nchannels (self, n):
        self.nchannels = n
        if self.tx: self.tx.set_ntx(n)
        if self.rx: self.rx.set_nrx(n)

    def set_upsample (self, m):
        self.upsample = default_phy_setup.d_options['upsample']
        if self.tx:
            self.tx.set_upsampling_factor(m)
            self.upsample = self.tx.upsampling_factor()
        if (self.verbose>4): sys.stderr.write("upsample factor = %d\n"%(self.upsample) )
        self.set_sample_rate(self.sample_rate)

    def set_tx_gain (self, g):
        self.tx_gain = default_phy_setup.d_options['tx_gain']
        if self.tx:
            self.tx.set_gain(g)
            self.tx_gain = self.tx.gain()
        if (self.verbose>4): sys.stderr.write("tx gain = %s\n"%(int(self.tx_gain)) )

    def set_rx_gain (self, gdb):
        self.rx_gain = default_phy_setup.d_options['rx_gain']
        if self.rxpath:
            self.rxpath.set_rx_gain(gdb)
            self.rx_gain = self.rxpath.rx_gain
        if (self.verbose>4): sys.stderr.write("rx gain = %d dB\n"%(int(self.rx_gain)) )

    """ Other control methods for controlling rf from transceiver """
    def set_freq(self, f):
        self.rxpath.set_freq(f)
        self.txpath.set_freq(f)
        self.freq = self.rxpath.freq

    def set_sample_rate(self, r):
        self.txpath.set_sample_rate(r*self.upsample)
        self.rxpath.set_sample_rate(r)
        if (self.verbose>4): sys.stderr.write("Tx sample rate = %.2fM\n"%(self.txpath.sample_rate/1.0e6) )
        if (self.verbose>4): sys.stderr.write("Rx sample rate = %.2fM\n"%(self.rxpath.sample_rate/1.0e6) )
        self.sample_rate = self.rxpath.sample_rate

    def set_tx_mode(self, m):
        if hasattr(self.txpath.pad, 'set_continuous'):
            self.txpath.pad.set_continuous(m)

    """ 
    Transmit/receive functions are depricated. They should not be used in
    conjunction with MAC/PHY interface objects defined in mpif. When operating
    with mpif objects, you will need to pass the transmitter (self.tx) and the
    receive output queue (self.rx.outputQ() ) to the configuration functions
    mpif_tx.set_transmitter() and mpif_rx.set_inputQ().
    """
    def transmit(self, s):
        if self.tx: self.tx.transmit (s)

    def receive(self):
        ##  DEPRICATED: do not use!
        #   check the global control queue phy.phyglobal.ctrlQ() instead
        return self.rx.outputQ().delete_head()

    def warning (self, msg, level=0):
        if self.verbose >= level: sys.stderr.write("PHY warning: "+str(msg)+"\n")

    def error (self, msg, level=0):
        if self.verbose >= level: sys.stderr.write("PHY ERROR: "+str(msg)+"\n")
    
    """ Add parser options to an OptionParser """
    def add_parser_options (parser):
        if not parser.has_option("-v"):
            parser.add_option ("-v", "--verbose", type="int", \
                    default=default_phy_setup.d_options['verbose'], \
                    help="set verbose level of output [default=%default]")
        if not parser.has_option("--debug"):
            parser.add_option ("", "--debug", type="int", \
                    default=default_phy_setup.d_options['debug'], \
                    help="set debug level of system [default=%default]")
        if not parser.has_option("-n"):
            parser.add_option ("-n", "--nchannels", type="int", \
                    default=default_phy_setup.d_options['nchannels'], \
                    help="set number of channels (or antennas) on USRP board [default=%default]")
        if not parser.has_option("-G"):
            parser.add_option ("-G", "--rx-gain", type="eng_float", \
                    default=default_phy_setup.d_options['rx_gain'], \
                    help="set usrp receive gain in dB [default=%default]")
        if not parser.has_option("-g"):
            parser.add_option ("-g", "--tx-gain", type="eng_float", \
                    default=default_phy_setup.d_options['tx_gain'], \
                    help="set software transmit gain in dB [default=%default]")
        if not parser.has_option("-u"):
            parser.add_option ("-u", "--upsample", type="int",
                    default=default_phy_setup.d_options['upsample'], \
                    help="set the upsampling factor [default=%default]")
        if not parser.has_option("--inband"):
            parser.add_option("", "--inband", action="store_true", \
                    default=default_phy_setup.d_options['inband'],
                    help="enable inband signalling in RF [default=%default]")
        RadioRx.add_parser_options(parser)
        RadioTx.add_parser_options(parser)

    add_parser_options = Callable (add_parser_options)