e7ec2a461d15bbe15ddb91ff605864faabf74bf0
[debian/gnuradio] / gnuradio-examples / python / network / vector_source.py
1 #!/usr/bin/env python
2 #
3 # Copyright 2006 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 3, 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 from gnuradio import gr
24 from gnuradio.eng_option import eng_option
25 from optparse import OptionParser
26
27 class vector_source(gr.top_block):
28     def __init__(self, src, dst, port, pkt_size):
29         gr.top_block.__init__(self, "vector_source")
30         data = [i*0.01 for i in range(1000)]
31         vec = gr.vector_source_f(data, True)
32         udp = gr.udp_sink(gr.sizeof_float, src, 0, dst, port, pkt_size)
33         self.connect(vec, udp)
34
35 if __name__ == '__main__':
36     parser = OptionParser(option_class=eng_option)
37     parser.add_option("", "--src-name", type="string", default="localhost",
38                       help="local host name (domain name or IP address)")
39     parser.add_option("", "--dst-name", type="string", default="localhost",
40                       help="Remote host name (domain name or IP address")
41     parser.add_option("", "--dst-port", type="int", default=65500,
42                       help="port value to connect to")
43     parser.add_option("", "--packet-size", type="int", default=1471,
44                       help="packet size.")
45     (options, args) = parser.parse_args()
46     if len(args) != 0:
47         parser.print_help()
48         raise SystemExit, 1
49
50 # Create an instance of a hierarchical block
51     top_block = vector_source(options.src_name, options.dst_name,
52                               options.dst_port, options.packet_size)
53     
54     try:    
55         # Run forever
56         top_block.run()
57     except KeyboardInterrupt:
58         # Ctrl-C exits
59         pass
60