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
Add a library/codegen folder and add the script to it
The script:
takes the json file path as a cmd line argument (use the argparse lib to parse)
read and validate the json file (a json schema might be useful here)
Generate a .c and .h pair of files with code that will add each setting to the lib and set the default values. See here for what Eva has done on Bbraun. Let's have a discussion on how exactly we want this to look in the end. I wrote a short example at the end here.
Write a "wrapping" .c file that: has a SYS_INIT call that will:
initialize the user settings lib
call the generated "add" function
load the settings
call the generated "set defaults" function
Definition of Done
Code is written, tested and reviewed.
Additional context - JSON FORMAT
The JSON format is defined as follows
{
"version": 1, // denotes the version of the user-settings JSON format
"settings": {
"<name_of_setting_1>": {
"id": <number>, // required
"type": <string (valid type)>, // required
"size": <integer>, // required for string and bytes type, otherwise must not be present
"default": <default value in specified type>
},
"<name_of_setting_2>": {
// ...
}
// ...
}
}
This is a stub of the generated code. The full generated files require all the docstrings, ifdefs and everything that is expected in the c header and source files.
/* h file */enumuser_settings_gen_id {
// this contains a list of IDs with enum "names" being all-caps names of the settingsUSER_SETTINGS_ID_FIRST_NAME=1,
USER_SETTINGS_ID_LORAWAN_CLASS=2,
};
/* final name of function pending */voiduser_settings_gen_add(void);
/* final name of function pending */voiduser_settings_gen_set_defaults(void);
/* c file *//* add each setting */voiduser_settings_gen_add(void)
{
user_settings_add_sized(1, "first_name", USER_SETTINGS_TYPE_STR, 50);
user_settings_add(2, "lorawan_class", USER_SETTINGS_TYPE_U8);
// ...
}
/* check the default and set the default value for each setting *//* NOTE: it would be nice to check the default for each setting before setting it, and asserting if there is already an existing default with a different value - the device flash must be deleted in this case. */voiduser_settings_gen_set_defaults(void)
{
user_settings_set_default_with_id(1, "Luka", 5);
uint8_tlorawan_class=1;
user_settings_set_default_with_id(2, &lorawan_class, 1);
}
The text was updated successfully, but these errors were encountered:
Required steps / Implementation details
library/codegen
folder and add the script to itSYS_INIT
call that will:Definition of Done
Code is written, tested and reviewed.
Additional context - JSON FORMAT
The JSON format is defined as follows
For example:
Full example: https://github.com/IRNAS/bbraun-gravityplus-firmware/blob/dev/scripts/settings/settings.json
Additional context - Generated code
This is a stub of the generated code. The full generated files require all the docstrings, ifdefs and everything that is expected in the c header and source files.
The text was updated successfully, but these errors were encountered: