You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
- Rebuild only if schema *after* pre-processing has changed.
- Add support for conditional selection using dictionary values
- Revert output directory to `out/ConfigDB`
Copy file name to clipboardExpand all lines: README.rst
+52-20Lines changed: 52 additions & 20 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -297,34 +297,32 @@ This example generates a `uint8_t` property value. A different type may be speci
297
297
Calculated Values
298
298
-----------------
299
299
300
-
With ConfigDB, if an attribute name is prefixed with ``@`` then it will be evaluated as a simple expression. See https://github.com/SmingHub/Sming/blob/develop/Tools/Python/evaluator/README.md for details.
301
-
302
-
Such expressions are parsed during loading of a schema. During the build process, copies are written to ``out/{SOC}/{build}/ConfigDB/schema`` to assist with debugging and development.
303
-
304
-
.. note::
305
-
306
-
Variable names correspond to environment variables.
307
-
The build system is not aware of variable dependencies, so it may be necessary to perform a manual `clean` or `configdb-rebuild` to pick up any changed values.
300
+
Within a ConfigDB schema, if an attribute name is prefixed with @ then the attribute value will be evaluated and the result used as the actual value.
301
+
The expression must be given as a string, with variable names corresponding to environment variables.
302
+
See :doc:`/_inc/Tools/Python/evaluator/README` for details.
308
303
304
+
The ``.cfgdb`` schema are pre-processed on every build and the source files regenerated automatically if there is a change.
305
+
The pre-processed schema can be found in ``out/ConfigDB/schema/``, together with a *summary.txt* file.
309
306
310
307
An example is included in the test application:
311
308
312
309
.. code-block:: json
313
310
314
-
"properties": {
311
+
"simple-string": {
312
+
"type": "string",
315
313
"@default": "SIMPLE_STRING"
316
314
}
317
315
318
-
During loading, the attribute value is evaluated in python and the result stored in `default`. The value `SIMPLE_STRING` must be available in the environment - an error occurs if not found.
316
+
The pre-processed schema will contain a ``default`` attribute with the contents of the environment variable ``SIMPLE_STRING``.
317
+
An error will be given if named variable is not present in the environment.
319
318
320
319
To test this, build and run as follows:
321
320
322
321
.. code-block:: bash
323
322
324
-
make clean
325
323
SIMPLE_STRING="donkey2" make -j run
326
324
327
-
The test application now fails as the value has changed - "donkey" is expected.
325
+
The test application now fails as the schema default value has changed - "donkey" is expected.
328
326
329
327
.. note::
330
328
@@ -338,21 +336,28 @@ JSON does not support extended number formats, such as `0x12`, so this mechanism
338
336
339
337
.. code-block:: json
340
338
341
-
"properties": {
339
+
"simple-int": {
340
+
"type": "integer",
342
341
"@default": "8 + 27",
343
342
"minimum": 0,
344
343
"@maximum": "0xffff"
345
344
}
346
345
347
346
348
-
Array defaults
349
-
~~~~~~~~~~~~~~
347
+
Array values
348
+
~~~~~~~~~~~~
349
+
350
+
If a calculated attribute value is an array, then each element is evaluated separately.
351
+
Arrays may contain a mixture of types, but only string values will be evalulated: others will be passed through unchanged.
350
352
351
-
Array defaults may contain a mixture of types:
352
353
353
354
.. code-block:: json
354
355
355
-
"properties": {
356
+
"simple-array": {
357
+
"type": "array",
358
+
"items": {
359
+
"type": "integer"
360
+
},
356
361
"@default": [
357
362
"0x12",
358
363
5,
@@ -361,7 +366,34 @@ Array defaults may contain a mixture of types:
361
366
]
362
367
}
363
368
364
-
Only string values will be evalulated, the others will be passed through unchanged.
369
+
370
+
Dictionary values
371
+
~~~~~~~~~~~~~~~~~
372
+
373
+
To conditionally select from one of a number of options, provide a dictionary as the calculated attribute value.
374
+
The first key which evaluates as *True* is matched, and the corresponding value becomes the value for the property.
375
+
If none of the entries matches, an error is raised.
376
+
377
+
In this example, the default contents of the *pin-list* array is determined by the targetted SOC.
378
+
The final *"True": []* ensures a value is provided if nothing else is matched.
379
+
380
+
.. code-block:: json
381
+
382
+
"pin-list": {
383
+
"type": "array",
384
+
"items": {
385
+
"type": "integer",
386
+
"minimum": 0,
387
+
"maximum": 255
388
+
},
389
+
"@default": {
390
+
"SMING_SOC == 'esp8266'": [ 1, 2, 3, 4 ],
391
+
"SMING_SOC == 'esp32c3'": [ 5, 6, 7, 8 ],
392
+
"SMING_SOC == 'esp32s2'": [ 9, 10, 11, 12 ],
393
+
"SMING_SOC in ['rp2040', 'rp2350']": [ 13, 14, 15, 16 ],
394
+
"True": []
395
+
}
396
+
}
365
397
366
398
367
399
Store loading / saving
@@ -375,11 +407,11 @@ This can be overridden to customise loading/saving behaviour.
375
407
The :cpp:func:`ConfigDB::Database::getFormat` method is called to get the storage format for a given Store.
376
408
A :cpp:class:`ConfigDB::Format` implementation provides various methods for serializing and de-serializing database and object content.
377
409
378
-
Currently only **json** is implemented - see :cpp:class:`ConfigDB::Json::format`.
410
+
Currently only **json** is implemented - see :cpp:member:`ConfigDB::Json::format`.
379
411
Each store is contained in a separate file.
380
412
The name of the store forms the JSONPath prefix for any contained objects and values.
381
413
382
-
The :sample:`BasicConfig` sample demonstrates using the stream classes to read and write data from a web client.
414
+
The :sample:`Basic_Config` sample demonstrates using the stream classes to read and write data from a web client.
0 commit comments