⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 173

📁 Unix/Linux 网络时间协议版本3 Network Time Protocol Version 3 (NTP) distribution for Unix systems
💻
📖 第 1 页 / 共 5 页
字号:
X	u_short driftsd[2];X	u_short dsum;			/* checksum */X};X#define JUPITER_O_GPOS_NAV_NOALT	0x01	/* altitude used */X#define JUPITER_O_GPOS_NAV_NODGPS	0x02	/* no differential GPS */X#define JUPITER_O_GPOS_NAV_NOSAT	0x04	/* not enough satellites */X#define JUPITER_O_GPOS_NAV_MAXH		0x08	/* exceeded max EHPE */X#define JUPITER_O_GPOS_NAV_MAXV		0x10	/* exceeded max EVPE */XX/* JUPITER_O_CHAN (1002) */Xstruct jchan {X	u_short stime[2];		/* set time (10 ms ticks) */X	u_short seq;			/* sequence number */X	u_short sseq;			/* sat measurement sequence number */X	u_short gweek;			/* GPS week number */X	u_short sweek[2];		/* GPS seconds into week */X	u_short gpsns[2];		/* GPS nanoseconds from epoch */X	struct jchan2 {X		u_short flags;		/* flags */X		u_short prn;		/* satellite PRN */X		u_short chan;		/* channel number */X	} sat[12];X	u_short dsum;X};XX/* JUPITER_O_VIS (1003) */Xstruct jvis {X	u_short stime[2];		/* set time (10 ms ticks) */X	u_short seq;			/* sequence number */X	u_short gdop;			/* best possible GDOP */X	u_short pdop;			/* best possible PDOP */X	u_short hdop;			/* best possible HDOP */X	u_short vdop;			/* best possible VDOP */X	u_short tdop;			/* best possible TDOP */X	u_short nvis;			/* number of visible satellites */X	struct jvis2 {X		u_short prn;		/* satellite PRN */X		u_short azi;		/* satellite azimuth (radians) */X		u_short elev;		/* satellite elevation (radians) */X	} sat[12];X	u_short dsum;			/* checksum */X};XX/* JUPITER_O_ID (1011) */Xstruct jid {X	u_short stime[2];		/* set time (10 ms ticks) */X	u_short seq;			/* sequence number */X	char chans[20];			/* number of channels (ascii) */X	char vers[20];			/* software version (ascii) */X	char date[20];			/* software date (ascii) */X	char opts[20];			/* software options (ascii) */X	char reserved[20];X	u_short dsum;			/* checksum */X};XX/* JUPITER_O_USER (1012) */Xstruct juser {X	u_short stime[2];		/* set time (10 ms ticks) */X	u_short seq;			/* sequence number */X	u_short status;			/* operatinoal status */X	u_short coldtmo;		/* cold start time-out */X	u_short dgpstmo;		/* DGPS correction time-out*/X	u_short emask;			/* elevation mask */X	u_short selcand[2];		/* selected candidate */X	u_short solflags;		/* solution validity criteria */X	u_short nsat;			/* number of satellites in track */X	u_short herr[2];		/* minimum expected horizontal error */X	u_short verr[2];		/* minimum expected vertical error */X	u_short platform;		/* application platform */X	u_short dsum;			/* checksum */X};XX/* JUPITER_O_PULSE (1108) */Xstruct jpulse {X	u_short stime[2];		/* set time (10 ms ticks) */X	u_short seq;			/* sequence number */X	u_short reserved[5];X	u_short sweek[2];		/* GPS seconds into week */X	short offs;			/* GPS to UTC time offset (seconds) */X	u_short offns[2];		/* GPS to UTC offset (nanoseconds) */X	u_short flags;			/* flags */X	u_short dsum;			/* checksum */X};X#define JUPITER_O_PULSE_VALID		0x1	/* time mark validity */X#define JUPITER_O_PULSE_UTC		0x2	/* GPS/UTC sync */XX/* JUPITER_O_EUP (1135) */Xstruct jeup {X	u_short stime[2];		/* set time (10 ms ticks) */X	u_short seq;			/* sequence number */X	u_char dataid;			/* data id */X	u_char prn;			/* satellite PRN */X	u_short dsum;			/* checksum */X};XX/* JUPITER_I_RESTART (1303) */Xstruct jrestart {X	u_short seq;			/* sequence number */X	u_short flags;X	u_short dsum;			/* checksum */X};X#define JUPITER_I_RESTART_INVRAM	0x01X#define JUPITER_I_RESTART_INVEEPROM	0x02X#define JUPITER_I_RESTART_INVRTC	0x04X#define JUPITER_I_RESTART_COLD		0x80XX/* JUPITER_I_PVTINIT (1200) */Xstruct jpvtinit {X	u_short flags;X	u_short gweek;			/* GPS week number */X	u_short sweek[2];		/* GPS seconds into week */X	u_short utcday;			/* 1 to 31 */X	u_short utcmon;			/* 1 to 12 */X	u_short utcyear;		/* 1980 to 2079 */X	u_short utchour;		/* 0 to 23 */X	u_short utcmin;			/* 0 to 59 */X	u_short utcsec;			/* 0 to 59 */X	u_short lat[2];			/* latitude (radians) */X	u_short lon[2];			/* longitude (radians) */X	u_short height[2];		/* height (meters) */X	u_short speed[2];		/* ground speed (meters/sec) */X	u_short course;			/* true course (radians) */X	u_short climb;X	u_short dsum;X};X#define JUPITER_I_PVTINIT_FORCE		0x01X#define JUPITER_I_PVTINIT_GPSVAL	0x02X#define JUPITER_I_PVTINIT_UTCVAL	0x04X#define JUPITER_I_PVTINIT_POSVAL	0x08X#define JUPITER_I_PVTINIT_ALTVAL	0x10X#define JUPITER_I_PVTINIT_SPDVAL	0x12X#define JUPITER_I_PVTINIT_MAGVAL	0x14X#define JUPITER_I_PVTINIT_CLIMBVAL	0x18XX/* JUPITER_I_PLAT (1220) */Xstruct jplat {X	u_short seq;			/* sequence number */X	u_short platform;		/* application platform */X	u_short dsum;X};X#define JUPITER_I_PLAT_DEFAULT		0	/* default dynamics */X#define JUPITER_I_PLAT_LOW		2	/* pedestrian */X#define JUPITER_I_PLAT_MED		5	/* land (e.g. automobile) */X#define JUPITER_I_PLAT_HIGH		6	/* air */SHAR_EOFif test 9321 -ne "`wc -c < 'jupiter.h'`"then	echo shar: error transmitting "'jupiter.h'" '(should have been 9321 characters)'fifi # end of overwriting checkecho shar: extracting "'refclock_jupiter.c'" '(33681 characters)'if test -f 'refclock_jupiter.c'then	echo shar: will not over-write existing file "'refclock_jupiter.c'"elsesed 's/^X//' << \SHAR_EOF > 'refclock_jupiter.c'X/*X * Copyright (c) 1997, 1998X *	The Regents of the University of California.  All rights reserved.X *X * Redistribution and use in source and binary forms, with or withoutX * modification, are permitted provided that the following conditionsX * are met:X * 1. Redistributions of source code must retain the above copyrightX *    notice, this list of conditions and the following disclaimer.X * 2. Redistributions in binary form must reproduce the above copyrightX *    notice, this list of conditions and the following disclaimer in theX *    documentation and/or other materials provided with the distribution.X * 3. All advertising materials mentioning features or use of this softwareX *    must display the following acknowledgement:X *	This product includes software developed by the University ofX *	California, Lawrence Berkeley Laboratory.X * 4. The name of the University may not be used to endorse or promoteX *    products derived from this software without specific priorX *    written permission.X *X * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' ANDX * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THEX * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSEX * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLEX * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIALX * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODSX * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)X * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICTX * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAYX * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OFX * SUCH DAMAGE.X */XX#ifdef HAVE_CONFIG_HX# include <config.h>X#endifXX#if defined(REFCLOCK) && defined(JUPITER) && defined(PPS)XX#include <stdio.h>X#include <ctype.h>X#include <sys/time.h>X#include <errno.h>XX#include "ntpd.h"X#include "ntp_io.h"X#include "ntp_refclock.h"X#include "ntp_unixtime.h"X#include "ntp_stdlib.h"X#include "ntp_calendar.h"XX#include "jupiter.h"XX#if __STDC__X#include <stdarg.h>X#elseX#include <varargs.h>X#endif /* __STDC__ */XX#include <sys/ppsclock.h>XX#ifdef XNTP_BIG_ENDIANX#define getshort(s) ((((s) & 0xff) << 8) | (((s) >> 8) & 0xff))X#define putshort(s) ((((s) & 0xff) << 8) | (((s) >> 8) & 0xff))X#elseX#define getshort(s) (s)X#define putshort(s) (s)X#endifXX/* XXX */X#ifdef sunXchar *strerror(int);X#endifXX/*X * This driver supports the Rockwell Jupiter GPS Receiver boardX * adapted to precision timing applications.  It requires theX * ppsclock line discipline or streams module described in theX * Line Disciplines and Streams Drivers page. It also requires aX * gadget box and 1-PPS level converter, such as described in theX * Pulse-per-second (PPS) Signal Interfacing page.X *X * It may work (with minor modifications) with other Rockwell GPSX * receivers such as the CityTracker.X */XX/*X * GPS DefinitionsX */X#define	DEVICE		"/dev/gps%d"	/* device name and unit */X#define	SPEED232	B9600		/* baud */XX/*X * The number of raw samples which we acquire to derive a single estimate.X * NSAMPLES ideally should not exceed the default poll interval 64.X * NKEEP must be a power of 2 to simplify the averaging process.X */X#define NSAMPLES	64X#define NKEEP		8X#define REFCLOCKMAXDISPERSE (FP_SECOND/4) /* max sample dispersion */XX/*X * Radio interface parametersX */X#define	PRECISION	(-18)	/* precision assumed (about 4 us) */X#define	REFID	"GPS\0"		/* reference id */X#define	DESCRIPTION	"Rockwell Jupiter GPS Receiver" /* who we are */X#define	DEFFUDGETIME	0	/* default fudge time (ms) */XX/* Unix timestamp for the GPS epoch: January 6, 1980 */X#define GPS_EPOCH 315964800XX/* Double short to unsigned int */X#define DS2UI(p) ((getshort((p)[1]) << 16) | getshort((p)[0]))XX/* Double short to signed int */X#define DS2I(p) ((getshort((p)[1]) << 16) | getshort((p)[0]))XX/* One week's worth of seconds */X#define WEEKSECS (7 * 24 * 60 * 60)XX/*X * Imported from the ntp_timer moduleX */Xextern u_long current_time;	/* current time (s) */XX/*X * Imported from ntpd moduleX */Xextern int debug;		/* global debug flag */XX/*X * Juptier unit control structure.X */Xstruct jupiterunit {X	u_int  pollcnt;			/* poll message counter */X	u_int  polled;			/* Hand in a time sample? */X	u_int  lastserial;		/* last pps serial number */X	struct ppsclockev ppsev;	/* PPS control structure */X	u_int gweek;			/* current GPS week number */X	u_int32 lastsweek;		/* last seconds into GPS week */X	u_int32 timecode;		/* current ntp timecode */X	u_int32 stime;			/* used to detect firmware bug */X	int wantid;			/* don't reconfig on channel id msg */X	u_int  moving;			/* mobile platform? */X	u_long sloppyclockflag;		/* fudge flags */X	u_int  known;			/* position known yet? */X	int    coderecv;		/* total received samples */X	int    nkeep;			/* number of samples to preserve */X	int    rshift;			/* number of rshifts for division */X	l_fp   filter[NSAMPLES];	/* offset filter */X	l_fp   lastref;			/* last reference timestamp */X	u_short sbuf[512];		/* local input buffer */X	int ssize;			/* space used in sbuf */X};XX/*X * Function prototypesX */Xstatic	void	jupiter_canmsg(struct peer *, u_int);Xstatic	u_short	jupiter_cksum(u_short *, u_int);X#ifdef QSORT_USES_VOID_PX	int	jupiter_cmpl_fp	P((const void *, const void *));X#elseX	int	jupiter_cmpl_fp	P((const l_fp *, const l_fp *));X#endif /* not QSORT_USES_VOID_P */Xstatic	void	jupiter_config	P((struct peer *));Xstatic	void	jupiter_debug	P((struct peer *, char *, ...))X    __attribute__ ((format (printf, 2, 3)));Xstatic	char *	jupiter_offset	P((struct peer *));Xstatic	char *	jupiter_parse_t	P((struct peer *, u_short *));Xstatic	void	jupiter_platform(struct peer *, u_int);Xstatic	void	jupiter_poll	P((int, struct peer *));Xstatic	int	jupiter_pps	P((struct peer *));Xstatic	char *	jupiter_process	P((struct peer *));Xstatic	int	jupiter_recv(struct peer *);Xstatic	void	jupiter_receive P ((register struct recvbuf *rbufp));Xstatic	void	jupiter_reqmsg(struct peer *, u_int, u_int);Xstatic	void	jupiter_reqonemsg(struct peer *, u_int);Xstatic	char *	jupiter_send(struct peer *, struct jheader *);Xstatic	void	jupiter_shutdown	P((int, struct peer *));Xstatic	int	jupiter_start	P((int, struct peer *));Xstatic	int	jupiter_ttyinit(struct peer *, int);XX/*X * Transfer vectorX */Xstruct	refclock refclock_jupiter = {X	jupiter_start,		/* start up driver */X	jupiter_shutdown,	/* shut down driver */X	jupiter_poll,		/* transmit poll message */X	noentry,		/* (clock control) */X	noentry,		/* (clock init) */X	noentry,		/* (clock buginfo) */X	NOFLAGS			/* not used */X};XX/*X * jupiter_start - open the devices and initialize data for processingX */Xstatic intXjupiter_start(register int unit, register struct peer *peer)X{X	struct refclockproc *pp;X	register struct jupiterunit *up;X	register int fd;X	char gpsdev[20];XX	/*X	 * Open serial portX	 */X	(void)sprintf(gpsdev, DEVICE, unit);X	fd = open(gpsdev, O_RDWRX#ifdef O_NONBLOCKX	    | O_NONBLOCKX#endifX	    , 0);X	if (fd < 0) {X		jupiter_debug(peer, "jupiter_start: open %s: %s\n",X		    gpsdev, strerror(errno));X		return (0);X	}X	if (!jupiter_ttyinit(peer, fd))X		return (0);XX	/* Allocate unit structure */X	if ((up = (struct jupiterunit *)X	    emalloc(sizeof(struct jupiterunit))) == NULL) {X		(void) close(fd);X		return (0);X	}X	memset((char *)up, 0, sizeof(struct jupiterunit));X	pp = peer->procptr;X	pp->io.clock_recv = jupiter_receive;X	pp->io.srcclock = (caddr_t)peer;X	pp->io.datalen = 0;X	pp->io.fd = fd;X	if (!io_addclock(&pp->io)) {X		(void) close(fd);X		free(up);X		return (0);X	}X	pp->unitptr = (caddr_t)up;XX	/*X	 * Initialize miscellaneous variablesX	 */X	peer->precision = PRECISION;X	pp->clockdesc = DESCRIPTION;X	memcpy((char *)&pp->refid, REFID, 4);XXX	/* Ensure the receiver is properly configured */X	jupiter_config(peer);XX	/* Turn on pulse gathering by requesting the first sample */X	if (ioctl(fd, CIOGETEV, (caddr_t)&up->ppsev) < 0) {X		jupiter_debug(peer, "jupiter_ttyinit: CIOGETEV: %s\n",X		    strerror(errno));X		(void) close(fd);X		free(up);X		return (0);X	}X	up->lastserial = up->ppsev.serial;X	memset(&up->ppsev, 0, sizeof(up->ppsev));X	return (1);X}XX/*X * jupiter_shutdown - shut down the clockX */Xstatic voidXjupiter_shutdown(register int unit, register struct peer *peer)X{X	register struct jupiterunit *up;X	struct refclockproc *pp;XX	pp = peer->procptr;X	up = (struct jupiterunit *)pp->unitptr;X	io_closeclock(&pp->io);X	free(up);X}XX/*X * jupiter_config - Configure the receiverX */Xstatic voidXjupiter_config(register struct peer *peer)X{X	register int i;X	register struct jupiterunit *up;X	register struct refclockproc *pp;XX	pp = peer->procptr;X	up = (struct jupiterunit *)pp->unitptr;XX	/*X	 * Initialize the unit variablesX	 *X	 * STRANGE BEHAVIOUR WARNING: The fudge flags are not availableX	 * at the time jupiter_start is called.  These are set later,

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -