# command_37_38.py import struct import logging import time class Command3738: def build_37h_request(self, pile_id, billing_template): """ 下发计费模版请求 :param pile_id: 8字节桩号 :param billing_template: 计费模版列表,格式 [(time_minutes, price_per_minute, total_seconds, total_cost), ...] """ frame = bytearray([0x4A, 0x58, 0x37]) # 帧头 + 命令 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) data.extend(b'\x1D\x00\x00\x00\x00\x00') # 未知字段,参考日志 # 计费模版数据 for entry in billing_template: time_minutes, price_per_minute, total_seconds, total_cost = entry data.extend(struct.pack('