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