|
|
@@ -265,6 +265,12 @@ void beep (UINT len, BYTE cnt)
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+/* Number of consecutive epochs (nmea_epoch_complete() pulses) a new
|
|
|
+ * fix-acquired/lost state must hold before it's logged - coalesces the rapid
|
|
|
+ * flapping seen on marginal reception (e.g. 2D/3D/no-fix alternating for
|
|
|
+ * about a minute) into at most one or two log lines instead of one per flip. */
|
|
|
+#define FIX_HOLD_EPOCHS 5
|
|
|
+
|
|
|
#define LOG_SIZE 300
|
|
|
|
|
|
struct {
|
|
|
@@ -423,6 +429,7 @@ int main (void)
|
|
|
unsigned char prev_status;
|
|
|
unsigned char already_logging = 0;
|
|
|
static unsigned char fix_ok_prev = 0;
|
|
|
+ static unsigned char fix_hold_counter = 0;
|
|
|
static unsigned char sbas_prev = 0xFF; /* 0xFF: not yet known, suppress the first (non-)transition */
|
|
|
static unsigned long int last_summary_uptime = 0;
|
|
|
|
|
|
@@ -542,15 +549,23 @@ int main (void)
|
|
|
if (System.bat_volt > 0 && System.bat_volt < System.bat_volt_min)
|
|
|
System.bat_volt_min = System.bat_volt;
|
|
|
|
|
|
- /* Fix acquired/lost events (a "fix" requires both a valid GPS status and enough satellites) */
|
|
|
- {
|
|
|
+ /* Fix acquired/lost events (a "fix" requires both a valid GPS status and enough
|
|
|
+ * satellites). Gated on nmea_epoch_complete() so sats=/hdop= are never read from a
|
|
|
+ * stale epoch, and debounced so a single bad epoch on marginal reception doesn't log
|
|
|
+ * a FIX/FIX LOST pair by itself - the new state must hold for FIX_HOLD_EPOCHS epochs. */
|
|
|
+ if (nmea_epoch_complete()) {
|
|
|
unsigned char fix_ok_now = (FLAGS & F_GPSOK) && !System.sat_count_low;
|
|
|
- if (fix_ok_now != fix_ok_prev) {
|
|
|
- if (fix_ok_now)
|
|
|
+ if (fix_ok_now == fix_ok_prev) {
|
|
|
+ fix_hold_counter = 0;
|
|
|
+ } else if (++fix_hold_counter >= FIX_HOLD_EPOCHS) {
|
|
|
+ fix_hold_counter = 0;
|
|
|
+ fix_ok_prev = fix_ok_now;
|
|
|
+ if (fix_ok_now) {
|
|
|
log_fix_event();
|
|
|
- else
|
|
|
+ } else {
|
|
|
log_fix_lost();
|
|
|
- fix_ok_prev = fix_ok_now;
|
|
|
+ request_immediate_sync();
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
|