YAML Config: Difference between revisions

From GNU Radio
Jump to navigation Jump to search
(initial creation)
 
mNo edit summary
 
(2 intermediate revisions by one other user not shown)
Line 5: Line 5:
     Sample Rate: yaml_config["samp_rate"]
     Sample Rate: yaml_config["samp_rate"]


Optionally, a json schema can be specified to validate the configuration. It may sound odd to use a json schema for a yaml file, but it works and jsonschema is a rich specification.
Optionally, a JSON schema can be specified to validate the configuration. It may sound odd to use a json schema for a yaml file, but it works and jsonschema is a rich specification.


For example, you could have a YAML file that contains:
For example, you could have a YAML file that contains:


  <nowiki>
  <nowiki>
{
   samp_rate: 1e6</nowiki>
   "samp_rate": 1e6,
}</nowiki>


And a schema that contains
And a schema that contains
Line 36: Line 34:
== Example Flowgraph ==
== Example Flowgraph ==


The <code>example.yaml</code> file contains:
The <code>fsk_params.yml</code> file contains:
<pre>
<pre>
{
samp_rate: 48000
"amplitude": 0.1,
baud: 1200
"frequency": 1000
mark: 1200
}
space: 2200
reverse: -1
thresh: 0
</pre>
</pre>


[[File:Json_config_example_prop.png]]
[[File:Yaml_test_fg.png|800px]]
 
[[File:Json_config_example_fg.png]]
 
== Example Output ==
 
[[File:Json_config_example_out.png]]


== Source Files ==
== Source Files ==

Latest revision as of 14:12, 20 June 2023

This block represents a yaml config file that is read in as a dictionary.

The values can be used directly when instantiating blocks. For example,

   Sample Rate: yaml_config["samp_rate"]

Optionally, a JSON schema can be specified to validate the configuration. It may sound odd to use a json schema for a yaml file, but it works and jsonschema is a rich specification.

For example, you could have a YAML file that contains:

  samp_rate: 1e6

And a schema that contains

{
  "type": "object",
  "properties": {
    "samp_rate": {"type": "number", "exclusiveMinimum": 0}
   }
}

If the id of this block is yaml_config_0, then you can access the samp rate in other blocks as yaml_config_0["samp_rate"].

Parameters

Config File
File name of the YAML config file
Config Schema
(Optional) File name of the JSON schema file

Example Flowgraph

The fsk_params.yml file contains:

samp_rate: 48000
baud: 1200
mark: 1200
space: 2200
reverse: -1
thresh: 0

Yaml test fg.png

Source Files

Block definition
yaml_config.block.yml