3 NMEA_DEFAULT_MAX_LENGTH = 82
4 NMEA_DEFAULT_MIN_LENGTH = 3
5 _NMEA_CHECKSUM_SEPERATOR =
"*" 9 def __init__(self, logerr=logging.error, logwarn=logging.warning, loginfo=logging.info, logdebug=logging.debug):
23 self.
_logwarn(
'Received invalid NMEA sentence. Max length is {}, but sentence was {} bytes'.format(self.
nmea_max_length, len(sentence)))
24 self.
_logwarn(
'Sentence: {}'.format(sentence))
27 self.
_logwarn(
'Received invalid NMEA sentence. We need at least {} bytes to parse but got {} bytes'.format(self.
nmea_min_length, len(sentence)))
28 self.
_logwarn(
'Sentence: {}'.format(sentence))
30 if sentence[0] !=
'$' and sentence[0] !=
'!':
31 self.
_logwarn(
'Received invalid NMEA sentence. Sentence should begin with "$" or "!", but instead begins with {}'.format(sentence[0]))
32 self.
_logwarn(
'Sentence: {}'.format(sentence))
34 if sentence[-2:] !=
'\r\n':
35 self.
_logwarn(
'Received invalid NMEA sentence. Sentence should end with \\r\\n, but instead ends with {}'.format(sentence[-2:]))
36 self.
_logwarn(
'Sentence: {}'.format(sentence))
38 if _NMEA_CHECKSUM_SEPERATOR
not in sentence:
39 self.
_logwarn(
'Received invalid NMEA sentence. Sentence should have a "{}" character to seperate the checksum, but we could not find it.'.format(_NMEA_CHECKSUM_SEPERATOR))
40 self.
_logwarn(
'Sentence: {}'.format(sentence))
44 data, expected_checksum_str = sentence.rsplit(_NMEA_CHECKSUM_SEPERATOR, 1)
45 expected_checksum = int(expected_checksum_str, 16)
46 calculated_checksum = 0
48 calculated_checksum ^= ord(char)
49 if expected_checksum != calculated_checksum:
50 self.
_logwarn(
'Received invalid NMEA sentence. Checksum mismatch');
51 self.
_logwarn(
'Expected Checksum: 0x{:X}'.format(expected_checksum))
52 self.
_logwarn(
'Calculated Checksum: 0x{:X}'.format(calculated_checksum))
def is_valid_sentence(self, sentence)
def __init__(self, logerr=logging.error, logwarn=logging.warning, loginfo=logging.info, logdebug=logging.debug)