refclock_palisade.h revision 82498
1193323Sed/* 2193323Sed * This software was developed by the Software and Component Technologies 3193323Sed * group of Trimble Navigation, Ltd. 4193323Sed * 5193323Sed * Copyright (c) 1997, 1998, 1999, 2000 Trimble Navigation Ltd. 6193323Sed * All rights reserved. 7193323Sed * 8193323Sed * Redistribution and use in source and binary forms, with or without 9193323Sed * modification, are permitted provided that the following conditions 10193323Sed * are met: 11193323Sed * 1. Redistributions of source code must retain the above copyright 12193323Sed * notice, this list of conditions and the following disclaimer. 13193323Sed * 2. Redistributions in binary form must reproduce the above copyright 14193323Sed * notice, this list of conditions and the following disclaimer in the 15198090Srdivacky * documentation and/or other materials provided with the distribution. 16203954Srdivacky * 3. All advertising materials mentioning features or use of this software 17193323Sed * must display the following acknowledgement: 18198090Srdivacky * This product includes software developed by Trimble Navigation, Ltd. 19193323Sed * 4. The name of Trimble Navigation Ltd. may not be used to endorse or 20193323Sed * promote products derived from this software without specific prior 21193323Sed * written permission. 22193323Sed * 23210299Sed * THIS SOFTWARE IS PROVIDED BY TRIMBLE NAVIGATION LTD. ``AS IS'' AND 24193323Sed * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 25203954Srdivacky * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 26203954Srdivacky * ARE DISCLAIMED. IN NO EVENT SHALL TRIMBLE NAVIGATION LTD. BE LIABLE 27193323Sed * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 28193323Sed * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 29223017Sdim * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 30198090Srdivacky * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 31193323Sed * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 32218893Sdim * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 33193323Sed * SUCH DAMAGE. 34193323Sed */ 35223017Sdim 36223017Sdim/* 37223017Sdim * refclock_palisade - clock driver for the Trimble Palisade GPS 38223017Sdim * timing receiver 39234353Sdim * 40223017Sdim * For detailed information on this program, please refer to the html 41223017Sdim * Refclock 29 page accompanying the NTP distribution. 42193323Sed * 43193323Sed * for questions / bugs / comments, contact: 44193323Sed * sven_dietrich@trimble.com 45193323Sed * 46193323Sed * Sven-Thorsten Dietrich 47193323Sed * 645 North Mary Avenue 48193323Sed * Post Office Box 3642 49193323Sed * Sunnyvale, CA 94088-3642 50193323Sed * 51193323Sed */ 52193323Sed 53193323Sed#ifndef _REFCLOCK_PALISADE_H 54193323Sed#define _REFCLOCK_PALISADE_H 55193323Sed 56193323Sed#ifdef HAVE_CONFIG_H 57199481Srdivacky#include "config.h" 58193323Sed#endif 59193323Sed 60193323Sed#if defined HAVE_SYS_MODEM_H 61193323Sed#include <sys/modem.h> 62224145Sdim#define TIOCMSET MCSETA 63224145Sdim#define TIOCMGET MCGETA 64224145Sdim#define TIOCM_RTS MRTS 65199481Srdivacky#endif 66193323Sed 67193323Sed#ifdef HAVE_TERMIOS_H 68193323Sed# ifdef TERMIOS_NEEDS__SVID3 69193323Sed# define _SVID3 70199481Srdivacky# endif 71193323Sed# include <termios.h> 72193323Sed# ifdef TERMIOS_NEEDS__SVID3 73193323Sed# undef _SVID3 74193323Sed# endif 75199481Srdivacky#endif 76193323Sed 77193323Sed#ifdef HAVE_SYS_IOCTL_H 78193323Sed#include <sys/ioctl.h> 79193323Sed#endif 80199481Srdivacky 81193323Sed#include "ntpd.h" 82193323Sed#include "ntp_io.h" 83193323Sed#include "ntp_control.h" 84193323Sed#include "ntp_refclock.h" 85221345Sdim#include "ntp_unixtime.h" 86221345Sdim#include "ntp_stdlib.h" 87221345Sdim 88221345Sdim/* 89221345Sdim * GPS Definitions 90221345Sdim */ 91221345Sdim#define DESCRIPTION "Trimble Palisade GPS" /* Long name */ 92221345Sdim#define PRECISION (-20) /* precision assumed (about 1 us) */ 93221345Sdim#define REFID "GPS\0" /* reference ID */ 94221345Sdim#define TRMB_MINPOLL 4 /* 16 seconds */ 95221345Sdim#define TRMB_MAXPOLL 5 /* 32 seconds */ 96221345Sdim 97221345Sdim/* 98193323Sed * I/O Definitions 99193323Sed */ 100193323Sed#define DEVICE "/dev/palisade%d" /* device name and unit */ 101193323Sed#define SPEED232 B9600 /* uart speed (9600 baud) */ 102193323Sed 103193323Sed/* 104193323Sed * TSIP Report Definitions 105193323Sed */ 106193323Sed#define LENCODE_8F0B 74 /* Length of TSIP 8F-0B Packet & header */ 107193323Sed#define LENCODE_NTP 22 /* Length of Palisade NTP Packet */ 108193323Sed 109193323Sed/* Allowed Sub-Packet ID's */ 110193323Sed#define PACKET_8F0B 0x0B 111193323Sed#define PACKET_NTP 0xAD 112193323Sed 113193323Sed#define DLE 0x10 114193323Sed#define ETX 0x03 115193323Sed 116193323Sed/* parse states */ 117193323Sed#define TSIP_PARSED_EMPTY 0 118193323Sed#define TSIP_PARSED_FULL 1 119193323Sed#define TSIP_PARSED_DLE_1 2 120224145Sdim#define TSIP_PARSED_DATA 3 121224145Sdim#define TSIP_PARSED_DLE_2 4 122224145Sdim 123224145Sdim/* 124193323Sed * Leap-Insert and Leap-Delete are encoded as follows: 125193323Sed * PALISADE_UTC_TIME set and PALISADE_LEAP_PENDING set: INSERT leap 126193323Sed */ 127193323Sed 128193323Sed#define PALISADE_LEAP_INPROGRESS 0x08 /* This is the leap flag */ 129193323Sed#define PALISADE_LEAP_WARNING 0x04 /* GPS Leap Warning (see ICD-200) */ 130193323Sed#define PALISADE_LEAP_PENDING 0x02 /* Leap Pending (24 hours) */ 131193323Sed#define PALISADE_UTC_TIME 0x01 /* UTC time available */ 132193323Sed 133193323Sed#define mb(_X_) (up->rpt_buf[(_X_ + 1)]) /* shortcut for buffer access */ 134193323Sed 135193323Sed/* Conversion Definitions */ 136193323Sed#define GPS_PI (3.1415926535898) 137193323Sed#define R2D (180.0/GPS_PI) 138193323Sed 139193323Sed/* 140193323Sed * Palisade unit control structure. 141193323Sed */ 142193323Sedstruct palisade_unit { 143193323Sed short unit; /* NTP refclock unit number */ 144193323Sed int polled; /* flag to detect noreplies */ 145193323Sed char leap_status; /* leap second flag */ 146193323Sed char rpt_status; /* TSIP Parser State */ 147193323Sed short rpt_cnt; /* TSIP packet length so far */ 148193323Sed char rpt_buf[BMAX]; /* packet assembly buffer */ 149193323Sed}; 150193323Sed 151193323Sed/* 152193323Sed * Function prototypes 153193323Sed */ 154193323Sed 155193323Sedstatic int palisade_start P((int, struct peer *)); 156193323Sedstatic void palisade_shutdown P((int, struct peer *)); 157193323Sedstatic void palisade_receive P((struct peer *)); 158193323Sedstatic void palisade_poll P((int, struct peer *)); 159193323Sedstatic void palisade_io P((struct recvbuf *)); 160193323Sedint palisade_configure P((int, struct peer *)); 161193323Sedint TSIP_decode P((struct peer *)); 162193323Sedlong HW_poll P((struct refclockproc *)); 163193323Sedfloat getfloat P((u_char *)); 164193323Seddouble getdbl P((u_char *)); 165193323Sedshort getint P((u_char *)); 166193323Sed 167193323Sed#endif /* PALISADE_H */ 168193323Sed