gpsread.cpp: NMEA ZDA processing improved

This commit is contained in:
Klaus K Wilting 2020-10-04 23:13:17 +02:00
parent 5dc44a02fb
commit b0d3dfebb5

View File

@ -12,7 +12,10 @@ static const char TAG[] = __FILE__;
// thus precision is only +/- 1 second
TinyGPSPlus gps;
TinyGPSCustom gpstime(gps, "GPZDA", 1); // field 1 = UTC time
TinyGPSCustom gpstime(gps, "GPZDA", 1); // field 1 = UTC time (hhmmss.ss)
TinyGPSCustom gpsday(gps, "GPZDA", 2); // field 2 = day (01..31)
TinyGPSCustom gpsmonth(gps, "GPZDA", 3); // field 3 = month (01..12)
TinyGPSCustom gpsyear(gps, "GPZDA", 4); // field 4 = year (4-digit)
static const String ZDA_Request = "$EIGPQ,ZDA*39\r\n";
TaskHandle_t GpsTask;
@ -102,34 +105,30 @@ time_t get_gpstime(uint16_t *msec) {
#ifdef GPS_SERIAL
GPS_Serial.print(ZDA_Request);
// wait for gps NMEA answer
vTaskDelay(tx_Ticks(NMEA_FRAME_SIZE, GPS_SERIAL));
// vTaskDelay(tx_Ticks(NMEA_FRAME_SIZE, GPS_SERIAL));
#elif defined GPS_I2C
Wire.print(ZDA_Request);
#endif
// did we get a current time?
if (gpstime.isUpdated() && gpstime.isValid()) {
// did we get a current date & time?
if (gpstime.isUpdated() && gpstime.isValid() && gpsday.isValid()) {
tmElements_t tm;
String rawtime = gpstime.value();
uint32_t time_bcd = rawtime.toFloat() * 100;
uint32_t time_bcd = atof(gpstime.value()) * 100;
uint32_t delay_ms =
gpstime.age() + nmea_txDelay_ms + NMEA_COMPENSATION_FACTOR;
uint8_t year =
CalendarYrToTm(gps.date.year()); // year offset from 1970 in microTime.h
ESP_LOGD(TAG, "time [bcd]: %u", time_bcd);
tm.Second = (time_bcd / 100) % 100; // second
tm.Minute = (time_bcd / 10000) % 100; // minute
tm.Hour = time_bcd / 1000000; // hour
tm.Day = gps.date.day(); // day
tm.Month = gps.date.month(); // month
tm.Year = year; // year
tm.Day = atoi(gpsday.value()); // day
tm.Month = atoi(gpsmonth.value()); // month
tm.Year = CalendarYrToTm(
atoi(gpsyear.value())); // year offset from 1970 in microTime.h
// add protocol delay to time with millisecond precision
time_sec = makeTime(tm) + delay_ms / 1000;
time_sec = makeTime(tm) + delay_ms / 1000 - 1;
*msec = (delay_ms % 1000) ? delay_ms % 1000 : 0;
}
@ -165,13 +164,13 @@ void gps_loop(void *pvParameters) {
// if time hasn't been synchronised yet, and we have a valid GPS time,
// update time from GPS.
if (timeSource == _unsynced && gpstime.isUpdated() && gpstime.isValid()) {
if (timeSource == _unsynced && gpstime.isUpdated() && gpstime.isValid() &&
gpsday.isValid())
calibrateTime();
}
} // if
// show NMEA data in verbose mode, useful for debugging GPS, bu tvery noisy
// show NMEA data in verbose mode, useful only for debugging GPS, very noisy
// ESP_LOGV(TAG, "GPS NMEA data: passed %u / failed: %u / with fix: %u",
// gps.passedChecksum(), gps.failedChecksum(),
// gps.sentencesWithFix());