summaryrefslogtreecommitdiff
path: root/gr-blocks/python
diff options
context:
space:
mode:
authorJosh Morman <jmorman@gnuradio.org>2021-11-24 12:03:48 -0500
committermormj <34754695+mormj@users.noreply.github.com>2021-11-24 14:41:53 -0500
commit25e2e7287b20e8dd8e5cf9c0fe07eb754b81c10c (patch)
tree0b76f5866d4ddf592d750ac4548ba7192d505f9e /gr-blocks/python
parent42e58f1ca211115e9a76922c36dfbf2b1ad39978 (diff)
blocks: pep8 formatting
Signed-off-by: Josh Morman <jmorman@gnuradio.org>
Diffstat (limited to 'gr-blocks/python')
-rw-r--r--gr-blocks/python/blocks/__init__.py2
-rw-r--r--gr-blocks/python/blocks/matrix_interleaver.py17
-rw-r--r--gr-blocks/python/blocks/msg_meta_to_pair.py8
-rw-r--r--gr-blocks/python/blocks/msg_pair_to_var.py12
-rw-r--r--gr-blocks/python/blocks/parse_file_metadata.py51
-rw-r--r--gr-blocks/python/blocks/pdu_compatibility.py31
-rw-r--r--gr-blocks/python/blocks/qa_add_mult_v.py4
-rw-r--r--gr-blocks/python/blocks/qa_block_gateway.py2
-rwxr-xr-xgr-blocks/python/blocks/qa_matrix_interleaver.py9
-rw-r--r--gr-blocks/python/blocks/qa_message_debug.py26
-rw-r--r--gr-blocks/python/blocks/qa_message_strobe.py25
-rw-r--r--gr-blocks/python/blocks/qa_pack_k_bits.py29
-rw-r--r--gr-blocks/python/blocks/qa_peak_detector2.py6
-rwxr-xr-xgr-blocks/python/blocks/qa_stream_demux.py4
-rw-r--r--gr-blocks/python/blocks/qa_stream_mux.py14
-rw-r--r--gr-blocks/python/blocks/qa_unpack_k_bits.py28
-rw-r--r--gr-blocks/python/blocks/stream_to_vector_decimator.py11
-rw-r--r--gr-blocks/python/blocks/var_to_msg.py12
18 files changed, 181 insertions, 110 deletions
diff --git a/gr-blocks/python/blocks/__init__.py b/gr-blocks/python/blocks/__init__.py
index c9a4b3f756..7178e376dd 100644
--- a/gr-blocks/python/blocks/__init__.py
+++ b/gr-blocks/python/blocks/__init__.py
@@ -27,7 +27,7 @@ from .msg_pair_to_var import msg_pair_to_var
from .var_to_msg import var_to_msg_pair
from .matrix_interleaver import *
-#alias old add_vXX and multiply_vXX
+# alias old add_vXX and multiply_vXX
add_vcc = add_cc
add_vff = add_ff
add_vii = add_ii
diff --git a/gr-blocks/python/blocks/matrix_interleaver.py b/gr-blocks/python/blocks/matrix_interleaver.py
index 26a8e86a6e..3cd962623b 100644
--- a/gr-blocks/python/blocks/matrix_interleaver.py
+++ b/gr-blocks/python/blocks/matrix_interleaver.py
@@ -10,6 +10,7 @@
from gnuradio import gr, blocks
+
class matrix_interleaver(gr.hier_block2):
"""
Block interleaver writes inputs into conceptual rows of the matrix
@@ -21,8 +22,8 @@ class matrix_interleaver(gr.hier_block2):
def __init__(self, itemsize, rows=1, cols=1, deint=False):
gr.hier_block2.__init__(
self, "Matrix Interleaver",
- gr.io_signature(1, 1, itemsize),
- gr.io_signature(1, 1, itemsize),
+ gr.io_signature(1, 1, itemsize),
+ gr.io_signature(1, 1, itemsize),
)
self.itemsize = itemsize
@@ -47,12 +48,14 @@ class matrix_interleaver(gr.hier_block2):
##################################################
# short circuit for unitary rows / columns
if rows == 1 or cols == 1:
- self.passthrough = blocks.copy(self.itemsize)
- self.connect((self, 0), (self.passthrough, 0), (self, 0))
- return
+ self.passthrough = blocks.copy(self.itemsize)
+ self.connect((self, 0), (self.passthrough, 0), (self, 0))
+ return
- self.deinterleaver = blocks.deinterleave(self.itemsize, 1 if deint else cols)
- self.interleaver = blocks.interleave(self.itemsize, cols if deint else 1)
+ self.deinterleaver = blocks.deinterleave(
+ self.itemsize, 1 if deint else cols)
+ self.interleaver = blocks.interleave(
+ self.itemsize, cols if deint else 1)
##################################################
# Connections
diff --git a/gr-blocks/python/blocks/msg_meta_to_pair.py b/gr-blocks/python/blocks/msg_meta_to_pair.py
index 1c6dde2f61..6178c64b6a 100644
--- a/gr-blocks/python/blocks/msg_meta_to_pair.py
+++ b/gr-blocks/python/blocks/msg_meta_to_pair.py
@@ -11,6 +11,7 @@
from gnuradio import gr
import pmt
+
class meta_to_pair(gr.sync_block):
"""
This block converts a metadata dictionary item to a pmt pair that is
@@ -18,8 +19,10 @@ class meta_to_pair(gr.sync_block):
which item in the incoming metadata to output as a pair and what
the pair name is.
"""
+
def __init__(self, incomingKeyName, outgoingPairName):
- gr.sync_block.__init__(self, name="meta_to_pair", in_sig=None, out_sig=None)
+ gr.sync_block.__init__(self, name="meta_to_pair",
+ in_sig=None, out_sig=None)
self.incomingKeyName = str(incomingKeyName)
self.outgoingPairName = str(outgoingPairName)
@@ -51,7 +54,8 @@ class meta_to_pair(gr.sync_block):
new_pair = None
try:
- new_pair = pmt.cons(pmt.intern(self.outgoingPairName), pmt.to_pmt(incomingVal))
+ new_pair = pmt.cons(pmt.intern(
+ self.outgoingPairName), pmt.to_pmt(incomingVal))
except Exception as e:
gr.log.error("Cannot construct new message: %s" % str(e))
return
diff --git a/gr-blocks/python/blocks/msg_pair_to_var.py b/gr-blocks/python/blocks/msg_pair_to_var.py
index 97f73f85f8..ab0fd14973 100644
--- a/gr-blocks/python/blocks/msg_pair_to_var.py
+++ b/gr-blocks/python/blocks/msg_pair_to_var.py
@@ -11,6 +11,7 @@
from gnuradio import gr
import pmt
+
class msg_pair_to_var(gr.sync_block):
"""
This block will take an input message pair and allow you to set a flowgraph variable
@@ -18,8 +19,10 @@ class msg_pair_to_var(gr.sync_block):
of the datatype expected by the flowgraph the behavior of the flowgraph may be
unpredictable.
"""
+
def __init__(self, callback):
- gr.sync_block.__init__(self, name="msg_pair_to_var", in_sig=None, out_sig=None)
+ gr.sync_block.__init__(
+ self, name="msg_pair_to_var", in_sig=None, out_sig=None)
self.callback = callback
@@ -28,15 +31,16 @@ class msg_pair_to_var(gr.sync_block):
def msg_handler(self, msg):
if not pmt.is_pair(msg) or pmt.is_dict(msg) or pmt.is_pdu(msg):
- gr.log.warn("Input message %s is not a simple pair, dropping" % repr(msg))
+ gr.log.warn(
+ "Input message %s is not a simple pair, dropping" % repr(msg))
return
new_val = pmt.to_python(pmt.cdr(msg))
try:
self.callback(new_val)
except Exception as e:
- gr.log.error("Error when calling " + repr(self.callback.name()) + " with "
- + repr(new_val) + " (reason: %s)" % repr(e))
+ gr.log.error("Error when calling " + repr(self.callback.name()) + " with " +
+ repr(new_val) + " (reason: %s)" % repr(e))
def stop(self):
return True
diff --git a/gr-blocks/python/blocks/parse_file_metadata.py b/gr-blocks/python/blocks/parse_file_metadata.py
index d98a6c6127..a6128682d7 100644
--- a/gr-blocks/python/blocks/parse_file_metadata.py
+++ b/gr-blocks/python/blocks/parse_file_metadata.py
@@ -31,23 +31,25 @@ ftype_to_string = {blocks.GR_FILE_BYTE: "bytes",
blocks.GR_FILE_LONG: "long",
blocks.GR_FILE_LONG_LONG: "long long",
blocks.GR_FILE_FLOAT: "float",
- blocks.GR_FILE_DOUBLE: "double" }
+ blocks.GR_FILE_DOUBLE: "double"}
ftype_to_size = {blocks.GR_FILE_BYTE: gr.sizeof_char,
blocks.GR_FILE_SHORT: gr.sizeof_short,
blocks.GR_FILE_INT: gr.sizeof_int,
blocks.GR_FILE_LONG: gr.sizeof_int,
- blocks.GR_FILE_LONG_LONG: 2*gr.sizeof_int,
+ blocks.GR_FILE_LONG_LONG: 2 * gr.sizeof_int,
blocks.GR_FILE_FLOAT: gr.sizeof_float,
blocks.GR_FILE_DOUBLE: gr.sizeof_double}
+
def parse_header(p, VERBOSE=False):
dump = pmt.PMT_NIL
info = dict()
if(pmt.is_dict(p) is False):
- sys.stderr.write("Header is not a PMT dictionary: invalid or corrupt data file.\n")
+ sys.stderr.write(
+ "Header is not a PMT dictionary: invalid or corrupt data file.\n")
sys.exit(1)
# GET FILE FORMAT VERSION NUMBER
@@ -57,7 +59,8 @@ def parse_header(p, VERBOSE=False):
if(VERBOSE):
print("Version Number: {0}".format(version))
else:
- sys.stderr.write("Could not find key 'version': invalid or corrupt data file.\n")
+ sys.stderr.write(
+ "Could not find key 'version': invalid or corrupt data file.\n")
sys.exit(1)
# EXTRACT SAMPLE RATE
@@ -68,7 +71,8 @@ def parse_header(p, VERBOSE=False):
if(VERBOSE):
print("Sample Rate: {0:.2f} sps".format(samp_rate))
else:
- sys.stderr.write("Could not find key 'sr': invalid or corrupt data file.\n")
+ sys.stderr.write(
+ "Could not find key 'sr': invalid or corrupt data file.\n")
sys.exit(1)
# EXTRACT TIME STAMP
@@ -83,15 +87,16 @@ def parse_header(p, VERBOSE=False):
info["rx_time_fracs"] = fracs
info["rx_time"] = t
if(VERBOSE):
- # We need are going to print with ~1e-16 resolution,
- # which is the precision we can expect in secs.
- # The default value of precision for decimal
- # is 28. The value of secs is not expected to be larger
- # than 1e12, so this precision is enough.
- s = decimal.Decimal(secs) + decimal.Decimal(fracs)
- print("Seconds: {0:.16f}".format(s))
+ # We need are going to print with ~1e-16 resolution,
+ # which is the precision we can expect in secs.
+ # The default value of precision for decimal
+ # is 28. The value of secs is not expected to be larger
+ # than 1e12, so this precision is enough.
+ s = decimal.Decimal(secs) + decimal.Decimal(fracs)
+ print("Seconds: {0:.16f}".format(s))
else:
- sys.stderr.write("Could not find key 'time': invalid or corrupt data file.\n")
+ sys.stderr.write(
+ "Could not find key 'time': invalid or corrupt data file.\n")
sys.exit(1)
# EXTRACT ITEM SIZE
@@ -102,7 +107,8 @@ def parse_header(p, VERBOSE=False):
if(VERBOSE):
print("Item size: {0}".format(dsize))
else:
- sys.stderr.write("Could not find key 'size': invalid or corrupt data file.\n")
+ sys.stderr.write(
+ "Could not find key 'size': invalid or corrupt data file.\n")
sys.exit(1)
# EXTRACT DATA TYPE
@@ -114,7 +120,8 @@ def parse_header(p, VERBOSE=False):
if(VERBOSE):
print("Data Type: {0} ({1})".format(stype, dtype))
else:
- sys.stderr.write("Could not find key 'type': invalid or corrupt data file.\n")
+ sys.stderr.write(
+ "Could not find key 'type': invalid or corrupt data file.\n")
sys.exit(1)
# EXTRACT COMPLEX
@@ -125,7 +132,8 @@ def parse_header(p, VERBOSE=False):
if(VERBOSE):
print("Complex? {0}".format(cplx))
else:
- sys.stderr.write("Could not find key 'cplx': invalid or corrupt data file.\n")
+ sys.stderr.write(
+ "Could not find key 'cplx': invalid or corrupt data file.\n")
sys.exit(1)
# EXTRACT WHERE CURRENT SEGMENT STARTS
@@ -140,7 +148,8 @@ def parse_header(p, VERBOSE=False):
print("Extra Length: {0}".format((info["extra_len"])))
print("Extra Header? {0}".format(info["has_extra"]))
else:
- sys.stderr.write("Could not find key 'strt': invalid or corrupt data file.\n")
+ sys.stderr.write(
+ "Could not find key 'strt': invalid or corrupt data file.\n")
sys.exit(1)
# EXTRACT SIZE OF DATA
@@ -156,15 +165,19 @@ def parse_header(p, VERBOSE=False):
print("Size of Data: {0} bytes".format(nbytes))
print(" {0} items".format(nitems))
else:
- sys.stderr.write("Could not find key 'size': invalid or corrupt data file.\n")
+ sys.stderr.write(
+ "Could not find key 'size': invalid or corrupt data file.\n")
sys.exit(1)
return info
# IF THERE IS EXTRA DATA, PULL OUT THE DICTIONARY AND PARSE IT
+
+
def parse_extra_dict(p, info, VERBOSE=False):
if(pmt.is_dict(p) is False):
- sys.stderr.write("Extra header is not a PMT dictionary: invalid or corrupt data file.\n")
+ sys.stderr.write(
+ "Extra header is not a PMT dictionary: invalid or corrupt data file.\n")
sys.exit(1)
items = pmt.dict_items(p)
diff --git a/gr-blocks/python/blocks/pdu_compatibility.py b/gr-blocks/python/blocks/pdu_compatibility.py
index 3d6af5f548..ed730055ac 100644
--- a/gr-blocks/python/blocks/pdu_compatibility.py
+++ b/gr-blocks/python/blocks/pdu_compatibility.py
@@ -16,34 +16,46 @@ from gnuradio import gr, network, pdu
######## PDU BLOCKS MOVED TO GR-PDU ########
+
class pdu_filter(pdu.pdu_filter):
def __init__(self, *args, **kwargs):
- gr.log.warn('`pdu_filter` has moved to gr-pdu and will be removed from gr-blocks soon. Please update to use pdu.pdu_filter()')
+ gr.log.warn(
+ '`pdu_filter` has moved to gr-pdu and will be removed from gr-blocks soon. Please update to use pdu.pdu_filter()')
pdu.pdu_filter.__init__(self, *args, **kwargs)
+
class pdu_remove(pdu.pdu_remove):
def __init__(self, *args, **kwargs):
- gr.log.warn('`pdu_remove` has moved to gr-pdu and will be removed from gr-blocks soon. Please update to use pdu.pdu_remove()')
+ gr.log.warn(
+ '`pdu_remove` has moved to gr-pdu and will be removed from gr-blocks soon. Please update to use pdu.pdu_remove()')
pdu.pdu_remove.__init__(self, *args, **kwargs)
+
class pdu_set(pdu.pdu_set):
def __init__(self, *args, **kwargs):
- gr.log.warn('`pdu_set` has moved to gr-pdu and will be removed from gr-blocks soon. Please update to use pdu.pdu_set()')
+ gr.log.warn(
+ '`pdu_set` has moved to gr-pdu and will be removed from gr-blocks soon. Please update to use pdu.pdu_set()')
pdu.pdu_set.__init__(self, *args, **kwargs)
+
class pdu_to_tagged_stream(pdu.pdu_to_tagged_stream):
def __init__(self, *args, **kwargs):
- gr.log.warn('`pdu_to_tagged_stream` has moved to gr-pdu and will be removed from gr-blocks soon. Please update to use pdu.pdu_to_tagged_stream()')
+ gr.log.warn(
+ '`pdu_to_tagged_stream` has moved to gr-pdu and will be removed from gr-blocks soon. Please update to use pdu.pdu_to_tagged_stream()')
pdu.pdu_to_tagged_stream.__init__(self, *args, **kwargs)
+
class random_pdu(pdu.random_pdu):
def __init__(self, *args, **kwargs):
- gr.log.warn('`random_pdu` has moved to gr-pdu and will be removed from gr-blocks soon. Please update to use pdu.random_pdu()')
+ gr.log.warn(
+ '`random_pdu` has moved to gr-pdu and will be removed from gr-blocks soon. Please update to use pdu.random_pdu()')
pdu.random_pdu.__init__(self, *args, **kwargs)
+
class tagged_stream_to_pdu(pdu.tagged_stream_to_pdu):
def __init__(self, *args, **kwargs):
- gr.log.warn('`tagged_stream_to_pdu` has moved to gr-pdu and will be removed from gr-blocks soon. Please update to use pdu.tagged_stream_to_pdu()')
+ gr.log.warn(
+ '`tagged_stream_to_pdu` has moved to gr-pdu and will be removed from gr-blocks soon. Please update to use pdu.tagged_stream_to_pdu()')
pdu.tagged_stream_to_pdu.__init__(self, *args, **kwargs)
@@ -51,10 +63,13 @@ class tagged_stream_to_pdu(pdu.tagged_stream_to_pdu):
class socket_pdu(network.socket_pdu):
def __init__(self, *args, **kwargs):
- gr.log.warn('`socket_pdu` has moved to gr-network and will be removed from gr-blocks soon. Please update to use network.socket_pdu()')
+ gr.log.warn(
+ '`socket_pdu` has moved to gr-network and will be removed from gr-blocks soon. Please update to use network.socket_pdu()')
network.socket_pdu.__init__(self, *args, **kwargs)
+
class tuntap_pdu(network.tuntap_pdu):
def __init__(self, *args, **kwargs):
- gr.log.warn('`tuntap_pdu` has moved to gr-network and will be removed from gr-blocks soon. Please update to use network.tuntap_pdu()')
+ gr.log.warn(
+ '`tuntap_pdu` has moved to gr-network and will be removed from gr-blocks soon. Please update to use network.tuntap_pdu()')
network.tuntap_pdu.__init__(self, *args, **kwargs)
diff --git a/gr-blocks/python/blocks/qa_add_mult_v.py b/gr-blocks/python/blocks/qa_add_mult_v.py
index 39f11bc4be..5568b20536 100644
--- a/gr-blocks/python/blocks/qa_add_mult_v.py
+++ b/gr-blocks/python/blocks/qa_add_mult_v.py
@@ -344,8 +344,8 @@ class test_add_mult_v(gr_unittest.TestCase):
25.0 + 26.0j,
27.0 + 28.0j,
29.0 + 30.0j]
- expected_result = [-1021.0 + 428.0j, -2647.0 + 1754.0j, - \
- 4945.0 + 3704.0j, -8011.0 + 6374.0j, -11941.0 + 9860.0j]
+ expected_result = [-1021.0 + 428.0j, -2647.0 + 1754.0j, -
+ 4945.0 + 3704.0j, -8011.0 + 6374.0j, -11941.0 + 9860.0j]
op = blocks.multiply_cc(5)
self.help_cc(5, (src1_data, src2_data, src3_data), expected_result, op)
diff --git a/gr-blocks/python/blocks/qa_block_gateway.py b/gr-blocks/python/blocks/qa_block_gateway.py
index 8088b59a85..7205fe3315 100644
--- a/gr-blocks/python/blocks/qa_block_gateway.py
+++ b/gr-blocks/python/blocks/qa_block_gateway.py
@@ -125,7 +125,7 @@ class tag_source(gr.sync_block):
if self.nitems_written(0) == 0:
# skip tagging in the first work block
return num_output_items
-
+
# make a new tag on the middle element every time work is called
count = self.nitems_written(0) + num_output_items // 2
key = pmt.string_to_symbol("example_key")
diff --git a/gr-blocks/python/blocks/qa_matrix_interleaver.py b/gr-blocks/python/blocks/qa_matrix_interleaver.py
index d254ef6b55..70a9c23559 100755
--- a/gr-blocks/python/blocks/qa_matrix_interleaver.py
+++ b/gr-blocks/python/blocks/qa_matrix_interleaver.py
@@ -12,6 +12,7 @@ from gnuradio import gr, gr_unittest
from gnuradio import blocks
from matrix_interleaver import matrix_interleaver
+
class qa_matrix_interleaver(gr_unittest.TestCase):
def setUp(self):
@@ -25,7 +26,7 @@ class qa_matrix_interleaver(gr_unittest.TestCase):
# set up fg
cols, rows = 4, 10
- vec = sum((cols * [x,] for x in range(rows)), [])
+ vec = sum((cols * [x, ] for x in range(rows)), [])
expected = cols * list(range(rows))
src = blocks.vector_source_f(vec, False)
@@ -44,11 +45,12 @@ class qa_matrix_interleaver(gr_unittest.TestCase):
# set up fg
cols, rows = 4, 10
- vec = sum((rows * [x,] for x in range(cols)), [])
+ vec = sum((rows * [x, ] for x in range(cols)), [])
expected = rows * list(range(cols))
src = blocks.vector_source_f(vec, False)
- itlv = matrix_interleaver(gr.sizeof_float, rows=rows, cols=cols, deint=True)
+ itlv = matrix_interleaver(
+ gr.sizeof_float, rows=rows, cols=cols, deint=True)
snk = blocks.vector_sink_f()
tb.connect(src, itlv, snk)
@@ -58,5 +60,6 @@ class qa_matrix_interleaver(gr_unittest.TestCase):
# check data
self.assertFloatTuplesAlmostEqual(expected, result)
+
if __name__ == '__main__':
gr_unittest.run(qa_matrix_interleaver)
diff --git a/gr-blocks/python/blocks/qa_message_debug.py b/gr-blocks/python/blocks/qa_message_debug.py
index 0f1dcff6fe..d9f108ab0e 100644
--- a/gr-blocks/python/blocks/qa_message_debug.py
+++ b/gr-blocks/python/blocks/qa_message_debug.py
@@ -18,6 +18,8 @@ import time
# this tests only the store port and the message retrival methods of the debug block
# print() and print_pdu() were omitted as they print to stdout
+
+
class qa_message_debug(gr_unittest.TestCase):
def setUp(self):
@@ -30,18 +32,22 @@ class qa_message_debug(gr_unittest.TestCase):
test_str = "test_msg"
new_msg = "new_msg"
message_period_ms = 100
- msg_strobe = blocks.message_strobe(pmt.intern(test_str), message_period_ms)
+ msg_strobe = blocks.message_strobe(
+ pmt.intern(test_str), message_period_ms)
msg_debug = blocks.message_debug()
self.tb.msg_connect(msg_strobe, "strobe", msg_debug, "store")
self.tb.start()
- self.assertAlmostEqual(msg_debug.num_messages(), 0, delta=2) # 1st call, expect 0
- time.sleep(1) # floor(1000/100) = 10
- self.assertAlmostEqual(msg_debug.num_messages(), 10, delta=3) # 2nd call == 1
- time.sleep(1) # floor(2000/100) = 15
- self.assertAlmostEqual(msg_debug.num_messages(), 20, delta=3) # 3th call == 3
+ self.assertAlmostEqual(msg_debug.num_messages(),
+ 0, delta=2) # 1st call, expect 0
+ time.sleep(1) # floor(1000/100) = 10
+ self.assertAlmostEqual(msg_debug.num_messages(),
+ 10, delta=3) # 2nd call == 1
+ time.sleep(1) # floor(2000/100) = 15
+ self.assertAlmostEqual(msg_debug.num_messages(),
+ 20, delta=3) # 3th call == 3
# change test message
msg_strobe.to_basic_block()._post(pmt.intern("set_msg"), pmt.intern(new_msg))
@@ -51,10 +57,14 @@ class qa_message_debug(gr_unittest.TestCase):
self.tb.wait()
# check data
# first received message matchs initial test message
- self.assertAlmostEqual(pmt.to_python(msg_debug.get_message(0)), test_str, "mismatch initial test string")
+ self.assertAlmostEqual(pmt.to_python(msg_debug.get_message(
+ 0)), test_str, "mismatch initial test string")
# last message matches changed test message
no_msgs = msg_debug.num_messages()
- self.assertAlmostEqual(pmt.to_python(msg_debug.get_message(no_msgs - 1)), new_msg, "failed to update string")
+ self.assertAlmostEqual(pmt.to_python(msg_debug.get_message(
+ no_msgs - 1)), new_msg, "failed to update string")
+
+
if __name__ == '__main__':
gr_unittest.run(qa_message_debug)
diff --git a/gr-blocks/python/blocks/qa_message_strobe.py b/gr-blocks/python/blocks/qa_message_strobe.py
index 2f11a1d5c8..8e5eb91738 100644
--- a/gr-blocks/python/blocks/qa_message_strobe.py
+++ b/gr-blocks/python/blocks/qa_message_strobe.py
@@ -17,6 +17,8 @@ import time
# similar tests contained in message_debug class
# this tests the periodic message output and the input port to change the message
+
+
class qa_message_strobe(gr_unittest.TestCase):
def setUp(self):
@@ -29,18 +31,22 @@ class qa_message_strobe(gr_unittest.TestCase):
test_str = "test_msg"
new_msg = "new_msg"
message_period_ms = 100
- msg_strobe = blocks.message_strobe(pmt.intern(test_str), message_period_ms)
+ msg_strobe = blocks.message_strobe(
+ pmt.intern(test_str), message_period_ms)
msg_debug = blocks.message_debug()
self.tb.msg_connect(msg_strobe, "strobe", msg_debug, "store")
self.tb.start()
- self.assertAlmostEqual(msg_debug.num_messages(), 0, delta=2) # 1st call, expect 0
- time.sleep(1) # floor(1000/100) = 10
- self.assertAlmostEqual(msg_debug.num_messages(), 10, delta=3) # 2nd call == 1
- time.sleep(1) # floor(2000/100) = 15
- self.assertAlmostEqual(msg_debug.num_messages(), 20, delta=3) # 3th call == 3
+ self.assertAlmostEqual(msg_debug.num_messages(),
+ 0, delta=2) # 1st call, expect 0
+ time.sleep(1) # floor(1000/100) = 10
+ self.assertAlmostEqual(msg_debug.num_messages(),
+ 10, delta=3) # 2nd call == 1
+ time.sleep(1) # floor(2000/100) = 15
+ self.assertAlmostEqual(msg_debug.num_messages(),
+ 20, delta=3) # 3th call == 3
# change test message
msg_strobe.to_basic_block()._post(pmt.intern("set_msg"), pmt.intern(new_msg))
@@ -51,11 +57,14 @@ class qa_message_strobe(gr_unittest.TestCase):
# check data
# first received message matchs initial test message
- self.assertAlmostEqual(pmt.to_python(msg_debug.get_message(0)), test_str, "mismatch initial test string")
+ self.assertAlmostEqual(pmt.to_python(msg_debug.get_message(
+ 0)), test_str, "mismatch initial test string")
# last message matches changed test message
no_msgs = msg_debug.num_messages()
- self.assertAlmostEqual(pmt.to_python(msg_debug.get_message(no_msgs - 1)), new_msg, "failed to update string")
+ self.assertAlmostEqual(pmt.to_python(msg_debug.get_message(
+ no_msgs - 1)), new_msg, "failed to update string")
+
if __name__ == '__main__':
gr_unittest.run(qa_message_strobe)
diff --git a/gr-blocks/python/blocks/qa_pack_k_bits.py b/gr-blocks/python/blocks/qa_pack_k_bits.py
index c4cfd6545e..5c5d077d44 100644
--- a/gr-blocks/python/blocks/qa_pack_k_bits.py
+++ b/gr-blocks/python/blocks/qa_pack_k_bits.py
@@ -14,6 +14,7 @@ import random
from gnuradio import gr, gr_unittest, blocks
import pmt
+
class test_pack(gr_unittest.TestCase):
def setUp(self):
@@ -56,27 +57,27 @@ class test_pack(gr_unittest.TestCase):
def test_004(self):
# Test tags propagation
- #Tags on the incoming bits
+ # Tags on the incoming bits
src_data = [1, 0, 1, 1, 0, 0, 0, 1]
#src_tag_offsets = [1, 2, 3, 5, 6]
src_tag_offsets = [1, 2, 3, 5, 6, 7]
- #Ground Truth
- expected_data= [2, 3, 0, 1]
+ # Ground Truth
+ expected_data = [2, 3, 0, 1]
expected_tag_offsets = [0, 1, 1, 2, 3, 3]
test_tags = list()
tag_indexs = range(len(src_tag_offsets))
for src_tag in tag_indexs:
test_tags.append(
- gr.tag_utils.python_to_tag(( src_tag_offsets[src_tag],
- pmt.intern('tag_byte'),
- pmt.from_long(src_tag),
- None
- ))
- )
-
- src = blocks.vector_source_b(src_data, False,1, test_tags )
+ gr.tag_utils.python_to_tag((src_tag_offsets[src_tag],
+ pmt.intern('tag_byte'),
+ pmt.from_long(src_tag),
+ None
+ ))
+ )
+
+ src = blocks.vector_source_b(src_data, False, 1, test_tags)
op = blocks.pack_k_bits_bb(2)
dst = blocks.vector_sink_b()
self.tb.connect(src, op, dst)
@@ -86,11 +87,11 @@ class test_pack(gr_unittest.TestCase):
self.assertEqual(expected_data, dst.data())
# Check the tag values
- self.assertEqual( list(tag_indexs), [ pmt.to_python(x.value) for x in dst.tags()])
+ self.assertEqual(list(tag_indexs), [
+ pmt.to_python(x.value) for x in dst.tags()])
# Check the tag offsets
- self.assertEqual( expected_tag_offsets, [ x.offset for x in dst.tags()])
-
+ self.assertEqual(expected_tag_offsets, [x.offset for x in dst.tags()])
if __name__ == '__main__':
diff --git a/gr-blocks/python/blocks/qa_peak_detector2.py b/gr-blocks/python/blocks/qa_peak_detector2.py
index d8055d61f7..fe5ab6e3ea 100644
--- a/gr-blocks/python/blocks/qa_peak_detector2.py
+++ b/gr-blocks/python/blocks/qa_peak_detector2.py
@@ -116,7 +116,7 @@ class test_peak_detector2(gr_unittest.TestCase):
self.assertEqual(expected_result[0:len(dst_data)], dst_data)
def test_peak5(self):
- #print "\n\nTEST 5"
+ # print "\n\nTEST 5"
tb = self.tb
data = [0, 0, 0, 10, 0, 0, 0, 0]
@@ -124,7 +124,8 @@ class test_peak_detector2(gr_unittest.TestCase):
expected_result_peak = [0, 0, 0, 1, 0, 0, 0, 0]
expected_result_average = [0]
for i in data:
- expected_result_average.append(expected_result_average[-1] * (1 - alpha) + i * alpha)
+ expected_result_average.append(
+ expected_result_average[-1] * (1 - alpha) + i * alpha)
src = blocks.vector_source_f(data, False)
regen = blocks.peak_detector2_fb(2.0, 2, alpha)
@@ -142,5 +143,6 @@ class test_peak_detector2(gr_unittest.TestCase):
self.assertEqual(expected_result_peak, dst_data)
self.assertFloatTuplesAlmostEqual(expected_result_average[1:], dst_avg)
+
if __name__ == '__main__':
gr_unittest.run(test_peak_detector2)
diff --git a/gr-blocks/python/blocks/qa_stream_demux.py b/gr-blocks/python/blocks/qa_stream_demux.py
index 629c35283c..a03a125d01 100755
--- a/gr-blocks/python/blocks/qa_stream_demux.py
+++ b/gr-blocks/python/blocks/qa_stream_demux.py
@@ -69,8 +69,8 @@ class qa_stream_demux(gr_unittest.TestCase):
return (dst0.data(), dst1.data())
def help_stream_tag_propagation(self, N, stream_sizes):
- src_data = (stream_sizes[0] * [1, ] + stream_sizes[1]
- * [2, ] + stream_sizes[2] * [3, ]) * N
+ src_data = (stream_sizes[0] * [1, ] + stream_sizes[1] *
+ [2, ] + stream_sizes[2] * [3, ]) * N
src = blocks.vector_source_f(src_data, False)
diff --git a/gr-blocks/python/blocks/qa_stream_mux.py b/gr-blocks/python/blocks/qa_stream_mux.py
index 4c935245db..57ebbe97af 100644
--- a/gr-blocks/python/blocks/qa_stream_mux.py
+++ b/gr-blocks/python/blocks/qa_stream_mux.py
@@ -203,19 +203,19 @@ class test_stream_mux (gr_unittest.TestCase):
N = 10 # Block length
stream_sizes = [1, 2, 3]
- expected_result = N * (stream_sizes[0] * [1, ]
- + stream_sizes[1] * [2, ]
- + stream_sizes[2] * [3, ])
+ expected_result = N * (stream_sizes[0] * [1, ] +
+ stream_sizes[1] * [2, ] +
+ stream_sizes[2] * [3, ])
# check the data
(result, tags) = self.help_stream_tag_propagation(N, stream_sizes)
self.assertFloatTuplesAlmostEqual(expected_result, result, places=6)
# check the tags
expected_tag_offsets_src1 = [sum(stream_sizes) * i for i in range(N)]
- expected_tag_offsets_src2 = [stream_sizes[0]
- + sum(stream_sizes) * i for i in range(N)]
- expected_tag_offsets_src3 = [stream_sizes[0] + stream_sizes[1]
- + sum(stream_sizes) * i for i in range(N)]
+ expected_tag_offsets_src2 = [stream_sizes[0] +
+ sum(stream_sizes) * i for i in range(N)]
+ expected_tag_offsets_src3 = [stream_sizes[0] + stream_sizes[1] +
+ sum(stream_sizes) * i for i in range(N)]
tags_src1 = [
tag for tag in tags if pmt.eq(
tag.key, pmt.intern('src1'))]
diff --git a/gr-blocks/python/blocks/qa_unpack_k_bits.py b/gr-blocks/python/blocks/qa_unpack_k_bits.py
index 82ea23c819..0ff70e0b59 100644
--- a/gr-blocks/python/blocks/qa_unpack_k_bits.py
+++ b/gr-blocks/python/blocks/qa_unpack_k_bits.py
@@ -46,11 +46,11 @@ class test_unpack(gr_unittest.TestCase):
def test_003(self):
- #Tags on the incoming bytes
- src_data= [2, 3, 0, 1]
+ # Tags on the incoming bytes
+ src_data = [2, 3, 0, 1]
src_tag_offsets = [0, 1, 1, 2, 3]
- #Ground Truth
+ # Ground Truth
expected_data = [1, 0, 1, 1, 0, 0, 0, 1]
expected_tag_offsets = [0, 2, 2, 4, 6]
@@ -58,14 +58,14 @@ class test_unpack(gr_unittest.TestCase):
tag_indexs = range(len(src_tag_offsets))
for src_tag in tag_indexs:
test_tags.append(
- gr.tag_utils.python_to_tag(( src_tag_offsets[src_tag],
- pmt.intern('tag_byte'),
- pmt.from_long(src_tag),
- None
- ))
- )
-
- src = blocks.vector_source_b(src_data, False,1, test_tags )
+ gr.tag_utils.python_to_tag((src_tag_offsets[src_tag],
+ pmt.intern('tag_byte'),
+ pmt.from_long(src_tag),
+ None
+ ))
+ )
+
+ src = blocks.vector_source_b(src_data, False, 1, test_tags)
op = blocks.unpack_k_bits_bb(2)
dst = blocks.vector_sink_b()
self.tb.connect(src, op, dst)
@@ -75,10 +75,12 @@ class test_unpack(gr_unittest.TestCase):
self.assertEqual(expected_data, dst.data())
# Check the tag values
- self.assertEqual( list(tag_indexs), [ pmt.to_python(x.value) for x in dst.tags()])
+ self.assertEqual(list(tag_indexs), [
+ pmt.to_python(x.value) for x in dst.tags()])
# Check the tag offsets
- self.assertEqual( expected_tag_offsets, [ x.offset for x in dst.tags()])
+ self.assertEqual(expected_tag_offsets, [x.offset for x in dst.tags()])
+
if __name__ == '__main__':
gr_unittest.run(test_unpack)
diff --git a/gr-blocks/python/blocks/stream_to_vector_decimator.py b/gr-blocks/python/blocks/stream_to_vector_decimator.py
index 2e1a383f32..e84bfc63b4 100644
--- a/gr-blocks/python/blocks/stream_to_vector_decimator.py
+++ b/gr-blocks/python/blocks/stream_to_vector_decimator.py
@@ -32,11 +32,12 @@ class stream_to_vector_decimator(gr.hier_block2):
self._sample_rate = sample_rate
gr.hier_block2.__init__(self, "stream_to_vector_decimator",
- gr.io_signature(1, 1, item_size), # Input signature
- gr.io_signature(1, 1, item_size*vec_len)) # Output signature
+ # Input signature
+ gr.io_signature(1, 1, item_size),
+ gr.io_signature(1, 1, item_size * vec_len)) # Output signature
s2v = blocks.stream_to_vector(item_size, vec_len)
- self.one_in_n = blocks.keep_one_in_n(item_size*vec_len, 1)
+ self.one_in_n = blocks.keep_one_in_n(item_size * vec_len, 1)
self._update_decimator()
self.connect(self, s2v, self.one_in_n, self)
@@ -71,7 +72,7 @@ class stream_to_vector_decimator(gr.hier_block2):
self.one_in_n.set_n(self._decim)
def _update_decimator(self):
- self.set_decimation(self._sample_rate/self._vec_len/self._vec_rate)
+ self.set_decimation(self._sample_rate / self._vec_len / self._vec_rate)
def decimation(self):
"""
@@ -89,4 +90,4 @@ class stream_to_vector_decimator(gr.hier_block2):
"""
Returns actual frame rate
"""
- return self._sample_rate/self._vec_len/self._decim
+ return self._sample_rate / self._vec_len / self._decim
diff --git a/gr-blocks/python/blocks/var_to_msg.py b/gr-blocks/python/blocks/var_to_msg.py
index 823609182c..0a317830cf 100644
--- a/gr-blocks/python/blocks/var_to_msg.py
+++ b/gr-blocks/python/blocks/var_to_msg.py
@@ -11,14 +11,17 @@
from gnuradio import gr
import pmt
+
class var_to_msg_pair(gr.sync_block):
"""
This block has a callback that will emit a message pair with the updated variable
value when called. This is useful for monitoring a GRC variable and emitting a message
when it is changed.
"""
+
def __init__(self, pairname):
- gr.sync_block.__init__(self, name="var_to_msg_pair", in_sig=None, out_sig=None)
+ gr.sync_block.__init__(
+ self, name="var_to_msg_pair", in_sig=None, out_sig=None)
self.pairname = pairname
@@ -37,11 +40,12 @@ class var_to_msg_pair(gr.sync_block):
else:
p = pmt.to_pmt(value)
- self.message_port_pub(pmt.intern("msgout"), pmt.cons(pmt.intern(self.pairname), p))
+ self.message_port_pub(pmt.intern("msgout"),
+ pmt.cons(pmt.intern(self.pairname), p))
except Exception as e:
- gr.log.error("Unable to convert " + repr(value) + " to PDU, no message will be emitted (reason: %s)" % repr(e))
-
+ gr.log.error("Unable to convert " + repr(value) +
+ " to PDU, no message will be emitted (reason: %s)" % repr(e))
def stop(self):
return True