# command_heartbeat.py import struct import logging import time class CommandHeartbeat: def build_0b_heartbeat(self, pile_id): frame = bytearray([0x4A, 0x58, 0x0B]) # 帧头 + 命令 frame.extend(pile_id) # 桩号 frame.append(0x01) # 数据加密方式(不加密) # 数据域:时间标识 data = bytearray() current_time = time.localtime() time_bytes = bytearray([ current_time.tm_year - 2000, current_time.tm_mon, current_time.tm_mday, current_time.tm_hour, current_time.tm_min, current_time.tm_sec ]) data.extend(time_bytes) frame.extend(struct.pack('