Imported Upstream version 3.0
[debian/gnuradio] / gnuradio-examples / python / usrp / max_power.py
1 #!/usr/bin/env python
2 #
3 # Copyright 2004 Free Software Foundation, Inc.
4
5 # This file is part of GNU Radio
6
7 # GNU Radio is free software; you can redistribute it and/or modify
8 # it under the terms of the GNU General Public License as published by
9 # the Free Software Foundation; either version 2, or (at your option)
10 # any later version.
11
12 # GNU Radio is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 # GNU General Public License for more details.
16
17 # You should have received a copy of the GNU General Public License
18 # along with GNU Radio; see the file COPYING.  If not, write to
19 # the Free Software Foundation, Inc., 51 Franklin Street,
20 # Boston, MA 02110-1301, USA.
21
22
23 """
24 Setup USRP for maximum power consumption.
25 """
26
27
28 from gnuradio import gr
29 from gnuradio import usrp
30 from gnuradio.eng_option import eng_option
31 from optparse import OptionParser
32
33 def ramp_source (fg):
34     period = 2**16
35     src = gr.vector_source_s (range (-period/2, period/2, 1), True)
36     return src
37
38 def build_graph (tx_enable, rx_enable):
39     max_usb_rate = 8e6                  # 8 MS/sec
40     dac_freq = 128e6
41     adc_freq =  64e6
42     
43     tx_nchan = 2
44     tx_mux = 0x0000ba98
45     tx_interp =  int (dac_freq / (max_usb_rate/2 * tx_nchan)) # 16
46     
47     rx_nchan = 2
48     rx_mux = 0x00003210
49     rx_decim = int ((adc_freq * rx_nchan) / (max_usb_rate/2)) # 32
50     
51     fg = gr.flow_graph ()
52
53     if tx_enable:
54         tx_src0 = gr.sig_source_c (dac_freq/tx_interp, gr.GR_CONST_WAVE, 0, 16e3, 0)
55         usrp_tx = usrp.sink_c (0, tx_interp, tx_nchan, tx_mux)
56         usrp_tx.set_tx_freq (0, 10e6)
57         usrp_tx.set_tx_freq (1,  9e6)
58         fg.connect (tx_src0, usrp_tx)
59
60     if rx_enable:
61         usrp_rx = usrp.source_c (0, rx_decim, rx_nchan, rx_mux)
62         usrp_rx.set_rx_freq (0, 5.5e6)
63         usrp_rx.set_rx_freq (1, 6.5e6)
64         rx_dst0 = gr.null_sink (gr.sizeof_gr_complex)
65         fg.connect (usrp_rx, rx_dst0)
66
67     return fg
68     
69 def main ():
70     parser = OptionParser (option_class=eng_option)
71     parser.add_option ("-t", action="store_true", dest="tx_enable",
72                        default=False, help="enable Tx path")
73     parser.add_option ("-r", action="store_true", dest="rx_enable",
74                        default=False, help="enable Rx path")
75     (options, args) = parser.parse_args ()
76     fg = build_graph (options.tx_enable, options.rx_enable)
77
78     fg.start ()
79     raw_input ('Press Enter to quit: ')
80     fg.stop ()
81
82 if __name__ == '__main__':
83     main ()