2 * /src/NTP/REPOSITORY/ntp4-dev/include/mbg_gps166.h,v 4.7 2006/06/22 18:41:43 kardel RELEASE_20060622_A
4 * mbg_gps166.h,v 4.7 2006/06/22 18:41:43 kardel RELEASE_20060622_A
6 * $Created: Sun Jul 20 09:20:50 1997 $
8 * File GPSSERIO.H Copyright (c) by Meinberg Funkuhren (www.meinberg.de)
11 * Copyright (c) 1997-2005 by Frank Kardel <kardel <AT> ntp.org>
13 * Redistribution and use in source and binary forms, with or without
14 * modification, are permitted provided that the following conditions
16 * 1. Redistributions of source code must retain the above copyright
17 * notice, this list of conditions and the following disclaimer.
18 * 2. Redistributions in binary form must reproduce the above copyright
19 * notice, this list of conditions and the following disclaimer in the
20 * documentation and/or other materials provided with the distribution.
21 * 3. Neither the name of the author nor the names of its contributors
22 * may be used to endorse or promote products derived from this software
23 * without specific prior written permission.
25 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``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 THE AUTHOR OR CONTRIBUTORS 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
42 /***************************************************************************/
44 /* File: GPSSERIO.H 4.1 */
46 /* Project: Common C Library */
48 /* Compiler: Borland C++ */
50 /* Author: M. Burnicki, Meinberg Funkuhren */
54 /* This file defines structures and codes to be used to access GPS166 */
55 /* via its serial interface COM0. COM0 should be set to a high baud */
56 /* rate, default is 19200. */
58 /* Standard GPS166 serial operation is to send a time string that is */
59 /* compatible with Meinberg UA31 or PZF535 DCF77 radio remote clocks. */
60 /* That string can be transmitted automatically once per second, once */
61 /* per minute or on request per ASCII '?'. */
63 /* Parameter setup or parameter readout works using blocks of binary */
64 /* data which have to be isolated from the standard string. A block of */
65 /* data starts with a SOH code (ASCII Start Of Header, 0x01) followed */
66 /* by a message header with constant length and a data portion with */
67 /* variable length. The first field (cmd) of the message header holds */
68 /* the command code rsp. the type of data to be transmitted. The next */
69 /* field (len) gives the number of data bytes that are transmitted */
70 /* after the header. This number ranges from 0 to sizeof( MSG_DATA ). */
71 /* The third field (data_csum) holds a checksum of all data bytes and */
72 /* the last field of the header finally holds the checksum of the. */
75 /***************************************************************************/
77 /* the control codes defined below are to be or'ed with a command/type code */
79 #define GPS_REQACK 0x8000 /* to GPS166: request acknowledge */
80 #define GPS_ACK 0x4000 /* from GPS166: acknowledge a command */
81 #define GPS_NACK 0x2000 /* from GPS166: error receiving command */
83 #define GPS_CTRL_MSK 0xF000 /* masks control code from command */
86 /* The codes below specify commands/types of data to be supplied to GPS166: */
88 /* GPS166 auto-message to host */
89 /* þ host request, GPS166 response */
90 /* þ þ host download to GPS166 */
94 GPS_AUTO_ON = 0x000, /* þ þ þ X þ enable auto-messages from GPS166 */
95 GPS_AUTO_OFF, /* þ þ þ X þ disable auto-messages from GPS166 */
96 GPS_SW_REV, /* þ þ X þ þ request software revision */
97 GPS_STAT, /* þ þ X þ þ request status of buffered variables */
98 GPS_TIME, /* þ X þ þ X þ current time or capture or init board time */
99 GPS_POS_XYZ, /* þ þ X þ X þ current position in ECEF coords */
100 GPS_POS_LLA, /* þ þ X þ X þ current position in geographic coords */
101 GPS_TZDL, /* þ þ X þ X þ time zone / daylight saving */
102 GPS_PORT_PARM, /* þ þ X þ X þ parameters of the serial ports */
103 GPS_SYNTH, /* þ þ X þ X þ synthesizer's frequency and phase */
104 GPS_ANT_INFO, /* þ X þ X þ þ time diff after antenna disconnect */
105 GPS_UCAP, /* þ X þ X þ þ user capture */
108 GPS_CFGH = 0x100, /* þ þ X þ X þ SVs' configuration and health codes */
109 GPS_ALM, /* þ þ X þ X þ one SV's almanac */
110 GPS_EPH, /* þ þ X þ X þ one SV's ephemeris */
111 GPS_UTC, /* þ þ X þ X þ UTC correction parameters */
112 GPS_IONO, /* þ þ X þ X þ ionospheric correction parameters */
113 GPS_ASCII_MSG /* þ þ X þ þ the GPS ASCII message */
117 * modelled after GPSDEFS.H Revision 1.5
119 /***************************************************************************/
121 /* File: GPSDEFS.H 4.1 */
123 /* Project: Common C Library */
125 /* Compiler: Borland C++ */
127 /* Author: M. Burnicki, Meinberg Funkuhren */
131 /* General definitions to be used with GPS166 */
132 /* GPS166 Rev. 1.23 or above */
134 /* Modifications: see file GPSLIB.TXT */
136 /***************************************************************************/
138 /* the type of various checksums */
140 #ifndef _CSUM_DEFINED
141 typedef unsigned short CSUM;
142 # define _CSUM_DEFINED
145 /* the message header */
148 unsigned short gps_cmd;
149 unsigned short gps_len;
150 unsigned short gps_data_csum;
151 unsigned short gps_hdr_csum;
154 /* a struct used to hold the software revision information */
157 unsigned short code; /* e.g. 0x0120 means rev. 1.20 */
158 unsigned char name[17]; /* used to identify customized versions */
161 /* GPS ASCII message */
164 CSUM csum; /* checksum of the remaining bytes */
165 short valid; /* flag data are valid */
166 char s[23]; /* 22 chars GPS ASCII message plus trailing zero */
169 #define MIN_SVNO 1 /* min. SV number */
170 #define MAX_SVNO 32 /* max. SV number */
171 #define N_SVNO ( MAX_SVNO - MIN_SVNO + 1) /* number of possibly active SVs */
174 typedef short SVNO; /* the number of a SV */
175 typedef unsigned short HEALTH; /* a SV's health code */
176 typedef unsigned short CFG; /* a SV's configuration code */
177 typedef unsigned short IOD; /* Issue-Of-Data code */
179 /* Date and time referred to the linear time scale defined by GPS. */
180 /* GPS time is defined by the number of weeks since midnight from */
181 /* January 5, 1980 to January 6, 1980 plus the number of seconds of */
182 /* the current week plus fractions of a second. GPS time differs from */
183 /* UTC because UTC is corrected with leap seconds while GPS time scale */
187 unsigned short wn; /* the week number since GPS has been installed */
188 unsigned long sec; /* the second of that week */
189 unsigned long tick; /* fractions of a second; scale: 1E-7 */
193 /* Local date and time computed from GPS time. The current number */
194 /* of leap seconds have to be added to get UTC from GPS time. */
195 /* Additional corrections could have been made according to the */
196 /* time zone/daylight saving parameters (TZDL, see below) defined */
197 /* by the user. The status field can be checked to see which corrections */
198 /* have been applied. */
202 short year; /* 0..9999 */
203 char month; /* 1..12 */
204 char mday; /* 1..31 */
205 short yday; /* 1..366 */
206 char wday; /* 0..6 == Sun..Sat */
207 char hour; /* 0..23 */
208 char minute; /* 0..59 */
209 char second; /* 0..59 */
210 long frac; /* fractions of a second, scale 1E-7 */
211 long offs_from_utc; /* local time's offset from UTC */
212 unsigned short status; /* flags */
215 /* status flags used with conversion from GPS time to local time */
217 # define TM_UTC 0x01 /* UTC correction has been made */
218 # define TM_LOCAL 0x02 /* UTC has been converted to local time */
219 # define TM_DL_ANN 0x04 /* state of daylight saving is going to change */
220 # define TM_DL_ENB 0x08 /* daylight saving is enabled */
221 # define TM_LS_ANN 0x10 /* leap second will be inserted */
222 # define TM_LS_ENB 0x20 /* current second is leap second */
228 /* the status flags below are defined starting with rev. 1.32 */
230 #define TM_ANT_DISCONN 0x1000 /* antenna currently disconnected */
231 #define TM_SYN_FLAG 0x2000 /* TIME_SYN output is low */
232 #define TM_NO_SYNC 0x4000 /* not sync'ed after reset */
233 #define TM_NO_POS 0x8000 /* position not computed after reset, */
236 /* a struct used to transmit information on date and time */
239 short channel; /* -1: the current time; 0, 1: capture 0, 1 */
240 T_GPS t; /* time in GPS format */
241 TM tm; /* that time converted to local time */
246 /* Two types of variables used to store a position. Type XYZ is */
247 /* used with a position in earth centered, earth fixed (ECEF) */
248 /* coordinates whereas type LLA holds such a position converted */
249 /* to geographic coordinates as defined by WGS84 (World Geodetic */
250 /* System from 1984). */
253 /* sequence and number of components of a cartesian position */
254 enum { XP, YP, ZP, N_XYZ };
256 /* a type of array holding a cartesian position */
257 typedef l_fp XYZ[N_XYZ]; /* values are in [m] */
259 # define _XYZ_DEFINED
264 /* sequence and number of components of a geographic position */
265 enum { LAT, LON, ALT, N_LLA }; /* latitude, longitude, altitude */
267 /* a type of array holding a geographic position */
268 typedef l_fp LLA[N_LLA]; /* lon, lat in [rad], alt in [m] */
270 # define _LLA_DEFINED
273 /* Synthesizer parameters. Synthesizer frequency is expressed as a */
274 /* four digit decimal number (freq) to be multiplied by 0.1 Hz and an */
275 /* base 10 exponent (range). If the effective frequency is less than */
276 /* 10 kHz its phase is synchronized corresponding to the variable phase. */
277 /* Phase may be in a range from -360° to +360° with a resolution of 0.1°, */
278 /* so the resulting numbers to be stored are in a range of -3600 to +3600. */
281 /* Assume the value of freq is 2345 (decimal) and the value of phase is 900. */
282 /* If range == 0 the effective frequency is 234.5 Hz with a phase of +90°. */
283 /* If range == 1 the synthesizer will generate a 2345 Hz output frequency */
287 /* If freq == 0 the synthesizer is disabled. If range == 0 the least */
288 /* significant digit of freq is limited to 0, 3, 5 or 6. The resulting */
289 /* frequency is shown in the examples below: */
290 /* freq == 1230 --> 123.0 Hz */
291 /* freq == 1233 --> 123 1/3 Hz (real 1/3 Hz, NOT 123.3 Hz) */
292 /* freq == 1235 --> 123.5 Hz */
293 /* freq == 1236 --> 123 2/3 Hz (real 2/3 Hz, NOT 123.6 Hz) */
295 /* If range == MAX_RANGE the value of freq must not exceed 1200, so the */
296 /* output frequency is limited to 12 MHz. */
298 /* Phase will be ignored if the resulting frequency is greater or equal */
301 #define MAX_SYNTH_FREQ 1200 /* if range == MAX_SYNTH_RANGE */
302 #define MIN_SYNTH_RANGE 0
303 #define MAX_SYNTH_RANGE 5
304 #define MAX_SYNTH_PHASE 3600
307 short freq; /* four digits used; scale: 0.1; e.g. 1234 -> 123.4 Hz */
308 short range; /* scale factor for freq; 0..MAX_SYNTH_RANGE */
309 short phase; /* -MAX_SYNTH_PHASE..+MAX_SYNTH_PHASE; >0 -> pulses later */
314 /* Time zone/daylight saving parameters. */
316 /* the name of a time zone, 5 characters plus trailing zero */
317 typedef char TZ_NAME[6];
320 long offs; /* offset from UTC to local time [sec] */
321 long offs_dl; /* additional offset if daylight saving enabled [sec] */
322 TM tm_on; /* date/time when daylight saving starts */
323 TM tm_off; /* date/time when daylight saving ends */
324 TZ_NAME name[2]; /* names without and with daylight saving enabled */
327 /* The constant below is defined beginning with software rev. 1.29. */
328 /* If the year in tzdl.tmon and tzdl.tm_off is or'ed with that constant, */
329 /* the receiver automatically generates daylight saving year by year. */
330 /* See GPSLIB.TXT for more information. */
332 #define DL_AUTO_FLAG 0x8000
335 /* for automatic daylight saving enable/disable in Central Europe, */
336 /* the variables are to be set as shown below: */
337 /* offs = 3600L one hour from UTC */
338 /* offs_dl = 3600L one additional hour if daylight saving enabled */
339 /* tm_on = first Sunday from March 25, 02:00:00h ( year |= DL_AUTO_FLAG ) */
340 /* tm_off = first Sunday from Sept 24, 03:00:00h ( year |= DL_AUTO_FLAG ) */
341 /* name[0] == "MEZ " name if daylight saving not enabled */
342 /* name[1] == "MESZ " name if daylight saving is enabled */
347 /* the structure below was defined in rev. 1.31. It reflects the status */
348 /* of the antenna, the times of last disconnect/reconnect and the boards */
349 /* clock offset after the phase of disconnection. */
352 short status; /* current status of antenna */
353 TM tm_disconn; /* time of antenna disconnect */
354 TM tm_reconn; /* time of antenna reconnect */
355 long delta_t; /* clock offset at reconnect time, units: TICKS_PER_SEC */
359 /* the status field may be set to one of the values below: */
362 ANT_INVALID, /* struct not set yet because ant. has not been disconn. */
363 ANT_DISCONN, /* ant. now disconn., tm_reconn and delta_t not set */
364 ANT_RECONN /* ant. has been disconn. and reconn., all fields valid */
368 /* Summary of configuration and health data of all SVs. */
371 CSUM csum; /* checksum of the remaining bytes */
372 short valid; /* flag data are valid */
374 T_GPS tot_51; /* time of transmission, page 51 */
375 T_GPS tot_63; /* time of transmission, page 63 */
376 T_GPS t0a; /* complete reference time almanac */
378 CFG cfg[N_SVNO]; /* SV configuration from page 63 */
379 HEALTH health[N_SVNO]; /* SV health from pages 51, 63 */
384 /* UTC correction parameters */
387 CSUM csum; /* checksum of the remaining bytes */
388 short valid; /* flag data are valid */
390 T_GPS t0t; /* Reference Time UTC Parameters [sec] */
391 l_fp A0; /* ± Clock Correction Coefficient 0 [sec] */
392 l_fp A1; /* ± Clock Correction Coefficient 1 [sec/sec] */
394 ushort WNlsf; /* week number of nearest leap second */
395 short DNt; /* the day number at the end of which LS is inserted */
396 char delta_tls; /* */
397 char delta_tlsf; /* */
401 /* a struct used to hold the settings of a serial port */
403 #ifndef _COM_PARM_DEFINED
404 typedef long BAUD_RATE;
406 /* indices used to identify a parameter in the framing string */
407 enum { F_DBITS, F_PRTY, F_STBITS };
409 /* types of handshake */
410 enum { HS_NONE, HS_XONXOFF, HS_RTSCTS };
413 BAUD_RATE baud_rate; /* e.g. 19200L */
414 char framing[4]; /* e.g. "8N1" */
415 short handshake; /* a numeric value, only HS_NONE supported yet */
418 #define _COM_PARM_DEFINED
423 /* the codes below define what has to comes out of the serial ports */
425 enum { STR_ON_REQ, STR_PER_SEC,
426 STR_PER_MIN, N_STR_MODE_0, /* COM0 and COM1 */
427 STR_UCAP = N_STR_MODE_0,
428 STR_UCAP_REQ, N_STR_MODE_1 /* COM1 only */
432 #define N_COM 2 /* the number of serial ports */
434 /* the structure used to store the modes of both serial ports */
437 COM_PARM com[N_COM]; /* COM0 and COM1 settings */
438 u_char mode[N_COM]; /* COM0 and COM1 output mode */
441 /* Ephemeris parameters of one specific SV. Needed to compute the position */
442 /* of a satellite at a given time with high precision. Valid for an */
443 /* interval of 4 to 6 hours from start of transmission. */
446 CSUM csum; /* checksum of the remaining bytes */
447 short valid; /* flag data are valid */
449 HEALTH health; /* health indication of transmitting SV [---] */
450 IOD IODC; /* Issue Of Data, Clock */
451 IOD IODE2; /* Issue of Data, Ephemeris (Subframe 2) */
452 IOD IODE3; /* Issue of Data, Ephemeris (Subframe 3) */
453 T_GPS tt; /* time of transmission */
454 T_GPS t0c; /* Reference Time Clock [---] */
455 T_GPS t0e; /* Reference Time Ephemeris [---] */
457 l_fp sqrt_A; /* Square Root of semi-major Axis [sqrt(m)] */
458 l_fp e; /* Eccentricity [---] */
459 l_fp M0; /* ± Mean Anomaly at Ref. Time [rad] */
460 l_fp omega; /* ± Argument of Perigee [rad] */
461 l_fp OMEGA0; /* ± Longit. of Asc. Node of orbit plane [rad] */
462 l_fp OMEGADOT; /* ± Rate of Right Ascension [rad/sec] */
463 l_fp deltan; /* ± Mean Motion Diff. from computed value [rad/sec] */
464 l_fp i0; /* ± Inclination Angle [rad] */
465 l_fp idot; /* ± Rate of Inclination Angle [rad/sec] */
466 l_fp crc; /* ± Cosine Corr. Term to Orbit Radius [m] */
467 l_fp crs; /* ± Sine Corr. Term to Orbit Radius [m] */
468 l_fp cuc; /* ± Cosine Corr. Term to Arg. of Latitude [rad] */
469 l_fp cus; /* ± Sine Corr. Term to Arg. of Latitude [rad] */
470 l_fp cic; /* ± Cosine Corr. Term to Inclination Angle [rad] */
471 l_fp cis; /* ± Sine Corr. Term to Inclination Angle [rad] */
473 l_fp af0; /* ± Clock Correction Coefficient 0 [sec] */
474 l_fp af1; /* ± Clock Correction Coefficient 1 [sec/sec] */
475 l_fp af2; /* ± Clock Correction Coefficient 2 [sec/sec²] */
476 l_fp tgd; /* ± estimated group delay differential [sec] */
478 u_short URA; /* predicted User Range Accuracy */
480 u_char L2code; /* code on L2 channel [---] */
481 u_char L2flag; /* L2 P data flag [---] */
485 /* Almanac parameters of one specific SV. A reduced precision set of */
486 /* parameters used to check if a satellite is in view at a given time. */
487 /* Valid for an interval of more than 7 days from start of transmission. */
490 CSUM csum; /* checksum of the remaining bytes */
491 short valid; /* flag data are valid */
493 HEALTH health; /* [---] */
494 T_GPS t0a; /* Reference Time Almanac [sec] */
496 l_fp sqrt_A; /* Square Root of semi-major Axis [sqrt(m)] */
497 l_fp e; /* Eccentricity [---] */
499 l_fp M0; /* ± Mean Anomaly at Ref. Time [rad] */
500 l_fp omega; /* ± Argument of Perigee [rad] */
501 l_fp OMEGA0; /* ± Longit. of Asc. Node of orbit plane [rad] */
502 l_fp OMEGADOT; /* ± Rate of Right Ascension [rad/sec] */
503 l_fp deltai; /* ± [rad] */
504 l_fp af0; /* ± Clock Correction Coefficient 0 [sec] */
505 l_fp af1; /* ± Clock Correction Coefficient 1 [sec/sec] */
509 /* ionospheric correction parameters */
512 CSUM csum; /* checksum of the remaining bytes */
513 short valid; /* flag data are valid */
515 l_fp alpha_0; /* Ionosph. Corr. Coeff. Alpha 0 [sec] */
516 l_fp alpha_1; /* Ionosph. Corr. Coeff. Alpha 1 [sec/deg] */
517 l_fp alpha_2; /* Ionosph. Corr. Coeff. Alpha 2 [sec/deg^2] */
518 l_fp alpha_3; /* Ionosph. Corr. Coeff. Alpha 3 [sec/deg^3] */
520 l_fp beta_0; /* Ionosph. Corr. Coeff. Beta 0 [sec] */
521 l_fp beta_1; /* Ionosph. Corr. Coeff. Beta 1 [sec/deg] */
522 l_fp beta_2; /* Ionosph. Corr. Coeff. Beta 2 [sec/deg^2] */
523 l_fp beta_3; /* Ionosph. Corr. Coeff. Beta 3 [sec/deg^3] */
527 void mbg_tm_str P((char **, TM *, int));
528 void mbg_tgps_str P((char **, T_GPS *, int));
529 void get_mbg_header P((unsigned char **, GPS_MSG_HDR *));
530 void put_mbg_header P((unsigned char **, GPS_MSG_HDR *));
531 void get_mbg_sw_rev P((unsigned char **, SW_REV *));
532 void get_mbg_ascii_msg P((unsigned char **, ASCII_MSG *));
533 void get_mbg_svno P((unsigned char **, SVNO *));
534 void get_mbg_health P((unsigned char **, HEALTH *));
535 void get_mbg_cfg P((unsigned char **, CFG *));
536 void get_mbg_tgps P((unsigned char **, T_GPS *));
537 void get_mbg_tm P((unsigned char **, TM *));
538 void get_mbg_ttm P((unsigned char **, TTM *));
539 void get_mbg_synth P((unsigned char **, SYNTH *));
540 void get_mbg_tzdl P((unsigned char **, TZDL *));
541 void get_mbg_antinfo P((unsigned char **, ANT_INFO *));
542 void get_mbg_cfgh P((unsigned char **, CFGH *));
543 void get_mbg_utc P((unsigned char **, UTC *));
544 void get_mbg_lla P((unsigned char **, LLA));
545 void get_mbg_xyz P((unsigned char **, XYZ));
546 void get_mbg_portparam P((unsigned char **, PORT_PARM *));
547 void get_mbg_eph P((unsigned char **, EPH *));
548 void get_mbg_alm P((unsigned char **, ALM *));
549 void get_mbg_iono P((unsigned char **, IONO *));
551 unsigned long mbg_csum P((unsigned char *, unsigned int));
558 * Revision 4.7 2006/06/22 18:41:43 kardel
559 * clean up signedness (gcc 4)
561 * Revision 4.6 2005/10/07 22:11:56 kardel
562 * bounded buffer implementation
564 * Revision 4.5.2.1 2005/09/25 10:23:48 kardel
565 * support bounded buffers
567 * Revision 4.5 2005/06/25 10:58:45 kardel
568 * add missing log keywords
570 * Revision 4.1 1998/06/12 15:07:30 kardel
573 * Revision 4.0 1998/04/10 19:50:42 kardel
574 * Start 4.0 release version numbering
576 * Revision 1.1 1998/04/10 19:27:34 kardel
577 * initial NTP VERSION 4 integration of PARSE with GPS166 binary support
579 * Revision 1.1 1997/10/06 20:55:38 kardel
580 * new parse structure