import struct class Command05: def __init__(self): self.pile_id = b"\x00\x27\x02\x12\x34\x56\x12\x34" # 示例桩号 def build_05h_request(self): """构建05H请求对时帧""" frame = bytearray([0x4A, 0x58]) # 帧头: "JX" frame.append(0x05) # 命令码: 05H frame.extend(self.pile_id) # 桩号 (8字节) frame.append(0x01) # 数据加密方式: 0x01 (不加密) frame.extend([0x00, 0x00]) # 数据域长度 (0) checksum = 0 for b in frame[2:-1]: checksum ^= b frame.append(checksum) # 校验码 return frame def process_05h_response(self, response): """处理06H响应(由充电桩调用)""" if response and len(response) >= 14 and response[2] == 0x06: logging.info("对时成功") return True logging.warning("无效的06H响应") return False if __name__ == "__main__": import logging logging.basicConfig(level=logging.INFO) cmd = Command05() request = cmd.build_05h_request() print(f"05H请求帧: {request.hex().upper()}")