import json def generate_packet(floor): """生成指定层的封包序列,每条指令占一行""" packets = [] # 命令 54_22 packet_54_22 = { "id": 15, "param": { "fmt": 0, "st": 1, "handler": "MB240906", "type": 99, "floor": floor }, "cmd": "54_22" } packets.append(f"|#send={json.dumps(packet_54_22)}|") # 时间延迟 1000ms packets.append("|#time=1000|") # 自动化标志 packets.append("|#auto=true|") # 等待指令 packets.append("|#wait|") # 命令 1212 packet_1212 = { "id": 13, "param": {}, "cmd": "1212" } packets.append(f"|#send={json.dumps(packet_1212)}|") # 时间延迟 3000ms packets.append("|#time=1000|") return packets def main(): # 生成 60 到 99 层的封包 all_packets = [] for floor in range(351, 450): packets = generate_packet(floor) all_packets.extend(packets) all_packets.append("") # 每层后加空行分隔 # 输出到控制台 for packet in all_packets: print(packet) # 保存到文件 with open("packets_60_to_99.txt", "w", encoding="utf-8") as f: for packet in all_packets: f.write(packet + "\n") if __name__ == "__main__": main()