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','))
评论列表
文章目录