积累更新;
This commit is contained in:
@@ -139,6 +139,7 @@ class LaminaAdapter:
|
||||
'data_define': modbus_map,
|
||||
},
|
||||
}
|
||||
self.output = {}
|
||||
|
||||
def __transfer_data(self, frame):
|
||||
""" 报文数据传输 """
|
||||
@@ -168,6 +169,13 @@ class LaminaAdapter:
|
||||
cnt += 1
|
||||
continue
|
||||
print(output_text)
|
||||
for line in output_text.split('\n'):
|
||||
line = line.strip()
|
||||
line_info = line.split('\t')
|
||||
if line_info[0] == '0x0100':
|
||||
self.output['version'] = line_info[2].rstrip('\x00')
|
||||
elif line_info[0] == '0x0082':
|
||||
self.output['address'] = line_info[2].rstrip('\x00')
|
||||
break
|
||||
|
||||
if self.flag_print:
|
||||
@@ -450,18 +458,38 @@ if __name__=='__main__':
|
||||
dev_lamina.frame_read(0x0170, 0x30)
|
||||
|
||||
if not hasattr(__builtins__,"__IPYTHON__"):
|
||||
path_bin = Path(r"D:\WorkSpace\UserTool\SelfTool\FrameParser\test\p460\result\lamina_adapter_t1.dat")
|
||||
path_bin = Path(r"D:\WorkSpace\UserTool\SelfTool\FrameParser\test\p460_o1\result\lamina_optimizer_t1.dat")
|
||||
# path_bin = Path(r"D:\WorkingProject\LightStackAdapter\software\lamina_adapter\tools\upgrade\SLCP001_240520_0000_T1.11.bin")
|
||||
# 生产镜像版本
|
||||
# path_bin = Path(r"D:\WorkingProject\LightStackAdapter\software\lamina_adapter\tools\upgrade\SLCP001_240525_1800_V1.12.bin")
|
||||
# 江苏发货产品灌装版本
|
||||
# path_bin = Path(r"D:\WorkingProject\LightStackAdapter\software\lamina_adapter\tools\upgrade\SLCP001_240603_2100_V1.18.bin")
|
||||
|
||||
version = "DLSY001_240911_1600_V1.01"
|
||||
addr = [0x24, 0x09, 0x12, 0x00, 0x00, 0x00]
|
||||
|
||||
while True:
|
||||
""" 自动检测升级流程 """
|
||||
ret = False
|
||||
while not ret or ('version' not in dev_lamina.output.keys()) or (version == dev_lamina.output['version']):
|
||||
dev_lamina.frame_read(0x82, 3)
|
||||
ret = dev_lamina.frame_read(0x0100, 0x20)
|
||||
time.sleep(1)
|
||||
|
||||
dev_lamina.frame_update(path_bin)
|
||||
|
||||
time.sleep(6)
|
||||
|
||||
dev_lamina.frame_read(0x0100, 0x20)
|
||||
ret = dev_lamina.frame_read(0x0100, 0x20)
|
||||
|
||||
if ret and (version == dev_lamina.output['version']):
|
||||
dev_lamina.frame_write_one(0x52, 0x01)
|
||||
|
||||
print(f"address: {' '.join(map(lambda x: ('000' + hex(x)[2:])[-2:], addr))}")
|
||||
dev_lamina.frame_write_str(0x82, addr)
|
||||
dev_lamina.frame_read(0x82, 3)
|
||||
addr[5] += 1
|
||||
if addr[5] & 0x0F >= 10:
|
||||
addr[5] += 0x10 - 10
|
||||
|
||||
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import time
|
||||
from pathlib import Path
|
||||
from serial import Serial
|
||||
from datetime import datetime
|
||||
from tools.ByteConv import trans_list_to_str
|
||||
from tools.IntelHex import file_Bin_to_IntelHex
|
||||
from func_frame import make_frame_modbus, check_frame_modbus
|
||||
@@ -210,48 +211,80 @@ class LaminaController:
|
||||
self.block['data']['step'] = 'start'
|
||||
frame_master = make_frame_modbus(self.block['data'])
|
||||
|
||||
ret = True
|
||||
ret, cnt, cnt_sub = True, 0, 0
|
||||
frame_data_cfg = []
|
||||
while ret:
|
||||
self.__com.read_all()
|
||||
self.__com.write(frame_master)
|
||||
time.sleep(0.1)
|
||||
frame_slave = self.__com.read_all()
|
||||
frame_slave = None
|
||||
while not frame_slave:
|
||||
time.sleep(0.1)
|
||||
frame_slave = self.__com.read_all()
|
||||
cnt_sub += 1
|
||||
if cnt_sub >= self.retry_sub:
|
||||
break
|
||||
|
||||
ret, block_cfg = check_frame_modbus(frame_slave, self.block['data'])
|
||||
try:
|
||||
ret, *block_cfg = check_frame_modbus(frame_slave, self.block['data'])
|
||||
print(f"{trans_list_to_str(frame_slave[:9])}")
|
||||
except Exception as ex:
|
||||
print(ex)
|
||||
cnt += 1
|
||||
ret = False
|
||||
|
||||
if ret:
|
||||
frame_data_cfg.append(block_cfg)
|
||||
if block_cfg['seq'] == 0:
|
||||
cnt = 0
|
||||
frame_data_cfg.append(block_cfg[0])
|
||||
if block_cfg[0]['seq'] == 0:
|
||||
self.block['data']['step'] = 'next'
|
||||
frame_master = make_frame_modbus(self.block['data'])
|
||||
elif (block_cfg['seq'] + 1) >= block_cfg['total']:
|
||||
elif (block_cfg[0]['seq']) >= block_cfg[0]['total']:
|
||||
ret = False
|
||||
elif cnt < self.retry:
|
||||
ret = True
|
||||
|
||||
# 读取data
|
||||
self.block['data']['type'] = 'record_data'
|
||||
self.block['data']['step'] = 'start'
|
||||
frame_master = make_frame_modbus(self.block['data'])
|
||||
|
||||
ret = True
|
||||
ret, cnt, cnt_sub = True, 0, 0
|
||||
frame_data_record = []
|
||||
while ret:
|
||||
self.__com.read_all()
|
||||
self.__com.write(frame_master)
|
||||
time.sleep(0.3)
|
||||
frame_slave = self.__com.read_all()
|
||||
frame_slave = None
|
||||
while not frame_slave:
|
||||
time.sleep(0.1)
|
||||
frame_slave = self.__com.read_all()
|
||||
cnt_sub += 1
|
||||
if cnt_sub >= self.retry_sub:
|
||||
break
|
||||
|
||||
ret, block_record = check_frame_modbus(frame_slave, self.block['data'])
|
||||
try:
|
||||
ret, *block_record = check_frame_modbus(frame_slave, self.block['data'])
|
||||
print(f"{trans_list_to_str(frame_slave[:9])}")
|
||||
except Exception as ex:
|
||||
print(ex)
|
||||
cnt += 1
|
||||
ret = False
|
||||
|
||||
if ret:
|
||||
frame_data_record.append(block_record)
|
||||
if block_record['seq'] == 0:
|
||||
cnt = 0
|
||||
frame_data_record.append(block_record[0])
|
||||
if block_record[0]['seq'] == 0:
|
||||
self.block['data']['step'] = 'next'
|
||||
frame_master = make_frame_modbus(self.block['data'])
|
||||
elif (block_record['seq'] + 1) >= block_record['total']:
|
||||
elif (block_record[0]['seq']) >= block_record[0]['total']:
|
||||
ret = False
|
||||
elif cnt < self.retry:
|
||||
ret = True
|
||||
|
||||
# 处理数据
|
||||
if len(frame_data_record) == 0:
|
||||
raise Exception("未取得录波数据.")
|
||||
|
||||
# 处理配置信息
|
||||
data_cfg_bare = b"".join([x['data'] for x in frame_data_cfg])
|
||||
config_record = {'LinePos': []}
|
||||
pos = 0
|
||||
@@ -300,7 +333,7 @@ class LaminaController:
|
||||
ch_coe = data_cfg_bare[pos+1] * 0x100 + data_cfg_bare[pos]
|
||||
pos += 2
|
||||
config_record['ChannelDescription'].append(bytearray(ch_desc).decode())
|
||||
config_record['ChannelCoefficient'].append(ch_coe / 10000)
|
||||
config_record['ChannelCoefficient'].append(ch_coe)
|
||||
if data_cfg_bare[pos+1] != 0xF4 or data_cfg_bare[pos] != 0xF4:
|
||||
Warning("config 配置文件格式异常")
|
||||
pos += 2
|
||||
@@ -327,8 +360,8 @@ class LaminaController:
|
||||
'day': data_cfg_bare[pos+5] * 0x100 + data_cfg_bare[pos+4],
|
||||
'hour': data_cfg_bare[pos+7] * 0x100 + data_cfg_bare[pos+6],
|
||||
'minute': data_cfg_bare[pos+9] * 0x100 + data_cfg_bare[pos+8],
|
||||
'second': data_cfg_bare[pos+11] * 0x100 + data_cfg_bare[pos+10],
|
||||
'msec': data_cfg_bare[pos+13] * 0x100 + data_cfg_bare[pos+12],
|
||||
'second': data_cfg_bare[pos+11] * 0x100 + data_cfg_bare[pos+10] +
|
||||
(data_cfg_bare[pos+13] * 0x100 + data_cfg_bare[pos+12]) * 0.001,
|
||||
}
|
||||
config_record['StartTime'] = time_stamp
|
||||
pos += 14
|
||||
@@ -338,12 +371,39 @@ class LaminaController:
|
||||
'day': data_cfg_bare[pos+5] * 0x100 + data_cfg_bare[pos+4],
|
||||
'hour': data_cfg_bare[pos+7] * 0x100 + data_cfg_bare[pos+6],
|
||||
'minute': data_cfg_bare[pos+9] * 0x100 + data_cfg_bare[pos+8],
|
||||
'second': data_cfg_bare[pos+11] * 0x100 + data_cfg_bare[pos+10],
|
||||
'msec': data_cfg_bare[pos+13] * 0x100 + data_cfg_bare[pos+12],
|
||||
'second': data_cfg_bare[pos+11] * 0x100 + data_cfg_bare[pos+10] +
|
||||
(data_cfg_bare[pos+13] * 0x100 + data_cfg_bare[pos+12]) * 0.001,
|
||||
}
|
||||
config_record['TriggerTime'] = time_stamp
|
||||
|
||||
data_record = b"".join([x['data'] for x in frame_data_record])
|
||||
# 处理录波数据
|
||||
data_record_bare = b"".join([x['data'] for x in frame_data_record])
|
||||
data_record = []
|
||||
pos = 0
|
||||
while pos < len(data_record_bare):
|
||||
record_point = {
|
||||
'index': data_record_bare[pos+3] * 0x1000 +
|
||||
data_record_bare[pos+2] * 0x100 +
|
||||
data_record_bare[pos+1] * 0x10 +
|
||||
data_record_bare[pos],
|
||||
'timestamp': data_record_bare[pos+7] * 0x1000 +
|
||||
data_record_bare[pos+6] * 0x100 +
|
||||
data_record_bare[pos+5] * 0x10 +
|
||||
data_record_bare[pos + 4],
|
||||
'ChAlg': [],
|
||||
'ChDgt': [],
|
||||
}
|
||||
pos += 8
|
||||
for i in range(config_record['ChNum_Alg']):
|
||||
point_data_alg = data_record_bare[pos+1] * 0x100 + data_record_bare[pos]
|
||||
if data_record_bare[pos+1] & 0x80:
|
||||
point_data_alg -= 0x10000
|
||||
record_point['ChAlg'].append(point_data_alg)
|
||||
pos += 2
|
||||
for i in range(config_record['ChNum_Dgt']):
|
||||
point_data_dgt = (data_record_bare[pos+(i // 8)] & (0x01 << (i % 8))) == (0x01 << (i % 8))
|
||||
record_point['ChDgt'].append(point_data_dgt)
|
||||
pos += 2
|
||||
data_record.append(record_point)
|
||||
|
||||
return config_record, data_record
|
||||
|
||||
@@ -372,8 +432,11 @@ class LaminaController:
|
||||
try_times -= 1
|
||||
continue
|
||||
|
||||
_, _, self.block["data"]['file_block_size'] = check_frame_modbus(frame_slave, self.block['data'])
|
||||
break
|
||||
try:
|
||||
ret, _, self.block["data"]['file_block_size'] = check_frame_modbus(frame_slave, self.block['data'])
|
||||
break
|
||||
except Exception as e:
|
||||
print(e)
|
||||
|
||||
if self.block["data"]['file_block_size'] == 0:
|
||||
raise Exception("Error slave response.")
|
||||
@@ -460,7 +523,7 @@ def test_communication(time_out=2):
|
||||
dev_lamina.flag_print = False
|
||||
try:
|
||||
while 1:
|
||||
if dev_lamina.frame_read(0x0E, 0x13):
|
||||
if dev_lamina.frame_read(0x0C, 0x20):
|
||||
log_success += 1
|
||||
cnt_failedseries = 0
|
||||
else:
|
||||
@@ -482,14 +545,61 @@ def test_communication(time_out=2):
|
||||
dev_lamina.flag_print = saveconfig_print
|
||||
|
||||
|
||||
def test_record(path_CFG=None, path_data=None):
|
||||
""" 执行录波数据读取流程 """
|
||||
if path_CFG is None: path_CFG = Path(r"D:\WorkSpace\UserTool\SelfTool\FrameParser\test\p280039\record") / f"record_{'-'.join(time.ctime().replace(':', '').split(' '))}.cfg"
|
||||
if path_data is None: path_data = Path(r"D:\WorkSpace\UserTool\SelfTool\FrameParser\test\p280039\record") / f"record_{'-'.join(time.ctime().replace(':', '').split(' '))}.dat"
|
||||
|
||||
config, data = dev_lamina.frame_record()
|
||||
|
||||
# Header File
|
||||
|
||||
# Config File
|
||||
text_cfg = ""
|
||||
text_cfg += f"LaminaController,1,{config['Standard']}\r\n"
|
||||
text_cfg += f"{config['ChannelNum']},{config['ChNum_Alg']}A,{config['ChNum_Dgt']}D\r\n"
|
||||
for i in range(config['ChNum_Alg']):
|
||||
if config['ChannelDescription'][i][-1] == 'V':
|
||||
text_cfg += f"{config['ChannelDescription'][i]},{1/config['ChannelCoefficient'][i]},0,0,-32767,32767,0.001,1,S\r\n"
|
||||
elif config['ChannelDescription'][i][-1] == 'A':
|
||||
text_cfg += f"{config['ChannelDescription'][i]},{1/config['ChannelCoefficient'][i]},0,0,-32767,32767,1,1,S\r\n"
|
||||
else:
|
||||
raise Exception("Unknow Channel Units.")
|
||||
for i in range(config['ChNum_Dgt']):
|
||||
text_cfg += f"{config['ChannelDescription'][i + config['ChNum_Alg']]}\r\n"
|
||||
text_cfg += f"{config['SysFreq']}\r\n"
|
||||
text_cfg += f"{config['FreqNum']}\r\n"
|
||||
for i in range(config['FreqNum']):
|
||||
text_cfg += f"{config['SampleFreq']},{config['SamplePoint']}\r\n"
|
||||
# text_cfg += f"{datetime(**config['StartTime']).strftime('%y/%m/%d,%H:%M:%S')}\r\n"
|
||||
# text_cfg += f"{datetime(**config['TriggerTime']).strftime('%y/%m/%d,%H:%M:%S')}\r\n"
|
||||
text_cfg += f"{datetime.now().strftime('%y/%m/%d,%H:%M:%S')}\r\n"
|
||||
text_cfg += f"{datetime.now().strftime('%y/%m/%d,%H:%M:%S')}\r\n"
|
||||
text_cfg += f"ASCII\r\n"
|
||||
text_cfg += f"1\r\n"
|
||||
path_CFG.write_text(text_cfg)
|
||||
|
||||
# Data File
|
||||
text_record = ""
|
||||
for point in data:
|
||||
# line_record = f"{point['index']},{point['timestamp'] * 1000},"
|
||||
line_record = f"{point['index']},{30},"
|
||||
for data_alg in point['ChAlg']:
|
||||
line_record += f"{data_alg},"
|
||||
for data_dgt in point['ChDgt']:
|
||||
line_record += f"{data_dgt},"
|
||||
text_record += line_record + "\r\n"
|
||||
path_data.write_text(text_record)
|
||||
|
||||
|
||||
def make_Image():
|
||||
""" 叠光控制器DSP镜像与升级包生成流程 """
|
||||
root = Path(r"test\p280039")
|
||||
result = Path(r"test\p280039\result")
|
||||
root = Path(r"D:\WorkSpace\UserTool\SelfTool\FrameParser\test\p280039")
|
||||
result = Path(r"D:\WorkSpace\UserTool\SelfTool\FrameParser\test\p280039\result")
|
||||
|
||||
# 正常启动镜像
|
||||
hex_boot = root / r"DLSP001_240828_0900_BL1.01.hex"
|
||||
hex_main = root / r"DLSP001_240828_0900_V1.01.hex"
|
||||
hex_boot = Path(r"D:\WorkingProject\LightStackOptimizer\software\lamina_controller_dsp\bootloader\Debug\bootloader.hex")
|
||||
hex_main = Path(r"D:\WorkingProject\LightStackOptimizer\software\lamina_controller_dsp\lamina_controller_dsp\DEBUG\lamina_controller_dsp.hex")
|
||||
hex_back = root / r"DLSP001_240828_0900_B1.01.hex"
|
||||
|
||||
file_image = result / f'{hex_main.stem}_ROM.hex'
|
||||
@@ -548,24 +658,8 @@ def make_Pakeage(fp: Path):
|
||||
|
||||
return file_package
|
||||
|
||||
if __name__=='__main__':
|
||||
mode_config = {
|
||||
"Log": {'com_name': None,
|
||||
# 'addr_645': [0x01, 0x00, 0x00, 0x00, 0x00, 0x40],
|
||||
},
|
||||
"Debug": {'com_name': 'COM8', 'baudrate': 115200, 'parity': 'N', 'bytesize': 8, 'stopbits': 1,
|
||||
# 'addr_645': [0x01, 0x02, 0x03, 0x04, 0x05, 0x06],
|
||||
'frame_print': True,
|
||||
'time_out': 0.2, 'retry': 3, 'retry_sub': 10},
|
||||
}
|
||||
|
||||
|
||||
dev_lamina = LaminaController(**mode_config['Debug'])
|
||||
|
||||
dev_lamina.frame_read(0x0100, 0x20)
|
||||
|
||||
dev_lamina.frame_record()
|
||||
|
||||
def test():
|
||||
""" 测试用代码 """
|
||||
if 0:
|
||||
dev_lamina.frame_write_str(0x82, [0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA])
|
||||
dev_lamina.frame_write_str(0x82, [0x00, 0x00, 0x00, 0x00, 0x00, 0x00])
|
||||
@@ -638,14 +732,45 @@ if __name__=='__main__':
|
||||
time.sleep(2)
|
||||
dev_lamina.frame_read(0x0170, 0x30)
|
||||
|
||||
if not hasattr(__builtins__,"__IPYTHON__"):
|
||||
|
||||
if __name__=='__main__':
|
||||
mode_config = {
|
||||
"Log": {'com_name': None,
|
||||
# 'addr_645': [0x01, 0x00, 0x00, 0x00, 0x00, 0x40],
|
||||
},
|
||||
"Debug": {'com_name': 'COM3', 'baudrate': 115200, 'parity': 'N', 'bytesize': 8, 'stopbits': 1,
|
||||
# 'addr_645': [0x01, 0x02, 0x03, 0x04, 0x05, 0x06],
|
||||
'frame_print': True,
|
||||
'time_out': 0.2, 'retry': 3, 'retry_sub': 10},
|
||||
}
|
||||
|
||||
dev_lamina = LaminaController(**mode_config['Debug'])
|
||||
|
||||
dev_lamina.frame_read(0x0100, 0x20)
|
||||
|
||||
|
||||
if not hasattr(__builtins__,"__IPYTHON__") and 0: #
|
||||
""" 读取故障录波数据 """
|
||||
path_CFG = Path(r"D:\WorkSpace\UserTool\SelfTool\FrameParser\test\p280039\result\record4.cfg")
|
||||
path_data = Path(r"D:\WorkSpace\UserTool\SelfTool\FrameParser\test\p280039\result\record4.dat")
|
||||
# 手动触发录波
|
||||
dev_lamina.frame_write_one(0x56, 1)
|
||||
|
||||
test_record(path_CFG, path_data)
|
||||
|
||||
if not hasattr(__builtins__,"__IPYTHON__"): # and 0
|
||||
""" 升级流程 """
|
||||
path_project = Path("D:\WorkingProject\LightStackOptimizer\software\lamina_controller_dsp\lamina_controller_dsp")
|
||||
file_hex = path_project / "DEBUG\lamina_controller_dsp.hex"
|
||||
# file_hex = Path(r"C:\Users\wrqal\Documents\WXWork\1688856624403708\Cache\File\2024-09\lamina_controller_dsp(1).hex")
|
||||
if not file_hex.exists():
|
||||
raise Exception("工程编译目标文件不存在.")
|
||||
file_package = make_Pakeage(file_hex)
|
||||
|
||||
dev_lamina.frame_write_one(0x60, 0)
|
||||
|
||||
time.sleep(1)
|
||||
|
||||
dev_lamina.frame_update(file_package)
|
||||
|
||||
time.sleep(6)
|
||||
|
||||
@@ -256,12 +256,14 @@ def find_frame_modbus(buffer, address, frame_defines: dict=frame_modbus):
|
||||
for i in range(len_buffer):
|
||||
if buffer[i] != address:
|
||||
continue
|
||||
if buffer[i+1] not in frame_defines.keys():
|
||||
if (buffer[i+1] & 0x7F) not in frame_defines.keys():
|
||||
continue
|
||||
|
||||
frame_define = frame_defines[buffer[i+1]]
|
||||
frame_define = frame_defines[buffer[i+1] & 0x7F]
|
||||
j = frame_define[0]
|
||||
if frame_define[1] == 0:
|
||||
if buffer[i+1] & 0x80:
|
||||
j = 5
|
||||
elif frame_define[1] == 0:
|
||||
pass
|
||||
elif frame_define[1] == 1:
|
||||
j += buffer[i+frame_define[2]]
|
||||
@@ -286,9 +288,9 @@ def find_frame_dlt645(buffer, address: list):
|
||||
|
||||
pos_frame, len_frame = 0, 0
|
||||
for i in range(len_buffer):
|
||||
if buffer[i] != 0x68 or buffer[i+8] != 0x68:
|
||||
if buffer[i] != 0x68 or buffer[i+7] != 0x68:
|
||||
continue
|
||||
if buffer[i+1] != bytearray(address):
|
||||
if address[0] != 0xAA and buffer[i+1:i+7] == bytes(address):
|
||||
continue
|
||||
|
||||
j = buffer[i+9] + 12
|
||||
|
||||
@@ -410,6 +410,97 @@ def GeneratePackage_SLCP001_p460(path_hex: Path):
|
||||
return bytearray(Image), bin_main
|
||||
|
||||
|
||||
def GenerateImage_DLSY001_p460(path_boot: Path, path_main: Path, path_back: Path):
|
||||
""" 叠光适配器-460平台版本 镜像生成 """
|
||||
config = {
|
||||
'prod_type': [0x45, 0x00], # 产品类型
|
||||
'method_compress': False, # 文件压缩
|
||||
'prog_id': list(b"DLSY001"), # 程序识别号
|
||||
'prog_type': 'app', # 程序类型
|
||||
'area_code': [0x00, 0x00], # 地区
|
||||
}
|
||||
bin_boot = file_IntelHex_to_Bin(path_boot.read_text(), len_max=0x00C000)
|
||||
bin_main = file_IntelHex_to_Bin(path_main.read_text(), len_max=0x024000)
|
||||
bin_back = file_IntelHex_to_Bin(path_back.read_text(), len_max=0x024000)
|
||||
encrypt_main = file_encryption(bin_main)
|
||||
encrypt_back = file_encryption(bin_back)
|
||||
|
||||
md5_ctx = hashlib.md5()
|
||||
md5_ctx.update(bin_main)
|
||||
config["md5"] = list(md5_ctx.digest())
|
||||
config['file_length'] = conv_int_to_array(len(bin_main))
|
||||
config['hex_name'] = list(path_main.name.encode())[:64]
|
||||
config['hex_name'] += [0] * (64 - len(config['hex_name']))
|
||||
if (main_header:=build_header_new(config)) is None:
|
||||
raise Exception("Header tag oversize. ")
|
||||
|
||||
md5_ctx = hashlib.md5()
|
||||
md5_ctx.update(bin_back)
|
||||
config["md5"] = list(md5_ctx.digest())
|
||||
config['file_length'] = conv_int_to_array(len(bin_back))
|
||||
config['hex_name'] = list(path_back.name.encode())[:64]
|
||||
config['hex_name'] += [0] * (64 - len(config['hex_name']))
|
||||
if (back_header:=build_header_new(config)) is None:
|
||||
raise Exception("Header tag oversize. ")
|
||||
|
||||
print("Merge Image generated successfully.")
|
||||
print(f"Main File:")
|
||||
print(f"\t header_length={len(main_header)}, bin_length={len(bin_main)}[{hex(len(bin_main))}]")
|
||||
print(f"Back File:")
|
||||
print(f"\t header_length={len(back_header)}, bin_length={len(bin_back)}[{hex(len(bin_back))}]")
|
||||
|
||||
# 组装镜像
|
||||
Image = [0xFF] * 0x058000
|
||||
offset_image = 0
|
||||
Image[offset_image: offset_image + len(bin_boot)] = bin_boot
|
||||
offset_image = 0x00C000
|
||||
Image[offset_image: offset_image + len(bin_main)] = bin_main
|
||||
offset_image = 0x030000
|
||||
Image[offset_image: offset_image + len(bin_back)] = bin_back
|
||||
offset_image = 0x054000
|
||||
Image[offset_image: offset_image + len(main_header)] = main_header
|
||||
offset_image = 0x056000
|
||||
Image[offset_image: offset_image + len(back_header)] = back_header
|
||||
|
||||
return bytearray(Image), main_header, back_header
|
||||
|
||||
|
||||
def GeneratePackage_DLSY001_p460(path_hex: Path):
|
||||
""" 叠光适配器-460平台版本 生成升级包 """
|
||||
config = {
|
||||
'prod_type': [0x45, 0x00], # 产品类型
|
||||
'method_compress': False, # 文件压缩
|
||||
'prog_id': list(b"DLSY001"), # 程序识别号
|
||||
'prog_type': 'app', # 程序类型
|
||||
'area_code': [0x00, 0x00], # 地区
|
||||
}
|
||||
bin_main = file_IntelHex_to_Bin(path_hex.read_text(), len_max=0x024000)
|
||||
encrypt_main = file_encryption(bin_main)
|
||||
|
||||
md5_ctx = hashlib.md5()
|
||||
md5_ctx.update(bin_main)
|
||||
config["md5"] = list(md5_ctx.digest())
|
||||
config['file_length'] = conv_int_to_array(len(bin_main))
|
||||
config['hex_name'] = list(path_hex.name.encode())[:64]
|
||||
config['hex_name'] += [0] * (64 - len(config['hex_name']))
|
||||
if (main_header:=build_header_new(config)) is None:
|
||||
raise Exception("Header tag oversize. ")
|
||||
|
||||
print("Package generated successfully.")
|
||||
print(f"File name: {path_hex.name}")
|
||||
print(f"File Info:")
|
||||
print(f"\t header_length={len(main_header)}, bin_length={len(bin_main)}[{hex(len(bin_main))}]")
|
||||
|
||||
# 组装镜像
|
||||
Image = [0xFF] * (len(main_header) + len(encrypt_main))
|
||||
offset_image = 0
|
||||
Image[offset_image: offset_image + len(main_header)] = main_header
|
||||
offset_image += len(main_header)
|
||||
Image[offset_image: offset_image + len(encrypt_main)] = encrypt_main
|
||||
|
||||
return bytearray(Image), bin_main
|
||||
|
||||
|
||||
def GenerateImage_DLSP001_p280039(path_boot: Path, path_main: Path, path_back: Path):
|
||||
""" 叠光适配器-460平台版本 镜像生成 """
|
||||
config = {
|
||||
@@ -559,9 +650,55 @@ def Process1():
|
||||
file_image3.write_bytes(data_image)
|
||||
|
||||
|
||||
def Process2():
|
||||
""" 镜像生成流程 """
|
||||
root = Path(r"D:\WorkingProject\LightStackOptimizer\software\lamina_optimizer\lamina_optimizer\Debug")
|
||||
# result = Path(r"test\p460_o1\result")
|
||||
result = root
|
||||
# 正常启动镜像
|
||||
hex_boot = Path(r"test\p460_o1\bootloader.hex")
|
||||
hex_main = root / r"lamina_optimizer.hex"
|
||||
hex_back = root / r"lamina_optimizer.hex"
|
||||
hex_update = root / r"lamina_optimizer.hex"
|
||||
|
||||
file_image = result / f'{hex_main.stem}_ROM.bin'
|
||||
file_main_header = result / 'DLSY001_header_main.bin'
|
||||
file_back_header = result / 'DLSY001_header_back.bin'
|
||||
file_package = result / f'{hex_update.stem}.dat'
|
||||
file_bin = result / f'{hex_update.stem}.bin'
|
||||
|
||||
data_bins = GenerateImage_DLSY001_p460(hex_boot, hex_main, hex_back)
|
||||
data_package, data_bin = GeneratePackage_DLSY001_p460(hex_update)
|
||||
|
||||
file_image.write_bytes(data_bins[0].copy())
|
||||
file_main_header.write_bytes(data_bins[1].copy())
|
||||
file_back_header.write_bytes(data_bins[2].copy())
|
||||
file_package.write_bytes(data_package)
|
||||
file_bin.write_bytes(data_bin)
|
||||
|
||||
# 异常镜像-主分区md5错误
|
||||
file_image1 = result / f'{file_image.stem}_b1.bin'
|
||||
data_image = data_bins[0].copy()
|
||||
data_image[0x054018: 0x05401A] = [0x00, 0x01]
|
||||
file_image1.write_bytes(data_image)
|
||||
|
||||
# 异常镜像-备份分区md5错误
|
||||
file_image2 = result / f'{file_image.stem}_b2.bin'
|
||||
data_image = data_bins[0].copy()
|
||||
data_image[0x056018: 0x05601A] = [0x00, 0x01]
|
||||
file_image2.write_bytes(data_image)
|
||||
|
||||
# 异常镜像-双分区md5错误
|
||||
file_image3 = result / f'{file_image.stem}_b3.bin'
|
||||
data_image = data_bins[0].copy()
|
||||
data_image[0x054018: 0x05401A] = [0x00, 0x01]
|
||||
data_image[0x056018: 0x05601A] = [0x00, 0x01]
|
||||
file_image3.write_bytes(data_image)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
# path_bin = Path("F:\\Work\\FPGA\\Test\\Vivado\\test_update\\test_update.vitis\\upgrade_system\\Debug\\sd_card\\BOOT.BIN")
|
||||
# GeneratePackage_Demo_Xilinx(path_bin)
|
||||
|
||||
# test2()
|
||||
Process2()
|
||||
pass
|
||||
|
||||
Reference in New Issue
Block a user