Guest User

Untitled

a guest
Jan 27th, 2022
165
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.34 KB | None | 0 0
  1. """
  2. Embedded Python Block:
  3. 27.01.22
  4. """
  5.  
  6. import numpy
  7. from gnuradio import gr
  8.  
  9. class general_test(gr.basic_block):
  10.     # Ordinary init function, with two variables and one input/output
  11.     def __init__(self, buffer_len=512, out_items= 128):
  12.         gr.basic_block.__init__(self,
  13.             name="general_test",
  14.             in_sig=[numpy.complex64],
  15.             out_sig=[numpy.complex64])
  16.         self.buffer_len = buffer_len
  17.         self.out_items = out_items
  18.  
  19.  
  20.     def general_work(self, input_items, output_items):
  21.         # Firstly check, if input_items has a sufficient amount of items
  22.         # and if output is large enough to hold an amount of items equal to out_items
  23.         if len(input_items[0]) >= self.buffer_len and (len(output_items[0])) >= self.out_items:
  24.            
  25.             # Only output a fraction of input, say the first self.out_items, on output port[0]
  26.             output_items[0][:self.out_items] = input_items[0][:self.out_items]
  27.             # Then consume exactly self.buffer_len items  
  28.             self.consume_each(self.buffer_len)
  29.             # return the length, that we want to return of output_items[0]
  30.             return self.out_items
  31.            
  32.            
  33.         else:
  34.             # if we do not have enough input_items, tell the scheduler that we produced nothing
  35.             return 0
Advertisement
Add Comment
Please, Sign In to add comment