]> CyberLeo.Net >> Repos - FreeBSD/releng/10.0.git/blob - contrib/ntp/ntpd/refclock_palisade.h
- Copy stable/10 (r259064) to releng/10.0 as part of the
[FreeBSD/releng/10.0.git] / contrib / ntp / ntpd / refclock_palisade.h
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, 2000   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 #ifndef __QNXNTO__
63 #define TIOCMSET MCSETA
64 #define TIOCMGET MCGETA
65 #define TIOCM_RTS MRTS
66 #endif
67 #endif
68
69 #ifdef HAVE_TERMIOS_H
70 # ifdef TERMIOS_NEEDS__SVID3
71 #  define _SVID3
72 # endif
73 # include <termios.h>
74 # ifdef TERMIOS_NEEDS__SVID3
75 #  undef _SVID3
76 # endif
77 #endif
78
79 #ifdef HAVE_SYS_IOCTL_H
80 #include <sys/ioctl.h>
81 #endif
82
83 #include "ntpd.h"
84 #include "ntp_io.h"
85 #include "ntp_control.h"
86 #include "ntp_refclock.h"
87 #include "ntp_unixtime.h"
88 #include "ntp_stdlib.h"
89
90 /*
91  * GPS Definitions
92  */
93 #define DESCRIPTION     "Trimble Palisade GPS" /* Long name */
94 #define PRECISION       (-20)   /* precision assumed (about 1 us) */
95 #define REFID           "GPS\0" /* reference ID */
96 #define TRMB_MINPOLL    4       /* 16 seconds */
97 #define TRMB_MAXPOLL    5       /* 32 seconds */
98
99 /*
100  * I/O Definitions
101  */
102 #define DEVICE          "/dev/palisade%d"       /* device name and unit */
103 #define SPEED232        B9600                   /* uart speed (9600 baud) */
104
105 /*
106  * TSIP Report Definitions
107  */
108 #define LENCODE_8F0B    74      /* Length of TSIP 8F-0B Packet & header */
109 #define LENCODE_NTP     22      /* Length of Palisade NTP Packet */
110
111 /* Allowed Sub-Packet ID's */
112 #define PACKET_8F0B     0x0B
113 #define PACKET_NTP      0xAD
114
115 #define DLE 0x10
116 #define ETX 0x03
117
118 /* parse states */
119 #define TSIP_PARSED_EMPTY       0       
120 #define TSIP_PARSED_FULL        1
121 #define TSIP_PARSED_DLE_1       2
122 #define TSIP_PARSED_DATA        3
123 #define TSIP_PARSED_DLE_2       4
124
125 /* 
126  * Leap-Insert and Leap-Delete are encoded as follows:
127  *      PALISADE_UTC_TIME set   and PALISADE_LEAP_PENDING set: INSERT leap
128  */
129
130 #define PALISADE_LEAP_INPROGRESS 0x08 /* This is the leap flag                  */
131 #define PALISADE_LEAP_WARNING    0x04 /* GPS Leap Warning (see ICD-200) */
132 #define PALISADE_LEAP_PENDING    0x02 /* Leap Pending (24 hours)                */
133 #define PALISADE_UTC_TIME        0x01 /* UTC time available                             */
134
135 #define mb(_X_) (up->rpt_buf[(_X_ + 1)]) /* shortcut for buffer access  */
136
137 /* Conversion Definitions */
138 #define GPS_PI          (3.1415926535898)
139 #define R2D             (180.0/GPS_PI)
140
141 /*
142  * Palisade unit control structure.
143  */
144 struct palisade_unit {
145         short           unit;           /* NTP refclock unit number */
146         int             polled;         /* flag to detect noreplies */
147         char            leap_status;    /* leap second flag */
148         char            rpt_status;     /* TSIP Parser State */
149         short           rpt_cnt;        /* TSIP packet length so far */
150         char            rpt_buf[BMAX];   /* packet assembly buffer */
151         int             type;           /* Clock mode type */
152 };
153
154 /*
155  * Function prototypes
156  */
157
158 static  int     palisade_start          P((int, struct peer *));
159 static  void    palisade_shutdown       P((int, struct peer *));
160 static  void    palisade_receive        P((struct peer *));
161 static  void    palisade_poll           P((int, struct peer *));
162 static  void    palisade_io             P((struct recvbuf *));
163 int             palisade_configure      P((int, struct peer *));
164 int             TSIP_decode             P((struct peer *));
165 long            HW_poll                 P((struct refclockproc *));
166 float           getfloat                P((u_char *)); 
167 double          getdbl                  P((u_char *));
168 short           getint                  P((u_char *));
169
170 #endif /* PALISADE_H */