Search code examples
pythonnumpygnuradio

How to declare the output type of a GNU Radio block to be PMT?


Short: I want to output PMTs in my block, but GNU Radio won't let me.

Generally I write OOT blocks for different applications on GNU Radio. Here I am trying to write a block for outputting a file as a message type.

The thing is if the output of our block if of type numpy.float32, we declare the same using:

def __init__(self):
  gr.sync_block.__init__(self,name="<anything_you_want>",out_sig=[(numpy.float32)])

Now I have a similar problem where I want the output to be of type PMT of GNU Radio. What should out_sig be in that case?


Solution

  • PMT (polymorphic types) are variable sized, portable containers.

    They are used for message passing and tags, but not for streaming data.

    If you want to output a message, then defined an empty out_sig, i.e.

    ..., out_sig=[], in_sig=[])
    

    and use the message_port_register_out method to register an output port, and the message_port_pub method to send a message.

    Message passing is documented in the doxygen documentation.

    However, I'd recommend you take the Guided Tutorials, and read chapters 1-5, which explain the difference between item streams and messages. Since you can already write OOTs, this should be a quick read for you :)

    If you want a minimal block that already uses the aforementioned methods, try my minimal variable_to_msg block.

    Also, there's already a block that opens a file, and extracts messages: It's part of Tim O'Shea's gr-pyqt, and is called file_message_source.