154359Sroberto/* 254359Sroberto * This software was developed by the Software and Component Technologies 354359Sroberto * group of Trimble Navigation, Ltd. 454359Sroberto * 582498Sroberto * Copyright (c) 1997, 1998, 1999, 2000 Trimble Navigation Ltd. 654359Sroberto * All rights reserved. 754359Sroberto * 854359Sroberto * Redistribution and use in source and binary forms, with or without 954359Sroberto * modification, are permitted provided that the following conditions 1054359Sroberto * are met: 1154359Sroberto * 1. Redistributions of source code must retain the above copyright 1254359Sroberto * notice, this list of conditions and the following disclaimer. 1354359Sroberto * 2. Redistributions in binary form must reproduce the above copyright 1454359Sroberto * notice, this list of conditions and the following disclaimer in the 1554359Sroberto * documentation and/or other materials provided with the distribution. 1654359Sroberto * 3. All advertising materials mentioning features or use of this software 1754359Sroberto * must display the following acknowledgement: 1854359Sroberto * This product includes software developed by Trimble Navigation, Ltd. 1954359Sroberto * 4. The name of Trimble Navigation Ltd. may not be used to endorse or 2054359Sroberto * promote products derived from this software without specific prior 2154359Sroberto * written permission. 2254359Sroberto * 2354359Sroberto * THIS SOFTWARE IS PROVIDED BY TRIMBLE NAVIGATION LTD. ``AS IS'' AND 2454359Sroberto * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 2554359Sroberto * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 2654359Sroberto * ARE DISCLAIMED. IN NO EVENT SHALL TRIMBLE NAVIGATION LTD. BE LIABLE 2754359Sroberto * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 2854359Sroberto * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 2954359Sroberto * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 3054359Sroberto * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 3154359Sroberto * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 3254359Sroberto * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 3354359Sroberto * SUCH DAMAGE. 3454359Sroberto */ 3554359Sroberto 3654359Sroberto/* 3754359Sroberto * refclock_palisade - clock driver for the Trimble Palisade GPS 3854359Sroberto * timing receiver 3954359Sroberto * 4054359Sroberto * For detailed information on this program, please refer to the html 4154359Sroberto * Refclock 29 page accompanying the NTP distribution. 4254359Sroberto * 4354359Sroberto * for questions / bugs / comments, contact: 4454359Sroberto * sven_dietrich@trimble.com 4554359Sroberto * 4654359Sroberto * Sven-Thorsten Dietrich 4754359Sroberto * 645 North Mary Avenue 4854359Sroberto * Post Office Box 3642 4954359Sroberto * Sunnyvale, CA 94088-3642 5054359Sroberto * 5154359Sroberto */ 5254359Sroberto 53290001Sglebius#ifndef REFCLOCK_PALISADE_H 54290001Sglebius#define REFCLOCK_PALISADE_H 5554359Sroberto 5654359Sroberto#if defined HAVE_SYS_MODEM_H 5754359Sroberto#include <sys/modem.h> 58182007Sroberto#ifndef __QNXNTO__ 5954359Sroberto#define TIOCMSET MCSETA 6054359Sroberto#define TIOCMGET MCGETA 6154359Sroberto#define TIOCM_RTS MRTS 6254359Sroberto#endif 63182007Sroberto#endif 6454359Sroberto 6554359Sroberto#ifdef HAVE_TERMIOS_H 6654359Sroberto# ifdef TERMIOS_NEEDS__SVID3 6754359Sroberto# define _SVID3 6854359Sroberto# endif 6954359Sroberto# include <termios.h> 70290001Sglebius# include <sys/stat.h> 7154359Sroberto# ifdef TERMIOS_NEEDS__SVID3 7254359Sroberto# undef _SVID3 7354359Sroberto# endif 7454359Sroberto#endif 7554359Sroberto 7654359Sroberto#ifdef HAVE_SYS_IOCTL_H 7754359Sroberto#include <sys/ioctl.h> 7854359Sroberto#endif 7954359Sroberto 8054359Sroberto#include "ntpd.h" 8154359Sroberto#include "ntp_io.h" 8254359Sroberto#include "ntp_control.h" 8354359Sroberto#include "ntp_refclock.h" 8454359Sroberto#include "ntp_unixtime.h" 8554359Sroberto#include "ntp_stdlib.h" 8654359Sroberto 8754359Sroberto/* 8854359Sroberto * GPS Definitions 8954359Sroberto */ 9054359Sroberto#define DESCRIPTION "Trimble Palisade GPS" /* Long name */ 9154359Sroberto#define PRECISION (-20) /* precision assumed (about 1 us) */ 9254359Sroberto#define REFID "GPS\0" /* reference ID */ 9382498Sroberto#define TRMB_MINPOLL 4 /* 16 seconds */ 9482498Sroberto#define TRMB_MAXPOLL 5 /* 32 seconds */ 9554359Sroberto 9654359Sroberto/* 9754359Sroberto * I/O Definitions 9854359Sroberto */ 9954359Sroberto#define DEVICE "/dev/palisade%d" /* device name and unit */ 10054359Sroberto#define SPEED232 B9600 /* uart speed (9600 baud) */ 10154359Sroberto 10254359Sroberto/* 10354359Sroberto * TSIP Report Definitions 10454359Sroberto */ 10554359Sroberto#define LENCODE_8F0B 74 /* Length of TSIP 8F-0B Packet & header */ 10654359Sroberto#define LENCODE_NTP 22 /* Length of Palisade NTP Packet */ 10754359Sroberto 108290001Sglebius#define LENCODE_8FAC 68 /* Length of Thunderbolt 8F-AC Position Packet*/ 109290001Sglebius#define LENCODE_8FAB 17 /* Length of Thunderbolt Primary Timing Packet*/ 110290001Sglebius 11154359Sroberto/* Allowed Sub-Packet ID's */ 11254359Sroberto#define PACKET_8F0B 0x0B 11354359Sroberto#define PACKET_NTP 0xAD 11454359Sroberto 115290001Sglebius/* Thunderbolt Packets */ 116290001Sglebius#define PACKET_8FAC 0xAC /* Supplementary Thunderbolt Time Packet */ 117290001Sglebius#define PACKET_8FAB 0xAB /* Primary Thunderbolt Time Packet */ 118290001Sglebius#define PACKET_6D 0x6D /* Supplementary Thunderbolt Tracking Stats */ 119290001Sglebius#define PACKET_41 0x41 /* Thunderbolt I dont know what this packet is, it's not documented on my manual*/ 120290001Sglebius 121290001Sglebius/* Acutime Packets */ 122290001Sglebius#define PACKET_41A 0x41 /* GPS time */ 123290001Sglebius#define PACKET_46 0x46 /* Receiver Health */ 124290001Sglebius 12554359Sroberto#define DLE 0x10 12654359Sroberto#define ETX 0x03 12754359Sroberto 12854359Sroberto/* parse states */ 12954359Sroberto#define TSIP_PARSED_EMPTY 0 13054359Sroberto#define TSIP_PARSED_FULL 1 13154359Sroberto#define TSIP_PARSED_DLE_1 2 13254359Sroberto#define TSIP_PARSED_DATA 3 13354359Sroberto#define TSIP_PARSED_DLE_2 4 13454359Sroberto 13554359Sroberto/* 13654359Sroberto * Leap-Insert and Leap-Delete are encoded as follows: 13754359Sroberto * PALISADE_UTC_TIME set and PALISADE_LEAP_PENDING set: INSERT leap 13854359Sroberto */ 13954359Sroberto 14054359Sroberto#define PALISADE_LEAP_INPROGRESS 0x08 /* This is the leap flag */ 14154359Sroberto#define PALISADE_LEAP_WARNING 0x04 /* GPS Leap Warning (see ICD-200) */ 14254359Sroberto#define PALISADE_LEAP_PENDING 0x02 /* Leap Pending (24 hours) */ 14354359Sroberto#define PALISADE_UTC_TIME 0x01 /* UTC time available */ 14454359Sroberto 14554359Sroberto#define mb(_X_) (up->rpt_buf[(_X_ + 1)]) /* shortcut for buffer access */ 14654359Sroberto 14754359Sroberto/* Conversion Definitions */ 14854359Sroberto#define GPS_PI (3.1415926535898) 14954359Sroberto#define R2D (180.0/GPS_PI) 15054359Sroberto 15154359Sroberto/* 152290001Sglebius * Structure for build data packets for send (thunderbolt uses it only) 153290001Sglebius * taken from Markus Prosch 154290001Sglebius */ 155290001Sglebiusstruct packettx 156290001Sglebius{ 157290001Sglebius short size; 158290001Sglebius u_char *data; 159290001Sglebius}; 160290001Sglebius 161290001Sglebius/* 16254359Sroberto * Palisade unit control structure. 16354359Sroberto */ 16454359Srobertostruct palisade_unit { 16554359Sroberto short unit; /* NTP refclock unit number */ 16654359Sroberto int polled; /* flag to detect noreplies */ 16754359Sroberto char leap_status; /* leap second flag */ 16854359Sroberto char rpt_status; /* TSIP Parser State */ 16954359Sroberto short rpt_cnt; /* TSIP packet length so far */ 170290001Sglebius char rpt_buf[BMAX]; /* packet assembly buffer */ 171132451Sroberto int type; /* Clock mode type */ 172290001Sglebius int month; /* for LEAP filter */ 17354359Sroberto}; 17454359Sroberto 17554359Sroberto/* 17654359Sroberto * Function prototypes 17754359Sroberto */ 17854359Sroberto 179290001Sglebiusstatic int palisade_start (int, struct peer *); 180290001Sglebiusstatic void palisade_shutdown (int, struct peer *); 181290001Sglebiusstatic void palisade_receive (struct peer *); 182290001Sglebiusstatic void palisade_poll (int, struct peer *); 183290001Sglebiusstatic void palisade_io (struct recvbuf *); 184290001Sglebiusint palisade_configure (int, struct peer *); 185290001Sglebiusint TSIP_decode (struct peer *); 186290001Sglebiuslong HW_poll (struct refclockproc *); 187290001Sglebiusstatic double getdbl (u_char *); 188290001Sglebiusstatic short getint (u_char *); 189290001Sglebiusstatic int32 getlong (u_char *); 19054359Sroberto 191290001Sglebius 192290001Sglebius#ifdef PALISADE_SENDCMD_RESURRECTED 193290001Sglebiusstatic void sendcmd (struct packettx *buffer, int c); 194290001Sglebius#endif 195290001Sglebiusstatic void sendsupercmd (struct packettx *buffer, int c1, int c2); 196290001Sglebiusstatic void sendbyte (struct packettx *buffer, int b); 197290001Sglebiusstatic void sendint (struct packettx *buffer, int a); 198290001Sglebiusstatic int sendetx (struct packettx *buffer, int fd); 199290001Sglebiusstatic void init_thunderbolt (int fd); 200290001Sglebiusstatic void init_acutime (int fd); 201290001Sglebius 202290001Sglebius#endif /* REFCLOCK_PALISADE_H */ 203