From bdab5265fcbf3f472545073a23f8999749a9f2b9 Mon Sep 17 00:00:00 2001 From: Lorry Tar Creator Date: Tue, 2 Dec 2014 09:01:21 +0000 Subject: Imported from /home/lorry/working-area/delta_ntp/ntp-dev-4.2.7p482.tar.gz. --- clockstuff/Makefile.am | 17 + clockstuff/Makefile.in | 749 ++++++++++++++++++++++++++++++++++++++++++++ clockstuff/README | 21 ++ clockstuff/chutest.c | 821 +++++++++++++++++++++++++++++++++++++++++++++++++ clockstuff/propdelay.c | 548 +++++++++++++++++++++++++++++++++ 5 files changed, 2156 insertions(+) create mode 100644 clockstuff/Makefile.am create mode 100644 clockstuff/Makefile.in create mode 100644 clockstuff/README create mode 100644 clockstuff/chutest.c create mode 100644 clockstuff/propdelay.c (limited to 'clockstuff') diff --git a/clockstuff/Makefile.am b/clockstuff/Makefile.am new file mode 100644 index 0000000..d909fbf --- /dev/null +++ b/clockstuff/Makefile.am @@ -0,0 +1,17 @@ +noinst_PROGRAMS = @PROPDELAY@ @CHUTEST@ +EXTRA_PROGRAMS = propdelay chutest + +AM_CFLAGS = $(CFLAGS_NTP) + +AM_CPPFLAGS = $(NTP_INCS) +AM_CPPFLAGS += $(CPPFLAGS_NTP) + +LDADD = ../libntp/libntp.a $(LDADD_LIBNTP) $(LIBM) $(PTHREAD_LIBS) +propdelay_LDADD = $(LDADD) + +BUILT_SOURCES = +CLEANFILES = + +include $(top_srcdir)/sntp/check-libntp.mf +include $(top_srcdir)/depsver.mf +include $(top_srcdir)/includes.mf diff --git a/clockstuff/Makefile.in b/clockstuff/Makefile.in new file mode 100644 index 0000000..179c98d --- /dev/null +++ b/clockstuff/Makefile.in @@ -0,0 +1,749 @@ +# Makefile.in generated by automake 1.11.1 from Makefile.am. +# @configure_input@ + +# Copyright (C) 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, +# 2003, 2004, 2005, 2006, 2007, 2008, 2009 Free Software Foundation, +# Inc. +# This Makefile.in is free software; the Free Software Foundation +# gives unlimited permission to copy and/or distribute it, +# with or without modifications, as long as this notice is preserved. + +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY, to the extent permitted by law; without +# even the implied warranty of MERCHANTABILITY or FITNESS FOR A +# PARTICULAR PURPOSE. + +@SET_MAKE@ + +VPATH = @srcdir@ +pkgdatadir = $(datadir)/@PACKAGE@ +pkgincludedir = $(includedir)/@PACKAGE@ +pkglibdir = $(libdir)/@PACKAGE@ +pkglibexecdir = $(libexecdir)/@PACKAGE@ +am__cd = CDPATH="$${ZSH_VERSION+.}$(PATH_SEPARATOR)" && cd +install_sh_DATA = $(install_sh) -c -m 644 +install_sh_PROGRAM = $(install_sh) -c +install_sh_SCRIPT = $(install_sh) -c +INSTALL_HEADER = $(INSTALL_DATA) +transform = $(program_transform_name) +NORMAL_INSTALL = : +PRE_INSTALL = : +POST_INSTALL = : +NORMAL_UNINSTALL = : +PRE_UNINSTALL = : +POST_UNINSTALL = : +build_triplet = @build@ +host_triplet = @host@ +EXTRA_PROGRAMS = propdelay$(EXEEXT) chutest$(EXEEXT) +DIST_COMMON = README $(srcdir)/Makefile.am $(srcdir)/Makefile.in \ + $(top_srcdir)/depsver.mf $(top_srcdir)/includes.mf \ + $(top_srcdir)/sntp/check-libntp.mf +subdir = clockstuff +ACLOCAL_M4 = $(top_srcdir)/aclocal.m4 +am__aclocal_m4_deps = $(top_srcdir)/sntp/libopts/m4/libopts.m4 \ + $(top_srcdir)/sntp/libopts/m4/stdnoreturn.m4 \ + $(top_srcdir)/sntp/libevent/m4/openldap-thread-check.m4 \ + $(top_srcdir)/sntp/libevent/m4/openldap.m4 \ + $(top_srcdir)/sntp/m4/define_dir.m4 \ + $(top_srcdir)/sntp/m4/hms_search_lib.m4 \ + $(top_srcdir)/sntp/m4/libtool.m4 \ + $(top_srcdir)/sntp/m4/ltoptions.m4 \ + $(top_srcdir)/sntp/m4/ltsugar.m4 \ + $(top_srcdir)/sntp/m4/ltversion.m4 \ + $(top_srcdir)/sntp/m4/lt~obsolete.m4 \ + $(top_srcdir)/sntp/m4/ntp_cacheversion.m4 \ + $(top_srcdir)/sntp/m4/ntp_compiler.m4 \ + $(top_srcdir)/sntp/m4/ntp_crosscompile.m4 \ + $(top_srcdir)/sntp/m4/ntp_debug.m4 \ + $(top_srcdir)/sntp/m4/ntp_dir_sep.m4 \ + $(top_srcdir)/sntp/m4/ntp_facilitynames.m4 \ + $(top_srcdir)/sntp/m4/ntp_googletest.m4 \ + $(top_srcdir)/sntp/m4/ntp_ipv6.m4 \ + $(top_srcdir)/sntp/m4/ntp_lib_m.m4 \ + $(top_srcdir)/sntp/m4/ntp_libevent.m4 \ + $(top_srcdir)/sntp/m4/ntp_libntp.m4 \ + $(top_srcdir)/sntp/m4/ntp_lineeditlibs.m4 \ + $(top_srcdir)/sntp/m4/ntp_locinfo.m4 \ + $(top_srcdir)/sntp/m4/ntp_openssl.m4 \ + $(top_srcdir)/sntp/m4/ntp_pkg_config.m4 \ + $(top_srcdir)/sntp/m4/ntp_prog_cc.m4 \ + $(top_srcdir)/sntp/m4/ntp_rlimit.m4 \ + $(top_srcdir)/sntp/m4/ntp_sntp.m4 \ + $(top_srcdir)/sntp/m4/ntp_ver_suffix.m4 \ + $(top_srcdir)/sntp/m4/ntp_vpathhack.m4 \ + $(top_srcdir)/sntp/m4/os_cflags.m4 \ + $(top_srcdir)/sntp/m4/snprintf.m4 \ + $(top_srcdir)/sntp/m4/version.m4 $(top_srcdir)/configure.ac +am__configure_deps = $(am__aclocal_m4_deps) $(CONFIGURE_DEPENDENCIES) \ + $(ACLOCAL_M4) +mkinstalldirs = $(install_sh) -d +CONFIG_HEADER = $(top_builddir)/config.h +CONFIG_CLEAN_FILES = +CONFIG_CLEAN_VPATH_FILES = +PROGRAMS = $(noinst_PROGRAMS) +chutest_SOURCES = chutest.c +chutest_OBJECTS = chutest.$(OBJEXT) +chutest_LDADD = $(LDADD) +am__DEPENDENCIES_1 = +chutest_DEPENDENCIES = ../libntp/libntp.a $(am__DEPENDENCIES_1) \ + $(am__DEPENDENCIES_1) $(am__DEPENDENCIES_1) +AM_V_lt = $(am__v_lt_$(V)) +am__v_lt_ = $(am__v_lt_$(AM_DEFAULT_VERBOSITY)) +am__v_lt_0 = --silent +propdelay_SOURCES = propdelay.c +propdelay_OBJECTS = propdelay.$(OBJEXT) +am__DEPENDENCIES_2 = ../libntp/libntp.a $(am__DEPENDENCIES_1) \ + $(am__DEPENDENCIES_1) $(am__DEPENDENCIES_1) +propdelay_DEPENDENCIES = $(am__DEPENDENCIES_2) +DEFAULT_INCLUDES = -I.@am__isrc@ -I$(top_builddir) +depcomp = $(SHELL) $(top_srcdir)/sntp/libevent/build-aux/depcomp +am__depfiles_maybe = depfiles +am__mv = mv -f +COMPILE = $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) \ + $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) +LTCOMPILE = $(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) \ + $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) \ + $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) \ + $(AM_CFLAGS) $(CFLAGS) +AM_V_CC = $(am__v_CC_$(V)) +am__v_CC_ = $(am__v_CC_$(AM_DEFAULT_VERBOSITY)) +am__v_CC_0 = @echo " CC " $@; +AM_V_at = $(am__v_at_$(V)) +am__v_at_ = $(am__v_at_$(AM_DEFAULT_VERBOSITY)) +am__v_at_0 = @ +CCLD = $(CC) +LINK = $(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) \ + $(LIBTOOLFLAGS) --mode=link $(CCLD) $(AM_CFLAGS) $(CFLAGS) \ + $(AM_LDFLAGS) $(LDFLAGS) -o $@ +AM_V_CCLD = $(am__v_CCLD_$(V)) +am__v_CCLD_ = $(am__v_CCLD_$(AM_DEFAULT_VERBOSITY)) +am__v_CCLD_0 = @echo " CCLD " $@; +AM_V_GEN = $(am__v_GEN_$(V)) +am__v_GEN_ = $(am__v_GEN_$(AM_DEFAULT_VERBOSITY)) +am__v_GEN_0 = @echo " GEN " $@; +SOURCES = chutest.c propdelay.c +DIST_SOURCES = chutest.c propdelay.c +ETAGS = etags +CTAGS = ctags +DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST) +ACLOCAL = @ACLOCAL@ +ALLOCA = @ALLOCA@ +AMTAR = @AMTAR@ +AM_DEFAULT_VERBOSITY = @AM_DEFAULT_VERBOSITY@ +AR = @AR@ +AUTOCONF = @AUTOCONF@ +AUTOHEADER = @AUTOHEADER@ +AUTOMAKE = @AUTOMAKE@ +AWK = @AWK@ +CALC_TICKADJ_DB = @CALC_TICKADJ_DB@ +CALC_TICKADJ_DL = @CALC_TICKADJ_DL@ +CALC_TICKADJ_DS = @CALC_TICKADJ_DS@ +CALC_TICKADJ_MS = @CALC_TICKADJ_MS@ +CALC_TICKADJ_NI = @CALC_TICKADJ_NI@ +CC = @CC@ +CCDEPMODE = @CCDEPMODE@ +CFLAGS = @CFLAGS@ +CFLAGS_NTP = @CFLAGS_NTP@ +CHUTEST = @CHUTEST@ +CONFIG_SHELL = @CONFIG_SHELL@ +CPP = @CPP@ +CPPFLAGS = @CPPFLAGS@ +CPPFLAGS_NTP = @CPPFLAGS_NTP@ +CXX = @CXX@ +CXXCPP = @CXXCPP@ +CXXDEPMODE = @CXXDEPMODE@ +CXXFLAGS = @CXXFLAGS@ +CYGPATH_W = @CYGPATH_W@ +DCFD = @DCFD@ +DEFS = @DEFS@ +DEPDIR = @DEPDIR@ +DLLTOOL = @DLLTOOL@ +DSYMUTIL = @DSYMUTIL@ +DUMPBIN = @DUMPBIN@ +ECHO_C = @ECHO_C@ +ECHO_N = @ECHO_N@ +ECHO_T = @ECHO_T@ +EDITLINE_LIBS = @EDITLINE_LIBS@ +EGREP = @EGREP@ +EXEEXT = @EXEEXT@ +FGREP = @FGREP@ +GREP = @GREP@ +GTEST_CONFIG = @GTEST_CONFIG@ +GTEST_CPPFLAGS = @GTEST_CPPFLAGS@ +GTEST_CXXFLAGS = @GTEST_CXXFLAGS@ +GTEST_LDFLAGS = @GTEST_LDFLAGS@ +GTEST_LIBS = @GTEST_LIBS@ +HAVE_INLINE = @HAVE_INLINE@ +HAVE_RLIMIT_MEMLOCK = @HAVE_RLIMIT_MEMLOCK@ +HAVE_RLIMIT_STACK = @HAVE_RLIMIT_STACK@ +INSTALL = @INSTALL@ +INSTALL_DATA = @INSTALL_DATA@ +INSTALL_PROGRAM = @INSTALL_PROGRAM@ +INSTALL_SCRIPT = @INSTALL_SCRIPT@ +INSTALL_STRIP_PROGRAM = @INSTALL_STRIP_PROGRAM@ +LD = @LD@ +LDADD_LIBNTP = @LDADD_LIBNTP@ +LDADD_NLIST = @LDADD_NLIST@ +LDADD_NTP = @LDADD_NTP@ +LDFLAGS = @LDFLAGS@ +LDFLAGS_NTP = @LDFLAGS_NTP@ +LIBISC_PTHREADS_NOTHREADS = @LIBISC_PTHREADS_NOTHREADS@ +LIBM = @LIBM@ +LIBOBJS = @LIBOBJS@ +LIBOPTS_CFLAGS = @LIBOPTS_CFLAGS@ +LIBOPTS_DIR = @LIBOPTS_DIR@ +LIBOPTS_LDADD = @LIBOPTS_LDADD@ +LIBPARSE = @LIBPARSE@ +LIBS = @LIBS@ +LIBTOOL = @LIBTOOL@ +LIBTOOL_DEPS = @LIBTOOL_DEPS@ +LIPO = @LIPO@ +LN_S = @LN_S@ +LSCF = @LSCF@ +LTLIBOBJS = @LTLIBOBJS@ +MAKEINFO = @MAKEINFO@ +MAKE_ADJTIMED = @MAKE_ADJTIMED@ +MAKE_CHECK_LAYOUT = @MAKE_CHECK_LAYOUT@ +MAKE_CHECK_Y2K = @MAKE_CHECK_Y2K@ +MAKE_LIBNTPSIM = @MAKE_LIBNTPSIM@ +MAKE_LIBPARSE = @MAKE_LIBPARSE@ +MAKE_LIBPARSE_KERNEL = @MAKE_LIBPARSE_KERNEL@ +MAKE_NTPDSIM = @MAKE_NTPDSIM@ +MAKE_NTPSNMPD = @MAKE_NTPSNMPD@ +MAKE_NTPTIME = @MAKE_NTPTIME@ +MAKE_PARSEKMODULE = @MAKE_PARSEKMODULE@ +MAKE_TICKADJ = @MAKE_TICKADJ@ +MAKE_TIMETRIM = @MAKE_TIMETRIM@ +MANIFEST_TOOL = @MANIFEST_TOOL@ +MANTAGFMT = @MANTAGFMT@ +MKDIR_P = @MKDIR_P@ +NM = @NM@ +NMEDIT = @NMEDIT@ +NTPDATE_DB = @NTPDATE_DB@ +NTPDATE_DL = @NTPDATE_DL@ +NTPDATE_DS = @NTPDATE_DS@ +NTPDATE_MS = @NTPDATE_MS@ +NTPDATE_NI = @NTPDATE_NI@ +NTPDC_DB = @NTPDC_DB@ +NTPDC_DL = @NTPDC_DL@ +NTPDC_DS = @NTPDC_DS@ +NTPDC_MS = @NTPDC_MS@ +NTPDC_NI = @NTPDC_NI@ +NTPDSIM_DB = @NTPDSIM_DB@ +NTPDSIM_DL = @NTPDSIM_DL@ +NTPDSIM_DS = @NTPDSIM_DS@ +NTPDSIM_MS = @NTPDSIM_MS@ +NTPDSIM_NI = @NTPDSIM_NI@ +NTPD_DB = @NTPD_DB@ +NTPD_DL = @NTPD_DL@ +NTPD_DS = @NTPD_DS@ +NTPD_MS = @NTPD_MS@ +NTPD_NI = @NTPD_NI@ +NTPQ_DB = @NTPQ_DB@ +NTPQ_DL = @NTPQ_DL@ +NTPQ_DS = @NTPQ_DS@ +NTPQ_MS = @NTPQ_MS@ +NTPQ_NI = @NTPQ_NI@ +NTPSNMPD_DB = @NTPSNMPD_DB@ +NTPSNMPD_DL = @NTPSNMPD_DL@ +NTPSNMPD_DS = @NTPSNMPD_DS@ +NTPSNMPD_MS = @NTPSNMPD_MS@ +NTPSNMPD_NI = @NTPSNMPD_NI@ +NTPSWEEP_DB = @NTPSWEEP_DB@ +NTPSWEEP_DL = @NTPSWEEP_DL@ +NTPSWEEP_DS = @NTPSWEEP_DS@ +NTPSWEEP_MS = @NTPSWEEP_MS@ +NTPSWEEP_NI = @NTPSWEEP_NI@ +NTPTIME_DB = @NTPTIME_DB@ +NTPTIME_DL = @NTPTIME_DL@ +NTPTIME_DS = @NTPTIME_DS@ +NTPTIME_MS = @NTPTIME_MS@ +NTPTIME_NI = @NTPTIME_NI@ +NTPTRACE_DB = @NTPTRACE_DB@ +NTPTRACE_DL = @NTPTRACE_DL@ +NTPTRACE_DS = @NTPTRACE_DS@ +NTPTRACE_MS = @NTPTRACE_MS@ +NTPTRACE_NI = @NTPTRACE_NI@ +NTP_KEYGEN_DB = @NTP_KEYGEN_DB@ +NTP_KEYGEN_DL = @NTP_KEYGEN_DL@ +NTP_KEYGEN_DS = @NTP_KEYGEN_DS@ +NTP_KEYGEN_MS = @NTP_KEYGEN_MS@ +NTP_KEYGEN_NI = @NTP_KEYGEN_NI@ +NTP_KEYSDIR = @NTP_KEYSDIR@ +NTP_WAIT_DB = @NTP_WAIT_DB@ +NTP_WAIT_DL = @NTP_WAIT_DL@ +NTP_WAIT_DS = @NTP_WAIT_DS@ +NTP_WAIT_MS = @NTP_WAIT_MS@ +NTP_WAIT_NI = @NTP_WAIT_NI@ +OBJDUMP = @OBJDUMP@ +OBJEXT = @OBJEXT@ +OTOOL = @OTOOL@ +OTOOL64 = @OTOOL64@ +PACKAGE = @PACKAGE@ +PACKAGE_BUGREPORT = @PACKAGE_BUGREPORT@ +PACKAGE_NAME = @PACKAGE_NAME@ +PACKAGE_STRING = @PACKAGE_STRING@ +PACKAGE_TARNAME = @PACKAGE_TARNAME@ +PACKAGE_URL = @PACKAGE_URL@ +PACKAGE_VERSION = @PACKAGE_VERSION@ +PATH_NET_SNMP_CONFIG = @PATH_NET_SNMP_CONFIG@ +PATH_PERL = @PATH_PERL@ +PATH_SEPARATOR = @PATH_SEPARATOR@ +PATH_TEST = @PATH_TEST@ +PERLLIBDIR = @PERLLIBDIR@ +PKG_CONFIG = @PKG_CONFIG@ +POSIX_SHELL = @POSIX_SHELL@ +PROPDELAY = @PROPDELAY@ +PTHREAD_LIBS = @PTHREAD_LIBS@ +RANLIB = @RANLIB@ +SED = @SED@ +SET_MAKE = @SET_MAKE@ +SHELL = @SHELL@ +SNMP_CFLAGS = @SNMP_CFLAGS@ +SNMP_CPPFLAGS = @SNMP_CPPFLAGS@ +SNMP_LIBS = @SNMP_LIBS@ +SNTP = @SNTP@ +SNTP_DB = @SNTP_DB@ +SNTP_DL = @SNTP_DL@ +SNTP_DS = @SNTP_DS@ +SNTP_MS = @SNTP_MS@ +SNTP_NI = @SNTP_NI@ +STDNORETURN_H = @STDNORETURN_H@ +STRIP = @STRIP@ +TESTDCF = @TESTDCF@ +TICKADJ_DB = @TICKADJ_DB@ +TICKADJ_DL = @TICKADJ_DL@ +TICKADJ_DS = @TICKADJ_DS@ +TICKADJ_MS = @TICKADJ_MS@ +TICKADJ_NI = @TICKADJ_NI@ +TIMETRIM_DB = @TIMETRIM_DB@ +TIMETRIM_DL = @TIMETRIM_DL@ +TIMETRIM_DS = @TIMETRIM_DS@ +TIMETRIM_MS = @TIMETRIM_MS@ +TIMETRIM_NI = @TIMETRIM_NI@ +VERSION = @VERSION@ +VER_SUFFIX = @VER_SUFFIX@ +YACC = @YACC@ +YFLAGS = @YFLAGS@ +abs_builddir = @abs_builddir@ +abs_srcdir = @abs_srcdir@ +abs_top_builddir = @abs_top_builddir@ +abs_top_srcdir = @abs_top_srcdir@ +ac_ct_AR = @ac_ct_AR@ +ac_ct_CC = @ac_ct_CC@ +ac_ct_CXX = @ac_ct_CXX@ +ac_ct_DUMPBIN = @ac_ct_DUMPBIN@ +am__include = @am__include@ +am__leading_dot = @am__leading_dot@ +am__quote = @am__quote@ +am__tar = @am__tar@ +am__untar = @am__untar@ +bindir = @bindir@ +build = @build@ +build_alias = @build_alias@ +build_cpu = @build_cpu@ +build_os = @build_os@ +build_vendor = @build_vendor@ +builddir = @builddir@ +datadir = @datadir@ +datarootdir = @datarootdir@ +docdir = @docdir@ +dvidir = @dvidir@ +exec_prefix = @exec_prefix@ +host = @host@ +host_alias = @host_alias@ +host_cpu = @host_cpu@ +host_os = @host_os@ +host_vendor = @host_vendor@ +htmldir = @htmldir@ +includedir = @includedir@ +infodir = @infodir@ +install_sh = @install_sh@ +libdir = @libdir@ +libexecdir = @libexecdir@ +localedir = @localedir@ +localstatedir = @localstatedir@ +mandir = @mandir@ +mkdir_p = @mkdir_p@ +oldincludedir = @oldincludedir@ +pdfdir = @pdfdir@ +prefix = @prefix@ +program_transform_name = @program_transform_name@ +psdir = @psdir@ +sbindir = @sbindir@ +sharedstatedir = @sharedstatedir@ +srcdir = @srcdir@ +subdirs = @subdirs@ +sysconfdir = @sysconfdir@ +target_alias = @target_alias@ +top_build_prefix = @top_build_prefix@ +top_builddir = @top_builddir@ +top_srcdir = @top_srcdir@ +noinst_PROGRAMS = @PROPDELAY@ @CHUTEST@ +AM_CFLAGS = $(CFLAGS_NTP) +AM_CPPFLAGS = $(NTP_INCS) $(CPPFLAGS_NTP) +LDADD = ../libntp/libntp.a $(LDADD_LIBNTP) $(LIBM) $(PTHREAD_LIBS) +propdelay_LDADD = $(LDADD) +BUILT_SOURCES = check-libntp .deps-ver +CLEANFILES = check-libntp .deps-ver +NTP_INCS = -I$(top_srcdir)/include -I$(top_srcdir)/lib/isc/include \ + -I$(top_srcdir)/lib/isc/$(LIBISC_PTHREADS_NOTHREADS)/include \ + -I$(top_srcdir)/lib/isc/unix/include +all: $(BUILT_SOURCES) + $(MAKE) $(AM_MAKEFLAGS) all-am + +.SUFFIXES: +.SUFFIXES: .c .lo .o .obj +$(srcdir)/Makefile.in: $(srcdir)/Makefile.am $(top_srcdir)/sntp/check-libntp.mf $(top_srcdir)/depsver.mf $(top_srcdir)/includes.mf $(am__configure_deps) + @for dep in $?; do \ + case '$(am__configure_deps)' in \ + *$$dep*) \ + ( cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh ) \ + && { if test -f $@; then exit 0; else break; fi; }; \ + exit 1;; \ + esac; \ + done; \ + echo ' cd $(top_srcdir) && $(AUTOMAKE) --foreign clockstuff/Makefile'; \ + $(am__cd) $(top_srcdir) && \ + $(AUTOMAKE) --foreign clockstuff/Makefile +.PRECIOUS: Makefile +Makefile: $(srcdir)/Makefile.in $(top_builddir)/config.status + @case '$?' in \ + *config.status*) \ + cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh;; \ + *) \ + echo ' cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__depfiles_maybe)'; \ + cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__depfiles_maybe);; \ + esac; + +$(top_builddir)/config.status: $(top_srcdir)/configure $(CONFIG_STATUS_DEPENDENCIES) + cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh + +$(top_srcdir)/configure: $(am__configure_deps) + cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh +$(ACLOCAL_M4): $(am__aclocal_m4_deps) + cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh +$(am__aclocal_m4_deps): + +clean-noinstPROGRAMS: + @list='$(noinst_PROGRAMS)'; test -n "$$list" || exit 0; \ + echo " rm -f" $$list; \ + rm -f $$list || exit $$?; \ + test -n "$(EXEEXT)" || exit 0; \ + list=`for p in $$list; do echo "$$p"; done | sed 's/$(EXEEXT)$$//'`; \ + echo " rm -f" $$list; \ + rm -f $$list +chutest$(EXEEXT): $(chutest_OBJECTS) $(chutest_DEPENDENCIES) + @rm -f chutest$(EXEEXT) + $(AM_V_CCLD)$(LINK) $(chutest_OBJECTS) $(chutest_LDADD) $(LIBS) +propdelay$(EXEEXT): $(propdelay_OBJECTS) $(propdelay_DEPENDENCIES) + @rm -f propdelay$(EXEEXT) + $(AM_V_CCLD)$(LINK) $(propdelay_OBJECTS) $(propdelay_LDADD) $(LIBS) + +mostlyclean-compile: + -rm -f *.$(OBJEXT) + +distclean-compile: + -rm -f *.tab.c + +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/chutest.Po@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/propdelay.Po@am__quote@ + +.c.o: +@am__fastdepCC_TRUE@ $(AM_V_CC)$(COMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ $< +@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/$*.Tpo $(DEPDIR)/$*.Po +@am__fastdepCC_FALSE@ $(AM_V_CC) @AM_BACKSLASH@ +@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='$<' object='$@' libtool=no @AMDEPBACKSLASH@ +@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ +@am__fastdepCC_FALSE@ $(COMPILE) -c $< + +.c.obj: +@am__fastdepCC_TRUE@ $(AM_V_CC)$(COMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ `$(CYGPATH_W) '$<'` +@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/$*.Tpo $(DEPDIR)/$*.Po +@am__fastdepCC_FALSE@ $(AM_V_CC) @AM_BACKSLASH@ +@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='$<' object='$@' libtool=no @AMDEPBACKSLASH@ +@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ +@am__fastdepCC_FALSE@ $(COMPILE) -c `$(CYGPATH_W) '$<'` + +.c.lo: +@am__fastdepCC_TRUE@ $(AM_V_CC)$(LTCOMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ $< +@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/$*.Tpo $(DEPDIR)/$*.Plo +@am__fastdepCC_FALSE@ $(AM_V_CC) @AM_BACKSLASH@ +@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='$<' object='$@' libtool=yes @AMDEPBACKSLASH@ +@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ +@am__fastdepCC_FALSE@ $(LTCOMPILE) -c -o $@ $< + +mostlyclean-libtool: + -rm -f *.lo + +clean-libtool: + -rm -rf .libs _libs + +ID: $(HEADERS) $(SOURCES) $(LISP) $(TAGS_FILES) + list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \ + unique=`for i in $$list; do \ + if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \ + done | \ + $(AWK) '{ files[$$0] = 1; nonempty = 1; } \ + END { if (nonempty) { for (i in files) print i; }; }'`; \ + mkid -fID $$unique +tags: TAGS + +TAGS: $(HEADERS) $(SOURCES) $(TAGS_DEPENDENCIES) \ + $(TAGS_FILES) $(LISP) + set x; \ + here=`pwd`; \ + list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \ + unique=`for i in $$list; do \ + if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \ + done | \ + $(AWK) '{ files[$$0] = 1; nonempty = 1; } \ + END { if (nonempty) { for (i in files) print i; }; }'`; \ + shift; \ + if test -z "$(ETAGS_ARGS)$$*$$unique"; then :; else \ + test -n "$$unique" || unique=$$empty_fix; \ + if test $$# -gt 0; then \ + $(ETAGS) $(ETAGSFLAGS) $(AM_ETAGSFLAGS) $(ETAGS_ARGS) \ + "$$@" $$unique; \ + else \ + $(ETAGS) $(ETAGSFLAGS) $(AM_ETAGSFLAGS) $(ETAGS_ARGS) \ + $$unique; \ + fi; \ + fi +ctags: CTAGS +CTAGS: $(HEADERS) $(SOURCES) $(TAGS_DEPENDENCIES) \ + $(TAGS_FILES) $(LISP) + list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \ + unique=`for i in $$list; do \ + if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \ + done | \ + $(AWK) '{ files[$$0] = 1; nonempty = 1; } \ + END { if (nonempty) { for (i in files) print i; }; }'`; \ + test -z "$(CTAGS_ARGS)$$unique" \ + || $(CTAGS) $(CTAGSFLAGS) $(AM_CTAGSFLAGS) $(CTAGS_ARGS) \ + $$unique + +GTAGS: + here=`$(am__cd) $(top_builddir) && pwd` \ + && $(am__cd) $(top_srcdir) \ + && gtags -i $(GTAGS_ARGS) "$$here" + +distclean-tags: + -rm -f TAGS ID GTAGS GRTAGS GSYMS GPATH tags + +distdir: $(DISTFILES) + @srcdirstrip=`echo "$(srcdir)" | sed 's/[].[^$$\\*]/\\\\&/g'`; \ + topsrcdirstrip=`echo "$(top_srcdir)" | sed 's/[].[^$$\\*]/\\\\&/g'`; \ + list='$(DISTFILES)'; \ + dist_files=`for file in $$list; do echo $$file; done | \ + sed -e "s|^$$srcdirstrip/||;t" \ + -e "s|^$$topsrcdirstrip/|$(top_builddir)/|;t"`; \ + case $$dist_files in \ + */*) $(MKDIR_P) `echo "$$dist_files" | \ + sed '/\//!d;s|^|$(distdir)/|;s,/[^/]*$$,,' | \ + sort -u` ;; \ + esac; \ + for file in $$dist_files; do \ + if test -f $$file || test -d $$file; then d=.; else d=$(srcdir); fi; \ + if test -d $$d/$$file; then \ + dir=`echo "/$$file" | sed -e 's,/[^/]*$$,,'`; \ + if test -d "$(distdir)/$$file"; then \ + find "$(distdir)/$$file" -type d ! -perm -700 -exec chmod u+rwx {} \;; \ + fi; \ + if test -d $(srcdir)/$$file && test $$d != $(srcdir); then \ + cp -fpR $(srcdir)/$$file "$(distdir)$$dir" || exit 1; \ + find "$(distdir)/$$file" -type d ! -perm -700 -exec chmod u+rwx {} \;; \ + fi; \ + cp -fpR $$d/$$file "$(distdir)$$dir" || exit 1; \ + else \ + test -f "$(distdir)/$$file" \ + || cp -p $$d/$$file "$(distdir)/$$file" \ + || exit 1; \ + fi; \ + done +check-am: all-am +check: $(BUILT_SOURCES) + $(MAKE) $(AM_MAKEFLAGS) check-am +all-am: Makefile $(PROGRAMS) +installdirs: +install: $(BUILT_SOURCES) + $(MAKE) $(AM_MAKEFLAGS) install-am +install-exec: install-exec-am +install-data: install-data-am +uninstall: uninstall-am + +install-am: all-am + @$(MAKE) $(AM_MAKEFLAGS) install-exec-am install-data-am + +installcheck: installcheck-am +install-strip: + $(MAKE) $(AM_MAKEFLAGS) INSTALL_PROGRAM="$(INSTALL_STRIP_PROGRAM)" \ + install_sh_PROGRAM="$(INSTALL_STRIP_PROGRAM)" INSTALL_STRIP_FLAG=-s \ + `test -z '$(STRIP)' || \ + echo "INSTALL_PROGRAM_ENV=STRIPPROG='$(STRIP)'"` install +mostlyclean-generic: + +clean-generic: + -test -z "$(CLEANFILES)" || rm -f $(CLEANFILES) + +distclean-generic: + -test -z "$(CONFIG_CLEAN_FILES)" || rm -f $(CONFIG_CLEAN_FILES) + -test . = "$(srcdir)" || test -z "$(CONFIG_CLEAN_VPATH_FILES)" || rm -f $(CONFIG_CLEAN_VPATH_FILES) + +maintainer-clean-generic: + @echo "This command is intended for maintainers to use" + @echo "it deletes files that may require special tools to rebuild." + -test -z "$(BUILT_SOURCES)" || rm -f $(BUILT_SOURCES) +clean: clean-am + +clean-am: clean-generic clean-libtool clean-noinstPROGRAMS \ + mostlyclean-am + +distclean: distclean-am + -rm -rf ./$(DEPDIR) + -rm -f Makefile +distclean-am: clean-am distclean-compile distclean-generic \ + distclean-tags + +dvi: dvi-am + +dvi-am: + +html: html-am + +html-am: + +info: info-am + +info-am: + +install-data-am: + +install-dvi: install-dvi-am + +install-dvi-am: + +install-exec-am: + +install-html: install-html-am + +install-html-am: + +install-info: install-info-am + +install-info-am: + +install-man: + +install-pdf: install-pdf-am + +install-pdf-am: + +install-ps: install-ps-am + +install-ps-am: + +installcheck-am: + +maintainer-clean: maintainer-clean-am + -rm -rf ./$(DEPDIR) + -rm -f Makefile +maintainer-clean-am: distclean-am maintainer-clean-generic + +mostlyclean: mostlyclean-am + +mostlyclean-am: mostlyclean-compile mostlyclean-generic \ + mostlyclean-libtool + +pdf: pdf-am + +pdf-am: + +ps: ps-am + +ps-am: + +uninstall-am: + +.MAKE: all check install install-am install-strip + +.PHONY: CTAGS GTAGS all all-am check check-am clean clean-generic \ + clean-libtool clean-noinstPROGRAMS ctags distclean \ + distclean-compile distclean-generic distclean-libtool \ + distclean-tags distdir dvi dvi-am html html-am info info-am \ + install install-am install-data install-data-am install-dvi \ + install-dvi-am install-exec install-exec-am install-html \ + install-html-am install-info install-info-am install-man \ + install-pdf install-pdf-am install-ps install-ps-am \ + install-strip installcheck installcheck-am installdirs \ + maintainer-clean maintainer-clean-generic mostlyclean \ + mostlyclean-compile mostlyclean-generic mostlyclean-libtool \ + pdf pdf-am ps ps-am tags uninstall uninstall-am + + +check-libntp: ../libntp/libntp.a + @echo stamp > $@ + +../libntp/libntp.a: + cd ../libntp && $(MAKE) $(AM_MAKEFLAGS) libntp.a +$(DEPDIR)/deps-ver: $(top_srcdir)/deps-ver + @[ -f $@ ] || \ + cp $(top_srcdir)/deps-ver $@ + @[ -w $@ ] || \ + chmod ug+w $@ + @cmp $(top_srcdir)/deps-ver $@ > /dev/null || ( \ + $(MAKE) $(AM_MAKEFLAGS) clean && \ + echo -n "Prior $(subdir)/$(DEPDIR) version " && \ + cat $@ && \ + rm -rf $(DEPDIR) && \ + mkdir $(DEPDIR) && \ + case "$(top_builddir)" in \ + .) \ + ./config.status Makefile depfiles \ + ;; \ + *) \ + cd "$(top_builddir)" && \ + ./config.status $(subdir)/Makefile depfiles && \ + cd $(subdir) \ + ;; \ + esac && \ + echo -n "Cleaned $(subdir)/$(DEPDIR) version " && \ + cat $(top_srcdir)/deps-ver \ + ) + cp $(top_srcdir)/deps-ver $@ + +.deps-ver: $(top_srcdir)/deps-ver + @[ ! -d $(DEPDIR) ] || $(MAKE) $(AM_MAKEFLAGS) $(DEPDIR)/deps-ver + @touch $@ + +# +# depsver.mf included in Makefile.am for directories with .deps +# +# When building in the same directory with sources that change over +# time, such as when tracking using bk, the .deps files can become +# stale with respect to moved, deleted, or superceded headers. Most +# commonly, this would exhibit as make reporting a failure to make a +# header file which is no longer in the location given. To address +# this issue, we use a deps-ver file which is updated with each change +# that breaks old .deps files. A copy of deps-ver is made into +# $(DEPDIR) if not already present. If $(DEPDIR)/deps-ver is present +# with different contents than deps-ver, we make clean to ensure all +# .o files built before the incompatible change are rebuilt along with +# their updated .deps files, then remove $(DEPDIR) and recreate it as +# empty stubs. +# +# It is normal when configured with --disable-dependency-tracking for +# the DEPDIR to not have been created. For this reason, we use the +# intermediate target .deps-ver, which invokes make recursively if +# DEPDIR exists. +# +# If you modify depsver.mf, please make the changes to the master +# copy, the one in sntp is copied by the bootstrap script from it. +# +# This comment block follows rather than leads the related code so that +# it stays with it in the generated Makefile.in and Makefile. +# + +# Tell versions [3.59,3.63) of GNU make to not export all variables. +# Otherwise a system limit (for SysV at least) may be exceeded. +.NOEXPORT: diff --git a/clockstuff/README b/clockstuff/README new file mode 100644 index 0000000..14089a9 --- /dev/null +++ b/clockstuff/README @@ -0,0 +1,21 @@ +README file for directory ./clockstuff of the NTP Version 4 distribution + +This directory contains the sources for utility programs designed to +support radio clocks. chutest.c is desgined to test the depredated +chu_clk line discipline or STREAMS module and can also test a CHU +modem in raw mode. + +You can make things in here by typing one or more of: + + make propdelay (or `make') + make chutest + +Propdelay computes high frequency propagation delays, given the +longitude and latitude of the transmitter and receiver. Use +this for WWV/H and CHU. Don't use it for WWVB (the computation +is easier for that). + +Chutest can be used to input and process data from a CHU modem +attached to a serial port. It will use the CHU line discipline +(if installed), or raw mode otherwise. This was used to test +out the initial reduction algorithms, and may not be up to date. diff --git a/clockstuff/chutest.c b/clockstuff/chutest.c new file mode 100644 index 0000000..488a0d1 --- /dev/null +++ b/clockstuff/chutest.c @@ -0,0 +1,821 @@ +/* chutest.c,v 3.1 1993/07/06 01:05:21 jbj Exp + * chutest - test the CHU clock + */ + +#ifdef HAVE_CONFIG_H +# include +#endif +#include +#include +#ifdef HAVE_UNISTD_H +# include +#endif +#ifdef HAVE_STROPTS_H +# include +#else +# ifdef HAVE_SYS_STROPTS_H +# include +# endif +#endif +#include +#include +#include +#include +#include +#include +#ifdef HAVE_TERMIOS_H +# include +#else +# ifdef HAVE_SGTTY_H +# include +# endif +#endif + +#include "ntp_fp.h" +#include "ntp.h" +#include "ntp_unixtime.h" +#include "ntp_calendar.h" + +#ifdef CHULDISC +# ifdef HAVE_SYS_CHUDEFS_H +# include +# endif +#endif + + +#ifndef CHULDISC +#define NCHUCHARS (10) + +struct chucode { + u_char codechars[NCHUCHARS]; /* code characters */ + u_char ncodechars; /* number of code characters */ + u_char chustatus; /* not used currently */ + struct timeval codetimes[NCHUCHARS]; /* arrival times */ +}; +#endif + +#define STREQ(a, b) (*(a) == *(b) && strcmp((a), (b)) == 0) + +char *progname; + +int dofilter = 0; /* set to 1 when we should run filter algorithm */ +int showtimes = 0; /* set to 1 when we should show char arrival times */ +int doprocess = 0; /* set to 1 when we do processing analogous to driver */ +#ifdef CHULDISC +int usechuldisc = 0; /* set to 1 when CHU line discipline should be used */ +#endif +#ifdef STREAM +int usechuldisc = 0; /* set to 1 when CHU line discipline should be used */ +#endif + +struct timeval lasttv; +struct chucode chudata; + +void error(char *fmt, char *s1, char *s2); +void init_chu(void); +int openterm(char *dev); +int process_raw(int s); +int process_ldisc(int s); +void raw_filter(unsigned int c, struct timeval *tv); +void chufilter(struct chucode *chuc, l_fp *rtime); + + +/* + * main - parse arguments and handle options + */ +int +main( + int argc, + char *argv[] + ) +{ + int c; + int errflg = 0; + extern int ntp_optind; + + progname = argv[0]; + while ((c = ntp_getopt(argc, argv, "cdfpt")) != EOF) + switch (c) { + case 'c': +#ifdef STREAM + usechuldisc = 1; + break; +#endif +#ifdef CHULDISC + usechuldisc = 1; + break; +#endif +#ifndef STREAM +#ifndef CHULDISC + (void) fprintf(stderr, + "%s: CHU line discipline not available on this machine\n", + progname); + exit(2); +#endif +#endif + case 'd': + ++debug; + break; + case 'f': + dofilter = 1; + break; + case 'p': + doprocess = 1; + case 't': + showtimes = 1; + break; + default: + errflg++; + break; + } + if (errflg || ntp_optind+1 != argc) { +#ifdef STREAM + (void) fprintf(stderr, "usage: %s [-dft] tty_device\n", + progname); +#endif +#ifdef CHULDISC + (void) fprintf(stderr, "usage: %s [-dft] tty_device\n", + progname); +#endif +#ifndef STREAM +#ifndef CHULDISC + (void) fprintf(stderr, "usage: %s [-cdft] tty_device\n", + progname); +#endif +#endif + exit(2); + } + + (void) gettimeofday(&lasttv, (struct timezone *)0); + c = openterm(argv[ntp_optind]); + init_chu(); +#ifdef STREAM + if (usechuldisc) + process_ldisc(c); + else +#endif +#ifdef CHULDISC + if (usechuldisc) + process_ldisc(c); + else +#endif + process_raw(c); + /*NOTREACHED*/ +} + + +/* + * openterm - open a port to the CHU clock + */ +int +openterm( + char *dev + ) +{ + int s; + struct sgttyb ttyb; + + if (debug) + (void) fprintf(stderr, "Doing open..."); + if ((s = open(dev, O_RDONLY, 0777)) < 0) + error("open(%s)", dev, ""); + if (debug) + (void) fprintf(stderr, "open okay\n"); + + if (debug) + (void) fprintf(stderr, "Setting exclusive use..."); + if (ioctl(s, TIOCEXCL, (char *)0) < 0) + error("ioctl(TIOCEXCL)", "", ""); + if (debug) + (void) fprintf(stderr, "done\n"); + + ttyb.sg_ispeed = ttyb.sg_ospeed = B300; + ttyb.sg_erase = ttyb.sg_kill = 0; + ttyb.sg_flags = EVENP|ODDP|RAW; + if (debug) + (void) fprintf(stderr, "Setting baud rate et al..."); + if (ioctl(s, TIOCSETP, (char *)&ttyb) < 0) + error("ioctl(TIOCSETP, raw)", "", ""); + if (debug) + (void) fprintf(stderr, "done\n"); + +#ifdef CHULDISC + if (usechuldisc) { + int ldisc; + + if (debug) + (void) fprintf(stderr, "Switching to CHU ldisc..."); + ldisc = CHULDISC; + if (ioctl(s, TIOCSETD, (char *)&ldisc) < 0) + error("ioctl(TIOCSETD, CHULDISC)", "", ""); + if (debug) + (void) fprintf(stderr, "okay\n"); + } +#endif +#ifdef STREAM + if (usechuldisc) { + + if (debug) + (void) fprintf(stderr, "Poping off streams..."); + while (ioctl(s, I_POP, 0) >=0) ; + if (debug) + (void) fprintf(stderr, "okay\n"); + if (debug) + (void) fprintf(stderr, "Pushing CHU stream..."); + if (ioctl(s, I_PUSH, "chu") < 0) + error("ioctl(I_PUSH, \"chu\")", "", ""); + if (debug) + (void) fprintf(stderr, "okay\n"); + } +#endif + return s; +} + + +/* + * process_raw - process characters in raw mode + */ +int +process_raw( + int s + ) +{ + u_char c; + int n; + struct timeval tv; + struct timeval difftv; + + while ((n = read(s, &c, sizeof(char))) > 0) { + (void) gettimeofday(&tv, (struct timezone *)0); + if (dofilter) + raw_filter((unsigned int)c, &tv); + else { + difftv.tv_sec = tv.tv_sec - lasttv.tv_sec; + difftv.tv_usec = tv.tv_usec - lasttv.tv_usec; + if (difftv.tv_usec < 0) { + difftv.tv_sec--; + difftv.tv_usec += 1000000; + } + (void) printf("%02x\t%lu.%06lu\t%lu.%06lu\n", + c, tv.tv_sec, tv.tv_usec, difftv.tv_sec, + difftv.tv_usec); + lasttv = tv; + } + } + + if (n == 0) { + (void) fprintf(stderr, "%s: zero returned on read\n", progname); + exit(1); + } else + error("read()", "", ""); +} + + +/* + * raw_filter - run the line discipline filter over raw data + */ +void +raw_filter( + unsigned int c, + struct timeval *tv + ) +{ + static struct timeval diffs[10]; + struct timeval diff; + l_fp ts; + + if ((c & 0xf) > 9 || ((c>>4)&0xf) > 9) { + if (debug) + (void) fprintf(stderr, + "character %02x failed BCD test\n", c); + chudata.ncodechars = 0; + return; + } + + if (chudata.ncodechars > 0) { + diff.tv_sec = tv->tv_sec + - chudata.codetimes[chudata.ncodechars].tv_sec; + diff.tv_usec = tv->tv_usec + - chudata.codetimes[chudata.ncodechars].tv_usec; + if (diff.tv_usec < 0) { + diff.tv_sec--; + diff.tv_usec += 1000000; + } /* + if (diff.tv_sec != 0 || diff.tv_usec > 900000) { + if (debug) + (void) fprintf(stderr, + "character %02x failed time test\n"); + chudata.ncodechars = 0; + return; + } */ + } + + chudata.codechars[chudata.ncodechars] = c; + chudata.codetimes[chudata.ncodechars] = *tv; + if (chudata.ncodechars > 0) + diffs[chudata.ncodechars] = diff; + if (++chudata.ncodechars == 10) { + if (doprocess) { + TVTOTS(&chudata.codetimes[NCHUCHARS-1], &ts); + ts.l_ui += JAN_1970; + chufilter(&chudata, &chudata.codetimes[NCHUCHARS-1]); + } else { + register int i; + + for (i = 0; i < chudata.ncodechars; i++) { + (void) printf("%x%x\t%lu.%06lu\t%lu.%06lu\n", + chudata.codechars[i] & 0xf, + (chudata.codechars[i] >>4 ) & 0xf, + chudata.codetimes[i].tv_sec, + chudata.codetimes[i].tv_usec, + diffs[i].tv_sec, diffs[i].tv_usec); + } + } + chudata.ncodechars = 0; + } +} + + +/* #ifdef CHULDISC*/ +/* + * process_ldisc - process line discipline + */ +int +process_ldisc( + int s + ) +{ + struct chucode chu; + int n; + register int i; + struct timeval diff; + l_fp ts; + void chufilter(); + + while ((n = read(s, (char *)&chu, sizeof chu)) > 0) { + if (n != sizeof chu) { + (void) fprintf(stderr, "Expected %d, got %d\n", + sizeof chu, n); + continue; + } + + if (doprocess) { + TVTOTS(&chu.codetimes[NCHUCHARS-1], &ts); + ts.l_ui += JAN_1970; + chufilter(&chu, &ts); + } else { + for (i = 0; i < NCHUCHARS; i++) { + if (i == 0) + diff.tv_sec = diff.tv_usec = 0; + else { + diff.tv_sec = chu.codetimes[i].tv_sec + - chu.codetimes[i-1].tv_sec; + diff.tv_usec = chu.codetimes[i].tv_usec + - chu.codetimes[i-1].tv_usec; + if (diff.tv_usec < 0) { + diff.tv_sec--; + diff.tv_usec += 1000000; + } + } + (void) printf("%x%x\t%lu.%06lu\t%lu.%06lu\n", + chu.codechars[i] & 0xf, (chu.codechars[i]>>4)&0xf, + chu.codetimes[i].tv_sec, chu.codetimes[i].tv_usec, + diff.tv_sec, diff.tv_usec); + } + } + } + if (n == 0) { + (void) fprintf(stderr, "%s: zero returned on read\n", progname); + exit(1); + } else + error("read()", "", ""); +} +/*#endif*/ + + +/* + * error - print an error message + */ +void +error( + char *fmt, + char *s1, + char *s2 + ) +{ + (void) fprintf(stderr, "%s: ", progname); + (void) fprintf(stderr, fmt, s1, s2); + (void) fprintf(stderr, ": "); + perror(""); + exit(1); +} + +/* + * Definitions + */ +#define MAXUNITS 4 /* maximum number of CHU units permitted */ +#define CHUDEV "/dev/chu%d" /* device we open. %d is unit number */ +#define NCHUCODES 9 /* expect 9 CHU codes per minute */ + +/* + * When CHU is operating optimally we want the primary clock distance + * to come out at 300 ms. Thus, peer.distance in the CHU peer structure + * is set to 290 ms and we compute delays which are at least 10 ms long. + * The following are 290 ms and 10 ms expressed in u_fp format + */ +#define CHUDISTANCE 0x00004a3d +#define CHUBASEDELAY 0x0000028f + +/* + * To compute a quality for the estimate (a pseudo delay) we add a + * fixed 10 ms for each missing code in the minute and add to this + * the sum of the differences between the remaining offsets and the + * estimated sample offset. + */ +#define CHUDELAYPENALTY 0x0000028f + +/* + * Other constant stuff + */ +#define CHUPRECISION (-9) /* what the heck */ +#define CHUREFID "CHU\0" + +/* + * Default fudge factors + */ +#define DEFPROPDELAY 0x00624dd3 /* 0.0015 seconds, 1.5 ms */ +#define DEFFILTFUDGE 0x000d1b71 /* 0.0002 seconds, 200 us */ + +/* + * Hacks to avoid excercising the multiplier. I have no pride. + */ +#define MULBY10(x) (((x)<<3) + ((x)<<1)) +#define MULBY60(x) (((x)<<6) - ((x)<<2)) /* watch overflow */ +#define MULBY24(x) (((x)<<4) + ((x)<<3)) + +/* + * Constants for use when multiplying by 0.1. ZEROPTONE is 0.1 + * as an l_fp fraction, NZPOBITS is the number of significant bits + * in ZEROPTONE. + */ +#define ZEROPTONE 0x1999999a +#define NZPOBITS 29 + +/* + * The CHU table. This gives the expected time of arrival of each + * character after the on-time second and is computed as follows: + * The CHU time code is sent at 300 bps. Your average UART will + * synchronize at the edge of the start bit and will consider the + * character complete at the center of the first stop bit, i.e. + * 0.031667 ms later. Thus the expected time of each interrupt + * is the start bit time plus 0.031667 seconds. These times are + * in chutable[]. To this we add such things as propagation delay + * and delay fudge factor. + */ +#define CHARDELAY 0x081b4e80 + +static u_long chutable[NCHUCHARS] = { + 0x2147ae14 + CHARDELAY, /* 0.130 (exactly) */ + 0x2ac08312 + CHARDELAY, /* 0.167 (exactly) */ + 0x34395810 + CHARDELAY, /* 0.204 (exactly) */ + 0x3db22d0e + CHARDELAY, /* 0.241 (exactly) */ + 0x472b020c + CHARDELAY, /* 0.278 (exactly) */ + 0x50a3d70a + CHARDELAY, /* 0.315 (exactly) */ + 0x5a1cac08 + CHARDELAY, /* 0.352 (exactly) */ + 0x63958106 + CHARDELAY, /* 0.389 (exactly) */ + 0x6d0e5604 + CHARDELAY, /* 0.426 (exactly) */ + 0x76872b02 + CHARDELAY, /* 0.463 (exactly) */ +}; + +/* + * Keep the fudge factors separately so they can be set even + * when no clock is configured. + */ +static l_fp propagation_delay; +static l_fp fudgefactor; +static l_fp offset_fudge; + +/* + * We keep track of the start of the year, watching for changes. + * We also keep track of whether the year is a leap year or not. + * All because stupid CHU doesn't include the year in the time code. + */ +static u_long yearstart; + +/* + * Imported from the timer module + */ +extern u_long current_time; +extern struct event timerqueue[]; + +/* + * init_chu - initialize internal chu driver data + */ +void +init_chu(void) +{ + + /* + * Initialize fudge factors to default. + */ + propagation_delay.l_ui = 0; + propagation_delay.l_uf = DEFPROPDELAY; + fudgefactor.l_ui = 0; + fudgefactor.l_uf = DEFFILTFUDGE; + offset_fudge = propagation_delay; + L_ADD(&offset_fudge, &fudgefactor); + + yearstart = 0; +} + + +void +chufilter( + struct chucode *chuc, + l_fp *rtime + ) +{ + register int i; + register u_long date_ui; + register u_long tmp; + register u_char *code; + int isneg; + int imin; + int imax; + u_long reftime; + l_fp off[NCHUCHARS]; + l_fp ts; + int day, hour, minute, second; + static u_char lastcode[NCHUCHARS]; + + /* + * We'll skip the checks made in the kernel, but assume they've + * been done. This means that all characters are BCD and + * the intercharacter spacing isn't unreasonable. + */ + + /* + * print the code + */ + for (i = 0; i < NCHUCHARS; i++) + printf("%c%c", (chuc->codechars[i] & 0xf) + '0', + ((chuc->codechars[i]>>4) & 0xf) + '0'); + printf("\n"); + + /* + * Format check. Make sure the two halves match. + */ + for (i = 0; i < NCHUCHARS/2; i++) + if (chuc->codechars[i] != chuc->codechars[i+(NCHUCHARS/2)]) { + (void) printf("Bad format, halves don't match\n"); + return; + } + + /* + * Break out the code into the BCD nibbles. Only need to fiddle + * with the first half since both are identical. Note the first + * BCD character is the low order nibble, the second the high order. + */ + code = lastcode; + for (i = 0; i < NCHUCHARS/2; i++) { + *code++ = chuc->codechars[i] & 0xf; + *code++ = (chuc->codechars[i] >> 4) & 0xf; + } + + /* + * If the first nibble isn't a 6, we're up the creek + */ + code = lastcode; + if (*code++ != 6) { + (void) printf("Bad format, no 6 at start\n"); + return; + } + + /* + * Collect the day, the hour, the minute and the second. + */ + day = *code++; + day = MULBY10(day) + *code++; + day = MULBY10(day) + *code++; + hour = *code++; + hour = MULBY10(hour) + *code++; + minute = *code++; + minute = MULBY10(minute) + *code++; + second = *code++; + second = MULBY10(second) + *code++; + + /* + * Sanity check the day and time. Note that this + * only occurs on the 31st through the 39th second + * of the minute. + */ + if (day < 1 || day > 366 + || hour > 23 || minute > 59 + || second < 31 || second > 39) { + (void) printf("Failed date sanity check: %d %d %d %d\n", + day, hour, minute, second); + return; + } + + /* + * Compute seconds into the year. + */ + tmp = (u_long)(MULBY24((day-1)) + hour); /* hours */ + tmp = MULBY60(tmp) + (u_long)minute; /* minutes */ + tmp = MULBY60(tmp) + (u_long)second; /* seconds */ + + /* + * Now the fun begins. We demand that the received time code + * be within CLOCK_WAYTOOBIG of the receive timestamp, but + * there is uncertainty about the year the timestamp is in. + * Use the current year start for the first check, this should + * work most of the time. + */ + date_ui = tmp + yearstart; +#define CLOCK_WAYTOOBIG 1000 /* revived from ancient sources */ + if (date_ui < (rtime->l_ui + CLOCK_WAYTOOBIG) + && date_ui > (rtime->l_ui - CLOCK_WAYTOOBIG)) + goto codeokay; /* looks good */ + + /* + * Trouble. Next check is to see if the year rolled over and, if + * so, try again with the new year's start. + */ + date_ui = calyearstart(rtime->l_ui, NULL); + if (date_ui != yearstart) { + yearstart = date_ui; + date_ui += tmp; + (void) printf("time %u, code %u, difference %d\n", + date_ui, rtime->l_ui, (long)date_ui-(long)rtime->l_ui); + if (date_ui < (rtime->l_ui + CLOCK_WAYTOOBIG) + && date_ui > (rtime->l_ui - CLOCK_WAYTOOBIG)) + goto codeokay; /* okay this time */ + } + + ts.l_uf = 0; + ts.l_ui = yearstart; + printf("yearstart %s\n", prettydate(&ts)); + printf("received %s\n", prettydate(rtime)); + ts.l_ui = date_ui; + printf("date_ui %s\n", prettydate(&ts)); + + /* + * Here we know the year start matches the current system + * time. One remaining possibility is that the time code + * is in the year previous to that of the system time. This + * is only worth checking if the receive timestamp is less + * than CLOCK_WAYTOOBIG seconds into the new year. + */ + if ((rtime->l_ui - yearstart) < CLOCK_WAYTOOBIG) { + date_ui = tmp; + date_ui += calyearstart(yearstart - CLOCK_WAYTOOBIG, + NULL); + if ((rtime->l_ui - date_ui) < CLOCK_WAYTOOBIG) + goto codeokay; + } + + /* + * One last possibility is that the time stamp is in the year + * following the year the system is in. Try this one before + * giving up. + */ + date_ui = tmp; + date_ui += calyearstart(yearstart + (400 * SECSPERDAY), + NULL); + if ((date_ui - rtime->l_ui) >= CLOCK_WAYTOOBIG) { + printf("Date hopelessly off\n"); + return; /* hopeless, let it sync to other peers */ + } + + codeokay: + reftime = date_ui; + /* + * We've now got the integral seconds part of the time code (we hope). + * The fractional part comes from the table. We next compute + * the offsets for each character. + */ + for (i = 0; i < NCHUCHARS; i++) { + register u_long tmp2; + + off[i].l_ui = date_ui; + off[i].l_uf = chutable[i]; + tmp = chuc->codetimes[i].tv_sec + JAN_1970; + TVUTOTSF(chuc->codetimes[i].tv_usec, tmp2); + M_SUB(off[i].l_ui, off[i].l_uf, tmp, tmp2); + } + + /* + * Here is a *big* problem. What one would normally + * do here on a machine with lots of clock bits (say + * a Vax or the gizmo board) is pick the most positive + * offset and the estimate, since this is the one that + * is most likely suffered the smallest interrupt delay. + * The trouble is that the low order clock bit on an IBM + * RT, which is the machine I had in mind when doing this, + * ticks at just under the millisecond mark. This isn't + * precise enough. What we can do to improve this is to + * average all 10 samples and rely on the second level + * filtering to pick the least delayed estimate. Trouble + * is, this means we have to divide a 64 bit fixed point + * number by 10, a procedure which really sucks. Oh, well. + * First compute the sum. + */ + date_ui = 0; + tmp = 0; + for (i = 0; i < NCHUCHARS; i++) + M_ADD(date_ui, tmp, off[i].l_ui, off[i].l_uf); + if (M_ISNEG(date_ui, tmp)) + isneg = 1; + else + isneg = 0; + + /* + * Here is a multiply-by-0.1 optimization that should apply + * just about everywhere. If the magnitude of the sum + * is less than 9 we don't have to worry about overflow + * out of a 64 bit product, even after rounding. + */ + if (date_ui < 9 || date_ui > 0xfffffff7) { + register u_long prod_ui; + register u_long prod_uf; + + prod_ui = prod_uf = 0; + /* + * This code knows the low order bit in 0.1 is zero + */ + for (i = 1; i < NZPOBITS; i++) { + M_LSHIFT(date_ui, tmp); + if (ZEROPTONE & (1< +#endif +#include +#include + +#include "ntp_stdlib.h" + +extern double sin (double); +extern double cos (double); +extern double acos (double); +extern double tan (double); +extern double atan (double); +extern double sqrt (double); + +#define STREQ(a, b) (*(a) == *(b) && strcmp((a), (b)) == 0) + +/* + * Program constants + */ +#define EARTHRADIUS (6370.0) /* raduis of earth (km) */ +#define LIGHTSPEED (299800.0) /* speed of light, km/s */ +#define PI (3.1415926536) +#define RADPERDEG (PI/180.0) /* radians per degree */ +#define MILE (1.609344) /* km in a mile */ + +#define SUMMERHEIGHT (350.0) /* summer height in km */ +#define WINTERHEIGHT (250.0) /* winter height in km */ + +#define SATHEIGHT (6.6110 * 6378.0) /* geosync satellite height in km + from centre of earth */ + +#define WWVLAT "n40:40:49" +#define WWVLONG "w105:02:27" + +#define WWVHLAT "n21:59:26" +#define WWVHLONG "w159:46:00" + +#define CHULAT "n45:17:47" +#define CHULONG "w75:45:22" + +#define GOES_UP_LAT "n37:52:00" +#define GOES_UP_LONG "w75:27:00" +#define GOES_EAST_LONG "w75:00:00" +#define GOES_STBY_LONG "w105:00:00" +#define GOES_WEST_LONG "w135:00:00" +#define GOES_SAT_LAT "n00:00:00" + +char *wwvlat = WWVLAT; +char *wwvlong = WWVLONG; + +char *wwvhlat = WWVHLAT; +char *wwvhlong = WWVHLONG; + +char *chulat = CHULAT; +char *chulong = CHULONG; + +char *goes_up_lat = GOES_UP_LAT; +char *goes_up_long = GOES_UP_LONG; +char *goes_east_long = GOES_EAST_LONG; +char *goes_stby_long = GOES_STBY_LONG; +char *goes_west_long = GOES_WEST_LONG; +char *goes_sat_lat = GOES_SAT_LAT; + +int hflag = 0; +int Wflag = 0; +int Cflag = 0; +int Gflag = 0; +int height; + +char *progname; + +static void doit (double, double, double, double, double, char *); +static double latlong (char *, int); +static double greatcircle (double, double, double, double); +static double waveangle (double, double, int); +static double propdelay (double, double, int); +static int finddelay (double, double, double, double, double, double *); +static void satdoit (double, double, double, double, double, double, char *); +static void satfinddelay (double, double, double, double, double *); +static double satpropdelay (double); + +/* + * main - parse arguments and handle options + */ +int +main( + int argc, + char *argv[] + ) +{ + int c; + int errflg = 0; + double lat1, long1; + double lat2, long2; + double lat3, long3; + + init_lib(); + + progname = argv[0]; + while ((c = ntp_getopt(argc, argv, "dh:CWG")) != EOF) + switch (c) { + case 'd': + ++debug; + break; + case 'h': + hflag++; + height = atof(ntp_optarg); + if (height <= 0.0) { + (void) fprintf(stderr, "height %s unlikely\n", + ntp_optarg); + errflg++; + } + break; + case 'C': + Cflag++; + break; + case 'W': + Wflag++; + break; + case 'G': + Gflag++; + break; + default: + errflg++; + break; + } + if (errflg || (!(Cflag || Wflag || Gflag) && ntp_optind+4 != argc) || + ((Cflag || Wflag || Gflag) && ntp_optind+2 != argc)) { + (void) fprintf(stderr, + "usage: %s [-d] [-h height] lat1 long1 lat2 long2\n", + progname); + (void) fprintf(stderr," - or -\n"); + (void) fprintf(stderr, + "usage: %s -CWG [-d] lat long\n", + progname); + exit(2); + } + + + if (!(Cflag || Wflag || Gflag)) { + lat1 = latlong(argv[ntp_optind], 1); + long1 = latlong(argv[ntp_optind + 1], 0); + lat2 = latlong(argv[ntp_optind + 2], 1); + long2 = latlong(argv[ntp_optind + 3], 0); + if (hflag) { + doit(lat1, long1, lat2, long2, height, ""); + } else { + doit(lat1, long1, lat2, long2, (double)SUMMERHEIGHT, + "summer propagation, "); + doit(lat1, long1, lat2, long2, (double)WINTERHEIGHT, + "winter propagation, "); + } + } else if (Wflag) { + /* + * Compute delay from WWV + */ + lat1 = latlong(argv[ntp_optind], 1); + long1 = latlong(argv[ntp_optind + 1], 0); + lat2 = latlong(wwvlat, 1); + long2 = latlong(wwvlong, 0); + if (hflag) { + doit(lat1, long1, lat2, long2, height, "WWV "); + } else { + doit(lat1, long1, lat2, long2, (double)SUMMERHEIGHT, + "WWV summer propagation, "); + doit(lat1, long1, lat2, long2, (double)WINTERHEIGHT, + "WWV winter propagation, "); + } + + /* + * Compute delay from WWVH + */ + lat2 = latlong(wwvhlat, 1); + long2 = latlong(wwvhlong, 0); + if (hflag) { + doit(lat1, long1, lat2, long2, height, "WWVH "); + } else { + doit(lat1, long1, lat2, long2, (double)SUMMERHEIGHT, + "WWVH summer propagation, "); + doit(lat1, long1, lat2, long2, (double)WINTERHEIGHT, + "WWVH winter propagation, "); + } + } else if (Cflag) { + lat1 = latlong(argv[ntp_optind], 1); + long1 = latlong(argv[ntp_optind + 1], 0); + lat2 = latlong(chulat, 1); + long2 = latlong(chulong, 0); + if (hflag) { + doit(lat1, long1, lat2, long2, height, "CHU "); + } else { + doit(lat1, long1, lat2, long2, (double)SUMMERHEIGHT, + "CHU summer propagation, "); + doit(lat1, long1, lat2, long2, (double)WINTERHEIGHT, + "CHU winter propagation, "); + } + } else if (Gflag) { + lat1 = latlong(goes_up_lat, 1); + long1 = latlong(goes_up_long, 0); + lat3 = latlong(argv[ntp_optind], 1); + long3 = latlong(argv[ntp_optind + 1], 0); + + lat2 = latlong(goes_sat_lat, 1); + + long2 = latlong(goes_west_long, 0); + satdoit(lat1, long1, lat2, long2, lat3, long3, + "GOES Delay via WEST"); + + long2 = latlong(goes_stby_long, 0); + satdoit(lat1, long1, lat2, long2, lat3, long3, + "GOES Delay via STBY"); + + long2 = latlong(goes_east_long, 0); + satdoit(lat1, long1, lat2, long2, lat3, long3, + "GOES Delay via EAST"); + + } + exit(0); +} + + +/* + * doit - compute a delay and print it + */ +static void +doit( + double lat1, + double long1, + double lat2, + double long2, + double h, + char *str + ) +{ + int hops; + double delay; + + hops = finddelay(lat1, long1, lat2, long2, h, &delay); + printf("%sheight %g km, hops %d, delay %g seconds\n", + str, h, hops, delay); +} + + +/* + * latlong - decode a latitude/longitude value + */ +static double +latlong( + char *str, + int islat + ) +{ + register char *cp; + register char *bp; + double arg; + double divby; + int isneg; + char buf[32]; + char *colon; + + if (islat) { + /* + * Must be north or south + */ + if (*str == 'N' || *str == 'n') + isneg = 0; + else if (*str == 'S' || *str == 's') + isneg = 1; + else + isneg = -1; + } else { + /* + * East is positive, west is negative + */ + if (*str == 'E' || *str == 'e') + isneg = 0; + else if (*str == 'W' || *str == 'w') + isneg = 1; + else + isneg = -1; + } + + if (isneg >= 0) + str++; + + colon = strchr(str, ':'); + if (colon != NULL) { + /* + * in hhh:mm:ss form + */ + cp = str; + bp = buf; + while (cp < colon) + *bp++ = *cp++; + *bp = '\0'; + cp++; + arg = atof(buf); + divby = 60.0; + colon = strchr(cp, ':'); + if (colon != NULL) { + bp = buf; + while (cp < colon) + *bp++ = *cp++; + *bp = '\0'; + cp++; + arg += atof(buf) / divby; + divby = 3600.0; + } + if (*cp != '\0') + arg += atof(cp) / divby; + } else { + arg = atof(str); + } + + if (isneg == 1) + arg = -arg; + + if (debug > 2) + (void) printf("latitude/longitude %s = %g\n", str, arg); + + return arg; +} + + +/* + * greatcircle - compute the great circle distance in kilometers + */ +static double +greatcircle( + double lat1, + double long1, + double lat2, + double long2 + ) +{ + double dg; + double l1r, l2r; + + l1r = lat1 * RADPERDEG; + l2r = lat2 * RADPERDEG; + dg = EARTHRADIUS * acos( + (cos(l1r) * cos(l2r) * cos((long2-long1)*RADPERDEG)) + + (sin(l1r) * sin(l2r))); + if (debug >= 2) + printf( + "greatcircle lat1 %g long1 %g lat2 %g long2 %g dist %g\n", + lat1, long1, lat2, long2, dg); + return dg; +} + + +/* + * waveangle - compute the wave angle for the given distance, virtual + * height and number of hops. + */ +static double +waveangle( + double dg, + double h, + int n + ) +{ + double theta; + double delta; + + theta = dg / (EARTHRADIUS * (double)(2 * n)); + delta = atan((h / (EARTHRADIUS * sin(theta))) + tan(theta/2)) - theta; + if (debug >= 2) + printf("waveangle dist %g height %g hops %d angle %g\n", + dg, h, n, delta / RADPERDEG); + return delta; +} + + +/* + * propdelay - compute the propagation delay + */ +static double +propdelay( + double dg, + double h, + int n + ) +{ + double phi; + double theta; + double td; + + theta = dg / (EARTHRADIUS * (double)(2 * n)); + phi = (PI/2.0) - atan((h / (EARTHRADIUS * sin(theta))) + tan(theta/2)); + td = dg / (LIGHTSPEED * sin(phi)); + if (debug >= 2) + printf("propdelay dist %g height %g hops %d time %g\n", + dg, h, n, td); + return td; +} + + +/* + * finddelay - find the propagation delay + */ +static int +finddelay( + double lat1, + double long1, + double lat2, + double long2, + double h, + double *delay + ) +{ + double dg; /* great circle distance */ + double delta; /* wave angle */ + int n; /* number of hops */ + + dg = greatcircle(lat1, long1, lat2, long2); + if (debug) + printf("great circle distance %g km %g miles\n", dg, dg/MILE); + + n = 1; + while ((delta = waveangle(dg, h, n)) < 0.0) { + if (debug) + printf("tried %d hop%s, no good\n", n, n>1?"s":""); + n++; + } + if (debug) + printf("%d hop%s okay, wave angle is %g\n", n, n>1?"s":"", + delta / RADPERDEG); + + *delay = propdelay(dg, h, n); + return n; +} + +/* + * satdoit - compute a delay and print it + */ +static void +satdoit( + double lat1, + double long1, + double lat2, + double long2, + double lat3, + double long3, + char *str + ) +{ + double up_delay,down_delay; + + satfinddelay(lat1, long1, lat2, long2, &up_delay); + satfinddelay(lat3, long3, lat2, long2, &down_delay); + + printf("%s, delay %g seconds\n", str, up_delay + down_delay); +} + +/* + * satfinddelay - calculate the one-way delay time between a ground station + * and a satellite + */ +static void +satfinddelay( + double lat1, + double long1, + double lat2, + double long2, + double *delay + ) +{ + double dg; /* great circle distance */ + + dg = greatcircle(lat1, long1, lat2, long2); + + *delay = satpropdelay(dg); +} + +/* + * satpropdelay - calculate the one-way delay time between a ground station + * and a satellite + */ +static double +satpropdelay( + double dg + ) +{ + double k1, k2, dist; + double theta; + double td; + + theta = dg / (EARTHRADIUS); + k1 = EARTHRADIUS * sin(theta); + k2 = SATHEIGHT - (EARTHRADIUS * cos(theta)); + if (debug >= 2) + printf("Theta %g k1 %g k2 %g\n", theta, k1, k2); + dist = sqrt(k1*k1 + k2*k2); + td = dist / LIGHTSPEED; + if (debug >= 2) + printf("propdelay dist %g height %g time %g\n", dg, dist, td); + return td; +} -- cgit v1.2.1