"""
Embedded Python Blocks:
Each time this file is saved, GRC will instantiate the first class it finds
to get ports and parameters of your block. The arguments to __init__ will
be the parameters. All of them are required to have default values!
"""
import numpy as np
from gnuradio import gr
class blk(gr.sync_block): # other base classes are basic_block, decim_block, interp_block
"""Embedded Python Block example - a simple multiply const"""
def __init__(self, ONpulsecount=1000,OFFpulsecount=10000,threshold = 0.5): # only default arguments here
"""arguments to this function show up as parameters in GRC"""
gr.sync_block.__init__(
self,
name='pulseshaper', # will show up in GRC
in_sig=[np.complex64,np.float32],
out_sig=[np.complex64,np.float32]
)
# if an attribute with the same name as a parameter is found,
# a callback is registered (properties work, too).
self.ONpulsecount = ONpulsecount
self.OFFpulsecount = OFFpulsecount
self.threshold = threshold
self.count=0
self.pulseblanker = 1.0
def work(self, input_items, output_items):
"""example: multiply with constant"""
self.count = self.count + 1
if self.count < self.ONpulsecount:
self.pulseblanker = 1.0
elif self.count < self.OFFpulsecount:
self.pulseblanker = 0.0
else:
self.count = 0
output_items[0][:] = input_items[0][:] * self.pulseblanker
output_items[1][:] = self.pulseblanker
return len(output_items[0])