YAML GRC

Starting with release 3.8, XML replaces YAML as the file format for GNU Radio Companion. This is triggered by switching from Cheetah to Mako as the templating engine, since Cheetah does not support Python 3. Specifically, this will impact .grc files, block descriptions and block tree files. This article won’t focus on the .grc files, because they aren’t meant for manual editing.

The most notable change is of course the absence of XML’s angle brackets in favour of YAML’s colon-separated keys and values, and the change in file names for blocks. The latter is important for GRC to recognise the file. Namely, the “.xml” ending has been replaced with “.block.yml” for block descriptions and the underscore in block tree files has been replaced with a dot. (For example, “qtgui_tree.xml” becomes “qtgui.tree.yml”)

Block Descriptions
The content of the block descriptions is still the same, although it has been shuffled around a bit. The parts are elaborated below, in the order they should appear in the files.

ID
The ID is unique for each block and is used to identify it.

Label
The label is simply the human-readable name of the block, and will be visible from within GRC. It will not appear in the generated code.

Flags (optional)
The flags indicate special attributes of the block. The only current example of this is the throttle flag, which is used in the Throttle and hardware blocks. For more information on throttling, see the Guided Tutorial:

Inputs and Outputs (optional)
This describes the input ports. domain can be either stream or message. Stream ports need a type, which usually is specified as a parameter. This is true for our example, the type is specified in type.t. The multiplicity tells us how many "copies" of this port we want. (Yes, this can be zero!) Finally, the optional flag tells us whether this port must be connected or not. (GRC won't generate the flowgraph if a non-optional port isn't connected)

Message ports don't have a specified type here, but they have IDs. This message port can also be hidden, using the "Show message ports" option in the parameters.

The output ports work similarly.

Asserts (optional)
Asserts (previously known as "checks" for the XML blocks) are expressions that need to be true, otherwise GRC won't let you generate the flowgraph.

Templates
The templates describe the code that is created when GRC generates the flowgraph. This part consists of the imports, the make/initialization statements and the callbacks. The values of these keys often happen to span over multiple lines, in which case you're likely to see the "|-" symbols. This is YAML syntax for a literal block scalar and the hyphen means that the line break at the end is omitted.

Your block probably utilizes parts of GNU Radio or other modules that need to be imported. These are specified as imports.

make holds the initialization code, and often depends on several of the parameters. Some of the more involved blocks may also use the "%" symbol, denoting the use of a YAML directive. This can occur both in imports and make. The snippet below may be helpful:

Please note that "${}" is not valid syntax in a directive.

Documentation
documentation simply contains information about the block. This information is displayed in the block's Documentation tab in GRC.