adafruit / Adafruit_CircuitPython_GPS

GPS parsing module for CircuitPython. Meant to parse NMEA data from serial GPS modules.
MIT License
75 stars 58 forks source link

Fail bad sentences that pass the CRC check #57

Closed lesamouraipourpre closed 3 years ago

lesamouraipourpre commented 3 years ago

As the CRC is only 8 bit and bad sentences will get past it, this PR attempts to catch bad sentences by comparing them to an expected parameter type list after the CRC check. Fixes #55

The _update() method does the following:

  1. When available read a complete sentence from UART/I2C. Return False if not available. (No change)
  2. Check the CRC. Return False if it fails. (No change)
  3. If the sentence is NOT from a GNSS talker, assume it is valid and return True.
  4. Call a _parse_XXX method for the sentence type, eg. _parse_rmc() for RMC.
  5. If the data length is not an expected size, return False.
  6. Within these methods, call _parse_data() with an appropriate sentence type and the data.
  7. Match the data against the expected type and convert it. Return False if it fails.
  8. Use the parsed data to interpret the message and update instance variables.
  9. Return True

The time/data parsing code has also been refactored into a method so that it is not repeated through the code.

Hardware tested with: Pyportal Pynt to Adafruit Mini GPS over I2C I've had it connected for over 18 hours with no errors raised.

This is Draft as it would be appreciated if others can test on different hardware.

tannewt commented 3 years ago

Here is how I think we'll want to fix the duplicate-code check: https://github.com/adafruit/cookiecutter-adafruit-circuitpython/pull/111