Editing Stream Tags

Jump to navigation Jump to search

Warning: You are not logged in. Your IP address will be publicly visible if you make any edits. If you log in or create an account, your edits will be attributed to your username, along with other benefits.

The edit can be undone. Please check the comparison below to verify that this is what you want to do, and then publish the changes below to finish undoing the edit.

Latest revision Your text
Line 179: Line 179:
just returns a list of tags. We would use it like this:
just returns a list of tags. We would use it like this:


<syntaxhighlight lang="python">
  def work(self, input_items, output_items):
  def work(self, input_items, output_items):
     ....
     ....
     tags = self.get_tags_in_window(which_input, rel_start, rel_end)
     tags = self.get_tags_in_window(which_input, rel_start, rel_end)
     ....
     ....
</syntaxhighlight>
If you want to grab all tags on the samples currently being processed by work(), on input port 0, here's a minimal example of doing that:
<syntaxhighlight lang="python">
import numpy as np
from gnuradio import gr
import pmt
class blk(gr.sync_block):
    def __init__(self):
        gr.sync_block.__init__(self,name='Read Tags', in_sig=[np.float32], out_sig=None)
    def work(self, input_items, output_items):
        tags = self.get_tags_in_window(0, 0, len(input_items[0]))
        for tag in tags:
            key = pmt.to_python(tag.key) # convert from PMT to python string
            value = pmt.to_python(tag.value) # Note that the type(value) can be several things, it depends what PMT type it was
            print 'key:', key
            print 'value:', value, type(value)
            print ''
        return len(input_items[0])
</syntaxhighlight>


== Tag Propagation ==
== Tag Propagation ==

Please note that all contributions to GNU Radio are considered to be released under the Creative Commons Attribution-ShareAlike (see GNU Radio:Copyrights for details). If you do not want your writing to be edited mercilessly and redistributed at will, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource. Do not submit copyrighted work without permission!

To edit this page, please answer the question that appears below (more info):

Cancel Editing help (opens in new window)