Knio / pynmea2

Python library for parsing the NMEA 0183 protocol (GPS)
MIT License
631 stars 224 forks source link

nmea crashes when RMC values are blank #94

Open gigs94 opened 5 years ago

gigs94 commented 5 years ago

If I send a RMC to nmea that has lots of blank values and then I try to get the datatime back, an exception is thrown. The question I have, is should pynmea2 handle this, or is there code that I can call to check if it's valid before I call, p.datetime where p is the RMC instance. Since, datetime is a derived attribute, should it have checks in there to determine if the timestamp in the record is valid or not? and if so, I don't know what to return, None? Or is there a way for a user to check this before calling datetime?

This is what my gps returns when it's doesn't have any signal (like when I'm testing my code in a building)... '$GPGGA,,,,,,0,00,,,M,0.0,M,,0000*48'

And I get this exception thrown:

Exception in thread Thread-1:
Traceback (most recent call last):
  File "/usr/lib/python2.7/threading.py", line 801, in __bootstrap_inner
    self.run()
  File "/usr/lib/python2.7/threading.py", line 754, in run
    self.__target(*self.__args, **self.__kwargs)
  File "/opt/fh/deployed/src/gps_sink.py", line 153, in run
    c(s)
  File "/opt/fh/deployed/src/gps_sink.py", line 50, in set_time
    self.__gps_time = p.datetime
  File "/opt/fh/env/local/lib/python2.7/site-packages/pynmea2/nmea_utils.py", line 98, in datetime
    return datetime.datetime.combine(self.datestamp, self.timestamp)
TypeError: combine() argument 1 must be datetime.date, not None
xOneca commented 5 years ago

I think this should be managed by pynmea. Returning None, as do datestamp and timestamp.