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 // thus precision is only +/- 1 second
TinyGPSPlus gps; 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"; static const String ZDA_Request = "$EIGPQ,ZDA*39\r\n";
TaskHandle_t GpsTask; TaskHandle_t GpsTask;
@ -102,34 +105,30 @@ time_t get_gpstime(uint16_t *msec) {
#ifdef GPS_SERIAL #ifdef GPS_SERIAL
GPS_Serial.print(ZDA_Request); GPS_Serial.print(ZDA_Request);
// wait for gps NMEA answer // 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 #elif defined GPS_I2C
Wire.print(ZDA_Request); Wire.print(ZDA_Request);
#endif #endif
// did we get a current time? // did we get a current date & time?
if (gpstime.isUpdated() && gpstime.isValid()) { if (gpstime.isUpdated() && gpstime.isValid() && gpsday.isValid()) {
tmElements_t tm; tmElements_t tm;
String rawtime = gpstime.value(); uint32_t time_bcd = atof(gpstime.value()) * 100;
uint32_t time_bcd = rawtime.toFloat() * 100;
uint32_t delay_ms = uint32_t delay_ms =
gpstime.age() + nmea_txDelay_ms + NMEA_COMPENSATION_FACTOR; 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.Second = (time_bcd / 100) % 100; // second
tm.Minute = (time_bcd / 10000) % 100; // minute tm.Minute = (time_bcd / 10000) % 100; // minute
tm.Hour = time_bcd / 1000000; // hour tm.Hour = time_bcd / 1000000; // hour
tm.Day = gps.date.day(); // day tm.Day = atoi(gpsday.value()); // day
tm.Month = gps.date.month(); // month tm.Month = atoi(gpsmonth.value()); // month
tm.Year = year; // year tm.Year = CalendarYrToTm(
atoi(gpsyear.value())); // year offset from 1970 in microTime.h
// add protocol delay to time with millisecond precision // 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; *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, // if time hasn't been synchronised yet, and we have a valid GPS time,
// update time from GPS. // update time from GPS.
if (timeSource == _unsynced && gpstime.isUpdated() && gpstime.isValid()) { if (timeSource == _unsynced && gpstime.isUpdated() && gpstime.isValid() &&
gpsday.isValid())
calibrateTime(); calibrateTime();
}
} // if } // 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", // ESP_LOGV(TAG, "GPS NMEA data: passed %u / failed: %u / with fix: %u",
// gps.passedChecksum(), gps.failedChecksum(), // gps.passedChecksum(), gps.failedChecksum(),
// gps.sentencesWithFix()); // gps.sentencesWithFix());