File: clk_computime.c

package info (click to toggle)
xntp3 5.93-2
  • links: PTS
  • area: main
  • in suites: hamm
  • size: 7,644 kB
  • ctags: 7,419
  • sloc: ansic: 59,474; perl: 3,633; sh: 2,623; awk: 417; makefile: 311; asm: 37
file content (149 lines) | stat: -rw-r--r-- 4,026 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif

#if defined(REFCLOCK) && (defined(PARSE) || defined(PARSEPPS)) && defined(CLOCK_COMPUTIME)
/*
 * clk_computime.c,v 1.8 1997/01/19 12:44:35 kardel Exp
 * 
 * Supports Diem's Computime Radio Clock
 * 
 * Used the Meinberg clock as a template for Diem's Computime Radio Clock
 *
 * adapted by Alois Camenzind <alois.camenzind@ubs.ch>
 * 
 * Copyright (C) 1992-1996 by Frank Kardel
 * Friedrich-Alexander Universitt Erlangen-Nrnberg, Germany
 * 
 * This program is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 * FITNESS FOR A PARTICULAR PURPOSE.
 * 
 */


#include "sys/types.h"
#include "sys/time.h"
#include "sys/errno.h"
#include "ntp_fp.h"
#include "ntp_unixtime.h"
#include "ntp_calendar.h"


#include "parse.h"

/*
 * The Computime receiver sends a datagram in the following format every minute
 * 
 * Timestamp	T:YY:MM:MD:WD:HH:MM:SSCRLF 
 * Pos          0123456789012345678901 2 3
 *              0000000000111111111122 2 2
 * Parse        T:  :  :  :  :  :  :  rn
 * 
 * T	Startcharacter "T" specifies start of the timestamp 
 * YY	Year MM	Month 1-12 
 * MD	Day of the month 
 * WD	Day of week 
 * HH	Hour 
 * MM   Minute 
 * SS   Second
 * CR   Carriage return 
 * LF   Linefeed
 * 
 */

static struct format computime_fmt =
{
	{
		{8, 2},  {5,  2}, {2,  2},	/* day, month, year */
		{14, 2}, {17, 2}, {20, 2},	/* hour, minute, second */
		{11, 2},                        /* dayofweek,  */
	},
	"T:  :  :  :  :  :  :  \r\n",
	0
};

static u_long   cvt_computime();

clockformat_t   clock_computime =
{
	(unsigned long (*) ()) 0,	/* no input handling */
	cvt_computime,			/* Computime conversion */
	syn_simple,			/* easy time stamps for RS232 (fallback) */
	(u_long (*)())0,		/* no PPS monitoring */
	(u_long(*) ())0,		/* no time code synthesizer monitoring */
	(void *)&computime_fmt,		/* conversion configuration */
	"Diem's Computime Radio Clock",	/* Computime Radio Clock */
	24,				/* string buffer */
	F_START|F_END|SYNC_START,	/* START/END delimiter, START synchronisation */
	0,				/* no private data (complete pakets) */
	{0, 0},
	'T',
	'\n',
	'0'
};

/*
 * cvt_computime
 * 
 * convert simple type format
 */
static          u_long
cvt_computime(buffer, size, format, clock)
	register char  *buffer;
	register int    size;
	register struct format *format;
	register clocktime_t *clock;
{

	if (!Strok(buffer, format->fixed_string)) { 
		return CVT_NONE;
	} else {
		if (Stoi(&buffer[format->field_offsets[O_DAY].offset], &clock->day,
				format->field_offsets[O_DAY].length) ||
			Stoi(&buffer[format->field_offsets[O_MONTH].offset], &clock->month,
				format->field_offsets[O_MONTH].length) ||
			Stoi(&buffer[format->field_offsets[O_YEAR].offset], &clock->year,
				format->field_offsets[O_YEAR].length) ||
			Stoi(&buffer[format->field_offsets[O_HOUR].offset], &clock->hour,
				format->field_offsets[O_HOUR].length) ||
			Stoi(&buffer[format->field_offsets[O_MIN].offset], &clock->minute,
				format->field_offsets[O_MIN].length) ||
			Stoi(&buffer[format->field_offsets[O_SEC].offset], &clock->second,
				format->field_offsets[O_SEC].length)) { 
			return CVT_FAIL | CVT_BADFMT;
		} else {

			clock->flags = 0;
			clock->utcoffset = 0;	/* We have UTC time */

			return CVT_OK;
		}
	}
}

#else /* not (REFCLOCK && (PARSE || PARSEPPS) && CLOCK_COMPUTIME) */
int clk_computime_bs;
#endif /* not (REFCLOCK && (PARSE || PARSEPPS) && CLOCK_COMPUTIME) */

/*
 * clk_computime.c,v
 * Revision 1.8  1997/01/19 12:44:35  kardel
 * 3-5.88.1 reconcilation
 *
 * Revision 1.7  1996/12/01 16:04:12  kardel
 * freeze for 5.86.12.2 PARSE-Patch
 *
 * Revision 1.6  1996/12/01 12:57:26  kardel
 * more standard string escapes
 *
 * Revision 1.5  1996/11/24 23:16:30  kardel
 * checkpoint - partial autoconfigure update for parse modules
 *
 * Revision 1.4  1996/11/24 17:34:43  kardel
 * updated copyright
 *
 * Revision 1.3  1996/11/16 19:44:36  kardel
 * Log entry added
 *
 */