A GPS disciplined clock
Dependencies: net lpc1768 crypto clock web log
gps/gps.c
- Committer:
- andrewboyson
- Date:
- 2019-10-10
- Revision:
- 75:0ed9157d3bb3
- Parent:
- 65:1412e3a1c5de
- Child:
- 76:bea8fd22bccf
File content as of revision 75:0ed9157d3bb3:
#include <stdint.h> #include <stdbool.h> #include <stdio.h> #include <stdarg.h> #include "log.h" #include "nmea.h" #include "pps.h" #include "clkgov.h" bool GpsTrace = true; bool GpsVerbose = false; void GpsLog(const char *fmt, ...) { if (!GpsTrace) return; va_list argptr; va_start(argptr, fmt); LogTimeF("GPS %04d ", PpsMsSinceLastPulse); LogV(fmt, argptr); va_end(argptr); } void GpsLogVerbose(const char *fmt, ...) { if (!GpsTrace || !GpsVerbose) return; va_list argptr; va_start(argptr, fmt); LogTimeF("GPS %04d ", PpsMsSinceLastPulse); LogV(fmt, argptr); va_end(argptr); } void GpsHadPps() { NmeaTimeAlign(); if (PpsIsStable() && NmeaFixIsStable() && NmeaModuleIsReady()) { if (NmeaTimeIsStable()) ClkGovSyncPpsN(NmeaTime); //Synchronise to Nmea time else ClkGovSyncPpsZ(); //Synchronise to nearest second of existing clock time } } static void mainConfidence() { ClkGovIsReceivingTime = PpsIsStable() && NmeaFixIsStable() && NmeaModuleIsReady(); //Tell the clock gov module if confident static bool wasStable = false; if (ClkGovIsReceivingTime && !wasStable) GpsLog("PPS and NMEA are stable - sync enabled\r\n"); wasStable = ClkGovIsReceivingTime; } void GpsMain() { NmeaMain(); PpsMain(); NmeaTimeAllowMessages = PpsIsStable(); mainConfidence(); } void GpsInit() { NmeaInit(); PpsInit(); }