5 #if defined(REFCLOCK) && defined(CLOCK_PARSE) && defined(CLOCK_COMPUTIME)
7 * /src/NTP/ntp-4/libparse/clk_computime.c,v 4.6 1999/11/28 09:13:49 kardel RELEASE_19991128_A
9 * clk_computime.c,v 4.6 1999/11/28 09:13:49 kardel RELEASE_19991128_A
11 * Supports Diem's Computime Radio Clock
13 * Used the Meinberg clock as a template for Diem's Computime Radio Clock
15 * adapted by Alois Camenzind <alois.camenzind@ubs.ch>
17 * Copyright (C) 1992-1998 by Frank Kardel
18 * Friedrich-Alexander Universität Erlangen-Nürnberg, Germany
20 * This program is distributed in the hope that it will be useful, but WITHOUT
21 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
22 * FITNESS FOR A PARTICULAR PURPOSE.
27 #include <sys/types.h>
31 #include "ntp_unixtime.h"
32 #include "ntp_calendar.h"
33 #include "ntp_stdlib.h"
40 #include "sys/parsestreams.h"
41 extern void printf P((const char *, ...));
45 * The Computime receiver sends a datagram in the following format every minute
47 * Timestamp T:YY:MM:MD:WD:HH:MM:SSCRLF
48 * Pos 0123456789012345678901 2 3
49 * 0000000000111111111122 2 2
50 * Parse T: : : : : : : rn
52 * T Startcharacter "T" specifies start of the timestamp
53 * YY Year MM Month 1-12
64 static struct format computime_fmt =
67 {8, 2}, {5, 2}, {2, 2}, /* day, month, year */
68 {14, 2}, {17, 2}, {20, 2}, /* hour, minute, second */
69 {11, 2}, /* dayofweek, */
71 (const unsigned char *)"T: : : : : : : \r\n",
75 static u_long cvt_computime P((unsigned char *, int, struct format *, clocktime_t *, void *));
76 static unsigned long inp_computime P((parse_t *, unsigned int, timestamp_t *));
78 clockformat_t clock_computime =
80 inp_computime, /* Computime input handling */
81 cvt_computime, /* Computime conversion */
82 0, /* no PPS monitoring */
83 (void *)&computime_fmt, /* conversion configuration */
84 "Diem's Computime Radio Clock", /* Computime Radio Clock */
85 24, /* string buffer */
86 0 /* no private data (complete pakets) */
92 * convert simple type format
96 unsigned char *buffer,
98 struct format *format,
99 clocktime_t *clock_time,
104 if (!Strok(buffer, format->fixed_string)) {
107 if (Stoi(&buffer[format->field_offsets[O_DAY].offset], &clock_time->day,
108 format->field_offsets[O_DAY].length) ||
109 Stoi(&buffer[format->field_offsets[O_MONTH].offset], &clock_time->month,
110 format->field_offsets[O_MONTH].length) ||
111 Stoi(&buffer[format->field_offsets[O_YEAR].offset], &clock_time->year,
112 format->field_offsets[O_YEAR].length) ||
113 Stoi(&buffer[format->field_offsets[O_HOUR].offset], &clock_time->hour,
114 format->field_offsets[O_HOUR].length) ||
115 Stoi(&buffer[format->field_offsets[O_MIN].offset], &clock_time->minute,
116 format->field_offsets[O_MIN].length) ||
117 Stoi(&buffer[format->field_offsets[O_SEC].offset], &clock_time->second,
118 format->field_offsets[O_SEC].length)) {
119 return CVT_FAIL | CVT_BADFMT;
122 clock_time->flags = 0;
123 clock_time->utcoffset = 0; /* We have UTC time */
133 * grep data from input stream
144 parseprintf(DD_PARSE, ("inp_computime(0x%x, 0x%x, ...)\n", (int)parseio, (int)ch));
149 parseprintf(DD_PARSE, ("inp_computime: START seen\n"));
151 parseio->parse_index = 1;
152 parseio->parse_data[0] = ch;
153 parseio->parse_dtime.parse_stime = *tstamp; /* collect timestamp */
154 return PARSE_INP_SKIP;
157 parseprintf(DD_PARSE, ("inp_computime: END seen\n"));
158 if ((rtc = parse_addchar(parseio, ch)) == PARSE_INP_SKIP)
159 return parse_end(parseio);
164 return parse_addchar(parseio, ch);
168 #else /* not (REFCLOCK && CLOCK_PARSE && CLOCK_COMPUTIME) */
169 int clk_computime_bs;
170 #endif /* not (REFCLOCK && CLOCK_PARSE && CLOCK_COMPUTIME) */
174 * Revision 4.6 1999/11/28 09:13:49 kardel
177 * Revision 4.5 1998/06/14 21:09:34 kardel
180 * Revision 4.4 1998/06/13 12:00:38 kardel
181 * fix SYSV clock name clash
183 * Revision 4.3 1998/06/12 15:22:26 kardel
186 * Revision 4.2 1998/06/12 09:13:24 kardel
187 * conditional compile macros fixed
190 * Revision 4.1 1998/05/24 09:39:51 kardel
191 * implementation of the new IO handling model
193 * Revision 4.0 1998/04/10 19:45:27 kardel
194 * Start 4.0 release version numbering
196 * from V3 1.8 log info deleted 1998/04/11 kardel