discuss-gnuradio
[Top][All Lists]
Advanced

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

Passing Message Input Index to


From: Merlo, Jason
Subject: Passing Message Input Index to
Date: Wed, 29 Jun 2022 16:53:07 +0000

Hi All,

I'm currently working on an asynchronous message multiplexing block using Python and I'm having difficulty determining from which input on my block a specific message came from in the message handler function. The issue is that the multiplicity of inputs is user configurable, so I need the number of inputs to be reconfigurable at initialization, thus I can't have a separate hard-coded callback for each input.

For reference, the "input" section .grc file looks like:

inputs:
  - label: in
    multiplicity: ${num_inputs}
    domain: message
  - label: sel
    domain: message

The idea is the sel message would set which input to pass through to the output and that the number of inputs is configurable in the block.

My challenge is determining from which input a message came. A separate function can be registered for each input, however I would need to dynamically generate functions based on the number of inputs a user has configured, which has been giving me trouble. Ideally, the function handler callback would provide auxiliary arguments to pass to the callback function as arguments that can be bound at instantiation (such as index), but I don't think this is possible.

Presently, I've looked into the functools package partialmethod to create separate instances of the process_msg(self, msg, idx) method with the ch_idx argument set, effectively creating process_msg_idx(self, msg) dynamically based on the number of inputs the user desires like:

def __init__(self, num_inputs=1, default_input=0):
    gr.basic_block.__init__(self, name="msg_mux", in_sig=None, out_sig=None)
    self.in_functions = [functools.partialmethod(self.process_msg, ch_idx=idx) for idx in range(num_inputs)]

    for ch_idx in range(num_inputs):
        self.message_port_register_in(pmt.intern('in{:d}'.format(ch_idx)))
        self.set_msg_handler(pmt.intern('in{:d}'), self.in_functions[ch_idx])
    ...
def process_msg(self, msg, ch_idx):
    print('got message from:', ch_idx)

But I have not been able to get this approach to work successfully; currently I’m still arguing with Python to get this to run, but it seems like there should be a more elegant approach.

Does anyone know of another way to pass the input index of a multiple input to the message handler function, either via GNU Radio methods, or via Python?

Thanks!

Jason

reply via email to

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