message.py 文件源码

python
阅读 31 收藏 0 点赞 0 评论 0

项目:PhasorToolBox 作者: sonusz 项目源码 文件源码
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)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号