GPS fixes & code sanitization
This commit is contained in:
parent
e8521094b8
commit
4973568546
@ -18,10 +18,10 @@ extern gpsStatus_t
|
||||
extern TaskHandle_t GpsTask;
|
||||
|
||||
int gps_init(void);
|
||||
void IRAM_ATTR gps_storetime(gpsStatus_t &gps_store);
|
||||
void gps_storelocation(gpsStatus_t &gps_store);
|
||||
void IRAM_ATTR gps_storetime(gpsStatus_t *gps_store);
|
||||
void gps_storelocation(gpsStatus_t *gps_store);
|
||||
void gps_loop(void *pvParameters);
|
||||
time_t get_gpstime(gpsStatus_t value);
|
||||
time_t fetch_gpsTime(gpsStatus_t value);
|
||||
int gps_config();
|
||||
|
||||
#endif
|
@ -195,16 +195,13 @@ void draw_page(time_t t, uint8_t page) {
|
||||
|
||||
// update GPS status (line 2)
|
||||
#if (HAS_GPS)
|
||||
// have we ever got valid gps data?
|
||||
if (gps.passedChecksum() > 0) {
|
||||
u8x8.setCursor(9, 2);
|
||||
if (!gps.location.isValid()) // if no fix then display Sats value inverse
|
||||
{
|
||||
if (gps.location.age() < 1500) // if no fix then display Sats value inverse
|
||||
u8x8.printf("Sats:%.2d", gps.satellites.value());
|
||||
else {
|
||||
u8x8.setInverseFont(1);
|
||||
u8x8.printf("Sats:%.2d", gps.satellites.value());
|
||||
u8x8.setInverseFont(0);
|
||||
} else
|
||||
u8x8.printf("Sats:%.2d", gps.satellites.value());
|
||||
}
|
||||
#endif
|
||||
|
||||
@ -252,12 +249,11 @@ void draw_page(time_t t, uint8_t page) {
|
||||
u8x8.setInverseFont(1);
|
||||
u8x8.printf("%c", timeState);
|
||||
u8x8.setInverseFont(0);
|
||||
u8x8.printf(" %2d.%3s", day(t), printmonth[month(t)]);
|
||||
#else
|
||||
u8x8.printf("%02d:%02d:%02d%c %2d.%3s", hour(t), minute(t), second(t),
|
||||
timeState, day(t), printmonth[month(t)]);
|
||||
u8x8.printf("%02d:%02d:%02d%c", hour(t), minute(t), second(t), timeState);
|
||||
#endif // HAS_DCF77 || HAS_IF482
|
||||
|
||||
if (timeSource != _unsynced)
|
||||
u8x8.printf(" %2d.%3s", day(t), printmonth[month(t)]);
|
||||
#else // update LoRa status display
|
||||
#if (HAS_LORA)
|
||||
u8x8.printf("%-16s", display_line6);
|
||||
|
@ -66,53 +66,50 @@ int gps_config() {
|
||||
}
|
||||
|
||||
// store current GPS location data in struct
|
||||
void gps_storelocation(gpsStatus_t &gps_store) {
|
||||
gps_store.latitude = (int32_t)(gps.location.lat() * 1e6);
|
||||
gps_store.longitude = (int32_t)(gps.location.lng() * 1e6);
|
||||
gps_store.satellites = (uint8_t)gps.satellites.value();
|
||||
gps_store.hdop = (uint16_t)gps.hdop.value();
|
||||
gps_store.altitude = (int16_t)gps.altitude.meters();
|
||||
void gps_storelocation(gpsStatus_t *gps_store) {
|
||||
if (gps.location.isUpdated() && gps.location.isValid() &&
|
||||
(gps.time.age() < 1500)) {
|
||||
gps_store->latitude = (int32_t)(gps.location.lat() * 1e6);
|
||||
gps_store->longitude = (int32_t)(gps.location.lng() * 1e6);
|
||||
gps_store->satellites = (uint8_t)gps.satellites.value();
|
||||
gps_store->hdop = (uint16_t)gps.hdop.value();
|
||||
gps_store->altitude = (int16_t)gps.altitude.meters();
|
||||
}
|
||||
}
|
||||
|
||||
// store current GPS timedate in struct
|
||||
void IRAM_ATTR gps_storetime(gpsStatus_t &gps_store) {
|
||||
void IRAM_ATTR gps_storetime(gpsStatus_t *gps_store) {
|
||||
|
||||
if (gps.time.isUpdated() && gps.date.isValid() && (gps.time.age() < 1000)) {
|
||||
|
||||
// nmea telegram serial delay compensation; not sure if we need this?
|
||||
/*
|
||||
if (gps.time.age() > nmea_txDelay_ms)
|
||||
gps_store.timedate.Second = gps.time.second() + 1;
|
||||
gps_store->timedate.Second = gps.time.second() + 1;
|
||||
else
|
||||
gps_store.timedate.Second = gps.time.second();
|
||||
gps_store->timedate.Second = gps.time.second();
|
||||
*/
|
||||
|
||||
gps_store.timedate.Second = gps.time.second();
|
||||
gps_store.timedate.Minute = gps.time.minute();
|
||||
gps_store.timedate.Hour = gps.time.hour();
|
||||
gps_store.timedate.Day = gps.date.day();
|
||||
gps_store.timedate.Month = gps.date.month();
|
||||
gps_store.timedate.Year =
|
||||
gps_store->timedate.Second = gps.time.second();
|
||||
gps_store->timedate.Minute = gps.time.minute();
|
||||
gps_store->timedate.Hour = gps.time.hour();
|
||||
gps_store->timedate.Day = gps.date.day();
|
||||
gps_store->timedate.Month = gps.date.month();
|
||||
gps_store->timedate.Year =
|
||||
CalendarYrToTm(gps.date.year()); // year offset from 1970 in microTime.h
|
||||
|
||||
} else
|
||||
gps_store.timedate = {0};
|
||||
gps_store->timedate = {0};
|
||||
}
|
||||
|
||||
// function to fetch current time from struct; note: this is costly
|
||||
time_t get_gpstime(gpsStatus_t value) {
|
||||
time_t fetch_gpsTime(gpsStatus_t value) {
|
||||
|
||||
time_t t = timeIsValid(makeTime(value.timedate));
|
||||
|
||||
// show NMEA data in debug mode, useful for debugging GPS
|
||||
ESP_LOGD(
|
||||
TAG,
|
||||
"GPS time: %d | GPS NMEA data: passed %d / failed: %d / with fix: %d", t,
|
||||
gps.passedChecksum(), gps.failedChecksum(), gps.sentencesWithFix());
|
||||
|
||||
ESP_LOGD(TAG, "GPS time: %d", t);
|
||||
return t;
|
||||
|
||||
} // get_gpstime()
|
||||
} // fetch_gpsTime()
|
||||
|
||||
// GPS serial feed FreeRTos Task
|
||||
void gps_loop(void *pvParameters) {
|
||||
@ -136,6 +133,11 @@ void gps_loop(void *pvParameters) {
|
||||
#endif
|
||||
} // if
|
||||
|
||||
// show NMEA data in verbose mode, useful for debugging GPS
|
||||
ESP_LOGV(TAG, "GPS NMEA data: passed %d / failed: %d / with fix: %d",
|
||||
gps.passedChecksum(), gps.failedChecksum(),
|
||||
gps.sentencesWithFix());
|
||||
|
||||
delay(2); // yield to CPU
|
||||
|
||||
} // end of infinite loop
|
||||
|
@ -48,7 +48,7 @@ void irqHandler(void *pvParameters) {
|
||||
// gps refresh buffer?
|
||||
#if (HAS_GPS)
|
||||
if (InterruptStatus & GPS_IRQ)
|
||||
gps_storelocation(gps_status);
|
||||
gps_storelocation(&gps_status);
|
||||
#endif
|
||||
|
||||
// are cyclic tasks due?
|
||||
|
@ -438,6 +438,11 @@ void setup() {
|
||||
#warning you did not specify a time source, time will not be synched
|
||||
#endif
|
||||
|
||||
// initialize gps time
|
||||
#if (HAS_GPS)
|
||||
gps_storetime(&gps_status);
|
||||
#endif
|
||||
|
||||
#if (defined HAS_IF482 || defined HAS_DCF77)
|
||||
ESP_LOGI(TAG, "Starting Clock Controller...");
|
||||
clock_init();
|
||||
|
@ -18,10 +18,6 @@ const char timeSetSymbols[] = {'G', 'R', 'L', '?'};
|
||||
HardwareSerial IF482(2); // use UART #2 (#1 may be in use for serial GPS)
|
||||
#endif
|
||||
|
||||
#if (HAS_GPS)
|
||||
static gpsStatus_t gps_pps_status;
|
||||
#endif
|
||||
|
||||
Ticker timesyncer;
|
||||
|
||||
void timeSync() { xTaskNotify(irqHandlerTask, TIMESYNC_IRQ, eSetBits); }
|
||||
@ -32,7 +28,7 @@ time_t timeProvider(void) {
|
||||
|
||||
#if (HAS_GPS)
|
||||
// fetch recent time from last NMEA record
|
||||
t = get_gpstime(gps_pps_status);
|
||||
t = fetch_gpsTime(gps_status);
|
||||
if (t) {
|
||||
#ifdef HAS_RTC
|
||||
set_rtctime(t, do_mutex); // calibrate RTC
|
||||
@ -44,7 +40,7 @@ time_t timeProvider(void) {
|
||||
}
|
||||
#endif
|
||||
|
||||
// no GPS -> fallback to RTC time while trying lora sync
|
||||
// no time from GPS -> fallback to RTC time while trying lora sync
|
||||
#ifdef HAS_RTC
|
||||
t = get_rtctime();
|
||||
if (t) {
|
||||
@ -123,11 +119,6 @@ void timepulse_start(void) {
|
||||
timerAlarmEnable(ppsIRQ);
|
||||
#endif
|
||||
|
||||
// initialize gps time
|
||||
#if (HAS_GPS)
|
||||
gps_storetime(gps_pps_status);
|
||||
#endif
|
||||
|
||||
// start cyclic time sync
|
||||
timeSync(); // init systime by RTC or GPS or LORA
|
||||
timesyncer.attach(TIME_SYNC_INTERVAL * 60, timeSync);
|
||||
@ -142,9 +133,7 @@ void IRAM_ATTR CLOCKIRQ(void) {
|
||||
|
||||
// store recent gps time, and try to get gps time if time is not synced
|
||||
#if (HAS_GPS)
|
||||
gps_storetime(gps_pps_status);
|
||||
if (timeSource == _unsynced)
|
||||
timeSync();
|
||||
gps_storetime(&gps_status);
|
||||
#endif
|
||||
|
||||
// advance wall clock, if we have
|
||||
|
Loading…
Reference in New Issue
Block a user