diff options
author | Don Ward | 2010-05-04 12:41:52 -0400 |
---|---|---|
committer | Don Ward | 2010-05-04 12:41:52 -0400 |
commit | d702e27d1f3b0e76ef3734ee6b5b6ac1333cdbff (patch) | |
tree | 40568ebdb838ba9222068433548070399c2e277e /gnuradio-examples/python | |
parent | dda6ed353551d3493983bd56e0ca8ee8ed4407c5 (diff) | |
download | gnuradio-d702e27d1f3b0e76ef3734ee6b5b6ac1333cdbff.tar.gz gnuradio-d702e27d1f3b0e76ef3734ee6b5b6ac1333cdbff.tar.bz2 gnuradio-d702e27d1f3b0e76ef3734ee6b5b6ac1333cdbff.zip |
Rework UDP source and sink, with incompatible API changes
Remove source address specifications for sink; add connect() and
disconnect() to sink; add get_port() to source; add optional EOF
signaling (using zero-length packets) to sink and source; modify
dial_tone, vector, and audio examples to match new code; add qa
test case.
Diffstat (limited to 'gnuradio-examples/python')
-rwxr-xr-x | gnuradio-examples/python/network/audio_sink.py | 20 | ||||
-rwxr-xr-x | gnuradio-examples/python/network/audio_source.py | 21 | ||||
-rwxr-xr-x | gnuradio-examples/python/network/dial_tone_sink.py | 19 | ||||
-rwxr-xr-x | gnuradio-examples/python/network/dial_tone_source.py | 22 | ||||
-rwxr-xr-x | gnuradio-examples/python/network/vector_sink.py | 19 | ||||
-rwxr-xr-x | gnuradio-examples/python/network/vector_source.py | 20 |
6 files changed, 69 insertions, 52 deletions
diff --git a/gnuradio-examples/python/network/audio_sink.py b/gnuradio-examples/python/network/audio_sink.py index e59d50834..eb18a75aa 100755 --- a/gnuradio-examples/python/network/audio_sink.py +++ b/gnuradio-examples/python/network/audio_sink.py @@ -1,6 +1,6 @@ #!/usr/bin/env python # -# Copyright 2006,2007 Free Software Foundation, Inc. +# Copyright 2006,2007,2010 Free Software Foundation, Inc. # # This file is part of GNU Radio # @@ -25,30 +25,36 @@ from gnuradio.eng_option import eng_option from optparse import OptionParser class audio_sink(gr.top_block): - def __init__(self, src, port, pkt_size, sample_rate): + def __init__(self, host, port, pkt_size, sample_rate, eof, wait): gr.top_block.__init__(self, "audio_sink") - src = gr.udp_source(gr.sizeof_float, src, port, pkt_size) + src = gr.udp_source(gr.sizeof_float, host, port, pkt_size, + eof=eof, wait=wait) dst = audio.sink(sample_rate) self.connect(src, dst) if __name__ == '__main__': parser = OptionParser(option_class=eng_option) - parser.add_option("", "--src-name", type="string", default="localhost", + parser.add_option("", "--host", type="string", default="0.0.0.0", help="local host name (domain name or IP address)") - parser.add_option("", "--src-port", type="int", default=65500, + parser.add_option("", "--port", type="int", default=65500, help="port value to listen to for connection") parser.add_option("", "--packet-size", type="int", default=1472, help="packet size.") parser.add_option("-r", "--sample-rate", type="int", default=32000, help="audio signal sample rate [default=%default]") + parser.add_option("", "--no-eof", action="store_true", default=False, + help="don't send EOF on disconnect") + parser.add_option("", "--no-wait", action="store_true", default=False, + help="don't wait for source") (options, args) = parser.parse_args() if len(args) != 0: parser.print_help() raise SystemExit, 1 # Create an instance of a hierarchical block - top_block = audio_sink(options.src_name, options.src_port, - options.packet_size, options.sample_rate) + top_block = audio_sink(options.host, options.port, + options.packet_size, options.sample_rate, + not options.no_eof, not options.no_wait) try: # Run forever diff --git a/gnuradio-examples/python/network/audio_source.py b/gnuradio-examples/python/network/audio_source.py index d7f4f6d93..5818ccbd8 100755 --- a/gnuradio-examples/python/network/audio_source.py +++ b/gnuradio-examples/python/network/audio_source.py @@ -1,6 +1,6 @@ #!/usr/bin/env python # -# Copyright 2006,2007 Free Software Foundation, Inc. +# Copyright 2006,2007,2010 Free Software Foundation, Inc. # # This file is part of GNU Radio # @@ -25,32 +25,33 @@ from gnuradio.eng_option import eng_option from optparse import OptionParser class audio_source(gr.top_block): - def __init__(self, src, dst, port, pkt_size, sample_rate): + def __init__(self, host, port, pkt_size, sample_rate, eof): gr.top_block.__init__(self, "audio_source") self.audio = audio.source(sample_rate) - self.sink = gr.udp_sink(gr.sizeof_float, src, 0, dst, port, pkt_size) + self.sink = gr.udp_sink(gr.sizeof_float, host, port, pkt_size, eof=eof) self.connect(self.audio, self.sink) if __name__ == '__main__': parser = OptionParser(option_class=eng_option) - parser.add_option("", "--src-name", type="string", default="localhost", - help="local host name (domain name or IP address)") - parser.add_option("", "--dst-name", type="string", default="localhost", + parser.add_option("", "--host", type="string", default="localhost", help="Remote host name (domain name or IP address") - parser.add_option("", "--dst-port", type="int", default=65500, - help="port value to connect to") + parser.add_option("", "--port", type="int", default=65500, + help="port number to connect to") parser.add_option("", "--packet-size", type="int", default=1472, help="packet size.") parser.add_option("-r", "--sample-rate", type="int", default=32000 , help="audio signal sample rate [default=%default]") + parser.add_option("", "--no-eof", action="store_true", default=False, + help="don't send EOF on disconnect") (options, args) = parser.parse_args() if len(args) != 0: parser.print_help() raise SystemExit, 1 # Create an instance of a hierarchical block - top_block = audio_source(options.src_name, options.dst_name, options.dst_port, - options.packet_size, options.sample_rate) + top_block = audio_source(options.host, options.port, + options.packet_size, options.sample_rate, + not options.no_eof) try: # Run forever diff --git a/gnuradio-examples/python/network/dial_tone_sink.py b/gnuradio-examples/python/network/dial_tone_sink.py index 82e925baa..1b9009552 100755 --- a/gnuradio-examples/python/network/dial_tone_sink.py +++ b/gnuradio-examples/python/network/dial_tone_sink.py @@ -1,6 +1,6 @@ #!/usr/bin/env python # -# Copyright 2006,2007 Free Software Foundation, Inc. +# Copyright 2006,2007,2010 Free Software Foundation, Inc. # # This file is part of GNU Radio # @@ -25,23 +25,26 @@ from gnuradio.eng_option import eng_option from optparse import OptionParser class dial_tone_sink(gr.top_block): - def __init__(self, src, port, pkt_size, sample_rate, wait): + def __init__(self, host, port, pkt_size, sample_rate, eof, wait): gr.top_block.__init__(self, "dial_tone_sink") - udp = gr.udp_source(gr.sizeof_float, src, port, pkt_size, wait=wait) + udp = gr.udp_source(gr.sizeof_float, host, port, pkt_size, + eof=eof, wait=wait) sink = audio.sink(sample_rate) self.connect(udp, sink) if __name__ == '__main__': parser = OptionParser(option_class=eng_option) - parser.add_option("", "--src-name", type="string", default="localhost", + parser.add_option("", "--host", type="string", default="0.0.0.0", help="local host name (domain name or IP address)") - parser.add_option("", "--src-port", type="int", default=65500, + parser.add_option("", "--port", type="int", default=65500, help="port value to listen to for connection") parser.add_option("", "--packet-size", type="int", default=1472, help="packet size.") parser.add_option("-r", "--sample-rate", type="int", default=8000, help="audio signal sample rate [default=%default]") - parser.add_option("-n", "--no-wait", action="store_true", default=False, + parser.add_option("", "--no-eof", action="store_true", default=False, + help="don't send EOF on disconnect") + parser.add_option("", "--no-wait", action="store_true", default=False, help="don't wait for source") (options, args) = parser.parse_args() if len(args) != 0: @@ -49,9 +52,9 @@ if __name__ == '__main__': raise SystemExit, 1 # Create an instance of a hierarchical block - top_block = dial_tone_sink(options.src_name, options.src_port, + top_block = dial_tone_sink(options.host, options.port, options.packet_size, options.sample_rate, - not options.no_wait) + not options.no_eof, not options.no_wait) try: # Run forever diff --git a/gnuradio-examples/python/network/dial_tone_source.py b/gnuradio-examples/python/network/dial_tone_source.py index 835f9aafc..766ecf16d 100755 --- a/gnuradio-examples/python/network/dial_tone_source.py +++ b/gnuradio-examples/python/network/dial_tone_source.py @@ -1,6 +1,6 @@ #!/usr/bin/env python # -# Copyright 2006,2007 Free Software Foundation, Inc. +# Copyright 2006,2007,2010 Free Software Foundation, Inc. # # This file is part of GNU Radio # @@ -25,7 +25,7 @@ from gnuradio.eng_option import eng_option from optparse import OptionParser class dial_tone_source(gr.top_block): - def __init__(self, src, dst, port, pkt_size, sample_rate): + def __init__(self, host, port, pkt_size, sample_rate, eof): gr.top_block.__init__(self, "dial_tone_source") amplitude = 0.3 @@ -35,31 +35,32 @@ class dial_tone_source(gr.top_block): # Throttle needed here to account for the other side's audio card sampling rate thr = gr.throttle(gr.sizeof_float, sample_rate) - sink = gr.udp_sink(gr.sizeof_float, src, 0, dst, port, pkt_size) + sink = gr.udp_sink(gr.sizeof_float, host, port, pkt_size, eof=eof) self.connect(src0, (add, 0)) self.connect(src1, (add, 1)) self.connect(add, thr, sink) if __name__ == '__main__': parser = OptionParser(option_class=eng_option) - parser.add_option("", "--src-name", type="string", default="localhost", - help="local host name (domain name or IP address)") - parser.add_option("", "--dst-name", type="string", default="localhost", + parser.add_option("", "--host", type="string", default="localhost", help="Remote host name (domain name or IP address") - parser.add_option("", "--dst-port", type="int", default=65500, - help="port value to connect to") + parser.add_option("", "--port", type="int", default=65500, + help="port number to connect to") parser.add_option("", "--packet-size", type="int", default=1472, help="packet size.") parser.add_option("-r", "--sample-rate", type="int", default=8000, help="audio signal sample rate [default=%default]") + parser.add_option("", "--no-eof", action="store_true", default=False, + help="don't send EOF on disconnect") (options, args) = parser.parse_args() if len(args) != 0: parser.print_help() raise SystemExit, 1 # Create an instance of a hierarchical block - top_block = dial_tone_source(options.src_name, options.dst_name, options.dst_port, - options.packet_size, options.sample_rate) + top_block = dial_tone_source(options.host, options.port, + options.packet_size, options.sample_rate, + not options.no_eof) try: # Run forever @@ -67,4 +68,3 @@ if __name__ == '__main__': except KeyboardInterrupt: # Ctrl-C exits pass - diff --git a/gnuradio-examples/python/network/vector_sink.py b/gnuradio-examples/python/network/vector_sink.py index 981cc598b..5d73858a3 100755 --- a/gnuradio-examples/python/network/vector_sink.py +++ b/gnuradio-examples/python/network/vector_sink.py @@ -1,6 +1,6 @@ #!/usr/bin/env python # -# Copyright 2006 Free Software Foundation, Inc. +# Copyright 2006,2010 Free Software Foundation, Inc. # # This file is part of GNU Radio # @@ -25,28 +25,35 @@ from gnuradio.eng_option import eng_option from optparse import OptionParser class vector_sink(gr.top_block): - def __init__(self, src, port, pkt_size): + def __init__(self, host, port, pkt_size, eof, wait): gr.top_block.__init__(self, "vector_sink") - udp = gr.udp_source(gr.sizeof_float, src, port, pkt_size) + udp = gr.udp_source(gr.sizeof_float, host, port, pkt_size, + eof=eof, wait=wait) sink = gr.file_sink(gr.sizeof_float, "received.dat") self.connect(udp, sink) if __name__ == "__main__": parser = OptionParser(option_class=eng_option) - parser.add_option("", "--src-name", type="string", default="localhost", + parser.add_option("", "--host", type="string", default="0.0.0.0", help="local host name (domain name or IP address)") - parser.add_option("", "--src-port", type="int", default=65500, + parser.add_option("", "--port", type="int", default=65500, help="port value to listen to for connection") parser.add_option("", "--packet-size", type="int", default=1471, help="packet size.") + parser.add_option("", "--no-eof", action="store_true", default=False, + help="don't send EOF on disconnect") + parser.add_option("", "--no-wait", action="store_true", default=False, + help="don't wait for source") (options, args) = parser.parse_args() if len(args) != 0: parser.print_help() raise SystemExit, 1 # Create an instance of a hierarchical block - top_block = vector_sink(options.src_name, options.src_port, options.packet_size) + top_block = vector_sink(options.host, options.port, + options.packet_size, + not options.no_eof, not options.no_wait) try: # Run forever diff --git a/gnuradio-examples/python/network/vector_source.py b/gnuradio-examples/python/network/vector_source.py index e7ec2a461..0e7d67844 100755 --- a/gnuradio-examples/python/network/vector_source.py +++ b/gnuradio-examples/python/network/vector_source.py @@ -1,6 +1,6 @@ #!/usr/bin/env python # -# Copyright 2006 Free Software Foundation, Inc. +# Copyright 2006,2010 Free Software Foundation, Inc. # # This file is part of GNU Radio # @@ -25,31 +25,31 @@ from gnuradio.eng_option import eng_option from optparse import OptionParser class vector_source(gr.top_block): - def __init__(self, src, dst, port, pkt_size): + def __init__(self, host, port, pkt_size, eof): gr.top_block.__init__(self, "vector_source") data = [i*0.01 for i in range(1000)] vec = gr.vector_source_f(data, True) - udp = gr.udp_sink(gr.sizeof_float, src, 0, dst, port, pkt_size) + udp = gr.udp_sink(gr.sizeof_float, host, port, pkt_size, eof=eof) self.connect(vec, udp) if __name__ == '__main__': parser = OptionParser(option_class=eng_option) - parser.add_option("", "--src-name", type="string", default="localhost", - help="local host name (domain name or IP address)") - parser.add_option("", "--dst-name", type="string", default="localhost", + parser.add_option("", "--host", type="string", default="localhost", help="Remote host name (domain name or IP address") - parser.add_option("", "--dst-port", type="int", default=65500, - help="port value to connect to") + parser.add_option("", "--port", type="int", default=65500, + help="port number to connect to") parser.add_option("", "--packet-size", type="int", default=1471, help="packet size.") + parser.add_option("", "--no-eof", action="store_true", default=False, + help="don't send EOF on disconnect") (options, args) = parser.parse_args() if len(args) != 0: parser.print_help() raise SystemExit, 1 # Create an instance of a hierarchical block - top_block = vector_source(options.src_name, options.dst_name, - options.dst_port, options.packet_size) + top_block = vector_source(options.host, options.port, options.packet_size, + not options.no_eof) try: # Run forever |