67 lines
2.8 KiB
Python
67 lines
2.8 KiB
Python
# -*- coding: utf-8 -*-
|
|
import re
|
|
import os
|
|
import sys
|
|
# 设置控制台编码为 UTF-8
|
|
sys.stdout.reconfigure(encoding='utf-8')
|
|
|
|
# 获取当前脚本所在目录
|
|
current_dir = os.path.dirname(os.path.abspath(__file__))
|
|
|
|
# 构建entity.h文件的绝对路径
|
|
file_path = os.path.join(current_dir, '../User/entity.h')
|
|
|
|
# 打开并读取文件内容
|
|
try:
|
|
with open(file_path, 'r', encoding='utf-8') as file:
|
|
content = file.read()
|
|
# 读取调试模式
|
|
debug_enable_match = re.search(r'#define DEBUG_ENABLE (TRUE|FALSE)', content)
|
|
# 读取制造方案
|
|
scheme_match = re.search(r'#define MAN_SCHEME_SERIAL_NUM "([^"]+)"', content)
|
|
# 读取印刷线路板序列号
|
|
serial_num_match = re.search(r'#define MAN_INFO_SERIAL_NUM "([^"]+)"', content)
|
|
# 读取HART软件测试
|
|
hart_soft_test_enbale = re.search(r'#define HART_SOFTWARE_TEST_ENABLE (TRUE|FALSE)', content)
|
|
# 读取HART硬件测试
|
|
hart_hard_test_enable = re.search(r'#define HART_HARDWARE_TEST_ENABLE (TRUE|FALSE)', content)
|
|
# 使用正则表达式匹配并提取版本号
|
|
dw_ver_match = re.search(r'#define DW_VER (\d+)', content)
|
|
hw_ver_match = re.search(r'#define HW_VER (\d+)', content)
|
|
sw_ver_match = re.search(r'#define SW_VER (\d+)', content)
|
|
|
|
# 提取调试模式
|
|
debug_enable = debug_enable_match.group(1) if debug_enable_match else 'N/A'
|
|
# 提取制造方案
|
|
scheme = scheme_match.group(1) if scheme_match else 'N/A'
|
|
# 提取印刷线路板序列号
|
|
serial_num = serial_num_match.group(1) if serial_num_match else 'N/A'
|
|
# 提取HART软件测试
|
|
hart_soft_test = hart_soft_test_enbale.group(1) if hart_soft_test_enbale else 'N/A'
|
|
# 提取HART硬件测试
|
|
hart_hard_test = hart_hard_test_enable.group(1) if hart_hard_test_enable else 'N/A'
|
|
|
|
# 提取版本号
|
|
dw_ver = dw_ver_match.group(1) if dw_ver_match else 'N/A'
|
|
hw_ver = hw_ver_match.group(1) if hw_ver_match else 'N/A'
|
|
sw_ver = sw_ver_match.group(1) if sw_ver_match else 'N/A'
|
|
|
|
version_info_path = os.path.join(current_dir, 'version.txt')
|
|
# 将版本号写入文件
|
|
with open(version_info_path, 'w', encoding='utf-8') as version_file:
|
|
version_file.write(f'VERSION=v{dw_ver}.{hw_ver}.{sw_ver}\n')
|
|
version_file.write(f'DEBUG_ENABLE={debug_enable}\n')
|
|
version_file.write(f'HART_SOFT_TEST_ENABLE={hart_soft_test}\n')
|
|
version_file.write(f'HART_HARD_TEST_ENABLE={hart_hard_test}\n')
|
|
version_file.write(f'SCHEME={scheme}\n')
|
|
version_file.write(f'SERIAL_NUM={serial_num}\n')
|
|
|
|
print(f"version: {dw_ver}.{hw_ver}.{sw_ver}")
|
|
print(f"debug: {debug_enable}")
|
|
print(f"hart_soft_test: {hart_soft_test}")
|
|
print(f"hart_hard_test: {hart_hard_test}")
|
|
print(f"scheme: {scheme}")
|
|
print(f"serial_num: {serial_num}")
|
|
except FileNotFoundError:
|
|
print(f"file not find: {file_path}")
|