nmea_device.py 文件源码

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

项目:NMEA-Tools 作者: slott56 项目源码 文件源码
def validate(sentence_bytes):
        """Validate an NMEA sentence, returning either a tuple of substrings or an 
        :exc:`AssertionError`.

        :param sentence_bytes: A bytes object with the raw sentence.
        :returns: tuple with individual fields, suitable for use with a
            :class:`Sentence_Factory` isntance.
        :raises AssertionError: If the sentence is incomplete in some way.
        """
        assert sentence_bytes.startswith(b'$'), "Sentence fragment"
        content, _, checksum_txt = sentence_bytes[1:].partition(b"*")
        if checksum_txt:
            checksum_exp = int(checksum_txt, 16)
            checksum_act = reduce(xor, content)
            assert checksum_exp == checksum_act, "Invalid checksum"
        return tuple(content.split(b','))
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号