get_gpstime optimization
This commit is contained in:
parent
aeccb59f55
commit
6a6e584234
@ -16,7 +16,6 @@ extern TinyGPSPlus gps; // Make TinyGPS++ instance globally availabe
|
|||||||
extern gpsStatus_t
|
extern gpsStatus_t
|
||||||
gps_status; // Make struct for storing gps data globally available
|
gps_status; // Make struct for storing gps data globally available
|
||||||
extern TaskHandle_t GpsTask;
|
extern TaskHandle_t GpsTask;
|
||||||
extern TickType_t const gpsDelay_ticks; // time to NMEA arrival
|
|
||||||
|
|
||||||
int gps_init(void);
|
int gps_init(void);
|
||||||
void gps_read(void);
|
void gps_read(void);
|
||||||
|
@ -11,10 +11,6 @@ TaskHandle_t GpsTask;
|
|||||||
|
|
||||||
#ifdef GPS_SERIAL
|
#ifdef GPS_SERIAL
|
||||||
HardwareSerial GPS_Serial(1); // use UART #1
|
HardwareSerial GPS_Serial(1); // use UART #1
|
||||||
TickType_t const gpsDelay_ticks = pdMS_TO_TICKS(1000 - NMEA_BUFFERTIME) -
|
|
||||||
tx_Ticks(NMEA_FRAME_SIZE, GPS_SERIAL);
|
|
||||||
#else
|
|
||||||
TickType_t const gpsDelay_ticks = pdMS_TO_TICKS(1000 - NMEA_BUFFERTIME);
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// initialize and configure GPS
|
// initialize and configure GPS
|
||||||
@ -27,13 +23,6 @@ int gps_init(void) {
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
// set timeout for reading recent time from GPS
|
|
||||||
#ifdef GPS_SERIAL // serial GPS
|
|
||||||
|
|
||||||
#else // I2C GPS
|
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if defined GPS_SERIAL
|
#if defined GPS_SERIAL
|
||||||
GPS_Serial.begin(GPS_SERIAL);
|
GPS_Serial.begin(GPS_SERIAL);
|
||||||
ESP_LOGI(TAG, "Using serial GPS");
|
ESP_LOGI(TAG, "Using serial GPS");
|
||||||
@ -88,20 +77,25 @@ void gps_read() {
|
|||||||
time_t get_gpstime(void) {
|
time_t get_gpstime(void) {
|
||||||
|
|
||||||
// set time to wait for arrive next recent NMEA time record
|
// set time to wait for arrive next recent NMEA time record
|
||||||
static const uint32_t gpsDelay_ms = gpsDelay_ticks / portTICK_PERIOD_MS;
|
static const uint32_t gpsDelay_ms = 500;
|
||||||
|
|
||||||
time_t t = 0;
|
time_t t = 0;
|
||||||
|
|
||||||
if ((gps.time.age() < gpsDelay_ms) && (gps.time.isValid()) &&
|
for (uint8_t i = 0; i <= 9; i++) { // trying to get a recent time.age
|
||||||
(gps.date.isValid())) {
|
|
||||||
|
|
||||||
ESP_LOGD(TAG, "GPS time age: %dms, is valid: %s, second: %d",
|
if ((gps.time.age() < gpsDelay_ms) && (gps.time.isValid()) &&
|
||||||
gps.time.age(),
|
(gps.date.isValid())) {
|
||||||
(gps.time.isValid() && gps.date.isValid()) ? "yes" : "no",
|
|
||||||
gps.time.second());
|
|
||||||
|
|
||||||
t = tmConvert(gps.date.year(), gps.date.month(), gps.date.day(),
|
ESP_LOGD(TAG, "GPS time age: %dms, is valid: %s, second: %d, trials: %d",
|
||||||
gps.time.hour(), gps.time.minute(), gps.time.second());
|
gps.time.age(),
|
||||||
|
(gps.time.isValid() && gps.date.isValid()) ? "yes" : "no",
|
||||||
|
gps.time.second(), i);
|
||||||
|
|
||||||
|
t = tmConvert(gps.date.year(), gps.date.month(), gps.date.day(),
|
||||||
|
gps.time.hour(), gps.time.minute(), gps.time.second());
|
||||||
|
|
||||||
|
break; // exit for
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return timeIsValid(t);
|
return timeIsValid(t);
|
||||||
} // get_gpstime()
|
} // get_gpstime()
|
||||||
|
Loading…
Reference in New Issue
Block a user