discuss-gnuradio
[Top][All Lists]
Advanced

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

How to dynamically change hier block content and connections


From: krono86
Subject: How to dynamically change hier block content and connections
Date: Wed, 06 Mar 2024 19:30:09 +0100

Hello everybody,
I am trying to to dynamically change hier block content and connections.
Let me explain with a minimal example below.
Why the method delete_path does not want to work?
Thanks a lot for help.
Ivan
from gnuradio import gr, blocks, TestModule

class Example(gr.hier_block2):
    def __init__(self, G=[1,1,1], N=3, d=[0,0,0]):
        gr.hier_block2.__init__(self,
            "Example",
            gr.io_signature(1, 1, gr.sizeof_gr_complex*1),  # Input signature
            gr.io_signature(1, 1, gr.sizeof_gr_complex*1),  # Output signature
        )

        ##################################################
        # Parameters
        ##################################################
        self.N = N
        self.G = G
        self.d = d

        self.valid_params()

        ##################################################
        # Blocks
        ##################################################
        self.create_paths()

        ##################################################
        # Connections
        ##################################################
        self.connect_paths()
        
        ##################################################
        # Blocks
        ##################################################
        self.create_paths()

        ##################################################
        # Connections
        ##################################################
        self.connect_paths()

    def connect_paths(self):
        for n in range(self.N):
            self.connect((self.TestModule_Delay[n], 0), (self.blocks_multiply_xx[n], 0))
            self.connect((self.TestModule_TapGain[n], 0), (self.blocks_multiply_xx[n], 1))
            self.connect((self.blocks_multiply_xx[n], 0), (self.blocks_add_xx, n))
            self.connect((self, 0), (self.TestModule_Delay[n], 0))
        self.connect((self.blocks_add_xx, 0), (self, 0))

    def create_paths(self):
        self.blocks_multiply_xx = []
        self.TestModule_TapGain = []
        self.TestModule_Delay = []
        for n in range(self.N):
            self.blocks_multiply_xx.append(blocks.multiply_vcc(1))
            self.TestModule_TapGain.append(TestModule.TapGain(self.G[n]))
            self.TestModule_Delay.append(TestModule.Delay(self.d[n]))
        self.blocks_add_xx = blocks.add_vcc(1)

    def valid_params(self):
        if (len(self.G)!=self.N):
            raise ValueError("Not all lists have same lenght!")

    def delete_path(self, idx):
        self.lock()
        self.disconnect(self.blocks_multiply_xx.pop(idx))
        self.disconnect(self.TestModule_Delay.pop(idx))
        self.TestModule_TapGain.pop(idx)
        self.unlock()


reply via email to

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