2 * /src/NTP/ntp4-dev/libparse/clk_hopf6021.c,v 4.10 2004/11/14 15:29:41 kardel RELEASE_20050508_A
4 * clk_hopf6021.c,v 4.10 2004/11/14 15:29:41 kardel RELEASE_20050508_A
6 * Radiocode Clocks HOPF Funkuhr 6021 mit serieller Schnittstelle
7 * base code version from 24th Nov 1995 - history at end
9 * Created by F.Schnekenbuehl <frank@comsys.dofn.de> from clk_rcc8000.c
10 * Nortel DASA Network Systems GmbH, Department: ND250
11 * A Joint venture of Daimler-Benz Aerospace and Nortel
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
23 #if defined(REFCLOCK) && defined(CLOCK_PARSE) && defined(CLOCK_HOPF6021)
26 #include "ntp_unixtime.h"
27 #include "ntp_calendar.h"
33 #include "ntp_stdlib.h"
36 #include "sys/parsestreams.h"
37 extern int printf (const char *, ...);
43 * UTC ueber serielle Schnittstelle
45 * ETX zum Sekundenvorlauf ON
47 * Ausgabe Uhrzeit und Datum
48 * Senden mit Steuerzeichen
53 * Type 6021 Serial Output format
55 * 000000000011111111 / char
56 * 012345678901234567 \ position
57 * sABHHMMSSDDMMYYnre Actual
58 * C4110046231195 Parse
61 * s = STX (0x02), e = ETX (0x03)
62 * n = NL (0x0A), r = CR (0x0D)
64 * A B - Status and weekday
69 * x x x 0 - no announcement
70 * x x x 1 - Summertime - wintertime - summertime announcement
71 * x x 0 x - Wintertime
72 * x x 1 x - Summertime
73 * 0 0 x x - Time/Date invalid
74 * 0 1 x x - Internal clock used
75 * 1 0 x x - Radio clock
76 * 1 1 x x - Radio clock highprecision
90 #define HOPF_DSTWARN 0x01 /* DST switch warning */
91 #define HOPF_DST 0x02 /* DST in effect */
93 #define HOPF_MODE 0x0C /* operation mode mask */
94 #define HOPF_INVALID 0x00 /* no time code available */
95 #define HOPF_INTERNAL 0x04 /* internal clock */
96 #define HOPF_RADIO 0x08 /* radio clock */
97 #define HOPF_RADIOHP 0x0C /* high precision radio clock */
99 #define HOPF_UTC 0x08 /* time code in UTC */
100 #define HOPF_WMASK 0x07 /* mask for weekday code */
102 static struct format hopf6021_fmt =
105 { 9, 2 }, {11, 2}, { 13, 2}, /* Day, Month, Year */
106 { 3, 2 }, { 5, 2}, { 7, 2}, /* Hour, Minute, Second */
107 { 2, 1 }, { 1, 1}, { 0, 0}, /* Weekday, Flags, Zone */
110 (const unsigned char *)"\002 \n\r\003",
114 #define OFFS(x) format->field_offsets[(x)].offset
115 #define STOI(x, y) Stoi(&buffer[OFFS(x)], y, format->field_offsets[(x)].length)
116 #define hexval(x) (('0' <= (x) && (x) <= '9') ? (x) - '0' : \
117 ('a' <= (x) && (x) <= 'f') ? (x) - 'a' + 10 : \
118 ('A' <= (x) && (x) <= 'F') ? (x) - 'A' + 10 : \
121 static parse_cvt_fnc_t cvt_hopf6021;
122 static parse_inp_fnc_t inp_hopf6021;
124 clockformat_t clock_hopf6021 =
126 inp_hopf6021, /* HOPF 6021 input handling */
127 cvt_hopf6021, /* Radiocode clock conversion */
128 0, /* no direct PPS monitoring */
129 (void *)&hopf6021_fmt, /* conversion configuration */
130 "hopf Funkuhr 6021", /* clock format name */
131 19, /* string buffer */
132 0 /* private data length, no private data */
135 /* parse_cvt_fnc_t cvt_hopf6021 */
138 unsigned char *buffer,
140 struct format *format,
141 clocktime_t *clock_time,
145 unsigned char status,weekday;
147 if (!Strok(buffer, format->fixed_string))
152 if ( STOI(O_DAY, &clock_time->day) ||
153 STOI(O_MONTH, &clock_time->month) ||
154 STOI(O_YEAR, &clock_time->year) ||
155 STOI(O_HOUR, &clock_time->hour) ||
156 STOI(O_MIN, &clock_time->minute) ||
157 STOI(O_SEC, &clock_time->second)
160 return CVT_FAIL|CVT_BADFMT;
163 clock_time->usecond = 0;
164 clock_time->utcoffset = 0;
166 status = (u_char) hexval(buffer[OFFS(O_FLAGS)]);
167 weekday= (u_char) hexval(buffer[OFFS(O_WDAY)]);
169 if ((status == 0xFF) || (weekday == 0xFF))
171 return CVT_FAIL|CVT_BADFMT;
174 clock_time->flags = 0;
176 if (weekday & HOPF_UTC)
178 clock_time->flags |= PARSEB_UTC;
182 if (status & HOPF_DST)
184 clock_time->flags |= PARSEB_DST;
185 clock_time->utcoffset = -2*60*60; /* MET DST */
189 clock_time->utcoffset = -1*60*60; /* MET */
193 clock_time->flags |= (status & HOPF_DSTWARN) ? PARSEB_ANNOUNCE : 0;
195 switch (status & HOPF_MODE)
197 case HOPF_INVALID: /* Time/Date invalid */
198 clock_time->flags |= PARSEB_POWERUP;
201 case HOPF_INTERNAL: /* internal clock */
202 clock_time->flags |= PARSEB_NOSYNC;
205 case HOPF_RADIO: /* Radio clock */
206 case HOPF_RADIOHP: /* Radio clock high precision */
210 return CVT_FAIL|CVT_BADFMT;
217 * parse_inp_fnc_t inp_hopf6021
219 * grab data from input stream
230 parseprintf(DD_PARSE, ("inp_hopf6021(0x%p, 0x%x, ...)\n", (void*)parseio, ch));
235 parseprintf(DD_PARSE, ("inp_hopf6021: EOL seen\n"));
236 parseio->parse_dtime.parse_stime = *tstamp; /* collect timestamp */
237 if ((rtc = parse_addchar(parseio, ch)) == PARSE_INP_SKIP)
238 return parse_end(parseio);
243 return parse_addchar(parseio, ch);
247 #else /* not (REFCLOCK && CLOCK_PARSE && CLOCK_HOPF6021) */
249 #endif /* not (REFCLOCK && CLOCK_PARSE && CLOCK_HOPF6021) */
255 * Revision 4.10 2004/11/14 15:29:41 kardel
256 * support PPSAPI, upgrade Copyright to Berkeley style
258 * Revision 4.7 1999/11/28 09:13:49 kardel
261 * Revision 4.6 1998/11/15 20:27:57 kardel
262 * Release 4.0.73e13 reconcilation
264 * Revision 4.5 1998/06/14 21:09:35 kardel
267 * Revision 4.4 1998/06/13 12:02:38 kardel
268 * fix SYSV clock name clash
270 * Revision 4.3 1998/06/12 15:22:27 kardel
273 * Revision 4.2 1998/06/12 09:13:25 kardel
274 * conditional compile macros fixed
277 * Revision 4.1 1998/05/24 09:39:52 kardel
278 * implementation of the new IO handling model
280 * Revision 4.0 1998/04/10 19:45:29 kardel
281 * Start 4.0 release version numbering
283 * from V3 3.6 log info deleted 1998/04/11 kardel