1 /* $NetBSD: clk_hopf6021.c,v 1.3 2003/12/04 16:23:37 drochner Exp $ */
4 * /src/NTP/ntp4-dev/libparse/clk_hopf6021.c,v 4.10 2004/11/14 15:29:41 kardel RELEASE_20050508_A
6 * clk_hopf6021.c,v 4.10 2004/11/14 15:29:41 kardel RELEASE_20050508_A
8 * Radiocode Clocks HOPF Funkuhr 6021 mit serieller Schnittstelle
9 * base code version from 24th Nov 1995 - history at end
11 * Created by F.Schnekenbuehl <frank@comsys.dofn.de> from clk_rcc8000.c
12 * Nortel DASA Network Systems GmbH, Department: ND250
13 * A Joint venture of Daimler-Benz Aerospace and Nortel
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
25 #if defined(REFCLOCK) && defined(CLOCK_PARSE) && defined(CLOCK_HOPF6021)
28 #include "ntp_unixtime.h"
29 #include "ntp_calendar.h"
35 #include "ntp_stdlib.h"
38 #include "sys/parsestreams.h"
39 extern void printf
P((const char *, ...));
45 * UTC ueber serielle Schnittstelle
47 * ETX zum Sekundenvorlauf ON
49 * Ausgabe Uhrzeit und Datum
50 * Senden mit Steuerzeichen
55 * Type 6021 Serial Output format
57 * 000000000011111111 / char
58 * 012345678901234567 \ position
59 * sABHHMMSSDDMMYYnre Actual
60 * C4110046231195 Parse
63 * s = STX (0x02), e = ETX (0x03)
64 * n = NL (0x0A), r = CR (0x0D)
66 * A B - Status and weekday
71 * x x x 0 - no announcement
72 * x x x 1 - Summertime - wintertime - summertime announcement
73 * x x 0 x - Wintertime
74 * x x 1 x - Summertime
75 * 0 0 x x - Time/Date invalid
76 * 0 1 x x - Internal clock used
77 * 1 0 x x - Radio clock
78 * 1 1 x x - Radio clock highprecision
92 #define HOPF_DSTWARN 0x01 /* DST switch warning */
93 #define HOPF_DST 0x02 /* DST in effect */
95 #define HOPF_MODE 0x0C /* operation mode mask */
96 #define HOPF_INVALID 0x00 /* no time code available */
97 #define HOPF_INTERNAL 0x04 /* internal clock */
98 #define HOPF_RADIO 0x08 /* radio clock */
99 #define HOPF_RADIOHP 0x0C /* high precision radio clock */
101 #define HOPF_UTC 0x08 /* time code in UTC */
102 #define HOPF_WMASK 0x07 /* mask for weekday code */
104 static struct format hopf6021_fmt
=
107 { 9, 2 }, {11, 2}, { 13, 2}, /* Day, Month, Year */
108 { 3, 2 }, { 5, 2}, { 7, 2}, /* Hour, Minute, Second */
109 { 2, 1 }, { 1, 1}, { 0, 0}, /* Weekday, Flags, Zone */
112 (const unsigned char *)"\002 \n\r\003",
116 #define OFFS(x) format->field_offsets[(x)].offset
117 #define STOI(x, y) Stoi(&buffer[OFFS(x)], y, format->field_offsets[(x)].length)
118 #define hexval(x) (('0' <= (x) && (x) <= '9') ? (x) - '0' : \
119 ('a' <= (x) && (x) <= 'f') ? (x) - 'a' + 10 : \
120 ('A' <= (x) && (x) <= 'F') ? (x) - 'A' + 10 : \
123 static unsigned long cvt_hopf6021
P((unsigned char *, int, struct format
*, clocktime_t
*, void *));
124 static unsigned long inp_hopf6021
P((parse_t
*, unsigned int, timestamp_t
*));
126 clockformat_t clock_hopf6021
=
128 inp_hopf6021
, /* HOPF 6021 input handling */
129 cvt_hopf6021
, /* Radiocode clock conversion */
130 0, /* no direct PPS monitoring */
131 (void *)&hopf6021_fmt
, /* conversion configuration */
132 "hopf Funkuhr 6021", /* clock format name */
133 19, /* string buffer */
134 0 /* private data length, no private data */
139 unsigned char *buffer
,
141 struct format
*format
,
142 clocktime_t
*clock_time
,
146 unsigned char status
,weekday
;
148 if (!Strok(buffer
, format
->fixed_string
))
153 if ( STOI(O_DAY
, &clock_time
->day
) ||
154 STOI(O_MONTH
, &clock_time
->month
) ||
155 STOI(O_YEAR
, &clock_time
->year
) ||
156 STOI(O_HOUR
, &clock_time
->hour
) ||
157 STOI(O_MIN
, &clock_time
->minute
) ||
158 STOI(O_SEC
, &clock_time
->second
)
161 return CVT_FAIL
|CVT_BADFMT
;
164 clock_time
->usecond
= 0;
165 clock_time
->utcoffset
= 0;
167 status
= hexval(buffer
[OFFS(O_FLAGS
)]);
168 weekday
= hexval(buffer
[OFFS(O_WDAY
)]);
170 if ((status
== 0xFF) || (weekday
== 0xFF))
172 return CVT_FAIL
|CVT_BADFMT
;
175 clock_time
->flags
= 0;
177 if (weekday
& HOPF_UTC
)
179 clock_time
->flags
|= PARSEB_UTC
;
183 if (status
& HOPF_DST
)
185 clock_time
->flags
|= PARSEB_DST
;
186 clock_time
->utcoffset
= -2*60*60; /* MET DST */
190 clock_time
->utcoffset
= -1*60*60; /* MET */
194 clock_time
->flags
|= (status
& HOPF_DSTWARN
) ? PARSEB_ANNOUNCE
: 0;
196 switch (status
& HOPF_MODE
)
198 case HOPF_INVALID
: /* Time/Date invalid */
199 clock_time
->flags
|= PARSEB_POWERUP
;
202 case HOPF_INTERNAL
: /* internal clock */
203 clock_time
->flags
|= PARSEB_NOSYNC
;
206 case HOPF_RADIO
: /* Radio clock */
207 case HOPF_RADIOHP
: /* Radio clock high precision */
211 return CVT_FAIL
|CVT_BADFMT
;
220 * grep data from input stream
231 parseprintf(DD_PARSE
, ("inp_hopf6021(0x%lx, 0x%x, ...)\n", (long)parseio
, ch
));
236 parseprintf(DD_PARSE
, ("inp_hopf6021: EOL seen\n"));
237 parseio
->parse_dtime
.parse_stime
= *tstamp
; /* collect timestamp */
238 if ((rtc
= parse_addchar(parseio
, ch
)) == PARSE_INP_SKIP
)
239 return parse_end(parseio
);
244 return parse_addchar(parseio
, ch
);
248 #else /* not (REFCLOCK && CLOCK_PARSE && CLOCK_HOPF6021) */
250 #endif /* not (REFCLOCK && CLOCK_PARSE && CLOCK_HOPF6021) */
256 * Revision 4.10 2004/11/14 15:29:41 kardel
257 * support PPSAPI, upgrade Copyright to Berkeley style
259 * Revision 4.7 1999/11/28 09:13:49 kardel
262 * Revision 4.6 1998/11/15 20:27:57 kardel
263 * Release 4.0.73e13 reconcilation
265 * Revision 4.5 1998/06/14 21:09:35 kardel
268 * Revision 4.4 1998/06/13 12:02:38 kardel
269 * fix SYSV clock name clash
271 * Revision 4.3 1998/06/12 15:22:27 kardel
274 * Revision 4.2 1998/06/12 09:13:25 kardel
275 * conditional compile macros fixed
278 * Revision 4.1 1998/05/24 09:39:52 kardel
279 * implementation of the new IO handling model
281 * Revision 4.0 1998/04/10 19:45:29 kardel
282 * Start 4.0 release version numbering
284 * from V3 3.6 log info deleted 1998/04/11 kardel