积累更新;
This commit is contained in:
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user