Configuration
Rob Dobson edited this page Mar 15, 2024
·
5 revisions
Raft applications are configured using JSON.
Raft supports multiple levels of configuration:
- default-level ... a constant (in Flash memory) JSON document which provides the default (fall-back) configuration for all of the SysMods in the case where there isn't a more specific configuration override.
- sys-type-level ... a JSON document which may completely define the configuration (i.e. entirely override the default-level configuration) or may only override a small part of it or none at all.
- local-mutable-level ... a JSON document which overrides a small part of the configuration and is (generally) localised to a specific SysMod. Configuration of a SysMod involves extraction of the specific part of the overall JSON document - i.e. just the part which relates to that SysMod. So, for instance, if a GPIO pin is to be specified it might be done using the following JSON:
{
"ExampleSysMod": {
"ExampleGpioPin": 4,
"OtherConfigValue": "Example"
}
}
And the C++ code for the SysMod (which must match the name "ExampleSysMod") which configures the GPIO pin:
int exampleGpioPin = _config.getLong("ExampleGpioPin", -1);
Here the value -1 is a default value which is assigned to exampleGpioPin when a value for the key "ExampleGpioPin" is not present. A test should be done to ensure that a valid GPIO pin value has been assigned before using the value.