3.1.15. waf_tools.config_codegen_task

Code Generator for foxBMS configuration C/H source and CSV files.

This waf tool implements the build tasks and task generators that transform JSON configuration files (e.g. battery_cell_cfg.json, battery_system_cfg.json, diag_array_cfg.json) into generated C source/header files and documentation CSV files. It uses template files located in conf/bms/templates/ and resolves define values, CSV lookup tables, and diagnostic array initializers at build time.

The tool provides two waf features:
  • codegen_config - Generates C/H files from JSON configuration. For each file entry in the JSON, a CreateCfgFile task is created that resolves typed values (bool, int, uint, float), CSV data, and diagnostic arrays, then renders them into the corresponding template. An optional validator callback is invoked to validate the JSON before code generation.

  • codegen_csv - Generates documentation CSV files summarizing the configuration defines for use in Sphinx documentation.

3.1.15.1. Usage

Declare task generators in a waf build script:

bld(
    features="codegen_config",
    json=bld.srcnode.find_node("conf/bms/battery_cell_cfg.json"),
    validator=battery_cell_config_validate.validate_battery_cell_configuration,
    target=f"{cp}battery_cell_cfg",
)

bld(
    features="codegen_csv",
    json=bld.srcnode.find_node(f"conf/bms/battery_cell_cfg.json"),
)

3.1.15.2. Dependencies

Functions

create_cfg_task(self)

Process the codegen_config feature on a task generator.

create_config(bld, json_node, idx)

Create the C/H code from a JSON configuration and template.

create_csv_task(self)

Process the codegen_csv feature on a task generator.

resolve_values(json_node, file_cfg)

Resolve all values in a file configuration.

Classes

CreateCfgFile(*k, **kw)

Waf task that generates a C/H file from a JSON configuration.

CreateCsvFile(*k, **kw)

Waf task that generates a documentation CSV file from a JSON configuration.

NumericLimits(min_value, max_value)

Min/max limits for numeric types.