GPS fixes & code sanitization

This commit is contained in:
Verkehrsrot 2019-07-28 23:51:24 +02:00
parent e8521094b8
commit 4973568546
6 changed files with 49 additions and 57 deletions

View File

@ -18,10 +18,10 @@ extern gpsStatus_t
extern TaskHandle_t GpsTask; extern TaskHandle_t GpsTask;
int gps_init(void); int gps_init(void);
void IRAM_ATTR gps_storetime(gpsStatus_t &gps_store); void IRAM_ATTR gps_storetime(gpsStatus_t *gps_store);
void gps_storelocation(gpsStatus_t &gps_store); void gps_storelocation(gpsStatus_t *gps_store);
void gps_loop(void *pvParameters); void gps_loop(void *pvParameters);
time_t get_gpstime(gpsStatus_t value); time_t fetch_gpsTime(gpsStatus_t value);
int gps_config(); int gps_config();
#endif #endif

View File

@ -195,16 +195,13 @@ void draw_page(time_t t, uint8_t page) {
// update GPS status (line 2) // update GPS status (line 2)
#if (HAS_GPS) #if (HAS_GPS)
// have we ever got valid gps data? u8x8.setCursor(9, 2);
if (gps.passedChecksum() > 0) { if (gps.location.age() < 1500) // if no fix then display Sats value inverse
u8x8.setCursor(9, 2); u8x8.printf("Sats:%.2d", gps.satellites.value());
if (!gps.location.isValid()) // if no fix then display Sats value inverse else {
{ u8x8.setInverseFont(1);
u8x8.setInverseFont(1); u8x8.printf("Sats:%.2d", gps.satellites.value());
u8x8.printf("Sats:%.2d", gps.satellites.value()); u8x8.setInverseFont(0);
u8x8.setInverseFont(0);
} else
u8x8.printf("Sats:%.2d", gps.satellites.value());
} }
#endif #endif
@ -252,12 +249,11 @@ void draw_page(time_t t, uint8_t page) {
u8x8.setInverseFont(1); u8x8.setInverseFont(1);
u8x8.printf("%c", timeState); u8x8.printf("%c", timeState);
u8x8.setInverseFont(0); u8x8.setInverseFont(0);
u8x8.printf(" %2d.%3s", day(t), printmonth[month(t)]);
#else #else
u8x8.printf("%02d:%02d:%02d%c %2d.%3s", hour(t), minute(t), second(t), u8x8.printf("%02d:%02d:%02d%c", hour(t), minute(t), second(t), timeState);
timeState, day(t), printmonth[month(t)]);
#endif // HAS_DCF77 || HAS_IF482 #endif // HAS_DCF77 || HAS_IF482
if (timeSource != _unsynced)
u8x8.printf(" %2d.%3s", day(t), printmonth[month(t)]);
#else // update LoRa status display #else // update LoRa status display
#if (HAS_LORA) #if (HAS_LORA)
u8x8.printf("%-16s", display_line6); u8x8.printf("%-16s", display_line6);

View File

@ -66,53 +66,50 @@ int gps_config() {
} }
// store current GPS location data in struct // store current GPS location data in struct
void gps_storelocation(gpsStatus_t &gps_store) { void gps_storelocation(gpsStatus_t *gps_store) {
gps_store.latitude = (int32_t)(gps.location.lat() * 1e6); if (gps.location.isUpdated() && gps.location.isValid() &&
gps_store.longitude = (int32_t)(gps.location.lng() * 1e6); (gps.time.age() < 1500)) {
gps_store.satellites = (uint8_t)gps.satellites.value(); gps_store->latitude = (int32_t)(gps.location.lat() * 1e6);
gps_store.hdop = (uint16_t)gps.hdop.value(); gps_store->longitude = (int32_t)(gps.location.lng() * 1e6);
gps_store.altitude = (int16_t)gps.altitude.meters(); 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 // 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)) { if (gps.time.isUpdated() && gps.date.isValid() && (gps.time.age() < 1000)) {
// nmea telegram serial delay compensation; not sure if we need this? // nmea telegram serial delay compensation; not sure if we need this?
/* /*
if (gps.time.age() > nmea_txDelay_ms) if (gps.time.age() > nmea_txDelay_ms)
gps_store.timedate.Second = gps.time.second() + 1; gps_store->timedate.Second = gps.time.second() + 1;
else 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.Second = gps.time.second();
gps_store.timedate.Minute = gps.time.minute(); gps_store->timedate.Minute = gps.time.minute();
gps_store.timedate.Hour = gps.time.hour(); gps_store->timedate.Hour = gps.time.hour();
gps_store.timedate.Day = gps.date.day(); gps_store->timedate.Day = gps.date.day();
gps_store.timedate.Month = gps.date.month(); gps_store->timedate.Month = gps.date.month();
gps_store.timedate.Year = gps_store->timedate.Year =
CalendarYrToTm(gps.date.year()); // year offset from 1970 in microTime.h CalendarYrToTm(gps.date.year()); // year offset from 1970 in microTime.h
} else } else
gps_store.timedate = {0}; gps_store->timedate = {0};
} }
// function to fetch current time from struct; note: this is costly // 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)); time_t t = timeIsValid(makeTime(value.timedate));
ESP_LOGD(TAG, "GPS time: %d", t);
// 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());
return t; return t;
} // get_gpstime() } // fetch_gpsTime()
// GPS serial feed FreeRTos Task // GPS serial feed FreeRTos Task
void gps_loop(void *pvParameters) { void gps_loop(void *pvParameters) {
@ -136,6 +133,11 @@ void gps_loop(void *pvParameters) {
#endif #endif
} // if } // 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 delay(2); // yield to CPU
} // end of infinite loop } // end of infinite loop

View File

@ -48,7 +48,7 @@ void irqHandler(void *pvParameters) {
// gps refresh buffer? // gps refresh buffer?
#if (HAS_GPS) #if (HAS_GPS)
if (InterruptStatus & GPS_IRQ) if (InterruptStatus & GPS_IRQ)
gps_storelocation(gps_status); gps_storelocation(&gps_status);
#endif #endif
// are cyclic tasks due? // are cyclic tasks due?

View File

@ -438,6 +438,11 @@ void setup() {
#warning you did not specify a time source, time will not be synched #warning you did not specify a time source, time will not be synched
#endif #endif
// initialize gps time
#if (HAS_GPS)
gps_storetime(&gps_status);
#endif
#if (defined HAS_IF482 || defined HAS_DCF77) #if (defined HAS_IF482 || defined HAS_DCF77)
ESP_LOGI(TAG, "Starting Clock Controller..."); ESP_LOGI(TAG, "Starting Clock Controller...");
clock_init(); clock_init();

View File

@ -18,10 +18,6 @@ const char timeSetSymbols[] = {'G', 'R', 'L', '?'};
HardwareSerial IF482(2); // use UART #2 (#1 may be in use for serial GPS) HardwareSerial IF482(2); // use UART #2 (#1 may be in use for serial GPS)
#endif #endif
#if (HAS_GPS)
static gpsStatus_t gps_pps_status;
#endif
Ticker timesyncer; Ticker timesyncer;
void timeSync() { xTaskNotify(irqHandlerTask, TIMESYNC_IRQ, eSetBits); } void timeSync() { xTaskNotify(irqHandlerTask, TIMESYNC_IRQ, eSetBits); }
@ -32,7 +28,7 @@ time_t timeProvider(void) {
#if (HAS_GPS) #if (HAS_GPS)
// fetch recent time from last NMEA record // fetch recent time from last NMEA record
t = get_gpstime(gps_pps_status); t = fetch_gpsTime(gps_status);
if (t) { if (t) {
#ifdef HAS_RTC #ifdef HAS_RTC
set_rtctime(t, do_mutex); // calibrate RTC set_rtctime(t, do_mutex); // calibrate RTC
@ -44,7 +40,7 @@ time_t timeProvider(void) {
} }
#endif #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 #ifdef HAS_RTC
t = get_rtctime(); t = get_rtctime();
if (t) { if (t) {
@ -123,11 +119,6 @@ void timepulse_start(void) {
timerAlarmEnable(ppsIRQ); timerAlarmEnable(ppsIRQ);
#endif #endif
// initialize gps time
#if (HAS_GPS)
gps_storetime(gps_pps_status);
#endif
// start cyclic time sync // start cyclic time sync
timeSync(); // init systime by RTC or GPS or LORA timeSync(); // init systime by RTC or GPS or LORA
timesyncer.attach(TIME_SYNC_INTERVAL * 60, timeSync); 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 // store recent gps time, and try to get gps time if time is not synced
#if (HAS_GPS) #if (HAS_GPS)
gps_storetime(gps_pps_status); gps_storetime(&gps_status);
if (timeSource == _unsynced)
timeSync();
#endif #endif
// advance wall clock, if we have // advance wall clock, if we have