reworked build-Process

This commit is contained in:
2025-08-24 22:55:34 +02:00
parent c6d65f50bf
commit 3a6c102b45
4 changed files with 128 additions and 32 deletions

View File

@@ -1,8 +0,0 @@
import subprocess
revision = (
subprocess.check_output(["git", "rev-parse", "--short=10", "HEAD"])
.strip()
.decode("utf-8")
)
print("-DGIT_REV='\"%s\"'" % revision)

View File

@@ -1,9 +1,87 @@
Import("env") # pylint: disable=undefined-variable
env.Execute("\"$PYTHONEXE\" -m pip install jinja2")
env.Replace(PROGNAME="firmware_pcb_1.%s.fw" % env.GetProjectOption("custom_pcb_revision"))
# run_pre.py — PlatformIO pre-build script
import os
import subprocess
from pathlib import Path
Import("env") # provided by PlatformIO
# ---- helper ----
def parse_ver(s: str):
"""
Accepts '1.04', '1.4', '1,04' etc. -> returns (major:int, minor:int, norm_str:'1.04')
"""
s = (s or "").strip().replace(",", ".")
if not s:
return 0, 0, "0.00"
parts = s.split(".")
try:
major = int(parts[0])
minor = int(parts[1]) if len(parts) > 1 else 0
except ValueError:
major, minor = 0, 0
norm_str = f"{major}.{minor:02d}"
return major, minor, norm_str
def read_text_file(p: Path):
try:
return p.read_text(encoding="utf-8").strip()
except Exception:
return ""
def git_short_hash():
try:
out = subprocess.check_output(
["git", "rev-parse", "--short", "HEAD"],
stderr=subprocess.DEVNULL
).decode("utf-8").strip()
return out or "nogit"
except Exception:
return "nogit"
# ---- ensure jinja present, like before ----
env.Execute("\"$PYTHONEXE\" -m pip install jinja2")
# ---- keep your other pre-steps ----
import struct2json
import dtcs
struct2json.struct2json()
dtcs.build_dtcs()
dtcs.build_dtcs()
# ---- collect inputs ----
proj_dir = Path(env["PROJECT_DIR"])
# user options from platformio.ini
pcb_rev = env.GetProjectOption("custom_pcb_revision", default="")
fw_ver_opt = env.GetProjectOption("custom_firmware_version", default="") # new
# required flash version from data/version
req_file = proj_dir / "data" / "version"
req_ver_raw = read_text_file(req_file)
fw_major, fw_minor, fw_norm = parse_ver(fw_ver_opt)
req_major, req_minor, req_norm = parse_ver(req_ver_raw)
githash = git_short_hash()
# ---- export as preprocessor defines ----
# numeric defines
env.Append(CPPDEFINES=[
("FW_VERSION_MAJOR", fw_major),
("FW_VERSION_MINOR", fw_minor),
("REQ_FLASH_MAJOR", req_major),
("REQ_FLASH_MINOR", req_minor),
])
# useful string defines (if du sie im Code/Logging brauchst)
env.Append(CPPDEFINES=[
("FW_VERSION_STR", f"\"{fw_norm}\""),
("REQ_FLASH_STR", f"\"{req_norm}\""),
("GIT_REV", f"\"{githash}\""),
])
# ---- build artifact name ----
# bisher: firmware_pcb_1.<pcb>.fw
# jetzt: firmware_pcb_<pcb>_v<fw>_<git>.fw (gut identifizierbar)
pcb_part = f"{pcb_rev}".strip() or "X"
fname = f"firmware_pcb_{pcb_part}_v{fw_norm}_{githash}.fw"
env.Replace(PROGNAME=fname)

View File

@@ -18,38 +18,63 @@
#include "config.h"
#include "common.h"
#ifndef FW_VERSION_MAJOR
#define FW_VERSION_MAJOR 0
#endif
#ifndef FW_VERSION_MINOR
#define FW_VERSION_MINOR 0
#endif
#ifndef REQ_FLASH_MAJOR
#define REQ_FLASH_MAJOR 0
#endif
#ifndef REQ_FLASH_MINOR
#define REQ_FLASH_MINOR 0
#endif
#ifndef GIT_REV
#define GIT_REV "nogit"
#endif
#ifndef FW_VERSION_STR
#define FW_VERSION_STR "0.00"
#endif
#ifndef REQ_FLASH_STR
#define REQ_FLASH_STR "0.00"
#endif
typedef struct Globals_s
{
tSystem_Status systemStatus = sysStat_Startup; /**< Current system status */
tSystem_Status resumeStatus = sysStat_Startup; /**< Status to resume after rain mode */
uint16_t purgePulses = 0; /**< Number of purge pulses */
EERequest_t requestEEAction = EE_IDLE; /**< EEPROM-related request */
char DeviceName[33]; /**< Device name */
char FlashVersion[10]; /**< Flash version */
uint16_t eePersistenceAddress; /**< EEPROM persistence address */
uint8_t TankPercentage; /**< Tank percentage */
bool hasDTC; /**< Flag indicating the presence of Diagnostic Trouble Codes (DTC) */
bool measurementActive; /**< Flag indicating active measurement */
uint32_t measuredPulses; /**< Number of measured pulses */
tSystem_Status systemStatus = sysStat_Startup; /**< Current system status */
tSystem_Status resumeStatus = sysStat_Startup; /**< Status to resume after rain mode */
uint16_t purgePulses = 0; /**< Number of purge pulses */
EERequest_t requestEEAction = EE_IDLE; /**< EEPROM-related request */
char DeviceName[33]; /**< Device name */
char FlashVersion[10]; /**< Flash version */
uint16_t eePersistenceAddress; /**< EEPROM persistence address */
uint8_t TankPercentage; /**< Tank percentage */
bool hasDTC; /**< Flag indicating the presence of Diagnostic Trouble Codes (DTC) */
bool measurementActive; /**< Flag indicating active measurement */
uint32_t measuredPulses; /**< Number of measured pulses */
bool toggle_wifi;
uint16_t isr_debug;
} Globals_t;
extern Globals_t globals; /**< Global variable struct */
extern Globals_t globals; /**< Global variable struct */
typedef struct Constants_s
{
uint8_t FW_Version_major; /**< Firmware version major number */
uint8_t FW_Version_minor; /**< Firmware version minor number */
uint8_t FW_Version_major; /**< Firmware version major number */
uint8_t FW_Version_minor; /**< Firmware version minor number */
uint8_t Required_Flash_Version_major; /**< Required flash version major number */
uint8_t Required_Flash_Version_minor; /**< Required flash version minor number */
char GitHash[11]; /**< Git hash string */
char GitHash[11]; /**< Git hash string */
} Constants_t;
const Constants_t constants PROGMEM = {
1,4, // Firmware_Version
1,4, // Required Flash Version
GIT_REV // Git-Hash-String
FW_VERSION_MAJOR, FW_VERSION_MINOR, // Firmware_Version
REQ_FLASH_MAJOR, REQ_FLASH_MINOR, // Required Flash Version
QUOTE(GIT_REV) // Git-Hash-String
};
/**

View File

@@ -19,8 +19,9 @@ board = d1_mini
framework = arduino
upload_speed = 921600
custom_firmware_version = 1.04
build_flags =
!python codegen/git_rev_macro.py
-DWIFI_SSID_CLIENT=${wifi_cred.wifi_ssid_client}
-DWIFI_PASSWORD_CLIENT=${wifi_cred.wifi_password_client}
-DADMIN_PASSWORD=${wifi_cred.admin_password}