1 /* $NetBSD: clk_wharton.c,v 1.3 2003/12/04 16:23:37 drochner Exp $ */
4 * /src/NTP/ntp4-dev/libparse/clk_wharton.c,v 4.2 2004/11/14 15:29:41 kardel RELEASE_20050508_A
6 * clk_wharton.c,v 4.2 2004/11/14 15:29:41 kardel RELEASE_20050508_A
8 * From Philippe De Muyter <phdm@macqel.be>, 1999
14 #if defined(REFCLOCK) && defined(CLOCK_PARSE) && defined(CLOCK_WHARTON_400A)
16 * Support for WHARTON 400A Series clock + 404.2 serial interface.
18 * Copyright (C) 1999, 2000 by Philippe De Muyter <phdm@macqel.be>
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.
31 #include "ntp_stdlib.h"
34 #include "sys/parsestreams.h"
35 extern void printf
P((const char *, ...));
39 * In private e-mail alastair@wharton.co.uk said :
40 * "If you are going to use the 400A and 404.2 system [for ntp] I recommend
41 * that you set the 400A to output the message every second. The start of
42 * transmission of the first byte of the message is synchronised to the
44 * The WHARTON 400A Series is able to send date/time serial messages
45 * in 7 output formats. We use format 1 here because it is the shortest.
46 * For use with this driver, the WHARTON 400A Series clock must be set-up
48 * Programmable Selected
50 * BST or CET display 3 9 or 11
51 * No external controller 7 0
52 * Serial Output Format 1 9 1
53 * Baud rate 9600 bps 10 96
54 * Bit length 8 bits 11 8
57 * WHARTON 400A Series output format 1 is as follows :
59 * Timestamp STXssmmhhDDMMYYSETX
60 * Pos 0 12345678901234
63 * STX start transmission (ASCII 0x02)
64 * ETX end transmission (ASCII 0x03)
65 * ss Second expressed in reversed decimal (units then tens)
66 * mm Minute expressed in reversed decimal
67 * hh Hour expressed in reversed decimal
68 * DD Day of month expressed in reversed decimal
69 * MM Month expressed in reversed decimal (January is 1)
70 * YY Year (without century) expressed in reversed decimal
71 * S Status byte : 0x30 +
72 * bit 0 0 = MSF source 1 = DCF source
73 * bit 1 0 = Winter time 1 = Summer time
74 * bit 2 0 = not synchronised 1 = synchronised
75 * bit 3 0 = no early warning 1 = early warning
82 * convert simple type format
86 unsigned char *buffer
,
88 struct format
*format
,
89 clocktime_t
*clock_time
,
95 /* The given `size' includes a terminating null-character. */
96 if (size
!= 16 || buffer
[0] != STX
|| buffer
[14] != ETX
97 || buffer
[13] < '0' || buffer
[13] > ('0' + 0xf))
99 for (i
= 1; i
< 13; i
+= 1)
100 if (buffer
[i
] < '0' || buffer
[i
] > '9')
102 clock_time
->second
= (buffer
[2] - '0') * 10 + buffer
[1] - '0';
103 clock_time
->minute
= (buffer
[4] - '0') * 10 + buffer
[3] - '0';
104 clock_time
->hour
= (buffer
[6] - '0') * 10 + buffer
[5] - '0';
105 clock_time
->day
= (buffer
[8] - '0') * 10 + buffer
[7] - '0';
106 clock_time
->month
= (buffer
[10] - '0') * 10 + buffer
[9] - '0';
107 clock_time
->year
= (buffer
[12] - '0') * 10 + buffer
[11] - '0';
108 clock_time
->usecond
= 0;
109 if (buffer
[13] & 0x1) /* We have CET time */
110 clock_time
->utcoffset
= -1*60*60;
111 else /* We have BST time */
112 clock_time
->utcoffset
= 0;
113 if (buffer
[13] & 0x2) {
114 clock_time
->flags
|= PARSEB_DST
;
115 clock_time
->utcoffset
+= -1*60*60;
117 if (!(buffer
[13] & 0x4))
118 clock_time
->flags
|= PARSEB_NOSYNC
;
119 if (buffer
[13] & 0x8)
120 clock_time
->flags
|= PARSEB_ANNOUNCE
;
128 * grep data from input stream
139 parseprintf(DD_PARSE
, ("inp_wharton_400a(0x%lx, 0x%x, ...)\n", (long)parseio
, ch
));
144 parseprintf(DD_PARSE
, ("inp_wharton_400a: STX seen\n"));
146 parseio
->parse_index
= 1;
147 parseio
->parse_data
[0] = ch
;
148 parseio
->parse_dtime
.parse_stime
= *tstamp
; /* collect timestamp */
149 return PARSE_INP_SKIP
;
152 parseprintf(DD_PARSE
, ("inp_wharton_400a: ETX seen\n"));
153 if ((rtc
= parse_addchar(parseio
, ch
)) == PARSE_INP_SKIP
)
154 return parse_end(parseio
);
159 return parse_addchar(parseio
, ch
);
163 clockformat_t clock_wharton_400a
=
165 inp_wharton_400a
, /* input handling function */
166 cvt_wharton_400a
, /* conversion function */
167 0, /* no PPS monitoring */
168 0, /* conversion configuration */
169 "WHARTON 400A Series clock Output Format 1", /* String format name */
170 15, /* string buffer */
171 0 /* no private data (complete pakets) */
174 #else /* not (REFCLOCK && CLOCK_PARSE && CLOCK_WHARTON_400A) */
175 int clk_wharton_400a_bs
;
176 #endif /* not (REFCLOCK && CLOCK_PARSE && CLOCK_WHARTON_400A) */
180 * Revision 4.1 1999/02/28 15:27:24 kardel
181 * wharton clock integration