1 /* $NetBSD: mbg_gps166.h,v 1.3 2006/06/11 19:34:09 kardel Exp $ */
4 * /src/NTP/REPOSITORY/ntp4-dev/include/mbg_gps166.h,v 4.7 2006/06/22 18:41:43 kardel RELEASE_20060622_A
6 * mbg_gps166.h,v 4.7 2006/06/22 18:41:43 kardel RELEASE_20060622_A
8 * Created: Sun Jul 20 09:20:50 1997
10 * File GPSSERIO.H Copyright (c) by Meinberg Funkuhren (www.meinberg.de)
13 * Copyright (c) 1997-2005 by Frank Kardel <kardel <AT> ntp.org>
15 * Redistribution and use in source and binary forms, with or without
16 * modification, are permitted provided that the following conditions
18 * 1. Redistributions of source code must retain the above copyright
19 * notice, this list of conditions and the following disclaimer.
20 * 2. Redistributions in binary form must reproduce the above copyright
21 * notice, this list of conditions and the following disclaimer in the
22 * documentation and/or other materials provided with the distribution.
23 * 3. Neither the name of the author nor the names of its contributors
24 * may be used to endorse or promote products derived from this software
25 * without specific prior written permission.
27 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
28 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
29 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
30 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
31 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
32 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
33 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
34 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
35 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
36 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
44 /***************************************************************************/
46 /* File: GPSSERIO.H 4.1 */
48 /* Project: Common C Library */
50 /* Compiler: Borland C++ */
52 /* Author: M. Burnicki, Meinberg Funkuhren */
56 /* This file defines structures and codes to be used to access GPS166 */
57 /* via its serial interface COM0. COM0 should be set to a high baud */
58 /* rate, default is 19200. */
60 /* Standard GPS166 serial operation is to send a time string that is */
61 /* compatible with Meinberg UA31 or PZF535 DCF77 radio remote clocks. */
62 /* That string can be transmitted automatically once per second, once */
63 /* per minute or on request per ASCII '?'. */
65 /* Parameter setup or parameter readout works using blocks of binary */
66 /* data which have to be isolated from the standard string. A block of */
67 /* data starts with a SOH code (ASCII Start Of Header, 0x01) followed */
68 /* by a message header with constant length and a data portion with */
69 /* variable length. The first field (cmd) of the message header holds */
70 /* the command code rsp. the type of data to be transmitted. The next */
71 /* field (len) gives the number of data bytes that are transmitted */
72 /* after the header. This number ranges from 0 to sizeof( MSG_DATA ). */
73 /* The third field (data_csum) holds a checksum of all data bytes and */
74 /* the last field of the header finally holds the checksum of the. */
77 /***************************************************************************/
79 /* the control codes defined below are to be or'ed with a command/type code */
81 #define GPS_REQACK 0x8000 /* to GPS166: request acknowledge */
82 #define GPS_ACK 0x4000 /* from GPS166: acknowledge a command */
83 #define GPS_NACK 0x2000 /* from GPS166: error receiving command */
85 #define GPS_CTRL_MSK 0xF000 /* masks control code from command */
88 /* The codes below specify commands/types of data to be supplied to GPS166: */
90 /* GPS166 auto-message to host */
91 /* þ host request, GPS166 response */
92 /* þ þ host download to GPS166 */
96 GPS_AUTO_ON
= 0x000, /* þ þ þ X þ enable auto-messages from GPS166 */
97 GPS_AUTO_OFF
, /* þ þ þ X þ disable auto-messages from GPS166 */
98 GPS_SW_REV
, /* þ þ X þ þ request software revision */
99 GPS_STAT
, /* þ þ X þ þ request status of buffered variables */
100 GPS_TIME
, /* þ X þ þ X þ current time or capture or init board time */
101 GPS_POS_XYZ
, /* þ þ X þ X þ current position in ECEF coords */
102 GPS_POS_LLA
, /* þ þ X þ X þ current position in geographic coords */
103 GPS_TZDL
, /* þ þ X þ X þ time zone / daylight saving */
104 GPS_PORT_PARM
, /* þ þ X þ X þ parameters of the serial ports */
105 GPS_SYNTH
, /* þ þ X þ X þ synthesizer's frequency and phase */
106 GPS_ANT_INFO
, /* þ X þ X þ þ time diff after antenna disconnect */
107 GPS_UCAP
, /* þ X þ X þ þ user capture */
110 GPS_CFGH
= 0x100, /* þ þ X þ X þ SVs' configuration and health codes */
111 GPS_ALM
, /* þ þ X þ X þ one SV's almanac */
112 GPS_EPH
, /* þ þ X þ X þ one SV's ephemeris */
113 GPS_UTC
, /* þ þ X þ X þ UTC correction parameters */
114 GPS_IONO
, /* þ þ X þ X þ ionospheric correction parameters */
115 GPS_ASCII_MSG
/* þ þ X þ þ the GPS ASCII message */
119 * modelled after GPSDEFS.H Revision 1.5
121 /***************************************************************************/
123 /* File: GPSDEFS.H 4.1 */
125 /* Project: Common C Library */
127 /* Compiler: Borland C++ */
129 /* Author: M. Burnicki, Meinberg Funkuhren */
133 /* General definitions to be used with GPS166 */
134 /* GPS166 Rev. 1.23 or above */
136 /* Modifications: see file GPSLIB.TXT */
138 /***************************************************************************/
140 /* the type of various checksums */
142 #ifndef _CSUM_DEFINED
143 typedef unsigned short CSUM
;
144 # define _CSUM_DEFINED
147 /* the message header */
150 unsigned short gps_cmd
;
151 unsigned short gps_len
;
152 unsigned short gps_data_csum
;
153 unsigned short gps_hdr_csum
;
156 /* a struct used to hold the software revision information */
159 unsigned short code
; /* e.g. 0x0120 means rev. 1.20 */
160 unsigned char name
[17]; /* used to identify customized versions */
163 /* GPS ASCII message */
166 CSUM csum
; /* checksum of the remaining bytes */
167 short valid
; /* flag data are valid */
168 char s
[23]; /* 22 chars GPS ASCII message plus trailing zero */
171 #define MIN_SVNO 1 /* min. SV number */
172 #define MAX_SVNO 32 /* max. SV number */
173 #define N_SVNO ( MAX_SVNO - MIN_SVNO + 1) /* number of possibly active SVs */
176 typedef short SVNO
; /* the number of a SV */
177 typedef unsigned short HEALTH
; /* a SV's health code */
178 typedef unsigned short CFG
; /* a SV's configuration code */
179 typedef unsigned short IOD
; /* Issue-Of-Data code */
181 /* Date and time referred to the linear time scale defined by GPS. */
182 /* GPS time is defined by the number of weeks since midnight from */
183 /* January 5, 1980 to January 6, 1980 plus the number of seconds of */
184 /* the current week plus fractions of a second. GPS time differs from */
185 /* UTC because UTC is corrected with leap seconds while GPS time scale */
189 unsigned short wn
; /* the week number since GPS has been installed */
190 unsigned long sec
; /* the second of that week */
191 unsigned long tick
; /* fractions of a second; scale: 1E-7 */
195 /* Local date and time computed from GPS time. The current number */
196 /* of leap seconds have to be added to get UTC from GPS time. */
197 /* Additional corrections could have been made according to the */
198 /* time zone/daylight saving parameters (TZDL, see below) defined */
199 /* by the user. The status field can be checked to see which corrections */
200 /* have been applied. */
204 short year
; /* 0..9999 */
205 char month
; /* 1..12 */
206 char mday
; /* 1..31 */
207 short yday
; /* 1..366 */
208 char wday
; /* 0..6 == Sun..Sat */
209 char hour
; /* 0..23 */
210 char minute
; /* 0..59 */
211 char second
; /* 0..59 */
212 long frac
; /* fractions of a second, scale 1E-7 */
213 long offs_from_utc
; /* local time's offset from UTC */
214 unsigned short status
; /* flags */
217 /* status flags used with conversion from GPS time to local time */
219 # define TM_UTC 0x01 /* UTC correction has been made */
220 # define TM_LOCAL 0x02 /* UTC has been converted to local time */
221 # define TM_DL_ANN 0x04 /* state of daylight saving is going to change */
222 # define TM_DL_ENB 0x08 /* daylight saving is enabled */
223 # define TM_LS_ANN 0x10 /* leap second will be inserted */
224 # define TM_LS_ENB 0x20 /* current second is leap second */
230 /* the status flags below are defined starting with rev. 1.32 */
232 #define TM_ANT_DISCONN 0x1000 /* antenna currently disconnected */
233 #define TM_SYN_FLAG 0x2000 /* TIME_SYN output is low */
234 #define TM_NO_SYNC 0x4000 /* not sync'ed after reset */
235 #define TM_NO_POS 0x8000 /* position not computed after reset, */
238 /* a struct used to transmit information on date and time */
241 short channel
; /* -1: the current time; 0, 1: capture 0, 1 */
242 T_GPS t
; /* time in GPS format */
243 TM tm
; /* that time converted to local time */
248 /* Two types of variables used to store a position. Type XYZ is */
249 /* used with a position in earth centered, earth fixed (ECEF) */
250 /* coordinates whereas type LLA holds such a position converted */
251 /* to geographic coordinates as defined by WGS84 (World Geodetic */
252 /* System from 1984). */
255 /* sequence and number of components of a cartesian position */
256 enum { XP
, YP
, ZP
, N_XYZ
};
258 /* a type of array holding a cartesian position */
259 typedef l_fp XYZ
[N_XYZ
]; /* values are in [m] */
261 # define _XYZ_DEFINED
266 /* sequence and number of components of a geographic position */
267 enum { LAT
, LON
, ALT
, N_LLA
}; /* latitude, longitude, altitude */
269 /* a type of array holding a geographic position */
270 typedef l_fp LLA
[N_LLA
]; /* lon, lat in [rad], alt in [m] */
272 # define _LLA_DEFINED
275 /* Synthesizer parameters. Synthesizer frequency is expressed as a */
276 /* four digit decimal number (freq) to be multiplied by 0.1 Hz and an */
277 /* base 10 exponent (range). If the effective frequency is less than */
278 /* 10 kHz its phase is synchronized corresponding to the variable phase. */
279 /* Phase may be in a range from -360° to +360° with a resolution of 0.1°, */
280 /* so the resulting numbers to be stored are in a range of -3600 to +3600. */
283 /* Assume the value of freq is 2345 (decimal) and the value of phase is 900. */
284 /* If range == 0 the effective frequency is 234.5 Hz with a phase of +90°. */
285 /* If range == 1 the synthesizer will generate a 2345 Hz output frequency */
289 /* If freq == 0 the synthesizer is disabled. If range == 0 the least */
290 /* significant digit of freq is limited to 0, 3, 5 or 6. The resulting */
291 /* frequency is shown in the examples below: */
292 /* freq == 1230 --> 123.0 Hz */
293 /* freq == 1233 --> 123 1/3 Hz (real 1/3 Hz, NOT 123.3 Hz) */
294 /* freq == 1235 --> 123.5 Hz */
295 /* freq == 1236 --> 123 2/3 Hz (real 2/3 Hz, NOT 123.6 Hz) */
297 /* If range == MAX_RANGE the value of freq must not exceed 1200, so the */
298 /* output frequency is limited to 12 MHz. */
300 /* Phase will be ignored if the resulting frequency is greater or equal */
303 #define MAX_SYNTH_FREQ 1200 /* if range == MAX_SYNTH_RANGE */
304 #define MIN_SYNTH_RANGE 0
305 #define MAX_SYNTH_RANGE 5
306 #define MAX_SYNTH_PHASE 3600
309 short freq
; /* four digits used; scale: 0.1; e.g. 1234 -> 123.4 Hz */
310 short range
; /* scale factor for freq; 0..MAX_SYNTH_RANGE */
311 short phase
; /* -MAX_SYNTH_PHASE..+MAX_SYNTH_PHASE; >0 -> pulses later */
316 /* Time zone/daylight saving parameters. */
318 /* the name of a time zone, 5 characters plus trailing zero */
319 typedef char TZ_NAME
[6];
322 long offs
; /* offset from UTC to local time [sec] */
323 long offs_dl
; /* additional offset if daylight saving enabled [sec] */
324 TM tm_on
; /* date/time when daylight saving starts */
325 TM tm_off
; /* date/time when daylight saving ends */
326 TZ_NAME name
[2]; /* names without and with daylight saving enabled */
329 /* The constant below is defined beginning with software rev. 1.29. */
330 /* If the year in tzdl.tmon and tzdl.tm_off is or'ed with that constant, */
331 /* the receiver automatically generates daylight saving year by year. */
332 /* See GPSLIB.TXT for more information. */
334 #define DL_AUTO_FLAG 0x8000
337 /* for automatic daylight saving enable/disable in Central Europe, */
338 /* the variables are to be set as shown below: */
339 /* offs = 3600L one hour from UTC */
340 /* offs_dl = 3600L one additional hour if daylight saving enabled */
341 /* tm_on = first Sunday from March 25, 02:00:00h ( year |= DL_AUTO_FLAG ) */
342 /* tm_off = first Sunday from Sept 24, 03:00:00h ( year |= DL_AUTO_FLAG ) */
343 /* name[0] == "MEZ " name if daylight saving not enabled */
344 /* name[1] == "MESZ " name if daylight saving is enabled */
349 /* the structure below was defined in rev. 1.31. It reflects the status */
350 /* of the antenna, the times of last disconnect/reconnect and the boards */
351 /* clock offset after the phase of disconnection. */
354 short status
; /* current status of antenna */
355 TM tm_disconn
; /* time of antenna disconnect */
356 TM tm_reconn
; /* time of antenna reconnect */
357 long delta_t
; /* clock offset at reconnect time, units: TICKS_PER_SEC */
361 /* the status field may be set to one of the values below: */
364 ANT_INVALID
, /* struct not set yet because ant. has not been disconn. */
365 ANT_DISCONN
, /* ant. now disconn., tm_reconn and delta_t not set */
366 ANT_RECONN
/* ant. has been disconn. and reconn., all fields valid */
370 /* Summary of configuration and health data of all SVs. */
373 CSUM csum
; /* checksum of the remaining bytes */
374 short valid
; /* flag data are valid */
376 T_GPS tot_51
; /* time of transmission, page 51 */
377 T_GPS tot_63
; /* time of transmission, page 63 */
378 T_GPS t0a
; /* complete reference time almanac */
380 CFG cfg
[N_SVNO
]; /* SV configuration from page 63 */
381 HEALTH health
[N_SVNO
]; /* SV health from pages 51, 63 */
386 /* UTC correction parameters */
389 CSUM csum
; /* checksum of the remaining bytes */
390 short valid
; /* flag data are valid */
392 T_GPS t0t
; /* Reference Time UTC Parameters [sec] */
393 l_fp A0
; /* ± Clock Correction Coefficient 0 [sec] */
394 l_fp A1
; /* ± Clock Correction Coefficient 1 [sec/sec] */
396 ushort WNlsf
; /* week number of nearest leap second */
397 short DNt
; /* the day number at the end of which LS is inserted */
398 char delta_tls
; /* */
399 char delta_tlsf
; /* */
403 /* a struct used to hold the settings of a serial port */
405 #ifndef _COM_PARM_DEFINED
406 typedef long BAUD_RATE
;
408 /* indices used to identify a parameter in the framing string */
409 enum { F_DBITS
, F_PRTY
, F_STBITS
};
411 /* types of handshake */
412 enum { HS_NONE
, HS_XONXOFF
, HS_RTSCTS
};
415 BAUD_RATE baud_rate
; /* e.g. 19200L */
416 char framing
[4]; /* e.g. "8N1" */
417 short handshake
; /* a numeric value, only HS_NONE supported yet */
420 #define _COM_PARM_DEFINED
425 /* the codes below define what has to comes out of the serial ports */
427 enum { STR_ON_REQ
, STR_PER_SEC
,
428 STR_PER_MIN
, N_STR_MODE_0
, /* COM0 and COM1 */
429 STR_UCAP
= N_STR_MODE_0
,
430 STR_UCAP_REQ
, N_STR_MODE_1
/* COM1 only */
434 #define N_COM 2 /* the number of serial ports */
436 /* the structure used to store the modes of both serial ports */
439 COM_PARM com
[N_COM
]; /* COM0 and COM1 settings */
440 u_char mode
[N_COM
]; /* COM0 and COM1 output mode */
443 /* Ephemeris parameters of one specific SV. Needed to compute the position */
444 /* of a satellite at a given time with high precision. Valid for an */
445 /* interval of 4 to 6 hours from start of transmission. */
448 CSUM csum
; /* checksum of the remaining bytes */
449 short valid
; /* flag data are valid */
451 HEALTH health
; /* health indication of transmitting SV [---] */
452 IOD IODC
; /* Issue Of Data, Clock */
453 IOD IODE2
; /* Issue of Data, Ephemeris (Subframe 2) */
454 IOD IODE3
; /* Issue of Data, Ephemeris (Subframe 3) */
455 T_GPS tt
; /* time of transmission */
456 T_GPS t0c
; /* Reference Time Clock [---] */
457 T_GPS t0e
; /* Reference Time Ephemeris [---] */
459 l_fp sqrt_A
; /* Square Root of semi-major Axis [sqrt(m)] */
460 l_fp e
; /* Eccentricity [---] */
461 l_fp M0
; /* ± Mean Anomaly at Ref. Time [rad] */
462 l_fp omega
; /* ± Argument of Perigee [rad] */
463 l_fp OMEGA0
; /* ± Longit. of Asc. Node of orbit plane [rad] */
464 l_fp OMEGADOT
; /* ± Rate of Right Ascension [rad/sec] */
465 l_fp deltan
; /* ± Mean Motion Diff. from computed value [rad/sec] */
466 l_fp i0
; /* ± Inclination Angle [rad] */
467 l_fp idot
; /* ± Rate of Inclination Angle [rad/sec] */
468 l_fp crc
; /* ± Cosine Corr. Term to Orbit Radius [m] */
469 l_fp crs
; /* ± Sine Corr. Term to Orbit Radius [m] */
470 l_fp cuc
; /* ± Cosine Corr. Term to Arg. of Latitude [rad] */
471 l_fp cus
; /* ± Sine Corr. Term to Arg. of Latitude [rad] */
472 l_fp cic
; /* ± Cosine Corr. Term to Inclination Angle [rad] */
473 l_fp cis
; /* ± Sine Corr. Term to Inclination Angle [rad] */
475 l_fp af0
; /* ± Clock Correction Coefficient 0 [sec] */
476 l_fp af1
; /* ± Clock Correction Coefficient 1 [sec/sec] */
477 l_fp af2
; /* ± Clock Correction Coefficient 2 [sec/sec²] */
478 l_fp tgd
; /* ± estimated group delay differential [sec] */
480 u_short URA
; /* predicted User Range Accuracy */
482 u_char L2code
; /* code on L2 channel [---] */
483 u_char L2flag
; /* L2 P data flag [---] */
487 /* Almanac parameters of one specific SV. A reduced precision set of */
488 /* parameters used to check if a satellite is in view at a given time. */
489 /* Valid for an interval of more than 7 days from start of transmission. */
492 CSUM csum
; /* checksum of the remaining bytes */
493 short valid
; /* flag data are valid */
495 HEALTH health
; /* [---] */
496 T_GPS t0a
; /* Reference Time Almanac [sec] */
498 l_fp sqrt_A
; /* Square Root of semi-major Axis [sqrt(m)] */
499 l_fp e
; /* Eccentricity [---] */
501 l_fp M0
; /* ± Mean Anomaly at Ref. Time [rad] */
502 l_fp omega
; /* ± Argument of Perigee [rad] */
503 l_fp OMEGA0
; /* ± Longit. of Asc. Node of orbit plane [rad] */
504 l_fp OMEGADOT
; /* ± Rate of Right Ascension [rad/sec] */
505 l_fp deltai
; /* ± [rad] */
506 l_fp af0
; /* ± Clock Correction Coefficient 0 [sec] */
507 l_fp af1
; /* ± Clock Correction Coefficient 1 [sec/sec] */
511 /* ionospheric correction parameters */
514 CSUM csum
; /* checksum of the remaining bytes */
515 short valid
; /* flag data are valid */
517 l_fp alpha_0
; /* Ionosph. Corr. Coeff. Alpha 0 [sec] */
518 l_fp alpha_1
; /* Ionosph. Corr. Coeff. Alpha 1 [sec/deg] */
519 l_fp alpha_2
; /* Ionosph. Corr. Coeff. Alpha 2 [sec/deg^2] */
520 l_fp alpha_3
; /* Ionosph. Corr. Coeff. Alpha 3 [sec/deg^3] */
522 l_fp beta_0
; /* Ionosph. Corr. Coeff. Beta 0 [sec] */
523 l_fp beta_1
; /* Ionosph. Corr. Coeff. Beta 1 [sec/deg] */
524 l_fp beta_2
; /* Ionosph. Corr. Coeff. Beta 2 [sec/deg^2] */
525 l_fp beta_3
; /* Ionosph. Corr. Coeff. Beta 3 [sec/deg^3] */
529 void mbg_tm_str
P((char **, TM
*, int));
530 void mbg_tgps_str
P((char **, T_GPS
*, int));
531 void get_mbg_header
P((unsigned char **, GPS_MSG_HDR
*));
532 void put_mbg_header
P((unsigned char **, GPS_MSG_HDR
*));
533 void get_mbg_sw_rev
P((unsigned char **, SW_REV
*));
534 void get_mbg_ascii_msg
P((unsigned char **, ASCII_MSG
*));
535 void get_mbg_svno
P((unsigned char **, SVNO
*));
536 void get_mbg_health
P((unsigned char **, HEALTH
*));
537 void get_mbg_cfg
P((unsigned char **, CFG
*));
538 void get_mbg_tgps
P((unsigned char **, T_GPS
*));
539 void get_mbg_tm
P((unsigned char **, TM
*));
540 void get_mbg_ttm
P((unsigned char **, TTM
*));
541 void get_mbg_synth
P((unsigned char **, SYNTH
*));
542 void get_mbg_tzdl
P((unsigned char **, TZDL
*));
543 void get_mbg_antinfo
P((unsigned char **, ANT_INFO
*));
544 void get_mbg_cfgh
P((unsigned char **, CFGH
*));
545 void get_mbg_utc
P((unsigned char **, UTC
*));
546 void get_mbg_lla
P((unsigned char **, LLA
));
547 void get_mbg_xyz
P((unsigned char **, XYZ
));
548 void get_mbg_portparam
P((unsigned char **, PORT_PARM
*));
549 void get_mbg_eph
P((unsigned char **, EPH
*));
550 void get_mbg_alm
P((unsigned char **, ALM
*));
551 void get_mbg_iono
P((unsigned char **, IONO
*));
553 unsigned long mbg_csum
P((unsigned char *, unsigned int));
560 * Revision 4.7 2006/06/22 18:41:43 kardel
561 * clean up signedness (gcc 4)
563 * Revision 4.6 2005/10/07 22:11:56 kardel
564 * bounded buffer implementation
566 * Revision 4.5.2.1 2005/09/25 10:23:48 kardel
567 * support bounded buffers
569 * Revision 4.5 2005/06/25 10:58:45 kardel
570 * add missing log keywords
572 * Revision 4.1 1998/06/12 15:07:30 kardel
575 * Revision 4.0 1998/04/10 19:50:42 kardel
576 * Start 4.0 release version numbering
578 * Revision 1.1 1998/04/10 19:27:34 kardel
579 * initial NTP VERSION 4 integration of PARSE with GPS166 binary support
581 * Revision 1.1 1997/10/06 20:55:38 kardel
582 * new parse structure