添加录波报文解析功能;
优化升级流程, 简化调用方式;
This commit is contained in:
@@ -70,6 +70,29 @@ def make_frame_modbus(block:dict):
|
||||
frame.append(0x00)
|
||||
else:
|
||||
raise Exception("Modbus Update Frame Step Error.")
|
||||
elif block['type'][:6] == 'record':
|
||||
""" 录波系列报文 """
|
||||
frame.append(0x11)
|
||||
frame_types = block['type'].split('_')
|
||||
|
||||
if block['type'][7:10] == 'cfg':
|
||||
frame.append(0x01)
|
||||
elif block['type'][7:11] == 'data':
|
||||
frame.append(0x02)
|
||||
else:
|
||||
raise Exception("Modbus Record Frame Type Error.")
|
||||
|
||||
if block['step'] == 'start':
|
||||
frame.append(0x00)
|
||||
elif block['step'] == 'next':
|
||||
frame.append(0x01)
|
||||
elif block['step'] == 'repeat':
|
||||
frame.append(0x02)
|
||||
else:
|
||||
raise Exception("Modbus Record Frame Step Error.")
|
||||
|
||||
frame.append(block['file_block_size'] // 256)
|
||||
frame.append(block['file_block_size'] % 256)
|
||||
else:
|
||||
""" 数据读取系列报文 """
|
||||
data_addr = block['data_addr']
|
||||
@@ -317,6 +340,25 @@ def check_frame_modbus(frame, block=None):
|
||||
elif code_func == 0x10:
|
||||
""" 多个数据写入帧 """
|
||||
return trans_list_to_str(frame[2:-2])
|
||||
elif code_func == 0x11:
|
||||
""" 录波功能帧 """
|
||||
frame_data = {
|
||||
'seq': frame[5] * 0x100 + frame[6],
|
||||
'total': frame[3] * 0x100 + frame[4],
|
||||
'data': frame[9:-2]
|
||||
}
|
||||
if frame[2] == 0x01:
|
||||
frame_data['type'] = 'config'
|
||||
elif frame[2] == 0x02:
|
||||
frame_data["type"] = 'data'
|
||||
else:
|
||||
raise Exception("Unknow data type")
|
||||
return True, frame_data
|
||||
elif code_func & 0x80:
|
||||
""" 错误返回帧 """
|
||||
if code_func & 0x7F == 0x07:
|
||||
return False, frame[3], code_func, code_subfunc
|
||||
return False, frame[2], code_func
|
||||
else:
|
||||
raise Exception(f"Frame Date error. func={code_func}, func_sub={code_subfunc}, len={len(frame)}")
|
||||
|
||||
|
||||
Reference in New Issue
Block a user