You've probably already found
https://wiki.gnuradio.org/index.php/Message_Pair_to_Var

For example, if samp_rate is the target variable, you end up with something
like

  self.p2v = blocks.msg_pair_to_var(self.set_samp_rate)

which will then call

    def set_samp_rate(self, samp_rate):
        self.samp_rate = samp_rate
        self.thr.set_sample_rate(self.samp_rate)

whenever a message is received.

On Wed, Nov 23, 2022 at 3:43 AM Nik Ansell <nikansel...@gmail.com> wrote:

> Hello All,
>
> I am writing a block that decodes metadata from an incoming stream and I
> would like the decoded metadata to be available to other downstream blocks.
> The best way to do this (I think) is to use the message passing
> functionality,
>
> My ultimate aim is to receive multiple metadata values via a single
> message from a c++ block and then to create a custom Python block which
> will parse the received message and set multiple variables.
>
> For reference I have been looking at the "message pair to var" block, but
> I am having trouble understanding exactly how the block updates the runtime
> variable.
>
> I think it has something to do with the callback line
> (self.callback(new_val)) here:
> https://github.com/gnuradio/gnuradio/blob/main/gr-blocks/python/blocks/msg_pair_to_var.py
> and the template make statement here:
> https://github.com/gnuradio/gnuradio/blob/main/gr-blocks/grc/blocks_msg_pair_to_var.block.yml.
> However, I am not 100% certain.
>
> Would someone be kind enough to explain to me exactly how the variable is
> set so I can determine how to write similar code that will update multiple
> variables. Thanks in advance!
>
> Kind Regards,
> Nik
>

Reply via email to