discuss-gnuradio
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Fwd: Python block development in gnuradio


From: Ivan Zahartchuk
Subject: Fwd: Python block development in gnuradio
Date: Thu, 1 Apr 2021 09:34:26 +0300



---------- Forwarded message ---------
От: Ivan Zahartchuk <adray0001@gmail.com>
Date: пн, 29 мар. 2021 г. в 22:54
Subject: Python block development in gnuradio
To: discuss-gnuradio <discuss-gnuradio@gnu.org>


Hello, I'm trying to create a block that will group data and switch gpio every time in the graph. That is, if I want to read the data, write it to memory, switch the gpio again to read the data and then transfer it to the socket. Tell me if I'm doing it right?
"""
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
import xmlrpclib
import time
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,antenna_array=2,len_vector=512):
 # only default arguments here
        """arguments to this function show up as parameters in GRC"""
        self.xmlrpc_client_freq = xmlrpclib.Server('http://127.0.0.1:8080')
        gr.sync_block.__init__(
            self,
            name='Embedded Python Block',   # will show up in GRC
            in_sig=[(np.float32,len_vector)],
            out_sig=[(np.float32,len_vector*antenna_array)]
        )
        # if an attribute with the same name as a parameter is found,
        # a callback is registered (properties work, too).
self.len_vector = len_vector
self.antenna_array = antenna_array
self.i =0
        self.buffer = np.zeros(self.len_vector*self.antenna_array)
    def work(self, input_items, output_items):
        """example: multiply with constant"""
       
       
        if self.i < self.antenna_array:
print(len(input_items[0][0]))
self.buffer[self.i*self.len_vector:(self.i+1)*self.len_vector] = input_items[0][0]
  self.xmlrpc_client_freq.set_phase(0+self.i)
self.i+=1
               
        else :
                output_items[0][:] = self.buffer[:]
print(self.buffer.size)
self.i =0
        return len(output_items[0])
               
       
       

reply via email to

[Prev in Thread] Current Thread [Next in Thread]