JSON Config: Difference between revisions

From GNU Radio
Jump to navigation Jump to search
m (change yaml to json)
 
(9 intermediate revisions by 2 users not shown)
Line 1: Line 1:
[[Category:Block Docs]]
<!-- JSON_Config.mediawiki -->
This block...
This block presents a JSON config file which is read in as a dictionary.


== Parameters ==
The values can be used directly when instantiating blocks.  For example,
Sample Rate: json_config["samp_rate"]


; Config File
Optionally, a JSON schema can be specified to validate the configuration.
: asdasdasd


; Config Schema
For example, you could have a JSON file that contains:
: (Optional) asdasd


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


And a schema that contains
<nowiki>
{
  "type": "object",
  "properties": {
    "samp_rate": {"type": "number", "exclusiveMinimum": 0}
  }
}</nowiki>


== Example Flowgraph ==
If the id of this block is <code>json_config_0</code>, then you can access the samp rate
in other blocks as <code>json_config_0["samp_rate"]</code>.


# Make a new file called example.json with the contents:
== Parameters ==
<code>
{
"amplitude": 0.1
}
</code>
# Add the JSON Config block and point Config File to that file
# Make a signal source, and for Amplitude enter the value json_config_0[ 'amplitude']
# Connect it to a Time Sink through a Throttle and you'll see the amplitude show up as 0.1


[[File:Screenshot from 2022-02-26 15-05-23.png]]
; Config File  
: File name of the JSON config file


[[File:Screenshot from 2022-02-26 15-05-28.png]]
; Config Schema
: (Optional) File name of the JSON schema file


== Example Flowgraph ==


[[File:Screenshot from 2022-02-26 15-05-37.png]]
The <code>example.json</code> file contains:
<pre>
{
"amplitude": 0.1,
"frequency": 1000
}
</pre>


== Source Files ==
[[File:Json_config_example_prop.png]]


REPLACE WITH ACTUAL FILES ONCE ITS MERGED
[[File:Json_config_example_fg.png]]


; C++ files
== Example Output ==
: [https://github.com/gnuradio/gnuradio/blob/master/gr-fft/lib/fft_vcc_fftw.cc Complex input]
: [https://github.com/gnuradio/gnuradio/blob/master/gr-fft/lib/fft_vfc_fftw.cc Real input]
: [https://github.com/gnuradio/gnuradio/blob/master/gr-fft/lib/fft.cc Core algorithms]


; Header files
[[File:Json_config_example_out.png]]
: [https://github.com/gnuradio/gnuradio/blob/master/gr-fft/lib/fft_vcc_fftw.h Complex input]
: [https://github.com/gnuradio/gnuradio/blob/master/gr-fft/lib/fft_vfc_fftw.h Real input]


; Public header files
== Source Files ==
: [https://github.com/gnuradio/gnuradio/blob/master/gr-fft/include/gnuradio/fft/fft_vcc.h Complex input]
: [https://github.com/gnuradio/gnuradio/blob/master/gr-fft/include/gnuradio/fft/fft_vfc.h Real input ]


; Block definition
; Block definition
: [https://github.com/gnuradio/gnuradio/blob/master/gr-fft/grc/fft_fft_vxx.block.yml GRC yaml]
: [https://github.com/gnuradio/gnuradio/blob/main/grc/blocks/json_config.block.yml json_config.block.yml]
 
[[Category:Block Docs]]

Latest revision as of 10:57, 20 June 2023

This block presents a JSON config file which is read in as a dictionary.

The values can be used directly when instantiating blocks. For example, Sample Rate: json_config["samp_rate"]

Optionally, a JSON schema can be specified to validate the configuration.

For example, you could have a JSON 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 json_config_0, then you can access the samp rate in other blocks as json_config_0["samp_rate"].

Parameters

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

Example Flowgraph

The example.json file contains:

{
"amplitude": 0.1,
"frequency": 1000
}

Json config example prop.png

Json config example fg.png

Example Output

Json config example out.png

Source Files

Block definition
json_config.block.yml