diff options
Diffstat (limited to 'gr-blocks/python')
-rw-r--r-- | gr-blocks/python/blocks/CMakeLists.txt | 1 | ||||
-rw-r--r-- | gr-blocks/python/blocks/qa_logger.py | 96 | ||||
-rwxr-xr-x | gr-blocks/python/blocks/qa_message.py | 31 | ||||
-rw-r--r-- | gr-blocks/python/blocks/qa_message_tags.py | 27 | ||||
-rwxr-xr-x | gr-blocks/python/blocks/qa_nlog10.py | 6 | ||||
-rwxr-xr-x | gr-blocks/python/blocks/qa_pdu.py | 19 | ||||
-rw-r--r-- | gr-blocks/python/grc_gnuradio/CMakeLists.txt | 37 | ||||
-rw-r--r-- | gr-blocks/python/grc_gnuradio/README | 11 | ||||
-rw-r--r-- | gr-blocks/python/grc_gnuradio/__init__.py | 1 | ||||
-rw-r--r-- | gr-blocks/python/grc_gnuradio/blks2/__init__.py | 30 | ||||
-rw-r--r-- | gr-blocks/python/grc_gnuradio/blks2/error_rate.py | 143 | ||||
-rw-r--r-- | gr-blocks/python/grc_gnuradio/blks2/selector.py | 147 | ||||
-rw-r--r-- | gr-blocks/python/grc_gnuradio/blks2/tcp.py | 74 |
13 files changed, 107 insertions, 516 deletions
diff --git a/gr-blocks/python/blocks/CMakeLists.txt b/gr-blocks/python/blocks/CMakeLists.txt index 19d808b1dd..afb860a075 100644 --- a/gr-blocks/python/blocks/CMakeLists.txt +++ b/gr-blocks/python/blocks/CMakeLists.txt @@ -26,7 +26,6 @@ GR_PYTHON_INSTALL( parse_file_metadata.py stream_to_vector_decimator.py DESTINATION ${GR_PYTHON_DIR}/gnuradio/blocks - COMPONENT "blocks_python" ) ######################################################################## diff --git a/gr-blocks/python/blocks/qa_logger.py b/gr-blocks/python/blocks/qa_logger.py new file mode 100644 index 0000000000..d2b6b3ee5e --- /dev/null +++ b/gr-blocks/python/blocks/qa_logger.py @@ -0,0 +1,96 @@ +#!/usr/bin/env python +# +# Copyright 2016 Free Software Foundation, Inc. +# +# This file is part of GNU Radio +# +# GNU Radio is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3, or (at your option) +# any later version. +# +# GNU Radio is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with GNU Radio; see the file COPYING. If not, write to +# the Free Software Foundation, Inc., 51 Franklin Street, +# Boston, MA 02110-1301, USA. +# + +from gnuradio import gr, gr_unittest, blocks + +class test_logger (gr_unittest.TestCase): + + def setUp(self): + pass + + def tearDown(self): + pass + + def set_and_assert_log_level(self, block, level): + block.set_log_level(level) + self.assertEqual(block.log_level(), level) + + def test_log_level_for_block(self): + # Test the python API for getting and setting log levels of individual block + # go through all of the documented log_levels + ns = blocks.null_source(1) + self.set_and_assert_log_level(ns, "notset") + self.set_and_assert_log_level(ns, "debug") + self.set_and_assert_log_level(ns, "info") + self.set_and_assert_log_level(ns, "notice") + self.set_and_assert_log_level(ns, "warn") + self.set_and_assert_log_level(ns, "error") + self.set_and_assert_log_level(ns, "crit") + self.set_and_assert_log_level(ns, "alert") + self.set_and_assert_log_level(ns, "emerg") + # There's a couple of special cases. "off" == "notset" (specific to gr) + # and "fatal" == "emerg" (built in to log4cpp) + ns.set_log_level("off") + self.assertEqual(ns.log_level(), "notset") + ns.set_log_level("fatal") + self.assertEqual(ns.log_level(), "emerg") + # Make sure exception is throw on bogus data + self.assertRaises(RuntimeError, ns.set_log_level, "11") + + + def test_log_level_for_tb(self): + # Test the python API for getting and setting log levels for a top_block + nsrc = blocks.null_source(4) + nsnk = blocks.null_sink(4) + # Set all log levels to a known state + nsrc.set_log_level("debug") + nsnk.set_log_level("debug") + tb = gr.top_block() + tb.connect(nsrc, nsnk) + # confirm that the tb has log_level of first block + self.assertEqual(tb.log_level(), "debug") + # confirm that changing tb log_level propagates to connected blocks + tb.set_log_level("alert") + self.assertEqual(tb.log_level(), "alert") + self.assertEqual(nsrc.log_level(), "alert") + self.assertEqual(nsnk.log_level(), "alert") + + def test_log_level_for_hier_block(self): + # Test the python API for getting and setting log levels for hier blocks + nsrc = blocks.null_source(4) + nsnk = blocks.null_sink(4) + b = blocks.stream_to_vector_decimator(4, 1, 1, 1) # just a random hier block that exists + tb = gr.top_block() + tb.connect(nsrc, b, nsnk) + tb.set_log_level("debug") + self.assertEqual(tb.log_level(), "debug") + self.assertEqual(nsrc.log_level(), "debug") + self.assertEqual(nsnk.log_level(), "debug") + self.assertEqual(b.one_in_n.log_level(), "debug") + tb.set_log_level("alert") + self.assertEqual(tb.log_level(), "alert") + self.assertEqual(nsrc.log_level(), "alert") + self.assertEqual(nsnk.log_level(), "alert") + self.assertEqual(b.one_in_n.log_level(), "alert") + +if __name__ == '__main__': + gr_unittest.run(test_logger, "test_logger.xml") diff --git a/gr-blocks/python/blocks/qa_message.py b/gr-blocks/python/blocks/qa_message.py index 1d677007b4..1d0380d44c 100755 --- a/gr-blocks/python/blocks/qa_message.py +++ b/gr-blocks/python/blocks/qa_message.py @@ -1,6 +1,6 @@ #!/usr/bin/env python # -# Copyright 2004,2010,2013 Free Software Foundation, Inc. +# Copyright 2004,2010,2013,2016 Free Software Foundation, Inc. # # This file is part of GNU Radio # @@ -100,35 +100,6 @@ class test_message(gr_unittest.TestCase): tb.run() self.assertEquals(input_data, dst.data()) - def test_301(self): - # Use itemsize, limit constructor - src = blocks.message_source(gr.sizeof_char) - dst = blocks.vector_sink_b() - tb = gr.top_block() - tb.connect(src, dst) - src.msgq().insert_tail(gr.message_from_string('01234')) - src.msgq().insert_tail(gr.message_from_string('5')) - src.msgq().insert_tail(gr.message_from_string('')) - src.msgq().insert_tail(gr.message_from_string('6789')) - src.msgq().insert_tail(gr.message(1)) # send EOF - tb.run() - self.assertEquals(tuple(map(ord, '0123456789')), dst.data()) - - def test_302(self): - # Use itemsize, msgq constructor - msgq = gr.msg_queue() - src = blocks.message_source(gr.sizeof_char, msgq) - dst = blocks.vector_sink_b() - tb = gr.top_block() - tb.connect(src, dst) - src.msgq().insert_tail(gr.message_from_string('01234')) - src.msgq().insert_tail(gr.message_from_string('5')) - src.msgq().insert_tail(gr.message_from_string('')) - src.msgq().insert_tail(gr.message_from_string('6789')) - src.msgq().insert_tail(gr.message(1)) # send EOF - tb.run() - self.assertEquals(tuple(map(ord, '0123456789')), dst.data()) - def test_debug_401(self): msg = pmt.intern("TESTING") src = blocks.message_strobe(msg, 500) diff --git a/gr-blocks/python/blocks/qa_message_tags.py b/gr-blocks/python/blocks/qa_message_tags.py deleted file mode 100644 index 0d4f77bf9f..0000000000 --- a/gr-blocks/python/blocks/qa_message_tags.py +++ /dev/null @@ -1,27 +0,0 @@ -import time - -from gnuradio import gr, gr_unittest, blocks - -class test_message_tags (gr_unittest.TestCase): - - def test_1 (self): - data = ('hello', 'you', 'there') - tx_msgq = gr.msg_queue() - rx_msgq = gr.msg_queue() - for d in data: - tx_msgq.insert_tail(gr.message_from_string(d)) - tx_msgq.insert_tail(gr.message(1)) # send EOF - tb = gr.top_block() - src = blocks.message_source(gr.sizeof_char, tx_msgq, "packet_length") - snk = blocks.message_sink(gr.sizeof_char, rx_msgq, False, "packet_length") - tb.connect(src, snk) - tb.start() - time.sleep(1) - tb.stop() - for d in data: - msg = rx_msgq.delete_head() - contents = msg.to_string() - self.assertEqual(d, contents) - -if __name__ == '__main__': - gr_unittest.run(test_message_tags, "test_message_tags.xml") diff --git a/gr-blocks/python/blocks/qa_nlog10.py b/gr-blocks/python/blocks/qa_nlog10.py index 0194e85d48..c925479f59 100755 --- a/gr-blocks/python/blocks/qa_nlog10.py +++ b/gr-blocks/python/blocks/qa_nlog10.py @@ -31,15 +31,15 @@ class test_nlog10(gr_unittest.TestCase): self.tb = None def test_001(self): - src_data = (-10, 0, 10, 100, 1000, 10000, 100000) - expected_result = (-180, -180, 10, 20, 30, 40, 50) + src_data = (1, 10, 100, 1000, 10000, 100000) + expected_result = (0, 10, 20, 30, 40, 50) src = blocks.vector_source_f(src_data) op = blocks.nlog10_ff(10) dst = blocks.vector_sink_f() self.tb.connect (src, op, dst) self.tb.run() result_data = dst.data() - self.assertFloatTuplesAlmostEqual (expected_result, result_data) + self.assertFloatTuplesAlmostEqual (expected_result, result_data, 5) if __name__ == '__main__': diff --git a/gr-blocks/python/blocks/qa_pdu.py b/gr-blocks/python/blocks/qa_pdu.py index bbee3605ba..79d39df48b 100755 --- a/gr-blocks/python/blocks/qa_pdu.py +++ b/gr-blocks/python/blocks/qa_pdu.py @@ -55,18 +55,17 @@ class test_pdu(gr_unittest.TestCase): self.tb.connect(src, snk2) self.tb.connect(src, snk3) self.tb.msg_connect(snk3, "pdus", dbg, "store") - self.tb.start() # make our reference and message pmts port = pmt.intern("pdus") msg = pmt.cons( pmt.PMT_NIL, pmt.make_u8vector(16, 0xFF)) # post the message - src.to_basic_block()._post(port, msg) # eww, what's that smell? + src.to_basic_block()._post(port, msg) + src.to_basic_block()._post(pmt.intern("system"), + pmt.cons(pmt.intern("done"), pmt.PMT_T)) - while dbg.num_messages() < 1: - time.sleep(0.1) - self.tb.stop() + self.tb.start() self.tb.wait() # Get the vector of data from the vector sink @@ -98,11 +97,11 @@ class test_pdu(gr_unittest.TestCase): msg = pmt.cons( pmt.PMT_NIL, pmt.init_f32vector(10, src_data)) src.to_basic_block()._post(port, msg) + src.to_basic_block()._post(pmt.intern("system"), + pmt.cons(pmt.intern("done"), pmt.PMT_T)) self.tb.start() - #ideally, would wait until we get ten samples - time.sleep(0.2) - self.tb.stop() + self.tb.wait() self.assertEqual(src_data, list(snk.data()) ) @@ -125,9 +124,6 @@ class test_pdu(gr_unittest.TestCase): self.tb.connect(src, s2ts, ts2pdu) self.tb.msg_connect(ts2pdu, "pdus", dbg, "store") self.tb.start() - while dbg.num_messages() < 1: - time.sleep(0.1) - self.tb.stop() self.tb.wait() result_msg = dbg.get_message(0) metadata = pmt.to_python(pmt.car(result_msg)) @@ -138,4 +134,3 @@ class test_pdu(gr_unittest.TestCase): if __name__ == '__main__': gr_unittest.run(test_pdu, "test_pdu.xml") - diff --git a/gr-blocks/python/grc_gnuradio/CMakeLists.txt b/gr-blocks/python/grc_gnuradio/CMakeLists.txt deleted file mode 100644 index 9ff1240997..0000000000 --- a/gr-blocks/python/grc_gnuradio/CMakeLists.txt +++ /dev/null @@ -1,37 +0,0 @@ -# Copyright 2011 Free Software Foundation, Inc. -# -# This file is part of GNU Radio -# -# GNU Radio is free software; you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation; either version 3, or (at your option) -# any later version. -# -# GNU Radio is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with GNU Radio; see the file COPYING. If not, write to -# the Free Software Foundation, Inc., 51 Franklin Street, -# Boston, MA 02110-1301, USA. - -######################################################################## - -include(GrPython) - -GR_PYTHON_INSTALL( - FILES __init__.py - DESTINATION ${GR_PYTHON_DIR}/grc_gnuradio - COMPONENT "blocks_python" -) - -GR_PYTHON_INSTALL(FILES - blks2/__init__.py - blks2/error_rate.py - blks2/selector.py - blks2/tcp.py - DESTINATION ${GR_PYTHON_DIR}/grc_gnuradio/blks2 - COMPONENT "blocks_python" -) diff --git a/gr-blocks/python/grc_gnuradio/README b/gr-blocks/python/grc_gnuradio/README deleted file mode 100644 index 897eed65ca..0000000000 --- a/gr-blocks/python/grc_gnuradio/README +++ /dev/null @@ -1,11 +0,0 @@ -This is the grc_gnuradio module. -It contains supplemental python modules that grc uses at runtime. -The supplemental modules are meant to mimic modules in gnuradio. -These will be phased-out as new functionaility is merged into gnuradio. - -The blk2s module wraps many blocks in blks2 and gives them streaming outputs. -Will be phased-out by new message passing implementations. -Other blks2 blocks will hopefully make their way into blks2impl. - -The wxgui module contains a top_block + wxgui frame. -Will be phased-out by gui.py in wxgui and a new top block template. diff --git a/gr-blocks/python/grc_gnuradio/__init__.py b/gr-blocks/python/grc_gnuradio/__init__.py deleted file mode 100644 index 8b13789179..0000000000 --- a/gr-blocks/python/grc_gnuradio/__init__.py +++ /dev/null @@ -1 +0,0 @@ - diff --git a/gr-blocks/python/grc_gnuradio/blks2/__init__.py b/gr-blocks/python/grc_gnuradio/blks2/__init__.py deleted file mode 100644 index d3c8210834..0000000000 --- a/gr-blocks/python/grc_gnuradio/blks2/__init__.py +++ /dev/null @@ -1,30 +0,0 @@ -# Copyright 2008-2011 Free Software Foundation, Inc. -# -# This file is part of GNU Radio -# -# GNU Radio is free software; you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation; either version 3, or (at your option) -# any later version. -# -# GNU Radio is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with GNU Radio; see the file COPYING. If not, write to -# the Free Software Foundation, Inc., 51 Franklin Street, -# Boston, MA 02110-1301, USA. -# - -from selector import selector, valve -from error_rate import error_rate -from tcp import tcp_source, tcp_sink - -try: - from packet import options, packet_encoder, packet_decoder, \ - packet_mod_b, packet_mod_s, packet_mod_i, packet_mod_f, packet_mod_c, \ - packet_demod_b, packet_demod_s, packet_demod_i, packet_demod_f, packet_demod_c -except ImportError: - pass # only available if gr-digital is install diff --git a/gr-blocks/python/grc_gnuradio/blks2/error_rate.py b/gr-blocks/python/grc_gnuradio/blks2/error_rate.py deleted file mode 100644 index df03f551b3..0000000000 --- a/gr-blocks/python/grc_gnuradio/blks2/error_rate.py +++ /dev/null @@ -1,143 +0,0 @@ -# Copyright 2008 Free Software Foundation, Inc. -# -# This file is part of GNU Radio -# -# GNU Radio is free software; you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation; either version 3, or (at your option) -# any later version. -# -# GNU Radio is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with GNU Radio; see the file COPYING. If not, write to -# the Free Software Foundation, Inc., 51 Franklin Street, -# Boston, MA 02110-1301, USA. -# - -default_win_size = 1000 - -from gnuradio import gr -from gnuradio import blocks -import gnuradio.gr.gr_threading as _threading -import numpy - -#generate 1s counts array -_1s_counts = [sum([1&(i>>j) for j in range(8)]) for i in range(2**8)] - -class input_watcher(_threading.Thread): - """ - Read samples from the message queue and hand them to the callback. - """ - - def __init__(self, msgq, callback): - self._msgq = msgq - self._callback = callback - _threading.Thread.__init__(self) - self.setDaemon(1) - self.keep_running = True - self.start() - - def run(self): - r = '' - while True: - msg = self._msgq.delete_head() - itemsize = int(msg.arg1()) - nitems = int(msg.arg2()) - s = r + msg.to_string() - i = (nitems-nitems%2)*itemsize - r = s[i:] - s = s[:i] - samples = numpy.fromstring(s, numpy.int8) - self._callback(samples) - -class error_rate(gr.hier_block2): - """ - Sample the incoming data streams (byte) and calculate the bit or symbol error rate. - Write the running rate to the output data stream (float). - """ - - def __init__(self, type='BER', win_size=default_win_size, bits_per_symbol=2): - """ - Error rate constructor. - - Args: - type: a string 'BER' or 'SER' - win_size: the number of samples to calculate over - bits_per_symbol: the number of information bits per symbol (BER only) - """ - #init - gr.hier_block2.__init__( - self, 'error_rate', - gr.io_signature(2, 2, gr.sizeof_char), - gr.io_signature(1, 1, gr.sizeof_float), - ) - - print "Warning: the blks2.error_rate is deprecated." - - assert type in ('BER', 'SER') - self._max_samples = win_size - self._bits_per_symbol = bits_per_symbol - #setup message queue - msg_source = blocks.message_source(gr.sizeof_float, 1) - self._msgq_source = msg_source.msgq() - msgq_sink = gr.msg_queue(2) - msg_sink = blocks.message_sink(gr.sizeof_char, msgq_sink, False) #False -> blocking - inter = blocks.interleave(gr.sizeof_char) - #start thread - self._num_errs = 0 - self._err_index = 0 - self._num_samps = 0 - self._err_array = numpy.zeros(self._max_samples, numpy.int8) - if type == 'BER': - input_watcher(msgq_sink, self._handler_ber) - elif type == 'SER': - input_watcher(msgq_sink, self._handler_ser) - #connect - self.connect(msg_source, self) - self.connect((self, 0), (inter, 0)) - self.connect((self, 1), (inter, 1)) - self.connect(inter, msg_sink) - - def _handler_ber(self, samples): - num = len(samples)/2 - arr = numpy.zeros(num, numpy.float32) - for i in range(num): - old_err = self._err_array[self._err_index] - #record error - self._err_array[self._err_index] = _1s_counts[samples[i*2] ^ samples[i*2 + 1]] - self._num_errs = self._num_errs + self._err_array[self._err_index] - old_err - #increment index - self._err_index = (self._err_index + 1)%self._max_samples - self._num_samps = min(self._num_samps + 1, self._max_samples) - #write sample - arr[i] = float(self._num_errs)/float(self._num_samps*self._bits_per_symbol) - #write message - msg = gr.message_from_string(arr.tostring(), 0, gr.sizeof_float, num) - self._msgq_source.insert_tail(msg) - - def _handler_ser(self, samples): - num = len(samples)/2 - arr = numpy.zeros(num, numpy.float32) - for i in range(num): - old_err = self._err_array[self._err_index] - #record error - ref = samples[i*2] - res = samples[i*2 + 1] - if ref == res: - self._err_array[self._err_index] = 0 - else: - self._err_array[self._err_index] = 1 - #update number of errors - self._num_errs = self._num_errs + self._err_array[self._err_index] - old_err - #increment index - self._err_index = (self._err_index + 1)%self._max_samples - self._num_samps = min(self._num_samps + 1, self._max_samples) - #write sample - arr[i] = float(self._num_errs)/float(self._num_samps) - #write message - msg = gr.message_from_string(arr.tostring(), 0, gr.sizeof_float, num) - self._msgq_source.insert_tail(msg) diff --git a/gr-blocks/python/grc_gnuradio/blks2/selector.py b/gr-blocks/python/grc_gnuradio/blks2/selector.py deleted file mode 100644 index 0a74309688..0000000000 --- a/gr-blocks/python/grc_gnuradio/blks2/selector.py +++ /dev/null @@ -1,147 +0,0 @@ -# -# Copyright 2008,2013 Free Software Foundation, Inc. -# -# This file is part of GNU Radio -# -# GNU Radio is free software; you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation; either version 3, or (at your option) -# any later version. -# -# GNU Radio is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with GNU Radio; see the file COPYING. If not, write to -# the Free Software Foundation, Inc., 51 Franklin Street, -# Boston, MA 02110-1301, USA. -# - -from gnuradio import gr -from gnuradio import blocks - -class selector(gr.hier_block2): - """A hier2 block with N inputs and M outputs, where data is only forwarded through input n to output m.""" - def __init__(self, item_size, num_inputs, num_outputs, input_index, output_index): - """ - Selector constructor. - - Args: - item_size: the size of the gr data stream in bytes - num_inputs: the number of inputs (integer) - num_outputs: the number of outputs (integer) - input_index: the index for the source data - output_index: the index for the destination data - """ - gr.hier_block2.__init__( - self, 'selector', - gr.io_signature(num_inputs, num_inputs, item_size), - gr.io_signature(num_outputs, num_outputs, item_size), - ) - - print "Warning: the blks2.selector block is deprecated." - - #terminator blocks for unused inputs and outputs - self.input_terminators = [blocks.null_sink(item_size) for i in range(num_inputs)] - self.output_terminators = [blocks.head(item_size, 0) for i in range(num_outputs)] - self.copy = blocks.copy(item_size) - #connections - for i in range(num_inputs): self.connect((self, i), self.input_terminators[i]) - for i in range(num_outputs): self.connect(blocks.null_source(item_size), - self.output_terminators[i], (self, i)) - self.item_size = item_size - self.input_index = input_index - self.output_index = output_index - self.num_inputs = num_inputs - self.num_outputs = num_outputs - self._connect_current() - - def _indexes_valid(self): - """ - Are the input and output indexes within range of the number of inputs and outputs? - - Returns: - true if input index and output index are in range - """ - return self.input_index in range(self.num_inputs) and self.output_index in range(self.num_outputs) - - def _connect_current(self): - """If the input and output indexes are valid: - disconnect the blocks at the input and output index from their terminators, - and connect them to one another. Then connect the terminators to one another.""" - if self._indexes_valid(): - self.disconnect((self, self.input_index), self.input_terminators[self.input_index]) - self.disconnect(self.output_terminators[self.output_index], (self, self.output_index)) - self.connect((self, self.input_index), self.copy) - self.connect(self.copy, (self, self.output_index)) - self.connect(self.output_terminators[self.output_index], self.input_terminators[self.input_index]) - - def _disconnect_current(self): - """If the input and output indexes are valid: - disconnect the blocks at the input and output index from one another, - and the terminators at the input and output index from one another. - Reconnect the blocks to the terminators.""" - if self._indexes_valid(): - self.disconnect((self, self.input_index), self.copy) - self.disconnect(self.copy, (self, self.output_index)) - self.disconnect(self.output_terminators[self.output_index], self.input_terminators[self.input_index]) - self.connect((self, self.input_index), self.input_terminators[self.input_index]) - self.connect(self.output_terminators[self.output_index], (self, self.output_index)) - - def set_input_index(self, input_index): - """ - Change the block to the new input index if the index changed. - - Args: - input_index: the new input index - """ - if self.input_index != input_index: - self.lock() - self._disconnect_current() - self.input_index = input_index - self._connect_current() - self.unlock() - - def set_output_index(self, output_index): - """ - Change the block to the new output index if the index changed. - - Args: - output_index: the new output index - """ - if self.output_index != output_index: - self.lock() - self._disconnect_current() - self.output_index = output_index - self._connect_current() - self.unlock() - -class valve(selector): - """Wrapper for selector with 1 input and 1 output.""" - - def __init__(self, item_size, open): - """ - Constructor for valve. - - Args: - item_size: the size of the gr data stream in bytes - open: true if initial valve state is open - """ - if open: output_index = -1 - else: output_index = 0 - selector.__init__(self, item_size, 1, 1, 0, output_index) - - print "Warning: the blks2.valve block is deprecated." - - def set_open(self, open): - """ - Callback to set open state. - - Args: - open: true to set valve state to open - """ - if open: output_index = -1 - else: output_index = 0 - self.set_output_index(output_index) diff --git a/gr-blocks/python/grc_gnuradio/blks2/tcp.py b/gr-blocks/python/grc_gnuradio/blks2/tcp.py deleted file mode 100644 index 6ae24d3a7b..0000000000 --- a/gr-blocks/python/grc_gnuradio/blks2/tcp.py +++ /dev/null @@ -1,74 +0,0 @@ -# -# Copyright 2009 Free Software Foundation, Inc. -# -# This file is part of GNU Radio -# -# GNU Radio is free software; you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation; either version 3, or (at your option) -# any later version. -# -# GNU Radio is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with GNU Radio; see the file COPYING. If not, write to -# the Free Software Foundation, Inc., 51 Franklin Street, -# Boston, MA 02110-1301, USA. -# - -from gnuradio import gr, blocks -import socket -import os - -def _get_sock_fd(addr, port, server): - """ - Get the file descriptor for the socket. - As a client, block on connect, dup the socket descriptor. - As a server, block on accept, dup the client descriptor. - - Args: - addr: the ip address string - port: the tcp port number - server: true for server mode, false for client mode - - Returns: - the file descriptor number - """ - sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) - if server: - sock.bind((addr, port)) - sock.listen(1) - clientsock, address = sock.accept() - return os.dup(clientsock.fileno()) - else: - sock.connect((addr, port)) - return os.dup(sock.fileno()) - -class tcp_source(gr.hier_block2): - def __init__(self, itemsize, addr, port, server=True): - #init hier block - gr.hier_block2.__init__( - self, 'tcp_source', - gr.io_signature(0, 0, 0), - gr.io_signature(1, 1, itemsize), - ) - fd = _get_sock_fd(addr, port, server) - self.connect(blocks.file_descriptor_source(itemsize, fd), self) - - print "Warning: the blks2.tcp_source block is deprecated." - -class tcp_sink(gr.hier_block2): - def __init__(self, itemsize, addr, port, server=False): - #init hier block - gr.hier_block2.__init__( - self, 'tcp_sink', - gr.io_signature(1, 1, itemsize), - gr.io_signature(0, 0, 0), - ) - fd = _get_sock_fd(addr, port, server) - self.connect(self, blocks.file_descriptor_sink(itemsize, fd)) - - print "Warning: the blks2.tcp_sink block is deprecated." |