Imported Upstream version 3.0
[debian/gnuradio] / gnuradio-examples / python / usrp / test_digital_loopback_counting.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 Digital loopback (Tx to Rx) for the USRP Rev1.
25 """
26
27
28 from gnuradio import gr
29 from gnuradio import usrp
30
31
32 def ramp_source (fg):
33     period = 2**16
34     src = gr.vector_source_s (range (-period/2, period/2, 1), True)
35     return src
36
37 def build_graph ():
38     tx_interp =  32       # tx should be twice rx
39     rx_decim  =  16
40     
41     fg = gr.flow_graph ()
42
43     data_src = ramp_source (fg)
44     # usrp_tx = usrp.sink_s (0, tx_interp, 1, 0x98)
45     usrp_tx = usrp.sink_s (0, tx_interp)
46     fg.connect (data_src, usrp_tx)
47
48     usrp_rx = usrp.source_s (0, rx_decim, 1, 0x32103210, usrp.FPGA_MODE_LOOPBACK)
49     sink = gr.check_counting_s ()
50     fg.connect (usrp_rx, sink)
51
52     # file_sink = gr.file_sink (gr.sizeof_short, "loopback.dat")
53     # fg.connect (usrp_rx, file_sink)
54     
55     return fg
56     
57 def main ():
58     fg = build_graph ()
59     try:
60         fg.run()
61     except KeyboardInterrupt:
62         pass
63
64 if __name__ == '__main__':
65     main ()