2 * /src/NTP/ntp-4/libparse/clk_schmid.c,v 4.5 1999/11/28 09:13:51 kardel RELEASE_19991128_A
4 * clk_schmid.c,v 4.5 1999/11/28 09:13:51 kardel RELEASE_19991128_A
8 * Copyright (C) 1992-1998 by Frank Kardel
9 * Friedrich-Alexander Universität Erlangen-Nürnberg, Germany
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
21 #if defined(REFCLOCK) && defined(CLOCK_PARSE) && defined(CLOCK_SCHMID)
24 #include "ntp_unixtime.h"
25 #include "ntp_calendar.h"
30 #include "ntp_stdlib.h"
33 #include "sys/parsestreams.h"
34 extern void printf P((const char *, ...));
38 * Description courtesy of Adam W. Feigin et. al (Swisstime iis.ethz.ch)
40 * The command to Schmid's DCF77 clock is a single byte; each bit
41 * allows the user to select some part of the time string, as follows (the
42 * output for the lsb is sent first).
44 * Bit 0: time in MEZ, 4 bytes *binary, not BCD*; hh.mm.ss.tenths
45 * Bit 1: date 3 bytes *binary, not BCD: dd.mm.yy
46 * Bit 2: week day, 1 byte (unused here)
47 * Bit 3: time zone, 1 byte, 0=MET, 1=MEST. (unused here)
48 * Bit 4: clock status, 1 byte, 0=time invalid,
49 * 1=time from crystal backup,
51 * Bit 5: transmitter status, 1 byte,
52 * bit 0: backup antenna
53 * bit 1: time zone change within 1h
54 * bit 3,2: TZ 01=MEST, 10=MET
55 * bit 4: leap second will be
56 * added within one hour
58 * Bit 6: time in backup mode, units of 5 minutes (unused here)
62 #define WS_SIGNAL 0x02
64 #define WS_ALTERNATE 0x01
65 #define WS_ANNOUNCE 0x02
71 static u_long cvt_schmid P((unsigned char *, int, struct format *, clocktime_t *, void *));
72 static unsigned long inp_schmid P((parse_t *, unsigned int, timestamp_t *));
74 clockformat_t clock_schmid =
76 inp_schmid, /* no input handling */
77 cvt_schmid, /* Schmid conversion */
78 0, /* not direct PPS monitoring */
79 0, /* conversion configuration */
80 "Schmid", /* Schmid receiver */
81 12, /* binary data buffer */
82 0, /* no private data (complete messages) */
88 unsigned char *buffer,
90 struct format *format,
91 clocktime_t *clock_time,
95 if ((size != 11) || (buffer[10] != (unsigned char)'\375'))
101 if (buffer[0] > 23 || buffer[1] > 59 || buffer[2] > 59 || buffer[3] > 9) /* Time */
103 return CVT_FAIL|CVT_BADTIME;
106 if (buffer[4] < 1 || buffer[4] > 31 || buffer[5] < 1 || buffer[5] > 12
109 return CVT_FAIL|CVT_BADDATE;
113 clock_time->hour = buffer[0];
114 clock_time->minute = buffer[1];
115 clock_time->second = buffer[2];
116 clock_time->usecond = buffer[3] * 100000;
117 clock_time->day = buffer[4];
118 clock_time->month = buffer[5];
119 clock_time->year = buffer[6];
121 clock_time->flags = 0;
123 switch (buffer[8] & WS_TZ)
126 clock_time->utcoffset = -1*60*60;
130 clock_time->utcoffset = -2*60*60;
131 clock_time->flags |= PARSEB_DST;
135 return CVT_FAIL|CVT_BADFMT;
138 if (!(buffer[7] & WS_TIME))
140 clock_time->flags |= PARSEB_POWERUP;
143 if (!(buffer[7] & WS_SIGNAL))
145 clock_time->flags |= PARSEB_NOSYNC;
148 if (buffer[7] & WS_SIGNAL)
150 if (buffer[8] & WS_ALTERNATE)
152 clock_time->flags |= PARSEB_ALTERNATE;
155 if (buffer[8] & WS_ANNOUNCE)
157 clock_time->flags |= PARSEB_ANNOUNCE;
160 if (buffer[8] & WS_LEAP)
162 clock_time->flags |= PARSEB_LEAPADD; /* default: DCF77 data format deficiency */
166 clock_time->flags |= PARSEB_S_LEAP|PARSEB_S_ANTENNA;
176 * grep data from input stream
187 parseprintf(DD_PARSE, ("inp_schmid(0x%lx, 0x%x, ...)\n", (long)parseio, ch));
192 parseprintf(DD_PARSE, ("mbg_input: ETX seen\n"));
193 if ((rtc = parse_addchar(parseio, ch)) == PARSE_INP_SKIP)
194 return parse_end(parseio);
199 return parse_addchar(parseio, ch);
203 #else /* not (REFCLOCK && CLOCK_PARSE && CLOCK_SCHMID) */
205 #endif /* not (REFCLOCK && CLOCK_PARSE && CLOCK_SCHMID) */
211 * Revision 4.5 1999/11/28 09:13:51 kardel
214 * Revision 4.4 1998/06/13 12:06:03 kardel
215 * fix SYSV clock name clash
217 * Revision 4.3 1998/06/12 15:22:29 kardel
220 * Revision 4.2 1998/06/12 09:13:26 kardel
221 * conditional compile macros fixed
224 * Revision 4.1 1998/05/24 09:39:53 kardel
225 * implementation of the new IO handling model
227 * Revision 4.0 1998/04/10 19:45:31 kardel
228 * Start 4.0 release version numbering
230 * from V3 3.22 log info deleted 1998/04/11 kardel