diff options
author | Stanley Huang <stanleyhuangyc@gmail.com> | 2015-10-01 13:04:15 +1000 |
---|---|---|
committer | Stanley Huang <stanleyhuangyc@gmail.com> | 2015-10-01 13:04:15 +1000 |
commit | a979a3a2c41ef3fe19ec154616460c755ed04a10 (patch) | |
tree | a9497ddd806b87beb2a4ac9539c4d171c6b2eb44 | |
parent | 72c5b65bc5c34a596f2137210ff672f5f40c3abe (diff) | |
download | 2021-arduino-obd-a979a3a2c41ef3fe19ec154616460c755ed04a10.tar.gz 2021-arduino-obd-a979a3a2c41ef3fe19ec154616460c755ed04a10.tar.bz2 2021-arduino-obd-a979a3a2c41ef3fe19ec154616460c755ed04a10.zip |
Add GPS date validation
-rw-r--r-- | megalogger/megalogger.ino | 13 |
1 files changed, 8 insertions, 5 deletions
diff --git a/megalogger/megalogger.ino b/megalogger/megalogger.ino index 3d8f326..03cc2a9 100644 --- a/megalogger/megalogger.ino +++ b/megalogger/megalogger.ino @@ -56,7 +56,7 @@ static uint32_t startTime = 0; static uint16_t lastSpeed = 0; static uint32_t lastSpeedTime = 0; static int gpsSpeed = -1; -static uint16_t gpsDate = 0; +static uint32_t gpsDate = 0; static uint32_t obdTime = 0; static uint8_t obdCount = 0; @@ -378,10 +378,13 @@ void processGPS() logger.dataTime = millis(); gps.get_datetime(&date, &time, 0); - if ((uint16_t)date != gpsDate) { - // log date only if it's changed - logger.logData(PID_GPS_DATE, (int32_t)date); - gpsDate = (uint16_t)date; + if (date != gpsDate) { + // log date only if it's changed and valid + int year = date % 100; + if (date < 1000000 && date >= 10000 && year >= 15 && (gpsDate == 0 || year - (gpsDate % 100) <= 1)) { + logger.logData(PID_GPS_DATE, (int32_t)date); + gpsDate = date; + } } logger.logData(PID_GPS_TIME, (int32_t)time); |