diff --git a/charging_pile_proxy/commands/__pycache__/command_02.cpython-311.pyc b/charging_pile_proxy/commands/__pycache__/command_02.cpython-311.pyc index eeff710..dd6f809 100644 Binary files a/charging_pile_proxy/commands/__pycache__/command_02.cpython-311.pyc and b/charging_pile_proxy/commands/__pycache__/command_02.cpython-311.pyc differ diff --git a/charging_pile_proxy/commands/command_02.py b/charging_pile_proxy/commands/command_02.py index 7c2c85b..595576d 100644 --- a/charging_pile_proxy/commands/command_02.py +++ b/charging_pile_proxy/commands/command_02.py @@ -257,22 +257,62 @@ def test_command(): # 创建响应处理器 handler = Command02() - # 原始测试数据 - hex_string = "4A5801031767631136065701100019010909371501000000000000000000004D" - - # 解析数据长度字段以确定正确的数据包长度 - expected_len = 14 + 16 + 1 # 头部(14字节) + 数据域(16字节) + 校验码(1字节) - - # 确保只取需要的字节 - test_data = bytes.fromhex(hex_string[:expected_len * 2]) # *2是因为hex字符串中一个字节用两个字符表示 + # 直接使用完整的测试数据,不进行裁剪 + test_data = bytes.fromhex("4A5801031767631136065701100019010909371501000000000000000000004D") print("\n测试数据:") - print(f"原始数据: {hex_string}") - print(f"处理后数据: {test_data.hex().upper()}") + print(f"数据内容: {test_data.hex().upper()}") print(f"数据长度: {len(test_data)}字节") - # 打印详细字段解析 - handler.debug_print_fields(test_data) + # 修改validate_frame方法来处理多余字节 + def validate_frame(self, data): + """验证帧格式""" + try: + print("\n开始验证帧格式:") + print(f"数据内容: {data.hex().upper()}") + print(f"数据长度: {len(data)}字节") + + # 1. 基本格式检查 + if len(data) < 14: + print("数据长度不足14字节") + return False + + if data[0:2] != b'JX': + print("帧起始标志不是'JX'") + return False + + # 2. 获取数据域长度 + data_len = struct.unpack("