refclock_palisade.h revision 54359
1/* 2 * This software was developed by the Software and Component Technologies 3 * group of Trimble Navigation, Ltd. 4 * 5 * Copyright (c) 1997, 1998, 1999 Trimble Navigation Ltd. 6 * All rights reserved. 7 * 8 * Redistribution and use in source and binary forms, with or without 9 * modification, are permitted provided that the following conditions 10 * are met: 11 * 1. Redistributions of source code must retain the above copyright 12 * notice, this list of conditions and the following disclaimer. 13 * 2. Redistributions in binary form must reproduce the above copyright 14 * notice, this list of conditions and the following disclaimer in the 15 * documentation and/or other materials provided with the distribution. 16 * 3. All advertising materials mentioning features or use of this software 17 * must display the following acknowledgement: 18 * This product includes software developed by Trimble Navigation, Ltd. 19 * 4. The name of Trimble Navigation Ltd. may not be used to endorse or 20 * promote products derived from this software without specific prior 21 * written permission. 22 * 23 * THIS SOFTWARE IS PROVIDED BY TRIMBLE NAVIGATION LTD. ``AS IS'' AND 24 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 25 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 26 * ARE DISCLAIMED. IN NO EVENT SHALL TRIMBLE NAVIGATION LTD. BE LIABLE 27 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 28 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 29 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 30 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 31 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 32 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 33 * SUCH DAMAGE. 34 */ 35 36/* 37 * refclock_palisade - clock driver for the Trimble Palisade GPS 38 * timing receiver 39 * 40 * For detailed information on this program, please refer to the html 41 * Refclock 29 page accompanying the NTP distribution. 42 * 43 * for questions / bugs / comments, contact: 44 * sven_dietrich@trimble.com 45 * 46 * Sven-Thorsten Dietrich 47 * 645 North Mary Avenue 48 * Post Office Box 3642 49 * Sunnyvale, CA 94088-3642 50 * 51 */ 52 53#ifndef _REFCLOCK_PALISADE_H 54#define _REFCLOCK_PALISADE_H 55 56#ifdef HAVE_CONFIG_H 57#include "config.h" 58#endif 59 60#if defined HAVE_SYS_MODEM_H 61#include <sys/modem.h> 62#define TIOCMSET MCSETA 63#define TIOCMGET MCGETA 64#define TIOCM_RTS MRTS 65#endif 66 67#ifdef HAVE_TERMIOS_H 68# ifdef TERMIOS_NEEDS__SVID3 69# define _SVID3 70# endif 71# include <termios.h> 72# ifdef TERMIOS_NEEDS__SVID3 73# undef _SVID3 74# endif 75#endif 76 77#ifdef HAVE_SYS_IOCTL_H 78#include <sys/ioctl.h> 79#endif 80 81#include "ntpd.h" 82#include "ntp_io.h" 83#include "ntp_control.h" 84#include "ntp_refclock.h" 85#include "ntp_unixtime.h" 86#include "ntp_stdlib.h" 87 88/* 89 * GPS Definitions 90 */ 91#define DESCRIPTION "Trimble Palisade GPS" /* Long name */ 92#define PRECISION (-20) /* precision assumed (about 1 us) */ 93#define REFID "GPS\0" /* reference ID */ 94#define TRMB_MINPOLL 5 /* 16 seconds */ 95#define TRMB_MAXPOLL 7 /* 64 seconds */ 96 97/* 98 * I/O Definitions 99 */ 100#define DEVICE "/dev/palisade%d" /* device name and unit */ 101#define SPEED232 B9600 /* uart speed (9600 baud) */ 102 103/* 104 * TSIP Report Definitions 105 */ 106#define LENCODE_8F0B 74 /* Length of TSIP 8F-0B Packet & header */ 107#define LENCODE_NTP 22 /* Length of Palisade NTP Packet */ 108 109/* Allowed Sub-Packet ID's */ 110#define PACKET_8F0B 0x0B 111#define PACKET_NTP 0xAD 112 113#define DLE 0x10 114#define ETX 0x03 115 116/* parse states */ 117#define TSIP_PARSED_EMPTY 0 118#define TSIP_PARSED_FULL 1 119#define TSIP_PARSED_DLE_1 2 120#define TSIP_PARSED_DATA 3 121#define TSIP_PARSED_DLE_2 4 122 123/* 124 * Leap-Insert and Leap-Delete are encoded as follows: 125 * PALISADE_UTC_TIME set and PALISADE_LEAP_PENDING set: INSERT leap 126 */ 127 128#define PALISADE_LEAP_INPROGRESS 0x08 /* This is the leap flag */ 129#define PALISADE_LEAP_WARNING 0x04 /* GPS Leap Warning (see ICD-200) */ 130#define PALISADE_LEAP_PENDING 0x02 /* Leap Pending (24 hours) */ 131#define PALISADE_UTC_TIME 0x01 /* UTC time available */ 132 133#define mb(_X_) (up->rpt_buf[(_X_ + 1)]) /* shortcut for buffer access */ 134 135/* Conversion Definitions */ 136#define GPS_PI (3.1415926535898) 137#define R2D (180.0/GPS_PI) 138 139/* 140 * Palisade unit control structure. 141 */ 142struct palisade_unit { 143 short unit; /* NTP refclock unit number */ 144 int polled; /* flag to detect noreplies */ 145 char leap_status; /* leap second flag */ 146 char rpt_status; /* TSIP Parser State */ 147 short rpt_cnt; /* TSIP packet length so far */ 148 char rpt_buf[BMAX]; /* packet assembly buffer */ 149}; 150 151/* 152 * Function prototypes 153 */ 154 155static int palisade_start P((int, struct peer *)); 156static void palisade_shutdown P((int, struct peer *)); 157static void palisade_receive P((struct peer *)); 158static void palisade_poll P((int, struct peer *)); 159static void palisade_io P((struct recvbuf *)); 160int palisade_configure P((int, struct peer *)); 161int TSIP_decode P((struct peer *)); 162long HW_poll P((struct refclockproc *)); 163float getfloat P((u_char *)); 164double getdbl P((u_char *)); 165short getint P((u_char *)); 166 167#endif /* PALISADE_H */ 168