Created
August 26, 2020 16:08
-
-
Save tai/4a65be9c5139eb132f311b68808d36a6 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
Tag Rewrite | |
""" | |
import numpy as np | |
from gnuradio import gr | |
import pmt | |
log = gr.logger("TR") | |
log.set_level("DEBUG") | |
class blk(gr.sync_block): # other base classes are basic_block, decim_block, interp_block | |
"""TagRewrite - rewrite tag to any value""" | |
def __init__(self, tag_name="", tag_value=1): # only default arguments here | |
"""arguments to this function show up as parameters in GRC""" | |
gr.sync_block.__init__( | |
self, | |
name='Tag Rewrite', # will show up in GRC | |
in_sig=[np.byte], | |
out_sig=[np.byte] | |
) | |
# if an attribute with the same name as a parameter is found, | |
# a callback is registered (properties work, too). | |
self.tag_name = pmt.intern(tag_name) | |
self.tag_value = pmt.intern(str(tag_value)) | |
# pass through tags | |
self.set_tag_propagation_policy(gr.TPP_DONT) | |
log.debug("TR init done") | |
def work(self, input_items, output_items): | |
"""Update tag value""" | |
output_items[0][:] = input_items[0] | |
nr = len(input_items[0]) | |
tags = self.get_tags_in_window(0, 0, nr, self.tag_name) | |
for tag in tags: | |
self.add_item_tag(0, tag.offset, self.tag_name, self.tag_value) | |
return len(output_items[0]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment