source: trunk/third/xntp/include/parse.h @ 10832

Revision 10832, 14.4 KB checked in by brlewis, 27 years ago (diff)
This commit was generated by cvs2svn to compensate for changes in r10831, which included commits to RCS files with non-trunk default branches.
RevLine 
[10831]1/*
2 * /src/NTP/REPOSITORY/v4/include/parse.h,v 3.31 1996/12/01 16:02:46 kardel Exp
3 *
4 * parse.h,v 3.31 1996/12/01 16:02:46 kardel Exp
5 *
6 * Copyright (C) 1989,1990,1991,1992,1993,1994,1995,1996 by Frank Kardel
7 * Friedrich-Alexander Universität Erlangen-Nürnberg, Germany
8 *                                   
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
12 *
13 */
14
15#ifndef __PARSE_H__
16#define __PARSE_H__
17#if     !(defined(lint) || defined(__GNUC__))
18  static char parsehrcsid[]="parse.h,v 3.31 1996/12/01 16:02:46 kardel Exp";
19#endif
20
21#include "ntp_types.h"
22
23#include "parse_conf.h"
24
25/*
26 * we use the following datastructures in two modes
27 * either in the NTP itself where we use NTP time stamps at some places
28 * or in the kernel, where only struct timeval will be used.
29 */
30#undef PARSEKERNEL
31#if defined(KERNEL) || defined(_KERNEL)
32#ifndef PARSESTREAM
33#define PARSESTREAM
34#endif
35#endif
36#if defined(PARSESTREAM) && defined(STREAM)
37#define PARSEKERNEL
38#endif
39#ifdef PARSEKERNEL
40#ifndef _KERNEL
41extern caddr_t kmem_alloc P((unsigned int));
42extern caddr_t kmem_free P((caddr_t, unsigned int));
43extern int splx();
44extern int splhigh();
45#define MALLOC(_X_) (char *)kmem_alloc(_X_)
46#define FREE(_X_, _Y_) kmem_free((caddr_t)_X_, _Y_)
47#else
48#include <sys/kmem.h>
49#define MALLOC(_X_) (char *)kmem_alloc(_X_, KM_SLEEP)
50#define FREE(_X_, _Y_) kmem_free((caddr_t)_X_, _Y_)
51#endif
52#else
53#define MALLOC(_X_) malloc(_X_)
54#define FREE(_X_, _Y_) free(_X_)
55#endif
56
57#if defined(PARSESTREAM) && defined(STREAM)
58#include <sys/stream.h>
59#include <sys/stropts.h>
60#else   /* STREAM */
61#include <stdio.h>
62#include "ntp_syslog.h"
63#ifdef  DEBUG
64extern int debug;
65#define DD_PARSE 5
66#define DD_RAWDCF 4
67#define parseprintf(LEVEL, ARGS) if (debug > LEVEL) printf ARGS
68#else   /* DEBUG */
69#define parseprintf(LEVEL, ARGS)
70#endif  /* DEBUG */
71#endif  /* PARSESTREAM */
72
73#if defined(timercmp) && defined(__GNUC__)
74#undef timercmp
75#define timercmp(tvp, uvp, cmp) \
76        ((tvp)->tv_sec cmp (uvp)->tv_sec || \
77         ((tvp)->tv_sec == (uvp)->tv_sec && (tvp)->tv_usec cmp (uvp)->tv_usec))
78#endif
79
80#ifndef TIMES10
81#define TIMES10(_X_)    (((_X_) << 3) + ((_X_) << 1))
82#endif
83
84/*
85 * state flags
86 */
87#define PARSEB_POWERUP            0x00000001 /* no synchronisation */
88#define PARSEB_NOSYNC             0x00000002 /* timecode currently not confirmed */
89
90/*
91 * time zone information
92 */
93#define PARSEB_ANNOUNCE           0x00000010 /* switch time zone warning (DST switch) */
94#define PARSEB_DST                0x00000020 /* DST in effect */
95#define PARSEB_UTC                0x00000040 /* UTC time */
96
97/*
98 * leap information
99 */
100#define PARSEB_LEAPDEL            0x00000100 /* LEAP deletion warning */
101#define PARSEB_LEAPADD            0x00000200 /* LEAP addition warning */
102#define PARSEB_LEAPS              0x00000300 /* LEAP warnings */
103#define PARSEB_LEAPSECOND         0x00000400 /* actual leap second */
104/*
105 * optional status information
106 */
107#define PARSEB_ALTERNATE          0x00001000 /* alternate antenna used */
108#define PARSEB_POSITION           0x00002000 /* position available */
109
110/*
111 * feature information
112 */
113#define PARSEB_S_LEAP             0x00010000 /* supports LEAP */
114#define PARSEB_S_ANTENNA          0x00020000 /* supports antenna information */
115#define PARSEB_S_PPS              0x00040000 /* supports PPS time stamping */
116#define PARSEB_S_POSITION         0x00080000 /* supports position information (GPS) */
117
118/*
119 * time stamp availability
120 */
121#define PARSEB_TIMECODE           0x10000000 /* valid time code sample */
122#define PARSEB_PPS                0x20000000 /* valid PPS sample */
123
124#define PARSE_TCINFO            (PARSEB_ANNOUNCE|PARSEB_POWERUP|PARSEB_NOSYNC|PARSEB_DST|\
125                                 PARSEB_UTC|PARSEB_LEAPS|PARSEB_ALTERNATE|PARSEB_S_LEAP|\
126                                 PARSEB_S_LOCATION|PARSEB_TIMECODE)
127
128#define PARSE_POWERUP(x)        ((x) & PARSEB_POWERUP)
129#define PARSE_NOSYNC(x)         (((x) & (PARSEB_POWERUP|PARSEB_NOSYNC)) == PARSEB_NOSYNC)
130#define PARSE_SYNC(x)           (((x) & (PARSEB_POWERUP|PARSEB_NOSYNC)) == 0)
131#define PARSE_ANNOUNCE(x)       ((x) & PARSEB_ANNOUNCE)
132#define PARSE_DST(x)            ((x) & PARSEB_DST)
133#define PARSE_UTC(x)            ((x) & PARSEB_UTC)
134#define PARSE_LEAPADD(x)        (PARSE_SYNC(x) && (((x) & PARSEB_LEAPS) == PARSEB_LEAPADD))
135#define PARSE_LEAPDEL(x)        (PARSE_SYNC(x) && (((x) & PARSEB_LEAPS) == PARSEB_LEAPDEL))
136#define PARSE_ALTERNATE(x)      ((x) & PARSEB_ALTERNATE)
137#define PARSE_LEAPSECOND(x)     (PARSE_SYNC(x) && ((x) & PARSEB_LEAP_SECOND))
138
139#define PARSE_S_LEAP(x)         ((x) & PARSEB_S_LEAP)
140#define PARSE_S_ANTENNA(x)      ((x) & PARSEB_S_ANTENNA)
141#define PARSE_S_PPS(x)          ((x) & PARSEB_S_PPS)
142#define PARSE_S_POSITION(x)     ((x) & PARSEB_S_POSITION)
143
144#define PARSE_TIMECODE(x)       ((x) & PARSEB_TIMECODE)
145#define PARSE_PPS(x)            ((x) & PARSEB_PPS)
146#define PARSE_POSITION(x)       ((x) & PARSEB_POSITION)
147
148/*
149 * operation flags - some are also fudge flags
150 */
151#define PARSE_STATISTICS    0x08  /* enable statistics */
152#define PARSE_LEAP_DELETE   0x04  /* delete leap - overides statistics */
153#define PARSE_FIXED_FMT     0x10  /* fixed format */
154#define PARSE_PPSCLOCK      0x20  /* try to get PPS time stamp via ppsclock ioctl */
155
156typedef union timestamp
157{
158  struct timeval tv;            /* timeval - usually kernel view */
159  l_fp           fp;            /* fixed point - xntp view */
160} timestamp_t;
161
162/*
163 * standard time stamp structure
164 */
165struct parsetime
166{
167  u_long  parse_status; /* data status - CVT_OK, CVT_NONE, CVT_FAIL ... */
168  timestamp_t    parse_time;    /* PARSE timestamp */
169  timestamp_t    parse_stime;   /* telegram sample timestamp */
170  timestamp_t    parse_ptime;   /* PPS time stamp */
171  long           parse_usecerror;       /* sampled usec error */
172  u_long         parse_state;   /* current receiver state */
173  unsigned short parse_format;  /* format code */
174};
175
176typedef struct parsetime parsetime_t;
177
178/*---------- STREAMS interface ----------*/
179
180#ifdef STREAM
181/*
182 * ioctls
183 */
184#define PARSEIOC_ENABLE         (('D'<<8) + 'E')
185#define PARSEIOC_DISABLE        (('D'<<8) + 'D')
186#define PARSEIOC_SETFMT         (('D'<<8) + 'f')
187#define PARSEIOC_GETFMT         (('D'<<8) + 'F')
188#define PARSEIOC_SETCS          (('D'<<8) + 'C')
189#define PARSEIOC_TIMECODE       (('D'<<8) + 'T')
190
191#endif
192
193/*------ IO handling flags (sorry) ------*/
194
195#define PARSE_IO_CSIZE  0x00000003
196#define PARSE_IO_CS5    0x00000000
197#define PARSE_IO_CS6    0x00000001
198#define PARSE_IO_CS7    0x00000002
199#define PARSE_IO_CS8    0x00000003
200
201/*
202 * sizes
203 */
204#define PARSE_TCMAX     128
205
206/*
207 * ioctl structure
208 */
209union parsectl
210{
211  struct parsegettc
212    {
213      u_long         parse_state;       /* last state */
214      u_long         parse_badformat; /* number of bad packets since last query */
215      unsigned short parse_format;/* last decoded format */
216      unsigned short parse_count;       /* count of valid time code bytes */
217      char           parse_buffer[PARSE_TCMAX+1]; /* timecode buffer */
218    } parsegettc;
219
220  struct parseformat
221    {
222      unsigned short parse_format;/* number of examined format */
223      unsigned short parse_count;       /* count of valid string bytes */
224      char           parse_buffer[PARSE_TCMAX+1]; /* format code string */
225    } parseformat;
226
227  struct parsesetcs
228    {
229      u_long         parse_cs;  /* character size (needed for stripping) */
230    } parsesetcs;
231};
232 
233typedef union parsectl parsectl_t;
234
235/*------ for conversion routines --------*/
236
237#define PARSE_DELTA        16
238
239struct parse                    /* parse module local data */
240{
241  int            parse_flags;   /* operation and current status flags */
242 
243  int            parse_ioflags;    /* io handling flags (5-8 Bit control currently) */
244  int            parse_syncflags;          /* possible sync events (START/END/character) */
245  /*
246   * RS232 input parser information
247   */
248  unsigned char  parse_startsym[32]; /* possible start packet values */
249  unsigned char  parse_endsym[32];   /* possible end packet values */
250  unsigned char  parse_syncsym[32];  /* sync characters */
251  struct timeval parse_timeout;    /* max gap between characters (us) */
252
253  /*
254   * PPS 'input' buffer
255   */
256  struct timeval parse_lastone; /* time stamp of last PPS 1 transition */
257  struct timeval parse_lastzero;        /* time stamp of last PPS 0 transition */
258
259  /*
260   * character input buffer
261   */
262  timestamp_t    parse_lastchar;        /* time stamp of last received character */
263
264  /*
265   * private data - fixed format only
266   */
267  unsigned short parse_plen;    /* length of private data */
268  void          *parse_pdata;   /* private data pointer */
269
270  /*
271   * time code input buffer (from RS232 or PPS)
272   */
273  unsigned short parse_index;   /* current buffer index */
274  char          *parse_data;    /* data buffer */
275  unsigned short parse_dsize;   /* size of data buffer */
276  unsigned short parse_lformat; /* last format used */
277  u_long         parse_lstate;  /* last state code */
278  char          *parse_ldata;   /* last data buffer */
279  unsigned short parse_ldsize;  /* last data buffer length */
280  u_long         parse_badformat;       /* number of unparsable pakets */
281 
282  parsetime_t      parse_dtime; /* external data prototype */
283};
284
285typedef struct parse parse_t;
286
287struct clocktime                /* clock time broken up from time code */
288{
289  long day;
290  long month;
291  long year;
292  long hour;
293  long minute;
294  long second;
295  long usecond;
296  long utcoffset;       /* in seconds */
297  time_t utctime;       /* the actual time - alternative to date/time */
298  long flags;           /* current clock status */
299};
300
301typedef struct clocktime clocktime_t;
302
303/*
304 * clock formats specify routines to be called to
305 * convert the buffer into a struct clock.
306 * functions are called
307 *   fn(buffer, data, clock) -> CVT_NONE, CVT_FAIL, CVT_OK
308 *
309 * the private data pointer can be used to
310 * distingush between different formats of a common
311 * base type
312 */
313#define F_START         0x00000001 /* start packet delimiter */
314#define F_END           0x00000002 /* end packet delimiter */
315#define SYNC_TIMEOUT    0x00000004 /* packet restart after timeout */
316#define SYNC_START      0x00000008 /* packet start is sync event */
317#define SYNC_END        0x00000010 /* packet end is sync event */
318#define SYNC_CHAR       0x00000020 /* special character is sync event */
319#define SYNC_ONE        0x00000040 /* PPS synchronize on 'ONE' transition */
320#define SYNC_ZERO       0x00000080 /* PPS synchronize on 'ZERO' transition */
321#define SYNC_SYNTHESIZE 0x00000100 /* generate intermediate time stamps */
322#define CVT_FIXEDONLY   0x00010000 /* convert only in fixed configuration */
323
324/*
325 * parser related return/error codes
326 */
327#define CVT_MASK        0x0000000F /* conversion exit code */
328#define   CVT_NONE      0x00000001 /* format not applicable */
329#define   CVT_FAIL      0x00000002 /* conversion failed - error code returned */
330#define   CVT_OK        0x00000004 /* conversion succeeded */
331#define   CVT_SKIP      0x00000008 /* conversion succeeded */
332#define CVT_BADFMT      0x00000010 /* general format error - (unparsable) */
333#define CVT_BADDATE     0x00000020 /* date field incorrect */
334#define CVT_BADTIME     0x00000040 /* time field incorrect */
335
336struct clockformat
337{
338  u_long        (*input)();     /* special input protocol - implies fixed format */
339  u_long        (*convert)();   /* conversion routine */
340  void          (*syncevt)();   /* routine for handling RS232 sync events (time stamps) */
341  u_long        (*syncpps)();   /* PPS input routine */
342  u_long        (*synth)();     /* time code synthesizer */
343  void           *data;         /* local parameters */
344  char           *name;         /* clock format name */
345  unsigned short  length;       /* maximum length of data packet */
346  u_long   flags;       /* valid start symbols etc. */
347  unsigned short  plen;         /* length of private data - implies fixed format */
348  struct timeval  timeout;      /* buffer restart after timeout (us) */
349  unsigned char   startsym;     /* start symbol */
350  unsigned char   endsym;       /* end symbol */
351  unsigned char   syncsym;      /* sync symbol */
352};
353
354typedef struct clockformat clockformat_t;
355
356/*
357 * parse interface
358 */
359extern int  parse_ioinit P((parse_t *));
360extern void parse_ioend P((parse_t *));
361extern int  parse_ioread P((parse_t *, unsigned int, timestamp_t *));
362extern int  parse_iopps P((parse_t *, int, timestamp_t *));
363extern void parse_iodone P((parse_t *));
364extern int  parse_timecode P((parsectl_t *, parse_t *));
365extern int  parse_getfmt P((parsectl_t *, parse_t *));
366extern int  parse_setfmt P((parsectl_t *, parse_t *));
367extern int  parse_setcs P((parsectl_t *, parse_t *));
368
369extern int Strok P((char *, char *));
370extern int Stoi P((char *, long *, int));
371
372extern time_t parse_to_unixtime P((clocktime_t *, u_long *));
373extern u_long updatetimeinfo P((parse_t *, time_t, u_long, u_long));
374extern void syn_simple P((parse_t *, timestamp_t *, struct format *, u_long));
375extern u_long pps_simple P((parse_t *, int, timestamp_t *));
376#endif
377
378/*
379 * History:
380 *
381 * parse.h,v
382 * Revision 3.31  1996/12/01 16:02:46  kardel
383 * freeze for 5.86.12.2 PARSE-Patch
384 *
385 * Revision 3.30  1996/11/24 20:09:17  kardel
386 * RELEASE_5_86_12_2 reconcilation
387 *
388 * Revision 3.29  1996/10/05 13:30:13  kardel
389 * general update
390 *
391 * Revision 3.28  1996/06/01 16:49:59  kardel
392 * changed flag value for statistics preparation
393 *
394 * Revision 3.27  1995/10/15 23:46:05  duwe
395 * look for ntp_syslog.h in the right place
396 *
397 * Revision 3.26  1995/07/02  20:01:00  kardel
398 * keep ANSI happy...
399 *
400 * Revision 3.25  1995/06/18  12:14:56  kardel
401 * removed dispersion calulation from parse subsystem
402 *
403 * Revision 3.24  1995/04/09  20:53:39  kardel
404 * 3.4n reconcilation
405 *
406 * Revision 3.23  1994/10/03  22:13:04  kardel
407 * typoe...
408 *
409 * Revision 3.22  1994/10/03  10:03:19  kardel
410 * 3.4e reconcilation
411 *
412 * Revision 3.21  1994/05/30  20:58:34  kardel
413 * fix prototypes
414 *
415 * Revision 3.20  1994/05/30  10:19:44  kardel
416 * int32 cleanup
417 *
418 * Revision 3.19  1994/05/15  11:30:33  kardel
419 * documented flag4 as statistics enable flag
420 *
421 * Revision 3.18  1994/05/12  12:40:34  kardel
422 * shut up gcc about broken Sun/BSD code
423 *
424 * Revision 3.17  1994/03/03  09:27:20  kardel
425 * rcs ids fixed
426 *
427 * Revision 3.13  1994/01/25  19:04:21  kardel
428 * 94/01/23 reconcilation
429 *
430 * Revision 3.12  1994/01/23  17:23:05  kardel
431 * 1994 reconcilation
432 *
433 * Revision 3.11  1993/11/11  11:20:18  kardel
434 * declaration fixes
435 *
436 * Revision 3.10  1993/11/01  19:59:48  kardel
437 * parse Solaris support (initial version)
438 *
439 * Revision 3.9  1993/10/06  00:14:57  kardel
440 * include fixes
441 *
442 * Revision 3.8  1993/10/05  23:15:41  kardel
443 * more STREAM protection
444 *
445 * Revision 3.7  1993/10/05  22:56:10  kardel
446 * STREAM must be defined for PARSESTREAMS
447 *
448 * Revision 3.6  1993/10/03  19:10:28  kardel
449 * restructured I/O handling
450 *
451 * Revision 3.5  1993/09/26  23:41:13  kardel
452 * new parse driver logic
453 *
454 * Revision 3.4  1993/09/01  21:46:31  kardel
455 * conditional cleanup
456 *
457 * Revision 3.3  1993/08/27  00:29:29  kardel
458 * compilation cleanup
459 *
460 * Revision 3.2  1993/07/09  11:37:05  kardel
461 * Initial restructured version + GPS support
462 *
463 * Revision 3.1  1993/07/06  09:59:12  kardel
464 * DCF77 driver goes generic...
465 *
466 */
Note: See TracBrowser for help on using the repository browser.