diff options
author | Eric S. Raymond <esr@thyrsus.com> | 2011-01-19 16:13:21 -0500 |
---|---|---|
committer | Eric S. Raymond <esr@thyrsus.com> | 2011-01-19 16:13:21 -0500 |
commit | f6a463bd47b8f3149a9fdba5e02383ae1bc4e4da (patch) | |
tree | fcdd6cee9a0ecf757fe02263c925b86fbb50cd95 | |
parent | 181a455552c3274c29f789b7cba1cd5185261b1f (diff) | |
download | gpsd-f6a463bd47b8f3149a9fdba5e02383ae1bc4e4da.tar.gz |
Generate coefficients for least-squares fit into the C code.
-rw-r--r-- | .gitignore | 1 | ||||
-rw-r--r-- | Makefile.am | 9 | ||||
-rw-r--r-- | leapcheck.i | 33 | ||||
-rwxr-xr-x | leapsecond.py | 41 | ||||
-rw-r--r-- | rollover.c | 2 |
5 files changed, 50 insertions, 36 deletions
@@ -62,6 +62,7 @@ gpsd_config.h.in gpsd_config.h packet_names.h revision.h +leapcheck.h gpsd.spec MANIFEST .kdbgrc.* diff --git a/Makefile.am b/Makefile.am index 78915549..93e9e2e4 100644 --- a/Makefile.am +++ b/Makefile.am @@ -209,7 +209,7 @@ libgpsd_h_sources = \ libgpsd_la_LDFLAGS = $(LIBUSB_LIBS) $(BLUEZ_LIBS) -BUILT_SOURCES = packet_names.h gpsd.h revision.h ais_json.i gps_maskdump.c gpsd_maskdump.c +BUILT_SOURCES = packet_names.h gpsd.h revision.h ais_json.i gps_maskdump.c gpsd_maskdump.c leapcheck.h packet_names.h: packet_states.h rm -f packet_names.h && \ @@ -244,14 +244,17 @@ gpsd_maskdump.c: gpsd.h maskaudit.py $(PYTHON) maskaudit.py -d >gpsd_maskdump.c && \ chmod a-w gpsd_maskdump.c +leapcheck.h: leapsecond.py #leapcheck.i + $(PYTHON) leapsecond.py -h leapcheck.i >leapcheck.h + # This gets kept in the repo so we can build without Internet access leapcheck.i: leapsecond.py - $(PYTHON) leapsecond.py -c leapcheck.i + $(PYTHON) leapsecond.py -f leapcheck.i libgps_la_SOURCES = $(libgps_c_sources) libgpsd_la_SOURCES = $(libgpsd_c_sources) $(libgpsd_h_sources) \ - driver_rtcm2.h packet_states.h + driver_rtcm2.h packet_states.h leapcheck.h # Warning: This overrides autoconf's normal link-line generation process if LIBGPSMM_ENABLE diff --git a/leapcheck.i b/leapcheck.i index 23015092..0c01c93c 100644 --- a/leapcheck.i +++ b/leapcheck.i @@ -1,17 +1,16 @@ - 315550800.0, // 31 Dec 1979 23:59:60 -> 0 - 362807999.0, // 30 Jun 1981 23:59:59 -> 1 - 394343999.0, // 30 Jun 1982 23:59:59 -> 2 - 425879999.0, // 30 Jun 1983 23:59:59 -> 3 - 489038399.0, // 30 Jun 1985 23:59:59 -> 4 - 568011600.0, // 31 Dec 1987 23:59:60 -> 5 - 631170000.0, // 31 Dec 1989 23:59:60 -> 6 - 662706000.0, // 31 Dec 1990 23:59:60 -> 7 - 709963199.0, // 30 Jun 1992 23:59:59 -> 8 - 741499199.0, // 30 Jun 1993 23:59:59 -> 9 - 773035199.0, // 30 Jun 1994 23:59:59 -> 10 - 820472400.0, // 31 Dec 1995 23:59:60 -> 11 - 867729599.0, // 30 Jun 1997 23:59:59 -> 12 - 915166800.0, // 31 Dec 1998 23:59:60 -> 13 - 1136091600.0, // 31 Dec 2005 23:59:60 -> 14 - 1230786000.0, // 31 Dec 2008 23:59:60 -> 15 - 1295350796.0, // 18 Jan 2011 06:39:56 -> ? +315550800.0 +362807999.0 +394343999.0 +425879999.0 +489038399.0 +568011600.0 +631170000.0 +662706000.0 +709963199.0 +741499199.0 +773035199.0 +820472400.0 +867729599.0 +915166800.0 +1136091600.0 +1230786000.0 diff --git a/leapsecond.py b/leapsecond.py index c8f1b509..bdcd84c8 100755 --- a/leapsecond.py +++ b/leapsecond.py @@ -110,29 +110,23 @@ def get(): return current_offset def save_leapseconds(outfile): - "Fetch the USNO leap-second history data and makw a leap-second list." + "Fetch the USNO leap-second history data and make a leap-second list." skip = True leapsecs = [] # This code assumes that after 1980, leap-second increments are # always integrally one second and every increment is listed here leapsecs = [] try: + fp = open(outfile, "w") for line in urllib.urlopen("ftp://maia.usno.navy.mil/ser7/tai-utc.dat"): if line.startswith(" 1980"): skip = False if skip: continue fields = line.strip().split() - leapsecs.append(leapbound(fields[0], fields[1])) - leapsecs.append(unix_to_rfc822(time.time())) # Add sentinel - def label(i): - if i == len(leapsecs) - 1: - return '?' - else: - return str(i) - with open(outfile, "w") as fp: - for (i, b) in enumerate(leapsecs): - fp.write(" %s, // %s -> %s\n" % (rfc822_to_unix(b), b, label(i))) + md = leapbound(fields[0], fields[1]) + fp.write(repr(rfc822_to_unix(md)) + "\n") + fp.close() except IOError: print >>sys.stderr, "Fetch from USNO failed, %s not updated." % outfile @@ -140,10 +134,24 @@ def fetch_leapsecs(filename): "Get a list of leap seconds from the local cache of the USNO history" leapsecs = [] with open(filename) as fp: - leapsecs = map(lambda x: int(x.split(',')[0][:-2]), fp.readlines()) - leapsecs.pop() # Remove the sentinel entry + leapsecs = map(lambda x: float(x.strip()), fp.readlines()) return leapsecs +def make_leapsecond_include(infile): + leapsecs = fetch_leapsecs(infile) + leapsecs.append(time.time()) # Add sentinel + (b, c, e) = leastsquares(zip(range(len(leapsecs)), leapsecs)) + def label(i): + if i == len(leapsecs) - 1: + return '?' + else: + return str(i) + for (i, b) in enumerate(leapsecs): + sys.stdout.write(" %s, // %s -> %s\n" % (b, unix_to_rfc822(b), label(i))) + sys.stdout.write("#define LEAPSECOND_B\t%s\n" % b) + sys.stdout.write("#define LEAPSECOND_C\t%s\n" % c) + sys.stdout.write("#define LEAPSECOND_E\t%s\n" % e) + def leastsquares(tuples): "Generate coefficients for a least-squares fit to the specified data." sum_x=0 @@ -238,14 +246,17 @@ def leapbound(year, month): if __name__ == '__main__': import sys, getopt - (options, arguments) = getopt.getopt(sys.argv[1:], "c:g:i:n:o:") + (options, arguments) = getopt.getopt(sys.argv[1:], "f:g:h:i:n:o:") for (switch, val) in options: - if (switch == '-c'): # Generate C initializer listing leap seconds + if (switch == '-f'): # Fetch USNO data to cache locally save_leapseconds(val) raise SystemExit, 0 elif (switch == '-g'): # Graph the leap_second history graph_history(val) raise SystemExit, 0 + elif (switch == '-h'): # make leapsecond include + make_leapsecond_include(val) + raise SystemExit, 0 elif (switch == '-i'): # Compute Unix time from RFC822 date print "#define FOO %d /* %s */" % (rfc822_to_unix(val), val) raise SystemExit, 0 @@ -98,7 +98,7 @@ static int gpsd_check_utc(const int leap, const double unixtime) /* consistency-check a GPS-reported UTC against a leap second */ { static double c_epochs[] = { -#include "leapcheck.i" +#include "leapcheck.h" }; #define DIM(a) (int)(sizeof(a)/sizeof(a[0])) |