Files
templates/c/gas-logger/tools/generate_map.py

24 lines
1.1 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# Генерация C-представления карты сигналов из JSON и проверка его актуальности. Один источник
# карты связывает прошивку и клиента; ручная правка сгенерированной таблицы создаст
# расхождение при следующей генерации.
"""Regenerate/verify the firmware mirror of the packaged JSON map."""
from pathlib import Path
import argparse
import sys
root = Path(__file__).resolve().parents[3]
sys.path.insert(0, str(root / 'python'))
from set_devices.gas_logger import load_map, c_header
parser = argparse.ArgumentParser()
parser.add_argument('--check', action='store_true')
args = parser.parse_args()
target = root / 'c/gas-logger/ports/pm35/pm35_map.h'
expected = c_header(load_map())
if args.check:
if not target.exists() or target.read_text(encoding='utf-8') != expected:
raise SystemExit('pm35_map.h differs from JSON; run generate_map.py')
else:
target.parent.mkdir(parents=True, exist_ok=True)
target.write_text(expected, encoding='utf-8')