3.1.5. waf_tools.battery_config_validate_utils

Shared helper functions for battery configuration validators.

This module provides common utilities used by the battery cell and battery system configuration validators. It handles the extraction of #define values from the foxBMS JSON configuration format and maps them to typed Python dataclass instances.

Key functionality:
  • Define extraction - Locates define entries for a specific generated file (e.g. battery_cell_cfg.h) within the JSON configuration structure.

  • Dataclass mapping - Converts flat define dictionaries into typed dataclass instances by matching field names to define name patterns.

  • Type checking - Validates the raw JSON values against the types declared in the target dataclass fields, raising descriptive errors on type mismatch.

3.1.5.1. Usage

These utilities are not called directly from build scripts but are imported by the specific validators:

from battery_config_validate_utils import extract_defines, parse_defines_to_dataclass

defines = extract_defines(cfg, "battery_cell_cfg.h", InvalidBatteryCellConfigurationError)
voltage = parse_defines_to_dataclass(
    defines, CellVoltageLimits, "BC_VOLTAGE", InvalidBatteryCellConfigurationError
)

Functions

extract_defines(cfg, file_name, error_cls)

Extract define values for a specific generated file.

parse_defines_to_dataclass(defines, cls, ...)

Map a flat define dictionary to a typed dataclass instance.