Sunday, May 9, 2021

Stream Tag in Embedded Python Blocks

Dear all,

I was following the GRC Wiki tutorial on Stream Tags. In the example
flowgraph, stream tags were added to the example QPSK de-modulator
using Python code. I was unable to replicate the behavior in an embedded
python block. How do I tell what port number to add the stream tag to?
How do I use `add_item_tag` with an embedded python block?


```
self.add_item_tag(0, # Port number
self.nitems_written(0) + i, # Offset
pmt.intern("amplitude_recovered"), # Key
pmt.PMT_T # Value
)
```

My entire `work` function code is shown below. It just creates a tag
whenever the input signal magnitude falls below 0.01, and when it rises
again above 0.01.

```
def work(self, input_items, output_items):
for i in range(0, len(input_items[0])):
if abs(input_items[0][i]) < 0.01 and not self.d_low_ampl_state:
self.add_item_tag(0,self.nitems_written(0)+i,
pmt.intern("amplitude_warning"),

pmt.from_double(
numpy.double(abs(input_items[0][i]))
)
)
self.d_low_ampl_state = True
elif abs(input_items[0][i]) >= 0.01 and self.d_low_ampl_state:
self.add_item_tag(0,self.nitems_written(0)+i,
pmt.intern("amplitude_recovered"),
pmt.from_double(numpy.double(abs(input_items[0][i]))))
self.d_low_ampl_state = False
output_items[0][:] = abs(input_items[0])
return len(output_items[0])

```

Indentation is edited to fit the 72 char limit. The error I got was a
runtime error (ie return -6). There was no error if I commented out the
`add_item_tag` function calls.

Thank you.
Cheers,
Sol

No comments:

Post a Comment