root / gnuradio-core / src / examples / network / vector_source.py @ faab807c
History | View | Annotate | Download (2.2 kB)
| 1 | 3bb7b864 | trondeau | #!/usr/bin/env python
|
|---|---|---|---|
| 2 | 3bb7b864 | trondeau | #
|
| 3 | d702e27d | Don Ward | # Copyright 2006,2010 Free Software Foundation, Inc.
|
| 4 | 3bb7b864 | trondeau | #
|
| 5 | 3bb7b864 | trondeau | # This file is part of GNU Radio
|
| 6 | 3bb7b864 | trondeau | #
|
| 7 | 3bb7b864 | trondeau | # GNU Radio is free software; you can redistribute it and/or modify
|
| 8 | 3bb7b864 | trondeau | # it under the terms of the GNU General Public License as published by
|
| 9 | 937b719d | eb | # the Free Software Foundation; either version 3, or (at your option)
|
| 10 | 3bb7b864 | trondeau | # any later version.
|
| 11 | 3bb7b864 | trondeau | #
|
| 12 | 3bb7b864 | trondeau | # GNU Radio is distributed in the hope that it will be useful,
|
| 13 | 3bb7b864 | trondeau | # but WITHOUT ANY WARRANTY; without even the implied warranty of
|
| 14 | 3bb7b864 | trondeau | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
| 15 | 3bb7b864 | trondeau | # GNU General Public License for more details.
|
| 16 | 3bb7b864 | trondeau | #
|
| 17 | 3bb7b864 | trondeau | # You should have received a copy of the GNU General Public License
|
| 18 | 3bb7b864 | trondeau | # along with GNU Radio; see the file COPYING. If not, write to
|
| 19 | 3bb7b864 | trondeau | # the Free Software Foundation, Inc., 51 Franklin Street,
|
| 20 | 3bb7b864 | trondeau | # Boston, MA 02110-1301, USA.
|
| 21 | 3bb7b864 | trondeau | #
|
| 22 | 3bb7b864 | trondeau | |
| 23 | 3bb7b864 | trondeau | from gnuradio import gr |
| 24 | 3bb7b864 | trondeau | from gnuradio.eng_option import eng_option |
| 25 | 3bb7b864 | trondeau | from optparse import OptionParser |
| 26 | 3bb7b864 | trondeau | |
| 27 | b26ea696 | jcorgan | class vector_source(gr.top_block): |
| 28 | d702e27d | Don Ward | def __init__(self, host, port, pkt_size, eof): |
| 29 | b26ea696 | jcorgan | gr.top_block.__init__(self, "vector_source") |
| 30 | 3e7f3d33 | trondeau | data = [i*0.01 for i in range(1000)] |
| 31 | b26ea696 | jcorgan | vec = gr.vector_source_f(data, True)
|
| 32 | d702e27d | Don Ward | udp = gr.udp_sink(gr.sizeof_float, host, port, pkt_size, eof=eof) |
| 33 | b26ea696 | jcorgan | self.connect(vec, udp)
|
| 34 | 3bb7b864 | trondeau | |
| 35 | 3bb7b864 | trondeau | if __name__ == '__main__': |
| 36 | 3bb7b864 | trondeau | parser = OptionParser(option_class=eng_option) |
| 37 | d702e27d | Don Ward | parser.add_option("", "--host", type="string", default="localhost", |
| 38 | 3e7f3d33 | trondeau | help="Remote host name (domain name or IP address")
|
| 39 | d702e27d | Don Ward | parser.add_option("", "--port", type="int", default=65500, |
| 40 | d702e27d | Don Ward | help="port number to connect to")
|
| 41 | 3e7f3d33 | trondeau | parser.add_option("", "--packet-size", type="int", default=1471, |
| 42 | 3e7f3d33 | trondeau | help="packet size.")
|
| 43 | d702e27d | Don Ward | parser.add_option("", "--no-eof", action="store_true", default=False, |
| 44 | d702e27d | Don Ward | help="don't send EOF on disconnect")
|
| 45 | 3bb7b864 | trondeau | (options, args) = parser.parse_args() |
| 46 | 3bb7b864 | trondeau | if len(args) != 0: |
| 47 | 3bb7b864 | trondeau | parser.print_help() |
| 48 | 3bb7b864 | trondeau | raise SystemExit, 1 |
| 49 | 3bb7b864 | trondeau | |
| 50 | 3bb7b864 | trondeau | # Create an instance of a hierarchical block
|
| 51 | d702e27d | Don Ward | top_block = vector_source(options.host, options.port, options.packet_size, |
| 52 | d702e27d | Don Ward | not options.no_eof)
|
| 53 | 3bb7b864 | trondeau | |
| 54 | 3bb7b864 | trondeau | try:
|
| 55 | 3bb7b864 | trondeau | # Run forever
|
| 56 | c088a546 | jcorgan | top_block.run() |
| 57 | 3bb7b864 | trondeau | except KeyboardInterrupt: |
| 58 | 3bb7b864 | trondeau | # Ctrl-C exits
|
| 59 | 3bb7b864 | trondeau | pass
|
| 60 | 3bb7b864 | trondeau |