64 lines
1.9 KiB
Python
64 lines
1.9 KiB
Python
import re
|
|
import argparse
|
|
import subprocess
|
|
import pandas as pd
|
|
from pathlib import Path
|
|
|
|
from PV_Inverter.CodeGenerator import code_param_arm
|
|
from CBB.Param import code_cbb_params
|
|
|
|
def save_file(content: str, path_file: Path):
|
|
if not path_file.parent.exists():
|
|
path_file.parent.mkdir(parents=True)
|
|
|
|
return path_file.write_text(content)
|
|
|
|
def main(args: argparse.Namespace) -> bool:
|
|
""" 核心执行函数 """
|
|
global type_list, dev_list
|
|
file_excel = Path(args.path)
|
|
code_folder = Path(args.output) if args.output else (file_excel.parent / "result")
|
|
|
|
# 读取Excel文件
|
|
if file_excel.exists():
|
|
if file_excel.suffix in ['.dec', '.xlsx']:
|
|
dataframes = pd.read_excel(file_excel, sheet_name=None)
|
|
elif file_excel.suffix == '.xls':
|
|
dataframes = pd.read_excel(file_excel, sheet_name=None, engine='xlrd')
|
|
else:
|
|
raise ValueError("File format Unsupported.")
|
|
else:
|
|
raise ValueError("File does not exist.")
|
|
|
|
if args.type == 'COMM_ARM':
|
|
# 光伏逆变器-ARM数据结构体生成
|
|
content_code = code_param_arm(dataframes['ARM地址表'])
|
|
elif args.type == 'CBB_Param':
|
|
content_code = code_cbb_params(dataframes)
|
|
save_file(content_code, code_folder / 'param_arm_struct.h')
|
|
|
|
if __name__ == "__main__":
|
|
type_list = ['COMM_DSP', 'COMM_ARM', 'CBB_Param']
|
|
dev_list = ['PV_INV30', 'PV_INV40', 'PV_INV50']
|
|
parser = argparse.ArgumentParser()
|
|
parser.add_argument("path")
|
|
parser.add_argument(
|
|
"-t", "--type",
|
|
choices=type_list,
|
|
help=f"Specify the Code Generate type [{', '.join(type_list)}]",
|
|
required=True
|
|
)
|
|
parser.add_argument(
|
|
"-d", "--device",
|
|
choices=dev_list,
|
|
help=f"Specify the device type [{', '.join(dev_list)}]",
|
|
required=True
|
|
)
|
|
|
|
parser.add_argument("-i", "--ignore")
|
|
parser.add_argument("-o", "--output")
|
|
args = parser.parse_args()
|
|
|
|
main(args)
|
|
|