3.1.5.1.1. waf_tools.battery_config_validate_utils.extract_defines

waf_tools.battery_config_validate_utils.extract_defines(cfg: dict, file_name: str, error_cls: type[RuntimeError]) → dict[str, object]

Extract define values for a specific generated file.

Searches the files list in the configuration dictionary for an entry whose file_name matches the requested target file. Returns the contained defines as a flat dictionary mapping define names to their raw values.

The expected JSON structure is:

{
    "files": [
        {
            "file_name": "<file_name>",
            "defines": [
                {
                    "name": "<define_name>",
                    "value": <value>,
                    "value_type": "<value_type>"
                },
                ...
            ],
        },
        ...
    ]
}
Parameters:
  • cfg – Parsed JSON content of a foxBMS configuration file (e.g. battery_cell_cfg.json), expected to contain a files list.

  • file_name – The target file name to look up (e.g. battery_cell_cfg.h).

  • error_cls – The exception class to raise if the file entry is not found.

Returns:

A dictionary mapping define names to their raw values.

Raises:
  • RuntimeError – If no entry with the given file_name exists in the configuration’s files list. The concrete exception type is determined by error_cls.

  • KeyError – If a files entry has no file_name or defines key, or a define entry has no name or value key.