def __new__(
self,
SYNC=b'\xaa\x01',
IDCODE=1,
TIME=None,
TQ_FLAGS='0000',
MSG_TQ='1111',
TIME_BASE=16777215,
DATA=b''
):
TIME = time.time() if not TIME else TIME
raw_data = b''.join((
SYNC,
(len(DATA) + 16).to_bytes(2, 'big'), # FRAMESIZE
IDCODE.to_bytes(2, 'big'),
int(TIME).to_bytes(4, 'big'), # SOC
int(TQ_FLAGS + MSG_TQ, 2).to_bytes(1, 'big'),
int(TIME % 1 * TIME_BASE).to_bytes(3, 'big'), # Frac of sec
DATA
))
chk_sum = binascii.crc_hqx(raw_data, -1).to_bytes(2, 'big')
return bytes.__new__(bytes, raw_data+chk_sum)
评论列表
文章目录